@dxos/react-ui-form 0.8.4-main.c4373fc → 0.8.4-main.d05539e30a

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 (234) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +0 -1
  3. package/dist/lib/browser/index.mjs +2747 -2324
  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 +82 -0
  7. package/dist/lib/browser/translations.mjs.map +7 -0
  8. package/dist/lib/node-esm/index.mjs +2747 -2324
  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 +84 -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 +68 -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 +109 -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 +114 -137
  20. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/Form/FormField.d.ts +43 -0
  22. package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
  23. package/dist/types/src/components/Form/FormFieldComponent.d.ts +79 -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 +15 -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 +11 -0
  36. package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
  37. package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +84 -0
  38. package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
  39. package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
  40. package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
  41. package/dist/types/src/components/Form/fields/RefField.d.ts +22 -0
  42. package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
  43. package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
  44. package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
  45. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
  46. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
  47. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +84 -0
  48. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
  49. package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
  50. package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
  51. package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
  52. package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
  53. package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
  54. package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
  55. package/dist/types/src/components/Form/fields/index.d.ts +12 -0
  56. package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
  57. package/dist/types/src/components/Form/index.d.ts +2 -4
  58. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  59. package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +9 -0
  60. package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
  61. package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
  62. package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
  63. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +37 -10
  64. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
  65. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +65 -59
  66. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
  68. package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
  69. package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +127 -0
  70. package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
  72. package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
  73. package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
  74. package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
  75. package/dist/types/src/components/Settings/Settings.d.ts +51 -0
  76. package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
  77. package/dist/types/src/components/Settings/Settings.stories.d.ts +84 -0
  78. package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
  80. package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
  81. package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
  82. package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
  83. package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
  84. package/dist/types/src/components/Settings/SettingsSelectField.d.ts.map +1 -0
  85. package/dist/types/src/components/Settings/index.d.ts +4 -0
  86. package/dist/types/src/components/Settings/index.d.ts.map +1 -0
  87. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +15 -16
  88. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  89. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +70 -64
  90. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  91. package/dist/types/src/components/index.d.ts +3 -1
  92. package/dist/types/src/components/index.d.ts.map +1 -1
  93. package/dist/types/src/components/testing.d.ts +4 -6
  94. package/dist/types/src/components/testing.d.ts.map +1 -1
  95. package/dist/types/src/hooks/index.d.ts +2 -3
  96. package/dist/types/src/hooks/index.d.ts.map +1 -1
  97. package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
  98. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
  99. package/dist/types/src/hooks/useKeyHandler.d.ts +7 -0
  100. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
  101. package/dist/types/src/index.d.ts +0 -2
  102. package/dist/types/src/index.d.ts.map +1 -1
  103. package/dist/types/src/translations.d.ts +65 -60
  104. package/dist/types/src/translations.d.ts.map +1 -1
  105. package/dist/types/src/util/field-type.d.ts +19 -0
  106. package/dist/types/src/util/field-type.d.ts.map +1 -0
  107. package/dist/types/src/util/field.d.ts +3 -3
  108. package/dist/types/src/util/field.d.ts.map +1 -1
  109. package/dist/types/src/util/formatting.d.ts +2 -2
  110. package/dist/types/src/util/formatting.d.ts.map +1 -1
  111. package/dist/types/src/util/index.d.ts +2 -1
  112. package/dist/types/src/util/index.d.ts.map +1 -1
  113. package/dist/types/src/util/properties.d.ts +13 -0
  114. package/dist/types/src/util/properties.d.ts.map +1 -0
  115. package/dist/types/src/util/properties.test.d.ts +2 -0
  116. package/dist/types/src/util/properties.test.d.ts.map +1 -0
  117. package/dist/types/src/util/refs.d.ts +2 -2
  118. package/dist/types/src/util/refs.d.ts.map +1 -1
  119. package/dist/types/tsconfig.tsbuildinfo +1 -1
  120. package/package.json +57 -51
  121. package/src/components/FieldEditor/FieldEditor.stories.tsx +44 -25
  122. package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
  123. package/src/components/FieldEditor/FieldEditor.tsx +76 -79
  124. package/src/components/Form/AUDIT.md +17 -0
  125. package/src/components/Form/Form.stories.tsx +139 -251
  126. package/src/components/Form/Form.tsx +375 -106
  127. package/src/components/Form/FormField.tsx +306 -0
  128. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  129. package/src/components/Form/FormFieldComponent.tsx +174 -0
  130. package/src/components/Form/FormFieldSet.tsx +144 -0
  131. package/src/components/Form/README.md +3 -0
  132. package/src/components/Form/fields/ArrayField.tsx +155 -0
  133. package/src/components/Form/fields/BooleanField.tsx +22 -0
  134. package/src/components/Form/fields/GeoPointField.tsx +121 -0
  135. package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
  136. package/src/components/Form/fields/MarkdownField.tsx +168 -0
  137. package/src/components/Form/fields/NumberField.tsx +39 -0
  138. package/src/components/Form/fields/RefField.tsx +229 -0
  139. package/src/components/Form/fields/SelectField.tsx +65 -0
  140. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +23 -18
  141. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +30 -24
  142. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  143. package/src/components/Form/fields/TextField.tsx +38 -0
  144. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +16 -9
  145. package/src/components/Form/fields/index.ts +15 -0
  146. package/src/components/Form/index.ts +3 -4
  147. package/src/components/ObjectForm/ObjectForm.tsx +114 -0
  148. package/src/components/{ControlSection → ObjectForm}/index.ts +1 -1
  149. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +50 -45
  150. package/src/components/ObjectPicker/ObjectPicker.tsx +127 -86
  151. package/src/components/ObjectProperties/ObjectProperties.stories.tsx +362 -0
  152. package/src/components/ObjectProperties/ObjectProperties.test.tsx +101 -0
  153. package/src/components/ObjectProperties/ObjectProperties.tsx +148 -0
  154. package/src/components/ObjectProperties/index.ts +5 -0
  155. package/src/components/Settings/AUDIT.md +51 -0
  156. package/src/components/Settings/Settings.stories.tsx +104 -0
  157. package/src/components/Settings/Settings.tsx +80 -0
  158. package/src/components/Settings/SettingsFieldSet.tsx +257 -0
  159. package/src/components/Settings/SettingsItem.tsx +58 -0
  160. package/src/components/Settings/SettingsSelectField.tsx +59 -0
  161. package/src/components/Settings/index.ts +7 -0
  162. package/src/components/ViewEditor/ViewEditor.stories.tsx +73 -54
  163. package/src/components/ViewEditor/ViewEditor.test.tsx +8 -7
  164. package/src/components/ViewEditor/ViewEditor.tsx +304 -269
  165. package/src/components/index.ts +3 -1
  166. package/src/components/testing.tsx +24 -11
  167. package/src/hooks/index.ts +2 -3
  168. package/src/hooks/useFormHandler.ts +380 -0
  169. package/src/hooks/useKeyHandler.tsx +37 -0
  170. package/src/index.ts +0 -4
  171. package/src/translations.ts +70 -65
  172. package/src/util/field-type.ts +60 -0
  173. package/src/util/field.ts +25 -25
  174. package/src/util/formatting.ts +22 -22
  175. package/src/util/index.ts +2 -1
  176. package/src/util/properties.test.ts +63 -0
  177. package/src/util/properties.ts +29 -0
  178. package/src/util/refs.ts +16 -18
  179. package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
  180. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
  181. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -84
  182. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
  183. package/dist/types/src/components/ControlSection/index.d.ts +0 -2
  184. package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
  185. package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
  186. package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
  187. package/dist/types/src/components/Form/Defaults.d.ts +0 -14
  188. package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
  189. package/dist/types/src/components/Form/FormActions.d.ts +0 -9
  190. package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
  191. package/dist/types/src/components/Form/FormContent.d.ts +0 -63
  192. package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
  193. package/dist/types/src/components/Form/FormContext.d.ts +0 -23
  194. package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
  195. package/dist/types/src/components/Form/Input.d.ts +0 -29
  196. package/dist/types/src/components/Form/Input.d.ts.map +0 -1
  197. package/dist/types/src/components/Form/RefField.d.ts +0 -21
  198. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  199. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
  200. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
  201. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
  202. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
  203. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -79
  204. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
  205. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  206. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  207. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  208. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  209. package/dist/types/src/components/Form/factory.d.ts +0 -8
  210. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  211. package/dist/types/src/hooks/useForm.d.ts +0 -67
  212. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  213. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -28
  214. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  215. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  216. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  217. package/dist/types/src/util/schema.d.ts +0 -3
  218. package/dist/types/src/util/schema.d.ts.map +0 -1
  219. package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
  220. package/src/components/ControlSection/ControlSection.tsx +0 -153
  221. package/src/components/Form/ArrayField.tsx +0 -125
  222. package/src/components/Form/Defaults.tsx +0 -205
  223. package/src/components/Form/FormActions.tsx +0 -54
  224. package/src/components/Form/FormContent.tsx +0 -322
  225. package/src/components/Form/FormContext.tsx +0 -110
  226. package/src/components/Form/Input.tsx +0 -54
  227. package/src/components/Form/RefField.tsx +0 -269
  228. package/src/components/Form/custom/GeoPointInput.tsx +0 -80
  229. package/src/components/Form/custom/index.ts +0 -7
  230. package/src/components/Form/factory.tsx +0 -31
  231. package/src/hooks/useForm.ts +0 -295
  232. package/src/hooks/useQueryRefOptions.ts +0 -59
  233. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  234. package/src/util/schema.ts +0 -12
