@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
package/src/menus.ts
ADDED
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
// menus 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 {
|
|
5
|
+
applyExcelFilter,
|
|
6
|
+
normalizeForFilter,
|
|
7
|
+
createColumnVirtualizer,
|
|
8
|
+
createCoreRowModel,
|
|
9
|
+
createExpandedRowModel,
|
|
10
|
+
createFilteredRowModel,
|
|
11
|
+
createGroupedRowModel,
|
|
12
|
+
createPaginatedRowModel,
|
|
13
|
+
createSvelteVirtualizer,
|
|
14
|
+
createSortedRowModel,
|
|
15
|
+
createSvGrid,
|
|
16
|
+
filterFns,
|
|
17
|
+
getGridCellA11yProps,
|
|
18
|
+
getGridCellDomId,
|
|
19
|
+
getGridHeaderA11yProps,
|
|
20
|
+
getGridRootA11yProps,
|
|
21
|
+
getGridRowA11yProps,
|
|
22
|
+
parseEditorValue,
|
|
23
|
+
normalizeEditorOptions,
|
|
24
|
+
sortFns,
|
|
25
|
+
tableFeatures,
|
|
26
|
+
rowSortingFeature,
|
|
27
|
+
columnFilteringFeature,
|
|
28
|
+
columnGroupingFeature,
|
|
29
|
+
type CellContext,
|
|
30
|
+
type EditorContext,
|
|
31
|
+
type CellEditorOption,
|
|
32
|
+
type CellEditorType,
|
|
33
|
+
type CellFormatter,
|
|
34
|
+
type CellFormatConfig,
|
|
35
|
+
type Column,
|
|
36
|
+
type ColumnDef,
|
|
37
|
+
type Row,
|
|
38
|
+
type RowData,
|
|
39
|
+
type SvGridApi,
|
|
40
|
+
type TableFeatures,
|
|
41
|
+
} from "./index";
|
|
42
|
+
import "./sv-grid-scrollbar";
|
|
43
|
+
import type { Snippet } from "svelte";
|
|
44
|
+
import { getKeyboardIntent, getNextActiveCell } from "./keyboard";
|
|
45
|
+
import {
|
|
46
|
+
formatNumericWithConfig,
|
|
47
|
+
getDateFormatter,
|
|
48
|
+
resolveDatePattern,
|
|
49
|
+
} from "./cell-formatting";
|
|
50
|
+
import {
|
|
51
|
+
RenderSnippetConfig,
|
|
52
|
+
RenderComponentConfig,
|
|
53
|
+
} from "./render-component";
|
|
54
|
+
import { buildFillPattern } from "./fill-patterns";
|
|
55
|
+
import { buildSparkline, toSparklineValues } from "./sparkline";
|
|
56
|
+
import {
|
|
57
|
+
resolveCellFormat,
|
|
58
|
+
computeColumnStat,
|
|
59
|
+
formatsNeedingStats,
|
|
60
|
+
type ColumnStat,
|
|
61
|
+
type ResolvedCellFormat,
|
|
62
|
+
} from "./conditional-formatting";
|
|
63
|
+
import SvGridDropdown from "./SvGridDropdown.svelte";
|
|
64
|
+
import type {
|
|
65
|
+
Props,
|
|
66
|
+
SelectionPoint,
|
|
67
|
+
SelectionRange,
|
|
68
|
+
CellEditState,
|
|
69
|
+
FilterOperator,
|
|
70
|
+
FilterOption,
|
|
71
|
+
MenuPosition,
|
|
72
|
+
} from "./SvGrid.types";
|
|
73
|
+
import {
|
|
74
|
+
cfTextStyle,
|
|
75
|
+
fmtStat,
|
|
76
|
+
getCellKey,
|
|
77
|
+
resolveClassList,
|
|
78
|
+
toDateInputValue,
|
|
79
|
+
toDateTimeLocalInputValue,
|
|
80
|
+
getEditableInputValue,
|
|
81
|
+
getEditorInputType,
|
|
82
|
+
toValueArray,
|
|
83
|
+
getOptionLabel,
|
|
84
|
+
getOptionColor,
|
|
85
|
+
colorfulChipStyle,
|
|
86
|
+
getEditorClass,
|
|
87
|
+
asDate,
|
|
88
|
+
clampMenuX,
|
|
89
|
+
cssEscape,
|
|
90
|
+
rawToNumber,
|
|
91
|
+
formatFacetNumber,
|
|
92
|
+
formatFacetDate,
|
|
93
|
+
} from "./SvGrid.helpers";
|
|
94
|
+
import { createCellRender } from "./cell-render";
|
|
95
|
+
import { createEditing } from "./editing";
|
|
96
|
+
import { createSelection } from "./selection";
|
|
97
|
+
import { createColumns } from "./columns";
|
|
98
|
+
import { createGridApi } from "./build-api";
|
|
99
|
+
import { createClipboard } from "./clipboard";
|
|
100
|
+
import {
|
|
101
|
+
filterOperatorOptions,
|
|
102
|
+
fallbackOperatorOption,
|
|
103
|
+
TEXT_OPERATORS,
|
|
104
|
+
NUMBER_OPERATORS,
|
|
105
|
+
DATE_OPERATORS,
|
|
106
|
+
CHECKBOX_OPERATORS,
|
|
107
|
+
operatorOption,
|
|
108
|
+
operatorsForColumn,
|
|
109
|
+
defaultOperatorFor,
|
|
110
|
+
operatorLabelFor,
|
|
111
|
+
} from "./filter-operators";
|
|
112
|
+
import {
|
|
113
|
+
type FacetBucket,
|
|
114
|
+
isBucketableColumn,
|
|
115
|
+
buildBuckets,
|
|
116
|
+
isInBucket,
|
|
117
|
+
} from "./facet-buckets";
|
|
118
|
+
import {
|
|
119
|
+
getColumnBaseValue,
|
|
120
|
+
isGroupRow,
|
|
121
|
+
toolPanelHeaderLabel,
|
|
122
|
+
formatSummaryNumeric,
|
|
123
|
+
getColumnAlign,
|
|
124
|
+
getPinnedCellValue,
|
|
125
|
+
getColumnAccessorValue,
|
|
126
|
+
columnDefMatchesId,
|
|
127
|
+
} from "./cell-values";
|
|
128
|
+
|
|
129
|
+
export function createMenus<
|
|
130
|
+
TFeatures extends TableFeatures = TableFeatures,
|
|
131
|
+
TData extends RowData = RowData,
|
|
132
|
+
>(ctx: any) {
|
|
133
|
+
function updateFilterRow(columnId: string, value: string) {
|
|
134
|
+
ctx.filterRowValues = { ...ctx.filterRowValues, [columnId]: value };
|
|
135
|
+
const current = ctx.filterMenuValues[columnId] ?? {
|
|
136
|
+
operator: "contains" as const,
|
|
137
|
+
value: "",
|
|
138
|
+
};
|
|
139
|
+
ctx.filterMenuValues = {
|
|
140
|
+
...ctx.filterMenuValues,
|
|
141
|
+
[columnId]: { ...current, value },
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function updateFilterOperator(columnId: string, operator: FilterOperator) {
|
|
146
|
+
const current = ctx.filterMenuValues[columnId] ?? {
|
|
147
|
+
operator: "contains" as const,
|
|
148
|
+
value: "",
|
|
149
|
+
};
|
|
150
|
+
ctx.filterMenuValues = {
|
|
151
|
+
...ctx.filterMenuValues,
|
|
152
|
+
[columnId]: { ...current, operator },
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function updateFilterMenuValue(columnId: string, value: string) {
|
|
157
|
+
const current = ctx.filterMenuValues[columnId] ?? {
|
|
158
|
+
operator: "contains" as const,
|
|
159
|
+
value: "",
|
|
160
|
+
};
|
|
161
|
+
ctx.filterMenuValues = {
|
|
162
|
+
...ctx.filterMenuValues,
|
|
163
|
+
[columnId]: { ...current, value },
|
|
164
|
+
};
|
|
165
|
+
ctx.filterRowValues = { ...ctx.filterRowValues, [columnId]: value };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Upper-bound input for the `between` operator. Only relevant when
|
|
169
|
+
* the column's current operator is `between`; harmless to call
|
|
170
|
+
* otherwise. */
|
|
171
|
+
function updateFilterMenuValueTo(columnId: string, valueTo: string) {
|
|
172
|
+
const current = ctx.filterMenuValues[columnId] ?? {
|
|
173
|
+
operator: "between" as const,
|
|
174
|
+
value: "",
|
|
175
|
+
};
|
|
176
|
+
ctx.filterMenuValues = {
|
|
177
|
+
...ctx.filterMenuValues,
|
|
178
|
+
[columnId]: { ...current, valueTo },
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function toggleCheckboxWithKeyboard(
|
|
183
|
+
event: KeyboardEvent,
|
|
184
|
+
toggle: () => void,
|
|
185
|
+
) {
|
|
186
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
toggle();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function isColumnFiltered(columnId: string) {
|
|
192
|
+
if (ctx.valueFilters[columnId]) return true;
|
|
193
|
+
const menuFilter = ctx.filterMenuValues[columnId];
|
|
194
|
+
return Boolean(
|
|
195
|
+
menuFilter &&
|
|
196
|
+
(menuFilter.operator === "isBlank" || menuFilter.value.trim()),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function closeMenus() {
|
|
201
|
+
ctx.columnMenuFor = null;
|
|
202
|
+
ctx.filterMenuFor = null;
|
|
203
|
+
ctx.operatorMenuFor = null;
|
|
204
|
+
ctx.chooseColumnsPos = null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function openChooseColumns(event: MouseEvent) {
|
|
208
|
+
event.stopPropagation();
|
|
209
|
+
// Submenu behavior: keep the parent operations menu open and float the
|
|
210
|
+
// Choose Columns panel out to the right of it (AG-Grid style). Falls
|
|
211
|
+
// back to below the item if the popover would clip the viewport.
|
|
212
|
+
const trigger = event.currentTarget as HTMLElement;
|
|
213
|
+
const menuEl = trigger.closest(".sv-grid-menu") as HTMLElement | null;
|
|
214
|
+
const anchor = (menuEl ?? trigger).getBoundingClientRect();
|
|
215
|
+
const panelWidth = 240;
|
|
216
|
+
const wantRight = anchor.right + 4;
|
|
217
|
+
const x =
|
|
218
|
+
wantRight + panelWidth + 8 > window.innerWidth
|
|
219
|
+
? clampMenuX(anchor.left - panelWidth - 4, panelWidth)
|
|
220
|
+
: clampMenuX(wantRight, panelWidth);
|
|
221
|
+
ctx.chooseColumnsPos = { x, y: anchor.top };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function openColumnMenu(event: MouseEvent, columnId: string) {
|
|
225
|
+
event.stopPropagation();
|
|
226
|
+
const wasOpen = ctx.columnMenuFor === columnId;
|
|
227
|
+
closeMenus();
|
|
228
|
+
if (wasOpen) return;
|
|
229
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
|
230
|
+
ctx.columnMenuPos = {
|
|
231
|
+
x: clampMenuX(rect.right - 240, 240),
|
|
232
|
+
y: rect.bottom + 4,
|
|
233
|
+
};
|
|
234
|
+
ctx.columnMenuTab = "general";
|
|
235
|
+
ctx.columnMenuFor = columnId;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function openFilterMenu(event: MouseEvent, columnId: string) {
|
|
239
|
+
event.stopPropagation();
|
|
240
|
+
const wasOpen = ctx.filterMenuFor === columnId;
|
|
241
|
+
closeMenus();
|
|
242
|
+
if (wasOpen) return;
|
|
243
|
+
|
|
244
|
+
// If the consumer is running in row-mode (or any mode where the
|
|
245
|
+
// funnel popover wouldn't render), redirect the click to the
|
|
246
|
+
// inline filter input for this column. Without this the funnel
|
|
247
|
+
// would be a dead button - it visibly clicks but nothing happens
|
|
248
|
+
// because the menu is gated behind `showColumnFiltersEffective`.
|
|
249
|
+
if (!ctx.showColumnFiltersEffective && ctx.showFilterRowEffective) {
|
|
250
|
+
// Find the row-mode filter input and focus it. The input is
|
|
251
|
+
// tagged with `data-svgrid-filter-col` so we can target by id
|
|
252
|
+
// without depending on column position.
|
|
253
|
+
const input = (ctx.scrollContainer as HTMLElement | null)?.querySelector<HTMLInputElement>(
|
|
254
|
+
`[data-svgrid-filter-col="${cssEscape(columnId)}"]`,
|
|
255
|
+
);
|
|
256
|
+
if (input) {
|
|
257
|
+
input.focus();
|
|
258
|
+
input.select();
|
|
259
|
+
// Brief pulse so the user sees where focus landed.
|
|
260
|
+
input.classList.add("sv-grid-filter-value-pulse");
|
|
261
|
+
setTimeout(() => input.classList.remove("sv-grid-filter-value-pulse"), 700);
|
|
262
|
+
}
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
|
267
|
+
ctx.filterMenuPos = {
|
|
268
|
+
x: clampMenuX(rect.right - 260, 260),
|
|
269
|
+
y: rect.bottom + 4,
|
|
270
|
+
};
|
|
271
|
+
ctx.columnMenuSearch = "";
|
|
272
|
+
ctx.filterMenuFor = columnId;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function openOperatorMenu(event: MouseEvent, columnId: string) {
|
|
276
|
+
event.stopPropagation();
|
|
277
|
+
const wasOpen = ctx.operatorMenuFor === columnId;
|
|
278
|
+
closeMenus();
|
|
279
|
+
if (wasOpen) return;
|
|
280
|
+
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
|
|
281
|
+
ctx.operatorMenuPos = { x: clampMenuX(rect.left, 184), y: rect.bottom + 4 };
|
|
282
|
+
ctx.operatorMenuFor = columnId;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function sortColumnFromMenu(columnId: string, desc: boolean) {
|
|
286
|
+
ctx.grid.store.setState((prev: any) => ({
|
|
287
|
+
...prev,
|
|
288
|
+
sorting: [{ id: columnId, desc }],
|
|
289
|
+
}));
|
|
290
|
+
closeMenus();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function clearColumnSort(columnId: string) {
|
|
294
|
+
ctx.grid.store.setState((prev: any) => ({
|
|
295
|
+
...prev,
|
|
296
|
+
sorting: (prev.sorting ?? []).filter(
|
|
297
|
+
(entry: { id: string }) => entry.id !== columnId,
|
|
298
|
+
),
|
|
299
|
+
}));
|
|
300
|
+
closeMenus();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function groupByColumnFromMenu(columnId: string) {
|
|
304
|
+
const current = ctx.grid.getState().grouping ?? [];
|
|
305
|
+
if (current.includes(columnId)) {
|
|
306
|
+
closeMenus();
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
ctx.grid.setGrouping([...current, columnId]);
|
|
310
|
+
closeMenus();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function clearGroupingFromMenu(columnId: string) {
|
|
314
|
+
const current = ctx.grid.getState().grouping ?? [];
|
|
315
|
+
ctx.grid.setGrouping(current.filter((id: string) => id !== columnId));
|
|
316
|
+
closeMenus();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function isFacetChecked(columnId: string, value: string) {
|
|
320
|
+
const selected = ctx.valueFilters[columnId];
|
|
321
|
+
return selected ? selected.has(value) : true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function toggleFacetValue(columnId: string, value: string) {
|
|
325
|
+
const allValues = ctx.columnMenuFacetValues;
|
|
326
|
+
const next = new Set(ctx.valueFilters[columnId] ?? allValues);
|
|
327
|
+
if (next.has(value)) next.delete(value);
|
|
328
|
+
else next.add(value);
|
|
329
|
+
if (next.size === allValues.length) {
|
|
330
|
+
const copy = { ...ctx.valueFilters };
|
|
331
|
+
delete copy[columnId];
|
|
332
|
+
ctx.valueFilters = copy;
|
|
333
|
+
} else {
|
|
334
|
+
ctx.valueFilters = { ...ctx.valueFilters, [columnId]: next };
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function isAllFacetsChecked(columnId: string) {
|
|
339
|
+
const selected = ctx.valueFilters[columnId];
|
|
340
|
+
return !selected || selected.size >= ctx.columnMenuFacetValues.length;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function toggleAllFacets(columnId: string) {
|
|
344
|
+
if (isAllFacetsChecked(columnId)) {
|
|
345
|
+
ctx.valueFilters = { ...ctx.valueFilters, [columnId]: new Set<string>() };
|
|
346
|
+
} else {
|
|
347
|
+
const copy = { ...ctx.valueFilters };
|
|
348
|
+
delete copy[columnId];
|
|
349
|
+
ctx.valueFilters = copy;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function clearColumnFilter(columnId: string) {
|
|
354
|
+
if (ctx.valueFilters[columnId]) {
|
|
355
|
+
const next = { ...ctx.valueFilters };
|
|
356
|
+
delete next[columnId];
|
|
357
|
+
ctx.valueFilters = next;
|
|
358
|
+
}
|
|
359
|
+
if (ctx.filterMenuValues[columnId]) {
|
|
360
|
+
const next = { ...ctx.filterMenuValues };
|
|
361
|
+
delete next[columnId];
|
|
362
|
+
ctx.filterMenuValues = next;
|
|
363
|
+
}
|
|
364
|
+
if (ctx.filterRowValues[columnId]) {
|
|
365
|
+
const next = { ...ctx.filterRowValues };
|
|
366
|
+
delete next[columnId];
|
|
367
|
+
ctx.filterRowValues = next;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function changePage(delta: number) {
|
|
372
|
+
ctx.grid.setPagination((prev: any) => ({
|
|
373
|
+
...prev,
|
|
374
|
+
pageIndex: Math.max((prev?.pageIndex ?? 0) + delta, 0),
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function goToPage(pageIndex: number) {
|
|
379
|
+
ctx.grid.setPagination((prev: any) => ({
|
|
380
|
+
...prev,
|
|
381
|
+
pageIndex: Math.max(0, pageIndex),
|
|
382
|
+
}));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function setPageSize(pageSize: number) {
|
|
386
|
+
ctx.grid.setPagination((prev: any) => {
|
|
387
|
+
const oldSize = prev?.pageSize ?? 10;
|
|
388
|
+
const oldIndex = prev?.pageIndex ?? 0;
|
|
389
|
+
// Keep the first visible row in view when the page size changes.
|
|
390
|
+
const firstVisibleRow = oldIndex * oldSize;
|
|
391
|
+
return {
|
|
392
|
+
...prev,
|
|
393
|
+
pageSize,
|
|
394
|
+
pageIndex: Math.max(0, Math.floor(firstVisibleRow / pageSize)),
|
|
395
|
+
};
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// ---- Right-click context menu --------------------------------------
|
|
400
|
+
type CtxTarget = { rowIndex: number; colIndex: number; columnId: string; rowId: string; row: TData | null };
|
|
401
|
+
type ResolvedItem = { key: string; label: string; separator?: boolean; disabled?: boolean; run?: () => void };
|
|
402
|
+
|
|
403
|
+
function insertRowAt(t: CtxTarget, offset: number) {
|
|
404
|
+
const data = ctx.internalData.slice() as TData[];
|
|
405
|
+
const idx = t.row ? data.indexOf(t.row) : -1;
|
|
406
|
+
const at = idx < 0 ? data.length : idx + offset;
|
|
407
|
+
data.splice(at, 0, {} as TData);
|
|
408
|
+
ctx.internalData = data;
|
|
409
|
+
}
|
|
410
|
+
function removeRowAt(t: CtxTarget) {
|
|
411
|
+
if (!t.row) return;
|
|
412
|
+
ctx.internalData = (ctx.internalData as TData[]).filter((r) => r !== t.row);
|
|
413
|
+
}
|
|
414
|
+
function removeColAt(t: CtxTarget) {
|
|
415
|
+
ctx.internalColumns = ctx.internalColumns.filter(
|
|
416
|
+
(d: any) => (d.id ?? d.field) !== t.columnId,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Built-in items, keyed. `run` reads the live target passed at click time.
|
|
421
|
+
const builtins: Record<string, { label: string; run: (t: CtxTarget) => void }> = {
|
|
422
|
+
copy: { label: "Copy", run: () => ctx.copySelectionToClipboard() },
|
|
423
|
+
cut: { label: "Cut", run: () => ctx.cutSelectionToClipboard() },
|
|
424
|
+
paste: { label: "Paste", run: () => void ctx.pasteFromClipboard() },
|
|
425
|
+
clear: { label: "Clear", run: () => ctx.clearSelectedCells() },
|
|
426
|
+
row_above: { label: "Insert row above", run: (t) => insertRowAt(t, 0) },
|
|
427
|
+
row_below: { label: "Insert row below", run: (t) => insertRowAt(t, 1) },
|
|
428
|
+
remove_row: { label: "Remove row", run: removeRowAt },
|
|
429
|
+
remove_col: { label: "Remove column", run: removeColAt },
|
|
430
|
+
comment: { label: "Edit comment", run: (t) => openCommentEditor(t) },
|
|
431
|
+
};
|
|
432
|
+
const DEFAULT_ITEMS = [
|
|
433
|
+
"copy", "cut", "paste", "clear", "separator",
|
|
434
|
+
"row_above", "row_below", "remove_row", "separator", "remove_col",
|
|
435
|
+
];
|
|
436
|
+
|
|
437
|
+
function openContextMenu(
|
|
438
|
+
event: MouseEvent,
|
|
439
|
+
rowIndex: number,
|
|
440
|
+
colIndex: number,
|
|
441
|
+
columnId: string,
|
|
442
|
+
) {
|
|
443
|
+
if (!ctx.props.contextMenu) return;
|
|
444
|
+
event.preventDefault();
|
|
445
|
+
closeMenus();
|
|
446
|
+
ctx.contextMenuFor = null;
|
|
447
|
+
const rowModel = ctx.allRows[rowIndex];
|
|
448
|
+
const row = rowModel?.original ?? null;
|
|
449
|
+
const rowId = rowModel?.id ?? String(rowIndex);
|
|
450
|
+
ctx.contextMenuPos = {
|
|
451
|
+
x: clampMenuX(event.clientX, 220),
|
|
452
|
+
y: Math.max(8, Math.min(event.clientY, window.innerHeight - 16)),
|
|
453
|
+
};
|
|
454
|
+
ctx.contextMenuFor = { rowIndex, colIndex, columnId, rowId, row };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function closeContextMenu() {
|
|
458
|
+
ctx.contextMenuFor = null;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ---- Editable comments ---------------------------------------------
|
|
462
|
+
function openCommentEditor(t: CtxTarget) {
|
|
463
|
+
const cur =
|
|
464
|
+
ctx.noteOverrides?.[t.rowId]?.[t.columnId] ??
|
|
465
|
+
ctx.props.notes?.[t.rowId]?.[t.columnId] ??
|
|
466
|
+
"";
|
|
467
|
+
ctx.commentDraft = cur;
|
|
468
|
+
ctx.commentEditFor = { rowId: t.rowId, columnId: t.columnId, x: ctx.contextMenuPos.x, y: ctx.contextMenuPos.y };
|
|
469
|
+
ctx.contextMenuFor = null;
|
|
470
|
+
}
|
|
471
|
+
function writeNote(rowId: string, columnId: string, note: string) {
|
|
472
|
+
const next = { ...ctx.noteOverrides };
|
|
473
|
+
next[rowId] = { ...(next[rowId] ?? {}), [columnId]: note };
|
|
474
|
+
ctx.noteOverrides = next;
|
|
475
|
+
ctx.props.onNoteChange?.({ rowId, columnId, note });
|
|
476
|
+
}
|
|
477
|
+
function saveComment() {
|
|
478
|
+
const e = ctx.commentEditFor;
|
|
479
|
+
if (!e) return;
|
|
480
|
+
writeNote(e.rowId, e.columnId, ctx.commentDraft);
|
|
481
|
+
ctx.commentEditFor = null;
|
|
482
|
+
}
|
|
483
|
+
function removeComment() {
|
|
484
|
+
const e = ctx.commentEditFor;
|
|
485
|
+
if (!e) return;
|
|
486
|
+
writeNote(e.rowId, e.columnId, "");
|
|
487
|
+
ctx.commentEditFor = null;
|
|
488
|
+
}
|
|
489
|
+
function closeCommentEditor() {
|
|
490
|
+
ctx.commentEditFor = null;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Resolve the configured items against the current target for rendering. */
|
|
494
|
+
function contextMenuItems(): ResolvedItem[] {
|
|
495
|
+
const target = ctx.contextMenuFor as CtxTarget | null;
|
|
496
|
+
if (!target) return [];
|
|
497
|
+
const cfg = ctx.props.contextMenu;
|
|
498
|
+
const entries: any[] = Array.isArray(cfg)
|
|
499
|
+
? cfg
|
|
500
|
+
: [...DEFAULT_ITEMS, ...(ctx.props.editableComments ? ["separator", "comment"] : [])];
|
|
501
|
+
const out: ResolvedItem[] = [];
|
|
502
|
+
for (const entry of entries) {
|
|
503
|
+
if (entry === "separator") { out.push({ key: "sep" + out.length, label: "", separator: true }); continue; }
|
|
504
|
+
if (typeof entry === "string") {
|
|
505
|
+
const b = builtins[entry];
|
|
506
|
+
if (!b) continue;
|
|
507
|
+
out.push({ key: entry, label: b.label, run: () => b.run(target) });
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
if (entry.hidden?.(target)) continue;
|
|
511
|
+
out.push({
|
|
512
|
+
key: entry.key,
|
|
513
|
+
label: entry.label,
|
|
514
|
+
disabled: entry.disabled?.(target) ?? false,
|
|
515
|
+
run: () => entry.action(target),
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
// Drop leading/trailing/double separators.
|
|
519
|
+
return out.filter((it, i, a) =>
|
|
520
|
+
!it.separator || (i > 0 && i < a.length - 1 && !a[i - 1]?.separator),
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return {
|
|
525
|
+
updateFilterRow,
|
|
526
|
+
updateFilterOperator,
|
|
527
|
+
updateFilterMenuValue,
|
|
528
|
+
updateFilterMenuValueTo,
|
|
529
|
+
toggleCheckboxWithKeyboard,
|
|
530
|
+
isColumnFiltered,
|
|
531
|
+
closeMenus,
|
|
532
|
+
openChooseColumns,
|
|
533
|
+
openColumnMenu,
|
|
534
|
+
openFilterMenu,
|
|
535
|
+
openOperatorMenu,
|
|
536
|
+
sortColumnFromMenu,
|
|
537
|
+
clearColumnSort,
|
|
538
|
+
groupByColumnFromMenu,
|
|
539
|
+
clearGroupingFromMenu,
|
|
540
|
+
isFacetChecked,
|
|
541
|
+
toggleFacetValue,
|
|
542
|
+
isAllFacetsChecked,
|
|
543
|
+
toggleAllFacets,
|
|
544
|
+
clearColumnFilter,
|
|
545
|
+
changePage,
|
|
546
|
+
goToPage,
|
|
547
|
+
setPageSize,
|
|
548
|
+
openContextMenu,
|
|
549
|
+
closeContextMenu,
|
|
550
|
+
contextMenuItems,
|
|
551
|
+
saveComment,
|
|
552
|
+
removeComment,
|
|
553
|
+
closeCommentEditor,
|
|
554
|
+
};
|
|
555
|
+
}
|