@toolbox-web/grid 1.30.2 → 1.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/internal/dom-builder.d.ts +3 -3
- package/lib/core/plugin/base-plugin.d.ts +31 -8
- package/lib/core/plugin/plugin-manager.d.ts +2 -2
- package/lib/core/types.d.ts +16 -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/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/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/MultiSortPlugin.d.ts +8 -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 +43 -1
- package/lib/plugins/pivot/index.d.ts +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-engine.d.ts +21 -2
- package/lib/plugins/pivot/pivot-model.d.ts +6 -3
- package/lib/plugins/pivot/pivot-panel.d.ts +8 -3
- package/lib/plugins/pivot/pivot-rows.d.ts +3 -3
- package/lib/plugins/pivot/types.d.ts +121 -8
- 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/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/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/themes/dg-theme-bootstrap.css +8 -1
- package/themes/dg-theme-large.css +3 -1
- package/themes/dg-theme-material.css +3 -1
- package/themes/dg-theme-standard.css +5 -0
- package/themes/dg-theme-vibrant.css +5 -0
- 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/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/filtering.umd.js +1 -1
- package/umd/plugins/filtering.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/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.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/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/print.umd.js +1 -1
- package/umd/plugins/print.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/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t="editing";function e(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,i,n,r){return`${e(n,r)} ${t}: ${i}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}const n=/* @__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"]),r=/^on\w+$/i,s=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),o=/^\s*(javascript|vbscript|data|blob):/i;function l(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 l of i){const t=l.tagName.toLowerCase();if(n.has(t)){e.push(l);continue}if("svg"===t||"http://www.w3.org/2000/svg"===l.namespaceURI){if(Array.from(l.attributes).some(t=>r.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(l);continue}}const i=[];for(const e of l.attributes){const t=e.name.toLowerCase();r.test(t)?i.push(e.name):(s.has(t)&&o.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name)}i.forEach(t=>l.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function d(e,i){if(e._virtualization?.enabled){const{rowHeight:t,container:i,viewportEl:n}=e._virtualization,r=i,s=n?.clientHeight??r?.clientHeight??0;if(r&&s>0){const i=e._focusRow*t;i<r.scrollTop?r.scrollTop=i:i+t>r.scrollTop+s&&(r.scrollTop=i-s+t)}}const n=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;var r;n||e.refreshVirtualWindow(!1),(r=e._bodyEl)&&r.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=e._focusRow,o=e._virtualization.start??0,l=e._virtualization.end??e._rows.length;if(s>=o&&s<l){const r=e._bodyEl.querySelectorAll(".data-grid-row")[s-o];let l=r?.children[e._focusCol];if(l&&l.classList?.contains("cell")||(l=r?.querySelector(`.cell[data-col="${e._focusCol}"]`)??r?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const s=e.querySelector(".tbw-scroll-area");if(s&&l&&(!n||i?.forceHorizontalScroll))if(i?.forceScrollLeft)s.scrollLeft=0;else if(i?.forceScrollRight)s.scrollLeft=s.scrollWidth-s.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(r??void 0,l)??{left:0,right:0};if(!t.skipScroll){const e=l.getBoundingClientRect(),i=s.getBoundingClientRect(),n=e.left-i.left+s.scrollLeft,r=n+e.width,o=s.scrollLeft+t.left,d=s.scrollLeft+s.clientWidth-t.right;n<o?s.scrollLeft=n-t.left:r>d&&(s.scrollLeft=r-s.clientWidth+t.right)}}if(n&&l.classList.contains(t)){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(n&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else n||document.activeElement!==e&&e.focus({preventScroll:!0})}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const a='<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>',c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:a,filterActive:a,print:"🖨️"};class u{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{...c,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=l(e):e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t,n){void 0!==n?console.warn(i(t,n,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}}function h(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}const f="__tbw_null__";function g(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return h(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?f:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const s=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===f?e.commit(null):e.commit(n.value)};return n.addEventListener("change",s),n.addEventListener("blur",s),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function w(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 m{#e=/* @__PURE__ */new Map;#i;constructor(t){this.#i=t}setInvalid(t,e,i=""){let n=this.#e.get(t);n||(n=/* @__PURE__ */new Map,this.#e.set(t,n)),n.set(e,i),this.#i(t,e,!0)}clearInvalid(t,e){const i=this.#e.get(t);i&&(i.delete(e),0===i.size&&this.#e.delete(t)),this.#i(t,e,!1)}clearRowInvalid(t){const e=this.#e.get(t);if(e){const i=Array.from(e.keys());this.#e.delete(t),i.forEach(e=>this.#i(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#e.entries());this.#e.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#i(t,i,!1))})}isCellInvalid(t,e){return this.#e.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#e.get(t)?.get(e)}hasInvalidCells(t){const e=this.#e.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#e.get(t)??[])}}function v(t,e,i){const n=t.get(e);return!!n&&!p(n,i)}function p(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(!p(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!p(i[t],n[t]))return!1;return!0}return!1}function y(t,e,i){t.set(e,structuredClone(i))}function E(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class b{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return v(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&&v(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!p(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&v(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){y(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&&y(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&v(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&v(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=E(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&&E(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const R='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function C(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function I(t){}function k(t,e){return!1===t.onBeforeEditClose?.(e)}function _(t,e,n,r,s,o,l,d){if(!r.editable)return;if(o.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:f}=t;let m;try{m=a.getRowId?.(e)}catch{}const v=m?t=>a.updateRow(m,t,"cascade"):I,p=C(r.field)?e[r.field]:void 0;o.classList.add("editing"),h.add(`${n}:${s}`);const y=d??o.parentElement;y&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(y);let E=!1;const b=i=>{if(E||!c&&!t.isEditSessionActive())return;const s=m?a._getRowEntry(m):void 0,o=s?.row??e,l=s?.index??n;t.commitCellValue(l,r,i,o)},_=()=>{if(E=!0,C(r.field)){const t=m?a._getRowEntry(m):void 0;(t?.row??e)[r.field]=p}},S=document.createElement("div");S.className="tbw-editor-host",o.innerHTML="",o.appendChild(S),S.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=S.querySelector("input,textarea,select");return void(t&&b(w(t,r,p)))}if(k(u,e))return;e.stopPropagation(),e.preventDefault(),E=!0,t.exitRowEdit(n,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(k(u,e))return;e.stopPropagation(),e.preventDefault(),_(),t.exitRowEdit(n,!0)}});const x=r,M=x.__editorTemplate,A=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,x)??g(r),L=p,D=`${n}:${r.field}`,T=[];f.set(D,t=>{for(const e of T)e(t)});const G=t=>{T.push(t)};if("template"===A&&M)!function(t,e,i,n,r,s,o,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit: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==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!C(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let e=!1;h.addEventListener("blur",()=>{e||s(w(h,i,r))}),h.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(k(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(w(h,i,r)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(k(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,S,x,e,p,b,_,l,n),G(t=>{if(null!=t&&"object"==typeof t)return;const e=S.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof A){const t=document.createElement(A);t.value=L,t.addEventListener("change",()=>b(t.value)),G(e=>{t.value=e}),S.appendChild(t),l||queueMicrotask(()=>{const t=S.querySelector(R);t?.focus({preventScroll:!0})})}else if("function"==typeof A){const t=A({row:e,rowId:m??"",value:L,field:r.field,column:r,commit:b,cancel:_,updateRow:v,onValueChange:G});if("string"==typeof t)S.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(w(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(w(r,e,n))))}(S,r,b,p),G(t=>{const e=S.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){S.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?G(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):o.setAttribute("data-editor-managed","")}else!t&&S.hasChildNodes()&&o.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=S.querySelector(R);t?.focus({preventScroll:!0})})}else if(A&&"object"==typeof A){const n=document.createElement("div");n.setAttribute("data-external-editor",""),n.setAttribute("data-field",r.field),S.appendChild(n),o.setAttribute("data-editor-managed","");const s={row:e,rowId:m??"",value:L,field:r.field,column:r,commit:b,cancel:_,updateRow:v,onValueChange:G};if(A.mount)try{A.mount({placeholder:n,context:s,spec:A})}catch(F){q="TBW080",P=`External editor mount error for column '${r.field}': ${F}`,$=t.grid.id,console.warn(i(q,P,$,O))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:n,spec:A,context:s}}))}var q,P,$,O}class S extends u{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:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#n(){return"grid"===this.config.mode}#r(t,e){const i=this.#s.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#o(t){return!0===t.editable||"function"==typeof t.editable}#l=-1;#d;#a;#c=-1;#u=/* @__PURE__ */new Map;#h=/* @__PURE__ */new Set;#f=/* @__PURE__ */new Map;#g=!1;#w=-1;#m;#v=!1;#p=!1;#y=!1;#E=null;#b=new b;#R;get#s(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#s;if(this.#m=new m((t,e,i)=>{this.#C(t,e,i)}),this.#R={grid:i,isGridMode:this.#n,config:this.config,editingCells:this.#h,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#l,commitCellValue:(t,e,i,n)=>this.#I(t,e,i,n),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.#b.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#l){if(k(this.config,t))return;this.#k(this.#l,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#n)return;if(-1===this.#l)return;const e=i.findRenderedRowElement?.(this.#l);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||k(this.config,t)||queueMicrotask(()=>{-1!==this.#l&&this.#k(this.#l,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#n)return;if(-1===this.#l)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#l&&this.#_()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#f.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#b.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#b.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#n&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(R)){if(this.#p)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#E;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#E={rowIndex:t,colIndex:n,field:i,value:r[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(R)||(this.#v=!1,this.#E=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#v){if(k(this.config,t))return void queueMicrotask(()=>{if(this.#v){this.#S();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#v=!1,this.#p=!0}});this.#S();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#v=!1,this.#p=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(R)&&(this.#p=!1)},{signal:e}))}detach(){this.#s._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#l=-1,this.#d=void 0,this.#a=void 0,this.#c=-1,this.#u.clear(),this.#b.clear(),this.#h.clear(),this.#f.clear(),this.#v=!1,this.#p=!1,this.#E=null,this.#y=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#n||-1!==this.#l}onCellClick(t){if(this.#n)return!1;const e=this.#s,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>this.#o(t));if(!s)return!1;const o=e._rows[r],l=e.effectiveConfig?.rowEditable;return!(o&&l&&!l(o))&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(t){const e=this.#s;if("Escape"===t.key){if(this.#n&&this.#v){this.#S();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#v=!1,this.#p=!0,this.requestAfterRender(),!0}if(-1!==this.#l&&!this.#n)return k(this.config,t)||this.#k(this.#l,!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.#l&&!this.#n){if(k(this.config,t))return!0;const i=e._rows.length-1,n=this.#l;return this.#k(n,!1),"ArrowDown"===t.key?e._focusRow=Math.min(i,e._focusRow+1):e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault(),d(e),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#l||this.#n)){if(t.preventDefault(),this.#y)return this.#k(this.#l,!1),!0;const e=!t.shiftKey;return this.#x(e),!0}if(" "===t.key||"Spacebar"===t.key){if(-1!==this.#l)return!1;const i=e._focusRow,n=e._focusCol;if(i>=0&&n>=0){const r=e._visibleColumns[n],s=e._rows[i];if(r&&s&&this.#r(r,s)&&"boolean"===r.type){const e=r.field;if(C(e)){const n=!s[e];return this.#I(i,r,n,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.#_(),!0;if(-1!==this.#l)return!!k(this.config,t);const i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;const n=e._focusRow,r=e._focusCol;if(n>=0){const i=e._columns?.some(t=>this.#o(t)),s=e._rows[n],o=e.effectiveConfig?.rowEditable,l=s&&o&&!o(s);if(i&&!l){const i=e._visibleColumns[r],s=e._rows[n],o=i?.field??"",l=o&&s?s[o]:void 0,d=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:l,row:s,cellEl:d,trigger:"keyboard",originalEvent:t}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===t.key){if(-1!==this.#l||this.#n)return!1;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i>=0&&n>=0){const r=e._visibleColumns[n],s=e._rows[i];if(r&&s&&this.#r(r,s)&&r.field)return t.preventDefault(),this.beginCellEdit(i,r.field),!0}return!1}return!1}processColumns(t){const e=this.#s,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.#s;if(this.config.dirtyTracking&&e.getRowId&&this.#b.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#l||this.#n)return t;const i=this.#d,n=this.#a;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#l!==s&&this.#M(this.#l,s),r)}afterRender(){const t=this.#s;if(-1!==this.#l&&this.#a&&!this.#n&&t._rows[this.#l]!==this.#a){const e=t._rows.indexOf(this.#a);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#M(this.#l,e)}if(this.#g&&(this.#g=!1,this.#A(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#b.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#n&&0!==this.#h.size)for(const i of this.#h){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const l=o.querySelector(`.cell[data-col="${s}"]`);if(!l||l.classList.contains("editing"))continue;const d=t._rows[r],a=t._visibleColumns[s];d&&a&&this.#L(d,r,a,s,l,!0)}}afterCellRender(t){const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t,o=this.#r(n,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[n.field];s.textContent=null==t?"":String(t)}this.#n&&o&&(s.classList.contains("editing")||this.#L(e,i,n,r,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#s,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#b.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#b.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.#b.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#b.getChangedRowIds()}get activeEditRow(){return this.#l}get activeEditCol(){return this.#c}isRowEditing(t){return this.#l===t}isCellEditing(t,e){return this.#h.has(`${t}:${e}`)}isRowChanged(t){const e=this.#s,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#b.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#b.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#b.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#b.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#s;return this.#b.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#b.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#b.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#b.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#b.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#s;this.#b.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#b.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#b.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#s;return this.#b.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#s;return this.#b.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#b.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#b.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#s;this.#b.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#b.changedRowIds.clear(),this.#b.committedDirtyRowIds.clear(),this.#D(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.#s;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#s,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],s=i._rows[t];if(!r||!s||!this.#r(r,s))return;const o=i.findRenderedRowElement?.(t),l=o?.querySelector(`.cell[data-col="${n}"]`);l&&(this.#y=!0,this.#T(t,n,l))}beginBulkEdit(t){const e=this.#s;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>this.#o(t));if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;const r=e._rows[t],s=e.effectiveConfig?.rowEditable;r&&s&&!s(r)||(this.#y=!1,this.#G(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s&&this.#r(s,r)){const e=i;e.classList.contains("editing")||this.#L(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(R);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#l&&this.#k(this.#l,!1)}cancelActiveRowEdit(){-1!==this.#l&&this.#k(this.#l,!0)}#C(t,e,i){const n=this.#s,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const l=n.findRenderedRowElement?.(o),d=l?.querySelector(`.cell[data-col="${r}"]`);if(d)if(i){d.setAttribute("data-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&d.setAttribute("title",i)}else d.removeAttribute("data-invalid"),d.removeAttribute("title")}#M(t,e){this.#l=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const o of this.#h)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#h.clear();for(const o of i)this.#h.add(o);const r=this.#u.get(t);void 0!==r&&(this.#u.delete(t),this.#u.set(e,r));const s=[];for(const[o,l]of this.#f)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,l]),this.#f.delete(o));for(const[o,l]of s)this.#f.set(o,l);this.#D()}#T(t,e,i){const n=this.#s,r=n._rows[t],s=n._visibleColumns[e];r&&s&&this.#r(s,r)&&(i.classList.contains("editing")||(this.#l!==t&&this.#G(t,r),this.#c=e,this.#L(r,t,s,e,i,!1)))}#S(){const t=this.#E;if(!t)return;const e=this.#s,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#f.get(n);if(r&&r(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.#b.isRowDirty(t,i)||(this.#b.changedRowIds.delete(t),this.emit("dirty-change",{rowId:t,row:i,original:this.#b.getOriginalRow(t),type:"reverted"})):this.#b.changedRowIds.delete(t))}this.requestRender(),this.#E=null}#_(){const t=this.#s,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(R);t&&(this.#p=!1,t.focus(),this.#v=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#x(t){const e=this.#s,i=e._rows,n=this.#n?e._focusRow:this.#l,r=i[n],s=e._visibleColumns.map((t,e)=>r&&this.#r(t,r)?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?.(n),i=t?.querySelector(`.cell[data-col="${s[o]}"]`);if(i?.classList.contains("editing")){const t=i.querySelector(R);t?.focus({preventScroll:!0})}return void d(e,{forceHorizontalScroll:!0})}const l=n+(t?1:-1);if(l>=0&&l<i.length){const r=i[l],s=e._visibleColumns.map((t,e)=>r&&this.#r(t,r)?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],d(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(R);t?.focus({preventScroll:!0})}},0)):(this.#k(n,!1),e._focusRow=l,e._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(l),d(e,{forceHorizontalScroll:!0}))}}#D(){const t=this.#s;t._activeEditRows=this.#l,t._rowEditSnapshots=this.#u}#G(t,e){if(this.#l!==t){-1!==this.#l&&this.#k(this.#l,!1),this.#u.set(t,{...e}),this.#l=t,this.#a=e;const i=this.#s;try{this.#d=i.getRowId?.(e)??void 0}catch{this.#d=void 0}this.#D(),this.#n||this.emit("edit-open",{rowIndex:t,rowId:this.#d??"",row:e})}}#k(t,e){if(this.#l!==t)return;const i=this.#s,n=this.#u.get(t),r=i.findRenderedRowElement?.(t);let s=this.#d;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#a??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=w(s,r,i);i!==n&&this.#I(t,r,n,l)}})}if(e||this.#n||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#b.changedRowIds.delete(s),this.#b.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#b.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#b.changedRowIds.delete(s),this.#b.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#b.isRowDirty(s,l)?this.#b.committedDirtyRowIds.add(s):this.#b.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#w=t))}this.#u.delete(t),this.#l=-1,this.#d=void 0,this.#a=void 0,this.#c=-1,this.#y=!1,this.#D();for(const d of this.#h)d.startsWith(`${t}:`)&&this.#h.delete(d);for(const d of this.#f.keys())d.startsWith(`${t}:`)&&this.#f.delete(d);if(this.#g=!0,r){const t=i.__frameworkAdapter,e=r.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.#A(i),this.#g=!1;!this.#n&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#I(t,e,i,n){const r=e.field;if(!C(r))return;const s=n[r];if(s===i)return;const o=this.#s;let l;try{l=this.grid.getRowId(n)}catch{}const d=!l||!this.#b.changedRowIds.has(l),a=l?t=>this.grid.updateRow(l,t,"cascade"):I;let c=!1;const u=l?t=>{c=!0,this.setInvalid(l,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:l??"",field:r,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,r)&&this.clearInvalid(l,r),n[r]=i,l&&this.#b.changedRowIds.add(l),this.#D(),this.config.dirtyTracking&&l){const t=this.#b.isRowDirty(l,n);this.emit("dirty-change",{rowId:l,row:n,original:this.#b.getOriginalRow(l),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#L(t,e,i,n,r,s,o){_(this.#R,t,e,i,n,r,s,o)}#A(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}export{S as EditingPlugin,g as defaultEditorFor};
|
|
1
|
+
const t="editing";function e(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}function i(t,i,r,n){return`${e(r,n)} ${t}: ${i}\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 r=/* @__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"]),n=/^on\w+$/i,s=/* @__PURE__ */new Set(["href","src","action","formaction","data","srcdoc","xlink:href","poster","srcset"]),o=/^\s*(javascript|vbscript|data|blob):/i;function l(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 l of i){const t=l.tagName.toLowerCase();if(r.has(t)){e.push(l);continue}if("svg"===t||"http://www.w3.org/2000/svg"===l.namespaceURI){if(Array.from(l.attributes).some(t=>n.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(l);continue}}const i=[];for(const e of l.attributes){const t=e.name.toLowerCase();n.test(t)?i.push(e.name):(s.has(t)&&o.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&i.push(e.name)}i.forEach(t=>l.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content),e.innerHTML}document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function d(e,i){if(e._virtualization?.enabled){const{rowHeight:t,container:i,viewportEl:r}=e._virtualization,n=i,s=r?.clientHeight??n?.clientHeight??0;if(n&&s>0){const i=e._focusRow*t;i<n.scrollTop?n.scrollTop=i:i+t>n.scrollTop+s&&(n.scrollTop=i-s+t)}}const r=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;var n;r||e.refreshVirtualWindow(!1),(n=e._bodyEl)&&n.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=e._focusRow,o=e._virtualization.start??0,l=e._virtualization.end??e._rows.length;if(s>=o&&s<l){const n=e._bodyEl.querySelectorAll(".data-grid-row")[s-o];let l=n?.children[e._focusCol];if(l&&l.classList?.contains("cell")||(l=n?.querySelector(`.cell[data-col="${e._focusCol}"]`)??n?.querySelector(".cell[data-col]")),l){l.classList.add("cell-focus"),l.setAttribute("aria-selected","true");const s=e.querySelector(".tbw-scroll-area");if(s&&l&&(!r||i?.forceHorizontalScroll))if(i?.forceScrollLeft)s.scrollLeft=0;else if(i?.forceScrollRight)s.scrollLeft=s.scrollWidth-s.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(n??void 0,l)??{left:0,right:0};if(!t.skipScroll){const e=l.getBoundingClientRect(),i=s.getBoundingClientRect(),r=e.left-i.left+s.scrollLeft,n=r+e.width,o=s.scrollLeft+t.left,d=s.scrollLeft+s.clientWidth-t.right;r<o?s.scrollLeft=r-t.left:n>d&&(s.scrollLeft=n-s.clientWidth+t.right)}}if(r&&l.classList.contains(t)){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(r&&!l.contains(document.activeElement)){l.hasAttribute("tabindex")||l.setAttribute("tabindex","-1");try{l.focus({preventScroll:!0})}catch{}}else r||document.activeElement!==e&&e.focus({preventScroll:!0})}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const a='<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>',c={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:a,filterActive:a,print:"🖨️"};class u{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{...c,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e,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=l(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,r){void 0!==r?console.warn(i(t,r,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(t,e){throw new Error(i(t,e,this.gridElement.id,this.name))}}function h(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 f="__tbw_null__";function g(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 h(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?f:"",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===f?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 w(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 m{#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 p(t,e,i){const r=t.get(e);return!!r&&!v(r,i)}function v(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(!v(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(!v(i[t],r[t]))return!1;return!0}return!1}function y(t,e,i){t.set(e,structuredClone(i))}function E(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 b{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 p(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&p(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,r){const n=t.get(e);return!!n&&!v(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)&&p(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){y(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&&y(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&&p(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&&p(this.baselines,i,r)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=E(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&&E(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 R='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function C(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function I(t){}function k(t,e){return!1===t.onBeforeEditClose?.(e)}function _(t,e,r,n,s,o,l,d){if(!n.editable)return;if(o.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:f}=t;let m;try{m=a.getRowId?.(e)}catch{}const p=m?t=>a.updateRow(m,t,"cascade"):I,v=C(n.field)?e[n.field]:void 0;o.classList.add("editing"),h.add(`${r}:${s}`);const y=d??o.parentElement;y&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(y);let E=!1;const b=i=>{if(E||!c&&!t.isEditSessionActive())return;const s=m?a._getRowEntry(m):void 0,o=s?.row??e,l=s?.index??r;t.commitCellValue(l,n,i,o)},_=()=>{if(E=!0,C(n.field)){const t=m?a._getRowEntry(m):void 0;(t?.row??e)[n.field]=v}},S=document.createElement("div");S.className="tbw-editor-host",o.innerHTML="",o.appendChild(S),S.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=S.querySelector("input,textarea,select");return void(t&&b(w(t,n,v)))}if(k(u,e))return;e.stopPropagation(),e.preventDefault(),E=!0,t.exitRowEdit(r,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(k(u,e))return;e.stopPropagation(),e.preventDefault(),_(),t.exitRowEdit(r,!0)}});const x=n,A=x.__editorTemplate,M=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const r=t.__frameworkAdapter;if(r?.getTypeDefault){const t=r.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,x)??g(n),L=v,D=`${r}:${n.field}`,T=[];f.set(D,t=>{for(const e of T)e(t)});const G=t=>{T.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(!C(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(w(h,i,n))}),h.addEventListener("keydown",r=>{const l=r;if("Enter"===l.key){if(k(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(w(h,i,n)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(k(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,S,x,e,v,b,_,l,r),G(t=>{if(null!=t&&"object"==typeof t)return;const e=S.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)),G(e=>{t.value=e}),S.appendChild(t),l||queueMicrotask(()=>{const t=S.querySelector(R);t?.focus({preventScroll:!0})})}else if("function"==typeof M){const t=M({row:e,rowId:m??"",value:L,field:n.field,column:n,commit:b,cancel:_,updateRow:p,onValueChange:G});if("string"==typeof t)S.innerHTML=t,function(t,e,i,r){const n=t.querySelector("input,textarea,select");n&&(n.addEventListener("blur",()=>{i(w(n,e,r))}),n instanceof HTMLInputElement&&"checkbox"===n.type?n.addEventListener("change",()=>i(n.checked)):n instanceof HTMLSelectElement&&n.addEventListener("change",()=>i(w(n,e,r))))}(S,n,b,v),G(t=>{const e=S.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){S.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?G(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):o.setAttribute("data-editor-managed","")}else!t&&S.hasChildNodes()&&o.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=S.querySelector(R);t?.focus({preventScroll:!0})})}else if(M&&"object"==typeof M){const r=document.createElement("div");r.setAttribute("data-external-editor",""),r.setAttribute("data-field",n.field),S.appendChild(r),o.setAttribute("data-editor-managed","");const s={row:e,rowId:m??"",value:L,field:n.field,column:n,commit:b,cancel:_,updateRow:p,onValueChange:G};if(M.mount)try{M.mount({placeholder:r,context:s,spec:M})}catch(O){q="TBW080",P=`External editor mount error for column '${n.field}': ${O}`,$=t.grid.id,console.warn(i(q,P,$,F))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:r,spec:M,context:s}}))}var q,P,$,F}class S extends u{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 b;#C;get#o(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#o;if(this.#p=new m((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.#k(t,e,i,r),exitRowEdit:(t,e)=>this.#_(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),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#d){if(k(this.config,t))return;this.#_(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)||k(this.config,t)||queueMicrotask(()=>{-1!==this.#d&&this.#_(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(R)){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(R)||(this.#v=!1,this.#b=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#v){if(k(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(R)&&(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 k(this.config,t)||this.#_(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(k(this.config,t))return!0;const i=e._rows.length-1,r=this.#d;return this.#_(r,!1),"ArrowDown"===t.key?e._focusRow=Math.min(i,e._focusRow+1):e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault(),d(e),this.requestAfterRender(),!0}if("Tab"===t.key&&(-1!==this.#d||this.#n)){if(t.preventDefault(),this.#E)return this.#_(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(C(e)){const r=!s[e];return this.#k(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!!k(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}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:r,col:n}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.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.#T(),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.#G(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(R);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#d&&this.#_(this.#d,!1)}cancelActiveRowEdit(){-1!==this.#d&&this.#_(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.#T()}#G(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(R);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(R);t?.focus({preventScroll:!0})}return void d(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],d(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(R);t?.focus({preventScroll:!0})}},0)):(this.#_(r,!1),e._focusRow=l,e._focusCol=t?s[0]:s[s.length-1],this.beginBulkEdit(l),d(e,{forceHorizontalScroll:!0}))}}#T(){const t=this.#o;t._activeEditRows=this.#d,t._rowEditSnapshots=this.#h}#q(t,e){if(this.#d!==t){-1!==this.#d&&this.#_(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.#T(),this.#n||this.emit("edit-open",{rowIndex:t,rowId:this.#a??"",row:e})}}#_(t,e){if(this.#d!==t)return;const i=this.#o,r=this.#h.get(t),n=i.findRenderedRowElement?.(t);let s=this.#a;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#c??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&n&&l){n.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=l[e],r=w(s,n,i);i!==r&&this.#k(t,n,r,l)}})}if(e||this.#n||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&r&&l)Object.keys(r).forEach(t=>{l[t]=r[t]}),s&&(this.#R.changedRowIds.delete(s),this.#R.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){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}(r,l),i=s?this.#R.changedRowIds.has(s):e,n=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:r,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});n&&r?(Object.keys(r).forEach(t=>{l[t]=r[t]}),s&&(this.#R.changedRowIds.delete(s),this.#R.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):n||(s&&this.config.dirtyTracking&&(this.#R.isRowDirty(s,l)?this.#R.committedDirtyRowIds.add(s):this.#R.committedDirtyRowIds.delete(s)),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.#T();for(const d of this.#f)d.startsWith(`${t}:`)&&this.#f.delete(d);for(const d of this.#g.keys())d.startsWith(`${t}:`)&&this.#g.delete(d);if(this.#w=!0,n){const t=i.__frameworkAdapter,e=n.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&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#k(t,e,i,r){const n=e.field;if(!C(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"):I;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.#T(),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){_(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{S as EditingPlugin,g as defaultEditorFor};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|