@vuu-ui/vuu-table 0.7.1-debug → 0.7.1

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