{"version":3,"file":"listHeaders.mjs","sources":["../../../lib/ui/headers/listHeaders.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors\n * SPDX-License-Identifier: AGPL-3.0-or-later\n */\n\nimport type { IFolder } from '../../node/folder.ts'\nimport type { IView } from '../navigation/view.ts'\n\nimport { scopedGlobals } from '../../globalScope.ts'\nimport logger from '../../utils/logger.ts'\nimport { getRegistry } from '../registry.ts'\n\nexport interface IFileListHeader {\n\t/** Unique ID */\n\tid: string\n\t/** Order */\n\torder: number\n\t/** Condition wether this header is shown or not */\n\tenabled?: (folder: IFolder, view: IView) => boolean\n\t/** Executed when file list is initialized */\n\trender(el: HTMLElement, folder: IFolder, view: IView): void\n\t/** Executed when root folder changed */\n\tupdated(folder: IFolder, view: IView): void\n}\n\n/**\n * Register a new file list header.\n *\n * @param header - The header to register\n */\nexport function registerFileListHeader(header: IFileListHeader): void {\n\tvalidateHeader(header)\n\n\tscopedGlobals.fileListHeaders ??= new Map<string, IFileListHeader>()\n\tif (scopedGlobals.fileListHeaders.has(header.id)) {\n\t\tlogger.error(`Header ${header.id} already registered`, { header })\n\t\treturn\n\t}\n\n\tscopedGlobals.fileListHeaders.set(header.id, header)\n\tgetRegistry()\n\t\t.dispatchTypedEvent('register:listHeader', new CustomEvent('register:listHeader', { detail: header }))\n}\n\n/**\n * Get all currently registered file list headers.\n */\nexport function getFileListHeaders(): IFileListHeader[] {\n\tif (!scopedGlobals.fileListHeaders) {\n\t\treturn []\n\t}\n\treturn [...scopedGlobals.fileListHeaders.values()]\n}\n\n/**\n * @param header - The header to validate\n */\nfunction validateHeader(header: IFileListHeader) {\n\tif (!header.id || !header.render || !header.updated) {\n\t\tthrow new Error('Invalid header: id, render and updated are required')\n\t}\n\n\tif (typeof header.id !== 'string') {\n\t\tthrow new Error('Invalid id property')\n\t}\n\n\tif (header.enabled !== undefined && typeof header.enabled !== 'function') {\n\t\tthrow new Error('Invalid enabled property')\n\t}\n\n\tif (header.render && typeof header.render !== 'function') {\n\t\tthrow new Error('Invalid render property')\n\t}\n\n\tif (header.updated && typeof header.updated !== 'function') {\n\t\tthrow new Error('Invalid updated property')\n\t}\n}\n"],"names":[],"mappings":";;;AA8BO,SAAS,uBAAuB,QAA+B;AACrE,iBAAe,MAAM;AAErB,gBAAc,wCAAwB,IAAA;AACtC,MAAI,cAAc,gBAAgB,IAAI,OAAO,EAAE,GAAG;AACjD,WAAO,MAAM,UAAU,OAAO,EAAE,uBAAuB,EAAE,QAAQ;AACjE;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,cAAc,iBAAiB;AACnC,WAAO,CAAA;AAAA,EACR;AACA,SAAO,CAAC,GAAG,cAAc,gBAAgB,QAAQ;AAClD;AAKA,SAAS,eAAe,QAAyB;AAChD,MAAI,CAAC,OAAO,MAAM,CAAC,OAAO,UAAU,CAAC,OAAO,SAAS;AACpD,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACtE;AAEA,MAAI,OAAO,OAAO,OAAO,UAAU;AAClC,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACtC;AAEA,MAAI,OAAO,YAAY,UAAa,OAAO,OAAO,YAAY,YAAY;AACzE,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC3C;AAEA,MAAI,OAAO,UAAU,OAAO,OAAO,WAAW,YAAY;AACzD,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC1C;AAEA,MAAI,OAAO,WAAW,OAAO,OAAO,YAAY,YAAY;AAC3D,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC3C;AACD;"}