@toolbox-web/grid 3.8.3 → 3.9.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.
Files changed (84) hide show
  1. package/all.d.ts +1 -0
  2. package/all.js +1 -1
  3. package/all.js.map +1 -1
  4. package/index.js +1 -1
  5. package/index.js.map +1 -1
  6. package/lib/core/plugin/base-plugin.d.ts +14 -0
  7. package/lib/core/plugin/plugin-manager.d.ts +5 -1
  8. package/lib/core/plugin/types.d.ts +2 -0
  9. package/lib/features/registry.js +1 -1
  10. package/lib/plugins/clipboard/index.js +1 -1
  11. package/lib/plugins/clipboard/index.js.map +1 -1
  12. package/lib/plugins/column-virtualization/index.js +1 -1
  13. package/lib/plugins/column-virtualization/index.js.map +1 -1
  14. package/lib/plugins/context-menu/index.js +1 -1
  15. package/lib/plugins/context-menu/index.js.map +1 -1
  16. package/lib/plugins/editing/index.js +1 -1
  17. package/lib/plugins/editing/index.js.map +1 -1
  18. package/lib/plugins/export/index.js +1 -1
  19. package/lib/plugins/export/index.js.map +1 -1
  20. package/lib/plugins/filtering/index.js +1 -1
  21. package/lib/plugins/filtering/index.js.map +1 -1
  22. package/lib/plugins/grouping-columns/index.js +1 -1
  23. package/lib/plugins/grouping-columns/index.js.map +1 -1
  24. package/lib/plugins/grouping-rows/grouping-rows-plugin.d.ts +20 -24
  25. package/lib/plugins/grouping-rows/grouping-rows.d.ts +9 -4
  26. package/lib/plugins/grouping-rows/index.d.ts +1 -1
  27. package/lib/plugins/grouping-rows/index.js +1 -1
  28. package/lib/plugins/grouping-rows/index.js.map +1 -1
  29. package/lib/plugins/grouping-rows/types.d.ts +32 -4
  30. package/lib/plugins/hierarchy/hierarchy-plugin.d.ts +79 -0
  31. package/lib/plugins/hierarchy/hierarchy.d.ts +28 -0
  32. package/lib/plugins/hierarchy/index.d.ts +9 -0
  33. package/lib/plugins/hierarchy/index.js +2 -0
  34. package/lib/plugins/hierarchy/index.js.map +1 -0
  35. package/lib/plugins/hierarchy/types.d.ts +92 -0
  36. package/lib/plugins/master-detail/index.js +1 -1
  37. package/lib/plugins/master-detail/index.js.map +1 -1
  38. package/lib/plugins/multi-sort/index.js +1 -1
  39. package/lib/plugins/multi-sort/index.js.map +1 -1
  40. package/lib/plugins/pinned-columns/index.js +1 -1
  41. package/lib/plugins/pinned-columns/index.js.map +1 -1
  42. package/lib/plugins/pinned-rows/index.js +1 -1
  43. package/lib/plugins/pinned-rows/index.js.map +1 -1
  44. package/lib/plugins/pivot/index.js +1 -1
  45. package/lib/plugins/pivot/index.js.map +1 -1
  46. package/lib/plugins/print/index.js +1 -1
  47. package/lib/plugins/print/index.js.map +1 -1
  48. package/lib/plugins/reorder-columns/index.js +1 -1
  49. package/lib/plugins/reorder-columns/index.js.map +1 -1
  50. package/lib/plugins/responsive/index.js +1 -1
  51. package/lib/plugins/responsive/index.js.map +1 -1
  52. package/lib/plugins/row-drag-drop/index.js +1 -1
  53. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  54. package/lib/plugins/selection/index.js +1 -1
  55. package/lib/plugins/selection/index.js.map +1 -1
  56. package/lib/plugins/server-side/index.js +1 -1
  57. package/lib/plugins/server-side/index.js.map +1 -1
  58. package/lib/plugins/shell/index.js +1 -1
  59. package/lib/plugins/shell/index.js.map +1 -1
  60. package/lib/plugins/sticky-rows/index.js +1 -1
  61. package/lib/plugins/sticky-rows/index.js.map +1 -1
  62. package/lib/plugins/tooltip/index.js +1 -1
  63. package/lib/plugins/tooltip/index.js.map +1 -1
  64. package/lib/plugins/tree/index.js +1 -1
  65. package/lib/plugins/tree/index.js.map +1 -1
  66. package/lib/plugins/tree/tree-datasource.d.ts +7 -10
  67. package/lib/plugins/tree/tree-plugin.d.ts +23 -3
  68. package/lib/plugins/undo-redo/index.js +1 -1
  69. package/lib/plugins/undo-redo/index.js.map +1 -1
  70. package/lib/plugins/visibility/index.js +1 -1
  71. package/lib/plugins/visibility/index.js.map +1 -1
  72. package/package.json +1 -1
  73. package/umd/grid.all.umd.js +1 -1
  74. package/umd/grid.all.umd.js.map +1 -1
  75. package/umd/grid.umd.js +1 -1
  76. package/umd/grid.umd.js.map +1 -1
  77. package/umd/plugins/grouping-rows.umd.js +1 -1
  78. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  79. package/umd/plugins/hierarchy.umd.js +2 -0
  80. package/umd/plugins/hierarchy.umd.js.map +1 -0
  81. package/umd/plugins/selection.umd.js +1 -1
  82. package/umd/plugins/selection.umd.js.map +1 -1
  83. package/umd/plugins/tree.umd.js +1 -1
  84. package/umd/plugins/tree.umd.js.map +1 -1
