@toolbox-web/grid 1.23.1 → 1.23.3

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 (74) hide show
  1. package/README.md +2 -2
  2. package/all.js +2 -2
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/types.d.ts +1 -1
  7. package/lib/plugins/clipboard/index.js.map +1 -1
  8. package/lib/plugins/column-virtualization/index.js.map +1 -1
  9. package/lib/plugins/context-menu/index.js.map +1 -1
  10. package/lib/plugins/editing/EditingPlugin.d.ts +19 -122
  11. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  12. package/lib/plugins/editing/editors.d.ts +4 -2
  13. package/lib/plugins/editing/editors.d.ts.map +1 -1
  14. package/lib/plugins/editing/index.d.ts +2 -2
  15. package/lib/plugins/editing/index.d.ts.map +1 -1
  16. package/lib/plugins/editing/index.js +1 -1
  17. package/lib/plugins/editing/index.js.map +1 -1
  18. package/lib/plugins/editing/internal/cell-validation.d.ts +80 -0
  19. package/lib/plugins/editing/internal/cell-validation.d.ts.map +1 -0
  20. package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +77 -0
  21. package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts.map +1 -0
  22. package/lib/plugins/editing/internal/editor-injection.d.ts +33 -0
  23. package/lib/plugins/editing/internal/editor-injection.d.ts.map +1 -0
  24. package/lib/plugins/editing/internal/helpers.d.ts +55 -0
  25. package/lib/plugins/editing/internal/helpers.d.ts.map +1 -0
  26. package/lib/plugins/editing/types.d.ts +20 -0
  27. package/lib/plugins/editing/types.d.ts.map +1 -1
  28. package/lib/plugins/export/index.js.map +1 -1
  29. package/lib/plugins/filtering/FilteringPlugin.d.ts +8 -23
  30. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  31. package/lib/plugins/filtering/filter-panel-date.d.ts +14 -0
  32. package/lib/plugins/filtering/filter-panel-date.d.ts.map +1 -0
  33. package/lib/plugins/filtering/filter-panel-default.d.ts +23 -0
  34. package/lib/plugins/filtering/filter-panel-default.d.ts.map +1 -0
  35. package/lib/plugins/filtering/filter-panel-number.d.ts +14 -0
  36. package/lib/plugins/filtering/filter-panel-number.d.ts.map +1 -0
  37. package/lib/plugins/filtering/index.js +1 -1
  38. package/lib/plugins/filtering/index.js.map +1 -1
  39. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
  40. package/lib/plugins/grouping-columns/grouping-columns.d.ts +7 -0
  41. package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
  42. package/lib/plugins/grouping-columns/index.js +1 -1
  43. package/lib/plugins/grouping-columns/index.js.map +1 -1
  44. package/lib/plugins/grouping-rows/index.js.map +1 -1
  45. package/lib/plugins/master-detail/index.js.map +1 -1
  46. package/lib/plugins/multi-sort/index.js.map +1 -1
  47. package/lib/plugins/pinned-columns/index.js.map +1 -1
  48. package/lib/plugins/pinned-rows/index.js.map +1 -1
  49. package/lib/plugins/pivot/index.js.map +1 -1
  50. package/lib/plugins/print/index.js.map +1 -1
  51. package/lib/plugins/reorder/index.js +1 -1
  52. package/lib/plugins/reorder/index.js.map +1 -1
  53. package/lib/plugins/responsive/index.js +1 -1
  54. package/lib/plugins/responsive/index.js.map +1 -1
  55. package/lib/plugins/row-reorder/index.js +1 -1
  56. package/lib/plugins/row-reorder/index.js.map +1 -1
  57. package/lib/plugins/selection/index.js.map +1 -1
  58. package/lib/plugins/server-side/index.js.map +1 -1
  59. package/lib/plugins/tree/index.js.map +1 -1
  60. package/lib/plugins/undo-redo/index.js.map +1 -1
  61. package/lib/plugins/visibility/index.js.map +1 -1
  62. package/package.json +1 -1
  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
  69. package/umd/plugins/filtering.umd.js +1 -1
  70. package/umd/plugins/filtering.umd.js.map +1 -1
  71. package/umd/plugins/grouping-columns.umd.js +1 -1
  72. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  73. package/umd/plugins/responsive.umd.js +1 -1
  74. package/umd/plugins/responsive.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/internal/keyboard"),require("../../core/internal/rows"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/keyboard","../../core/internal/rows","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_editing={},e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,i,n){"use strict";function o(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="date",t.value instanceof Date?n.valueAsDate=t.value:"string"==typeof t.value&&t.value&&(n.value=t.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 o;if(n.value)"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate);else if(e.nullable)t.commit(null);else{const e=i?.default;"string"==typeof t.value||"string"==typeof e?t.commit("string"==typeof e?e:`${(o=e??new Date).getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`):t.commit(e instanceof Date?e:new Date)}}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}const s="__tbw_null__";function r(e){switch(e.type){case"number":return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="number",n.value=null!=t.value?String(t.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 o=()=>{""===n.value?e.nullable?t.commit(null):t.commit(i?.min??0):t.commit(Number(n.value))};return n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Enter"===e.key&&o(),"Escape"===e.key&&t.cancel()}),n}}(e);case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t};case"date":return o(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),e.nullable||i?.includeEmpty){const o=document.createElement("option");o.value=e.nullable?s:"",o.textContent=e.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==t.value&&(o.selected=!0),n.appendChild(o)}const o=function(e){const t=e.options;return t?"function"==typeof t?t():t:[]}(e);o.forEach(i=>{const o=document.createElement("option");o.value=String(i.value),o.textContent=i.label,e.multi&&Array.isArray(t.value)&&t.value.includes(i.value)?o.selected=!0:e.multi||t.value!==i.value||(o.selected=!0),n.appendChild(o)});const r=()=>{if(e.multi){const e=Array.from(n.selectedOptions).map(e=>e.value);t.commit(e)}else e.nullable&&n.value===s?t.commit(null):t.commit(n.value)};return n.addEventListener("change",r),n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);default:return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="text",n.value=null!=t.value?String(t.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const o=()=>{const i=n.value;""!==i?"string"==typeof t.value&&i===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value?t.commit(Number(i)):t.commit(i)):e.nullable?t.commit(null):t.commit("")};return n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Enter"===e.key&&o(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function d(e,t,i){const n=e.get(t);return!!n&&!a(n,i)}function l(e,t,i,n){const o=e.get(t);if(!o)return!1;return!a(o[n],i[n])}function a(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(typeof e!=typeof t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!a(e[i],t[i]))return!1;return!0}if("object"==typeof e){const i=e,n=t,o=Object.keys(i),s=Object.keys(n);if(o.length!==s.length)return!1;for(const e of o)if(!a(i[e],n[e]))return!1;return!0}return!1}function c(e,t,i){e.set(t,structuredClone(i))}function u(e,t){const i=e.get(t);return i?structuredClone(i):void 0}function h(e,t,i){const n=e.get(t);if(!n)return!1;const o=n,s=i;for(const r of Object.keys(o))s[r]=o[r];return!0}function f(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function g(e,t,i){if(e instanceof HTMLInputElement){if("checkbox"===e.type)return e.checked;if("number"===e.type){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}if("date"===e.type)return e.value?"string"==typeof i?e.value:e.valueAsDate:t?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date;if("number"==typeof i){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}return""===e.value&&null==i?t?.nullable?null:"":"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value}return"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?t?.nullable?null:"":e.value}function w(e){}class m extends n.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>!0===e},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#e(){return"grid"===this.config.mode}#t=-1;#i;#n;#o=-1;#s=new Map;#r=new Set;#d=new Set;#l=new Map;#a=!1;#c=-1;#u=new Map;#h=!1;#f=!1;#g=!1;#w=new Map;#m=!1;#E=new Set;#p=new Set;attach(e){super.attach(e);const t=this.disconnectSignal,n=e;if(n._activeEditRows=-1,n._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=e=>this.resetChangedRows(e),e.beginBulkEdit=(e,t)=>{t&&this.beginCellEdit(e,t)},document.addEventListener("keydown",e=>{if(!this.#e&&"Escape"===e.key&&-1!==this.#t){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}this.#v(this.#t,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",e=>{if(this.#e)return;if(-1===this.#t)return;const t=n.findRenderedRowElement?.(this.#t);if(!t)return;if((e.composedPath&&e.composedPath()||[]).includes(t))return;const i=e.target;if(!i||this.gridElement.contains(i)||!this.grid.containsFocus?.(i)){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}queueMicrotask(()=>{-1!==this.#t&&this.#v(this.#t,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",e=>{if(this.#e)return;if(-1===this.#t)return;const t=e.relatedTarget;t&&this.grid.containsFocus?.(t)||t&&this.gridElement.contains(t)||queueMicrotask(()=>{-1!==this.#t&&this.#R()})},{signal:t}),this.gridElement.addEventListener("cell-change",e=>{const t=e.detail;if("user"===t.source)return;const i=`${t.rowIndex}:${t.field}`,n=this.#l.get(i);n&&n(t.newValue)},{signal:t}),this.config.dirtyTracking){const e=e=>{const t=e.detail,i=t?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const o=this.grid.getRowId(n);if(!o)return;const s=d(this.#w,o,n);this.emit("dirty-change",{rowId:o,row:n,original:u(this.#w,o),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",e=>{const t=this.grid.getRowId(e.row);null!=t&&this.markAsNew(String(t))})}this.#e&&(n._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",e=>{const t=e.target;if(t.matches(i.FOCUSABLE_EDITOR_SELECTOR)){if(this.#f)return t.blur(),void this.gridElement.focus();this.#h=!0}},{signal:t}),this.gridElement.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.gridElement.contains(t)||this.grid.containsFocus?.(t))&&t.matches(i.FOCUSABLE_EDITOR_SELECTOR)||(this.#h=!1)},{signal:t}),this.gridElement.addEventListener("keydown",e=>{if("Escape"===e.key&&this.#h){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#h=!1,this.#f=!0,e.preventDefault(),e.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",e=>{e.target.matches(i.FOCUSABLE_EDITOR_SELECTOR)&&(this.#f=!1)},{signal:t}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#t=-1,this.#i=void 0,this.#n=void 0,this.#o=-1,this.#s.clear(),this.#r.clear(),this.#p.clear(),this.#d.clear(),this.#l.clear(),this.#w.clear(),this.#E.clear(),this.#h=!1,this.#f=!1,this.#g=!1,super.detach()}handleQuery(e){if("isEditing"===e.type)return this.#e||-1!==this.#t}onCellClick(e){if(this.#e)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===e.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:o}=e,s=t._columns?.some(e=>e.editable);return!!s&&(e.originalEvent.stopPropagation(),this.beginBulkEdit(o),!0)}onKeyDown(e){const i=this.grid;if("Escape"===e.key){if(this.#e&&this.#h){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const t=document.activeElement;return t&&this.gridElement.contains(t)&&t.blur(),this.#h=!1,this.requestAfterRender(),!0}if(-1!==this.#t&&!this.#e){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return this.#v(this.#t,!0),!0}}if(this.#e&&!this.#h&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#e&&this.#h&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#t&&!this.#e){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const n=i._rows.length-1,o=this.#t;return this.#v(o,!1),"ArrowDown"===e.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),e.preventDefault(),t.ensureCellVisible(i),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#t||this.#e)){if(e.preventDefault(),this.#g)return this.#v(this.#t,!1),!0;const t=!e.shiftKey;return this.#b(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#t)return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const o=i._visibleColumns[n],s=i._rows[t];if(o?.editable&&"boolean"===o.type&&s){const i=o.field;if(f(i)){const n=!s[i];return this.#y(t,o,n,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#e&&!this.#h)return this.#R(),!0;if(-1!==this.#t){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return!1}const t=this.config.editOn??i.effectiveConfig?.editOn;if(!1===t||"manual"===t)return!1;const n=i._focusRow,o=i._focusCol;if(n>=0){const t=i._columns?.some(e=>e.editable);if(t){const t=i._visibleColumns[o],s=i._rows[n],r=t?.field??"",d=r&&s?s[r]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${o}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:o,field:r,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:o}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#t||this.#e)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const o=i._visibleColumns[n];if(o?.editable&&o.field)return e.preventDefault(),this.beginCellEdit(t,o.field),!0}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return i||n?.getTypeDefault?e.map(e=>{if(!e.type)return e;let t;if(i?.[e.type]?.editorParams&&(t=i[e.type].editorParams),!t&&n?.getTypeDefault){const i=n.getTypeDefault(e.type);i?.editorParams&&(t=i.editorParams)}return t?{...e,editorParams:{...t,...e.editorParams}}:e}):e}processRows(e){const t=this.grid;if(this.config.dirtyTracking&&t.getRowId){const i=this.#w.size;!function(e,t,i){for(const n of t)try{const t=i(n);null==t||e.has(t)||e.set(t,structuredClone(n))}catch{}}(this.#w,e,e=>{try{return t.getRowId?.(e)}catch{return}}),this.#w.size>i&&(this.#m=!0)}if(-1===this.#t||this.#e)return e;const i=this.#i,n=this.#n;if(!i||!n)return e;const o=[...e];let s=-1;for(let r=0;r<o.length;r++)try{if(t.getRowId?.(o[r])===i){s=r;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),o):(o[s]=n,this.#t!==s&&this.#C(this.#t,s),o)}afterRender(){const e=this.grid;if(-1!==this.#t&&this.#n&&!this.#e&&e._rows[this.#t]!==this.#n){const t=e._rows.indexOf(this.#n);if(-1===t)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#C(this.#t,t)}if(this.#a&&(this.#a=!1,this.#I(e)),-1!==this.#c){const t=this.#c;this.#c=-1,e.animateRow?.(t,"change")}if(this.#m&&(this.#m=!1,this.emit("baselines-captured",{count:this.#w.size})),!this.#e&&0!==this.#d.size)for(const t of this.#d){const[i,n]=t.split(":"),o=parseInt(i,10),s=parseInt(n,10),r=e.findRenderedRowElement?.(o);if(!r)continue;const d=r.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=e._rows[o],a=e._visibleColumns[s];l&&a&&this.#k(l,o,a,s,d,!0)}}afterCellRender(e){if(!this.#e)return;const{row:t,rowIndex:i,column:n,colIndex:o,cellElement:s}=e;n.editable&&(s.classList.contains("editing")||this.#k(t,i,n,o,s,!0))}afterRowRender(e){if(!this.config.dirtyTracking)return;const t=this.gridElement,i=t.getRowId?.(e.row);if(!i)return;const n=this.#E.has(i),o=!n&&this.#p.has(i)&&d(this.#w,i,e.row),s=e.rowElement;s.classList.toggle("tbw-row-dirty",o),s.classList.toggle("tbw-row-new",n);if(this.#w.has(i)){const t=s.querySelectorAll(".cell[data-field]");for(let n=0;n<t.length;n++){const o=t[n],s=o.getAttribute("data-field");s&&o.classList.toggle("tbw-cell-dirty",l(this.#w,i,e.row,s))}}else{const e=s.querySelectorAll(".tbw-cell-dirty");for(let t=0;t<e.length;t++)e[t].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#r){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#r)}get activeEditRow(){return this.#t}get activeEditCol(){return this.#o}isRowEditing(e){return this.#t===e}isCellEditing(e,t){return this.#d.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const e=t.getRowId?.(i);return!!e&&this.#r.has(e)}catch{return!1}}isRowChangedById(e){return this.#r.has(e)}isDirty(e){if(!this.config.dirtyTracking)return!1;if(this.#E.has(e))return!0;const t=this.grid.getRow(e);return!!t&&d(this.#w,e,t)}isPristine(e){return!this.isDirty(e)}get dirty(){if(!this.config.dirtyTracking)return!1;if(this.#E.size>0)return!0;const e=this.grid;for(const[t,i]of this.#w){const i=e._getRowEntry(t)?.row;if(i&&d(this.#w,t,i))return!0}return!1}get pristine(){return!this.dirty}markAsPristine(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(c(this.#w,e,t),this.#E.delete(e),this.#r.delete(e),this.#p.delete(e),this.emit("dirty-change",{rowId:e,row:t,original:t,type:"pristine"}))}markAsNew(e){if(!this.config.dirtyTracking)return;this.#E.add(e),this.#p.add(e);const t=this.grid.getRow(e);this.emit("dirty-change",{rowId:e,row:t,original:void 0,type:"new"})}markAsDirty(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(this.#r.add(e),this.#p.add(e),this.emit("dirty-change",{rowId:e,row:t,original:u(this.#w,e),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const e=this.grid;for(const[t]of this.#w){const i=e._getRowEntry(t)?.row;i&&c(this.#w,t,i)}this.#E.clear(),this.#r.clear(),this.#p.clear()}getOriginalRow(e){if(this.config.dirtyTracking)return u(this.#w,e)}hasBaseline(e){return!!this.config.dirtyTracking&&this.#w.has(e)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const e=[],t=this.grid;for(const[i,n]of this.#w){const o=t._getRowEntry(i);o&&d(this.#w,i,o.row)&&e.push({id:i,original:structuredClone(n),current:o.row})}for(const i of this.#E){const n=t._getRowEntry(i);n&&e.push({id:i,original:void 0,current:n.row})}return e}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const e=[],t=this.grid;for(const[i]of this.#w){const n=t._getRowEntry(i);n&&d(this.#w,i,n.row)&&e.push(i)}for(const i of this.#E)e.push(i);return e}revertRow(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);if(!t)return;h(this.#w,e,t)&&(this.#r.delete(e),this.#p.delete(e),this.emit("dirty-change",{rowId:e,row:t,original:u(this.#w,e),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const e=this.grid;for(const[t]of this.#w){const i=e._getRowEntry(t);i&&h(this.#w,t,i.row)}this.#r.clear(),this.#p.clear(),this.requestRender()}setInvalid(e,t,i=""){let n=this.#u.get(e);n||(n=new Map,this.#u.set(e,n)),n.set(t,i),this.#_(e,t,!0)}clearInvalid(e,t){const i=this.#u.get(e);i&&(i.delete(t),0===i.size&&this.#u.delete(e)),this.#_(e,t,!1)}clearRowInvalid(e){const t=this.#u.get(e);if(t){const i=Array.from(t.keys());this.#u.delete(e),i.forEach(t=>this.#_(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#u.entries());this.#u.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#_(e,i,!1))})}isCellInvalid(e,t){return this.#u.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#u.get(e)?.get(t)}hasInvalidCells(e){const t=this.#u.get(e);return!!t&&t.size>0}getInvalidFields(e){return new Map(this.#u.get(e)??[])}#_(e,t,i){const n=this.grid,o=n._visibleColumns?.findIndex(e=>e.field===t);if(-1===o||void 0===o)return;const s=n._rows,r=s?.findIndex(t=>{try{return n.getRowId?.(t)===e}catch{return!1}});if(-1===r||void 0===r)return;const d=n.findRenderedRowElement?.(r),l=d?.querySelector(`.cell[data-col="${o}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#u.get(e)?.get(t);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#r.clear(),this.#p.clear(),this.#S(),e||this.emit("changed-rows-reset",{rows:t,ids:i});const n=this.grid;n._rowPool?.forEach(e=>e.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(e=>e.field===t);if(-1===n)return;const o=i._visibleColumns[n];if(!o?.editable)return;const s=i.findRenderedRowElement?.(e),r=s?.querySelector(`.cell[data-col="${n}"]`);r&&(this.#g=!0,this.#L(e,n,r))}beginBulkEdit(e){const t=this.grid;if(!1===(this.config.editOn??t.effectiveConfig?.editOn))return;const n=t._columns?.some(e=>e.editable);if(!n)return;const o=t.findRenderedRowElement?.(e);if(!o)return;this.#g=!1;const s=t._rows[e];this.#x(e,s),Array.from(o.children).forEach((i,n)=>{const o=t._visibleColumns[n];if(o?.editable){const t=i;t.classList.contains("editing")||this.#k(s,e,o,n,t,!0)}}),setTimeout(()=>{let e=o.querySelector(`.cell[data-col="${t._focusCol}"]`);if(e?.classList.contains("editing")||(e=o.querySelector(".cell.editing")),e?.classList.contains("editing")){const t=e.querySelector(i.FOCUSABLE_EDITOR_SELECTOR);try{t?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#t&&this.#v(this.#t,!1)}cancelActiveRowEdit(){-1!==this.#t&&this.#v(this.#t,!0)}#C(e,t){this.#t=t;const i=new Set,n=`${e}:`;for(const r of this.#d)r.startsWith(n)?i.add(`${t}:${r.substring(n.length)}`):i.add(r);this.#d.clear();for(const r of i)this.#d.add(r);const o=this.#s.get(e);void 0!==o&&(this.#s.delete(e),this.#s.set(t,o));const s=[];for(const[r,d]of this.#l)r.startsWith(n)&&(s.push([`${t}:${r.substring(n.length)}`,d]),this.#l.delete(r));for(const[r,d]of s)this.#l.set(r,d);this.#S()}#L(e,t,i){const n=this.grid,o=n._rows[e],s=n._visibleColumns[t];o&&s?.editable&&(i.classList.contains("editing")||(this.#t!==e&&this.#x(e,o),this.#o=t,this.#k(o,e,s,t,i,!1)))}#R(){const e=this.grid,t=e._focusRow,n=e._focusCol;if(t<0||n<0)return;const o=e.findRenderedRowElement?.(t),s=o?.querySelector(`.cell[data-col="${n}"]`);if(s?.classList.contains("editing")){const e=s.querySelector(i.FOCUSABLE_EDITOR_SELECTOR);e&&(this.#f=!1,e.focus(),this.#h=!0,e instanceof HTMLInputElement&&("text"===e.type||"number"===e.type)&&e.select())}}#b(e){const n=this.grid,o=n._rows,s=this.#e?n._focusRow:this.#t,r=n._visibleColumns.map((e,t)=>e.editable?t:-1).filter(e=>e>=0);if(0===r.length)return;const d=r.indexOf(n._focusCol)+(e?1:-1);if(d>=0&&d<r.length){n._focusCol=r[d];const e=n.findRenderedRowElement?.(s),o=e?.querySelector(`.cell[data-col="${r[d]}"]`);if(o?.classList.contains("editing")){const e=o.querySelector(i.FOCUSABLE_EDITOR_SELECTOR);e?.focus({preventScroll:!0})}return void t.ensureCellVisible(n,{forceHorizontalScroll:!0})}const l=s+(e?1:-1);l>=0&&l<o.length&&(this.#e?(n._focusRow=l,n._focusCol=e?r[0]:r[r.length-1],t.ensureCellVisible(n,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const e=n.findRenderedRowElement?.(l),t=e?.querySelector(`.cell[data-col="${n._focusCol}"]`);if(t?.classList.contains("editing")){const e=t.querySelector(i.FOCUSABLE_EDITOR_SELECTOR);e?.focus({preventScroll:!0})}},0)):(this.#v(s,!1),n._focusRow=l,n._focusCol=e?r[0]:r[r.length-1],this.beginBulkEdit(l),t.ensureCellVisible(n,{forceHorizontalScroll:!0})))}#S(){const e=this.grid;e._activeEditRows=this.#t,e._rowEditSnapshots=this.#s}#x(e,t){if(this.#t!==e){-1!==this.#t&&this.#v(this.#t,!1),this.#s.set(e,{...t}),this.#t=e,this.#n=t;const i=this.grid;try{this.#i=i.getRowId?.(t)??void 0}catch{this.#i=void 0}this.#S(),this.#e||this.emit("edit-open",{rowIndex:e,rowId:this.#i??"",row:t})}}#v(e,t){if(this.#t!==e)return;const i=this.grid,n=this.#s.get(e),o=i.findRenderedRowElement?.(e);let s=this.#i;const r=s?i._getRowEntry(s):void 0,l=r?.row??this.#n??i._rows[e];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!t&&o&&l){o.querySelectorAll(".cell.editing").forEach(t=>{const n=Number(t.getAttribute("data-col"));if(isNaN(n))return;const o=i._visibleColumns[n];if(!o)return;if(t.hasAttribute("data-editor-managed"))return;const s=t.querySelector("input,textarea,select");if(s){const t=o.field,i=l[t],n=g(s,o,i);i!==n&&this.#y(e,o,n,l)}})}if(t||this.#e||!l||this.emit("before-edit-close",{rowIndex:e,rowId:s??"",row:l}),t&&n&&l)Object.keys(n).forEach(e=>{l[e]=n[e]}),s&&(this.#r.delete(s),this.#p.delete(s),this.clearRowInvalid(s));else if(!t&&l){const t=this.#T(n,l),i=s?this.#r.has(s):t,o=this.emitCancelable("row-commit",{rowIndex:e,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});o&&n?(Object.keys(n).forEach(e=>{l[e]=n[e]}),s&&(this.#r.delete(s),this.#p.delete(s),this.clearRowInvalid(s))):o||(s&&this.config.dirtyTracking&&(d(this.#w,s,l)?this.#p.add(s):this.#p.delete(s)),t&&this.isAnimationEnabled&&(this.#c=e))}this.#s.delete(e),this.#t=-1,this.#i=void 0,this.#n=void 0,this.#o=-1,this.#g=!1,this.#S();for(const d of this.#d)d.startsWith(`${e}:`)&&this.#d.delete(d);for(const d of this.#l.keys())d.startsWith(`${e}:`)&&this.#l.delete(d);this.#a=!0,o?(o.querySelectorAll(".cell.editing").forEach(e=>{e.classList.remove("editing"),function(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing")}(e.parentElement)}),i.refreshVirtualWindow(!0)):(this.#I(i),this.#a=!1),!this.#e&&l&&this.emit("edit-close",{rowIndex:e,rowId:s??"",row:l,reverted:t})}#y(e,t,i,n){const o=t.field;if(!f(o))return;const s=n[o];if(s===i)return;const r=this.grid;let l;try{l=this.grid.getRowId(n)}catch{}const a=!l||!this.#r.has(l),c=l?e=>this.grid.updateRow(l,e,"cascade"):w;let h=!1;const g=l?e=>{h=!0,this.setInvalid(l,o,e??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:l??"",field:o,oldValue:s,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:a,updateRow:c,setInvalid:g}))return;if(l&&!h&&this.isCellInvalid(l,o)&&this.clearInvalid(l,o),n[o]=i,l&&this.#r.add(l),this.#S(),this.config.dirtyTracking&&l){const e=d(this.#w,l,n);this.emit("dirty-change",{rowId:l,row:n,original:u(this.#w,l),type:e?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:o,oldValue:s,newValue:i});const m=r.findRenderedRowElement?.(e);m&&m.classList.add("changed")}#k(e,t,n,o,s,d){if(!n.editable)return;if(s.classList.contains("editing"))return;let l;try{l=this.grid.getRowId(e)}catch{}const a=l?e=>this.grid.updateRow(l,e,"cascade"):w,c=f(n.field)?e[n.field]:void 0;s.classList.add("editing"),this.#d.add(`${t}:${o}`);const u=s.parentElement;u&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(u);let h=!1;const m=i=>{if(h||!this.#e&&-1===this.#t)return;const o=this.grid,s=l?o._getRowEntry(l):void 0,r=s?.row??e,d=s?.index??t;this.#y(d,n,i,r)},E=()=>{if(h=!0,f(n.field)){const t=this.grid,i=l?t._getRowEntry(l):void 0;(i?.row??e)[n.field]=c}},p=document.createElement("div");p.className="tbw-editor-host",s.innerHTML="",s.appendChild(p),p.addEventListener("keydown",e=>{if("Enter"===e.key){if(this.#e){e.stopPropagation(),e.preventDefault();const t=p.querySelector("input,textarea,select");return void(t&&m(g(t,n,c)))}if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),h=!0,this.#v(t,!1)}if("Escape"===e.key){if(this.#e)return e.stopPropagation(),void e.preventDefault();if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),E(),this.#v(t,!0)}});const v=n,R=v.__editorTemplate,b=function(e,t){if(t.editor)return t.editor;if(t.__editorTemplate)return"template";if(!t.type)return;const i=e.effectiveConfig?.typeDefaults;if(i?.[t.type]?.editor)return i[t.type].editor;const n=e.__frameworkAdapter;if(n?.getTypeDefault){const e=n.getTypeDefault(t.type);if(e?.editor)return e.editor}}(this.grid,v)??r(n),y=c,C=`${t}:${n.field}`,I=[];this.#l.set(C,e=>{for(const t of I)t(e)});const k=e=>{I.push(e)};if("template"===b&&R)this.#A(p,v,e,c,m,E,d,t),k(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if("string"==typeof b){const e=document.createElement(b);e.value=y,e.addEventListener("change",()=>m(e.value)),k(t=>{e.value=t}),p.appendChild(e),d||queueMicrotask(()=>{const e=p.querySelector(i.FOCUSABLE_EDITOR_SELECTOR);e?.focus({preventScroll:!0})})}else if("function"==typeof b){const t=b({row:e,rowId:l??"",value:y,field:n.field,column:n,commit:m,cancel:E,updateRow:a,onValueChange:k});if("string"==typeof t)p.innerHTML=t,function(e,t,i,n){const o=e.querySelector("input,textarea,select");o&&(o.addEventListener("blur",()=>{i(g(o,t,n))}),o instanceof HTMLInputElement&&"checkbox"===o.type?o.addEventListener("change",()=>i(o.checked)):o instanceof HTMLSelectElement&&o.addEventListener("change",()=>i(g(o,t,n))))}(p,n,m,c),k(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(t instanceof Node){p.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?k(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):s.setAttribute("data-editor-managed","")}else!t&&p.hasChildNodes()&&s.setAttribute("data-editor-managed","");d||queueMicrotask(()=>{const e=p.querySelector(i.FOCUSABLE_EDITOR_SELECTOR);e?.focus({preventScroll:!0})})}else if(b&&"object"==typeof b){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),p.appendChild(t),s.setAttribute("data-editor-managed","");const i={row:e,rowId:l??"",value:y,field:n.field,column:n,commit:m,cancel:E,updateRow:a,onValueChange:k};if(b.mount)try{b.mount({placeholder:t,context:i,spec:b})}catch(_){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,_)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:b,context:i}}))}}#A(e,t,i,n,o,s,r,d){const l=t.__editorTemplate;if(!l)return;const a=l.cloneNode(!0),c=t.__compiledEditor;c?a.innerHTML=c({row:i,value:n,field:t.field,column:t,commit:o,cancel:s}):a.querySelectorAll("*").forEach(e=>{1===e.childNodes.length&&e.firstChild?.nodeType===Node.TEXT_NODE&&(e.textContent=e.textContent?.replace(/{{\s*value\s*}}/g,null==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(e,t)=>{if(!f(t))return"";const n=i[t];return null==n?"":String(n)})||"")});const u=a.querySelector("input,textarea,select");if(u){u instanceof HTMLInputElement&&"checkbox"===u.type?u.checked=!!n:u.value=String(n??"");let e=!1;u.addEventListener("blur",()=>{e||o(g(u,t,n))}),u.addEventListener("keydown",i=>{const r=i;if("Enter"===r.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(r))return}r.stopPropagation(),r.preventDefault(),e=!0,o(g(u,t,n)),this.#v(d,!1)}if("Escape"===r.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(r))return}r.stopPropagation(),r.preventDefault(),s(),this.#v(d,!0)}}),u instanceof HTMLInputElement&&"checkbox"===u.type&&u.addEventListener("change",()=>o(u.checked)),r||setTimeout(()=>u.focus({preventScroll:!0}),0)}e.appendChild(a)}#T(e,t){if(!e)return!1;const i=e,n=t,o=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of o)if(i[s]!==n[s])return!0;return!1}#I(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(e=>e.classList.remove("cell-focus"));const o=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);o&&(o.classList.add("cell-focus"),o.setAttribute("aria-selected","true"),o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1"),o.focus({preventScroll:!0}))}}catch{}})}}e.EditingPlugin=m,e.defaultEditorFor=r,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("../../core/internal/keyboard"),require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/internal/keyboard","../../core/plugin/base-plugin"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid,t.TbwGrid)}(this,function(t,e,i){"use strict";function n(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 r="__tbw_null__";function s(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 n(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 s=document.createElement("option");s.value=t.nullable?r:"",s.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(s.selected=!0),n.appendChild(s)}const s=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);s.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===r?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function o(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 d{#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 l(t,e,i){const n=t.get(e);return!!n&&!a(n,i)}function a(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(!a(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(!a(i[t],n[t]))return!1;return!0}return!1}function c(t,e,i){t.set(e,structuredClone(i))}function u(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 h{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 l(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&&l(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&&!a(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)&&l(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){c(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&&c(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&&l(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&&l(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=u(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&&u(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const g='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function f(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function w(t){}function m(t,e){return!1===t.onBeforeEditClose?.(e)}function v(t,e,i,n,r,d,l){if(!n.editable)return;if(d.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:v}=t;let p;try{p=a.getRowId?.(e)}catch{}const y=p?t=>a.updateRow(p,t,"cascade"):w,E=f(n.field)?e[n.field]:void 0;d.classList.add("editing"),h.add(`${i}:${r}`);const R=d.parentElement;R&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(R);let b=!1;const I=r=>{if(b||!c&&!t.isEditSessionActive())return;const s=p?a._getRowEntry(p):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},C=()=>{if(b=!0,f(n.field)){const t=p?a._getRowEntry(p):void 0;(t?.row??e)[n.field]=E}},k=document.createElement("div");k.className="tbw-editor-host",d.innerHTML="",d.appendChild(k),k.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=k.querySelector("input,textarea,select");return void(t&&I(o(t,n,E)))}if(m(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(m(u,e))return;e.stopPropagation(),e.preventDefault(),C(),t.exitRowEdit(i,!0)}});const x=n,_=x.__editorTemplate,M=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,x)??s(n),S=E,A=`${i}:${n.field}`,L=[];v.set(A,t=>{for(const e of L)e(t)});const D=t=>{L.push(t)};if("template"===M&&_)!function(t,e,i,n,r,s,d,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:d}):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(!f(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(o(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(m(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(o(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(m(t.config,l))return;l.stopPropagation(),l.preventDefault(),d(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,k,x,e,E,I,C,l,i),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof M){const t=document.createElement(M);t.value=S,t.addEventListener("change",()=>I(t.value)),D(e=>{t.value=e}),k.appendChild(t),l||queueMicrotask(()=>{const t=k.querySelector(g);t?.focus({preventScroll:!0})})}else if("function"==typeof M){const t=M({row:e,rowId:p??"",value:S,field:n.field,column:n,commit:I,cancel:C,updateRow:y,onValueChange:D});if("string"==typeof t)k.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(o(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(o(r,e,n))))}(k,n,I,E),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){k.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?D(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):d.setAttribute("data-editor-managed","")}else!t&&k.hasChildNodes()&&d.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=k.querySelector(g);t?.focus({preventScroll:!0})})}else if(M&&"object"==typeof M){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),k.appendChild(t),d.setAttribute("data-editor-managed","");const i={row:e,rowId:p??"",value:S,field:n.field,column:n,commit:I,cancel:C,updateRow:y,onValueChange:D};if(M.mount)try{M.mount({placeholder:t,context:i,spec:M})}catch(T){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,T)}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:M,context:i}}))}}class p extends i.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n=-1;#r;#s;#o=-1;#d=new Map;#l=new Set;#a=new Map;#c=!1;#u=-1;#h;#g=!1;#f=!1;#w=!1;#m=null;#v=new h;#p;attach(t){super.attach(t);const e=this.disconnectSignal,i=t;if(this.#h=new d((t,e,i)=>{this.#y(t,e,i)}),this.#p={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#l,editorValueCallbacks:this.#a,isEditSessionActive:()=>-1!==this.#n,commitCellValue:(t,e,i,n)=>this.#E(t,e,i,n),exitRowEdit:(t,e)=>this.#R(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#n){if(m(this.config,t))return;this.#R(this.#n,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#n)return;const e=i.findRenderedRowElement?.(this.#n);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||m(this.config,t)||queueMicrotask(()=>{-1!==this.#n&&this.#R(this.#n,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#n)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#n&&this.#b()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#a.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#v.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#v.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(g)){if(this.#f)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#m;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#m={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#g=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(g)||(this.#g=!1,this.#m=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#g){if(m(this.config,t))return void queueMicrotask(()=>{if(this.#g){this.#I();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0}});this.#I();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(g)&&(this.#f=!1)},{signal:e}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#d.clear(),this.#v.clear(),this.#l.clear(),this.#a.clear(),this.#g=!1,this.#f=!1,this.#m=null,this.#w=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#n}onCellClick(t){if(this.#i)return!1;const e=this.grid,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(t){const i=this.grid;if("Escape"===t.key){if(this.#i&&this.#g){this.#I();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#g=!1,this.#f=!0,this.requestAfterRender(),!0}if(-1!==this.#n&&!this.#i)return m(this.config,t)||this.#R(this.#n,!0),!0}if(this.#i&&!this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#i&&this.#g&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#n&&!this.#i){if(m(this.config,t))return!0;const n=i._rows.length-1,r=this.#n;return this.#R(r,!1),"ArrowDown"===t.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),t.preventDefault(),e.ensureCellVisible(i),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#n||this.#i)){if(t.preventDefault(),this.#w)return this.#R(this.#n,!1),!0;const e=!t.shiftKey;return this.#C(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#n)return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[e];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(f(i)){const n=!s[i];return this.#E(e,r,n,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#i&&!this.#g)return this.#b(),!0;if(-1!==this.#n)return!!m(this.config,t);const e=this.config.editOn??i.effectiveConfig?.editOn;if(!1===e||"manual"===e)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const e=i._columns?.some(t=>t.editable);if(e){const e=i._visibleColumns[r],s=i._rows[n],o=e?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:t}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===t.key){if(-1!==this.#n||this.#i)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const e=i._focusRow,n=i._focusCol;if(e>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return t.preventDefault(),this.beginCellEdit(e,r.field),!0}return!1}return!1}processColumns(t){const e=this.grid,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.grid;if(this.config.dirtyTracking&&e.getRowId&&this.#v.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#n||this.#i)return t;const i=this.#r,n=this.#s;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#n!==s&&this.#k(this.#n,s),r)}afterRender(){const t=this.grid;if(-1!==this.#n&&this.#s&&!this.#i&&t._rows[this.#n]!==this.#s){const e=t._rows.indexOf(this.#s);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#k(this.#n,e)}if(this.#c&&(this.#c=!1,this.#x(t)),-1!==this.#u){const e=this.#u;this.#u=-1,t.animateRow?.(e,"change")}const e=this.#v.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#l.size)for(const i of this.#l){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#_(l,r,a,s,d,!0)}}afterCellRender(t){if(!this.#i)return;const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable&&(s.classList.contains("editing")||this.#_(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.gridElement,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#v.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#v.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#v.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#v.getChangedRowIds()}get activeEditRow(){return this.#n}get activeEditCol(){return this.#o}isRowEditing(t){return this.#n===t}isCellEditing(t,e){return this.#l.has(`${t}:${e}`)}isRowChanged(t){const e=this.grid,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#v.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#v.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#v.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#v.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.grid;return this.#v.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#v.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#v.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#v.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#v.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#v.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#v.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#v.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#v.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#v.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#v.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#h.setInvalid(t,e,i)}clearInvalid(t,e){this.#h.clearInvalid(t,e)}clearRowInvalid(t){this.#h.clearRowInvalid(t)}clearAllInvalid(){this.#h.clearAllInvalid()}isCellInvalid(t,e){return this.#h.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#h.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#h.hasInvalidCells(t)}getInvalidFields(t){return this.#h.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#v.changedRowIds.clear(),this.#v.committedDirtyRowIds.clear(),this.#M(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.grid;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.grid,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#w=!0,this.#S(t,n,o))}beginBulkEdit(t){const e=this.grid;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#w=!1;const r=e._rows[t];this.#A(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#_(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(g);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#n&&this.#R(this.#n,!1)}cancelActiveRowEdit(){-1!==this.#n&&this.#R(this.#n,!0)}#y(t,e,i){const n=this.grid,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#h.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#k(t,e){this.#n=e;const i=new Set,n=`${t}:`;for(const o of this.#l)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#l.clear();for(const o of i)this.#l.add(o);const r=this.#d.get(t);void 0!==r&&(this.#d.delete(t),this.#d.set(e,r));const s=[];for(const[o,d]of this.#a)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#a.delete(o));for(const[o,d]of s)this.#a.set(o,d);this.#M()}#S(t,e,i){const n=this.grid,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#n!==t&&this.#A(t,r),this.#o=e,this.#_(r,t,s,e,i,!1)))}#I(){const t=this.#m;if(!t)return;const e=this.grid,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#a.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#m=null}#b(){const t=this.grid,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(g);t&&(this.#f=!1,t.focus(),this.#g=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#C(t){const i=this.grid,n=i._rows,r=this.#i?i._focusRow:this.#n,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(t?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const t=i.findRenderedRowElement?.(r),n=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(g);t?.focus({preventScroll:!0})}return void e.ensureCellVisible(i,{forceHorizontalScroll:!0})}const d=r+(t?1:-1);d>=0&&d<n.length&&(this.#i?(i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],e.ensureCellVisible(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(g);t?.focus({preventScroll:!0})}},0)):(this.#R(r,!1),i._focusRow=d,i._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(d),e.ensureCellVisible(i,{forceHorizontalScroll:!0})))}#M(){const t=this.grid;t._activeEditRows=this.#n,t._rowEditSnapshots=this.#d}#A(t,e){if(this.#n!==t){-1!==this.#n&&this.#R(this.#n,!1),this.#d.set(t,{...e}),this.#n=t,this.#s=e;const i=this.grid;try{this.#r=i.getRowId?.(e)??void 0}catch{this.#r=void 0}this.#M(),this.#i||this.emit("edit-open",{rowIndex:t,rowId:this.#r??"",row:e})}}#R(t,e){if(this.#n!==t)return;const i=this.grid,n=this.#d.get(t),r=i.findRenderedRowElement?.(t);let s=this.#r;const d=s?i._getRowEntry(s):void 0,l=d?.row??this.#s??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=o(s,r,i);i!==n&&this.#E(t,r,n,l)}})}if(e||this.#i||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#v.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#v.changedRowIds.delete(s),this.#v.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#v.isRowDirty(s,l)?this.#v.committedDirtyRowIds.add(s):this.#v.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#u=t))}this.#d.delete(t),this.#n=-1,this.#r=void 0,this.#s=void 0,this.#o=-1,this.#w=!1,this.#M();for(const o of this.#l)o.startsWith(`${t}:`)&&this.#l.delete(o);for(const o of this.#a.keys())o.startsWith(`${t}:`)&&this.#a.delete(o);this.#c=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#x(i),this.#c=!1),!this.#i&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#E(t,e,i,n){const r=e.field;if(!f(r))return;const s=n[r];if(s===i)return;const o=this.grid;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#v.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):w;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#v.changedRowIds.add(d),this.#M(),this.config.dirtyTracking&&d){const t=this.#v.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#v.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#_(t,e,i,n,r,s){v(this.#p,t,e,i,n,r,s)}#x(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=p,t.defaultEditorFor=s,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=editing.umd.js.map