@dxos/react-ui-table 0.4.7-next.f4b92be → 0.4.8-main.00e6f19
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/dist/lib/browser/index.mjs +93 -56
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Cell/Cell.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +2 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +3 -0
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/theme.d.ts +1 -1
- package/dist/types/src/theme.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/components/Cell/Cell.tsx +4 -1
- package/src/components/Table/Table.stories.tsx +77 -60
- package/src/components/Table/Table.tsx +45 -39
- package/src/helpers.tsx +52 -43
- package/src/theme.ts +3 -1
|
@@ -195,6 +195,8 @@ import { getCoreRowModel, useReactTable, getGroupedRowModel } from "@tanstack/re
|
|
|
195
195
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
196
196
|
import React6, { Fragment, useCallback, useEffect, useState as useState2 } from "react";
|
|
197
197
|
import { debounce } from "@dxos/async";
|
|
198
|
+
import { log } from "@dxos/log";
|
|
199
|
+
import { useDefaultValue } from "@dxos/react-ui";
|
|
198
200
|
|
|
199
201
|
// packages/ui/react-ui-table/src/components/Table/TableBody.tsx
|
|
200
202
|
import { useArrowNavigationGroup } from "@fluentui/react-tabster";
|
|
@@ -214,7 +216,7 @@ var selectedRow = "!bg-primary-100 dark:!bg-primary-700";
|
|
|
214
216
|
var flushPadding = "pli-0 plb-0";
|
|
215
217
|
var textPadding = "pli-2 plb-0.5";
|
|
216
218
|
var headPadding = "pli-2 plb-1.5";
|
|
217
|
-
var gridCellFocusRing = "focus:z-[11] focus:outline outline-2 outline-primary-500 dark:outline-primary-400";
|
|
219
|
+
var gridCellFocusRing = "focus-within:z-[11] focus-within:outline outline-2 outline-primary-500 dark:outline-primary-400";
|
|
218
220
|
var tableRoot = ({ fullWidth }, ...etc) => mx2("table-fixed", fullWidth && "is-full", ...etc);
|
|
219
221
|
var groupTh = (_props, ...etc) => mx2("text-start font-medium", flushPadding, ...etc);
|
|
220
222
|
var theadRoot = ({ header, stickyHeader }, ...etc) => mx2(header ? stickyHeader && "sticky block-start-[--sticky-top] z-[1]" : "collapse", header && fixedSurface, ...etc);
|
|
@@ -239,10 +241,11 @@ var FocusableCell = ({ cell, children }) => {
|
|
|
239
241
|
const domAttributes = useFocusableGroup({
|
|
240
242
|
tabBehavior: "limited"
|
|
241
243
|
});
|
|
244
|
+
const className = tdRoot(tableContext, cell.column.columnDef.meta?.cell?.classNames);
|
|
242
245
|
return /* @__PURE__ */ React2.createElement("td", {
|
|
243
246
|
tabIndex: 0,
|
|
244
247
|
...domAttributes,
|
|
245
|
-
className
|
|
248
|
+
className
|
|
246
249
|
}, children);
|
|
247
250
|
};
|
|
248
251
|
var StaticCell = ({ cell, children }) => {
|
|
@@ -376,8 +379,11 @@ var TableHead = (_props) => {
|
|
|
376
379
|
TableHead.displayName = TABLE_HEAD_NAME;
|
|
377
380
|
|
|
378
381
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
382
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
|
|
379
383
|
var Table = (props) => {
|
|
380
|
-
const { role,
|
|
384
|
+
const { role, onColumnResize, columnVisibility, header = true, rowsSelectable, debug, onDataSelectionChange, getScrollElement } = props;
|
|
385
|
+
const columns = useDefaultValue(props.columns, []);
|
|
386
|
+
const data = useDefaultValue(props.data, []);
|
|
381
387
|
const TableProvider2 = TableProvider;
|
|
382
388
|
const [columnSizing, setColumnSizing] = useState2({});
|
|
383
389
|
useEffect(() => {
|
|
@@ -386,28 +392,15 @@ var Table = (props) => {
|
|
|
386
392
|
return state;
|
|
387
393
|
}, {}));
|
|
388
394
|
}, [
|
|
389
|
-
columns
|
|
395
|
+
columns,
|
|
396
|
+
setColumnSizing
|
|
390
397
|
]);
|
|
391
398
|
const [columnSizingInfo, setColumnSizingInfo] = useState2({});
|
|
392
|
-
const onColumnResizeDebounced = onColumnResize && debounce(onColumnResize, 1e3);
|
|
393
|
-
useEffect(() => {
|
|
394
|
-
if (columnSizingInfo.columnSizingStart?.length === 0) {
|
|
395
|
-
onColumnResizeDebounced?.(table.getState().columnSizing);
|
|
396
|
-
}
|
|
397
|
-
}, [
|
|
398
|
-
columnSizingInfo
|
|
399
|
-
]);
|
|
400
399
|
const [rowSelection = {}, setRowSelection] = useControllableState({
|
|
401
400
|
prop: props.rowSelection,
|
|
402
401
|
onChange: props.onRowSelectionChange,
|
|
403
402
|
defaultProp: props.defaultRowSelection
|
|
404
403
|
});
|
|
405
|
-
useEffect(() => {
|
|
406
|
-
onDataSelectionChange?.(Object.keys(rowSelection).map((id) => table.getRowModel().rowsById[id].original));
|
|
407
|
-
}, [
|
|
408
|
-
onDataSelectionChange,
|
|
409
|
-
rowSelection
|
|
410
|
-
]);
|
|
411
404
|
const handleRowSelectionChange = useCallback((updaterOrValue) => {
|
|
412
405
|
const nextRowSelection = typeof updaterOrValue === "function" ? updaterOrValue(rowSelection) : updaterOrValue;
|
|
413
406
|
if (rowsSelectable === "multi") {
|
|
@@ -421,11 +414,13 @@ var Table = (props) => {
|
|
|
421
414
|
setRowSelection({});
|
|
422
415
|
}
|
|
423
416
|
}, [
|
|
424
|
-
|
|
425
|
-
setRowSelection
|
|
417
|
+
rowsSelectable,
|
|
418
|
+
setRowSelection,
|
|
419
|
+
rowSelection
|
|
426
420
|
]);
|
|
427
421
|
const [grouping, handleGroupingChange] = useState2(props.grouping ?? []);
|
|
428
422
|
useEffect(() => handleGroupingChange(props.grouping ?? []), [
|
|
423
|
+
handleGroupingChange,
|
|
429
424
|
props.grouping
|
|
430
425
|
]);
|
|
431
426
|
const table = useReactTable({
|
|
@@ -456,17 +451,39 @@ var Table = (props) => {
|
|
|
456
451
|
// Grouping
|
|
457
452
|
getGroupedRowModel: grouping.length > 1 ? getGroupedRowModel() : void 0,
|
|
458
453
|
onGroupingChange: handleGroupingChange,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
enableMultiRowSelection: true
|
|
462
|
-
} : rowsSelectable ? {
|
|
463
|
-
enableRowSelection: true
|
|
464
|
-
} : {},
|
|
454
|
+
enableMultiRowSelection: rowsSelectable === "multi" ? true : void 0,
|
|
455
|
+
enableRowSelection: rowsSelectable === true ? true : void 0,
|
|
465
456
|
onRowSelectionChange: handleRowSelectionChange,
|
|
466
457
|
// Debug
|
|
467
458
|
debugTable: debug
|
|
468
459
|
});
|
|
460
|
+
const onColumnResizeDebounced = onColumnResize && debounce(onColumnResize, 1e3);
|
|
461
|
+
useEffect(() => {
|
|
462
|
+
onDataSelectionChange?.(Object.keys(rowSelection).map((id) => table.getRowModel().rowsById[id].original));
|
|
463
|
+
}, [
|
|
464
|
+
onDataSelectionChange,
|
|
465
|
+
rowSelection,
|
|
466
|
+
table
|
|
467
|
+
]);
|
|
468
|
+
useEffect(() => {
|
|
469
|
+
const shouldTriggerResize = columnSizingInfo.columnSizingStart?.length === 0;
|
|
470
|
+
if (shouldTriggerResize) {
|
|
471
|
+
onColumnResizeDebounced?.(table.getState().columnSizing);
|
|
472
|
+
}
|
|
473
|
+
}, [
|
|
474
|
+
columnSizingInfo,
|
|
475
|
+
onColumnResizeDebounced,
|
|
476
|
+
table
|
|
477
|
+
]);
|
|
469
478
|
const expand = false;
|
|
479
|
+
if (!getScrollElement) {
|
|
480
|
+
log.warn("Table: getScrollElement is not set. This is required for virtualized tables.", void 0, {
|
|
481
|
+
F: __dxlog_file,
|
|
482
|
+
L: 148,
|
|
483
|
+
S: void 0,
|
|
484
|
+
C: (f, a) => f(...a)
|
|
485
|
+
});
|
|
486
|
+
}
|
|
470
487
|
return /* @__PURE__ */ React6.createElement(TableProvider2, {
|
|
471
488
|
...props,
|
|
472
489
|
table,
|
|
@@ -474,11 +491,13 @@ var Table = (props) => {
|
|
|
474
491
|
expand,
|
|
475
492
|
isGrid: role === "grid" || role === "treegrid"
|
|
476
493
|
}, /* @__PURE__ */ React6.createElement(TableImpl, {
|
|
477
|
-
debug: false
|
|
494
|
+
debug: false,
|
|
495
|
+
getScrollElement,
|
|
496
|
+
...props
|
|
478
497
|
}));
|
|
479
498
|
};
|
|
480
499
|
var TableImpl = (props) => {
|
|
481
|
-
const {
|
|
500
|
+
const { debug, classNames, getScrollElement, role, footer, grouping, fullWidth } = props;
|
|
482
501
|
const { table } = useTableContext("TableImpl");
|
|
483
502
|
const { rows } = table.getRowModel();
|
|
484
503
|
if (debug) {
|
|
@@ -486,6 +505,7 @@ var TableImpl = (props) => {
|
|
|
486
505
|
className: "font-mono text-xs text-neutral-500 m-1 p-2 ring"
|
|
487
506
|
}, /* @__PURE__ */ React6.createElement("code", null, JSON.stringify(table.getState(), void 0, 2)));
|
|
488
507
|
}
|
|
508
|
+
const isResizingColumn = table.getState().columnSizingInfo.isResizingColumn;
|
|
489
509
|
return /* @__PURE__ */ React6.createElement("table", {
|
|
490
510
|
role,
|
|
491
511
|
className: tableRoot(props, classNames),
|
|
@@ -494,7 +514,9 @@ var TableImpl = (props) => {
|
|
|
494
514
|
width: table.getTotalSize()
|
|
495
515
|
}
|
|
496
516
|
}
|
|
497
|
-
}, /* @__PURE__ */ React6.createElement(TableHead, null), grouping?.length !== 0 ? getScrollElement ? /* @__PURE__ */ React6.createElement(
|
|
517
|
+
}, /* @__PURE__ */ React6.createElement(TableHead, null), grouping?.length !== 0 ? getScrollElement ? isResizingColumn ? /* @__PURE__ */ React6.createElement(MemoizedVirtualisedTableContent, {
|
|
518
|
+
getScrollElement
|
|
519
|
+
}) : /* @__PURE__ */ React6.createElement(VirtualizedTableContent, {
|
|
498
520
|
getScrollElement
|
|
499
521
|
}) : /* @__PURE__ */ React6.createElement(TableBody, {
|
|
500
522
|
rows
|
|
@@ -506,7 +528,7 @@ var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
|
506
528
|
const { getTotalSize, getVirtualItems } = useVirtualizer({
|
|
507
529
|
getScrollElement,
|
|
508
530
|
count: rows.length,
|
|
509
|
-
overscan:
|
|
531
|
+
overscan: 4,
|
|
510
532
|
estimateSize: () => 33
|
|
511
533
|
});
|
|
512
534
|
const virtualRows = getVirtualItems();
|
|
@@ -535,6 +557,7 @@ var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
|
535
557
|
role: "none"
|
|
536
558
|
}))));
|
|
537
559
|
};
|
|
560
|
+
var MemoizedVirtualisedTableContent = /* @__PURE__ */ React6.memo(VirtualizedTableContent);
|
|
538
561
|
var GroupedTableContent = () => {
|
|
539
562
|
const { table: { getGroupedRowModel: getGroupedRowModel2, getHeaderGroups, getState }, debug } = useTableContext("GroupedTableContent");
|
|
540
563
|
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, getGroupedRowModel2().rows.map((row, i) => {
|
|
@@ -626,8 +649,10 @@ import { createColumnHelper } from "@tanstack/react-table";
|
|
|
626
649
|
import { format } from "date-fns/format";
|
|
627
650
|
import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
|
|
628
651
|
import React8, { useEffect as useEffect2, useRef as useRef2, useState as useState4 } from "react";
|
|
652
|
+
import { log as log2 } from "@dxos/log";
|
|
629
653
|
import { Input as Input2, Tooltip } from "@dxos/react-ui";
|
|
630
654
|
import { getSize as getSize3, mx as mx5 } from "@dxos/react-ui-theme";
|
|
655
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/helpers.tsx";
|
|
631
656
|
var createColumnBuilder = () => ({
|
|
632
657
|
helper: createColumnHelper(),
|
|
633
658
|
builder: new ColumnBuilder()
|
|
@@ -641,8 +666,9 @@ var ComboboxBuilderCell = (cellContext) => {
|
|
|
641
666
|
}) : null;
|
|
642
667
|
};
|
|
643
668
|
var StringBuilderCell = (cellContext) => {
|
|
644
|
-
const
|
|
645
|
-
const {
|
|
669
|
+
const ref = useRef2(null);
|
|
670
|
+
const { findPrevFocusable } = useFocusFinders();
|
|
671
|
+
const { onUpdate, cell } = cellContext.column.columnDef.meta;
|
|
646
672
|
const initialValue = cellContext.getValue();
|
|
647
673
|
const [value, setValue] = useState4(() => {
|
|
648
674
|
if (initialValue?.content) {
|
|
@@ -651,27 +677,26 @@ var StringBuilderCell = (cellContext) => {
|
|
|
651
677
|
return initialValue;
|
|
652
678
|
});
|
|
653
679
|
const handleSave = () => {
|
|
654
|
-
|
|
655
|
-
|
|
680
|
+
ref.current && document.activeElement === ref.current && findPrevFocusable(ref.current)?.focus();
|
|
681
|
+
if (value !== initialValue) {
|
|
682
|
+
onUpdate?.(cellContext.row.original, cellContext.column.id, value);
|
|
656
683
|
}
|
|
657
|
-
onUpdate?.(cellContext.row.original, cellContext.column.id, value);
|
|
658
|
-
};
|
|
659
|
-
const handleCancel = () => {
|
|
660
|
-
setValue(initialValue);
|
|
661
684
|
};
|
|
685
|
+
const handleCancel = () => setValue(initialValue);
|
|
662
686
|
const rows = cellContext.table.getRowModel().flatRows;
|
|
663
687
|
const columns = cellContext.table.getVisibleFlatColumns();
|
|
664
688
|
const placeholder = cellContext.row.index === rows.length - 1 && columns[0].id === cellContext.column.id;
|
|
665
689
|
return /* @__PURE__ */ React8.createElement(Input2.Root, null, /* @__PURE__ */ React8.createElement(Input2.TextInput, {
|
|
666
|
-
ref
|
|
690
|
+
ref,
|
|
667
691
|
variant: "subdued",
|
|
668
692
|
placeholder: placeholder ? "Add row..." : void 0,
|
|
669
693
|
classNames: [
|
|
670
694
|
"is-full",
|
|
671
|
-
textPadding
|
|
695
|
+
textPadding,
|
|
696
|
+
cell?.classNames
|
|
672
697
|
],
|
|
673
698
|
value: value ?? "",
|
|
674
|
-
onBlur:
|
|
699
|
+
onBlur: handleSave,
|
|
675
700
|
onChange: (event) => setValue(event.target.value),
|
|
676
701
|
onKeyDown: (event) => event.key === "Enter" && handleSave() || event.key === "Escape" && handleCancel()
|
|
677
702
|
}));
|
|
@@ -693,15 +718,15 @@ var NumberBuilderCell = (cellContext) => {
|
|
|
693
718
|
digits,
|
|
694
719
|
value
|
|
695
720
|
]);
|
|
696
|
-
const handleEdit = () =>
|
|
697
|
-
if (onUpdate) {
|
|
698
|
-
setText(value !== void 0 ? String(value) : "");
|
|
699
|
-
}
|
|
700
|
-
};
|
|
721
|
+
const handleEdit = () => setText(value !== void 0 ? String(value) : "");
|
|
701
722
|
const handleSave = () => {
|
|
702
723
|
const nextValue = parseNumber(text);
|
|
703
|
-
|
|
704
|
-
|
|
724
|
+
if (!isNaN(nextValue)) {
|
|
725
|
+
onUpdate?.(cellContext.row.original, cellContext.column.id, nextValue);
|
|
726
|
+
setText(displayNumber(nextValue, digits));
|
|
727
|
+
} else {
|
|
728
|
+
setText(displayNumber(value, digits));
|
|
729
|
+
}
|
|
705
730
|
ref.current && document.activeElement === ref.current && findPrevFocusable(ref.current)?.focus();
|
|
706
731
|
};
|
|
707
732
|
const _handleCancel = () => {
|
|
@@ -731,10 +756,12 @@ var RowSelectorBuilderCell = (cellContext) => {
|
|
|
731
756
|
const { cell } = cellContext.column.columnDef.meta;
|
|
732
757
|
const { row } = cellContext;
|
|
733
758
|
const checked = row.getCanSelect() ? row.getIsSelected() : row.getCanSelectSubRows() && (row.getIsSomeSelected() ? "indeterminate" : row.getIsAllSubRowsSelected());
|
|
734
|
-
return /* @__PURE__ */ React8.createElement(
|
|
759
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
760
|
+
className: "flex justify-center w-full h-full",
|
|
761
|
+
role: "presentation"
|
|
762
|
+
}, /* @__PURE__ */ React8.createElement(Input2.Root, null, /* @__PURE__ */ React8.createElement(Input2.Checkbox, {
|
|
735
763
|
size: 4,
|
|
736
764
|
classNames: [
|
|
737
|
-
"mli-auto",
|
|
738
765
|
cell?.classNames
|
|
739
766
|
],
|
|
740
767
|
checked,
|
|
@@ -744,7 +771,7 @@ var RowSelectorBuilderCell = (cellContext) => {
|
|
|
744
771
|
}
|
|
745
772
|
},
|
|
746
773
|
disabled: !(row.getCanSelect() || row.getCanSelectSubRows())
|
|
747
|
-
}));
|
|
774
|
+
})));
|
|
748
775
|
};
|
|
749
776
|
var SwitchBuilderCell = (cellContext) => {
|
|
750
777
|
const { onUpdate } = cellContext.column.columnDef.meta;
|
|
@@ -861,7 +888,14 @@ var ColumnBuilder = class {
|
|
|
861
888
|
className: mx5(textPadding, classNames)
|
|
862
889
|
}, str);
|
|
863
890
|
} catch (err) {
|
|
864
|
-
|
|
891
|
+
log2.info("formatError", {
|
|
892
|
+
value
|
|
893
|
+
}, {
|
|
894
|
+
F: __dxlog_file2,
|
|
895
|
+
L: 370,
|
|
896
|
+
S: this,
|
|
897
|
+
C: (f, a) => f(...a)
|
|
898
|
+
});
|
|
865
899
|
return null;
|
|
866
900
|
}
|
|
867
901
|
},
|
|
@@ -922,8 +956,7 @@ var ColumnBuilder = class {
|
|
|
922
956
|
return {
|
|
923
957
|
id,
|
|
924
958
|
size: 32,
|
|
925
|
-
|
|
926
|
-
maxSize: 32,
|
|
959
|
+
enableResizing: false,
|
|
927
960
|
meta: {
|
|
928
961
|
onUpdate,
|
|
929
962
|
cell: {
|
|
@@ -933,7 +966,10 @@ var ColumnBuilder = class {
|
|
|
933
966
|
header: ({ table }) => {
|
|
934
967
|
const { rowsSelectable } = useTableContext("HELPER_SELECT_ROW_HEADER_CELL");
|
|
935
968
|
const checked = table.getIsSomeRowsSelected() ? "indeterminate" : table.getIsAllRowsSelected();
|
|
936
|
-
return rowsSelectable === "multi" ? /* @__PURE__ */ React8.createElement(
|
|
969
|
+
return rowsSelectable === "multi" ? /* @__PURE__ */ React8.createElement("div", {
|
|
970
|
+
className: "flex justify-center w-full h-full",
|
|
971
|
+
role: "presentation"
|
|
972
|
+
}, /* @__PURE__ */ React8.createElement(Input2.Root, null, /* @__PURE__ */ React8.createElement(Input2.Checkbox, {
|
|
937
973
|
size: 4,
|
|
938
974
|
classNames: [
|
|
939
975
|
"mli-auto",
|
|
@@ -941,7 +977,7 @@ var ColumnBuilder = class {
|
|
|
941
977
|
],
|
|
942
978
|
checked,
|
|
943
979
|
onCheckedChange: () => table.toggleAllRowsSelected()
|
|
944
|
-
})) : null;
|
|
980
|
+
}))) : null;
|
|
945
981
|
},
|
|
946
982
|
cell: RowSelectorBuilderCell
|
|
947
983
|
};
|
|
@@ -1003,6 +1039,7 @@ export {
|
|
|
1003
1039
|
ColumnBuilder,
|
|
1004
1040
|
ColumnMenu,
|
|
1005
1041
|
ColumnPanel,
|
|
1042
|
+
MemoizedVirtualisedTableContent,
|
|
1006
1043
|
Table,
|
|
1007
1044
|
createColumnBuilder,
|
|
1008
1045
|
currentRow,
|