@nocopypaste/vue-grid 0.8.0 → 0.10.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 (74) hide show
  1. package/AGENTS.md +68 -32
  2. package/CHANGELOG.md +35 -0
  3. package/README.md +140 -29
  4. package/agent/api.json +85 -2
  5. package/agent/api.md +13 -2
  6. package/agent/grid-config.schema.json +41 -0
  7. package/dist/agent/api.js +80 -2
  8. package/dist/agent/requirements.js +9 -2
  9. package/dist/agent/requirements.js.map +1 -1
  10. package/dist/base.css +1 -1
  11. package/dist/components/VGrid.vue_vue_type_script_setup_true_lang.js +595 -576
  12. package/dist/components/VGrid.vue_vue_type_script_setup_true_lang.js.map +1 -1
  13. package/dist/components/VGridCell.vue_vue_type_script_setup_true_lang.js +78 -56
  14. package/dist/components/VGridCell.vue_vue_type_script_setup_true_lang.js.map +1 -1
  15. package/dist/components/VGridCellEditor.js +6 -0
  16. package/dist/components/VGridCellEditor.js.map +1 -0
  17. package/dist/components/VGridCellEditor.vue_vue_type_script_setup_true_lang.js +208 -0
  18. package/dist/components/VGridCellEditor.vue_vue_type_script_setup_true_lang.js.map +1 -0
  19. package/dist/components/VGridHeader.vue_vue_type_script_setup_true_lang.js +82 -53
  20. package/dist/components/VGridHeader.vue_vue_type_script_setup_true_lang.js.map +1 -1
  21. package/dist/components/VGridSortMarker.js +6 -0
  22. package/dist/components/VGridSortMarker.js.map +1 -0
  23. package/dist/components/VGridSortMarker.vue_vue_type_script_setup_true_lang.js +21 -0
  24. package/dist/components/VGridSortMarker.vue_vue_type_script_setup_true_lang.js.map +1 -0
  25. package/dist/composables/useDataSource.js.map +1 -1
  26. package/dist/composables/useEditing.js +202 -0
  27. package/dist/composables/useEditing.js.map +1 -0
  28. package/dist/composables/useGridKeyboard.js +5 -1
  29. package/dist/composables/useGridKeyboard.js.map +1 -1
  30. package/dist/composables/useGridMenus.js +24 -12
  31. package/dist/composables/useGridMenus.js.map +1 -1
  32. package/dist/composables/useRowGrouping.js.map +1 -1
  33. package/dist/composables/useSorting.js +48 -0
  34. package/dist/composables/useSorting.js.map +1 -0
  35. package/dist/core/grouping.js +1 -1
  36. package/dist/core/grouping.js.map +1 -1
  37. package/dist/core/sort.js +31 -1
  38. package/dist/core/sort.js.map +1 -1
  39. package/dist/core/value.js +18 -2
  40. package/dist/core/value.js.map +1 -1
  41. package/dist/core.css +1 -1
  42. package/dist/features/editing.js +12 -0
  43. package/dist/features/editing.js.map +1 -0
  44. package/dist/features/index.js +30 -28
  45. package/dist/features/index.js.map +1 -1
  46. package/dist/features/sorting.js +8 -4
  47. package/dist/features/sorting.js.map +1 -1
  48. package/dist/index.js +63 -62
  49. package/dist/internal/context.js.map +1 -1
  50. package/dist/internal/features.js.map +1 -1
  51. package/dist/theme.css +1 -1
  52. package/dist/types/agent/requirements.d.ts +1 -1
  53. package/dist/types/components/VGrid.vue.d.ts +20 -4
  54. package/dist/types/components/VGridCellEditor.vue.d.ts +11 -0
  55. package/dist/types/components/VGridHeader.vue.d.ts +4 -3
  56. package/dist/types/components/VGridSortMarker.vue.d.ts +9 -0
  57. package/dist/types/composables/useDataSource.d.ts +3 -0
  58. package/dist/types/composables/useEditing.d.ts +73 -0
  59. package/dist/types/composables/useGridMenus.d.ts +5 -0
  60. package/dist/types/composables/useRowGrouping.d.ts +2 -1
  61. package/dist/types/composables/useSorting.d.ts +24 -0
  62. package/dist/types/core/grouping.d.ts +5 -2
  63. package/dist/types/core/sort.d.ts +16 -0
  64. package/dist/types/core/value.d.ts +6 -0
  65. package/dist/types/features/editing.d.ts +2 -0
  66. package/dist/types/features/index.d.ts +2 -1
  67. package/dist/types/index.d.ts +2 -2
  68. package/dist/types/internal/context.d.ts +6 -0
  69. package/dist/types/internal/features.d.ts +2 -1
  70. package/dist/types/types.d.ts +112 -1
  71. package/dist/vue-grid.css +1 -1
  72. package/llms-full.txt +221 -63
  73. package/llms.txt +1 -1
  74. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -33,44 +33,50 @@ runs in the [live examples](https://eboye.github.io/eboye-vue-grid/), each with
33
33
  row that height, px) and a bounded height. `pagination` is ignored while `virtual` is on.
34
34
  8. **Rows are never mutated** by the grid. To change a cell: assign the field on a reactive row, or
