@toolbox-web/grid 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/all.js +1483 -1403
  2. package/all.js.map +1 -1
  3. package/index.js +11 -4
  4. package/index.js.map +1 -1
  5. package/lib/core/internal/row-animation.d.ts.map +1 -1
  6. package/lib/core/plugin/types.d.ts +1 -1
  7. package/lib/core/plugin/types.d.ts.map +1 -1
  8. package/lib/core/types.d.ts +44 -1
  9. package/lib/core/types.d.ts.map +1 -1
  10. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +69 -8
  11. package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
  12. package/lib/plugins/clipboard/index.d.ts +1 -1
  13. package/lib/plugins/clipboard/index.d.ts.map +1 -1
  14. package/lib/plugins/clipboard/index.js +257 -192
  15. package/lib/plugins/clipboard/index.js.map +1 -1
  16. package/lib/plugins/clipboard/types.d.ts +31 -0
  17. package/lib/plugins/clipboard/types.d.ts.map +1 -1
  18. package/lib/plugins/column-virtualization/index.js.map +1 -1
  19. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +8 -0
  20. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
  21. package/lib/plugins/context-menu/index.js +75 -60
  22. package/lib/plugins/context-menu/index.js.map +1 -1
  23. package/lib/plugins/context-menu/types.d.ts +7 -0
  24. package/lib/plugins/context-menu/types.d.ts.map +1 -1
  25. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  26. package/lib/plugins/editing/editors.d.ts +2 -2
  27. package/lib/plugins/editing/editors.d.ts.map +1 -1
  28. package/lib/plugins/editing/index.js +420 -381
  29. package/lib/plugins/editing/index.js.map +1 -1
  30. package/lib/plugins/editing/types.d.ts +6 -23
  31. package/lib/plugins/editing/types.d.ts.map +1 -1
  32. package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
  33. package/lib/plugins/export/index.js +75 -66
  34. package/lib/plugins/export/index.js.map +1 -1
  35. package/lib/plugins/filtering/index.d.ts +1 -1
  36. package/lib/plugins/filtering/index.d.ts.map +1 -1
  37. package/lib/plugins/filtering/index.js.map +1 -1
  38. package/lib/plugins/grouping-columns/index.js.map +1 -1
  39. package/lib/plugins/grouping-rows/index.js.map +1 -1
  40. package/lib/plugins/master-detail/index.js.map +1 -1
  41. package/lib/plugins/multi-sort/index.js.map +1 -1
  42. package/lib/plugins/pinned-columns/index.js.map +1 -1
  43. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -0
  44. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
  45. package/lib/plugins/pinned-rows/index.js +118 -87
  46. package/lib/plugins/pinned-rows/index.js.map +1 -1
  47. package/lib/plugins/pinned-rows/pinned-rows.d.ts +2 -1
  48. package/lib/plugins/pinned-rows/pinned-rows.d.ts.map +1 -1
  49. package/lib/plugins/pinned-rows/types.d.ts +23 -2
  50. package/lib/plugins/pinned-rows/types.d.ts.map +1 -1
  51. package/lib/plugins/pivot/index.js.map +1 -1
  52. package/lib/plugins/print/index.js.map +1 -1
  53. package/lib/plugins/reorder/index.js.map +1 -1
  54. package/lib/plugins/responsive/index.js.map +1 -1
  55. package/lib/plugins/row-reorder/index.js.map +1 -1
  56. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  57. package/lib/plugins/selection/index.js +147 -139
  58. package/lib/plugins/selection/index.js.map +1 -1
  59. package/lib/plugins/server-side/index.js.map +1 -1
  60. package/lib/plugins/shared/data-collection.d.ts +33 -0
  61. package/lib/plugins/shared/data-collection.d.ts.map +1 -0
  62. package/lib/plugins/tree/index.js.map +1 -1
  63. package/lib/plugins/undo-redo/index.js.map +1 -1
  64. package/lib/plugins/visibility/index.js.map +1 -1
  65. package/package.json +1 -1
  66. package/umd/grid.all.umd.js +23 -23
  67. package/umd/grid.all.umd.js.map +1 -1
  68. package/umd/grid.umd.js +2 -2
  69. package/umd/grid.umd.js.map +1 -1
  70. package/umd/plugins/clipboard.umd.js +5 -5
  71. package/umd/plugins/clipboard.umd.js.map +1 -1
  72. package/umd/plugins/context-menu.umd.js +1 -1
  73. package/umd/plugins/context-menu.umd.js.map +1 -1
  74. package/umd/plugins/editing.umd.js +1 -1
  75. package/umd/plugins/editing.umd.js.map +1 -1
  76. package/umd/plugins/export.umd.js +7 -7
  77. package/umd/plugins/export.umd.js.map +1 -1
  78. package/umd/plugins/pinned-rows.umd.js +1 -1
  79. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  80. package/umd/plugins/selection.umd.js +2 -2
  81. package/umd/plugins/selection.umd.js.map +1 -1
