@svgrid/grid 3.0.4 → 3.0.6

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 (176) hide show
  1. package/README.md +32 -11
  2. package/dist/GridMenus.svelte +34 -4
  3. package/dist/SvGrid.controller.svelte.d.ts +33 -5
  4. package/dist/SvGrid.controller.svelte.js +397 -58
  5. package/dist/SvGrid.css +200 -2
  6. package/dist/SvGrid.svelte +350 -40
  7. package/dist/SvGrid.types.d.ts +433 -7
  8. package/dist/SvGridDropdown.svelte +20 -0
  9. package/dist/SvGridDropdown.svelte.d.ts +12 -0
  10. package/dist/SvModal.svelte +22 -0
  11. package/dist/SvModal.svelte.d.ts +7 -0
  12. package/dist/a11y/dismissable.d.ts +10 -0
  13. package/dist/a11y/dismissable.js +24 -2
  14. package/dist/build-api.js +92 -37
  15. package/dist/cdn/{GridMenus-BL7ZgQvU.js → GridMenus-C-NtjlrJ.js} +155 -146
  16. package/dist/cdn/GridMenus-TssHej3q.js +644 -0
  17. package/dist/cdn/{SvChartMenu-FBSMINA6.js → SvChartMenu-BFSTpvB-.js} +1 -1
  18. package/dist/cdn/{SvChartMenu-Bl6PBbkT.js → SvChartMenu-BZ1Iwv0y.js} +1 -1
  19. package/dist/cdn/{SvDateTimePicker-DQwt4UAs.js → SvDateTimePicker-D9u_cOf8.js} +1 -1
  20. package/dist/cdn/{SvDateTimePicker-vNU6bZ-q.js → SvDateTimePicker-s_6IUpI7.js} +1 -1
  21. package/dist/cdn/{SvGridCellEditor-B1p-vCK5.js → SvGridCellEditor-BlyCSp0q.js} +1 -1
  22. package/dist/cdn/{SvGridCellEditor-D_0q4xAu.js → SvGridCellEditor-ClRRA9lW.js} +1 -1
  23. package/dist/cdn/{SvGridChart-DzLkSwCH.js → SvGridChart-B4EV8U6t.js} +4 -4
  24. package/dist/cdn/{SvGridChart-C3EWAZaM.js → SvGridChart-DsmwTyZF.js} +4 -4
  25. package/dist/cdn/{SvGridChartBuilder-CfII62sZ.js → SvGridChartBuilder-cHloHobN.js} +4 -4
  26. package/dist/cdn/{SvGridChartBuilder-BE2T1ykB.js → SvGridChartBuilder-vOl7C0Za.js} +4 -4
  27. package/dist/cdn/{SvGridChartPanel-xf4sWVTo.js → SvGridChartPanel-AcqF-Ll5.js} +5 -5
  28. package/dist/cdn/{SvGridChartPanel-CCX5_Wgd.js → SvGridChartPanel-biMtSBPA.js} +5 -5
  29. package/dist/cdn/{SvGridChartView-DYwabQWj.js → SvGridChartView-Dx_GmZuL.js} +2 -2
  30. package/dist/cdn/{SvGridChartView-CfuXmY5I.js → SvGridChartView-I3rDHXAq.js} +2 -2
  31. package/dist/cdn/{SvGridDropdown-D0VdjeR8.js → SvGridDropdown-BWeM3lMe.js} +46 -46
  32. package/dist/cdn/{SvGridDropdown-D13MtJ2j.js → SvGridDropdown-CJ6QqTxu.js} +67 -67
  33. package/dist/cdn/{SvModal-CIZWCcad.js → SvModal-ClxGmpAc.js} +187 -186
  34. package/dist/cdn/{SvModal-BAE-pjZX.js → SvModal-DhB_VMFR.js} +148 -147
  35. package/dist/cdn/{cell-formatting-C2Hf5gqd.js → cell-formatting-DVVKOSI9.js} +1 -1
  36. package/dist/cdn/{chart-Dz7SqMXH.js → chart-DEZxwC0i.js} +1 -1
  37. package/dist/cdn/{chart-panel-messages-CUbf2R4i.js → chart-panel-messages-D12XcTZJ.js} +1 -1
  38. package/dist/cdn/{chart-panel-messages-CmNrMdsr.js → chart-panel-messages-DguS7gC5.js} +1 -1
  39. package/dist/cdn/{chart-summary-BJW_tg_X.js → chart-summary-CMAXBGY-.js} +1 -1
  40. package/dist/cdn/{chart-trend-CaN9mDEV.js → chart-trend-BkEp61Gj.js} +1 -1
  41. package/dist/cdn/{dismissable-DAHetSNk.js → dismissable-Brc4EZU1.js} +5 -1
  42. package/dist/cdn/{export-format-CUDLy2yn.js → export-format-YzdwBww2.js} +1 -1
  43. package/dist/cdn/{row-resize-niQCp040.js → row-resize-DtOS1KG6.js} +41 -32
  44. package/dist/cdn/server-block-cache-DIqb3VZn.js +241 -0
  45. package/dist/cdn/{src-V1uu8iE9.js → src-CgoeSM8k.js} +5339 -4753
  46. package/dist/cdn/{src-BKhZ6eXd.js → src-DfwxB1TH.js} +9817 -9231
  47. package/dist/cdn/svgrid.js +28 -27
  48. package/dist/cdn/svgrid.svelte-external.js +28 -27
  49. package/dist/cdn/validate-AZoD8BoR.js +80 -0
  50. package/dist/cell-formatting.js +18 -1
  51. package/dist/cell-render.js +25 -6
  52. package/dist/clipboard.d.ts +2 -2
  53. package/dist/clipboard.js +72 -23
  54. package/dist/columns.js +7 -2
  55. package/dist/conditional-formatting.d.ts +2 -0
  56. package/dist/conditional-formatting.js +2 -0
  57. package/dist/core.d.ts +22 -6
  58. package/dist/core.js +401 -38
  59. package/dist/editing.js +34 -0
  60. package/dist/gantt-view.svelte.d.ts +24 -0
  61. package/dist/gantt-view.svelte.js +13 -0
  62. package/dist/grid-icons.d.ts +2 -2
  63. package/dist/grid-icons.js +2 -2
  64. package/dist/grid-messages.d.ts +10 -0
  65. package/dist/grid-messages.js +9 -0
  66. package/dist/headless.d.ts +5 -0
  67. package/dist/headless.js +12 -0
  68. package/dist/history.d.ts +21 -0
  69. package/dist/history.js +34 -4
  70. package/dist/index.d.ts +5 -4
  71. package/dist/index.js +3 -3
  72. package/dist/keyboard-handlers.js +24 -1
  73. package/dist/keyboard.js +4 -0
  74. package/dist/row-drag-touch.d.ts +1 -1
  75. package/dist/row-drag.js +35 -1
  76. package/dist/row-model.d.ts +139 -0
  77. package/dist/row-model.js +16 -0
  78. package/dist/row-resize.js +22 -1
  79. package/dist/selection.d.ts +2 -1
  80. package/dist/selection.js +31 -3
  81. package/dist/server-block-cache.d.ts +219 -0
  82. package/dist/server-block-cache.js +539 -0
  83. package/dist/server-data-source.d.ts +274 -8
  84. package/dist/server-data-source.js +229 -20
  85. package/dist/server.d.ts +13 -0
  86. package/dist/server.js +13 -0
  87. package/dist/sparkline.js +7 -5
  88. package/dist/svgrid-wrapper.types.d.ts +33 -0
  89. package/dist/validate.d.ts +4 -0
  90. package/dist/validate.js +29 -3
  91. package/package.json +11 -1
  92. package/src/GridMenus.svelte +34 -4
  93. package/src/SvGrid.controller.svelte.ts +397 -61
  94. package/src/SvGrid.css +200 -2
  95. package/src/SvGrid.svelte +350 -40
  96. package/src/SvGrid.types.ts +453 -7
  97. package/src/SvGridDropdown.svelte +20 -0
  98. package/src/SvModal.svelte +22 -0
  99. package/src/SvModal.test.ts +30 -1
  100. package/src/a11y/dismissable.test.ts +10 -1
  101. package/src/a11y/dismissable.ts +22 -2
  102. package/src/build-api.ts +96 -31
  103. package/src/cell-formatting.test.ts +17 -0
  104. package/src/cell-formatting.ts +18 -1
  105. package/src/cell-render.test.ts +24 -2
  106. package/src/cell-render.ts +24 -8
  107. package/src/clipboard.test.ts +107 -0
  108. package/src/clipboard.ts +62 -23
  109. package/src/columns.test.ts +4 -4
  110. package/src/columns.ts +7 -2
  111. package/src/conditional-formatting.test.ts +8 -0
  112. package/src/conditional-formatting.ts +3 -0
  113. package/src/core.rowmodel-cache.test.ts +51 -0
  114. package/src/core.tick-repair.test.ts +287 -0
  115. package/src/core.ts +407 -38
  116. package/src/editing.test.ts +52 -0
  117. package/src/editing.ts +33 -0
  118. package/src/gantt-stub.test.svelte +38 -0
  119. package/src/gantt-view.svelte.ts +35 -0
  120. package/src/grid-icons.ts +2 -2
  121. package/src/grid-messages.test.ts +7 -0
  122. package/src/grid-messages.ts +22 -0
  123. package/src/headless.ts +24 -0
  124. package/src/history.test.ts +49 -1
  125. package/src/history.ts +48 -2
  126. package/src/icon-seam.test.ts +2 -4
  127. package/src/index.ts +38 -10
  128. package/src/keyboard-handlers.coverage.test.ts +65 -0
  129. package/src/keyboard-handlers.ts +26 -1
  130. package/src/keyboard.ts +3 -0
  131. package/src/row-drag-touch.ts +2 -2
  132. package/src/row-drag.test.ts +51 -0
  133. package/src/row-drag.ts +35 -2
  134. package/src/row-model.ts +152 -0
  135. package/src/row-resize.ts +24 -1
  136. package/src/selection.test.ts +3 -0
  137. package/src/selection.ts +33 -3
  138. package/src/server-block-cache.test.ts +672 -0
  139. package/src/server-block-cache.ts +690 -0
  140. package/src/server-data-source.infinite.test.ts +405 -0
  141. package/src/server-data-source.test.ts +19 -0
  142. package/src/server-data-source.ts +496 -29
  143. package/src/server.ts +49 -0
  144. package/src/sparkline.test.ts +7 -0
  145. package/src/sparkline.ts +6 -4
  146. package/src/svgrid-wrapper.types.ts +32 -0
  147. package/src/svgrid.api.test.ts +21 -0
  148. package/src/svgrid.charting.test.ts +12 -4
  149. package/src/svgrid.context-menu.test.ts +12 -0
  150. package/src/svgrid.detail-rows.svelte.test.ts +187 -0
  151. package/src/svgrid.filter-menu-scroll.test.ts +9 -0
  152. package/src/svgrid.gantt-seam.test.ts +199 -0
  153. package/src/svgrid.live-update-paths.svelte.test.ts +184 -0
  154. package/src/svgrid.menu-scroll-close.test.ts +10 -0
  155. package/src/svgrid.row-model-prop.svelte.test.ts +352 -0
  156. package/src/svgrid.row-model-seam.svelte.test.ts +305 -0
  157. package/src/svgrid.row-pinning.test.ts +15 -1
  158. package/src/svgrid.selection-bar-seam.test.ts +1 -1
  159. package/src/svgrid.sticky-groups.svelte.test.ts +145 -0
  160. package/src/svgrid.upsell-license.test.ts +8 -5
  161. package/src/test-setup.ts +12 -0
  162. package/src/transaction.test.ts +58 -0
  163. package/src/validate.test.ts +29 -0
  164. package/src/validate.ts +34 -3
  165. package/dist/SvGroupCell.svelte +0 -141
  166. package/dist/SvGroupCell.svelte.d.ts +0 -49
  167. package/dist/SvRowGroupPanel.svelte +0 -186
  168. package/dist/SvRowGroupPanel.svelte.d.ts +0 -25
  169. package/dist/cdn/GridMenus-7kbpnnBW.js +0 -635
  170. package/dist/cdn/validate-_CDJzgIo.js +0 -75
  171. package/dist/server-group-model.d.ts +0 -98
  172. package/dist/server-group-model.js +0 -263
  173. package/src/SvGroupCell.svelte +0 -141
  174. package/src/SvRowGroupPanel.svelte +0 -186
  175. package/src/server-group-model.test.ts +0 -294
  176. package/src/server-group-model.ts +0 -370