35
35
  replace rows (`patchRows(rows, patches, rowKey)` keeps unchanged rows' identity).
36
- 9. **Editable renderers are controlled** (`checkbox`, `switch`, `radio`, `icon-toggle`, `edit`,
37
- buttons, menus): they emit `@cell-action="{ name, payload, row, rowKey, column }"`; your handler
38
- updates the data.
39
- 10. **Type columns** with `const col = createColumnHelper<Row>()` → `col({ ... })`: `rendererOptions`
36
+ 9. **Inline editing is controlled too** (`editingFeature`, `editable` columns): the grid emits
37
+ `@cell-edit="{ row, rowKey, column, value, oldValue }"` and never writes the value; store it
38
+ (`setCellValue(e.row, e.column, e.value)` on reactive rows), or do it in `:save-cell` (may return a
39
+ Promise; a rejection keeps the editor open with the message).
40
+ 10. **Editable renderers are controlled** (`checkbox`, `switch`, `radio`, `icon-toggle`, `edit`,
41
+ buttons, menus): they emit `@cell-action="{ name, payload, row, rowKey, column }"`; your handler
42
+ updates the data.
43
+ 11. **Type columns** with `const col = createColumnHelper<Row>()` → `col({ ... })`: `rendererOptions`
40
44
  are then checked against the chosen renderer.
41
- 11. **Server data** (`:data-source` + `serverDataFeature`): don't also pass `rows`; pass the
45
+ 12. **Server data** (`:data-source` + `serverDataFeature`): don't also pass `rows`; pass the
42
46
  `signal` to `fetch`; return `{ rows, total }` (`total` drives the pager).
43
- 12. Width is any CSS grid track as a **string**: `'8rem'`, `'1fr'`, `'minmax(10rem, 2fr)'`,
47
+ 13. Width is any CSS grid track as a **string**: `'8rem'`, `'1fr'`, `'minmax(10rem, 2fr)'`,
44
48
  `'min-content'` (default `auto`). Numbers are not accepted.
45
49
 
46
50
  ## Which feature for what
47
51
 
48
- | The user wants… | Feature(s) | Props / column options |
49
- | ------------------------------------------------- | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50
- | Click a header to sort | `sortingFeature` | column `sortable: true`; `sort-mode="client"` (or handle `v-model:sort`) |
51
- | Filters per column, a filter row, quick search | `filteringFeature` | column `filterable: true` (`filter: 'text' \| 'number' \| 'date' \| 'boolean' \| 'set'`); `filter-row`; `<VGridSearch />` in `#toolbar` |
52
- | Pages | `paginationFeature` | `pagination` (or `{ pageSizes: [10, 25, 50] }`), `v-model:page`, `v-model:page-size` |
53
- | Backend sorting / filtering / paging | `serverDataFeature` (+ the above) | `:data-source="(query, { signal }) => Promise<{ rows, total }>"` |
54
- | Checkboxes / row selection, batch actions | `selectionFeature` | `selectable` (or `'single'`), `v-model:selected`, `is-row-selectable`, `prune-selection`; `#toolbar="{ selected, selectedCount, clearSelection }"`; server data: `v-model:select-all-matching` |
55
- | Nested child rows aligned to the parent's columns | `subGridsFeature` | `:sub-rows="(row) => row.children"` or `:load-sub-rows` + `:has-sub-rows` |
56
- | An expandable panel under a row | — | `#detail="{ row }"` slot (`row-expandable` to limit it) |
57
- | 10,000+ rows | `virtualScrollingFeature` | `:virtual="{ rowHeight: 40 }"` + bounded height |
58
- | Right-click menus (cells, headers) | `menusFeature` | `:context-menu="(ctx) => MenuItem[]"` + `@context-action`; header menu is on by default |
59
- | Freeze columns left / right | `columnPinningFeature` | column `pinned: 'left' \| 'right'`; on narrow grids they scroll unless `pinned-max-share` allows (default half the width) |
60
- | Show / hide columns | `columnVisibilityFeature` | column `hidden: true`; `<VGridColumnMenu>` in `#toolbar` |
61
- | Drag columns to reorder | `columnReorderFeature` | column `reorderable: false` to lock one |
62
- | Drag column edges to resize | `columnResizingFeature` | `minWidth` / `maxWidth`, `resizable: false` |
63
- | Grouped headers ("Q1" over three columns) | `columnGroupsFeature` | column `group: 'Q1'` |
64
- | Rows that stay on top / bottom | `rowPinningFeature` | `v-model:pinned-rows="{ top: [id], bottom: [] }"`, `pinRow()`, `pinned-top-rows` |
65
- | A totals row (sum, avg, …) | `aggregationFeature` | column `aggregate: 'sum' \| 'avg' \| 'min' \| 'max' \| 'count' \| fn`; `totals` (or `'top'`) |
66
- | Group server data across all rows (not the page) | `serverGroupingFeature` (+ `rowGroupingFeature`, `serverDataFeature`) | return `{ groups: [{ value, count, aggregates }], total }` for `query.groupBy` / `query.groupPath`, `{ rows }` at the last level; `v-model:selected-groups` |
67
- | Group rows by a column ("by status, then city") | `rowGroupingFeature` | `v-model:group-by="['status', 'city']"`, `groups-expanded`; column `groupable: true` (header menu), `groupValue: (row) => …` (e.g. month); `aggregate` shows per group |
68
- | Download CSV / Excel, print, copy rows / cells | `exportFeature` | `grid.exportCsv()`, `getCsv()`, `exportXlsx()`, `getXlsx()`, `print()`, `copyRows()`, `@copy`; column `exportValue`, `exportable: false` |
69
- | Row / selection counts, sum of the selected rows | `statusBarFeature` | `status-bar` (or `{ summary: ['total'], aggregates?: ['sum', 'avg'] }`); `#status-bar="{ rowCount, selectedCount, summary, … }"` |
70
- | Translate / reword the grid, drop built-in pieces | — | `messages` (`GridMessages`), `parts` (`GridParts`): app-wide in `createVueGrid` or per grid; slots `#load-error`, `#no-match`, `#select-all-banner` |
71
- | Arrow-key navigation (ARIA grid) | `keyboardNavigationFeature` | — |
72
- | Remember column layout | — | `storage="orders-grid"` (localStorage key) |
73
- | Cell type (money, date, badge, link, …) | — | `renderer: currencyRenderer` etc. (list below) |
52
+ | The user wants… | Feature(s) | Props / column options |
53
+ | ------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | Click a header to sort | `sortingFeature` | column `sortable: true`; `sort-mode="client"` (or handle `v-model:sort`) |
55
+ | Sort by several columns ("city, then stake") | `sortingFeature` | `multi-sort`, `v-model:sorts="[{ key, dir }, …]"`; Shift-click adds a column; server: `query.sorts` |
56
+ | Filters per column, a filter row, quick search | `filteringFeature` | column `filterable: true` (`filter: 'text' \| 'number' \| 'date' \| 'boolean' \| 'set'`); `filter-row`; `<VGridSearch />` in `#toolbar` |
57
+ | Pages | `paginationFeature` | `pagination` (or `{ pageSizes: [10, 25, 50] }`), `v-model:page`, `v-model:page-size` |
58
+ | Backend sorting / filtering / paging | `serverDataFeature` (+ the above) | `:data-source="(query, { signal }) => Promise<{ rows, total }>"` |
59
+ | Checkboxes / row selection, batch actions | `selectionFeature` | `selectable` (or `'single'`), `v-model:selected`, `is-row-selectable`, `prune-selection`; `#toolbar="{ selected, selectedCount, clearSelection }"`; server data: `v-model:select-all-matching` |
60
+ | Nested child rows aligned to the parent's columns | `subGridsFeature` | `:sub-rows="(row) => row.children"` or `:load-sub-rows` + `:has-sub-rows` |
61
+ | An expandable panel under a row | — | `#detail="{ row }"` slot (`row-expandable` to limit it) |
62
+ | 10,000+ rows | `virtualScrollingFeature` | `:virtual="{ rowHeight: 40 }"` + bounded height |
63
+ | Right-click menus (cells, headers) | `menusFeature` | `:context-menu="(ctx) => MenuItem[]"` + `@context-action`; header menu is on by default |
64
+ | Freeze columns left / right | `columnPinningFeature` | column `pinned: 'left' \| 'right'`; on narrow grids they scroll unless `pinned-max-share` allows (default half the width) |
65
+ | Show / hide columns | `columnVisibilityFeature` | column `hidden: true`; `<VGridColumnMenu>` in `#toolbar` |
66
+ | Drag columns to reorder | `columnReorderFeature` | column `reorderable: false` to lock one |
67
+ | Drag column edges to resize | `columnResizingFeature` | `minWidth` / `maxWidth`, `resizable: false` |
68
+ | Grouped headers ("Q1" over three columns) | `columnGroupsFeature` | column `group: 'Q1'` |
69
+ | Rows that stay on top / bottom | `rowPinningFeature` | `v-model:pinned-rows="{ top: [id], bottom: [] }"`, `pinRow()`, `pinned-top-rows` |
70
+ | A totals row (sum, avg, …) | `aggregationFeature` | column `aggregate: 'sum' \| 'avg' \| 'min' \| 'max' \| 'count' \| fn`; `totals` (or `'top'`) |
71
+ | Group server data across all rows (not the page) | `serverGroupingFeature` (+ `rowGroupingFeature`, `serverDataFeature`) | return `{ groups: [{ value, count, aggregates }], total }` for `query.groupBy` / `query.groupPath`, `{ rows }` at the last level; `v-model:selected-groups` |
72
+ | Group rows by a column ("by status, then city") | `rowGroupingFeature` | `v-model:group-by="['status', 'city']"`, `groups-expanded`; column `groupable: true` (header menu), `groupValue: (row) => …` (e.g. month); `aggregate` shows per group |
73
+ | Download CSV / Excel, print, copy rows / cells | `exportFeature` | `grid.exportCsv()`, `getCsv()`, `exportXlsx()`, `getXlsx()`, `print()`, `copyRows()`, `@copy`; column `exportValue`, `exportable: false` |
74
+ | Row / selection counts, sum of the selected rows | `statusBarFeature` | `status-bar` (or `{ summary: ['total'], aggregates?: ['sum', 'avg'] }`); `#status-bar="{ rowCount, selectedCount, summary, … }"` |
75
+ | Edit cells in place (spreadsheet-like) | `editingFeature` (+ `keyboardNavigationFeature` for typing / Enter) | column `editable: true \| (row) => boolean`, `editor`, `editorOptions`, `validate`; `@cell-edit` (store `value`: `setCellValue(e.row, e.column, e.value)`), `:save-cell` (async, rejection = error) |
76
+ | Translate / reword the grid, drop built-in pieces | — | `messages` (`GridMessages`), `parts` (`GridParts`): app-wide in `createVueGrid` or per grid; slots `#load-error`, `#no-match`, `#select-all-banner` |
77
+ | Arrow-key navigation (ARIA grid) | `keyboardNavigationFeature` | — |
78
+ | Remember column layout | — | `storage="orders-grid"` (localStorage key) |
79
+ | Cell type (money, date, badge, link, …) | — | `renderer: currencyRenderer` etc. (list below) |
74
80
 
75
81
  ## Renderers (pick by data)
76
82
 
@@ -453,6 +459,31 @@ function onAction(e: CellActionEvent<Order>) {
453
459
  </template>
454
460
  ```
455
461
 
462
+ ### Inline editing
463
+
464
+ ```ts
465
+ import { editingFeature, keyboardNavigationFeature, setCellValue } from '@nocopypaste/vue-grid'
466
+ const rows = reactive(bets) // the handler writes into them
467
+ const columns = [
468
+ col({
469
+ key: 'player',
470
+ field: 'player.name',
471
+ editable: true,
472
+ validate: (v) => (String(v).trim() ? undefined : 'Required'),
473
+ }),
474
+ col({ key: 'stake', renderer: currencyRenderer, editable: true, editorOptions: { min: 0 } }), // number
475
+ col({ key: 'status', renderer: statusRenderer, editable: (b) => b.status !== 'Void' }), // select
476
+ col({ key: 'verified', renderer: booleanRenderer, editable: true }), // flips at once
477
+ ]
478
+ // <VGrid :rows :columns row-key="id" :features="[editingFeature, keyboardNavigationFeature]"
479
+ // @cell-edit="(e) => setCellValue(e.row, e.column, e.value)" />
480
+ // async: :save-cell="async (e) => { await api.save(e); setCellValue(e.row, e.column, e.value) }"
481
+ ```
482
+
483
+ The editor comes from the renderer (number, date, datetime, select, checkbox, text) or `editor`
484
+ (a name or your component). Double-click / Enter / F2 / typing opens it; Enter saves, Tab moves to
485
+ the next editable cell, Esc cancels.
486
+
456
487
  ### Editable checkbox (controlled)
457
488
 
458
489
  ```ts
@@ -501,6 +532,11 @@ only sees stylesheet rules. Density:
501
532
  ## Pitfalls
502
533
 
503
534
  - Nothing sorts → `sort-mode="client"` missing (or `sortingFeature` missing).
535
+ - An edited cell snaps back to its old value → nothing stores it: handle `@cell-edit` (or
536
+ `save-cell`) and write `e.value` into reactive rows (`setCellValue`); the grid never does.
537
+ - Typing / Enter on a cell doesn't start editing → cells only take focus with
538
+ `keyboardNavigationFeature`; without it, double-click.
539
+ - Shift-click sorts by one column only → add `multi-sort`, and bind `v-model:sorts` (not `sort`) to read every key; a `dataSource` reads `query.sorts`.
504
540
  - Columns are squeezed / the page scrolls sideways → give `width`s (`minmax(8rem, 1fr)`); the grid
505
541
  scrolls horizontally inside itself when columns are wider than it.
506
542
  - Grid grows forever / no sticky header → no bounded height.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0 — 2026-11-25
4
+
5
+ **Inline cell editing** (`editingFeature`, opt-in): mark columns `editable` (or `(row) => boolean`).
6
+ A cell opens its editor on double-click, on Enter or F2 when focused, or when you start typing on
7
+ it (the keys replace the value, even typed before the editor has loaded). Enter saves, Tab /
8
+ Shift+Tab save and edit the next / previous editable cell (a checkbox cell only takes focus), Esc
9
+ cancels, clicking elsewhere saves. The editor follows the renderer: number (money, numbers),
10
+ date, date and time, a select of the column's values (status, chip), a checkbox that flips at
11
+ once, else text; `editor` picks another or your own component (`CellEditorProps`), `editorOptions`
12
+ sets a select's choices, a number's `min` / `max`, a placeholder. `validate(value, row)` returns a
13
+ message to keep the editor open with it, shown below the cell (and as the input's description);
14
+ numbers are checked too. The grid emits `cell-edit({ row, rowKey, column, value, oldValue })` and
15
+ never writes the value; `save-cell` may return a Promise: the cell shows it saving, and a rejection
16
+ keeps the editor open with the error. The cell keeps its width while editing. `startEdit(rowKey,
17
+ columnKey)` / `stopEdit(cancel?)` from code. New exports: `editingFeature` (also in
18
+ `allFeatures`), `setCellValue(row, column, value)`, types `CellEditEvent`, `CellEditorProps`,
19
+ `EditorName`, `EditorOptions`, `EditorOption`; messages `editCell`, `editNotANumber`,
20
+ `editOutOfRange`, `editSaveFailed`, `editSaving`. The editor (3.0 kB gzip) loads on demand, while
21
+ the browser is idle, once a grid has an editable column. A plain grid grows by 0.3 kB gzip (to 15.3),
22
+ a grid with editing is 17.0 kB plus the editor's chunk.
23
+
24
+ ## 0.9.0 — 2026-11-24
25
+
26
+ **Multi-column sort** (`sortingFeature`): with `multi-sort`, Shift-click a header (Shift+Enter on
27
+ a focused one) to sort by it after the others: ascending, descending, then removed; a plain click
28
+ still sorts by that column alone. `v-model:sorts` holds every key (`sort` stays the first, and
29
+ setting it from outside makes it the only one). Headers show each column's number; `aria-sort` stays
30
+ on the first key and screen readers hear “sorted 2 of 3, descending” for the others. The header
31
+ menu gains **Then sort ascending / descending**, and its Clear sort drops only that column. A
32
+ `dataSource` gets every key in `query.sorts` (only with `multi-sort`). Row groups follow their own
33
+ column's key wherever it is in the list. New exports: `sortRowsBy(rows, keys)`, `nextSorts(sorts,
34
+ key)`, `type SortKey`; `GridQuery.sorts`; messages `thenSortAscending`, `thenSortDescending`,
35
+ `sortPosition(position, dir)`. The logic lives in `sortingFeature`: a plain grid grows by 0.2 kB
36
+ gzip (to 15.0), a grid with sorting by 0.9 kB (to 16.0).
37
+
3
38
  ## 0.8.0 — 2026-11-24
4
39
 
5
40
  **Server-side row grouping** (`serverGroupingFeature`, with `rowGroupingFeature` and
package/README.md CHANGED
@@ -135,6 +135,7 @@ an opt-in feature:
135
135
  | `serverGroupingFeature` | With a `data-source`: groups from the server (`query.groupBy` / `groupPath`), each one's contents loaded on expand, groups selected by query (`v-model:selected-groups`). See [Server-side grouping](#server-side-grouping) |
136
136
  | `exportFeature` | `exportCsv()` / `getCsv()`, `exportXlsx()` / `getXlsx()` (Excel, typed cells), `print()` (every row, header on each page), `copyRows()`, Ctrl/⌘+C for the selected rows or the focused cell, the `copy` event; column `exportValue` / `exportable` |
137
137
  | `statusBarFeature` | `status-bar`: a bar under the grid with the rows that pass the filters, the selected rows, the active filters (with Clear), and `{ summary: [keys] }` columns' sum and average over the selected rows; the `#status-bar` slot |
138
+ | `editingFeature` | `editable` columns: an editor in the cell (text, number, date, select, checkbox, or your own) on double-click, Enter / F2 or typing; `cell-edit`, and `save-cell` for async saves. See [Inline editing](#inline-editing) |
138
139
 
139
140
  ```ts
140
141
  // per grid
@@ -178,34 +179,35 @@ what you import.
178
179
 
179
180
  | Import (minified / gzip, Vue excluded) | Initial chunk |
180
181
  | ---------------------------------------------------------------------------- | ------------------ |
181
- | `VGrid` (no features) | 43.1 kB / 14.8 kB |
182
- | `VGrid` + `sortingFeature` | 43.8 kB / 15.1 kB |
183
- | `VGrid` + `filteringFeature` | 53.8 kB / 18.6 kB |
184
- | `VGrid` + `serverDataFeature` | 44.5 kB / 15.4 kB |
185
- | `VGrid` + `paginationFeature` | 43.2 kB / 14.8 kB |
186
- | `VGrid` + `selectionFeature` | 47.2 kB / 16.2 kB |
187
- | `VGrid` + `subGridsFeature` | 45.4 kB / 15.6 kB |
188
- | `VGrid` + `menusFeature` | 53.9 kB / 18.4 kB |
189
- | `VGrid` + `columnReorderFeature` | 46.7 kB / 16.0 kB |
190
- | `VGrid` + `columnPinningFeature` | 46.0 kB / 15.8 kB |
191
- | `VGrid` + `virtualScrollingFeature` | 48.8 kB / 17.0 kB |
192
- | `VGrid` + `columnVisibilityFeature` | 43.2 kB / 14.8 kB |
193
- | `VGrid` + `keyboardNavigationFeature` | 45.8 kB / 15.8 kB |
194
- | `VGrid` + `columnResizingFeature` | 46.3 kB / 16.0 kB |
195
- | `VGrid` + `columnGroupsFeature` | 44.4 kB / 15.2 kB |
196
- | `VGrid` + `rowPinningFeature` | 48.0 kB / 16.1 kB |
197
- | `VGrid` + `aggregationFeature` | 48.2 kB / 16.2 kB |
198
- | `VGrid` + `rowGroupingFeature` | 53.8 kB / 18.3 kB |
199
- | `VGrid` + `exportFeature` | 48.0 kB / 16.7 kB |
200
- | `VGrid` + `statusBarFeature` | 45.5 kB / 15.7 kB |
201
- | `VGrid` + `serverGroupingFeature` | 46.2 kB / 15.9 kB |
202
- | `VGrid` + `allFeatures` + `VGridSearch` | 115.0 kB / 38.6 kB |
203
- | `VGrid` + `currencyRenderer` | 44.4 kB / 15.2 kB |
204
- | `VGrid` + `VGridPagination` + `VGridColumnMenu` | 50.3 kB / 17.2 kB |
182
+ | `VGrid` (no features) | 44.5 kB / 15.3 kB |
183
+ | `VGrid` + `sortingFeature` | 47.2 kB / 16.3 kB |
184
+ | `VGrid` + `filteringFeature` | 55.2 kB / 19.1 kB |
185
+ | `VGrid` + `serverDataFeature` | 45.9 kB / 15.9 kB |
186
+ | `VGrid` + `paginationFeature` | 44.6 kB / 15.3 kB |
187
+ | `VGrid` + `selectionFeature` | 48.6 kB / 16.7 kB |
188
+ | `VGrid` + `subGridsFeature` | 46.8 kB / 16.1 kB |
189
+ | `VGrid` + `menusFeature` | 55.7 kB / 19.1 kB |
190
+ | `VGrid` + `columnReorderFeature` | 48.1 kB / 16.5 kB |
191
+ | `VGrid` + `columnPinningFeature` | 47.4 kB / 16.3 kB |
192
+ | `VGrid` + `virtualScrollingFeature` | 50.2 kB / 17.5 kB |
193
+ | `VGrid` + `columnVisibilityFeature` | 44.6 kB / 15.3 kB |
194
+ | `VGrid` + `keyboardNavigationFeature` | 47.2 kB / 16.3 kB |
195
+ | `VGrid` + `columnResizingFeature` | 47.7 kB / 16.5 kB |
196
+ | `VGrid` + `columnGroupsFeature` | 45.8 kB / 15.7 kB |
197
+ | `VGrid` + `rowPinningFeature` | 49.4 kB / 16.6 kB |
198
+ | `VGrid` + `aggregationFeature` | 49.6 kB / 16.7 kB |
199
+ | `VGrid` + `rowGroupingFeature` | 55.3 kB / 18.8 kB |
200
+ | `VGrid` + `exportFeature` | 49.4 kB / 17.2 kB |
201
+ | `VGrid` + `statusBarFeature` | 46.9 kB / 16.2 kB |
202
+ | `VGrid` + `serverGroupingFeature` | 47.6 kB / 16.4 kB |
203
+ | `VGrid` + `editingFeature` | 48.8 kB / 17.0 kB |
204
+ | `VGrid` + `allFeatures` + `VGridSearch` | 123.4 kB / 41.7 kB |
205
+ | `VGrid` + `currencyRenderer` | 45.8 kB / 15.7 kB |
206
+ | `VGrid` + `VGridPagination` + `VGridColumnMenu` | 51.7 kB / 17.7 kB |
205
207
  | `sortRows` only | 0.7 kB / 0.4 kB |
206
208
  | `toCsv` only | 1.1 kB / 0.6 kB |
207
- | everything | 168.7 kB / 54.0 kB |
208
- | `validateGridConfig` (`@nocopypaste/vue-grid/agent`, never in an app bundle) | 72.9 kB / 19.8 kB |
209
+ | everything | 177.3 kB / 57.2 kB |
210
+ | `validateGridConfig` (`@nocopypaste/vue-grid/agent`, never in an app bundle) | 75.6 kB / 20.7 kB |
209
211
 
210
212
  With `filteringFeature`, the filter popover body and the filter-row editors are **on-demand
211
213
  chunks**: they load the first time a popover opens or `filter-row` is on. With
@@ -230,6 +232,8 @@ chunks that on-demand imports share with the entry, even when nothing uses them.
230
232
  | `columns` | `ColumnDef<T>[]` | — | See below. |
231
233
  | `rowKey` | `keyof T \| (row) => string \| number` | — | Stable unique id; all row state is keyed by it. |
232
234
  | `v-model:sort` | `{ key, dir: 'asc' \| 'desc' } \| null` | `null` | Header click cycles asc → desc → none. Needs `sortingFeature` for the header UI. |
235
+ | `multiSort` | `boolean` | `false` | Shift-click (Shift+Enter) a header to sort by it next; `v-model:sorts` holds every key. See [Sorting](#sorting). |
236
+ | `v-model:sorts` | `SortState[]` | `[]` | Every sort key, the first one first (with `multiSort`). `sort` follows its first key. |
233
237
  | `sortMode` | `'controlled' \| 'client'` | `'controlled'` | `controlled` only emits (server-side sorting). Ignored with `dataSource`. |
234
238
  | `v-model:filters` | `FilterState \| null` | `null` | `{ columns: Record<key, ColumnFilter>, search }`. Needs `filteringFeature` (as do the next four). See [Filtering](#filtering). |
235
239
  | `filterMode` | `'client' \| 'controlled'` | `'client'` | `controlled` only emits (server-side filtering). Ignored with `dataSource`. |
@@ -272,6 +276,7 @@ chunks that on-demand imports share with the entry, even when nothing uses them.
272
276
  | `emptyText` | `string` | `messages.empty` | Shown when there are no rows (`No data to show.`). |
273
277
  | `ariaLabel` | `string` | — | |
274
278
  | `statusBar` | `boolean \| StatusBarOptions` | `false` | A status bar under the grid (status bar feature): counts, and `{ summary: [keys] }` sums of the selected rows. See [Status bar](#status-bar). |
279
+ | `saveCell` | `(event: CellEditEvent) => unknown` | — | Saves an edited cell (editing feature): return a Promise and the cell shows it saving; a rejection keeps the editor open with its message. See [Inline editing](#inline-editing). |
275
280
  | `messages` | `GridMessages` | — | Built-in text (translations, wording), over `createVueGrid({ messages })`. See [Text and parts](#text-and-parts). |
276
281
  | `parts` | `GridParts` | — | Built-in parts to leave out (`{ filterButtons: false }`), over `createVueGrid({ parts })`. |
277
282
  | `contextMenu` | `(ctx: { row, rowKey, column, value }) => MenuItem[] \| null` | — | Right-click menu for body cells. Needs `menusFeature`. |
@@ -285,6 +290,7 @@ chunks that on-demand imports share with the entry, even when nothing uses them.
285
290
  `query-change(query: GridQuery)` (sort + filters + page as one object, on mount and on every real change) ·
286
291
  `copy({ kind, text, rows, columns })` (rows or a cell were copied: `exportFeature`) ·
287
292
  `load-error(error)` (a `dataSource` call failed) ·
293
+ `cell-edit({ row, rowKey, column, value, oldValue })` (an edited cell: `editingFeature`; update your data) ·
288
294
  plus the `update:*` events of every `v-model`.
289
295
 
290
296
  Clicks on links, buttons and inputs inside a cell never trigger `row-click`.
@@ -311,6 +317,7 @@ grid.value?.clearSelection() // selectionFeature: clears the selection, "all mat
311
317
  grid.value?.reloadSubRows('c2') // forget lazily loaded children (of one row, or all): they load again
312
318
  grid.value?.pinRow(42, 'top') // pin a row above the body ('bottom' below it, null to unpin): rowPinningFeature
313
319
  grid.value?.exportCsv({ filename: 'orders.csv' }) / getCsv() / copyRows() // exportFeature, see Export and copy
320
+ grid.value?.startEdit(42, 'stake') / stopEdit() // editingFeature: open a cell's editor; save (or stopEdit(true): drop) the open one
314
321
  ```
315
322
 
316
323
  `reload()` also forgets lazily loaded children, as does passing a different `load-sub-rows`
@@ -375,6 +382,10 @@ animate on the compositor (GPU): a busy live feed costs the main thread about a
375
382
  groupValue?: (row) => unknown // what rows are grouped by (default: the cell value), e.g. the month of a date
376
383
  exportValue?: (row) => unknown // what CSV exports and copying use (exportFeature), e.g. an id instead of a link
377
384
  exportable?: boolean // in exports and copied rows (default true); false for action columns
385
+ editable?: boolean | ((row) => boolean) // edit cells in place (editingFeature)
386
+ editor?: 'text' | 'number' | 'date' | 'datetime' | 'select' | 'checkbox' | Component // default from the renderer
387
+ editorOptions?: { options?, min?, max?, placeholder?, maxLength? } // a select's choices, a number's range…
388
+ validate?: (value, row) => string | void // an error message keeps the editor open
378
389
  cellClass?: ClassValue | ((row) => ClassValue); headerClass?: ClassValue
379
390
  }
380
391
  ```
@@ -502,7 +513,7 @@ typeahead move through items; focus returns to the cell on close.
502
513
  ### Column headers
503
514
 
504
515
  Right-clicking a header opens a built-in menu: **Sort ascending / descending / Clear sort** (sortable
505
- columns), **Pin left / Pin right / Unpin**, **Move left / right**, **Hide column**, **Reset columns**.
516
+ columns; with `multi-sort` also **Then sort ascending / descending**, and Clear sort drops only that column), **Pin left / Pin right / Unpin**, **Move left / right**, **Hide column**, **Reset columns**.
506
517
  Pin items need `columnPinningFeature`, move items `columnReorderFeature`, Hide column `columnVisibilityFeature`. Runtime pins are stored in column state (`columnState.pinned`) and persisted with `storage`.
507
518
 
508
519
  ```vue
@@ -529,6 +540,47 @@ The same component powers the `actions-menu` renderer and is exported for add-on
529
540
  <!-- or imperatively: menuRef.value.openAt(element | { x, y }) -->
530
541
  ```
531
542
 
543
+ ## Sorting
544
+
545
+ A `sortable` column (with `sortingFeature`) sorts on a header click: ascending, descending, none.
546
+ `v-model:sort` holds `{ key, dir }`. The grid sorts the rows itself with `sort-mode="client"`;
547
+ otherwise it only updates `sort` (or asks the `dataSource`). Values sort by type (numbers, dates,
548
+ text with `localeCompare`), a renderer can define its sort value, and a column can override it with
549
+ `sortValue: (row) => …` or `sortFn: (a, b) => …`. Empty values sort last in both directions.
550
+
551
+ **Several columns.** With `multi-sort`, Shift-click a header (Shift+Enter on a focused one) to sort
552
+ by it after the others: ascending, then descending, then removed. A plain click still sorts by that
553
+ column alone. The headers show each column's number (1, 2, …); `aria-sort` stays on the first key, as
554
+ the ARIA grid pattern has it, and screen readers hear the rest as “sorted 2 of 3, descending”. The
555
+ header menu adds **Then sort ascending / descending**.
556
+
557
+ ```vue
558
+ <script setup lang="ts">
559
+ import { VGrid, sortingFeature, type SortState } from '@nocopypaste/vue-grid'
560
+ const sorts = ref<SortState[]>([
561
+ { key: 'city', dir: 'asc' },
562
+ { key: 'stake', dir: 'desc' },
563
+ ])
564
+ </script>
565
+
566
+ <template>
567
+ <VGrid
568
+ v-model:sorts="sorts"
569
+ multi-sort
570
+ sort-mode="client"
571
+ :rows
572
+ :columns
573
+ row-key="id"
574
+ :features="[sortingFeature]"
575
+ />
576
+ </template>
577
+ ```
578
+
579
+ `v-model:sort` keeps working beside it: it is the first key, and setting it from outside makes it
580
+ the only one. A `dataSource` gets every key in `query.sorts` (only with `multi-sort`; `query.sort`
581
+ is still the first). Row groups follow their own column's key wherever it is in the list.
582
+ `sortRowsBy(rows, keys)` and `nextSorts(sorts, key)` sort and cycle without a grid.
583
+
532
584
  ## Filtering
533
585
 
534
586
  ```vue
@@ -674,7 +726,7 @@ import {
674
726
  } from '@nocopypaste/vue-grid'
675
727
 
676
728
  const fetchBets: DataSource<Bet> = async (query, { signal }) => {
677
- // query: { sort: { key, dir } | null, filters: FilterState, page: number, pageSize: number | null }
729
+ // query: { sort: { key, dir } | null, sorts?: SortState[] (multi-sort), filters: FilterState, page: number, pageSize: number | null }
678
730
  const res = await fetch('/api/bets', { method: 'POST', body: JSON.stringify(query), signal })
679
731
  if (!res.ok) throw new Error(res.statusText)
680
732
  return res.json() // { rows: Bet[], total?: number }
@@ -1028,6 +1080,65 @@ await grid.value?.print({ title: 'Orders', totals: true, landscape: true })
1028
1080
  (a heading, also the document title) and `landscape`.
1029
1081
  - It resolves when printing is over. The printing code (1.1 kB gzip) loads on first use.
1030
1082
 
1083
+ ## Inline editing
1084
+
1085
+ `editingFeature` edits cells in place. Mark columns `editable` (or `(row) => boolean`). A cell opens
1086
+ its editor on double-click, on Enter or F2 when focused, or when you start typing on it (the
1087
+ keys replace the value). **Enter** saves, **Tab** / **Shift+Tab** save and edit the next / previous
1088
+ editable cell, **Esc** cancels, and clicking elsewhere saves.
1089
+
1090
+ The editor follows the column's renderer: numbers and money → a number input, `date` → a date
1091
+ picker, `datetime` → date and time, `boolean` → it flips at once (no editor), `status` / `chip`
1092
+ → a select of the column's values, anything else → text. `editor` picks another, or your own
1093
+ component (`CellEditorProps`: `v-model`, emit `commit` / `cancel`; Enter, Tab and Esc work around it).
1094
+
1095
+ The grid never changes your rows: it emits `cell-edit` with the typed `value` (a number, a date
1096
+ string in the cell's own format, a select's value) and `oldValue`, and your handler stores it.
1097
+ `setCellValue(row, column, value)` writes along the column's `field` path.
1098
+
1099
+ ```vue
1100
+ <script setup lang="ts">
1101
+ import { VGrid, editingFeature, setCellValue, type CellEditEvent } from '@nocopypaste/vue-grid'
1102
+
1103
+ const rows = reactive(await loadBets())
1104
+ const columns = [
1105
+ col({
1106
+ key: 'player',
1107
+ field: 'player.name',
1108
+ editable: true,
1109
+ validate: (v) => (String(v).trim() ? undefined : 'A player needs a name.'),
1110
+ }),
1111
+ col({ key: 'stake', renderer: currencyRenderer, editable: true, editorOptions: { min: 0 } }),
1112
+ col({
1113
+ key: 'status',
1114
+ renderer: statusRenderer,
1115
+ editable: (bet) => bet.status !== 'Void',
1116
+ editorOptions: { options: ['Open', 'Won', 'Lost', 'Void'] },
1117
+ }),
1118
+ col({ key: 'verified', renderer: booleanRenderer, editable: true }),
1119
+ ]
1120
+
1121
+ // optional: an async save. The cell shows it saving; a rejection keeps the editor open with the message.
1122
+ async function saveCell(e: CellEditEvent<Bet>) {
1123
+ await api.patch(`/bets/${e.rowKey}`, { [e.column.key]: e.value }) // throws on a 4xx
1124
+ setCellValue(e.row, e.column, e.value)
1125
+ }
1126
+ </script>
1127
+
1128
+ <template>
1129
+ <VGrid :rows :columns row-key="id" :save-cell="saveCell" :features="[editingFeature]" />
1130
+ <!-- or without a save function: @cell-edit="(e) => setCellValue(e.row, e.column, e.value)" -->
1131
+ </template>
1132
+ ```
1133
+
1134
+ `validate` returns a message to keep the editor open with it (shown below the cell, and as the
1135
+ input's description for screen readers); a number outside `min` / `max` or not a number is refused
1136
+ the same way. One cell edits at a time. With `keyboardNavigationFeature` cells take focus, so typing
1137
+ and Enter / F2 work; without it, double-click. Pinned rows and group rows aren't editable. The
1138
+ editor's code loads on demand, while the browser is idle, once a grid has an editable column.
1139
+ `grid.startEdit(rowKey, columnKey)` opens an editor from code, `grid.stopEdit()` closes it. Its
1140
+ text (`Edit {column}`, `Enter a number.`, `Saving…`) is in `messages`.
1141
+
1031
1142
  ## Status bar
1032
1143
 
1033
1144
  `statusBarFeature` adds a bar under the grid, like a spreadsheet's:
@@ -1144,7 +1255,7 @@ and the grid's own controls (sort buttons, expanders, checkboxes, filter buttons
1144
1255
  normal Tab order.
1145
1256
 
1146
1257
  With `keyboardNavigationFeature` it is an ARIA `grid` (`treegrid` with sub-grids). The grid is one tab stop. Arrow keys move between cells (header, rows, sub-grid rows, detail rows),
1147
- `Home`/`End`, `Ctrl+Home`/`Ctrl+End`, `PageUp`/`PageDown`; `ContextMenu` / `Shift+F10` opens the context menu. `Enter` sorts a header or activates the
1258
+ `Home`/`End`, `Ctrl+Home`/`Ctrl+End`, `PageUp`/`PageDown`; `ContextMenu` / `Shift+F10` opens the context menu. `Enter` sorts a header (`Shift+Enter` adds it with `multi-sort`) or activates the
1148
1259
  cell's control; `Space` toggles row selection; `→`/`←` on a tree cell expands/collapses; `Alt+←/→` on a
1149
1260
  header moves the column; `Alt+Shift+←/→` on a header resizes it (with `columnResizingFeature`).
1150
1261
 
package/agent/api.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@nocopypaste/vue-grid",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "component": "VGrid",
5
5
  "props": [
6
6
  {
@@ -50,6 +50,13 @@
50
50
  "description": "A status bar under the grid (status bar feature): rows that pass the filters (\"84 of 200 rows\"), selected rows, active filters with Clear; `{ summary: ['total'] }` adds the sum and average of those columns over the selected rows. `#status-bar` replaces its content.",
51
51
  "feature": "statusBar"
52
52
  },
53
+ {
54
+ "name": "saveCell",
55
+ "type": "(event: CellEditEvent<T>) => unknown",
56
+ "required": false,
57
+ "description": "Saves an edited cell (editing feature), after `cell-edit`: return a Promise and the cell shows it saving; a rejection keeps the editor open with the error's message. Without it, `cell-edit` alone carries the change.",
58
+ "feature": "editing"
59
+ },
53
60
  {
54
61
  "name": "messages",
55
62
  "type": "GridMessages",
@@ -317,6 +324,13 @@
317
324
  "default": "false",
318
325
  "description": "Groups start expanded (row grouping feature). Default: collapsed.",
319
326
  "feature": "rowGrouping"
327
+ },
328
+ {
329
+ "name": "multiSort",
330
+ "type": "boolean",
331
+ "required": false,
332
+ "description": "Multi-column sort (sorting feature): Shift-click (or Shift+Enter) on a header adds it as the next key, Shift-click again turns it descending, then removes it. `v-model:sorts` holds every key, `v-model:sort` the first; server queries get `sorts` too.",
333
+ "feature": "sorting"
320
334
  }
321
335
  ],
322
336
  "models": [
@@ -326,6 +340,13 @@
326
340
  "default": "null",
327
341
  "description": "Sort state: a header click cycles asc → desc → none. Header UI needs the sorting feature."
328
342
  },
343
+ {
344
+ "name": "sorts",
345
+ "type": "SortState[]",
346
+ "default": "[]",
347
+ "description": "Every sort key, the first one first (`multi-sort`). `sort` is the first of them.",
348
+ "feature": "sorting"
349
+ },
329
350
  {
330
351
  "name": "columnState",
331
352
  "type": "ColumnState | undefined",
@@ -421,6 +442,11 @@
421
442
  "payload": "[event: CellActionEvent<T>]",
422
443
  "description": "A renderer emitted an action (buttons, toggles, menus, edit, copy)."
423
444
  },
445
+ {
446
+ "name": "cell-edit",
447
+ "payload": "[event: CellEditEvent<T>]",
448
+ "description": "A cell was edited (editing feature): update your data with `value`. The grid doesn't."
449
+ },
424
450
  {
425
451
  "name": "sub-rows-error",
426
452
  "payload": "[event: { row: T; error: unknown }]",
@@ -628,6 +654,18 @@
628
654
  "type": "Promise<boolean>",
629
655
  "required": true,
630
656
  "description": "Copies rows to the clipboard as tab-separated text (pastes as cells into spreadsheets): the selected rows by default, as displayed, no header. Resolves `false` if nothing was copied. Export feature."
657
+ },
658
+ {
659
+ "name": "startEdit",
660
+ "type": "boolean",
661
+ "required": true,
662
+ "description": "Opens the editor of a cell (editing feature), if the column is `editable` for that row and the row is on screen. Returns whether it opened."
663
+ },
664
+ {
665
+ "name": "stopEdit",
666
+ "type": "void",
667
+ "required": true,
668
+ "description": "Closes the open editor: saves its value, or with `cancel` drops it. Editing feature."
631
669
  }
632
670
  ],
633
671
  "column": [
@@ -857,6 +895,34 @@
857
895
  "description": "Included in CSV exports and copied rows (export feature)? Default `true`; set `false` on action columns.",
858
896
  "feature": "export"
859
897
  },
898
+ {
899
+ "name": "editable",
900
+ "type": "boolean | ((row: T) => boolean)",
901
+ "required": false,
902
+ "description": "Cells can be edited in place (editing feature): `true`, or per row. Double-click, Enter or F2 on a focused cell, or typing, opens the editor; the grid emits `cell-edit` and your handler updates the data (the grid never changes rows itself).",
903
+ "feature": "editing"
904
+ },
905
+ {
906
+ "name": "editor",
907
+ "type": "EditorName | Component",
908
+ "required": false,
909
+ "description": "The editor (editing feature): `text`, `number`, `date`, `datetime`, `select`, `checkbox`, or your own component (`CellEditorProps`). Default from the renderer: numbers and money → number, dates → date, booleans → checkbox, status / chip → select, else text.",
910
+ "feature": "editing"
911
+ },
912
+ {
913
+ "name": "editorOptions",
914
+ "type": "EditorOptions",
915
+ "required": false,
916
+ "description": "Options of the editor: the choices of a select, a number's `min` / `max`, a `placeholder`.",
917
+ "feature": "editing"
918
+ },
919
+ {
920
+ "name": "validate",
921
+ "type": "(value: unknown, row: T) => string | null | undefined | void",
922
+ "required": false,
923
+ "description": "Checks an edited value before it is saved (editing feature): return an error message to keep the editor open with it, or nothing to accept the value.",
924
+ "feature": "editing"
925
+ },
860
926
  {
861
927
  "name": "cellClass",
862
928
  "type": "ClassValue | ((row: T) => ClassValue)",
@@ -934,6 +1000,20 @@
934
1000
  "hideable"
935
1001
  ]
936
1002
  },
1003
+ {
1004
+ "id": "editing",
1005
+ "export": "editingFeature",
1006
+ "description": "",
1007
+ "props": [
1008
+ "saveCell"
1009
+ ],
1010
+ "columnOptions": [
1011
+ "editable",
1012
+ "editor",
1013
+ "editorOptions",
1014
+ "validate"
1015
+ ]
1016
+ },
937
1017
  {
938
1018
  "id": "export",
939
1019
  "export": "exportFeature",
@@ -1052,7 +1132,10 @@
1052
1132
  "id": "sorting",
1053
1133
  "export": "sortingFeature",
1054
1134
  "description": "Sorting: the sort button on `sortable` column headers, the sort items of the header menu and, with `sort-mode=\"client\"`, sorting the rows in the browser.",
1055
- "props": [],
1135
+ "props": [
1136
+ "multiSort",
1137
+ "sorts"
1138
+ ],
1056
1139
  "columnOptions": [
1057
1140
  "sortable",
1058
1141
  "sortValue",