@dxos/react-ui-table 0.4.3-main.f97384b → 0.4.3
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 +114 -97
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableBody.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableFooter.d.ts +2 -1
- package/dist/types/src/components/Table/TableFooter.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableHead.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/components/Table/Table.tsx +167 -135
- package/src/components/Table/TableBody.tsx +5 -4
- package/src/components/Table/TableFooter.tsx +7 -4
- package/src/components/Table/TableHead.tsx +3 -1
|
@@ -191,7 +191,7 @@ var ColumnPanel = ({ context, tableDefs, tableDef, column, onUpdate, onDelete })
|
|
|
191
191
|
|
|
192
192
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
193
193
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
194
|
-
import { getCoreRowModel,
|
|
194
|
+
import { getCoreRowModel, useReactTable, getGroupedRowModel } from "@tanstack/react-table";
|
|
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";
|
|
@@ -263,8 +263,7 @@ Cell.displayName = CELL_NAME;
|
|
|
263
263
|
// packages/ui/react-ui-table/src/components/Table/TableBody.tsx
|
|
264
264
|
var TABLE_BODY_NAME = "TableBody";
|
|
265
265
|
var TableBody = ({ rows }) => {
|
|
266
|
-
const
|
|
267
|
-
const { table, keyAccessor, debug, expand, isGrid, onDatumClick, currentDatum } = tableContext;
|
|
266
|
+
const { table, keyAccessor, currentDatum, debug, expand, isGrid, onDatumClick } = useTableContext(TABLE_BODY_NAME);
|
|
268
267
|
const rowSelection = table.getState().rowSelection;
|
|
269
268
|
const domAttributes = useArrowNavigationGroup({
|
|
270
269
|
axis: "grid"
|
|
@@ -311,9 +310,9 @@ TableBody.displayName = TABLE_BODY_NAME;
|
|
|
311
310
|
// packages/ui/react-ui-table/src/components/Table/TableFooter.tsx
|
|
312
311
|
import { flexRender as flexRender2 } from "@tanstack/react-table";
|
|
313
312
|
import React4 from "react";
|
|
314
|
-
var
|
|
313
|
+
var TABLE_FOOT_NAME = "TableFooter";
|
|
315
314
|
var TableFooter = (props) => {
|
|
316
|
-
const tableContext = useTableContext(
|
|
315
|
+
const tableContext = useTableContext(TABLE_FOOT_NAME);
|
|
317
316
|
const { table, expand, debug } = tableContext;
|
|
318
317
|
const footers = table.getFooterGroups();
|
|
319
318
|
return /* @__PURE__ */ React4.createElement("tfoot", {
|
|
@@ -328,13 +327,13 @@ var TableFooter = (props) => {
|
|
|
328
327
|
}, footer.isPlaceholder ? null : flexRender2(footer.column.columnDef.footer, footer.getContext()));
|
|
329
328
|
}), expand && /* @__PURE__ */ React4.createElement("th", null))));
|
|
330
329
|
};
|
|
331
|
-
TableFooter.displayName =
|
|
330
|
+
TableFooter.displayName = TABLE_FOOT_NAME;
|
|
332
331
|
|
|
333
332
|
// packages/ui/react-ui-table/src/components/Table/TableHead.tsx
|
|
334
333
|
import { flexRender as flexRender3 } from "@tanstack/react-table";
|
|
335
334
|
import React5 from "react";
|
|
336
335
|
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
337
|
-
var TABLE_HEAD_NAME = "
|
|
336
|
+
var TABLE_HEAD_NAME = "TableHeader";
|
|
338
337
|
var TableHead = (_props) => {
|
|
339
338
|
const tableContext = useTableContext(TABLE_HEAD_NAME);
|
|
340
339
|
const headerGroups = tableContext.table.getHeaderGroups();
|
|
@@ -377,90 +376,56 @@ var TableHead = (_props) => {
|
|
|
377
376
|
TableHead.displayName = TABLE_HEAD_NAME;
|
|
378
377
|
|
|
379
378
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
380
|
-
var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
381
|
-
const { table: { getRowModel } } = useTableContext("VirtualizedTableContent");
|
|
382
|
-
const rows = getRowModel().rows;
|
|
383
|
-
const { getTotalSize, getVirtualItems } = useVirtualizer({
|
|
384
|
-
getScrollElement,
|
|
385
|
-
count: rows.length,
|
|
386
|
-
overscan: 16,
|
|
387
|
-
estimateSize: () => 33
|
|
388
|
-
});
|
|
389
|
-
const virtualRows = getVirtualItems();
|
|
390
|
-
const totalSize = getTotalSize();
|
|
391
|
-
const paddingTop = virtualRows.length > 0 ? virtualRows?.[0]?.start || 0 : 0;
|
|
392
|
-
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows?.[virtualRows.length - 1]?.end || 0) : 0;
|
|
393
|
-
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, paddingTop > 0 && /* @__PURE__ */ React6.createElement("tbody", {
|
|
394
|
-
role: "none"
|
|
395
|
-
}, /* @__PURE__ */ React6.createElement("tr", {
|
|
396
|
-
role: "none"
|
|
397
|
-
}, /* @__PURE__ */ React6.createElement("td", {
|
|
398
|
-
style: {
|
|
399
|
-
height: `${paddingTop}px`
|
|
400
|
-
},
|
|
401
|
-
role: "none"
|
|
402
|
-
}))), /* @__PURE__ */ React6.createElement(TableBody, {
|
|
403
|
-
rows: virtualRows.map((virtualRow) => rows[virtualRow.index])
|
|
404
|
-
}), paddingBottom > 0 && /* @__PURE__ */ React6.createElement("tbody", {
|
|
405
|
-
role: "none"
|
|
406
|
-
}, /* @__PURE__ */ React6.createElement("tr", {
|
|
407
|
-
role: "none"
|
|
408
|
-
}, /* @__PURE__ */ React6.createElement("td", {
|
|
409
|
-
style: {
|
|
410
|
-
height: `${paddingBottom}px`
|
|
411
|
-
},
|
|
412
|
-
role: "none"
|
|
413
|
-
}))));
|
|
414
|
-
};
|
|
415
|
-
var GroupedTableContent = () => {
|
|
416
|
-
const { table: { getGroupedRowModel: getGroupedRowModel2, getHeaderGroups, getState }, debug } = useTableContext("GroupedTableContent");
|
|
417
|
-
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, getGroupedRowModel2().rows.map((row, i) => {
|
|
418
|
-
return /* @__PURE__ */ React6.createElement(Fragment, {
|
|
419
|
-
key: i
|
|
420
|
-
}, /* @__PURE__ */ React6.createElement("thead", null, /* @__PURE__ */ React6.createElement("tr", null, debug && /* @__PURE__ */ React6.createElement("th", null), /* @__PURE__ */ React6.createElement("th", {
|
|
421
|
-
// TODO(burdon): Calculate row span.
|
|
422
|
-
colSpan: getHeaderGroups()[0].headers.length,
|
|
423
|
-
className: groupTh({})
|
|
424
|
-
}, getState().grouping[0], "[", String(row.getGroupingValue(getState().grouping[0])), "]"))), /* @__PURE__ */ React6.createElement(TableBody, {
|
|
425
|
-
rows: row.subRows
|
|
426
|
-
}));
|
|
427
|
-
}));
|
|
428
|
-
};
|
|
429
379
|
var Table = (props) => {
|
|
430
|
-
const { role, data = [], columns = [], onColumnResize, columnVisibility, header = true,
|
|
380
|
+
const { role, data = [], columns = [], onColumnResize, columnVisibility, header = true, rowsSelectable, debug, onDataSelectionChange } = props;
|
|
431
381
|
const TableProvider2 = TableProvider;
|
|
432
|
-
const [
|
|
382
|
+
const [columnSizing, setColumnSizing] = useState2({});
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
setColumnSizing(columns.filter((column) => !!column.size && column.prop !== void 0).reduce((state, column) => {
|
|
385
|
+
state[column.prop] = column.size;
|
|
386
|
+
return state;
|
|
387
|
+
}, {}));
|
|
388
|
+
}, [
|
|
389
|
+
columns
|
|
390
|
+
]);
|
|
391
|
+
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
|
+
const [rowSelection = {}, setRowSelection] = useControllableState({
|
|
433
401
|
prop: props.rowSelection,
|
|
434
402
|
onChange: props.onRowSelectionChange,
|
|
435
403
|
defaultProp: props.defaultRowSelection
|
|
436
404
|
});
|
|
405
|
+
useEffect(() => {
|
|
406
|
+
onDataSelectionChange?.(Object.keys(rowSelection).map((id) => table.getRowModel().rowsById[id].original));
|
|
407
|
+
}, [
|
|
408
|
+
onDataSelectionChange,
|
|
409
|
+
rowSelection
|
|
410
|
+
]);
|
|
437
411
|
const handleRowSelectionChange = useCallback((updaterOrValue) => {
|
|
438
412
|
const nextRowSelection = typeof updaterOrValue === "function" ? updaterOrValue(rowSelection) : updaterOrValue;
|
|
439
413
|
if (rowsSelectable === "multi") {
|
|
440
|
-
|
|
414
|
+
setRowSelection(nextRowSelection);
|
|
441
415
|
} else if (rowsSelectable) {
|
|
442
416
|
const nextRowSelectionKey = Object.keys(nextRowSelection).filter((id) => !rowSelection[id])[0];
|
|
443
|
-
|
|
417
|
+
setRowSelection(nextRowSelectionKey ? {
|
|
444
418
|
[nextRowSelectionKey]: true
|
|
445
419
|
} : {});
|
|
446
420
|
} else {
|
|
447
|
-
|
|
421
|
+
setRowSelection({});
|
|
448
422
|
}
|
|
449
423
|
}, [
|
|
450
424
|
rowSelection,
|
|
451
|
-
|
|
425
|
+
setRowSelection
|
|
452
426
|
]);
|
|
453
|
-
const [
|
|
454
|
-
|
|
455
|
-
useEffect(() => {
|
|
456
|
-
if (columnSizingInfo.columnSizingStart?.length === 0) {
|
|
457
|
-
onColumnResizeDebounced(table.getState().columnSizing);
|
|
458
|
-
}
|
|
459
|
-
}, [
|
|
460
|
-
columnSizingInfo
|
|
461
|
-
]);
|
|
462
|
-
const [grouping, setGrouping] = useState2(props.grouping ?? []);
|
|
463
|
-
useEffect(() => setGrouping(props.grouping ?? []), [
|
|
427
|
+
const [grouping, handleGroupingChange] = useState2(props.grouping ?? []);
|
|
428
|
+
useEffect(() => handleGroupingChange(props.grouping ?? []), [
|
|
464
429
|
props.grouping
|
|
465
430
|
]);
|
|
466
431
|
const table = useReactTable({
|
|
@@ -473,18 +438,24 @@ var Table = (props) => {
|
|
|
473
438
|
size: 256,
|
|
474
439
|
maxSize: 1024
|
|
475
440
|
},
|
|
476
|
-
// Rows
|
|
477
|
-
getCoreRowModel: getCoreRowModel(),
|
|
478
441
|
// State
|
|
479
442
|
state: {
|
|
480
443
|
columnVisibility,
|
|
444
|
+
columnSizing,
|
|
481
445
|
columnSizingInfo,
|
|
482
446
|
rowSelection,
|
|
483
447
|
grouping
|
|
484
448
|
},
|
|
449
|
+
// Resize columns
|
|
450
|
+
columnResizeMode: "onChange",
|
|
451
|
+
enableColumnResizing: true,
|
|
452
|
+
onColumnSizingChange: setColumnSizing,
|
|
453
|
+
onColumnSizingInfoChange: setColumnSizingInfo,
|
|
454
|
+
// Rows
|
|
455
|
+
getCoreRowModel: getCoreRowModel(),
|
|
485
456
|
// Grouping
|
|
486
|
-
getGroupedRowModel: getGroupedRowModel(),
|
|
487
|
-
onGroupingChange:
|
|
457
|
+
getGroupedRowModel: grouping.length > 1 ? getGroupedRowModel() : void 0,
|
|
458
|
+
onGroupingChange: handleGroupingChange,
|
|
488
459
|
// Selection
|
|
489
460
|
...rowsSelectable === "multi" ? {
|
|
490
461
|
enableMultiRowSelection: true
|
|
@@ -492,31 +463,30 @@ var Table = (props) => {
|
|
|
492
463
|
enableRowSelection: true
|
|
493
464
|
} : {},
|
|
494
465
|
onRowSelectionChange: handleRowSelectionChange,
|
|
495
|
-
// Resize columns
|
|
496
|
-
columnResizeMode: "onChange",
|
|
497
|
-
enableColumnResizing: true,
|
|
498
|
-
onColumnSizingInfoChange: setColumnSizingInfo,
|
|
499
466
|
// Debug
|
|
500
467
|
debugTable: debug
|
|
501
468
|
});
|
|
502
|
-
const rows = table.getRowModel().rows;
|
|
503
|
-
useEffect(() => {
|
|
504
|
-
if (onDataSelectionChange) {
|
|
505
|
-
onDataSelectionChange(Object.keys(rowSelection).map((id) => table.getRowModel().rowsById[id].original));
|
|
506
|
-
}
|
|
507
|
-
}, [
|
|
508
|
-
onDataSelectionChange,
|
|
509
|
-
rowSelection,
|
|
510
|
-
table
|
|
511
|
-
]);
|
|
512
469
|
const expand = false;
|
|
513
470
|
return /* @__PURE__ */ React6.createElement(TableProvider2, {
|
|
514
471
|
...props,
|
|
472
|
+
table,
|
|
515
473
|
header,
|
|
516
474
|
expand,
|
|
517
|
-
table,
|
|
518
475
|
isGrid: role === "grid" || role === "treegrid"
|
|
519
|
-
}, /* @__PURE__ */ React6.createElement(
|
|
476
|
+
}, /* @__PURE__ */ React6.createElement(TableImpl, {
|
|
477
|
+
debug: false
|
|
478
|
+
}));
|
|
479
|
+
};
|
|
480
|
+
var TableImpl = (props) => {
|
|
481
|
+
const { role, footer, grouping, getScrollElement, fullWidth, classNames, debug } = props;
|
|
482
|
+
const { table } = useTableContext("TableImpl");
|
|
483
|
+
const { rows } = table.getRowModel();
|
|
484
|
+
if (debug) {
|
|
485
|
+
return /* @__PURE__ */ React6.createElement("pre", {
|
|
486
|
+
className: "font-mono text-xs text-neutral-500 m-1 p-2 ring"
|
|
487
|
+
}, /* @__PURE__ */ React6.createElement("code", null, JSON.stringify(table.getState(), void 0, 2)));
|
|
488
|
+
}
|
|
489
|
+
return /* @__PURE__ */ React6.createElement("table", {
|
|
520
490
|
role,
|
|
521
491
|
className: tableRoot(props, classNames),
|
|
522
492
|
...!fullWidth && {
|
|
@@ -524,13 +494,60 @@ var Table = (props) => {
|
|
|
524
494
|
width: table.getTotalSize()
|
|
525
495
|
}
|
|
526
496
|
}
|
|
527
|
-
}, /* @__PURE__ */ React6.createElement(TableHead, null), grouping
|
|
497
|
+
}, /* @__PURE__ */ React6.createElement(TableHead, null), grouping?.length !== 0 ? getScrollElement ? /* @__PURE__ */ React6.createElement(VirtualizedTableContent, {
|
|
528
498
|
getScrollElement
|
|
529
499
|
}) : /* @__PURE__ */ React6.createElement(TableBody, {
|
|
530
500
|
rows
|
|
531
|
-
}) : /* @__PURE__ */ React6.createElement(GroupedTableContent, null), footer && /* @__PURE__ */ React6.createElement(TableFooter, null))
|
|
532
|
-
|
|
533
|
-
|
|
501
|
+
}) : /* @__PURE__ */ React6.createElement(GroupedTableContent, null), footer && /* @__PURE__ */ React6.createElement(TableFooter, null));
|
|
502
|
+
};
|
|
503
|
+
var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
504
|
+
const { table: { getRowModel } } = useTableContext("VirtualizedTableContent");
|
|
505
|
+
const rows = getRowModel().rows;
|
|
506
|
+
const { getTotalSize, getVirtualItems } = useVirtualizer({
|
|
507
|
+
getScrollElement,
|
|
508
|
+
count: rows.length,
|
|
509
|
+
overscan: 16,
|
|
510
|
+
estimateSize: () => 33
|
|
511
|
+
});
|
|
512
|
+
const virtualRows = getVirtualItems();
|
|
513
|
+
const totalSize = getTotalSize();
|
|
514
|
+
const paddingTop = virtualRows.length > 0 ? virtualRows?.[0]?.start || 0 : 0;
|
|
515
|
+
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows?.[virtualRows.length - 1]?.end || 0) : 0;
|
|
516
|
+
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, paddingTop > 0 && /* @__PURE__ */ React6.createElement("tbody", {
|
|
517
|
+
role: "none"
|
|
518
|
+
}, /* @__PURE__ */ React6.createElement("tr", {
|
|
519
|
+
role: "none"
|
|
520
|
+
}, /* @__PURE__ */ React6.createElement("td", {
|
|
521
|
+
style: {
|
|
522
|
+
height: `${paddingTop}px`
|
|
523
|
+
},
|
|
524
|
+
role: "none"
|
|
525
|
+
}))), /* @__PURE__ */ React6.createElement(TableBody, {
|
|
526
|
+
rows: virtualRows.map((virtualRow) => rows[virtualRow.index])
|
|
527
|
+
}), paddingBottom > 0 && /* @__PURE__ */ React6.createElement("tbody", {
|
|
528
|
+
role: "none"
|
|
529
|
+
}, /* @__PURE__ */ React6.createElement("tr", {
|
|
530
|
+
role: "none"
|
|
531
|
+
}, /* @__PURE__ */ React6.createElement("td", {
|
|
532
|
+
style: {
|
|
533
|
+
height: `${paddingBottom}px`
|
|
534
|
+
},
|
|
535
|
+
role: "none"
|
|
536
|
+
}))));
|
|
537
|
+
};
|
|
538
|
+
var GroupedTableContent = () => {
|
|
539
|
+
const { table: { getGroupedRowModel: getGroupedRowModel2, getHeaderGroups, getState }, debug } = useTableContext("GroupedTableContent");
|
|
540
|
+
return /* @__PURE__ */ React6.createElement(React6.Fragment, null, getGroupedRowModel2().rows.map((row, i) => {
|
|
541
|
+
return /* @__PURE__ */ React6.createElement(Fragment, {
|
|
542
|
+
key: i
|
|
543
|
+
}, /* @__PURE__ */ React6.createElement("thead", null, /* @__PURE__ */ React6.createElement("tr", null, debug && /* @__PURE__ */ React6.createElement("th", null), /* @__PURE__ */ React6.createElement("th", {
|
|
544
|
+
// TODO(burdon): Calculate row span.
|
|
545
|
+
colSpan: getHeaderGroups()[0].headers.length,
|
|
546
|
+
className: groupTh({})
|
|
547
|
+
}, getState().grouping[0], "[", String(row.getGroupingValue(getState().grouping[0])), "]"))), /* @__PURE__ */ React6.createElement(TableBody, {
|
|
548
|
+
rows: row.subRows
|
|
549
|
+
}));
|
|
550
|
+
}));
|
|
534
551
|
};
|
|
535
552
|
|
|
536
553
|
// packages/ui/react-ui-table/src/components/Cell/CellCombobox.tsx
|