@toolbox-web/grid 3.9.2 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/all.js +1 -1
  2. package/all.js.map +1 -1
  3. package/index.js +1 -1
  4. package/index.js.map +1 -1
  5. package/lib/core/types.d.ts +6 -3
  6. package/lib/features/clipboard.js.map +1 -1
  7. package/lib/features/column-virtualization.js.map +1 -1
  8. package/lib/features/context-menu.js.map +1 -1
  9. package/lib/features/editing.js.map +1 -1
  10. package/lib/features/export.js.map +1 -1
  11. package/lib/features/filtering.js.map +1 -1
  12. package/lib/features/grouping-columns.js.map +1 -1
  13. package/lib/features/grouping-rows.js.map +1 -1
  14. package/lib/features/master-detail.js.map +1 -1
  15. package/lib/features/multi-sort.js.map +1 -1
  16. package/lib/features/pinned-columns.js.map +1 -1
  17. package/lib/features/pinned-rows.js.map +1 -1
  18. package/lib/features/pivot.js.map +1 -1
  19. package/lib/features/print.js.map +1 -1
  20. package/lib/features/registry.js +1 -1
  21. package/lib/features/registry.js.map +1 -1
  22. package/lib/features/reorder-columns.js.map +1 -1
  23. package/lib/features/responsive.js.map +1 -1
  24. package/lib/features/row-drag-drop.js.map +1 -1
  25. package/lib/features/selection.js.map +1 -1
  26. package/lib/features/server-side.js.map +1 -1
  27. package/lib/features/shell.js.map +1 -1
  28. package/lib/features/sticky-rows.js.map +1 -1
  29. package/lib/features/tooltip.js.map +1 -1
  30. package/lib/features/tree.js.map +1 -1
  31. package/lib/features/undo-redo.js.map +1 -1
  32. package/lib/features/visibility.js.map +1 -1
  33. package/lib/plugins/clipboard/index.js.map +1 -1
  34. package/lib/plugins/column-virtualization/index.js.map +1 -1
  35. package/lib/plugins/context-menu/index.js.map +1 -1
  36. package/lib/plugins/editing/editors.d.ts +15 -0
  37. package/lib/plugins/editing/index.js +1 -1
  38. package/lib/plugins/editing/index.js.map +1 -1
  39. package/lib/plugins/editing/internal/helpers.d.ts +23 -0
  40. package/lib/plugins/editing/types.d.ts +16 -1
  41. package/lib/plugins/export/index.js +1 -1
  42. package/lib/plugins/export/index.js.map +1 -1
  43. package/lib/plugins/filtering/filter-model.d.ts +20 -1
  44. package/lib/plugins/filtering/filter-panel-default.d.ts +15 -1
  45. package/lib/plugins/filtering/index.d.ts +1 -1
  46. package/lib/plugins/filtering/index.js +1 -1
  47. package/lib/plugins/filtering/index.js.map +1 -1
  48. package/lib/plugins/filtering/types.d.ts +58 -3
  49. package/lib/plugins/grouping-columns/index.js.map +1 -1
  50. package/lib/plugins/grouping-rows/index.js +1 -1
  51. package/lib/plugins/grouping-rows/index.js.map +1 -1
  52. package/lib/plugins/hierarchy/index.js.map +1 -1
  53. package/lib/plugins/master-detail/index.js +1 -1
  54. package/lib/plugins/master-detail/index.js.map +1 -1
  55. package/lib/plugins/master-detail/master-detail-plugin.d.ts +6 -1
  56. package/lib/plugins/multi-sort/index.js.map +1 -1
  57. package/lib/plugins/pinned-columns/index.js.map +1 -1
  58. package/lib/plugins/pinned-rows/index.js.map +1 -1
  59. package/lib/plugins/pivot/index.js +1 -1
  60. package/lib/plugins/pivot/index.js.map +1 -1
  61. package/lib/plugins/pivot/pivot-plugin.d.ts +2 -0
  62. package/lib/plugins/pivot/types.d.ts +2 -0
  63. package/lib/plugins/print/index.js.map +1 -1
  64. package/lib/plugins/reorder-columns/index.js.map +1 -1
  65. package/lib/plugins/responsive/index.js.map +1 -1
  66. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  67. package/lib/plugins/selection/index.js +1 -1
  68. package/lib/plugins/selection/index.js.map +1 -1
  69. package/lib/plugins/server-side/index.js.map +1 -1
  70. package/lib/plugins/shared/form-field-target.d.ts +10 -0
  71. package/lib/plugins/shared/format-value.d.ts +12 -0
  72. package/lib/plugins/shared/structural-toggle.d.ts +14 -0
  73. package/lib/plugins/shell/index.js.map +1 -1
  74. package/lib/plugins/sticky-rows/index.js.map +1 -1
  75. package/lib/plugins/tooltip/index.js.map +1 -1
  76. package/lib/plugins/tree/index.js +1 -1
  77. package/lib/plugins/tree/index.js.map +1 -1
  78. package/lib/plugins/undo-redo/index.d.ts +1 -1
  79. package/lib/plugins/undo-redo/index.js +1 -1
  80. package/lib/plugins/undo-redo/index.js.map +1 -1
  81. package/lib/plugins/undo-redo/types.d.ts +20 -2
  82. package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +8 -0
  83. package/lib/plugins/visibility/index.js.map +1 -1
  84. package/package.json +1 -1
  85. package/umd/grid.all.umd.js +1 -1
  86. package/umd/grid.all.umd.js.map +1 -1
  87. package/umd/grid.umd.js +1 -1
  88. package/umd/grid.umd.js.map +1 -1
  89. package/umd/plugins/clipboard.umd.js.map +1 -1
  90. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  91. package/umd/plugins/context-menu.umd.js.map +1 -1
  92. package/umd/plugins/editing.umd.js +1 -1
  93. package/umd/plugins/editing.umd.js.map +1 -1
  94. package/umd/plugins/export.umd.js +1 -1
  95. package/umd/plugins/export.umd.js.map +1 -1
  96. package/umd/plugins/filtering.umd.js +1 -1
  97. package/umd/plugins/filtering.umd.js.map +1 -1
  98. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  99. package/umd/plugins/grouping-rows.umd.js +1 -1
  100. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  101. package/umd/plugins/hierarchy.umd.js.map +1 -1
  102. package/umd/plugins/master-detail.umd.js +1 -1
  103. package/umd/plugins/master-detail.umd.js.map +1 -1
  104. package/umd/plugins/multi-sort.umd.js.map +1 -1
  105. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  106. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  107. package/umd/plugins/pivot.umd.js +1 -1
  108. package/umd/plugins/pivot.umd.js.map +1 -1
  109. package/umd/plugins/print.umd.js.map +1 -1
  110. package/umd/plugins/reorder-columns.umd.js.map +1 -1
  111. package/umd/plugins/responsive.umd.js.map +1 -1
  112. package/umd/plugins/row-drag-drop.umd.js.map +1 -1
  113. package/umd/plugins/selection.umd.js +1 -1
  114. package/umd/plugins/selection.umd.js.map +1 -1
  115. package/umd/plugins/server-side.umd.js.map +1 -1
  116. package/umd/plugins/shell.umd.js.map +1 -1
  117. package/umd/plugins/sticky-rows.umd.js.map +1 -1
  118. package/umd/plugins/tooltip.umd.js.map +1 -1
  119. package/umd/plugins/tree.umd.js +1 -1
  120. package/umd/plugins/tree.umd.js.map +1 -1
  121. package/umd/plugins/undo-redo.umd.js +1 -1
  122. package/umd/plugins/undo-redo.umd.js.map +1 -1
  123. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -15,4 +15,19 @@ export declare function defaultEditorFor(column: AnyColumn): (ctx: ColumnEditorC
15
15
  * string dates stay as strings, null/undefined for empty fields).
16
16
  */
17
17
  export declare function getInputValue(input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, column?: AnyColumn, originalValue?: unknown): unknown;
18
+ /**
19
+ * Write a value into a native editor — the inverse of {@link getInputValue}. Used to push
20
+ * external row updates (`updateRow`, cascades, reverts) into an open editor, where a blind
21
+ * `input.value = String(value)` would corrupt it: a multi-select matches no option for
22
+ * `'a,c'` and drops its whole selection, a date input rejects `Date.toString()`, and a
23
+ * nullable select has no `''` option for `null`. Pass the column so the nullable blank
24
+ * sentinel is only honoured where {@link getInputValue} decodes it.
25
+ */
26
+ export declare function setInputValue(input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, value: unknown, column?: AnyColumn): void;
27
+ /**
28
+ * Whether a value re-read from an editor equals the cell's original value. Arrays
29
+ * (multi-select) compare as sets, since the DOM reports selections in option order
30
+ * and every read yields a new array instance.
31
+ */
32
+ export declare function isSameEditorValue(originalValue: unknown, value: unknown): boolean;
18
33
  export {};
