@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,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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createCellRender } from './cell-render';
|
|
3
|
+
function makeRow(id, data) {
|
|
4
|
+
return {
|
|
5
|
+
id,
|
|
6
|
+
original: data,
|
|
7
|
+
getCellValueByColumnId: (colId) => data[colId],
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function makeColumn(id, def = {}) {
|
|
11
|
+
return { id, columnDef: { ...def } };
|
|
12
|
+
}
|
|
13
|
+
function makeCtx(overrides = {}) {
|
|
14
|
+
return {
|
|
15
|
+
props: {},
|
|
16
|
+
grid: { id: 'grid' },
|
|
17
|
+
conditionalColumnStats: new Map(),
|
|
18
|
+
noteOverrides: {},
|
|
19
|
+
editorOptionsCache: {},
|
|
20
|
+
...overrides,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
describe('createCellRender / cellConditionalFormat', () => {
|
|
24
|
+
it('returns null when no conditionalFormats are configured', () => {
|
|
25
|
+
const cr = createCellRender(makeCtx());
|
|
26
|
+
const out = cr.cellConditionalFormat(makeRow('r1', { amt: 5 }), makeColumn('amt'), 5);
|
|
27
|
+
expect(out).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
it('returns null when conditionalFormats is an empty array', () => {
|
|
30
|
+
const cr = createCellRender(makeCtx({ props: { conditionalFormats: [] } }));
|
|
31
|
+
expect(cr.cellConditionalFormat(makeRow('r', {}), makeColumn('amt'), 1)).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
it('resolves a rule format against the value', () => {
|
|
34
|
+
const formats = [
|
|
35
|
+
{
|
|
36
|
+
type: 'rule',
|
|
37
|
+
columns: ['amt'],
|
|
38
|
+
when: ({ value }) => Number(value) > 10,
|
|
39
|
+
background: '#ff0000',
|
|
40
|
+
fontWeight: 700,
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
const cr = createCellRender(makeCtx({ props: { conditionalFormats: formats } }));
|
|
44
|
+
const hit = cr.cellConditionalFormat(makeRow('r', { amt: 20 }), makeColumn('amt'), 20);
|
|
45
|
+
expect(hit?.background).toBe('#ff0000');
|
|
46
|
+
expect(hit?.fontWeight).toBe(700);
|
|
47
|
+
const miss = cr.cellConditionalFormat(makeRow('r', { amt: 1 }), makeColumn('amt'), 1);
|
|
48
|
+
expect(miss).toEqual({});
|
|
49
|
+
});
|
|
50
|
+
it('passes the precomputed column stat through to colorScale formats', () => {
|
|
51
|
+
const formats = [{ type: 'colorScale', min: '#fff', max: '#000' }];
|
|
52
|
+
const stats = new Map([['amt', { min: 0, max: 100 }]]);
|
|
53
|
+
const cr = createCellRender(makeCtx({ props: { conditionalFormats: formats }, conditionalColumnStats: stats }));
|
|
54
|
+
const out = cr.cellConditionalFormat(makeRow('r', { amt: 50 }), makeColumn('amt'), 50);
|
|
55
|
+
expect(out).not.toBeNull();
|
|
56
|
+
expect(out?.background).toBeDefined();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('createCellRender / computeRowClass', () => {
|
|
60
|
+
it('returns empty string when no rowClass configured', () => {
|
|
61
|
+
const cr = createCellRender(makeCtx());
|
|
62
|
+
expect(cr.computeRowClass(makeRow('r', {}), 0)).toBe('');
|
|
63
|
+
});
|
|
64
|
+
it('resolves a string rowClass', () => {
|
|
65
|
+
const rowClass = vi.fn(() => 'highlight');
|
|
66
|
+
const cr = createCellRender(makeCtx({ props: { rowClass } }));
|
|
67
|
+
const row = makeRow('r', { a: 1 });
|
|
68
|
+
expect(cr.computeRowClass(row, 3)).toBe('highlight');
|
|
69
|
+
expect(rowClass).toHaveBeenCalledWith({ row: row.original, rowIndex: 3 });
|
|
70
|
+
});
|
|
71
|
+
it('resolves an array / object rowClass', () => {
|
|
72
|
+
const cr = createCellRender(makeCtx({ props: { rowClass: () => ['a', '', 'b'] } }));
|
|
73
|
+
expect(cr.computeRowClass(makeRow('r', {}), 0)).toBe('a b');
|
|
74
|
+
const cr2 = createCellRender(makeCtx({ props: { rowClass: () => ({ on: true, off: false }) } }));
|
|
75
|
+
expect(cr2.computeRowClass(makeRow('r', {}), 0)).toBe('on');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('createCellRender / computeCellClass', () => {
|
|
79
|
+
it('returns empty string when cellClass is null/undefined', () => {
|
|
80
|
+
const cr = createCellRender(makeCtx());
|
|
81
|
+
expect(cr.computeCellClass(makeRow('r', {}), makeColumn('a'))).toBe('');
|
|
82
|
+
});
|
|
83
|
+
it('resolves a string cellClass', () => {
|
|
84
|
+
const cr = createCellRender(makeCtx());
|
|
85
|
+
expect(cr.computeCellClass(makeRow('r', {}), makeColumn('a', { cellClass: 'red' }))).toBe('red');
|
|
86
|
+
});
|
|
87
|
+
it('resolves an array cellClass', () => {
|
|
88
|
+
const cr = createCellRender(makeCtx());
|
|
89
|
+
expect(cr.computeCellClass(makeRow('r', {}), makeColumn('a', { cellClass: ['x', 'y'] }))).toBe('x y');
|
|
90
|
+
});
|
|
91
|
+
it('invokes a function cellClass with a minimal cell context', () => {
|
|
92
|
+
const cellClass = vi.fn((c) => (c.getValue() > 5 ? 'big' : 'small'));
|
|
93
|
+
const cr = createCellRender(makeCtx());
|
|
94
|
+
const row = makeRow('r', { score: 9 });
|
|
95
|
+
expect(cr.computeCellClass(row, makeColumn('score', { cellClass }))).toBe('big');
|
|
96
|
+
expect(cellClass).toHaveBeenCalledTimes(1);
|
|
97
|
+
const passed = cellClass.mock.calls[0][0];
|
|
98
|
+
expect(passed.row).toBe(row);
|
|
99
|
+
expect(passed.getValue()).toBe(9);
|
|
100
|
+
});
|
|
101
|
+
it('returns empty string for an unsupported cellClass type (number)', () => {
|
|
102
|
+
const cr = createCellRender(makeCtx());
|
|
103
|
+
expect(cr.computeCellClass(makeRow('r', {}), makeColumn('a', { cellClass: 123 }))).toBe('');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('createCellRender / computeCellTooltip', () => {
|
|
107
|
+
it('returns null when no tooltip configured', () => {
|
|
108
|
+
const cr = createCellRender(makeCtx());
|
|
109
|
+
expect(cr.computeCellTooltip(makeRow('r', {}), makeColumn('a'))).toBeNull();
|
|
110
|
+
});
|
|
111
|
+
it('returns a static string tooltip, but null for empty string', () => {
|
|
112
|
+
const cr = createCellRender(makeCtx());
|
|
113
|
+
expect(cr.computeCellTooltip(makeRow('r', {}), makeColumn('a', { tooltip: 'help' }))).toBe('help');
|
|
114
|
+
expect(cr.computeCellTooltip(makeRow('r', {}), makeColumn('a', { tooltip: '' }))).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
it('invokes a function tooltip and stringifies the result', () => {
|
|
117
|
+
const tooltip = (c) => `val=${c.getValue()}`;
|
|
118
|
+
const cr = createCellRender(makeCtx());
|
|
119
|
+
const row = makeRow('r', { a: 42 });
|
|
120
|
+
expect(cr.computeCellTooltip(row, makeColumn('a', { tooltip }))).toBe('val=42');
|
|
121
|
+
});
|
|
122
|
+
it('returns null when the function tooltip returns a falsy value', () => {
|
|
123
|
+
const cr = createCellRender(makeCtx());
|
|
124
|
+
expect(cr.computeCellTooltip(makeRow('r', {}), makeColumn('a', { tooltip: () => '' }))).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
it('returns null for an unsupported tooltip type', () => {
|
|
127
|
+
const cr = createCellRender(makeCtx());
|
|
128
|
+
expect(cr.computeCellTooltip(makeRow('r', {}), makeColumn('a', { tooltip: 5 }))).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('createCellRender / computeCellNote', () => {
|
|
132
|
+
it('returns null when neither overrides nor notes have an entry', () => {
|
|
133
|
+
const cr = createCellRender(makeCtx());
|
|
134
|
+
expect(cr.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBeNull();
|
|
135
|
+
});
|
|
136
|
+
it('prefers the internal note override over props.notes', () => {
|
|
137
|
+
const cr = createCellRender(makeCtx({
|
|
138
|
+
noteOverrides: { r: { a: 'overlay' } },
|
|
139
|
+
props: { notes: { r: { a: 'stored' } } },
|
|
140
|
+
}));
|
|
141
|
+
expect(cr.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBe('overlay');
|
|
142
|
+
});
|
|
143
|
+
it('treats a blank override as a removal (null)', () => {
|
|
144
|
+
const cr = createCellRender(makeCtx({
|
|
145
|
+
noteOverrides: { r: { a: ' ' } },
|
|
146
|
+
props: { notes: { r: { a: 'stored' } } },
|
|
147
|
+
}));
|
|
148
|
+
expect(cr.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBeNull();
|
|
149
|
+
});
|
|
150
|
+
it('falls back to props.notes when no override exists', () => {
|
|
151
|
+
const cr = createCellRender(makeCtx({ props: { notes: { r: { a: 'stored note' } } } }));
|
|
152
|
+
expect(cr.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBe('stored note');
|
|
153
|
+
});
|
|
154
|
+
it('returns null for a whitespace-only stored note', () => {
|
|
155
|
+
const cr = createCellRender(makeCtx({ props: { notes: { r: { a: ' ' } } } }));
|
|
156
|
+
expect(cr.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBeNull();
|
|
157
|
+
});
|
|
158
|
+
it('returns null when the row or column is absent in the notes map', () => {
|
|
159
|
+
const cr = createCellRender(makeCtx({ props: { notes: { other: { a: 'x' } } } }));
|
|
160
|
+
expect(cr.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBeNull();
|
|
161
|
+
const cr2 = createCellRender(makeCtx({ props: { notes: { r: { b: 'x' } } } }));
|
|
162
|
+
expect(cr2.computeCellNote(makeRow('r', {}), makeColumn('a'))).toBeNull();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('createCellRender / getColumnEditorOptions', () => {
|
|
166
|
+
it('returns [] for a function editorOptions when row has no original', () => {
|
|
167
|
+
const cr = createCellRender(makeCtx());
|
|
168
|
+
const col = makeColumn('a', { editorOptions: () => [{ value: 1, label: 'one' }] });
|
|
169
|
+
expect(cr.getColumnEditorOptions(col, null)).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
it('evaluates a function editorOptions per row', () => {
|
|
172
|
+
const cr = createCellRender(makeCtx());
|
|
173
|
+
const col = makeColumn('a', {
|
|
174
|
+
editorOptions: (data) => [{ value: data.code, label: data.name }],
|
|
175
|
+
});
|
|
176
|
+
const row = makeRow('r', { code: 'x', name: 'X' });
|
|
177
|
+
const opts = cr.getColumnEditorOptions(col, row);
|
|
178
|
+
expect(opts).toEqual([{ value: 'x', label: 'X' }]);
|
|
179
|
+
});
|
|
180
|
+
it('caches normalized static editorOptions and reuses them', () => {
|
|
181
|
+
const ctx = makeCtx();
|
|
182
|
+
const cr = createCellRender(ctx);
|
|
183
|
+
const src = ['a', 'b'];
|
|
184
|
+
const col = makeColumn('a', { editorOptions: src });
|
|
185
|
+
const first = cr.getColumnEditorOptions(col);
|
|
186
|
+
const second = cr.getColumnEditorOptions(col);
|
|
187
|
+
expect(first).toBe(second); // same cached array reference
|
|
188
|
+
expect(ctx.editorOptionsCache['a']).toBe(first);
|
|
189
|
+
});
|
|
190
|
+
it('re-normalizes when the editorOptions source changes', () => {
|
|
191
|
+
const ctx = makeCtx();
|
|
192
|
+
const cr = createCellRender(ctx);
|
|
193
|
+
const first = cr.getColumnEditorOptions(makeColumn('a', { editorOptions: ['a'] }));
|
|
194
|
+
const second = cr.getColumnEditorOptions(makeColumn('a', { editorOptions: ['b'] }));
|
|
195
|
+
expect(first).not.toBe(second);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe('createCellRender / formatListCellValue', () => {
|
|
199
|
+
it('joins an array of values using the default separator', () => {
|
|
200
|
+
const cr = createCellRender(makeCtx());
|
|
201
|
+
const col = makeColumn('a', {
|
|
202
|
+
editorOptions: [
|
|
203
|
+
{ value: 1, label: 'One' },
|
|
204
|
+
{ value: 2, label: 'Two' },
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
expect(cr.formatListCellValue(col, [1, 2])).toBe('One, Two');
|
|
208
|
+
});
|
|
209
|
+
it('honors a custom editorSeparator', () => {
|
|
210
|
+
const cr = createCellRender(makeCtx());
|
|
211
|
+
const col = makeColumn('a', {
|
|
212
|
+
editorSeparator: ' | ',
|
|
213
|
+
editorOptions: [
|
|
214
|
+
{ value: 1, label: 'One' },
|
|
215
|
+
{ value: 2, label: 'Two' },
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
expect(cr.formatListCellValue(col, [1, 2])).toBe('One | Two');
|
|
219
|
+
});
|
|
220
|
+
it('returns empty string for null / empty scalar values', () => {
|
|
221
|
+
const cr = createCellRender(makeCtx());
|
|
222
|
+
const col = makeColumn('a', { editorOptions: [] });
|
|
223
|
+
expect(cr.formatListCellValue(col, null)).toBe('');
|
|
224
|
+
expect(cr.formatListCellValue(col, '')).toBe('');
|
|
225
|
+
});
|
|
226
|
+
it('maps a single scalar value to its label', () => {
|
|
227
|
+
const cr = createCellRender(makeCtx());
|
|
228
|
+
const col = makeColumn('a', {
|
|
229
|
+
editorOptions: [{ value: 'k', label: 'Known' }],
|
|
230
|
+
});
|
|
231
|
+
expect(cr.formatListCellValue(col, 'k')).toBe('Known');
|
|
232
|
+
// unknown value falls back to its string form
|
|
233
|
+
expect(cr.formatListCellValue(col, 'z')).toBe('z');
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
describe('createCellRender / formatCellValue', () => {
|
|
237
|
+
const row = makeRow('r', {});
|
|
238
|
+
it('uses a custom formatter callback when present', () => {
|
|
239
|
+
const cr = createCellRender(makeCtx());
|
|
240
|
+
const col = makeColumn('a', {
|
|
241
|
+
formatter: ({ value }) => `<<${value}>>`,
|
|
242
|
+
});
|
|
243
|
+
expect(cr.formatCellValue(col, 7, row)).toBe('<<7>>');
|
|
244
|
+
});
|
|
245
|
+
it('coerces a nullish formatter result to empty string', () => {
|
|
246
|
+
const cr = createCellRender(makeCtx());
|
|
247
|
+
const col = makeColumn('a', { formatter: () => null });
|
|
248
|
+
expect(cr.formatCellValue(col, 1, row)).toBe('');
|
|
249
|
+
});
|
|
250
|
+
it('masks password columns with bullets, capped at 12', () => {
|
|
251
|
+
const cr = createCellRender(makeCtx());
|
|
252
|
+
const col = makeColumn('a', { editorType: 'password' });
|
|
253
|
+
expect(cr.formatCellValue(col, 'abc', row)).toBe('•••');
|
|
254
|
+
expect(cr.formatCellValue(col, '', row)).toBe('');
|
|
255
|
+
expect(cr.formatCellValue(col, 'x'.repeat(50), row)).toBe('•'.repeat(12));
|
|
256
|
+
});
|
|
257
|
+
it('stringifies plain values when there is no format config', () => {
|
|
258
|
+
const cr = createCellRender(makeCtx());
|
|
259
|
+
const col = makeColumn('a');
|
|
260
|
+
expect(cr.formatCellValue(col, 'hello', row)).toBe('hello');
|
|
261
|
+
expect(cr.formatCellValue(col, null, row)).toBe('');
|
|
262
|
+
});
|
|
263
|
+
it('applies numeric / currency / percent format configs', () => {
|
|
264
|
+
const cr = createCellRender(makeCtx());
|
|
265
|
+
expect(cr.formatCellValue(makeColumn('a', { format: { type: 'number' } }), 1234.5, row)).toContain('1,234');
|
|
266
|
+
const cur = cr.formatCellValue(makeColumn('a', { format: { type: 'currency', currency: 'USD' } }), 1000, row);
|
|
267
|
+
expect(cur).toContain('$');
|
|
268
|
+
const pct = cr.formatCellValue(makeColumn('a', { format: { type: 'percent' } }), 0.25, row);
|
|
269
|
+
expect(pct).toContain('%');
|
|
270
|
+
});
|
|
271
|
+
it('formats date configs and falls back when the value is not a date', () => {
|
|
272
|
+
const cr = createCellRender(makeCtx());
|
|
273
|
+
const dateCol = makeColumn('a', { format: { type: 'date' } });
|
|
274
|
+
const out = cr.formatCellValue(dateCol, '2024-01-15T00:00:00Z', row);
|
|
275
|
+
expect(out).toMatch(/2024/);
|
|
276
|
+
// Unparseable -> returns String(value)
|
|
277
|
+
expect(cr.formatCellValue(dateCol, 'not-a-date', row)).toBe('not-a-date');
|
|
278
|
+
});
|
|
279
|
+
it('formats datetime configs with merged default options', () => {
|
|
280
|
+
const cr = createCellRender(makeCtx());
|
|
281
|
+
const col = makeColumn('a', { format: { type: 'datetime' } });
|
|
282
|
+
const out = cr.formatCellValue(col, '2024-03-10T13:45:00Z', row);
|
|
283
|
+
expect(out).toMatch(/2024/);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
describe('createCellRender / formatPinnedValue', () => {
|
|
287
|
+
it('invokes a formatter with a null row', () => {
|
|
288
|
+
const cr = createCellRender(makeCtx());
|
|
289
|
+
const formatter = vi.fn(({ value, row }) => `${value}:${row}`);
|
|
290
|
+
const col = makeColumn('a', { formatter });
|
|
291
|
+
expect(cr.formatPinnedValue(col, 5)).toBe('5:null');
|
|
292
|
+
expect(formatter.mock.calls[0][0].row).toBeNull();
|
|
293
|
+
});
|
|
294
|
+
it('masks password pinned values', () => {
|
|
295
|
+
const cr = createCellRender(makeCtx());
|
|
296
|
+
expect(cr.formatPinnedValue(makeColumn('a', { editorType: 'password' }), 'pw')).toBe('••');
|
|
297
|
+
expect(cr.formatPinnedValue(makeColumn('a', { editorType: 'password' }), '')).toBe('');
|
|
298
|
+
});
|
|
299
|
+
it('stringifies when no format config', () => {
|
|
300
|
+
const cr = createCellRender(makeCtx());
|
|
301
|
+
expect(cr.formatPinnedValue(makeColumn('a'), 'total')).toBe('total');
|
|
302
|
+
expect(cr.formatPinnedValue(makeColumn('a'), null)).toBe('');
|
|
303
|
+
});
|
|
304
|
+
it('applies numeric and date format configs', () => {
|
|
305
|
+
const cr = createCellRender(makeCtx());
|
|
306
|
+
expect(cr.formatPinnedValue(makeColumn('a', { format: { type: 'number' } }), 9999)).toContain('9,999');
|
|
307
|
+
const d = cr.formatPinnedValue(makeColumn('a', { format: { type: 'date' } }), '2022-06-01T00:00:00Z');
|
|
308
|
+
expect(d).toMatch(/2022/);
|
|
309
|
+
// unparseable date falls through to String()
|
|
310
|
+
expect(cr.formatPinnedValue(makeColumn('a', { format: { type: 'date' } }), 'xyz')).toBe('xyz');
|
|
311
|
+
});
|
|
312
|
+
it('formats datetime pinned configs', () => {
|
|
313
|
+
const cr = createCellRender(makeCtx());
|
|
314
|
+
const out = cr.formatPinnedValue(makeColumn('a', { format: { type: 'datetime' } }), '2021-12-31T08:00:00Z');
|
|
315
|
+
expect(out).toMatch(/2021/);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
describe('createCellRender / computePinnedCellClass', () => {
|
|
319
|
+
it('returns empty string when cellClass is not a function', () => {
|
|
320
|
+
const cr = createCellRender(makeCtx());
|
|
321
|
+
expect(cr.computePinnedCellClass({ a: 1 }, makeColumn('a', { cellClass: 'x' }))).toBe('');
|
|
322
|
+
});
|
|
323
|
+
it('invokes a function cellClass with a null row and the pinned value', () => {
|
|
324
|
+
const cr = createCellRender(makeCtx());
|
|
325
|
+
const cellClass = vi.fn((c) => (c.value > 0 ? 'pos' : 'neg'));
|
|
326
|
+
const col = makeColumn('a', {
|
|
327
|
+
cellClass,
|
|
328
|
+
field: 'a',
|
|
329
|
+
});
|
|
330
|
+
expect(cr.computePinnedCellClass({ a: 3 }, col)).toBe('pos');
|
|
331
|
+
expect(cellClass.mock.calls[0][0].row).toBeNull();
|
|
332
|
+
});
|
|
333
|
+
it('coerces a falsy cellClass result to empty string', () => {
|
|
334
|
+
const cr = createCellRender(makeCtx());
|
|
335
|
+
const col = makeColumn('a', { cellClass: () => undefined, field: 'a' });
|
|
336
|
+
expect(cr.computePinnedCellClass({ a: 1 }, col)).toBe('');
|
|
337
|
+
});
|
|
338
|
+
});
|
|
@@ -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;
|