@omnigrid/selection-plugin 0.1.2 → 0.1.3

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
@@ -5,21 +5,44 @@ Headless row/column selection plugin for OmniGrid.
5
5
  ## What it provides
6
6
 
7
7
  - Row selection (single, multi, range, checkbox toggle)
8
+ - Disabled rows marked by `isRowSelectable` with the `omnigrid-row-unselectable` class
8
9
  - Cell selection with range drag
9
10
  - Keyboard navigation support (Shift+Click, Ctrl+Click)
10
11
  - API to read/modify selection state programmatically
11
12
 
13
+ ## Styling
14
+
15
+ Selected rows receive the `omnigrid-row-selected` CSS class. The plugin does
16
+ **not** set inline colors — the concrete selected-row color is owned by the
17
+ active theme (for example, `@omnigrid/default-theme` and `@omnigrid/mint-theme`
18
+ define `--omnigrid-cell-selected-background` and `--omnigrid-checkbox-accent`
19
+ for light and dark modes). Rows rejected by `isRowSelectable` receive
20
+ `omnigrid-row-unselectable` and use theme-provided muted background and text
21
+ colors via `--omnigrid-cell-unselectable-background` and
22
+ `--omnigrid-cell-unselectable-color`.
23
+
12
24
  ## Usage
13
25
 
14
26
  ```ts
15
- import { selectionPlugin } from "@omnigrid/selection-plugin";
16
-
17
- const grid = new Grid({
18
- plugins: [selectionPlugin()],
19
- // ...
27
+ import { SelectionPlugin } from "@omnigrid/selection-plugin";
28
+
29
+ const plugin = new SelectionPlugin({
30
+ mode: "multiple",
31
+ onSelectionChange: ({ selectedRowIds, selectedRows }) => {
32
+ console.log("Selected count:", selectedRows.length);
33
+ console.log("Selected IDs:", selectedRowIds);
34
+ console.log("Selected records:", selectedRows);
35
+ },
20
36
  });
37
+
38
+ // Read the current selection at any time:
39
+ const selection = plugin.getSelectionState();
21
40
  ```
22
41
 
42
+ `onSelectionChange` runs when selection changes and receives the current row
43
+ IDs and row records. `getSelectedRowIds()`, `getSelectedRows()`, and
44
+ `getSelectionState()` provide synchronous access to the current selection.
45
+
23
46
  ## Links
24
47
 
25
48
  - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/plugins/base/selection
package/dist/index.d.ts CHANGED
@@ -1,5 +1,13 @@
1
- import type { CheckboxRenderParams, GridApi, GridPlugin, RowId, RowRenderParams, RowStyle } from "@omnigrid/core";
1
+ import type { CheckboxRenderParams, GridApi, GridPlugin, RowId, RowRenderParams } from "@omnigrid/core";
2
2
  export type SelectionMode = "single" | "multiple";
3
+ /**
4
+ * CSS class applied to selected rows. The concrete selected-row color is
5
+ * owned by the active theme (e.g. `@omnigrid/default-theme` defines
6
+ * `--omnigrid-cell-selected-background`); the plugin only marks the row.
7
+ */
8
+ export declare const SELECTED_ROW_CLASS = "omnigrid-row-selected";
9
+ /** Applied to rows rejected by `isRowSelectable`; themes supply muted colors. */
10
+ export declare const UNSELECTABLE_ROW_CLASS = "omnigrid-row-unselectable";
3
11
  export interface SelectionRendererParams<T> extends CheckboxRenderParams {
4
12
  data?: T;
5
13
  rowId?: RowId;
@@ -15,6 +23,7 @@ export interface SelectionPluginOptions<T> {
15
23
  showHeaderCheckbox?: boolean;
16
24
  isRowSelectable?: (row: T, index: number) => boolean;
17
25
  checkboxRenderer?: SelectionRenderer<T>;
26
+ onSelectionChange?: (state: SelectionState<T>) => void;
18
27
  selectionColumnId?: string;
19
28
  selectionColumnWidth?: number;
20
29
  }
@@ -32,6 +41,7 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
32
41
  private showHeaderCheckbox;
33
42
  private isRowSelectable;
34
43
  private checkboxRenderer;
44
+ private onSelectionChange?;
35
45
  private readonly selectionColumnId;
36
46
  private readonly selectionColumnWidth;
37
47
  private readonly selectedRowIds;
@@ -49,7 +59,7 @@ export declare class SelectionPlugin<T> implements GridPlugin<T> {
49
59
  shiftKey?: boolean;
50
60
  ctrlKey?: boolean;
51
61
  }): void;
