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