@svgrid/grid 1.0.2 → 1.1.1

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 (216) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +137 -39
  3. package/dist/GridFooter.svelte +164 -0
  4. package/dist/GridFooter.svelte.d.ts +29 -0
  5. package/dist/GridMenus.svelte +648 -0
  6. package/dist/GridMenus.svelte.d.ts +31 -0
  7. package/dist/SvGrid.controller.svelte.d.ts +472 -0
  8. package/dist/SvGrid.controller.svelte.js +1917 -0
  9. package/dist/SvGrid.css +2012 -0
  10. package/dist/SvGrid.helpers.d.ts +35 -0
  11. package/dist/SvGrid.helpers.js +160 -0
  12. package/dist/SvGrid.helpers.test.d.ts +1 -0
  13. package/dist/SvGrid.helpers.test.js +298 -0
  14. package/dist/SvGrid.svelte +2346 -8742
  15. package/dist/SvGrid.svelte.d.ts +4 -357
  16. package/dist/SvGrid.types.d.ts +523 -0
  17. package/dist/SvGrid.types.js +1 -0
  18. package/dist/SvGridChart.svelte +1060 -23
  19. package/dist/SvGridChart.svelte.d.ts +17 -0
  20. package/dist/aligned-grids.d.ts +6 -0
  21. package/dist/aligned-grids.js +84 -0
  22. package/dist/aligned-grids.test.d.ts +1 -0
  23. package/dist/aligned-grids.test.js +75 -0
  24. package/dist/build-api.coverage.test.d.ts +20 -0
  25. package/dist/build-api.coverage.test.js +505 -0
  26. package/dist/build-api.d.ts +5 -0
  27. package/dist/build-api.js +557 -0
  28. package/dist/cell-render.d.ts +15 -0
  29. package/dist/cell-render.js +246 -0
  30. package/dist/cell-render.test.d.ts +1 -0
  31. package/dist/cell-render.test.js +338 -0
  32. package/dist/cell-values.d.ts +28 -0
  33. package/dist/cell-values.js +89 -0
  34. package/dist/chart-export.test.d.ts +1 -0
  35. package/dist/chart-export.test.js +302 -0
  36. package/dist/chart.coverage.test.d.ts +1 -0
  37. package/dist/chart.coverage.test.js +748 -0
  38. package/dist/chart.d.ts +370 -3
  39. package/dist/chart.js +1135 -42
  40. package/dist/clipboard.d.ts +15 -0
  41. package/dist/clipboard.js +420 -0
  42. package/dist/clipboard.test.d.ts +1 -0
  43. package/dist/clipboard.test.js +700 -0
  44. package/dist/collaboration.coverage.test.d.ts +1 -0
  45. package/dist/collaboration.coverage.test.js +200 -0
  46. package/dist/column-groups.d.ts +19 -0
  47. package/dist/column-groups.js +62 -0
  48. package/dist/column-groups.test.d.ts +1 -0
  49. package/dist/column-groups.test.js +56 -0
  50. package/dist/column-types.d.ts +10 -0
  51. package/dist/column-types.js +63 -0
  52. package/dist/column-types.test.d.ts +1 -0
  53. package/dist/column-types.test.js +62 -0
  54. package/dist/columns.d.ts +30 -0
  55. package/dist/columns.js +277 -0
  56. package/dist/columns.test.d.ts +1 -0
  57. package/dist/columns.test.js +625 -0
  58. package/dist/core.d.ts +86 -1
  59. package/dist/css.d.ts +3 -0
  60. package/dist/editing.d.ts +31 -0
  61. package/dist/editing.js +529 -0
  62. package/dist/editing.test.d.ts +1 -0
  63. package/dist/editing.test.js +732 -0
  64. package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
  65. package/dist/editors/cell-editors.coverage.test.js +139 -0
  66. package/dist/editors/cell-editors.d.ts +1 -1
  67. package/dist/facet-buckets.d.ts +13 -0
  68. package/dist/facet-buckets.js +54 -0
  69. package/dist/facet-buckets.test.d.ts +1 -0
  70. package/dist/facet-buckets.test.js +296 -0
  71. package/dist/features.d.ts +5 -0
  72. package/dist/features.js +30 -0
  73. package/dist/filter-operators.d.ts +16 -0
  74. package/dist/filter-operators.js +69 -0
  75. package/dist/filter-operators.test.d.ts +1 -0
  76. package/dist/filter-operators.test.js +135 -0
  77. package/dist/hyperformula-adapter.d.ts +82 -0
  78. package/dist/hyperformula-adapter.js +73 -0
  79. package/dist/hyperformula-adapter.test.d.ts +1 -0
  80. package/dist/hyperformula-adapter.test.js +205 -0
  81. package/dist/index.d.ts +9 -3
  82. package/dist/index.js +8 -2
  83. package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
  84. package/dist/keyboard-handlers.coverage.test.js +495 -0
  85. package/dist/keyboard-handlers.d.ts +7 -0
  86. package/dist/keyboard-handlers.js +202 -0
  87. package/dist/menus.d.ts +40 -0
  88. package/dist/menus.js +390 -0
  89. package/dist/menus.test.d.ts +1 -0
  90. package/dist/menus.test.js +560 -0
  91. package/dist/named-views.coverage.test.d.ts +1 -0
  92. package/dist/named-views.coverage.test.js +180 -0
  93. package/dist/named-views.d.ts +27 -0
  94. package/dist/named-views.js +39 -0
  95. package/dist/row-drag.d.ts +49 -0
  96. package/dist/row-drag.js +221 -0
  97. package/dist/row-drag.test.d.ts +1 -0
  98. package/dist/row-drag.test.js +142 -0
  99. package/dist/row-resize.d.ts +43 -0
  100. package/dist/row-resize.js +158 -0
  101. package/dist/row-resize.test.d.ts +1 -0
  102. package/dist/row-resize.test.js +329 -0
  103. package/dist/scroll-sync.d.ts +9 -0
  104. package/dist/scroll-sync.js +89 -0
  105. package/dist/scroll-sync.test.d.ts +1 -0
  106. package/dist/scroll-sync.test.js +290 -0
  107. package/dist/selection.d.ts +32 -0
  108. package/dist/selection.js +427 -0
  109. package/dist/selection.multi-range.test.d.ts +1 -0
  110. package/dist/selection.multi-range.test.js +55 -0
  111. package/dist/selection.test.d.ts +1 -0
  112. package/dist/selection.test.js +647 -0
  113. package/dist/server-data-source.coverage.test.d.ts +1 -0
  114. package/dist/server-data-source.coverage.test.js +154 -0
  115. package/dist/spreadsheet.d.ts +110 -0
  116. package/dist/spreadsheet.js +242 -0
  117. package/dist/spreadsheet.test.d.ts +1 -0
  118. package/dist/spreadsheet.test.js +446 -0
  119. package/dist/summaries.d.ts +12 -0
  120. package/dist/summaries.js +65 -0
  121. package/dist/sv-grid-scrollbar.js +13 -1
  122. package/dist/svgrid-wrapper.types.d.ts +31 -1
  123. package/dist/svgrid.behavior.test.js +20 -0
  124. package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
  125. package/dist/svgrid.comments-autocomplete.test.js +96 -0
  126. package/dist/svgrid.context-menu.test.d.ts +1 -0
  127. package/dist/svgrid.context-menu.test.js +102 -0
  128. package/dist/svgrid.interaction.test.js +31 -0
  129. package/dist/svgrid.new-features.wrapper.test.js +64 -6
  130. package/dist/svgrid.wrapper.test.js +27 -1
  131. package/dist/test-setup.js +9 -3
  132. package/dist/virtualization/column-virtualizer.d.ts +2 -0
  133. package/dist/virtualization/scroll-scaling.d.ts +45 -0
  134. package/dist/virtualization/scroll-scaling.js +99 -0
  135. package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
  136. package/dist/virtualization/scroll-scaling.test.js +127 -0
  137. package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
  138. package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
  139. package/dist/virtualization/virtualizer.d.ts +7 -0
  140. package/dist/virtualization/virtualizer.js +30 -0
  141. package/package.json +2 -1
  142. package/src/GridFooter.svelte +164 -0
  143. package/src/GridMenus.svelte +648 -0
  144. package/src/SvGrid.controller.svelte.ts +2352 -0
  145. package/src/SvGrid.css +2012 -0
  146. package/src/SvGrid.helpers.test.ts +415 -0
  147. package/src/SvGrid.helpers.ts +185 -0
  148. package/src/SvGrid.svelte +2346 -8742
  149. package/src/SvGrid.types.ts +537 -0
  150. package/src/SvGridChart.svelte +1060 -23
  151. package/src/aligned-grids.test.ts +80 -0
  152. package/src/aligned-grids.ts +87 -0
  153. package/src/build-api.coverage.test.ts +532 -0
  154. package/src/build-api.ts +683 -0
  155. package/src/cell-render.test.ts +451 -0
  156. package/src/cell-render.ts +426 -0
  157. package/src/cell-values.ts +114 -0
  158. package/src/chart-export.test.ts +370 -0
  159. package/src/chart.coverage.test.ts +814 -0
  160. package/src/chart.ts +1352 -47
  161. package/src/clipboard.test.ts +780 -0
  162. package/src/clipboard.ts +552 -0
  163. package/src/collaboration.coverage.test.ts +220 -0
  164. package/src/column-groups.test.ts +59 -0
  165. package/src/column-groups.ts +80 -0
  166. package/src/column-types.test.ts +68 -0
  167. package/src/column-types.ts +82 -0
  168. package/src/columns.test.ts +702 -0
  169. package/src/columns.ts +419 -0
  170. package/src/core.ts +86 -0
  171. package/src/css.d.ts +3 -0
  172. package/src/editing.test.ts +837 -0
  173. package/src/editing.ts +669 -0
  174. package/src/editors/cell-editors.coverage.test.ts +156 -0
  175. package/src/editors/cell-editors.ts +1 -0
  176. package/src/facet-buckets.test.ts +353 -0
  177. package/src/facet-buckets.ts +67 -0
  178. package/src/features.ts +128 -0
  179. package/src/filter-operators.test.ts +174 -0
  180. package/src/filter-operators.ts +87 -0
  181. package/src/hyperformula-adapter.test.ts +256 -0
  182. package/src/hyperformula-adapter.ts +124 -0
  183. package/src/index.ts +49 -0
  184. package/src/keyboard-handlers.coverage.test.ts +560 -0
  185. package/src/keyboard-handlers.ts +353 -0
  186. package/src/keyboard.ts +97 -97
  187. package/src/menus.test.ts +620 -0
  188. package/src/menus.ts +555 -0
  189. package/src/named-views.coverage.test.ts +210 -0
  190. package/src/named-views.ts +48 -0
  191. package/src/row-drag.test.ts +168 -0
  192. package/src/row-drag.ts +255 -0
  193. package/src/row-resize.test.ts +369 -0
  194. package/src/row-resize.ts +171 -0
  195. package/src/scroll-sync.test.ts +330 -0
  196. package/src/scroll-sync.ts +218 -0
  197. package/src/selection.multi-range.test.ts +61 -0
  198. package/src/selection.test.ts +722 -0
  199. package/src/selection.ts +579 -0
  200. package/src/server-data-source.coverage.test.ts +180 -0
  201. package/src/spreadsheet.test.ts +489 -0
  202. package/src/spreadsheet.ts +304 -0
  203. package/src/summaries.ts +204 -0
  204. package/src/sv-grid-scrollbar.ts +13 -1
  205. package/src/svgrid-wrapper.types.ts +31 -1
  206. package/src/svgrid.behavior.test.ts +22 -0
  207. package/src/svgrid.comments-autocomplete.test.ts +112 -0
  208. package/src/svgrid.context-menu.test.ts +126 -0
  209. package/src/svgrid.interaction.test.ts +30 -0
  210. package/src/svgrid.new-features.wrapper.test.ts +67 -6
  211. package/src/svgrid.wrapper.test.ts +27 -1
  212. package/src/test-setup.ts +9 -6
  213. package/src/virtualization/scroll-scaling.test.ts +148 -0
  214. package/src/virtualization/scroll-scaling.ts +121 -0
  215. package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
  216. package/src/virtualization/virtualizer.ts +26 -0
