@dxos/react-ui-table 0.8.0 → 0.8.1-main.81238a8
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-3FR6NHPD.mjs → chunk-5MKYB7NF.mjs} +5 -7
- package/dist/lib/browser/chunk-5MKYB7NF.mjs.map +7 -0
- package/dist/lib/browser/{_deprecated → deprecated}/index.mjs +26 -26
- package/dist/lib/{node-esm/_deprecated → browser/deprecated}/index.mjs.map +4 -4
- package/dist/lib/browser/index.mjs +289 -123
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{chunk-NB3SFHGA.cjs → chunk-NRFKBRPV.cjs} +7 -9
- package/dist/lib/node/chunk-NRFKBRPV.cjs.map +7 -0
- package/dist/lib/node/{_deprecated → deprecated}/index.cjs +5 -5
- package/dist/lib/node/{_deprecated → deprecated}/index.cjs.map +4 -4
- package/dist/lib/node/index.cjs +282 -120
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +3 -3
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{chunk-RLVVOZW5.mjs → chunk-SU4D55KI.mjs} +5 -7
- package/dist/lib/node-esm/chunk-SU4D55KI.mjs.map +7 -0
- package/dist/lib/node-esm/{_deprecated → deprecated}/index.mjs +26 -26
- package/dist/lib/node-esm/deprecated/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +289 -123
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +2 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +19 -0
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -0
- package/dist/types/src/components/Table/RefPanel.d.ts +2 -1
- package/dist/types/src/components/Table/RefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +2 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +6 -1
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +2 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/index.d.ts +1 -0
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +2 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +14 -7
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/{_deprecated → deprecated}/components/Cell/Cell.d.ts +2 -2
- package/dist/types/src/deprecated/components/Cell/Cell.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/Cell/CellCombobox.d.ts +2 -1
- package/dist/types/src/deprecated/components/Cell/CellCombobox.d.ts.map +1 -0
- package/dist/types/src/deprecated/components/Cell/index.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnMenu.d.ts +3 -2
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnMenu.stories.d.ts +3 -2
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnSettings.d.ts +2 -1
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnSettings.stories.d.ts +3 -2
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -0
- package/dist/types/src/deprecated/components/ColumnMenu/index.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/Table/Table.d.ts +5 -5
- package/dist/types/src/deprecated/components/Table/Table.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/Table/Table.stories.d.ts +8 -7
- package/dist/types/src/deprecated/components/Table/Table.stories.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/Table/TableBody.d.ts +2 -1
- package/dist/types/src/deprecated/components/Table/TableBody.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/Table/TableContext.d.ts +1 -1
- package/dist/types/src/deprecated/components/Table/TableContext.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/components/Table/TableHead.d.ts +2 -1
- package/dist/types/src/deprecated/components/Table/TableHead.d.ts.map +1 -0
- package/dist/types/src/deprecated/components/Table/TableRootContext.d.ts.map +1 -0
- package/dist/types/src/deprecated/components/Table/index.d.ts.map +1 -0
- package/dist/types/src/deprecated/components/Table/props.d.ts.map +1 -0
- package/dist/types/src/deprecated/components/index.d.ts.map +1 -0
- package/dist/types/src/deprecated/helpers.d.ts.map +1 -0
- package/dist/types/src/deprecated/hooks/index.d.ts.map +1 -0
- package/dist/types/src/deprecated/hooks/useColumnSizing.d.ts.map +1 -0
- package/dist/types/src/deprecated/hooks/useColumnSorting.d.ts.map +1 -0
- package/dist/types/src/deprecated/hooks/usePinLastRow.d.ts.map +1 -0
- package/dist/types/src/deprecated/hooks/useRowSelection.d.ts.map +1 -0
- package/dist/types/src/deprecated/index.d.ts.map +1 -0
- package/dist/types/src/{_deprecated → deprecated}/schema/Schema.stories.d.ts +2 -1
- package/dist/types/src/deprecated/schema/Schema.stories.d.ts.map +1 -0
- package/dist/types/src/deprecated/schema/column-utils.d.ts.map +1 -0
- package/dist/types/src/deprecated/schema/index.d.ts.map +1 -0
- package/dist/types/src/deprecated/schema/types.d.ts.map +1 -0
- package/dist/types/src/deprecated/theme.d.ts.map +1 -0
- package/dist/types/src/deprecated/translations.d.ts.map +1 -0
- package/dist/types/src/deprecated/types.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +5 -2
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +26 -7
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +16 -21
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +40 -0
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/package.json +35 -35
- package/src/components/Table/ColumnSettings.tsx +5 -6
- package/src/components/Table/CreateRefPanel.tsx +3 -3
- package/src/components/Table/DynamicTable.tsx +86 -0
- package/src/components/Table/RefPanel.tsx +3 -3
- package/src/components/Table/RowActionsMenu.tsx +13 -0
- package/src/components/Table/Table.stories.tsx +27 -2
- package/src/components/Table/Table.tsx +29 -10
- package/src/components/Table/index.ts +1 -0
- package/src/components/testing.ts +1 -0
- package/src/{_deprecated → deprecated}/components/Cell/Cell.tsx +2 -2
- package/src/{_deprecated → deprecated}/components/Table/TableBody.tsx +2 -2
- package/src/{_deprecated → deprecated}/helpers.tsx +2 -2
- package/src/{_deprecated → deprecated}/schema/Schema.stories.tsx +1 -1
- package/src/hooks/useTableModel.ts +22 -6
- package/src/model/table-model.test.ts +1 -1
- package/src/model/table-model.ts +76 -21
- package/src/model/table-presentation.test.ts +1 -1
- package/src/model/table-presentation.ts +3 -3
- package/src/model/table-sorting.ts +1 -0
- package/src/types/table.ts +5 -7
- package/src/util/dynamic-table.ts +71 -0
- package/src/util/index.ts +1 -0
- package/dist/lib/browser/_deprecated/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-3FR6NHPD.mjs.map +0 -7
- package/dist/lib/node/chunk-NB3SFHGA.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-RLVVOZW5.mjs.map +0 -7
- package/dist/types/src/_deprecated/components/Cell/Cell.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Cell/CellCombobox.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Cell/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/ColumnMenu/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/Table.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableBody.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableContext.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableHead.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/TableRootContext.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/Table/props.d.ts.map +0 -1
- package/dist/types/src/_deprecated/components/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/helpers.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/useColumnSizing.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/usePinLastRow.d.ts.map +0 -1
- package/dist/types/src/_deprecated/hooks/useRowSelection.d.ts.map +0 -1
- package/dist/types/src/_deprecated/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/Schema.stories.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/column-utils.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/index.d.ts.map +0 -1
- package/dist/types/src/_deprecated/schema/types.d.ts.map +0 -1
- package/dist/types/src/_deprecated/theme.d.ts.map +0 -1
- package/dist/types/src/_deprecated/translations.d.ts.map +0 -1
- package/dist/types/src/_deprecated/types.d.ts.map +0 -1
- /package/dist/types/src/{_deprecated → deprecated}/components/Cell/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/components/ColumnMenu/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/components/Table/TableRootContext.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/components/Table/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/components/Table/props.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/components/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/helpers.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/hooks/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/hooks/useColumnSizing.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/hooks/useColumnSorting.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/hooks/usePinLastRow.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/hooks/useRowSelection.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/schema/column-utils.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/schema/index.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/schema/types.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/theme.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/translations.d.ts +0 -0
- /package/dist/types/src/{_deprecated → deprecated}/types.d.ts +0 -0
- /package/src/{_deprecated → deprecated}/components/Cell/CellCombobox.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/Cell/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnMenu.stories.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnMenu.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnSettings.stories.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/ColumnMenu/ColumnSettings.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/ColumnMenu/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/Table.stories.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/Table.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/TableContext.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/TableHead.tsx +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/TableRootContext.ts +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/components/Table/props.ts +0 -0
- /package/src/{_deprecated → deprecated}/components/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/hooks/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/hooks/useColumnSizing.ts +0 -0
- /package/src/{_deprecated → deprecated}/hooks/useColumnSorting.ts +0 -0
- /package/src/{_deprecated → deprecated}/hooks/usePinLastRow.ts +0 -0
- /package/src/{_deprecated → deprecated}/hooks/useRowSelection.ts +0 -0
- /package/src/{_deprecated → deprecated}/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/schema/column-utils.ts +0 -0
- /package/src/{_deprecated → deprecated}/schema/index.ts +0 -0
- /package/src/{_deprecated → deprecated}/schema/types.ts +0 -0
- /package/src/{_deprecated → deprecated}/theme.ts +0 -0
- /package/src/{_deprecated → deprecated}/translations.ts +0 -0
- /package/src/{_deprecated → deprecated}/types.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TableSchema,
|
|
3
3
|
TableType
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5MKYB7NF.mjs";
|
|
5
5
|
|
|
6
6
|
// packages/ui/react-ui-table/src/translations.ts
|
|
7
7
|
var translationKey = "table";
|
|
@@ -39,12 +39,12 @@ var translations_default = [
|
|
|
39
39
|
import React7, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4 } from "react";
|
|
40
40
|
import { getValue as getValue4 } from "@dxos/echo-schema";
|
|
41
41
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
42
|
-
import { Filter
|
|
43
|
-
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
42
|
+
import { Filter } from "@dxos/react-client/echo";
|
|
43
|
+
import { useDefaultValue, useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
44
44
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
45
45
|
import { Grid, closestCell } from "@dxos/react-ui-grid";
|
|
46
46
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
47
|
-
import { isNotFalsy } from "@dxos/util";
|
|
47
|
+
import { isNotFalsy, safeParseInt } from "@dxos/util";
|
|
48
48
|
|
|
49
49
|
// packages/ui/react-ui-table/src/components/Table/ColumnActionsMenu.tsx
|
|
50
50
|
import React from "react";
|
|
@@ -83,13 +83,12 @@ var ColumnActionsMenu = ({ model, modals }) => {
|
|
|
83
83
|
|
|
84
84
|
// packages/ui/react-ui-table/src/components/Table/ColumnSettings.tsx
|
|
85
85
|
import React2, { useCallback, useEffect, useMemo, useState } from "react";
|
|
86
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
87
86
|
import { DropdownMenu as DropdownMenu2 } from "@dxos/react-ui";
|
|
88
87
|
import { FieldEditor } from "@dxos/react-ui-form";
|
|
89
88
|
var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
90
89
|
const [newField, setNewField] = useState();
|
|
91
90
|
const state = modals.state.value;
|
|
92
|
-
const space =
|
|
91
|
+
const space = model?.space;
|
|
93
92
|
useEffect(() => {
|
|
94
93
|
if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
|
|
95
94
|
setNewField(model.projection.createFieldProjection());
|
|
@@ -107,12 +106,12 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
|
107
106
|
if (state?.type === "columnSettings") {
|
|
108
107
|
const { mode } = state;
|
|
109
108
|
if (mode.type === "edit") {
|
|
110
|
-
return model?.
|
|
109
|
+
return model?.view?.fields.find((f) => f.id === mode.fieldId);
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
return void 0;
|
|
114
113
|
}, [
|
|
115
|
-
model?.
|
|
114
|
+
model?.view?.fields,
|
|
116
115
|
state
|
|
117
116
|
]);
|
|
118
117
|
const field = existingField ?? newField;
|
|
@@ -130,7 +129,7 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
|
130
129
|
state,
|
|
131
130
|
newField
|
|
132
131
|
]);
|
|
133
|
-
if (!model?.
|
|
132
|
+
if (!model?.view || !model.projection || !field) {
|
|
134
133
|
return null;
|
|
135
134
|
}
|
|
136
135
|
return /* @__PURE__ */ React2.createElement(DropdownMenu2.Root, {
|
|
@@ -141,7 +140,7 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
|
141
140
|
}), /* @__PURE__ */ React2.createElement(DropdownMenu2.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu2.Content, {
|
|
142
141
|
classNames: "md:is-64"
|
|
143
142
|
}, /* @__PURE__ */ React2.createElement(DropdownMenu2.Viewport, null, /* @__PURE__ */ React2.createElement(FieldEditor, {
|
|
144
|
-
view: model.
|
|
143
|
+
view: model.view,
|
|
145
144
|
projection: model.projection,
|
|
146
145
|
field,
|
|
147
146
|
registry: space?.db.schemaRegistry,
|
|
@@ -153,13 +152,13 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
|
153
152
|
// packages/ui/react-ui-table/src/components/Table/CreateRefPanel.tsx
|
|
154
153
|
import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
155
154
|
import { S } from "@dxos/echo-schema";
|
|
156
|
-
import { create
|
|
155
|
+
import { create } from "@dxos/react-client/echo";
|
|
157
156
|
import { Popover } from "@dxos/react-ui";
|
|
158
157
|
import { Form } from "@dxos/react-ui-form";
|
|
159
158
|
import { useGridContext } from "@dxos/react-ui-grid";
|
|
160
159
|
var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
161
160
|
const { id: gridId } = useGridContext("TableCellEditor", __gridScope);
|
|
162
|
-
const space =
|
|
161
|
+
const space = model?.space;
|
|
163
162
|
const state = modals.state.value;
|
|
164
163
|
const schema = useMemo2(() => {
|
|
165
164
|
if (!space || state?.type !== "createRefPanel") {
|
|
@@ -200,7 +199,7 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
200
199
|
}, [
|
|
201
200
|
modals
|
|
202
201
|
]);
|
|
203
|
-
if (!model?.
|
|
202
|
+
if (!model?.view || !model.projection) {
|
|
204
203
|
return null;
|
|
205
204
|
}
|
|
206
205
|
return /* @__PURE__ */ React3.createElement(Popover.Root, {
|
|
@@ -226,7 +225,6 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
226
225
|
|
|
227
226
|
// packages/ui/react-ui-table/src/components/Table/RefPanel.tsx
|
|
228
227
|
import React4 from "react";
|
|
229
|
-
import { getSpace as getSpace3 } from "@dxos/react-client/echo";
|
|
230
228
|
import { Popover as Popover2 } from "@dxos/react-ui";
|
|
231
229
|
import { Form as Form2 } from "@dxos/react-ui-form";
|
|
232
230
|
var getRefTargetObj = (space, id) => {
|
|
@@ -238,10 +236,10 @@ var getRefTargetObj = (space, id) => {
|
|
|
238
236
|
};
|
|
239
237
|
var RefPanel = ({ model, modals }) => {
|
|
240
238
|
const state = modals.state.value;
|
|
241
|
-
const space =
|
|
239
|
+
const space = model?.space;
|
|
242
240
|
const targetObj = getRefTargetObj(space, state?.type === "refPanel" ? state.targetId : void 0);
|
|
243
241
|
const schema = space && state?.type === "refPanel" ? space.db.schemaRegistry.getSchema(state.typename) : void 0;
|
|
244
|
-
if (!model.
|
|
242
|
+
if (!model.view || !model.projection) {
|
|
245
243
|
return null;
|
|
246
244
|
}
|
|
247
245
|
return /* @__PURE__ */ React4.createElement(Popover2.Root, {
|
|
@@ -282,7 +280,14 @@ var RowActionsMenu = ({ model, modals }) => {
|
|
|
282
280
|
}), /* @__PURE__ */ React5.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React5.createElement(DropdownMenu3.Viewport, null, /* @__PURE__ */ React5.createElement(DropdownMenu3.Item, {
|
|
283
281
|
"data-testid": "row-menu-delete",
|
|
284
282
|
onClick: () => model.deleteRow(state.rowIndex)
|
|
285
|
-
}, t(hasSelection ? "bulk delete row label" : "delete row label"))
|
|
283
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React5.createElement(DropdownMenu3.Item, {
|
|
284
|
+
key: action.id,
|
|
285
|
+
"data-testid": `row-action-${action.id}`,
|
|
286
|
+
onClick: () => {
|
|
287
|
+
modals.close();
|
|
288
|
+
model.handleRowAction(action.id, state.rowIndex);
|
|
289
|
+
}
|
|
290
|
+
}, t(action.translationKey)))), /* @__PURE__ */ React5.createElement(DropdownMenu3.Arrow, null)));
|
|
286
291
|
};
|
|
287
292
|
|
|
288
293
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
@@ -290,22 +295,76 @@ import { computed as computed3, effect as effect2, signal as signal3 } from "@pr
|
|
|
290
295
|
import { Resource as Resource2 } from "@dxos/context";
|
|
291
296
|
import { FormatEnum as FormatEnum3, getValue as getValue2, setValue } from "@dxos/echo-schema";
|
|
292
297
|
import { invariant } from "@dxos/invariant";
|
|
293
|
-
import { isReactiveObject, makeRef as
|
|
294
|
-
import { PublicKey as PublicKey2 } from "@dxos/react-client";
|
|
298
|
+
import { isReactiveObject, makeRef as makeRef3 } from "@dxos/live-object";
|
|
295
299
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
296
300
|
|
|
297
301
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
298
302
|
import { computed, effect, signal } from "@preact/signals-core";
|
|
299
303
|
import { Resource } from "@dxos/context";
|
|
300
304
|
|
|
305
|
+
// packages/ui/react-ui-table/src/util/dynamic-table.ts
|
|
306
|
+
import { create as create2, makeRef } from "@dxos/live-object";
|
|
307
|
+
import { createView, echoSchemaFromPropertyDefinitions, ViewProjection } from "@dxos/schema";
|
|
308
|
+
var makeDynamicTable = (typename, properties) => {
|
|
309
|
+
const table = create2(TableType, {
|
|
310
|
+
name: "dynamic-table"
|
|
311
|
+
});
|
|
312
|
+
const echoSchema = echoSchemaFromPropertyDefinitions(typename, properties);
|
|
313
|
+
const propertyNames = properties.map((property) => property.name);
|
|
314
|
+
const view = createView({
|
|
315
|
+
name: "dynamic-table",
|
|
316
|
+
typename: echoSchema.typename,
|
|
317
|
+
jsonSchema: echoSchema.jsonSchema,
|
|
318
|
+
fields: propertyNames
|
|
319
|
+
});
|
|
320
|
+
table.view = makeRef(view);
|
|
321
|
+
const viewProjection = new ViewProjection(echoSchema, view);
|
|
322
|
+
for (const property of properties) {
|
|
323
|
+
if (!view.fields) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const field = view.fields.find((field2) => field2.path === property.name);
|
|
327
|
+
if (field) {
|
|
328
|
+
if (property.size !== void 0) {
|
|
329
|
+
field.size = property.size;
|
|
330
|
+
}
|
|
331
|
+
if (property.title !== void 0) {
|
|
332
|
+
const fieldProjection = viewProjection.getFieldProjection(field.id);
|
|
333
|
+
viewProjection.setFieldProjection({
|
|
334
|
+
...fieldProjection,
|
|
335
|
+
props: {
|
|
336
|
+
...fieldProjection.props,
|
|
337
|
+
title: property.title
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (property.sort) {
|
|
342
|
+
const fieldId = field.id;
|
|
343
|
+
view.query.sort = [
|
|
344
|
+
{
|
|
345
|
+
fieldId,
|
|
346
|
+
direction: property.sort
|
|
347
|
+
}
|
|
348
|
+
];
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
table,
|
|
354
|
+
schema: echoSchema,
|
|
355
|
+
view,
|
|
356
|
+
viewProjection
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
|
|
301
360
|
// packages/ui/react-ui-table/src/util/signals.ts
|
|
302
361
|
var touch = (value) => value;
|
|
303
362
|
|
|
304
363
|
// packages/ui/react-ui-table/src/util/table.ts
|
|
305
364
|
import { AST, Format, FormatEnum, S as S2, TypedObject, TypeEnum } from "@dxos/echo-schema";
|
|
306
365
|
import { PublicKey } from "@dxos/react-client";
|
|
307
|
-
import { create as
|
|
308
|
-
import { createFieldId, createView, getSchemaProperties, ViewProjection } from "@dxos/schema";
|
|
366
|
+
import { create as create3, makeRef as makeRef2 } from "@dxos/react-client/echo";
|
|
367
|
+
import { createFieldId, createView as createView2, getSchemaProperties, ViewProjection as ViewProjection2 } from "@dxos/schema";
|
|
309
368
|
var initializeTable = async ({ space, table, initialRow = true, initialSchema }) => {
|
|
310
369
|
if (initialSchema) {
|
|
311
370
|
const schema = await space.db.schemaRegistry.query({
|
|
@@ -315,7 +374,7 @@ var initializeTable = async ({ space, table, initialRow = true, initialSchema })
|
|
|
315
374
|
throw new Error(`Schema not found: ${initialSchema}`);
|
|
316
375
|
}
|
|
317
376
|
const fields = getSchemaProperties(schema.ast).filter((prop) => prop.format !== FormatEnum.Ref).map((prop) => prop.name);
|
|
318
|
-
table.view =
|
|
377
|
+
table.view = makeRef2(createView2({
|
|
319
378
|
// TODO(ZaymonFC): Don't hardcode name?
|
|
320
379
|
name: "View",
|
|
321
380
|
typename: schema.typename,
|
|
@@ -340,7 +399,7 @@ var initializeTable = async ({ space, table, initialRow = true, initialSchema })
|
|
|
340
399
|
const [contactSchema] = await space.db.schemaRegistry.register([
|
|
341
400
|
ContactSchema
|
|
342
401
|
]);
|
|
343
|
-
table.view =
|
|
402
|
+
table.view = makeRef2(createView2({
|
|
344
403
|
name: "View",
|
|
345
404
|
typename: contactSchema.typename,
|
|
346
405
|
jsonSchema: contactSchema.jsonSchema,
|
|
@@ -351,7 +410,7 @@ var initializeTable = async ({ space, table, initialRow = true, initialSchema })
|
|
|
351
410
|
"active"
|
|
352
411
|
]
|
|
353
412
|
}));
|
|
354
|
-
const projection = new
|
|
413
|
+
const projection = new ViewProjection2(contactSchema, table.view.target);
|
|
355
414
|
projection.setFieldProjection({
|
|
356
415
|
field: {
|
|
357
416
|
id: table.view.target.fields.find((f) => f.path === "salary").id,
|
|
@@ -381,7 +440,7 @@ var initializeTable = async ({ space, table, initialRow = true, initialSchema })
|
|
|
381
440
|
}
|
|
382
441
|
});
|
|
383
442
|
if (initialRow) {
|
|
384
|
-
space.db.add(
|
|
443
|
+
space.db.add(create3(contactSchema, {}));
|
|
385
444
|
}
|
|
386
445
|
return contactSchema;
|
|
387
446
|
}
|
|
@@ -805,12 +864,11 @@ var TableSorting = class {
|
|
|
805
864
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
806
865
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
807
866
|
var TableModel = class extends Resource2 {
|
|
808
|
-
constructor({
|
|
867
|
+
constructor({ id, space, view, projection, sorting = [], pinnedRows = {
|
|
809
868
|
top: [],
|
|
810
869
|
bottom: []
|
|
811
|
-
}, onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChanged }) {
|
|
870
|
+
}, onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChanged, rowActions = [], onRowAction }) {
|
|
812
871
|
super();
|
|
813
|
-
this.id = `table-model-${PublicKey2.random().truncate()}`;
|
|
814
872
|
this._visibleRange = signal3({
|
|
815
873
|
start: {
|
|
816
874
|
row: 0,
|
|
@@ -829,7 +887,7 @@ var TableModel = class extends Resource2 {
|
|
|
829
887
|
this._rows.value = obj;
|
|
830
888
|
};
|
|
831
889
|
this.getRowCount = () => this._rows.value.length;
|
|
832
|
-
this.getColumnCount = () => this.
|
|
890
|
+
this.getColumnCount = () => this._view?.fields.length ?? 0;
|
|
833
891
|
this.insertRow = (rowIndex) => {
|
|
834
892
|
const row = rowIndex !== void 0 ? this._sorting.getDataIndex(rowIndex) : this._rows.value.length;
|
|
835
893
|
this._onInsertRow?.(row);
|
|
@@ -846,8 +904,18 @@ var TableModel = class extends Resource2 {
|
|
|
846
904
|
}
|
|
847
905
|
this._onDeleteRows?.(row, objectsToDelete);
|
|
848
906
|
};
|
|
907
|
+
this.handleRowAction = (actionId, rowIndex) => {
|
|
908
|
+
if (!this._onRowAction) {
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
912
|
+
const data = this._rows.value[row];
|
|
913
|
+
if (data) {
|
|
914
|
+
this._onRowAction(actionId, data);
|
|
915
|
+
}
|
|
916
|
+
};
|
|
849
917
|
this.getCellData = ({ col, row }) => {
|
|
850
|
-
const fields = this.
|
|
918
|
+
const fields = this._view?.fields ?? [];
|
|
851
919
|
if (col < 0 || col >= fields.length) {
|
|
852
920
|
return void 0;
|
|
853
921
|
}
|
|
@@ -876,7 +944,7 @@ var TableModel = class extends Resource2 {
|
|
|
876
944
|
};
|
|
877
945
|
this.setCellData = ({ col, row }, value) => {
|
|
878
946
|
const rowIdx = this._sorting.getDataIndex(row);
|
|
879
|
-
const fields = this.
|
|
947
|
+
const fields = this._view?.fields ?? [];
|
|
880
948
|
if (col < 0 || col >= fields.length) {
|
|
881
949
|
return;
|
|
882
950
|
}
|
|
@@ -885,7 +953,7 @@ var TableModel = class extends Resource2 {
|
|
|
885
953
|
switch (props.format) {
|
|
886
954
|
case FormatEnum3.Ref: {
|
|
887
955
|
if (isReactiveObject(value)) {
|
|
888
|
-
setValue(this._rows.value[rowIdx], field.path,
|
|
956
|
+
setValue(this._rows.value[rowIdx], field.path, makeRef3(value));
|
|
889
957
|
}
|
|
890
958
|
break;
|
|
891
959
|
}
|
|
@@ -899,9 +967,11 @@ var TableModel = class extends Resource2 {
|
|
|
899
967
|
}
|
|
900
968
|
}
|
|
901
969
|
};
|
|
902
|
-
this.
|
|
970
|
+
this._id = id;
|
|
971
|
+
this._space = space;
|
|
972
|
+
this._view = view;
|
|
903
973
|
this._projection = projection;
|
|
904
|
-
this._sorting = new TableSorting(this._rows,
|
|
974
|
+
this._sorting = new TableSorting(this._rows, this._view, projection);
|
|
905
975
|
if (sorting.length > 0) {
|
|
906
976
|
const [sort] = sorting;
|
|
907
977
|
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
@@ -912,9 +982,17 @@ var TableModel = class extends Resource2 {
|
|
|
912
982
|
this._onDeleteColumn = onDeleteColumn;
|
|
913
983
|
this._onCellUpdate = onCellUpdate;
|
|
914
984
|
this._onRowOrderChanged = onRowOrderChanged;
|
|
985
|
+
this._rowActions = rowActions;
|
|
986
|
+
this._onRowAction = onRowAction;
|
|
987
|
+
}
|
|
988
|
+
get id() {
|
|
989
|
+
return this._id;
|
|
915
990
|
}
|
|
916
|
-
get
|
|
917
|
-
return this.
|
|
991
|
+
get space() {
|
|
992
|
+
return this._space;
|
|
993
|
+
}
|
|
994
|
+
get view() {
|
|
995
|
+
return this._view;
|
|
918
996
|
}
|
|
919
997
|
get projection() {
|
|
920
998
|
return this._projection;
|
|
@@ -928,13 +1006,22 @@ var TableModel = class extends Resource2 {
|
|
|
928
1006
|
get sorting() {
|
|
929
1007
|
return this._sorting;
|
|
930
1008
|
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Gets the row data at the specified display index.
|
|
1011
|
+
*/
|
|
1012
|
+
getRowAt(displayIndex) {
|
|
1013
|
+
if (displayIndex < 0 || displayIndex >= this._sorting.sortedRows.value.length) {
|
|
1014
|
+
return void 0;
|
|
1015
|
+
}
|
|
1016
|
+
return this._sorting.sortedRows.value[displayIndex];
|
|
1017
|
+
}
|
|
931
1018
|
get pinnedRows() {
|
|
932
1019
|
return this._pinnedRows;
|
|
933
1020
|
}
|
|
934
1021
|
get columnMeta() {
|
|
935
1022
|
invariant(this._columnMeta, void 0, {
|
|
936
1023
|
F: __dxlog_file,
|
|
937
|
-
L:
|
|
1024
|
+
L: 155,
|
|
938
1025
|
S: this,
|
|
939
1026
|
A: [
|
|
940
1027
|
"this._columnMeta",
|
|
@@ -950,6 +1037,9 @@ var TableModel = class extends Resource2 {
|
|
|
950
1037
|
get isViewDirty() {
|
|
951
1038
|
return this._sorting.isDirty;
|
|
952
1039
|
}
|
|
1040
|
+
get rowActions() {
|
|
1041
|
+
return this._rowActions;
|
|
1042
|
+
}
|
|
953
1043
|
//
|
|
954
1044
|
// Initialisation
|
|
955
1045
|
//
|
|
@@ -961,7 +1051,7 @@ var TableModel = class extends Resource2 {
|
|
|
961
1051
|
}
|
|
962
1052
|
initializeColumnMeta() {
|
|
963
1053
|
this._columnMeta = computed3(() => {
|
|
964
|
-
const fields = this.
|
|
1054
|
+
const fields = this._view?.fields ?? [];
|
|
965
1055
|
const meta = Object.fromEntries(fields.map((field, index) => [
|
|
966
1056
|
index,
|
|
967
1057
|
{
|
|
@@ -998,7 +1088,7 @@ var TableModel = class extends Resource2 {
|
|
|
998
1088
|
for (let row = start.row; row <= end.row; row++) {
|
|
999
1089
|
rowEffects.push(effect2(() => {
|
|
1000
1090
|
const obj = this._sorting.sortedRows.value[row];
|
|
1001
|
-
this?.
|
|
1091
|
+
this._view?.fields.forEach((field) => touch(getValue2(obj, field.path)));
|
|
1002
1092
|
this._onCellUpdate?.({
|
|
1003
1093
|
row,
|
|
1004
1094
|
col: start.col,
|
|
@@ -1017,7 +1107,7 @@ var TableModel = class extends Resource2 {
|
|
|
1017
1107
|
*/
|
|
1018
1108
|
updateCellData({ col, row }, update) {
|
|
1019
1109
|
const dataRow = this._sorting.getDataIndex(row);
|
|
1020
|
-
const fields = this.
|
|
1110
|
+
const fields = this._view?.fields ?? [];
|
|
1021
1111
|
const field = fields[col];
|
|
1022
1112
|
const value = getValue2(this._rows.value[dataRow], field.path);
|
|
1023
1113
|
const updatedValue = update(value);
|
|
@@ -1027,10 +1117,10 @@ var TableModel = class extends Resource2 {
|
|
|
1027
1117
|
// Column Operations
|
|
1028
1118
|
//
|
|
1029
1119
|
deleteColumn(fieldId) {
|
|
1030
|
-
if (!this.
|
|
1120
|
+
if (!this._view) {
|
|
1031
1121
|
return;
|
|
1032
1122
|
}
|
|
1033
|
-
const field = this.
|
|
1123
|
+
const field = this._view?.fields.find((field2) => field2.id === fieldId);
|
|
1034
1124
|
if (field && this._onDeleteColumn) {
|
|
1035
1125
|
this._onDeleteColumn(field.id);
|
|
1036
1126
|
}
|
|
@@ -1039,7 +1129,7 @@ var TableModel = class extends Resource2 {
|
|
|
1039
1129
|
// Resize
|
|
1040
1130
|
//
|
|
1041
1131
|
setColumnWidth(columnIndex, width) {
|
|
1042
|
-
const fields = this.
|
|
1132
|
+
const fields = this._view?.fields ?? [];
|
|
1043
1133
|
if (columnIndex < fields.length) {
|
|
1044
1134
|
const newWidth = Math.max(0, width);
|
|
1045
1135
|
const field = fields[columnIndex];
|
|
@@ -1197,7 +1287,7 @@ var TablePresentation = class {
|
|
|
1197
1287
|
}
|
|
1198
1288
|
getMainGridCells(range) {
|
|
1199
1289
|
const cells = {};
|
|
1200
|
-
const fields = this.model.
|
|
1290
|
+
const fields = this.model.view?.fields ?? [];
|
|
1201
1291
|
const addCell = (obj, field, colIndex, displayIndex) => {
|
|
1202
1292
|
const { props } = this.model.projection.getFieldProjection(field.id);
|
|
1203
1293
|
const cell = {
|
|
@@ -1289,7 +1379,7 @@ var TablePresentation = class {
|
|
|
1289
1379
|
}
|
|
1290
1380
|
getHeaderCells(range) {
|
|
1291
1381
|
const cells = {};
|
|
1292
|
-
const fields = this.model.
|
|
1382
|
+
const fields = this.model.view?.fields ?? [];
|
|
1293
1383
|
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
1294
1384
|
const { field, props } = this.model.projection.getFieldProjection(fields[col].id);
|
|
1295
1385
|
const sorting = this.model.sorting?.sorting;
|
|
@@ -1379,7 +1469,7 @@ var TablePresentation = class {
|
|
|
1379
1469
|
row: 0
|
|
1380
1470
|
})]: {
|
|
1381
1471
|
accessoryHtml: tableButtons.addColumn.render({
|
|
1382
|
-
disabled: (this.model.
|
|
1472
|
+
disabled: (this.model.view?.fields?.length ?? 0) >= VIEW_FIELD_LIMIT
|
|
1383
1473
|
}),
|
|
1384
1474
|
className: "!bg-gridHeader",
|
|
1385
1475
|
readonly: true,
|
|
@@ -1606,22 +1696,27 @@ var determineNavigationDelta = ({ key, shift }) => {
|
|
|
1606
1696
|
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
|
|
1607
1697
|
var inlineEndLine = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-separator";
|
|
1608
1698
|
var blockEndLine = "[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-separator";
|
|
1609
|
-
var frozen = {
|
|
1610
|
-
frozenRowsStart: 1,
|
|
1611
|
-
frozenColsStart: 1,
|
|
1612
|
-
frozenColsEnd: 1
|
|
1613
|
-
};
|
|
1614
1699
|
var TableRoot = ({ children, role }) => {
|
|
1615
1700
|
return /* @__PURE__ */ React7.createElement("div", {
|
|
1616
1701
|
role: "none",
|
|
1617
1702
|
className: mx2("relative border-bs !border-separator", role === "section" ? "attention-surface overflow-hidden [&_.dx-grid]:max-is-[--dx-grid-content-inline-size]" : "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:bs-0 [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]")
|
|
1618
1703
|
}, children);
|
|
1619
1704
|
};
|
|
1620
|
-
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention }, forwardedRef) => {
|
|
1705
|
+
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, onRowClicked, features }, forwardedRef) => {
|
|
1621
1706
|
const [dxGrid, setDxGrid] = useState2(null);
|
|
1622
|
-
const { hasAttention } = useAttention(model?.
|
|
1707
|
+
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
1623
1708
|
const { t } = useTranslation3(translationKey);
|
|
1624
1709
|
const modals = useMemo4(() => new ModalController(), []);
|
|
1710
|
+
const { selection } = useDefaultValue(features, () => ({
|
|
1711
|
+
selection: true
|
|
1712
|
+
}));
|
|
1713
|
+
const frozen = useMemo4(() => ({
|
|
1714
|
+
frozenRowsStart: 1,
|
|
1715
|
+
frozenColsStart: selection ? 1 : 0,
|
|
1716
|
+
frozenColsEnd: 1
|
|
1717
|
+
}), [
|
|
1718
|
+
selection
|
|
1719
|
+
]);
|
|
1625
1720
|
useImperativeHandle(forwardedRef, () => {
|
|
1626
1721
|
if (!presentation || !dxGrid) {
|
|
1627
1722
|
return {};
|
|
@@ -1642,6 +1737,13 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1642
1737
|
dxGrid
|
|
1643
1738
|
]);
|
|
1644
1739
|
const handleGridClick = useCallback4((event) => {
|
|
1740
|
+
if (onRowClicked) {
|
|
1741
|
+
const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
|
|
1742
|
+
if (rowIndex != null) {
|
|
1743
|
+
const row = model?.getRowAt(rowIndex);
|
|
1744
|
+
row && onRowClicked(row);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1645
1747
|
if (!modals) {
|
|
1646
1748
|
return;
|
|
1647
1749
|
}
|
|
@@ -1773,10 +1875,10 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1773
1875
|
]);
|
|
1774
1876
|
const handleQuery = useCallback4(async ({ field, props }, text) => {
|
|
1775
1877
|
if (model && props.referenceSchema && field.referencePath) {
|
|
1776
|
-
const space =
|
|
1878
|
+
const space = model.space;
|
|
1777
1879
|
invariant3(space, void 0, {
|
|
1778
1880
|
F: __dxlog_file4,
|
|
1779
|
-
L:
|
|
1881
|
+
L: 283,
|
|
1780
1882
|
S: void 0,
|
|
1781
1883
|
A: [
|
|
1782
1884
|
"space",
|
|
@@ -1818,7 +1920,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1818
1920
|
});
|
|
1819
1921
|
}
|
|
1820
1922
|
return /* @__PURE__ */ React7.createElement(Grid.Root, {
|
|
1821
|
-
id: model.
|
|
1923
|
+
id: model.id ?? "table-grid"
|
|
1822
1924
|
}, /* @__PURE__ */ React7.createElement(TableCellEditor, {
|
|
1823
1925
|
model,
|
|
1824
1926
|
modals,
|
|
@@ -1831,7 +1933,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1831
1933
|
frozen,
|
|
1832
1934
|
columns: model.columnMeta.value,
|
|
1833
1935
|
limitRows: model.getRowCount() ?? 0,
|
|
1834
|
-
limitColumns: model.
|
|
1936
|
+
limitColumns: model.view?.fields?.length ?? 0,
|
|
1835
1937
|
onAxisResize: handleAxisResize,
|
|
1836
1938
|
onClick: handleGridClick,
|
|
1837
1939
|
onKeyDown: handleKeyDown,
|
|
@@ -1860,9 +1962,131 @@ var Table = {
|
|
|
1860
1962
|
Main: TableMain
|
|
1861
1963
|
};
|
|
1862
1964
|
|
|
1965
|
+
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
1966
|
+
import React8, { useRef as useRef2, useMemo as useMemo5, useCallback as useCallback5 } from "react";
|
|
1967
|
+
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
1968
|
+
|
|
1969
|
+
// packages/ui/react-ui-table/src/hooks/useTableModel.ts
|
|
1970
|
+
import { effect as effect3 } from "@preact/signals-core";
|
|
1971
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
1972
|
+
import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
|
|
1973
|
+
import { useSelectionActions } from "@dxos/react-ui-attention";
|
|
1974
|
+
import { isNonNullable } from "@dxos/util";
|
|
1975
|
+
var useTableModel = ({ objects, table, projection, onSelectionChanged, rowActions, onRowAction, ...props }) => {
|
|
1976
|
+
const [model, setModel] = useState3();
|
|
1977
|
+
useEffect2(() => {
|
|
1978
|
+
if (!table || !projection) {
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
let model2;
|
|
1982
|
+
const t = setTimeout(async () => {
|
|
1983
|
+
model2 = new TableModel({
|
|
1984
|
+
id: fullyQualifiedId(table),
|
|
1985
|
+
space: getSpace(table),
|
|
1986
|
+
view: table.view?.target,
|
|
1987
|
+
projection,
|
|
1988
|
+
rowActions,
|
|
1989
|
+
onRowAction,
|
|
1990
|
+
...props
|
|
1991
|
+
});
|
|
1992
|
+
await model2.open();
|
|
1993
|
+
setModel(model2);
|
|
1994
|
+
});
|
|
1995
|
+
return () => {
|
|
1996
|
+
clearTimeout(t);
|
|
1997
|
+
void model2?.close();
|
|
1998
|
+
};
|
|
1999
|
+
}, [
|
|
2000
|
+
table,
|
|
2001
|
+
projection,
|
|
2002
|
+
table?.view?.target,
|
|
2003
|
+
rowActions
|
|
2004
|
+
]);
|
|
2005
|
+
useEffect2(() => {
|
|
2006
|
+
if (objects) {
|
|
2007
|
+
model?.setRows(objects);
|
|
2008
|
+
}
|
|
2009
|
+
}, [
|
|
2010
|
+
model,
|
|
2011
|
+
objects
|
|
2012
|
+
]);
|
|
2013
|
+
const { select, clear } = useSelectionActions([
|
|
2014
|
+
table?.id,
|
|
2015
|
+
table?.view?.target?.query.typename
|
|
2016
|
+
].filter(isNonNullable));
|
|
2017
|
+
useEffect2(() => {
|
|
2018
|
+
if (!model) {
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
const unsubscribe = effect3(() => {
|
|
2022
|
+
const selectedItems = [
|
|
2023
|
+
...model.selection.selection.value
|
|
2024
|
+
];
|
|
2025
|
+
select(selectedItems);
|
|
2026
|
+
onSelectionChanged?.(selectedItems);
|
|
2027
|
+
});
|
|
2028
|
+
return () => {
|
|
2029
|
+
clear();
|
|
2030
|
+
unsubscribe();
|
|
2031
|
+
};
|
|
2032
|
+
}, [
|
|
2033
|
+
model,
|
|
2034
|
+
onSelectionChanged
|
|
2035
|
+
]);
|
|
2036
|
+
return model;
|
|
2037
|
+
};
|
|
2038
|
+
|
|
2039
|
+
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
2040
|
+
var DynamicTable = ({ data, properties, classNames, tableName = "com.example/dynamic_table", onRowClicked, rowActions, onRowAction }) => {
|
|
2041
|
+
const { table, viewProjection } = useMemo5(() => {
|
|
2042
|
+
return makeDynamicTable(tableName, properties);
|
|
2043
|
+
}, [
|
|
2044
|
+
tableName,
|
|
2045
|
+
properties
|
|
2046
|
+
]);
|
|
2047
|
+
const tableRef = useRef2(null);
|
|
2048
|
+
const handleCellUpdate = useCallback5((cell) => {
|
|
2049
|
+
tableRef.current?.update?.(cell);
|
|
2050
|
+
}, []);
|
|
2051
|
+
const handleRowOrderChanged = useCallback5(() => {
|
|
2052
|
+
tableRef.current?.update?.();
|
|
2053
|
+
}, []);
|
|
2054
|
+
const model = useTableModel({
|
|
2055
|
+
table,
|
|
2056
|
+
objects: data,
|
|
2057
|
+
projection: viewProjection,
|
|
2058
|
+
onCellUpdate: handleCellUpdate,
|
|
2059
|
+
onRowOrderChanged: handleRowOrderChanged,
|
|
2060
|
+
rowActions,
|
|
2061
|
+
onRowAction
|
|
2062
|
+
});
|
|
2063
|
+
const presentation = useMemo5(() => {
|
|
2064
|
+
if (model) {
|
|
2065
|
+
return new TablePresentation(model);
|
|
2066
|
+
}
|
|
2067
|
+
}, [
|
|
2068
|
+
model
|
|
2069
|
+
]);
|
|
2070
|
+
const features = useMemo5(() => ({
|
|
2071
|
+
selection: false
|
|
2072
|
+
}), []);
|
|
2073
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
2074
|
+
className: mx3("is-full bs-full grow grid", classNames)
|
|
2075
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
2076
|
+
className: "grid min-bs-0 overflow-hidden"
|
|
2077
|
+
}, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
|
|
2078
|
+
ref: tableRef,
|
|
2079
|
+
model,
|
|
2080
|
+
presentation,
|
|
2081
|
+
features,
|
|
2082
|
+
onRowClicked,
|
|
2083
|
+
ignoreAttention: true
|
|
2084
|
+
}))));
|
|
2085
|
+
};
|
|
2086
|
+
|
|
1863
2087
|
// packages/ui/react-ui-table/src/components/TableToolbar/TableToolbar.tsx
|
|
1864
|
-
import
|
|
1865
|
-
import { create as
|
|
2088
|
+
import React9, { useCallback as useCallback6, useMemo as useMemo6 } from "react";
|
|
2089
|
+
import { create as create4 } from "@dxos/live-object";
|
|
1866
2090
|
import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
|
|
1867
2091
|
var createTableToolbarActions = (state) => {
|
|
1868
2092
|
const add = createMenuAction("add-row", {
|
|
@@ -1916,84 +2140,25 @@ var createTableToolbarActions = (state) => {
|
|
|
1916
2140
|
};
|
|
1917
2141
|
};
|
|
1918
2142
|
var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
|
|
1919
|
-
const state =
|
|
2143
|
+
const state = useMemo6(() => create4({
|
|
1920
2144
|
viewDirty
|
|
1921
2145
|
}), []);
|
|
1922
|
-
const actionsCreator =
|
|
2146
|
+
const actionsCreator = useCallback6(() => createTableToolbarActions(state), [
|
|
1923
2147
|
state
|
|
1924
2148
|
]);
|
|
1925
2149
|
const menu = useMenuActions(actionsCreator);
|
|
1926
|
-
return /* @__PURE__ */
|
|
2150
|
+
return /* @__PURE__ */ React9.createElement(MenuProvider, {
|
|
1927
2151
|
...menu,
|
|
1928
2152
|
attendableId,
|
|
1929
2153
|
onAction
|
|
1930
|
-
}, /* @__PURE__ */
|
|
2154
|
+
}, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
|
|
1931
2155
|
classNames
|
|
1932
2156
|
}));
|
|
1933
2157
|
};
|
|
1934
|
-
|
|
1935
|
-
// packages/ui/react-ui-table/src/hooks/useTableModel.ts
|
|
1936
|
-
import { effect as effect3 } from "@preact/signals-core";
|
|
1937
|
-
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
1938
|
-
import { useSelectionActions } from "@dxos/react-ui-attention";
|
|
1939
|
-
import { isNonNullable } from "@dxos/util";
|
|
1940
|
-
var useTableModel = ({ objects, table, projection, ...props }) => {
|
|
1941
|
-
const [model, setModel] = useState3();
|
|
1942
|
-
useEffect2(() => {
|
|
1943
|
-
if (!table || !projection) {
|
|
1944
|
-
return;
|
|
1945
|
-
}
|
|
1946
|
-
let model2;
|
|
1947
|
-
const t = setTimeout(async () => {
|
|
1948
|
-
model2 = new TableModel({
|
|
1949
|
-
table,
|
|
1950
|
-
projection,
|
|
1951
|
-
...props
|
|
1952
|
-
});
|
|
1953
|
-
await model2.open();
|
|
1954
|
-
setModel(model2);
|
|
1955
|
-
});
|
|
1956
|
-
return () => {
|
|
1957
|
-
clearTimeout(t);
|
|
1958
|
-
void model2?.close();
|
|
1959
|
-
};
|
|
1960
|
-
}, [
|
|
1961
|
-
table,
|
|
1962
|
-
projection
|
|
1963
|
-
]);
|
|
1964
|
-
useEffect2(() => {
|
|
1965
|
-
if (objects) {
|
|
1966
|
-
model?.setRows(objects);
|
|
1967
|
-
}
|
|
1968
|
-
}, [
|
|
1969
|
-
model,
|
|
1970
|
-
objects
|
|
1971
|
-
]);
|
|
1972
|
-
const { select, clear } = useSelectionActions([
|
|
1973
|
-
table?.id,
|
|
1974
|
-
table?.view?.target?.query.typename
|
|
1975
|
-
].filter(isNonNullable));
|
|
1976
|
-
useEffect2(() => {
|
|
1977
|
-
if (!model) {
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
const unsubscribe = effect3(() => {
|
|
1981
|
-
select([
|
|
1982
|
-
...model.selection.selection.value
|
|
1983
|
-
]);
|
|
1984
|
-
});
|
|
1985
|
-
return () => {
|
|
1986
|
-
clear();
|
|
1987
|
-
unsubscribe();
|
|
1988
|
-
};
|
|
1989
|
-
}, [
|
|
1990
|
-
model
|
|
1991
|
-
]);
|
|
1992
|
-
return model;
|
|
1993
|
-
};
|
|
1994
2158
|
export {
|
|
1995
2159
|
BUTTON_IDENTIFIERS,
|
|
1996
2160
|
CONTROL_IDENTIFIERS,
|
|
2161
|
+
DynamicTable,
|
|
1997
2162
|
ModalController,
|
|
1998
2163
|
Table,
|
|
1999
2164
|
TableModel,
|
|
@@ -2002,6 +2167,7 @@ export {
|
|
|
2002
2167
|
TableToolbar,
|
|
2003
2168
|
TableType,
|
|
2004
2169
|
initializeTable,
|
|
2170
|
+
makeDynamicTable,
|
|
2005
2171
|
renderCheckbox,
|
|
2006
2172
|
renderSwitch,
|
|
2007
2173
|
tableButtons,
|