package/src/validate.ts CHANGED
@@ -20,6 +20,7 @@
20
20
  * changes, and must not scale with row count.
21
21
  */
22
22
  import type { ColumnDef, RowData, TableFeatures } from './core'
23
+ import { rowPlaceholderState } from './server-block-cache'
23
24
 
24
25
  /** How many rows to sample when deciding whether a `field` exists. */
25
26
  const FIELD_SAMPLE_ROWS = 10
@@ -37,6 +38,10 @@ export type ValidateInput<TFeatures extends TableFeatures, TData extends RowData
37
38
  pageSize?: number
38
39
  groupBy?: ReadonlyArray<string>
39
40
  treeData?: { parentField?: string; idField?: string; column?: string }
41
+ /** Gantt mode. Only its presence matters here - see rule 6b. */
42
+ gantt?: unknown
43
+ /** Server-side grouping: group rows carry their key and aggregates, not the leaf fields. */
44
+ serverGroup?: unknown
40
45
  initialColumnPinning?: { left?: ReadonlyArray<string>; right?: ReadonlyArray<string> }
41
46
  columnVirtualization?: boolean
42
47
  externalPagination?: boolean
@@ -69,9 +74,19 @@ export function validateGridConfig<
69
74
  // ---- 1. A `field` that does not exist on the data -------------------------
