@toolbox-web/grid 3.0.0-beta.4 → 3.0.0-rc.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/features/registry.js +1 -1
- package/lib/features/registry.js.map +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/index.js +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 +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/shell/index.js +1 -1
- package/lib/plugins/shell/index.js.map +1 -1
- package/lib/plugins/sticky-rows/index.js +1 -1
- package/lib/plugins/sticky-rows/index.js.map +1 -1
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/internal/aria"),require("../../core/internal/utils"),require("../../core/plugin/base-plugin"),require("../../core/plugin/expander-column")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/internal/aria","../../core/internal/utils","../../core/plugin/base-plugin","../../core/plugin/expander-column"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_selection={},e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,s,i,l,n){"use strict";function o(e){const t=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 o(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 s=e.find(e=>"column"!==e);if("column"===s)throw new Error(`[SelectionPlugin] Invalid selection mode: [${e.join(", ")}].`);return{primary:s,columnEnabled:!0,bothAxes:!0}}function r(e){const t=[];for(const s of e)!0!==s.utility&&"string"==typeof s.field&&s.field.length>0&&t.push(s.field);return t}function c(e,t){return t.indexOf(e)}function a(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 d(e){const t=a(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function h(e,t,s){return s.some(s=>function(e,t,s){const i=a(s);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,s))}function u(e){const t=[],s=a(e);for(let i=s.startRow;i<=s.endRow;i++)for(let e=s.startCol;e<=s.endCol;e++)t.push({row:i,col:e});return t}function g(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function m(e,t){const s=a(e),i=a(t);return s.startRow===i.startRow&&s.startCol===i.startCol&&s.endRow===i.endRow&&s.endCol===i.endCol}function f(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"}const w="__tbw_checkbox";class b extends l.BaseGridPlugin{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"},{type:"getSelectedColumns",description:"Get field names of selected columns (column mode only)"},{type:"selectColumns",description:"Select specific columns by field name (column mode only)"}],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"===f(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"!==f(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}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:"";position:absolute;inset:0;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}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:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}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:.6}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:.6}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;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}tbw-grid .header-row>.cell.column-selected,tbw-grid .data-grid-row>.cell.column-selected{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 .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)}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;pendingRowKeyUpdate=null;selectedCell=null;selectedColumns=new Set;columnAnchor=null;columnHead=null;activeAxis="none";#e={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:s}=this.config;if(!s)return!0;const i=this.rows[e];if(!i)return!1;return s(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.#e=o(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.#e.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.#t()),this.requestAfterRender())))});let t=-1;e.addEventListener("data-change",e=>{const{sourceRowCount:s}=e.detail,i=this.selected.size>0||this.ranges.length>0||null!==this.selectedCell;-1!==t&&s!==t&&i&&this.clearSelectionSilent(),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.#s(t),!0}}detach(){const e=this.gridElement?.querySelector(".rows-body");e?.removeAttribute("aria-multiselectable"),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}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()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:s,originalEvent:i}=e,{triggerOn:l="click"}=this.config,o=this.#e.primary;if(i.type!==l)return!1;const r=e.column,c=r&&n.isUtilityColumn(r);if("cell"===o){if(c)return!1;if(!this.isCellSelectable(t,s))return!1;const e=this.selectedCell;return e&&e.row===t&&e.col===s||(this.selectedCell={row:t,col:s},this.emit("selection-change",this.#t()),this.requestAfterRender()),!1}if("row"===o){if(!this.isRowSelectable(t))return!1;const e=!1!==this.config.multiSelect,s=i.shiftKey&&e,l=(i.ctrlKey||i.metaKey)&&e,n=!0===r?.checkboxColumn;if(s&&null!==this.anchor){const e=Math.min(this.anchor,t),s=Math.max(this.anchor,t);l||this.selected.clear();for(let t=e;t<=s;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(l||n&&e)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.#t()),this.requestAfterRender(),!1}if("range"===o){if(c)return!1;if(!this.isCellSelectable(t,s))return!1;const e=i.shiftKey,l=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(e&&this.cellAnchor){const e=g(this.cellAnchor,{row:t,col:s}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&m(i,e))return!1;l?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else if(l){const e={startRow:t,startCol:s,endRow:t,endCol:s};this.ranges.push(e),this.activeRange=e,this.cellAnchor={row:t,col:s}}else{const e={startRow:t,startCol:s,endRow:t,endCol:s};if(1===this.ranges.length&&m(this.ranges[0],e))return!1;this.ranges=[e],this.activeRange=e,this.cellAnchor={row:t,col:s}}return this.emit("selection-change",this.#t()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const t=this.#e.primary,s=this.#e.columnEnabled,i=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(s&&(e.ctrlKey||e.metaKey)&&(" "===e.key||"Spacebar"===e.key)){const t=this.grid._focusCol,s=this.visibleColumns[t];if(s&&!n.isUtilityColumn(s)&&"string"==typeof s.field)return e.preventDefault(),e.stopPropagation(),this.selectColumn(s.field,{toggle:!0}),!0}if(s&&"column"===this.activeAxis&&!1!==this.config.multiSelect&&(e.ctrlKey||e.metaKey)&&e.shiftKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)){const t=r(this.visibleColumns),s="ArrowLeft"===e.key?"left":"right",i=function(e,t,s){if(0===t.length)return null;if(null===e)return null;const i=c(e,t);if(i<0)return null;const l="left"===s?Math.max(0,i-1):Math.min(t.length-1,i+1);return l===i?null:t[l]}(this.columnHead,t,s);if(null!==i&&null!==this.columnAnchor)return e.preventDefault(),e.stopPropagation(),this.selectColumn(i,{range:!0}),!0}if("Escape"===e.key){return!this.grid.query("isEditing").some(Boolean)&&("column"===this.activeAxis?(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.emit("selection-change",this.#t()),this.requestAfterRender(),!0):("cell"===t?this.selectedCell=null:"row"===t?(this.selected.clear(),this.anchor=null):"range"===t&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#t()),this.requestAfterRender(),!0))}if("cell"===t&&i)return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.isCellSelectable(e,t)?this.selectedCell={row:e,col:t}:this.selectedCell=null,this.emit("selection-change",this.#t()),this.requestAfterRender()}),!1;if("row"===t){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 s=e.shiftKey&&t;return s&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if(t&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}}if("range"===t&&i){const t="Tab"===e.key,s=e.shiftKey&&!t;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if("range"===t&&!1!==this.config.multiSelect&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}return!1}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("range"!==this.#e.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(e.column&&n.isUtilityColumn(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,s=e.colIndex,i=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,l={startRow:t,startCol:s,endRow:t,endCol:s};return!i&&1===this.ranges.length&&m(this.ranges[0],l)?(this.cellAnchor={row:t,col:s},!0):(this.cellAnchor={row:t,col:s},i||(this.ranges=[]),this.ranges.push(l),this.activeRange=l,this.emit("selection-change",this.#t()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#e.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 s=this.visibleColumns[t];if(s&&n.isUtilityColumn(s)){const e=this.visibleColumns.findIndex(e=>!n.isUtilityColumn(e));e>=0&&(t=e)}const i=g(this.cellAnchor,{row:e.rowIndex,col:t}),l=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return l&&m(l,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#t()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#e.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#e.columnEnabled)return!1;if(e.column&&n.isUtilityColumn(e.column))return!1;const t=e.originalEvent;if(!(t.ctrlKey||t.metaKey))return!1;const s=e.field;if(!s)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(s,i?{range:!0}:{toggle:!0}),!0}processColumns(e){if(this.config.checkbox&&"row"===this.#e.primary){if(e.some(e=>e.field===w))return e;const t=this.#i(),s=e.findIndex(n.isExpanderColumn),i=s>=0?s+1:0;return[...e.slice(0,i),t,...e.slice(i)]}return e}#i(){return{field:w,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("div");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const s=e.cellEl;if(s){const e=parseInt(s.getAttribute("data-row")??"-1",10);e>=0&&(t.checked=this.selected.has(e))}return t}}}#l(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),s=t?i.getRowIndexFromCell(t):-1;s>=0&&(e.checked=this.selected.has(s))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let s=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&s++;else s=e;const i=s>0&&this.selected.size>=s,l=this.selected.size>0;t.checked=i,t.indeterminate=l&&!i}}#n(){return this.gridElement?.hasAttribute("data-has-focus")??!1}#o(e){const t=this.grid._focusRow,s=this.grid._focusCol;if(!this.#n())return this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=s);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.#t()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=s);if((t!==this.lastSyncedFocusRow||s!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=s,this.isCellSelectable(t,s))){const e=this.selectedCell;e&&e.row===t&&e.col===s||(this.selectedCell={row:t,col:s},this.emit("selection-change",this.#t()))}}}#r(){const e=this.gridElement;if(!e)return;const s=this.#e.primary,l=this.#e.columnEnabled,o=!!this.config.isSelectable,r=e.querySelector(".rows-body");if(r){const e=!1!==this.config.multiSelect;r.setAttribute("aria-multiselectable",e?"true":"false")}e.querySelectorAll(".cell").forEach(e=>{const s=e.classList.contains(t.GridClasses.SELECTED)||e.classList.contains("column-selected");e.classList.remove(t.GridClasses.SELECTED,"top","bottom","first","last","column-selected"),s&&e.removeAttribute("aria-selected"),o&&e.removeAttribute("data-selectable")});const c=e.querySelectorAll(".data-grid-row");if(c.forEach(e=>{e.classList.remove(t.GridClasses.SELECTED,"row-focus"),e.setAttribute("aria-selected","false"),o&&e.removeAttribute("data-selectable")}),l){e.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")})}if("row"===s&&(i.clearCellFocus(e),c.forEach(e=>{const s=e.querySelector(".cell[data-row]"),l=i.getRowIndexFromCell(s);l>=0&&(o&&!this.isRowSelectable(l)&&e.setAttribute("data-selectable","false"),this.selected.has(l)&&(e.classList.add(t.GridClasses.SELECTED,"row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#l(e)),("cell"===s||"range"===s)&&o){e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),s=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&s>=0&&(this.isCellSelectable(t,s)||e.setAttribute("data-selectable","false"))})}if("range"===s&&this.ranges.length>0){i.clearCellFocus(e);const s=this.ranges.map(a),l=(e,t)=>{for(const i of s)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const s=parseInt(e.getAttribute("data-row")??"-1",10),i=parseInt(e.getAttribute("data-col")??"-1",10);if(s>=0&&i>=0){const o=this.visibleColumns[i];if(o&&n.isUtilityColumn(o))return;l(s,i)&&(e.classList.add(t.GridClasses.SELECTED),e.setAttribute("aria-selected","true"),l(s-1,i)||e.classList.add("top"),l(s+1,i)||e.classList.add("bottom"),l(s,i-1)||e.classList.add("first"),l(s,i+1)||e.classList.add("last"))}})}if(l&&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 s=parseInt(e.getAttribute("data-col")??"-1",10),i=s>=0?t[s]: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 s=parseInt(e.getAttribute("data-col")??"-1",10);if(s<0)return;const i=this.visibleColumns[s];if(!i||n.isUtilityColumn(i))return;const l=t[s];l&&this.selectedColumns.has(l)&&(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"),s=this.#e.primary;if(this.pendingRowKeyUpdate&&"row"===s){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),s=Math.max(this.anchor,t);for(let t=e;t<=s;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.#t())}if(this.pendingKeyboardUpdate&&"range"===s){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,s=this.grid._focusCol;if(e&&this.cellAnchor){const e=g(this.cellAnchor,{row:t,col:s});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:s});this.emit("selection-change",this.#t())}this.#o(s),this.gridElement.setAttribute("data-selection-mode",s),t&&t.classList.toggle("selecting",this.isDragging),this.#r()}onScrollRender(){this.isSelectionEnabled()&&this.#r()}getSelection(){const e=this.#t();return{mode:this.config.mode,activeAxis:e.activeAxis,ranges:e.ranges,selectedColumns:e.selectedColumns,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=new Map;for(const s of e)for(const e of u(s))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return h(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#t()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const s={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[s],this.activeRange=s,this.emit("selection-change",this.#t()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#e.primary)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const s of t)s>=0&&s<this.rows.length&&this.isRowSelectable(s)&&this.selected.add(s);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#t()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const e=this.#e.primary,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=new Set;for(const s of this.ranges){const i=Math.max(0,Math.min(s.startRow,s.endRow)),l=Math.min(t.length-1,Math.max(s.startRow,s.endRow));for(let t=i;t<=l;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}#s(e){if(!this.#e.columnEnabled)return;const t=r(this.visibleColumns),s=new Set(t),i=[],l=new Set;for(const o of e)s.has(o)&&!l.has(o)&&(l.add(o),i.push(o));this.#c("column"),this.selectedColumns.clear();for(const o of i)this.selectedColumns.add(o);const n=i.length>0?i[i.length-1]:null;this.columnAnchor=n,this.columnHead=n,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#t()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#e.columnEnabled)return;const s=r(this.visibleColumns);if(!s.includes(e))return;this.#c("column");if(!1!==this.config.multiSelect)if(t.range&&this.columnAnchor){const t=function(e,t,s){const i=c(e,s),l=c(t,s);if(-1===i||-1===l)return[];const n=Math.min(i,l),o=Math.max(i,l);return s.slice(n,o+1)}(this.columnAnchor,e,s);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);else 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.#t()),this.requestAfterRender()}deselectColumn(e){this.#e.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.#t()),this.requestAfterRender())}selectAllColumns(){if(!this.#e.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=r(this.visibleColumns);if(0!==e.length){this.#c("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.#t()),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.#t()),this.requestAfterRender())}getSelectedColumns(){if(0===this.selectedColumns.size)return[];return r(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.#t()),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.#t()),this.requestAfterRender()}#t(){const e=this.#e.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let i;this.#e.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"selectionAxisChanged","row"))),i=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=i;const l=function(e,t,s,i,l,n){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:n.filter(e=>i.selectedColumns.has(e))};if("cell"===s&&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"===s&&i.selected.size>0){const t=[...i.selected].sort((e,t)=>e-t),s=[];let n=t[0],o=n;for(let e=1;e<t.length;e++)t[e]===o+1?o=t[e]:(s.push({from:{row:n,col:0},to:{row:o,col:l-1}}),n=t[e],o=n);return s.push({from:{row:n,col:0},to:{row:o,col:l-1}}),{mode:e,activeAxis:"row",ranges:s,selectedColumns:[]}}return"range"===s&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(o=i.ranges,o.map(d)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var o}(this.config.mode,i,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,r(this.visibleColumns));return this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if("column"===l.activeAxis){const e=l.selectedColumns;if(1===e.length){const t=e[0],i=this.columns.find(e=>e.field===t),l="string"==typeof i?.header&&i.header||t;s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"columnSelected",l))}else e.length>1?s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"columnSelectionChanged",e.length)):s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"columnSelectionCleared"))}else{const e="row"===l.activeAxis?this.selected.size:l.ranges.length;e>0&&s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"selectionChanged",e))}},150),l}#c(e){if(this.#e.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&&s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"selectionAxisChanged","column"))}}}e.SelectionPlugin=b,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/internal/aria"),require("../../core/internal/utils"),require("../../core/plugin/base-plugin"),require("../../core/plugin/expander-column")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/internal/aria","../../core/internal/utils","../../core/plugin/base-plugin","../../core/plugin/expander-column"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_selection={},e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,s,i,l,n){"use strict";function o(e){const t=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 o(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 s=e.find(e=>"column"!==e);if("column"===s)throw new Error(`[SelectionPlugin] Invalid selection mode: [${e.join(", ")}].`);return{primary:s,columnEnabled:!0,bothAxes:!0}}function r(e){const t=[];for(const s of e)!0!==s.utility&&"string"==typeof s.field&&s.field.length>0&&t.push(s.field);return t}function c(e,t){return t.indexOf(e)}function a(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 d(e){const t=a(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function h(e,t,s){return s.some(s=>function(e,t,s){const i=a(s);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,s))}function u(e){const t=[],s=a(e);for(let i=s.startRow;i<=s.endRow;i++)for(let e=s.startCol;e<=s.endCol;e++)t.push({row:i,col:e});return t}function g(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function m(e,t){const s=a(e),i=a(t);return s.startRow===i.startRow&&s.startCol===i.startCol&&s.endRow===i.endRow&&s.endCol===i.endCol}function f(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"}const w="__tbw_checkbox";class b extends l.BaseGridPlugin{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"},{type:"getSelectedColumns",description:"Get field names of selected columns (column mode only)"},{type:"selectColumns",description:"Select specific columns by field name (column mode only)"}],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"===f(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"!==f(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}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:"";position:absolute;inset:0;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}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:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}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:.6}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:.6}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;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}tbw-grid .header-row>.cell.column-selected,tbw-grid .data-grid-row>.cell.column-selected{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 .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)}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0}}selected=new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;pendingRowKeyUpdate=null;selectedCell=null;selectedColumns=new Set;columnAnchor=null;columnHead=null;activeAxis="none";#e={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:s}=this.config;if(!s)return!0;const i=this.rows[e];if(!i)return!1;return s(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.#e=o(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.#e.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.#t()),this.requestAfterRender())))});let t=-1;e.addEventListener("data-change",e=>{const{sourceRowCount:s}=e.detail,i=this.selected.size>0||this.ranges.length>0||null!==this.selectedCell;-1!==t&&s!==t&&i&&this.clearSelectionSilent(),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.#s(t),!0}}detach(){const e=this.gridElement?.querySelector(".rows-body");e?.removeAttribute("aria-multiselectable"),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()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:s,originalEvent:i}=e,{triggerOn:l="click"}=this.config,o=this.#e.primary;if(i.type!==l)return!1;const r=e.column,c=r&&n.isUtilityColumn(r);if("cell"===o){if(c)return!1;if(!this.isCellSelectable(t,s))return!1;const e=this.selectedCell;return e&&e.row===t&&e.col===s||(this.selectedCell={row:t,col:s},this.emit("selection-change",this.#t()),this.requestAfterRender()),!1}if("row"===o){if(!this.isRowSelectable(t))return!1;const e=!1!==this.config.multiSelect,s=i.shiftKey&&e,l=(i.ctrlKey||i.metaKey)&&e,n=!0===r?.checkboxColumn;if(s&&null!==this.anchor){const e=Math.min(this.anchor,t),s=Math.max(this.anchor,t);l||this.selected.clear();for(let t=e;t<=s;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(l||n&&e)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.#t()),this.requestAfterRender(),!1}if("range"===o){if(c)return!1;if(!this.isCellSelectable(t,s))return!1;const e=i.shiftKey,l=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(e&&this.cellAnchor){const e=g(this.cellAnchor,{row:t,col:s}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&m(i,e))return!1;l?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else if(l){const e={startRow:t,startCol:s,endRow:t,endCol:s};this.ranges.push(e),this.activeRange=e,this.cellAnchor={row:t,col:s}}else{const e={startRow:t,startCol:s,endRow:t,endCol:s};if(1===this.ranges.length&&m(this.ranges[0],e))return!1;this.ranges=[e],this.activeRange=e,this.cellAnchor={row:t,col:s}}return this.emit("selection-change",this.#t()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const t=this.#e.primary,s=this.#e.columnEnabled,i=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if(s&&(e.ctrlKey||e.metaKey)&&(" "===e.key||"Spacebar"===e.key)){const t=this.grid._focusCol,s=this.visibleColumns[t];if(s&&!n.isUtilityColumn(s)&&"string"==typeof s.field)return e.preventDefault(),e.stopPropagation(),this.selectColumn(s.field,{toggle:!0}),!0}if(s&&"column"===this.activeAxis&&!1!==this.config.multiSelect&&(e.ctrlKey||e.metaKey)&&e.shiftKey&&("ArrowLeft"===e.key||"ArrowRight"===e.key)){const t=r(this.visibleColumns),s="ArrowLeft"===e.key?"left":"right",i=function(e,t,s){if(0===t.length)return null;if(null===e)return null;const i=c(e,t);if(i<0)return null;const l="left"===s?Math.max(0,i-1):Math.min(t.length-1,i+1);return l===i?null:t[l]}(this.columnHead,t,s);if(null!==i&&null!==this.columnAnchor)return e.preventDefault(),e.stopPropagation(),this.selectColumn(i,{range:!0}),!0}if("Escape"===e.key){return!this.grid.query("isEditing").some(Boolean)&&("column"===this.activeAxis?(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.emit("selection-change",this.#t()),this.requestAfterRender(),!0):("cell"===t?this.selectedCell=null:"row"===t?(this.selected.clear(),this.anchor=null):"range"===t&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#t()),this.requestAfterRender(),!0))}if("cell"===t&&i)return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.isCellSelectable(e,t)?this.selectedCell={row:e,col:t}:this.selectedCell=null,this.emit("selection-change",this.#t()),this.requestAfterRender()}),!1;if("row"===t){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 s=e.shiftKey&&t;return s&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if(t&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}}if("range"===t&&i){const t="Tab"===e.key,s=e.shiftKey&&!t;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if("range"===t&&!1!==this.config.multiSelect&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}return!1}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("range"!==this.#e.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(2===e.originalEvent.button&&h(e.rowIndex,e.colIndex,this.ranges))return;if(e.column&&n.isUtilityColumn(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,s=e.colIndex,i=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,l={startRow:t,startCol:s,endRow:t,endCol:s};return!i&&1===this.ranges.length&&m(this.ranges[0],l)?(this.cellAnchor={row:t,col:s},!0):(this.cellAnchor={row:t,col:s},i||(this.ranges=[]),this.ranges.push(l),this.activeRange=l,this.emit("selection-change",this.#t()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#e.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 s=this.visibleColumns[t];if(s&&n.isUtilityColumn(s)){const e=this.visibleColumns.findIndex(e=>!n.isUtilityColumn(e));e>=0&&(t=e)}const i=g(this.cellAnchor,{row:e.rowIndex,col:t}),l=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return l&&m(l,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#t()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#e.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#e.columnEnabled)return!1;if(e.column&&n.isUtilityColumn(e.column))return!1;const t=e.originalEvent;if(!(t.ctrlKey||t.metaKey))return!1;const s=e.field;if(!s)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(s,i?{range:!0}:{toggle:!0}),!0}processColumns(e){if(this.config.checkbox&&"row"===this.#e.primary){if(e.some(e=>e.field===w))return e;const t=this.#i(),s=e.findIndex(n.isExpanderColumn),i=s>=0?s+1:0;return[...e.slice(0,i),t,...e.slice(i)]}return e}#i(){return{field:w,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("div");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const s=e.cellEl;if(s){const e=parseInt(s.getAttribute("data-row")??"-1",10);e>=0&&(t.checked=this.selected.has(e))}return t}}}#l(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),s=t?i.getRowIndexFromCell(t):-1;s>=0&&(e.checked=this.selected.has(s))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let s=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&s++;else s=e;const i=s>0&&this.selected.size>=s,l=this.selected.size>0;t.checked=i,t.indeterminate=l&&!i}}#n(){return this.gridElement?.hasAttribute("data-has-focus")??!1}#o(e){const t=this.grid._focusRow,s=this.grid._focusCol;if(!this.#n())return this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=s);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.#t()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=s);if((t!==this.lastSyncedFocusRow||s!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=s,this.isCellSelectable(t,s))){const e=this.selectedCell;e&&e.row===t&&e.col===s||(this.selectedCell={row:t,col:s},this.emit("selection-change",this.#t()))}}}#r(){const e=this.gridElement;if(!e)return;const s=this.#e.primary,l=this.#e.columnEnabled,o=!!this.config.isSelectable,r=e.querySelector(".rows-body");if(r){const e=!1!==this.config.multiSelect;r.setAttribute("aria-multiselectable",e?"true":"false")}e.querySelectorAll(".cell").forEach(e=>{const s=e.classList.contains(t.GridClasses.SELECTED)||e.classList.contains("column-selected");e.classList.remove(t.GridClasses.SELECTED,"top","bottom","first","last","column-selected"),s&&e.removeAttribute("aria-selected"),o&&e.removeAttribute("data-selectable")});const c=e.querySelectorAll(".data-grid-row");if(c.forEach(e=>{e.classList.remove(t.GridClasses.SELECTED,"row-focus"),e.setAttribute("aria-selected","false"),o&&e.removeAttribute("data-selectable")}),l){e.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")})}if("row"===s&&(i.clearCellFocus(e),c.forEach(e=>{const s=e.querySelector(".cell[data-row]"),l=i.getRowIndexFromCell(s);l>=0&&(o&&!this.isRowSelectable(l)&&e.setAttribute("data-selectable","false"),this.selected.has(l)&&(e.classList.add(t.GridClasses.SELECTED,"row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#l(e)),("cell"===s||"range"===s)&&o){e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),s=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&s>=0&&(this.isCellSelectable(t,s)||e.setAttribute("data-selectable","false"))})}if("range"===s&&this.ranges.length>0){i.clearCellFocus(e);const s=this.ranges.map(a),l=(e,t)=>{for(const i of s)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const s=parseInt(e.getAttribute("data-row")??"-1",10),i=parseInt(e.getAttribute("data-col")??"-1",10);if(s>=0&&i>=0){const o=this.visibleColumns[i];if(o&&n.isUtilityColumn(o))return;l(s,i)&&(e.classList.add(t.GridClasses.SELECTED),e.setAttribute("aria-selected","true"),l(s-1,i)||e.classList.add("top"),l(s+1,i)||e.classList.add("bottom"),l(s,i-1)||e.classList.add("first"),l(s,i+1)||e.classList.add("last"))}})}if(l&&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 s=parseInt(e.getAttribute("data-col")??"-1",10),i=s>=0?t[s]: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 s=parseInt(e.getAttribute("data-col")??"-1",10);if(s<0)return;const i=this.visibleColumns[s];if(!i||n.isUtilityColumn(i))return;const l=t[s];l&&this.selectedColumns.has(l)&&(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"),s=this.#e.primary;if(this.pendingRowKeyUpdate&&"row"===s){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),s=Math.max(this.anchor,t);for(let t=e;t<=s;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.#t())}if(this.pendingKeyboardUpdate&&"range"===s){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,s=this.grid._focusCol;if(e&&this.cellAnchor){const e=g(this.cellAnchor,{row:t,col:s});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:s});this.emit("selection-change",this.#t())}this.#o(s),this.gridElement.setAttribute("data-selection-mode",s),t&&t.classList.toggle("selecting",this.isDragging),this.#r()}onScrollRender(){this.isSelectionEnabled()&&this.#r()}getSelection(){const e=this.#t();return{mode:this.config.mode,activeAxis:e.activeAxis,ranges:e.ranges,selectedColumns:e.selectedColumns,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=new Map;for(const s of e)for(const e of u(s))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return h(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#t()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const s={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[s],this.activeRange=s,this.emit("selection-change",this.#t()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#e.primary)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const s of t)s>=0&&s<this.rows.length&&this.isRowSelectable(s)&&this.selected.add(s);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#t()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const e=this.#e.primary,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=new Set;for(const s of this.ranges){const i=Math.max(0,Math.min(s.startRow,s.endRow)),l=Math.min(t.length-1,Math.max(s.startRow,s.endRow));for(let t=i;t<=l;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}#s(e){if(!this.#e.columnEnabled)return;const t=r(this.visibleColumns),s=new Set(t),i=[],l=new Set;for(const o of e)s.has(o)&&!l.has(o)&&(l.add(o),i.push(o));this.#c("column"),this.selectedColumns.clear();for(const o of i)this.selectedColumns.add(o);const n=i.length>0?i[i.length-1]:null;this.columnAnchor=n,this.columnHead=n,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#t()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#e.columnEnabled)return;const s=r(this.visibleColumns);if(!s.includes(e))return;this.#c("column");if(!1!==this.config.multiSelect)if(t.range&&this.columnAnchor){const t=function(e,t,s){const i=c(e,s),l=c(t,s);if(-1===i||-1===l)return[];const n=Math.min(i,l),o=Math.max(i,l);return s.slice(n,o+1)}(this.columnAnchor,e,s);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);else 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.#t()),this.requestAfterRender()}deselectColumn(e){this.#e.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.#t()),this.requestAfterRender())}selectAllColumns(){if(!this.#e.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=r(this.visibleColumns);if(0!==e.length){this.#c("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.#t()),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.#t()),this.requestAfterRender())}getSelectedColumns(){if(0===this.selectedColumns.size)return[];return r(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.#t()),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.#t()),this.requestAfterRender()}#t(){const e=this.#e.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let i;this.#e.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"selectionAxisChanged","row"))),i=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=i;const l=function(e,t,s,i,l,n){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:n.filter(e=>i.selectedColumns.has(e))};if("cell"===s&&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"===s&&i.selected.size>0){const t=[...i.selected].sort((e,t)=>e-t),s=[];let n=t[0],o=n;for(let e=1;e<t.length;e++)t[e]===o+1?o=t[e]:(s.push({from:{row:n,col:0},to:{row:o,col:l-1}}),n=t[e],o=n);return s.push({from:{row:n,col:0},to:{row:o,col:l-1}}),{mode:e,activeAxis:"row",ranges:s,selectedColumns:[]}}return"range"===s&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(o=i.ranges,o.map(d)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var o}(this.config.mode,i,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,r(this.visibleColumns));return this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if("column"===l.activeAxis){const e=l.selectedColumns;if(1===e.length){const t=e[0],i=this.columns.find(e=>e.field===t),l="string"==typeof i?.header&&i.header||t;s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"columnSelected",l))}else e.length>1?s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"columnSelectionChanged",e.length)):s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"columnSelectionCleared"))}else{const e="row"===l.activeAxis?this.selected.size:l.ranges.length;e>0&&s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"selectionChanged",e))}},150),l}#c(e){if(this.#e.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&&s.announce(this.gridElement,s.getA11yMessage(this.gridElement,"selectionAxisChanged","column"))}}}e.SelectionPlugin=b,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=selection.umd.js.map
|