2020-07-16 06:09:01 -04:00
|
|
|
import App from '../../base'
|
|
|
|
|
2021-05-17 07:50:19 -04:00
|
|
|
export default App.directive('verticalResizablePanes', (localStorage, ide) => ({
|
2020-07-16 06:09:01 -04:00
|
|
|
restrict: 'A',
|
|
|
|
link(scope, element, attrs) {
|
2020-07-23 05:20:41 -04:00
|
|
|
const name = attrs.verticalResizablePanes
|
2022-08-05 05:03:49 -04:00
|
|
|
const minSize = scope.$eval(attrs.verticalResizablePanesMinSize)
|
|
|
|
const maxSize = scope.$eval(attrs.verticalResizablePanesMaxSize)
|
|
|
|
const defaultSize = scope.$eval(attrs.verticalResizablePanesDefaultSize)
|
2020-07-16 06:09:01 -04:00
|
|
|
let storedSize = null
|
|
|
|
let manualResizeIncoming = false
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
const storageKey = `vertical-resizable:${name}:south-size`
|
|
|
|
storedSize = localStorage(storageKey)
|
|
|
|
$(window).unload(() => {
|
|
|
|
if (storedSize) {
|
|
|
|
localStorage(storageKey, storedSize)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-05 05:03:49 -04:00
|
|
|
const layoutOptions = {
|
|
|
|
center: {
|
|
|
|
paneSelector: '[vertical-resizable-top]',
|
|
|
|
paneClass: 'vertical-resizable-top',
|
|
|
|
size: 'auto',
|
|
|
|
},
|
|
|
|
south: {
|
|
|
|
paneSelector: '[vertical-resizable-bottom]',
|
|
|
|
paneClass: 'vertical-resizable-bottom',
|
|
|
|
resizerClass: 'vertical-resizable-resizer',
|
|
|
|
resizerCursor: 'ns-resize',
|
|
|
|
size: 'auto',
|
|
|
|
resizable: true,
|
|
|
|
closable: false,
|
|
|
|
slidable: false,
|
|
|
|
spacing_open: 6,
|
|
|
|
spacing_closed: 6,
|
|
|
|
maxSize: '75%',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-16 06:09:01 -04:00
|
|
|
const toggledExternally = attrs.verticalResizablePanesToggledExternallyOn
|
2021-05-17 07:50:19 -04:00
|
|
|
const hiddenExternally = attrs.verticalResizablePanesHiddenExternallyOn
|
|
|
|
const hiddenInitially = attrs.verticalResizablePanesHiddenInitially
|
2020-11-26 09:22:30 -05:00
|
|
|
const resizeOn = attrs.verticalResizablePanesResizeOn
|
2020-07-16 06:09:01 -04:00
|
|
|
const resizerDisabledClass = `${layoutOptions.south.resizerClass}-disabled`
|
|
|
|
|
|
|
|
function enableResizer() {
|
|
|
|
if (layoutHandle.resizers && layoutHandle.resizers.south) {
|
|
|
|
layoutHandle.resizers.south.removeClass(resizerDisabledClass)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableResizer() {
|
|
|
|
if (layoutHandle.resizers && layoutHandle.resizers.south) {
|
|
|
|
layoutHandle.resizers.south.addClass(resizerDisabledClass)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDragEnd() {
|
|
|
|
manualResizeIncoming = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleResize(paneName, paneEl, paneState) {
|
|
|
|
if (manualResizeIncoming) {
|
|
|
|
storedSize = paneState.size
|
|
|
|
}
|
|
|
|
manualResizeIncoming = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toggledExternally) {
|
|
|
|
scope.$on(toggledExternally, (e, open) => {
|
|
|
|
if (open) {
|
|
|
|
enableResizer()
|
2022-08-05 05:43:16 -04:00
|
|
|
layoutHandle.sizePane('south', storedSize ?? defaultSize ?? 'auto')
|
2020-07-16 06:09:01 -04:00
|
|
|
} else {
|
|
|
|
disableResizer()
|
2022-08-05 05:43:16 -04:00
|
|
|
layoutHandle.sizePane('south', 'auto')
|
2020-07-16 06:09:01 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-17 07:50:19 -04:00
|
|
|
if (hiddenExternally) {
|
|
|
|
ide.$scope.$on(hiddenExternally, (e, open) => {
|
|
|
|
if (open) {
|
|
|
|
layoutHandle.show('south')
|
|
|
|
} else {
|
|
|
|
layoutHandle.hide('south')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
if (resizeOn) {
|
2021-09-03 05:07:52 -04:00
|
|
|
ide.$scope.$on(resizeOn, () => {
|
|
|
|
ide.$timeout(() => {
|
|
|
|
layoutHandle.resizeAll()
|
|
|
|
})
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-23 05:20:41 -04:00
|
|
|
if (maxSize) {
|
|
|
|
layoutOptions.south.maxSize = maxSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minSize) {
|
|
|
|
layoutOptions.south.minSize = minSize
|
|
|
|
}
|
|
|
|
|
2021-05-17 07:50:19 -04:00
|
|
|
if (defaultSize) {
|
|
|
|
layoutOptions.south.size = defaultSize
|
|
|
|
}
|
|
|
|
|
2020-07-16 06:09:01 -04:00
|
|
|
// The `drag` event fires only when the user manually resizes the panes; the `resize` event fires even when
|
|
|
|
// the layout library internally resizes itself. In order to get explicit user-initiated resizes, we need to
|
|
|
|
// listen to `drag` events. However, when the `drag` event fires, the panes aren't yet finished sizing so we
|
|
|
|
// get the pane size *before* the resize happens. We do get the correct size in the next `resize` event.
|
|
|
|
// The solution to work around this is to set up a flag in `drag` events which tells the next `resize` event
|
|
|
|
// that it was user-initiated (therefore, storing the value).
|
|
|
|
layoutOptions.south.ondrag_end = handleDragEnd
|
|
|
|
layoutOptions.south.onresize = handleResize
|
|
|
|
|
|
|
|
const layoutHandle = element.layout(layoutOptions)
|
2021-05-17 07:50:19 -04:00
|
|
|
if (hiddenInitially === 'true') {
|
|
|
|
layoutHandle.hide('south')
|
|
|
|
}
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-07-16 06:09:01 -04:00
|
|
|
}))
|