From de95405ab45c1f46362ec43cf4340ff8a079bd28 Mon Sep 17 00:00:00 2001 From: ThrawnCA Date: Tue, 14 Nov 2023 12:49:43 +1000 Subject: [PATCH] [QOLDEV-614] use QGOV CDN for grid scripts --- lib/premium.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/premium.js b/lib/premium.js index e167d515..d60037a2 100644 --- a/lib/premium.js +++ b/lib/premium.js @@ -158,7 +158,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var formiojs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! formiojs */ \"formiojs\");\n/* harmony import */ var formiojs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(formiojs__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _customFilters__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./customFilters */ \"./lib/components/DataTable/customFilters.js\");\n/* harmony import */ var _DataTable_form__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./DataTable.form */ \"./lib/components/DataTable/DataTable.form.js\");\n/* harmony import */ var _DataTableFormioIntegration__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./DataTableFormioIntegration */ \"./lib/components/DataTable/DataTableFormioIntegration.js\");\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __spreadArrays = (undefined && undefined.__spreadArrays) || function () {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n};\n\n\n\nvar EditGridComponent = formiojs__WEBPACK_IMPORTED_MODULE_0__.Components.components.editgrid;\n\n\nif (!Formio.cdn.baseUrl) {\n Formio.cdn.setBaseUrl('https://cdn.form.io');\n}\n;\nif ((Formio.version || '').includes('rc')) {\n Formio.cdn.setOverrideUrl('grid', 'https://cdn.test-form.io');\n Formio.cdn.setOverrideUrl('core', 'https://cdn.test-form.io');\n}\n;\nvar DataTableComponent = /** @class */ (function (_super) {\n __extends(DataTableComponent, _super);\n function DataTableComponent() {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n var _this = _super.apply(this, args) || this;\n _this.editRows = [];\n _this.savedRows = [];\n _this.isModalOpened = false;\n _this.columns = {};\n _this.initComponents = [];\n _this.type = 'datatable';\n _this.tabIndex = 0;\n var dataTableReadyPromise = new Formio.Promise(function (resolve, reject) {\n _this.dataTableReady = { resolve: resolve, reject: reject };\n });\n _this.dataTableReady.promise = dataTableReadyPromise;\n return _this;\n }\n DataTableComponent.schema = function () {\n var extend = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n extend[_i] = arguments[_i];\n }\n return EditGridComponent.schema.apply(EditGridComponent, __spreadArrays([{\n type: 'datatable',\n label: 'Data Table',\n key: 'dataTable',\n }], extend));\n };\n Object.defineProperty(DataTableComponent, \"builderInfo\", {\n get: function () {\n return {\n title: 'Data Table',\n group: 'premium',\n icon: 'table',\n weight: 115,\n documentation: '/userguide/forms/premium-components#data-table',\n schema: DataTableComponent.schema(),\n };\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(DataTableComponent.prototype, \"dataReady\", {\n get: function () {\n return this.dataTableReady.promise;\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.render = function (children) {\n var _this = this;\n var _a;\n if (this.builderMode) {\n return _super.prototype.render.call(this);\n }\n return _super.prototype.render.call(this, children || this.renderTemplate('datatable', {\n ref: {\n row: this.rowRef,\n addRow: this.addRowRef,\n saveRow: this.saveRowRef,\n cancelRow: this.cancelRowRef,\n },\n header: \"

\" + (((_a = this.editRows[0]) === null || _a === void 0 ? void 0 : _a.state) === 'new' ? 'Add row' : 'Edit row') + \"