@@ -1,2 +1,2 @@
1
- (function(v,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("../../core/internal/keyboard"),require("../../core/internal/rows"),require("../../core/plugin/base-plugin")):typeof define=="function"&&define.amd?define(["exports","../../core/internal/keyboard","../../core/internal/rows","../../core/plugin/base-plugin"],y):(v=typeof globalThis<"u"?globalThis:v||self,y(v.TbwGridPlugin_editing={},v.TbwGrid,v.TbwGrid,v.TbwGrid))})(this,(function(v,y,b,A){"use strict";const I="@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}}";function O(l){const e=l.options;return e?typeof e=="function"?e():e:[]}function q(l){return e=>{const t=l.editorParams,i=document.createElement("input");i.type="number",i.value=e.value!=null?String(e.value):"",t?.min!==void 0&&(i.min=String(t.min)),t?.max!==void 0&&(i.max=String(t.max)),t?.step!==void 0&&(i.step=String(t.step)),t?.placeholder&&(i.placeholder=t.placeholder);const r=()=>e.commit(i.value===""?null:Number(i.value));return i.addEventListener("blur",r),i.addEventListener("keydown",n=>{n.key==="Enter"&&r(),n.key==="Escape"&&e.cancel()}),i}}function P(){return l=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!l.value,e.addEventListener("change",()=>l.commit(e.checked)),e}}function B(l){return e=>{const t=l.editorParams,i=document.createElement("input");i.type="date",e.value instanceof Date?i.valueAsDate=e.value:typeof e.value=="string"&&e.value&&(i.value=e.value.split("T")[0]),t?.min&&(i.min=t.min),t?.max&&(i.max=t.max),t?.placeholder&&(i.placeholder=t.placeholder);const r=()=>{typeof e.value=="string"?e.commit(i.value):e.commit(i.valueAsDate)};return i.addEventListener("change",r),i.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),i}}function D(l){return e=>{const t=l.editorParams,i=document.createElement("select");if(l.multi&&(i.multiple=!0),t?.includeEmpty){const s=document.createElement("option");s.value="",s.textContent=t.emptyLabel??"",i.appendChild(s)}O(l).forEach(s=>{const o=document.createElement("option");o.value=String(s.value),o.textContent=s.label,(l.multi&&Array.isArray(e.value)&&e.value.includes(s.value)||!l.multi&&e.value===s.value)&&(o.selected=!0),i.appendChild(o)});const n=()=>{if(l.multi){const s=Array.from(i.selectedOptions).map(o=>o.value);e.commit(s)}else e.commit(i.value)};return i.addEventListener("change",n),i.addEventListener("blur",n),i.addEventListener("keydown",s=>{s.key==="Escape"&&e.cancel()}),i}}function M(l){return e=>{const t=l.editorParams,i=document.createElement("input");i.type="text",i.value=e.value!=null?String(e.value):"",t?.maxLength!==void 0&&(i.maxLength=t.maxLength),t?.pattern&&(i.pattern=t.pattern),t?.placeholder&&(i.placeholder=t.placeholder);const r=()=>{const n=i.value;(e.value===null||e.value===void 0)&&n===""||typeof e.value=="string"&&n===e.value.replace(/[\n\r]/g,"")||(typeof e.value=="number"&&n!==""?e.commit(Number(n)):e.commit(n))};return i.addEventListener("blur",r),i.addEventListener("keydown",n=>{n.key==="Enter"&&r(),n.key==="Escape"&&e.cancel()}),i}}function k(l){switch(l.type){case"number":return q(l);case"boolean":return P();case"date":return B(l);case"select":return D(l);default:return M(l)}}function G(l,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=l.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const r=l.__frameworkAdapter;if(r?.getTypeDefault){const n=r.getTypeDefault(e.type);if(n?.editor)return n.editor}}function _(l){return!(typeof l!="string"||l==="__proto__"||l==="constructor"||l==="prototype")}function H(l){const e=(l.__editingCellCount??0)+1;l.__editingCellCount=e,l.setAttribute("data-has-editing","")}function x(l){l.__editingCellCount=0,l.removeAttribute("data-has-editing")}function C(l,e,t){return l instanceof HTMLInputElement?l.type==="checkbox"?l.checked:l.type==="number"?l.value===""?null:Number(l.value):l.type==="date"?typeof t=="string"?l.value:l.valueAsDate:typeof t=="number"?l.value===""?null:Number(l.value):t==null&&l.value===""||typeof t=="string"&&l.value===t.replace(/[\n\r]/g,"")?t:l.value:e?.type==="number"&&l.value!==""||typeof t=="number"&&l.value!==""?Number(l.value):t==null&&l.value===""?t:l.value}function T(l){}function $(l,e,t,i){const r=l.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{t(C(r,e,i))}),r instanceof HTMLInputElement&&r.type==="checkbox"?r.addEventListener("change",()=>t(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>t(C(r,e,i))))}class N extends A.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>e===!0},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}],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=I;get defaultConfig(){return{mode:"row",editOn:"click"}}get#t(){return this.config.mode==="grid"}#e=-1;#d=-1;#l=new Map;#n=new Set;#o=new Set;#c=!1;#u=-1;#i=new Map;#s=!1;#a=!1;attach(e){super.attach(e);const t=this.disconnectSignal,i=e;i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=r=>this.resetChangedRows(r),e.beginBulkEdit=(r,n)=>{n&&this.beginCellEdit(r,n)},document.addEventListener("keydown",r=>{if(!this.#t&&r.key==="Escape"&&this.#e!==-1){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(r)===!1)return;this.#r(this.#e,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",r=>{if(this.#t||this.#e===-1)return;const n=i.findRenderedRowElement?.(this.#e);!n||(r.composedPath&&r.composedPath()||[]).includes(n)||this.config.onBeforeEditClose&&this.config.onBeforeEditClose(r)===!1||queueMicrotask(()=>{this.#e!==-1&&this.#r(this.#e,!1)})},{signal:t}),this.#t&&(this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",r=>{const n=r.target;if(n.matches(b.FOCUSABLE_EDITOR_SELECTOR)){if(this.#a){n.blur(),this.gridElement.focus();return}this.#s=!0}},{signal:t}),this.gridElement.addEventListener("focusout",r=>{const n=r.relatedTarget;(!n||!this.gridElement.contains(n)||!n.matches(b.FOCUSABLE_EDITOR_SELECTOR))&&(this.#s=!1)},{signal:t}),this.gridElement.addEventListener("keydown",r=>{if(r.key==="Escape"&&this.#s){const n=document.activeElement;n&&this.gridElement.contains(n)&&(n.blur(),this.gridElement.focus()),this.#s=!1,this.#a=!0,r.preventDefault(),r.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",r=>{r.target.matches(b.FOCUSABLE_EDITOR_SELECTOR)&&(this.#a=!1)},{signal:t}))}detach(){this.gridElement.classList.remove("tbw-grid-mode"),this.#e=-1,this.#d=-1,this.#l.clear(),this.#n.clear(),this.#o.clear(),this.#s=!1,this.#a=!1,super.detach()}handleQuery(e){if(e.type==="isEditing")return this.#t||this.#e!==-1}onCellClick(e){if(this.#t)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual"||i!=="click"&&i!=="dblclick")return!1;const r=e.originalEvent.type==="dblclick";if(i==="click"&&r||i==="dblclick"&&!r)return!1;const{rowIndex:n}=e;return t._columns?.some(o=>o.editable)?(e.originalEvent.stopPropagation(),this.beginBulkEdit(n),!0):!1}onKeyDown(e){const t=this.grid;if(e.key==="Escape"){if(this.#t&&this.#s){const i=document.activeElement;return i&&this.gridElement.contains(i)&&i.blur(),this.#s=!1,this.requestAfterRender(),!0}if(this.#e!==-1&&!this.#t)return this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1||this.#r(this.#e,!0),!0}if(this.#t&&!this.#s&&(e.key==="ArrowUp"||e.key==="ArrowDown"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return!1;if((e.key==="ArrowUp"||e.key==="ArrowDown")&&this.#e!==-1&&!this.#t){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1)return!0;const i=t._rows.length-1,r=this.#e;return this.#r(r,!1),e.key==="ArrowDown"?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),y.ensureCellVisible(t),this.requestAfterRender(),!0}if(e.key==="Tab"&&(this.#e!==-1||this.#t)){e.preventDefault();const i=!e.shiftKey;return this.#b(i),!0}if(e.key===" "||e.key==="Spacebar"){if(this.#e!==-1)return!1;const i=t._focusRow,r=t._focusCol;if(i>=0&&r>=0){const n=t._visibleColumns[r],s=t._rows[i];if(n?.editable&&n.type==="boolean"&&s){const o=n.field;if(_(o)){const d=!s[o];return this.#p(i,n,d,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#t&&!this.#s)return this.#v(),!0;if(this.#e!==-1)return!!(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1);const i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual")return!1;const r=t._focusRow,n=t._focusCol;if(r>=0&&t._columns?.some(o=>o.editable)){const o=t._visibleColumns[n],a=t._rows[r],d=o?.field??"",c=d&&a?a[d]:void 0,g=this.gridElement.querySelector(`[data-row="${r}"][data-col="${n}"]`),u=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:r,colIndex:n,field:d,value:c,row:a,cellEl:g,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(u);const E=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:r,col:n}});return this.gridElement.dispatchEvent(E),u.defaultPrevented||E.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(r),!0)}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,r=t.__frameworkAdapter;return!i&&!r?.getTypeDefault?e:e.map(n=>{if(!n.type)return n;let s;if(i?.[n.type]?.editorParams&&(s=i[n.type].editorParams),!s&&r?.getTypeDefault){const o=r.getTypeDefault(n.type);o?.editorParams&&(s=o.editorParams)}return s?{...n,editorParams:{...s,...n.editorParams}}:n})}afterRender(){const e=this.grid;if(this.#c&&(this.#c=!1,this.#m(e)),this.#u!==-1){const t=this.#u;this.#u=-1,e.animateRow?.(t,"change")}if(!this.#t&&this.#o.size!==0)for(const t of this.#o){const[i,r]=t.split(":"),n=parseInt(i,10),s=parseInt(r,10),o=e.findRenderedRowElement?.(n);if(!o)continue;const a=o.querySelector(`.cell[data-col="${s}"]`);if(!a||a.classList.contains("editing"))continue;const d=e._rows[n],c=e._visibleColumns[s];d&&c&&this.#g(d,n,c,s,a,!0)}}afterCellRender(e){if(!this.#t)return;const{row:t,rowIndex:i,column:r,colIndex:n,cellElement:s}=e;r.editable&&(s.classList.contains("editing")||this.#g(t,i,r,n,s,!0))}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#n){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#n)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#d}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#o.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const r=t.getRowId?.(i);return r?this.#n.has(r):!1}catch{return!1}}isRowChangedById(e){return this.#n.has(e)}setInvalid(e,t,i=""){let r=this.#i.get(e);r||(r=new Map,this.#i.set(e,r)),r.set(t,i),this.#f(e,t,!0)}clearInvalid(e,t){const i=this.#i.get(e);i&&(i.delete(t),i.size===0&&this.#i.delete(e)),this.#f(e,t,!1)}clearRowInvalid(e){const t=this.#i.get(e);if(t){const i=Array.from(t.keys());this.#i.delete(e),i.forEach(r=>this.#f(e,r,!1))}}clearAllInvalid(){const e=Array.from(this.#i.entries());this.#i.clear(),e.forEach(([t,i])=>{i.forEach((r,n)=>this.#f(t,n,!1))})}isCellInvalid(e,t){return this.#i.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#i.get(e)?.get(t)}hasInvalidCells(e){const t=this.#i.get(e);return t?t.size>0:!1}getInvalidFields(e){return new Map(this.#i.get(e)??[])}#f(e,t,i){const r=this.grid,n=r._visibleColumns?.findIndex(c=>c.field===t);if(n===-1||n===void 0)return;const o=r._rows?.findIndex(c=>{try{return r.getRowId?.(c)===e}catch{return!1}});if(o===-1||o===void 0)return;const d=r.findRenderedRowElement?.(o)?.querySelector(`.cell[data-col="${n}"]`);if(d)if(i){d.setAttribute("data-invalid","true");const c=this.#i.get(e)?.get(t);c&&d.setAttribute("title",c)}else d.removeAttribute("data-invalid"),d.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#n.clear(),this.#h(),e||this.emit("changed-rows-reset",{rows:t,ids:i}),this.grid._rowPool?.forEach(n=>n.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,r=i._visibleColumns.findIndex(a=>a.field===t);if(r===-1||!i._visibleColumns[r]?.editable)return;const o=i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${r}"]`);o&&this.#w(e,r,o)}beginBulkEdit(e){const t=this.grid;if((this.config.editOn??t.effectiveConfig?.editOn)===!1||!t._columns?.some(o=>o.editable))return;const n=t.findRenderedRowElement?.(e);if(!n)return;const s=t._rows[e];this.#E(e,s),Array.from(n.children).forEach((o,a)=>{const d=t._visibleColumns[a];if(d?.editable){const c=o;c.classList.contains("editing")||this.#g(s,e,d,a,c,!0)}}),setTimeout(()=>{let o=n.querySelector(`.cell[data-col="${t._focusCol}"]`);if(o?.classList.contains("editing")||(o=n.querySelector(".cell.editing")),o?.classList.contains("editing")){const a=o.querySelector(b.FOCUSABLE_EDITOR_SELECTOR);try{a?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){this.#e!==-1&&this.#r(this.#e,!1)}cancelActiveRowEdit(){this.#e!==-1&&this.#r(this.#e,!0)}#w(e,t,i){const r=this.grid,n=r._rows[e],s=r._visibleColumns[t];!n||!s?.editable||i.classList.contains("editing")||(this.#e!==e&&this.#E(e,n),this.#d=t,this.#g(n,e,s,t,i,!1))}#v(){const e=this.grid,t=e._focusRow,i=e._focusCol;if(t<0||i<0)return;const n=e.findRenderedRowElement?.(t)?.querySelector(`.cell[data-col="${i}"]`);if(n?.classList.contains("editing")){const s=n.querySelector(b.FOCUSABLE_EDITOR_SELECTOR);s&&(this.#a=!1,s.focus(),this.#s=!0,s instanceof HTMLInputElement&&(s.type==="text"||s.type==="number")&&s.select())}}#b(e){const t=this.grid,i=t._rows,r=this.#t?t._focusRow:this.#e,n=t._visibleColumns.map((d,c)=>d.editable?c:-1).filter(d=>d>=0);if(n.length===0)return;const o=n.indexOf(t._focusCol)+(e?1:-1);if(o>=0&&o<n.length){t._focusCol=n[o];const c=t.findRenderedRowElement?.(r)?.querySelector(`.cell[data-col="${n[o]}"]`);c?.classList.contains("editing")&&c.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0}),y.ensureCellVisible(t,{forceHorizontalScroll:!0});return}const a=r+(e?1:-1);a>=0&&a<i.length&&(this.#t?(t._focusRow=a,t._focusCol=e?n[0]:n[n.length-1],y.ensureCellVisible(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const c=t.findRenderedRowElement?.(a)?.querySelector(`.cell[data-col="${t._focusCol}"]`);c?.classList.contains("editing")&&c.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0})},0)):(this.#r(r,!1),t._focusRow=a,t._focusCol=e?n[0]:n[n.length-1],this.beginBulkEdit(a),y.ensureCellVisible(t,{forceHorizontalScroll:!0})))}#h(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#l}#E(e,t){if(this.#e!==e&&(this.#l.set(e,{...t}),this.#e=e,this.#h(),!this.#t)){const i=this.grid;let r="";try{r=i.getRowId?.(t)??""}catch{}this.emit("edit-open",{rowIndex:e,rowId:r,row:t})}}#r(e,t){if(this.#e!==e)return;const i=this.grid,r=this.#l.get(e),n=i._rows[e],s=i.findRenderedRowElement?.(e);let o;if(n)try{o=i.getRowId?.(n)}catch{}if(!t&&s&&n&&s.querySelectorAll(".cell.editing").forEach(d=>{const c=Number(d.getAttribute("data-col"));if(isNaN(c))return;const g=i._visibleColumns[c];if(!g||d.hasAttribute("data-editor-managed"))return;const u=d.querySelector("input,textarea,select");if(u){const E=g.field,p=n[E],h=C(u,g,p);p!==h&&this.#p(e,g,h,n)}}),t&&r&&n)Object.keys(r).forEach(a=>{n[a]=r[a]}),o&&(this.#n.delete(o),this.clearRowInvalid(o));else if(!t&&n){const a=this.#C(r,n),d=o?this.#n.has(o):a,c=this.emitCancelable("row-commit",{rowIndex:e,rowId:o??"",row:n,oldValue:r,newValue:n,changed:d,changedRows:this.changedRows,changedRowIds:this.changedRowIds});c&&r?(Object.keys(r).forEach(g=>{n[g]=r[g]}),o&&(this.#n.delete(o),this.clearRowInvalid(o))):!c&&a&&this.isAnimationEnabled&&(this.#u=e)}this.#l.delete(e),this.#e=-1,this.#d=-1,this.#h();for(const a of this.#o)a.startsWith(`${e}:`)&&this.#o.delete(a);s&&(s.querySelectorAll(".cell.editing").forEach(a=>{a.classList.remove("editing"),x(a.parentElement)}),this.requestRender()),this.#c=!0,s||(this.#m(i),this.#c=!1),!this.#t&&n&&this.emit("edit-close",{rowIndex:e,rowId:o??"",row:n,reverted:t})}#p(e,t,i,r){const n=t.field;if(!_(n))return;const s=r[n];if(s===i)return;const o=this.grid;let a;try{a=this.grid.getRowId(r)}catch{}const d=a?!this.#n.has(a):!0,c=a?h=>this.grid.updateRow(a,h,"cascade"):T;let g=!1;const u=a?h=>{g=!0,this.setInvalid(a,n,h??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:r,rowId:a??"",field:n,oldValue:s,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:d,updateRow:c,setInvalid:u}))return;a&&!g&&this.isCellInvalid(a,n)&&this.clearInvalid(a,n),r[n]=i,a&&this.#n.add(a),this.#h(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:n,oldValue:s,newValue:i});const p=o.findRenderedRowElement?.(e);p&&p.classList.add("changed")}#g(e,t,i,r,n,s){if(!i.editable||n.classList.contains("editing"))return;let o;try{o=this.grid.getRowId(e)}catch{}const a=o?f=>this.grid.updateRow(o,f,"cascade"):T,d=_(i.field)?e[i.field]:void 0;n.classList.add("editing"),this.#o.add(`${t}:${r}`);const c=n.parentElement;c&&H(c);let g=!1;const u=f=>{g||!this.#t&&this.#e===-1||this.#p(t,i,f,e)},E=()=>{g=!0,_(i.field)&&(e[i.field]=d)},p=document.createElement("div");p.className="tbw-editor-host",n.innerHTML="",n.appendChild(p),p.addEventListener("keydown",f=>{if(f.key==="Enter"){if(this.#t){f.stopPropagation(),f.preventDefault();const m=p.querySelector("input,textarea,select");m&&u(C(m,i,d));return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(f)===!1)return;f.stopPropagation(),f.preventDefault(),g=!0,this.#r(t,!1)}if(f.key==="Escape"){if(this.#t){f.stopPropagation(),f.preventDefault();return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(f)===!1)return;f.stopPropagation(),f.preventDefault(),E(),this.#r(t,!0)}});const h=i,R=h.__editorTemplate,w=G(this.grid,h)??k(i),S=d;if(w==="template"&&R)this.#y(p,h,e,d,u,E,s,t);else if(typeof w=="string"){const f=document.createElement(w);f.value=S,f.addEventListener("change",()=>u(f.value)),p.appendChild(f),s||queueMicrotask(()=>{p.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0})})}else if(typeof w=="function"){const f={row:e,rowId:o??"",value:S,field:i.field,column:i,commit:u,cancel:E,updateRow:a},m=w(f);typeof m=="string"?(p.innerHTML=m,$(p,i,u,d)):m instanceof Node&&(p.appendChild(m),m instanceof HTMLInputElement||m instanceof HTMLSelectElement||m instanceof HTMLTextAreaElement||n.setAttribute("data-editor-managed","")),s||queueMicrotask(()=>{p.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0})})}else if(w&&typeof w=="object"){const f=document.createElement("div");f.setAttribute("data-external-editor",""),f.setAttribute("data-field",i.field),p.appendChild(f),n.setAttribute("data-editor-managed","");const m={row:e,rowId:o??"",value:S,field:i.field,column:i,commit:u,cancel:E,updateRow:a};if(w.mount)try{w.mount({placeholder:f,context:m,spec:w})}catch(L){console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`,L)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:f,spec:w,context:m}}))}}#y(e,t,i,r,n,s,o,a){const d=t.__editorTemplate;if(!d)return;const c=d.cloneNode(!0),g=t.__compiledEditor;g?c.innerHTML=g({row:i,value:r,field:t.field,column:t,commit:n,cancel:s}):c.querySelectorAll("*").forEach(E=>{E.childNodes.length===1&&E.firstChild?.nodeType===Node.TEXT_NODE&&(E.textContent=E.textContent?.replace(/{{\s*value\s*}}/g,r==null?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(p,h)=>{if(!_(h))return"";const R=i[h];return R==null?"":String(R)})||"")});const u=c.querySelector("input,textarea,select");if(u){u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked=!!r:u.value=String(r??"");let E=!1;u.addEventListener("blur",()=>{E||n(C(u,t,r))}),u.addEventListener("keydown",p=>{const h=p;if(h.key==="Enter"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(h)===!1)return;h.stopPropagation(),h.preventDefault(),E=!0,n(C(u,t,r)),this.#r(a,!1)}if(h.key==="Escape"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(h)===!1)return;h.stopPropagation(),h.preventDefault(),s(),this.#r(a,!0)}}),u instanceof HTMLInputElement&&u.type==="checkbox"&&u.addEventListener("change",()=>n(u.checked)),o||setTimeout(()=>u.focus({preventScroll:!0}),0)}e.appendChild(c)}#C(e,t){if(!e)return!1;const i=e,r=t,n=new Set([...Object.keys(i),...Object.keys(r)]);for(const s of n)if(i[s]!==r[s])return!0;return!1}#m(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,r=e.findRenderedRowElement?.(t);if(r){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(s=>s.classList.remove("cell-focus"));const n=r.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);n&&(n.classList.add("cell-focus"),n.setAttribute("aria-selected","true"),n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}}catch{}})}}v.EditingPlugin=N,v.defaultEditorFor=k,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(v,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("../../core/internal/keyboard"),require("../../core/internal/rows"),require("../../core/plugin/base-plugin")):typeof define=="function"&&define.amd?define(["exports","../../core/internal/keyboard","../../core/internal/rows","../../core/plugin/base-plugin"],y):(v=typeof globalThis<"u"?globalThis:v||self,y(v.TbwGridPlugin_editing={},v.TbwGrid,v.TbwGrid,v.TbwGrid))})(this,(function(v,y,b,q){"use strict";const P="@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}}";function B(l){const e=l.options;return e?typeof e=="function"?e():e:[]}function D(l){return e=>{const t=l.editorParams,i=document.createElement("input");i.type="number",i.value=e.value!=null?String(e.value):"",t?.min!==void 0&&(i.min=String(t.min)),t?.max!==void 0&&(i.max=String(t.max)),t?.step!==void 0&&(i.step=String(t.step)),t?.placeholder&&(i.placeholder=t.placeholder);const s=()=>e.commit(i.value===""?null:Number(i.value));return i.addEventListener("blur",s),i.addEventListener("keydown",n=>{n.key==="Enter"&&s(),n.key==="Escape"&&e.cancel()}),i}}function M(){return l=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!l.value,e.addEventListener("change",()=>l.commit(e.checked)),e}}function H(l){return e=>{const t=l.editorParams,i=document.createElement("input");i.type="date",e.value instanceof Date?i.valueAsDate=e.value:typeof e.value=="string"&&e.value&&(i.value=e.value.split("T")[0]),t?.min&&(i.min=t.min),t?.max&&(i.max=t.max),t?.placeholder&&(i.placeholder=t.placeholder);const s=()=>{typeof e.value=="string"?e.commit(i.value):e.commit(i.valueAsDate)};return i.addEventListener("change",s),i.addEventListener("keydown",n=>{n.key==="Escape"&&e.cancel()}),i}}function $(l){return e=>{const t=l.editorParams,i=document.createElement("select");if(l.multi&&(i.multiple=!0),t?.includeEmpty){const r=document.createElement("option");r.value="",r.textContent=t.emptyLabel??"",i.appendChild(r)}B(l).forEach(r=>{const o=document.createElement("option");o.value=String(r.value),o.textContent=r.label,(l.multi&&Array.isArray(e.value)&&e.value.includes(r.value)||!l.multi&&e.value===r.value)&&(o.selected=!0),i.appendChild(o)});const n=()=>{if(l.multi){const r=Array.from(i.selectedOptions).map(o=>o.value);e.commit(r)}else e.commit(i.value)};return i.addEventListener("change",n),i.addEventListener("blur",n),i.addEventListener("keydown",r=>{r.key==="Escape"&&e.cancel()}),i}}function x(l){return e=>{const t=l.editorParams,i=document.createElement("input");i.type="text",i.value=e.value!=null?String(e.value):"",t?.maxLength!==void 0&&(i.maxLength=t.maxLength),t?.pattern&&(i.pattern=t.pattern),t?.placeholder&&(i.placeholder=t.placeholder);const s=()=>{const n=i.value;(e.value===null||e.value===void 0)&&n===""||typeof e.value=="string"&&n===e.value.replace(/[\n\r]/g,"")||(typeof e.value=="number"&&n!==""?e.commit(Number(n)):e.commit(n))};return i.addEventListener("blur",s),i.addEventListener("keydown",n=>{n.key==="Enter"&&s(),n.key==="Escape"&&e.cancel()}),i}}function A(l){switch(l.type){case"number":return D(l);case"boolean":return M();case"date":return H(l);case"select":return $(l);default:return x(l)}}function G(l,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=l.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const s=l.__frameworkAdapter;if(s?.getTypeDefault){const n=s.getTypeDefault(e.type);if(n?.editor)return n.editor}}function k(l){return!(typeof l!="string"||l==="__proto__"||l==="constructor"||l==="prototype")}function N(l){const e=(l.__editingCellCount??0)+1;l.__editingCellCount=e,l.setAttribute("data-has-editing","")}function F(l){l.__editingCellCount=0,l.removeAttribute("data-has-editing")}function R(l,e,t){return l instanceof HTMLInputElement?l.type==="checkbox"?l.checked:l.type==="number"?l.value===""?null:Number(l.value):l.type==="date"?typeof t=="string"?l.value:l.valueAsDate:typeof t=="number"?l.value===""?null:Number(l.value):t==null&&l.value===""||typeof t=="string"&&l.value===t.replace(/[\n\r]/g,"")?t:l.value:e?.type==="number"&&l.value!==""||typeof t=="number"&&l.value!==""?Number(l.value):t==null&&l.value===""?t:l.value}function I(l){}function j(l,e,t,i){const s=l.querySelector("input,textarea,select");s&&(s.addEventListener("blur",()=>{t(R(s,e,i))}),s instanceof HTMLInputElement&&s.type==="checkbox"?s.addEventListener("change",()=>t(s.checked)):s instanceof HTMLSelectElement&&s.addEventListener("change",()=>t(R(s,e,i))))}class U extends q.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>e===!0},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'}],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=P;get defaultConfig(){return{mode:"row",editOn:"click"}}get#t(){return this.config.mode==="grid"}#e=-1;#d=-1;#l=new Map;#n=new Set;#o=new Set;#a=new Map;#u=!1;#f=-1;#i=new Map;#r=!1;#c=!1;attach(e){super.attach(e);const t=this.disconnectSignal,i=e;i._activeEditRows=-1,i._rowEditSnapshots=new Map,Object.defineProperty(e,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(e,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),e.resetChangedRows=s=>this.resetChangedRows(s),e.beginBulkEdit=(s,n)=>{n&&this.beginCellEdit(s,n)},document.addEventListener("keydown",s=>{if(!this.#t&&s.key==="Escape"&&this.#e!==-1){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(s)===!1)return;this.#s(this.#e,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",s=>{if(this.#t||this.#e===-1)return;const n=i.findRenderedRowElement?.(this.#e);!n||(s.composedPath&&s.composedPath()||[]).includes(n)||this.config.onBeforeEditClose&&this.config.onBeforeEditClose(s)===!1||queueMicrotask(()=>{this.#e!==-1&&this.#s(this.#e,!1)})},{signal:t}),this.gridElement.addEventListener("cell-change",s=>{const n=s.detail;if(n.source==="user")return;const r=`${n.rowIndex}:${n.field}`,o=this.#a.get(r);o&&o(n.newValue)},{signal:t}),this.#t&&(this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",s=>{const n=s.target;if(n.matches(b.FOCUSABLE_EDITOR_SELECTOR)){if(this.#c){n.blur(),this.gridElement.focus();return}this.#r=!0}},{signal:t}),this.gridElement.addEventListener("focusout",s=>{const n=s.relatedTarget;(!n||!this.gridElement.contains(n)||!n.matches(b.FOCUSABLE_EDITOR_SELECTOR))&&(this.#r=!1)},{signal:t}),this.gridElement.addEventListener("keydown",s=>{if(s.key==="Escape"&&this.#r){const n=document.activeElement;n&&this.gridElement.contains(n)&&(n.blur(),this.gridElement.focus()),this.#r=!1,this.#c=!0,s.preventDefault(),s.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",s=>{s.target.matches(b.FOCUSABLE_EDITOR_SELECTOR)&&(this.#c=!1)},{signal:t}))}detach(){this.gridElement.classList.remove("tbw-grid-mode"),this.#e=-1,this.#d=-1,this.#l.clear(),this.#n.clear(),this.#o.clear(),this.#a.clear(),this.#r=!1,this.#c=!1,super.detach()}handleQuery(e){if(e.type==="isEditing")return this.#t||this.#e!==-1}onCellClick(e){if(this.#t)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual"||i!=="click"&&i!=="dblclick")return!1;const s=e.originalEvent.type==="dblclick";if(i==="click"&&s||i==="dblclick"&&!s)return!1;const{rowIndex:n}=e;return t._columns?.some(o=>o.editable)?(e.originalEvent.stopPropagation(),this.beginBulkEdit(n),!0):!1}onKeyDown(e){const t=this.grid;if(e.key==="Escape"){if(this.#t&&this.#r){const i=document.activeElement;return i&&this.gridElement.contains(i)&&i.blur(),this.#r=!1,this.requestAfterRender(),!0}if(this.#e!==-1&&!this.#t)return this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1||this.#s(this.#e,!0),!0}if(this.#t&&!this.#r&&(e.key==="ArrowUp"||e.key==="ArrowDown"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return!1;if((e.key==="ArrowUp"||e.key==="ArrowDown")&&this.#e!==-1&&!this.#t){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1)return!0;const i=t._rows.length-1,s=this.#e;return this.#s(s,!1),e.key==="ArrowDown"?t._focusRow=Math.min(i,t._focusRow+1):t._focusRow=Math.max(0,t._focusRow-1),e.preventDefault(),y.ensureCellVisible(t),this.requestAfterRender(),!0}if(e.key==="Tab"&&(this.#e!==-1||this.#t)){e.preventDefault();const i=!e.shiftKey;return this.#y(i),!0}if(e.key===" "||e.key==="Spacebar"){if(this.#e!==-1)return!1;const i=t._focusRow,s=t._focusCol;if(i>=0&&s>=0){const n=t._visibleColumns[s],r=t._rows[i];if(n?.editable&&n.type==="boolean"&&r){const o=n.field;if(k(o)){const c=!r[o];return this.#E(i,n,c,r),e.preventDefault(),this.requestRender(),!0}}}return!1}if(e.key==="Enter"&&!e.shiftKey){if(this.#t&&!this.#r)return this.#b(),!0;if(this.#e!==-1)return!!(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(e)===!1);const i=this.config.editOn??t.effectiveConfig?.editOn;if(i===!1||i==="manual")return!1;const s=t._focusRow,n=t._focusCol;if(s>=0&&t._columns?.some(o=>o.editable)){const o=t._visibleColumns[n],a=t._rows[s],c=o?.field??"",d=c&&a?a[c]:void 0,E=this.gridElement.querySelector(`[data-row="${s}"][data-col="${n}"]`),h=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:s,colIndex:n,field:c,value:d,row:a,cellEl:E,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(h);const m=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:s,col:n}});return this.gridElement.dispatchEvent(m),h.defaultPrevented||m.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(s),!0)}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,s=t.__frameworkAdapter;return!i&&!s?.getTypeDefault?e:e.map(n=>{if(!n.type)return n;let r;if(i?.[n.type]?.editorParams&&(r=i[n.type].editorParams),!r&&s?.getTypeDefault){const o=s.getTypeDefault(n.type);o?.editorParams&&(r=o.editorParams)}return r?{...n,editorParams:{...r,...n.editorParams}}:n})}afterRender(){const e=this.grid;if(this.#u&&(this.#u=!1,this.#w(e)),this.#f!==-1){const t=this.#f;this.#f=-1,e.animateRow?.(t,"change")}if(!this.#t&&this.#o.size!==0)for(const t of this.#o){const[i,s]=t.split(":"),n=parseInt(i,10),r=parseInt(s,10),o=e.findRenderedRowElement?.(n);if(!o)continue;const a=o.querySelector(`.cell[data-col="${r}"]`);if(!a||a.classList.contains("editing"))continue;const c=e._rows[n],d=e._visibleColumns[r];c&&d&&this.#p(c,n,d,r,a,!0)}}afterCellRender(e){if(!this.#t)return;const{row:t,rowIndex:i,column:s,colIndex:n,cellElement:r}=e;s.editable&&(r.classList.contains("editing")||this.#p(t,i,s,n,r,!0))}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#n){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#n)}get activeEditRow(){return this.#e}get activeEditCol(){return this.#d}isRowEditing(e){return this.#e===e}isCellEditing(e,t){return this.#o.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const s=t.getRowId?.(i);return s?this.#n.has(s):!1}catch{return!1}}isRowChangedById(e){return this.#n.has(e)}setInvalid(e,t,i=""){let s=this.#i.get(e);s||(s=new Map,this.#i.set(e,s)),s.set(t,i),this.#h(e,t,!0)}clearInvalid(e,t){const i=this.#i.get(e);i&&(i.delete(t),i.size===0&&this.#i.delete(e)),this.#h(e,t,!1)}clearRowInvalid(e){const t=this.#i.get(e);if(t){const i=Array.from(t.keys());this.#i.delete(e),i.forEach(s=>this.#h(e,s,!1))}}clearAllInvalid(){const e=Array.from(this.#i.entries());this.#i.clear(),e.forEach(([t,i])=>{i.forEach((s,n)=>this.#h(t,n,!1))})}isCellInvalid(e,t){return this.#i.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#i.get(e)?.get(t)}hasInvalidCells(e){const t=this.#i.get(e);return t?t.size>0:!1}getInvalidFields(e){return new Map(this.#i.get(e)??[])}#h(e,t,i){const s=this.grid,n=s._visibleColumns?.findIndex(d=>d.field===t);if(n===-1||n===void 0)return;const o=s._rows?.findIndex(d=>{try{return s.getRowId?.(d)===e}catch{return!1}});if(o===-1||o===void 0)return;const c=s.findRenderedRowElement?.(o)?.querySelector(`.cell[data-col="${n}"]`);if(c)if(i){c.setAttribute("data-invalid","true");const d=this.#i.get(e)?.get(t);d&&c.setAttribute("title",d)}else c.removeAttribute("data-invalid"),c.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#n.clear(),this.#g(),e||this.emit("changed-rows-reset",{rows:t,ids:i}),this.grid._rowPool?.forEach(n=>n.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,s=i._visibleColumns.findIndex(a=>a.field===t);if(s===-1||!i._visibleColumns[s]?.editable)return;const o=i.findRenderedRowElement?.(e)?.querySelector(`.cell[data-col="${s}"]`);o&&this.#v(e,s,o)}beginBulkEdit(e){const t=this.grid;if((this.config.editOn??t.effectiveConfig?.editOn)===!1||!t._columns?.some(o=>o.editable))return;const n=t.findRenderedRowElement?.(e);if(!n)return;const r=t._rows[e];this.#m(e,r),Array.from(n.children).forEach((o,a)=>{const c=t._visibleColumns[a];if(c?.editable){const d=o;d.classList.contains("editing")||this.#p(r,e,c,a,d,!0)}}),setTimeout(()=>{let o=n.querySelector(`.cell[data-col="${t._focusCol}"]`);if(o?.classList.contains("editing")||(o=n.querySelector(".cell.editing")),o?.classList.contains("editing")){const a=o.querySelector(b.FOCUSABLE_EDITOR_SELECTOR);try{a?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){this.#e!==-1&&this.#s(this.#e,!1)}cancelActiveRowEdit(){this.#e!==-1&&this.#s(this.#e,!0)}#v(e,t,i){const s=this.grid,n=s._rows[e],r=s._visibleColumns[t];!n||!r?.editable||i.classList.contains("editing")||(this.#e!==e&&this.#m(e,n),this.#d=t,this.#p(n,e,r,t,i,!1))}#b(){const e=this.grid,t=e._focusRow,i=e._focusCol;if(t<0||i<0)return;const n=e.findRenderedRowElement?.(t)?.querySelector(`.cell[data-col="${i}"]`);if(n?.classList.contains("editing")){const r=n.querySelector(b.FOCUSABLE_EDITOR_SELECTOR);r&&(this.#c=!1,r.focus(),this.#r=!0,r instanceof HTMLInputElement&&(r.type==="text"||r.type==="number")&&r.select())}}#y(e){const t=this.grid,i=t._rows,s=this.#t?t._focusRow:this.#e,n=t._visibleColumns.map((c,d)=>c.editable?d:-1).filter(c=>c>=0);if(n.length===0)return;const o=n.indexOf(t._focusCol)+(e?1:-1);if(o>=0&&o<n.length){t._focusCol=n[o];const d=t.findRenderedRowElement?.(s)?.querySelector(`.cell[data-col="${n[o]}"]`);d?.classList.contains("editing")&&d.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0}),y.ensureCellVisible(t,{forceHorizontalScroll:!0});return}const a=s+(e?1:-1);a>=0&&a<i.length&&(this.#t?(t._focusRow=a,t._focusCol=e?n[0]:n[n.length-1],y.ensureCellVisible(t,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const d=t.findRenderedRowElement?.(a)?.querySelector(`.cell[data-col="${t._focusCol}"]`);d?.classList.contains("editing")&&d.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0})},0)):(this.#s(s,!1),t._focusRow=a,t._focusCol=e?n[0]:n[n.length-1],this.beginBulkEdit(a),y.ensureCellVisible(t,{forceHorizontalScroll:!0})))}#g(){const e=this.grid;e._activeEditRows=this.#e,e._rowEditSnapshots=this.#l}#m(e,t){if(this.#e!==e&&(this.#l.set(e,{...t}),this.#e=e,this.#g(),!this.#t)){const i=this.grid;let s="";try{s=i.getRowId?.(t)??""}catch{}this.emit("edit-open",{rowIndex:e,rowId:s,row:t})}}#s(e,t){if(this.#e!==e)return;const i=this.grid,s=this.#l.get(e),n=i._rows[e],r=i.findRenderedRowElement?.(e);let o;if(n)try{o=i.getRowId?.(n)}catch{}if(!t&&r&&n&&r.querySelectorAll(".cell.editing").forEach(c=>{const d=Number(c.getAttribute("data-col"));if(isNaN(d))return;const E=i._visibleColumns[d];if(!E||c.hasAttribute("data-editor-managed"))return;const h=c.querySelector("input,textarea,select");if(h){const m=E.field,g=n[m],p=R(h,E,g);g!==p&&this.#E(e,E,p,n)}}),t&&s&&n)Object.keys(s).forEach(a=>{n[a]=s[a]}),o&&(this.#n.delete(o),this.clearRowInvalid(o));else if(!t&&n){const a=this.#R(s,n),c=o?this.#n.has(o):a,d=this.emitCancelable("row-commit",{rowIndex:e,rowId:o??"",row:n,oldValue:s,newValue:n,changed:c,changedRows:this.changedRows,changedRowIds:this.changedRowIds});d&&s?(Object.keys(s).forEach(E=>{n[E]=s[E]}),o&&(this.#n.delete(o),this.clearRowInvalid(o))):!d&&a&&this.isAnimationEnabled&&(this.#f=e)}this.#l.delete(e),this.#e=-1,this.#d=-1,this.#g();for(const a of this.#o)a.startsWith(`${e}:`)&&this.#o.delete(a);for(const a of this.#a.keys())a.startsWith(`${e}:`)&&this.#a.delete(a);r&&(r.querySelectorAll(".cell.editing").forEach(a=>{a.classList.remove("editing"),F(a.parentElement)}),this.requestRender()),this.#u=!0,r||(this.#w(i),this.#u=!1),!this.#t&&n&&this.emit("edit-close",{rowIndex:e,rowId:o??"",row:n,reverted:t})}#E(e,t,i,s){const n=t.field;if(!k(n))return;const r=s[n];if(r===i)return;const o=this.grid;let a;try{a=this.grid.getRowId(s)}catch{}const c=a?!this.#n.has(a):!0,d=a?p=>this.grid.updateRow(a,p,"cascade"):I;let E=!1;const h=a?p=>{E=!0,this.setInvalid(a,n,p??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:s,rowId:a??"",field:n,oldValue:r,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:d,setInvalid:h}))return;a&&!E&&this.isCellInvalid(a,n)&&this.clearInvalid(a,n),s[n]=i,a&&this.#n.add(a),this.#g(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:n,oldValue:r,newValue:i});const g=o.findRenderedRowElement?.(e);g&&g.classList.add("changed")}#p(e,t,i,s,n,r){if(!i.editable||n.classList.contains("editing"))return;let o;try{o=this.grid.getRowId(e)}catch{}const a=o?u=>this.grid.updateRow(o,u,"cascade"):I,c=k(i.field)?e[i.field]:void 0;n.classList.add("editing"),this.#o.add(`${t}:${s}`);const d=n.parentElement;d&&N(d);let E=!1;const h=u=>{E||!this.#t&&this.#e===-1||this.#E(t,i,u,e)},m=()=>{E=!0,k(i.field)&&(e[i.field]=c)},g=document.createElement("div");g.className="tbw-editor-host",n.innerHTML="",n.appendChild(g),g.addEventListener("keydown",u=>{if(u.key==="Enter"){if(this.#t){u.stopPropagation(),u.preventDefault();const f=g.querySelector("input,textarea,select");f&&h(R(f,i,c));return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(u)===!1)return;u.stopPropagation(),u.preventDefault(),E=!0,this.#s(t,!1)}if(u.key==="Escape"){if(this.#t){u.stopPropagation(),u.preventDefault();return}if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(u)===!1)return;u.stopPropagation(),u.preventDefault(),m(),this.#s(t,!0)}});const p=i,_=p.__editorTemplate,w=G(this.grid,p)??A(i),T=c,z=`${t}:${i.field}`,O=[];this.#a.set(z,u=>{for(const f of O)f(u)});const S=u=>{O.push(u)};if(w==="template"&&_)this.#C(g,p,e,c,h,m,r,t),S(u=>{const f=g.querySelector("input,textarea,select");f&&(f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked=!!u:f.value=String(u??""))});else if(typeof w=="string"){const u=document.createElement(w);u.value=T,u.addEventListener("change",()=>h(u.value)),S(f=>{u.value=f}),g.appendChild(u),r||queueMicrotask(()=>{g.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0})})}else if(typeof w=="function"){const u={row:e,rowId:o??"",value:T,field:i.field,column:i,commit:h,cancel:m,updateRow:a,onValueChange:S},f=w(u);typeof f=="string"?(g.innerHTML=f,j(g,i,h,c),S(L=>{const C=g.querySelector("input,textarea,select");C&&(C instanceof HTMLInputElement&&C.type==="checkbox"?C.checked=!!L:C.value=String(L??""))})):f instanceof Node&&(g.appendChild(f),f instanceof HTMLInputElement||f instanceof HTMLSelectElement||f instanceof HTMLTextAreaElement?S(C=>{f instanceof HTMLInputElement&&f.type==="checkbox"?f.checked=!!C:f.value=String(C??"")}):n.setAttribute("data-editor-managed","")),r||queueMicrotask(()=>{g.querySelector(b.FOCUSABLE_EDITOR_SELECTOR)?.focus({preventScroll:!0})})}else if(w&&typeof w=="object"){const u=document.createElement("div");u.setAttribute("data-external-editor",""),u.setAttribute("data-field",i.field),g.appendChild(u),n.setAttribute("data-editor-managed","");const f={row:e,rowId:o??"",value:T,field:i.field,column:i,commit:h,cancel:m,updateRow:a,onValueChange:S};if(w.mount)try{w.mount({placeholder:u,context:f,spec:w})}catch(L){console.warn(`[tbw-grid] External editor mount error for column '${i.field}':`,L)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:u,spec:w,context:f}}))}}#C(e,t,i,s,n,r,o,a){const c=t.__editorTemplate;if(!c)return;const d=c.cloneNode(!0),E=t.__compiledEditor;E?d.innerHTML=E({row:i,value:s,field:t.field,column:t,commit:n,cancel:r}):d.querySelectorAll("*").forEach(m=>{m.childNodes.length===1&&m.firstChild?.nodeType===Node.TEXT_NODE&&(m.textContent=m.textContent?.replace(/{{\s*value\s*}}/g,s==null?"":String(s)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(g,p)=>{if(!k(p))return"";const _=i[p];return _==null?"":String(_)})||"")});const h=d.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&h.type==="checkbox"?h.checked=!!s:h.value=String(s??"");let m=!1;h.addEventListener("blur",()=>{m||n(R(h,t,s))}),h.addEventListener("keydown",g=>{const p=g;if(p.key==="Enter"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(p)===!1)return;p.stopPropagation(),p.preventDefault(),m=!0,n(R(h,t,s)),this.#s(a,!1)}if(p.key==="Escape"){if(this.config.onBeforeEditClose&&this.config.onBeforeEditClose(p)===!1)return;p.stopPropagation(),p.preventDefault(),r(),this.#s(a,!0)}}),h instanceof HTMLInputElement&&h.type==="checkbox"&&h.addEventListener("change",()=>n(h.checked)),o||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(d)}#R(e,t){if(!e)return!1;const i=e,s=t,n=new Set([...Object.keys(i),...Object.keys(s)]);for(const r of n)if(i[r]!==s[r])return!0;return!1}#w(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,s=e.findRenderedRowElement?.(t);if(s){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(r=>r.classList.remove("cell-focus"));const n=s.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);n&&(n.classList.add("cell-focus"),n.setAttribute("aria-selected","true"),n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}}catch{}})}}v.EditingPlugin=U,v.defaultEditorFor=A,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=editing.umd.js.map