@dxos/react-ui-form 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (177) hide show
  1. package/dist/lib/browser/index.mjs +2182 -2231
  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 +2182 -2231
  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 +11 -8
  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 +13 -7
  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 +59 -84
  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} +10 -7
  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 +14 -9
  58. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
  59. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +9 -6
  60. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
  61. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +11 -13
  62. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  63. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +12 -9
  64. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  65. package/dist/types/src/components/testing.d.ts +0 -2
  66. package/dist/types/src/components/testing.d.ts.map +1 -1
  67. package/dist/types/src/hooks/index.d.ts +2 -3
  68. package/dist/types/src/hooks/index.d.ts.map +1 -1
  69. package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
  70. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
  71. package/dist/types/src/hooks/useKeyHandler.d.ts +6 -0
  72. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
  73. package/dist/types/src/translations.d.ts +10 -7
  74. package/dist/types/src/translations.d.ts.map +1 -1
  75. package/dist/types/src/util/echo.d.ts +6 -0
  76. package/dist/types/src/util/echo.d.ts.map +1 -0
  77. package/dist/types/src/util/field.d.ts +3 -3
  78. package/dist/types/src/util/field.d.ts.map +1 -1
  79. package/dist/types/src/util/formatting.d.ts +2 -2
  80. package/dist/types/src/util/formatting.d.ts.map +1 -1
  81. package/dist/types/src/util/index.d.ts +2 -1
  82. package/dist/types/src/util/index.d.ts.map +1 -1
  83. package/dist/types/src/util/properties.d.ts +7 -0
  84. package/dist/types/src/util/properties.d.ts.map +1 -0
  85. package/dist/types/src/util/refs.d.ts +1 -2
  86. package/dist/types/src/util/refs.d.ts.map +1 -1
  87. package/dist/types/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +49 -43
  89. package/src/components/ControlSection/ControlSection.stories.tsx +1 -1
  90. package/src/components/ControlSection/ControlSection.tsx +8 -8
  91. package/src/components/FieldEditor/FieldEditor.stories.tsx +42 -21
  92. package/src/components/FieldEditor/FieldEditor.tsx +73 -76
  93. package/src/components/Form/Form-old.stories.tsx +314 -0
  94. package/src/components/Form/Form.stories.tsx +148 -248
  95. package/src/components/Form/Form.tsx +320 -108
  96. package/src/components/Form/FormField.tsx +286 -0
  97. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  98. package/src/components/Form/FormFieldComponent.tsx +174 -0
  99. package/src/components/Form/FormFieldSet.tsx +125 -0
  100. package/src/components/Form/README.md +3 -0
  101. package/src/components/Form/fields/ArrayField.tsx +151 -0
  102. package/src/components/Form/fields/BooleanField.tsx +22 -0
  103. package/src/components/Form/fields/GeoPointField.tsx +120 -0
  104. package/src/components/Form/fields/MarkdownField.tsx +78 -0
  105. package/src/components/Form/fields/NumberField.tsx +39 -0
  106. package/src/components/Form/fields/RefField.tsx +181 -0
  107. package/src/components/Form/fields/SelectField.tsx +65 -0
  108. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +17 -14
  109. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +21 -15
  110. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  111. package/src/components/Form/fields/TextField.tsx +38 -0
  112. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +15 -8
  113. package/src/components/Form/fields/index.ts +15 -0
  114. package/src/components/Form/index.ts +3 -4
  115. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +20 -13
  116. package/src/components/ObjectPicker/ObjectPicker.tsx +76 -62
  117. package/src/components/ViewEditor/ViewEditor.stories.tsx +42 -40
  118. package/src/components/ViewEditor/ViewEditor.test.tsx +8 -4
  119. package/src/components/ViewEditor/ViewEditor.tsx +233 -172
  120. package/src/components/testing.tsx +9 -7
  121. package/src/hooks/index.ts +2 -3
  122. package/src/hooks/useFormHandler.ts +362 -0
  123. package/src/hooks/useKeyHandler.tsx +37 -0
  124. package/src/translations.ts +12 -10
  125. package/src/util/echo.ts +25 -0
  126. package/src/util/field.ts +25 -25
  127. package/src/util/formatting.ts +22 -22
  128. package/src/util/index.ts +2 -1
  129. package/src/util/properties.ts +18 -0
  130. package/src/util/refs.ts +11 -17
  131. package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
  132. package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
  133. package/dist/types/src/components/Form/Defaults.d.ts +0 -14
  134. package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
  135. package/dist/types/src/components/Form/FormActions.d.ts +0 -9
  136. package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
  137. package/dist/types/src/components/Form/FormContent.d.ts +0 -63
  138. package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
  139. package/dist/types/src/components/Form/FormContext.d.ts +0 -23
  140. package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
  141. package/dist/types/src/components/Form/Input.d.ts +0 -29
  142. package/dist/types/src/components/Form/Input.d.ts.map +0 -1
  143. package/dist/types/src/components/Form/RefField.d.ts +0 -22
  144. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  145. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
  146. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
  147. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
  148. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
  149. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
  150. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  151. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  152. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  153. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  154. package/dist/types/src/components/Form/factory.d.ts +0 -8
  155. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  156. package/dist/types/src/hooks/useForm.d.ts +0 -67
  157. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  158. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -29
  159. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  160. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  161. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  162. package/dist/types/src/util/schema.d.ts +0 -3
  163. package/dist/types/src/util/schema.d.ts.map +0 -1
  164. package/src/components/Form/ArrayField.tsx +0 -125
  165. package/src/components/Form/Defaults.tsx +0 -205
  166. package/src/components/Form/FormActions.tsx +0 -54
  167. package/src/components/Form/FormContent.tsx +0 -322
  168. package/src/components/Form/FormContext.tsx +0 -110
  169. package/src/components/Form/Input.tsx +0 -54
  170. package/src/components/Form/RefField.tsx +0 -283
  171. package/src/components/Form/custom/GeoPointInput.tsx +0 -80
  172. package/src/components/Form/custom/index.ts +0 -7
  173. package/src/components/Form/factory.tsx +0 -31
  174. package/src/hooks/useForm.ts +0 -296
  175. package/src/hooks/useQueryRefOptions.ts +0 -62
  176. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  177. package/src/util/schema.ts +0 -12
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-form",
3
- "version": "0.8.4-main.ae835ea",
3
+ "version": "0.8.4-main.bc674ce",
4
4
  "description": "Data components.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
