2020-05-20 04:50:46 +00:00
|
|
|
/**
|
|
|
|
* Note that it assumes the presence of cssVars.cssRootVars on <body>.
|
|
|
|
*/
|
2023-03-23 04:52:28 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2022-06-17 03:43:26 +00:00
|
|
|
import * as commands from 'app/client/components/commands';
|
2022-07-27 19:02:28 +00:00
|
|
|
import {watchElementForBlur} from 'app/client/lib/FocusLayer';
|
2021-02-08 19:00:02 +00:00
|
|
|
import {urlState} from "app/client/models/gristUrlState";
|
2020-05-20 04:50:46 +00:00
|
|
|
import {resizeFlexVHandle} from 'app/client/ui/resizeHandle';
|
2023-03-23 04:52:28 +00:00
|
|
|
import {hoverTooltip} from 'app/client/ui/tooltips';
|
2022-06-17 03:43:26 +00:00
|
|
|
import {transition, TransitionWatcher} from 'app/client/ui/transitions';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {cssHideForNarrowScreen, isScreenResizing, mediaNotSmall, mediaSmall, theme} from 'app/client/ui2018/cssVars';
|
2021-02-08 19:00:02 +00:00
|
|
|
import {isNarrowScreenObs} from 'app/client/ui2018/cssVars';
|
2020-05-20 04:50:46 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2023-01-03 10:52:25 +00:00
|
|
|
import {
|
|
|
|
dom, DomElementArg, DomElementMethod, MultiHolder, noTestId, Observable, styled, subscribe, TestId
|
|
|
|
} from "grainjs";
|
2022-07-27 19:02:28 +00:00
|
|
|
import noop from 'lodash/noop';
|
|
|
|
import once from 'lodash/once';
|
|
|
|
import {SessionObs} from 'app/client/lib/sessionObs';
|
|
|
|
import debounce from 'lodash/debounce';
|
|
|
|
|
2023-03-23 04:52:28 +00:00
|
|
|
const t = makeT('PagePanels');
|
|
|
|
|
2022-07-27 19:02:28 +00:00
|
|
|
const AUTO_EXPAND_TIMEOUT_MS = 400;
|
|
|
|
|
|
|
|
// delay must be greater than the time needed for transientInput to update focus (ie: 10ms);
|
|
|
|
const DELAY_BEFORE_TESTING_FOCUS_CHANGE_MS = 12;
|
2020-05-20 04:50:46 +00:00
|
|
|
|
|
|
|
export interface PageSidePanel {
|
|
|
|
// Note that widths need to start out with a correct default in JS (having them in CSS is not
|
|
|
|
// enough), needed for open/close transitions.
|
|
|
|
panelWidth: Observable<number>;
|
|
|
|
panelOpen: Observable<boolean>;
|
|
|
|
hideOpener?: boolean; // If true, don't show the opener handle.
|
2022-12-20 02:06:39 +00:00
|
|
|
header: DomElementArg;
|
|
|
|
content: DomElementArg;
|
2020-05-20 04:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface PageContents {
|
|
|
|
leftPanel: PageSidePanel;
|
|
|
|
rightPanel?: PageSidePanel; // If omitted, the right panel isn't shown at all.
|
|
|
|
|
2022-12-20 02:06:39 +00:00
|
|
|
headerMain: DomElementArg;
|
|
|
|
contentMain: DomElementArg;
|
2023-01-03 10:52:25 +00:00
|
|
|
banner?: DomElementArg;
|
2020-05-20 04:50:46 +00:00
|
|
|
|
|
|
|
onResize?: () => void; // Callback for when either pane is opened, closed, or resized.
|
|
|
|
testId?: TestId;
|
2022-12-20 02:06:39 +00:00
|
|
|
contentTop?: DomElementArg;
|
|
|
|
contentBottom?: DomElementArg;
|
2020-05-20 04:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function pagePanels(page: PageContents) {
|
|
|
|
const testId = page.testId || noTestId;
|
|
|
|
const left = page.leftPanel;
|
|
|
|
const right = page.rightPanel;
|
|
|
|
const onResize = page.onResize || (() => null);
|
2022-07-27 19:02:28 +00:00
|
|
|
const leftOverlap = Observable.create(null, false);
|
|
|
|
const dragResizer = Observable.create(null, false);
|
2023-01-03 10:52:25 +00:00
|
|
|
const bannerHeight = Observable.create(null, 0);
|
2022-09-01 08:07:15 +00:00
|
|
|
const isScreenResizingObs = isScreenResizing();
|
2020-05-20 04:50:46 +00:00
|
|
|
|
2021-02-08 19:00:02 +00:00
|
|
|
let lastLeftOpen = left.panelOpen.get();
|
|
|
|
let lastRightOpen = right?.panelOpen.get() || false;
|
2022-06-17 03:43:26 +00:00
|
|
|
let leftPaneDom: HTMLElement;
|
2022-12-20 02:06:39 +00:00
|
|
|
let rightPaneDom: HTMLElement;
|
2023-01-03 10:52:25 +00:00
|
|
|
let mainHeaderDom: HTMLElement;
|
|
|
|
let contentTopDom: HTMLElement;
|
2022-07-27 19:02:28 +00:00
|
|
|
let onLeftTransitionFinish = noop;
|
2021-02-08 19:00:02 +00:00
|
|
|
|
|
|
|
// When switching to mobile mode, close panels; when switching to desktop, restore the
|
|
|
|
// last desktop state.
|
|
|
|
const sub1 = subscribe(isNarrowScreenObs(), (use, narrow) => {
|
|
|
|
if (narrow) {
|
2022-09-01 08:07:15 +00:00
|
|
|
lastLeftOpen = leftOverlap.get() ? false : left.panelOpen.get();
|
2021-02-08 19:00:02 +00:00
|
|
|
lastRightOpen = right?.panelOpen.get() || false;
|
|
|
|
}
|
|
|
|
left.panelOpen.set(narrow ? false : lastLeftOpen);
|
|
|
|
right?.panelOpen.set(narrow ? false : lastRightOpen);
|
2022-09-01 08:07:15 +00:00
|
|
|
|
|
|
|
// overlap should always be OFF when switching screen mode
|
|
|
|
leftOverlap.set(false);
|
2021-02-08 19:00:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// When url changes, we must have navigated; close the left panel since if it were open, it was
|
|
|
|
// the likely cause of the navigation (e.g. switch to another page or workspace).
|
|
|
|
const sub2 = subscribe(isNarrowScreenObs(), urlState().state, (use, narrow, state) => {
|
|
|
|
if (narrow) {
|
|
|
|
left.panelOpen.set(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-07-27 19:02:28 +00:00
|
|
|
const pauseSavingLeft = (yesNo: boolean) => {
|
|
|
|
(left.panelOpen as SessionObs<boolean>)?.pauseSaving?.(yesNo);
|
|
|
|
};
|
|
|
|
|
2022-06-17 03:43:26 +00:00
|
|
|
const commandsGroup = commands.createGroup({
|
|
|
|
leftPanelOpen: () => new Promise((resolve) => {
|
|
|
|
const watcher = new TransitionWatcher(leftPaneDom);
|
|
|
|
watcher.onDispose(() => resolve(undefined));
|
|
|
|
left.panelOpen.set(true);
|
|
|
|
}),
|
2022-12-20 02:06:39 +00:00
|
|
|
rightPanelOpen: () => new Promise((resolve, reject) => {
|
|
|
|
if (!right) {
|
|
|
|
reject(new Error('PagePanels rightPanelOpen called while right panel is undefined'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const watcher = new TransitionWatcher(rightPaneDom);
|
|
|
|
watcher.onDispose(() => resolve(undefined));
|
|
|
|
right.panelOpen.set(true);
|
|
|
|
}),
|
2022-06-17 03:43:26 +00:00
|
|
|
}, null, true);
|
2022-07-27 19:02:28 +00:00
|
|
|
let contentWrapper: HTMLElement;
|
2021-02-08 19:00:02 +00:00
|
|
|
return cssPageContainer(
|
|
|
|
dom.autoDispose(sub1),
|
|
|
|
dom.autoDispose(sub2),
|
2022-06-17 03:43:26 +00:00
|
|
|
dom.autoDispose(commandsGroup),
|
2022-07-27 19:02:28 +00:00
|
|
|
dom.autoDispose(leftOverlap),
|
2023-01-03 10:52:25 +00:00
|
|
|
dom('div', page.contentTop, elem => { contentTopDom = elem; }),
|
|
|
|
dom.maybe(page.banner, () => {
|
|
|
|
let elem: HTMLElement;
|
|
|
|
const updateTop = () => {
|
|
|
|
const height = mainHeaderDom.getBoundingClientRect().bottom;
|
|
|
|
elem.style.top = height + 'px';
|
|
|
|
};
|
|
|
|
setTimeout(() => watchHeightElem(contentTopDom, updateTop));
|
|
|
|
const lis = isScreenResizingObs.addListener(val => val || updateTop());
|
|
|
|
return elem = cssBannerContainer(
|
|
|
|
page.banner,
|
|
|
|
watchHeight(h => bannerHeight.set(h)),
|
|
|
|
dom.autoDispose(lis),
|
|
|
|
);
|
|
|
|
}),
|
2022-04-21 17:57:33 +00:00
|
|
|
cssContentMain(
|
2022-06-17 03:43:26 +00:00
|
|
|
leftPaneDom = cssLeftPane(
|
2022-04-21 17:57:33 +00:00
|
|
|
testId('left-panel'),
|
2022-07-27 19:02:28 +00:00
|
|
|
cssOverflowContainer(
|
|
|
|
contentWrapper = cssLeftPanelContainer(
|
2023-01-03 10:52:25 +00:00
|
|
|
cssLeftPaneHeader(
|
|
|
|
left.header,
|
|
|
|
dom.style('margin-bottom', use => use(bannerHeight) + 'px')
|
|
|
|
),
|
2022-07-27 19:02:28 +00:00
|
|
|
left.content,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
// Show plain border when the resize handle is hidden.
|
|
|
|
cssResizeDisabledBorder(
|
|
|
|
dom.hide((use) => use(left.panelOpen) && !use(leftOverlap)),
|
|
|
|
cssHideForNarrowScreen.cls(''),
|
|
|
|
testId('left-disabled-resizer'),
|
|
|
|
),
|
2020-05-20 04:50:46 +00:00
|
|
|
|
2022-04-21 17:57:33 +00:00
|
|
|
dom.style('width', (use) => use(left.panelOpen) ? use(left.panelWidth) + 'px' : ''),
|
2020-05-20 04:50:46 +00:00
|
|
|
|
2022-04-21 17:57:33 +00:00
|
|
|
// Opening/closing the left pane, with transitions.
|
|
|
|
cssLeftPane.cls('-open', left.panelOpen),
|
|
|
|
transition(use => (use(isNarrowScreenObs()) ? false : use(left.panelOpen)), {
|
2022-07-27 19:02:28 +00:00
|
|
|
prepare(elem, open) {
|
|
|
|
elem.style.width = (open ? 48 : left.panelWidth.get()) + 'px';
|
|
|
|
},
|
|
|
|
run(elem, open) {
|
|
|
|
elem.style.width = contentWrapper.style.width = (open ? left.panelWidth.get() : 48) + 'px';
|
|
|
|
},
|
|
|
|
finish() {
|
|
|
|
onResize();
|
|
|
|
contentWrapper.style.width = '';
|
|
|
|
onLeftTransitionFinish();
|
|
|
|
},
|
2022-04-21 17:57:33 +00:00
|
|
|
}),
|
2022-07-27 19:02:28 +00:00
|
|
|
|
|
|
|
// opening left panel on over
|
2022-09-01 08:07:15 +00:00
|
|
|
dom.on('mouseenter', (evt1, elem) => {
|
|
|
|
|
|
|
|
|
|
|
|
if (left.panelOpen.get()
|
|
|
|
|
|
|
|
// when no opener should not auto-expand
|
|
|
|
|| left.hideOpener
|
|
|
|
|
|
|
|
// if user is resizing the window, don't expand.
|
|
|
|
|| isScreenResizingObs.get()) { return; }
|
|
|
|
|
|
|
|
|
2022-07-27 19:02:28 +00:00
|
|
|
|
|
|
|
let isMouseInsideLeftPane = true;
|
|
|
|
let isFocusInsideLeftPane = false;
|
|
|
|
let isMouseDragging = false;
|
|
|
|
|
|
|
|
const owner = new MultiHolder();
|
|
|
|
const startExpansion = () => {
|
|
|
|
leftOverlap.set(true);
|
|
|
|
pauseSavingLeft(true); // prevents from updating state in the window storage
|
|
|
|
left.panelOpen.set(true);
|
|
|
|
onLeftTransitionFinish = noop;
|
|
|
|
watchBlur();
|
|
|
|
};
|
|
|
|
const startCollapse = () => {
|
|
|
|
left.panelOpen.set(false);
|
|
|
|
pauseSavingLeft(false);
|
|
|
|
// turns overlap off only when the transition finishes
|
|
|
|
onLeftTransitionFinish = once(() => leftOverlap.set(false));
|
|
|
|
clear();
|
|
|
|
};
|
|
|
|
const clear = () => {
|
|
|
|
if (owner.isDisposed()) { return; }
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
owner.dispose();
|
|
|
|
};
|
|
|
|
dom.onDisposeElem(elem, clear);
|
|
|
|
|
|
|
|
// updates isFocusInsideLeftPane and starts watch for blur on activeElement.
|
|
|
|
const watchBlur = debounce(() => {
|
|
|
|
if (owner.isDisposed()) { return; }
|
|
|
|
isFocusInsideLeftPane = Boolean(leftPaneDom.contains(document.activeElement) ||
|
|
|
|
document.activeElement?.closest('.grist-floating-menu'));
|
|
|
|
maybeStartCollapse();
|
|
|
|
if (document.activeElement) {
|
|
|
|
maybePatchDomAndChangeFocus(); // This is to support projects test environment
|
|
|
|
watchElementForBlur(document.activeElement, watchBlur);
|
|
|
|
}
|
|
|
|
}, DELAY_BEFORE_TESTING_FOCUS_CHANGE_MS);
|
|
|
|
|
|
|
|
// starts collapsed only if neither mouse nor focus are inside the left pane. Return true
|
|
|
|
// if started collapsed, false otherwise.
|
|
|
|
const maybeStartCollapse = () => {
|
|
|
|
if (!isMouseInsideLeftPane && !isFocusInsideLeftPane && !isMouseDragging) {
|
|
|
|
startCollapse();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// mouse events
|
|
|
|
const onMouseEvt = (evt: MouseEvent) => {
|
|
|
|
const rect = leftPaneDom.getBoundingClientRect();
|
|
|
|
isMouseInsideLeftPane = evt.clientX <= rect.right;
|
|
|
|
isMouseDragging = evt.buttons !== 0;
|
|
|
|
maybeStartCollapse();
|
|
|
|
};
|
|
|
|
owner.autoDispose(dom.onElem(document, 'mousemove', onMouseEvt));
|
|
|
|
owner.autoDispose(dom.onElem(document, 'mouseup', onMouseEvt));
|
|
|
|
|
2022-09-01 08:07:15 +00:00
|
|
|
// Enables collapsing when the cursor leaves the window. This comes handy in a split
|
|
|
|
// screen setup, especially when Grist is on the right side: moving the cursor back and
|
|
|
|
// forth between the 2 windows, the cursor is likely to hover the left pane and expand it
|
|
|
|
// inadvertendly. This line collapses it back.
|
|
|
|
const onMouseLeave = () => {
|
|
|
|
isMouseInsideLeftPane = false;
|
|
|
|
maybeStartCollapse();
|
|
|
|
};
|
|
|
|
owner.autoDispose(dom.onElem(document.body, 'mouseleave', onMouseLeave));
|
|
|
|
|
2022-07-27 19:02:28 +00:00
|
|
|
// schedule start of expansion
|
|
|
|
const timeoutId = setTimeout(startExpansion, AUTO_EXPAND_TIMEOUT_MS);
|
|
|
|
}),
|
|
|
|
cssLeftPane.cls('-overlap', leftOverlap),
|
|
|
|
cssLeftPane.cls('-dragging', dragResizer),
|
2020-05-20 04:50:46 +00:00
|
|
|
),
|
2022-04-21 17:57:33 +00:00
|
|
|
|
|
|
|
// Resizer for the left pane.
|
|
|
|
// TODO: resizing to small size should collapse. possibly should allow expanding too
|
2020-05-20 04:50:46 +00:00
|
|
|
cssResizeFlexVHandle(
|
2022-07-27 19:02:28 +00:00
|
|
|
{target: 'left', onSave: (val) => { left.panelWidth.set(val); onResize();
|
|
|
|
leftPaneDom.style['width'] = val + 'px';
|
|
|
|
setTimeout(() => dragResizer.set(false), 0); },
|
|
|
|
onDrag: (val) => { dragResizer.set(true); }},
|
2022-04-21 17:57:33 +00:00
|
|
|
testId('left-resizer'),
|
2022-07-27 19:02:28 +00:00
|
|
|
dom.show((use) => use(left.panelOpen) && !use(leftOverlap)),
|
2022-04-21 17:57:33 +00:00
|
|
|
cssHideForNarrowScreen.cls('')),
|
2020-05-20 04:50:46 +00:00
|
|
|
|
2022-04-21 17:57:33 +00:00
|
|
|
cssMainPane(
|
2023-01-03 10:52:25 +00:00
|
|
|
mainHeaderDom = cssTopHeader(
|
2022-04-21 17:57:33 +00:00
|
|
|
testId('top-header'),
|
|
|
|
(left.hideOpener ? null :
|
|
|
|
cssPanelOpener('PanelRight', cssPanelOpener.cls('-open', left.panelOpen),
|
|
|
|
testId('left-opener'),
|
|
|
|
dom.on('click', () => toggleObs(left.panelOpen)),
|
|
|
|
cssHideForNarrowScreen.cls(''))
|
|
|
|
),
|
2020-05-20 04:50:46 +00:00
|
|
|
|
2022-04-21 17:57:33 +00:00
|
|
|
page.headerMain,
|
|
|
|
|
|
|
|
(!right || right.hideOpener ? null :
|
|
|
|
cssPanelOpener('PanelLeft', cssPanelOpener.cls('-open', right.panelOpen),
|
|
|
|
testId('right-opener'),
|
|
|
|
dom.cls('tour-creator-panel'),
|
2023-03-23 04:52:28 +00:00
|
|
|
hoverTooltip(() => (right.panelOpen.get() ? t('Close Creator Panel') : t('Open Creator Panel')),
|
|
|
|
{key: 'topBarBtnTooltip'}),
|
2022-04-21 17:57:33 +00:00
|
|
|
dom.on('click', () => toggleObs(right.panelOpen)),
|
|
|
|
cssHideForNarrowScreen.cls(''))
|
2021-01-21 19:12:24 +00:00
|
|
|
),
|
2023-01-03 10:52:25 +00:00
|
|
|
dom.style('margin-bottom', use => use(bannerHeight) + 'px'),
|
2021-01-12 15:11:28 +00:00
|
|
|
),
|
2022-04-21 17:57:33 +00:00
|
|
|
page.contentMain,
|
2022-07-27 19:02:28 +00:00
|
|
|
cssMainPane.cls('-left-overlap', leftOverlap),
|
2022-04-21 17:57:33 +00:00
|
|
|
testId('main-pane'),
|
|
|
|
),
|
|
|
|
(right ? [
|
|
|
|
// Resizer for the right pane.
|
|
|
|
cssResizeFlexVHandle(
|
|
|
|
{target: 'right', onSave: (val) => { right.panelWidth.set(val); onResize(); }},
|
|
|
|
testId('right-resizer'),
|
|
|
|
dom.show(right.panelOpen),
|
|
|
|
cssHideForNarrowScreen.cls('')),
|
|
|
|
|
2022-12-20 02:06:39 +00:00
|
|
|
rightPaneDom = cssRightPane(
|
2022-04-21 17:57:33 +00:00
|
|
|
testId('right-panel'),
|
2023-01-03 10:52:25 +00:00
|
|
|
cssRightPaneHeader(
|
|
|
|
right.header,
|
|
|
|
dom.style('margin-bottom', use => use(bannerHeight) + 'px')
|
|
|
|
),
|
2022-04-21 17:57:33 +00:00
|
|
|
right.content,
|
|
|
|
|
|
|
|
dom.style('width', (use) => use(right.panelOpen) ? use(right.panelWidth) + 'px' : ''),
|
|
|
|
|
|
|
|
// Opening/closing the right pane, with transitions.
|
|
|
|
cssRightPane.cls('-open', right.panelOpen),
|
|
|
|
transition(use => (use(isNarrowScreenObs()) ? false : use(right.panelOpen)), {
|
|
|
|
prepare(elem, open) { elem.style.marginLeft = (open ? -1 : 1) * right.panelWidth.get() + 'px'; },
|
|
|
|
run(elem, open) { elem.style.marginLeft = ''; },
|
|
|
|
finish: onResize,
|
|
|
|
}),
|
|
|
|
)] : null
|
|
|
|
),
|
|
|
|
cssContentOverlay(
|
|
|
|
dom.show((use) => use(left.panelOpen) || Boolean(right && use(right.panelOpen))),
|
|
|
|
dom.on('click', () => {
|
|
|
|
left.panelOpen.set(false);
|
|
|
|
if (right) { right.panelOpen.set(false); }
|
|
|
|
}),
|
|
|
|
testId('overlay')
|
|
|
|
),
|
|
|
|
dom.maybe(isNarrowScreenObs(), () =>
|
|
|
|
cssBottomFooter(
|
|
|
|
testId('bottom-footer'),
|
2021-01-21 19:12:24 +00:00
|
|
|
cssPanelOpenerNarrowScreenBtn(
|
|
|
|
cssPanelOpenerNarrowScreen(
|
2022-04-21 17:57:33 +00:00
|
|
|
'FieldTextbox',
|
2021-01-21 19:12:24 +00:00
|
|
|
dom.on('click', () => {
|
2022-04-21 17:57:33 +00:00
|
|
|
right?.panelOpen.set(false);
|
|
|
|
toggleObs(left.panelOpen);
|
2021-01-21 19:12:24 +00:00
|
|
|
}),
|
2022-04-21 17:57:33 +00:00
|
|
|
testId('left-opener-ns')
|
2021-01-21 19:12:24 +00:00
|
|
|
),
|
2022-04-21 17:57:33 +00:00
|
|
|
cssPanelOpenerNarrowScreenBtn.cls('-open', left.panelOpen)
|
|
|
|
),
|
|
|
|
page.contentBottom,
|
|
|
|
(!right ? null :
|
|
|
|
cssPanelOpenerNarrowScreenBtn(
|
|
|
|
cssPanelOpenerNarrowScreen(
|
|
|
|
'Settings',
|
|
|
|
dom.on('click', () => {
|
|
|
|
left.panelOpen.set(false);
|
|
|
|
toggleObs(right.panelOpen);
|
|
|
|
}),
|
|
|
|
testId('right-opener-ns')
|
|
|
|
),
|
|
|
|
cssPanelOpenerNarrowScreenBtn.cls('-open', right.panelOpen),
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
),
|
2021-02-08 19:00:02 +00:00
|
|
|
),
|
|
|
|
);
|
2020-05-20 04:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function toggleObs(boolObs: Observable<boolean>) {
|
|
|
|
boolObs.set(!boolObs.get());
|
|
|
|
}
|
|
|
|
|
2022-06-17 03:43:26 +00:00
|
|
|
const bottomFooterHeightPx = 48;
|
2020-05-20 04:50:46 +00:00
|
|
|
const cssVBox = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
`);
|
|
|
|
const cssHBox = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
`);
|
2022-04-21 17:57:33 +00:00
|
|
|
const cssPageContainer = styled(cssVBox, `
|
2020-05-20 04:50:46 +00:00
|
|
|
position: absolute;
|
|
|
|
isolation: isolate; /* Create a new stacking context */
|
|
|
|
z-index: 0; /* As of March 2019, isolation does not have Edge support, so force one with z-index */
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
2021-01-12 15:11:28 +00:00
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
2021-01-21 19:12:24 +00:00
|
|
|
min-width: 600px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.pageBg};
|
2021-01-12 15:11:28 +00:00
|
|
|
|
2021-01-21 19:12:24 +00:00
|
|
|
@media ${mediaSmall} {
|
2021-02-08 19:00:02 +00:00
|
|
|
& {
|
2022-06-17 03:43:26 +00:00
|
|
|
padding-bottom: ${bottomFooterHeightPx}px;
|
2021-01-21 19:12:24 +00:00
|
|
|
min-width: 240px;
|
2021-01-12 15:11:28 +00:00
|
|
|
}
|
2023-08-15 17:29:29 +00:00
|
|
|
.interface-singlePage & {
|
2021-02-08 19:00:02 +00:00
|
|
|
padding-bottom: 0;
|
2021-02-04 06:49:01 +00:00
|
|
|
}
|
2021-01-12 15:11:28 +00:00
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
2022-04-21 17:57:33 +00:00
|
|
|
const cssContentMain = styled(cssHBox, `
|
|
|
|
flex: 1 1 0px;
|
|
|
|
overflow: hidden;
|
|
|
|
`);
|
2020-05-20 04:50:46 +00:00
|
|
|
export const cssLeftPane = styled(cssVBox, `
|
|
|
|
position: relative;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.leftPanelBg};
|
2020-05-20 04:50:46 +00:00
|
|
|
width: 48px;
|
|
|
|
margin-right: 0px;
|
2022-07-27 19:02:28 +00:00
|
|
|
transition: width 0.4s;
|
|
|
|
will-change: width;
|
2021-01-21 19:12:24 +00:00
|
|
|
@media ${mediaSmall} {
|
2021-02-08 19:00:02 +00:00
|
|
|
& {
|
2021-01-25 13:09:09 +00:00
|
|
|
width: 240px;
|
2021-01-26 14:54:59 +00:00
|
|
|
position: fixed;
|
2021-01-12 15:11:28 +00:00
|
|
|
z-index: 10;
|
|
|
|
top: 0;
|
2022-06-17 03:43:26 +00:00
|
|
|
bottom: ${bottomFooterHeightPx}px;
|
2021-01-25 13:09:09 +00:00
|
|
|
left: -${240 + 15}px; /* adds an extra 15 pixels to also hide the box shadow */
|
2021-01-26 14:54:59 +00:00
|
|
|
visibility: hidden;
|
2021-01-12 15:11:28 +00:00
|
|
|
box-shadow: 10px 0 5px rgba(0, 0, 0, 0.2);
|
2021-01-26 14:54:59 +00:00
|
|
|
transition: left 0.4s, visibility 0.4s;
|
|
|
|
will-change: left;
|
2021-01-25 13:09:09 +00:00
|
|
|
}
|
2021-02-08 19:00:02 +00:00
|
|
|
&-open {
|
2021-01-25 13:09:09 +00:00
|
|
|
left: 0;
|
2021-01-26 14:54:59 +00:00
|
|
|
visibility: visible;
|
2021-01-12 15:11:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
&-open {
|
|
|
|
width: 240px;
|
|
|
|
}
|
2020-08-07 21:53:53 +00:00
|
|
|
@media print {
|
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2023-08-15 17:29:29 +00:00
|
|
|
.interface-singlePage & {
|
2020-08-14 16:40:39 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2022-07-27 19:02:28 +00:00
|
|
|
&-overlap {
|
|
|
|
position: fixed;
|
|
|
|
z-index: 10;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
min-width: unset;
|
|
|
|
}
|
|
|
|
&-dragging {
|
|
|
|
transition: unset;
|
|
|
|
min-width: 160px;
|
|
|
|
max-width: 320px;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
const cssOverflowContainer = styled(cssVBox, `
|
|
|
|
overflow: hidden;
|
|
|
|
flex: 1 1 0px;
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
|
|
|
const cssMainPane = styled(cssVBox, `
|
|
|
|
position: relative;
|
|
|
|
flex: 1 1 0px;
|
|
|
|
min-width: 0px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.mainPanelBg};
|
2020-05-20 04:50:46 +00:00
|
|
|
z-index: 1;
|
2022-07-27 19:02:28 +00:00
|
|
|
&-left-overlap {
|
|
|
|
margin-left: 48px;
|
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
|
|
|
const cssRightPane = styled(cssVBox, `
|
|
|
|
position: relative;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.rightPanelBg};
|
2020-05-20 04:50:46 +00:00
|
|
|
width: 0px;
|
|
|
|
margin-left: 0px;
|
|
|
|
overflow: hidden;
|
|
|
|
transition: margin-left 0.4s;
|
|
|
|
z-index: 0;
|
2021-01-21 19:12:24 +00:00
|
|
|
@media ${mediaSmall} {
|
2021-02-08 19:00:02 +00:00
|
|
|
& {
|
2021-01-25 13:09:09 +00:00
|
|
|
width: 240px;
|
2021-01-26 14:54:59 +00:00
|
|
|
position: fixed;
|
2021-01-12 15:11:28 +00:00
|
|
|
z-index: 10;
|
|
|
|
top: 0;
|
2022-06-17 03:43:26 +00:00
|
|
|
bottom: ${bottomFooterHeightPx}px;
|
2021-01-25 13:09:09 +00:00
|
|
|
right: -${240 + 15}px; /* adds an extra 15 pixels to also hide the box shadow */
|
2021-01-12 15:11:28 +00:00
|
|
|
box-shadow: -10px 0 5px rgba(0, 0, 0, 0.2);
|
2021-01-26 14:54:59 +00:00
|
|
|
visibility: hidden;
|
|
|
|
transition: right 0.4s, visibility 0.4s;
|
|
|
|
will-change: right;
|
2021-01-25 13:09:09 +00:00
|
|
|
}
|
2021-02-08 19:00:02 +00:00
|
|
|
&-open {
|
2021-01-25 13:09:09 +00:00
|
|
|
right: 0;
|
2021-01-26 14:54:59 +00:00
|
|
|
visibility: visible;
|
2021-01-12 15:11:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
&-open {
|
|
|
|
width: 240px;
|
|
|
|
min-width: 240px;
|
|
|
|
max-width: 320px;
|
|
|
|
}
|
2020-08-07 21:53:53 +00:00
|
|
|
@media print {
|
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2023-08-15 17:29:29 +00:00
|
|
|
.interface-singlePage & {
|
2020-08-14 16:40:39 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
2022-09-06 01:51:57 +00:00
|
|
|
const cssHeader = styled('div', `
|
|
|
|
height: 49px;
|
2020-05-20 04:50:46 +00:00
|
|
|
flex: none;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
2022-09-06 01:51:57 +00:00
|
|
|
border-bottom: 1px solid ${theme.pagePanelsBorder};
|
2020-08-07 21:53:53 +00:00
|
|
|
|
|
|
|
@media print {
|
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2020-08-14 16:40:39 +00:00
|
|
|
|
2023-08-15 17:29:29 +00:00
|
|
|
.interface-singlePage & {
|
2020-08-14 16:40:39 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
2022-09-06 01:51:57 +00:00
|
|
|
const cssTopHeader = styled(cssHeader, `
|
|
|
|
background-color: ${theme.topHeaderBg};
|
|
|
|
`);
|
|
|
|
const cssLeftPaneHeader = styled(cssHeader, `
|
|
|
|
background-color: ${theme.leftPanelBg};
|
|
|
|
`);
|
|
|
|
const cssRightPaneHeader = styled(cssHeader, `
|
|
|
|
background-color: ${theme.rightPanelBg};
|
|
|
|
`);
|
2021-01-12 15:11:28 +00:00
|
|
|
const cssBottomFooter = styled ('div', `
|
2022-06-17 03:43:26 +00:00
|
|
|
height: ${bottomFooterHeightPx}px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.bottomFooterBg};
|
2021-01-12 15:11:28 +00:00
|
|
|
z-index: 20;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2021-01-14 11:20:13 +00:00
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
2021-01-12 15:11:28 +00:00
|
|
|
padding: 8px 16px;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
2022-09-06 01:51:57 +00:00
|
|
|
border-top: 1px solid ${theme.pagePanelsBorder};
|
2021-01-21 19:12:24 +00:00
|
|
|
@media ${mediaNotSmall} {
|
2021-01-12 15:11:28 +00:00
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 06:49:01 +00:00
|
|
|
@media print {
|
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2023-08-15 17:29:29 +00:00
|
|
|
.interface-singlePage & {
|
2021-02-04 06:49:01 +00:00
|
|
|
display: none;
|
|
|
|
}
|
2021-01-12 15:11:28 +00:00
|
|
|
`);
|
2020-05-20 04:50:46 +00:00
|
|
|
const cssResizeFlexVHandle = styled(resizeFlexVHandle, `
|
2022-09-06 01:51:57 +00:00
|
|
|
--resize-handle-color: ${theme.pagePanelsBorder};
|
|
|
|
--resize-handle-highlight: ${theme.pagePanelsBorderResizing};
|
2020-10-09 21:39:13 +00:00
|
|
|
|
|
|
|
@media print {
|
|
|
|
& {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
|
|
|
const cssResizeDisabledBorder = styled('div', `
|
|
|
|
flex: none;
|
|
|
|
width: 1px;
|
|
|
|
height: 100%;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.pagePanelsBorder};
|
2022-07-27 19:02:28 +00:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
right: -1px;
|
|
|
|
z-index: 2;
|
2020-05-20 04:50:46 +00:00
|
|
|
`);
|
|
|
|
const cssPanelOpener = styled(icon, `
|
|
|
|
flex: none;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
padding: 8px 8px;
|
|
|
|
cursor: pointer;
|
|
|
|
-webkit-mask-size: 16px 16px;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlFg};
|
2020-05-20 04:50:46 +00:00
|
|
|
transition: transform 0.4s;
|
2022-09-06 01:51:57 +00:00
|
|
|
&:hover { background-color: ${theme.controlHoverFg}; }
|
2020-05-20 04:50:46 +00:00
|
|
|
&-open { transform: rotateY(180deg); }
|
|
|
|
`);
|
2021-01-12 15:11:28 +00:00
|
|
|
const cssPanelOpenerNarrowScreenBtn = styled('div', `
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
2022-09-06 01:51:57 +00:00
|
|
|
--icon-color: ${theme.sidePanelOpenerFg};
|
2021-01-12 15:11:28 +00:00
|
|
|
cursor: pointer;
|
|
|
|
border-radius: 4px;
|
|
|
|
&-open {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.sidePanelOpenerActiveBg};
|
|
|
|
--icon-color: ${theme.sidePanelOpenerActiveFg};
|
2021-01-12 15:11:28 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
const cssPanelOpenerNarrowScreen = styled(icon, `
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
margin: 4px;
|
|
|
|
`);
|
|
|
|
const cssContentOverlay = styled('div', `
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
bottom: 0;
|
|
|
|
right: 0;
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.pageBackdrop};
|
2021-01-12 15:11:28 +00:00
|
|
|
opacity: 0.5;
|
|
|
|
display: none;
|
|
|
|
z-index: 9;
|
2021-01-21 19:12:24 +00:00
|
|
|
@media ${mediaSmall} {
|
2021-02-08 19:00:02 +00:00
|
|
|
& {
|
2021-01-12 15:11:28 +00:00
|
|
|
display: unset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
2022-07-27 19:02:28 +00:00
|
|
|
const cssLeftPanelContainer = styled('div', `
|
|
|
|
flex: 1 1 0px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
`);
|
|
|
|
const cssHiddenInput = styled('input', `
|
|
|
|
position: absolute;
|
|
|
|
top: -100px;
|
|
|
|
left: 0;
|
|
|
|
width: 10px;
|
|
|
|
height: 10px;
|
|
|
|
font-size: 1;
|
|
|
|
z-index: -1;
|
|
|
|
`);
|
2023-01-03 10:52:25 +00:00
|
|
|
const cssBannerContainer = styled('div', `
|
|
|
|
position: absolute;
|
|
|
|
z-index: 11;
|
|
|
|
width: 100%;
|
|
|
|
`);
|
2022-07-27 19:02:28 +00:00
|
|
|
// watchElementForBlur does not work if focus is on body. Which never happens when running in Grist
|
|
|
|
// because focus is constantly given to the copypasteField. But it does happen when running inside a
|
|
|
|
// projects test. For that latter case we had a hidden <input> field to the dom and give it focus.
|
|
|
|
function maybePatchDomAndChangeFocus() {
|
|
|
|
if (document.activeElement?.matches('body')) {
|
|
|
|
const hiddenInput = cssHiddenInput();
|
|
|
|
document.body.appendChild(hiddenInput);
|
|
|
|
hiddenInput.focus();
|
|
|
|
}
|
|
|
|
}
|
2023-01-03 10:52:25 +00:00
|
|
|
// Watch for changes in dom subtree and call callback with element height;
|
|
|
|
function watchHeight(callback: (height: number) => void): DomElementMethod {
|
|
|
|
return elem => watchHeightElem(elem, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
function watchHeightElem(elem: HTMLElement, callback: (height: number) => void) {
|
|
|
|
const onChange = () => callback(elem.getBoundingClientRect().height);
|
|
|
|
const observer = new MutationObserver(onChange);
|
|
|
|
observer.observe(elem, {childList: true, subtree: true, attributes: true});
|
|
|
|
dom.onDisposeElem(elem, () => observer.disconnect());
|
|
|
|
onChange();
|
|
|
|
}
|