@svgrid/grid 1.0.2 → 1.1.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.
- 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 +570 -0
- package/dist/GridMenus.svelte.d.ts +31 -0
- package/dist/SvGrid.controller.svelte.d.ts +429 -0
- package/dist/SvGrid.controller.svelte.js +1732 -0
- package/dist/SvGrid.css +1709 -0
- package/dist/SvGrid.helpers.d.ts +35 -0
- package/dist/SvGrid.helpers.js +160 -0
- package/dist/SvGrid.svelte +344 -7043
- package/dist/SvGrid.svelte.d.ts +4 -357
- package/dist/SvGrid.types.d.ts +436 -0
- package/dist/SvGrid.types.js +1 -0
- package/dist/SvGridChart.svelte +1060 -23
- package/dist/SvGridChart.svelte.d.ts +17 -0
- package/dist/build-api.d.ts +5 -0
- package/dist/build-api.js +527 -0
- package/dist/cell-render.d.ts +15 -0
- package/dist/cell-render.js +246 -0
- package/dist/cell-values.d.ts +28 -0
- package/dist/cell-values.js +89 -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 +356 -0
- package/dist/columns.d.ts +30 -0
- package/dist/columns.js +277 -0
- package/dist/core.d.ts +1 -1
- package/dist/css.d.ts +3 -0
- package/dist/editing.d.ts +24 -0
- package/dist/editing.js +343 -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/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/hyperformula-adapter.d.ts +82 -0
- package/dist/hyperformula-adapter.js +73 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/keyboard-handlers.d.ts +7 -0
- package/dist/keyboard-handlers.js +197 -0
- package/dist/menus.d.ts +40 -0
- package/dist/menus.js +389 -0
- package/dist/named-views.d.ts +27 -0
- package/dist/named-views.js +39 -0
- package/dist/row-resize.d.ts +43 -0
- package/dist/row-resize.js +158 -0
- package/dist/scroll-sync.d.ts +9 -0
- package/dist/scroll-sync.js +86 -0
- package/dist/selection.d.ts +26 -0
- package/dist/selection.js +387 -0
- package/dist/spreadsheet.d.ts +80 -0
- package/dist/spreadsheet.js +194 -0
- package/dist/summaries.d.ts +12 -0
- package/dist/summaries.js +65 -0
- package/dist/svgrid-wrapper.types.d.ts +12 -1
- 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.new-features.wrapper.test.js +30 -4
- package/dist/svgrid.wrapper.test.js +27 -1
- package/dist/virtualization/column-virtualizer.d.ts +2 -0
- package/dist/virtualization/scroll-scaling.d.ts +28 -0
- package/dist/virtualization/scroll-scaling.js +64 -0
- package/dist/virtualization/scroll-scaling.test.d.ts +1 -0
- package/dist/virtualization/scroll-scaling.test.js +86 -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 +1 -1
- package/src/GridFooter.svelte +164 -0
- package/src/GridMenus.svelte +570 -0
- package/src/SvGrid.controller.svelte.ts +2195 -0
- package/src/SvGrid.css +1747 -0
- package/src/SvGrid.helpers.test.ts +415 -0
- package/src/SvGrid.helpers.ts +185 -0
- package/src/SvGrid.svelte +348 -7043
- package/src/SvGrid.types.ts +456 -0
- package/src/SvGridChart.svelte +1060 -23
- package/src/build-api.coverage.test.ts +532 -0
- package/src/build-api.ts +663 -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 +731 -0
- package/src/clipboard.ts +524 -0
- package/src/collaboration.coverage.test.ts +220 -0
- package/src/columns.test.ts +702 -0
- package/src/columns.ts +419 -0
- package/src/core.ts +8 -0
- package/src/css.d.ts +3 -0
- package/src/editing.test.ts +837 -0
- package/src/editing.ts +513 -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 +37 -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 +554 -0
- package/src/named-views.coverage.test.ts +210 -0
- package/src/named-views.ts +48 -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 +216 -0
- package/src/selection.test.ts +722 -0
- package/src/selection.ts +545 -0
- package/src/server-data-source.coverage.test.ts +180 -0
- package/src/spreadsheet.test.ts +445 -0
- package/src/spreadsheet.ts +246 -0
- package/src/summaries.ts +204 -0
- package/src/sv-grid-scrollbar.ts +13 -1
- package/src/svgrid-wrapper.types.ts +12 -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 +65 -4
- 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,246 @@
|
|
|
1
|
+
// cell-render handlers extracted from the controller. Imperative event handlers
|
|
2
|
+
// reading/writing controller state via the `ctx` handle; the reactive core
|
|
3
|
+
// ($state/$derived/$effect) stays in the controller.
|
|
4
|
+
import { normalizeEditorOptions, } from "./index";
|
|
5
|
+
import "./sv-grid-scrollbar";
|
|
6
|
+
import { formatNumericWithConfig, getDateFormatter, resolveDatePattern, } from "./cell-formatting";
|
|
7
|
+
import { resolveCellFormat, } from "./conditional-formatting";
|
|
8
|
+
import { resolveClassList, getOptionLabel, asDate, } from "./SvGrid.helpers";
|
|
9
|
+
import { getPinnedCellValue, } from "./cell-values";
|
|
10
|
+
export function createCellRender(ctx) {
|
|
11
|
+
function cellConditionalFormat(row, column, value) {
|
|
12
|
+
const formats = ctx.props.conditionalFormats;
|
|
13
|
+
if (!formats?.length)
|
|
14
|
+
return null;
|
|
15
|
+
return resolveCellFormat(value, row.original, column.id, formats, ctx.conditionalColumnStats.get(column.id) ?? null);
|
|
16
|
+
}
|
|
17
|
+
/** Compute the consumer-supplied row class for one rendered row. */
|
|
18
|
+
function computeRowClass(row, rowIndex) {
|
|
19
|
+
if (!ctx.props.rowClass)
|
|
20
|
+
return "";
|
|
21
|
+
return resolveClassList(ctx.props.rowClass({ row: row.original, rowIndex }));
|
|
22
|
+
}
|
|
23
|
+
/** Compute the consumer-supplied cell class for one rendered cell. */
|
|
24
|
+
function computeCellClass(row, column) {
|
|
25
|
+
const raw = column.columnDef.cellClass;
|
|
26
|
+
if (raw == null)
|
|
27
|
+
return "";
|
|
28
|
+
if (typeof raw === "string" || Array.isArray(raw)) {
|
|
29
|
+
return resolveClassList(raw);
|
|
30
|
+
}
|
|
31
|
+
if (typeof raw === "function") {
|
|
32
|
+
// Build a minimal CellContext - the only fields the wrapper-side
|
|
33
|
+
// cellClass author needs are `row` and `column`. Callers can read
|
|
34
|
+
// `ctx.row.original` and `ctx.column.id` exactly like in a `cell`
|
|
35
|
+
// renderer. The other fields are stubbed for compatibility.
|
|
36
|
+
const cellCtx = {
|
|
37
|
+
row,
|
|
38
|
+
column,
|
|
39
|
+
cell: undefined,
|
|
40
|
+
table: undefined,
|
|
41
|
+
getValue: () => row.getCellValueByColumnId(column.id),
|
|
42
|
+
};
|
|
43
|
+
return resolveClassList(raw(cellCtx));
|
|
44
|
+
}
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve the per-cell tooltip. Column-level `tooltip` field can be a
|
|
49
|
+
* plain string (rendered as `title=`) or a `(ctx) => string` callback
|
|
50
|
+
* for value-dependent text. Returning empty / nullish means no
|
|
51
|
+
* tooltip - the renderer omits the `title=` attribute entirely.
|
|
52
|
+
*/
|
|
53
|
+
function computeCellTooltip(row, column) {
|
|
54
|
+
const raw = column.columnDef.tooltip;
|
|
55
|
+
if (raw == null)
|
|
56
|
+
return null;
|
|
57
|
+
if (typeof raw === "string")
|
|
58
|
+
return raw || null;
|
|
59
|
+
if (typeof raw === "function") {
|
|
60
|
+
const ctx = {
|
|
61
|
+
row,
|
|
62
|
+
column,
|
|
63
|
+
cell: undefined,
|
|
64
|
+
table: undefined,
|
|
65
|
+
getValue: () => row.getCellValueByColumnId(column.id),
|
|
66
|
+
};
|
|
67
|
+
const out = raw(ctx);
|
|
68
|
+
return out ? String(out) : null;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Resolve a per-cell note (a longer comment / annotation). Notes
|
|
74
|
+
* come from the grid's `notes` prop - a `{ [rowId]: { [columnId]: string } }`
|
|
75
|
+
* map - so the consumer keeps note storage. Returning non-empty
|
|
76
|
+
* paints a corner indicator AND becomes the cell's tooltip text.
|
|
77
|
+
*/
|
|
78
|
+
function computeCellNote(row, column) {
|
|
79
|
+
// Internal overlay (from the comment editor) wins over props.notes so
|
|
80
|
+
// edits show immediately even when `notes` is controlled. An empty
|
|
81
|
+
// overlay entry means "removed".
|
|
82
|
+
const ov = ctx.noteOverrides?.[row.id]?.[column.id];
|
|
83
|
+
if (ov !== undefined)
|
|
84
|
+
return ov.trim() ? ov : null;
|
|
85
|
+
const map = ctx.props.notes;
|
|
86
|
+
if (!map)
|
|
87
|
+
return null;
|
|
88
|
+
const byCol = map[row.id];
|
|
89
|
+
if (!byCol)
|
|
90
|
+
return null;
|
|
91
|
+
const v = byCol[column.id];
|
|
92
|
+
return v && v.trim() ? v : null;
|
|
93
|
+
}
|
|
94
|
+
function getColumnEditorOptions(column, row) {
|
|
95
|
+
const def = column.columnDef.editorOptions;
|
|
96
|
+
if (typeof def === "function") {
|
|
97
|
+
// Dynamic per-row: must be re-evaluated because the row's other
|
|
98
|
+
// cells may have just changed (cascade).
|
|
99
|
+
if (!row?.original)
|
|
100
|
+
return [];
|
|
101
|
+
return normalizeEditorOptions(def(row.original));
|
|
102
|
+
}
|
|
103
|
+
const id = column.id;
|
|
104
|
+
if (!ctx.editorOptionsCache[id] ||
|
|
105
|
+
ctx.editorOptionsCache[id + "__src"] !== def) {
|
|
106
|
+
ctx.editorOptionsCache[id] = normalizeEditorOptions(def);
|
|
107
|
+
ctx.editorOptionsCache[id + "__src"] = def;
|
|
108
|
+
}
|
|
109
|
+
return ctx.editorOptionsCache[id];
|
|
110
|
+
}
|
|
111
|
+
/** Joined display string for list/chips cells. */
|
|
112
|
+
function formatListCellValue(column, value, row) {
|
|
113
|
+
const options = getColumnEditorOptions(column, row);
|
|
114
|
+
const sep = column.columnDef.editorSeparator ?? ", ";
|
|
115
|
+
if (Array.isArray(value)) {
|
|
116
|
+
return value.map((v) => getOptionLabel(options, v)).join(sep);
|
|
117
|
+
}
|
|
118
|
+
if (value == null || value === "")
|
|
119
|
+
return "";
|
|
120
|
+
return getOptionLabel(options, value);
|
|
121
|
+
}
|
|
122
|
+
function formatCellValue(column, value, row) {
|
|
123
|
+
const formatter = column.columnDef.formatter;
|
|
124
|
+
if (typeof formatter === "function") {
|
|
125
|
+
const formatted = formatter({ value, row, column, table: ctx.grid });
|
|
126
|
+
return String(formatted ?? "");
|
|
127
|
+
}
|
|
128
|
+
// Password columns: mask the stored value with bullets when the cell
|
|
129
|
+
// is in read-only mode. The editor still receives the real string.
|
|
130
|
+
if (column.columnDef.editorType === "password") {
|
|
131
|
+
const s = String(value ?? "");
|
|
132
|
+
return s.length > 0 ? "•".repeat(Math.min(s.length, 12)) : "";
|
|
133
|
+
}
|
|
134
|
+
const formatConfig = column.columnDef.format;
|
|
135
|
+
if (!formatConfig)
|
|
136
|
+
return String(value ?? "");
|
|
137
|
+
if (formatConfig.type === "number" ||
|
|
138
|
+
formatConfig.type === "currency" ||
|
|
139
|
+
formatConfig.type === "percent") {
|
|
140
|
+
return formatNumericWithConfig(value, {
|
|
141
|
+
type: formatConfig.type,
|
|
142
|
+
locales: formatConfig.locales,
|
|
143
|
+
currency: formatConfig.type === "currency"
|
|
144
|
+
? (formatConfig.currency ?? "USD")
|
|
145
|
+
: undefined,
|
|
146
|
+
valueIsPercentPoints: formatConfig.type === "percent"
|
|
147
|
+
? formatConfig.valueIsPercentPoints
|
|
148
|
+
: undefined,
|
|
149
|
+
options: formatConfig.options,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (formatConfig.type === "date" || formatConfig.type === "datetime") {
|
|
153
|
+
const parsedDate = asDate(value);
|
|
154
|
+
if (parsedDate) {
|
|
155
|
+
const preset = resolveDatePattern(formatConfig.pattern, formatConfig.type);
|
|
156
|
+
const merged = preset || formatConfig.options
|
|
157
|
+
? { ...preset, ...formatConfig.options }
|
|
158
|
+
: formatConfig.type === "date"
|
|
159
|
+
? { year: "numeric", month: "2-digit", day: "2-digit" }
|
|
160
|
+
: {
|
|
161
|
+
year: "numeric",
|
|
162
|
+
month: "2-digit",
|
|
163
|
+
day: "2-digit",
|
|
164
|
+
hour: "2-digit",
|
|
165
|
+
minute: "2-digit",
|
|
166
|
+
};
|
|
167
|
+
return getDateFormatter(formatConfig.locales, merged).format(parsedDate);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return String(value ?? "");
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Format a cell value for a PINNED row. Same surface as
|
|
174
|
+
* `formatCellValue` but doesn't depend on Row<TData>. Custom
|
|
175
|
+
* `formatter` callbacks are invoked with a `row` of `null` (their
|
|
176
|
+
* type allows it; most don't read it).
|
|
177
|
+
*/
|
|
178
|
+
function formatPinnedValue(column, value) {
|
|
179
|
+
const def = column.columnDef;
|
|
180
|
+
const formatter = def.formatter;
|
|
181
|
+
if (typeof formatter === "function") {
|
|
182
|
+
return String(formatter({ value, row: null, column, table: ctx.grid }) ?? "");
|
|
183
|
+
}
|
|
184
|
+
if (def.editorType === "password") {
|
|
185
|
+
const s = String(value ?? "");
|
|
186
|
+
return s.length > 0 ? "•".repeat(Math.min(s.length, 12)) : "";
|
|
187
|
+
}
|
|
188
|
+
const formatConfig = def.format;
|
|
189
|
+
if (!formatConfig)
|
|
190
|
+
return String(value ?? "");
|
|
191
|
+
if (formatConfig.type === "number" ||
|
|
192
|
+
formatConfig.type === "currency" ||
|
|
193
|
+
formatConfig.type === "percent") {
|
|
194
|
+
return formatNumericWithConfig(value, {
|
|
195
|
+
type: formatConfig.type,
|
|
196
|
+
locales: formatConfig.locales,
|
|
197
|
+
currency: formatConfig.type === "currency"
|
|
198
|
+
? (formatConfig.currency ?? "USD")
|
|
199
|
+
: undefined,
|
|
200
|
+
valueIsPercentPoints: formatConfig.type === "percent"
|
|
201
|
+
? formatConfig.valueIsPercentPoints
|
|
202
|
+
: undefined,
|
|
203
|
+
options: formatConfig.options,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (formatConfig.type === "date" || formatConfig.type === "datetime") {
|
|
207
|
+
const parsedDate = asDate(value);
|
|
208
|
+
if (parsedDate) {
|
|
209
|
+
const preset = resolveDatePattern(formatConfig.pattern, formatConfig.type);
|
|
210
|
+
const merged = preset || formatConfig.options
|
|
211
|
+
? { ...preset, ...formatConfig.options }
|
|
212
|
+
: formatConfig.type === "date"
|
|
213
|
+
? { year: "numeric", month: "2-digit", day: "2-digit" }
|
|
214
|
+
: { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" };
|
|
215
|
+
return getDateFormatter(formatConfig.locales, merged).format(parsedDate);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return String(value ?? "");
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Resolve `cellClass` for a pinned row. We synthesise a minimal
|
|
222
|
+
* context `{ getValue, value, row: null, column }`; cell-class
|
|
223
|
+
* callbacks that read only the value (the common case) work
|
|
224
|
+
* unchanged.
|
|
225
|
+
*/
|
|
226
|
+
function computePinnedCellClass(rowData, column) {
|
|
227
|
+
const cellClass = column.columnDef.cellClass;
|
|
228
|
+
if (typeof cellClass !== "function")
|
|
229
|
+
return "";
|
|
230
|
+
const value = getPinnedCellValue(rowData, column);
|
|
231
|
+
const out = cellClass({ getValue: () => value, value, row: null, column });
|
|
232
|
+
return out ? String(out) : "";
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
cellConditionalFormat,
|
|
236
|
+
computeRowClass,
|
|
237
|
+
computeCellClass,
|
|
238
|
+
computeCellTooltip,
|
|
239
|
+
computeCellNote,
|
|
240
|
+
getColumnEditorOptions,
|
|
241
|
+
formatListCellValue,
|
|
242
|
+
formatCellValue,
|
|
243
|
+
formatPinnedValue,
|
|
244
|
+
computePinnedCellClass,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Column, ColumnDef, Row, RowData, TableFeatures } from "./index";
|
|
2
|
+
export declare function getColumnBaseValue<TData extends RowData>(row: Row<TData>, column: Column<TData>): unknown;
|
|
3
|
+
export declare function isGroupRow<TData extends RowData>(row: Row<TData>): boolean;
|
|
4
|
+
export declare function toolPanelHeaderLabel<TData extends RowData>(column: Column<TData>): string;
|
|
5
|
+
/** Apply the column's `format` config to a raw numeric summary value
|
|
6
|
+
* (sum / avg / etc.). Mirrors the currency/number/percent branches in
|
|
7
|
+
* `formatCellValue` so a totaled salary column shows "$1,234,567" in
|
|
8
|
+
* the footer instead of "1234567". Per-row `formatter` functions are
|
|
9
|
+
* intentionally NOT invoked here - they may close over row state. */
|
|
10
|
+
export declare function formatSummaryNumeric<TData extends RowData>(column: Column<TData>, value: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* Effective horizontal alignment for a column. Honors the explicit
|
|
13
|
+
* `align` prop on the ColumnDef; otherwise picks a sensible default
|
|
14
|
+
* based on `editorType`:
|
|
15
|
+
* number / date / datetime → 'right'
|
|
16
|
+
* checkbox → 'center'
|
|
17
|
+
* everything else → 'left'
|
|
18
|
+
*/
|
|
19
|
+
export declare function getColumnAlign<TData extends RowData>(column: Column<TData>): "left" | "center" | "right";
|
|
20
|
+
/**
|
|
21
|
+
* Read a cell value from a PINNED row. Pinned rows aren't bound to a
|
|
22
|
+
* TanStack Row<TData>, so we resolve the value directly off the raw
|
|
23
|
+
* TData via `accessorFn` or `field`. Mirrors `getColumnBaseValue`'s
|
|
24
|
+
* lookup path minus the Row indirection.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getPinnedCellValue<TData extends RowData>(rowData: TData, column: Column<TData>): unknown;
|
|
27
|
+
export declare function getColumnAccessorValue<TData extends RowData>(rowData: TData, column: Column<TData>): unknown;
|
|
28
|
+
export declare function columnDefMatchesId<TFeatures extends TableFeatures, TData extends RowData>(def: ColumnDef<TFeatures, TData>, columnId: string): boolean;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { formatNumericWithConfig } from "./cell-formatting";
|
|
2
|
+
export function getColumnBaseValue(row, column) {
|
|
3
|
+
const def = column.columnDef;
|
|
4
|
+
if (def.accessorFn)
|
|
5
|
+
return def.accessorFn(row.original);
|
|
6
|
+
if (def.field)
|
|
7
|
+
return row.original[def.field];
|
|
8
|
+
return row.getCellValueByColumnId(column.id);
|
|
9
|
+
}
|
|
10
|
+
export function isGroupRow(row) {
|
|
11
|
+
return typeof row.getCanExpand === "function" && row.getCanExpand();
|
|
12
|
+
}
|
|
13
|
+
export function toolPanelHeaderLabel(column) {
|
|
14
|
+
const h = column.columnDef.header;
|
|
15
|
+
return typeof h === "string" ? h : column.id;
|
|
16
|
+
}
|
|
17
|
+
/** Apply the column's `format` config to a raw numeric summary value
|
|
18
|
+
* (sum / avg / etc.). Mirrors the currency/number/percent branches in
|
|
19
|
+
* `formatCellValue` so a totaled salary column shows "$1,234,567" in
|
|
20
|
+
* the footer instead of "1234567". Per-row `formatter` functions are
|
|
21
|
+
* intentionally NOT invoked here - they may close over row state. */
|
|
22
|
+
export function formatSummaryNumeric(column, value) {
|
|
23
|
+
const formatConfig = column.columnDef.format;
|
|
24
|
+
if (formatConfig &&
|
|
25
|
+
(formatConfig.type === "number" ||
|
|
26
|
+
formatConfig.type === "currency" ||
|
|
27
|
+
formatConfig.type === "percent")) {
|
|
28
|
+
return formatNumericWithConfig(value, {
|
|
29
|
+
type: formatConfig.type,
|
|
30
|
+
locales: formatConfig.locales,
|
|
31
|
+
currency: formatConfig.type === "currency"
|
|
32
|
+
? (formatConfig.currency ?? "USD")
|
|
33
|
+
: undefined,
|
|
34
|
+
valueIsPercentPoints: formatConfig.type === "percent"
|
|
35
|
+
? formatConfig.valueIsPercentPoints
|
|
36
|
+
: undefined,
|
|
37
|
+
options: formatConfig.options,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return String(value);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Effective horizontal alignment for a column. Honors the explicit
|
|
44
|
+
* `align` prop on the ColumnDef; otherwise picks a sensible default
|
|
45
|
+
* based on `editorType`:
|
|
46
|
+
* number / date / datetime → 'right'
|
|
47
|
+
* checkbox → 'center'
|
|
48
|
+
* everything else → 'left'
|
|
49
|
+
*/
|
|
50
|
+
export function getColumnAlign(column) {
|
|
51
|
+
const explicit = column.columnDef.align;
|
|
52
|
+
if (explicit)
|
|
53
|
+
return explicit;
|
|
54
|
+
const editorType = column.columnDef.editorType;
|
|
55
|
+
if (editorType === "number" ||
|
|
56
|
+
editorType === "date" ||
|
|
57
|
+
editorType === "datetime") {
|
|
58
|
+
return "right";
|
|
59
|
+
}
|
|
60
|
+
if (editorType === "checkbox")
|
|
61
|
+
return "center";
|
|
62
|
+
return "left";
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Read a cell value from a PINNED row. Pinned rows aren't bound to a
|
|
66
|
+
* TanStack Row<TData>, so we resolve the value directly off the raw
|
|
67
|
+
* TData via `accessorFn` or `field`. Mirrors `getColumnBaseValue`'s
|
|
68
|
+
* lookup path minus the Row indirection.
|
|
69
|
+
*/
|
|
70
|
+
export function getPinnedCellValue(rowData, column) {
|
|
71
|
+
const def = column.columnDef;
|
|
72
|
+
if (def.accessorFn)
|
|
73
|
+
return def.accessorFn(rowData);
|
|
74
|
+
const field = def.field;
|
|
75
|
+
if (!field)
|
|
76
|
+
return undefined;
|
|
77
|
+
return rowData[field];
|
|
78
|
+
}
|
|
79
|
+
export function getColumnAccessorValue(rowData, column) {
|
|
80
|
+
const def = column.columnDef;
|
|
81
|
+
if (def.accessorFn)
|
|
82
|
+
return def.accessorFn(rowData);
|
|
83
|
+
if (def.field)
|
|
84
|
+
return rowData[def.field];
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
export function columnDefMatchesId(def, columnId) {
|
|
88
|
+
return (def.id ?? def.field ?? null) === columnId;
|
|
89
|
+
}
|