@omnigrid/selection-plugin 0.1.3 → 0.1.4

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CheckboxRenderParams, GridApi, GridPlugin, RowId, RowRenderParams } from "@omnigrid/core";
2
+ /** Selection behavior supported by the plugin. */
2
3
  export type SelectionMode = "single" | "multiple";
3
4
  /**
4
5
  * CSS class applied to selected rows. The concrete selected-row color is
@@ -8,29 +9,50 @@ export type SelectionMode = "single" | "multiple";
8
9
  export declare const SELECTED_ROW_CLASS = "omnigrid-row-selected";
9
10
  /** Applied to rows rejected by `isRowSelectable`; themes supply muted colors. */
10
11
  export declare const UNSELECTABLE_ROW_CLASS = "omnigrid-row-unselectable";
12
+ /** Values provided to a custom checkbox renderer. */
11
13
  export interface SelectionRendererParams<T> extends CheckboxRenderParams {
14
+ /** Row data for a row checkbox; absent for the header checkbox. */
12
15
  data?: T;
16
+ /** Row identifier for a row checkbox. */
13
17
  rowId?: RowId;
18
+ /** Row index for a row checkbox. */
14
19
  index?: number;
20
+ /** Whether the renderer is being called for the header checkbox. */
15
21
  header: boolean;
16
22
  }
23
+ /** Renderer used to customize selection checkboxes. */
17
24
  export type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;
25
+ /** Configuration for the selection plugin. */
18
26
  export interface SelectionPluginOptions<T> {
27
+ /** Supports selecting one row or multiple rows. @default "single" */
19
28
  mode?: SelectionMode;
29
+ /** Restricts selection changes to checkbox interaction. @default false */
20
30
  checkboxOnly?: boolean;
31
+ /** In multiple mode, clicking a row replaces the current selection. @default false */
21
32
  replaceSelectionOnClick?: boolean;
33
+ /** Adds a checkbox to each row. @default false */
22
34
  showRowCheckboxes?: boolean;
35
+ /** Adds a select-all checkbox to the selection column header. @default false */
23
36
  showHeaderCheckbox?: boolean;
37
+ /** Determines whether a row can be selected. */
24
38
  isRowSelectable?: (row: T, index: number) => boolean;
39
+ /** Renders checkbox UI; defaults to the OmniGrid checkbox renderer. */
25
40
  checkboxRenderer?: SelectionRenderer<T>;
41
+ /** Called when the selected rows change. */
26
42
  onSelectionChange?: (state: SelectionState<T>) => void;
43
+ /** ID for the automatically inserted checkbox column. @default "__omnigrid_selection__" */
27
44
  selectionColumnId?: string;
45
+ /** Width in pixels of the automatically inserted checkbox column. @default 44 */
28
46
  selectionColumnWidth?: number;
29
47
  }
48
+ /** Selected row identifiers and their corresponding row data. */
30
49
  export interface SelectionState<T> {
50
+ /** IDs of selected rows. */
31
51
  selectedRowIds: RowId[];
52
+ /** Data objects for selected rows. */
32
53
  selectedRows: T[];
33
54
  }
