@dxos/react-ui-form 0.8.4-main.1da679c → 0.8.4-main.21d9917

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 (180) hide show
  1. package/dist/lib/browser/index.mjs +2188 -2119
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +2188 -2119
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/ControlSection/ControlSection.d.ts +2 -2
  8. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
  9. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +14 -10
  10. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +6 -5
  12. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  13. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +16 -9
  14. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/Form/Form-old.stories.d.ts +131 -0
  16. package/dist/types/src/components/Form/Form-old.stories.d.ts.map +1 -0
  17. package/dist/types/src/components/Form/Form.d.ts +81 -26
  18. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  19. package/dist/types/src/components/Form/Form.stories.d.ts +63 -87
  20. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/Form/FormField.d.ts +37 -0
  22. package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
  23. package/dist/types/src/components/Form/FormFieldComponent.d.ts +78 -0
  24. package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
  25. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
  26. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
  27. package/dist/types/src/components/Form/FormFieldSet.d.ts +19 -0
  28. package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
  29. package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
  30. package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
  31. package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
  32. package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
  33. package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
  34. package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
  35. package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
  36. package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
  37. package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
  38. package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
  39. package/dist/types/src/components/Form/fields/RefField.d.ts +14 -0
  40. package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
  41. package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
  42. package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
  43. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
  44. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
  45. package/dist/types/src/components/Form/{custom/SelectOptionsInput.stories.d.ts → fields/SelectOptionField.stories.d.ts} +13 -9
  46. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
  47. package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
  48. package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
  49. package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
  50. package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
  51. package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
  52. package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
  53. package/dist/types/src/components/Form/fields/index.d.ts +12 -0
  54. package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
  55. package/dist/types/src/components/Form/index.d.ts +2 -4
  56. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  57. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +46 -0
  58. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
  59. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +85 -0
  60. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
  61. package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
  62. package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
  63. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +21 -10
  64. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  65. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +17 -13
  66. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/index.d.ts +1 -0
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/components/testing.d.ts +0 -2
  70. package/dist/types/src/components/testing.d.ts.map +1 -1
  71. package/dist/types/src/hooks/index.d.ts +2 -3
  72. package/dist/types/src/hooks/index.d.ts.map +1 -1
  73. package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
  74. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
  75. package/dist/types/src/hooks/useKeyHandler.d.ts +6 -0
  76. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
  77. package/dist/types/src/translations.d.ts +12 -8
  78. package/dist/types/src/translations.d.ts.map +1 -1
  79. package/dist/types/src/util/field.d.ts +3 -3
  80. package/dist/types/src/util/field.d.ts.map +1 -1
  81. package/dist/types/src/util/formatting.d.ts +2 -2
  82. package/dist/types/src/util/formatting.d.ts.map +1 -1
  83. package/dist/types/src/util/index.d.ts +1 -1
  84. package/dist/types/src/util/index.d.ts.map +1 -1
  85. package/dist/types/src/util/properties.d.ts +7 -0
  86. package/dist/types/src/util/properties.d.ts.map +1 -0
  87. package/dist/types/src/util/refs.d.ts +2 -3
  88. package/dist/types/src/util/refs.d.ts.map +1 -1
  89. package/dist/types/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +50 -44
  91. package/src/components/ControlSection/ControlSection.stories.tsx +4 -5
  92. package/src/components/ControlSection/ControlSection.tsx +8 -8
  93. package/src/components/FieldEditor/FieldEditor.stories.tsx +46 -24
  94. package/src/components/FieldEditor/FieldEditor.tsx +77 -77
  95. package/src/components/Form/Form-old.stories.tsx +314 -0
  96. package/src/components/Form/Form.stories.tsx +151 -251
  97. package/src/components/Form/Form.tsx +319 -100
  98. package/src/components/Form/FormField.tsx +286 -0
  99. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  100. package/src/components/Form/FormFieldComponent.tsx +174 -0
  101. package/src/components/Form/FormFieldSet.tsx +125 -0
  102. package/src/components/Form/README.md +3 -0
  103. package/src/components/Form/fields/ArrayField.tsx +151 -0
  104. package/src/components/Form/fields/BooleanField.tsx +22 -0
  105. package/src/components/Form/fields/GeoPointField.tsx +120 -0
  106. package/src/components/Form/fields/MarkdownField.tsx +78 -0
  107. package/src/components/Form/fields/NumberField.tsx +39 -0
  108. package/src/components/Form/fields/RefField.tsx +181 -0
  109. package/src/components/Form/fields/SelectField.tsx +65 -0
  110. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +21 -19
  111. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +22 -16
  112. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  113. package/src/components/Form/fields/TextField.tsx +38 -0
  114. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +15 -8
  115. package/src/components/Form/fields/index.ts +15 -0
  116. package/src/components/Form/index.ts +3 -4
  117. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +214 -0
  118. package/src/components/ObjectPicker/ObjectPicker.tsx +175 -0
  119. package/src/components/ObjectPicker/index.ts +5 -0
  120. package/src/components/ViewEditor/ViewEditor.stories.tsx +112 -68
  121. package/src/components/ViewEditor/ViewEditor.test.tsx +12 -7
  122. package/src/components/ViewEditor/ViewEditor.tsx +283 -184
  123. package/src/components/index.ts +1 -0
  124. package/src/components/testing.tsx +9 -7
  125. package/src/hooks/index.ts +2 -3
  126. package/src/hooks/useFormHandler.ts +356 -0
  127. package/src/hooks/useKeyHandler.tsx +37 -0
  128. package/src/translations.ts +14 -11
  129. package/src/util/field.ts +25 -25
  130. package/src/util/formatting.ts +22 -22
  131. package/src/util/index.ts +1 -1
  132. package/src/util/properties.ts +18 -0
  133. package/src/util/refs.ts +12 -18
  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 -18
  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.map +0 -1
  153. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  154. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  155. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  156. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  157. package/dist/types/src/components/Form/factory.d.ts +0 -8
  158. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  159. package/dist/types/src/hooks/useForm.d.ts +0 -67
  160. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  161. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
  162. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  163. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  164. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  165. package/dist/types/src/util/schema.d.ts +0 -3
  166. package/dist/types/src/util/schema.d.ts.map +0 -1
  167. package/src/components/Form/ArrayField.tsx +0 -124
  168. package/src/components/Form/Defaults.tsx +0 -205
  169. package/src/components/Form/FormActions.tsx +0 -54
  170. package/src/components/Form/FormContent.tsx +0 -302
  171. package/src/components/Form/FormContext.tsx +0 -110
  172. package/src/components/Form/Input.tsx +0 -54
  173. package/src/components/Form/RefField.tsx +0 -299
  174. package/src/components/Form/custom/GeoPointInput.tsx +0 -80
  175. package/src/components/Form/custom/index.ts +0 -7
  176. package/src/components/Form/factory.tsx +0 -31
  177. package/src/hooks/useForm.ts +0 -293
  178. package/src/hooks/useQueryRefOptions.ts +0 -53
  179. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  180. package/src/util/schema.ts +0 -14
