@dxos/react-ui-form 0.8.4-main.406dc2a → 0.8.4-main.4668b7de9b

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 (283) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +0 -1
  3. package/dist/lib/browser/index.mjs +3504 -2302
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/translations.mjs +83 -0
  7. package/dist/lib/browser/translations.mjs.map +7 -0
  8. package/dist/lib/node-esm/index.mjs +3504 -2302
  9. package/dist/lib/node-esm/index.mjs.map +4 -4
  10. package/dist/lib/node-esm/meta.json +1 -1
  11. package/dist/lib/node-esm/translations.mjs +85 -0
  12. package/dist/lib/node-esm/translations.mjs.map +7 -0
  13. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +8 -7
  14. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  15. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +69 -60
  16. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
  17. package/dist/types/src/components/Form/Form.d.ts +135 -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 +175 -138
  20. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/Form/FormField.d.ts +53 -0
  22. package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
  23. package/dist/types/src/components/Form/FormFieldComponent.d.ts +91 -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 +21 -0
  28. package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
  29. package/dist/types/src/components/Form/FormTooltipsContext.d.ts +19 -0
  30. package/dist/types/src/components/Form/FormTooltipsContext.d.ts.map +1 -0
  31. package/dist/types/src/components/Form/Layout/FormLayout.d.ts +50 -0
  32. package/dist/types/src/components/Form/Layout/FormLayout.d.ts.map +1 -0
  33. package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts +119 -0
  34. package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts.map +1 -0
  35. package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts +2 -0
  36. package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts.map +1 -0
  37. package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts +2 -0
  38. package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts.map +1 -0
  39. package/dist/types/src/components/Form/Layout/annotation.d.ts +30 -0
  40. package/dist/types/src/components/Form/Layout/annotation.d.ts.map +1 -0
  41. package/dist/types/src/components/Form/Layout/index.d.ts +4 -0
  42. package/dist/types/src/components/Form/Layout/index.d.ts.map +1 -0
  43. package/dist/types/src/components/Form/Layout/parser.d.ts +31 -0
  44. package/dist/types/src/components/Form/Layout/parser.d.ts.map +1 -0
  45. package/dist/types/src/components/Form/Layout/parser.test.d.ts +2 -0
  46. package/dist/types/src/components/Form/Layout/parser.test.d.ts.map +1 -0
  47. package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
  48. package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
  49. package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
  50. package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
  51. package/dist/types/src/components/Form/fields/DateField.d.ts +4 -0
  52. package/dist/types/src/components/Form/fields/DateField.d.ts.map +1 -0
  53. package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
  54. package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
  55. package/dist/types/src/components/Form/fields/InlineRefField.d.ts +13 -0
  56. package/dist/types/src/components/Form/fields/InlineRefField.d.ts.map +1 -0
  57. package/dist/types/src/components/Form/fields/MarkdownField.d.ts +11 -0
  58. package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
  59. package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +85 -0
  60. package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
  61. package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
  62. package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
  63. package/dist/types/src/components/Form/fields/RefField.d.ts +22 -0
  64. package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
  65. package/dist/types/src/components/Form/fields/SelectField.d.ts +13 -0
  66. package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
  67. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
  68. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
  69. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +85 -0
  70. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
  72. package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
  73. package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
  74. package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
  75. package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
  76. package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
  77. package/dist/types/src/components/Form/fields/index.d.ts +14 -0
  78. package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
  79. package/dist/types/src/components/Form/index.d.ts +5 -4
  80. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  81. package/dist/types/src/components/Form/meta-tags.d.ts +30 -0
  82. package/dist/types/src/components/Form/meta-tags.d.ts.map +1 -0
  83. package/dist/types/src/components/Form/meta-tags.test.d.ts +2 -0
  84. package/dist/types/src/components/Form/meta-tags.test.d.ts.map +1 -0
  85. package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +8 -0
  86. package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
  87. package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
  88. package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
  89. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +39 -12
  90. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
  91. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +65 -59
  92. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
  93. package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
  94. package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
  95. package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +128 -0
  96. package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
  97. package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
  98. package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
  99. package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
  100. package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
  101. package/dist/types/src/components/ObjectTree/ObjectTree.d.ts +9 -0
  102. package/dist/types/src/components/ObjectTree/ObjectTree.d.ts.map +1 -0
  103. package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts +87 -0
  104. package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts.map +1 -0
  105. package/dist/types/src/components/ObjectTree/index.d.ts +2 -0
  106. package/dist/types/src/components/ObjectTree/index.d.ts.map +1 -0
  107. package/dist/types/src/components/Settings/Settings.d.ts +51 -0
  108. package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
  109. package/dist/types/src/components/Settings/Settings.stories.d.ts +85 -0
  110. package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
  111. package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
  112. package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
  113. package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
  114. package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
  115. package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
  116. package/dist/types/src/components/Settings/SettingsSelectField.d.ts.map +1 -0
  117. package/dist/types/src/components/Settings/index.d.ts +4 -0
  118. package/dist/types/src/components/Settings/index.d.ts.map +1 -0
  119. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +16 -20
  120. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  121. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +72 -66
  122. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  123. package/dist/types/src/components/index.d.ts +4 -1
  124. package/dist/types/src/components/index.d.ts.map +1 -1
  125. package/dist/types/src/components/testing.d.ts +13 -6
  126. package/dist/types/src/components/testing.d.ts.map +1 -1
  127. package/dist/types/src/hooks/index.d.ts +2 -3
  128. package/dist/types/src/hooks/index.d.ts.map +1 -1
  129. package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
  130. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
  131. package/dist/types/src/hooks/useKeyHandler.d.ts +7 -0
  132. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
  133. package/dist/types/src/index.d.ts +0 -2
  134. package/dist/types/src/index.d.ts.map +1 -1
  135. package/dist/types/src/translations.d.ts +66 -60
  136. package/dist/types/src/translations.d.ts.map +1 -1
  137. package/dist/types/src/util/field-type.d.ts +19 -0
  138. package/dist/types/src/util/field-type.d.ts.map +1 -0
  139. package/dist/types/src/util/field.d.ts +3 -3
  140. package/dist/types/src/util/field.d.ts.map +1 -1
  141. package/dist/types/src/util/formatting.d.ts +2 -2
  142. package/dist/types/src/util/formatting.d.ts.map +1 -1
  143. package/dist/types/src/util/index.d.ts +2 -1
  144. package/dist/types/src/util/index.d.ts.map +1 -1
  145. package/dist/types/src/util/properties.d.ts +24 -0
  146. package/dist/types/src/util/properties.d.ts.map +1 -0
  147. package/dist/types/src/util/properties.test.d.ts +2 -0
  148. package/dist/types/src/util/properties.test.d.ts.map +1 -0
  149. package/dist/types/src/util/refs.d.ts +2 -2
  150. package/dist/types/src/util/refs.d.ts.map +1 -1
  151. package/dist/types/tsconfig.tsbuildinfo +1 -1
  152. package/package.json +62 -51
  153. package/src/components/FieldEditor/FieldEditor.stories.tsx +44 -25
  154. package/src/components/FieldEditor/FieldEditor.test.tsx +4 -2
  155. package/src/components/FieldEditor/FieldEditor.tsx +88 -86
  156. package/src/components/Form/AUDIT.md +17 -0
  157. package/src/components/Form/Form.stories.tsx +134 -252
  158. package/src/components/Form/Form.tsx +461 -106
  159. package/src/components/Form/FormField.tsx +363 -0
  160. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  161. package/src/components/Form/FormFieldComponent.tsx +229 -0
  162. package/src/components/Form/FormFieldSet.tsx +173 -0
  163. package/src/components/Form/FormTooltipsContext.ts +25 -0
  164. package/src/components/Form/Layout/FormLayout.stories.test.tsx +51 -0
  165. package/src/components/Form/Layout/FormLayout.stories.tsx +422 -0
  166. package/src/components/Form/Layout/FormLayout.test.ts +59 -0
  167. package/src/components/Form/Layout/FormLayout.tsx +251 -0
  168. package/src/components/Form/Layout/annotation.ts +38 -0
  169. package/src/components/Form/Layout/index.ts +7 -0
  170. package/src/components/Form/Layout/parser.test.ts +120 -0
  171. package/src/components/Form/Layout/parser.ts +167 -0
  172. package/src/components/Form/README.md +3 -0
  173. package/src/components/Form/fields/ArrayField.tsx +178 -0
  174. package/src/components/Form/fields/BooleanField.tsx +22 -0
  175. package/src/components/Form/fields/DateField.tsx +101 -0
  176. package/src/components/Form/fields/GeoPointField.tsx +124 -0
  177. package/src/components/Form/fields/InlineRefField.tsx +146 -0
  178. package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
  179. package/src/components/Form/fields/MarkdownField.tsx +168 -0
  180. package/src/components/Form/fields/NumberField.tsx +39 -0
  181. package/src/components/Form/fields/RefField.tsx +235 -0
  182. package/src/components/Form/fields/SelectField.tsx +77 -0
  183. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +23 -18
  184. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +31 -24
  185. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  186. package/src/components/Form/fields/TextField.tsx +38 -0
  187. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +17 -9
  188. package/src/components/Form/fields/index.ts +17 -0
  189. package/src/components/Form/index.ts +6 -4
  190. package/src/components/Form/meta-tags.test.ts +47 -0
  191. package/src/components/Form/meta-tags.ts +33 -0
  192. package/src/components/ObjectForm/ObjectForm.tsx +109 -0
  193. package/src/components/{ControlSection → ObjectForm}/index.ts +1 -1
  194. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +30 -25
  195. package/src/components/ObjectPicker/ObjectPicker.tsx +123 -82
  196. package/src/components/ObjectProperties/ObjectProperties.stories.tsx +350 -0
  197. package/src/components/ObjectProperties/ObjectProperties.test.tsx +111 -0
  198. package/src/components/ObjectProperties/ObjectProperties.tsx +144 -0
  199. package/src/components/ObjectProperties/index.ts +5 -0
  200. package/src/components/ObjectTree/ObjectTree.stories.tsx +134 -0
  201. package/src/components/ObjectTree/ObjectTree.tsx +190 -0
  202. package/src/components/ObjectTree/index.ts +5 -0
  203. package/src/components/Settings/AUDIT.md +51 -0
  204. package/src/components/Settings/Settings.stories.tsx +104 -0
  205. package/src/components/Settings/Settings.tsx +81 -0
  206. package/src/components/Settings/SettingsFieldSet.tsx +257 -0
  207. package/src/components/Settings/SettingsItem.tsx +58 -0
  208. package/src/components/Settings/SettingsSelectField.tsx +59 -0
  209. package/src/components/Settings/index.ts +7 -0
  210. package/src/components/ViewEditor/ViewEditor.stories.tsx +75 -77
  211. package/src/components/ViewEditor/ViewEditor.test.tsx +16 -13
  212. package/src/components/ViewEditor/ViewEditor.tsx +295 -215
  213. package/src/components/index.ts +4 -1
  214. package/src/components/testing.tsx +24 -11
  215. package/src/hooks/index.ts +2 -3
  216. package/src/hooks/useFormHandler.ts +380 -0
  217. package/src/hooks/useKeyHandler.tsx +37 -0
  218. package/src/index.ts +0 -4
  219. package/src/translations.ts +71 -65
  220. package/src/util/field-type.ts +60 -0
  221. package/src/util/field.ts +25 -25
  222. package/src/util/formatting.ts +22 -22
  223. package/src/util/index.ts +2 -1
  224. package/src/util/properties.test.ts +121 -0
  225. package/src/util/properties.ts +61 -0
  226. package/src/util/refs.ts +16 -18
  227. package/src/vite-env.d.ts +10 -0
  228. package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
  229. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
  230. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -84
  231. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
  232. package/dist/types/src/components/ControlSection/index.d.ts +0 -2
  233. package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
  234. package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
  235. package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
  236. package/dist/types/src/components/Form/Defaults.d.ts +0 -14
  237. package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
  238. package/dist/types/src/components/Form/FormActions.d.ts +0 -9
  239. package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
  240. package/dist/types/src/components/Form/FormContent.d.ts +0 -63
  241. package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
  242. package/dist/types/src/components/Form/FormContext.d.ts +0 -23
  243. package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
  244. package/dist/types/src/components/Form/Input.d.ts +0 -29
  245. package/dist/types/src/components/Form/Input.d.ts.map +0 -1
  246. package/dist/types/src/components/Form/RefField.d.ts +0 -22
  247. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  248. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
  249. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
  250. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
  251. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
  252. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -79
  253. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
  254. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  255. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  256. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  257. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  258. package/dist/types/src/components/Form/factory.d.ts +0 -8
  259. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  260. package/dist/types/src/hooks/useForm.d.ts +0 -67
  261. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  262. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -29
  263. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  264. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  265. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  266. package/dist/types/src/util/schema.d.ts +0 -3
  267. package/dist/types/src/util/schema.d.ts.map +0 -1
  268. package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
  269. package/src/components/ControlSection/ControlSection.tsx +0 -153
  270. package/src/components/Form/ArrayField.tsx +0 -125
  271. package/src/components/Form/Defaults.tsx +0 -205
  272. package/src/components/Form/FormActions.tsx +0 -54
  273. package/src/components/Form/FormContent.tsx +0 -322
  274. package/src/components/Form/FormContext.tsx +0 -110
  275. package/src/components/Form/Input.tsx +0 -54
  276. package/src/components/Form/RefField.tsx +0 -283
  277. package/src/components/Form/custom/GeoPointInput.tsx +0 -80
  278. package/src/components/Form/custom/index.ts +0 -7
  279. package/src/components/Form/factory.tsx +0 -31
  280. package/src/hooks/useForm.ts +0 -296
  281. package/src/hooks/useQueryRefOptions.ts +0 -62
  282. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  283. package/src/util/schema.ts +0 -12
