@dxos/react-ui-table 0.4.10-main.c5e8686 → 0.4.10-main.cb83c78
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 +68 -115
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts +1 -5
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +0 -3
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/usePinLastRow.d.ts +1 -1
- package/dist/types/src/hooks/usePinLastRow.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/components/ColumnMenu/ColumnMenu.stories.tsx +0 -30
- package/src/components/ColumnMenu/ColumnSettingsForm.tsx +63 -69
- package/src/components/Table/Table.stories.tsx +1 -56
- package/src/components/Table/Table.tsx +8 -23
- package/src/hooks/usePinLastRow.ts +20 -41
|
@@ -92,7 +92,7 @@ var CellCombobox = ({ model, value, onValueChange }) => {
|
|
|
92
92
|
|
|
93
93
|
// packages/ui/react-ui-table/src/components/ColumnMenu/ColumnMenu.tsx
|
|
94
94
|
import { X as X2, GearSix, CaretDown as CaretDown2, ArrowDown, ArrowUp } from "@phosphor-icons/react";
|
|
95
|
-
import React3, { useRef as useRef2, useState as useState5, useCallback as
|
|
95
|
+
import React3, { useRef as useRef2, useState as useState5, useCallback as useCallback2 } from "react";
|
|
96
96
|
import { Button as Button2, DensityProvider, Popover as Popover2, DropdownMenu } from "@dxos/react-ui";
|
|
97
97
|
import { getSize as getSize3, mx as mx3 } from "@dxos/react-ui-theme";
|
|
98
98
|
|
|
@@ -107,21 +107,19 @@ var Section = ({ children, className }) => /* @__PURE__ */ React2.createElement(
|
|
|
107
107
|
className: mx2("p-2", className)
|
|
108
108
|
}, children);
|
|
109
109
|
var ColumnSettingsForm = ({ column, tableDef, tableDefs, onUpdate, onDelete, onClose }) => {
|
|
110
|
-
const [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
digits: String(column.digits ?? "0")
|
|
117
|
-
});
|
|
110
|
+
const [prop, setProp] = useState2(column.id);
|
|
111
|
+
const [refTable, setRefTable] = useState2(column.refTable);
|
|
112
|
+
const [refProp, setRefProp] = useState2(column.refProp);
|
|
113
|
+
const [type, setType] = useState2(String(column.type));
|
|
114
|
+
const [label, setLabel] = useState2(column.label);
|
|
115
|
+
const [digits, setDigits] = useState2(String(column.digits ?? "0"));
|
|
118
116
|
const propRef = useRef(null);
|
|
119
117
|
const { t } = useTranslation2(translationKey);
|
|
120
118
|
const handleCancel = () => {
|
|
119
|
+
setProp(column.id);
|
|
121
120
|
onClose?.();
|
|
122
121
|
};
|
|
123
122
|
const handleSave = () => {
|
|
124
|
-
const { prop, refTable, refProp, type, label, digits } = formState;
|
|
125
123
|
if (!prop.length || !prop.match(/^[a-zA-Z_].+/i)) {
|
|
126
124
|
propRef.current?.focus();
|
|
127
125
|
return;
|
|
@@ -133,7 +131,7 @@ var ColumnSettingsForm = ({ column, tableDef, tableDefs, onUpdate, onDelete, onC
|
|
|
133
131
|
return;
|
|
134
132
|
}
|
|
135
133
|
}
|
|
136
|
-
onUpdate?.(
|
|
134
|
+
onUpdate?.(prop, {
|
|
137
135
|
id: prop,
|
|
138
136
|
prop,
|
|
139
137
|
label,
|
|
@@ -150,30 +148,22 @@ var ColumnSettingsForm = ({ column, tableDef, tableDefs, onUpdate, onDelete, onC
|
|
|
150
148
|
classNames: "mbe-1"
|
|
151
149
|
}, t("column label label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
152
150
|
placeholder: "Column label",
|
|
153
|
-
value:
|
|
154
|
-
onChange: (event) =>
|
|
155
|
-
...prevState,
|
|
156
|
-
label: event.target.value
|
|
157
|
-
})),
|
|
151
|
+
value: label ?? "",
|
|
152
|
+
onChange: (event) => setLabel(event.target.value),
|
|
158
153
|
autoFocus: true
|
|
159
154
|
})), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
160
155
|
classNames: "mbe-1 mbs-3"
|
|
161
156
|
}, t("property key label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
162
157
|
ref: propRef,
|
|
163
158
|
placeholder: "Property key",
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
prop: event.target.value.replace(/[^\w_]/g, "")
|
|
168
|
-
}))
|
|
159
|
+
// TODO(burdon): Provide hooks for value normalization, ENTER, ESC, etc.
|
|
160
|
+
value: prop ?? "",
|
|
161
|
+
onChange: (event) => setProp(event.target.value.replace(/[^\w_]/g, ""))
|
|
169
162
|
})), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
170
163
|
classNames: "mbe-1 mbs-3"
|
|
171
164
|
}, t("column type label")), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
172
|
-
value:
|
|
173
|
-
onValueChange:
|
|
174
|
-
...prevState,
|
|
175
|
-
type: value
|
|
176
|
-
}))
|
|
165
|
+
value: type,
|
|
166
|
+
onValueChange: setType
|
|
177
167
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
178
168
|
placeholder: "Type",
|
|
179
169
|
classNames: "is-full"
|
|
@@ -182,46 +172,37 @@ var ColumnSettingsForm = ({ column, tableDef, tableDefs, onUpdate, onDelete, onC
|
|
|
182
172
|
"boolean",
|
|
183
173
|
"string",
|
|
184
174
|
"ref"
|
|
185
|
-
].map((
|
|
186
|
-
key:
|
|
187
|
-
value:
|
|
188
|
-
}, t(`${
|
|
175
|
+
].map((type2) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
176
|
+
key: type2,
|
|
177
|
+
value: type2
|
|
178
|
+
}, t(`${type2} column type label`))))))))), type === "number" && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Section, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
189
179
|
classNames: "mbe-1 mbs-3"
|
|
190
180
|
}, t("digits label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
191
|
-
value:
|
|
192
|
-
onChange: (event) =>
|
|
193
|
-
|
|
194
|
-
digits: event.target.value
|
|
195
|
-
}))
|
|
196
|
-
}))), formState.type === "ref" && /* @__PURE__ */ React2.createElement(Section, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
181
|
+
value: digits ?? "",
|
|
182
|
+
onChange: (event) => setDigits(event.target.value)
|
|
183
|
+
})))), type === "ref" && /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Section, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
197
184
|
classNames: "mbe-1 mbs-3"
|
|
198
185
|
}, "Table"), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
199
|
-
value:
|
|
200
|
-
onValueChange:
|
|
201
|
-
...prevState,
|
|
202
|
-
refTable: value
|
|
203
|
-
}))
|
|
186
|
+
value: refTable,
|
|
187
|
+
onValueChange: setRefTable
|
|
204
188
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
205
189
|
placeholder: "Table",
|
|
206
190
|
classNames: "is-full"
|
|
207
191
|
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tableDefs.filter((t2) => t2.id !== tableDef.id).map(({ id, name }) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
208
192
|
key: id,
|
|
209
193
|
value: id
|
|
210
|
-
}, name ?? id))))))),
|
|
194
|
+
}, name ?? id))))))), refTable && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
211
195
|
classNames: "mbe-1 mbs-3"
|
|
212
196
|
}, "Table property"), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
213
|
-
value:
|
|
214
|
-
onValueChange:
|
|
215
|
-
...prevState,
|
|
216
|
-
refProp: value
|
|
217
|
-
}))
|
|
197
|
+
value: refProp,
|
|
198
|
+
onValueChange: setRefProp
|
|
218
199
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
219
200
|
placeholder: "Property",
|
|
220
201
|
classNames: "is-full"
|
|
221
|
-
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tableDefs.find((tableDef2) => tableDef2.id ===
|
|
202
|
+
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tableDefs.find((tableDef2) => tableDef2.id === refTable)?.columns.map(({ id, label: label2 }) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
222
203
|
key: id,
|
|
223
204
|
value: id
|
|
224
|
-
},
|
|
205
|
+
}, label2 ?? id))))))))), /* @__PURE__ */ React2.createElement(Separator, {
|
|
225
206
|
classNames: "mli-2"
|
|
226
207
|
}), /* @__PURE__ */ React2.createElement(Section, {
|
|
227
208
|
className: "space-b-1.5"
|
|
@@ -299,58 +280,38 @@ var useColumnSorting = (column) => {
|
|
|
299
280
|
};
|
|
300
281
|
|
|
301
282
|
// packages/ui/react-ui-table/src/hooks/usePinLastRow.ts
|
|
302
|
-
import {
|
|
283
|
+
import { useEffect, useState as useState4 } from "react";
|
|
303
284
|
var usePinLastRow = (pinLastRow, table, data, getScrollElement) => {
|
|
304
285
|
const [pinnedRowKey, setPinnedRowKey] = useState4();
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
requestAnimationFrame(() => scrollElement.scrollTo({
|
|
309
|
-
top: scrollElement.scrollHeight
|
|
310
|
-
}));
|
|
286
|
+
useEffect(() => {
|
|
287
|
+
if (!pinLastRow) {
|
|
288
|
+
return;
|
|
311
289
|
}
|
|
312
|
-
}, [
|
|
313
|
-
getScrollElement
|
|
314
|
-
]);
|
|
315
|
-
const pinRow = useCallback2((rowToPin) => {
|
|
316
|
-
table.resetRowPinning();
|
|
317
|
-
rowToPin.pin("bottom");
|
|
318
|
-
setPinnedRowKey(rowToPin.id);
|
|
319
|
-
}, [
|
|
320
|
-
table
|
|
321
|
-
]);
|
|
322
|
-
const clearRowPinning = useCallback2(() => {
|
|
323
|
-
table.resetRowPinning();
|
|
324
|
-
setPinnedRowKey(void 0);
|
|
325
|
-
}, [
|
|
326
|
-
table
|
|
327
|
-
]);
|
|
328
|
-
const pinLastRowCallback = useCallback2(() => {
|
|
329
290
|
const rows = table.getRowModel().rows;
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const lastRow = rows[rows.length - 1];
|
|
334
|
-
if (lastRow.id === pinnedRowKey) {
|
|
291
|
+
const rowToPin = rows[rows.length - 1];
|
|
292
|
+
const rowId = rowToPin.id;
|
|
293
|
+
if (rowId === pinnedRowKey) {
|
|
335
294
|
return;
|
|
336
295
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (pinLastRow) {
|
|
348
|
-
pinLastRowCallback();
|
|
296
|
+
table.resetRowPinning();
|
|
297
|
+
rowToPin.pin("bottom");
|
|
298
|
+
const scrollElement = getScrollElement?.();
|
|
299
|
+
const isFirstRender = pinnedRowKey === void 0;
|
|
300
|
+
if (scrollElement && !isFirstRender) {
|
|
301
|
+
requestAnimationFrame(() => {
|
|
302
|
+
scrollElement.scrollTo({
|
|
303
|
+
top: scrollElement.scrollHeight
|
|
304
|
+
});
|
|
305
|
+
});
|
|
349
306
|
}
|
|
307
|
+
setPinnedRowKey(rowId);
|
|
350
308
|
}, [
|
|
351
|
-
data,
|
|
352
309
|
pinLastRow,
|
|
353
|
-
|
|
310
|
+
table,
|
|
311
|
+
getScrollElement,
|
|
312
|
+
pinnedRowKey,
|
|
313
|
+
setPinnedRowKey,
|
|
314
|
+
data
|
|
354
315
|
]);
|
|
355
316
|
};
|
|
356
317
|
|
|
@@ -362,14 +323,14 @@ var ColumnMenu = ({ column, ...props }) => {
|
|
|
362
323
|
const columnSettingsAnchorRef = useRef2(null);
|
|
363
324
|
const [isColumnSettingsOpen, setIsColumnSettingsOpen] = useState5(false);
|
|
364
325
|
const shouldPreventFocusOnClose = useRef2(false);
|
|
365
|
-
const onOpenColumnSettings =
|
|
326
|
+
const onOpenColumnSettings = useCallback2(() => {
|
|
366
327
|
shouldPreventFocusOnClose.current = true;
|
|
367
328
|
setIsColumnSettingsOpen(true);
|
|
368
329
|
}, [
|
|
369
330
|
shouldPreventFocusOnClose,
|
|
370
331
|
setIsColumnSettingsOpen
|
|
371
332
|
]);
|
|
372
|
-
const onDropdownCloseAutoFocus =
|
|
333
|
+
const onDropdownCloseAutoFocus = useCallback2((event) => {
|
|
373
334
|
if (shouldPreventFocusOnClose.current) {
|
|
374
335
|
event.preventDefault();
|
|
375
336
|
shouldPreventFocusOnClose.current = false;
|
|
@@ -483,7 +444,7 @@ var SortIndicator = ({ direction, onClick }) => {
|
|
|
483
444
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
484
445
|
import { getCoreRowModel, getSortedRowModel, useReactTable, getGroupedRowModel, getExpandedRowModel } from "@tanstack/react-table";
|
|
485
446
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
486
|
-
import React9, { Fragment, useCallback as
|
|
447
|
+
import React9, { Fragment, useCallback as useCallback3, useEffect as useEffect2, useState as useState6 } from "react";
|
|
487
448
|
import { log } from "@dxos/log";
|
|
488
449
|
import { useDefaultValue, useOnTransition } from "@dxos/react-ui";
|
|
489
450
|
|
|
@@ -699,7 +660,7 @@ var Table = (props) => {
|
|
|
699
660
|
setColumnSizing
|
|
700
661
|
]);
|
|
701
662
|
const [columnSizingInfo, setColumnSizingInfo] = useState6({});
|
|
702
|
-
const notifyColumnResize =
|
|
663
|
+
const notifyColumnResize = useCallback3(() => onColumnResize?.(columnSizing), [
|
|
703
664
|
onColumnResize,
|
|
704
665
|
columnSizing
|
|
705
666
|
]);
|
|
@@ -709,7 +670,7 @@ var Table = (props) => {
|
|
|
709
670
|
onChange: props.onRowSelectionChange,
|
|
710
671
|
defaultProp: props.defaultRowSelection
|
|
711
672
|
});
|
|
712
|
-
const handleRowSelectionChange =
|
|
673
|
+
const handleRowSelectionChange = useCallback3((updaterOrValue) => {
|
|
713
674
|
const nextRowSelection = typeof updaterOrValue === "function" ? updaterOrValue(rowSelection) : updaterOrValue;
|
|
714
675
|
if (rowsSelectable === "multi") {
|
|
715
676
|
setRowSelection(nextRowSelection);
|
|
@@ -781,7 +742,7 @@ var Table = (props) => {
|
|
|
781
742
|
if (!getScrollElement) {
|
|
782
743
|
log.warn("Table: getScrollElement is not set. This is required for virtualized tables.", void 0, {
|
|
783
744
|
F: __dxlog_file,
|
|
784
|
-
L:
|
|
745
|
+
L: 159,
|
|
785
746
|
S: void 0,
|
|
786
747
|
C: (f, a) => f(...a)
|
|
787
748
|
});
|
|
@@ -801,6 +762,12 @@ var Table = (props) => {
|
|
|
801
762
|
var TableImpl = (props) => {
|
|
802
763
|
const { debug, classNames, getScrollElement, role, footer, grouping, fullWidth } = props;
|
|
803
764
|
const { table } = useTableContext();
|
|
765
|
+
const centerRows = table.getCenterRows();
|
|
766
|
+
const bottomRows = table.getBottomRows();
|
|
767
|
+
const rows = [
|
|
768
|
+
...centerRows,
|
|
769
|
+
...bottomRows
|
|
770
|
+
];
|
|
804
771
|
if (debug) {
|
|
805
772
|
return /* @__PURE__ */ React9.createElement("pre", {
|
|
806
773
|
className: "font-mono text-xs text-neutral-500 m-1 p-2 ring"
|
|
@@ -820,28 +787,14 @@ var TableImpl = (props) => {
|
|
|
820
787
|
getScrollElement
|
|
821
788
|
}) : /* @__PURE__ */ React9.createElement(VirtualizedTableContent, {
|
|
822
789
|
getScrollElement
|
|
823
|
-
}) : /* @__PURE__ */ React9.createElement(
|
|
824
|
-
};
|
|
825
|
-
var UnvirtualizedTableContent = () => {
|
|
826
|
-
const { table } = useTableContext();
|
|
827
|
-
const centerRows = table.getCenterRows();
|
|
828
|
-
const pinnedRows = table.getBottomRows();
|
|
829
|
-
const rows = [
|
|
830
|
-
...centerRows,
|
|
831
|
-
...pinnedRows
|
|
832
|
-
];
|
|
833
|
-
return /* @__PURE__ */ React9.createElement(TableBody, {
|
|
790
|
+
}) : /* @__PURE__ */ React9.createElement(TableBody, {
|
|
834
791
|
rows
|
|
835
|
-
});
|
|
792
|
+
}) : /* @__PURE__ */ React9.createElement(GroupedTableContent, null), footer && /* @__PURE__ */ React9.createElement(TableFooter, null));
|
|
836
793
|
};
|
|
837
794
|
var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
838
795
|
const { table } = useTableContext();
|
|
839
796
|
const centerRows = table.getCenterRows();
|
|
840
|
-
|
|
841
|
-
try {
|
|
842
|
-
pinnedRows = table.getBottomRows();
|
|
843
|
-
} catch (_) {
|
|
844
|
-
}
|
|
797
|
+
const pinnedRows = table.getBottomRows();
|
|
845
798
|
const { getTotalSize, getVirtualItems } = useVirtualizer({
|
|
846
799
|
getScrollElement,
|
|
847
800
|
count: centerRows.length,
|