@toolbox-web/grid 0.5.0 → 1.0.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 (182) hide show
  1. package/README.md +80 -27
  2. package/all.js +725 -1731
  3. package/all.js.map +1 -1
  4. package/index.js +1431 -2379
  5. package/index.js.map +1 -1
  6. package/lib/core/constants.d.ts +8 -0
  7. package/lib/core/constants.d.ts.map +1 -1
  8. package/lib/core/grid.d.ts +721 -55
  9. package/lib/core/grid.d.ts.map +1 -1
  10. package/lib/core/internal/config-manager.d.ts +3 -7
  11. package/lib/core/internal/config-manager.d.ts.map +1 -1
  12. package/lib/core/internal/dom-builder.d.ts +2 -10
  13. package/lib/core/internal/dom-builder.d.ts.map +1 -1
  14. package/lib/core/internal/event-delegation.d.ts +21 -0
  15. package/lib/core/internal/event-delegation.d.ts.map +1 -1
  16. package/lib/core/internal/inference.d.ts.map +1 -1
  17. package/lib/core/internal/keyboard.d.ts.map +1 -1
  18. package/lib/core/internal/render-scheduler.d.ts +2 -0
  19. package/lib/core/internal/render-scheduler.d.ts.map +1 -1
  20. package/lib/core/internal/rows.d.ts +10 -2
  21. package/lib/core/internal/rows.d.ts.map +1 -1
  22. package/lib/core/internal/shell.d.ts +41 -41
  23. package/lib/core/internal/shell.d.ts.map +1 -1
  24. package/lib/core/internal/validate-config.d.ts.map +1 -1
  25. package/lib/core/plugin/base-plugin.d.ts +2 -15
  26. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  27. package/lib/core/plugin/types.d.ts +33 -6
  28. package/lib/core/plugin/types.d.ts.map +1 -1
  29. package/lib/core/types.d.ts +411 -68
  30. package/lib/core/types.d.ts.map +1 -1
  31. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +89 -2
  32. package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
  33. package/lib/plugins/clipboard/index.d.ts +2 -0
  34. package/lib/plugins/clipboard/index.d.ts.map +1 -1
  35. package/lib/plugins/clipboard/index.js +24 -35
  36. package/lib/plugins/clipboard/index.js.map +1 -1
  37. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +57 -2
  38. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
  39. package/lib/plugins/column-virtualization/index.d.ts +2 -0
  40. package/lib/plugins/column-virtualization/index.d.ts.map +1 -1
  41. package/lib/plugins/column-virtualization/index.js +7 -17
  42. package/lib/plugins/column-virtualization/index.js.map +1 -1
  43. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +75 -5
  44. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
  45. package/lib/plugins/context-menu/index.d.ts +3 -1
  46. package/lib/plugins/context-menu/index.d.ts.map +1 -1
  47. package/lib/plugins/context-menu/index.js +15 -27
  48. package/lib/plugins/context-menu/index.js.map +1 -1
  49. package/lib/plugins/editing/EditingPlugin.d.ts +101 -9
  50. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  51. package/lib/plugins/editing/editors.d.ts +9 -1
  52. package/lib/plugins/editing/editors.d.ts.map +1 -1
  53. package/lib/plugins/editing/index.d.ts +4 -2
  54. package/lib/plugins/editing/index.d.ts.map +1 -1
  55. package/lib/plugins/editing/index.js +412 -279
  56. package/lib/plugins/editing/index.js.map +1 -1
  57. package/lib/plugins/editing/types.d.ts +88 -0
  58. package/lib/plugins/editing/types.d.ts.map +1 -1
  59. package/lib/plugins/export/ExportPlugin.d.ts +73 -7
  60. package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
  61. package/lib/plugins/export/index.d.ts +2 -0
  62. package/lib/plugins/export/index.d.ts.map +1 -1
  63. package/lib/plugins/export/index.js +4 -19
  64. package/lib/plugins/export/index.js.map +1 -1
  65. package/lib/plugins/filtering/FilteringPlugin.d.ts +98 -2
  66. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  67. package/lib/plugins/filtering/index.d.ts +2 -0
  68. package/lib/plugins/filtering/index.d.ts.map +1 -1
  69. package/lib/plugins/filtering/index.js +50 -58
  70. package/lib/plugins/filtering/index.js.map +1 -1
  71. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +80 -6
  72. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
  73. package/lib/plugins/grouping-columns/index.d.ts +2 -0
  74. package/lib/plugins/grouping-columns/index.d.ts.map +1 -1
  75. package/lib/plugins/grouping-columns/index.js +10 -21
  76. package/lib/plugins/grouping-columns/index.js.map +1 -1
  77. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +81 -5
  78. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  79. package/lib/plugins/grouping-rows/index.d.ts +3 -1
  80. package/lib/plugins/grouping-rows/index.d.ts.map +1 -1
  81. package/lib/plugins/grouping-rows/index.js +13 -21
  82. package/lib/plugins/grouping-rows/index.js.map +1 -1
  83. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +90 -5
  84. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  85. package/lib/plugins/master-detail/index.d.ts +2 -0
  86. package/lib/plugins/master-detail/index.d.ts.map +1 -1
  87. package/lib/plugins/master-detail/index.js +11 -17
  88. package/lib/plugins/master-detail/index.js.map +1 -1
  89. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +83 -2
  90. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
  91. package/lib/plugins/multi-sort/index.d.ts +2 -0
  92. package/lib/plugins/multi-sort/index.d.ts.map +1 -1
  93. package/lib/plugins/multi-sort/index.js +11 -19
  94. package/lib/plugins/multi-sort/index.js.map +1 -1
  95. package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +61 -2
  96. package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
  97. package/lib/plugins/pinned-columns/index.d.ts +3 -1
  98. package/lib/plugins/pinned-columns/index.d.ts.map +1 -1
  99. package/lib/plugins/pinned-columns/index.js +7 -17
  100. package/lib/plugins/pinned-columns/index.js.map +1 -1
  101. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +71 -10
  102. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
  103. package/lib/plugins/pinned-rows/index.d.ts +3 -1
  104. package/lib/plugins/pinned-rows/index.d.ts.map +1 -1
  105. package/lib/plugins/pinned-rows/index.js +5 -17
  106. package/lib/plugins/pinned-rows/index.js.map +1 -1
  107. package/lib/plugins/pivot/PivotPlugin.d.ts +81 -4
  108. package/lib/plugins/pivot/PivotPlugin.d.ts.map +1 -1
  109. package/lib/plugins/pivot/index.d.ts +2 -0
  110. package/lib/plugins/pivot/index.d.ts.map +1 -1
  111. package/lib/plugins/pivot/index.js +10 -17
  112. package/lib/plugins/pivot/index.js.map +1 -1
  113. package/lib/plugins/reorder/ReorderPlugin.d.ts +71 -3
  114. package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
  115. package/lib/plugins/reorder/index.d.ts +2 -0
  116. package/lib/plugins/reorder/index.d.ts.map +1 -1
  117. package/lib/plugins/reorder/index.js +8 -18
  118. package/lib/plugins/reorder/index.js.map +1 -1
  119. package/lib/plugins/reorder/types.d.ts +0 -5
  120. package/lib/plugins/reorder/types.d.ts.map +1 -1
  121. package/lib/plugins/selection/SelectionPlugin.d.ts +84 -20
  122. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  123. package/lib/plugins/selection/index.d.ts +2 -1
  124. package/lib/plugins/selection/index.d.ts.map +1 -1
  125. package/lib/plugins/selection/index.js +70 -131
  126. package/lib/plugins/selection/index.js.map +1 -1
  127. package/lib/plugins/selection/types.d.ts +25 -4
  128. package/lib/plugins/selection/types.d.ts.map +1 -1
  129. package/lib/plugins/server-side/ServerSidePlugin.d.ts +65 -4
  130. package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
  131. package/lib/plugins/server-side/index.d.ts +3 -1
  132. package/lib/plugins/server-side/index.d.ts.map +1 -1
  133. package/lib/plugins/server-side/index.js +5 -17
  134. package/lib/plugins/server-side/index.js.map +1 -1
  135. package/lib/plugins/tree/TreePlugin.d.ts +89 -2
  136. package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
  137. package/lib/plugins/tree/index.d.ts +3 -2
  138. package/lib/plugins/tree/index.d.ts.map +1 -1
  139. package/lib/plugins/tree/index.js +59 -94
  140. package/lib/plugins/tree/index.js.map +1 -1
  141. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +66 -3
  142. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
  143. package/lib/plugins/undo-redo/index.d.ts +3 -1
  144. package/lib/plugins/undo-redo/index.d.ts.map +1 -1
  145. package/lib/plugins/undo-redo/index.js +5 -17
  146. package/lib/plugins/undo-redo/index.js.map +1 -1
  147. package/lib/plugins/visibility/VisibilityPlugin.d.ts +86 -2
  148. package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
  149. package/lib/plugins/visibility/index.d.ts +2 -0
  150. package/lib/plugins/visibility/index.d.ts.map +1 -1
  151. package/lib/plugins/visibility/index.js +6 -17
  152. package/lib/plugins/visibility/index.js.map +1 -1
  153. package/package.json +6 -6
  154. package/public.d.ts +72 -2
  155. package/public.d.ts.map +1 -1
  156. package/umd/grid.all.umd.js +16 -16
  157. package/umd/grid.all.umd.js.map +1 -1
  158. package/umd/grid.umd.js +9 -9
  159. package/umd/grid.umd.js.map +1 -1
  160. package/umd/plugins/clipboard.umd.js.map +1 -1
  161. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  162. package/umd/plugins/context-menu.umd.js.map +1 -1
  163. package/umd/plugins/editing.umd.js +1 -1
  164. package/umd/plugins/editing.umd.js.map +1 -1
  165. package/umd/plugins/export.umd.js.map +1 -1
  166. package/umd/plugins/filtering.umd.js.map +1 -1
  167. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  168. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  169. package/umd/plugins/master-detail.umd.js.map +1 -1
  170. package/umd/plugins/multi-sort.umd.js.map +1 -1
  171. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  172. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  173. package/umd/plugins/pivot.umd.js.map +1 -1
  174. package/umd/plugins/reorder.umd.js +1 -1
  175. package/umd/plugins/reorder.umd.js.map +1 -1
  176. package/umd/plugins/selection.umd.js +1 -1
  177. package/umd/plugins/selection.umd.js.map +1 -1
  178. package/umd/plugins/server-side.umd.js.map +1 -1
  179. package/umd/plugins/tree.umd.js +1 -1
  180. package/umd/plugins/tree.umd.js.map +1 -1
  181. package/umd/plugins/undo-redo.umd.js.map +1 -1
  182. package/umd/plugins/visibility.umd.js.map +1 -1
