{"version":3,"file":"Sidebar.mjs","sources":["../../../lib/ui/sidebar/Sidebar.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { INode } from '../../node/node.ts'\nimport type { ISidebarAction } from './SidebarAction.ts'\nimport type { ISidebarContext, ISidebarTab } from './SidebarTab.ts'\n\nimport logger from '../../utils/logger.ts'\nimport { registerSidebarAction } from './SidebarAction.ts'\nimport { registerSidebarTab } from './SidebarTab.ts'\n\nexport interface ISidebar {\n\t/**\n\t * If the files sidebar can currently be accessed,\n\t * meaning it is rendered on the current page either by the files app\n\t * or by an app rendering the sidebar within its own app.\n\t * Registering tabs also works if the sidebar is currently not available.\n\t */\n\treadonly available: boolean\n\n\t/**\n\t * The current open state of the sidebar\n\t */\n\treadonly isOpen: boolean\n\n\t/**\n\t * The currently active sidebar tab id\n\t */\n\treadonly activeTab?: string\n\n\t/**\n\t * The currently opened node in the sidebar\n\t */\n\treadonly node?: INode\n\n\t/**\n\t * Open the sidebar for a specific node.\n\t *\n\t * When the sidebar is fully opened the `files:sidebar:opened` event is emitted,\n\t * see also `@nextcloud/event-bus`.\n\t *\n\t * @param node - The node to open the sidebar for\n\t * @param tab - The tab to open by default\n\t */\n\topen(node: INode, tab?: string): void\n\n\t/**\n\t * Close the sidebar.\n\t *\n\t * When the sidebar is fully closed the `files:sidebar:closed` event is emitted,\n\t * see also `@nextcloud/event-bus`.\n\t */\n\tclose(): void\n\n\t/**\n\t * Set the active sidebar tab\n\t *\n\t * @param tabId - The tab to set active\n\t */\n\tsetActiveTab(tabId: string): void\n\n\t/**\n\t * Render the sidebar as a fullscreen overlay of the current page.\n\t *\n\t * @param isFullScreen - Whether to render the sidebar fullscreen\n\t */\n\tsetFullScreenMode(isFullScreen: boolean): void\n\n\t/**\n\t * Render the sidebar into an element of the current app.\n\t *\n\t * The sidebar is rendered into the app content element as soon as the page is loaded,\n\t * so this is only needed by apps that render the sidebar into a specific element\n\t * or that set up their own layout after the page was loaded.\n\t * Calling this again moves an already rendered sidebar into the requested element.\n\t *\n\t * Requires the app to request the sidebar for the current page,\n\t * by dispatching the `OCA\\Files\\Event\\LoadSidebar` event while rendering it.\n\t * Within the files app the sidebar is part of the app layout, so this does nothing.\n\t *\n\t * @param target - The element to render the sidebar into\n\t */\n\tmount(target: HTMLElement): void\n\n\t/**\n\t * Register a new sidebar tab.\n\t * This should ideally be done on app initialization using Nextcloud init scripts.\n\t *\n\t * @param tab - The sidebar tab to register\n\t */\n\tregisterTab(tab: ISidebarTab): void\n\n\t/**\n\t * Get all registered sidebar tabs.\n\t * If a node is passed only the enabled tabs are retrieved.\n\t */\n\tgetTabs(context?: ISidebarContext): ISidebarTab[]\n\n\t/**\n\t * Get all registered sidebar actions.\n\t *\n\t * If a context is provided only the enabled actions are returned.\n\t *\n\t * @param context - The context\n\t */\n\tgetActions(context?: ISidebarContext): ISidebarAction[]\n\n\t/**\n\t * Register a new sidebar action.\n\t *\n\t * @param action - The action to register\n\t */\n\tregisterAction(action: ISidebarAction): void\n}\n\n/**\n * This is just a proxy allowing an arbitrary `@nextcloud/files` library version to access the defined interface of the sidebar.\n * By proxying this instead of providing the implementation here we ensure that if apps use different versions of the library,\n * we do not end up with version conflicts between them.\n *\n * If we add new properties they just will be available in new library versions.\n * If we decide to do a breaking change we can either add compatibility wrappers in the implementation in the files app.\n */\nclass SidebarProxy implements ISidebar {\n\tget #impl(): Omit<ISidebar, 'available' | 'mount' | 'registerTab' | 'registerAction'> | undefined {\n\t\treturn window.OCA?.Files?._sidebar?.()\n\t}\n\n\tget available(): boolean {\n\t\treturn !!this.#impl\n\t}\n\n\tget isOpen(): boolean {\n\t\treturn this.#impl?.isOpen ?? false\n\t}\n\n\tget activeTab(): string | undefined {\n\t\treturn this.#impl?.activeTab\n\t}\n\n\tget node(): INode | undefined {\n\t\treturn this.#impl?.node\n\t}\n\n\topen(node: INode, tab?: string): void {\n\t\tthis.#impl?.open(node, tab)\n\t}\n\n\tclose(): void {\n\t\tthis.#impl?.close()\n\t}\n\n\tsetActiveTab(tabId: string): void {\n\t\tthis.#impl?.setActiveTab(tabId)\n\t}\n\n\tsetFullScreenMode(isFullScreen: boolean): void {\n\t\tthis.#impl?.setFullScreenMode(isFullScreen)\n\t}\n\n\tmount(target: HTMLElement): void {\n\t\tconst mountSidebar = window.OCA?.Files?._mountSidebar\n\t\tif (mountSidebar === undefined) {\n\t\t\tlogger.error('Cannot render the sidebar as it was not loaded for this page, see the `LoadSidebar` event.')\n\t\t\treturn\n\t\t}\n\n\t\tmountSidebar(target)\n\t}\n\n\tregisterTab(tab: ISidebarTab): void {\n\t\tregisterSidebarTab(tab)\n\t}\n\n\tgetTabs(context?: ISidebarContext): ISidebarTab[] {\n\t\treturn this.#impl?.getTabs(context) ?? []\n\t}\n\n\tgetActions(context?: ISidebarContext): ISidebarAction[] {\n\t\treturn this.#impl?.getActions(context) ?? []\n\t}\n\n\tregisterAction(action: ISidebarAction): void {\n\t\tregisterSidebarAction(action)\n\t}\n}\n\n/**\n * Get a reference to the files sidebar.\n */\nexport function getSidebar(): ISidebar {\n\treturn new SidebarProxy()\n}\n"],"names":[],"mappings":";;;AA6HA,MAAM,aAAiC;AAAA,EACtC,IAAI,QAA8F;AACjG,WAAO,OAAO,KAAK,OAAO,WAAA;AAAA,EAC3B;AAAA,EAEA,IAAI,YAAqB;AACxB,WAAO,CAAC,CAAC,KAAK;AAAA,EACf;AAAA,EAEA,IAAI,SAAkB;AACrB,WAAO,KAAK,OAAO,UAAU;AAAA,EAC9B;AAAA,EAEA,IAAI,YAAgC;AACnC,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEA,IAAI,OAA0B;AAC7B,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEA,KAAK,MAAa,KAAoB;AACrC,SAAK,OAAO,KAAK,MAAM,GAAG;AAAA,EAC3B;AAAA,EAEA,QAAc;AACb,SAAK,OAAO,MAAA;AAAA,EACb;AAAA,EAEA,aAAa,OAAqB;AACjC,SAAK,OAAO,aAAa,KAAK;AAAA,EAC/B;AAAA,EAEA,kBAAkB,cAA6B;AAC9C,SAAK,OAAO,kBAAkB,YAAY;AAAA,EAC3C;AAAA,EAEA,MAAM,QAA2B;AAChC,UAAM,eAAe,OAAO,KAAK,OAAO;AACxC,QAAI,iBAAiB,QAAW;AAC/B,aAAO,MAAM,4FAA4F;AACzG;AAAA,IACD;AAEA,iBAAa,MAAM;AAAA,EACpB;AAAA,EAEA,YAAY,KAAwB;AACnC,uBAAmB,GAAG;AAAA,EACvB;AAAA,EAEA,QAAQ,SAA0C;AACjD,WAAO,KAAK,OAAO,QAAQ,OAAO,KAAK,CAAA;AAAA,EACxC;AAAA,EAEA,WAAW,SAA6C;AACvD,WAAO,KAAK,OAAO,WAAW,OAAO,KAAK,CAAA;AAAA,EAC3C;AAAA,EAEA,eAAe,QAA8B;AAC5C,0BAAsB,MAAM;AAAA,EAC7B;AACD;AAKO,SAAS,aAAuB;AACtC,SAAO,IAAI,aAAA;AACZ;"}