2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-useless-escape,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../base'
|
2020-07-16 06:09:01 -04:00
|
|
|
import _ from 'lodash'
|
2021-09-14 04:55:09 -04:00
|
|
|
import '../../vendor/libs/jquery-layout'
|
|
|
|
import '../../vendor/libs/jquery.ui.touch-punch'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
export default App.directive('layout', ($parse, $compile, ide) => ({
|
|
|
|
compile() {
|
|
|
|
return {
|
|
|
|
pre(scope, element, attrs) {
|
|
|
|
let customTogglerEl, spacingClosed, spacingOpen, state
|
|
|
|
const name = attrs.layout
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const { customTogglerPane } = attrs
|
|
|
|
const { customTogglerMsgWhenOpen } = attrs
|
|
|
|
const { customTogglerMsgWhenClosed } = attrs
|
|
|
|
const hasCustomToggler =
|
|
|
|
customTogglerPane != null &&
|
|
|
|
customTogglerMsgWhenOpen != null &&
|
|
|
|
customTogglerMsgWhenClosed != null
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.spacingOpen != null) {
|
|
|
|
spacingOpen = parseInt(attrs.spacingOpen, 10)
|
|
|
|
} else {
|
2021-02-22 11:21:43 -05:00
|
|
|
spacingOpen = 7
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.spacingClosed != null) {
|
|
|
|
spacingClosed = parseInt(attrs.spacingClosed, 10)
|
|
|
|
} else {
|
2021-02-22 11:21:43 -05:00
|
|
|
spacingClosed = 7
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
spacing_open: spacingOpen,
|
|
|
|
spacing_closed: spacingClosed,
|
|
|
|
slidable: false,
|
|
|
|
enableCursorHotkey: false,
|
|
|
|
onopen: pane => {
|
|
|
|
return onPaneOpen(pane)
|
|
|
|
},
|
|
|
|
onclose: pane => {
|
|
|
|
return onPaneClose(pane)
|
|
|
|
},
|
|
|
|
onresize: () => {
|
|
|
|
return onInternalResize()
|
|
|
|
},
|
|
|
|
maskIframesOnResize: scope.$eval(
|
|
|
|
attrs.maskIframesOnResize || 'false'
|
|
|
|
),
|
|
|
|
east: {
|
|
|
|
size: scope.$eval(attrs.initialSizeEast),
|
2021-04-27 03:52:58 -04:00
|
|
|
initClosed: scope.$eval(attrs.initClosedEast),
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
west: {
|
2022-05-20 04:15:14 -04:00
|
|
|
size: scope.$eval(attrs.initialSizeWest),
|
2021-04-27 03:52:58 -04:00
|
|
|
initClosed: scope.$eval(attrs.initClosedWest),
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Restore previously recorded state
|
|
|
|
if ((state = ide.localStorage(`layout.${name}`)) != null) {
|
|
|
|
if (state.east != null) {
|
|
|
|
if (
|
|
|
|
attrs.minimumRestoreSizeEast == null ||
|
|
|
|
(state.east.size >= attrs.minimumRestoreSizeEast &&
|
|
|
|
!state.east.initClosed)
|
|
|
|
) {
|
|
|
|
options.east = state.east
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2022-05-20 04:15:14 -04:00
|
|
|
options.east.initClosed = state.east.initClosed
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
if (state.west != null) {
|
|
|
|
if (
|
|
|
|
attrs.minimumRestoreSizeWest == null ||
|
|
|
|
(state.west.size >= attrs.minimumRestoreSizeWest &&
|
|
|
|
!state.west.initClosed)
|
|
|
|
) {
|
|
|
|
options.west = state.west
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2022-05-23 07:57:09 -04:00
|
|
|
// NOTE: disabled so that the file tree re-opens on page load
|
|
|
|
// options.west.initClosed = state.west.initClosed
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-02-22 11:21:43 -05:00
|
|
|
options.east.resizerCursor = 'ew-resize'
|
|
|
|
options.west.resizerCursor = 'ew-resize'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2022-05-20 04:13:06 -04:00
|
|
|
function repositionControls() {
|
|
|
|
state = layout.readState()
|
2020-05-19 05:02:56 -04:00
|
|
|
if (state.east != null) {
|
|
|
|
const controls = element.find('> .ui-layout-resizer-controls')
|
|
|
|
if (state.east.initClosed) {
|
|
|
|
return controls.hide()
|
|
|
|
} else {
|
|
|
|
controls.show()
|
|
|
|
return controls.css({
|
2021-04-27 03:52:58 -04:00
|
|
|
right: state.east.size,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2022-05-20 04:13:06 -04:00
|
|
|
function repositionCustomToggler() {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (customTogglerEl == null) {
|
|
|
|
return
|
|
|
|
}
|
2022-05-20 04:13:06 -04:00
|
|
|
state = layout.readState()
|
2020-05-19 05:02:56 -04:00
|
|
|
const positionAnchor = customTogglerPane === 'east' ? 'right' : 'left'
|
|
|
|
const paneState = state[customTogglerPane]
|
|
|
|
if (paneState != null) {
|
|
|
|
return customTogglerEl.css(
|
|
|
|
positionAnchor,
|
|
|
|
paneState.initClosed ? 0 : paneState.size
|
|
|
|
)
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2022-05-20 04:13:06 -04:00
|
|
|
function resetOpenStates() {
|
|
|
|
state = layout.readState()
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.openEast != null && state.east != null) {
|
|
|
|
const openEast = $parse(attrs.openEast)
|
|
|
|
return openEast.assign(scope, !state.east.initClosed)
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Someone moved the resizer
|
2021-10-26 04:08:56 -04:00
|
|
|
function onInternalResize() {
|
2022-05-20 04:13:06 -04:00
|
|
|
state = layout.readState()
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.$broadcast(`layout:${name}:resize`, state)
|
|
|
|
repositionControls()
|
|
|
|
if (hasCustomToggler) {
|
|
|
|
repositionCustomToggler()
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return resetOpenStates()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
let oldWidth = element.width()
|
|
|
|
// Something resized our parent element
|
2021-04-14 09:17:21 -04:00
|
|
|
const onExternalResize = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
attrs.resizeProportionally != null &&
|
|
|
|
scope.$eval(attrs.resizeProportionally)
|
|
|
|
) {
|
2022-05-20 04:13:06 -04:00
|
|
|
const eastState = layout.readState().east
|
2020-05-19 05:02:56 -04:00
|
|
|
if (eastState != null) {
|
2022-05-20 04:15:14 -04:00
|
|
|
const currentWidth = element.width()
|
|
|
|
if (currentWidth > 0) {
|
|
|
|
const newInternalWidth =
|
|
|
|
(eastState.size / oldWidth) * currentWidth
|
|
|
|
oldWidth = currentWidth
|
|
|
|
layout.sizePane('east', newInternalWidth)
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-09-03 05:08:35 -04:00
|
|
|
ide.$timeout(() => {
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.resizeAll()
|
2021-09-03 05:08:35 -04:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2022-05-20 04:13:06 -04:00
|
|
|
const layout = element.layout(options)
|
|
|
|
layout.resizeAll()
|
2020-05-19 05:02:56 -04:00
|
|
|
|
|
|
|
if (attrs.resizeOn != null) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const event of Array.from(attrs.resizeOn.split(','))) {
|
2020-05-19 05:02:56 -04:00
|
|
|
scope.$on(event, () => onExternalResize())
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (hasCustomToggler) {
|
2022-05-20 04:13:06 -04:00
|
|
|
state = layout.readState()
|
2020-05-19 05:02:56 -04:00
|
|
|
const customTogglerScope = scope.$new()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerScope.isOpen = true
|
|
|
|
customTogglerScope.isVisible = true
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
(state[customTogglerPane] != null
|
|
|
|
? state[customTogglerPane].initClosed
|
|
|
|
: undefined) === true
|
|
|
|
) {
|
|
|
|
customTogglerScope.isOpen = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerScope.tooltipMsgWhenOpen = customTogglerMsgWhenOpen
|
|
|
|
customTogglerScope.tooltipMsgWhenClosed = customTogglerMsgWhenClosed
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerScope.tooltipPlacement =
|
|
|
|
customTogglerPane === 'east' ? 'left' : 'right'
|
2021-04-14 09:17:21 -04:00
|
|
|
customTogglerScope.handleClick = function () {
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.toggle(customTogglerPane)
|
2020-05-19 05:02:56 -04:00
|
|
|
return repositionCustomToggler()
|
|
|
|
}
|
|
|
|
customTogglerEl = $compile(`\
|
2018-11-05 05:06:39 -05:00
|
|
|
<a href \
|
|
|
|
ng-show=\"isVisible\" \
|
|
|
|
class=\"custom-toggler ${`custom-toggler-${customTogglerPane}`}\" \
|
|
|
|
ng-class=\"isOpen ? 'custom-toggler-open' : 'custom-toggler-closed'\" \
|
|
|
|
tooltip=\"{{ isOpen ? tooltipMsgWhenOpen : tooltipMsgWhenClosed }}\" \
|
|
|
|
tooltip-placement=\"{{ tooltipPlacement }}\" \
|
|
|
|
ng-click=\"handleClick()\">\
|
|
|
|
`)(customTogglerScope)
|
2020-05-19 05:02:56 -04:00
|
|
|
element.append(customTogglerEl)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-10-26 04:08:56 -04:00
|
|
|
function onPaneOpen(pane) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (!hasCustomToggler && pane !== customTogglerPane) {
|
|
|
|
return
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return customTogglerEl
|
|
|
|
.scope()
|
|
|
|
.$applyAsync(() => (customTogglerEl.scope().isOpen = true))
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-10-26 04:08:56 -04:00
|
|
|
function onPaneClose(pane) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (!hasCustomToggler && pane !== customTogglerPane) {
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return customTogglerEl
|
|
|
|
.scope()
|
|
|
|
.$applyAsync(() => (customTogglerEl.scope().isOpen = false))
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2022-12-06 09:51:59 -05:00
|
|
|
// Ensure editor resizes after loading. This is to handle the case where
|
|
|
|
// the window has been resized while the editor is loading
|
|
|
|
scope.$on('editor:loaded', () => {
|
|
|
|
ide.$timeout(() => layout.resizeAll())
|
|
|
|
})
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
// Save state when exiting
|
2020-07-16 06:09:01 -04:00
|
|
|
$(window).unload(() => {
|
|
|
|
// Save only the state properties for the current layout, ignoring sublayouts inside it.
|
|
|
|
// If we save sublayouts state (`children`), the layout library will use it when
|
|
|
|
// initializing. This raises errors when the sublayout elements aren't available (due to
|
|
|
|
// being loaded at init or just not existing for the current project/user).
|
2022-05-20 04:13:06 -04:00
|
|
|
const stateToSave = _.mapValues(layout.readState(), pane =>
|
2020-07-16 06:09:01 -04:00
|
|
|
_.omit(pane, 'children')
|
|
|
|
)
|
|
|
|
ide.localStorage(`layout.${name}`, stateToSave)
|
|
|
|
})
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.openEast != null) {
|
2021-04-14 09:17:21 -04:00
|
|
|
scope.$watch(attrs.openEast, function (value, oldValue) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (value != null && value !== oldValue) {
|
2019-07-16 05:13:18 -04:00
|
|
|
if (value) {
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.open('east')
|
2019-07-16 05:13:18 -04:00
|
|
|
} else {
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.close('east')
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2022-05-20 04:15:14 -04:00
|
|
|
if (hasCustomToggler) {
|
|
|
|
repositionCustomToggler()
|
|
|
|
customTogglerEl.scope().$applyAsync(function () {
|
|
|
|
customTogglerEl.scope().isOpen = value
|
|
|
|
})
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
return setTimeout(() => scope.$digest(), 0)
|
|
|
|
})
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (attrs.allowOverflowOn != null) {
|
|
|
|
const overflowPane = scope.$eval(attrs.allowOverflowOn)
|
2022-05-20 04:13:06 -04:00
|
|
|
const overflowPaneEl = layout.panes[overflowPane]
|
2020-05-19 05:02:56 -04:00
|
|
|
// Set the panel as overflowing (gives it higher z-index and sets overflow rules)
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.allowOverflow(overflowPane)
|
2020-05-19 05:02:56 -04:00
|
|
|
// Read the given z-index value and increment it, so that it's higher than synctex controls.
|
|
|
|
const overflowPaneZVal = overflowPaneEl.zIndex()
|
|
|
|
overflowPaneEl.css('z-index', overflowPaneZVal + 1)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
|
|
|
resetOpenStates()
|
|
|
|
onInternalResize()
|
|
|
|
|
|
|
|
if (attrs.layoutDisabled != null) {
|
2021-04-14 09:17:21 -04:00
|
|
|
return scope.$watch(attrs.layoutDisabled, function (value) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (value) {
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.hide('east')
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
2022-05-20 04:13:06 -04:00
|
|
|
layout.show('east')
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
if (hasCustomToggler) {
|
2021-04-14 09:17:21 -04:00
|
|
|
return customTogglerEl.scope().$applyAsync(function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
customTogglerEl.scope().isOpen = !value
|
|
|
|
return (customTogglerEl.scope().isVisible = !value)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
post(scope, element, attrs) {
|
|
|
|
const name = attrs.layout
|
|
|
|
const state = element.layout().readState()
|
|
|
|
return scope.$broadcast(`layout:${name}:linked`, state)
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}))
|