@dxos/react-ui-form 0.8.4-main.b97322e → 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 (197) hide show
  1. package/dist/lib/browser/index.mjs +2220 -2058
  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 +2220 -2058
  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 +4 -4
  8. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +1 -1
  9. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +84 -5
  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 +82 -5
  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 -25
  18. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  19. package/dist/types/src/components/Form/Form.stories.d.ts +127 -55
  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/fields/SelectOptionField.stories.d.ts +82 -0
  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 -9
  64. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  65. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +83 -8
  66. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/index.d.ts +1 -1
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/components/testing.d.ts +4 -3
  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 +19 -10
  78. package/dist/types/src/translations.d.ts.map +1 -1
  79. package/dist/types/src/util/echo.d.ts +6 -0
  80. package/dist/types/src/util/echo.d.ts.map +1 -0
  81. package/dist/types/src/util/field.d.ts +3 -3
  82. package/dist/types/src/util/field.d.ts.map +1 -1
  83. package/dist/types/src/util/formatting.d.ts +2 -2
  84. package/dist/types/src/util/formatting.d.ts.map +1 -1
  85. package/dist/types/src/util/index.d.ts +2 -1
  86. package/dist/types/src/util/index.d.ts.map +1 -1
  87. package/dist/types/src/util/properties.d.ts +7 -0
  88. package/dist/types/src/util/properties.d.ts.map +1 -0
  89. package/dist/types/src/util/refs.d.ts +2 -3
  90. package/dist/types/src/util/refs.d.ts.map +1 -1
  91. package/dist/types/tsconfig.tsbuildinfo +1 -1
  92. package/package.json +51 -40
  93. package/src/components/ControlSection/ControlSection.stories.tsx +11 -14
  94. package/src/components/ControlSection/ControlSection.tsx +30 -16
  95. package/src/components/FieldEditor/FieldEditor.stories.tsx +52 -31
  96. package/src/components/FieldEditor/FieldEditor.test.tsx +3 -2
  97. package/src/components/FieldEditor/FieldEditor.tsx +86 -81
  98. package/src/components/Form/Form-old.stories.tsx +314 -0
  99. package/src/components/Form/Form.stories.tsx +155 -219
  100. package/src/components/Form/Form.tsx +320 -96
  101. package/src/components/Form/FormField.tsx +286 -0
  102. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  103. package/src/components/Form/FormFieldComponent.tsx +174 -0
  104. package/src/components/Form/FormFieldSet.tsx +125 -0
  105. package/src/components/Form/README.md +3 -0
  106. package/src/components/Form/fields/ArrayField.tsx +151 -0
  107. package/src/components/Form/fields/BooleanField.tsx +22 -0
  108. package/src/components/Form/fields/GeoPointField.tsx +120 -0
  109. package/src/components/Form/fields/MarkdownField.tsx +78 -0
  110. package/src/components/Form/fields/NumberField.tsx +39 -0
  111. package/src/components/Form/fields/RefField.tsx +181 -0
  112. package/src/components/Form/fields/SelectField.tsx +65 -0
  113. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +25 -22
  114. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +47 -42
  115. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  116. package/src/components/Form/fields/TextField.tsx +38 -0
  117. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +16 -9
  118. package/src/components/Form/fields/index.ts +15 -0
  119. package/src/components/Form/index.ts +3 -4
  120. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +214 -0
  121. package/src/components/ObjectPicker/ObjectPicker.tsx +175 -0
  122. package/src/components/ObjectPicker/index.ts +5 -0
  123. package/src/components/ViewEditor/ViewEditor.stories.tsx +137 -61
  124. package/src/components/ViewEditor/ViewEditor.test.tsx +19 -17
  125. package/src/components/ViewEditor/ViewEditor.tsx +324 -203
  126. package/src/components/index.ts +1 -2
  127. package/src/components/testing.tsx +19 -11
  128. package/src/hooks/index.ts +2 -3
  129. package/src/hooks/useFormHandler.ts +362 -0
  130. package/src/hooks/useKeyHandler.tsx +37 -0
  131. package/src/translations.ts +21 -12
  132. package/src/util/echo.ts +25 -0
  133. package/src/util/field.ts +33 -43
  134. package/src/util/formatting.ts +22 -22
  135. package/src/util/index.ts +2 -1
  136. package/src/util/properties.ts +18 -0
  137. package/src/util/refs.ts +12 -18
  138. package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
  139. package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
  140. package/dist/types/src/components/Form/Defaults.d.ts +0 -14
  141. package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
  142. package/dist/types/src/components/Form/FormActions.d.ts +0 -9
  143. package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
  144. package/dist/types/src/components/Form/FormContent.d.ts +0 -57
  145. package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
  146. package/dist/types/src/components/Form/FormContext.d.ts +0 -23
  147. package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
  148. package/dist/types/src/components/Form/Input.d.ts +0 -26
  149. package/dist/types/src/components/Form/Input.d.ts.map +0 -1
  150. package/dist/types/src/components/Form/RefField.d.ts +0 -12
  151. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  152. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
  153. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
  154. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
  155. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
  156. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -7
  157. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
  158. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  159. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  160. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  161. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  162. package/dist/types/src/components/Form/factory.d.ts +0 -8
  163. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  164. package/dist/types/src/components/deprecated/Form.d.ts +0 -15
  165. package/dist/types/src/components/deprecated/Form.d.ts.map +0 -1
  166. package/dist/types/src/components/deprecated/Form.stories.d.ts +0 -13
  167. package/dist/types/src/components/deprecated/Form.stories.d.ts.map +0 -1
  168. package/dist/types/src/components/deprecated/FormInput.d.ts +0 -16
  169. package/dist/types/src/components/deprecated/FormInput.d.ts.map +0 -1
  170. package/dist/types/src/components/deprecated/index.d.ts +0 -2
  171. package/dist/types/src/components/deprecated/index.d.ts.map +0 -1
  172. package/dist/types/src/hooks/useForm.d.ts +0 -67
  173. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  174. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
  175. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  176. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  177. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  178. package/dist/types/src/util/schema.d.ts +0 -3
  179. package/dist/types/src/util/schema.d.ts.map +0 -1
  180. package/src/components/Form/ArrayField.tsx +0 -124
  181. package/src/components/Form/Defaults.tsx +0 -203
  182. package/src/components/Form/FormActions.tsx +0 -53
  183. package/src/components/Form/FormContent.tsx +0 -240
  184. package/src/components/Form/FormContext.tsx +0 -110
  185. package/src/components/Form/Input.tsx +0 -51
  186. package/src/components/Form/RefField.tsx +0 -213
  187. package/src/components/Form/custom/GeoPointInput.tsx +0 -72
  188. package/src/components/Form/custom/index.ts +0 -7
  189. package/src/components/Form/factory.tsx +0 -31
  190. package/src/components/deprecated/Form.stories.tsx +0 -62
  191. package/src/components/deprecated/Form.tsx +0 -119
  192. package/src/components/deprecated/FormInput.tsx +0 -71
  193. package/src/components/deprecated/index.ts +0 -5
  194. package/src/hooks/useForm.ts +0 -291
  195. package/src/hooks/useQueryRefOptions.ts +0 -53
  196. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  197. package/src/util/schema.ts +0 -14
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-form",
3
- "version": "0.8.4-main.b97322e",
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",
10
14
  "exports": {
11
15
  ".": {
16
+ "source": "./src/index.ts",
12
17
  "types": "./dist/types/src/index.d.ts",
13
18
  "browser": "./dist/lib/browser/index.mjs",
14
19
  "node": "./dist/lib/node-esm/index.mjs"
@@ -23,54 +28,60 @@
23
28
  "src"
24
29
  ],
25
30
  "dependencies": {
26
- "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
27
- "@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.0.3",
28
- "@preact-signals/safe-react": "^0.9.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",
29
35
  "@radix-ui/react-context": "1.1.1",
36
+ "@radix-ui/react-use-controllable-state": "1.1.0",
30
37
  "date-fns": "^3.3.1",
31
38
  "jsonpath": "^1.1.1",
32
- "@dxos/async": "0.8.4-main.b97322e",
33
- "@dxos/debug": "0.8.4-main.b97322e",
34
- "@dxos/echo-schema": "0.8.4-main.b97322e",
35
- "@dxos/echo": "0.8.4-main.b97322e",
36
- "@dxos/echo-db": "0.8.4-main.b97322e",
37
- "@dxos/effect": "0.8.4-main.b97322e",
38
- "@dxos/invariant": "0.8.4-main.b97322e",
39
- "@dxos/keys": "0.8.4-main.b97322e",
40
- "@dxos/lit-ui": "0.8.4-main.b97322e",
41
- "@dxos/log": "0.8.4-main.b97322e",
42
- "@dxos/react-client": "0.8.4-main.b97322e",
43
- "@dxos/live-object": "0.8.4-main.b97322e",
44
- "@dxos/react-ui-list": "0.8.4-main.b97322e",
45
- "@dxos/react-ui-stack": "0.8.4-main.b97322e",
46
- "@dxos/react-ui-pickers": "0.8.4-main.b97322e",
47
- "@dxos/react-ui-types": "0.8.4-main.b97322e",
48
- "@dxos/react-ui-tag-picker": "0.8.4-main.b97322e",
49
- "@dxos/schema": "0.8.4-main.b97322e",
50
- "@dxos/util": "0.8.4-main.b97322e"
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"
51
62
  },
52
63
  "devDependencies": {
53
64
  "@types/jsonpath": "^0.2.4",
54
- "@types/react": "~18.2.0",
55
- "@types/react-dom": "~18.2.0",
56
- "effect": "3.17.0",
65
+ "@types/react": "~19.2.7",
66
+ "@types/react-dom": "~19.2.3",
67
+ "effect": "3.19.11",
57
68
  "fast-check": "^3.19.0",
58
- "react": "~18.2.0",
59
- "react-dom": "~18.2.0",
60
- "vite": "5.4.7",
61
- "@dxos/echo-signals": "0.8.4-main.b97322e",
62
- "@dxos/random": "0.8.4-main.b97322e",
63
- "@dxos/react-ui": "0.8.4-main.b97322e",
64
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.b97322e",
65
- "@dxos/storybook-utils": "0.8.4-main.b97322e",
66
- "@dxos/react-ui-theme": "0.8.4-main.b97322e"
69
+ "react": "~19.2.3",
70
+ "react-dom": "~19.2.3",
71
+ "vite": "7.1.9",
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"
67
78
  },
68
79
  "peerDependencies": {
69
- "effect": "^3.13.3",
70
- "react": "~18.2.0",
71
- "react-dom": "~18.2.0",
72
- "@dxos/react-ui": "0.8.4-main.b97322e",
73
- "@dxos/react-ui-theme": "0.8.4-main.b97322e"
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"
74
85
  },
75
86
  "publishConfig": {
76
87
  "access": "public"
@@ -2,36 +2,33 @@
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
6
  import React from 'react';
9
7
 
10
- import { StackItem } from '@dxos/react-ui-stack';
11
- import { withLayout, withTheme } from '@dxos/storybook-utils';
8
+ import { withTheme } from '@dxos/react-ui/testing';
12
9
 
13
- import { ControlPage, ControlSection, type ControlSectionProps } from './ControlSection';
14
10
  import { translations } from '../../translations';
15
11
 
16
- const meta: Meta<ControlSectionProps> = {
12
+ import { ControlPage, ControlSection } from './ControlSection';
13
+
14
+ const meta = {
17
15
  title: 'ui/react-ui-form/ControlSection',
18
16
  component: ControlSection,
19
17
  render: (args) => (
20
- <StackItem.Content classNames='w-[40rem]'>
21
- <ControlPage>
22
- <ControlSection {...args} />
23
- </ControlPage>
24
- </StackItem.Content>
18
+ <ControlPage classNames='is-[40rem]'>
19
+ <ControlSection {...args} />
20
+ </ControlPage>
25
21
  ),
26
- decorators: [withLayout({ fullscreen: true, classNames: 'justify-center' }), withTheme],
22
+ decorators: [withTheme],
27
23
  parameters: {
24
+ layout: 'centered',
28
25
  translations,
29
26
  },
30
- };
27
+ } satisfies Meta<typeof ControlSection>;
31
28
 
32
29
  export default meta;
33
30
 
34
- type Story = StoryObj<ControlSectionProps>;
31
+ type Story = StoryObj<typeof meta>;
35
32
 
36
33
  export const Default: Story = {
37
34
  args: {
@@ -13,17 +13,20 @@ import {
13
13
  toLocalizedString,
14
14
  useTranslation,
15
15
  } from '@dxos/react-ui';
16
- import { mx } from '@dxos/react-ui-theme';
16
+ import { Layout } from '@dxos/react-ui-mosaic';
17
+ import { mx } from '@dxos/ui-theme';
17
18
 
18
19
  import { translationKey } from '../../translations';
19
20
 
20
- export type ControlPageProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
21
+ export type ControlPageParams = ThemedClassName<ComponentPropsWithoutRef<'div'>>;
21
22
 
22
- export const ControlPage = ({ children, classNames, ...props }: ControlPageProps) => {
23
+ export const ControlPage = ({ children, classNames, ...props }: ControlPageParams) => {
23
24
  return (
24
- <div role='none' className={mx('pli-cardSpacingInline', classNames)} {...props}>
25
- {children}
26
- </div>
25
+ <Layout.Container scrollable classNames='[--control-spacing:var(--dx-trimMd)]'>
26
+ <div role='none' className={mx('pli-cardSpacingInline pbe-trimMd', classNames)} {...props}>
27
+ {children}
28
+ </div>
29
+ </Layout.Container>
27
30
  );
28
31
  };
29
32
 
@@ -45,7 +48,7 @@ export const ControlSectionHeading = ({ title, description }: Omit<ControlSectio
45
48
  const { t } = useTranslation(translationKey);
46
49
  return (
47
50
  <>
48
- <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>
49
52
  {description && (
50
53
  <p className='pli-trimMd mlb-trimMd container-max-width text-description'>
51
54
  {toLocalizedString(description, t)}
@@ -59,12 +62,16 @@ export const ControlGroupButton = ({ classNames, ...props }: ButtonProps) => {
59
62
  return <Button {...props} classNames={['md:col-span-2', classNames]} />;
60
63
  };
61
64
 
62
- export type ControlGroupProps = ThemedClassName<PropsWithChildren<{}>>;
65
+ export type ControlGroupProps = ThemedClassName<PropsWithChildren>;
63
66
 
64
67
  export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
65
68
  <div
66
69
  role='none'
67
- className={mx('group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd', classNames)}
70
+ className={mx(
71
+ 'group container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content] gap-trimMd',
72
+ '[--control-spacing:0px] [&_input]:justify-self-end [&_button]:justify-self-end',
73
+ classNames,
74
+ )}
68
75
  >
69
76
  {children}
70
77
  </div>
@@ -73,23 +80,30 @@ export const ControlGroup = ({ children, classNames }: ControlGroupProps) => (
73
80
  export const ControlFrame = ({ children }: ControlGroupProps) => (
74
81
  <div
75
82
  role='none'
76
- className='p-trimMd container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd border border-separator rounded-md'
83
+ className={mx(
84
+ 'container-max-width grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-trimSm md:gap-trimMd p-trimMd',
85
+ 'border border-separator rounded-md',
86
+ )}
77
87
  >
78
88
  {children}
79
89
  </div>
80
90
  );
81
91
 
92
+ export const controlItemClasses = mx([
93
+ 'container-max-width grid md:col-span-2 grid-cols-subgrid gap-trimSm items-center',
94
+ // TODO(burdon): Use grid gap consistently or apply margins consistently?
95
+ 'mlb-[--control-spacing] *:first:!mbs-0 *:last:!mbe-0 pli-trimMd plb-trimMd',
96
+ 'border border-separator rounded-md',
97
+ ]);
98
+
99
+ const controlItemTitleClasses = 'mbe-0 text-lg text-baseText font-normal';
100
+ const controlItemDescriptionClasses = 'mlb-trimSm md:mbe-0 text-base text-description';
101
+
82
102
  export type ControlItemProps = PropsWithChildren<{
83
103
  title: Label;
84
104
  description?: Label;
85
105
  }>;
86
106
 
87
- export const controlItemClasses =
88
- 'pli-trimMd plb-trimMd container-max-width grid md:col-span-2 grid-cols-subgrid items-center gap-trimSm border border-separator rounded-md *:first:!mbs-0 *:last:!mbe-0';
89
-
90
- const controlItemTitleClasses = 'text-lg font-normal';
91
- const controlItemDescriptionClasses = 'text-base mlb-trimSm md:mbe-0 text-description';
92
-
93
107
  export const ControlItem = ({ title, description, children }: ControlItemProps) => {
94
108
  const { t } = useTranslation(translationKey);
95
109
 
@@ -2,20 +2,20 @@
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 React, { useMemo, useEffect } from 'react';
6
+ import React, { useEffect, useMemo } from 'react';
9
7
 
10
- import { createEchoSchema } from '@dxos/live-object/testing';
8
+ import { Filter, Query } from '@dxos/echo';
9
+ import { createEchoSchema } from '@dxos/echo/testing';
11
10
  import { log } from '@dxos/log';
12
- import { ProjectionModel } from '@dxos/schema';
13
- import { TestSchema, testView } from '@dxos/schema/testing';
14
- import { withLayout, withTheme } from '@dxos/storybook-utils';
11
+ import { withTheme } from '@dxos/react-ui/testing';
12
+ import { ProjectionModel, View, createEchoChangeCallback } from '@dxos/schema';
13
+ import { Example } from '@dxos/schema/testing';
15
14
 
16
- import { FieldEditor, type FieldEditorProps } from './FieldEditor';
17
15
  import { translations } from '../../translations';
18
- import { TestLayout, TestPanel, FIELD_EDITOR_DEBUG_SYMBOL } from '../testing';
16
+ import { FIELD_EDITOR_DEBUG_SYMBOL, TestLayout } from '../testing';
17
+
18
+ import { FieldEditor, type FieldEditorProps } from './FieldEditor';
19
19
 
20
20
  // Type definition for debug objects exposed to tests.
21
21
  export type FieldEditorDebugObjects = {
@@ -23,11 +23,36 @@ export type FieldEditorDebugObjects = {
23
23
  projection: ProjectionModel;
24
24
  };
25
25
 
26
- type StoryProps = 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();
27
47
 
28
- const DefaultStory = (props: FieldEditorProps) => {
29
48
  const handleComplete: FieldEditorProps['onSave'] = () => {
30
- 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,
31
56
  };
32
57
 
33
58
  // Expose objects on window for test access.
@@ -35,44 +60,40 @@ const DefaultStory = (props: FieldEditorProps) => {
35
60
  if (typeof window !== 'undefined') {
36
61
  (window as any)[FIELD_EDITOR_DEBUG_SYMBOL] = {
37
62
  props,
38
- projection: props.projection,
63
+ projection,
39
64
  } satisfies FieldEditorDebugObjects;
40
65
  }
41
- }, [props, props.projection]);
66
+ }, [props, projection]);
42
67
 
43
68
  // NOTE(ZaymonFC): This looks awkward but it resolves an infinite parsing issue with sb.
44
69
  const json = useMemo(
45
- () => JSON.parse(JSON.stringify({ props, projection: props.projection })),
46
- [JSON.stringify(props), JSON.stringify(props.projection)],
70
+ () => JSON.parse(JSON.stringify({ props, projection })),
71
+ [JSON.stringify(props), JSON.stringify(projection)],
47
72
  );
48
73
 
49
74
  return (
50
75
  <TestLayout json={json}>
51
- <TestPanel>
52
- <FieldEditor {...props} onSave={handleComplete} />
53
- </TestPanel>
76
+ <FieldEditor {...props} />
54
77
  </TestLayout>
55
78
  );
56
79
  };
57
80
 
58
- const meta: Meta<StoryProps> = {
81
+ const meta = {
59
82
  title: 'ui/react-ui-form/FieldEditor',
60
- component: FieldEditor,
83
+ component: FieldEditor as any,
61
84
  render: DefaultStory,
62
- decorators: [withLayout({ fullscreen: true }), withTheme],
85
+ decorators: [withTheme],
63
86
  parameters: {
87
+ layout: 'fullscreen',
64
88
  translations,
89
+ controls: {
90
+ disabled: true,
91
+ },
65
92
  },
66
- };
93
+ } satisfies Meta<typeof DefaultStory>;
67
94
 
68
95
  export default meta;
69
96
 
70
- type Story = StoryObj<StoryProps>;
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 = {};
@@ -3,14 +3,15 @@
3
3
  //
4
4
 
5
5
  import { composeStories } from '@storybook/react';
6
- import { screen, cleanup, fireEvent, act } from '@testing-library/react';
6
+ import { act, cleanup, fireEvent, screen } from '@testing-library/react';
7
7
  import { afterEach, describe, expect, test } from 'vitest';
8
8
 
9
9
  import { ProjectionModel } from '@dxos/schema';
10
10
 
11
+ import { FIELD_EDITOR_DEBUG_SYMBOL } from '../testing';
12
+
11
13
  import * as stories from './FieldEditor.stories';
12
14
  import { type FieldEditorDebugObjects } from './FieldEditor.stories';
13
- import { FIELD_EDITOR_DEBUG_SYMBOL } from '../testing';
14
15
 
15
16
  const { Default } = composeStories(stories);
16
17
 
@@ -4,41 +4,42 @@
4
4
 
5
5
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
6
6
 
7
- import { type SchemaRegistry } from '@dxos/echo-db';
8
- import { FormatEnum, FormatEnums, formatToType, type EchoSchema } from '@dxos/echo-schema';
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
- import { useTranslation } from '@dxos/react-ui';
11
+ import { useAsyncEffect, useTranslation } from '@dxos/react-ui';
11
12
  import {
12
- getFormatSchema,
13
- getSchemaProperties,
14
- sortProperties,
15
13
  type FieldType,
16
- type PropertyType,
17
14
  type ProjectionModel,
18
- type SchemaProperty,
15
+ type PropertyType,
16
+ formatToAdditionalPropertyAttributes,
17
+ getFormatSchema,
19
18
  } from '@dxos/schema';
20
19
 
21
20
  import { translationKey } from '../../translations';
22
- 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';
23
23
 
24
24
  export type FieldEditorProps = {
25
25
  projection: ProjectionModel;
26
26
  field: FieldType;
27
- registry?: SchemaRegistry;
27
+ registry?: SchemaRegistry.SchemaRegistry;
28
+ view?: Obj.Unknown;
28
29
  onSave: () => void;
29
30
  onCancel?: () => void;
30
- } & Pick<FormProps<any>, 'outerSpacing'>;
31
+ } & Pick<FormRootProps<any>, 'readonly'>;
31
32
 
32
33
  /**
33
34
  * Displays a Form representing the metadata for a given `Field` and `View`.
34
35
  */
35
- export const FieldEditor = ({ projection, field, registry, onSave, onCancel, outerSpacing }: FieldEditorProps) => {
36
+ export const FieldEditor = ({ readonly, projection, field, registry, view, onSave, onCancel }: FieldEditorProps) => {
36
37
  const { t } = useTranslation(translationKey);
37
38
  const [props, setProps] = useState<PropertyType>(projection.getFieldProjection(field.id).props);
38
39
  useEffect(() => setProps(projection.getFieldProjection(field.id).props), [field, projection]);
39
40
 
40
41
  const [schemas, setSchemas] = useState<EchoSchema[]>([]);
41
- useEffect(() => {
42
+ useAsyncEffect(async () => {
42
43
  if (!registry) {
43
44
  return;
44
45
  }
@@ -46,14 +47,10 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
46
47
  const subscription = registry.query().subscribe((query) => setSchemas(query.results), { fire: true });
47
48
 
48
49
  // TODO(dmaretskyi): This shouldn't be needed.
49
- const t = setTimeout(async () => {
50
- const schemas = await registry.query().run();
51
- setSchemas(schemas);
52
- });
53
- return () => {
54
- clearTimeout(t);
55
- subscription?.();
56
- };
50
+ const schemas = await registry.query().run();
51
+ setSchemas(schemas);
52
+
53
+ return () => subscription?.();
57
54
  }, [registry]);
58
55
 
59
56
  const [referenceSchema, setReferenceSchema] = useState<EchoSchema>();
@@ -65,11 +62,47 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
65
62
  // Class constructor SchemaClass cannot be invoked without 'new'.
66
63
  const [{ fieldSchema }, setFieldSchema] = useState({ fieldSchema: getFormatSchema(props?.format) });
67
64
 
68
- 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']>>(
69
104
  (_props) => {
70
- // TODO(burdon): Callback should pass `changed` to indicate which fields have changed.
71
- // TODO(Zaymon): Workout why old and new format values are the same sometimes even when
72
- // selecting novel format values.
105
+ // TODO(Zaymon): Workout why old and new format values are the same sometimes even when selecting novel format values.
73
106
  setFieldSchema((prev) => {
74
107
  const fieldSchema = getFormatSchema(_props.format);
75
108
  if (prev.fieldSchema === fieldSchema) {
@@ -90,8 +123,10 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
90
123
 
91
124
  setProps((props) => {
92
125
  const type = formatToType[_props.format as keyof typeof formatToType];
126
+ const additionalProps =
127
+ formatToAdditionalPropertyAttributes[_props.format as keyof typeof formatToAdditionalPropertyAttributes];
93
128
  if (props.type !== type) {
94
- return { ...props, ..._props, type };
129
+ return { ...props, ..._props, ...additionalProps, type } as PropertyType;
95
130
  }
96
131
 
97
132
  return _props as PropertyType;
@@ -100,9 +135,9 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
100
135
  [schemas, props.format, props.referenceSchema],
101
136
  );
102
137
 
103
- const handleValidate = useCallback<NonNullable<FormProps<PropertyType>['onValidate']>>(
138
+ const handleValidate = useCallback<NonNullable<FormRootProps<PropertyType>['onValidate']>>(
104
139
  ({ property }) => {
105
- 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)) {
106
141
  return [
107
142
  {
108
143
  path: 'property',
@@ -111,83 +146,53 @@ export const FieldEditor = ({ projection, field, registry, onSave, onCancel, out
111
146
  ];
112
147
  }
113
148
  },
114
- [projection.fields, field],
149
+ [projection.getFields(), field],
115
150
  );
116
151
 
117
- const handleSave = useCallback<NonNullable<FormProps<PropertyType>['onSave']>>(
152
+ const handleSave = useCallback<NonNullable<FormRootProps<PropertyType>['onSave']>>(
118
153
  (props) => {
119
- 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
+ }
120
161
  onSave();
121
162
  },
122
- [projection, field, onSave],
163
+ [projection, field, view, onSave],
123
164
  );
124
165
 
125
- const handleCancel = useCallback<NonNullable<FormProps<PropertyType>['onCancel']>>(() => {
166
+ const handleCancel = useCallback<NonNullable<FormRootProps<PropertyType>['onCancel']>>(() => {
167
+ onSave();
126
168
  // Need to defer to allow form to close.
127
169
  requestAnimationFrame(() => onCancel?.());
128
- onSave();
129
170
  }, [onSave]);
130
171
 
131
- const custom: Partial<Record<string, InputComponent>> = useMemo(
132
- () => ({
133
- ['format' satisfies keyof PropertyType]: (props) => (
134
- <SelectInput
135
- {...props}
136
- options={FormatEnums.filter((value) => value !== FormatEnum.None).map((value) => ({
137
- value,
138
- label: t(`format ${value}`),
139
- }))}
140
- />
141
- ),
142
- ['referenceSchema' satisfies keyof PropertyType]: (props) => (
143
- <SelectInput
144
- {...props}
145
- options={schemas.map((schema) => ({
146
- value: schema.typename,
147
- }))}
148
- />
149
- ),
150
- ['referencePath' satisfies keyof PropertyType]: (props) => (
151
- <SelectInput
152
- {...props}
153
- options={
154
- referenceSchema
155
- ? getSchemaProperties(referenceSchema.ast)
156
- .sort(sortProperties)
157
- .map((p) => ({ value: p.name }))
158
- : []
159
- }
160
- />
161
- ),
162
- ['options' satisfies keyof PropertyType]: (props) => <SelectOptionInput {...props} />,
163
- }),
164
- [t, schemas, referenceSchema],
165
- );
166
-
167
- const propIsNotType = useCallback(
168
- (props: SchemaProperty<PropertyType>[]) => props.filter((p) => p.name !== 'type'),
169
- [],
170
- );
171
-
172
172
  if (!fieldSchema) {
173
173
  log.warn('invalid format', { props });
174
174
  return null;
175
175
  }
176
176
 
177
177
  return (
178
- <Form<PropertyType>
178
+ <Form.Root<PropertyType>
179
179
  key={field.id}
180
+ fieldMap={fieldMap}
180
181
  autoFocus
181
- values={props}
182
+ readonly={readonly}
182
183
  schema={fieldSchema}
183
- filter={propIsNotType}
184
+ values={props}
185
+ exclude={propIsNotType}
184
186
  sort={['property', 'format']}
185
187
  onValuesChanged={handleValuesChanged}
186
188
  onValidate={handleValidate}
187
189
  onSave={handleSave}
188
190
  onCancel={handleCancel}
189
- Custom={custom}
190
- outerSpacing={outerSpacing}
191
- />
191
+ >
192
+ <Form.Content>
193
+ <Form.FieldSet />
194
+ <Form.Actions />
195
+ </Form.Content>
196
+ </Form.Root>
192
197
  );
193
198
  };