File size: 1,792 Bytes
71174bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import { localStorageSetItem } from "@/Core/LocalStorage";
import { setStoreVar } from "@/Store/StoreExternalAccess";
import { GoldenLayout, Stack, Tab } from "golden-layout";
import { layoutApi } from "@/Api/Layout";
import { isMobile } from "@/Core/GlobalVars";
export let goldenLayout: GoldenLayout;
/**
* Creates the golden layout and stores it in a global variable for reference
* elsewhere.
*
* @param {HTMLElement} glContainer The HTML container to put the golden layout
* in.
* @returns {GoldenLayout} The golden layout.
*/
export function makeGoldenLayout(glContainer: HTMLElement): GoldenLayout {
goldenLayout = new GoldenLayout(glContainer);
// (window as any).gl = goldenLayout;
// const savedLayout = store.state.goldenLayout;
// if (savedLayout !== null) {
// goldenLayout.loadLayout(savedLayout);
// }
// Add a double-click listener to tabs to toggle maximize/minimize
goldenLayout.on("tabCreated", (tab: Tab) => {
const tabElement = tab.element;
tabElement.addEventListener("dblclick", () => {
const parent = tab.contentItem.parent;
// Check if the parent is a Stack, then toggle its maximized state.
if (parent && parent.isStack) {
(parent as Stack).toggleMaximise();
}
});
});
goldenLayout.on("stateChanged", function () {
const state = goldenLayout.saveLayout();
setStoreVar("goldenLayout", state);
// Only save to local storage if a session layout is NOT active and not on mobile.
if (!isMobile && !layoutApi.isSessionLayoutActive()) {
localStorageSetItem("goldenLayoutState", state, undefined, false);
}
});
return goldenLayout;
}
|