52
- getRowStyle({ id }: RowRenderParams<T>): RowStyle | undefined;
62
+ getRowClass({ id, index, data }: RowRenderParams<T>): string | undefined;
53
63
  private handleRowClick;
54
64
  private applySelection;
55
65
  private updateColumns;
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * CSS class applied to selected rows. The concrete selected-row color is
3
+ * owned by the active theme (e.g. `@omnigrid/default-theme` defines
4
+ * `--omnigrid-cell-selected-background`); the plugin only marks the row.
5
+ */
6
+ export const SELECTED_ROW_CLASS = "omnigrid-row-selected";
7
+ /** Applied to rows rejected by `isRowSelectable`; themes supply muted colors. */
8
+ export const UNSELECTABLE_ROW_CLASS = "omnigrid-row-unselectable";
1
9
  const CHECKBOX_COLUMN_DEFAULT_ID = "__omnigrid_selection__";
2
10
  function defaultCheckboxRenderer(params) {
3
11
  return { type: "@omnigrid/checkbox", ...params };
@@ -13,6 +21,7 @@ export class SelectionPlugin {
13
21
  this.showHeaderCheckbox = options.showHeaderCheckbox ?? false;
14
22
  this.isRowSelectable = options.isRowSelectable ?? (() => true);
15
23
  this.checkboxRenderer = options.checkboxRenderer ?? defaultCheckboxRenderer;
24
+ this.onSelectionChange = options.onSelectionChange;
16
25
  this.selectionColumnId = options.selectionColumnId ?? CHECKBOX_COLUMN_DEFAULT_ID;
17
26
  this.selectionColumnWidth = options.selectionColumnWidth ?? 44;
18
27
  }
@@ -62,8 +71,13 @@ export class SelectionPlugin {
62
71
  }
63
72
  this.applySelection(rowId, index, modifiers);
64
73
  }
65
- getRowStyle({ id }) {
66
- return this.selectedRowIds.has(id) ? { backgroundColor: "#dceffd" } : undefined;
74
+ getRowClass({ id, index, data }) {
75
+ const classes = [];
76
+ if (this.selectedRowIds.has(id))
77
+ classes.push(SELECTED_ROW_CLASS);
78
+ if (!this.isRowSelectable(data, index))
79
+ classes.push(UNSELECTABLE_ROW_CLASS);
80
+ return classes.length > 0 ? classes.join(" ") : undefined;
67
81
  }
68
82
  handleRowClick(event) {
69
83
  if (this.checkboxOnly)
@@ -204,6 +218,7 @@ export class SelectionPlugin {
204
218
  if (!this.api || this.api.isDestroyed())
205
219
  return;
206
220
  this.api.setData(this.api.getState().data);
221
+ this.onSelectionChange?.(this.getSelectionState());
207
222
  }
208
223
  validateSelection() {
209
224
  if (!this.api)
@@ -237,6 +252,8 @@ export class SelectionPlugin {
237
252
  this.isRowSelectable = newOptions.isRowSelectable;
238
253
  if (newOptions.checkboxRenderer !== undefined)
239
254
  this.checkboxRenderer = newOptions.checkboxRenderer;
255
+ if (newOptions.onSelectionChange !== undefined)
256
+ this.onSelectionChange = newOptions.onSelectionChange;
240
257
  this.updateColumns();
241
258
  this.validateSelection();
242
259
  this.refresh();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/selection-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Headless row selection plugin for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",