55
+ /** Adds row selection and optional checkbox controls to a grid. */
34
56
  export declare class SelectionPlugin<T> implements GridPlugin<T> {
35
57
  readonly name = "@omnigrid/selection-plugin";
36
58
  private api?;
@@ -49,16 +71,45 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
49
71
  private unregisterRowClick?;
50
72
  constructor(options?: SelectionPluginOptions<T>);
51
73
  register(api: GridApi<T>): () => void;
74
+ /**
75
+ * Returns the IDs of all currently selected rows.
76
+ * @api
77
+ */
52
78
  getSelectedRowIds(): RowId[];
79
+ /**
80
+ * Returns the data objects of all currently selected rows.
81
+ * @api
82
+ */
53
83
  getSelectedRows(): T[];
84
+ /**
85
+ * Returns selected row IDs and row data together.
86
+ * @api
87
+ */
54
88
  getSelectionState(): SelectionState<T>;
89
+ /**
90
+ * Checks whether a row ID is currently selected.
91
+ * @api
92
+ */
55
93
  isSelected(rowId: RowId): boolean;
94
+ /**
95
+ * Replaces the current selection with the supplied row IDs.
96
+ * @api
97
+ */
56
98
  setSelectedRowIds(rowIds: RowId[]): void;
99
+ /**
100
+ * Clears all selected rows.
101
+ * @api
102
+ */
57
103
  clearSelection(): void;
104
+ /**
105
+ * Toggles a row's selection. Shift and Ctrl modifiers control range and additive selection.
106
+ * @api
107
+ */
58
108
  toggleRow(rowId: RowId, index: number, modifiers?: {
59
109
  shiftKey?: boolean;
60
110
  ctrlKey?: boolean;
61
111
  }): void;
112
+ /** Returns selection-related CSS classes for a row. */
62
113
  getRowClass({ id, index, data }: RowRenderParams<T>): string | undefined;
63
114
  private handleRowClick;
64
115
  private applySelection;
@@ -70,5 +121,9 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
70
121
  private toggleAll;
71
122
  private refresh;
72
123
  private validateSelection;
124
+ /**
125
+ * Updates plugin options at runtime.
126
+ * @api
127
+ */
73
128
  updateOptions(newOptions: Partial<SelectionPluginOptions<T>>): void;
74
129
  }
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ const CHECKBOX_COLUMN_DEFAULT_ID = "__omnigrid_selection__";
10
10
  function defaultCheckboxRenderer(params) {
11
11
  return { type: "@omnigrid/checkbox", ...params };
12
12
  }
13
+ /** Adds row selection and optional checkbox controls to a grid. */
13
14
  export class SelectionPlugin {
14
15
  constructor(options = {}) {
15
16
  this.name = "@omnigrid/selection-plugin";
@@ -35,28 +36,56 @@ export class SelectionPlugin {
35
36
  this.api = undefined;
36
37
  };
37
38
  }
39
+ /**
40
+ * Returns the IDs of all currently selected rows.
41
+ * @api
42
+ */
38
43
  getSelectedRowIds() {
39
44
  return [...this.selectedRowIds];
40
45
  }
46
+ /**
47
+ * Returns the data objects of all currently selected rows.
48
+ * @api
49
+ */
41
50
  getSelectedRows() {
42
51
  if (!this.api)
43
52
  return [];
44
53
  return this.api.getProcessedData().filter((row, index) => this.selectedRowIds.has(this.api.getRowId(row, index)));
45
54
  }
55
+ /**
56
+ * Returns selected row IDs and row data together.
57
+ * @api
58
+ */
46
59
  getSelectionState() {
47
60
  return { selectedRowIds: this.getSelectedRowIds(), selectedRows: this.getSelectedRows() };
48
61
  }
62
+ /**
63
+ * Checks whether a row ID is currently selected.
64
+ * @api
65
+ */
49
66
  isSelected(rowId) {
50
67
  return this.selectedRowIds.has(rowId);
51
68
  }
69
+ /**
70
+ * Replaces the current selection with the supplied row IDs.
71
+ * @api
72
+ */
52
73
  setSelectedRowIds(rowIds) {
53
74
  this.selectedRowIds.clear();
54
75
  rowIds.forEach((rowId) => this.selectedRowIds.add(rowId));
55
76
  this.refresh();
56
77
  }
78
+ /**
79
+ * Clears all selected rows.
80
+ * @api
81
+ */
57
82
  clearSelection() {
58
83
  this.setSelectedRowIds([]);
59
84
  }
85
+ /**
86
+ * Toggles a row's selection. Shift and Ctrl modifiers control range and additive selection.
87
+ * @api
88
+ */
60
89
  toggleRow(rowId, index, modifiers = {}) {
61
90
  if (!this.api)
62
91
  return;
@@ -71,6 +100,7 @@ export class SelectionPlugin {
71
100
  }
72
101
  this.applySelection(rowId, index, modifiers);
73
102
  }
103
+ /** Returns selection-related CSS classes for a row. */
74
104
  getRowClass({ id, index, data }) {
75
105
  const classes = [];
76
106
  if (this.selectedRowIds.has(id))
@@ -237,6 +267,10 @@ export class SelectionPlugin {
237
267
  this.refresh();
238
268
  }
239
269
  }
270
+ /**
271
+ * Updates plugin options at runtime.
272
+ * @api
273
+ */
240
274
  updateOptions(newOptions) {
241
275
  if (newOptions.mode !== undefined)
242
276
  this.mode = newOptions.mode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/selection-plugin",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Headless row selection plugin for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",