@toolbox-web/grid 1.25.2 → 1.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/keyboard"),require("../../core/plugin/base-plugin"),require("../../core/internal/diagnostics")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/keyboard","../../core/plugin/base-plugin","../../core/internal/diagnostics"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid,t.TbwGrid)}(this,function(t,e,i,n){"use strict";function r(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}const s="__tbw_null__";function o(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return r(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?s:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===s?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function d(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class l{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=new Map,this.#t.set(t,n)),n.set(e,i),this.#e(t,e,!0)}clearInvalid(t,e){const i=this.#t.get(t);i&&(i.delete(e),0===i.size&&this.#t.delete(t)),this.#e(t,e,!1)}clearRowInvalid(t){const e=this.#t.get(t);if(e){const i=Array.from(e.keys());this.#t.delete(t),i.forEach(e=>this.#e(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#t.entries());this.#t.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#e(t,i,!1))})}isCellInvalid(t,e){return this.#t.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#t.get(t)?.get(e)}hasInvalidCells(t){const e=this.#t.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#t.get(t)??[])}}function a(t,e,i){const n=t.get(e);return!!n&&!c(n,i)}function c(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!c(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!c(i[t],n[t]))return!1;return!0}return!1}function u(t,e,i){t.set(e,structuredClone(i))}function h(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class g{baselines=new Map;baselinesWereCaptured=!1;newRowIds=new Set;changedRowIds=new Set;committedDirtyRowIds=new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return a(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&a(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!c(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&a(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){u(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&u(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&a(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&a(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=h(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&h(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const f='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function w(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function m(t){}function v(t,e){return!1===t.onBeforeEditClose?.(e)}function p(t,e,i,r,s,l,a){if(!r.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:g,editorValueCallbacks:p}=t;let y;try{y=c.getRowId?.(e)}catch{}const E=y?t=>c.updateRow(y,t,"cascade"):m,R=w(r.field)?e[r.field]:void 0;l.classList.add("editing"),g.add(`${i}:${s}`);const b=l.parentElement;b&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(b);let I=!1;const C=n=>{if(I||!u&&!t.isEditSessionActive())return;const s=y?c._getRowEntry(y):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,r,n,o)},k=()=>{if(I=!0,w(r.field)){const t=y?c._getRowEntry(y):void 0;(t?.row??e)[r.field]=R}},x=document.createElement("div");x.className="tbw-editor-host",l.innerHTML="",l.appendChild(x),x.addEventListener("keydown",e=>{if("Enter"===e.key){if(u){e.stopPropagation(),e.preventDefault();const t=x.querySelector("input,textarea,select");return void(t&&C(d(t,r,R)))}if(v(h,e))return;e.stopPropagation(),e.preventDefault(),I=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(u)return e.stopPropagation(),void e.preventDefault();if(v(h,e))return;e.stopPropagation(),e.preventDefault(),k(),t.exitRowEdit(i,!0)}});const _=r,M=_.__editorTemplate,S=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(c,_)??o(r),A=R,D=`${i}:${r.field}`,L=[];p.set(D,t=>{for(const e of L)e(t)});const G=t=>{L.push(t)};if("template"===S&&M)!function(t,e,i,n,r,s,o,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:o}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!w(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(d(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(d(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,x,_,e,R,C,k,a,i),G(t=>{const e=x.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof S){const t=document.createElement(S);t.value=A,t.addEventListener("change",()=>C(t.value)),G(e=>{t.value=e}),x.appendChild(t),a||queueMicrotask(()=>{const t=x.querySelector(f);t?.focus({preventScroll:!0})})}else if("function"==typeof S){const t=S({row:e,rowId:y??"",value:A,field:r.field,column:r,commit:C,cancel:k,updateRow:E,onValueChange:G});if("string"==typeof t)x.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(d(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(d(r,e,n))))}(x,r,C,R),G(t=>{const e=x.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){x.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?G(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):l.setAttribute("data-editor-managed","")}else!t&&x.hasChildNodes()&&l.setAttribute("data-editor-managed","");a||queueMicrotask(()=>{const t=x.querySelector(f);t?.focus({preventScroll:!0})})}else if(S&&"object"==typeof S){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",r.field),x.appendChild(i),l.setAttribute("data-editor-managed","");const s={row:e,rowId:y??"",value:A,field:r.field,column:r,commit:C,cancel:k,updateRow:E,onValueChange:G};if(S.mount)try{S.mount({placeholder:i,context:s,spec:S})}catch(T){n.warnDiagnostic(n.EDITOR_MOUNT_ERROR,`External editor mount error for column '${r.field}': ${T}`,t.grid.id)}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:S,context:s}}))}}class y extends i.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n=-1;#r;#s;#o=-1;#d=new Map;#l=new Set;#a=new Map;#c=!1;#u=-1;#h;#g=!1;#f=!1;#w=!1;#m=null;#v=new g;#p;get#y(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#y;if(this.#h=new l((t,e,i)=>{this.#E(t,e,i)}),this.#p={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#l,editorValueCallbacks:this.#a,isEditSessionActive:()=>-1!==this.#n,commitCellValue:(t,e,i,n)=>this.#R(t,e,i,n),exitRowEdit:(t,e)=>this.#b(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#v.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#n){if(v(this.config,t))return;this.#b(this.#n,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#n)return;const e=i.findRenderedRowElement?.(this.#n);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||v(this.config,t)||queueMicrotask(()=>{-1!==this.#n&&this.#b(this.#n,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#n)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#n&&this.#I()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#a.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#v.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#v.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(f)){if(this.#f)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#m;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#m={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#g=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(f)||(this.#g=!1,this.#m=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#g){if(v(this.config,t))return void queueMicrotask(()=>{if(this.#g){this.#C();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0}});this.#C();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(f)&&(this.#f=!1)},{signal:e}))}detach(){this.#y._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#d.clear(),this.#v.clear(),this.#l.clear(),this.#a.clear(),this.#g=!1,this.#f=!1,this.#m=null,this.#w=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#n}onCellClick(t){if(this.#i)return!1;const e=this.#y,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(t){const i=this.#y;if("Escape"===t.key){if(this.#i&&this.#g){this.#C();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,this.requestAfterRender(),!0}if(-1!==this.#n&&!this.#i)return v(this.config,t)||this.#b(this.#n,!0),!0}if(this.#i&&!this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#n&&!this.#i){if(v(this.config,t))return!0;const n=i._rows.length-1,r=this.#n;return this.#b(r,!1),"ArrowDown"===t.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),t.preventDefault(),e.ensureCellVisible(i),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#n||this.#i)){if(t.preventDefault(),this.#w)return this.#b(this.#n,!1),!0;const e=!t.shiftKey;return this.#k(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#n)return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[e];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(w(i)){const n=!s[i];return this.#R(e,r,n,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#i&&!this.#g)return this.#I(),!0;if(-1!==this.#n)return!!v(this.config,t);const e=this.config.editOn??i.effectiveConfig?.editOn;if(!1===e||"manual"===e)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const e=i._columns?.some(t=>t.editable);if(e){const e=i._visibleColumns[r],s=i._rows[n],o=e?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:t}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===t.key){if(-1!==this.#n||this.#i)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return t.preventDefault(),this.beginCellEdit(e,r.field),!0}return!1}return!1}processColumns(t){const e=this.#y,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.#y;if(this.config.dirtyTracking&&e.getRowId&&this.#v.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#n||this.#i)return t;const i=this.#r,n=this.#s;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#n!==s&&this.#x(this.#n,s),r)}afterRender(){const t=this.#y;if(-1!==this.#n&&this.#s&&!this.#i&&t._rows[this.#n]!==this.#s){const e=t._rows.indexOf(this.#s);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#x(this.#n,e)}if(this.#c&&(this.#c=!1,this.#_(t)),-1!==this.#u){const e=this.#u;this.#u=-1,t.animateRow?.(e,"change")}const e=this.#v.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#l.size)for(const i of this.#l){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#M(l,r,a,s,d,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable?s.removeAttribute("aria-readonly"):s.setAttribute("aria-readonly","true"),this.#i&&n.editable&&(s.classList.contains("editing")||this.#M(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#y,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#v.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#v.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#v.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#v.getChangedRowIds()}get activeEditRow(){return this.#n}get activeEditCol(){return this.#o}isRowEditing(t){return this.#n===t}isCellEditing(t,e){return this.#l.has(`${t}:${e}`)}isRowChanged(t){const e=this.#y,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#v.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#v.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#v.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#v.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#y;return this.#v.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#v.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#y;this.#v.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#v.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#v.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#y;return this.#v.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#y;return this.#v.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#v.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#y;this.#v.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#h.setInvalid(t,e,i)}clearInvalid(t,e){this.#h.clearInvalid(t,e)}clearRowInvalid(t){this.#h.clearRowInvalid(t)}clearAllInvalid(){this.#h.clearAllInvalid()}isCellInvalid(t,e){return this.#h.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#h.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#h.hasInvalidCells(t)}getInvalidFields(t){return this.#h.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#v.changedRowIds.clear(),this.#v.committedDirtyRowIds.clear(),this.#S(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.#y;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#y,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#w=!0,this.#A(t,n,o))}beginBulkEdit(t){const e=this.#y;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#w=!1;const r=e._rows[t];this.#D(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#M(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(f);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#n&&this.#b(this.#n,!1)}cancelActiveRowEdit(){-1!==this.#n&&this.#b(this.#n,!0)}#E(t,e,i){const n=this.#y,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#h.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#x(t,e){this.#n=e;const i=new Set,n=`${t}:`;for(const o of this.#l)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#l.clear();for(const o of i)this.#l.add(o);const r=this.#d.get(t);void 0!==r&&(this.#d.delete(t),this.#d.set(e,r));const s=[];for(const[o,d]of this.#a)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#a.delete(o));for(const[o,d]of s)this.#a.set(o,d);this.#S()}#A(t,e,i){const n=this.#y,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#n!==t&&this.#D(t,r),this.#o=e,this.#M(r,t,s,e,i,!1)))}#C(){const t=this.#m;if(!t)return;const e=this.#y,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#a.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#m=null}#I(){const t=this.#y,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(f);t&&(this.#f=!1,t.focus(),this.#g=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#k(t){const i=this.#y,n=i._rows,r=this.#i?i._focusRow:this.#n,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(t?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const t=i.findRenderedRowElement?.(r),n=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(f);t?.focus({preventScroll:!0})}return void e.ensureCellVisible(i,{forceHorizontalScroll:!0})}const d=r+(t?1:-1);d>=0&&d<n.length&&(this.#i?(i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],e.ensureCellVisible(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(f);t?.focus({preventScroll:!0})}},0)):(this.#b(r,!1),i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(d),e.ensureCellVisible(i,{forceHorizontalScroll:!0})))}#S(){const t=this.#y;t._activeEditRows=this.#n,t._rowEditSnapshots=this.#d}#D(t,e){if(this.#n!==t){-1!==this.#n&&this.#b(this.#n,!1),this.#d.set(t,{...e}),this.#n=t,this.#s=e;const i=this.#y;try{this.#r=i.getRowId?.(e)??void 0}catch{this.#r=void 0}this.#S(),this.#i||this.emit("edit-open",{rowIndex:t,rowId:this.#r??"",row:e})}}#b(t,e){if(this.#n!==t)return;const i=this.#y,n=this.#d.get(t),r=i.findRenderedRowElement?.(t);let s=this.#r;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#s??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=d(s,r,i);i!==n&&this.#R(t,r,n,l)}})}if(e||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#v.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#v.isRowDirty(s,l)?this.#v.committedDirtyRowIds.add(s):this.#v.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#u=t))}this.#d.delete(t),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#w=!1,this.#S();for(const d of this.#l)d.startsWith(`${t}:`)&&this.#l.delete(d);for(const d of this.#a.keys())d.startsWith(`${t}:`)&&this.#a.delete(d);this.#c=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#_(i),this.#c=!1),!this.#i&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#R(t,e,i,n){const r=e.field;if(!w(r))return;const s=n[r];if(s===i)return;const o=this.#y;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#v.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):m;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#v.changedRowIds.add(d),this.#S(),this.config.dirtyTracking&&d){const t=this.#v.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#v.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#M(t,e,i,n,r,s){p(this.#p,t,e,i,n,r,s)}#_(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}t.EditingPlugin=y,t.defaultEditorFor=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/keyboard"),require("../../core/plugin/base-plugin"),require("../../core/internal/diagnostics")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/keyboard","../../core/plugin/base-plugin","../../core/internal/diagnostics"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid,t.TbwGrid)}(this,function(t,e,i,n){"use strict";function r(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}const s="__tbw_null__";function o(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return r(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?s:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===s?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function d(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class l{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=new Map,this.#t.set(t,n)),n.set(e,i),this.#e(t,e,!0)}clearInvalid(t,e){const i=this.#t.get(t);i&&(i.delete(e),0===i.size&&this.#t.delete(t)),this.#e(t,e,!1)}clearRowInvalid(t){const e=this.#t.get(t);if(e){const i=Array.from(e.keys());this.#t.delete(t),i.forEach(e=>this.#e(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#t.entries());this.#t.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#e(t,i,!1))})}isCellInvalid(t,e){return this.#t.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#t.get(t)?.get(e)}hasInvalidCells(t){const e=this.#t.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#t.get(t)??[])}}function a(t,e,i){const n=t.get(e);return!!n&&!c(n,i)}function c(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!c(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!c(i[t],n[t]))return!1;return!0}return!1}function u(t,e,i){t.set(e,structuredClone(i))}function h(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class f{baselines=new Map;baselinesWereCaptured=!1;newRowIds=new Set;changedRowIds=new Set;committedDirtyRowIds=new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return a(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&a(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!c(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&a(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){u(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&u(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&a(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&a(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=h(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&h(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const g='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function w(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function m(t){}function v(t,e){return!1===t.onBeforeEditClose?.(e)}function p(t,e,i,r,s,l,a){if(!r.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:f,editorValueCallbacks:p}=t;let y;try{y=c.getRowId?.(e)}catch{}const E=y?t=>c.updateRow(y,t,"cascade"):m,R=w(r.field)?e[r.field]:void 0;l.classList.add("editing"),f.add(`${i}:${s}`);const b=l.parentElement;b&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(b);let C=!1;const I=n=>{if(C||!u&&!t.isEditSessionActive())return;const s=y?c._getRowEntry(y):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,r,n,o)},k=()=>{if(C=!0,w(r.field)){const t=y?c._getRowEntry(y):void 0;(t?.row??e)[r.field]=R}},_=document.createElement("div");_.className="tbw-editor-host",l.innerHTML="",l.appendChild(_),_.addEventListener("keydown",e=>{if("Enter"===e.key){if(u){e.stopPropagation(),e.preventDefault();const t=_.querySelector("input,textarea,select");return void(t&&I(d(t,r,R)))}if(v(h,e))return;e.stopPropagation(),e.preventDefault(),C=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(u)return e.stopPropagation(),void e.preventDefault();if(v(h,e))return;e.stopPropagation(),e.preventDefault(),k(),t.exitRowEdit(i,!0)}});const x=r,M=x.__editorTemplate,S=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(c,x)??o(r),A=R,D=`${i}:${r.field}`,L=[];p.set(D,t=>{for(const e of L)e(t)});const G=t=>{L.push(t)};if("template"===S&&M)!function(t,e,i,n,r,s,o,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:o}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!w(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const f=u.querySelector("input,textarea,select");if(f){f instanceof HTMLInputElement&&"checkbox"===f.type?f.checked=!!r:f.value=String(r??"");let e=!1;f.addEventListener("blur",()=>{e||s(d(f,i,r))}),f.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(d(f,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(a,!0)}}),f instanceof HTMLInputElement&&"checkbox"===f.type&&f.addEventListener("change",()=>s(f.checked)),l||setTimeout(()=>f.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,_,x,e,R,I,k,a,i),G(t=>{const e=_.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof S){const t=document.createElement(S);t.value=A,t.addEventListener("change",()=>I(t.value)),G(e=>{t.value=e}),_.appendChild(t),a||queueMicrotask(()=>{const t=_.querySelector(g);t?.focus({preventScroll:!0})})}else if("function"==typeof S){const t=S({row:e,rowId:y??"",value:A,field:r.field,column:r,commit:I,cancel:k,updateRow:E,onValueChange:G});if("string"==typeof t)_.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(d(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(d(r,e,n))))}(_,r,I,R),G(t=>{const e=_.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){_.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?G(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):l.setAttribute("data-editor-managed","")}else!t&&_.hasChildNodes()&&l.setAttribute("data-editor-managed","");a||queueMicrotask(()=>{const t=_.querySelector(g);t?.focus({preventScroll:!0})})}else if(S&&"object"==typeof S){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",r.field),_.appendChild(i),l.setAttribute("data-editor-managed","");const s={row:e,rowId:y??"",value:A,field:r.field,column:r,commit:I,cancel:k,updateRow:E,onValueChange:G};if(S.mount)try{S.mount({placeholder:i,context:s,spec:S})}catch(T){n.warnDiagnostic(n.EDITOR_MOUNT_ERROR,`External editor mount error for column '${r.field}': ${T}`,t.grid.id)}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:S,context:s}}))}}class y extends i.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n(t,e){const i=this.#r.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#s(t){return!0===t.editable||"function"==typeof t.editable}#o=-1;#d;#l;#a=-1;#c=new Map;#u=new Set;#h=new Map;#f=!1;#g=-1;#w;#m=!1;#v=!1;#p=!1;#y=null;#E=new f;#R;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;if(this.#w=new l((t,e,i)=>{this.#b(t,e,i)}),this.#R={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#h,isEditSessionActive:()=>-1!==this.#o,commitCellValue:(t,e,i,n)=>this.#C(t,e,i,n),exitRowEdit:(t,e)=>this.#I(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#E.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#o){if(v(this.config,t))return;this.#I(this.#o,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#o)return;const e=i.findRenderedRowElement?.(this.#o);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||v(this.config,t)||queueMicrotask(()=>{-1!==this.#o&&this.#I(this.#o,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#o)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#o&&this.#k()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#h.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#E.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#E.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(g)){if(this.#v)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#y;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#y={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#m=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(g)||(this.#m=!1,this.#y=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#m){if(v(this.config,t))return void queueMicrotask(()=>{if(this.#m){this.#_();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#m=!1,this.#v=!0}});this.#_();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#m=!1,this.#v=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(g)&&(this.#v=!1)},{signal:e}))}detach(){this.#r._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#o=-1,this.#d=void 0,this.#l=void 0,this.#a=-1,this.#c.clear(),this.#E.clear(),this.#u.clear(),this.#h.clear(),this.#m=!1,this.#v=!1,this.#y=null,this.#p=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#o}onCellClick(t){if(this.#i)return!1;const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>this.#s(t));if(!s)return!1;const o=e._rows[r],d=e.effectiveConfig?.rowEditable;return!(o&&d&&!d(o))&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(t){const i=this.#r;if("Escape"===t.key){if(this.#i&&this.#m){this.#_();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#m=!1,this.#v=!0,this.requestAfterRender(),!0}if(-1!==this.#o&&!this.#i)return v(this.config,t)||this.#I(this.#o,!0),!0}if(this.#i&&!this.#m&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&this.#m&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#o&&!this.#i){if(v(this.config,t))return!0;const n=i._rows.length-1,r=this.#o;return this.#I(r,!1),"ArrowDown"===t.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),t.preventDefault(),e.ensureCellVisible(i),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#o||this.#i)){if(t.preventDefault(),this.#p)return this.#I(this.#o,!1),!0;const e=!t.shiftKey;return this.#x(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#o)return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[e];if(r&&s&&this.#n(r,s)&&"boolean"===r.type){const i=r.field;if(w(i)){const n=!s[i];return this.#C(e,r,n,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#i&&!this.#m)return this.#k(),!0;if(-1!==this.#o)return!!v(this.config,t);const e=this.config.editOn??i.effectiveConfig?.editOn;if(!1===e||"manual"===e)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const e=i._columns?.some(t=>this.#s(t)),s=i._rows[n],o=i.effectiveConfig?.rowEditable,d=s&&o&&!o(s);if(e&&!d){const e=i._visibleColumns[r],s=i._rows[n],o=e?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:t}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===t.key){if(-1!==this.#o||this.#i)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[e];if(r&&s&&this.#n(r,s)&&r.field)return t.preventDefault(),this.beginCellEdit(e,r.field),!0}return!1}return!1}processColumns(t){const e=this.#r,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.#r;if(this.config.dirtyTracking&&e.getRowId&&this.#E.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#o||this.#i)return t;const i=this.#d,n=this.#l;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#o!==s&&this.#M(this.#o,s),r)}afterRender(){const t=this.#r;if(-1!==this.#o&&this.#l&&!this.#i&&t._rows[this.#o]!==this.#l){const e=t._rows.indexOf(this.#l);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#M(this.#o,e)}if(this.#f&&(this.#f=!1,this.#S(t)),-1!==this.#g){const e=this.#g;this.#g=-1,t.animateRow?.(e,"change")}const e=this.#E.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#u.size)for(const i of this.#u){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#A(l,r,a,s,d,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t,o=this.#n(n,e);o?s.removeAttribute("aria-readonly"):s.setAttribute("aria-readonly","true"),this.#i&&o&&(s.classList.contains("editing")||this.#A(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#E.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#E.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#E.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#E.getChangedRowIds()}get activeEditRow(){return this.#o}get activeEditCol(){return this.#a}isRowEditing(t){return this.#o===t}isCellEditing(t,e){return this.#u.has(`${t}:${e}`)}isRowChanged(t){const e=this.#r,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#E.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#E.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#E.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#E.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#E.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#E.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#E.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#E.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#E.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#w.setInvalid(t,e,i)}clearInvalid(t,e){this.#w.clearInvalid(t,e)}clearRowInvalid(t){this.#w.clearRowInvalid(t)}clearAllInvalid(){this.#w.clearAllInvalid()}isCellInvalid(t,e){return this.#w.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#w.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#w.hasInvalidCells(t)}getInvalidFields(t){return this.#w.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#D(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.#r;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#r,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],s=i._rows[t];if(!r||!s||!this.#n(r,s))return;const o=i.findRenderedRowElement?.(t),d=o?.querySelector(`.cell[data-col="${n}"]`);d&&(this.#p=!0,this.#L(t,n,d))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>this.#s(t));if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;const r=e._rows[t],s=e.effectiveConfig?.rowEditable;r&&s&&!s(r)||(this.#p=!1,this.#G(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s&&this.#n(s,r)){const e=i;e.classList.contains("editing")||this.#A(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(g);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#o&&this.#I(this.#o,!1)}cancelActiveRowEdit(){-1!==this.#o&&this.#I(this.#o,!0)}#b(t,e,i){const n=this.#r,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#w.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#M(t,e){this.#o=e;const i=new Set,n=`${t}:`;for(const o of this.#u)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#u.clear();for(const o of i)this.#u.add(o);const r=this.#c.get(t);void 0!==r&&(this.#c.delete(t),this.#c.set(e,r));const s=[];for(const[o,d]of this.#h)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#h.delete(o));for(const[o,d]of s)this.#h.set(o,d);this.#D()}#L(t,e,i){const n=this.#r,r=n._rows[t],s=n._visibleColumns[e];r&&s&&this.#n(s,r)&&(i.classList.contains("editing")||(this.#o!==t&&this.#G(t,r),this.#a=e,this.#A(r,t,s,e,i,!1)))}#_(){const t=this.#y;if(!t)return;const e=this.#r,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#h.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#y=null}#k(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(g);t&&(this.#v=!1,t.focus(),this.#m=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#x(t){const i=this.#r,n=i._rows,r=this.#i?i._focusRow:this.#o,s=n[r],o=i._visibleColumns.map((t,e)=>s&&this.#n(t,s)?e:-1).filter(t=>t>=0);if(0===o.length)return;const d=o.indexOf(i._focusCol)+(t?1:-1);if(d>=0&&d<o.length){i._focusCol=o[d];const t=i.findRenderedRowElement?.(r),n=t?.querySelector(`.cell[data-col="${o[d]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(g);t?.focus({preventScroll:!0})}return void e.ensureCellVisible(i,{forceHorizontalScroll:!0})}const l=r+(t?1:-1);if(l>=0&&l<n.length){const s=n[l],o=i._visibleColumns.map((t,e)=>s&&this.#n(t,s)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(i._focusRow=l,i._focusCol=t?o[0]:o[o.length-1],e.ensureCellVisible(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(l),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(g);t?.focus({preventScroll:!0})}},0)):(this.#I(r,!1),i._focusRow=l,i._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),e.ensureCellVisible(i,{forceHorizontalScroll:!0}))}}#D(){const t=this.#r;t._activeEditRows=this.#o,t._rowEditSnapshots=this.#c}#G(t,e){if(this.#o!==t){-1!==this.#o&&this.#I(this.#o,!1),this.#c.set(t,{...e}),this.#o=t,this.#l=e;const i=this.#r;try{this.#d=i.getRowId?.(e)??void 0}catch{this.#d=void 0}this.#D(),this.#i||this.emit("edit-open",{rowIndex:t,rowId:this.#d??"",row:e})}}#I(t,e){if(this.#o!==t)return;const i=this.#r,n=this.#c.get(t),r=i.findRenderedRowElement?.(t);let s=this.#d;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#l??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=d(s,r,i);i!==n&&this.#C(t,r,n,l)}})}if(e||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#E.changedRowIds.delete(s),this.#E.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#E.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#E.changedRowIds.delete(s),this.#E.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#E.isRowDirty(s,l)?this.#E.committedDirtyRowIds.add(s):this.#E.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#g=t))}this.#c.delete(t),this.#o=-1,this.#d=void 0,this.#l=void 0,this.#a=-1,this.#p=!1,this.#D();for(const d of this.#u)d.startsWith(`${t}:`)&&this.#u.delete(d);for(const d of this.#h.keys())d.startsWith(`${t}:`)&&this.#h.delete(d);this.#f=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#S(i),this.#f=!1),!this.#i&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#C(t,e,i,n){const r=e.field;if(!w(r))return;const s=n[r];if(s===i)return;const o=this.#r;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#E.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):m;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#E.changedRowIds.add(d),this.#D(),this.config.dirtyTracking&&d){const t=this.#E.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#E.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#A(t,e,i,n,r,s){p(this.#R,t,e,i,n,r,s)}#S(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}t.EditingPlugin=y,t.defaultEditorFor=o,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=editing.umd.js.map