@dxos/react-ui-form 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +2008 -840
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +83 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2008 -840
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +85 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +64 -61
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +71 -17
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +148 -86
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +24 -8
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +26 -13
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +11 -9
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts +19 -0
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts +50 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts +119 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts +30 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/index.d.ts +4 -0
- package/dist/types/src/components/Form/Layout/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts +31 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +4 -4
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/DateField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/DateField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts +13 -0
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +8 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +85 -0
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +12 -6
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts +4 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +64 -61
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/index.d.ts +2 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +3 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/meta-tags.d.ts +30 -0
- package/dist/types/src/components/Form/meta-tags.d.ts.map +1 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts +2 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +8 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
- package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +28 -6
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +64 -61
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +128 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts +9 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts +87 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/index.d.ts +2 -0
- package/dist/types/src/components/ObjectTree/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +28 -33
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.stories.d.ts +65 -61
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +9 -11
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +68 -66
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +13 -4
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts +2 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +64 -61
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field-type.d.ts +19 -0
- package/dist/types/src/util/field-type.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +18 -1
- package/dist/types/src/util/properties.d.ts.map +1 -1
- package/dist/types/src/util/properties.test.d.ts +2 -0
- package/dist/types/src/util/properties.test.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +1 -0
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +48 -41
- package/src/components/FieldEditor/FieldEditor.stories.tsx +4 -4
- package/src/components/FieldEditor/FieldEditor.test.tsx +4 -2
- package/src/components/FieldEditor/FieldEditor.tsx +23 -17
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +46 -65
- package/src/components/Form/Form.tsx +176 -60
- package/src/components/Form/FormField.tsx +107 -38
- package/src/components/Form/FormFieldComponent.tsx +77 -20
- package/src/components/Form/FormFieldSet.tsx +128 -78
- package/src/components/Form/FormTooltipsContext.ts +25 -0
- package/src/components/Form/Layout/FormLayout.stories.test.tsx +51 -0
- package/src/components/Form/Layout/FormLayout.stories.tsx +422 -0
- package/src/components/Form/Layout/FormLayout.test.ts +59 -0
- package/src/components/Form/Layout/FormLayout.tsx +251 -0
- package/src/components/Form/Layout/annotation.ts +38 -0
- package/src/components/Form/Layout/index.ts +7 -0
- package/src/components/Form/Layout/parser.test.ts +120 -0
- package/src/components/Form/Layout/parser.ts +167 -0
- package/src/components/Form/fields/ArrayField.tsx +64 -35
- package/src/components/Form/fields/DateField.tsx +101 -0
- package/src/components/Form/fields/GeoPointField.tsx +12 -8
- package/src/components/Form/fields/InlineRefField.tsx +146 -0
- package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
- package/src/components/Form/fields/MarkdownField.tsx +135 -45
- package/src/components/Form/fields/RefField.tsx +83 -42
- package/src/components/Form/fields/SelectField.tsx +17 -5
- package/src/components/Form/fields/SelectOptionField.stories.tsx +8 -6
- package/src/components/Form/fields/SelectOptionField.tsx +14 -13
- package/src/components/Form/fields/TextAreaField.tsx +1 -1
- package/src/components/Form/fields/TextField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +3 -2
- package/src/components/Form/fields/index.ts +2 -0
- package/src/components/Form/index.ts +3 -0
- package/src/components/Form/meta-tags.test.ts +47 -0
- package/src/components/Form/meta-tags.ts +33 -0
- package/src/components/ObjectForm/ObjectForm.tsx +109 -0
- package/src/components/ObjectForm/index.ts +5 -0
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +13 -11
- package/src/components/ObjectPicker/ObjectPicker.tsx +93 -66
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +350 -0
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +111 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +144 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/ObjectTree/ObjectTree.stories.tsx +134 -0
- package/src/components/ObjectTree/ObjectTree.tsx +190 -0
- package/src/components/ObjectTree/index.ts +5 -0
- package/src/components/Settings/AUDIT.md +51 -0
- package/src/components/Settings/Settings.stories.tsx +69 -21
- package/src/components/Settings/Settings.tsx +32 -181
- package/src/components/Settings/SettingsFieldSet.tsx +257 -0
- package/src/components/Settings/SettingsItem.tsx +58 -0
- package/src/components/Settings/SettingsSelectField.tsx +59 -0
- package/src/components/Settings/index.ts +2 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +45 -51
- package/src/components/ViewEditor/ViewEditor.test.tsx +11 -9
- package/src/components/ViewEditor/ViewEditor.tsx +45 -55
- package/src/components/index.ts +3 -0
- package/src/components/testing.tsx +19 -11
- package/src/hooks/useKeyHandler.tsx +7 -7
- package/src/index.ts +0 -4
- package/src/translations.ts +67 -63
- package/src/util/field-type.ts +60 -0
- package/src/util/index.ts +1 -0
- package/src/util/properties.test.ts +121 -0
- package/src/util/properties.ts +47 -4
- package/src/util/refs.ts +7 -3
- package/src/vite-env.d.ts +10 -0
|
@@ -6,9 +6,8 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import { DXN, Filter, JsonSchema, Obj, Query, type QueryAST, Tag, Type } from '@dxos/echo';
|
|
10
|
-
import { type
|
|
11
|
-
import { type EchoSchema, Format, type Mutable } from '@dxos/echo/internal';
|
|
9
|
+
import { DXN, EID, Filter, JsonSchema, Obj, Query, type QueryAST, Scope, Tag, Type, type View } from '@dxos/echo';
|
|
10
|
+
import { Format, type Mutable } from '@dxos/echo/internal';
|
|
12
11
|
import { useQuery } from '@dxos/react-client/echo';
|
|
13
12
|
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
14
13
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
@@ -16,31 +15,31 @@ import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
|
16
15
|
import { type ProjectionModel, ViewModel, getTypenameFromQuery } from '@dxos/schema';
|
|
17
16
|
import { Employer, Organization, Person, Pipeline } from '@dxos/types';
|
|
18
17
|
|
|
19
|
-
import { translations } from '
|
|
20
|
-
import { TestLayout, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
18
|
+
import { translations } from '#translations';
|
|
21
19
|
|
|
20
|
+
import { TestLayout, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
22
21
|
import { ViewEditor, type ViewEditorProps } from './ViewEditor';
|
|
23
22
|
|
|
24
23
|
const types = [
|
|
25
24
|
// TODO(burdon): Get label from annotation.
|
|
26
|
-
{ value: Organization.Organization
|
|
27
|
-
{ value: Person.Person
|
|
28
|
-
{ value: Pipeline.Pipeline
|
|
29
|
-
{ value: Employer.Employer
|
|
25
|
+
{ value: Type.getTypename(Organization.Organization), label: 'Organization' },
|
|
26
|
+
{ value: Type.getTypename(Person.Person), label: 'Person' },
|
|
27
|
+
{ value: Type.getTypename(Pipeline.Pipeline), label: 'Project' },
|
|
28
|
+
{ value: Type.getTypename(Employer.Employer), label: 'Employer' },
|
|
30
29
|
];
|
|
31
30
|
|
|
32
31
|
// Type definition for debug objects exposed to tests.
|
|
33
32
|
export type ViewEditorDebugObjects = {
|
|
34
|
-
|
|
33
|
+
type: Type.AnyEntity;
|
|
35
34
|
view: View.View;
|
|
36
35
|
projection: ProjectionModel;
|
|
37
36
|
};
|
|
38
37
|
|
|
39
|
-
type
|
|
38
|
+
type DefaultStoryProps = Pick<ViewEditorProps, 'readonly' | 'mode'>;
|
|
40
39
|
|
|
41
|
-
const DefaultStory = (props:
|
|
40
|
+
const DefaultStory = (props: DefaultStoryProps) => {
|
|
42
41
|
const { space } = useClientStory();
|
|
43
|
-
const [
|
|
42
|
+
const [type, setType] = useState<Type.AnyEntity>();
|
|
44
43
|
const [view, setView] = useState<View.View>();
|
|
45
44
|
const projectionRef = useRef<ProjectionModel>(null);
|
|
46
45
|
|
|
@@ -52,71 +51,66 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
52
51
|
name: Schema.String,
|
|
53
52
|
email: Format.Email,
|
|
54
53
|
salary: Format.Currency(),
|
|
55
|
-
}).pipe(
|
|
56
|
-
Type.object({
|
|
57
|
-
typename: 'com.example.type.test',
|
|
58
|
-
version: '0.1.0',
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
54
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.test', '0.1.0')));
|
|
61
55
|
|
|
62
56
|
const AlternateSchema = Schema.Struct({
|
|
63
57
|
title: Schema.String,
|
|
64
58
|
description: Schema.String,
|
|
65
59
|
completed: Schema.Boolean,
|
|
66
|
-
}).pipe(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const [testSchema] = await space.db.schemaRegistry.register([TestSchema, AlternateSchema]);
|
|
60
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.alternate', '0.1.0')));
|
|
61
|
+
|
|
62
|
+
const testType = await space.db.addType(TestSchema);
|
|
63
|
+
await space.db.addType(AlternateSchema);
|
|
74
64
|
const view = ViewModel.make({
|
|
75
65
|
name: 'Test',
|
|
76
66
|
query: Query.select(Filter.type(TestSchema)),
|
|
77
67
|
jsonSchema: JsonSchema.toJsonSchema(TestSchema),
|
|
78
68
|
});
|
|
79
69
|
|
|
80
|
-
|
|
70
|
+
setType(testType);
|
|
81
71
|
setView(view);
|
|
82
72
|
}
|
|
83
73
|
}, [space]);
|
|
84
74
|
|
|
85
75
|
const updateViewQuery = useCallback(
|
|
86
|
-
async (newQuery: QueryAST.Query, target?:
|
|
87
|
-
if (!
|
|
76
|
+
async (newQuery: QueryAST.Query, target?: EID.EID) => {
|
|
77
|
+
if (!type || !view || !space) {
|
|
88
78
|
return;
|
|
89
79
|
}
|
|
90
80
|
|
|
91
81
|
if (props.mode === 'tag') {
|
|
92
|
-
const queue = target
|
|
93
|
-
const query = queue
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
const queue = target;
|
|
83
|
+
const query = queue
|
|
84
|
+
? Query.fromAst(newQuery).from([
|
|
85
|
+
Scope.feed(`dxn:queue:data:${EID.getSpaceId(queue)}:${EID.getEntityId(queue)}`),
|
|
86
|
+
])
|
|
87
|
+
: Query.fromAst(newQuery);
|
|
88
|
+
Obj.update(view, (view) => {
|
|
89
|
+
view.query.ast = query.ast as Mutable<typeof query.ast>;
|
|
96
90
|
});
|
|
97
91
|
|
|
98
92
|
const typename = getTypenameFromQuery(query.ast);
|
|
99
|
-
const
|
|
93
|
+
const allTypes = space.db.graph.registry.list().filter(Type.isType);
|
|
94
|
+
const newSchema = allTypes.find((t) => Type.getTypename(t) === typename);
|
|
100
95
|
if (!newSchema) {
|
|
101
96
|
return;
|
|
102
97
|
}
|
|
103
98
|
|
|
104
99
|
const newView = ViewModel.make({
|
|
105
100
|
query,
|
|
106
|
-
jsonSchema: newSchema
|
|
101
|
+
jsonSchema: JsonSchema.toJsonSchema(newSchema),
|
|
107
102
|
});
|
|
108
|
-
Obj.
|
|
109
|
-
|
|
103
|
+
Obj.update(view, (view) => {
|
|
104
|
+
view.projection = Obj.getSnapshot(newView).projection as Mutable<typeof view.projection>;
|
|
110
105
|
});
|
|
111
|
-
|
|
106
|
+
setType(() => newSchema);
|
|
112
107
|
} else {
|
|
113
|
-
Obj.
|
|
114
|
-
|
|
108
|
+
Obj.update(view, (view) => {
|
|
109
|
+
view.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
115
110
|
});
|
|
116
|
-
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
117
111
|
}
|
|
118
112
|
},
|
|
119
|
-
[view,
|
|
113
|
+
[view, type],
|
|
120
114
|
);
|
|
121
115
|
|
|
122
116
|
const handleDelete = useCallback(
|
|
@@ -126,22 +120,22 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
126
120
|
|
|
127
121
|
// Expose objects on window for test access.
|
|
128
122
|
useEffect(() => {
|
|
129
|
-
if (typeof window !== 'undefined' &&
|
|
123
|
+
if (typeof window !== 'undefined' && type && view && projectionRef.current) {
|
|
130
124
|
(window as any)[VIEW_EDITOR_DEBUG_SYMBOL] = {
|
|
131
|
-
|
|
125
|
+
type,
|
|
132
126
|
view,
|
|
133
127
|
projection: projectionRef.current,
|
|
134
128
|
} satisfies ViewEditorDebugObjects;
|
|
135
129
|
}
|
|
136
|
-
}, [
|
|
130
|
+
}, [type, view]);
|
|
137
131
|
|
|
138
132
|
// NOTE(ZaymonFC): This looks awkward but it resolves an infinite parsing issue with sb.
|
|
139
133
|
const json = useMemo(
|
|
140
|
-
() => JSON.parse(JSON.stringify({ schema, view, projection: projectionRef.current })),
|
|
141
|
-
[JSON.stringify(
|
|
134
|
+
() => JSON.parse(JSON.stringify({ schema: type, view, projection: projectionRef.current })),
|
|
135
|
+
[JSON.stringify(type), JSON.stringify(view)],
|
|
142
136
|
);
|
|
143
137
|
|
|
144
|
-
if (!
|
|
138
|
+
if (!type || !view) {
|
|
145
139
|
return <div />;
|
|
146
140
|
}
|
|
147
141
|
|
|
@@ -149,9 +143,9 @@ const DefaultStory = (props: StoryProps) => {
|
|
|
149
143
|
<TestLayout json={json}>
|
|
150
144
|
<ViewEditor
|
|
151
145
|
ref={projectionRef}
|
|
152
|
-
|
|
146
|
+
type={type}
|
|
153
147
|
view={view}
|
|
154
|
-
registry={space?.db.
|
|
148
|
+
registry={space?.db.graph.registry}
|
|
155
149
|
mode={props.mode}
|
|
156
150
|
readonly={props.readonly}
|
|
157
151
|
types={types}
|
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { composeStories } from '@storybook/react';
|
|
6
|
-
import { cleanup, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
6
|
+
import { act, cleanup, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
7
7
|
import { afterEach, describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import { View } from '@dxos/echo';
|
|
10
|
-
import {
|
|
9
|
+
import { Type, View } from '@dxos/echo';
|
|
10
|
+
import { isInstanceOf } from '@dxos/echo/internal';
|
|
11
11
|
import { ProjectionModel } from '@dxos/schema';
|
|
12
12
|
|
|
13
13
|
import { VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
14
|
-
|
|
15
14
|
import * as stories from './ViewEditor.stories';
|
|
16
15
|
import { type ViewEditorDebugObjects } from './ViewEditor.stories';
|
|
17
16
|
|
|
@@ -20,7 +19,7 @@ const { Default } = composeStories(stories);
|
|
|
20
19
|
const getViewEditorDebugObjects = (): ViewEditorDebugObjects => {
|
|
21
20
|
const debugObjects = (window as any)[VIEW_EDITOR_DEBUG_SYMBOL] as ViewEditorDebugObjects;
|
|
22
21
|
expect(debugObjects).toBeDefined();
|
|
23
|
-
expect(debugObjects.
|
|
22
|
+
expect(Type.isType(debugObjects.type)).toBe(true);
|
|
24
23
|
expect(isInstanceOf(View.View, debugObjects.view)).toBeTruthy();
|
|
25
24
|
expect(debugObjects.projection).toBeInstanceOf(ProjectionModel);
|
|
26
25
|
return debugObjects;
|
|
@@ -36,7 +35,10 @@ const waitForViewEditor = async () => {
|
|
|
36
35
|
};
|
|
37
36
|
|
|
38
37
|
describe('ViewEditor', () => {
|
|
39
|
-
afterEach(() => {
|
|
38
|
+
afterEach(async () => {
|
|
39
|
+
// Flush pending React scheduler work before teardown to prevent
|
|
40
|
+
// "window is not defined" errors from setImmediate callbacks firing after happy-dom cleanup.
|
|
41
|
+
await act(async () => {});
|
|
40
42
|
cleanup();
|
|
41
43
|
});
|
|
42
44
|
|
|
@@ -69,7 +71,7 @@ describe('ViewEditor', () => {
|
|
|
69
71
|
const debugObjects = getViewEditorDebugObjects();
|
|
70
72
|
|
|
71
73
|
// Check schema contains new_property.
|
|
72
|
-
const schemaProperties = debugObjects.
|
|
74
|
+
const schemaProperties = debugObjects.type.jsonSchema.properties;
|
|
73
75
|
expect(schemaProperties).toBeDefined();
|
|
74
76
|
expect(schemaProperties!.new_property).toBeDefined();
|
|
75
77
|
expect(schemaProperties!.name).toBeUndefined();
|
|
@@ -117,7 +119,7 @@ describe('ViewEditor', () => {
|
|
|
117
119
|
const debugObjects = getViewEditorDebugObjects();
|
|
118
120
|
|
|
119
121
|
// Check schema contains added_property.
|
|
120
|
-
const schemaProperties = debugObjects.
|
|
122
|
+
const schemaProperties = debugObjects.type.jsonSchema.properties;
|
|
121
123
|
expect(schemaProperties).toBeDefined();
|
|
122
124
|
expect(schemaProperties!.added_property).toBeDefined();
|
|
123
125
|
|
|
@@ -161,7 +163,7 @@ describe('ViewEditor', () => {
|
|
|
161
163
|
const debugObjects = getViewEditorDebugObjects();
|
|
162
164
|
|
|
163
165
|
// Check schema no longer contains the name property.
|
|
164
|
-
const schemaProperties = debugObjects.
|
|
166
|
+
const schemaProperties = debugObjects.type.jsonSchema.properties;
|
|
165
167
|
expect(schemaProperties).toBeDefined();
|
|
166
168
|
expect(schemaProperties!.name).toBeUndefined();
|
|
167
169
|
|
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
-
import * as Array from 'effect/Array';
|
|
7
6
|
import * as Match from 'effect/Match';
|
|
8
7
|
import * as Option from 'effect/Option';
|
|
9
8
|
import * as Schema from 'effect/Schema';
|
|
10
9
|
import React, { forwardRef, useCallback, useContext, useImperativeHandle, useMemo, useState } from 'react';
|
|
11
10
|
|
|
12
|
-
import { Entity, Feed, Filter, Format, Obj, Query, QueryAST, Ref, type
|
|
13
|
-
import {
|
|
14
|
-
import { EchoSchema, type JsonProp, isMutable, toJsonSchema } from '@dxos/echo/internal';
|
|
11
|
+
import { EID, Entity, Feed, Filter, Format, Obj, Query, QueryAST, Ref, type Registry, Type, View } from '@dxos/echo';
|
|
12
|
+
import { type JsonProp } from '@dxos/echo/internal';
|
|
15
13
|
import { invariant } from '@dxos/invariant';
|
|
16
14
|
import { useObject, useQuery } from '@dxos/react-client/echo';
|
|
17
15
|
import { IconButton, Input, Message, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
@@ -24,9 +22,10 @@ import {
|
|
|
24
22
|
createEchoChangeCallback,
|
|
25
23
|
getTypenameFromQuery,
|
|
26
24
|
} from '@dxos/schema';
|
|
27
|
-
import { mx, osTranslations
|
|
25
|
+
import { mx, osTranslations } from '@dxos/ui-theme';
|
|
26
|
+
|
|
27
|
+
import { translationKey } from '#translations';
|
|
28
28
|
|
|
29
|
-
import { translationKey } from '../../translations';
|
|
30
29
|
import { FieldEditor } from '../FieldEditor';
|
|
31
30
|
import {
|
|
32
31
|
Form,
|
|
@@ -39,12 +38,12 @@ import {
|
|
|
39
38
|
|
|
40
39
|
export type ViewEditorProps = ThemedClassName<
|
|
41
40
|
{
|
|
42
|
-
|
|
41
|
+
type: Type.AnyEntity;
|
|
43
42
|
view: View.View;
|
|
44
43
|
mode?: 'schema' | 'tag';
|
|
45
|
-
registry?:
|
|
44
|
+
registry?: Registry.Registry;
|
|
46
45
|
showHeading?: boolean;
|
|
47
|
-
onQueryChanged?: (query: QueryAST.Query, target?:
|
|
46
|
+
onQueryChanged?: (query: QueryAST.Query, target?: EID.EID) => void;
|
|
48
47
|
onDelete?: (fieldId: string) => void;
|
|
49
48
|
} & Pick<QueryFormProps, 'types' | 'tags'> &
|
|
50
49
|
Pick<FormRootProps<any>, 'readonly' | 'db'>
|
|
@@ -57,7 +56,7 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
57
56
|
(
|
|
58
57
|
{
|
|
59
58
|
classNames,
|
|
60
|
-
|
|
59
|
+
type,
|
|
61
60
|
view,
|
|
62
61
|
mode = 'schema',
|
|
63
62
|
registry,
|
|
@@ -72,16 +71,15 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
72
71
|
forwardedRef,
|
|
73
72
|
) => {
|
|
74
73
|
const atomRegistry = useContext(RegistryContext);
|
|
75
|
-
const schemaReadonly =
|
|
74
|
+
const schemaReadonly = Type.getDatabase(type) == null;
|
|
76
75
|
const { t } = useTranslation(translationKey);
|
|
77
76
|
|
|
78
77
|
const projectionModel = useMemo(() => {
|
|
79
|
-
|
|
80
|
-
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
78
|
+
const jsonSchema = type.jsonSchema;
|
|
81
79
|
|
|
82
80
|
// Always use createEchoChangeCallback since the view is ECHO-backed.
|
|
83
|
-
// Pass
|
|
84
|
-
const change = createEchoChangeCallback(view,
|
|
81
|
+
// Pass type only when mutable to allow schema mutations.
|
|
82
|
+
const change = createEchoChangeCallback(view, Type.getDatabase(type) != null ? type : undefined);
|
|
85
83
|
|
|
86
84
|
const model = new ProjectionModel({
|
|
87
85
|
registry: atomRegistry,
|
|
@@ -91,7 +89,7 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
91
89
|
});
|
|
92
90
|
|
|
93
91
|
return model;
|
|
94
|
-
}, [atomRegistry,
|
|
92
|
+
}, [atomRegistry, type, view]);
|
|
95
93
|
|
|
96
94
|
useImperativeHandle(forwardedRef, () => projectionModel, [projectionModel]);
|
|
97
95
|
|
|
@@ -100,9 +98,9 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
100
98
|
if (from._tag !== 'scope') {
|
|
101
99
|
return undefined;
|
|
102
100
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Option.map(
|
|
101
|
+
const feedScope = from.scopes.find((s) => s._tag === 'feed');
|
|
102
|
+
return Option.fromNullable(feedScope).pipe(
|
|
103
|
+
Option.map((s) => s.feedUri),
|
|
106
104
|
Option.getOrUndefined,
|
|
107
105
|
);
|
|
108
106
|
}),
|
|
@@ -115,8 +113,8 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
115
113
|
if (!queueTarget) {
|
|
116
114
|
return undefined;
|
|
117
115
|
}
|
|
118
|
-
const feed = feeds.find((feed) => Feed.
|
|
119
|
-
return feed ? Ref.
|
|
116
|
+
const feed = feeds.find((feed) => Feed.getQueueUri(feed)?.toString() === queueTarget);
|
|
117
|
+
return feed ? Ref.fromURI(Entity.getURI(feed)) : undefined;
|
|
120
118
|
}, [queueTarget, feeds]);
|
|
121
119
|
|
|
122
120
|
const viewSchema = useMemo(() => {
|
|
@@ -160,13 +158,13 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
160
158
|
const handleUpdate = useCallback(
|
|
161
159
|
(values: any) => {
|
|
162
160
|
const targetValue = values.target;
|
|
163
|
-
let queueDxn:
|
|
161
|
+
let queueDxn: EID.EID | undefined;
|
|
164
162
|
|
|
165
163
|
if (Ref.isRef(targetValue)) {
|
|
166
|
-
const
|
|
167
|
-
const feed = feeds.find((feed) => Obj.
|
|
164
|
+
const feedUri = targetValue.uri;
|
|
165
|
+
const feed = feeds.find((feed) => Obj.getURI(feed) === feedUri);
|
|
168
166
|
if (feed) {
|
|
169
|
-
queueDxn = Feed.
|
|
167
|
+
queueDxn = Feed.getQueueUri(feed);
|
|
170
168
|
}
|
|
171
169
|
}
|
|
172
170
|
|
|
@@ -189,11 +187,11 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
189
187
|
);
|
|
190
188
|
|
|
191
189
|
return (
|
|
192
|
-
<div
|
|
190
|
+
<div className={mx(classNames)}>
|
|
193
191
|
{/* If readonly is set, then the callout is not needed. */}
|
|
194
192
|
{schemaReadonly && !readonly && (
|
|
195
193
|
<Message.Root valence='info' classNames='my-form-padding'>
|
|
196
|
-
<Message.Title>{t('system
|
|
194
|
+
<Message.Title>{t('system-schema.description')}</Message.Title>
|
|
197
195
|
</Message.Root>
|
|
198
196
|
)}
|
|
199
197
|
|
|
@@ -201,9 +199,9 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
201
199
|
<Form.Root schema={viewSchema} values={viewValues} fieldMap={fieldMap} db={db} onValuesChanged={handleUpdate}>
|
|
202
200
|
<Form.FieldSet />
|
|
203
201
|
|
|
204
|
-
<FormFieldLabel label={t('fields
|
|
202
|
+
<FormFieldLabel label={t('fields.label')} asChild />
|
|
205
203
|
<FieldList
|
|
206
|
-
|
|
204
|
+
type={type}
|
|
207
205
|
view={view}
|
|
208
206
|
registry={registry}
|
|
209
207
|
readonly={readonly}
|
|
@@ -216,23 +214,22 @@ export const ViewEditor = forwardRef<ProjectionModel, ViewEditorProps>(
|
|
|
216
214
|
},
|
|
217
215
|
);
|
|
218
216
|
|
|
219
|
-
type FieldListProps = Pick<ViewEditorProps, '
|
|
217
|
+
type FieldListProps = Pick<ViewEditorProps, 'type' | 'view' | 'registry' | 'readonly' | 'showHeading' | 'onDelete'>;
|
|
220
218
|
|
|
221
|
-
const FieldList = ({
|
|
219
|
+
const FieldList = ({ type, view, registry, readonly, showHeading = false, onDelete }: FieldListProps) => {
|
|
222
220
|
const atomRegistry = useContext(RegistryContext);
|
|
223
|
-
const schemaReadonly =
|
|
221
|
+
const schemaReadonly = Type.getDatabase(type) == null;
|
|
224
222
|
const { t } = useTranslation(translationKey);
|
|
225
223
|
|
|
226
224
|
// Subscribe to view changes for reactivity.
|
|
227
225
|
const [viewSnapshot] = useObject(view);
|
|
228
226
|
|
|
229
227
|
const projectionModel = useMemo(() => {
|
|
230
|
-
|
|
231
|
-
const jsonSchema = schema instanceof EchoSchema ? schema.jsonSchema : toJsonSchema(schema);
|
|
228
|
+
const jsonSchema = type.jsonSchema;
|
|
232
229
|
|
|
233
230
|
// Always use createEchoChangeCallback since the view is ECHO-backed.
|
|
234
|
-
// Pass
|
|
235
|
-
const change = createEchoChangeCallback(view,
|
|
231
|
+
// Pass type only when mutable to allow schema mutations.
|
|
232
|
+
const change = createEchoChangeCallback(view, Type.getDatabase(type) != null ? type : undefined);
|
|
236
233
|
|
|
237
234
|
const model = new ProjectionModel({
|
|
238
235
|
registry: atomRegistry,
|
|
@@ -242,7 +239,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
242
239
|
});
|
|
243
240
|
|
|
244
241
|
return model;
|
|
245
|
-
}, [atomRegistry,
|
|
242
|
+
}, [atomRegistry, type, view]);
|
|
246
243
|
|
|
247
244
|
const [expandedField, setExpandedField] = useState<View.FieldType['id']>();
|
|
248
245
|
|
|
@@ -274,12 +271,12 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
274
271
|
const handleMove = useCallback(
|
|
275
272
|
(fromIndex: number, toIndex: number) => {
|
|
276
273
|
invariant(!readonly);
|
|
277
|
-
Obj.
|
|
274
|
+
Obj.update(view, (view) => {
|
|
278
275
|
// NOTE(ZaymonFC): Using arrayMove here causes a race condition with the kanban model.
|
|
279
|
-
const fields = [...
|
|
276
|
+
const fields = [...view.projection.fields];
|
|
280
277
|
const [moved] = fields.splice(fromIndex, 1);
|
|
281
278
|
fields.splice(toIndex, 0, moved);
|
|
282
|
-
|
|
279
|
+
view.projection.fields = fields;
|
|
283
280
|
});
|
|
284
281
|
},
|
|
285
282
|
[view, readonly],
|
|
@@ -317,7 +314,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
317
314
|
>
|
|
318
315
|
{({ items: fields }) => (
|
|
319
316
|
<>
|
|
320
|
-
{showHeading && <h3 className='text-sm'>{t('field
|
|
317
|
+
{showHeading && <h3 className='text-sm'>{t('field-path.label')}</h3>}
|
|
321
318
|
<div role='list' className='grid grid-cols-[min-content_1fr_min-content_min-content_min-content]'>
|
|
322
319
|
{fields?.map((field) => {
|
|
323
320
|
const hidden = field.visible === false;
|
|
@@ -328,20 +325,13 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
328
325
|
classNames={'grid grid-cols-subgrid col-span-5'}
|
|
329
326
|
aria-expanded={expandedField === field.id}
|
|
330
327
|
>
|
|
331
|
-
<div
|
|
332
|
-
role='none'
|
|
333
|
-
className={mx(
|
|
334
|
-
subtleHover,
|
|
335
|
-
'grid grid-cols-subgrid col-span-5',
|
|
336
|
-
'rounded-xs cursor-pointer min-h-10',
|
|
337
|
-
)}
|
|
338
|
-
>
|
|
328
|
+
<div className='grid grid-cols-subgrid col-span-5 rounded-xs cursor-pointer min-h-10 dx-hover'>
|
|
339
329
|
<List.ItemDragHandle disabled={readonly || schemaReadonly} />
|
|
340
330
|
<List.ItemTitle classNames={hidden && 'text-subdued'} onClick={() => handleToggleField(field)}>
|
|
341
331
|
{field.path}
|
|
342
332
|
</List.ItemTitle>
|
|
343
333
|
<List.ItemIconButton
|
|
344
|
-
label={t(hidden ? 'show
|
|
334
|
+
label={t(hidden ? 'show-field.label' : 'hide-field.label')}
|
|
345
335
|
data-testid={hidden ? 'show-field-button' : 'hide-field-button'}
|
|
346
336
|
icon={hidden ? 'ph--eye-closed--regular' : 'ph--eye--regular'}
|
|
347
337
|
autoHide={false}
|
|
@@ -351,7 +341,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
351
341
|
{!readonly && (
|
|
352
342
|
<>
|
|
353
343
|
<List.ItemDeleteButton
|
|
354
|
-
label={t('delete
|
|
344
|
+
label={t('delete-field.label')}
|
|
355
345
|
autoHide={false}
|
|
356
346
|
disabled={readonly || schemaReadonly || viewSnapshot.projection.fields.length <= 1}
|
|
357
347
|
onClick={() => handleDelete(field.id)}
|
|
@@ -360,7 +350,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
360
350
|
<List.ItemIconButton
|
|
361
351
|
iconOnly
|
|
362
352
|
variant='ghost'
|
|
363
|
-
label={t('toggle
|
|
353
|
+
label={t('toggle-expand.label', { ns: osTranslations })}
|
|
364
354
|
icon={expandedField === field.id ? 'ph--caret-down--regular' : 'ph--caret-right--regular'}
|
|
365
355
|
onClick={() => handleToggleField(field)}
|
|
366
356
|
data-testid='field.toggle'
|
|
@@ -369,7 +359,7 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
369
359
|
)}
|
|
370
360
|
</div>
|
|
371
361
|
{expandedField === field.id && !readonly && (
|
|
372
|
-
<div
|
|
362
|
+
<div className='col-span-full mt-1 mb-1 border border-separator rounded-md'>
|
|
373
363
|
<FieldEditor
|
|
374
364
|
readonly={readonly || schemaReadonly}
|
|
375
365
|
registry={registry}
|
|
@@ -384,10 +374,10 @@ const FieldList = ({ schema, view, registry, readonly, showHeading = false, onDe
|
|
|
384
374
|
})}
|
|
385
375
|
</div>
|
|
386
376
|
{!readonly && !expandedField && (
|
|
387
|
-
<div
|
|
377
|
+
<div className='my-form-padding'>
|
|
388
378
|
<IconButton
|
|
389
379
|
icon='ph--plus--regular'
|
|
390
|
-
label={t('add
|
|
380
|
+
label={t('add-property-button.label')}
|
|
391
381
|
onClick={handleAdd}
|
|
392
382
|
disabled={viewSnapshot.projection.fields.length >= VIEW_FIELD_LIMIT}
|
|
393
383
|
classNames='w-full'
|
package/src/components/index.ts
CHANGED
|
@@ -5,17 +5,24 @@
|
|
|
5
5
|
import React, { type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { composableProps, slottable } from '@dxos/react-ui';
|
|
9
|
+
import { Syntax } from '@dxos/react-ui-syntax-highlighter';
|
|
10
10
|
|
|
11
|
-
type TestLayoutProps =
|
|
11
|
+
type TestLayoutProps = PropsWithChildren<{ json?: any }>;
|
|
12
12
|
|
|
13
|
-
export const TestLayout = ({
|
|
13
|
+
export const TestLayout = ({ children, json }: TestLayoutProps) => {
|
|
14
14
|
return (
|
|
15
|
-
<div className='
|
|
16
|
-
<TestPanel
|
|
17
|
-
<TestPanel
|
|
18
|
-
<
|
|
15
|
+
<div className='dx-container grid grid-cols-[1fr_1fr] p-4 gap-4'>
|
|
16
|
+
<TestPanel>{children}</TestPanel>
|
|
17
|
+
<TestPanel>
|
|
18
|
+
<Syntax.Root data={json}>
|
|
19
|
+
<Syntax.Content>
|
|
20
|
+
<Syntax.Filter />
|
|
21
|
+
<Syntax.Viewport>
|
|
22
|
+
<Syntax.Code testId='debug' classNames='text-sm' />
|
|
23
|
+
</Syntax.Viewport>
|
|
24
|
+
</Syntax.Content>
|
|
25
|
+
</Syntax.Root>
|
|
19
26
|
</TestPanel>
|
|
20
27
|
</div>
|
|
21
28
|
);
|
|
@@ -23,14 +30,15 @@ export const TestLayout = ({ classNames, children, json }: TestLayoutProps) => {
|
|
|
23
30
|
|
|
24
31
|
type TestPanelProps = ThemedClassName<PropsWithChildren>;
|
|
25
32
|
|
|
26
|
-
const TestPanel = ({
|
|
33
|
+
export const TestPanel = slottable<HTMLDivElement, TestPanelProps>(({ children }, forwardedRef) => {
|
|
27
34
|
return (
|
|
28
|
-
<div
|
|
35
|
+
<div {...composableProps({ classNames: 'dx-container bg-card-surface rounded-md' })} ref={forwardedRef}>
|
|
29
36
|
{children}
|
|
30
37
|
</div>
|
|
31
38
|
);
|
|
32
|
-
};
|
|
39
|
+
});
|
|
33
40
|
|
|
34
41
|
// Symbol for accessing debug objects in tests.
|
|
35
42
|
export const VIEW_EDITOR_DEBUG_SYMBOL = Symbol('viewEditorDebug');
|
|
36
43
|
export const FIELD_EDITOR_DEBUG_SYMBOL = Symbol('fieldEditorDebug');
|
|
44
|
+
export const OBJECT_PROPERTIES_DEBUG_SYMBOL = Symbol('objectPropertiesDebug');
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useCallback,
|
|
5
|
+
import { type RefObject, useCallback, useLayoutEffect } from 'react';
|
|
6
6
|
|
|
7
7
|
import { addEventListener } from '@dxos/async';
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ import { type FormHandler } from './useFormHandler';
|
|
|
11
11
|
/**
|
|
12
12
|
* Key handler.
|
|
13
13
|
*/
|
|
14
|
-
export const useKeyHandler = (
|
|
14
|
+
export const useKeyHandler = (elRef: RefObject<HTMLDivElement | null>, form: FormHandler<any>) => {
|
|
15
15
|
const handleKeyDown = useCallback(
|
|
16
16
|
(event: KeyboardEvent) => {
|
|
17
17
|
switch (event.key) {
|
|
@@ -26,12 +26,12 @@ export const useKeyHandler = (formElement: HTMLDivElement | null, form: FormHand
|
|
|
26
26
|
[form.isValid, form.canSave, form.onSave, form.autoSave],
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
const el = elRef.current;
|
|
31
|
+
if (!el) {
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, [formElement, handleKeyDown]);
|
|
35
|
+
return addEventListener(el, 'keydown', handleKeyDown);
|
|
36
|
+
}, [elRef, handleKeyDown]);
|
|
37
37
|
};
|