@toolbox-web/grid 2.0.0-rc.1 → 2.0.0-rc.2
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 +23 -6
- 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/internal/sorting.d.ts +4 -0
- package/lib/core/plugin/base-plugin.d.ts +31 -0
- package/lib/core/plugin/plugin-manager.d.ts +4 -1
- package/lib/core/plugin/types.d.ts +2 -0
- package/lib/core/types.d.ts +20 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +8 -1
- 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/ExportPlugin.d.ts +8 -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/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +33 -1
- package/lib/plugins/grouping-rows/grouping-rows.d.ts +15 -1
- package/lib/plugins/grouping-rows/index.js +2 -2
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- 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-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts +10 -0
- 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-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts +3 -0
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js.map +1 -1
- 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/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +16 -0
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +6 -0
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +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/clipboard.umd.js +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/reorder-rows.umd.js +1 -1
- package/umd/plugins/reorder-rows.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tooltip.umd.js +1 -1
- package/umd/plugins/tooltip.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t={sortApplied:(t,e)=>`Sorted by ${t}, ${e}`,sortCleared:()=>"Sort cleared",filterApplied:t=>`Filter applied on ${t}`,filterCleared:t=>`Filter cleared from ${t}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(t,e)=>`Group ${t} expanded, ${e} rows`,groupCollapsed:t=>`Group ${t} collapsed`,selectionChanged:t=>`${t} rows selected`,editingStarted:t=>`Editing row ${t+1}`,editingCommitted:t=>`Row ${t+1} saved`,dataLoaded:t=>`${t} rows loaded`},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:"🖨️"};function r(t,e){if(!t)return;const i="effectiveConfig"in t?t.effectiveConfig:void 0;if(!1===i?.a11y?.announcements)return;const r=t.querySelector?.(".tbw-sr-only");r&&(r.textContent="",requestAnimationFrame(()=>{r.textContent=e}))}function n(e,i,...r){const n=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,s=n?.a11y?.messages?.[i];return s?s(...r):t[i](...r)}const s="editing";function o(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function l(t,e,i,r){return`${o(i,r)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}["__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"].map(t=>t.split("").reverse().join(""));const d=/* @__PURE__ */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"]),a=/^on\w+$/i,c=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),u=/^\s*(javascript|vbscript|data|blob):/i;function h(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const r of i){const t=r.tagName.toLowerCase();if(d.has(t)){e.push(r);continue}if("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(t=>a.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}}const i=[];for(const e of r.attributes){const t=e.name.toLowerCase();a.test(t)?i.push(e.name):(c.has(t)&&u.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name)}i.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function f(t,e){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:r}=t._virtualization,n=i,s=r?.clientHeight??n?.clientHeight??0;if(n&&s>0){const i=t._focusRow*e;i<n.scrollTop?n.scrollTop=i:i+e>n.scrollTop+s&&(n.scrollTop=i-s+e)}}const i=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var r;i||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 n=t._focusRow,o=t._virtualization.start??0,l=t._virtualization.end??t._rows.length;if(n>=o&&n<l){const r=t._bodyEl.querySelectorAll(".data-grid-row")[n-o];let l=r?.children[t._focusCol];if(l&&l.classList?.contains("cell")||(l=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const n=t.querySelector(".tbw-scroll-area");if(n&&l&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)n.scrollLeft=0;else if(e?.forceScrollRight)n.scrollLeft=n.scrollWidth-n.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(r??void 0,l)??{left:0,right:0};if(!e.skipScroll){const t=l.getBoundingClientRect(),i=n.getBoundingClientRect(),r=t.left-i.left+n.scrollLeft,s=r+t.width,o=n.scrollLeft+e.left,d=n.scrollLeft+n.clientWidth-e.right;r<o?n.scrollLeft=r-e.left:s>d&&(n.scrollLeft=s-n.clientWidth+e.right)}}if(i&&l.classList.contains(s)){const t=l.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&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else i||document.activeElement!==t&&t.focus({preventScroll:!0})}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';class g{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?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}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?._hostElement}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}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,i);void 0!==r?"string"==typeof r?t.innerHTML=h(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(r.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(i,r):t.appendChild(i),i}warn(t,e){void 0!==e?console.warn(l(t,e,this.gridElement.id,this.name)):console.warn(`${o(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(l(t,e,this.gridElement.id,this.name))}}function w(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="date",e.value instanceof Date?r.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(r.value=e.value.split("T")[0]),i?.min&&(r.min=i.min),i?.max&&(r.max=i.max),i?.placeholder&&(r.placeholder=i.placeholder);return r.addEventListener("change",()=>{var n;if(r.value)"string"==typeof e.value?e.commit(r.value):e.commit(r.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:`${(n=t??/* @__PURE__ */new Date).getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),r.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),r}}const m="__tbw_null__";function p(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="number",r.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(r.min=String(i.min)),void 0!==i?.max&&(r.max=String(i.max)),void 0!==i?.step&&(r.step=String(i.step)),i?.placeholder&&(r.placeholder=i.placeholder);const n=()=>{""===r.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(r.value))};return r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Enter"===t.key&&n(),"Escape"===t.key&&e.cancel()}),r}}(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 w(t);case"select":return function(t){return e=>{const i=t.editorParams,r=document.createElement("select");if(t.multi&&(r.multiple=!0),t.nullable||i?.includeEmpty){const n=document.createElement("option");n.value=t.nullable?m:"",n.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(n.selected=!0),r.appendChild(n)}const n=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);n.forEach(i=>{const n=document.createElement("option");n.value=String(i.value),n.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?n.selected=!0:t.multi||e.value!==i.value||(n.selected=!0),r.appendChild(n)});const s=()=>{if(t.multi){const t=Array.from(r.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&r.value===m?e.commit(null):e.commit(r.value)};return r.addEventListener("change",s),r.addEventListener("blur",s),r.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),r}}(t);default:return function(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="text",r.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(r.maxLength=i.maxLength),i?.pattern&&(r.pattern=i.pattern),i?.placeholder&&(r.placeholder=i.placeholder);const n=()=>{const i=r.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 r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Enter"===t.key&&n(),"Escape"===t.key&&e.cancel()}),r}}(t)}}function v(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 y{#i=/* @__PURE__ */new Map;#r;constructor(t){this.#r=t}setInvalid(t,e,i=""){let r=this.#i.get(t);r||(r=/* @__PURE__ */new Map,this.#i.set(t,r)),r.set(e,i),this.#r(t,e,!0)}clearInvalid(t,e){const i=this.#i.get(t);i&&(i.delete(e),0===i.size&&this.#i.delete(t)),this.#r(t,e,!1)}clearRowInvalid(t){const e=this.#i.get(t);if(e){const i=Array.from(e.keys());this.#i.delete(t),i.forEach(e=>this.#r(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#i.entries());this.#i.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#r(t,i,!1))})}isCellInvalid(t,e){return this.#i.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#i.get(t)?.get(e)}hasInvalidCells(t){const e=this.#i.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#i.get(t)??[])}}function E(t,e,i){const r=t.get(e);return!!r&&!b(r,i)}function b(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(!b(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,r=e,n=Object.keys(i),s=Object.keys(r);if(n.length!==s.length)return!1;for(const t of n)if(!b(i[t],r[t]))return!1;return!0}return!1}function R(t,e,i){t.set(e,structuredClone(i))}function C(t,e,i){const r=t.get(e);if(!r)return!1;const n=r,s=i;for(const o of Object.keys(n))s[o]=n[o];return!0}class I{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 r of e)try{const e=i(r);null==e||t.has(e)||t.set(e,structuredClone(r))}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 E(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&&E(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,r){const n=t.get(e);return!!n&&!b(n[r],i[r])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&E(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){R(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&&R(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,r]of this.baselines){const n=t(i);n&&E(this.baselines,i,n)&&e.push({id:i,original:structuredClone(r),current:n})}for(const i of this.newRowIds){const r=t(i);r&&e.push({id:i,original:void 0,current:r})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const r=t(i);r&&E(this.baselines,i,r)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=C(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&&C(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const r=t(i);r&&e.push(r)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const _='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function k(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function S(t){}function x(t,e){return!1===t.onBeforeEditClose?.(e)}function A(t,e,i,r,n,s,o,d){if(!r.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:f}=t;let g;try{g=a.getRowId?.(e)}catch{}const w=g?t=>a.updateRow(g,t,"cascade"):S,m=k(r.field)?e[r.field]:void 0;s.classList.add("editing"),h.add(`${i}:${n}`);const y=d??s.parentElement;y&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(y);let E=!1;const b=n=>{if(E||!c&&!t.isEditSessionActive())return;const s=g?a._getRowEntry(g):void 0,o=s?.row??e,l=s?.index??i;t.commitCellValue(l,r,n,o)},R=()=>{if(E=!0,k(r.field)){const t=g?a._getRowEntry(g):void 0;(t?.row??e)[r.field]=m}},C=document.createElement("div");C.className="tbw-editor-host",s.innerHTML="",s.appendChild(C),C.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=C.querySelector("input,textarea,select");return void(t&&b(v(t,r,m)))}if(x(u,e))return;e.stopPropagation(),e.preventDefault(),E=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(x(u,e))return;e.stopPropagation(),e.preventDefault(),R(),t.exitRowEdit(i,!0)}});const I=r,A=I.__editorTemplate,M=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const r=t.__frameworkAdapter;if(r?.getTypeDefault){const t=r.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,I)??p(r),L=m,D=`${i}:${r.field}`,G=[];f.set(D,t=>{for(const e of G)e(t)});const T=t=>{G.push(t)};if("template"===M&&A)!function(t,e,i,r,n,s,o,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:r,value:n,field:i.field,column:i,commit:s,cancel:o}):c.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!k(e))return"";const i=r[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!n:h.value=String(n??"");let e=!1;h.addEventListener("blur",()=>{e||s(v(h,i,n))}),h.addEventListener("keydown",r=>{const l=r;if("Enter"===l.key){if(x(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(v(h,i,n)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(x(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(d,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>s(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(t,C,I,e,m,b,R,o,i),T(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 M){const t=document.createElement(M);t.value=L,t.addEventListener("change",()=>b(t.value)),T(e=>{t.value=e}),C.appendChild(t),o||queueMicrotask(()=>{const t=C.querySelector(_);t?.focus({preventScroll:!0})})}else if("function"==typeof M){const t=M({row:e,rowId:g??"",value:L,field:r.field,column:r,commit:b,cancel:R,updateRow:w,onValueChange:T});if("string"==typeof t)C.innerHTML=t,function(t,e,i,r){const n=t.querySelector("input,textarea,select");n&&(n.addEventListener("blur",()=>{i(v(n,e,r))}),n instanceof HTMLInputElement&&"checkbox"===n.type?n.addEventListener("change",()=>i(n.checked)):n instanceof HTMLSelectElement&&n.addEventListener("change",()=>i(v(n,e,r))))}(C,r,b,m),T(t=>{const e=C.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){C.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?T(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):s.setAttribute("data-editor-managed","")}else!t&&C.hasChildNodes()&&s.setAttribute("data-editor-managed","");o||queueMicrotask(()=>{const t=C.querySelector(_);t?.focus({preventScroll:!0})})}else if(M&&"object"==typeof M){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",r.field),C.appendChild(i),s.setAttribute("data-editor-managed","");const n={row:e,rowId:g??"",value:L,field:r.field,column:r,commit:b,cancel:R,updateRow:w,onValueChange:T};if(M.mount)try{M.mount({placeholder:i,context:n,spec:M})}catch(O){q="TBW080",$=`External editor mount error for column '${r.field}': ${O}`,P=t.grid.id,console.warn(l(q,$,P,F))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:M,context:n}}))}var q,$,P,F}class M extends g{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};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:max(var(--tbw-row-height),calc(1lh + 2 * var(--tbw-cell-padding-v, .25em) + var(--tbw-border-width, 1px)));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;align-self:stretch;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}#s(t,e){const i=this.#o.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:r}=t;return"function"==typeof r?r(e):!0===r}#l(t){return!0===t.editable||"function"==typeof t.editable}#d=-1;#a;#c;#u=-1;#h=/* @__PURE__ */new Map;#f=/* @__PURE__ */new Set;#g=/* @__PURE__ */new Map;#w=!1;#m=-1;#p;#v=!1;#y=!1;#E=!1;#b=null;#R=new I;#C;get#o(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#o;if(this.#p=new y((t,e,i)=>{this.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#n,config:this.config,editingCells:this.#f,editorValueCallbacks:this.#g,isEditSessionActive:()=>-1!==this.#d,commitCellValue:(t,e,i,r)=>this.#_(t,e,i,r),exitRowEdit:(t,e)=>this.#k(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}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#R.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#d){if(x(this.config,t))return;this.#k(this.#d,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#n)return;if(-1===this.#d)return;const e=i.findRenderedRowElement?.(this.#d);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const r=t.target;r&&!this.gridElement.contains(r)&&this.grid.containsFocus?.(r)||x(this.config,t)||queueMicrotask(()=>{-1!==this.#d&&this.#k(this.#d,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#n)return;if(-1===this.#d)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#d&&this.#S()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,r=this.#g.get(i);r&&r(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const r=this.rows[i.rowIndex];if(!r)return;const n=this.grid.getRowId(r);if(!n)return;const s=this.#R.isRowDirty(n,r);this.emit("dirty-change",{rowId:n,row:r,original:this.#R.getOriginalRow(n),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(_)){if(this.#y)return e.blur(),void this.gridElement.focus();const t=i._focusRow,r=i._focusCol,n=this.#b;if(!n||n.rowIndex!==t||n.colIndex!==r){const e=i._visibleColumns?.[r],n=i._rows?.[t];if(e?.field&&n){const i=e.field;this.#b={rowIndex:t,colIndex:r,field:i,value:n[i]}}}this.#v=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(_)||(this.#v=!1,this.#b=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#v){if(x(this.config,t))return void queueMicrotask(()=>{if(this.#v){this.#x();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#v=!1,this.#y=!0}});this.#x();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#v=!1,this.#y=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(_)&&(this.#y=!1)},{signal:e}))}detach(){this.#o._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#d=-1,this.#a=void 0,this.#c=void 0,this.#u=-1,this.#h.clear(),this.#R.clear(),this.#f.clear(),this.#g.clear(),this.#v=!1,this.#y=!1,this.#b=null,this.#E=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#n||-1!==this.#d}onCellClick(t){if(this.#n)return!1;const e=this.#o,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const r="dblclick"===t.originalEvent.type;if("click"===i&&r)return!1;if("dblclick"===i&&!r)return!1;const{rowIndex:n}=t,s=e._columns?.some(t=>this.#l(t));if(!s)return!1;const o=e._rows[n],l=e.effectiveConfig?.rowEditable;return!(o&&l&&!l(o))&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(n),!0)}onKeyDown(t){const e=this.#o;if("Escape"===t.key){if(this.#n&&this.#v){this.#x();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#v=!1,this.#y=!0,this.requestAfterRender(),!0}if(-1!==this.#d&&!this.#n)return x(this.config,t)||this.#k(this.#d,!0),!0}if(this.#n&&!this.#v&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#n&&this.#v&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#d&&!this.#n){if(x(this.config,t))return!0;const i=e._rows.length-1,r=this.#d;return this.#k(r,!1),"ArrowDown"===t.key?e._focusRow=Math.min(i,e._focusRow+1):e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault(),f(e),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#d||this.#n)){if(t.preventDefault(),this.#E)return this.#k(this.#d,!1),!0;const e=!t.shiftKey;return this.#A(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#d)return!1;const i=e._focusRow,r=e._focusCol;if(i>=0&&r>=0){const n=e._visibleColumns[r],s=e._rows[i];if(n&&s&&this.#s(n,s)&&"boolean"===n.type){const e=n.field;if(k(e)){const r=!s[e];return this.#_(i,n,r,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#n&&!this.#v)return this.#S(),!0;if(-1!==this.#d)return!!x(this.config,t);const i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const r=e._focusRow,n=e._focusCol;if(r>=0){const i=e._columns?.some(t=>this.#l(t)),s=e._rows[r],o=e.effectiveConfig?.rowEditable,l=s&&o&&!o(s);if(i&&!l){const i=e._visibleColumns[n],s=e._rows[r],o=i?.field??"",l=o&&s?s[o]:void 0,d=this.gridElement.querySelector(`[data-row="${r}"][data-col="${n}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:r,colIndex:n,field:o,value:l,row:s,cellEl:d,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(a),a.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(r),!0)}}return!1}if("F2"===t.key){if(-1!==this.#d||this.#n)return!1;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,r=e._focusCol;if(i>=0&&r>=0){const n=e._visibleColumns[r],s=e._rows[i];if(n&&s&&this.#s(n,s)&&n.field)return t.preventDefault(),this.beginCellEdit(i,n.field),!0}return!1}return!1}processColumns(t){const e=this.#o,i=e.effectiveConfig?.typeDefaults,r=e.__frameworkAdapter;return i||r?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&r?.getTypeDefault){const i=r.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.#o;if(this.config.dirtyTracking&&e.getRowId&&this.#R.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#d||this.#n)return t;const i=this.#a,r=this.#c;if(!i||!r)return t;const n=[...t];let s=-1;for(let o=0;o<n.length;o++)try{if(e.getRowId?.(n[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),n):(n[s]=r,this.#d!==s&&this.#M(this.#d,s),n)}afterRender(){const t=this.#o;if(-1!==this.#d&&this.#c&&!this.#n&&t._rows[this.#d]!==this.#c){const e=t._rows.indexOf(this.#c);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#M(this.#d,e)}if(this.#w&&(this.#w=!1,this.#L(t)),-1!==this.#m){const e=this.#m;this.#m=-1,t.animateRow?.(e,"change")}const e=this.#R.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#n&&0!==this.#f.size)for(const i of this.#f){const[e,r]=i.split(":"),n=parseInt(e,10),s=parseInt(r,10),o=t.findRenderedRowElement?.(n);if(!o)continue;const l=o.querySelector(`.cell[data-col="${s}"]`);if(!l||l.classList.contains("editing"))continue;const d=t._rows[n],a=t._visibleColumns[s];d&&a&&this.#D(d,n,a,s,l,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:r,colIndex:n,cellElement:s}=t,o=this.#s(r,e);if(o)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#n&&s.classList.contains("editing")){s.classList.remove("editing");const t=e[r.field];s.textContent=null==t?"":String(t)}this.#n&&o&&(s.classList.contains("editing")||this.#D(e,i,r,n,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#o,i=e.getRowId?.(t.row);if(!i)return;const{isNew:r,isCommittedDirty:n,hasBaseline:s}=this.#R.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",r),s){const e=o.querySelectorAll(".cell[data-field]");for(let r=0;r<e.length;r++){const n=e[r],s=n.getAttribute("data-field");s&&n.classList.toggle("tbw-cell-dirty",this.#R.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.#R.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#R.getChangedRowIds()}get activeEditRow(){return this.#d}get activeEditCol(){return this.#u}isRowEditing(t){return this.#d===t}isCellEditing(t,e){return this.#f.has(`${t}:${e}`)}isRowChanged(t){const e=this.#o,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#R.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#R.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#R.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#R.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#o;return this.#R.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.#R.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#R.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.#R.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#R.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#o;this.#R.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#R.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#R.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#o;return this.#R.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#o;return this.#R.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#R.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#R.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#o;this.#R.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#p.setInvalid(t,e,i)}clearInvalid(t,e){this.#p.clearInvalid(t,e)}clearRowInvalid(t){this.#p.clearRowInvalid(t)}clearAllInvalid(){this.#p.clearAllInvalid()}isCellInvalid(t,e){return this.#p.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#p.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#p.hasInvalidCells(t)}getInvalidFields(t){return this.#p.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#R.changedRowIds.clear(),this.#R.committedDirtyRowIds.clear(),this.#G(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const r=this.#o;r._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#o,r=i._visibleColumns.findIndex(t=>t.field===e);if(-1===r)return;const n=i._visibleColumns[r],s=i._rows[t];if(!n||!s||!this.#s(n,s))return;const o=i.findRenderedRowElement?.(t),l=o?.querySelector(`.cell[data-col="${r}"]`);l&&(this.#E=!0,this.#T(t,r,l))}beginBulkEdit(t){const e=this.#o;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>this.#l(t));if(!i)return;const r=e.findRenderedRowElement?.(t);if(!r)return;const n=e._rows[t],s=e.effectiveConfig?.rowEditable;n&&s&&!s(n)||(this.#E=!1,this.#q(t,n),Array.from(r.children).forEach((i,r)=>{const s=e._visibleColumns[r];if(s&&this.#s(s,n)){const e=i;e.classList.contains("editing")||this.#D(n,t,s,r,e,!0)}}),setTimeout(()=>{let t=r.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=r.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(_);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#d&&this.#k(this.#d,!1)}cancelActiveRowEdit(){-1!==this.#d&&this.#k(this.#d,!0)}#I(t,e,i){const r=this.#o,n=r._visibleColumns?.findIndex(t=>t.field===e);if(-1===n||void 0===n)return;const s=r._rows,o=s?.findIndex(e=>{try{return r.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const l=r.findRenderedRowElement?.(o),d=l?.querySelector(`.cell[data-col="${n}"]`);if(d)if(i){d.setAttribute("data-invalid","true");const i=this.#p.getInvalidMessage(t,e);i&&d.setAttribute("title",i)}else d.removeAttribute("data-invalid"),d.removeAttribute("title")}#M(t,e){this.#d=e;const i=/* @__PURE__ */new Set,r=`${t}:`;for(const o of this.#f)o.startsWith(r)?i.add(`${e}:${o.substring(r.length)}`):i.add(o);this.#f.clear();for(const o of i)this.#f.add(o);const n=this.#h.get(t);void 0!==n&&(this.#h.delete(t),this.#h.set(e,n));const s=[];for(const[o,l]of this.#g)o.startsWith(r)&&(s.push([`${e}:${o.substring(r.length)}`,l]),this.#g.delete(o));for(const[o,l]of s)this.#g.set(o,l);this.#G()}#T(t,e,i){const r=this.#o,n=r._rows[t],s=r._visibleColumns[e];n&&s&&this.#s(s,n)&&(i.classList.contains("editing")||(this.#d!==t&&this.#q(t,n),this.#u=e,this.#D(n,t,s,e,i,!1)))}#x(){const t=this.#b;if(!t)return;const e=this.#o,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const r=`${t.rowIndex}:${t.field}`,n=this.#g.get(r);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),i){let t;try{t=this.grid.getRowId(i)}catch{}t&&(this.config.dirtyTracking?this.#R.isRowDirty(t,i)||(this.#R.changedRowIds.delete(t),this.emit("dirty-change",{rowId:t,row:i,original:this.#R.getOriginalRow(t),type:"reverted"})):this.#R.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#S(){const t=this.#o,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const r=t.findRenderedRowElement?.(e),n=r?.querySelector(`.cell[data-col="${i}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(_);t&&(this.#y=!1,t.focus(),this.#v=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#A(t){const e=this.#o,i=e._rows,r=this.#n?e._focusRow:this.#d,n=i[r],s=e._visibleColumns.map((t,e)=>n&&this.#s(t,n)?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(e._focusCol)+(t?1:-1);if(o>=0&&o<s.length){e._focusCol=s[o];const t=e.findRenderedRowElement?.(r),i=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(i?.classList.contains("editing")){const t=i.querySelector(_);t?.focus({preventScroll:!0})}return void f(e,{forceHorizontalScroll:!0})}const l=r+(t?1:-1);if(l>=0&&l<i.length){const n=i[l],s=e._visibleColumns.map((t,e)=>n&&this.#s(t,n)?e:-1).filter(t=>t>=0);if(0===s.length)return;this.#n?(e._focusRow=l,e._focusCol=t?s[0]:s[s.length-1],f(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=e.findRenderedRowElement?.(l),i=t?.querySelector(`.cell[data-col="${e._focusCol}"]`);if(i?.classList.contains("editing")){const t=i.querySelector(_);t?.focus({preventScroll:!0})}},0)):(this.#k(r,!1),e._focusRow=l,e._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(l),f(e,{forceHorizontalScroll:!0}))}}#G(){const t=this.#o;t._activeEditRows=this.#d,t._rowEditSnapshots=this.#h}#q(t,e){if(this.#d!==t){-1!==this.#d&&this.#k(this.#d,!1),this.#h.set(t,{...e}),this.#d=t,this.#c=e;const i=this.#o;try{this.#a=i.getRowId?.(e)??void 0}catch{this.#a=void 0}this.#G(),this.#n||(this.emit("edit-open",{rowIndex:t,rowId:this.#a??"",row:e}),r(this.gridElement,n(this.gridElement,"editingStarted",t)))}}#k(t,e){if(this.#d!==t)return;const i=this.#o,s=this.#h.get(t),o=i.findRenderedRowElement?.(t);let l=this.#a;const d=l?i._getRowEntry(l):void 0,a=d?.row??this.#c??i._rows[t];if(!l&&a)try{l=i.getRowId?.(a)}catch{}if(!e&&o&&a){o.querySelectorAll(".cell.editing").forEach(e=>{const r=Number(e.getAttribute("data-col"));if(isNaN(r))return;const n=i._visibleColumns[r];if(!n)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=n.field,i=a[e],r=v(s,n,i);i!==r&&this.#_(t,n,r,a)}})}if(e||this.#n||!a||this.emit("before-edit-close",{rowIndex:t,rowId:l??"",row:a}),e&&s&&a)Object.keys(s).forEach(t=>{a[t]=s[t]}),l&&(this.#R.changedRowIds.delete(l),this.#R.committedDirtyRowIds.delete(l),this.clearRowInvalid(l));else if(!e&&a){const e=function(t,e){if(!t)return!1;const i=t,r=e,n=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(r)]);for(const s of n)if(i[s]!==r[s])return!0;return!1}(s,a),i=l?this.#R.changedRowIds.has(l):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:l??"",row:a,oldValue:s,newValue:a,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&s?(Object.keys(s).forEach(t=>{a[t]=s[t]}),l&&(this.#R.changedRowIds.delete(l),this.#R.committedDirtyRowIds.delete(l),this.clearRowInvalid(l))):r||(l&&this.config.dirtyTracking&&(this.#R.isRowDirty(l,a)?this.#R.committedDirtyRowIds.add(l):this.#R.committedDirtyRowIds.delete(l)),e&&this.isAnimationEnabled&&(this.#m=t))}this.#h.delete(t),this.#d=-1,this.#a=void 0,this.#c=void 0,this.#u=-1,this.#E=!1,this.#G();for(const r of this.#f)r.startsWith(`${t}:`)&&this.#f.delete(r);for(const r of this.#g.keys())r.startsWith(`${t}:`)&&this.#g.delete(r);if(this.#w=!0,o){const t=i.__frameworkAdapter,e=o.querySelectorAll(".cell.editing");t?.releaseCell&&e.forEach(e=>{t.releaseCell(e)}),e.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)}else this.#L(i),this.#w=!1;!this.#n&&a&&(this.emit("edit-close",{rowIndex:t,rowId:l??"",row:a,reverted:e}),e||r(this.gridElement,n(this.gridElement,"editingCommitted",t)))}#_(t,e,i,r){const n=e.field;if(!k(n))return;const s=r[n];if(s===i)return;const o=this.#o;let l;try{l=this.grid.getRowId(r)}catch{}const d=!l||!this.#R.changedRowIds.has(l),a=l?t=>this.grid.updateRow(l,t,"cascade"):S;let c=!1;const u=l?t=>{c=!0,this.setInvalid(l,n,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:r,rowId:l??"",field:n,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:d,updateRow:a,setInvalid:u}))return;if(l&&!c&&this.isCellInvalid(l,n)&&this.clearInvalid(l,n),r[n]=i,l&&this.#R.changedRowIds.add(l),this.#G(),this.config.dirtyTracking&&l){const t=this.#R.isRowDirty(l,r);this.emit("dirty-change",{rowId:l,row:r,original:this.#R.getOriginalRow(l),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:n,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#D(t,e,i,r,n,s,o){A(this.#C,t,e,i,r,n,s,o)}#L(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,r=t.findRenderedRowElement?.(e);if(r){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const n=r.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);n&&(n.classList.add("cell-focus"),n.setAttribute("aria-selected","true"),n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}}catch{}})}}export{M as EditingPlugin,p as defaultEditorFor};
|
|
1
|
+
const t={sortApplied:(t,e)=>`Sorted by ${t}, ${e}`,sortCleared:()=>"Sort cleared",filterApplied:t=>`Filter applied on ${t}`,filterCleared:t=>`Filter cleared from ${t}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(t,e)=>`Group ${t} expanded, ${e} rows`,groupCollapsed:t=>`Group ${t} collapsed`,selectionChanged:t=>`${t} rows selected`,editingStarted:t=>`Editing row ${t+1}`,editingCommitted:t=>`Row ${t+1} saved`,dataLoaded:t=>`${t} rows loaded`},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:"🖨️"};function r(t,e){if(!t)return;const i="effectiveConfig"in t?t.effectiveConfig:void 0;if(!1===i?.a11y?.announcements)return;const r=t.querySelector?.(".tbw-sr-only");r&&(r.textContent="",requestAnimationFrame(()=>{r.textContent=e}))}function n(e,i,...r){const n=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,s=n?.a11y?.messages?.[i];return s?s(...r):t[i](...r)}const s="editing";function o(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function l(t,e,i,r){return`${o(i,r)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}["__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"].map(t=>t.split("").reverse().join(""));const d=/* @__PURE__ */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"]),a=/^on\w+$/i,c=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),u=/^\s*(javascript|vbscript|data|blob):/i;function h(t){if(!t||"string"!=typeof t)return"";if(-1===t.indexOf("<"))return t;const e=document.createElement("template");return e.innerHTML=t,function(t){const e=[],i=t.querySelectorAll("*");for(const r of i){const t=r.tagName.toLowerCase();if(d.has(t)){e.push(r);continue}if("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI){if(Array.from(r.attributes).some(t=>a.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}}const i=[];for(const e of r.attributes){const t=e.name.toLowerCase();a.test(t)?i.push(e.name):(c.has(t)&&u.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name)}i.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function f(t,e){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:r}=t._virtualization,n=i,s=r?.clientHeight??n?.clientHeight??0;if(n&&s>0){const i=t._focusRow*e;i<n.scrollTop?n.scrollTop=i:i+e>n.scrollTop+s&&(n.scrollTop=i-s+e)}}const i=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var r;i||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 n=t._focusRow,o=t._virtualization.start??0,l=t._virtualization.end??t._rows.length;if(n>=o&&n<l){const r=t._bodyEl.querySelectorAll(".data-grid-row")[n-o];let l=r?.children[t._focusCol];if(l&&l.classList?.contains("cell")||(l=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const n=t.querySelector(".tbw-scroll-area");if(n&&l&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)n.scrollLeft=0;else if(e?.forceScrollRight)n.scrollLeft=n.scrollWidth-n.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(r??void 0,l)??{left:0,right:0};if(!e.skipScroll){const t=l.getBoundingClientRect(),i=n.getBoundingClientRect(),r=t.left-i.left+n.scrollLeft,s=r+t.width,o=n.scrollLeft+e.left,d=n.scrollLeft+n.clientWidth-e.right;r<o?n.scrollLeft=r-e.left:s>d&&(n.scrollLeft=s-n.clientWidth+e.right)}}if(i&&l.classList.contains(s)){const t=l.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&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else i||document.activeElement!==t&&t.focus({preventScroll:!0})}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';class g{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)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}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?._hostElement}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}setIcon(t,e,i){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,i);void 0!==r?"string"==typeof r?t.innerHTML=h(r):r instanceof HTMLElement&&(t.innerHTML="",t.appendChild(r.cloneNode(!0))):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const i=document.createElement("span");i.setAttribute("part","sort-indicator"),i.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(i,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(i,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(i,r):t.appendChild(i),i}warn(t,e){void 0!==e?console.warn(l(t,e,this.gridElement.id,this.name)):console.warn(`${o(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(l(t,e,this.gridElement.id,this.name))}}function w(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="date",e.value instanceof Date?r.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(r.value=e.value.split("T")[0]),i?.min&&(r.min=i.min),i?.max&&(r.max=i.max),i?.placeholder&&(r.placeholder=i.placeholder);return r.addEventListener("change",()=>{var n;if(r.value)"string"==typeof e.value?e.commit(r.value):e.commit(r.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:`${(n=t??/* @__PURE__ */new Date).getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),r.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),r}}const m="__tbw_null__";function p(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="number",r.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(r.min=String(i.min)),void 0!==i?.max&&(r.max=String(i.max)),void 0!==i?.step&&(r.step=String(i.step)),i?.placeholder&&(r.placeholder=i.placeholder);const n=()=>{""===r.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(r.value))};return r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Enter"===t.key&&n(),"Escape"===t.key&&e.cancel()}),r}}(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 w(t);case"select":return function(t){return e=>{const i=t.editorParams,r=document.createElement("select");if(t.multi&&(r.multiple=!0),t.nullable||i?.includeEmpty){const n=document.createElement("option");n.value=t.nullable?m:"",n.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(n.selected=!0),r.appendChild(n)}const n=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);n.forEach(i=>{const n=document.createElement("option");n.value=String(i.value),n.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?n.selected=!0:t.multi||e.value!==i.value||(n.selected=!0),r.appendChild(n)});const s=()=>{if(t.multi){const t=Array.from(r.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&r.value===m?e.commit(null):e.commit(r.value)};return r.addEventListener("change",s),r.addEventListener("blur",s),r.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),r}}(t);default:return function(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="text",r.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(r.maxLength=i.maxLength),i?.pattern&&(r.pattern=i.pattern),i?.placeholder&&(r.placeholder=i.placeholder);const n=()=>{const i=r.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 r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Enter"===t.key&&n(),"Escape"===t.key&&e.cancel()}),r}}(t)}}function v(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 y{#i=/* @__PURE__ */new Map;#r;constructor(t){this.#r=t}setInvalid(t,e,i=""){let r=this.#i.get(t);r||(r=/* @__PURE__ */new Map,this.#i.set(t,r)),r.set(e,i),this.#r(t,e,!0)}clearInvalid(t,e){const i=this.#i.get(t);i&&(i.delete(e),0===i.size&&this.#i.delete(t)),this.#r(t,e,!1)}clearRowInvalid(t){const e=this.#i.get(t);if(e){const i=Array.from(e.keys());this.#i.delete(t),i.forEach(e=>this.#r(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#i.entries());this.#i.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#r(t,i,!1))})}isCellInvalid(t,e){return this.#i.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#i.get(t)?.get(e)}hasInvalidCells(t){const e=this.#i.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#i.get(t)??[])}}function E(t,e,i){const r=t.get(e);return!!r&&!b(r,i)}function b(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(!b(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,r=e,n=Object.keys(i),s=Object.keys(r);if(n.length!==s.length)return!1;for(const t of n)if(!b(i[t],r[t]))return!1;return!0}return!1}function R(t,e,i){t.set(e,structuredClone(i))}function C(t,e,i){const r=t.get(e);if(!r)return!1;const n=r,s=i;for(const o of Object.keys(n))s[o]=n[o];return!0}class I{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 r of e)try{const e=i(r);null==e||t.has(e)||t.set(e,structuredClone(r))}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 E(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&&E(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,r){const n=t.get(e);return!!n&&!b(n[r],i[r])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&E(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){R(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&&R(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,r]of this.baselines){const n=t(i);n&&E(this.baselines,i,n)&&e.push({id:i,original:structuredClone(r),current:n})}for(const i of this.newRowIds){const r=t(i);r&&e.push({id:i,original:void 0,current:r})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const r=t(i);r&&E(this.baselines,i,r)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=C(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&&C(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const r=t(i);r&&e.push(r)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const _='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function k(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function S(t){}function x(t,e){return!1===t.onBeforeEditClose?.(e)}function A(t,e,i,r,n,s,o,d){if(!r.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:f}=t;let g;try{g=a.getRowId?.(e)}catch{}const w=g?t=>a.updateRow(g,t,"cascade"):S,m=k(r.field)?e[r.field]:void 0;s.classList.add("editing"),h.add(`${i}:${n}`);const y=d??s.parentElement;y&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(y);let E=!1;const b=n=>{if(E||!c&&!t.isEditSessionActive())return;const s=g?a._getRowEntry(g):void 0,o=s?.row??e,l=s?.index??i;t.commitCellValue(l,r,n,o)},R=()=>{if(E=!0,k(r.field)){const t=g?a._getRowEntry(g):void 0;(t?.row??e)[r.field]=m}},C=document.createElement("div");C.className="tbw-editor-host",s.innerHTML="",s.appendChild(C),C.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=C.querySelector("input,textarea,select");return void(t&&b(v(t,r,m)))}if(x(u,e))return;e.stopPropagation(),e.preventDefault(),E=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(x(u,e))return;e.stopPropagation(),e.preventDefault(),R(),t.exitRowEdit(i,!0)}});const I=r,A=I.__editorTemplate,M=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const r=t.__frameworkAdapter;if(r?.getTypeDefault){const i=r.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(a,I)??p(r),L=m,D=`${i}:${r.field}`,G=[];f.set(D,t=>{for(const e of G)e(t)});const T=t=>{G.push(t)};if("template"===M&&A)!function(t,e,i,r,n,s,o,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:r,value:n,field:i.field,column:i,commit:s,cancel:o}):c.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!k(e))return"";const i=r[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!n:h.value=String(n??"");let e=!1;h.addEventListener("blur",()=>{e||s(v(h,i,n))}),h.addEventListener("keydown",r=>{const l=r;if("Enter"===l.key){if(x(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(v(h,i,n)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(x(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(d,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>s(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(t,C,I,e,m,b,R,o,i),T(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 M){const t=document.createElement(M);t.value=L,t.addEventListener("change",()=>b(t.value)),T(e=>{t.value=e}),C.appendChild(t),o||queueMicrotask(()=>{const t=C.querySelector(_);t?.focus({preventScroll:!0})})}else if("function"==typeof M){const t=M({row:e,rowId:g??"",value:L,field:r.field,column:r,commit:b,cancel:R,updateRow:w,onValueChange:T});if("string"==typeof t)C.innerHTML=t,function(t,e,i,r){const n=t.querySelector("input,textarea,select");n&&(n.addEventListener("blur",()=>{i(v(n,e,r))}),n instanceof HTMLInputElement&&"checkbox"===n.type?n.addEventListener("change",()=>i(n.checked)):n instanceof HTMLSelectElement&&n.addEventListener("change",()=>i(v(n,e,r))))}(C,r,b,m),T(t=>{const e=C.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){C.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?T(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):s.setAttribute("data-editor-managed","")}else!t&&C.hasChildNodes()&&s.setAttribute("data-editor-managed","");o||queueMicrotask(()=>{const t=C.querySelector(_);t?.focus({preventScroll:!0})})}else if(M&&"object"==typeof M){const i=document.createElement("div");i.setAttribute("data-external-editor",""),i.setAttribute("data-field",r.field),C.appendChild(i),s.setAttribute("data-editor-managed","");const n={row:e,rowId:g??"",value:L,field:r.field,column:r,commit:b,cancel:R,updateRow:w,onValueChange:T};if(M.mount)try{M.mount({placeholder:i,context:n,spec:M})}catch(O){q="TBW080",$=`External editor mount error for column '${r.field}': ${O}`,P=t.grid.id,console.warn(l(q,$,P,F))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:i,spec:M,context:n}}))}var q,$,P,F}class M extends g{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};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:max(var(--tbw-row-height),calc(1lh + 2 * var(--tbw-cell-padding-v, .25em) + var(--tbw-border-width, 1px)));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;align-self:stretch;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}#s(t,e){const i=this.#o.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:r}=t;return"function"==typeof r?r(e):!0===r}#l(t){return!0===t.editable||"function"==typeof t.editable}#d=-1;#a;#c;#u=-1;#h=/* @__PURE__ */new Map;#f=/* @__PURE__ */new Set;#g=/* @__PURE__ */new Map;#w=!1;#m=-1;#p;#v=!1;#y=!1;#E=!1;#b=null;#R=new I;#C;get#o(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#o;if(this.#p=new y((t,e,i)=>{this.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#n,config:this.config,editingCells:this.#f,editorValueCallbacks:this.#g,isEditSessionActive:()=>-1!==this.#d,commitCellValue:(t,e,i,r)=>this.#_(t,e,i,r),exitRowEdit:(t,e)=>this.#k(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}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#R.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#d){if(x(this.config,t))return;this.#k(this.#d,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#n)return;if(-1===this.#d)return;const e=i.findRenderedRowElement?.(this.#d);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const r=t.target;r&&!this.gridElement.contains(r)&&this.grid.containsFocus?.(r)||x(this.config,t)||queueMicrotask(()=>{-1!==this.#d&&this.#k(this.#d,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#n)return;if(-1===this.#d)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#d&&this.#S()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,r=this.#g.get(i);r&&r(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const r=this.rows[i.rowIndex];if(!r)return;const n=this.grid.getRowId(r);if(!n)return;const s=this.#R.isRowDirty(n,r);this.emit("dirty-change",{rowId:n,row:r,original:this.#R.getOriginalRow(n),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(_)){if(this.#y)return e.blur(),void this.gridElement.focus();const t=i._focusRow,r=i._focusCol,n=this.#b;if(!n||n.rowIndex!==t||n.colIndex!==r){const e=i._visibleColumns?.[r],n=i._rows?.[t];if(e?.field&&n){const i=e.field;this.#b={rowIndex:t,colIndex:r,field:i,value:n[i]}}}this.#v=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(_)||(this.#v=!1,this.#b=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#v){if(x(this.config,t))return void queueMicrotask(()=>{if(this.#v){this.#x();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#v=!1,this.#y=!0}});this.#x();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#v=!1,this.#y=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(_)&&(this.#y=!1)},{signal:e}))}detach(){this.#o._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#d=-1,this.#a=void 0,this.#c=void 0,this.#u=-1,this.#h.clear(),this.#R.clear(),this.#f.clear(),this.#g.clear(),this.#v=!1,this.#y=!1,this.#b=null,this.#E=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#n||-1!==this.#d}onCellClick(t){if(this.#n)return!1;const e=this.#o,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const r="dblclick"===t.originalEvent.type;if("click"===i&&r)return!1;if("dblclick"===i&&!r)return!1;const{rowIndex:n}=t,s=e._columns?.some(t=>this.#l(t));if(!s)return!1;const o=e._rows[n],l=e.effectiveConfig?.rowEditable;return!(o&&l&&!l(o))&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(n),!0)}onKeyDown(t){const e=this.#o;if("Escape"===t.key){if(this.#n&&this.#v){this.#x();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#v=!1,this.#y=!0,this.requestAfterRender(),!0}if(-1!==this.#d&&!this.#n)return x(this.config,t)||this.#k(this.#d,!0),!0}if(this.#n&&!this.#v&&("ArrowUp"===t.key||"ArrowDown"===t.key||"ArrowLeft"===t.key||"ArrowRight"===t.key))return!1;if(this.#n&&this.#v&&("ArrowUp"===t.key||"ArrowDown"===t.key))return!0;if(("ArrowUp"===t.key||"ArrowDown"===t.key)&&-1!==this.#d&&!this.#n){if(x(this.config,t))return!0;const i=e._rows.length-1,r=this.#d;return this.#k(r,!1),"ArrowDown"===t.key?e._focusRow=Math.min(i,e._focusRow+1):e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault(),f(e),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#d||this.#n)){if(t.preventDefault(),this.#E)return this.#k(this.#d,!1),!0;const e=!t.shiftKey;return this.#A(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#d)return!1;const i=e._focusRow,r=e._focusCol;if(i>=0&&r>=0){const n=e._visibleColumns[r],s=e._rows[i];if(n&&s&&this.#s(n,s)&&"boolean"===n.type){const e=n.field;if(k(e)){const r=!s[e];return this.#_(i,n,r,s),t.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==t.key||t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)){if(this.#n&&!this.#v)return this.#S(),!0;if(-1!==this.#d)return!!x(this.config,t);const i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const r=e._focusRow,n=e._focusCol;if(r>=0){const i=e._columns?.some(t=>this.#l(t)),s=e._rows[r],o=e.effectiveConfig?.rowEditable,l=s&&o&&!o(s);if(i&&!l){const i=e._visibleColumns[n],s=e._rows[r],o=i?.field??"",l=o&&s?s[o]:void 0,d=this.gridElement.querySelector(`[data-row="${r}"][data-col="${n}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:r,colIndex:n,field:o,value:l,row:s,cellEl:d,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(a),a.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(r),!0)}}return!1}if("F2"===t.key){if(-1!==this.#d||this.#n)return!1;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,r=e._focusCol;if(i>=0&&r>=0){const n=e._visibleColumns[r],s=e._rows[i];if(n&&s&&this.#s(n,s)&&n.field)return t.preventDefault(),this.beginCellEdit(i,n.field),!0}return!1}return!1}processColumns(t){const e=this.#o,i=e.effectiveConfig?.typeDefaults,r=e.__frameworkAdapter;return i||r?.getTypeDefault?t.map(t=>{if(!t.type)return t;let n;if(i?.[t.type]?.editorParams&&(n=i[t.type].editorParams),!n&&r?.getTypeDefault){const i=r.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(n=i.editorParams)}return n?{...t,editorParams:{...n,...t.editorParams}}:t}):t}processRows(t){const e=this.#o;if(this.config.dirtyTracking&&e.getRowId&&this.#R.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#d||this.#n)return t;const i=this.#a,r=this.#c;if(!i||!r)return t;const n=[...t];let s=-1;for(let o=0;o<n.length;o++)try{if(e.getRowId?.(n[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),n):(n[s]=r,this.#d!==s&&this.#M(this.#d,s),n)}afterRender(){const t=this.#o;if(-1!==this.#d&&this.#c&&!this.#n&&t._rows[this.#d]!==this.#c){const e=t._rows.indexOf(this.#c);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#M(this.#d,e)}if(this.#w&&(this.#w=!1,this.#L(t)),-1!==this.#m){const e=this.#m;this.#m=-1,t.animateRow?.(e,"change")}const e=this.#R.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#n&&0!==this.#f.size)for(const i of this.#f){const[e,r]=i.split(":"),n=parseInt(e,10),s=parseInt(r,10),o=t.findRenderedRowElement?.(n);if(!o)continue;const l=o.querySelector(`.cell[data-col="${s}"]`);if(!l||l.classList.contains("editing"))continue;const d=t._rows[n],a=t._visibleColumns[s];d&&a&&this.#D(d,n,a,s,l,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:r,colIndex:n,cellElement:s}=t,o=this.#s(r,e);if(o)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#n&&s.classList.contains("editing")){s.classList.remove("editing");const t=e[r.field];s.textContent=null==t?"":String(t)}this.#n&&o&&(s.classList.contains("editing")||this.#D(e,i,r,n,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#o,i=e.getRowId?.(t.row);if(!i)return;const{isNew:r,isCommittedDirty:n,hasBaseline:s}=this.#R.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",r),s){const e=o.querySelectorAll(".cell[data-field]");for(let r=0;r<e.length;r++){const n=e[r],s=n.getAttribute("data-field");s&&n.classList.toggle("tbw-cell-dirty",this.#R.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.#R.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#R.getChangedRowIds()}get activeEditRow(){return this.#d}get activeEditCol(){return this.#u}isRowEditing(t){return this.#d===t}isCellEditing(t,e){return this.#f.has(`${t}:${e}`)}isRowChanged(t){const e=this.#o,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#R.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#R.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#R.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#R.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#o;return this.#R.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.#R.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#R.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.#R.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#R.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#o;this.#R.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#R.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#R.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#o;return this.#R.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#o;return this.#R.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#R.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#R.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#o;this.#R.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#p.setInvalid(t,e,i)}clearInvalid(t,e){this.#p.clearInvalid(t,e)}clearRowInvalid(t){this.#p.clearRowInvalid(t)}clearAllInvalid(){this.#p.clearAllInvalid()}isCellInvalid(t,e){return this.#p.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#p.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#p.hasInvalidCells(t)}getInvalidFields(t){return this.#p.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#R.changedRowIds.clear(),this.#R.committedDirtyRowIds.clear(),this.#G(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const r=this.#o;r._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#o,r=i._visibleColumns.findIndex(t=>t.field===e);if(-1===r)return;const n=i._visibleColumns[r],s=i._rows[t];if(!n||!s||!this.#s(n,s))return;const o=i.findRenderedRowElement?.(t),l=o?.querySelector(`.cell[data-col="${r}"]`);l&&(this.#E=!0,this.#T(t,r,l))}beginBulkEdit(t){const e=this.#o;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>this.#l(t));if(!i)return;const r=e.findRenderedRowElement?.(t);if(!r)return;const n=e._rows[t],s=e.effectiveConfig?.rowEditable;n&&s&&!s(n)||(this.#E=!1,this.#q(t,n),Array.from(r.children).forEach((i,r)=>{const s=e._visibleColumns[r];if(s&&this.#s(s,n)){const e=i;e.classList.contains("editing")||this.#D(n,t,s,r,e,!0)}}),setTimeout(()=>{let t=r.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=r.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(_);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#d&&this.#k(this.#d,!1)}cancelActiveRowEdit(){-1!==this.#d&&this.#k(this.#d,!0)}#I(t,e,i){const r=this.#o,n=r._visibleColumns?.findIndex(t=>t.field===e);if(-1===n||void 0===n)return;const s=r._rows,o=s?.findIndex(e=>{try{return r.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const l=r.findRenderedRowElement?.(o),d=l?.querySelector(`.cell[data-col="${n}"]`);if(d)if(i){d.setAttribute("data-invalid","true");const i=this.#p.getInvalidMessage(t,e);i&&d.setAttribute("title",i)}else d.removeAttribute("data-invalid"),d.removeAttribute("title")}#M(t,e){this.#d=e;const i=/* @__PURE__ */new Set,r=`${t}:`;for(const o of this.#f)o.startsWith(r)?i.add(`${e}:${o.substring(r.length)}`):i.add(o);this.#f.clear();for(const o of i)this.#f.add(o);const n=this.#h.get(t);void 0!==n&&(this.#h.delete(t),this.#h.set(e,n));const s=[];for(const[o,l]of this.#g)o.startsWith(r)&&(s.push([`${e}:${o.substring(r.length)}`,l]),this.#g.delete(o));for(const[o,l]of s)this.#g.set(o,l);this.#G()}#T(t,e,i){const r=this.#o,n=r._rows[t],s=r._visibleColumns[e];n&&s&&this.#s(s,n)&&(i.classList.contains("editing")||(this.#d!==t&&this.#q(t,n),this.#u=e,this.#D(n,t,s,e,i,!1)))}#x(){const t=this.#b;if(!t)return;const e=this.#o,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const r=`${t.rowIndex}:${t.field}`,n=this.#g.get(r);if(n&&n(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),i){let t;try{t=this.grid.getRowId(i)}catch{}t&&(this.config.dirtyTracking?this.#R.isRowDirty(t,i)||(this.#R.changedRowIds.delete(t),this.emit("dirty-change",{rowId:t,row:i,original:this.#R.getOriginalRow(t),type:"reverted"})):this.#R.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#S(){const t=this.#o,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const r=t.findRenderedRowElement?.(e),n=r?.querySelector(`.cell[data-col="${i}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(_);t&&(this.#y=!1,t.focus(),this.#v=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#A(t){const e=this.#o,i=e._rows,r=this.#n?e._focusRow:this.#d,n=i[r],s=e._visibleColumns.map((t,e)=>n&&this.#s(t,n)?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(e._focusCol)+(t?1:-1);if(o>=0&&o<s.length){e._focusCol=s[o];const t=e.findRenderedRowElement?.(r),i=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(i?.classList.contains("editing")){const t=i.querySelector(_);t?.focus({preventScroll:!0})}return void f(e,{forceHorizontalScroll:!0})}const l=r+(t?1:-1);if(l>=0&&l<i.length){const n=i[l],s=e._visibleColumns.map((t,e)=>n&&this.#s(t,n)?e:-1).filter(t=>t>=0);if(0===s.length)return;this.#n?(e._focusRow=l,e._focusCol=t?s[0]:s[s.length-1],f(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=e.findRenderedRowElement?.(l),i=t?.querySelector(`.cell[data-col="${e._focusCol}"]`);if(i?.classList.contains("editing")){const t=i.querySelector(_);t?.focus({preventScroll:!0})}},0)):(this.#k(r,!1),e._focusRow=l,e._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(l),f(e,{forceHorizontalScroll:!0}))}}#G(){const t=this.#o;t._activeEditRows=this.#d,t._rowEditSnapshots=this.#h}#q(t,e){if(this.#d!==t){-1!==this.#d&&this.#k(this.#d,!1),this.#h.set(t,{...e}),this.#d=t,this.#c=e;const i=this.#o;try{this.#a=i.getRowId?.(e)??void 0}catch{this.#a=void 0}this.#G(),this.#n||(this.emit("edit-open",{rowIndex:t,rowId:this.#a??"",row:e}),r(this.gridElement,n(this.gridElement,"editingStarted",t)))}}#k(t,e){if(this.#d!==t)return;const i=this.#o,s=this.#h.get(t),o=i.findRenderedRowElement?.(t);let l=this.#a;const d=l?i._getRowEntry(l):void 0,a=d?.row??this.#c??i._rows[t];if(!l&&a)try{l=i.getRowId?.(a)}catch{}if(!e&&o&&a){o.querySelectorAll(".cell.editing").forEach(e=>{const r=Number(e.getAttribute("data-col"));if(isNaN(r))return;const n=i._visibleColumns[r];if(!n)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=n.field,i=a[e],r=v(s,n,i);i!==r&&this.#_(t,n,r,a)}})}if(e||this.#n||!a||this.emit("before-edit-close",{rowIndex:t,rowId:l??"",row:a}),e&&s&&a)Object.keys(s).forEach(t=>{a[t]=s[t]}),l&&(this.#R.changedRowIds.delete(l),this.#R.committedDirtyRowIds.delete(l),this.clearRowInvalid(l));else if(!e&&a){const e=function(t,e){if(!t)return!1;const i=t,r=e,n=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(r)]);for(const s of n)if(i[s]!==r[s])return!0;return!1}(s,a),i=l?this.#R.changedRowIds.has(l):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:l??"",row:a,oldValue:s,newValue:a,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&s?(Object.keys(s).forEach(t=>{a[t]=s[t]}),l&&(this.#R.changedRowIds.delete(l),this.#R.committedDirtyRowIds.delete(l),this.clearRowInvalid(l))):r||(l&&this.config.dirtyTracking&&(this.#R.isRowDirty(l,a)?this.#R.committedDirtyRowIds.add(l):this.#R.committedDirtyRowIds.delete(l)),e&&this.isAnimationEnabled&&(this.#m=t))}this.#h.delete(t),this.#d=-1,this.#a=void 0,this.#c=void 0,this.#u=-1,this.#E=!1,this.#G();for(const r of this.#f)r.startsWith(`${t}:`)&&this.#f.delete(r);for(const r of this.#g.keys())r.startsWith(`${t}:`)&&this.#g.delete(r);if(this.#w=!0,o){const t=i.__frameworkAdapter,e=o.querySelectorAll(".cell.editing");t?.releaseCell&&e.forEach(e=>{t.releaseCell(e)}),e.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)}else this.#L(i),this.#w=!1;!this.#n&&a&&(this.emit("edit-close",{rowIndex:t,rowId:l??"",row:a,reverted:e}),e||r(this.gridElement,n(this.gridElement,"editingCommitted",t)))}#_(t,e,i,r){const n=e.field;if(!k(n))return;const s=r[n];if(s===i)return;const o=this.#o;let l;try{l=this.grid.getRowId(r)}catch{}const d=!l||!this.#R.changedRowIds.has(l),a=l?t=>this.grid.updateRow(l,t,"cascade"):S;let c=!1;const u=l?t=>{c=!0,this.setInvalid(l,n,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:r,rowId:l??"",field:n,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:d,updateRow:a,setInvalid:u}))return;if(l&&!c&&this.isCellInvalid(l,n)&&this.clearInvalid(l,n),r[n]=i,l&&this.#R.changedRowIds.add(l),this.#G(),this.config.dirtyTracking&&l){const t=this.#R.isRowDirty(l,r);this.emit("dirty-change",{rowId:l,row:r,original:this.#R.getOriginalRow(l),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:n,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#D(t,e,i,r,n,s,o){A(this.#C,t,e,i,r,n,s,o)}#L(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,r=t.findRenderedRowElement?.(e);if(r){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const n=r.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);n&&(n.classList.add("cell-focus"),n.setAttribute("aria-selected","true"),n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}}catch{}})}}export{M as EditingPlugin,p as defaultEditorFor};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|