@dxos/react-ui-form 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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/README.md +0 -1
- package/dist/lib/browser/index.mjs +2315 -2116
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +2315 -2116
- 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 +8 -7
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +82 -5
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +84 -25
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +127 -55
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +43 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +77 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts +18 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts +16 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +82 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/index.d.ts +12 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +2 -4
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +54 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +85 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +39 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts +81 -0
- 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 +22 -10
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +84 -8
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +4 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -3
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts +6 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +63 -54
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts +3 -3
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts +2 -2
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +7 -0
- package/dist/types/src/util/properties.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +3 -3
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +52 -43
- package/src/components/FieldEditor/FieldEditor.stories.tsx +51 -32
- package/src/components/FieldEditor/FieldEditor.test.tsx +3 -2
- package/src/components/FieldEditor/FieldEditor.tsx +87 -83
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +154 -219
- package/src/components/Form/Form.tsx +314 -97
- package/src/components/Form/FormField.tsx +305 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +171 -0
- package/src/components/Form/FormFieldSet.tsx +129 -0
- package/src/components/Form/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +154 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/GeoPointField.tsx +120 -0
- package/src/components/Form/fields/MarkdownField.tsx +78 -0
- package/src/components/Form/fields/NumberField.tsx +39 -0
- package/src/components/Form/fields/RefField.tsx +199 -0
- package/src/components/Form/fields/SelectField.tsx +65 -0
- package/src/components/Form/fields/SelectOptionField.stories.tsx +64 -0
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +49 -45
- package/src/components/Form/fields/TextAreaField.tsx +38 -0
- package/src/components/Form/fields/TextField.tsx +38 -0
- package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +17 -10
- package/src/components/Form/fields/index.ts +15 -0
- package/src/components/Form/index.ts +3 -4
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +210 -0
- package/src/components/ObjectPicker/ObjectPicker.tsx +186 -0
- package/src/components/{ControlSection → ObjectPicker}/index.ts +1 -1
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +129 -0
- package/src/components/Settings/index.ts +5 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +141 -63
- package/src/components/ViewEditor/ViewEditor.test.tsx +17 -18
- package/src/components/ViewEditor/ViewEditor.tsx +353 -203
- package/src/components/index.ts +2 -3
- package/src/components/testing.tsx +33 -13
- package/src/hooks/index.ts +2 -3
- package/src/hooks/useFormHandler.ts +380 -0
- package/src/hooks/useKeyHandler.tsx +37 -0
- package/src/translations.ts +66 -58
- package/src/util/field.ts +33 -43
- package/src/util/formatting.ts +22 -22
- package/src/util/index.ts +1 -1
- package/src/util/properties.ts +18 -0
- package/src/util/refs.ts +17 -19
- 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 +0 -8
- 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/components/Form/ArrayField.d.ts +0 -16
- package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
- package/dist/types/src/components/Form/Defaults.d.ts +0 -14
- package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormActions.d.ts +0 -9
- package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContent.d.ts +0 -57
- package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContext.d.ts +0 -23
- package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
- package/dist/types/src/components/Form/Input.d.ts +0 -26
- package/dist/types/src/components/Form/Input.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -12
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -7
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/index.d.ts +0 -4
- package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/factory.d.ts +0 -8
- package/dist/types/src/components/Form/factory.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.d.ts +0 -15
- package/dist/types/src/components/deprecated/Form.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +0 -13
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +0 -16
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/index.d.ts +0 -2
- package/dist/types/src/components/deprecated/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useForm.d.ts +0 -67
- package/dist/types/src/hooks/useForm.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/dist/types/src/util/schema.d.ts +0 -3
- package/dist/types/src/util/schema.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -41
- package/src/components/ControlSection/ControlSection.tsx +0 -139
- package/src/components/Form/ArrayField.tsx +0 -124
- package/src/components/Form/Defaults.tsx +0 -203
- package/src/components/Form/FormActions.tsx +0 -53
- package/src/components/Form/FormContent.tsx +0 -240
- package/src/components/Form/FormContext.tsx +0 -110
- package/src/components/Form/Input.tsx +0 -51
- package/src/components/Form/RefField.tsx +0 -213
- package/src/components/Form/custom/GeoPointInput.tsx +0 -72
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +0 -61
- package/src/components/Form/custom/index.ts +0 -7
- package/src/components/Form/factory.tsx +0 -31
- package/src/components/deprecated/Form.stories.tsx +0 -62
- package/src/components/deprecated/Form.tsx +0 -119
- package/src/components/deprecated/FormInput.tsx +0 -71
- package/src/components/deprecated/index.ts +0 -5
- package/src/hooks/useForm.ts +0 -291
- package/src/hooks/useQueryRefOptions.ts +0 -53
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -14
|
@@ -2,265 +2,200 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
9
7
|
import React, { useCallback, useState } from 'react';
|
|
10
8
|
|
|
11
|
-
import {
|
|
12
|
-
import { type
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
9
|
+
import { Annotation, Format, Obj, Ref, Tag, Type } from '@dxos/echo';
|
|
10
|
+
import { type AnyProperties } from '@dxos/echo/internal';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
13
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
14
|
+
import { Tooltip } from '@dxos/react-ui';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
17
16
|
|
|
18
|
-
import { SelectInput } from './Defaults';
|
|
19
|
-
import { Form, type FormProps } from './Form';
|
|
20
17
|
import { translations } from '../../translations';
|
|
21
|
-
import { TestLayout
|
|
18
|
+
import { TestLayout } from '../testing';
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
street: Schema.optional(Schema.String.annotations({ title: 'Street' })),
|
|
25
|
-
city: Schema.optional(Schema.String.annotations({ title: 'City' })),
|
|
26
|
-
zip: Schema.optional(Schema.String.pipe(Schema.pattern(/^\d{5}(-\d{4})?$/)).annotations({ title: 'ZIP' })),
|
|
27
|
-
location: Schema.optional(Format.GeoPoint.annotations({ title: 'Location' })),
|
|
28
|
-
}).annotations({ title: 'Address' });
|
|
20
|
+
import { type ExcludeId, Form, type FormRootProps, omitId } from './Form';
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
type TestType = Schema.Schema.Type<typeof TestSchema>;
|
|
22
|
+
const Organization = Schema.Struct({
|
|
23
|
+
name: Schema.String.pipe(Schema.minLength(1)).annotations({ title: 'Full name' }),
|
|
24
|
+
}).pipe(
|
|
25
|
+
Type.object({
|
|
26
|
+
typename: 'com.example.type.organization',
|
|
27
|
+
version: '0.1.0',
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
40
30
|
|
|
41
|
-
|
|
31
|
+
export interface Organization extends Schema.Schema.Type<typeof Organization> {}
|
|
42
32
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
const Person = Schema.Struct({
|
|
34
|
+
name: Schema.String.pipe(Schema.minLength(1)).annotations({ title: 'Full name' }),
|
|
35
|
+
ignore: Schema.String.pipe(Annotation.FormInputAnnotation.set(false), Schema.optional),
|
|
36
|
+
active: Schema.optional(Schema.Boolean.annotations({ title: 'Active' })),
|
|
37
|
+
address: Schema.optional(
|
|
38
|
+
Schema.Struct({
|
|
39
|
+
street: Schema.String,
|
|
40
|
+
city: Schema.String,
|
|
41
|
+
// TODO(burdon): Constrain input control.
|
|
42
|
+
state: Schema.String.pipe(Schema.minLength(2), Schema.maxLength(2)).annotations({
|
|
43
|
+
title: 'State',
|
|
44
|
+
description: 'State code',
|
|
45
|
+
}),
|
|
46
|
+
zip: Schema.Number,
|
|
47
|
+
}).annotations({ title: 'Address' }),
|
|
48
|
+
),
|
|
49
|
+
employer: Schema.optional(Ref.Ref(Organization).annotations({ title: 'Employer' })),
|
|
50
|
+
tags: Schema.optional(Schema.Array(Ref.Ref(Tag.Tag)).annotations({ title: 'Tags' })),
|
|
51
|
+
status: Schema.optional(Schema.Literal('active', 'inactive').annotations({ title: 'Status' })),
|
|
52
|
+
notes: Schema.optional(Format.Text.annotations({ title: 'Notes' })),
|
|
53
|
+
location: Schema.optional(Format.GeoPoint.annotations({ title: 'Location' })),
|
|
54
|
+
tasks: Schema.optional(Schema.Array(Schema.String).annotations({ title: 'Tasks' })),
|
|
55
|
+
locations: Schema.optional(Schema.Array(Format.GeoPoint).annotations({ title: 'Locations' })),
|
|
56
|
+
identities: Schema.optional(
|
|
57
|
+
Schema.Array(
|
|
58
|
+
Schema.Struct({
|
|
59
|
+
type: Schema.String.annotations({ title: 'Type' }),
|
|
60
|
+
value: Schema.String.annotations({ title: 'Value' }),
|
|
61
|
+
}).annotations({ title: 'Identities' }),
|
|
62
|
+
).annotations({
|
|
63
|
+
title: 'Identities',
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
}).pipe(
|
|
67
|
+
Type.object({
|
|
68
|
+
typename: 'org.dxos.type.person', // TODO(burdon): Change all types to /schema
|
|
69
|
+
version: '0.1.0',
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export interface Person extends Schema.Schema.Type<typeof Person> {}
|
|
74
|
+
|
|
75
|
+
type DefaultStoryProps<T extends AnyProperties> = {
|
|
76
|
+
debug?: boolean;
|
|
77
|
+
schema: Schema.Schema<T>;
|
|
78
|
+
} & FormRootProps<T>;
|
|
79
|
+
|
|
80
|
+
const DefaultStory = <T extends AnyProperties = AnyProperties>({
|
|
81
|
+
debug,
|
|
82
|
+
schema,
|
|
83
|
+
values: valuesProp,
|
|
84
|
+
...props
|
|
85
|
+
}: DefaultStoryProps<T>) => {
|
|
86
|
+
const [values, setValues] = useState<Partial<T>>(valuesProp ?? {});
|
|
87
|
+
const spaces = useSpaces();
|
|
88
|
+
const space = spaces[0];
|
|
89
|
+
|
|
90
|
+
const handleSave = useCallback<NonNullable<FormRootProps<T>['onSave']>>((values) => {
|
|
91
|
+
log.info('save', { values, meta });
|
|
46
92
|
setValues(values);
|
|
47
93
|
}, []);
|
|
48
94
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const DebugStory = <T extends BaseObject>({ schema, values: initialValues, ...props }: StoryProps<T>) => {
|
|
53
|
-
const [values, setValues] = useState(initialValues);
|
|
54
|
-
const handleSave = useCallback<NonNullable<FormProps<T>['onSave']>>((values) => {
|
|
55
|
-
setValues(values);
|
|
95
|
+
const handleCancel = useCallback<NonNullable<FormRootProps<T>['onCancel']>>(() => {
|
|
96
|
+
log.info('cancel');
|
|
97
|
+
setValues(valuesProp ?? {});
|
|
56
98
|
}, []);
|
|
57
99
|
|
|
100
|
+
if (!space) {
|
|
101
|
+
return <></>;
|
|
102
|
+
}
|
|
103
|
+
|
|
58
104
|
return (
|
|
59
|
-
<
|
|
60
|
-
<
|
|
61
|
-
<Form
|
|
62
|
-
|
|
63
|
-
|
|
105
|
+
<Tooltip.Provider>
|
|
106
|
+
<TestLayout json={{ values, schema: schema.ast }}>
|
|
107
|
+
<Form.Root
|
|
108
|
+
debug={debug}
|
|
109
|
+
schema={schema}
|
|
110
|
+
defaultValues={values}
|
|
111
|
+
db={space.db}
|
|
112
|
+
onSave={handleSave}
|
|
113
|
+
onCancel={handleCancel}
|
|
114
|
+
{...props}
|
|
115
|
+
>
|
|
116
|
+
<Form.Viewport>
|
|
117
|
+
<Form.Content>
|
|
118
|
+
<Form.FieldSet />
|
|
119
|
+
<Form.Actions />
|
|
120
|
+
</Form.Content>
|
|
121
|
+
</Form.Viewport>
|
|
122
|
+
</Form.Root>
|
|
123
|
+
</TestLayout>
|
|
124
|
+
</Tooltip.Provider>
|
|
64
125
|
);
|
|
65
126
|
};
|
|
66
127
|
|
|
67
|
-
const meta
|
|
128
|
+
const meta = {
|
|
68
129
|
title: 'ui/react-ui-form/Form',
|
|
69
|
-
component: Form
|
|
70
|
-
render:
|
|
71
|
-
|
|
130
|
+
component: Form.Root,
|
|
131
|
+
render: DefaultStory,
|
|
132
|
+
|
|
133
|
+
decorators: [
|
|
134
|
+
withTheme(),
|
|
135
|
+
withLayout({ layout: 'fullscreen' }),
|
|
136
|
+
withClientProvider({
|
|
137
|
+
createIdentity: true,
|
|
138
|
+
createSpace: true,
|
|
139
|
+
types: [Tag.Tag, Organization, Person],
|
|
140
|
+
onCreateSpace: ({ space }) => {
|
|
141
|
+
[
|
|
142
|
+
...Array.from({ length: 3 }).map((_, i) => Obj.make(Tag.Tag, { label: `Tag ${i}` })),
|
|
143
|
+
...Array.from({ length: 50 }).map((_, i) => Obj.make(Organization, { name: `Organization ${i}` })),
|
|
144
|
+
].map((obj) => space.db.add(obj));
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
],
|
|
72
148
|
parameters: {
|
|
149
|
+
layout: 'fullscreen',
|
|
73
150
|
translations,
|
|
74
151
|
},
|
|
75
|
-
|
|
76
|
-
readonly: {
|
|
77
|
-
control: 'boolean',
|
|
78
|
-
description: 'Readonly',
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
};
|
|
152
|
+
} satisfies Meta<DefaultStoryProps<any>>;
|
|
82
153
|
|
|
83
154
|
export default meta;
|
|
84
155
|
|
|
85
|
-
type Story<T extends
|
|
86
|
-
|
|
87
|
-
export const Default: Story<TestType> = {
|
|
88
|
-
render: DefaultStory,
|
|
89
|
-
decorators: [withSurfaceVariantsLayout(), withTheme],
|
|
90
|
-
args: {
|
|
91
|
-
schema: TestSchema,
|
|
92
|
-
values: {
|
|
93
|
-
name: 'DXOS',
|
|
94
|
-
active: true,
|
|
95
|
-
address: {
|
|
96
|
-
zip: '11205',
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
readonly: false,
|
|
100
|
-
},
|
|
101
|
-
};
|
|
156
|
+
type Story<T extends AnyProperties> = StoryObj<DefaultStoryProps<T>>;
|
|
102
157
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
name: 'DXOS',
|
|
108
|
-
website: 'https://dxos.org',
|
|
109
|
-
},
|
|
110
|
-
readonly: false,
|
|
111
|
-
},
|
|
158
|
+
const values: Partial<Person> = {
|
|
159
|
+
name: 'Alice',
|
|
160
|
+
location: [40.7128, -74.006],
|
|
161
|
+
tasks: ['task 1', 'task 2'],
|
|
112
162
|
};
|
|
113
163
|
|
|
114
|
-
export const
|
|
164
|
+
export const Default: Story<ExcludeId<typeof Person>> = {
|
|
115
165
|
args: {
|
|
116
|
-
schema:
|
|
117
|
-
values
|
|
118
|
-
name: 'DXOS',
|
|
119
|
-
website: 'https://dxos.org',
|
|
120
|
-
},
|
|
166
|
+
schema: omitId(Person),
|
|
167
|
+
values,
|
|
121
168
|
autoSave: true,
|
|
122
|
-
readonly: false,
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// TODO(burdon): Type issue with employer reference.
|
|
127
|
-
// TODO(burdon): Test table/form with compound values (e.g., address).
|
|
128
|
-
// export const Contact: Story<Testing.ContactSchemaType> = {
|
|
129
|
-
// args: {
|
|
130
|
-
// // Property name is missing in type EncodedReference but required in type
|
|
131
|
-
// schema: Testing.ContactSchema,
|
|
132
|
-
// values: {
|
|
133
|
-
// name: 'Bot',
|
|
134
|
-
// },
|
|
135
|
-
// },
|
|
136
|
-
// };
|
|
137
|
-
|
|
138
|
-
const ShapeSchema = Schema.Struct({
|
|
139
|
-
shape: Schema.optional(
|
|
140
|
-
Schema.Union(
|
|
141
|
-
Schema.Struct({
|
|
142
|
-
type: Schema.Literal('circle').annotations({ title: 'Type' }),
|
|
143
|
-
radius: Schema.optional(Schema.Number.annotations({ title: 'Radius' })),
|
|
144
|
-
}),
|
|
145
|
-
Schema.Struct({
|
|
146
|
-
type: Schema.Literal('square').annotations({ title: 'Type' }),
|
|
147
|
-
size: Schema.optional(Schema.Number.pipe(Schema.nonNegative()).annotations({ title: 'Size' })),
|
|
148
|
-
}),
|
|
149
|
-
).annotations({ title: 'Shape' }),
|
|
150
|
-
),
|
|
151
|
-
}).pipe(Schema.mutable);
|
|
152
|
-
|
|
153
|
-
type ShapeType = Schema.Schema.Type<typeof ShapeSchema>;
|
|
154
|
-
|
|
155
|
-
export const DiscriminatedShape: Story<ShapeType> = {
|
|
156
|
-
args: {
|
|
157
|
-
schema: ShapeSchema,
|
|
158
|
-
readonly: false,
|
|
159
|
-
values: {
|
|
160
|
-
shape: {
|
|
161
|
-
type: 'circle',
|
|
162
|
-
radius: 5,
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
Custom: {
|
|
166
|
-
['shape.type' as const]: (props) => (
|
|
167
|
-
<SelectInput
|
|
168
|
-
{...props}
|
|
169
|
-
options={['circle', 'square'].map((value) => ({
|
|
170
|
-
value,
|
|
171
|
-
label: value,
|
|
172
|
-
}))}
|
|
173
|
-
/>
|
|
174
|
-
),
|
|
175
|
-
},
|
|
176
169
|
},
|
|
177
170
|
};
|
|
178
171
|
|
|
179
|
-
const
|
|
180
|
-
names: Schema.Array(Schema.String.pipe(Schema.nonEmptyString())),
|
|
181
|
-
addresses: Schema.Array(AddressSchema),
|
|
182
|
-
}).pipe(Schema.mutable);
|
|
183
|
-
|
|
184
|
-
type ArraysType = Schema.Schema.Type<typeof ArraysSchema>;
|
|
185
|
-
|
|
186
|
-
export const Arrays: StoryObj<FormProps<ArraysType>> = {
|
|
172
|
+
export const Readonly: Story<ExcludeId<typeof Person>> = {
|
|
187
173
|
args: {
|
|
188
|
-
schema:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
names: ['Alice', 'Bob'],
|
|
192
|
-
addresses: [],
|
|
193
|
-
},
|
|
174
|
+
schema: omitId(Person),
|
|
175
|
+
values,
|
|
176
|
+
readonly: true,
|
|
194
177
|
},
|
|
195
178
|
};
|
|
196
179
|
|
|
197
|
-
const
|
|
198
|
-
color: Schema.Union(Schema.Literal('red'), Schema.Literal('green'), Schema.Literal('blue')).annotations({
|
|
199
|
-
title: 'Color',
|
|
200
|
-
}),
|
|
201
|
-
}).pipe(Schema.mutable);
|
|
202
|
-
|
|
203
|
-
type ColorType = Schema.Schema.Type<typeof ColorSchema>;
|
|
204
|
-
|
|
205
|
-
export const Enum: StoryObj<FormProps<ColorType>> = {
|
|
180
|
+
export const Static: Story<ExcludeId<typeof Person>> = {
|
|
206
181
|
args: {
|
|
207
|
-
schema:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
color: 'red',
|
|
211
|
-
},
|
|
182
|
+
schema: omitId(Person),
|
|
183
|
+
values,
|
|
184
|
+
layout: 'static',
|
|
212
185
|
},
|
|
213
186
|
};
|
|
214
187
|
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const [values, setValues] = useState(initialValues);
|
|
227
|
-
const handleSave = useCallback<NonNullable<FormProps<any>['onSave']>>((values) => {
|
|
228
|
-
setValues(values);
|
|
229
|
-
}, []);
|
|
230
|
-
|
|
231
|
-
const onQueryRefOptions = useCallback((typeInfo: TypeAnnotation) => {
|
|
232
|
-
switch (typeInfo.typename) {
|
|
233
|
-
case ContactType.typename:
|
|
234
|
-
return [
|
|
235
|
-
{ dxn: getObjectDXN(contact1)!, label: 'John Coltraine' },
|
|
236
|
-
{ dxn: getObjectDXN(contact2)!, label: 'Erykah Badu' },
|
|
237
|
-
];
|
|
238
|
-
default:
|
|
239
|
-
return [];
|
|
240
|
-
}
|
|
241
|
-
}, []);
|
|
242
|
-
|
|
243
|
-
return (
|
|
244
|
-
<TestLayout json={{ values, schema: RefSchema.ast.toJSON() }}>
|
|
245
|
-
<TestPanel>
|
|
246
|
-
<Form
|
|
247
|
-
schema={RefSchema}
|
|
248
|
-
values={values}
|
|
249
|
-
readonly={readonly}
|
|
250
|
-
onSave={handleSave}
|
|
251
|
-
onQueryRefOptions={onQueryRefOptions}
|
|
252
|
-
/>
|
|
253
|
-
</TestPanel>
|
|
188
|
+
export const Empty: Story<ExcludeId<typeof Person>> = {
|
|
189
|
+
render: () => (
|
|
190
|
+
<TestLayout>
|
|
191
|
+
<Form.Root>
|
|
192
|
+
<Form.Viewport>
|
|
193
|
+
<Form.Content>
|
|
194
|
+
<Form.FieldSet />
|
|
195
|
+
<Form.Actions />
|
|
196
|
+
</Form.Content>
|
|
197
|
+
</Form.Viewport>
|
|
198
|
+
</Form.Root>
|
|
254
199
|
</TestLayout>
|
|
255
|
-
)
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
export const Refs: StoryObj<FormProps<ContactType>> = {
|
|
259
|
-
render: RefStory,
|
|
260
|
-
args: {
|
|
261
|
-
readonly: false,
|
|
262
|
-
values: {
|
|
263
|
-
refArray: [Ref.make(contact1), Ref.make(contact2)],
|
|
264
|
-
} as any,
|
|
265
|
-
},
|
|
200
|
+
),
|
|
266
201
|
};
|