@dxos/react-ui-form 0.8.4-main.406dc2a → 0.8.4-main.422d1c7879

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