{"version":3,"file":"fileListAction.mjs","sources":["../../../lib/ui/actions/fileListAction.ts"],"sourcesContent":["/**\n * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { ViewActionContext } from '../types.ts'\n\nimport { scopedGlobals } from '../../globalScope.ts'\nimport logger from '../../utils/logger.ts'\nimport { getRegistry } from '../registry.ts'\n\nexport interface IFileListAction {\n\t/** Unique ID */\n\tid: string\n\n\t/** Translated name of the action */\n\tdisplayName: (context: ViewActionContext) => string\n\n\t/** Raw svg string */\n\ticonSvgInline?: (context: ViewActionContext) => string\n\n\t/** Sort order */\n\torder: number\n\n\t/**\n\t * Condition whether this action is shown or not\n\t */\n\tenabled?: (context: ViewActionContext) => boolean\n\n\t/**\n\t * Function executed on single file action\n\t *\n\t * @return true if the action was executed successfully,\n\t * false otherwise and null if the action is silent/undefined.\n\t * @throws {Error} If the action failed\n\t */\n\texec: (context: ViewActionContext) => Promise<boolean | null>\n}\n\n/**\n * Register a new file list action.\n *\n * @param action - The file list action to register\n */\nexport function registerFileListAction(action: IFileListAction) {\n\tvalidateAction(action)\n\n\tscopedGlobals.fileListActions ??= new Map<string, IFileListAction>()\n\tif (scopedGlobals.fileListActions.has(action.id)) {\n\t\tlogger.error(`FileListAction with id \"${action.id}\" is already registered`, { action })\n\t\treturn\n\t}\n\n\tscopedGlobals.fileListActions.set(action.id, action)\n\tgetRegistry()\n\t\t.dispatchTypedEvent('register:listAction', new CustomEvent('register:listAction', { detail: action }))\n}\n\n/**\n * Get all currently registered file list actions.\n */\nexport function getFileListActions(): IFileListAction[] {\n\tif (scopedGlobals.fileListActions) {\n\t\treturn [...scopedGlobals.fileListActions.values()]\n\t}\n\treturn []\n}\n\n/**\n * Validate a file list action.\n *\n * @param action - The action to validate\n */\nfunction validateAction(action: IFileListAction) {\n\tif (!action.id || typeof action.id !== 'string') {\n\t\tthrow new Error('Invalid id')\n\t}\n\n\tif (!action.displayName || typeof action.displayName !== 'function') {\n\t\tthrow new Error('Invalid displayName function')\n\t}\n\n\tif ('iconSvgInline' in action && typeof action.iconSvgInline !== 'function') {\n\t\tthrow new Error('Invalid iconSvgInline function')\n\t}\n\n\tif ('order' in action && typeof action.order !== 'number') {\n\t\tthrow new Error('Invalid order')\n\t}\n\n\tif ('enabled' in action && typeof action.enabled !== 'function') {\n\t\tthrow new Error('Invalid enabled function')\n\t}\n\n\tif (!action.exec || typeof action.exec !== 'function') {\n\t\tthrow new Error('Invalid exec function')\n\t}\n}\n"],"names":[],"mappings":";;;AA4CO,SAAS,uBAAuB,QAAyB;AAC/D,iBAAe,MAAM;AAErB,gBAAc,wCAAwB,IAAA;AACtC,MAAI,cAAc,gBAAgB,IAAI,OAAO,EAAE,GAAG;AACjD,WAAO,MAAM,2BAA2B,OAAO,EAAE,2BAA2B,EAAE,QAAQ;AACtF;AAAA,EACD;AAEA,gBAAc,gBAAgB,IAAI,OAAO,IAAI,MAAM;AACnD,cAAA,EACE,mBAAmB,uBAAuB,IAAI,YAAY,uBAAuB,EAAE,QAAQ,OAAA,CAAQ,CAAC;AACvG;AAKO,SAAS,qBAAwC;AACvD,MAAI,cAAc,iBAAiB;AAClC,WAAO,CAAC,GAAG,cAAc,gBAAgB,QAAQ;AAAA,EAClD;AACA,SAAO,CAAA;AACR;AAOA,SAAS,eAAe,QAAyB;AAChD,MAAI,CAAC,OAAO,MAAM,OAAO,OAAO,OAAO,UAAU;AAChD,UAAM,IAAI,MAAM,YAAY;AAAA,EAC7B;AAEA,MAAI,CAAC,OAAO,eAAe,OAAO,OAAO,gBAAgB,YAAY;AACpE,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAC/C;AAEA,MAAI,mBAAmB,UAAU,OAAO,OAAO,kBAAkB,YAAY;AAC5E,UAAM,IAAI,MAAM,gCAAgC;AAAA,EACjD;AAEA,MAAI,WAAW,UAAU,OAAO,OAAO,UAAU,UAAU;AAC1D,UAAM,IAAI,MAAM,eAAe;AAAA,EAChC;AAEA,MAAI,aAAa,UAAU,OAAO,OAAO,YAAY,YAAY;AAChE,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC3C;AAEA,MAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,YAAY;AACtD,UAAM,IAAI,MAAM,uBAAuB;AAAA,EACxC;AACD;"}