@omnigrid/selection-plugin 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,6 +28,7 @@ import { SelectionPlugin } from "@omnigrid/selection-plugin";
28
28
 
29
29
  const plugin = new SelectionPlugin({
30
30
  mode: "multiple",
31
+ groupSelection: "filteredDescendants",
31
32
  onSelectionChange: ({ selectedRowIds, selectedRows }) => {
32
33
  console.log("Selected count:", selectedRows.length);
33
34
  console.log("Selected IDs:", selectedRowIds);
@@ -43,6 +44,14 @@ const selection = plugin.getSelectionState();
43
44
  IDs and row records. `getSelectedRowIds()`, `getSelectedRows()`, and
44
45
  `getSelectionState()` provide synchronous access to the current selection.
45
46
 
47
+ When used with a row-grouping plugin, `groupSelection` controls the group
48
+ checkbox behavior. `"descendants"` selects every selectable leaf row in the
49
+ group, including filtered-out rows; `"filteredDescendants"` limits selection
50
+ to leaves that remain after filtering. Group checkboxes show an indeterminate
51
+ state when only some selectable descendants are selected. The default,
52
+ `"none"`, preserves the regular row-only selection behavior, and group
53
+ selection is available only in `"multiple"` mode.
54
+
46
55
  ## Links
47
56
 
48
57
  - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/selection
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { CheckboxRenderParams, GridApi, GridPlugin, RowId, RowRenderParams } from "@omnigrid/core";
2
- /** Selection behavior supported by the plugin. */
3
- export type SelectionMode = "single" | "multiple";
1
+ import type { GridApi, GridPlugin, RowId, RowRenderParams } from "@omnigrid/core";
2
+ import type { GroupSelectionMode, SelectionMode, SelectionPluginOptions, SelectionRenderer, SelectionRendererParams, SelectionState } from "./types";
3
+ export type { GroupSelectionMode, SelectionMode, SelectionPluginOptions, SelectionRenderer, SelectionRendererParams, SelectionState, };
4
4
  /**
5
5
  * CSS class applied to selected rows. The concrete selected-row color is
6
6
  * owned by the active theme (e.g. `@omnigrid/default-theme` defines
@@ -9,49 +9,6 @@ export type SelectionMode = "single" | "multiple";
9
9
  export declare const SELECTED_ROW_CLASS = "omnigrid-row-selected";
10
10
  /** Applied to rows rejected by `isRowSelectable`; themes supply muted colors. */
11
11
  export declare const UNSELECTABLE_ROW_CLASS = "omnigrid-row-unselectable";
12
- /** Values provided to a custom checkbox renderer. */
13
- export interface SelectionRendererParams<T> extends CheckboxRenderParams {
14
- /** Row data for a row checkbox; absent for the header checkbox. */
15
- data?: T;
16
- /** Row identifier for a row checkbox. */
17
- rowId?: RowId;
18
- /** Row index for a row checkbox. */
19
- index?: number;
20
- /** Whether the renderer is being called for the header checkbox. */
21
- header: boolean;
22
- }
23
- /** Renderer used to customize selection checkboxes. */
24
- export type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;
25
- /** Configuration for the selection plugin. */
26
- export interface SelectionPluginOptions<T> {
27
- /** Supports selecting one row or multiple rows. @default "single" */
28
- mode?: SelectionMode;
29
- /** Restricts selection changes to checkbox interaction. @default false */
30
- checkboxOnly?: boolean;
31
- /** In multiple mode, clicking a row replaces the current selection. @default false */
32
- replaceSelectionOnClick?: boolean;
33
- /** Adds a checkbox to each row. @default false */
34
- showRowCheckboxes?: boolean;
35
- /** Adds a select-all checkbox to the selection column header. @default false */
36
- showHeaderCheckbox?: boolean;
37
- /** Determines whether a row can be selected. */
38
- isRowSelectable?: (row: T, index: number) => boolean;
39
- /** Renders checkbox UI; defaults to the OmniGrid checkbox renderer. */
40
- checkboxRenderer?: SelectionRenderer<T>;
41
- /** Called when the selected rows change. */
42
- onSelectionChange?: (state: SelectionState<T>) => void;
43
- /** ID for the automatically inserted checkbox column. @default "__omnigrid_selection__" */
44
- selectionColumnId?: string;
45
- /** Width in pixels of the automatically inserted checkbox column. @default 44 */
46
- selectionColumnWidth?: number;
47
- }
48
- /** Selected row identifiers and their corresponding row data. */
49
- export interface SelectionState<T> {
50
- /** IDs of selected rows. */
51
- selectedRowIds: RowId[];
52
- /** Data objects for selected rows. */
53
- selectedRows: T[];
54
- }
55
12
  /** Adds row selection and optional checkbox controls to a grid. */
56
13
  export declare class SelectionPlugin<T> implements GridPlugin<T> {
57
14
  readonly name = "@omnigrid/selection-plugin";
@@ -59,6 +16,7 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
59
16
  private mode;
60
17
  private checkboxOnly;
61
18
  private replaceSelectionOnClick;
19
+ private groupSelection;
62
20
  private showRowCheckboxes;
63
21
  private showHeaderCheckbox;
64
22
  private isRowSelectable;
@@ -69,6 +27,7 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
69
27
  private readonly selectedRowIds;
70
28
  private anchorIndex?;
71
29
  private unregisterRowClick?;
30
+ private unregisterMethods?;
72
31
  constructor(options?: SelectionPluginOptions<T>);
73
32
  register(api: GridApi<T>): () => void;
74
33
  /**
@@ -112,6 +71,11 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
112
71
  /** Returns selection-related CSS classes for a row. */
113
72
  getRowClass({ id, index, data }: RowRenderParams<T>): string | undefined;
114
73
  private handleRowClick;
74
+ private toggleStableRow;
75
+ private getRowByStableId;
76
+ private getSelectionRowId;
77
+ private getCheckboxState;
78
+ private toggleGroupSelection;
115
79
  private applySelection;
116
80
  private updateColumns;
117
81
  private renderCheckbox;
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ export class SelectionPlugin {
18
18
  this.mode = options.mode ?? "single";
19
19
  this.checkboxOnly = options.checkboxOnly ?? false;
20
20
  this.replaceSelectionOnClick = options.replaceSelectionOnClick ?? false;
21
+ this.groupSelection = options.groupSelection ?? "none";
21
22
  this.showRowCheckboxes = options.showRowCheckboxes ?? false;
22
23
  this.showHeaderCheckbox = options.showHeaderCheckbox ?? false;
23
24
  this.isRowSelectable = options.isRowSelectable ?? (() => true);
@@ -29,13 +30,33 @@ export class SelectionPlugin {
29
30
  register(api) {
30
31
  this.api = api;
31
32
  this.unregisterRowClick = api.on("rowClick", (event) => this.handleRowClick(event));
33
+ this.unregisterMethods = api.registerMethods({
34
+ selectRow: (rowId) => {
35
+ this.selectedRowIds.add(rowId);
36
+ this.refresh();
37
+ },
38
+ deselectRow: (rowId) => {
39
+ this.selectedRowIds.delete(rowId);
40
+ this.refresh();
41
+ },
42
+ getSelection: () => this.getSelectionState(),
43
+ clearSelection: () => this.clearSelection(),
44
+ });
45
+ api.setState((prev) => ({ ...prev, selection: this.getSelectionState() }));
32
46
  this.updateColumns();
33
47
  return () => {
34
48
  this.unregisterRowClick?.();
35
49
  this.unregisterRowClick = undefined;
36
- const api = this.api;
37
- if (api && !api.isDestroyed()) {
38
- api.setColumns(api.getState().columns.filter((column) => column.id !== this.selectionColumnId));
50
+ this.unregisterMethods?.();
51
+ this.unregisterMethods = undefined;
52
+ const targetApi = this.api;
53
+ if (targetApi && !targetApi.isDestroyed()) {
54
+ targetApi.setColumns(targetApi.getState().columns.filter((column) => column.id !== this.selectionColumnId));
55
+ targetApi.setState((prev) => {
56
+ const next = { ...prev };
57
+ delete next.selection;
58
+ return next;
59
+ });
39
60
  }
40
61
  this.selectedRowIds.clear();
41
62
  this.anchorIndex = undefined;
@@ -56,6 +77,9 @@ export class SelectionPlugin {
56
77
  getSelectedRows() {
57
78
  if (!this.api)
58
79
  return [];
80
+ if (this.groupSelection !== "none" && this.api.getRowHierarchy()) {
81
+ return this.api.getState().data.filter((row, index) => this.selectedRowIds.has(this.api.getRowId(row, index)));
82
+ }
59
83
  return this.api.getProcessedData().filter((row, index) => this.selectedRowIds.has(this.api.getRowId(row, index)));
60
84
  }
61
85
  /**
@@ -108,18 +132,127 @@ export class SelectionPlugin {
108
132
  }
109
133
  /** Returns selection-related CSS classes for a row. */
110
134
  getRowClass({ id, index, data }) {
135
+ const checkboxState = this.getCheckboxState(id, index, data);
111
136
  const classes = [];
112
- if (this.selectedRowIds.has(id))
113
- classes.push(SELECTED_ROW_CLASS);
114
- if (!this.isRowSelectable(data, index))
115
- classes.push(UNSELECTABLE_ROW_CLASS);
137
+ if (checkboxState.group) {
138
+ if (this.mode !== "multiple" || this.groupSelection === "none")
139
+ return undefined;
140
+ if (checkboxState.checked)
141
+ classes.push(SELECTED_ROW_CLASS);
142
+ if (checkboxState.disabled)
143
+ classes.push(UNSELECTABLE_ROW_CLASS);
144
+ }
145
+ else {
146
+ if (this.selectedRowIds.has(id))
147
+ classes.push(SELECTED_ROW_CLASS);
148
+ if (!this.isRowSelectable(data, index))
149
+ classes.push(UNSELECTABLE_ROW_CLASS);
150
+ }
116
151
  return classes.length > 0 ? classes.join(" ") : undefined;
117
152
  }
118
153
  handleRowClick(event) {
119
154
  if (this.checkboxOnly)
120
155
  return;
156
+ const hierarchy = this.api?.getRowHierarchy();
157
+ if (hierarchy) {
158
+ if (hierarchy.getLeafRowIds(event.id, "all") !== undefined)
159
+ return;
160
+ const row = this.getRowByStableId(event.id);
161
+ if (!row || !this.isRowSelectable(row.data, row.index))
162
+ return;
163
+ this.toggleStableRow(event.id, event, row.index);
164
+ return;
165
+ }
121
166
  this.applySelection(event.id, event.index, event);
122
167
  }
168
+ toggleStableRow(rowId, modifiers, index) {
169
+ if (this.mode === "single") {
170
+ if (!this.replaceSelectionOnClick && this.selectedRowIds.has(rowId) && !modifiers.shiftKey) {
171
+ this.selectedRowIds.delete(rowId);
172
+ }
173
+ else {
174
+ this.selectedRowIds.clear();
175
+ this.selectedRowIds.add(rowId);
176
+ }
177
+ }
178
+ else if (this.selectedRowIds.has(rowId)) {
179
+ this.selectedRowIds.delete(rowId);
180
+ }
181
+ else {
182
+ this.selectedRowIds.add(rowId);
183
+ }
184
+ this.anchorIndex = index;
185
+ this.refresh();
186
+ }
187
+ getRowByStableId(rowId) {
188
+ if (!this.api)
189
+ return undefined;
190
+ const rows = this.api.getState().data;
191
+ for (let index = 0; index < rows.length; index += 1) {
192
+ if (this.api.getRowId(rows[index], index) === rowId)
193
+ return { data: rows[index], index };
194
+ }
195
+ return undefined;
196
+ }
197
+ getSelectionRowId(row, index) {
198
+ if (!this.api)
199
+ return index;
200
+ const sourceIndex = this.api.getRowHierarchy() ? this.api.getState().data.indexOf(row) : -1;
201
+ return this.api.getRowId(row, sourceIndex >= 0 ? sourceIndex : index);
202
+ }
203
+ getCheckboxState(rowId, index, data) {
204
+ const hierarchy = this.api?.getRowHierarchy();
205
+ const allDescendants = hierarchy?.getLeafRowIds(rowId, "all");
206
+ const isGroup = allDescendants !== undefined;
207
+ if (!isGroup) {
208
+ const row = hierarchy ? this.getRowByStableId(rowId) : { data, index };
209
+ const selectable = row !== undefined && this.isRowSelectable(row.data, row.index);
210
+ return {
211
+ checked: this.selectedRowIds.has(rowId),
212
+ indeterminate: false,
213
+ disabled: !selectable,
214
+ group: false,
215
+ rowIds: selectable ? [rowId] : [],
216
+ data: row?.data ?? data,
217
+ index: row?.index ?? index,
218
+ };
219
+ }
220
+ if (this.mode !== "multiple" || this.groupSelection === "none" || !hierarchy) {
221
+ return { checked: false, indeterminate: false, disabled: true, group: true, rowIds: [] };
222
+ }
223
+ const scope = this.groupSelection === "descendants" ? "all" : "filtered";
224
+ const descendants = scope === "all" ? (allDescendants ?? []) : (hierarchy.getLeafRowIds(rowId, "filtered") ?? []);
225
+ const sourceRows = scope === "all" ? (this.api?.getState().data ?? []) : (this.api?.getFilteredData() ?? []);
226
+ const selectableIds = [];
227
+ sourceRows.forEach((row, rowIndex) => {
228
+ const rawIndex = this.api?.getState().data.indexOf(row) ?? -1;
229
+ const sourceIndex = rawIndex >= 0 ? rawIndex : rowIndex;
230
+ const leafId = this.api?.getRowId(row, sourceIndex);
231
+ if (leafId !== undefined && descendants.includes(leafId) && this.isRowSelectable(row, rowIndex))
232
+ selectableIds.push(leafId);
233
+ });
234
+ const selectedCount = selectableIds.filter((leafId) => this.selectedRowIds.has(leafId)).length;
235
+ const checked = selectableIds.length > 0 && selectedCount === selectableIds.length;
236
+ return {
237
+ checked,
238
+ indeterminate: selectedCount > 0 && !checked,
239
+ disabled: selectableIds.length === 0,
240
+ group: true,
241
+ rowIds: selectableIds,
242
+ };
243
+ }
244
+ toggleGroupSelection(rowIds) {
245
+ if (rowIds.length === 0)
246
+ return;
247
+ const allSelected = rowIds.every((rowId) => this.selectedRowIds.has(rowId));
248
+ rowIds.forEach((rowId) => {
249
+ if (allSelected)
250
+ this.selectedRowIds.delete(rowId);
251
+ else
252
+ this.selectedRowIds.add(rowId);
253
+ });
254
+ this.refresh();
255
+ }
123
256
  applySelection(rowId, index, modifiers) {
124
257
  if (!this.api)
125
258
  return;
@@ -171,7 +304,6 @@ export class SelectionPlugin {
171
304
  this.api.setColumns(columns);
172
305
  return;
173
306
  }
174
- const hasPinnedLeft = columns.some((column) => column.pinned === "left");
175
307
  const selectionColumn = {
176
308
  id: this.selectionColumnId,
177
309
  header: "",
@@ -181,12 +313,8 @@ export class SelectionPlugin {
181
313
  sortable: false,
182
314
  stopHeaderClick: true,
183
315
  stopRowClick: true,
184
- // The checkbox column must stay in view while scrolling horizontally.
185
- // When the table already has left-pinned columns, pin the checkbox
186
- // column to the left (as the very first pinned column) so it never
187
- // scrolls away together with its pinned peers. With no left-pinned
188
- // columns the checkbox column stays as the first scrollable column.
189
- pinned: hasPinnedLeft ? "left" : undefined,
316
+ // The checkbox column must always stay pinned to the left.
317
+ pinned: "left",
190
318
  headerRenderer: () => this.renderCheckbox({
191
319
  checked: this.isAllSelectableRowsSelected(),
192
320
  indeterminate: this.hasSomeSelectableRowsSelected() && !this.isAllSelectableRowsSelected(),
@@ -195,17 +323,43 @@ export class SelectionPlugin {
195
323
  header: true,
196
324
  onChange: (event) => this.toggleAll(event),
197
325
  }),
198
- cellRenderer: ({ data, id, index }) => this.renderCheckbox({
199
- checked: id !== undefined && this.selectedRowIds.has(id),
200
- indeterminate: false,
201
- disabled: index === undefined || !this.isRowSelectable(data, index),
202
- ariaLabel: "Select row",
203
- data,
204
- rowId: id,
205
- index,
206
- header: false,
207
- onChange: (event) => id !== undefined && index !== undefined && this.toggleRow(id, index, event),
208
- }),
326
+ cellRenderer: ({ data, id, index }) => {
327
+ if (id === undefined || index === undefined) {
328
+ return this.renderCheckbox({
329
+ checked: false,
330
+ indeterminate: false,
331
+ disabled: true,
332
+ ariaLabel: "Select row",
333
+ header: false,
334
+ onChange: () => { },
335
+ });
336
+ }
337
+ const checkboxState = this.getCheckboxState(id, index, data);
338
+ if (checkboxState.group && (this.mode !== "multiple" || this.groupSelection === "none"))
339
+ return "";
340
+ return this.renderCheckbox({
341
+ checked: checkboxState.checked,
342
+ indeterminate: checkboxState.indeterminate,
343
+ disabled: checkboxState.disabled,
344
+ ariaLabel: checkboxState.group ? "Select group" : "Select row",
345
+ data: checkboxState.group ? undefined : checkboxState.data,
346
+ rowId: id,
347
+ index: checkboxState.index,
348
+ header: false,
349
+ group: checkboxState.group,
350
+ onChange: (event) => {
351
+ if (checkboxState.group) {
352
+ this.toggleGroupSelection(checkboxState.rowIds);
353
+ }
354
+ else if (this.api?.getRowHierarchy()) {
355
+ this.toggleStableRow(id, event, checkboxState.index ?? index);
356
+ }
357
+ else {
358
+ this.toggleRow(id, index, event);
359
+ }
360
+ },
361
+ });
362
+ },
209
363
  };
210
364
  this.api.setColumns([selectionColumn, ...columns]);
211
365
  }
@@ -225,12 +379,14 @@ export class SelectionPlugin {
225
379
  const processedData = this.api.getProcessedData();
226
380
  const selectableRows = processedData.filter((row, index) => this.isRowSelectable(row, index));
227
381
  return (selectableRows.length > 0 &&
228
- processedData.every((row, index) => !this.isRowSelectable(row, index) || this.selectedRowIds.has(this.api.getRowId(row, index))));
382
+ processedData.every((row, index) => !this.isRowSelectable(row, index) || this.selectedRowIds.has(this.getSelectionRowId(row, index))));
229
383
  }
230
384
  hasSomeSelectableRowsSelected() {
231
385
  if (!this.api)
232
386
  return false;
233
- return this.api.getProcessedData().some((row, index) => this.isRowSelectable(row, index) && this.selectedRowIds.has(this.api.getRowId(row, index)));
387
+ return this.api
388
+ .getProcessedData()
389
+ .some((row, index) => this.isRowSelectable(row, index) && this.selectedRowIds.has(this.getSelectionRowId(row, index)));
234
390
  }
235
391
  toggleAll(modifiers) {
236
392
  if (!this.api)
@@ -239,13 +395,13 @@ export class SelectionPlugin {
239
395
  if (this.isAllSelectableRowsSelected()) {
240
396
  processedData.forEach((row, index) => {
241
397
  if (this.isRowSelectable(row, index))
242
- this.selectedRowIds.delete(this.api.getRowId(row, index));
398
+ this.selectedRowIds.delete(this.getSelectionRowId(row, index));
243
399
  });
244
400
  }
245
401
  else {
246
402
  processedData.forEach((row, index) => {
247
403
  if (this.isRowSelectable(row, index))
248
- this.selectedRowIds.add(this.api.getRowId(row, index));
404
+ this.selectedRowIds.add(this.getSelectionRowId(row, index));
249
405
  });
250
406
  }
251
407
  this.refresh();
@@ -253,7 +409,8 @@ export class SelectionPlugin {
253
409
  refresh() {
254
410
  if (!this.api || this.api.isDestroyed())
255
411
  return;
256
- this.api.setData(this.api.getState().data);
412
+ this.api.setState((prev) => ({ ...prev, selection: this.getSelectionState() }));
413
+ this.api.refresh();
257
414
  this.onSelectionChange?.(this.getSelectionState());
258
415
  }
259
416
  validateSelection() {
@@ -262,7 +419,7 @@ export class SelectionPlugin {
262
419
  const processedData = this.api.getProcessedData();
263
420
  let hasChanges = false;
264
421
  for (const rowId of this.selectedRowIds) {
265
- const index = processedData.findIndex((row, idx) => this.api.getRowId(row, idx) === rowId);
422
+ const index = processedData.findIndex((row, idx) => this.getSelectionRowId(row, idx) === rowId);
266
423
  const row = index !== -1 ? processedData[index] : undefined;
267
424
  if (row && index !== -1 && !this.isRowSelectable(row, index)) {
268
425
  this.selectedRowIds.delete(rowId);
@@ -284,6 +441,8 @@ export class SelectionPlugin {
284
441
  this.checkboxOnly = newOptions.checkboxOnly;
285
442
  if (newOptions.replaceSelectionOnClick !== undefined)
286
443
  this.replaceSelectionOnClick = newOptions.replaceSelectionOnClick;
444
+ if (newOptions.groupSelection !== undefined)
445
+ this.groupSelection = newOptions.groupSelection;
287
446
  if (newOptions.showRowCheckboxes !== undefined)
288
447
  this.showRowCheckboxes = newOptions.showRowCheckboxes;
289
448
  if (newOptions.showHeaderCheckbox !== undefined)
@@ -0,0 +1,68 @@
1
+ import type { CheckboxRenderParams, RowId } from "@omnigrid/core";
2
+ /** Selection behavior supported by the plugin. */
3
+ export type SelectionMode = "single" | "multiple";
4
+ /** Controls whether group checkboxes select their descendants. @api */
5
+ export type GroupSelectionMode = "none" | "descendants" | "filteredDescendants";
6
+ /** Values provided to a custom checkbox renderer. */
7
+ export interface SelectionRendererParams<T> extends CheckboxRenderParams {
8
+ /** Row data for a row checkbox; absent for the header checkbox. */
9
+ data?: T;
10
+ /** Row identifier for a row checkbox. */
11
+ rowId?: RowId;
12
+ /** Row index for a row checkbox. */
13
+ index?: number;
14
+ /** Whether the renderer is being called for the header checkbox. */
15
+ header: boolean;
16
+ /** Whether the row checkbox represents a composite row. */
17
+ group?: boolean;
18
+ }
19
+ /** Renderer used to customize selection checkboxes. */
20
+ export type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;
21
+ /** Configuration for the selection plugin. */
22
+ export interface SelectionPluginOptions<T> {
23
+ /** Supports selecting one row or multiple rows. @default "single" */
24
+ mode?: SelectionMode;
25
+ /** Restricts selection changes to checkbox interaction. @default false */
26
+ checkboxOnly?: boolean;
27
+ /** In multiple mode, clicking a row replaces the current selection. @default false */
28
+ replaceSelectionOnClick?: boolean;
29
+ /** Enables group checkbox selection in multiple mode. @default "none" */
30
+ groupSelection?: GroupSelectionMode;
31
+ /** Adds a checkbox to each row. @default false */
32
+ showRowCheckboxes?: boolean;
33
+ /** Adds a select-all checkbox to the selection column header. @default false */
34
+ showHeaderCheckbox?: boolean;
35
+ /** Determines whether a row can be selected. */
36
+ isRowSelectable?: (row: T, index: number) => boolean;
37
+ /** Renders checkbox UI; defaults to the OmniGrid checkbox renderer. */
38
+ checkboxRenderer?: SelectionRenderer<T>;
39
+ /** Called when the selected rows change. */
40
+ onSelectionChange?: (state: SelectionState<T>) => void;
41
+ /** ID for the automatically inserted checkbox column. @default "__omnigrid_selection__" */
42
+ selectionColumnId?: string;
43
+ /** Width in pixels of the automatically inserted checkbox column. @default 44 */
44
+ selectionColumnWidth?: number;
45
+ }
46
+ /** Selected row identifiers and their corresponding row data. */
47
+ export interface SelectionState<T> {
48
+ /** IDs of selected rows. */
49
+ selectedRowIds: RowId[];
50
+ /** Data objects for selected rows. */
51
+ selectedRows: T[];
52
+ }
53
+ declare module "@omnigrid/core" {
54
+ interface PluginStateExtensions<T> {
55
+ /** Active selection state. */
56
+ selection?: SelectionState<T>;
57
+ }
58
+ interface PluginApiExtensions<T> {
59
+ /** Selects a row by id. */
60
+ selectRow?: (rowId: RowId) => void;
61
+ /** Deselects a row by id. */
62
+ deselectRow?: (rowId: RowId) => void;
63
+ /** Returns the current selection state. */
64
+ getSelection?: () => SelectionState<T>;
65
+ /** Clears the current selection. */
66
+ clearSelection?: () => void;
67
+ }
68
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/selection-plugin",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Headless row selection plugin for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",