Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed changeSizeInRatio #86

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 49 additions & 44 deletions src/utils/set-size-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,48 @@ import {
} from './panes'
import {getChangeInViewSize} from './resizable-pane'
import {findIndex} from './util'
import {setSizesAfterVisibilityChange} from './visibility-helper'
import {updateSizeInRatio} from './visibility-helper'

export const setSizeTopAndBottom = (
sizeChange: number,
behavior: ISetSizeBehaviour,
visibleItems: IResizableItem[],
requestIndexInVisibleItems: number
) => {
let firstInningItems : IResizableItem[]
let secondInningItems: IResizableItem[]
const getActionOnItem = (operation: addAndRemoveType, direction: number) => (item: IResizableItem) => {
item.syncAxisSize()
item.restoreLimits()
sizeChange = item.changeSize(sizeChange, operation, direction)
}

const changeSizeOfFirstAndSecondInningsItems = (firstInningDirection: number, secondInningDirection: number) => {
if (sizeChange > 0) { // Need to reduce other
firstInningItems.forEach(getActionOnItem(MINUS, firstInningDirection))
secondInningItems.forEach(getActionOnItem(MINUS, secondInningDirection))
}

if (sizeChange < 0) { // Need to increase other
sizeChange = Math.abs(sizeChange)

firstInningItems.forEach(getActionOnItem(PLUS, firstInningDirection))
secondInningItems.forEach(getActionOnItem(PLUS, secondInningDirection))
}
}

if (behavior === BUTTOM_FIRST) {
firstInningItems = visibleItems.slice(requestIndexInVisibleItems + 2)
secondInningItems = visibleItems.slice(0, requestIndexInVisibleItems - 1).reverse()

changeSizeOfFirstAndSecondInningsItems(DIRECTIONS.DOWN, DIRECTIONS.UP)
} else if (behavior === TOP_FIRST) {
firstInningItems = visibleItems.slice(0, requestIndexInVisibleItems - 1).reverse()
secondInningItems = visibleItems.slice(requestIndexInVisibleItems + 2)

changeSizeOfFirstAndSecondInningsItems(DIRECTIONS.UP, DIRECTIONS.DOWN)
}
}