package/README.md CHANGED
@@ -27,7 +27,7 @@ document.body.appendChild(grid);
27
27
  ```
28
28
 
29
29
  > [!TIP]
30
- > For complete examples, see the [Storybook documentation](https://oysteinamundsen.github.io/toolbox/).
30
+ > For complete examples, see the [Storybook documentation](https://toolboxjs.com/).
31
31
 
32
32
  ---
33
33
 
@@ -43,7 +43,6 @@ The grid supports multiple configuration methods, all converging into a **single
43
43
  grid.gridConfig = {
44
44
  columns: [{ field: 'name' }, { field: 'age', type: 'number' }],
45
45
  fitMode: 'stretch',
46
- editOn: 'dblClick',
47
46
  plugins: [new SelectionPlugin({ mode: 'row' })],
48
47
  shell: { header: { title: 'My Data Grid' } },
49
48
  };
@@ -54,7 +53,6 @@ grid.gridConfig = {
54
53
  ```typescript
55
54
  grid.columns = [{ field: 'name' }, { field: 'age' }];
56
55
  grid.fitMode = 'stretch';
57
- grid.editOn = 'dblClick';
58
56
  ```
59
57
 
60
58
  **3. Via Light DOM (declarative HTML):**
@@ -75,7 +73,7 @@ grid.editOn = 'dblClick';
75
73
 
76
74
  When the same property is set via multiple methods, higher precedence wins:
77
75
 
78
- 1. Individual props (`fitMode`, `editOn`) - highest
76
+ 1. Individual props (`fitMode`) - highest
79
77
  2. `columns` prop
80
78
  3. Light DOM elements
81
79
  4. `gridConfig` property - lowest
@@ -137,7 +135,6 @@ The grid supports configuration via HTML attributes with JSON-serialized values:
137
135
  | `columns` | JSON | Column definitions (JSON-serialized) |
138
136
  | `grid-config` | JSON | Full configuration object (JSON-serialized) |
139
137
  | `fit-mode` | string | Column sizing: `'stretch'` or `'fixed'` |
140
- | `edit-on` | string | Edit trigger: `'click'` or `'dblClick'` |
141
138
 
142
139
  **Example with HTML attributes:**
143
140
 
@@ -146,21 +143,19 @@ The grid supports configuration via HTML attributes with JSON-serialized values:
146
143
  rows='[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]'
147
144
  columns='[{"field":"id","header":"ID"},{"field":"name","header":"Name"}]'
148
145
  fit-mode="stretch"
149
- edit-on="dblClick"
150
146
  >
151
147
  </tbw-grid>
152
148
  ```
