import { html, connectStore, customElement, GemElement, refobject, RefObject } from '@mantou/gem'; import { MenuItem, GemPanelElement, Layout, Panel, Window, theme } from '../../../'; import { bridgeStore, layoutModes, updateLayoutMode } from '../store'; import { ContextMenuDetail } from '../base-element'; import './navigation'; const getMenu = async (window: Window, _panel: Panel, defaultMenus: MenuItem[]) => { const menus: MenuItem[] = [...defaultMenus]; const gemPanelEle = document.querySelector('gem-panel'); if (gemPanelEle) { gemPanelEle.hiddenPanels.forEach((panel) => { menus.unshift({ text: `open "${panel.title}"`, handle: () => gemPanelEle.openPanelInWindow(panel, window), }); }); } return menus; }; const favorites = new Panel('favorites', { title: 'favorites', getMenu, async getContent() { await import('./panel-favorites'); return html``; }, }); const content = new Panel('content', { title: 'content', getMenu, async getContent() { await import('./panel-content'); return html``; }, }); const filter = new Panel('filter', { title: 'filter', getMenu, async getContent() { await import('./panel-filter'); return html``; }, }); const metadata = new Panel('metadata', { title: 'metadata', getMenu, async getContent() { await import('./panel-metadata'); return html``; }, }); const preview = new Panel('preview', { title: 'preview', getMenu, async getContent() { await import('./panel-preview'); return html``; }, }); const folders = new Panel('folders', { title: 'folders', getMenu, async getContent() { await import('./panel-folders'); return html``; }, }); const libraries = new Panel('libraries', { title: 'libraries', getMenu, }); const panels = [favorites, content, filter, metadata, preview, folders, libraries]; @connectStore(bridgeStore) @customElement('bridge-root') export class BridgeRootElement extends GemElement { @refobject panelElementRef: RefObject; #essentialsLayout = (() => { const w1 = new Window([favorites], { gridArea: 'favorites' }); const w2 = new Window([content], { gridArea: 'content' }); const w3 = new Window([filter], { gridArea: 'filter' }); const w4 = new Window([preview], { gridArea: 'preview' }); const w5 = new Window([metadata], { gridArea: 'metadata' }); const layout = new Layout([w1, w2, w3, w4, w5], { gridTemplateAreas: ` "favorites content preview" "filter content preview" "filter content metadata" `, gridTemplateColumns: '1fr 2fr 1fr', gridTemplateRows: '3fr 1fr 3fr', }); return layout; })(); #librariesLayout = (() => { const w1 = new Window([folders], { gridArea: 'folders' }); const w2 = new Window([content], { gridArea: 'content' }); const w3 = new Window([libraries], { gridArea: 'libraries' }); const w4 = new Window([preview], { gridArea: 'preview' }); const w5 = new Window([metadata], { gridArea: 'metadata' }); const layout = new Layout([w1, w2, w3, w4, w5], { gridTemplateAreas: ` "folders preview libraries" "metadata preview libraries" "metadata content libraries" `, gridTemplateColumns: '1fr 2fr 1fr', gridTemplateRows: '6fr 1fr 3fr', }); return layout; })(); #getLayout = () => { if (bridgeStore.mode === 'essentials') { return this.#essentialsLayout; } else { return this.#librariesLayout; } }; mounted = () => { this.addEventListener('contextmenu', (evt) => { evt.preventDefault(); }); this.addEventListener('open-context-menu', ({ detail }: CustomEvent) => { const { activeElement, x, y, menu } = detail; this.panelElementRef.element?.openContextMenu(activeElement, x, y, menu); }); }; render() { return html`
${layoutModes.map( (mode) => html`
updateLayoutMode(mode)}> ${mode}
`, )}
`; } }