@dxos/react-ui-table 0.8.4-main.bc674ce → 0.8.4-main.c351d160a8
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/{chunk-OZBLY7XM.mjs → chunk-BF54SSNL.mjs} +12 -18
- package/dist/lib/browser/chunk-BF54SSNL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-I5IFW7UF.mjs → chunk-PTHMYAAM.mjs} +33 -28
- package/dist/lib/browser/chunk-PTHMYAAM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +178 -176
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-DDJKYJFY.mjs → chunk-GI72MQSG.mjs} +33 -28
- package/dist/lib/node-esm/chunk-GI72MQSG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-WNZSKIRF.mjs → chunk-SIRDIPHZ.mjs} +12 -18
- package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +178 -176
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +5 -4
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +6 -6
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +3 -3
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +2 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +1 -1
- package/dist/types/src/model/table-model.d.ts +5 -4
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +2 -2
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +1 -6
- package/dist/types/src/types/Table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +6 -5
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +42 -42
- package/src/components/Table/ColumnSettings.tsx +3 -4
- package/src/components/Table/DynamicTable.stories.tsx +6 -5
- package/src/components/Table/DynamicTable.tsx +11 -10
- package/src/components/Table/Relations.stories.tsx +13 -10
- package/src/components/Table/Table.stories.tsx +54 -32
- package/src/components/Table/Table.tsx +51 -56
- package/src/components/TableCellEditor/CellValidationMessage.tsx +4 -4
- package/src/components/TableCellEditor/FormCellEditor.tsx +11 -5
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +4 -3
- package/src/components/TableCellEditor/TableCellEditor.tsx +3 -3
- package/src/components/TableToolbar/TableToolbar.tsx +6 -6
- package/src/components/testing.ts +1 -1
- package/src/hooks/useAddRow.ts +1 -1
- package/src/hooks/useProjectionModel.ts +3 -3
- package/src/hooks/useTableModel.ts +1 -1
- package/src/model/table-model.test.ts +5 -5
- package/src/model/table-model.ts +9 -8
- package/src/model/table-presentation.test.ts +5 -5
- package/src/model/table-presentation.ts +12 -11
- package/src/playwright/TableManager.ts +10 -3
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +45 -2
- package/src/testing/useTestTableModel.ts +3 -3
- package/src/types/Table.ts +11 -22
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +13 -12
- package/src/util/query-ast.ts +3 -0
- package/src/util/table-buttons.ts +1 -1
- package/src/util/table-controls.ts +2 -2
- package/dist/lib/browser/chunk-I5IFW7UF.mjs.map +0 -7
- package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-DDJKYJFY.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +0 -7
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
useAddRow,
|
|
17
17
|
useProjectionModel,
|
|
18
18
|
useTableModel
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-PTHMYAAM.mjs";
|
|
20
20
|
import {
|
|
21
21
|
Table_exports
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-BF54SSNL.mjs";
|
|
23
23
|
|
|
24
24
|
// src/translations.ts
|
|
25
25
|
var translationKey = "@dxos/react-ui-table";
|
|
@@ -54,29 +54,29 @@ var translations = [
|
|
|
54
54
|
];
|
|
55
55
|
|
|
56
56
|
// src/components/Table/Table.tsx
|
|
57
|
-
import { Atom as
|
|
57
|
+
import { Atom as Atom3, RegistryContext as RegistryContext2, useAtomValue as useAtomValue4 } from "@effect-atom/atom-react";
|
|
58
58
|
import * as String2 from "effect/String";
|
|
59
|
-
import
|
|
59
|
+
import React8, { forwardRef, useCallback as useCallback4, useContext as useContext2, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo5, useState as useState4 } from "react";
|
|
60
60
|
import { log } from "@dxos/log";
|
|
61
61
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
62
62
|
import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
|
|
63
63
|
import { DxEditRequest } from "@dxos/react-ui-grid";
|
|
64
|
-
import { mx } from "@dxos/ui-theme";
|
|
64
|
+
import { composableProps, mx } from "@dxos/ui-theme";
|
|
65
65
|
|
|
66
66
|
// src/util/dynamic-table.ts
|
|
67
|
-
import { Filter, Obj, Order, Query, Ref, Type } from "@dxos/echo";
|
|
68
|
-
import { ProjectionModel,
|
|
67
|
+
import { Filter, JsonSchema, Obj, Order, Query, Ref, Type } from "@dxos/echo";
|
|
68
|
+
import { ProjectionModel, ViewModel, createEchoChangeCallback as createEchoChangeCallback2, getSchemaFromPropertyDefinitions } from "@dxos/schema";
|
|
69
69
|
var getBaseSchema = ({ schema, typename, properties, jsonSchema }) => {
|
|
70
70
|
if (typename && properties) {
|
|
71
71
|
const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
|
|
72
72
|
return {
|
|
73
73
|
typename: schema2.typename,
|
|
74
|
-
jsonSchema: schema2
|
|
74
|
+
jsonSchema: JsonSchema.toJsonSchema(schema2)
|
|
75
75
|
};
|
|
76
76
|
} else if (schema) {
|
|
77
77
|
return {
|
|
78
78
|
typename: Type.getTypename(schema),
|
|
79
|
-
jsonSchema:
|
|
79
|
+
jsonSchema: JsonSchema.toJsonSchema(schema)
|
|
80
80
|
};
|
|
81
81
|
} else if (typename && jsonSchema) {
|
|
82
82
|
return {
|
|
@@ -88,7 +88,7 @@ var getBaseSchema = ({ schema, typename, properties, jsonSchema }) => {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
var makeDynamicTable = ({ registry, jsonSchema, properties }) => {
|
|
91
|
-
const view =
|
|
91
|
+
const view = ViewModel.make({
|
|
92
92
|
query: Query.select(Filter.everything()),
|
|
93
93
|
jsonSchema,
|
|
94
94
|
...properties && {
|
|
@@ -103,7 +103,7 @@ var makeDynamicTable = ({ registry, jsonSchema, properties }) => {
|
|
|
103
103
|
registry,
|
|
104
104
|
view,
|
|
105
105
|
baseSchema: jsonSchema,
|
|
106
|
-
change:
|
|
106
|
+
change: createEchoChangeCallback2(view, jsonSchema)
|
|
107
107
|
});
|
|
108
108
|
projection.normalizeView();
|
|
109
109
|
if (properties && projection.getFields()) {
|
|
@@ -253,14 +253,14 @@ var CellValidationMessage = ({ __gridScope, validationError, variant = "error" }
|
|
|
253
253
|
if (!editing || !validationError) {
|
|
254
254
|
return null;
|
|
255
255
|
}
|
|
256
|
-
const bgClass = variant === "error" ? "bg-
|
|
257
|
-
const textClass = variant === "error" ? "text-
|
|
256
|
+
const bgClass = variant === "error" ? "bg-error-surface" : "bg-warning-surface";
|
|
257
|
+
const textClass = variant === "error" ? "text-error-surface-text" : "text-warning-surface-text";
|
|
258
258
|
return /* @__PURE__ */ React.createElement("div", {
|
|
259
259
|
role: "none",
|
|
260
|
-
className: `absolute ${bgClass} ${textClass} rounded-
|
|
260
|
+
className: `absolute ${bgClass} ${textClass} rounded-h-sm text-xs p-1`,
|
|
261
261
|
style: {
|
|
262
262
|
...{
|
|
263
|
-
"--dx-
|
|
263
|
+
"--dx-grid-cell-width": `${box?.inlineSize ?? 200}px`
|
|
264
264
|
},
|
|
265
265
|
zIndex: 10,
|
|
266
266
|
insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
|
|
@@ -346,9 +346,13 @@ var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onC
|
|
|
346
346
|
model,
|
|
347
347
|
contextEditing
|
|
348
348
|
]);
|
|
349
|
-
const
|
|
349
|
+
const initialFormValues = useMemo(() => originalRow ? JSON.parse(JSON.stringify(originalRow)) : {}, [
|
|
350
350
|
originalRow
|
|
351
351
|
]);
|
|
352
|
+
const [formValues, setFormValues] = useState(initialFormValues);
|
|
353
|
+
const handleValuesChanged = useCallback((values) => {
|
|
354
|
+
setFormValues(values);
|
|
355
|
+
}, []);
|
|
352
356
|
const handleOpenChange = useCallback((nextOpen) => {
|
|
353
357
|
if (nextOpen === false) {
|
|
354
358
|
setEditing(null);
|
|
@@ -433,12 +437,14 @@ var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onC
|
|
|
433
437
|
virtualRef: anchorRef
|
|
434
438
|
}), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
|
|
435
439
|
tabIndex: -1,
|
|
436
|
-
classNames: "
|
|
440
|
+
classNames: "dx-card-popover-width dx-density-fine"
|
|
437
441
|
}, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Root, {
|
|
438
442
|
...formProps,
|
|
439
443
|
autoFocus: true,
|
|
440
444
|
schema: narrowedSchema,
|
|
441
445
|
values: formValues,
|
|
446
|
+
onValuesChanged: handleValuesChanged,
|
|
447
|
+
projection: model?.projection,
|
|
442
448
|
createInitialValuePath: fieldProjection.field.referencePath,
|
|
443
449
|
createOptionIcon: "ph--plus--regular",
|
|
444
450
|
createOptionLabel,
|
|
@@ -453,7 +459,7 @@ var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onC
|
|
|
453
459
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
454
460
|
var editorSlots = {
|
|
455
461
|
scroll: {
|
|
456
|
-
className: "!
|
|
462
|
+
className: "!py-(--dx-grid-cell-editor-padding-block)"
|
|
457
463
|
}
|
|
458
464
|
};
|
|
459
465
|
var TableValueEditor = ({ __gridScope, schema, model, modals, onFocus, onSave, onCreate }) => {
|
|
@@ -682,9 +688,98 @@ var determineNavigationDelta = ({ key, shift }) => {
|
|
|
682
688
|
return shift ? -1 : 1;
|
|
683
689
|
};
|
|
684
690
|
|
|
691
|
+
// src/components/TableToolbar/TableToolbar.tsx
|
|
692
|
+
import { Atom as Atom2, RegistryContext } from "@effect-atom/atom-react";
|
|
693
|
+
import React4, { useContext, useEffect as useEffect2, useMemo as useMemo3 } from "react";
|
|
694
|
+
import { Menu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
|
|
695
|
+
var createTableToolbarActions = ({ stateAtom, onAdd, onSave, customActions }) => Atom2.make((get) => {
|
|
696
|
+
const nodes = [];
|
|
697
|
+
if (onAdd) {
|
|
698
|
+
const add = createMenuAction("add-row", onAdd, {
|
|
699
|
+
type: "add-row",
|
|
700
|
+
icon: "ph--plus--regular",
|
|
701
|
+
label: [
|
|
702
|
+
"add row label",
|
|
703
|
+
{
|
|
704
|
+
ns: translationKey
|
|
705
|
+
}
|
|
706
|
+
],
|
|
707
|
+
testId: "table.toolbar.add-row"
|
|
708
|
+
});
|
|
709
|
+
nodes.push(add);
|
|
710
|
+
}
|
|
711
|
+
if (onSave) {
|
|
712
|
+
const state = get(stateAtom);
|
|
713
|
+
const save = createMenuAction("save-view", onSave, {
|
|
714
|
+
type: "save-view",
|
|
715
|
+
icon: "ph--floppy-disk--regular",
|
|
716
|
+
label: [
|
|
717
|
+
"save view label",
|
|
718
|
+
{
|
|
719
|
+
ns: translationKey
|
|
720
|
+
}
|
|
721
|
+
],
|
|
722
|
+
testId: "table.toolbar.save-view",
|
|
723
|
+
iconOnly: false,
|
|
724
|
+
hidden: !state.viewDirty
|
|
725
|
+
});
|
|
726
|
+
nodes.push(save);
|
|
727
|
+
}
|
|
728
|
+
const gap = createGapSeparator();
|
|
729
|
+
nodes.push(...gap.nodes);
|
|
730
|
+
const edges = nodes.map(({ id: target }) => ({
|
|
731
|
+
source: "root",
|
|
732
|
+
target,
|
|
733
|
+
relation: "child"
|
|
734
|
+
}));
|
|
735
|
+
if (customActions) {
|
|
736
|
+
const custom = get(customActions);
|
|
737
|
+
nodes.push(...custom.nodes);
|
|
738
|
+
edges.push(...custom.edges);
|
|
739
|
+
}
|
|
740
|
+
return {
|
|
741
|
+
nodes,
|
|
742
|
+
edges
|
|
743
|
+
};
|
|
744
|
+
});
|
|
745
|
+
var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions, ...props }) => {
|
|
746
|
+
const registry = useContext(RegistryContext);
|
|
747
|
+
const stateAtom = useMemo3(() => Atom2.make({
|
|
748
|
+
viewDirty
|
|
749
|
+
}), []);
|
|
750
|
+
useEffect2(() => {
|
|
751
|
+
registry.set(stateAtom, {
|
|
752
|
+
viewDirty
|
|
753
|
+
});
|
|
754
|
+
}, [
|
|
755
|
+
registry,
|
|
756
|
+
stateAtom,
|
|
757
|
+
viewDirty
|
|
758
|
+
]);
|
|
759
|
+
const actionsCreator = useMemo3(() => createTableToolbarActions({
|
|
760
|
+
stateAtom,
|
|
761
|
+
onAdd,
|
|
762
|
+
onSave,
|
|
763
|
+
customActions
|
|
764
|
+
}), [
|
|
765
|
+
stateAtom,
|
|
766
|
+
onAdd,
|
|
767
|
+
onSave,
|
|
768
|
+
customActions
|
|
769
|
+
]);
|
|
770
|
+
const menu = useMenuActions(actionsCreator);
|
|
771
|
+
return /* @__PURE__ */ React4.createElement(Menu.Root, {
|
|
772
|
+
...menu,
|
|
773
|
+
attendableId
|
|
774
|
+
}, /* @__PURE__ */ React4.createElement(Menu.Toolbar, {
|
|
775
|
+
...props,
|
|
776
|
+
classNames
|
|
777
|
+
}));
|
|
778
|
+
};
|
|
779
|
+
|
|
685
780
|
// src/components/Table/ColumnActionsMenu.tsx
|
|
686
781
|
import { useAtomValue } from "@effect-atom/atom-react";
|
|
687
|
-
import
|
|
782
|
+
import React5 from "react";
|
|
688
783
|
import { DropdownMenu, useTranslation } from "@dxos/react-ui";
|
|
689
784
|
var ColumnActionsMenu = ({ model, modals }) => {
|
|
690
785
|
const { t } = useTranslation(translationKey);
|
|
@@ -694,39 +789,39 @@ var ColumnActionsMenu = ({ model, modals }) => {
|
|
|
694
789
|
}
|
|
695
790
|
const currentSort = model.getSorting();
|
|
696
791
|
const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
|
|
697
|
-
return /* @__PURE__ */
|
|
792
|
+
return /* @__PURE__ */ React5.createElement(DropdownMenu.Root, {
|
|
698
793
|
modal: false,
|
|
699
794
|
open: true,
|
|
700
795
|
onOpenChange: modals.close
|
|
701
|
-
}, /* @__PURE__ */
|
|
796
|
+
}, /* @__PURE__ */ React5.createElement(DropdownMenu.VirtualTrigger, {
|
|
702
797
|
virtualRef: modals.trigger
|
|
703
|
-
}), /* @__PURE__ */
|
|
798
|
+
}), /* @__PURE__ */ React5.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React5.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React5.createElement(DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ React5.createElement(DropdownMenu.Item, {
|
|
704
799
|
"data-testid": "column-sort-descending",
|
|
705
800
|
onClick: () => model.setSort(state.fieldId, "desc")
|
|
706
|
-
}, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */
|
|
801
|
+
}, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React5.createElement(DropdownMenu.Item, {
|
|
707
802
|
"data-testid": "column-sort-ascending",
|
|
708
803
|
onClick: () => model.setSort(state.fieldId, "asc")
|
|
709
|
-
}, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */
|
|
804
|
+
}, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ React5.createElement(DropdownMenu.Item, {
|
|
710
805
|
"data-testid": "column-clear-sort",
|
|
711
806
|
onClick: () => model.clearSort()
|
|
712
|
-
}, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */
|
|
807
|
+
}, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React5.createElement(DropdownMenu.Item, {
|
|
713
808
|
"data-testid": "column-delete",
|
|
714
809
|
onClick: () => model.deleteColumn(state.fieldId)
|
|
715
|
-
}, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */
|
|
810
|
+
}, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ React5.createElement(DropdownMenu.Item, {
|
|
716
811
|
"data-testid": "column-settings",
|
|
717
812
|
onClick: () => modals.openColumnSettings()
|
|
718
|
-
}, t("column action settings"))), /* @__PURE__ */
|
|
813
|
+
}, t("column action settings"))), /* @__PURE__ */ React5.createElement(DropdownMenu.Arrow, null))));
|
|
719
814
|
};
|
|
720
815
|
|
|
721
816
|
// src/components/Table/ColumnSettings.tsx
|
|
722
817
|
import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
|
|
723
|
-
import
|
|
818
|
+
import React6, { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
724
819
|
import { Popover as Popover2 } from "@dxos/react-ui";
|
|
725
820
|
import { FieldEditor } from "@dxos/react-ui-form";
|
|
726
821
|
var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
|
|
727
822
|
const [newField, setNewField] = useState3();
|
|
728
823
|
const state = useAtomValue2(modals.state);
|
|
729
|
-
|
|
824
|
+
useEffect3(() => {
|
|
730
825
|
if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
|
|
731
826
|
setNewField(model.projection.createFieldProjection());
|
|
732
827
|
requestAnimationFrame(() => {
|
|
@@ -739,7 +834,7 @@ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
|
|
|
739
834
|
model?.projection,
|
|
740
835
|
state
|
|
741
836
|
]);
|
|
742
|
-
const existingField =
|
|
837
|
+
const existingField = useMemo4(() => {
|
|
743
838
|
if (state?.type === "columnSettings") {
|
|
744
839
|
const { mode } = state;
|
|
745
840
|
if (mode.type === "edit") {
|
|
@@ -769,25 +864,25 @@ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
|
|
|
769
864
|
if (!model?.projection || !field) {
|
|
770
865
|
return null;
|
|
771
866
|
}
|
|
772
|
-
return /* @__PURE__ */
|
|
867
|
+
return /* @__PURE__ */ React6.createElement(Popover2.Root, {
|
|
773
868
|
modal: false,
|
|
774
869
|
open: state?.type === "columnSettings"
|
|
775
|
-
}, /* @__PURE__ */
|
|
870
|
+
}, /* @__PURE__ */ React6.createElement(Popover2.VirtualTrigger, {
|
|
776
871
|
virtualRef: modals.trigger
|
|
777
|
-
}), /* @__PURE__ */
|
|
778
|
-
classNames: "md:
|
|
779
|
-
}, /* @__PURE__ */
|
|
872
|
+
}), /* @__PURE__ */ React6.createElement(Popover2.Portal, null, /* @__PURE__ */ React6.createElement(Popover2.Content, {
|
|
873
|
+
classNames: "md:w-64"
|
|
874
|
+
}, /* @__PURE__ */ React6.createElement(Popover2.Viewport, null, /* @__PURE__ */ React6.createElement(FieldEditor, {
|
|
780
875
|
projection: model.projection,
|
|
781
876
|
field,
|
|
782
877
|
registry,
|
|
783
878
|
onSave: handleSave,
|
|
784
879
|
onCancel: handleCancel
|
|
785
|
-
})), /* @__PURE__ */
|
|
880
|
+
})), /* @__PURE__ */ React6.createElement(Popover2.Arrow, null))));
|
|
786
881
|
};
|
|
787
882
|
|
|
788
883
|
// src/components/Table/RowActionsMenu.tsx
|
|
789
884
|
import { useAtomValue as useAtomValue3 } from "@effect-atom/atom-react";
|
|
790
|
-
import
|
|
885
|
+
import React7 from "react";
|
|
791
886
|
import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
792
887
|
var RowActionsMenu = ({ model, modals }) => {
|
|
793
888
|
const { t } = useTranslation2(translationKey);
|
|
@@ -796,23 +891,23 @@ var RowActionsMenu = ({ model, modals }) => {
|
|
|
796
891
|
if (state?.type !== "row") {
|
|
797
892
|
return null;
|
|
798
893
|
}
|
|
799
|
-
return /* @__PURE__ */
|
|
894
|
+
return /* @__PURE__ */ React7.createElement(DropdownMenu2.Root, {
|
|
800
895
|
modal: false,
|
|
801
896
|
open: true,
|
|
802
897
|
onOpenChange: modals.close
|
|
803
|
-
}, /* @__PURE__ */
|
|
898
|
+
}, /* @__PURE__ */ React7.createElement(DropdownMenu2.VirtualTrigger, {
|
|
804
899
|
virtualRef: modals.trigger
|
|
805
|
-
}), /* @__PURE__ */
|
|
900
|
+
}), /* @__PURE__ */ React7.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React7.createElement(DropdownMenu2.Viewport, null, model.rowActions?.length > 0 && /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(DropdownMenu2.Group, null, model.rowActions?.map((action) => /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
|
|
806
901
|
key: action.id,
|
|
807
902
|
"data-testid": `row-action-${action.id}`,
|
|
808
903
|
onClick: () => {
|
|
809
904
|
modals.close();
|
|
810
905
|
model.handleRowAction(action.id, state.rowIndex);
|
|
811
906
|
}
|
|
812
|
-
}, toLocalizedString(action.label, t)))), /* @__PURE__ */
|
|
907
|
+
}, toLocalizedString(action.label, t)))), /* @__PURE__ */ React7.createElement(DropdownMenu2.Separator, null)), model.features.dataEditable !== false && /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
|
|
813
908
|
"data-testid": "row-menu-delete",
|
|
814
909
|
onClick: () => model.deleteRow(state.rowIndex)
|
|
815
|
-
}, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */
|
|
910
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ React7.createElement(DropdownMenu2.Arrow, null)));
|
|
816
911
|
};
|
|
817
912
|
|
|
818
913
|
// src/components/Table/Table.tsx
|
|
@@ -829,29 +924,19 @@ var rowDefault = {
|
|
|
829
924
|
focusUnfurl: false
|
|
830
925
|
}
|
|
831
926
|
};
|
|
832
|
-
var emptyColumnMeta =
|
|
927
|
+
var emptyColumnMeta = Atom3.make({
|
|
833
928
|
grid: {}
|
|
834
929
|
});
|
|
835
|
-
var TableRoot = ({ children
|
|
836
|
-
return /* @__PURE__ */
|
|
837
|
-
role: "none",
|
|
838
|
-
className: mx("relative !border-separator [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]", role === "card--popover" && "popover-card-height", role === "section" && "attention-surface", role === "card--intrinsic" && "[&_.dx-grid]:bs-[--dx-grid-content-block-size]", [
|
|
839
|
-
"card--popover",
|
|
840
|
-
"section",
|
|
841
|
-
"card--extrinsic"
|
|
842
|
-
].includes(role) && "overflow-hidden", [
|
|
843
|
-
"article",
|
|
844
|
-
"slide"
|
|
845
|
-
].includes(role) && "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:bs-0")
|
|
846
|
-
}, children);
|
|
930
|
+
var TableRoot = ({ children }) => {
|
|
931
|
+
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, children);
|
|
847
932
|
};
|
|
848
|
-
var emptyRowsAtom =
|
|
849
|
-
var emptyCellUpdateAtom =
|
|
850
|
-
var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId }, forwardedRef) => {
|
|
851
|
-
const registry =
|
|
933
|
+
var emptyRowsAtom = Atom3.make([]);
|
|
934
|
+
var emptyCellUpdateAtom = Atom3.make(0);
|
|
935
|
+
var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId, ...props }, forwardedRef) => {
|
|
936
|
+
const registry = useContext2(RegistryContext2);
|
|
852
937
|
const [dxGrid, setDxGrid] = useState4(null);
|
|
853
938
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
854
|
-
const modals =
|
|
939
|
+
const modals = useMemo5(() => new ModalController(registry), [
|
|
855
940
|
registry
|
|
856
941
|
]);
|
|
857
942
|
const columnMeta = useAtomValue4(model?.columnMeta ?? emptyColumnMeta);
|
|
@@ -859,7 +944,7 @@ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate,
|
|
|
859
944
|
const cellUpdateCounter = useAtomValue4(model?.cellUpdate ?? emptyCellUpdateAtom);
|
|
860
945
|
const columnCount = Object.keys(columnMeta.grid).length || model?.projection.getFields().length || 0;
|
|
861
946
|
const draftRowCount = model?.getDraftRowCount() ?? 0;
|
|
862
|
-
const frozen =
|
|
947
|
+
const frozen = useMemo5(() => {
|
|
863
948
|
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
864
949
|
return {
|
|
865
950
|
frozenRowsStart: 1,
|
|
@@ -874,7 +959,7 @@ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate,
|
|
|
874
959
|
const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
|
|
875
960
|
presentation
|
|
876
961
|
]);
|
|
877
|
-
|
|
962
|
+
useEffect4(() => {
|
|
878
963
|
if (!dxGrid || !presentation) {
|
|
879
964
|
return;
|
|
880
965
|
}
|
|
@@ -884,7 +969,7 @@ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate,
|
|
|
884
969
|
presentation,
|
|
885
970
|
getCells
|
|
886
971
|
]);
|
|
887
|
-
|
|
972
|
+
useEffect4(() => {
|
|
888
973
|
if (!dxGrid) {
|
|
889
974
|
return;
|
|
890
975
|
}
|
|
@@ -1057,7 +1142,7 @@ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate,
|
|
|
1057
1142
|
} catch (error) {
|
|
1058
1143
|
log.catch(error, void 0, {
|
|
1059
1144
|
F: __dxlog_file3,
|
|
1060
|
-
L:
|
|
1145
|
+
L: 310,
|
|
1061
1146
|
S: void 0,
|
|
1062
1147
|
C: (f, a) => f(...a)
|
|
1063
1148
|
});
|
|
@@ -1156,22 +1241,25 @@ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate,
|
|
|
1156
1241
|
presentation
|
|
1157
1242
|
]);
|
|
1158
1243
|
if (!model || !modals) {
|
|
1159
|
-
return /* @__PURE__ */
|
|
1244
|
+
return /* @__PURE__ */ React8.createElement("span", {
|
|
1160
1245
|
role: "none",
|
|
1161
|
-
className: "attention-surface"
|
|
1246
|
+
className: "dx-attention-surface"
|
|
1162
1247
|
});
|
|
1163
1248
|
}
|
|
1164
|
-
return /* @__PURE__ */
|
|
1249
|
+
return /* @__PURE__ */ React8.createElement("div", composableProps(props, {
|
|
1250
|
+
role: "none",
|
|
1251
|
+
className: "dx-container relative"
|
|
1252
|
+
}), /* @__PURE__ */ React8.createElement(Grid.Root, {
|
|
1165
1253
|
id: model.id ?? "table-grid"
|
|
1166
|
-
}, /* @__PURE__ */
|
|
1254
|
+
}, /* @__PURE__ */ React8.createElement(TableValueEditor, {
|
|
1167
1255
|
model,
|
|
1168
1256
|
modals,
|
|
1169
1257
|
schema,
|
|
1170
1258
|
onFocus: handleFocus,
|
|
1171
1259
|
onSave: handleSave,
|
|
1172
1260
|
onCreate
|
|
1173
|
-
}), /* @__PURE__ */
|
|
1174
|
-
className: mx("[--dx-grid-base:var(--
|
|
1261
|
+
}), /* @__PURE__ */ React8.createElement(Grid.Content, {
|
|
1262
|
+
className: mx("[--dx-grid-base:var(--base-surface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
|
|
1175
1263
|
frozen,
|
|
1176
1264
|
columns: columnMeta,
|
|
1177
1265
|
columnDefault,
|
|
@@ -1187,44 +1275,45 @@ var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate,
|
|
|
1187
1275
|
"data-testid": testId
|
|
1188
1276
|
},
|
|
1189
1277
|
ref: setDxGrid
|
|
1190
|
-
}), /* @__PURE__ */
|
|
1278
|
+
}), /* @__PURE__ */ React8.createElement(RowActionsMenu, {
|
|
1191
1279
|
model,
|
|
1192
1280
|
modals
|
|
1193
|
-
}), /* @__PURE__ */
|
|
1281
|
+
}), /* @__PURE__ */ React8.createElement(ColumnActionsMenu, {
|
|
1194
1282
|
model,
|
|
1195
1283
|
modals
|
|
1196
|
-
}), /* @__PURE__ */
|
|
1284
|
+
}), /* @__PURE__ */ React8.createElement(ColumnSettings, {
|
|
1197
1285
|
model,
|
|
1198
1286
|
modals,
|
|
1199
1287
|
onNewColumn: handleNewColumn
|
|
1200
|
-
}));
|
|
1288
|
+
})));
|
|
1201
1289
|
};
|
|
1202
1290
|
var TableMain = /* @__PURE__ */ forwardRef(TableMainInner);
|
|
1203
1291
|
var Table = {
|
|
1204
1292
|
Root: TableRoot,
|
|
1205
|
-
Main: TableMain
|
|
1293
|
+
Main: TableMain,
|
|
1294
|
+
Toolbar: TableToolbar
|
|
1206
1295
|
};
|
|
1207
1296
|
|
|
1208
1297
|
// src/components/Table/DynamicTable.tsx
|
|
1209
|
-
import { RegistryContext as
|
|
1210
|
-
import
|
|
1298
|
+
import { RegistryContext as RegistryContext3 } from "@effect-atom/atom-react";
|
|
1299
|
+
import React9, { useCallback as useCallback5, useContext as useContext3, useEffect as useEffect5, useMemo as useMemo6, useRef as useRef3, useState as useState5 } from "react";
|
|
1211
1300
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
1212
1301
|
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1213
|
-
var DynamicTable = ({ classNames, schema, name = "example.
|
|
1214
|
-
const registry =
|
|
1302
|
+
var DynamicTable = ({ classNames, schema, name = "com.example.dynamic-table", rows, properties, jsonSchema: jsonSchemaProp, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
1303
|
+
const registry = useContext3(RegistryContext3);
|
|
1215
1304
|
const [dynamicTable, setDynamicTable] = useState5();
|
|
1216
|
-
const { jsonSchema } =
|
|
1305
|
+
const { jsonSchema } = useMemo6(() => getBaseSchema({
|
|
1217
1306
|
typename: name,
|
|
1218
1307
|
properties,
|
|
1219
|
-
jsonSchema:
|
|
1308
|
+
jsonSchema: jsonSchemaProp,
|
|
1220
1309
|
schema
|
|
1221
1310
|
}), [
|
|
1222
1311
|
name,
|
|
1223
1312
|
properties,
|
|
1224
|
-
|
|
1313
|
+
jsonSchemaProp,
|
|
1225
1314
|
schema
|
|
1226
1315
|
]);
|
|
1227
|
-
|
|
1316
|
+
useEffect5(() => {
|
|
1228
1317
|
setDynamicTable(makeDynamicTable({
|
|
1229
1318
|
registry,
|
|
1230
1319
|
jsonSchema,
|
|
@@ -1258,7 +1347,7 @@ var DynamicTable = ({ classNames, schema, name = "example.com/dynamic-table", ro
|
|
|
1258
1347
|
onRowOrderChange: handleRowOrderChange,
|
|
1259
1348
|
onRowAction
|
|
1260
1349
|
});
|
|
1261
|
-
const presentation =
|
|
1350
|
+
const presentation = useMemo6(() => {
|
|
1262
1351
|
if (model) {
|
|
1263
1352
|
return new TablePresentation(registry, model);
|
|
1264
1353
|
}
|
|
@@ -1266,13 +1355,13 @@ var DynamicTable = ({ classNames, schema, name = "example.com/dynamic-table", ro
|
|
|
1266
1355
|
registry,
|
|
1267
1356
|
model
|
|
1268
1357
|
]);
|
|
1269
|
-
return /* @__PURE__ */
|
|
1358
|
+
return /* @__PURE__ */ React9.createElement("div", {
|
|
1270
1359
|
role: "none",
|
|
1271
|
-
className: mx2("
|
|
1272
|
-
}, /* @__PURE__ */
|
|
1360
|
+
className: mx2("w-full h-full grow grid", classNames)
|
|
1361
|
+
}, /* @__PURE__ */ React9.createElement("div", {
|
|
1273
1362
|
role: "none",
|
|
1274
|
-
className: "grid min-
|
|
1275
|
-
}, /* @__PURE__ */
|
|
1363
|
+
className: "grid min-h-0 overflow-hidden"
|
|
1364
|
+
}, /* @__PURE__ */ React9.createElement(Table.Root, null, /* @__PURE__ */ React9.createElement(Table.Main, {
|
|
1276
1365
|
ref: tableRef,
|
|
1277
1366
|
model,
|
|
1278
1367
|
presentation,
|
|
@@ -1280,93 +1369,6 @@ var DynamicTable = ({ classNames, schema, name = "example.com/dynamic-table", ro
|
|
|
1280
1369
|
onRowClick
|
|
1281
1370
|
}))));
|
|
1282
1371
|
};
|
|
1283
|
-
|
|
1284
|
-
// src/components/TableToolbar/TableToolbar.tsx
|
|
1285
|
-
import { Atom as Atom3, RegistryContext as RegistryContext3 } from "@effect-atom/atom-react";
|
|
1286
|
-
import React9, { useContext as useContext3, useEffect as useEffect5, useMemo as useMemo6 } from "react";
|
|
1287
|
-
import { MenuProvider, ToolbarMenu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
|
|
1288
|
-
var createTableToolbarActions = ({ stateAtom, onAdd, onSave, customActions }) => Atom3.make((get) => {
|
|
1289
|
-
const nodes = [];
|
|
1290
|
-
if (onAdd) {
|
|
1291
|
-
const add = createMenuAction("add-row", onAdd, {
|
|
1292
|
-
type: "add-row",
|
|
1293
|
-
icon: "ph--plus--regular",
|
|
1294
|
-
label: [
|
|
1295
|
-
"add row label",
|
|
1296
|
-
{
|
|
1297
|
-
ns: translationKey
|
|
1298
|
-
}
|
|
1299
|
-
],
|
|
1300
|
-
testId: "table.toolbar.add-row"
|
|
1301
|
-
});
|
|
1302
|
-
nodes.push(add);
|
|
1303
|
-
}
|
|
1304
|
-
if (onSave) {
|
|
1305
|
-
const state = get(stateAtom);
|
|
1306
|
-
const save = createMenuAction("save-view", onSave, {
|
|
1307
|
-
type: "save-view",
|
|
1308
|
-
icon: "ph--floppy-disk--regular",
|
|
1309
|
-
label: [
|
|
1310
|
-
"save view label",
|
|
1311
|
-
{
|
|
1312
|
-
ns: translationKey
|
|
1313
|
-
}
|
|
1314
|
-
],
|
|
1315
|
-
testId: "table.toolbar.save-view",
|
|
1316
|
-
iconOnly: false,
|
|
1317
|
-
hidden: !state.viewDirty
|
|
1318
|
-
});
|
|
1319
|
-
nodes.push(save);
|
|
1320
|
-
}
|
|
1321
|
-
const gap = createGapSeparator();
|
|
1322
|
-
nodes.push(...gap.nodes);
|
|
1323
|
-
const edges = nodes.map(({ id: target }) => ({
|
|
1324
|
-
source: "root",
|
|
1325
|
-
target
|
|
1326
|
-
}));
|
|
1327
|
-
if (customActions) {
|
|
1328
|
-
const custom = get(customActions);
|
|
1329
|
-
nodes.push(...custom.nodes);
|
|
1330
|
-
edges.push(...custom.edges);
|
|
1331
|
-
}
|
|
1332
|
-
return {
|
|
1333
|
-
nodes,
|
|
1334
|
-
edges
|
|
1335
|
-
};
|
|
1336
|
-
});
|
|
1337
|
-
var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
|
|
1338
|
-
const registry = useContext3(RegistryContext3);
|
|
1339
|
-
const stateAtom = useMemo6(() => Atom3.make({
|
|
1340
|
-
viewDirty
|
|
1341
|
-
}), []);
|
|
1342
|
-
useEffect5(() => {
|
|
1343
|
-
registry.set(stateAtom, {
|
|
1344
|
-
viewDirty
|
|
1345
|
-
});
|
|
1346
|
-
}, [
|
|
1347
|
-
registry,
|
|
1348
|
-
stateAtom,
|
|
1349
|
-
viewDirty
|
|
1350
|
-
]);
|
|
1351
|
-
const actionsCreator = useMemo6(() => createTableToolbarActions({
|
|
1352
|
-
stateAtom,
|
|
1353
|
-
onAdd,
|
|
1354
|
-
onSave,
|
|
1355
|
-
customActions
|
|
1356
|
-
}), [
|
|
1357
|
-
stateAtom,
|
|
1358
|
-
onAdd,
|
|
1359
|
-
onSave,
|
|
1360
|
-
customActions
|
|
1361
|
-
]);
|
|
1362
|
-
const menu = useMenuActions(actionsCreator);
|
|
1363
|
-
return /* @__PURE__ */ React9.createElement(MenuProvider, {
|
|
1364
|
-
...menu,
|
|
1365
|
-
attendableId
|
|
1366
|
-
}, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
|
|
1367
|
-
classNames
|
|
1368
|
-
}));
|
|
1369
|
-
};
|
|
1370
1372
|
export {
|
|
1371
1373
|
BUTTON_IDENTIFIERS,
|
|
1372
1374
|
CONTROL_IDENTIFIERS,
|