@@ -2,301 +2,201 @@
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 { Schema } from 'effect';
6
+ import * as Schema from 'effect/Schema';
9
7
  import React, { useCallback, useState } from 'react';
10
8
 
11
- import { ContactType } from '@dxos/client/testing';
12
- import { type Type } from '@dxos/echo';
13
- import { type BaseObject, Expando, Format, Ref, type TypeAnnotation, getObjectDXN } from '@dxos/echo-schema';
14
- import { live } from '@dxos/live-object';
15
- import { withSurfaceVariantsLayout } from '@dxos/react-ui/testing';
16
- import { Testing } from '@dxos/schema/testing';
17
- import { withLayout, withTheme } from '@dxos/storybook-utils';
9
+ import { Annotation, Format, Obj, Tag, Type } from '@dxos/echo';
10
+ import { type AnyProperties } from '@dxos/echo/internal';
11
+ import { log } from '@dxos/log';
12
+ import { useClient } from '@dxos/react-client';
13
+ import { withClientProvider } from '@dxos/react-client/testing';
14
+ import { Tooltip } from '@dxos/react-ui';
15
+ import { withTheme } from '@dxos/react-ui/testing';
18
16
 
19
17
  import { translations } from '../../translations';
20
- import { TestLayout, TestPanel } from '../testing';
18
+ import { TestLayout } from '../testing';
19
+
20
+ import { type ExcludeId, Form, type FormRootProps, omitId } from './Form';
21
+
22
+ const Organization = Schema.Struct({
23
+ name: Schema.String.pipe(Schema.minLength(1)).annotations({ title: 'Full name' }),
24
+ }).pipe(
25
+ Type.object({
26
+ typename: 'example.com/type/Organization', // TODO(burdon): Change all types to /schema
27
+ version: '0.1.0',
28
+ }),
29
+ );
30
+
31
+ export interface Organization extends Schema.Schema.Type<typeof Organization> {}
32
+
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(Type.Ref(Organization).annotations({ title: 'Employer' })),
50
+ tags: Schema.optional(Schema.Array(Type.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: 'dxos.org/type/Person', // TODO(burdon): Change all types to /schema
69
+ version: '0.1.0',
70
+ }),
71
+ );
21
72
 
