diff --git a/docs/demos/1-simple/index.html b/docs/demos/1-simple/index.html index b01c813b..6cdbf9d7 100644 --- a/docs/demos/1-simple/index.html +++ b/docs/demos/1-simple/index.html @@ -26,7 +26,7 @@

Simple

- Name + Name Ext. City @@ -757,8 +757,7 @@

Simple

headerClass: "red" } ] -}) - + }) diff --git a/docs/demos/24-footer/index.html b/docs/demos/24-footer/index.html new file mode 100644 index 00000000..d9e0b7e2 --- /dev/null +++ b/docs/demos/24-footer/index.html @@ -0,0 +1,125 @@ + + + + + + + Custom Footer + + + + + + + + +

Custom Footer

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/demos/dist/module.js b/docs/demos/dist/module.js index b3a89b2e..e85bdd1b 100644 --- a/docs/demos/dist/module.js +++ b/docs/demos/dist/module.js @@ -1949,7 +1949,7 @@ const headingsToVirtualHeaderRowDOM = (headings, columnSettings, columnsState, { if (column.hidden) { return; } - const attributes = {}; + const attributes = heading.attributes ? { ...heading.attributes } : {}; if (column.sortable && sortable && (!scrollY.length || unhideHeader)) { if (column.filter) { attributes["data-filterable"] = "true"; @@ -1959,7 +1959,7 @@ const headingsToVirtualHeaderRowDOM = (headings, columnSettings, columnsState, { } } if (column.headerClass) { - attributes.class = column.headerClass; + attributes.class = attributes.class ? `${attributes.class} ${column.headerClass}` : column.headerClass; } if (columnsState.sort && columnsState.sort.column === index) { const directionClass = columnsState.sort.dir === "asc" ? classes.ascending : classes.descending; @@ -1969,15 +1969,13 @@ const headingsToVirtualHeaderRowDOM = (headings, columnSettings, columnsState, { else if (columnsState.filters[index]) { attributes.class = attributes.class ? `${attributes.class} ${classes.filterActive}` : classes.filterActive; } - let style = ""; if (columnsState.widths[index] && !noColumnWidths) { - style += `width: ${columnsState.widths[index]}%;`; + const style = `width: ${columnsState.widths[index]}%;`; + attributes.style = attributes.style ? `${attributes.style} ${style}` : style; } if (scrollY.length && !unhideHeader) { - style += "padding-bottom: 0;padding-top: 0;border: 0;"; - } - if (style.length) { - attributes.style = style; + const style = "padding-bottom: 0;padding-top: 0;border: 0;"; + attributes.style = attributes.style ? `${attributes.style} ${style}` : style; } const headerNodes = heading.type === "html" ? heading.data : @@ -1992,8 +1990,10 @@ const headingsToVirtualHeaderRowDOM = (headings, columnSettings, columnsState, { attributes, childNodes: ((hiddenHeader || scrollY.length) && !unhideHeader) ? [ - { nodeName: "#text", - data: "" } + { + nodeName: "#text", + data: "" + } ] : !column.sortable || !sortable ? headerNodes : @@ -2009,7 +2009,7 @@ const headingsToVirtualHeaderRowDOM = (headings, columnSettings, columnsState, { }; }).filter((column) => column) }); -const dataToVirtualDOM = (tableAttributes, headings, rows, columnSettings, columnsState, rowCursor, { classes, hiddenHeader, header, footer, format, sortable, scrollY, type, rowRender, tabIndex }, { noColumnWidths, unhideHeader, renderHeader }) => { +const dataToVirtualDOM = (tableAttributes, headings, rows, columnSettings, columnsState, rowCursor, { classes, hiddenHeader, header, footer, format, sortable, scrollY, type, rowRender, tabIndex }, { noColumnWidths, unhideHeader, renderHeader }, footers, captions) => { const table = { nodeName: "TABLE", attributes: { ...tableAttributes }, @@ -2032,30 +2032,30 @@ const dataToVirtualDOM = (tableAttributes, headings, rows, columnSettings, colum if (column.hidden) { return; } - const td = column.type === "html" ? - { - nodeName: "TD", - childNodes: cell.data - } : - { - nodeName: "TD", - childNodes: [ - { - nodeName: "#text", - data: cell.text ?? String(cell.data) - } - ] - }; + const td = { + nodeName: "TD", + attributes: cell.attributes ? { ...cell.attributes } : {}, + childNodes: column.type === "html" ? cell.data : [ + { + nodeName: "#text", + data: cell.text ?? String(cell.data) + } + ] + }; if (!header && !footer && columnsState.widths[cIndex] && !noColumnWidths) { - td.attributes = { - style: `width: ${columnsState.widths[cIndex]}%;` - }; + if (!td.attributes.style) { + td.attributes.style = ""; + } + td.attributes.style += `width: ${columnsState.widths[cIndex]}%;`; } if (column.cellClass) { - if (!td.attributes) { - td.attributes = {}; + if (!td.attributes.class) { + td.attributes.class = ""; + } + else { + td.attributes.class += " "; } - td.attributes.class = column.cellClass; + td.attributes.class += column.cellClass; } if (column.render) { const renderedCell = column.render(cell.data, td, index, cIndex); @@ -2117,7 +2117,9 @@ const dataToVirtualDOM = (tableAttributes, headings, rows, columnSettings, colum childNodes: [headerRow] }; if ((scrollY.length || hiddenHeader) && !unhideHeader) { - thead.attributes = { style: "height: 0px;" }; + thead.attributes = { + style: "height: 0px;" + }; } table.childNodes.unshift(thead); } @@ -2133,6 +2135,8 @@ const dataToVirtualDOM = (tableAttributes, headings, rows, columnSettings, colum table.childNodes.push(tfoot); } } + footers.forEach(foot => table.childNodes.push(foot)); + captions.forEach(caption => table.childNodes.push(caption)); if (tabIndex !== false) { table.attributes.tabindex = String(tabIndex); } @@ -2272,8 +2276,8 @@ const readDOMDataCell = (cell, columnSettings) => { const data = !["false", "0", "null", "undefined"].includes(cell.innerText.toLowerCase().trim()); cellData = { data, - order: data ? 1 : 0, - text: data ? "1" : "0" + text: data ? "1" : "0", + order: data ? 1 : 0 }; break; } @@ -2287,6 +2291,13 @@ const readDOMDataCell = (cell, columnSettings) => { break; } } + // Save cell attributes to reference when rendering + cellData.attributes = {}; + if (cell.attributes) { + for (const attr of cell.attributes) { + cellData.attributes[attr.name] = attr.value; + } + } return cellData; }; const readHeaderCell = (cell) => { @@ -2334,6 +2345,8 @@ const readDOMHeaderCell = (cell) => { type: "string" }; } + // Save header cell attributes to reference when rendering + cellData.attributes = node.attributes; return cellData; }; const readTableData = (dataOption, dom = undefined, columnSettings, defaultType, defaultFormat) => { @@ -3008,6 +3021,7 @@ const defaultConfig$2 = { footer: false, header: true, hiddenHeader: false, + caption: undefined, rowNavigation: false, tabIndex: false, // for overriding rendering @@ -3246,6 +3260,19 @@ class DataTable { } this._virtualDOM = nodeToObj(this.dom, this.options.diffDomOptions || {}); this._tableAttributes = { ...this._virtualDOM.attributes }; + this._tableFooters = this._virtualDOM.childNodes.filter(node => node.nodeName === "TFOOT"); + this._tableCaptions = this._virtualDOM.childNodes.filter(node => node.nodeName === "CAPTION"); + if (this.options.caption !== undefined) { + this._tableCaptions.push({ + nodeName: "CAPTION", + childNodes: [ + { + nodeName: "#text", + data: this.options.caption + } + ] + }); + } this.rows = new Rows(this); this.columns = new Columns(this); this.data = readTableData(this.options.data, this.dom, this.columns.settings, this.options.type, this.options.format); @@ -3300,9 +3327,8 @@ class DataTable { this.containerDOM.appendChild(this.dom); // Store the table dimensions this._rect = this.dom.getBoundingClientRect(); - // // Fix height + // Fix height this._fixHeight(); - // // Class names if (!this.options.header) { this.wrapperDOM.classList.add("no-header"); @@ -3329,12 +3355,15 @@ class DataTable { this.update(true); } _renderTable(renderOptions = {}) { - let newVirtualDOM = dataToVirtualDOM(this._tableAttributes, this.data.headings, (this.options.paging || this._searchQueries.length || this.columns._state.filters.length) && this._currentPage && this.pages.length && !renderOptions.noPaging ? - this.pages[this._currentPage - 1] : - this.data.data.map((row, index) => ({ - row, - index - })), this.columns.settings, this.columns._state, this.rows.cursor, this.options, renderOptions); + let rows; + const isPaged = (this.options.paging || this._searchQueries.length || this.columns._state.filters.length) && this._currentPage && this.pages.length && !renderOptions.noPaging; + if (isPaged) { + rows = this.pages[this._currentPage - 1]; + } + else { + rows = this.data.data.map((row, index) => ({ row, index })); + } + let newVirtualDOM = dataToVirtualDOM(this._tableAttributes, this.data.headings, rows, this.columns.settings, this.columns._state, this.rows.cursor, this.options, renderOptions, this._tableFooters, this._tableCaptions); if (this.options.tableRender) { const renderedTableVirtualDOM = this.options.tableRender(this.data, newVirtualDOM, "main"); if (renderedTableVirtualDOM) { @@ -3708,7 +3737,7 @@ class DataTable { if (this.options.paging && this.options.perPage > 0) { // Check for hidden columns this.pages = rows - .map((row, i) => i % this.options.perPage === 0 ? rows.slice(i, i + this.options.perPage) : null) + .map((_row, i) => i % this.options.perPage === 0 ? rows.slice(i, i + this.options.perPage) : null) .filter((page) => page); } else { @@ -3909,7 +3938,7 @@ class DataTable { this.options, { noColumnWidths: true, unhideHeader: true - }); + }, this._tableFooters, this._tableCaptions); if (this.options.tableRender) { const renderedTableVirtualDOM = this.options.tableRender(this.data, newTableVirtualDOM, "print"); if (renderedTableVirtualDOM) { diff --git a/docs/demos/dist/module.js.map b/docs/demos/dist/module.js.map index 6c3f4d34..7e94cc87 100644 --- a/docs/demos/dist/module.js.map +++ b/docs/demos/dist/module.js.map @@ -1 +1 @@ -{"version":3,"file":"module.js","sources":["../../../src/helpers.ts","../../../node_modules/.pnpm/diff-dom@5.1.2/node_modules/diff-dom/dist/module.js","../../../src/virtual_dom.ts","../../../node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js","../../../node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/plugin/customParseFormat.js","../../../src/date.ts","../../../src/read_data.ts","../../../src/rows.ts","../../../src/column_settings.ts","../../../src/columns.ts","../../../src/templates.ts","../../../src/config.ts","../../../src/virtual_pager_dom.ts","../../../src/datatable.ts","../../../src/convert/csv.ts","../../../src/convert/json.ts","../../../src/export/csv.ts","../../../src/export/json.ts","../../../src/export/sql.ts","../../../src/export/txt.ts","../../../src/editing/config.ts","../../../src/editing/helpers.ts","../../../src/editing/editor.ts","../../../src/column_filter/config.ts","../../../src/column_filter/column_filter.ts"],"sourcesContent":["import {elementNodeType, columnSettingsType, textNodeType} from \"./types\"\n\n/**\n * Check is item is object\n */\nexport const isObject = (val: (string | number | boolean | object | null | undefined )) => Object.prototype.toString.call(val) === \"[object Object]\"\n\n/**\n * Check for valid JSON string\n */\nexport const isJson = (str: string) => {\n let t = !1\n try {\n t = JSON.parse(str)\n } catch (e) {\n return !1\n }\n return !(null === t || (!Array.isArray(t) && !isObject(t))) && t\n}\n\n/**\n * Create DOM element node\n */\nexport const createElement = (nodeName: string, attrs?: { [key: string]: string}) => {\n const dom = document.createElement(nodeName)\n if (attrs && \"object\" == typeof attrs) {\n for (const attr in attrs) {\n if (\"html\" === attr) {\n dom.innerHTML = attrs[attr]\n } else {\n dom.setAttribute(attr, attrs[attr])\n }\n }\n }\n return dom\n}\n\nexport const objToText = (obj: (elementNodeType| textNodeType)) => {\n if ([\"#text\", \"#comment\"].includes(obj.nodeName)) {\n return (obj as textNodeType).data\n }\n if (obj.childNodes) {\n return obj.childNodes.map((childNode: (elementNodeType | textNodeType)) => objToText(childNode)).join(\"\")\n }\n return \"\"\n}\n\n\nexport const escapeText = function(text: string) {\n return text\n .replace(/&/g, \"&\")\n .replace(//g, \">\")\n .replace(/\"/g, \""\")\n}\n\n\nexport const visibleToColumnIndex = function(visibleIndex: number, columns: columnSettingsType[]) {\n let counter = 0\n let columnIndex = 0\n while (counter < (visibleIndex+1)) {\n const columnSettings = columns[columnIndex]\n if (!columnSettings.hidden) {\n counter += 1\n }\n columnIndex += 1\n }\n return columnIndex-1\n}\n\nexport const columnToVisibleIndex = function(columnIndex: number, columns: columnSettingsType[]) {\n let visibleIndex = columnIndex\n let counter = 0\n while (counter < columnIndex) {\n const columnSettings = columns[counter]\n if (columnSettings.hidden) {\n visibleIndex -= 1\n }\n counter++\n }\n return visibleIndex\n}\n","var Diff = /** @class */ (function () {\n function Diff(options) {\n var _this = this;\n if (options === void 0) { options = {}; }\n Object.entries(options).forEach(function (_a) {\n var key = _a[0], value = _a[1];\n return (_this[key] = value);\n });\n }\n Diff.prototype.toString = function () {\n return JSON.stringify(this);\n };\n Diff.prototype.setValue = function (aKey, aValue) {\n this[aKey] = aValue;\n return this;\n };\n return Diff;\n}());\nfunction checkElementType(element) {\n var arguments$1 = arguments;\n\n var elementTypeNames = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n elementTypeNames[_i - 1] = arguments$1[_i];\n }\n if (typeof element === \"undefined\" || element === null) {\n return false;\n }\n return elementTypeNames.some(function (elementTypeName) {\n var _a, _b;\n // We need to check if the specified type is defined\n // because otherwise instanceof throws an exception.\n return typeof ((_b = (_a = element === null || element === void 0 ? void 0 : element.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b[elementTypeName]) ===\n \"function\" &&\n element instanceof\n element.ownerDocument.defaultView[elementTypeName];\n });\n}\n\nfunction objToNode(objNode, insideSvg, options) {\n var node;\n if (objNode.nodeName === \"#text\") {\n node = options.document.createTextNode(objNode.data);\n }\n else if (objNode.nodeName === \"#comment\") {\n node = options.document.createComment(objNode.data);\n }\n else {\n if (insideSvg) {\n node = options.document.createElementNS(\"http://www.w3.org/2000/svg\", objNode.nodeName);\n }\n else if (objNode.nodeName.toLowerCase() === \"svg\") {\n node = options.document.createElementNS(\"http://www.w3.org/2000/svg\", \"svg\");\n insideSvg = true;\n }\n else {\n node = options.document.createElement(objNode.nodeName);\n }\n if (objNode.attributes) {\n Object.entries(objNode.attributes).forEach(function (_a) {\n var key = _a[0], value = _a[1];\n return node.setAttribute(key, value);\n });\n }\n if (objNode.childNodes) {\n node = node;\n objNode.childNodes.forEach(function (childNode) {\n return node.appendChild(objToNode(childNode, insideSvg, options));\n });\n }\n if (options.valueDiffing) {\n if (objNode.value &&\n checkElementType(node, \"HTMLButtonElement\", \"HTMLDataElement\", \"HTMLInputElement\", \"HTMLLIElement\", \"HTMLMeterElement\", \"HTMLOptionElement\", \"HTMLProgressElement\", \"HTMLParamElement\")) {\n node.value = objNode.value;\n }\n if (objNode.checked && checkElementType(node, \"HTMLInputElement\")) {\n node.checked = objNode.checked;\n }\n if (objNode.selected &&\n checkElementType(node, \"HTMLOptionElement\")) {\n node.selected = objNode.selected;\n }\n }\n }\n return node;\n}\n\n// ===== Apply a diff =====\nvar getFromRoute = function (node, route) {\n route = route.slice();\n while (route.length > 0) {\n var c = route.splice(0, 1)[0];\n node = node.childNodes[c];\n }\n return node;\n};\nfunction applyDiff(tree, diff, options) {\n var action = diff[options._const.action];\n var route = diff[options._const.route];\n var node;\n if (![options._const.addElement, options._const.addTextElement].includes(action)) {\n // For adding nodes, we calculate the route later on. It's different because it includes the position of the newly added item.\n node = getFromRoute(tree, route);\n }\n var newNode;\n var reference;\n var nodeArray;\n // pre-diff hook\n var info = {\n diff: diff,\n node: node,\n };\n if (options.preDiffApply(info)) {\n return true;\n }\n switch (action) {\n case options._const.addAttribute:\n if (!node || !checkElementType(node, \"Element\")) {\n return false;\n }\n node.setAttribute(diff[options._const.name], diff[options._const.value]);\n break;\n case options._const.modifyAttribute:\n if (!node || !checkElementType(node, \"Element\")) {\n return false;\n }\n node.setAttribute(diff[options._const.name], diff[options._const.newValue]);\n if (checkElementType(node, \"HTMLInputElement\") &&\n diff[options._const.name] === \"value\") {\n node.value = diff[options._const.newValue];\n }\n break;\n case options._const.removeAttribute:\n if (!node || !checkElementType(node, \"Element\")) {\n return false;\n }\n node.removeAttribute(diff[options._const.name]);\n break;\n case options._const.modifyTextElement:\n if (!node || !checkElementType(node, \"Text\")) {\n return false;\n }\n options.textDiff(node, node.data, diff[options._const.oldValue], diff[options._const.newValue]);\n if (checkElementType(node.parentNode, \"HTMLTextAreaElement\")) {\n node.parentNode.value = diff[options._const.newValue];\n }\n break;\n case options._const.modifyValue:\n if (!node || typeof node.value === \"undefined\") {\n return false;\n }\n node.value = diff[options._const.newValue];\n break;\n case options._const.modifyComment:\n if (!node || !checkElementType(node, \"Comment\")) {\n return false;\n }\n options.textDiff(node, node.data, diff[options._const.oldValue], diff[options._const.newValue]);\n break;\n case options._const.modifyChecked:\n if (!node || typeof node.checked === \"undefined\") {\n return false;\n }\n node.checked = diff[options._const.newValue];\n break;\n case options._const.modifySelected:\n if (!node || typeof node.selected === \"undefined\") {\n return false;\n }\n node.selected = diff[options._const.newValue];\n break;\n case options._const.replaceElement: {\n var insideSvg = diff[options._const.newValue].nodeName.toLowerCase() === \"svg\" ||\n node.parentNode.namespaceURI === \"http://www.w3.org/2000/svg\";\n node.parentNode.replaceChild(objToNode(diff[options._const.newValue], insideSvg, options), node);\n break;\n }\n case options._const.relocateGroup:\n nodeArray = Array.apply(void 0, new Array(diff[options._const.groupLength])).map(function () {\n return node.removeChild(node.childNodes[diff[options._const.from]]);\n });\n nodeArray.forEach(function (childNode, index) {\n if (index === 0) {\n reference =\n node.childNodes[diff[options._const.to]];\n }\n node.insertBefore(childNode, reference || null);\n });\n break;\n case options._const.removeElement:\n node.parentNode.removeChild(node);\n break;\n case options._const.addElement: {\n var parentRoute = route.slice();\n var c = parentRoute.splice(parentRoute.length - 1, 1)[0];\n node = getFromRoute(tree, parentRoute);\n if (!checkElementType(node, \"Element\")) {\n return false;\n }\n node.insertBefore(objToNode(diff[options._const.element], node.namespaceURI === \"http://www.w3.org/2000/svg\", options), node.childNodes[c] || null);\n break;\n }\n case options._const.removeTextElement: {\n if (!node || node.nodeType !== 3) {\n return false;\n }\n var parentNode = node.parentNode;\n parentNode.removeChild(node);\n if (checkElementType(parentNode, \"HTMLTextAreaElement\")) {\n parentNode.value = \"\";\n }\n break;\n }\n case options._const.addTextElement: {\n var parentRoute = route.slice();\n var c = parentRoute.splice(parentRoute.length - 1, 1)[0];\n newNode = options.document.createTextNode(diff[options._const.value]);\n node = getFromRoute(tree, parentRoute);\n if (!node.childNodes) {\n return false;\n }\n node.insertBefore(newNode, node.childNodes[c] || null);\n if (checkElementType(node.parentNode, \"HTMLTextAreaElement\")) {\n node.parentNode.value = diff[options._const.value];\n }\n break;\n }\n default:\n console.log(\"unknown action\");\n }\n // if a new node was created, we might be interested in its\n // post diff hook\n options.postDiffApply({\n diff: info.diff,\n node: info.node,\n newNode: newNode,\n });\n return true;\n}\nfunction applyDOM(tree, diffs, options) {\n return diffs.every(function (diff) {\n return applyDiff(tree, diff, options);\n });\n}\n\n// ===== Undo a diff =====\nfunction swap(obj, p1, p2) {\n var tmp = obj[p1];\n obj[p1] = obj[p2];\n obj[p2] = tmp;\n}\nfunction undoDiff(tree, diff, options) {\n switch (diff[options._const.action]) {\n case options._const.addAttribute:\n diff[options._const.action] = options._const.removeAttribute;\n applyDiff(tree, diff, options);\n break;\n case options._const.modifyAttribute:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.removeAttribute:\n diff[options._const.action] = options._const.addAttribute;\n applyDiff(tree, diff, options);\n break;\n case options._const.modifyTextElement:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.modifyValue:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.modifyComment:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.modifyChecked:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.modifySelected:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.replaceElement:\n swap(diff, options._const.oldValue, options._const.newValue);\n applyDiff(tree, diff, options);\n break;\n case options._const.relocateGroup:\n swap(diff, options._const.from, options._const.to);\n applyDiff(tree, diff, options);\n break;\n case options._const.removeElement:\n diff[options._const.action] = options._const.addElement;\n applyDiff(tree, diff, options);\n break;\n case options._const.addElement:\n diff[options._const.action] = options._const.removeElement;\n applyDiff(tree, diff, options);\n break;\n case options._const.removeTextElement:\n diff[options._const.action] = options._const.addTextElement;\n applyDiff(tree, diff, options);\n break;\n case options._const.addTextElement:\n diff[options._const.action] = options._const.removeTextElement;\n applyDiff(tree, diff, options);\n break;\n default:\n console.log(\"unknown action\");\n }\n}\nfunction undoDOM(tree, diffs, options) {\n diffs = diffs.slice();\n diffs.reverse();\n diffs.forEach(function (diff) {\n undoDiff(tree, diff, options);\n });\n}\n\n/******************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise, SuppressedError, Symbol */\r\n\r\n\r\nvar __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\n var arguments$1 = arguments;\n\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments$1[i];\r\n for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p)) { t[p] = s[p]; } }\r\n }\r\n return t;\r\n };\r\n return __assign.apply(this, arguments);\r\n};\r\n\r\ntypeof SuppressedError === \"function\" ? SuppressedError : function (error, suppressed, message) {\r\n var e = new Error(message);\r\n return e.name = \"SuppressedError\", e.error = error, e.suppressed = suppressed, e;\r\n};\n\nvar elementDescriptors = function (el) {\n var output = [];\n output.push(el.nodeName);\n if (el.nodeName !== \"#text\" && el.nodeName !== \"#comment\") {\n el = el;\n if (el.attributes) {\n if (el.attributes[\"class\"]) {\n output.push(\"\".concat(el.nodeName, \".\").concat(el.attributes[\"class\"].replace(/ /g, \".\")));\n }\n if (el.attributes.id) {\n output.push(\"\".concat(el.nodeName, \"#\").concat(el.attributes.id));\n }\n }\n }\n return output;\n};\nvar findUniqueDescriptors = function (li) {\n var uniqueDescriptors = {};\n var duplicateDescriptors = {};\n li.forEach(function (node) {\n elementDescriptors(node).forEach(function (descriptor) {\n var inUnique = descriptor in uniqueDescriptors;\n var inDupes = descriptor in duplicateDescriptors;\n if (!inUnique && !inDupes) {\n uniqueDescriptors[descriptor] = true;\n }\n else if (inUnique) {\n delete uniqueDescriptors[descriptor];\n duplicateDescriptors[descriptor] = true;\n }\n });\n });\n return uniqueDescriptors;\n};\nvar uniqueInBoth = function (l1, l2) {\n var l1Unique = findUniqueDescriptors(l1);\n var l2Unique = findUniqueDescriptors(l2);\n var inBoth = {};\n Object.keys(l1Unique).forEach(function (key) {\n if (l2Unique[key]) {\n inBoth[key] = true;\n }\n });\n return inBoth;\n};\nvar removeDone = function (tree) {\n delete tree.outerDone;\n delete tree.innerDone;\n delete tree.valueDone;\n if (tree.childNodes) {\n return tree.childNodes.every(removeDone);\n }\n else {\n return true;\n }\n};\nvar cleanNode = function (diffNode) {\n if (Object.prototype.hasOwnProperty.call(diffNode, \"data\")) {\n var textNode = {\n nodeName: diffNode.nodeName === \"#text\" ? \"#text\" : \"#comment\",\n data: diffNode.data,\n };\n return textNode;\n }\n else {\n var elementNode = {\n nodeName: diffNode.nodeName,\n };\n diffNode = diffNode;\n if (Object.prototype.hasOwnProperty.call(diffNode, \"attributes\")) {\n elementNode.attributes = __assign({}, diffNode.attributes);\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"checked\")) {\n elementNode.checked = diffNode.checked;\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"value\")) {\n elementNode.value = diffNode.value;\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"selected\")) {\n elementNode.selected = diffNode.selected;\n }\n if (Object.prototype.hasOwnProperty.call(diffNode, \"childNodes\")) {\n elementNode.childNodes = diffNode.childNodes.map(function (diffChildNode) {\n return cleanNode(diffChildNode);\n });\n }\n return elementNode;\n }\n};\nvar isEqual = function (e1, e2) {\n if (![\"nodeName\", \"value\", \"checked\", \"selected\", \"data\"].every(function (element) {\n if (e1[element] !== e2[element]) {\n return false;\n }\n return true;\n })) {\n return false;\n }\n if (Object.prototype.hasOwnProperty.call(e1, \"data\")) {\n // Comment or Text\n return true;\n }\n e1 = e1;\n e2 = e2;\n if (Boolean(e1.attributes) !== Boolean(e2.attributes)) {\n return false;\n }\n if (Boolean(e1.childNodes) !== Boolean(e2.childNodes)) {\n return false;\n }\n if (e1.attributes) {\n var e1Attributes = Object.keys(e1.attributes);\n var e2Attributes = Object.keys(e2.attributes);\n if (e1Attributes.length !== e2Attributes.length) {\n return false;\n }\n if (!e1Attributes.every(function (attribute) {\n if (e1.attributes[attribute] !==\n e2.attributes[attribute]) {\n return false;\n }\n return true;\n })) {\n return false;\n }\n }\n if (e1.childNodes) {\n if (e1.childNodes.length !== e2.childNodes.length) {\n return false;\n }\n if (!e1.childNodes.every(function (childNode, index) {\n return isEqual(childNode, e2.childNodes[index]);\n })) {\n return false;\n }\n }\n return true;\n};\nvar roughlyEqual = function (e1, e2, uniqueDescriptors, sameSiblings, preventRecursion) {\n if (preventRecursion === void 0) { preventRecursion = false; }\n if (!e1 || !e2) {\n return false;\n }\n if (e1.nodeName !== e2.nodeName) {\n return false;\n }\n if ([\"#text\", \"#comment\"].includes(e1.nodeName)) {\n // Note that we initially don't care what the text content of a node is,\n // the mere fact that it's the same tag and \"has text\" means it's roughly\n // equal, and then we can find out the true text difference later.\n return preventRecursion\n ? true\n : e1.data === e2.data;\n }\n e1 = e1;\n e2 = e2;\n if (e1.nodeName in uniqueDescriptors) {\n return true;\n }\n if (e1.attributes && e2.attributes) {\n if (e1.attributes.id) {\n if (e1.attributes.id !== e2.attributes.id) {\n return false;\n }\n else {\n var idDescriptor = \"\".concat(e1.nodeName, \"#\").concat(e1.attributes.id);\n if (idDescriptor in uniqueDescriptors) {\n return true;\n }\n }\n }\n if (e1.attributes[\"class\"] &&\n e1.attributes[\"class\"] === e2.attributes[\"class\"]) {\n var classDescriptor = \"\".concat(e1.nodeName, \".\").concat(e1.attributes[\"class\"].replace(/ /g, \".\"));\n if (classDescriptor in uniqueDescriptors) {\n return true;\n }\n }\n }\n if (sameSiblings) {\n return true;\n }\n var nodeList1 = e1.childNodes ? e1.childNodes.slice().reverse() : [];\n var nodeList2 = e2.childNodes ? e2.childNodes.slice().reverse() : [];\n if (nodeList1.length !== nodeList2.length) {\n return false;\n }\n if (preventRecursion) {\n return nodeList1.every(function (element, index) {\n return element.nodeName === nodeList2[index].nodeName;\n });\n }\n else {\n // note: we only allow one level of recursion at any depth. If 'preventRecursion'\n // was not set, we must explicitly force it to true for child iterations.\n var childUniqueDescriptors_1 = uniqueInBoth(nodeList1, nodeList2);\n return nodeList1.every(function (element, index) {\n return roughlyEqual(element, nodeList2[index], childUniqueDescriptors_1, true, true);\n });\n }\n};\n/**\n * based on https://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest_common_substring#JavaScript\n */\nvar findCommonSubsets = function (c1, c2, marked1, marked2) {\n var lcsSize = 0;\n var index = [];\n var c1Length = c1.length;\n var c2Length = c2.length;\n var // set up the matching table\n matches = Array.apply(void 0, new Array(c1Length + 1)).map(function () { return []; });\n var uniqueDescriptors = uniqueInBoth(c1, c2);\n var // If all of the elements are the same tag, id and class, then we can\n // consider them roughly the same even if they have a different number of\n // children. This will reduce removing and re-adding similar elements.\n subsetsSame = c1Length === c2Length;\n if (subsetsSame) {\n c1.some(function (element, i) {\n var c1Desc = elementDescriptors(element);\n var c2Desc = elementDescriptors(c2[i]);\n if (c1Desc.length !== c2Desc.length) {\n subsetsSame = false;\n return true;\n }\n c1Desc.some(function (description, i) {\n if (description !== c2Desc[i]) {\n subsetsSame = false;\n return true;\n }\n });\n if (!subsetsSame) {\n return true;\n }\n });\n }\n // fill the matches with distance values\n for (var c1Index = 0; c1Index < c1Length; c1Index++) {\n var c1Element = c1[c1Index];\n for (var c2Index = 0; c2Index < c2Length; c2Index++) {\n var c2Element = c2[c2Index];\n if (!marked1[c1Index] &&\n !marked2[c2Index] &&\n roughlyEqual(c1Element, c2Element, uniqueDescriptors, subsetsSame)) {\n matches[c1Index + 1][c2Index + 1] = matches[c1Index][c2Index]\n ? matches[c1Index][c2Index] + 1\n : 1;\n if (matches[c1Index + 1][c2Index + 1] >= lcsSize) {\n lcsSize = matches[c1Index + 1][c2Index + 1];\n index = [c1Index + 1, c2Index + 1];\n }\n }\n else {\n matches[c1Index + 1][c2Index + 1] = 0;\n }\n }\n }\n if (lcsSize === 0) {\n return false;\n }\n return {\n oldValue: index[0] - lcsSize,\n newValue: index[1] - lcsSize,\n length: lcsSize,\n };\n};\nvar makeBooleanArray = function (n, v) {\n return Array.apply(void 0, new Array(n)).map(function () { return v; });\n};\n/**\n * Generate arrays that indicate which node belongs to which subset,\n * or whether it's actually an orphan node, existing in only one\n * of the two trees, rather than somewhere in both.\n *\n * So if t1 =
, t2 =
.\n * The longest subset is \"
\" (length 2), so it will group 0.\n * The second longest is \"\" (length 1), so it will be group 1.\n * gaps1 will therefore be [1,0,0] and gaps2 [0,0,1].\n *\n * If an element is not part of any group, it will stay being 'true', which\n * is the initial value. For example:\n * t1 =


, t2 =
\n *\n * The \"

\" and \"\" do only show up in one of the two and will\n * therefore be marked by \"true\". The remaining parts are parts of the\n * groups 0 and 1:\n * gaps1 = [1, true, 0, 0], gaps2 = [true, 0, 0, 1]\n *\n */\nvar getGapInformation = function (t1, t2, stable) {\n var gaps1 = t1.childNodes\n ? makeBooleanArray(t1.childNodes.length, true)\n : [];\n var gaps2 = t2.childNodes\n ? makeBooleanArray(t2.childNodes.length, true)\n : [];\n var group = 0;\n // give elements from the same subset the same group number\n stable.forEach(function (subset) {\n var endOld = subset.oldValue + subset.length;\n var endNew = subset.newValue + subset.length;\n for (var j = subset.oldValue; j < endOld; j += 1) {\n gaps1[j] = group;\n }\n for (var j = subset.newValue; j < endNew; j += 1) {\n gaps2[j] = group;\n }\n group += 1;\n });\n return {\n gaps1: gaps1,\n gaps2: gaps2,\n };\n};\n/**\n * Find all matching subsets, based on immediate child differences only.\n */\nvar markBoth = function (marked1, marked2, subset, i) {\n marked1[subset.oldValue + i] = true;\n marked2[subset.newValue + i] = true;\n};\nvar markSubTrees = function (oldTree, newTree) {\n // note: the child lists are views, and so update as we update old/newTree\n var oldChildren = oldTree.childNodes ? oldTree.childNodes : [];\n var newChildren = newTree.childNodes ? newTree.childNodes : [];\n var marked1 = makeBooleanArray(oldChildren.length, false);\n var marked2 = makeBooleanArray(newChildren.length, false);\n var subsets = [];\n var returnIndex = function () {\n return arguments[1];\n };\n var foundAllSubsets = false;\n var _loop_1 = function () {\n var subset = findCommonSubsets(oldChildren, newChildren, marked1, marked2);\n if (subset) {\n subsets.push(subset);\n var subsetArray = Array.apply(void 0, new Array(subset.length)).map(returnIndex);\n subsetArray.forEach(function (item) {\n return markBoth(marked1, marked2, subset, item);\n });\n }\n else {\n foundAllSubsets = true;\n }\n };\n while (!foundAllSubsets) {\n _loop_1();\n }\n oldTree.subsets = subsets;\n oldTree.subsetsAge = 100;\n return subsets;\n};\nvar DiffTracker = /** @class */ (function () {\n function DiffTracker() {\n this.list = [];\n }\n DiffTracker.prototype.add = function (diffs) {\n var _a;\n (_a = this.list).push.apply(_a, diffs);\n };\n DiffTracker.prototype.forEach = function (fn) {\n this.list.forEach(function (li) { return fn(li); });\n };\n return DiffTracker;\n}());\n\n// ===== Apply a virtual diff =====\nfunction getFromVirtualRoute(tree, route) {\n var node = tree;\n var parentNode;\n var nodeIndex;\n route = route.slice();\n while (route.length > 0) {\n nodeIndex = route.splice(0, 1)[0];\n parentNode = node;\n node = node.childNodes ? node.childNodes[nodeIndex] : undefined;\n }\n return {\n node: node,\n parentNode: parentNode,\n nodeIndex: nodeIndex,\n };\n}\nfunction applyVirtualDiff(tree, diff, options) {\n var _a;\n var node, parentNode, nodeIndex;\n if (![options._const.addElement, options._const.addTextElement].includes(diff[options._const.action])) {\n // For adding nodes, we calculate the route later on. It's different because it includes the position of the newly added item.\n var routeInfo = getFromVirtualRoute(tree, diff[options._const.route]);\n node = routeInfo.node;\n parentNode = routeInfo.parentNode;\n nodeIndex = routeInfo.nodeIndex;\n }\n var newSubsets = [];\n // pre-diff hook\n var info = {\n diff: diff,\n node: node,\n };\n if (options.preVirtualDiffApply(info)) {\n return true;\n }\n var newNode;\n var nodeArray;\n var route;\n switch (diff[options._const.action]) {\n case options._const.addAttribute:\n if (!node.attributes) {\n node.attributes = {};\n }\n node.attributes[diff[options._const.name]] =\n diff[options._const.value];\n if (diff[options._const.name] === \"checked\") {\n node.checked = true;\n }\n else if (diff[options._const.name] === \"selected\") {\n node.selected = true;\n }\n else if (node.nodeName === \"INPUT\" &&\n diff[options._const.name] === \"value\") {\n node.value = diff[options._const.value];\n }\n break;\n case options._const.modifyAttribute:\n node.attributes[diff[options._const.name]] =\n diff[options._const.newValue];\n break;\n case options._const.removeAttribute:\n delete node.attributes[diff[options._const.name]];\n if (Object.keys(node.attributes).length === 0) {\n delete node.attributes;\n }\n if (diff[options._const.name] === \"checked\") {\n node.checked = false;\n }\n else if (diff[options._const.name] === \"selected\") {\n delete node.selected;\n }\n else if (node.nodeName === \"INPUT\" &&\n diff[options._const.name] === \"value\") {\n delete node.value;\n }\n break;\n case options._const.modifyTextElement:\n node.data = diff[options._const.newValue];\n if (parentNode.nodeName === \"TEXTAREA\") {\n parentNode.value = diff[options._const.newValue];\n }\n break;\n case options._const.modifyValue:\n node.value = diff[options._const.newValue];\n break;\n case options._const.modifyComment:\n node.data = diff[options._const.newValue];\n break;\n case options._const.modifyChecked:\n node.checked = diff[options._const.newValue];\n break;\n case options._const.modifySelected:\n node.selected = diff[options._const.newValue];\n break;\n case options._const.replaceElement:\n newNode = cleanNode(diff[options._const.newValue]);\n parentNode.childNodes[nodeIndex] = newNode;\n break;\n case options._const.relocateGroup:\n nodeArray = node.childNodes\n .splice(diff[options._const.from], diff[options._const.groupLength])\n .reverse();\n nodeArray.forEach(function (movedNode) {\n return node.childNodes.splice(diff[options._const.to], 0, movedNode);\n });\n if (node.subsets) {\n node.subsets.forEach(function (map) {\n if (diff[options._const.from] < diff[options._const.to] &&\n map.oldValue <= diff[options._const.to] &&\n map.oldValue > diff[options._const.from]) {\n map.oldValue -= diff[options._const.groupLength];\n var splitLength = map.oldValue + map.length - diff[options._const.to];\n if (splitLength > 0) {\n // new insertion splits map.\n newSubsets.push({\n oldValue: diff[options._const.to] +\n diff[options._const.groupLength],\n newValue: map.newValue + map.length - splitLength,\n length: splitLength,\n });\n map.length -= splitLength;\n }\n }\n else if (diff[options._const.from] > diff[options._const.to] &&\n map.oldValue > diff[options._const.to] &&\n map.oldValue < diff[options._const.from]) {\n map.oldValue += diff[options._const.groupLength];\n var splitLength = map.oldValue + map.length - diff[options._const.to];\n if (splitLength > 0) {\n // new insertion splits map.\n newSubsets.push({\n oldValue: diff[options._const.to] +\n diff[options._const.groupLength],\n newValue: map.newValue + map.length - splitLength,\n length: splitLength,\n });\n map.length -= splitLength;\n }\n }\n else if (map.oldValue === diff[options._const.from]) {\n map.oldValue = diff[options._const.to];\n }\n });\n }\n break;\n case options._const.removeElement:\n parentNode.childNodes.splice(nodeIndex, 1);\n if (parentNode.subsets) {\n parentNode.subsets.forEach(function (map) {\n if (map.oldValue > nodeIndex) {\n map.oldValue -= 1;\n }\n else if (map.oldValue === nodeIndex) {\n map.delete = true;\n }\n else if (map.oldValue < nodeIndex &&\n map.oldValue + map.length > nodeIndex) {\n if (map.oldValue + map.length - 1 === nodeIndex) {\n map.length--;\n }\n else {\n newSubsets.push({\n newValue: map.newValue + nodeIndex - map.oldValue,\n oldValue: nodeIndex,\n length: map.length - nodeIndex + map.oldValue - 1,\n });\n map.length = nodeIndex - map.oldValue;\n }\n }\n });\n }\n node = parentNode;\n break;\n case options._const.addElement: {\n route = diff[options._const.route].slice();\n var c_1 = route.splice(route.length - 1, 1)[0];\n node = (_a = getFromVirtualRoute(tree, route)) === null || _a === void 0 ? void 0 : _a.node;\n newNode = cleanNode(diff[options._const.element]);\n if (!node.childNodes) {\n node.childNodes = [];\n }\n if (c_1 >= node.childNodes.length) {\n node.childNodes.push(newNode);\n }\n else {\n node.childNodes.splice(c_1, 0, newNode);\n }\n if (node.subsets) {\n node.subsets.forEach(function (map) {\n if (map.oldValue >= c_1) {\n map.oldValue += 1;\n }\n else if (map.oldValue < c_1 &&\n map.oldValue + map.length > c_1) {\n var splitLength = map.oldValue + map.length - c_1;\n newSubsets.push({\n newValue: map.newValue + map.length - splitLength,\n oldValue: c_1 + 1,\n length: splitLength,\n });\n map.length -= splitLength;\n }\n });\n }\n break;\n }\n case options._const.removeTextElement:\n parentNode.childNodes.splice(nodeIndex, 1);\n if (parentNode.nodeName === \"TEXTAREA\") {\n delete parentNode.value;\n }\n if (parentNode.subsets) {\n parentNode.subsets.forEach(function (map) {\n if (map.oldValue > nodeIndex) {\n map.oldValue -= 1;\n }\n else if (map.oldValue === nodeIndex) {\n map.delete = true;\n }\n else if (map.oldValue < nodeIndex &&\n map.oldValue + map.length > nodeIndex) {\n if (map.oldValue + map.length - 1 === nodeIndex) {\n map.length--;\n }\n else {\n newSubsets.push({\n newValue: map.newValue + nodeIndex - map.oldValue,\n oldValue: nodeIndex,\n length: map.length - nodeIndex + map.oldValue - 1,\n });\n map.length = nodeIndex - map.oldValue;\n }\n }\n });\n }\n node = parentNode;\n break;\n case options._const.addTextElement: {\n route = diff[options._const.route].slice();\n var c_2 = route.splice(route.length - 1, 1)[0];\n newNode = {\n nodeName: \"#text\",\n data: diff[options._const.value],\n };\n node = getFromVirtualRoute(tree, route).node;\n if (!node.childNodes) {\n node.childNodes = [];\n }\n if (c_2 >= node.childNodes.length) {\n node.childNodes.push(newNode);\n }\n else {\n node.childNodes.splice(c_2, 0, newNode);\n }\n if (node.nodeName === \"TEXTAREA\") {\n node.value = diff[options._const.newValue];\n }\n if (node.subsets) {\n node.subsets.forEach(function (map) {\n if (map.oldValue >= c_2) {\n map.oldValue += 1;\n }\n if (map.oldValue < c_2 && map.oldValue + map.length > c_2) {\n var splitLength = map.oldValue + map.length - c_2;\n newSubsets.push({\n newValue: map.newValue + map.length - splitLength,\n oldValue: c_2 + 1,\n length: splitLength,\n });\n map.length -= splitLength;\n }\n });\n }\n break;\n }\n default:\n console.log(\"unknown action\");\n }\n if (node.subsets) {\n node.subsets = node.subsets.filter(function (map) { return !map.delete && map.oldValue !== map.newValue; });\n if (newSubsets.length) {\n node.subsets = node.subsets.concat(newSubsets);\n }\n }\n options.postVirtualDiffApply({\n node: info.node,\n diff: info.diff,\n newNode: newNode,\n });\n return;\n}\nfunction applyVirtual(tree, diffs, options) {\n diffs.forEach(function (diff) {\n applyVirtualDiff(tree, diff, options);\n });\n return true;\n}\n\nfunction nodeToObj(aNode, options) {\n if (options === void 0) { options = { valueDiffing: true }; }\n var objNode = {\n nodeName: aNode.nodeName,\n };\n if (checkElementType(aNode, \"Text\", \"Comment\")) {\n objNode.data = aNode.data;\n }\n else {\n if (aNode.attributes && aNode.attributes.length > 0) {\n objNode.attributes = {};\n var nodeArray = Array.prototype.slice.call(aNode.attributes);\n nodeArray.forEach(function (attribute) {\n return (objNode.attributes[attribute.name] = attribute.value);\n });\n }\n if (aNode.childNodes && aNode.childNodes.length > 0) {\n objNode.childNodes = [];\n var nodeArray = Array.prototype.slice.call(aNode.childNodes);\n nodeArray.forEach(function (childNode) {\n return objNode.childNodes.push(nodeToObj(childNode, options));\n });\n }\n if (options.valueDiffing) {\n if (checkElementType(aNode, \"HTMLTextAreaElement\")) {\n objNode.value = aNode.value;\n }\n if (checkElementType(aNode, \"HTMLInputElement\") &&\n [\"radio\", \"checkbox\"].includes(aNode.type.toLowerCase()) &&\n aNode.checked !== undefined) {\n objNode.checked = aNode.checked;\n }\n else if (checkElementType(aNode, \"HTMLButtonElement\", \"HTMLDataElement\", \"HTMLInputElement\", \"HTMLLIElement\", \"HTMLMeterElement\", \"HTMLOptionElement\", \"HTMLProgressElement\", \"HTMLParamElement\")) {\n objNode.value = aNode.value;\n }\n if (checkElementType(aNode, \"HTMLOptionElement\")) {\n objNode.selected = aNode.selected;\n }\n }\n }\n return objNode;\n}\n\n// from html-parse-stringify (MIT)\nvar tagRE = /<\\s*\\/*[a-zA-Z:_][a-zA-Z0-9:_\\-.]*\\s*(?:\"[^\"]*\"['\"]*|'[^']*'['\"]*|[^'\"/>])*\\/*\\s*>|/g;\nvar attrRE = /\\s([^'\"/\\s><]+?)[\\s/>]|([^\\s=]+)=\\s?(\".*?\"|'.*?')/g;\nfunction unescape(string) {\n return string\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/&/g, \"&\");\n}\n// create optimized lookup object for\n// void elements as listed here:\n// https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements\nvar lookup = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n menuItem: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n};\nvar parseTag = function (tag, caseSensitive) {\n var res = {\n nodeName: \"\",\n attributes: {},\n };\n var voidElement = false;\n var type = \"tag\";\n var tagMatch = tag.match(/<\\/?([^\\s]+?)[/\\s>]/);\n if (tagMatch) {\n res.nodeName =\n caseSensitive || tagMatch[1] === \"svg\"\n ? tagMatch[1]\n : tagMatch[1].toUpperCase();\n if (lookup[tagMatch[1]] || tag.charAt(tag.length - 2) === \"/\") {\n voidElement = true;\n }\n // handle comment tag\n if (res.nodeName.startsWith(\"!--\")) {\n var endIndex = tag.indexOf(\"-->\");\n return {\n type: \"comment\",\n node: {\n nodeName: \"#comment\",\n data: endIndex !== -1 ? tag.slice(4, endIndex) : \"\",\n },\n voidElement: voidElement,\n };\n }\n }\n var reg = new RegExp(attrRE);\n var result = null;\n var done = false;\n while (!done) {\n result = reg.exec(tag);\n if (result === null) {\n done = true;\n }\n else if (result[0].trim()) {\n if (result[1]) {\n var attr = result[1].trim();\n var arr = [attr, \"\"];\n if (attr.indexOf(\"=\") > -1)\n { arr = attr.split(\"=\"); }\n res.attributes[arr[0]] = arr[1];\n reg.lastIndex--;\n }\n else if (result[2])\n { res.attributes[result[2]] = result[3]\n .trim()\n .substring(1, result[3].length - 1); }\n }\n }\n return {\n type: type,\n node: res,\n voidElement: voidElement,\n };\n};\nvar stringToObj = function (html, options) {\n if (options === void 0) { options = {\n valueDiffing: true,\n caseSensitive: false,\n }; }\n var result = [];\n var current;\n var level = -1;\n var arr = [];\n var inComponent = false, insideSvg = false;\n // handle text at top level\n if (html.indexOf(\"<\") !== 0) {\n var end = html.indexOf(\"<\");\n result.push({\n nodeName: \"#text\",\n data: end === -1 ? html : html.substring(0, end),\n });\n }\n html.replace(tagRE, function (tag, index) {\n var isOpen = tag.charAt(1) !== \"/\";\n var isComment = tag.startsWith(\"/g;\nvar attrRE = /\\s([^'\"/\\s><]+?)[\\s/>]|([^\\s=]+)=\\s?(\".*?\"|'.*?')/g;\nfunction unescape(string) {\n return string\n .replace(/</g, \"<\")\n .replace(/>/g, \">\")\n .replace(/&/g, \"&\");\n}\n// create optimized lookup object for\n// void elements as listed here:\n// https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements\nvar lookup = {\n area: true,\n base: true,\n br: true,\n col: true,\n embed: true,\n hr: true,\n img: true,\n input: true,\n keygen: true,\n link: true,\n menuItem: true,\n meta: true,\n param: true,\n source: true,\n track: true,\n wbr: true,\n};\nvar parseTag = function (tag, caseSensitive) {\n var res = {\n nodeName: \"\",\n attributes: {},\n };\n var voidElement = false;\n var type = \"tag\";\n var tagMatch = tag.match(/<\\/?([^\\s]+?)[/\\s>]/);\n if (tagMatch) {\n res.nodeName =\n caseSensitive || tagMatch[1] === \"svg\"\n ? tagMatch[1]\n : tagMatch[1].toUpperCase();\n if (lookup[tagMatch[1]] || tag.charAt(tag.length - 2) === \"/\") {\n voidElement = true;\n }\n // handle comment tag\n if (res.nodeName.startsWith(\"!--\")) {\n var endIndex = tag.indexOf(\"-->\");\n return {\n type: \"comment\",\n node: {\n nodeName: \"#comment\",\n data: endIndex !== -1 ? tag.slice(4, endIndex) : \"\",\n },\n voidElement: voidElement,\n };\n }\n }\n var reg = new RegExp(attrRE);\n var result = null;\n var done = false;\n while (!done) {\n result = reg.exec(tag);\n if (result === null) {\n done = true;\n }\n else if (result[0].trim()) {\n if (result[1]) {\n var attr = result[1].trim();\n var arr = [attr, \"\"];\n if (attr.indexOf(\"=\") > -1)\n { arr = attr.split(\"=\"); }\n res.attributes[arr[0]] = arr[1];\n reg.lastIndex--;\n }\n else if (result[2])\n { res.attributes[result[2]] = result[3]\n .trim()\n .substring(1, result[3].length - 1); }\n }\n }\n return {\n type: type,\n node: res,\n voidElement: voidElement,\n };\n};\nvar stringToObj = function (html, options) {\n if (options === void 0) { options = {\n valueDiffing: true,\n caseSensitive: false,\n }; }\n var result = [];\n var current;\n var level = -1;\n var arr = [];\n var inComponent = false, insideSvg = false;\n // handle text at top level\n if (html.indexOf(\"<\") !== 0) {\n var end = html.indexOf(\"<\");\n result.push({\n nodeName: \"#text\",\n data: end === -1 ? html : html.substring(0, end),\n });\n }\n html.replace(tagRE, function (tag, index) {\n var isOpen = tag.charAt(1) !== \"/\";\n var isComment = tag.startsWith(\"/g,V=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function $(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}var S={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuItem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},C=function(t,e){var s={nodeName:"",attributes:{}},i=!1,n=t.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(s.nodeName=e||"svg"===n[1]?n[1]:n[1].toUpperCase(),(S[n[1]]||"/"===t.charAt(t.length-2))&&(i=!0),s.nodeName.startsWith("!--"))){var a=t.indexOf("--\x3e");return{type:"comment",node:{nodeName:"#comment",data:-1!==a?t.slice(4,a):""},voidElement:i}}for(var o=new RegExp(V),r=null,l=!1;!l;)if(null===(r=o.exec(t)))l=!0;else if(r[0].trim())if(r[1]){var d=r[1].trim(),c=[d,""];d.indexOf("=")>-1&&(c=d.split("=")),s.attributes[c[0]]=c[1],o.lastIndex--}else r[2]&&(s.attributes[r[2]]=r[3].trim().substring(1,r[3].length-1));return{type:"tag",node:s,voidElement:i}},k=function(t,e){void 0===e&&(e={valueDiffing:!0,caseSensitive:!1});var s,i=[],n=-1,a=[],o=!1;if(0!==t.indexOf("<")){var r=t.indexOf("<");i.push({nodeName:"#text",data:-1===r?t:t.substring(0,r)})}return t.replace(E,(function(r,l){var d="/"!==r.charAt(1),c=r.startsWith("\x3c!--"),h=l+r.length,u=t.charAt(h);if(c){var p=C(r,e.caseSensitive).node;if(n<0)return i.push(p),"";var f=a[n];return f&&p.nodeName&&(f.node.childNodes||(f.node.childNodes=[]),f.node.childNodes.push(p)),""}if(d){if("svg"===(s=C(r,e.caseSensitive||o)).node.nodeName&&(o=!0),n++,!s.voidElement&&u&&"<"!==u){s.node.childNodes||(s.node.childNodes=[]);var m=$(t.slice(h,t.indexOf("<",h)));s.node.childNodes.push({nodeName:"#text",data:m}),e.valueDiffing&&"TEXTAREA"===s.node.nodeName&&(s.node.value=m)}0===n&&s.node.nodeName&&i.push(s.node);var g=a[n-1];g&&s.node.nodeName&&(g.node.childNodes||(g.node.childNodes=[]),g.node.childNodes.push(s.node)),a[n]=s}if((!d||s.voidElement)&&(n>-1&&(s.voidElement||e.caseSensitive&&s.node.nodeName===r.slice(2,-1)||!e.caseSensitive&&s.node.nodeName.toUpperCase()===r.slice(2,-1).toUpperCase())&&--n>-1&&("svg"===s.node.nodeName&&(o=!1),s=a[n]),"<"!==u&&u)){var b=-1===n?i:a[n].node.childNodes||[],v=t.indexOf("<",h);m=$(t.slice(h,-1===v?void 0:v));b.push({nodeName:"#text",data:m})}return""})),i[0]},T=function(){function t(t,e,s){this.options=s,this.t1="undefined"!=typeof Element&&r(t,"Element")?O(t,this.options):"string"==typeof t?k(t,this.options):JSON.parse(JSON.stringify(t)),this.t2="undefined"!=typeof Element&&r(e,"Element")?O(e,this.options):"string"==typeof e?k(e,this.options):JSON.parse(JSON.stringify(e)),this.diffcount=0,this.foundAll=!1,this.debug&&(this.t1Orig="undefined"!=typeof Element&&r(t,"Element")?O(t,this.options):"string"==typeof t?k(t,this.options):JSON.parse(JSON.stringify(t)),this.t2Orig="undefined"!=typeof Element&&r(e,"Element")?O(e,this.options):"string"==typeof e?k(e,this.options):JSON.parse(JSON.stringify(e))),this.tracker=new D}return t.prototype.init=function(){return this.findDiffs(this.t1,this.t2)},t.prototype.findDiffs=function(t,e){var s;do{if(this.options.debug&&(this.diffcount+=1,this.diffcount>this.options.diffcap))throw new Error("surpassed diffcap:".concat(JSON.stringify(this.t1Orig)," -> ").concat(JSON.stringify(this.t2Orig)));0===(s=this.findNextDiff(t,e,[])).length&&(w(t,e)||(this.foundAll?console.error("Could not find remaining diffs!"):(this.foundAll=!0,b(t),s=this.findNextDiff(t,e,[])))),s.length>0&&(this.foundAll=!1,this.tracker.add(s),M(t,s,this.options))}while(s.length>0);return this.tracker.list},t.prototype.findNextDiff=function(t,e,s){var i,n;if(this.options.maxDepth&&s.length>this.options.maxDepth)return[];if(!t.outerDone){if(i=this.findOuterDiff(t,e,s),this.options.filterOuterDiff&&(n=this.options.filterOuterDiff(t,e,i))&&(i=n),i.length>0)return t.outerDone=!0,i;t.outerDone=!0}if(Object.prototype.hasOwnProperty.call(t,"data"))return[];if(!t.innerDone){if((i=this.findInnerDiff(t,e,s)).length>0)return i;t.innerDone=!0}if(this.options.valueDiffing&&!t.valueDone){if((i=this.findValueDiff(t,e,s)).length>0)return t.valueDone=!0,i;t.valueDone=!0}return[]},t.prototype.findOuterDiff=function(t,e,s){var i,n,a,r,l,d,c=[];if(t.nodeName!==e.nodeName){if(!s.length)throw new Error("Top level nodes have to be of the same kind.");return[(new o).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,v(t)).setValue(this.options._const.newValue,v(e)).setValue(this.options._const.route,s)]}if(s.length&&this.options.diffcap0&&(l=this.attemptGroupRelocation(t,e,h,s,c)).length>0)return l}for(var u=0;un.length?("#text"===p.nodeName?l.push((new o).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,s.concat(d)).setValue(this.options._const.value,p.data)):l.push((new o).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.element,v(p)).setValue(this.options._const.route,s.concat(d))),i.splice(u,1),u-=1,d-=1,r-=1):i.lengthD+1&&"#text"===f[D+1].nodeName;)if(D+=1,m[w].data===f[D].data){c=!0;break}c||b.push((new o).setValue(this.options._const.action,this.options._const.modifyTextElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.oldValue,d.data).setValue(this.options._const.newValue,m[w].data))}}else b.push((new o).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.value,d.data)),u.splice(x,1),f.splice(x,1),g=Math.min(u.length,p.length),x-=1,w-=1;else!0===p[w]?b.push((new o).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,v(d)).setValue(this.options._const.newValue,v(m[w])).setValue(this.options._const.route,i.concat(x))):(b.push((new o).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.element,v(d))),u.splice(x,1),f.splice(x,1),g=Math.min(u.length,p.length),x-=1,w-=1);else if(!0===p[w])"#text"===(d=m[w]).nodeName?(b.push((new o).setValue(this.options._const.action,this.options._const.addTextElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.value,d.data)),u.splice(x,0,!0),f.splice(x,0,{nodeName:"#text",data:d.data}),g=Math.min(u.length,p.length)):(b.push((new o).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.element,v(d))),u.splice(x,0,!0),f.splice(x,0,v(d)),g=Math.min(u.length,p.length));else if(u[x]!==p[w]){if(b.length>0)return b;if(l=s[u[x]],(r=Math.min(l.newValue,f.length-l.length))!==l.oldValue){a=!1;for(var N=0;N({nodeName:"TR",childNodes:t.map(((t,h)=>{const u=e[h]||{type:l,format:n,sortable:!0,searchable:!0};if(u.hidden)return;const p={};if(u.sortable&&o&&(!r.length||c)&&(u.filter?p["data-filterable"]="true":p["data-sortable"]="true"),u.headerClass&&(p.class=u.headerClass),s.sort&&s.sort.column===h){const t="asc"===s.sort.dir?i.ascending:i.descending;p.class=p.class?`${p.class} ${t}`:t,p["aria-sort"]="asc"===s.sort.dir?"ascending":"descending"}else s.filters[h]&&(p.class=p.class?`${p.class} ${i.filterActive}`:i.filterActive);let f="";s.widths[h]&&!d&&(f+=`width: ${s.widths[h]}%;`),r.length&&!c&&(f+="padding-bottom: 0;padding-top: 0;border: 0;"),f.length&&(p.style=f);const m="html"===t.type?t.data:[{nodeName:"#text",data:t.text??String(t.data)}];return{nodeName:"TH",attributes:p,childNodes:!a&&!r.length||c?u.sortable&&o?[{nodeName:"BUTTON",attributes:{class:u.filter?i.filter:i.sorter},childNodes:m}]:m:[{nodeName:"#text",data:""}]}})).filter((t=>t))}),R=(t,e,s,i,n,a,{classes:o,hiddenHeader:r,header:l,footer:d,format:c,sortable:h,scrollY:u,type:p,rowRender:f,tabIndex:m},{noColumnWidths:g,unhideHeader:b,renderHeader:v})=>{const w={nodeName:"TABLE",attributes:{...t},childNodes:[{nodeName:"TBODY",childNodes:s.map((({row:t,index:e})=>{const s={nodeName:"TR",attributes:{"data-index":String(e)},childNodes:t.map(((t,s)=>{const a=i[s]||{type:p,format:c,sortable:!0,searchable:!0};if(a.hidden)return;const o="html"===a.type?{nodeName:"TD",childNodes:t.data}:{nodeName:"TD",childNodes:[{nodeName:"#text",data:t.text??String(t.data)}]};if(l||d||!n.widths[s]||g||(o.attributes={style:`width: ${n.widths[s]}%;`}),a.cellClass&&(o.attributes||(o.attributes={}),o.attributes.class=a.cellClass),a.render){const i=a.render(t.data,o,e,s);if(i){if("string"!=typeof i)return i;{const t=k(`${i}`);1===t.childNodes.length&&["#text","#comment"].includes(t.childNodes[0].nodeName)?o.childNodes[0].data=i:o.childNodes=t.childNodes}}}return o})).filter((t=>t))};if(e===a&&(s.attributes.class=o.cursor),f){const i=f(t,s,e);if(i){if("string"!=typeof i)return i;{const t=k(`${i}`);!t.childNodes||1===t.childNodes.length&&["#text","#comment"].includes(t.childNodes[0].nodeName)?s.childNodes[0].data=i:s.childNodes=t.childNodes}}}return s}))}]};if(w.attributes.class=w.attributes.class?`${w.attributes.class} ${o.table}`:o.table,l||d||v){const t=P(e,i,n,{classes:o,hiddenHeader:r,sortable:h,scrollY:u},{noColumnWidths:g,unhideHeader:b});if(l||v){const e={nodeName:"THEAD",childNodes:[t]};!u.length&&!r||b||(e.attributes={style:"height: 0px;"}),w.childNodes.unshift(e)}if(d){const e={nodeName:"TFOOT",childNodes:[l?structuredClone(t):t]};!u.length&&!r||b||(e.attributes={style:"height: 0px;"}),w.childNodes.push(e)}}return!1!==m&&(w.attributes.tabindex=String(m)),w};"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function H(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var I={exports:{}},Y=H(I.exports=function(){var t=1e3,e=6e4,s=36e5,i="millisecond",n="second",a="minute",o="hour",r="day",l="week",d="month",c="quarter",h="year",u="date",p="Invalid Date",f=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,m=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],s=t%100;return"["+t+(e[(s-20)%10]||e[s]||e[0])+"]"}},b=function(t,e,s){var i=String(t);return!i||i.length>=e?t:""+Array(e+1-i.length).join(s)+t},v={s:b,z:function(t){var e=-t.utcOffset(),s=Math.abs(e),i=Math.floor(s/60),n=s%60;return(e<=0?"+":"-")+b(i,2,"0")+":"+b(n,2,"0")},m:function t(e,s){if(e.date()1)return t(o[0])}else{var r=e.name;_[r]=e,n=r}return!i&&n&&(w=n),n||!i&&w},N=function(t,e){if(x(t))return t.clone();var s="object"==typeof e?e:{};return s.date=t,s.args=arguments,new O(s)},M=v;M.l=D,M.i=x,M.w=function(t,e){return N(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var O=function(){function g(t){this.$L=D(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[y]=!0}var b=g.prototype;return b.parse=function(t){this.$d=function(t){var e=t.date,s=t.utc;if(null===e)return new Date(NaN);if(M.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var i=e.match(f);if(i){var n=i[2]-1||0,a=(i[7]||"0").substring(0,3);return s?new Date(Date.UTC(i[1],n,i[3]||1,i[4]||0,i[5]||0,i[6]||0,a)):new Date(i[1],n,i[3]||1,i[4]||0,i[5]||0,i[6]||0,a)}}return new Date(e)}(t),this.init()},b.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},b.$utils=function(){return M},b.isValid=function(){return!(this.$d.toString()===p)},b.isSame=function(t,e){var s=N(t);return this.startOf(e)<=s&&s<=this.endOf(e)},b.isAfter=function(t,e){return N(t)68?1900:2e3)},r=function(t){return function(e){this[t]=+e}},l=[/[+-]\d\d:?(\d\d)?|Z/,function(t){(this.zone||(this.zone={})).offset=function(t){if(!t)return 0;if("Z"===t)return 0;var e=t.match(/([+-]|\d\d)/g),s=60*e[1]+(+e[2]||0);return 0===s?0:"+"===e[0]?-s:s}(t)}],d=function(t){var e=a[t];return e&&(e.indexOf?e:e.s.concat(e.f))},c=function(t,e){var s,i=a.meridiem;if(i){for(var n=1;n<=24;n+=1)if(t.indexOf(i(n,0,e))>-1){s=n>12;break}}else s=t===(e?"pm":"PM");return s},h={A:[n,function(t){this.afternoon=c(t,!1)}],a:[n,function(t){this.afternoon=c(t,!0)}],S:[/\d/,function(t){this.milliseconds=100*+t}],SS:[s,function(t){this.milliseconds=10*+t}],SSS:[/\d{3}/,function(t){this.milliseconds=+t}],s:[i,r("seconds")],ss:[i,r("seconds")],m:[i,r("minutes")],mm:[i,r("minutes")],H:[i,r("hours")],h:[i,r("hours")],HH:[i,r("hours")],hh:[i,r("hours")],D:[i,r("day")],DD:[s,r("day")],Do:[n,function(t){var e=a.ordinal,s=t.match(/\d+/);if(this.day=s[0],e)for(var i=1;i<=31;i+=1)e(i).replace(/\[|\]/g,"")===t&&(this.day=i)}],M:[i,r("month")],MM:[s,r("month")],MMM:[n,function(t){var e=d("months"),s=(d("monthsShort")||e.map((function(t){return t.slice(0,3)}))).indexOf(t)+1;if(s<1)throw new Error;this.month=s%12||s}],MMMM:[n,function(t){var e=d("months").indexOf(t)+1;if(e<1)throw new Error;this.month=e%12||e}],Y:[/[+-]?\d+/,r("year")],YY:[s,function(t){this.year=o(t)}],YYYY:[/\d{4}/,r("year")],Z:l,ZZ:l};function u(s){var i,n;i=s,n=a&&a.formats;for(var o=(s=i.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(e,s,i){var a=i&&i.toUpperCase();return s||n[i]||t[i]||n[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,e,s){return e||s.slice(1)}))}))).match(e),r=o.length,l=0;l-1)return new Date(("X"===e?1e3:1)*t);var i=u(e)(t),n=i.year,a=i.month,o=i.day,r=i.hours,l=i.minutes,d=i.seconds,c=i.milliseconds,h=i.zone,p=new Date,f=o||(n||a?1:p.getDate()),m=n||p.getFullYear(),g=0;n&&!a||(g=a>0?a-1:p.getMonth());var b=r||0,v=l||0,w=d||0,_=c||0;return h?new Date(Date.UTC(m,g,f,b,v,w,_+60*h.offset*1e3)):s?new Date(Date.UTC(m,g,f,b,v,w,_)):new Date(m,g,f,b,v,w,_)}catch(t){return new Date("")}}(e,r,i),this.init(),h&&!0!==h&&(this.$L=this.locale(h).$L),c&&e!=this.format(r)&&(this.$d=new Date("")),a={}}else if(r instanceof Array)for(var p=r.length,f=1;f<=p;f+=1){o[1]=r[f-1];var m=s.apply(this,o);if(m.isValid()){this.$d=m.$d,this.$L=m.$L,this.init();break}f===p&&(this.$d=new Date(""))}else n.call(this,t)}}}());Y.extend(q);const B=(t,e)=>{let s;if(e)switch(e){case"ISO_8601":s=t;break;case"RFC_2822":s=Y(t.slice(5),"DD MMM YYYY HH:mm:ss ZZ").unix();break;case"MYSQL":s=Y(t,"YYYY-MM-DD hh:mm:ss").unix();break;case"UNIX":s=Y(t).unix();break;default:s=Y(t,e,!0).valueOf()}return s},F=(t,e)=>{if(t?.constructor===Object&&Object.prototype.hasOwnProperty.call(t,"data")&&!Object.keys(t).find((t=>!["text","order","data"].includes(t))))return t;const s={data:t};switch(e.type){case"string":"string"!=typeof t&&(s.text=String(s.data),s.order=s.text);break;case"date":e.format&&(s.order=B(String(s.data),e.format));break;case"number":s.text=String(s.data),s.data=parseInt(s.data,10);break;case"html":{const t=Array.isArray(s.data)?{nodeName:"TD",childNodes:s.data}:k(`${String(s.data)}`);s.data=t.childNodes||[];const e=i(t);s.text=e,s.order=e;break}case"boolean":"string"==typeof s.data&&(s.data=s.data.toLowerCase().trim()),s.data=!["false",!1,null,void 0,0].includes(s.data),s.order=s.data?1:0,s.text=String(s.data);break;case"other":s.text="",s.order=0;break;default:s.text=JSON.stringify(s.data)}return s},z=t=>{if(t instanceof Object&&t.constructor===Object&&t.hasOwnProperty("data")&&("string"==typeof t.text||"string"==typeof t.data))return t;const e={data:t};if("string"==typeof t){if(t.length){const s=k(`${t}`);if(s.childNodes&&(1!==s.childNodes.length||"#text"!==s.childNodes[0].nodeName)){e.data=s.childNodes,e.type="html";const t=i(s);e.text=t}}}else[null,void 0].includes(t)?e.text="":e.text=JSON.stringify(t);return e},U=(t,e=void 0,s,n,a)=>{const o={data:[],headings:[]};t.headings?o.headings=t.headings.map((t=>z(t))):e?.tHead?o.headings=Array.from(e.tHead.querySelectorAll("th")).map(((t,e)=>{const o=(t=>{const e=O(t,{valueDiffing:!1});let s;return s=!e.childNodes||1===e.childNodes.length&&"#text"===e.childNodes[0].nodeName?{data:t.innerText,type:"string"}:{data:e.childNodes,type:"html",text:i(e)},s})(t);s[e]||(s[e]={type:n,format:a,searchable:!0,sortable:!0});const r=s[e];return"false"!==t.dataset.sortable?.trim().toLowerCase()&&"false"!==t.dataset.sort?.trim().toLowerCase()||(r.sortable=!1),"false"===t.dataset.searchable?.trim().toLowerCase()&&(r.searchable=!1),"true"!==t.dataset.hidden?.trim().toLowerCase()&&"true"!==t.getAttribute("hidden")?.trim().toLowerCase()||(r.hidden=!0),["number","string","html","date","boolean","other"].includes(t.dataset.type)&&(r.type=t.dataset.type,"date"===r.type&&t.dataset.format&&(r.format=t.dataset.format)),o})):t.data?.length?o.headings=t.data[0].map((t=>z(""))):e?.tBodies.length&&(o.headings=Array.from(e.tBodies[0].rows[0].cells).map((t=>z(""))));for(let t=0;tt.map(((t,e)=>F(t,s[e]))))):e?.tBodies?.length&&(o.data=Array.from(e.tBodies[0].rows).map((t=>Array.from(t.cells).map(((t,e)=>{const i=t.dataset.content?F(t.dataset.content,s[e]):((t,e)=>{let s;switch(e.type){case"string":s={data:t.innerText};break;case"date":{const i=t.innerText;s={data:i,order:B(i,e.format)};break}case"number":s={data:parseInt(t.innerText,10),text:t.innerText};break;case"boolean":{const e=!["false","0","null","undefined"].includes(t.innerText.toLowerCase().trim());s={data:e,order:e?1:0,text:e?"1":"0"};break}default:s={data:O(t,{valueDiffing:!1}).childNodes||[],text:t.innerText,order:t.innerText}}return s})(t,s[e]);return t.dataset.order&&(i.order=isNaN(parseFloat(t.dataset.order))?t.dataset.order:parseFloat(t.dataset.order)),i}))))),o.data.length&&o.data[0].length!==o.headings.length)throw new Error("Data heading length mismatch.");return o};class J{constructor(t){this.dt=t,this.cursor=!1}setCursor(t=!1){if(t===this.cursor)return;const e=this.cursor;if(this.cursor=t,this.dt._renderTable(),!1!==t&&this.dt.options.scrollY){const t=this.dt.dom.querySelector(`tr.${this.dt.options.classes.cursor}`);t&&t.scrollIntoView({block:"nearest"})}this.dt.emit("datatable.cursormove",this.cursor,e)}add(t){const e=t.map(((t,e)=>{const s=this.dt.columns.settings[e];return F(t,s)}));this.dt.data.data.push(e),this.dt.data.data.length&&(this.dt.hasRows=!0),this.dt.update(!0)}remove(t){if(!Array.isArray(t))return this.remove([t]);this.dt.data.data=this.dt.data.data.filter(((e,s)=>!t.includes(s))),this.dt.data.data.length||(this.dt.hasRows=!1),this.dt.update(!0)}findRowIndex(t,e){return this.dt.data.data.findIndex((s=>(s[t].text??String(s[t].data)).toLowerCase().includes(String(e).toLowerCase())))}findRow(t,e){const s=this.findRowIndex(t,e);if(s<0)return{index:-1,row:null,cols:[]};const i=this.dt.data.data[s],n=i.map((t=>t.data));return{index:s,row:i,cols:n}}updateRow(t,e){const s=e.map(((t,e)=>{const s=this.dt.columns.settings[e];return F(t,s)}));this.dt.data.data.splice(t,1,s),this.dt.update(!0)}}class W{constructor(t){this.dt=t,this.init()}init(){[this.settings,this._state]=((t=[],e,s)=>{let i=[],n=!1;const a=[];return t.forEach((t=>{(Array.isArray(t.select)?t.select:[t.select]).forEach((o=>{i[o]?t.type&&(i[o].type=t.type):i[o]={type:t.type||e,sortable:!0,searchable:!0};const r=i[o];t.render&&(r.render=t.render),t.format?r.format=t.format:"date"===t.type&&(r.format=s),t.cellClass&&(r.cellClass=t.cellClass),t.headerClass&&(r.headerClass=t.headerClass),t.locale&&(r.locale=t.locale),!1===t.sortable?r.sortable=!1:(t.numeric&&(r.numeric=t.numeric),t.caseFirst&&(r.caseFirst=t.caseFirst)),!1===t.searchable?r.searchable=!1:t.sensitivity&&(r.sensitivity=t.sensitivity),(r.searchable||r.sortable)&&void 0!==t.ignorePunctuation&&(r.ignorePunctuation=t.ignorePunctuation),t.hidden&&(r.hidden=!0),t.filter&&(r.filter=t.filter),t.sortSequence&&(r.sortSequence=t.sortSequence),t.sort&&(t.filter?a[o]=t.sort:n={column:o,dir:t.sort}),void 0!==t.searchItemSeparator&&(r.searchItemSeparator=t.searchItemSeparator)}))})),i=i.map((t=>t||{type:e,format:"date"===e?s:void 0,sortable:!0,searchable:!0})),[i,{filters:a,sort:n,widths:[]}]})(this.dt.options.columns,this.dt.options.type,this.dt.options.format)}get(t){return t<0||t>=this.size()?null:{...this.settings[t]}}size(){return this.settings.length}swap(t){if(2===t.length){const e=this.dt.data.headings.map(((t,e)=>e)),s=t[0],i=t[1],n=e[i];return e[i]=e[s],e[s]=n,this.order(e)}}order(t){this.dt.data.headings=t.map((t=>this.dt.data.headings[t])),this.dt.data.data=this.dt.data.data.map((e=>t.map((t=>e[t])))),this.settings=t.map((t=>this.settings[t])),this.dt.update()}hide(t){t.length&&(t.forEach((t=>{this.settings[t]||(this.settings[t]={type:"string"});this.settings[t].hidden=!0})),this.dt.update())}show(t){t.length&&(t.forEach((t=>{this.settings[t]||(this.settings[t]={type:"string",sortable:!0});delete this.settings[t].hidden})),this.dt.update())}visible(t){return void 0===t&&(t=[...Array(this.dt.data.headings.length).keys()]),Array.isArray(t)?t.map((t=>!this.settings[t]?.hidden)):!this.settings[t]?.hidden}add(t){const e=this.dt.data.headings.length;if(this.dt.data.headings=this.dt.data.headings.concat([z(t.heading)]),this.dt.data.data=this.dt.data.data.map(((e,s)=>e.concat([F(t.data[s],t)]))),this.settings[e]={type:t.type||"string",sortable:!0,searchable:!0},t.type||t.format||t.sortable||t.render||t.filter){const s=this.settings[e];t.render&&(s.render=t.render),t.format&&(s.format=t.format),t.cellClass&&(s.cellClass=t.cellClass),t.headerClass&&(s.headerClass=t.headerClass),t.locale&&(s.locale=t.locale),!1===t.sortable?s.sortable=!1:(t.numeric&&(s.numeric=t.numeric),t.caseFirst&&(s.caseFirst=t.caseFirst)),!1===t.searchable?s.searchable=!1:t.sensitivity&&(s.sensitivity=t.sensitivity),(s.searchable||s.sortable)&&t.ignorePunctuation&&(s.ignorePunctuation=t.ignorePunctuation),t.hidden&&(s.hidden=!0),t.filter&&(s.filter=t.filter),t.sortSequence&&(s.sortSequence=t.sortSequence)}this.dt.update(!0)}remove(t){if(!Array.isArray(t))return this.remove([t]);this.dt.data.headings=this.dt.data.headings.filter(((e,s)=>!t.includes(s))),this.dt.data.data=this.dt.data.data.map((e=>e.filter(((e,s)=>!t.includes(s))))),this.dt.update(!0)}filter(t,e=!1){if(!this.settings[t]?.filter?.length)return;const s=this._state.filters[t];let i;if(s){let e=!1;i=this.settings[t].filter.find((t=>!!e||(t===s&&(e=!0),!1)))}else{const e=this.settings[t].filter;i=e?e[0]:void 0}i?this._state.filters[t]=i:s&&(this._state.filters[t]=void 0),this.dt._currentPage=1,this.dt.update(),e||this.dt.emit("datatable.filter",t,i)}sort(t,e=void 0,s=!1){const i=this.settings[t];if(s||this.dt.emit("datatable.sorting",t,e),!e){const s=!(!this._state.sort||this._state.sort.column!==t)&&this._state.sort?.dir,n=i?.sortSequence||["asc","desc"];if(s){const t=n.indexOf(s);e=-1===t?n[0]||"asc":t===n.length-1?n[0]:n[t+1]}else e=n.length?n[0]:"asc"}const n=!!["string","html"].includes(i.type)&&new Intl.Collator(i.locale||this.dt.options.locale,{usage:"sort",numeric:i.numeric||this.dt.options.numeric,caseFirst:i.caseFirst||this.dt.options.caseFirst,ignorePunctuation:i.ignorePunctuation||this.dt.options.ignorePunctuation});this.dt.data.data.sort(((s,i)=>{let a=s[t].order||s[t].data,o=i[t].order||i[t].data;if("desc"===e){const t=a;a=o,o=t}return n?n.compare(String(a),String(o)):ao?1:0})),this._state.sort={column:t,dir:e},this.dt._searchQueries.length?(this.dt.multiSearch(this.dt._searchQueries),this.dt.emit("datatable.sort",t,e)):s||(this.dt._currentPage=1,this.dt.update(),this.dt.emit("datatable.sort",t,e))}_measureWidths(){const t=this.dt.data.headings.filter(((t,e)=>!this.settings[e]?.hidden));if((this.dt.options.scrollY.length||this.dt.options.fixedColumns)&&t?.length){this._state.widths=[];const t={noPaging:!0};if(this.dt.options.header||this.dt.options.footer){this.dt.options.scrollY.length&&(t.unhideHeader=!0),this.dt.headerDOM&&this.dt.headerDOM.parentElement.removeChild(this.dt.headerDOM),t.noColumnWidths=!0,this.dt._renderTable(t);const e=Array.from(this.dt.dom.querySelector("thead, tfoot")?.firstElementChild?.querySelectorAll("th")||[]);let s=0;const i=this.dt.data.headings.map(((t,i)=>{if(this.settings[i]?.hidden)return 0;const n=e[s].offsetWidth;return s+=1,n})),n=i.reduce(((t,e)=>t+e),0);this._state.widths=i.map((t=>t/n*100))}else{t.renderHeader=!0,this.dt._renderTable(t);const e=Array.from(this.dt.dom.querySelector("thead, tfoot")?.firstElementChild?.querySelectorAll("th")||[]);let s=0;const i=this.dt.data.headings.map(((t,i)=>{if(this.settings[i]?.hidden)return 0;const n=e[s].offsetWidth;return s+=1,n})),n=i.reduce(((t,e)=>t+e),0);this._state.widths=i.map((t=>t/n*100))}this.dt._renderTable()}}}const Q={sortable:!0,locale:"en",numeric:!0,caseFirst:"false",searchable:!0,sensitivity:"base",ignorePunctuation:!0,destroyable:!0,searchItemSeparator:"",searchQuerySeparator:" ",searchAnd:!1,data:{},type:"html",format:"YYYY-MM-DD",columns:[],paging:!0,perPage:10,perPageSelect:[5,10,15,20,25],nextPrev:!0,firstLast:!1,prevText:"‹",nextText:"›",firstText:"«",lastText:"»",ellipsisText:"…",truncatePager:!0,pagerDelta:2,scrollY:"",fixedColumns:!0,fixedHeight:!1,footer:!1,header:!0,hiddenHeader:!1,rowNavigation:!1,tabIndex:!1,pagerRender:!1,rowRender:!1,tableRender:!1,diffDomOptions:{valueDiffing:!1},labels:{placeholder:"Search...",searchTitle:"Search within table",perPage:"entries per page",pageTitle:"Page {page}",noRows:"No entries found",noResults:"No results match your search query",info:"Showing {start} to {end} of {rows} entries"},template:(t,e)=>`
\n ${t.paging&&t.perPageSelect?`
\n \n
`:""}\n ${t.searchable?`
\n \n
`:""}\n
\n
\n
\n ${t.paging?`
`:""}\n \n
`,classes:{active:"datatable-active",ascending:"datatable-ascending",bottom:"datatable-bottom",container:"datatable-container",cursor:"datatable-cursor",descending:"datatable-descending",disabled:"datatable-disabled",dropdown:"datatable-dropdown",ellipsis:"datatable-ellipsis",filter:"datatable-filter",filterActive:"datatable-filter-active",empty:"datatable-empty",headercontainer:"datatable-headercontainer",hidden:"datatable-hidden",info:"datatable-info",input:"datatable-input",loading:"datatable-loading",pagination:"datatable-pagination",paginationList:"datatable-pagination-list",paginationListItem:"datatable-pagination-list-item",paginationListItemLink:"datatable-pagination-list-item-link",search:"datatable-search",selector:"datatable-selector",sorter:"datatable-sorter",table:"datatable-table",top:"datatable-top",wrapper:"datatable-wrapper"}},X=(t,e,s,i={})=>({nodeName:"LI",attributes:{class:i.active&&!i.hidden?`${s.classes.paginationListItem} ${s.classes.active}`:i.hidden?`${s.classes.paginationListItem} ${s.classes.hidden} ${s.classes.disabled}`:s.classes.paginationListItem},childNodes:[{nodeName:"BUTTON",attributes:{"data-page":String(t),class:s.classes.paginationListItemLink,"aria-label":s.labels.pageTitle.replace("{page}",String(t))},childNodes:[{nodeName:"#text",data:e}]}]}),Z=(t,e,s,i,n)=>{let a=[];if(n.firstLast&&a.push(X(1,n.firstText,n)),n.nextPrev){const e=t?1:s-1;a.push(X(e,n.prevText,n,{hidden:t}))}let o=[...Array(i).keys()].map((t=>X(t+1,String(t+1),n,{active:t===s-1})));if(n.truncatePager&&(o=((t,e,s,i)=>{const n=i.pagerDelta,a=i.classes,o=i.ellipsisText,r=2*n;let l=e-n,d=e+n;e<4-n+r?d=3+r:e>s-(3-n+r)&&(l=s-(2+r));const c=[];for(let e=1;e<=s;e++)if(1==e||e==s||e>=l&&e<=d){const s=t[e-1];c.push(s)}let h;const u=[];return c.forEach((e=>{const s=parseInt(e.childNodes[0].attributes["data-page"],10);if(h){const e=parseInt(h.childNodes[0].attributes["data-page"],10);if(s-e==2)u.push(t[e]);else if(s-e!=1){const t={nodeName:"LI",attributes:{class:`${a.paginationListItem} ${a.ellipsis} ${a.disabled}`},childNodes:[{nodeName:"BUTTON",attributes:{class:a.paginationListItemLink},childNodes:[{nodeName:"#text",data:o}]}]};u.push(t)}}u.push(e),h=e})),u})(o,s,i,n)),a=a.concat(o),n.nextPrev){const t=e?i:s+1;a.push(X(t,n.nextText,n,{hidden:e}))}n.firstLast&&a.push(X(i,n.lastText,n));return{nodeName:"UL",attributes:{class:n.classes.paginationList},childNodes:o.length>1?a:[]}};const G={classes:{row:"datatable-editor-row",form:"datatable-editor-form",item:"datatable-editor-item",menu:"datatable-editor-menu",save:"datatable-editor-save",block:"datatable-editor-block",cancel:"datatable-editor-cancel",close:"datatable-editor-close",inner:"datatable-editor-inner",input:"datatable-editor-input",label:"datatable-editor-label",modal:"datatable-editor-modal",action:"datatable-editor-action",header:"datatable-editor-header",wrapper:"datatable-editor-wrapper",editable:"datatable-editor-editable",container:"datatable-editor-container",separator:"datatable-editor-separator"},labels:{closeX:"x",editCell:"Edit Cell",editRow:"Edit Row",removeRow:"Remove Row",reallyRemove:"Are you sure?",reallyCancel:"Do you really want to cancel?",save:"Save",cancel:"Cancel"},cancelModal:t=>confirm(t.options.labels.reallyCancel),inline:!0,hiddenColumns:!1,contextMenu:!0,clickEvent:"dblclick",excludeColumns:[],menuItems:[{text:t=>t.options.labels.editCell,action:(t,e)=>{if(!(t.event.target instanceof Element))return;const s=t.event.target.closest("td");return t.editCell(s)}},{text:t=>t.options.labels.editRow,action:(t,e)=>{if(!(t.event.target instanceof Element))return;const s=t.event.target.closest("tr");return t.editRow(s)}},{separator:!0},{text:t=>t.options.labels.removeRow,action:(t,e)=>{if(t.event.target instanceof Element&&confirm(t.options.labels.reallyRemove)){const e=t.event.target.closest("tr");t.removeRow(e)}}}]};class K{constructor(t,e={}){this.dt=t,this.options={...G,...e}}init(){this.initialized||(this.dt.wrapperDOM.classList.add(this.options.classes.editable),this.options.inline&&(this.originalRowRender=this.dt.options.rowRender,this.dt.options.rowRender=(t,e,s)=>{let i=this.rowRender(t,e,s);return this.originalRowRender&&(i=this.originalRowRender(t,i,s)),i}),this.options.contextMenu&&(this.containerDOM=s("div",{id:this.options.classes.container}),this.wrapperDOM=s("div",{class:this.options.classes.wrapper}),this.menuDOM=s("ul",{class:this.options.classes.menu}),this.options.menuItems&&this.options.menuItems.length&&this.options.menuItems.forEach((t=>{const e=s("li",{class:t.separator?this.options.classes.separator:this.options.classes.item});if(!t.separator){const i=s("a",{class:this.options.classes.action,href:t.url||"#",html:"function"==typeof t.text?t.text(this):t.text});e.appendChild(i),t.action&&"function"==typeof t.action&&i.addEventListener("click",(e=>{e.preventDefault(),t.action(this,e)}))}this.menuDOM.appendChild(e)})),this.wrapperDOM.appendChild(this.menuDOM),this.containerDOM.appendChild(this.wrapperDOM),this.updateMenu()),this.data={},this.menuOpen=!1,this.editing=!1,this.editingRow=!1,this.editingCell=!1,this.bindEvents(),setTimeout((()=>{this.initialized=!0,this.dt.emit("editable.init")}),10))}bindEvents(){this.events={keydown:this.keydown.bind(this),click:this.click.bind(this)},this.dt.dom.addEventListener(this.options.clickEvent,this.events.click),document.addEventListener("keydown",this.events.keydown),this.options.contextMenu&&(this.events.context=this.context.bind(this),this.events.updateMenu=this.updateMenu.bind(this),this.events.dismissMenu=this.dismissMenu.bind(this),this.events.reset=function(t,e=300){let s;return(...i)=>{clearTimeout(s),s=window.setTimeout((()=>t()),e)}}((()=>this.events.updateMenu()),50),this.dt.dom.addEventListener("contextmenu",this.events.context),document.addEventListener("click",this.events.dismissMenu),window.addEventListener("resize",this.events.reset),window.addEventListener("scroll",this.events.reset))}context(t){const e=t.target;if(!(e instanceof Element))return;this.event=t;const s=e.closest("tbody td");if(!this.disabled&&s){t.preventDefault();let e=t.pageX,s=t.pageY;e>this.limits.x&&(e-=this.rect.width),s>this.limits.y&&(s-=this.rect.height),this.wrapperDOM.style.top=`${s}px`,this.wrapperDOM.style.left=`${e}px`,this.openMenu(),this.updateMenu()}}click(t){const e=t.target;if(e instanceof Element)if(this.editing&&this.data&&this.editingCell){const t=this.modalDOM?this.modalDOM.querySelector(`input.${this.options.classes.input}[type=text]`):this.dt.wrapperDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}else if(!this.editing){const s=e.closest("tbody td");s&&(this.editCell(s),t.preventDefault())}}keydown(t){if(this.modalDOM){if("Escape"===t.key)this.options.cancelModal(this)&&this.closeModal();else if("Enter"===t.key)if(this.editingCell){const t=this.modalDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}else{const t=Array.from(this.modalDOM.querySelectorAll(`input.${this.options.classes.input}[type=text]`)).map((t=>t.value.trim()));this.saveRow(t,this.data.row)}}else if(this.editing&&this.data)if("Enter"===t.key){if(this.editingCell){const t=this.dt.wrapperDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}else if(this.editingRow){const t=Array.from(this.dt.wrapperDOM.querySelectorAll(`input.${this.options.classes.input}[type=text]`)).map((t=>t.value.trim()));this.saveRow(t,this.data.row)}}else"Escape"===t.key&&(this.editingCell?this.saveCell(this.data.content):this.editingRow&&this.saveRow(null,this.data.row))}editCell(t){const e=a(t.cellIndex,this.dt.columns.settings);if(this.options.excludeColumns.includes(e))return void this.closeMenu();const s=parseInt(t.parentElement.dataset.index,10),i=this.dt.data.data[s][e];this.data={cell:i,rowIndex:s,columnIndex:e,content:i.text||String(i.data)},this.editing=!0,this.editingCell=!0,this.options.inline?this.dt.update():this.editCellModal(),this.closeMenu()}editCellModal(){const t=this.data.cell,e=this.data.columnIndex,i=this.dt.data.headings[e].text||String(this.dt.data.headings[e].data),a=[`
`,`
`,`

${this.options.labels.editCell}

`,``,"
",`
`,`
`,`
`,``,``,"
",`
`,``,``,"
","
","
","
"].join(""),o=s("div",{class:this.options.classes.modal,html:a});this.modalDOM=o,this.openModal();const r=o.querySelector(`input.${this.options.classes.input}[type=text]`);r.focus(),r.selectionStart=r.selectionEnd=r.value.length,o.addEventListener("click",(t=>{const e=t.target;e instanceof Element&&(e.hasAttribute("data-editor-cancel")?(t.preventDefault(),this.options.cancelModal(this)&&this.closeModal()):e.hasAttribute("data-editor-save")&&(t.preventDefault(),this.saveCell(r.value)))}))}saveCell(t){const e=this.data.content,s=this.dt.columns.settings[this.data.columnIndex].type||this.dt.options.type,i=t.trim();let n;if("number"===s)n={data:parseFloat(i)};else if("boolean"===s)n=["","false","0"].includes(i)?{data:!1,text:"false",order:0}:{data:!0,text:"true",order:1};else if("html"===s)n={data:[{nodeName:"#text",data:t}],text:t,order:t};else if("string"===s)n={data:t};else if("date"===s){const e=this.dt.columns.settings[this.data.columnIndex].format||this.dt.options.format;n={data:t,order:B(String(t),e)}}else n={data:t};this.dt.data.data[this.data.rowIndex][this.data.columnIndex]=n,this.closeModal();const a=this.data.rowIndex,o=this.data.columnIndex;this.data={},this.dt.update(!0),this.editing=!1,this.editingCell=!1,this.dt.emit("editable.save.cell",t,e,a,o)}editRow(t){if(!t||"TR"!==t.nodeName||this.editing)return;const e=parseInt(t.dataset.index,10),s=this.dt.data.data[e];this.data={row:s,rowIndex:e},this.editing=!0,this.editingRow=!0,this.options.inline?this.dt.update():this.editRowModal(),this.closeMenu()}editRowModal(){const t=this.data.row,e=[`
`,`
`,`

${this.options.labels.editRow}

`,``,"
",`
`,`
`,`
`,``,``,"
","
","
","
"].join(""),i=s("div",{class:this.options.classes.modal,html:e}),a=i.firstElementChild;if(!a)return;const o=a.lastElementChild?.firstElementChild;if(!o)return;t.forEach(((t,e)=>{const i=this.dt.columns.settings[e];if((!i.hidden||i.hidden&&this.options.hiddenColumns)&&!this.options.excludeColumns.includes(e)){const i=this.dt.data.headings[e].text||String(this.dt.data.headings[e].data);o.insertBefore(s("div",{class:this.options.classes.row,html:[`
`,``,``,"
"].join("")}),o.lastElementChild)}})),this.modalDOM=i,this.openModal();const r=Array.from(o.querySelectorAll(`input.${this.options.classes.input}[type=text]`));i.addEventListener("click",(t=>{const e=t.target;if(e instanceof Element)if(e.hasAttribute("data-editor-cancel"))this.options.cancelModal(this)&&this.closeModal();else if(e.hasAttribute("data-editor-save")){const t=r.map((t=>t.value.trim()));this.saveRow(t,this.data.row)}}))}saveRow(t,e){const s=e.map((t=>t.text??String(t.data)));if(t){let s=0;this.dt.data.data[this.data.rowIndex]=e.map(((e,i)=>{if(this.options.excludeColumns.includes(i)||this.dt.columns.settings[i].hidden)return e;const n=this.dt.columns.settings[i].type||this.dt.options.type,a=t[s++];let o;if("number"===n)o={data:parseFloat(a)};else if("boolean"===n)o=["","false","0"].includes(a)?{data:!1,text:"false",order:0}:{data:!0,text:"true",order:1};else if("html"===n)o={data:[{nodeName:"#text",data:a}],text:a,order:a};else if("string"===n)o={data:a};else if("date"===n){const t=this.dt.columns.settings[i].format||this.dt.options.format;o={data:a,order:B(String(a),t)}}else o={data:a};return o}))}const i=this.dt.data.data[this.data.rowIndex].map((t=>t.text??String(t.data)));this.data={},this.dt.update(!0),this.closeModal(),this.editing=!1,this.dt.emit("editable.save.row",i,s,e)}openModal(){this.modalDOM&&document.body.appendChild(this.modalDOM)}closeModal(){this.editing&&this.modalDOM&&(document.body.removeChild(this.modalDOM),this.modalDOM=this.editing=this.editingRow=this.editingCell=!1)}removeRow(t){if(!t||"TR"!==t.nodeName||this.editing)return;const e=parseInt(t.dataset.index,10);this.dt.rows.remove(e),this.closeMenu()}updateMenu(){const t=window.scrollX||window.pageXOffset,e=window.scrollY||window.pageYOffset;this.rect=this.wrapperDOM.getBoundingClientRect(),this.limits={x:window.innerWidth+t-this.rect.width,y:window.innerHeight+e-this.rect.height}}dismissMenu(t){const e=t.target;if(!(e instanceof Element)||this.wrapperDOM.contains(e))return;let s=!0;this.editing&&(s=!e.matches(`input.${this.options.classes.input}[type=text]`)),s&&this.closeMenu()}openMenu(){if(this.editing&&this.data&&this.editingCell){const t=this.modalDOM?this.modalDOM.querySelector(`input.${this.options.classes.input}[type=text]`):this.dt.wrapperDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}document.body.appendChild(this.containerDOM),this.menuOpen=!0,this.dt.emit("editable.context.open")}closeMenu(){this.menuOpen&&(this.menuOpen=!1,document.body.removeChild(this.containerDOM),this.dt.emit("editable.context.close"))}destroy(){this.dt.dom.removeEventListener(this.options.clickEvent,this.events.click),this.dt.dom.removeEventListener("contextmenu",this.events.context),document.removeEventListener("click",this.events.dismissMenu),document.removeEventListener("keydown",this.events.keydown),window.removeEventListener("resize",this.events.reset),window.removeEventListener("scroll",this.events.reset),document.body.contains(this.containerDOM)&&document.body.removeChild(this.containerDOM),this.options.inline&&(this.dt.options.rowRender=this.originalRowRender),this.initialized=!1}rowRender(t,e,s){if(!this.data||this.data.rowIndex!==s)return e;if(this.editingCell){e.childNodes[function(t,e){let s=t,i=0;for(;i{const o=a(i,this.dt.columns.settings),r=t[o];if(!this.options.excludeColumns.includes(o)){e.childNodes[i].childNodes=[{nodeName:"INPUT",attributes:{type:"text",value:n(r.text||String(r.data)||""),class:this.options.classes.input}}]}}));return e}}const tt={classes:{button:"datatable-column-filter-button",menu:"datatable-column-filter-menu",container:"datatable-column-filter-container",wrapper:"datatable-column-filter-wrapper"},labels:{button:"Filter columns within the table"},hiddenColumns:[]};class et{constructor(t,e={}){this.dt=t,this.options={...tt,...e}}init(){if(this.initialized)return;let t=this.dt.wrapperDOM.querySelector(`.${this.options.classes.button}`);if(!t){t=s("button",{class:this.options.classes.button,html:"▦"});const e=this.dt.wrapperDOM.querySelector(`.${this.dt.options.classes.search}`);e?e.appendChild(t):this.dt.wrapperDOM.appendChild(t),this.addedButtonDOM=!0}this.buttonDOM=t,this.containerDOM=s("div",{id:this.options.classes.container}),this.wrapperDOM=s("div",{class:this.options.classes.wrapper}),this.menuDOM=s("ul",{class:this.options.classes.menu,html:this.dt.data.headings.map(((t,e)=>{const s=this.dt.columns.settings[e];return this.options.hiddenColumns.includes(e)?"":`
  • \n \n \n
  • `})).join("")}),this.wrapperDOM.appendChild(this.menuDOM),this.containerDOM.appendChild(this.wrapperDOM),this._measureSpace(),this._bind(),this.initialized=!0}dismiss(){this.addedButtonDOM&&this.buttonDOM.parentElement&&this.buttonDOM.parentElement.removeChild(this.buttonDOM),document.removeEventListener("click",this.events.click)}_bind(){this.events={click:this._click.bind(this)},document.addEventListener("click",this.events.click)}_openMenu(){document.body.appendChild(this.containerDOM),this._measureSpace(),this.menuOpen=!0,this.dt.emit("columnFilter.menu.open")}_closeMenu(){this.menuOpen&&(this.menuOpen=!1,document.body.removeChild(this.containerDOM),this.dt.emit("columnFilter.menu.close"))}_measureSpace(){const t=window.scrollX||window.pageXOffset,e=window.scrollY||window.pageYOffset;this.rect=this.wrapperDOM.getBoundingClientRect(),this.limits={x:window.innerWidth+t-this.rect.width,y:window.innerHeight+e-this.rect.height}}_click(t){const e=t.target;if(e instanceof Element)if(this.event=t,this.buttonDOM.contains(e)){if(t.preventDefault(),this.menuOpen)return void this._closeMenu();this._openMenu();let e=t.pageX,s=t.pageY;e>this.limits.x&&(e-=this.rect.width),s>this.limits.y&&(s-=this.rect.height),this.wrapperDOM.style.top=`${s}px`,this.wrapperDOM.style.left=`${e}px`}else if(this.menuDOM.contains(e)){const t=e.closest(`.${this.options.classes.menu} > li`);if(!t)return;const s=t.querySelector("input[type=checkbox]");s.contains(e)||(s.checked=!s.checked);const i=Number(t.dataset.column);s.checked?this.dt.columns.show([i]):this.dt.columns.hide([i])}else this.menuOpen&&this._closeMenu()}}exports.DataTable=class{constructor(t,e={}){const s="string"==typeof t?document.querySelector(t):t;s instanceof HTMLTableElement?this.dom=s:(this.dom=document.createElement("table"),s.appendChild(this.dom));const i={...Q.diffDomOptions,...e.diffDomOptions},n={...Q.labels,...e.labels},a={...Q.classes,...e.classes};this.options={...Q,...e,diffDomOptions:i,labels:n,classes:a},this._initialInnerHTML=this.options.destroyable?this.dom.innerHTML:"",this.options.tabIndex?this.dom.tabIndex=this.options.tabIndex:this.options.rowNavigation&&-1===this.dom.tabIndex&&(this.dom.tabIndex=0),this._listeners={onResize:()=>this._onResize()},this._dd=new A(this.options.diffDomOptions||{}),this.initialized=!1,this._events={},this._currentPage=0,this.onFirstPage=!0,this.hasHeadings=!1,this.hasRows=!1,this._searchQueries=[],this.init()}init(){if(this.initialized||this.dom.classList.contains(this.options.classes.table))return!1;this._virtualDOM=O(this.dom,this.options.diffDomOptions||{}),this._tableAttributes={...this._virtualDOM.attributes},this.rows=new J(this),this.columns=new W(this),this.data=U(this.options.data,this.dom,this.columns.settings,this.options.type,this.options.format),this._render(),setTimeout((()=>{this.emit("datatable.init"),this.initialized=!0}),10)}_render(){this.wrapperDOM=s("div",{class:`${this.options.classes.wrapper} ${this.options.classes.loading}`}),this.wrapperDOM.innerHTML=this.options.template(this.options,this.dom);const t=this.wrapperDOM.querySelector(`select.${this.options.classes.selector}`);t&&this.options.paging&&this.options.perPageSelect?this.options.perPageSelect.forEach((e=>{const[s,i]=Array.isArray(e)?[e[0],e[1]]:[String(e),e],n=i===this.options.perPage,a=new Option(s,String(i),n,n);t.appendChild(a)})):t&&t.parentElement.removeChild(t),this.containerDOM=this.wrapperDOM.querySelector(`.${this.options.classes.container}`),this._pagerDOMs=[],Array.from(this.wrapperDOM.querySelectorAll(`.${this.options.classes.pagination}`)).forEach((t=>{t instanceof HTMLElement&&(t.innerHTML=`
      `,this._pagerDOMs.push(t.firstElementChild))})),this._virtualPagerDOM={nodeName:"UL",attributes:{class:this.options.classes.paginationList}},this._label=this.wrapperDOM.querySelector(`.${this.options.classes.info}`),this.dom.parentElement.replaceChild(this.wrapperDOM,this.dom),this.containerDOM.appendChild(this.dom),this._rect=this.dom.getBoundingClientRect(),this._fixHeight(),this.options.header||this.wrapperDOM.classList.add("no-header"),this.options.footer||this.wrapperDOM.classList.add("no-footer"),this.options.sortable&&this.wrapperDOM.classList.add("sortable"),this.options.searchable&&this.wrapperDOM.classList.add("searchable"),this.options.fixedHeight&&this.wrapperDOM.classList.add("fixed-height"),this.options.fixedColumns&&this.wrapperDOM.classList.add("fixed-columns"),this._bindEvents(),this.columns._state.sort&&this.columns.sort(this.columns._state.sort.column,this.columns._state.sort.dir,!0),this.update(!0)}_renderTable(t={}){let e=R(this._tableAttributes,this.data.headings,(this.options.paging||this._searchQueries.length||this.columns._state.filters.length)&&this._currentPage&&this.pages.length&&!t.noPaging?this.pages[this._currentPage-1]:this.data.data.map(((t,e)=>({row:t,index:e}))),this.columns.settings,this.columns._state,this.rows.cursor,this.options,t);if(this.options.tableRender){const t=this.options.tableRender(this.data,e,"main");t&&(e=t)}const s=this._dd.diff(this._virtualDOM,e);this._dd.apply(this.dom,s),this._virtualDOM=e}_renderPage(t=!1){this.hasRows&&this.totalPages?(this._currentPage>this.totalPages&&(this._currentPage=1),this._renderTable(),this.onFirstPage=1===this._currentPage,this.onLastPage=this._currentPage===this.lastPage):this.setMessage(this.options.labels.noRows);let e,s=0,i=0,n=0;if(this.totalPages&&(s=this._currentPage-1,i=s*this.options.perPage,n=i+this.pages[s].length,i+=1,e=this._searchQueries.length?this._searchData.length:this.data.data.length),this._label&&this.options.labels.info.length){const t=this.options.labels.info.replace("{start}",String(i)).replace("{end}",String(n)).replace("{page}",String(this._currentPage)).replace("{pages}",String(this.totalPages)).replace("{rows}",String(e));this._label.innerHTML=e?t:""}if(1==this._currentPage&&this._fixHeight(),this.options.rowNavigation&&this._currentPage&&(!this.rows.cursor||!this.pages[this._currentPage-1].find((t=>t.index===this.rows.cursor)))){const e=this.pages[this._currentPage-1];e.length&&(t?this.rows.setCursor(e[e.length-1].index):this.rows.setCursor(e[0].index))}}_renderPagers(){if(!this.options.paging)return;let t=Z(this.onFirstPage,this.onLastPage,this._currentPage,this.totalPages,this.options);if(this.options.pagerRender){const e=this.options.pagerRender([this.onFirstPage,this.onLastPage,this._currentPage,this.totalPages],t);e&&(t=e)}const e=this._dd.diff(this._virtualPagerDOM,t);this._pagerDOMs.forEach((t=>{this._dd.apply(t,e)})),this._virtualPagerDOM=t}_renderSeparateHeader(){const t=this.dom.parentElement;this.headerDOM||(this.headerDOM=document.createElement("div"),this._virtualHeaderDOM={nodeName:"DIV"}),t.parentElement.insertBefore(this.headerDOM,t);let e={nodeName:"TABLE",attributes:this._tableAttributes,childNodes:[{nodeName:"THEAD",childNodes:[P(this.data.headings,this.columns.settings,this.columns._state,this.options,{unhideHeader:!0})]}]};if(e.attributes.class=e.attributes.class?`${e.attributes.class} ${this.options.classes.table}`:this.options.classes.table,this.options.tableRender){const t=this.options.tableRender(this.data,e,"header");t&&(e=t)}const s={nodeName:"DIV",attributes:{class:this.options.classes.headercontainer},childNodes:[e]},i=this._dd.diff(this._virtualHeaderDOM,s);this._dd.apply(this.headerDOM,i),this._virtualHeaderDOM=s;const n=this.headerDOM.firstElementChild.clientWidth-this.dom.clientWidth;if(n){const t=structuredClone(this._virtualHeaderDOM);t.attributes.style=`padding-right: ${n}px;`;const e=this._dd.diff(this._virtualHeaderDOM,t);this._dd.apply(this.headerDOM,e),this._virtualHeaderDOM=t}t.scrollHeight>t.clientHeight&&(t.style.overflowY="scroll")}_bindEvents(){if(this.options.perPageSelect){const t=this.wrapperDOM.querySelector(`select.${this.options.classes.selector}`);t&&t instanceof HTMLSelectElement&&t.addEventListener("change",(()=>{this.options.perPage=parseInt(t.value,10),this.update(),this._fixHeight(),this.emit("datatable.perpage",this.options.perPage)}),!1)}this.options.searchable&&this.wrapperDOM.addEventListener("input",(t=>{const e=t.target;if(!(e instanceof HTMLInputElement&&e.matches(`.${this.options.classes.input}`)))return;t.preventDefault();const s=[];if(Array.from(this.wrapperDOM.querySelectorAll(`.${this.options.classes.input}`)).filter((t=>t.value.length)).forEach((t=>{const e=t.dataset.and||this.options.searchAnd,i=t.dataset.querySeparator||this.options.searchQuerySeparator?t.value.split(this.options.searchQuerySeparator):[t.value];e?i.forEach((e=>{t.dataset.columns?s.push({terms:[e],columns:JSON.parse(t.dataset.columns)}):s.push({terms:[e],columns:void 0})})):t.dataset.columns?s.push({terms:i,columns:JSON.parse(t.dataset.columns)}):s.push({terms:i,columns:void 0})})),1===s.length&&1===s[0].terms.length){const t=s[0];this.search(t.terms[0],t.columns)}else this.multiSearch(s)})),this.wrapperDOM.addEventListener("click",(t=>{const e=t.target.closest("a, button");if(e)if(e.hasAttribute("data-page"))this.page(parseInt(e.getAttribute("data-page"),10)),t.preventDefault();else if(e.classList.contains(this.options.classes.sorter)){const s=Array.from(e.parentElement.parentElement.children).indexOf(e.parentElement),i=a(s,this.columns.settings);this.columns.sort(i),t.preventDefault()}else if(e.classList.contains(this.options.classes.filter)){const s=Array.from(e.parentElement.parentElement.children).indexOf(e.parentElement),i=a(s,this.columns.settings);this.columns.filter(i),t.preventDefault()}}),!1),this.options.rowNavigation?(this.dom.addEventListener("keydown",(t=>{if("ArrowUp"===t.key){let e;t.preventDefault(),t.stopPropagation(),this.pages[this._currentPage-1].find((t=>t.index===this.rows.cursor||(e=t,!1))),e?this.rows.setCursor(e.index):this.onFirstPage||this.page(this._currentPage-1,!0)}else if("ArrowDown"===t.key){let e;t.preventDefault(),t.stopPropagation();const s=this.pages[this._currentPage-1].find((t=>!!e||(t.index===this.rows.cursor&&(e=!0),!1)));s?this.rows.setCursor(s.index):this.onLastPage||this.page(this._currentPage+1)}else["Enter"," "].includes(t.key)&&this.emit("datatable.selectrow",this.rows.cursor,t)})),this.dom.addEventListener("mousedown",(t=>{const e=t.target;if(e instanceof Element&&this.dom.matches(":focus")){const s=Array.from(this.dom.querySelectorAll("body tr")).find((t=>t.contains(e)));s&&s instanceof HTMLElement&&this.emit("datatable.selectrow",parseInt(s.dataset.index,10),t)}}))):this.dom.addEventListener("mousedown",(t=>{const e=t.target;if(!(e instanceof Element))return;const s=Array.from(this.dom.querySelectorAll("body tr")).find((t=>t.contains(e)));s&&s instanceof HTMLElement&&this.emit("datatable.selectrow",parseInt(s.dataset.index,10),t)})),window.addEventListener("resize",this._listeners.onResize)}_onResize(){this._rect=this.containerDOM.getBoundingClientRect(),this._rect.width&&this.update(!0)}destroy(){this.options.destroyable&&(this.dom.innerHTML=this._initialInnerHTML,this.dom.classList.remove(this.options.classes.table),this.wrapperDOM.parentElement&&this.wrapperDOM.parentElement.replaceChild(this.dom,this.wrapperDOM),this.initialized=!1,window.removeEventListener("resize",this._listeners.onResize))}update(t=!1){t&&(this.columns._measureWidths(),this.hasRows=Boolean(this.data.data.length),this.hasHeadings=Boolean(this.data.headings.length)),this.wrapperDOM.classList.remove(this.options.classes.empty),this._paginate(),this._renderPage(),this._renderPagers(),this.options.scrollY.length&&this._renderSeparateHeader(),this.emit("datatable.update")}_paginate(){let t=this.data.data.map(((t,e)=>({row:t,index:e})));return this._searchQueries.length&&(t=[],this._searchData.forEach((e=>t.push({index:e,row:this.data.data[e]})))),this.columns._state.filters.length&&this.columns._state.filters.forEach(((e,s)=>{e&&(t=t.filter((t=>"function"==typeof e?e(t.row[s].data):(t.row[s].text??t.row[s].data)===e)))})),this.options.paging&&this.options.perPage>0?this.pages=t.map(((e,s)=>s%this.options.perPage==0?t.slice(s,s+this.options.perPage):null)).filter((t=>t)):this.pages=[t],this.totalPages=this.lastPage=this.pages.length,this._currentPage||(this._currentPage=1),this.totalPages}_fixHeight(){this.options.fixedHeight&&(this.containerDOM.style.height=null,this._rect=this.containerDOM.getBoundingClientRect(),this.containerDOM.style.height=`${this._rect.height}px`)}search(t,e=void 0){if(!t.length)return this._currentPage=1,this._searchQueries=[],this._searchData=[],this.update(),this.emit("datatable.search","",[]),this.wrapperDOM.classList.remove("search-results"),!1;this.multiSearch([{terms:[t],columns:e||void 0}]),this.emit("datatable.search",t,this._searchData)}multiSearch(t){if(!this.hasRows)return!1;this._currentPage=1,this._searchData=[];const e=t.map((t=>({columns:t.columns,terms:t.terms.map((t=>t.trim())).filter((t=>t))}))).filter((t=>t.terms.length));if(this._searchQueries=e,!e.length)return this.update(),this.emit("datatable.multisearch",e,this._searchData),this.wrapperDOM.classList.remove("search-results"),!1;const s=e.map((t=>this.columns.settings.map(((e,s)=>{if(e.hidden||!e.searchable||t.columns&&!t.columns.includes(s))return!1;let i=t.terms;const n=e.sensitivity||this.options.sensitivity;["base","accent"].includes(n)&&(i=i.map((t=>t.toLowerCase()))),["base","case"].includes(n)&&(i=i.map((t=>t.normalize("NFD").replace(/\p{Diacritic}/gu,""))));return(e.ignorePunctuation??this.options.ignorePunctuation)&&(i=i.map((t=>t.replace(/[.,/#!$%^&*;:{}=-_`~()]/g,"")))),i}))));this.data.data.forEach(((t,e)=>{const i=t.map(((t,e)=>{let s=(t.text||String(t.data)).trim();const i=this.columns.settings[e];if(s.length){const t=i.sensitivity||this.options.sensitivity;["base","accent"].includes(t)&&(s=s.toLowerCase()),["base","case"].includes(t)&&(s=s.normalize("NFD").replace(/\p{Diacritic}/gu,""));(i.ignorePunctuation??this.options.ignorePunctuation)&&(s=s.replace(/[.,/#!$%^&*;:{}=-_`~()]/g,""))}const n=i.searchItemSeparator||this.options.searchItemSeparator;return n?s.split(n):[s]}));s.every((t=>t.find(((t,e)=>!!t&&t.find((t=>i[e].find((e=>e.includes(t)))))))))&&this._searchData.push(e)})),this.wrapperDOM.classList.add("search-results"),this._searchData.length?this.update():(this.wrapperDOM.classList.remove("search-results"),this.setMessage(this.options.labels.noResults)),this.emit("datatable.multisearch",e,this._searchData)}page(t,e=!1){return t!==this._currentPage&&(isNaN(t)||(this._currentPage=t),!(t>this.pages.length||t<0)&&(this._renderPage(e),this._renderPagers(),void this.emit("datatable.page",t)))}insert(e){let s=[];if(Array.isArray(e)){const t=this.data.headings.map((t=>t.text??String(t.data)));e.forEach(((e,i)=>{const n=[];Object.entries(e).forEach((([e,s])=>{const a=t.indexOf(e);a>-1?n[a]=F(s,this.columns.settings[a]):this.hasHeadings||this.hasRows||0!==i||(n[t.length]=F(s,this.columns.settings[t.length]),t.push(e),this.data.headings.push(z(e)))})),s.push(n)}))}else t(e)&&(!e.headings||this.hasHeadings||this.hasRows?e.data&&Array.isArray(e.data)&&(s=e.data.map((t=>t.map(((t,e)=>F(t,this.columns.settings[e])))))):this.data=U(e,void 0,this.columns.settings,this.options.type,this.options.format));s.length&&s.forEach((t=>this.data.data.push(t))),this.hasHeadings=Boolean(this.data.headings.length),this.columns._state.sort&&this.columns.sort(this.columns._state.sort.column,this.columns._state.sort.dir,!0),this.update(!0)}refresh(){this.options.searchable&&(Array.from(this.wrapperDOM.querySelectorAll(`.${this.options.classes.input}`)).forEach((t=>{t.value=""})),this._searchQueries=[]),this._currentPage=1,this.onFirstPage=!0,this.update(!0),this.emit("datatable.refresh")}print(){const t=s("table");let e=R(this._tableAttributes,this.data.headings,this.data.data.map(((t,e)=>({row:t,index:e}))),this.columns.settings,this.columns._state,!1,this.options,{noColumnWidths:!0,unhideHeader:!0});if(this.options.tableRender){const t=this.options.tableRender(this.data,e,"print");t&&(e=t)}const i=this._dd.diff({nodeName:"TABLE"},e);this._dd.apply(t,i);const n=window.open();n.document.body.appendChild(t),n.print()}setMessage(t){const e=this.data.headings.filter(((t,e)=>!this.columns.settings[e]?.hidden)).length||1;this.wrapperDOM.classList.add(this.options.classes.empty),this._label&&(this._label.innerHTML=""),this.totalPages=0,this._renderPagers();let s={nodeName:"TABLE",attributes:this._tableAttributes,childNodes:[{nodeName:"THEAD",childNodes:[P(this.data.headings,this.columns.settings,this.columns._state,this.options,{})]},{nodeName:"TBODY",childNodes:[{nodeName:"TR",childNodes:[{nodeName:"TD",attributes:{class:this.options.classes.empty,colspan:String(e)},childNodes:[{nodeName:"#text",data:t}]}]}]}]};if(s.attributes.class=s.attributes.class?`${s.attributes.class} ${this.options.classes.table}`:this.options.classes.table,this.options.tableRender){const t=this.options.tableRender(this.data,s,"message");t&&(s=t)}const i=this._dd.diff(this._virtualDOM,s);this._dd.apply(this.dom,i),this._virtualDOM=s}on(t,e){this._events[t]=this._events[t]||[],this._events[t].push(e)}off(t,e){t in this._events!=!1&&this._events[t].splice(this._events[t].indexOf(e),1)}emit(t,...e){if(t in this._events!=!1)for(let s=0;ss.init())),s},exports.convertCSV=function(e){let s;if(!t(e))return!1;const i={lineDelimiter:"\n",columnDelimiter:",",removeDoubleQuotes:!1,...e};if(i.data.length){s={data:[]};const t=i.data.split(i.lineDelimiter);if(t.length&&(i.headings&&(s.headings=t[0].split(i.columnDelimiter),i.removeDoubleQuotes&&(s.headings=s.headings.map((t=>t.trim().replace(/(^"|"$)/g,"")))),t.shift()),t.forEach(((t,e)=>{s.data[e]=[];const n=t.split(i.columnDelimiter);n.length&&n.forEach((t=>{i.removeDoubleQuotes&&(t=t.trim().replace(/(^"|"$)/g,"")),s.data[e].push(t)}))}))),s)return s}return!1},exports.convertJSON=function(s){let i;if(!t(s))return!1;const n={data:"",...s};if(n.data.length||t(n.data)){const t=!!e(n.data)&&JSON.parse(n.data);if(t?(i={headings:[],data:[]},t.forEach(((t,e)=>{i.data[e]=[],Object.entries(t).forEach((([t,s])=>{i.headings.includes(t)||i.headings.push(t),i.data[e].push(s)}))}))):console.warn("That's not valid JSON!"),i)return i}return!1},exports.createElement=s,exports.exportCSV=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],lineDelimiter:"\n",columnDelimiter:",",...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??t.data));if(a[0]=o,i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));if(a.length){let t="";if(a.forEach((e=>{e.forEach((e=>{"string"==typeof e&&(e=(e=(e=(e=(e=e.trim()).replace(/\s{2,}/g," ")).replace(/\n/g," ")).replace(/"/g,'""')).replace(/#/g,"%23")).includes(",")&&(e=`"${e}"`),t+=e+i.columnDelimiter})),t=t.trim().substring(0,t.length-1),t+=i.lineDelimiter})),t=t.trim().substring(0,t.length-1),i.download){const e=document.createElement("a");e.href=encodeURI(`data:text/csv;charset=utf-8,${t}`),e.download=`${i.filename||"datatable_export"}.csv`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}return t}return!1},exports.exportJSON=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],replacer:null,space:4,...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];if(i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.data)))));const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??String(t.data)));if(a.length){const t=[];a.forEach(((e,s)=>{t[s]=t[s]||{},e.forEach(((e,i)=>{t[s][o[i]]=e}))}));const e=JSON.stringify(t,i.replacer,i.space);if(i.download){const t=new Blob([e],{type:"data:application/json;charset=utf-8"}),s=URL.createObjectURL(t),n=document.createElement("a");n.href=s,n.download=`${i.filename||"datatable_export"}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(s)}return e}return!1},exports.exportSQL=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],tableName:"myTable",...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];if(i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??String(t.data)));if(a.length){let t=`INSERT INTO \`${i.tableName}\` (`;if(o.forEach((e=>{t+=`\`${e}\`,`})),t=t.trim().substring(0,t.length-1),t+=") VALUES ",a.forEach((e=>{t+="(",e.forEach((e=>{t+="string"==typeof e?`"${e}",`:`${e},`})),t=t.trim().substring(0,t.length-1),t+="),"})),t=t.trim().substring(0,t.length-1),t+=";",i.download&&(t=`data:application/sql;charset=utf-8,${t}`),i.download){const e=document.createElement("a");e.href=encodeURI(t),e.download=`${i.filename||"datatable_export"}.sql`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}return t}return!1},exports.exportTXT=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],lineDelimiter:"\n",columnDelimiter:",",...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??t.data));if(a[0]=o,i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.data)))));if(a.length){let t="";if(a.forEach((e=>{e.forEach((e=>{"string"==typeof e&&(e=(e=(e=(e=(e=e.trim()).replace(/\s{2,}/g," ")).replace(/\n/g," ")).replace(/"/g,'""')).replace(/#/g,"%23")).includes(",")&&(e=`"${e}"`),t+=e+i.columnDelimiter})),t=t.trim().substring(0,t.length-1),t+=i.lineDelimiter})),t=t.trim().substring(0,t.length-1),i.download&&(t=`data:text/csv;charset=utf-8,${t}`),i.download){const e=document.createElement("a");e.href=encodeURI(t),e.download=`${i.filename||"datatable_export"}.txt`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}return t}return!1},exports.isJson=e,exports.isObject=t,exports.makeEditable=function(t,e={}){const s=new K(t,e);return t.initialized?s.init():t.on("datatable.init",(()=>s.init())),s}; +"use strict";const t=t=>"[object Object]"===Object.prototype.toString.call(t),e=e=>{let s=!1;try{s=JSON.parse(e)}catch(t){return!1}return!(null===s||!Array.isArray(s)&&!t(s))&&s},s=(t,e)=>{const s=document.createElement(t);if(e&&"object"==typeof e)for(const t in e)"html"===t?s.innerHTML=e[t]:s.setAttribute(t,e[t]);return s},i=t=>["#text","#comment"].includes(t.nodeName)?t.data:t.childNodes?t.childNodes.map((t=>i(t))).join(""):"",n=function(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""")},a=function(t,e){let s=0,i=0;for(;s0;){var s=e.splice(0,1)[0];t=t.childNodes[s]}return t};function c(t,e,s){var i,n,a,o=e[s._const.action],c=e[s._const.route];[s._const.addElement,s._const.addTextElement].includes(o)||(i=d(t,c));var h={diff:e,node:i};if(s.preDiffApply(h))return!0;switch(o){case s._const.addAttribute:if(!i||!r(i,"Element"))return!1;i.setAttribute(e[s._const.name],e[s._const.value]);break;case s._const.modifyAttribute:if(!i||!r(i,"Element"))return!1;i.setAttribute(e[s._const.name],e[s._const.newValue]),r(i,"HTMLInputElement")&&"value"===e[s._const.name]&&(i.value=e[s._const.newValue]);break;case s._const.removeAttribute:if(!i||!r(i,"Element"))return!1;i.removeAttribute(e[s._const.name]);break;case s._const.modifyTextElement:if(!i||!r(i,"Text"))return!1;s.textDiff(i,i.data,e[s._const.oldValue],e[s._const.newValue]),r(i.parentNode,"HTMLTextAreaElement")&&(i.parentNode.value=e[s._const.newValue]);break;case s._const.modifyValue:if(!i||void 0===i.value)return!1;i.value=e[s._const.newValue];break;case s._const.modifyComment:if(!i||!r(i,"Comment"))return!1;s.textDiff(i,i.data,e[s._const.oldValue],e[s._const.newValue]);break;case s._const.modifyChecked:if(!i||void 0===i.checked)return!1;i.checked=e[s._const.newValue];break;case s._const.modifySelected:if(!i||void 0===i.selected)return!1;i.selected=e[s._const.newValue];break;case s._const.replaceElement:var u="svg"===e[s._const.newValue].nodeName.toLowerCase()||"http://www.w3.org/2000/svg"===i.parentNode.namespaceURI;i.parentNode.replaceChild(l(e[s._const.newValue],u,s),i);break;case s._const.relocateGroup:Array.apply(void 0,new Array(e[s._const.groupLength])).map((function(){return i.removeChild(i.childNodes[e[s._const.from]])})).forEach((function(t,n){0===n&&(a=i.childNodes[e[s._const.to]]),i.insertBefore(t,a||null)}));break;case s._const.removeElement:i.parentNode.removeChild(i);break;case s._const.addElement:var p=(m=c.slice()).splice(m.length-1,1)[0];if(!r(i=d(t,m),"Element"))return!1;i.insertBefore(l(e[s._const.element],"http://www.w3.org/2000/svg"===i.namespaceURI,s),i.childNodes[p]||null);break;case s._const.removeTextElement:if(!i||3!==i.nodeType)return!1;var f=i.parentNode;f.removeChild(i),r(f,"HTMLTextAreaElement")&&(f.value="");break;case s._const.addTextElement:var m;p=(m=c.slice()).splice(m.length-1,1)[0];if(n=s.document.createTextNode(e[s._const.value]),!(i=d(t,m)).childNodes)return!1;i.insertBefore(n,i.childNodes[p]||null),r(i.parentNode,"HTMLTextAreaElement")&&(i.parentNode.value=e[s._const.value]);break;default:console.log("unknown action")}return s.postDiffApply({diff:h.diff,node:h.node,newNode:n}),!0}function h(t,e,s){var i=t[e];t[e]=t[s],t[s]=i}function u(t,e,s){(e=e.slice()).reverse(),e.forEach((function(e){!function(t,e,s){switch(e[s._const.action]){case s._const.addAttribute:e[s._const.action]=s._const.removeAttribute,c(t,e,s);break;case s._const.modifyAttribute:h(e,s._const.oldValue,s._const.newValue),c(t,e,s);break;case s._const.removeAttribute:e[s._const.action]=s._const.addAttribute,c(t,e,s);break;case s._const.modifyTextElement:case s._const.modifyValue:case s._const.modifyComment:case s._const.modifyChecked:case s._const.modifySelected:case s._const.replaceElement:h(e,s._const.oldValue,s._const.newValue),c(t,e,s);break;case s._const.relocateGroup:h(e,s._const.from,s._const.to),c(t,e,s);break;case s._const.removeElement:e[s._const.action]=s._const.addElement,c(t,e,s);break;case s._const.addElement:e[s._const.action]=s._const.removeElement,c(t,e,s);break;case s._const.removeTextElement:e[s._const.action]=s._const.addTextElement,c(t,e,s);break;case s._const.addTextElement:e[s._const.action]=s._const.removeTextElement,c(t,e,s);break;default:console.log("unknown action")}}(t,e,s)}))}var p=function(){return p=Object.assign||function(t){for(var e,s=arguments,i=1,n=arguments.length;i=n&&(n=l[h+1][p+1],a=[h+1,p+1]))}return 0!==n&&{oldValue:a[0]-n,newValue:a[1]-n,length:n}}(s,i,n,a);t?(o.push(t),Array.apply(void 0,new Array(t.length)).map(r).forEach((function(e){return function(t,e,s,i){t[s.oldValue+i]=!0,e[s.newValue+i]=!0}(n,a,t,e)}))):l=!0};!l;)d();return t.subsets=o,t.subsetsAge=100,o},N=function(){function t(){this.list=[]}return t.prototype.add=function(t){var e;(e=this.list).push.apply(e,t)},t.prototype.forEach=function(t){this.list.forEach((function(e){return t(e)}))},t}();function D(t,e){var s,i,n=t;for(e=e.slice();e.length>0;)i=e.splice(0,1)[0],s=n,n=n.childNodes?n.childNodes[i]:void 0;return{node:n,parentNode:s,nodeIndex:i}}function M(t,e,s){return e.forEach((function(e){!function(t,e,s){var i,n,a,o;if(![s._const.addElement,s._const.addTextElement].includes(e[s._const.action])){var r=D(t,e[s._const.route]);n=r.node,a=r.parentNode,o=r.nodeIndex}var l,d,c=[],h={diff:e,node:n};if(s.preVirtualDiffApply(h))return!0;switch(e[s._const.action]){case s._const.addAttribute:n.attributes||(n.attributes={}),n.attributes[e[s._const.name]]=e[s._const.value],"checked"===e[s._const.name]?n.checked=!0:"selected"===e[s._const.name]?n.selected=!0:"INPUT"===n.nodeName&&"value"===e[s._const.name]&&(n.value=e[s._const.value]);break;case s._const.modifyAttribute:n.attributes[e[s._const.name]]=e[s._const.newValue];break;case s._const.removeAttribute:delete n.attributes[e[s._const.name]],0===Object.keys(n.attributes).length&&delete n.attributes,"checked"===e[s._const.name]?n.checked=!1:"selected"===e[s._const.name]?delete n.selected:"INPUT"===n.nodeName&&"value"===e[s._const.name]&&delete n.value;break;case s._const.modifyTextElement:n.data=e[s._const.newValue],"TEXTAREA"===a.nodeName&&(a.value=e[s._const.newValue]);break;case s._const.modifyValue:n.value=e[s._const.newValue];break;case s._const.modifyComment:n.data=e[s._const.newValue];break;case s._const.modifyChecked:n.checked=e[s._const.newValue];break;case s._const.modifySelected:n.selected=e[s._const.newValue];break;case s._const.replaceElement:l=v(e[s._const.newValue]),a.childNodes[o]=l;break;case s._const.relocateGroup:n.childNodes.splice(e[s._const.from],e[s._const.groupLength]).reverse().forEach((function(t){return n.childNodes.splice(e[s._const.to],0,t)})),n.subsets&&n.subsets.forEach((function(t){if(e[s._const.from]e[s._const.from])t.oldValue-=e[s._const.groupLength],(i=t.oldValue+t.length-e[s._const.to])>0&&(c.push({oldValue:e[s._const.to]+e[s._const.groupLength],newValue:t.newValue+t.length-i,length:i}),t.length-=i);else if(e[s._const.from]>e[s._const.to]&&t.oldValue>e[s._const.to]&&t.oldValue0&&(c.push({oldValue:e[s._const.to]+e[s._const.groupLength],newValue:t.newValue+t.length-i,length:i}),t.length-=i)}else t.oldValue===e[s._const.from]&&(t.oldValue=e[s._const.to])}));break;case s._const.removeElement:a.childNodes.splice(o,1),a.subsets&&a.subsets.forEach((function(t){t.oldValue>o?t.oldValue-=1:t.oldValue===o?t.delete=!0:t.oldValueo&&(t.oldValue+t.length-1===o?t.length--:(c.push({newValue:t.newValue+o-t.oldValue,oldValue:o,length:t.length-o+t.oldValue-1}),t.length=o-t.oldValue))})),n=a;break;case s._const.addElement:var u=(d=e[s._const.route].slice()).splice(d.length-1,1)[0];n=null===(i=D(t,d))||void 0===i?void 0:i.node,l=v(e[s._const.element]),n.childNodes||(n.childNodes=[]),u>=n.childNodes.length?n.childNodes.push(l):n.childNodes.splice(u,0,l),n.subsets&&n.subsets.forEach((function(t){if(t.oldValue>=u)t.oldValue+=1;else if(t.oldValueu){var e=t.oldValue+t.length-u;c.push({newValue:t.newValue+t.length-e,oldValue:u+1,length:e}),t.length-=e}}));break;case s._const.removeTextElement:a.childNodes.splice(o,1),"TEXTAREA"===a.nodeName&&delete a.value,a.subsets&&a.subsets.forEach((function(t){t.oldValue>o?t.oldValue-=1:t.oldValue===o?t.delete=!0:t.oldValueo&&(t.oldValue+t.length-1===o?t.length--:(c.push({newValue:t.newValue+o-t.oldValue,oldValue:o,length:t.length-o+t.oldValue-1}),t.length=o-t.oldValue))})),n=a;break;case s._const.addTextElement:var p=(d=e[s._const.route].slice()).splice(d.length-1,1)[0];l={nodeName:"#text",data:e[s._const.value]},(n=D(t,d).node).childNodes||(n.childNodes=[]),p>=n.childNodes.length?n.childNodes.push(l):n.childNodes.splice(p,0,l),"TEXTAREA"===n.nodeName&&(n.value=e[s._const.newValue]),n.subsets&&n.subsets.forEach((function(t){if(t.oldValue>=p&&(t.oldValue+=1),t.oldValuep){var e=t.oldValue+t.length-p;c.push({newValue:t.newValue+t.length-e,oldValue:p+1,length:e}),t.length-=e}}));break;default:console.log("unknown action")}n.subsets&&(n.subsets=n.subsets.filter((function(t){return!t.delete&&t.oldValue!==t.newValue})),c.length&&(n.subsets=n.subsets.concat(c))),s.postVirtualDiffApply({node:h.node,diff:h.diff,newNode:l})}(t,e,s)})),!0}function O(t,e){void 0===e&&(e={valueDiffing:!0});var s={nodeName:t.nodeName};if(r(t,"Text","Comment"))s.data=t.data;else{if(t.attributes&&t.attributes.length>0)s.attributes={},Array.prototype.slice.call(t.attributes).forEach((function(t){return s.attributes[t.name]=t.value}));if(t.childNodes&&t.childNodes.length>0)s.childNodes=[],Array.prototype.slice.call(t.childNodes).forEach((function(t){return s.childNodes.push(O(t,e))}));e.valueDiffing&&(r(t,"HTMLTextAreaElement")&&(s.value=t.value),r(t,"HTMLInputElement")&&["radio","checkbox"].includes(t.type.toLowerCase())&&void 0!==t.checked?s.checked=t.checked:r(t,"HTMLButtonElement","HTMLDataElement","HTMLInputElement","HTMLLIElement","HTMLMeterElement","HTMLOptionElement","HTMLProgressElement","HTMLParamElement")&&(s.value=t.value),r(t,"HTMLOptionElement")&&(s.selected=t.selected))}return s}var E=/<\s*\/*[a-zA-Z:_][a-zA-Z0-9:_\-.]*\s*(?:"[^"]*"['"]*|'[^']*'['"]*|[^'"/>])*\/*\s*>|/g,V=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function $(t){return t.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}var C={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,menuItem:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0},S=function(t,e){var s={nodeName:"",attributes:{}},i=!1,n=t.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(s.nodeName=e||"svg"===n[1]?n[1]:n[1].toUpperCase(),(C[n[1]]||"/"===t.charAt(t.length-2))&&(i=!0),s.nodeName.startsWith("!--"))){var a=t.indexOf("--\x3e");return{type:"comment",node:{nodeName:"#comment",data:-1!==a?t.slice(4,a):""},voidElement:i}}for(var o=new RegExp(V),r=null,l=!1;!l;)if(null===(r=o.exec(t)))l=!0;else if(r[0].trim())if(r[1]){var d=r[1].trim(),c=[d,""];d.indexOf("=")>-1&&(c=d.split("=")),s.attributes[c[0]]=c[1],o.lastIndex--}else r[2]&&(s.attributes[r[2]]=r[3].trim().substring(1,r[3].length-1));return{type:"tag",node:s,voidElement:i}},k=function(t,e){void 0===e&&(e={valueDiffing:!0,caseSensitive:!1});var s,i=[],n=-1,a=[],o=!1;if(0!==t.indexOf("<")){var r=t.indexOf("<");i.push({nodeName:"#text",data:-1===r?t:t.substring(0,r)})}return t.replace(E,(function(r,l){var d="/"!==r.charAt(1),c=r.startsWith("\x3c!--"),h=l+r.length,u=t.charAt(h);if(c){var p=S(r,e.caseSensitive).node;if(n<0)return i.push(p),"";var f=a[n];return f&&p.nodeName&&(f.node.childNodes||(f.node.childNodes=[]),f.node.childNodes.push(p)),""}if(d){if("svg"===(s=S(r,e.caseSensitive||o)).node.nodeName&&(o=!0),n++,!s.voidElement&&u&&"<"!==u){s.node.childNodes||(s.node.childNodes=[]);var m=$(t.slice(h,t.indexOf("<",h)));s.node.childNodes.push({nodeName:"#text",data:m}),e.valueDiffing&&"TEXTAREA"===s.node.nodeName&&(s.node.value=m)}0===n&&s.node.nodeName&&i.push(s.node);var g=a[n-1];g&&s.node.nodeName&&(g.node.childNodes||(g.node.childNodes=[]),g.node.childNodes.push(s.node)),a[n]=s}if((!d||s.voidElement)&&(n>-1&&(s.voidElement||e.caseSensitive&&s.node.nodeName===r.slice(2,-1)||!e.caseSensitive&&s.node.nodeName.toUpperCase()===r.slice(2,-1).toUpperCase())&&--n>-1&&("svg"===s.node.nodeName&&(o=!1),s=a[n]),"<"!==u&&u)){var b=-1===n?i:a[n].node.childNodes||[],v=t.indexOf("<",h);m=$(t.slice(h,-1===v?void 0:v));b.push({nodeName:"#text",data:m})}return""})),i[0]},T=function(){function t(t,e,s){this.options=s,this.t1="undefined"!=typeof Element&&r(t,"Element")?O(t,this.options):"string"==typeof t?k(t,this.options):JSON.parse(JSON.stringify(t)),this.t2="undefined"!=typeof Element&&r(e,"Element")?O(e,this.options):"string"==typeof e?k(e,this.options):JSON.parse(JSON.stringify(e)),this.diffcount=0,this.foundAll=!1,this.debug&&(this.t1Orig="undefined"!=typeof Element&&r(t,"Element")?O(t,this.options):"string"==typeof t?k(t,this.options):JSON.parse(JSON.stringify(t)),this.t2Orig="undefined"!=typeof Element&&r(e,"Element")?O(e,this.options):"string"==typeof e?k(e,this.options):JSON.parse(JSON.stringify(e))),this.tracker=new N}return t.prototype.init=function(){return this.findDiffs(this.t1,this.t2)},t.prototype.findDiffs=function(t,e){var s;do{if(this.options.debug&&(this.diffcount+=1,this.diffcount>this.options.diffcap))throw new Error("surpassed diffcap:".concat(JSON.stringify(this.t1Orig)," -> ").concat(JSON.stringify(this.t2Orig)));0===(s=this.findNextDiff(t,e,[])).length&&(w(t,e)||(this.foundAll?console.error("Could not find remaining diffs!"):(this.foundAll=!0,b(t),s=this.findNextDiff(t,e,[])))),s.length>0&&(this.foundAll=!1,this.tracker.add(s),M(t,s,this.options))}while(s.length>0);return this.tracker.list},t.prototype.findNextDiff=function(t,e,s){var i,n;if(this.options.maxDepth&&s.length>this.options.maxDepth)return[];if(!t.outerDone){if(i=this.findOuterDiff(t,e,s),this.options.filterOuterDiff&&(n=this.options.filterOuterDiff(t,e,i))&&(i=n),i.length>0)return t.outerDone=!0,i;t.outerDone=!0}if(Object.prototype.hasOwnProperty.call(t,"data"))return[];if(!t.innerDone){if((i=this.findInnerDiff(t,e,s)).length>0)return i;t.innerDone=!0}if(this.options.valueDiffing&&!t.valueDone){if((i=this.findValueDiff(t,e,s)).length>0)return t.valueDone=!0,i;t.valueDone=!0}return[]},t.prototype.findOuterDiff=function(t,e,s){var i,n,a,r,l,d,c=[];if(t.nodeName!==e.nodeName){if(!s.length)throw new Error("Top level nodes have to be of the same kind.");return[(new o).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,v(t)).setValue(this.options._const.newValue,v(e)).setValue(this.options._const.route,s)]}if(s.length&&this.options.diffcap0&&(l=this.attemptGroupRelocation(t,e,h,s,c)).length>0)return l}for(var u=0;un.length?("#text"===p.nodeName?l.push((new o).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,s.concat(d)).setValue(this.options._const.value,p.data)):l.push((new o).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.element,v(p)).setValue(this.options._const.route,s.concat(d))),i.splice(u,1),u-=1,d-=1,r-=1):i.lengthN+1&&"#text"===f[N+1].nodeName;)if(N+=1,m[w].data===f[N].data){c=!0;break}c||b.push((new o).setValue(this.options._const.action,this.options._const.modifyTextElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.oldValue,d.data).setValue(this.options._const.newValue,m[w].data))}}else b.push((new o).setValue(this.options._const.action,this.options._const.removeTextElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.value,d.data)),u.splice(x,1),f.splice(x,1),g=Math.min(u.length,p.length),x-=1,w-=1;else!0===p[w]?b.push((new o).setValue(this.options._const.action,this.options._const.replaceElement).setValue(this.options._const.oldValue,v(d)).setValue(this.options._const.newValue,v(m[w])).setValue(this.options._const.route,i.concat(x))):(b.push((new o).setValue(this.options._const.action,this.options._const.removeElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.element,v(d))),u.splice(x,1),f.splice(x,1),g=Math.min(u.length,p.length),x-=1,w-=1);else if(!0===p[w])"#text"===(d=m[w]).nodeName?(b.push((new o).setValue(this.options._const.action,this.options._const.addTextElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.value,d.data)),u.splice(x,0,!0),f.splice(x,0,{nodeName:"#text",data:d.data}),g=Math.min(u.length,p.length)):(b.push((new o).setValue(this.options._const.action,this.options._const.addElement).setValue(this.options._const.route,i.concat(x)).setValue(this.options._const.element,v(d))),u.splice(x,0,!0),f.splice(x,0,v(d)),g=Math.min(u.length,p.length));else if(u[x]!==p[w]){if(b.length>0)return b;if(l=s[u[x]],(r=Math.min(l.newValue,f.length-l.length))!==l.oldValue){a=!1;for(var D=0;D({nodeName:"TR",childNodes:t.map(((t,h)=>{const u=e[h]||{type:l,format:n,sortable:!0,searchable:!0};if(u.hidden)return;const p=t.attributes?{...t.attributes}:{};if(u.sortable&&o&&(!r.length||c)&&(u.filter?p["data-filterable"]="true":p["data-sortable"]="true"),u.headerClass&&(p.class=p.class?`${p.class} ${u.headerClass}`:u.headerClass),s.sort&&s.sort.column===h){const t="asc"===s.sort.dir?i.ascending:i.descending;p.class=p.class?`${p.class} ${t}`:t,p["aria-sort"]="asc"===s.sort.dir?"ascending":"descending"}else s.filters[h]&&(p.class=p.class?`${p.class} ${i.filterActive}`:i.filterActive);if(s.widths[h]&&!d){const t=`width: ${s.widths[h]}%;`;p.style=p.style?`${p.style} ${t}`:t}if(r.length&&!c){const t="padding-bottom: 0;padding-top: 0;border: 0;";p.style=p.style?`${p.style} ${t}`:t}const f="html"===t.type?t.data:[{nodeName:"#text",data:t.text??String(t.data)}];return{nodeName:"TH",attributes:p,childNodes:!a&&!r.length||c?u.sortable&&o?[{nodeName:"BUTTON",attributes:{class:u.filter?i.filter:i.sorter},childNodes:f}]:f:[{nodeName:"#text",data:""}]}})).filter((t=>t))}),R=(t,e,s,i,n,a,{classes:o,hiddenHeader:r,header:l,footer:d,format:c,sortable:h,scrollY:u,type:p,rowRender:f,tabIndex:m},{noColumnWidths:g,unhideHeader:b,renderHeader:v},w,_)=>{const y={nodeName:"TABLE",attributes:{...t},childNodes:[{nodeName:"TBODY",childNodes:s.map((({row:t,index:e})=>{const s={nodeName:"TR",attributes:{"data-index":String(e)},childNodes:t.map(((t,s)=>{const a=i[s]||{type:p,format:c,sortable:!0,searchable:!0};if(a.hidden)return;const o={nodeName:"TD",attributes:t.attributes?{...t.attributes}:{},childNodes:"html"===a.type?t.data:[{nodeName:"#text",data:t.text??String(t.data)}]};if(l||d||!n.widths[s]||g||(o.attributes.style||(o.attributes.style=""),o.attributes.style+=`width: ${n.widths[s]}%;`),a.cellClass&&(o.attributes.class?o.attributes.class+=" ":o.attributes.class="",o.attributes.class+=a.cellClass),a.render){const i=a.render(t.data,o,e,s);if(i){if("string"!=typeof i)return i;{const t=k(`${i}`);1===t.childNodes.length&&["#text","#comment"].includes(t.childNodes[0].nodeName)?o.childNodes[0].data=i:o.childNodes=t.childNodes}}}return o})).filter((t=>t))};if(e===a&&(s.attributes.class=o.cursor),f){const i=f(t,s,e);if(i){if("string"!=typeof i)return i;{const t=k(`${i}`);!t.childNodes||1===t.childNodes.length&&["#text","#comment"].includes(t.childNodes[0].nodeName)?s.childNodes[0].data=i:s.childNodes=t.childNodes}}}return s}))}]};if(y.attributes.class=y.attributes.class?`${y.attributes.class} ${o.table}`:o.table,l||d||v){const t=P(e,i,n,{classes:o,hiddenHeader:r,sortable:h,scrollY:u},{noColumnWidths:g,unhideHeader:b});if(l||v){const e={nodeName:"THEAD",childNodes:[t]};!u.length&&!r||b||(e.attributes={style:"height: 0px;"}),y.childNodes.unshift(e)}if(d){const e={nodeName:"TFOOT",childNodes:[l?structuredClone(t):t]};!u.length&&!r||b||(e.attributes={style:"height: 0px;"}),y.childNodes.push(e)}}return w.forEach((t=>y.childNodes.push(t))),_.forEach((t=>y.childNodes.push(t))),!1!==m&&(y.attributes.tabindex=String(m)),y};"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function H(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var I={exports:{}},Y=H(I.exports=function(){var t=1e3,e=6e4,s=36e5,i="millisecond",n="second",a="minute",o="hour",r="day",l="week",d="month",c="quarter",h="year",u="date",p="Invalid Date",f=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,m=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,g={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],s=t%100;return"["+t+(e[(s-20)%10]||e[s]||e[0])+"]"}},b=function(t,e,s){var i=String(t);return!i||i.length>=e?t:""+Array(e+1-i.length).join(s)+t},v={s:b,z:function(t){var e=-t.utcOffset(),s=Math.abs(e),i=Math.floor(s/60),n=s%60;return(e<=0?"+":"-")+b(i,2,"0")+":"+b(n,2,"0")},m:function t(e,s){if(e.date()1)return t(o[0])}else{var r=e.name;_[r]=e,n=r}return!i&&n&&(w=n),n||!i&&w},D=function(t,e){if(x(t))return t.clone();var s="object"==typeof e?e:{};return s.date=t,s.args=arguments,new O(s)},M=v;M.l=N,M.i=x,M.w=function(t,e){return D(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var O=function(){function g(t){this.$L=N(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[y]=!0}var b=g.prototype;return b.parse=function(t){this.$d=function(t){var e=t.date,s=t.utc;if(null===e)return new Date(NaN);if(M.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var i=e.match(f);if(i){var n=i[2]-1||0,a=(i[7]||"0").substring(0,3);return s?new Date(Date.UTC(i[1],n,i[3]||1,i[4]||0,i[5]||0,i[6]||0,a)):new Date(i[1],n,i[3]||1,i[4]||0,i[5]||0,i[6]||0,a)}}return new Date(e)}(t),this.init()},b.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},b.$utils=function(){return M},b.isValid=function(){return!(this.$d.toString()===p)},b.isSame=function(t,e){var s=D(t);return this.startOf(e)<=s&&s<=this.endOf(e)},b.isAfter=function(t,e){return D(t)68?1900:2e3)},r=function(t){return function(e){this[t]=+e}},l=[/[+-]\d\d:?(\d\d)?|Z/,function(t){(this.zone||(this.zone={})).offset=function(t){if(!t)return 0;if("Z"===t)return 0;var e=t.match(/([+-]|\d\d)/g),s=60*e[1]+(+e[2]||0);return 0===s?0:"+"===e[0]?-s:s}(t)}],d=function(t){var e=a[t];return e&&(e.indexOf?e:e.s.concat(e.f))},c=function(t,e){var s,i=a.meridiem;if(i){for(var n=1;n<=24;n+=1)if(t.indexOf(i(n,0,e))>-1){s=n>12;break}}else s=t===(e?"pm":"PM");return s},h={A:[n,function(t){this.afternoon=c(t,!1)}],a:[n,function(t){this.afternoon=c(t,!0)}],S:[/\d/,function(t){this.milliseconds=100*+t}],SS:[s,function(t){this.milliseconds=10*+t}],SSS:[/\d{3}/,function(t){this.milliseconds=+t}],s:[i,r("seconds")],ss:[i,r("seconds")],m:[i,r("minutes")],mm:[i,r("minutes")],H:[i,r("hours")],h:[i,r("hours")],HH:[i,r("hours")],hh:[i,r("hours")],D:[i,r("day")],DD:[s,r("day")],Do:[n,function(t){var e=a.ordinal,s=t.match(/\d+/);if(this.day=s[0],e)for(var i=1;i<=31;i+=1)e(i).replace(/\[|\]/g,"")===t&&(this.day=i)}],M:[i,r("month")],MM:[s,r("month")],MMM:[n,function(t){var e=d("months"),s=(d("monthsShort")||e.map((function(t){return t.slice(0,3)}))).indexOf(t)+1;if(s<1)throw new Error;this.month=s%12||s}],MMMM:[n,function(t){var e=d("months").indexOf(t)+1;if(e<1)throw new Error;this.month=e%12||e}],Y:[/[+-]?\d+/,r("year")],YY:[s,function(t){this.year=o(t)}],YYYY:[/\d{4}/,r("year")],Z:l,ZZ:l};function u(s){var i,n;i=s,n=a&&a.formats;for(var o=(s=i.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(e,s,i){var a=i&&i.toUpperCase();return s||n[i]||t[i]||n[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(t,e,s){return e||s.slice(1)}))}))).match(e),r=o.length,l=0;l-1)return new Date(("X"===e?1e3:1)*t);var i=u(e)(t),n=i.year,a=i.month,o=i.day,r=i.hours,l=i.minutes,d=i.seconds,c=i.milliseconds,h=i.zone,p=new Date,f=o||(n||a?1:p.getDate()),m=n||p.getFullYear(),g=0;n&&!a||(g=a>0?a-1:p.getMonth());var b=r||0,v=l||0,w=d||0,_=c||0;return h?new Date(Date.UTC(m,g,f,b,v,w,_+60*h.offset*1e3)):s?new Date(Date.UTC(m,g,f,b,v,w,_)):new Date(m,g,f,b,v,w,_)}catch(t){return new Date("")}}(e,r,i),this.init(),h&&!0!==h&&(this.$L=this.locale(h).$L),c&&e!=this.format(r)&&(this.$d=new Date("")),a={}}else if(r instanceof Array)for(var p=r.length,f=1;f<=p;f+=1){o[1]=r[f-1];var m=s.apply(this,o);if(m.isValid()){this.$d=m.$d,this.$L=m.$L,this.init();break}f===p&&(this.$d=new Date(""))}else n.call(this,t)}}}());Y.extend(q);const F=(t,e)=>{let s;if(e)switch(e){case"ISO_8601":s=t;break;case"RFC_2822":s=Y(t.slice(5),"DD MMM YYYY HH:mm:ss ZZ").unix();break;case"MYSQL":s=Y(t,"YYYY-MM-DD hh:mm:ss").unix();break;case"UNIX":s=Y(t).unix();break;default:s=Y(t,e,!0).valueOf()}return s},B=(t,e)=>{if(t?.constructor===Object&&Object.prototype.hasOwnProperty.call(t,"data")&&!Object.keys(t).find((t=>!["text","order","data"].includes(t))))return t;const s={data:t};switch(e.type){case"string":"string"!=typeof t&&(s.text=String(s.data),s.order=s.text);break;case"date":e.format&&(s.order=F(String(s.data),e.format));break;case"number":s.text=String(s.data),s.data=parseInt(s.data,10);break;case"html":{const t=Array.isArray(s.data)?{nodeName:"TD",childNodes:s.data}:k(`${String(s.data)}`);s.data=t.childNodes||[];const e=i(t);s.text=e,s.order=e;break}case"boolean":"string"==typeof s.data&&(s.data=s.data.toLowerCase().trim()),s.data=!["false",!1,null,void 0,0].includes(s.data),s.order=s.data?1:0,s.text=String(s.data);break;case"other":s.text="",s.order=0;break;default:s.text=JSON.stringify(s.data)}return s},z=t=>{if(t instanceof Object&&t.constructor===Object&&t.hasOwnProperty("data")&&("string"==typeof t.text||"string"==typeof t.data))return t;const e={data:t};if("string"==typeof t){if(t.length){const s=k(`${t}`);if(s.childNodes&&(1!==s.childNodes.length||"#text"!==s.childNodes[0].nodeName)){e.data=s.childNodes,e.type="html";const t=i(s);e.text=t}}}else[null,void 0].includes(t)?e.text="":e.text=JSON.stringify(t);return e},U=(t,e=void 0,s,n,a)=>{const o={data:[],headings:[]};t.headings?o.headings=t.headings.map((t=>z(t))):e?.tHead?o.headings=Array.from(e.tHead.querySelectorAll("th")).map(((t,e)=>{const o=(t=>{const e=O(t,{valueDiffing:!1});let s;return s=!e.childNodes||1===e.childNodes.length&&"#text"===e.childNodes[0].nodeName?{data:t.innerText,type:"string"}:{data:e.childNodes,type:"html",text:i(e)},s.attributes=e.attributes,s})(t);s[e]||(s[e]={type:n,format:a,searchable:!0,sortable:!0});const r=s[e];return"false"!==t.dataset.sortable?.trim().toLowerCase()&&"false"!==t.dataset.sort?.trim().toLowerCase()||(r.sortable=!1),"false"===t.dataset.searchable?.trim().toLowerCase()&&(r.searchable=!1),"true"!==t.dataset.hidden?.trim().toLowerCase()&&"true"!==t.getAttribute("hidden")?.trim().toLowerCase()||(r.hidden=!0),["number","string","html","date","boolean","other"].includes(t.dataset.type)&&(r.type=t.dataset.type,"date"===r.type&&t.dataset.format&&(r.format=t.dataset.format)),o})):t.data?.length?o.headings=t.data[0].map((t=>z(""))):e?.tBodies.length&&(o.headings=Array.from(e.tBodies[0].rows[0].cells).map((t=>z(""))));for(let t=0;tt.map(((t,e)=>B(t,s[e]))))):e?.tBodies?.length&&(o.data=Array.from(e.tBodies[0].rows).map((t=>Array.from(t.cells).map(((t,e)=>{const i=t.dataset.content?B(t.dataset.content,s[e]):((t,e)=>{let s;switch(e.type){case"string":s={data:t.innerText};break;case"date":{const i=t.innerText;s={data:i,order:F(i,e.format)};break}case"number":s={data:parseInt(t.innerText,10),text:t.innerText};break;case"boolean":{const e=!["false","0","null","undefined"].includes(t.innerText.toLowerCase().trim());s={data:e,text:e?"1":"0",order:e?1:0};break}default:s={data:O(t,{valueDiffing:!1}).childNodes||[],text:t.innerText,order:t.innerText}}if(s.attributes={},t.attributes)for(const e of t.attributes)s.attributes[e.name]=e.value;return s})(t,s[e]);return t.dataset.order&&(i.order=isNaN(parseFloat(t.dataset.order))?t.dataset.order:parseFloat(t.dataset.order)),i}))))),o.data.length&&o.data[0].length!==o.headings.length)throw new Error("Data heading length mismatch.");return o};class J{constructor(t){this.dt=t,this.cursor=!1}setCursor(t=!1){if(t===this.cursor)return;const e=this.cursor;if(this.cursor=t,this.dt._renderTable(),!1!==t&&this.dt.options.scrollY){const t=this.dt.dom.querySelector(`tr.${this.dt.options.classes.cursor}`);t&&t.scrollIntoView({block:"nearest"})}this.dt.emit("datatable.cursormove",this.cursor,e)}add(t){const e=t.map(((t,e)=>{const s=this.dt.columns.settings[e];return B(t,s)}));this.dt.data.data.push(e),this.dt.data.data.length&&(this.dt.hasRows=!0),this.dt.update(!0)}remove(t){if(!Array.isArray(t))return this.remove([t]);this.dt.data.data=this.dt.data.data.filter(((e,s)=>!t.includes(s))),this.dt.data.data.length||(this.dt.hasRows=!1),this.dt.update(!0)}findRowIndex(t,e){return this.dt.data.data.findIndex((s=>(s[t].text??String(s[t].data)).toLowerCase().includes(String(e).toLowerCase())))}findRow(t,e){const s=this.findRowIndex(t,e);if(s<0)return{index:-1,row:null,cols:[]};const i=this.dt.data.data[s],n=i.map((t=>t.data));return{index:s,row:i,cols:n}}updateRow(t,e){const s=e.map(((t,e)=>{const s=this.dt.columns.settings[e];return B(t,s)}));this.dt.data.data.splice(t,1,s),this.dt.update(!0)}}class W{constructor(t){this.dt=t,this.init()}init(){[this.settings,this._state]=((t=[],e,s)=>{let i=[],n=!1;const a=[];return t.forEach((t=>{(Array.isArray(t.select)?t.select:[t.select]).forEach((o=>{i[o]?t.type&&(i[o].type=t.type):i[o]={type:t.type||e,sortable:!0,searchable:!0};const r=i[o];t.render&&(r.render=t.render),t.format?r.format=t.format:"date"===t.type&&(r.format=s),t.cellClass&&(r.cellClass=t.cellClass),t.headerClass&&(r.headerClass=t.headerClass),t.locale&&(r.locale=t.locale),!1===t.sortable?r.sortable=!1:(t.numeric&&(r.numeric=t.numeric),t.caseFirst&&(r.caseFirst=t.caseFirst)),!1===t.searchable?r.searchable=!1:t.sensitivity&&(r.sensitivity=t.sensitivity),(r.searchable||r.sortable)&&void 0!==t.ignorePunctuation&&(r.ignorePunctuation=t.ignorePunctuation),t.hidden&&(r.hidden=!0),t.filter&&(r.filter=t.filter),t.sortSequence&&(r.sortSequence=t.sortSequence),t.sort&&(t.filter?a[o]=t.sort:n={column:o,dir:t.sort}),void 0!==t.searchItemSeparator&&(r.searchItemSeparator=t.searchItemSeparator)}))})),i=i.map((t=>t||{type:e,format:"date"===e?s:void 0,sortable:!0,searchable:!0})),[i,{filters:a,sort:n,widths:[]}]})(this.dt.options.columns,this.dt.options.type,this.dt.options.format)}get(t){return t<0||t>=this.size()?null:{...this.settings[t]}}size(){return this.settings.length}swap(t){if(2===t.length){const e=this.dt.data.headings.map(((t,e)=>e)),s=t[0],i=t[1],n=e[i];return e[i]=e[s],e[s]=n,this.order(e)}}order(t){this.dt.data.headings=t.map((t=>this.dt.data.headings[t])),this.dt.data.data=this.dt.data.data.map((e=>t.map((t=>e[t])))),this.settings=t.map((t=>this.settings[t])),this.dt.update()}hide(t){t.length&&(t.forEach((t=>{this.settings[t]||(this.settings[t]={type:"string"});this.settings[t].hidden=!0})),this.dt.update())}show(t){t.length&&(t.forEach((t=>{this.settings[t]||(this.settings[t]={type:"string",sortable:!0});delete this.settings[t].hidden})),this.dt.update())}visible(t){return void 0===t&&(t=[...Array(this.dt.data.headings.length).keys()]),Array.isArray(t)?t.map((t=>!this.settings[t]?.hidden)):!this.settings[t]?.hidden}add(t){const e=this.dt.data.headings.length;if(this.dt.data.headings=this.dt.data.headings.concat([z(t.heading)]),this.dt.data.data=this.dt.data.data.map(((e,s)=>e.concat([B(t.data[s],t)]))),this.settings[e]={type:t.type||"string",sortable:!0,searchable:!0},t.type||t.format||t.sortable||t.render||t.filter){const s=this.settings[e];t.render&&(s.render=t.render),t.format&&(s.format=t.format),t.cellClass&&(s.cellClass=t.cellClass),t.headerClass&&(s.headerClass=t.headerClass),t.locale&&(s.locale=t.locale),!1===t.sortable?s.sortable=!1:(t.numeric&&(s.numeric=t.numeric),t.caseFirst&&(s.caseFirst=t.caseFirst)),!1===t.searchable?s.searchable=!1:t.sensitivity&&(s.sensitivity=t.sensitivity),(s.searchable||s.sortable)&&t.ignorePunctuation&&(s.ignorePunctuation=t.ignorePunctuation),t.hidden&&(s.hidden=!0),t.filter&&(s.filter=t.filter),t.sortSequence&&(s.sortSequence=t.sortSequence)}this.dt.update(!0)}remove(t){if(!Array.isArray(t))return this.remove([t]);this.dt.data.headings=this.dt.data.headings.filter(((e,s)=>!t.includes(s))),this.dt.data.data=this.dt.data.data.map((e=>e.filter(((e,s)=>!t.includes(s))))),this.dt.update(!0)}filter(t,e=!1){if(!this.settings[t]?.filter?.length)return;const s=this._state.filters[t];let i;if(s){let e=!1;i=this.settings[t].filter.find((t=>!!e||(t===s&&(e=!0),!1)))}else{const e=this.settings[t].filter;i=e?e[0]:void 0}i?this._state.filters[t]=i:s&&(this._state.filters[t]=void 0),this.dt._currentPage=1,this.dt.update(),e||this.dt.emit("datatable.filter",t,i)}sort(t,e=void 0,s=!1){const i=this.settings[t];if(s||this.dt.emit("datatable.sorting",t,e),!e){const s=!(!this._state.sort||this._state.sort.column!==t)&&this._state.sort?.dir,n=i?.sortSequence||["asc","desc"];if(s){const t=n.indexOf(s);e=-1===t?n[0]||"asc":t===n.length-1?n[0]:n[t+1]}else e=n.length?n[0]:"asc"}const n=!!["string","html"].includes(i.type)&&new Intl.Collator(i.locale||this.dt.options.locale,{usage:"sort",numeric:i.numeric||this.dt.options.numeric,caseFirst:i.caseFirst||this.dt.options.caseFirst,ignorePunctuation:i.ignorePunctuation||this.dt.options.ignorePunctuation});this.dt.data.data.sort(((s,i)=>{let a=s[t].order||s[t].data,o=i[t].order||i[t].data;if("desc"===e){const t=a;a=o,o=t}return n?n.compare(String(a),String(o)):ao?1:0})),this._state.sort={column:t,dir:e},this.dt._searchQueries.length?(this.dt.multiSearch(this.dt._searchQueries),this.dt.emit("datatable.sort",t,e)):s||(this.dt._currentPage=1,this.dt.update(),this.dt.emit("datatable.sort",t,e))}_measureWidths(){const t=this.dt.data.headings.filter(((t,e)=>!this.settings[e]?.hidden));if((this.dt.options.scrollY.length||this.dt.options.fixedColumns)&&t?.length){this._state.widths=[];const t={noPaging:!0};if(this.dt.options.header||this.dt.options.footer){this.dt.options.scrollY.length&&(t.unhideHeader=!0),this.dt.headerDOM&&this.dt.headerDOM.parentElement.removeChild(this.dt.headerDOM),t.noColumnWidths=!0,this.dt._renderTable(t);const e=Array.from(this.dt.dom.querySelector("thead, tfoot")?.firstElementChild?.querySelectorAll("th")||[]);let s=0;const i=this.dt.data.headings.map(((t,i)=>{if(this.settings[i]?.hidden)return 0;const n=e[s].offsetWidth;return s+=1,n})),n=i.reduce(((t,e)=>t+e),0);this._state.widths=i.map((t=>t/n*100))}else{t.renderHeader=!0,this.dt._renderTable(t);const e=Array.from(this.dt.dom.querySelector("thead, tfoot")?.firstElementChild?.querySelectorAll("th")||[]);let s=0;const i=this.dt.data.headings.map(((t,i)=>{if(this.settings[i]?.hidden)return 0;const n=e[s].offsetWidth;return s+=1,n})),n=i.reduce(((t,e)=>t+e),0);this._state.widths=i.map((t=>t/n*100))}this.dt._renderTable()}}}const Q={sortable:!0,locale:"en",numeric:!0,caseFirst:"false",searchable:!0,sensitivity:"base",ignorePunctuation:!0,destroyable:!0,searchItemSeparator:"",searchQuerySeparator:" ",searchAnd:!1,data:{},type:"html",format:"YYYY-MM-DD",columns:[],paging:!0,perPage:10,perPageSelect:[5,10,15,20,25],nextPrev:!0,firstLast:!1,prevText:"‹",nextText:"›",firstText:"«",lastText:"»",ellipsisText:"…",truncatePager:!0,pagerDelta:2,scrollY:"",fixedColumns:!0,fixedHeight:!1,footer:!1,header:!0,hiddenHeader:!1,caption:void 0,rowNavigation:!1,tabIndex:!1,pagerRender:!1,rowRender:!1,tableRender:!1,diffDomOptions:{valueDiffing:!1},labels:{placeholder:"Search...",searchTitle:"Search within table",perPage:"entries per page",pageTitle:"Page {page}",noRows:"No entries found",noResults:"No results match your search query",info:"Showing {start} to {end} of {rows} entries"},template:(t,e)=>`
      \n ${t.paging&&t.perPageSelect?`
      \n \n
      `:""}\n ${t.searchable?`
      \n \n
      `:""}\n
      \n
      \n
      \n ${t.paging?`
      `:""}\n \n
      `,classes:{active:"datatable-active",ascending:"datatable-ascending",bottom:"datatable-bottom",container:"datatable-container",cursor:"datatable-cursor",descending:"datatable-descending",disabled:"datatable-disabled",dropdown:"datatable-dropdown",ellipsis:"datatable-ellipsis",filter:"datatable-filter",filterActive:"datatable-filter-active",empty:"datatable-empty",headercontainer:"datatable-headercontainer",hidden:"datatable-hidden",info:"datatable-info",input:"datatable-input",loading:"datatable-loading",pagination:"datatable-pagination",paginationList:"datatable-pagination-list",paginationListItem:"datatable-pagination-list-item",paginationListItemLink:"datatable-pagination-list-item-link",search:"datatable-search",selector:"datatable-selector",sorter:"datatable-sorter",table:"datatable-table",top:"datatable-top",wrapper:"datatable-wrapper"}},X=(t,e,s,i={})=>({nodeName:"LI",attributes:{class:i.active&&!i.hidden?`${s.classes.paginationListItem} ${s.classes.active}`:i.hidden?`${s.classes.paginationListItem} ${s.classes.hidden} ${s.classes.disabled}`:s.classes.paginationListItem},childNodes:[{nodeName:"BUTTON",attributes:{"data-page":String(t),class:s.classes.paginationListItemLink,"aria-label":s.labels.pageTitle.replace("{page}",String(t))},childNodes:[{nodeName:"#text",data:e}]}]}),Z=(t,e,s,i,n)=>{let a=[];if(n.firstLast&&a.push(X(1,n.firstText,n)),n.nextPrev){const e=t?1:s-1;a.push(X(e,n.prevText,n,{hidden:t}))}let o=[...Array(i).keys()].map((t=>X(t+1,String(t+1),n,{active:t===s-1})));if(n.truncatePager&&(o=((t,e,s,i)=>{const n=i.pagerDelta,a=i.classes,o=i.ellipsisText,r=2*n;let l=e-n,d=e+n;e<4-n+r?d=3+r:e>s-(3-n+r)&&(l=s-(2+r));const c=[];for(let e=1;e<=s;e++)if(1==e||e==s||e>=l&&e<=d){const s=t[e-1];c.push(s)}let h;const u=[];return c.forEach((e=>{const s=parseInt(e.childNodes[0].attributes["data-page"],10);if(h){const e=parseInt(h.childNodes[0].attributes["data-page"],10);if(s-e==2)u.push(t[e]);else if(s-e!=1){const t={nodeName:"LI",attributes:{class:`${a.paginationListItem} ${a.ellipsis} ${a.disabled}`},childNodes:[{nodeName:"BUTTON",attributes:{class:a.paginationListItemLink},childNodes:[{nodeName:"#text",data:o}]}]};u.push(t)}}u.push(e),h=e})),u})(o,s,i,n)),a=a.concat(o),n.nextPrev){const t=e?i:s+1;a.push(X(t,n.nextText,n,{hidden:e}))}n.firstLast&&a.push(X(i,n.lastText,n));return{nodeName:"UL",attributes:{class:n.classes.paginationList},childNodes:o.length>1?a:[]}};const G={classes:{row:"datatable-editor-row",form:"datatable-editor-form",item:"datatable-editor-item",menu:"datatable-editor-menu",save:"datatable-editor-save",block:"datatable-editor-block",cancel:"datatable-editor-cancel",close:"datatable-editor-close",inner:"datatable-editor-inner",input:"datatable-editor-input",label:"datatable-editor-label",modal:"datatable-editor-modal",action:"datatable-editor-action",header:"datatable-editor-header",wrapper:"datatable-editor-wrapper",editable:"datatable-editor-editable",container:"datatable-editor-container",separator:"datatable-editor-separator"},labels:{closeX:"x",editCell:"Edit Cell",editRow:"Edit Row",removeRow:"Remove Row",reallyRemove:"Are you sure?",reallyCancel:"Do you really want to cancel?",save:"Save",cancel:"Cancel"},cancelModal:t=>confirm(t.options.labels.reallyCancel),inline:!0,hiddenColumns:!1,contextMenu:!0,clickEvent:"dblclick",excludeColumns:[],menuItems:[{text:t=>t.options.labels.editCell,action:(t,e)=>{if(!(t.event.target instanceof Element))return;const s=t.event.target.closest("td");return t.editCell(s)}},{text:t=>t.options.labels.editRow,action:(t,e)=>{if(!(t.event.target instanceof Element))return;const s=t.event.target.closest("tr");return t.editRow(s)}},{separator:!0},{text:t=>t.options.labels.removeRow,action:(t,e)=>{if(t.event.target instanceof Element&&confirm(t.options.labels.reallyRemove)){const e=t.event.target.closest("tr");t.removeRow(e)}}}]};class K{constructor(t,e={}){this.dt=t,this.options={...G,...e}}init(){this.initialized||(this.dt.wrapperDOM.classList.add(this.options.classes.editable),this.options.inline&&(this.originalRowRender=this.dt.options.rowRender,this.dt.options.rowRender=(t,e,s)=>{let i=this.rowRender(t,e,s);return this.originalRowRender&&(i=this.originalRowRender(t,i,s)),i}),this.options.contextMenu&&(this.containerDOM=s("div",{id:this.options.classes.container}),this.wrapperDOM=s("div",{class:this.options.classes.wrapper}),this.menuDOM=s("ul",{class:this.options.classes.menu}),this.options.menuItems&&this.options.menuItems.length&&this.options.menuItems.forEach((t=>{const e=s("li",{class:t.separator?this.options.classes.separator:this.options.classes.item});if(!t.separator){const i=s("a",{class:this.options.classes.action,href:t.url||"#",html:"function"==typeof t.text?t.text(this):t.text});e.appendChild(i),t.action&&"function"==typeof t.action&&i.addEventListener("click",(e=>{e.preventDefault(),t.action(this,e)}))}this.menuDOM.appendChild(e)})),this.wrapperDOM.appendChild(this.menuDOM),this.containerDOM.appendChild(this.wrapperDOM),this.updateMenu()),this.data={},this.menuOpen=!1,this.editing=!1,this.editingRow=!1,this.editingCell=!1,this.bindEvents(),setTimeout((()=>{this.initialized=!0,this.dt.emit("editable.init")}),10))}bindEvents(){this.events={keydown:this.keydown.bind(this),click:this.click.bind(this)},this.dt.dom.addEventListener(this.options.clickEvent,this.events.click),document.addEventListener("keydown",this.events.keydown),this.options.contextMenu&&(this.events.context=this.context.bind(this),this.events.updateMenu=this.updateMenu.bind(this),this.events.dismissMenu=this.dismissMenu.bind(this),this.events.reset=function(t,e=300){let s;return(...i)=>{clearTimeout(s),s=window.setTimeout((()=>t()),e)}}((()=>this.events.updateMenu()),50),this.dt.dom.addEventListener("contextmenu",this.events.context),document.addEventListener("click",this.events.dismissMenu),window.addEventListener("resize",this.events.reset),window.addEventListener("scroll",this.events.reset))}context(t){const e=t.target;if(!(e instanceof Element))return;this.event=t;const s=e.closest("tbody td");if(!this.disabled&&s){t.preventDefault();let e=t.pageX,s=t.pageY;e>this.limits.x&&(e-=this.rect.width),s>this.limits.y&&(s-=this.rect.height),this.wrapperDOM.style.top=`${s}px`,this.wrapperDOM.style.left=`${e}px`,this.openMenu(),this.updateMenu()}}click(t){const e=t.target;if(e instanceof Element)if(this.editing&&this.data&&this.editingCell){const t=this.modalDOM?this.modalDOM.querySelector(`input.${this.options.classes.input}[type=text]`):this.dt.wrapperDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}else if(!this.editing){const s=e.closest("tbody td");s&&(this.editCell(s),t.preventDefault())}}keydown(t){if(this.modalDOM){if("Escape"===t.key)this.options.cancelModal(this)&&this.closeModal();else if("Enter"===t.key)if(this.editingCell){const t=this.modalDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}else{const t=Array.from(this.modalDOM.querySelectorAll(`input.${this.options.classes.input}[type=text]`)).map((t=>t.value.trim()));this.saveRow(t,this.data.row)}}else if(this.editing&&this.data)if("Enter"===t.key){if(this.editingCell){const t=this.dt.wrapperDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}else if(this.editingRow){const t=Array.from(this.dt.wrapperDOM.querySelectorAll(`input.${this.options.classes.input}[type=text]`)).map((t=>t.value.trim()));this.saveRow(t,this.data.row)}}else"Escape"===t.key&&(this.editingCell?this.saveCell(this.data.content):this.editingRow&&this.saveRow(null,this.data.row))}editCell(t){const e=a(t.cellIndex,this.dt.columns.settings);if(this.options.excludeColumns.includes(e))return void this.closeMenu();const s=parseInt(t.parentElement.dataset.index,10),i=this.dt.data.data[s][e];this.data={cell:i,rowIndex:s,columnIndex:e,content:i.text||String(i.data)},this.editing=!0,this.editingCell=!0,this.options.inline?this.dt.update():this.editCellModal(),this.closeMenu()}editCellModal(){const t=this.data.cell,e=this.data.columnIndex,i=this.dt.data.headings[e].text||String(this.dt.data.headings[e].data),a=[`
      `,`
      `,`

      ${this.options.labels.editCell}

      `,``,"
      ",`
      `,`
      `,`
      `,``,``,"
      ",`
      `,``,``,"
      ","
      ","
      ","
      "].join(""),o=s("div",{class:this.options.classes.modal,html:a});this.modalDOM=o,this.openModal();const r=o.querySelector(`input.${this.options.classes.input}[type=text]`);r.focus(),r.selectionStart=r.selectionEnd=r.value.length,o.addEventListener("click",(t=>{const e=t.target;e instanceof Element&&(e.hasAttribute("data-editor-cancel")?(t.preventDefault(),this.options.cancelModal(this)&&this.closeModal()):e.hasAttribute("data-editor-save")&&(t.preventDefault(),this.saveCell(r.value)))}))}saveCell(t){const e=this.data.content,s=this.dt.columns.settings[this.data.columnIndex].type||this.dt.options.type,i=t.trim();let n;if("number"===s)n={data:parseFloat(i)};else if("boolean"===s)n=["","false","0"].includes(i)?{data:!1,text:"false",order:0}:{data:!0,text:"true",order:1};else if("html"===s)n={data:[{nodeName:"#text",data:t}],text:t,order:t};else if("string"===s)n={data:t};else if("date"===s){const e=this.dt.columns.settings[this.data.columnIndex].format||this.dt.options.format;n={data:t,order:F(String(t),e)}}else n={data:t};this.dt.data.data[this.data.rowIndex][this.data.columnIndex]=n,this.closeModal();const a=this.data.rowIndex,o=this.data.columnIndex;this.data={},this.dt.update(!0),this.editing=!1,this.editingCell=!1,this.dt.emit("editable.save.cell",t,e,a,o)}editRow(t){if(!t||"TR"!==t.nodeName||this.editing)return;const e=parseInt(t.dataset.index,10),s=this.dt.data.data[e];this.data={row:s,rowIndex:e},this.editing=!0,this.editingRow=!0,this.options.inline?this.dt.update():this.editRowModal(),this.closeMenu()}editRowModal(){const t=this.data.row,e=[`
      `,`
      `,`

      ${this.options.labels.editRow}

      `,``,"
      ",`
      `,`
      `,`
      `,``,``,"
      ","
      ","
      ","
      "].join(""),i=s("div",{class:this.options.classes.modal,html:e}),a=i.firstElementChild;if(!a)return;const o=a.lastElementChild?.firstElementChild;if(!o)return;t.forEach(((t,e)=>{const i=this.dt.columns.settings[e];if((!i.hidden||i.hidden&&this.options.hiddenColumns)&&!this.options.excludeColumns.includes(e)){const i=this.dt.data.headings[e].text||String(this.dt.data.headings[e].data);o.insertBefore(s("div",{class:this.options.classes.row,html:[`
      `,``,``,"
      "].join("")}),o.lastElementChild)}})),this.modalDOM=i,this.openModal();const r=Array.from(o.querySelectorAll(`input.${this.options.classes.input}[type=text]`));i.addEventListener("click",(t=>{const e=t.target;if(e instanceof Element)if(e.hasAttribute("data-editor-cancel"))this.options.cancelModal(this)&&this.closeModal();else if(e.hasAttribute("data-editor-save")){const t=r.map((t=>t.value.trim()));this.saveRow(t,this.data.row)}}))}saveRow(t,e){const s=e.map((t=>t.text??String(t.data)));if(t){let s=0;this.dt.data.data[this.data.rowIndex]=e.map(((e,i)=>{if(this.options.excludeColumns.includes(i)||this.dt.columns.settings[i].hidden)return e;const n=this.dt.columns.settings[i].type||this.dt.options.type,a=t[s++];let o;if("number"===n)o={data:parseFloat(a)};else if("boolean"===n)o=["","false","0"].includes(a)?{data:!1,text:"false",order:0}:{data:!0,text:"true",order:1};else if("html"===n)o={data:[{nodeName:"#text",data:a}],text:a,order:a};else if("string"===n)o={data:a};else if("date"===n){const t=this.dt.columns.settings[i].format||this.dt.options.format;o={data:a,order:F(String(a),t)}}else o={data:a};return o}))}const i=this.dt.data.data[this.data.rowIndex].map((t=>t.text??String(t.data)));this.data={},this.dt.update(!0),this.closeModal(),this.editing=!1,this.dt.emit("editable.save.row",i,s,e)}openModal(){this.modalDOM&&document.body.appendChild(this.modalDOM)}closeModal(){this.editing&&this.modalDOM&&(document.body.removeChild(this.modalDOM),this.modalDOM=this.editing=this.editingRow=this.editingCell=!1)}removeRow(t){if(!t||"TR"!==t.nodeName||this.editing)return;const e=parseInt(t.dataset.index,10);this.dt.rows.remove(e),this.closeMenu()}updateMenu(){const t=window.scrollX||window.pageXOffset,e=window.scrollY||window.pageYOffset;this.rect=this.wrapperDOM.getBoundingClientRect(),this.limits={x:window.innerWidth+t-this.rect.width,y:window.innerHeight+e-this.rect.height}}dismissMenu(t){const e=t.target;if(!(e instanceof Element)||this.wrapperDOM.contains(e))return;let s=!0;this.editing&&(s=!e.matches(`input.${this.options.classes.input}[type=text]`)),s&&this.closeMenu()}openMenu(){if(this.editing&&this.data&&this.editingCell){const t=this.modalDOM?this.modalDOM.querySelector(`input.${this.options.classes.input}[type=text]`):this.dt.wrapperDOM.querySelector(`input.${this.options.classes.input}[type=text]`);this.saveCell(t.value)}document.body.appendChild(this.containerDOM),this.menuOpen=!0,this.dt.emit("editable.context.open")}closeMenu(){this.menuOpen&&(this.menuOpen=!1,document.body.removeChild(this.containerDOM),this.dt.emit("editable.context.close"))}destroy(){this.dt.dom.removeEventListener(this.options.clickEvent,this.events.click),this.dt.dom.removeEventListener("contextmenu",this.events.context),document.removeEventListener("click",this.events.dismissMenu),document.removeEventListener("keydown",this.events.keydown),window.removeEventListener("resize",this.events.reset),window.removeEventListener("scroll",this.events.reset),document.body.contains(this.containerDOM)&&document.body.removeChild(this.containerDOM),this.options.inline&&(this.dt.options.rowRender=this.originalRowRender),this.initialized=!1}rowRender(t,e,s){if(!this.data||this.data.rowIndex!==s)return e;if(this.editingCell){e.childNodes[function(t,e){let s=t,i=0;for(;i{const o=a(i,this.dt.columns.settings),r=t[o];if(!this.options.excludeColumns.includes(o)){e.childNodes[i].childNodes=[{nodeName:"INPUT",attributes:{type:"text",value:n(r.text||String(r.data)||""),class:this.options.classes.input}}]}}));return e}}const tt={classes:{button:"datatable-column-filter-button",menu:"datatable-column-filter-menu",container:"datatable-column-filter-container",wrapper:"datatable-column-filter-wrapper"},labels:{button:"Filter columns within the table"},hiddenColumns:[]};class et{constructor(t,e={}){this.dt=t,this.options={...tt,...e}}init(){if(this.initialized)return;let t=this.dt.wrapperDOM.querySelector(`.${this.options.classes.button}`);if(!t){t=s("button",{class:this.options.classes.button,html:"▦"});const e=this.dt.wrapperDOM.querySelector(`.${this.dt.options.classes.search}`);e?e.appendChild(t):this.dt.wrapperDOM.appendChild(t),this.addedButtonDOM=!0}this.buttonDOM=t,this.containerDOM=s("div",{id:this.options.classes.container}),this.wrapperDOM=s("div",{class:this.options.classes.wrapper}),this.menuDOM=s("ul",{class:this.options.classes.menu,html:this.dt.data.headings.map(((t,e)=>{const s=this.dt.columns.settings[e];return this.options.hiddenColumns.includes(e)?"":`
    • \n \n \n
    • `})).join("")}),this.wrapperDOM.appendChild(this.menuDOM),this.containerDOM.appendChild(this.wrapperDOM),this._measureSpace(),this._bind(),this.initialized=!0}dismiss(){this.addedButtonDOM&&this.buttonDOM.parentElement&&this.buttonDOM.parentElement.removeChild(this.buttonDOM),document.removeEventListener("click",this.events.click)}_bind(){this.events={click:this._click.bind(this)},document.addEventListener("click",this.events.click)}_openMenu(){document.body.appendChild(this.containerDOM),this._measureSpace(),this.menuOpen=!0,this.dt.emit("columnFilter.menu.open")}_closeMenu(){this.menuOpen&&(this.menuOpen=!1,document.body.removeChild(this.containerDOM),this.dt.emit("columnFilter.menu.close"))}_measureSpace(){const t=window.scrollX||window.pageXOffset,e=window.scrollY||window.pageYOffset;this.rect=this.wrapperDOM.getBoundingClientRect(),this.limits={x:window.innerWidth+t-this.rect.width,y:window.innerHeight+e-this.rect.height}}_click(t){const e=t.target;if(e instanceof Element)if(this.event=t,this.buttonDOM.contains(e)){if(t.preventDefault(),this.menuOpen)return void this._closeMenu();this._openMenu();let e=t.pageX,s=t.pageY;e>this.limits.x&&(e-=this.rect.width),s>this.limits.y&&(s-=this.rect.height),this.wrapperDOM.style.top=`${s}px`,this.wrapperDOM.style.left=`${e}px`}else if(this.menuDOM.contains(e)){const t=e.closest(`.${this.options.classes.menu} > li`);if(!t)return;const s=t.querySelector("input[type=checkbox]");s.contains(e)||(s.checked=!s.checked);const i=Number(t.dataset.column);s.checked?this.dt.columns.show([i]):this.dt.columns.hide([i])}else this.menuOpen&&this._closeMenu()}}exports.DataTable=class{constructor(t,e={}){const s="string"==typeof t?document.querySelector(t):t;s instanceof HTMLTableElement?this.dom=s:(this.dom=document.createElement("table"),s.appendChild(this.dom));const i={...Q.diffDomOptions,...e.diffDomOptions},n={...Q.labels,...e.labels},a={...Q.classes,...e.classes};this.options={...Q,...e,diffDomOptions:i,labels:n,classes:a},this._initialInnerHTML=this.options.destroyable?this.dom.innerHTML:"",this.options.tabIndex?this.dom.tabIndex=this.options.tabIndex:this.options.rowNavigation&&-1===this.dom.tabIndex&&(this.dom.tabIndex=0),this._listeners={onResize:()=>this._onResize()},this._dd=new A(this.options.diffDomOptions||{}),this.initialized=!1,this._events={},this._currentPage=0,this.onFirstPage=!0,this.hasHeadings=!1,this.hasRows=!1,this._searchQueries=[],this.init()}init(){if(this.initialized||this.dom.classList.contains(this.options.classes.table))return!1;this._virtualDOM=O(this.dom,this.options.diffDomOptions||{}),this._tableAttributes={...this._virtualDOM.attributes},this._tableFooters=this._virtualDOM.childNodes.filter((t=>"TFOOT"===t.nodeName)),this._tableCaptions=this._virtualDOM.childNodes.filter((t=>"CAPTION"===t.nodeName)),void 0!==this.options.caption&&this._tableCaptions.push({nodeName:"CAPTION",childNodes:[{nodeName:"#text",data:this.options.caption}]}),this.rows=new J(this),this.columns=new W(this),this.data=U(this.options.data,this.dom,this.columns.settings,this.options.type,this.options.format),this._render(),setTimeout((()=>{this.emit("datatable.init"),this.initialized=!0}),10)}_render(){this.wrapperDOM=s("div",{class:`${this.options.classes.wrapper} ${this.options.classes.loading}`}),this.wrapperDOM.innerHTML=this.options.template(this.options,this.dom);const t=this.wrapperDOM.querySelector(`select.${this.options.classes.selector}`);t&&this.options.paging&&this.options.perPageSelect?this.options.perPageSelect.forEach((e=>{const[s,i]=Array.isArray(e)?[e[0],e[1]]:[String(e),e],n=i===this.options.perPage,a=new Option(s,String(i),n,n);t.appendChild(a)})):t&&t.parentElement.removeChild(t),this.containerDOM=this.wrapperDOM.querySelector(`.${this.options.classes.container}`),this._pagerDOMs=[],Array.from(this.wrapperDOM.querySelectorAll(`.${this.options.classes.pagination}`)).forEach((t=>{t instanceof HTMLElement&&(t.innerHTML=`
        `,this._pagerDOMs.push(t.firstElementChild))})),this._virtualPagerDOM={nodeName:"UL",attributes:{class:this.options.classes.paginationList}},this._label=this.wrapperDOM.querySelector(`.${this.options.classes.info}`),this.dom.parentElement.replaceChild(this.wrapperDOM,this.dom),this.containerDOM.appendChild(this.dom),this._rect=this.dom.getBoundingClientRect(),this._fixHeight(),this.options.header||this.wrapperDOM.classList.add("no-header"),this.options.footer||this.wrapperDOM.classList.add("no-footer"),this.options.sortable&&this.wrapperDOM.classList.add("sortable"),this.options.searchable&&this.wrapperDOM.classList.add("searchable"),this.options.fixedHeight&&this.wrapperDOM.classList.add("fixed-height"),this.options.fixedColumns&&this.wrapperDOM.classList.add("fixed-columns"),this._bindEvents(),this.columns._state.sort&&this.columns.sort(this.columns._state.sort.column,this.columns._state.sort.dir,!0),this.update(!0)}_renderTable(t={}){let e;e=(this.options.paging||this._searchQueries.length||this.columns._state.filters.length)&&this._currentPage&&this.pages.length&&!t.noPaging?this.pages[this._currentPage-1]:this.data.data.map(((t,e)=>({row:t,index:e})));let s=R(this._tableAttributes,this.data.headings,e,this.columns.settings,this.columns._state,this.rows.cursor,this.options,t,this._tableFooters,this._tableCaptions);if(this.options.tableRender){const t=this.options.tableRender(this.data,s,"main");t&&(s=t)}const i=this._dd.diff(this._virtualDOM,s);this._dd.apply(this.dom,i),this._virtualDOM=s}_renderPage(t=!1){this.hasRows&&this.totalPages?(this._currentPage>this.totalPages&&(this._currentPage=1),this._renderTable(),this.onFirstPage=1===this._currentPage,this.onLastPage=this._currentPage===this.lastPage):this.setMessage(this.options.labels.noRows);let e,s=0,i=0,n=0;if(this.totalPages&&(s=this._currentPage-1,i=s*this.options.perPage,n=i+this.pages[s].length,i+=1,e=this._searchQueries.length?this._searchData.length:this.data.data.length),this._label&&this.options.labels.info.length){const t=this.options.labels.info.replace("{start}",String(i)).replace("{end}",String(n)).replace("{page}",String(this._currentPage)).replace("{pages}",String(this.totalPages)).replace("{rows}",String(e));this._label.innerHTML=e?t:""}if(1==this._currentPage&&this._fixHeight(),this.options.rowNavigation&&this._currentPage&&(!this.rows.cursor||!this.pages[this._currentPage-1].find((t=>t.index===this.rows.cursor)))){const e=this.pages[this._currentPage-1];e.length&&(t?this.rows.setCursor(e[e.length-1].index):this.rows.setCursor(e[0].index))}}_renderPagers(){if(!this.options.paging)return;let t=Z(this.onFirstPage,this.onLastPage,this._currentPage,this.totalPages,this.options);if(this.options.pagerRender){const e=this.options.pagerRender([this.onFirstPage,this.onLastPage,this._currentPage,this.totalPages],t);e&&(t=e)}const e=this._dd.diff(this._virtualPagerDOM,t);this._pagerDOMs.forEach((t=>{this._dd.apply(t,e)})),this._virtualPagerDOM=t}_renderSeparateHeader(){const t=this.dom.parentElement;this.headerDOM||(this.headerDOM=document.createElement("div"),this._virtualHeaderDOM={nodeName:"DIV"}),t.parentElement.insertBefore(this.headerDOM,t);let e={nodeName:"TABLE",attributes:this._tableAttributes,childNodes:[{nodeName:"THEAD",childNodes:[P(this.data.headings,this.columns.settings,this.columns._state,this.options,{unhideHeader:!0})]}]};if(e.attributes.class=e.attributes.class?`${e.attributes.class} ${this.options.classes.table}`:this.options.classes.table,this.options.tableRender){const t=this.options.tableRender(this.data,e,"header");t&&(e=t)}const s={nodeName:"DIV",attributes:{class:this.options.classes.headercontainer},childNodes:[e]},i=this._dd.diff(this._virtualHeaderDOM,s);this._dd.apply(this.headerDOM,i),this._virtualHeaderDOM=s;const n=this.headerDOM.firstElementChild.clientWidth-this.dom.clientWidth;if(n){const t=structuredClone(this._virtualHeaderDOM);t.attributes.style=`padding-right: ${n}px;`;const e=this._dd.diff(this._virtualHeaderDOM,t);this._dd.apply(this.headerDOM,e),this._virtualHeaderDOM=t}t.scrollHeight>t.clientHeight&&(t.style.overflowY="scroll")}_bindEvents(){if(this.options.perPageSelect){const t=this.wrapperDOM.querySelector(`select.${this.options.classes.selector}`);t&&t instanceof HTMLSelectElement&&t.addEventListener("change",(()=>{this.options.perPage=parseInt(t.value,10),this.update(),this._fixHeight(),this.emit("datatable.perpage",this.options.perPage)}),!1)}this.options.searchable&&this.wrapperDOM.addEventListener("input",(t=>{const e=t.target;if(!(e instanceof HTMLInputElement&&e.matches(`.${this.options.classes.input}`)))return;t.preventDefault();const s=[];if(Array.from(this.wrapperDOM.querySelectorAll(`.${this.options.classes.input}`)).filter((t=>t.value.length)).forEach((t=>{const e=t.dataset.and||this.options.searchAnd,i=t.dataset.querySeparator||this.options.searchQuerySeparator?t.value.split(this.options.searchQuerySeparator):[t.value];e?i.forEach((e=>{t.dataset.columns?s.push({terms:[e],columns:JSON.parse(t.dataset.columns)}):s.push({terms:[e],columns:void 0})})):t.dataset.columns?s.push({terms:i,columns:JSON.parse(t.dataset.columns)}):s.push({terms:i,columns:void 0})})),1===s.length&&1===s[0].terms.length){const t=s[0];this.search(t.terms[0],t.columns)}else this.multiSearch(s)})),this.wrapperDOM.addEventListener("click",(t=>{const e=t.target.closest("a, button");if(e)if(e.hasAttribute("data-page"))this.page(parseInt(e.getAttribute("data-page"),10)),t.preventDefault();else if(e.classList.contains(this.options.classes.sorter)){const s=Array.from(e.parentElement.parentElement.children).indexOf(e.parentElement),i=a(s,this.columns.settings);this.columns.sort(i),t.preventDefault()}else if(e.classList.contains(this.options.classes.filter)){const s=Array.from(e.parentElement.parentElement.children).indexOf(e.parentElement),i=a(s,this.columns.settings);this.columns.filter(i),t.preventDefault()}}),!1),this.options.rowNavigation?(this.dom.addEventListener("keydown",(t=>{if("ArrowUp"===t.key){let e;t.preventDefault(),t.stopPropagation(),this.pages[this._currentPage-1].find((t=>t.index===this.rows.cursor||(e=t,!1))),e?this.rows.setCursor(e.index):this.onFirstPage||this.page(this._currentPage-1,!0)}else if("ArrowDown"===t.key){let e;t.preventDefault(),t.stopPropagation();const s=this.pages[this._currentPage-1].find((t=>!!e||(t.index===this.rows.cursor&&(e=!0),!1)));s?this.rows.setCursor(s.index):this.onLastPage||this.page(this._currentPage+1)}else["Enter"," "].includes(t.key)&&this.emit("datatable.selectrow",this.rows.cursor,t)})),this.dom.addEventListener("mousedown",(t=>{const e=t.target;if(e instanceof Element&&this.dom.matches(":focus")){const s=Array.from(this.dom.querySelectorAll("body tr")).find((t=>t.contains(e)));s&&s instanceof HTMLElement&&this.emit("datatable.selectrow",parseInt(s.dataset.index,10),t)}}))):this.dom.addEventListener("mousedown",(t=>{const e=t.target;if(!(e instanceof Element))return;const s=Array.from(this.dom.querySelectorAll("body tr")).find((t=>t.contains(e)));s&&s instanceof HTMLElement&&this.emit("datatable.selectrow",parseInt(s.dataset.index,10),t)})),window.addEventListener("resize",this._listeners.onResize)}_onResize(){this._rect=this.containerDOM.getBoundingClientRect(),this._rect.width&&this.update(!0)}destroy(){this.options.destroyable&&(this.dom.innerHTML=this._initialInnerHTML,this.dom.classList.remove(this.options.classes.table),this.wrapperDOM.parentElement&&this.wrapperDOM.parentElement.replaceChild(this.dom,this.wrapperDOM),this.initialized=!1,window.removeEventListener("resize",this._listeners.onResize))}update(t=!1){t&&(this.columns._measureWidths(),this.hasRows=Boolean(this.data.data.length),this.hasHeadings=Boolean(this.data.headings.length)),this.wrapperDOM.classList.remove(this.options.classes.empty),this._paginate(),this._renderPage(),this._renderPagers(),this.options.scrollY.length&&this._renderSeparateHeader(),this.emit("datatable.update")}_paginate(){let t=this.data.data.map(((t,e)=>({row:t,index:e})));return this._searchQueries.length&&(t=[],this._searchData.forEach((e=>t.push({index:e,row:this.data.data[e]})))),this.columns._state.filters.length&&this.columns._state.filters.forEach(((e,s)=>{e&&(t=t.filter((t=>"function"==typeof e?e(t.row[s].data):(t.row[s].text??t.row[s].data)===e)))})),this.options.paging&&this.options.perPage>0?this.pages=t.map(((e,s)=>s%this.options.perPage==0?t.slice(s,s+this.options.perPage):null)).filter((t=>t)):this.pages=[t],this.totalPages=this.lastPage=this.pages.length,this._currentPage||(this._currentPage=1),this.totalPages}_fixHeight(){this.options.fixedHeight&&(this.containerDOM.style.height=null,this._rect=this.containerDOM.getBoundingClientRect(),this.containerDOM.style.height=`${this._rect.height}px`)}search(t,e=void 0){if(!t.length)return this._currentPage=1,this._searchQueries=[],this._searchData=[],this.update(),this.emit("datatable.search","",[]),this.wrapperDOM.classList.remove("search-results"),!1;this.multiSearch([{terms:[t],columns:e||void 0}]),this.emit("datatable.search",t,this._searchData)}multiSearch(t){if(!this.hasRows)return!1;this._currentPage=1,this._searchData=[];const e=t.map((t=>({columns:t.columns,terms:t.terms.map((t=>t.trim())).filter((t=>t))}))).filter((t=>t.terms.length));if(this._searchQueries=e,!e.length)return this.update(),this.emit("datatable.multisearch",e,this._searchData),this.wrapperDOM.classList.remove("search-results"),!1;const s=e.map((t=>this.columns.settings.map(((e,s)=>{if(e.hidden||!e.searchable||t.columns&&!t.columns.includes(s))return!1;let i=t.terms;const n=e.sensitivity||this.options.sensitivity;["base","accent"].includes(n)&&(i=i.map((t=>t.toLowerCase()))),["base","case"].includes(n)&&(i=i.map((t=>t.normalize("NFD").replace(/\p{Diacritic}/gu,""))));return(e.ignorePunctuation??this.options.ignorePunctuation)&&(i=i.map((t=>t.replace(/[.,/#!$%^&*;:{}=-_`~()]/g,"")))),i}))));this.data.data.forEach(((t,e)=>{const i=t.map(((t,e)=>{let s=(t.text||String(t.data)).trim();const i=this.columns.settings[e];if(s.length){const t=i.sensitivity||this.options.sensitivity;["base","accent"].includes(t)&&(s=s.toLowerCase()),["base","case"].includes(t)&&(s=s.normalize("NFD").replace(/\p{Diacritic}/gu,""));(i.ignorePunctuation??this.options.ignorePunctuation)&&(s=s.replace(/[.,/#!$%^&*;:{}=-_`~()]/g,""))}const n=i.searchItemSeparator||this.options.searchItemSeparator;return n?s.split(n):[s]}));s.every((t=>t.find(((t,e)=>!!t&&t.find((t=>i[e].find((e=>e.includes(t)))))))))&&this._searchData.push(e)})),this.wrapperDOM.classList.add("search-results"),this._searchData.length?this.update():(this.wrapperDOM.classList.remove("search-results"),this.setMessage(this.options.labels.noResults)),this.emit("datatable.multisearch",e,this._searchData)}page(t,e=!1){return t!==this._currentPage&&(isNaN(t)||(this._currentPage=t),!(t>this.pages.length||t<0)&&(this._renderPage(e),this._renderPagers(),void this.emit("datatable.page",t)))}insert(e){let s=[];if(Array.isArray(e)){const t=this.data.headings.map((t=>t.text??String(t.data)));e.forEach(((e,i)=>{const n=[];Object.entries(e).forEach((([e,s])=>{const a=t.indexOf(e);a>-1?n[a]=B(s,this.columns.settings[a]):this.hasHeadings||this.hasRows||0!==i||(n[t.length]=B(s,this.columns.settings[t.length]),t.push(e),this.data.headings.push(z(e)))})),s.push(n)}))}else t(e)&&(!e.headings||this.hasHeadings||this.hasRows?e.data&&Array.isArray(e.data)&&(s=e.data.map((t=>t.map(((t,e)=>B(t,this.columns.settings[e])))))):this.data=U(e,void 0,this.columns.settings,this.options.type,this.options.format));s.length&&s.forEach((t=>this.data.data.push(t))),this.hasHeadings=Boolean(this.data.headings.length),this.columns._state.sort&&this.columns.sort(this.columns._state.sort.column,this.columns._state.sort.dir,!0),this.update(!0)}refresh(){this.options.searchable&&(Array.from(this.wrapperDOM.querySelectorAll(`.${this.options.classes.input}`)).forEach((t=>{t.value=""})),this._searchQueries=[]),this._currentPage=1,this.onFirstPage=!0,this.update(!0),this.emit("datatable.refresh")}print(){const t=s("table");let e=R(this._tableAttributes,this.data.headings,this.data.data.map(((t,e)=>({row:t,index:e}))),this.columns.settings,this.columns._state,!1,this.options,{noColumnWidths:!0,unhideHeader:!0},this._tableFooters,this._tableCaptions);if(this.options.tableRender){const t=this.options.tableRender(this.data,e,"print");t&&(e=t)}const i=this._dd.diff({nodeName:"TABLE"},e);this._dd.apply(t,i);const n=window.open();n.document.body.appendChild(t),n.print()}setMessage(t){const e=this.data.headings.filter(((t,e)=>!this.columns.settings[e]?.hidden)).length||1;this.wrapperDOM.classList.add(this.options.classes.empty),this._label&&(this._label.innerHTML=""),this.totalPages=0,this._renderPagers();let s={nodeName:"TABLE",attributes:this._tableAttributes,childNodes:[{nodeName:"THEAD",childNodes:[P(this.data.headings,this.columns.settings,this.columns._state,this.options,{})]},{nodeName:"TBODY",childNodes:[{nodeName:"TR",childNodes:[{nodeName:"TD",attributes:{class:this.options.classes.empty,colspan:String(e)},childNodes:[{nodeName:"#text",data:t}]}]}]}]};if(s.attributes.class=s.attributes.class?`${s.attributes.class} ${this.options.classes.table}`:this.options.classes.table,this.options.tableRender){const t=this.options.tableRender(this.data,s,"message");t&&(s=t)}const i=this._dd.diff(this._virtualDOM,s);this._dd.apply(this.dom,i),this._virtualDOM=s}on(t,e){this._events[t]=this._events[t]||[],this._events[t].push(e)}off(t,e){t in this._events!=!1&&this._events[t].splice(this._events[t].indexOf(e),1)}emit(t,...e){if(t in this._events!=!1)for(let s=0;ss.init())),s},exports.convertCSV=function(e){let s;if(!t(e))return!1;const i={lineDelimiter:"\n",columnDelimiter:",",removeDoubleQuotes:!1,...e};if(i.data.length){s={data:[]};const t=i.data.split(i.lineDelimiter);if(t.length&&(i.headings&&(s.headings=t[0].split(i.columnDelimiter),i.removeDoubleQuotes&&(s.headings=s.headings.map((t=>t.trim().replace(/(^"|"$)/g,"")))),t.shift()),t.forEach(((t,e)=>{s.data[e]=[];const n=t.split(i.columnDelimiter);n.length&&n.forEach((t=>{i.removeDoubleQuotes&&(t=t.trim().replace(/(^"|"$)/g,"")),s.data[e].push(t)}))}))),s)return s}return!1},exports.convertJSON=function(s){let i;if(!t(s))return!1;const n={data:"",...s};if(n.data.length||t(n.data)){const t=!!e(n.data)&&JSON.parse(n.data);if(t?(i={headings:[],data:[]},t.forEach(((t,e)=>{i.data[e]=[],Object.entries(t).forEach((([t,s])=>{i.headings.includes(t)||i.headings.push(t),i.data[e].push(s)}))}))):console.warn("That's not valid JSON!"),i)return i}return!1},exports.createElement=s,exports.exportCSV=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],lineDelimiter:"\n",columnDelimiter:",",...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??t.data));if(a[0]=o,i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));if(a.length){let t="";if(a.forEach((e=>{e.forEach((e=>{"string"==typeof e&&(e=(e=(e=(e=(e=e.trim()).replace(/\s{2,}/g," ")).replace(/\n/g," ")).replace(/"/g,'""')).replace(/#/g,"%23")).includes(",")&&(e=`"${e}"`),t+=e+i.columnDelimiter})),t=t.trim().substring(0,t.length-1),t+=i.lineDelimiter})),t=t.trim().substring(0,t.length-1),i.download){const e=document.createElement("a");e.href=encodeURI(`data:text/csv;charset=utf-8,${t}`),e.download=`${i.filename||"datatable_export"}.csv`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}return t}return!1},exports.exportJSON=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],replacer:null,space:4,...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];if(i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.data)))));const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??String(t.data)));if(a.length){const t=[];a.forEach(((e,s)=>{t[s]=t[s]||{},e.forEach(((e,i)=>{t[s][o[i]]=e}))}));const e=JSON.stringify(t,i.replacer,i.space);if(i.download){const t=new Blob([e],{type:"data:application/json;charset=utf-8"}),s=URL.createObjectURL(t),n=document.createElement("a");n.href=s,n.download=`${i.filename||"datatable_export"}.json`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(s)}return e}return!1},exports.exportSQL=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],tableName:"myTable",...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];if(i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.text??t.data)))));const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??String(t.data)));if(a.length){let t=`INSERT INTO \`${i.tableName}\` (`;if(o.forEach((e=>{t+=`\`${e}\`,`})),t=t.trim().substring(0,t.length-1),t+=") VALUES ",a.forEach((e=>{t+="(",e.forEach((e=>{t+="string"==typeof e?`"${e}",`:`${e},`})),t=t.trim().substring(0,t.length-1),t+="),"})),t=t.trim().substring(0,t.length-1),t+=";",i.download&&(t=`data:application/sql;charset=utf-8,${t}`),i.download){const e=document.createElement("a");e.href=encodeURI(t),e.download=`${i.filename||"datatable_export"}.sql`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}return t}return!1},exports.exportTXT=function(e,s={}){if(!e.hasHeadings&&!e.hasRows)return!1;if(!t(s))return!1;const i={download:!0,skipColumn:[],lineDelimiter:"\n",columnDelimiter:",",...s},n=t=>!i.skipColumn.includes(t)&&!e.columns.settings[t]?.hidden;let a=[];const o=e.data.headings.filter(((t,e)=>n(e))).map((t=>t.text??t.data));if(a[0]=o,i.selection)if(Array.isArray(i.selection))for(let t=0;tt.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.pages[i.selection-1].map((t=>t.row.filter(((t,e)=>n(e))).map((t=>t.data)))));else a=a.concat(e.data.data.map((t=>t.filter(((t,e)=>n(e))).map((t=>t.data)))));if(a.length){let t="";if(a.forEach((e=>{e.forEach((e=>{"string"==typeof e&&(e=(e=(e=(e=(e=e.trim()).replace(/\s{2,}/g," ")).replace(/\n/g," ")).replace(/"/g,'""')).replace(/#/g,"%23")).includes(",")&&(e=`"${e}"`),t+=e+i.columnDelimiter})),t=t.trim().substring(0,t.length-1),t+=i.lineDelimiter})),t=t.trim().substring(0,t.length-1),i.download&&(t=`data:text/csv;charset=utf-8,${t}`),i.download){const e=document.createElement("a");e.href=encodeURI(t),e.download=`${i.filename||"datatable_export"}.txt`,document.body.appendChild(e),e.click(),document.body.removeChild(e)}return t}return!1},exports.isJson=e,exports.isObject=t,exports.makeEditable=function(t,e={}){const s=new K(t,e);return t.initialized?s.init():t.on("datatable.init",(()=>s.init())),s}; }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) diff --git a/docs/demos/index.html b/docs/demos/index.html index 3083c17b..9e9cdc46 100644 --- a/docs/demos/index.html +++ b/docs/demos/index.html @@ -22,7 +22,7 @@

        Demos

        Datetime sorting Init-destroy-import-export Add 1000 rows - Add-1000-rows-without-conversion (faster) + Add 1000 rows without conversion (faster) Filters Export Updating @@ -37,6 +37,7 @@

        Demos

        SVGs AND Search Column filter button + Custom footer diff --git a/docs/documentation/Options.md b/docs/documentation/Options.md index 49dd8b73..191718e1 100644 --- a/docs/documentation/Options.md +++ b/docs/documentation/Options.md @@ -15,6 +15,7 @@ let dataTable = new DataTable(myTable, options); * [type](columns#type) * [format](columns#format) ### Appearance +* [caption](caption) * [classes](classes) * [columns](columns) * [fixedColumns](fixedColumns) diff --git a/docs/documentation/caption.md b/docs/documentation/caption.md new file mode 100644 index 00000000..a0e276a9 --- /dev/null +++ b/docs/documentation/caption.md @@ -0,0 +1,6 @@ +### `caption` +#### Type: `string` +#### Default: `undefined` + +Display a table caption with [](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption). No caption +is displayed by default. diff --git a/docs/documentation/columns.md b/docs/documentation/columns.md index dfd303d2..86a48e6c 100644 --- a/docs/documentation/columns.md +++ b/docs/documentation/columns.md @@ -1,3 +1,4 @@ +### `columns` #### Type: `array` #### Default: `undefined` diff --git a/docs/documentation/ellipsisText.md b/docs/documentation/ellipsisText.md index 8c751502..113d6abb 100644 --- a/docs/documentation/ellipsisText.md +++ b/docs/documentation/ellipsisText.md @@ -1,4 +1,4 @@ -### `firstText` +### `ellipsisText` #### Type: `string` #### Default: `'…'` diff --git a/docs/documentation/footer.md b/docs/documentation/footer.md index f50dc20b..f9e44023 100644 --- a/docs/documentation/footer.md +++ b/docs/documentation/footer.md @@ -1,5 +1,5 @@ ### `footer` -#### Default: `false` #### Type: `boolean` +#### Default: `false` Enable or disable the table footer. \ No newline at end of file diff --git a/docs/documentation/header.md b/docs/documentation/header.md index 6ac89a59..17eea7a2 100644 --- a/docs/documentation/header.md +++ b/docs/documentation/header.md @@ -1,5 +1,5 @@ ### `header` -#### Default: `true` #### Type: `boolean` +#### Default: `true` Enable or disable the table header. \ No newline at end of file diff --git a/docs/documentation/hiddenHeader.md b/docs/documentation/hiddenHeader.md index 79296b35..91a72d6a 100644 --- a/docs/documentation/hiddenHeader.md +++ b/docs/documentation/hiddenHeader.md @@ -1,5 +1,5 @@ ### `hiddenHeader` -#### Default: `false` #### Type: `boolean` +#### Default: `false` Whether to hide the table header. \ No newline at end of file diff --git a/docs/documentation/pagerRender.md b/docs/documentation/pagerRender.md index fb6028e1..4512a58f 100644 --- a/docs/documentation/pagerRender.md +++ b/docs/documentation/pagerRender.md @@ -1,6 +1,6 @@ -### `rowRender` -#### Default: `false` +### `pagerRender` #### Type: `boolean` \ `function(data, ul)` +#### Default: `false` If specified, declares a callback to customise the rendering of all pagers. The function can take 2 parameters: diff --git a/src/config.ts b/src/config.ts index b6ea3637..c009caf4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -47,6 +47,7 @@ export const defaultConfig: DataTableConfiguration = { footer: false, header: true, hiddenHeader: false, + caption: undefined, rowNavigation: false, tabIndex: false, diff --git a/src/datatable.ts b/src/datatable.ts index 4d446700..0b3a9add 100644 --- a/src/datatable.ts +++ b/src/datatable.ts @@ -12,6 +12,7 @@ import { inputCellType, elementNodeType, renderOptions, + rowType, TableDataType } from "./types" import {DiffDOM, nodeToObj} from "diff-dom" @@ -66,7 +67,7 @@ export class DataTable { _virtualPagerDOM: elementNodeType - pages: {row: cellType[], index: number}[][] + pages: rowType[][] _rect: {width: number, height: number} @@ -76,7 +77,11 @@ export class DataTable { _searchQueries: {terms: string[], columns: (number[] | undefined)}[] - _tableAttributes: { [key: string]: string} + _tableAttributes: {[key: string]: string} + + _tableFooters: elementNodeType[] + + _tableCaptions: elementNodeType[] totalPages: number @@ -88,7 +93,6 @@ export class DataTable { constructor(table: HTMLTableElement | string, options: DataTableOptions = {}) { - const dom = typeof table === "string" ? document.querySelector(table) : table @@ -161,6 +165,19 @@ export class DataTable { this._virtualDOM = nodeToObj(this.dom, this.options.diffDomOptions || {}) this._tableAttributes = {...this._virtualDOM.attributes} + this._tableFooters = this._virtualDOM.childNodes.filter(node => node.nodeName === "TFOOT") + this._tableCaptions = this._virtualDOM.childNodes.filter(node => node.nodeName === "CAPTION") + if (this.options.caption !== undefined) { + this._tableCaptions.push({ + nodeName: "CAPTION", + childNodes: [ + { + nodeName: "#text", + data: this.options.caption + } + ] + }) + } this.rows = new Rows(this) this.columns = new Columns(this) @@ -234,10 +251,8 @@ export class DataTable { // Store the table dimensions this._rect = this.dom.getBoundingClientRect() - // // Fix height + // Fix height this._fixHeight() - // - // Class names if (!this.options.header) { @@ -273,21 +288,27 @@ export class DataTable { this.update(true) } - _renderTable(renderOptions: renderOptions ={}) { + _renderTable(renderOptions: renderOptions = {}) { + let rows: rowType[] + const isPaged = (this.options.paging || this._searchQueries.length || this.columns._state.filters.length) && this._currentPage && this.pages.length && !renderOptions.noPaging + if (isPaged) { + rows = this.pages[this._currentPage - 1] + } else { + rows = this.data.data.map((row, index) => ({row, + index})) + } + let newVirtualDOM = dataToVirtualDOM( this._tableAttributes, this.data.headings, - (this.options.paging || this._searchQueries.length || this.columns._state.filters.length) && this._currentPage && this.pages.length && !renderOptions.noPaging ? - this.pages[this._currentPage - 1] : - this.data.data.map((row, index) => ({ - row, - index - })), + rows, this.columns.settings, this.columns._state, this.rows.cursor, this.options, - renderOptions + renderOptions, + this._tableFooters, + this._tableCaptions ) if (this.options.tableRender) { @@ -686,7 +707,7 @@ export class DataTable { } _paginate() { - let rows = this.data.data.map((row, index) => ({ + let rows: rowType[] = this.data.data.map((row, index) => ({ row, index })) @@ -714,7 +735,7 @@ export class DataTable { if (this.options.paging && this.options.perPage > 0) { // Check for hidden columns this.pages = rows - .map((row: {row: cellType[], index: number}, i: number) => i % this.options.perPage === 0 ? rows.slice(i, i + this.options.perPage) : null) + .map((_row, i: number) => i % this.options.perPage === 0 ? rows.slice(i, i + this.options.perPage) : null) .filter((page: {row: cellType[], index: number}[]) => page) } else { this.pages = [rows] @@ -957,7 +978,9 @@ export class DataTable { { noColumnWidths: true, unhideHeader: true - } + }, + this._tableFooters, + this._tableCaptions ) if (this.options.tableRender) { diff --git a/src/read_data.ts b/src/read_data.ts index 69b17ce2..4e722aca 100644 --- a/src/read_data.ts +++ b/src/read_data.ts @@ -83,8 +83,8 @@ const readDOMDataCell = (cell: HTMLElement, columnSettings : columnSettingsType) const data = !["false", "0", "null", "undefined"].includes(cell.innerText.toLowerCase().trim()) cellData = { data, - order: data ? 1 : 0, - text: data ? "1" : "0" + text: data ? "1" : "0", + order: data ? 1 : 0 } break } @@ -99,6 +99,14 @@ const readDOMDataCell = (cell: HTMLElement, columnSettings : columnSettingsType) } } + // Save cell attributes to reference when rendering + cellData.attributes = {} + if (cell.attributes) { + for (const attr of cell.attributes) { + cellData.attributes[attr.name] = attr.value + } + } + return cellData } @@ -136,7 +144,7 @@ export const readHeaderCell = (cell: inputHeaderCellType) : headerCellType => { export const readDOMHeaderCell = (cell: HTMLElement) : headerCellType => { const node = nodeToObj(cell, {valueDiffing: false}) - let cellData + let cellData: headerCellType if (node.childNodes && (node.childNodes.length !== 1 || node.childNodes[0].nodeName !== "#text")) { cellData = { data: node.childNodes, @@ -149,6 +157,10 @@ export const readDOMHeaderCell = (cell: HTMLElement) : headerCellType => { type: "string" } } + + // Save header cell attributes to reference when rendering + cellData.attributes = node.attributes + return cellData } diff --git a/src/types.ts b/src/types.ts index 9f043d64..eaeb19f4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -24,6 +24,7 @@ interface cellType { data: string | number | boolean | elementNodeType[] | object; text?: string; order?: string | number; + attributes?: { [key: string]: string }; } type inputCellType = cellType | string | number | boolean; @@ -32,6 +33,7 @@ interface headerCellType { data: string | number | boolean | elementNodeType[] | object; type?: ("html" | "string"); text?: string; + attributes?: { [key: string]: string }; } type inputHeaderCellType = headerCellType | string | number | boolean; @@ -49,6 +51,11 @@ interface TableDataType{ type renderType = ((cellData: (string | number | boolean | object | elementNodeType[]), td: object, rowIndex: number, cellIndex: number) => elementNodeType | string | void); +interface rowType { + row: cellType[]; + index: number; +} + export type DeepPartial = T extends Function ? T : (T extends object ? { [P in keyof T]?: DeepPartial; } : T); // eslint-disable-line @typescript-eslint/ban-types // Source https://gist.github.com/navix/6c25c15e0a2d3cd0e5bce999e0086fc9 @@ -210,6 +217,13 @@ type tableRenderType = ((data: object, table: elementNodeType, type: string) => interface DataTableConfiguration { + /** + * Display a table caption with [](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption). + * No caption is displayed by default. + * + * Docs: https://fiduswriter.github.io/simple-datatables/documentation/caption + */ + caption: string | undefined; classes: ClassConfiguration; columns: ColumnOption[]; /**Controls various aspects of individual or groups of columns. Should be an array of objects with the following properties: @@ -294,13 +308,13 @@ interface DataTableConfiguration { info: "Showing {start} to {end} of {rows} entries", } * - * Docs : https://fiduswriter.github.io/simple-datatables/documentation/labels + * Docs: https://fiduswriter.github.io/simple-datatables/documentation/labels */ template: (DataTableConfiguration, HTMLTableElement) => string; /** * Allows for custom arranging of the DOM elements in the top and bottom containers. There are for 4 variables you can utilize: * - * Docs :https://fiduswriter.github.io/simple-datatables/documentation/layout + * Docs: https://fiduswriter.github.io/simple-datatables/documentation/layout */ lastText: string; /** @@ -472,6 +486,7 @@ export { renderOptions, renderType, rowRenderType, + rowType, columnSettingsType, TableDataType, textNodeType diff --git a/src/virtual_dom.ts b/src/virtual_dom.ts index 5f553ea3..2fff27f3 100644 --- a/src/virtual_dom.ts +++ b/src/virtual_dom.ts @@ -1,6 +1,6 @@ import {stringToObj} from "diff-dom" -import {cellType, columnsStateType, columnSettingsType, DataTableOptions, headerCellType, elementNodeType, textNodeType, renderOptions} from "./types" +import {cellType, columnsStateType, columnSettingsType, DataTableOptions, headerCellType, elementNodeType, textNodeType, renderOptions, rowType} from "./types" export const headingsToVirtualHeaderRowDOM = ( @@ -33,7 +33,7 @@ export const headingsToVirtualHeaderRowDOM = ( if (column.hidden) { return } - const attributes : { [key: string]: string} = {} + const attributes : { [key: string]: string } = heading.attributes ? {...heading.attributes} : {} if (column.sortable && sortable && (!scrollY.length || unhideHeader)) { if (column.filter) { attributes["data-filterable"] = "true" @@ -41,8 +41,9 @@ export const headingsToVirtualHeaderRowDOM = ( attributes["data-sortable"] = "true" } } + if (column.headerClass) { - attributes.class = column.headerClass + attributes.class = attributes.class ? `${attributes.class} ${column.headerClass}` : column.headerClass } if (columnsState.sort && columnsState.sort.column === index) { const directionClass = columnsState.sort.dir === "asc" ? classes.ascending : classes.descending @@ -51,16 +52,14 @@ export const headingsToVirtualHeaderRowDOM = ( } else if (columnsState.filters[index]) { attributes.class = attributes.class ? `${attributes.class} ${classes.filterActive}` : classes.filterActive } - let style = "" + if (columnsState.widths[index] && !noColumnWidths) { - style += `width: ${columnsState.widths[index]}%;` + const style = `width: ${columnsState.widths[index]}%;` + attributes.style = attributes.style ? `${attributes.style} ${style}` : style } if (scrollY.length && !unhideHeader) { - style += "padding-bottom: 0;padding-top: 0;border: 0;" - } - - if (style.length) { - attributes.style = style + const style = "padding-bottom: 0;padding-top: 0;border: 0;" + attributes.style = attributes.style ? `${attributes.style} ${style}` : style } const headerNodes : elementNodeType[] = heading.type === "html" ? @@ -77,8 +76,10 @@ export const headingsToVirtualHeaderRowDOM = ( childNodes: ((hiddenHeader || scrollY.length) && !unhideHeader) ? [ - {nodeName: "#text", - data: ""} + { + nodeName: "#text", + data: "" + } ] : !column.sortable || !sortable ? headerNodes : @@ -96,7 +97,7 @@ export const headingsToVirtualHeaderRowDOM = ( ).filter((column: (elementNodeType | void)) => column) }) -export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, headings: headerCellType[], rows: {row: cellType[], index: number}[], columnSettings: columnSettingsType[], columnsState: columnsStateType, rowCursor: (number | false), { +export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, headings: headerCellType[], rows: rowType[], columnSettings: columnSettingsType[], columnsState: columnsStateType, rowCursor: (number | false), { classes, hiddenHeader, header, @@ -111,7 +112,7 @@ export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, head noColumnWidths, unhideHeader, renderHeader -}: renderOptions) => { +}: renderOptions, footers: elementNodeType[], captions: elementNodeType[]) => { const table: elementNodeType = { nodeName: "TABLE", attributes: {...tableAttributes}, @@ -119,10 +120,7 @@ export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, head { nodeName: "TBODY", childNodes: rows.map( - ({ - row, - index - }: {row: cellType[], index: number}) => { + ({row, index}) => { const tr: elementNodeType = { nodeName: "TR", attributes: { @@ -139,30 +137,31 @@ export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, head if (column.hidden) { return } - const td : elementNodeType = column.type === "html" ? - { - nodeName: "TD", - childNodes: cell.data - } as elementNodeType: - { - nodeName: "TD", - childNodes: [ + const td: elementNodeType = { + nodeName: "TD", + attributes: cell.attributes ? {...cell.attributes} : {}, + childNodes: column.type === "html" ? + cell.data : + [ { nodeName: "#text", data: cell.text ?? String(cell.data) } ] - } as elementNodeType + } as elementNodeType if (!header && !footer && columnsState.widths[cIndex] && !noColumnWidths) { - td.attributes = { - style: `width: ${columnsState.widths[cIndex]}%;` + if (!td.attributes.style) { + td.attributes.style = "" } + td.attributes.style += `width: ${columnsState.widths[cIndex]}%;` } if (column.cellClass) { - if (!td.attributes) { - td.attributes = {} + if (!td.attributes.class) { + td.attributes.class = "" + } else { + td.attributes.class += " " } - td.attributes.class = column.cellClass + td.attributes.class += column.cellClass } if (column.render) { const renderedCell : (string | elementNodeType | void) = column.render(cell.data, td, index, cIndex) @@ -187,7 +186,7 @@ export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, head } ).filter((column: (elementNodeType | void)) => column) } - if (index===rowCursor) { + if (index === rowCursor) { tr.attributes.class = classes.cursor } if (rowRender) { @@ -229,7 +228,9 @@ export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, head childNodes: [headerRow] } if ((scrollY.length || hiddenHeader) && !unhideHeader) { - thead.attributes = {style: "height: 0px;"} + thead.attributes = { + style: "height: 0px;" + } } table.childNodes.unshift(thead) } @@ -244,9 +245,11 @@ export const dataToVirtualDOM = (tableAttributes: { [key: string]: string}, head } table.childNodes.push(tfoot) } - } + footers.forEach(foot => table.childNodes.push(foot)) + captions.forEach(caption => table.childNodes.push(caption)) + if (tabIndex !== false) { table.attributes.tabindex = String(tabIndex) }