@toolbox-web/grid 3.0.0-beta → 3.0.0-beta.1

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.
Files changed (68) hide show
  1. package/all.js +2 -2
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/grid.d.ts +2 -1
  6. package/lib/core/internal/column-shorthand.d.ts +61 -0
  7. package/lib/core/internal/columns.d.ts +10 -0
  8. package/lib/core/types.d.ts +3 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/features/registry.js.map +1 -1
  11. package/lib/plugins/clipboard/index.js +1 -1
  12. package/lib/plugins/clipboard/index.js.map +1 -1
  13. package/lib/plugins/column-virtualization/index.js +1 -1
  14. package/lib/plugins/column-virtualization/index.js.map +1 -1
  15. package/lib/plugins/context-menu/index.js +1 -1
  16. package/lib/plugins/context-menu/index.js.map +1 -1
  17. package/lib/plugins/editing/index.js +1 -1
  18. package/lib/plugins/editing/index.js.map +1 -1
  19. package/lib/plugins/export/index.js +1 -1
  20. package/lib/plugins/export/index.js.map +1 -1
  21. package/lib/plugins/filtering/index.js +1 -1
  22. package/lib/plugins/filtering/index.js.map +1 -1
  23. package/lib/plugins/grouping-columns/index.js +1 -1
  24. package/lib/plugins/grouping-columns/index.js.map +1 -1
  25. package/lib/plugins/grouping-rows/index.js +1 -1
  26. package/lib/plugins/grouping-rows/index.js.map +1 -1
  27. package/lib/plugins/master-detail/index.js +1 -1
  28. package/lib/plugins/master-detail/index.js.map +1 -1
  29. package/lib/plugins/multi-sort/index.js +1 -1
  30. package/lib/plugins/multi-sort/index.js.map +1 -1
  31. package/lib/plugins/pinned-columns/index.js +1 -1
  32. package/lib/plugins/pinned-columns/index.js.map +1 -1
  33. package/lib/plugins/pinned-rows/index.js +1 -1
  34. package/lib/plugins/pinned-rows/index.js.map +1 -1
  35. package/lib/plugins/pivot/index.js +1 -1
  36. package/lib/plugins/pivot/index.js.map +1 -1
  37. package/lib/plugins/print/index.js +1 -1
  38. package/lib/plugins/print/index.js.map +1 -1
  39. package/lib/plugins/reorder-columns/index.js +1 -1
  40. package/lib/plugins/reorder-columns/index.js.map +1 -1
  41. package/lib/plugins/responsive/index.js +1 -1
  42. package/lib/plugins/responsive/index.js.map +1 -1
  43. package/lib/plugins/row-drag-drop/index.js +1 -1
  44. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  45. package/lib/plugins/selection/index.js +1 -1
  46. package/lib/plugins/selection/index.js.map +1 -1
  47. package/lib/plugins/server-side/index.js +1 -1
  48. package/lib/plugins/server-side/index.js.map +1 -1
  49. package/lib/plugins/shell/index.js +1 -1
  50. package/lib/plugins/shell/index.js.map +1 -1
  51. package/lib/plugins/sticky-rows/index.js +1 -1
  52. package/lib/plugins/sticky-rows/index.js.map +1 -1
  53. package/lib/plugins/tooltip/index.js +1 -1
  54. package/lib/plugins/tooltip/index.js.map +1 -1
  55. package/lib/plugins/tree/index.js +1 -1
  56. package/lib/plugins/tree/index.js.map +1 -1
  57. package/lib/plugins/undo-redo/index.js +1 -1
  58. package/lib/plugins/undo-redo/index.js.map +1 -1
  59. package/lib/plugins/visibility/index.js +1 -1
  60. package/lib/plugins/visibility/index.js.map +1 -1
  61. package/package.json +1 -1
  62. package/public.d.ts +2 -0
  63. package/umd/grid.all.umd.js +1 -1
  64. package/umd/grid.all.umd.js.map +1 -1
  65. package/umd/grid.umd.js +1 -1
  66. package/umd/grid.umd.js.map +1 -1
  67. package/umd/plugins/editing.umd.js +1 -1
  68. package/umd/plugins/editing.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/aria"),require("../../core/internal/keyboard"),require("../../core/internal/value-accessor"),require("../../core/plugin/base-plugin"),require("../../core/internal/diagnostics")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/aria","../../core/internal/keyboard","../../core/internal/value-accessor","../../core/plugin/base-plugin","../../core/internal/diagnostics"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid,t.TbwGrid,t.TbwGrid,t.TbwGrid)}(this,function(t,e,i,n,r,s){"use strict";function o(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 d="__tbw_null__";function l(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 o(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?d:"",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 s=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===d?e.commit(null):e.commit(n.value)};return n.addEventListener("change",s),n.addEventListener("blur",s),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 a(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 c{#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 u(t,e,i){const n=t.get(e);return!!n&&!h(n,i)}function h(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(!h(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(!h(i[t],n[t]))return!1;return!0}return!1}function f(t,e,i){t.set(e,structuredClone(i))}function g(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 w{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 u(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&&u(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&&!h(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)&&u(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){f(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&&f(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&&u(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&&u(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=g(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&&g(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 m='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function p(t){const e=t;return e?.closest?.(m)??null}function v(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function y(t){}function E(t,e){return!1===t.onBeforeEditClose?.(e)}function b(t,e,i,n,r,o,d,c){if(!n.editable)return;if(o.classList.contains("editing"))return;const{grid:u,isGridMode:h,config:f,editingCells:g,editorValueCallbacks:w}=t;let b;try{b=u.getRowId?.(e)}catch{}const R=b?t=>u.updateRow(b,t,"cascade"):y,C=v(n.field)?e[n.field]:void 0;o.classList.add("editing"),g.add(`${i}:${r}`);const I=c??o.parentElement;I&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(I);let k=!1;const _=r=>{if(k||!h&&!t.isEditSessionActive())return;const s=b?u._getRowEntry(b):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},x=()=>{if(k=!0,v(n.field)){const t=b?u._getRowEntry(b):void 0;(t?.row??e)[n.field]=C}},A=document.createElement("div");A.className="tbw-editor-host",o.firstElementChild&&u.__frameworkAdapter?.releaseCell?.(o),o.innerHTML="",o.appendChild(A),A.addEventListener("keydown",e=>{if(!e.defaultPrevented){if("Enter"===e.key){const t=e.target;if(t&&"true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute?.("aria-controls"))return}if("Enter"===e.key){if(h){const t=e.target,i=p(t);if(i&&i!==t)return;e.preventDefault();const r=A.querySelector("input,textarea,select");return void(r&&_(a(r,n,C)))}if(E(f,e))return;e.stopPropagation(),e.preventDefault(),k=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(h)return e.stopPropagation(),void e.preventDefault();if(E(f,e))return;e.stopPropagation(),e.preventDefault(),x(),t.exitRowEdit(i,!0)}}});const S=n,M=S.__editorTemplate,G=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 i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(u,S)??l(n),D=C,L=`${i}:${n.field}`,T=[];w.set(L,t=>{for(const e of T)e(t)});const q=t=>{T.push(t)};if("template"===G&&M)!function(t,e,i,n,r,s,o,d,l){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(!v(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(a(f,i,r))}),f.addEventListener("keydown",n=>{const d=n;if("Enter"===d.key){if(E(t.config,d))return;d.stopPropagation(),d.preventDefault(),e=!0,s(a(f,i,r)),t.exitRowEdit(l,!1)}if("Escape"===d.key){if(E(t.config,d))return;d.stopPropagation(),d.preventDefault(),o(),t.exitRowEdit(l,!0)}}),f instanceof HTMLInputElement&&"checkbox"===f.type&&f.addEventListener("change",()=>s(f.checked)),d||setTimeout(()=>f.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,A,S,e,C,_,x,d,i),q(t=>{if(null!=t&&"object"==typeof t)return;const e=A.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof G){const t=document.createElement(G);t.value=D,t.addEventListener("change",()=>_(t.value)),q(e=>{t.value=e}),A.appendChild(t),d||queueMicrotask(()=>{const t=A.querySelector(m);t?.focus({preventScroll:!0})})}else if("function"==typeof G){const i=G({row:e,rowId:b??"",value:D,field:n.field,column:n,commit:_,cancel:x,updateRow:R,onValueChange:q,grid:t.grid});if("string"==typeof i)A.innerHTML=i,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(a(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(a(r,e,n))))}(A,n,_,C),q(t=>{const e=A.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(i instanceof Node){A.appendChild(i);i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement?q(t=>{i instanceof HTMLInputElement&&"checkbox"===i.type?i.checked=!!t:i.value=String(t??"")}):o.setAttribute("data-editor-managed","")}else!i&&A.hasChildNodes()&&o.setAttribute("data-editor-managed","");d||queueMicrotask(()=>{const t=A.querySelector(m);t?.focus({preventScroll:!0})})}else if(G&&"object"==typeof G){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",n.field),A.appendChild(i),o.setAttribute("data-editor-managed","");const r={row:e,rowId:b??"",value:D,field:n.field,column:n,commit:_,cancel:x,updateRow:R,onValueChange:q,grid:t.grid};if(G.mount)try{G.mount({placeholder:i,context:r,spec:G})}catch(F){s.warnDiagnostic(s.EDITOR_MOUNT_ERROR,`External editor mount error for column '${n.field}': ${F}`,t.grid.id)}else u.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:G,context:r}}))}}class R extends r.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"},{type:"getEditableFields",description:"Returns the field names of columns that are unconditionally editable (editable === true), for consumers like clipboard paste"}]};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:max(var(--tbw-row-height),calc(1lh + 2 * var(--tbw-cell-padding-v, .25em) + var(--tbw-border-width, 1px)));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;align-self:stretch;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 WeakSet;#f=new Map;#g=!1;#w=-1;#m;#p=!1;#v=!1;#y=!1;#E=null;#b=new w;#R;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;if(this.#m=new c((t,e,i)=>{this.#C(t,e,i)}),this.#R={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#o,commitCellValue:(t,e,i,n)=>this.#I(t,e,i,n),exitRowEdit:(t,e)=>this.#k(t,e)},this.#_(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#b.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#o){if(E(this.config,t))return;this.#k(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;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=i.findRenderedRowElement?.(this.#o);if(t&&function(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const s=e.ownerDocument?.getElementById(r);if(s&&s.contains(t))return!0}return!1}(n,t))return}E(this.config,t)||queueMicrotask(()=>{-1!==this.#o&&this.#k(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.#x()})},{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.#f.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.#A(n);if(!r)return;const s=this.#b.isRowDirty(r,n);this.#S(r,n,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.#A(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(m)){if(this.#v)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#E;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.#E={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#p=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=p(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches(m)||(this.#p=!1,this.#E=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#p){if(E(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#M()});this.#M(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(m)&&(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.#b.clear(),this.#u.clear(),this.#f.clear(),this.#p=!1,this.#v=!1,this.#E=null,this.#y=!1,this.#h=new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#o;if("getEditableFields"===t.type){const e=t.context;return(e?.columns??this.#r.effectiveConfig?.columns??[]).filter(t=>!0===t.editable).map(t=>t.field)}}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));return!!s&&(!!this.#G(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){const e=this.#r;if("Escape"===t.key){if(this.#i&&this.#p)return this.#M(),this.requestAfterRender(),!0;if(-1!==this.#o&&!this.#i)return E(this.config,t)||this.#k(this.#o,!0),!0}const i=p(t.target),n=!!i&&i!==this.gridElement;if(this.#i&&!this.#p&&!n&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&(this.#p||n)&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#o&&!this.#i)return!0;if("Tab"===t.key&&(-1!==this.#o||this.#i)){if(t.preventDefault(),this.#y)return this.#k(this.#o,!1),!0;const e=!t.shiftKey;return this.#D(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#o)return!1;const i=e._focusRow,n=e._focusCol;if(i>=0&&n>=0){const r=e._visibleColumns[n],s=e._rows[i];if(r&&s&&this.#n(r,s)&&"boolean"===r.type){const e=r.field;if(v(e)){const n=!s[e];return this.#I(i,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.#p)return this.#x(),!0;if(this.#i&&this.#p){const e=p(t.target);if(e&&e!==t.target)return!0;this.#E=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0,this.requestAfterRender(),!0}if(-1!==this.#o){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!E(this.config,t)}const i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,r=e._focusCol;if(n>=0){const i=e._columns?.some(t=>this.#s(t)),s=e._rows[n];if(i&&this.#G(s)){const i=e._visibleColumns[r],s=e._rows[n],o=i?.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}});return this.gridElement.dispatchEvent(a),a.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??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i>=0&&n>=0){const r=e._visibleColumns[n],s=e._rows[i];if(r&&s&&this.#n(r,s)&&r.field)return t.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}processColumns(t){const e=this.#r,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const s=t.__element;if(s&&!this.#h.has(s)){this.#h.add(s),null==t.editable&&s.hasAttribute("editable")&&(t.editable="false"!==s.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=s.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let o;if(i?.[t.type]?.editorParams&&(o=i[t.type].editorParams),!o&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(o=i.editorParams)}return o?{...t,editorParams:{...o,...t.editorParams}}:t})}processRows(t){const e=this.#r;if(this.config.dirtyTracking&&e.getRowId&&this.#b.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++)if(this.#A(r[o])===i){s=o;break}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#o!==s&&this.#L(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.#L(this.#o,e)}if(this.#g&&(this.#g=!1,this.#T(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#b.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=this.#q(r,s);if(!o||o.classList.contains("editing"))continue;const d=t._rows[r],l=t._visibleColumns[s];d&&l&&this.#F(d,r,l,s,o,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t,o=this.#n(n,e);if(o)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#i&&s.classList.contains("editing")){s.classList.remove("editing");const t=e[n.field];s.textContent=null==t?"":String(t)}this.#i&&o&&(s.classList.contains("editing")||this.#F(e,i,n,r,s,!0,t.rowElement))}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.#b.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.#b.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.#b.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#b.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.#b.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#b.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#b.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#b.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#b.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.#b.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#b.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.#b.markDirty(t),this.#S(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#b.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#b.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#b.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#b.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#b.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#b.revertRow(t,e)&&(this.#S(t,e,"reverted"),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#b.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#b.changedRowIds.clear(),this.#b.committedDirtyRowIds.clear(),this.#_(),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=this.#q(t,n);o&&(this.#y=!0,this.#P(t,n,o))}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];this.#G(r)&&(this.#y=!1,this.#O(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.#F(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(m);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#o&&this.#k(this.#o,!1)}cancelActiveRowEdit(){-1!==this.#o&&this.#k(this.#o,!0)}#A(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#q(t,e){const i=this.#r.findRenderedRowElement?.(t);return i?.querySelector(`.cell[data-col="${e}"]`)??null}#G(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#S(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#b.getOriginalRow(t),type:i})}#M(){this.#V();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#N(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#b.changedRowIds.delete(t),this.#b.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)))}#C(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=>this.#A(e)===t);if(-1===o||void 0===o)return;const d=this.#q(o,r);if(d)if(i){d.setAttribute("data-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&d.setAttribute("title",i)}else d.removeAttribute("data-invalid"),d.removeAttribute("title")}#L(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.#f)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#f.delete(o));for(const[o,d]of s)this.#f.set(o,d);this.#_()}#P(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.#O(t,r),this.#a=e,this.#F(r,t,s,e,i,!1)))}#V(){const t=this.#E;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.#f.get(n);if(r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),i){const t=this.#A(i);t&&(this.config.dirtyTracking?this.#b.isRowDirty(t,i)||(this.#b.changedRowIds.delete(t),this.#S(t,i,"reverted")):this.#b.changedRowIds.delete(t))}this.requestRender(),this.#E=null}#x(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#q(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(m);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#D(t){const e=this.#r,n=e._rows,r=this.#i?e._focusRow:this.#o,s=n[r],o=e._visibleColumns.map((t,e)=>s&&this.#n(t,s)?e:-1).filter(t=>t>=0);if(0===o.length)return;const d=o.indexOf(e._focusCol)+(t?1:-1);if(d>=0&&d<o.length){e._focusCol=o[d];const t=this.#q(r,o[d]);if(t?.classList.contains("editing")){const e=t.querySelector(m);e?.focus({preventScroll:!0})}return void i.ensureCellVisible(e,{forceHorizontalScroll:!0})}const l=r+(t?1:-1);if(l>=0&&l<n.length){const s=n[l],o=e._visibleColumns.map((t,e)=>s&&this.#n(t,s)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],i.ensureCellVisible(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#q(l,e._focusCol);if(t?.classList.contains("editing")){const e=t.querySelector(m);e?.focus({preventScroll:!0})}},0)):(this.#k(r,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),i.ensureCellVisible(e,{forceHorizontalScroll:!0}))}}#_(){const t=this.#r;t._activeEditRows=this.#o,t._rowEditSnapshots=this.#c}#O(t,i){this.#o!==t&&(-1!==this.#o&&this.#k(this.#o,!1),this.#c.set(t,{...i}),this.#o=t,this.#l=i,this.#d=this.#A(i),this.#_(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#d??"",row:i}),e.announce(this.gridElement,e.getA11yMessage(this.gridElement,"editingStarted",t))))}#k(t,i){if(this.#o!==t)return;const n=this.#r,r=this.#c.get(t),s=n.findRenderedRowElement?.(t);let o=this.#d;const d=o?n._getRowEntry(o):void 0,l=d?.row??this.#l??n._rows[t];if(!o&&l&&(o=this.#A(l)),!i&&s&&l){s.querySelectorAll(".cell.editing").forEach(e=>{const i=Number(e.getAttribute("data-col"));if(isNaN(i))return;const r=n._visibleColumns[i];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=a(s,r,i);i!==n&&this.#I(t,r,n,l)}})}if(i||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:l}),i&&l)this.#N(o,l,r);else if(!i&&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}(r,l),i=o?this.#b.changedRowIds.has(o):e,n=this.emitCancelable("row-commit",{rowIndex:t,rowId:o??"",row:l,oldValue:r,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});n&&r?this.#N(o,l,r):n||(o&&this.config.dirtyTracking&&(this.#b.isRowDirty(o,l)?this.#b.committedDirtyRowIds.add(o):this.#b.committedDirtyRowIds.delete(o)),e&&this.isAnimationEnabled&&(this.#w=t))}this.#c.delete(t),this.#o=-1,this.#d=void 0,this.#l=void 0,this.#a=-1,this.#y=!1,this.#_();for(const e of this.#u)e.startsWith(`${t}:`)&&this.#u.delete(e);for(const e of this.#f.keys())e.startsWith(`${t}:`)&&this.#f.delete(e);if(this.#g=!0,s){const t=n.__frameworkAdapter,e=s.querySelectorAll(".cell.editing");t?.releaseCell&&e.forEach(e=>{t.releaseCell(e)}),e.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),n.refreshVirtualWindow(!0)}else this.#T(n),this.#g=!1;!this.#i&&l&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:l,reverted:i}),i||e.announce(this.gridElement,e.getA11yMessage(this.gridElement,"editingCommitted",t)))}#I(t,e,i,r){const s=e.field;if(!v(s))return;const o=r[s];if(o===i)return;const d=this.#r,l=this.#A(r),a=!l||!this.#b.changedRowIds.has(l),c=l?t=>this.grid.updateRow(l,t,"cascade"):y;let u=!1;const h=l?t=>{u=!0,this.setInvalid(l,s,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:r,rowId:l??"",field:s,oldValue:o,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:a,updateRow:c,setInvalid:h}))return;if(l&&!u&&this.isCellInvalid(l,s)&&this.clearInvalid(l,s),r[s]=i,n.invalidateAccessorCache(r,s),l&&this.#b.changedRowIds.add(l),this.#_(),this.config.dirtyTracking&&l){const t=this.#b.isRowDirty(l,r);this.#S(l,r,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:s,oldValue:o,newValue:i});const f=d.findRenderedRowElement?.(t);f&&f.classList.add("changed")}#F(t,e,i,n,r,s,o){b(this.#R,t,e,i,n,r,s,o)}#T(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=R,t.defaultEditorFor=l,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/aria"),require("../../core/internal/keyboard"),require("../../core/internal/sanitize"),require("../../core/internal/value-accessor"),require("../../core/plugin/base-plugin"),require("../../core/internal/diagnostics")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/aria","../../core/internal/keyboard","../../core/internal/sanitize","../../core/internal/value-accessor","../../core/plugin/base-plugin","../../core/internal/diagnostics"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid,t.TbwGrid,t.TbwGrid,t.TbwGrid,t.TbwGrid)}(this,function(t,e,i,n,r,s,o){"use strict";function d(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 l="__tbw_null__";function a(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 d(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?l:"",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 s=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===l?e.commit(null):e.commit(n.value)};return n.addEventListener("change",s),n.addEventListener("blur",s),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 c(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 u{#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 h(t,e,i){const n=t.get(e);return!!n&&!f(n,i)}function f(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(!f(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(!f(i[t],n[t]))return!1;return!0}return!1}function g(t,e,i){t.set(e,structuredClone(i))}function w(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 m{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 h(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&&h(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&&!f(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)&&h(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){g(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&&g(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&&h(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&&h(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=w(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&&w(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 p='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function v(t){const e=t;return e?.closest?.(p)??null}function y(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function E(t){}function b(t,e){return!1===t.onBeforeEditClose?.(e)}function R(t,e,i,n,r,s,d,l){if(!n.editable)return;if(s.classList.contains("editing"))return;const{grid:u,isGridMode:h,config:f,editingCells:g,editorValueCallbacks:w}=t;let m;try{m=u.getRowId?.(e)}catch{}const R=m?t=>u.updateRow(m,t,"cascade"):E,C=y(n.field)?e[n.field]:void 0;s.classList.add("editing"),g.add(`${i}:${r}`);const I=l??s.parentElement;I&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(I);let k=!1;const _=r=>{if(k||!h&&!t.isEditSessionActive())return;const s=m?u._getRowEntry(m):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},A=()=>{if(k=!0,y(n.field)){const t=m?u._getRowEntry(m):void 0;(t?.row??e)[n.field]=C}},x=document.createElement("div");x.className="tbw-editor-host",s.firstElementChild&&u.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.appendChild(x),x.addEventListener("keydown",e=>{if(!e.defaultPrevented){if("Enter"===e.key){const t=e.target;if(t&&"true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute?.("aria-controls"))return}if("Enter"===e.key){if(h){const t=e.target,i=v(t);if(i&&i!==t)return;e.preventDefault();const r=x.querySelector("input,textarea,select");return void(r&&_(c(r,n,C)))}if(b(f,e))return;e.stopPropagation(),e.preventDefault(),k=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(h)return e.stopPropagation(),void e.preventDefault();if(b(f,e))return;e.stopPropagation(),e.preventDefault(),A(),t.exitRowEdit(i,!0)}}});const S=n,M=S.__editorTemplate,G=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 i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(u,S)??a(n),D=C,L=`${i}:${n.field}`,T=[];w.set(L,t=>{for(const e of T)e(t)});const q=t=>{T.push(t)};if("template"===G&&M)!function(t,e,i,n,r,s,o,d,l){const a=i.__editorTemplate;if(!a)return;const u=a.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(!y(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(c(f,i,r))}),f.addEventListener("keydown",n=>{const d=n;if("Enter"===d.key){if(b(t.config,d))return;d.stopPropagation(),d.preventDefault(),e=!0,s(c(f,i,r)),t.exitRowEdit(l,!1)}if("Escape"===d.key){if(b(t.config,d))return;d.stopPropagation(),d.preventDefault(),o(),t.exitRowEdit(l,!0)}}),f instanceof HTMLInputElement&&"checkbox"===f.type&&f.addEventListener("change",()=>s(f.checked)),d||setTimeout(()=>f.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,x,S,e,C,_,A,d,i),q(t=>{if(null!=t&&"object"==typeof t)return;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 G){const t=document.createElement(G);t.value=D,t.addEventListener("change",()=>_(t.value)),q(e=>{t.value=e}),x.appendChild(t),d||queueMicrotask(()=>{const t=x.querySelector(p);t?.focus({preventScroll:!0})})}else if("function"==typeof G){const i=G({row:e,rowId:m??"",value:D,field:n.field,column:n,commit:_,cancel:A,updateRow:R,onValueChange:q,grid:t.grid});if("string"==typeof i)x.innerHTML=i,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(c(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(c(r,e,n))))}(x,n,_,C),q(t=>{const e=x.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(i instanceof Node){x.appendChild(i);i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement?q(t=>{i instanceof HTMLInputElement&&"checkbox"===i.type?i.checked=!!t:i.value=String(t??"")}):s.setAttribute("data-editor-managed","")}else!i&&x.hasChildNodes()&&s.setAttribute("data-editor-managed","");d||queueMicrotask(()=>{const t=x.querySelector(p);t?.focus({preventScroll:!0})})}else if(G&&"object"==typeof G){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",n.field),x.appendChild(i),s.setAttribute("data-editor-managed","");const r={row:e,rowId:m??"",value:D,field:n.field,column:n,commit:_,cancel:A,updateRow:R,onValueChange:q,grid:t.grid};if(G.mount)try{G.mount({placeholder:i,context:r,spec:G})}catch(F){o.warnDiagnostic(o.EDITOR_MOUNT_ERROR,`External editor mount error for column '${n.field}': ${F}`,t.grid.id)}else u.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:G,context:r}}))}}class C extends s.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"},{type:"getEditableFields",description:"Returns the field names of columns that are unconditionally editable (editable === true), for consumers like clipboard paste"}]};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:max(var(--tbw-row-height),calc(1lh + 2 * var(--tbw-cell-padding-v, .25em) + var(--tbw-border-width, 1px)));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;align-self:stretch;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 WeakSet;#f=new Map;#g=!1;#w=-1;#m;#p=!1;#v=!1;#y=!1;#E=null;#b=new m;#R;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;if(this.#m=new u((t,e,i)=>{this.#C(t,e,i)}),this.#R={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#o,commitCellValue:(t,e,i,n)=>this.#I(t,e,i,n),exitRowEdit:(t,e)=>this.#k(t,e)},this.#_(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#b.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#o){if(b(this.config,t))return;this.#k(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;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=i.findRenderedRowElement?.(this.#o);if(t&&function(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const s=e.ownerDocument?.getElementById(r);if(s&&s.contains(t))return!0}return!1}(n,t))return}b(this.config,t)||queueMicrotask(()=>{-1!==this.#o&&this.#k(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.#A()})},{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.#f.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.#x(n);if(!r)return;const s=this.#b.isRowDirty(r,n);this.#S(r,n,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.#x(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(p)){if(this.#v)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#E;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.#E={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#p=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=v(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches(p)||(this.#p=!1,this.#E=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#p){if(b(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#M()});this.#M(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(p)&&(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.#b.clear(),this.#u.clear(),this.#f.clear(),this.#p=!1,this.#v=!1,this.#E=null,this.#y=!1,this.#h=new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#o;if("getEditableFields"===t.type){const e=t.context;return(e?.columns??this.#r.effectiveConfig?.columns??[]).filter(t=>!0===t.editable).map(t=>t.field)}}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));return!!s&&(!!this.#G(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){const e=this.#r;if("Escape"===t.key){if(this.#i&&this.#p)return this.#M(),this.requestAfterRender(),!0;if(-1!==this.#o&&!this.#i)return b(this.config,t)||this.#k(this.#o,!0),!0}const i=v(t.target),n=!!i&&i!==this.gridElement;if(this.#i&&!this.#p&&!n&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&(this.#p||n)&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#o&&!this.#i)return!0;if("Tab"===t.key&&(-1!==this.#o||this.#i)){if(t.preventDefault(),this.#y)return this.#k(this.#o,!1),!0;const e=!t.shiftKey;return this.#D(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#o)return!1;const i=e._focusRow,n=e._focusCol;if(i>=0&&n>=0){const r=e._visibleColumns[n],s=e._rows[i];if(r&&s&&this.#n(r,s)&&"boolean"===r.type){const e=r.field;if(y(e)){const n=!s[e];return this.#I(i,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.#p)return this.#A(),!0;if(this.#i&&this.#p){const e=v(t.target);if(e&&e!==t.target)return!0;this.#E=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0,this.requestAfterRender(),!0}if(-1!==this.#o){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!b(this.config,t)}const i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,r=e._focusCol;if(n>=0){const i=e._columns?.some(t=>this.#s(t)),s=e._rows[n];if(i&&this.#G(s)){const i=e._visibleColumns[r],s=e._rows[n],o=i?.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}});return this.gridElement.dispatchEvent(a),a.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??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i>=0&&n>=0){const r=e._visibleColumns[n],s=e._rows[i];if(r&&s&&this.#n(r,s)&&r.field)return t.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}#L(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#T(){const t=this.#r,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const r=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!r.length)return;const s=t.__frameworkAdapter,o=i.typeDefaults??={};for(let d=0;d<r.length;d++){const t=r[d],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),a=l??t;let c=s?.canHandle?.(a)?s.createEditor?.(a):void 0;if(!c&&l){const e=this.#L(t),i=n.compileTemplate(l.innerHTML);c=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}c&&(o[e]={...i??{},editor:c})}}processColumns(t){const e=this.#r;this.#T();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const s=t.__element;if(s&&!this.#h.has(s)){this.#h.add(s),null==t.editable&&s.hasAttribute("editable")&&(t.editable="false"!==s.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=s.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let o;if(i?.[t.type]?.editorParams&&(o=i[t.type].editorParams),!o&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(o=i.editorParams)}return o?{...t,editorParams:{...o,...t.editorParams}}:t})}processRows(t){const e=this.#r;if(this.config.dirtyTracking&&e.getRowId&&this.#b.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++)if(this.#x(r[o])===i){s=o;break}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#o!==s&&this.#q(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.#q(this.#o,e)}if(this.#g&&(this.#g=!1,this.#F(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#b.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=this.#P(r,s);if(!o||o.classList.contains("editing"))continue;const d=t._rows[r],l=t._visibleColumns[s];d&&l&&this.#O(d,r,l,s,o,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t,o=this.#n(n,e);if(o)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#i&&s.classList.contains("editing")){s.classList.remove("editing");const t=e[n.field];s.textContent=null==t?"":String(t)}this.#i&&o&&(s.classList.contains("editing")||this.#O(e,i,n,r,s,!0,t.rowElement))}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.#b.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.#b.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.#b.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#b.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.#b.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#b.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#b.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#b.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#b.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.#b.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#b.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.#b.markDirty(t),this.#S(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#b.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#b.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#b.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#b.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#b.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#b.revertRow(t,e)&&(this.#S(t,e,"reverted"),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#b.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#b.changedRowIds.clear(),this.#b.committedDirtyRowIds.clear(),this.#_(),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=this.#P(t,n);o&&(this.#y=!0,this.#V(t,n,o))}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];this.#G(r)&&(this.#y=!1,this.#N(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.#O(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(p);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#o&&this.#k(this.#o,!1)}cancelActiveRowEdit(){-1!==this.#o&&this.#k(this.#o,!0)}#x(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#P(t,e){const i=this.#r.findRenderedRowElement?.(t);return i?.querySelector(`.cell[data-col="${e}"]`)??null}#G(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#S(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#b.getOriginalRow(t),type:i})}#M(){this.#$();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#j(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#b.changedRowIds.delete(t),this.#b.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)))}#C(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=>this.#x(e)===t);if(-1===o||void 0===o)return;const d=this.#P(o,r);if(d)if(i){d.setAttribute("data-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&d.setAttribute("title",i)}else d.removeAttribute("data-invalid"),d.removeAttribute("title")}#q(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.#f)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#f.delete(o));for(const[o,d]of s)this.#f.set(o,d);this.#_()}#V(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.#N(t,r),this.#a=e,this.#O(r,t,s,e,i,!1)))}#$(){const t=this.#E;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.#f.get(n);if(r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),i){const t=this.#x(i);t&&(this.config.dirtyTracking?this.#b.isRowDirty(t,i)||(this.#b.changedRowIds.delete(t),this.#S(t,i,"reverted")):this.#b.changedRowIds.delete(t))}this.requestRender(),this.#E=null}#A(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#P(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(p);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#D(t){const e=this.#r,n=e._rows,r=this.#i?e._focusRow:this.#o,s=n[r],o=e._visibleColumns.map((t,e)=>s&&this.#n(t,s)?e:-1).filter(t=>t>=0);if(0===o.length)return;const d=o.indexOf(e._focusCol)+(t?1:-1);if(d>=0&&d<o.length){e._focusCol=o[d];const t=this.#P(r,o[d]);if(t?.classList.contains("editing")){const e=t.querySelector(p);e?.focus({preventScroll:!0})}return void i.ensureCellVisible(e,{forceHorizontalScroll:!0})}const l=r+(t?1:-1);if(l>=0&&l<n.length){const s=n[l],o=e._visibleColumns.map((t,e)=>s&&this.#n(t,s)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],i.ensureCellVisible(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#P(l,e._focusCol);if(t?.classList.contains("editing")){const e=t.querySelector(p);e?.focus({preventScroll:!0})}},0)):(this.#k(r,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),i.ensureCellVisible(e,{forceHorizontalScroll:!0}))}}#_(){const t=this.#r;t._activeEditRows=this.#o,t._rowEditSnapshots=this.#c}#N(t,i){this.#o!==t&&(-1!==this.#o&&this.#k(this.#o,!1),this.#c.set(t,{...i}),this.#o=t,this.#l=i,this.#d=this.#x(i),this.#_(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#d??"",row:i}),e.announce(this.gridElement,e.getA11yMessage(this.gridElement,"editingStarted",t))))}#k(t,i){if(this.#o!==t)return;const n=this.#r,r=this.#c.get(t),s=n.findRenderedRowElement?.(t);let o=this.#d;const d=o?n._getRowEntry(o):void 0,l=d?.row??this.#l??n._rows[t];if(!o&&l&&(o=this.#x(l)),!i&&s&&l){s.querySelectorAll(".cell.editing").forEach(e=>{const i=Number(e.getAttribute("data-col"));if(isNaN(i))return;const r=n._visibleColumns[i];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=c(s,r,i);i!==n&&this.#I(t,r,n,l)}})}if(i||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:l}),i&&l)this.#j(o,l,r);else if(!i&&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}(r,l),i=o?this.#b.changedRowIds.has(o):e,n=this.emitCancelable("row-commit",{rowIndex:t,rowId:o??"",row:l,oldValue:r,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});n&&r?this.#j(o,l,r):n||(o&&this.config.dirtyTracking&&(this.#b.isRowDirty(o,l)?this.#b.committedDirtyRowIds.add(o):this.#b.committedDirtyRowIds.delete(o)),e&&this.isAnimationEnabled&&(this.#w=t))}this.#c.delete(t),this.#o=-1,this.#d=void 0,this.#l=void 0,this.#a=-1,this.#y=!1,this.#_();for(const e of this.#u)e.startsWith(`${t}:`)&&this.#u.delete(e);for(const e of this.#f.keys())e.startsWith(`${t}:`)&&this.#f.delete(e);if(this.#g=!0,s){const t=n.__frameworkAdapter,e=s.querySelectorAll(".cell.editing");t?.releaseCell&&e.forEach(e=>{t.releaseCell(e)}),e.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),n.refreshVirtualWindow(!0)}else this.#F(n),this.#g=!1;!this.#i&&l&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:l,reverted:i}),i||e.announce(this.gridElement,e.getA11yMessage(this.gridElement,"editingCommitted",t)))}#I(t,e,i,n){const s=e.field;if(!y(s))return;const o=n[s];if(o===i)return;const d=this.#r,l=this.#x(n),a=!l||!this.#b.changedRowIds.has(l),c=l?t=>this.grid.updateRow(l,t,"cascade"):E;let u=!1;const h=l?t=>{u=!0,this.setInvalid(l,s,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:l??"",field:s,oldValue:o,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:a,updateRow:c,setInvalid:h}))return;if(l&&!u&&this.isCellInvalid(l,s)&&this.clearInvalid(l,s),n[s]=i,r.invalidateAccessorCache(n,s),l&&this.#b.changedRowIds.add(l),this.#_(),this.config.dirtyTracking&&l){const t=this.#b.isRowDirty(l,n);this.#S(l,n,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:s,oldValue:o,newValue:i});const f=d.findRenderedRowElement?.(t);f&&f.classList.add("changed")}#O(t,e,i,n,r,s,o){R(this.#R,t,e,i,n,r,s,o)}#F(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=C,t.defaultEditorFor=a,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=editing.umd.js.map