@toolbox-web/grid 1.30.1 → 1.30.3
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/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -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/filtering/types.d.ts +16 -0
- 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 +1 -1
- 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/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/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/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/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
|
@@ -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,n,r){return`${e(n,r)} ${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 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(O){q="TBW080",P=`External editor mount error for column '${r.field}': ${O}`,$=t.grid.id,console.warn(i(q,P,$,F))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:n,spec:A,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: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};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|