UNPKG

smart-webcomponents-react

Version:

[![Price](https://img.shields.io/badge/price-COMMERCIAL-00JS8f7.svg)](https://jqwidgets.com/license/)

6 lines (4 loc) 110 kB
/* Smart UI v23.0.8 (2025-05-13) Copyright (c) 2011-2024 jQWidgets. License: https://htmlelements.com/license/ */ // (()=>{Smart.Utilities.Assign("Grid.Edit",class{_renderCommandBar(){const e=this,t=e.editing.commandBar.dataSource,i="icon"!==e.editing.commandBar.displayMode,n="label"!==e.editing.commandBar.displayMode,l=l=>{for(let o in t){const a=t[o],r=document.createElement("div");r.classList.add("smart-grid-command-item"),r.label="{{messages}}"===a.label?e.localize(o):a.label;const d=r.label;let s="";n&&i?(s+='<span class="smart-grid-icon '+a.icon+'"></span>',s+='<span class="smart-grid-label">'+d+"</span>"):n&&!i?s+='<span title="'+d+'" class="smart-grid-icon '+a.icon+'"></span>':i&&!n&&(s+='<span class="smart-grid-label">'+d+"</span>"),r.innerHTML=s,a.visible||r.classList.add("smart-hidden"),r.command=a.command,r.onclick=function(){const t=r.command;e._applyCommand(t,[])},l.appendChild(r)}};e.editing.enabled&&e.editing.commandBar.visible&&(e.$.headerCommandBar.innerHTML="",e.$.footerCommandBar.innerHTML="","far"!==e.editing.commandBar.position&&l(e.$.headerCommandBar),"near"!==e.editing.commandBar.position&&l(e.$.footerCommandBar))}commandKeyEditCommand(){const e=this;if(e._selection&&e._selection.focusedCell&&void 0!==e._selection.focusedCell.id){const t=e.rowById[e._selection.focusedCell.id];e.beginEdit(t.id)}}commandKeyCancelCommand(){this.cancelEdit()}commandKeyUpdateCommand(){this.endEdit()}commandColumnMenuCommand(){this._openColumnChooserMenu(this._commandColumn)}commandColumnEditCommand(e){const t=this;t._disableEndEdit=!0;const i=t._scrollView.vScrollBar.value===t._scrollView.vScrollBar.max;t.beginEdit(e.id),i&&(t._scrollView.vScrollBar.value=t._scrollView.vScrollBar.max),setTimeout((()=>{delete t._disableEndEdit}),50)}commandColumnUpdateCommand(){this.endEdit()}commandColumnRowMenuCommand(){}commandColumnCancelCommand(e){const t=this;if(t.editing.batch){const i=t._rowsDeleted?t._rowsDeleted.indexOf(e):-1;i>=0&&t._rowsDeleted.splice(i,1);for(let i=0;i<t.columns.length;i++){const n=t.columns[i].dataField;t._cellsUpdatedValues&&t._cellsUpdatedValues[e.id+"_"+n]&&(delete t._cellsUpdatedValues[e.id+"_"+n],t._cellsUpdatedValues.length--)}t._recycle(!1)}t.cancelEdit()}commandColumnDeleteCommand(e){this.deleteRow(e.id)}_renderAddNewRow(){const e=this;e._frozenNearDefaultRows=[],e._frozenFarDefaultRows=[];const t=new Smart.Grid.Row({data:{},index:-1,grid:e,freeze:"near",visible:"far"!==e.editing.addNewRow.position,autoGenerated:!0,addNewRow:!0}),i=new Smart.Grid.Row({data:{},index:-2,grid:e,freeze:"far",visible:"near"!==e.editing.addNewRow.position,autoGenerated:!0,addNewRow:!0});if(e._newNearRow){const t=e._frozenNearRows.indexOf(e._newNearRow);if(t>=0&&(e._frozenNearRows.splice(t,1),e.$.rowNearContainer.children.length>0)){const t=e.$.rowNearContainer.children[0];t.parentNode.removeChild(t)}}if(e._newFarRow){const t=e._frozenFarRows.indexOf(e._newFarRow);if(t>=0&&(e._frozenFarRows.splice(t,1),e.$.rowFarContainer.children.length>0)){const t=e.$.rowFarContainer.children[e.$.rowFarContainer.children.length-1];t.parentNode.removeChild(t)}}e.editing.addNewRow.visible&&"button"!==e.editing.addNewRow.displayMode&&(e._frozenNearDefaultRows.push(t),e._frozenFarDefaultRows.push(i),e._frozenNearRows.splice(0,0,t),e._frozenFarRows.push(i));const n=()=>{e.editing.addNewRow.autoCreate&&e._scrollView.vScrollBar.value===e._scrollView.vScrollBar.max&&(e.addUnboundRow(1),e._scrollView.vScrollBar.value=e._scrollView.vScrollBar.max),"button"===e.editing.addNewRow.displayMode&&e._scrollView.vScrollBar.value===e._scrollView.vScrollBar.max&&(e._add({}),e._scrollView.vScrollBar.value=e._scrollView.vScrollBar.max)};if(e._addRowOnButtonClickHandler||(e._addRowOnButtonClickHandler=n),e._scrollView&&e._scrollView.vScrollBar&&(e._scrollView.vScrollBar.$.farButton.removeEventListener("click",e._addRowOnButtonClickHandler),e._scrollView.vScrollBar.$.farButton.addEventListener("click",e._addRowOnButtonClickHandler)),e._newNearRow=t,e._newFarRow=i,e.editing.addNewRow.visible&&"button"!==e.editing.addNewRow.displayMode){if(!e._newNearRow.element){const t=e._newNearRow,i=t.createElement();t.visible="far"!==e.editing.addNewRow.position,t.element=i,e.$.rowNearContainer.children.length>0?e.$.rowNearContainer.insertBefore(i,e.$.rowNearContainer.children[0]):e.$.rowNearContainer.appendChild(i)}if(!e._newFarRow.element){const t=e._newFarRow,i=t.createElement();t.visible="near"!==e.editing.addNewRow.position,t.element=i,e.$.rowFarContainer.children.length>0?e.$.rowFarContainer.insertBefore(i,e.$.rowFarContainer.children[0]):e.$.rowFarContainer.appendChild(i)}}}_insertNewRowAfter(e){return this._insertNewRowBefore(e,!0)}_insertNewRowBefore(e,t=!1){const i=this,n=new Smart.Grid.Row({index:t?0:-1,id:Smart.Utilities.Core.createGUID(),grid:i}),l={};for(let e=0;e<i.columns.length;e++){const t=i.columns[e];void 0!==t.defaultValue?l[t.dataField]=t.defaultValue:"uuid"===t.template&&(dataRow[t.dataField]=i._generateUUID())}n.data=l;const o=function(t,n){i._suppressSort=i._suppressFilter=!0;const l=e=>{i._supressEnter=!0,i.scrollTop=n?i.scrollHeight:0,i.editing.addDialog.enabled||setTimeout((function(){if(i.editing.enabled&&i.editing.addNewRow.autoEdit){i.ensureVisible(e.id);let t=null;if(!t)if(i.columns[0]&&i.columns[0].allowEdit&&i.columns[0].visible)t=i.columns[0].dataField;else for(let e=0;e<i.columns.length;e++)if(i.columns[e].allowEdit&&i.columns[e].visible){t=i.columns[e].dataField;break}const n=()=>{i._selection.focusedCell={id:e.id,dataField:t,index:e.index},i._selection.rows=[],i._selection.columns=[],i._selection.cells=[],i._setSelection(e.id,t)};i.paging.enabled?setTimeout((()=>{if(!e.element){const t=e.createElement();e.element=t}n(),i._beginEdit(e)}),200):(n(),i._beginEdit(e))}}),100),i._suppressSort=i._suppressFilter=!1},o=i.dataSource&&i.dataSource.virtualDataSource&&!i.dataSource.virtualDataSourceOnExpand&&"infinite"!==i.scrolling;!0===i.editing.batch||i.editing.batch&&i.editing.batch.indexOf("add")>=0?(i._batchAddRow(t,n?i.rows.length:0),o||l(t),e&&e(t)):i.addRow(t.data,n,(t=>{o||l(t),e&&e(t)}))}.bind(this);return i.editing.addDialog.enabled?i._openAddRowDialog(n,o):o(n,t),!0}commandBarBatchSaveCommand(){this._saveBatchEdit()}commandBarAddRowCommand(){this._insertNewRowAfter()}commandBarAddTopRowCommand(){this._insertNewRowBefore()}commandBarDeleteRowCommand(){const e=this;let t=1,i=e.rows[e.rows.length-t];for(e._rowsDeleted||(e._rowsDeleted=[]);e._rowsDeleted.indexOf(e.rows[e.rows.length-t])>=0;)t++;if(i=e.rows[e.rows.length-t],e.selection.enabled)if(e.selection.allowCellSelection){const t=e.getSelectedCells();if(t.length>0){const n=t[0][0];i=e.rowById[n]}}else{const t=e.getSelectedRowIds();t.length>0&&(i=e.rowById[t[0]])}i&&e.commandColumnDeleteCommand(i)}commandBarBatchRevertCommand(){this.revertBatchEdit()}_beginEdit(e,t){const i=this;if(!t)if(i.columns[0]&&i.columns[0].allowEdit&&i.columns[0].visible)t=i.columns[0].dataField;else for(let e=0;e<i.columns.length;e++)if(i.columns[e].allowEdit&&i.columns[e].visible){t=i.columns[e].dataField;break}const n=i.columnByDataField[t];if(i.editing.allowColumnHeaderEdit&&!e&&n)return void i._beginColumnEdit(n);if(!e||!n||n&&n.autoGenerated)return!1;const l=e.getCell(t);if(!l)return!1;i.$.fireEvent("beginEdit",{id:e.id,dataField:n.dataField,row:e,column:n,cell:l,data:l.row.data,value:l.value}).defaultPrevented||("cell"===i.editing.mode?i._beginCellEdit(l):"row"===i.editing.mode&&i._beginRowEdit(e,l))}_saveUnboundRows(e){const t=this;if(t._unboundRows&&t._unboundRows.length>0&&t.editing.addNewRow.autoSave){const i=t.rowById[e];if(!i.unbound)return;const n=t._unboundRows.indexOf(i);if(n<0)return;const l=n+1;t.beginUpdate();for(let e=0;e<l;e++){const i=t._unboundRows[e];if(!i)continue;delete t.rowById[i.id],i.unbound=!1;let n=!1;t._selection.focusedCell&&t._selection.focusedCell.id===i.id&&(n=!0),t._nearRowsAdded&&t._nearRowsAdded.indexOf(i)>=0?(t._nearRowsAdded.splice(t._nearRowsAdded.indexOf(i),1),t._add(0,i.data),n&&(t._selection.focusedCell.id=t.rows[0].id,t._selection.focusedCell.index=t.rows[0].index)):t._farRowsAdded&&t._farRowsAdded.indexOf(i)>=0&&(t._farRowsAdded.splice(t._farRowsAdded.indexOf(i),1),t._add(i.data),n&&(t._selection.focusedCell.id=t.rows[t.rows.length-1].id,t._selection.focusedCell.id=t.rows[t.rows.length-1].index))}t._unboundRows.splice(0,l),t.endUpdate()}}_validateCell(e,t,n){const l=this;if(l._errorOverlay&&(l._errorOverlay.remove(),l._errorMessage&&l._errorMessage.remove(),l._isUpdating=!1),e.column.validationRules||n||e.column.editor&&e.column.editor.onValidate){let o={},a=e._updating;if(e._updating=!0,e.error="",n){for(let i in n)n[i]&&"valid"!==i&&(e.error=n.message),"custom"===i&&n[i].minLength?e.error=l.localize("invalidCellValue",{value:t,validationRule:"minLength: "+n[i].value}):"custom"===i&&n[i].maxLength&&(e.error=l.localize("invalidCellValue",{value:t,validationRule:"maxLength: "+n[i].value}));e.error&&(l._isUpdating=!0)}for(let n of e.column.validationRules){switch(n.type){case"min":o.min=i.min(t,n.value);break;case"max":o.max=i.max(t,n.value);break;case"minLength":o.minLength=i.minLength(t,n.value);break;case"maxLength":o.maxLength=i.maxLength(t,n.value);break;case"minDate":o.minDate=i.minDate(t,n.value);break;case"maxDate":o.maxDate=i.maxDate(t,n.value);break;case"required":o.required=i.required(t);break;case"requiredTrue":o.requiredTrue=i.requiredTrue(t);break;case"pattern":o.pattern=i.pattern(t,n.value);break;case"email":o.email=i.email(t);break;case"null":o.null=i.null(t)}o[n.type]&&(n.message?e.error=n.message:e.error=l.localize("invalidCellValue",{value:t,validationRule:void 0!==n.value?n.type+": "+n.value:n.type}),e._updating=a,l._isUpdating=!0,e.element&&e.element.setAttribute("error",e.error),e.row.element.setAttribute("error",""))}if(e.column.editor&&e.column.editor.onValidate){const i=e.column.editor.onValidate(t,e.row.data);"string"==typeof i&&(e.error=i,e._updating=a,l._isUpdating=!0,e.element&&e.element.setAttribute("error",e.error),e.row.element.setAttribute("error",""))}if(e._updating=a,e.error){l._errorOverlay=l._createOverlay(),l._errorOverlay.onpointerdown=function(){l.endEdit()};const t=document.createElement("div");t.innerHTML=e.error,t.classList.add("smart-grid-validation-error");const i=l.offset(e.element),n=e.element.getBoundingClientRect(),o=l.offset(l);return i.left=i.left,i.top=i.top,i.top+n.height+5-l.offsetTop>l.offsetHeight?t.style.top=i.top-n.height-o.top-5+"px":t.style.top=i.top+n.height-o.top+5+"px",t.style.left=i.left-o.left+"px",l._errorMessage=t,l.$.root.appendChild(l._errorOverlay),l.$.root.appendChild(l._errorMessage),e.editor&&e.editor.instance&&e.editor.instance.focus(),!1}l._isUpdating=!1}return!0}hideCellMessage(){const e=this;if(e._messageOverlay){e._messageOverlay.remove();for(let t in e._message)e._message[t].remove();delete e._message,delete e._messageOverlay}}showCellMessage(e,t,i){const n=this,l=n.rowById[e].getCell(t);n._messageOverlay||(n._messageOverlay=n._createOverlay(),n._messageOverlay.onpointerdown=function(){n.hideCellMessage()});const o=document.createElement("div");o.innerHTML=i,o.classList.add("smart-grid-cell-notification");const a=n.offset(l.element),r=l.element.getBoundingClientRect(),d=n.offset(n);a.left=a.left,a.top=a.top,a.top+r.height+5-n.offsetTop>n.offsetHeight?o.style.top=a.top-r.height-d.top-5+"px":o.style.top=a.top+r.height-d.top+5+"px",o.style.left=a.left+"px",n._message||(n._message=[]),n._message.push(o),n._messageOverlay.parentNode||n.$.root.appendChild(n._messageOverlay),n.$.root.appendChild(o)}_endCellEdit(e){const t=this,i=e||t.editing.editCell;if(!i||i&&!i.isEditing)return null;let n=t._getEditorValue(i),l=null;if(n&&n.error&&(i.canNotify=!1,i.element.setAttribute("error",""),i.row.element.setAttribute("error",""),i.error=!0,i.canNotify=!0,l=n.validity,n=n.value),"string"===i.column.dataType&&t.formulas&&n&&"string"==typeof n){if(i.formula!==n){const e=i.canNotify;i.canNotify=!1,n.startsWith("=")?i.formula=t._unescapeString(n):i.formula=null,i.canNotify=e}if(n.startsWith("=")&&i.formula){const e=t._formulaParser;if(e){let t=e.parse(i.formula.slice(1));n=isNaN(t)?"#VALUE!"===n?0:"#ERROR!"===n?"#ERROR!":t:t}}}const o=function(e,t){return"date"===i.column.dataType?e&&t?e.valueOf()===t.valueOf():!e&&!t:!("any"!==i.column.dataType||void 0===e||void 0===t||!Array.isArray(e)||0!==e.length||""!==t)||(!(null!=t&&""!==t||null!==e&&""!==e)||e===t)},a=function(){const e=t._getEditorId(i);t._cellEditors[e].detach(),i.row.element.removeAttribute("edit"),i.element&&(i.element.removeAttribute("editor"),i.element.removeAttribute("error")),i.row.element.removeAttribute("error"),i.isEditing=!1,i.element&&(i.element.content.innerHTML="");const l=function(){t.editing.editRow||(t.dataSource&&t.dataSource.boundHierarchy?(t.dataSource.refreshHierarchy(),t._refreshRowHierarchy(),t.refresh()):t.layout.allowCellsWrap?t.refresh():t._recycle(!1))},a=t._cellsUpdatedValues?t._cellsUpdatedValues[i.row.id+"_"+i.column.dataField]:void 0,r=void 0!==a?a:i.value,d=()=>{if(t._fireEndEdit){let e=i.value;if(t.editing.batch&&i.row&&i.column){const t=i.modifiedValue;void 0!==t&&(e=t)}t.$.fireEvent("endEdit",{id:i.row.id,dataField:i.column.dataField,row:i.row,column:i.column,cell:i,data:i.row.data,value:e}),t._fireEndEdit=!1}};if(o(n,r))t.editing.isEditing=!1,d(),t.editing.editCell=null,t.editing.editRow||(t.editing.isEditing=!1,l());else{const e=function(){t.editing.editCell=null,t.editing.editRow||(t.editing.isEditing=!1),delete t._editInfo};if(!0===t.editing.batch||t.editing.batch&&t.editing.batch.indexOf("update")>=0)e(),t._batchUpdateCell(i.row,i.column,n,i.value),l(),d();else{const o=function(){e(),i._updating=!0,t.editing.readOnlyEdit?t.onCellEditRequest&&t.onCellEditRequest(i.row.id,i.column.dataField,n,i.value,i.row.data,t):i.value=n,i._updating=!1,l(),d()};if(!t.editing.editRow&&t.dataSource&&t.dataSource.virtualDataSource){const e={};e[i.column.dataField]=n,t.updateRow(i.row.id,e,(()=>{o()}))}else o()}}return t.editing.commandColumn.visible&&!t.editing.commandColumn.width&&"cell"===t.editing.mode&&t.refresh(),t.focus(),!0};let r=t._validateCell(i,n,l);if(!r)return i.editor.instance&&!i.editor.autoOpen&&setTimeout((()=>{i.editor.instance.focus()}),50),!1;const d=t._cellsUpdatedValues?t._cellsUpdatedValues[i.row.id+"_"+i.column.dataField]:void 0,s=void 0!==d?d:i.value;if(o(n,s))return a(),!!r;if(t._setCellUndoRedo(i,s,n),t.onCellUpdate&&!t.editing.editRow){t.beginUpdate(),t.appearance.displayLoadingIndicator=!0,t._setLoadingIndicatorVisibility();const e=t._createOverlay();t.$.root.appendChild(e),t.onCellUpdate([i],[s],[n],(function(l){l?a():t.cancelEdit(),t.appearance.displayLoadingIndicator=!1,t._setLoadingIndicatorVisibility(),e.parentNode.removeChild(e),t.endUpdate(),t.onCellUpdated&&t.onCellUpdated([i.row.index],[i.row],[i.column],[i.row.data],[s],[n],t),t._onCellUpdated&&t._onCellUpdated(i.row.index,i.row,i.column,i.row.data,s,n)}),t)}else if(t.onRowUpdate){t.beginUpdate(),t.appearance.displayLoadingIndicator=!0,t._setLoadingIndicatorVisibility();const e=t._createOverlay();t.$.root.appendChild(e);const l=i.column.dataField,o=Object.assign({},i.row.data),r=Object.assign({},i.row.data);r[l]=n,t.onRowUpdate([i.row.index],[i.row],[o],[r],(function(n){n?a():t.cancelEdit(),t.appearance.displayLoadingIndicator=!1,t._setLoadingIndicatorVisibility(),e.parentNode.removeChild(e),t.endUpdate(),t.onRowUpdated&&t.onRowUpdated([i.row.index],[i.row],[i.row.data],t),t._onRowUpdated&&t._onRowUpdated(i.row.index,i.row,i.row.data)}),t)}else a();return!!r}_endRowEdit(){const e=this,t=e.editing.editRow;if(!t)return!1;let i=!0;const n=t.cells;let l={},o={};t.element.removeAttribute("error");for(let a=0;a<n.length;a++){const r=n[a];let d=e._getEditorValue(r),s=null;d&&d.error&&(r.canNotify=!1,r.element.setAttribute("error",""),r.row.element.setAttribute("error",""),r.error=!0,r.canNotify=!0,s=d.validity,d=d.value),d!==r.value&&(l[r.column.dataField]=r.value,o[r.column.dataField]=d);if(!e._validateCell(r,d,s))return i=!1,t.element.setAttribute("error",""),e._isUpdating=!0,r.editor.instance&&setTimeout((()=>{r.editor.instance.focus()}),50),!1}if(i){const i=function(){const i=e._fireEndEdit;e._fireEndEdit=!1;for(let t=0;t<n.length;t++){const i=n[t];e._endCellEdit(i)}e._fireEndEdit=i,e.onRowUpdate||null===e.onRowUpdated||e.onRowUpdated([t.index],[t],[t.data],e),e.editing.isEditing=!1,e.editing.editRow=null,e.editing.commandColumn.visible&&!e.editing.commandColumn.width?e.refresh():e._recycle(!1)};if(!0===e.editing.batch||e.editing.batch&&e.editing.batch.indexOf("update")>=0)i();else if(e.onRowUpdate){e.beginUpdate(),e.appearance.displayLoadingIndicator=!0,e._setLoadingIndicatorVisibility();const n=e._createOverlay();e.$.root.appendChild(n);const a=e.onRowHistory;e.onRowHistory=null,t.updatedDate=new Date,t.updatedBy=e.currentUser,e.storeHistory&&e._updateRowHistory(t,l,o),setTimeout((()=>{e.onRowHistory=a}),100),e.onRowUpdate([t.index],[t],[l],[o],(function(l){const o=e.onRowUpdate,a=e.onCellUpdate;e.onRowUpdate=null,e.onCellUpdate=null,l?i():e.cancelEdit(),e.onRowUpdate=o,e.onCellUpdate=a,e.appearance.displayLoadingIndicator=!1,e._setLoadingIndicatorVisibility(),n.parentNode.removeChild(n),e.endUpdate(),e.onRowUpdated&&e.onRowUpdated([t.index],[t],[t.data])}),e)}else if(e.dataSource&&e.dataSource.virtualDataSource&&e.editing.isEditing){e.beginUpdate(),e.appearance.displayLoadingIndicator=!0,e._setLoadingIndicatorVisibility();const t=e._createOverlay();e.$.root.appendChild(t);let n=Object.assign({},e.editing.editRow.data);for(let t=0;t<e.editing.editRow.cells.length;t++){const i=e.editing.editRow.cells[t];if(!i.column.allowEdit)continue;const l=e._getEditorValue(i);void 0!==l&&(n[i.column.dataField]=l)}e._editInfo={row:n},e._virtualDataRequest("update",(function(n){n?i():e.cancelEdit(),e.appearance.displayLoadingIndicator=!1,e._setLoadingIndicatorVisibility(),t.parentNode.removeChild(t),e.endUpdate()}))}else i();return!0}return e.focus(),!1}_batchDeleteRow(e){const t=this;if(t._rowsDeleted||(t._rowsDeleted=[]),t.onRowRemove){if(!1===t.onRowRemove([e.id],t))return}t._rowsDeleted.push(e.id),t._recycle(!1),t.onRowRemoved&&t.onRowRemoved([e.id],[e.data.$.index],t)}_batchAddRow(e,t){const i=this;i._rowsAdded||(i._rowsAdded=[]),i._rowsAdded.push(e.id),i.rowById[e.id]=e,e.index=i.rows.length+(i._rowsAdded?i._rowsAdded.length:0),0===t?i._nearRowsAdded.splice(0,0,e):i._farRowsAdded.push(e);i.isInitialized&&i._rowElements&&i._rowElements.length<i.rows.length+i._rowsAdded.length&&i._initializeRowElements(),i.refresh()}_batchUpdateCell(e,t,i,n){const l=this;l._cellsUpdatedValues||(l._cellsUpdatedValues=[]);!function(e,i){return"date"===t.dataType?!(!e&&i)&&(!(e&&!i)&&e.valueOf()===i.valueOf()):e===i}(i,n)?l._cellsUpdatedValues[e.id+"_"+t.dataField]=i:delete l._cellsUpdatedValues[e.id+"_"+t.dataField],l._cellsUpdatedValues.length++}_saveBatchEdit(){const e=this;for(let t in e._cellsUpdatedValues){const i=e._cellsUpdatedValues[t],n=t.substring(0,t.indexOf("_")),l=t.substring(t.indexOf("_")+1),o=e.rowById[n],a=o.getCell(l);if(e.dataSource.virtualDataSource){const t={};t[a.column.dataField]=i,o.data.$&&o.data.$.id?e.updateRow(o.data.$.id,t):(a._updating=!0,a.value=i,a._updating=!1)}else a._updating=!0,a.value=i,a._updating=!1}const t=e._rowsDeleted&&e._rowsDeleted.length>0||e._rowsAdded&&e._rowsAdded.length>0;if(t&&e.beginUpdate(),e._rowsAdded&&e._rowsAdded.length>0)for(let t in e._rowsAdded){const i=e._rowsAdded[t],n=e.rowById[i];if(n){if(e._rowsDeleted&&e._rowsDeleted.length>0){let t=!1;for(let n=0;n<e._rowsDeleted.length;n++){if(e._rowsDeleted[n].id===i){t=!0;break}}if(t)continue}e.dataSource.virtualDataSource?e.addRow(n.data,!0):e._nearRowsAdded.indexOf(n)>=0?e.rows.splice(0,0,n):e._farRowsAdded.indexOf(n)>=0&&e.rows.push(n)}}if(e._rowsDeleted&&e._rowsDeleted.length>0)for(let t=0;t<e._rowsDeleted.length;t++){const i=e._rowsDeleted[t],n=e.rowById[i];if(n)if(e.dataSource&&e.dataSource.virtualDataSource)e._editInfo={row:n.data},e._virtualDataRequest("remove",(function(t){if(t){const t=e.rows.indexOf(n);e.rows.splice(t,1),delete e.rowById[n.id]}}));else{const t=e.rows.indexOf(n);e.rows.splice(t,1)}}t&&e.endUpdate(),e._clearBatchEdit(!1),e.$.fireEvent("saveBatchEdit")}_clearBatchEdit(){const e=this;let t=!1;e._rowsAdded&&e._rowsAdded.length>0&&(t=!0),e._cellsUpdatedValues=[],e._rowsAdded=[],e._rowsDeleted=[],e._nearRowsAdded=[],e._farRowsAdded=[],t?e.refresh():e._recycle(!1),e.$.fireEvent("clearBatchEdit")}_getEditorId(e){const t=e.column._editorId?e.column._editorId:"";return e.editor!==e.column.editor?e.editor.template+"_"+e.column.dataField+"_"+e.row.id+t:e.editor.template+"_"+e.column.dataField+t}_applyCommand(e,t){const i=this;t||(t=[]);const n=function(){"function"==typeof e?e.apply(i,t):i[e]?i[e].apply(i,t):Smart[e]?Smart[e].apply(i,t):window[e]&&window[e].apply(i,t)};if(i.onCommand){t||(t=[]),t[1]||(t[1]=null);const l={name:e,command:n,details:t[0],event:t[1],handled:!1};setTimeout((()=>{i.onCommand.apply(i,[l]),l.handled||n()}),200)}else n()}_getCommandColumnCommandsTemplate(){const e=this,t=e.editing.commandColumn.dataSource,i="icon"!==e.editing.commandColumn.displayMode,n="label"!==e.editing.commandColumn.displayMode;let l="";for(let o in t){const a=t[o];let r="<div",d=!1;if("commandColumnMenu"===o)continue;d||(r+=' item="'+o+'" command="'+a.command+'" class="smart-grid-command-item">',d=!0);const s="{{messages}}"===a.label?e.localize(o):a.label;n&&i?(r+='<span class="smart-grid-icon '+a.icon+'"></span>',r+='<span class="smart-grid-label">'+s+"</span>"):n&&!i?r+='<span title="'+s+'" class="smart-grid-icon '+a.icon+'"></span>':i&&!n&&(r+='<span class="smart-grid-label">'+s+"</span>"),r+="</div>",l+=r}return l}_updateCommandColumnCommandsVisibility(e,t){const i=this,n=e.children,l=i.editing.commandColumn.dataSource;for(let e=0;e<n.length;e++){const o=n[e],a=o.getAttribute("item"),r=l[a].visible;!0===r?o.classList.remove("smart-hidden"):!1===r?o.classList.add("smart-hidden"):"auto"===r&&(!i.editing.dialog.enabled&&(i.editing.editRow===t||i.editing.editCell&&i.editing.editCell.row===t)?"commandColumnEdit"===a?o.classList.add("smart-hidden"):"commandColumnUpdate"!==a&&"commandColumnCancel"!==a||n[e].classList.remove("smart-hidden"):"commandColumnEdit"===a?o.classList.remove("smart-hidden"):"commandColumnUpdate"!==a&&"commandColumnCancel"!==a||n[e].classList.add("smart-hidden"))}}_handleEditKeyDown(e){const t=this,i=e.key,n=t.editing.commandKeys;if(!t.editing.dialog.enabled){if("cell"===t.editing.mode&&t.selection.allowCellSelection&&t.selection.enabled){const n=t.editing.editCell,l=n.column,o=n.row,a=t.columns.indexOf(l);("ArrowLeft"===i&&a>0||"ArrowRight"===i&&a<t.columns.length-1||"ArrowDown"===i&&o.visibleIndex<t.rows.length-1||"ArrowUp"===i&&o.visibleIndex>0)&&(t.editing.editKeyHandling=!0,t._keyDownHandler(e),t.editing.editKeyHandling=!1)}for(let l in n){const o=n[l],a=o.key.replace(/ /gi,"").split("|");if(("Tab"!==i||!t.editing.editRow)&&a.indexOf(i)>=0){if(t._editDownKey=i,t._applyCommand(o.command),"Enter"===i&&e){if(e.stopPropagation(),t._supressEnter)return void delete t._supressEnter;t.selection.enabled&&t.selection.allowCellSelection&&t._keyDownHandler(e)}delete t._editDownKey;break}}}}_getCustomCellEditor(e){const t=this;e.editor.selector=e.editor.template,e.editor.template="custom";const i=t._getEditorId(e);if(!t._cellEditors[i]){let n=document.createElement("div");t._applyCellEditorUserSettings(n,e),n.classList.add("smart-grid-cell-editor");const l=function(e){"keydown"!==e.type||t._handleEditKeyDown(e)},o=function(){const t=e.editor.instance.element.firstElementChild;Smart.Utilities.Core.isMobile||(e.editor.focus?setTimeout((function(){e.editor.focus.apply(e.editor.instance.element,[])}),50):setTimeout((function(){t.focus()}),50))},a=function(t){const i=e.editor.instance.element.firstElementChild;e.editor.blur?e.editor.blur.apply(e.editor.instance.element,[t]):i.blur()},r=function(t){const i=e.editor.instance.element.firstElementChild;if(!e.editor.isInitialized&&e.editor.settings&&i)for(let t in e.editor.settings)i[t]=e.editor.settings[t];if(e.editor.setValue)e.editor.setValue.apply(e.editor.instance.element,[t]);else{if(i.innerHTML.indexOf("{{")>=0){const n=i.innerHTML.replace(/{{value}}/gi,t).replace(/{{id}}/gi,e.row.id);i.innerHTML=n}i.value=t,t instanceof Date&&(i.value=t.toISOString().split("T")[0]),e.editor.instance.element.value=i.value}},d=function(){if(!e.editor.instance)return"";const t=e.editor.instance.element.firstElementChild;if(e.editor.getValue){const i=t.querySelector("input");return i&&i.blur(),e.editor.getValue.apply(e.editor.instance.element,[t.value])}const i=t.value;return e.editor.settings&&e.editor.settings.valueProperty?i?Array.isArray(i)&&i.length>0?i[0][e.editor.settings.valueProperty]:i[e.editor.settings.valueProperty]:"":i||""},s=function(){n.removeEventListener("keydown",l),e.editor.detach&&e.editor.detach.apply(n,[])},c=function(){n.addEventListener("keydown",l),e.editor.attach&&e.editor.attach.apply(n,[])};let u=null;if((e.editor.selector.startsWith("#")||e.editor.selector.startsWith("."))&&(u=document.querySelector(e.editor.selector)),u)n.appendChild(u.content.cloneNode(!0).firstElementChild);else{const i=function(e){const t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content.firstChild}(e.editor.selector);if(i){if("#text"===i.nodeName)return t._getInputCellEditor(e);n.appendChild(i)}}t._cellEditors[i]={element:n,focus:o,blur:a,getValue:d,setValue:r,attach:c,detach:s}}return t._cellEditors[i]}_getSliderCellEditor(e){const t=this,i=t._getEditorId(e),n=document.createElement("div"),l=document.createElement("input"),o=document.createElement("div"),a=document.createElement("smart-number-input");if(l.type="range",l.step="0.01",t._applyCellEditorUserSettings(n,e),"{}"===JSON.stringify(a.numberFormat)){let i={};if(e.column.cellsFormat)if(e.column.cellsFormat.indexOf("c")>=0){i={style:"currency",currency:t.messages[t.locale].calendar.currency};let n=parseInt(e.column.cellsFormat.substring(1));isNaN(n)||(i.maximumFractionDigits=n)}else if(e.column.cellsFormat.indexOf("p")>=0){i={style:"percent"};let t=parseInt(e.column.cellsFormat.substring(1));isNaN(t)||(i.maximumFractionDigits=t)}else e.column.Intl&&e.column.Intl.NumberFormat&&(i=e.column.Intl.NumberFormat);a.numberFormat=i}e.editor.min&&(l.min=a.min=e.editor.min),e.editor.max&&(l.max=a.max=e.editor.max),n.classList.add("smart-grid-cell-editor"),n.classList.add("smart-grid-slider-cell-editor"),o.classList.add("nav"),a.classList.add("smart-flex"),a.style.paddingLeft="6px",o.classList.add("smart-icon-resize-full","smart-grid-icon");const r=function(e){if("keydown"===e.type&&(t._handleEditKeyDown(e),"Backspace"!==e.key&&"Delete"!==e.key&&"Tab"!==e.key&&"Escape"!==e.key&&!e.altKey&&!e.shiftKey))return o.click(),void e.preventDefault()};o.onclick=function(){const i=document.createElement("div"),n=document.createElement("input");n.type="range";const r=e.editor.instance.element,d=document.createElement("div");d.classList.add("smart-slider-editor"),i.setAttribute("theme",t.theme),d.appendChild(n);const s=Smart.Utilities.Core.createGUID().replace(/-/gi,"");i.id="Slider"+s,r.setAttribute("aria-owns",i.id),d.classList.add("smart-grid-slider-container"),n.value=l.value,l.min&&(n.min=l.min),l.max&&(n.max=l.max),o.sliderEditorDialog=i,o.popupSlider=n,n.onchange=n.oninput=function(){a.value=parseFloat(n.value)};const c=e=>{e&&e.key&&("Enter"===e.key&&(i.parentNode.removeChild(i),l.value=parseFloat(n.value),t.endEdit()),"Escape"===e.key&&(i.parentNode.removeChild(i),t.cancelEdit()))};a.onchange=a.onkeyup=e=>{n.value=a.value,c(e)},n.onkeydown=function(e){c(e)},i.classList.add("smart-grid-slider-dialog"),i.appendChild(d),document.body.appendChild(i),i.style.top=t._offsetTop(r)+r.offsetHeight+"px",i.style.left=t._offsetLeft(r)+15+r.offsetWidth-i.offsetHeight+"px",i.style.width=r.offsetWidth+"px";const u=t._offsetLeft(t)+t.offsetWidth;t._offsetLeft(r)+i.offsetWidth>u&&(i.style.left=u-i.offsetWidth-10+"px")};let d=e.value;void 0===d&&(d=0),a.value=d,l.value=d,n.appendChild(a);const s=e=>{"Escape"===e.key&&(o.sliderEditorDialog&&o.sliderEditorDialog.parentNode.removeChild(o.sliderEditorDialog),t.cancelEdit()),"Enter"===e.key&&(o.sliderEditorDialog&&o.sliderEditorDialog.parentNode.removeChild(o.sliderEditorDialog),l.value=parseFloat(a.value),t.endEdit())};return t._cellEditors[i]={element:n,focus:function(){o.click(),Smart.Utilities.Core.isMobile||setTimeout((function(){a.focus(),t.$.scrollView.scrollTop=0}),50)},blur:function(){},setValue:function(e){l.value=void 0!==e&&""!==e?parseFloat(e):0,a.isReady&&a.setValue(e)},getValue:function(){const e=parseFloat(l.value);return o.sliderEditorDialog&&o.sliderEditorDialog.parentNode?(l.value=parseFloat(o.popupSlider.value),l.value):e},attach:function(){l.addEventListener("keydown",r),a.addEventListener("keydown",s)},detach:function(){l.removeEventListener("keydown",r),a.removeEventListener("keydown",s),o.sliderEditorDialog&&o.sliderEditorDialog.parentNode&&(l.value=o.popupSlider.value,o.sliderEditorDialog.parentNode.removeChild(o.sliderEditorDialog))}},t._cellEditors[i]}_getBeginEditKey(e){const t=this;t._beginEditKey?t._beginEditKey+=e:t._beginEditKey=e}_getTextAreaCellEditor(e){const t=this,i=t._getEditorId(e),n=t._cellEditors[i],l=document.createElement("div");let o=t.editing.dialog.enabled?document.createElement("smart-text-area"):document.createElement("textarea");o.users=t.users;let a=!1;Smart.Editor&&(o=t.editing.dialog.enabled?document.createElement("smart-editor"):document.createElement("textarea"),o.users=t.users,o.spellcheck=!1,o.editMode="blockHtml",o.style.border="none",o.style.setProperty("--smart-editor-input-min-height","100px"),o.style.setProperty("--smart-editor-default-height","250px"),a=!0);const r=document.createElement("div");"richText"===e.column.template&&(o.richText=!0,o.style.setProperty("--smart-editor-label-padding","0px")),t._applyCellEditorUserSettings(l,e),o.style.direction="",t.rightToLeft&&(o.style.direction="rtl"),e.editor.min&&(o.minLength=e.editor.min),e.editor.max&&(o.maxLength=e.editor.max),o.classList.add("smart-input"),l.classList.add("smart-grid-cell-editor"),l.classList.add("smart-grid-text-area-cell-editor"),r.classList.add("nav"),r.classList.add("smart-icon-resize-full","smart-grid-icon");const d=function(e){if(t._getBeginEditKey(e.key),"keydown"===e.type&&(t._handleEditKeyDown(e),"Backspace"!==e.key&&"Delete"!==e.key&&"Tab"!==e.key&&"Escape"!==e.key&&!e.altKey&&!e.shiftKey)){if(t.editing.dialog.enabled)return;return r.click(),void e.preventDefault()}};r.onclick=function(){if(t.editing.dialog.enabled)return;const l=document.createElement("div");l.style.paddingRight=l.style.paddingBottom="4px";let d=document.createElement("smart-text-area");if(a){if(d=document.createElement("smart-editor"),n&&n.popupTextAreaId){const e=document.querySelector("#"+n.popupTextAreaId+"_toolbar");e&&e.remove()}d.spellCheck=!1,d.users=t.users,d.compactImageDialog=!0,d.ai.key=t.ai.key,d.ai.model=t.ai.model,d.ai.url=t.ai.url,d.editMode="blockHtml",d.uploadUrl=t.uploadSettings.url,d.removeUrl=t.uploadSettings.removeUrl,d.onImageRemove=t.uploadSettings.onUploadRemove,d.whenRendered((()=>{const e=t._cellEditors[i];e&&(e.popupTextAreaId=d.id)})),d.style.setProperty("--smart-editor-padding","5px"),d.style.setProperty("--smart-editor-input-min-height","100px"),d.style.setProperty("--smart-editor-default-height","250px");const e=["bold","italic","underline","|","fontsize","fontname","alignment","|","orderedlist","unorderedlist","checklist","hyperlink","image"];t.ai.key&&e.push("ai"),e.push("|"),e.push("clearFormat"),d.toolbarItems=e,d.style.border="none",t._hasRichTextEditor=!0,t._errorOverlay=t._createOverlay(),t._errorOverlay.onpointerdown=function(){t._hasRichTextEditor=!1,t.endEdit()},d._setEditorValue(o.value,d),t.$.root.appendChild(t._errorOverlay)}const s=e.editor.instance.element,c=document.createElement("div"),u=document.createElement("div");t._resizeHandling=!1,u.classList.add("smart-grid-text-area-resizer","show","smart-icon-resize-full","smart-grid-icon"),u.title=t.localize("expandCell");let m=s.offsetHeight+20;t._resizable(l,d,"bottom-right",s.offsetWidth,m),u.onpointerdown=e=>{if(u.hasAttribute("expanded"))return void t.endEdit();d.sortable=!0,d.style.setProperty("--smart-editor-padding","15px"),u.setAttribute("expanded",""),u.classList.add("smart-grid-text-area-resizer","show","smart-icon-close","smart-grid-icon");const i=t.offset(t);l.style.top=i.top+40+"px",l.style.left=i.left+40+"px",l.style.width=t.offsetWidth-80+"px",l.style.height=t.offsetHeight-80+"px";const n=window.innerWidth,o=window.innerHeight;o<t.offsetHeight&&(l.style.height=o-80+"px"),n<t.offsetWidth&&(l.style.width=n-80+"px");const a=["bold","italic","underline","strikethrough","subscript","superscript","outdent","indent","|","fontsize","fontname","formats","fontcolor","backgroundcolor","alignment","|","orderedlist","unorderedlist","checklist","hyperlink","image","file","table","video","print"];t.ai.key&&a.push("ai"),a.push("|"),a.push("undo"),a.push("redo"),a.push("|"),a.push("sourceCode"),a.push("clearFormat"),a.push("delete"),d.style.height=t.offsetHeight-80+"px",d.toolbarItems=a,d.style.width=l.offsetWidth+"px",l.resizeMode="none",document.body.style.cursor="",d.recycle&&d.recycle(),e.preventDefault(),e.stopPropagation()},"richText"===e.column.template&&(d.richText=!0,d.toolbarOnFocus=!0),d.users=t.users,s.offsetHeight>180&&(d.style.height=s.offsetHeight+20+"px"),l.appendChild(u),r.textAreaEditorDialog&&r.textAreaEditorDialog.parentNode&&r.textAreaEditorDialog.parentNode.contains(r.textAreaEditorDialog)&&(r.textAreaEditorDialog.parentNode.removeChild(r.textAreaEditorDialog),r.textAreaEditorDialog.menu&&r.textAreaEditorDialog.menu.remove()),l.id="TextArea"+i,s.setAttribute("aria-owns",l.id),t.rightToLeft&&(d.style.direction="rtl"),l.setAttribute("theme",t.theme),c.appendChild(d),c.classList.add("smart-grid-text-area-container"),d.value=o.value,d.classList.add("smart-input"),o.minLength>=0&&(d.minLength=o.minLength),o.maxLength>=0&&(d.maxLength=o.maxLength),r.textAreaEditorDialog=l,r.popupTextArea=d,d.onkeydown=function(e){if(d._key=e.key,t._getBeginEditKey(e.key),"Escape"===e.key){try{l.parentNode.contains(l)&&(l.parentNode.removeChild(l),l.menu&&l.menu.remove())}catch(e){l.error=e}t.editing.editCell&&t.cancelEdit()}if("Tab"===e.key||"Enter"===e.key&&e.shiftKey){if(o.value=d.value,t.editing.editCell?t.endEdit():d.blur(),"Tab"===e.key)return void t._keyDownHandler(e);e.preventDefault(),e.stopPropagation()}},l.classList.add("smart-grid-text-area-dialog"),l.appendChild(c),document.body.appendChild(l);const g=t._offsetTop(s);if(l.style.top=g+"px",l.style.left=t._offsetLeft(s)+"px",l.style.width=Math.max(320,s.offsetWidth)+"px",g+c.offsetHeight>window.innerHeight&&(l.style.top=s.offsetHeight+g-l.offsetHeight+"px"),t.grouping.enabled&&e.column._treeColumn){const e=s.parentNode.parentNode;l.style.top=t._offsetTop(e)+"px",l.style.left=t._offsetLeft(e)+"px",l.style.width=e.offsetWidth+"px"}t._beginEditKey&&!Smart.Utilities.Core.isMobile?d.focus():setTimeout((function(){Smart.Utilities.Core.isMobile||d.select()}),50),d.onblur=()=>{if(!t._dialogTextArea||t._dialogTextArea.classList.contains("smart-hidden")){"Escape"!==d._key&&(o.value=r.popupTextArea.value),o.focus();try{r.textAreaEditorDialog.parentNode&&(r.textAreaEditorDialog.parentNode.removeChild(r.textAreaEditorDialog),r.textAreaEditorDialog.menu&&r.textAreaEditorDialog.menu.remove())}catch(e){r.error=e}}}},l.appendChild(o);return t._cellEditors[i]={element:l,focus:function(){r.click()},blur:function(){},setValue:function(i){i&&(""+i).indexOf("&#")>=0&&(i=t._fromHTMLEntities(i)),"richText"!==e.column.template&&"string"==typeof i&&(i=i.replaceAll("<br/>","\n\r").replaceAll("<br>","\n\r")),null===i&&(i="");const n=t._unescapeString(i);o.value=n,r.popupTextArea&&(r.popupTextArea.value=o.value,r.popupTextArea.dispatchEvent(new Event("input")),r.popupTextArea.focus())},getValue:function(){let i=o.value;return t._resizeHandling=!0,"Smart-TEXT-AREA"===o.nodeName&&"richText"===e.column.template&&(i=o.getHTML()),r.textAreaEditorDialog&&r.textAreaEditorDialog.parentNode?(o.value=r.popupTextArea.value,r.popupTextArea.richText?r.popupTextArea.getHTML():o.value):i},attach:function(){o.addEventListener("keydown",d)},detach:function(){if(o.removeEventListener("keydown",d),n&&n.popupTextAreaId){const e=document.querySelector("#"+n.popupTextAreaId+"_toolbar");e&&e.remove()}if(setTimeout((()=>{const e=document.querySelector(".smart-editor-toolbar[popup]");e&&e.remove()}),100),r.textAreaEditorDialog&&r.textAreaEditorDialog.parentNode){o.value=r.popupTextArea.value;try{r.textAreaEditorDialog.parentNode&&r.textAreaEditorDialog.parentNode.removeChild(r.textAreaEditorDialog),r.textAreaEditorDialog.menu&&r.textAreaEditorDialog.menu.remove(),r.popupTextArea&&r.popupTextArea.remove();const e=document.querySelector(".smart-grid-textarea-dialog");e&&e.close()}catch(e){r.error=e}}else r.popupTextArea&&r.popupTextArea.remove()}},t._cellEditors[i]}_getGridCellEditor(e){const t=this,i=t._getEditorId(e);if(!t._cellEditors[i]){const n=document.createElement("div"),l=document.createElement("smart-grid");l.users=t.users;const o=document.createElement("div");if(o.setAttribute("theme",t.theme),o.classList.add("smart-grid-cell-drop-down-menu","smart-input-drop-down-menu"),o.style.width="550px",o.style.height="350px",document.body.appendChild(o),l.sorting.enabled=l.filtering.enabled=l.selection.enabled=!0,l.style.width=l.style.height="100%",l.selection.mode="one",l.appearance.showColumnLines=!1,l.layout.rowMinHeight=45,l.appearance.showRowHeader=!0,l.appearance.allowHover=!0,l.behavior.columnResizeMode=l.behavior.rowResizeMode="growAndShrink",l.selection.allowRowHeaderSelection=!0,e.column.relationId&&e.column.relationField){const i=t._getRelationData(e.column.relationId,e.column.relationField,e.column.relationCascadingFields),n=t._getRelationColumns(e.column.relationId);l.columns=n,l.dataSource=i}else t._applyCellEditorUserSettings(l,e);o.appendChild(l),n.classList.add("smart-grid-cell-editor");const a=document.createElement("div");a.innerHTML='<span class="smart-flex middle center smart-truncate">'+e.value+"</span>";const r=document.createElement("span");r.classList.add("smart-arrow-down","arrowbtn");const d=document.createElement("div");d.classList.add("smart-multi-combo-input-container","tokens","smart-flex","smart-flex-auto"),a.classList.add("smart-flex-auto","smart-flex","middle","center","smart-multi-combo-input"),a.style.justifyContent="space-between",a.style.alignItems="center",a.style.width="100%",r.style.width="30px",d.appendChild(a),d.appendChild(r),n.appendChild(d);const s=e=>{const t=this._offsetTop(n),i=this._offsetLeft(n);o.setAttribute("open","");const a=n.closest("smart-grid-cell");a&&a.setAttribute("focus","");const r=window.scrollX,d=window.scrollY;if(o.style.left=-3+i+r+"px",o.removeAttribute("top"),o.style.top=t+n.offsetHeight+d+1+"px",window.innerHeight<parseInt(o.style.top)+o.offsetHeight-d?(o.style.top=t-o.offsetHeight+d+1+"px",o.setAttribute("top","")):o.style.top=t+n.offsetHeight+d+1+"px",l._firstSelect=!0,void 0!==e)l.selectRow(e);else if(a&&a.cell){const e=a.cell.value;l.rowById[e]&&l.selectRow(e)}l._firstSelect=!1};d.onpointerdown=r.onpointerdown=e=>{o.hasAttribute("open")?o.removeAttribute("open"):s(),e.stopPropagation(),e.preventDefault()},n.open=()=>{s()};const c=n.close=()=>{o.removeAttribute("open"),l.clearSelection()},u=t=>{if(e.column.templateSettings&&t){const i=e.column.templateSettings.dataFields;let n="";if(i)for(let e=0;e<i.length;e++){const l=t[i[e]];l&&(n+='<span class="smart-truncate smart-token smart-flex middle center ">'+l+"</span>")}a.innerHTML=n}else a.innerHTML='<span class="smart-flex middle center smart-truncate"></span>'};l.onRowSelect=e=>{if(l._firstSelect)return;o.removeAttribute("open");const t=e.data;u(t)};const m=function(){const i=l.getSelectedRows();if(i.length){const l=i[0][0],o=e.column._computedFields;if(o)for(let e=0;e<o.length;e++){const l=o[e],a=t.columnByDataField[l],r=i[0][1],d=n.closest("smart-grid-cell").cell,s=r[a.cascadingDataField];requestAnimationFrame((()=>{t.setCellValue(d.row.id,a.dataField,s),t.flashCell(d.row.id,a.dataField)}))}return l}return""},g=function(e){e&&(""+e).indexOf("&#")>=0&&(e=t._fromHTMLEntities(e)),null===e&&(e="");t._unescapeString(e);if(void 0!==e){if(!l.rowById)return;const t=l.rowById[e];t?u(t.data):u()}},p=function(){Smart.Utilities.Core.isMobile},f=function(){},h=function(){document.body.appendChild(o)},w=function(){c(),setTimeout((()=>{!o.hasAttribute("open")&&o.parentNode&&(o.style.left="-1000px",o.style.top="-1000px")}),200)};t._cellEditors[i]={element:n,focus:p,blur:f,setValue:g,getValue:m,attach:h,detach:w}}if(e.column.relationId&&e.column.relationField){const n=t._getRelationData(e.column.relationId,e.column.relationField,e.column.relationCascadingFields),l=t._getRelationColumns(e.column.relationId);t._cellEditors[i].element.columns=l,t._cellEditors[i].element.dataSource=n,e.column.editor.columns=l,e.column.editor.dataSource=n}return t._cellEditors[i]}_getColorInputCellEditor(e){const t=this,i=t._getEditorId(e);if(!t._cellEditors[i]){const n=t._getColorInput();t._applyCellEditorUserSettings(n,e),n.classList.add("smart-grid-cell-editor"),n.classList.add("smart-grid-color-input-cell-editor"),n.dropDownWidth=90,n.autocomplete="off",n.style.direction="",t.rightToLeft&&(n.rightToLeft=!0);const l=function(e){"keydown"!==e.type||t._handleEditKeyDown(e)},o=function(){Smart.Utilities.Core.isMobile||setTimeout((function(){n.select()}),50)},a=function(){},r=function(e){null==e&&(e=""),n.value=e},d=function(){return n.value},s=function(){n.removeEventListener("keydown",l)},c=function(){n.addEventListener("keydown",l)};t._cellEditors[i]={element:n,focus:o,blur:a,getValue:d,setValue:r,attach:c,detach:s}}return t._cellEditors[i]}_getInputCellEditor(e){const t=this,i=t._getEditorId(e);if(!t._cellEditors[i]){const n=document.createElement("input");t._applyCellEditorUserSettings(n,e),e.editor.min&&(n.minLength=e.editor.min),e.editor.max&&(n.maxLength=e.editor.max),n.classList.add("smart-input"),n.classList.add("smart-grid-cell-editor"),n.classList.add("smart-grid-input-cell-editor"),n.autocomplete="off",n.style.direction="",t.rightToLeft&&(n.style.direction="rtl");const l=function(i){let l=i.key;if(t._getBeginEditKey(i.key),"keydown"!==i.type);else{if(!("number"!==e.column.dataType&&"int"!==e.column.dataType&&"float"!==e.column.dataType||t.editing.editColumn||i.key.match(/[0-9]/)||"-"===i.key||1!==i.key.length))return i.preventDefault(),void i.stopPropagation();if("ArrowLeft"===l&&0!==n.selectionStart)return;if("ArrowRight"===l&&n.selectionStart<n.value.length)return;t._handleEditKeyDown(i)}},o=function(){Smart.Utilities.Core.isMobile||(t._beginEditKey?n.focus():setTimeout((function(){n.select()}),50))},a=function(){},r=function(i){if(e.column.rowHeaderColumn&&!i)return void(n.value=e.editor.row.visibleIndex+1);if("number"===e.column.dataType||"int"===e.column.dataType||"float"===e.column.dataType){if(""===i)return;if(i&&!i.toString().match(/[0-9]/)&&"-"!==i)return}i&&(""+i).indexOf("&#")>=0&&(i=t._fromHTMLEntities(i));const l=t._unescapeString(i);n.value=l},d=function(){return n.value},s=function(){n.removeEventListener("keydown",l)},c=function(){n.addEventListener("keydown",l)};t._cellEditors[i]={element:n,focus:o,blur:a,getValue:d,setValue:r,attach:c,detach:s}}return t._cellEditors[i]}_applyCellEditorUserSettings(e,t){for(let i in t.editor)"template"!==i&&("list"!==i?"onInit"!==i&&"onRender"!==i&&(e[i]=t.editor[i]):e.setAttribute(i,t.editor[i]));if(t.editor.settings)for(let i in t.editor.settings)e[i]=t.editor.settings[i]}_getCheckInputCellEditor(e){return this._getAutoCompleteCellEditor(e,"smart-check-input")}_getMultiInputCellEditor(e){return this._getAutoCompleteCellEditor(e,"smart-multi-input")}_getMultiComboInputCellEditor(e){const t=this._getAutoCompleteCellEditor(e,"smart-multi-combo-input");return"tags"!==e.column.template&&"collaborator"!==e.column.template||(t.getValue=()=>{const e=t.element.selectedItems;if(e&&0===e.length)return"";let i=[];for(let t=0;t<e.length;t++){const n=e[t];"string"==typeof n?i.push(n):i.push(n.value)}return i.toString()},t.setValue=e=>{if(null===e&&(e=""),"number"==typeof e&&(e=""+e),e&&e.indexOf("{")>=0||e&&e.indexOf("[")>=0)t.element.selectedItems=JSON.parse(e);else if(e&&e.indexOf(",")>=0)if(e=e.split(",").map((e=>e.trim())),t.element.readonly){let i=[];t.element.dataSource.forEach((t=>{for(let n=0;n<e.length;n++){const l=e[n];("string"==typeof t&&""+t===l||t&&void 0!==t.label&&""+t.value===l)&&i.push(t)}})),t.element.selectedItems=i}else t.element.selectedItems=e;else if(t.element.readonly){let i=[];t.element.dataSource.forEach((t=>{("string"==typeof t&&""+t===e||t&&void 0!==t.label&&""+t.value===e)&&i.push(t)})),e&&0===i.length&&t.element.allowItemsAdd&&i.push(e),t.element.selectedItems=i}else t.element.value=e},t.focus=function(){if(Smart.Utilities.Core.isMobile)return;const e=t.element;setTimeout((()=>{t.element.readonly?t.element.focus():e&&e.select&&e.select()}),50)}),t}_getAutoCompleteCellEditor(e,t){const i=this,n=i._getEditorId(e);if(i._cellEditors[n]&&e.column.editor.isDirty&&(delete e.column.editor.isDirty,delete i._cellEditors[n]),!i._cellEditors[n]){let l=document.createElement("smart-input");t&&(l=document.createElement(t)),l.dropDownPlaceholder=i.localize("noOptions"),i._applyCellEditorUserSettings(l,e),l.readonly&&(l.dropDownButtonPosition="right"),l.dropDownOpenPosition="auto";const o=function(e){if(l.opened)return;const t=e.key;if("keydown"!==e.type);else{if("ArrowLeft"===t&&l.$.input&&0!==l.$.input.selectionStart)return;if("ArrowRight"===t&&l.$.input&&l.$.input.selectionStart<l.$.input.value.length)return;i._handleEditKeyDown(e)}};l.rightToLeft=i.rightToLeft,l.classList.add("smart-grid-cell-editor"),l.classList.add("smart-grid-auto-complete-cell-editor"),l.dropDownOpenPosition="auto";const a=function(){Smart.Utilities.Core.isMobile||setTimeout((()=>{l&&l.select&&l.select()}),50)},r=function(e){e&&1===e.length&&l.readonly||(l.value=null!==e?e:"")},d=function(){if(e.column.dataField!==e.column.displayField){const e=l.selectedValues[0];return{label:l.value,value:e}}return l.value},s=function(){l&&l.close&&(l.value="",l.close(),l.removeEventListener("keydown",o))},c=function(){},u=function(){l.addEventListener("keydown",o)};i._cellEditors[n]={element:l,focus:a,blur:c,setValue:r,getValue:d,attach:u,detach:s}}if(!e.editor.isInitialized&&e.editor.dataSource&&(e.editor.dataSource.length<=7?i._cellEditors[n].element.dropDownHeight="auto":i._cellEditors[n].element.dropDownHeight=200),e.editor.allowItemsAdd&&e.editor.dataSource&&(e.editor.dataSource.length<=12?i._cellEditors[n].element.dropDownHeight="auto":i._cellEditors[n].element.dropDownHeight=200,i._cellEditors[n].element.onAdd=()=>{i.onColumnUpdated&&i.onColumnUpdated(i.columns.indexOf(e.column),e.column)}),e.editor.dataSource||e.editor.isInitialized){if(e.column.editor.collaborator){let t=[];for(let e=0;e<i.users.length;e++)t.push({color:i.users[e].color,label:i.users[e].name,id:i.users[e].id,value:i.users[e].id,name:i.users[e].name,image:i.users[e].image});if(e.column.editor.singleSelect&&(t=[""].concat(t)),t&&i._cellEditors[n]&&i._cellEditors[n].element&&i._cellEditors[n].element.dataSource&&JSON.stringify(t)!==JSON.stringify(i._cellEditors[n].element.dataSource)){i._cellEditors[n].element.dropDownHeight="auto";const l=i._cellEditors[n].element.dataSource;if(l)for(let e=0;e<t.length;e++){const i=t[e],n=l.find((e=>{if(e.id===i.id)return e}));n&&"object"==typeof i&&(i.color=n.color)}i._cellEditors[n].element.dataSource=t,e.column.editor.dataSource=t}}}else{const t=i.getVisibleRows(),l=[],o=[];for(let n=0;n<t.length;n++){let a=i.dataSource[t[n].index];if(a){if(e.column.displayField!==e.column.dataField){const t=a[e.column.displayField],i=a[e.column.dataField];-1===o.indexOf(t)&&(l.push({label:t,value:i}),o.push(t));continue}if(a=a[e.column.dataField],!a)continue;-1===l.indexOf(a)&&l.push(a)}}l.length<=7?i._cellEditors[n].element.dropDownHeight="auto":i._cellEditors[n].element.dropDownHeight=200,i._cellEditors[n].element.dataSource=l}return i._cellEditors[n]}_getDateRangeInputCellEditor(e){const t=this,i=t._getEditorId(e);if(!t._cellEditors[i]){const n=document.createElement("smart-date-range-input");n.dropDownButtonPosition="right",n.dropDownAppendTo="body",n.autoClose=!0,n.selectionMode="default",n.rightToLeft=t.rightToLeft,n.timepicker=!0,n.dropDownOpenPosition="auto",t._applyCellEditorUserSettings(n,e);const l=function(e){let i=e.key;if(!n.opened)if("keydown"!==e.type);else{if("ArrowLeft"===i&&n.$.input&&0!==n.$.input.selectionStart)return;if("ArrowRight"===i&&n.$.input&&n.$.input.selectionStart<n.$.input.value.length)return;t._handleEditKeyDown(e)}};n.classList.add("smart-grid-cell-editor"),n.classList.add("smart-grid-date-time-picker-cell-editor");const o=function(){Smart.Utilities.Core.isMobile||setTimeout((()=>{n.select()}),50)},a=function(e){n.value=e,n.selectedDates=[]},r=function(){return n._performSelect(),n.selectedDates},d=function(){n.value="",n.close(),n.removeEventListener("keydown",l)},s=function(e){const i=n.getAttribute("aria-controls");if(i&&n.opened){const n=t.getBoundingRect(document.getElementById(i));e.pageX<n.left||e.pageX>n.right||e.pageY<n.top||e.pageY>n.bottom||e.preventDefault()}},c=function(){n.addEventListener("keydown",l)};t._cellEditors[i]={element:n,focus:o,blur:s,setValue:a,getValue:r,attach:c,detach:d}}return t._cellEditors[i]}_getDateTimePickerCellEditor(e){const t=this,i=t._getEditorId(e);if(!t._cellEditors[i]){const n=document.createElement("smart-date-time-picker");n.calendarButton=!0,n.dropDownAppendTo="body",n.autoClose=!0,n.dropDownDisplayMode="calendar",n.rightToLeft=t.rightToLeft,n.nullable=!0,e.column.cellsFormat&&(n.formatString=e.column.cellsFormat),t._applyCellEditorUserSettings