@dxos/react-ui-form 0.8.4-main.70d3990 → 0.8.4-main.74a063c4e0

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