@dxos/react-ui-table 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549
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-5XWSB3JP.mjs +71 -0
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GS2UNGJK.mjs → chunk-KNC7XYT6.mjs} +116 -108
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +25 -13
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/{chunk-TRR3C5NX.mjs → chunk-CWSGS3Y2.mjs} +116 -108
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs +72 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +25 -13
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +14 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +2 -2
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +7 -6
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +67 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +2 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +0 -2
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +4 -5
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +6 -8
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +7 -3
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +1 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +21 -15
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/types/Table.d.ts +28 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +7 -6
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -38
- package/src/components/Table/DynamicTable.stories.tsx +7 -7
- package/src/components/Table/DynamicTable.tsx +12 -4
- package/src/components/Table/Relations.stories.tsx +9 -14
- package/src/components/Table/Table.stories.tsx +47 -42
- package/src/components/TableCellEditor/FormCellEditor.tsx +2 -2
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +5 -4
- package/src/components/TableCellEditor/TableCellEditor.tsx +4 -4
- package/src/components/TableToolbar/TableToolbar.tsx +1 -1
- package/src/components/testing.ts +3 -3
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useProjectionModel.ts +19 -0
- package/src/hooks/useTableModel.ts +10 -12
- package/src/model/table-model.test.ts +4 -4
- package/src/model/table-model.ts +27 -36
- package/src/model/table-presentation.test.ts +4 -4
- package/src/model/table-presentation.ts +9 -9
- package/src/model/table-sorting.ts +21 -12
- package/src/playwright/TableManager.ts +3 -3
- package/src/playwright/smoke.spec.ts +1 -1
- package/src/testing/useTestTableModel.ts +32 -24
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +89 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +9 -12
- package/dist/lib/browser/chunk-2PFAPQL4.mjs +0 -66
- package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +0 -7
- package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs +0 -67
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +0 -7
- package/dist/types/src/types/schema.d.ts +0 -28
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/types/schema.ts +0 -73
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-table",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.7ace549",
|
|
4
4
|
"description": "A table component.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -65,33 +65,33 @@
|
|
|
65
65
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
66
66
|
"date-fns": "^3.3.1",
|
|
67
67
|
"lodash.orderby": "^4.6.0",
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/keys": "0.8.4-main.
|
|
76
|
-
"@dxos/live-object": "0.8.4-main.
|
|
77
|
-
"@dxos/log": "0.8.4-main.
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/
|
|
80
|
-
"@dxos/random": "0.8.4-main.
|
|
81
|
-
"@dxos/react-
|
|
82
|
-
"@dxos/react-ui-
|
|
83
|
-
"@dxos/react-ui-
|
|
84
|
-
"@dxos/react-ui-
|
|
85
|
-
"@dxos/react-ui-
|
|
86
|
-
"@dxos/react-ui-
|
|
87
|
-
"@dxos/react-ui-
|
|
88
|
-
"@dxos/react-ui-
|
|
89
|
-
"@dxos/
|
|
90
|
-
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.
|
|
91
|
-
"@dxos/react-ui-types": "0.8.4-main.
|
|
92
|
-
"@dxos/
|
|
93
|
-
"@dxos/
|
|
94
|
-
"@dxos/
|
|
68
|
+
"@dxos/context": "0.8.4-main.7ace549",
|
|
69
|
+
"@dxos/async": "0.8.4-main.7ace549",
|
|
70
|
+
"@dxos/debug": "0.8.4-main.7ace549",
|
|
71
|
+
"@dxos/echo": "0.8.4-main.7ace549",
|
|
72
|
+
"@dxos/echo-db": "0.8.4-main.7ace549",
|
|
73
|
+
"@dxos/effect": "0.8.4-main.7ace549",
|
|
74
|
+
"@dxos/invariant": "0.8.4-main.7ace549",
|
|
75
|
+
"@dxos/keys": "0.8.4-main.7ace549",
|
|
76
|
+
"@dxos/live-object": "0.8.4-main.7ace549",
|
|
77
|
+
"@dxos/log": "0.8.4-main.7ace549",
|
|
78
|
+
"@dxos/lit-grid": "0.8.4-main.7ace549",
|
|
79
|
+
"@dxos/plugin-search": "0.8.4-main.7ace549",
|
|
80
|
+
"@dxos/random": "0.8.4-main.7ace549",
|
|
81
|
+
"@dxos/react-client": "0.8.4-main.7ace549",
|
|
82
|
+
"@dxos/react-ui-attention": "0.8.4-main.7ace549",
|
|
83
|
+
"@dxos/react-ui-components": "0.8.4-main.7ace549",
|
|
84
|
+
"@dxos/react-ui-editor": "0.8.4-main.7ace549",
|
|
85
|
+
"@dxos/react-ui-form": "0.8.4-main.7ace549",
|
|
86
|
+
"@dxos/react-ui-grid": "0.8.4-main.7ace549",
|
|
87
|
+
"@dxos/react-ui-menu": "0.8.4-main.7ace549",
|
|
88
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.7ace549",
|
|
89
|
+
"@dxos/react-ui-stack": "0.8.4-main.7ace549",
|
|
90
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.7ace549",
|
|
91
|
+
"@dxos/react-ui-types": "0.8.4-main.7ace549",
|
|
92
|
+
"@dxos/schema": "0.8.4-main.7ace549",
|
|
93
|
+
"@dxos/types": "0.8.4-main.7ace549",
|
|
94
|
+
"@dxos/util": "0.8.4-main.7ace549"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
97
|
"@effect-atom/atom-react": "^0.3.4",
|
|
@@ -104,14 +104,14 @@
|
|
|
104
104
|
"react": "~19.2.0",
|
|
105
105
|
"react-dom": "~19.2.0",
|
|
106
106
|
"vite": "7.1.9",
|
|
107
|
-
"@dxos/
|
|
108
|
-
"@dxos/
|
|
109
|
-
"@dxos/plugin-search": "0.8.4-main.
|
|
110
|
-
"@dxos/
|
|
111
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
112
|
-
"@dxos/
|
|
113
|
-
"@dxos/test-utils": "0.8.4-main.
|
|
114
|
-
"@dxos/
|
|
107
|
+
"@dxos/lit-ui": "0.8.4-main.7ace549",
|
|
108
|
+
"@dxos/random": "0.8.4-main.7ace549",
|
|
109
|
+
"@dxos/plugin-search": "0.8.4-main.7ace549",
|
|
110
|
+
"@dxos/react-ui": "0.8.4-main.7ace549",
|
|
111
|
+
"@dxos/react-ui-theme": "0.8.4-main.7ace549",
|
|
112
|
+
"@dxos/storybook-utils": "0.8.4-main.7ace549",
|
|
113
|
+
"@dxos/test-utils": "0.8.4-main.7ace549",
|
|
114
|
+
"@dxos/echo-signals": "0.8.4-main.7ace549"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"@effect-atom/atom-react": "^0.3.4",
|
|
@@ -119,8 +119,8 @@
|
|
|
119
119
|
"effect": "^3.13.3",
|
|
120
120
|
"react": "^19.0.0",
|
|
121
121
|
"react-dom": "^19.0.0",
|
|
122
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
123
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
122
|
+
"@dxos/react-ui": "0.8.4-main.7ace549",
|
|
123
|
+
"@dxos/react-ui-theme": "0.8.4-main.7ace549"
|
|
124
124
|
},
|
|
125
125
|
"publishConfig": {
|
|
126
126
|
"access": "public"
|
|
@@ -6,14 +6,14 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import {
|
|
9
|
+
import { Format, type JsonSchemaType } from '@dxos/echo/internal';
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
11
11
|
import { useClient } from '@dxos/react-client';
|
|
12
12
|
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
13
13
|
import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
14
14
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
15
|
import { type SchemaPropertyDefinition } from '@dxos/schema';
|
|
16
|
-
import {
|
|
16
|
+
import { TestSchema } from '@dxos/schema/testing';
|
|
17
17
|
|
|
18
18
|
import { type TableFeatures } from '../../model';
|
|
19
19
|
import { translations } from '../../translations';
|
|
@@ -25,8 +25,8 @@ faker.seed(0);
|
|
|
25
25
|
const useTestPropertiesAndObjects = () => {
|
|
26
26
|
const properties = useMemo<SchemaPropertyDefinition[]>(
|
|
27
27
|
() => [
|
|
28
|
-
{ name: 'name', format:
|
|
29
|
-
{ name: 'age', format:
|
|
28
|
+
{ name: 'name', format: Format.TypeFormat.String },
|
|
29
|
+
{ name: 'age', format: Format.TypeFormat.Number },
|
|
30
30
|
],
|
|
31
31
|
[],
|
|
32
32
|
);
|
|
@@ -132,7 +132,7 @@ export const WithEchoSchema: StoryObj = {
|
|
|
132
132
|
render: () => {
|
|
133
133
|
const client = useClient();
|
|
134
134
|
const { space } = useClientProvider();
|
|
135
|
-
const schema = useSchema(client, space,
|
|
135
|
+
const schema = useSchema(client, space, TestSchema.Person.typename);
|
|
136
136
|
const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
|
|
137
137
|
if (!schema) {
|
|
138
138
|
return <div>Loading schema...</div>;
|
|
@@ -142,13 +142,13 @@ export const WithEchoSchema: StoryObj = {
|
|
|
142
142
|
},
|
|
143
143
|
decorators: [
|
|
144
144
|
withClientProvider({
|
|
145
|
-
types: [
|
|
145
|
+
types: [TestSchema.Person],
|
|
146
146
|
createIdentity: true,
|
|
147
147
|
createSpace: true,
|
|
148
148
|
onCreateSpace: async ({ space }) => {
|
|
149
149
|
Array.from({ length: 10 }).forEach(() => {
|
|
150
150
|
space.db.add(
|
|
151
|
-
Obj.make(
|
|
151
|
+
Obj.make(TestSchema.Person, {
|
|
152
152
|
name: faker.person.fullName(),
|
|
153
153
|
email: faker.internet.email(),
|
|
154
154
|
}),
|
|
@@ -8,6 +8,7 @@ import React, { useCallback, useMemo, useRef } from 'react';
|
|
|
8
8
|
import { type JsonSchemaType } from '@dxos/echo/internal';
|
|
9
9
|
import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
|
|
10
10
|
import { mx } from '@dxos/react-ui-theme';
|
|
11
|
+
import { ProjectionModel } from '@dxos/schema';
|
|
11
12
|
|
|
12
13
|
import { useTableModel } from '../../hooks';
|
|
13
14
|
import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
|
|
@@ -50,7 +51,7 @@ export const DynamicTable = ({
|
|
|
50
51
|
[name, properties, _jsonSchema, schema],
|
|
51
52
|
);
|
|
52
53
|
|
|
53
|
-
const {
|
|
54
|
+
const { object, projection } = useMemo(() => makeDynamicTable({ jsonSchema, properties }), [jsonSchema, properties]);
|
|
54
55
|
|
|
55
56
|
const tableRef = useRef<TableController>(null);
|
|
56
57
|
const handleCellUpdate = useCallback((cell: any) => {
|
|
@@ -70,11 +71,18 @@ export const DynamicTable = ({
|
|
|
70
71
|
}) as const,
|
|
71
72
|
);
|
|
72
73
|
|
|
74
|
+
const projectionModel = useMemo(() => {
|
|
75
|
+
if (jsonSchema && projection) {
|
|
76
|
+
const model = new ProjectionModel(jsonSchema, projection);
|
|
77
|
+
model.normalizeView();
|
|
78
|
+
return model;
|
|
79
|
+
}
|
|
80
|
+
}, [jsonSchema, projection]);
|
|
81
|
+
|
|
73
82
|
const model = useTableModel({
|
|
74
83
|
rows,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
projection,
|
|
84
|
+
object,
|
|
85
|
+
projection: projectionModel,
|
|
78
86
|
features,
|
|
79
87
|
rowActions,
|
|
80
88
|
onCellUpdate: handleCellUpdate,
|
|
@@ -8,7 +8,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
8
8
|
import { expect, userEvent, within } from 'storybook/test';
|
|
9
9
|
|
|
10
10
|
import { Obj, Type } from '@dxos/echo';
|
|
11
|
-
import { type JsonSchemaType } from '@dxos/echo/internal';
|
|
12
11
|
import { type DxGrid } from '@dxos/lit-grid';
|
|
13
12
|
import '@dxos/lit-ui/dx-tag-picker.pcss';
|
|
14
13
|
import { faker } from '@dxos/random';
|
|
@@ -21,7 +20,7 @@ import { View } from '@dxos/schema';
|
|
|
21
20
|
import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
|
|
22
21
|
import { Organization, Person } from '@dxos/types';
|
|
23
22
|
|
|
24
|
-
import { useTableModel } from '../../hooks';
|
|
23
|
+
import { useProjectionModel, useTableModel } from '../../hooks';
|
|
25
24
|
import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
|
|
26
25
|
import { translations } from '../../translations';
|
|
27
26
|
import { Table } from '../../types';
|
|
@@ -38,8 +37,7 @@ const generator: ValueGenerator = faker as any;
|
|
|
38
37
|
const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
39
38
|
const client = useClient();
|
|
40
39
|
const { space } = useClientProvider();
|
|
41
|
-
const [
|
|
42
|
-
const [jsonSchema, setJsonSchema] = useState<JsonSchemaType>();
|
|
40
|
+
const [object, setObject] = useState<Table.Table>();
|
|
43
41
|
|
|
44
42
|
const features = useMemo<TableFeatures>(
|
|
45
43
|
() => ({ schemaEditable: false, dataEditable: true, selection: { enabled: false } }),
|
|
@@ -51,18 +49,15 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
|
|
|
51
49
|
return;
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
setJsonSchema(jsonSchema);
|
|
60
|
-
setView(view);
|
|
61
|
-
space.db.add(view);
|
|
62
|
-
await space.db.schemaRegistry.register([effectSchema]);
|
|
52
|
+
const { view, jsonSchema } = await View.makeFromSpace({ client, space, typename: Type.getTypename(schema) });
|
|
53
|
+
const object = Table.make({ view, jsonSchema });
|
|
54
|
+
setObject(object);
|
|
55
|
+
space.db.add(object);
|
|
56
|
+
await space.db.schemaRegistry.register([schema]);
|
|
63
57
|
}, [client, space, schema]);
|
|
64
58
|
|
|
65
|
-
const
|
|
59
|
+
const projection = useProjectionModel(schema, object);
|
|
60
|
+
const model = useTableModel<TableRow>({ object, projection, features });
|
|
66
61
|
|
|
67
62
|
useEffect(() => {
|
|
68
63
|
if (!model || !space) {
|
|
@@ -6,26 +6,18 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useCallback } from 'react';
|
|
8
8
|
|
|
9
|
-
import { Obj, type QueryAST, Type } from '@dxos/echo';
|
|
10
|
-
import {
|
|
11
|
-
EchoObject,
|
|
12
|
-
FormatAnnotation,
|
|
13
|
-
FormatEnum,
|
|
14
|
-
GeneratorAnnotation,
|
|
15
|
-
LabelAnnotation,
|
|
16
|
-
PropertyMetaAnnotationId,
|
|
17
|
-
} from '@dxos/echo/internal';
|
|
18
|
-
import { live } from '@dxos/echo/internal';
|
|
9
|
+
import { Annotation, Format, Obj, type QueryAST, Type } from '@dxos/echo';
|
|
10
|
+
import { PropertyMetaAnnotationId } from '@dxos/echo/internal';
|
|
19
11
|
import { invariant } from '@dxos/invariant';
|
|
20
12
|
import { faker } from '@dxos/random';
|
|
21
13
|
import { PublicKey } from '@dxos/react-client';
|
|
22
14
|
import { type Space } from '@dxos/react-client/echo';
|
|
23
15
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
24
16
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
25
|
-
import { ViewEditor } from '@dxos/react-ui-form';
|
|
17
|
+
import { ViewEditor, translations as formTranslations } from '@dxos/react-ui-form';
|
|
26
18
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
27
19
|
import { View, getSchemaFromPropertyDefinitions, getTypenameFromQuery } from '@dxos/schema';
|
|
28
|
-
import {
|
|
20
|
+
import { TestSchema, createObjectFactory } from '@dxos/schema/testing';
|
|
29
21
|
|
|
30
22
|
import { useTestTableModel } from '../../testing';
|
|
31
23
|
import { translations } from '../../translations';
|
|
@@ -34,13 +26,13 @@ import { TableToolbar } from '../TableToolbar';
|
|
|
34
26
|
|
|
35
27
|
import { Table as TableComponent } from './Table';
|
|
36
28
|
|
|
37
|
-
const
|
|
29
|
+
const Example = Schema.Struct({
|
|
38
30
|
// TODO(wittjosiah): Should be title. Currently name to work with default label.
|
|
39
31
|
name: Schema.optional(Schema.String).annotations({ title: 'Title' }),
|
|
40
32
|
urgent: Schema.optional(Schema.Boolean).annotations({ title: 'Urgent' }),
|
|
41
33
|
status: Schema.optional(
|
|
42
34
|
Schema.Literal('todo', 'in-progress', 'done')
|
|
43
|
-
.pipe(FormatAnnotation.set(
|
|
35
|
+
.pipe(Format.FormatAnnotation.set(Format.TypeFormat.SingleSelect))
|
|
44
36
|
.annotations({
|
|
45
37
|
title: 'Status',
|
|
46
38
|
[PropertyMetaAnnotationId]: {
|
|
@@ -55,14 +47,14 @@ const TestSchema = Schema.Struct({
|
|
|
55
47
|
}),
|
|
56
48
|
),
|
|
57
49
|
description: Schema.optional(Schema.String).annotations({ title: 'Description' }),
|
|
58
|
-
parent: Schema.optional(Schema.suspend((): Type.Ref<
|
|
50
|
+
parent: Schema.optional(Schema.suspend((): Type.Ref<Example> => Type.Ref(Example))).annotations({
|
|
59
51
|
title: 'Parent',
|
|
60
52
|
}),
|
|
61
53
|
}).pipe(
|
|
62
54
|
Type.Obj({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }),
|
|
63
|
-
LabelAnnotation.set(['name']),
|
|
55
|
+
Annotation.LabelAnnotation.set(['name']),
|
|
64
56
|
);
|
|
65
|
-
interface
|
|
57
|
+
interface Example extends Schema.Schema.Type<typeof Example> {}
|
|
66
58
|
|
|
67
59
|
const StoryViewEditor = ({
|
|
68
60
|
view,
|
|
@@ -109,7 +101,7 @@ const DefaultStory = () => {
|
|
|
109
101
|
const {
|
|
110
102
|
space,
|
|
111
103
|
schema,
|
|
112
|
-
|
|
104
|
+
table,
|
|
113
105
|
tableRef,
|
|
114
106
|
model,
|
|
115
107
|
presentation,
|
|
@@ -119,7 +111,7 @@ const DefaultStory = () => {
|
|
|
119
111
|
handleDeleteColumn,
|
|
120
112
|
} = useTestTableModel();
|
|
121
113
|
|
|
122
|
-
if (!schema || !view) {
|
|
114
|
+
if (!schema || !table?.view.target) {
|
|
123
115
|
return <div />;
|
|
124
116
|
}
|
|
125
117
|
|
|
@@ -139,9 +131,14 @@ const DefaultStory = () => {
|
|
|
139
131
|
</TableComponent.Root>
|
|
140
132
|
</div>
|
|
141
133
|
<div className='flex flex-col bs-full border-l border-separator overflow-y-auto'>
|
|
142
|
-
<StoryViewEditor
|
|
134
|
+
<StoryViewEditor
|
|
135
|
+
view={table.view.target}
|
|
136
|
+
schema={schema}
|
|
137
|
+
space={space}
|
|
138
|
+
handleDeleteColumn={handleDeleteColumn}
|
|
139
|
+
/>
|
|
143
140
|
<SyntaxHighlighter language='json' className='text-xs'>
|
|
144
|
-
{JSON.stringify({ view, schema }, null, 2)}
|
|
141
|
+
{JSON.stringify({ view: table.view.target, schema }, null, 2)}
|
|
145
142
|
</SyntaxHighlighter>
|
|
146
143
|
</div>
|
|
147
144
|
</div>
|
|
@@ -166,14 +163,15 @@ const meta = {
|
|
|
166
163
|
createIdentity: true,
|
|
167
164
|
createSpace: true,
|
|
168
165
|
onCreateSpace: async ({ client, space }) => {
|
|
169
|
-
const [schema] = await space.db.schemaRegistry.register([
|
|
170
|
-
const { view } = await
|
|
166
|
+
const [schema] = await space.db.schemaRegistry.register([Example]);
|
|
167
|
+
const { view, jsonSchema } = await View.makeFromSpace({ client, space, typename: schema.typename });
|
|
168
|
+
const table = Table.make({ view, jsonSchema });
|
|
171
169
|
view.projection.fields = [
|
|
172
170
|
view.projection.fields.find((field: any) => field.path === 'name')!,
|
|
173
171
|
...view.projection.fields.filter((field: any) => field.path !== 'name'),
|
|
174
172
|
];
|
|
175
173
|
|
|
176
|
-
space.db.add(
|
|
174
|
+
space.db.add(table);
|
|
177
175
|
|
|
178
176
|
Array.from({ length: 10 }).map(() => {
|
|
179
177
|
return space.db.add(
|
|
@@ -192,7 +190,7 @@ const meta = {
|
|
|
192
190
|
controls: {
|
|
193
191
|
disable: true,
|
|
194
192
|
},
|
|
195
|
-
translations,
|
|
193
|
+
translations: [...translations, ...formTranslations],
|
|
196
194
|
},
|
|
197
195
|
} satisfies Meta<typeof TableComponent>;
|
|
198
196
|
|
|
@@ -210,25 +208,26 @@ export const StaticSchema: StoryObj = {
|
|
|
210
208
|
createIdentity: true,
|
|
211
209
|
createSpace: true,
|
|
212
210
|
onCreateSpace: async ({ client, space }) => {
|
|
213
|
-
const { view } = await
|
|
214
|
-
|
|
211
|
+
const { view, jsonSchema } = await View.makeFromSpace({ client, space, typename: TestSchema.Person.typename });
|
|
212
|
+
const table = Table.make({ view, jsonSchema });
|
|
213
|
+
space.db.add(table);
|
|
215
214
|
|
|
216
215
|
const factory = createObjectFactory(space.db, faker as any);
|
|
217
216
|
await factory([
|
|
218
|
-
{ type:
|
|
219
|
-
// { type:
|
|
217
|
+
{ type: TestSchema.Person, count: 10 },
|
|
218
|
+
// { type: TestSchema.Organization, count: 1 },
|
|
220
219
|
]);
|
|
221
220
|
},
|
|
222
221
|
}),
|
|
223
222
|
],
|
|
224
223
|
parameters: {
|
|
225
224
|
layout: 'fullscreen',
|
|
226
|
-
translations,
|
|
225
|
+
translations: [...translations, ...formTranslations],
|
|
227
226
|
},
|
|
228
227
|
};
|
|
229
228
|
|
|
230
229
|
const ContactWithArrayOfEmails = Schema.Struct({
|
|
231
|
-
name: Schema.String.pipe(GeneratorAnnotation.set('person.fullName')),
|
|
230
|
+
name: Schema.String.pipe(Annotation.GeneratorAnnotation.set('person.fullName')),
|
|
232
231
|
emails: Schema.optional(
|
|
233
232
|
Schema.Array(
|
|
234
233
|
Schema.Struct({
|
|
@@ -238,7 +237,7 @@ const ContactWithArrayOfEmails = Schema.Struct({
|
|
|
238
237
|
),
|
|
239
238
|
),
|
|
240
239
|
}).pipe(
|
|
241
|
-
|
|
240
|
+
Type.Obj({
|
|
242
241
|
typename: 'dxos.org/type/ContactWithArrayOfEmails',
|
|
243
242
|
version: '0.1.0',
|
|
244
243
|
}),
|
|
@@ -248,17 +247,22 @@ export const ArrayOfObjects: StoryObj = {
|
|
|
248
247
|
render: DefaultStory,
|
|
249
248
|
decorators: [
|
|
250
249
|
withClientProvider({
|
|
251
|
-
types: [View.View, Table.Table,
|
|
250
|
+
types: [View.View, Table.Table, TestSchema.Person, TestSchema.Organization, ContactWithArrayOfEmails],
|
|
252
251
|
createIdentity: true,
|
|
253
252
|
createSpace: true,
|
|
254
253
|
onCreateSpace: async ({ client, space }) => {
|
|
255
|
-
const { view } = await
|
|
256
|
-
|
|
254
|
+
const { view, jsonSchema } = await View.makeFromSpace({
|
|
255
|
+
client,
|
|
256
|
+
space,
|
|
257
|
+
typename: ContactWithArrayOfEmails.typename,
|
|
258
|
+
});
|
|
259
|
+
const table = Table.make({ view, jsonSchema });
|
|
260
|
+
space.db.add(table);
|
|
257
261
|
|
|
258
262
|
const factory = createObjectFactory(space.db, faker as any);
|
|
259
263
|
await factory([
|
|
260
|
-
// { type:
|
|
261
|
-
// { type:
|
|
264
|
+
// { type: TestSchema.Person, count: 10 },
|
|
265
|
+
// { type: TestSchema.Organization, count: 1 },
|
|
262
266
|
{ type: ContactWithArrayOfEmails, count: 10 },
|
|
263
267
|
]);
|
|
264
268
|
},
|
|
@@ -294,25 +298,26 @@ export const Tags: Meta<StoryProps> = {
|
|
|
294
298
|
const schema = getSchemaFromPropertyDefinitions(typename, [
|
|
295
299
|
{
|
|
296
300
|
name: 'single',
|
|
297
|
-
format:
|
|
301
|
+
format: Format.TypeFormat.SingleSelect,
|
|
298
302
|
config: { options: selectOptions },
|
|
299
303
|
},
|
|
300
304
|
{
|
|
301
305
|
name: 'multiple',
|
|
302
|
-
format:
|
|
306
|
+
format: Format.TypeFormat.MultiSelect,
|
|
303
307
|
config: { options: selectOptions },
|
|
304
308
|
},
|
|
305
309
|
]);
|
|
306
310
|
const [storedSchema] = await space.db.schemaRegistry.register([schema]);
|
|
307
311
|
|
|
308
312
|
// Initialize table.
|
|
309
|
-
const { view } = await
|
|
310
|
-
|
|
313
|
+
const { view, jsonSchema } = await View.makeFromSpace({ client, space, typename });
|
|
314
|
+
const table = Table.make({ view, jsonSchema });
|
|
315
|
+
space.db.add(table);
|
|
311
316
|
|
|
312
317
|
// Populate.
|
|
313
318
|
Array.from({ length: 10 }).map(() => {
|
|
314
319
|
return space.db.add(
|
|
315
|
-
|
|
320
|
+
Obj.make(storedSchema, {
|
|
316
321
|
single: faker.helpers.arrayElement([...selectOptionIds, undefined]),
|
|
317
322
|
multiple: faker.helpers.randomSubset(selectOptionIds),
|
|
318
323
|
}),
|
|
@@ -6,7 +6,7 @@ import * as Schema from 'effect/Schema';
|
|
|
6
6
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { Filter, Obj } from '@dxos/echo';
|
|
9
|
-
import {
|
|
9
|
+
import { Format, Ref, type TypeAnnotation, getValue } from '@dxos/echo/internal';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { getSnapshot } from '@dxos/live-object';
|
|
12
12
|
import { type Client } from '@dxos/react-client';
|
|
@@ -151,7 +151,7 @@ export const FormCellEditor = ({
|
|
|
151
151
|
}, []);
|
|
152
152
|
|
|
153
153
|
const refSchema = useMemo(() => {
|
|
154
|
-
if (fieldProjection.props.format ===
|
|
154
|
+
if (fieldProjection.props.format === Format.TypeFormat.Ref && fieldProjection.props.referenceSchema) {
|
|
155
155
|
const { schema: refSchema } = getSchema({
|
|
156
156
|
typename: fieldProjection.props.referenceSchema,
|
|
157
157
|
});
|
|
@@ -24,9 +24,9 @@ type StoryProps = {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const DefaultStory = ({ editing }: StoryProps) => {
|
|
27
|
-
const { model,
|
|
27
|
+
const { model, table } = useTestTableModel();
|
|
28
28
|
|
|
29
|
-
if (!model || !
|
|
29
|
+
if (!model || !table) {
|
|
30
30
|
return <div />;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -50,8 +50,9 @@ const meta = {
|
|
|
50
50
|
createIdentity: true,
|
|
51
51
|
createSpace: true,
|
|
52
52
|
onCreateSpace: async ({ client, space }) => {
|
|
53
|
-
const { view } = await
|
|
54
|
-
|
|
53
|
+
const { view, jsonSchema } = await View.makeFromSpace({ client, space, typename: Task.Task.typename });
|
|
54
|
+
const table = Table.make({ view, jsonSchema });
|
|
55
|
+
space.db.add(table);
|
|
55
56
|
Array.from({ length: 10 }).forEach(() => {
|
|
56
57
|
space.db.add(
|
|
57
58
|
Obj.make(Task.Task, {
|
|
@@ -9,7 +9,7 @@ import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
|
9
9
|
|
|
10
10
|
import { debounce } from '@dxos/async';
|
|
11
11
|
import type { Client } from '@dxos/client';
|
|
12
|
-
import {
|
|
12
|
+
import { Format, TypeEnum } from '@dxos/echo/internal';
|
|
13
13
|
import { invariant } from '@dxos/invariant';
|
|
14
14
|
import { type DxGridAxis, type DxGridPosition } from '@dxos/lit-grid';
|
|
15
15
|
import {
|
|
@@ -74,9 +74,9 @@ export const TableValueEditor = ({
|
|
|
74
74
|
|
|
75
75
|
if (
|
|
76
76
|
fieldProjection?.props.type === TypeEnum.Array ||
|
|
77
|
-
fieldProjection?.props.format ===
|
|
78
|
-
fieldProjection?.props.format ===
|
|
79
|
-
// TODO(thure): Support `
|
|
77
|
+
fieldProjection?.props.format === Format.TypeFormat.SingleSelect ||
|
|
78
|
+
fieldProjection?.props.format === Format.TypeFormat.Ref
|
|
79
|
+
// TODO(thure): Support `Format.TypeFormat.MultiSelect`
|
|
80
80
|
) {
|
|
81
81
|
return (
|
|
82
82
|
<FormCellEditor
|
|
@@ -58,7 +58,7 @@ const createTableToolbarActions = ({
|
|
|
58
58
|
const add = createMenuAction<TableToolbarActionProperties>('add-row', onAdd, {
|
|
59
59
|
type: 'add-row' as const,
|
|
60
60
|
icon: 'ph--plus--regular',
|
|
61
|
-
label: ['add row', { ns: translationKey }],
|
|
61
|
+
label: ['add row label', { ns: translationKey }],
|
|
62
62
|
testId: 'table.toolbar.add-row',
|
|
63
63
|
});
|
|
64
64
|
nodes.push(add);
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
import { useEffect } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Format } from '@dxos/echo';
|
|
9
|
+
import { TypeEnum, TypedObject, setValue } from '@dxos/echo/internal';
|
|
9
10
|
import { live } from '@dxos/live-object';
|
|
10
11
|
import { faker } from '@dxos/random';
|
|
11
12
|
import { type ProjectionModel } from '@dxos/schema';
|
|
12
13
|
|
|
13
14
|
export const TestSchema = TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
|
|
14
|
-
id: ObjectId,
|
|
15
15
|
name: Schema.optional(Schema.String),
|
|
16
16
|
age: Schema.optional(Schema.Number),
|
|
17
17
|
active: Schema.optional(Schema.Boolean),
|
|
@@ -88,7 +88,7 @@ export const useSimulator = ({ items, projection, insertInterval, updateInterval
|
|
|
88
88
|
|
|
89
89
|
if (format) {
|
|
90
90
|
switch (format) {
|
|
91
|
-
case
|
|
91
|
+
case Format.TypeFormat.Currency: {
|
|
92
92
|
item[path] = Math.floor(Math.random() * 1000);
|
|
93
93
|
break;
|
|
94
94
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Type } from '@dxos/echo';
|
|
8
|
+
import { ProjectionModel } from '@dxos/schema';
|
|
9
|
+
|
|
10
|
+
import { type Table } from '../types';
|
|
11
|
+
|
|
12
|
+
export const useProjectionModel = <S extends Type.Entity.Any>(schema: S | undefined, table: Table.Table | undefined) =>
|
|
13
|
+
useMemo(() => {
|
|
14
|
+
if (schema && table?.view.target?.projection) {
|
|
15
|
+
const projection = new ProjectionModel(Type.toJsonSchema(schema), table.view.target.projection);
|
|
16
|
+
projection.normalizeView();
|
|
17
|
+
return projection;
|
|
18
|
+
}
|
|
19
|
+
}, [schema, table?.view.target?.projection]);
|