@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { normalizeEditorOptions, parseEditorValue } from './cell-editors';
|
|
3
|
+
describe('normalizeEditorOptions', () => {
|
|
4
|
+
it('returns [] for undefined', () => {
|
|
5
|
+
expect(normalizeEditorOptions(undefined)).toEqual([]);
|
|
6
|
+
});
|
|
7
|
+
it('treats a function (mistakenly passed) as empty', () => {
|
|
8
|
+
// The type says functions are resolved earlier, but the guard handles it.
|
|
9
|
+
const fn = (() => []);
|
|
10
|
+
expect(normalizeEditorOptions(fn)).toEqual([]);
|
|
11
|
+
});
|
|
12
|
+
it('maps bare strings to { value, label }', () => {
|
|
13
|
+
expect(normalizeEditorOptions(['a', 'b'])).toEqual([
|
|
14
|
+
{ value: 'a', label: 'a' },
|
|
15
|
+
{ value: 'b', label: 'b' },
|
|
16
|
+
]);
|
|
17
|
+
});
|
|
18
|
+
it('maps bare numbers to stringified labels', () => {
|
|
19
|
+
expect(normalizeEditorOptions([1, 2])).toEqual([
|
|
20
|
+
{ value: 1, label: '1' },
|
|
21
|
+
{ value: 2, label: '2' },
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
it('keeps an explicit label and color', () => {
|
|
25
|
+
expect(normalizeEditorOptions([{ value: 'x', label: 'Ex', color: '#f00' }])).toEqual([{ value: 'x', label: 'Ex', color: '#f00' }]);
|
|
26
|
+
});
|
|
27
|
+
it('defaults a missing label to String(value)', () => {
|
|
28
|
+
expect(normalizeEditorOptions([{ value: 7 }])).toEqual([
|
|
29
|
+
{ value: 7, label: '7', color: undefined },
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('parseEditorValue - rating', () => {
|
|
34
|
+
it('rounds and clamps into 0..5', () => {
|
|
35
|
+
expect(parseEditorValue('rating', 3.4)).toBe(3);
|
|
36
|
+
expect(parseEditorValue('rating', 4.6)).toBe(5);
|
|
37
|
+
expect(parseEditorValue('rating', 9)).toBe(5);
|
|
38
|
+
expect(parseEditorValue('rating', -2)).toBe(0);
|
|
39
|
+
});
|
|
40
|
+
it('returns 0 for non-finite input', () => {
|
|
41
|
+
expect(parseEditorValue('rating', 'nope')).toBe(0);
|
|
42
|
+
expect(parseEditorValue('rating', Infinity)).toBe(0);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('parseEditorValue - color', () => {
|
|
46
|
+
it('returns the trimmed color string', () => {
|
|
47
|
+
expect(parseEditorValue('color', ' #abcdef ')).toBe('#abcdef');
|
|
48
|
+
});
|
|
49
|
+
it('passes non-hex color strings through', () => {
|
|
50
|
+
expect(parseEditorValue('color', 'rebeccapurple')).toBe('rebeccapurple');
|
|
51
|
+
});
|
|
52
|
+
it('falls back to #000000 for empty/nullish', () => {
|
|
53
|
+
expect(parseEditorValue('color', '')).toBe('#000000');
|
|
54
|
+
expect(parseEditorValue('color', null)).toBe('#000000');
|
|
55
|
+
expect(parseEditorValue('color', undefined)).toBe('#000000');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('parseEditorValue - time', () => {
|
|
59
|
+
it('returns null for empty input', () => {
|
|
60
|
+
expect(parseEditorValue('time', '')).toBe(null);
|
|
61
|
+
expect(parseEditorValue('time', null)).toBe(null);
|
|
62
|
+
});
|
|
63
|
+
it('returns null for malformed strings', () => {
|
|
64
|
+
expect(parseEditorValue('time', 'noon')).toBe(null);
|
|
65
|
+
expect(parseEditorValue('time', '12')).toBe(null);
|
|
66
|
+
});
|
|
67
|
+
it('normalizes HH:MM', () => {
|
|
68
|
+
expect(parseEditorValue('time', '9:05')).toBe('09:05');
|
|
69
|
+
});
|
|
70
|
+
it('keeps seconds when present', () => {
|
|
71
|
+
expect(parseEditorValue('time', '23:59:59')).toBe('23:59:59');
|
|
72
|
+
});
|
|
73
|
+
it('clamps out-of-range components', () => {
|
|
74
|
+
expect(parseEditorValue('time', '99:99:99')).toBe('23:59:59');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe('parseEditorValue - password', () => {
|
|
78
|
+
it('keeps an empty string instead of nulling it', () => {
|
|
79
|
+
expect(parseEditorValue('password', '')).toBe('');
|
|
80
|
+
});
|
|
81
|
+
it('stringifies and preserves content', () => {
|
|
82
|
+
expect(parseEditorValue('password', 'hunter2')).toBe('hunter2');
|
|
83
|
+
expect(parseEditorValue('password', null)).toBe('');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('parseEditorValue - select / rich-select', () => {
|
|
87
|
+
it('returns scalar value as-is', () => {
|
|
88
|
+
expect(parseEditorValue('select', 'one')).toBe('one');
|
|
89
|
+
expect(parseEditorValue('rich-select', 5)).toBe(5);
|
|
90
|
+
});
|
|
91
|
+
it('takes the first element of an array', () => {
|
|
92
|
+
expect(parseEditorValue('select', ['a', 'b'])).toBe('a');
|
|
93
|
+
});
|
|
94
|
+
it('coerces nullish to null', () => {
|
|
95
|
+
expect(parseEditorValue('select', null)).toBe(null);
|
|
96
|
+
expect(parseEditorValue('select', undefined)).toBe(null);
|
|
97
|
+
expect(parseEditorValue('rich-select', [])).toBe(null);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe('parseEditorValue - textarea', () => {
|
|
101
|
+
it('stringifies, nullish to empty', () => {
|
|
102
|
+
expect(parseEditorValue('textarea', 'multi\nline')).toBe('multi\nline');
|
|
103
|
+
expect(parseEditorValue('textarea', null)).toBe('');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('parseEditorValue - list / chips (single)', () => {
|
|
107
|
+
it('returns scalar as-is', () => {
|
|
108
|
+
expect(parseEditorValue('list', 'x')).toBe('x');
|
|
109
|
+
expect(parseEditorValue('chips', 7)).toBe(7);
|
|
110
|
+
});
|
|
111
|
+
it('takes first element of array', () => {
|
|
112
|
+
expect(parseEditorValue('list', ['a', 'b'])).toBe('a');
|
|
113
|
+
expect(parseEditorValue('chips', [])).toBe(null);
|
|
114
|
+
});
|
|
115
|
+
it('coerces nullish to null', () => {
|
|
116
|
+
expect(parseEditorValue('list', null)).toBe(null);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('parseEditorValue - list / chips (multiple)', () => {
|
|
120
|
+
it('clones an array', () => {
|
|
121
|
+
const input = ['a', 'b'];
|
|
122
|
+
const out = parseEditorValue('list', input, { multiple: true });
|
|
123
|
+
expect(out).toEqual(['a', 'b']);
|
|
124
|
+
expect(out).not.toBe(input);
|
|
125
|
+
});
|
|
126
|
+
it('returns [] for empty/nullish', () => {
|
|
127
|
+
expect(parseEditorValue('chips', null, { multiple: true })).toEqual([]);
|
|
128
|
+
expect(parseEditorValue('chips', '', { multiple: true })).toEqual([]);
|
|
129
|
+
});
|
|
130
|
+
it('wraps a scalar into a single-element array', () => {
|
|
131
|
+
expect(parseEditorValue('list', 'solo', { multiple: true })).toEqual(['solo']);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('parseEditorValue - unknown type fallback', () => {
|
|
135
|
+
it('stringifies, nullish to empty', () => {
|
|
136
|
+
expect(parseEditorValue('autocomplete', 'hey')).toBe('hey');
|
|
137
|
+
expect(parseEditorValue('autocomplete', undefined)).toBe('');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type CellEditorType = 'text' | 'number' | 'date' | 'datetime' | 'time' | 'password' | 'checkbox' | 'list' | 'chips' | 'select' | 'rich-select' | 'textarea' | 'color' | 'rating';
|
|
1
|
+
export type CellEditorType = 'text' | 'number' | 'date' | 'datetime' | 'time' | 'password' | 'checkbox' | 'list' | 'chips' | 'select' | 'rich-select' | 'autocomplete' | 'textarea' | 'color' | 'rating';
|
|
2
2
|
/** Normalized option used by list/chips editors. The optional `color`
|
|
3
3
|
* paints the chip - both in the in-cell readonly chips render and in
|
|
4
4
|
* the dropdown trigger when `renderChipsInTrigger` is on. Any CSS
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Column, RowData } from "./index";
|
|
2
|
+
export type FacetBucket = {
|
|
3
|
+
label: string;
|
|
4
|
+
numericMin: number;
|
|
5
|
+
numericMax: number;
|
|
6
|
+
isLast: boolean;
|
|
7
|
+
isDate: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function isBucketableColumn<TData extends RowData>(column: Column<TData>): {
|
|
10
|
+
isDate: boolean;
|
|
11
|
+
} | null;
|
|
12
|
+
export declare function buildBuckets<TData extends RowData>(column: Column<TData>, isDate: boolean, data: ReadonlyArray<TData>, getAccessor: (row: TData, column: Column<TData>) => unknown): Array<FacetBucket> | null;
|
|
13
|
+
export declare function isInBucket(num: number, bucket: FacetBucket): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { rawToNumber, formatFacetDate, formatFacetNumber } from "./SvGrid.helpers";
|
|
2
|
+
const FACET_BUCKET_THRESHOLD = 30;
|
|
3
|
+
const FACET_BUCKET_COUNT = 10;
|
|
4
|
+
export function isBucketableColumn(column) {
|
|
5
|
+
const editorType = column.columnDef.editorType;
|
|
6
|
+
if (editorType === "number")
|
|
7
|
+
return { isDate: false };
|
|
8
|
+
if (editorType === "date" || editorType === "datetime")
|
|
9
|
+
return { isDate: true };
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
export function buildBuckets(column, isDate, data, getAccessor) {
|
|
13
|
+
let min = Number.POSITIVE_INFINITY;
|
|
14
|
+
let max = Number.NEGATIVE_INFINITY;
|
|
15
|
+
const distinct = new Set();
|
|
16
|
+
for (const rowData of data) {
|
|
17
|
+
const num = rawToNumber(getAccessor(rowData, column), isDate);
|
|
18
|
+
if (!Number.isFinite(num))
|
|
19
|
+
continue;
|
|
20
|
+
distinct.add(num);
|
|
21
|
+
if (num < min)
|
|
22
|
+
min = num;
|
|
23
|
+
if (num > max)
|
|
24
|
+
max = num;
|
|
25
|
+
}
|
|
26
|
+
if (distinct.size <= FACET_BUCKET_THRESHOLD)
|
|
27
|
+
return null;
|
|
28
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || min === max)
|
|
29
|
+
return null;
|
|
30
|
+
const span = max - min;
|
|
31
|
+
const buckets = [];
|
|
32
|
+
for (let i = 0; i < FACET_BUCKET_COUNT; i += 1) {
|
|
33
|
+
const lo = min + (span * i) / FACET_BUCKET_COUNT;
|
|
34
|
+
const hi = min + (span * (i + 1)) / FACET_BUCKET_COUNT;
|
|
35
|
+
const label = isDate
|
|
36
|
+
? `${formatFacetDate(lo)} – ${formatFacetDate(hi)}`
|
|
37
|
+
: `${formatFacetNumber(lo)} – ${formatFacetNumber(hi)}`;
|
|
38
|
+
buckets.push({
|
|
39
|
+
label,
|
|
40
|
+
numericMin: lo,
|
|
41
|
+
numericMax: hi,
|
|
42
|
+
isLast: i === FACET_BUCKET_COUNT - 1,
|
|
43
|
+
isDate,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return buckets;
|
|
47
|
+
}
|
|
48
|
+
export function isInBucket(num, bucket) {
|
|
49
|
+
if (!Number.isFinite(num))
|
|
50
|
+
return false;
|
|
51
|
+
if (num < bucket.numericMin)
|
|
52
|
+
return false;
|
|
53
|
+
return bucket.isLast ? num <= bucket.numericMax : num < bucket.numericMax;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the facet value-bucketing helpers: isBucketableColumn,
|
|
3
|
+
* buildBuckets, isInBucket. These are pure functions - the only grid
|
|
4
|
+
* coupling is the Column type (we use createSvGrid to mint real columns
|
|
5
|
+
* carrying an `editorType`) and the rawToNumber/format helpers.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
import { createCoreRowModel, createSvGrid, tableFeatures, rowSortingFeature, } from './index';
|
|
9
|
+
import { isBucketableColumn, buildBuckets, isInBucket, } from './facet-buckets';
|
|
10
|
+
const features = tableFeatures({ rowSortingFeature });
|
|
11
|
+
/** Build a real grid and return its columns keyed by id so tests can grab
|
|
12
|
+
* a genuine Column<Row> object (with columnDef.editorType populated). */
|
|
13
|
+
function makeColumns() {
|
|
14
|
+
const columns = [
|
|
15
|
+
{ field: 'id', header: 'ID', editorType: 'text' },
|
|
16
|
+
{ field: 'num', header: 'Number', editorType: 'number' },
|
|
17
|
+
{ field: 'when', header: 'When', editorType: 'date' },
|
|
18
|
+
{ field: 'name', header: 'Name' }, // no editorType
|
|
19
|
+
{ field: 'flag', header: 'Flag', editorType: 'checkbox' },
|
|
20
|
+
];
|
|
21
|
+
const grid = createSvGrid({
|
|
22
|
+
_features: features,
|
|
23
|
+
_rowModels: { coreRowModel: createCoreRowModel() },
|
|
24
|
+
columns,
|
|
25
|
+
data: [],
|
|
26
|
+
});
|
|
27
|
+
const byId = {};
|
|
28
|
+
for (const c of grid.getAllColumns())
|
|
29
|
+
byId[c.id] = c;
|
|
30
|
+
return byId;
|
|
31
|
+
}
|
|
32
|
+
// Field accessor used by buildBuckets in production - read the property
|
|
33
|
+
// matching the column id off the row.
|
|
34
|
+
function accessor(row, column) {
|
|
35
|
+
return row[column.id];
|
|
36
|
+
}
|
|
37
|
+
describe('isBucketableColumn', () => {
|
|
38
|
+
const cols = makeColumns();
|
|
39
|
+
it('returns { isDate: false } for a number column', () => {
|
|
40
|
+
expect(isBucketableColumn(cols.num)).toEqual({ isDate: false });
|
|
41
|
+
});
|
|
42
|
+
it('returns { isDate: true } for a date column', () => {
|
|
43
|
+
expect(isBucketableColumn(cols.when)).toEqual({ isDate: true });
|
|
44
|
+
});
|
|
45
|
+
it('returns { isDate: true } for a datetime column', () => {
|
|
46
|
+
const grid = createSvGrid({
|
|
47
|
+
_features: features,
|
|
48
|
+
_rowModels: { coreRowModel: createCoreRowModel() },
|
|
49
|
+
columns: [{ field: 'when', header: 'When', editorType: 'datetime' }],
|
|
50
|
+
data: [],
|
|
51
|
+
});
|
|
52
|
+
const col = grid.getAllColumns().find((c) => c.id === 'when');
|
|
53
|
+
expect(isBucketableColumn(col)).toEqual({ isDate: true });
|
|
54
|
+
});
|
|
55
|
+
it('returns null for a text column', () => {
|
|
56
|
+
expect(isBucketableColumn(cols.id)).toBeNull();
|
|
57
|
+
});
|
|
58
|
+
it('returns null for a checkbox column', () => {
|
|
59
|
+
expect(isBucketableColumn(cols.flag)).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
it('returns null for a column with no editorType', () => {
|
|
62
|
+
expect(isBucketableColumn(cols.name)).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('buildBuckets - numeric', () => {
|
|
66
|
+
const cols = makeColumns();
|
|
67
|
+
it('returns null when distinct values do not exceed the threshold (30)', () => {
|
|
68
|
+
// 30 distinct values -> not > 30 -> null
|
|
69
|
+
const data = Array.from({ length: 30 }, (_, i) => ({
|
|
70
|
+
id: String(i),
|
|
71
|
+
num: i,
|
|
72
|
+
when: '',
|
|
73
|
+
name: '',
|
|
74
|
+
flag: false,
|
|
75
|
+
}));
|
|
76
|
+
expect(buildBuckets(cols.num, false, data, accessor)).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
it('builds 10 buckets when distinct values exceed the threshold', () => {
|
|
79
|
+
// 31 distinct values 0..30 -> > 30 -> buckets
|
|
80
|
+
const data = Array.from({ length: 31 }, (_, i) => ({
|
|
81
|
+
id: String(i),
|
|
82
|
+
num: i,
|
|
83
|
+
when: '',
|
|
84
|
+
name: '',
|
|
85
|
+
flag: false,
|
|
86
|
+
}));
|
|
87
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
88
|
+
expect(buckets).not.toBeNull();
|
|
89
|
+
expect(buckets).toHaveLength(10);
|
|
90
|
+
});
|
|
91
|
+
it('spans the full numeric range with contiguous edges', () => {
|
|
92
|
+
const data = Array.from({ length: 31 }, (_, i) => ({
|
|
93
|
+
id: String(i),
|
|
94
|
+
num: i, // 0..30
|
|
95
|
+
when: '',
|
|
96
|
+
name: '',
|
|
97
|
+
flag: false,
|
|
98
|
+
}));
|
|
99
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
100
|
+
expect(buckets[0].numericMin).toBe(0);
|
|
101
|
+
expect(buckets[9].numericMax).toBe(30);
|
|
102
|
+
// bucket i's max equals bucket i+1's min (contiguous, no gaps)
|
|
103
|
+
for (let i = 0; i < buckets.length - 1; i += 1) {
|
|
104
|
+
expect(buckets[i].numericMax).toBeCloseTo(buckets[i + 1].numericMin, 10);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
it('flags only the final bucket as isLast and sets isDate=false', () => {
|
|
108
|
+
const data = Array.from({ length: 31 }, (_, i) => ({
|
|
109
|
+
id: String(i),
|
|
110
|
+
num: i,
|
|
111
|
+
when: '',
|
|
112
|
+
name: '',
|
|
113
|
+
flag: false,
|
|
114
|
+
}));
|
|
115
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
116
|
+
expect(buckets.filter((b) => b.isLast)).toHaveLength(1);
|
|
117
|
+
expect(buckets[9].isLast).toBe(true);
|
|
118
|
+
expect(buckets[0].isLast).toBe(false);
|
|
119
|
+
expect(buckets.every((b) => b.isDate === false)).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
it('uses numeric labels containing an en-dash separator', () => {
|
|
122
|
+
const data = Array.from({ length: 31 }, (_, i) => ({
|
|
123
|
+
id: String(i),
|
|
124
|
+
num: i,
|
|
125
|
+
when: '',
|
|
126
|
+
name: '',
|
|
127
|
+
flag: false,
|
|
128
|
+
}));
|
|
129
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
130
|
+
expect(buckets[0].label).toContain('–');
|
|
131
|
+
});
|
|
132
|
+
it('ignores non-finite / blank values when computing min/max and distinct', () => {
|
|
133
|
+
// 31 numeric values plus a pile of null/undefined/empty/NaN-ish ones
|
|
134
|
+
const data = [
|
|
135
|
+
...Array.from({ length: 31 }, (_, i) => ({
|
|
136
|
+
id: String(i),
|
|
137
|
+
num: i,
|
|
138
|
+
when: '',
|
|
139
|
+
name: '',
|
|
140
|
+
flag: false,
|
|
141
|
+
})),
|
|
142
|
+
{ id: 'a', num: null, when: '', name: '', flag: false },
|
|
143
|
+
{ id: 'b', num: undefined, when: '', name: '', flag: false },
|
|
144
|
+
{ id: 'c', num: 'not-a-number', when: '', name: '', flag: false },
|
|
145
|
+
];
|
|
146
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
147
|
+
// range is still 0..30 - the junk rows were skipped
|
|
148
|
+
expect(buckets[0].numericMin).toBe(0);
|
|
149
|
+
expect(buckets[9].numericMax).toBe(30);
|
|
150
|
+
});
|
|
151
|
+
it('returns null when all finite values are identical (min === max)', () => {
|
|
152
|
+
// 40 rows but every num is 5 -> distinct.size === 1 -> <= threshold -> null.
|
|
153
|
+
// (Also exercises the min === max guard via a distinct-but-uniform case below.)
|
|
154
|
+
const data = Array.from({ length: 40 }, (_, i) => ({
|
|
155
|
+
id: String(i),
|
|
156
|
+
num: 5,
|
|
157
|
+
when: '',
|
|
158
|
+
name: '',
|
|
159
|
+
flag: false,
|
|
160
|
+
}));
|
|
161
|
+
expect(buildBuckets(cols.num, false, data, accessor)).toBeNull();
|
|
162
|
+
});
|
|
163
|
+
it('returns null when there is no finite data at all', () => {
|
|
164
|
+
const data = Array.from({ length: 40 }, (_, i) => ({
|
|
165
|
+
id: String(i),
|
|
166
|
+
num: null,
|
|
167
|
+
when: '',
|
|
168
|
+
name: '',
|
|
169
|
+
flag: false,
|
|
170
|
+
}));
|
|
171
|
+
expect(buildBuckets(cols.num, false, data, accessor)).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
it('returns null for an empty dataset', () => {
|
|
174
|
+
expect(buildBuckets(cols.num, false, [], accessor)).toBeNull();
|
|
175
|
+
});
|
|
176
|
+
it('handles negative ranges', () => {
|
|
177
|
+
const data = Array.from({ length: 41 }, (_, i) => ({
|
|
178
|
+
id: String(i),
|
|
179
|
+
num: i - 20, // -20..20, 41 distinct
|
|
180
|
+
when: '',
|
|
181
|
+
name: '',
|
|
182
|
+
flag: false,
|
|
183
|
+
}));
|
|
184
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
185
|
+
expect(buckets[0].numericMin).toBe(-20);
|
|
186
|
+
expect(buckets[9].numericMax).toBe(20);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
describe('buildBuckets - date', () => {
|
|
190
|
+
const cols = makeColumns();
|
|
191
|
+
it('builds buckets from date strings with isDate=true and date labels', () => {
|
|
192
|
+
const start = Date.UTC(2020, 0, 1);
|
|
193
|
+
const day = 24 * 60 * 60 * 1000;
|
|
194
|
+
const data = Array.from({ length: 40 }, (_, i) => ({
|
|
195
|
+
id: String(i),
|
|
196
|
+
num: 0,
|
|
197
|
+
when: new Date(start + i * day).toISOString(),
|
|
198
|
+
name: '',
|
|
199
|
+
flag: false,
|
|
200
|
+
}));
|
|
201
|
+
const buckets = buildBuckets(cols.when, true, data, accessor);
|
|
202
|
+
expect(buckets).toHaveLength(10);
|
|
203
|
+
expect(buckets.every((b) => b.isDate === true)).toBe(true);
|
|
204
|
+
// labels should look like dates (contain a 4-digit year)
|
|
205
|
+
expect(buckets[0].label).toMatch(/\d{4}/);
|
|
206
|
+
});
|
|
207
|
+
it('accepts Date instances directly', () => {
|
|
208
|
+
const start = Date.UTC(2020, 0, 1);
|
|
209
|
+
const day = 24 * 60 * 60 * 1000;
|
|
210
|
+
const data = Array.from({ length: 40 }, (_, i) => ({ id: 'when' + i, when: new Date(start + i * day) }));
|
|
211
|
+
// accessor reads row[column.id]; column id is 'when'
|
|
212
|
+
const rows = data.map((d) => ({ when: d.when }));
|
|
213
|
+
const buckets = buildBuckets(cols.when, true, rows, accessor);
|
|
214
|
+
expect(buckets).toHaveLength(10);
|
|
215
|
+
expect(buckets[0].numericMin).toBe(start);
|
|
216
|
+
});
|
|
217
|
+
it('returns null when date values are too few', () => {
|
|
218
|
+
const data = Array.from({ length: 5 }, (_, i) => ({
|
|
219
|
+
id: String(i),
|
|
220
|
+
num: 0,
|
|
221
|
+
when: new Date(Date.UTC(2020, 0, 1 + i)).toISOString(),
|
|
222
|
+
name: '',
|
|
223
|
+
flag: false,
|
|
224
|
+
}));
|
|
225
|
+
expect(buildBuckets(cols.when, true, data, accessor)).toBeNull();
|
|
226
|
+
});
|
|
227
|
+
it('skips invalid date strings', () => {
|
|
228
|
+
const start = Date.UTC(2021, 0, 1);
|
|
229
|
+
const day = 24 * 60 * 60 * 1000;
|
|
230
|
+
const data = [
|
|
231
|
+
...Array.from({ length: 40 }, (_, i) => ({
|
|
232
|
+
id: String(i),
|
|
233
|
+
num: 0,
|
|
234
|
+
when: new Date(start + i * day).toISOString(),
|
|
235
|
+
name: '',
|
|
236
|
+
flag: false,
|
|
237
|
+
})),
|
|
238
|
+
{ id: 'bad', num: 0, when: 'not-a-date', name: '', flag: false },
|
|
239
|
+
];
|
|
240
|
+
const buckets = buildBuckets(cols.when, true, data, accessor);
|
|
241
|
+
expect(buckets).toHaveLength(10);
|
|
242
|
+
expect(buckets[0].numericMin).toBe(start);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
describe('isInBucket', () => {
|
|
246
|
+
const mid = {
|
|
247
|
+
label: '10 - 20',
|
|
248
|
+
numericMin: 10,
|
|
249
|
+
numericMax: 20,
|
|
250
|
+
isLast: false,
|
|
251
|
+
isDate: false,
|
|
252
|
+
};
|
|
253
|
+
const last = {
|
|
254
|
+
label: '20 - 30',
|
|
255
|
+
numericMin: 20,
|
|
256
|
+
numericMax: 30,
|
|
257
|
+
isLast: true,
|
|
258
|
+
isDate: false,
|
|
259
|
+
};
|
|
260
|
+
it('returns false for non-finite numbers', () => {
|
|
261
|
+
expect(isInBucket(Number.NaN, mid)).toBe(false);
|
|
262
|
+
expect(isInBucket(Number.POSITIVE_INFINITY, mid)).toBe(false);
|
|
263
|
+
});
|
|
264
|
+
it('returns false below the lower bound', () => {
|
|
265
|
+
expect(isInBucket(9.999, mid)).toBe(false);
|
|
266
|
+
});
|
|
267
|
+
it('includes the lower bound', () => {
|
|
268
|
+
expect(isInBucket(10, mid)).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
it('excludes the upper bound for a non-last bucket (half-open interval)', () => {
|
|
271
|
+
expect(isInBucket(20, mid)).toBe(false);
|
|
272
|
+
expect(isInBucket(19.999, mid)).toBe(true);
|
|
273
|
+
});
|
|
274
|
+
it('includes the upper bound for the last bucket (closed interval)', () => {
|
|
275
|
+
expect(isInBucket(30, last)).toBe(true);
|
|
276
|
+
expect(isInBucket(20, last)).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
it('rejects values past the upper bound even on the last bucket', () => {
|
|
279
|
+
expect(isInBucket(30.0001, last)).toBe(false);
|
|
280
|
+
});
|
|
281
|
+
it('partitions a value into exactly one bucket across a built set', () => {
|
|
282
|
+
const cols = makeColumns();
|
|
283
|
+
const data = Array.from({ length: 101 }, (_, i) => ({
|
|
284
|
+
id: String(i),
|
|
285
|
+
num: i, // 0..100
|
|
286
|
+
when: '',
|
|
287
|
+
name: '',
|
|
288
|
+
flag: false,
|
|
289
|
+
}));
|
|
290
|
+
const buckets = buildBuckets(cols.num, false, data, accessor);
|
|
291
|
+
for (const v of [0, 1, 15, 50, 99, 100]) {
|
|
292
|
+
const hits = buckets.filter((b) => isInBucket(v, b));
|
|
293
|
+
expect(hits).toHaveLength(1);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type RowData, type TableFeatures } from "./index";
|
|
2
|
+
import "./sv-grid-scrollbar";
|
|
3
|
+
export declare function createFeatures<TFeatures extends TableFeatures = TableFeatures, TData extends RowData = RowData>(ctx: any): {
|
|
4
|
+
resolveEffectiveFeatures: () => TableFeatures;
|
|
5
|
+
};
|
package/dist/features.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// features 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 { tableFeatures, rowSortingFeature, columnFilteringFeature, columnGroupingFeature, } from "./index";
|
|
5
|
+
import "./sv-grid-scrollbar";
|
|
6
|
+
export function createFeatures(ctx) {
|
|
7
|
+
// Merge the consumer's `features` set with whatever the boolean shortcuts
|
|
8
|
+
// imply. A shortcut set to `true` injects its feature; set to `false` it
|
|
9
|
+
// removes it (so `sortable={false}` wins even if `rowSortingFeature` was
|
|
10
|
+
// passed in `features`); left undefined it defers to `features`.
|
|
11
|
+
function resolveEffectiveFeatures() {
|
|
12
|
+
const merged = { ...(ctx.props.features ?? {}) };
|
|
13
|
+
if (ctx.props.sortable === true)
|
|
14
|
+
merged.rowSortingFeature = rowSortingFeature;
|
|
15
|
+
else if (ctx.props.sortable === false)
|
|
16
|
+
delete merged.rowSortingFeature;
|
|
17
|
+
if (ctx.props.filterable === true)
|
|
18
|
+
merged.columnFilteringFeature = columnFilteringFeature;
|
|
19
|
+
else if (ctx.props.filterable === false)
|
|
20
|
+
delete merged.columnFilteringFeature;
|
|
21
|
+
if (ctx.props.groupable === true)
|
|
22
|
+
merged.columnGroupingFeature = columnGroupingFeature;
|
|
23
|
+
else if (ctx.props.groupable === false)
|
|
24
|
+
delete merged.columnGroupingFeature;
|
|
25
|
+
return tableFeatures(merged);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
resolveEffectiveFeatures,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Column, RowData } from "./index";
|
|
2
|
+
import type { FilterOperator, FilterOption } from "./SvGrid.types";
|
|
3
|
+
export declare const filterOperatorOptions: Array<FilterOption>;
|
|
4
|
+
/** Which operators make sense for each column editor type. */
|
|
5
|
+
export declare const TEXT_OPERATORS: Array<FilterOperator>;
|
|
6
|
+
export declare const NUMBER_OPERATORS: Array<FilterOperator>;
|
|
7
|
+
export declare const DATE_OPERATORS: Array<FilterOperator>;
|
|
8
|
+
export declare const CHECKBOX_OPERATORS: Array<FilterOperator>;
|
|
9
|
+
export declare const fallbackOperatorOption: FilterOption;
|
|
10
|
+
export declare function operatorOption(value: FilterOperator): FilterOption;
|
|
11
|
+
/** Returns the operators that make sense for the given column's data type. */
|
|
12
|
+
export declare function operatorsForColumn<TData extends RowData>(column: Column<TData> | undefined): Array<FilterOption>;
|
|
13
|
+
/** Default operator for a column (first one valid for its type). */
|
|
14
|
+
export declare function defaultOperatorFor<TData extends RowData>(column: Column<TData> | undefined): FilterOperator;
|
|
15
|
+
/** Date columns get friendlier labels for "less / greater than". */
|
|
16
|
+
export declare function operatorLabelFor<TData extends RowData>(option: FilterOption, column: Column<TData> | undefined): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export const filterOperatorOptions = [
|
|
2
|
+
{ value: "contains", label: "Contains", iconName: "op-contains" },
|
|
3
|
+
{ value: "equals", label: "Equals", iconName: "op-equals" },
|
|
4
|
+
{ value: "startsWith", label: "Starts with", iconName: "op-startsWith" },
|
|
5
|
+
{ value: "greaterThan", label: "Greater than", iconName: "op-greaterThan" },
|
|
6
|
+
{ value: "lessThan", label: "Less than", iconName: "op-lessThan" },
|
|
7
|
+
{ value: "between", label: "Between", iconName: "op-between" },
|
|
8
|
+
{ value: "isBlank", label: "Is blank", iconName: "op-isBlank" },
|
|
9
|
+
];
|
|
10
|
+
/** Which operators make sense for each column editor type. */
|
|
11
|
+
export const TEXT_OPERATORS = [
|
|
12
|
+
"contains",
|
|
13
|
+
"equals",
|
|
14
|
+
"startsWith",
|
|
15
|
+
"isBlank",
|
|
16
|
+
];
|
|
17
|
+
export const NUMBER_OPERATORS = [
|
|
18
|
+
"equals",
|
|
19
|
+
"greaterThan",
|
|
20
|
+
"lessThan",
|
|
21
|
+
"between",
|
|
22
|
+
"isBlank",
|
|
23
|
+
];
|
|
24
|
+
export const DATE_OPERATORS = [
|
|
25
|
+
"equals",
|
|
26
|
+
"lessThan",
|
|
27
|
+
"greaterThan",
|
|
28
|
+
"between",
|
|
29
|
+
"isBlank",
|
|
30
|
+
];
|
|
31
|
+
export const CHECKBOX_OPERATORS = ["equals", "isBlank"];
|
|
32
|
+
export const fallbackOperatorOption = {
|
|
33
|
+
value: "contains",
|
|
34
|
+
label: "Contains",
|
|
35
|
+
iconName: "op-contains",
|
|
36
|
+
};
|
|
37
|
+
export function operatorOption(value) {
|
|
38
|
+
return (filterOperatorOptions.find((option) => option.value === value) ??
|
|
39
|
+
fallbackOperatorOption);
|
|
40
|
+
}
|
|
41
|
+
/** Returns the operators that make sense for the given column's data type. */
|
|
42
|
+
export function operatorsForColumn(column) {
|
|
43
|
+
const editorType = column?.columnDef.editorType ?? "text";
|
|
44
|
+
const ids = editorType === "number"
|
|
45
|
+
? NUMBER_OPERATORS
|
|
46
|
+
: editorType === "date" || editorType === "datetime"
|
|
47
|
+
? DATE_OPERATORS
|
|
48
|
+
: editorType === "checkbox"
|
|
49
|
+
? CHECKBOX_OPERATORS
|
|
50
|
+
: TEXT_OPERATORS;
|
|
51
|
+
return ids
|
|
52
|
+
.map((id) => filterOperatorOptions.find((option) => option.value === id))
|
|
53
|
+
.filter((option) => Boolean(option));
|
|
54
|
+
}
|
|
55
|
+
/** Default operator for a column (first one valid for its type). */
|
|
56
|
+
export function defaultOperatorFor(column) {
|
|
57
|
+
return operatorsForColumn(column)[0]?.value ?? "contains";
|
|
58
|
+
}
|
|
59
|
+
/** Date columns get friendlier labels for "less / greater than". */
|
|
60
|
+
export function operatorLabelFor(option, column) {
|
|
61
|
+
const editorType = column?.columnDef.editorType;
|
|
62
|
+
if (editorType === "date" || editorType === "datetime") {
|
|
63
|
+
if (option.value === "lessThan")
|
|
64
|
+
return "Before";
|
|
65
|
+
if (option.value === "greaterThan")
|
|
66
|
+
return "After";
|
|
67
|
+
}
|
|
68
|
+
return option.label;
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|