153
149
 
154
150
  ### Properties
155
151
 
156
- | Property | Type | Description |
157
- | ------------ | -------------------------------- | ------------------------------------------------------------------------ |
158
- | `rows` | `T[]` | Data array |
159
- | `sourceRows` | `T[]` (readonly) | Original unfiltered/unprocessed rows |
160
- | `columns` | `ColumnConfig[]` | Column definitions (→ `gridConfig.columns`) |
161
- | `gridConfig` | `GridConfig` | Full configuration object (single source of truth) |
162
- | `fitMode` | `'stretch' \| 'fixed'` | Column sizing behavior (→ `gridConfig.fitMode`) |
163
- | `editOn` | `'click' \| 'dblClick' \| false` | Edit trigger (→ `gridConfig.editOn`). Set to `false` to disable editing. |
152
+ | Property | Type | Description |
153
+ | ------------ | ---------------------- | -------------------------------------------------- |
154
+ | `rows` | `T[]` | Data array |
155
+ | `sourceRows` | `T[]` (readonly) | Original unfiltered/unprocessed rows |
156
+ | `columns` | `ColumnConfig[]` | Column definitions (→ `gridConfig.columns`) |
157
+ | `gridConfig` | `GridConfig` | Full configuration object (single source of truth) |
158
+ | `fitMode` | `'stretch' \| 'fixed'` | Column sizing behavior (→ `gridConfig.fitMode`) |
164
159
 
