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