@@ -0,0 +1,363 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Match from 'effect/Match';
6
+ import * as Option from 'effect/Option';
7
+ import * as Schema from 'effect/Schema';
8
+ import * as SchemaAST from 'effect/SchemaAST';
9
+ import * as String from 'effect/String';
10
+ import React, { PropsWithChildren, useMemo } from 'react';
11
+
12
+ import { Annotation, Format } from '@dxos/echo';
13
+ import {
14
+ createJsonPath,
15
+ findNode,
16
+ getAnnotation,
17
+ getDiscriminatedType,
18
+ isArrayType,
19
+ isDiscriminatedUnion,
20
+ isLiteralUnion,
21
+ isNestedType,
22
+ } from '@dxos/effect';
23
+ import { IconButton, IconButtonProps, useTranslation } from '@dxos/react-ui';
24
+ import { type ProjectionModel } from '@dxos/schema';
25
+ import { mx } from '@dxos/ui-theme';
26
+
27
+ import { translationKey } from '#translations';
28
+
29
+ import { getRefProps } from '../../util';
30
+ import {
31
+ ArrayField,
32
+ BooleanField,
33
+ DateField,
34
+ GeoPointField,
35
+ InlineRefField,
36
+ MarkdownField,
37
+ NumberField,
38
+ RefField,
39
+ type RefFieldProps,
40
+ SelectField,
41
+ TextAreaField,
42
+ TextField,
43
+ } from './fields';
44
+ import { useFormFieldState } from './Form';
45
+ import {
46
+ type FormFieldComponent,
47
+ type FormFieldComponentProps,
48
+ type FormFieldMap,
49
+ type FormFieldProvider,
50
+ } from './FormFieldComponent';
51
+ import { FormFieldSet } from './FormFieldSet';
52
+
53
+ export type FormFieldProps = {
54
+ /**
55
+ * AST of the property to render.
56
+ */
57
+ type: SchemaAST.AST;
58
+
59
+ /**
60
+ * Name of the property. Used to derive a default label
61
+ * (`title ?? capitalize(name)`) and as the projection lookup key. Pass
62
+ * `null` to suppress the header label entirely -- the form still renders
63
+ * the field/struct, but `FormFieldSet`'s top-level `<FormFieldLabel>` is
64
+ * skipped. Used by `ArrayField` for object-array items, where every item
65
+ * would otherwise repeat the array's parent name.
66
+ */
67
+ name: string | null;
68
+
69
+ /**
70
+ * Path to the current object from the root. Used with nested forms.
71
+ */
72
+ path?: (string | number)[];
73
+
74
+ /**
75
+ * Optional projection for projection-based field management.
76
+ */
77
+ projection?: ProjectionModel;
78
+
79
+ /**
80
+ * Map of custom renderers for specific properties.
81
+ * Prefer fieldProvider for plugin specific input surfaces.
82
+ */
83
+ fieldMap?: FormFieldMap;
84
+
85
+ /**
86
+ * Function to lookup custom renderers for specific properties.
87
+ */
88
+ fieldProvider?: FormFieldProvider;
89
+
90
+ /**
91
+ * Typename of the ref type that the create props apply to.
92
+ * When set, createOptionLabel/createOptionIcon/createInitialValuePath/createFieldMap/onCreate
93
+ * are only passed to ref fields whose typename matches.
94
+ */
95
+ createTypename?: string;
96
+ } & Pick<FormFieldComponentProps, 'autoFocus' | 'readonly' | 'layout'> &
97
+ Pick<
98
+ RefFieldProps,
99
+ | 'createOptionLabel'
100
+ | 'createOptionIcon'
101
+ | 'createInitialValuePath'
102
+ | 'createFieldMap'
103
+ | 'db'
104
+ | 'useType'
105
+ | 'getOptions'
106
+ | 'onCreate'
107
+ >;
108
+
109
+ export const FormField = (props: FormFieldProps) => {
110
+ const {
111
+ type,
112
+ name,
113
+ path,
114
+ projection,
115
+ fieldMap,
116
+ fieldProvider,
117
+ readonly,
118
+ layout,
119
+
120
+ // RefFieldProps
121
+ createTypename,
122
+ createOptionLabel,
123
+ createOptionIcon,
124
+ createInitialValuePath,
125
+ createFieldMap,
126
+ db,
127
+ useType: schemaHook,
128
+ getOptions,
129
+ onCreate,
130
+ } = props;
131
+ const { t } = useTranslation(translationKey);
132
+ const title = getAnnotation<string>(SchemaAST.TitleAnnotationId)(type);
133
+ const description = getAnnotation<string>(SchemaAST.DescriptionAnnotationId)(type);
134
+ const examples = getAnnotation<string[]>(SchemaAST.ExamplesAnnotationId)(type);
135
+
136
+ // `name === null` means "no header" -- collapse to an empty string so
137
+ // downstream consumers keep their `label: string` types, and the falsy
138
+ // value lets `FormFieldSet`'s `label && <FormFieldLabel ...>` guard skip
139
+ // the header.
140
+ const label = useMemo(() => title ?? (name == null ? '' : String.capitalize(name)), [title, name]);
141
+ const placeholder = useMemo(
142
+ () => (examples?.length ? `${t('example.placeholder')}: ${examples[0]}` : (description ?? label)),
143
+ [examples, description, label],
144
+ );
145
+
146
+ const fieldState = useFormFieldState(FormField.displayName, path);
147
+ const jsonPath = createJsonPath(path ?? []);
148
+ const fieldProps: FormFieldComponentProps = {
149
+ type,
150
+ format: Format.FormatAnnotation.getFromAst(type).pipe((annotation) => Option.getOrUndefined(annotation)),
151
+ readonly,
152
+ label,
153
+ jsonPath,
154
+ placeholder,
155
+ layout,
156
+ db,
157
+ ...fieldState,
158
+ };
159
+
160
+ // Omit empty fields entirely in read-only mode -- an empty value has nothing
161
+ // to display, so a labelled row with a blank input is just noise. This
162
+ // mirrors what `FormFieldWrapper` already does for `layout === 'static'`, but
163
+ // covers every field type (including those that bypass the wrapper:
164
+ // RefField, SelectField, MarkdownField, ...). Container fields
165
+ // (`ArrayField`, nested-struct -> `FormFieldSet`) keep their own
166
+ // empty-value checks, but those branches only apply when the value is
167
+ // actually a non-null array/object, so this check doesn't interfere.
168
+ if (readonly && fieldState.getValue() == null) {
169
+ return null;
170
+ }
171
+
172
+ //
173
+ // Custom field.
174
+ //
175
+
176
+ const CustomField = fieldMap?.[jsonPath];
177
+ if (CustomField) {
178
+ return <CustomField {...fieldProps} />;
179
+ }
180
+
181
+ // TODO(burdon): Expensive to create schema each time; pass AST?
182
+ const component = fieldProvider?.({ schema: Schema.make(type), prop: name ?? '', fieldProps });
183
+ if (component) {
184
+ return component;
185
+ }
186
+
187
+ //
188
+ // Array field.
189
+ //
190
+
191
+ if (isArrayType(type)) {
192
+ return <ArrayField fieldProps={fieldState} label={label} {...props} />;
193
+ }
194
+
195
+ //
196
+ // Regular field.
197
+ //
198
+
199
+ const Field = getFormField(fieldProps);
200
+ if (Field) {
201
+ return <Field {...fieldProps} />;
202
+ }
203
+
204
+ //
205
+ // Select field.
206
+ //
207
+
208
+ const options = getSelectOptions(type);
209
+ if (options) {
210
+ // Resolve labels from projection metadata when available.
211
+ const fieldProjections = projection?.getFieldProjections();
212
+ const fieldProjection = fieldProjections?.find((fp) => fp.field.path === name);
213
+ const selectOptions = fieldProjection?.props.options;
214
+
215
+ return (
216
+ <SelectField
217
+ {...fieldProps}
218
+ options={options.map((option) => {
219
+ const selectOption = selectOptions?.find((so) => so.id === globalThis.String(option));
220
+ return {
221
+ value: option,
222
+ label: selectOption?.title ?? option.toString(),
223
+ };
224
+ })}
225
+ />
226
+ );
227
+ }
228
+
229
+ //
230
+ // Ref field.
231
+ //
232
+
233
+ const refProps = getRefProps(type);
234
+ if (refProps) {
235
+ // Inline a single referenced object's own fields (nested form) instead of a picker.
236
+ const inline = Annotation.FormInlineAnnotation.getFromAst(refProps.ast).pipe(Option.getOrElse(() => false));
237
+ if (inline && !refProps.isArray) {
238
+ return <InlineRefField {...fieldProps} {...refProps} db={db} useType={schemaHook} onCreate={onCreate} />;
239
+ }
240
+
241
+ const isCreateTarget = !createTypename || refProps.typename === createTypename;
242
+ return (
243
+ <RefField
244
+ {...fieldProps}
245
+ {...refProps}
246
+ createOptionLabel={isCreateTarget ? createOptionLabel : undefined}
247
+ createOptionIcon={isCreateTarget ? createOptionIcon : undefined}
248
+ createInitialValuePath={isCreateTarget ? createInitialValuePath : undefined}
249
+ createFieldMap={isCreateTarget ? createFieldMap : undefined}
250
+ db={db}
251
+ useType={schemaHook}
252
+ getOptions={getOptions}
253
+ onCreate={onCreate}
254
+ />
255
+ );
256
+ }
257
+
258
+ //
259
+ // Nested Object field.
260
+ //
261
+
262
+ if (isNestedType(type)) {
263
+ const baseNode = findNode(type, isDiscriminatedUnion);
264
+ const typeLiteral = baseNode
265
+ ? getDiscriminatedType(baseNode, fieldState.getValue() as any)
266
+ : findNode(type, SchemaAST.isTypeLiteral);
267
+
268
+ if (typeLiteral) {
269
+ const schema = Schema.make(typeLiteral);
270
+ return (
271
+ <Nesting>
272
+ <FormFieldSet
273
+ schema={schema}
274
+ path={path}
275
+ readonly={readonly}
276
+ layout={layout}
277
+ label={label}
278
+ projection={projection}
279
+ fieldMap={fieldMap}
280
+ fieldProvider={fieldProvider}
281
+ createOptionLabel={createOptionLabel}
282
+ createOptionIcon={createOptionIcon}
283
+ createInitialValuePath={createInitialValuePath}
284
+ db={db}
285
+ useType={schemaHook}
286
+ getOptions={getOptions}
287
+ onCreate={onCreate}
288
+ />
289
+ </Nesting>
290
+ );
291
+ }
292
+ }
293
+
294
+ return null;
295
+ };
296
+
297
+ FormField.displayName = 'Form.FormField';
298
+
299
+ //
300
+ // Layout components
301
+ //
302
+
303
+ // TODO(burdon): Options (nested or flat).
304
+ // TODO(burdon): Support collapsible.
305
+ export const Nesting = ({ children }: PropsWithChildren) => (
306
+ <div className='px-2 border border-subdued-separator rounded-sm mt-2'>
307
+ <div className='pb-2'>{children}</div>
308
+ </div>
309
+ );
310
+
311
+ export const IconBlock = ({ inline, ...props }: IconButtonProps & { inline?: boolean }) => {
312
+ return (
313
+ <div className={mx('h-full flex px-1', inline ? 'items-center' : 'flex-col pt-2.5')}>
314
+ <IconButton variant='ghost' density='xs' square iconOnly {...props} />
315
+ </div>
316
+ );
317
+ };
318
+
319
+ /**
320
+ * Get property input component.
321
+ */
322
+ const getFormField = ({ type, format }: FormFieldComponentProps): FormFieldComponent | undefined => {
323
+ //
324
+ // Standard formats.
325
+ //
326
+
327
+ const formatField = Match.value(format).pipe(
328
+ Match.withReturnType<FormFieldComponent | undefined>(),
329
+ Match.when(Format.TypeFormat.Date, () => DateField),
330
+ Match.when(Format.TypeFormat.DateTime, () => DateField),
331
+ Match.when(Format.TypeFormat.GeoPoint, () => GeoPointField),
332
+ Match.when(Format.TypeFormat.Markdown, () => MarkdownField),
333
+ Match.when(Format.TypeFormat.Text, () => TextAreaField),
334
+ Match.when(Format.TypeFormat.Time, () => DateField),
335
+ Match.orElse(() => undefined),
336
+ );
337
+ if (formatField) {
338
+ return formatField;
339
+ }
340
+
341
+ //
342
+ // Standard types.
343
+ //
344
+
345
+ switch (type._tag) {
346
+ // TODO(wittjosiah): Schema.Any is currently used to represent template inputs.
347
+ case 'AnyKeyword':
348
+ case 'StringKeyword':
349
+ return TextField;
350
+ case 'NumberKeyword':
351
+ return NumberField;
352
+ case 'BooleanKeyword':
353
+ return BooleanField;
354
+ }
355
+ };
356
+
357
+ const getSelectOptions = (ast: SchemaAST.AST): Format.Options[] | undefined => {
358
+ if (isLiteralUnion(ast)) {
359
+ return ast.types.map((type) => type.literal).filter((v): v is string | number => v !== null);
360
+ }
361
+
362
+ return Format.OptionsAnnotation.getFromAst(ast).pipe((annotation) => Option.getOrUndefined(annotation));
363
+ };
@@ -0,0 +1,65 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React, { type ChangeEvent, useCallback } from 'react';
7
+
8
+ import { Input } from '@dxos/react-ui';
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
+
11
+ import { type FormFieldComponentProps, FormFieldWrapper } from './FormFieldComponent';
12
+
13
+ const DefaultStory = ({
14
+ type,
15
+ placeholder,
16
+ readonly,
17
+ onBlur,
18
+ onValueChange,
19
+ ...props
20
+ }: FormFieldComponentProps<string>) => {
21
+ const handleChange = useCallback(
22
+ (event: ChangeEvent<HTMLInputElement>) => onValueChange(type, event.target.value),
23
+ [type, onValueChange],
24
+ );
25
+
26
+ return (
27
+ <div className='p-form-padding'>
28
+ <FormFieldWrapper<string> {...props}>
29
+ {({ value = '' }) => (
30
+ <Input.TextInput
31
+ disabled={!!readonly}
32
+ placeholder={placeholder}
33
+ noAutoFill
34
+ value={value}
35
+ onChange={handleChange}
36
+ onBlur={onBlur}
37
+ />
38
+ )}
39
+ </FormFieldWrapper>
40
+ </div>
41
+ );
42
+ };
43
+
44
+ const meta: Meta<typeof DefaultStory> = {
45
+ title: 'ui/react-ui-form/FormFieldComponent',
46
+ component: DefaultStory,
47
+ decorators: [withTheme(), withLayout({ layout: 'column' })],
48
+ parameters: {
49
+ layout: 'fullscreen',
50
+ },
51
+ };
52
+
53
+ export default meta;
54
+
55
+ type Story = StoryObj<typeof meta>;
56
+
57
+ export const Default: Story = {
58
+ args: {
59
+ label: 'Label',
60
+ getStatus: () => ({ status: 'error', error: 'Required field' }),
61
+ getValue: () => 'DXOS',
62
+ onBlur: () => {},
63
+ onValueChange: () => {},
64
+ },
65
+ };
@@ -0,0 +1,229 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { format as formatDate } from 'date-fns';
6
+ import type * as Schema from 'effect/Schema';
7
+ import type * as SchemaAST from 'effect/SchemaAST';
8
+ import React, {
9
+ Component,
10
+ type FC,
11
+ type FocusEvent,
12
+ type PropsWithChildren,
13
+ type ReactElement,
14
+ type ReactNode,
15
+ } from 'react';
16
+
17
+ import { type Database, Format } from '@dxos/echo';
18
+ import { Icon, Input, Tooltip } from '@dxos/react-ui';
19
+ import { inputTextLabel } from '@dxos/react-ui';
20
+ import { mx } from '@dxos/ui-theme';
21
+
22
+ import { type FormFieldStatus } from '../../hooks';
23
+ import { useFormTooltips } from './FormTooltipsContext';
24
+
25
+ /**
26
+ * Dynamic props passed to input components.
27
+ */
28
+ export type FormFieldStateProps<T = any> = {
29
+ getStatus: () => FormFieldStatus;
30
+ getValue: () => T | undefined;
31
+ onBlur: (event: FocusEvent<HTMLElement>) => void;
32
+ onValueChange: (type: SchemaAST.AST, value: T) => void;
33
+ };
34
+
35
+ /**
36
+ * Presentation mode.
37
+ * - full: Show label, control, and status.
38
+ * - compact: Show label and control.
39
+ * - inline: Control only.
40
+ * - static: Plain DOM; omit all undefined values.
41
+ */
42
+ // TODO(burdon): 'inline' should be orthogonal to the layout (e.g., array of inline static).
43
+ export type Presentation = 'full' | 'compact' | 'inline' | 'static';
44
+
45
+ /**
46
+ * Props passed to input components.
47
+ */
48
+ export type FormFieldComponentProps<T = any> = {
49
+ /** Database the form is editing against; populated for fields whose value is an ECHO object/Ref. */
50
+ db?: Database.Database;
51
+ type: SchemaAST.AST;
52
+ format?: Format.TypeFormat;
53
+ readonly?: boolean;
54
+ label: string;
55
+ /**
56
+ * Dotted JSON path of this field within the form values (e.g.
57
+ * `runtime.client.storage.persistent`). Forwarded to `FormFieldLabel` so
58
+ * that it can render the path as a debug hint when the enclosing
59
+ * `Form.Root` has `debug` enabled.
60
+ */
61
+ jsonPath?: string;
62
+ placeholder?: string;
63
+ autoFocus?: boolean;
64
+ layout?: Presentation;
65
+ } & FormFieldStateProps<T>;
66
+
67
+ export type FormFieldComponent = FC<FormFieldComponentProps>;
68
+
69
+ export type FormFieldMap = Record<string, FormFieldComponent>;
70
+
71
+ export type FormFieldProvider = (props: {
72
+ prop: string;
73
+ schema: Schema.Schema<any>;
74
+ fieldProps: FormFieldComponentProps;
75
+ }) => ReactElement | null | undefined;
76
+
77
+ //
78
+ // FormFieldLabel
79
+ //
80
+
81
+ export type FormFieldLabelProps = {
82
+ asChild?: boolean;
83
+ error?: string;
84
+ /**
85
+ * JSON path of the field this label describes (e.g. `runtime.client.storage.persistent`).
86
+ * Surfaced as a hover tooltip on the label when the enclosing `Form.Root`
87
+ * has `tooltips` enabled (the default) -- useful for spotting which field
88
+ * maps to which path when authoring schemas or filing bugs against a form.
89
+ * Callers can supply the path unconditionally; the label suppresses the
90
+ * tooltip when `Form.Root tooltips={false}`.
91
+ */
92
+ path?: string;
93
+ } & Pick<FormFieldComponentProps, 'label' | 'readonly'>;
94
+
95
+ export const FormFieldLabel = ({ label, error, readonly, asChild, path }: FormFieldLabelProps) => {
96
+ const tooltips = useFormTooltips();
97
+ const Label = readonly || asChild ? 'span' : Input.Label;
98
+ const labelNode = <Label className={mx(inputTextLabel, 'text-sm')}>{label}</Label>;
99
+ return (
100
+ <div className='flex items-center justify-between'>
101
+ {tooltips && path ? (
102
+ <Tooltip.Trigger asChild content={path} side='bottom'>
103
+ {labelNode}
104
+ </Tooltip.Trigger>
105
+ ) : (
106
+ labelNode
107
+ )}
108
+ {error && (
109
+ <Tooltip.Trigger asChild content={error} side='bottom'>
110
+ <Icon icon='ph--warning--regular' size={4} classNames='text-error-text' />
111
+ </Tooltip.Trigger>
112
+ )}
113
+ </div>
114
+ );
115
+ };
116
+
117
+ FormFieldLabel.displayName = 'Form.FieldLabel';
118
+
119
+ //
120
+ // FormFieldWrapper
121
+ //
122
+
123
+ export type FormFieldWrapperProps<T = any> = Pick<
124
+ FormFieldComponentProps,
125
+ 'readonly' | 'label' | 'layout' | 'getStatus' | 'getValue' | 'jsonPath' | 'format'
126
+ > & {
127
+ children?: (props: { value: T }) => ReactNode;
128
+ };
129
+
130
+ /**
131
+ * Formats a value for `static` (read-only, plain-DOM) presentation based on its
132
+ * type `format`. Dates/times are rendered human-readable; everything else falls
133
+ * back to `String(value)`.
134
+ */
135
+ const formatStaticValue = (value: unknown, format?: Format.TypeFormat): string => {
136
+ if (value == null) {
137
+ return '';
138
+ }
139
+
140
+ switch (format) {
141
+ case Format.TypeFormat.DateTime:
142
+ case Format.TypeFormat.Date:
143
+ case Format.TypeFormat.Time: {
144
+ const date = new Date(value as string);
145
+ if (Number.isNaN(date.getTime())) {
146
+ return String(value);
147
+ }
148
+ const pattern = format === Format.TypeFormat.DateTime ? 'PPp' : format === Format.TypeFormat.Date ? 'PP' : 'p';
149
+ return formatDate(date, pattern);
150
+ }
151
+ default:
152
+ return String(value);
153
+ }
154
+ };
155
+
156
+ export const FormFieldWrapper = <T,>(props: FormFieldWrapperProps<T>) => {
157
+ const { children, readonly, layout, label, jsonPath, format, getStatus, getValue } = props;
158
+ const { status, error } = getStatus();
159
+
160
+ const value = getValue();
161
+ if (layout === 'static' && value == null) {
162
+ return null;
163
+ }
164
+
165
+ const str = formatStaticValue(value, format);
166
+
167
+ return (
168
+ <div className='contents'>
169
+ <Input.Root validationValence={status}>
170
+ {layout !== 'inline' && <FormFieldLabel error={error} readonly={readonly} label={label} path={jsonPath} />}
171
+ {layout === 'static' ? (
172
+ <p className='truncate min-w-0' title={str}>
173
+ {str}
174
+ </p>
175
+ ) : children ? (
176
+ children({ value })
177
+ ) : null}
178
+ {layout === 'full' && error && (
179
+ <Input.DescriptionAndValidation>
180
+ <Input.Validation>{error}</Input.Validation>
181
+ </Input.DescriptionAndValidation>
182
+ )}
183
+ </Input.Root>
184
+ </div>
185
+ );
186
+ };
187
+
188
+ //
189
+ // FormFieldErrorBoundary
190
+ //
191
+
192
+ type FormFieldErrorState = {
193
+ error: Error | undefined;
194
+ };
195
+
196
+ type FormFieldErrorBoundaryProps = PropsWithChildren<{
197
+ path?: (string | number)[];
198
+ }>;
199
+
200
+ export class FormFieldErrorBoundary extends Component<FormFieldErrorBoundaryProps, FormFieldErrorState> {
201
+ static getDerivedStateFromError(error: Error): { error: Error } {
202
+ return { error };
203
+ }
204
+
205
+ override state = { error: undefined };
206
+
207
+ override componentDidUpdate(prevProps: FormFieldErrorBoundaryProps) {
208
+ if (prevProps.path !== this.props.path) {
209
+ this.resetError();
210
+ }
211
+ }
212
+
213
+ override render() {
214
+ if (this.state.error) {
215
+ return (
216
+ <div className='flex gap-2 border border-rose-bg font-mono text-sm'>
217
+ <span className='bg-rose-bg text-base-fg px-1 font-thin'>ERROR</span>
218
+ {String(this.props.path?.join('.'))}
219
+ </div>
220
+ );
221
+ }
222
+
223
+ return this.props.children;
224
+ }
225
+
226
+ private resetError() {
227
+ this.setState({ error: undefined });
228
+ }
229
+ }