165
160
  ### Methods
166
161
 
@@ -169,6 +164,10 @@ The grid supports configuration via HTML attributes with JSON-serialized values:
169
164
  | `ready()` | `Promise<void>` | Resolves when fully initialized |
170
165
  | `forceLayout()` | `Promise<void>` | Force re-layout |
171
166
  | `getConfig()` | `Promise<GridConfig>` | Get effective configuration |
167
+ | `getRowId(row)` | `string` | Get unique identifier for a row |
168
+ | `getRow(id)` | `T \| undefined` | Get row by its ID |
169
+ | `updateRow(id, changes, source?)` | `void` | Update a single row by ID |
170
+ | `updateRows(updates, source?)` | `void` | Batch update multiple rows |
172
171
  | `resetChangedRows(silent?)` | `Promise<void>` | Clear change tracking |
173
172
  | `beginBulkEdit(rowIndex)` | `Promise<void>` | Start row editing |
174
173
  | `commitActiveRowEdit()` | `Promise<void>` | Commit current edit |
@@ -180,18 +179,19 @@ The grid supports configuration via HTML attributes with JSON-serialized values:
180
179
 
181
180
  ### Events
182
181
 
183
- | Event | Detail | Description |
184
- | ----------------------- | --------------------------- | ----------------------------- |
185
- | `cell-commit` | `CellCommitDetail` | Cell value committed |
186
- | `row-commit` | `RowCommitDetail` | Row edit committed |
187
- | `changed-rows-reset` | `ChangedRowsResetDetail` | Change tracking cleared |
188
- | `sort-change` | `SortChangeDetail` | Sort state changed |
189
- | `column-resize` | `ColumnResizeDetail` | Column resized |
190
- | `column-state-change` | `ColumnState` | Column state changed |
191
- | `activate-cell` | `ActivateCellDetail` | Cell activated |
192
- | `group-toggle` | `GroupToggleDetail` | Row group expanded/collapsed |
193
- | `mount-external-view` | `ExternalMountViewDetail` | External view mount request |
194
- | `mount-external-editor` | `ExternalMountEditorDetail` | External editor mount request |
182
+ | Event | Detail | Description |
183
+ | ----------------------- | --------------------------- | ---------------------------------- |
184
+ | `cell-commit` | `CellCommitDetail` | Cell value committed (inline edit) |
185
+ | `cell-change` | `CellChangeDetail` | Row updated via Row Update API |
186
+ | `row-commit` | `RowCommitDetail` | Row edit committed |
187
+ | `changed-rows-reset` | `ChangedRowsResetDetail` | Change tracking cleared |
188
+ | `sort-change` | `SortChangeDetail` | Sort state changed |
189
+ | `column-resize` | `ColumnResizeDetail` | Column resized |
190
+ | `column-state-change` | `ColumnState` | Column state changed |
191
+ | `activate-cell` | `ActivateCellDetail` | Cell activated |
192
+ | `group-toggle` | `GroupToggleDetail` | Row group expanded/collapsed |
193
+ | `mount-external-view` | `ExternalMountViewDetail` | External view mount request |
194
+ | `mount-external-editor` | `ExternalMountEditorDetail` | External editor mount request |
195
195
 