13
  "type": "module",
@@ -24,58 +28,60 @@
24
28
  "src"
25
29
  ],
26
30
  "dependencies": {
27
- "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
28
- "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3",
29
- "@fluentui/react-tabster": "^9.24.2",
30
- "@preact-signals/safe-react": "^0.9.0",
31
- "@preact/signals-react": "^3.2.0",
31
+ "@atlaskit/pragmatic-drag-and-drop": "1.7.7",
32
+ "@atlaskit/pragmatic-drag-and-drop-hitbox": "1.1.0",
33
+ "@effect-atom/atom-react": "^0.4.6",
34
+ "@fluentui/react-tabster": "9.26.11",
32
35
  "@radix-ui/react-context": "1.1.1",
36
+ "@radix-ui/react-use-controllable-state": "1.1.0",
33
37
  "date-fns": "^3.3.1",
34
38
  "jsonpath": "^1.1.1",
35
- "@dxos/echo": "0.8.4-main.ae835ea",
36
- "@dxos/echo-db": "0.8.4-main.ae835ea",
37
- "@dxos/async": "0.8.4-main.ae835ea",
38
- "@dxos/echo-query": "0.8.4-main.ae835ea",
39
- "@dxos/effect": "0.8.4-main.ae835ea",
40
- "@dxos/invariant": "0.8.4-main.ae835ea",
41
- "@dxos/keys": "0.8.4-main.ae835ea",
42
- "@dxos/lit-ui": "0.8.4-main.ae835ea",
43
- "@dxos/debug": "0.8.4-main.ae835ea",
44
- "@dxos/react-client": "0.8.4-main.ae835ea",
45
- "@dxos/log": "0.8.4-main.ae835ea",
46
- "@dxos/react-ui-components": "0.8.4-main.ae835ea",
47
- "@dxos/react-ui-editor": "0.8.4-main.ae835ea",
48
- "@dxos/live-object": "0.8.4-main.ae835ea",
49
- "@dxos/react-ui-list": "0.8.4-main.ae835ea",
50
- "@dxos/react-ui-stack": "0.8.4-main.ae835ea",
51
- "@dxos/util": "0.8.4-main.ae835ea",
52
- "@dxos/schema": "0.8.4-main.ae835ea",
53
- "@dxos/react-ui-searchlist": "0.8.4-main.ae835ea",
54
- "@dxos/react-ui-types": "0.8.4-main.ae835ea",
55
- "@dxos/react-ui-pickers": "0.8.4-main.ae835ea"
39
+ "tabster": "^8.5.5",
40
+ "@dxos/async": "0.8.4-main.bc674ce",
41
+ "@dxos/debug": "0.8.4-main.bc674ce",
42
+ "@dxos/echo": "0.8.4-main.bc674ce",
43
+ "@dxos/echo-react": "0.8.4-main.bc674ce",
44
+ "@dxos/effect": "0.8.4-main.bc674ce",
45
+ "@dxos/invariant": "0.8.4-main.bc674ce",
46
+ "@dxos/keys": "0.8.4-main.bc674ce",
47
+ "@dxos/echo-query": "0.8.4-main.bc674ce",
48
+ "@dxos/lit-ui": "0.8.4-main.bc674ce",
49
+ "@dxos/log": "0.8.4-main.bc674ce",
50
+ "@dxos/react-client": "0.8.4-main.bc674ce",
51
+ "@dxos/react-ui-components": "0.8.4-main.bc674ce",
52
+ "@dxos/react-ui-editor": "0.8.4-main.bc674ce",
53
+ "@dxos/react-ui-mosaic": "0.8.4-main.bc674ce",
54
+ "@dxos/react-ui-pickers": "0.8.4-main.bc674ce",
55
+ "@dxos/react-ui-list": "0.8.4-main.bc674ce",
56
+ "@dxos/schema": "0.8.4-main.bc674ce",
57
+ "@dxos/react-ui-searchlist": "0.8.4-main.bc674ce",
58
+ "@dxos/react-ui-stack": "0.8.4-main.bc674ce",
59
+ "@dxos/types": "0.8.4-main.bc674ce",
60
+ "@dxos/ui-types": "0.8.4-main.bc674ce",
61
+ "@dxos/util": "0.8.4-main.bc674ce"
56
62
  },
