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