@@ -1,125 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Function from 'effect/Function';
6
- import * as SchemaAST from 'effect/SchemaAST';
7
- import * as String from 'effect/String';
8
- import React, { Fragment, useCallback } from 'react';
9
-
10
- import { SimpleType, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
11
- import { invariant } from '@dxos/invariant';
12
- import { IconButton, useTranslation } from '@dxos/react-ui';
13
- import { type SchemaProperty, getSchemaProperties } from '@dxos/schema';
14
-
15
- import { translationKey } from '../../translations';
16
- import { findArrayElementType } from '../../util';
17
-
18
- import { type ComponentLookup } from './Form';
19
- import { FormField, type FormFieldProps } from './FormContent';
20
- import { type FormInputStateProps, useFormValues } from './FormContext';
21
- import { type InputComponent, InputHeader } from './Input';
22
-
23
- type ArrayFieldProps = {
24
- property: SchemaProperty<any>;
25
- inputProps: FormInputStateProps;
26
- path?: (string | number)[];
27
- Custom?: Partial<Record<string, InputComponent>>;
28
- lookupComponent?: ComponentLookup;
29
- } & Pick<FormFieldProps, 'readonly'>;
30
-
31
- export const ArrayField = ({ property, readonly, path, inputProps, Custom, lookupComponent }: ArrayFieldProps) => {
32
- const { t } = useTranslation(translationKey);
33
- const { ast, name, type, title } = property;
34
- // TODO(wittjosiah): The fallback to an empty array stops the form from crashing but isn't immediately live.
35
- // It doesn't become live until another field is touched, but that's better than the whole form crashing.
36
- const values = (useFormValues(path ?? []) ?? []) as any[];
37
- invariant(Array.isArray(values), `Values at path ${path?.join('.')} must be an array.`);
38
- const label = title ?? Function.pipe(name, String.capitalize);
39
-
40
- const elementType = findArrayElementType(ast);
41
-
42
- const getDefaultObjectValue = (typeNode: SchemaAST.AST): any => {
43
- const baseNode = findNode(typeNode, isDiscriminatedUnion);
44
- const typeLiteral = baseNode ? getDiscriminatedType(baseNode, {}) : findNode(typeNode, SchemaAST.isTypeLiteral);
45
- if (!typeLiteral) {
46
- return {};
47
- }
48
-
49
- return Object.fromEntries(getSchemaProperties(typeLiteral, {}).map((prop) => [prop.name, prop.defaultValue]));
50
- };
51
-
52
- const getDefaultValue = () =>
53
- type === 'object' && elementType ? getDefaultObjectValue(elementType) : SimpleType.getDefaultValue(type);
54
-
55
- const handleAdd = useCallback(() => {
56
- inputProps.onValueChange(type, [...values, getDefaultValue()]);
57
- }, [type, elementType, inputProps, values]);
58
-
59
- const handleRemove = useCallback(
60
- (index: number) => {
61
- const newValues = values.filter((_, i) => i !== index);
62
- inputProps.onValueChange(type, newValues);
63
- },
64
- [type, inputProps, values],
65
- );
66
-
67
- if (!elementType) {
68
- return null;
69
- }
70
-
71
- return readonly && values.length < 1 ? null : (
72
- <>
73
- <InputHeader readonly label={label} />
74
- <div
75
- role='none'
76
- className={
77
- readonly
78
- ? 'flex flex-wrap gap-1 mlb-1'
79
- : values.length > 0
80
- ? 'grid gap-1 grid-cols-[1fr_min-content] mlb-1'
81
- : 'hidden'
82
- }
83
- >
84
- {values.map((_value, index) => {
85
- const field = (
86
- <FormField
87
- property={{
88
- ...property,
89
- array: false, // NOTE(ZaymonFC): This breaks arrays of arrays but ¯\_(ツ)_/¯. Ping me if you need that.
90
- ast: elementType,
91
- }}
92
- path={[...(path ?? []), index]}
93
- readonly={readonly}
94
- inline
95
- Custom={Custom}
96
- lookupComponent={lookupComponent}
97
- />
98
- );
99
- return readonly ? (
100
- field
101
- ) : (
102
- <Fragment key={index}>
103
- <div role='none'>{field}</div>
104
- <IconButton
105
- icon='ph--trash--regular'
106
- iconOnly
107
- label={t('button remove')}
108
- onClick={() => handleRemove(index)}
109
- classNames='self-center'
110
- />
111
- </Fragment>
112
- );
113
- })}
114
- </div>
115
- {!readonly && (
116
- <IconButton
117
- classNames='is-full mlb-cardSpacingBlock flex'
118
- icon='ph--plus--regular'
119
- label={t('add field')}
120
- onClick={handleAdd}
121
- />
122
- )}
123
- </>
124
- );
125
- };
@@ -1,205 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import React, { useCallback, useEffect, useRef } from 'react';
6
-
7
- import { Input, Select, useTranslation } from '@dxos/react-ui';
8
-
9
- import { translationKey } from '../../translations';
10
-
11
- import { InputHeader, type InputProps } from './Input';
12
-
13
- export const TextInput = ({
14
- type,
15
- label,
16
- inputOnly,
17
- readonly,
18
- placeholder,
19
- getStatus,
20
- getValue,
21
- onValueChange,
22
- onBlur,
23
- }: InputProps) => {
24
- const { status, error } = getStatus();
25
-
26
- return readonly && !getValue() ? null : readonly === 'static' && inputOnly ? (
27
- <p>{getValue() ?? ''}</p>
28
- ) : (
29
- <Input.Root validationValence={status}>
30
- {!inputOnly && <InputHeader error={error} label={label} />}
31
- {readonly === 'static' ? (
32
- <p>{getValue() ?? ''}</p>
33
- ) : (
34
- <Input.TextInput
35
- disabled={!!readonly}
36
- placeholder={placeholder}
37
- value={getValue() ?? ''}
38
- onChange={(event) => onValueChange(type, event.target.value)}
39
- onBlur={onBlur}
40
- />
41
- )}
42
- {inputOnly && <Input.Validation>{error}</Input.Validation>}
43
- </Input.Root>
44
- );
45
- };
46
-
47
- export const NumberInput = ({
48
- type,
49
- label,
50
- inputOnly,
51
- readonly,
52
- placeholder,
53
- getStatus,
54
- getValue,
55
- onValueChange,
56
- onBlur,
57
- }: InputProps) => {
58
- const { status, error } = getStatus();
59
-
60
- return readonly && !getValue() ? null : readonly === 'static' && inputOnly ? (
61
- <p>{getValue() ?? ''}</p>
62
- ) : (
63
- <Input.Root validationValence={status}>
64
- {!inputOnly && <InputHeader error={error} label={label} />}
65
- {readonly === 'static' ? (
66
- <p>{getValue() ?? ''}</p>
67
- ) : (
68
- <Input.TextInput
69
- type='number'
70
- disabled={!!readonly}
71
- placeholder={placeholder}
72
- value={getValue()}
73
- onChange={(event) => onValueChange(type, event.target.value)}
74
- onBlur={onBlur}
75
- />
76
- )}
77
- {inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
78
- </Input.Root>
79
- );
80
- };
81
-
82
- export const BooleanInput = ({ type, label, inputOnly, getStatus, getValue, onValueChange, readonly }: InputProps) => {
83
- const { status, error } = getStatus();
84
- const checked = Boolean(getValue());
85
- const { t } = useTranslation(translationKey);
86
-
87
- return (
88
- <Input.Root validationValence={status}>
89
- {!inputOnly && <InputHeader error={error} label={label} />}
90
- {readonly === 'static' ? (
91
- <p>{t(checked ? 'boolean input true value' : 'boolean input false value')}</p>
92
- ) : (
93
- <Input.Switch disabled={!!readonly} checked={checked} onCheckedChange={(value) => onValueChange(type, value)} />
94
- )}
95
- {inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
96
- </Input.Root>
97
- );
98
- };
99
-
100
- export type SelectInputOptions = InputProps & {
101
- options?: Array<{ value: string | number; label?: string }>;
102
- };
103
-
104
- export const SelectInput = ({
105
- type,
106
- label,
107
- inputOnly,
108
- readonly,
109
- placeholder,
110
- options,
111
- getStatus,
112
- getValue,
113
- onValueChange,
114
- }: SelectInputOptions) => {
115
- const { status, error } = getStatus();
116
-
117
- const value = getValue() as string | undefined;
118
- const handleValueChange = useCallback((value: string | number) => onValueChange(type, value), [type, onValueChange]);
119
-
120
- return readonly && !value ? null : (
121
- <Input.Root validationValence={status}>
122
- {!inputOnly && <InputHeader error={error} label={label} />}
123
- {readonly === 'static' ? (
124
- <p>{options?.find(({ value: optionValue }) => optionValue === value)?.label ?? String(value)}</p>
125
- ) : (
126
- <Select.Root value={value} onValueChange={handleValueChange}>
127
- {/* TODO(burdon): Placeholder not working? */}
128
- <Select.TriggerButton classNames='is-full' disabled={!!readonly} placeholder={placeholder} />
129
- <Select.Portal>
130
- <Select.Content>
131
- <Select.Viewport>
132
- {options?.map(({ value, label }) => (
133
- // NOTE: Numeric values are converted to and from strings.
134
- <Select.Option key={String(value)} value={String(value)}>
135
- {label ?? String(value)}
136
- </Select.Option>
137
- ))}
138
- </Select.Viewport>
139
- <Select.Arrow />
140
- </Select.Content>
141
- </Select.Portal>
142
- </Select.Root>
143
- )}
144
- {inputOnly && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
145
- </Input.Root>
146
- );
147
- };
148
-
149
- export const MarkdownInput = ({
150
- type,
151
- label,
152
- inputOnly,
153
- readonly,
154
- placeholder,
155
- getStatus,
156
- getValue,
157
- onValueChange,
158
- onBlur,
159
- }: InputProps) => {
160
- const { status, error } = getStatus();
161
- const textareaRef = useRef<HTMLTextAreaElement>(null);
162
-
163
- // TODO(ZaymonFC): If we start using `Enter` for form submission, we should prevent default behavior here
164
- // since we're using a textarea element and the user needs to be able to enter new lines.
165
-
166
- const adjustHeight = useCallback(() => {
167
- const textarea = textareaRef.current;
168
- if (textarea) {
169
- textarea.style.blockSize = 'auto'; // For measurement.
170
- textarea.style.blockSize = `${textarea.scrollHeight + 2}px`;
171
- }
172
- }, []);
173
-
174
- // Adjust height on initial render.
175
- useEffect(() => {
176
- adjustHeight();
177
- }, [adjustHeight]);
178
-
179
- // Adjust height when the content changes.
180
- useEffect(() => {
181
- adjustHeight();
182
- }, [getValue(), adjustHeight]);
183
-
184
- return (
185
- <Input.Root validationValence={status}>
186
- {!inputOnly && <InputHeader error={error} label={label} />}
187
- {readonly === 'static' ? (
188
- <p>{getValue() ?? ''}</p>
189
- ) : (
190
- <Input.TextArea
191
- ref={textareaRef}
192
- disabled={!!readonly}
193
- placeholder={placeholder}
194
- value={getValue() ?? ''}
195
- classNames={'min-bs-auto max-h-40 overflow-auto'}
196
- onChange={(event) => onValueChange(type, event.target.value)}
197
- onBlur={onBlur}
198
- style={{ resize: 'none' }}
199
- spellCheck={false}
200
- />
201
- )}
202
- {inputOnly && <Input.Validation>{error}</Input.Validation>}
203
- </Input.Root>
204
- );
205
- };
@@ -1,54 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import React from 'react';
6
-
7
- import { IconButton, useTranslation } from '@dxos/react-ui';
8
- import { cardSpacing } from '@dxos/react-ui-stack';
9
- import { mx } from '@dxos/react-ui-theme';
10
-
11
- import { translationKey } from '../../translations';
12
-
13
- import { useFormContext } from './FormContext';
14
-
15
- export type FormOuterSpacing = boolean | 'blockStart-0' | 'scroll-fields';
16
-
17
- export type FormActionsProps = {
18
- readonly?: boolean;
19
- onCancel?: () => void;
20
- outerSpacing?: FormOuterSpacing;
21
- };
22
-
23
- export const FormActions = ({ readonly, onCancel, outerSpacing = true }: FormActionsProps) => {
24
- const { t } = useTranslation(translationKey);
25
- const { canSave, handleSave } = useFormContext();
26
-
27
- return (
28
- <div
29
- role='none'
30
- className={mx(
31
- outerSpacing === 'scroll-fields'
32
- ? 'pli-cardSpacingInline mbe-cardSpacingBlock'
33
- : outerSpacing
34
- ? cardSpacing
35
- : 'mbs-cardSpacingBlock',
36
- 'flex [&_button]:grow gap-1 first:mbs-0',
37
- )}
38
- >
39
- {onCancel && !readonly && (
40
- <IconButton data-testid='cancel-button' icon='ph--x--regular' label={t('button cancel')} onClick={onCancel} />
41
- )}
42
- {handleSave && (
43
- <IconButton
44
- type='submit'
45
- data-testid='save-button'
46
- disabled={!canSave}
47
- icon='ph--check--regular'
48
- label={t('button save')}
49
- onClick={handleSave}
50
- />
51
- )}
52
- </div>
53
- );
54
- };
@@ -1,322 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Function from 'effect/Function';
6
- import * as Schema from 'effect/Schema';
7
- import * as SchemaAST from 'effect/SchemaAST';
8
- import * as StringEffect from 'effect/String';
9
- import React, { forwardRef, useMemo } from 'react';
10
-
11
- import { createJsonPath, findNode, getDiscriminatedType, isDiscriminatedUnion } from '@dxos/effect';
12
- import { type ThemedClassName } from '@dxos/react-ui';
13
- import { mx } from '@dxos/react-ui-theme';
14
- import { type ProjectionModel, type SchemaProperty, getSchemaProperties } from '@dxos/schema';
15
- import { isTruthy } from '@dxos/util';
16
-
17
- import { type QueryRefOptions } from '../../hooks';
18
- import { getRefProps } from '../../util';
19
-
20
- import { ArrayField } from './ArrayField';
21
- import { SelectInput } from './Defaults';
22
- import { getInputComponent } from './factory';
23
- import { type ComponentLookup } from './Form';
24
- import { useFormValues, useInputProps } from './FormContext';
25
- import { type InputComponent } from './Input';
26
- import { RefField, type RefFieldProps } from './RefField';
27
-
28
- export type FormFieldProps = {
29
- property: SchemaProperty<any>;
30
- path?: (string | number)[];
31
- /** Used to indicate if input should be presented inline (e.g. for array items). */
32
- inline?: boolean;
33
- projection?: ProjectionModel;
34
- lookupComponent?: ComponentLookup;
35
- Custom?: Partial<Record<string, InputComponent>>;
36
- } & Pick<
37
- RefFieldProps,
38
- | 'readonly'
39
- | 'onQueryRefOptions'
40
- | 'createOptionLabel'
41
- | 'createOptionIcon'
42
- | 'onCreate'
43
- | 'createSchema'
44
- | 'createInitialValuePath'
45
- >;
46
-
47
- export const FormField = ({
48
- property,
49
- path,
50
- readonly,
51
- inline,
52
- projection,
53
- onQueryRefOptions,
54
- createOptionLabel,
55
- createOptionIcon,
56
- onCreate,
57
- createSchema,
58
- createInitialValuePath,
59
- lookupComponent,
60
- Custom,
61
- }: FormFieldProps) => {
62
- const { ast, name, type, format, title, description, options, examples, array } = property;
63
- const inputProps = useInputProps(path);
64
-
65
- const label = useMemo(() => title ?? Function.pipe(name, StringEffect.capitalize), [title, name]);
66
- const placeholder = useMemo(
67
- () => (examples?.length ? `Example: "${examples[0]}"` : description),
68
- [examples, description],
69
- );
70
-
71
- //
72
- // Registry and Custom.
73
- //
74
-
75
- const FoundComponent = lookupComponent?.({
76
- prop: name,
77
- schema: Schema.make(ast),
78
- inputProps: {
79
- type,
80
- format,
81
- label,
82
- readonly,
83
- placeholder,
84
- ...inputProps,
85
- },
86
- });
87
-
88
- if (FoundComponent) {
89
- return FoundComponent;
90
- }
91
-
92
- const jsonPath = createJsonPath(path ?? []);
93
- const CustomComponent = Custom?.[jsonPath];
94
- if (CustomComponent) {
95
- return (
96
- <CustomComponent
97
- type={type}
98
- format={format}
99
- label={label}
100
- inputOnly={inline}
101
- placeholder={placeholder}
102
- readonly={readonly}
103
- {...inputProps}
104
- />
105
- );
106
- }
107
-
108
- //
109
- // Refs.
110
- //
111
-
112
- const refProps = getRefProps(property);
113
- if (refProps) {
114
- return (
115
- <RefField
116
- ast={refProps.ast}
117
- array={refProps.isArray}
118
- type={type}
119
- format={format}
120
- label={label}
121
- placeholder={placeholder}
122
- readonly={readonly}
123
- inputOnly={inline}
124
- onQueryRefOptions={onQueryRefOptions}
125
- createOptionLabel={createOptionLabel}
126
- createOptionIcon={createOptionIcon}
127
- onCreate={onCreate}
128
- createSchema={createSchema}
129
- createInitialValuePath={createInitialValuePath}
130
- {...inputProps}
131
- />
132
- );
133
- }
134
-
135
- //
136
- // Arrays.
137
- //
138
-
139
- if (array) {
140
- return <ArrayField property={property} path={path} inputProps={inputProps} readonly={readonly} Custom={Custom} />;
141
- }
142
-
143
- //
144
- // Standard Inputs.
145
- //
146
-
147
- const InputComponent = getInputComponent(type, format);
148
- if (InputComponent) {
149
- return (
150
- <InputComponent
151
- type={type}
152
- format={format}
153
- label={label}
154
- inputOnly={inline}
155
- placeholder={placeholder}
156
- readonly={readonly}
157
- {...inputProps}
158
- />
159
- );
160
- }
161
-
162
- //
163
- // Select.
164
- //
165
-
166
- if (options) {
167
- return (
168
- <SelectInput
169
- type={type}
170
- format={format}
171
- readonly={readonly}
172
- inputOnly={inline}
173
- label={label}
174
- options={options.map((option) => ({ value: option, label: String(option) }))}
175
- placeholder={placeholder}
176
- {...inputProps}
177
- />
178
- );
179
- }
180
-
181
- //
182
- // Nested Objects.
183
- //
184
-
185
- if (type === 'object') {
186
- const baseNode = findNode(ast, isDiscriminatedUnion);
187
- const typeLiteral = baseNode
188
- ? getDiscriminatedType(baseNode, inputProps.getValue() as any)
189
- : findNode(ast, SchemaAST.isTypeLiteral);
190
-
191
- if (typeLiteral) {
192
- return (
193
- <>
194
- {!inline && <h3 className={mx('text-lg mlb-inputSpacingBlock first:mbs-0')}>{label}</h3>}
195
- <FormFields
196
- schema={Schema.make(typeLiteral)}
197
- path={path}
198
- readonly={readonly}
199
- projection={projection}
200
- onQueryRefOptions={onQueryRefOptions}
201
- createOptionLabel={createOptionLabel}
202
- createOptionIcon={createOptionIcon}
203
- onCreate={onCreate}
204
- Custom={Custom}
205
- lookupComponent={lookupComponent}
206
- />
207
- </>
208
- );
209
- }
210
- }
211
-
212
- return null;
213
- };
214
-
215
- export type FormFieldsProps = ThemedClassName<
216
- {
217
- testId?: string;
218
- schema: Schema.Schema.All;
219
- /**
220
- * Path to the current object from the root. Used with nested forms.
221
- */
222
- path?: (string | number)[];
223
- filter?: (props: SchemaProperty<any>[]) => SchemaProperty<any>[];
224
- sort?: string[];
225
- /**
226
- * Optional projection for projection-based field management
227
- */
228
- projection?: ProjectionModel;
229
- lookupComponent?: ComponentLookup;
230
- /**
231
- * Map of custom renderers for specific properties.
232
- * Prefer lookupComponent for plugin specific input surfaces.
233
- */
234
- Custom?: Partial<Record<string, InputComponent>>;
235
- onQueryRefOptions?: QueryRefOptions;
236
- } & Pick<FormFieldProps, 'readonly'> &
237
- Pick<
238
- RefFieldProps,
239
- | 'onQueryRefOptions'
240
- | 'createOptionLabel'
241
- | 'createOptionIcon'
242
- | 'onCreate'
243
- | 'createSchema'
244
- | 'createInitialValuePath'
245
- >
246
- >;
247
-
248
- export const FormFields = forwardRef<HTMLDivElement, FormFieldsProps>(
249
- (
250
- {
251
- classNames,
252
- schema,
253
- path,
254
- filter,
255
- sort,
256
- projection,
257
- readonly,
258
- lookupComponent,
259
- Custom,
260
- onQueryRefOptions,
261
- ...props
262
- },
263
- forwardRef,
264
- ) => {
265
- const values = useFormValues(path);
266
- const properties = useMemo(() => {
267
- const props = getSchemaProperties(schema.ast, values);
268
-
269
- // Use projection-based field management when view and projection are available
270
- if (projection) {
271
- const fieldProjections = projection.getFieldProjections();
272
- const hiddenProperties = new Set(projection.getHiddenProperties());
273
-
274
- // Filter properties to only include visible ones and order by projection
275
- const visibleProps = props.filter((prop) => !hiddenProperties.has(prop.name));
276
- const orderedProps: SchemaProperty<any>[] = [];
277
-
278
- // Add properties in projection field order
279
- for (const fieldProjection of fieldProjections) {
280
- const fieldPath = String(fieldProjection.field.path);
281
- const prop = visibleProps.find((p) => p.name === fieldPath);
282
- if (prop) {
283
- orderedProps.push(prop);
284
- }
285
- }
286
-
287
- // Add any remaining properties not in projection
288
- const projectionPaths = new Set(fieldProjections.map((fp) => String(fp.field.path)));
289
- const remainingProps = visibleProps.filter((prop) => !projectionPaths.has(prop.name));
290
- orderedProps.push(...remainingProps);
291
-
292
- return orderedProps;
293
- }
294
-
295
- // Fallback to legacy filter/sort behavior
296
- const filtered = filter ? filter(props) : props;
297
- return sort ? filtered.sort((a, b) => sort.indexOf(a.name) - sort.indexOf(b.name)) : filtered;
298
- }, [schema, values, filter, sort, projection?.fields]);
299
-
300
- return (
301
- <div role='form' className={mx('is-full', classNames)} ref={forwardRef}>
302
- {properties
303
- .map((property) => {
304
- return (
305
- <FormField
306
- key={property.name}
307
- property={property}
308
- path={[...(path ?? []), property.name]}
309
- readonly={readonly}
310
- projection={projection}
311
- onQueryRefOptions={onQueryRefOptions}
312
- lookupComponent={lookupComponent}
313
- Custom={Custom}
314
- {...props}
315
- />
316
- );
317
- })
318
- .filter(isTruthy)}
319
- </div>
320
- );
321
- },
322
- );