57
63
  "devDependencies": {
58
64
  "@types/jsonpath": "^0.2.4",
59
- "@types/react": "~19.2.2",
60
- "@types/react-dom": "~19.2.2",
61
- "effect": "3.18.3",
65
+ "@types/react": "~19.2.7",
66
+ "@types/react-dom": "~19.2.3",
67
+ "effect": "3.19.11",
62
68
  "fast-check": "^3.19.0",
63
- "react": "~19.2.0",
64
- "react-dom": "~19.2.0",
69
+ "react": "~19.2.3",
70
+ "react-dom": "~19.2.3",
65
71
  "vite": "7.1.9",
66
- "@dxos/echo-signals": "0.8.4-main.ae835ea",
67
- "@dxos/random": "0.8.4-main.ae835ea",
68
- "@dxos/react-ui": "0.8.4-main.ae835ea",
69
- "@dxos/react-ui-theme": "0.8.4-main.ae835ea",
70
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.ae835ea",
71
- "@dxos/storybook-utils": "0.8.4-main.ae835ea"
72
+ "@dxos/react-client": "0.8.4-main.bc674ce",
73
+ "@dxos/react-ui": "0.8.4-main.bc674ce",
74
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.bc674ce",
75
+ "@dxos/random": "0.8.4-main.bc674ce",
76
+ "@dxos/ui-theme": "0.8.4-main.bc674ce",
77
+ "@dxos/storybook-utils": "0.8.4-main.bc674ce"
72
78
  },
73
79
  "peerDependencies": {
74
- "effect": "^3.13.3",
75
- "react": "^19.0.0",
76
- "react-dom": "^19.0.0",
77
- "@dxos/react-ui": "0.8.4-main.ae835ea",
78
- "@dxos/react-ui-theme": "0.8.4-main.ae835ea"
80
+ "effect": "3.19.11",
81
+ "react": "~19.2.3",
82
+ "react-dom": "~19.2.3",
83
+ "@dxos/ui-theme": "0.8.4-main.bc674ce",
84
+ "@dxos/react-ui": "0.8.4-main.bc674ce"
79
85
  },
