@toolbox-web/grid 3.9.2 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +6 -3
- package/lib/features/clipboard.js.map +1 -1
- package/lib/features/column-virtualization.js.map +1 -1
- package/lib/features/context-menu.js.map +1 -1
- package/lib/features/editing.js.map +1 -1
- package/lib/features/export.js.map +1 -1
- package/lib/features/filtering.js.map +1 -1
- package/lib/features/grouping-columns.js.map +1 -1
- package/lib/features/grouping-rows.js.map +1 -1
- package/lib/features/master-detail.js.map +1 -1
- package/lib/features/multi-sort.js.map +1 -1
- package/lib/features/pinned-columns.js.map +1 -1
- package/lib/features/pinned-rows.js.map +1 -1
- package/lib/features/pivot.js.map +1 -1
- package/lib/features/print.js.map +1 -1
- package/lib/features/registry.js +1 -1
- package/lib/features/registry.js.map +1 -1
- package/lib/features/reorder-columns.js.map +1 -1
- package/lib/features/responsive.js.map +1 -1
- package/lib/features/row-drag-drop.js.map +1 -1
- package/lib/features/selection.js.map +1 -1
- package/lib/features/server-side.js.map +1 -1
- package/lib/features/shell.js.map +1 -1
- package/lib/features/sticky-rows.js.map +1 -1
- package/lib/features/tooltip.js.map +1 -1
- package/lib/features/tree.js.map +1 -1
- package/lib/features/undo-redo.js.map +1 -1
- package/lib/features/visibility.js.map +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/editors.d.ts +15 -0
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +5 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/filter-model.d.ts +20 -1
- package/lib/plugins/filtering/filter-panel-default.d.ts +15 -1
- package/lib/plugins/filtering/index.d.ts +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +58 -3
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/hierarchy/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-plugin.d.ts +2 -0
- package/lib/plugins/pivot/types.d.ts +2 -0
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shared/form-field-target.d.ts +10 -0
- package/lib/plugins/shared/format-value.d.ts +12 -0
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/hierarchy.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/reorder-columns.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/row-drag-drop.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/shell.umd.js.map +1 -1
- package/umd/plugins/sticky-rows.umd.js.map +1 -1
- package/umd/plugins/tooltip.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BaseGridPlugin as e,DEFAULT_A11Y_MESSAGES as t,getPrimaryPointer as n,startPointerDrag as i}from"@toolbox-web/grid";var s="selected";function o(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 l(e,n,...i){const s=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[n];return s?s(...i):t[n](...i)}function r(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 o=0;o<s.length;o++)if(s[o]===n)return o;return-1}function c(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function a(e){return"__tbw_expander"===e.field}function d(e){return!0===e.utility}function h(){return"function"==typeof HTMLElement.prototype?.showPopover}function u(e,t){let n=null,i=!1,s=!1;const o=new AbortController;function l(){i&&n&&(i=!1,h()&&n.hidePopover(),n.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&n&&!e.composedPath().includes(n)&&l()},{capture:!0,signal:o.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&l()},{capture:!0,signal:o.signal}),{get element(){return n},open(r,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)&&l()},{signal:o.signal}),n}());const d=r.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",()=>{l(),e.run()}),n.appendChild(i)}n.hidden=!1,!i&&h()&&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)),o=t.bottom+6,l=o+i.height<=window.innerHeight?o:Math.max(4,t.top-6-i.height);n.style.left=`${Math.round(s)}px`,n.style.top=`${Math.round(l)}px`}(r),n.querySelector("button:not([disabled])")?.focus()},close:l,dispose(){s=!0,l(),o.abort(),n?.remove(),n=null}}}function g(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 g(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 m(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 w(e,t){return t.indexOf(e)}function f(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 b(e){const t=f(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function p(e,t,n){return n.some(n=>function(e,t,n){const i=f(n);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,n))}function C(e){const t=[],n=f(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 v(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function y(e,t){const n=f(e),i=f(t);return n.startRow===i.startRow&&n.startCol===i.startCol&&n.endRow===i.endRow&&n.endCol===i.endCol}var S="tbw-selection-toolbar",x=class{#e=null;#t=null;#n=null;#i=null;get mounted(){return null!==this.#e}get element(){return this.#e}show(e,t,n,i){this.#i=i,this.#e||this.#s(e),this.#t&&(this.#t.textContent=`${t} selected`),this.#e?.setAttribute("data-selected-count",String(t)),this.#n&&(this.#n.hidden=!n)}destroy(){this.#e?.remove(),this.#e=null,this.#t=null,this.#n=null,this.#i=null}#s(e){const t=e.ownerDocument.createElement("div");t.className=S,t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Selection");const n=e.ownerDocument.createElement("span");n.className=`${S}-count`,n.setAttribute("aria-live","polite"),t.appendChild(n);const i=e.ownerDocument.createElement("div");i.className=`${S}-actions`,t.appendChild(i),i.appendChild(this.#o(e,"select-all","Select all",()=>this.#i?.selectAll())),i.appendChild(this.#o(e,"clear","Clear",()=>this.#i?.clear()));const s=this.#o(e,"more","More…",e=>this.#i?.more(e));s.setAttribute("aria-haspopup","menu"),i.appendChild(s),i.appendChild(this.#o(e,"done","Done",()=>this.#i?.done())),e.prepend(t),this.#e=t,this.#t=n,this.#n=s}#o(e,t,n,i){const s=e.ownerDocument.createElement("button");return s.type="button",s.className=`${S}-btn`,s.dataset.action=t,s.textContent=n,s.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),i(s)}),s}},A="tbw-range-handle",R=class{#l=null;#r=null;#i=null;#c=null;render(e,t,n,i){this.#i=i,t?(this.#l??=this.#a(e,"start"),this.#r??=this.#a(e,"end"),this.#d(e,this.#l,n(t.startRow,t.startCol),"start"),this.#d(e,this.#r,n(t.endRow,t.endCol),"end"),this.setArmed(this.#c)):this.#h()}setArmed(e){this.#c=e;for(const[t,n]of[[this.#l,"start"],[this.#r,"end"]]){if(!t)continue;const i=e===n;t.classList.toggle("armed",i),t.setAttribute("aria-pressed",String(i))}}destroy(){this.#l?.remove(),this.#r?.remove(),this.#l=null,this.#r=null,this.#i=null,this.#c=null}#h(){this.#l&&(this.#l.hidden=!0),this.#r&&(this.#r.hidden=!0)}#d(e,t,n,i){if(!t)return;if(!n)return void(t.hidden=!0);t.hidden=!1;const s=n.getBoundingClientRect?.(),o=e.getBoundingClientRect?.();if(!s||!o)return;const l="start"===i?s.left-o.left:s.right-o.left,r="start"===i?s.top-o.top:s.bottom-o.top;t.style.left=`${l}px`,t.style.top=`${r}px`}#a(e,t){const n=e.ownerDocument.createElement("div");return n.className=`${A} ${A}-${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.#u(e,n,t)),e.appendChild(n),n}#u(e,t,n){if(0!==e.button&&"mouse"===e.pointerType)return;e.preventDefault(),e.stopPropagation();const s=this.#i;if(!s)return;t.classList.add("dragging");let o=!1;i(e,t,{onMove:e=>{o=!0;const t=s.cellAt(e.clientX,e.clientY);t&&s.resize(n,t.row,t.col)},onEnd:()=>{t.classList.remove("dragging"),o?s.commit():s.arm(n)},onCancel:()=>{t.classList.remove("dragging"),s.commit()}})}};function E(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 k="__tbw_checkbox";function M(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||e.isContentEditable}var I=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"];var q=class extends e{static manifest={hookPriority:{processColumns:-20},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 row indices touched by the current selection (works in all modes)"},{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:"selectContextMenuTarget",description:"Move the selection to the cell a context menu was invoked on unless it is already selected; returns getSelectedRowIndices()"},{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"===E(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"!==E(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.#g}#g=!1;#m=!1;#w=new x;#f=new R;#b=null;#p=null;#C=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";#v={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;#y=null;#S=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.#v=g(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.#v.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.#x()),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.#A())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.#R(n,i);s&&(e.preventDefault(),this.#E(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("selectContextMenuTarget"===e.type){const{rowIndex:t,colIndex:n}=e.context;return this.#M(t,n),this.getSelectedRowIndices()}if("getContextMenuItems"===e.type){const t=e.context;if(!t||t.isHeader)return;const n=this.#R(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.#w.destroy(),this.#f.destroy(),this.#C?.dispose(),this.#C=null,this.#b=null,this.#p=null,this.#g=!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()}#I(e){const t=e.pointerType;return"touch"===t||"pen"===t||"mouse"!==t&&"coarse"===n()}#q(e){return!!this.isRowSelectable(e)&&(this.#g=!0,this.selected.clear(),this.selected.add(e),this.anchor=e,this.lastSelected=e,this.explicitSelection=!0,this.emit("selection-change",this.#x()),this.requestAfterRender(),!0)}exitTouchSelection(){this.#g&&(this.#g=!1,"transient"===(this.config.touchMode??"transient")&&(this.selected.clear(),this.anchor=null,this.lastSelected=null,this.emit("selection-change",this.#x())),this.requestAfterRender())}#P(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.#x()),this.requestAfterRender()}#A(){const e=this.grid?.getPluginByName?.("contextMenu")??this.grid?.getPluginByName?.("context-menu");return"function"==typeof e?.showMenu?e:void 0}#K(e,t){return this.gridElement?.querySelector(`.cell[data-row="${e}"][data-col="${t}"]`)??null}#T(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),o=parseInt(i.getAttribute("data-col")??"-1",10);return s>=0&&o>=0?{row:s,col:o}:null}#L(e,t,n){const i=this.ranges[this.ranges.length-1];if(!i)return;const s=f(i),o="start"===e?{row:s.endRow,col:s.endCol}:{row:s.startRow,col:s.startCol},l=v(o,{row:t,col:n});y(i,l)||(this.ranges[this.ranges.length-1]=l,this.activeRange=l,this.cellAnchor=o,this.emit("selection-change",this.#x()),this.requestAfterRender())}#R(e,t){if("range"!==this.#v.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.#p;return n?n.row===e&&n.col===t?null:[{label:"Extend selection to here",run:()=>this.#z(e,t)}]:null}#z(e,t){const n=this.#p;if(!n)return;const i=v(n,{row:e,col:t});this.ranges=[i],this.activeRange=i,this.cellAnchor=n,this.emit("selection-change",this.#x()),this.requestAfterRender()}#E(e,t){this.#C??=u("tbw-range-extend-menu","tbw-range-extend-menu"),this.#C.open(e,"Selection",t)}#H(e){this.#b=this.#b===e?null:e,this.#f.setArmed(this.#b),this.gridElement&&o(this.gridElement,this.#b?"Select a cell to place the selection corner":"Selection corner placement cancelled")}#D(){return!!this.#b&&(this.#b=null,this.#f.setArmed(null),!0)}#F(e){if(!e)return;this.#g?this.#w.show(e,this.selected.size,void 0!==this.#A(),{selectAll:()=>this.selectAll(),clear:()=>this.clearSelection(),done:()=>this.exitTouchSelection(),more:e=>this.#_(e)}):this.#w.destroy();const t=this.#m&&"range"===this.#v.primary&&this.ranges.length>0?this.ranges[this.ranges.length-1]:null,n=t?f(t):null;n||this.#D(),this.#f.render(e,n,(e,t)=>this.#K(e,t),{cellAt:(e,t)=>this.#T(e,t),resize:(e,t,n)=>this.#L(e,t,n),commit:()=>this.requestAfterRender(),arm:e=>this.#H(e)})}#_(e){const t=this.#A();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.#v.primary){case"cell":return this.#$(e);case"row":return this.#N(e);case"range":return this.#U(e);default:return!1}}#$(e){const{rowIndex:t,colIndex:n}=e;if(e.column&&d(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.#x()),this.requestAfterRender()),!1}#N(e){const{rowIndex:t,originalEvent:n,column:i}=e;if(!this.isRowSelectable(t))return!1;const s=!1!==this.config.multiSelect,o=n.shiftKey&&s,l=(n.ctrlKey||n.metaKey||this.#g)&&s,r=!0===i?.checkboxColumn;if(o&&null!==this.anchor){const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);l||this.selected.clear();for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(l||r&&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.#x()),this.requestAfterRender(),!1}#U(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e;if(e.column&&d(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;if(this.#b){const e=this.#b;return this.#D(),this.#L(e,t,n),!0}this.#m=this.#I(i);const s=i.shiftKey,o=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(s&&this.cellAnchor){const e=v(this.cellAnchor,{row:t,col:n}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&y(i,e))return!1;o?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(o)this.ranges.push(e);else{if(1===this.ranges.length&&y(this.ranges[0],e))return!1;this.ranges=[e]}this.activeRange=e,this.cellAnchor={row:t,col:n},this.#p={row:t,col:n}}return this.emit("selection-change",this.#x()),this.requestAfterRender(),!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;if(this.#v.columnEnabled&&this.#B(e))return!0;const t=this.#v.primary;if("Escape"===e.key&&this.#D())return!0;if("Escape"===e.key&&this.#g)return this.exitTouchSelection(),!0;if("Escape"===e.key)return this.#O(t);const n=I.includes(e.key);switch(t){case"cell":return!!n&&this.#j();case"row":return this.#G(e);case"range":return this.#W(e,n);default:return!1}}#B(e){if(!e.ctrlKey&&!e.metaKey)return!1;if(M(e.target)||this.grid.query("isEditing").some(Boolean))return!1;if(" "===e.key||"Spacebar"===e.key){const t=this.visibleColumns[this.grid._focusCol];return!(!t||d(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=m(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=w(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}#O(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.#x()),this.requestAfterRender(),!0)}#j(){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.#x()),this.requestAfterRender()}),!1}#G(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.#X(e,t)}#W(e,t){if(!t)return this.#Q(e)||this.#X(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}#Q(e){if(" "!==e.key&&"Spacebar"!==e.key)return!1;const t=e.ctrlKey||e.metaKey;let n;if(e.shiftKey&&!t)n="row";else{if(!t||e.shiftKey||this.#v.columnEnabled)return!1;n="column"}if(e.altKey)return!1;if(M(e.target))return!1;if(this.grid.query("isEditing").some(Boolean))return!1;const i=this.rows.length,s=this.visibleColumns.length;if(0===i||0===s)return!1;const o={row:this.grid._focusRow,col:this.grid._focusCol},l=this.activeRange?f(this.activeRange):{startRow:o.row,startCol:o.col,endRow:o.row,endCol:o.col},r="row"===n?{startRow:l.startRow,startCol:0,endRow:l.endRow,endCol:s-1}:{startRow:0,startCol:l.startCol,endRow:i-1,endCol:l.endCol};e.preventDefault(),e.stopPropagation();const c={row:Math.abs(o.row-r.startRow)>=Math.abs(o.row-r.endRow)?r.startRow:r.endRow,col:Math.abs(o.col-r.startCol)>=Math.abs(o.col-r.endCol)?r.startCol:r.endCol};return this.ranges=[r],this.activeRange=r,this.#S={axis:n,range:r},this.cellAnchor=c,this.#p=c,this.#y={axis:n,count:"row"===n?r.endRow-r.startRow+1:r.endCol-r.startCol+1},this.emit("selection-change",this.#x()),this.requestAfterRender(),!0}#X(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.#v.primary){if(void 0===e.rowIndex||e.rowIndex<0)return;if(!1===this.config.multiSelect)return;if(!this.#I(e.originalEvent))return;if(e.column&&d(e.column))return;return this.#g?(this.#P(e.rowIndex),!0):this.#q(e.rowIndex)||void 0}if("range"!==this.#v.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(this.#b)return!0;if(this.#m=this.#I(e.originalEvent),e.column&&d(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&&y(this.ranges[0],s)?(this.cellAnchor={row:t,col:n},this.#p={row:t,col:n},!0):(this.cellAnchor={row:t,col:n},this.#p={row:t,col:n},i||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#x()),this.requestAfterRender(),!0)}#M(e,t){if(e<0||!this.isSelectionEnabled())return;if("column"===this.activeAxis&&this.selectedColumns.has(this.visibleColumns[t]?.field??""))return;const n=this.#v.primary;if("row"===n)return void(this.selected.has(e)||this.selectRows([e]));if("cell"!==n&&"range"!==n)return;const i=this.visibleColumns[t];if(i&&!d(i)&&this.isCellSelectable(e,t)){if("cell"===n){const n=this.selectedCell;if(n&&n.row===e&&n.col===t)return;this.selectedCell={row:e,col:t}}else{if(p(e,t,this.ranges))return;const n={startRow:e,startCol:t,endRow:e,endCol:t};this.ranges=[n],this.activeRange=n,this.cellAnchor={row:e,col:t}}this.emit("selection-change",this.#x()),this.requestAfterRender()}}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#v.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&&d(n)){const e=this.visibleColumns.findIndex(e=>!d(e));e>=0&&(t=e)}const i=v(this.cellAnchor,{row:e.rowIndex,col:t}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return s&&y(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.#x()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#v.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#v.columnEnabled)return!1;if(e.column&&d(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.#v.primary){if(e.some(e=>e.field===k))return e;const t=this.#Y(),n=e.findIndex(a),i=e.findIndex(e=>"left"!==e.pinned),s=i<0?e.length:i,o=n>=0?Math.max(n+1,s):s;return[...e.slice(0,o),t,...e.slice(o)]}return e}#Y(){return{field:k,header:"",width:32,pinned:"left",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=l(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",l(this.gridElement,"selectRow",Math.max(i,0))),t}}}#J(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),n=t?r(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}}#V(){return this.gridElement?.hasAttribute("data-has-focus")??!1}#Z(e){const t=this.grid._focusRow,n=this.grid._focusCol;if(!this.#V())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.#x()))))}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.#x()))}}}#ee(){const e=this.gridElement;if(!e)return;const t=this.#v.primary,n=this.#v.columnEnabled,i=!!this.config.isSelectable,o=e.querySelector(".rows-body");if(o){const e=!1!==this.config.multiSelect;o.setAttribute("aria-multiselectable",e?"true":"false")}e.querySelectorAll(".cell").forEach(e=>{const t=e.classList.contains(s)||e.classList.contains("column-selected");e.classList.remove(s,"top","bottom","first","last","column-selected"),t&&e.removeAttribute("aria-selected"),i&&e.removeAttribute("data-selectable")});const l=e.querySelectorAll(".data-grid-row");if(l.forEach(e=>{e.classList.remove(s,"row-focus"),e.setAttribute("aria-selected","false"),i&&e.removeAttribute("data-selectable")}),n&&e.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")}),"row"===t&&(c(e),l.forEach(e=>{const t=r(e.querySelector(".cell[data-row]"));t>=0&&(i&&!this.isRowSelectable(t)&&e.setAttribute("data-selectable","false"),this.selected.has(t)&&(e.classList.add(s,"row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#J(e)),"cell"!==t&&"range"!==t||!i||e.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"===t&&this.ranges.length>0){c(e);const t=this.ranges.map(f),n=(e,n)=>{for(const i of t)if(e>=i.startRow&&e<=i.endRow&&n>=i.startCol&&n<=i.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),i=parseInt(e.getAttribute("data-col")??"-1",10);if(t>=0&&i>=0){const o=this.visibleColumns[i];if(o&&d(o))return;n(t,i)&&(e.classList.add(s),e.setAttribute("aria-selected","true"),n(t-1,i)||e.classList.add("top"),n(t+1,i)||e.classList.add("bottom"),n(t,i-1)||e.classList.add("first"),n(t,i+1)||e.classList.add("last"))}})}if(n&&this.selectedColumns.size>0){const t=this.visibleColumns.map(e=>"string"==typeof e.field?e.field:void 0);e.querySelectorAll(".header-row > .cell[data-col]").forEach(e=>{const n=parseInt(e.getAttribute("data-col")??"-1",10),i=n>=0?t[n]:void 0;i&&this.selectedColumns.has(i)&&(e.classList.add("column-selected"),e.setAttribute("aria-selected","true"))}),e.querySelectorAll(".cell[data-col]:not(.header-row .cell)").forEach(e=>{if(e.closest(".header-row"))return;const n=parseInt(e.getAttribute("data-col")??"-1",10);if(n<0)return;const i=this.visibleColumns[n];if(!i||d(i))return;const s=t[n];s&&this.selectedColumns.has(s)&&(e.classList.add("column-selected"),e.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.#v.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.#x())}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){let e=v(this.cellAnchor,{row:t,col:n});const i=this.#S;i&&i.range===this.activeRange&&(e="row"===i.axis?{...e,startCol:0,endCol:this.visibleColumns.length-1}:{...e,startRow:0,endRow:this.rows.length-1},i.range=e),this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:n});this.emit("selection-change",this.#x())}this.#Z(n),this.gridElement.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#ee(),this.#F(t)}onScrollRender(){this.isSelectionEnabled()&&this.#ee()}getSelection(){const e=this.#x();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 C(n))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return p(e,t,this.ranges)}selectAll(){const e=this.#v.primary;if(!1!==this.config.multiSelect)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.#x()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.visibleColumns.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.#x()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#v.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.#x()),this.requestAfterRender()}getSelectedRowIndices(){const e=this.#v.primary;if("row"===e)return[...this.selected].sort((e,t)=>e-t);const t=this.rows.length;if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t?[e]:[]}if("range"===e&&this.ranges.length>0){const e=[];for(const s of this.ranges){const n=Math.max(0,Math.min(s.startRow,s.endRow)),i=Math.min(t-1,Math.max(s.startRow,s.endRow));n<=i&&e.push([n,i])}e.sort((e,t)=>e[0]-t[0]);const n=[];let i=0;for(const[t,s]of e){for(let e=Math.max(t,i);e<=s;e++)n.push(e);i=Math.max(i,s+1)}return n}return[]}getSelectedRows(){const e=this.rows;return this.getSelectedRowIndices().filter(t=>t>=0&&t<e.length).map(t=>e[t])}#k(e){if(!this.#v.columnEnabled)return;const t=m(this.visibleColumns),n=new Set(t),i=[],s=/* @__PURE__ */new Set;for(const l of e)n.has(l)&&!s.has(l)&&(s.add(l),i.push(l));this.#te("column"),this.selectedColumns.clear();for(const l of i)this.selectedColumns.add(l);const o=i.length>0?i[i.length-1]:null;this.columnAnchor=o,this.columnHead=o,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#x()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#v.columnEnabled)return;const n=m(this.visibleColumns);if(n.includes(e)){if(this.#te("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=w(e,n),s=w(t,n);if(-1===i||-1===s)return[];const o=Math.min(i,s),l=Math.max(i,s);return n.slice(o,l+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.#x()),this.requestAfterRender()}}deselectColumn(e){this.#v.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.#x()),this.requestAfterRender())}selectAllColumns(){if(!this.#v.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=m(this.visibleColumns);if(0!==e.length){this.#te("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.#x()),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.#x()),this.requestAfterRender())}getSelectedColumns(){return 0===this.selectedColumns.size?[]:m(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.#x()),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.#x()),this.requestAfterRender()}#x(){const e=this.#v.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let n;this.#v.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&o(this.gridElement,l(this.gridElement,"selectionAxisChanged","row"))),n=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=n;const i=function(e,t,n,i,s,o){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:o.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 o=t[0],l=o;for(let e=1;e<t.length;e++)t[e]===l+1?l=t[e]:(n.push({from:{row:o,col:0},to:{row:l,col:s-1}}),o=t[e],l=o);return n.push({from:{row:o,col:0},to:{row:l,col:s-1}}),{mode:e,activeAxis:"row",ranges:n,selectedColumns:[]}}return"range"===n&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(l=i.ranges,l.map(b)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var l}(this.config.mode,n,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,m(this.visibleColumns)),s=this.#y;return this.#y=null,this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if(s)o(this.gridElement,l(this.gridElement,"rangeSpanSelected",s.axis,s.count));else if("column"===i.activeAxis){const e=i.selectedColumns;if(1===e.length){const t=e[0],n=this.columns.find(e=>e.field===t),i="string"==typeof n?.header&&n.header||t;o(this.gridElement,l(this.gridElement,"columnSelected",i))}else e.length>1?o(this.gridElement,l(this.gridElement,"columnSelectionChanged",e.length)):o(this.gridElement,l(this.gridElement,"columnSelectionCleared"))}else{const e="row"===i.activeAxis?this.selected.size:i.ranges.length;e>0&&o(this.gridElement,l(this.gridElement,"selectionChanged",e))}},150),i}#te(e){if(this.#v.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&&o(this.gridElement,l(this.gridElement,"selectionAxisChanged","column"))}}};export{q as SelectionPlugin};
|
|
1
|
+
import{BaseGridPlugin as e,DEFAULT_A11Y_MESSAGES as t,getPrimaryPointer as n,startPointerDrag as i}from"@toolbox-web/grid";var s="selected";function o(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 l(e,n,...i){const s=(e&&"effectiveConfig"in e?e.effectiveConfig:void 0)?.a11y?.messages?.[n];return s?s(...i):t[n](...i)}function r(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 o=0;o<s.length;o++)if(s[o]===n)return o;return-1}function c(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function a(e){return"__tbw_expander"===e.field}function d(e){return!0===e.utility}function h(){return"function"==typeof HTMLElement.prototype?.showPopover}function u(e,t){let n=null,i=!1,s=!1;const o=new AbortController;function l(){i&&n&&(i=!1,h()&&n.hidePopover(),n.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&n&&!e.composedPath().includes(n)&&l()},{capture:!0,signal:o.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&l()},{capture:!0,signal:o.signal}),{get element(){return n},open(r,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)&&l()},{signal:o.signal}),n}());const d=r.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",()=>{l(),e.run()}),n.appendChild(i)}n.hidden=!1,!i&&h()&&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)),o=t.bottom+6,l=o+i.height<=window.innerHeight?o:Math.max(4,t.top-6-i.height);n.style.left=`${Math.round(s)}px`,n.style.top=`${Math.round(l)}px`}(r),n.querySelector("button:not([disabled])")?.focus()},close:l,dispose(){s=!0,l(),o.abort(),n?.remove(),n=null}}}function g(e){const t=e.composedPath?.()??[],n=t.length?t[0]:e.target;if(!(n instanceof HTMLElement))return!1;const i=n.tagName;return"INPUT"===i||"SELECT"===i||"TEXTAREA"===i||n.isContentEditable}function m(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 m(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 w(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 f(e,t){return t.indexOf(e)}function b(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 p(e){const t=b(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function C(e,t,n){return n.some(n=>function(e,t,n){const i=b(n);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,n))}function v(e){const t=[],n=b(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 y(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function S(e,t){const n=b(e),i=b(t);return n.startRow===i.startRow&&n.startCol===i.startCol&&n.endRow===i.endRow&&n.endCol===i.endCol}var x="tbw-selection-toolbar",A=class{#e=null;#t=null;#n=null;#i=null;get mounted(){return null!==this.#e}get element(){return this.#e}show(e,t,n,i){this.#i=i,this.#e||this.#s(e),this.#t&&(this.#t.textContent=`${t} selected`),this.#e?.setAttribute("data-selected-count",String(t)),this.#n&&(this.#n.hidden=!n)}destroy(){this.#e?.remove(),this.#e=null,this.#t=null,this.#n=null,this.#i=null}#s(e){const t=e.ownerDocument.createElement("div");t.className=x,t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Selection");const n=e.ownerDocument.createElement("span");n.className=`${x}-count`,n.setAttribute("aria-live","polite"),t.appendChild(n);const i=e.ownerDocument.createElement("div");i.className=`${x}-actions`,t.appendChild(i),i.appendChild(this.#o(e,"select-all","Select all",()=>this.#i?.selectAll())),i.appendChild(this.#o(e,"clear","Clear",()=>this.#i?.clear()));const s=this.#o(e,"more","More…",e=>this.#i?.more(e));s.setAttribute("aria-haspopup","menu"),i.appendChild(s),i.appendChild(this.#o(e,"done","Done",()=>this.#i?.done())),e.prepend(t),this.#e=t,this.#t=n,this.#n=s}#o(e,t,n,i){const s=e.ownerDocument.createElement("button");return s.type="button",s.className=`${x}-btn`,s.dataset.action=t,s.textContent=n,s.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),i(s)}),s}},R="tbw-range-handle",E=class{#l=null;#r=null;#i=null;#c=null;render(e,t,n,i){this.#i=i,t?(this.#l??=this.#a(e,"start"),this.#r??=this.#a(e,"end"),this.#d(e,this.#l,n(t.startRow,t.startCol),"start"),this.#d(e,this.#r,n(t.endRow,t.endCol),"end"),this.setArmed(this.#c)):this.#h()}setArmed(e){this.#c=e;for(const[t,n]of[[this.#l,"start"],[this.#r,"end"]]){if(!t)continue;const i=e===n;t.classList.toggle("armed",i),t.setAttribute("aria-pressed",String(i))}}destroy(){this.#l?.remove(),this.#r?.remove(),this.#l=null,this.#r=null,this.#i=null,this.#c=null}#h(){this.#l&&(this.#l.hidden=!0),this.#r&&(this.#r.hidden=!0)}#d(e,t,n,i){if(!t)return;if(!n)return void(t.hidden=!0);t.hidden=!1;const s=n.getBoundingClientRect?.(),o=e.getBoundingClientRect?.();if(!s||!o)return;const l="start"===i?s.left-o.left:s.right-o.left,r="start"===i?s.top-o.top:s.bottom-o.top;t.style.left=`${l}px`,t.style.top=`${r}px`}#a(e,t){const n=e.ownerDocument.createElement("div");return n.className=`${R} ${R}-${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.#u(e,n,t)),e.appendChild(n),n}#u(e,t,n){if(0!==e.button&&"mouse"===e.pointerType)return;e.preventDefault(),e.stopPropagation();const s=this.#i;if(!s)return;t.classList.add("dragging");let o=!1;i(e,t,{onMove:e=>{o=!0;const t=s.cellAt(e.clientX,e.clientY);t&&s.resize(n,t.row,t.col)},onEnd:()=>{t.classList.remove("dragging"),o?s.commit():s.arm(n)},onCancel:()=>{t.classList.remove("dragging"),s.commit()}})}};function k(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 M="__tbw_checkbox",I=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"];var q=class extends e{static manifest={hookPriority:{processColumns:-20},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 row indices touched by the current selection (works in all modes)"},{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:"selectContextMenuTarget",description:"Move the selection to the cell a context menu was invoked on unless it is already selected; returns getSelectedRowIndices()"},{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"===k(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"!==k(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.#g}#g=!1;#m=!1;#w=new A;#f=new E;#b=null;#p=null;#C=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";#v={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;#y=null;#S=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.#v=m(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.#v.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.#x()),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.#A())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.#R(n,i);s&&(e.preventDefault(),this.#E(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("selectContextMenuTarget"===e.type){const{rowIndex:t,colIndex:n}=e.context;return this.#M(t,n),this.getSelectedRowIndices()}if("getContextMenuItems"===e.type){const t=e.context;if(!t||t.isHeader)return;const n=this.#R(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.#w.destroy(),this.#f.destroy(),this.#C?.dispose(),this.#C=null,this.#b=null,this.#p=null,this.#g=!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()}#I(e){const t=e.pointerType;return"touch"===t||"pen"===t||"mouse"!==t&&"coarse"===n()}#q(e){return!!this.isRowSelectable(e)&&(this.#g=!0,this.selected.clear(),this.selected.add(e),this.anchor=e,this.lastSelected=e,this.explicitSelection=!0,this.emit("selection-change",this.#x()),this.requestAfterRender(),!0)}exitTouchSelection(){this.#g&&(this.#g=!1,"transient"===(this.config.touchMode??"transient")&&(this.selected.clear(),this.anchor=null,this.lastSelected=null,this.emit("selection-change",this.#x())),this.requestAfterRender())}#P(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.#x()),this.requestAfterRender()}#A(){const e=this.grid?.getPluginByName?.("contextMenu")??this.grid?.getPluginByName?.("context-menu");return"function"==typeof e?.showMenu?e:void 0}#K(e,t){return this.gridElement?.querySelector(`.cell[data-row="${e}"][data-col="${t}"]`)??null}#T(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),o=parseInt(i.getAttribute("data-col")??"-1",10);return s>=0&&o>=0?{row:s,col:o}:null}#L(e,t,n){const i=this.ranges[this.ranges.length-1];if(!i)return;const s=b(i),o="start"===e?{row:s.endRow,col:s.endCol}:{row:s.startRow,col:s.startCol},l=y(o,{row:t,col:n});S(i,l)||(this.ranges[this.ranges.length-1]=l,this.activeRange=l,this.cellAnchor=o,this.emit("selection-change",this.#x()),this.requestAfterRender())}#R(e,t){if("range"!==this.#v.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.#p;return n?n.row===e&&n.col===t?null:[{label:"Extend selection to here",run:()=>this.#z(e,t)}]:null}#z(e,t){const n=this.#p;if(!n)return;const i=y(n,{row:e,col:t});this.ranges=[i],this.activeRange=i,this.cellAnchor=n,this.emit("selection-change",this.#x()),this.requestAfterRender()}#E(e,t){this.#C??=u("tbw-range-extend-menu","tbw-range-extend-menu"),this.#C.open(e,"Selection",t)}#H(e){this.#b=this.#b===e?null:e,this.#f.setArmed(this.#b),this.gridElement&&o(this.gridElement,this.#b?"Select a cell to place the selection corner":"Selection corner placement cancelled")}#D(){return!!this.#b&&(this.#b=null,this.#f.setArmed(null),!0)}#F(e){if(!e)return;this.#g?this.#w.show(e,this.selected.size,void 0!==this.#A(),{selectAll:()=>this.selectAll(),clear:()=>this.clearSelection(),done:()=>this.exitTouchSelection(),more:e=>this.#_(e)}):this.#w.destroy();const t=this.#m&&"range"===this.#v.primary&&this.ranges.length>0?this.ranges[this.ranges.length-1]:null,n=t?b(t):null;n||this.#D(),this.#f.render(e,n,(e,t)=>this.#K(e,t),{cellAt:(e,t)=>this.#T(e,t),resize:(e,t,n)=>this.#L(e,t,n),commit:()=>this.requestAfterRender(),arm:e=>this.#H(e)})}#_(e){const t=this.#A();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.#v.primary){case"cell":return this.#$(e);case"row":return this.#N(e);case"range":return this.#U(e);default:return!1}}#$(e){const{rowIndex:t,colIndex:n}=e;if(e.column&&d(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.#x()),this.requestAfterRender()),!1}#N(e){const{rowIndex:t,originalEvent:n,column:i}=e;if(!this.isRowSelectable(t))return!1;const s=!1!==this.config.multiSelect,o=n.shiftKey&&s,l=(n.ctrlKey||n.metaKey||this.#g)&&s,r=!0===i?.checkboxColumn;if(o&&null!==this.anchor){const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);l||this.selected.clear();for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(l||r&&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.#x()),this.requestAfterRender(),!1}#U(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e;if(e.column&&d(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;if(this.#b){const e=this.#b;return this.#D(),this.#L(e,t,n),!0}this.#m=this.#I(i);const s=i.shiftKey,o=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(s&&this.cellAnchor){const e=y(this.cellAnchor,{row:t,col:n}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&S(i,e))return!1;o?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(o)this.ranges.push(e);else{if(1===this.ranges.length&&S(this.ranges[0],e))return!1;this.ranges=[e]}this.activeRange=e,this.cellAnchor={row:t,col:n},this.#p={row:t,col:n}}return this.emit("selection-change",this.#x()),this.requestAfterRender(),!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;if(this.#v.columnEnabled&&this.#B(e))return!0;const t=this.#v.primary;if("Escape"===e.key&&this.#D())return!0;if("Escape"===e.key&&this.#g)return this.exitTouchSelection(),!0;if("Escape"===e.key)return this.#O(t);const n=I.includes(e.key);switch(t){case"cell":return!!n&&this.#j();case"row":return this.#G(e);case"range":return this.#W(e,n);default:return!1}}#B(e){if(!e.ctrlKey&&!e.metaKey)return!1;if(g(e)||this.grid.query("isEditing").some(Boolean))return!1;if(" "===e.key||"Spacebar"===e.key){const t=this.visibleColumns[this.grid._focusCol];return!(!t||d(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=w(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=f(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}#O(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.#x()),this.requestAfterRender(),!0)}#j(){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.#x()),this.requestAfterRender()}),!1}#G(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.#X(e,t)}#W(e,t){if(!t)return this.#Q(e)||this.#X(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}#Q(e){if(" "!==e.key&&"Spacebar"!==e.key)return!1;const t=e.ctrlKey||e.metaKey;let n;if(e.shiftKey&&!t)n="row";else{if(!t||e.shiftKey||this.#v.columnEnabled)return!1;n="column"}if(e.altKey)return!1;if(g(e))return!1;if(this.grid.query("isEditing").some(Boolean))return!1;const i=this.rows.length,s=this.visibleColumns.length;if(0===i||0===s)return!1;const o={row:this.grid._focusRow,col:this.grid._focusCol},l=this.activeRange?b(this.activeRange):{startRow:o.row,startCol:o.col,endRow:o.row,endCol:o.col},r="row"===n?{startRow:l.startRow,startCol:0,endRow:l.endRow,endCol:s-1}:{startRow:0,startCol:l.startCol,endRow:i-1,endCol:l.endCol};e.preventDefault(),e.stopPropagation();const c={row:Math.abs(o.row-r.startRow)>=Math.abs(o.row-r.endRow)?r.startRow:r.endRow,col:Math.abs(o.col-r.startCol)>=Math.abs(o.col-r.endCol)?r.startCol:r.endCol};return this.ranges=[r],this.activeRange=r,this.#S={axis:n,range:r},this.cellAnchor=c,this.#p=c,this.#y={axis:n,count:"row"===n?r.endRow-r.startRow+1:r.endCol-r.startCol+1},this.emit("selection-change",this.#x()),this.requestAfterRender(),!0}#X(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.#v.primary){if(void 0===e.rowIndex||e.rowIndex<0)return;if(!1===this.config.multiSelect)return;if(!this.#I(e.originalEvent))return;if(e.column&&d(e.column))return;return this.#g?(this.#P(e.rowIndex),!0):this.#q(e.rowIndex)||void 0}if("range"!==this.#v.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(this.#b)return!0;if(this.#m=this.#I(e.originalEvent),e.column&&d(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&&S(this.ranges[0],s)?(this.cellAnchor={row:t,col:n},this.#p={row:t,col:n},!0):(this.cellAnchor={row:t,col:n},this.#p={row:t,col:n},i||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#x()),this.requestAfterRender(),!0)}#M(e,t){if(e<0||!this.isSelectionEnabled())return;if("column"===this.activeAxis&&this.selectedColumns.has(this.visibleColumns[t]?.field??""))return;const n=this.#v.primary;if("row"===n)return void(this.selected.has(e)||this.selectRows([e]));if("cell"!==n&&"range"!==n)return;const i=this.visibleColumns[t];if(i&&!d(i)&&this.isCellSelectable(e,t)){if("cell"===n){const n=this.selectedCell;if(n&&n.row===e&&n.col===t)return;this.selectedCell={row:e,col:t}}else{if(C(e,t,this.ranges))return;const n={startRow:e,startCol:t,endRow:e,endCol:t};this.ranges=[n],this.activeRange=n,this.cellAnchor={row:e,col:t}}this.emit("selection-change",this.#x()),this.requestAfterRender()}}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#v.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&&d(n)){const e=this.visibleColumns.findIndex(e=>!d(e));e>=0&&(t=e)}const i=y(this.cellAnchor,{row:e.rowIndex,col:t}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return s&&S(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.#x()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#v.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#v.columnEnabled)return!1;if(e.column&&d(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.#v.primary){if(e.some(e=>e.field===M))return e;const t=this.#Y(),n=e.findIndex(a),i=e.findIndex(e=>"left"!==e.pinned),s=i<0?e.length:i,o=n>=0?Math.max(n+1,s):s;return[...e.slice(0,o),t,...e.slice(o)]}return e}#Y(){return{field:M,header:"",width:32,pinned:"left",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=l(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",l(this.gridElement,"selectRow",Math.max(i,0))),t}}}#J(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),n=t?r(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}}#V(){return this.gridElement?.hasAttribute("data-has-focus")??!1}#Z(e){const t=this.grid._focusRow,n=this.grid._focusCol;if(!this.#V())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.#x()))))}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.#x()))}}}#ee(){const e=this.gridElement;if(!e)return;const t=this.#v.primary,n=this.#v.columnEnabled,i=!!this.config.isSelectable,o=e.querySelector(".rows-body");if(o){const e=!1!==this.config.multiSelect;o.setAttribute("aria-multiselectable",e?"true":"false")}e.querySelectorAll(".cell").forEach(e=>{const t=e.classList.contains(s)||e.classList.contains("column-selected");e.classList.remove(s,"top","bottom","first","last","column-selected"),t&&e.removeAttribute("aria-selected"),i&&e.removeAttribute("data-selectable")});const l=e.querySelectorAll(".data-grid-row");if(l.forEach(e=>{e.classList.remove(s,"row-focus"),e.setAttribute("aria-selected","false"),i&&e.removeAttribute("data-selectable")}),n&&e.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")}),"row"===t&&(c(e),l.forEach(e=>{const t=r(e.querySelector(".cell[data-row]"));t>=0&&(i&&!this.isRowSelectable(t)&&e.setAttribute("data-selectable","false"),this.selected.has(t)&&(e.classList.add(s,"row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#J(e)),"cell"!==t&&"range"!==t||!i||e.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"===t&&this.ranges.length>0){c(e);const t=this.ranges.map(b),n=(e,n)=>{for(const i of t)if(e>=i.startRow&&e<=i.endRow&&n>=i.startCol&&n<=i.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),i=parseInt(e.getAttribute("data-col")??"-1",10);if(t>=0&&i>=0){const o=this.visibleColumns[i];if(o&&d(o))return;n(t,i)&&(e.classList.add(s),e.setAttribute("aria-selected","true"),n(t-1,i)||e.classList.add("top"),n(t+1,i)||e.classList.add("bottom"),n(t,i-1)||e.classList.add("first"),n(t,i+1)||e.classList.add("last"))}})}if(n&&this.selectedColumns.size>0){const t=this.visibleColumns.map(e=>"string"==typeof e.field?e.field:void 0);e.querySelectorAll(".header-row > .cell[data-col]").forEach(e=>{const n=parseInt(e.getAttribute("data-col")??"-1",10),i=n>=0?t[n]:void 0;i&&this.selectedColumns.has(i)&&(e.classList.add("column-selected"),e.setAttribute("aria-selected","true"))}),e.querySelectorAll(".cell[data-col]:not(.header-row .cell)").forEach(e=>{if(e.closest(".header-row"))return;const n=parseInt(e.getAttribute("data-col")??"-1",10);if(n<0)return;const i=this.visibleColumns[n];if(!i||d(i))return;const s=t[n];s&&this.selectedColumns.has(s)&&(e.classList.add("column-selected"),e.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.#v.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.#x())}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){let e=y(this.cellAnchor,{row:t,col:n});const i=this.#S;i&&i.range===this.activeRange&&(e="row"===i.axis?{...e,startCol:0,endCol:this.visibleColumns.length-1}:{...e,startRow:0,endRow:this.rows.length-1},i.range=e),this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:n});this.emit("selection-change",this.#x())}this.#Z(n),this.gridElement.setAttribute("data-selection-mode",n),t&&t.classList.toggle("selecting",this.isDragging),this.#ee(),this.#F(t)}onScrollRender(){this.isSelectionEnabled()&&this.#ee()}getSelection(){const e=this.#x();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 v(n))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return C(e,t,this.ranges)}selectAll(){const e=this.#v.primary;if(!1!==this.config.multiSelect)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.#x()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.visibleColumns.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.#x()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#v.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.#x()),this.requestAfterRender()}getSelectedRowIndices(){const e=this.#v.primary;if("row"===e)return[...this.selected].sort((e,t)=>e-t);const t=this.rows.length;if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t?[e]:[]}if("range"===e&&this.ranges.length>0){const e=[];for(const s of this.ranges){const n=Math.max(0,Math.min(s.startRow,s.endRow)),i=Math.min(t-1,Math.max(s.startRow,s.endRow));n<=i&&e.push([n,i])}e.sort((e,t)=>e[0]-t[0]);const n=[];let i=0;for(const[t,s]of e){for(let e=Math.max(t,i);e<=s;e++)n.push(e);i=Math.max(i,s+1)}return n}return[]}getSelectedRows(){const e=this.rows;return this.getSelectedRowIndices().filter(t=>t>=0&&t<e.length).map(t=>e[t])}#k(e){if(!this.#v.columnEnabled)return;const t=w(this.visibleColumns),n=new Set(t),i=[],s=/* @__PURE__ */new Set;for(const l of e)n.has(l)&&!s.has(l)&&(s.add(l),i.push(l));this.#te("column"),this.selectedColumns.clear();for(const l of i)this.selectedColumns.add(l);const o=i.length>0?i[i.length-1]:null;this.columnAnchor=o,this.columnHead=o,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#x()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#v.columnEnabled)return;const n=w(this.visibleColumns);if(n.includes(e)){if(this.#te("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=f(e,n),s=f(t,n);if(-1===i||-1===s)return[];const o=Math.min(i,s),l=Math.max(i,s);return n.slice(o,l+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.#x()),this.requestAfterRender()}}deselectColumn(e){this.#v.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.#x()),this.requestAfterRender())}selectAllColumns(){if(!this.#v.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=w(this.visibleColumns);if(0!==e.length){this.#te("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.#x()),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.#x()),this.requestAfterRender())}getSelectedColumns(){return 0===this.selectedColumns.size?[]:w(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.#x()),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.#x()),this.requestAfterRender()}#x(){const e=this.#v.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let n;this.#v.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&o(this.gridElement,l(this.gridElement,"selectionAxisChanged","row"))),n=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=n;const i=function(e,t,n,i,s,o){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:o.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 o=t[0],l=o;for(let e=1;e<t.length;e++)t[e]===l+1?l=t[e]:(n.push({from:{row:o,col:0},to:{row:l,col:s-1}}),o=t[e],l=o);return n.push({from:{row:o,col:0},to:{row:l,col:s-1}}),{mode:e,activeAxis:"row",ranges:n,selectedColumns:[]}}return"range"===n&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(l=i.ranges,l.map(p)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var l}(this.config.mode,n,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,w(this.visibleColumns)),s=this.#y;return this.#y=null,this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if(s)o(this.gridElement,l(this.gridElement,"rangeSpanSelected",s.axis,s.count));else if("column"===i.activeAxis){const e=i.selectedColumns;if(1===e.length){const t=e[0],n=this.columns.find(e=>e.field===t),i="string"==typeof n?.header&&n.header||t;o(this.gridElement,l(this.gridElement,"columnSelected",i))}else e.length>1?o(this.gridElement,l(this.gridElement,"columnSelectionChanged",e.length)):o(this.gridElement,l(this.gridElement,"columnSelectionCleared"))}else{const e="row"===i.activeAxis?this.selected.size:i.ranges.length;e>0&&o(this.gridElement,l(this.gridElement,"selectionChanged",e))}},150),i}#te(e){if(this.#v.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&&o(this.gridElement,l(this.gridElement,"selectionAxisChanged","column"))}}};export{q as SelectionPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|