@vuu-ui/vuu-table 0.7.3-debug → 0.7.3
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/cjs/index.js +1 -2846
- package/cjs/index.js.map +2 -2
- package/esm/index.js +1 -2885
- package/esm/index.js.map +2 -2
- package/index.css +1 -493
- package/index.css.map +1 -1
- package/package.json +5 -5
package/esm/index.js
CHANGED
|
@@ -1,2886 +1,2 @@
|
|
|
1
|
-
// src/context-menu/buildContextMenuDescriptors.ts
|
|
2
|
-
import { isNumericColumn } from "@vuu-ui/vuu-utils";
|
|
3
|
-
var buildContextMenuDescriptors = (dataSource) => (location, options) => {
|
|
4
|
-
const descriptors = [];
|
|
5
|
-
if (dataSource === void 0) {
|
|
6
|
-
return descriptors;
|
|
7
|
-
}
|
|
8
|
-
if (location === "header") {
|
|
9
|
-
descriptors.push(
|
|
10
|
-
...buildSortMenuItems(options, dataSource)
|
|
11
|
-
);
|
|
12
|
-
descriptors.push(
|
|
13
|
-
...buildGroupMenuItems(options, dataSource)
|
|
14
|
-
);
|
|
15
|
-
descriptors.push(
|
|
16
|
-
...buildAggregationMenuItems(options, dataSource)
|
|
17
|
-
);
|
|
18
|
-
descriptors.push(...buildColumnDisplayMenuItems(options));
|
|
19
|
-
} else if (location === "filter") {
|
|
20
|
-
const { column, filter } = options;
|
|
21
|
-
const colIsOnlyFilter = (filter == null ? void 0 : filter.column) === (column == null ? void 0 : column.name);
|
|
22
|
-
descriptors.push({
|
|
23
|
-
label: "Edit filter",
|
|
24
|
-
action: "filter-edit",
|
|
25
|
-
options
|
|
26
|
-
});
|
|
27
|
-
descriptors.push({
|
|
28
|
-
label: "Remove filter",
|
|
29
|
-
action: "filter-remove-column",
|
|
30
|
-
options
|
|
31
|
-
});
|
|
32
|
-
if (column && !colIsOnlyFilter) {
|
|
33
|
-
descriptors.push({
|
|
34
|
-
label: `Remove all filters`,
|
|
35
|
-
action: "remove-filters",
|
|
36
|
-
options
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return descriptors;
|
|
41
|
-
};
|
|
42
|
-
function buildSortMenuItems(options, { sort: { sortDefs } }) {
|
|
43
|
-
const { column } = options;
|
|
44
|
-
const menuItems = [];
|
|
45
|
-
if (column === void 0) {
|
|
46
|
-
return menuItems;
|
|
47
|
-
}
|
|
48
|
-
const hasSort = sortDefs.length > 0;
|
|
49
|
-
if (column.sorted === "A") {
|
|
50
|
-
menuItems.push({
|
|
51
|
-
label: "Reverse Sort (DSC)",
|
|
52
|
-
action: "sort-dsc",
|
|
53
|
-
options
|
|
54
|
-
});
|
|
55
|
-
} else if (column.sorted === "D") {
|
|
56
|
-
menuItems.push({
|
|
57
|
-
label: "Reverse Sort (ASC)",
|
|
58
|
-
action: "sort-asc",
|
|
59
|
-
options
|
|
60
|
-
});
|
|
61
|
-
} else if (typeof column.sorted === "number") {
|
|
62
|
-
if (column.sorted > 0) {
|
|
63
|
-
menuItems.push({
|
|
64
|
-
label: "Reverse Sort (DSC)",
|
|
65
|
-
action: "sort-add-dsc",
|
|
66
|
-
options
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
menuItems.push({
|
|
70
|
-
label: "Reverse Sort (ASC)",
|
|
71
|
-
action: "sort-add-asc",
|
|
72
|
-
options
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
|
|
76
|
-
menuItems.push({
|
|
77
|
-
label: "Remove from sort",
|
|
78
|
-
action: "sort-remove",
|
|
79
|
-
options
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
menuItems.push({
|
|
83
|
-
label: "New Sort",
|
|
84
|
-
children: [
|
|
85
|
-
{ label: "Ascending", action: "sort-asc", options },
|
|
86
|
-
{ label: "Descending", action: "sort-dsc", options }
|
|
87
|
-
]
|
|
88
|
-
});
|
|
89
|
-
} else if (hasSort) {
|
|
90
|
-
menuItems.push({
|
|
91
|
-
label: "Add to sort",
|
|
92
|
-
children: [
|
|
93
|
-
{ label: "Ascending", action: "sort-add-asc", options },
|
|
94
|
-
{ label: "Descending", action: "sort-add-dsc", options }
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
menuItems.push({
|
|
98
|
-
label: "New Sort",
|
|
99
|
-
children: [
|
|
100
|
-
{ label: "Ascending", action: "sort-asc", options },
|
|
101
|
-
{ label: "Descending", action: "sort-dsc", options }
|
|
102
|
-
]
|
|
103
|
-
});
|
|
104
|
-
} else {
|
|
105
|
-
menuItems.push({
|
|
106
|
-
label: "Sort",
|
|
107
|
-
children: [
|
|
108
|
-
{ label: "Ascending", action: "sort-asc", options },
|
|
109
|
-
{ label: "Descending", action: "sort-dsc", options }
|
|
110
|
-
]
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return menuItems;
|
|
114
|
-
}
|
|
115
|
-
function buildAggregationMenuItems(options, dataSource) {
|
|
116
|
-
const { column } = options;
|
|
117
|
-
if (column === void 0 || dataSource.groupBy.length === 0) {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
const { name, label = name } = column;
|
|
121
|
-
return [
|
|
122
|
-
{
|
|
123
|
-
label: `Aggregate ${label}`,
|
|
124
|
-
children: [
|
|
125
|
-
{ label: "Count", action: "agg-count", options },
|
|
126
|
-
{ label: "Distinct", action: "agg-distinct", options }
|
|
127
|
-
].concat(
|
|
128
|
-
isNumericColumn(column) ? [
|
|
129
|
-
{ label: "Sum", action: "agg-sum", options },
|
|
130
|
-
{ label: "Avg", action: "agg-avg", options },
|
|
131
|
-
{ label: "High", action: "agg-high", options },
|
|
132
|
-
{ label: "Low", action: "agg-low", options }
|
|
133
|
-
] : []
|
|
134
|
-
)
|
|
135
|
-
}
|
|
136
|
-
];
|
|
137
|
-
}
|
|
138
|
-
var pinColumn = (options, pinLocation) => ({
|
|
139
|
-
label: `Pin ${pinLocation}`,
|
|
140
|
-
action: `column-pin-${pinLocation}`,
|
|
141
|
-
options
|
|
142
|
-
});
|
|
143
|
-
var pinLeft = (options) => pinColumn(options, "left");
|
|
144
|
-
var pinFloating = (options) => pinColumn(options, "floating");
|
|
145
|
-
var pinRight = (options) => pinColumn(options, "right");
|
|
146
|
-
function buildColumnDisplayMenuItems(options) {
|
|
147
|
-
const { column } = options;
|
|
148
|
-
if (column === void 0) {
|
|
149
|
-
return [];
|
|
150
|
-
}
|
|
151
|
-
const { pin } = column;
|
|
152
|
-
const menuItems = [
|
|
153
|
-
{
|
|
154
|
-
label: `Hide column`,
|
|
155
|
-
action: "column-hide",
|
|
156
|
-
options
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
label: `Remove column`,
|
|
160
|
-
action: "column-remove",
|
|
161
|
-
options
|
|
162
|
-
}
|
|
163
|
-
];
|
|
164
|
-
if (pin === void 0) {
|
|
165
|
-
menuItems.push({
|
|
166
|
-
label: `Pin column`,
|
|
167
|
-
children: [pinLeft(options), pinFloating(options), pinRight(options)]
|
|
168
|
-
});
|
|
169
|
-
} else if (pin === "left") {
|
|
170
|
-
menuItems.push(
|
|
171
|
-
{ label: "Unpin column", action: "column-unpin", options },
|
|
172
|
-
{
|
|
173
|
-
label: `Pin column`,
|
|
174
|
-
children: [pinFloating(options), pinRight(options)]
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
} else if (pin === "right") {
|
|
178
|
-
menuItems.push(
|
|
179
|
-
{ label: "Unpin column", action: "column-unpin", options },
|
|
180
|
-
{
|
|
181
|
-
label: `Pin column`,
|
|
182
|
-
children: [pinLeft(options), pinFloating(options)]
|
|
183
|
-
}
|
|
184
|
-
);
|
|
185
|
-
} else if (pin === "floating") {
|
|
186
|
-
menuItems.push(
|
|
187
|
-
{ label: "Unpin column", action: "column-unpin", options },
|
|
188
|
-
{
|
|
189
|
-
label: `Pin column`,
|
|
190
|
-
children: [pinLeft(options), pinRight(options)]
|
|
191
|
-
}
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
return menuItems;
|
|
195
|
-
}
|
|
196
|
-
function buildGroupMenuItems(options, { groupBy }) {
|
|
197
|
-
const { column } = options;
|
|
198
|
-
const menuItems = [];
|
|
199
|
-
if (column === void 0) {
|
|
200
|
-
return menuItems;
|
|
201
|
-
}
|
|
202
|
-
const { name, label = name } = column;
|
|
203
|
-
if (groupBy.length === 0) {
|
|
204
|
-
menuItems.push({
|
|
205
|
-
label: `Group by ${label}`,
|
|
206
|
-
action: "group",
|
|
207
|
-
options
|
|
208
|
-
});
|
|
209
|
-
} else {
|
|
210
|
-
menuItems.push({
|
|
211
|
-
label: `Add ${label} to group by`,
|
|
212
|
-
action: "group-add",
|
|
213
|
-
options
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return menuItems;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/context-menu/useTableContextMenu.ts
|
|
220
|
-
import { removeColumnFromFilter } from "@vuu-ui/vuu-filters";
|
|
221
|
-
import {
|
|
222
|
-
addGroupColumn,
|
|
223
|
-
addSortColumn,
|
|
224
|
-
AggregationType,
|
|
225
|
-
setAggregations,
|
|
226
|
-
setSortColumn
|
|
227
|
-
} from "@vuu-ui/vuu-utils";
|
|
228
|
-
var removeFilterColumn = (dataSourceFilter, column) => {
|
|
229
|
-
if (dataSourceFilter.filterStruct && column) {
|
|
230
|
-
const [filterStruct, filter] = removeColumnFromFilter(
|
|
231
|
-
column,
|
|
232
|
-
dataSourceFilter.filterStruct
|
|
233
|
-
);
|
|
234
|
-
return {
|
|
235
|
-
filter,
|
|
236
|
-
filterStruct
|
|
237
|
-
};
|
|
238
|
-
} else {
|
|
239
|
-
return dataSourceFilter;
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
var { Average, Count, Distinct, High, Low, Sum } = AggregationType;
|
|
243
|
-
var useTableContextMenu = ({
|
|
244
|
-
dataSource,
|
|
245
|
-
onPersistentColumnOperation
|
|
246
|
-
}) => {
|
|
247
|
-
const handleContextMenuAction = (type, options) => {
|
|
248
|
-
const gridOptions = options;
|
|
249
|
-
if (gridOptions.column && dataSource) {
|
|
250
|
-
const { column } = gridOptions;
|
|
251
|
-
switch (type) {
|
|
252
|
-
case "sort-asc":
|
|
253
|
-
return dataSource.sort = setSortColumn(dataSource.sort, column, "A"), true;
|
|
254
|
-
case "sort-dsc":
|
|
255
|
-
return dataSource.sort = setSortColumn(dataSource.sort, column, "D"), true;
|
|
256
|
-
case "sort-add-asc":
|
|
257
|
-
return dataSource.sort = addSortColumn(dataSource.sort, column, "A"), true;
|
|
258
|
-
case "sort-add-dsc":
|
|
259
|
-
return dataSource.sort = addSortColumn(dataSource.sort, column, "D"), true;
|
|
260
|
-
case "group":
|
|
261
|
-
return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
|
|
262
|
-
case "group-add":
|
|
263
|
-
return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
|
|
264
|
-
case "column-hide":
|
|
265
|
-
return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
|
|
266
|
-
case "column-remove":
|
|
267
|
-
return dataSource.columns = dataSource.columns.filter((name) => name !== column.name), true;
|
|
268
|
-
case "filter-remove-column":
|
|
269
|
-
return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
|
|
270
|
-
case "remove-filters":
|
|
271
|
-
return dataSource.filter = { filter: "" }, true;
|
|
272
|
-
case "agg-avg":
|
|
273
|
-
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Average), true;
|
|
274
|
-
case "agg-high":
|
|
275
|
-
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, High), true;
|
|
276
|
-
case "agg-low":
|
|
277
|
-
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Low), true;
|
|
278
|
-
case "agg-count":
|
|
279
|
-
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Count), true;
|
|
280
|
-
case "agg-distinct":
|
|
281
|
-
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Distinct), true;
|
|
282
|
-
case "agg-sum":
|
|
283
|
-
return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Sum), true;
|
|
284
|
-
case "column-pin-floating":
|
|
285
|
-
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
|
|
286
|
-
case "column-pin-left":
|
|
287
|
-
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
|
|
288
|
-
case "column-pin-right":
|
|
289
|
-
return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
|
|
290
|
-
case "column-unpin":
|
|
291
|
-
return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
|
|
292
|
-
default:
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return false;
|
|
296
|
-
};
|
|
297
|
-
return handleContextMenuAction;
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
// src/Table.tsx
|
|
301
|
-
import { ContextMenuProvider } from "@vuu-ui/vuu-popups";
|
|
302
|
-
import { Button, useIdMemo } from "@salt-ds/core";
|
|
303
|
-
|
|
304
|
-
// src/RowBasedTable.tsx
|
|
305
|
-
import {
|
|
306
|
-
buildColumnMap,
|
|
307
|
-
getColumnStyle as getColumnStyle3,
|
|
308
|
-
isGroupColumn as isGroupColumn2,
|
|
309
|
-
metadataKeys as metadataKeys4,
|
|
310
|
-
notHidden as notHidden2,
|
|
311
|
-
visibleColumnAtIndex
|
|
312
|
-
} from "@vuu-ui/vuu-utils";
|
|
313
|
-
import { useCallback as useCallback8, useMemo } from "react";
|
|
314
|
-
|
|
315
|
-
// src/TableRow.tsx
|
|
316
|
-
import {
|
|
317
|
-
isGroupColumn,
|
|
318
|
-
isJsonColumn,
|
|
319
|
-
isJsonGroup,
|
|
320
|
-
metadataKeys as metadataKeys3,
|
|
321
|
-
notHidden
|
|
322
|
-
} from "@vuu-ui/vuu-utils";
|
|
323
|
-
import cx2 from "classnames";
|
|
324
|
-
import { memo as memo2, useCallback as useCallback3 } from "react";
|
|
325
|
-
|
|
326
|
-
// src/TableCell.tsx
|
|
327
|
-
import { getColumnStyle, metadataKeys } from "@vuu-ui/vuu-utils";
|
|
328
|
-
import { EditableLabel } from "@heswell/salt-lab";
|
|
329
|
-
import cx from "classnames";
|
|
330
|
-
import {
|
|
331
|
-
memo,
|
|
332
|
-
useCallback,
|
|
333
|
-
useRef,
|
|
334
|
-
useState
|
|
335
|
-
} from "react";
|
|
336
|
-
import { jsx } from "react/jsx-runtime";
|
|
337
|
-
var { KEY } = metadataKeys;
|
|
338
|
-
var TableCell = memo(
|
|
339
|
-
({
|
|
340
|
-
className: classNameProp,
|
|
341
|
-
column,
|
|
342
|
-
columnMap,
|
|
343
|
-
onClick,
|
|
344
|
-
row
|
|
345
|
-
}) => {
|
|
346
|
-
const labelFieldRef = useRef(null);
|
|
347
|
-
const {
|
|
348
|
-
align,
|
|
349
|
-
CellRenderer,
|
|
350
|
-
key,
|
|
351
|
-
pin,
|
|
352
|
-
editable,
|
|
353
|
-
resizing,
|
|
354
|
-
valueFormatter
|
|
355
|
-
} = column;
|
|
356
|
-
const [editing, setEditing] = useState(false);
|
|
357
|
-
const value = valueFormatter(row[key]);
|
|
358
|
-
const [editableValue, setEditableValue] = useState(value);
|
|
359
|
-
const handleTitleMouseDown = () => {
|
|
360
|
-
var _a;
|
|
361
|
-
(_a = labelFieldRef.current) == null ? void 0 : _a.focus();
|
|
362
|
-
};
|
|
363
|
-
const handleTitleKeyDown = (evt) => {
|
|
364
|
-
if (evt.key === "Enter") {
|
|
365
|
-
setEditing(true);
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
const handleClick = useCallback(
|
|
369
|
-
(evt) => {
|
|
370
|
-
onClick == null ? void 0 : onClick(evt, column);
|
|
371
|
-
},
|
|
372
|
-
[column, onClick]
|
|
373
|
-
);
|
|
374
|
-
const handleEnterEditMode = () => {
|
|
375
|
-
setEditing(true);
|
|
376
|
-
};
|
|
377
|
-
const handleExitEditMode = (originalValue = "", finalValue = "", allowDeactivation = true, editCancelled = false) => {
|
|
378
|
-
var _a;
|
|
379
|
-
setEditing(false);
|
|
380
|
-
if (editCancelled) {
|
|
381
|
-
setEditableValue(originalValue);
|
|
382
|
-
} else if (finalValue !== originalValue) {
|
|
383
|
-
setEditableValue(finalValue);
|
|
384
|
-
}
|
|
385
|
-
if (allowDeactivation === false) {
|
|
386
|
-
(_a = labelFieldRef.current) == null ? void 0 : _a.focus();
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
const className = cx(classNameProp, {
|
|
390
|
-
vuuAlignRight: align === "right",
|
|
391
|
-
vuuPinFloating: pin === "floating",
|
|
392
|
-
vuuPinLeft: pin === "left",
|
|
393
|
-
vuuPinRight: pin === "right",
|
|
394
|
-
"vuuTableCell-resizing": resizing
|
|
395
|
-
}) || void 0;
|
|
396
|
-
const style = getColumnStyle(column);
|
|
397
|
-
return editable ? /* @__PURE__ */ jsx(
|
|
398
|
-
"div",
|
|
399
|
-
{
|
|
400
|
-
className,
|
|
401
|
-
"data-editable": true,
|
|
402
|
-
role: "cell",
|
|
403
|
-
style,
|
|
404
|
-
onKeyDown: handleTitleKeyDown,
|
|
405
|
-
children: /* @__PURE__ */ jsx(
|
|
406
|
-
EditableLabel,
|
|
407
|
-
{
|
|
408
|
-
editing,
|
|
409
|
-
value: editableValue,
|
|
410
|
-
onChange: setEditableValue,
|
|
411
|
-
onMouseDownCapture: handleTitleMouseDown,
|
|
412
|
-
onEnterEditMode: handleEnterEditMode,
|
|
413
|
-
onExitEditMode: handleExitEditMode,
|
|
414
|
-
onKeyDown: handleTitleKeyDown,
|
|
415
|
-
ref: labelFieldRef,
|
|
416
|
-
tabIndex: 0
|
|
417
|
-
},
|
|
418
|
-
"title"
|
|
419
|
-
)
|
|
420
|
-
}
|
|
421
|
-
) : /* @__PURE__ */ jsx(
|
|
422
|
-
"div",
|
|
423
|
-
{
|
|
424
|
-
className,
|
|
425
|
-
role: "cell",
|
|
426
|
-
style,
|
|
427
|
-
onClick: handleClick,
|
|
428
|
-
children: CellRenderer ? /* @__PURE__ */ jsx(CellRenderer, { column, columnMap, row }) : value
|
|
429
|
-
}
|
|
430
|
-
);
|
|
431
|
-
},
|
|
432
|
-
cellValuesAreEqual
|
|
433
|
-
);
|
|
434
|
-
TableCell.displayName = "TableCell";
|
|
435
|
-
function cellValuesAreEqual(prev, next) {
|
|
436
|
-
return prev.column === next.column && prev.onClick === next.onClick && prev.row[KEY] === next.row[KEY] && prev.row[prev.column.key] === next.row[next.column.key];
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// src/TableGroupCell.tsx
|
|
440
|
-
import { getColumnStyle as getColumnStyle2, metadataKeys as metadataKeys2 } from "@vuu-ui/vuu-utils";
|
|
441
|
-
import { useCallback as useCallback2 } from "react";
|
|
442
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
443
|
-
var { DEPTH, IS_LEAF } = metadataKeys2;
|
|
444
|
-
var getGroupValueAndOffset = (columns, row) => {
|
|
445
|
-
const { [DEPTH]: depth, [IS_LEAF]: isLeaf } = row;
|
|
446
|
-
if (isLeaf || depth > columns.length) {
|
|
447
|
-
return [null, depth === null ? 0 : Math.max(0, depth - 1)];
|
|
448
|
-
} else if (depth === 0) {
|
|
449
|
-
return ["$root", 0];
|
|
450
|
-
} else {
|
|
451
|
-
const { key, valueFormatter } = columns[depth - 1];
|
|
452
|
-
const value = valueFormatter(row[key]);
|
|
453
|
-
return [value, depth - 1];
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
var TableGroupCell = ({ column, onClick, row }) => {
|
|
457
|
-
const { columns } = column;
|
|
458
|
-
const [value, offset] = getGroupValueAndOffset(columns, row);
|
|
459
|
-
const handleClick = useCallback2(
|
|
460
|
-
(evt) => {
|
|
461
|
-
onClick == null ? void 0 : onClick(evt, column);
|
|
462
|
-
},
|
|
463
|
-
[column, onClick]
|
|
464
|
-
);
|
|
465
|
-
const style = getColumnStyle2(column);
|
|
466
|
-
const isLeaf = row[IS_LEAF];
|
|
467
|
-
const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-spacer" }, i));
|
|
468
|
-
return /* @__PURE__ */ jsxs(
|
|
469
|
-
"div",
|
|
470
|
-
{
|
|
471
|
-
className: "vuuTableGroupCell vuuPinLeft",
|
|
472
|
-
onClick: isLeaf ? void 0 : handleClick,
|
|
473
|
-
role: "cell",
|
|
474
|
-
style,
|
|
475
|
-
children: [
|
|
476
|
-
spacers,
|
|
477
|
-
isLeaf ? null : /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-toggle", "data-icon": "triangle-right" }),
|
|
478
|
-
/* @__PURE__ */ jsx2("span", { children: value })
|
|
479
|
-
]
|
|
480
|
-
}
|
|
481
|
-
);
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
// src/TableRow.tsx
|
|
485
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
486
|
-
var { IDX, IS_EXPANDED, SELECTED } = metadataKeys3;
|
|
487
|
-
var classBase = "vuuTableRow";
|
|
488
|
-
var TableRow = memo2(function Row({
|
|
489
|
-
columnMap,
|
|
490
|
-
columns,
|
|
491
|
-
offset,
|
|
492
|
-
onClick,
|
|
493
|
-
onToggleGroup,
|
|
494
|
-
virtualColSpan = 0,
|
|
495
|
-
row
|
|
496
|
-
}) {
|
|
497
|
-
const {
|
|
498
|
-
[IDX]: rowIndex,
|
|
499
|
-
[IS_EXPANDED]: isExpanded,
|
|
500
|
-
[SELECTED]: isSelected
|
|
501
|
-
} = row;
|
|
502
|
-
const className = cx2(classBase, {
|
|
503
|
-
[`${classBase}-even`]: rowIndex % 2 === 0,
|
|
504
|
-
[`${classBase}-expanded`]: isExpanded,
|
|
505
|
-
[`${classBase}-preSelected`]: isSelected === 2
|
|
506
|
-
});
|
|
507
|
-
const handleRowClick = useCallback3(
|
|
508
|
-
(evt) => {
|
|
509
|
-
const rangeSelect = evt.shiftKey;
|
|
510
|
-
const keepExistingSelection = evt.ctrlKey || evt.metaKey;
|
|
511
|
-
onClick == null ? void 0 : onClick(row, rangeSelect, keepExistingSelection);
|
|
512
|
-
},
|
|
513
|
-
[onClick, row]
|
|
514
|
-
);
|
|
515
|
-
const handleGroupCellClick = useCallback3(
|
|
516
|
-
(evt, column) => {
|
|
517
|
-
if (isGroupColumn(column) || isJsonGroup(column, row)) {
|
|
518
|
-
evt.stopPropagation();
|
|
519
|
-
onToggleGroup == null ? void 0 : onToggleGroup(row, column);
|
|
520
|
-
}
|
|
521
|
-
},
|
|
522
|
-
[onToggleGroup, row]
|
|
523
|
-
);
|
|
524
|
-
return /* @__PURE__ */ jsxs2(
|
|
525
|
-
"div",
|
|
526
|
-
{
|
|
527
|
-
"aria-selected": isSelected === 1 ? true : void 0,
|
|
528
|
-
"aria-rowindex": rowIndex,
|
|
529
|
-
className,
|
|
530
|
-
onClick: handleRowClick,
|
|
531
|
-
role: "row",
|
|
532
|
-
style: {
|
|
533
|
-
transform: `translate3d(0px, ${offset}px, 0px)`
|
|
534
|
-
},
|
|
535
|
-
children: [
|
|
536
|
-
virtualColSpan > 0 ? /* @__PURE__ */ jsx3("div", { role: "cell", style: { width: virtualColSpan } }) : null,
|
|
537
|
-
columns.filter(notHidden).map((column) => {
|
|
538
|
-
const isGroup = isGroupColumn(column);
|
|
539
|
-
const isJsonCell = isJsonColumn(column);
|
|
540
|
-
const Cell = isGroup ? TableGroupCell : TableCell;
|
|
541
|
-
return /* @__PURE__ */ jsx3(
|
|
542
|
-
Cell,
|
|
543
|
-
{
|
|
544
|
-
column,
|
|
545
|
-
columnMap,
|
|
546
|
-
onClick: isGroup || isJsonCell ? handleGroupCellClick : void 0,
|
|
547
|
-
row
|
|
548
|
-
},
|
|
549
|
-
column.name
|
|
550
|
-
);
|
|
551
|
-
})
|
|
552
|
-
]
|
|
553
|
-
}
|
|
554
|
-
);
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
// src/TableGroupHeaderCell.tsx
|
|
558
|
-
import cx3 from "classnames";
|
|
559
|
-
import { useRef as useRef4 } from "react";
|
|
560
|
-
|
|
561
|
-
// src/ColumnResizer.tsx
|
|
562
|
-
import { useCallback as useCallback4, useRef as useRef2 } from "react";
|
|
563
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
564
|
-
var NOOP = () => void 0;
|
|
565
|
-
var baseClass = "vuuColumnResizer";
|
|
566
|
-
var ColumnResizer = ({
|
|
567
|
-
onDrag,
|
|
568
|
-
onDragEnd = NOOP,
|
|
569
|
-
onDragStart = NOOP
|
|
570
|
-
}) => {
|
|
571
|
-
const position = useRef2(0);
|
|
572
|
-
const onMouseMove = useCallback4(
|
|
573
|
-
(e) => {
|
|
574
|
-
if (e.stopPropagation) {
|
|
575
|
-
e.stopPropagation();
|
|
576
|
-
}
|
|
577
|
-
if (e.preventDefault) {
|
|
578
|
-
e.preventDefault();
|
|
579
|
-
}
|
|
580
|
-
const x = Math.round(e.clientX);
|
|
581
|
-
const moveBy = x - position.current;
|
|
582
|
-
position.current = x;
|
|
583
|
-
if (moveBy !== 0) {
|
|
584
|
-
onDrag(e, moveBy);
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
[onDrag]
|
|
588
|
-
);
|
|
589
|
-
const onMouseUp = useCallback4(
|
|
590
|
-
(e) => {
|
|
591
|
-
window.removeEventListener("mouseup", onMouseUp);
|
|
592
|
-
window.removeEventListener("mousemove", onMouseMove);
|
|
593
|
-
onDragEnd(e);
|
|
594
|
-
},
|
|
595
|
-
[onDragEnd, onMouseMove]
|
|
596
|
-
);
|
|
597
|
-
const handleMouseDown = useCallback4(
|
|
598
|
-
(e) => {
|
|
599
|
-
onDragStart(e);
|
|
600
|
-
position.current = Math.round(e.clientX);
|
|
601
|
-
window.addEventListener("mouseup", onMouseUp);
|
|
602
|
-
window.addEventListener("mousemove", onMouseMove);
|
|
603
|
-
if (e.stopPropagation) {
|
|
604
|
-
e.stopPropagation();
|
|
605
|
-
}
|
|
606
|
-
if (e.preventDefault) {
|
|
607
|
-
e.preventDefault();
|
|
608
|
-
}
|
|
609
|
-
},
|
|
610
|
-
[onDragStart, onMouseMove, onMouseUp]
|
|
611
|
-
);
|
|
612
|
-
return /* @__PURE__ */ jsx4("div", { className: baseClass, "data-align": "end", onMouseDown: handleMouseDown });
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
// src/useTableColumnResize.tsx
|
|
616
|
-
import { useCallback as useCallback5, useRef as useRef3 } from "react";
|
|
617
|
-
var useTableColumnResize = ({
|
|
618
|
-
column,
|
|
619
|
-
onResize,
|
|
620
|
-
rootRef
|
|
621
|
-
}) => {
|
|
622
|
-
const widthRef = useRef3(0);
|
|
623
|
-
const isResizing = useRef3(false);
|
|
624
|
-
const { name } = column;
|
|
625
|
-
const handleResizeStart = useCallback5(() => {
|
|
626
|
-
if (onResize && rootRef.current) {
|
|
627
|
-
const { width } = rootRef.current.getBoundingClientRect();
|
|
628
|
-
widthRef.current = Math.round(width);
|
|
629
|
-
isResizing.current = true;
|
|
630
|
-
onResize == null ? void 0 : onResize("begin", name);
|
|
631
|
-
}
|
|
632
|
-
}, [name, onResize, rootRef]);
|
|
633
|
-
const handleResize = useCallback5(
|
|
634
|
-
(_evt, moveBy) => {
|
|
635
|
-
if (rootRef.current) {
|
|
636
|
-
if (onResize) {
|
|
637
|
-
const { width } = rootRef.current.getBoundingClientRect();
|
|
638
|
-
const newWidth = Math.round(width) + moveBy;
|
|
639
|
-
if (newWidth !== widthRef.current && newWidth > 0) {
|
|
640
|
-
onResize("resize", name, newWidth);
|
|
641
|
-
widthRef.current = newWidth;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
},
|
|
646
|
-
[name, onResize, rootRef]
|
|
647
|
-
);
|
|
648
|
-
const handleResizeEnd = useCallback5(() => {
|
|
649
|
-
if (onResize) {
|
|
650
|
-
onResize("end", name, widthRef.current);
|
|
651
|
-
setTimeout(() => {
|
|
652
|
-
isResizing.current = false;
|
|
653
|
-
}, 100);
|
|
654
|
-
}
|
|
655
|
-
}, [name, onResize]);
|
|
656
|
-
return {
|
|
657
|
-
isResizing: isResizing.current,
|
|
658
|
-
onDrag: handleResize,
|
|
659
|
-
onDragStart: handleResizeStart,
|
|
660
|
-
onDragEnd: handleResizeEnd
|
|
661
|
-
};
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
// src/TableGroupHeaderCell.tsx
|
|
665
|
-
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
666
|
-
var classBase2 = "vuuTable-groupHeaderCell";
|
|
667
|
-
var RemoveButton = ({
|
|
668
|
-
column,
|
|
669
|
-
onClick,
|
|
670
|
-
...htmlAttributes
|
|
671
|
-
}) => {
|
|
672
|
-
return /* @__PURE__ */ jsx5(
|
|
673
|
-
"span",
|
|
674
|
-
{
|
|
675
|
-
...htmlAttributes,
|
|
676
|
-
className: `${classBase2}-close`,
|
|
677
|
-
"data-icon": "close-circle",
|
|
678
|
-
onClick: () => onClick == null ? void 0 : onClick(column)
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
|
-
};
|
|
682
|
-
var ColHeader = (props) => {
|
|
683
|
-
const { children, column, className } = props;
|
|
684
|
-
return /* @__PURE__ */ jsxs3("div", { className: cx3(`${classBase2}-col`, className), role: "columnheader", children: [
|
|
685
|
-
/* @__PURE__ */ jsx5("span", { className: `${classBase2}-label`, children: column.name }),
|
|
686
|
-
children
|
|
687
|
-
] });
|
|
688
|
-
};
|
|
689
|
-
var TableGroupHeaderCell = ({
|
|
690
|
-
column: groupColumn,
|
|
691
|
-
className: classNameProp,
|
|
692
|
-
onRemoveColumn,
|
|
693
|
-
onResize,
|
|
694
|
-
...props
|
|
695
|
-
}) => {
|
|
696
|
-
const rootRef = useRef4(null);
|
|
697
|
-
const { isResizing, ...resizeProps } = useTableColumnResize({
|
|
698
|
-
column: groupColumn,
|
|
699
|
-
onResize,
|
|
700
|
-
rootRef
|
|
701
|
-
});
|
|
702
|
-
const className = cx3(classBase2, classNameProp, {
|
|
703
|
-
vuuPinLeft: groupColumn.pin === "left",
|
|
704
|
-
[`${classBase2}-right`]: groupColumn.align === "right",
|
|
705
|
-
[`${classBase2}-resizing`]: groupColumn.resizing,
|
|
706
|
-
[`${classBase2}-pending`]: groupColumn.groupConfirmed === false
|
|
707
|
-
});
|
|
708
|
-
const { columns } = groupColumn;
|
|
709
|
-
return /* @__PURE__ */ jsx5("div", { className, ref: rootRef, ...props, children: /* @__PURE__ */ jsxs3("div", { className: `${classBase2}-inner`, children: [
|
|
710
|
-
columns.map((column) => /* @__PURE__ */ jsx5(ColHeader, { column, children: columns.length > 1 ? /* @__PURE__ */ jsx5(RemoveButton, { column, onClick: onRemoveColumn }) : null }, column.key)),
|
|
711
|
-
/* @__PURE__ */ jsx5(RemoveButton, { "data-align": "end", onClick: onRemoveColumn }),
|
|
712
|
-
groupColumn.resizeable !== false ? /* @__PURE__ */ jsx5(ColumnResizer, { ...resizeProps }) : null
|
|
713
|
-
] }) });
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
// src/TableHeaderCell.tsx
|
|
717
|
-
import cx6 from "classnames";
|
|
718
|
-
import { useCallback as useCallback7, useRef as useRef5 } from "react";
|
|
719
|
-
|
|
720
|
-
// src/SortIndicator.tsx
|
|
721
|
-
import cx4 from "classnames";
|
|
722
|
-
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
723
|
-
var classBase3 = "vuuSortIndicator";
|
|
724
|
-
var SortIndicator = ({ sorted }) => {
|
|
725
|
-
if (!sorted) {
|
|
726
|
-
return null;
|
|
727
|
-
}
|
|
728
|
-
const direction = typeof sorted === "number" ? sorted < 0 ? "dsc" : "asc" : sorted === "A" ? "asc" : "dsc";
|
|
729
|
-
return typeof sorted === "number" ? /* @__PURE__ */ jsxs4("div", { className: cx4(classBase3, "multi-col", direction), children: [
|
|
730
|
-
/* @__PURE__ */ jsx6("span", { "data-icon": `sorted-${direction}` }),
|
|
731
|
-
/* @__PURE__ */ jsx6("span", { className: "vuuSortPosition", children: Math.abs(sorted) })
|
|
732
|
-
] }) : /* @__PURE__ */ jsx6("div", { className: cx4(classBase3, "single-col"), children: /* @__PURE__ */ jsx6("span", { "data-icon": `sorted-${direction}` }) });
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
// src/TableHeaderCell.tsx
|
|
736
|
-
import { useContextMenu as useContextMenu2 } from "@vuu-ui/vuu-popups";
|
|
737
|
-
|
|
738
|
-
// src/filter-indicator.tsx
|
|
739
|
-
import { useContextMenu } from "@vuu-ui/vuu-popups";
|
|
740
|
-
import cx5 from "classnames";
|
|
741
|
-
import { useCallback as useCallback6 } from "react";
|
|
742
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
743
|
-
var FilterIndicator = ({ column, filter }) => {
|
|
744
|
-
const showContextMenu = useContextMenu();
|
|
745
|
-
const handleClick = useCallback6(
|
|
746
|
-
(evt) => {
|
|
747
|
-
evt.stopPropagation();
|
|
748
|
-
showContextMenu(evt, "filter", { column, filter });
|
|
749
|
-
},
|
|
750
|
-
[column, filter, showContextMenu]
|
|
751
|
-
);
|
|
752
|
-
if (!column.filter) {
|
|
753
|
-
return null;
|
|
754
|
-
}
|
|
755
|
-
return /* @__PURE__ */ jsx7(
|
|
756
|
-
"div",
|
|
757
|
-
{
|
|
758
|
-
className: cx5("vuuFilterIndicator"),
|
|
759
|
-
"data-icon": "filter",
|
|
760
|
-
onClick: handleClick
|
|
761
|
-
}
|
|
762
|
-
);
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
// src/TableHeaderCell.tsx
|
|
766
|
-
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
767
|
-
var classBase4 = "vuuTable-headerCell";
|
|
768
|
-
var TableHeaderCell = ({
|
|
769
|
-
column,
|
|
770
|
-
className: classNameProp,
|
|
771
|
-
onClick,
|
|
772
|
-
onDragStart,
|
|
773
|
-
onResize,
|
|
774
|
-
...props
|
|
775
|
-
}) => {
|
|
776
|
-
const rootRef = useRef5(null);
|
|
777
|
-
const { isResizing, ...resizeProps } = useTableColumnResize({
|
|
778
|
-
column,
|
|
779
|
-
onResize,
|
|
780
|
-
rootRef
|
|
781
|
-
});
|
|
782
|
-
const showContextMenu = useContextMenu2();
|
|
783
|
-
const dragTimerRef = useRef5(null);
|
|
784
|
-
const handleContextMenu = (e) => {
|
|
785
|
-
showContextMenu(e, "header", { column });
|
|
786
|
-
};
|
|
787
|
-
const handleClick = useCallback7(
|
|
788
|
-
(evt) => !isResizing && (onClick == null ? void 0 : onClick(evt)),
|
|
789
|
-
[isResizing, onClick]
|
|
790
|
-
);
|
|
791
|
-
const handleMouseDown = useCallback7(
|
|
792
|
-
(evt) => {
|
|
793
|
-
dragTimerRef.current = window.setTimeout(() => {
|
|
794
|
-
onDragStart == null ? void 0 : onDragStart(evt);
|
|
795
|
-
dragTimerRef.current = null;
|
|
796
|
-
}, 500);
|
|
797
|
-
},
|
|
798
|
-
[onDragStart]
|
|
799
|
-
);
|
|
800
|
-
const handleMouseUp = useCallback7(() => {
|
|
801
|
-
if (dragTimerRef.current !== null) {
|
|
802
|
-
window.clearTimeout(dragTimerRef.current);
|
|
803
|
-
dragTimerRef.current = null;
|
|
804
|
-
}
|
|
805
|
-
}, []);
|
|
806
|
-
const className = cx6(classBase4, classNameProp, {
|
|
807
|
-
vuuPinFloating: column.pin === "floating",
|
|
808
|
-
vuuPinLeft: column.pin === "left",
|
|
809
|
-
vuuPinRight: column.pin === "right",
|
|
810
|
-
vuuEndPin: column.endPin,
|
|
811
|
-
[`${classBase4}-resizing`]: column.resizing,
|
|
812
|
-
[`${classBase4}-right`]: column.align === "right"
|
|
813
|
-
});
|
|
814
|
-
return /* @__PURE__ */ jsx8(
|
|
815
|
-
"div",
|
|
816
|
-
{
|
|
817
|
-
className,
|
|
818
|
-
...props,
|
|
819
|
-
onClick: handleClick,
|
|
820
|
-
onContextMenu: handleContextMenu,
|
|
821
|
-
onMouseDown: handleMouseDown,
|
|
822
|
-
onMouseUp: handleMouseUp,
|
|
823
|
-
ref: rootRef,
|
|
824
|
-
children: /* @__PURE__ */ jsxs5("div", { className: `${classBase4}-inner`, children: [
|
|
825
|
-
/* @__PURE__ */ jsx8(FilterIndicator, { column }),
|
|
826
|
-
/* @__PURE__ */ jsx8("div", { className: `${classBase4}-label`, children: column.label }),
|
|
827
|
-
/* @__PURE__ */ jsx8(SortIndicator, { sorted: column.sorted }),
|
|
828
|
-
column.resizeable !== false ? /* @__PURE__ */ jsx8(ColumnResizer, { ...resizeProps }) : null
|
|
829
|
-
] })
|
|
830
|
-
}
|
|
831
|
-
);
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// src/RowBasedTable.tsx
|
|
835
|
-
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
836
|
-
var classBase5 = "vuuTable";
|
|
837
|
-
var { RENDER_IDX } = metadataKeys4;
|
|
838
|
-
var RowBasedTable = ({
|
|
839
|
-
columns,
|
|
840
|
-
columnsWithinViewport,
|
|
841
|
-
data,
|
|
842
|
-
getRowOffset,
|
|
843
|
-
headings,
|
|
844
|
-
onColumnResize,
|
|
845
|
-
onHeaderCellDragStart,
|
|
846
|
-
onContextMenu,
|
|
847
|
-
onRemoveColumnFromGroupBy,
|
|
848
|
-
onRowClick,
|
|
849
|
-
onSort,
|
|
850
|
-
onToggleGroup,
|
|
851
|
-
tableId,
|
|
852
|
-
virtualColSpan = 0,
|
|
853
|
-
rowCount
|
|
854
|
-
}) => {
|
|
855
|
-
const handleDragStart = useCallback8(
|
|
856
|
-
(evt) => {
|
|
857
|
-
onHeaderCellDragStart == null ? void 0 : onHeaderCellDragStart(evt);
|
|
858
|
-
},
|
|
859
|
-
[onHeaderCellDragStart]
|
|
860
|
-
);
|
|
861
|
-
const visibleColumns = useMemo(() => {
|
|
862
|
-
return columns.filter(notHidden2);
|
|
863
|
-
}, [columns]);
|
|
864
|
-
const columnMap = useMemo(() => buildColumnMap(columns), [columns]);
|
|
865
|
-
const handleHeaderClick = useCallback8(
|
|
866
|
-
(evt) => {
|
|
867
|
-
var _a;
|
|
868
|
-
const targetElement = evt.target;
|
|
869
|
-
const headerCell = targetElement.closest(
|
|
870
|
-
".vuuTable-headerCell"
|
|
871
|
-
);
|
|
872
|
-
const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.idx) != null ? _a : "-1");
|
|
873
|
-
const column = visibleColumnAtIndex(columns, colIdx);
|
|
874
|
-
const isAdditive = evt.shiftKey;
|
|
875
|
-
column && onSort(column, isAdditive);
|
|
876
|
-
},
|
|
877
|
-
[columns, onSort]
|
|
878
|
-
);
|
|
879
|
-
return /* @__PURE__ */ jsxs6("div", { "aria-rowcount": rowCount, className: `${classBase5}-table`, role: "table", children: [
|
|
880
|
-
/* @__PURE__ */ jsxs6("div", { className: `${classBase5}-headers`, role: "rowGroup", children: [
|
|
881
|
-
headings.map((colHeaders, i) => /* @__PURE__ */ jsx9("div", { className: "vuuTable-heading", children: colHeaders.map(({ label, width }, j) => /* @__PURE__ */ jsx9("div", { className: "vuuTable-headingCell", style: { width }, children: label }, j)) }, i)),
|
|
882
|
-
/* @__PURE__ */ jsx9("div", { role: "row", children: visibleColumns.map((column, i) => {
|
|
883
|
-
const style = getColumnStyle3(column);
|
|
884
|
-
return isGroupColumn2(column) ? /* @__PURE__ */ jsx9(
|
|
885
|
-
TableGroupHeaderCell,
|
|
886
|
-
{
|
|
887
|
-
column,
|
|
888
|
-
"data-idx": i,
|
|
889
|
-
onRemoveColumn: onRemoveColumnFromGroupBy,
|
|
890
|
-
onResize: onColumnResize,
|
|
891
|
-
role: "columnHeader",
|
|
892
|
-
style
|
|
893
|
-
},
|
|
894
|
-
i
|
|
895
|
-
) : /* @__PURE__ */ jsx9(
|
|
896
|
-
TableHeaderCell,
|
|
897
|
-
{
|
|
898
|
-
column,
|
|
899
|
-
"data-idx": i,
|
|
900
|
-
id: `${tableId}-${i}`,
|
|
901
|
-
onClick: handleHeaderClick,
|
|
902
|
-
onDragStart: handleDragStart,
|
|
903
|
-
onResize: onColumnResize,
|
|
904
|
-
role: "columnHeader",
|
|
905
|
-
style
|
|
906
|
-
},
|
|
907
|
-
i
|
|
908
|
-
);
|
|
909
|
-
}) })
|
|
910
|
-
] }),
|
|
911
|
-
/* @__PURE__ */ jsx9(
|
|
912
|
-
"div",
|
|
913
|
-
{
|
|
914
|
-
className: `${classBase5}-body`,
|
|
915
|
-
onContextMenu,
|
|
916
|
-
role: "rowGroup",
|
|
917
|
-
children: data == null ? void 0 : data.map((row) => /* @__PURE__ */ jsx9(
|
|
918
|
-
TableRow,
|
|
919
|
-
{
|
|
920
|
-
columnMap,
|
|
921
|
-
columns: columnsWithinViewport,
|
|
922
|
-
offset: getRowOffset(row),
|
|
923
|
-
onClick: onRowClick,
|
|
924
|
-
virtualColSpan,
|
|
925
|
-
onToggleGroup,
|
|
926
|
-
row
|
|
927
|
-
},
|
|
928
|
-
row[RENDER_IDX]
|
|
929
|
-
))
|
|
930
|
-
}
|
|
931
|
-
)
|
|
932
|
-
] });
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
// src/useTable.ts
|
|
936
|
-
import { useContextMenu as usePopupContextMenu } from "@vuu-ui/vuu-popups";
|
|
937
|
-
import {
|
|
938
|
-
applySort,
|
|
939
|
-
buildColumnMap as buildColumnMap2,
|
|
940
|
-
isJsonGroup as isJsonGroup2,
|
|
941
|
-
metadataKeys as metadataKeys8,
|
|
942
|
-
moveItem as moveItem2
|
|
943
|
-
} from "@vuu-ui/vuu-utils";
|
|
944
|
-
import {
|
|
945
|
-
useCallback as useCallback18,
|
|
946
|
-
useEffect as useEffect5,
|
|
947
|
-
useMemo as useMemo7,
|
|
948
|
-
useRef as useRef15,
|
|
949
|
-
useState as useState5
|
|
950
|
-
} from "react";
|
|
951
|
-
|
|
952
|
-
// src/useDataSource.ts
|
|
953
|
-
import {
|
|
954
|
-
isVuuFeatureAction,
|
|
955
|
-
isVuuFeatureInvocation
|
|
956
|
-
} from "@vuu-ui/vuu-data";
|
|
957
|
-
import { getFullRange, metadataKeys as metadataKeys5, WindowRange } from "@vuu-ui/vuu-utils";
|
|
958
|
-
import { useCallback as useCallback9, useEffect, useMemo as useMemo2, useRef as useRef6, useState as useState2 } from "react";
|
|
959
|
-
var { SELECTED: SELECTED2 } = metadataKeys5;
|
|
960
|
-
function useDataSource({
|
|
961
|
-
dataSource,
|
|
962
|
-
onConfigChange,
|
|
963
|
-
onFeatureEnabled,
|
|
964
|
-
onFeatureInvocation,
|
|
965
|
-
onSizeChange,
|
|
966
|
-
onSubscribed,
|
|
967
|
-
range = { from: 0, to: 0 },
|
|
968
|
-
renderBufferSize = 0,
|
|
969
|
-
viewportRowCount
|
|
970
|
-
}) {
|
|
971
|
-
const [, forceUpdate] = useState2(null);
|
|
972
|
-
const isMounted = useRef6(true);
|
|
973
|
-
const hasUpdated = useRef6(false);
|
|
974
|
-
const rangeRef = useRef6({ from: 0, to: 0 });
|
|
975
|
-
const rafHandle = useRef6(null);
|
|
976
|
-
const data = useRef6([]);
|
|
977
|
-
const dataWindow = useMemo2(
|
|
978
|
-
() => new MovingWindow(getFullRange(range)),
|
|
979
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
980
|
-
[]
|
|
981
|
-
);
|
|
982
|
-
const setData = useCallback9(
|
|
983
|
-
(updates) => {
|
|
984
|
-
for (const row of updates) {
|
|
985
|
-
dataWindow.add(row);
|
|
986
|
-
}
|
|
987
|
-
data.current = dataWindow.data;
|
|
988
|
-
hasUpdated.current = true;
|
|
989
|
-
},
|
|
990
|
-
[dataWindow]
|
|
991
|
-
);
|
|
992
|
-
const datasourceMessageHandler = useCallback9(
|
|
993
|
-
(message) => {
|
|
994
|
-
if (message.type === "subscribed") {
|
|
995
|
-
onSubscribed == null ? void 0 : onSubscribed(message);
|
|
996
|
-
} else if (message.type === "viewport-update") {
|
|
997
|
-
if (typeof message.size === "number") {
|
|
998
|
-
onSizeChange == null ? void 0 : onSizeChange(message.size);
|
|
999
|
-
dataWindow.setRowCount(message.size);
|
|
1000
|
-
}
|
|
1001
|
-
if (message.rows) {
|
|
1002
|
-
setData(message.rows);
|
|
1003
|
-
} else if (typeof message.size === "number") {
|
|
1004
|
-
data.current = dataWindow.data;
|
|
1005
|
-
hasUpdated.current = true;
|
|
1006
|
-
}
|
|
1007
|
-
} else if (isVuuFeatureAction(message)) {
|
|
1008
|
-
onFeatureEnabled == null ? void 0 : onFeatureEnabled(message);
|
|
1009
|
-
} else if (isVuuFeatureInvocation(message)) {
|
|
1010
|
-
onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
|
|
1011
|
-
} else {
|
|
1012
|
-
console.log(`useDataSource unexpected message ${message.type}`);
|
|
1013
|
-
}
|
|
1014
|
-
},
|
|
1015
|
-
[
|
|
1016
|
-
dataWindow,
|
|
1017
|
-
onFeatureEnabled,
|
|
1018
|
-
onFeatureInvocation,
|
|
1019
|
-
onSizeChange,
|
|
1020
|
-
onSubscribed,
|
|
1021
|
-
setData
|
|
1022
|
-
]
|
|
1023
|
-
);
|
|
1024
|
-
useEffect(
|
|
1025
|
-
() => () => {
|
|
1026
|
-
if (rafHandle.current) {
|
|
1027
|
-
cancelAnimationFrame(rafHandle.current);
|
|
1028
|
-
rafHandle.current = null;
|
|
1029
|
-
}
|
|
1030
|
-
isMounted.current = false;
|
|
1031
|
-
},
|
|
1032
|
-
[]
|
|
1033
|
-
);
|
|
1034
|
-
const refreshIfUpdated = useCallback9(() => {
|
|
1035
|
-
if (isMounted.current) {
|
|
1036
|
-
if (hasUpdated.current) {
|
|
1037
|
-
forceUpdate({});
|
|
1038
|
-
hasUpdated.current = false;
|
|
1039
|
-
}
|
|
1040
|
-
rafHandle.current = requestAnimationFrame(refreshIfUpdated);
|
|
1041
|
-
}
|
|
1042
|
-
}, [forceUpdate]);
|
|
1043
|
-
useEffect(() => {
|
|
1044
|
-
rafHandle.current = requestAnimationFrame(refreshIfUpdated);
|
|
1045
|
-
}, [refreshIfUpdated]);
|
|
1046
|
-
const adjustRange = useCallback9(
|
|
1047
|
-
(rowCount) => {
|
|
1048
|
-
const { from } = dataSource.range;
|
|
1049
|
-
const rowRange = { from, to: from + rowCount };
|
|
1050
|
-
const fullRange = getFullRange(rowRange, renderBufferSize);
|
|
1051
|
-
dataWindow.setRange(fullRange);
|
|
1052
|
-
dataSource.range = rangeRef.current = fullRange;
|
|
1053
|
-
dataSource.emit("range", rowRange);
|
|
1054
|
-
},
|
|
1055
|
-
[dataSource, dataWindow, renderBufferSize]
|
|
1056
|
-
);
|
|
1057
|
-
const setRange = useCallback9(
|
|
1058
|
-
(range2) => {
|
|
1059
|
-
const fullRange = getFullRange(range2, renderBufferSize);
|
|
1060
|
-
dataWindow.setRange(fullRange);
|
|
1061
|
-
dataSource.range = rangeRef.current = fullRange;
|
|
1062
|
-
dataSource.emit("range", range2);
|
|
1063
|
-
},
|
|
1064
|
-
[dataSource, dataWindow, renderBufferSize]
|
|
1065
|
-
);
|
|
1066
|
-
const getSelectedRows = useCallback9(() => {
|
|
1067
|
-
return dataWindow.getSelectedRows();
|
|
1068
|
-
}, [dataWindow]);
|
|
1069
|
-
useEffect(() => {
|
|
1070
|
-
dataSource == null ? void 0 : dataSource.subscribe(
|
|
1071
|
-
{
|
|
1072
|
-
range: rangeRef.current
|
|
1073
|
-
},
|
|
1074
|
-
datasourceMessageHandler
|
|
1075
|
-
);
|
|
1076
|
-
}, [dataSource, datasourceMessageHandler, onConfigChange]);
|
|
1077
|
-
useEffect(() => {
|
|
1078
|
-
adjustRange(viewportRowCount);
|
|
1079
|
-
}, [adjustRange, viewportRowCount]);
|
|
1080
|
-
return {
|
|
1081
|
-
data: data.current,
|
|
1082
|
-
getSelectedRows,
|
|
1083
|
-
range: rangeRef.current,
|
|
1084
|
-
setRange,
|
|
1085
|
-
dataSource
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
var MovingWindow = class {
|
|
1089
|
-
constructor({ from, to }) {
|
|
1090
|
-
this.rowCount = 0;
|
|
1091
|
-
this.setRowCount = (rowCount) => {
|
|
1092
|
-
if (rowCount < this.data.length) {
|
|
1093
|
-
this.data.length = rowCount;
|
|
1094
|
-
}
|
|
1095
|
-
this.rowCount = rowCount;
|
|
1096
|
-
};
|
|
1097
|
-
this.range = new WindowRange(from, to);
|
|
1098
|
-
this.data = new Array(to - from);
|
|
1099
|
-
this.rowCount = 0;
|
|
1100
|
-
}
|
|
1101
|
-
add(data) {
|
|
1102
|
-
var _a;
|
|
1103
|
-
const [index] = data;
|
|
1104
|
-
if (this.isWithinRange(index)) {
|
|
1105
|
-
const internalIndex = index - this.range.from;
|
|
1106
|
-
this.data[internalIndex] = data;
|
|
1107
|
-
const isSelected = data[SELECTED2];
|
|
1108
|
-
const preSelected = (_a = this.data[internalIndex - 1]) == null ? void 0 : _a[SELECTED2];
|
|
1109
|
-
if (preSelected === 0 && isSelected) {
|
|
1110
|
-
this.data[internalIndex - 1][SELECTED2] = 2;
|
|
1111
|
-
} else if (preSelected === 2 && !isSelected) {
|
|
1112
|
-
this.data[internalIndex - 1][SELECTED2] = 0;
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
getAtIndex(index) {
|
|
1117
|
-
return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
|
|
1118
|
-
}
|
|
1119
|
-
isWithinRange(index) {
|
|
1120
|
-
return this.range.isWithin(index);
|
|
1121
|
-
}
|
|
1122
|
-
setRange({ from, to }) {
|
|
1123
|
-
if (from !== this.range.from || to !== this.range.to) {
|
|
1124
|
-
const [overlapFrom, overlapTo] = this.range.overlap(from, to);
|
|
1125
|
-
const newData = new Array(Math.max(0, to - from));
|
|
1126
|
-
for (let i = overlapFrom; i < overlapTo; i++) {
|
|
1127
|
-
const data = this.getAtIndex(i);
|
|
1128
|
-
if (data) {
|
|
1129
|
-
const index = i - from;
|
|
1130
|
-
newData[index] = data;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
this.data = newData;
|
|
1134
|
-
this.range.from = from;
|
|
1135
|
-
this.range.to = to;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
getSelectedRows() {
|
|
1139
|
-
return this.data.filter((row) => row[SELECTED2] === 1);
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1142
|
-
|
|
1143
|
-
// src/useDraggableColumn.ts
|
|
1144
|
-
import { useDragDrop } from "@heswell/salt-lab";
|
|
1145
|
-
import { useCallback as useCallback10, useRef as useRef7 } from "react";
|
|
1146
|
-
var useDraggableColumn = ({ onDrop }) => {
|
|
1147
|
-
const mousePosRef = useRef7();
|
|
1148
|
-
const containerRef = useRef7(null);
|
|
1149
|
-
const handleDropSettle = useCallback10(() => {
|
|
1150
|
-
console.log(`handleDropSettle`);
|
|
1151
|
-
mousePosRef.current = void 0;
|
|
1152
|
-
containerRef.current = null;
|
|
1153
|
-
}, []);
|
|
1154
|
-
const { draggable, draggedItemIndex, onMouseDown } = useDragDrop({
|
|
1155
|
-
// allowDragDrop: "drop-indicator",
|
|
1156
|
-
allowDragDrop: true,
|
|
1157
|
-
draggableClassName: "vuuTable-headerCell",
|
|
1158
|
-
orientation: "horizontal",
|
|
1159
|
-
containerRef,
|
|
1160
|
-
itemQuery: ".vuuTable-headerCell",
|
|
1161
|
-
onDrop,
|
|
1162
|
-
onDropSettle: handleDropSettle
|
|
1163
|
-
});
|
|
1164
|
-
const onHeaderCellDragStart = useCallback10(
|
|
1165
|
-
(evt) => {
|
|
1166
|
-
const { clientX, clientY } = evt;
|
|
1167
|
-
console.log(
|
|
1168
|
-
`useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable`
|
|
1169
|
-
);
|
|
1170
|
-
const sourceElement = evt.target;
|
|
1171
|
-
const columnHeaderCell = sourceElement.closest(".vuuTable-headerCell");
|
|
1172
|
-
containerRef.current = columnHeaderCell == null ? void 0 : columnHeaderCell.closest(
|
|
1173
|
-
"[role='row']"
|
|
1174
|
-
);
|
|
1175
|
-
const {
|
|
1176
|
-
dataset: { idx = "-1" }
|
|
1177
|
-
} = columnHeaderCell;
|
|
1178
|
-
mousePosRef.current = {
|
|
1179
|
-
clientX,
|
|
1180
|
-
clientY,
|
|
1181
|
-
idx
|
|
1182
|
-
};
|
|
1183
|
-
onMouseDown == null ? void 0 : onMouseDown(evt);
|
|
1184
|
-
},
|
|
1185
|
-
[onMouseDown]
|
|
1186
|
-
);
|
|
1187
|
-
return {
|
|
1188
|
-
draggable,
|
|
1189
|
-
draggedItemIndex,
|
|
1190
|
-
onHeaderCellDragStart
|
|
1191
|
-
};
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
|
-
// src/useKeyboardNavigation.ts
|
|
1195
|
-
import { withinRange } from "@vuu-ui/vuu-utils";
|
|
1196
|
-
import {
|
|
1197
|
-
useCallback as useCallback11,
|
|
1198
|
-
useEffect as useEffect2,
|
|
1199
|
-
useLayoutEffect,
|
|
1200
|
-
useMemo as useMemo3,
|
|
1201
|
-
useRef as useRef8
|
|
1202
|
-
} from "react";
|
|
1203
|
-
|
|
1204
|
-
// src/keyUtils.ts
|
|
1205
|
-
function union(set1, ...sets) {
|
|
1206
|
-
const result = new Set(set1);
|
|
1207
|
-
for (let set of sets) {
|
|
1208
|
-
for (let element of set) {
|
|
1209
|
-
result.add(element);
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
return result;
|
|
1213
|
-
}
|
|
1214
|
-
var ArrowUp = "ArrowUp";
|
|
1215
|
-
var ArrowDown = "ArrowDown";
|
|
1216
|
-
var ArrowLeft = "ArrowLeft";
|
|
1217
|
-
var ArrowRight = "ArrowRight";
|
|
1218
|
-
var Home = "Home";
|
|
1219
|
-
var End = "End";
|
|
1220
|
-
var PageUp = "PageUp";
|
|
1221
|
-
var PageDown = "PageDown";
|
|
1222
|
-
var actionKeys = /* @__PURE__ */ new Set(["Enter", "Delete", " "]);
|
|
1223
|
-
var focusKeys = /* @__PURE__ */ new Set(["Tab"]);
|
|
1224
|
-
var arrowLeftRightKeys = /* @__PURE__ */ new Set(["ArrowRight", "ArrowLeft"]);
|
|
1225
|
-
var navigationKeys = /* @__PURE__ */ new Set([
|
|
1226
|
-
Home,
|
|
1227
|
-
End,
|
|
1228
|
-
PageUp,
|
|
1229
|
-
PageDown,
|
|
1230
|
-
ArrowDown,
|
|
1231
|
-
ArrowLeft,
|
|
1232
|
-
ArrowRight,
|
|
1233
|
-
ArrowUp
|
|
1234
|
-
]);
|
|
1235
|
-
var functionKeys = /* @__PURE__ */ new Set([
|
|
1236
|
-
"F1",
|
|
1237
|
-
"F2",
|
|
1238
|
-
"F3",
|
|
1239
|
-
"F4",
|
|
1240
|
-
"F5",
|
|
1241
|
-
"F6",
|
|
1242
|
-
"F7",
|
|
1243
|
-
"F8",
|
|
1244
|
-
"F9",
|
|
1245
|
-
"F10",
|
|
1246
|
-
"F11",
|
|
1247
|
-
"F12"
|
|
1248
|
-
]);
|
|
1249
|
-
var specialKeys = union(
|
|
1250
|
-
actionKeys,
|
|
1251
|
-
navigationKeys,
|
|
1252
|
-
arrowLeftRightKeys,
|
|
1253
|
-
functionKeys,
|
|
1254
|
-
focusKeys
|
|
1255
|
-
);
|
|
1256
|
-
var PageKeys = ["Home", "End", "PageUp", "PageDown"];
|
|
1257
|
-
var isPagingKey = (key) => PageKeys.includes(key);
|
|
1258
|
-
var isNavigationKey = (key) => {
|
|
1259
|
-
return navigationKeys.has(key);
|
|
1260
|
-
};
|
|
1261
|
-
|
|
1262
|
-
// src/useKeyboardNavigation.ts
|
|
1263
|
-
var headerCellQuery = (colIdx) => `.vuuTable-headers .vuuTable-headerCell:nth-child(${colIdx + 1})`;
|
|
1264
|
-
var dataCellQuery = (rowIdx, colIdx) => `.vuuTable-body > [aria-rowindex='${rowIdx}'] > [role='cell']:nth-child(${colIdx + 1})`;
|
|
1265
|
-
var NULL_CELL_POS = [-1, -1];
|
|
1266
|
-
function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
|
|
1267
|
-
if (key === ArrowUp) {
|
|
1268
|
-
if (rowIdx > -1) {
|
|
1269
|
-
return [rowIdx - 1, colIdx];
|
|
1270
|
-
} else {
|
|
1271
|
-
return [rowIdx, colIdx];
|
|
1272
|
-
}
|
|
1273
|
-
} else if (key === ArrowDown) {
|
|
1274
|
-
if (rowIdx === -1) {
|
|
1275
|
-
return [0, colIdx];
|
|
1276
|
-
} else if (rowIdx === rowCount - 1) {
|
|
1277
|
-
return [rowIdx, colIdx];
|
|
1278
|
-
} else {
|
|
1279
|
-
return [rowIdx + 1, colIdx];
|
|
1280
|
-
}
|
|
1281
|
-
} else if (key === ArrowRight) {
|
|
1282
|
-
if (colIdx < columnCount - 1) {
|
|
1283
|
-
return [rowIdx, colIdx + 1];
|
|
1284
|
-
} else {
|
|
1285
|
-
return [rowIdx, colIdx];
|
|
1286
|
-
}
|
|
1287
|
-
} else if (key === ArrowLeft) {
|
|
1288
|
-
if (colIdx > 0) {
|
|
1289
|
-
return [rowIdx, colIdx - 1];
|
|
1290
|
-
} else {
|
|
1291
|
-
return [rowIdx, colIdx];
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
return [rowIdx, colIdx];
|
|
1295
|
-
}
|
|
1296
|
-
var useKeyboardNavigation = ({
|
|
1297
|
-
columnCount = 0,
|
|
1298
|
-
containerRef,
|
|
1299
|
-
disableHighlightOnFocus,
|
|
1300
|
-
data,
|
|
1301
|
-
requestScroll,
|
|
1302
|
-
rowCount = 0,
|
|
1303
|
-
viewportRange
|
|
1304
|
-
}) => {
|
|
1305
|
-
var _a;
|
|
1306
|
-
const { from: viewportFirstRow, to: viewportLastRow } = viewportRange;
|
|
1307
|
-
const focusedCellPos = useRef8([-1, -1]);
|
|
1308
|
-
const focusableCell = useRef8();
|
|
1309
|
-
const activeCellPos = useRef8([-1, 0]);
|
|
1310
|
-
const getTableCell = useCallback11(
|
|
1311
|
-
([rowIdx, colIdx]) => {
|
|
1312
|
-
var _a2;
|
|
1313
|
-
const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
|
|
1314
|
-
return (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
|
|
1315
|
-
cssQuery
|
|
1316
|
-
);
|
|
1317
|
-
},
|
|
1318
|
-
[containerRef]
|
|
1319
|
-
);
|
|
1320
|
-
const getFocusedCell = (element) => element == null ? void 0 : element.closest(
|
|
1321
|
-
"[role='columnHeader'],[role='cell']"
|
|
1322
|
-
);
|
|
1323
|
-
const getTableCellPos = (tableCell) => {
|
|
1324
|
-
var _a2, _b;
|
|
1325
|
-
if (tableCell.role === "columnHeader") {
|
|
1326
|
-
const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
|
|
1327
|
-
return [-1, colIdx];
|
|
1328
|
-
} else {
|
|
1329
|
-
const focusedRow = tableCell.closest("[role='row']");
|
|
1330
|
-
if (focusedRow) {
|
|
1331
|
-
const rowIdx = parseInt((_b = focusedRow.ariaRowIndex) != null ? _b : "-1", 10);
|
|
1332
|
-
const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
|
|
1333
|
-
return [rowIdx, colIdx];
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
return NULL_CELL_POS;
|
|
1337
|
-
};
|
|
1338
|
-
const focusCell = useCallback11(
|
|
1339
|
-
(cellPos) => {
|
|
1340
|
-
var _a2;
|
|
1341
|
-
if (containerRef.current) {
|
|
1342
|
-
const activeCell = getTableCell(cellPos);
|
|
1343
|
-
if (activeCell) {
|
|
1344
|
-
if (activeCell !== focusableCell.current) {
|
|
1345
|
-
(_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
|
|
1346
|
-
focusableCell.current = activeCell;
|
|
1347
|
-
activeCell.setAttribute("tabindex", "0");
|
|
1348
|
-
}
|
|
1349
|
-
activeCell.focus();
|
|
1350
|
-
} else if (!withinRange(cellPos[0], viewportRange)) {
|
|
1351
|
-
focusableCell.current = void 0;
|
|
1352
|
-
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
},
|
|
1356
|
-
// TODO we recreate this function whenever viewportRange changes, which will
|
|
1357
|
-
// be often whilst scrolling - store range in a a ref ?
|
|
1358
|
-
[containerRef, getTableCell, requestScroll, viewportRange]
|
|
1359
|
-
);
|
|
1360
|
-
const setActiveCell = useCallback11(
|
|
1361
|
-
(rowIdx, colIdx, fromKeyboard = false) => {
|
|
1362
|
-
const pos = [rowIdx, colIdx];
|
|
1363
|
-
activeCellPos.current = pos;
|
|
1364
|
-
focusCell(pos);
|
|
1365
|
-
if (fromKeyboard) {
|
|
1366
|
-
focusedCellPos.current = pos;
|
|
1367
|
-
}
|
|
1368
|
-
},
|
|
1369
|
-
[focusCell]
|
|
1370
|
-
);
|
|
1371
|
-
const virtualizeActiveCell = useCallback11(() => {
|
|
1372
|
-
var _a2;
|
|
1373
|
-
(_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
|
|
1374
|
-
focusableCell.current = void 0;
|
|
1375
|
-
}, []);
|
|
1376
|
-
const nextPageItemIdx = useCallback11(
|
|
1377
|
-
async (key, cellPos) => {
|
|
1378
|
-
switch (key) {
|
|
1379
|
-
case PageDown:
|
|
1380
|
-
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
|
|
1381
|
-
break;
|
|
1382
|
-
case PageUp:
|
|
1383
|
-
requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
|
|
1384
|
-
break;
|
|
1385
|
-
case Home:
|
|
1386
|
-
requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
|
|
1387
|
-
break;
|
|
1388
|
-
case End:
|
|
1389
|
-
requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
|
|
1390
|
-
break;
|
|
1391
|
-
}
|
|
1392
|
-
return cellPos;
|
|
1393
|
-
},
|
|
1394
|
-
[requestScroll]
|
|
1395
|
-
);
|
|
1396
|
-
const handleFocus = useCallback11(() => {
|
|
1397
|
-
var _a2;
|
|
1398
|
-
if (disableHighlightOnFocus !== true) {
|
|
1399
|
-
if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
|
|
1400
|
-
const focusedCell = getFocusedCell(document.activeElement);
|
|
1401
|
-
if (focusedCell) {
|
|
1402
|
-
focusedCellPos.current = getTableCellPos(focusedCell);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
}, [disableHighlightOnFocus, containerRef]);
|
|
1407
|
-
const navigateChildItems = useCallback11(
|
|
1408
|
-
async (key) => {
|
|
1409
|
-
const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
|
|
1410
|
-
const [rowIdx, colIdx] = activeCellPos.current;
|
|
1411
|
-
if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
|
|
1412
|
-
setActiveCell(nextRowIdx, nextColIdx, true);
|
|
1413
|
-
}
|
|
1414
|
-
},
|
|
1415
|
-
[columnCount, nextPageItemIdx, rowCount, setActiveCell]
|
|
1416
|
-
);
|
|
1417
|
-
const handleKeyDown = useCallback11(
|
|
1418
|
-
(e) => {
|
|
1419
|
-
if (data.length > 0 && isNavigationKey(e.key)) {
|
|
1420
|
-
e.preventDefault();
|
|
1421
|
-
e.stopPropagation();
|
|
1422
|
-
void navigateChildItems(e.key);
|
|
1423
|
-
}
|
|
1424
|
-
},
|
|
1425
|
-
[data, navigateChildItems]
|
|
1426
|
-
);
|
|
1427
|
-
const handleClick = useCallback11(
|
|
1428
|
-
// Might not be a cell e.g the Settings button
|
|
1429
|
-
(evt) => {
|
|
1430
|
-
const target = evt.target;
|
|
1431
|
-
const focusedCell = getFocusedCell(target);
|
|
1432
|
-
if (focusedCell) {
|
|
1433
|
-
const [rowIdx, colIdx] = getTableCellPos(focusedCell);
|
|
1434
|
-
setActiveCell(rowIdx, colIdx);
|
|
1435
|
-
}
|
|
1436
|
-
},
|
|
1437
|
-
[setActiveCell]
|
|
1438
|
-
);
|
|
1439
|
-
const containerProps = useMemo3(() => {
|
|
1440
|
-
return {
|
|
1441
|
-
onClick: handleClick,
|
|
1442
|
-
onFocus: handleFocus,
|
|
1443
|
-
onKeyDown: handleKeyDown
|
|
1444
|
-
};
|
|
1445
|
-
}, [handleClick, handleFocus, handleKeyDown]);
|
|
1446
|
-
useLayoutEffect(() => {
|
|
1447
|
-
const { current: cellPos } = activeCellPos;
|
|
1448
|
-
const withinViewport = cellPos[0] >= viewportFirstRow && cellPos[0] <= viewportLastRow;
|
|
1449
|
-
if (focusableCell.current && !withinViewport) {
|
|
1450
|
-
virtualizeActiveCell();
|
|
1451
|
-
} else if (!focusableCell.current && withinViewport) {
|
|
1452
|
-
focusCell(cellPos);
|
|
1453
|
-
}
|
|
1454
|
-
}, [focusCell, viewportFirstRow, viewportLastRow, virtualizeActiveCell]);
|
|
1455
|
-
const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
|
|
1456
|
-
useEffect2(() => {
|
|
1457
|
-
var _a2;
|
|
1458
|
-
if (fullyRendered && focusableCell.current === void 0) {
|
|
1459
|
-
const headerCell = (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
|
|
1460
|
-
headerCellQuery(0)
|
|
1461
|
-
);
|
|
1462
|
-
if (headerCell) {
|
|
1463
|
-
headerCell.setAttribute("tabindex", "0");
|
|
1464
|
-
focusableCell.current = headerCell;
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
}, [containerRef, fullyRendered]);
|
|
1468
|
-
return containerProps;
|
|
1469
|
-
};
|
|
1470
|
-
|
|
1471
|
-
// src/useMeasuredContainer.ts
|
|
1472
|
-
import { isValidNumber } from "@vuu-ui/vuu-utils";
|
|
1473
|
-
import { useCallback as useCallback13, useMemo as useMemo4, useRef as useRef10, useState as useState3 } from "react";
|
|
1474
|
-
|
|
1475
|
-
// src/useResizeObserver.ts
|
|
1476
|
-
import { useCallback as useCallback12, useEffect as useEffect3, useRef as useRef9 } from "react";
|
|
1477
|
-
var observedMap = /* @__PURE__ */ new Map();
|
|
1478
|
-
var getTargetSize = (element, size, dimension) => {
|
|
1479
|
-
switch (dimension) {
|
|
1480
|
-
case "height":
|
|
1481
|
-
return size.height;
|
|
1482
|
-
case "clientHeight":
|
|
1483
|
-
return element.clientHeight;
|
|
1484
|
-
case "clientWidth":
|
|
1485
|
-
return element.clientWidth;
|
|
1486
|
-
case "contentHeight":
|
|
1487
|
-
return size.contentHeight;
|
|
1488
|
-
case "contentWidth":
|
|
1489
|
-
return size.contentWidth;
|
|
1490
|
-
case "scrollHeight":
|
|
1491
|
-
return Math.ceil(element.scrollHeight);
|
|
1492
|
-
case "scrollWidth":
|
|
1493
|
-
return Math.ceil(element.scrollWidth);
|
|
1494
|
-
case "width":
|
|
1495
|
-
return size.width;
|
|
1496
|
-
default:
|
|
1497
|
-
return 0;
|
|
1498
|
-
}
|
|
1499
|
-
};
|
|
1500
|
-
var resizeObserver = new ResizeObserver((entries) => {
|
|
1501
|
-
for (const entry of entries) {
|
|
1502
|
-
const { target, borderBoxSize, contentBoxSize } = entry;
|
|
1503
|
-
const observedTarget = observedMap.get(target);
|
|
1504
|
-
if (observedTarget) {
|
|
1505
|
-
const [{ blockSize: height, inlineSize: width }] = borderBoxSize;
|
|
1506
|
-
const [{ blockSize: contentHeight, inlineSize: contentWidth }] = contentBoxSize;
|
|
1507
|
-
const { onResize, measurements } = observedTarget;
|
|
1508
|
-
let sizeChanged = false;
|
|
1509
|
-
for (const [dimension, size] of Object.entries(measurements)) {
|
|
1510
|
-
const newSize = getTargetSize(
|
|
1511
|
-
target,
|
|
1512
|
-
{ height, width, contentHeight, contentWidth },
|
|
1513
|
-
dimension
|
|
1514
|
-
);
|
|
1515
|
-
if (newSize !== size) {
|
|
1516
|
-
sizeChanged = true;
|
|
1517
|
-
measurements[dimension] = newSize;
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
if (sizeChanged) {
|
|
1521
|
-
onResize && onResize(measurements);
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
});
|
|
1526
|
-
function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false) {
|
|
1527
|
-
const dimensionsRef = useRef9(dimensions);
|
|
1528
|
-
const measure = useCallback12((target) => {
|
|
1529
|
-
const { width, height } = target.getBoundingClientRect();
|
|
1530
|
-
const { clientWidth: contentWidth, clientHeight: contentHeight } = target;
|
|
1531
|
-
return dimensionsRef.current.reduce(
|
|
1532
|
-
(map, dim) => {
|
|
1533
|
-
map[dim] = getTargetSize(
|
|
1534
|
-
target,
|
|
1535
|
-
{ width, height, contentHeight, contentWidth },
|
|
1536
|
-
dim
|
|
1537
|
-
);
|
|
1538
|
-
return map;
|
|
1539
|
-
},
|
|
1540
|
-
{}
|
|
1541
|
-
);
|
|
1542
|
-
}, []);
|
|
1543
|
-
useEffect3(() => {
|
|
1544
|
-
const target = ref.current;
|
|
1545
|
-
async function registerObserver() {
|
|
1546
|
-
observedMap.set(target, { measurements: {} });
|
|
1547
|
-
await document.fonts.ready;
|
|
1548
|
-
const observedTarget = observedMap.get(target);
|
|
1549
|
-
if (observedTarget) {
|
|
1550
|
-
const measurements = measure(target);
|
|
1551
|
-
observedTarget.measurements = measurements;
|
|
1552
|
-
resizeObserver.observe(target);
|
|
1553
|
-
if (reportInitialSize) {
|
|
1554
|
-
onResize(measurements);
|
|
1555
|
-
}
|
|
1556
|
-
} else {
|
|
1557
|
-
console.log(
|
|
1558
|
-
`%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation`,
|
|
1559
|
-
"font-weight:bold; color:red;"
|
|
1560
|
-
);
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
if (target) {
|
|
1564
|
-
if (observedMap.has(target)) {
|
|
1565
|
-
throw Error(
|
|
1566
|
-
"useResizeObserver attemping to observe same element twice"
|
|
1567
|
-
);
|
|
1568
|
-
}
|
|
1569
|
-
registerObserver();
|
|
1570
|
-
}
|
|
1571
|
-
return () => {
|
|
1572
|
-
if (target && observedMap.has(target)) {
|
|
1573
|
-
resizeObserver.unobserve(target);
|
|
1574
|
-
observedMap.delete(target);
|
|
1575
|
-
}
|
|
1576
|
-
};
|
|
1577
|
-
}, [measure, ref]);
|
|
1578
|
-
useEffect3(() => {
|
|
1579
|
-
const target = ref.current;
|
|
1580
|
-
const record = observedMap.get(target);
|
|
1581
|
-
if (record) {
|
|
1582
|
-
if (dimensionsRef.current !== dimensions) {
|
|
1583
|
-
dimensionsRef.current = dimensions;
|
|
1584
|
-
const measurements = measure(target);
|
|
1585
|
-
record.measurements = measurements;
|
|
1586
|
-
}
|
|
1587
|
-
record.onResize = onResize;
|
|
1588
|
-
}
|
|
1589
|
-
}, [dimensions, measure, ref, onResize]);
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
// src/useMeasuredContainer.ts
|
|
1593
|
-
var ClientWidthHeight = ["clientHeight", "clientWidth"];
|
|
1594
|
-
var isNumber = (val) => Number.isFinite(val);
|
|
1595
|
-
var FULL_SIZE = { height: "100%", width: "100%" };
|
|
1596
|
-
var getInitialCssSize = (height, width) => {
|
|
1597
|
-
if (isValidNumber(height) && isValidNumber(width)) {
|
|
1598
|
-
return {
|
|
1599
|
-
height: `${height}px`,
|
|
1600
|
-
width: `${width}px`
|
|
1601
|
-
};
|
|
1602
|
-
} else {
|
|
1603
|
-
return FULL_SIZE;
|
|
1604
|
-
}
|
|
1605
|
-
};
|
|
1606
|
-
var getInitialInnerSize = (height, width) => {
|
|
1607
|
-
if (isValidNumber(height) && isValidNumber(width)) {
|
|
1608
|
-
return {
|
|
1609
|
-
height,
|
|
1610
|
-
width
|
|
1611
|
-
};
|
|
1612
|
-
}
|
|
1613
|
-
};
|
|
1614
|
-
var useMeasuredContainer = ({
|
|
1615
|
-
defaultHeight = 0,
|
|
1616
|
-
defaultWidth = 0,
|
|
1617
|
-
height,
|
|
1618
|
-
width
|
|
1619
|
-
}) => {
|
|
1620
|
-
const containerRef = useRef10(null);
|
|
1621
|
-
const [size, setSize] = useState3({
|
|
1622
|
-
css: getInitialCssSize(height, width),
|
|
1623
|
-
inner: getInitialInnerSize(height, width),
|
|
1624
|
-
outer: {
|
|
1625
|
-
height: height != null ? height : "100%",
|
|
1626
|
-
width: width != null ? width : "100%"
|
|
1627
|
-
}
|
|
1628
|
-
});
|
|
1629
|
-
useMemo4(() => {
|
|
1630
|
-
setSize((currentSize) => {
|
|
1631
|
-
const { inner, outer } = currentSize;
|
|
1632
|
-
if (isValidNumber(height) && isValidNumber(width) && inner && outer) {
|
|
1633
|
-
const { height: innerHeight, width: innerWidth } = inner;
|
|
1634
|
-
const { height: outerHeight, width: outerWidth } = outer;
|
|
1635
|
-
if (outerHeight !== height || outerWidth !== width) {
|
|
1636
|
-
const heightDiff = isValidNumber(outerHeight) ? outerHeight - innerHeight : 0;
|
|
1637
|
-
const widthDiff = isValidNumber(outerWidth) ? outerWidth - innerWidth : 0;
|
|
1638
|
-
return {
|
|
1639
|
-
...currentSize,
|
|
1640
|
-
outer: { height, width },
|
|
1641
|
-
inner: { height: height - heightDiff, width: width - widthDiff }
|
|
1642
|
-
};
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return currentSize;
|
|
1646
|
-
});
|
|
1647
|
-
}, [height, width]);
|
|
1648
|
-
const onResize = useCallback13(
|
|
1649
|
-
({ clientWidth, clientHeight }) => {
|
|
1650
|
-
setSize((currentSize) => {
|
|
1651
|
-
const { css, inner, outer } = currentSize;
|
|
1652
|
-
return isNumber(clientHeight) && isNumber(clientWidth) && (clientWidth !== (inner == null ? void 0 : inner.width) || clientHeight !== (inner == null ? void 0 : inner.height)) ? {
|
|
1653
|
-
css,
|
|
1654
|
-
outer,
|
|
1655
|
-
inner: {
|
|
1656
|
-
width: Math.floor(clientWidth) || defaultWidth,
|
|
1657
|
-
height: Math.floor(clientHeight) || defaultHeight
|
|
1658
|
-
}
|
|
1659
|
-
} : currentSize;
|
|
1660
|
-
});
|
|
1661
|
-
},
|
|
1662
|
-
[defaultHeight, defaultWidth]
|
|
1663
|
-
);
|
|
1664
|
-
useResizeObserver(containerRef, ClientWidthHeight, onResize, true);
|
|
1665
|
-
return {
|
|
1666
|
-
containerRef,
|
|
1667
|
-
cssSize: size.css,
|
|
1668
|
-
outerSize: size.outer,
|
|
1669
|
-
innerSize: size.inner
|
|
1670
|
-
};
|
|
1671
|
-
};
|
|
1672
|
-
|
|
1673
|
-
// src/useSelection.ts
|
|
1674
|
-
import { deselectItem, metadataKeys as metadataKeys6, selectItem } from "@vuu-ui/vuu-utils";
|
|
1675
|
-
import { useCallback as useCallback14, useRef as useRef11 } from "react";
|
|
1676
|
-
var { IDX: IDX2, SELECTED: SELECTED3 } = metadataKeys6;
|
|
1677
|
-
var NO_SELECTION = [];
|
|
1678
|
-
var useSelection = ({
|
|
1679
|
-
selectionModel,
|
|
1680
|
-
onSelectionChange
|
|
1681
|
-
}) => {
|
|
1682
|
-
selectionModel === "extended" || selectionModel === "checkbox";
|
|
1683
|
-
const lastActiveRef = useRef11(-1);
|
|
1684
|
-
const selectedRef = useRef11(NO_SELECTION);
|
|
1685
|
-
const handleSelectionChange = useCallback14(
|
|
1686
|
-
(row, rangeSelect, keepExistingSelection) => {
|
|
1687
|
-
const { [IDX2]: idx, [SELECTED3]: isSelected } = row;
|
|
1688
|
-
const { current: active } = lastActiveRef;
|
|
1689
|
-
const { current: selected } = selectedRef;
|
|
1690
|
-
const selectOperation = isSelected ? deselectItem : selectItem;
|
|
1691
|
-
const newSelected = selectOperation(
|
|
1692
|
-
selectionModel,
|
|
1693
|
-
selected,
|
|
1694
|
-
idx,
|
|
1695
|
-
rangeSelect,
|
|
1696
|
-
keepExistingSelection,
|
|
1697
|
-
active
|
|
1698
|
-
);
|
|
1699
|
-
selectedRef.current = newSelected;
|
|
1700
|
-
lastActiveRef.current = idx;
|
|
1701
|
-
if (onSelectionChange) {
|
|
1702
|
-
onSelectionChange(newSelected);
|
|
1703
|
-
}
|
|
1704
|
-
},
|
|
1705
|
-
[onSelectionChange, selectionModel]
|
|
1706
|
-
);
|
|
1707
|
-
return handleSelectionChange;
|
|
1708
|
-
};
|
|
1709
|
-
|
|
1710
|
-
// src/useTableModel.ts
|
|
1711
|
-
import { moveItem } from "@heswell/salt-lab";
|
|
1712
|
-
import {
|
|
1713
|
-
applyFilterToColumns,
|
|
1714
|
-
applyGroupByToColumns,
|
|
1715
|
-
applySortToColumns,
|
|
1716
|
-
findColumn,
|
|
1717
|
-
getCellRenderer,
|
|
1718
|
-
getColumnName,
|
|
1719
|
-
getTableHeadings,
|
|
1720
|
-
getValueFormatter,
|
|
1721
|
-
isFilteredColumn,
|
|
1722
|
-
isGroupColumn as isGroupColumn3,
|
|
1723
|
-
isPinned,
|
|
1724
|
-
isTypeDescriptor,
|
|
1725
|
-
logger,
|
|
1726
|
-
metadataKeys as metadataKeys7,
|
|
1727
|
-
sortPinnedColumns,
|
|
1728
|
-
stripFilterFromColumns
|
|
1729
|
-
} from "@vuu-ui/vuu-utils";
|
|
1730
|
-
import { useReducer } from "react";
|
|
1731
|
-
var { info } = logger("useTableModel");
|
|
1732
|
-
var DEFAULT_COLUMN_WIDTH = 100;
|
|
1733
|
-
var KEY_OFFSET = metadataKeys7.count;
|
|
1734
|
-
var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
|
|
1735
|
-
var getCellRendererForColumn = (column) => {
|
|
1736
|
-
var _a;
|
|
1737
|
-
if (isTypeDescriptor(column.type)) {
|
|
1738
|
-
return getCellRenderer((_a = column.type) == null ? void 0 : _a.renderer);
|
|
1739
|
-
}
|
|
1740
|
-
};
|
|
1741
|
-
var getServerDataTypeForColumn = (column, tableSchema) => {
|
|
1742
|
-
if (column.serverDataType) {
|
|
1743
|
-
return column.serverDataType;
|
|
1744
|
-
} else if (tableSchema) {
|
|
1745
|
-
const schemaColumn = tableSchema.columns.find(
|
|
1746
|
-
(col) => col.name === column.name
|
|
1747
|
-
);
|
|
1748
|
-
if (schemaColumn) {
|
|
1749
|
-
return schemaColumn.serverDataType;
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
return "string";
|
|
1753
|
-
};
|
|
1754
|
-
var numericTypes = ["int", "long", "double"];
|
|
1755
|
-
var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
|
|
1756
|
-
var columnReducer = (state, action) => {
|
|
1757
|
-
info == null ? void 0 : info(`GridModelReducer ${action.type}`);
|
|
1758
|
-
switch (action.type) {
|
|
1759
|
-
case "init":
|
|
1760
|
-
return init(action);
|
|
1761
|
-
case "moveColumn":
|
|
1762
|
-
return moveColumn(state, action);
|
|
1763
|
-
case "resizeColumn":
|
|
1764
|
-
return resizeColumn(state, action);
|
|
1765
|
-
case "setTableSchema":
|
|
1766
|
-
return setTableSchema(state, action);
|
|
1767
|
-
case "hideColumns":
|
|
1768
|
-
return hideColumns(state, action);
|
|
1769
|
-
case "showColumns":
|
|
1770
|
-
return showColumns(state, action);
|
|
1771
|
-
case "pinColumn":
|
|
1772
|
-
return pinColumn2(state, action);
|
|
1773
|
-
case "updateColumnProp":
|
|
1774
|
-
return updateColumnProp(state, action);
|
|
1775
|
-
case "tableConfig":
|
|
1776
|
-
return updateTableConfig(state, action);
|
|
1777
|
-
default:
|
|
1778
|
-
console.log(`unhandled action ${action.type}`);
|
|
1779
|
-
return state;
|
|
1780
|
-
}
|
|
1781
|
-
};
|
|
1782
|
-
var useTableModel = (tableConfig, dataSourceConfig) => {
|
|
1783
|
-
const [state, dispatchColumnAction] = useReducer(columnReducer, { tableConfig, dataSourceConfig }, init);
|
|
1784
|
-
return {
|
|
1785
|
-
columns: state.columns,
|
|
1786
|
-
dispatchColumnAction,
|
|
1787
|
-
headings: state.headings
|
|
1788
|
-
};
|
|
1789
|
-
};
|
|
1790
|
-
function init({ dataSourceConfig, tableConfig }) {
|
|
1791
|
-
const columns = tableConfig.columns.map(
|
|
1792
|
-
toKeyedColumWithDefaults(tableConfig)
|
|
1793
|
-
);
|
|
1794
|
-
const maybePinnedColumns = columns.some(isPinned) ? sortPinnedColumns(columns) : columns;
|
|
1795
|
-
const state = {
|
|
1796
|
-
columns: maybePinnedColumns,
|
|
1797
|
-
headings: getTableHeadings(maybePinnedColumns)
|
|
1798
|
-
};
|
|
1799
|
-
if (dataSourceConfig) {
|
|
1800
|
-
const { columns: columns2, ...rest } = dataSourceConfig;
|
|
1801
|
-
return updateTableConfig(state, {
|
|
1802
|
-
type: "tableConfig",
|
|
1803
|
-
...rest
|
|
1804
|
-
});
|
|
1805
|
-
} else {
|
|
1806
|
-
return state;
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
var getLabel = (label, columnFormatHeader) => {
|
|
1810
|
-
if (columnFormatHeader === "uppercase") {
|
|
1811
|
-
return label.toUpperCase();
|
|
1812
|
-
} else if (columnFormatHeader === "capitalize") {
|
|
1813
|
-
return label[0].toUpperCase() + label.slice(1).toLowerCase();
|
|
1814
|
-
}
|
|
1815
|
-
return label;
|
|
1816
|
-
};
|
|
1817
|
-
var toKeyedColumWithDefaults = (options) => (column, index) => {
|
|
1818
|
-
const serverDataType = getServerDataTypeForColumn(
|
|
1819
|
-
column,
|
|
1820
|
-
options.tableSchema
|
|
1821
|
-
);
|
|
1822
|
-
const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = options;
|
|
1823
|
-
const {
|
|
1824
|
-
align = getDefaultAlignment(serverDataType),
|
|
1825
|
-
key,
|
|
1826
|
-
name,
|
|
1827
|
-
label = name,
|
|
1828
|
-
width = columnDefaultWidth,
|
|
1829
|
-
...rest
|
|
1830
|
-
} = column;
|
|
1831
|
-
const keyedColumnWithDefaults = {
|
|
1832
|
-
...rest,
|
|
1833
|
-
align,
|
|
1834
|
-
CellRenderer: getCellRendererForColumn(column),
|
|
1835
|
-
label: getLabel(label, columnFormatHeader),
|
|
1836
|
-
key: key != null ? key : index + KEY_OFFSET,
|
|
1837
|
-
name,
|
|
1838
|
-
originalIdx: index,
|
|
1839
|
-
serverDataType,
|
|
1840
|
-
valueFormatter: getValueFormatter(column),
|
|
1841
|
-
width
|
|
1842
|
-
};
|
|
1843
|
-
if (isGroupColumn3(keyedColumnWithDefaults)) {
|
|
1844
|
-
keyedColumnWithDefaults.columns = keyedColumnWithDefaults.columns.map(
|
|
1845
|
-
(col) => toKeyedColumWithDefaults(options)(col, col.key)
|
|
1846
|
-
);
|
|
1847
|
-
}
|
|
1848
|
-
return keyedColumnWithDefaults;
|
|
1849
|
-
};
|
|
1850
|
-
function moveColumn(state, { column, moveBy, moveTo }) {
|
|
1851
|
-
const { columns } = state;
|
|
1852
|
-
if (typeof moveBy === "number") {
|
|
1853
|
-
const idx = columns.indexOf(column);
|
|
1854
|
-
const newColumns = columns.slice();
|
|
1855
|
-
const [movedColumns] = newColumns.splice(idx, 1);
|
|
1856
|
-
newColumns.splice(idx + moveBy, 0, movedColumns);
|
|
1857
|
-
return {
|
|
1858
|
-
...state,
|
|
1859
|
-
columns: newColumns
|
|
1860
|
-
};
|
|
1861
|
-
} else if (typeof moveTo === "number") {
|
|
1862
|
-
const index = columns.indexOf(column);
|
|
1863
|
-
return {
|
|
1864
|
-
...state,
|
|
1865
|
-
columns: moveItem(columns, index, moveTo)
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
return state;
|
|
1869
|
-
}
|
|
1870
|
-
function hideColumns(state, { columns }) {
|
|
1871
|
-
if (columns.some((col) => col.hidden !== true)) {
|
|
1872
|
-
return columns.reduce((s, c) => {
|
|
1873
|
-
if (c.hidden !== true) {
|
|
1874
|
-
return updateColumnProp(s, {
|
|
1875
|
-
type: "updateColumnProp",
|
|
1876
|
-
column: c,
|
|
1877
|
-
hidden: true
|
|
1878
|
-
});
|
|
1879
|
-
} else {
|
|
1880
|
-
return s;
|
|
1881
|
-
}
|
|
1882
|
-
}, state);
|
|
1883
|
-
} else {
|
|
1884
|
-
return state;
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
function showColumns(state, { columns }) {
|
|
1888
|
-
if (columns.some((col) => col.hidden)) {
|
|
1889
|
-
return columns.reduce((s, c) => {
|
|
1890
|
-
if (c.hidden) {
|
|
1891
|
-
return updateColumnProp(s, {
|
|
1892
|
-
type: "updateColumnProp",
|
|
1893
|
-
column: c,
|
|
1894
|
-
hidden: false
|
|
1895
|
-
});
|
|
1896
|
-
} else {
|
|
1897
|
-
return s;
|
|
1898
|
-
}
|
|
1899
|
-
}, state);
|
|
1900
|
-
} else {
|
|
1901
|
-
return state;
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
function resizeColumn(state, { column, phase, width }) {
|
|
1905
|
-
const type = "updateColumnProp";
|
|
1906
|
-
const resizing = phase !== "end";
|
|
1907
|
-
switch (phase) {
|
|
1908
|
-
case "begin":
|
|
1909
|
-
case "end":
|
|
1910
|
-
return updateColumnProp(state, { type, column, resizing });
|
|
1911
|
-
case "resize":
|
|
1912
|
-
return updateColumnProp(state, { type, column, width });
|
|
1913
|
-
default:
|
|
1914
|
-
throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
function setTableSchema(state, { tableSchema }) {
|
|
1918
|
-
const { columns } = state;
|
|
1919
|
-
if (columns.some(columnWithoutDataType)) {
|
|
1920
|
-
const cols = columns.map((column) => {
|
|
1921
|
-
var _a;
|
|
1922
|
-
const serverDataType = getServerDataTypeForColumn(column, tableSchema);
|
|
1923
|
-
return {
|
|
1924
|
-
...column,
|
|
1925
|
-
align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
|
|
1926
|
-
serverDataType
|
|
1927
|
-
};
|
|
1928
|
-
});
|
|
1929
|
-
return {
|
|
1930
|
-
...state,
|
|
1931
|
-
columns: cols,
|
|
1932
|
-
tableSchema
|
|
1933
|
-
};
|
|
1934
|
-
} else {
|
|
1935
|
-
return {
|
|
1936
|
-
...state,
|
|
1937
|
-
tableSchema
|
|
1938
|
-
};
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
function pinColumn2(state, action) {
|
|
1942
|
-
let { columns } = state;
|
|
1943
|
-
const { column, pin } = action;
|
|
1944
|
-
const targetColumn = columns.find((col) => col.name === column.name);
|
|
1945
|
-
if (targetColumn) {
|
|
1946
|
-
columns = replaceColumn(columns, { ...targetColumn, pin });
|
|
1947
|
-
columns = sortPinnedColumns(columns);
|
|
1948
|
-
return {
|
|
1949
|
-
...state,
|
|
1950
|
-
columns
|
|
1951
|
-
};
|
|
1952
|
-
} else {
|
|
1953
|
-
return state;
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
function updateColumnProp(state, action) {
|
|
1957
|
-
let { columns } = state;
|
|
1958
|
-
const { align, column, hidden, label, resizing, width } = action;
|
|
1959
|
-
const targetColumn = columns.find((col) => col.name === column.name);
|
|
1960
|
-
if (targetColumn) {
|
|
1961
|
-
if (align === "left" || align === "right") {
|
|
1962
|
-
columns = replaceColumn(columns, { ...targetColumn, align });
|
|
1963
|
-
}
|
|
1964
|
-
if (typeof label === "string") {
|
|
1965
|
-
columns = replaceColumn(columns, { ...targetColumn, label });
|
|
1966
|
-
}
|
|
1967
|
-
if (typeof resizing === "boolean") {
|
|
1968
|
-
columns = replaceColumn(columns, { ...targetColumn, resizing });
|
|
1969
|
-
}
|
|
1970
|
-
if (typeof hidden === "boolean") {
|
|
1971
|
-
columns = replaceColumn(columns, { ...targetColumn, hidden });
|
|
1972
|
-
}
|
|
1973
|
-
if (typeof width === "number") {
|
|
1974
|
-
columns = replaceColumn(columns, { ...targetColumn, width });
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
return {
|
|
1978
|
-
...state,
|
|
1979
|
-
columns
|
|
1980
|
-
};
|
|
1981
|
-
}
|
|
1982
|
-
function updateTableConfig(state, { columns, confirmed, filter, groupBy, sort }) {
|
|
1983
|
-
const hasColumns = columns && columns.length > 0;
|
|
1984
|
-
const hasGroupBy = groupBy !== void 0;
|
|
1985
|
-
const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
|
|
1986
|
-
const hasSort = sort && sort.sortDefs.length > 0;
|
|
1987
|
-
let result = state;
|
|
1988
|
-
if (hasColumns) {
|
|
1989
|
-
result = {
|
|
1990
|
-
...state,
|
|
1991
|
-
columns: columns.map((colName, index) => {
|
|
1992
|
-
const columnName = getColumnName(colName);
|
|
1993
|
-
const key = index + KEY_OFFSET;
|
|
1994
|
-
const col = findColumn(result.columns, columnName);
|
|
1995
|
-
if (col) {
|
|
1996
|
-
if (col.key === key) {
|
|
1997
|
-
return col;
|
|
1998
|
-
} else {
|
|
1999
|
-
return {
|
|
2000
|
-
...col,
|
|
2001
|
-
key
|
|
2002
|
-
};
|
|
2003
|
-
}
|
|
2004
|
-
} else {
|
|
2005
|
-
return toKeyedColumWithDefaults(state)(
|
|
2006
|
-
{
|
|
2007
|
-
name: colName
|
|
2008
|
-
},
|
|
2009
|
-
index
|
|
2010
|
-
);
|
|
2011
|
-
}
|
|
2012
|
-
throw Error(`useTableModel column ${colName} not found`);
|
|
2013
|
-
})
|
|
2014
|
-
};
|
|
2015
|
-
}
|
|
2016
|
-
if (hasGroupBy) {
|
|
2017
|
-
result = {
|
|
2018
|
-
...state,
|
|
2019
|
-
columns: applyGroupByToColumns(result.columns, groupBy, confirmed)
|
|
2020
|
-
};
|
|
2021
|
-
}
|
|
2022
|
-
if (hasSort) {
|
|
2023
|
-
result = {
|
|
2024
|
-
...state,
|
|
2025
|
-
columns: applySortToColumns(result.columns, sort)
|
|
2026
|
-
};
|
|
2027
|
-
}
|
|
2028
|
-
if (hasFilter) {
|
|
2029
|
-
result = {
|
|
2030
|
-
...state,
|
|
2031
|
-
columns: applyFilterToColumns(result.columns, filter)
|
|
2032
|
-
};
|
|
2033
|
-
} else if (result.columns.some(isFilteredColumn)) {
|
|
2034
|
-
result = {
|
|
2035
|
-
...state,
|
|
2036
|
-
columns: stripFilterFromColumns(result.columns)
|
|
2037
|
-
};
|
|
2038
|
-
}
|
|
2039
|
-
return result;
|
|
2040
|
-
}
|
|
2041
|
-
function replaceColumn(state, column) {
|
|
2042
|
-
return state.map((col) => col.name === column.name ? column : col);
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
// src/useTableScroll.ts
|
|
2046
|
-
import { useCallback as useCallback15, useRef as useRef12 } from "react";
|
|
2047
|
-
var getPctScroll = (container) => {
|
|
2048
|
-
const { scrollLeft, scrollTop } = container;
|
|
2049
|
-
const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
|
|
2050
|
-
const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
|
|
2051
|
-
const pctScrollTop = scrollTop / (scrollHeight - clientHeight);
|
|
2052
|
-
return [pctScrollLeft, pctScrollTop];
|
|
2053
|
-
};
|
|
2054
|
-
var getMaxScroll = (container) => {
|
|
2055
|
-
const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
|
|
2056
|
-
return [scrollWidth - clientWidth, scrollHeight - clientHeight];
|
|
2057
|
-
};
|
|
2058
|
-
var useCallbackRef = ({
|
|
2059
|
-
onAttach,
|
|
2060
|
-
onDetach
|
|
2061
|
-
}) => {
|
|
2062
|
-
const ref = useRef12(null);
|
|
2063
|
-
const callbackRef = useCallback15(
|
|
2064
|
-
(el) => {
|
|
2065
|
-
if (el) {
|
|
2066
|
-
ref.current = el;
|
|
2067
|
-
onAttach == null ? void 0 : onAttach(el);
|
|
2068
|
-
} else if (ref.current) {
|
|
2069
|
-
const { current: originalRef } = ref;
|
|
2070
|
-
ref.current = el;
|
|
2071
|
-
onDetach == null ? void 0 : onDetach(originalRef);
|
|
2072
|
-
}
|
|
2073
|
-
},
|
|
2074
|
-
[onAttach, onDetach]
|
|
2075
|
-
);
|
|
2076
|
-
return callbackRef;
|
|
2077
|
-
};
|
|
2078
|
-
var useTableScroll = ({
|
|
2079
|
-
onHorizontalScroll,
|
|
2080
|
-
onVerticalScroll,
|
|
2081
|
-
viewport
|
|
2082
|
-
}) => {
|
|
2083
|
-
const contentContainerScrolledRef = useRef12(false);
|
|
2084
|
-
const scrollPosRef = useRef12({ scrollTop: 0, scrollLeft: 0 });
|
|
2085
|
-
const scrollbarContainerRef = useRef12(null);
|
|
2086
|
-
const contentContainerRef = useRef12(null);
|
|
2087
|
-
const {
|
|
2088
|
-
maxScrollContainerScrollHorizontal: maxScrollLeft,
|
|
2089
|
-
maxScrollContainerScrollVertical: maxScrollTop
|
|
2090
|
-
} = viewport;
|
|
2091
|
-
const handleScrollbarContainerScroll = useCallback15(() => {
|
|
2092
|
-
const { current: contentContainer } = contentContainerRef;
|
|
2093
|
-
const { current: scrollbarContainer } = scrollbarContainerRef;
|
|
2094
|
-
const { current: contentContainerScrolled } = contentContainerScrolledRef;
|
|
2095
|
-
if (contentContainerScrolled) {
|
|
2096
|
-
contentContainerScrolledRef.current = false;
|
|
2097
|
-
} else if (contentContainer && scrollbarContainer) {
|
|
2098
|
-
const [pctScrollLeft, pctScrollTop] = getPctScroll(scrollbarContainer);
|
|
2099
|
-
const [maxScrollLeft2, maxScrollTop2] = getMaxScroll(contentContainer);
|
|
2100
|
-
const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft2);
|
|
2101
|
-
const rootScrollTop = Math.round(pctScrollTop * maxScrollTop2);
|
|
2102
|
-
contentContainer.scrollTo({
|
|
2103
|
-
left: rootScrollLeft,
|
|
2104
|
-
top: rootScrollTop,
|
|
2105
|
-
behavior: "auto"
|
|
2106
|
-
});
|
|
2107
|
-
}
|
|
2108
|
-
}, []);
|
|
2109
|
-
const handleContentContainerScroll = useCallback15(() => {
|
|
2110
|
-
const { current: contentContainer } = contentContainerRef;
|
|
2111
|
-
const { current: scrollbarContainer } = scrollbarContainerRef;
|
|
2112
|
-
const { current: scrollPos } = scrollPosRef;
|
|
2113
|
-
if (contentContainer && scrollbarContainer) {
|
|
2114
|
-
const { scrollLeft, scrollTop } = contentContainer;
|
|
2115
|
-
const [pctScrollLeft, pctScrollTop] = getPctScroll(contentContainer);
|
|
2116
|
-
contentContainerScrolledRef.current = true;
|
|
2117
|
-
scrollbarContainer.scrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
|
|
2118
|
-
scrollbarContainer.scrollTop = Math.round(pctScrollTop * maxScrollTop);
|
|
2119
|
-
if (scrollPos.scrollTop !== scrollTop) {
|
|
2120
|
-
scrollPos.scrollTop = scrollTop;
|
|
2121
|
-
onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop, pctScrollTop);
|
|
2122
|
-
}
|
|
2123
|
-
if (scrollPos.scrollLeft !== scrollLeft) {
|
|
2124
|
-
scrollPos.scrollLeft = scrollLeft;
|
|
2125
|
-
onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
|
|
2126
|
-
}
|
|
2127
|
-
}
|
|
2128
|
-
}, [maxScrollLeft, maxScrollTop, onHorizontalScroll, onVerticalScroll]);
|
|
2129
|
-
const handleAttachScrollbarContainer = useCallback15(
|
|
2130
|
-
(el) => {
|
|
2131
|
-
scrollbarContainerRef.current = el;
|
|
2132
|
-
el.addEventListener("scroll", handleScrollbarContainerScroll, {
|
|
2133
|
-
passive: true
|
|
2134
|
-
});
|
|
2135
|
-
},
|
|
2136
|
-
[handleScrollbarContainerScroll]
|
|
2137
|
-
);
|
|
2138
|
-
const handleDetachScrollbarContainer = useCallback15(
|
|
2139
|
-
(el) => {
|
|
2140
|
-
scrollbarContainerRef.current = null;
|
|
2141
|
-
el.removeEventListener("scroll", handleScrollbarContainerScroll);
|
|
2142
|
-
},
|
|
2143
|
-
[handleScrollbarContainerScroll]
|
|
2144
|
-
);
|
|
2145
|
-
const handleAttachContentContainer = useCallback15(
|
|
2146
|
-
(el) => {
|
|
2147
|
-
contentContainerRef.current = el;
|
|
2148
|
-
el.addEventListener("scroll", handleContentContainerScroll, {
|
|
2149
|
-
passive: true
|
|
2150
|
-
});
|
|
2151
|
-
},
|
|
2152
|
-
[handleContentContainerScroll]
|
|
2153
|
-
);
|
|
2154
|
-
const handleDetachContentContainer = useCallback15(
|
|
2155
|
-
(el) => {
|
|
2156
|
-
contentContainerRef.current = null;
|
|
2157
|
-
el.removeEventListener("scroll", handleContentContainerScroll);
|
|
2158
|
-
},
|
|
2159
|
-
[handleContentContainerScroll]
|
|
2160
|
-
);
|
|
2161
|
-
const contentContainerCallbackRef = useCallbackRef({
|
|
2162
|
-
onAttach: handleAttachContentContainer,
|
|
2163
|
-
onDetach: handleDetachContentContainer
|
|
2164
|
-
});
|
|
2165
|
-
const scrollbarContainerCallbackRef = useCallbackRef({
|
|
2166
|
-
onAttach: handleAttachScrollbarContainer,
|
|
2167
|
-
onDetach: handleDetachScrollbarContainer
|
|
2168
|
-
});
|
|
2169
|
-
const requestScroll = useCallback15(
|
|
2170
|
-
(scrollRequest) => {
|
|
2171
|
-
const { current: scrollbarContainer } = contentContainerRef;
|
|
2172
|
-
if (scrollbarContainer) {
|
|
2173
|
-
contentContainerScrolledRef.current = false;
|
|
2174
|
-
if (scrollRequest.type === "scroll-page") {
|
|
2175
|
-
const { clientHeight, scrollLeft, scrollTop } = scrollbarContainer;
|
|
2176
|
-
const { direction } = scrollRequest;
|
|
2177
|
-
const scrollBy = direction === "down" ? clientHeight : -clientHeight;
|
|
2178
|
-
const newScrollTop = Math.min(
|
|
2179
|
-
Math.max(0, scrollTop + scrollBy),
|
|
2180
|
-
maxScrollTop
|
|
2181
|
-
);
|
|
2182
|
-
scrollbarContainer.scrollTo({
|
|
2183
|
-
top: newScrollTop,
|
|
2184
|
-
left: scrollLeft,
|
|
2185
|
-
behavior: "auto"
|
|
2186
|
-
});
|
|
2187
|
-
} else if (scrollRequest.type === "scroll-end") {
|
|
2188
|
-
const { direction } = scrollRequest;
|
|
2189
|
-
const scrollTo = direction === "end" ? maxScrollTop : 0;
|
|
2190
|
-
scrollbarContainer.scrollTo({
|
|
2191
|
-
top: scrollTo,
|
|
2192
|
-
left: scrollbarContainer.scrollLeft,
|
|
2193
|
-
behavior: "auto"
|
|
2194
|
-
});
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
},
|
|
2198
|
-
[maxScrollTop]
|
|
2199
|
-
);
|
|
2200
|
-
return {
|
|
2201
|
-
/** Ref to be assigned to ScrollbarContainer */
|
|
2202
|
-
scrollbarContainerRef: scrollbarContainerCallbackRef,
|
|
2203
|
-
/** Ref to be assigned to ContentContainer */
|
|
2204
|
-
contentContainerRef: contentContainerCallbackRef,
|
|
2205
|
-
/** Scroll the table */
|
|
2206
|
-
requestScroll
|
|
2207
|
-
};
|
|
2208
|
-
};
|
|
2209
|
-
|
|
2210
|
-
// src/useTableViewport.ts
|
|
2211
|
-
import { useCallback as useCallback16, useMemo as useMemo5, useRef as useRef13 } from "react";
|
|
2212
|
-
import {
|
|
2213
|
-
actualRowPositioning,
|
|
2214
|
-
virtualRowPositioning
|
|
2215
|
-
} from "@vuu-ui/vuu-utils";
|
|
2216
|
-
var MAX_RAW_ROWS = 15e5;
|
|
2217
|
-
var UNMEASURED_VIEWPORT = {
|
|
2218
|
-
contentHeight: 0,
|
|
2219
|
-
contentWidth: 0,
|
|
2220
|
-
getRowAtPosition: () => -1,
|
|
2221
|
-
getRowOffset: () => -1,
|
|
2222
|
-
horizontalScrollbarHeight: 0,
|
|
2223
|
-
maxScrollContainerScrollHorizontal: 0,
|
|
2224
|
-
maxScrollContainerScrollVertical: 0,
|
|
2225
|
-
pinnedWidthLeft: 0,
|
|
2226
|
-
pinnedWidthRight: 0,
|
|
2227
|
-
rowCount: 0,
|
|
2228
|
-
setPctScrollTop: () => void 0,
|
|
2229
|
-
totalHeaderHeight: 0,
|
|
2230
|
-
verticalScrollbarWidth: 0,
|
|
2231
|
-
viewportBodyHeight: 0
|
|
2232
|
-
};
|
|
2233
|
-
var measurePinnedColumns = (columns) => {
|
|
2234
|
-
let pinnedWidthLeft = 0;
|
|
2235
|
-
let pinnedWidthRight = 0;
|
|
2236
|
-
let unpinnedWidth = 0;
|
|
2237
|
-
for (const column of columns) {
|
|
2238
|
-
const { hidden, pin, width } = column;
|
|
2239
|
-
const visibleWidth = hidden ? 0 : width;
|
|
2240
|
-
if (pin === "left") {
|
|
2241
|
-
pinnedWidthLeft += visibleWidth;
|
|
2242
|
-
} else if (pin === "right") {
|
|
2243
|
-
pinnedWidthRight += visibleWidth;
|
|
2244
|
-
} else {
|
|
2245
|
-
unpinnedWidth += visibleWidth;
|
|
2246
|
-
}
|
|
2247
|
-
}
|
|
2248
|
-
return { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth };
|
|
2249
|
-
};
|
|
2250
|
-
var useTableViewport = ({
|
|
2251
|
-
columns,
|
|
2252
|
-
headerHeight,
|
|
2253
|
-
headings,
|
|
2254
|
-
rowCount,
|
|
2255
|
-
rowHeight,
|
|
2256
|
-
size
|
|
2257
|
-
}) => {
|
|
2258
|
-
const pctScrollTopRef = useRef13(0);
|
|
2259
|
-
const appliedRowCount = Math.min(rowCount, MAX_RAW_ROWS);
|
|
2260
|
-
const appliedContentHeight = appliedRowCount * rowHeight;
|
|
2261
|
-
const virtualContentHeight = rowCount * rowHeight;
|
|
2262
|
-
const virtualisedExtent = virtualContentHeight - appliedContentHeight;
|
|
2263
|
-
const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo5(
|
|
2264
|
-
() => measurePinnedColumns(columns),
|
|
2265
|
-
[columns]
|
|
2266
|
-
);
|
|
2267
|
-
const [actualRowOffset, actualRowAtPosition] = useMemo5(
|
|
2268
|
-
() => actualRowPositioning(rowHeight),
|
|
2269
|
-
[rowHeight]
|
|
2270
|
-
);
|
|
2271
|
-
const [getRowOffset, getRowAtPosition] = useMemo5(() => {
|
|
2272
|
-
if (virtualisedExtent) {
|
|
2273
|
-
return virtualRowPositioning(
|
|
2274
|
-
rowHeight,
|
|
2275
|
-
virtualisedExtent,
|
|
2276
|
-
pctScrollTopRef
|
|
2277
|
-
);
|
|
2278
|
-
} else {
|
|
2279
|
-
return [actualRowOffset, actualRowAtPosition];
|
|
2280
|
-
}
|
|
2281
|
-
}, [actualRowAtPosition, actualRowOffset, virtualisedExtent, rowHeight]);
|
|
2282
|
-
const setPctScrollTop = useCallback16((scrollPct) => {
|
|
2283
|
-
pctScrollTopRef.current = scrollPct;
|
|
2284
|
-
}, []);
|
|
2285
|
-
return useMemo5(() => {
|
|
2286
|
-
var _a;
|
|
2287
|
-
if (size) {
|
|
2288
|
-
const headingsDepth = headings.length;
|
|
2289
|
-
const scrollbarSize = 15;
|
|
2290
|
-
const contentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
|
|
2291
|
-
const horizontalScrollbarHeight = contentWidth > size.width ? scrollbarSize : 0;
|
|
2292
|
-
const totalHeaderHeight = headerHeight * (1 + headingsDepth);
|
|
2293
|
-
const maxScrollContainerScrollVertical = appliedContentHeight - (((_a = size == null ? void 0 : size.height) != null ? _a : 0) - horizontalScrollbarHeight) + totalHeaderHeight;
|
|
2294
|
-
const maxScrollContainerScrollHorizontal = contentWidth - size.width + pinnedWidthLeft;
|
|
2295
|
-
const visibleRows = (size.height - headerHeight) / rowHeight;
|
|
2296
|
-
const count = Number.isInteger(visibleRows) ? visibleRows + 1 : Math.ceil(visibleRows);
|
|
2297
|
-
const viewportBodyHeight = size.height - totalHeaderHeight;
|
|
2298
|
-
const verticalScrollbarWidth = appliedContentHeight > viewportBodyHeight ? scrollbarSize : 0;
|
|
2299
|
-
return {
|
|
2300
|
-
contentHeight: appliedContentHeight,
|
|
2301
|
-
getRowAtPosition,
|
|
2302
|
-
getRowOffset,
|
|
2303
|
-
horizontalScrollbarHeight,
|
|
2304
|
-
maxScrollContainerScrollHorizontal,
|
|
2305
|
-
maxScrollContainerScrollVertical,
|
|
2306
|
-
pinnedWidthLeft,
|
|
2307
|
-
pinnedWidthRight,
|
|
2308
|
-
rowCount: count,
|
|
2309
|
-
contentWidth,
|
|
2310
|
-
setPctScrollTop,
|
|
2311
|
-
totalHeaderHeight,
|
|
2312
|
-
verticalScrollbarWidth,
|
|
2313
|
-
viewportBodyHeight
|
|
2314
|
-
};
|
|
2315
|
-
} else {
|
|
2316
|
-
return UNMEASURED_VIEWPORT;
|
|
2317
|
-
}
|
|
2318
|
-
}, [
|
|
2319
|
-
size,
|
|
2320
|
-
headings.length,
|
|
2321
|
-
pinnedWidthLeft,
|
|
2322
|
-
unpinnedWidth,
|
|
2323
|
-
pinnedWidthRight,
|
|
2324
|
-
appliedContentHeight,
|
|
2325
|
-
headerHeight,
|
|
2326
|
-
rowHeight,
|
|
2327
|
-
getRowAtPosition,
|
|
2328
|
-
getRowOffset,
|
|
2329
|
-
setPctScrollTop
|
|
2330
|
-
]);
|
|
2331
|
-
};
|
|
2332
|
-
|
|
2333
|
-
// src/useVirtualViewport.ts
|
|
2334
|
-
import {
|
|
2335
|
-
getColumnsInViewport,
|
|
2336
|
-
itemsChanged
|
|
2337
|
-
} from "@vuu-ui/vuu-utils";
|
|
2338
|
-
import { useCallback as useCallback17, useEffect as useEffect4, useMemo as useMemo6, useRef as useRef14, useState as useState4 } from "react";
|
|
2339
|
-
var useVirtualViewport = ({
|
|
2340
|
-
columns,
|
|
2341
|
-
getRowAtPosition,
|
|
2342
|
-
setRange,
|
|
2343
|
-
viewportMeasurements
|
|
2344
|
-
}) => {
|
|
2345
|
-
const firstRowRef = useRef14(-1);
|
|
2346
|
-
const {
|
|
2347
|
-
rowCount: viewportRowCount,
|
|
2348
|
-
contentWidth,
|
|
2349
|
-
maxScrollContainerScrollHorizontal
|
|
2350
|
-
} = viewportMeasurements;
|
|
2351
|
-
const availableWidth = contentWidth - maxScrollContainerScrollHorizontal;
|
|
2352
|
-
const scrollLeftRef = useRef14(0);
|
|
2353
|
-
const [visibleColumns, preSpan] = useMemo6(
|
|
2354
|
-
() => getColumnsInViewport(
|
|
2355
|
-
columns,
|
|
2356
|
-
scrollLeftRef.current,
|
|
2357
|
-
scrollLeftRef.current + availableWidth
|
|
2358
|
-
),
|
|
2359
|
-
[availableWidth, columns]
|
|
2360
|
-
);
|
|
2361
|
-
const preSpanRef = useRef14(preSpan);
|
|
2362
|
-
useEffect4(() => {
|
|
2363
|
-
setColumnsWithinViewport(visibleColumns);
|
|
2364
|
-
}, [visibleColumns]);
|
|
2365
|
-
const [columnsWithinViewport, setColumnsWithinViewport] = useState4(visibleColumns);
|
|
2366
|
-
const handleHorizontalScroll = useCallback17(
|
|
2367
|
-
(scrollLeft) => {
|
|
2368
|
-
scrollLeftRef.current = scrollLeft;
|
|
2369
|
-
const [visibleColumns2, pre] = getColumnsInViewport(
|
|
2370
|
-
columns,
|
|
2371
|
-
scrollLeft,
|
|
2372
|
-
scrollLeft + availableWidth
|
|
2373
|
-
);
|
|
2374
|
-
if (itemsChanged(columnsWithinViewport, visibleColumns2)) {
|
|
2375
|
-
preSpanRef.current = pre;
|
|
2376
|
-
setColumnsWithinViewport(visibleColumns2);
|
|
2377
|
-
}
|
|
2378
|
-
},
|
|
2379
|
-
[availableWidth, columns, columnsWithinViewport]
|
|
2380
|
-
);
|
|
2381
|
-
const handleVerticalScroll = useCallback17(
|
|
2382
|
-
(scrollTop) => {
|
|
2383
|
-
const firstRow = getRowAtPosition(scrollTop);
|
|
2384
|
-
if (firstRow !== firstRowRef.current) {
|
|
2385
|
-
firstRowRef.current = firstRow;
|
|
2386
|
-
setRange({ from: firstRow, to: firstRow + viewportRowCount });
|
|
2387
|
-
}
|
|
2388
|
-
},
|
|
2389
|
-
[getRowAtPosition, setRange, viewportRowCount]
|
|
2390
|
-
);
|
|
2391
|
-
return {
|
|
2392
|
-
columnsWithinViewport,
|
|
2393
|
-
onHorizontalScroll: handleHorizontalScroll,
|
|
2394
|
-
onVerticalScroll: handleVerticalScroll,
|
|
2395
|
-
/** number of leading columns not rendered because of virtualization */
|
|
2396
|
-
virtualColSpan: preSpanRef.current
|
|
2397
|
-
};
|
|
2398
|
-
};
|
|
2399
|
-
|
|
2400
|
-
// src/useTable.ts
|
|
2401
|
-
var NO_ROWS = [];
|
|
2402
|
-
var { KEY: KEY2, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = metadataKeys8;
|
|
2403
|
-
var useTable = ({
|
|
2404
|
-
config,
|
|
2405
|
-
dataSource,
|
|
2406
|
-
headerHeight,
|
|
2407
|
-
onConfigChange,
|
|
2408
|
-
onFeatureEnabled,
|
|
2409
|
-
onFeatureInvocation,
|
|
2410
|
-
onSelectionChange,
|
|
2411
|
-
renderBufferSize = 0,
|
|
2412
|
-
rowHeight,
|
|
2413
|
-
selectionModel,
|
|
2414
|
-
...measuredProps
|
|
2415
|
-
}) => {
|
|
2416
|
-
var _a, _b;
|
|
2417
|
-
const [rowCount, setRowCount] = useState5(dataSource.size);
|
|
2418
|
-
const expectConfigChangeRef = useRef15(false);
|
|
2419
|
-
const dataSourceRef = useRef15();
|
|
2420
|
-
dataSourceRef.current = dataSource;
|
|
2421
|
-
if (dataSource === void 0) {
|
|
2422
|
-
throw Error("no data source provided to Vuu Table");
|
|
2423
|
-
}
|
|
2424
|
-
const containerMeasurements = useMeasuredContainer(measuredProps);
|
|
2425
|
-
const onDataRowcountChange = useCallback18((size) => {
|
|
2426
|
-
setRowCount(size);
|
|
2427
|
-
}, []);
|
|
2428
|
-
const { columns, dispatchColumnAction, headings } = useTableModel(
|
|
2429
|
-
config,
|
|
2430
|
-
dataSource.config
|
|
2431
|
-
);
|
|
2432
|
-
const {
|
|
2433
|
-
getRowAtPosition,
|
|
2434
|
-
getRowOffset,
|
|
2435
|
-
setPctScrollTop,
|
|
2436
|
-
...viewportMeasurements
|
|
2437
|
-
} = useTableViewport({
|
|
2438
|
-
columns,
|
|
2439
|
-
headerHeight,
|
|
2440
|
-
headings,
|
|
2441
|
-
rowCount,
|
|
2442
|
-
rowHeight,
|
|
2443
|
-
size: containerMeasurements.innerSize
|
|
2444
|
-
});
|
|
2445
|
-
const onSubscribed = useCallback18(
|
|
2446
|
-
({ tableSchema }) => {
|
|
2447
|
-
if (tableSchema) {
|
|
2448
|
-
expectConfigChangeRef.current = true;
|
|
2449
|
-
dispatchColumnAction({
|
|
2450
|
-
type: "setTableSchema",
|
|
2451
|
-
tableSchema
|
|
2452
|
-
});
|
|
2453
|
-
} else {
|
|
2454
|
-
console.log("usbscription message with no schema");
|
|
2455
|
-
}
|
|
2456
|
-
},
|
|
2457
|
-
[dispatchColumnAction]
|
|
2458
|
-
);
|
|
2459
|
-
const handleSelectionChange = useCallback18(
|
|
2460
|
-
(selected) => {
|
|
2461
|
-
dataSource.select(selected);
|
|
2462
|
-
onSelectionChange == null ? void 0 : onSelectionChange(selected);
|
|
2463
|
-
},
|
|
2464
|
-
[dataSource, onSelectionChange]
|
|
2465
|
-
);
|
|
2466
|
-
const handleRowClick = useSelection({
|
|
2467
|
-
onSelectionChange: handleSelectionChange,
|
|
2468
|
-
selectionModel
|
|
2469
|
-
});
|
|
2470
|
-
const { data, getSelectedRows, range, setRange } = useDataSource({
|
|
2471
|
-
dataSource,
|
|
2472
|
-
onFeatureEnabled,
|
|
2473
|
-
onFeatureInvocation,
|
|
2474
|
-
onSubscribed,
|
|
2475
|
-
onSizeChange: onDataRowcountChange,
|
|
2476
|
-
renderBufferSize,
|
|
2477
|
-
viewportRowCount: viewportMeasurements.rowCount
|
|
2478
|
-
});
|
|
2479
|
-
const dataRef = useRef15();
|
|
2480
|
-
dataRef.current = data;
|
|
2481
|
-
const onPersistentColumnOperation = useCallback18(
|
|
2482
|
-
(action) => {
|
|
2483
|
-
expectConfigChangeRef.current = true;
|
|
2484
|
-
dispatchColumnAction(action);
|
|
2485
|
-
},
|
|
2486
|
-
[dispatchColumnAction]
|
|
2487
|
-
);
|
|
2488
|
-
const handleContextMenuAction = useTableContextMenu({
|
|
2489
|
-
dataSource,
|
|
2490
|
-
onPersistentColumnOperation
|
|
2491
|
-
});
|
|
2492
|
-
const handleSort = useCallback18(
|
|
2493
|
-
(column, extendSort = false, sortType) => {
|
|
2494
|
-
if (dataSource) {
|
|
2495
|
-
dataSource.sort = applySort(
|
|
2496
|
-
dataSource.sort,
|
|
2497
|
-
column,
|
|
2498
|
-
extendSort,
|
|
2499
|
-
sortType
|
|
2500
|
-
);
|
|
2501
|
-
}
|
|
2502
|
-
},
|
|
2503
|
-
[dataSource]
|
|
2504
|
-
);
|
|
2505
|
-
const handleColumnResize = useCallback18(
|
|
2506
|
-
(phase, columnName, width) => {
|
|
2507
|
-
const column = columns.find((column2) => column2.name === columnName);
|
|
2508
|
-
if (column) {
|
|
2509
|
-
if (phase === "end") {
|
|
2510
|
-
expectConfigChangeRef.current = true;
|
|
2511
|
-
}
|
|
2512
|
-
dispatchColumnAction({
|
|
2513
|
-
type: "resizeColumn",
|
|
2514
|
-
phase,
|
|
2515
|
-
column,
|
|
2516
|
-
width
|
|
2517
|
-
});
|
|
2518
|
-
} else {
|
|
2519
|
-
throw Error(
|
|
2520
|
-
`useDataTable.handleColumnResize, column ${columnName} not found`
|
|
2521
|
-
);
|
|
2522
|
-
}
|
|
2523
|
-
},
|
|
2524
|
-
[columns, dispatchColumnAction]
|
|
2525
|
-
);
|
|
2526
|
-
const handleToggleGroup = useCallback18(
|
|
2527
|
-
(row, column) => {
|
|
2528
|
-
const isJson = isJsonGroup2(column, row);
|
|
2529
|
-
const key = row[KEY2];
|
|
2530
|
-
if (row[IS_EXPANDED2]) {
|
|
2531
|
-
dataSource.closeTreeNode(key, true);
|
|
2532
|
-
if (isJson) {
|
|
2533
|
-
const idx = columns.indexOf(column);
|
|
2534
|
-
const rows = dataSource.getRowsAtDepth(idx + 1);
|
|
2535
|
-
if (!rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
|
|
2536
|
-
dispatchColumnAction({
|
|
2537
|
-
type: "hideColumns",
|
|
2538
|
-
columns: columns.slice(idx + 2)
|
|
2539
|
-
});
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
} else {
|
|
2543
|
-
dataSource.openTreeNode(key);
|
|
2544
|
-
if (isJson) {
|
|
2545
|
-
const childRows = dataSource.getChildRows(key);
|
|
2546
|
-
const idx = columns.indexOf(column) + 1;
|
|
2547
|
-
const columnsToShow = [columns[idx]];
|
|
2548
|
-
if (childRows.some((row2) => row2[IS_LEAF2])) {
|
|
2549
|
-
columnsToShow.push(columns[idx + 1]);
|
|
2550
|
-
}
|
|
2551
|
-
if (columnsToShow.some((col) => col.hidden)) {
|
|
2552
|
-
dispatchColumnAction({
|
|
2553
|
-
type: "showColumns",
|
|
2554
|
-
columns: columnsToShow
|
|
2555
|
-
});
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
}
|
|
2559
|
-
},
|
|
2560
|
-
[columns, dataSource, dispatchColumnAction]
|
|
2561
|
-
);
|
|
2562
|
-
const {
|
|
2563
|
-
onVerticalScroll,
|
|
2564
|
-
onHorizontalScroll,
|
|
2565
|
-
columnsWithinViewport,
|
|
2566
|
-
virtualColSpan
|
|
2567
|
-
} = useVirtualViewport({
|
|
2568
|
-
columns,
|
|
2569
|
-
getRowAtPosition,
|
|
2570
|
-
setRange,
|
|
2571
|
-
viewportMeasurements
|
|
2572
|
-
});
|
|
2573
|
-
const handleVerticalScroll = useCallback18(
|
|
2574
|
-
(scrollTop, pctScrollTop) => {
|
|
2575
|
-
setPctScrollTop(pctScrollTop);
|
|
2576
|
-
onVerticalScroll(scrollTop);
|
|
2577
|
-
},
|
|
2578
|
-
[onVerticalScroll, setPctScrollTop]
|
|
2579
|
-
);
|
|
2580
|
-
const { requestScroll, ...scrollProps } = useTableScroll({
|
|
2581
|
-
onHorizontalScroll,
|
|
2582
|
-
onVerticalScroll: handleVerticalScroll,
|
|
2583
|
-
viewport: viewportMeasurements,
|
|
2584
|
-
viewportHeight: ((_b = (_a = containerMeasurements.innerSize) == null ? void 0 : _a.height) != null ? _b : 0) - headerHeight
|
|
2585
|
-
});
|
|
2586
|
-
const containerProps = useKeyboardNavigation({
|
|
2587
|
-
columnCount: columns.length,
|
|
2588
|
-
containerRef: containerMeasurements.containerRef,
|
|
2589
|
-
data,
|
|
2590
|
-
requestScroll,
|
|
2591
|
-
rowCount: dataSource == null ? void 0 : dataSource.size,
|
|
2592
|
-
viewportRange: range
|
|
2593
|
-
});
|
|
2594
|
-
const handleRemoveColumnFromGroupBy = useCallback18(
|
|
2595
|
-
(column) => {
|
|
2596
|
-
if (column) {
|
|
2597
|
-
if (dataSource && dataSource.groupBy.includes(column.name)) {
|
|
2598
|
-
dataSource.groupBy = dataSource.groupBy.filter(
|
|
2599
|
-
(columnName) => columnName !== column.name
|
|
2600
|
-
);
|
|
2601
|
-
}
|
|
2602
|
-
} else {
|
|
2603
|
-
dataSource.groupBy = [];
|
|
2604
|
-
}
|
|
2605
|
-
},
|
|
2606
|
-
[dataSource]
|
|
2607
|
-
);
|
|
2608
|
-
const handleDropColumn = useCallback18(
|
|
2609
|
-
(fromIndex, toIndex) => {
|
|
2610
|
-
const column = dataSource.columns[fromIndex];
|
|
2611
|
-
const columns2 = moveItem2(dataSource.columns, column, toIndex);
|
|
2612
|
-
if (columns2 !== dataSource.columns) {
|
|
2613
|
-
dataSource.columns = columns2;
|
|
2614
|
-
dispatchColumnAction({ type: "tableConfig", columns: columns2 });
|
|
2615
|
-
}
|
|
2616
|
-
},
|
|
2617
|
-
[dataSource, dispatchColumnAction]
|
|
2618
|
-
);
|
|
2619
|
-
const draggableHook = useDraggableColumn({
|
|
2620
|
-
onDrop: handleDropColumn
|
|
2621
|
-
});
|
|
2622
|
-
useEffect5(() => {
|
|
2623
|
-
if (dataSourceRef.current) {
|
|
2624
|
-
expectConfigChangeRef.current = true;
|
|
2625
|
-
dispatchColumnAction({
|
|
2626
|
-
type: "init",
|
|
2627
|
-
tableConfig: config,
|
|
2628
|
-
dataSourceConfig: dataSourceRef.current.config
|
|
2629
|
-
});
|
|
2630
|
-
}
|
|
2631
|
-
}, [config, dispatchColumnAction]);
|
|
2632
|
-
useEffect5(() => {
|
|
2633
|
-
dataSource.on("config", (config2, confirmed) => {
|
|
2634
|
-
expectConfigChangeRef.current = true;
|
|
2635
|
-
dispatchColumnAction({
|
|
2636
|
-
type: "tableConfig",
|
|
2637
|
-
...config2,
|
|
2638
|
-
confirmed
|
|
2639
|
-
});
|
|
2640
|
-
});
|
|
2641
|
-
}, [dataSource, dispatchColumnAction]);
|
|
2642
|
-
useMemo7(() => {
|
|
2643
|
-
if (expectConfigChangeRef.current) {
|
|
2644
|
-
onConfigChange == null ? void 0 : onConfigChange({
|
|
2645
|
-
...config,
|
|
2646
|
-
columns
|
|
2647
|
-
});
|
|
2648
|
-
expectConfigChangeRef.current = false;
|
|
2649
|
-
}
|
|
2650
|
-
}, [columns, config, onConfigChange]);
|
|
2651
|
-
const showContextMenu = usePopupContextMenu();
|
|
2652
|
-
const onContextMenu = useCallback18(
|
|
2653
|
-
(evt) => {
|
|
2654
|
-
var _a2;
|
|
2655
|
-
const { current: currentData } = dataRef;
|
|
2656
|
-
const { current: currentDataSource } = dataSourceRef;
|
|
2657
|
-
const target = evt.target;
|
|
2658
|
-
const cellEl = target == null ? void 0 : target.closest("div[role='cell']");
|
|
2659
|
-
const rowEl = target == null ? void 0 : target.closest(".vuuTableRow");
|
|
2660
|
-
if (cellEl && rowEl && currentData && currentDataSource) {
|
|
2661
|
-
const { columns: columns2, selectedRowsCount } = currentDataSource;
|
|
2662
|
-
const columnMap = buildColumnMap2(columns2);
|
|
2663
|
-
const rowIndex = parseInt((_a2 = rowEl.ariaRowIndex) != null ? _a2 : "-1");
|
|
2664
|
-
const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
|
|
2665
|
-
const row = currentData.find(([idx]) => idx === rowIndex);
|
|
2666
|
-
const columnName = columns2[cellIndex];
|
|
2667
|
-
showContextMenu(evt, "grid", {
|
|
2668
|
-
columnMap,
|
|
2669
|
-
columnName,
|
|
2670
|
-
row,
|
|
2671
|
-
selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
|
|
2672
|
-
viewport: dataSource == null ? void 0 : dataSource.viewport
|
|
2673
|
-
});
|
|
2674
|
-
}
|
|
2675
|
-
},
|
|
2676
|
-
[dataSource == null ? void 0 : dataSource.viewport, getSelectedRows, showContextMenu]
|
|
2677
|
-
);
|
|
2678
|
-
return {
|
|
2679
|
-
columns,
|
|
2680
|
-
columnsWithinViewport,
|
|
2681
|
-
containerMeasurements,
|
|
2682
|
-
containerProps,
|
|
2683
|
-
data,
|
|
2684
|
-
dispatchColumnAction,
|
|
2685
|
-
getRowOffset,
|
|
2686
|
-
handleContextMenuAction,
|
|
2687
|
-
headings,
|
|
2688
|
-
onColumnResize: handleColumnResize,
|
|
2689
|
-
onContextMenu,
|
|
2690
|
-
onRemoveColumnFromGroupBy: handleRemoveColumnFromGroupBy,
|
|
2691
|
-
onRowClick: handleRowClick,
|
|
2692
|
-
onSort: handleSort,
|
|
2693
|
-
onToggleGroup: handleToggleGroup,
|
|
2694
|
-
virtualColSpan,
|
|
2695
|
-
scrollProps,
|
|
2696
|
-
rowCount,
|
|
2697
|
-
viewportMeasurements,
|
|
2698
|
-
...draggableHook
|
|
2699
|
-
};
|
|
2700
|
-
};
|
|
2701
|
-
|
|
2702
|
-
// src/Table.tsx
|
|
2703
|
-
import cx7 from "classnames";
|
|
2704
|
-
import { isDataLoading } from "@vuu-ui/vuu-utils";
|
|
2705
|
-
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2706
|
-
var classBase6 = "vuuTable";
|
|
2707
|
-
var Table = ({
|
|
2708
|
-
allowConfigEditing: showSettings = false,
|
|
2709
|
-
className: classNameProp,
|
|
2710
|
-
config,
|
|
2711
|
-
dataSource,
|
|
2712
|
-
headerHeight = 25,
|
|
2713
|
-
height,
|
|
2714
|
-
id: idProp,
|
|
2715
|
-
onConfigChange,
|
|
2716
|
-
onFeatureEnabled,
|
|
2717
|
-
onFeatureInvocation,
|
|
2718
|
-
onSelectionChange,
|
|
2719
|
-
onShowConfigEditor: onShowSettings,
|
|
2720
|
-
renderBufferSize = 0,
|
|
2721
|
-
rowHeight = 20,
|
|
2722
|
-
selectionModel = "extended",
|
|
2723
|
-
style: styleProp,
|
|
2724
|
-
width,
|
|
2725
|
-
zebraStripes = false,
|
|
2726
|
-
...htmlAttributes
|
|
2727
|
-
}) => {
|
|
2728
|
-
const id = useIdMemo(idProp);
|
|
2729
|
-
const {
|
|
2730
|
-
containerMeasurements: { containerRef, innerSize, outerSize },
|
|
2731
|
-
containerProps,
|
|
2732
|
-
dispatchColumnAction,
|
|
2733
|
-
draggable,
|
|
2734
|
-
draggedItemIndex,
|
|
2735
|
-
handleContextMenuAction,
|
|
2736
|
-
scrollProps,
|
|
2737
|
-
viewportMeasurements,
|
|
2738
|
-
...tableProps
|
|
2739
|
-
} = useTable({
|
|
2740
|
-
config,
|
|
2741
|
-
dataSource,
|
|
2742
|
-
renderBufferSize,
|
|
2743
|
-
headerHeight,
|
|
2744
|
-
height,
|
|
2745
|
-
onConfigChange,
|
|
2746
|
-
onFeatureEnabled,
|
|
2747
|
-
onFeatureInvocation,
|
|
2748
|
-
onSelectionChange,
|
|
2749
|
-
rowHeight,
|
|
2750
|
-
selectionModel,
|
|
2751
|
-
width
|
|
2752
|
-
});
|
|
2753
|
-
const style = {
|
|
2754
|
-
...outerSize,
|
|
2755
|
-
"--content-height": `${viewportMeasurements.contentHeight}px`,
|
|
2756
|
-
"--horizontal-scrollbar-height": `${viewportMeasurements.horizontalScrollbarHeight}px`,
|
|
2757
|
-
"--content-width": `${viewportMeasurements.contentWidth}px`,
|
|
2758
|
-
"--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
|
|
2759
|
-
"--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
|
|
2760
|
-
"--header-height": `${headerHeight}px`,
|
|
2761
|
-
"--row-height": `${rowHeight}px`,
|
|
2762
|
-
"--table-height": `${innerSize == null ? void 0 : innerSize.height}px`,
|
|
2763
|
-
"--table-width": `${innerSize == null ? void 0 : innerSize.width}px`,
|
|
2764
|
-
"--total-header-height": `${viewportMeasurements.totalHeaderHeight}px`,
|
|
2765
|
-
"--vertical-scrollbar-width": `${viewportMeasurements.verticalScrollbarWidth}px`,
|
|
2766
|
-
"--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
|
|
2767
|
-
};
|
|
2768
|
-
const className = cx7(classBase6, classNameProp, {
|
|
2769
|
-
[`${classBase6}-zebra`]: zebraStripes,
|
|
2770
|
-
[`${classBase6}-loading`]: isDataLoading(tableProps.columns)
|
|
2771
|
-
});
|
|
2772
|
-
return /* @__PURE__ */ jsx10(
|
|
2773
|
-
ContextMenuProvider,
|
|
2774
|
-
{
|
|
2775
|
-
menuActionHandler: handleContextMenuAction,
|
|
2776
|
-
menuBuilder: buildContextMenuDescriptors(dataSource),
|
|
2777
|
-
children: /* @__PURE__ */ jsxs7(
|
|
2778
|
-
"div",
|
|
2779
|
-
{
|
|
2780
|
-
...htmlAttributes,
|
|
2781
|
-
...containerProps,
|
|
2782
|
-
className,
|
|
2783
|
-
id,
|
|
2784
|
-
ref: containerRef,
|
|
2785
|
-
style,
|
|
2786
|
-
tabIndex: -1,
|
|
2787
|
-
children: [
|
|
2788
|
-
innerSize ? /* @__PURE__ */ jsx10(
|
|
2789
|
-
"div",
|
|
2790
|
-
{
|
|
2791
|
-
className: `${classBase6}-scrollbarContainer`,
|
|
2792
|
-
ref: scrollProps.scrollbarContainerRef,
|
|
2793
|
-
children: /* @__PURE__ */ jsx10("div", { className: `${classBase6}-scrollbarContent` })
|
|
2794
|
-
}
|
|
2795
|
-
) : null,
|
|
2796
|
-
innerSize ? /* @__PURE__ */ jsxs7(
|
|
2797
|
-
"div",
|
|
2798
|
-
{
|
|
2799
|
-
className: `${classBase6}-contentContainer`,
|
|
2800
|
-
ref: scrollProps.contentContainerRef,
|
|
2801
|
-
children: [
|
|
2802
|
-
/* @__PURE__ */ jsx10(
|
|
2803
|
-
RowBasedTable,
|
|
2804
|
-
{
|
|
2805
|
-
...tableProps,
|
|
2806
|
-
headerHeight,
|
|
2807
|
-
tableId: id
|
|
2808
|
-
}
|
|
2809
|
-
),
|
|
2810
|
-
draggable
|
|
2811
|
-
]
|
|
2812
|
-
}
|
|
2813
|
-
) : null,
|
|
2814
|
-
showSettings && innerSize ? /* @__PURE__ */ jsx10(
|
|
2815
|
-
Button,
|
|
2816
|
-
{
|
|
2817
|
-
className: `${classBase6}-settings`,
|
|
2818
|
-
"data-icon": "settings",
|
|
2819
|
-
onClick: onShowSettings,
|
|
2820
|
-
variant: "secondary"
|
|
2821
|
-
}
|
|
2822
|
-
) : null
|
|
2823
|
-
]
|
|
2824
|
-
}
|
|
2825
|
-
)
|
|
2826
|
-
}
|
|
2827
|
-
);
|
|
2828
|
-
};
|
|
2829
|
-
|
|
2830
|
-
// src/cell-renderers/json-cell/JsonCell.tsx
|
|
2831
|
-
import cx8 from "classnames";
|
|
2832
|
-
import {
|
|
2833
|
-
isJsonAttribute,
|
|
2834
|
-
metadataKeys as metadataKeys9,
|
|
2835
|
-
registerComponent
|
|
2836
|
-
} from "@vuu-ui/vuu-utils";
|
|
2837
|
-
import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2838
|
-
var classBase7 = "vuuJsonCell";
|
|
2839
|
-
var { IS_EXPANDED: IS_EXPANDED3, KEY: KEY3 } = metadataKeys9;
|
|
2840
|
-
var localKey = (key) => {
|
|
2841
|
-
const pos = key.lastIndexOf("|");
|
|
2842
|
-
if (pos === -1) {
|
|
2843
|
-
return "";
|
|
2844
|
-
} else {
|
|
2845
|
-
return key.slice(pos + 1);
|
|
2846
|
-
}
|
|
2847
|
-
};
|
|
2848
|
-
var JsonCell = ({ column, row }) => {
|
|
2849
|
-
const {
|
|
2850
|
-
key: columnKey
|
|
2851
|
-
/*, type, valueFormatter */
|
|
2852
|
-
} = column;
|
|
2853
|
-
let value = row[columnKey];
|
|
2854
|
-
let isToggle = false;
|
|
2855
|
-
if (isJsonAttribute(value)) {
|
|
2856
|
-
value = value.slice(0, -1);
|
|
2857
|
-
isToggle = true;
|
|
2858
|
-
}
|
|
2859
|
-
const rowKey = localKey(row[KEY3]);
|
|
2860
|
-
const className = cx8({
|
|
2861
|
-
[`${classBase7}-name`]: rowKey === value,
|
|
2862
|
-
[`${classBase7}-value`]: rowKey !== value,
|
|
2863
|
-
[`${classBase7}-group`]: isToggle
|
|
2864
|
-
});
|
|
2865
|
-
if (isToggle) {
|
|
2866
|
-
const toggleIcon = row[IS_EXPANDED3] ? "minus-box" : "plus-box";
|
|
2867
|
-
return /* @__PURE__ */ jsxs8("span", { className, children: [
|
|
2868
|
-
/* @__PURE__ */ jsx11("span", { className: `${classBase7}-value`, children: value }),
|
|
2869
|
-
/* @__PURE__ */ jsx11("span", { className: `${classBase7}-toggle`, "data-icon": toggleIcon })
|
|
2870
|
-
] });
|
|
2871
|
-
} else if (value) {
|
|
2872
|
-
return /* @__PURE__ */ jsx11("span", { className, children: value });
|
|
2873
|
-
} else {
|
|
2874
|
-
return null;
|
|
2875
|
-
}
|
|
2876
|
-
};
|
|
2877
|
-
registerComponent("json", JsonCell, "cell-renderer", {});
|
|
2878
|
-
export {
|
|
2879
|
-
Table,
|
|
2880
|
-
buildContextMenuDescriptors,
|
|
2881
|
-
useMeasuredContainer,
|
|
2882
|
-
useTableContextMenu,
|
|
2883
|
-
useTableModel,
|
|
2884
|
-
useTableViewport
|
|
2885
|
-
};
|
|
1
|
+
import{isNumericColumn as Rn}from"@vuu-ui/vuu-utils";var Be=e=>(t,n)=>{let o=[];if(e===void 0)return o;if(t==="header")o.push(...Dn(n,e)),o.push(...Pn(n,e)),o.push(...xn(n,e)),o.push(...Hn(n));else if(t==="filter"){let{column:r,filter:i}=n,s=(i==null?void 0:i.column)===(r==null?void 0:r.name);o.push({label:"Edit filter",action:"filter-edit",options:n}),o.push({label:"Remove filter",action:"filter-remove-column",options:n}),r&&!s&&o.push({label:"Remove all filters",action:"remove-filters",options:n})}return o};function Dn(e,{sort:{sortDefs:t}}){let{column:n}=e,o=[];if(n===void 0)return o;let r=t.length>0;return n.sorted==="A"?o.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):n.sorted==="D"?o.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof n.sorted=="number"?(n.sorted>0?o.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):o.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),r&&Math.abs(n.sorted)<t.length&&o.push({label:"Remove from sort",action:"sort-remove",options:e}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r?(o.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),o.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):o.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),o}function xn(e,t){let{column:n}=e;if(n===void 0||t.groupBy.length===0)return[];let{name:o,label:r=o}=n;return[{label:`Aggregate ${r}`,children:[{label:"Count",action:"agg-count",options:e},{label:"Distinct",action:"agg-distinct",options:e}].concat(Rn(n)?[{label:"Sum",action:"agg-sum",options:e},{label:"Avg",action:"agg-avg",options:e},{label:"High",action:"agg-high",options:e},{label:"Low",action:"agg-low",options:e}]:[])}]}var Ce=(e,t)=>({label:`Pin ${t}`,action:`column-pin-${t}`,options:e}),fe=e=>Ce(e,"left"),ge=e=>Ce(e,"floating"),be=e=>Ce(e,"right");function Hn(e){let{column:t}=e;if(t===void 0)return[];let{pin:n}=t,o=[{label:"Hide column",action:"column-hide",options:e},{label:"Remove column",action:"column-remove",options:e}];return n===void 0?o.push({label:"Pin column",children:[fe(e),ge(e),be(e)]}):n==="left"?o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[ge(e),be(e)]}):n==="right"?o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[fe(e),ge(e)]}):n==="floating"&&o.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[fe(e),be(e)]}),o}function Pn(e,{groupBy:t}){let{column:n}=e,o=[];if(n===void 0)return o;let{name:r,label:i=r}=n;return t.length===0?o.push({label:`Group by ${i}`,action:"group",options:e}):o.push({label:`Add ${i} to group by`,action:"group-add",options:e}),o}import{removeColumnFromFilter as En}from"@vuu-ui/vuu-filters";import{addGroupColumn as Ue,addSortColumn as _e,AggregationType as Sn,setAggregations as Y,setSortColumn as Je}from"@vuu-ui/vuu-utils";var An=(e,t)=>{if(e.filterStruct&&t){let[n,o]=En(t,e.filterStruct);return{filter:o,filterStruct:n}}else return e},{Average:Ln,Count:kn,Distinct:Kn,High:zn,Low:Nn,Sum:Fn}=Sn,Xe=({dataSource:e,onPersistentColumnOperation:t})=>(o,r)=>{let i=r;if(i.column&&e){let{column:s}=i;switch(o){case"sort-asc":return e.sort=Je(e.sort,s,"A"),!0;case"sort-dsc":return e.sort=Je(e.sort,s,"D"),!0;case"sort-add-asc":return e.sort=_e(e.sort,s,"A"),!0;case"sort-add-dsc":return e.sort=_e(e.sort,s,"D"),!0;case"group":return e.groupBy=Ue(e.groupBy,s),!0;case"group-add":return e.groupBy=Ue(e.groupBy,s),!0;case"column-hide":return t({type:"hideColumns",columns:[s]}),!0;case"column-remove":return e.columns=e.columns.filter(l=>l!==s.name),!0;case"filter-remove-column":return e.filter=An(e.filter,s),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=Y(e.aggregations,s,Ln),!0;case"agg-high":return e.aggregations=Y(e.aggregations,s,zn),!0;case"agg-low":return e.aggregations=Y(e.aggregations,s,Nn),!0;case"agg-count":return e.aggregations=Y(e.aggregations,s,kn),!0;case"agg-distinct":return e.aggregations=Y(e.aggregations,s,Kn),!0;case"agg-sum":return e.aggregations=Y(e.aggregations,s,Fn),!0;case"column-pin-floating":return t({type:"pinColumn",column:s,pin:"floating"}),!0;case"column-pin-left":return t({type:"pinColumn",column:s,pin:"left"}),!0;case"column-pin-right":return t({type:"pinColumn",column:s,pin:"right"}),!0;case"column-unpin":return t({type:"pinColumn",column:s,pin:void 0}),!0;default:}}return!1};import{ContextMenuProvider as cs}from"@vuu-ui/vuu-popups";import{Button as us,useIdMemo as ms}from"@salt-ds/core";import{buildColumnMap as Mo,getColumnStyle as To,isGroupColumn as Ro,metadataKeys as Do,notHidden as xo,visibleColumnAtIndex as Ho}from"@vuu-ui/vuu-utils";import{useCallback as gt,useMemo as bt}from"react";import{isGroupColumn as qe,isJsonColumn as jn,isJsonGroup as qn,metadataKeys as eo,notHidden as to}from"@vuu-ui/vuu-utils";import no from"classnames";import{memo as oo,useCallback as et}from"react";import{getColumnStyle as In,metadataKeys as Vn}from"@vuu-ui/vuu-utils";import{EditableLabel as Wn}from"@heswell/salt-lab";import $n from"classnames";import{memo as On,useCallback as Gn,useRef as Bn,useState as Ye}from"react";import{jsx as ie}from"react/jsx-runtime";var{KEY:Qe}=Vn,he=On(({className:e,column:t,columnMap:n,onClick:o,row:r})=>{let i=Bn(null),{align:s,CellRenderer:l,key:a,pin:u,editable:c,resizing:p,valueFormatter:d}=t,[g,h]=Ye(!1),f=d(r[a]),[T,y]=Ye(f),m=()=>{var P;(P=i.current)==null||P.focus()},C=P=>{P.key==="Enter"&&h(!0)},R=Gn(P=>{o==null||o(P,t)},[t,o]),w=()=>{h(!0)},v=(P="",b="",M=!0,E=!1)=>{var x;h(!1),E?y(P):b!==P&&y(b),M===!1&&((x=i.current)==null||x.focus())},D=$n(e,{vuuAlignRight:s==="right",vuuPinFloating:u==="floating",vuuPinLeft:u==="left",vuuPinRight:u==="right","vuuTableCell-resizing":p})||void 0,S=In(t);return c?ie("div",{className:D,"data-editable":!0,role:"cell",style:S,onKeyDown:C,children:ie(Wn,{editing:g,value:T,onChange:y,onMouseDownCapture:m,onEnterEditMode:w,onExitEditMode:v,onKeyDown:C,ref:i,tabIndex:0},"title")}):ie("div",{className:D,role:"cell",style:S,onClick:R,children:l?ie(l,{column:t,columnMap:n,row:r}):f})},Un);he.displayName="TableCell";function Un(e,t){return e.column===t.column&&e.onClick===t.onClick&&e.row[Qe]===t.row[Qe]&&e.row[e.column.key]===t.row[t.column.key]}import{getColumnStyle as _n,metadataKeys as Jn}from"@vuu-ui/vuu-utils";import{useCallback as Xn}from"react";import{jsx as ve,jsxs as Zn}from"react/jsx-runtime";var{DEPTH:Yn,IS_LEAF:Ze}=Jn,Qn=(e,t)=>{let{[Yn]:n,[Ze]:o}=t;if(o||n>e.length)return[null,n===null?0:Math.max(0,n-1)];if(n===0)return["$root",0];{let{key:r,valueFormatter:i}=e[n-1];return[i(t[r]),n-1]}},je=({column:e,onClick:t,row:n})=>{let{columns:o}=e,[r,i]=Qn(o,n),s=Xn(c=>{t==null||t(c,e)},[e,t]),l=_n(e),a=n[Ze],u=Array(i).fill(0).map((c,p)=>ve("span",{className:"vuuTableGroupCell-spacer"},p));return Zn("div",{className:"vuuTableGroupCell vuuPinLeft",onClick:a?void 0:s,role:"cell",style:l,children:[u,a?null:ve("span",{className:"vuuTableGroupCell-toggle","data-icon":"triangle-right"}),ve("span",{children:r})]})};import{jsx as tt,jsxs as lo}from"react/jsx-runtime";var{IDX:ro,IS_EXPANDED:so,SELECTED:io}=eo,le="vuuTableRow",nt=oo(function({columnMap:t,columns:n,offset:o,onClick:r,onToggleGroup:i,virtualColSpan:s=0,row:l}){let{[ro]:a,[so]:u,[io]:c}=l,p=no(le,{[`${le}-even`]:a%2===0,[`${le}-expanded`]:u,[`${le}-preSelected`]:c===2}),d=et(h=>{let f=h.shiftKey,T=h.ctrlKey||h.metaKey;r==null||r(l,f,T)},[r,l]),g=et((h,f)=>{(qe(f)||qn(f,l))&&(h.stopPropagation(),i==null||i(l,f))},[i,l]);return lo("div",{"aria-selected":c===1?!0:void 0,"aria-rowindex":a,className:p,onClick:d,role:"row",style:{transform:`translate3d(0px, ${o}px, 0px)`},children:[s>0?tt("div",{role:"cell",style:{width:s}}):null,n.filter(to).map(h=>{let f=qe(h),T=jn(h);return tt(f?je:he,{column:h,columnMap:t,onClick:f||T?g:void 0,row:l},h.name)})]})});import it from"classnames";import{useRef as mo}from"react";import{useCallback as ye,useRef as ao}from"react";import{jsx as uo}from"react/jsx-runtime";var ot=()=>{},co="vuuColumnResizer",ae=({onDrag:e,onDragEnd:t=ot,onDragStart:n=ot})=>{let o=ao(0),r=ye(l=>{l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault();let a=Math.round(l.clientX),u=a-o.current;o.current=a,u!==0&&e(l,u)},[e]),i=ye(l=>{window.removeEventListener("mouseup",i),window.removeEventListener("mousemove",r),t(l)},[t,r]),s=ye(l=>{n(l),o.current=Math.round(l.clientX),window.addEventListener("mouseup",i),window.addEventListener("mousemove",r),l.stopPropagation&&l.stopPropagation(),l.preventDefault&&l.preventDefault()},[n,r,i]);return uo("div",{className:co,"data-align":"end",onMouseDown:s})};import{useCallback as we,useRef as rt}from"react";var ce=({column:e,onResize:t,rootRef:n})=>{let o=rt(0),r=rt(!1),{name:i}=e,s=we(()=>{if(t&&n.current){let{width:u}=n.current.getBoundingClientRect();o.current=Math.round(u),r.current=!0,t==null||t("begin",i)}},[i,t,n]),l=we((u,c)=>{if(n.current&&t){let{width:p}=n.current.getBoundingClientRect(),d=Math.round(p)+c;d!==o.current&&d>0&&(t("resize",i,d),o.current=d)}},[i,t,n]),a=we(()=>{t&&(t("end",i,o.current),setTimeout(()=>{r.current=!1},100))},[i,t]);return{isResizing:r.current,onDrag:l,onDragStart:s,onDragEnd:a}};import{jsx as G,jsxs as at}from"react/jsx-runtime";var V="vuuTable-groupHeaderCell",st=({column:e,onClick:t,...n})=>G("span",{...n,className:`${V}-close`,"data-icon":"close-circle",onClick:()=>t==null?void 0:t(e)}),po=e=>{let{children:t,column:n,className:o}=e;return at("div",{className:it(`${V}-col`,o),role:"columnheader",children:[G("span",{className:`${V}-label`,children:n.name}),t]})},lt=({column:e,className:t,onRemoveColumn:n,onResize:o,...r})=>{let i=mo(null),{isResizing:s,...l}=ce({column:e,onResize:o,rootRef:i}),a=it(V,t,{vuuPinLeft:e.pin==="left",[`${V}-right`]:e.align==="right",[`${V}-resizing`]:e.resizing,[`${V}-pending`]:e.groupConfirmed===!1}),{columns:u}=e;return G("div",{className:a,ref:i,...r,children:at("div",{className:`${V}-inner`,children:[u.map(c=>G(po,{column:c,children:u.length>1?G(st,{column:c,onClick:n}):null},c.key)),G(st,{"data-align":"end",onClick:n}),e.resizeable!==!1?G(ae,{...l}):null]})})};import vo from"classnames";import{useCallback as Me,useRef as pt}from"react";import ct from"classnames";import{jsx as ue,jsxs as fo}from"react/jsx-runtime";var ut="vuuSortIndicator",mt=({sorted:e})=>{if(!e)return null;let t=typeof e=="number"?e<0?"dsc":"asc":e==="A"?"asc":"dsc";return typeof e=="number"?fo("div",{className:ct(ut,"multi-col",t),children:[ue("span",{"data-icon":`sorted-${t}`}),ue("span",{className:"vuuSortPosition",children:Math.abs(e)})]}):ue("div",{className:ct(ut,"single-col"),children:ue("span",{"data-icon":`sorted-${t}`})})};import{useContextMenu as yo}from"@vuu-ui/vuu-popups";import{useContextMenu as go}from"@vuu-ui/vuu-popups";import bo from"classnames";import{useCallback as Co}from"react";import{jsx as ho}from"react/jsx-runtime";var dt=({column:e,filter:t})=>{let n=go(),o=Co(r=>{r.stopPropagation(),n(r,"filter",{column:e,filter:t})},[e,t,n]);return e.filter?ho("div",{className:bo("vuuFilterIndicator"),"data-icon":"filter",onClick:o}):null};import{jsx as q,jsxs as wo}from"react/jsx-runtime";var j="vuuTable-headerCell",ft=({column:e,className:t,onClick:n,onDragStart:o,onResize:r,...i})=>{let s=pt(null),{isResizing:l,...a}=ce({column:e,onResize:r,rootRef:s}),u=yo(),c=pt(null),p=T=>{u(T,"header",{column:e})},d=Me(T=>!l&&(n==null?void 0:n(T)),[l,n]),g=Me(T=>{c.current=window.setTimeout(()=>{o==null||o(T),c.current=null},500)},[o]),h=Me(()=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),f=vo(j,t,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:e.endPin,[`${j}-resizing`]:e.resizing,[`${j}-right`]:e.align==="right"});return q("div",{className:f,...i,onClick:d,onContextMenu:p,onMouseDown:g,onMouseUp:h,ref:s,children:wo("div",{className:`${j}-inner`,children:[q(dt,{column:e}),q("div",{className:`${j}-label`,children:e.label}),q(mt,{sorted:e.sorted}),e.resizeable!==!1?q(ae,{...a}):null]})})};import{jsx as B,jsxs as Ct}from"react/jsx-runtime";var Te="vuuTable",{RENDER_IDX:Po}=Do,ht=({columns:e,columnsWithinViewport:t,data:n,getRowOffset:o,headings:r,onColumnResize:i,onHeaderCellDragStart:s,onContextMenu:l,onRemoveColumnFromGroupBy:a,onRowClick:u,onSort:c,onToggleGroup:p,tableId:d,virtualColSpan:g=0,rowCount:h})=>{let f=gt(C=>{s==null||s(C)},[s]),T=bt(()=>e.filter(xo),[e]),y=bt(()=>Mo(e),[e]),m=gt(C=>{var P;let w=C.target.closest(".vuuTable-headerCell"),v=parseInt((P=w==null?void 0:w.dataset.idx)!=null?P:"-1"),D=Ho(e,v),S=C.shiftKey;D&&c(D,S)},[e,c]);return Ct("div",{"aria-rowcount":h,className:`${Te}-table`,role:"table",children:[Ct("div",{className:`${Te}-headers`,role:"rowGroup",children:[r.map((C,R)=>B("div",{className:"vuuTable-heading",children:C.map(({label:w,width:v},D)=>B("div",{className:"vuuTable-headingCell",style:{width:v},children:w},D))},R)),B("div",{role:"row",children:T.map((C,R)=>{let w=To(C);return Ro(C)?B(lt,{column:C,"data-idx":R,onRemoveColumn:a,onResize:i,role:"columnHeader",style:w},R):B(ft,{column:C,"data-idx":R,id:`${d}-${R}`,onClick:m,onDragStart:f,onResize:i,role:"columnHeader",style:w},R)})})]}),B("div",{className:`${Te}-body`,onContextMenu:l,role:"rowGroup",children:n==null?void 0:n.map(C=>B(nt,{columnMap:y,columns:t,offset:o(C),onClick:u,virtualColSpan:g,onToggleGroup:p,row:C},C[Po]))})]})};import{useContextMenu as qr}from"@vuu-ui/vuu-popups";import{applySort as es,buildColumnMap as ts,isJsonGroup as ns,metadataKeys as os,moveItem as rs}from"@vuu-ui/vuu-utils";import{useCallback as z,useEffect as Qt,useMemo as ss,useRef as Ie,useState as is}from"react";import{isVuuFeatureAction as Eo,isVuuFeatureInvocation as So}from"@vuu-ui/vuu-data";import{getFullRange as Re,metadataKeys as Ao,WindowRange as Lo}from"@vuu-ui/vuu-utils";import{useCallback as Q,useEffect as me,useMemo as ko,useRef as ee,useState as Ko}from"react";var{SELECTED:te}=Ao;function vt({dataSource:e,onConfigChange:t,onFeatureEnabled:n,onFeatureInvocation:o,onSizeChange:r,onSubscribed:i,range:s={from:0,to:0},renderBufferSize:l=0,viewportRowCount:a}){let[,u]=Ko(null),c=ee(!0),p=ee(!1),d=ee({from:0,to:0}),g=ee(null),h=ee([]),f=ko(()=>new De(Re(s)),[]),T=Q(v=>{for(let D of v)f.add(D);h.current=f.data,p.current=!0},[f]),y=Q(v=>{v.type==="subscribed"?i==null||i(v):v.type==="viewport-update"?(typeof v.size=="number"&&(r==null||r(v.size),f.setRowCount(v.size)),v.rows?T(v.rows):typeof v.size=="number"&&(h.current=f.data,p.current=!0)):Eo(v)?n==null||n(v):So(v)?o==null||o(v):console.log(`useDataSource unexpected message ${v.type}`)},[f,n,o,r,i,T]);me(()=>()=>{g.current&&(cancelAnimationFrame(g.current),g.current=null),c.current=!1},[]);let m=Q(()=>{c.current&&(p.current&&(u({}),p.current=!1),g.current=requestAnimationFrame(m))},[u]);me(()=>{g.current=requestAnimationFrame(m)},[m]);let C=Q(v=>{let{from:D}=e.range,S={from:D,to:D+v},P=Re(S,l);f.setRange(P),e.range=d.current=P,e.emit("range",S)},[e,f,l]),R=Q(v=>{let D=Re(v,l);f.setRange(D),e.range=d.current=D,e.emit("range",v)},[e,f,l]),w=Q(()=>f.getSelectedRows(),[f]);return me(()=>{e==null||e.subscribe({range:d.current},y)},[e,y,t]),me(()=>{C(a)},[C,a]),{data:h.current,getSelectedRows:w,range:d.current,setRange:R,dataSource:e}}var De=class{constructor({from:t,to:n}){this.rowCount=0;this.setRowCount=t=>{t<this.data.length&&(this.data.length=t),this.rowCount=t};this.range=new Lo(t,n),this.data=new Array(n-t),this.rowCount=0}add(t){var o;let[n]=t;if(this.isWithinRange(n)){let r=n-this.range.from;this.data[r]=t;let i=t[te],s=(o=this.data[r-1])==null?void 0:o[te];s===0&&i?this.data[r-1][te]=2:s===2&&!i&&(this.data[r-1][te]=0)}}getAtIndex(t){return this.range.isWithin(t)&&this.data[t-this.range.from]!=null?this.data[t-this.range.from]:void 0}isWithinRange(t){return this.range.isWithin(t)}setRange({from:t,to:n}){if(t!==this.range.from||n!==this.range.to){let[o,r]=this.range.overlap(t,n),i=new Array(Math.max(0,n-t));for(let s=o;s<r;s++){let l=this.getAtIndex(s);if(l){let a=s-t;i[a]=l}}this.data=i,this.range.from=t,this.range.to=n}}getSelectedRows(){return this.data.filter(t=>t[te]===1)}};import{useDragDrop as zo}from"@heswell/salt-lab";import{useCallback as yt,useRef as wt}from"react";var Mt=({onDrop:e})=>{let t=wt(),n=wt(null),o=yt(()=>{console.log("handleDropSettle"),t.current=void 0,n.current=null},[]),{draggable:r,draggedItemIndex:i,onMouseDown:s}=zo({allowDragDrop:!0,draggableClassName:"vuuTable-headerCell",orientation:"horizontal",containerRef:n,itemQuery:".vuuTable-headerCell",onDrop:e,onDropSettle:o}),l=yt(a=>{let{clientX:u,clientY:c}=a;console.log("useDraggableColumn handleHeaderCellDragStart means mouseDown fired on a column in RowBasedTable");let d=a.target.closest(".vuuTable-headerCell");n.current=d==null?void 0:d.closest("[role='row']");let{dataset:{idx:g="-1"}}=d;t.current={clientX:u,clientY:c,idx:g},s==null||s(a)},[s]);return{draggable:r,draggedItemIndex:i,onHeaderCellDragStart:l}};import{withinRange as Oo}from"@vuu-ui/vuu-utils";import{useCallback as I,useEffect as Go,useLayoutEffect as Bo,useMemo as Uo,useRef as Ke}from"react";function No(e,...t){let n=new Set(e);for(let o of t)for(let r of o)n.add(r);return n}var xe="ArrowUp",He="ArrowDown",Pe="ArrowLeft",Ee="ArrowRight";var Se="Home",Ae="End",Le="PageUp",ke="PageDown";var Fo=new Set(["Enter","Delete"," "]),Io=new Set(["Tab"]),Vo=new Set(["ArrowRight","ArrowLeft"]),Tt=new Set([Se,Ae,Le,ke,He,Pe,Ee,xe]),Wo=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),El=No(Fo,Tt,Vo,Wo,Io);var $o=["Home","End","PageUp","PageDown"],Rt=e=>$o.includes(e),Dt=e=>Tt.has(e);var xt=e=>`.vuuTable-headers .vuuTable-headerCell:nth-child(${e+1})`,_o=(e,t)=>`.vuuTable-body > [aria-rowindex='${e}'] > [role='cell']:nth-child(${t+1})`,Jo=[-1,-1];function Xo(e,[t,n],o,r){return e===xe?t>-1?[t-1,n]:[t,n]:e===He?t===-1?[0,n]:t===r-1?[t,n]:[t+1,n]:e===Ee?n<o-1?[t,n+1]:[t,n]:e===Pe?n>0?[t,n-1]:[t,n]:[t,n]}var Ht=({columnCount:e=0,containerRef:t,disableHighlightOnFocus:n,data:o,requestScroll:r,rowCount:i=0,viewportRange:s})=>{var P;let{from:l,to:a}=s,u=Ke([-1,-1]),c=Ke(),p=Ke([-1,0]),d=I(([b,M])=>{var x;let E=b===-1?xt(M):_o(b,M);return(x=t.current)==null?void 0:x.querySelector(E)},[t]),g=b=>b==null?void 0:b.closest("[role='columnHeader'],[role='cell']"),h=b=>{var M,E;if(b.role==="columnHeader")return[-1,parseInt((M=b.dataset.idx)!=null?M:"-1",10)];{let x=b.closest("[role='row']");if(x){let k=parseInt((E=x.ariaRowIndex)!=null?E:"-1",10),J=Array.from(x.childNodes).indexOf(b);return[k,J]}}return Jo},f=I(b=>{var M;if(t.current){let E=d(b);E?(E!==c.current&&((M=c.current)==null||M.setAttribute("tabindex",""),c.current=E,E.setAttribute("tabindex","0")),E.focus()):Oo(b[0],s)||(c.current=void 0,r==null||r({type:"scroll-page",direction:"up"}))}},[t,d,r,s]),T=I((b,M,E=!1)=>{let x=[b,M];p.current=x,f(x),E&&(u.current=x)},[f]),y=I(()=>{var b;(b=c.current)==null||b.setAttribute("tabindex",""),c.current=void 0},[]),m=I(async(b,M)=>{switch(b){case ke:r==null||r({type:"scroll-page",direction:"down"});break;case Le:r==null||r({type:"scroll-page",direction:"up"});break;case Se:r==null||r({type:"scroll-end",direction:"home"});break;case Ae:r==null||r({type:"scroll-end",direction:"end"});break}return M},[r]),C=I(()=>{var b;if(n!==!0&&(b=t.current)!=null&&b.contains(document.activeElement)){let M=g(document.activeElement);M&&(u.current=h(M))}},[n,t]),R=I(async b=>{let[M,E]=Rt(b)?await m(b,p.current):Xo(b,p.current,e,i),[x,k]=p.current;(M!==x||E!==k)&&T(M,E,!0)},[e,m,i,T]),w=I(b=>{o.length>0&&Dt(b.key)&&(b.preventDefault(),b.stopPropagation(),R(b.key))},[o,R]),v=I(b=>{let M=b.target,E=g(M);if(E){let[x,k]=h(E);T(x,k)}},[T]),D=Uo(()=>({onClick:v,onFocus:C,onKeyDown:w}),[v,C,w]);Bo(()=>{let{current:b}=p,M=b[0]>=l&&b[0]<=a;c.current&&!M?y():!c.current&&M&&f(b)},[f,l,a,y]);let S=((P=t.current)==null?void 0:P.firstChild)!=null;return Go(()=>{var b;if(S&&c.current===void 0){let M=(b=t.current)==null?void 0:b.querySelector(xt(0));M&&(M.setAttribute("tabindex","0"),c.current=M)}},[t,S]),D};import{isValidNumber as W}from"@vuu-ui/vuu-utils";import{useCallback as Zo,useMemo as jo,useRef as qo,useState as er}from"react";import{useCallback as Yo,useEffect as Pt,useRef as Qo}from"react";var U=new Map,St=(e,t,n)=>{switch(n){case"height":return t.height;case"clientHeight":return e.clientHeight;case"clientWidth":return e.clientWidth;case"contentHeight":return t.contentHeight;case"contentWidth":return t.contentWidth;case"scrollHeight":return Math.ceil(e.scrollHeight);case"scrollWidth":return Math.ceil(e.scrollWidth);case"width":return t.width;default:return 0}},Et=new ResizeObserver(e=>{for(let t of e){let{target:n,borderBoxSize:o,contentBoxSize:r}=t,i=U.get(n);if(i){let[{blockSize:s,inlineSize:l}]=o,[{blockSize:a,inlineSize:u}]=r,{onResize:c,measurements:p}=i,d=!1;for(let[g,h]of Object.entries(p)){let f=St(n,{height:s,width:l,contentHeight:a,contentWidth:u},g);f!==h&&(d=!0,p[g]=f)}d&&c&&c(p)}}});function At(e,t,n,o=!1){let r=Qo(t),i=Yo(s=>{let{width:l,height:a}=s.getBoundingClientRect(),{clientWidth:u,clientHeight:c}=s;return r.current.reduce((p,d)=>(p[d]=St(s,{width:l,height:a,contentHeight:c,contentWidth:u},d),p),{})},[]);Pt(()=>{let s=e.current;async function l(){U.set(s,{measurements:{}}),await document.fonts.ready;let a=U.get(s);if(a){let u=i(s);a.measurements=u,Et.observe(s),o&&n(u)}else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation","font-weight:bold; color:red;")}if(s){if(U.has(s))throw Error("useResizeObserver attemping to observe same element twice");l()}return()=>{s&&U.has(s)&&(Et.unobserve(s),U.delete(s))}},[i,e]),Pt(()=>{let s=e.current,l=U.get(s);if(l){if(r.current!==t){r.current=t;let a=i(s);l.measurements=a}l.onResize=n}},[t,i,e,n])}var tr=["clientHeight","clientWidth"],Lt=e=>Number.isFinite(e),nr={height:"100%",width:"100%"},or=(e,t)=>W(e)&&W(t)?{height:`${e}px`,width:`${t}px`}:nr,rr=(e,t)=>{if(W(e)&&W(t))return{height:e,width:t}},kt=({defaultHeight:e=0,defaultWidth:t=0,height:n,width:o})=>{let r=qo(null),[i,s]=er({css:or(n,o),inner:rr(n,o),outer:{height:n!=null?n:"100%",width:o!=null?o:"100%"}});jo(()=>{s(a=>{let{inner:u,outer:c}=a;if(W(n)&&W(o)&&u&&c){let{height:p,width:d}=u,{height:g,width:h}=c;if(g!==n||h!==o){let f=W(g)?g-p:0,T=W(h)?h-d:0;return{...a,outer:{height:n,width:o},inner:{height:n-f,width:o-T}}}}return a})},[n,o]);let l=Zo(({clientWidth:a,clientHeight:u})=>{s(c=>{let{css:p,inner:d,outer:g}=c;return Lt(u)&&Lt(a)&&(a!==(d==null?void 0:d.width)||u!==(d==null?void 0:d.height))?{css:p,outer:g,inner:{width:Math.floor(a)||t,height:Math.floor(u)||e}}:c})},[e,t]);return At(r,tr,l,!0),{containerRef:r,cssSize:i.css,outerSize:i.outer,innerSize:i.inner}};import{deselectItem as sr,metadataKeys as ir,selectItem as lr}from"@vuu-ui/vuu-utils";import{useCallback as ar,useRef as Kt}from"react";var{IDX:cr,SELECTED:ur}=ir,mr=[],zt=({selectionModel:e,onSelectionChange:t})=>{let n=Kt(-1),o=Kt(mr);return ar((i,s,l)=>{let{[cr]:a,[ur]:u}=i,{current:c}=n,{current:p}=o,g=(u?sr:lr)(e,p,a,s,l,c);o.current=g,n.current=a,t&&t(g)},[t,e])};import{moveItem as dr}from"@heswell/salt-lab";import{applyFilterToColumns as pr,applyGroupByToColumns as fr,applySortToColumns as gr,findColumn as br,getCellRenderer as Cr,getColumnName as hr,getTableHeadings as vr,getValueFormatter as yr,isFilteredColumn as wr,isGroupColumn as Mr,isPinned as Tr,isTypeDescriptor as Rr,logger as Dr,metadataKeys as xr,sortPinnedColumns as Nt,stripFilterFromColumns as Hr}from"@vuu-ui/vuu-utils";import{useReducer as Pr}from"react";var{info:ze}=Dr("useTableModel"),Er=100,Ft=xr.count,Sr=({serverDataType:e})=>e===void 0,Ar=e=>{var t;if(Rr(e.type))return Cr((t=e.type)==null?void 0:t.renderer)},It=(e,t)=>{if(e.serverDataType)return e.serverDataType;if(t){let n=t.columns.find(o=>o.name===e.name);if(n)return n.serverDataType}return"string"},Lr=["int","long","double"],Vt=e=>e===void 0?void 0:Lr.includes(e)?"right":"left",kr=(e,t)=>{switch(ze==null||ze(`GridModelReducer ${t.type}`),t.type){case"init":return $t(t);case"moveColumn":return zr(e,t);case"resizeColumn":return Ir(e,t);case"setTableSchema":return Vr(e,t);case"hideColumns":return Nr(e,t);case"showColumns":return Fr(e,t);case"pinColumn":return Wr(e,t);case"updateColumnProp":return ne(e,t);case"tableConfig":return Ot(e,t);default:return console.log(`unhandled action ${t.type}`),e}},Wt=(e,t)=>{let[n,o]=Pr(kr,{tableConfig:e,dataSourceConfig:t},$t);return{columns:n.columns,dispatchColumnAction:o,headings:n.headings}};function $t({dataSourceConfig:e,tableConfig:t}){let n=t.columns.map(Ne(t)),o=n.some(Tr)?Nt(n):n,r={columns:o,headings:vr(o)};if(e){let{columns:i,...s}=e;return Ot(r,{type:"tableConfig",...s})}else return r}var Kr=(e,t)=>t==="uppercase"?e.toUpperCase():t==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,Ne=e=>(t,n)=>{let o=It(t,e.tableSchema),{columnDefaultWidth:r=Er,columnFormatHeader:i}=e,{align:s=Vt(o),key:l,name:a,label:u=a,width:c=r,...p}=t,d={...p,align:s,CellRenderer:Ar(t),label:Kr(u,i),key:l!=null?l:n+Ft,name:a,originalIdx:n,serverDataType:o,valueFormatter:yr(t),width:c};return Mr(d)&&(d.columns=d.columns.map(g=>Ne(e)(g,g.key))),d};function zr(e,{column:t,moveBy:n,moveTo:o}){let{columns:r}=e;if(typeof n=="number"){let i=r.indexOf(t),s=r.slice(),[l]=s.splice(i,1);return s.splice(i+n,0,l),{...e,columns:s}}else if(typeof o=="number"){let i=r.indexOf(t);return{...e,columns:dr(r,i,o)}}return e}function Nr(e,{columns:t}){return t.some(n=>n.hidden!==!0)?t.reduce((n,o)=>o.hidden!==!0?ne(n,{type:"updateColumnProp",column:o,hidden:!0}):n,e):e}function Fr(e,{columns:t}){return t.some(n=>n.hidden)?t.reduce((n,o)=>o.hidden?ne(n,{type:"updateColumnProp",column:o,hidden:!1}):n,e):e}function Ir(e,{column:t,phase:n,width:o}){let r="updateColumnProp",i=n!=="end";switch(n){case"begin":case"end":return ne(e,{type:r,column:t,resizing:i});case"resize":return ne(e,{type:r,column:t,width:o});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${n}`)}}function Vr(e,{tableSchema:t}){let{columns:n}=e;if(n.some(Sr)){let o=n.map(r=>{var s;let i=It(r,t);return{...r,align:(s=r.align)!=null?s:Vt(i),serverDataType:i}});return{...e,columns:o,tableSchema:t}}else return{...e,tableSchema:t}}function Wr(e,t){let{columns:n}=e,{column:o,pin:r}=t,i=n.find(s=>s.name===o.name);return i?(n=Z(n,{...i,pin:r}),n=Nt(n),{...e,columns:n}):e}function ne(e,t){let{columns:n}=e,{align:o,column:r,hidden:i,label:s,resizing:l,width:a}=t,u=n.find(c=>c.name===r.name);return u&&((o==="left"||o==="right")&&(n=Z(n,{...u,align:o})),typeof s=="string"&&(n=Z(n,{...u,label:s})),typeof l=="boolean"&&(n=Z(n,{...u,resizing:l})),typeof i=="boolean"&&(n=Z(n,{...u,hidden:i})),typeof a=="number"&&(n=Z(n,{...u,width:a}))),{...e,columns:n}}function Ot(e,{columns:t,confirmed:n,filter:o,groupBy:r,sort:i}){let s=t&&t.length>0,l=r!==void 0,a=typeof(o==null?void 0:o.filter)=="string",u=i&&i.sortDefs.length>0,c=e;return s&&(c={...e,columns:t.map((p,d)=>{let g=hr(p),h=d+Ft,f=br(c.columns,g);return f?f.key===h?f:{...f,key:h}:Ne(e)({name:p},d)})}),l&&(c={...e,columns:fr(c.columns,r,n)}),u&&(c={...e,columns:gr(c.columns,i)}),a?c={...e,columns:pr(c.columns,o)}:c.columns.some(wr)&&(c={...e,columns:Hr(c.columns)}),c}function Z(e,t){return e.map(n=>n.name===t.name?t:n)}import{useCallback as $,useRef as oe}from"react";var Gt=e=>{let{scrollLeft:t,scrollTop:n}=e,{clientHeight:o,clientWidth:r,scrollHeight:i,scrollWidth:s}=e,l=t/(s-r),a=n/(i-o);return[l,a]},$r=e=>{let{clientHeight:t,clientWidth:n,scrollHeight:o,scrollWidth:r}=e;return[r-n,o-t]},Bt=({onAttach:e,onDetach:t})=>{let n=oe(null);return $(r=>{if(r)n.current=r,e==null||e(r);else if(n.current){let{current:i}=n;n.current=r,t==null||t(i)}},[e,t])},Ut=({onHorizontalScroll:e,onVerticalScroll:t,viewport:n})=>{let o=oe(!1),r=oe({scrollTop:0,scrollLeft:0}),i=oe(null),s=oe(null),{maxScrollContainerScrollHorizontal:l,maxScrollContainerScrollVertical:a}=n,u=$(()=>{let{current:m}=s,{current:C}=i,{current:R}=o;if(R)o.current=!1;else if(m&&C){let[w,v]=Gt(C),[D,S]=$r(m),P=Math.round(w*D),b=Math.round(v*S);m.scrollTo({left:P,top:b,behavior:"auto"})}},[]),c=$(()=>{let{current:m}=s,{current:C}=i,{current:R}=r;if(m&&C){let{scrollLeft:w,scrollTop:v}=m,[D,S]=Gt(m);o.current=!0,C.scrollLeft=Math.round(D*l),C.scrollTop=Math.round(S*a),R.scrollTop!==v&&(R.scrollTop=v,t==null||t(v,S)),R.scrollLeft!==w&&(R.scrollLeft=w,e==null||e(w))}},[l,a,e,t]),p=$(m=>{i.current=m,m.addEventListener("scroll",u,{passive:!0})},[u]),d=$(m=>{i.current=null,m.removeEventListener("scroll",u)},[u]),g=$(m=>{s.current=m,m.addEventListener("scroll",c,{passive:!0})},[c]),h=$(m=>{s.current=null,m.removeEventListener("scroll",c)},[c]),f=Bt({onAttach:g,onDetach:h}),T=Bt({onAttach:p,onDetach:d}),y=$(m=>{let{current:C}=s;if(C){if(o.current=!1,m.type==="scroll-page"){let{clientHeight:R,scrollLeft:w,scrollTop:v}=C,{direction:D}=m,S=D==="down"?R:-R,P=Math.min(Math.max(0,v+S),a);C.scrollTo({top:P,left:w,behavior:"auto"})}else if(m.type==="scroll-end"){let{direction:R}=m,w=R==="end"?a:0;C.scrollTo({top:w,left:C.scrollLeft,behavior:"auto"})}}},[a]);return{scrollbarContainerRef:T,contentContainerRef:f,requestScroll:y}};import{useCallback as Or,useMemo as de,useRef as Gr}from"react";import{actualRowPositioning as Br,virtualRowPositioning as Ur}from"@vuu-ui/vuu-utils";var _r=15e5,Jr={contentHeight:0,contentWidth:0,getRowAtPosition:()=>-1,getRowOffset:()=>-1,horizontalScrollbarHeight:0,maxScrollContainerScrollHorizontal:0,maxScrollContainerScrollVertical:0,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,setPctScrollTop:()=>{},totalHeaderHeight:0,verticalScrollbarWidth:0,viewportBodyHeight:0},Xr=e=>{let t=0,n=0,o=0;for(let r of e){let{hidden:i,pin:s,width:l}=r,a=i?0:l;s==="left"?t+=a:s==="right"?n+=a:o+=a}return{pinnedWidthLeft:t,pinnedWidthRight:n,unpinnedWidth:o}},_t=({columns:e,headerHeight:t,headings:n,rowCount:o,rowHeight:r,size:i})=>{let s=Gr(0),a=Math.min(o,_r)*r,c=o*r-a,{pinnedWidthLeft:p,pinnedWidthRight:d,unpinnedWidth:g}=de(()=>Xr(e),[e]),[h,f]=de(()=>Br(r),[r]),[T,y]=de(()=>c?Ur(r,c,s):[h,f],[f,h,c,r]),m=Or(C=>{s.current=C},[]);return de(()=>{var C;if(i){let R=n.length,w=15,v=p+g+d,D=v>i.width?w:0,S=t*(1+R),P=a-(((C=i==null?void 0:i.height)!=null?C:0)-D)+S,b=v-i.width+p,M=(i.height-t)/r,E=Number.isInteger(M)?M+1:Math.ceil(M),x=i.height-S,k=a>x?w:0;return{contentHeight:a,getRowAtPosition:y,getRowOffset:T,horizontalScrollbarHeight:D,maxScrollContainerScrollHorizontal:b,maxScrollContainerScrollVertical:P,pinnedWidthLeft:p,pinnedWidthRight:d,rowCount:E,contentWidth:v,setPctScrollTop:m,totalHeaderHeight:S,verticalScrollbarWidth:k,viewportBodyHeight:x}}else return Jr},[i,n.length,p,g,d,a,t,r,y,T,m])};import{getColumnsInViewport as Jt,itemsChanged as Yr}from"@vuu-ui/vuu-utils";import{useCallback as Xt,useEffect as Qr,useMemo as Zr,useRef as Fe,useState as jr}from"react";var Yt=({columns:e,getRowAtPosition:t,setRange:n,viewportMeasurements:o})=>{let r=Fe(-1),{rowCount:i,contentWidth:s,maxScrollContainerScrollHorizontal:l}=o,a=s-l,u=Fe(0),[c,p]=Zr(()=>Jt(e,u.current,u.current+a),[a,e]),d=Fe(p);Qr(()=>{h(c)},[c]);let[g,h]=jr(c),f=Xt(y=>{u.current=y;let[m,C]=Jt(e,y,y+a);Yr(g,m)&&(d.current=C,h(m))},[a,e,g]),T=Xt(y=>{let m=t(y);m!==r.current&&(r.current=m,n({from:m,to:m+i}))},[t,n,i]);return{columnsWithinViewport:g,onHorizontalScroll:f,onVerticalScroll:T,virtualColSpan:d.current}};var ls=[],{KEY:as,IS_EXPANDED:Zt,IS_LEAF:jt}=os,qt=({config:e,dataSource:t,headerHeight:n,onConfigChange:o,onFeatureEnabled:r,onFeatureInvocation:i,onSelectionChange:s,renderBufferSize:l=0,rowHeight:a,selectionModel:u,...c})=>{var Oe,Ge;let[p,d]=is(t.size),g=Ie(!1),h=Ie();if(h.current=t,t===void 0)throw Error("no data source provided to Vuu Table");let f=kt(c),T=z(H=>{d(H)},[]),{columns:y,dispatchColumnAction:m,headings:C}=Wt(e,t.config),{getRowAtPosition:R,getRowOffset:w,setPctScrollTop:v,...D}=_t({columns:y,headerHeight:n,headings:C,rowCount:p,rowHeight:a,size:f.innerSize}),S=z(({tableSchema:H})=>{H?(g.current=!0,m({type:"setTableSchema",tableSchema:H})):console.log("usbscription message with no schema")},[m]),P=z(H=>{t.select(H),s==null||s(H)},[t,s]),b=zt({onSelectionChange:P,selectionModel:u}),{data:M,getSelectedRows:E,range:x,setRange:k}=vt({dataSource:t,onFeatureEnabled:r,onFeatureInvocation:i,onSubscribed:S,onSizeChange:T,renderBufferSize:l,viewportRowCount:D.rowCount}),J=Ie();J.current=M;let pe=z(H=>{g.current=!0,m(H)},[m]),tn=Xe({dataSource:t,onPersistentColumnOperation:pe}),nn=z((H,A=!1,K)=>{t&&(t.sort=es(t.sort,H,A,K))},[t]),on=z((H,A,K)=>{let L=y.find(N=>N.name===A);if(L)H==="end"&&(g.current=!0),m({type:"resizeColumn",phase:H,column:L,width:K});else throw Error(`useDataTable.handleColumnResize, column ${A} not found`)},[y,m]),rn=z((H,A)=>{let K=ns(A,H),L=H[as];if(H[Zt]){if(t.closeTreeNode(L,!0),K){let N=y.indexOf(A);t.getRowsAtDepth(N+1).some(F=>F[Zt]||F[jt])||m({type:"hideColumns",columns:y.slice(N+2)})}}else if(t.openTreeNode(L),K){let N=t.getChildRows(L),O=y.indexOf(A)+1,F=[y[O]];N.some(X=>X[jt])&&F.push(y[O+1]),F.some(X=>X.hidden)&&m({type:"showColumns",columns:F})}},[y,t,m]),{onVerticalScroll:We,onHorizontalScroll:sn,columnsWithinViewport:ln,virtualColSpan:an}=Yt({columns:y,getRowAtPosition:R,setRange:k,viewportMeasurements:D}),cn=z((H,A)=>{v(A),We(H)},[We,v]),{requestScroll:un,...mn}=Ut({onHorizontalScroll:sn,onVerticalScroll:cn,viewport:D,viewportHeight:((Ge=(Oe=f.innerSize)==null?void 0:Oe.height)!=null?Ge:0)-n}),dn=Ht({columnCount:y.length,containerRef:f.containerRef,data:M,requestScroll:un,rowCount:t==null?void 0:t.size,viewportRange:x}),pn=z(H=>{H?t&&t.groupBy.includes(H.name)&&(t.groupBy=t.groupBy.filter(A=>A!==H.name)):t.groupBy=[]},[t]),fn=z((H,A)=>{let K=t.columns[H],L=rs(t.columns,K,A);L!==t.columns&&(t.columns=L,m({type:"tableConfig",columns:L}))},[t,m]),gn=Mt({onDrop:fn});Qt(()=>{h.current&&(g.current=!0,m({type:"init",tableConfig:e,dataSourceConfig:h.current.config}))},[e,m]),Qt(()=>{t.on("config",(H,A)=>{g.current=!0,m({type:"tableConfig",...H,confirmed:A})})},[t,m]),ss(()=>{g.current&&(o==null||o({...e,columns:y}),g.current=!1)},[y,e,o]);let $e=qr(),bn=z(H=>{var F;let{current:A}=J,{current:K}=h,L=H.target,N=L==null?void 0:L.closest("div[role='cell']"),O=L==null?void 0:L.closest(".vuuTableRow");if(N&&O&&A&&K){let{columns:X,selectedRowsCount:Cn}=K,hn=ts(X),vn=parseInt((F=O.ariaRowIndex)!=null?F:"-1"),yn=Array.from(O.childNodes).indexOf(N),wn=A.find(([Tn])=>Tn===vn),Mn=X[yn];$e(H,"grid",{columnMap:hn,columnName:Mn,row:wn,selectedRows:Cn===0?ls:E(),viewport:t==null?void 0:t.viewport})}},[t==null?void 0:t.viewport,E,$e]);return{columns:y,columnsWithinViewport:ln,containerMeasurements:f,containerProps:dn,data:M,dispatchColumnAction:m,getRowOffset:w,handleContextMenuAction:tn,headings:C,onColumnResize:on,onContextMenu:bn,onRemoveColumnFromGroupBy:pn,onRowClick:b,onSort:nn,onToggleGroup:rn,virtualColSpan:an,scrollProps:mn,rowCount:p,viewportMeasurements:D,...gn}};import ds from"classnames";import{isDataLoading as ps}from"@vuu-ui/vuu-utils";import{jsx as re,jsxs as en}from"react/jsx-runtime";var _="vuuTable",Ua=({allowConfigEditing:e=!1,className:t,config:n,dataSource:o,headerHeight:r=25,height:i,id:s,onConfigChange:l,onFeatureEnabled:a,onFeatureInvocation:u,onSelectionChange:c,onShowConfigEditor:p,renderBufferSize:d=0,rowHeight:g=20,selectionModel:h="extended",style:f,width:T,zebraStripes:y=!1,...m})=>{let C=ms(s),{containerMeasurements:{containerRef:R,innerSize:w,outerSize:v},containerProps:D,dispatchColumnAction:S,draggable:P,draggedItemIndex:b,handleContextMenuAction:M,scrollProps:E,viewportMeasurements:x,...k}=qt({config:n,dataSource:o,renderBufferSize:d,headerHeight:r,height:i,onConfigChange:l,onFeatureEnabled:a,onFeatureInvocation:u,onSelectionChange:c,rowHeight:g,selectionModel:h,width:T}),J={...v,"--content-height":`${x.contentHeight}px`,"--horizontal-scrollbar-height":`${x.horizontalScrollbarHeight}px`,"--content-width":`${x.contentWidth}px`,"--pinned-width-left":`${x.pinnedWidthLeft}px`,"--pinned-width-right":`${x.pinnedWidthRight}px`,"--header-height":`${r}px`,"--row-height":`${g}px`,"--table-height":`${w==null?void 0:w.height}px`,"--table-width":`${w==null?void 0:w.width}px`,"--total-header-height":`${x.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${x.verticalScrollbarWidth}px`,"--viewport-body-height":`${x.viewportBodyHeight}px`},pe=ds(_,t,{[`${_}-zebra`]:y,[`${_}-loading`]:ps(k.columns)});return re(cs,{menuActionHandler:M,menuBuilder:Be(o),children:en("div",{...m,...D,className:pe,id:C,ref:R,style:J,tabIndex:-1,children:[w?re("div",{className:`${_}-scrollbarContainer`,ref:E.scrollbarContainerRef,children:re("div",{className:`${_}-scrollbarContent`})}):null,w?en("div",{className:`${_}-contentContainer`,ref:E.contentContainerRef,children:[re(ht,{...k,headerHeight:r,tableId:C}),P]}):null,e&&w?re(us,{className:`${_}-settings`,"data-icon":"settings",onClick:p,variant:"secondary"}):null]})})};import fs from"classnames";import{isJsonAttribute as gs,metadataKeys as bs,registerComponent as Cs}from"@vuu-ui/vuu-utils";import{jsx as Ve,jsxs as Ms}from"react/jsx-runtime";var se="vuuJsonCell",{IS_EXPANDED:hs,KEY:vs}=bs,ys=e=>{let t=e.lastIndexOf("|");return t===-1?"":e.slice(t+1)},ws=({column:e,row:t})=>{let{key:n}=e,o=t[n],r=!1;gs(o)&&(o=o.slice(0,-1),r=!0);let i=ys(t[vs]),s=fs({[`${se}-name`]:i===o,[`${se}-value`]:i!==o,[`${se}-group`]:r});if(r){let l=t[hs]?"minus-box":"plus-box";return Ms("span",{className:s,children:[Ve("span",{className:`${se}-value`,children:o}),Ve("span",{className:`${se}-toggle`,"data-icon":l})]})}else return o?Ve("span",{className:s,children:o}):null};Cs("json",ws,"cell-renderer",{});export{Ua as Table,Be as buildContextMenuDescriptors,kt as useMeasuredContainer,Xe as useTableContextMenu,Wt as useTableModel,_t as useTableViewport};
|
|
2886
2
|
//# sourceMappingURL=index.js.map
|