80
86
  "publishConfig": {
81
87
  "access": "public"
@@ -15,7 +15,7 @@ const meta = {
15
15
  title: 'ui/react-ui-form/ControlSection',
16
16
  component: ControlSection,
17
17
  render: (args) => (
18
- <ControlPage classNames='w-[40rem]'>
18
+ <ControlPage classNames='is-[40rem]'>
19
19
  <ControlSection {...args} />
20
20
  </ControlPage>
21
21
  ),
@@ -13,20 +13,20 @@ import {
13
13
  toLocalizedString,
14
14
  useTranslation,
15
15
  } from '@dxos/react-ui';
16
- import { StackItem } from '@dxos/react-ui-stack';
17
- import { mx } from '@dxos/react-ui-theme';
16
+ import { Layout } from '@dxos/react-ui-mosaic';
17
+ import { mx } from '@dxos/ui-theme';
18
18
 
19
19
  import { translationKey } from '../../translations';
20
20
 
21
- export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
21
+ export type ControlPageParams = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
22
22
 
23
- export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
23
+ export const ControlPage = ({ children, classNames, ...props }: ControlPageParams) => {
24
24
  return (
25
- <StackItem.Content scrollable classNames='[--control-spacing:var(--dx-trimMd)]'>
26
- <div role='none' className={mx('pli-cardSpacingInline pbe-trimLg', classNames)} {...props}>
25
+ <Layout.Container scrollable classNames='[--control-spacing:var(--dx-trimMd)]'>
26
+ <div role='none' className={mx('pli-cardSpacingInline pbe-trimMd', classNames)} {...props}>
27
27
  {children}
28
28
  </div>
29
- </StackItem.Content>
29
+ </Layout.Container>
30
30
  );
31
31
  };
32
32
 
@@ -48,7 +48,7 @@ export const ControlSectionHeading = ({ title, description }: Omit<ControlSectio
48
48
  const { t } = useTranslation(translationKey);
49
49
  return (
50
50
  <>
51
- <h2 className='pli-trimMd container-max-width text-xl mbs-trimLg mbe-trimMd'>{toLocalizedString(title, t)}</h2>
51
+ <h2 className='pli-trimMd container-max-width text-xl mbs-trimMd mbe-trimMd'>{toLocalizedString(title, t)}</h2>
52
52
  {description && (
53
53
  <p className='pli-trimMd mlb-trimMd container-max-width text-description'>
54
54
  {toLocalizedString(description, t)}
@@ -5,14 +5,15 @@
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import React, { useEffect, useMemo } from 'react';
7
7
 
8
+ import { Filter, Query } from '@dxos/echo';
8
9
  import { createEchoSchema } from '@dxos/echo/testing';
9
10
  import { log } from '@dxos/log';
10
11
  import { withTheme } from '@dxos/react-ui/testing';
11
- import { ProjectionModel } from '@dxos/schema';
12
- import { TestSchema, testView } from '@dxos/schema/testing';
12
+ import { ProjectionModel, View, createEchoChangeCallback } from '@dxos/schema';
13
+ import { Example } from '@dxos/schema/testing';
13
14
 
14
15
  import { translations } from '../../translations';
15
- import { FIELD_EDITOR_DEBUG_SYMBOL, TestLayout, TestPanel } from '../testing';
16
+ import { FIELD_EDITOR_DEBUG_SYMBOL, TestLayout } from '../testing';
16
17
 
17
18
  import { FieldEditor, type FieldEditorProps } from './FieldEditor';
18
19
 
@@ -22,34 +23,57 @@ export type FieldEditorDebugObjects = {
22
23
  projection: ProjectionModel;
23
24
  };
24
25
 
25
- const DefaultStory = (props: FieldEditorProps) => {
26
+ // TODO(wittjosiah): ECHO objects don't work when passed via Storybook args.
27
+ const useTestProjection = () => {
28
+ return useMemo(() => {
29
+ const schema = createEchoSchema(Example);
30
+ const view = View.make({
31
+ name: 'Test',
32
+ query: Query.select(Filter.type(Example)),
33
+ jsonSchema: schema.jsonSchema,
34
+ });
35
+ const projection = new ProjectionModel({
36
+ view,
37
+ baseSchema: schema.jsonSchema,
38
+ change: createEchoChangeCallback(view, schema),
39
+ });
40
+ projection.normalizeView();
41
+ return { view, projection };
42
+ }, []);
43
+ };
44
+
45
+ const DefaultStory = () => {
46
+ const { view, projection } = useTestProjection();
47
+
26
48
  const handleComplete: FieldEditorProps['onSave'] = () => {
27
- log.info('onClose', { props });
49
+ log.info('onClose');
50
+ };
51
+
52
+ const props: FieldEditorProps = {
53
+ projection,
54
+ field: view.projection.fields[0],
55
+ onSave: handleComplete,
28
56
  };
29
57
 
30
58
  // Expose objects on window for test access.
31
59
  useEffect(() => {
32
- props.projection.normalizeView();
33
-
34
60
  if (typeof window !== 'undefined') {
35
61
  (window as any)[FIELD_EDITOR_DEBUG_SYMBOL] = {
36
62
  props,
37
- projection: props.projection,
63
+ projection,
38
64
  } satisfies FieldEditorDebugObjects;
39
65
  }
40
- }, [props, props.projection]);
66
+ }, [props, projection]);
41
67
 
42
68
  // NOTE(ZaymonFC): This looks awkward but it resolves an infinite parsing issue with sb.
43
69
  const json = useMemo(
44
- () => JSON.parse(JSON.stringify({ props, projection: props.projection })),
45
- [JSON.stringify(props), JSON.stringify(props.projection)],
70
+ () => JSON.parse(JSON.stringify({ props, projection })),
71
+ [JSON.stringify(props), JSON.stringify(projection)],
46
72
  );
47
73
 
48
74
  return (
49
75
  <TestLayout json={json}>
50
- <TestPanel>
51
- <FieldEditor {...props} onSave={handleComplete} />
52
- </TestPanel>
76
+ <FieldEditor {...props} />
53
77
  </TestLayout>
54
78
  );
55
79
  };
@@ -62,6 +86,9 @@ const meta = {
62
86
  parameters: {
63
87
  layout: 'fullscreen',
64
88
  translations,
89
+ controls: {
90
+ disabled: true,
91
+ },
65
92
  },
66
93
  } satisfies Meta<typeof DefaultStory>;
67
94
 
@@ -69,10 +96,4 @@ export default meta;
69
96
 
70
97
  type Story = StoryObj<typeof meta>;
71
98
 
72
- export const Default: Story = {
73
- args: {
74
- projection: new ProjectionModel(createEchoSchema(TestSchema).jsonSchema, testView.projection),
75
- field: testView.projection.fields[0],
76
- },
77
- parameters: { controls: { disabled: true } },
78
- };
99
+ export const Default: Story = {};
@@ -4,44 +4,36 @@
4
4
 
5
5
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
6
6
 
7
- import { type EchoSchema, FormatEnum, FormatEnums, formatToType } from '@dxos/echo/internal';
8
- import { type SchemaRegistry } from '@dxos/echo-db';
7
+ import { Obj, type SchemaRegistry } from '@dxos/echo';
8
+ import { type EchoSchema, Format, FormatEnums, formatToType } from '@dxos/echo/internal';
9
+ import { type SchemaProperty } from '@dxos/effect';
9
10
  import { log } from '@dxos/log';
10
11
  import { useAsyncEffect, useTranslation } from '@dxos/react-ui';
11
12
  import {
12
13
  type FieldType,
13
14
  type ProjectionModel,
14
15
  type PropertyType,
15
- type SchemaProperty,
16
16
  formatToAdditionalPropertyAttributes,
17
17
  getFormatSchema,
18
- getSchemaProperties,
19
- sortProperties,
20
18
  } from '@dxos/schema';
21
19
 
22
20
  import { translationKey } from '../../translations';
23
- import { Form, type FormProps, type InputComponent, SelectInput, SelectOptionInput } from '../Form';
21
+ import { getFormProperties } from '../../util';
22
+ import { Form, type FormFieldMap, type FormRootProps, SelectField, SelectOptionField } from '../Form';
24
23
 
25
24
  export type FieldEditorProps = {
26
25
  projection: ProjectionModel;
27
26
  field: FieldType;
28
- registry?: SchemaRegistry;
27
+ registry?: SchemaRegistry.SchemaRegistry;
28
+ view?: Obj.Unknown;
29
29
  onSave: () => void;
30
30
  onCancel?: () => void;
31
- } & Pick<FormProps<any>, 'outerSpacing' | 'readonly'>;
31
+ } & Pick<FormRootProps<any>, 'readonly'>;
32
32
 
33
33
  /**
34
34
  * Displays a Form representing the metadata for a given `Field` and `View`.
35
35
  */
36
- export const FieldEditor = ({
37
- readonly,
38
- projection,
39
- field,
40
- registry,
41
- onSave,
42
- onCancel,
43
- outerSpacing,
44
- }: FieldEditorProps) => {
36
+ export const FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }: FieldEditorProps) => {
45
37
  const { t } = useTranslation(translationKey);
46
38
  const [props, setProps] = useState<PropertyType>(projection.getFieldProjection(field.id).props);
47
39
  useEffect(() => setProps(projection.getFieldProjection(field.id).props), [field, projection]);
@@ -70,11 +62,47 @@ export const FieldEditor = ({
70
62
  // Class constructor SchemaClass cannot be invoked without 'new'.
71
63
  const [{ fieldSchema }, setFieldSchema] = useState({ fieldSchema: getFormatSchema(props?.format) });
72
64
 
73
- const handleValuesChanged = useCallback<NonNullable<FormProps<PropertyType>['onValuesChanged']>>(
65
+ const fieldMap = useMemo<FormFieldMap>(
66
+ () => ({
67
+ ['format' satisfies keyof PropertyType]: (props) => (
68
+ <SelectField
69
+ {...props}
70
+ options={FormatEnums.filter((value) => value !== Format.TypeFormat.None).map((value) => ({
71
+ value,
72
+ label: t(`format ${value}`),
73
+ }))}
74
+ />
75
+ ),
76
+ ['referenceSchema' satisfies keyof PropertyType]: (props) => (
77
+ <SelectField
78
+ {...props}
79
+ options={schemas.map((schema) => ({
80
+ value: schema.typename,
81
+ }))}
82
+ />
83
+ ),
84
+ ['referencePath' satisfies keyof PropertyType]: (props) => (
85
+ <SelectField
86
+ {...props}
87
+ options={
88
+ referenceSchema
89
+ ? getFormProperties(referenceSchema.ast)
90
+ .sort((a, b) => a.name.toString().localeCompare(b.name.toString()))
91
+ .map((p) => ({ value: p.name.toString() }))
92
+ : []
93
+ }
94
+ />
95
+ ),
96
+ ['options' satisfies keyof PropertyType]: (props) => <SelectOptionField {...props} />,
97
+ }),
98
+ [t, schemas, referenceSchema],
99
+ );
100
+
101
+ const propIsNotType = useCallback((props: SchemaProperty[]) => props.filter((prop) => prop.name !== 'type'), []);
102
+
103
+ const handleValuesChanged = useCallback<NonNullable<FormRootProps<PropertyType>['onValuesChanged']>>(
74
104
  (_props) => {
75
- // TODO(burdon): Callback should pass `changed` to indicate which fields have changed.
76
- // TODO(Zaymon): Workout why old and new format values are the same sometimes even when
77
- // selecting novel format values.
105
+ // TODO(Zaymon): Workout why old and new format values are the same sometimes even when selecting novel format values.
78
106
  setFieldSchema((prev) => {
79
107
  const fieldSchema = getFormatSchema(_props.format);
80
108
  if (prev.fieldSchema === fieldSchema) {
@@ -107,9 +135,9 @@ export const FieldEditor = ({
107
135
  [schemas, props.format, props.referenceSchema],
108
136
  );
109
137
 
110
- const handleValidate = useCallback<NonNullable<FormProps<PropertyType>['onValidate']>>(
138
+ const handleValidate = useCallback<NonNullable<FormRootProps<PropertyType>['onValidate']>>(
111
139
  ({ property }) => {
112
- if (property && projection.fields.find((f) => f.path === property && f.path !== field.path)) {
140
+ if (property && projection.getFields().find((f) => f.path === property && f.path !== field.path)) {
113
141
  return [
114
142
  {
115
143
  path: 'property',
@@ -118,84 +146,53 @@ export const FieldEditor = ({
118
146
  ];
119
147
  }
120
148
  },
121
- [projection.fields, field],
149
+ [projection.getFields(), field],
122
150
  );
123
151
 
124
- const handleSave = useCallback<NonNullable<FormProps<PropertyType>['onSave']>>(
152
+ const handleSave = useCallback<NonNullable<FormRootProps<PropertyType>['onSave']>>(
125
153
  (props) => {
126
- projection.setFieldProjection({ field, props });
154
+ if (view) {
155
+ Obj.change(view, () => {
156
+ projection.setFieldProjection({ field, props });
157
+ });
158
+ } else {
159
+ projection.setFieldProjection({ field, props });
160
+ }
127
161
  onSave();
128
162
  },
129
- [projection, field, onSave],
163
+ [projection, field, view, onSave],
130
164
  );
131
165
 
132
- const handleCancel = useCallback<NonNullable<FormProps<PropertyType>['onCancel']>>(() => {
166
+ const handleCancel = useCallback<NonNullable<FormRootProps<PropertyType>['onCancel']>>(() => {
167
+ onSave();
133
168
  // Need to defer to allow form to close.
134
169
  requestAnimationFrame(() => onCancel?.());
135
- onSave();
136
170
  }, [onSave]);
137
171
 
138
- const custom: Partial<Record<string, InputComponent>> = useMemo(
139
- () => ({
140
- ['format' satisfies keyof PropertyType]: (props) => (
141
- <SelectInput
142
- {...props}
143
- options={FormatEnums.filter((value) => value !== FormatEnum.None).map((value) => ({
144
- value,
145
- label: t(`format ${value}`),
146
- }))}
147
- />
148
- ),
149
- ['referenceSchema' satisfies keyof PropertyType]: (props) => (
150
- <SelectInput
151
- {...props}
152
- options={schemas.map((schema) => ({
153
- value: schema.typename,
154
- }))}
155
- />
156
- ),
157
- ['referencePath' satisfies keyof PropertyType]: (props) => (
158
- <SelectInput
159
- {...props}
160
- options={
161
- referenceSchema
162
- ? getSchemaProperties(referenceSchema.ast)
163
- .sort(sortProperties)
164
- .map((p) => ({ value: p.name }))
165
- : []
166
- }
167
- />
168
- ),
169
- ['options' satisfies keyof PropertyType]: (props) => <SelectOptionInput {...props} />,
170
- }),
171
- [t, schemas, referenceSchema],
172
- );
173
-
174
- const propIsNotType = useCallback(
175
- (props: SchemaProperty<PropertyType>[]) => props.filter((p) => p.name !== 'type'),
176
- [],
177
- );
178
-
179
172
  if (!fieldSchema) {
180
173
  log.warn('invalid format', { props });
181
174
  return null;
182
175
  }
183
176
 
184
177
  return (
185
- <Form<PropertyType>
178
+ <Form.Root<PropertyType>
186
179
  key={field.id}
180
+ fieldMap={fieldMap}
187
181
  autoFocus
188
182
  readonly={readonly}
189
- values={props}
190
183
  schema={fieldSchema}
191
- filter={propIsNotType}
184
+ values={props}
185
+ exclude={propIsNotType}
192
186
  sort={['property', 'format']}
193
187
  onValuesChanged={handleValuesChanged}
194
188
  onValidate={handleValidate}
195
189
  onSave={handleSave}
196
190
  onCancel={handleCancel}
197
- Custom={custom}
198
- outerSpacing={outerSpacing}
199
- />
191
+ >
192
+ <Form.Content>
193
+ <Form.FieldSet />
194
+ <Form.Actions />
195
+ </Form.Content>
196
+ </Form.Root>
200
197
  );
201
198
  };