@@ -0,0 +1,124 @@
1
+ /**
2
+ * HyperFormula adapter — Excel-class formula evaluation for SvGrid.
3
+ *
4
+ * `hyperformula` is an OPTIONAL peer dependency. Consumers who want
5
+ * full Excel-compatible formulas install it themselves:
6
+ *
7
+ * ```bash
8
+ * pnpm add hyperformula
9
+ * ```
10
+ *
11
+ * The adapter wraps an HF instance around the grid's flat-row data:
12
+ *
13
+ * - Treats each `data[]` row as a spreadsheet row
14
+ * - Each registered field maps to a spreadsheet column
15
+ * - Values that start with `=` are evaluated by HF
16
+ * - The adapter returns the computed rows ready to render
17
+ * - On edit, call `update(rowIdx, field, value)` and the adapter
18
+ * re-evaluates only the cells HF tells it are dirty
19
+ *
20
+ * Why not bundle HF: it's ~1MB minified and 99% of grids never need it.
21
+ * Keeping it peer-optional means tiny default bundle + heavy-formula
22
+ * users get the ~400 functions (VLOOKUP, INDIRECT, IFS, XLOOKUP, full
23
+ * date/time/financial libraries) on demand.
24
+ */
25
+
26
+ /** Minimal HF type surface this adapter uses. Mirrored here (rather
27
+ * than importing) so consumers without `hyperformula` installed still
28
+ * type-check. */
29
+ export type HyperFormulaInstance = {
30
+ setCellContents(
31
+ cell: { sheet: number; row: number; col: number },
32
+ contents: unknown,
33
+ ): Array<{ address: { sheet: number; row: number; col: number }; newValue: unknown }>
34
+ getCellValue(cell: { sheet: number; row: number; col: number }): unknown
35
+ destroy(): void
36
+ rebuildAndRecalculate(): void
37
+ }
38
+
39
+ export type HyperFormulaSheetConfig<T extends Record<string, unknown>> = {
40
+ /** The HF instance the consumer constructed (so they pick the
41
+ * license key + options). */
42
+ hyperformula: HyperFormulaInstance
43
+ /** Sheet index inside the HF instance. Default 0. */
44
+ sheetId?: number
45
+ /** Source rows. Cell values starting with `=` are evaluated. */
46
+ rows: T[]
47
+ /** Ordered list of fields to expose to the formula engine. The
48
+ * order determines the HF column index, which is how A1-style
49
+ * references resolve. */
50
+ fields: ReadonlyArray<keyof T & string>
51
+ }
52
+
53
+ export type HyperFormulaSheet<T extends Record<string, unknown>> = {
54
+ /** Rows with every `=...` formula replaced by its evaluated value.
55
+ * Use this in a custom cell renderer to DISPLAY the result. */
56
+ computed: T[]
57
+ /** Rows with formulas kept as their raw `=SUM(...)` strings.
58
+ * Pass this as `<SvGrid data={...}>` so the inline editor lets the
59
+ * user edit the formula text itself, not the evaluated value. */
60
+ raw: T[]
61
+ /** Call when a cell edit lands. Returns the new computed + raw
62
+ * snapshots so the consumer can reassign both. */
63
+ update(rowIndex: number, field: keyof T & string, value: unknown): {
64
+ computed: T[]
65
+ raw: T[]
66
+ }
67
+ /** Tear the adapter + the HF instance down (releases memory). */
68
+ destroy(): void
69
+ }
70
+
71
+ /** Build a live spreadsheet adapter around a HyperFormula instance.
72
+ * Returns computed rows + an `update()` hook to push edits back into
73
+ * the engine. */
74
+ export function createHyperFormulaSheet<T extends Record<string, unknown>>(
75
+ config: HyperFormulaSheetConfig<T>,
76
+ ): HyperFormulaSheet<T> {
77
+ const { hyperformula: hf, rows, fields } = config
78
+ const sheetId = config.sheetId ?? 0
79
+ const colByField = new Map<string, number>()
80
+ fields.forEach((f, i) => colByField.set(f as string, i))
81
+
82
+ // 1. Seed HF with every cell. HF expects raw strings for formulas
83
+ // (`'=A1+B1'`) and primitives for everything else.
84
+ for (let r = 0; r < rows.length; r += 1) {
85
+ const row = rows[r]!
86
+ for (let c = 0; c < fields.length; c += 1) {
87
+ const field = fields[c]! as string
88
+ hf.setCellContents({ sheet: sheetId, row: r, col: c }, row[field as keyof T])
89
+ }
90
+ }
91
+
92
+ /** Pull computed values out of HF into a fresh row array. Preserves
93
+ * any non-formula fields (i.e. those not in `fields`) untouched. */
94
+ function snapshot(): T[] {
95
+ const out: T[] = new Array(rows.length)
96
+ for (let r = 0; r < rows.length; r += 1) {
97
+ const next: Record<string, unknown> = { ...rows[r]! }
98
+ for (let c = 0; c < fields.length; c += 1) {
99
+ const field = fields[c]! as string
100
+ const v = hf.getCellValue({ sheet: sheetId, row: r, col: c })
101
+ next[field] = v
102
+ }
103
+ out[r] = next as T
104
+ }
105
+ return out
106
+ }
107
+
108
+ function rawSnapshot(): T[] {
109
+ return rows.map((r) => ({ ...r }))
110
+ }
111
+ return {
112
+ computed: snapshot(),
113
+ raw: rawSnapshot(),
114
+ update(rowIndex, field, value) {
115
+ const col = colByField.get(field as string)
116
+ if (col !== undefined) {
117
+ hf.setCellContents({ sheet: sheetId, row: rowIndex, col }, value)
118
+ }
119
+ rows[rowIndex] = { ...rows[rowIndex]!, [field]: value } as T
120
+ return { computed: snapshot(), raw: rawSnapshot() }
121
+ },
122
+ destroy() { hf.destroy() },
123
+ }
124
+ }
package/src/index.ts CHANGED
@@ -19,6 +19,8 @@ export {
19
19
  tableFeatures,
20
20
  type Cell,
21
21
  type CellContext,
22
+ type CellSpanParams,
23
+ type ValueParserParams,
22
24
  type EditorContext,
23
25
  type CellData,
24
26
  type ActiveCellState,
@@ -51,6 +53,14 @@ export {
51
53
  buildChart,
52
54
  rowsToChartSpec,
53
55
  niceScale,
56
+ niceLogScale,
57
+ linearTrend,
58
+ simpleMovingAverage,
59
+ exponentialMovingAverage,
60
+ computeOverlay,
61
+ buildLinePath,
62
+ sampleGradient,
63
+ pickContrastText,
54
64
  DEFAULT_PALETTE,
55
65
  type ChartType,
56
66
  type ChartSpec,
@@ -67,6 +77,19 @@ export {
67
77
  type ChartScatterDot,
68
78
  type ScatterPoint,
69
79
  type NiceScale,
80
+ type SeriesOverlay,
81
+ type SeriesPattern,
82
+ type ChartAnnotation,
83
+ type ChartHeatmapCell,
84
+ type ChartFunnelSegment,
85
+ type ChartRadarSeries,
86
+ type ChartRadarAxis,
87
+ type ChartTreemapCell,
88
+ type ChartCalendarCell,
89
+ type ChartGaugeLayout,
90
+ type ChartSankeyNode,
91
+ type ChartSankeyLink,
92
+ type TreeNode,
70
93
  } from './chart'
71
94
  export {
72
95
  chartToSvgString,
@@ -82,6 +105,30 @@ export {
82
105
  type SparklineType,
83
106
  type SparklineGeometry,
84
107
  } from './sparkline'
108
+ export {
109
+ spreadsheetLayout,
110
+ spansToMerges,
111
+ type SpanColumn,
112
+ type SpreadsheetActionOptions,
113
+ type MergeSpec,
114
+ type CellBorderSpec,
115
+ type BorderSpec,
116
+ } from './spreadsheet'
117
+ export { rowResize, type RowResizeOptions } from './row-resize'
118
+ export { rowDropZone, type RowDragEndEvent, type RowDropZoneOptions } from './row-drag'
119
+ export { resolveColumnTypes, inferCellDataType, type CellDataType } from './column-types'
120
+ export {
121
+ computeColumnGroupMeta,
122
+ hiddenLeavesForCollapse,
123
+ type ColumnGroupMeta,
124
+ type ColumnGroupShow,
125
+ } from './column-groups'
126
+ export {
127
+ createHyperFormulaSheet,
128
+ type HyperFormulaSheet,
129
+ type HyperFormulaSheetConfig,
130
+ type HyperFormulaInstance,
131
+ } from './hyperformula-adapter'
85
132
  export {
86
133
  createCollaboration,
87
134
  broadcastChannelTransport,
@@ -106,9 +153,11 @@ export {
106
153
  createNamedViews,
107
154
  memoryViews,
108
155
  localStorageViews,
156
+ attachAutoSavedView,
109
157
  type SavedView,
110
158
  type ViewStorage,
111
159
  type NamedViews,
160
+ type AutoSavedViewOptions,
112
161
  } from './named-views'
113
162
  export {
114
163
  resolveCellFormat,