@dxos/react-ui-form 0.8.4-main.3c1ae3b → 0.8.4-main.3eb6e50203
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/index.mjs +1610 -1825
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +1610 -1825
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +3 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form-old.stories.d.ts +1 -42
- package/dist/types/src/components/Form/Form-old.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +9 -6
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +32 -32
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +2 -2
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +3 -3
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +8 -12
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +14 -9
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.d.ts +56 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/{ControlSection/ControlSection.stories.d.ts → Settings/Settings.stories.d.ts} +3 -9
- package/dist/types/src/components/Settings/Settings.stories.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 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -2
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/echo.d.ts +6 -0
- package/dist/types/src/util/echo.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/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +49 -45
- package/src/components/FieldEditor/FieldEditor.stories.tsx +39 -18
- package/src/components/FieldEditor/FieldEditor.tsx +13 -6
- package/src/components/Form/Form-old.stories.tsx +42 -42
- package/src/components/Form/Form.stories.tsx +12 -17
- package/src/components/Form/Form.tsx +52 -27
- package/src/components/Form/FormField.tsx +23 -17
- package/src/components/Form/FormFieldComponent.stories.tsx +1 -1
- package/src/components/Form/FormFieldComponent.tsx +17 -16
- package/src/components/Form/FormFieldSet.tsx +8 -5
- package/src/components/Form/fields/ArrayField.tsx +11 -11
- package/src/components/Form/fields/RefField.tsx +82 -99
- package/src/components/Form/fields/SelectOptionField.stories.tsx +1 -1
- package/src/components/Form/fields/SelectOptionField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +1 -1
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +12 -5
- package/src/components/ObjectPicker/ObjectPicker.tsx +66 -57
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +234 -0
- package/src/components/{ControlSection → Settings}/index.ts +1 -1
- package/src/components/ViewEditor/ViewEditor.stories.tsx +18 -12
- package/src/components/ViewEditor/ViewEditor.test.tsx +1 -5
- package/src/components/ViewEditor/ViewEditor.tsx +77 -44
- package/src/components/index.ts +1 -1
- package/src/components/testing.tsx +3 -5
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useFormHandler.ts +20 -6
- package/src/translations.ts +1 -1
- package/src/util/echo.ts +25 -0
- package/src/util/index.ts +1 -0
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/index.d.ts +0 -2
- package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -30
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryOptions.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryOptions.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
- package/src/components/ControlSection/ControlSection.tsx +0 -153
- package/src/hooks/useQueryRefOptions.ts +0 -70
- package/src/hooks/useRefQueryOptions.ts +0 -37
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-form",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.3eb6e50203",
|
|
4
4
|
"description": "Data components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
13
|
"type": "module",
|
|
@@ -24,60 +28,60 @@
|
|
|
24
28
|
"src"
|
|
25
29
|
],
|
|
26
30
|
"dependencies": {
|
|
27
|
-
"@atlaskit/pragmatic-drag-and-drop": "
|
|
28
|
-
"@atlaskit/pragmatic-drag-and-drop-hitbox": "
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@preact/signals-react": "^3.2.0",
|
|
31
|
+
"@atlaskit/pragmatic-drag-and-drop": "1.7.7",
|
|
32
|
+
"@atlaskit/pragmatic-drag-and-drop-hitbox": "1.1.0",
|
|
33
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
34
|
+
"@fluentui/react-tabster": "9.26.11",
|
|
32
35
|
"@radix-ui/react-context": "1.1.1",
|
|
33
|
-
"@radix-ui/react-use-controllable-state": "
|
|
36
|
+
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
34
37
|
"date-fns": "^3.3.1",
|
|
35
38
|
"jsonpath": "^1.1.1",
|
|
36
|
-
"
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/echo": "0.8.4-main.
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/effect": "0.8.4-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/keys": "0.8.4-main.
|
|
44
|
-
"@dxos/lit-ui": "0.8.4-main.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/react-
|
|
48
|
-
"@dxos/react-ui-
|
|
49
|
-
"@dxos/react-ui-
|
|
50
|
-
"@dxos/react-ui-pickers": "0.8.4-main.
|
|
51
|
-
"@dxos/react-ui-
|
|
52
|
-
"@dxos/react-ui-
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/types": "0.8.4-main.
|
|
56
|
-
"@dxos/util": "0.8.4-main.
|
|
57
|
-
"@dxos/react-ui-
|
|
39
|
+
"tabster": "^8.5.5",
|
|
40
|
+
"@dxos/echo-query": "0.8.4-main.3eb6e50203",
|
|
41
|
+
"@dxos/echo-react": "0.8.4-main.3eb6e50203",
|
|
42
|
+
"@dxos/async": "0.8.4-main.3eb6e50203",
|
|
43
|
+
"@dxos/effect": "0.8.4-main.3eb6e50203",
|
|
44
|
+
"@dxos/invariant": "0.8.4-main.3eb6e50203",
|
|
45
|
+
"@dxos/echo": "0.8.4-main.3eb6e50203",
|
|
46
|
+
"@dxos/keys": "0.8.4-main.3eb6e50203",
|
|
47
|
+
"@dxos/lit-ui": "0.8.4-main.3eb6e50203",
|
|
48
|
+
"@dxos/log": "0.8.4-main.3eb6e50203",
|
|
49
|
+
"@dxos/react-client": "0.8.4-main.3eb6e50203",
|
|
50
|
+
"@dxos/react-ui-editor": "0.8.4-main.3eb6e50203",
|
|
51
|
+
"@dxos/react-ui-list": "0.8.4-main.3eb6e50203",
|
|
52
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.3eb6e50203",
|
|
53
|
+
"@dxos/react-ui-pickers": "0.8.4-main.3eb6e50203",
|
|
54
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.3eb6e50203",
|
|
55
|
+
"@dxos/react-ui-stack": "0.8.4-main.3eb6e50203",
|
|
56
|
+
"@dxos/schema": "0.8.4-main.3eb6e50203",
|
|
57
|
+
"@dxos/types": "0.8.4-main.3eb6e50203",
|
|
58
|
+
"@dxos/ui-types": "0.8.4-main.3eb6e50203",
|
|
59
|
+
"@dxos/util": "0.8.4-main.3eb6e50203",
|
|
60
|
+
"@dxos/react-ui-components": "0.8.4-main.3eb6e50203",
|
|
61
|
+
"@dxos/debug": "0.8.4-main.3eb6e50203"
|
|
58
62
|
},
|
|
59
63
|
"devDependencies": {
|
|
60
64
|
"@types/jsonpath": "^0.2.4",
|
|
61
|
-
"@types/react": "~19.2.
|
|
62
|
-
"@types/react-dom": "~19.2.
|
|
63
|
-
"effect": "3.
|
|
65
|
+
"@types/react": "~19.2.7",
|
|
66
|
+
"@types/react-dom": "~19.2.3",
|
|
67
|
+
"effect": "3.19.16",
|
|
64
68
|
"fast-check": "^3.19.0",
|
|
65
|
-
"react": "~19.2.
|
|
66
|
-
"react-dom": "~19.2.
|
|
69
|
+
"react": "~19.2.3",
|
|
70
|
+
"react-dom": "~19.2.3",
|
|
67
71
|
"vite": "7.1.9",
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/react-ui-
|
|
71
|
-
"@dxos/react-ui
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
72
|
+
"@dxos/random": "0.8.4-main.3eb6e50203",
|
|
73
|
+
"@dxos/react-client": "0.8.4-main.3eb6e50203",
|
|
74
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.3eb6e50203",
|
|
75
|
+
"@dxos/react-ui": "0.8.4-main.3eb6e50203",
|
|
76
|
+
"@dxos/storybook-utils": "0.8.4-main.3eb6e50203",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.3eb6e50203"
|
|
74
78
|
},
|
|
75
79
|
"peerDependencies": {
|
|
76
|
-
"effect": "
|
|
77
|
-
"react": "
|
|
78
|
-
"react-dom": "
|
|
79
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
80
|
-
"@dxos/
|
|
80
|
+
"effect": "3.19.16",
|
|
81
|
+
"react": "~19.2.3",
|
|
82
|
+
"react-dom": "~19.2.3",
|
|
83
|
+
"@dxos/react-ui": "0.8.4-main.3eb6e50203",
|
|
84
|
+
"@dxos/ui-theme": "0.8.4-main.3eb6e50203"
|
|
81
85
|
},
|
|
82
86
|
"publishConfig": {
|
|
83
87
|
"access": "public"
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useEffect, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
+
import { Filter, Query } from '@dxos/echo';
|
|
8
9
|
import { createEchoSchema } from '@dxos/echo/testing';
|
|
9
10
|
import { log } from '@dxos/log';
|
|
10
11
|
import { withTheme } from '@dxos/react-ui/testing';
|
|
11
|
-
import { ProjectionModel } from '@dxos/schema';
|
|
12
|
-
import { Example
|
|
12
|
+
import { ProjectionModel, View, createEchoChangeCallback } from '@dxos/schema';
|
|
13
|
+
import { Example } from '@dxos/schema/testing';
|
|
13
14
|
|
|
14
15
|
import { translations } from '../../translations';
|
|
15
16
|
import { FIELD_EDITOR_DEBUG_SYMBOL, TestLayout } from '../testing';
|
|
@@ -22,32 +23,57 @@ export type FieldEditorDebugObjects = {
|
|
|
22
23
|
projection: ProjectionModel;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
// TODO(wittjosiah): ECHO objects don't work when passed via Storybook args.
|
|
27
|
+
const useTestProjection = () => {
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
const schema = createEchoSchema(Example);
|
|
30
|
+
const view = View.make({
|
|
31
|
+
name: 'Test',
|
|
32
|
+
query: Query.select(Filter.type(Example)),
|
|
33
|
+
jsonSchema: schema.jsonSchema,
|
|
34
|
+
});
|
|
35
|
+
const projection = new ProjectionModel({
|
|
36
|
+
view,
|
|
37
|
+
baseSchema: schema.jsonSchema,
|
|
38
|
+
change: createEchoChangeCallback(view, schema),
|
|
39
|
+
});
|
|
40
|
+
projection.normalizeView();
|
|
41
|
+
return { view, projection };
|
|
42
|
+
}, []);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const DefaultStory = () => {
|
|
46
|
+
const { view, projection } = useTestProjection();
|
|
47
|
+
|
|
26
48
|
const handleComplete: FieldEditorProps['onSave'] = () => {
|
|
27
|
-
log.info('onClose'
|
|
49
|
+
log.info('onClose');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const props: FieldEditorProps = {
|
|
53
|
+
projection,
|
|
54
|
+
field: view.projection.fields[0],
|
|
55
|
+
onSave: handleComplete,
|
|
28
56
|
};
|
|
29
57
|
|
|
30
58
|
// Expose objects on window for test access.
|
|
31
59
|
useEffect(() => {
|
|
32
|
-
props.projection.normalizeView();
|
|
33
|
-
|
|
34
60
|
if (typeof window !== 'undefined') {
|
|
35
61
|
(window as any)[FIELD_EDITOR_DEBUG_SYMBOL] = {
|
|
36
62
|
props,
|
|
37
|
-
projection
|
|
63
|
+
projection,
|
|
38
64
|
} satisfies FieldEditorDebugObjects;
|
|
39
65
|
}
|
|
40
|
-
}, [props,
|
|
66
|
+
}, [props, projection]);
|
|
41
67
|
|
|
42
68
|
// NOTE(ZaymonFC): This looks awkward but it resolves an infinite parsing issue with sb.
|
|
43
69
|
const json = useMemo(
|
|
44
|
-
() => JSON.parse(JSON.stringify({ props, projection
|
|
45
|
-
[JSON.stringify(props), JSON.stringify(
|
|
70
|
+
() => JSON.parse(JSON.stringify({ props, projection })),
|
|
71
|
+
[JSON.stringify(props), JSON.stringify(projection)],
|
|
46
72
|
);
|
|
47
73
|
|
|
48
74
|
return (
|
|
49
75
|
<TestLayout json={json}>
|
|
50
|
-
<FieldEditor {...props}
|
|
76
|
+
<FieldEditor {...props} />
|
|
51
77
|
</TestLayout>
|
|
52
78
|
);
|
|
53
79
|
};
|
|
@@ -56,7 +82,7 @@ const meta = {
|
|
|
56
82
|
title: 'ui/react-ui-form/FieldEditor',
|
|
57
83
|
component: FieldEditor as any,
|
|
58
84
|
render: DefaultStory,
|
|
59
|
-
decorators: [withTheme],
|
|
85
|
+
decorators: [withTheme()],
|
|
60
86
|
parameters: {
|
|
61
87
|
layout: 'fullscreen',
|
|
62
88
|
translations,
|
|
@@ -70,9 +96,4 @@ export default meta;
|
|
|
70
96
|
|
|
71
97
|
type Story = StoryObj<typeof meta>;
|
|
72
98
|
|
|
73
|
-
export const Default: Story = {
|
|
74
|
-
args: {
|
|
75
|
-
projection: new ProjectionModel(createEchoSchema(Example).jsonSchema, testView.projection),
|
|
76
|
-
field: testView.projection.fields[0],
|
|
77
|
-
},
|
|
78
|
-
};
|
|
99
|
+
export const Default: Story = {};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type SchemaRegistry } from '@dxos/echo';
|
|
7
|
+
import { Obj, type SchemaRegistry } from '@dxos/echo';
|
|
8
8
|
import { type EchoSchema, Format, FormatEnums, formatToType } from '@dxos/echo/internal';
|
|
9
9
|
import { type SchemaProperty } from '@dxos/effect';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
@@ -25,6 +25,7 @@ export type FieldEditorProps = {
|
|
|
25
25
|
projection: ProjectionModel;
|
|
26
26
|
field: FieldType;
|
|
27
27
|
registry?: SchemaRegistry.SchemaRegistry;
|
|
28
|
+
view?: Obj.Unknown;
|
|
28
29
|
onSave: () => void;
|
|
29
30
|
onCancel?: () => void;
|
|
30
31
|
} & Pick<FormRootProps<any>, 'readonly'>;
|
|
@@ -32,7 +33,7 @@ export type FieldEditorProps = {
|
|
|
32
33
|
/**
|
|
33
34
|
* Displays a Form representing the metadata for a given `Field` and `View`.
|
|
34
35
|
*/
|
|
35
|
-
export const FieldEditor = ({ readonly, projection, field, registry, onSave, onCancel }: FieldEditorProps) => {
|
|
36
|
+
export const FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }: FieldEditorProps) => {
|
|
36
37
|
const { t } = useTranslation(translationKey);
|
|
37
38
|
const [props, setProps] = useState<PropertyType>(projection.getFieldProjection(field.id).props);
|
|
38
39
|
useEffect(() => setProps(projection.getFieldProjection(field.id).props), [field, projection]);
|
|
@@ -136,7 +137,7 @@ export const FieldEditor = ({ readonly, projection, field, registry, onSave, onC
|
|
|
136
137
|
|
|
137
138
|
const handleValidate = useCallback<NonNullable<FormRootProps<PropertyType>['onValidate']>>(
|
|
138
139
|
({ property }) => {
|
|
139
|
-
if (property && projection.
|
|
140
|
+
if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
|
|
140
141
|
return [
|
|
141
142
|
{
|
|
142
143
|
path: 'property',
|
|
@@ -145,15 +146,21 @@ export const FieldEditor = ({ readonly, projection, field, registry, onSave, onC
|
|
|
145
146
|
];
|
|
146
147
|
}
|
|
147
148
|
},
|
|
148
|
-
[projection.
|
|
149
|
+
[projection.getFields(), field],
|
|
149
150
|
);
|
|
150
151
|
|
|
151
152
|
const handleSave = useCallback<NonNullable<FormRootProps<PropertyType>['onSave']>>(
|
|
152
153
|
(props) => {
|
|
153
|
-
|
|
154
|
+
if (view) {
|
|
155
|
+
Obj.change(view, () => {
|
|
156
|
+
projection.setFieldProjection({ field, props });
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
projection.setFieldProjection({ field, props });
|
|
160
|
+
}
|
|
154
161
|
onSave();
|
|
155
162
|
},
|
|
156
|
-
[projection, field, onSave],
|
|
163
|
+
[projection, field, view, onSave],
|
|
157
164
|
);
|
|
158
165
|
|
|
159
166
|
const handleCancel = useCallback<NonNullable<FormRootProps<PropertyType>['onCancel']>>(() => {
|
|
@@ -6,7 +6,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useCallback, useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import { Format
|
|
9
|
+
import { Format } from '@dxos/echo';
|
|
10
10
|
import { type AnyProperties } from '@dxos/echo/internal';
|
|
11
11
|
import { Tooltip } from '@dxos/react-ui';
|
|
12
12
|
import { withLayoutVariants, withTheme } from '@dxos/react-ui/testing';
|
|
@@ -61,21 +61,21 @@ const DefaultStory = <T extends AnyProperties = any>({
|
|
|
61
61
|
);
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
const RefStory = <T extends AnyProperties = any>(props: StoryProps<T>) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
64
|
+
// const RefStory = <T extends AnyProperties = any>(props: StoryProps<T>) => {
|
|
65
|
+
// const onQueryRefOptions = useCallback<NonNullable<FormRootProps<T>['onQueryRefOptions']>>(({ typename }) => {
|
|
66
|
+
// switch (typename) {
|
|
67
|
+
// case TestSchema.Person.typename:
|
|
68
|
+
// return [
|
|
69
|
+
// { dxn: Obj.getDXN(contact1), label: 'Alice' },
|
|
70
|
+
// { dxn: Obj.getDXN(contact2), label: 'Bob' },
|
|
71
|
+
// ];
|
|
72
|
+
// default:
|
|
73
|
+
// return [];
|
|
74
|
+
// }
|
|
75
|
+
// }, []);
|
|
76
|
+
|
|
77
|
+
// return <DefaultStory<T> onQueryRefOptions={onQueryRefOptions} {...props} />;
|
|
78
|
+
// };
|
|
79
79
|
|
|
80
80
|
const AddressSchema = Schema.Struct({
|
|
81
81
|
street: Schema.optional(Schema.String.annotations({ title: 'Street' })),
|
|
@@ -98,7 +98,7 @@ const meta = {
|
|
|
98
98
|
title: 'ui/react-ui-form/Form-Old',
|
|
99
99
|
component: Form.Root as any,
|
|
100
100
|
render: DefaultStory,
|
|
101
|
-
decorators: [withTheme, withLayoutVariants()],
|
|
101
|
+
decorators: [withTheme(), withLayoutVariants()],
|
|
102
102
|
parameters: {
|
|
103
103
|
layout: 'fullscreen',
|
|
104
104
|
translations,
|
|
@@ -287,28 +287,28 @@ export const Enum: StoryObj<StoryProps<ColorType>> = {
|
|
|
287
287
|
// Refs
|
|
288
288
|
//
|
|
289
289
|
|
|
290
|
-
const RefSchema = Schema.Struct({
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
type RefSchema = Schema.Schema.Type<typeof RefSchema>;
|
|
300
|
-
|
|
301
|
-
const contact1 = Obj.make(TestSchema.Person, { name: 'Alice' });
|
|
302
|
-
const contact2 = Obj.make(TestSchema.Person, { name: 'Bob' });
|
|
303
|
-
|
|
304
|
-
export const Refs: StoryObj<StoryProps<RefSchema>> = {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
};
|
|
290
|
+
// const RefSchema = Schema.Struct({
|
|
291
|
+
// contact: Type.Ref(TestSchema.Person).annotations({ title: 'Contact Reference' }),
|
|
292
|
+
// optionalContact: Schema.optional(Type.Ref(TestSchema.Person).annotations({ title: 'Optional Contact Reference' })),
|
|
293
|
+
// refArray: Schema.optional(Schema.Array(Type.Ref(TestSchema.Person))),
|
|
294
|
+
// unknownExpando: Schema.optional(
|
|
295
|
+
// Type.Ref(TestSchema.Expando).annotations({ title: 'Optional Ref to an Expando (DXN Input)' }),
|
|
296
|
+
// ),
|
|
297
|
+
// });
|
|
298
|
+
|
|
299
|
+
// type RefSchema = Schema.Schema.Type<typeof RefSchema>;
|
|
300
|
+
|
|
301
|
+
// const contact1 = Obj.make(TestSchema.Person, { name: 'Alice' });
|
|
302
|
+
// const contact2 = Obj.make(TestSchema.Person, { name: 'Bob' });
|
|
303
|
+
|
|
304
|
+
// export const Refs: StoryObj<StoryProps<RefSchema>> = {
|
|
305
|
+
// render: RefStory,
|
|
306
|
+
// args: {
|
|
307
|
+
// debug: true,
|
|
308
|
+
// schema: RefSchema,
|
|
309
|
+
// readonly: false,
|
|
310
|
+
// values: {
|
|
311
|
+
// refArray: [Ref.make(contact1), Ref.make(contact2)],
|
|
312
|
+
// },
|
|
313
|
+
// },
|
|
314
|
+
// };
|
|
@@ -6,13 +6,13 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import React, { useCallback, useState } from 'react';
|
|
8
8
|
|
|
9
|
-
import { Annotation,
|
|
9
|
+
import { Annotation, Format, Obj, Tag, Type } from '@dxos/echo';
|
|
10
10
|
import { type AnyProperties } from '@dxos/echo/internal';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { useClient } from '@dxos/react-client';
|
|
13
13
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
14
14
|
import { Tooltip } from '@dxos/react-ui';
|
|
15
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
16
|
|
|
17
17
|
import { translations } from '../../translations';
|
|
18
18
|
import { TestLayout } from '../testing';
|
|
@@ -22,7 +22,7 @@ import { type ExcludeId, Form, type FormRootProps, omitId } from './Form';
|
|
|
22
22
|
const Organization = Schema.Struct({
|
|
23
23
|
name: Schema.String.pipe(Schema.minLength(1)).annotations({ title: 'Full name' }),
|
|
24
24
|
}).pipe(
|
|
25
|
-
Type.
|
|
25
|
+
Type.object({
|
|
26
26
|
typename: 'example.com/type/Organization', // TODO(burdon): Change all types to /schema
|
|
27
27
|
version: '0.1.0',
|
|
28
28
|
}),
|
|
@@ -64,7 +64,7 @@ const Person = Schema.Struct({
|
|
|
64
64
|
}),
|
|
65
65
|
),
|
|
66
66
|
}).pipe(
|
|
67
|
-
Type.
|
|
67
|
+
Type.object({
|
|
68
68
|
typename: 'dxos.org/type/Person', // TODO(burdon): Change all types to /schema
|
|
69
69
|
version: '0.1.0',
|
|
70
70
|
}),
|
|
@@ -80,10 +80,10 @@ type StoryProps<T extends AnyProperties> = {
|
|
|
80
80
|
const DefaultStory = <T extends AnyProperties = AnyProperties>({
|
|
81
81
|
debug,
|
|
82
82
|
schema,
|
|
83
|
-
values:
|
|
83
|
+
values: valuesProp,
|
|
84
84
|
...props
|
|
85
85
|
}: StoryProps<T>) => {
|
|
86
|
-
const [values, setValues] = useState<Partial<T>>(
|
|
86
|
+
const [values, setValues] = useState<Partial<T>>(valuesProp ?? {});
|
|
87
87
|
const client = useClient();
|
|
88
88
|
const space = client.spaces.default;
|
|
89
89
|
|
|
@@ -94,17 +94,9 @@ const DefaultStory = <T extends AnyProperties = AnyProperties>({
|
|
|
94
94
|
|
|
95
95
|
const handleCancel = useCallback<NonNullable<FormRootProps<T>['onCancel']>>(() => {
|
|
96
96
|
log.info('cancel');
|
|
97
|
-
setValues(
|
|
97
|
+
setValues(valuesProp ?? {});
|
|
98
98
|
}, []);
|
|
99
99
|
|
|
100
|
-
const handleQueryRefOptions = useCallback<NonNullable<FormRootProps<T>['onQueryRefOptions']>>(
|
|
101
|
-
async ({ typename }) => {
|
|
102
|
-
const objects = await space.db.query(Filter.typename(typename)).run();
|
|
103
|
-
return objects.map((result: any) => ({ dxn: Obj.getDXN(result), label: Obj.getLabel(result) }));
|
|
104
|
-
},
|
|
105
|
-
[space],
|
|
106
|
-
);
|
|
107
|
-
|
|
108
100
|
return (
|
|
109
101
|
<Tooltip.Provider>
|
|
110
102
|
<TestLayout json={{ values, schema: schema.ast }}>
|
|
@@ -112,9 +104,9 @@ const DefaultStory = <T extends AnyProperties = AnyProperties>({
|
|
|
112
104
|
debug={debug}
|
|
113
105
|
schema={schema}
|
|
114
106
|
values={values}
|
|
107
|
+
db={space.db}
|
|
115
108
|
onSave={handleSave}
|
|
116
109
|
onCancel={handleCancel}
|
|
117
|
-
onQueryRefOptions={handleQueryRefOptions}
|
|
118
110
|
{...props}
|
|
119
111
|
>
|
|
120
112
|
<Form.Viewport>
|
|
@@ -135,7 +127,10 @@ const meta = {
|
|
|
135
127
|
render: DefaultStory,
|
|
136
128
|
|
|
137
129
|
decorators: [
|
|
138
|
-
withTheme,
|
|
130
|
+
withTheme(),
|
|
131
|
+
withLayout({
|
|
132
|
+
layout: 'fullscreen',
|
|
133
|
+
}),
|
|
139
134
|
withClientProvider({
|
|
140
135
|
createIdentity: true,
|
|
141
136
|
createSpace: true,
|