2022-07-04 14:14:55 +00:00
|
|
|
import BaseView from 'app/client/components/BaseView';
|
2023-08-29 14:50:42 +00:00
|
|
|
import {buildViewSectionDom} from 'app/client/components/buildViewSectionDom';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {ChartView} from 'app/client/components/ChartView';
|
|
|
|
import * as commands from 'app/client/components/commands';
|
2023-08-29 14:50:42 +00:00
|
|
|
import {CustomCalendarView} from "app/client/components/CustomCalendarView";
|
2020-10-02 15:10:00 +00:00
|
|
|
import {CustomView} from 'app/client/components/CustomView';
|
|
|
|
import * as DetailView from 'app/client/components/DetailView';
|
2023-12-12 09:58:20 +00:00
|
|
|
import {FormView} from 'app/client/components/Forms/FormView';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as GridView from 'app/client/components/GridView';
|
|
|
|
import {GristDoc} from 'app/client/components/GristDoc';
|
2023-02-24 11:12:55 +00:00
|
|
|
import {BoxSpec, Layout} from 'app/client/components/Layout';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {LayoutEditor} from 'app/client/components/LayoutEditor';
|
2023-08-29 14:50:42 +00:00
|
|
|
import {LayoutTray} from 'app/client/components/LayoutTray';
|
2020-10-09 21:39:13 +00:00
|
|
|
import {printViewSection} from 'app/client/components/Printing';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {Delay} from 'app/client/lib/Delay';
|
|
|
|
import {createObsArray} from 'app/client/lib/koArrayWrap';
|
|
|
|
import {ViewRec, ViewSectionRec} from 'app/client/models/DocModel';
|
|
|
|
import {reportError} from 'app/client/models/errors';
|
2023-02-24 11:12:55 +00:00
|
|
|
import {isNarrowScreen, mediaSmall, testId, theme} from 'app/client/ui2018/cssVars';
|
2022-04-27 17:46:24 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {DisposableWithEvents} from 'app/common/DisposableWithEvents';
|
|
|
|
import {mod} from 'app/common/gutil';
|
2023-08-29 14:50:42 +00:00
|
|
|
import {
|
|
|
|
Computed,
|
|
|
|
computedArray,
|
|
|
|
Disposable,
|
|
|
|
dom,
|
|
|
|
fromKo,
|
|
|
|
Holder,
|
|
|
|
IDomComponent,
|
|
|
|
MultiHolder,
|
|
|
|
Observable,
|
|
|
|
styled,
|
|
|
|
subscribe
|
|
|
|
} from 'grainjs';
|
2020-10-02 15:10:00 +00:00
|
|
|
import * as ko from 'knockout';
|
2023-01-04 16:37:32 +00:00
|
|
|
import debounce from 'lodash/debounce';
|
2023-08-29 14:50:42 +00:00
|
|
|
import * as _ from 'underscore';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// tslint:disable:no-console
|
|
|
|
|
|
|
|
const viewSectionTypes: {[key: string]: any} = {
|
|
|
|
record: GridView,
|
|
|
|
detail: DetailView,
|
|
|
|
chart: ChartView,
|
|
|
|
single: DetailView,
|
|
|
|
custom: CustomView,
|
2023-12-12 09:58:20 +00:00
|
|
|
form: FormView,
|
2023-08-29 14:50:42 +00:00
|
|
|
'custom.calendar': CustomCalendarView,
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function getInstanceConstructor(parentKey: string) {
|
|
|
|
const Cons = viewSectionTypes[parentKey];
|
|
|
|
if (!Cons) {
|
|
|
|
console.error('ViewLayout error: requested an unsupported section type:', parentKey);
|
|
|
|
}
|
|
|
|
// Default to GridView if no valid constructor
|
|
|
|
return Cons || viewSectionTypes.record;
|
|
|
|
}
|
|
|
|
|
2022-02-07 14:02:26 +00:00
|
|
|
export class ViewSectionHelper extends Disposable {
|
2020-10-02 15:10:00 +00:00
|
|
|
private _instance = Holder.create<BaseView>(this);
|
|
|
|
|
|
|
|
constructor(gristDoc: GristDoc, vs: ViewSectionRec) {
|
|
|
|
super();
|
|
|
|
this.onDispose(() => vs.viewInstance(null));
|
|
|
|
|
|
|
|
this.autoDispose(subscribe((use) => {
|
|
|
|
// Rebuild the section when its type changes or its underlying table.
|
|
|
|
const table = use(vs.table);
|
|
|
|
const Cons = getInstanceConstructor(use(vs.parentKey));
|
|
|
|
this._instance.clear();
|
|
|
|
if (table.getRowId()) {
|
|
|
|
this._instance.autoDispose(Cons.create(gristDoc, vs));
|
|
|
|
}
|
|
|
|
vs.viewInstance(this._instance.get());
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ViewLayout - Handles layout for a single page.
|
|
|
|
*/
|
|
|
|
export class ViewLayout extends DisposableWithEvents implements IDomComponent {
|
|
|
|
public docModel = this.gristDoc.docModel;
|
|
|
|
public viewModel: ViewRec;
|
2023-02-24 11:12:55 +00:00
|
|
|
public layoutSpec: ko.Computed<BoxSpec>;
|
2023-01-18 19:33:45 +00:00
|
|
|
public maximized: Observable<number|null>;
|
2023-02-24 11:12:55 +00:00
|
|
|
public isResizing = Observable.create(this, false);
|
|
|
|
public layout: Layout;
|
|
|
|
public layoutEditor: LayoutEditor;
|
|
|
|
public layoutTray: LayoutTray;
|
|
|
|
public layoutSaveDelay = this.autoDispose(new Delay());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
private _freeze = false;
|
2023-02-24 11:12:55 +00:00
|
|
|
// Exposed for test to indicate that save has not yet been called.
|
|
|
|
private _savePending = Observable.create(this, false);
|
2020-10-02 15:10:00 +00:00
|
|
|
constructor(public readonly gristDoc: GristDoc, viewId: number) {
|
|
|
|
super();
|
|
|
|
this.viewModel = this.docModel.views.getRowModel(viewId);
|
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// A Map from viewSection RowModels to corresponding View class instances.
|
|
|
|
// TODO add a test that creating / deleting a section creates/destroys one instance, and
|
|
|
|
// switching pages destroys all instances.
|
|
|
|
const viewSectionObs = createObsArray(this, this.viewModel.viewSections());
|
|
|
|
this.autoDispose(computedArray(viewSectionObs, (vs, i, compArr) =>
|
|
|
|
ViewSectionHelper.create(compArr, gristDoc, vs)));
|
|
|
|
|
|
|
|
// Update the stored layoutSpecObj with any missing fields that are present in viewFields.
|
|
|
|
this.layoutSpec = this.autoDispose(ko.computed(
|
|
|
|
() => this._updateLayoutSpecWithSections(this.viewModel.layoutSpecObj()))
|
|
|
|
.extend({rateLimit: 0}));
|
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
this.layout = this.autoDispose(Layout.create(this.layoutSpec(),
|
2020-10-02 15:10:00 +00:00
|
|
|
this._buildLeafContent.bind(this), true));
|
2023-02-24 11:12:55 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// When the layoutSpec changes by some means other than the layout editor, rebuild.
|
|
|
|
// This includes adding/removing sections and undo/redo.
|
2023-02-24 11:12:55 +00:00
|
|
|
this.autoDispose(this.layoutSpec.subscribe((spec) => this._freeze || this.rebuildLayout(spec)));
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
this.listenTo(this.layout, 'layoutUserEditStop', () => {
|
|
|
|
this.isResizing.set(false);
|
|
|
|
this.layoutSaveDelay.schedule(1000, () => {
|
|
|
|
this.saveLayoutSpec();
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Do not save if the user has started editing again.
|
2023-02-24 11:12:55 +00:00
|
|
|
this.listenTo(this.layout, 'layoutUserEditStart', () => {
|
|
|
|
this.layoutSaveDelay.cancel();
|
|
|
|
this._savePending.set(true);
|
|
|
|
this.isResizing.set(true);
|
2021-03-05 03:35:53 +00:00
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
this.layoutEditor = this.autoDispose(LayoutEditor.create(this.layout));
|
|
|
|
this.layoutTray = LayoutTray.create(this, this);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Add disposal of this._layout after layoutEditor, so that it gets disposed first, and
|
|
|
|
// layoutEditor doesn't attempt to update it in its own disposal logic.
|
2023-02-24 11:12:55 +00:00
|
|
|
this.onDispose(() => this.layout.dispose());
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
this.autoDispose(this.gristDoc.resizeEmitter.addListener(this._onResize, this));
|
|
|
|
|
|
|
|
// It's hard to detect a click or mousedown on a third-party iframe
|
|
|
|
// (See https://stackoverflow.com/questions/2381336/detect-click-into-iframe-using-javascript).
|
|
|
|
this.listenTo(this.gristDoc.app, 'clipboard_blur', this._maybeFocusInSection);
|
|
|
|
|
2023-01-04 16:37:32 +00:00
|
|
|
// On narrow screens (e.g. mobile), we need to resize the section after a transition.
|
|
|
|
// There will two transition events (one from section one from row), so we debounce them after a tick.
|
|
|
|
const handler = debounce((e: TransitionEvent) => {
|
|
|
|
// We work only on the transition of the flex-grow property, and only on narrow screens.
|
|
|
|
if (e.propertyName !== 'flex-grow' || !isNarrowScreen()) { return; }
|
|
|
|
// Make sure the view is still active.
|
|
|
|
if (this.viewModel.isDisposed() || !this.viewModel.activeSection) { return; }
|
|
|
|
const section = this.viewModel.activeSection.peek();
|
|
|
|
if (!section || section.isDisposed()) { return; }
|
|
|
|
const view = section.viewInstance.peek();
|
|
|
|
if (!view || view.isDisposed()) { return; }
|
|
|
|
// Make resize.
|
|
|
|
view.onResize();
|
|
|
|
}, 0);
|
2023-02-24 11:12:55 +00:00
|
|
|
this.layout.rootElem.addEventListener('transitionend', handler);
|
2023-01-04 16:37:32 +00:00
|
|
|
// Don't need to dispose the listener, as the rootElem is disposed with the layout.
|
|
|
|
|
2021-02-09 04:40:04 +00:00
|
|
|
const classActive = cssLayoutBox.className + '-active';
|
|
|
|
const classInactive = cssLayoutBox.className + '-inactive';
|
2021-02-09 23:38:05 +00:00
|
|
|
this.autoDispose(subscribe(fromKo(this.viewModel.activeSection), (use, section) => {
|
|
|
|
const id = section.getRowId();
|
2023-02-24 11:12:55 +00:00
|
|
|
this.layout.forEachBox(box => {
|
2023-01-18 19:33:45 +00:00
|
|
|
box.dom!.classList.add(classInactive);
|
|
|
|
box.dom!.classList.remove(classActive);
|
|
|
|
box.dom!.classList.remove("transition");
|
2021-02-09 04:40:04 +00:00
|
|
|
});
|
2023-02-24 11:12:55 +00:00
|
|
|
let elem: Element|null = this.layout.getLeafBox(id)?.dom || null;
|
2021-02-09 04:40:04 +00:00
|
|
|
while (elem?.matches('.layout_box')) {
|
|
|
|
elem.classList.remove(classInactive);
|
|
|
|
elem.classList.add(classActive);
|
|
|
|
elem = elem.parentElement;
|
|
|
|
}
|
2023-01-04 16:37:32 +00:00
|
|
|
if (!isNarrowScreen()) {
|
|
|
|
section.viewInstance.peek()?.onResize();
|
|
|
|
}
|
2021-02-09 04:40:04 +00:00
|
|
|
}));
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
const commandGroup = {
|
2023-02-24 11:12:55 +00:00
|
|
|
deleteSection: () => { this.removeViewSection(this.viewModel.activeSectionId()); },
|
2020-10-02 15:10:00 +00:00
|
|
|
nextSection: () => { this._otherSection(+1); },
|
|
|
|
prevSection: () => { this._otherSection(-1); },
|
2023-02-24 11:12:55 +00:00
|
|
|
printSection: () => { printViewSection(this.layout, this.viewModel.activeSection()).catch(reportError); },
|
2022-11-17 20:17:51 +00:00
|
|
|
sortFilterMenuOpen: (sectionId?: number) => { this._openSortFilterMenu(sectionId); },
|
2024-01-18 17:23:50 +00:00
|
|
|
expandSection: () => { this._expandSection(); },
|
2023-01-18 19:33:45 +00:00
|
|
|
cancel: () => {
|
|
|
|
if (this.maximized.get()) {
|
|
|
|
this.maximized.set(null);
|
|
|
|
}
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
};
|
|
|
|
this.autoDispose(commands.createGroup(commandGroup, this, true));
|
2023-01-18 19:33:45 +00:00
|
|
|
|
2023-03-22 15:21:53 +00:00
|
|
|
this.maximized = fromKo(this.layout.maximizedLeaf) as any;
|
|
|
|
this.autoDispose(this.maximized.addListener((sectionId, prev) => {
|
|
|
|
// If we are closing popup, resize all sections.
|
|
|
|
if (!sectionId) {
|
|
|
|
this._onResize();
|
|
|
|
} else {
|
|
|
|
// Otherwise resize only active one (the one in popup).
|
|
|
|
const section = this.viewModel.activeSection.peek();
|
|
|
|
if (!section.isDisposed() && section.id.peek()) {
|
|
|
|
section?.viewInstance.peek()?.onResize();
|
|
|
|
}
|
2023-01-18 19:33:45 +00:00
|
|
|
}
|
|
|
|
}));
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom() {
|
2023-03-22 15:21:53 +00:00
|
|
|
const owner = MultiHolder.create(null);
|
2023-01-18 19:33:45 +00:00
|
|
|
const close = () => this.maximized.set(null);
|
2023-03-22 15:21:53 +00:00
|
|
|
const mainBoxInPopup = Computed.create(owner, use => this.layout.getAllLeafIds().includes(use(this.maximized)));
|
|
|
|
const miniBoxInPopup = Computed.create(owner, use => use(mainBoxInPopup) ? null : use(this.maximized));
|
2023-01-18 19:33:45 +00:00
|
|
|
return cssOverlay(
|
2023-03-22 15:21:53 +00:00
|
|
|
dom.autoDispose(owner),
|
2023-01-18 19:33:45 +00:00
|
|
|
cssOverlay.cls('-active', use => !!use(this.maximized)),
|
|
|
|
testId('viewLayout-overlay'),
|
2023-03-22 15:21:53 +00:00
|
|
|
cssVFull(
|
2023-02-24 11:12:55 +00:00
|
|
|
this.layoutTray.buildDom(),
|
|
|
|
cssLayoutWrapper(
|
2023-03-22 15:21:53 +00:00
|
|
|
cssLayoutWrapper.cls('-active', use => Boolean(use(this.maximized))),
|
|
|
|
dom.update(
|
|
|
|
this.layout.rootElem,
|
|
|
|
dom.hide(use => Boolean(use(miniBoxInPopup))),
|
|
|
|
),
|
|
|
|
this.layoutTray.buildPopup(owner, miniBoxInPopup, close),
|
2023-02-24 11:12:55 +00:00
|
|
|
),
|
2023-01-18 19:33:45 +00:00
|
|
|
),
|
|
|
|
dom.maybe(use => !!use(this.maximized), () =>
|
|
|
|
cssCloseButton('CrossBig',
|
|
|
|
testId('close-button'),
|
|
|
|
dom.on('click', () => close())
|
|
|
|
)
|
|
|
|
),
|
|
|
|
// Close the lightbox when user clicks exactly on the overlay.
|
2023-02-24 11:12:55 +00:00
|
|
|
dom.on('click', (ev, elem) => void (ev.target === elem && this.maximized.get() ? close() : null)),
|
|
|
|
dom.cls('test-viewLayout-save-pending', this._savePending)
|
2023-01-18 19:33:45 +00:00
|
|
|
);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Freezes the layout until the passed in promise resolves. This is useful to achieve a single
|
|
|
|
// layout rebuild when multiple user actions needs to apply, simply pass in a promise that resolves
|
|
|
|
// when all user actions have resolved.
|
2022-04-07 10:10:58 +00:00
|
|
|
public async freezeUntil<T>(promise: Promise<T>): Promise<T> {
|
2020-10-02 15:10:00 +00:00
|
|
|
this._freeze = true;
|
|
|
|
try {
|
2022-04-07 10:10:58 +00:00
|
|
|
return await promise;
|
2020-10-02 15:10:00 +00:00
|
|
|
} finally {
|
|
|
|
this._freeze = false;
|
2023-02-24 11:12:55 +00:00
|
|
|
this.rebuildLayout(this.layoutSpec.peek());
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
public saveLayoutSpec(specs?: BoxSpec) {
|
|
|
|
this._savePending.set(false);
|
|
|
|
// Cancel the automatic delay.
|
|
|
|
this.layoutSaveDelay.cancel();
|
|
|
|
if (!this.layout) { return; }
|
|
|
|
// Only save layout changes when the document isn't read-only.
|
|
|
|
if (!this.gristDoc.isReadonly.get()) {
|
|
|
|
if (!specs) {
|
|
|
|
specs = this.layout.getLayoutSpec();
|
|
|
|
specs.collapsed = this.viewModel.activeCollapsedSections.peek().map((leaf)=> ({leaf}));
|
|
|
|
}
|
|
|
|
this.viewModel.layoutSpecObj.setAndSave(specs).catch(reportError);
|
|
|
|
}
|
|
|
|
this._onResize();
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
// Removes a view section from the current view. Should only be called if there is
|
|
|
|
// more than one viewsection in the view.
|
2023-02-24 11:12:55 +00:00
|
|
|
public removeViewSection(viewSectionRowId: number) {
|
2023-03-22 15:21:53 +00:00
|
|
|
this.maximized.set(null);
|
2020-10-02 15:10:00 +00:00
|
|
|
this.gristDoc.docData.sendAction(['RemoveViewSection', viewSectionRowId]).catch(reportError);
|
|
|
|
}
|
|
|
|
|
2023-03-22 15:21:53 +00:00
|
|
|
public rebuildLayout(layoutSpec: BoxSpec) {
|
|
|
|
// Rebuild the collapsed section layout. In return we will get all leaves that were
|
|
|
|
// removed from collapsed dom. Some of them will hold a view instance dom.
|
|
|
|
const oldTray = this.layoutTray.replaceLayout();
|
|
|
|
// Build the normal layout. While building, some leaves will grab the view instance dom
|
|
|
|
// and attach it to their dom (and detach them from the old layout in the process).
|
2023-02-24 11:12:55 +00:00
|
|
|
this.layout.buildLayout(layoutSpec, true);
|
|
|
|
this._onResize();
|
2023-03-22 15:21:53 +00:00
|
|
|
// Dispose the old layout. This will dispose the view instances that were not reused.
|
|
|
|
oldTray.dispose();
|
2023-02-24 11:12:55 +00:00
|
|
|
}
|
|
|
|
|
2024-01-18 17:23:50 +00:00
|
|
|
private _expandSection() {
|
2023-01-18 19:33:45 +00:00
|
|
|
const activeSection = this.viewModel.activeSection();
|
|
|
|
const activeSectionId = activeSection.getRowId();
|
2023-02-24 11:12:55 +00:00
|
|
|
const activeSectionBox = this.layout.getLeafBox(activeSectionId);
|
2023-01-18 19:33:45 +00:00
|
|
|
if (!activeSectionBox) { return; }
|
|
|
|
activeSectionBox.maximize();
|
|
|
|
}
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
private _buildLeafContent(sectionRowId: number) {
|
2022-03-11 10:48:36 +00:00
|
|
|
return buildViewSectionDom({
|
|
|
|
gristDoc: this.gristDoc,
|
|
|
|
sectionRowId,
|
2023-02-24 11:12:55 +00:00
|
|
|
isResizing: this.isResizing,
|
2022-03-11 10:48:36 +00:00
|
|
|
viewModel: this.viewModel
|
|
|
|
});
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is no layout saved, we can create a default layout just from the list of fields for
|
|
|
|
* this view section. By default we just arrange them into a list of rows, two fields per row.
|
|
|
|
*/
|
2023-02-24 11:12:55 +00:00
|
|
|
private _updateLayoutSpecWithSections(spec: BoxSpec) {
|
2020-10-02 15:10:00 +00:00
|
|
|
// We use tmpLayout as a way to manipulate the layout before we get a final spec from it.
|
2023-01-18 19:33:45 +00:00
|
|
|
const tmpLayout = Layout.create(spec, () => dom('div'), true);
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
const specFieldIds = tmpLayout.getAllLeafIds();
|
|
|
|
const viewSectionIds = this.viewModel.viewSections().all().map(function(f) { return f.getRowId(); });
|
|
|
|
|
|
|
|
function addToSpec(leafId: number) {
|
|
|
|
const newBox = tmpLayout.buildLayoutBox({ leaf: leafId });
|
2023-01-18 19:33:45 +00:00
|
|
|
const rows = tmpLayout.rootBox()!.childBoxes.peek();
|
2020-10-02 15:10:00 +00:00
|
|
|
const lastRow = rows[rows.length - 1];
|
|
|
|
if (rows.length >= 1 && lastRow.isLeaf()) {
|
|
|
|
// Add a new child to the last row.
|
|
|
|
lastRow.addChild(newBox, true);
|
|
|
|
} else {
|
|
|
|
// Add a new row.
|
2023-01-18 19:33:45 +00:00
|
|
|
tmpLayout.rootBox()!.addChild(newBox, true);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
return newBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For any stale fields (no longer among viewFields), remove them from tmpLayout.
|
2023-02-24 11:12:55 +00:00
|
|
|
_.difference(specFieldIds, viewSectionIds).forEach(function(leafId: string|number) {
|
2023-01-18 19:33:45 +00:00
|
|
|
tmpLayout.getLeafBox(leafId)?.dispose();
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// For all fields that should be in the spec but aren't, add them to tmpLayout. We maintain a
|
|
|
|
// two-column layout, so add a new row, or a second box to the last row if it's a leaf.
|
2023-02-24 11:12:55 +00:00
|
|
|
const missingLeafs = _.difference(viewSectionIds, specFieldIds);
|
|
|
|
const collapsedLeafs = new Set((spec.collapsed || []).map(c => c.leaf));
|
|
|
|
missingLeafs.forEach(function(leafId: any) {
|
|
|
|
if (!collapsedLeafs.has(leafId)) {
|
|
|
|
addToSpec(leafId);
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
spec = tmpLayout.getLayoutSpec();
|
|
|
|
tmpLayout.dispose();
|
|
|
|
return spec;
|
|
|
|
}
|
|
|
|
|
2023-02-24 11:12:55 +00:00
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
// Resizes the scrolly windows of all viewSection classes with a 'scrolly' property.
|
|
|
|
private _onResize() {
|
|
|
|
this.viewModel.viewSections().all().forEach(vs => {
|
|
|
|
const inst = vs.viewInstance.peek();
|
|
|
|
if (inst) {
|
|
|
|
inst.onResize();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select another section in cyclic ordering of sections. Order is counter-clockwise if given a
|
|
|
|
// positive `delta`, clockwise otherwise.
|
|
|
|
private _otherSection(delta: number) {
|
2023-02-24 11:12:55 +00:00
|
|
|
const sectionIds = this.layout.getAllLeafIds();
|
2020-10-02 15:10:00 +00:00
|
|
|
const sectionId = this.viewModel.activeSectionId.peek();
|
2023-02-24 11:12:55 +00:00
|
|
|
const currentIndex = sectionIds.indexOf(sectionId);
|
|
|
|
const index = mod(currentIndex + delta, sectionIds.length);
|
2020-10-02 15:10:00 +00:00
|
|
|
// update the active section id
|
2023-02-24 11:12:55 +00:00
|
|
|
this.viewModel.activeSectionId(sectionIds[index]);
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private _maybeFocusInSection() {
|
|
|
|
// If the focused element is inside a view section, make that section active.
|
2023-02-24 11:12:55 +00:00
|
|
|
const layoutBox = this.layout.getContainingBox(document.activeElement);
|
2020-10-02 15:10:00 +00:00
|
|
|
if (layoutBox && layoutBox.leafId) {
|
|
|
|
this.gristDoc.viewModel.activeSectionId(layoutBox.leafId.peek());
|
|
|
|
}
|
|
|
|
}
|
2022-11-17 20:17:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the sort and filter menu of the active view section.
|
|
|
|
*
|
|
|
|
* Optionally accepts a `sectionId` for opening a specific section's menu.
|
|
|
|
*/
|
|
|
|
private _openSortFilterMenu(sectionId?: number) {
|
|
|
|
const id = sectionId ?? this.viewModel.activeSectionId();
|
2023-02-24 11:12:55 +00:00
|
|
|
const leafBoxDom = this.layout.getLeafBox(id)?.dom;
|
2022-11-17 20:17:51 +00:00
|
|
|
if (!leafBoxDom) { return; }
|
|
|
|
|
|
|
|
const menu: HTMLElement | null = leafBoxDom.querySelector('.test-section-menu-sortAndFilter');
|
|
|
|
menu?.click();
|
|
|
|
}
|
2020-10-02 15:10:00 +00:00
|
|
|
}
|
2021-02-09 04:40:04 +00:00
|
|
|
|
|
|
|
const cssLayoutBox = styled('div', `
|
2021-02-10 22:00:41 +00:00
|
|
|
@media screen and ${mediaSmall} {
|
2021-02-09 04:40:04 +00:00
|
|
|
&-active, &-inactive {
|
2023-01-04 16:37:32 +00:00
|
|
|
transition: flex-grow var(--grist-layout-animation-duration, 0.4s); // Exposed for tests
|
2021-02-09 04:40:04 +00:00
|
|
|
}
|
|
|
|
&-active > &-inactive,
|
|
|
|
&-active > &-inactive.layout_hbox .layout_hbox,
|
|
|
|
&-active > &-inactive.layout_vbox .layout_vbox {
|
|
|
|
flex: none !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-active > &-inactive.layout_hbox.layout_leaf,
|
|
|
|
&-active > &-inactive.layout_hbox .layout_hbox.layout_leaf {
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-active > &-inactive.layout_vbox.layout_leaf,
|
|
|
|
&-active > &-inactive.layout_vbox .layout_vbox.layout_leaf {
|
|
|
|
width: 40px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&-inactive.layout_leaf {
|
|
|
|
min-height: 40px;
|
|
|
|
min-width: 40px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
2021-03-05 03:35:53 +00:00
|
|
|
|
2023-01-18 19:33:45 +00:00
|
|
|
const cssLayoutWrapper = styled('div', `
|
2023-02-24 11:12:55 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
position: relative;
|
|
|
|
flex-grow: 1;
|
2023-01-18 19:33:45 +00:00
|
|
|
@media not print {
|
|
|
|
&-active {
|
|
|
|
background: ${theme.mainPanelBg};
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
border-radius: 5px;
|
|
|
|
border-bottom-left-radius: 0px;
|
|
|
|
border-bottom-right-radius: 0px;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
&-active .viewsection_content {
|
|
|
|
margin: 0px;
|
2023-09-21 16:57:58 +00:00
|
|
|
margin-top: 8px;
|
2023-01-18 19:33:45 +00:00
|
|
|
}
|
|
|
|
&-active .viewsection_title {
|
|
|
|
padding: 0px 12px;
|
|
|
|
}
|
|
|
|
&-active .filter_bar {
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssOverlay = styled('div', `
|
2023-02-24 11:12:55 +00:00
|
|
|
height: 100%;
|
2023-01-18 19:33:45 +00:00
|
|
|
@media screen {
|
|
|
|
&-active {
|
|
|
|
background-color: ${theme.modalBackdrop};
|
|
|
|
inset: 0px;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
padding: 20px 56px 20px 56px;
|
|
|
|
position: absolute;
|
|
|
|
}
|
2023-02-24 11:12:55 +00:00
|
|
|
&-active .collapsed_layout {
|
|
|
|
display: none !important;
|
|
|
|
}
|
2023-01-18 19:33:45 +00:00
|
|
|
}
|
|
|
|
@media screen and ${mediaSmall} {
|
|
|
|
&-active {
|
|
|
|
padding: 22px;
|
|
|
|
padding-top: 30px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCloseButton = styled(icon, `
|
|
|
|
position: absolute;
|
|
|
|
top: 16px;
|
|
|
|
right: 16px;
|
|
|
|
height: 24px;
|
|
|
|
width: 24px;
|
|
|
|
cursor: pointer;
|
|
|
|
--icon-color: ${theme.modalBackdropCloseButtonFg};
|
|
|
|
&:hover {
|
|
|
|
--icon-color: ${theme.modalBackdropCloseButtonHoverFg};
|
|
|
|
}
|
|
|
|
@media ${mediaSmall} {
|
|
|
|
& {
|
|
|
|
top: 6px;
|
|
|
|
right: 6px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
2023-02-24 11:12:55 +00:00
|
|
|
|
2023-03-22 15:21:53 +00:00
|
|
|
const cssVFull = styled('div', `
|
2023-02-24 11:12:55 +00:00
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
`);
|