@toolbox-web/grid 1.23.4 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -6
- package/all.d.ts +2 -2
- package/all.d.ts.map +1 -1
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +21 -0
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/feature-hook.d.ts +8 -0
- package/lib/core/internal/feature-hook.d.ts.map +1 -0
- package/lib/core/plugin/base-plugin.d.ts +8 -2
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/types.d.ts +1 -1
- package/lib/core/types.d.ts +59 -0
- package/lib/core/types.d.ts.map +1 -1
- package/lib/features/clipboard.d.ts +8 -0
- package/lib/features/clipboard.d.ts.map +1 -0
- package/lib/features/clipboard.js +2 -0
- package/lib/features/clipboard.js.map +1 -0
- package/lib/features/column-virtualization.d.ts +8 -0
- package/lib/features/column-virtualization.d.ts.map +1 -0
- package/lib/features/column-virtualization.js +2 -0
- package/lib/features/column-virtualization.js.map +1 -0
- package/lib/features/context-menu.d.ts +8 -0
- package/lib/features/context-menu.d.ts.map +1 -0
- package/lib/features/context-menu.js +2 -0
- package/lib/features/context-menu.js.map +1 -0
- package/lib/features/editing.d.ts +8 -0
- package/lib/features/editing.d.ts.map +1 -0
- package/lib/features/editing.js +2 -0
- package/lib/features/editing.js.map +1 -0
- package/lib/features/export.d.ts +8 -0
- package/lib/features/export.d.ts.map +1 -0
- package/lib/features/export.js +2 -0
- package/lib/features/export.js.map +1 -0
- package/lib/features/filtering.d.ts +8 -0
- package/lib/features/filtering.d.ts.map +1 -0
- package/lib/features/filtering.js +2 -0
- package/lib/features/filtering.js.map +1 -0
- package/lib/features/grouping-columns.d.ts +8 -0
- package/lib/features/grouping-columns.d.ts.map +1 -0
- package/lib/features/grouping-columns.js +2 -0
- package/lib/features/grouping-columns.js.map +1 -0
- package/lib/features/grouping-rows.d.ts +8 -0
- package/lib/features/grouping-rows.d.ts.map +1 -0
- package/lib/features/grouping-rows.js +2 -0
- package/lib/features/grouping-rows.js.map +1 -0
- package/lib/features/magic-string.es-CkyDP9Ir.mjs.map +1 -0
- package/lib/features/master-detail.d.ts +8 -0
- package/lib/features/master-detail.d.ts.map +1 -0
- package/lib/features/master-detail.js +2 -0
- package/lib/features/master-detail.js.map +1 -0
- package/lib/features/multi-sort.d.ts +10 -0
- package/lib/features/multi-sort.d.ts.map +1 -0
- package/lib/features/multi-sort.js +2 -0
- package/lib/features/multi-sort.js.map +1 -0
- package/lib/features/pinned-columns.d.ts +18 -0
- package/lib/features/pinned-columns.d.ts.map +1 -0
- package/lib/features/pinned-columns.js +2 -0
- package/lib/features/pinned-columns.js.map +1 -0
- package/lib/features/pinned-rows.d.ts +8 -0
- package/lib/features/pinned-rows.d.ts.map +1 -0
- package/lib/features/pinned-rows.js +2 -0
- package/lib/features/pinned-rows.js.map +1 -0
- package/lib/features/pivot.d.ts +8 -0
- package/lib/features/pivot.d.ts.map +1 -0
- package/lib/features/pivot.js +2 -0
- package/lib/features/pivot.js.map +1 -0
- package/lib/features/print.d.ts +8 -0
- package/lib/features/print.d.ts.map +1 -0
- package/lib/features/print.js +2 -0
- package/lib/features/print.js.map +1 -0
- package/lib/features/registry.d.ts +50 -0
- package/lib/features/registry.d.ts.map +1 -0
- package/lib/features/registry.js +2 -0
- package/lib/features/registry.js.map +1 -0
- package/lib/features/registry.spec.js +5 -0
- package/lib/features/registry.spec.js.map +1 -0
- package/lib/features/reorder-columns.d.ts +10 -0
- package/lib/features/reorder-columns.d.ts.map +1 -0
- package/lib/features/reorder-columns.js +2 -0
- package/lib/features/reorder-columns.js.map +1 -0
- package/lib/features/reorder-rows.d.ts +10 -0
- package/lib/features/reorder-rows.d.ts.map +1 -0
- package/lib/features/reorder-rows.js +2 -0
- package/lib/features/reorder-rows.js.map +1 -0
- package/lib/features/responsive.d.ts +8 -0
- package/lib/features/responsive.d.ts.map +1 -0
- package/lib/features/responsive.js +2 -0
- package/lib/features/responsive.js.map +1 -0
- package/lib/features/selection.d.ts +8 -0
- package/lib/features/selection.d.ts.map +1 -0
- package/lib/features/selection.js +2 -0
- package/lib/features/selection.js.map +1 -0
- package/lib/features/server-side.d.ts +8 -0
- package/lib/features/server-side.d.ts.map +1 -0
- package/lib/features/server-side.js +2 -0
- package/lib/features/server-side.js.map +1 -0
- package/lib/features/tree.d.ts +8 -0
- package/lib/features/tree.d.ts.map +1 -0
- package/lib/features/tree.js +2 -0
- package/lib/features/tree.js.map +1 -0
- package/lib/features/undo-redo.d.ts +8 -0
- package/lib/features/undo-redo.d.ts.map +1 -0
- package/lib/features/undo-redo.js +2 -0
- package/lib/features/undo-redo.js.map +1 -0
- package/lib/features/visibility.d.ts +8 -0
- package/lib/features/visibility.d.ts.map +1 -0
- package/lib/features/visibility.js +2 -0
- package/lib/features/visibility.js.map +1 -0
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +428 -27
- package/lib/plugins/filtering/types.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.d.ts +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.d.ts +2 -2
- package/lib/plugins/grouping-rows/index.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +2 -2
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-columns/types.d.ts +3 -3
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/{reorder → reorder-columns}/ReorderPlugin.d.ts +5 -3
- package/lib/plugins/reorder-columns/ReorderPlugin.d.ts.map +1 -0
- package/lib/plugins/reorder-columns/column-drag.d.ts.map +1 -0
- package/lib/plugins/{reorder → reorder-columns}/index.d.ts +2 -2
- package/lib/plugins/reorder-columns/index.d.ts.map +1 -0
- package/lib/plugins/reorder-columns/index.js +2 -0
- package/lib/plugins/reorder-columns/index.js.map +1 -0
- package/lib/plugins/{reorder → reorder-columns}/types.d.ts +5 -0
- package/lib/plugins/reorder-columns/types.d.ts.map +1 -0
- package/lib/plugins/{row-reorder → reorder-rows}/RowReorderPlugin.d.ts +5 -3
- package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts.map +1 -0
- package/lib/plugins/{row-reorder → reorder-rows}/index.d.ts +2 -2
- package/lib/plugins/reorder-rows/index.d.ts.map +1 -0
- package/lib/plugins/reorder-rows/index.js +2 -0
- package/lib/plugins/reorder-rows/index.js.map +1 -0
- package/lib/plugins/{row-reorder → reorder-rows}/types.d.ts +5 -0
- package/lib/plugins/reorder-rows/types.d.ts.map +1 -0
- package/lib/plugins/responsive/ResponsivePlugin.d.ts +2 -2
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +17 -2
- package/public.d.ts +9 -2
- package/public.d.ts.map +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/reorder-columns.umd.js +2 -0
- package/umd/plugins/reorder-columns.umd.js.map +1 -0
- package/umd/plugins/reorder-rows.umd.js +2 -0
- package/umd/plugins/reorder-rows.umd.js.map +1 -0
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
- package/lib/plugins/reorder/ReorderPlugin.d.ts.map +0 -1
- package/lib/plugins/reorder/column-drag.d.ts.map +0 -1
- package/lib/plugins/reorder/index.d.ts.map +0 -1
- package/lib/plugins/reorder/index.js +0 -2
- package/lib/plugins/reorder/index.js.map +0 -1
- package/lib/plugins/reorder/types.d.ts.map +0 -1
- package/lib/plugins/row-reorder/RowReorderPlugin.d.ts.map +0 -1
- package/lib/plugins/row-reorder/index.d.ts.map +0 -1
- package/lib/plugins/row-reorder/index.js +0 -2
- package/lib/plugins/row-reorder/index.js.map +0 -1
- package/lib/plugins/row-reorder/types.d.ts.map +0 -1
- package/umd/plugins/reorder.umd.js +0 -2
- package/umd/plugins/reorder.umd.js.map +0 -1
- package/umd/plugins/row-reorder.umd.js +0 -2
- package/umd/plugins/row-reorder.umd.js.map +0 -1
- /package/lib/plugins/{reorder → reorder-columns}/column-drag.d.ts +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function t(t,e){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:n}=t._virtualization,r=i,s=n?.clientHeight??r?.clientHeight??0;if(r&&s>0){const i=t._focusRow*e;i<r.scrollTop?r.scrollTop=i:i+e>r.scrollTop+s&&(r.scrollTop=i-s+e)}}const i=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var n;i||t.refreshVirtualWindow(!1),(n=t._bodyEl)&&n.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 r=t._focusRow,s=t._virtualization.start??0,o=t._virtualization.end??t._rows.length;if(r>=s&&r<o){const n=t._bodyEl.querySelectorAll(".data-grid-row")[r-s];let o=n?.children[t._focusCol];if(o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${t._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const r=t.querySelector(".tbw-scroll-area");if(r&&o&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)r.scrollLeft=0;else if(e?.forceScrollRight)r.scrollLeft=r.scrollWidth-r.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(n??void 0,o)??{left:0,right:0};if(!e.skipScroll){const t=o.getBoundingClientRect(),i=r.getBoundingClientRect(),n=t.left-i.left+r.scrollLeft,s=n+t.width,d=r.scrollLeft+e.left,l=r.scrollLeft+r.clientWidth-e.right;n<d?r.scrollLeft=n-e.left:s>l&&(r.scrollLeft=s-r.clientWidth+e.right)}}if(i&&o.classList.contains("editing")){const t=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}}else if(i&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!i){const e=t;document.activeElement!==e&&e.focus({preventScroll:!0})}}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const e='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',i={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class n{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...i,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}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}}const s="__tbw_null__";function o(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?s:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}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 d(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class l{#e=/* @__PURE__ */new Map;#i;constructor(t){this.#i=t}setInvalid(t,e,i=""){let n=this.#e.get(t);n||(n=/* @__PURE__ */new Map,this.#e.set(t,n)),n.set(e,i),this.#i(t,e,!0)}clearInvalid(t,e){const i=this.#e.get(t);i&&(i.delete(e),0===i.size&&this.#e.delete(t)),this.#i(t,e,!1)}clearRowInvalid(t){const e=this.#e.get(t);if(e){const i=Array.from(e.keys());this.#e.delete(t),i.forEach(e=>this.#i(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#e.entries());this.#e.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#i(t,i,!1))})}isCellInvalid(t,e){return this.#e.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#e.get(t)?.get(e)}hasInvalidCells(t){const e=this.#e.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#e.get(t)??[])}}function a(t,e,i){const n=t.get(e);return!!n&&!c(n,i)}function c(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(!c(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!c(i[t],n[t]))return!1;return!0}return!1}function u(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,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class g{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;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return a(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&&a(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!c(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&a(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){u(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&u(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&&a(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&&a(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)}}const f='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function w(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function m(t){}function v(t,e){return!1===t.onBeforeEditClose?.(e)}function p(t,e,i,n,r,s,l){if(!n.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:g}=t;let p;try{p=a.getRowId?.(e)}catch{}const y=p?t=>a.updateRow(p,t,"cascade"):m,E=w(n.field)?e[n.field]:void 0;s.classList.add("editing"),h.add(`${i}:${r}`);const R=s.parentElement;R&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(R);let b=!1;const C=r=>{if(b||!c&&!t.isEditSessionActive())return;const s=p?a._getRowEntry(p):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},I=()=>{if(b=!0,w(n.field)){const t=p?a._getRowEntry(p):void 0;(t?.row??e)[n.field]=E}},k=document.createElement("div");k.className="tbw-editor-host",s.innerHTML="",s.appendChild(k),k.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=k.querySelector("input,textarea,select");return void(t&&C(d(t,n,E)))}if(v(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(v(u,e))return;e.stopPropagation(),e.preventDefault(),I(),t.exitRowEdit(i,!0)}});const _=n,S=_.__editorTemplate,x=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,_)??o(n),M=E,A=`${i}:${n.field}`,L=[];g.set(A,t=>{for(const e of L)e(t)});const D=t=>{L.push(t)};if("template"===x&&S)!function(t,e,i,n,r,s,o,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:o}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!w(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(d(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(d(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,k,_,e,E,C,I,l,i),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof x){const t=document.createElement(x);t.value=M,t.addEventListener("change",()=>C(t.value)),D(e=>{t.value=e}),k.appendChild(t),l||queueMicrotask(()=>{const t=k.querySelector(f);t?.focus({preventScroll:!0})})}else if("function"==typeof x){const t=x({row:e,rowId:p??"",value:M,field:n.field,column:n,commit:C,cancel:I,updateRow:y,onValueChange:D});if("string"==typeof t)k.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(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))))}(k,n,C,E),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){k.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?D(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):s.setAttribute("data-editor-managed","")}else!t&&k.hasChildNodes()&&s.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=k.querySelector(f);t?.focus({preventScroll:!0})})}else if(x&&"object"==typeof x){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),k.appendChild(t),s.setAttribute("data-editor-managed","");const i={row:e,rowId:p??"",value:M,field:n.field,column:n,commit:C,cancel:I,updateRow:y,onValueChange:D};if(x.mount)try{x.mount({placeholder:t,context:i,spec:x})}catch(T){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,T)}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:x,context:i}}))}}class y extends n{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#n(){return"grid"===this.config.mode}#r=-1;#s;#o;#d=-1;#l=/* @__PURE__ */new Map;#a=/* @__PURE__ */new Set;#c=/* @__PURE__ */new Map;#u=!1;#h=-1;#g;#f=!1;#w=!1;#m=!1;#v=null;#p=new g;#y;attach(t){super.attach(t);const e=this.disconnectSignal,i=t;if(this.#g=new l((t,e,i)=>{this.#E(t,e,i)}),this.#y={grid:i,isGridMode:this.#n,config:this.config,editingCells:this.#a,editorValueCallbacks:this.#c,isEditSessionActive:()=>-1!==this.#r,commitCellValue:(t,e,i,n)=>this.#R(t,e,i,n),exitRowEdit:(t,e)=>this.#b(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#r){if(v(this.config,t))return;this.#b(this.#r,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#n)return;if(-1===this.#r)return;const e=i.findRenderedRowElement?.(this.#r);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||v(this.config,t)||queueMicrotask(()=>{-1!==this.#r&&this.#b(this.#r,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#n)return;if(-1===this.#r)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#r&&this.#C()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#c.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#p.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#p.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#n&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(f)){if(this.#w)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#v;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#v={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#f=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(f)||(this.#f=!1,this.#v=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#f){if(v(this.config,t))return void queueMicrotask(()=>{if(this.#f){this.#I();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0}});this.#I();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(f)&&(this.#w=!1)},{signal:e}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#r=-1,this.#s=void 0,this.#o=void 0,this.#d=-1,this.#l.clear(),this.#p.clear(),this.#a.clear(),this.#c.clear(),this.#f=!1,this.#w=!1,this.#v=null,this.#m=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#n||-1!==this.#r}onCellClick(t){if(this.#n)return!1;const e=this.grid,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const i=this.grid;if("Escape"===e.key){if(this.#n&&this.#f){this.#I();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0,this.requestAfterRender(),!0}if(-1!==this.#r&&!this.#n)return v(this.config,e)||this.#b(this.#r,!0),!0}if(this.#n&&!this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#n&&this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#r&&!this.#n){if(v(this.config,e))return!0;const n=i._rows.length-1,r=this.#r;return this.#b(r,!1),"ArrowDown"===e.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),e.preventDefault(),t(i),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#r||this.#n)){if(e.preventDefault(),this.#m)return this.#b(this.#r,!1),!0;const t=!e.shiftKey;return this.#k(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#r)return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[t];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(w(i)){const n=!s[i];return this.#R(t,r,n,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#n&&!this.#f)return this.#C(),!0;if(-1!==this.#r)return!!v(this.config,e);const t=this.config.editOn??i.effectiveConfig?.editOn;if(!1===t||"manual"===t)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const t=i._columns?.some(t=>t.editable);if(t){const t=i._visibleColumns[r],s=i._rows[n],o=t?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#r||this.#n)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return e.preventDefault(),this.beginCellEdit(t,r.field),!0}return!1}return!1}processColumns(t){const e=this.grid,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.grid;if(this.config.dirtyTracking&&e.getRowId&&this.#p.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#r||this.#n)return t;const i=this.#s,n=this.#o;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#r!==s&&this.#_(this.#r,s),r)}afterRender(){const t=this.grid;if(-1!==this.#r&&this.#o&&!this.#n&&t._rows[this.#r]!==this.#o){const e=t._rows.indexOf(this.#o);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#_(this.#r,e)}if(this.#u&&(this.#u=!1,this.#S(t)),-1!==this.#h){const e=this.#h;this.#h=-1,t.animateRow?.(e,"change")}const e=this.#p.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#n&&0!==this.#a.size)for(const i of this.#a){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#x(l,r,a,s,d,!0)}}afterCellRender(t){if(!this.#n)return;const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable&&(s.classList.contains("editing")||this.#x(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.gridElement,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#p.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#p.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#p.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#p.getChangedRowIds()}get activeEditRow(){return this.#r}get activeEditCol(){return this.#d}isRowEditing(t){return this.#r===t}isCellEditing(t,e){return this.#a.has(`${t}:${e}`)}isRowChanged(t){const e=this.grid,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#p.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#p.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#p.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#p.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.grid;return this.#p.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.#p.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#p.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.#p.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#p.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#p.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#p.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#p.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#p.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#p.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#p.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#p.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#p.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#g.setInvalid(t,e,i)}clearInvalid(t,e){this.#g.clearInvalid(t,e)}clearRowInvalid(t){this.#g.clearRowInvalid(t)}clearAllInvalid(){this.#g.clearAllInvalid()}isCellInvalid(t,e){return this.#g.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#g.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#g.hasInvalidCells(t)}getInvalidFields(t){return this.#g.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#p.changedRowIds.clear(),this.#p.committedDirtyRowIds.clear(),this.#M(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.grid;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.grid,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#m=!0,this.#A(t,n,o))}beginBulkEdit(t){const e=this.grid;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#m=!1;const r=e._rows[t];this.#L(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#x(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(f);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#r&&this.#b(this.#r,!1)}cancelActiveRowEdit(){-1!==this.#r&&this.#b(this.#r,!0)}#E(t,e,i){const n=this.grid,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#g.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#_(t,e){this.#r=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const o of this.#a)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#a.clear();for(const o of i)this.#a.add(o);const r=this.#l.get(t);void 0!==r&&(this.#l.delete(t),this.#l.set(e,r));const s=[];for(const[o,d]of this.#c)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#c.delete(o));for(const[o,d]of s)this.#c.set(o,d);this.#M()}#A(t,e,i){const n=this.grid,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#r!==t&&this.#L(t,r),this.#d=e,this.#x(r,t,s,e,i,!1)))}#I(){const t=this.#v;if(!t)return;const e=this.grid,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#c.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#v=null}#C(){const t=this.grid,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(f);t&&(this.#w=!1,t.focus(),this.#f=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#k(e){const i=this.grid,n=i._rows,r=this.#n?i._focusRow:this.#r,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(e?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const e=i.findRenderedRowElement?.(r),n=e?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(f);t?.focus({preventScroll:!0})}return void t(i,{forceHorizontalScroll:!0})}const d=r+(e?1:-1);d>=0&&d<n.length&&(this.#n?(i._focusRow=d,i._focusCol=e?s[0]:s[s.length-1],t(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(f);t?.focus({preventScroll:!0})}},0)):(this.#b(r,!1),i._focusRow=d,i._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(d),t(i,{forceHorizontalScroll:!0})))}#M(){const t=this.grid;t._activeEditRows=this.#r,t._rowEditSnapshots=this.#l}#L(t,e){if(this.#r!==t){-1!==this.#r&&this.#b(this.#r,!1),this.#l.set(t,{...e}),this.#r=t,this.#o=e;const i=this.grid;try{this.#s=i.getRowId?.(e)??void 0}catch{this.#s=void 0}this.#M(),this.#n||this.emit("edit-open",{rowIndex:t,rowId:this.#s??"",row:e})}}#b(t,e){if(this.#r!==t)return;const i=this.grid,n=this.#l.get(t),r=i.findRenderedRowElement?.(t);let s=this.#s;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#o??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=d(s,r,i);i!==n&&this.#R(t,r,n,l)}})}if(e||this.#n||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#p.changedRowIds.delete(s),this.#p.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#p.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#p.changedRowIds.delete(s),this.#p.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#p.isRowDirty(s,l)?this.#p.committedDirtyRowIds.add(s):this.#p.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#h=t))}this.#l.delete(t),this.#r=-1,this.#s=void 0,this.#o=void 0,this.#d=-1,this.#m=!1,this.#M();for(const d of this.#a)d.startsWith(`${t}:`)&&this.#a.delete(d);for(const d of this.#c.keys())d.startsWith(`${t}:`)&&this.#c.delete(d);this.#u=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#S(i),this.#u=!1),!this.#n&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#R(t,e,i,n){const r=e.field;if(!w(r))return;const s=n[r];if(s===i)return;const o=this.grid;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#p.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):m;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#p.changedRowIds.add(d),this.#M(),this.config.dirtyTracking&&d){const t=this.#p.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#p.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#x(t,e,i,n,r,s){p(this.#y,t,e,i,n,r,s)}#S(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{y as EditingPlugin,o as defaultEditorFor};
|
|
1
|
+
document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function t(t,e){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:n}=t._virtualization,r=i,s=n?.clientHeight??r?.clientHeight??0;if(r&&s>0){const i=t._focusRow*e;i<r.scrollTop?r.scrollTop=i:i+e>r.scrollTop+s&&(r.scrollTop=i-s+e)}}const i=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var n;i||t.refreshVirtualWindow(!1),(n=t._bodyEl)&&n.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 r=t._focusRow,s=t._virtualization.start??0,o=t._virtualization.end??t._rows.length;if(r>=s&&r<o){const n=t._bodyEl.querySelectorAll(".data-grid-row")[r-s];let o=n?.children[t._focusCol];if(o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${t._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const r=t.querySelector(".tbw-scroll-area");if(r&&o&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)r.scrollLeft=0;else if(e?.forceScrollRight)r.scrollLeft=r.scrollWidth-r.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(n??void 0,o)??{left:0,right:0};if(!e.skipScroll){const t=o.getBoundingClientRect(),i=r.getBoundingClientRect(),n=t.left-i.left+r.scrollLeft,s=n+t.width,d=r.scrollLeft+e.left,l=r.scrollLeft+r.clientWidth-e.right;n<d?r.scrollLeft=n-e.left:s>l&&(r.scrollLeft=s-r.clientWidth+e.right)}}if(i&&o.classList.contains("editing")){const t=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}}else if(i&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!i){const e=t;document.activeElement!==e&&e.focus({preventScroll:!0})}}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const e='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',i={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class n{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...i,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}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}}const s="__tbw_null__";function o(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?s:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}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 d(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class l{#e=/* @__PURE__ */new Map;#i;constructor(t){this.#i=t}setInvalid(t,e,i=""){let n=this.#e.get(t);n||(n=/* @__PURE__ */new Map,this.#e.set(t,n)),n.set(e,i),this.#i(t,e,!0)}clearInvalid(t,e){const i=this.#e.get(t);i&&(i.delete(e),0===i.size&&this.#e.delete(t)),this.#i(t,e,!1)}clearRowInvalid(t){const e=this.#e.get(t);if(e){const i=Array.from(e.keys());this.#e.delete(t),i.forEach(e=>this.#i(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#e.entries());this.#e.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#i(t,i,!1))})}isCellInvalid(t,e){return this.#e.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#e.get(t)?.get(e)}hasInvalidCells(t){const e=this.#e.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#e.get(t)??[])}}function a(t,e,i){const n=t.get(e);return!!n&&!c(n,i)}function c(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(!c(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!c(i[t],n[t]))return!1;return!0}return!1}function u(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,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class g{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;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return a(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&&a(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!c(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&a(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){u(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&u(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&&a(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&&a(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)}}const f='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function w(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function m(t){}function v(t,e){return!1===t.onBeforeEditClose?.(e)}function p(t,e,i,n,r,s,l){if(!n.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:g}=t;let p;try{p=a.getRowId?.(e)}catch{}const y=p?t=>a.updateRow(p,t,"cascade"):m,E=w(n.field)?e[n.field]:void 0;s.classList.add("editing"),h.add(`${i}:${r}`);const R=s.parentElement;R&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(R);let b=!1;const C=r=>{if(b||!c&&!t.isEditSessionActive())return;const s=p?a._getRowEntry(p):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},I=()=>{if(b=!0,w(n.field)){const t=p?a._getRowEntry(p):void 0;(t?.row??e)[n.field]=E}},k=document.createElement("div");k.className="tbw-editor-host",s.innerHTML="",s.appendChild(k),k.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=k.querySelector("input,textarea,select");return void(t&&C(d(t,n,E)))}if(v(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(v(u,e))return;e.stopPropagation(),e.preventDefault(),I(),t.exitRowEdit(i,!0)}});const _=n,S=_.__editorTemplate,x=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,_)??o(n),M=E,A=`${i}:${n.field}`,L=[];g.set(A,t=>{for(const e of L)e(t)});const D=t=>{L.push(t)};if("template"===x&&S)!function(t,e,i,n,r,s,o,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:o}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!w(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(d(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(d(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,k,_,e,E,C,I,l,i),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof x){const t=document.createElement(x);t.value=M,t.addEventListener("change",()=>C(t.value)),D(e=>{t.value=e}),k.appendChild(t),l||queueMicrotask(()=>{const t=k.querySelector(f);t?.focus({preventScroll:!0})})}else if("function"==typeof x){const t=x({row:e,rowId:p??"",value:M,field:n.field,column:n,commit:C,cancel:I,updateRow:y,onValueChange:D});if("string"==typeof t)k.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(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))))}(k,n,C,E),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){k.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?D(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):s.setAttribute("data-editor-managed","")}else!t&&k.hasChildNodes()&&s.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=k.querySelector(f);t?.focus({preventScroll:!0})})}else if(x&&"object"==typeof x){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),k.appendChild(t),s.setAttribute("data-editor-managed","");const i={row:e,rowId:p??"",value:M,field:n.field,column:n,commit:C,cancel:I,updateRow:y,onValueChange:D};if(x.mount)try{x.mount({placeholder:t,context:i,spec:x})}catch(T){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,T)}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:x,context:i}}))}}class y extends n{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#n(){return"grid"===this.config.mode}#r=-1;#s;#o;#d=-1;#l=/* @__PURE__ */new Map;#a=/* @__PURE__ */new Set;#c=/* @__PURE__ */new Map;#u=!1;#h=-1;#g;#f=!1;#w=!1;#m=!1;#v=null;#p=new g;#y;attach(t){super.attach(t);const e=this.disconnectSignal,i=t;if(this.#g=new l((t,e,i)=>{this.#E(t,e,i)}),this.#y={grid:i,isGridMode:this.#n,config:this.config,editingCells:this.#a,editorValueCallbacks:this.#c,isEditSessionActive:()=>-1!==this.#r,commitCellValue:(t,e,i,n)=>this.#R(t,e,i,n),exitRowEdit:(t,e)=>this.#b(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#r){if(v(this.config,t))return;this.#b(this.#r,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#n)return;if(-1===this.#r)return;const e=i.findRenderedRowElement?.(this.#r);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||v(this.config,t)||queueMicrotask(()=>{-1!==this.#r&&this.#b(this.#r,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#n)return;if(-1===this.#r)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#r&&this.#C()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#c.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#p.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#p.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#n&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(f)){if(this.#w)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#v;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#v={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#f=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(f)||(this.#f=!1,this.#v=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#f){if(v(this.config,t))return void queueMicrotask(()=>{if(this.#f){this.#I();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0}});this.#I();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(f)&&(this.#w=!1)},{signal:e}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#r=-1,this.#s=void 0,this.#o=void 0,this.#d=-1,this.#l.clear(),this.#p.clear(),this.#a.clear(),this.#c.clear(),this.#f=!1,this.#w=!1,this.#v=null,this.#m=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#n||-1!==this.#r}onCellClick(t){if(this.#n)return!1;const e=this.grid,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const i=this.grid;if("Escape"===e.key){if(this.#n&&this.#f){this.#I();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0,this.requestAfterRender(),!0}if(-1!==this.#r&&!this.#n)return v(this.config,e)||this.#b(this.#r,!0),!0}if(this.#n&&!this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#n&&this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#r&&!this.#n){if(v(this.config,e))return!0;const n=i._rows.length-1,r=this.#r;return this.#b(r,!1),"ArrowDown"===e.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),e.preventDefault(),t(i),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#r||this.#n)){if(e.preventDefault(),this.#m)return this.#b(this.#r,!1),!0;const t=!e.shiftKey;return this.#k(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#r)return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[t];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(w(i)){const n=!s[i];return this.#R(t,r,n,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#n&&!this.#f)return this.#C(),!0;if(-1!==this.#r)return!!v(this.config,e);const t=this.config.editOn??i.effectiveConfig?.editOn;if(!1===t||"manual"===t)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const t=i._columns?.some(t=>t.editable);if(t){const t=i._visibleColumns[r],s=i._rows[n],o=t?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#r||this.#n)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return e.preventDefault(),this.beginCellEdit(t,r.field),!0}return!1}return!1}processColumns(t){const e=this.grid,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.grid;if(this.config.dirtyTracking&&e.getRowId&&this.#p.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#r||this.#n)return t;const i=this.#s,n=this.#o;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#r!==s&&this.#_(this.#r,s),r)}afterRender(){const t=this.grid;if(-1!==this.#r&&this.#o&&!this.#n&&t._rows[this.#r]!==this.#o){const e=t._rows.indexOf(this.#o);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#_(this.#r,e)}if(this.#u&&(this.#u=!1,this.#S(t)),-1!==this.#h){const e=this.#h;this.#h=-1,t.animateRow?.(e,"change")}const e=this.#p.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#n&&0!==this.#a.size)for(const i of this.#a){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#x(l,r,a,s,d,!0)}}afterCellRender(t){if(!this.#n)return;const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable&&(s.classList.contains("editing")||this.#x(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.gridElement,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#p.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#p.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#p.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#p.getChangedRowIds()}get activeEditRow(){return this.#r}get activeEditCol(){return this.#d}isRowEditing(t){return this.#r===t}isCellEditing(t,e){return this.#a.has(`${t}:${e}`)}isRowChanged(t){const e=this.grid,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#p.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#p.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#p.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#p.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.grid;return this.#p.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.#p.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#p.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.#p.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#p.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#p.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#p.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#p.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#p.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#p.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#p.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#p.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#p.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#g.setInvalid(t,e,i)}clearInvalid(t,e){this.#g.clearInvalid(t,e)}clearRowInvalid(t){this.#g.clearRowInvalid(t)}clearAllInvalid(){this.#g.clearAllInvalid()}isCellInvalid(t,e){return this.#g.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#g.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#g.hasInvalidCells(t)}getInvalidFields(t){return this.#g.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#p.changedRowIds.clear(),this.#p.committedDirtyRowIds.clear(),this.#M(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.grid;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.grid,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#m=!0,this.#A(t,n,o))}beginBulkEdit(t){const e=this.grid;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#m=!1;const r=e._rows[t];this.#L(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#x(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(f);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#r&&this.#b(this.#r,!1)}cancelActiveRowEdit(){-1!==this.#r&&this.#b(this.#r,!0)}#E(t,e,i){const n=this.grid,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#g.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#_(t,e){this.#r=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const o of this.#a)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#a.clear();for(const o of i)this.#a.add(o);const r=this.#l.get(t);void 0!==r&&(this.#l.delete(t),this.#l.set(e,r));const s=[];for(const[o,d]of this.#c)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#c.delete(o));for(const[o,d]of s)this.#c.set(o,d);this.#M()}#A(t,e,i){const n=this.grid,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#r!==t&&this.#L(t,r),this.#d=e,this.#x(r,t,s,e,i,!1)))}#I(){const t=this.#v;if(!t)return;const e=this.grid,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#c.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#v=null}#C(){const t=this.grid,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(f);t&&(this.#w=!1,t.focus(),this.#f=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#k(e){const i=this.grid,n=i._rows,r=this.#n?i._focusRow:this.#r,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(e?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const e=i.findRenderedRowElement?.(r),n=e?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(f);t?.focus({preventScroll:!0})}return void t(i,{forceHorizontalScroll:!0})}const d=r+(e?1:-1);d>=0&&d<n.length&&(this.#n?(i._focusRow=d,i._focusCol=e?s[0]:s[s.length-1],t(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(f);t?.focus({preventScroll:!0})}},0)):(this.#b(r,!1),i._focusRow=d,i._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(d),t(i,{forceHorizontalScroll:!0})))}#M(){const t=this.grid;t._activeEditRows=this.#r,t._rowEditSnapshots=this.#l}#L(t,e){if(this.#r!==t){-1!==this.#r&&this.#b(this.#r,!1),this.#l.set(t,{...e}),this.#r=t,this.#o=e;const i=this.grid;try{this.#s=i.getRowId?.(e)??void 0}catch{this.#s=void 0}this.#M(),this.#n||this.emit("edit-open",{rowIndex:t,rowId:this.#s??"",row:e})}}#b(t,e){if(this.#r!==t)return;const i=this.grid,n=this.#l.get(t),r=i.findRenderedRowElement?.(t);let s=this.#s;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#o??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=d(s,r,i);i!==n&&this.#R(t,r,n,l)}})}if(e||this.#n||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#p.changedRowIds.delete(s),this.#p.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#p.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#p.changedRowIds.delete(s),this.#p.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#p.isRowDirty(s,l)?this.#p.committedDirtyRowIds.add(s):this.#p.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#h=t))}this.#l.delete(t),this.#r=-1,this.#s=void 0,this.#o=void 0,this.#d=-1,this.#m=!1,this.#M();for(const d of this.#a)d.startsWith(`${t}:`)&&this.#a.delete(d);for(const d of this.#c.keys())d.startsWith(`${t}:`)&&this.#c.delete(d);this.#u=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#S(i),this.#u=!1),!this.#n&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#R(t,e,i,n){const r=e.field;if(!w(r))return;const s=n[r];if(s===i)return;const o=this.grid;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#p.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):m;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#p.changedRowIds.add(d),this.#M(),this.config.dirtyTracking&&d){const t=this.#p.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#p.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#x(t,e,i,n,r,s){p(this.#y,t,e,i,n,r,s)}#S(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{y as EditingPlugin,o as defaultEditorFor};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|