@vuu-ui/vuu-table 0.7.0-debug → 0.7.1-debug
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 +125 -72
- package/cjs/index.js.map +4 -4
- package/esm/index.js +106 -48
- package/esm/index.js.map +4 -4
- package/package.json +5 -5
- package/types/Table.d.ts +1 -1
- package/types/context-menu/index.d.ts +1 -1
- package/types/context-menu/{useContextMenu.d.ts → useTableContextMenu.d.ts} +1 -1
- package/types/index.d.ts +3 -0
- package/types/useMeasuredContainer.d.ts +5 -0
- package/types/useTable.d.ts +2 -2
package/esm/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// src/Table.tsx
|
|
2
|
-
import { ContextMenuProvider } from "@vuu-ui/vuu-popups";
|
|
3
|
-
import { Button, useIdMemo } from "@salt-ds/core";
|
|
4
|
-
|
|
5
1
|
// src/context-menu/buildContextMenuDescriptors.ts
|
|
6
2
|
import { isNumericColumn } from "@vuu-ui/vuu-utils";
|
|
7
3
|
var buildContextMenuDescriptors = (dataSource) => (location, options) => {
|
|
@@ -217,7 +213,7 @@ function buildGroupMenuItems(options, { groupBy }) {
|
|
|
217
213
|
return menuItems;
|
|
218
214
|
}
|
|
219
215
|
|
|
220
|
-
// src/context-menu/
|
|
216
|
+
// src/context-menu/useTableContextMenu.ts
|
|
221
217
|
import { removeColumnFromFilter } from "@vuu-ui/vuu-filters";
|
|
222
218
|
import {
|
|
223
219
|
addGroupColumn,
|
|
@@ -241,7 +237,7 @@ var removeFilterColumn = (dataSourceFilter, column) => {
|
|
|
241
237
|
}
|
|
242
238
|
};
|
|
243
239
|
var { Average, Count, High, Low, Sum } = AggregationType;
|
|
244
|
-
var
|
|
240
|
+
var useTableContextMenu = ({
|
|
245
241
|
dataSource,
|
|
246
242
|
onPersistentColumnOperation
|
|
247
243
|
}) => {
|
|
@@ -296,6 +292,10 @@ var useContextMenu = ({
|
|
|
296
292
|
return handleContextMenuAction;
|
|
297
293
|
};
|
|
298
294
|
|
|
295
|
+
// src/Table.tsx
|
|
296
|
+
import { ContextMenuProvider } from "@vuu-ui/vuu-popups";
|
|
297
|
+
import { Button, useIdMemo } from "@salt-ds/core";
|
|
298
|
+
|
|
299
299
|
// src/RowBasedTable.tsx
|
|
300
300
|
import {
|
|
301
301
|
buildColumnMap,
|
|
@@ -322,7 +322,12 @@ import { memo as memo2, useCallback as useCallback3 } from "react";
|
|
|
322
322
|
import { getColumnStyle, metadataKeys } from "@vuu-ui/vuu-utils";
|
|
323
323
|
import { EditableLabel } from "@heswell/salt-lab";
|
|
324
324
|
import cx from "classnames";
|
|
325
|
-
import {
|
|
325
|
+
import {
|
|
326
|
+
memo,
|
|
327
|
+
useCallback,
|
|
328
|
+
useRef,
|
|
329
|
+
useState
|
|
330
|
+
} from "react";
|
|
326
331
|
import { jsx } from "react/jsx-runtime";
|
|
327
332
|
var { KEY } = metadataKeys;
|
|
328
333
|
var TableCell = memo(
|
|
@@ -355,9 +360,12 @@ var TableCell = memo(
|
|
|
355
360
|
setEditing(true);
|
|
356
361
|
}
|
|
357
362
|
};
|
|
358
|
-
const handleClick = useCallback(
|
|
359
|
-
|
|
360
|
-
|
|
363
|
+
const handleClick = useCallback(
|
|
364
|
+
(evt) => {
|
|
365
|
+
onClick == null ? void 0 : onClick(evt, column);
|
|
366
|
+
},
|
|
367
|
+
[column, onClick]
|
|
368
|
+
);
|
|
361
369
|
const handleEnterEditMode = () => {
|
|
362
370
|
setEditing(true);
|
|
363
371
|
};
|
|
@@ -443,9 +451,12 @@ var getGroupValueAndOffset = (columns, row) => {
|
|
|
443
451
|
var TableGroupCell = ({ column, onClick, row }) => {
|
|
444
452
|
const { columns } = column;
|
|
445
453
|
const [value, offset] = getGroupValueAndOffset(columns, row);
|
|
446
|
-
const handleClick = useCallback2(
|
|
447
|
-
|
|
448
|
-
|
|
454
|
+
const handleClick = useCallback2(
|
|
455
|
+
(evt) => {
|
|
456
|
+
onClick == null ? void 0 : onClick(evt, column);
|
|
457
|
+
},
|
|
458
|
+
[column, onClick]
|
|
459
|
+
);
|
|
449
460
|
const style = getColumnStyle2(column);
|
|
450
461
|
const isLeaf = row[IS_LEAF];
|
|
451
462
|
const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-spacer" }, i));
|
|
@@ -497,8 +508,9 @@ var TableRow = memo2(function Row({
|
|
|
497
508
|
[onClick, row]
|
|
498
509
|
);
|
|
499
510
|
const handleGroupCellClick = useCallback3(
|
|
500
|
-
(column) => {
|
|
511
|
+
(evt, column) => {
|
|
501
512
|
if (isGroupColumn(column) || isJsonGroup(column, row)) {
|
|
513
|
+
evt.stopPropagation();
|
|
502
514
|
onToggleGroup == null ? void 0 : onToggleGroup(row, column);
|
|
503
515
|
}
|
|
504
516
|
},
|
|
@@ -716,15 +728,15 @@ var SortIndicator = ({ sorted }) => {
|
|
|
716
728
|
};
|
|
717
729
|
|
|
718
730
|
// src/TableHeaderCell.tsx
|
|
719
|
-
import { useContextMenu as
|
|
731
|
+
import { useContextMenu as useContextMenu2 } from "@vuu-ui/vuu-popups";
|
|
720
732
|
|
|
721
733
|
// src/filter-indicator.tsx
|
|
722
|
-
import { useContextMenu
|
|
734
|
+
import { useContextMenu } from "@vuu-ui/vuu-popups";
|
|
723
735
|
import cx5 from "classnames";
|
|
724
736
|
import { useCallback as useCallback6 } from "react";
|
|
725
737
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
726
738
|
var FilterIndicator = ({ column, filter }) => {
|
|
727
|
-
const showContextMenu =
|
|
739
|
+
const showContextMenu = useContextMenu();
|
|
728
740
|
const handleClick = useCallback6(
|
|
729
741
|
(evt) => {
|
|
730
742
|
evt.stopPropagation();
|
|
@@ -762,7 +774,7 @@ var TableHeaderCell = ({
|
|
|
762
774
|
onResize,
|
|
763
775
|
rootRef
|
|
764
776
|
});
|
|
765
|
-
const showContextMenu =
|
|
777
|
+
const showContextMenu = useContextMenu2();
|
|
766
778
|
const dragTimerRef = useRef5(null);
|
|
767
779
|
const handleContextMenu = (e) => {
|
|
768
780
|
showContextMenu(e, "header", { column });
|
|
@@ -927,7 +939,7 @@ import {
|
|
|
927
939
|
import {
|
|
928
940
|
useCallback as useCallback18,
|
|
929
941
|
useEffect as useEffect5,
|
|
930
|
-
useMemo as
|
|
942
|
+
useMemo as useMemo7,
|
|
931
943
|
useRef as useRef15,
|
|
932
944
|
useState as useState5
|
|
933
945
|
} from "react";
|
|
@@ -1452,7 +1464,8 @@ var useKeyboardNavigation = ({
|
|
|
1452
1464
|
};
|
|
1453
1465
|
|
|
1454
1466
|
// src/useMeasuredContainer.ts
|
|
1455
|
-
import {
|
|
1467
|
+
import { isValidNumber } from "@vuu-ui/vuu-utils";
|
|
1468
|
+
import { useCallback as useCallback13, useMemo as useMemo4, useRef as useRef10, useState as useState3 } from "react";
|
|
1456
1469
|
|
|
1457
1470
|
// src/useResizeObserver.ts
|
|
1458
1471
|
import { useCallback as useCallback12, useEffect as useEffect3, useRef as useRef9 } from "react";
|
|
@@ -1574,6 +1587,25 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
|
|
|
1574
1587
|
// src/useMeasuredContainer.ts
|
|
1575
1588
|
var ClientWidthHeight = ["clientHeight", "clientWidth"];
|
|
1576
1589
|
var isNumber = (val) => Number.isFinite(val);
|
|
1590
|
+
var FULL_SIZE = { height: "100%", width: "100%" };
|
|
1591
|
+
var getInitialCssSize = (height, width) => {
|
|
1592
|
+
if (isValidNumber(height) && isValidNumber(width)) {
|
|
1593
|
+
return {
|
|
1594
|
+
height: `${height}px`,
|
|
1595
|
+
width: `${width}px`
|
|
1596
|
+
};
|
|
1597
|
+
} else {
|
|
1598
|
+
return FULL_SIZE;
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
var getInitialInnerSize = (height, width) => {
|
|
1602
|
+
if (isValidNumber(height) && isValidNumber(width)) {
|
|
1603
|
+
return {
|
|
1604
|
+
height,
|
|
1605
|
+
width
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1577
1609
|
var useMeasuredContainer = ({
|
|
1578
1610
|
defaultHeight = 0,
|
|
1579
1611
|
defaultWidth = 0,
|
|
@@ -1582,17 +1614,38 @@ var useMeasuredContainer = ({
|
|
|
1582
1614
|
}) => {
|
|
1583
1615
|
const containerRef = useRef10(null);
|
|
1584
1616
|
const [size, setSize] = useState3({
|
|
1617
|
+
css: getInitialCssSize(height, width),
|
|
1618
|
+
inner: getInitialInnerSize(height, width),
|
|
1585
1619
|
outer: {
|
|
1586
1620
|
height: height != null ? height : "100%",
|
|
1587
1621
|
width: width != null ? width : "100%"
|
|
1588
1622
|
}
|
|
1589
1623
|
});
|
|
1624
|
+
useMemo4(() => {
|
|
1625
|
+
setSize((currentSize) => {
|
|
1626
|
+
const { inner, outer } = currentSize;
|
|
1627
|
+
if (isValidNumber(height) && isValidNumber(width) && inner && outer) {
|
|
1628
|
+
const { height: innerHeight, width: innerWidth } = inner;
|
|
1629
|
+
const { height: outerHeight, width: outerWidth } = outer;
|
|
1630
|
+
if (outerHeight !== height || outerWidth !== width) {
|
|
1631
|
+
const heightDiff = isValidNumber(outerHeight) ? outerHeight - innerHeight : 0;
|
|
1632
|
+
const widthDiff = isValidNumber(outerWidth) ? outerWidth - innerWidth : 0;
|
|
1633
|
+
return {
|
|
1634
|
+
...currentSize,
|
|
1635
|
+
outer: { height, width },
|
|
1636
|
+
inner: { height: height - heightDiff, width: width - widthDiff }
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return currentSize;
|
|
1641
|
+
});
|
|
1642
|
+
}, [height, width]);
|
|
1590
1643
|
const onResize = useCallback13(
|
|
1591
1644
|
({ clientWidth, clientHeight }) => {
|
|
1592
|
-
console.log(`Resize ${clientHeight}`);
|
|
1593
1645
|
setSize((currentSize) => {
|
|
1594
|
-
const { inner, outer } = currentSize;
|
|
1646
|
+
const { css, inner, outer } = currentSize;
|
|
1595
1647
|
return isNumber(clientHeight) && isNumber(clientWidth) && (clientWidth !== (inner == null ? void 0 : inner.width) || clientHeight !== (inner == null ? void 0 : inner.height)) ? {
|
|
1648
|
+
css,
|
|
1596
1649
|
outer,
|
|
1597
1650
|
inner: {
|
|
1598
1651
|
width: Math.floor(clientWidth) || defaultWidth,
|
|
@@ -1606,6 +1659,7 @@ var useMeasuredContainer = ({
|
|
|
1606
1659
|
useResizeObserver(containerRef, ClientWidthHeight, onResize, true);
|
|
1607
1660
|
return {
|
|
1608
1661
|
containerRef,
|
|
1662
|
+
cssSize: size.css,
|
|
1609
1663
|
outerSize: size.outer,
|
|
1610
1664
|
innerSize: size.inner
|
|
1611
1665
|
};
|
|
@@ -2129,7 +2183,7 @@ var useTableScroll = ({
|
|
|
2129
2183
|
};
|
|
2130
2184
|
|
|
2131
2185
|
// src/useTableViewport.ts
|
|
2132
|
-
import { useCallback as useCallback16, useMemo as
|
|
2186
|
+
import { useCallback as useCallback16, useMemo as useMemo5, useRef as useRef13 } from "react";
|
|
2133
2187
|
import {
|
|
2134
2188
|
actualRowPositioning,
|
|
2135
2189
|
virtualRowPositioning
|
|
@@ -2181,15 +2235,15 @@ var useTableViewport = ({
|
|
|
2181
2235
|
const appliedContentHeight = appliedRowCount * rowHeight;
|
|
2182
2236
|
const virtualContentHeight = rowCount * rowHeight;
|
|
2183
2237
|
const virtualisedExtent = virtualContentHeight - appliedContentHeight;
|
|
2184
|
-
const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } =
|
|
2238
|
+
const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo5(
|
|
2185
2239
|
() => measurePinnedColumns(columns),
|
|
2186
2240
|
[columns]
|
|
2187
2241
|
);
|
|
2188
|
-
const [actualRowOffset, actualRowAtPosition] =
|
|
2242
|
+
const [actualRowOffset, actualRowAtPosition] = useMemo5(
|
|
2189
2243
|
() => actualRowPositioning(rowHeight),
|
|
2190
2244
|
[rowHeight]
|
|
2191
2245
|
);
|
|
2192
|
-
const [getRowOffset, getRowAtPosition] =
|
|
2246
|
+
const [getRowOffset, getRowAtPosition] = useMemo5(() => {
|
|
2193
2247
|
if (virtualisedExtent) {
|
|
2194
2248
|
return virtualRowPositioning(
|
|
2195
2249
|
rowHeight,
|
|
@@ -2203,7 +2257,7 @@ var useTableViewport = ({
|
|
|
2203
2257
|
const setPctScrollTop = useCallback16((scrollPct) => {
|
|
2204
2258
|
pctScrollTopRef.current = scrollPct;
|
|
2205
2259
|
}, []);
|
|
2206
|
-
return
|
|
2260
|
+
return useMemo5(() => {
|
|
2207
2261
|
var _a;
|
|
2208
2262
|
if (size) {
|
|
2209
2263
|
const headingsDepth = headings.length;
|
|
@@ -2256,7 +2310,7 @@ import {
|
|
|
2256
2310
|
getColumnsInViewport,
|
|
2257
2311
|
itemsChanged
|
|
2258
2312
|
} from "@vuu-ui/vuu-utils";
|
|
2259
|
-
import { useCallback as useCallback17, useEffect as useEffect4, useMemo as
|
|
2313
|
+
import { useCallback as useCallback17, useEffect as useEffect4, useMemo as useMemo6, useRef as useRef14, useState as useState4 } from "react";
|
|
2260
2314
|
var useVirtualViewport = ({
|
|
2261
2315
|
columns,
|
|
2262
2316
|
getRowAtPosition,
|
|
@@ -2271,7 +2325,7 @@ var useVirtualViewport = ({
|
|
|
2271
2325
|
} = viewportMeasurements;
|
|
2272
2326
|
const availableWidth = contentWidth - maxScrollContainerScrollHorizontal;
|
|
2273
2327
|
const scrollLeftRef = useRef14(0);
|
|
2274
|
-
const [visibleColumns, preSpan] =
|
|
2328
|
+
const [visibleColumns, preSpan] = useMemo6(
|
|
2275
2329
|
() => getColumnsInViewport(
|
|
2276
2330
|
columns,
|
|
2277
2331
|
scrollLeftRef.current,
|
|
@@ -2335,12 +2389,12 @@ var useTable = ({
|
|
|
2335
2389
|
...measuredProps
|
|
2336
2390
|
}) => {
|
|
2337
2391
|
var _a, _b;
|
|
2338
|
-
const [rowCount, setRowCount] = useState5(
|
|
2392
|
+
const [rowCount, setRowCount] = useState5(dataSource.size);
|
|
2339
2393
|
const expectConfigChangeRef = useRef15(false);
|
|
2340
2394
|
const dataSourceRef = useRef15();
|
|
2341
2395
|
dataSourceRef.current = dataSource;
|
|
2342
2396
|
if (dataSource === void 0) {
|
|
2343
|
-
throw Error("no data source provided to
|
|
2397
|
+
throw Error("no data source provided to Vuu Table");
|
|
2344
2398
|
}
|
|
2345
2399
|
const containerMeasurements = useMeasuredContainer(measuredProps);
|
|
2346
2400
|
const onDataRowcountChange = useCallback18((size) => {
|
|
@@ -2350,17 +2404,6 @@ var useTable = ({
|
|
|
2350
2404
|
config,
|
|
2351
2405
|
dataSource.config
|
|
2352
2406
|
);
|
|
2353
|
-
const handlePersistentColumnOperation = useCallback18(
|
|
2354
|
-
(action) => {
|
|
2355
|
-
expectConfigChangeRef.current = true;
|
|
2356
|
-
dispatchColumnAction(action);
|
|
2357
|
-
},
|
|
2358
|
-
[dispatchColumnAction]
|
|
2359
|
-
);
|
|
2360
|
-
const handleContextMenuAction = useContextMenu({
|
|
2361
|
-
dataSource,
|
|
2362
|
-
onPersistentColumnOperation: handlePersistentColumnOperation
|
|
2363
|
-
});
|
|
2364
2407
|
const {
|
|
2365
2408
|
getRowAtPosition,
|
|
2366
2409
|
getRowOffset,
|
|
@@ -2410,6 +2453,17 @@ var useTable = ({
|
|
|
2410
2453
|
});
|
|
2411
2454
|
const dataRef = useRef15();
|
|
2412
2455
|
dataRef.current = data;
|
|
2456
|
+
const onPersistentColumnOperation = useCallback18(
|
|
2457
|
+
(action) => {
|
|
2458
|
+
expectConfigChangeRef.current = true;
|
|
2459
|
+
dispatchColumnAction(action);
|
|
2460
|
+
},
|
|
2461
|
+
[dispatchColumnAction]
|
|
2462
|
+
);
|
|
2463
|
+
const handleContextMenuAction = useTableContextMenu({
|
|
2464
|
+
dataSource,
|
|
2465
|
+
onPersistentColumnOperation
|
|
2466
|
+
});
|
|
2413
2467
|
const handleSort = useCallback18(
|
|
2414
2468
|
(column, extendSort = false, sortType) => {
|
|
2415
2469
|
if (dataSource) {
|
|
@@ -2560,7 +2614,7 @@ var useTable = ({
|
|
|
2560
2614
|
});
|
|
2561
2615
|
});
|
|
2562
2616
|
}, [dataSource, dispatchColumnAction]);
|
|
2563
|
-
|
|
2617
|
+
useMemo7(() => {
|
|
2564
2618
|
if (expectConfigChangeRef.current) {
|
|
2565
2619
|
onConfigChange == null ? void 0 : onConfigChange({
|
|
2566
2620
|
...config,
|
|
@@ -2597,10 +2651,10 @@ var useTable = ({
|
|
|
2597
2651
|
[dataSource == null ? void 0 : dataSource.viewport, getSelectedRows, showContextMenu]
|
|
2598
2652
|
);
|
|
2599
2653
|
return {
|
|
2600
|
-
containerMeasurements,
|
|
2601
|
-
containerProps,
|
|
2602
2654
|
columns,
|
|
2603
2655
|
columnsWithinViewport,
|
|
2656
|
+
containerMeasurements,
|
|
2657
|
+
containerProps,
|
|
2604
2658
|
data,
|
|
2605
2659
|
dispatchColumnAction,
|
|
2606
2660
|
getRowOffset,
|
|
@@ -2644,7 +2698,7 @@ var Table = ({
|
|
|
2644
2698
|
style: styleProp,
|
|
2645
2699
|
width,
|
|
2646
2700
|
zebraStripes = false,
|
|
2647
|
-
...
|
|
2701
|
+
...htmlAttributes
|
|
2648
2702
|
}) => {
|
|
2649
2703
|
const id = useIdMemo(idProp);
|
|
2650
2704
|
const {
|
|
@@ -2698,7 +2752,7 @@ var Table = ({
|
|
|
2698
2752
|
children: /* @__PURE__ */ jsxs7(
|
|
2699
2753
|
"div",
|
|
2700
2754
|
{
|
|
2701
|
-
...
|
|
2755
|
+
...htmlAttributes,
|
|
2702
2756
|
...containerProps,
|
|
2703
2757
|
className,
|
|
2704
2758
|
id,
|
|
@@ -2798,6 +2852,10 @@ var JsonCell = ({ column, row }) => {
|
|
|
2798
2852
|
registerComponent("json", JsonCell, "cell-renderer", {});
|
|
2799
2853
|
export {
|
|
2800
2854
|
Table,
|
|
2801
|
-
|
|
2855
|
+
buildContextMenuDescriptors,
|
|
2856
|
+
useMeasuredContainer,
|
|
2857
|
+
useTableContextMenu,
|
|
2858
|
+
useTableModel,
|
|
2859
|
+
useTableViewport
|
|
2802
2860
|
};
|
|
2803
2861
|
//# sourceMappingURL=index.js.map
|