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

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/esm/index.js CHANGED
@@ -1,3554 +1,2 @@
1
- // src/header-cell/GroupHeaderCellNext.tsx
2
- import { OverflowContainer } from "@vuu-ui/vuu-layout";
3
- import { useLayoutEffectSkipFirst } from "@vuu-ui/vuu-utils";
4
- import cx3 from "clsx";
5
- import { useCallback as useCallback4, useRef as useRef3, useState as useState2 } from "react";
6
-
7
- // src/column-header-pill/ColumnHeaderPill.tsx
8
- import cx from "clsx";
9
- import { useCallback } from "react";
10
- import { jsx, jsxs } from "react/jsx-runtime";
11
- var classBase = "vuuColumnHeaderPill";
12
- var ColumnHeaderPill = ({
13
- children,
14
- className,
15
- column,
16
- onRemove,
17
- removable,
18
- ...htmlAttributes
19
- }) => {
20
- if (removable && typeof onRemove !== "function") {
21
- throw Error(
22
- "ColumnHeaderPill onRemove prop must be provided if Pill is removable"
23
- );
24
- }
25
- const handleClickRemove = useCallback(
26
- (evt) => {
27
- evt.preventDefault();
28
- evt.stopPropagation();
29
- onRemove == null ? void 0 : onRemove(column);
30
- },
31
- [column, onRemove]
32
- );
33
- return /* @__PURE__ */ jsxs("div", { ...htmlAttributes, className: cx(classBase, className), children: [
34
- children,
35
- removable ? /* @__PURE__ */ jsx(
36
- "span",
37
- {
38
- className: `${classBase}-removeButton`,
39
- role: "button",
40
- "data-icon": "cross",
41
- onClick: handleClickRemove
42
- }
43
- ) : null
44
- ] });
45
- };
46
-
47
- // src/column-header-pill/GroupColumnPill.tsx
48
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
49
- var GroupColumnPill = ({
50
- column,
51
- ...columnHeaderProps
52
- }) => {
53
- const { name, sorted } = column;
54
- const icon = typeof sorted === "number" ? sorted < 0 ? "arrow-down" : "arrow-up" : sorted === "A" ? "arrow-up" : sorted === "D" ? "arrow-down" : void 0;
55
- return /* @__PURE__ */ jsxs2(ColumnHeaderPill, { ...columnHeaderProps, column, children: [
56
- /* @__PURE__ */ jsx2("span", { className: "vuuGroupColumnPill-label", children: name }),
57
- icon !== void 0 ? /* @__PURE__ */ jsx2("span", { "data-icon": icon }) : null,
58
- typeof sorted === "number" ? /* @__PURE__ */ jsx2("span", { className: "vuuSortPosition", children: Math.abs(sorted) }) : null
59
- ] });
60
- };
61
-
62
- // src/column-header-pill/SortIndicator.tsx
63
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
64
- var SortIndicator = ({ column }) => {
65
- if (!column.sorted) {
66
- return null;
67
- }
68
- const icon = typeof column.sorted === "number" ? column.sorted < 0 ? "arrow-down" : "arrow-up" : column.sorted === "A" ? "arrow-up" : "arrow-down";
69
- return /* @__PURE__ */ jsxs3(ColumnHeaderPill, { column, children: [
70
- /* @__PURE__ */ jsx3("span", { "data-icon": icon }),
71
- typeof column.sorted === "number" ? /* @__PURE__ */ jsx3("span", { className: "vuuSortPosition", children: Math.abs(column.sorted) }) : null
72
- ] });
73
- };
74
-
75
- // src/column-resizing/ColumnResizer.tsx
76
- import { useCallback as useCallback2, useRef } from "react";
77
- import { jsx as jsx4 } from "react/jsx-runtime";
78
- var NOOP = () => void 0;
79
- var baseClass = "vuuColumnResizerNext";
80
- var ColumnResizer = ({
81
- onDrag,
82
- onDragEnd = NOOP,
83
- onDragStart = NOOP
84
- }) => {
85
- const position = useRef(0);
86
- const onMouseMove = useCallback2(
87
- (e) => {
88
- if (e.stopPropagation) {
89
- e.stopPropagation();
90
- }
91
- if (e.preventDefault) {
92
- e.preventDefault();
93
- }
94
- const x = Math.round(e.clientX);
95
- const moveBy = x - position.current;
96
- position.current = x;
97
- if (moveBy !== 0) {
98
- onDrag(e, moveBy);
99
- }
100
- },
101
- [onDrag]
102
- );
103
- const onMouseUp = useCallback2(
104
- (e) => {
105
- window.removeEventListener("mouseup", onMouseUp);
106
- window.removeEventListener("mousemove", onMouseMove);
107
- onDragEnd(e);
108
- },
109
- [onDragEnd, onMouseMove]
110
- );
111
- const handleMouseDown = useCallback2(
112
- (e) => {
113
- onDragStart(e);
114
- position.current = Math.round(e.clientX);
115
- window.addEventListener("mouseup", onMouseUp);
116
- window.addEventListener("mousemove", onMouseMove);
117
- if (e.stopPropagation) {
118
- e.stopPropagation();
119
- }
120
- if (e.preventDefault) {
121
- e.preventDefault();
122
- }
123
- },
124
- [onDragStart, onMouseMove, onMouseUp]
125
- );
126
- return /* @__PURE__ */ jsx4("div", { className: baseClass, onMouseDown: handleMouseDown });
127
- };
128
-
129
- // src/column-resizing/useTableColumnResize.tsx
130
- import { useCallback as useCallback3, useRef as useRef2, useState } from "react";
131
- var useTableColumnResize = ({
132
- column,
133
- onResize,
134
- rootRef
135
- }) => {
136
- const widthRef = useRef2(0);
137
- const [isResizing, setResizing] = useState(false);
138
- const { name } = column;
139
- const handleResizeStart = useCallback3(() => {
140
- if (onResize && rootRef.current) {
141
- const { width } = rootRef.current.getBoundingClientRect();
142
- widthRef.current = Math.round(width);
143
- setResizing(true);
144
- onResize == null ? void 0 : onResize("begin", name);
145
- }
146
- }, [name, onResize, rootRef]);
147
- const handleResize = useCallback3(
148
- (_evt, moveBy) => {
149
- if (rootRef.current) {
150
- if (onResize) {
151
- const { width } = rootRef.current.getBoundingClientRect();
152
- const newWidth = Math.round(width) + moveBy;
153
- if (newWidth !== widthRef.current && newWidth > 0) {
154
- onResize("resize", name, newWidth);
155
- widthRef.current = newWidth;
156
- }
157
- }
158
- }
159
- },
160
- [name, onResize, rootRef]
161
- );
162
- const handleResizeEnd = useCallback3(() => {
163
- if (onResize) {
164
- onResize("end", name, widthRef.current);
165
- setTimeout(() => {
166
- setResizing(false);
167
- }, 80);
168
- }
169
- }, [name, onResize]);
170
- return {
171
- isResizing,
172
- onDrag: handleResize,
173
- onDragStart: handleResizeStart,
174
- onDragEnd: handleResizeEnd
175
- };
176
- };
177
-
178
- // src/useCell.ts
179
- import { getColumnStyle } from "@vuu-ui/vuu-utils";
180
- import cx2 from "clsx";
181
- import { useMemo } from "react";
182
- var useCell = (column, classBase10, isHeader) => (
183
- // TODO measure perf without the memo, might not be worth the cost
184
- useMemo(() => {
185
- const className = cx2(classBase10, {
186
- vuuPinFloating: column.pin === "floating",
187
- vuuPinLeft: column.pin === "left",
188
- vuuPinRight: column.pin === "right",
189
- vuuEndPin: isHeader && column.endPin,
190
- // [`${classBase}-resizing`]: column.resizing,
191
- [`${classBase10}-editable`]: column.editable,
192
- [`${classBase10}-right`]: column.align === "right"
193
- });
194
- const style = getColumnStyle(column);
195
- return {
196
- className,
197
- style
198
- };
199
- }, [column, classBase10, isHeader])
200
- );
201
-
202
- // src/header-cell/GroupHeaderCellNext.tsx
203
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
204
- import { createElement } from "react";
205
- var classBase2 = "vuuTableGroupHeaderCell";
206
- var switchIfChanged = (columns, newColumns) => {
207
- if (columns === newColumns) {
208
- return columns;
209
- } else {
210
- return newColumns;
211
- }
212
- };
213
- var GroupHeaderCellNext = ({
214
- column: groupColumn,
215
- className: classNameProp,
216
- onMoveColumn,
217
- onRemoveColumn,
218
- onResize,
219
- ...htmlAttributes
220
- }) => {
221
- const rootRef = useRef3(null);
222
- const { isResizing, ...resizeProps } = useTableColumnResize({
223
- column: groupColumn,
224
- onResize,
225
- rootRef
226
- });
227
- const [columns, setColumns] = useState2(groupColumn.columns);
228
- const { className, style } = useCell(groupColumn, classBase2, true);
229
- const columnPillProps = columns.length > 1 ? {
230
- removable: true,
231
- onRemove: onRemoveColumn
232
- } : void 0;
233
- const handleMoveItem = useCallback4(
234
- (fromIndex, toIndex) => {
235
- setColumns((cols) => {
236
- const newCols = cols.slice();
237
- const [tab] = newCols.splice(fromIndex, 1);
238
- if (toIndex === -1) {
239
- const result = newCols.concat(tab);
240
- onMoveColumn == null ? void 0 : onMoveColumn(result);
241
- return result;
242
- } else {
243
- newCols.splice(toIndex, 0, tab);
244
- onMoveColumn == null ? void 0 : onMoveColumn(newCols);
245
- return newCols;
246
- }
247
- });
248
- },
249
- [onMoveColumn]
250
- );
251
- useLayoutEffectSkipFirst(() => {
252
- setColumns((cols) => switchIfChanged(cols, groupColumn.columns));
253
- }, [groupColumn.columns]);
254
- return /* @__PURE__ */ jsxs4(
255
- "div",
256
- {
257
- ...htmlAttributes,
258
- className: cx3(className, classNameProp, {
259
- [`${classBase2}-pending`]: groupColumn.groupConfirmed === false
260
- }),
261
- ref: rootRef,
262
- role: "columnheader",
263
- style,
264
- children: [
265
- /* @__PURE__ */ jsx5(
266
- OverflowContainer,
267
- {
268
- allowDragDrop: true,
269
- className: `${classBase2}-inner`,
270
- height: 24,
271
- onMoveItem: handleMoveItem,
272
- overflowPosition: "start",
273
- children: columns.map((column) => {
274
- return /* @__PURE__ */ createElement(
275
- GroupColumnPill,
276
- {
277
- ...columnPillProps,
278
- column,
279
- key: column.key
280
- }
281
- );
282
- })
283
- }
284
- ),
285
- /* @__PURE__ */ jsx5(
286
- ColumnHeaderPill,
287
- {
288
- column: groupColumn,
289
- removable: true,
290
- onRemove: onRemoveColumn
291
- }
292
- ),
293
- groupColumn.resizeable !== false ? /* @__PURE__ */ jsx5(ColumnResizer, { ...resizeProps }) : null
294
- ]
295
- }
296
- );
297
- };
298
-
299
- // src/header-cell/HeaderCell.tsx
300
- import cx5 from "clsx";
301
- import { useCallback as useCallback6, useRef as useRef5 } from "react";
302
-
303
- // src/column-menu/ColumnMenu.tsx
304
- import { useContextMenu } from "@vuu-ui/vuu-popups";
305
- import cx4 from "clsx";
306
- import {
307
- useCallback as useCallback5,
308
- useRef as useRef4,
309
- useState as useState3
310
- } from "react";
311
- import { jsx as jsx6 } from "react/jsx-runtime";
312
- var getPosition = (element) => {
313
- if (element) {
314
- const { bottom, left } = element.getBoundingClientRect();
315
- return { x: left, y: bottom + 6 };
316
- }
317
- };
318
- var ColumnMenu = ({
319
- className,
320
- column,
321
- ...props
322
- }) => {
323
- const rootRef = useRef4(null);
324
- const [menuOpen, setMenuOpen] = useState3(false);
325
- const [showContextMenu] = useContextMenu();
326
- const handleMenuClose = useCallback5(() => {
327
- setMenuOpen(false);
328
- }, []);
329
- const showColumnMenu = useCallback5(
330
- (e) => {
331
- setMenuOpen(true);
332
- showContextMenu(e, "column-menu", {
333
- column,
334
- ContextMenuProps: {
335
- onClose: handleMenuClose,
336
- position: getPosition(rootRef.current)
337
- }
338
- });
339
- },
340
- [column, handleMenuClose, showContextMenu]
341
- );
342
- return /* @__PURE__ */ jsx6(
343
- "span",
344
- {
345
- ...props,
346
- className: cx4("vuuTable-columnMenu", className, {
347
- "vuuTable-columnMenu-open": menuOpen
348
- }),
349
- "data-icon": "more-vert",
350
- onClick: showColumnMenu,
351
- ref: rootRef
352
- }
353
- );
354
- };
355
-
356
- // src/header-cell/HeaderCell.tsx
357
- import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
358
- var classBase3 = "vuuTableHeaderCell";
359
- var HeaderCell = ({
360
- className: classNameProp,
361
- column,
362
- onClick,
363
- onResize,
364
- ...htmlAttributes
365
- }) => {
366
- var _a;
367
- const { HeaderCellContentRenderer, HeaderCellLabelRenderer } = column;
368
- const rootRef = useRef5(null);
369
- const { isResizing, ...resizeProps } = useTableColumnResize({
370
- column,
371
- onResize,
372
- rootRef
373
- });
374
- const handleClick = useCallback6(
375
- (evt) => {
376
- !isResizing && (onClick == null ? void 0 : onClick(evt));
377
- },
378
- [isResizing, onClick]
379
- );
380
- const { className, style } = useCell(column, classBase3, true);
381
- const columnMenu = /* @__PURE__ */ jsx7(ColumnMenu, { column });
382
- const columnLabel = HeaderCellLabelRenderer ? /* @__PURE__ */ jsx7(HeaderCellLabelRenderer, { className: `${classBase3}-label`, column }) : /* @__PURE__ */ jsx7("div", { className: `${classBase3}-label`, children: (_a = column.label) != null ? _a : column.name });
383
- const columnContent = HeaderCellContentRenderer ? [/* @__PURE__ */ jsx7(HeaderCellContentRenderer, { column }, "content")] : [];
384
- const sortIndicator = /* @__PURE__ */ jsx7(SortIndicator, { column });
385
- const headerItems = column.align === "right" ? [sortIndicator, columnLabel].concat(columnContent).concat(columnMenu) : [columnMenu, columnLabel, sortIndicator].concat(columnContent);
386
- return /* @__PURE__ */ jsxs5(
387
- "div",
388
- {
389
- ...htmlAttributes,
390
- className: cx5(className, classNameProp, {
391
- [`${classBase3}-resizing`]: isResizing
392
- }),
393
- onClick: handleClick,
394
- ref: rootRef,
395
- role: "columnheader",
396
- style,
397
- children: [
398
- ...headerItems,
399
- column.resizeable !== false ? /* @__PURE__ */ jsx7(ColumnResizer, { ...resizeProps }) : null
400
- ]
401
- }
402
- );
403
- };
404
-
405
- // src/Table.tsx
406
- import {
407
- MeasuredContainer
408
- } from "@vuu-ui/vuu-layout";
409
- import { ContextMenuProvider } from "@vuu-ui/vuu-popups";
410
- import { metadataKeys as metadataKeys7, useId } from "@vuu-ui/vuu-utils";
411
- import { useForkRef } from "@salt-ds/core";
412
- import cx9 from "clsx";
413
- import {
414
- forwardRef,
415
- useRef as useRef15,
416
- useState as useState7
417
- } from "react";
418
-
419
- // src/Row.tsx
420
- import {
421
- isGroupColumn,
422
- isJsonColumn,
423
- isJsonGroup,
424
- metadataKeys as metadataKeys2,
425
- isNotHidden,
426
- RowSelected
427
- } from "@vuu-ui/vuu-utils";
428
- import cx7 from "clsx";
429
- import { memo, useCallback as useCallback9 } from "react";
430
-
431
- // src/table-cell/TableCell.tsx
432
- import { isNumericColumn } from "@vuu-ui/vuu-utils";
433
- import { useCallback as useCallback7 } from "react";
434
- import { jsx as jsx8 } from "react/jsx-runtime";
435
- var classBase4 = "vuuTableCell";
436
- var TableCell = ({
437
- column,
438
- columnMap,
439
- onClick,
440
- onDataEdited,
441
- row
442
- }) => {
443
- const { className, style } = useCell(column, classBase4);
444
- const { CellRenderer, name, valueFormatter } = column;
445
- const dataIdx = columnMap[name];
446
- const handleDataItemEdited = useCallback7(
447
- (value) => {
448
- if (onDataEdited) {
449
- let typedValue = value;
450
- if (isNumericColumn(column) && typeof value === "string") {
451
- typedValue = column.serverDataType === "double" ? parseFloat(value) : parseInt(value);
452
- }
453
- return onDataEdited == null ? void 0 : onDataEdited(row, name, typedValue);
454
- } else {
455
- throw Error(
456
- "TableCell onDataEdited prop not supplied for an editable cell"
457
- );
458
- }
459
- },
460
- [column, name, onDataEdited, row]
461
- );
462
- const handleClick = useCallback7(
463
- (evt) => {
464
- onClick == null ? void 0 : onClick(evt, column);
465
- },
466
- [column, onClick]
467
- );
468
- return /* @__PURE__ */ jsx8(
469
- "div",
470
- {
471
- className,
472
- onClick: onClick ? handleClick : void 0,
473
- role: "cell",
474
- style,
475
- children: CellRenderer ? /* @__PURE__ */ jsx8(
476
- CellRenderer,
477
- {
478
- column,
479
- columnMap,
480
- onCommit: handleDataItemEdited,
481
- row
482
- }
483
- ) : valueFormatter(row[dataIdx])
484
- }
485
- );
486
- };
487
-
488
- // src/table-cell/TableGroupCell.tsx
489
- import { getGroupValueAndOffset, metadataKeys } from "@vuu-ui/vuu-utils";
490
- import { useCallback as useCallback8 } from "react";
491
- import cx6 from "clsx";
492
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
493
- var { IS_LEAF } = metadataKeys;
494
- var classBase5 = "vuuTableGroupCell";
495
- var TableGroupCell = ({ column, onClick, row }) => {
496
- const { columns } = column;
497
- const [value, offset] = getGroupValueAndOffset(columns, row);
498
- const { className, style } = useCell(column, classBase5);
499
- const handleClick = useCallback8(
500
- (evt) => {
501
- onClick == null ? void 0 : onClick(evt, column);
502
- },
503
- [column, onClick]
504
- );
505
- const isLeaf = row[IS_LEAF];
506
- const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx9("span", { className: `${classBase5}-spacer` }, i));
507
- return /* @__PURE__ */ jsxs6(
508
- "div",
509
- {
510
- className: cx6(className, "vuuTableCell"),
511
- role: "cell",
512
- style,
513
- onClick: isLeaf ? void 0 : handleClick,
514
- children: [
515
- spacers,
516
- isLeaf ? null : /* @__PURE__ */ jsx9("span", { className: `${classBase5}-toggle`, "data-icon": "triangle-right" }),
517
- /* @__PURE__ */ jsx9("span", { children: value })
518
- ]
519
- }
520
- );
521
- };
522
-
523
- // src/Row.tsx
524
- import { jsx as jsx10 } from "react/jsx-runtime";
525
- import { createElement as createElement2 } from "react";
526
- var { IDX, IS_EXPANDED, SELECTED } = metadataKeys2;
527
- var classBase6 = "vuuTableRow";
528
- var Row = memo(
529
- ({
530
- className: classNameProp,
531
- columnMap,
532
- columns,
533
- highlighted,
534
- row,
535
- offset,
536
- onClick,
537
- onDataEdited,
538
- onToggleGroup,
539
- zebraStripes = false,
540
- ...htmlAttributes
541
- }) => {
542
- const {
543
- [IDX]: rowIndex,
544
- [IS_EXPANDED]: isExpanded,
545
- [SELECTED]: selectionStatus
546
- } = row;
547
- const handleRowClick = useCallback9(
548
- (evt) => {
549
- const rangeSelect = evt.shiftKey;
550
- const keepExistingSelection = evt.ctrlKey || evt.metaKey;
551
- onClick == null ? void 0 : onClick(row, rangeSelect, keepExistingSelection);
552
- },
553
- [onClick, row]
554
- );
555
- const { True, First, Last } = RowSelected;
556
- const className = cx7(classBase6, classNameProp, {
557
- [`${classBase6}-even`]: zebraStripes && rowIndex % 2 === 0,
558
- [`${classBase6}-expanded`]: isExpanded,
559
- [`${classBase6}-highlighted`]: highlighted,
560
- [`${classBase6}-selected`]: selectionStatus & True,
561
- [`${classBase6}-selectedStart`]: selectionStatus & First,
562
- [`${classBase6}-selectedEnd`]: selectionStatus & Last
563
- });
564
- const style = { transform: `translate3d(0px, ${offset}px, 0px)` };
565
- const handleGroupCellClick = useCallback9(
566
- (evt, column) => {
567
- if (isGroupColumn(column) || isJsonGroup(column, row)) {
568
- evt.stopPropagation();
569
- onToggleGroup == null ? void 0 : onToggleGroup(row, column);
570
- }
571
- },
572
- [onToggleGroup, row]
573
- );
574
- return /* @__PURE__ */ createElement2(
575
- "div",
576
- {
577
- ...htmlAttributes,
578
- "aria-rowindex": row[0] + 1,
579
- key: `row-${row[0]}`,
580
- role: "row",
581
- className,
582
- onClick: handleRowClick,
583
- style
584
- },
585
- /* @__PURE__ */ jsx10("span", { className: `${classBase6}-selectionDecorator vuuStickyLeft` }),
586
- columns.filter(isNotHidden).map((column) => {
587
- const isGroup = isGroupColumn(column);
588
- const isJsonCell = isJsonColumn(column);
589
- const Cell = isGroup ? TableGroupCell : TableCell;
590
- return /* @__PURE__ */ jsx10(
591
- Cell,
592
- {
593
- column,
594
- columnMap,
595
- onClick: isGroup || isJsonCell ? handleGroupCellClick : void 0,
596
- onDataEdited,
597
- row
598
- },
599
- column.key
600
- );
601
- }),
602
- /* @__PURE__ */ jsx10("span", { className: `${classBase6}-selectionDecorator vuuStickyRight` })
603
- );
604
- }
605
- );
606
- Row.displayName = "Row";
607
-
608
- // src/useTable.ts
609
- import {
610
- useDragDropNext as useDragDrop
611
- } from "@vuu-ui/vuu-ui-controls";
612
- import {
613
- applySort,
614
- buildColumnMap as buildColumnMap2,
615
- getIndexFromRowElement as getIndexFromRowElement2,
616
- isGroupColumn as isGroupColumn3,
617
- isJsonGroup as isJsonGroup2,
618
- isValidNumber,
619
- metadataKeys as metadataKeys6,
620
- updateColumn,
621
- useLayoutEffectSkipFirst as useLayoutEffectSkipFirst2
622
- } from "@vuu-ui/vuu-utils";
623
- import {
624
- useCallback as useCallback19,
625
- useEffect as useEffect4,
626
- useMemo as useMemo5,
627
- useState as useState6
628
- } from "react";
629
-
630
- // src/context-menu/buildContextMenuDescriptors.ts
631
- import { isNumericColumn as isNumericColumn2 } from "@vuu-ui/vuu-utils";
632
- var buildContextMenuDescriptors = (dataSource) => (location, options) => {
633
- const descriptors = [];
634
- if (dataSource === void 0) {
635
- return descriptors;
636
- }
637
- if (location === "header" || location === "column-menu") {
638
- descriptors.push(
639
- ...buildSortMenuItems(options, dataSource)
640
- );
641
- descriptors.push(
642
- ...buildGroupMenuItems(options, dataSource)
643
- );
644
- descriptors.push(
645
- ...buildAggregationMenuItems(options, dataSource)
646
- );
647
- descriptors.push(...buildColumnDisplayMenuItems(options));
648
- descriptors.push({
649
- action: "column-settings",
650
- icon: "cog",
651
- label: `Column Settings`,
652
- options
653
- });
654
- descriptors.push({
655
- action: "table-settings",
656
- icon: "cog",
657
- label: `DataGrid Settings`,
658
- options
659
- });
660
- }
661
- return descriptors;
662
- };
663
- function buildSortMenuItems(options, { sort: { sortDefs } }) {
664
- const { column } = options;
665
- const menuItems = [];
666
- if (column === void 0) {
667
- return menuItems;
668
- }
669
- const hasSort = sortDefs.length > 0;
670
- if (column.sorted === "A") {
671
- menuItems.push({
672
- label: "Reverse Sort (DSC)",
673
- action: "sort-dsc",
674
- options
675
- });
676
- } else if (column.sorted === "D") {
677
- menuItems.push({
678
- label: "Reverse Sort (ASC)",
679
- action: "sort-asc",
680
- options
681
- });
682
- } else if (typeof column.sorted === "number") {
683
- if (column.sorted > 0) {
684
- menuItems.push({
685
- label: "Reverse Sort (DSC)",
686
- action: "sort-add-dsc",
687
- options
688
- });
689
- } else {
690
- menuItems.push({
691
- label: "Reverse Sort (ASC)",
692
- action: "sort-add-asc",
693
- options
694
- });
695
- }
696
- if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
697
- menuItems.push({
698
- label: "Remove from sort",
699
- action: "sort-remove",
700
- options
701
- });
702
- }
703
- menuItems.push({
704
- label: "New Sort",
705
- children: [
706
- { label: "Ascending", action: "sort-asc", options },
707
- { label: "Descending", action: "sort-dsc", options }
708
- ]
709
- });
710
- } else if (hasSort) {
711
- menuItems.push({
712
- label: "Add to sort",
713
- children: [
714
- { label: "Ascending", action: "sort-add-asc", options },
715
- { label: "Descending", action: "sort-add-dsc", options }
716
- ]
717
- });
718
- menuItems.push({
719
- label: "New Sort",
720
- children: [
721
- { label: "Ascending", action: "sort-asc", options },
722
- { label: "Descending", action: "sort-dsc", options }
723
- ]
724
- });
725
- } else {
726
- menuItems.push({
727
- label: "Sort",
728
- children: [
729
- { label: "Ascending", action: "sort-asc", options },
730
- { label: "Descending", action: "sort-dsc", options }
731
- ]
732
- });
733
- }
734
- return menuItems;
735
- }
736
- function buildAggregationMenuItems(options, dataSource) {
737
- const { column } = options;
738
- if (column === void 0 || dataSource.groupBy.length === 0) {
739
- return [];
740
- }
741
- const { name, label = name } = column;
742
- return [
743
- {
744
- label: `Aggregate ${label}`,
745
- children: [
746
- { label: "Count", action: "agg-count", options },
747
- { label: "Distinct", action: "agg-distinct", options }
748
- ].concat(
749
- isNumericColumn2(column) ? [
750
- { label: "Sum", action: "agg-sum", options },
751
- { label: "Avg", action: "agg-avg", options },
752
- { label: "High", action: "agg-high", options },
753
- { label: "Low", action: "agg-low", options }
754
- ] : []
755
- )
756
- }
757
- ];
758
- }
759
- var pinColumn = (options, pinLocation) => ({
760
- label: `Pin ${pinLocation}`,
761
- action: `column-pin-${pinLocation}`,
762
- options
763
- });
764
- var pinLeft = (options) => pinColumn(options, "left");
765
- var pinFloating = (options) => pinColumn(options, "floating");
766
- var pinRight = (options) => pinColumn(options, "right");
767
- function buildColumnDisplayMenuItems(options) {
768
- const { column } = options;
769
- if (column === void 0) {
770
- return [];
771
- }
772
- const { pin } = column;
773
- const menuItems = [
774
- {
775
- label: `Hide column`,
776
- action: "column-hide",
777
- options
778
- },
779
- {
780
- label: `Remove column`,
781
- action: "column-remove",
782
- options
783
- }
784
- ];
785
- if (pin === void 0) {
786
- menuItems.push({
787
- label: `Pin column`,
788
- children: [pinLeft(options), pinFloating(options), pinRight(options)]
789
- });
790
- } else if (pin === "left") {
791
- menuItems.push(
792
- { label: "Unpin column", action: "column-unpin", options },
793
- {
794
- label: `Pin column`,
795
- children: [pinFloating(options), pinRight(options)]
796
- }
797
- );
798
- } else if (pin === "right") {
799
- menuItems.push(
800
- { label: "Unpin column", action: "column-unpin", options },
801
- {
802
- label: `Pin column`,
803
- children: [pinLeft(options), pinFloating(options)]
804
- }
805
- );
806
- } else if (pin === "floating") {
807
- menuItems.push(
808
- { label: "Unpin column", action: "column-unpin", options },
809
- {
810
- label: `Pin column`,
811
- children: [pinLeft(options), pinRight(options)]
812
- }
813
- );
814
- }
815
- return menuItems;
816
- }
817
- function buildGroupMenuItems(options, { groupBy }) {
818
- const { column } = options;
819
- const menuItems = [];
820
- if (column === void 0) {
821
- return menuItems;
822
- }
823
- const { name, label = name } = column;
824
- if (groupBy.length === 0) {
825
- menuItems.push({
826
- label: `Group by ${label}`,
827
- action: "group",
828
- options
829
- });
830
- } else {
831
- menuItems.push({
832
- label: `Add ${label} to group by`,
833
- action: "group-add",
834
- options
835
- });
836
- }
837
- return menuItems;
838
- }
839
-
840
- // src/context-menu/useHandleTableContextMenu.ts
841
- import { removeColumnFromFilter } from "@vuu-ui/vuu-utils";
842
- import {
843
- addGroupColumn,
844
- addSortColumn,
845
- AggregationType,
846
- setAggregations,
847
- setSortColumn
848
- } from "@vuu-ui/vuu-utils";
849
- var removeFilterColumn = (dataSourceFilter, column) => {
850
- if (dataSourceFilter.filterStruct && column) {
851
- const [filterStruct, filter] = removeColumnFromFilter(
852
- column,
853
- dataSourceFilter.filterStruct
854
- );
855
- return {
856
- filter,
857
- filterStruct
858
- };
859
- } else {
860
- return dataSourceFilter;
861
- }
862
- };
863
- var { Average, Count, Distinct, High, Low, Sum } = AggregationType;
864
- var useHandleTableContextMenu = ({
865
- dataSource,
866
- onPersistentColumnOperation
867
- }) => {
868
- const handleContextMenuAction = (action) => {
869
- const gridOptions = action.options;
870
- if (gridOptions.column && dataSource) {
871
- const { column } = gridOptions;
872
- switch (action.menuId) {
873
- case "sort-asc":
874
- return dataSource.sort = setSortColumn(dataSource.sort, column, "A"), true;
875
- case "sort-dsc":
876
- return dataSource.sort = setSortColumn(dataSource.sort, column, "D"), true;
877
- case "sort-add-asc":
878
- return dataSource.sort = addSortColumn(dataSource.sort, column, "A"), true;
879
- case "sort-add-dsc":
880
- return dataSource.sort = addSortColumn(dataSource.sort, column, "D"), true;
881
- case "group":
882
- return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
883
- case "group-add":
884
- return dataSource.groupBy = addGroupColumn(dataSource.groupBy, column), true;
885
- case "column-hide":
886
- return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
887
- case "column-remove":
888
- return dataSource.columns = dataSource.columns.filter((name) => name !== column.name), true;
889
- case "filter-remove-column":
890
- return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
891
- case "remove-filters":
892
- return dataSource.filter = { filter: "" }, true;
893
- case "agg-avg":
894
- return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Average), true;
895
- case "agg-high":
896
- return dataSource.aggregations = setAggregations(dataSource.aggregations, column, High), true;
897
- case "agg-low":
898
- return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Low), true;
899
- case "agg-count":
900
- return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Count), true;
901
- case "agg-distinct":
902
- return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Distinct), true;
903
- case "agg-sum":
904
- return dataSource.aggregations = setAggregations(dataSource.aggregations, column, Sum), true;
905
- case "column-pin-floating":
906
- return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
907
- case "column-pin-left":
908
- return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
909
- case "column-pin-right":
910
- return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
911
- case "column-unpin":
912
- return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
913
- case "column-settings":
914
- return onPersistentColumnOperation({ type: "columnSettings", column }), true;
915
- case "table-settings":
916
- return onPersistentColumnOperation({ type: "tableSettings" }), true;
917
- default:
918
- }
919
- }
920
- return false;
921
- };
922
- return handleContextMenuAction;
923
- };
924
-
925
- // src/table-config.ts
926
- var updateTableConfig = (config, action) => {
927
- switch (action.type) {
928
- case "col-size":
929
- return {
930
- ...config,
931
- columns: config.columns.map(
932
- (col) => col.name === action.column.name ? { ...col, width: action.width } : col
933
- )
934
- };
935
- case "column-prop":
936
- return {
937
- ...config,
938
- columns: config.columns.map(
939
- (col) => col.name === action.column.name ? { ...col, [action.property]: action.value } : col
940
- )
941
- };
942
- default:
943
- return config;
944
- }
945
- };
946
-
947
- // src/useCellEditing.ts
948
- import { isCharacterKey } from "@vuu-ui/vuu-utils";
949
- import {
950
- useCallback as useCallback10
951
- } from "react";
952
-
953
- // src/table-dom-utils.ts
954
- var headerCellQuery = (colIdx) => `.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${colIdx})`;
955
- var dataCellQuery = (rowIdx, colIdx) => `.vuuTable-body > [aria-rowindex='${rowIdx}'] > [role='cell']:nth-child(${colIdx + 1})`;
956
- var getTableCell = (containerRef, [rowIdx, colIdx]) => {
957
- var _a;
958
- const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
959
- const cell = (_a = containerRef.current) == null ? void 0 : _a.querySelector(
960
- cssQuery
961
- );
962
- if (cellIsEditable(cell)) {
963
- const focusableContent = cell.querySelector("button");
964
- return focusableContent || cell;
965
- } else {
966
- return cell;
967
- }
968
- };
969
- var cellIsEditable = (cell) => cell.classList.contains("vuuTableCell-editable");
970
- var cellIsTextInput = (cell) => cell.querySelector(".vuuTableInputCell") !== null;
971
- function getRowIndex(rowEl) {
972
- if (rowEl) {
973
- const idx = rowEl.ariaRowIndex;
974
- if (idx !== null) {
975
- return parseInt(idx, 10) - 1;
976
- }
977
- }
978
- return -1;
979
- }
980
- var closestRow = (el) => el.closest('[role="row"]');
981
- var closestRowIndex = (el) => getRowIndex(closestRow(el));
982
-
983
- // src/useCellEditing.ts
984
- var useCellEditing = ({ navigate }) => {
985
- const commitHandler = useCallback10(() => {
986
- navigate();
987
- }, [navigate]);
988
- const editInput = useCallback10(
989
- (evt) => {
990
- const cellEl = evt.target;
991
- const input = cellEl.matches("input") ? cellEl : cellEl.querySelector("input");
992
- if (input) {
993
- input.focus();
994
- input.select();
995
- }
996
- },
997
- []
998
- );
999
- const focusInput = useCallback10(
1000
- (evt) => {
1001
- const cellEl = evt.target;
1002
- const input = cellEl.querySelector("input");
1003
- if (input) {
1004
- input.focus();
1005
- input.select();
1006
- }
1007
- },
1008
- []
1009
- );
1010
- const handleKeyDown = useCallback10(
1011
- (e) => {
1012
- const el = e.target;
1013
- if (cellIsTextInput(el)) {
1014
- if (isCharacterKey(e.key)) {
1015
- editInput(e);
1016
- } else if (e.key === "Enter") {
1017
- focusInput(e);
1018
- }
1019
- }
1020
- },
1021
- [editInput, focusInput]
1022
- );
1023
- const handleDoubleClick = useCallback10(
1024
- (e) => {
1025
- const el = e.target;
1026
- if (el.matches("input") || el.querySelector("input")) {
1027
- editInput(e);
1028
- e.stopPropagation();
1029
- }
1030
- },
1031
- [editInput]
1032
- );
1033
- const handleBlur = useCallback10(
1034
- (e) => {
1035
- const el = e.target;
1036
- el.removeEventListener("vuu-commit", commitHandler, true);
1037
- },
1038
- [commitHandler]
1039
- );
1040
- const handleFocus = useCallback10(
1041
- (e) => {
1042
- const el = e.target;
1043
- el.addEventListener("vuu-commit", commitHandler, true);
1044
- },
1045
- [commitHandler]
1046
- );
1047
- return {
1048
- onBlur: handleBlur,
1049
- onDoubleClick: handleDoubleClick,
1050
- onFocus: handleFocus,
1051
- onKeyDown: handleKeyDown
1052
- };
1053
- };
1054
-
1055
- // src/useDataSource.ts
1056
- import { getFullRange, NULL_RANGE } from "@vuu-ui/vuu-utils";
1057
- import { useCallback as useCallback11, useEffect, useMemo as useMemo2, useRef as useRef6, useState as useState4 } from "react";
1058
-
1059
- // src/moving-window.ts
1060
- import {
1061
- isRowSelectedLast,
1062
- metadataKeys as metadataKeys3,
1063
- WindowRange
1064
- } from "@vuu-ui/vuu-utils";
1065
- var { SELECTED: SELECTED2 } = metadataKeys3;
1066
- var MovingWindow = class {
1067
- constructor({ from, to }) {
1068
- this.rowCount = 0;
1069
- this.setRowCount = (rowCount) => {
1070
- if (rowCount < this.data.length) {
1071
- this.data.length = rowCount;
1072
- }
1073
- this.rowCount = rowCount;
1074
- };
1075
- this.range = new WindowRange(from, to);
1076
- this.data = new Array(Math.max(0, to - from));
1077
- this.rowCount = 0;
1078
- }
1079
- add(data) {
1080
- const [index] = data;
1081
- if (this.isWithinRange(index)) {
1082
- const internalIndex = index - this.range.from;
1083
- this.data[internalIndex] = data;
1084
- if (data[SELECTED2]) {
1085
- const previousRow = this.data[internalIndex - 1];
1086
- if (isRowSelectedLast(previousRow)) {
1087
- this.data[internalIndex - 1] = previousRow.slice();
1088
- this.data[internalIndex - 1][SELECTED2] -= 4;
1089
- }
1090
- }
1091
- }
1092
- }
1093
- getAtIndex(index) {
1094
- return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
1095
- }
1096
- isWithinRange(index) {
1097
- return this.range.isWithin(index);
1098
- }
1099
- setRange({ from, to }) {
1100
- if (from !== this.range.from || to !== this.range.to) {
1101
- const [overlapFrom, overlapTo] = this.range.overlap(from, to);
1102
- const newData = new Array(Math.max(0, to - from));
1103
- for (let i = overlapFrom; i < overlapTo; i++) {
1104
- const data = this.getAtIndex(i);
1105
- if (data) {
1106
- const index = i - from;
1107
- newData[index] = data;
1108
- }
1109
- }
1110
- this.data = newData;
1111
- this.range.from = from;
1112
- this.range.to = to;
1113
- }
1114
- }
1115
- getSelectedRows() {
1116
- return this.data.filter((row) => row[SELECTED2] !== 0);
1117
- }
1118
- };
1119
-
1120
- // src/useDataSource.ts
1121
- var isVuuFeatureInvocation = (action) => action.type === "vuu-link-created" || action.type === "vuu-link-removed";
1122
- var useDataSource = ({
1123
- dataSource,
1124
- onFeatureInvocation,
1125
- onSizeChange,
1126
- onSubscribed,
1127
- range = NULL_RANGE,
1128
- renderBufferSize = 0
1129
- }) => {
1130
- const [, forceUpdate] = useState4(null);
1131
- const data = useRef6([]);
1132
- const isMounted = useRef6(true);
1133
- const hasUpdated = useRef6(false);
1134
- const rangeRef = useRef6(NULL_RANGE);
1135
- const dataWindow = useMemo2(
1136
- () => new MovingWindow(getFullRange(range, renderBufferSize)),
1137
- // eslint-disable-next-line react-hooks/exhaustive-deps
1138
- []
1139
- );
1140
- const setData = useCallback11(
1141
- (updates) => {
1142
- for (const row of updates) {
1143
- dataWindow.add(row);
1144
- }
1145
- data.current = dataWindow.data;
1146
- if (isMounted.current) {
1147
- forceUpdate({});
1148
- } else {
1149
- console.log(`ignore update as we're not mounted`);
1150
- }
1151
- },
1152
- [dataWindow]
1153
- );
1154
- const datasourceMessageHandler = useCallback11(
1155
- (message) => {
1156
- if (message.type === "subscribed") {
1157
- onSubscribed == null ? void 0 : onSubscribed(message);
1158
- } else if (message.type === "viewport-update") {
1159
- if (typeof message.size === "number") {
1160
- onSizeChange == null ? void 0 : onSizeChange(message.size);
1161
- dataWindow.setRowCount(message.size);
1162
- }
1163
- if (message.rows) {
1164
- setData(message.rows);
1165
- } else if (typeof message.size === "number") {
1166
- data.current = dataWindow.data;
1167
- hasUpdated.current = true;
1168
- }
1169
- } else if (isVuuFeatureInvocation(message)) {
1170
- onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
1171
- } else {
1172
- console.log(`useDataSource unexpected message ${message.type}`);
1173
- }
1174
- },
1175
- [dataWindow, onFeatureInvocation, onSizeChange, onSubscribed, setData]
1176
- );
1177
- const getSelectedRows = useCallback11(() => {
1178
- return dataWindow.getSelectedRows();
1179
- }, [dataWindow]);
1180
- useEffect(() => {
1181
- var _a;
1182
- isMounted.current = true;
1183
- (_a = dataSource.resume) == null ? void 0 : _a.call(dataSource);
1184
- return () => {
1185
- var _a2;
1186
- isMounted.current = false;
1187
- (_a2 = dataSource.suspend) == null ? void 0 : _a2.call(dataSource);
1188
- };
1189
- }, [dataSource]);
1190
- useEffect(() => {
1191
- var _a;
1192
- if (dataSource.status === "disabled") {
1193
- (_a = dataSource.enable) == null ? void 0 : _a.call(dataSource, datasourceMessageHandler);
1194
- } else {
1195
- dataSource == null ? void 0 : dataSource.subscribe(
1196
- { range: getFullRange(range, renderBufferSize) },
1197
- datasourceMessageHandler
1198
- );
1199
- }
1200
- }, [dataSource, datasourceMessageHandler, range, renderBufferSize]);
1201
- const setRange = useCallback11(
1202
- (range2) => {
1203
- const fullRange = getFullRange(range2, renderBufferSize);
1204
- dataWindow.setRange(fullRange);
1205
- dataSource.range = rangeRef.current = fullRange;
1206
- dataSource.emit("range", range2);
1207
- },
1208
- [dataSource, dataWindow, renderBufferSize]
1209
- );
1210
- return {
1211
- data: data.current,
1212
- dataRef: data,
1213
- getSelectedRows,
1214
- range: rangeRef.current,
1215
- setRange
1216
- };
1217
- };
1218
-
1219
- // src/useInitialValue.ts
1220
- import { useMemo as useMemo3, useRef as useRef7 } from "react";
1221
- var useInitialValue = (value) => {
1222
- const ref = useRef7(value);
1223
- return useMemo3(() => ref.current, []);
1224
- };
1225
-
1226
- // src/useKeyboardNavigation.ts
1227
- import { useControlled } from "@salt-ds/core";
1228
- import {
1229
- useCallback as useCallback12,
1230
- useEffect as useEffect2,
1231
- useRef as useRef8
1232
- } from "react";
1233
- var rowNavigationKeys = /* @__PURE__ */ new Set([
1234
- "Home",
1235
- "End",
1236
- "PageUp",
1237
- "PageDown",
1238
- "ArrowDown",
1239
- "ArrowUp"
1240
- ]);
1241
- var cellNavigationKeys = new Set(rowNavigationKeys);
1242
- cellNavigationKeys.add("ArrowLeft");
1243
- cellNavigationKeys.add("ArrowRight");
1244
- var isNavigationKey = (key, navigationStyle) => {
1245
- switch (navigationStyle) {
1246
- case "cell":
1247
- return cellNavigationKeys.has(key);
1248
- case "row":
1249
- return rowNavigationKeys.has(key);
1250
- default:
1251
- return false;
1252
- }
1253
- };
1254
- var PageKeys = ["Home", "End", "PageUp", "PageDown"];
1255
- var isPagingKey = (key) => PageKeys.includes(key);
1256
- var NULL_CELL_POS = [-1, -1];
1257
- var NO_SCROLL_NECESSARY = [void 0, void 0];
1258
- var howFarIsRowOutsideViewport = (rowEl, contentContainer = rowEl.closest(".vuuTable-contentContainer")) => {
1259
- if (contentContainer) {
1260
- const viewport = contentContainer == null ? void 0 : contentContainer.getBoundingClientRect();
1261
- const row = rowEl.getBoundingClientRect();
1262
- if (row) {
1263
- if (row.bottom > viewport.bottom) {
1264
- return ["down", row.bottom - viewport.bottom];
1265
- } else if (row.top < viewport.top) {
1266
- return ["up", row.top - viewport.top];
1267
- } else {
1268
- return NO_SCROLL_NECESSARY;
1269
- }
1270
- } else {
1271
- throw Error("Whats going on, row not found");
1272
- }
1273
- } else {
1274
- throw Error("Whats going on, scrollbar container not found");
1275
- }
1276
- };
1277
- var howFarIsCellOutsideViewport = (cellEl) => {
1278
- var _a;
1279
- const contentContainer = cellEl.closest(".vuuTable-contentContainer");
1280
- if (contentContainer) {
1281
- const rowEl = cellEl.closest(".vuuTableRow");
1282
- if (rowEl) {
1283
- const result = howFarIsRowOutsideViewport(rowEl, contentContainer);
1284
- if (result !== NO_SCROLL_NECESSARY) {
1285
- return result;
1286
- }
1287
- const viewport = contentContainer == null ? void 0 : contentContainer.getBoundingClientRect();
1288
- const cell = (_a = cellEl.closest(".vuuTableCell")) == null ? void 0 : _a.getBoundingClientRect();
1289
- if (cell) {
1290
- if (cell.right > viewport.right) {
1291
- return ["right", cell.right + 6 - viewport.right];
1292
- } else if (cell.left < viewport.left) {
1293
- return ["left", cell.left - viewport.left];
1294
- }
1295
- } else {
1296
- throw Error("Whats going on, cell not found");
1297
- }
1298
- }
1299
- }
1300
- return NO_SCROLL_NECESSARY;
1301
- };
1302
- function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
1303
- if (key === "ArrowUp") {
1304
- if (rowIdx > -1) {
1305
- return [rowIdx - 1, colIdx];
1306
- } else {
1307
- return [rowIdx, colIdx];
1308
- }
1309
- } else if (key === "ArrowDown") {
1310
- if (rowIdx === -1) {
1311
- return [0, colIdx];
1312
- } else if (rowIdx === rowCount - 1) {
1313
- return [rowIdx, colIdx];
1314
- } else {
1315
- return [rowIdx + 1, colIdx];
1316
- }
1317
- } else if (key === "ArrowRight") {
1318
- if (colIdx < columnCount) {
1319
- return [rowIdx, colIdx + 1];
1320
- } else {
1321
- return [rowIdx, colIdx];
1322
- }
1323
- } else if (key === "ArrowLeft") {
1324
- if (colIdx > 1) {
1325
- return [rowIdx, colIdx - 1];
1326
- } else {
1327
- return [rowIdx, colIdx];
1328
- }
1329
- }
1330
- return [rowIdx, colIdx];
1331
- }
1332
- var useKeyboardNavigation = ({
1333
- columnCount = 0,
1334
- containerRef,
1335
- disableFocus = false,
1336
- defaultHighlightedIndex,
1337
- disableHighlightOnFocus,
1338
- highlightedIndex: highlightedIndexProp,
1339
- navigationStyle,
1340
- requestScroll,
1341
- onHighlight,
1342
- rowCount = 0,
1343
- viewportRowCount
1344
- }) => {
1345
- var _a;
1346
- const focusedCellPos = useRef8([-1, -1]);
1347
- const focusableCell = useRef8();
1348
- const activeCellPos = useRef8([-1, 0]);
1349
- const highlightedIndexRef = useRef8();
1350
- const [highlightedIndex, setHighlightedIdx] = useControlled({
1351
- controlled: highlightedIndexProp,
1352
- default: defaultHighlightedIndex,
1353
- name: "UseKeyboardNavigation"
1354
- });
1355
- highlightedIndexRef.current = highlightedIndex;
1356
- const setHighlightedIndex = useCallback12(
1357
- (idx, fromKeyboard = false) => {
1358
- onHighlight == null ? void 0 : onHighlight(idx);
1359
- setHighlightedIdx(idx);
1360
- if (fromKeyboard) {
1361
- }
1362
- },
1363
- [onHighlight, setHighlightedIdx]
1364
- );
1365
- const getFocusedCell = (element) => element == null ? void 0 : element.closest(
1366
- "[role='columnHeader'],[role='cell']"
1367
- );
1368
- const getTableCellPos = (tableCell) => {
1369
- var _a2, _b;
1370
- if (tableCell.role === "columnHeader") {
1371
- const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
1372
- return [-1, colIdx];
1373
- } else {
1374
- const focusedRow = tableCell.closest("[role='row']");
1375
- if (focusedRow) {
1376
- const rowIdx = parseInt((_b = focusedRow.ariaRowIndex) != null ? _b : "-1", 10);
1377
- const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
1378
- return [rowIdx, colIdx];
1379
- }
1380
- }
1381
- return NULL_CELL_POS;
1382
- };
1383
- const focusCell = useCallback12(
1384
- (cellPos) => {
1385
- var _a2;
1386
- if (containerRef.current) {
1387
- const activeCell = getTableCell(containerRef, cellPos);
1388
- if (activeCell) {
1389
- if (activeCell !== focusableCell.current) {
1390
- (_a2 = focusableCell.current) == null ? void 0 : _a2.removeAttribute("tabindex");
1391
- focusableCell.current = activeCell;
1392
- activeCell.setAttribute("tabindex", "0");
1393
- }
1394
- const [direction, distance] = howFarIsCellOutsideViewport(activeCell);
1395
- if (direction && distance) {
1396
- requestScroll == null ? void 0 : requestScroll({ type: "scroll-distance", distance, direction });
1397
- }
1398
- console.log(`activeCell focus`);
1399
- activeCell.focus({ preventScroll: true });
1400
- }
1401
- }
1402
- },
1403
- // TODO we recreate this function whenever viewportRange changes, which will
1404
- // be often whilst scrolling - store range in a a ref ?
1405
- [containerRef, requestScroll]
1406
- );
1407
- const setActiveCell = useCallback12(
1408
- (rowIdx, colIdx, fromKeyboard = false) => {
1409
- const pos = [rowIdx, colIdx];
1410
- activeCellPos.current = pos;
1411
- if (navigationStyle === "row") {
1412
- setHighlightedIdx(rowIdx);
1413
- } else {
1414
- focusCell(pos);
1415
- }
1416
- if (fromKeyboard) {
1417
- focusedCellPos.current = pos;
1418
- }
1419
- },
1420
- [focusCell, navigationStyle, setHighlightedIdx]
1421
- );
1422
- const nextPageItemIdx = useCallback12(
1423
- (key, [rowIdx, colIdx]) => new Promise((resolve) => {
1424
- let newRowIdx = rowIdx;
1425
- switch (key) {
1426
- case "PageDown":
1427
- newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);
1428
- requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
1429
- break;
1430
- case "PageUp":
1431
- newRowIdx = Math.max(0, rowIdx - viewportRowCount);
1432
- requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
1433
- break;
1434
- case "Home":
1435
- newRowIdx = 0;
1436
- requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
1437
- break;
1438
- case "End":
1439
- newRowIdx = rowCount - 1;
1440
- requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
1441
- break;
1442
- }
1443
- setTimeout(() => {
1444
- resolve([newRowIdx, colIdx]);
1445
- }, 90);
1446
- }),
1447
- [requestScroll, rowCount, viewportRowCount]
1448
- );
1449
- const handleFocus = useCallback12(() => {
1450
- var _a2;
1451
- if (disableHighlightOnFocus !== true) {
1452
- if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
1453
- const focusedCell = getFocusedCell(document.activeElement);
1454
- if (focusedCell) {
1455
- focusedCellPos.current = getTableCellPos(focusedCell);
1456
- if (navigationStyle === "row") {
1457
- setHighlightedIdx(focusedCellPos.current[0]);
1458
- }
1459
- }
1460
- }
1461
- }
1462
- }, [
1463
- disableHighlightOnFocus,
1464
- containerRef,
1465
- navigationStyle,
1466
- setHighlightedIdx
1467
- ]);
1468
- const navigateChildItems = useCallback12(
1469
- async (key) => {
1470
- const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
1471
- const [rowIdx, colIdx] = activeCellPos.current;
1472
- if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
1473
- setActiveCell(nextRowIdx, nextColIdx, true);
1474
- }
1475
- },
1476
- [columnCount, nextPageItemIdx, rowCount, setActiveCell]
1477
- );
1478
- const scrollRowIntoViewIfNecessary = useCallback12(
1479
- (rowIndex) => {
1480
- const { current: container } = containerRef;
1481
- const activeRow = container == null ? void 0 : container.querySelector(
1482
- `[aria-rowindex="${rowIndex}"]`
1483
- );
1484
- if (activeRow) {
1485
- const [direction, distance] = howFarIsRowOutsideViewport(activeRow);
1486
- if (direction && distance) {
1487
- requestScroll == null ? void 0 : requestScroll({ type: "scroll-distance", distance, direction });
1488
- }
1489
- }
1490
- },
1491
- [containerRef, requestScroll]
1492
- );
1493
- const moveHighlightedRow = useCallback12(
1494
- async (key) => {
1495
- const { current: highlighted } = highlightedIndexRef;
1496
- const [nextRowIdx] = isPagingKey(key) ? await nextPageItemIdx(key, [highlighted != null ? highlighted : -1, 0]) : nextCellPos(key, [highlighted != null ? highlighted : -1, 0], columnCount, rowCount);
1497
- if (nextRowIdx !== highlighted) {
1498
- setHighlightedIndex(nextRowIdx);
1499
- scrollRowIntoViewIfNecessary(nextRowIdx);
1500
- }
1501
- },
1502
- [
1503
- columnCount,
1504
- nextPageItemIdx,
1505
- rowCount,
1506
- scrollRowIntoViewIfNecessary,
1507
- setHighlightedIndex
1508
- ]
1509
- );
1510
- useEffect2(() => {
1511
- if (highlightedIndexProp !== void 0 && highlightedIndexProp !== -1) {
1512
- scrollRowIntoViewIfNecessary(highlightedIndexProp);
1513
- }
1514
- }, [highlightedIndexProp, scrollRowIntoViewIfNecessary]);
1515
- const handleKeyDown = useCallback12(
1516
- (e) => {
1517
- if (rowCount > 0 && isNavigationKey(e.key, navigationStyle)) {
1518
- e.preventDefault();
1519
- e.stopPropagation();
1520
- if (navigationStyle === "row") {
1521
- moveHighlightedRow(e.key);
1522
- } else {
1523
- void navigateChildItems(e.key);
1524
- }
1525
- }
1526
- },
1527
- [rowCount, navigationStyle, moveHighlightedRow, navigateChildItems]
1528
- );
1529
- const handleClick = useCallback12(
1530
- // Might not be a cell e.g the Settings button
1531
- (evt) => {
1532
- const target = evt.target;
1533
- const focusedCell = getFocusedCell(target);
1534
- if (focusedCell) {
1535
- const [rowIdx, colIdx] = getTableCellPos(focusedCell);
1536
- setActiveCell(rowIdx, colIdx);
1537
- }
1538
- },
1539
- [setActiveCell]
1540
- );
1541
- const handleMouseLeave = useCallback12(() => {
1542
- setHighlightedIndex(-1);
1543
- }, [setHighlightedIndex]);
1544
- const handleMouseMove = useCallback12(
1545
- (evt) => {
1546
- const idx = closestRowIndex(evt.target);
1547
- if (idx !== -1 && idx !== highlightedIndexRef.current) {
1548
- setHighlightedIndex(idx);
1549
- }
1550
- },
1551
- [setHighlightedIndex]
1552
- );
1553
- const navigate = useCallback12(() => {
1554
- navigateChildItems("ArrowDown");
1555
- }, [navigateChildItems]);
1556
- const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
1557
- useEffect2(() => {
1558
- if (fullyRendered && focusableCell.current === void 0 && !disableFocus) {
1559
- const { current: container } = containerRef;
1560
- const cell = (container == null ? void 0 : container.querySelector(headerCellQuery(0))) || (container == null ? void 0 : container.querySelector(dataCellQuery(0, 0)));
1561
- if (cell) {
1562
- cell.setAttribute("tabindex", "0");
1563
- focusableCell.current = cell;
1564
- }
1565
- }
1566
- }, [containerRef, disableFocus, fullyRendered]);
1567
- return {
1568
- highlightedIndexRef,
1569
- navigate,
1570
- onClick: handleClick,
1571
- onFocus: handleFocus,
1572
- onKeyDown: handleKeyDown,
1573
- onMouseLeave: navigationStyle === "row" ? handleMouseLeave : void 0,
1574
- onMouseMove: navigationStyle === "row" ? handleMouseMove : void 0
1575
- };
1576
- };
1577
-
1578
- // src/useSelection.ts
1579
- import {
1580
- deselectItem,
1581
- dispatchMouseEvent,
1582
- isRowSelected,
1583
- metadataKeys as metadataKeys4,
1584
- selectItem
1585
- } from "@vuu-ui/vuu-utils";
1586
- import {
1587
- useCallback as useCallback13,
1588
- useRef as useRef9
1589
- } from "react";
1590
- var { IDX: IDX2 } = metadataKeys4;
1591
- var NO_SELECTION = [];
1592
- var defaultSelectionKeys = ["Enter", " "];
1593
- var useSelection = ({
1594
- highlightedIndexRef,
1595
- selectionKeys = defaultSelectionKeys,
1596
- selectionModel,
1597
- onSelect,
1598
- onSelectionChange
1599
- }) => {
1600
- selectionModel === "extended" || selectionModel === "checkbox";
1601
- const lastActiveRef = useRef9(-1);
1602
- const selectedRef = useRef9(NO_SELECTION);
1603
- const isSelectionEvent = useCallback13(
1604
- (evt) => selectionKeys.includes(evt.key),
1605
- [selectionKeys]
1606
- );
1607
- const handleRowClick = useCallback13(
1608
- (row, rangeSelect, keepExistingSelection) => {
1609
- const { [IDX2]: idx } = row;
1610
- const { current: active } = lastActiveRef;
1611
- const { current: selected } = selectedRef;
1612
- const selectOperation = isRowSelected(row) ? deselectItem : selectItem;
1613
- const newSelected = selectOperation(
1614
- selectionModel,
1615
- selected,
1616
- idx,
1617
- rangeSelect,
1618
- keepExistingSelection,
1619
- active
1620
- );
1621
- selectedRef.current = newSelected;
1622
- lastActiveRef.current = idx;
1623
- onSelect == null ? void 0 : onSelect(row);
1624
- onSelectionChange == null ? void 0 : onSelectionChange(newSelected);
1625
- },
1626
- [onSelect, onSelectionChange, selectionModel]
1627
- );
1628
- const handleKeyDown = useCallback13(
1629
- (e) => {
1630
- if (isSelectionEvent(e)) {
1631
- const { current: rowIndex } = highlightedIndexRef;
1632
- if (rowIndex !== void 0 && rowIndex !== -1) {
1633
- const rowEl = e.target.querySelector(
1634
- `[aria-rowindex="${rowIndex}"]`
1635
- );
1636
- if (rowEl) {
1637
- dispatchMouseEvent(rowEl, "click");
1638
- }
1639
- }
1640
- }
1641
- },
1642
- [highlightedIndexRef, isSelectionEvent]
1643
- );
1644
- return {
1645
- onKeyDown: handleKeyDown,
1646
- onRowClick: handleRowClick
1647
- };
1648
- };
1649
-
1650
- // src/useTableContextMenu.ts
1651
- import { useContextMenu as usePopupContextMenu } from "@vuu-ui/vuu-popups";
1652
- import { buildColumnMap, getIndexFromRowElement } from "@vuu-ui/vuu-utils";
1653
- import { useCallback as useCallback14 } from "react";
1654
- var NO_ROWS = [];
1655
- var useTableContextMenu = ({
1656
- columns,
1657
- data,
1658
- dataSource,
1659
- getSelectedRows
1660
- }) => {
1661
- const [showContextMenu] = usePopupContextMenu();
1662
- const onContextMenu = useCallback14(
1663
- (evt) => {
1664
- const target = evt.target;
1665
- const cellEl = target == null ? void 0 : target.closest("div[role='cell']");
1666
- const rowEl = target == null ? void 0 : target.closest("div[role='row']");
1667
- if (cellEl && rowEl) {
1668
- const { selectedRowsCount } = dataSource;
1669
- const columnMap = buildColumnMap(columns);
1670
- const rowIndex = getIndexFromRowElement(rowEl);
1671
- const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
1672
- const row = data.find(([idx]) => idx === rowIndex);
1673
- const columnName = columns[cellIndex];
1674
- showContextMenu(evt, "grid", {
1675
- columnMap,
1676
- columnName,
1677
- row,
1678
- selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
1679
- viewport: dataSource.viewport
1680
- });
1681
- }
1682
- },
1683
- [columns, data, dataSource, getSelectedRows, showContextMenu]
1684
- );
1685
- return onContextMenu;
1686
- };
1687
-
1688
- // src/useTableModel.ts
1689
- import {
1690
- applyFilterToColumns,
1691
- applyGroupByToColumns,
1692
- applySortToColumns,
1693
- getCellRenderer,
1694
- getColumnHeaderContentRenderer,
1695
- getColumnHeaderLabelRenderer,
1696
- getColumnLabel,
1697
- getTableHeadings,
1698
- getValueFormatter,
1699
- hasValidationRules,
1700
- isFilteredColumn,
1701
- isGroupColumn as isGroupColumn2,
1702
- isPinned,
1703
- logger,
1704
- metadataKeys as metadataKeys5,
1705
- replaceColumn,
1706
- sortPinnedColumns,
1707
- stripFilterFromColumns,
1708
- subscribedOnly
1709
- } from "@vuu-ui/vuu-utils";
1710
- import { buildValidationChecker } from "@vuu-ui/vuu-ui-controls";
1711
- import { useReducer } from "react";
1712
- var { info } = logger("useTableModel");
1713
- var DEFAULT_COLUMN_WIDTH = 100;
1714
- var KEY_OFFSET = metadataKeys5.count;
1715
- var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
1716
- var getDataType = (column, tableSchema) => {
1717
- const schemaColumn = tableSchema == null ? void 0 : tableSchema.columns.find(
1718
- ({ name }) => name === column.name
1719
- );
1720
- if (schemaColumn) {
1721
- return schemaColumn.serverDataType;
1722
- } else {
1723
- return column.serverDataType;
1724
- }
1725
- };
1726
- var numericTypes = ["int", "long", "double"];
1727
- var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
1728
- var isShowColumnSettings = (action) => action.type === "columnSettings";
1729
- var isShowTableSettings = (action) => action.type === "tableSettings";
1730
- var columnReducer = (state, action) => {
1731
- info == null ? void 0 : info(`TableModelReducer ${action.type}`);
1732
- switch (action.type) {
1733
- case "init":
1734
- return init(action);
1735
- case "moveColumn":
1736
- return moveColumn(state, action);
1737
- case "resizeColumn":
1738
- return resizeColumn(state, action);
1739
- case "setTableSchema":
1740
- return setTableSchema(state, action);
1741
- case "hideColumns":
1742
- return hideColumns(state, action);
1743
- case "showColumns":
1744
- return showColumns(state, action);
1745
- case "pinColumn":
1746
- return pinColumn2(state, action);
1747
- case "updateColumnProp":
1748
- return updateColumnProp(state, action);
1749
- case "tableConfig":
1750
- return updateTableConfig2(state, action);
1751
- default:
1752
- console.log(`unhandled action ${action.type}`);
1753
- return state;
1754
- }
1755
- };
1756
- var useTableModel = (tableConfigProp, dataSource) => {
1757
- const [state, dispatchColumnAction] = useReducer(columnReducer, { tableConfig: tableConfigProp, dataSource }, init);
1758
- const { columns, headings, tableConfig, ...tableAttributes } = state;
1759
- return {
1760
- columns,
1761
- dispatchColumnAction,
1762
- headings,
1763
- tableAttributes,
1764
- tableConfig
1765
- };
1766
- };
1767
- function init({ dataSource, tableConfig }) {
1768
- const { columns, ...tableAttributes } = tableConfig;
1769
- const { config: dataSourceConfig, tableSchema } = dataSource;
1770
- const runtimeColumns = columns.filter(subscribedOnly(dataSourceConfig == null ? void 0 : dataSourceConfig.columns)).map(
1771
- columnDescriptorToRuntimeColumDescriptor(tableAttributes, tableSchema)
1772
- );
1773
- const maybePinnedColumns = runtimeColumns.some(isPinned) ? sortPinnedColumns(runtimeColumns) : runtimeColumns;
1774
- let state = {
1775
- columns: maybePinnedColumns,
1776
- headings: getTableHeadings(maybePinnedColumns),
1777
- tableConfig,
1778
- ...tableAttributes
1779
- };
1780
- if (dataSourceConfig) {
1781
- const { columns: _, ...rest } = dataSourceConfig;
1782
- state = updateTableConfig2(state, {
1783
- type: "tableConfig",
1784
- ...rest
1785
- });
1786
- }
1787
- return state;
1788
- }
1789
- var getLabel = (label, columnFormatHeader) => {
1790
- if (columnFormatHeader === "uppercase") {
1791
- return label.toUpperCase();
1792
- } else if (columnFormatHeader === "capitalize") {
1793
- return label[0].toUpperCase() + label.slice(1).toLowerCase();
1794
- }
1795
- return label;
1796
- };
1797
- var columnDescriptorToRuntimeColumDescriptor = (tableAttributes, tableSchema) => (column, index) => {
1798
- const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = tableAttributes;
1799
- const serverDataType = getDataType(column, tableSchema);
1800
- const {
1801
- align = getDefaultAlignment(serverDataType),
1802
- key,
1803
- name,
1804
- label = getColumnLabel(column),
1805
- width = columnDefaultWidth,
1806
- ...rest
1807
- } = column;
1808
- const runtimeColumnWithDefaults = {
1809
- ...rest,
1810
- align,
1811
- CellRenderer: getCellRenderer(column),
1812
- HeaderCellContentRenderer: getColumnHeaderContentRenderer(column),
1813
- HeaderCellLabelRenderer: getColumnHeaderLabelRenderer(column),
1814
- clientSideEditValidationCheck: hasValidationRules(column.type) ? buildValidationChecker(column.type.renderer.rules) : void 0,
1815
- label: getLabel(label, columnFormatHeader),
1816
- key: key != null ? key : index + KEY_OFFSET,
1817
- name,
1818
- originalIdx: index,
1819
- serverDataType,
1820
- valueFormatter: getValueFormatter(column, serverDataType),
1821
- width
1822
- };
1823
- if (isGroupColumn2(runtimeColumnWithDefaults)) {
1824
- runtimeColumnWithDefaults.columns = runtimeColumnWithDefaults.columns.map(
1825
- (col) => columnDescriptorToRuntimeColumDescriptor(tableAttributes)(
1826
- col,
1827
- col.key
1828
- )
1829
- );
1830
- }
1831
- return runtimeColumnWithDefaults;
1832
- };
1833
- function moveColumn(state, { column, moveBy }) {
1834
- const { columns } = state;
1835
- if (typeof moveBy === "number") {
1836
- const idx = columns.indexOf(column);
1837
- const newColumns = columns.slice();
1838
- const [movedColumns] = newColumns.splice(idx, 1);
1839
- newColumns.splice(idx + moveBy, 0, movedColumns);
1840
- return {
1841
- ...state,
1842
- columns: newColumns
1843
- };
1844
- }
1845
- return state;
1846
- }
1847
- function hideColumns(state, { columns }) {
1848
- if (columns.some((col) => col.hidden !== true)) {
1849
- return columns.reduce((s, c) => {
1850
- if (c.hidden !== true) {
1851
- return updateColumnProp(s, {
1852
- type: "updateColumnProp",
1853
- column: c,
1854
- hidden: true
1855
- });
1856
- } else {
1857
- return s;
1858
- }
1859
- }, state);
1860
- } else {
1861
- return state;
1862
- }
1863
- }
1864
- function showColumns(state, { columns }) {
1865
- if (columns.some((col) => col.hidden)) {
1866
- return columns.reduce((s, c) => {
1867
- if (c.hidden) {
1868
- return updateColumnProp(s, {
1869
- type: "updateColumnProp",
1870
- column: c,
1871
- hidden: false
1872
- });
1873
- } else {
1874
- return s;
1875
- }
1876
- }, state);
1877
- } else {
1878
- return state;
1879
- }
1880
- }
1881
- function resizeColumn(state, { column, phase, width }) {
1882
- const type = "updateColumnProp";
1883
- const resizing = phase !== "end";
1884
- switch (phase) {
1885
- case "begin":
1886
- return updateColumnProp(state, { type, column, resizing });
1887
- case "end":
1888
- return updateColumnProp(state, { type, column, resizing, width });
1889
- case "resize":
1890
- return updateColumnProp(state, { type, column, width });
1891
- default:
1892
- throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
1893
- }
1894
- }
1895
- function setTableSchema(state, { tableSchema }) {
1896
- const { columns } = state;
1897
- if (columns.some(columnWithoutDataType)) {
1898
- const cols = columns.map((column) => {
1899
- var _a;
1900
- const serverDataType = getDataType(column, tableSchema);
1901
- return {
1902
- ...column,
1903
- align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
1904
- serverDataType
1905
- };
1906
- });
1907
- return {
1908
- ...state,
1909
- columns: cols
1910
- };
1911
- } else {
1912
- return state;
1913
- }
1914
- }
1915
- function pinColumn2(state, action) {
1916
- let { columns } = state;
1917
- const { column, pin } = action;
1918
- const targetColumn = columns.find((col) => col.name === column.name);
1919
- if (targetColumn) {
1920
- columns = replaceColumn(columns, { ...targetColumn, pin });
1921
- columns = sortPinnedColumns(columns);
1922
- return {
1923
- ...state,
1924
- columns
1925
- };
1926
- } else {
1927
- return state;
1928
- }
1929
- }
1930
- function updateColumnProp(state, action) {
1931
- let { columns, tableConfig } = state;
1932
- const { align, column, hidden, label, resizing, width } = action;
1933
- const targetColumn = columns.find((col) => col.name === column.name);
1934
- if (targetColumn) {
1935
- if (align === "left" || align === "right") {
1936
- columns = replaceColumn(columns, { ...targetColumn, align });
1937
- }
1938
- if (typeof label === "string") {
1939
- columns = replaceColumn(columns, { ...targetColumn, label });
1940
- }
1941
- if (typeof resizing === "boolean") {
1942
- columns = replaceColumn(columns, { ...targetColumn, resizing });
1943
- }
1944
- if (typeof hidden === "boolean") {
1945
- columns = replaceColumn(columns, { ...targetColumn, hidden });
1946
- }
1947
- if (typeof width === "number") {
1948
- columns = replaceColumn(columns, { ...targetColumn, width });
1949
- const targetConfigColumn = tableConfig.columns.find(
1950
- (col) => col.name === column.name
1951
- );
1952
- if (targetConfigColumn) {
1953
- tableConfig = {
1954
- ...tableConfig,
1955
- columns: replaceColumn(tableConfig.columns, {
1956
- ...targetConfigColumn,
1957
- width
1958
- })
1959
- };
1960
- }
1961
- }
1962
- }
1963
- return {
1964
- ...state,
1965
- columns,
1966
- tableConfig
1967
- };
1968
- }
1969
- function updateTableConfig2(state, { confirmed, filter, groupBy, sort }) {
1970
- const hasGroupBy = groupBy !== void 0;
1971
- const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
1972
- const hasSort = sort && sort.sortDefs.length > 0;
1973
- let result = state;
1974
- if (hasGroupBy) {
1975
- result = {
1976
- ...state,
1977
- columns: applyGroupByToColumns(result.columns, groupBy, confirmed)
1978
- };
1979
- }
1980
- if (hasSort) {
1981
- result = {
1982
- ...state,
1983
- columns: applySortToColumns(result.columns, sort)
1984
- };
1985
- }
1986
- if (hasFilter) {
1987
- result = {
1988
- ...state,
1989
- columns: applyFilterToColumns(result.columns, filter)
1990
- };
1991
- } else if (result.columns.some(isFilteredColumn)) {
1992
- result = {
1993
- ...state,
1994
- columns: stripFilterFromColumns(result.columns)
1995
- };
1996
- }
1997
- return result;
1998
- }
1999
-
2000
- // src/useTableScroll.ts
2001
- import { useCallback as useCallback15, useRef as useRef10 } from "react";
2002
- var getPctScroll = (container) => {
2003
- const { scrollLeft, scrollTop } = container;
2004
- const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
2005
- const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
2006
- const pctScrollTop = scrollTop / (scrollHeight - clientHeight);
2007
- return [pctScrollLeft, pctScrollTop];
2008
- };
2009
- var useCallbackRef = ({
2010
- onAttach,
2011
- onDetach
2012
- }) => {
2013
- const ref = useRef10(null);
2014
- const callbackRef = useCallback15(
2015
- (el) => {
2016
- if (el) {
2017
- ref.current = el;
2018
- onAttach == null ? void 0 : onAttach(el);
2019
- } else if (ref.current) {
2020
- const { current: originalRef } = ref;
2021
- ref.current = el;
2022
- onDetach == null ? void 0 : onDetach(originalRef);
2023
- }
2024
- },
2025
- [onAttach, onDetach]
2026
- );
2027
- return callbackRef;
2028
- };
2029
- var useTableScroll = ({
2030
- maxScrollLeft,
2031
- maxScrollTop,
2032
- onHorizontalScroll,
2033
- onVerticalScroll,
2034
- rowHeight,
2035
- viewportRowCount
2036
- }) => {
2037
- const contentContainerScrolledRef = useRef10(false);
2038
- const scrollPosRef = useRef10({ scrollTop: 0, scrollLeft: 0 });
2039
- const scrollbarContainerRef = useRef10(null);
2040
- const contentContainerRef = useRef10(null);
2041
- const handleScrollbarContainerScroll = useCallback15(() => {
2042
- const { current: contentContainer } = contentContainerRef;
2043
- const { current: scrollbarContainer } = scrollbarContainerRef;
2044
- const { current: contentContainerScrolled } = contentContainerScrolledRef;
2045
- if (contentContainerScrolled) {
2046
- contentContainerScrolledRef.current = false;
2047
- } else if (contentContainer && scrollbarContainer) {
2048
- const [pctScrollLeft, pctScrollTop] = getPctScroll(scrollbarContainer);
2049
- const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
2050
- const rootScrollTop = Math.round(pctScrollTop * maxScrollTop);
2051
- contentContainer.scrollTo({
2052
- left: rootScrollLeft,
2053
- top: rootScrollTop,
2054
- behavior: "auto"
2055
- });
2056
- }
2057
- }, [maxScrollLeft, maxScrollTop]);
2058
- const handleContentContainerScroll = useCallback15(() => {
2059
- const { current: contentContainer } = contentContainerRef;
2060
- const { current: scrollbarContainer } = scrollbarContainerRef;
2061
- const { current: scrollPos } = scrollPosRef;
2062
- if (contentContainer && scrollbarContainer) {
2063
- const { scrollLeft, scrollTop } = contentContainer;
2064
- const [pctScrollLeft, pctScrollTop] = getPctScroll(contentContainer);
2065
- contentContainerScrolledRef.current = true;
2066
- scrollbarContainer.scrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
2067
- scrollbarContainer.scrollTop = Math.round(pctScrollTop * maxScrollTop);
2068
- if (scrollPos.scrollTop !== scrollTop) {
2069
- scrollPos.scrollTop = scrollTop;
2070
- onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop, pctScrollTop);
2071
- }
2072
- if (scrollPos.scrollLeft !== scrollLeft) {
2073
- scrollPos.scrollLeft = scrollLeft;
2074
- onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
2075
- }
2076
- }
2077
- }, [maxScrollLeft, maxScrollTop, onHorizontalScroll, onVerticalScroll]);
2078
- const handleAttachScrollbarContainer = useCallback15(
2079
- (el) => {
2080
- scrollbarContainerRef.current = el;
2081
- el.addEventListener("scroll", handleScrollbarContainerScroll, {
2082
- passive: true
2083
- });
2084
- },
2085
- [handleScrollbarContainerScroll]
2086
- );
2087
- const handleDetachScrollbarContainer = useCallback15(
2088
- (el) => {
2089
- scrollbarContainerRef.current = null;
2090
- el.removeEventListener("scroll", handleScrollbarContainerScroll);
2091
- },
2092
- [handleScrollbarContainerScroll]
2093
- );
2094
- const handleAttachContentContainer = useCallback15(
2095
- (el) => {
2096
- contentContainerRef.current = el;
2097
- el.addEventListener("scroll", handleContentContainerScroll, {
2098
- passive: true
2099
- });
2100
- },
2101
- [handleContentContainerScroll]
2102
- );
2103
- const handleDetachContentContainer = useCallback15(
2104
- (el) => {
2105
- contentContainerRef.current = null;
2106
- el.removeEventListener("scroll", handleContentContainerScroll);
2107
- },
2108
- [handleContentContainerScroll]
2109
- );
2110
- const contentContainerCallbackRef = useCallbackRef({
2111
- onAttach: handleAttachContentContainer,
2112
- onDetach: handleDetachContentContainer
2113
- });
2114
- const scrollbarContainerCallbackRef = useCallbackRef({
2115
- onAttach: handleAttachScrollbarContainer,
2116
- onDetach: handleDetachScrollbarContainer
2117
- });
2118
- const requestScroll = useCallback15(
2119
- (scrollRequest) => {
2120
- const { current: scrollbarContainer } = contentContainerRef;
2121
- if (scrollbarContainer) {
2122
- const { scrollLeft, scrollTop } = scrollbarContainer;
2123
- contentContainerScrolledRef.current = false;
2124
- if (scrollRequest.type === "scroll-distance") {
2125
- let newScrollLeft = scrollLeft;
2126
- let newScrollTop = scrollTop;
2127
- if (scrollRequest.direction === "up" || scrollRequest.direction === "down") {
2128
- newScrollTop = Math.min(
2129
- Math.max(0, scrollTop + scrollRequest.distance),
2130
- maxScrollTop
2131
- );
2132
- } else {
2133
- newScrollLeft = Math.min(
2134
- Math.max(0, scrollLeft + scrollRequest.distance),
2135
- maxScrollLeft
2136
- );
2137
- }
2138
- scrollbarContainer.scrollTo({
2139
- top: newScrollTop,
2140
- left: newScrollLeft,
2141
- behavior: "smooth"
2142
- });
2143
- } else if (scrollRequest.type === "scroll-page") {
2144
- const { direction } = scrollRequest;
2145
- const scrollBy = viewportRowCount * (direction === "down" ? rowHeight : -rowHeight);
2146
- const newScrollTop = Math.min(
2147
- Math.max(0, scrollTop + scrollBy),
2148
- maxScrollTop
2149
- );
2150
- scrollbarContainer.scrollTo({
2151
- top: newScrollTop,
2152
- left: scrollLeft,
2153
- behavior: "auto"
2154
- });
2155
- } else if (scrollRequest.type === "scroll-end") {
2156
- const { direction } = scrollRequest;
2157
- const scrollTo = direction === "end" ? maxScrollTop : 0;
2158
- scrollbarContainer.scrollTo({
2159
- top: scrollTo,
2160
- left: scrollbarContainer.scrollLeft,
2161
- behavior: "auto"
2162
- });
2163
- }
2164
- }
2165
- },
2166
- [maxScrollLeft, maxScrollTop, rowHeight, viewportRowCount]
2167
- );
2168
- return {
2169
- /** Ref to be assigned to ScrollbarContainer */
2170
- scrollbarContainerRef: scrollbarContainerCallbackRef,
2171
- /** Ref to be assigned to ContentContainer */
2172
- contentContainerRef: contentContainerCallbackRef,
2173
- /** Scroll the table */
2174
- requestScroll
2175
- };
2176
- };
2177
-
2178
- // src/useTableViewport.ts
2179
- import { useCallback as useCallback16, useMemo as useMemo4, useRef as useRef11 } from "react";
2180
- import {
2181
- actualRowPositioning,
2182
- virtualRowPositioning
2183
- } from "@vuu-ui/vuu-utils";
2184
- var MAX_RAW_ROWS = 15e5;
2185
- var UNMEASURED_VIEWPORT = {
2186
- contentHeight: 0,
2187
- contentWidth: 0,
2188
- getRowAtPosition: () => -1,
2189
- getRowOffset: () => -1,
2190
- horizontalScrollbarHeight: 0,
2191
- maxScrollContainerScrollHorizontal: 0,
2192
- maxScrollContainerScrollVertical: 0,
2193
- pinnedWidthLeft: 0,
2194
- pinnedWidthRight: 0,
2195
- rowCount: 0,
2196
- setPctScrollTop: () => void 0,
2197
- totalHeaderHeight: 0,
2198
- verticalScrollbarWidth: 0,
2199
- viewportBodyHeight: 0
2200
- };
2201
- var measurePinnedColumns = (columns) => {
2202
- let pinnedWidthLeft = 0;
2203
- let pinnedWidthRight = 0;
2204
- let unpinnedWidth = 0;
2205
- for (const column of columns) {
2206
- const { hidden, pin, width } = column;
2207
- const visibleWidth = hidden ? 0 : width;
2208
- if (pin === "left") {
2209
- pinnedWidthLeft += visibleWidth;
2210
- } else if (pin === "right") {
2211
- pinnedWidthRight += visibleWidth;
2212
- } else {
2213
- unpinnedWidth += visibleWidth;
2214
- }
2215
- }
2216
- return {
2217
- pinnedWidthLeft: pinnedWidthLeft + 4,
2218
- pinnedWidthRight: pinnedWidthRight + 4,
2219
- unpinnedWidth
2220
- };
2221
- };
2222
- var useTableViewport = ({
2223
- columns,
2224
- headerHeight,
2225
- headings,
2226
- rowCount,
2227
- rowHeight,
2228
- size
2229
- }) => {
2230
- const pctScrollTopRef = useRef11(0);
2231
- const appliedRowCount = Math.min(rowCount, MAX_RAW_ROWS);
2232
- const appliedContentHeight = appliedRowCount * rowHeight;
2233
- const virtualContentHeight = rowCount * rowHeight;
2234
- const virtualisedExtent = virtualContentHeight - appliedContentHeight;
2235
- const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo4(
2236
- () => measurePinnedColumns(columns),
2237
- [columns]
2238
- );
2239
- const [actualRowOffset, actualRowAtPosition] = useMemo4(
2240
- () => actualRowPositioning(rowHeight),
2241
- [rowHeight]
2242
- );
2243
- const [getRowOffset, getRowAtPosition] = useMemo4(() => {
2244
- if (virtualisedExtent) {
2245
- return virtualRowPositioning(
2246
- rowHeight,
2247
- virtualisedExtent,
2248
- pctScrollTopRef
2249
- );
2250
- } else {
2251
- return [actualRowOffset, actualRowAtPosition];
2252
- }
2253
- }, [actualRowAtPosition, actualRowOffset, virtualisedExtent, rowHeight]);
2254
- const setPctScrollTop = useCallback16((scrollPct) => {
2255
- pctScrollTopRef.current = scrollPct;
2256
- }, []);
2257
- return useMemo4(() => {
2258
- var _a;
2259
- if (size) {
2260
- const headingsDepth = headings.length;
2261
- const scrollbarSize = 15;
2262
- const contentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
2263
- const horizontalScrollbarHeight = contentWidth > size.width ? scrollbarSize : 0;
2264
- const totalHeaderHeight = headerHeight * (1 + headingsDepth);
2265
- const maxScrollContainerScrollVertical = appliedContentHeight - (((_a = size == null ? void 0 : size.height) != null ? _a : 0) - horizontalScrollbarHeight) + totalHeaderHeight;
2266
- const maxScrollContainerScrollHorizontal = contentWidth - size.width + pinnedWidthLeft;
2267
- const visibleRows = (size.height - headerHeight) / rowHeight;
2268
- const count = Number.isInteger(visibleRows) ? visibleRows + 1 : Math.ceil(visibleRows);
2269
- const viewportBodyHeight = size.height - totalHeaderHeight;
2270
- const verticalScrollbarWidth = appliedContentHeight > viewportBodyHeight ? scrollbarSize : 0;
2271
- return {
2272
- contentHeight: appliedContentHeight,
2273
- getRowAtPosition,
2274
- getRowOffset,
2275
- horizontalScrollbarHeight,
2276
- maxScrollContainerScrollHorizontal,
2277
- maxScrollContainerScrollVertical,
2278
- pinnedWidthLeft,
2279
- pinnedWidthRight,
2280
- rowCount: count,
2281
- contentWidth,
2282
- setPctScrollTop,
2283
- totalHeaderHeight,
2284
- verticalScrollbarWidth,
2285
- viewportBodyHeight
2286
- };
2287
- } else {
2288
- return UNMEASURED_VIEWPORT;
2289
- }
2290
- }, [
2291
- size,
2292
- headings.length,
2293
- pinnedWidthLeft,
2294
- unpinnedWidth,
2295
- pinnedWidthRight,
2296
- appliedContentHeight,
2297
- headerHeight,
2298
- rowHeight,
2299
- getRowAtPosition,
2300
- getRowOffset,
2301
- setPctScrollTop
2302
- ]);
2303
- };
2304
-
2305
- // src/useVirtualViewport.ts
2306
- import { useCallback as useCallback17, useEffect as useEffect3, useRef as useRef12 } from "react";
2307
- var useVirtualViewport = ({
2308
- getRowAtPosition,
2309
- setRange,
2310
- viewportMeasurements
2311
- }) => {
2312
- const firstRowRef = useRef12(0);
2313
- const { rowCount: viewportRowCount } = viewportMeasurements;
2314
- const handleVerticalScroll = useCallback17(
2315
- (scrollTop) => {
2316
- const firstRow = getRowAtPosition(scrollTop);
2317
- if (firstRow !== firstRowRef.current) {
2318
- firstRowRef.current = firstRow;
2319
- setRange({ from: firstRow, to: firstRow + viewportRowCount });
2320
- }
2321
- },
2322
- [getRowAtPosition, setRange, viewportRowCount]
2323
- );
2324
- useEffect3(() => {
2325
- const { current: from } = firstRowRef;
2326
- const rowRange = { from, to: from + viewportRowCount };
2327
- setRange(rowRange);
2328
- }, [setRange, viewportRowCount]);
2329
- return {
2330
- onVerticalScroll: handleVerticalScroll
2331
- };
2332
- };
2333
-
2334
- // src/useTableAndColumnSettings.ts
2335
- import { useLayoutProviderDispatch } from "@vuu-ui/vuu-layout";
2336
- import { getCalculatedColumnType } from "@vuu-ui/vuu-utils";
2337
- import { useCallback as useCallback18, useRef as useRef13, useState as useState5 } from "react";
2338
- var useTableAndColumnSettings = ({
2339
- availableColumns: availableColumnsProps,
2340
- onAvailableColumnsChange,
2341
- onConfigChange,
2342
- onCreateCalculatedColumn,
2343
- onDataSourceConfigChange,
2344
- tableConfig
2345
- }) => {
2346
- const dispatchLayoutAction = useLayoutProviderDispatch();
2347
- const showTableSettingsRef = useRef13();
2348
- const [availableColumns, setAvailableColumns] = useState5(
2349
- availableColumnsProps
2350
- );
2351
- const showContextPanel = useCallback18(
2352
- (componentType, title, props) => {
2353
- dispatchLayoutAction({
2354
- type: "set-props",
2355
- path: "#context-panel",
2356
- props: {
2357
- expanded: true,
2358
- content: {
2359
- type: componentType,
2360
- props
2361
- },
2362
- title
2363
- }
2364
- });
2365
- },
2366
- [dispatchLayoutAction]
2367
- );
2368
- const handleCancelCreateColumn = useCallback18(() => {
2369
- requestAnimationFrame(() => {
2370
- var _a;
2371
- (_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
2372
- });
2373
- }, []);
2374
- const handleCreateCalculatedColumn = useCallback18(
2375
- (column) => {
2376
- const newAvailableColumns = availableColumns.concat({
2377
- name: column.name,
2378
- serverDataType: getCalculatedColumnType(column)
2379
- });
2380
- setAvailableColumns(newAvailableColumns);
2381
- onAvailableColumnsChange == null ? void 0 : onAvailableColumnsChange(newAvailableColumns);
2382
- requestAnimationFrame(() => {
2383
- var _a;
2384
- (_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
2385
- });
2386
- onCreateCalculatedColumn(column);
2387
- },
2388
- [availableColumns, onAvailableColumnsChange, onCreateCalculatedColumn]
2389
- );
2390
- const showColumnSettingsPanel = useCallback18(
2391
- (action) => {
2392
- showContextPanel("ColumnSettings", "Column Settings", {
2393
- column: action.column,
2394
- onCancelCreateColumn: handleCancelCreateColumn,
2395
- onConfigChange,
2396
- onCreateCalculatedColumn: handleCreateCalculatedColumn,
2397
- tableConfig,
2398
- vuuTable: action.vuuTable
2399
- });
2400
- },
2401
- [
2402
- handleCancelCreateColumn,
2403
- handleCreateCalculatedColumn,
2404
- onConfigChange,
2405
- showContextPanel,
2406
- tableConfig
2407
- ]
2408
- );
2409
- const handleAddCalculatedColumn = useCallback18(() => {
2410
- showColumnSettingsPanel({
2411
- column: {
2412
- name: "::",
2413
- serverDataType: "string"
2414
- },
2415
- type: "columnSettings",
2416
- vuuTable: { module: "SIMUL", table: "instruments" }
2417
- });
2418
- }, [showColumnSettingsPanel]);
2419
- const handleNavigateToColumn = useCallback18(
2420
- (columnName) => {
2421
- const column = tableConfig.columns.find((c) => c.name === columnName);
2422
- if (column) {
2423
- showColumnSettingsPanel({
2424
- type: "columnSettings",
2425
- column,
2426
- //TODO where do we get this from
2427
- vuuTable: { module: "SIMUL", table: "instruments" }
2428
- });
2429
- }
2430
- },
2431
- [showColumnSettingsPanel, tableConfig.columns]
2432
- );
2433
- showTableSettingsRef.current = useCallback18(() => {
2434
- showContextPanel("TableSettings", "DataGrid Settings", {
2435
- availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType }) => ({
2436
- name,
2437
- serverDataType
2438
- })),
2439
- onAddCalculatedColumn: handleAddCalculatedColumn,
2440
- onConfigChange,
2441
- onDataSourceConfigChange,
2442
- onNavigateToColumn: handleNavigateToColumn,
2443
- tableConfig
2444
- });
2445
- }, [
2446
- availableColumns,
2447
- handleAddCalculatedColumn,
2448
- handleNavigateToColumn,
2449
- onConfigChange,
2450
- onDataSourceConfigChange,
2451
- showContextPanel,
2452
- tableConfig
2453
- ]);
2454
- return {
2455
- showColumnSettingsPanel,
2456
- showTableSettingsPanel: showTableSettingsRef.current
2457
- };
2458
- };
2459
-
2460
- // src/useTable.ts
2461
- var stripInternalProperties = (tableConfig) => {
2462
- return tableConfig;
2463
- };
2464
- var { KEY, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = metadataKeys6;
2465
- var NULL_DRAG_DROP = {
2466
- draggable: void 0,
2467
- onMouseDown: void 0
2468
- };
2469
- var useNullDragDrop = () => NULL_DRAG_DROP;
2470
- var addColumn = (tableConfig, column) => ({
2471
- ...tableConfig,
2472
- columns: tableConfig.columns.concat(column)
2473
- });
2474
- var useTable = ({
2475
- allowDragDrop = false,
2476
- availableColumns,
2477
- config,
2478
- containerRef,
2479
- dataSource,
2480
- disableFocus,
2481
- headerHeight = 25,
2482
- highlightedIndex: highlightedIndexProp,
2483
- id,
2484
- navigationStyle = "cell",
2485
- onAvailableColumnsChange,
2486
- onConfigChange,
2487
- onDragStart,
2488
- onDrop,
2489
- onFeatureInvocation,
2490
- onHighlight,
2491
- onRowClick: onRowClickProp,
2492
- onSelect,
2493
- onSelectionChange,
2494
- renderBufferSize = 0,
2495
- rowHeight = 20,
2496
- selectionModel,
2497
- size
2498
- }) => {
2499
- const [rowCount, setRowCount] = useState6(dataSource.size);
2500
- if (dataSource === void 0) {
2501
- throw Error("no data source provided to Vuu Table");
2502
- }
2503
- const useRowDragDrop = allowDragDrop ? useDragDrop : useNullDragDrop;
2504
- const menuBuilder = useMemo5(
2505
- () => buildContextMenuDescriptors(dataSource),
2506
- [dataSource]
2507
- );
2508
- const onDataRowcountChange = useCallback19((size2) => {
2509
- setRowCount(size2);
2510
- }, []);
2511
- const {
2512
- columns: runtimeColumns,
2513
- dispatchColumnAction,
2514
- headings,
2515
- tableAttributes,
2516
- tableConfig
2517
- } = useTableModel(config, dataSource);
2518
- useLayoutEffectSkipFirst2(() => {
2519
- dispatchColumnAction({
2520
- type: "init",
2521
- dataSource,
2522
- tableConfig
2523
- });
2524
- }, [tableConfig, dataSource, dispatchColumnAction]);
2525
- const applyTableConfigChange = useCallback19(
2526
- (config2) => {
2527
- dispatchColumnAction({
2528
- type: "init",
2529
- tableConfig: config2,
2530
- dataSource
2531
- });
2532
- onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(config2));
2533
- },
2534
- [dataSource, dispatchColumnAction, onConfigChange]
2535
- );
2536
- const [stateColumns, setStateColumns] = useState6();
2537
- const [columns, setColumnSize] = useMemo5(() => {
2538
- const setSize = (columnName, width) => {
2539
- const cols = updateColumn(runtimeColumns, columnName, { width });
2540
- setStateColumns(cols);
2541
- };
2542
- return [stateColumns != null ? stateColumns : runtimeColumns, setSize];
2543
- }, [runtimeColumns, stateColumns]);
2544
- const columnMap = useMemo5(
2545
- () => buildColumnMap2(dataSource.columns),
2546
- [dataSource.columns]
2547
- );
2548
- const {
2549
- getRowAtPosition,
2550
- getRowOffset,
2551
- setPctScrollTop,
2552
- ...viewportMeasurements
2553
- } = useTableViewport({
2554
- columns,
2555
- headerHeight,
2556
- headings,
2557
- rowCount,
2558
- rowHeight,
2559
- size
2560
- });
2561
- const initialRange = useInitialValue({
2562
- from: 0,
2563
- to: viewportMeasurements.rowCount
2564
- });
2565
- const onSubscribed = useCallback19(
2566
- ({ tableSchema }) => {
2567
- if (tableSchema) {
2568
- dispatchColumnAction({
2569
- type: "setTableSchema",
2570
- tableSchema
2571
- });
2572
- } else {
2573
- console.log("subscription message with no schema");
2574
- }
2575
- },
2576
- [dispatchColumnAction]
2577
- );
2578
- const { data, dataRef, getSelectedRows, range, setRange } = useDataSource({
2579
- dataSource,
2580
- // We need to factor this out of Table
2581
- onFeatureInvocation,
2582
- renderBufferSize,
2583
- onSizeChange: onDataRowcountChange,
2584
- onSubscribed,
2585
- range: initialRange
2586
- });
2587
- const handleConfigEditedInSettingsPanel = useCallback19(
2588
- (tableConfig2) => {
2589
- console.log(`settings changed`);
2590
- dispatchColumnAction({
2591
- type: "init",
2592
- tableConfig: tableConfig2,
2593
- dataSource
2594
- });
2595
- onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(tableConfig2));
2596
- },
2597
- [dataSource, dispatchColumnAction, onConfigChange]
2598
- );
2599
- const handleDataSourceConfigChanged = useCallback19(
2600
- (dataSourceConfig) => {
2601
- dataSource.config = {
2602
- ...dataSource.config,
2603
- ...dataSourceConfig
2604
- };
2605
- },
2606
- [dataSource]
2607
- );
2608
- useEffect4(() => {
2609
- dataSource.on("config", (config2, confirmed) => {
2610
- dispatchColumnAction({
2611
- type: "tableConfig",
2612
- ...config2,
2613
- confirmed
2614
- });
2615
- });
2616
- }, [dataSource, dispatchColumnAction]);
2617
- const handleCreateCalculatedColumn = useCallback19(
2618
- (column) => {
2619
- dataSource.columns = dataSource.columns.concat(column.name);
2620
- applyTableConfigChange(addColumn(tableConfig, column));
2621
- },
2622
- [dataSource, tableConfig, applyTableConfigChange]
2623
- );
2624
- const hideColumns2 = useCallback19(
2625
- (action) => {
2626
- const { columns: columns2 } = action;
2627
- const hiddenColumns = columns2.map((c) => c.name);
2628
- const newTableConfig = {
2629
- ...tableConfig,
2630
- columns: tableConfig.columns.map(
2631
- (col) => hiddenColumns.includes(col.name) ? { ...col, hidden: true } : col
2632
- )
2633
- };
2634
- applyTableConfigChange(newTableConfig);
2635
- },
2636
- [tableConfig, applyTableConfigChange]
2637
- );
2638
- const pinColumn3 = useCallback19(
2639
- (action) => {
2640
- applyTableConfigChange({
2641
- ...tableConfig,
2642
- columns: updateColumn(tableConfig.columns, {
2643
- ...action.column,
2644
- pin: action.pin
2645
- })
2646
- });
2647
- },
2648
- [tableConfig, applyTableConfigChange]
2649
- );
2650
- const { showColumnSettingsPanel, showTableSettingsPanel } = useTableAndColumnSettings({
2651
- availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType = "string" }) => ({
2652
- name,
2653
- serverDataType
2654
- })),
2655
- onAvailableColumnsChange,
2656
- onConfigChange: handleConfigEditedInSettingsPanel,
2657
- onCreateCalculatedColumn: handleCreateCalculatedColumn,
2658
- onDataSourceConfigChange: handleDataSourceConfigChanged,
2659
- tableConfig
2660
- });
2661
- const onPersistentColumnOperation = useCallback19(
2662
- (action) => {
2663
- if (isShowColumnSettings(action)) {
2664
- showColumnSettingsPanel(action);
2665
- } else if (isShowTableSettings(action)) {
2666
- showTableSettingsPanel();
2667
- } else {
2668
- switch (action.type) {
2669
- case "hideColumns":
2670
- return hideColumns2(action);
2671
- case "pinColumn":
2672
- return pinColumn3(action);
2673
- default:
2674
- dispatchColumnAction(action);
2675
- }
2676
- }
2677
- },
2678
- [
2679
- dispatchColumnAction,
2680
- hideColumns2,
2681
- pinColumn3,
2682
- showColumnSettingsPanel,
2683
- showTableSettingsPanel
2684
- ]
2685
- );
2686
- const handleContextMenuAction = useHandleTableContextMenu({
2687
- dataSource,
2688
- onPersistentColumnOperation
2689
- });
2690
- const handleSort = useCallback19(
2691
- (column, extendSort = false, sortType) => {
2692
- if (dataSource) {
2693
- dataSource.sort = applySort(
2694
- dataSource.sort,
2695
- column,
2696
- extendSort,
2697
- sortType
2698
- );
2699
- }
2700
- },
2701
- [dataSource]
2702
- );
2703
- const onResizeColumn = useCallback19(
2704
- (phase, columnName, width) => {
2705
- const column = columns.find((column2) => column2.name === columnName);
2706
- if (column) {
2707
- if (phase === "resize") {
2708
- if (isValidNumber(width)) {
2709
- setColumnSize(columnName, width);
2710
- }
2711
- } else if (phase === "end") {
2712
- if (isValidNumber(width)) {
2713
- dispatchColumnAction({
2714
- type: "resizeColumn",
2715
- phase,
2716
- column,
2717
- width
2718
- });
2719
- setStateColumns(void 0);
2720
- onConfigChange == null ? void 0 : onConfigChange(
2721
- stripInternalProperties(
2722
- updateTableConfig(tableConfig, {
2723
- type: "col-size",
2724
- column,
2725
- width
2726
- })
2727
- )
2728
- );
2729
- }
2730
- } else {
2731
- setStateColumns(void 0);
2732
- dispatchColumnAction({
2733
- type: "resizeColumn",
2734
- phase,
2735
- column,
2736
- width
2737
- });
2738
- }
2739
- } else {
2740
- throw Error(
2741
- `useDataTable.handleColumnResize, column ${columnName} not found`
2742
- );
2743
- }
2744
- },
2745
- [columns, tableConfig, dispatchColumnAction, onConfigChange, setColumnSize]
2746
- );
2747
- const onToggleGroup = useCallback19(
2748
- (row, column) => {
2749
- var _a, _b;
2750
- const isJson = isJsonGroup2(column, row);
2751
- const key = row[KEY];
2752
- if (row[IS_EXPANDED2]) {
2753
- dataSource.closeTreeNode(key, true);
2754
- if (isJson) {
2755
- const idx = columns.indexOf(column);
2756
- const rows = (_a = dataSource.getRowsAtDepth) == null ? void 0 : _a.call(dataSource, idx + 1);
2757
- if (rows && !rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
2758
- dispatchColumnAction({
2759
- type: "hideColumns",
2760
- columns: columns.slice(idx + 2)
2761
- });
2762
- }
2763
- }
2764
- } else {
2765
- dataSource.openTreeNode(key);
2766
- if (isJson) {
2767
- const childRows = (_b = dataSource.getChildRows) == null ? void 0 : _b.call(dataSource, key);
2768
- const idx = columns.indexOf(column) + 1;
2769
- const columnsToShow = [columns[idx]];
2770
- if (childRows && childRows.some((row2) => row2[IS_LEAF2])) {
2771
- columnsToShow.push(columns[idx + 1]);
2772
- }
2773
- if (columnsToShow.some((col) => col.hidden)) {
2774
- dispatchColumnAction({
2775
- type: "showColumns",
2776
- columns: columnsToShow
2777
- });
2778
- }
2779
- }
2780
- }
2781
- },
2782
- [columns, dataSource, dispatchColumnAction]
2783
- );
2784
- const { onVerticalScroll } = useVirtualViewport({
2785
- columns,
2786
- getRowAtPosition,
2787
- setRange,
2788
- viewportMeasurements
2789
- });
2790
- const handleVerticalScroll = useCallback19(
2791
- (scrollTop) => {
2792
- onVerticalScroll(scrollTop);
2793
- },
2794
- [onVerticalScroll]
2795
- );
2796
- const { requestScroll, ...scrollProps } = useTableScroll({
2797
- maxScrollLeft: viewportMeasurements.maxScrollContainerScrollHorizontal,
2798
- maxScrollTop: viewportMeasurements.maxScrollContainerScrollVertical,
2799
- rowHeight,
2800
- onVerticalScroll: handleVerticalScroll,
2801
- viewportRowCount: viewportMeasurements.rowCount
2802
- });
2803
- const {
2804
- highlightedIndexRef,
2805
- navigate,
2806
- onFocus: navigationFocus,
2807
- onKeyDown: navigationKeyDown,
2808
- ...containerProps
2809
- } = useKeyboardNavigation({
2810
- columnCount: columns.filter((c) => c.hidden !== true).length,
2811
- containerRef,
2812
- disableFocus,
2813
- highlightedIndex: highlightedIndexProp,
2814
- navigationStyle,
2815
- requestScroll,
2816
- rowCount: dataSource == null ? void 0 : dataSource.size,
2817
- onHighlight,
2818
- viewportRange: range,
2819
- viewportRowCount: viewportMeasurements.rowCount
2820
- });
2821
- const {
2822
- onBlur: editingBlur,
2823
- onDoubleClick: editingDoubleClick,
2824
- onKeyDown: editingKeyDown,
2825
- onFocus: editingFocus
2826
- } = useCellEditing({
2827
- navigate
2828
- });
2829
- const handleFocus = useCallback19(
2830
- (e) => {
2831
- navigationFocus();
2832
- if (!e.defaultPrevented) {
2833
- editingFocus(e);
2834
- }
2835
- },
2836
- [editingFocus, navigationFocus]
2837
- );
2838
- const onContextMenu = useTableContextMenu({
2839
- columns,
2840
- data,
2841
- dataSource,
2842
- getSelectedRows
2843
- });
2844
- const onMoveGroupColumn = useCallback19(
2845
- (columns2) => {
2846
- dataSource.groupBy = columns2.map((col) => col.name);
2847
- },
2848
- [dataSource]
2849
- );
2850
- const onRemoveGroupColumn = useCallback19(
2851
- (column) => {
2852
- if (isGroupColumn3(column)) {
2853
- dataSource.groupBy = [];
2854
- } else {
2855
- if (dataSource && dataSource.groupBy.includes(column.name)) {
2856
- dataSource.groupBy = dataSource.groupBy.filter(
2857
- (columnName) => columnName !== column.name
2858
- );
2859
- }
2860
- }
2861
- },
2862
- [dataSource]
2863
- );
2864
- const handleSelectionChange = useCallback19(
2865
- (selected) => {
2866
- dataSource.select(selected);
2867
- onSelectionChange == null ? void 0 : onSelectionChange(selected);
2868
- },
2869
- [dataSource, onSelectionChange]
2870
- );
2871
- const {
2872
- onKeyDown: selectionHookKeyDown,
2873
- onRowClick: selectionHookOnRowClick
2874
- } = useSelection({
2875
- highlightedIndexRef,
2876
- onSelect,
2877
- onSelectionChange: handleSelectionChange,
2878
- selectionModel
2879
- });
2880
- const handleKeyDown = useCallback19(
2881
- (e) => {
2882
- navigationKeyDown(e);
2883
- if (!e.defaultPrevented) {
2884
- editingKeyDown(e);
2885
- }
2886
- if (!e.defaultPrevented) {
2887
- selectionHookKeyDown(e);
2888
- }
2889
- },
2890
- [navigationKeyDown, editingKeyDown, selectionHookKeyDown]
2891
- );
2892
- const handleRowClick = useCallback19(
2893
- (row, rangeSelect, keepExistingSelection) => {
2894
- selectionHookOnRowClick(row, rangeSelect, keepExistingSelection);
2895
- onRowClickProp == null ? void 0 : onRowClickProp(row);
2896
- },
2897
- [onRowClickProp, selectionHookOnRowClick]
2898
- );
2899
- useLayoutEffectSkipFirst2(() => {
2900
- dispatchColumnAction({
2901
- type: "init",
2902
- tableConfig: config,
2903
- dataSource
2904
- });
2905
- }, [config, dataSource, dispatchColumnAction]);
2906
- const onMoveColumn = useCallback19(
2907
- (columns2) => {
2908
- console.log(`useTable onMoveColumn`, {
2909
- columns: columns2
2910
- });
2911
- const newTableConfig = {
2912
- ...tableConfig,
2913
- columns: columns2
2914
- };
2915
- dispatchColumnAction({
2916
- type: "init",
2917
- tableConfig: newTableConfig,
2918
- dataSource
2919
- });
2920
- onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(newTableConfig));
2921
- },
2922
- [dataSource, dispatchColumnAction, onConfigChange, tableConfig]
2923
- );
2924
- const handleDropRow = useCallback19(
2925
- (dragDropState) => {
2926
- onDrop == null ? void 0 : onDrop(dragDropState);
2927
- },
2928
- [onDrop]
2929
- );
2930
- const handleDataEdited = useCallback19(
2931
- async (row, columnName, value) => dataSource.applyEdit(row, columnName, value),
2932
- [dataSource]
2933
- );
2934
- const handleDragStartRow = useCallback19(
2935
- (dragDropState) => {
2936
- const { initialDragElement } = dragDropState;
2937
- const rowIndex = getIndexFromRowElement2(initialDragElement);
2938
- const row = dataRef.current.find((row2) => row2[0] === rowIndex);
2939
- if (row) {
2940
- dragDropState.setPayload(row);
2941
- } else {
2942
- }
2943
- onDragStart == null ? void 0 : onDragStart(dragDropState);
2944
- },
2945
- [dataRef, onDragStart]
2946
- );
2947
- const { onMouseDown: rowDragMouseDown, draggable: draggableRow } = useRowDragDrop({
2948
- allowDragDrop,
2949
- containerRef,
2950
- draggableClassName: `vuuTable`,
2951
- id,
2952
- onDragStart: handleDragStartRow,
2953
- onDrop: handleDropRow,
2954
- orientation: "vertical",
2955
- itemQuery: ".vuuTableRow"
2956
- });
2957
- return {
2958
- ...containerProps,
2959
- "aria-rowcount": dataSource.size,
2960
- draggableRow,
2961
- onBlur: editingBlur,
2962
- onDoubleClick: editingDoubleClick,
2963
- onFocus: handleFocus,
2964
- onKeyDown: handleKeyDown,
2965
- onMouseDown: rowDragMouseDown,
2966
- columnMap,
2967
- columns,
2968
- data,
2969
- handleContextMenuAction,
2970
- headings,
2971
- highlightedIndex: highlightedIndexRef.current,
2972
- menuBuilder,
2973
- onContextMenu,
2974
- onDataEdited: handleDataEdited,
2975
- onMoveColumn,
2976
- onMoveGroupColumn,
2977
- onRemoveGroupColumn,
2978
- onRowClick: handleRowClick,
2979
- onSortColumn: handleSort,
2980
- onResizeColumn,
2981
- onToggleGroup,
2982
- scrollProps,
2983
- // TODO don't think we need these ...
2984
- tableAttributes,
2985
- tableConfig,
2986
- viewportMeasurements
2987
- };
2988
- };
2989
-
2990
- // src/table-header/TableHeader.tsx
2991
- import { isGroupColumn as isGroupColumn4, isNotHidden as isNotHidden2 } from "@vuu-ui/vuu-utils";
2992
- import cx8 from "clsx";
2993
-
2994
- // src/table-header/useTableHeader.ts
2995
- import { useDragDropNext as useDragDrop2 } from "@vuu-ui/vuu-ui-controls";
2996
- import { moveColumnTo, visibleColumnAtIndex } from "@vuu-ui/vuu-utils";
2997
- import { useCallback as useCallback20, useRef as useRef14 } from "react";
2998
- var useTableHeader = ({
2999
- columns,
3000
- onMoveColumn,
3001
- onSortColumn,
3002
- tableConfig
3003
- }) => {
3004
- const containerRef = useRef14(null);
3005
- const handleDropColumnHeader = useCallback20(
3006
- (moveFrom, moveTo) => {
3007
- const column = columns[moveFrom];
3008
- const orderedColumns = moveColumnTo(columns, column, moveTo);
3009
- const ofColumn = ({ name }) => (col) => col.name === name;
3010
- const targetIndex = orderedColumns.findIndex(ofColumn(column));
3011
- const nextColumn = orderedColumns[targetIndex + 1];
3012
- const insertPos = nextColumn ? tableConfig.columns.findIndex(ofColumn(nextColumn)) : -1;
3013
- if (moveTo > moveFrom && insertPos !== -1) {
3014
- onMoveColumn(moveColumnTo(tableConfig.columns, column, insertPos - 1));
3015
- } else {
3016
- onMoveColumn(moveColumnTo(tableConfig.columns, column, insertPos));
3017
- }
3018
- },
3019
- [columns, onMoveColumn, tableConfig.columns]
3020
- );
3021
- const handleColumnHeaderClick = useCallback20(
3022
- (evt) => {
3023
- var _a;
3024
- const targetElement = evt.target;
3025
- const headerCell = targetElement.closest(
3026
- ".vuuTableHeaderCell"
3027
- );
3028
- const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.index) != null ? _a : "-1");
3029
- const column = visibleColumnAtIndex(columns, colIdx);
3030
- const isAdditive = evt.shiftKey;
3031
- column && onSortColumn(column, isAdditive);
3032
- },
3033
- [columns, onSortColumn]
3034
- );
3035
- const {
3036
- onMouseDown: columnHeaderDragMouseDown,
3037
- draggable: draggableColumn,
3038
- ...dragDropHook
3039
- } = useDragDrop2({
3040
- allowDragDrop: true,
3041
- containerRef,
3042
- draggableClassName: `vuuTable`,
3043
- onDrop: handleDropColumnHeader,
3044
- orientation: "horizontal",
3045
- itemQuery: ".vuuTableHeaderCell"
3046
- });
3047
- return {
3048
- containerRef,
3049
- draggableColumn,
3050
- draggedColumnIndex: dragDropHook.draggedItemIndex,
3051
- onClick: handleColumnHeaderClick,
3052
- onMouseDown: columnHeaderDragMouseDown
3053
- };
3054
- };
3055
-
3056
- // src/table-header/TableHeader.tsx
3057
- import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
3058
- var TableHeader = ({
3059
- classBase: classBase10 = "vuuTable",
3060
- columns,
3061
- headings,
3062
- onMoveColumn,
3063
- onMoveGroupColumn,
3064
- onRemoveGroupColumn,
3065
- onResizeColumn,
3066
- onSortColumn,
3067
- tableConfig,
3068
- tableId
3069
- }) => {
3070
- const {
3071
- containerRef,
3072
- draggableColumn,
3073
- draggedColumnIndex,
3074
- onClick,
3075
- onMouseDown
3076
- } = useTableHeader({
3077
- columns,
3078
- onMoveColumn,
3079
- onSortColumn,
3080
- tableConfig
3081
- });
3082
- return /* @__PURE__ */ jsxs7("div", { className: `${classBase10}-col-headings`, ref: containerRef, children: [
3083
- headings.map((colHeaders, i) => /* @__PURE__ */ jsx11("div", { className: "vuuTable-heading", children: colHeaders.map(({ label, width }, j) => /* @__PURE__ */ jsx11("div", { className: "vuuTable-headingCell", style: { width }, children: label }, j)) }, i)),
3084
- /* @__PURE__ */ jsxs7("div", { className: `${classBase10}-col-headers`, role: "row", children: [
3085
- columns.filter(isNotHidden2).map(
3086
- (col, i) => isGroupColumn4(col) ? /* @__PURE__ */ jsx11(
3087
- GroupHeaderCellNext,
3088
- {
3089
- column: col,
3090
- "data-index": i,
3091
- onMoveColumn: onMoveGroupColumn,
3092
- onRemoveColumn: onRemoveGroupColumn,
3093
- onResize: onResizeColumn
3094
- },
3095
- col.name
3096
- ) : /* @__PURE__ */ jsx11(
3097
- HeaderCell,
3098
- {
3099
- className: cx8({
3100
- "vuuDraggable-dragAway": i === draggedColumnIndex
3101
- }),
3102
- column: col,
3103
- "data-index": i,
3104
- id: `${tableId}-col-${i}`,
3105
- onClick,
3106
- onMouseDown,
3107
- onResize: onResizeColumn
3108
- },
3109
- col.name
3110
- )
3111
- ),
3112
- draggableColumn
3113
- ] })
3114
- ] });
3115
- };
3116
-
3117
- // src/Table.tsx
3118
- import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
3119
- var classBase7 = "vuuTable";
3120
- var { IDX: IDX3, RENDER_IDX } = metadataKeys7;
3121
- var TableCore = ({
3122
- Row: Row2 = Row,
3123
- allowDragDrop,
3124
- availableColumns,
3125
- config,
3126
- containerRef,
3127
- dataSource,
3128
- disableFocus = false,
3129
- highlightedIndex: highlightedIndexProp,
3130
- id: idProp,
3131
- navigationStyle = "cell",
3132
- onAvailableColumnsChange,
3133
- onConfigChange,
3134
- onDragStart,
3135
- onDrop,
3136
- onFeatureInvocation,
3137
- onHighlight,
3138
- onRowClick: onRowClickProp,
3139
- onSelect,
3140
- onSelectionChange,
3141
- renderBufferSize = 0,
3142
- rowHeight = 20,
3143
- selectionModel = "extended",
3144
- showColumnHeaders = true,
3145
- headerHeight = showColumnHeaders ? 25 : 0,
3146
- size
3147
- }) => {
3148
- const id = useId(idProp);
3149
- const {
3150
- columnMap,
3151
- columns,
3152
- data,
3153
- draggableRow,
3154
- handleContextMenuAction,
3155
- headings,
3156
- highlightedIndex,
3157
- onDataEdited,
3158
- onMoveColumn,
3159
- onMoveGroupColumn,
3160
- onRemoveGroupColumn,
3161
- onResizeColumn,
3162
- onRowClick,
3163
- onSortColumn,
3164
- onToggleGroup,
3165
- menuBuilder,
3166
- scrollProps,
3167
- tableAttributes,
3168
- tableConfig,
3169
- viewportMeasurements,
3170
- ...tableProps
3171
- } = useTable({
3172
- allowDragDrop,
3173
- availableColumns,
3174
- config,
3175
- containerRef,
3176
- dataSource,
3177
- disableFocus,
3178
- headerHeight,
3179
- highlightedIndex: highlightedIndexProp,
3180
- id,
3181
- navigationStyle,
3182
- onAvailableColumnsChange,
3183
- onConfigChange,
3184
- onDragStart,
3185
- onDrop,
3186
- onFeatureInvocation,
3187
- onHighlight,
3188
- onRowClick: onRowClickProp,
3189
- onSelect,
3190
- onSelectionChange,
3191
- renderBufferSize,
3192
- rowHeight,
3193
- selectionModel,
3194
- size
3195
- });
3196
- const className = cx9(`${classBase7}-contentContainer`, {
3197
- [`${classBase7}-colLines`]: tableAttributes.columnSeparators,
3198
- [`${classBase7}-rowLines`]: tableAttributes.rowSeparators,
3199
- // [`${classBase}-highlight`]: tableAttributes.showHighlightedRow,
3200
- [`${classBase7}-zebra`]: tableAttributes.zebraStripes
3201
- // [`${classBase}-loading`]: isDataLoading(tableProps.columns),
3202
- });
3203
- const cssVariables = {
3204
- "--content-height": `${viewportMeasurements.contentHeight}px`,
3205
- "--content-width": `${viewportMeasurements.contentWidth}px`,
3206
- "--horizontal-scrollbar-height": `${viewportMeasurements.horizontalScrollbarHeight}px`,
3207
- "--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
3208
- "--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
3209
- "--header-height": `${headerHeight}px`,
3210
- "--row-height": `${rowHeight}px`,
3211
- "--total-header-height": `${viewportMeasurements.totalHeaderHeight}px`,
3212
- "--vertical-scrollbar-width": `${viewportMeasurements.verticalScrollbarWidth}px`,
3213
- "--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
3214
- };
3215
- return /* @__PURE__ */ jsxs8(
3216
- ContextMenuProvider,
3217
- {
3218
- menuActionHandler: handleContextMenuAction,
3219
- menuBuilder,
3220
- children: [
3221
- /* @__PURE__ */ jsx12(
3222
- "div",
3223
- {
3224
- className: `${classBase7}-scrollbarContainer`,
3225
- ref: scrollProps.scrollbarContainerRef,
3226
- style: cssVariables,
3227
- children: /* @__PURE__ */ jsx12("div", { className: `${classBase7}-scrollbarContent` })
3228
- }
3229
- ),
3230
- /* @__PURE__ */ jsx12(
3231
- "div",
3232
- {
3233
- className,
3234
- ref: scrollProps.contentContainerRef,
3235
- style: cssVariables,
3236
- children: /* @__PURE__ */ jsxs8(
3237
- "div",
3238
- {
3239
- ...tableProps,
3240
- className: `${classBase7}-table`,
3241
- role: "table",
3242
- tabIndex: disableFocus ? void 0 : -1,
3243
- children: [
3244
- showColumnHeaders ? /* @__PURE__ */ jsx12(
3245
- TableHeader,
3246
- {
3247
- columns,
3248
- headings,
3249
- onMoveColumn,
3250
- onMoveGroupColumn,
3251
- onRemoveGroupColumn,
3252
- onResizeColumn,
3253
- onSortColumn,
3254
- tableConfig,
3255
- tableId: id
3256
- }
3257
- ) : null,
3258
- /* @__PURE__ */ jsx12("div", { className: `${classBase7}-body`, children: data.map((data2) => /* @__PURE__ */ jsx12(
3259
- Row2,
3260
- {
3261
- columnMap,
3262
- columns,
3263
- highlighted: highlightedIndex === data2[IDX3],
3264
- onClick: onRowClick,
3265
- onDataEdited,
3266
- row: data2,
3267
- offset: rowHeight * data2[IDX3] + viewportMeasurements.totalHeaderHeight,
3268
- onToggleGroup,
3269
- zebraStripes: tableAttributes.zebraStripes
3270
- },
3271
- data2[RENDER_IDX]
3272
- )) })
3273
- ]
3274
- }
3275
- )
3276
- }
3277
- ),
3278
- draggableRow
3279
- ]
3280
- }
3281
- );
3282
- };
3283
- var Table = forwardRef(function TableNext({
3284
- Row: Row2,
3285
- allowDragDrop,
3286
- availableColumns,
3287
- className: classNameProp,
3288
- config,
3289
- dataSource,
3290
- disableFocus,
3291
- highlightedIndex,
3292
- id,
3293
- navigationStyle,
3294
- onAvailableColumnsChange,
3295
- onConfigChange,
3296
- onDragStart,
3297
- onDrop,
3298
- onFeatureInvocation,
3299
- onHighlight,
3300
- onRowClick,
3301
- onSelect,
3302
- onSelectionChange,
3303
- renderBufferSize,
3304
- rowHeight,
3305
- selectionModel,
3306
- showColumnHeaders,
3307
- headerHeight,
3308
- style: styleProp,
3309
- ...htmlAttributes
3310
- }, forwardedRef) {
3311
- const containerRef = useRef15(null);
3312
- const [size, setSize] = useState7();
3313
- if (config === void 0) {
3314
- throw Error(
3315
- "vuu Table requires config prop. Minimum config is list of Column Descriptors"
3316
- );
3317
- }
3318
- if (dataSource === void 0) {
3319
- throw Error("vuu Table requires dataSource prop");
3320
- }
3321
- return /* @__PURE__ */ jsx12(
3322
- MeasuredContainer,
3323
- {
3324
- ...htmlAttributes,
3325
- className: cx9(classBase7, classNameProp),
3326
- id,
3327
- onResize: setSize,
3328
- ref: useForkRef(containerRef, forwardedRef),
3329
- children: size ? /* @__PURE__ */ jsx12(
3330
- TableCore,
3331
- {
3332
- Row: Row2,
3333
- allowDragDrop,
3334
- availableColumns,
3335
- config,
3336
- containerRef,
3337
- dataSource,
3338
- disableFocus,
3339
- headerHeight,
3340
- highlightedIndex,
3341
- id,
3342
- navigationStyle,
3343
- onAvailableColumnsChange,
3344
- onConfigChange,
3345
- onDragStart,
3346
- onDrop,
3347
- onFeatureInvocation,
3348
- onHighlight,
3349
- onRowClick,
3350
- onSelect,
3351
- onSelectionChange,
3352
- renderBufferSize,
3353
- rowHeight,
3354
- selectionModel,
3355
- showColumnHeaders,
3356
- size
3357
- }
3358
- ) : null
3359
- }
3360
- );
3361
- });
3362
-
3363
- // src/cell-renderers/checkbox-cell/CheckboxCell.tsx
3364
- import { memo as memo2, useCallback as useCallback21 } from "react";
3365
- import { CheckboxIcon, WarnCommit } from "@vuu-ui/vuu-ui-controls";
3366
- import { Checkbox } from "@salt-ds/core";
3367
-
3368
- // src/cell-renderers/cell-utils.ts
3369
- var dataAndColumnUnchanged = (p, p1) => p.column === p1.column && p.column.valueFormatter(p.row[p.columnMap[p.column.name]]) === p1.column.valueFormatter(p1.row[p1.columnMap[p1.column.name]]);
3370
-
3371
- // src/cell-renderers/checkbox-cell/CheckboxCell.tsx
3372
- import { dispatchCustomEvent, registerComponent } from "@vuu-ui/vuu-utils";
3373
- import { jsx as jsx13 } from "react/jsx-runtime";
3374
- var CheckboxCell = memo2(
3375
- ({ column, columnMap, onCommit = WarnCommit, row }) => {
3376
- const dataIdx = columnMap[column.name];
3377
- const isChecked = row[dataIdx];
3378
- const handleCommit = useCallback21(
3379
- (value) => async (evt) => {
3380
- const res = await onCommit(value);
3381
- if (res === true) {
3382
- dispatchCustomEvent(evt.target, "vuu-commit");
3383
- }
3384
- return res;
3385
- },
3386
- [onCommit]
3387
- );
3388
- return column.editable ? /* @__PURE__ */ jsx13(Checkbox, { checked: isChecked, onClick: handleCommit(!isChecked) }) : /* @__PURE__ */ jsx13(CheckboxIcon, { checked: isChecked, disabled: true });
3389
- },
3390
- dataAndColumnUnchanged
3391
- );
3392
- CheckboxCell.displayName = "CheckboxCell";
3393
- registerComponent("checkbox-cell", CheckboxCell, "cell-renderer", {
3394
- serverDataType: "boolean"
3395
- });
3396
-
3397
- // src/cell-renderers/input-cell/InputCell.tsx
3398
- import { registerComponent as registerComponent2 } from "@vuu-ui/vuu-utils";
3399
- import { Input } from "@salt-ds/core";
3400
- import { useEditableText } from "@vuu-ui/vuu-ui-controls";
3401
- import cx10 from "clsx";
3402
- import { jsx as jsx14 } from "react/jsx-runtime";
3403
- var classBase8 = "vuuTableInputCell";
3404
- var WarnCommit2 = () => {
3405
- console.warn(
3406
- "onCommit handler has not been provided to InputCell cell renderer"
3407
- );
3408
- return Promise.resolve(true);
3409
- };
3410
- var InputCell = ({
3411
- column,
3412
- columnMap,
3413
- onCommit = WarnCommit2,
3414
- row
3415
- }) => {
3416
- const dataIdx = columnMap[column.name];
3417
- const { align = "left", clientSideEditValidationCheck } = column;
3418
- const { warningMessage, ...editProps } = useEditableText({
3419
- initialValue: row[dataIdx],
3420
- onCommit,
3421
- clientSideEditValidationCheck
3422
- });
3423
- const endAdornment = warningMessage && align === "left" ? /* @__PURE__ */ jsx14("span", { className: `${classBase8}-icon`, "data-icon": "error" }) : void 0;
3424
- const startAdornment = warningMessage && align === "right" ? /* @__PURE__ */ jsx14("span", { className: `${classBase8}-icon`, "data-icon": "error" }) : void 0;
3425
- return /* @__PURE__ */ jsx14(
3426
- Input,
3427
- {
3428
- ...editProps,
3429
- className: cx10(classBase8, {
3430
- [`${classBase8}-error`]: warningMessage !== void 0
3431
- }),
3432
- endAdornment,
3433
- startAdornment
3434
- }
3435
- );
3436
- };
3437
- registerComponent2("input-cell", InputCell, "cell-renderer", {});
3438
-
3439
- // src/cell-renderers/toggle-cell/ToggleCell.tsx
3440
- import { WarnCommit as WarnCommit3 } from "@vuu-ui/vuu-ui-controls";
3441
- import {
3442
- dispatchCustomEvent as dispatchCustomEvent2,
3443
- isTypeDescriptor,
3444
- isValueListRenderer,
3445
- registerComponent as registerComponent3
3446
- } from "@vuu-ui/vuu-utils";
3447
- import cx11 from "clsx";
3448
- import { memo as memo3, useCallback as useCallback22 } from "react";
3449
- import { CycleStateButton } from "@vuu-ui/vuu-ui-controls";
3450
- import { jsx as jsx15 } from "react/jsx-runtime";
3451
- var classBase9 = "vuuTableToggleCell";
3452
- var getValueList = ({ name, type }) => {
3453
- if (isTypeDescriptor(type) && isValueListRenderer(type.renderer)) {
3454
- return type.renderer.values;
3455
- } else {
3456
- throw Error(
3457
- `useLookupValues column ${name} has not been configured with a values list`
3458
- );
3459
- }
3460
- };
3461
- var ToggleCell = memo3(
3462
- function ToggleCell2({
3463
- column,
3464
- columnMap,
3465
- onCommit = WarnCommit3,
3466
- row
3467
- }) {
3468
- const values = getValueList(column);
3469
- const dataIdx = columnMap[column.name];
3470
- const value = row[dataIdx];
3471
- const handleCommit = useCallback22(
3472
- (evt, value2) => {
3473
- return onCommit(value2).then((response) => {
3474
- if (response === true) {
3475
- dispatchCustomEvent2(evt.target, "vuu-commit");
3476
- }
3477
- return response;
3478
- });
3479
- },
3480
- [onCommit]
3481
- );
3482
- return /* @__PURE__ */ jsx15(
3483
- CycleStateButton,
3484
- {
3485
- className: cx11(classBase9, `${classBase9}-${column.name}`),
3486
- onCommit: handleCommit,
3487
- value,
3488
- values,
3489
- variant: "cta",
3490
- children: value
3491
- }
3492
- );
3493
- },
3494
- dataAndColumnUnchanged
3495
- );
3496
- registerComponent3("toggle-cell", ToggleCell, "cell-renderer", {});
3497
-
3498
- // src/useControlledTableNavigation.ts
3499
- import { useStateRef } from "@vuu-ui/vuu-ui-controls";
3500
- import { dispatchMouseEvent as dispatchMouseEvent2 } from "@vuu-ui/vuu-utils";
3501
- import { useCallback as useCallback23, useRef as useRef16 } from "react";
3502
- var useControlledTableNavigation = (initialValue, rowCount) => {
3503
- const tableRef = useRef16(null);
3504
- const [highlightedIndexRef, setHighlightedIndex] = useStateRef(initialValue);
3505
- const handleKeyDown = useCallback23(
3506
- (e) => {
3507
- var _a;
3508
- if (e.key === "ArrowDown") {
3509
- setHighlightedIndex((index = -1) => Math.min(rowCount - 1, index + 1));
3510
- } else if (e.key === "ArrowUp") {
3511
- setHighlightedIndex((index = -1) => Math.max(0, index - 1));
3512
- } else if (e.key === "Enter" || e.key === " ") {
3513
- const { current: rowIdx } = highlightedIndexRef;
3514
- const rowEl = (_a = tableRef.current) == null ? void 0 : _a.querySelector(
3515
- `[aria-rowindex="${rowIdx}"]`
3516
- );
3517
- if (rowEl) {
3518
- dispatchMouseEvent2(rowEl, "click");
3519
- }
3520
- }
3521
- },
3522
- [highlightedIndexRef, rowCount, setHighlightedIndex]
3523
- );
3524
- const handleHighlight = useCallback23(
3525
- (idx) => {
3526
- setHighlightedIndex(idx);
3527
- },
3528
- [setHighlightedIndex]
3529
- );
3530
- return {
3531
- highlightedIndexRef,
3532
- onHighlight: handleHighlight,
3533
- onKeyDown: handleKeyDown,
3534
- tableRef
3535
- };
3536
- };
3537
- export {
3538
- CheckboxCell,
3539
- GroupHeaderCellNext,
3540
- HeaderCell,
3541
- InputCell,
3542
- Table,
3543
- TableCell,
3544
- TableGroupCell,
3545
- ToggleCell,
3546
- dataAndColumnUnchanged,
3547
- isShowColumnSettings,
3548
- isShowTableSettings,
3549
- updateTableConfig,
3550
- useControlledTableNavigation,
3551
- useTableModel,
3552
- useTableViewport
3553
- };
1
+ import{OverflowContainer as wn}from"@vuu-ui/vuu-layout";import{useLayoutEffectSkipFirst as Rn}from"@vuu-ui/vuu-utils";import yn from"clsx";import{useCallback as Dn,useRef as Mn,useState as Hn}from"react";import sn from"clsx";import{useCallback as un}from"react";import{jsx as cn,jsxs as mn}from"react/jsx-runtime";var Co="vuuColumnHeaderPill",re=({children:e,className:o,column:t,onRemove:r,removable:n,...l})=>{if(n&&typeof r!="function")throw Error("ColumnHeaderPill onRemove prop must be provided if Pill is removable");let a=un(i=>{i.preventDefault(),i.stopPropagation(),r==null||r(t)},[t,r]);return mn("div",{...l,className:sn(Co,o),children:[e,n?cn("span",{className:`${Co}-removeButton`,role:"button","data-icon":"cross",onClick:a}):null]})};import{jsx as Se,jsxs as dn}from"react/jsx-runtime";var vo=({column:e,...o})=>{let{name:t,sorted:r}=e,n=typeof r=="number"?r<0?"arrow-down":"arrow-up":r==="A"?"arrow-up":r==="D"?"arrow-down":void 0;return dn(re,{...o,column:e,children:[Se("span",{className:"vuuGroupColumnPill-label",children:t}),n!==void 0?Se("span",{"data-icon":n}):null,typeof r=="number"?Se("span",{className:"vuuSortPosition",children:Math.abs(r)}):null]})};import{jsx as ho,jsxs as pn}from"react/jsx-runtime";var xo=({column:e})=>{if(!e.sorted)return null;let o=typeof e.sorted=="number"?e.sorted<0?"arrow-down":"arrow-up":e.sorted==="A"?"arrow-up":"arrow-down";return pn(re,{column:e,children:[ho("span",{"data-icon":o}),typeof e.sorted=="number"?ho("span",{className:"vuuSortPosition",children:Math.abs(e.sorted)}):null]})};import{useCallback as ke,useRef as bn}from"react";import{jsx as gn}from"react/jsx-runtime";var To=()=>{},fn="vuuColumnResizerNext",fe=({onDrag:e,onDragEnd:o=To,onDragStart:t=To})=>{let r=bn(0),n=ke(i=>{i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault();let s=Math.round(i.clientX),u=s-r.current;r.current=s,u!==0&&e(i,u)},[e]),l=ke(i=>{window.removeEventListener("mouseup",l),window.removeEventListener("mousemove",n),o(i)},[o,n]),a=ke(i=>{t(i),r.current=Math.round(i.clientX),window.addEventListener("mouseup",l),window.addEventListener("mousemove",n),i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault()},[t,n,l]);return gn("div",{className:fn,onMouseDown:a})};import{useCallback as Le,useRef as Cn,useState as vn}from"react";var ge=({column:e,onResize:o,rootRef:t})=>{let r=Cn(0),[n,l]=vn(!1),{name:a}=e,i=Le(()=>{if(o&&t.current){let{width:c}=t.current.getBoundingClientRect();r.current=Math.round(c),l(!0),o==null||o("begin",a)}},[a,o,t]),s=Le((c,m)=>{if(t.current&&o){let{width:f}=t.current.getBoundingClientRect(),b=Math.round(f)+m;b!==r.current&&b>0&&(o("resize",a,b),r.current=b)}},[a,o,t]),u=Le(()=>{o&&(o("end",a,r.current),setTimeout(()=>{l(!1)},80))},[a,o]);return{isResizing:n,onDrag:s,onDragStart:i,onDragEnd:u}};import{getColumnStyle as hn}from"@vuu-ui/vuu-utils";import xn from"clsx";import{useMemo as Tn}from"react";var J=(e,o,t)=>Tn(()=>{let r=xn(o,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:t&&e.endPin,[`${o}-editable`]:e.editable,[`${o}-right`]:e.align==="right"}),n=hn(e);return{className:r,style:n}},[e,o,t]);import{jsx as Ie,jsxs as Sn}from"react/jsx-runtime";import{createElement as En}from"react";var Ae="vuuTableGroupHeaderCell",Pn=(e,o)=>e===o?e:o,ze=({column:e,className:o,onMoveColumn:t,onRemoveColumn:r,onResize:n,...l})=>{let a=Mn(null),{isResizing:i,...s}=ge({column:e,onResize:n,rootRef:a}),[u,c]=Hn(e.columns),{className:m,style:f}=J(e,Ae,!0),b=u.length>1?{removable:!0,onRemove:r}:void 0,x=Dn((T,d)=>{c(v=>{let R=v.slice(),[C]=R.splice(T,1);if(d===-1){let M=R.concat(C);return t==null||t(M),M}else return R.splice(d,0,C),t==null||t(R),R})},[t]);return Rn(()=>{c(T=>Pn(T,e.columns))},[e.columns]),Sn("div",{...l,className:yn(m,o,{[`${Ae}-pending`]:e.groupConfirmed===!1}),ref:a,role:"columnheader",style:f,children:[Ie(wn,{allowDragDrop:!0,className:`${Ae}-inner`,height:24,onMoveItem:x,overflowPosition:"start",children:u.map(T=>En(vo,{...b,column:T,key:T.key}))}),Ie(re,{column:e,removable:!0,onRemove:r}),e.resizeable!==!1?Ie(fe,{...s}):null]})};import Vn from"clsx";import{useCallback as Fn,useRef as Kn}from"react";import{useContextMenu as kn}from"@vuu-ui/vuu-popups";import Ln from"clsx";import{useCallback as wo,useRef as An,useState as In}from"react";import{jsx as Nn}from"react/jsx-runtime";var zn=e=>{if(e){let{bottom:o,left:t}=e.getBoundingClientRect();return{x:t,y:o+6}}},Ro=({className:e,column:o,...t})=>{let r=An(null),[n,l]=In(!1),[a]=kn(),i=wo(()=>{l(!1)},[]),s=wo(u=>{l(!0),a(u,"column-menu",{column:o,ContextMenuProps:{onClose:i,position:zn(r.current)}})},[o,i,a]);return Nn("span",{...t,className:Ln("vuuTable-columnMenu",e,{"vuuTable-columnMenu-open":n}),"data-icon":"more-vert",onClick:s,ref:r})};import{jsx as le,jsxs as Gn}from"react/jsx-runtime";var Ce="vuuTableHeaderCell",yo=({className:e,column:o,onClick:t,onResize:r,...n})=>{var R;let{HeaderCellContentRenderer:l,HeaderCellLabelRenderer:a}=o,i=Kn(null),{isResizing:s,...u}=ge({column:o,onResize:r,rootRef:i}),c=Fn(C=>{!s&&(t==null||t(C))},[s,t]),{className:m,style:f}=J(o,Ce,!0),b=le(Ro,{column:o}),x=a?le(a,{className:`${Ce}-label`,column:o}):le("div",{className:`${Ce}-label`,children:(R=o.label)!=null?R:o.name}),T=l?[le(l,{column:o},"content")]:[],d=le(xo,{column:o}),v=o.align==="right"?[d,x].concat(T).concat(b):[b,x,d].concat(T);return Gn("div",{...n,className:Vn(m,e,{[`${Ce}-resizing`]:s}),onClick:c,ref:i,role:"columnheader",style:f,children:[...v,o.resizeable!==!1?le(fe,{...u}):null]})};import{MeasuredContainer as li}from"@vuu-ui/vuu-layout";import{ContextMenuProvider as ii}from"@vuu-ui/vuu-popups";import{metadataKeys as ai,useId as si}from"@vuu-ui/vuu-utils";import{useForkRef as ui}from"@salt-ds/core";import Pt from"clsx";import{forwardRef as ci,useRef as mi,useState as di}from"react";import{isGroupColumn as Eo,isJsonColumn as Jn,isJsonGroup as Yn,metadataKeys as Zn,isNotHidden as jn,RowSelected as qn}from"@vuu-ui/vuu-utils";import er from"clsx";import{memo as or,useCallback as So}from"react";import{isNumericColumn as $n}from"@vuu-ui/vuu-utils";import{useCallback as Do}from"react";import{jsx as Mo}from"react/jsx-runtime";var Bn="vuuTableCell",Ho=({column:e,columnMap:o,onClick:t,onDataEdited:r,row:n})=>{let{className:l,style:a}=J(e,Bn),{CellRenderer:i,name:s,valueFormatter:u}=e,c=o[s],m=Do(b=>{if(r){let x=b;return $n(e)&&typeof b=="string"&&(x=e.serverDataType==="double"?parseFloat(b):parseInt(b)),r==null?void 0:r(n,s,x)}else throw Error("TableCell onDataEdited prop not supplied for an editable cell")},[e,s,r,n]),f=Do(b=>{t==null||t(b,e)},[e,t]);return Mo("div",{className:l,onClick:t?f:void 0,role:"cell",style:a,children:i?Mo(i,{column:e,columnMap:o,onCommit:m,row:n}):u(n[c])})};import{getGroupValueAndOffset as On,metadataKeys as Wn}from"@vuu-ui/vuu-utils";import{useCallback as Un}from"react";import _n from"clsx";import{jsx as Ve,jsxs as Qn}from"react/jsx-runtime";var{IS_LEAF:Xn}=Wn,Ne="vuuTableGroupCell",Po=({column:e,onClick:o,row:t})=>{let{columns:r}=e,[n,l]=On(r,t),{className:a,style:i}=J(e,Ne),s=Un(m=>{o==null||o(m,e)},[e,o]),u=t[Xn],c=Array(l).fill(0).map((m,f)=>Ve("span",{className:`${Ne}-spacer`},f));return Qn("div",{className:_n(a,"vuuTableCell"),role:"cell",style:i,onClick:u?void 0:s,children:[c,u?null:Ve("span",{className:`${Ne}-toggle`,"data-icon":"triangle-right"}),Ve("span",{children:n})]})};import{jsx as Fe}from"react/jsx-runtime";import{createElement as lr}from"react";var{IDX:tr,IS_EXPANDED:nr,SELECTED:rr}=Zn,X="vuuTableRow",Ke=or(({className:e,columnMap:o,columns:t,highlighted:r,row:n,offset:l,onClick:a,onDataEdited:i,onToggleGroup:s,zebraStripes:u=!1,...c})=>{let{[tr]:m,[nr]:f,[rr]:b}=n,x=So(y=>{let D=y.shiftKey,E=y.ctrlKey||y.metaKey;a==null||a(n,D,E)},[a,n]),{True:T,First:d,Last:v}=qn,R=er(X,e,{[`${X}-even`]:u&&m%2===0,[`${X}-expanded`]:f,[`${X}-highlighted`]:r,[`${X}-selected`]:b&T,[`${X}-selectedStart`]:b&d,[`${X}-selectedEnd`]:b&v}),C={transform:`translate3d(0px, ${l}px, 0px)`},M=So((y,D)=>{(Eo(D)||Yn(D,n))&&(y.stopPropagation(),s==null||s(n,D))},[s,n]);return lr("div",{...c,"aria-rowindex":n[0]+1,key:`row-${n[0]}`,role:"row",className:R,onClick:x,style:C},Fe("span",{className:`${X}-selectionDecorator vuuStickyLeft`}),t.filter(jn).map(y=>{let D=Eo(y),E=Jn(y);return Fe(D?Po:Ho,{column:y,columnMap:o,onClick:D||E?M:void 0,onDataEdited:i,row:n},y.key)}),Fe("span",{className:`${X}-selectionDecorator vuuStickyRight`}))});Ke.displayName="Row";import{useDragDropNext as $l}from"@vuu-ui/vuu-ui-controls";import{applySort as Bl,buildColumnMap as Ol,getIndexFromRowElement as Wl,isGroupColumn as Ul,isJsonGroup as _l,isValidNumber as ft,metadataKeys as Xl,updateColumn as gt,useLayoutEffectSkipFirst as Ct}from"@vuu-ui/vuu-utils";import{useCallback as L,useEffect as Ql,useMemo as je,useState as vt}from"react";import{isNumericColumn as ir}from"@vuu-ui/vuu-utils";var ko=e=>(o,t)=>{let r=[];return e===void 0||(o==="header"||o==="column-menu")&&(r.push(...ar(t,e)),r.push(...cr(t,e)),r.push(...sr(t,e)),r.push(...ur(t)),r.push({action:"column-settings",icon:"cog",label:"Column Settings",options:t}),r.push({action:"table-settings",icon:"cog",label:"DataGrid Settings",options:t})),r};function ar(e,{sort:{sortDefs:o}}){let{column:t}=e,r=[];if(t===void 0)return r;let n=o.length>0;return t.sorted==="A"?r.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):t.sorted==="D"?r.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof t.sorted=="number"?(t.sorted>0?r.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):r.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),n&&Math.abs(t.sorted)<o.length&&r.push({label:"Remove from sort",action:"sort-remove",options:e}),r.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):n?(r.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),r.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),r}function sr(e,o){let{column:t}=e;if(t===void 0||o.groupBy.length===0)return[];let{name:r,label:n=r}=t;return[{label:`Aggregate ${n}`,children:[{label:"Count",action:"agg-count",options:e},{label:"Distinct",action:"agg-distinct",options:e}].concat(ir(t)?[{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 Oe=(e,o)=>({label:`Pin ${o}`,action:`column-pin-${o}`,options:e}),Ge=e=>Oe(e,"left"),$e=e=>Oe(e,"floating"),Be=e=>Oe(e,"right");function ur(e){let{column:o}=e;if(o===void 0)return[];let{pin:t}=o,r=[{label:"Hide column",action:"column-hide",options:e},{label:"Remove column",action:"column-remove",options:e}];return t===void 0?r.push({label:"Pin column",children:[Ge(e),$e(e),Be(e)]}):t==="left"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[$e(e),Be(e)]}):t==="right"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Ge(e),$e(e)]}):t==="floating"&&r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Ge(e),Be(e)]}),r}function cr(e,{groupBy:o}){let{column:t}=e,r=[];if(t===void 0)return r;let{name:n,label:l=n}=t;return o.length===0?r.push({label:`Group by ${l}`,action:"group",options:e}):r.push({label:`Add ${l} to group by`,action:"group-add",options:e}),r}import{removeColumnFromFilter as mr}from"@vuu-ui/vuu-utils";import{addGroupColumn as Lo,addSortColumn as Ao,AggregationType as dr,setAggregations as ie,setSortColumn as Io}from"@vuu-ui/vuu-utils";var pr=(e,o)=>{if(e.filterStruct&&o){let[t,r]=mr(o,e.filterStruct);return{filter:r,filterStruct:t}}else return e},{Average:br,Count:fr,Distinct:gr,High:Cr,Low:vr,Sum:hr}=dr,zo=({dataSource:e,onPersistentColumnOperation:o})=>r=>{let n=r.options;if(n.column&&e){let{column:l}=n;switch(r.menuId){case"sort-asc":return e.sort=Io(e.sort,l,"A"),!0;case"sort-dsc":return e.sort=Io(e.sort,l,"D"),!0;case"sort-add-asc":return e.sort=Ao(e.sort,l,"A"),!0;case"sort-add-dsc":return e.sort=Ao(e.sort,l,"D"),!0;case"group":return e.groupBy=Lo(e.groupBy,l),!0;case"group-add":return e.groupBy=Lo(e.groupBy,l),!0;case"column-hide":return o({type:"hideColumns",columns:[l]}),!0;case"column-remove":return e.columns=e.columns.filter(a=>a!==l.name),!0;case"filter-remove-column":return e.filter=pr(e.filter,l),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=ie(e.aggregations,l,br),!0;case"agg-high":return e.aggregations=ie(e.aggregations,l,Cr),!0;case"agg-low":return e.aggregations=ie(e.aggregations,l,vr),!0;case"agg-count":return e.aggregations=ie(e.aggregations,l,fr),!0;case"agg-distinct":return e.aggregations=ie(e.aggregations,l,gr),!0;case"agg-sum":return e.aggregations=ie(e.aggregations,l,hr),!0;case"column-pin-floating":return o({type:"pinColumn",column:l,pin:"floating"}),!0;case"column-pin-left":return o({type:"pinColumn",column:l,pin:"left"}),!0;case"column-pin-right":return o({type:"pinColumn",column:l,pin:"right"}),!0;case"column-unpin":return o({type:"pinColumn",column:l,pin:void 0}),!0;case"column-settings":return o({type:"columnSettings",column:l}),!0;case"table-settings":return o({type:"tableSettings"}),!0;default:}}return!1};var No=(e,o)=>{switch(o.type){case"col-size":return{...e,columns:e.columns.map(t=>t.name===o.column.name?{...t,width:o.width}:t)};case"column-prop":return{...e,columns:e.columns.map(t=>t.name===o.column.name?{...t,[o.property]:o.value}:t)};default:return e}};import{isCharacterKey as Rr}from"@vuu-ui/vuu-utils";import{useCallback as j}from"react";var We=e=>`.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${e})`,Ue=(e,o)=>`.vuuTable-body > [aria-rowindex='${e}'] > [role='cell']:nth-child(${o+1})`,Vo=(e,[o,t])=>{var l;let r=o===-1?We(t):Ue(o,t),n=(l=e.current)==null?void 0:l.querySelector(r);return xr(n)&&n.querySelector("button")||n},xr=e=>e.classList.contains("vuuTableCell-editable"),Fo=e=>e.querySelector(".vuuTableInputCell")!==null;function Tr(e){if(e){let o=e.ariaRowIndex;if(o!==null)return parseInt(o,10)-1}return-1}var wr=e=>e.closest('[role="row"]'),Ko=e=>Tr(wr(e));var Go=({navigate:e})=>{let o=j(()=>{e()},[e]),t=j(s=>{let u=s.target,c=u.matches("input")?u:u.querySelector("input");c&&(c.focus(),c.select())},[]),r=j(s=>{let c=s.target.querySelector("input");c&&(c.focus(),c.select())},[]),n=j(s=>{let u=s.target;Fo(u)&&(Rr(s.key)?t(s):s.key==="Enter"&&r(s))},[t,r]),l=j(s=>{let u=s.target;(u.matches("input")||u.querySelector("input"))&&(t(s),s.stopPropagation())},[t]),a=j(s=>{s.target.removeEventListener("vuu-commit",o,!0)},[o]),i=j(s=>{s.target.addEventListener("vuu-commit",o,!0)},[o]);return{onBlur:a,onDoubleClick:l,onFocus:i,onKeyDown:n}};import{getFullRange as Xe,NULL_RANGE as $o}from"@vuu-ui/vuu-utils";import{useCallback as he,useEffect as Bo,useMemo as Hr,useRef as xe,useState as Pr}from"react";import{isRowSelectedLast as yr,metadataKeys as Dr,WindowRange as Mr}from"@vuu-ui/vuu-utils";var{SELECTED:_e}=Dr,ve=class{constructor({from:o,to:t}){this.rowCount=0;this.setRowCount=o=>{o<this.data.length&&(this.data.length=o),this.rowCount=o};this.range=new Mr(o,t),this.data=new Array(Math.max(0,t-o)),this.rowCount=0}add(o){let[t]=o;if(this.isWithinRange(t)){let r=t-this.range.from;if(this.data[r]=o,o[_e]){let n=this.data[r-1];yr(n)&&(this.data[r-1]=n.slice(),this.data[r-1][_e]-=4)}}}getAtIndex(o){return this.range.isWithin(o)&&this.data[o-this.range.from]!=null?this.data[o-this.range.from]:void 0}isWithinRange(o){return this.range.isWithin(o)}setRange({from:o,to:t}){if(o!==this.range.from||t!==this.range.to){let[r,n]=this.range.overlap(o,t),l=new Array(Math.max(0,t-o));for(let a=r;a<n;a++){let i=this.getAtIndex(a);if(i){let s=a-o;l[s]=i}}this.data=l,this.range.from=o,this.range.to=t}}getSelectedRows(){return this.data.filter(o=>o[_e]!==0)}};var Er=e=>e.type==="vuu-link-created"||e.type==="vuu-link-removed",Oo=({dataSource:e,onFeatureInvocation:o,onSizeChange:t,onSubscribed:r,range:n=$o,renderBufferSize:l=0})=>{let[,a]=Pr(null),i=xe([]),s=xe(!0),u=xe(!1),c=xe($o),m=Hr(()=>new ve(Xe(n,l)),[]),f=he(d=>{for(let v of d)m.add(v);i.current=m.data,s.current?a({}):console.log("ignore update as we're not mounted")},[m]),b=he(d=>{d.type==="subscribed"?r==null||r(d):d.type==="viewport-update"?(typeof d.size=="number"&&(t==null||t(d.size),m.setRowCount(d.size)),d.rows?f(d.rows):typeof d.size=="number"&&(i.current=m.data,u.current=!0)):Er(d)?o==null||o(d):console.log(`useDataSource unexpected message ${d.type}`)},[m,o,t,r,f]),x=he(()=>m.getSelectedRows(),[m]);Bo(()=>{var d;return s.current=!0,(d=e.resume)==null||d.call(e),()=>{var v;s.current=!1,(v=e.suspend)==null||v.call(e)}},[e]),Bo(()=>{var d;e.status==="disabled"?(d=e.enable)==null||d.call(e,b):e==null||e.subscribe({range:Xe(n,l)},b)},[e,b,n,l]);let T=he(d=>{let v=Xe(d,l);m.setRange(v),e.range=c.current=v,e.emit("range",d)},[e,m,l]);return{data:i.current,dataRef:i,getSelectedRows:x,range:c.current,setRange:T}};import{useMemo as Sr,useRef as kr}from"react";var Wo=e=>{let o=kr(e);return Sr(()=>o.current,[])};import{useControlled as Lr}from"@salt-ds/core";import{useCallback as F,useEffect as Uo,useRef as Te}from"react";var Qo=new Set(["Home","End","PageUp","PageDown","ArrowDown","ArrowUp"]),Je=new Set(Qo);Je.add("ArrowLeft");Je.add("ArrowRight");var Ar=(e,o)=>{switch(o){case"cell":return Je.has(e);case"row":return Qo.has(e);default:return!1}},Ir=["Home","End","PageUp","PageDown"],_o=e=>Ir.includes(e),zr=[-1,-1],Qe=[void 0,void 0],Jo=(e,o=e.closest(".vuuTable-contentContainer"))=>{if(o){let t=o==null?void 0:o.getBoundingClientRect(),r=e.getBoundingClientRect();if(r)return r.bottom>t.bottom?["down",r.bottom-t.bottom]:r.top<t.top?["up",r.top-t.top]:Qe;throw Error("Whats going on, row not found")}else throw Error("Whats going on, scrollbar container not found")},Nr=e=>{var t;let o=e.closest(".vuuTable-contentContainer");if(o){let r=e.closest(".vuuTableRow");if(r){let n=Jo(r,o);if(n!==Qe)return n;let l=o==null?void 0:o.getBoundingClientRect(),a=(t=e.closest(".vuuTableCell"))==null?void 0:t.getBoundingClientRect();if(a){if(a.right>l.right)return["right",a.right+6-l.right];if(a.left<l.left)return["left",a.left-l.left]}else throw Error("Whats going on, cell not found")}}return Qe};function Xo(e,[o,t],r,n){return e==="ArrowUp"?o>-1?[o-1,t]:[o,t]:e==="ArrowDown"?o===-1?[0,t]:o===n-1?[o,t]:[o+1,t]:e==="ArrowRight"?t<r?[o,t+1]:[o,t]:e==="ArrowLeft"?t>1?[o,t-1]:[o,t]:[o,t]}var Yo=({columnCount:e=0,containerRef:o,disableFocus:t=!1,defaultHighlightedIndex:r,disableHighlightOnFocus:n,highlightedIndex:l,navigationStyle:a,requestScroll:i,onHighlight:s,rowCount:u=0,viewportRowCount:c})=>{var O;let m=Te([-1,-1]),f=Te(),b=Te([-1,0]),x=Te(),[T,d]=Lr({controlled:l,default:r,name:"UseKeyboardNavigation"});x.current=T;let v=F((g,h=!1)=>{s==null||s(g),d(g)},[s,d]),R=g=>g==null?void 0:g.closest("[role='columnHeader'],[role='cell']"),C=g=>{var h,w;if(g.role==="columnHeader")return[-1,parseInt((h=g.dataset.idx)!=null?h:"-1",10)];{let k=g.closest("[role='row']");if(k){let I=parseInt((w=k.ariaRowIndex)!=null?w:"-1",10),ue=Array.from(k.childNodes).indexOf(g);return[I,ue]}}return zr},M=F(g=>{var h;if(o.current){let w=Vo(o,g);if(w){w!==f.current&&((h=f.current)==null||h.removeAttribute("tabindex"),f.current=w,w.setAttribute("tabindex","0"));let[k,I]=Nr(w);k&&I&&(i==null||i({type:"scroll-distance",distance:I,direction:k})),console.log("activeCell focus"),w.focus({preventScroll:!0})}}},[o,i]),y=F((g,h,w=!1)=>{let k=[g,h];b.current=k,a==="row"?d(g):M(k),w&&(m.current=k)},[M,a,d]),D=F((g,[h,w])=>new Promise(k=>{let I=h;switch(g){case"PageDown":I=Math.min(u-1,h+c),i==null||i({type:"scroll-page",direction:"down"});break;case"PageUp":I=Math.max(0,h-c),i==null||i({type:"scroll-page",direction:"up"});break;case"Home":I=0,i==null||i({type:"scroll-end",direction:"home"});break;case"End":I=u-1,i==null||i({type:"scroll-end",direction:"end"});break}setTimeout(()=>{k([I,w])},90)}),[i,u,c]),E=F(()=>{var g;if(n!==!0&&(g=o.current)!=null&&g.contains(document.activeElement)){let h=R(document.activeElement);h&&(m.current=C(h),a==="row"&&d(m.current[0]))}},[n,o,a,d]),S=F(async g=>{let[h,w]=_o(g)?await D(g,b.current):Xo(g,b.current,e,u),[k,I]=b.current;(h!==k||w!==I)&&y(h,w,!0)},[e,D,u,y]),N=F(g=>{let{current:h}=o,w=h==null?void 0:h.querySelector(`[aria-rowindex="${g}"]`);if(w){let[k,I]=Jo(w);k&&I&&(i==null||i({type:"scroll-distance",distance:I,direction:k}))}},[o,i]),W=F(async g=>{let{current:h}=x,[w]=_o(g)?await D(g,[h!=null?h:-1,0]):Xo(g,[h!=null?h:-1,0],e,u);w!==h&&(v(w),N(w))},[e,D,u,N,v]);Uo(()=>{l!==void 0&&l!==-1&&N(l)},[l,N]);let K=F(g=>{u>0&&Ar(g.key,a)&&(g.preventDefault(),g.stopPropagation(),a==="row"?W(g.key):S(g.key))},[u,a,W,S]),G=F(g=>{let h=g.target,w=R(h);if(w){let[k,I]=C(w);y(k,I)}},[y]),H=F(()=>{v(-1)},[v]),U=F(g=>{let h=Ko(g.target);h!==-1&&h!==x.current&&v(h)},[v]),se=F(()=>{S("ArrowDown")},[S]),A=((O=o.current)==null?void 0:O.firstChild)!=null;return Uo(()=>{if(A&&f.current===void 0&&!t){let{current:g}=o,h=(g==null?void 0:g.querySelector(We(0)))||(g==null?void 0:g.querySelector(Ue(0,0)));h&&(h.setAttribute("tabindex","0"),f.current=h)}},[o,t,A]),{highlightedIndexRef:x,navigate:se,onClick:G,onFocus:E,onKeyDown:K,onMouseLeave:a==="row"?H:void 0,onMouseMove:a==="row"?U:void 0}};import{deselectItem as Vr,dispatchMouseEvent as Fr,isRowSelected as Kr,metadataKeys as Gr,selectItem as $r}from"@vuu-ui/vuu-utils";import{useCallback as Ye,useRef as Zo}from"react";var{IDX:Br}=Gr,Or=[],Wr=["Enter"," "],jo=({highlightedIndexRef:e,selectionKeys:o=Wr,selectionModel:t,onSelect:r,onSelectionChange:n})=>{let l=Zo(-1),a=Zo(Or),i=Ye(c=>o.includes(c.key),[o]),s=Ye((c,m,f)=>{let{[Br]:b}=c,{current:x}=l,{current:T}=a,v=(Kr(c)?Vr:$r)(t,T,b,m,f,x);a.current=v,l.current=b,r==null||r(c),n==null||n(v)},[r,n,t]);return{onKeyDown:Ye(c=>{if(i(c)){let{current:m}=e;if(m!==void 0&&m!==-1){let f=c.target.querySelector(`[aria-rowindex="${m}"]`);f&&Fr(f,"click")}}},[e,i]),onRowClick:s}};import{useContextMenu as Ur}from"@vuu-ui/vuu-popups";import{buildColumnMap as _r,getIndexFromRowElement as Xr}from"@vuu-ui/vuu-utils";import{useCallback as Qr}from"react";var Jr=[],qo=({columns:e,data:o,dataSource:t,getSelectedRows:r})=>{let[n]=Ur();return Qr(a=>{let i=a.target,s=i==null?void 0:i.closest("div[role='cell']"),u=i==null?void 0:i.closest("div[role='row']");if(s&&u){let{selectedRowsCount:c}=t,m=_r(e),f=Xr(u),b=Array.from(u.childNodes).indexOf(s),x=o.find(([d])=>d===f),T=e[b];n(a,"grid",{columnMap:m,columnName:T,row:x,selectedRows:c===0?Jr:r(),viewport:t.viewport})}},[e,o,t,r,n])};import{applyFilterToColumns as Yr,applyGroupByToColumns as Zr,applySortToColumns as jr,getCellRenderer as qr,getColumnHeaderContentRenderer as el,getColumnHeaderLabelRenderer as ol,getColumnLabel as tl,getTableHeadings as nl,getValueFormatter as rl,hasValidationRules as ll,isFilteredColumn as il,isGroupColumn as al,isPinned as sl,logger as ul,metadataKeys as cl,replaceColumn as q,sortPinnedColumns as et,stripFilterFromColumns as ml,subscribedOnly as dl}from"@vuu-ui/vuu-utils";import{buildValidationChecker as pl}from"@vuu-ui/vuu-ui-controls";import{useReducer as bl}from"react";var{info:Ze}=ul("useTableModel"),fl=100,gl=cl.count,Cl=({serverDataType:e})=>e===void 0,ot=(e,o)=>{let t=o==null?void 0:o.columns.find(({name:r})=>r===e.name);return t?t.serverDataType:e.serverDataType},vl=["int","long","double"],tt=e=>e===void 0?void 0:vl.includes(e)?"right":"left",nt=e=>e.type==="columnSettings",rt=e=>e.type==="tableSettings",hl=(e,o)=>{switch(Ze==null||Ze(`TableModelReducer ${o.type}`),o.type){case"init":return it(o);case"moveColumn":return Tl(e,o);case"resizeColumn":return yl(e,o);case"setTableSchema":return Dl(e,o);case"hideColumns":return wl(e,o);case"showColumns":return Rl(e,o);case"pinColumn":return Ml(e,o);case"updateColumnProp":return ae(e,o);case"tableConfig":return st(e,o);default:return console.log(`unhandled action ${o.type}`),e}},lt=(e,o)=>{let[t,r]=bl(hl,{tableConfig:e,dataSource:o},it),{columns:n,headings:l,tableConfig:a,...i}=t;return{columns:n,dispatchColumnAction:r,headings:l,tableAttributes:i,tableConfig:a}};function it({dataSource:e,tableConfig:o}){let{columns:t,...r}=o,{config:n,tableSchema:l}=e,a=t.filter(dl(n==null?void 0:n.columns)).map(at(r,l)),i=a.some(sl)?et(a):a,s={columns:i,headings:nl(i),tableConfig:o,...r};if(n){let{columns:u,...c}=n;s=st(s,{type:"tableConfig",...c})}return s}var xl=(e,o)=>o==="uppercase"?e.toUpperCase():o==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,at=(e,o)=>(t,r)=>{let{columnDefaultWidth:n=fl,columnFormatHeader:l}=e,a=ot(t,o),{align:i=tt(a),key:s,name:u,label:c=tl(t),width:m=n,...f}=t,b={...f,align:i,CellRenderer:qr(t),HeaderCellContentRenderer:el(t),HeaderCellLabelRenderer:ol(t),clientSideEditValidationCheck:ll(t.type)?pl(t.type.renderer.rules):void 0,label:xl(c,l),key:s!=null?s:r+gl,name:u,originalIdx:r,serverDataType:a,valueFormatter:rl(t,a),width:m};return al(b)&&(b.columns=b.columns.map(x=>at(e)(x,x.key))),b};function Tl(e,{column:o,moveBy:t}){let{columns:r}=e;if(typeof t=="number"){let n=r.indexOf(o),l=r.slice(),[a]=l.splice(n,1);return l.splice(n+t,0,a),{...e,columns:l}}return e}function wl(e,{columns:o}){return o.some(t=>t.hidden!==!0)?o.reduce((t,r)=>r.hidden!==!0?ae(t,{type:"updateColumnProp",column:r,hidden:!0}):t,e):e}function Rl(e,{columns:o}){return o.some(t=>t.hidden)?o.reduce((t,r)=>r.hidden?ae(t,{type:"updateColumnProp",column:r,hidden:!1}):t,e):e}function yl(e,{column:o,phase:t,width:r}){let n="updateColumnProp",l=t!=="end";switch(t){case"begin":return ae(e,{type:n,column:o,resizing:l});case"end":return ae(e,{type:n,column:o,resizing:l,width:r});case"resize":return ae(e,{type:n,column:o,width:r});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${t}`)}}function Dl(e,{tableSchema:o}){let{columns:t}=e;if(t.some(Cl)){let r=t.map(n=>{var a;let l=ot(n,o);return{...n,align:(a=n.align)!=null?a:tt(l),serverDataType:l}});return{...e,columns:r}}else return e}function Ml(e,o){let{columns:t}=e,{column:r,pin:n}=o,l=t.find(a=>a.name===r.name);return l?(t=q(t,{...l,pin:n}),t=et(t),{...e,columns:t}):e}function ae(e,o){let{columns:t,tableConfig:r}=e,{align:n,column:l,hidden:a,label:i,resizing:s,width:u}=o,c=t.find(m=>m.name===l.name);if(c&&((n==="left"||n==="right")&&(t=q(t,{...c,align:n})),typeof i=="string"&&(t=q(t,{...c,label:i})),typeof s=="boolean"&&(t=q(t,{...c,resizing:s})),typeof a=="boolean"&&(t=q(t,{...c,hidden:a})),typeof u=="number")){t=q(t,{...c,width:u});let m=r.columns.find(f=>f.name===l.name);m&&(r={...r,columns:q(r.columns,{...m,width:u})})}return{...e,columns:t,tableConfig:r}}function st(e,{confirmed:o,filter:t,groupBy:r,sort:n}){let l=r!==void 0,a=typeof(t==null?void 0:t.filter)=="string",i=n&&n.sortDefs.length>0,s=e;return l&&(s={...e,columns:Zr(s.columns,r,o)}),i&&(s={...e,columns:jr(s.columns,n)}),a?s={...e,columns:Yr(s.columns,t)}:s.columns.some(il)&&(s={...e,columns:ml(s.columns)}),s}import{useCallback as Y,useRef as de}from"react";var ut=e=>{let{scrollLeft:o,scrollTop:t}=e,{clientHeight:r,clientWidth:n,scrollHeight:l,scrollWidth:a}=e,i=o/(a-n),s=t/(l-r);return[i,s]},ct=({onAttach:e,onDetach:o})=>{let t=de(null);return Y(n=>{if(n)t.current=n,e==null||e(n);else if(t.current){let{current:l}=t;t.current=n,o==null||o(l)}},[e,o])},mt=({maxScrollLeft:e,maxScrollTop:o,onHorizontalScroll:t,onVerticalScroll:r,rowHeight:n,viewportRowCount:l})=>{let a=de(!1),i=de({scrollTop:0,scrollLeft:0}),s=de(null),u=de(null),c=Y(()=>{let{current:C}=u,{current:M}=s,{current:y}=a;if(y)a.current=!1;else if(C&&M){let[D,E]=ut(M),S=Math.round(D*e),N=Math.round(E*o);C.scrollTo({left:S,top:N,behavior:"auto"})}},[e,o]),m=Y(()=>{let{current:C}=u,{current:M}=s,{current:y}=i;if(C&&M){let{scrollLeft:D,scrollTop:E}=C,[S,N]=ut(C);a.current=!0,M.scrollLeft=Math.round(S*e),M.scrollTop=Math.round(N*o),y.scrollTop!==E&&(y.scrollTop=E,r==null||r(E,N)),y.scrollLeft!==D&&(y.scrollLeft=D,t==null||t(D))}},[e,o,t,r]),f=Y(C=>{s.current=C,C.addEventListener("scroll",c,{passive:!0})},[c]),b=Y(C=>{s.current=null,C.removeEventListener("scroll",c)},[c]),x=Y(C=>{u.current=C,C.addEventListener("scroll",m,{passive:!0})},[m]),T=Y(C=>{u.current=null,C.removeEventListener("scroll",m)},[m]),d=ct({onAttach:x,onDetach:T}),v=ct({onAttach:f,onDetach:b}),R=Y(C=>{let{current:M}=u;if(M){let{scrollLeft:y,scrollTop:D}=M;if(a.current=!1,C.type==="scroll-distance"){let E=y,S=D;C.direction==="up"||C.direction==="down"?S=Math.min(Math.max(0,D+C.distance),o):E=Math.min(Math.max(0,y+C.distance),e),M.scrollTo({top:S,left:E,behavior:"smooth"})}else if(C.type==="scroll-page"){let{direction:E}=C,S=l*(E==="down"?n:-n),N=Math.min(Math.max(0,D+S),o);M.scrollTo({top:N,left:y,behavior:"auto"})}else if(C.type==="scroll-end"){let{direction:E}=C,S=E==="end"?o:0;M.scrollTo({top:S,left:M.scrollLeft,behavior:"auto"})}}},[e,o,n,l]);return{scrollbarContainerRef:v,contentContainerRef:d,requestScroll:R}};import{useCallback as Hl,useMemo as we,useRef as Pl}from"react";import{actualRowPositioning as El,virtualRowPositioning as Sl}from"@vuu-ui/vuu-utils";var kl=15e5,Ll={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},Al=e=>{let o=0,t=0,r=0;for(let n of e){let{hidden:l,pin:a,width:i}=n,s=l?0:i;a==="left"?o+=s:a==="right"?t+=s:r+=s}return{pinnedWidthLeft:o+4,pinnedWidthRight:t+4,unpinnedWidth:r}},dt=({columns:e,headerHeight:o,headings:t,rowCount:r,rowHeight:n,size:l})=>{let a=Pl(0),s=Math.min(r,kl)*n,c=r*n-s,{pinnedWidthLeft:m,pinnedWidthRight:f,unpinnedWidth:b}=we(()=>Al(e),[e]),[x,T]=we(()=>El(n),[n]),[d,v]=we(()=>c?Sl(n,c,a):[x,T],[T,x,c,n]),R=Hl(C=>{a.current=C},[]);return we(()=>{var C;if(l){let M=t.length,y=15,D=m+b+f,E=D>l.width?y:0,S=o*(1+M),N=s-(((C=l==null?void 0:l.height)!=null?C:0)-E)+S,W=D-l.width+m,K=(l.height-o)/n,G=Number.isInteger(K)?K+1:Math.ceil(K),H=l.height-S,U=s>H?y:0;return{contentHeight:s,getRowAtPosition:v,getRowOffset:d,horizontalScrollbarHeight:E,maxScrollContainerScrollHorizontal:W,maxScrollContainerScrollVertical:N,pinnedWidthLeft:m,pinnedWidthRight:f,rowCount:G,contentWidth:D,setPctScrollTop:R,totalHeaderHeight:S,verticalScrollbarWidth:U,viewportBodyHeight:H}}else return Ll},[l,t.length,m,b,f,s,o,n,v,d,R])};import{useCallback as Il,useEffect as zl,useRef as Nl}from"react";var pt=({getRowAtPosition:e,setRange:o,viewportMeasurements:t})=>{let r=Nl(0),{rowCount:n}=t,l=Il(a=>{let i=e(a);i!==r.current&&(r.current=i,o({from:i,to:i+n}))},[e,o,n]);return zl(()=>{let{current:a}=r,i={from:a,to:a+n};o(i)},[o,n]),{onVerticalScroll:l}};import{useLayoutProviderDispatch as Vl}from"@vuu-ui/vuu-layout";import{getCalculatedColumnType as Fl}from"@vuu-ui/vuu-utils";import{useCallback as ee,useRef as Kl,useState as Gl}from"react";var bt=({availableColumns:e,onAvailableColumnsChange:o,onConfigChange:t,onCreateCalculatedColumn:r,onDataSourceConfigChange:n,tableConfig:l})=>{let a=Vl(),i=Kl(),[s,u]=Gl(e),c=ee((d,v,R)=>{a({type:"set-props",path:"#context-panel",props:{expanded:!0,content:{type:d,props:R},title:v}})},[a]),m=ee(()=>{requestAnimationFrame(()=>{var d;(d=i.current)==null||d.call(i)})},[]),f=ee(d=>{let v=s.concat({name:d.name,serverDataType:Fl(d)});u(v),o==null||o(v),requestAnimationFrame(()=>{var R;(R=i.current)==null||R.call(i)}),r(d)},[s,o,r]),b=ee(d=>{c("ColumnSettings","Column Settings",{column:d.column,onCancelCreateColumn:m,onConfigChange:t,onCreateCalculatedColumn:f,tableConfig:l,vuuTable:d.vuuTable})},[m,f,t,c,l]),x=ee(()=>{b({column:{name:"::",serverDataType:"string"},type:"columnSettings",vuuTable:{module:"SIMUL",table:"instruments"}})},[b]),T=ee(d=>{let v=l.columns.find(R=>R.name===d);v&&b({type:"columnSettings",column:v,vuuTable:{module:"SIMUL",table:"instruments"}})},[b,l.columns]);return i.current=ee(()=>{c("TableSettings","DataGrid Settings",{availableColumns:s!=null?s:l.columns.map(({name:d,serverDataType:v})=>({name:d,serverDataType:v})),onAddCalculatedColumn:x,onConfigChange:t,onDataSourceConfigChange:n,onNavigateToColumn:T,tableConfig:l})},[s,x,T,t,n,c,l]),{showColumnSettingsPanel:b,showTableSettingsPanel:i.current}};var Re=e=>e,{KEY:Jl,IS_EXPANDED:ht,IS_LEAF:xt}=Xl,Yl={draggable:void 0,onMouseDown:void 0},Zl=()=>Yl,jl=(e,o)=>({...e,columns:e.columns.concat(o)}),Tt=({allowDragDrop:e=!1,availableColumns:o,config:t,containerRef:r,dataSource:n,disableFocus:l,headerHeight:a=25,highlightedIndex:i,id:s,navigationStyle:u="cell",onAvailableColumnsChange:c,onConfigChange:m,onDragStart:f,onDrop:b,onFeatureInvocation:x,onHighlight:T,onRowClick:d,onSelect:v,onSelectionChange:R,renderBufferSize:C=0,rowHeight:M=20,selectionModel:y,size:D})=>{let[E,S]=vt(n.size);if(n===void 0)throw Error("no data source provided to Vuu Table");let N=e?$l:Zl,W=je(()=>ko(n),[n]),K=L(p=>{S(p)},[]),{columns:G,dispatchColumnAction:H,headings:U,tableAttributes:se,tableConfig:A}=lt(t,n);Ct(()=>{H({type:"init",dataSource:n,tableConfig:A})},[A,n,H]);let O=L(p=>{H({type:"init",tableConfig:p,dataSource:n}),m==null||m(Re(p))},[n,H,m]),[g,h]=vt(),[w,k]=je(()=>{let p=(P,z)=>{let V=gt(G,P,{width:z});h(V)};return[g!=null?g:G,p]},[G,g]),I=je(()=>Ol(n.columns),[n.columns]),{getRowAtPosition:ue,getRowOffset:oo,setPctScrollTop:to,..._}=dt({columns:w,headerHeight:a,headings:U,rowCount:E,rowHeight:M,size:D}),oe=Wo({from:0,to:_.rowCount}),He=L(({tableSchema:p})=>{p?H({type:"setTableSchema",tableSchema:p}):console.log("subscription message with no schema")},[H]),{data:$,dataRef:pe,getSelectedRows:Pe,range:be,setRange:te}=Oo({dataSource:n,onFeatureInvocation:x,renderBufferSize:C,onSizeChange:K,onSubscribed:He,range:oe}),At=L(p=>{console.log("settings changed"),H({type:"init",tableConfig:p,dataSource:n}),m==null||m(Re(p))},[n,H,m]),It=L(p=>{n.config={...n.config,...p}},[n]);Ql(()=>{n.on("config",(p,P)=>{H({type:"tableConfig",...p,confirmed:P})})},[n,H]);let zt=L(p=>{n.columns=n.columns.concat(p.name),O(jl(A,p))},[n,A,O]),no=L(p=>{let{columns:P}=p,z=P.map(B=>B.name),V={...A,columns:A.columns.map(B=>z.includes(B.name)?{...B,hidden:!0}:B)};O(V)},[A,O]),ro=L(p=>{O({...A,columns:gt(A.columns,{...p.column,pin:p.pin})})},[A,O]),{showColumnSettingsPanel:lo,showTableSettingsPanel:io}=bt({availableColumns:o!=null?o:A.columns.map(({name:p,serverDataType:P="string"})=>({name:p,serverDataType:P})),onAvailableColumnsChange:c,onConfigChange:At,onCreateCalculatedColumn:zt,onDataSourceConfigChange:It,tableConfig:A}),Nt=L(p=>{if(nt(p))lo(p);else if(rt(p))io();else switch(p.type){case"hideColumns":return no(p);case"pinColumn":return ro(p);default:H(p)}},[H,no,ro,lo,io]),Vt=zo({dataSource:n,onPersistentColumnOperation:Nt}),Ft=L((p,P=!1,z)=>{n&&(n.sort=Bl(n.sort,p,P,z))},[n]),Kt=L((p,P,z)=>{let V=w.find(B=>B.name===P);if(V)p==="resize"?ft(z)&&k(P,z):p==="end"?ft(z)&&(H({type:"resizeColumn",phase:p,column:V,width:z}),h(void 0),m==null||m(Re(No(A,{type:"col-size",column:V,width:z})))):(h(void 0),H({type:"resizeColumn",phase:p,column:V,width:z}));else throw Error(`useDataTable.handleColumnResize, column ${P} not found`)},[w,A,H,m,k]),Gt=L((p,P)=>{var B,go;let z=_l(P,p),V=p[Jl];if(p[ht]){if(n.closeTreeNode(V,!0),z){let ce=w.indexOf(P),me=(B=n.getRowsAtDepth)==null?void 0:B.call(n,ce+1);me&&!me.some(ne=>ne[ht]||ne[xt])&&H({type:"hideColumns",columns:w.slice(ce+2)})}}else if(n.openTreeNode(V),z){let ce=(go=n.getChildRows)==null?void 0:go.call(n,V),me=w.indexOf(P)+1,ne=[w[me]];ce&&ce.some(Ee=>Ee[xt])&&ne.push(w[me+1]),ne.some(Ee=>Ee.hidden)&&H({type:"showColumns",columns:ne})}},[w,n,H]),{onVerticalScroll:ao}=pt({columns:w,getRowAtPosition:ue,setRange:te,viewportMeasurements:_}),$t=L(p=>{ao(p)},[ao]),{requestScroll:Bt,...Ot}=mt({maxScrollLeft:_.maxScrollContainerScrollHorizontal,maxScrollTop:_.maxScrollContainerScrollVertical,rowHeight:M,onVerticalScroll:$t,viewportRowCount:_.rowCount}),{highlightedIndexRef:so,navigate:Wt,onFocus:uo,onKeyDown:co,...Ut}=Yo({columnCount:w.filter(p=>p.hidden!==!0).length,containerRef:r,disableFocus:l,highlightedIndex:i,navigationStyle:u,requestScroll:Bt,rowCount:n==null?void 0:n.size,onHighlight:T,viewportRange:be,viewportRowCount:_.rowCount}),{onBlur:_t,onDoubleClick:Xt,onKeyDown:mo,onFocus:po}=Go({navigate:Wt}),Qt=L(p=>{uo(),p.defaultPrevented||po(p)},[po,uo]),Jt=qo({columns:w,data:$,dataSource:n,getSelectedRows:Pe}),Yt=L(p=>{n.groupBy=p.map(P=>P.name)},[n]),Zt=L(p=>{Ul(p)?n.groupBy=[]:n&&n.groupBy.includes(p.name)&&(n.groupBy=n.groupBy.filter(P=>P!==p.name))},[n]),jt=L(p=>{n.select(p),R==null||R(p)},[n,R]),{onKeyDown:bo,onRowClick:fo}=jo({highlightedIndexRef:so,onSelect:v,onSelectionChange:jt,selectionModel:y}),qt=L(p=>{co(p),p.defaultPrevented||mo(p),p.defaultPrevented||bo(p)},[co,mo,bo]),en=L((p,P,z)=>{fo(p,P,z),d==null||d(p)},[d,fo]);Ct(()=>{H({type:"init",tableConfig:t,dataSource:n})},[t,n,H]);let on=L(p=>{console.log("useTable onMoveColumn",{columns:p});let P={...A,columns:p};H({type:"init",tableConfig:P,dataSource:n}),m==null||m(Re(P))},[n,H,m,A]),tn=L(p=>{b==null||b(p)},[b]),nn=L(async(p,P,z)=>n.applyEdit(p,P,z),[n]),rn=L(p=>{let{initialDragElement:P}=p,z=Wl(P),V=pe.current.find(B=>B[0]===z);V&&p.setPayload(V),f==null||f(p)},[pe,f]),{onMouseDown:ln,draggable:an}=N({allowDragDrop:e,containerRef:r,draggableClassName:"vuuTable",id:s,onDragStart:rn,onDrop:tn,orientation:"vertical",itemQuery:".vuuTableRow"});return{...Ut,"aria-rowcount":n.size,draggableRow:an,onBlur:_t,onDoubleClick:Xt,onFocus:Qt,onKeyDown:qt,onMouseDown:ln,columnMap:I,columns:w,data:$,handleContextMenuAction:Vt,headings:U,highlightedIndex:so.current,menuBuilder:W,onContextMenu:Jt,onDataEdited:nn,onMoveColumn:on,onMoveGroupColumn:Yt,onRemoveGroupColumn:Zt,onRowClick:en,onSortColumn:Ft,onResizeColumn:Kt,onToggleGroup:Gt,scrollProps:Ot,tableAttributes:se,tableConfig:A,viewportMeasurements:_}};import{isGroupColumn as ti,isNotHidden as ni}from"@vuu-ui/vuu-utils";import ri from"clsx";import{useDragDropNext as ql}from"@vuu-ui/vuu-ui-controls";import{moveColumnTo as qe,visibleColumnAtIndex as ei}from"@vuu-ui/vuu-utils";import{useCallback as wt,useRef as oi}from"react";var Rt=({columns:e,onMoveColumn:o,onSortColumn:t,tableConfig:r})=>{let n=oi(null),l=wt((c,m)=>{let f=e[c],b=qe(e,f,m),x=({name:R})=>C=>C.name===R,T=b.findIndex(x(f)),d=b[T+1],v=d?r.columns.findIndex(x(d)):-1;m>c&&v!==-1?o(qe(r.columns,f,v-1)):o(qe(r.columns,f,v))},[e,o,r.columns]),a=wt(c=>{var d;let f=c.target.closest(".vuuTableHeaderCell"),b=parseInt((d=f==null?void 0:f.dataset.index)!=null?d:"-1"),x=ei(e,b),T=c.shiftKey;x&&t(x,T)},[e,t]),{onMouseDown:i,draggable:s,...u}=ql({allowDragDrop:!0,containerRef:n,draggableClassName:"vuuTable",onDrop:l,orientation:"horizontal",itemQuery:".vuuTableHeaderCell"});return{containerRef:n,draggableColumn:s,draggedColumnIndex:u.draggedItemIndex,onClick:a,onMouseDown:i}};import{jsx as ye,jsxs as yt}from"react/jsx-runtime";var Dt=({classBase:e="vuuTable",columns:o,headings:t,onMoveColumn:r,onMoveGroupColumn:n,onRemoveGroupColumn:l,onResizeColumn:a,onSortColumn:i,tableConfig:s,tableId:u})=>{let{containerRef:c,draggableColumn:m,draggedColumnIndex:f,onClick:b,onMouseDown:x}=Rt({columns:o,onMoveColumn:r,onSortColumn:i,tableConfig:s});return yt("div",{className:`${e}-col-headings`,ref:c,children:[t.map((T,d)=>ye("div",{className:"vuuTable-heading",children:T.map(({label:v,width:R},C)=>ye("div",{className:"vuuTable-headingCell",style:{width:R},children:v},C))},d)),yt("div",{className:`${e}-col-headers`,role:"row",children:[o.filter(ni).map((T,d)=>ti(T)?ye(ze,{column:T,"data-index":d,onMoveColumn:n,onRemoveColumn:l,onResize:a},T.name):ye(yo,{className:ri({"vuuDraggable-dragAway":d===f}),column:T,"data-index":d,id:`${u}-col-${d}`,onClick:b,onMouseDown:x,onResize:a},T.name)),m]})]})};import{jsx as Z,jsxs as Ht}from"react/jsx-runtime";var Q="vuuTable",{IDX:Mt,RENDER_IDX:pi}=ai,bi=({Row:e=Ke,allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:a=!1,highlightedIndex:i,id:s,navigationStyle:u="cell",onAvailableColumnsChange:c,onConfigChange:m,onDragStart:f,onDrop:b,onFeatureInvocation:x,onHighlight:T,onRowClick:d,onSelect:v,onSelectionChange:R,renderBufferSize:C=0,rowHeight:M=20,selectionModel:y="extended",showColumnHeaders:D=!0,headerHeight:E=D?25:0,size:S})=>{let N=si(s),{columnMap:W,columns:K,data:G,draggableRow:H,handleContextMenuAction:U,headings:se,highlightedIndex:A,onDataEdited:O,onMoveColumn:g,onMoveGroupColumn:h,onRemoveGroupColumn:w,onResizeColumn:k,onRowClick:I,onSortColumn:ue,onToggleGroup:oo,menuBuilder:to,scrollProps:_,tableAttributes:oe,tableConfig:He,viewportMeasurements:$,...pe}=Tt({allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:a,headerHeight:E,highlightedIndex:i,id:N,navigationStyle:u,onAvailableColumnsChange:c,onConfigChange:m,onDragStart:f,onDrop:b,onFeatureInvocation:x,onHighlight:T,onRowClick:d,onSelect:v,onSelectionChange:R,renderBufferSize:C,rowHeight:M,selectionModel:y,size:S}),Pe=Pt(`${Q}-contentContainer`,{[`${Q}-colLines`]:oe.columnSeparators,[`${Q}-rowLines`]:oe.rowSeparators,[`${Q}-zebra`]:oe.zebraStripes}),be={"--content-height":`${$.contentHeight}px`,"--content-width":`${$.contentWidth}px`,"--horizontal-scrollbar-height":`${$.horizontalScrollbarHeight}px`,"--pinned-width-left":`${$.pinnedWidthLeft}px`,"--pinned-width-right":`${$.pinnedWidthRight}px`,"--header-height":`${E}px`,"--row-height":`${M}px`,"--total-header-height":`${$.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${$.verticalScrollbarWidth}px`,"--viewport-body-height":`${$.viewportBodyHeight}px`};return Ht(ii,{menuActionHandler:U,menuBuilder:to,children:[Z("div",{className:`${Q}-scrollbarContainer`,ref:_.scrollbarContainerRef,style:be,children:Z("div",{className:`${Q}-scrollbarContent`})}),Z("div",{className:Pe,ref:_.contentContainerRef,style:be,children:Ht("div",{...pe,className:`${Q}-table`,role:"table",tabIndex:a?void 0:-1,children:[D?Z(Dt,{columns:K,headings:se,onMoveColumn:g,onMoveGroupColumn:h,onRemoveGroupColumn:w,onResizeColumn:k,onSortColumn:ue,tableConfig:He,tableId:N}):null,Z("div",{className:`${Q}-body`,children:G.map(te=>Z(e,{columnMap:W,columns:K,highlighted:A===te[Mt],onClick:I,onDataEdited:O,row:te,offset:M*te[Mt]+$.totalHeaderHeight,onToggleGroup:oo,zebraStripes:oe.zebraStripes},te[pi]))})]})}),H]})},am=ci(function({Row:o,allowDragDrop:t,availableColumns:r,className:n,config:l,dataSource:a,disableFocus:i,highlightedIndex:s,id:u,navigationStyle:c,onAvailableColumnsChange:m,onConfigChange:f,onDragStart:b,onDrop:x,onFeatureInvocation:T,onHighlight:d,onRowClick:v,onSelect:R,onSelectionChange:C,renderBufferSize:M,rowHeight:y,selectionModel:D,showColumnHeaders:E,headerHeight:S,style:N,...W},K){let G=mi(null),[H,U]=di();if(l===void 0)throw Error("vuu Table requires config prop. Minimum config is list of Column Descriptors");if(a===void 0)throw Error("vuu Table requires dataSource prop");return Z(li,{...W,className:Pt(Q,n),id:u,onResize:U,ref:ui(G,K),children:H?Z(bi,{Row:o,allowDragDrop:t,availableColumns:r,config:l,containerRef:G,dataSource:a,disableFocus:i,headerHeight:S,highlightedIndex:s,id:u,navigationStyle:c,onAvailableColumnsChange:m,onConfigChange:f,onDragStart:b,onDrop:x,onFeatureInvocation:T,onHighlight:d,onRowClick:v,onSelect:R,onSelectionChange:C,renderBufferSize:M,rowHeight:y,selectionModel:D,showColumnHeaders:E,size:H}):null})});import{memo as fi,useCallback as gi}from"react";import{CheckboxIcon as Ci,WarnCommit as vi}from"@vuu-ui/vuu-ui-controls";import{Checkbox as hi}from"@salt-ds/core";var De=(e,o)=>e.column===o.column&&e.column.valueFormatter(e.row[e.columnMap[e.column.name]])===o.column.valueFormatter(o.row[o.columnMap[o.column.name]]);import{dispatchCustomEvent as xi,registerComponent as Ti}from"@vuu-ui/vuu-utils";import{jsx as Et}from"react/jsx-runtime";var St=fi(({column:e,columnMap:o,onCommit:t=vi,row:r})=>{let n=o[e.name],l=r[n],a=gi(i=>async s=>{let u=await t(i);return u===!0&&xi(s.target,"vuu-commit"),u},[t]);return e.editable?Et(hi,{checked:l,onClick:a(!l)}):Et(Ci,{checked:l,disabled:!0})},De);St.displayName="CheckboxCell";Ti("checkbox-cell",St,"cell-renderer",{serverDataType:"boolean"});import{registerComponent as wi}from"@vuu-ui/vuu-utils";import{Input as Ri}from"@salt-ds/core";import{useEditableText as yi}from"@vuu-ui/vuu-ui-controls";import Di from"clsx";import{jsx as eo}from"react/jsx-runtime";var Me="vuuTableInputCell",Mi=()=>(console.warn("onCommit handler has not been provided to InputCell cell renderer"),Promise.resolve(!0)),Hi=({column:e,columnMap:o,onCommit:t=Mi,row:r})=>{let n=o[e.name],{align:l="left",clientSideEditValidationCheck:a}=e,{warningMessage:i,...s}=yi({initialValue:r[n],onCommit:t,clientSideEditValidationCheck:a}),u=i&&l==="left"?eo("span",{className:`${Me}-icon`,"data-icon":"error"}):void 0,c=i&&l==="right"?eo("span",{className:`${Me}-icon`,"data-icon":"error"}):void 0;return eo(Ri,{...s,className:Di(Me,{[`${Me}-error`]:i!==void 0}),endAdornment:u,startAdornment:c})};wi("input-cell",Hi,"cell-renderer",{});import{WarnCommit as Pi}from"@vuu-ui/vuu-ui-controls";import{dispatchCustomEvent as Ei,isTypeDescriptor as Si,isValueListRenderer as ki,registerComponent as Li}from"@vuu-ui/vuu-utils";import Ai from"clsx";import{memo as Ii,useCallback as zi}from"react";import{CycleStateButton as Ni}from"@vuu-ui/vuu-ui-controls";import{jsx as Ki}from"react/jsx-runtime";var kt="vuuTableToggleCell",Vi=({name:e,type:o})=>{if(Si(o)&&ki(o.renderer))return o.renderer.values;throw Error(`useLookupValues column ${e} has not been configured with a values list`)},Fi=Ii(function({column:o,columnMap:t,onCommit:r=Pi,row:n}){let l=Vi(o),a=t[o.name],i=n[a],s=zi((u,c)=>r(c).then(m=>(m===!0&&Ei(u.target,"vuu-commit"),m)),[r]);return Ki(Ni,{className:Ai(kt,`${kt}-${o.name}`),onCommit:s,value:i,values:l,variant:"cta",children:i})},De);Li("toggle-cell",Fi,"cell-renderer",{});import{useStateRef as Gi}from"@vuu-ui/vuu-ui-controls";import{dispatchMouseEvent as $i}from"@vuu-ui/vuu-utils";import{useCallback as Lt,useRef as Bi}from"react";var od=(e,o)=>{let t=Bi(null),[r,n]=Gi(e),l=Lt(i=>{var s;if(i.key==="ArrowDown")n((u=-1)=>Math.min(o-1,u+1));else if(i.key==="ArrowUp")n((u=-1)=>Math.max(0,u-1));else if(i.key==="Enter"||i.key===" "){let{current:u}=r,c=(s=t.current)==null?void 0:s.querySelector(`[aria-rowindex="${u}"]`);c&&$i(c,"click")}},[r,o,n]),a=Lt(i=>{n(i)},[n]);return{highlightedIndexRef:r,onHighlight:a,onKeyDown:l,tableRef:t}};export{St as CheckboxCell,ze as GroupHeaderCellNext,yo as HeaderCell,Hi as InputCell,am as Table,Ho as TableCell,Po as TableGroupCell,Fi as ToggleCell,De as dataAndColumnUnchanged,nt as isShowColumnSettings,rt as isShowTableSettings,No as updateTableConfig,od as useControlledTableNavigation,lt as useTableModel,dt as useTableViewport};
3554
2
  //# sourceMappingURL=index.js.map