@toolbox-web/grid 3.8.0 → 3.8.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/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/types.d.ts +4 -0
- package/lib/features/registry.js +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/row-drag-drop/index.js +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e="selected",t={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,selectAllRows:()=>"Select all rows",selectRow:e=>`Select row ${e+1}`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function i(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const n=e.querySelector?.(".tbw-sr-only");n&&(n.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{n.textContent=t}):n.textContent=t)}function s(e,n,...i){const s=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[n];return s?s(...i):t[n](...i)}var r=null,o=/* @__PURE__ */new Set;function l(e){const t=e.matches?"coarse":"fine";o.forEach(e=>e(t))}function c(){const e=r||("function"!=typeof globalThis.matchMedia?null:("function"==typeof(r=globalThis.matchMedia("(pointer: coarse)")).addEventListener?r.addEventListener("change",l):"function"==typeof r.addListener&&r.addListener(l),r));return e?function(e){return e.matches?"coarse":"fine"}(e):"fine"}function a(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const n=e.closest(".data-grid-row");if(!n)return-1;const i=n.parentElement;if(!i)return-1;const s=i.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<s.length;r++)if(s[r]===n)return r;return-1}function d(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function h(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function u(e,t,n,i){return`${h(n,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var g="__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(e=>e.split("").reverse().join("")),m=(new RegExp(`__(proto|defineGetter|defineSetter)|${g.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("|"))),f=/^on\w+$/i,w=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),b=/^\s*(javascript|vbscript|data|blob):/i;function p(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const i of n){const e=i.tagName.toLowerCase();if(m.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>f.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const n=[];for(const t of i.attributes){const e=t.name.toLowerCase();f.test(e)?n.push(t.name):"is"!==e?(w.has(e)&&b.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name):n.push(t.name)}n.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var v=class{static dependencies;static manifest;aliases;version="3.8.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},n={};for(const i of Object.keys(t))n[i]=this;for(const i of e){const e=i.userConfig;for(const[s,r]of Object.entries(e)){if(void 0===r)continue;if(!(s in t)){t[s]=r,n[s]=i;continue}if(t[s]===r)continue;const e=n[s]?.constructor.name??this.constructor.name,o=i.constructor.name,l=u("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${s}" supplied by both ${e} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,n={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,n)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const n=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const n=this.grid?.query?.(e,t);return Array.isArray(n)?n.some(Boolean):!!n}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...n,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}setIcon(e,t,n){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,n);var s,r;void 0!==i?"string"==typeof i?(s=e,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?s.replaceChildren(p(r)):s.textContent=r:s.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(i.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(n,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(n,i):e.appendChild(n),n}warn(e,t){void 0!==t?console.warn(u(e,t,this.gridElement.id,this.name)):console.warn(`${h(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(u(e,t,this.gridElement.id,this.name))}};function C(e){return"__tbw_expander"===e.field}function y(e){return!0===e.utility}function S(){return"function"==typeof HTMLElement.prototype?.showPopover}function A(e,t){let n=null,i=!1,s=!1;const r=new AbortController;function o(){i&&n&&(i=!1,S()&&n.hidePopover(),n.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&n&&!e.composedPath().includes(n)&&o()},{capture:!0,signal:r.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&o()},{capture:!0,signal:r.signal}),{get element(){return n},open(l,c,a){if(s||0===a.length)return;n||(n=function(){const n=document.createElement("div");return n.id=e,n.className=t,n.setAttribute("popover","manual"),n.setAttribute("role","group"),n.hidden=!0,n.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!n.contains(t)&&o()},{signal:r.signal}),n}());const d=l.closest("tbw-grid, [data-tbw-grid]")??document.body;n.parentNode!==d&&d.appendChild(n),n.setAttribute("aria-label",c),n.replaceChildren();for(const e of a){const i=document.createElement("button");i.type="button",i.className=`${t}-item`,i.textContent=e.label,i.disabled=!0===e.disabled,i.addEventListener("click",()=>{o(),e.run()}),n.appendChild(i)}n.hidden=!1,!i&&S()&&n.showPopover(),i=!0,function(e){if(!n)return;const t=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=Math.max(4,Math.min(t.left,window.innerWidth-i.width-4)),r=t.bottom+6,o=r+i.height<=window.innerHeight?r:Math.max(4,t.top-6-i.height);n.style.left=`${Math.round(s)}px`,n.style.top=`${Math.round(o)}px`}(l),n.querySelector("button:not([disabled])")?.focus()},close:o,dispose(){s=!0,o(),r.abort(),n?.remove(),n=null}}}function x(e){const t=/* @__PURE__ */new Set(["cell","row","column","range"]);if("string"==typeof e){if(!t.has(e))throw new Error(`[SelectionPlugin] Invalid selection mode: "${e}". Expected one of: 'cell' | 'row' | 'column' | 'range'.`);return{primary:e,columnEnabled:"column"===e,bothAxes:!1}}if(!Array.isArray(e))throw new Error(`[SelectionPlugin] Invalid selection mode: expected string or array, got ${typeof e}.`);if(0===e.length)throw new Error("[SelectionPlugin] Invalid selection mode: array must contain at least one mode.");for(const i of e)if(!t.has(i))throw new Error(`[SelectionPlugin] Invalid selection mode in array: "${i}". Expected one of: 'cell' | 'row' | 'column' | 'range'.`);if(new Set(e).size!==e.length)throw new Error(`[SelectionPlugin] Invalid selection mode: array contains duplicate entries (${e.join(", ")}).`);if(1===e.length)return x(e[0]);if(e.length>2)throw new Error(`[SelectionPlugin] Invalid selection mode: arrays of more than 2 modes are not supported. Got [${e.join(", ")}].`);if(!e.includes("column"))throw new Error(`[SelectionPlugin] Invalid selection mode: [${e.join(", ")}]. Two-mode arrays must include 'column' (the only valid combinations are ['row','column'], ['cell','column'], ['range','column']). Other in-row modes don't compose meaningfully.`);const n=e.find(e=>"column"!==e);if("column"===n)throw new Error(`[SelectionPlugin] Invalid selection mode: [${e.join(", ")}].`);return{primary:n,columnEnabled:!0,bothAxes:!0}}function E(e){const t=[];for(const n of e)!0!==n.utility&&"string"==typeof n.field&&n.field.length>0&&t.push(n.field);return t}function R(e,t){return t.indexOf(e)}function k(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function M(e){const t=k(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function I(e,t,n){return n.some(n=>function(e,t,n){const i=k(n);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,n))}function q(e){const t=[],n=k(e);for(let i=n.startRow;i<=n.endRow;i++)for(let e=n.startCol;e<=n.endCol;e++)t.push({row:i,col:e});return t}function P(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function L(e,t){const n=k(e),i=k(t);return n.startRow===i.startRow&&n.startCol===i.startCol&&n.endRow===i.endRow&&n.endCol===i.endCol}var $=/* @__PURE__ */new WeakMap;function _(e,t,n,i){const{onMove:s,onEnd:r,onCancel:o,onPromote:l}=n,c=i?.threshold??0,a=i?.longPressDuration??0,d=i?.longPressSlop??8,h=e.pointerId;if(!function(e,t){let n=$.get(e);return n||(n=/* @__PURE__ */new Set,$.set(e,n)),!n.has(t)&&(n.add(t),!0)}(t,h))return()=>{};const u=e.clientX,g=e.clientY;let m=0===c&&0===a,f=!1,w=null,b=!1;function p(){return m=!0,function(){try{return t.setPointerCapture(h),!0}catch{return b=!0,!1}}()?(l?.(),!0):(C(),!1)}function v(){if(!f){var e,n;f=!0,null!==w&&(clearTimeout(w),w=null),t.removeEventListener("pointermove",y),t.removeEventListener("pointerup",S),t.removeEventListener("pointercancel",A),t.removeEventListener("lostpointercapture",x),document.removeEventListener("keydown",E,!0),e=t,n=h,$.get(e)?.delete(n);try{t.hasPointerCapture(h)&&t.releasePointerCapture(h)}catch{}}}function C(){f||(v(),o?.())}function y(e){const t=e;if(t.pointerId!==h||f)return;const n=t.clientX-u,i=t.clientY-g,r=Math.sqrt(n*n+i*i);if(!m){if(a>0)return r>d?void C():void 0;if(c>0&&r<c)return;if(!p())return}s(t)}function S(e){const t=e;if(t.pointerId!==h||f)return;const n=m;v(),n?r(t):o?.()}function A(e){e.pointerId!==h||f||C()}function x(e){e.pointerId!==h||f||C()}function E(e){"Escape"!==e.key||f||C()}return t.addEventListener("pointermove",y),t.addEventListener("pointerup",S),t.addEventListener("pointercancel",A),t.addEventListener("lostpointercapture",x),document.addEventListener("keydown",E,!0),m&&(p(),b)?()=>{}:(a>0&&(w=setTimeout(()=>{w=null,f||p()},a)),C)}var T="tbw-selection-toolbar",F=class{#n=null;#i=null;#s=null;#r=null;get mounted(){return null!==this.#n}get element(){return this.#n}show(e,t,n,i){this.#r=i,this.#n||this.#o(e),this.#i&&(this.#i.textContent=`${t} selected`),this.#n?.setAttribute("data-selected-count",String(t)),this.#s&&(this.#s.hidden=!n)}destroy(){this.#n?.remove(),this.#n=null,this.#i=null,this.#s=null,this.#r=null}#o(e){const t=e.ownerDocument.createElement("div");t.className=T,t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Selection");const n=e.ownerDocument.createElement("span");n.className=`${T}-count`,n.setAttribute("aria-live","polite"),t.appendChild(n);const i=e.ownerDocument.createElement("div");i.className=`${T}-actions`,t.appendChild(i),i.appendChild(this.#l(e,"select-all","Select all",()=>this.#r?.selectAll())),i.appendChild(this.#l(e,"clear","Clear",()=>this.#r?.clear()));const s=this.#l(e,"more","More…",e=>this.#r?.more(e));s.setAttribute("aria-haspopup","menu"),i.appendChild(s),i.appendChild(this.#l(e,"done","Done",()=>this.#r?.done())),e.prepend(t),this.#n=t,this.#i=n,this.#s=s}#l(e,t,n,i){const s=e.ownerDocument.createElement("button");return s.type="button",s.className=`${T}-btn`,s.dataset.action=t,s.textContent=n,s.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),i(s)}),s}},K="tbw-range-handle",D=class{#c=null;#a=null;#r=null;#d=null;render(e,t,n,i){this.#r=i,t?(this.#c??=this.#h(e,"start"),this.#a??=this.#h(e,"end"),this.#u(e,this.#c,n(t.startRow,t.startCol),"start"),this.#u(e,this.#a,n(t.endRow,t.endCol),"end"),this.setArmed(this.#d)):this.#g()}setArmed(e){this.#d=e;for(const[t,n]of[[this.#c,"start"],[this.#a,"end"]]){if(!t)continue;const i=e===n;t.classList.toggle("armed",i),t.setAttribute("aria-pressed",String(i))}}destroy(){this.#c?.remove(),this.#a?.remove(),this.#c=null,this.#a=null,this.#r=null,this.#d=null}#g(){this.#c&&(this.#c.hidden=!0),this.#a&&(this.#a.hidden=!0)}#u(e,t,n,i){if(!t)return;if(!n)return void(t.hidden=!0);t.hidden=!1;const s=n.getBoundingClientRect?.(),r=e.getBoundingClientRect?.();if(!s||!r)return;const o="start"===i?s.left-r.left:s.right-r.left,l="start"===i?s.top-r.top:s.bottom-r.top;t.style.left=`${o}px`,t.style.top=`${l}px`}#h(e,t){const n=e.ownerDocument.createElement("div");return n.className=`${K} ${K}-${t}`,n.dataset.corner=t,n.setAttribute("role","button"),n.setAttribute("tabindex","-1"),n.setAttribute("aria-pressed","false"),n.setAttribute("aria-label","start"===t?"Selection start corner — drag, or activate to place it with a tap":"Selection end corner — drag, or activate to place it with a tap"),n.addEventListener("pointerdown",e=>this.#m(e,n,t)),e.appendChild(n),n}#m(e,t,n){if(0!==e.button&&"mouse"===e.pointerType)return;e.preventDefault(),e.stopPropagation();const i=this.#r;if(!i)return;t.classList.add("dragging");let s=!1;_(e,t,{onMove:e=>{s=!0;const t=i.cellAt(e.clientX,e.clientY);t&&i.resize(n,t.row,t.col)},onEnd:()=>{t.classList.remove("dragging"),s?i.commit():i.arm(n)},onCancel:()=>{t.classList.remove("dragging"),i.commit()}})}};function H(e){if("string"==typeof e)return e;if(Array.isArray(e)){const t=e.find(e=>"column"!==e);if(t)return t;if(e.includes("column"))return"column"}return"cell"}var z="__tbw_checkbox",N=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"];var U=class extends v{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"},{type:"getSelectedColumns",description:"Get field names of selected columns (column mode only)"},{type:"selectColumns",description:"Select specific columns by field name (column mode only)"},{type:"getContextMenuItems",description:"Contribute the non-dragging range-extension action (WCAG 2.2 SC 2.5.7)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:'"triggerOn: \'dblclick\'" has no effect when mode is "range".\n → Range selection uses drag interaction (mousedown → mousemove), not click events.\n → The "triggerOn" option only affects "cell" and "row" selection modes.',check:e=>"range"===H(e.mode)&&"dblclick"===e.triggerOn},{id:"selection/column-checkbox",severity:"warn",message:'"checkbox: true" only renders in row mode.\n → Column selection has no checkbox UI; activate columns via Ctrl+Click on a header or Ctrl+Space on a focused cell.',check:e=>!!e.checkbox&&"row"!==H(e.mode)}]};name="selection";styles='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}:is(tbw-grid:has(.selection)[data-selection-mode=row] .cell-focus,tbw-grid:has(.selection)[data-selection-mode=row] .row-focus,tbw-grid:has(.selection)[data-selection-mode=range] .cell-focus){outline:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background,rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style,var(--tbw-border-style));border-color:var(--tbw-range-border-color,var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width,var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width,var(--tbw-border-width));z-index:26;position:absolute;inset:0}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid .data-grid-row.row-focus>.cell.sticky-left,tbw-grid .data-grid-row.row-focus>.cell.sticky-right{background:linear-gradient(var(--tbw-focus-background,rgba(from var(--tbw-color-accent) r g b / 12%)) 0 0), var(--tbw-color-panel-bg)}tbw-grid .data-grid-row.row-focus[data-selectable=false]>.cell.sticky-left,tbw-grid .data-grid-row.row-focus[data-selectable=false]>.cell.sticky-right{background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";pointer-events:none;border:0 var(--tbw-selection-border-style,var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1;position:absolute;inset:0}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:var(--tbw-selection-disabled-opacity,.65)}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:var(--tbw-selection-disabled-opacity,.65)}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg,rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm,.8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;justify-content:center;align-items:center;padding:0;display:flex}tbw-grid .tbw-select-row-checkbox{pointer-events:none;cursor:pointer;margin:0}tbw-grid .tbw-checkbox-header{cursor:pointer;justify-content:center;align-items:center;height:100%;display:flex}tbw-grid .tbw-select-all-checkbox{cursor:pointer;margin:0}@media (pointer:coarse){tbw-grid .tbw-select-row-checkbox,tbw-grid .tbw-select-all-checkbox{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}tbw-grid .header-row>.cell.column-selected,tbw-grid .data-grid-row>.cell.column-selected,tbw-grid .data-grid-row>.cell.column-selected.sticky-left,tbw-grid .data-grid-row>.cell.column-selected.sticky-right,tbw-grid .header-row>.cell.column-selected.sticky-left,tbw-grid .header-row>.cell.column-selected.sticky-right{background:linear-gradient(var(--tbw-column-selection-bg,rgba(from var(--tbw-color-accent) r g b / 12%)) 0 0), var(--tbw-color-panel-bg)}tbw-grid .tbw-selection-toolbar{z-index:30;background:var(--tbw-color-panel-bg);border-bottom:1px solid var(--tbw-color-border);justify-content:space-between;align-items:center;gap:8px;padding:4px 8px;font-size:13px;display:flex;position:sticky;top:0}tbw-grid .tbw-selection-toolbar-count{white-space:nowrap;font-weight:600}tbw-grid .tbw-selection-toolbar-actions{align-items:center;gap:4px;display:flex}tbw-grid .tbw-selection-toolbar-btn{min-height:var(--tbw-touch-target-min,24px);border-radius:min(var(--tbw-border-radius,4px), 6px);color:inherit;font:inherit;cursor:pointer;background:0 0;border:0;padding:0 10px}tbw-grid .tbw-selection-toolbar-btn:hover,tbw-grid .tbw-selection-toolbar-btn:focus-visible{background:var(--tbw-color-row-hover,light-dark(#f0f0f0,#2a2a2a))}tbw-grid .tbw-selection-toolbar-btn[data-action=done]{color:var(--tbw-color-accent-text,var(--tbw-color-accent));font-weight:600}tbw-grid .tbw-range-handle{z-index:25;width:var(--tbw-touch-target-min,24px);height:var(--tbw-touch-target-min,24px);background:radial-gradient(circle, var(--tbw-color-accent) 0 5px, transparent 5px);cursor:crosshair;touch-action:none;position:absolute;translate:-50% -50%}tbw-grid .tbw-range-handle[hidden]{display:none}tbw-grid .tbw-range-handle.dragging{scale:1.3}tbw-grid .tbw-range-handle.armed{outline:2px solid var(--tbw-color-accent);outline-offset:-4px;border-radius:50%;scale:1.3}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0,touchMode:"transient"}}get touchSelectionActive(){return this.#f}#f=!1;#w=!1;#b=new F;#p=new D;#v=null;#C=null;#y=null;selected=/* @__PURE__ */new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;pendingRowKeyUpdate=null;selectedCell=null;selectedColumns=/* @__PURE__ */new Set;columnAnchor=null;columnHead=null;activeAxis="none";#S={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:n}=this.config;if(!n)return!0;const i=this.rows[e];return!!i&&n(i,e,void 0!==t?this.visibleColumns[t]:void 0,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.#S=x(this.config.mode),this.on("filter-change",()=>this.clearSelectionSilent()),this.on("group-toggle",()=>this.clearSelectionSilent()),this.on("tree-expand",()=>this.clearSelectionSilent()),this.on("sort-change",()=>this.clearSelectionSilent()),this.on("edit-open",({rowIndex:e,row:t})=>{this.isSelectionEnabled()&&(null==t||e<0||"row"===this.#S.primary&&this.isRowSelectable(e)&&(this.selected.has(e)||(!1===this.config.multiSelect&&this.selected.clear(),this.selected.add(e),this.lastSelected=e,this.anchor=e,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender())))});let t=-1;e.addEventListener("data-change",e=>{const{sourceRowCount:n}=e.detail,i=this.selected.size>0||this.ranges.length>0||null!==this.selectedCell;-1!==t&&n!==t&&i&&this.clearSelectionSilent(),t=n},{signal:this.disconnectSignal}),e.addEventListener("contextmenu",e=>{if(this.#x())return;const t=e.target?.closest?.(".cell[data-row][data-col]");if(!t)return;const n=parseInt(t.getAttribute("data-row")??"-1",10),i=parseInt(t.getAttribute("data-col")??"-1",10),s=this.#E(n,i);s&&(e.preventDefault(),this.#R(t,s))},{signal:this.disconnectSignal})}handleQuery(e){if("getSelection"===e.type)return this.getSelection();if("getSelectedRowIndices"===e.type)return this.getSelectedRowIndices();if("getSelectedRows"===e.type)return this.getSelectedRows();if("selectRows"===e.type)return this.selectRows(e.context),!0;if("getSelectedColumns"===e.type)return this.getSelectedColumns();if("selectColumns"===e.type){const t=e.context;return this.#k(t),!0}if("getContextMenuItems"===e.type){const t=e.context;if(!t||t.isHeader)return;const n=this.#E(t.rowIndex,t.columnIndex);if(!n)return;return n.map((e,t)=>({id:`selection-extend-${t}`,label:e.label,disabled:e.disabled,action:()=>e.run(),order:60+t}))}}detach(){(this.gridElement?.querySelector(".rows-body"))?.removeAttribute("aria-multiselectable"),this.#b.destroy(),this.#p.destroy(),this.#y?.dispose(),this.#y=null,this.#v=null,this.#C=null,this.#f=!1,this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.pendingKeyboardUpdate=null,this.pendingRowKeyUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.announceTimer&&(clearTimeout(this.announceTimer),this.announceTimer=null)}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,"column"!==this.activeAxis&&(this.activeAxis="none"),this.requestAfterRender()}#M(e){const t=e.pointerType;return"touch"===t||"pen"===t||"mouse"!==t&&"coarse"===c()}#I(e){return!!this.isRowSelectable(e)&&(this.#f=!0,this.selected.clear(),this.selected.add(e),this.anchor=e,this.lastSelected=e,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}exitTouchSelection(){this.#f&&(this.#f=!1,"transient"===(this.config.touchMode??"transient")&&(this.selected.clear(),this.anchor=null,this.lastSelected=null,this.emit("selection-change",this.#A())),this.requestAfterRender())}#q(e){const t=this.anchor??e,n=Math.min(t,e),i=Math.max(t,e);for(let s=n;s<=i;s++)this.isRowSelectable(s)&&this.selected.add(s);this.lastSelected=e,this.emit("selection-change",this.#A()),this.requestAfterRender()}#x(){const e=this.grid?.getPluginByName?.("contextMenu")??this.grid?.getPluginByName?.("context-menu");return"function"==typeof e?.showMenu?e:void 0}#P(e,t){return this.gridElement?.querySelector(`.cell[data-row="${e}"][data-col="${t}"]`)??null}#L(e,t){const n=this.gridElement,i=((n?.ownerDocument)?.elementFromPoint?.(e,t))?.closest?.(".cell[data-row][data-col]");if(!i||!n?.contains?.(i))return null;const s=parseInt(i.getAttribute("data-row")??"-1",10),r=parseInt(i.getAttribute("data-col")??"-1",10);return s>=0&&r>=0?{row:s,col:r}:null}#$(e,t,n){const i=this.ranges[this.ranges.length-1];if(!i)return;const s=k(i),r="start"===e?{row:s.endRow,col:s.endCol}:{row:s.startRow,col:s.startCol},o=P(r,{row:t,col:n});L(i,o)||(this.ranges[this.ranges.length-1]=o,this.activeRange=o,this.cellAnchor=r,this.emit("selection-change",this.#A()),this.requestAfterRender())}#E(e,t){if("range"!==this.#S.primary)return null;if(!this.isSelectionEnabled())return null;if(e<0||t<0)return null;if(!this.isCellSelectable(e,t))return null;const n=this.#C;return n?n.row===e&&n.col===t?null:[{label:"Extend selection to here",run:()=>this.#_(e,t)}]:null}#_(e,t){const n=this.#C;if(!n)return;const i=P(n,{row:e,col:t});this.ranges=[i],this.activeRange=i,this.cellAnchor=n,this.emit("selection-change",this.#A()),this.requestAfterRender()}#R(e,t){this.#y??=A("tbw-range-extend-menu","tbw-range-extend-menu"),this.#y.open(e,"Selection",t)}#T(e){this.#v=this.#v===e?null:e,this.#p.setArmed(this.#v),this.gridElement&&i(this.gridElement,this.#v?"Select a cell to place the selection corner":"Selection corner placement cancelled")}#F(){return!!this.#v&&(this.#v=null,this.#p.setArmed(null),!0)}#K(e){if(!e)return;this.#f?this.#b.show(e,this.selected.size,void 0!==this.#x(),{selectAll:()=>this.selectAll(),clear:()=>this.clearSelection(),done:()=>this.exitTouchSelection(),more:e=>this.#D(e)}):this.#b.destroy();const t=this.#w&&"range"===this.#S.primary&&this.ranges.length>0?this.ranges[this.ranges.length-1]:null,n=t?k(t):null;n||this.#F(),this.#p.render(e,n,(e,t)=>this.#P(e,t),{cellAt:(e,t)=>this.#L(e,t),resize:(e,t,n)=>this.#$(e,t,n),commit:()=>this.requestAfterRender(),arm:e=>this.#T(e)})}#D(e){const t=this.#x();if(!t)return;const n=e.getBoundingClientRect?.(),i=this.lastSelected??-1;t.showMenu(n?.left??0,n?.bottom??0,{row:i>=0?this.rows[i]:null,rowIndex:i,selectedRows:this.getSelectedRowIndices()})}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{triggerOn:t="click"}=this.config;if(e.originalEvent.type!==t)return!1;switch(this.#S.primary){case"cell":return this.#H(e);case"row":return this.#z(e);case"range":return this.#N(e);default:return!1}}#H(e){const{rowIndex:t,colIndex:n}=e;if(e.column&&y(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;const i=this.selectedCell;return i&&i.row===t&&i.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()),this.requestAfterRender()),!1}#z(e){const{rowIndex:t,originalEvent:n,column:i}=e;if(!this.isRowSelectable(t))return!1;const s=!1!==this.config.multiSelect,r=n.shiftKey&&s,o=(n.ctrlKey||n.metaKey||this.#f)&&s,l=!0===i?.checkboxColumn;if(r&&null!==this.anchor){const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);o||this.selected.clear();for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(o||l&&s)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(1===this.selected.size&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender(),!1}#N(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e;if(e.column&&y(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;if(this.#v){const e=this.#v;return this.#F(),this.#$(e,t,n),!0}this.#w=this.#M(i);const s=i.shiftKey,r=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(s&&this.cellAnchor){const e=P(this.cellAnchor,{row:t,col:n}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&L(i,e))return!1;r?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else{const e={startRow:t,startCol:n,endRow:t,endCol:n};if(r)this.ranges.push(e);else{if(1===this.ranges.length&&L(this.ranges[0],e))return!1;this.ranges=[e]}this.activeRange=e,this.cellAnchor={row:t,col:n},this.#C={row:t,col:n}}return this.emit("selection-change",this.#A()),this.requestAfterRender(),!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;if(this.#S.columnEnabled&&this.#U(e))return!0;const t=this.#S.primary;if("Escape"===e.key&&this.#F())return!0;if("Escape"===e.key&&this.#f)return this.exitTouchSelection(),!0;if("Escape"===e.key)return this.#j(t);const n=N.includes(e.key);switch(t){case"cell":return!!n&&this.#O();case"row":return this.#B(e);case"range":return this.#G(e,n);default:return!1}}#U(e){if(!e.ctrlKey&&!e.metaKey)return!1;if(" "===e.key||"Spacebar"===e.key){const t=this.visibleColumns[this.grid._focusCol];return!(!t||y(t)||"string"!=typeof t.field)&&(e.preventDefault(),e.stopPropagation(),this.selectColumn(t.field,{toggle:!0}),!0)}if(e.shiftKey&&"column"===this.activeAxis&&!1!==this.config.multiSelect&&("ArrowLeft"===e.key||"ArrowRight"===e.key)){const t=E(this.visibleColumns),n="ArrowLeft"===e.key?"left":"right",i=function(e,t,n){if(0===t.length)return null;if(null===e)return null;const i=R(e,t);if(i<0)return null;const s="left"===n?Math.max(0,i-1):Math.min(t.length-1,i+1);return s===i?null:t[s]}(this.columnHead,t,n);return null!==i&&null!==this.columnAnchor&&(e.preventDefault(),e.stopPropagation(),this.selectColumn(i,{range:!0}),!0)}return!1}#j(e){return!this.grid.query("isEditing").some(Boolean)&&("column"===this.activeAxis?(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none"):"cell"===e?this.selectedCell=null:"row"===e?(this.selected.clear(),this.anchor=null):"range"===e&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#O(){return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.selectedCell=this.isCellSelectable(e,t)?{row:e,col:t}:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}),!1}#B(e){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const n=e.shiftKey&&t;return n&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}return this.#W(e,t)}#G(e,t){if(!t)return this.#W(e,!1!==this.config.multiSelect);const n=e.shiftKey&&"Tab"!==e.key;return n&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}#W(e,t){return!(!t||"a"!==e.key||!e.ctrlKey&&!e.metaKey)&&(!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0))}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("row"===this.#S.primary){if(void 0===e.rowIndex||e.rowIndex<0)return;if(!1===this.config.multiSelect)return;if(!this.#M(e.originalEvent))return;if(e.column&&y(e.column))return;return this.#f?(this.#q(e.rowIndex),!0):this.#I(e.rowIndex)||void 0}if("range"!==this.#S.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(this.#v)return!0;if(this.#w=this.#M(e.originalEvent),2===e.originalEvent.button&&I(e.rowIndex,e.colIndex,this.ranges))return;if(e.column&&y(e.column))return;if(!this.isCellSelectable(e.rowIndex,e.colIndex))return;if(e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,n=e.colIndex,i=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,s={startRow:t,startCol:n,endRow:t,endCol:n};return!i&&1===this.ranges.length&&L(this.ranges[0],s)?(this.cellAnchor={row:t,col:n},this.#V(e,t,n),!0):(this.cellAnchor={row:t,col:n},this.#V(e,t,n),i||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#V(e,t,n){2!==e.originalEvent.button&&(this.#C={row:t,col:n})}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#S.primary)return;if(!this.isDragging||!this.cellAnchor)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;let t=e.colIndex;const n=this.visibleColumns[t];if(n&&y(n)){const e=this.visibleColumns.findIndex(e=>!y(e));e>=0&&(t=e)}const i=P(this.cellAnchor,{row:e.rowIndex,col:t}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return s&&L(s,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#A()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#S.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#S.columnEnabled)return!1;if(e.column&&y(e.column))return!1;const t=e.originalEvent;if(!t.ctrlKey&&!t.metaKey)return!1;const n=e.field;if(!n)return!1;t.preventDefault(),"function"==typeof t.stopPropagation&&t.stopPropagation();const i=!0===t.shiftKey&&!1!==this.config.multiSelect&&null!==this.columnAnchor;return this.selectColumn(n,i?{range:!0}:{toggle:!0}),!0}processColumns(e){if(this.config.checkbox&&"row"===this.#S.primary){if(e.some(e=>e.field===z))return e;const t=this.#X(),n=e.findIndex(C),i=n>=0?n+1:0;return[...e.slice(0,i),t,...e.slice(i)]}return e}#X(){return{field:z,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("label");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-all-checkbox";const n=document.createElement("span");return n.className="tbw-sr-only",n.textContent=s(this.gridElement,"selectAllRows"),t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.addEventListener("click",e=>e.stopPropagation()),e.append(t,n),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const n=e.cellEl,i=n?parseInt(n.getAttribute("data-row")??"-1",10):-1;return i>=0&&(t.checked=this.selected.has(i)),t.setAttribute("aria-label",s(this.gridElement,"selectRow",Math.max(i,0))),t}}}#Y(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),n=t?a(t):-1;n>=0&&(e.checked=this.selected.has(n))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let n=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&n++;else n=e;const i=n>0&&this.selected.size>=n,s=this.selected.size>0;t.checked=i,t.indeterminate=s&&!i}}#J(){return this.gridElement?.hasAttribute("data-has-focus")??!1}#Q(e){const t=this.grid._focusRow,n=this.grid._focusCol;if(!this.#J())return this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=n);if("row"===e){if(this.explicitSelection)return this.explicitSelection=!1,void(this.lastSyncedFocusRow=t);t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(this.selected.has(t)&&1===this.selected.size||(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#A()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=n);if((t!==this.lastSyncedFocusRow||n!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=n,this.isCellSelectable(t,n))){const e=this.selectedCell;e&&e.row===t&&e.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()))}}}#Z(){const t=this.gridElement;if(!t)return;const n=this.#S.primary,i=this.#S.columnEnabled,s=!!this.config.isSelectable,r=t.querySelector(".rows-body");if(r){const e=!1!==this.config.multiSelect;r.setAttribute("aria-multiselectable",e?"true":"false")}t.querySelectorAll(".cell").forEach(t=>{const n=t.classList.contains(e)||t.classList.contains("column-selected");t.classList.remove(e,"top","bottom","first","last","column-selected"),n&&t.removeAttribute("aria-selected"),s&&t.removeAttribute("data-selectable")});const o=t.querySelectorAll(".data-grid-row");if(o.forEach(t=>{t.classList.remove(e,"row-focus"),t.setAttribute("aria-selected","false"),s&&t.removeAttribute("data-selectable")}),i&&t.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")}),"row"===n&&(d(t),o.forEach(t=>{const n=a(t.querySelector(".cell[data-row]"));n>=0&&(s&&!this.isRowSelectable(n)&&t.setAttribute("data-selectable","false"),this.selected.has(n)&&(t.classList.add(e,"row-focus"),t.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#Y(t)),"cell"!==n&&"range"!==n||!s||t.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),n=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&n>=0&&(this.isCellSelectable(t,n)||e.setAttribute("data-selectable","false"))}),"range"===n&&this.ranges.length>0){d(t);const n=this.ranges.map(k),i=(e,t)=>{for(const i of n)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};t.querySelectorAll(".cell[data-row][data-col]").forEach(t=>{const n=parseInt(t.getAttribute("data-row")??"-1",10),s=parseInt(t.getAttribute("data-col")??"-1",10);if(n>=0&&s>=0){const r=this.visibleColumns[s];if(r&&y(r))return;i(n,s)&&(t.classList.add(e),t.setAttribute("aria-selected","true"),i(n-1,s)||t.classList.add("top"),i(n+1,s)||t.classList.add("bottom"),i(n,s-1)||t.classList.add("first"),i(n,s+1)||t.classList.add("last"))}})}if(i&&this.selectedColumns.size>0){const e=this.visibleColumns.map(e=>"string"==typeof e.field?e.field:void 0);t.querySelectorAll(".header-row > .cell[data-col]").forEach(t=>{const n=parseInt(t.getAttribute("data-col")??"-1",10),i=n>=0?e[n]:void 0;i&&this.selectedColumns.has(i)&&(t.classList.add("column-selected"),t.setAttribute("aria-selected","true"))}),t.querySelectorAll(".cell[data-col]:not(.header-row .cell)").forEach(t=>{if(t.closest(".header-row"))return;const n=parseInt(t.getAttribute("data-col")??"-1",10);if(n<0)return;const i=this.visibleColumns[n];if(!i||y(i))return;const s=e[n];s&&this.selectedColumns.has(s)&&(t.classList.add("column-selected"),t.setAttribute("aria-selected","true"))})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root"),n=this.#S.primary;if(this.pendingRowKeyUpdate&&"row"===n){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#A())}if(this.pendingKeyboardUpdate&&"range"===n){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,n=this.grid._focusCol;if(e&&this.cellAnchor){const e=P(this.cellAnchor,{row:t,col:n});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:n});this.emit("selection-change",this.#A())}this.#Q(n),this.gridElement.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#Z(),this.#K(t)}onScrollRender(){this.isSelectionEnabled()&&this.#Z()}getSelection(){const e=this.#A();return{mode:this.config.mode,activeAxis:e.activeAxis,ranges:e.ranges,selectedColumns:e.selectedColumns,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of q(n))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return I(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const n={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[n],this.activeRange=n,this.emit("selection-change",this.#A()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#S.primary)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const n of t)n>=0&&n<this.rows.length&&this.isRowSelectable(n)&&this.selected.add(n);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const e=this.#S.primary,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=/* @__PURE__ */new Set;for(const n of this.ranges){const i=Math.max(0,Math.min(n.startRow,n.endRow)),s=Math.min(t.length-1,Math.max(n.startRow,n.endRow));for(let t=i;t<=s;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}#k(e){if(!this.#S.columnEnabled)return;const t=E(this.visibleColumns),n=new Set(t),i=[],s=/* @__PURE__ */new Set;for(const o of e)n.has(o)&&!s.has(o)&&(s.add(o),i.push(o));this.#ee("column"),this.selectedColumns.clear();for(const o of i)this.selectedColumns.add(o);const r=i.length>0?i[i.length-1]:null;this.columnAnchor=r,this.columnHead=r,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#S.columnEnabled)return;const n=E(this.visibleColumns);if(n.includes(e)){if(this.#ee("column"),!1===this.config.multiSelect)this.selectedColumns.clear(),this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e;else if(t.range&&this.columnAnchor){const t=function(e,t,n){const i=R(e,n),s=R(t,n);if(-1===i||-1===s)return[];const r=Math.min(i,s),o=Math.max(i,s);return n.slice(r,o+1)}(this.columnAnchor,e,n);this.selectedColumns.clear();for(const e of t)this.selectedColumns.add(e);this.columnHead=e}else t.toggle?(this.selectedColumns.has(e)?this.selectedColumns.delete(e):this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e):(this.selectedColumns.clear(),this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e);this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}}deselectColumn(e){this.#S.columnEnabled&&this.selectedColumns.delete(e)&&(0===this.selectedColumns.size&&(this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none")),this.emit("selection-change",this.#A()),this.requestAfterRender())}selectAllColumns(){if(!this.#S.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=E(this.visibleColumns);if(0!==e.length){this.#ee("column"),this.selectedColumns.clear();for(const t of e)this.selectedColumns.add(t);this.columnAnchor=e[0],this.columnHead=e[e.length-1],this.activeAxis="column",this.emit("selection-change",this.#A()),this.requestAfterRender()}}clearColumnSelection(){0!==this.selectedColumns.size&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none"),this.emit("selection-change",this.#A()),this.requestAfterRender())}getSelectedColumns(){return 0===this.selectedColumns.size?[]:E(this.visibleColumns).filter(e=>this.selectedColumns.has(e))}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.emit("selection-change",this.#A()),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}#A(){const e=this.#S.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let n;this.#S.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&i(this.gridElement,s(this.gridElement,"selectionAxisChanged","row"))),n=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=n;const r=function(e,t,n,i,s,r){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:r.filter(e=>i.selectedColumns.has(e))};if("cell"===n&&i.selectedCell)return{mode:e,activeAxis:"cell",ranges:[{from:{row:i.selectedCell.row,col:i.selectedCell.col},to:{row:i.selectedCell.row,col:i.selectedCell.col}}],selectedColumns:[]};if("row"===n&&i.selected.size>0){const t=[...i.selected].sort((e,t)=>e-t),n=[];let r=t[0],o=r;for(let e=1;e<t.length;e++)t[e]===o+1?o=t[e]:(n.push({from:{row:r,col:0},to:{row:o,col:s-1}}),r=t[e],o=r);return n.push({from:{row:r,col:0},to:{row:o,col:s-1}}),{mode:e,activeAxis:"row",ranges:n,selectedColumns:[]}}return"range"===n&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(o=i.ranges,o.map(M)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var o}(this.config.mode,n,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,E(this.visibleColumns));return this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if("column"===r.activeAxis){const e=r.selectedColumns;if(1===e.length){const t=e[0],n=this.columns.find(e=>e.field===t),r="string"==typeof n?.header&&n.header||t;i(this.gridElement,s(this.gridElement,"columnSelected",r))}else e.length>1?i(this.gridElement,s(this.gridElement,"columnSelectionChanged",e.length)):i(this.gridElement,s(this.gridElement,"columnSelectionCleared"))}else{const e="row"===r.activeAxis?this.selected.size:r.ranges.length;e>0&&i(this.gridElement,s(this.gridElement,"selectionChanged",e))}},150),r}#ee(e){if(this.#S.bothAxes&&"column"===e){if(!(this.selected.size>0||null!==this.selectedCell||this.ranges.length>0))return;this.selected.clear(),this.lastSelected=null,this.anchor=null,this.selectedCell=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.gridElement&&i(this.gridElement,s(this.gridElement,"selectionAxisChanged","column"))}}};export{U as SelectionPlugin};
|
|
1
|
+
var e="selected",t={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,selectAllRows:()=>"Select all rows",selectRow:e=>`Select row ${e+1}`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function i(e,t){if(!e)return;if(!1===("effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.announcements)return;const n=e.querySelector?.(".tbw-sr-only");n&&(n.textContent="","function"==typeof requestAnimationFrame?requestAnimationFrame(()=>{n.textContent=t}):n.textContent=t)}function s(e,n,...i){const s=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[n];return s?s(...i):t[n](...i)}var r=null,o=/* @__PURE__ */new Set;function l(e){const t=e.matches?"coarse":"fine";o.forEach(e=>e(t))}function c(){const e=r||("function"!=typeof globalThis.matchMedia?null:("function"==typeof(r=globalThis.matchMedia("(pointer: coarse)")).addEventListener?r.addEventListener("change",l):"function"==typeof r.addListener&&r.addListener(l),r));return e?function(e){return e.matches?"coarse":"fine"}(e):"fine"}function a(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const n=e.closest(".data-grid-row");if(!n)return-1;const i=n.parentElement;if(!i)return-1;const s=i.querySelectorAll(":scope > .data-grid-row");for(let r=0;r<s.length;r++)if(s[r]===n)return r;return-1}function d(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function h(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function u(e,t,n,i){return`${h(n,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}var g="__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(e=>e.split("").reverse().join("")),m=(new RegExp(`__(proto|defineGetter|defineSetter)|${g.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("|"))),f=/^on\w+$/i,w=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),b=/^\s*(javascript|vbscript|data|blob):/i;function p(e){const t=document.createElement("template");return e&&"string"==typeof e&&(t.innerHTML=e,function(e){const t=[],n=e.querySelectorAll("*");for(const i of n){const e=i.tagName.toLowerCase();if(m.has(e)){t.push(i);continue}if(("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI)&&Array.from(i.attributes).some(e=>f.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}const n=[];for(const t of i.attributes){const e=t.name.toLowerCase();f.test(e)?n.push(t.name):"is"!==e?(w.has(e)&&b.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&n.push(t.name):n.push(t.name)}n.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content)),t.content}var v=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},n={};for(const i of Object.keys(t))n[i]=this;for(const i of e){const e=i.userConfig;for(const[s,r]of Object.entries(e)){if(void 0===r)continue;if(!(s in t)){t[s]=r,n[s]=i;continue}if(t[s]===r)continue;const e=n[s]?.constructor.name??this.constructor.name,o=i.constructor.name,l=u("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${s}" supplied by both ${e} and ${o}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig,n={...e.userConfig};for(const i of Object.keys(t))delete t[i];Object.assign(t,n)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const n=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(n),n.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}queryBoolean(e,t=null){const n=this.grid?.query?.(e,t);return Array.isArray(n)?n.some(Boolean):!!n}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...n,...e}}t(e,t){return this.grid?.effectiveConfig?.locale?.[e]??t}get translate(){return(e,t)=>this.t(e,t)}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;return!t||"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),n=parseInt(t,10);if(!isNaN(n))return n}return 200}setIcon(e,t,n){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,n);var s,r;void 0!==i?"string"==typeof i?(s=e,(r=i)&&"string"==typeof r?-1!==r.indexOf("<")||-1!==r.indexOf("&")?s.replaceChildren(p(r)):s.textContent=r:s.replaceChildren()):i instanceof HTMLElement&&e.replaceChildren(i.cloneNode(!0)):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const n=document.createElement("span");n.setAttribute("part","sort-indicator"),n.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(n,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(n,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(n,i):e.appendChild(n),n}warn(e,t){void 0!==t?console.warn(u(e,t,this.gridElement.id,this.name)):console.warn(`${h(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(u(e,t,this.gridElement.id,this.name))}};function C(e){return"__tbw_expander"===e.field}function y(e){return!0===e.utility}function S(){return"function"==typeof HTMLElement.prototype?.showPopover}function A(e,t){let n=null,i=!1,s=!1;const r=new AbortController;function o(){i&&n&&(i=!1,S()&&n.hidePopover(),n.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&n&&!e.composedPath().includes(n)&&o()},{capture:!0,signal:r.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&o()},{capture:!0,signal:r.signal}),{get element(){return n},open(l,c,a){if(s||0===a.length)return;n||(n=function(){const n=document.createElement("div");return n.id=e,n.className=t,n.setAttribute("popover","manual"),n.setAttribute("role","group"),n.hidden=!0,n.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!n.contains(t)&&o()},{signal:r.signal}),n}());const d=l.closest("tbw-grid, [data-tbw-grid]")??document.body;n.parentNode!==d&&d.appendChild(n),n.setAttribute("aria-label",c),n.replaceChildren();for(const e of a){const i=document.createElement("button");i.type="button",i.className=`${t}-item`,i.textContent=e.label,i.disabled=!0===e.disabled,i.addEventListener("click",()=>{o(),e.run()}),n.appendChild(i)}n.hidden=!1,!i&&S()&&n.showPopover(),i=!0,function(e){if(!n)return;const t=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=Math.max(4,Math.min(t.left,window.innerWidth-i.width-4)),r=t.bottom+6,o=r+i.height<=window.innerHeight?r:Math.max(4,t.top-6-i.height);n.style.left=`${Math.round(s)}px`,n.style.top=`${Math.round(o)}px`}(l),n.querySelector("button:not([disabled])")?.focus()},close:o,dispose(){s=!0,o(),r.abort(),n?.remove(),n=null}}}function x(e){const t=/* @__PURE__ */new Set(["cell","row","column","range"]);if("string"==typeof e){if(!t.has(e))throw new Error(`[SelectionPlugin] Invalid selection mode: "${e}". Expected one of: 'cell' | 'row' | 'column' | 'range'.`);return{primary:e,columnEnabled:"column"===e,bothAxes:!1}}if(!Array.isArray(e))throw new Error(`[SelectionPlugin] Invalid selection mode: expected string or array, got ${typeof e}.`);if(0===e.length)throw new Error("[SelectionPlugin] Invalid selection mode: array must contain at least one mode.");for(const i of e)if(!t.has(i))throw new Error(`[SelectionPlugin] Invalid selection mode in array: "${i}". Expected one of: 'cell' | 'row' | 'column' | 'range'.`);if(new Set(e).size!==e.length)throw new Error(`[SelectionPlugin] Invalid selection mode: array contains duplicate entries (${e.join(", ")}).`);if(1===e.length)return x(e[0]);if(e.length>2)throw new Error(`[SelectionPlugin] Invalid selection mode: arrays of more than 2 modes are not supported. Got [${e.join(", ")}].`);if(!e.includes("column"))throw new Error(`[SelectionPlugin] Invalid selection mode: [${e.join(", ")}]. Two-mode arrays must include 'column' (the only valid combinations are ['row','column'], ['cell','column'], ['range','column']). Other in-row modes don't compose meaningfully.`);const n=e.find(e=>"column"!==e);if("column"===n)throw new Error(`[SelectionPlugin] Invalid selection mode: [${e.join(", ")}].`);return{primary:n,columnEnabled:!0,bothAxes:!0}}function E(e){const t=[];for(const n of e)!0!==n.utility&&"string"==typeof n.field&&n.field.length>0&&t.push(n.field);return t}function R(e,t){return t.indexOf(e)}function k(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function M(e){const t=k(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function I(e,t,n){return n.some(n=>function(e,t,n){const i=k(n);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,n))}function q(e){const t=[],n=k(e);for(let i=n.startRow;i<=n.endRow;i++)for(let e=n.startCol;e<=n.endCol;e++)t.push({row:i,col:e});return t}function P(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function L(e,t){const n=k(e),i=k(t);return n.startRow===i.startRow&&n.startCol===i.startCol&&n.endRow===i.endRow&&n.endCol===i.endCol}var $=/* @__PURE__ */new WeakMap;function _(e,t,n,i){const{onMove:s,onEnd:r,onCancel:o,onPromote:l}=n,c=i?.threshold??0,a=i?.longPressDuration??0,d=i?.longPressSlop??8,h=e.pointerId;if(!function(e,t){let n=$.get(e);return n||(n=/* @__PURE__ */new Set,$.set(e,n)),!n.has(t)&&(n.add(t),!0)}(t,h))return()=>{};const u=e.clientX,g=e.clientY;let m=0===c&&0===a,f=!1,w=null,b=!1;function p(){return m=!0,function(){try{return t.setPointerCapture(h),!0}catch{return b=!0,!1}}()?(l?.(),!0):(C(),!1)}function v(){if(!f){var e,n;f=!0,null!==w&&(clearTimeout(w),w=null),t.removeEventListener("pointermove",y),t.removeEventListener("pointerup",S),t.removeEventListener("pointercancel",A),t.removeEventListener("lostpointercapture",x),document.removeEventListener("keydown",E,!0),e=t,n=h,$.get(e)?.delete(n);try{t.hasPointerCapture(h)&&t.releasePointerCapture(h)}catch{}}}function C(){f||(v(),o?.())}function y(e){const t=e;if(t.pointerId!==h||f)return;const n=t.clientX-u,i=t.clientY-g,r=Math.sqrt(n*n+i*i);if(!m){if(a>0)return r>d?void C():void 0;if(c>0&&r<c)return;if(!p())return}s(t)}function S(e){const t=e;if(t.pointerId!==h||f)return;const n=m;v(),n?r(t):o?.()}function A(e){e.pointerId!==h||f||C()}function x(e){e.pointerId!==h||f||C()}function E(e){"Escape"!==e.key||f||C()}return t.addEventListener("pointermove",y),t.addEventListener("pointerup",S),t.addEventListener("pointercancel",A),t.addEventListener("lostpointercapture",x),document.addEventListener("keydown",E,!0),m&&(p(),b)?()=>{}:(a>0&&(w=setTimeout(()=>{w=null,f||p()},a)),C)}var T="tbw-selection-toolbar",F=class{#n=null;#i=null;#s=null;#r=null;get mounted(){return null!==this.#n}get element(){return this.#n}show(e,t,n,i){this.#r=i,this.#n||this.#o(e),this.#i&&(this.#i.textContent=`${t} selected`),this.#n?.setAttribute("data-selected-count",String(t)),this.#s&&(this.#s.hidden=!n)}destroy(){this.#n?.remove(),this.#n=null,this.#i=null,this.#s=null,this.#r=null}#o(e){const t=e.ownerDocument.createElement("div");t.className=T,t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Selection");const n=e.ownerDocument.createElement("span");n.className=`${T}-count`,n.setAttribute("aria-live","polite"),t.appendChild(n);const i=e.ownerDocument.createElement("div");i.className=`${T}-actions`,t.appendChild(i),i.appendChild(this.#l(e,"select-all","Select all",()=>this.#r?.selectAll())),i.appendChild(this.#l(e,"clear","Clear",()=>this.#r?.clear()));const s=this.#l(e,"more","More…",e=>this.#r?.more(e));s.setAttribute("aria-haspopup","menu"),i.appendChild(s),i.appendChild(this.#l(e,"done","Done",()=>this.#r?.done())),e.prepend(t),this.#n=t,this.#i=n,this.#s=s}#l(e,t,n,i){const s=e.ownerDocument.createElement("button");return s.type="button",s.className=`${T}-btn`,s.dataset.action=t,s.textContent=n,s.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),i(s)}),s}},K="tbw-range-handle",D=class{#c=null;#a=null;#r=null;#d=null;render(e,t,n,i){this.#r=i,t?(this.#c??=this.#h(e,"start"),this.#a??=this.#h(e,"end"),this.#u(e,this.#c,n(t.startRow,t.startCol),"start"),this.#u(e,this.#a,n(t.endRow,t.endCol),"end"),this.setArmed(this.#d)):this.#g()}setArmed(e){this.#d=e;for(const[t,n]of[[this.#c,"start"],[this.#a,"end"]]){if(!t)continue;const i=e===n;t.classList.toggle("armed",i),t.setAttribute("aria-pressed",String(i))}}destroy(){this.#c?.remove(),this.#a?.remove(),this.#c=null,this.#a=null,this.#r=null,this.#d=null}#g(){this.#c&&(this.#c.hidden=!0),this.#a&&(this.#a.hidden=!0)}#u(e,t,n,i){if(!t)return;if(!n)return void(t.hidden=!0);t.hidden=!1;const s=n.getBoundingClientRect?.(),r=e.getBoundingClientRect?.();if(!s||!r)return;const o="start"===i?s.left-r.left:s.right-r.left,l="start"===i?s.top-r.top:s.bottom-r.top;t.style.left=`${o}px`,t.style.top=`${l}px`}#h(e,t){const n=e.ownerDocument.createElement("div");return n.className=`${K} ${K}-${t}`,n.dataset.corner=t,n.setAttribute("role","button"),n.setAttribute("tabindex","-1"),n.setAttribute("aria-pressed","false"),n.setAttribute("aria-label","start"===t?"Selection start corner — drag, or activate to place it with a tap":"Selection end corner — drag, or activate to place it with a tap"),n.addEventListener("pointerdown",e=>this.#m(e,n,t)),e.appendChild(n),n}#m(e,t,n){if(0!==e.button&&"mouse"===e.pointerType)return;e.preventDefault(),e.stopPropagation();const i=this.#r;if(!i)return;t.classList.add("dragging");let s=!1;_(e,t,{onMove:e=>{s=!0;const t=i.cellAt(e.clientX,e.clientY);t&&i.resize(n,t.row,t.col)},onEnd:()=>{t.classList.remove("dragging"),s?i.commit():i.arm(n)},onCancel:()=>{t.classList.remove("dragging"),i.commit()}})}};function H(e){if("string"==typeof e)return e;if(Array.isArray(e)){const t=e.find(e=>"column"!==e);if(t)return t;if(e.includes("column"))return"column"}return"cell"}var z="__tbw_checkbox",N=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"];var U=class extends v{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"},{type:"getSelectedColumns",description:"Get field names of selected columns (column mode only)"},{type:"selectColumns",description:"Select specific columns by field name (column mode only)"},{type:"getContextMenuItems",description:"Contribute the non-dragging range-extension action (WCAG 2.2 SC 2.5.7)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:'"triggerOn: \'dblclick\'" has no effect when mode is "range".\n → Range selection uses drag interaction (mousedown → mousemove), not click events.\n → The "triggerOn" option only affects "cell" and "row" selection modes.',check:e=>"range"===H(e.mode)&&"dblclick"===e.triggerOn},{id:"selection/column-checkbox",severity:"warn",message:'"checkbox: true" only renders in row mode.\n → Column selection has no checkbox UI; activate columns via Ctrl+Click on a header or Ctrl+Space on a focused cell.',check:e=>!!e.checkbox&&"row"!==H(e.mode)}]};name="selection";styles='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}:is(tbw-grid:has(.selection)[data-selection-mode=row] .cell-focus,tbw-grid:has(.selection)[data-selection-mode=row] .row-focus,tbw-grid:has(.selection)[data-selection-mode=range] .cell-focus){outline:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background,rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style,var(--tbw-border-style));border-color:var(--tbw-range-border-color,var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width,var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width,var(--tbw-border-width));z-index:26;position:absolute;inset:0}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid .data-grid-row.row-focus>.cell.sticky-left,tbw-grid .data-grid-row.row-focus>.cell.sticky-right{background:linear-gradient(var(--tbw-focus-background,rgba(from var(--tbw-color-accent) r g b / 12%)) 0 0), var(--tbw-color-panel-bg)}tbw-grid .data-grid-row.row-focus[data-selectable=false]>.cell.sticky-left,tbw-grid .data-grid-row.row-focus[data-selectable=false]>.cell.sticky-right{background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";pointer-events:none;border:0 var(--tbw-selection-border-style,var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1;position:absolute;inset:0}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width,var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:var(--tbw-selection-disabled-opacity,.65)}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:var(--tbw-selection-disabled-opacity,.65)}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg,rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm,.8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;justify-content:center;align-items:center;padding:0;display:flex}tbw-grid .tbw-select-row-checkbox{pointer-events:none;cursor:pointer;margin:0}tbw-grid .tbw-checkbox-header{cursor:pointer;justify-content:center;align-items:center;height:100%;display:flex}tbw-grid .tbw-select-all-checkbox{cursor:pointer;margin:0}@media (pointer:coarse){tbw-grid .tbw-select-row-checkbox,tbw-grid .tbw-select-all-checkbox{min-width:var(--tbw-touch-target-min,24px);min-height:var(--tbw-touch-target-min,24px)}}tbw-grid .header-row>.cell.column-selected,tbw-grid .data-grid-row>.cell.column-selected,tbw-grid .data-grid-row>.cell.column-selected.sticky-left,tbw-grid .data-grid-row>.cell.column-selected.sticky-right,tbw-grid .header-row>.cell.column-selected.sticky-left,tbw-grid .header-row>.cell.column-selected.sticky-right{background:linear-gradient(var(--tbw-column-selection-bg,rgba(from var(--tbw-color-accent) r g b / 12%)) 0 0), var(--tbw-color-panel-bg)}tbw-grid .tbw-selection-toolbar{z-index:30;background:var(--tbw-color-panel-bg);border-bottom:1px solid var(--tbw-color-border);justify-content:space-between;align-items:center;gap:8px;padding:4px 8px;font-size:13px;display:flex;position:sticky;top:0}tbw-grid .tbw-selection-toolbar-count{white-space:nowrap;font-weight:600}tbw-grid .tbw-selection-toolbar-actions{align-items:center;gap:4px;display:flex}tbw-grid .tbw-selection-toolbar-btn{min-height:var(--tbw-touch-target-min,24px);border-radius:min(var(--tbw-border-radius,4px), 6px);color:inherit;font:inherit;cursor:pointer;background:0 0;border:0;padding:0 10px}tbw-grid .tbw-selection-toolbar-btn:hover,tbw-grid .tbw-selection-toolbar-btn:focus-visible{background:var(--tbw-color-row-hover,light-dark(#f0f0f0,#2a2a2a))}tbw-grid .tbw-selection-toolbar-btn[data-action=done]{color:var(--tbw-color-accent-text,var(--tbw-color-accent));font-weight:600}tbw-grid .tbw-range-handle{z-index:25;width:var(--tbw-touch-target-min,24px);height:var(--tbw-touch-target-min,24px);background:radial-gradient(circle, var(--tbw-color-accent) 0 5px, transparent 5px);cursor:crosshair;touch-action:none;position:absolute;translate:-50% -50%}tbw-grid .tbw-range-handle[hidden]{display:none}tbw-grid .tbw-range-handle.dragging{scale:1.3}tbw-grid .tbw-range-handle.armed{outline:2px solid var(--tbw-color-accent);outline-offset:-4px;border-radius:50%;scale:1.3}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0,touchMode:"transient"}}get touchSelectionActive(){return this.#f}#f=!1;#w=!1;#b=new F;#p=new D;#v=null;#C=null;#y=null;selected=/* @__PURE__ */new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;pendingRowKeyUpdate=null;selectedCell=null;selectedColumns=/* @__PURE__ */new Set;columnAnchor=null;columnHead=null;activeAxis="none";#S={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:n}=this.config;if(!n)return!0;const i=this.rows[e];return!!i&&n(i,e,void 0!==t?this.visibleColumns[t]:void 0,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.#S=x(this.config.mode),this.on("filter-change",()=>this.clearSelectionSilent()),this.on("group-toggle",()=>this.clearSelectionSilent()),this.on("tree-expand",()=>this.clearSelectionSilent()),this.on("sort-change",()=>this.clearSelectionSilent()),this.on("edit-open",({rowIndex:e,row:t})=>{this.isSelectionEnabled()&&(null==t||e<0||"row"===this.#S.primary&&this.isRowSelectable(e)&&(this.selected.has(e)||(!1===this.config.multiSelect&&this.selected.clear(),this.selected.add(e),this.lastSelected=e,this.anchor=e,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender())))});let t=-1;e.addEventListener("data-change",e=>{const{sourceRowCount:n}=e.detail,i=this.selected.size>0||this.ranges.length>0||null!==this.selectedCell;-1!==t&&n!==t&&i&&this.clearSelectionSilent(),t=n},{signal:this.disconnectSignal}),e.addEventListener("contextmenu",e=>{if(this.#x())return;const t=e.target?.closest?.(".cell[data-row][data-col]");if(!t)return;const n=parseInt(t.getAttribute("data-row")??"-1",10),i=parseInt(t.getAttribute("data-col")??"-1",10),s=this.#E(n,i);s&&(e.preventDefault(),this.#R(t,s))},{signal:this.disconnectSignal})}handleQuery(e){if("getSelection"===e.type)return this.getSelection();if("getSelectedRowIndices"===e.type)return this.getSelectedRowIndices();if("getSelectedRows"===e.type)return this.getSelectedRows();if("selectRows"===e.type)return this.selectRows(e.context),!0;if("getSelectedColumns"===e.type)return this.getSelectedColumns();if("selectColumns"===e.type){const t=e.context;return this.#k(t),!0}if("getContextMenuItems"===e.type){const t=e.context;if(!t||t.isHeader)return;const n=this.#E(t.rowIndex,t.columnIndex);if(!n)return;return n.map((e,t)=>({id:`selection-extend-${t}`,label:e.label,disabled:e.disabled,action:()=>e.run(),order:60+t}))}}detach(){(this.gridElement?.querySelector(".rows-body"))?.removeAttribute("aria-multiselectable"),this.#b.destroy(),this.#p.destroy(),this.#y?.dispose(),this.#y=null,this.#v=null,this.#C=null,this.#f=!1,this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.pendingKeyboardUpdate=null,this.pendingRowKeyUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.announceTimer&&(clearTimeout(this.announceTimer),this.announceTimer=null)}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,"column"!==this.activeAxis&&(this.activeAxis="none"),this.requestAfterRender()}#M(e){const t=e.pointerType;return"touch"===t||"pen"===t||"mouse"!==t&&"coarse"===c()}#I(e){return!!this.isRowSelectable(e)&&(this.#f=!0,this.selected.clear(),this.selected.add(e),this.anchor=e,this.lastSelected=e,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}exitTouchSelection(){this.#f&&(this.#f=!1,"transient"===(this.config.touchMode??"transient")&&(this.selected.clear(),this.anchor=null,this.lastSelected=null,this.emit("selection-change",this.#A())),this.requestAfterRender())}#q(e){const t=this.anchor??e,n=Math.min(t,e),i=Math.max(t,e);for(let s=n;s<=i;s++)this.isRowSelectable(s)&&this.selected.add(s);this.lastSelected=e,this.emit("selection-change",this.#A()),this.requestAfterRender()}#x(){const e=this.grid?.getPluginByName?.("contextMenu")??this.grid?.getPluginByName?.("context-menu");return"function"==typeof e?.showMenu?e:void 0}#P(e,t){return this.gridElement?.querySelector(`.cell[data-row="${e}"][data-col="${t}"]`)??null}#L(e,t){const n=this.gridElement,i=((n?.ownerDocument)?.elementFromPoint?.(e,t))?.closest?.(".cell[data-row][data-col]");if(!i||!n?.contains?.(i))return null;const s=parseInt(i.getAttribute("data-row")??"-1",10),r=parseInt(i.getAttribute("data-col")??"-1",10);return s>=0&&r>=0?{row:s,col:r}:null}#$(e,t,n){const i=this.ranges[this.ranges.length-1];if(!i)return;const s=k(i),r="start"===e?{row:s.endRow,col:s.endCol}:{row:s.startRow,col:s.startCol},o=P(r,{row:t,col:n});L(i,o)||(this.ranges[this.ranges.length-1]=o,this.activeRange=o,this.cellAnchor=r,this.emit("selection-change",this.#A()),this.requestAfterRender())}#E(e,t){if("range"!==this.#S.primary)return null;if(!this.isSelectionEnabled())return null;if(e<0||t<0)return null;if(!this.isCellSelectable(e,t))return null;const n=this.#C;return n?n.row===e&&n.col===t?null:[{label:"Extend selection to here",run:()=>this.#_(e,t)}]:null}#_(e,t){const n=this.#C;if(!n)return;const i=P(n,{row:e,col:t});this.ranges=[i],this.activeRange=i,this.cellAnchor=n,this.emit("selection-change",this.#A()),this.requestAfterRender()}#R(e,t){this.#y??=A("tbw-range-extend-menu","tbw-range-extend-menu"),this.#y.open(e,"Selection",t)}#T(e){this.#v=this.#v===e?null:e,this.#p.setArmed(this.#v),this.gridElement&&i(this.gridElement,this.#v?"Select a cell to place the selection corner":"Selection corner placement cancelled")}#F(){return!!this.#v&&(this.#v=null,this.#p.setArmed(null),!0)}#K(e){if(!e)return;this.#f?this.#b.show(e,this.selected.size,void 0!==this.#x(),{selectAll:()=>this.selectAll(),clear:()=>this.clearSelection(),done:()=>this.exitTouchSelection(),more:e=>this.#D(e)}):this.#b.destroy();const t=this.#w&&"range"===this.#S.primary&&this.ranges.length>0?this.ranges[this.ranges.length-1]:null,n=t?k(t):null;n||this.#F(),this.#p.render(e,n,(e,t)=>this.#P(e,t),{cellAt:(e,t)=>this.#L(e,t),resize:(e,t,n)=>this.#$(e,t,n),commit:()=>this.requestAfterRender(),arm:e=>this.#T(e)})}#D(e){const t=this.#x();if(!t)return;const n=e.getBoundingClientRect?.(),i=this.lastSelected??-1;t.showMenu(n?.left??0,n?.bottom??0,{row:i>=0?this.rows[i]:null,rowIndex:i,selectedRows:this.getSelectedRowIndices()})}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{triggerOn:t="click"}=this.config;if(e.originalEvent.type!==t)return!1;switch(this.#S.primary){case"cell":return this.#H(e);case"row":return this.#z(e);case"range":return this.#N(e);default:return!1}}#H(e){const{rowIndex:t,colIndex:n}=e;if(e.column&&y(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;const i=this.selectedCell;return i&&i.row===t&&i.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()),this.requestAfterRender()),!1}#z(e){const{rowIndex:t,originalEvent:n,column:i}=e;if(!this.isRowSelectable(t))return!1;const s=!1!==this.config.multiSelect,r=n.shiftKey&&s,o=(n.ctrlKey||n.metaKey||this.#f)&&s,l=!0===i?.checkboxColumn;if(r&&null!==this.anchor){const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);o||this.selected.clear();for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(o||l&&s)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(1===this.selected.size&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender(),!1}#N(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e;if(e.column&&y(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;if(this.#v){const e=this.#v;return this.#F(),this.#$(e,t,n),!0}this.#w=this.#M(i);const s=i.shiftKey,r=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(s&&this.cellAnchor){const e=P(this.cellAnchor,{row:t,col:n}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&L(i,e))return!1;r?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else{const e={startRow:t,startCol:n,endRow:t,endCol:n};if(r)this.ranges.push(e);else{if(1===this.ranges.length&&L(this.ranges[0],e))return!1;this.ranges=[e]}this.activeRange=e,this.cellAnchor={row:t,col:n},this.#C={row:t,col:n}}return this.emit("selection-change",this.#A()),this.requestAfterRender(),!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;if(this.#S.columnEnabled&&this.#U(e))return!0;const t=this.#S.primary;if("Escape"===e.key&&this.#F())return!0;if("Escape"===e.key&&this.#f)return this.exitTouchSelection(),!0;if("Escape"===e.key)return this.#j(t);const n=N.includes(e.key);switch(t){case"cell":return!!n&&this.#O();case"row":return this.#B(e);case"range":return this.#G(e,n);default:return!1}}#U(e){if(!e.ctrlKey&&!e.metaKey)return!1;if(" "===e.key||"Spacebar"===e.key){const t=this.visibleColumns[this.grid._focusCol];return!(!t||y(t)||"string"!=typeof t.field)&&(e.preventDefault(),e.stopPropagation(),this.selectColumn(t.field,{toggle:!0}),!0)}if(e.shiftKey&&"column"===this.activeAxis&&!1!==this.config.multiSelect&&("ArrowLeft"===e.key||"ArrowRight"===e.key)){const t=E(this.visibleColumns),n="ArrowLeft"===e.key?"left":"right",i=function(e,t,n){if(0===t.length)return null;if(null===e)return null;const i=R(e,t);if(i<0)return null;const s="left"===n?Math.max(0,i-1):Math.min(t.length-1,i+1);return s===i?null:t[s]}(this.columnHead,t,n);return null!==i&&null!==this.columnAnchor&&(e.preventDefault(),e.stopPropagation(),this.selectColumn(i,{range:!0}),!0)}return!1}#j(e){return!this.grid.query("isEditing").some(Boolean)&&("column"===this.activeAxis?(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none"):"cell"===e?this.selectedCell=null:"row"===e?(this.selected.clear(),this.anchor=null):"range"===e&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#O(){return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.selectedCell=this.isCellSelectable(e,t)?{row:e,col:t}:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}),!1}#B(e){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const n=e.shiftKey&&t;return n&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}return this.#W(e,t)}#G(e,t){if(!t)return this.#W(e,!1!==this.config.multiSelect);const n=e.shiftKey&&"Tab"!==e.key;return n&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}#W(e,t){return!(!t||"a"!==e.key||!e.ctrlKey&&!e.metaKey)&&(!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0))}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("row"===this.#S.primary){if(void 0===e.rowIndex||e.rowIndex<0)return;if(!1===this.config.multiSelect)return;if(!this.#M(e.originalEvent))return;if(e.column&&y(e.column))return;return this.#f?(this.#q(e.rowIndex),!0):this.#I(e.rowIndex)||void 0}if("range"!==this.#S.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(this.#v)return!0;if(this.#w=this.#M(e.originalEvent),2===e.originalEvent.button&&I(e.rowIndex,e.colIndex,this.ranges))return;if(e.column&&y(e.column))return;if(!this.isCellSelectable(e.rowIndex,e.colIndex))return;if(e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,n=e.colIndex,i=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,s={startRow:t,startCol:n,endRow:t,endCol:n};return!i&&1===this.ranges.length&&L(this.ranges[0],s)?(this.cellAnchor={row:t,col:n},this.#V(e,t,n),!0):(this.cellAnchor={row:t,col:n},this.#V(e,t,n),i||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#V(e,t,n){2!==e.originalEvent.button&&(this.#C={row:t,col:n})}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#S.primary)return;if(!this.isDragging||!this.cellAnchor)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;let t=e.colIndex;const n=this.visibleColumns[t];if(n&&y(n)){const e=this.visibleColumns.findIndex(e=>!y(e));e>=0&&(t=e)}const i=P(this.cellAnchor,{row:e.rowIndex,col:t}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return s&&L(s,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#A()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#S.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#S.columnEnabled)return!1;if(e.column&&y(e.column))return!1;const t=e.originalEvent;if(!t.ctrlKey&&!t.metaKey)return!1;const n=e.field;if(!n)return!1;t.preventDefault(),"function"==typeof t.stopPropagation&&t.stopPropagation();const i=!0===t.shiftKey&&!1!==this.config.multiSelect&&null!==this.columnAnchor;return this.selectColumn(n,i?{range:!0}:{toggle:!0}),!0}processColumns(e){if(this.config.checkbox&&"row"===this.#S.primary){if(e.some(e=>e.field===z))return e;const t=this.#X(),n=e.findIndex(C),i=n>=0?n+1:0;return[...e.slice(0,i),t,...e.slice(i)]}return e}#X(){return{field:z,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("label");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-all-checkbox";const n=document.createElement("span");return n.className="tbw-sr-only",n.textContent=s(this.gridElement,"selectAllRows"),t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.addEventListener("click",e=>e.stopPropagation()),e.append(t,n),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const n=e.cellEl,i=n?parseInt(n.getAttribute("data-row")??"-1",10):-1;return i>=0&&(t.checked=this.selected.has(i)),t.setAttribute("aria-label",s(this.gridElement,"selectRow",Math.max(i,0))),t}}}#Y(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),n=t?a(t):-1;n>=0&&(e.checked=this.selected.has(n))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let n=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&n++;else n=e;const i=n>0&&this.selected.size>=n,s=this.selected.size>0;t.checked=i,t.indeterminate=s&&!i}}#J(){return this.gridElement?.hasAttribute("data-has-focus")??!1}#Q(e){const t=this.grid._focusRow,n=this.grid._focusCol;if(!this.#J())return this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=n);if("row"===e){if(this.explicitSelection)return this.explicitSelection=!1,void(this.lastSyncedFocusRow=t);t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(this.selected.has(t)&&1===this.selected.size||(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#A()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=n);if((t!==this.lastSyncedFocusRow||n!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=n,this.isCellSelectable(t,n))){const e=this.selectedCell;e&&e.row===t&&e.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()))}}}#Z(){const t=this.gridElement;if(!t)return;const n=this.#S.primary,i=this.#S.columnEnabled,s=!!this.config.isSelectable,r=t.querySelector(".rows-body");if(r){const e=!1!==this.config.multiSelect;r.setAttribute("aria-multiselectable",e?"true":"false")}t.querySelectorAll(".cell").forEach(t=>{const n=t.classList.contains(e)||t.classList.contains("column-selected");t.classList.remove(e,"top","bottom","first","last","column-selected"),n&&t.removeAttribute("aria-selected"),s&&t.removeAttribute("data-selectable")});const o=t.querySelectorAll(".data-grid-row");if(o.forEach(t=>{t.classList.remove(e,"row-focus"),t.setAttribute("aria-selected","false"),s&&t.removeAttribute("data-selectable")}),i&&t.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")}),"row"===n&&(d(t),o.forEach(t=>{const n=a(t.querySelector(".cell[data-row]"));n>=0&&(s&&!this.isRowSelectable(n)&&t.setAttribute("data-selectable","false"),this.selected.has(n)&&(t.classList.add(e,"row-focus"),t.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#Y(t)),"cell"!==n&&"range"!==n||!s||t.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),n=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&n>=0&&(this.isCellSelectable(t,n)||e.setAttribute("data-selectable","false"))}),"range"===n&&this.ranges.length>0){d(t);const n=this.ranges.map(k),i=(e,t)=>{for(const i of n)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};t.querySelectorAll(".cell[data-row][data-col]").forEach(t=>{const n=parseInt(t.getAttribute("data-row")??"-1",10),s=parseInt(t.getAttribute("data-col")??"-1",10);if(n>=0&&s>=0){const r=this.visibleColumns[s];if(r&&y(r))return;i(n,s)&&(t.classList.add(e),t.setAttribute("aria-selected","true"),i(n-1,s)||t.classList.add("top"),i(n+1,s)||t.classList.add("bottom"),i(n,s-1)||t.classList.add("first"),i(n,s+1)||t.classList.add("last"))}})}if(i&&this.selectedColumns.size>0){const e=this.visibleColumns.map(e=>"string"==typeof e.field?e.field:void 0);t.querySelectorAll(".header-row > .cell[data-col]").forEach(t=>{const n=parseInt(t.getAttribute("data-col")??"-1",10),i=n>=0?e[n]:void 0;i&&this.selectedColumns.has(i)&&(t.classList.add("column-selected"),t.setAttribute("aria-selected","true"))}),t.querySelectorAll(".cell[data-col]:not(.header-row .cell)").forEach(t=>{if(t.closest(".header-row"))return;const n=parseInt(t.getAttribute("data-col")??"-1",10);if(n<0)return;const i=this.visibleColumns[n];if(!i||y(i))return;const s=e[n];s&&this.selectedColumns.has(s)&&(t.classList.add("column-selected"),t.setAttribute("aria-selected","true"))})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root"),n=this.#S.primary;if(this.pendingRowKeyUpdate&&"row"===n){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#A())}if(this.pendingKeyboardUpdate&&"range"===n){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,n=this.grid._focusCol;if(e&&this.cellAnchor){const e=P(this.cellAnchor,{row:t,col:n});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:n});this.emit("selection-change",this.#A())}this.#Q(n),this.gridElement.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#Z(),this.#K(t)}onScrollRender(){this.isSelectionEnabled()&&this.#Z()}getSelection(){const e=this.#A();return{mode:this.config.mode,activeAxis:e.activeAxis,ranges:e.ranges,selectedColumns:e.selectedColumns,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=/* @__PURE__ */new Map;for(const n of e)for(const e of q(n))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return I(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const n={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[n],this.activeRange=n,this.emit("selection-change",this.#A()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#S.primary)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const n of t)n>=0&&n<this.rows.length&&this.isRowSelectable(n)&&this.selected.add(n);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const e=this.#S.primary,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=/* @__PURE__ */new Set;for(const n of this.ranges){const i=Math.max(0,Math.min(n.startRow,n.endRow)),s=Math.min(t.length-1,Math.max(n.startRow,n.endRow));for(let t=i;t<=s;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}#k(e){if(!this.#S.columnEnabled)return;const t=E(this.visibleColumns),n=new Set(t),i=[],s=/* @__PURE__ */new Set;for(const o of e)n.has(o)&&!s.has(o)&&(s.add(o),i.push(o));this.#ee("column"),this.selectedColumns.clear();for(const o of i)this.selectedColumns.add(o);const r=i.length>0?i[i.length-1]:null;this.columnAnchor=r,this.columnHead=r,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#S.columnEnabled)return;const n=E(this.visibleColumns);if(n.includes(e)){if(this.#ee("column"),!1===this.config.multiSelect)this.selectedColumns.clear(),this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e;else if(t.range&&this.columnAnchor){const t=function(e,t,n){const i=R(e,n),s=R(t,n);if(-1===i||-1===s)return[];const r=Math.min(i,s),o=Math.max(i,s);return n.slice(r,o+1)}(this.columnAnchor,e,n);this.selectedColumns.clear();for(const e of t)this.selectedColumns.add(e);this.columnHead=e}else t.toggle?(this.selectedColumns.has(e)?this.selectedColumns.delete(e):this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e):(this.selectedColumns.clear(),this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e);this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}}deselectColumn(e){this.#S.columnEnabled&&this.selectedColumns.delete(e)&&(0===this.selectedColumns.size&&(this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none")),this.emit("selection-change",this.#A()),this.requestAfterRender())}selectAllColumns(){if(!this.#S.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=E(this.visibleColumns);if(0!==e.length){this.#ee("column"),this.selectedColumns.clear();for(const t of e)this.selectedColumns.add(t);this.columnAnchor=e[0],this.columnHead=e[e.length-1],this.activeAxis="column",this.emit("selection-change",this.#A()),this.requestAfterRender()}}clearColumnSelection(){0!==this.selectedColumns.size&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none"),this.emit("selection-change",this.#A()),this.requestAfterRender())}getSelectedColumns(){return 0===this.selectedColumns.size?[]:E(this.visibleColumns).filter(e=>this.selectedColumns.has(e))}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.emit("selection-change",this.#A()),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}#A(){const e=this.#S.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let n;this.#S.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&i(this.gridElement,s(this.gridElement,"selectionAxisChanged","row"))),n=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=n;const r=function(e,t,n,i,s,r){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:r.filter(e=>i.selectedColumns.has(e))};if("cell"===n&&i.selectedCell)return{mode:e,activeAxis:"cell",ranges:[{from:{row:i.selectedCell.row,col:i.selectedCell.col},to:{row:i.selectedCell.row,col:i.selectedCell.col}}],selectedColumns:[]};if("row"===n&&i.selected.size>0){const t=[...i.selected].sort((e,t)=>e-t),n=[];let r=t[0],o=r;for(let e=1;e<t.length;e++)t[e]===o+1?o=t[e]:(n.push({from:{row:r,col:0},to:{row:o,col:s-1}}),r=t[e],o=r);return n.push({from:{row:r,col:0},to:{row:o,col:s-1}}),{mode:e,activeAxis:"row",ranges:n,selectedColumns:[]}}return"range"===n&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(o=i.ranges,o.map(M)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var o}(this.config.mode,n,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,E(this.visibleColumns));return this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if("column"===r.activeAxis){const e=r.selectedColumns;if(1===e.length){const t=e[0],n=this.columns.find(e=>e.field===t),r="string"==typeof n?.header&&n.header||t;i(this.gridElement,s(this.gridElement,"columnSelected",r))}else e.length>1?i(this.gridElement,s(this.gridElement,"columnSelectionChanged",e.length)):i(this.gridElement,s(this.gridElement,"columnSelectionCleared"))}else{const e="row"===r.activeAxis?this.selected.size:r.ranges.length;e>0&&i(this.gridElement,s(this.gridElement,"selectionChanged",e))}},150),r}#ee(e){if(this.#S.bothAxes&&"column"===e){if(!(this.selected.size>0||null!==this.selectedCell||this.ranges.length>0))return;this.selected.clear(),this.lastSelected=null,this.anchor=null,this.selectedCell=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.gridElement&&i(this.gridElement,s(this.gridElement,"selectionAxisChanged","column"))}}};export{U as SelectionPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}var e="TBW140";function o(e,o,r,s){return`${t(r,s)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}function r(t,e,r,s){console.debug(o(t,e,r,s))}function s(t,e,r,s){console.error(o(t,e,r,s))}var n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"},i=/* @__PURE__ */new WeakMap;function a(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var l=/* @__PURE__ */new Map;function c(t){if(-1===t.indexOf("."))return null;let e=l.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),l.set(t,e)),e}function d(t,e){let o=t;for(let r=0;r<e.length;r++){if(null==o||"object"!=typeof o)return;const t=e[r];if(a(t))return;o=o[t]}return o}function u(t){const e=c(t);return null===e?a(t)?()=>{}:e=>null==e?void 0:e[t]:o=>{if(null==o)return;const r=o;return Object.prototype.hasOwnProperty.call(r,t)?r[t]:d(r,e)}}function h(t,e,o=-1){if(!e.valueAccessor)return function(t,e){if(null==t)return;const o=c(e),r=t;return null===o?a(e)?void 0:r[e]:Object.prototype.hasOwnProperty.call(r,e)?r[e]:d(r,o)}(t,e.field);if("object"!=typeof t||null===t)return e.valueAccessor({row:t,column:e,rowIndex:o});const r=t,s=e.field;let n=i.get(r);if(n){const t=n.get(s);if(void 0!==t)return t.v}else n=/* @__PURE__ */new Map,i.set(r,n);const l=e.valueAccessor({row:t,column:e,rowIndex:o});return n.set(s,{v:l}),l}function g(t,e,o){const r=[...t];return function(t,e,o,r){const s=r.find(t=>t.field===e),n=s?.sortComparator;if(n)if(s?.valueAccessor)t.sort((t,e)=>n(h(t,s),h(e,s),t,e)*o);else{const r=u(e);t.sort((t,e)=>n(r(t),r(e),t,e)*o)}else s?.valueAccessor?function(t,e,o){f(t,t=>h(t,e),o)}(t,s,o):function(t,e,o){if(function(t){return-1===t.indexOf(".")&&!a(t)}(e))return void t.sort((t,r)=>{const s=function(t,e){const o=!0===t?.__loading;return o===(!0===e?.__loading)?0:o?1:-1}(t,r);if(0!==s)return s;const n=t[e],i=r[e];return null==n&&null==i?0:null==n?-o:null==i||n>i?o:n<i?-o:0});f(t,u(e),o)}(t,e,o)}(r,e.field,e.direction,o),r}function f(t,e,o){const r=t.length;if(r<2)return;const s=new Array(r),n=new Uint8Array(r),i=new Array(r);for(let l=0;l<r;l++){const o=t[l];i[l]=l,s[l]=e(o),n[l]=!0===o?.__loading?1:0}i.sort((t,e)=>{const r=n[t];if(r!==n[e])return r?1:-1;const i=s[t],a=s[e];return null==i&&null==a?0:null==i?-o:null==a||i>a?o:i<a?-o:0});const a=new Array(r);for(let l=0;l<r;l++)a[l]=t[i[l]];for(let l=0;l<r;l++)t[l]=a[l]}var m="__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("")),p=(new RegExp(`__(proto|defineGetter|defineSetter)|${m.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("|"))),b=/^on\w+$/i,w=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),C=/^\s*(javascript|vbscript|data|blob):/i;function v(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const r of o){const t=r.tagName.toLowerCase();if(p.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>b.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}const o=[];for(const e of r.attributes){const t=e.name.toLowerCase();b.test(t)?o.push(e.name):"is"!==t?(w.has(t)&&C.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name):o.push(e.name)}o.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var S=class{static dependencies;static manifest;aliases;version="3.8.0";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},r={};for(const o of Object.keys(e))r[o]=this;for(const s of t){const t=s.userConfig;for(const[n,i]of Object.entries(t)){if(void 0===i)continue;if(!(n in e)){e[n]=i,r[n]=s;continue}if(e[n]===i)continue;const t=r[n]?.constructor.name??this.constructor.name,a=s.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,o={...t.userConfig};for(const r of Object.keys(e))delete e[r];Object.assign(e,o)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const o=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const o=this.grid?.query?.(t,e);return Array.isArray(o)?o.some(Boolean):!!o}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...n,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(e,10);if(!isNaN(o))return o}return 200}setIcon(t,e,o){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,o);var s,n;void 0!==r?"string"==typeof r?(s=t,(n=r)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?s.replaceChildren(v(n)):s.textContent=n:s.replaceChildren()):r instanceof HTMLElement&&t.replaceChildren(r.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(o,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(o,r):t.appendChild(o),o}warn(e,r){void 0!==r?console.warn(o(e,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(t,e){throw new Error(o(t,e,this.gridElement.id,this.name))}};function k(t,e){return Math.floor(t/e)}function N(){return new DOMException("Aborted","AbortError")}function y(t,e,o,r,s){const n=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return function(t,e){return e.aborted?Promise.reject(N()):"object"!=typeof(o=t)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,r)=>{const s=()=>r(N());e.addEventListener("abort",s,{once:!0}),Promise.resolve(t).then(t=>{e.removeEventListener("abort",s),o(t)},t=>{e.removeEventListener("abort",s),r(t)})}):new Promise((o,r)=>{let s=!1;const n=t.subscribe({next:t=>{s||(s=!0,o(t),n.unsubscribe())},error:t=>{s||(s=!0,r(t))},complete:()=>{s||(s=!0,r(/* @__PURE__ */new Error("getRows observable completed without emitting a value")))}});s||e.addEventListener("abort",()=>{s||(s=!0,n.unsubscribe(),r(N()))},{once:!0})});var o}(t.getRows({startNode:n.start,endNode:n.end,pageSize:n.end-n.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:s}),s)}function B(t,e,o){const r=k(t,e),s=o.get(r);if(s)return s[t%e]}function R(t){let e=null;return{async getRows({startNode:o,endNode:r,signal:s}){const{rows:n,total:i}=await(o=>(e||(e=fetch(t,{signal:o}).then(async e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}": ${e.status} ${e.statusText}`);const o=await e.json();if(Array.isArray(o))return{rows:o,total:o.length};const r=o??{},s=Array.isArray(r.rows)?r.rows:[];return{rows:s,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:s.length}}).catch(t=>{throw e=null,t})),e))(s);return{rows:n.slice(o,r),totalNodeCount:i}}}}var M=class extends S{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-10},incompatibleWith:[{name:"pivot",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],events:[{type:"datasource:data",description:"Root data page/block loaded"},{type:"datasource:children",description:"Child data loaded for a parent context"},{type:"datasource:loading",description:"Loading state changed"},{type:"datasource:error",description:"Fetch operation failed"}],queries:[{type:"datasource:fetch-children",description:"Request child rows for a parent context"},{type:"datasource:is-active",description:"Check if ServerSide plugin has an active data source"}]};name="serverSide";get defaultConfig(){return{maxConcurrentRequests:2}}dataSource=null;totalNodeCount=0;infiniteScrollMode=!1;loadedBlocks=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;blockControllers=/* @__PURE__ */new Map;lastRequestId=0;scrollDebounceTimer;managedNodes=[];attach(t){if(super.attach(t),this.on("sort-change",()=>{"local"===this.config.sortMode?this.requestRender():this.onModelChange()}),this.on("filter-change",()=>{"local"===this.config.filterMode?this.requestRender():this.onModelChange()}),this.config.dataSource)return void this.setDataSource(this.config.dataSource);const e=this.gridElement?.getAttribute("data-src");e&&this.setDataSource(R(e))}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.abortAllBlocks(),this.managedNodes=[],this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}abortAllBlocks(){for(const t of this.blockControllers.values())t.abort();this.blockControllers.clear()}getEnrichmentParams(){const t="local"===this.config.sortMode,e="local"===this.config.filterMode,o=t?void 0:this.grid?.query?.("sort:get-model",null),r=e?void 0:this.grid?.query?.("filter:get-model",null);let s=o?.[0];const n=this.grid;if(!t&&!s&&n?._sortState){const{field:t,direction:e}=n._sortState;s=[{field:t,direction:1===e?"asc":"desc"}]}return{sortModel:s,filterModel:r?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},r=this.grid?.query?.("datasource:viewport-mapping",o);return r?.[0]?r[0]:{startNode:t,endNode:e,totalLoadedNodes:this.totalNodeCount}}onModelChange(){this.dataSource&&(this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.requestRender(),this.loadRequiredBlocks())}applyServerResult(t,e,o){void 0!==t.lastNode?(this.totalNodeCount=t.lastNode+1,this.infiniteScrollMode=!1):-1===t.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=t.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&t.rows.length<o&&(this.totalNodeCount=e*o+t.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(t){let e=0;for(const[o,r]of this.loadedBlocks){const s=o*t+r.length;s>e&&(e=s)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:t}=this.grid,o=this.config.pageSize??100,n=this.getViewportMapping(t.start,t.end),i=Math.max(0,this.config.loadThreshold??0),a=Math.max(0,n.startNode-i),l=this.totalNodeCount>0?this.totalNodeCount:1/0,c=Math.min(l,n.endNode+i);if(c<=a)return;const d=function(t,e,o){const r=k(t,o),s=k(e-1,o),n=[];for(let i=r;i<=s;i++)n.push(i);return n}(a,c,o),u=this.getEnrichmentParams(),h=this.grid?.getAttribute?.("id")??void 0;for(const g of d){if(this.loadedBlocks.has(g)||this.loadingBlocks.has(g))continue;if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){r("TBW143","Concurrent request limit reached, deferring block load",h);break}this.loadingBlocks.add(g);const t=new AbortController;this.blockControllers.set(g,t),this.broadcast("datasource:loading",{loading:!0}),y(this.dataSource,g,o,u,t.signal).then(e=>{if(this.blockControllers.delete(g),t.signal.aborted)return this.loadingBlocks.delete(g),void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(g,e.rows);const r=this.managedNodes.length;this.applyServerResult(e,g,o),this.loadingBlocks.delete(g);const s=g*o;for(let t=0;t<e.rows.length;t++)s+t<this.managedNodes.length&&(this.managedNodes[s+t]=e.rows[t]);const n={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:s,endNode:s+e.rows.length,claimed:!1};this.broadcast("datasource:data",n),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||n.claimed||this.managedNodes.length<(Number.isFinite(this.totalNodeCount)?this.totalNodeCount:0)?this.requestRender():this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(o=>{if(this.blockControllers.delete(g),this.loadingBlocks.delete(g),t.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const r=o instanceof Error?o:new Error(String(o));s(e,`getRows() failed: ${r.message}`,h),this.broadcast("datasource:error",{error:r}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.pageSize??100,o=this.infiniteScrollMode?this.getInfiniteScrollEstimate(e):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<o;){const t=this.managedNodes.length;this.managedNodes.push({__loading:!0,__index:t})}this.managedNodes.length=o;for(let s=0;s<o;s++){const t=B(s,e,this.loadedBlocks);t&&(this.managedNodes[s]=t)}const r=this.grid;if("local"===this.config.sortMode&&r?._sortState){const t=r._columns??[],e=(r.effectiveConfig?.sortHandler??g)(this.managedNodes,r._sortState,t);return e&&"function"==typeof e.then?(e.catch(()=>{}),this.managedNodes):e}return this.managedNodes}onScroll(t){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(t){switch(t.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:e}=t.context;return void this.fetchChildren(e)}}}fetchChildren(t){if(!this.dataSource)return;const e=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void function(t,e,r,s){console.warn(o(t,e,r,s))}("TBW142",`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,e);const r=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:r.sortModel,filterModel:r.filterModel}).then(e=>{const o={rows:e.rows,context:t,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:t})}).catch(o=>{const r=o instanceof Error?o:new Error(String(o));s("TBW141",`getChildRows() failed: ${r.message}`,e),this.broadcast("datasource:error",{error:r,context:t}),this.broadcast("datasource:loading",{loading:!1,context:t})})}setDataSource(t){this.abortAllBlocks(),this.dataSource=t,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1;const o=this.config.pageSize??100,r=this.getEnrichmentParams(),n=this.grid?.getAttribute?.("id")??void 0,i=new AbortController;this.blockControllers.set(0,i),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),y(t,0,o,r,i.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});this.loadedBlocks.set(0,t.rows),this.applyServerResult(t,0,o);const e={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",e),this.broadcast("datasource:loading",{loading:!1}),this.requestRender(),(this.config.loadThreshold??0)>0&&this.loadRequiredBlocks()}).catch(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const o=t instanceof Error?t:new Error(String(t));s(e,`getRows() failed: ${o.message}`,n),this.broadcast("datasource:error",{error:o}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const t=this.dataSource;this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(t)}purgeCache(){this.abortAllBlocks(),this.loadedBlocks.clear(),this.managedNodes=[]}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(t){const e=k(t,this.config.pageSize??100);return this.loadedBlocks.has(e)}getLoadedBlockCount(){return this.loadedBlocks.size}};export{M as ServerSidePlugin};
|
|
1
|
+
function t(t,e){return`[tbw-grid${t?`#${t}`:""}${e?`:${e}`:""}]`}var e="TBW140";function o(e,o,r,s){return`${t(r,s)} ${e}: ${o}\n\n → More info: ${function(t){return`https://toolboxjs.com/grid/errors#${t.toLowerCase()}`}(e)}`}function r(t,e,r,s){console.debug(o(t,e,r,s))}function s(t,e,r,s){console.error(o(t,e,r,s))}var n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"},i=/* @__PURE__ */new WeakMap;function a(t){return"__proto__"===t||"constructor"===t||"prototype"===t}var l=/* @__PURE__ */new Map;function c(t){if(-1===t.indexOf("."))return null;let e=l.get(t);return void 0===e&&(e=Object.freeze(t.split(".")),l.set(t,e)),e}function d(t,e){let o=t;for(let r=0;r<e.length;r++){if(null==o||"object"!=typeof o)return;const t=e[r];if(a(t))return;o=o[t]}return o}function u(t){const e=c(t);return null===e?a(t)?()=>{}:e=>null==e?void 0:e[t]:o=>{if(null==o)return;const r=o;return Object.prototype.hasOwnProperty.call(r,t)?r[t]:d(r,e)}}function h(t,e,o=-1){if(!e.valueAccessor)return function(t,e){if(null==t)return;const o=c(e),r=t;return null===o?a(e)?void 0:r[e]:Object.prototype.hasOwnProperty.call(r,e)?r[e]:d(r,o)}(t,e.field);if("object"!=typeof t||null===t)return e.valueAccessor({row:t,column:e,rowIndex:o});const r=t,s=e.field;let n=i.get(r);if(n){const t=n.get(s);if(void 0!==t)return t.v}else n=/* @__PURE__ */new Map,i.set(r,n);const l=e.valueAccessor({row:t,column:e,rowIndex:o});return n.set(s,{v:l}),l}function g(t,e,o){const r=[...t];return function(t,e,o,r){const s=r.find(t=>t.field===e),n=s?.sortComparator;if(n)if(s?.valueAccessor)t.sort((t,e)=>n(h(t,s),h(e,s),t,e)*o);else{const r=u(e);t.sort((t,e)=>n(r(t),r(e),t,e)*o)}else s?.valueAccessor?function(t,e,o){f(t,t=>h(t,e),o)}(t,s,o):function(t,e,o){if(function(t){return-1===t.indexOf(".")&&!a(t)}(e))return void t.sort((t,r)=>{const s=function(t,e){const o=!0===t?.__loading;return o===(!0===e?.__loading)?0:o?1:-1}(t,r);if(0!==s)return s;const n=t[e],i=r[e];return null==n&&null==i?0:null==n?-o:null==i||n>i?o:n<i?-o:0});f(t,u(e),o)}(t,e,o)}(r,e.field,e.direction,o),r}function f(t,e,o){const r=t.length;if(r<2)return;const s=new Array(r),n=new Uint8Array(r),i=new Array(r);for(let l=0;l<r;l++){const o=t[l];i[l]=l,s[l]=e(o),n[l]=!0===o?.__loading?1:0}i.sort((t,e)=>{const r=n[t];if(r!==n[e])return r?1:-1;const i=s[t],a=s[e];return null==i&&null==a?0:null==i?-o:null==a||i>a?o:i<a?-o:0});const a=new Array(r);for(let l=0;l<r;l++)a[l]=t[i[l]];for(let l=0;l<r;l++)t[l]=a[l]}var m="__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("")),p=(new RegExp(`__(proto|defineGetter|defineSetter)|${m.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("|"))),b=/^on\w+$/i,w=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),C=/^\s*(javascript|vbscript|data|blob):/i;function v(t){const e=document.createElement("template");return t&&"string"==typeof t&&(e.innerHTML=t,function(t){const e=[],o=t.querySelectorAll("*");for(const r of o){const t=r.tagName.toLowerCase();if(p.has(t)){e.push(r);continue}if(("svg"===t||"http://www.w3.org/2000/svg"===r.namespaceURI)&&Array.from(r.attributes).some(t=>b.test(t.name)||"href"===t.name||"xlink:href"===t.name)){e.push(r);continue}const o=[];for(const e of r.attributes){const t=e.name.toLowerCase();b.test(t)?o.push(e.name):"is"!==t?(w.has(t)&&C.test(e.value)||"style"===t&&/expression\s*\(|javascript:|behavior\s*:/i.test(e.value))&&o.push(e.name):o.push(e.name)}o.forEach(t=>r.removeAttribute(t))}e.forEach(t=>t.remove())}(e.content)),e.content}var S=class{static dependencies;static manifest;aliases;version="3.8.2";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}get resolvedConfig(){return this.#t?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(t){if(0===t.length)return;const e={...this.userConfig},r={};for(const o of Object.keys(e))r[o]=this;for(const s of t){const t=s.userConfig;for(const[n,i]of Object.entries(t)){if(void 0===i)continue;if(!(n in e)){e[n]=i,r[n]=s;continue}if(e[n]===i)continue;const t=r[n]?.constructor.name??this.constructor.name,a=s.constructor.name,l=o("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${n}" supplied by both ${t} and ${a}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,e)}refreshUserConfigFrom(t){const e=this.userConfig,o={...t.userConfig};for(const r of Object.keys(e))delete e[r];Object.assign(e,o)}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const o=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}broadcast(t,e){this.emitPluginEvent(t,e),this.emit(t,e)}queryBoolean(t,e=null){const o=this.grid?.query?.(t,e);return Array.isArray(o)?o.some(Boolean):!!o}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...n,...t}}t(t,e){return this.grid?.effectiveConfig?.locale?.[t]??e}get translate(){return(t,e)=>this.t(t,e)}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;return!e||"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(e,10);if(!isNaN(o))return o}return 200}setIcon(t,e,o){t.dataset.icon=e.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===e?t.dataset.expanded="":"expand"===e&&delete t.dataset.expanded;const r=this.#e(e,o);var s,n;void 0!==r?"string"==typeof r?(s=t,(n=r)&&"string"==typeof n?-1!==n.indexOf("<")||-1!==n.indexOf("&")?s.replaceChildren(v(n)):s.textContent=n:s.replaceChildren()):r instanceof HTMLElement&&t.replaceChildren(r.cloneNode(!0)):t.innerHTML=""}#e(t,e){return void 0!==e?e:this.grid?.gridConfig?.icons?.[t]}updateSortIndicator(t,e){t.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",e?(t.setAttribute("aria-sort","asc"===e?"ascending":"descending"),t.setAttribute("data-sort",e),this.setIcon(o,"asc"===e?"sortAsc":"sortDesc")):(t.setAttribute("aria-sort","none"),t.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const r=t.querySelector(".tbw-filter-btn")??t.querySelector(".resize-handle");return r?t.insertBefore(o,r):t.appendChild(o),o}warn(e,r){void 0!==r?console.warn(o(e,r,this.gridElement.id,this.name)):console.warn(`${t(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(t,e){throw new Error(o(t,e,this.gridElement.id,this.name))}};function k(t,e){return Math.floor(t/e)}function N(){return new DOMException("Aborted","AbortError")}function y(t,e,o,r,s){const n=function(t,e){return{start:t*e,end:(t+1)*e}}(e,o);return function(t,e){return e.aborted?Promise.reject(N()):"object"!=typeof(o=t)||null===o||"function"!=typeof o.subscribe||"function"==typeof o.then?new Promise((o,r)=>{const s=()=>r(N());e.addEventListener("abort",s,{once:!0}),Promise.resolve(t).then(t=>{e.removeEventListener("abort",s),o(t)},t=>{e.removeEventListener("abort",s),r(t)})}):new Promise((o,r)=>{let s=!1;const n=t.subscribe({next:t=>{s||(s=!0,o(t),n.unsubscribe())},error:t=>{s||(s=!0,r(t))},complete:()=>{s||(s=!0,r(/* @__PURE__ */new Error("getRows observable completed without emitting a value")))}});s||e.addEventListener("abort",()=>{s||(s=!0,n.unsubscribe(),r(N()))},{once:!0})});var o}(t.getRows({startNode:n.start,endNode:n.end,pageSize:n.end-n.start,sortModel:r.sortModel,filterModel:r.filterModel,signal:s}),s)}function B(t,e,o){const r=k(t,e),s=o.get(r);if(s)return s[t%e]}function R(t){let e=null;return{async getRows({startNode:o,endNode:r,signal:s}){const{rows:n,total:i}=await(o=>(e||(e=fetch(t,{signal:o}).then(async e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}": ${e.status} ${e.statusText}`);const o=await e.json();if(Array.isArray(o))return{rows:o,total:o.length};const r=o??{},s=Array.isArray(r.rows)?r.rows:[];return{rows:s,total:"number"==typeof r.totalNodeCount?r.totalNodeCount:s.length}}).catch(t=>{throw e=null,t})),e))(s);return{rows:n.slice(o,r),totalNodeCount:i}}}}var M=class extends S{static manifest={modifiesRowStructure:!0,hookPriority:{processRows:-10},incompatibleWith:[{name:"pivot",reason:"PivotPlugin requires the full dataset to compute aggregations. ServerSidePlugin lazy-loads rows in blocks, so pivot aggregation cannot be performed client-side."}],events:[{type:"datasource:data",description:"Root data page/block loaded"},{type:"datasource:children",description:"Child data loaded for a parent context"},{type:"datasource:loading",description:"Loading state changed"},{type:"datasource:error",description:"Fetch operation failed"}],queries:[{type:"datasource:fetch-children",description:"Request child rows for a parent context"},{type:"datasource:is-active",description:"Check if ServerSide plugin has an active data source"}]};name="serverSide";get defaultConfig(){return{maxConcurrentRequests:2}}dataSource=null;totalNodeCount=0;infiniteScrollMode=!1;loadedBlocks=/* @__PURE__ */new Map;loadingBlocks=/* @__PURE__ */new Set;blockControllers=/* @__PURE__ */new Map;lastRequestId=0;scrollDebounceTimer;managedNodes=[];attach(t){if(super.attach(t),this.on("sort-change",()=>{"local"===this.config.sortMode?this.requestRender():this.onModelChange()}),this.on("filter-change",()=>{"local"===this.config.filterMode?this.requestRender():this.onModelChange()}),this.config.dataSource)return void this.setDataSource(this.config.dataSource);const e=this.gridElement?.getAttribute("data-src");e&&this.setDataSource(R(e))}detach(){this.dataSource=null,this.totalNodeCount=0,this.infiniteScrollMode=!1,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.abortAllBlocks(),this.managedNodes=[],this.lastRequestId=0,this.scrollDebounceTimer&&(clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=void 0)}abortAllBlocks(){for(const t of this.blockControllers.values())t.abort();this.blockControllers.clear()}getEnrichmentParams(){const t="local"===this.config.sortMode,e="local"===this.config.filterMode,o=t?void 0:this.grid?.query?.("sort:get-model",null),r=e?void 0:this.grid?.query?.("filter:get-model",null);let s=o?.[0];const n=this.grid;if(!t&&!s&&n?._sortState){const{field:t,direction:e}=n._sortState;s=[{field:t,direction:1===e?"asc":"desc"}]}return{sortModel:s,filterModel:r?.[0]}}getViewportMapping(t,e){const o={viewportStart:t,viewportEnd:e},r=this.grid?.query?.("datasource:viewport-mapping",o);return r?.[0]?r[0]:{startNode:t,endNode:e,totalLoadedNodes:this.totalNodeCount}}onModelChange(){this.dataSource&&(this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.requestRender(),this.loadRequiredBlocks())}applyServerResult(t,e,o){void 0!==t.lastNode?(this.totalNodeCount=t.lastNode+1,this.infiniteScrollMode=!1):-1===t.totalNodeCount?this.infiniteScrollMode=!0:(this.totalNodeCount=t.totalNodeCount,this.infiniteScrollMode=!1),this.infiniteScrollMode&&t.rows.length<o&&(this.totalNodeCount=e*o+t.rows.length,this.infiniteScrollMode=!1)}getInfiniteScrollEstimate(t){let e=0;for(const[o,r]of this.loadedBlocks){const s=o*t+r.length;s>e&&(e=s)}return e+t}loadRequiredBlocks(){if(!this.dataSource)return;const{_virtualization:t}=this.grid,o=this.config.pageSize??100,n=this.getViewportMapping(t.start,t.end),i=Math.max(0,this.config.loadThreshold??0),a=Math.max(0,n.startNode-i),l=this.totalNodeCount>0?this.totalNodeCount:1/0,c=Math.min(l,n.endNode+i);if(c<=a)return;const d=function(t,e,o){const r=k(t,o),s=k(e-1,o),n=[];for(let i=r;i<=s;i++)n.push(i);return n}(a,c,o),u=this.getEnrichmentParams(),h=this.grid?.getAttribute?.("id")??void 0;for(const g of d){if(this.loadedBlocks.has(g)||this.loadingBlocks.has(g))continue;if(this.loadingBlocks.size>=(this.config.maxConcurrentRequests??2)){r("TBW143","Concurrent request limit reached, deferring block load",h);break}this.loadingBlocks.add(g);const t=new AbortController;this.blockControllers.set(g,t),this.broadcast("datasource:loading",{loading:!0}),y(this.dataSource,g,o,u,t.signal).then(e=>{if(this.blockControllers.delete(g),t.signal.aborted)return this.loadingBlocks.delete(g),void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));this.loadedBlocks.set(g,e.rows);const r=this.managedNodes.length;this.applyServerResult(e,g,o),this.loadingBlocks.delete(g);const s=g*o;for(let t=0;t<e.rows.length;t++)s+t<this.managedNodes.length&&(this.managedNodes[s+t]=e.rows[t]);const n={rows:e.rows,totalNodeCount:e.totalNodeCount,startNode:s,endNode:s+e.rows.length,claimed:!1};this.broadcast("datasource:data",n),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}),0===r||n.claimed||this.managedNodes.length<(Number.isFinite(this.totalNodeCount)?this.totalNodeCount:0)?this.requestRender():this.requestVirtualRefresh(),this.loadRequiredBlocks()}).catch(o=>{if(this.blockControllers.delete(g),this.loadingBlocks.delete(g),t.signal.aborted)return void(0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1}));const r=o instanceof Error?o:new Error(String(o));s(e,`getRows() failed: ${r.message}`,h),this.broadcast("datasource:error",{error:r}),0===this.loadingBlocks.size&&this.broadcast("datasource:loading",{loading:!1})})}}processRows(t){if(!this.dataSource)return[...t];const e=this.config.pageSize??100,o=this.infiniteScrollMode?this.getInfiniteScrollEstimate(e):Number.isFinite(this.totalNodeCount)&&this.totalNodeCount>=0?this.totalNodeCount:0;for(;this.managedNodes.length<o;){const t=this.managedNodes.length;this.managedNodes.push({__loading:!0,__index:t})}this.managedNodes.length=o;for(let s=0;s<o;s++){const t=B(s,e,this.loadedBlocks);t&&(this.managedNodes[s]=t)}const r=this.grid;if("local"===this.config.sortMode&&r?._sortState){const t=r._columns??[],e=(r.effectiveConfig?.sortHandler??g)(this.managedNodes,r._sortState,t);return e&&"function"==typeof e.then?(e.catch(()=>{}),this.managedNodes):e}return this.managedNodes}onScroll(t){this.dataSource&&(this.loadRequiredBlocks(),this.scrollDebounceTimer&&clearTimeout(this.scrollDebounceTimer),this.scrollDebounceTimer=setTimeout(()=>{this.loadRequiredBlocks()},100))}handleQuery(t){switch(t.type){case"datasource:is-active":return null!=this.dataSource;case"datasource:fetch-children":{const{context:e}=t.context;return void this.fetchChildren(e)}}}fetchChildren(t){if(!this.dataSource)return;const e=this.grid?.getAttribute?.("id")??void 0;if(!this.dataSource.getChildRows)return void function(t,e,r,s){console.warn(o(t,e,r,s))}("TBW142",`Plugin "${t.source}" requested child rows but getChildRows() is not implemented on the dataSource`,e);const r=this.getEnrichmentParams();this.broadcast("datasource:loading",{loading:!0,context:t}),this.dataSource.getChildRows({context:t,sortModel:r.sortModel,filterModel:r.filterModel}).then(e=>{const o={rows:e.rows,context:t,claimed:!1};this.broadcast("datasource:children",o),this.broadcast("datasource:loading",{loading:!1,context:t})}).catch(o=>{const r=o instanceof Error?o:new Error(String(o));s("TBW141",`getChildRows() failed: ${r.message}`,e),this.broadcast("datasource:error",{error:r,context:t}),this.broadcast("datasource:loading",{loading:!1,context:t})})}setDataSource(t){this.abortAllBlocks(),this.dataSource=t,this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1;const o=this.config.pageSize??100,r=this.getEnrichmentParams(),n=this.grid?.getAttribute?.("id")??void 0,i=new AbortController;this.blockControllers.set(0,i),this.loadingBlocks.add(0),this.broadcast("datasource:loading",{loading:!0}),y(t,0,o,r,i.signal).then(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});this.loadedBlocks.set(0,t.rows),this.applyServerResult(t,0,o);const e={rows:t.rows,totalNodeCount:t.totalNodeCount,startNode:0,endNode:t.rows.length,claimed:!1};this.broadcast("datasource:data",e),this.broadcast("datasource:loading",{loading:!1}),this.requestRender(),(this.config.loadThreshold??0)>0&&this.loadRequiredBlocks()}).catch(t=>{if(this.blockControllers.delete(0),this.loadingBlocks.delete(0),i.signal.aborted)return void this.broadcast("datasource:loading",{loading:!1});const o=t instanceof Error?t:new Error(String(t));s(e,`getRows() failed: ${o.message}`,n),this.broadcast("datasource:error",{error:o}),this.broadcast("datasource:loading",{loading:!1})})}refresh(){if(!this.dataSource)return;const t=this.dataSource;this.abortAllBlocks(),this.loadedBlocks.clear(),this.loadingBlocks.clear(),this.managedNodes=[],this.totalNodeCount=0,this.infiniteScrollMode=!1,this.setDataSource(t)}purgeCache(){this.abortAllBlocks(),this.loadedBlocks.clear(),this.managedNodes=[]}getTotalNodeCount(){return this.totalNodeCount}isNodeLoaded(t){const e=k(t,this.config.pageSize??100);return this.loadedBlocks.has(e)}getLoadedBlockCount(){return this.loadedBlocks.size}};export{M as ServerSidePlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|