196
196
  Import event names from the `DGEvents` constant:
197
197
 
@@ -241,13 +241,25 @@ See [Storybook](https://oysteinamundsen.github.io/toolbox/) for complete configu
241
241
  interface GridConfig {
242
242
  columns?: ColumnConfig[];
243
243
  fitMode?: 'stretch' | 'fixed';
244
- editOn?: 'click' | 'dblClick' | false;
245
244
  plugins?: BaseGridPlugin[]; // Array of plugin class instances
246
245
  icons?: GridIcons; // Centralized icon configuration
247
246
  shell?: ShellConfig; // Optional header bar and tool panels
247
+ getRowId?: (row: T) => string; // Custom row ID resolver
248
+ typeDefaults?: Record<string, TypeDefault<T>>; // Type-level renderers/editors
248
249
  }
249
250
  ```
250
251
 
252
+ ### Row Identification
253
+
254
+ The grid uses row IDs for the [Row Update API](#methods). By default, it looks for `id` or `_id` properties on row objects. Rows without an identifiable ID are not accessible via the Row Update API. For custom ID fields, provide a `getRowId` function:
255
+
256
+ ```typescript
257
+ grid.gridConfig = {
258
+ columns: [...],
259
+ getRowId: (row) => row.employeeNumber, // Use custom field as ID
260
+ };
261
+ ```
262
+
251
263
  ### Icons Configuration
252
264
 
253
265
  The grid provides a centralized icon system via `gridConfig.icons`. All plugins (tree, grouping, sorting, context menus, etc.) automatically use these icons, ensuring visual consistency across the entire grid.
@@ -270,6 +282,47 @@ grid.gridConfig = {
270
282
 
271
283
  Icons can be strings (text or HTML) or `HTMLElement` instances. Plugins use grid-level icons by default but can override with their own config when needed.
272
284
 
285
+ ### Type-Level Defaults
286
+
287
+ Define renderers and editors at the type level that apply to all columns with matching `type`:
288
+
289
+ ```typescript
290
+ grid.gridConfig = {
291
+ typeDefaults: {
292
+ country: {
293
+ renderer: (ctx) => {
294
+ const span = document.createElement('span');
295
+ span.textContent = `🌍 ${ctx.value}`;
296
+ return span;
297
+ },
298
+ editor: (ctx) => {
299
+ const select = document.createElement('select');
300
+ ['USA', 'UK', 'Germany'].forEach((c) => {
301
+ const opt = document.createElement('option');
302
+ opt.value = c;
303
+ opt.textContent = c;
304
+ select.appendChild(opt);
305
+ });
306
+ select.value = ctx.value;
307
+ select.onchange = () => ctx.commit(select.value);
308
+ return select;
309
+ },
310
+ },
311
+ currency: {
312
+ editorParams: { min: 0, step: 0.01 },
313
+ },
314
+ },
315
+ columns: [
316
+ { field: 'country', type: 'country', editable: true }, // Uses country renderer/editor
317
+ { field: 'salary', type: 'currency', editable: true }, // Uses currency editorParams
318
+ ],
319
+ };
320
+ ```
321
+
322
+ **Resolution Priority:** Column-level → `gridConfig.typeDefaults` → Framework adapter → Built-in
323
+
324
+ Framework adapters (`@toolbox-web/grid-react`, `@toolbox-web/grid-angular`) provide app-level type registries for React/Angular components.
325
+
273
326
  ### Plugin Configuration Example
274
327
 
275
328
  Plugins are class instances that you import and instantiate with their configuration: