{"version":3,"file":"column.mjs","sources":["../../../lib/ui/navigation/column.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2022 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 { IView } from './view.ts'\n\nimport { checkOptionalProperty } from '../../utils/objectValidation.ts'\n\nexport interface IColumn {\n\t/** Unique column ID */\n\tid: string\n\t/** Translated column title */\n\ttitle: string\n\t/** The content of the cell. The element will be appended within */\n\trender: (node: INode, view: IView) => HTMLElement\n\t/** Function used to sort INodes between them */\n\tsort?: (nodeA: INode, nodeB: INode) => number\n\t/**\n\t * Custom summary of the column to display at the end of the list.\n\t * Will not be displayed if  nothing is provided\n\t */\n\tsummary?: (node: INode[], view: IView) => string\n}\n\nexport class Column implements IColumn {\n\tprivate _column: IColumn\n\n\tconstructor(column: IColumn) {\n\t\tvalidateColumn(column)\n\t\tthis._column = column\n\t}\n\n\tget id() {\n\t\treturn this._column.id\n\t}\n\n\tget title() {\n\t\treturn this._column.title\n\t}\n\n\tget render() {\n\t\treturn this._column.render\n\t}\n\n\tget sort() {\n\t\treturn this._column.sort\n\t}\n\n\tget summary() {\n\t\treturn this._column.summary\n\t}\n}\n\n/**\n * Validate a column definition\n *\n * @param column - the column to check\n * @throws {Error} if the column is not valid\n */\nexport function validateColumn(column: IColumn): void {\n\tif (typeof column !== 'object' || column === null) {\n\t\tthrow new Error('View column must be an object')\n\t}\n\n\tif (!column.id || typeof column.id !== 'string') {\n\t\tthrow new Error('A column id is required')\n\t}\n\n\tif (!column.title || typeof column.title !== 'string') {\n\t\tthrow new Error('A column title is required')\n\t}\n\n\tif (!column.render || typeof column.render !== 'function') {\n\t\tthrow new Error('A render function is required')\n\t}\n\n\t// Optional properties\n\tcheckOptionalProperty(column, 'sort', 'function')\n\tcheckOptionalProperty(column, 'summary', 'function')\n}\n"],"names":[],"mappings":";AA0BO,MAAM,OAA0B;AAAA,EAC9B;AAAA,EAER,YAAY,QAAiB;AAC5B,mBAAe,MAAM;AACrB,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,IAAI,KAAK;AACR,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEA,IAAI,QAAQ;AACX,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEA,IAAI,SAAS;AACZ,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEA,IAAI,OAAO;AACV,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEA,IAAI,UAAU;AACb,WAAO,KAAK,QAAQ;AAAA,EACrB;AACD;AAQO,SAAS,eAAe,QAAuB;AACrD,MAAI,OAAO,WAAW,YAAY,WAAW,MAAM;AAClD,UAAM,IAAI,MAAM,+BAA+B;AAAA,EAChD;AAEA,MAAI,CAAC,OAAO,MAAM,OAAO,OAAO,OAAO,UAAU;AAChD,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC1C;AAEA,MAAI,CAAC,OAAO,SAAS,OAAO,OAAO,UAAU,UAAU;AACtD,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC7C;AAEA,MAAI,CAAC,OAAO,UAAU,OAAO,OAAO,WAAW,YAAY;AAC1D,UAAM,IAAI,MAAM,+BAA+B;AAAA,EAChD;AAGA,wBAAsB,QAAQ,QAAQ,UAAU;AAChD,wBAAsB,QAAQ,WAAW,UAAU;AACpD;"}