@toolbox-web/grid 3.0.0 → 3.0.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 (53) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/features/registry.js +1 -1
  6. package/lib/plugins/clipboard/index.js +1 -1
  7. package/lib/plugins/column-virtualization/index.js +1 -1
  8. package/lib/plugins/context-menu/index.js +1 -1
  9. package/lib/plugins/editing/index.js +1 -1
  10. package/lib/plugins/editing/index.js.map +1 -1
  11. package/lib/plugins/export/index.js +1 -1
  12. package/lib/plugins/filtering/index.js +1 -1
  13. package/lib/plugins/filtering/index.js.map +1 -1
  14. package/lib/plugins/grouping-columns/index.js +1 -1
  15. package/lib/plugins/grouping-rows/index.js +1 -1
  16. package/lib/plugins/master-detail/index.js +1 -1
  17. package/lib/plugins/multi-sort/index.js +1 -1
  18. package/lib/plugins/pinned-columns/index.js +1 -1
  19. package/lib/plugins/pinned-rows/index.js +1 -1
  20. package/lib/plugins/pivot/index.js +1 -1
  21. package/lib/plugins/print/index.js +1 -1
  22. package/lib/plugins/print/index.js.map +1 -1
  23. package/lib/plugins/reorder-columns/index.js +1 -1
  24. package/lib/plugins/responsive/index.js +1 -1
  25. package/lib/plugins/responsive/index.js.map +1 -1
  26. package/lib/plugins/row-drag-drop/index.js +1 -1
  27. package/lib/plugins/selection/index.js +1 -1
  28. package/lib/plugins/selection/index.js.map +1 -1
  29. package/lib/plugins/server-side/index.js +1 -1
  30. package/lib/plugins/shell/index.js +1 -1
  31. package/lib/plugins/sticky-rows/index.js +1 -1
  32. package/lib/plugins/tooltip/index.js +1 -1
  33. package/lib/plugins/tooltip/index.js.map +1 -1
  34. package/lib/plugins/tree/index.js +1 -1
  35. package/lib/plugins/undo-redo/index.js +1 -1
  36. package/lib/plugins/visibility/index.js +1 -1
  37. package/package.json +1 -1
  38. package/umd/grid.all.umd.js +1 -1
  39. package/umd/grid.all.umd.js.map +1 -1
  40. package/umd/grid.umd.js +1 -1
  41. package/umd/grid.umd.js.map +1 -1
  42. package/umd/plugins/editing.umd.js +1 -1
  43. package/umd/plugins/editing.umd.js.map +1 -1
  44. package/umd/plugins/filtering.umd.js +1 -1
  45. package/umd/plugins/filtering.umd.js.map +1 -1
  46. package/umd/plugins/print.umd.js +1 -1
  47. package/umd/plugins/print.umd.js.map +1 -1
  48. package/umd/plugins/responsive.umd.js +1 -1
  49. package/umd/plugins/responsive.umd.js.map +1 -1
  50. package/umd/plugins/selection.umd.js +1 -1
  51. package/umd/plugins/selection.umd.js.map +1 -1
  52. package/umd/plugins/tooltip.umd.js +1 -1
  53. package/umd/plugins/tooltip.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/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){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});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}}var 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)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).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 r=()=>{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",r),n.addEventListener("blur",r),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){return t instanceof HTMLInputElement?"checkbox"===t.type?t.checked:"number"===t.type?""===t.value?e?.nullable?null:(e?.editorParams)?.min??0:Number(t.value):"date"===t.type?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:"number"==typeof i?""===t.value?e?.nullable?null:(e?.editorParams)?.min??0:Number(t.value):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value:"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}var u=class{#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}var m=class{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)}},p='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function v(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function y(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function b(t){}function E(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"):b,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){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(I);let k=!1;const x=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)},_=()=>{if(k=!0,y(n.field)){((m?u._getRowEntry(m):void 0)?.row??e)[n.field]=C}},A=document.createElement("div");A.className="tbw-editor-host",s.firstElementChild&&u.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.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){const r=e.target,s=v(r);if(s&&s!==r)return;if(h){e.preventDefault();const t=A.querySelector("input,textarea,select");return void(t&&x(c(t,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(),_(),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(E(t.config,d))return;d.stopPropagation(),d.preventDefault(),e=!0,s(c(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",()=>x(t.value)),q(e=>{t.value=e}),A.appendChild(t),d||queueMicrotask(()=>{A.querySelector(p)?.focus({preventScroll:!0})})}else if("function"==typeof G){const i=G({row:e,rowId:m??"",value:D,field:n.field,column:n,commit:x,cancel:_,updateRow:R,onValueChange:q,grid:t.grid});"string"==typeof i?(A.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))))}(A,n,x,C),q(t=>{const e=A.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):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??"")}):s.setAttribute("data-editor-managed","")):!i&&A.hasChildNodes()&&s.setAttribute("data-editor-managed",""),d||queueMicrotask(()=>{A.querySelector(p)?.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),s.setAttribute("data-editor-managed","");const r={row:e,rowId:m??"",value:D,field:n.field,column:n,commit:x,cancel:_,updateRow:R,onValueChange:q,grid:t.grid};if(G.mount)try{G.mount({placeholder:i,context:r,spec:G})}catch(P){(0,o.warnDiagnostic)(o.EDITOR_MOUNT_ERROR,`External editor mount error for column '${n.field}': ${P}`,t.grid.id)}else u.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:G,context:r}}))}}var C=class 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:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};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-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{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}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{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:var(--lightningcss-light,#fef2f2)var(--lightningcss-dark,#450a0a);--tbw-invalid-border-color:var(--lightningcss-light,#ef4444)var(--lightningcss-dark,#f87171)}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;#b=null;#E=new m;#R=new Set;#C;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.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#o,commitCellValue:(t,e,i,n)=>this.#k(t,e,i,n),exitRowEdit:(t,e)=>this.#x(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.#E.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.#x(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.#x(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?.action;if(!e)return;const i=this.rows[e.rowIndex];if(!i)return;const n=this.#S(i);if(!n)return;const r=this.#E.isRowDirty(n,i);this.#M(n,i,r?"modified":"pristine")};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.#S(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('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#b;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.#b={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('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#p=!1,this.#b=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.#G()});this.#G(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(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.#f.clear(),this.#p=!1,this.#v=!1,this.#b=null,this.#y=!1,this.#h=new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#o;if("getCellEditableResolver"===t.type){const t=this.#r.effectiveConfig?.columns??[],e=new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#n(n,i)}}return"commitCellValue"===t.type?this.#D(t.context):void 0}#D(t){const e=this.#r,i=(e._visibleColumns??[]).find(e=>e.field===t.field)??e._columns?.find(e=>e.field===t.field),n=(null!=t.rowId?e._getRowEntry(t.rowId)?.row:void 0)??e._rows?.[t.rowIndex];if(i&&n&&y(t.field)){if("history"===t.source){n[t.field]=t.newValue,(0,r.invalidateAccessorCache)(n,t.field);const e=this.#S(n);if(e&&this.config.dirtyTracking){const t=this.#E.isRowDirty(e,n);t||this.#E.changedRowIds.delete(e),this.#M(e,n,t?"modified":"pristine")}return!0}return this.#k(t.rowIndex,i,t.newValue,n,t.source),n[t.field]===t.newValue}}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;return!!e._columns?.some(t=>this.#s(t))&&(!!this.#L(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.#G(),this.requestAfterRender(),!0;if(-1!==this.#o&&!this.#i)return E(this.config,t)||this.#x(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.#x(this.#o,!1),!0;const e=!t.shiftKey;return this.#T(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.#k(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.#b=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.#L(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}#q(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}#P(){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.#q(t),i=(0,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.#P();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.#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++)if(this.#S(r[o])===i){s=o;break}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#o!==s&&this.#F(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.#F(this.#o,e)}if(this.#g&&(this.#g=!1,this.#V(t)),-1!==this.#w){const e=this.#w;this.#w=-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=this.#O(r,s);if(!o||o.classList.contains("editing"))continue;const d=t._rows[r],l=t._visibleColumns[s];d&&l&&this.#$(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.#$(e,i,n,r,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#E.getRowDirtyState(e,t.row),s=t.rowElement;if(s.classList.toggle("tbw-row-dirty",n),s.classList.toggle("tbw-row-new",i),r){const i=s.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#E.isCellDirty(e,t.row,s))}}else{const t=s.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.#M(t,e,"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.#M(t,e,"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.#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.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#_(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#r._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.#O(t,n);o&&(this.#y=!0,this.#N(t,n,o))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#s(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#L(n)&&(this.#y=!1,this.#j(t,n),Array.from(i.children).forEach((i,r)=>{const s=e._visibleColumns[r];if(s&&this.#n(s,n)){const e=i;e.classList.contains("editing")||this.#$(n,t,s,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(p);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#o&&this.#x(this.#o,!1)}cancelActiveRowEdit(){-1!==this.#o&&this.#x(this.#o,!0)}#S(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#O(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#L(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#M(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:i})}#G(){this.#H();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#z(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#E.changedRowIds.delete(t),this.#E.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)))}#I(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?.findIndex(e=>this.#S(e)===t);if(-1===s||void 0===s)return;const o=this.#O(s,r);if(o)if(i){o.setAttribute("data-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&o.setAttribute("title",i)}else o.removeAttribute("data-invalid"),o.removeAttribute("title")}#F(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.#_()}#N(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.#j(t,r),this.#a=e,this.#$(r,t,s,e,i,!1)))}#H(){const t=this.#b;if(!t)return;const e=this.#r._rows?.[t.rowIndex];e&&(e[t.field]=t.value);const i=`${t.rowIndex}:${t.field}`,n=this.#f.get(i);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),e){const t=this.#S(e);t&&(this.config.dirtyTracking?this.#E.isRowDirty(t,e)||(this.#E.changedRowIds.delete(t),this.#M(t,e,"reverted")):this.#E.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#A(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#O(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())}}#T(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.#O(r,o[d]);return t?.classList.contains("editing")&&t.querySelector(p)?.focus({preventScroll:!0}),void(0,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],(0,i.ensureCellVisible)(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#O(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(p)?.focus({preventScroll:!0})},0)):(this.#x(r,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),(0,i.ensureCellVisible)(e,{forceHorizontalScroll:!0}))}}#_(){const t=this.#r;t._activeEditRows=this.#o,t._rowEditSnapshots=this.#c}#j(t,i){this.#o!==t&&(-1!==this.#o&&this.#x(this.#o,!1),this.#c.set(t,{...i}),this.#o=t,this.#l=i,this.#d=this.#S(i),this.#_(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#d??"",row:i}),(0,e.announce)(this.gridElement,(0,e.getA11yMessage)(this.gridElement,"editingStarted",t))))}#x(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)?.row??this.#l??n._rows[t];if(!o&&d&&(o=this.#S(d)),!i&&s&&d&&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=d[e],n=c(s,r,i);i!==n&&this.#k(t,r,n,d)}}),i||this.#i||!d||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:d}),i&&d)this.#z(o,d,r);else if(!i&&d){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,d),i=o?this.#E.changedRowIds.has(o):e,n=this.emitCancelable("row-commit",{rowIndex:t,rowId:o??"",row:d,oldValue:r,newValue:d,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});n&&r?this.#z(o,d,r):n||(o&&this.config.dirtyTracking&&(this.#E.isRowDirty(o,d)?this.#E.committedDirtyRowIds.add(o):this.#E.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.#V(n),this.#g=!1;!this.#i&&d&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:d,reverted:i}),i||(0,e.announce)(this.gridElement,(0,e.getA11yMessage)(this.gridElement,"editingCommitted",t)))}#k(t,e,i,n,s="user"){const o=e.field;if(!y(o))return;const d=n[o];if(d===i)return;const l=this.#r,a=this.#S(n),c=!a||!this.#E.changedRowIds.has(a),u=a?t=>this.grid.updateRow(a,t,"cascade"):b;let h=!1;const f=a?t=>{h=!0,this.setInvalid(a,o,t??"")}:()=>{},g=`${a??t}\0${o}`;if(this.#R.has(g))return;let w=!1;this.#R.add(g);try{w=this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:o,oldValue:d,value:i,source:s,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:u,setInvalid:f})}finally{this.#R.delete(g)}if(w)return;if(a&&!h&&this.isCellInvalid(a,o)&&this.clearInvalid(a,o),n[o]=i,(0,r.invalidateAccessorCache)(n,o),a&&this.#E.changedRowIds.add(a),this.#_(),this.config.dirtyTracking&&a){const t=this.#E.isRowDirty(a,n);this.#M(a,n,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:o,oldValue:d,newValue:i});const m=l.findRenderedRowElement?.(t);m&&m.classList.add("changed")}#$(t,e,i,n,r,s,o){R(this.#C,t,e,i,n,r,s,o)}#V(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});
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){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});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}}var 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)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).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 r=()=>{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",r),n.addEventListener("blur",r),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){return t instanceof HTMLInputElement?"checkbox"===t.type?t.checked:"number"===t.type?""===t.value?e?.nullable?null:(e?.editorParams)?.min??0:Number(t.value):"date"===t.type?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:"number"==typeof i?""===t.value?e?.nullable?null:(e?.editorParams)?.min??0:Number(t.value):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value:"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}var u=class{#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}var m=class{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)}},p='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function v(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function y(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function b(t){}function E(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"):b,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){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(I);let k=!1;const x=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)},_=()=>{if(k=!0,y(n.field)){((m?u._getRowEntry(m):void 0)?.row??e)[n.field]=C}},A=document.createElement("div");A.className="tbw-editor-host",s.firstElementChild&&u.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.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){const r=e.target,s=v(r);if(s&&s!==r)return;if(h){e.preventDefault();const t=A.querySelector("input,textarea,select");return void(t&&x(c(t,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(),_(),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(E(t.config,d))return;d.stopPropagation(),d.preventDefault(),e=!0,s(c(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",()=>x(t.value)),q(e=>{t.value=e}),A.appendChild(t),d||queueMicrotask(()=>{A.querySelector(p)?.focus({preventScroll:!0})})}else if("function"==typeof G){const i=G({row:e,rowId:m??"",value:D,field:n.field,column:n,commit:x,cancel:_,updateRow:R,onValueChange:q,grid:t.grid});"string"==typeof i?(A.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))))}(A,n,x,C),q(t=>{const e=A.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):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??"")}):s.setAttribute("data-editor-managed","")):!i&&A.hasChildNodes()&&s.setAttribute("data-editor-managed",""),d||queueMicrotask(()=>{A.querySelector(p)?.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),s.setAttribute("data-editor-managed","");const r={row:e,rowId:m??"",value:D,field:n.field,column:n,commit:x,cancel:_,updateRow:R,onValueChange:q,grid:t.grid};if(G.mount)try{G.mount({placeholder:i,context:r,spec:G})}catch(P){(0,o.warnDiagnostic)(o.EDITOR_MOUNT_ERROR,`External editor mount error for column '${n.field}': ${P}`,t.grid.id)}else u.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:G,context:r}}))}}var C=class 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:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};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-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{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}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{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}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;#b=null;#E=new m;#R=new Set;#C;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.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#o,commitCellValue:(t,e,i,n)=>this.#k(t,e,i,n),exitRowEdit:(t,e)=>this.#x(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.#E.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.#x(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.#x(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?.action;if(!e)return;const i=this.rows[e.rowIndex];if(!i)return;const n=this.#S(i);if(!n)return;const r=this.#E.isRowDirty(n,i);this.#M(n,i,r?"modified":"pristine")};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.#S(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('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#b;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.#b={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('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#p=!1,this.#b=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.#G()});this.#G(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(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.#f.clear(),this.#p=!1,this.#v=!1,this.#b=null,this.#y=!1,this.#h=new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#o;if("getCellEditableResolver"===t.type){const t=this.#r.effectiveConfig?.columns??[],e=new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#n(n,i)}}return"commitCellValue"===t.type?this.#D(t.context):void 0}#D(t){const e=this.#r,i=(e._visibleColumns??[]).find(e=>e.field===t.field)??e._columns?.find(e=>e.field===t.field),n=(null!=t.rowId?e._getRowEntry(t.rowId)?.row:void 0)??e._rows?.[t.rowIndex];if(i&&n&&y(t.field)){if("history"===t.source){n[t.field]=t.newValue,(0,r.invalidateAccessorCache)(n,t.field);const e=this.#S(n);if(e&&this.config.dirtyTracking){const t=this.#E.isRowDirty(e,n);t||this.#E.changedRowIds.delete(e),this.#M(e,n,t?"modified":"pristine")}return!0}return this.#k(t.rowIndex,i,t.newValue,n,t.source),n[t.field]===t.newValue}}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;return!!e._columns?.some(t=>this.#s(t))&&(!!this.#L(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.#G(),this.requestAfterRender(),!0;if(-1!==this.#o&&!this.#i)return E(this.config,t)||this.#x(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.#x(this.#o,!1),!0;const e=!t.shiftKey;return this.#T(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.#k(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.#b=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.#L(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}#q(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}#P(){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.#q(t),i=(0,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.#P();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.#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++)if(this.#S(r[o])===i){s=o;break}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#o!==s&&this.#F(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.#F(this.#o,e)}if(this.#g&&(this.#g=!1,this.#V(t)),-1!==this.#w){const e=this.#w;this.#w=-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=this.#O(r,s);if(!o||o.classList.contains("editing"))continue;const d=t._rows[r],l=t._visibleColumns[s];d&&l&&this.#$(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.#$(e,i,n,r,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#E.getRowDirtyState(e,t.row),s=t.rowElement;if(s.classList.toggle("tbw-row-dirty",n),s.classList.toggle("tbw-row-new",i),r){const i=s.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#E.isCellDirty(e,t.row,s))}}else{const t=s.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.#M(t,e,"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.#M(t,e,"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.#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.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#_(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#r._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.#O(t,n);o&&(this.#y=!0,this.#N(t,n,o))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#s(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#L(n)&&(this.#y=!1,this.#j(t,n),Array.from(i.children).forEach((i,r)=>{const s=e._visibleColumns[r];if(s&&this.#n(s,n)){const e=i;e.classList.contains("editing")||this.#$(n,t,s,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(p);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#o&&this.#x(this.#o,!1)}cancelActiveRowEdit(){-1!==this.#o&&this.#x(this.#o,!0)}#S(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#O(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#L(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#M(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:i})}#G(){this.#H();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#z(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#E.changedRowIds.delete(t),this.#E.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)))}#I(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?.findIndex(e=>this.#S(e)===t);if(-1===s||void 0===s)return;const o=this.#O(s,r);if(o)if(i){o.setAttribute("data-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&o.setAttribute("title",i)}else o.removeAttribute("data-invalid"),o.removeAttribute("title")}#F(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.#_()}#N(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.#j(t,r),this.#a=e,this.#$(r,t,s,e,i,!1)))}#H(){const t=this.#b;if(!t)return;const e=this.#r._rows?.[t.rowIndex];e&&(e[t.field]=t.value);const i=`${t.rowIndex}:${t.field}`,n=this.#f.get(i);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),e){const t=this.#S(e);t&&(this.config.dirtyTracking?this.#E.isRowDirty(t,e)||(this.#E.changedRowIds.delete(t),this.#M(t,e,"reverted")):this.#E.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#A(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#O(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())}}#T(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.#O(r,o[d]);return t?.classList.contains("editing")&&t.querySelector(p)?.focus({preventScroll:!0}),void(0,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],(0,i.ensureCellVisible)(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#O(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(p)?.focus({preventScroll:!0})},0)):(this.#x(r,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),(0,i.ensureCellVisible)(e,{forceHorizontalScroll:!0}))}}#_(){const t=this.#r;t._activeEditRows=this.#o,t._rowEditSnapshots=this.#c}#j(t,i){this.#o!==t&&(-1!==this.#o&&this.#x(this.#o,!1),this.#c.set(t,{...i}),this.#o=t,this.#l=i,this.#d=this.#S(i),this.#_(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#d??"",row:i}),(0,e.announce)(this.gridElement,(0,e.getA11yMessage)(this.gridElement,"editingStarted",t))))}#x(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)?.row??this.#l??n._rows[t];if(!o&&d&&(o=this.#S(d)),!i&&s&&d&&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=d[e],n=c(s,r,i);i!==n&&this.#k(t,r,n,d)}}),i||this.#i||!d||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:d}),i&&d)this.#z(o,d,r);else if(!i&&d){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,d),i=o?this.#E.changedRowIds.has(o):e,n=this.emitCancelable("row-commit",{rowIndex:t,rowId:o??"",row:d,oldValue:r,newValue:d,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});n&&r?this.#z(o,d,r):n||(o&&this.config.dirtyTracking&&(this.#E.isRowDirty(o,d)?this.#E.committedDirtyRowIds.add(o):this.#E.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.#V(n),this.#g=!1;!this.#i&&d&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:d,reverted:i}),i||(0,e.announce)(this.gridElement,(0,e.getA11yMessage)(this.gridElement,"editingCommitted",t)))}#k(t,e,i,n,s="user"){const o=e.field;if(!y(o))return;const d=n[o];if(d===i)return;const l=this.#r,a=this.#S(n),c=!a||!this.#E.changedRowIds.has(a),u=a?t=>this.grid.updateRow(a,t,"cascade"):b;let h=!1;const f=a?t=>{h=!0,this.setInvalid(a,o,t??"")}:()=>{},g=`${a??t}\0${o}`;if(this.#R.has(g))return;let w=!1;this.#R.add(g);try{w=this.emitCancelable("cell-commit",{row:n,rowId:a??"",field:o,oldValue:d,value:i,source:s,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:u,setInvalid:f})}finally{this.#R.delete(g)}if(w)return;if(a&&!h&&this.isCellInvalid(a,o)&&this.clearInvalid(a,o),n[o]=i,(0,r.invalidateAccessorCache)(n,o),a&&this.#E.changedRowIds.add(a),this.#_(),this.config.dirtyTracking&&a){const t=this.#E.isRowDirty(a,n);this.#M(a,n,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:o,oldValue:d,newValue:i});const m=l.findRenderedRowElement?.(t);m&&m.classList.add("changed")}#$(t,e,i,n,r,s,o){R(this.#C,t,e,i,n,r,s,o)}#V(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});
2
2
  //# sourceMappingURL=editing.umd.js.map