// eslint-disable-next-line complexity
export const setSizeMethod = (resizable: ResizableModel, id: string, newSize: number,
Expand Down Expand Up @@ -40,7 +81,6 @@ export const setSizeMethod = (resizable: ResizableModel, id: string, newSize: nu
pane.changeSizeAndReturnRemaing(newSize)

const acceptableNewSize = pane.size
let allowedChange: number // Task it has only two condition, It (can be calc) smaller or greater than container Size
let sizeChange = acceptableNewSize - preSize

if (!sizeChange) {
Expand All @@ -50,68 +90,33 @@ export const setSizeMethod = (resizable: ResizableModel, id: string, newSize: nu

let addOnSizeChange = 0
let resizer: IResizableItem
// setting hiddenResizer state to NONE in final State

if (pane.hiddenResizer === LEFT) {
resizer = visibleItems[requestIndexInVisibleItems - 1]
} else if (pane.hiddenResizer === RIGHT) {
resizer = visibleItems[requestIndexInVisibleItems + 1]
}
pane.hiddenResizer = NONE

if (resizer) {
resizer.setVisibility(true, false)
addOnSizeChange = resizer.resizerSize
sizeChange += addOnSizeChange
}
pane.hiddenResizer = NONE

const getActionOnItem = (operation: addAndRemoveType, direction: number) => (item: IResizableItem) => {
item.syncAxisSize()
item.restoreLimits()
sizeChange = item.changeSize(sizeChange, operation, direction)
}

if (behavior === RATIO) {
const remainingVisiblePanes = [...visiblePanes]
remainingVisiblePanes.splice(requestIndex, 1)

const newMaxPaneSizeAllowd = initialSizeSum - pane.size - addOnSizeChange
setSizesAfterVisibilityChange(remainingVisiblePanes, newMaxPaneSizeAllowd)

const nowSizeSum = getItemsSizeSum(visiblePanes)
allowedChange = newSize - (nowSizeSum - initialSizeSum + addOnSizeChange)
} else if (behavior === BUTTOM_FIRST) {
const firstInningItems = visibleItems.slice(requestIndexInVisibleItems + 2)
const secondInningItems = visibleItems.slice(0, requestIndexInVisibleItems - 1).reverse()

if (sizeChange > 0) { // Need to reduce other
firstInningItems.forEach(getActionOnItem(MINUS, DIRECTIONS.DOWN))
secondInningItems.forEach(getActionOnItem(MINUS, DIRECTIONS.UP))
}
if (sizeChange < 0) { // Need to increase other
sizeChange = Math.abs(sizeChange)

firstInningItems.forEach(getActionOnItem(PLUS, DIRECTIONS.DOWN))
secondInningItems.forEach(getActionOnItem(PLUS, DIRECTIONS.UP))
}
} else if (behavior === TOP_FIRST) {
const firstInningItems = visibleItems.slice(0, requestIndexInVisibleItems - 1).reverse()
const secondInningItems = visibleItems.slice(requestIndexInVisibleItems + 2)

if (sizeChange > 0) { // Need to reduce other
firstInningItems.forEach(getActionOnItem(MINUS, DIRECTIONS.UP))
secondInningItems.forEach(getActionOnItem(MINUS, DIRECTIONS.DOWN))
}
updateSizeInRatio(remainingVisiblePanes, newMaxPaneSizeAllowd, remainingVisiblePanes)
}

if (sizeChange < 0) { // Need to increase other
sizeChange = Math.abs(sizeChange)
setSizeTopAndBottom(sizeChange, behavior, visibleItems, requestIndexInVisibleItems)

firstInningItems.forEach(getActionOnItem(PLUS, DIRECTIONS.UP))
secondInningItems.forEach(getActionOnItem(PLUS, DIRECTIONS.DOWN))
}
}
const changeInView = getChangeInViewSize(resizable)
allowedChange = newSize + changeInView
if (!isSecondAttemp) {
const changeInView = getChangeInViewSize(resizable)
const allowedChange = newSize + changeInView
setSizeMethod(resizable, id, allowedChange, behavior, true)
}
}
12 changes: 4 additions & 8 deletions src/utils/visibility-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,18 @@ export const setVisibilityOfResizers = (resizable: ResizableModel) => {
getItemsVisibleAndNoPartialHidden(items)
}
// actionList it can be removed
export const setSizesAfterVisibilityChange = (
export const updateSizeInRatio = (
allVisiblePanes: PaneModel[],
maxPaneSize: number,
actionVisibleList: PaneModel[] = allVisiblePanes
actionVisibleList: PaneModel[]
) => {
const currentPanesSize = getItemsSizeSum(allVisiblePanes)
const sizeChange = maxPaneSize - currentPanesSize

if (sizeChange === 0 || actionVisibleList.length === 0) {
return
}
changeSizeInRatio(allVisiblePanes, actionVisibleList, sizeChange, maxPaneSize)
}

export const changeSizeInRatio = (allVisiblePanes: PaneModel[], actionVisibleList: PaneModel[],
sizeChange: number, maxPaneSize: number) => {
const operation = sizeChange > 0 ? PLUS : MINUS

const sizeChangeAbsolute = Math.abs(sizeChange)
Expand All @@ -199,7 +195,7 @@ export const changeSizeInRatio = (allVisiblePanes: PaneModel[], actionVisibleLis
}
})

setSizesAfterVisibilityChange(allVisiblePanes, maxPaneSize, nextActionVisibleList)
updateSizeInRatio(allVisiblePanes, maxPaneSize, nextActionVisibleList)
}

export const setVisibilityFn = (resizable: ResizableModel, idMap: IKeyToBoolMap) => {
Expand Down Expand Up @@ -238,5 +234,5 @@ export const setVisibilityFn = (resizable: ResizableModel, idMap: IKeyToBoolMap)

const {maxPaneSize} = getMaxContainerSizes(resizable)

setSizesAfterVisibilityChange(visiblePanes, maxPaneSize)
updateSizeInRatio(visiblePanes, maxPaneSize, visiblePanes)
}
Loading