@toolbox-web/grid 3.10.0 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/lib/features/registry.js +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/helpers.d.ts +23 -0
- package/lib/plugins/editing/types.d.ts +11 -0
- 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/master-detail/master-detail-plugin.d.ts +6 -1
- package/lib/plugins/shared/structural-toggle.d.ts +14 -0
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.d.ts +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +20 -2
- package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +8 -0
- 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/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.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/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@toolbox-web/grid")):"function"==typeof define&&define.amd?define(["exports","@toolbox-web/grid"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid)}(this,function(t,e){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var i="editing",n="data-tbw-truncated";function r(t,e){if(!t)return;if(!1===("effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.announcements)return;const i=t.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=e}):i.textContent=e)}function o(t,i,...n){const r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[i];return r?r(...n):e.DEFAULT_A11Y_MESSAGES[i](...n)}function s(t,n){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:i,container:n,viewportEl:r,scrollMapping:o}=t._virtualization,s=n,l=r?.clientHeight??s?.clientHeight??0;if(!s||l<=0)return;const d=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const a=Math.max(0,d.top),c=l-a-Math.max(0,d.bottom);if(c<=0)return;const u=t._focusRow*i,h=o?(0,e.toVirtualScrollTop)(s.scrollTop,o):s.scrollTop;if(u<h+a){const t=Math.max(0,u-a);s.scrollTop=o?(0,e.fromVirtualScrollTop)(t,o):t}else if(u+i>h+a+c){const t=Math.max(0,u-c+i-a);s.scrollTop=o?(0,e.fromVirtualScrollTop)(t,o):t}}(t);const r=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var o;r||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=function(t){const e=t._focusRow,i=t._virtualization.start??0,n=t._virtualization.end??t._rows.length;if(e<i||e>=n)return;const r=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=r?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o?{rowEl:r??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:l,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),r&&!n?.forceHorizontalScroll||function(t,e,i,n){const r=t.querySelector(".tbw-scroll-area");if(!r)return;if(n?.forceScrollLeft)return void(r.scrollLeft=0);if(n?.forceScrollRight)return void(r.scrollLeft=r.scrollWidth-r.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=r.getBoundingClientRect(),d=s.left-l.left+r.scrollLeft,a=d+s.width,c=r.scrollLeft+o.left,u=r.scrollLeft+r.clientWidth-o.right;d<c?r.scrollLeft=d-o.left:a>u&&(r.scrollLeft=a-r.clientWidth+o.right)}(t,l,d,n),function(t,e,n){if(n&&e.classList.contains(i)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(n){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const r=document.activeElement;r instanceof HTMLElement&&r!==t&&"function"==typeof t.contains&&t.contains(r)&&!r.classList.contains("cell")&&!r.closest(".cell")||r===t||t.focus({preventScroll:!0})}(t,d,r)}var l=/{{\s*([^}]+)\s*}}/g,d="__DG_EMPTY__",a=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,c="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),u=new RegExp(`__(proto|defineGetter|defineSetter)|${c.slice(3).join("|")}|this\\b`);new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|"));function h(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const n=t[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const n=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<t.length&&"'"!==t[i];)n+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(n,i)});continue}if(i+2<t.length){const n=t.slice(i,i+3);if("==="===n||"!=="===n){e.push({type:"op",v:n}),i+=3;continue}}if(i+1<t.length){const n=t.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){e.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;e.push({type:"op",v:n}),i++}else i++}return e}(t);if(!i)return;const n=i;let r=0;function o(){return n[r]}function s(){return n[r++]}function l(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function d(){const t=function(){let t=a();for(;l("op","||");)s(),t=t||a();return t}();if(l("op","?")){s();const e=d();if(!l("op",":"))return;s();const i=d();return t?e:i}return t}function a(){let t=c();for(;l("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=f();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=f();else{if("-"!==e.v)break;s(),t-=f()}}return t}function f(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return l("op","!")?(s(),!g()):w()}function w(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=d();return l("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-w()):void 0}}const m=d();return r<n.length?void 0:m}function f(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],n=(r=t.replace(l,(t,n)=>{const r=function(t,e){if(!(t=(t||"").trim()))return d;if(g.test(t))return d;if("value"===t)return null==e.value?d:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return null==n?d:String(n)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),n=e.typeDefault?e.typeDefault[i]:void 0;return null==n?d:String(n)}if(t.length>80)return d;if(!a.test(t)||u.test(t))return d;const i=t.match(/\./g);if(i&&i.length>1)return d;try{const i=h(t,e),n=null==i?"":String(i);return g.test(n)?d:n||d}catch{return d}}(n,e);return i.push({expr:n.trim(),result:r}),r===d?r:(o=r)&&"string"==typeof o?o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):"";var o}),r?r.replace(new RegExp(d,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):r);var r;const o=i.length&&i.every(t=>""===t.result||t.result===d);return g.test(t)||o?"":n}var g=/Reflect|Proxy|ownKeys/;function w(t){if(g.test(t)){const t=()=>"";return t.__blocked=!0,t}const e=e=>f(t,e);return e.__blocked=!1,e}function m(t){if(!t.firstElementChild)return null;const e=t.querySelector(":scope > .tbw-cell-loading-overlay");if(!e)return null;const i=t.parentElement;return i?i.insertBefore(e,t):e.remove(),e}function p(t){const e=t.options;return e?"function"==typeof e?e():e:[]}function v(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??new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}var y="__tbw_null__",b=new WeakMap;function E(t,e){let i;const n=[];let r=!1;for(const o of Array.from(t.options)){if(!o.selected)continue;if(b.has(o)){n.push(b.get(o));continue}if(e?.nullable&&o.value===y){r=!0;continue}i??=e?p(e):[];const t=i.find(t=>String(t.value)===o.value);n.push(t?t.value:o.value)}return r&&0===n.length?null:n}function R(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 v(t);case"select":return function(t){return i=>{const n=t.editorParams,r=document.createElement("select");if(t.multi&&(r.multiple=!0),t.nullable||n?.includeEmpty){const e=document.createElement("option");e.value=t.nullable?y:"",e.textContent=t.nullable?n?.emptyLabel??"(Blank)":n?.emptyLabel??"",null==i.value&&(e.selected=!0),r.appendChild(e)}p(t).forEach(e=>{const n=document.createElement("option");n.value=String(e.value),n.textContent=e.label,b.set(n,e.value),t.multi&&Array.isArray(i.value)&&i.value.includes(e.value)?n.selected=!0:t.multi||i.value!==e.value||(n.selected=!0),r.appendChild(n)});const o=()=>{if(t.multi){const n=E(r,t);if(k((0,e.readCellField)(i.row,i.field),n))return;i.commit(n)}else t.nullable&&r.value===y?i.commit(null):i.commit(r.value)};return r.addEventListener("change",o),r.addEventListener("blur",o),r.addEventListener("keydown",t=>{"Escape"===t.key&&i.cancel()}),r}}(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 C(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function I(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return t instanceof HTMLSelectElement&&t.multiple?E(t,e):t instanceof HTMLSelectElement&&e?.nullable&&t.value===y?null:""===t.value||"number"!==e?.type&&"number"!=typeof i?null==i&&""===t.value?e?.nullable?null:"":t.value:Number(t.value)}(t,e,i);switch(t.type){case"checkbox":return t.checked;case"number":return C(t.value,e);case"date":return function(t,e,i){return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date}(t,e,i);default:return function(t,e,i){return"number"==typeof i?C(t.value,e):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}(t,e,i)}}function _(t,e,i){t instanceof HTMLSelectElement?function(t,e,i){t.multiple?function(t,e,i){const n=Array.isArray(e)?e:null==e?[]:[e];for(const r of Array.from(t.options))if(b.has(r)){const t=b.get(r);r.selected=n.some(e=>e===t)}else S(r,i)?r.selected=null==e:r.selected=n.some(t=>String(t)===r.value)}(t,e,i):null==e&&Array.from(t.options).some(t=>S(t,i))?t.value=y:t.value=String(e??"")}(t,e,!!i?.nullable):t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t instanceof HTMLInputElement&&"date"===t.type&&e instanceof Date?t.valueAsDate=e:t instanceof HTMLInputElement&&"date"===t.type&&"string"==typeof e?t.value=e.split("T")[0]:t.value=String(e??"")}function S(t,e){return e&&t.value===y&&!b.has(t)}function k(t,e){if(Array.isArray(t)&&Array.isArray(e)){const i=new Set(t),n=new Set(e);return i.size===n.size&&[...n].every(t=>i.has(t))}return t===e}var x=class{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=new Map,this.#t.set(t,n)),n.set(e,i),this.#e(t,e,!0)}clearInvalid(t,e){const i=this.#t.get(t);i&&(i.delete(e),0===i.size&&this.#t.delete(t)),this.#e(t,e,!1)}clearRowInvalid(t){const e=this.#t.get(t);if(e){const i=Array.from(e.keys());this.#t.delete(t),i.forEach(e=>this.#e(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#t.entries());this.#t.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#e(t,i,!1))})}isCellInvalid(t,e){return this.#t.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#t.get(t)?.get(e)}hasInvalidCells(t){const e=this.#t.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#t.get(t)??[])}};function A(t,e,i){const n=t.get(e);return!!n&&!M(n,i)}function M(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(!M(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const t of r)if(!M(i[t],n[t]))return!1;return!0}return!1}function L(t,e,i){t.set(e,structuredClone(i))}function G(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}var D=class{baselines=new Map;baselinesWereCaptured=!1;newRowIds=new Set;changedRowIds=new Set;committedDirtyRowIds=new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;return function(t,e,i){for(const n of e)if(!0!==n?.__loading)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0,!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return A(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&A(this.baselines,e,i))return!0}return!1}isCellDirty(t,i,n){return function(t,i,n,r){const o=t.get(i);return!!o&&!M((0,e.readCellField)(o,r),(0,e.readCellField)(n,r))}(this.baselines,t,i,n)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&A(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){L(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,i,n){const r=this.baselines.get(t);r&&(0,e.writeCellField)(r,i,n)}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&&L(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&A(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&A(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=G(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&&G(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}};var T='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function F(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function q(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function P(t){}function $(t,e){return!1===t.onBeforeEditClose?.(e)}function V(t,i,n,r,o,s,l,d){if(!r.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:f}=t;let g;try{g=a.getRowId?.(i)}catch{}const w=g?t=>a.updateRow(g,t,"cascade"):P,p=q(r.field)?(0,e.readCellField)(i,r.field):void 0;s.classList.add("editing"),h.add(`${n}:${o}`);const v=d??s.parentElement;v&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(v);let y=!1;const b=e=>{if(y||!c&&!t.isEditSessionActive())return;const o=g?a._getRowEntry(g):void 0,s=o?.row??i,l=o?.index??n;t.commitCellValue(l,r,e,s)},E=()=>{if(y=!0,q(r.field)){const t=(g?a._getRowEntry(g):void 0)?.row??i;(0,e.writeCellField)(t,r.field,p)}},C=document.createElement("div");C.className="tbw-editor-host";const S=m(s);s.firstElementChild&&a.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.appendChild(C),S&&s.appendChild(S),C.addEventListener("keydown",e=>{if(!e.defaultPrevented){if("Enter"===e.key){const t=e.target;if(t&&"true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute?.("aria-controls"))return}if("Enter"===e.key){const i=e.target,o=F(i);if(o&&o!==i)return;if(c){e.preventDefault();const t=C.querySelector("input,textarea,select");return void(t&&b(I(t,r,p)))}if($(u,e))return;e.stopPropagation(),e.preventDefault(),y=!0,t.exitRowEdit(n,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if($(u,e))return;e.stopPropagation(),e.preventDefault(),E(),t.exitRowEdit(n,!0)}}});const k=r,x=k.__editorTemplate,A=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(a,k)??R(r),M=p,L=`${n}:${r.field}`,G=[];f.set(L,t=>{for(const e of G)e(t)});const D=t=>{G.push(t)};if("template"===A&&x)!function(t,e,i,n,r,o,s,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!q(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let e=!1;h.addEventListener("blur",()=>{e||o(I(h,i,r))}),h.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if($(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,o(I(h,i,r)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if($(t.config,l))return;l.stopPropagation(),l.preventDefault(),s(),t.exitRowEdit(d,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(t,C,k,i,p,b,E,l,n),D(t=>{const e=C.querySelector("input,textarea,select");if(!e)return;const i=e instanceof HTMLSelectElement&&e.multiple,n=t instanceof Date&&e instanceof HTMLInputElement&&"date"===e.type;(i||n||null==t||"object"!=typeof t)&&_(e,t,r)});else if("string"==typeof A){const t=document.createElement(A);t.value=M,t.addEventListener("change",()=>b(t.value)),D(e=>{t.value=e}),C.appendChild(t),l||queueMicrotask(()=>{C.querySelector(T)?.focus({preventScroll:!0})})}else if("function"==typeof A){const e=A({row:i,rowId:g??"",value:M,field:r.field,column:r,commit:b,cancel:E,updateRow:w,onValueChange:D,grid:t.grid});"string"==typeof e?(C.innerHTML=e,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(I(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(I(r,e,n))))}(C,r,b,p),D(t=>{const e=C.querySelector("input,textarea,select");e&&_(e,t,r)})):e instanceof Node?(C.appendChild(e),e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?D(t=>_(e,t,r)):s.setAttribute("data-editor-managed","")):!e&&C.hasChildNodes()&&s.setAttribute("data-editor-managed",""),l||queueMicrotask(()=>{C.querySelector(T)?.focus({preventScroll:!0})})}else if(A&&"object"==typeof A){const e=document.createElement("div");e.setAttribute("data-external-editor",""),e.setAttribute("data-field",r.field),C.appendChild(e),s.setAttribute("data-editor-managed","");const n={row:i,rowId:g??"",value:M,field:r.field,column:r,commit:b,cancel:E,updateRow:w,onValueChange:D,grid:t.grid};if(A.mount)try{A.mount({placeholder:e,context:n,spec:A})}catch(N){V="TBW080",H=`External editor mount error for column '${r.field}': ${N}`,O=t.grid.id,console.warn(function(t,e,i,n){return`${function(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}(i,n)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}(V,H,O,W))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:e,spec:A,context:n}}))}var V,H,O,W;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(T);e&&(e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")||e.hasAttribute("title")||e.id&&t.querySelector(`label[for="${CSS.escape(e.id)}"]`)||e.closest("label")||e.setAttribute("aria-label",i))})}(C,r)}var H=class extends e.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"},{type:"cell-edit-reverted",description:"Emitted when row values are rolled back in place (revertRow/revertAll, row-edit cancel, grid-mode Escape) — not recorded as history"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"},{type:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg:var(--tbw-color-selection);--tbw-editing-row-bg:var(--tbw-editing-bg);--tbw-editing-border:var(--tbw-border-input,1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input:var(--tbw-cell-padding-input,2px 6px);--tbw-font-size-editor:inherit;--tbw-editing-row-outline-color:var(--tbw-color-accent);--tbw-editing-row-outline-width:1px}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n(t,e){const i=this.#r.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#o(t){return!0===t.editable||"function"==typeof t.editable}#s=-1;#l;#d;#a=-1;#c=new Map;#u=new Set;#h=new WeakSet;#f=new Map;#g=!1;#w=-1;#m;#p=!1;#v=!1;#y=!1;#b=null;#E=new D;#R=new Set;#C;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;this.#m=new x((t,e,i)=>{this.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#s,commitCellValue:(t,e,i,n)=>this.#_(t,e,i,n),exitRowEdit:(t,e)=>this.#S(t,e)},this.#k(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#E.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),this.#x(e,i),this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.#A(e,i))}#x(t,e){if(document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#s){if($(this.config,t))return;this.#S(this.#s,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#s)return;const i=e.findRenderedRowElement?.(this.#s);if(!i)return;if((t.composedPath&&t.composedPath()||[]).includes(i))return;const n=t.target;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=e.findRenderedRowElement?.(this.#s);if(t&&function(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const o=e.ownerDocument?.getElementById(r);if(o&&o.contains(t))return!0}return!1}(n,t))return}$(this.config,t)||queueMicrotask(()=>{-1!==this.#s&&this.#S(this.#s,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#s)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#s&&this.#M()})},{signal:t}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#f.get(i);n&&n(e.newValue)},{signal:t}),this.config.dirtyTracking){const e=t=>{const e=t.detail?.action;if(!e)return;const i="compound"===e.type?e.actions:[e],n=new Set;for(const r of i){const t=void 0!==r.rowId?this.#r._getRowEntry(r.rowId)?.row:this.rows[r.rowIndex];if(!t)continue;const e=r.rowId??this.#L(t);if(!e||n.has(e))continue;n.add(e);const i=this.#E.isRowDirty(e,t);this.#G(e,t,i?"modified":"pristine")}};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",t=>{const e=this.#L(t.row);null!=e&&this.markAsNew(String(e))}),this.on("datasource:data",t=>{this.#D(t.rows)&&this.requestAfterRender()})}}#D(t){const e=this.#r;return!!e.getRowId&&this.#E.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}})}#A(t,i){this.gridElement.addEventListener("focusin",t=>{const n=t.target;if(n!==this.gridElement&&n.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return n.blur(),void this.gridElement.focus();const t=i._focusRow,r=i._focusCol,o=this.#b;if(!o||o.rowIndex!==t||o.colIndex!==r){const n=i._visibleColumns?.[r],o=i._rows?.[t];if(n?.field&&o){const i=n.field;this.#b={rowIndex:t,colIndex:r,field:i,value:(0,e.readCellField)(o,i)}}}this.#p=!0}},{signal:t}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=F(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#p=!1,this.#b=null)},{signal:t}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#p){if($(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#T()});this.#T(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(this.#v=!1)},{signal:t})}detach(){this.#r._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#c.clear(),this.#E.clear(),this.#u.clear(),this.#f.clear(),this.#p=!1,this.#v=!1,this.#b=null,this.#y=!1,this.#h=new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#s;if("getCellEditableResolver"===t.type){const t=this.#r.effectiveConfig?.columns??[],e=new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#n(n,i)}}return"commitCellValue"===t.type?this.#F(t.context):void 0}#F(t){const i=this.#r,n=(i._visibleColumns??[]).find(e=>e.field===t.field)??i._columns?.find(e=>e.field===t.field),r=t.row??(null!=t.rowId?i._getRowEntry(t.rowId)?.row:void 0)??i._rows?.[t.rowIndex];if("sync"===t.source){if(!r||!q(t.field))return;(0,e.writeCellField)(r,t.field,t.newValue),(0,e.invalidateAccessorCache)(r);const i=this.#L(r);if(i&&this.config.dirtyTracking){this.#E.rebaselineCell(i,t.field,t.newValue);const e=this.#E.isRowDirty(i,r);e||this.#E.changedRowIds.delete(i),this.#G(i,r,e?"modified":"pristine")}return!0}if(n&&r&&q(t.field)){if("history"===t.source){(0,e.writeCellField)(r,t.field,t.newValue),(0,e.invalidateAccessorCache)(r);const i=this.#L(r);if(i&&this.config.dirtyTracking){const t=this.#E.isRowDirty(i,r);t||this.#E.changedRowIds.delete(i),this.#G(i,r,t?"modified":"pristine")}return!0}return this.#_(t.rowIndex,n,t.newValue,r,t.source),(0,e.readCellField)(r,t.field)===t.newValue}}onCellClick(t){if(this.#i)return!1;const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t;return!!e._columns?.some(t=>this.#o(t))&&(!!this.#q(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){switch(t.key){case"Escape":return this.#P(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#$(t);case"Tab":return this.#V(t);case" ":case"Spacebar":return this.#H(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#O(t);case"F2":return this.#W(t);default:return!1}}#P(t){return this.#i&&this.#p?(this.#T(),this.requestAfterRender(),!0):-1!==this.#s&&!this.#i&&($(this.config,t)||this.#S(this.#s,!0),!0)}#$(t){const e=F(t.target),i=!!e&&e!==this.gridElement,n="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#i&&!this.#p&&!i)&&(!(!this.#i||!this.#p&&!i||!n)||!(!n||-1===this.#s||this.#i))}#V(t){return!(-1===this.#s&&!this.#i)&&(t.preventDefault(),this.#y?(this.#S(this.#s,!1),!0):(this.#N(!t.shiftKey),!0))}#H(t){if(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;if(-1!==this.#s)return!1;const i=this.#r,n=i._focusRow,r=i._focusCol;if(n<0||r<0)return!1;const o=i._visibleColumns[r],s=i._rows[n];if(!o||!s||"boolean"!==o.type)return!1;if(!this.#n(o,s))return!1;const l=o.field;return!!q(l)&&(this.#_(n,o,!(0,e.readCellField)(s,l),s),t.preventDefault(),this.requestRender(),!0)}#O(t){if(this.#i&&!this.#p)return this.#M(),!0;if(this.#i&&this.#p)return this.#z(t);if(-1!==this.#s){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!$(this.config,t)}return this.#j(t)}#z(t){const e=F(t.target);if(e&&e!==t.target)return!0;this.#b=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0,this.requestAfterRender(),!0}#j(t){const i=this.#r,n=this.config.editOn??i.effectiveConfig?.editOn;if(!1===n||"manual"===n)return!1;const r=i._focusRow,o=i._focusCol;if(r<0)return!1;const s=i._columns?.some(t=>this.#o(t)),l=i._rows[r];if(!s||!this.#q(l))return!1;const d=i._visibleColumns[o]?.field??"",a=d&&l?(0,e.readCellField)(l,d):void 0,c=this.gridElement.querySelector(`[data-row="${r}"][data-col="${o}"]`),u=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:r,colIndex:o,field:d,value:a,row:l,cellEl:c,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(u),u.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(r),!0)}#W(t){if(-1!==this.#s||this.#i)return!1;const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];return!!(r&&o&&r.field)&&(!!this.#n(r,o)&&(t.preventDefault(),this.beginCellEdit(i,r.field),!0))}#K(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#B(){const t=this.#r,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const n=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!n.length)return;const r=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<n.length;s++){const t=n[s],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),d=l??t;let a=r?.canHandle?.(d)?r.createEditor?.(d):void 0;if(!a&&l){const e=this.#K(t),i=w(l.innerHTML);a=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}a&&(o[e]={...i??{},editor:a})}}processColumns(t){const e=this.#r;this.#B();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const o=t.__element;if(o&&!this.#h.has(o)){this.#h.add(o),null==t.editable&&o.hasAttribute("editable")&&(t.editable="false"!==o.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=o.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(s=i.editorParams)}return s?{...t,editorParams:{...s,...t.editorParams}}:t})}processRows(t){if(this.config.dirtyTracking&&this.#D(t),-1===this.#s||this.#i)return t;const e=this.#l,i=this.#d;if(!e||!i)return t;const n=[...t];let r=-1;for(let o=0;o<n.length;o++)if(this.#L(n[o])===e){r=o;break}return-1===r?(setTimeout(()=>this.cancelActiveRowEdit(),0),n):(n[r]=i,this.#s!==r&&this.#U(this.#s,r),n)}afterRender(){const t=this.#r;if(-1!==this.#s&&this.#d&&!this.#i&&t._rows[this.#s]!==this.#d){const e=t._rows.indexOf(this.#d);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#U(this.#s,e)}if(this.#g&&(this.#g=!1,this.#Y(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#E.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#u.size)for(const i of this.#u){const[e,n]=i.split(":"),r=parseInt(e,10),o=parseInt(n,10),s=this.#X(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],d=t._visibleColumns[o];l&&d&&this.#Z(l,r,d,o,s,!0)}}afterCellRender(t){const{row:i,rowIndex:n,column:r,colIndex:o,cellElement:s}=t,l=this.#n(r,i);if(l)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#i&&s.classList.contains("editing")){s.classList.remove("editing");const t=(0,e.readCellField)(i,r.field);s.textContent=null==t?"":String(t)}this.#i&&l&&(s.classList.contains("editing")||this.#Z(i,n,r,o,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#E.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",i),r){const i=o.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#E.isCellDirty(e,t.row,o))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#E.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#E.getChangedRowIds()}get activeEditRow(){return this.#s}get activeEditCol(){return this.#a}isRowEditing(t){return this.#s===t}isCellEditing(t,e){return this.#u.has(`${t}:${e}`)}isRowChanged(t){const e=this.#r,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#E.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#E.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#E.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#E.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#E.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#E.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markDirty(t),this.#G(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#E.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#E.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#E.revertRow(t,e)&&(this.#G(t,e,"reverted"),this.emitPluginEvent("cell-edit-reverted",{rowId:t}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.revertAll(e=>t._getRowEntry(e)?.row),this.emitPluginEvent("cell-edit-reverted",{}),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#k(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#r._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#r,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[t];if(!r||!o||!this.#n(r,o))return;const s=this.#X(t,n);s&&(this.#y=!0,this.#Q(t,n,s))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#o(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#q(n)&&(this.#y=!1,this.#J(t,n),Array.from(i.children).forEach((i,r)=>{const o=e._visibleColumns[r];if(o&&this.#n(o,n)){const e=i;e.classList.contains("editing")||this.#Z(n,t,o,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(T);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#s&&this.#S(this.#s,!1)}cancelActiveRowEdit(){-1!==this.#s&&this.#S(this.#s,!0)}#L(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#X(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#q(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#G(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:i})}#T(){this.#tt();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#et(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#E.changedRowIds.delete(t),this.#E.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)),this.emitPluginEvent("cell-edit-reverted",{rowId:t}))}#I(t,e,i){const r=this.#r,o=r._visibleColumns?.findIndex(t=>t.field===e);if(-1===o||void 0===o)return;const s=r._rows?.findIndex(e=>this.#L(e)===t);if(-1===s||void 0===s)return;const l=this.#X(s,o);if(l)if(i){l.setAttribute("data-invalid","true"),l.setAttribute("aria-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&(l.setAttribute("title",i),l.removeAttribute(n))}else l.removeAttribute("data-invalid"),l.removeAttribute("aria-invalid"),l.removeAttribute("title")}#U(t,e){this.#s=e;const i=new Set,n=`${t}:`;for(const s of this.#u)s.startsWith(n)?i.add(`${e}:${s.substring(n.length)}`):i.add(s);this.#u.clear();for(const s of i)this.#u.add(s);const r=this.#c.get(t);void 0!==r&&(this.#c.delete(t),this.#c.set(e,r));const o=[];for(const[s,l]of this.#f)s.startsWith(n)&&(o.push([`${e}:${s.substring(n.length)}`,l]),this.#f.delete(s));for(const[s,l]of o)this.#f.set(s,l);this.#k()}#Q(t,e,i){const n=this.#r,r=n._rows[t],o=n._visibleColumns[e];r&&o&&this.#n(o,r)&&(i.classList.contains("editing")||(this.#s!==t&&this.#J(t,r),this.#a=e,this.#Z(r,t,o,e,i,!1)))}#tt(){const t=this.#b;if(!t)return;const i=this.#r._rows?.[t.rowIndex];i&&((0,e.writeCellField)(i,t.field,t.value),this.emitPluginEvent("cell-edit-reverted",{rowId:this.#L(i)}));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){const t=this.#L(i);t&&(this.config.dirtyTracking?this.#E.isRowDirty(t,i)||(this.#E.changedRowIds.delete(t),this.#G(t,i,"reverted")):this.#E.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#M(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#X(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(T);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#N(t){const e=this.#r,i=e._rows,n=this.#i?e._focusRow:this.#s,r=i[n],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;const l=o.indexOf(e._focusCol)+(t?1:-1);if(l>=0&&l<o.length){e._focusCol=o[l];const t=this.#X(n,o[l]);return t?.classList.contains("editing")&&t.querySelector(T)?.focus({preventScroll:!0}),void s(e,{forceHorizontalScroll:!0})}const d=n+(t?1:-1);if(d>=0&&d<i.length){const r=i[d],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(e._focusRow=d,e._focusCol=t?o[0]:o[o.length-1],s(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#X(d,e._focusCol);t?.classList.contains("editing")&&t.querySelector(T)?.focus({preventScroll:!0})},0)):(this.#S(n,!1),e._focusRow=d,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(d),s(e,{forceHorizontalScroll:!0}))}}#k(){const t=this.#r;t._activeEditRows=this.#s,t._rowEditSnapshots=this.#c}#J(t,e){this.#s!==t&&(-1!==this.#s&&this.#S(this.#s,!1),this.#c.set(t,{...e}),this.#s=t,this.#d=e,this.#l=this.#L(e),this.#k(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#l??"",row:e}),r(this.gridElement,o(this.gridElement,"editingStarted",t))))}#S(t,e){if(this.#s!==t)return;const i=this.#r,n=this.#c.get(t),s=i.findRenderedRowElement?.(t),{rowId:l,current:d}=this.#it(t);!e&&s&&d&&this.#nt(s,t,d),e||this.#i||!d||this.emit("before-edit-close",{rowIndex:t,rowId:l??"",row:d}),e&&d?this.#et(l,d,n):!e&&d&&this.#rt(t,l,d,n),this.#ot(t),this.#g=!0,s?this.#st(s,i):(this.#Y(i),this.#g=!1),!this.#i&&d&&(this.broadcast("edit-close",{rowIndex:t,rowId:l??"",row:d,reverted:e}),e||r(this.gridElement,o(this.gridElement,"editingCommitted",t)))}#it(t){const e=this.#r;let i=this.#l;const n=(i?e._getRowEntry(i):void 0)?.row??this.#d??e._rows[t];return!i&&n&&(i=this.#L(n)),{rowId:i,current:n}}#nt(t,i,n){const r=this.#r;t.querySelectorAll(".cell.editing").forEach(t=>{const o=Number(t.getAttribute("data-col"));if(isNaN(o))return;const s=r._visibleColumns[o];if(!s)return;if(t.hasAttribute("data-editor-managed"))return;const l=t.querySelector("input,textarea,select");if(!l)return;const d=s.field,a=(0,e.readCellField)(n,d),c=I(l,s,a);k(a,c)||this.#_(i,s,c,n)})}#rt(t,e,i,n){const r=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}(n,i),o=e?this.#E.changedRowIds.has(e):r;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:n,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?n&&this.#et(e,i,n):(e&&this.config.dirtyTracking&&(this.#E.isRowDirty(e,i)?this.#E.committedDirtyRowIds.add(e):this.#E.committedDirtyRowIds.delete(e)),r&&this.isAnimationEnabled&&(this.#w=t))}#ot(t){this.#c.delete(t),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#y=!1,this.#k();for(const e of this.#u)e.startsWith(`${t}:`)&&this.#u.delete(e);for(const e of this.#f.keys())e.startsWith(`${t}:`)&&this.#f.delete(e)}#st(t,e){const i=e.__frameworkAdapter,n=t.querySelectorAll(".cell.editing");i?.releaseCell&&n.forEach(t=>{const e=m(t);i.releaseCell(t),e&&t.appendChild(e)}),n.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#_(t,i,n,r,o="user"){const s=i.field;if(!q(s))return;const l=(0,e.readCellField)(r,s);if(l===n)return;const d=this.#r,a=this.#L(r),c=!a||!this.#E.changedRowIds.has(a),u=a?t=>this.grid.updateRow(a,t,"cascade"):P;let h=!1;const f=a?t=>{h=!0,this.setInvalid(a,s,t??"")}:()=>{},g=`${a??t}\0${s}`;if(this.#R.has(g))return;let w=!1;this.#R.add(g);try{w=this.emitCancelable("cell-commit",{row:r,rowId:a??"",field:s,oldValue:l,value:n,source:o,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:u,setInvalid:f})}finally{this.#R.delete(g)}if(w)return;if(a&&!h&&this.isCellInvalid(a,s)&&this.clearInvalid(a,s),(0,e.writeCellField)(r,s,n),(0,e.invalidateAccessorCache)(r),a&&this.#E.changedRowIds.add(a),this.#k(),this.config.dirtyTracking&&a){const t=this.#E.isRowDirty(a,r);this.#G(a,r,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,rowId:a,field:s,oldValue:l,newValue:n});const m=d.findRenderedRowElement?.(t);m&&m.classList.add("changed")}#Z(t,e,i,n,r,o,s){V(this.#C,t,e,i,n,r,o,s)}#Y(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{}})}};t.EditingPlugin=H,t.defaultEditorFor=R});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@toolbox-web/grid")):"function"==typeof define&&define.amd?define(["exports","@toolbox-web/grid"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TbwGridPlugin_editing={},t.TbwGrid)}(this,function(t,e){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var i="editing",n="tree-toggle",r="group-toggle",o="data-tbw-truncated";function s(t,e){if(!t)return;if(!1===("effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.announcements)return;const i=t.querySelector?.(".tbw-sr-only");i&&(i.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{i.textContent=e}):i.textContent=e)}function l(t,i,...n){const r=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[i];return r?r(...n):e.DEFAULT_A11Y_MESSAGES[i](...n)}function d(t,n){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:i,container:n,viewportEl:r,scrollMapping:o}=t._virtualization,s=n,l=r?.clientHeight??s?.clientHeight??0;if(!s||l<=0)return;const d=t._getVerticalScrollOffsets?.(t._focusRow)??{top:0,bottom:0};if(d.skipScroll)return;const a=Math.max(0,d.top),c=l-a-Math.max(0,d.bottom);if(c<=0)return;const u=t._focusRow*i,h=o?(0,e.toVirtualScrollTop)(s.scrollTop,o):s.scrollTop;if(u<h+a){const t=Math.max(0,u-a);s.scrollTop=o?(0,e.fromVirtualScrollTop)(t,o):t}else if(u+i>h+a+c){const t=Math.max(0,u-c+i-a);s.scrollTop=o?(0,e.fromVirtualScrollTop)(t,o):t}}(t);const r=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var o;r||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const s=function(t){const e=t._focusRow,i=t._virtualization.start??0,n=t._virtualization.end??t._rows.length;if(e<i||e>=n)return;const r=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=r?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=r?.querySelector(`.cell[data-col="${t._focusCol}"]`)??r?.querySelector(".cell[data-col]")),o?{rowEl:r??null,cell:o}:void 0}(t);if(!s)return;const{rowEl:l,cell:d}=s;d.classList.add("cell-focus"),d.setAttribute("aria-selected","true"),r&&!n?.forceHorizontalScroll||function(t,e,i,n){const r=t.querySelector(".tbw-scroll-area");if(!r)return;if(n?.forceScrollLeft)return void(r.scrollLeft=0);if(n?.forceScrollRight)return void(r.scrollLeft=r.scrollWidth-r.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=r.getBoundingClientRect(),d=s.left-l.left+r.scrollLeft,a=d+s.width,c=r.scrollLeft+o.left,u=r.scrollLeft+r.clientWidth-o.right;d<c?r.scrollLeft=d-o.left:a>u&&(r.scrollLeft=a-r.clientWidth+o.right)}(t,l,d,n),function(t,e,n){if(n&&e.classList.contains(i)){const t=e.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}return}if(n){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const r=document.activeElement;r instanceof HTMLElement&&r!==t&&"function"==typeof t.contains&&t.contains(r)&&!r.classList.contains("cell")&&!r.closest(".cell")||r===t||t.focus({preventScroll:!0})}(t,d,r)}var a=/{{\s*([^}]+)\s*}}/g,c="__DG_EMPTY__",u=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,h="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(t=>t.split("").reverse().join("")),f=new RegExp(`__(proto|defineGetter|defineSetter)|${h.slice(3).join("|")}|this\\b`);new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing|math".split("|")),new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|"));function g(t,e){const i=function(t){const e=[];let i=0;for(;i<t.length;){const n=t[i];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const n=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(n,i))});continue}if("'"===n){let n="";for(i++;i<t.length&&"'"!==t[i];)n+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(n,i)});continue}if(i+2<t.length){const n=t.slice(i,i+3);if("==="===n||"!=="===n){e.push({type:"op",v:n}),i+=3;continue}}if(i+1<t.length){const n=t.slice(i,i+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){e.push({type:"op",v:n}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;e.push({type:"op",v:n}),i++}else i++}return e}(t);if(!i)return;const n=i;let r=0;function o(){return n[r]}function s(){return n[r++]}function l(t,e){const i=o();return!!i&&(i.type===t&&(void 0===e||i.v===e))}function d(){const t=function(){let t=a();for(;l("op","||");)s(),t=t||a();return t}();if(l("op","?")){s();const e=d();if(!l("op",":"))return;s();const i=d();return t?e:i}return t}function a(){let t=c();for(;l("op","&&");)s(),t=t&&c();return t}function c(){let t=u();for(;;){const e=o();if(!e||"op"!==e.type)break;if("==="===e.v)s(),t=t===u();else if("!=="===e.v)s(),t=t!==u();else if("=="===e.v)s(),t=t==u();else{if("!="!==e.v)break;s(),t=t!=u()}}return t}function u(){let t=h();for(;;){const e=o();if(!e||"op"!==e.type)break;if("<"===e.v)s(),t=t<h();else if(">"===e.v)s(),t=t>h();else if("<="===e.v)s(),t=t<=h();else{if(">="!==e.v)break;s(),t=t>=h()}}return t}function h(){let t=f();for(;;){const e=o();if(!e||"op"!==e.type)break;if("+"===e.v)s(),t+=f();else{if("-"!==e.v)break;s(),t-=f()}}return t}function f(){let t=g();for(;;){const e=o();if(!e||"op"!==e.type)break;if("*"===e.v)s(),t*=g();else if("/"===e.v)s(),t/=g();else{if("%"!==e.v)break;s(),t%=g()}}return t}function g(){return l("op","!")?(s(),!g()):w()}function w(){const t=o();if(t){if("num"===t.type)return s(),t.v;if("str"===t.type)return s(),t.v;if("id"===t.type)return s(),function(t){if("value"===t)return e.value;if(t.startsWith("row.")){const i=t.slice(4);return e.row?e.row[i]:void 0}if(t.startsWith("typeDefault.")){const i=t.slice(12);return e.typeDefault?e.typeDefault[i]:void 0}return"row"===t?e.row:"typeDefault"===t?e.typeDefault:void 0}(t.v);if("op"===t.type&&"("===t.v){s();const t=d();return l("op",")")&&s(),t}return"op"===t.type&&"-"===t.v?(s(),-w()):void 0}}const m=d();return r<n.length?void 0:m}function w(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],n=(r=t.replace(a,(t,n)=>{const r=function(t,e){if(!(t=(t||"").trim()))return c;if(m.test(t))return c;if("value"===t)return null==e.value?c:String(e.value);if(t.startsWith("row.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(4),n=e.row?e.row[i]:void 0;return null==n?c:String(n)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),n=e.typeDefault?e.typeDefault[i]:void 0;return null==n?c:String(n)}if(t.length>80)return c;if(!u.test(t)||f.test(t))return c;const i=t.match(/\./g);if(i&&i.length>1)return c;try{const i=g(t,e),n=null==i?"":String(i);return m.test(n)?c:n||c}catch{return c}}(n,e);return i.push({expr:n.trim(),result:r}),r===c?r:(o=r)&&"string"==typeof o?o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):"";var o}),r?r.replace(new RegExp(c,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):r);var r;const o=i.length&&i.every(t=>""===t.result||t.result===c);return m.test(t)||o?"":n}var m=/Reflect|Proxy|ownKeys/;function p(t){if(m.test(t)){const t=()=>"";return t.__blocked=!0,t}const e=e=>w(t,e);return e.__blocked=!1,e}function v(t){if(!t.firstElementChild)return null;const e=t.querySelector(":scope > .tbw-cell-loading-overlay");if(!e)return null;const i=t.parentElement;return i?i.insertBefore(e,t):e.remove(),e}var y=`.${n},.master-detail-toggle,.${r}`;function b(t){const e=t.options;return e?"function"==typeof e?e():e:[]}function E(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??new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}var R="__tbw_null__",C=new WeakMap;function I(t,e){let i;const n=[];let r=!1;for(const o of Array.from(t.options)){if(!o.selected)continue;if(C.has(o)){n.push(C.get(o));continue}if(e?.nullable&&o.value===R){r=!0;continue}i??=e?b(e):[];const t=i.find(t=>String(t.value)===o.value);n.push(t?t.value:o.value)}return r&&0===n.length?null:n}function _(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 E(t);case"select":return function(t){return i=>{const n=t.editorParams,r=document.createElement("select");if(t.multi&&(r.multiple=!0),t.nullable||n?.includeEmpty){const e=document.createElement("option");e.value=t.nullable?R:"",e.textContent=t.nullable?n?.emptyLabel??"(Blank)":n?.emptyLabel??"",null==i.value&&(e.selected=!0),r.appendChild(e)}b(t).forEach(e=>{const n=document.createElement("option");n.value=String(e.value),n.textContent=e.label,C.set(n,e.value),t.multi&&Array.isArray(i.value)&&i.value.includes(e.value)?n.selected=!0:t.multi||i.value!==e.value||(n.selected=!0),r.appendChild(n)});const o=()=>{if(t.multi){const n=I(r,t);if(M((0,e.readCellField)(i.row,i.field),n))return;i.commit(n)}else t.nullable&&r.value===R?i.commit(null):i.commit(r.value)};return r.addEventListener("change",o),r.addEventListener("blur",o),r.addEventListener("keydown",t=>{"Escape"===t.key&&i.cancel()}),r}}(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 S(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function k(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return t instanceof HTMLSelectElement&&t.multiple?I(t,e):t instanceof HTMLSelectElement&&e?.nullable&&t.value===R?null:""===t.value||"number"!==e?.type&&"number"!=typeof i?null==i&&""===t.value?e?.nullable?null:"":t.value:Number(t.value)}(t,e,i);switch(t.type){case"checkbox":return t.checked;case"number":return S(t.value,e);case"date":return function(t,e,i){return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||(new Date).toISOString().slice(0,10):i??new Date}(t,e,i);default:return function(t,e,i){return"number"==typeof i?S(t.value,e):""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}(t,e,i)}}function x(t,e,i){t instanceof HTMLSelectElement?function(t,e,i){t.multiple?function(t,e,i){const n=Array.isArray(e)?e:null==e?[]:[e];for(const r of Array.from(t.options))if(C.has(r)){const t=C.get(r);r.selected=n.some(e=>e===t)}else A(r,i)?r.selected=null==e:r.selected=n.some(t=>String(t)===r.value)}(t,e,i):null==e&&Array.from(t.options).some(t=>A(t,i))?t.value=R:t.value=String(e??"")}(t,e,!!i?.nullable):t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t instanceof HTMLInputElement&&"date"===t.type&&e instanceof Date?t.valueAsDate=e:t instanceof HTMLInputElement&&"date"===t.type&&"string"==typeof e?t.value=e.split("T")[0]:t.value=String(e??"")}function A(t,e){return e&&t.value===R&&!C.has(t)}function M(t,e){if(Array.isArray(t)&&Array.isArray(e)){const i=new Set(t),n=new Set(e);return i.size===n.size&&[...n].every(t=>i.has(t))}return t===e}var L=class{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let n=this.#t.get(t);n||(n=new Map,this.#t.set(t,n)),n.set(e,i),this.#e(t,e,!0)}clearInvalid(t,e){const i=this.#t.get(t);i&&(i.delete(e),0===i.size&&this.#t.delete(t)),this.#e(t,e,!1)}clearRowInvalid(t){const e=this.#t.get(t);if(e){const i=Array.from(e.keys());this.#t.delete(t),i.forEach(e=>this.#e(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#t.entries());this.#t.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#e(t,i,!1))})}isCellInvalid(t,e){return this.#t.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#t.get(t)?.get(e)}hasInvalidCells(t){const e=this.#t.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#t.get(t)??[])}};function G(t,e,i){const n=t.get(e);return!!n&&!D(n,i)}function D(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(!D(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),o=Object.keys(n);if(r.length!==o.length)return!1;for(const t of r)if(!D(i[t],n[t]))return!1;return!0}return!1}function T(t,e,i){t.set(e,structuredClone(i))}function F(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,o=i;for(const s of Object.keys(r))o[s]=r[s];return!0}var q=class{baselines=new Map;baselinesWereCaptured=!1;newRowIds=new Set;changedRowIds=new Set;committedDirtyRowIds=new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;return function(t,e,i){for(const n of e)if(!0!==n?.__loading)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0,!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return G(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&&G(this.baselines,e,i))return!0}return!1}isCellDirty(t,i,n){return function(t,i,n,r){const o=t.get(i);return!!o&&!D((0,e.readCellField)(o,r),(0,e.readCellField)(n,r))}(this.baselines,t,i,n)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&G(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){T(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,i,n){const r=this.baselines.get(t);r&&(0,e.writeCellField)(r,i,n)}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&&T(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&&G(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&&G(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=F(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&&F(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}};var P='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function $(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function V(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function H(t){}var W=new WeakMap;function O(t,e){const i=t.onBeforeEditClose;if(!i)return!1;let n=W.get(e);const r=n?.get(i);if(void 0!==r)return r;const o=!1===i(e);return n||W.set(e,n=new Map),n.set(i,o),o}function N(t,e){if(!t)return!1;const i=e.querySelectorAll('[aria-expanded="true"][aria-controls]');for(let n=0;n<i.length;n++){const r=i[n].getAttribute("aria-controls");if(!r)continue;const o=e.ownerDocument?.getElementById(r);if(o&&o.contains(t))return!0}return!1}var z=new WeakMap;function j(t,e){if(!e)return!1;const i=z.get(t);if(i&&(i.contains(e)||e.contains(i)))return!0;const n=function(t,e){const i=t.composedPath?.()??[];if(!i.includes(e))return!1;for(const n of i){if(n===e)return!1;const t=n;if("true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute("aria-controls"))return!0}return!1}(t,e)||N(t.target,e);return n&&z.set(t,e),n}function K(t,i,n,r,o,s,l,d){if(!r.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:f}=t;let g;try{g=a.getRowId?.(i)}catch{}const w=g?t=>a.updateRow(g,t,"cascade"):H,m=V(r.field)?(0,e.readCellField)(i,r.field):void 0;s.classList.add("editing"),h.add(`${n}:${o}`);const p=d??s.parentElement;p&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(p);let y=!1;const b=e=>{if(y||!c&&!t.isEditSessionActive())return;const o=g?a._getRowEntry(g):void 0,s=o?.row??i,l=o?.index??n;t.commitCellValue(l,r,e,s)},E=()=>{if(y=!0,V(r.field)){const t=(g?a._getRowEntry(g):void 0)?.row??i;(0,e.writeCellField)(t,r.field,m)}},R=document.createElement("div");R.className="tbw-editor-host";const C=v(s);s.firstElementChild&&a.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.appendChild(R),C&&s.appendChild(C),R.addEventListener("keydown",e=>{if(!e.defaultPrevented){if("Enter"===e.key){const t=e.target;if(t&&"true"===t.getAttribute?.("aria-expanded")&&t.hasAttribute?.("aria-controls"))return}if("Enter"===e.key){const i=e.target,o=$(i);if(o&&o!==i)return;if(c){e.preventDefault();const t=R.querySelector("input,textarea,select");return void(t&&b(k(t,r,m)))}if(O(u,e))return;e.stopPropagation(),e.preventDefault(),t.exitRowEdit(n,!1),y=!0}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(j(e,R))return;if(O(u,e))return;e.stopPropagation(),e.preventDefault(),E(),t.exitRowEdit(n,!0)}}});const I=r,S=I.__editorTemplate,A=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const i=n.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(a,I)??_(r),M=m,L=`${n}:${r.field}`,G=[];f.set(L,t=>{for(const e of G)e(t)});const D=t=>{G.push(t)};if("template"===A&&S)!function(t,e,i,n,r,o,s,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:n,value:r,field:i.field,column:i,commit:o,cancel:s}):c.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!V(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!r:h.value=String(r??"");let n=!1;h.addEventListener("blur",()=>{n||o(k(h,i,r))}),h.addEventListener("keydown",l=>{const a=l;if("Enter"===a.key){if(O(t.config,a))return;a.stopPropagation(),a.preventDefault(),n=!0,o(k(h,i,r)),t.exitRowEdit(d,!1)}if("Escape"===a.key){if(j(a,e))return;if(O(t.config,a))return;a.stopPropagation(),a.preventDefault(),s(),t.exitRowEdit(d,!0)}}),h instanceof HTMLInputElement&&"checkbox"===h.type&&h.addEventListener("change",()=>o(h.checked)),l||setTimeout(()=>h.focus({preventScroll:!0}),0)}e.appendChild(c)}(t,R,I,i,m,b,E,l,n),D(t=>{const e=R.querySelector("input,textarea,select");if(!e)return;const i=e instanceof HTMLSelectElement&&e.multiple,n=t instanceof Date&&e instanceof HTMLInputElement&&"date"===e.type;(i||n||null==t||"object"!=typeof t)&&x(e,t,r)});else if("string"==typeof A){const t=document.createElement(A);t.value=M,t.addEventListener("change",()=>b(t.value)),D(e=>{t.value=e}),R.appendChild(t),l||queueMicrotask(()=>{R.querySelector(P)?.focus({preventScroll:!0})})}else if("function"==typeof A){const e=A({row:i,rowId:g??"",value:M,field:r.field,column:r,commit:b,cancel:E,updateRow:w,onValueChange:D,grid:t.grid});"string"==typeof e?(R.innerHTML=e,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(k(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(k(r,e,n))))}(R,r,b,m),D(t=>{const e=R.querySelector("input,textarea,select");e&&x(e,t,r)})):e instanceof Node?(R.appendChild(e),e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?D(t=>x(e,t,r)):s.setAttribute("data-editor-managed","")):!e&&R.hasChildNodes()&&s.setAttribute("data-editor-managed",""),l||queueMicrotask(()=>{R.querySelector(P)?.focus({preventScroll:!0})})}else if(A&&"object"==typeof A){const e=document.createElement("div");e.setAttribute("data-external-editor",""),e.setAttribute("data-field",r.field),R.appendChild(e),s.setAttribute("data-editor-managed","");const n={row:i,rowId:g??"",value:M,field:r.field,column:r,commit:b,cancel:E,updateRow:w,onValueChange:D,grid:t.grid};if(A.mount)try{A.mount({placeholder:e,context:n,spec:A})}catch(N){T="TBW080",F=`External editor mount error for column '${r.field}': ${N}`,q=t.grid.id,console.warn(function(t,e,i,n){return`${function(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}(i,n)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}(T,F,q,W))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:e,spec:A,context:n}}))}var T,F,q,W;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(P);e&&(e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")||e.hasAttribute("title")||e.id&&t.querySelector(`label[for="${CSS.escape(e.id)}"]`)||e.closest("label")||e.setAttribute("aria-label",i))})}(R,r)}var B=class extends e.BaseGridPlugin{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t||"function"==typeof t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"},{type:"cell-edit-reverted",description:"Emitted when row values are rolled back in place (revertRow/revertAll, row-edit cancel, grid-mode Escape) — not recorded as history"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"},{type:"getCellEditableResolver",description:"Returns a predicate (field, row) => boolean resolving per-cell editability (rowEditable gate + column.editable true/false/function), for consumers like clipboard paste"},{type:"commitCellValue",description:"Commits a single cell value coming from a core row mutation (updateRow/updateRows), running the full edit pipeline: cancelable cell-commit (validation/abortion), dirty tracking, history, and cascade. Returns true (applied), false (vetoed), or undefined (not handled)."}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg:var(--tbw-color-selection);--tbw-editing-row-bg:var(--tbw-editing-bg);--tbw-editing-border:var(--tbw-border-input,1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input:var(--tbw-cell-padding-input,2px 6px);--tbw-font-size-editor:inherit;--tbw-editing-row-outline-color:var(--tbw-color-accent);--tbw-editing-row-outline-width:1px}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{min-height:max(var(--tbw-row-height), calc(1lh + 2 * var(--tbw-cell-padding-v,.25em) + var(--tbw-border-width,1px)));justify-content:center;align-items:center;padding:0;display:flex;overflow:hidden}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{border:var(--tbw-editing-border);width:100%;min-width:0;height:100%;padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor);flex:auto;align-self:stretch}tbw-grid .tbw-editor-host{display:contents}tbw-grid{--tbw-invalid-bg:light-dark(#fef2f2,#450a0a);--tbw-invalid-border-color:light-dark(#ef4444,#f87171)}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#i(){return"grid"===this.config.mode}#n(t,e){const i=this.#r.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:n}=t;return"function"==typeof n?n(e):!0===n}#o(t){return!0===t.editable||"function"==typeof t.editable}#s=-1;#l;#d;#a=-1;#c=new Map;#u=new Set;#h=new WeakSet;#f=new Map;#g=!1;#w=-1;#m;#p=!1;#v=!1;#y=!1;#b=null;#E=new q;#R=new Set;#C;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;this.#m=new L((t,e,i)=>{this.#I(t,e,i)}),this.#C={grid:i,isGridMode:this.#i,config:this.config,editingCells:this.#u,editorValueCallbacks:this.#f,isEditSessionActive:()=>-1!==this.#s,commitCellValue:(t,e,i,n)=>this.#_(t,e,i,n),exitRowEdit:(t,e)=>this.#S(t,e)},this.#k(),Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),Object.defineProperty(t,"_changedRowIdSet",{get:()=>this.#E.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),this.#x(e,i),this.#i&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.#A(e,i))}#x(t,e){if(document.addEventListener("keydown",t=>{if(!this.#i&&"Escape"===t.key&&-1!==this.#s){if(j(t,e.findRenderedRowElement?.(this.#s)))return;if(O(this.config,t))return;this.#S(this.#s,!0)}},{capture:!0,signal:t}),document.addEventListener("mousedown",t=>{if(this.#i)return;if(-1===this.#s)return;const i=e.findRenderedRowElement?.(this.#s);if(!i)return;if((t.composedPath&&t.composedPath()||[]).includes(i))return;const n=t.target;if(!n||this.gridElement.contains(n)||!this.grid.containsFocus?.(n)){if(n&&!this.gridElement.contains(n)){const t=e.findRenderedRowElement?.(this.#s);if(t&&N(n,t))return}O(this.config,t)||queueMicrotask(()=>{-1!==this.#s&&this.#S(this.#s,!1)})}},{signal:t}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#i)return;if(-1===this.#s)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#s&&this.#M()})},{signal:t}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#f.get(i);n&&n(e.newValue)},{signal:t}),this.config.dirtyTracking){const e=t=>{const e=t.detail?.action;if(!e)return;const i="compound"===e.type?e.actions:[e],n=new Set;for(const r of i){const t=void 0!==r.rowId?this.#r._getRowEntry(r.rowId)?.row:this.rows[r.rowIndex];if(!t)continue;const e=r.rowId??this.#L(t);if(!e||n.has(e))continue;n.add(e);const i=this.#E.isRowDirty(e,t);this.#G(e,t,i?"modified":"pristine")}};this.gridElement.addEventListener("undo",e,{signal:t}),this.gridElement.addEventListener("redo",e,{signal:t}),this.on("row-inserted",t=>{const e=this.#L(t.row);null!=e&&this.markAsNew(String(e))}),this.on("datasource:data",t=>{this.#D(t.rows)&&this.requestAfterRender()})}}#D(t){const e=this.#r;return!!e.getRowId&&this.#E.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}})}#A(t,i){this.gridElement.addEventListener("focusin",t=>{const n=t.target;if(n!==this.gridElement&&n.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return n.blur(),void this.gridElement.focus();const t=i._focusRow,r=i._focusCol,o=this.#b;if(!o||o.rowIndex!==t||o.colIndex!==r){const n=i._visibleColumns?.[r],o=i._rows?.[t];if(n?.field&&o){const i=n.field;this.#b={rowIndex:t,colIndex:r,field:i,value:(0,e.readCellField)(o,i)}}}this.#p=!0}},{signal:t}),this.gridElement.addEventListener("focusout",t=>{const e=t.target,i=t.relatedTarget;if(e&&i){if(e.contains(i))return;const t=$(i);if(t&&t!==this.gridElement&&this.gridElement.contains(t))return}i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')||(this.#p=!1,this.#b=null)},{signal:t}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#p){if(O(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#T()});this.#T(),t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:t}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')&&(this.#v=!1)},{signal:t})}detach(){this.#r._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#c.clear(),this.#E.clear(),this.#u.clear(),this.#f.clear(),this.#p=!1,this.#v=!1,this.#b=null,this.#y=!1,this.#h=new WeakSet,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#i||-1!==this.#s;if("getCellEditableResolver"===t.type){const t=this.#r.effectiveConfig?.columns??[],e=new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const n=e.get(t);return!!n&&this.#n(n,i)}}return"commitCellValue"===t.type?this.#F(t.context):void 0}#F(t){const i=this.#r,n=(i._visibleColumns??[]).find(e=>e.field===t.field)??i._columns?.find(e=>e.field===t.field),r=t.row??(null!=t.rowId?i._getRowEntry(t.rowId)?.row:void 0)??i._rows?.[t.rowIndex];if("sync"===t.source){if(!r||!V(t.field))return;(0,e.writeCellField)(r,t.field,t.newValue),(0,e.invalidateAccessorCache)(r);const i=this.#L(r);if(i&&this.config.dirtyTracking){this.#E.rebaselineCell(i,t.field,t.newValue);const e=this.#E.isRowDirty(i,r);e||this.#E.changedRowIds.delete(i),this.#G(i,r,e?"modified":"pristine")}return!0}if(n&&r&&V(t.field)){if("history"===t.source){(0,e.writeCellField)(r,t.field,t.newValue),(0,e.invalidateAccessorCache)(r);const i=this.#L(r);if(i&&this.config.dirtyTracking){const t=this.#E.isRowDirty(i,r);t||this.#E.changedRowIds.delete(i),this.#G(i,r,t?"modified":"pristine")}return!0}return this.#_(t.rowIndex,n,t.newValue,r,t.source),(0,e.readCellField)(r,t.field)===t.newValue}}onCellClick(t){if(this.#i)return!1;const e=this.#r,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t;return(r!==this.#s||!t.cellEl.classList.contains("editing"))&&(!function(t){return!!t.target?.closest?.(y)}(t.originalEvent)&&(!!e._columns?.some(t=>this.#o(t))&&(!!this.#q(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))))}onKeyDown(t){switch(t.key){case"Escape":return this.#P(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#$(t);case"Tab":return this.#V(t);case" ":case"Spacebar":return this.#H(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#W(t);case"F2":return this.#O(t);default:return!1}}#P(t){return this.#i&&this.#p?(this.#T(),this.requestAfterRender(),!0):-1!==this.#s&&!this.#i&&(j(t,this.#r.findRenderedRowElement?.(this.#s))||O(this.config,t)||this.#S(this.#s,!0),!0)}#$(t){const e=$(t.target),i=!!e&&e!==this.gridElement,n="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#i&&!this.#p&&!i)&&(!(!this.#i||!this.#p&&!i||!n)||!(!n||-1===this.#s||this.#i))}#V(t){return!(-1===this.#s&&!this.#i)&&(t.preventDefault(),this.#y?(this.#S(this.#s,!1),!0):(this.#N(!t.shiftKey),!0))}#H(t){if(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;if(-1!==this.#s)return!1;const i=this.#r,n=i._focusRow,r=i._focusCol;if(n<0||r<0)return!1;const o=i._visibleColumns[r],s=i._rows[n];if(!o||!s||"boolean"!==o.type)return!1;if(!this.#n(o,s))return!1;const l=o.field;return!!V(l)&&(this.#_(n,o,!(0,e.readCellField)(s,l),s),t.preventDefault(),this.requestRender(),!0)}#W(t){if(this.#i&&!this.#p)return this.#M(),!0;if(this.#i&&this.#p)return this.#z(t);if(-1!==this.#s){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!O(this.config,t)}return this.#j(t)}#z(t){const e=$(t.target);if(e&&e!==t.target)return!0;this.#b=null;const i=document.activeElement;return i&&this.gridElement.contains(i)&&(i.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0,this.requestAfterRender(),!0}#j(t){const i=this.#r,n=this.config.editOn??i.effectiveConfig?.editOn;if(!1===n||"manual"===n)return!1;const r=i._focusRow,o=i._focusCol;if(r<0)return!1;const s=i._columns?.some(t=>this.#o(t)),l=i._rows[r];if(!s||!this.#q(l))return!1;const d=i._visibleColumns[o]?.field??"",a=d&&l?(0,e.readCellField)(l,d):void 0,c=this.gridElement.querySelector(`[data-row="${r}"][data-col="${o}"]`),u=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:r,colIndex:o,field:d,value:a,row:l,cellEl:c,trigger:"keyboard",originalEvent:t}});return this.gridElement.dispatchEvent(u),u.defaultPrevented?(t.preventDefault(),!0):(this.beginBulkEdit(r),!0)}#O(t){if(-1!==this.#s||this.#i)return!1;const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,n=e._focusCol;if(i<0||n<0)return!1;const r=e._visibleColumns[n],o=e._rows[i];return!!(r&&o&&r.field)&&(!!this.#n(r,o)&&(t.preventDefault(),this.beginCellEdit(i,r.field),!0))}#K(t){const e={};for(const i of Array.from(t.attributes)){if(!i.name.startsWith("data-"))continue;const t=i.name.slice(5).replace(/-([a-z])/g,(t,e)=>e.toUpperCase()).trim();t&&(e[t]=i.value)}return e}#B(){const t=this.#r,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const n=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!n.length)return;const r=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<n.length;s++){const t=n[s],e=t.getAttribute("name")?.trim();if(!e)continue;const i=o[e];if(i?.editor)continue;const l=t.querySelector("tbw-grid-column-editor"),d=l??t;let a=r?.canHandle?.(d)?r.createEditor?.(d):void 0;if(!a&&l){const e=this.#K(t),i=p(l.innerHTML);a=t=>i({row:t.row,value:t.value,field:t.field,column:t.column,typeDefault:e})}a&&(o[e]={...i??{},editor:a})}}processColumns(t){const e=this.#r;this.#B();const i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter,r=!!i||!!n?.getTypeDefault;return t.map(t=>{const o=t.__element;if(o&&!this.#h.has(o)){this.#h.add(o),null==t.editable&&o.hasAttribute("editable")&&(t.editable="false"!==o.getAttribute("editable"));const e=t;if(!e.__editorTemplate){const t=o.querySelector("tbw-grid-column-editor");t&&(e.__editorTemplate=t)}}if(!t.type||!r)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&n?.getTypeDefault){const i=n.getTypeDefault(t.type,e._hostElement);i?.editorParams&&(s=i.editorParams)}return s?{...t,editorParams:{...s,...t.editorParams}}:t})}processRows(t){if(this.config.dirtyTracking&&this.#D(t),-1===this.#s||this.#i)return t;const e=this.#l,i=this.#d;if(!e||!i)return t;const n=[...t];let r=-1;for(let o=0;o<n.length;o++)if(this.#L(n[o])===e){r=o;break}return-1===r?(setTimeout(()=>this.cancelActiveRowEdit(),0),n):(n[r]=i,this.#s!==r&&this.#U(this.#s,r),n)}afterRender(){const t=this.#r;if(-1!==this.#s&&this.#d&&!this.#i&&t._rows[this.#s]!==this.#d){const e=t._rows.indexOf(this.#d);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#U(this.#s,e)}if(this.#g&&(this.#g=!1,this.#Y(t)),-1!==this.#w){const e=this.#w;this.#w=-1,t.animateRow?.(e,"change")}const e=this.#E.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#i&&0!==this.#u.size)for(const i of this.#u){const[e,n]=i.split(":"),r=parseInt(e,10),o=parseInt(n,10),s=this.#X(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],d=t._visibleColumns[o];l&&d&&this.#Z(l,r,d,o,s,!0)}}afterCellRender(t){const{row:i,rowIndex:n,column:r,colIndex:o,cellElement:s}=t,l=this.#n(r,i);if(l)s.removeAttribute("aria-readonly");else if(s.setAttribute("aria-readonly","true"),this.#i&&s.classList.contains("editing")){s.classList.remove("editing");const t=(0,e.readCellField)(i,r.field);s.textContent=null==t?"":String(t)}this.#i&&l&&(s.classList.contains("editing")||this.#Z(i,n,r,o,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#r.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:n,hasBaseline:r}=this.#E.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",n),o.classList.toggle("tbw-row-new",i),r){const i=o.querySelectorAll(".cell[data-field]");for(let n=0;n<i.length;n++){const r=i[n],o=r.getAttribute("data-field");o&&r.classList.toggle("tbw-cell-dirty",this.#E.isCellDirty(e,t.row,o))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#E.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#E.getChangedRowIds()}get activeEditRow(){return this.#s}get activeEditCol(){return this.#a}isRowEditing(t){return this.#s===t}isCellEditing(t,e){return this.#u.has(`${t}:${e}`)}isRowChanged(t){const e=this.#r,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#E.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#E.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#E.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#E.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.#r;return this.#E.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#E.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#E.markDirty(t),this.#G(t,e,"modified"))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#E.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#E.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#r;return this.#E.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#E.revertRow(t,e)&&(this.#G(t,e,"reverted"),this.emitPluginEvent("cell-edit-reverted",{rowId:t}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.revertAll(e=>t._getRowEntry(e)?.row),this.emitPluginEvent("cell-edit-reverted",{}),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#k(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#r._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#r,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n],o=i._rows[t];if(!r||!o||!this.#n(r,o))return;const s=this.#X(t,n);s&&(this.#y=!0,this.#Q(t,n,s))}beginBulkEdit(t){const e=this.#r;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;if(!e._columns?.some(t=>this.#o(t)))return;const i=e.findRenderedRowElement?.(t);if(!i)return;const n=e._rows[t];this.#q(n)&&(this.#y=!1,this.#J(t,n),Array.from(i.children).forEach((i,r)=>{const o=e._visibleColumns[r];if(o&&this.#n(o,n)){const e=i;e.classList.contains("editing")||this.#Z(n,t,o,r,e,!0)}}),setTimeout(()=>{let t=i.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=i.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(P);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#s&&this.#S(this.#s,!1)}cancelActiveRowEdit(){-1!==this.#s&&this.#S(this.#s,!0)}#L(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#X(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#q(t){if(!t)return!0;const e=this.#r.effectiveConfig?.rowEditable;return!e||!1!==e(t)}#G(t,e,i){this.emit("dirty-change",{rowId:t,row:e,original:this.#E.getOriginalRow(t),type:i})}#T(){this.#tt();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#et(t,e,i){i&&(Object.keys(i).forEach(t=>{e[t]=i[t]}),t&&(this.#E.changedRowIds.delete(t),this.#E.committedDirtyRowIds.delete(t),this.clearRowInvalid(t)),this.emitPluginEvent("cell-edit-reverted",{rowId:t}))}#I(t,e,i){const n=this.#r,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows?.findIndex(e=>this.#L(e)===t);if(-1===s||void 0===s)return;const l=this.#X(s,r);if(l)if(i){l.setAttribute("data-invalid","true"),l.setAttribute("aria-invalid","true");const i=this.#m.getInvalidMessage(t,e);i&&(l.setAttribute("title",i),l.removeAttribute(o))}else l.removeAttribute("data-invalid"),l.removeAttribute("aria-invalid"),l.removeAttribute("title")}#U(t,e){this.#s=e;const i=new Set,n=`${t}:`;for(const s of this.#u)s.startsWith(n)?i.add(`${e}:${s.substring(n.length)}`):i.add(s);this.#u.clear();for(const s of i)this.#u.add(s);const r=this.#c.get(t);void 0!==r&&(this.#c.delete(t),this.#c.set(e,r));const o=[];for(const[s,l]of this.#f)s.startsWith(n)&&(o.push([`${e}:${s.substring(n.length)}`,l]),this.#f.delete(s));for(const[s,l]of o)this.#f.set(s,l);this.#k()}#Q(t,e,i){const n=this.#r,r=n._rows[t],o=n._visibleColumns[e];r&&o&&this.#n(o,r)&&(i.classList.contains("editing")||(this.#s!==t&&this.#J(t,r),this.#a=e,this.#Z(r,t,o,e,i,!1)))}#tt(){const t=this.#b;if(!t)return;const i=this.#r._rows?.[t.rowIndex];i&&((0,e.writeCellField)(i,t.field,t.value),this.emitPluginEvent("cell-edit-reverted",{rowId:this.#L(i)}));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){const t=this.#L(i);t&&(this.config.dirtyTracking?this.#E.isRowDirty(t,i)||(this.#E.changedRowIds.delete(t),this.#G(t,i,"reverted")):this.#E.changedRowIds.delete(t))}this.requestRender(),this.#b=null}#M(){const t=this.#r,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=this.#X(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(P);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#N(t){const e=this.#r,i=e._rows,n=this.#i?e._focusRow:this.#s,r=i[n],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;const s=o.indexOf(e._focusCol)+(t?1:-1);if(s>=0&&s<o.length){e._focusCol=o[s];const t=this.#X(n,o[s]);return t?.classList.contains("editing")&&t.querySelector(P)?.focus({preventScroll:!0}),void d(e,{forceHorizontalScroll:!0})}const l=n+(t?1:-1);if(l>=0&&l<i.length){const r=i[l],o=e._visibleColumns.map((t,e)=>r&&this.#n(t,r)?e:-1).filter(t=>t>=0);if(0===o.length)return;this.#i?(e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],d(e,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=this.#X(l,e._focusCol);t?.classList.contains("editing")&&t.querySelector(P)?.focus({preventScroll:!0})},0)):(this.#S(n,!1),e._focusRow=l,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(l),d(e,{forceHorizontalScroll:!0}))}}#k(){const t=this.#r;t._activeEditRows=this.#s,t._rowEditSnapshots=this.#c}#J(t,e){this.#s!==t&&(-1!==this.#s&&this.#S(this.#s,!1),this.#c.set(t,{...e}),this.#s=t,this.#d=e,this.#l=this.#L(e),this.#k(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#l??"",row:e}),s(this.gridElement,l(this.gridElement,"editingStarted",t))))}#S(t,e){if(this.#s!==t)return;const i=this.#r,n=this.#c.get(t),r=i.findRenderedRowElement?.(t),{rowId:o,current:d}=this.#it(t);!e&&r&&d&&this.#nt(r,t,d),e||this.#i||!d||this.emit("before-edit-close",{rowIndex:t,rowId:o??"",row:d}),e&&d?this.#et(o,d,n):!e&&d&&this.#rt(t,o,d,n),this.#ot(t),this.#g=!0,r?this.#st(r,i):(this.#Y(i),this.#g=!1),!this.#i&&d&&(this.broadcast("edit-close",{rowIndex:t,rowId:o??"",row:d,reverted:e}),e||s(this.gridElement,l(this.gridElement,"editingCommitted",t)))}#it(t){const e=this.#r;let i=this.#l;const n=(i?e._getRowEntry(i):void 0)?.row??this.#d??e._rows[t];return!i&&n&&(i=this.#L(n)),{rowId:i,current:n}}#nt(t,i,n){const r=this.#r;t.querySelectorAll(".cell.editing").forEach(t=>{const o=Number(t.getAttribute("data-col"));if(isNaN(o))return;const s=r._visibleColumns[o];if(!s)return;if(t.hasAttribute("data-editor-managed"))return;const l=t.querySelector("input,textarea,select");if(!l)return;const d=s.field,a=(0,e.readCellField)(n,d),c=k(l,s,a);M(a,c)||this.#_(i,s,c,n)})}#rt(t,e,i,n){const r=function(t,e){if(!t)return!1;const i=t,n=e,r=new Set([...Object.keys(i),...Object.keys(n)]);for(const o of r)if(i[o]!==n[o])return!0;return!1}(n,i),o=e?this.#E.changedRowIds.has(e):r;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:n,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?n&&this.#et(e,i,n):(e&&this.config.dirtyTracking&&(this.#E.isRowDirty(e,i)?this.#E.committedDirtyRowIds.add(e):this.#E.committedDirtyRowIds.delete(e)),r&&this.isAnimationEnabled&&(this.#w=t))}#ot(t){this.#c.delete(t),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#y=!1,this.#k();for(const e of this.#u)e.startsWith(`${t}:`)&&this.#u.delete(e);for(const e of this.#f.keys())e.startsWith(`${t}:`)&&this.#f.delete(e)}#st(t,e){const i=e.__frameworkAdapter,n=t.querySelectorAll(".cell.editing");i?.releaseCell&&n.forEach(t=>{const e=v(t);i.releaseCell(t),e&&t.appendChild(e)}),n.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#_(t,i,n,r,o="user"){const s=i.field;if(!V(s))return;const l=(0,e.readCellField)(r,s);if(l===n)return;const d=this.#r,a=this.#L(r),c=!a||!this.#E.changedRowIds.has(a),u=a?t=>this.grid.updateRow(a,t,"cascade"):H;let h=!1;const f=a?t=>{h=!0,this.setInvalid(a,s,t??"")}:()=>{},g=`${a??t}\0${s}`;if(this.#R.has(g))return;let w=!1;this.#R.add(g);try{w=this.emitCancelable("cell-commit",{row:r,rowId:a??"",field:s,oldValue:l,value:n,source:o,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:u,setInvalid:f})}finally{this.#R.delete(g)}if(w)return;if(a&&!h&&this.isCellInvalid(a,s)&&this.clearInvalid(a,s),(0,e.writeCellField)(r,s,n),(0,e.invalidateAccessorCache)(r),a&&this.#E.changedRowIds.add(a),this.#k(),this.config.dirtyTracking&&a){const t=this.#E.isRowDirty(a,r);this.#G(a,r,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,rowId:a,field:s,oldValue:l,newValue:n});const m=d.findRenderedRowElement?.(t);m&&m.classList.add("changed")}#Z(t,e,i,n,r,o,s){K(this.#C,t,e,i,n,r,o,s)}#Y(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{}})}};t.EditingPlugin=B,t.defaultEditorFor=_});
|
|
2
2
|
//# sourceMappingURL=editing.umd.js.map
|