@toolbox-web/grid 3.9.1 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all.js +1 -1
- package/all.js.map +1 -1
- package/custom-elements.json +2 -2
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +8 -4
- package/lib/core/plugin/base-plugin.d.ts +7 -0
- package/lib/core/types.d.ts +2 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/context-menu/context-menu-plugin.d.ts +9 -4
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/context-menu/types.d.ts +8 -4
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +2 -1
- package/lib/plugins/filtering/filter-model.d.ts +2 -1
- package/lib/plugins/filtering/filtering-plugin.d.ts +5 -2
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +7 -14
- package/lib/plugins/grouping-rows/grouping-rows.d.ts +48 -0
- package/lib/plugins/grouping-rows/index.d.ts +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/grouping-rows/types.d.ts +21 -0
- package/lib/plugins/master-detail/index.d.ts +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 +28 -6
- package/lib/plugins/master-detail/master-detail.d.ts +0 -8
- package/lib/plugins/master-detail/types.d.ts +25 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/selection-plugin.d.ts +8 -1
- package/lib/plugins/server-side/datasource-types.d.ts +28 -0
- package/lib/plugins/server-side/datasource.d.ts +7 -0
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/server-side/server-side-plugin.d.ts +61 -8
- package/lib/plugins/server-side/types.d.ts +9 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/tree-plugin.d.ts +5 -11
- package/lib/plugins/tree/types.d.ts +22 -6
- package/lib/plugins/undo-redo/history.d.ts +2 -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 +13 -1
- package/lib/plugins/undo-redo/undo-redo-plugin.d.ts +15 -2
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/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){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 v="__tbw_null__";function y(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 p(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?v:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const r=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===v?e.commit(null):e.commit(n.value)};return n.addEventListener("change",r),n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function b(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function E(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return""===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 b(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?b(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)}}var R=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 C(t,e,i){const n=t.get(e);return!!n&&!I(n,i)}function I(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(!I(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(!I(i[t],n[t]))return!1;return!0}return!1}function _(t,e,i){t.set(e,structuredClone(i))}function k(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 S=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;!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)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return C(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&&C(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&&!I((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)&&C(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){_(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&&_(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&&C(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&&C(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=k(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&&k(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 x='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function A(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function M(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function L(t){}function G(t,e){return!1===t.onBeforeEditClose?.(e)}function D(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"):L,p=M(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 b=!1;const R=e=>{if(b||!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)},C=()=>{if(b=!0,M(r.field)){const t=(g?a._getRowEntry(g):void 0)?.row??i;(0,e.writeCellField)(t,r.field,p)}},I=document.createElement("div");I.className="tbw-editor-host";const _=m(s);s.firstElementChild&&a.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.appendChild(I),_&&s.appendChild(_),I.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=A(i);if(o&&o!==i)return;if(c){e.preventDefault();const t=I.querySelector("input,textarea,select");return void(t&&R(E(t,r,p)))}if(G(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(n,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(G(u,e))return;e.stopPropagation(),e.preventDefault(),C(),t.exitRowEdit(n,!0)}}});const k=r,S=k.__editorTemplate,D=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)??y(r),T=p,F=`${n}:${r.field}`,q=[];f.set(F,t=>{for(const e of q)e(t)});const P=t=>{q.push(t)};if("template"===D&&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(!M(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(E(h,i,r))}),h.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(G(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,o(E(h,i,r)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(G(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,I,k,i,p,R,C,l,n),P(t=>{if(null!=t&&"object"==typeof t)return;const e=I.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof D){const t=document.createElement(D);t.value=T,t.addEventListener("change",()=>R(t.value)),P(e=>{t.value=e}),I.appendChild(t),l||queueMicrotask(()=>{I.querySelector(x)?.focus({preventScroll:!0})})}else if("function"==typeof D){const e=D({row:i,rowId:g??"",value:T,field:r.field,column:r,commit:R,cancel:C,updateRow:w,onValueChange:P,grid:t.grid});"string"==typeof e?(I.innerHTML=e,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(E(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(E(r,e,n))))}(I,r,R,p),P(t=>{const e=I.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):e instanceof Node?(I.appendChild(e),e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?P(t=>{e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??"")}):s.setAttribute("data-editor-managed","")):!e&&I.hasChildNodes()&&s.setAttribute("data-editor-managed",""),l||queueMicrotask(()=>{I.querySelector(x)?.focus({preventScroll:!0})})}else if(D&&"object"==typeof D){const e=document.createElement("div");e.setAttribute("data-external-editor",""),e.setAttribute("data-field",r.field),I.appendChild(e),s.setAttribute("data-editor-managed","");const n={row:i,rowId:g??"",value:T,field:r.field,column:r,commit:R,cancel:C,updateRow:w,onValueChange:P,grid:t.grid};if(D.mount)try{D.mount({placeholder:e,context:n,spec:D})}catch(N){$="TBW080",V=`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,O,W))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:e,spec:D,context:n}}))}var $,V,O,W;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(x);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))})}(I,r)}var T=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)"}],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 S;#R=new Set;#C;get#r(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#r;this.#m=new R((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.#k(t,e)},this.#S(),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(G(this.config,t))return;this.#k(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}G(this.config,t)||queueMicrotask(()=>{-1!==this.#s&&this.#k(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=this.rows[e.rowIndex];if(!i)return;const n=this.#L(i);if(!n)return;const r=this.#E.isRowDirty(n,i);this.#G(n,i,r?"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))})}}#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=A(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(G(this.config,t))return void queueMicrotask(()=>{this.#p&&this.#D()});this.#D(),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.#T(t.context):void 0}#T(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||!M(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&&M(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.#F(e._rows[r])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0))}onKeyDown(t){switch(t.key){case"Escape":return this.#q(t);case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":return this.#P(t);case"Tab":return this.#$(t);case" ":case"Spacebar":return this.#V(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#O(t);case"F2":return this.#W(t);default:return!1}}#q(t){return this.#i&&this.#p?(this.#D(),this.requestAfterRender(),!0):-1!==this.#s&&!this.#i&&(G(this.config,t)||this.#k(this.#s,!0),!0)}#P(t){const e=A(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))}#$(t){return!(-1===this.#s&&!this.#i)&&(t.preventDefault(),this.#y?(this.#k(this.#s,!1),!0):(this.#N(!t.shiftKey),!0))}#V(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!!M(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.#H(t);if(-1!==this.#s){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!G(this.config,t)}return this.#j(t)}#H(t){const e=A(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.#F(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))}#z(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}#K(){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.#z(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.#K();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){const e=this.#r;if(this.config.dirtyTracking&&e.getRowId&&this.#E.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#s||this.#i)return t;const i=this.#l,n=this.#d;if(!i||!n)return t;const r=[...t];let o=-1;for(let s=0;s<r.length;s++)if(this.#L(r[s])===i){o=s;break}return-1===o?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[o]=n,this.#s!==o&&this.#B(this.#s,o),r)}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.#B(this.#s,e)}if(this.#g&&(this.#g=!1,this.#U(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.#Y(r,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[r],d=t._visibleColumns[o];l&&d&&this.#X(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.#X(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.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.#r;this.#E.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#m.setInvalid(t,e,i)}clearInvalid(t,e){this.#m.clearInvalid(t,e)}clearRowInvalid(t){this.#m.clearRowInvalid(t)}clearAllInvalid(){this.#m.clearAllInvalid()}isCellInvalid(t,e){return this.#m.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#m.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#m.hasInvalidCells(t)}getInvalidFields(t){return this.#m.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#E.changedRowIds.clear(),this.#E.committedDirtyRowIds.clear(),this.#S(),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.#Y(t,n);s&&(this.#y=!0,this.#Z(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.#F(n)&&(this.#y=!1,this.#Q(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.#X(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(x);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!1)}cancelActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!0)}#L(t){if(t)try{return this.#r.getRowId?.(t)}catch{return}}#Y(t,e){return(this.#r.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#F(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})}#D(){this.#J();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#p=!1,this.#v=!0}#tt(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)))}#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.#Y(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")}#B(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.#S()}#Z(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.#Q(t,r),this.#a=e,this.#X(r,t,o,e,i,!1)))}#J(){const t=this.#b;if(!t)return;const i=this.#r._rows?.[t.rowIndex];i&&(0,e.writeCellField)(i,t.field,t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#f.get(n);if(r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),i){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.#Y(e,i);if(n?.classList.contains("editing")){const t=n.querySelector(x);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.#Y(n,o[l]);return t?.classList.contains("editing")&&t.querySelector(x)?.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.#Y(d,e._focusCol);t?.classList.contains("editing")&&t.querySelector(x)?.focus({preventScroll:!0})},0)):(this.#k(n,!1),e._focusRow=d,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(d),s(e,{forceHorizontalScroll:!0}))}}#S(){const t=this.#r;t._activeEditRows=this.#s,t._rowEditSnapshots=this.#c}#Q(t,e){this.#s!==t&&(-1!==this.#s&&this.#k(this.#s,!1),this.#c.set(t,{...e}),this.#s=t,this.#d=e,this.#l=this.#L(e),this.#S(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#l??"",row:e}),r(this.gridElement,o(this.gridElement,"editingStarted",t))))}#k(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.#et(t);!e&&s&&d&&this.#it(s,t,d),e||this.#i||!d||this.emit("before-edit-close",{rowIndex:t,rowId:l??"",row:d}),e&&d?this.#tt(l,d,n):!e&&d&&this.#nt(t,l,d,n),this.#rt(t),this.#g=!0,s?this.#ot(s,i):(this.#U(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)))}#et(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}}#it(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=E(l,s,a);a!==c&&this.#_(i,s,c,n)})}#nt(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.#tt(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))}#rt(t){this.#c.delete(t),this.#s=-1,this.#l=void 0,this.#d=void 0,this.#a=-1,this.#y=!1,this.#S();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)}#ot(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(!M(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"):L;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.#S(),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,field:s,oldValue:l,newValue:n});const m=d.findRenderedRowElement?.(t);m&&m.classList.add("changed")}#X(t,e,i,n,r,o,s){D(this.#C,t,e,i,n,r,o,s)}#U(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=T,t.defaultEditorFor=y});
|
|
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",r="data-tbw-truncated";function n(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,...r){const n=(t&&"effectiveConfig"in t?t.effectiveConfig:void 0)?.a11y?.messages?.[i];return n?n(...r):e.DEFAULT_A11Y_MESSAGES[i](...r)}function s(t,r){!function(t){if(!t._virtualization?.enabled)return;const{rowHeight:i,container:r,viewportEl:n,scrollMapping:o}=t._virtualization,s=r,l=n?.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 n=function(t){return void 0!==t._activeEditRows&&-1!==t._activeEditRows}(t)||!!t._isGridEditMode;var o;n||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,r=t._virtualization.end??t._rows.length;if(e<i||e>=r)return;const n=t._bodyEl.querySelectorAll(".data-grid-row")[e-i];let o=n?.children[t._focusCol];return o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${t._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o?{rowEl:n??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"),n&&!r?.forceHorizontalScroll||function(t,e,i,r){const n=t.querySelector(".tbw-scroll-area");if(!n)return;if(r?.forceScrollLeft)return void(n.scrollLeft=0);if(r?.forceScrollRight)return void(n.scrollLeft=n.scrollWidth-n.clientWidth);const o=t._getHorizontalScrollOffsets?.(e??void 0,i)??{left:0,right:0};if(o.skipScroll)return;const s=i.getBoundingClientRect(),l=n.getBoundingClientRect(),d=s.left-l.left+n.scrollLeft,a=d+s.width,c=n.scrollLeft+o.left,u=n.scrollLeft+n.clientWidth-o.right;d<c?n.scrollLeft=d-o.left:a>u&&(n.scrollLeft=a-n.clientWidth+o.right)}(t,l,d,r),function(t,e,r){if(r&&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(r){if(e.contains(document.activeElement))return;e.hasAttribute("tabindex")||e.setAttribute("tabindex","-1");try{e.focus({preventScroll:!0})}catch{}return}const n=document.activeElement;n instanceof HTMLElement&&n!==t&&"function"==typeof t.contains&&t.contains(n)&&!n.classList.contains("cell")&&!n.closest(".cell")||n===t||t.focus({preventScroll:!0})}(t,d,n)}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 r=t[i];if(" "!==r){if(r>="0"&&r<="9"||"."===r&&i+1<t.length&&t[i+1]>="0"&&t[i+1]<="9"){const r=i;for(;i<t.length&&(t[i]>="0"&&t[i]<="9"||"."===t[i]);)i++;e.push({type:"num",v:Number(t.slice(r,i))});continue}if("'"===r){let r="";for(i++;i<t.length&&"'"!==t[i];)r+=t[i++];if(i>=t.length)return null;i++,e.push({type:"str",v:r});continue}if(r>="a"&&r<="z"||r>="A"&&r<="Z"||"_"===r||"$"===r){const r=i;for(;i<t.length&&/[\w$.]/.test(t[i]);)i++;e.push({type:"id",v:t.slice(r,i)});continue}if(i+2<t.length){const r=t.slice(i,i+3);if("==="===r||"!=="===r){e.push({type:"op",v:r}),i+=3;continue}}if(i+1<t.length){const r=t.slice(i,i+2);if("=="===r||"!="===r||"<="===r||">="===r||"&&"===r||"||"===r){e.push({type:"op",v:r}),i+=2;continue}}if(!"+-*/%<>!?:(),".includes(r))return null;e.push({type:"op",v:r}),i++}else i++}return e}(t);if(!i)return;const r=i;let n=0;function o(){return r[n]}function s(){return r[n++]}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 n<r.length?void 0:m}function f(t,e){if(!t||-1===t.indexOf("{{"))return t;const i=[],r=(n=t.replace(l,(t,r)=>{const n=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),r=e.row?e.row[i]:void 0;return null==r?d:String(r)}if(t.startsWith("typeDefault.")&&!/[()?]/.test(t)&&!t.includes(":")){const i=t.slice(12),r=e.typeDefault?e.typeDefault[i]:void 0;return null==r?d:String(r)}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),r=null==i?"":String(i);return g.test(r)?d:r||d}catch{return d}}(r,e);return i.push({expr:r.trim(),result:n}),n===d?n:(o=n)&&"string"==typeof o?o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"):"";var o}),n?n.replace(new RegExp(d,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):n);var n;const o=i.length&&i.every(t=>""===t.result||t.result===d);return g.test(t)||o?"":r}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){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="date",e.value instanceof Date?r.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(r.value=e.value.split("T")[0]),i?.min&&(r.min=i.min),i?.max&&(r.max=i.max),i?.placeholder&&(r.placeholder=i.placeholder);return r.addEventListener("change",()=>{var n;if(r.value)"string"==typeof e.value?e.commit(r.value):e.commit(r.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(n=t??new Date).getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:new Date)}}),r.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),r}}var v="__tbw_null__";function y(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="number",r.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(r.min=String(i.min)),void 0!==i?.max&&(r.max=String(i.max)),void 0!==i?.step&&(r.step=String(i.step)),i?.placeholder&&(r.placeholder=i.placeholder);const n=()=>{""===r.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(r.value))};return r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Enter"===t.key&&n(),"Escape"===t.key&&e.cancel()}),r}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return p(t);case"select":return function(t){return e=>{const i=t.editorParams,r=document.createElement("select");if(t.multi&&(r.multiple=!0),t.nullable||i?.includeEmpty){const n=document.createElement("option");n.value=t.nullable?v:"",n.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(n.selected=!0),r.appendChild(n)}(function(t){const e=t.options;return e?"function"==typeof e?e():e:[]})(t).forEach(i=>{const n=document.createElement("option");n.value=String(i.value),n.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?n.selected=!0:t.multi||e.value!==i.value||(n.selected=!0),r.appendChild(n)});const n=()=>{if(t.multi){const t=Array.from(r.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&r.value===v?e.commit(null):e.commit(r.value)};return r.addEventListener("change",n),r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),r}}(t);default:return function(t){return e=>{const i=t.editorParams,r=document.createElement("input");r.type="text",r.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(r.maxLength=i.maxLength),i?.pattern&&(r.pattern=i.pattern),i?.placeholder&&(r.placeholder=i.placeholder);const n=()=>{const i=r.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return r.addEventListener("blur",n),r.addEventListener("keydown",t=>{"Enter"===t.key&&n(),"Escape"===t.key&&e.cancel()}),r}}(t)}}function b(t,e){return""===t?e?.nullable?null:(e?.editorParams)?.min??0:Number(t)}function E(t,e,i){if(!(t instanceof HTMLInputElement))return function(t,e,i){return""===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 b(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?b(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)}}var R=class{#t=new Map;#e;constructor(t){this.#e=t}setInvalid(t,e,i=""){let r=this.#t.get(t);r||(r=new Map,this.#t.set(t,r)),r.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 C(t,e,i){const r=t.get(e);return!!r&&!I(r,i)}function I(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(!I(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,r=e,n=Object.keys(i),o=Object.keys(r);if(n.length!==o.length)return!1;for(const t of n)if(!I(i[t],r[t]))return!1;return!0}return!1}function _(t,e,i){t.set(e,structuredClone(i))}function k(t,e,i){const r=t.get(e);if(!r)return!1;const n=r,o=i;for(const s of Object.keys(n))o[s]=n[s];return!0}var S=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 r of e)if(!0!==r?.__loading)try{const e=i(r);null==e||t.has(e)||t.set(e,structuredClone(r))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0,!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return C(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&&C(this.baselines,e,i))return!0}return!1}isCellDirty(t,i,r){return function(t,i,r,n){const o=t.get(i);return!!o&&!I((0,e.readCellField)(o,n),(0,e.readCellField)(r,n))}(this.baselines,t,i,r)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&C(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){_(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}rebaselineCell(t,i,r){const n=this.baselines.get(t);n&&(0,e.writeCellField)(n,i,r)}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&&_(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,r]of this.baselines){const n=t(i);n&&C(this.baselines,i,n)&&e.push({id:i,original:structuredClone(r),current:n})}for(const i of this.newRowIds){const r=t(i);r&&e.push({id:i,original:void 0,current:r})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const r=t(i);r&&C(this.baselines,i,r)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=k(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&&k(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const r=t(i);r&&e.push(r)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}};var x='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function A(t){return t?.closest?.('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')??null}function M(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function L(t){}function G(t,e){return!1===t.onBeforeEditClose?.(e)}function D(t,i,r,n,o,s,l,d){if(!n.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"):L,p=M(n.field)?(0,e.readCellField)(i,n.field):void 0;s.classList.add("editing"),h.add(`${r}:${o}`);const v=d??s.parentElement;v&&function(t){t.__editingCellCount=(t.__editingCellCount??0)+1,t.setAttribute("data-has-editing","")}(v);let b=!1;const R=e=>{if(b||!c&&!t.isEditSessionActive())return;const o=g?a._getRowEntry(g):void 0,s=o?.row??i,l=o?.index??r;t.commitCellValue(l,n,e,s)},C=()=>{if(b=!0,M(n.field)){const t=(g?a._getRowEntry(g):void 0)?.row??i;(0,e.writeCellField)(t,n.field,p)}},I=document.createElement("div");I.className="tbw-editor-host";const _=m(s);s.firstElementChild&&a.__frameworkAdapter?.releaseCell?.(s),s.innerHTML="",s.appendChild(I),_&&s.appendChild(_),I.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=A(i);if(o&&o!==i)return;if(c){e.preventDefault();const t=I.querySelector("input,textarea,select");return void(t&&R(E(t,n,p)))}if(G(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(r,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(G(u,e))return;e.stopPropagation(),e.preventDefault(),C(),t.exitRowEdit(r,!0)}}});const k=n,S=k.__editorTemplate,D=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const r=t.__frameworkAdapter;if(r?.getTypeDefault){const i=r.getTypeDefault(e.type,t._hostElement);if(i?.editor)return i.editor}}(a,k)??y(n),T=p,F=`${r}:${n.field}`,q=[];f.set(F,t=>{for(const e of q)e(t)});const P=t=>{q.push(t)};if("template"===D&&S)!function(t,e,i,r,n,o,s,l,d){const a=i.__editorTemplate;if(!a)return;const c=a.cloneNode(!0),u=i.__compiledEditor;u?c.innerHTML=u({row:r,value:n,field:i.field,column:i,commit: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==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!M(e))return"";const i=r[e];return null==i?"":String(i)})||"")});const h=c.querySelector("input,textarea,select");if(h){h instanceof HTMLInputElement&&"checkbox"===h.type?h.checked=!!n:h.value=String(n??"");let e=!1;h.addEventListener("blur",()=>{e||o(E(h,i,n))}),h.addEventListener("keydown",r=>{const l=r;if("Enter"===l.key){if(G(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,o(E(h,i,n)),t.exitRowEdit(d,!1)}if("Escape"===l.key){if(G(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,I,k,i,p,R,C,l,r),P(t=>{if(null!=t&&"object"==typeof t)return;const e=I.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof D){const t=document.createElement(D);t.value=T,t.addEventListener("change",()=>R(t.value)),P(e=>{t.value=e}),I.appendChild(t),l||queueMicrotask(()=>{I.querySelector(x)?.focus({preventScroll:!0})})}else if("function"==typeof D){const e=D({row:i,rowId:g??"",value:T,field:n.field,column:n,commit:R,cancel:C,updateRow:w,onValueChange:P,grid:t.grid});"string"==typeof e?(I.innerHTML=e,function(t,e,i,r){const n=t.querySelector("input,textarea,select");n&&(n.addEventListener("blur",()=>{i(E(n,e,r))}),n instanceof HTMLInputElement&&"checkbox"===n.type?n.addEventListener("change",()=>i(n.checked)):n instanceof HTMLSelectElement&&n.addEventListener("change",()=>i(E(n,e,r))))}(I,n,R,p),P(t=>{const e=I.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))})):e instanceof Node?(I.appendChild(e),e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?P(t=>{e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??"")}):s.setAttribute("data-editor-managed","")):!e&&I.hasChildNodes()&&s.setAttribute("data-editor-managed",""),l||queueMicrotask(()=>{I.querySelector(x)?.focus({preventScroll:!0})})}else if(D&&"object"==typeof D){const e=document.createElement("div");e.setAttribute("data-external-editor",""),e.setAttribute("data-field",n.field),I.appendChild(e),s.setAttribute("data-editor-managed","");const r={row:i,rowId:g??"",value:T,field:n.field,column:n,commit:R,cancel:C,updateRow:w,onValueChange:P,grid:t.grid};if(D.mount)try{D.mount({placeholder:e,context:r,spec:D})}catch(N){$="TBW080",V=`External editor mount error for column '${n.field}': ${N}`,O=t.grid.id,console.warn(function(t,e,i,r){return`${function(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}(i,r)} ${t}: ${e}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(t)}`}($,V,O,W))}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:e,spec:D,context:r}}))}var $,V,O,W;!function(t,e){const i="string"==typeof e.header?e.header:e.field;if(!i)return;queueMicrotask(()=>{const e=t.querySelector(x);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))})}(I,n)}var T=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}#r(t,e){const i=this.#n.effectiveConfig?.rowEditable;if(i&&!i(e))return!1;const{editable:r}=t;return"function"==typeof r?r(e):!0===r}#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 S;#R=new Set;#C;get#n(){return this.grid}attach(t){super.attach(t);const e=this.disconnectSignal,i=this.#n;this.#m=new R((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,r)=>this.#_(t,e,i,r),exitRowEdit:(t,e)=>this.#k(t,e)},this.#S(),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(G(this.config,t))return;this.#k(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 r=t.target;if(!r||this.gridElement.contains(r)||!this.grid.containsFocus?.(r)){if(r&&!this.gridElement.contains(r)){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 r=0;r<i.length;r++){const n=i[r].getAttribute("aria-controls");if(!n)continue;const o=e.ownerDocument?.getElementById(n);if(o&&o.contains(t))return!0}return!1}(r,t))return}G(this.config,t)||queueMicrotask(()=>{-1!==this.#s&&this.#k(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}`,r=this.#f.get(i);r&&r(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],r=new Set;for(const n of i){const t=void 0!==n.rowId?this.#n._getRowEntry(n.rowId)?.row:this.rows[n.rowIndex];if(!t)continue;const e=n.rowId??this.#L(t);if(!e||r.has(e))continue;r.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.#n;return!!e.getRowId&&this.#E.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}})}#A(t,i){this.gridElement.addEventListener("focusin",t=>{const r=t.target;if(r!==this.gridElement&&r.matches('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])')){if(this.#v)return r.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,o=this.#b;if(!o||o.rowIndex!==t||o.colIndex!==n){const r=i._visibleColumns?.[n],o=i._rows?.[t];if(r?.field&&o){const i=r.field;this.#b={rowIndex:t,colIndex:n,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=A(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(G(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.#n._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.#n.effectiveConfig?.columns??[],e=new Map;for(const i of t)e.set(i.field,i);return(t,i)=>{const r=e.get(t);return!!r&&this.#r(r,i)}}return"commitCellValue"===t.type?this.#F(t.context):void 0}#F(t){const i=this.#n,r=(i._visibleColumns??[]).find(e=>e.field===t.field)??i._columns?.find(e=>e.field===t.field),n=t.row??(null!=t.rowId?i._getRowEntry(t.rowId)?.row:void 0)??i._rows?.[t.rowIndex];if("sync"===t.source){if(!n||!M(t.field))return;(0,e.writeCellField)(n,t.field,t.newValue),(0,e.invalidateAccessorCache)(n);const i=this.#L(n);if(i&&this.config.dirtyTracking){this.#E.rebaselineCell(i,t.field,t.newValue);const e=this.#E.isRowDirty(i,n);e||this.#E.changedRowIds.delete(i),this.#G(i,n,e?"modified":"pristine")}return!0}if(r&&n&&M(t.field)){if("history"===t.source){(0,e.writeCellField)(n,t.field,t.newValue),(0,e.invalidateAccessorCache)(n);const i=this.#L(n);if(i&&this.config.dirtyTracking){const t=this.#E.isRowDirty(i,n);t||this.#E.changedRowIds.delete(i),this.#G(i,n,t?"modified":"pristine")}return!0}return this.#_(t.rowIndex,r,t.newValue,n,t.source),(0,e.readCellField)(n,t.field)===t.newValue}}onCellClick(t){if(this.#i)return!1;const e=this.#n,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const r="dblclick"===t.originalEvent.type;if("click"===i&&r)return!1;if("dblclick"===i&&!r)return!1;const{rowIndex:n}=t;return!!e._columns?.some(t=>this.#o(t))&&(!!this.#q(e._rows[n])&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(n),!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.#O(t);case"Enter":return!(t.shiftKey||t.ctrlKey||t.altKey||t.metaKey)&&this.#W(t);case"F2":return this.#N(t);default:return!1}}#P(t){return this.#i&&this.#p?(this.#T(),this.requestAfterRender(),!0):-1!==this.#s&&!this.#i&&(G(this.config,t)||this.#k(this.#s,!0),!0)}#$(t){const e=A(t.target),i=!!e&&e!==this.gridElement,r="ArrowUp"===t.key||"ArrowDown"===t.key;return!(this.#i&&!this.#p&&!i)&&(!(!this.#i||!this.#p&&!i||!r)||!(!r||-1===this.#s||this.#i))}#V(t){return!(-1===this.#s&&!this.#i)&&(t.preventDefault(),this.#y?(this.#k(this.#s,!1),!0):(this.#H(!t.shiftKey),!0))}#O(t){if(t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;if(-1!==this.#s)return!1;const i=this.#n,r=i._focusRow,n=i._focusCol;if(r<0||n<0)return!1;const o=i._visibleColumns[n],s=i._rows[r];if(!o||!s||"boolean"!==o.type)return!1;if(!this.#r(o,s))return!1;const l=o.field;return!!M(l)&&(this.#_(r,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.#j(t);if(-1!==this.#s){const e=t.target;return(!e||"true"!==e.getAttribute?.("aria-expanded")||!e.hasAttribute?.("aria-controls"))&&!!G(this.config,t)}return this.#z(t)}#j(t){const e=A(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}#z(t){const i=this.#n,r=this.config.editOn??i.effectiveConfig?.editOn;if(!1===r||"manual"===r)return!1;const n=i._focusRow,o=i._focusCol;if(n<0)return!1;const s=i._columns?.some(t=>this.#o(t)),l=i._rows[n];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="${n}"][data-col="${o}"]`),u=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,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(n),!0)}#N(t){if(-1!==this.#s||this.#i)return!1;const e=this.#n;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return!1;const i=e._focusRow,r=e._focusCol;if(i<0||r<0)return!1;const n=e._visibleColumns[r],o=e._rows[i];return!!(n&&o&&n.field)&&(!!this.#r(n,o)&&(t.preventDefault(),this.beginCellEdit(i,n.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.#n,e=t._hostElement;if(!e)return;const i=t.effectiveConfig;if(!i)return;const r=Array.from(e.children).filter(t=>"tbw-grid-type"===t.tagName.toLowerCase());if(!r.length)return;const n=t.__frameworkAdapter,o=i.typeDefaults??={};for(let s=0;s<r.length;s++){const t=r[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=n?.canHandle?.(d)?n.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.#n;this.#B();const i=e.effectiveConfig?.typeDefaults,r=e.__frameworkAdapter,n=!!i||!!r?.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||!n)return t;let s;if(i?.[t.type]?.editorParams&&(s=i[t.type].editorParams),!s&&r?.getTypeDefault){const i=r.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 r=[...t];let n=-1;for(let o=0;o<r.length;o++)if(this.#L(r[o])===e){n=o;break}return-1===n?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[n]=i,this.#s!==n&&this.#U(this.#s,n),r)}afterRender(){const t=this.#n;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,r]=i.split(":"),n=parseInt(e,10),o=parseInt(r,10),s=this.#X(n,o);if(!s||s.classList.contains("editing"))continue;const l=t._rows[n],d=t._visibleColumns[o];l&&d&&this.#Z(l,n,d,o,s,!0)}}afterCellRender(t){const{row:i,rowIndex:r,column:n,colIndex:o,cellElement:s}=t,l=this.#r(n,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,n.field);s.textContent=null==t?"":String(t)}this.#i&&l&&(s.classList.contains("editing")||this.#Z(i,r,n,o,s,!0,t.rowElement))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.#n.getRowId?.(t.row);if(!e)return;const{isNew:i,isCommittedDirty:r,hasBaseline:n}=this.#E.getRowDirtyState(e,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",i),n){const i=o.querySelectorAll(".cell[data-field]");for(let r=0;r<i.length;r++){const n=i[r],o=n.getAttribute("data-field");o&&n.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.#n,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.#n;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.#n;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.#n;return this.#E.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.#n;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.#n;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.#S(),t||this.emit("changed-rows-reset",{rows:e,ids:i}),this.#n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.#n,r=i._visibleColumns.findIndex(t=>t.field===e);if(-1===r)return;const n=i._visibleColumns[r],o=i._rows[t];if(!n||!o||!this.#r(n,o))return;const s=this.#X(t,r);s&&(this.#y=!0,this.#Q(t,r,s))}beginBulkEdit(t){const e=this.#n;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 r=e._rows[t];this.#q(r)&&(this.#y=!1,this.#J(t,r),Array.from(i.children).forEach((i,n)=>{const o=e._visibleColumns[n];if(o&&this.#r(o,r)){const e=i;e.classList.contains("editing")||this.#Z(r,t,o,n,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(x);try{e?.focus({preventScroll:!0})}catch{}}},0))}commitActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!1)}cancelActiveRowEdit(){-1!==this.#s&&this.#k(this.#s,!0)}#L(t){if(t)try{return this.#n.getRowId?.(t)}catch{return}}#X(t,e){return(this.#n.findRenderedRowElement?.(t))?.querySelector(`.cell[data-col="${e}"]`)??null}#q(t){if(!t)return!0;const e=this.#n.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.#n,o=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===o||void 0===o)return;const s=n._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(r))}else l.removeAttribute("data-invalid"),l.removeAttribute("aria-invalid"),l.removeAttribute("title")}#U(t,e){this.#s=e;const i=new Set,r=`${t}:`;for(const s of this.#u)s.startsWith(r)?i.add(`${e}:${s.substring(r.length)}`):i.add(s);this.#u.clear();for(const s of i)this.#u.add(s);const n=this.#c.get(t);void 0!==n&&(this.#c.delete(t),this.#c.set(e,n));const o=[];for(const[s,l]of this.#f)s.startsWith(r)&&(o.push([`${e}:${s.substring(r.length)}`,l]),this.#f.delete(s));for(const[s,l]of o)this.#f.set(s,l);this.#S()}#Q(t,e,i){const r=this.#n,n=r._rows[t],o=r._visibleColumns[e];n&&o&&this.#r(o,n)&&(i.classList.contains("editing")||(this.#s!==t&&this.#J(t,n),this.#a=e,this.#Z(n,t,o,e,i,!1)))}#tt(){const t=this.#b;if(!t)return;const i=this.#n._rows?.[t.rowIndex];i&&((0,e.writeCellField)(i,t.field,t.value),this.emitPluginEvent("cell-edit-reverted",{rowId:this.#L(i)}));const r=`${t.rowIndex}:${t.field}`,n=this.#f.get(r);if(n&&n(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.#n,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const r=this.#X(e,i);if(r?.classList.contains("editing")){const t=r.querySelector(x);t&&(this.#v=!1,t.focus(),this.#p=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#H(t){const e=this.#n,i=e._rows,r=this.#i?e._focusRow:this.#s,n=i[r],o=e._visibleColumns.map((t,e)=>n&&this.#r(t,n)?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(r,o[l]);return t?.classList.contains("editing")&&t.querySelector(x)?.focus({preventScroll:!0}),void s(e,{forceHorizontalScroll:!0})}const d=r+(t?1:-1);if(d>=0&&d<i.length){const n=i[d],o=e._visibleColumns.map((t,e)=>n&&this.#r(t,n)?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(x)?.focus({preventScroll:!0})},0)):(this.#k(r,!1),e._focusRow=d,e._focusCol=t?o[0]:o[o.length-1],this.beginBulkEdit(d),s(e,{forceHorizontalScroll:!0}))}}#S(){const t=this.#n;t._activeEditRows=this.#s,t._rowEditSnapshots=this.#c}#J(t,e){this.#s!==t&&(-1!==this.#s&&this.#k(this.#s,!1),this.#c.set(t,{...e}),this.#s=t,this.#d=e,this.#l=this.#L(e),this.#S(),this.#i||(this.broadcast("edit-open",{rowIndex:t,rowId:this.#l??"",row:e}),n(this.gridElement,o(this.gridElement,"editingStarted",t))))}#k(t,e){if(this.#s!==t)return;const i=this.#n,r=this.#c.get(t),s=i.findRenderedRowElement?.(t),{rowId:l,current:d}=this.#it(t);!e&&s&&d&&this.#rt(s,t,d),e||this.#i||!d||this.emit("before-edit-close",{rowIndex:t,rowId:l??"",row:d}),e&&d?this.#et(l,d,r):!e&&d&&this.#nt(t,l,d,r),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||n(this.gridElement,o(this.gridElement,"editingCommitted",t)))}#it(t){const e=this.#n;let i=this.#l;const r=(i?e._getRowEntry(i):void 0)?.row??this.#d??e._rows[t];return!i&&r&&(i=this.#L(r)),{rowId:i,current:r}}#rt(t,i,r){const n=this.#n;t.querySelectorAll(".cell.editing").forEach(t=>{const o=Number(t.getAttribute("data-col"));if(isNaN(o))return;const s=n._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)(r,d),c=E(l,s,a);a!==c&&this.#_(i,s,c,r)})}#nt(t,e,i,r){const n=function(t,e){if(!t)return!1;const i=t,r=e,n=new Set([...Object.keys(i),...Object.keys(r)]);for(const o of n)if(i[o]!==r[o])return!0;return!1}(r,i),o=e?this.#E.changedRowIds.has(e):n;this.emitCancelable("row-commit",{rowIndex:t,rowId:e??"",row:i,oldValue:r,newValue:i,changed:o,changedRows:this.changedRows,changedRowIds:this.changedRowIds})?r&&this.#et(e,i,r):(e&&this.config.dirtyTracking&&(this.#E.isRowDirty(e,i)?this.#E.committedDirtyRowIds.add(e):this.#E.committedDirtyRowIds.delete(e)),n&&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.#S();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,r=t.querySelectorAll(".cell.editing");i?.releaseCell&&r.forEach(t=>{const e=m(t);i.releaseCell(t),e&&t.appendChild(e)}),r.forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),e.refreshVirtualWindow(!0)}#_(t,i,r,n,o="user"){const s=i.field;if(!M(s))return;const l=(0,e.readCellField)(n,s);if(l===r)return;const d=this.#n,a=this.#L(n),c=!a||!this.#E.changedRowIds.has(a),u=a?t=>this.grid.updateRow(a,t,"cascade"):L;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:n,rowId:a??"",field:s,oldValue:l,value:r,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)(n,s,r),(0,e.invalidateAccessorCache)(n),a&&this.#E.changedRowIds.add(a),this.#S(),this.config.dirtyTracking&&a){const t=this.#E.isRowDirty(a,n);this.#G(a,n,t?"modified":"pristine")}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,rowId:a,field:s,oldValue:l,newValue:r});const m=d.findRenderedRowElement?.(t);m&&m.classList.add("changed")}#Z(t,e,i,r,n,o,s){D(this.#C,t,e,i,r,n,o,s)}#Y(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,r=t.findRenderedRowElement?.(e);if(r){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const n=r.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);n&&(n.classList.add("cell-focus"),n.setAttribute("aria-selected","true"),n.hasAttribute("tabindex")||n.setAttribute("tabindex","-1"),n.focus({preventScroll:!0}))}}catch{}})}};t.EditingPlugin=T,t.defaultEditorFor=y});
|
|
2
2
|
//# sourceMappingURL=editing.umd.js.map
|