{"version":3,"file":"SidebarAction.mjs","sources":["../../../lib/ui/sidebar/SidebarAction.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { ISidebarContext } from './SidebarTab.ts'\n\nimport { scopedGlobals } from '../../globalScope.ts'\nimport logger from '../../utils/logger.ts'\n\n/**\n * Implementation of a custom sidebar tab within the files app.\n */\nexport interface ISidebarAction {\n\t/**\n\t * Unique id of the sidebar tab.\n\t * This has to conform to the HTML id attribute specification.\n\t */\n\tid: string\n\n\t/**\n\t * The order of this tab.\n\t * Use a low number to make this tab ordered in front.\n\t */\n\torder: number\n\n\t/**\n\t * The localized name of the sidebar tab.\n\t *\n\t * @param context - The current context of the files app\n\t */\n\tdisplayName(context: ISidebarContext): string\n\n\t/**\n\t * The icon, as SVG, of the sidebar tab.\n\t *\n\t * @param context - The current context of the files app\n\t */\n\ticonSvgInline(context: ISidebarContext): string\n\n\t/**\n\t * Callback to check if the sidebar tab should be shown for the selected node.\n\t *\n\t * @param context - The current context of the files app\n\t */\n\tenabled(context: ISidebarContext): boolean\n\n\t/**\n\t * Handle the sidebar action.\n\t *\n\t * @param context - The current context of the files app\n\t */\n\tonClick(context: ISidebarContext): void\n}\n\n/**\n * Register a new sidebar action.\n *\n * @param action - The sidebar action to register\n * @throws {Error} If the provided action is not a valid sidebar action and thus cannot be registered.\n */\nexport function registerSidebarAction(action: ISidebarAction): void {\n\tvalidateSidebarAction(action)\n\n\tscopedGlobals.filesSidebarActions ??= new Map<string, ISidebarAction>()\n\tif (scopedGlobals.filesSidebarActions.has(action.id)) {\n\t\tlogger.warn(`Sidebar action with id \"${action.id}\" already registered. Skipping.`)\n\t\treturn\n\t}\n\tscopedGlobals.filesSidebarActions.set(action.id, action)\n\tlogger.debug(`New sidebar action with id \"${action.id}\" registered.`)\n}\n\n/**\n * Get all currently registered sidebar actions.\n */\nexport function getSidebarActions(): ISidebarAction[] {\n\tif (scopedGlobals.filesSidebarActions) {\n\t\treturn [...scopedGlobals.filesSidebarActions.values()]\n\t}\n\treturn []\n}\n\n/**\n * Check if a given sidebar action object implements all necessary fields.\n *\n * @param action - The sidebar action to validate\n */\nfunction validateSidebarAction(action: ISidebarAction): void {\n\tif (typeof action !== 'object') {\n\t\tthrow new Error('Sidebar action is not an object')\n\t}\n\n\tif (!action.id || (typeof action.id !== 'string') || action.id !== CSS.escape(action.id)) {\n\t\tthrow new Error('Sidebar actions need to have an id conforming to the HTML id attribute specifications')\n\t}\n\n\tif (!action.displayName || typeof action.displayName !== 'function') {\n\t\tthrow new Error('Sidebar actions need to have a displayName function')\n\t}\n\n\tif (!action.iconSvgInline || typeof action.iconSvgInline !== 'function') {\n\t\tthrow new Error('Sidebar actions need to have a iconSvgInline function')\n\t}\n\n\tif (!action.enabled || typeof action.enabled !== 'function') {\n\t\tthrow new Error('Sidebar actions need to have an enabled function')\n\t}\n\n\tif (!action.onClick || typeof action.onClick !== 'function') {\n\t\tthrow new Error('Sidebar actions need to have an onClick function')\n\t}\n}\n"],"names":[],"mappings":";;AA6DO,SAAS,sBAAsB,QAA8B;AACnE,wBAAsB,MAAM;AAE5B,gBAAc,4CAA4B,IAAA;AAC1C,MAAI,cAAc,oBAAoB,IAAI,OAAO,EAAE,GAAG;AACrD,WAAO,KAAK,2BAA2B,OAAO,EAAE,iCAAiC;AACjF;AAAA,EACD;AACA,gBAAc,oBAAoB,IAAI,OAAO,IAAI,MAAM;AACvD,SAAO,MAAM,+BAA+B,OAAO,EAAE,eAAe;AACrE;AAKO,SAAS,oBAAsC;AACrD,MAAI,cAAc,qBAAqB;AACtC,WAAO,CAAC,GAAG,cAAc,oBAAoB,QAAQ;AAAA,EACtD;AACA,SAAO,CAAA;AACR;AAOA,SAAS,sBAAsB,QAA8B;AAC5D,MAAI,OAAO,WAAW,UAAU;AAC/B,UAAM,IAAI,MAAM,iCAAiC;AAAA,EAClD;AAEA,MAAI,CAAC,OAAO,MAAO,OAAO,OAAO,OAAO,YAAa,OAAO,OAAO,IAAI,OAAO,OAAO,EAAE,GAAG;AACzF,UAAM,IAAI,MAAM,uFAAuF;AAAA,EACxG;AAEA,MAAI,CAAC,OAAO,eAAe,OAAO,OAAO,gBAAgB,YAAY;AACpE,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACtE;AAEA,MAAI,CAAC,OAAO,iBAAiB,OAAO,OAAO,kBAAkB,YAAY;AACxE,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACxE;AAEA,MAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,YAAY;AAC5D,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACnE;AAEA,MAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,YAAY;AAC5D,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACnE;AACD;"}