22
- import { SelectInput } from './Defaults';
23
- import { Form, type FormProps } from './Form';
73
+ export interface Person extends Schema.Schema.Type<typeof Person> {}
24
74
 
25
- type StoryProps<T extends BaseObject> = {
75
+ type StoryProps<T extends AnyProperties> = {
26
76
  debug?: boolean;
27
- schema: Type.Obj.Any;
28
- } & FormProps<T>;
77
+ schema: Schema.Schema<T>;
78
+ } & FormRootProps<T>;
29
79
 
30
- const DefaultStory = <T extends BaseObject = any>({
80
+ const DefaultStory = <T extends AnyProperties = AnyProperties>({
31
81
  debug,
32
82
  schema,
33
- values: initialValues,
83
+ values: valuesProp,
34
84
  ...props
35
85
  }: StoryProps<T>) => {
36
- const [values, setValues] = useState(initialValues);
37
- const handleSave = useCallback<NonNullable<FormProps<T>['onSave']>>((values) => {
86
+ const [values, setValues] = useState<Partial<T>>(valuesProp ?? {});
87
+ const client = useClient();
88
+ const space = client.spaces.default;
89
+
90
+ const handleSave = useCallback<NonNullable<FormRootProps<T>['onSave']>>((values) => {
91
+ log.info('save', { values, meta });
38
92
  setValues(values);
39
93
  }, []);
40
94
 
41
- if (debug) {
42
- return (
43
- <TestLayout json={{ values, schema: schema.ast }}>
44
- <TestPanel>
45
- <Form<T> schema={schema} values={values} onSave={handleSave} {...props} />
46
- </TestPanel>
47
- </TestLayout>
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
- }
95
+ const handleCancel = useCallback<NonNullable<FormRootProps<T>['onCancel']>>(() => {
96
+ log.info('cancel');
97
+ setValues(valuesProp ?? {});
65
98
  }, []);
66
99
 
67
- return <DefaultStory<T> onQueryRefOptions={onQueryRefOptions} {...props} />;
100
+ return (
101
+ <Tooltip.Provider>
102
+ <TestLayout json={{ values, schema: schema.ast }}>
103
+ <Form.Root
104
+ debug={debug}
105
+ schema={schema}
106
+ values={values}
107
+ db={space.db}
108
+ onSave={handleSave}
109
+ onCancel={handleCancel}
110
+ {...props}
111
+ >
112
+ <Form.Viewport>
113
+ <Form.Content>
114
+ <Form.FieldSet />
115
+ <Form.Actions />
116
+ </Form.Content>
117
+ </Form.Viewport>
118
+ </Form.Root>
119
+ </TestLayout>
120
+ </Tooltip.Provider>
121
+ );
68
122
  };
69
123
 
70
124
  const meta = {
71
125
  title: 'ui/react-ui-form/Form',
72
- component: Form as any,
126
+ component: Form.Root,
73
127
  render: DefaultStory,
74
- decorators: [withLayout({ fullscreen: true }), withTheme],
128
+
129
+ decorators: [
130
+ withTheme,
131
+ withClientProvider({
132
+ createIdentity: true,
133
+ createSpace: true,
134
+ types: [Tag.Tag, Organization, Person],
135
+ onCreateIdentity: ({ client }) => {
136
+ const space = client.spaces.default;
137
+ [
138
+ Obj.make(Organization, { name: 'DXOS' }),
139
+ Obj.make(Organization, { name: 'BlueYard' }),
140
+ Obj.make(Organization, { name: 'Backed' }),
141
+ Obj.make(Organization, { name: 'BCV' }),
142
+ Tag.make({ label: 'Tag 1' }),
143
+ Tag.make({ label: 'Tag 2' }),
144
+ Tag.make({ label: 'Tag 3' }),
145
+ ].map((obj) => space.db.add(obj));
146
+ },
147
+ }),
148
+ ],
75
149
  parameters: {
150
+ layout: 'fullscreen',
76
151
  translations,
77
152
  },
78
- argTypes: {
79
- readonly: {
80
- control: 'boolean',
81
- description: 'Readonly',
82
- },
83
- },
84
153
  } satisfies Meta<StoryProps<any>>;
85
154
 
86
155
  export default meta;
87
156
 
88
- const AddressSchema = Schema.Struct({
89
- street: Schema.optional(Schema.String.annotations({ title: 'Street' })),
90
- city: Schema.optional(Schema.String.annotations({ title: 'City' })),
91
- zip: Schema.optional(Schema.String.pipe(Schema.pattern(/^\d{5}(-\d{4})?$/)).annotations({ title: 'ZIP' })),
92
- location: Schema.optional(Format.GeoPoint.annotations({ title: 'Location' })),
93
- }).annotations({ title: 'Address' });
94
-
95
- const ContactSchema = Schema.Struct({
96
- name: Schema.optional(Schema.String.annotations({ title: 'Name' })),
97
- active: Schema.optional(Schema.Boolean.annotations({ title: 'Active' })),
98
- rank: Schema.optional(Schema.Number.annotations({ title: 'Rank' })),
99
- website: Schema.optional(Format.URL.annotations({ title: 'Website' })),
100
- address: Schema.optional(AddressSchema),
101
- }).pipe(Schema.mutable);
157
+ type Story<T extends AnyProperties> = StoryObj<StoryProps<T>>;
102
158
 
103
- type ContactSchema = Schema.Schema.Type<typeof ContactSchema>;
104
-
105
- type Story = StoryObj<StoryProps<any>>;
106
-
107
- export const Default: Story = {
108
- decorators: [withSurfaceVariantsLayout(), withTheme],
109
- args: {
110
- schema: ContactSchema,
111
- values: {
112
- name: 'DXOS',
113
- active: true,
114
- address: {
115
- zip: '11205',
116
- },
117
- },
118
- readonly: false,
119
- },
159
+ const values: Partial<Person> = {
160
+ name: 'Alice',
161
+ location: [40.7128, -74.006],
162
+ tasks: ['task 1', 'task 2'],
120
163
  };
121
164
 
122
- export const Organization: Story = {
165
+ export const Default: Story<ExcludeId<typeof Person>> = {
123
166
  args: {
124
- debug: true,
125
- schema: Testing.OrganizationSchema,
126
- values: {
127
- name: 'DXOS',
128
- website: 'https://dxos.org',
129
- },
130
- readonly: false,
131
- },
132
- };
133
-
134
- export const OrganizationAutoSave: Story = {
135
- args: {
136
- debug: true,
137
- schema: Testing.OrganizationSchema,
138
- values: {
139
- name: 'DXOS',
140
- website: 'https://dxos.org',
141
- },
167
+ schema: omitId(Person),
168
+ values,
142
169
  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
170
  },
204
171
  };
205
172
 
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>> = {
173
+ export const Readonly: Story<ExcludeId<typeof Person>> = {
218
174
  args: {
219
- debug: true,
220
- schema: ArraysSchema,
221
- readonly: false,
222
- values: {
223
- names: ['Alice', 'Bob'],
224
- addresses: [],
225
- },
175
+ schema: omitId(Person),
176
+ values,
177
+ readonly: true,
226
178
  },
227
179
  };
228
180
 
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>> = {
181
+ export const Static: Story<ExcludeId<typeof Person>> = {
242
182
  args: {
243
- debug: true,
244
- schema: TupleSchema,
245
- readonly: false,
246
- values: {
247
- tuple: [1, 'a', true],
248
- geopoint: [-122.41941, 37.77492],
249
- },
183
+ schema: omitId(Person),
184
+ values,
185
+ layout: 'static',
250
186
  },
251
187
  };
252
188
 
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>> = {
266
- args: {
267
- debug: true,
268
- schema: ColorSchema,
269
- readonly: false,
270
- values: {
271
- color: 'red',
272
- },
273
- },
274
- };
275
-
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
- },
189
+ export const Empty: Story<ExcludeId<typeof Person>> = {
190
+ render: () => (
191
+ <TestLayout>
192
+ <Form.Root>
193
+ <Form.Viewport>
194
+ <Form.Content>
195
+ <Form.FieldSet />
196
+ <Form.Actions />
197
+ </Form.Content>
198
+ </Form.Viewport>
199
+ </Form.Root>
200
+ </TestLayout>
201
+ ),
302
202
  };