@@ -0,0 +1,2 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/plugin/base-plugin")):"function"==typeof define&&define.amd?define(["exports","../../core/plugin/base-plugin"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_hierarchy={},e.TbwGrid)}(this,function(e,t){function r(e,t,r=new WeakMap){const o=[];for(const c of["structure","transform"])for(const r of t)r.hierarchyStage===c&&r.beginHierarchy(e)&&o.push(r);if(0===o.length)return[...e];const n=[],i=(e,t,r)=>{const n={parent:t?t.row:null,parentKey:t?.key??null,depth:r};for(const i of o)e=i.processSiblings(e,n);return e},s=(e,t)=>{const o=e.length;for(let l=0;l<o;l++){const a=e[l];n.push(a.row),"object"==typeof a.row&&null!==a.row&&r.set(a.row,{level:t+1,setSize:o,posInSet:l+1});const u=a.children;a.expanded&&u&&s(a.shaped?u:i(u,a,t+1),t+1)}},l=new Array(e.length);for(let c=0;c<e.length;c++)l[c]={row:e[c]};s(i(l,null,0),0);const a=e=>"object"==typeof e&&null!==e?r.get(e):void 0;let u=!1;for(const c of o)c.endHierarchy(n,a)&&(u=!0);if(!u)for(const c of n)"object"==typeof c&&null!==c&&r.delete(c);return n}function o(e,t,r){const o=String(r);e.getAttribute(t)!==o&&e.setAttribute(t,o)}function n(e){return"function"==typeof e.processSiblings}function i(e){return e.constructor.manifest?.hookPriority?.processRows??0}Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});var s=class extends t.BaseGridPlugin{static manifest={modifiesRowStructure:!0};name="hierarchy";#e=new WeakMap;detach(){this.gridElement?.querySelector(".rows-body")?.setAttribute("role","grid"),this.#e=new WeakMap}process(e,t){const o=this.#t();return o.includes(t)?o[o.length-1]!==t?e:(this.#e=new WeakMap,r(e,o,this.#e)):(this.#e=new WeakMap,r(e,[t],this.#e))}getRowMeta(e){return"object"==typeof e&&null!==e?this.#e.get(e):void 0}afterRender(){this.#r()}onScrollRender(){this.#r()}#t(){return(this.grid?._pluginManager?.getPlugins?.()??[]).filter(n).sort((e,t)=>i(e)-i(t))}#r(){if(0===this.#t().length)return;const e=this.gridElement?.querySelector(".rows");if(!e)return;let t=!1;for(const i of e.querySelectorAll(".data-grid-row")){const e=this.getRowMeta(i.__rowDataRef);e?(t=!0,o(i,"aria-level",e.level),o(i,"aria-setsize",e.setSize),o(i,"aria-posinset",e.posInSet)):(i.removeAttribute("aria-level"),i.removeAttribute("aria-setsize"),i.removeAttribute("aria-posinset"))}const r=t?"treegrid":"grid",n=this.gridElement?.querySelector(".rows-body");n&&n.getAttribute("role")!==r&&n.setAttribute("role",r)}};e.HierarchyPlugin=s,e.buildHierarchy=r});
2
+ //# sourceMappingURL=hierarchy.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hierarchy.umd.js","names":[],"sources":["../../../../../libs/grid/src/lib/plugins/hierarchy/hierarchy.ts","../../../../../libs/grid/src/lib/plugins/hierarchy/hierarchy-plugin.ts"],"sourcesContent":["/**\n * Hierarchy Engine\n *\n * Pure row-model builder shared by the HierarchyPlugin and its contributors.\n */\n\nimport type { HierarchyContributor, HierarchyNode, HierarchyRowMeta } from './types';\n\n/**\n * Build the flat row list for `rows` from every contributor's sibling-list\n * transforms, recording each emitted row's ARIA position in `meta`.\n *\n * Contributors whose `beginHierarchy` returns `false` sit out the rebuild.\n * With no active contributor the rows pass through unchanged. When every\n * active contributor's `endHierarchy` returns `false`, no position is kept in `meta`.\n *\n * This is what `HierarchyPlugin.process()` runs for all attached contributors.\n * Call it directly to run a contributor without a grid — e.g. as the\n * `processRows` fallback when no HierarchyPlugin is attached, or in unit tests.\n *\n * @example\n * ```ts\n * override processRows(rows: readonly unknown[]): unknown[] {\n * const hierarchy = this.grid?.getPluginByName('hierarchy');\n * return hierarchy ? hierarchy.process(rows, this) : buildHierarchy(rows, [this]);\n * }\n * ```\n *\n * @param rows - The root rows.\n * @param contributors - Contributors to run, in `processRows` hook order.\n * @param meta - Receives each emitted row's position. Pass a fresh map per rebuild.\n * @returns The flattened rows, in render order.\n * @since 3.9.0\n */\nexport function buildHierarchy(\n rows: readonly unknown[],\n contributors: readonly HierarchyContributor[],\n meta: WeakMap<object, HierarchyRowMeta> = new WeakMap(),\n): unknown[] {\n const active: HierarchyContributor[] = [];\n for (const stage of ['structure', 'transform'] as const) {\n for (const c of contributors) {\n if (c.hierarchyStage === stage && c.beginHierarchy(rows)) active.push(c);\n }\n }\n if (active.length === 0) return [...rows];\n\n const out: unknown[] = [];\n const process = (nodes: HierarchyNode[], parent: HierarchyNode | null, depth: number): HierarchyNode[] => {\n const context = { parent: parent ? parent.row : null, parentKey: parent?.key ?? null, depth };\n for (const c of active) nodes = c.processSiblings(nodes, context);\n return nodes;\n };\n const emit = (nodes: HierarchyNode[], depth: number): void => {\n const setSize = nodes.length;\n for (let i = 0; i < setSize; i++) {\n const node = nodes[i];\n out.push(node.row);\n if (typeof node.row === 'object' && node.row !== null) {\n meta.set(node.row, { level: depth + 1, setSize, posInSet: i + 1 });\n }\n const children = node.children;\n if (node.expanded && children) {\n emit(node.shaped ? children : process(children, node, depth + 1), depth + 1);\n }\n }\n };\n\n const roots: HierarchyNode[] = new Array(rows.length);\n for (let i = 0; i < rows.length; i++) roots[i] = { row: rows[i] };\n emit(process(roots, null, 0), 0);\n\n const positionOf = (row: unknown) => (typeof row === 'object' && row !== null ? meta.get(row) : undefined);\n let shaped = false;\n for (const c of active) if (c.endHierarchy(out, positionOf)) shaped = true;\n if (!shaped) {\n for (const row of out) if (typeof row === 'object' && row !== null) meta.delete(row);\n }\n return out;\n}\n","/**\n * Hierarchy Plugin\n *\n * Owns the hierarchical row model shared by structure-contributing plugins.\n */\n\nimport type { PluginManifest } from '../../core/plugin/base-plugin';\nimport { BaseGridPlugin } from '../../core/plugin/base-plugin';\nimport type { RowElementInternal } from '../../core/types';\nimport { buildHierarchy } from './hierarchy';\nimport type { HierarchyContributor, HierarchyRowMeta } from './types';\n\n/** Attribute write that skips the DOM mutation when the value is unchanged (per-frame hot path). */\nfunction setAttrIfChanged(el: Element, name: string, value: number): void {\n const next = String(value);\n if (el.getAttribute(name) !== next) el.setAttribute(name, next);\n}\n\nfunction isContributor(plugin: unknown): plugin is HierarchyContributor & BaseGridPlugin {\n return typeof (plugin as Partial<HierarchyContributor>).processSiblings === 'function';\n}\n\nfunction processRowsPriority(plugin: BaseGridPlugin): number {\n return (plugin.constructor as typeof BaseGridPlugin).manifest?.hookPriority?.processRows ?? 0;\n}\n\n/**\n * Hierarchy Plugin for tbw-grid\n *\n * Builds one hierarchical row model from every attached structure contributor\n * — {@link https://toolboxjs.com/grid/plugins/tree/ | TreePlugin} discovers\n * child rows, {@link https://toolboxjs.com/grid/plugins/grouping-rows/ | GroupingRowsPlugin}\n * groups sibling lists — and announces each row's position with the WAI-ARIA\n * treegrid pattern (`aria-level` / `aria-setsize` / `aria-posinset`).\n *\n * Contributors know nothing about each other, so they compose: a grid with\n * both Tree and GroupingRows groups the children of every tree level.\n *\n * You never need to add this plugin yourself — TreePlugin and\n * GroupingRowsPlugin declare it as a dependency and the grid attaches it\n * automatically. It has no configuration.\n *\n * @example Group the children of every tree node\n * ```ts\n * import { TreePlugin } from '@toolbox-web/grid/plugins/tree';\n * import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';\n *\n * grid.gridConfig = {\n * plugins: [\n * new TreePlugin({ childrenField: 'children' }),\n * new GroupingRowsPlugin({\n * // Leave the root level ungrouped, group every child level by kind\n * groupOn: (row, { depth }) => (depth > 0 ? row.kind : null),\n * }),\n * ],\n * };\n * ```\n *\n * @since 3.9.0\n */\nexport class HierarchyPlugin extends BaseGridPlugin {\n /** @internal */\n static override readonly manifest: PluginManifest = {\n modifiesRowStructure: true,\n };\n\n /** @internal */\n readonly name = 'hierarchy';\n\n #meta = new WeakMap<object, HierarchyRowMeta>();\n\n /** @internal */\n override detach(): void {\n // Restore the default `role=\"grid\"` (template default in `core/internal/dom-builder.ts`).\n this.gridElement?.querySelector('.rows-body')?.setAttribute('role', 'grid');\n this.#meta = new WeakMap();\n }\n\n /**\n * Build the row model for a contributor's `processRows` hook.\n *\n * Every contributor forwards its hook here; only the one that runs last in\n * the `processRows` pipeline builds the model (for all contributors at\n * once) — the earlier ones pass their rows through untouched.\n *\n * @example\n * ```ts\n * override processRows(rows: readonly unknown[]): unknown[] {\n * return this.grid.getPluginByName('hierarchy')?.process(rows, this) ?? [...rows];\n * }\n * ```\n *\n * @since 3.9.0\n */\n process(rows: readonly unknown[], caller: HierarchyContributor): unknown[] {\n const contributors = this.#contributors();\n if (!contributors.includes(caller as HierarchyContributor & BaseGridPlugin)) {\n this.#meta = new WeakMap();\n return buildHierarchy(rows, [caller], this.#meta);\n }\n if (contributors[contributors.length - 1] !== caller) return rows as unknown[];\n this.#meta = new WeakMap();\n return buildHierarchy(rows, contributors, this.#meta);\n }\n\n /**\n * Hierarchy position of a row in the current row model, or `undefined` when\n * the row is not rendered (e.g. collapsed under a parent).\n *\n * @example\n * ```ts\n * const meta = grid.getPluginByName('hierarchy')?.getRowMeta(grid.rows[0]);\n * console.log(meta?.level, meta?.posInSet, meta?.setSize);\n * ```\n *\n * @since 3.9.0\n */\n getRowMeta(row: unknown): HierarchyRowMeta | undefined {\n return typeof row === 'object' && row !== null ? this.#meta.get(row) : undefined;\n }\n\n /** @internal */\n override afterRender(): void {\n this.#applyAria();\n }\n\n /** @internal */\n override onScrollRender(): void {\n this.#applyAria();\n }\n\n /** Attached contributors, in `processRows` hook order. */\n #contributors(): Array<HierarchyContributor & BaseGridPlugin> {\n const plugins = (this.grid?._pluginManager?.getPlugins?.() ?? []) as readonly BaseGridPlugin[];\n return plugins.filter(isContributor).sort((a, b) => processRowsPriority(a) - processRowsPriority(b));\n }\n\n #applyAria(): void {\n if (this.#contributors().length === 0) return;\n const body = this.gridElement?.querySelector('.rows');\n if (!body) return;\n\n let hierarchical = false;\n for (const rowEl of body.querySelectorAll('.data-grid-row')) {\n const meta = this.getRowMeta((rowEl as RowElementInternal).__rowDataRef);\n if (!meta) {\n // Pooled row elements may carry a position from a previous row model.\n rowEl.removeAttribute('aria-level');\n rowEl.removeAttribute('aria-setsize');\n rowEl.removeAttribute('aria-posinset');\n continue;\n }\n hierarchical = true;\n setAttrIfChanged(rowEl, 'aria-level', meta.level);\n setAttrIfChanged(rowEl, 'aria-setsize', meta.setSize);\n setAttrIfChanged(rowEl, 'aria-posinset', meta.posInSet);\n }\n\n // `treegrid` only while the model has hierarchy, so per-row level/setsize/posinset are valid in context.\n const role = hierarchical ? 'treegrid' : 'grid';\n const rowsBody = this.gridElement?.querySelector('.rows-body');\n if (rowsBody && rowsBody.getAttribute('role') !== role) rowsBody.setAttribute('role', role);\n }\n}\n"],"mappings":"sUAkCA,SAAgB,EACd,EACA,EACA,EAA0C,IAAI,SAE9C,MAAM,EAAiC,GACvC,IAAK,MAAM,IAAS,CAAC,YAAa,aAChC,IAAK,MAAM,KAAK,EACV,EAAE,iBAAmB,GAAS,EAAE,eAAe,IAAO,EAAO,KAAK,GAG1E,GAAsB,IAAlB,EAAO,OAAc,MAAO,IAAI,GAEpC,MAAM,EAAiB,GACjB,EAAA,CAAW,EAAwB,EAA8B,KACrE,MAAM,EAAU,CAAE,OAAQ,EAAS,EAAO,IAAM,KAAM,UAAW,GAAQ,KAAO,KAAM,SACtF,IAAK,MAAM,KAAK,EAAQ,EAAQ,EAAE,gBAAgB,EAAO,GACzD,OAAO,GAEH,EAAA,CAAQ,EAAwB,KACpC,MAAM,EAAU,EAAM,OACtB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAS,IAAK,CAChC,MAAM,EAAO,EAAM,GACnB,EAAI,KAAK,EAAK,KACU,iBAAb,EAAK,KAAiC,OAAb,EAAK,KACvC,EAAK,IAAI,EAAK,IAAK,CAAE,MAAO,EAAQ,EAAG,UAAS,SAAU,EAAI,IAEhE,MAAM,EAAW,EAAK,SAClB,EAAK,UAAY,GACnB,EAAK,EAAK,OAAS,EAAW,EAAQ,EAAU,EAAM,EAAQ,GAAI,EAAQ,EAE9E,GAGI,EAAyB,IAAI,MAAM,EAAK,QAC9C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAK,OAAQ,IAAK,EAAM,GAAK,CAAE,IAAK,EAAK,IAC7D,EAAK,EAAQ,EAAO,KAAM,GAAI,GAE9B,MAAM,EAAc,GAAiC,iBAAR,GAA4B,OAAR,EAAe,EAAK,IAAI,QAAO,EAChG,IAAI,GAAS,EACb,IAAK,MAAM,KAAK,EAAY,EAAE,aAAa,EAAK,KAAa,GAAS,GACtE,IAAK,EACE,IAAA,MAAM,KAAO,EAAwB,iBAAR,GAA4B,OAAR,GAAc,EAAK,OAAO,GAElF,OAAO,CACT,CClEA,SAAS,EAAiB,EAAa,EAAc,GACnD,MAAM,EAAO,OAAO,GAChB,EAAG,aAAa,KAAU,GAAM,EAAG,aAAa,EAAM,EAC5D,CAEA,SAAS,EAAc,GACrB,MAA4E,mBAA7D,EAAyC,eAC1D,CAEA,SAAS,EAAoB,GAC3B,OAAQ,EAAO,YAAsC,UAAU,cAAc,aAAe,CAC9F,8DAoCA,IAAa,EAAb,cAAqC,EAAA,eAEnC,gBAAoD,CAClD,sBAAsB,GAIxB,KAAgB,YAEhB,GAAQ,IAAI,QAGZ,MAAA,GAEE,KAAK,aAAa,cAAc,eAAe,aAAa,OAAQ,QACpE,MAAK,EAAQ,IAAI,OACnB,CAkBA,OAAA,CAAQ,EAA0B,GAChC,MAAM,EAAe,MAAK,IAC1B,OAAK,EAAa,SAAS,GAIvB,EAAa,EAAa,OAAS,KAAO,EAAe,GAC7D,MAAK,EAAQ,IAAI,QACV,EAAe,EAAM,EAAc,MAAK,KAL7C,MAAK,EAAQ,IAAI,QACV,EAAe,EAAM,CAAC,GAAS,MAAK,GAK/C,CAcA,UAAA,CAAW,GACT,MAAsB,iBAAR,GAA4B,OAAR,EAAe,MAAK,EAAM,IAAI,QAAO,CACzE,CAGA,WAAA,GACE,MAAK,GACP,CAGA,cAAA,GACE,MAAK,GACP,CAGA,EAAA,GAEE,OADiB,KAAK,MAAM,gBAAgB,gBAAkB,IAC/C,OAAO,GAAe,KAAA,CAAM,EAAG,IAAM,EAAoB,GAAK,EAAoB,GACnG,CAEA,EAAA,GACE,GAAoC,IAAhC,MAAK,IAAgB,OAAc,OACvC,MAAM,EAAO,KAAK,aAAa,cAAc,SAC7C,IAAK,EAAM,OAEX,IAAI,GAAe,EACnB,IAAK,MAAM,KAAS,EAAK,iBAAiB,kBAAmB,CAC3D,MAAM,EAAO,KAAK,WAAY,EAA6B,cACtD,GAOL,GAAe,EACf,EAAiB,EAAO,aAAc,EAAK,OAC3C,EAAiB,EAAO,eAAgB,EAAK,SAC7C,EAAiB,EAAO,gBAAiB,EAAK,YAR5C,EAAM,gBAAgB,cACtB,EAAM,gBAAgB,gBACtB,EAAM,gBAAgB,iBAO1B,CAGA,MAAM,EAAO,EAAe,WAAa,OACnC,EAAW,KAAK,aAAa,cAAc,cAC7C,GAAY,EAAS,aAAa,UAAY,GAAM,EAAS,aAAa,OAAQ,EACxF"}
@@ -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/pointer-modality"),require("../../core/internal/utils"),require("../../core/plugin/base-plugin"),require("../../core/plugin/expander-column"),require("../../core/internal/pointer-drag")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/internal/aria","../../core/internal/pointer-modality","../../core/internal/utils","../../core/plugin/base-plugin","../../core/plugin/expander-column","../../core/internal/pointer-drag"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_selection={},e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,n,i,s,l,o,r){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function c(){return"function"==typeof HTMLElement.prototype?.showPopover}function a(e,t){let n=null,i=!1,s=!1;const l=new AbortController;function o(){i&&n&&(i=!1,c()&&n.hidePopover(),n.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&n&&!e.composedPath().includes(n)&&o()},{capture:!0,signal:l.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&o()},{capture:!0,signal:l.signal}),{get element(){return n},open(r,a,d){if(s||0===d.length)return;n||(n=function(){const n=document.createElement("div");return n.id=e,n.className=t,n.setAttribute("popover","manual"),n.setAttribute("role","group"),n.hidden=!0,n.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!n.contains(t)&&o()},{signal:l.signal}),n}());const h=r.closest("tbw-grid, [data-tbw-grid]")??document.body;n.parentNode!==h&&h.appendChild(n),n.setAttribute("aria-label",a),n.replaceChildren();for(const e of d){const i=document.createElement("button");i.type="button",i.className=`${t}-item`,i.textContent=e.label,i.disabled=!0===e.disabled,i.addEventListener("click",()=>{o(),e.run()}),n.appendChild(i)}n.hidden=!1,!i&&c()&&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)),l=t.bottom+6,o=l+i.height<=window.innerHeight?l:Math.max(4,t.top-6-i.height);n.style.left=`${Math.round(s)}px`,n.style.top=`${Math.round(o)}px`}(r),n.querySelector("button:not([disabled])")?.focus()},close:o,dispose(){s=!0,o(),l.abort(),n?.remove(),n=null}}}function d(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 d(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 h(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 u(e,t){return t.indexOf(e)}function g(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function m(e){const t=g(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function w(e,t,n){return n.some(n=>function(e,t,n){const i=g(n);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,n))}function b(e){const t=[],n=g(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 f(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function p(e,t){const n=g(e),i=g(t);return n.startRow===i.startRow&&n.startCol===i.startCol&&n.endRow===i.endRow&&n.endCol===i.endCol}var C="tbw-selection-toolbar",y=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=C,t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Selection");const n=e.ownerDocument.createElement("span");n.className=`${C}-count`,n.setAttribute("aria-live","polite"),t.appendChild(n);const i=e.ownerDocument.createElement("div");i.className=`${C}-actions`,t.appendChild(i),i.appendChild(this.#l(e,"select-all","Select all",()=>this.#i?.selectAll())),i.appendChild(this.#l(e,"clear","Clear",()=>this.#i?.clear()));const s=this.#l(e,"more","More…",e=>this.#i?.more(e));s.setAttribute("aria-haspopup","menu"),i.appendChild(s),i.appendChild(this.#l(e,"done","Done",()=>this.#i?.done())),e.prepend(t),this.#e=t,this.#t=n,this.#n=s}#l(e,t,n,i){const s=e.ownerDocument.createElement("button");return s.type="button",s.className=`${C}-btn`,s.dataset.action=t,s.textContent=n,s.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),i(s)}),s}},v="tbw-range-handle",S=class{#o=null;#r=null;#i=null;#c=null;render(e,t,n,i){this.#i=i,t?(this.#o??=this.#a(e,"start"),this.#r??=this.#a(e,"end"),this.#d(e,this.#o,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.#o,"start"],[this.#r,"end"]]){if(!t)continue;const i=e===n;t.classList.toggle("armed",i),t.setAttribute("aria-pressed",String(i))}}destroy(){this.#o?.remove(),this.#r?.remove(),this.#o=null,this.#r=null,this.#i=null,this.#c=null}#h(){this.#o&&(this.#o.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?.(),l=e.getBoundingClientRect?.();if(!s||!l)return;const o="start"===i?s.left-l.left:s.right-l.left,r="start"===i?s.top-l.top:s.bottom-l.top;t.style.left=`${o}px`,t.style.top=`${r}px`}#a(e,t){const n=e.ownerDocument.createElement("div");return n.className=`${v} ${v}-${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 i=this.#i;if(!i)return;t.classList.add("dragging");let s=!1;(0,r.startPointerDrag)(e,t,{onMove:e=>{s=!0;const t=i.cellAt(e.clientX,e.clientY);t&&i.resize(n,t.row,t.col)},onEnd:()=>{t.classList.remove("dragging"),s?i.commit():i.arm(n)},onCancel:()=>{t.classList.remove("dragging"),i.commit()}})}};function A(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 x="__tbw_checkbox";function R(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||e.isContentEditable}var E=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"];var k=class 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)"},{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"===A(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"!==A(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 y;#b=new S;#f=null;#p=null;#C=null;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";#y={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;#v=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.#y=d(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.#y.primary&&this.isRowSelectable(e)&&(this.selected.has(e)||(!1===this.config.multiSelect&&this.selected.clear(),this.selected.add(e),this.lastSelected=e,this.anchor=e,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender())))});let t=-1;e.addEventListener("data-change",e=>{const{sourceRowCount:n}=e.detail,i=this.selected.size>0||this.ranges.length>0||null!==this.selectedCell;-1!==t&&n!==t&&i&&this.clearSelectionSilent(),t=n},{signal:this.disconnectSignal}),e.addEventListener("contextmenu",e=>{if(this.#x())return;const t=e.target?.closest?.(".cell[data-row][data-col]");if(!t)return;const n=parseInt(t.getAttribute("data-row")??"-1",10),i=parseInt(t.getAttribute("data-col")??"-1",10),s=this.#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("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.#b.destroy(),this.#C?.dispose(),this.#C=null,this.#f=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()}#M(e){const t=e.pointerType;return"touch"===t||"pen"===t||"mouse"!==t&&"coarse"===(0,i.getPrimaryPointer)()}#I(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.#A()),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.#A())),this.requestAfterRender())}#q(e){const t=this.anchor??e,n=Math.min(t,e),i=Math.max(t,e);for(let s=n;s<=i;s++)this.isRowSelectable(s)&&this.selected.add(s);this.lastSelected=e,this.emit("selection-change",this.#A()),this.requestAfterRender()}#x(){const e=this.grid?.getPluginByName?.("contextMenu")??this.grid?.getPluginByName?.("context-menu");return"function"==typeof e?.showMenu?e:void 0}#T(e,t){return this.gridElement?.querySelector(`.cell[data-row="${e}"][data-col="${t}"]`)??null}#P(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),l=parseInt(i.getAttribute("data-col")??"-1",10);return s>=0&&l>=0?{row:s,col:l}:null}#K(e,t,n){const i=this.ranges[this.ranges.length-1];if(!i)return;const s=g(i),l="start"===e?{row:s.endRow,col:s.endCol}:{row:s.startRow,col:s.startCol},o=f(l,{row:t,col:n});p(i,o)||(this.ranges[this.ranges.length-1]=o,this.activeRange=o,this.cellAnchor=l,this.emit("selection-change",this.#A()),this.requestAfterRender())}#R(e,t){if("range"!==this.#y.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.#L(e,t)}]:null}#L(e,t){const n=this.#p;if(!n)return;const i=f(n,{row:e,col:t});this.ranges=[i],this.activeRange=i,this.cellAnchor=n,this.emit("selection-change",this.#A()),this.requestAfterRender()}#E(e,t){this.#C??=a("tbw-range-extend-menu","tbw-range-extend-menu"),this.#C.open(e,"Selection",t)}#D(e){this.#f=this.#f===e?null:e,this.#b.setArmed(this.#f),this.gridElement&&(0,n.announce)(this.gridElement,this.#f?"Select a cell to place the selection corner":"Selection corner placement cancelled")}#z(){return!!this.#f&&(this.#f=null,this.#b.setArmed(null),!0)}#F(e){if(!e)return;this.#g?this.#w.show(e,this.selected.size,void 0!==this.#x(),{selectAll:()=>this.selectAll(),clear:()=>this.clearSelection(),done:()=>this.exitTouchSelection(),more:e=>this.#H(e)}):this.#w.destroy();const t=this.#m&&"range"===this.#y.primary&&this.ranges.length>0?this.ranges[this.ranges.length-1]:null,n=t?g(t):null;n||this.#z(),this.#b.render(e,n,(e,t)=>this.#T(e,t),{cellAt:(e,t)=>this.#P(e,t),resize:(e,t,n)=>this.#K(e,t,n),commit:()=>this.requestAfterRender(),arm:e=>this.#D(e)})}#H(e){const t=this.#x();if(!t)return;const n=e.getBoundingClientRect?.(),i=this.lastSelected??-1;t.showMenu(n?.left??0,n?.bottom??0,{row:i>=0?this.rows[i]:null,rowIndex:i,selectedRows:this.getSelectedRowIndices()})}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{triggerOn:t="click"}=this.config;if(e.originalEvent.type!==t)return!1;switch(this.#y.primary){case"cell":return this.#U(e);case"row":return this.#$(e);case"range":return this.#_(e);default:return!1}}#U(e){const{rowIndex:t,colIndex:n}=e;if(e.column&&(0,o.isUtilityColumn)(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;const i=this.selectedCell;return i&&i.row===t&&i.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()),this.requestAfterRender()),!1}#$(e){const{rowIndex:t,originalEvent:n,column:i}=e;if(!this.isRowSelectable(t))return!1;const s=!1!==this.config.multiSelect,l=n.shiftKey&&s,o=(n.ctrlKey||n.metaKey||this.#g)&&s,r=!0===i?.checkboxColumn;if(l&&null!==this.anchor){const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);o||this.selected.clear();for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(o||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.#A()),this.requestAfterRender(),!1}#_(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e;if(e.column&&(0,o.isUtilityColumn)(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;if(this.#f){const e=this.#f;return this.#z(),this.#K(e,t,n),!0}this.#m=this.#M(i);const s=i.shiftKey,l=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(s&&this.cellAnchor){const e=f(this.cellAnchor,{row:t,col:n}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&p(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{const e={startRow:t,startCol:n,endRow:t,endCol:n};if(l)this.ranges.push(e);else{if(1===this.ranges.length&&p(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.#A()),this.requestAfterRender(),!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;if(this.#y.columnEnabled&&this.#G(e))return!0;const t=this.#y.primary;if("Escape"===e.key&&this.#z())return!0;if("Escape"===e.key&&this.#g)return this.exitTouchSelection(),!0;if("Escape"===e.key)return this.#N(t);const n=E.includes(e.key);switch(t){case"cell":return!!n&&this.#B();case"row":return this.#j(e);case"range":return this.#O(e,n);default:return!1}}#G(e){if(!e.ctrlKey&&!e.metaKey)return!1;if(R(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||(0,o.isUtilityColumn)(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=h(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=u(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}#N(e){return!this.grid.query("isEditing").some(Boolean)&&("column"===this.activeAxis?(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none"):"cell"===e?this.selectedCell=null:"row"===e?(this.selected.clear(),this.anchor=null):"range"===e&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#B(){return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.selectedCell=this.isCellSelectable(e,t)?{row:e,col:t}:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}),!1}#j(e){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const n=e.shiftKey&&t;return n&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}return this.#W(e,t)}#O(e,t){if(!t)return this.#X(e)||this.#W(e,!1!==this.config.multiSelect);const n=e.shiftKey&&"Tab"!==e.key;return n&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}#X(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.#y.columnEnabled)return!1;n="column"}if(e.altKey)return!1;if(R(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 l={row:this.grid._focusRow,col:this.grid._focusCol},o=this.activeRange?g(this.activeRange):{startRow:l.row,startCol:l.col,endRow:l.row,endCol:l.col},r="row"===n?{startRow:o.startRow,startCol:0,endRow:o.endRow,endCol:s-1}:{startRow:0,startCol:o.startCol,endRow:i-1,endCol:o.endCol};e.preventDefault(),e.stopPropagation();const c={row:Math.abs(l.row-r.startRow)>=Math.abs(l.row-r.endRow)?r.startRow:r.endRow,col:Math.abs(l.col-r.startCol)>=Math.abs(l.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.#v={axis:n,count:"row"===n?r.endRow-r.startRow+1:r.endCol-r.startCol+1},this.emit("selection-change",this.#A()),this.requestAfterRender(),!0}#W(e,t){return!(!t||"a"!==e.key||!e.ctrlKey&&!e.metaKey)&&(!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0))}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("row"===this.#y.primary){if(void 0===e.rowIndex||e.rowIndex<0)return;if(!1===this.config.multiSelect)return;if(!this.#M(e.originalEvent))return;if(e.column&&(0,o.isUtilityColumn)(e.column))return;return this.#g?(this.#q(e.rowIndex),!0):this.#I(e.rowIndex)||void 0}if("range"!==this.#y.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(this.#f)return!0;if(this.#m=this.#M(e.originalEvent),2===e.originalEvent.button&&w(e.rowIndex,e.colIndex,this.ranges))return;if(e.column&&(0,o.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,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&&p(this.ranges[0],s)?(this.cellAnchor={row:t,col:n},this.#Q(e,t,n),!0):(this.cellAnchor={row:t,col:n},this.#Q(e,t,n),i||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#Q(e,t,n){2!==e.originalEvent.button&&(this.#p={row:t,col:n})}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#y.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&&(0,o.isUtilityColumn)(n)){const e=this.visibleColumns.findIndex(e=>!(0,o.isUtilityColumn)(e));e>=0&&(t=e)}const i=f(this.cellAnchor,{row:e.rowIndex,col:t}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return s&&p(s,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#A()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#y.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#y.columnEnabled)return!1;if(e.column&&(0,o.isUtilityColumn)(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.#y.primary){if(e.some(e=>e.field===x))return e;const t=this.#Y(),n=e.findIndex(o.isExpanderColumn),i=n>=0?n+1:0;return[...e.slice(0,i),t,...e.slice(i)]}return e}#Y(){return{field:x,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("label");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-all-checkbox";const i=document.createElement("span");return i.className="tbw-sr-only",i.textContent=(0,n.getA11yMessage)(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,i),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl,s=i?parseInt(i.getAttribute("data-row")??"-1",10):-1;return s>=0&&(t.checked=this.selected.has(s)),t.setAttribute("aria-label",(0,n.getA11yMessage)(this.gridElement,"selectRow",Math.max(s,0))),t}}}#J(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),n=t?(0,s.getRowIndexFromCell)(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.#A()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=n);if((t!==this.lastSyncedFocusRow||n!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=n,this.isCellSelectable(t,n))){const e=this.selectedCell;e&&e.row===t&&e.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()))}}}#ee(){const e=this.gridElement;if(!e)return;const n=this.#y.primary,i=this.#y.columnEnabled,l=!!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 n=e.classList.contains(t.GridClasses.SELECTED)||e.classList.contains("column-selected");e.classList.remove(t.GridClasses.SELECTED,"top","bottom","first","last","column-selected"),n&&e.removeAttribute("aria-selected"),l&&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"),l&&e.removeAttribute("data-selectable")}),i&&e.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")}),"row"===n&&((0,s.clearCellFocus)(e),c.forEach(e=>{const n=e.querySelector(".cell[data-row]"),i=(0,s.getRowIndexFromCell)(n);i>=0&&(l&&!this.isRowSelectable(i)&&e.setAttribute("data-selectable","false"),this.selected.has(i)&&(e.classList.add(t.GridClasses.SELECTED,"row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#J(e)),"cell"!==n&&"range"!==n||!l||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"===n&&this.ranges.length>0){(0,s.clearCellFocus)(e);const n=this.ranges.map(g),i=(e,t)=>{for(const i of n)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const n=parseInt(e.getAttribute("data-row")??"-1",10),s=parseInt(e.getAttribute("data-col")??"-1",10);if(n>=0&&s>=0){const l=this.visibleColumns[s];if(l&&(0,o.isUtilityColumn)(l))return;i(n,s)&&(e.classList.add(t.GridClasses.SELECTED),e.setAttribute("aria-selected","true"),i(n-1,s)||e.classList.add("top"),i(n+1,s)||e.classList.add("bottom"),i(n,s-1)||e.classList.add("first"),i(n,s+1)||e.classList.add("last"))}})}if(i&&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||(0,o.isUtilityColumn)(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.#y.primary;if(this.pendingRowKeyUpdate&&"row"===n){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#A())}if(this.pendingKeyboardUpdate&&"range"===n){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,n=this.grid._focusCol;if(e&&this.cellAnchor){let e=f(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.#A())}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.#A();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 n of e)for(const e of b(n))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return w(e,t,this.ranges)}selectAll(){const e=this.#y.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.#A()),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.#A()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#y.primary)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const n of t)n>=0&&n<this.rows.length&&this.isRowSelectable(n)&&this.selected.add(n);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const e=this.#y.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 n of this.ranges){const i=Math.max(0,Math.min(n.startRow,n.endRow)),s=Math.min(t.length-1,Math.max(n.startRow,n.endRow));for(let t=i;t<=s;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}#k(e){if(!this.#y.columnEnabled)return;const t=h(this.visibleColumns),n=new Set(t),i=[],s=new Set;for(const o of e)n.has(o)&&!s.has(o)&&(s.add(o),i.push(o));this.#te("column"),this.selectedColumns.clear();for(const o of i)this.selectedColumns.add(o);const l=i.length>0?i[i.length-1]:null;this.columnAnchor=l,this.columnHead=l,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#y.columnEnabled)return;const n=h(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=u(e,n),s=u(t,n);if(-1===i||-1===s)return[];const l=Math.min(i,s),o=Math.max(i,s);return n.slice(l,o+1)}(this.columnAnchor,e,n);this.selectedColumns.clear();for(const e of t)this.selectedColumns.add(e);this.columnHead=e}else t.toggle?(this.selectedColumns.has(e)?this.selectedColumns.delete(e):this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e):(this.selectedColumns.clear(),this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e);this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}}deselectColumn(e){this.#y.columnEnabled&&this.selectedColumns.delete(e)&&(0===this.selectedColumns.size&&(this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none")),this.emit("selection-change",this.#A()),this.requestAfterRender())}selectAllColumns(){if(!this.#y.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=h(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.#A()),this.requestAfterRender()}}clearColumnSelection(){0!==this.selectedColumns.size&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none"),this.emit("selection-change",this.#A()),this.requestAfterRender())}getSelectedColumns(){return 0===this.selectedColumns.size?[]:h(this.visibleColumns).filter(e=>this.selectedColumns.has(e))}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.emit("selection-change",this.#A()),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}#A(){const e=this.#y.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let i;this.#y.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"selectionAxisChanged","row"))),i=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=i;const s=function(e,t,n,i,s,l){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:l.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 l=t[0],o=l;for(let e=1;e<t.length;e++)t[e]===o+1?o=t[e]:(n.push({from:{row:l,col:0},to:{row:o,col:s-1}}),l=t[e],o=l);return n.push({from:{row:l,col:0},to:{row:o,col:s-1}}),{mode:e,activeAxis:"row",ranges:n,selectedColumns:[]}}return"range"===n&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(o=i.ranges,o.map(m)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var o}(this.config.mode,i,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,h(this.visibleColumns)),l=this.#v;return this.#v=null,this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if(l)(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"rangeSpanSelected",l.axis,l.count));else if("column"===s.activeAxis){const e=s.selectedColumns;if(1===e.length){const t=e[0],i=this.columns.find(e=>e.field===t),s="string"==typeof i?.header&&i.header||t;(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"columnSelected",s))}else e.length>1?(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"columnSelectionChanged",e.length)):(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"columnSelectionCleared"))}else{const e="row"===s.activeAxis?this.selected.size:s.ranges.length;e>0&&(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"selectionChanged",e))}},150),s}#te(e){if(this.#y.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&&(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"selectionAxisChanged","column"))}}};e.SelectionPlugin=k});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("../../core/constants"),require("../../core/internal/aria"),require("../../core/internal/pointer-modality"),require("../../core/internal/utils"),require("../../core/plugin/base-plugin"),require("../../core/plugin/expander-column"),require("../../core/internal/pointer-drag")):"function"==typeof define&&define.amd?define(["exports","../../core/constants","../../core/internal/aria","../../core/internal/pointer-modality","../../core/internal/utils","../../core/plugin/base-plugin","../../core/plugin/expander-column","../../core/internal/pointer-drag"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TbwGridPlugin_selection={},e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid,e.TbwGrid)}(this,function(e,t,n,i,s,l,o,r){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"});function c(){return"function"==typeof HTMLElement.prototype?.showPopover}function a(e,t){let n=null,i=!1,s=!1;const l=new AbortController;function o(){i&&n&&(i=!1,c()&&n.hidePopover(),n.hidden=!0)}return document.addEventListener("pointerdown",e=>{i&&n&&!e.composedPath().includes(n)&&o()},{capture:!0,signal:l.signal}),document.addEventListener("keydown",e=>{"Escape"===e.key&&o()},{capture:!0,signal:l.signal}),{get element(){return n},open(r,a,d){if(s||0===d.length)return;n||(n=function(){const n=document.createElement("div");return n.id=e,n.className=t,n.setAttribute("popover","manual"),n.setAttribute("role","group"),n.hidden=!0,n.addEventListener("focusout",e=>{const t=e.relatedTarget;t instanceof Node&&!n.contains(t)&&o()},{signal:l.signal}),n}());const h=r.closest("tbw-grid, [data-tbw-grid]")??document.body;n.parentNode!==h&&h.appendChild(n),n.setAttribute("aria-label",a),n.replaceChildren();for(const e of d){const i=document.createElement("button");i.type="button",i.className=`${t}-item`,i.textContent=e.label,i.disabled=!0===e.disabled,i.addEventListener("click",()=>{o(),e.run()}),n.appendChild(i)}n.hidden=!1,!i&&c()&&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)),l=t.bottom+6,o=l+i.height<=window.innerHeight?l:Math.max(4,t.top-6-i.height);n.style.left=`${Math.round(s)}px`,n.style.top=`${Math.round(o)}px`}(r),n.querySelector("button:not([disabled])")?.focus()},close:o,dispose(){s=!0,o(),l.abort(),n?.remove(),n=null}}}function d(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 d(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 h(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 u(e,t){return t.indexOf(e)}function g(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function m(e){const t=g(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function w(e,t,n){return n.some(n=>function(e,t,n){const i=g(n);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,n))}function b(e){const t=[],n=g(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 f(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function p(e,t){const n=g(e),i=g(t);return n.startRow===i.startRow&&n.startCol===i.startCol&&n.endRow===i.endRow&&n.endCol===i.endCol}var C="tbw-selection-toolbar",y=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=C,t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Selection");const n=e.ownerDocument.createElement("span");n.className=`${C}-count`,n.setAttribute("aria-live","polite"),t.appendChild(n);const i=e.ownerDocument.createElement("div");i.className=`${C}-actions`,t.appendChild(i),i.appendChild(this.#l(e,"select-all","Select all",()=>this.#i?.selectAll())),i.appendChild(this.#l(e,"clear","Clear",()=>this.#i?.clear()));const s=this.#l(e,"more","More…",e=>this.#i?.more(e));s.setAttribute("aria-haspopup","menu"),i.appendChild(s),i.appendChild(this.#l(e,"done","Done",()=>this.#i?.done())),e.prepend(t),this.#e=t,this.#t=n,this.#n=s}#l(e,t,n,i){const s=e.ownerDocument.createElement("button");return s.type="button",s.className=`${C}-btn`,s.dataset.action=t,s.textContent=n,s.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),i(s)}),s}},v="tbw-range-handle",S=class{#o=null;#r=null;#i=null;#c=null;render(e,t,n,i){this.#i=i,t?(this.#o??=this.#a(e,"start"),this.#r??=this.#a(e,"end"),this.#d(e,this.#o,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.#o,"start"],[this.#r,"end"]]){if(!t)continue;const i=e===n;t.classList.toggle("armed",i),t.setAttribute("aria-pressed",String(i))}}destroy(){this.#o?.remove(),this.#r?.remove(),this.#o=null,this.#r=null,this.#i=null,this.#c=null}#h(){this.#o&&(this.#o.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?.(),l=e.getBoundingClientRect?.();if(!s||!l)return;const o="start"===i?s.left-l.left:s.right-l.left,r="start"===i?s.top-l.top:s.bottom-l.top;t.style.left=`${o}px`,t.style.top=`${r}px`}#a(e,t){const n=e.ownerDocument.createElement("div");return n.className=`${v} ${v}-${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 i=this.#i;if(!i)return;t.classList.add("dragging");let s=!1;(0,r.startPointerDrag)(e,t,{onMove:e=>{s=!0;const t=i.cellAt(e.clientX,e.clientY);t&&i.resize(n,t.row,t.col)},onEnd:()=>{t.classList.remove("dragging"),s?i.commit():i.arm(n)},onCancel:()=>{t.classList.remove("dragging"),i.commit()}})}};function A(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 x="__tbw_checkbox";function R(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||e.isContentEditable}var E=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"];var k=class extends l.BaseGridPlugin{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 selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"},{type:"getSelectedColumns",description:"Get field names of selected columns (column mode only)"},{type:"selectColumns",description:"Select specific columns by field name (column mode only)"},{type:"getContextMenuItems",description:"Contribute the non-dragging range-extension action (WCAG 2.2 SC 2.5.7)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:'"triggerOn: \'dblclick\'" has no effect when mode is "range".\n → Range selection uses drag interaction (mousedown → mousemove), not click events.\n → The "triggerOn" option only affects "cell" and "row" selection modes.',check:e=>"range"===A(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"!==A(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 y;#b=new S;#f=null;#p=null;#C=null;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";#y={primary:"cell",columnEnabled:!1,bothAxes:!1};lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;#v=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.#y=d(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.#y.primary&&this.isRowSelectable(e)&&(this.selected.has(e)||(!1===this.config.multiSelect&&this.selected.clear(),this.selected.add(e),this.lastSelected=e,this.anchor=e,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender())))});let t=-1;e.addEventListener("data-change",e=>{const{sourceRowCount:n}=e.detail,i=this.selected.size>0||this.ranges.length>0||null!==this.selectedCell;-1!==t&&n!==t&&i&&this.clearSelectionSilent(),t=n},{signal:this.disconnectSignal}),e.addEventListener("contextmenu",e=>{if(this.#x())return;const t=e.target?.closest?.(".cell[data-row][data-col]");if(!t)return;const n=parseInt(t.getAttribute("data-row")??"-1",10),i=parseInt(t.getAttribute("data-col")??"-1",10),s=this.#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("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.#b.destroy(),this.#C?.dispose(),this.#C=null,this.#f=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()}#M(e){const t=e.pointerType;return"touch"===t||"pen"===t||"mouse"!==t&&"coarse"===(0,i.getPrimaryPointer)()}#I(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.#A()),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.#A())),this.requestAfterRender())}#q(e){const t=this.anchor??e,n=Math.min(t,e),i=Math.max(t,e);for(let s=n;s<=i;s++)this.isRowSelectable(s)&&this.selected.add(s);this.lastSelected=e,this.emit("selection-change",this.#A()),this.requestAfterRender()}#x(){const e=this.grid?.getPluginByName?.("contextMenu")??this.grid?.getPluginByName?.("context-menu");return"function"==typeof e?.showMenu?e:void 0}#T(e,t){return this.gridElement?.querySelector(`.cell[data-row="${e}"][data-col="${t}"]`)??null}#P(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),l=parseInt(i.getAttribute("data-col")??"-1",10);return s>=0&&l>=0?{row:s,col:l}:null}#K(e,t,n){const i=this.ranges[this.ranges.length-1];if(!i)return;const s=g(i),l="start"===e?{row:s.endRow,col:s.endCol}:{row:s.startRow,col:s.startCol},o=f(l,{row:t,col:n});p(i,o)||(this.ranges[this.ranges.length-1]=o,this.activeRange=o,this.cellAnchor=l,this.emit("selection-change",this.#A()),this.requestAfterRender())}#R(e,t){if("range"!==this.#y.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.#L(e,t)}]:null}#L(e,t){const n=this.#p;if(!n)return;const i=f(n,{row:e,col:t});this.ranges=[i],this.activeRange=i,this.cellAnchor=n,this.emit("selection-change",this.#A()),this.requestAfterRender()}#E(e,t){this.#C??=a("tbw-range-extend-menu","tbw-range-extend-menu"),this.#C.open(e,"Selection",t)}#D(e){this.#f=this.#f===e?null:e,this.#b.setArmed(this.#f),this.gridElement&&(0,n.announce)(this.gridElement,this.#f?"Select a cell to place the selection corner":"Selection corner placement cancelled")}#z(){return!!this.#f&&(this.#f=null,this.#b.setArmed(null),!0)}#F(e){if(!e)return;this.#g?this.#w.show(e,this.selected.size,void 0!==this.#x(),{selectAll:()=>this.selectAll(),clear:()=>this.clearSelection(),done:()=>this.exitTouchSelection(),more:e=>this.#H(e)}):this.#w.destroy();const t=this.#m&&"range"===this.#y.primary&&this.ranges.length>0?this.ranges[this.ranges.length-1]:null,n=t?g(t):null;n||this.#z(),this.#b.render(e,n,(e,t)=>this.#T(e,t),{cellAt:(e,t)=>this.#P(e,t),resize:(e,t,n)=>this.#K(e,t,n),commit:()=>this.requestAfterRender(),arm:e=>this.#D(e)})}#H(e){const t=this.#x();if(!t)return;const n=e.getBoundingClientRect?.(),i=this.lastSelected??-1;t.showMenu(n?.left??0,n?.bottom??0,{row:i>=0?this.rows[i]:null,rowIndex:i,selectedRows:this.getSelectedRowIndices()})}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{triggerOn:t="click"}=this.config;if(e.originalEvent.type!==t)return!1;switch(this.#y.primary){case"cell":return this.#U(e);case"row":return this.#$(e);case"range":return this.#_(e);default:return!1}}#U(e){const{rowIndex:t,colIndex:n}=e;if(e.column&&(0,o.isUtilityColumn)(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;const i=this.selectedCell;return i&&i.row===t&&i.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()),this.requestAfterRender()),!1}#$(e){const{rowIndex:t,originalEvent:n,column:i}=e;if(!this.isRowSelectable(t))return!1;const s=!1!==this.config.multiSelect,l=n.shiftKey&&s,o=(n.ctrlKey||n.metaKey||this.#g)&&s,r=!0===i?.checkboxColumn;if(l&&null!==this.anchor){const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);o||this.selected.clear();for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(o||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.#A()),this.requestAfterRender(),!1}#_(e){const{rowIndex:t,colIndex:n,originalEvent:i}=e;if(e.column&&(0,o.isUtilityColumn)(e.column))return!1;if(!this.isCellSelectable(t,n))return!1;if(this.#f){const e=this.#f;return this.#z(),this.#K(e,t,n),!0}this.#m=this.#M(i);const s=i.shiftKey,l=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(s&&this.cellAnchor){const e=f(this.cellAnchor,{row:t,col:n}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&p(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{const e={startRow:t,startCol:n,endRow:t,endCol:n};if(l)this.ranges.push(e);else{if(1===this.ranges.length&&p(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.#A()),this.requestAfterRender(),!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;if(this.#y.columnEnabled&&this.#G(e))return!0;const t=this.#y.primary;if("Escape"===e.key&&this.#z())return!0;if("Escape"===e.key&&this.#g)return this.exitTouchSelection(),!0;if("Escape"===e.key)return this.#N(t);const n=E.includes(e.key);switch(t){case"cell":return!!n&&this.#B();case"row":return this.#j(e);case"range":return this.#O(e,n);default:return!1}}#G(e){if(!e.ctrlKey&&!e.metaKey)return!1;if(R(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||(0,o.isUtilityColumn)(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=h(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=u(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}#N(e){return!this.grid.query("isEditing").some(Boolean)&&("column"===this.activeAxis?(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none"):"cell"===e?this.selectedCell=null:"row"===e?(this.selected.clear(),this.anchor=null):"range"===e&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#B(){return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.selectedCell=this.isCellSelectable(e,t)?{row:e,col:t}:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}),!1}#j(e){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const n=e.shiftKey&&t;return n&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}return this.#W(e,t)}#O(e,t){if(!t)return this.#X(e)||this.#W(e,!1!==this.config.multiSelect);const n=e.shiftKey&&"Tab"!==e.key;return n&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:n},queueMicrotask(()=>this.requestAfterRender()),!1}#X(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.#y.columnEnabled)return!1;n="column"}if(e.altKey)return!1;if(R(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 l={row:this.grid._focusRow,col:this.grid._focusCol},o=this.activeRange?g(this.activeRange):{startRow:l.row,startCol:l.col,endRow:l.row,endCol:l.col},r="row"===n?{startRow:o.startRow,startCol:0,endRow:o.endRow,endCol:s-1}:{startRow:0,startCol:o.startCol,endRow:i-1,endCol:o.endCol};e.preventDefault(),e.stopPropagation();const c={row:Math.abs(l.row-r.startRow)>=Math.abs(l.row-r.endRow)?r.startRow:r.endRow,col:Math.abs(l.col-r.startCol)>=Math.abs(l.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.#v={axis:n,count:"row"===n?r.endRow-r.startRow+1:r.endCol-r.startCol+1},this.emit("selection-change",this.#A()),this.requestAfterRender(),!0}#W(e,t){return!(!t||"a"!==e.key||!e.ctrlKey&&!e.metaKey)&&(!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0))}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("row"===this.#y.primary){if(void 0===e.rowIndex||e.rowIndex<0)return;if(!1===this.config.multiSelect)return;if(!this.#M(e.originalEvent))return;if(e.column&&(0,o.isUtilityColumn)(e.column))return;return this.#g?(this.#q(e.rowIndex),!0):this.#I(e.rowIndex)||void 0}if("range"!==this.#y.primary)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(this.#f)return!0;if(this.#m=this.#M(e.originalEvent),2===e.originalEvent.button&&w(e.rowIndex,e.colIndex,this.ranges))return;if(e.column&&(0,o.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,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&&p(this.ranges[0],s)?(this.cellAnchor={row:t,col:n},this.#Q(e,t,n),!0):(this.cellAnchor={row:t,col:n},this.#Q(e,t,n),i||(this.ranges=[]),this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#A()),this.requestAfterRender(),!0)}#Q(e,t,n){2!==e.originalEvent.button&&(this.#p={row:t,col:n})}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.#y.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&&(0,o.isUtilityColumn)(n)){const e=this.visibleColumns.findIndex(e=>!(0,o.isUtilityColumn)(e));e>=0&&(t=e)}const i=f(this.cellAnchor,{row:e.rowIndex,col:t}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return s&&p(s,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#A()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.#y.primary)return this.isDragging?(this.isDragging=!1,!0):void 0}onHeaderClick(e){if(!this.isSelectionEnabled())return!1;if(!this.#y.columnEnabled)return!1;if(e.column&&(0,o.isUtilityColumn)(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.#y.primary){if(e.some(e=>e.field===x))return e;const t=this.#Y(),n=e.findIndex(o.isExpanderColumn),i=e.findIndex(e=>"left"!==e.pinned),s=i<0?e.length:i,l=n>=0?Math.max(n+1,s):s;return[...e.slice(0,l),t,...e.slice(l)]}return e}#Y(){return{field:x,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 i=document.createElement("span");return i.className="tbw-sr-only",i.textContent=(0,n.getA11yMessage)(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,i),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const i=e.cellEl,s=i?parseInt(i.getAttribute("data-row")??"-1",10):-1;return s>=0&&(t.checked=this.selected.has(s)),t.setAttribute("aria-label",(0,n.getA11yMessage)(this.gridElement,"selectRow",Math.max(s,0))),t}}}#J(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),n=t?(0,s.getRowIndexFromCell)(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.#A()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=n);if((t!==this.lastSyncedFocusRow||n!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=n,this.isCellSelectable(t,n))){const e=this.selectedCell;e&&e.row===t&&e.col===n||(this.selectedCell={row:t,col:n},this.emit("selection-change",this.#A()))}}}#ee(){const e=this.gridElement;if(!e)return;const n=this.#y.primary,i=this.#y.columnEnabled,l=!!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 n=e.classList.contains(t.GridClasses.SELECTED)||e.classList.contains("column-selected");e.classList.remove(t.GridClasses.SELECTED,"top","bottom","first","last","column-selected"),n&&e.removeAttribute("aria-selected"),l&&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"),l&&e.removeAttribute("data-selectable")}),i&&e.querySelectorAll(".header-row > .cell").forEach(e=>{e.classList.remove("column-selected"),e.removeAttribute("aria-selected")}),"row"===n&&((0,s.clearCellFocus)(e),c.forEach(e=>{const n=e.querySelector(".cell[data-row]"),i=(0,s.getRowIndexFromCell)(n);i>=0&&(l&&!this.isRowSelectable(i)&&e.setAttribute("data-selectable","false"),this.selected.has(i)&&(e.classList.add(t.GridClasses.SELECTED,"row-focus"),e.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#J(e)),"cell"!==n&&"range"!==n||!l||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"===n&&this.ranges.length>0){(0,s.clearCellFocus)(e);const n=this.ranges.map(g),i=(e,t)=>{for(const i of n)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};e.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const n=parseInt(e.getAttribute("data-row")??"-1",10),s=parseInt(e.getAttribute("data-col")??"-1",10);if(n>=0&&s>=0){const l=this.visibleColumns[s];if(l&&(0,o.isUtilityColumn)(l))return;i(n,s)&&(e.classList.add(t.GridClasses.SELECTED),e.setAttribute("aria-selected","true"),i(n-1,s)||e.classList.add("top"),i(n+1,s)||e.classList.add("bottom"),i(n,s-1)||e.classList.add("first"),i(n,s+1)||e.classList.add("last"))}})}if(i&&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||(0,o.isUtilityColumn)(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.#y.primary;if(this.pendingRowKeyUpdate&&"row"===n){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),n=Math.max(this.anchor,t);for(let t=e;t<=n;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#A())}if(this.pendingKeyboardUpdate&&"range"===n){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,n=this.grid._focusCol;if(e&&this.cellAnchor){let e=f(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.#A())}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.#A();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 n of e)for(const e of b(n))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return w(e,t,this.ranges)}selectAll(){const e=this.#y.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.#A()),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.#A()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.#y.primary)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const n of t)n>=0&&n<this.rows.length&&this.isRowSelectable(n)&&this.selected.add(n);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#A()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const e=this.#y.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 n of this.ranges){const i=Math.max(0,Math.min(n.startRow,n.endRow)),s=Math.min(t.length-1,Math.max(n.startRow,n.endRow));for(let t=i;t<=s;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}#k(e){if(!this.#y.columnEnabled)return;const t=h(this.visibleColumns),n=new Set(t),i=[],s=new Set;for(const o of e)n.has(o)&&!s.has(o)&&(s.add(o),i.push(o));this.#te("column"),this.selectedColumns.clear();for(const o of i)this.selectedColumns.add(o);const l=i.length>0?i[i.length-1]:null;this.columnAnchor=l,this.columnHead=l,this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}selectColumn(e,t={}){if(!this.#y.columnEnabled)return;const n=h(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=u(e,n),s=u(t,n);if(-1===i||-1===s)return[];const l=Math.min(i,s),o=Math.max(i,s);return n.slice(l,o+1)}(this.columnAnchor,e,n);this.selectedColumns.clear();for(const e of t)this.selectedColumns.add(e);this.columnHead=e}else t.toggle?(this.selectedColumns.has(e)?this.selectedColumns.delete(e):this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e):(this.selectedColumns.clear(),this.selectedColumns.add(e),this.columnAnchor=e,this.columnHead=e);this.activeAxis=this.selectedColumns.size>0?"column":"none",this.emit("selection-change",this.#A()),this.requestAfterRender()}}deselectColumn(e){this.#y.columnEnabled&&this.selectedColumns.delete(e)&&(0===this.selectedColumns.size&&(this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none")),this.emit("selection-change",this.#A()),this.requestAfterRender())}selectAllColumns(){if(!this.#y.columnEnabled)return;if(!1===this.config.multiSelect)return;const e=h(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.#A()),this.requestAfterRender()}}clearColumnSelection(){0!==this.selectedColumns.size&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,"column"===this.activeAxis&&(this.activeAxis="none"),this.emit("selection-change",this.#A()),this.requestAfterRender())}getSelectedColumns(){return 0===this.selectedColumns.size?[]:h(this.visibleColumns).filter(e=>this.selectedColumns.has(e))}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.activeAxis="none",this.emit("selection-change",this.#A()),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",this.#A()),this.requestAfterRender()}#A(){const e=this.#y.primary,t="row"===e&&this.selected.size>0||"cell"===e&&null!==this.selectedCell||"range"===e&&this.ranges.length>0;let i;this.#y.bothAxes&&t&&this.selectedColumns.size>0&&(this.selectedColumns.clear(),this.columnAnchor=null,this.columnHead=null,this.gridElement&&(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"selectionAxisChanged","row"))),i=t?"row"===e?"row":"cell"===e?"cell":"range":this.selectedColumns.size>0?"column":"none",this.activeAxis=i;const s=function(e,t,n,i,s,l){if("column"===t&&i.selectedColumns.size>0)return{mode:e,activeAxis:"column",ranges:[],selectedColumns:l.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 l=t[0],o=l;for(let e=1;e<t.length;e++)t[e]===o+1?o=t[e]:(n.push({from:{row:l,col:0},to:{row:o,col:s-1}}),l=t[e],o=l);return n.push({from:{row:l,col:0},to:{row:o,col:s-1}}),{mode:e,activeAxis:"row",ranges:n,selectedColumns:[]}}return"range"===n&&i.ranges.length>0?{mode:e,activeAxis:"range",ranges:(o=i.ranges,o.map(m)),selectedColumns:[]}:{mode:e,activeAxis:"none",ranges:[],selectedColumns:[]};var o}(this.config.mode,i,e,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges,selectedColumns:this.selectedColumns},this.columns.length,h(this.visibleColumns)),l=this.#v;return this.#v=null,this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{if(l)(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"rangeSpanSelected",l.axis,l.count));else if("column"===s.activeAxis){const e=s.selectedColumns;if(1===e.length){const t=e[0],i=this.columns.find(e=>e.field===t),s="string"==typeof i?.header&&i.header||t;(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"columnSelected",s))}else e.length>1?(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"columnSelectionChanged",e.length)):(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"columnSelectionCleared"))}else{const e="row"===s.activeAxis?this.selected.size:s.ranges.length;e>0&&(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"selectionChanged",e))}},150),s}#te(e){if(this.#y.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&&(0,n.announce)(this.gridElement,(0,n.getA11yMessage)(this.gridElement,"selectionAxisChanged","column"))}}};e.SelectionPlugin=k});
2
2
  //# sourceMappingURL=selection.umd.js.map