\",\n rows: this.editRows.map(this.renderRow.bind(this)),\n openRows: this.editRows.map(function (row) { return _this.isOpen(row); }),\n errors: this.editRows.map(function (row) { return row.error; }),\n hasRemoveButtons: this.hasRemoveButtons(),\n }));\n };\n DataTableComponent.prototype.attach = function (element) {\n var _this = this;\n var dataTableReadyPromise = new Formio.Promise(function (resolve, reject) {\n _this.dataTableReady = { resolve: resolve, reject: reject };\n });\n this.dataTableReady.promise = dataTableReadyPromise;\n if (this.builderMode) {\n return _super.prototype.attach.call(this, element);\n }\n return _super.prototype.attach.call(this, element)\n .then(function () {\n var _a;\n _this.attachModal(_this.element);\n _this.loadRefs(_this.element, {\n tableContainer: 'single',\n });\n if (_this.formioGrid && _this.refs.tableContainer) {\n _this.formioGrid.setData(_this.dataValue);\n _this.formioGrid.init();\n _this.formioGrid.attach(_this.refs.tableContainer);\n if ((_a = _this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) {\n _this.dataTableReady.resolve();\n }\n return;\n }\n _this.loadFormioGrid()\n .then(function (FormioGrid) {\n _this.FormioCore.Template.framework = Formio.Templates.framework;\n return _this.initFormioGrid(FormioGrid)\n .then(function () {\n _this.dataTableReady.resolve();\n });\n });\n });\n };\n DataTableComponent.prototype.loadFormioGrid = function () {\n var _this = this;\n Formio.requireLibrary('formioGridCSS', 'FormioGrid', [\n { type: 'styles', src: Formio.cdn.grid + \"/formio.grid.min.css\" }\n ], false);\n return Formio.requireLibrary('FormioCore', 'FormioCore', Formio.cdn.core + \"/formio.core.min.js\", true)\n .then(function (FormioCore) {\n _this.FormioCore = FormioCore;\n return Formio.requireLibrary('FormioGrid', 'FormioGrid', Formio.cdn.grid + \"/formio.grid.min.js\", true);\n });\n };\n DataTableComponent.prototype.attachComponent = function (_a) {\n var _b;\n var _this = this;\n var key = _a.key, element = _a.element, value = _a.value, onChange = _a.onChange, row = _a.row, rowIndex = _a.rowIndex, index = _a.index, readOnly = _a.readOnly;\n var component = this.columns[key];\n if (component) {\n component = __assign(__assign({}, component), { hideLabel: true, hidden: false });\n var options = __assign(__assign({}, this.options), { onChange: function (flags, changed, modified) {\n if (!modified) {\n return;\n }\n onChange === null || onChange === void 0 ? void 0 : onChange(changed.value);\n if (_this.component.inlineEditing && !lodash__WEBPACK_IMPORTED_MODULE_1__.isUndefined(row)) {\n changed.instance.checkComponentValidity();\n }\n ;\n }, readOnly: readOnly });\n // Do not validate the component in the filtering field\n if (lodash__WEBPACK_IMPORTED_MODULE_1__.isUndefined(row)) {\n delete component.validate;\n if (component.type === 'phoneNumber') {\n component.inputMask = '';\n }\n ;\n // Creating radio fields for filtering Signature and File Components\n if (['signature', 'file', 'checkbox'].includes(component.type)) {\n component = {\n optionsLabelPosition: 'right',\n values: [\n {\n label: 'Yes',\n value: component.type === 'signature' ? '/./i' : true\n },\n {\n label: 'No',\n value: component.type === 'signature' ? '^(?!.)*$/i' : false\n }\n ],\n dataType: 'boolean',\n key: component.key,\n type: 'radio',\n hideLabel: true,\n input: true\n };\n }\n }\n var comp_1 = this.createComponent(component, options, (_b = {}, _b[key] = value, _b), false, true);\n comp_1.rowIndex = index !== null && index !== void 0 ? index : comp_1.rowIndex;\n comp_1.data = row !== null && row !== void 0 ? row : comp_1.data;\n comp_1.build(element);\n return {\n component: comp_1,\n resetValue: function () {\n comp_1.resetValue();\n }\n };\n }\n return null;\n };\n DataTableComponent.prototype.customFilters = function (component) {\n return _customFilters__WEBPACK_IMPORTED_MODULE_2__.filterByComponentType[component === null || component === void 0 ? void 0 : component.type];\n };\n DataTableComponent.prototype.isSortable = function (component) {\n return !['button', 'htmlelement', 'content'].includes(component.type) && !component.disableSortingAndFiltering;\n };\n DataTableComponent.prototype.isFilterable = function (component) {\n return !['button', 'htmlelement', 'content', 'address', 'datatable', 'editgrid', 'password', 'tagpad', 'sketchpad', 'form', 'container', 'tree', 'datagrid', 'datamap'].includes(component.type) && !component.disableSortingAndFiltering;\n };\n Object.defineProperty(DataTableComponent.prototype, \"maxLength\", {\n get: function () {\n var _a, _b, _c;\n return (_c = (_b = (_a = this.component) === null || _a === void 0 ? void 0 : _a.validate) === null || _b === void 0 ? void 0 : _b.maxLength) !== null && _c !== void 0 ? _c : Infinity;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(DataTableComponent.prototype, \"minLength\", {\n get: function () {\n var _a, _b, _c;\n return (_c = (_b = (_a = this.component) === null || _a === void 0 ? void 0 : _a.validate) === null || _b === void 0 ? void 0 : _b.minLength) !== null && _c !== void 0 ? _c : 0;\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.isAttachable = function (type) {\n return this.component.inlineEditing || ['button', 'htmlelement', 'content'].includes(type);\n };\n Object.defineProperty(DataTableComponent.prototype, \"visibility\", {\n get: function () {\n var _a = this, dataValue = _a.dataValue, savedRows = _a.savedRows;\n if (!savedRows.length) {\n return lodash__WEBPACK_IMPORTED_MODULE_1__.mapValues(this.columns, function (val) {\n var _a;\n if (val.hidden && !val.hideColumnByDefault) {\n return false;\n }\n return (_a = !val.hideColumnByDefault) !== null && _a !== void 0 ? _a : true;\n });\n }\n return lodash__WEBPACK_IMPORTED_MODULE_1__.reduce(savedRows, function (vis, row) {\n lodash__WEBPACK_IMPORTED_MODULE_1__.each(row.components, function (comp) {\n var visible = true;\n var _a = comp.component, conditional = _a.conditional, logic = _a.logic;\n var isConditionalPurposeMatched = (conditional === null || conditional === void 0 ? void 0 : conditional.show) === vis[comp.key];\n var isLogicPurposeMatched = (logic === null || logic === void 0 ? void 0 : logic.length) && logic.some(function (_a) {\n var actions = _a.actions;\n return actions.length && actions.some(function (action) {\n var _a;\n if (((_a = action.property) === null || _a === void 0 ? void 0 : _a.value) === 'hidden') {\n var expectedVisibility = !action.state;\n return expectedVisibility === vis[comp.key];\n }\n return false;\n });\n });\n if (vis.hasOwnProperty(comp.key) && (isConditionalPurposeMatched || isLogicPurposeMatched)) {\n visible = vis[comp.key];\n }\n else if (!(logic === null || logic === void 0 ? void 0 : logic.length) || !comp.hasCondition()) {\n visible = comp.visible;\n }\n else if (comp.type === 'hidden' || comp.component.hideColumnByDefault) {\n visible = false;\n }\n else if (typeof comp.checkConditions === 'function') {\n visible = comp.checkConditions(dataValue, {}, row.data);\n }\n vis[comp.key] = visible;\n });\n return vis;\n }, {});\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.updateComponentsVisibility = function () {\n var _a;\n var _b = this, formioGrid = _b.formioGrid, visibility = _b.visibility;\n if ((_a = formioGrid === null || formioGrid === void 0 ? void 0 : formioGrid.component) === null || _a === void 0 ? void 0 : _a.components.length) {\n this.formioGrid.menu.emit('changeVisibility', this.formioGrid.component.components.map(function (comp) {\n var _a;\n return (__assign(__assign({}, comp), { show: (comp.key in visibility) ? visibility[comp.key] : (((_a = !comp.hideColumnByDefault) !== null && _a !== void 0 ? _a : true) && !comp.hidden) }));\n }));\n }\n };\n Object.defineProperty(DataTableComponent.prototype, \"fetchProvider\", {\n get: function () {\n var _this = this;\n var _a, _b, _c, _d;\n if ((_a = this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) {\n var Provider = formiojs__WEBPACK_IMPORTED_MODULE_0__.Providers.getProvider('fetch', ((_b = this.component.fetch) === null || _b === void 0 ? void 0 : _b.provider) || 'url');\n if (Provider) {\n return new Provider({\n headers: lodash__WEBPACK_IMPORTED_MODULE_1__.map(((_c = this.component.fetch) === null || _c === void 0 ? void 0 : _c.headers) || [], function (header) {\n header.value = _this.interpolate(header.value);\n return header;\n }),\n url: this.interpolate(this.component.fetch.url),\n addFormioToken: this.component.fetch && this.component.fetch.authenticate,\n ignoreCache: !this.component.allowCaching,\n method: 'GET'\n });\n }\n /* tslint:disable */\n console.warn((((_d = this.component.fetch) === null || _d === void 0 ? void 0 : _d.provider) || 'url') + \" fetch provider is not found.\");\n /* tslint:enable */\n return null;\n }\n return null;\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.initFormioGrid = function (FormioGrid) {\n var _this = this;\n var components = [];\n formiojs__WEBPACK_IMPORTED_MODULE_0__.Utils.eachComponent(this.component.components, function (comp) {\n var _a, _b;\n if (comp.tableView || ['htmlelement', 'content'].includes(comp.type)) {\n components.push(__assign(__assign({ type: 'datavalue', sortable: _this.isSortable(comp), show: comp.hidden && !((_a = _this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) ? _this.visibility[comp.key] : ((_b = !comp.hideColumnByDefault) !== null && _b !== void 0 ? _b : true), attach: _this.isAttachable(comp.type) ? function (_a) {\n var _b;\n var key = _a.key, element = _a.element, value = _a.value, onChange = _a.onChange, row = _a.row, rowIndex = _a.rowIndex, index = _a.index;\n onChange = onChange !== null && onChange !== void 0 ? onChange : (function (value) {\n _this.dataValue[index][key] = value;\n // onChange(value);\n });\n value = ((_b = _this.component.fetch) === null || _b === void 0 ? void 0 : _b.enableFetch) ? value : (value !== null && value !== void 0 ? value : _this.dataValue[index][key]);\n _this.attachComponent({\n key: key,\n element: element,\n value: value,\n onChange: onChange,\n row: row,\n rowIndex: rowIndex,\n index: index,\n readOnly: _this.options.readOnly || _this.component.disabled\n });\n } : null }, comp), { filterable: _this.isFilterable(comp) }));\n _this.columns[comp.key] = comp;\n }\n return ['datagrid', 'editgrid', 'datamap', 'datatable', 'tree', 'container'].includes(comp.type);\n }, true);\n components.sort(function (a, b) { var _a, _b; return ((_a = a.columnWeight) !== null && _a !== void 0 ? _a : 0) - ((_b = b.columnWeight) !== null && _b !== void 0 ? _b : 0); });\n var _a = this.component, sortable = _a.sortable, filterable = _a.filterable, disabled = _a.disabled, cellMaxWidth = _a.cellMaxWidth, clipCells = _a.clipCells, itemsPerPage = _a.itemsPerPage, _b = _a.showAddBtn, showAddBtn = _b === void 0 ? true : _b, _c = _a.showEditBtn, showEditBtn = _c === void 0 ? true : _c, _d = _a.showDeleteBtn, showDeleteBtn = _d === void 0 ? true : _d, showDeleteAllBtn = _a.showDeleteAllBtn, fetch = _a.fetch, _e = _a.isSubmitData, isSubmitData = _e === void 0 ? false : _e, hideLabel = _a.hideLabel;\n var _f = this.options, readOnly = _f.readOnly, _g = _f.pdf, pdf = _g === void 0 ? false : _g;\n this.initComponents = this.createRowComponents({}, 0);\n return FormioGrid.render(this.refs.tableContainer, {\n components: components,\n fetch: fetch,\n isSubmitData: isSubmitData,\n hideLabel: hideLabel,\n pagination: {\n itemsPerPage: itemsPerPage || 10,\n },\n cellMaxWidth: cellMaxWidth,\n clipCells: clipCells,\n showAddBtn: showAddBtn && (!this.maxLength || this.maxLength > this.dataValue.length),\n showEditBtn: showEditBtn,\n showDeleteBtn: showDeleteBtn && this.minLength < this.dataValue.length,\n showDeleteAllBtn: showDeleteAllBtn\n }, {\n sortable: sortable,\n filterable: filterable,\n readOnly: readOnly || disabled,\n actions: this.options.dataTableActions,\n fetchProvider: this.fetchProvider,\n hooks: {\n attachFilter: this.attachComponent.bind(this),\n format: function (key, value) { return _this.format(key, value); },\n filter: function (key) { return _this.customFilters(_this.columns[key]); },\n transformData: function (responseData) { return _this.transformFetchedData(responseData); },\n },\n pdf: pdf\n }, this.dataValue)\n .then(function (formioGrid) {\n var _a;\n _this.formioGrid = formioGrid;\n _this.formioGrid.on('rowAdd', function () {\n _this.emit('rowAdd', _this);\n _this.onAddRow();\n });\n _this.formioGrid.on('rowEdit', function (data, rowIndex, index) {\n _this.emit('rowEdit', data, rowIndex, index, _this);\n _this.onEditRow(data, rowIndex, index);\n });\n _this.formioGrid.on('rowDelete', function (data, rowIndex, index) {\n if (window.confirm('Are you sure you wish to delete the row?')) {\n _this.emit('rowDelete', data, rowIndex, index, _this);\n if (!lodash__WEBPACK_IMPORTED_MODULE_1__.isEqual(_this.dataValue[index], data)) {\n index = lodash__WEBPACK_IMPORTED_MODULE_1__.findIndex(_this.dataValue, data);\n }\n ;\n _this.dataValue.splice(index, 1);\n _this.savedRows.splice(index, 1);\n _this.setValue(_this.dataValue);\n }\n });\n _this.formioGrid.on('deleteAll', function () {\n if (window.confirm(_this.component.deleteAllConfirmationMessage)) {\n _this.emit('deleteAll', _this);\n _this.dataValue = _this.defaultValue;\n _this.setValue(_this.dataValue);\n }\n });\n _this.formioGrid.on('rowClick', function (row, rowIndex, index, event) {\n _this.emit('rowClick', row, rowIndex, index, _this);\n });\n _this.formioGrid.on('rowSelectChange', function (rows) {\n _this.emit('rowSelectChange', rows, _this);\n });\n (_a = _this.component.customHeaderElements) === null || _a === void 0 ? void 0 : _a.forEach(function (element) {\n _this.formioGrid.on(element.customBtnEvent, function () {\n _this.emit(element.customBtnEvent, _this);\n });\n });\n _this.formioGrid.on('page', function (currentPage, viewGrid) {\n var _a, _b;\n if (((_a = _this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) && ((_b = _this.component.fetch) === null || _b === void 0 ? void 0 : _b.url) && viewGrid && !_this.builderMode) {\n _this.setValue(viewGrid);\n _this.triggerChange();\n }\n _this.emit('page', currentPage, _this, viewGrid);\n });\n _this.formioGrid.on('changeItemsPerPage', function (itemsPerPage) {\n _this.emit('changeItemsPerPage', itemsPerPage);\n });\n });\n };\n DataTableComponent.prototype.transformFetchedData = function (responseData) {\n var transformFunction = formiojs__WEBPACK_IMPORTED_MODULE_0__.Utils._.get(this.component, 'fetch.mapFunction');\n if (!transformFunction) {\n return responseData;\n }\n var result = null;\n try {\n result = this.evaluate(transformFunction, { responseData: responseData }, 'value');\n }\n catch (e) {\n result = responseData;\n }\n return result;\n };\n DataTableComponent.prototype.createRowComponents = function (row, rowIndex) {\n var components = _super.prototype.createRowComponents.call(this, row, rowIndex);\n if (this.disabled) {\n components.forEach(function (component) {\n component.disabled = true;\n });\n }\n return components;\n };\n DataTableComponent.prototype.createComponent = function (component, options, data, before, fromAttach) {\n var comp = _super.prototype.createComponent.call(this, component, options, data, before);\n if (fromAttach) {\n var visibility = this.visibility;\n if (visibility.hasOwnProperty(component.key) && comp.visible !== visibility[component.key]) {\n comp.visible = visibility[component.key];\n }\n }\n comp.inDataTable = true;\n return comp;\n };\n DataTableComponent.prototype.getComponents = function (rowIndex) {\n var _a;\n this.savedRows = this.savedRows || [];\n return this.builderMode\n ? _super.prototype.getComponents.call(this)\n : lodash__WEBPACK_IMPORTED_MODULE_1__.isNumber(rowIndex)\n ? (((_a = this.savedRows[rowIndex]) === null || _a === void 0 ? void 0 : _a.components) || [])\n : this.savedRows.reduce(function (result, row) { return result.concat(row.components || []); }, []);\n };\n DataTableComponent.prototype.beforeFocus = function (component) {\n var rowIndex = this.savedRows.findIndex(function (row) { return row.components.find(function (c) { return component === c; }); });\n if (lodash__WEBPACK_IMPORTED_MODULE_1__.isNumber(rowIndex) && !this.builderMode) {\n this.onEditRow(this.dataValue[rowIndex], rowIndex, rowIndex);\n }\n };\n DataTableComponent.prototype.onAddRow = function () {\n if (this.options.readOnly) {\n return;\n }\n var dataObj = {};\n this.editRows = [\n {\n components: this.createRowComponents(dataObj, 0),\n data: dataObj,\n state: 'new',\n index: this.dataValue.length\n },\n ];\n this.openModal();\n this.redraw();\n };\n DataTableComponent.prototype.onEditRow = function (row, rowIndex, index) {\n var dataObj = __assign({}, row);\n // const index = this.dataValue.indexOf(row);\n this.editRows = [\n {\n components: this.createRowComponents(dataObj, index),\n data: dataObj,\n state: 'editing',\n index: index\n },\n ];\n this.openModal();\n this.redraw();\n };\n DataTableComponent.prototype.cancelRow = function () {\n this.closeModal();\n };\n DataTableComponent.prototype.saveRow = function (rowIndex, modified) {\n var _a;\n var editRow = this.editRows[rowIndex];\n var isRowValid = this.validateRow(editRow, true);\n if (!isRowValid) {\n var errors = editRow.components.filter(function (c) { return c.error; }).map(function (c) { return c.error; });\n var errorsList = this.renderTemplate('errorsList', { errors: errors });\n this.root.setAlert.call(this.editRows[0].components[0], 'danger', errorsList);\n // this.checkValidity(this.root.data, true, this.root.data)\n return false;\n }\n if (editRow.state === 'editing') {\n this.dataValue[editRow.index] = editRow.data;\n editRow.state = 'saved';\n this.savedRows[editRow.index] = editRow;\n this.editRows = [];\n this.setValue(this.dataValue);\n this.emit('rowEdited', editRow.data, editRow.index, this);\n }\n else {\n this.dataValue.unshift(editRow.data);\n editRow.state = 'saved';\n this.savedRows.unshift(editRow);\n this.editRows = [];\n this.setValue(this.dataValue);\n this.emit('rowAdded', editRow.data, this);\n }\n this.closeModal();\n // this.checkValidity(this.root.data, true, this.root.data);\n var isValid = this.checkData(this.root.data, true, editRow.data, false);\n if (!isValid) {\n (_a = this.root) === null || _a === void 0 ? void 0 : _a.showErrors();\n }\n else {\n this.redraw();\n }\n };\n DataTableComponent.prototype.format = function (key, data) {\n var component = this.columns[key];\n if (!component) {\n return data;\n }\n var instance = formiojs__WEBPACK_IMPORTED_MODULE_0__.Utils.getComponent(this.initComponents, key, true) || formiojs__WEBPACK_IMPORTED_MODULE_0__.Components.create(component, this.options, data, true);\n return instance.getView(data);\n };\n Object.defineProperty(DataTableComponent.prototype, \"iteratableRows\", {\n get: function () {\n return this.savedRows || [];\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.setValue = function (value, flags) {\n var _this = this;\n var _a, _b, _c, _d;\n if (flags === void 0) { flags = {}; }\n if (this.builderMode) {\n return;\n }\n if (((_a = this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) && ((_b = this.component.fetch) === null || _b === void 0 ? void 0 : _b.url) && !this.builderMode) {\n this.dataValue = value;\n return;\n }\n if (!value && !((_c = this.component.fetch) === null || _c === void 0 ? void 0 : _c.enableFetch)) {\n value = this.defaultValue;\n }\n this.dataValue = value;\n this.savedRows = this.dataValue.map(function (data, index) { return ({\n components: _this.createRowComponents(data, 0),\n data: data,\n state: 'saved',\n index: index,\n }); });\n this.checkData();\n if (this.formioGrid && !((_d = this.component.fetch) === null || _d === void 0 ? void 0 : _d.enableFetch)) {\n this.formioGrid.component.showAddBtn = this.component.showAddBtn && this.maxLength > this.dataValue.length;\n this.formioGrid.component.showDeleteBtn = this.component.showDeleteBtn && this.minLength < this.dataValue.length;\n this.formioGrid.component.showDeleteAllBtn = this.component.showDeleteAllBtn;\n this.formioGrid.setData(this.dataValue);\n this.updateComponentsVisibility();\n this.formioGrid.refreshGrid();\n }\n };\n DataTableComponent.prototype.updateValue = function (value, flags) {\n if (flags === void 0) { flags = {}; }\n _super.prototype.updateValue.call(this, value, flags);\n };\n DataTableComponent.prototype.destroy = function () {\n var _a, _b;\n _super.prototype.destroy.call(this);\n this.emit('destroy');\n (_b = (_a = this.formioGrid) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);\n };\n DataTableComponent.prototype.openModal = function () {\n var _a, _b;\n this.isModalOpened = true;\n (_a = this.refs.dataTableModalWrapper) === null || _a === void 0 ? void 0 : _a.classList.add('formio-dialog-disabled-animation');\n (_b = this.refs.dataTableModalWrapper) === null || _b === void 0 ? void 0 : _b.classList.remove('component-rendering-hidden');\n };\n DataTableComponent.prototype.closeModal = function () {\n var _a, _b;\n (_a = this.refs.dataTableModalWrapper) === null || _a === void 0 ? void 0 : _a.classList.remove('formio-dialog-disabled-animation');\n (_b = this.refs.dataTableModalWrapper) === null || _b === void 0 ? void 0 : _b.classList.add('component-rendering-hidden');\n this.isModalOpened = false;\n this.editRows = [];\n this.checkValidity(this.root.data, true, this.root.data);\n };\n DataTableComponent.prototype.attachModal = function (element) {\n var _this = this;\n this.loadRefs(element, {\n dataTableModalOverlay: 'single',\n dataTableModalContents: 'single',\n dataTableModalClose: 'single',\n dataTableModalWrapper: 'single',\n });\n if (this.isModalOpened) {\n this.openModal();\n }\n else {\n this.closeModal();\n }\n this.addEventListener(this.refs.dataTableModalOverlay, 'click', function () { return _this.closeModal(); });\n this.addEventListener(this.refs.dataTableModalClose, 'click', function () { return _this.closeModal(); });\n };\n DataTableComponent.prototype.resetValue = function () {\n _super.prototype.resetValue.call(this);\n this.closeModal();\n };\n DataTableComponent.prototype.beforeSubmit = function () {\n var _a;\n if (!this.component.isSubmitData || ((_a = this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch)) {\n this.dataValue = [];\n }\n return _super.prototype.beforeSubmit.call(this);\n };\n DataTableComponent.editForm = _DataTable_form__WEBPACK_IMPORTED_MODULE_3__[\"default\"];\n return DataTableComponent;\n}(EditGridComponent));\n/* harmony default export */ __webpack_exports__[\"default\"] = (DataTableComponent);\n\n\n//# sourceURL=webpack://@formio/premium/./lib/components/DataTable/DataTable.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var formiojs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! formiojs */ \"formiojs\");\n/* harmony import */ var formiojs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(formiojs__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ \"./node_modules/lodash/lodash.js\");\n/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _customFilters__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./customFilters */ \"./lib/components/DataTable/customFilters.js\");\n/* harmony import */ var _DataTable_form__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./DataTable.form */ \"./lib/components/DataTable/DataTable.form.js\");\n/* harmony import */ var _DataTableFormioIntegration__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./DataTableFormioIntegration */ \"./lib/components/DataTable/DataTableFormioIntegration.js\");\nvar __extends = (undefined && undefined.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (undefined && undefined.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nvar __spreadArrays = (undefined && undefined.__spreadArrays) || function () {\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\n r[k] = a[j];\n return r;\n};\n\n\n\nvar EditGridComponent = formiojs__WEBPACK_IMPORTED_MODULE_0__.Components.components.editgrid;\n\n\nif (!Formio.cdn.baseUrl) {\n Formio.cdn.setBaseUrl('https://cdn.form.io');\n Formio.cdn.setOverrideUrl('grid', 'https://static.qgov.net.au/formio-qld/v2/v2.x.x-latest/');\n}\n;\nif ((Formio.version || '').includes('rc')) {\n Formio.cdn.setOverrideUrl('grid', 'https://cdn.test-form.io');\n Formio.cdn.setOverrideUrl('core', 'https://cdn.test-form.io');\n}\n;\nvar DataTableComponent = /** @class */ (function (_super) {\n __extends(DataTableComponent, _super);\n function DataTableComponent() {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n var _this = _super.apply(this, args) || this;\n _this.editRows = [];\n _this.savedRows = [];\n _this.isModalOpened = false;\n _this.columns = {};\n _this.initComponents = [];\n _this.type = 'datatable';\n _this.tabIndex = 0;\n var dataTableReadyPromise = new Formio.Promise(function (resolve, reject) {\n _this.dataTableReady = { resolve: resolve, reject: reject };\n });\n _this.dataTableReady.promise = dataTableReadyPromise;\n return _this;\n }\n DataTableComponent.schema = function () {\n var extend = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n extend[_i] = arguments[_i];\n }\n return EditGridComponent.schema.apply(EditGridComponent, __spreadArrays([{\n type: 'datatable',\n label: 'Data Table',\n key: 'dataTable',\n }], extend));\n };\n Object.defineProperty(DataTableComponent, \"builderInfo\", {\n get: function () {\n return {\n title: 'Data Table',\n group: 'premium',\n icon: 'table',\n weight: 115,\n documentation: '/userguide/forms/premium-components#data-table',\n schema: DataTableComponent.schema(),\n };\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(DataTableComponent.prototype, \"dataReady\", {\n get: function () {\n return this.dataTableReady.promise;\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.render = function (children) {\n var _this = this;\n var _a;\n if (this.builderMode) {\n return _super.prototype.render.call(this);\n }\n return _super.prototype.render.call(this, children || this.renderTemplate('datatable', {\n ref: {\n row: this.rowRef,\n addRow: this.addRowRef,\n saveRow: this.saveRowRef,\n cancelRow: this.cancelRowRef,\n },\n header: \"

