@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.
- package/LICENSE +1 -1
- package/README.md +137 -39
- package/dist/GridFooter.svelte +164 -0
- package/dist/GridFooter.svelte.d.ts +29 -0
- package/dist/GridMenus.svelte +648 -0
- package/dist/GridMenus.svelte.d.ts +31 -0
- package/dist/SvGrid.controller.svelte.d.ts +472 -0
- package/dist/SvGrid.controller.svelte.js +1917 -0
- package/dist/SvGrid.css +2012 -0
- package/dist/SvGrid.helpers.d.ts +35 -0
- package/dist/SvGrid.helpers.js +160 -0
- package/dist/SvGrid.helpers.test.d.ts +1 -0
- package/dist/SvGrid.helpers.test.js +298 -0
- package/dist/SvGrid.svelte +2346 -8742
- package/dist/SvGrid.svelte.d.ts +4 -357
- package/dist/SvGrid.types.d.ts +523 -0
- package/dist/SvGrid.types.js +1 -0
- package/dist/SvGridChart.svelte +1060 -23
- package/dist/SvGridChart.svelte.d.ts +17 -0
- package/dist/aligned-grids.d.ts +6 -0
- package/dist/aligned-grids.js +84 -0
- package/dist/aligned-grids.test.d.ts +1 -0
- package/dist/aligned-grids.test.js +75 -0
- package/dist/build-api.coverage.test.d.ts +20 -0
- package/dist/build-api.coverage.test.js +505 -0
- package/dist/build-api.d.ts +5 -0
- package/dist/build-api.js +557 -0
- package/dist/cell-render.d.ts +15 -0
- package/dist/cell-render.js +246 -0
- package/dist/cell-render.test.d.ts +1 -0
- package/dist/cell-render.test.js +338 -0
- package/dist/cell-values.d.ts +28 -0
- package/dist/cell-values.js +89 -0
- package/dist/chart-export.test.d.ts +1 -0
- package/dist/chart-export.test.js +302 -0
- package/dist/chart.coverage.test.d.ts +1 -0
- package/dist/chart.coverage.test.js +748 -0
- package/dist/chart.d.ts +370 -3
- package/dist/chart.js +1135 -42
- package/dist/clipboard.d.ts +15 -0
- package/dist/clipboard.js +420 -0
- package/dist/clipboard.test.d.ts +1 -0
- package/dist/clipboard.test.js +700 -0
- package/dist/collaboration.coverage.test.d.ts +1 -0
- package/dist/collaboration.coverage.test.js +200 -0
- package/dist/column-groups.d.ts +19 -0
- package/dist/column-groups.js +62 -0
- package/dist/column-groups.test.d.ts +1 -0
- package/dist/column-groups.test.js +56 -0
- package/dist/column-types.d.ts +10 -0
- package/dist/column-types.js +63 -0
- package/dist/column-types.test.d.ts +1 -0
- package/dist/column-types.test.js +62 -0
- package/dist/columns.d.ts +30 -0
- package/dist/columns.js +277 -0
- package/dist/columns.test.d.ts +1 -0
- package/dist/columns.test.js +625 -0
- package/dist/core.d.ts +86 -1
- package/dist/css.d.ts +3 -0
- package/dist/editing.d.ts +31 -0
- package/dist/editing.js +529 -0
- package/dist/editing.test.d.ts +1 -0
- package/dist/editing.test.js +732 -0
- package/dist/editors/cell-editors.coverage.test.d.ts +1 -0
- package/dist/editors/cell-editors.coverage.test.js +139 -0
- package/dist/editors/cell-editors.d.ts +1 -1
- package/dist/facet-buckets.d.ts +13 -0
- package/dist/facet-buckets.js +54 -0
- package/dist/facet-buckets.test.d.ts +1 -0
- package/dist/facet-buckets.test.js +296 -0
- package/dist/features.d.ts +5 -0
- package/dist/features.js +30 -0
- package/dist/filter-operators.d.ts +16 -0
- package/dist/filter-operators.js +69 -0
- package/dist/filter-operators.test.d.ts +1 -0
- package/dist/filter-operators.test.js +135 -0
- package/dist/hyperformula-adapter.d.ts +82 -0
- package/dist/hyperformula-adapter.js +73 -0
- package/dist/hyperformula-adapter.test.d.ts +1 -0
- package/dist/hyperformula-adapter.test.js +205 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +8 -2
- package/dist/keyboard-handlers.coverage.test.d.ts +1 -0
- package/dist/keyboard-handlers.coverage.test.js +495 -0
- package/dist/keyboard-handlers.d.ts +7 -0
- package/dist/keyboard-handlers.js +202 -0
- package/dist/menus.d.ts +40 -0
- package/dist/menus.js +390 -0
- package/dist/menus.test.d.ts +1 -0
- package/dist/menus.test.js +560 -0
- package/dist/named-views.coverage.test.d.ts +1 -0
- package/dist/named-views.coverage.test.js +180 -0
- package/dist/named-views.d.ts +27 -0
- package/dist/named-views.js +39 -0
- package/dist/row-drag.d.ts +49 -0
- package/dist/row-drag.js +221 -0
- package/dist/row-drag.test.d.ts +1 -0
- package/dist/row-drag.test.js +142 -0
- package/dist/row-resize.d.ts +43 -0
- package/dist/row-resize.js +158 -0
- package/dist/row-resize.test.d.ts +1 -0
- package/dist/row-resize.test.js +329 -0
- package/dist/scroll-sync.d.ts +9 -0
- package/dist/scroll-sync.js +89 -0
- package/dist/scroll-sync.test.d.ts +1 -0
- package/dist/scroll-sync.test.js +290 -0
- package/dist/selection.d.ts +32 -0
- package/dist/selection.js +427 -0
- package/dist/selection.multi-range.test.d.ts +1 -0
- package/dist/selection.multi-range.test.js +55 -0
- package/dist/selection.test.d.ts +1 -0
- package/dist/selection.test.js +647 -0
- package/dist/server-data-source.coverage.test.d.ts +1 -0
- package/dist/server-data-source.coverage.test.js +154 -0
- package/dist/spreadsheet.d.ts +110 -0
- package/dist/spreadsheet.js +242 -0
- package/dist/spreadsheet.test.d.ts +1 -0
- package/dist/spreadsheet.test.js +446 -0
- package/dist/summaries.d.ts +12 -0
- package/dist/summaries.js +65 -0
- package/dist/sv-grid-scrollbar.js +13 -1
- package/dist/svgrid-wrapper.types.d.ts +31 -1
- package/dist/svgrid.behavior.test.js +20 -0
- package/dist/svgrid.comments-autocomplete.test.d.ts +1 -0
- package/dist/svgrid.comments-autocomplete.test.js +96 -0
- package/dist/svgrid.context-menu.test.d.ts +1 -0
- package/dist/svgrid.context-menu.test.js +102 -0
- package/dist/svgrid.interaction.test.js +31 -0
- package/dist/svgrid.new-features.wrapper.test.js +64 -6
- package/dist/svgrid.wrapper.test.js +27 -1
- package/dist/test-setup.js +9 -3
- package/dist/virtualization/column-virtualizer.d.ts +2 -0
- package/dist/virtualization/scroll-scaling.d.ts +45 -0
- package/dist/virtualization/scroll-scaling.js +99 -0
- package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
- package/dist/virtualization/scroll-scaling.test.js +127 -0
- package/dist/virtualization/svelte-virtualizer.svelte.d.ts +2 -0
- package/dist/virtualization/svelte-virtualizer.svelte.js +2 -0
- package/dist/virtualization/virtualizer.d.ts +7 -0
- package/dist/virtualization/virtualizer.js +30 -0
- package/package.json +2 -1
- package/src/GridFooter.svelte +164 -0
- package/src/GridMenus.svelte +648 -0
- package/src/SvGrid.controller.svelte.ts +2352 -0
- package/src/SvGrid.css +2012 -0
- package/src/SvGrid.helpers.test.ts +415 -0
- package/src/SvGrid.helpers.ts +185 -0
- package/src/SvGrid.svelte +2346 -8742
- package/src/SvGrid.types.ts +537 -0
- package/src/SvGridChart.svelte +1060 -23
- package/src/aligned-grids.test.ts +80 -0
- package/src/aligned-grids.ts +87 -0
- package/src/build-api.coverage.test.ts +532 -0
- package/src/build-api.ts +683 -0
- package/src/cell-render.test.ts +451 -0
- package/src/cell-render.ts +426 -0
- package/src/cell-values.ts +114 -0
- package/src/chart-export.test.ts +370 -0
- package/src/chart.coverage.test.ts +814 -0
- package/src/chart.ts +1352 -47
- package/src/clipboard.test.ts +780 -0
- package/src/clipboard.ts +552 -0
- package/src/collaboration.coverage.test.ts +220 -0
- package/src/column-groups.test.ts +59 -0
- package/src/column-groups.ts +80 -0
- package/src/column-types.test.ts +68 -0
- package/src/column-types.ts +82 -0
- package/src/columns.test.ts +702 -0
- package/src/columns.ts +419 -0
- package/src/core.ts +86 -0
- package/src/css.d.ts +3 -0
- package/src/editing.test.ts +837 -0
- package/src/editing.ts +669 -0
- package/src/editors/cell-editors.coverage.test.ts +156 -0
- package/src/editors/cell-editors.ts +1 -0
- package/src/facet-buckets.test.ts +353 -0
- package/src/facet-buckets.ts +67 -0
- package/src/features.ts +128 -0
- package/src/filter-operators.test.ts +174 -0
- package/src/filter-operators.ts +87 -0
- package/src/hyperformula-adapter.test.ts +256 -0
- package/src/hyperformula-adapter.ts +124 -0
- package/src/index.ts +49 -0
- package/src/keyboard-handlers.coverage.test.ts +560 -0
- package/src/keyboard-handlers.ts +353 -0
- package/src/keyboard.ts +97 -97
- package/src/menus.test.ts +620 -0
- package/src/menus.ts +555 -0
- package/src/named-views.coverage.test.ts +210 -0
- package/src/named-views.ts +48 -0
- package/src/row-drag.test.ts +168 -0
- package/src/row-drag.ts +255 -0
- package/src/row-resize.test.ts +369 -0
- package/src/row-resize.ts +171 -0
- package/src/scroll-sync.test.ts +330 -0
- package/src/scroll-sync.ts +218 -0
- package/src/selection.multi-range.test.ts +61 -0
- package/src/selection.test.ts +722 -0
- package/src/selection.ts +579 -0
- package/src/server-data-source.coverage.test.ts +180 -0
- package/src/spreadsheet.test.ts +489 -0
- package/src/spreadsheet.ts +304 -0
- package/src/summaries.ts +204 -0
- package/src/sv-grid-scrollbar.ts +13 -1
- package/src/svgrid-wrapper.types.ts +31 -1
- package/src/svgrid.behavior.test.ts +22 -0
- package/src/svgrid.comments-autocomplete.test.ts +112 -0
- package/src/svgrid.context-menu.test.ts +126 -0
- package/src/svgrid.interaction.test.ts +30 -0
- package/src/svgrid.new-features.wrapper.test.ts +67 -6
- package/src/svgrid.wrapper.test.ts +27 -1
- package/src/test-setup.ts +9 -6
- package/src/virtualization/scroll-scaling.test.ts +148 -0
- package/src/virtualization/scroll-scaling.ts +121 -0
- package/src/virtualization/svelte-virtualizer.svelte.ts +2 -0
- 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,
|