70
75
  // The single most expensive silent failure: the column renders, and every
71
76
  // cell in it is blank. Sampled across several rows so genuinely sparse data
72
- // (a key absent from row 0 but present later) does not trip it.
73
- const sample = (input.data ?? []).slice(0, FIELD_SAMPLE_ROWS)
74
- if (sample.length) {
77
+ // (a key absent from row 0 but present later) does not trip it. A row
78
+ // model shows placeholder rows before its first block lands; those carry
79
+ // no data keys at all and say nothing about the columns.
80
+ // Stops at the sample size: this runs on every data change, and a filter
81
+ // over all the rows first was O(n) per tick on a live feed.
82
+ const sample: TData[] = []
83
+ for (const row of input.data ?? []) {
84
+ if (sample.length >= FIELD_SAMPLE_ROWS) break
85
+ if (!rowPlaceholderState(row)) sample.push(row)
86
+ }
87
+ // Under server-side grouping the first rows are group rows, which carry
88
+ // a key and aggregates and none of the leaf fields; nothing to judge by.
89
+ if (sample.length && !input.serverGroup) {
75
90
  const known = new Set<string>()
76
91
  for (const row of sample) {
77
92
  if (row && typeof row === 'object') for (const k of Object.keys(row)) known.add(k)
@@ -189,6 +204,22 @@ export function validateGridConfig<
189
204
  }
190
205
  }
191
206
 
207
+ // ---- 6b. gantt + treeData: two trees over one set of rows -----------------
208
+ // The Gantt builds its own work-breakdown tree from `gantt.parentField`,
209
+ // because it needs every descendant - a collapsed phase still contributes to
210
+ // its summary bar. `treeData` hides collapsed children from the view before
211
+ // the renderer sees them, so the two together silently drop tasks out of
212
+ // their phase's rollup the moment anything is collapsed.
213
+ if (input.gantt && input.treeData) {
214
+ messages.push(
215
+ '[svgrid] `gantt` and `treeData` are both set. The Gantt builds its own ' +
216
+ 'work-breakdown tree from `gantt.parentField` and needs every ' +
217
+ 'descendant row, but `treeData` hides collapsed children from the view, ' +
218
+ 'so summary bars will under-report. Remove `treeData` and set ' +
219
+ '`gantt.parentField` instead.',
220
+ )
221
+ }
222
+
192
223
  // ---- 7. Pinning that column virtualization will hide ----------------------
193
224
  // Documented incompatibility: the virtualizer recycles column DOM nodes, so
194
225
  // sticky pinning cannot survive it. `columnVirtualization` defaults to ON,
@@ -1,141 +0,0 @@
1
- <!--
2
- Built-in group cell for the server-side group/tree model. Drop it into the
3
- grouping column and it draws the expander + indentation for group rows (and an
4
- indented leaf value) - no hand-written cell recipe. Pair with `serverGroupRows`
5
- to feed `<SvGrid data>`, and wire `onToggle` to the controller's `toggleGroup`.
6
-
7
- cell: (ctx) => renderComponent(SvGroupCell, {
8
- row: ctx.row.original, onToggle: ctl.toggleGroup, leafField: 'name',
9
- })
10
- -->
11
- <script lang="ts" generics="TData">
12
- import type { ServerDisplayRow } from './server-data-source'
13
- import type { GridIcons } from './grid-icons'
14
-
15
- type GroupGridRow = { __group?: ServerDisplayRow<TData> } & Record<string, unknown>
16
- type Props = {
17
- /** The grid row from `serverGroupRows` (carries the `__group` marker). */
18
- row: GroupGridRow
19
- /**
20
- * Expand / collapse a group, or load more children. Receives the grid row;
21
- * wire to `serverGroupNav(ctl).onToggle` (which drives clicks and keyboard).
22
- */
23
- onToggle: (row: GroupGridRow) => void
24
- /** Field to show for leaf rows in the group column (blank if omitted). */
25
- leafField?: string
26
- /** Pixels of indentation per level. Default 18. */
27
- indent?: number
28
- /**
29
- * Icon overrides, the same map `<SvGrid icons>` takes. Only
30
- * `chevron-right` is drawn here. You mount this component yourself, so it
31
- * cannot inherit the grid's icons - pass the same object to both to keep
32
- * the expander consistent with the rest of the chrome.
33
- */
34
- icons?: GridIcons
35
- }
36
-
37
- let { row, onToggle, leafField, indent = 18, icons }: Props = $props()
38
- const chevron = $derived(icons?.['chevron-right'])
39
- const meta = $derived(row.__group)
40
- </script>
41
-
42
- {#if meta && meta.kind === 'group'}
43
- <button
44
- type="button"
45
- class="sv-group-cell"
46
- style={`padding-inline-start: ${meta.level * indent}px`}
47
- aria-expanded={meta.expanded}
48
- aria-label={meta.expanded ? 'Collapse group' : 'Expand group'}
49
- onclick={() => onToggle(row)}
50
- >
51
- <!-- Same chevron the grid's own expanders and SvTree draw, so every
52
- expander in the library looks identical. -->
53
- <span class="sv-group-chev" class:open={meta.expanded} aria-hidden="true">
54
- {#if chevron}
55
- {@render chevron()}
56
- {:else}
57
- <svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor"
58
- stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6" /></svg>
59
- {/if}
60
- </span>
61
- <span class="sv-group-key">{meta.key}</span>
62
- {#if meta.loading}<span class="sv-group-load" aria-hidden="true">…</span>{/if}
63
- </button>
64
- {:else if meta && meta.kind === 'more'}
65
- <button
66
- type="button"
67
- class="sv-group-more"
68
- style={`padding-inline-start: ${meta.level * indent}px`}
69
- disabled={meta.loading}
70
- onclick={() => onToggle(row)}
71
- >
72
- {meta.loading ? 'Loading...' : `Load ${meta.remaining} more`}
73
- </button>
74
- {:else if meta && meta.kind === 'footer'}
75
- <span class="sv-group-footer" style={`padding-inline-start: ${meta.level * indent}px`}>Total</span>
76
- {:else if meta && meta.kind === 'skeleton'}
77
- <span class="sv-group-skeleton" style={`margin-inline-start: ${meta.level * indent}px`} aria-hidden="true"></span>
78
- {:else if meta}
79
- <span class="sv-group-leaf" style={`padding-inline-start: ${(meta.level + 1) * indent}px`}>
80
- {leafField ? (row[leafField] ?? '') : ''}
81
- </span>
82
- {/if}
83
-
84
- <style>
85
- .sv-group-cell {
86
- display: inline-flex;
87
- align-items: center;
88
- gap: 6px;
89
- background: none;
90
- border: 0;
91
- padding: 0;
92
- font: inherit;
93
- color: inherit;
94
- cursor: pointer;
95
- }
96
- .sv-group-chev {
97
- display: inline-flex;
98
- align-items: center;
99
- justify-content: center;
100
- width: 12px;
101
- height: 12px;
102
- transition: transform 0.15s;
103
- color: var(--sg-muted, #64748b);
104
- }
105
- /* An `icons` override renders inside this wrapper, and this style block is
106
- scoped, so its markup needs :global() to be reached. Sizing it here means
107
- a custom chevron lands in the same box as the built-in and rotates with
108
- the wrapper rather than needing to know the rule exists. */
109
- .sv-group-chev :global(svg),
110
- .sv-group-chev :global(img) {
111
- width: 100%;
112
- height: 100%;
113
- display: block;
114
- }
115
- .sv-group-chev.open { transform: rotate(90deg); }
116
- .sv-group-key { font-weight: 600; }
117
- .sv-group-load { color: var(--sg-muted, #64748b); font-size: 12px; }
118
- .sv-group-leaf { color: var(--sg-muted, #475569); }
119
- .sv-group-more {
120
- background: none;
121
- border: 0;
122
- padding: 0;
123
- font: inherit;
124
- font-size: 13px;
125
- color: var(--sg-accent, #2563eb);
126
- cursor: pointer;
127
- }
128
- .sv-group-more:disabled { color: var(--sg-muted, #64748b); cursor: default; }
129
- .sv-group-footer { font-weight: 600; color: var(--sg-muted, #64748b); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
130
- .sv-group-skeleton {
131
- display: inline-block;
132
- width: 60%;
133
- height: 10px;
134
- border-radius: 5px;
135
- background: linear-gradient(90deg, var(--sg-border, #e2e8f0) 25%, var(--sg-header-bg, #f1f5f9) 50%, var(--sg-border, #e2e8f0) 75%);
136
- background-size: 200% 100%;
137
- animation: sv-group-shimmer 1.2s infinite;
138
- }
139
- @keyframes sv-group-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
140
- @media (prefers-reduced-motion: reduce) { .sv-group-skeleton { animation: none; } }
141
- </style>
@@ -1,49 +0,0 @@
1
- import type { ServerDisplayRow } from './server-data-source.js';
2
- import type { GridIcons } from './grid-icons.js';
3
- declare function $$render<TData>(): {
4
- props: {
5
- /** The grid row from `serverGroupRows` (carries the `__group` marker). */
6
- row: {
7
- __group?: ServerDisplayRow<TData>;
8
- } & Record<string, unknown>;
9
- /**
10
- * Expand / collapse a group, or load more children. Receives the grid row;
11
- * wire to `serverGroupNav(ctl).onToggle` (which drives clicks and keyboard).
12
- */
13
- onToggle: (row: {
14
- __group?: ServerDisplayRow<TData>;
15
- } & Record<string, unknown>) => void;
16
- /** Field to show for leaf rows in the group column (blank if omitted). */
17
- leafField?: string;
18
- /** Pixels of indentation per level. Default 18. */
19
- indent?: number;
20
- /**
21
- * Icon overrides, the same map `<SvGrid icons>` takes. Only
22
- * `chevron-right` is drawn here. You mount this component yourself, so it
23
- * cannot inherit the grid's icons - pass the same object to both to keep
24
- * the expander consistent with the rest of the chrome.
25
- */
26
- icons?: GridIcons;
27
- };
28
- exports: {};
29
- bindings: "";
30
- slots: {};
31
- events: {};
32
- };
33
- declare class __sveltets_Render<TData> {
34
- props(): ReturnType<typeof $$render<TData>>['props'];
35
- events(): ReturnType<typeof $$render<TData>>['events'];
36
- slots(): ReturnType<typeof $$render<TData>>['slots'];
37
- bindings(): "";
38
- exports(): {};
39
- }
40
- interface $$IsomorphicComponent {
41
- new <TData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData>['props']>, ReturnType<__sveltets_Render<TData>['events']>, ReturnType<__sveltets_Render<TData>['slots']>> & {
42
- $$bindings?: ReturnType<__sveltets_Render<TData>['bindings']>;
43
- } & ReturnType<__sveltets_Render<TData>['exports']>;
44
- <TData>(internal: unknown, props: ReturnType<__sveltets_Render<TData>['props']> & {}): ReturnType<__sveltets_Render<TData>['exports']>;
45
- z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
46
- }
47
- declare const SvGroupCell: $$IsomorphicComponent;
48
- type SvGroupCell<TData> = InstanceType<typeof SvGroupCell<TData>>;
49
- export default SvGroupCell;
@@ -1,186 +0,0 @@
1
- <!--
2
- A row-group panel (like the "drag columns to group" bar in enterprise grids).
3
- Shows the current group-by columns as chips you can remove or drag to reorder,
4
- plus a "+ Group by" menu to add one. It is also a drop target: a column drag
5
- that carries `text/sv-column` (its column id) adds that column. Wire `onChange`
6
- to a server group model's `setGroupBy`, or to client grouping.
7
-
8
- <SvRowGroupPanel
9
- columns={[{ id: 'region', label: 'Region' }, { id: 'country', label: 'Country' }]}
10
- groupBy={view.groupBy}
11
- onChange={(g) => ctl.setGroupBy(g)}
12
- />
13
- -->
14
- <script lang="ts">
15
- import { GRID_ICON_GLYPHS, type GridIconName, type GridIcons } from './grid-icons'
16
-
17
- type Col = { id: string; label: string }
18
- type Props = {
19
- /** Columns that can be grouped on. */
20
- columns: Col[]
21
- /** Current group-by column ids, outer to inner. */
22
- groupBy: string[]
23
- /** Called with the new group-by order. */
24
- onChange: (groupBy: string[]) => void
25
- /** Text shown when nothing is grouped. */
26
- placeholder?: string
27
- /**
28
- * Icon overrides, the same map `<SvGrid icons>` takes. This panel draws
29
- * `drag-handle`, `remove` and `breadcrumb-separator`. You mount it
30
- * yourself, so pass the same object you gave the grid to keep them
31
- * consistent.
32
- */
33
- icons?: GridIcons
34
- }
35
- let { columns, groupBy, onChange, placeholder = 'Drag a column here to group by it', icons }: Props = $props()
36
-
37
- const labelOf = (id: string) => columns.find((c) => c.id === id)?.label ?? id
38
- const available = $derived(columns.filter((c) => !groupBy.includes(c.id)))
39
-
40
- let dragIndex = $state<number | null>(null)
41
-
42
- function remove(id: string) {
43
- onChange(groupBy.filter((g) => g !== id))
44
- }
45
- function add(id: string) {
46
- if (id && !groupBy.includes(id)) onChange([...groupBy, id])
47
- }
48
- function reorder(to: number) {
49
- if (dragIndex === null || dragIndex === to) return
50
- const next = [...groupBy]
51
- const [moved] = next.splice(dragIndex, 1)
52
- next.splice(to, 0, moved!)
53
- dragIndex = null
54
- onChange(next)
55
- }
56
- function onPanelDrop(e: DragEvent) {
57
- const id = e.dataTransfer?.getData('text/sv-column')
58
- if (id) add(id)
59
- }
60
- /** Keyboard equivalent of dragging a chip: moves the chip at `i` one slot earlier/later,
61
- * reusing `reorder()` (via `dragIndex`) so there is a single source of truth for the move. */
62
- function moveByKeyboard(i: number, delta: number) {
63
- const to = i + delta
64
- if (to < 0 || to >= groupBy.length) return
65
- dragIndex = i
66
- reorder(to)
67
- }
68
- function onChipKeydown(e: KeyboardEvent, i: number) {
69
- if (!e.altKey) return
70
- if (e.key === 'ArrowLeft') {
71
- e.preventDefault()
72
- moveByKeyboard(i, -1)
73
- } else if (e.key === 'ArrowRight') {
74
- e.preventDefault()
75
- moveByKeyboard(i, 1)
76
- }
77
- }
78
- </script>
79
-
80
- <!-- Same override-or-default resolution SvGrid uses, kept local because this
81
- component is mounted by the consumer and never sees the grid's snippet. -->
82
- {#snippet ic(name: GridIconName)}
83
- {@const override = icons?.[name]}
84
- {#if override}{@render override()}{:else}{GRID_ICON_GLYPHS[name]}{/if}
85
- {/snippet}
86
-
87
- <div
88
- class="sv-rowgroup-panel"
89
- role="group"
90
- aria-label="Row groups"
91
- ondragover={(e) => e.preventDefault()}
92
- ondrop={onPanelDrop}
93
- >
94
- <span class="sv-rgp-label" aria-hidden="true">Group by:</span>
95
- {#if groupBy.length === 0}
96
- <span class="sv-rgp-empty">{placeholder}</span>
97
- {:else}
98
- {#each groupBy as id, i (id)}
99
- {#if i > 0}<span class="sv-rgp-sep" aria-hidden="true">{@render ic('breadcrumb-separator')}</span>{/if}
100
- <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
101
- <span
102
- class="sv-rgp-chip"
103
- class:sv-rgp-chip-drag={dragIndex === i}
104
- role="group"
105
- tabindex="0"
106
- aria-label={`Grouped by ${labelOf(id)}, position ${i + 1} of ${groupBy.length}. Press Alt+Arrow keys to reorder.`}
107
- draggable="true"
108
- ondragstart={() => (dragIndex = i)}
109
- ondragend={() => (dragIndex = null)}
110
- ondragover={(e) => e.preventDefault()}
111
- ondrop={() => reorder(i)}
112
- onkeydown={(e) => onChipKeydown(e, i)}
113
- >
114
- <span class="sv-rgp-grip" aria-hidden="true">{@render ic('drag-handle')}</span>
115
- {labelOf(id)}
116
- <button type="button" class="sv-rgp-x" onclick={() => remove(id)} aria-label={`Stop grouping by ${labelOf(id)}`}>{@render ic('remove')}</button>
117
- </span>
118
- {/each}
119
- {/if}
120
- {#if available.length}
121
- <select
122
- class="sv-rgp-add"
123
- aria-label="Add a group column"
124
- onchange={(e) => { add(e.currentTarget.value); e.currentTarget.value = '' }}
125
- >
126
- <option value="">+ Group by</option>
127
- {#each available as c (c.id)}<option value={c.id}>{c.label}</option>{/each}
128
- </select>
129
- {/if}
130
- </div>
131
-
132
- <style>
133
- .sv-rowgroup-panel {
134
- display: flex;
135
- align-items: center;
136
- flex-wrap: wrap;
137
- gap: 6px;
138
- padding: 8px 10px;
139
- border: 1px dashed var(--sg-border, #cbd5e1);
140
- border-radius: 10px;
141
- background: var(--sg-header-bg, #f8fafc);
142
- font-size: 13px;
143
- }
144
- .sv-rgp-label { color: var(--sg-muted, #64748b); font-weight: 600; }
145
- .sv-rgp-empty { color: var(--sg-muted, #94a3b8); font-style: italic; }
146
- .sv-rgp-sep { color: var(--sg-muted, #94a3b8); }
147
- .sv-rgp-chip {
148
- display: inline-flex;
149
- align-items: center;
150
- gap: 6px;
151
- padding: 3px 6px 3px 8px;
152
- border-radius: 999px;
153
- background: var(--sg-bg, #fff);
154
- border: 1px solid var(--sg-border, #e2e8f0);
155
- cursor: grab;
156
- user-select: none;
157
- font-weight: 600;
158
- }
159
- .sv-rgp-chip-drag { opacity: 0.5; }
160
- .sv-rgp-grip { color: var(--sg-muted, #94a3b8); cursor: grab; }
161
- .sv-rgp-x {
162
- display: inline-flex;
163
- align-items: center;
164
- justify-content: center;
165
- width: 16px;
166
- height: 16px;
167
- border: 0;
168
- border-radius: 50%;
169
- background: none;
170
- color: var(--sg-muted, #64748b);
171
- cursor: pointer;
172
- font-size: 14px;
173
- line-height: 1;
174
- }
175
- .sv-rgp-x:hover { background: var(--sg-header-bg, #f1f5f9); color: var(--sg-fg, #0f172a); }
176
- .sv-rgp-add {
177
- font: inherit;
178
- font-size: 13px;
179
- padding: 4px 8px;
180
- border-radius: 8px;
181
- border: 1px solid var(--sg-border, #e2e8f0);
182
- background: var(--sg-bg, #fff);
183
- color: var(--sg-accent, #2563eb);
184
- cursor: pointer;
185
- }
186
- </style>
@@ -1,25 +0,0 @@
1
- import { type GridIcons } from './grid-icons.js';
2
- type Col = {
3
- id: string;
4
- label: string;
5
- };
6
- type Props = {
7
- /** Columns that can be grouped on. */
8
- columns: Col[];
9
- /** Current group-by column ids, outer to inner. */
10
- groupBy: string[];
11
- /** Called with the new group-by order. */
12
- onChange: (groupBy: string[]) => void;
13
- /** Text shown when nothing is grouped. */
14
- placeholder?: string;
15
- /**
16
- * Icon overrides, the same map `<SvGrid icons>` takes. This panel draws
17
- * `drag-handle`, `remove` and `breadcrumb-separator`. You mount it
18
- * yourself, so pass the same object you gave the grid to keep them
19
- * consistent.
20
- */
21
- icons?: GridIcons;
22
- };
23
- declare const SvRowGroupPanel: import("svelte").Component<Props, {}, "">;
24
- type SvRowGroupPanel = ReturnType<typeof SvRowGroupPanel>;
25
- export default SvRowGroupPanel;