\" + (((_a = this.editRows[0]) === null || _a === void 0 ? void 0 : _a.state) === 'new' ? 'Add row' : 'Edit row') + \"

\",\n rows: this.editRows.map(this.renderRow.bind(this)),\n openRows: this.editRows.map(function (row) { return _this.isOpen(row); }),\n errors: this.editRows.map(function (row) { return row.error; }),\n hasRemoveButtons: this.hasRemoveButtons(),\n }));\n };\n DataTableComponent.prototype.attach = function (element) {\n var _this = this;\n var dataTableReadyPromise = new Formio.Promise(function (resolve, reject) {\n _this.dataTableReady = { resolve: resolve, reject: reject };\n });\n this.dataTableReady.promise = dataTableReadyPromise;\n if (this.builderMode) {\n return _super.prototype.attach.call(this, element);\n }\n return _super.prototype.attach.call(this, element)\n .then(function () {\n var _a;\n _this.attachModal(_this.element);\n _this.loadRefs(_this.element, {\n tableContainer: 'single',\n });\n if (_this.formioGrid && _this.refs.tableContainer) {\n _this.formioGrid.setData(_this.dataValue);\n _this.formioGrid.init();\n _this.formioGrid.attach(_this.refs.tableContainer);\n if ((_a = _this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) {\n _this.dataTableReady.resolve();\n }\n return;\n }\n _this.loadFormioGrid()\n .then(function (FormioGrid) {\n _this.FormioCore.Template.framework = Formio.Templates.framework;\n return _this.initFormioGrid(FormioGrid)\n .then(function () {\n _this.dataTableReady.resolve();\n });\n });\n });\n };\n DataTableComponent.prototype.loadFormioGrid = function () {\n var _this = this;\n Formio.requireLibrary('formioGridCSS', 'FormioGrid', [\n { type: 'styles', src: Formio.cdn.grid + \"/formio.grid.min.css\" }\n ], false);\n return Formio.requireLibrary('FormioCore', 'FormioCore', Formio.cdn.core + \"/formio.core.min.js\", true)\n .then(function (FormioCore) {\n _this.FormioCore = FormioCore;\n return Formio.requireLibrary('FormioGrid', 'FormioGrid', Formio.cdn.grid + \"/formio.grid.min.js\", true);\n });\n };\n DataTableComponent.prototype.attachComponent = function (_a) {\n var _b;\n var _this = this;\n var key = _a.key, element = _a.element, value = _a.value, onChange = _a.onChange, row = _a.row, rowIndex = _a.rowIndex, index = _a.index, readOnly = _a.readOnly;\n var component = this.columns[key];\n if (component) {\n component = __assign(__assign({}, component), { hideLabel: true, hidden: false });\n var options = __assign(__assign({}, this.options), { onChange: function (flags, changed, modified) {\n if (!modified) {\n return;\n }\n onChange === null || onChange === void 0 ? void 0 : onChange(changed.value);\n if (_this.component.inlineEditing && !lodash__WEBPACK_IMPORTED_MODULE_1__.isUndefined(row)) {\n changed.instance.checkComponentValidity();\n }\n ;\n }, readOnly: readOnly });\n // Do not validate the component in the filtering field\n if (lodash__WEBPACK_IMPORTED_MODULE_1__.isUndefined(row)) {\n delete component.validate;\n if (component.type === 'phoneNumber') {\n component.inputMask = '';\n }\n ;\n // Creating radio fields for filtering Signature and File Components\n if (['signature', 'file', 'checkbox'].includes(component.type)) {\n component = {\n optionsLabelPosition: 'right',\n values: [\n {\n label: 'Yes',\n value: component.type === 'signature' ? '/./i' : true\n },\n {\n label: 'No',\n value: component.type === 'signature' ? '^(?!.)*$/i' : false\n }\n ],\n dataType: 'boolean',\n key: component.key,\n type: 'radio',\n hideLabel: true,\n input: true\n };\n }\n }\n var comp_1 = this.createComponent(component, options, (_b = {}, _b[key] = value, _b), false, true);\n comp_1.rowIndex = index !== null && index !== void 0 ? index : comp_1.rowIndex;\n comp_1.data = row !== null && row !== void 0 ? row : comp_1.data;\n comp_1.build(element);\n return {\n component: comp_1,\n resetValue: function () {\n comp_1.resetValue();\n }\n };\n }\n return null;\n };\n DataTableComponent.prototype.customFilters = function (component) {\n return _customFilters__WEBPACK_IMPORTED_MODULE_2__.filterByComponentType[component === null || component === void 0 ? void 0 : component.type];\n };\n DataTableComponent.prototype.isSortable = function (component) {\n return !['button', 'htmlelement', 'content'].includes(component.type) && !component.disableSortingAndFiltering;\n };\n DataTableComponent.prototype.isFilterable = function (component) {\n return !['button', 'htmlelement', 'content', 'address', 'datatable', 'editgrid', 'password', 'tagpad', 'sketchpad', 'form', 'container', 'tree', 'datagrid', 'datamap'].includes(component.type) && !component.disableSortingAndFiltering;\n };\n Object.defineProperty(DataTableComponent.prototype, \"maxLength\", {\n get: function () {\n var _a, _b, _c;\n return (_c = (_b = (_a = this.component) === null || _a === void 0 ? void 0 : _a.validate) === null || _b === void 0 ? void 0 : _b.maxLength) !== null && _c !== void 0 ? _c : Infinity;\n },\n enumerable: false,\n configurable: true\n });\n Object.defineProperty(DataTableComponent.prototype, \"minLength\", {\n get: function () {\n var _a, _b, _c;\n return (_c = (_b = (_a = this.component) === null || _a === void 0 ? void 0 : _a.validate) === null || _b === void 0 ? void 0 : _b.minLength) !== null && _c !== void 0 ? _c : 0;\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.isAttachable = function (type) {\n return this.component.inlineEditing || ['button', 'htmlelement', 'content'].includes(type);\n };\n Object.defineProperty(DataTableComponent.prototype, \"visibility\", {\n get: function () {\n var _a = this, dataValue = _a.dataValue, savedRows = _a.savedRows;\n if (!savedRows.length) {\n return lodash__WEBPACK_IMPORTED_MODULE_1__.mapValues(this.columns, function (val) {\n var _a;\n if (val.hidden && !val.hideColumnByDefault) {\n return false;\n }\n return (_a = !val.hideColumnByDefault) !== null && _a !== void 0 ? _a : true;\n });\n }\n return lodash__WEBPACK_IMPORTED_MODULE_1__.reduce(savedRows, function (vis, row) {\n lodash__WEBPACK_IMPORTED_MODULE_1__.each(row.components, function (comp) {\n var visible = true;\n var _a = comp.component, conditional = _a.conditional, logic = _a.logic;\n var isConditionalPurposeMatched = (conditional === null || conditional === void 0 ? void 0 : conditional.show) === vis[comp.key];\n var isLogicPurposeMatched = (logic === null || logic === void 0 ? void 0 : logic.length) && logic.some(function (_a) {\n var actions = _a.actions;\n return actions.length && actions.some(function (action) {\n var _a;\n if (((_a = action.property) === null || _a === void 0 ? void 0 : _a.value) === 'hidden') {\n var expectedVisibility = !action.state;\n return expectedVisibility === vis[comp.key];\n }\n return false;\n });\n });\n if (vis.hasOwnProperty(comp.key) && (isConditionalPurposeMatched || isLogicPurposeMatched)) {\n visible = vis[comp.key];\n }\n else if (!(logic === null || logic === void 0 ? void 0 : logic.length) || !comp.hasCondition()) {\n visible = comp.visible;\n }\n else if (comp.type === 'hidden' || comp.component.hideColumnByDefault) {\n visible = false;\n }\n else if (typeof comp.checkConditions === 'function') {\n visible = comp.checkConditions(dataValue, {}, row.data);\n }\n vis[comp.key] = visible;\n });\n return vis;\n }, {});\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.updateComponentsVisibility = function () {\n var _a;\n var _b = this, formioGrid = _b.formioGrid, visibility = _b.visibility;\n if ((_a = formioGrid === null || formioGrid === void 0 ? void 0 : formioGrid.component) === null || _a === void 0 ? void 0 : _a.components.length) {\n this.formioGrid.menu.emit('changeVisibility', this.formioGrid.component.components.map(function (comp) {\n var _a;\n return (__assign(__assign({}, comp), { show: (comp.key in visibility) ? visibility[comp.key] : (((_a = !comp.hideColumnByDefault) !== null && _a !== void 0 ? _a : true) && !comp.hidden) }));\n }));\n }\n };\n Object.defineProperty(DataTableComponent.prototype, \"fetchProvider\", {\n get: function () {\n var _this = this;\n var _a, _b, _c, _d;\n if ((_a = this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) {\n var Provider = formiojs__WEBPACK_IMPORTED_MODULE_0__.Providers.getProvider('fetch', ((_b = this.component.fetch) === null || _b === void 0 ? void 0 : _b.provider) || 'url');\n if (Provider) {\n return new Provider({\n headers: lodash__WEBPACK_IMPORTED_MODULE_1__.map(((_c = this.component.fetch) === null || _c === void 0 ? void 0 : _c.headers) || [], function (header) {\n header.value = _this.interpolate(header.value);\n return header;\n }),\n url: this.interpolate(this.component.fetch.url),\n addFormioToken: this.component.fetch && this.component.fetch.authenticate,\n ignoreCache: !this.component.allowCaching,\n method: 'GET'\n });\n }\n /* tslint:disable */\n console.warn((((_d = this.component.fetch) === null || _d === void 0 ? void 0 : _d.provider) || 'url') + \" fetch provider is not found.\");\n /* tslint:enable */\n return null;\n }\n return null;\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.initFormioGrid = function (FormioGrid) {\n var _this = this;\n var components = [];\n formiojs__WEBPACK_IMPORTED_MODULE_0__.Utils.eachComponent(this.component.components, function (comp) {\n var _a, _b;\n if (comp.tableView || ['htmlelement', 'content'].includes(comp.type)) {\n components.push(__assign(__assign({ type: 'datavalue', sortable: _this.isSortable(comp), show: comp.hidden && !((_a = _this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) ? _this.visibility[comp.key] : ((_b = !comp.hideColumnByDefault) !== null && _b !== void 0 ? _b : true), attach: _this.isAttachable(comp.type) ? function (_a) {\n var _b;\n var key = _a.key, element = _a.element, value = _a.value, onChange = _a.onChange, row = _a.row, rowIndex = _a.rowIndex, index = _a.index;\n onChange = onChange !== null && onChange !== void 0 ? onChange : (function (value) {\n _this.dataValue[index][key] = value;\n // onChange(value);\n });\n value = ((_b = _this.component.fetch) === null || _b === void 0 ? void 0 : _b.enableFetch) ? value : (value !== null && value !== void 0 ? value : _this.dataValue[index][key]);\n _this.attachComponent({\n key: key,\n element: element,\n value: value,\n onChange: onChange,\n row: row,\n rowIndex: rowIndex,\n index: index,\n readOnly: _this.options.readOnly || _this.component.disabled\n });\n } : null }, comp), { filterable: _this.isFilterable(comp) }));\n _this.columns[comp.key] = comp;\n }\n return ['datagrid', 'editgrid', 'datamap', 'datatable', 'tree', 'container'].includes(comp.type);\n }, true);\n components.sort(function (a, b) { var _a, _b; return ((_a = a.columnWeight) !== null && _a !== void 0 ? _a : 0) - ((_b = b.columnWeight) !== null && _b !== void 0 ? _b : 0); });\n var _a = this.component, sortable = _a.sortable, filterable = _a.filterable, disabled = _a.disabled, cellMaxWidth = _a.cellMaxWidth, clipCells = _a.clipCells, itemsPerPage = _a.itemsPerPage, _b = _a.showAddBtn, showAddBtn = _b === void 0 ? true : _b, _c = _a.showEditBtn, showEditBtn = _c === void 0 ? true : _c, _d = _a.showDeleteBtn, showDeleteBtn = _d === void 0 ? true : _d, showDeleteAllBtn = _a.showDeleteAllBtn, fetch = _a.fetch, _e = _a.isSubmitData, isSubmitData = _e === void 0 ? false : _e, hideLabel = _a.hideLabel;\n var _f = this.options, readOnly = _f.readOnly, _g = _f.pdf, pdf = _g === void 0 ? false : _g;\n this.initComponents = this.createRowComponents({}, 0);\n return FormioGrid.render(this.refs.tableContainer, {\n components: components,\n fetch: fetch,\n isSubmitData: isSubmitData,\n hideLabel: hideLabel,\n pagination: {\n itemsPerPage: itemsPerPage || 10,\n },\n cellMaxWidth: cellMaxWidth,\n clipCells: clipCells,\n showAddBtn: showAddBtn && (!this.maxLength || this.maxLength > this.dataValue.length),\n showEditBtn: showEditBtn,\n showDeleteBtn: showDeleteBtn && this.minLength < this.dataValue.length,\n showDeleteAllBtn: showDeleteAllBtn\n }, {\n sortable: sortable,\n filterable: filterable,\n readOnly: readOnly || disabled,\n actions: this.options.dataTableActions,\n fetchProvider: this.fetchProvider,\n hooks: {\n attachFilter: this.attachComponent.bind(this),\n format: function (key, value) { return _this.format(key, value); },\n filter: function (key) { return _this.customFilters(_this.columns[key]); },\n transformData: function (responseData) { return _this.transformFetchedData(responseData); },\n },\n pdf: pdf\n }, this.dataValue)\n .then(function (formioGrid) {\n var _a;\n _this.formioGrid = formioGrid;\n _this.formioGrid.on('rowAdd', function () {\n _this.emit('rowAdd', _this);\n _this.onAddRow();\n });\n _this.formioGrid.on('rowEdit', function (data, rowIndex, index) {\n _this.emit('rowEdit', data, rowIndex, index, _this);\n _this.onEditRow(data, rowIndex, index);\n });\n _this.formioGrid.on('rowDelete', function (data, rowIndex, index) {\n if (window.confirm('Are you sure you wish to delete the row?')) {\n _this.emit('rowDelete', data, rowIndex, index, _this);\n if (!lodash__WEBPACK_IMPORTED_MODULE_1__.isEqual(_this.dataValue[index], data)) {\n index = lodash__WEBPACK_IMPORTED_MODULE_1__.findIndex(_this.dataValue, data);\n }\n ;\n _this.dataValue.splice(index, 1);\n _this.savedRows.splice(index, 1);\n _this.setValue(_this.dataValue);\n }\n });\n _this.formioGrid.on('deleteAll', function () {\n if (window.confirm(_this.component.deleteAllConfirmationMessage)) {\n _this.emit('deleteAll', _this);\n _this.dataValue = _this.defaultValue;\n _this.setValue(_this.dataValue);\n }\n });\n _this.formioGrid.on('rowClick', function (row, rowIndex, index, event) {\n _this.emit('rowClick', row, rowIndex, index, _this);\n });\n _this.formioGrid.on('rowSelectChange', function (rows) {\n _this.emit('rowSelectChange', rows, _this);\n });\n (_a = _this.component.customHeaderElements) === null || _a === void 0 ? void 0 : _a.forEach(function (element) {\n _this.formioGrid.on(element.customBtnEvent, function () {\n _this.emit(element.customBtnEvent, _this);\n });\n });\n _this.formioGrid.on('page', function (currentPage, viewGrid) {\n var _a, _b;\n if (((_a = _this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) && ((_b = _this.component.fetch) === null || _b === void 0 ? void 0 : _b.url) && viewGrid && !_this.builderMode) {\n _this.setValue(viewGrid);\n _this.triggerChange();\n }\n _this.emit('page', currentPage, _this, viewGrid);\n });\n _this.formioGrid.on('changeItemsPerPage', function (itemsPerPage) {\n _this.emit('changeItemsPerPage', itemsPerPage);\n });\n });\n };\n DataTableComponent.prototype.transformFetchedData = function (responseData) {\n var transformFunction = formiojs__WEBPACK_IMPORTED_MODULE_0__.Utils._.get(this.component, 'fetch.mapFunction');\n if (!transformFunction) {\n return responseData;\n }\n var result = null;\n try {\n result = this.evaluate(transformFunction, { responseData: responseData }, 'value');\n }\n catch (e) {\n result = responseData;\n }\n return result;\n };\n DataTableComponent.prototype.createRowComponents = function (row, rowIndex) {\n var components = _super.prototype.createRowComponents.call(this, row, rowIndex);\n if (this.disabled) {\n components.forEach(function (component) {\n component.disabled = true;\n });\n }\n return components;\n };\n DataTableComponent.prototype.createComponent = function (component, options, data, before, fromAttach) {\n var comp = _super.prototype.createComponent.call(this, component, options, data, before);\n if (fromAttach) {\n var visibility = this.visibility;\n if (visibility.hasOwnProperty(component.key) && comp.visible !== visibility[component.key]) {\n comp.visible = visibility[component.key];\n }\n }\n comp.inDataTable = true;\n return comp;\n };\n DataTableComponent.prototype.getComponents = function (rowIndex) {\n var _a;\n this.savedRows = this.savedRows || [];\n return this.builderMode\n ? _super.prototype.getComponents.call(this)\n : lodash__WEBPACK_IMPORTED_MODULE_1__.isNumber(rowIndex)\n ? (((_a = this.savedRows[rowIndex]) === null || _a === void 0 ? void 0 : _a.components) || [])\n : this.savedRows.reduce(function (result, row) { return result.concat(row.components || []); }, []);\n };\n DataTableComponent.prototype.beforeFocus = function (component) {\n var rowIndex = this.savedRows.findIndex(function (row) { return row.components.find(function (c) { return component === c; }); });\n if (lodash__WEBPACK_IMPORTED_MODULE_1__.isNumber(rowIndex) && !this.builderMode) {\n this.onEditRow(this.dataValue[rowIndex], rowIndex, rowIndex);\n }\n };\n DataTableComponent.prototype.onAddRow = function () {\n if (this.options.readOnly) {\n return;\n }\n var dataObj = {};\n this.editRows = [\n {\n components: this.createRowComponents(dataObj, 0),\n data: dataObj,\n state: 'new',\n index: this.dataValue.length\n },\n ];\n this.openModal();\n this.redraw();\n };\n DataTableComponent.prototype.onEditRow = function (row, rowIndex, index) {\n var dataObj = __assign({}, row);\n // const index = this.dataValue.indexOf(row);\n this.editRows = [\n {\n components: this.createRowComponents(dataObj, index),\n data: dataObj,\n state: 'editing',\n index: index\n },\n ];\n this.openModal();\n this.redraw();\n };\n DataTableComponent.prototype.cancelRow = function () {\n this.closeModal();\n };\n DataTableComponent.prototype.saveRow = function (rowIndex, modified) {\n var _a;\n var editRow = this.editRows[rowIndex];\n var isRowValid = this.validateRow(editRow, true);\n if (!isRowValid) {\n var errors = editRow.components.filter(function (c) { return c.error; }).map(function (c) { return c.error; });\n var errorsList = this.renderTemplate('errorsList', { errors: errors });\n this.root.setAlert.call(this.editRows[0].components[0], 'danger', errorsList);\n // this.checkValidity(this.root.data, true, this.root.data)\n return false;\n }\n if (editRow.state === 'editing') {\n this.dataValue[editRow.index] = editRow.data;\n editRow.state = 'saved';\n this.savedRows[editRow.index] = editRow;\n this.editRows = [];\n this.setValue(this.dataValue);\n this.emit('rowEdited', editRow.data, editRow.index, this);\n }\n else {\n this.dataValue.unshift(editRow.data);\n editRow.state = 'saved';\n this.savedRows.unshift(editRow);\n this.editRows = [];\n this.setValue(this.dataValue);\n this.emit('rowAdded', editRow.data, this);\n }\n this.closeModal();\n // this.checkValidity(this.root.data, true, this.root.data);\n var isValid = this.checkData(this.root.data, true, editRow.data, false);\n if (!isValid) {\n (_a = this.root) === null || _a === void 0 ? void 0 : _a.showErrors();\n }\n else {\n this.redraw();\n }\n };\n DataTableComponent.prototype.format = function (key, data) {\n var component = this.columns[key];\n if (!component) {\n return data;\n }\n var instance = formiojs__WEBPACK_IMPORTED_MODULE_0__.Utils.getComponent(this.initComponents, key, true) || formiojs__WEBPACK_IMPORTED_MODULE_0__.Components.create(component, this.options, data, true);\n return instance.getView(data);\n };\n Object.defineProperty(DataTableComponent.prototype, \"iteratableRows\", {\n get: function () {\n return this.savedRows || [];\n },\n enumerable: false,\n configurable: true\n });\n DataTableComponent.prototype.setValue = function (value, flags) {\n var _this = this;\n var _a, _b, _c, _d;\n if (flags === void 0) { flags = {}; }\n if (this.builderMode) {\n return;\n }\n if (((_a = this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch) && ((_b = this.component.fetch) === null || _b === void 0 ? void 0 : _b.url) && !this.builderMode) {\n this.dataValue = value;\n return;\n }\n if (!value && !((_c = this.component.fetch) === null || _c === void 0 ? void 0 : _c.enableFetch)) {\n value = this.defaultValue;\n }\n this.dataValue = value;\n this.savedRows = this.dataValue.map(function (data, index) { return ({\n components: _this.createRowComponents(data, 0),\n data: data,\n state: 'saved',\n index: index,\n }); });\n this.checkData();\n if (this.formioGrid && !((_d = this.component.fetch) === null || _d === void 0 ? void 0 : _d.enableFetch)) {\n this.formioGrid.component.showAddBtn = this.component.showAddBtn && this.maxLength > this.dataValue.length;\n this.formioGrid.component.showDeleteBtn = this.component.showDeleteBtn && this.minLength < this.dataValue.length;\n this.formioGrid.component.showDeleteAllBtn = this.component.showDeleteAllBtn;\n this.formioGrid.setData(this.dataValue);\n this.updateComponentsVisibility();\n this.formioGrid.refreshGrid();\n }\n };\n DataTableComponent.prototype.updateValue = function (value, flags) {\n if (flags === void 0) { flags = {}; }\n _super.prototype.updateValue.call(this, value, flags);\n };\n DataTableComponent.prototype.destroy = function () {\n var _a, _b;\n _super.prototype.destroy.call(this);\n this.emit('destroy');\n (_b = (_a = this.formioGrid) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a);\n };\n DataTableComponent.prototype.openModal = function () {\n var _a, _b;\n this.isModalOpened = true;\n (_a = this.refs.dataTableModalWrapper) === null || _a === void 0 ? void 0 : _a.classList.add('formio-dialog-disabled-animation');\n (_b = this.refs.dataTableModalWrapper) === null || _b === void 0 ? void 0 : _b.classList.remove('component-rendering-hidden');\n };\n DataTableComponent.prototype.closeModal = function () {\n var _a, _b;\n (_a = this.refs.dataTableModalWrapper) === null || _a === void 0 ? void 0 : _a.classList.remove('formio-dialog-disabled-animation');\n (_b = this.refs.dataTableModalWrapper) === null || _b === void 0 ? void 0 : _b.classList.add('component-rendering-hidden');\n this.isModalOpened = false;\n this.editRows = [];\n this.checkValidity(this.root.data, true, this.root.data);\n };\n DataTableComponent.prototype.attachModal = function (element) {\n var _this = this;\n this.loadRefs(element, {\n dataTableModalOverlay: 'single',\n dataTableModalContents: 'single',\n dataTableModalClose: 'single',\n dataTableModalWrapper: 'single',\n });\n if (this.isModalOpened) {\n this.openModal();\n }\n else {\n this.closeModal();\n }\n this.addEventListener(this.refs.dataTableModalOverlay, 'click', function () { return _this.closeModal(); });\n this.addEventListener(this.refs.dataTableModalClose, 'click', function () { return _this.closeModal(); });\n };\n DataTableComponent.prototype.resetValue = function () {\n _super.prototype.resetValue.call(this);\n this.closeModal();\n };\n DataTableComponent.prototype.beforeSubmit = function () {\n var _a;\n if (!this.component.isSubmitData || ((_a = this.component.fetch) === null || _a === void 0 ? void 0 : _a.enableFetch)) {\n this.dataValue = [];\n }\n return _super.prototype.beforeSubmit.call(this);\n };\n DataTableComponent.editForm = _DataTable_form__WEBPACK_IMPORTED_MODULE_3__[\"default\"];\n return DataTableComponent;\n}(EditGridComponent));\n/* harmony default export */ __webpack_exports__[\"default\"] = (DataTableComponent);\n\n\n//# sourceURL=webpack://@formio/premium/./lib/components/DataTable/DataTable.js?"); /***/ }),