@@ -1,2 +1,2 @@
1
- import{BaseGridPlugin as t,DEFAULT_A11Y_MESSAGES as e,fromVirtualScrollTop as i,invalidateAccessorCache as n,readCellField as r,toVirtualScrollTop as o,writeCellField as s}from"@toolbox-web/grid";var l="editing",d="data-tbw-truncated";function a(t,e){if(!t)return;if(!1===("effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.announcements)return;const i=t.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=e}):i.textContent=e)}function c(t,i,...n){const r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[i];return r?r(...n):e[i](...n)}function u(t,e){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:e,container:n,viewportEl:r,scrollMapping:s}=t._virtualization,l=n,d=r?.clientHeight??l?.clientHeight??0;if(!l||d<=0)return;const a=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(a.skipScroll)return;const c=Math.max(0,a.top),u=d-c-Math.max(0,a.bottom);if(u<=0)return;const h=t._focusRow*e,f=s?o(l.scrollTop,s):l.scrollTop;if(h<f+c){const t=Math.max(0,h-c);l.scrollTop=s?i(t,s):t}else if(h+e>f+c+u){const t=Math.max(0,h-u+e-c);l.scrollTop=s?i(t,s):t}}(t);const n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var r;n||t.refreshVirtualWindow(!1),(r=t._bodyEl)&&r.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=function(t){const e=t._focusRow,i=t._virtualization.start??0,n=t._virtualization.end??t._rows.length;if(e<i||e>=n)return;const r=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=r?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o?{rowEl:r??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:d,cell:a}=s;a.classList.add("cell-focus"),a.setAttribute("aria-selected","true"),n&&!e?.forceHorizontalScroll||function(t,e,i,n){const r=t.querySelector(".tbw-scroll-area");if(!r)return;if(n?.forceScrollLeft)return void(r.scrollLeft=0);if(n?.forceScrollRight)return void(r.scrollLeft=r.scrollWidth-r.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=r.getBoundingClientRect(),d=s.left-l.left+r.scrollLeft,a=d+s.width,c=r.scrollLeft+o.left,u=r.scrollLeft+r.clientWidth-o.right;d<c?r.scrollLeft=d-o.left:a>u&&(r.scrollLeft=a-r.clientWidth+o.right)}(t,d,a,e),function(t,e,i){if(i&&e.classList.contains(l)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(i){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,a,n)}var h=/{{\s*([^}]+)\s*}}/g,f="__DG_EMPTY__",g=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,w="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),m=new RegExp(`__(proto|defineGetter|defineSetter)|${w.slice(3).join("|")}|this\\b`);new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|"));function p(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const n=t[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const n=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<t.length&&"'"!==t[i];)n+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(n,i)});continue}if(i+2<t.length){const n=t.slice(i,i+3);if("==="===n||"!=="===n){e.push({type:"op",v:n}),i+=3;continue}}if(i+1<t.length){const n=t.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){e.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;e.push({type:"op",v:n}),i++}else i++}return e}(t);if(!i)return;const n=i;let r=0;function o(){return n[r]}function s(){return n[r++]}function l(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function d(){const t=function(){let t=a();for(;l("op","||");)s(),t=t||a();return t}();if(l("op","?")){s();const e=d();if(!l("op",":"))return;s();const i=d();return t?e:i}return t}function a(){let t=c();for(;l("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=f();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=f();else{if("-"!==e.v)break;s(),t-=f()}}return t}function f(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return l("op","!")?(s(),!g()):w()}function w(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=d();return l("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-w()):void 0}}const m=d();return r<n.length?void 0:m}function v(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],n=(r=t.replace(h,(t,n)=>{const r=function(t,e){if(!(t=(t||"").trim()))return f;if(y.test(t))return f;if("value"===t)return null==e.value?f:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return null==n?f:String(n)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),n=e.typeDefault?e.typeDefault[i]:void 0;return null==n?f:String(n)}if(t.length>80)return f;if(!g.test(t)||m.test(t))return f;const i=t.match(/\./g);if(i&&i.length>1)return f;try{const i=p(t,e),n=null==i?"":String(i);return y.test(n)?f:n||f}catch{return f}}(n,e);return i.push({expr:n.trim(),result:r}),r===f?r:(o=r)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),r?r.replace(new RegExp(f,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):r);var r;const o=i.length&&i.every(t=>""===t.result||t.result===f);return y.test(t)||o?"":n}var y=/Reflect|Proxy|ownKeys/;function b(t){if(y.test(t)){const t=()=>"";return t.__blocked=!0,t}const e=e=>v(t,e);return e.__blocked=!1,e}function E(t){if(!t.firstElementChild)return null;const e=t.querySelector(":scope > .tbw-cell-loading-overlay");if(!e)return null;const i=t.parentElement;return i?i.insertBefore(e,t):e.remove(),e}function R(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}var C="__tbw_null__";function I(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return R(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?C:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const r=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===C?e.commit(null):e.commit(n.value)};return n.addEventListener("change",r),n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function _(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function k(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return""===t.value||"number"!==e?.type&&"number"!=typeof i?null==i&&""===t.value?e?.nullable?null:"":t.value:Number(t.value)}(t,e,i);switch(t.type){case"checkbox":return t.checked;case"number":return _(t.value,e);case"date":return function(t,e,i){return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date}(t,e,i);default:return function(t,e,i){return"number"==typeof i?_(t.value,e):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}(t,e,i)}}var x=class{#t=/* @__PURE__ */new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=/* @__PURE__ */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 S(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),o=Object.keys(n);if(r.length!==o.length)return!1;for(const t of r)if(!A(i[t],n[t]))return!1;return!0}return!1}function M(t,e,i){t.set(e,structuredClone(i))}function L(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}var G=class{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */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;return function(t,e,i){for(const n of e)if(!0!==n?.__loading)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,!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return S(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&&S(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const o=t.get(e);return!!o&&!A(r(o,n),r(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)&&S(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){M(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,e,i){const n=this.baselines.get(t);n&&s(n,e,i)}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&&M(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&&S(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&&S(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=L(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&&L(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)}};var D='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function T(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function q(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function F(t){}function P(t,e){return!1===t.onBeforeEditClose?.(e)}function $(t,e,i,n,o,l,d,a){if(!n.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:f,editorValueCallbacks:g}=t;let w;try{w=c.getRowId?.(e)}catch{}const m=w?t=>c.updateRow(w,t,"cascade"):F,p=q(n.field)?r(e,n.field):void 0;l.classList.add("editing"),f.add(`${i}:${o}`);const v=a??l.parentElement;v&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(v);let y=!1;const b=r=>{if(y||!u&&!t.isEditSessionActive())return;const o=w?c._getRowEntry(w):void 0,s=o?.row??e,l=o?.index??i;t.commitCellValue(l,n,r,s)},R=()=>{if(y=!0,q(n.field)){const t=(w?c._getRowEntry(w):void 0)?.row??e;s(t,n.field,p)}},C=document.createElement("div");C.className="tbw-editor-host";const _=E(l);l.firstElementChild&&c.__frameworkAdapter?.releaseCell?.(l),l.innerHTML="",l.appendChild(C),_&&l.appendChild(_),C.addEventListener("keydown",e=>{if(!e.defaultPrevented){if("Enter"===e.key){const t=e.target;if(t&&"true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute?.("aria-controls"))return}if("Enter"===e.key){const r=e.target,o=T(r);if(o&&o!==r)return;if(u){e.preventDefault();const t=C.querySelector("input,textarea,select");return void(t&&b(k(t,n,p)))}if(P(h,e))return;e.stopPropagation(),e.preventDefault(),y=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(u)return e.stopPropagation(),void e.preventDefault();if(P(h,e))return;e.stopPropagation(),e.preventDefault(),R(),t.exitRowEdit(i,!0)}}});const x=n,S=x.__editorTemplate,A=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(c,x)??I(n),M=p,L=`${i}:${n.field}`,G=[];g.set(L,t=>{for(const e of G)e(t)});const $=t=>{G.push(t)};if("template"===A&&S)!function(t,e,i,n,r,o,s,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.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(!q(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let e=!1;h.addEventListener("blur",()=>{e||o(k(h,i,r))}),h.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(P(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,o(k(h,i,r)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(P(t.config,l))return;l.stopPropagation(),l.preventDefault(),s(),t.exitRowEdit(d,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(t,C,x,e,p,b,R,d,i),$(t=>{if(null!=t&&"object"==typeof t)return;const e=C.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof A){const t=document.createElement(A);t.value=M,t.addEventListener("change",()=>b(t.value)),$(e=>{t.value=e}),C.appendChild(t),d||queueMicrotask(()=>{C.querySelector(D)?.focus({preventScroll:!0})})}else if("function"==typeof A){const i=A({row:e,rowId:w??"",value:M,field:n.field,column:n,commit:b,cancel:R,updateRow:m,onValueChange:$,grid:t.grid});"string"==typeof i?(C.innerHTML=i,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(k(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(k(r,e,n))))}(C,n,b,p),$(t=>{const e=C.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):i instanceof Node?(C.appendChild(i),i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement?$(t=>{i instanceof HTMLInputElement&&"checkbox"===i.type?i.checked=!!t:i.value=String(t??"")}):l.setAttribute("data-editor-managed","")):!i&&C.hasChildNodes()&&l.setAttribute("data-editor-managed",""),d||queueMicrotask(()=>{C.querySelector(D)?.focus({preventScroll:!0})})}else if(A&&"object"==typeof A){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",n.field),C.appendChild(i),l.setAttribute("data-editor-managed","");const r={row:e,rowId:w??"",value:M,field:n.field,column:n,commit:b,cancel:R,updateRow:m,onValueChange:$,grid:t.grid};if(A.mount)try{A.mount({placeholder:i,context:r,spec:A})}catch(H){V="TBW080",O=`External editor mount error for column '${n.field}': ${H}`,W=t.grid.id,console.warn(function(t,e,i,n){return`${function(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}(i,n)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}(V,O,W,N))}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:A,context:r}}))}var V,O,W,N;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(D);e&&(e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")||e.hasAttribute("title")||e.id&&t.querySelector(`label[for="${CSS.escape(e.id)}"]`)||e.closest("label")||e.setAttribute("aria-label",i))})}(C,n)}var V=class extends t{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"},{type:"cell-edit-reverted",description:"Emitted when row values are rolled back in place (revertRow/revertAll, row-edit cancel, grid-mode Escape) — not recorded as history"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"},{type:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg:var(--tbw-color-selection);--tbw-editing-row-bg:var(--tbw-editing-bg);--tbw-editing-border:var(--tbw-border-input,1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input:var(--tbw-cell-padding-input,2px 6px);--tbw-font-size-editor:inherit;--tbw-editing-row-outline-color:var(--tbw-color-accent);--tbw-editing-row-outline-width:1px}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n(t,e){const i=this.#r.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#o(t){return!0===t.editable||"function"==typeof t.editable}#s=-1;#l;#d;#a=-1;#c=/* @__PURE__ */new Map;#u=/* @__PURE__ */new Set;#h=/* @__PURE__ */new WeakSet;#f=/* @__PURE__ */new Map;#g=!1;#w=-1;#m;#p=!1;#v=!1;#y=!1;#b=null;#E=new G;#R=/* @__PURE__ */new Set;#C;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;this.#m=new x((t,e,i)=>{this.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#s,commitCellValue:(t,e,i,n)=>this.#_(t,e,i,n),exitRowEdit:(t,e)=>this.#k(t,e)},this.#x(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#E.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),this.#S(e,i),this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.#A(e,i))}#S(t,e){if(document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#s){if(P(this.config,t))return;this.#k(this.#s,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#s)return;const i=e.findRenderedRowElement?.(this.#s);if(!i)return;if((t.composedPath&&t.composedPath()||[]).includes(i))return;const n=t.target;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=e.findRenderedRowElement?.(this.#s);if(t&&function(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const o=e.ownerDocument?.getElementById(r);if(o&&o.contains(t))return!0}return!1}(n,t))return}P(this.config,t)||queueMicrotask(()=>{-1!==this.#s&&this.#k(this.#s,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#s)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#s&&this.#M()})},{signal:t}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#f.get(i);n&&n(e.newValue)},{signal:t}),this.config.dirtyTracking){const e=t=>{const e=t.detail?.action;if(!e)return;const i="compound"===e.type?e.actions:[e],n=/* @__PURE__ */new Set;for(const r of i){const t=void 0!==r.rowId?this.#r._getRowEntry(r.rowId)?.row:this.rows[r.rowIndex];if(!t)continue;const e=r.rowId??this.#L(t);if(!e||n.has(e))continue;n.add(e);const i=this.#E.isRowDirty(e,t);this.#G(e,t,i?"modified":"pristine")}};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",t=>{const e=this.#L(t.row);null!=e&&this.markAsNew(String(e))}),this.on("datasource:data",t=>{this.#D(t.rows)&&this.requestAfterRender()})}}#D(t){const e=this.#r;return!!e.getRowId&&this.#E.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}})}#A(t,e){this.gridElement.addEventListener("focusin",t=>{const i=t.target;if(i!==this.gridElement&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return i.blur(),void this.gridElement.focus();const t=e._focusRow,n=e._focusCol,o=this.#b;if(!o||o.rowIndex!==t||o.colIndex!==n){const i=e._visibleColumns?.[n],o=e._rows?.[t];if(i?.field&&o){const e=i.field;this.#b={rowIndex:t,colIndex:n,field:e,value:r(o,e)}}}this.#p=!0}},{signal:t}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=T(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#p=!1,this.#b=null)},{signal:t}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#p){if(P(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#T()});this.#T(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(this.#v=!1)},{signal:t})}detach(){this.#r._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#c.clear(),this.#E.clear(),this.#u.clear(),this.#f.clear(),this.#p=!1,this.#v=!1,this.#b=null,this.#y=!1,this.#h=/* @__PURE__ */new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#s;if("getCellEditableResolver"===t.type){const t=this.#r.effectiveConfig?.columns??[],e=/* @__PURE__ */new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#n(n,i)}}return"commitCellValue"===t.type?this.#q(t.context):void 0}#q(t){const e=this.#r,i=(e._visibleColumns??[]).find(e=>e.field===t.field)??e._columns?.find(e=>e.field===t.field),o=t.row??(null!=t.rowId?e._getRowEntry(t.rowId)?.row:void 0)??e._rows?.[t.rowIndex];if("sync"===t.source){if(!o||!q(t.field))return;s(o,t.field,t.newValue),n(o);const e=this.#L(o);if(e&&this.config.dirtyTracking){this.#E.rebaselineCell(e,t.field,t.newValue);const i=this.#E.isRowDirty(e,o);i||this.#E.changedRowIds.delete(e),this.#G(e,o,i?"modified":"pristine")}return!0}if(i&&o&&q(t.field)){if("history"===t.source){s(o,t.field,t.newValue),n(o);const e=this.#L(o);if(e&&this.config.dirtyTracking){const t=this.#E.isRowDirty(e,o);t||this.#E.changedRowIds.delete(e),this.#G(e,o,t?"modified":"pristine")}return!0}return this.#_(t.rowIndex,i,t.newValue,o,t.source),r(o,t.field)===t.newValue}}onCellClick(t){if(this.#i)return!1;const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t;return!!e._columns?.some(t=>this.#o(t))&&(!!this.#F(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){switch(t.key){case"Escape":return this.#P(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#$(t);case"Tab":return this.#V(t);case" ":case"Spacebar":return this.#O(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#W(t);case"F2":return this.#N(t);default:return!1}}#P(t){return this.#i&&this.#p?(this.#T(),this.requestAfterRender(),!0):-1!==this.#s&&!this.#i&&(P(this.config,t)||this.#k(this.#s,!0),!0)}#$(t){const e=T(t.target),i=!!e&&e!==this.gridElement,n="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#i&&!this.#p&&!i)&&(!(!this.#i||!this.#p&&!i||!n)||!(!n||-1===this.#s||this.#i))}#V(t){return!(-1===this.#s&&!this.#i)&&(t.preventDefault(),this.#y?(this.#k(this.#s,!1),!0):(this.#H(!t.shiftKey),!0))}#O(t){if(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;if(-1!==this.#s)return!1;const e=this.#r,i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const o=e._visibleColumns[n],s=e._rows[i];if(!o||!s||"boolean"!==o.type)return!1;if(!this.#n(o,s))return!1;const l=o.field;return!!q(l)&&(this.#_(i,o,!r(s,l),s),t.preventDefault(),this.requestRender(),!0)}#W(t){if(this.#i&&!this.#p)return this.#M(),!0;if(this.#i&&this.#p)return this.#z(t);if(-1!==this.#s){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!P(this.config,t)}return this.#K(t)}#z(t){const e=T(t.target);if(e&&e!==t.target)return!0;this.#b=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0,this.requestAfterRender(),!0}#K(t){const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,o=e._focusCol;if(n<0)return!1;const s=e._columns?.some(t=>this.#o(t)),l=e._rows[n];if(!s||!this.#F(l))return!1;const d=e._visibleColumns[o]?.field??"",a=d&&l?r(l,d):void 0,c=this.gridElement.querySelector(`[data-row="${n}"][data-col="${o}"]`),u=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:o,field:d,value:a,row:l,cellEl:c,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(u),u.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}#N(t){if(-1!==this.#s||this.#i)return!1;const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];return!!(r&&o&&r.field)&&(!!this.#n(r,o)&&(t.preventDefault(),this.beginCellEdit(i,r.field),!0))}#j(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#B(){const t=this.#r,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const n=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!n.length)return;const r=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<n.length;s++){const t=n[s],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),d=l??t;let a=r?.canHandle?.(d)?r.createEditor?.(d):void 0;if(!a&&l){const e=this.#j(t),i=b(l.innerHTML);a=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}a&&(o[e]={...i??{},editor:a})}}processColumns(t){const e=this.#r;this.#B();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const o=t.__element;if(o&&!this.#h.has(o)){this.#h.add(o),null==t.editable&&o.hasAttribute("editable")&&(t.editable="false"!==o.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=o.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(s=i.editorParams)}return s?{...t,editorParams:{...s,...t.editorParams}}:t})}processRows(t){if(this.config.dirtyTracking&&this.#D(t),-1===this.#s||this.#i)return t;const e=this.#l,i=this.#d;if(!e||!i)return t;const n=[...t];let r=-1;for(let o=0;o<n.length;o++)if(this.#L(n[o])===e){r=o;break}return-1===r?(setTimeout(()=>this.cancelActiveRowEdit(),0),n):(n[r]=i,this.#s!==r&&this.#U(this.#s,r),n)}afterRender(){const t=this.#r;if(-1!==this.#s&&this.#d&&!this.#i&&t._rows[this.#s]!==this.#d){const e=t._rows.indexOf(this.#d);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#U(this.#s,e)}if(this.#g&&(this.#g=!1,this.#X(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#E.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#u.size)for(const i of this.#u){const[e,n]=i.split(":"),r=parseInt(e,10),o=parseInt(n,10),s=this.#Y(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],d=t._visibleColumns[o];l&&d&&this.#Z(l,r,d,o,s,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:o,cellElement:s}=t,l=this.#n(n,e);if(l)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#i&&s.classList.contains("editing")){s.classList.remove("editing");const t=r(e,n.field);s.textContent=null==t?"":String(t)}this.#i&&l&&(s.classList.contains("editing")||this.#Z(e,i,n,o,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#E.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",i),r){const i=o.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#E.isCellDirty(e,t.row,o))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#E.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#E.getChangedRowIds()}get activeEditRow(){return this.#s}get activeEditCol(){return this.#a}isRowEditing(t){return this.#s===t}isCellEditing(t,e){return this.#u.has(`${t}:${e}`)}isRowChanged(t){const e=this.#r,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#E.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#E.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#E.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#E.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#E.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#E.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markDirty(t),this.#G(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#E.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#E.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#E.revertRow(t,e)&&(this.#G(t,e,"reverted"),this.emitPluginEvent("cell-edit-reverted",{rowId:t}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.revertAll(e=>t._getRowEntry(e)?.row),this.emitPluginEvent("cell-edit-reverted",{}),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#x(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#r._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#r,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[t];if(!r||!o||!this.#n(r,o))return;const s=this.#Y(t,n);s&&(this.#y=!0,this.#Q(t,n,s))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#o(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#F(n)&&(this.#y=!1,this.#J(t,n),Array.from(i.children).forEach((i,r)=>{const o=e._visibleColumns[r];if(o&&this.#n(o,n)){const e=i;e.classList.contains("editing")||this.#Z(n,t,o,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(D);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!1)}cancelActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!0)}#L(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#Y(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#F(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#G(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:i})}#T(){this.#tt();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#et(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#E.changedRowIds.delete(t),this.#E.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)),this.emitPluginEvent("cell-edit-reverted",{rowId:t}))}#I(t,e,i){const n=this.#r,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const o=n._rows?.findIndex(e=>this.#L(e)===t);if(-1===o||void 0===o)return;const s=this.#Y(o,r);if(s)if(i){s.setAttribute("data-invalid","true"),s.setAttribute("aria-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&(s.setAttribute("title",i),s.removeAttribute(d))}else s.removeAttribute("data-invalid"),s.removeAttribute("aria-invalid"),s.removeAttribute("title")}#U(t,e){this.#s=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const s of this.#u)s.startsWith(n)?i.add(`${e}:${s.substring(n.length)}`):i.add(s);this.#u.clear();for(const s of i)this.#u.add(s);const r=this.#c.get(t);void 0!==r&&(this.#c.delete(t),this.#c.set(e,r));const o=[];for(const[s,l]of this.#f)s.startsWith(n)&&(o.push([`${e}:${s.substring(n.length)}`,l]),this.#f.delete(s));for(const[s,l]of o)this.#f.set(s,l);this.#x()}#Q(t,e,i){const n=this.#r,r=n._rows[t],o=n._visibleColumns[e];r&&o&&this.#n(o,r)&&(i.classList.contains("editing")||(this.#s!==t&&this.#J(t,r),this.#a=e,this.#Z(r,t,o,e,i,!1)))}#tt(){const t=this.#b;if(!t)return;const e=this.#r._rows?.[t.rowIndex];e&&(s(e,t.field,t.value),this.emitPluginEvent("cell-edit-reverted",{rowId:this.#L(e)}));const i=`${t.rowIndex}:${t.field}`,n=this.#f.get(i);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),e){const t=this.#L(e);t&&(this.config.dirtyTracking?this.#E.isRowDirty(t,e)||(this.#E.changedRowIds.delete(t),this.#G(t,e,"reverted")):this.#E.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#M(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#Y(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(D);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#H(t){const e=this.#r,i=e._rows,n=this.#i?e._focusRow:this.#s,r=i[n],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;const s=o.indexOf(e._focusCol)+(t?1:-1);if(s>=0&&s<o.length){e._focusCol=o[s];const t=this.#Y(n,o[s]);return t?.classList.contains("editing")&&t.querySelector(D)?.focus({preventScroll:!0}),void u(e,{forceHorizontalScroll:!0})}const l=n+(t?1:-1);if(l>=0&&l<i.length){const r=i[l],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],u(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#Y(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(D)?.focus({preventScroll:!0})},0)):(this.#k(n,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),u(e,{forceHorizontalScroll:!0}))}}#x(){const t=this.#r;t._activeEditRows=this.#s,t._rowEditSnapshots=this.#c}#J(t,e){this.#s!==t&&(-1!==this.#s&&this.#k(this.#s,!1),this.#c.set(t,{...e}),this.#s=t,this.#d=e,this.#l=this.#L(e),this.#x(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#l??"",row:e}),a(this.gridElement,c(this.gridElement,"editingStarted",t))))}#k(t,e){if(this.#s!==t)return;const i=this.#r,n=this.#c.get(t),r=i.findRenderedRowElement?.(t),{rowId:o,current:s}=this.#it(t);!e&&r&&s&&this.#nt(r,t,s),e||this.#i||!s||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:s}),e&&s?this.#et(o,s,n):!e&&s&&this.#rt(t,o,s,n),this.#ot(t),this.#g=!0,r?this.#st(r,i):(this.#X(i),this.#g=!1),!this.#i&&s&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:s,reverted:e}),e||a(this.gridElement,c(this.gridElement,"editingCommitted",t)))}#it(t){const e=this.#r;let i=this.#l;const n=(i?e._getRowEntry(i):void 0)?.row??this.#d??e._rows[t];return!i&&n&&(i=this.#L(n)),{rowId:i,current:n}}#nt(t,e,i){const n=this.#r;t.querySelectorAll(".cell.editing").forEach(t=>{const o=Number(t.getAttribute("data-col"));if(isNaN(o))return;const s=n._visibleColumns[o];if(!s)return;if(t.hasAttribute("data-editor-managed"))return;const l=t.querySelector("input,textarea,select");if(!l)return;const d=s.field,a=r(i,d),c=k(l,s,a);a!==c&&this.#_(e,s,c,i)})}#rt(t,e,i,n){const r=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}(n,i),o=e?this.#E.changedRowIds.has(e):r;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:n,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?n&&this.#et(e,i,n):(e&&this.config.dirtyTracking&&(this.#E.isRowDirty(e,i)?this.#E.committedDirtyRowIds.add(e):this.#E.committedDirtyRowIds.delete(e)),r&&this.isAnimationEnabled&&(this.#w=t))}#ot(t){this.#c.delete(t),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#y=!1,this.#x();for(const e of this.#u)e.startsWith(`${t}:`)&&this.#u.delete(e);for(const e of this.#f.keys())e.startsWith(`${t}:`)&&this.#f.delete(e)}#st(t,e){const i=e.__frameworkAdapter,n=t.querySelectorAll(".cell.editing");i?.releaseCell&&n.forEach(t=>{const e=E(t);i.releaseCell(t),e&&t.appendChild(e)}),n.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#_(t,e,i,o,l="user"){const d=e.field;if(!q(d))return;const a=r(o,d);if(a===i)return;const c=this.#r,u=this.#L(o),h=!u||!this.#E.changedRowIds.has(u),f=u?t=>this.grid.updateRow(u,t,"cascade"):F;let g=!1;const w=u?t=>{g=!0,this.setInvalid(u,d,t??"")}:()=>{},m=`${u??t}\0${d}`;if(this.#R.has(m))return;let p=!1;this.#R.add(m);try{p=this.emitCancelable("cell-commit",{row:o,rowId:u??"",field:d,oldValue:a,value:i,source:l,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:h,updateRow:f,setInvalid:w})}finally{this.#R.delete(m)}if(p)return;if(u&&!g&&this.isCellInvalid(u,d)&&this.clearInvalid(u,d),s(o,d,i),n(o),u&&this.#E.changedRowIds.add(u),this.#x(),this.config.dirtyTracking&&u){const t=this.#E.isRowDirty(u,o);this.#G(u,o,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,rowId:u,field:d,oldValue:a,newValue:i});const v=c.findRenderedRowElement?.(t);v&&v.classList.add("changed")}#Z(t,e,i,n,r,o,s){$(this.#C,t,e,i,n,r,o,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{}})}};export{V as EditingPlugin,I as defaultEditorFor};
1
+ import{BaseGridPlugin as t,DEFAULT_A11Y_MESSAGES as e,fromVirtualScrollTop as i,invalidateAccessorCache as n,readCellField as r,toVirtualScrollTop as o,writeCellField as s}from"@toolbox-web/grid";var l="editing",a="tree-toggle",d="group-toggle",c="data-tbw-truncated";function u(t,e){if(!t)return;if(!1===("effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.announcements)return;const i=t.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=e}):i.textContent=e)}function h(t,i,...n){const r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[i];return r?r(...n):e[i](...n)}function f(t,e){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:e,container:n,viewportEl:r,scrollMapping:s}=t._virtualization,l=n,a=r?.clientHeight??l?.clientHeight??0;if(!l||a<=0)return;const d=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const c=Math.max(0,d.top),u=a-c-Math.max(0,d.bottom);if(u<=0)return;const h=t._focusRow*e,f=s?o(l.scrollTop,s):l.scrollTop;if(h<f+c){const t=Math.max(0,h-c);l.scrollTop=s?i(t,s):t}else if(h+e>f+c+u){const t=Math.max(0,h-u+e-c);l.scrollTop=s?i(t,s):t}}(t);const n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var r;n||t.refreshVirtualWindow(!1),(r=t._bodyEl)&&r.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=function(t){const e=t._focusRow,i=t._virtualization.start??0,n=t._virtualization.end??t._rows.length;if(e<i||e>=n)return;const r=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=r?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o?{rowEl:r??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:a,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),n&&!e?.forceHorizontalScroll||function(t,e,i,n){const r=t.querySelector(".tbw-scroll-area");if(!r)return;if(n?.forceScrollLeft)return void(r.scrollLeft=0);if(n?.forceScrollRight)return void(r.scrollLeft=r.scrollWidth-r.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=r.getBoundingClientRect(),a=s.left-l.left+r.scrollLeft,d=a+s.width,c=r.scrollLeft+o.left,u=r.scrollLeft+r.clientWidth-o.right;a<c?r.scrollLeft=a-o.left:d>u&&(r.scrollLeft=d-r.clientWidth+o.right)}(t,a,d,e),function(t,e,i){if(i&&e.classList.contains(l)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(i){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,d,n)}var g=/{{\s*([^}]+)\s*}}/g,w="__DG_EMPTY__",m=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,p="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),v=new RegExp(`__(proto|defineGetter|defineSetter)|${p.slice(3).join("|")}|this\\b`);new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|"));function y(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const n=t[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const n=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<t.length&&"'"!==t[i];)n+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(n,i)});continue}if(i+2<t.length){const n=t.slice(i,i+3);if("==="===n||"!=="===n){e.push({type:"op",v:n}),i+=3;continue}}if(i+1<t.length){const n=t.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){e.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;e.push({type:"op",v:n}),i++}else i++}return e}(t);if(!i)return;const n=i;let r=0;function o(){return n[r]}function s(){return n[r++]}function l(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function a(){const t=function(){let t=d();for(;l("op","||");)s(),t=t||d();return t}();if(l("op","?")){s();const e=a();if(!l("op",":"))return;s();const i=a();return t?e:i}return t}function d(){let t=c();for(;l("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=f();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=f();else{if("-"!==e.v)break;s(),t-=f()}}return t}function f(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return l("op","!")?(s(),!g()):w()}function w(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=a();return l("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-w()):void 0}}const m=a();return r<n.length?void 0:m}function E(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],n=(r=t.replace(g,(t,n)=>{const r=function(t,e){if(!(t=(t||"").trim()))return w;if(b.test(t))return w;if("value"===t)return null==e.value?w:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return null==n?w:String(n)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),n=e.typeDefault?e.typeDefault[i]:void 0;return null==n?w:String(n)}if(t.length>80)return w;if(!m.test(t)||v.test(t))return w;const i=t.match(/\./g);if(i&&i.length>1)return w;try{const i=y(t,e),n=null==i?"":String(i);return b.test(n)?w:n||w}catch{return w}}(n,e);return i.push({expr:n.trim(),result:r}),r===w?r:(o=r)&&"string"==typeof o?o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):"";var o}),r?r.replace(new RegExp(w,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):r);var r;const o=i.length&&i.every(t=>""===t.result||t.result===w);return b.test(t)||o?"":n}var b=/Reflect|Proxy|ownKeys/;function R(t){if(b.test(t)){const t=()=>"";return t.__blocked=!0,t}const e=e=>E(t,e);return e.__blocked=!1,e}function C(t){if(!t.firstElementChild)return null;const e=t.querySelector(":scope > .tbw-cell-loading-overlay");if(!e)return null;const i=t.parentElement;return i?i.insertBefore(e,t):e.remove(),e}var I=`.${a},.master-detail-toggle,.${d}`;function _(t){const e=t.options;return e?"function"==typeof e?e():e:[]}function k(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??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}var S="__tbw_null__",x=/* @__PURE__ */new WeakMap;function A(t,e){let i;const n=[];let r=!1;for(const o of Array.from(t.options)){if(!o.selected)continue;if(x.has(o)){n.push(x.get(o));continue}if(e?.nullable&&o.value===S){r=!0;continue}i??=e?_(e):[];const t=i.find(t=>String(t.value)===o.value);n.push(t?t.value:o.value)}return r&&0===n.length?null:n}function M(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 k(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?S:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}_(t).forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,x.set(r,i.value),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 i=A(n,t);if(q(r(e.row,e.field),i))return;e.commit(i)}else t.nullable&&n.value===S?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function L(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function D(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return t instanceof HTMLSelectElement&&t.multiple?A(t,e):t instanceof HTMLSelectElement&&e?.nullable&&t.value===S?null:""===t.value||"number"!==e?.type&&"number"!=typeof i?null==i&&""===t.value?e?.nullable?null:"":t.value:Number(t.value)}(t,e,i);switch(t.type){case"checkbox":return t.checked;case"number":return L(t.value,e);case"date":return function(t,e,i){return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date}(t,e,i);default:return function(t,e,i){return"number"==typeof i?L(t.value,e):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}(t,e,i)}}function G(t,e,i){t instanceof HTMLSelectElement?function(t,e,i){t.multiple?function(t,e,i){const n=Array.isArray(e)?e:null==e?[]:[e];for(const r of Array.from(t.options))if(x.has(r)){const t=x.get(r);r.selected=n.some(e=>e===t)}else T(r,i)?r.selected=null==e:r.selected=n.some(t=>String(t)===r.value)}(t,e,i):null==e&&Array.from(t.options).some(t=>T(t,i))?t.value=S:t.value=String(e??"")}(t,e,!!i?.nullable):t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t instanceof HTMLInputElement&&"date"===t.type&&e instanceof Date?t.valueAsDate=e:t instanceof HTMLInputElement&&"date"===t.type&&"string"==typeof e?t.value=e.split("T")[0]:t.value=String(e??"")}function T(t,e){return e&&t.value===S&&!x.has(t)}function q(t,e){if(Array.isArray(t)&&Array.isArray(e)){const i=new Set(t),n=new Set(e);return i.size===n.size&&[...n].every(t=>i.has(t))}return t===e}var F=class{#t=/* @__PURE__ */new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=/* @__PURE__ */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 P(t,e,i){const n=t.get(e);return!!n&&!$(n,i)}function $(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(!$(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const t of r)if(!$(i[t],n[t]))return!1;return!0}return!1}function V(t,e,i){t.set(e,structuredClone(i))}function H(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}var W=class{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */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;return function(t,e,i){for(const n of e)if(!0!==n?.__loading)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,!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return P(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&&P(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const o=t.get(e);return!!o&&!$(r(o,n),r(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)&&P(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){V(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,e,i){const n=this.baselines.get(t);n&&s(n,e,i)}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&&V(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&&P(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&&P(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=H(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&H(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}};var O='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function N(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function z(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function K(t){}var j=/* @__PURE__ */new WeakMap;function B(t,e){const i=t.onBeforeEditClose;if(!i)return!1;let n=j.get(e);const r=n?.get(i);if(void 0!==r)return r;const o=!1===i(e);return n||j.set(e,n=/* @__PURE__ */new Map),n.set(i,o),o}function U(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const o=e.ownerDocument?.getElementById(r);if(o&&o.contains(t))return!0}return!1}var X=/* @__PURE__ */new WeakMap;function Y(t,e){if(!e)return!1;const i=X.get(t);if(i&&(i.contains(e)||e.contains(i)))return!0;const n=function(t,e){const i=t.composedPath?.()??[];if(!i.includes(e))return!1;for(const n of i){if(n===e)return!1;const t=n;if("true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute("aria-controls"))return!0}return!1}(t,e)||U(t.target,e);return n&&X.set(t,e),n}function Z(t,e,i,n,o,l,a,d){if(!n.editable)return;if(l.classList.contains("editing"))return;const{grid:c,isGridMode:u,config:h,editingCells:f,editorValueCallbacks:g}=t;let w;try{w=c.getRowId?.(e)}catch{}const m=w?t=>c.updateRow(w,t,"cascade"):K,p=z(n.field)?r(e,n.field):void 0;l.classList.add("editing"),f.add(`${i}:${o}`);const v=d??l.parentElement;v&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(v);let y=!1;const E=r=>{if(y||!u&&!t.isEditSessionActive())return;const o=w?c._getRowEntry(w):void 0,s=o?.row??e,l=o?.index??i;t.commitCellValue(l,n,r,s)},b=()=>{if(y=!0,z(n.field)){const t=(w?c._getRowEntry(w):void 0)?.row??e;s(t,n.field,p)}},R=document.createElement("div");R.className="tbw-editor-host";const I=C(l);l.firstElementChild&&c.__frameworkAdapter?.releaseCell?.(l),l.innerHTML="",l.appendChild(R),I&&l.appendChild(I),R.addEventListener("keydown",e=>{if(!e.defaultPrevented){if("Enter"===e.key){const t=e.target;if(t&&"true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute?.("aria-controls"))return}if("Enter"===e.key){const r=e.target,o=N(r);if(o&&o!==r)return;if(u){e.preventDefault();const t=R.querySelector("input,textarea,select");return void(t&&E(D(t,n,p)))}if(B(h,e))return;e.stopPropagation(),e.preventDefault(),t.exitRowEdit(i,!1),y=!0}if("Escape"===e.key){if(u)return e.stopPropagation(),void e.preventDefault();if(Y(e,R))return;if(B(h,e))return;e.stopPropagation(),e.preventDefault(),b(),t.exitRowEdit(i,!0)}}});const _=n,k=_.__editorTemplate,S=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(c,_)??M(n),x=p,A=`${i}:${n.field}`,L=[];g.set(A,t=>{for(const e of L)e(t)});const T=t=>{L.push(t)};if("template"===S&&k)!function(t,e,i,n,r,o,s,l,a){const d=i.__editorTemplate;if(!d)return;const c=d.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.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(!z(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let n=!1;h.addEventListener("blur",()=>{n||o(D(h,i,r))}),h.addEventListener("keydown",l=>{const d=l;if("Enter"===d.key){if(B(t.config,d))return;d.stopPropagation(),d.preventDefault(),n=!0,o(D(h,i,r)),t.exitRowEdit(a,!1)}if("Escape"===d.key){if(Y(d,e))return;if(B(t.config,d))return;d.stopPropagation(),d.preventDefault(),s(),t.exitRowEdit(a,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(t,R,_,e,p,E,b,a,i),T(t=>{const e=R.querySelector("input,textarea,select");if(!e)return;const i=e instanceof HTMLSelectElement&&e.multiple,r=t instanceof Date&&e instanceof HTMLInputElement&&"date"===e.type;(i||r||null==t||"object"!=typeof t)&&G(e,t,n)});else if("string"==typeof S){const t=document.createElement(S);t.value=x,t.addEventListener("change",()=>E(t.value)),T(e=>{t.value=e}),R.appendChild(t),a||queueMicrotask(()=>{R.querySelector(O)?.focus({preventScroll:!0})})}else if("function"==typeof S){const i=S({row:e,rowId:w??"",value:x,field:n.field,column:n,commit:E,cancel:b,updateRow:m,onValueChange:T,grid:t.grid});"string"==typeof i?(R.innerHTML=i,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(D(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(D(r,e,n))))}(R,n,E,p),T(t=>{const e=R.querySelector("input,textarea,select");e&&G(e,t,n)})):i instanceof Node?(R.appendChild(i),i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement?T(t=>G(i,t,n)):l.setAttribute("data-editor-managed","")):!i&&R.hasChildNodes()&&l.setAttribute("data-editor-managed",""),a||queueMicrotask(()=>{R.querySelector(O)?.focus({preventScroll:!0})})}else if(S&&"object"==typeof S){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",n.field),R.appendChild(i),l.setAttribute("data-editor-managed","");const r={row:e,rowId:w??"",value:x,field:n.field,column:n,commit:E,cancel:b,updateRow:m,onValueChange:T,grid:t.grid};if(S.mount)try{S.mount({placeholder:i,context:r,spec:S})}catch(V){q="TBW080",F=`External editor mount error for column '${n.field}': ${V}`,P=t.grid.id,console.warn(function(t,e,i,n){return`${function(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}(i,n)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}(q,F,P,$))}else c.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:S,context:r}}))}var q,F,P,$;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(O);e&&(e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")||e.hasAttribute("title")||e.id&&t.querySelector(`label[for="${CSS.escape(e.id)}"]`)||e.closest("label")||e.setAttribute("aria-label",i))})}(R,n)}var Q=class extends t{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"},{type:"cell-edit-reverted",description:"Emitted when row values are rolled back in place (revertRow/revertAll, row-edit cancel, grid-mode Escape) — not recorded as history"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"},{type:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg:var(--tbw-color-selection);--tbw-editing-row-bg:var(--tbw-editing-bg);--tbw-editing-border:var(--tbw-border-input,1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input:var(--tbw-cell-padding-input,2px 6px);--tbw-font-size-editor:inherit;--tbw-editing-row-outline-color:var(--tbw-color-accent);--tbw-editing-row-outline-width:1px}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n(t,e){const i=this.#r.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#o(t){return!0===t.editable||"function"==typeof t.editable}#s=-1;#l;#a;#d=-1;#c=/* @__PURE__ */new Map;#u=/* @__PURE__ */new Set;#h=/* @__PURE__ */new WeakSet;#f=/* @__PURE__ */new Map;#g=!1;#w=-1;#m;#p=!1;#v=!1;#y=!1;#E=null;#b=new W;#R=/* @__PURE__ */new Set;#C;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;this.#m=new F((t,e,i)=>{this.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#s,commitCellValue:(t,e,i,n)=>this.#_(t,e,i,n),exitRowEdit:(t,e)=>this.#k(t,e)},this.#S(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#b.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),this.#x(e,i),this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.#A(e,i))}#x(t,e){if(document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#s){if(Y(t,e.findRenderedRowElement?.(this.#s)))return;if(B(this.config,t))return;this.#k(this.#s,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#s)return;const i=e.findRenderedRowElement?.(this.#s);if(!i)return;if((t.composedPath&&t.composedPath()||[]).includes(i))return;const n=t.target;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=e.findRenderedRowElement?.(this.#s);if(t&&U(n,t))return}B(this.config,t)||queueMicrotask(()=>{-1!==this.#s&&this.#k(this.#s,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#s)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#s&&this.#M()})},{signal:t}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#f.get(i);n&&n(e.newValue)},{signal:t}),this.config.dirtyTracking){const e=t=>{const e=t.detail?.action;if(!e)return;const i="compound"===e.type?e.actions:[e],n=/* @__PURE__ */new Set;for(const r of i){const t=void 0!==r.rowId?this.#r._getRowEntry(r.rowId)?.row:this.rows[r.rowIndex];if(!t)continue;const e=r.rowId??this.#L(t);if(!e||n.has(e))continue;n.add(e);const i=this.#b.isRowDirty(e,t);this.#D(e,t,i?"modified":"pristine")}};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",t=>{const e=this.#L(t.row);null!=e&&this.markAsNew(String(e))}),this.on("datasource:data",t=>{this.#G(t.rows)&&this.requestAfterRender()})}}#G(t){const e=this.#r;return!!e.getRowId&&this.#b.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}})}#A(t,e){this.gridElement.addEventListener("focusin",t=>{const i=t.target;if(i!==this.gridElement&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return i.blur(),void this.gridElement.focus();const t=e._focusRow,n=e._focusCol,o=this.#E;if(!o||o.rowIndex!==t||o.colIndex!==n){const i=e._visibleColumns?.[n],o=e._rows?.[t];if(i?.field&&o){const e=i.field;this.#E={rowIndex:t,colIndex:n,field:e,value:r(o,e)}}}this.#p=!0}},{signal:t}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=N(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#p=!1,this.#E=null)},{signal:t}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#p){if(B(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#T()});this.#T(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(this.#v=!1)},{signal:t})}detach(){this.#r._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#s=-1,this.#l=void 0,this.#a=void 0,this.#d=-1,this.#c.clear(),this.#b.clear(),this.#u.clear(),this.#f.clear(),this.#p=!1,this.#v=!1,this.#E=null,this.#y=!1,this.#h=/* @__PURE__ */new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#s;if("getCellEditableResolver"===t.type){const t=this.#r.effectiveConfig?.columns??[],e=/* @__PURE__ */new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#n(n,i)}}return"commitCellValue"===t.type?this.#q(t.context):void 0}#q(t){const e=this.#r,i=(e._visibleColumns??[]).find(e=>e.field===t.field)??e._columns?.find(e=>e.field===t.field),o=t.row??(null!=t.rowId?e._getRowEntry(t.rowId)?.row:void 0)??e._rows?.[t.rowIndex];if("sync"===t.source){if(!o||!z(t.field))return;s(o,t.field,t.newValue),n(o);const e=this.#L(o);if(e&&this.config.dirtyTracking){this.#b.rebaselineCell(e,t.field,t.newValue);const i=this.#b.isRowDirty(e,o);i||this.#b.changedRowIds.delete(e),this.#D(e,o,i?"modified":"pristine")}return!0}if(i&&o&&z(t.field)){if("history"===t.source){s(o,t.field,t.newValue),n(o);const e=this.#L(o);if(e&&this.config.dirtyTracking){const t=this.#b.isRowDirty(e,o);t||this.#b.changedRowIds.delete(e),this.#D(e,o,t?"modified":"pristine")}return!0}return this.#_(t.rowIndex,i,t.newValue,o,t.source),r(o,t.field)===t.newValue}}onCellClick(t){if(this.#i)return!1;const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t;return(r!==this.#s||!t.cellEl.classList.contains("editing"))&&(!function(t){return!!t.target?.closest?.(I)}(t.originalEvent)&&(!!e._columns?.some(t=>this.#o(t))&&(!!this.#F(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))))}onKeyDown(t){switch(t.key){case"Escape":return this.#P(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#$(t);case"Tab":return this.#V(t);case" ":case"Spacebar":return this.#H(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#W(t);case"F2":return this.#O(t);default:return!1}}#P(t){return this.#i&&this.#p?(this.#T(),this.requestAfterRender(),!0):-1!==this.#s&&!this.#i&&(Y(t,this.#r.findRenderedRowElement?.(this.#s))||B(this.config,t)||this.#k(this.#s,!0),!0)}#$(t){const e=N(t.target),i=!!e&&e!==this.gridElement,n="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#i&&!this.#p&&!i)&&(!(!this.#i||!this.#p&&!i||!n)||!(!n||-1===this.#s||this.#i))}#V(t){return!(-1===this.#s&&!this.#i)&&(t.preventDefault(),this.#y?(this.#k(this.#s,!1),!0):(this.#N(!t.shiftKey),!0))}#H(t){if(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;if(-1!==this.#s)return!1;const e=this.#r,i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const o=e._visibleColumns[n],s=e._rows[i];if(!o||!s||"boolean"!==o.type)return!1;if(!this.#n(o,s))return!1;const l=o.field;return!!z(l)&&(this.#_(i,o,!r(s,l),s),t.preventDefault(),this.requestRender(),!0)}#W(t){if(this.#i&&!this.#p)return this.#M(),!0;if(this.#i&&this.#p)return this.#z(t);if(-1!==this.#s){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!B(this.config,t)}return this.#K(t)}#z(t){const e=N(t.target);if(e&&e!==t.target)return!0;this.#E=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0,this.requestAfterRender(),!0}#K(t){const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,o=e._focusCol;if(n<0)return!1;const s=e._columns?.some(t=>this.#o(t)),l=e._rows[n];if(!s||!this.#F(l))return!1;const a=e._visibleColumns[o]?.field??"",d=a&&l?r(l,a):void 0,c=this.gridElement.querySelector(`[data-row="${n}"][data-col="${o}"]`),u=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:o,field:a,value:d,row:l,cellEl:c,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(u),u.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}#O(t){if(-1!==this.#s||this.#i)return!1;const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];return!!(r&&o&&r.field)&&(!!this.#n(r,o)&&(t.preventDefault(),this.beginCellEdit(i,r.field),!0))}#j(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#B(){const t=this.#r,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const n=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!n.length)return;const r=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<n.length;s++){const t=n[s],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),a=l??t;let d=r?.canHandle?.(a)?r.createEditor?.(a):void 0;if(!d&&l){const e=this.#j(t),i=R(l.innerHTML);d=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}d&&(o[e]={...i??{},editor:d})}}processColumns(t){const e=this.#r;this.#B();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const o=t.__element;if(o&&!this.#h.has(o)){this.#h.add(o),null==t.editable&&o.hasAttribute("editable")&&(t.editable="false"!==o.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=o.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(s=i.editorParams)}return s?{...t,editorParams:{...s,...t.editorParams}}:t})}processRows(t){if(this.config.dirtyTracking&&this.#G(t),-1===this.#s||this.#i)return t;const e=this.#l,i=this.#a;if(!e||!i)return t;const n=[...t];let r=-1;for(let o=0;o<n.length;o++)if(this.#L(n[o])===e){r=o;break}return-1===r?(setTimeout(()=>this.cancelActiveRowEdit(),0),n):(n[r]=i,this.#s!==r&&this.#U(this.#s,r),n)}afterRender(){const t=this.#r;if(-1!==this.#s&&this.#a&&!this.#i&&t._rows[this.#s]!==this.#a){const e=t._rows.indexOf(this.#a);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#U(this.#s,e)}if(this.#g&&(this.#g=!1,this.#X(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#b.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#u.size)for(const i of this.#u){const[e,n]=i.split(":"),r=parseInt(e,10),o=parseInt(n,10),s=this.#Y(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[o];l&&a&&this.#Z(l,r,a,o,s,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:o,cellElement:s}=t,l=this.#n(n,e);if(l)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#i&&s.classList.contains("editing")){s.classList.remove("editing");const t=r(e,n.field);s.textContent=null==t?"":String(t)}this.#i&&l&&(s.classList.contains("editing")||this.#Z(e,i,n,o,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#b.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",i),r){const i=o.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#b.isCellDirty(e,t.row,o))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#b.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#b.getChangedRowIds()}get activeEditRow(){return this.#s}get activeEditCol(){return this.#d}isRowEditing(t){return this.#s===t}isCellEditing(t,e){return this.#u.has(`${t}:${e}`)}isRowChanged(t){const e=this.#r,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#b.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#b.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#b.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#b.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#b.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#b.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#b.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#b.markDirty(t),this.#D(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#b.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#b.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#b.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#b.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#b.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#b.revertRow(t,e)&&(this.#D(t,e,"reverted"),this.emitPluginEvent("cell-edit-reverted",{rowId:t}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#b.revertAll(e=>t._getRowEntry(e)?.row),this.emitPluginEvent("cell-edit-reverted",{}),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#b.changedRowIds.clear(),this.#b.committedDirtyRowIds.clear(),this.#S(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#r._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#r,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[t];if(!r||!o||!this.#n(r,o))return;const s=this.#Y(t,n);s&&(this.#y=!0,this.#Q(t,n,s))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#o(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#F(n)&&(this.#y=!1,this.#J(t,n),Array.from(i.children).forEach((i,r)=>{const o=e._visibleColumns[r];if(o&&this.#n(o,n)){const e=i;e.classList.contains("editing")||this.#Z(n,t,o,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(O);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!1)}cancelActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!0)}#L(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#Y(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#F(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#D(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#b.getOriginalRow(t),type:i})}#T(){this.#tt();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#et(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#b.changedRowIds.delete(t),this.#b.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)),this.emitPluginEvent("cell-edit-reverted",{rowId:t}))}#I(t,e,i){const n=this.#r,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const o=n._rows?.findIndex(e=>this.#L(e)===t);if(-1===o||void 0===o)return;const s=this.#Y(o,r);if(s)if(i){s.setAttribute("data-invalid","true"),s.setAttribute("aria-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&(s.setAttribute("title",i),s.removeAttribute(c))}else s.removeAttribute("data-invalid"),s.removeAttribute("aria-invalid"),s.removeAttribute("title")}#U(t,e){this.#s=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const s of this.#u)s.startsWith(n)?i.add(`${e}:${s.substring(n.length)}`):i.add(s);this.#u.clear();for(const s of i)this.#u.add(s);const r=this.#c.get(t);void 0!==r&&(this.#c.delete(t),this.#c.set(e,r));const o=[];for(const[s,l]of this.#f)s.startsWith(n)&&(o.push([`${e}:${s.substring(n.length)}`,l]),this.#f.delete(s));for(const[s,l]of o)this.#f.set(s,l);this.#S()}#Q(t,e,i){const n=this.#r,r=n._rows[t],o=n._visibleColumns[e];r&&o&&this.#n(o,r)&&(i.classList.contains("editing")||(this.#s!==t&&this.#J(t,r),this.#d=e,this.#Z(r,t,o,e,i,!1)))}#tt(){const t=this.#E;if(!t)return;const e=this.#r._rows?.[t.rowIndex];e&&(s(e,t.field,t.value),this.emitPluginEvent("cell-edit-reverted",{rowId:this.#L(e)}));const i=`${t.rowIndex}:${t.field}`,n=this.#f.get(i);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),e){const t=this.#L(e);t&&(this.config.dirtyTracking?this.#b.isRowDirty(t,e)||(this.#b.changedRowIds.delete(t),this.#D(t,e,"reverted")):this.#b.changedRowIds.delete(t))}this.requestRender(),this.#E=null}#M(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#Y(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(O);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#N(t){const e=this.#r,i=e._rows,n=this.#i?e._focusRow:this.#s,r=i[n],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;const s=o.indexOf(e._focusCol)+(t?1:-1);if(s>=0&&s<o.length){e._focusCol=o[s];const t=this.#Y(n,o[s]);return t?.classList.contains("editing")&&t.querySelector(O)?.focus({preventScroll:!0}),void f(e,{forceHorizontalScroll:!0})}const l=n+(t?1:-1);if(l>=0&&l<i.length){const r=i[l],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],f(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#Y(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(O)?.focus({preventScroll:!0})},0)):(this.#k(n,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),f(e,{forceHorizontalScroll:!0}))}}#S(){const t=this.#r;t._activeEditRows=this.#s,t._rowEditSnapshots=this.#c}#J(t,e){this.#s!==t&&(-1!==this.#s&&this.#k(this.#s,!1),this.#c.set(t,{...e}),this.#s=t,this.#a=e,this.#l=this.#L(e),this.#S(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#l??"",row:e}),u(this.gridElement,h(this.gridElement,"editingStarted",t))))}#k(t,e){if(this.#s!==t)return;const i=this.#r,n=this.#c.get(t),r=i.findRenderedRowElement?.(t),{rowId:o,current:s}=this.#it(t);!e&&r&&s&&this.#nt(r,t,s),e||this.#i||!s||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:s}),e&&s?this.#et(o,s,n):!e&&s&&this.#rt(t,o,s,n),this.#ot(t),this.#g=!0,r?this.#st(r,i):(this.#X(i),this.#g=!1),!this.#i&&s&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:s,reverted:e}),e||u(this.gridElement,h(this.gridElement,"editingCommitted",t)))}#it(t){const e=this.#r;let i=this.#l;const n=(i?e._getRowEntry(i):void 0)?.row??this.#a??e._rows[t];return!i&&n&&(i=this.#L(n)),{rowId:i,current:n}}#nt(t,e,i){const n=this.#r;t.querySelectorAll(".cell.editing").forEach(t=>{const o=Number(t.getAttribute("data-col"));if(isNaN(o))return;const s=n._visibleColumns[o];if(!s)return;if(t.hasAttribute("data-editor-managed"))return;const l=t.querySelector("input,textarea,select");if(!l)return;const a=s.field,d=r(i,a),c=D(l,s,d);q(d,c)||this.#_(e,s,c,i)})}#rt(t,e,i,n){const r=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}(n,i),o=e?this.#b.changedRowIds.has(e):r;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:n,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?n&&this.#et(e,i,n):(e&&this.config.dirtyTracking&&(this.#b.isRowDirty(e,i)?this.#b.committedDirtyRowIds.add(e):this.#b.committedDirtyRowIds.delete(e)),r&&this.isAnimationEnabled&&(this.#w=t))}#ot(t){this.#c.delete(t),this.#s=-1,this.#l=void 0,this.#a=void 0,this.#d=-1,this.#y=!1,this.#S();for(const e of this.#u)e.startsWith(`${t}:`)&&this.#u.delete(e);for(const e of this.#f.keys())e.startsWith(`${t}:`)&&this.#f.delete(e)}#st(t,e){const i=e.__frameworkAdapter,n=t.querySelectorAll(".cell.editing");i?.releaseCell&&n.forEach(t=>{const e=C(t);i.releaseCell(t),e&&t.appendChild(e)}),n.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#_(t,e,i,o,l="user"){const a=e.field;if(!z(a))return;const d=r(o,a);if(d===i)return;const c=this.#r,u=this.#L(o),h=!u||!this.#b.changedRowIds.has(u),f=u?t=>this.grid.updateRow(u,t,"cascade"):K;let g=!1;const w=u?t=>{g=!0,this.setInvalid(u,a,t??"")}:()=>{},m=`${u??t}\0${a}`;if(this.#R.has(m))return;let p=!1;this.#R.add(m);try{p=this.emitCancelable("cell-commit",{row:o,rowId:u??"",field:a,oldValue:d,value:i,source:l,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:h,updateRow:f,setInvalid:w})}finally{this.#R.delete(m)}if(p)return;if(u&&!g&&this.isCellInvalid(u,a)&&this.clearInvalid(u,a),s(o,a,i),n(o),u&&this.#b.changedRowIds.add(u),this.#S(),this.config.dirtyTracking&&u){const t=this.#b.isRowDirty(u,o);this.#D(u,o,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,rowId:u,field:a,oldValue:d,newValue:i});const v=c.findRenderedRowElement?.(t);v&&v.classList.add("changed")}#Z(t,e,i,n,r,o,s){Z(this.#C,t,e,i,n,r,o,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{}})}};export{Q as EditingPlugin,M as defaultEditorFor};
2
2
  //# sourceMappingURL=index.js.map