@dxos/react-ui-form 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731

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 (209) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/index.mjs +2008 -840
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/translations.mjs +83 -0
  6. package/dist/lib/browser/translations.mjs.map +7 -0
  7. package/dist/lib/node-esm/index.mjs +2008 -840
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/lib/node-esm/translations.mjs +85 -0
  11. package/dist/lib/node-esm/translations.mjs.map +7 -0
  12. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
  13. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  14. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +64 -61
  15. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
  16. package/dist/types/src/components/Form/Form.d.ts +71 -17
  17. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  18. package/dist/types/src/components/Form/Form.stories.d.ts +148 -86
  19. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/Form/FormField.d.ts +24 -8
  21. package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
  22. package/dist/types/src/components/Form/FormFieldComponent.d.ts +26 -13
  23. package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
  24. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/Form/FormFieldSet.d.ts +11 -9
  26. package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
  27. package/dist/types/src/components/Form/FormTooltipsContext.d.ts +19 -0
  28. package/dist/types/src/components/Form/FormTooltipsContext.d.ts.map +1 -0
  29. package/dist/types/src/components/Form/Layout/FormLayout.d.ts +50 -0
  30. package/dist/types/src/components/Form/Layout/FormLayout.d.ts.map +1 -0
  31. package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts +119 -0
  32. package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts.map +1 -0
  33. package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts +2 -0
  34. package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts.map +1 -0
  35. package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts +2 -0
  36. package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts.map +1 -0
  37. package/dist/types/src/components/Form/Layout/annotation.d.ts +30 -0
  38. package/dist/types/src/components/Form/Layout/annotation.d.ts.map +1 -0
  39. package/dist/types/src/components/Form/Layout/index.d.ts +4 -0
  40. package/dist/types/src/components/Form/Layout/index.d.ts.map +1 -0
  41. package/dist/types/src/components/Form/Layout/parser.d.ts +31 -0
  42. package/dist/types/src/components/Form/Layout/parser.d.ts.map +1 -0
  43. package/dist/types/src/components/Form/Layout/parser.test.d.ts +2 -0
  44. package/dist/types/src/components/Form/Layout/parser.test.d.ts.map +1 -0
  45. package/dist/types/src/components/Form/fields/ArrayField.d.ts +4 -4
  46. package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
  47. package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -1
  48. package/dist/types/src/components/Form/fields/DateField.d.ts +4 -0
  49. package/dist/types/src/components/Form/fields/DateField.d.ts.map +1 -0
  50. package/dist/types/src/components/Form/fields/GeoPointField.d.ts +1 -1
  51. package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
  52. package/dist/types/src/components/Form/fields/InlineRefField.d.ts +13 -0
  53. package/dist/types/src/components/Form/fields/InlineRefField.d.ts.map +1 -0
  54. package/dist/types/src/components/Form/fields/MarkdownField.d.ts +8 -1
  55. package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -1
  56. package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +85 -0
  57. package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
  58. package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -1
  59. package/dist/types/src/components/Form/fields/RefField.d.ts +12 -6
  60. package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
  61. package/dist/types/src/components/Form/fields/SelectField.d.ts +4 -1
  62. package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
  63. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +1 -1
  64. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
  65. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +64 -61
  66. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -1
  68. package/dist/types/src/components/Form/fields/TextField.d.ts +1 -1
  69. package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -1
  70. package/dist/types/src/components/Form/fields/TupleField.d.ts +1 -1
  71. package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
  72. package/dist/types/src/components/Form/fields/index.d.ts +2 -0
  73. package/dist/types/src/components/Form/fields/index.d.ts.map +1 -1
  74. package/dist/types/src/components/Form/index.d.ts +3 -0
  75. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  76. package/dist/types/src/components/Form/meta-tags.d.ts +30 -0
  77. package/dist/types/src/components/Form/meta-tags.d.ts.map +1 -0
  78. package/dist/types/src/components/Form/meta-tags.test.d.ts +2 -0
  79. package/dist/types/src/components/Form/meta-tags.test.d.ts.map +1 -0
  80. package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +8 -0
  81. package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
  82. package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
  83. package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
  84. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +28 -6
  85. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
  86. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +64 -61
  87. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
  88. package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
  89. package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
  90. package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +128 -0
  91. package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
  92. package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
  93. package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
  94. package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
  95. package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
  96. package/dist/types/src/components/ObjectTree/ObjectTree.d.ts +9 -0
  97. package/dist/types/src/components/ObjectTree/ObjectTree.d.ts.map +1 -0
  98. package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts +87 -0
  99. package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts.map +1 -0
  100. package/dist/types/src/components/ObjectTree/index.d.ts +2 -0
  101. package/dist/types/src/components/ObjectTree/index.d.ts.map +1 -0
  102. package/dist/types/src/components/Settings/Settings.d.ts +28 -33
  103. package/dist/types/src/components/Settings/Settings.d.ts.map +1 -1
  104. package/dist/types/src/components/Settings/Settings.stories.d.ts +65 -61
  105. package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -1
  106. package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
  107. package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
  108. package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
  109. package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
  110. package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
  111. package/dist/types/src/components/Settings/SettingsSelectField.d.ts.map +1 -0
  112. package/dist/types/src/components/Settings/index.d.ts +2 -0
  113. package/dist/types/src/components/Settings/index.d.ts.map +1 -1
  114. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +9 -11
  115. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  116. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +68 -66
  117. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  118. package/dist/types/src/components/index.d.ts +3 -0
  119. package/dist/types/src/components/index.d.ts.map +1 -1
  120. package/dist/types/src/components/testing.d.ts +13 -4
  121. package/dist/types/src/components/testing.d.ts.map +1 -1
  122. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
  123. package/dist/types/src/hooks/useKeyHandler.d.ts +2 -1
  124. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -1
  125. package/dist/types/src/index.d.ts +0 -2
  126. package/dist/types/src/index.d.ts.map +1 -1
  127. package/dist/types/src/translations.d.ts +64 -61
  128. package/dist/types/src/translations.d.ts.map +1 -1
  129. package/dist/types/src/util/field-type.d.ts +19 -0
  130. package/dist/types/src/util/field-type.d.ts.map +1 -0
  131. package/dist/types/src/util/field.d.ts.map +1 -1
  132. package/dist/types/src/util/formatting.d.ts.map +1 -1
  133. package/dist/types/src/util/index.d.ts +1 -0
  134. package/dist/types/src/util/index.d.ts.map +1 -1
  135. package/dist/types/src/util/properties.d.ts +18 -1
  136. package/dist/types/src/util/properties.d.ts.map +1 -1
  137. package/dist/types/src/util/properties.test.d.ts +2 -0
  138. package/dist/types/src/util/properties.test.d.ts.map +1 -0
  139. package/dist/types/src/util/refs.d.ts +1 -0
  140. package/dist/types/src/util/refs.d.ts.map +1 -1
  141. package/dist/types/tsconfig.tsbuildinfo +1 -1
  142. package/package.json +48 -41
  143. package/src/components/FieldEditor/FieldEditor.stories.tsx +4 -4
  144. package/src/components/FieldEditor/FieldEditor.test.tsx +4 -2
  145. package/src/components/FieldEditor/FieldEditor.tsx +23 -17
  146. package/src/components/Form/AUDIT.md +17 -0
  147. package/src/components/Form/Form.stories.tsx +46 -65
  148. package/src/components/Form/Form.tsx +176 -60
  149. package/src/components/Form/FormField.tsx +107 -38
  150. package/src/components/Form/FormFieldComponent.tsx +77 -20
  151. package/src/components/Form/FormFieldSet.tsx +128 -78
  152. package/src/components/Form/FormTooltipsContext.ts +25 -0
  153. package/src/components/Form/Layout/FormLayout.stories.test.tsx +51 -0
  154. package/src/components/Form/Layout/FormLayout.stories.tsx +422 -0
  155. package/src/components/Form/Layout/FormLayout.test.ts +59 -0
  156. package/src/components/Form/Layout/FormLayout.tsx +251 -0
  157. package/src/components/Form/Layout/annotation.ts +38 -0
  158. package/src/components/Form/Layout/index.ts +7 -0
  159. package/src/components/Form/Layout/parser.test.ts +120 -0
  160. package/src/components/Form/Layout/parser.ts +167 -0
  161. package/src/components/Form/fields/ArrayField.tsx +64 -35
  162. package/src/components/Form/fields/DateField.tsx +101 -0
  163. package/src/components/Form/fields/GeoPointField.tsx +12 -8
  164. package/src/components/Form/fields/InlineRefField.tsx +146 -0
  165. package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
  166. package/src/components/Form/fields/MarkdownField.tsx +135 -45
  167. package/src/components/Form/fields/RefField.tsx +83 -42
  168. package/src/components/Form/fields/SelectField.tsx +17 -5
  169. package/src/components/Form/fields/SelectOptionField.stories.tsx +8 -6
  170. package/src/components/Form/fields/SelectOptionField.tsx +14 -13
  171. package/src/components/Form/fields/TextAreaField.tsx +1 -1
  172. package/src/components/Form/fields/TextField.tsx +2 -2
  173. package/src/components/Form/fields/TupleField.tsx +3 -2
  174. package/src/components/Form/fields/index.ts +2 -0
  175. package/src/components/Form/index.ts +3 -0
  176. package/src/components/Form/meta-tags.test.ts +47 -0
  177. package/src/components/Form/meta-tags.ts +33 -0
  178. package/src/components/ObjectForm/ObjectForm.tsx +109 -0
  179. package/src/components/ObjectForm/index.ts +5 -0
  180. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +13 -11
  181. package/src/components/ObjectPicker/ObjectPicker.tsx +93 -66
  182. package/src/components/ObjectProperties/ObjectProperties.stories.tsx +350 -0
  183. package/src/components/ObjectProperties/ObjectProperties.test.tsx +111 -0
  184. package/src/components/ObjectProperties/ObjectProperties.tsx +144 -0
  185. package/src/components/ObjectProperties/index.ts +5 -0
  186. package/src/components/ObjectTree/ObjectTree.stories.tsx +134 -0
  187. package/src/components/ObjectTree/ObjectTree.tsx +190 -0
  188. package/src/components/ObjectTree/index.ts +5 -0
  189. package/src/components/Settings/AUDIT.md +51 -0
  190. package/src/components/Settings/Settings.stories.tsx +69 -21
  191. package/src/components/Settings/Settings.tsx +32 -181
  192. package/src/components/Settings/SettingsFieldSet.tsx +257 -0
  193. package/src/components/Settings/SettingsItem.tsx +58 -0
  194. package/src/components/Settings/SettingsSelectField.tsx +59 -0
  195. package/src/components/Settings/index.ts +2 -0
  196. package/src/components/ViewEditor/ViewEditor.stories.tsx +45 -51
  197. package/src/components/ViewEditor/ViewEditor.test.tsx +11 -9
  198. package/src/components/ViewEditor/ViewEditor.tsx +45 -55
  199. package/src/components/index.ts +3 -0
  200. package/src/components/testing.tsx +19 -11
  201. package/src/hooks/useKeyHandler.tsx +7 -7
  202. package/src/index.ts +0 -4
  203. package/src/translations.ts +67 -63
  204. package/src/util/field-type.ts +60 -0
  205. package/src/util/index.ts +1 -0
  206. package/src/util/properties.test.ts +121 -0
  207. package/src/util/properties.ts +47 -4
  208. package/src/util/refs.ts +7 -3
  209. package/src/vite-env.d.ts +10 -0
@@ -17,6 +17,7 @@ export const TupleField = ({
17
17
  type,
18
18
  readonly,
19
19
  label,
20
+ jsonPath,
20
21
  getStatus,
21
22
  getValue,
22
23
  onValueChange,
@@ -31,8 +32,8 @@ export const TupleField = ({
31
32
 
32
33
  return (
33
34
  <Input.Root validationValence={status}>
34
- <FormFieldLabel error={error} readonly={readonly} label={label} />
35
- <div className={mx('grid gap-2', gridCols[binding.length - 1])}>
35
+ <FormFieldLabel error={error} readonly={readonly} label={label} path={jsonPath} />
36
+ <div className={mx('grid gap-form-gap', gridCols[binding.length - 1])}>
36
37
  {binding.map((prop) => (
37
38
  <Input.TextInput
38
39
  key={prop}
@@ -4,7 +4,9 @@
4
4
 
5
5
  export * from './ArrayField';
6
6
  export * from './BooleanField';
7
+ export * from './DateField';
7
8
  export * from './GeoPointField';
9
+ export * from './InlineRefField';
8
10
  export * from './MarkdownField';
9
11
  export * from './NumberField';
10
12
  export * from './RefField';
@@ -6,3 +6,6 @@ export * from './fields';
6
6
 
7
7
  export * from './Form';
8
8
  export * from './FormFieldComponent';
9
+ export * from './FormTooltipsContext';
10
+ export * from './meta-tags';
11
+ export * from './Layout';
@@ -0,0 +1,47 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
+ import { describe, test } from 'vitest';
8
+
9
+ import { Obj, Ref, Tag } from '@dxos/echo';
10
+
11
+ import { META_TAGS_KEY, withMetaTags } from './meta-tags';
12
+
13
+ // A feed-host schema whose own `tags` field is a `TagIndex` record (tagId -> objectId[]), not an
14
+ // array — mirrors plugin-commerce `Search`, plugin-inbox `Mailbox`, plugin-feed `Subscription`.
15
+ const TagIndexHost = Schema.Struct({
16
+ name: Schema.String.pipe(Schema.optional),
17
+ tags: Schema.Record({ key: Schema.String, value: Schema.Array(Obj.ID) }).pipe(Schema.optional),
18
+ });
19
+
20
+ const propertyNames = (schema: Schema.Schema.AnyNoContext): string[] =>
21
+ SchemaAST.getPropertySignatures(schema.ast).map((property) => property.name.toString());
22
+
23
+ describe('withMetaTags', () => {
24
+ test('keying meta-tags as `tags` collides with a schema-declared `tags` record (regression)', ({ expect }) => {
25
+ // The pre-fix shape: splice a `tags: Array<Ref<Tag>>` onto a schema that already declares `tags`.
26
+ // `Schema.extend` cannot merge an array with a record at the same key, hence the companion crash:
27
+ // "overlapping types at path: [\"tags\"]".
28
+ expect(() =>
29
+ Schema.Struct({ tags: Schema.Array(Ref.Ref(Tag.Tag)).pipe(Schema.optional) }).pipe(Schema.extend(TagIndexHost)),
30
+ ).toThrow(/tags/i);
31
+ });
32
+
33
+ test('splices meta-tags under `_tags` without colliding with a schema-declared `tags`', ({ expect }) => {
34
+ const schema = withMetaTags(TagIndexHost);
35
+ const names = propertyNames(schema);
36
+ expect(names).toContain(META_TAGS_KEY);
37
+ expect(names).toContain('tags');
38
+ expect(names).not.toContain('id');
39
+ });
40
+
41
+ test('still splices meta-tags onto a schema with no `tags` field', ({ expect }) => {
42
+ const Plain = Schema.Struct({ name: Schema.String });
43
+ const names = propertyNames(withMetaTags(Plain));
44
+ expect(names).toContain(META_TAGS_KEY);
45
+ expect(names).toContain('name');
46
+ });
47
+ });
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Ref, Tag } from '@dxos/echo';
8
+
9
+ import { omitId } from './Form';
10
+
11
+ /**
12
+ * Form-field key for the synthetic meta-tags array spliced into property/create forms.
13
+ *
14
+ * An object's tags live in `Obj.getMeta(obj).tags` (off-schema), so the form surfaces them as an
15
+ * extra field rather than reading the schema. The key is underscore-prefixed so it never collides
16
+ * with a `tags` field an object schema declares itself — e.g. a `TagIndex` record on a feed host,
17
+ * whose `tags` is `Record<tagId, objectId[]>`, not an array. Extending such a schema with a `tags`
18
+ * array threw "overlapping types at path: [\"tags\"]"; the disjoint `_tags` key avoids it. The
19
+ * human-facing label is restored via the `title` annotation on {@link withMetaTags}.
20
+ */
21
+ export const META_TAGS_KEY = '_tags';
22
+
23
+ /**
24
+ * Splices the synthetic meta-tags array (an object's `meta.tags`, surfaced as {@link Tag} refs) onto
25
+ * a schema for editing and drops `id`. Keyed by {@link META_TAGS_KEY} so it never collides with a
26
+ * `tags` field the schema declares itself.
27
+ */
28
+ export const withMetaTags = (schema: Schema.Schema.AnyNoContext) =>
29
+ omitId(
30
+ Schema.Struct({
31
+ [META_TAGS_KEY]: Schema.Array(Ref.Ref(Tag.Tag)).pipe(Schema.annotations({ title: 'Tags' }), Schema.optional),
32
+ }).pipe(Schema.extend(schema)),
33
+ );
@@ -0,0 +1,109 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useMemo } from 'react';
6
+
7
+ import { Obj, Ref, Tag, Type } from '@dxos/echo';
8
+ import { type JsonPath, splitJsonPath } from '@dxos/echo/internal';
9
+ import { invariant } from '@dxos/invariant';
10
+ import { HuePicker } from '@dxos/react-ui-pickers';
11
+
12
+ import { translationKey } from '#translations';
13
+
14
+ import { Form, type FormFieldMap, META_TAGS_KEY, withMetaTags } from '../Form';
15
+
16
+ export type ObjectFormProps = {
17
+ type: Type.AnyEntity;
18
+ object: Obj.Unknown;
19
+ };
20
+
21
+ const createFieldMap: FormFieldMap = {
22
+ hue: ({ type, label, layout, getValue, onValueChange }) => {
23
+ const handleChange = useCallback((nextHue: string) => onValueChange(type, nextHue), [onValueChange, type]);
24
+ const handleReset = useCallback(() => onValueChange(type, undefined), [onValueChange, type]);
25
+ return (
26
+ <>
27
+ {layout !== 'inline' && <Form.Label label={label} />}
28
+ <HuePicker value={getValue()} onChange={handleChange} onReset={handleReset} />
29
+ </>
30
+ );
31
+ },
32
+ };
33
+
34
+ export const ObjectForm = ({ object, type }: ObjectFormProps) => {
35
+ const db = Obj.getDatabase(object);
36
+ const meta = Obj.getMeta(object);
37
+ // `meta.tags` already holds `Ref<Tag>`s (materialized by the database handler).
38
+ const tags = [...meta.tags];
39
+ const values = useMemo(() => ({ [META_TAGS_KEY]: tags, ...object }), [object, tags]);
40
+ const formSchema = useMemo(() => withMetaTags(Type.getSchema(type)), [type]);
41
+
42
+ const handleCreate = useCallback((type: Type.AnyEntity, values: any) => {
43
+ invariant(db);
44
+ invariant(Type.isObject(type));
45
+ const newObject = db.add(Obj.make(type, values));
46
+ if (Obj.instanceOf(Tag.Tag, newObject)) {
47
+ Obj.update(object, (object) => {
48
+ Obj.getMeta(object).tags = [...Obj.getMeta(object).tags, Ref.make(newObject)];
49
+ });
50
+ }
51
+ }, []);
52
+
53
+ // TODO(wittjosiah): Use FormRootProps type.
54
+ const handleChange = useCallback(
55
+ (
56
+ { [META_TAGS_KEY]: metaTags, ...values }: any,
57
+ { isValid, changed }: { isValid: boolean; changed: Record<JsonPath, boolean> },
58
+ ) => {
59
+ if (!isValid) {
60
+ return;
61
+ }
62
+
63
+ const changedPaths = Object.keys(changed).filter((path) => changed[path as JsonPath]) as JsonPath[];
64
+
65
+ // Handle meta-tags separately using Obj.update.
66
+ const hasTagsChange = changedPaths.some((path) => splitJsonPath(path)[0] === META_TAGS_KEY);
67
+ if (hasTagsChange) {
68
+ Obj.update(object, (object) => {
69
+ // Copy so later in-place form mutations don't bypass the `Obj.update` boundary.
70
+ Obj.getMeta(object).tags = Array.isArray(metaTags) ? [...(metaTags as Ref.Ref<Tag.Tag>[])] : [];
71
+ });
72
+ }
73
+
74
+ // Handle other property changes.
75
+ const nonTagPaths = changedPaths.filter((path) => splitJsonPath(path)[0] !== META_TAGS_KEY);
76
+ if (nonTagPaths.length > 0) {
77
+ Obj.update(object, () => {
78
+ for (const path of nonTagPaths) {
79
+ const parts = splitJsonPath(path);
80
+ const value = Obj.getValue(values, parts);
81
+ Obj.setValue(object, parts, value);
82
+ }
83
+ });
84
+ }
85
+ },
86
+ [object],
87
+ );
88
+
89
+ return (
90
+ <Form.Root
91
+ schema={formSchema}
92
+ defaultValues={values}
93
+ createTypename={Type.getTypename(Tag.Tag)}
94
+ createOptionIcon='ph--plus--regular'
95
+ createOptionLabel={['add-tag.label', { ns: translationKey }]}
96
+ createInitialValuePath='label'
97
+ createFieldMap={createFieldMap}
98
+ db={db}
99
+ onValuesChanged={handleChange}
100
+ onCreate={handleCreate}
101
+ >
102
+ <Form.Viewport>
103
+ <Form.Content>
104
+ <Form.FieldSet />
105
+ </Form.Content>
106
+ </Form.Viewport>
107
+ </Form.Root>
108
+ );
109
+ };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './ObjectForm';
@@ -7,28 +7,28 @@ import * as Schema from 'effect/Schema';
7
7
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
8
8
  import { expect, fn, userEvent, within } from 'storybook/test';
9
9
 
10
- import { Obj } from '@dxos/echo';
11
- import { faker } from '@dxos/random';
12
- import { Filter, useQuery } from '@dxos/react-client/echo';
10
+ import { Filter, Obj, Type } from '@dxos/echo';
11
+ import { random } from '@dxos/random';
12
+ import { useQuery } from '@dxos/react-client/echo';
13
13
  import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
14
14
  import { Button } from '@dxos/react-ui';
15
15
  import { withTheme } from '@dxos/react-ui/testing';
16
16
  import { Person } from '@dxos/types';
17
17
  import { osTranslations } from '@dxos/ui-theme';
18
18
 
19
- import { translations } from '../../translations';
19
+ import { translations } from '#translations';
20
20
 
21
21
  import { ObjectPicker } from './ObjectPicker';
22
22
 
23
- faker.seed(1);
23
+ random.seed(1);
24
24
 
25
25
  const createPerson = () =>
26
26
  Obj.make(Person.Person, {
27
- fullName: faker.person.fullName(),
27
+ fullName: random.person.fullName(),
28
28
  });
29
29
 
30
30
  const omitId = Schema.omit<any, any, ['id']>('id');
31
- const personSchema = omitId(Person.Person);
31
+ const personSchema = omitId(Type.getSchema(Person.Person));
32
32
 
33
33
  // Mock functions for testing
34
34
  const mockHandleSelect = fn();
@@ -48,7 +48,7 @@ const DefaultStory = () => {
48
48
  }
49
49
  }, [space]);
50
50
 
51
- // Get all objects in the space (similar to BoardContainer)
51
+ // Get all objects in the space (similar to BoardArticle)
52
52
  const allObjects = useQuery(space?.db, Filter.everything());
53
53
 
54
54
  // Map objects to options format expected by ObjectPicker
@@ -65,7 +65,9 @@ const DefaultStory = () => {
65
65
  const handleCreateCallback = useCallback(
66
66
  (values: any) => {
67
67
  console.log('[on create]', values);
68
- if (!space) return;
68
+ if (!space) {
69
+ return;
70
+ }
69
71
  const newPerson = space.db.add(Obj.make(Person.Person, values));
70
72
  mockHandleCreate(values);
71
73
  return newPerson;
@@ -74,7 +76,7 @@ const DefaultStory = () => {
74
76
  );
75
77
 
76
78
  return (
77
- <div role='none' className='flex w-96'>
79
+ <div className='w-96'>
78
80
  <ObjectPicker.Root open={isOpen} onOpenChange={setIsOpen}>
79
81
  <ObjectPicker.Trigger asChild>
80
82
  <Button variant='primary' data-testid='trigger' classNames='w-full'>
@@ -85,7 +87,7 @@ const DefaultStory = () => {
85
87
  classNames='dx-card-popover-width'
86
88
  options={options}
87
89
  createSchema={personSchema}
88
- createOptionLabel={['create new person label', { ns: osTranslations }]}
90
+ createOptionLabel={['create-new-person.label', { ns: osTranslations }]}
89
91
  createOptionIcon='ph--user-plus--regular'
90
92
  createInitialValuePath='fullName'
91
93
  onCreate={handleCreateCallback}
@@ -6,10 +6,13 @@ import type * as Schema from 'effect/Schema';
6
6
  import React, { type KeyboardEvent, forwardRef, useCallback, useState } from 'react';
7
7
 
8
8
  import { type Palette, Popover, type ThemedClassName, useTranslation } from '@dxos/react-ui';
9
- import { Combobox, useSearchListInput, useSearchListResults } from '@dxos/react-ui-searchlist';
9
+ import { Combobox } from '@dxos/react-ui-list';
10
+ import { useSearchListResults } from '@dxos/react-ui-search';
11
+
12
+ import { translationKey } from '#translations';
10
13
 
11
- import { translationKey } from '../../translations';
12
14
  import { Form } from '../Form';
15
+ import { type FormFieldMap } from '../Form/FormFieldComponent';
13
16
 
14
17
  export type RefOption = {
15
18
  id: string;
@@ -20,40 +23,22 @@ export type RefOption = {
20
23
  export type ObjectPickerContentProps = ThemedClassName<{
21
24
  options: RefOption[];
22
25
  selectedIds?: string[];
23
- createOptionLabel?: [string, { ns: string }];
26
+ createOptionLabel?: [string, { ns: string | readonly string[] }];
24
27
  createOptionIcon?: string;
25
28
  createSchema?: Schema.Schema.AnyNoContext;
26
29
  createInitialValuePath?: string;
27
- onCreate?: (values: any) => void;
30
+ createFieldMap?: FormFieldMap;
31
+ /**
32
+ * Persist a newly-created object given the form values. May be async (e.g.
33
+ * to write to a database). The Promise is awaited before the inline create
34
+ * form is collapsed back to the picker list, so consumers can complete
35
+ * follow-up work (assign the new ref to a parent slot, close the popover)
36
+ * before the picker UI re-renders.
37
+ */
38
+ onCreate?: (values: any) => unknown | Promise<unknown>;
28
39
  onSelect: (id: string) => void;
29
40
  }>;
30
41
 
31
- const CreateItem = ({
32
- createOptionLabel,
33
- createOptionIcon,
34
- onCreateItemSelect,
35
- }: {
36
- createOptionLabel: [string, { ns: string }];
37
- createOptionIcon: string;
38
- onCreateItemSelect: (query: string) => void;
39
- }) => {
40
- const { t } = useTranslation(translationKey);
41
- const { query } = useSearchListInput();
42
-
43
- return (
44
- <Combobox.Item
45
- value='__create__'
46
- label={t(createOptionLabel[0], { ns: createOptionLabel[1].ns, text: query })}
47
- icon={createOptionIcon}
48
- classNames='flex items-center gap-2'
49
- closeOnSelect={false}
50
- onSelect={() => {
51
- onCreateItemSelect(query);
52
- }}
53
- />
54
- );
55
- };
56
-
57
42
  const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>(
58
43
  (
59
44
  {
@@ -63,23 +48,24 @@ const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>
63
48
  createOptionLabel,
64
49
  createOptionIcon,
65
50
  createInitialValuePath,
51
+ createFieldMap,
66
52
  onSelect,
67
53
  onCreate,
68
54
  ...props
69
55
  },
70
- ref,
56
+ forwardedRef,
71
57
  ) => {
72
58
  const { t } = useTranslation(translationKey);
73
59
  const [showForm, setShowForm] = useState(false);
74
60
  const [formInitialValue, setFormInitialValue] = useState<string>('');
75
61
 
76
- const { results, handleSearch } = useSearchListResults({
62
+ const { results, query, handleSearch } = useSearchListResults({
77
63
  items: options,
78
64
  });
79
65
 
80
66
  const handleFormSave = useCallback(
81
- (values: any) => {
82
- onCreate?.(values);
67
+ async (values: any) => {
68
+ await onCreate?.(values);
83
69
  setShowForm(false);
84
70
  setFormInitialValue('');
85
71
  },
@@ -112,14 +98,15 @@ const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>
112
98
  [createSchema],
113
99
  );
114
100
 
115
- return (
116
- <Combobox.Content {...props} ref={ref} onSearch={handleSearch} onKeyDownCapture={handleKeyDown}>
117
- {showForm && createSchema ? (
101
+ if (showForm && createSchema) {
102
+ return (
103
+ <Combobox.Content {...props} onKeyDownCapture={handleKeyDown} ref={forwardedRef}>
118
104
  <Popover.Viewport>
119
105
  <Form.Root
120
106
  testId='create-referenced-object-form'
121
107
  schema={createSchema}
122
- values={createInitialValuePath ? { [createInitialValuePath]: formInitialValue } : {}}
108
+ defaultValues={createInitialValuePath ? { [createInitialValuePath]: formInitialValue } : {}}
109
+ fieldMap={createFieldMap}
123
110
  onSave={handleFormSave}
124
111
  onCancel={handleFormCancel}
125
112
  >
@@ -131,40 +118,80 @@ const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>
131
118
  </Form.Viewport>
132
119
  </Form.Root>
133
120
  </Popover.Viewport>
134
- ) : (
135
- <>
136
- <Combobox.Input placeholder={t('ref field combobox input placeholder')} autoFocus />
137
- <Combobox.List>
138
- {results.map((option) => (
139
- <Combobox.Item
140
- key={option.id}
141
- value={option.id}
142
- label={option.label}
143
- checked={selectedIds?.includes(option.id)}
144
- onSelect={() => onSelect(option.id)}
145
- classNames='flex items-center gap-2'
146
- />
147
- ))}
148
- {createOptionLabel && createOptionIcon && createSchema && onCreate && (
149
- <CreateItem
150
- createOptionLabel={createOptionLabel}
151
- createOptionIcon={createOptionIcon}
152
- onCreateItemSelect={(query: string) => {
153
- setFormInitialValue(query);
154
- setShowForm(true);
155
- }}
156
- />
157
- )}
158
- </Combobox.List>
159
- </>
160
- )}
121
+ <Combobox.Arrow />
122
+ </Combobox.Content>
123
+ );
124
+ }
125
+
126
+ return (
127
+ <Combobox.Content {...props} onKeyDownCapture={handleKeyDown} ref={forwardedRef}>
128
+ <Combobox.Input
129
+ placeholder={t('ref-field-combobox-input.placeholder')}
130
+ autoFocus
131
+ value={query}
132
+ onValueChange={handleSearch}
133
+ />
134
+ <Combobox.List>
135
+ {results.map((option) => (
136
+ <Combobox.Item
137
+ key={option.id}
138
+ value={option.id}
139
+ label={option.label}
140
+ checked={selectedIds?.includes(option.id)}
141
+ onSelect={() => onSelect(option.id)}
142
+ classNames='flex items-center gap-2'
143
+ />
144
+ ))}
145
+ {createSchema && onCreate && (
146
+ <CreateItem
147
+ query={query}
148
+ createOptionLabel={createOptionLabel}
149
+ createOptionIcon={createOptionIcon ?? 'ph--plus--regular'}
150
+ onCreateItemSelect={(currentQuery: string) => {
151
+ setFormInitialValue(currentQuery);
152
+ setShowForm(true);
153
+ }}
154
+ />
155
+ )}
156
+ </Combobox.List>
161
157
  <Combobox.Arrow />
162
158
  </Combobox.Content>
163
159
  );
164
160
  },
165
161
  );
166
162
 
167
- ObjectPickerContent.displayName = 'ObjectPickerContent';
163
+ const CreateItem = ({
164
+ query,
165
+ createOptionLabel,
166
+ createOptionIcon,
167
+ onCreateItemSelect,
168
+ }: {
169
+ query: string;
170
+ createOptionLabel?: [string, { ns: string | readonly string[] }];
171
+ createOptionIcon: string;
172
+ onCreateItemSelect: (query: string) => void;
173
+ }) => {
174
+ const { t } = useTranslation(translationKey);
175
+
176
+ const label = createOptionLabel
177
+ ? t(createOptionLabel[0], { ns: createOptionLabel[1].ns, text: query })
178
+ : t('create-option.label');
179
+
180
+ return (
181
+ <Combobox.Item
182
+ value='__create__'
183
+ label={label}
184
+ icon={createOptionIcon}
185
+ classNames='flex items-center gap-2'
186
+ closeOnSelect={false}
187
+ onSelect={() => {
188
+ onCreateItemSelect(query);
189
+ }}
190
+ />
191
+ );
192
+ };
193
+
194
+ ObjectPickerContent.displayName = 'ObjectPicker.Content';
168
195
 
169
196
  export const ObjectPicker = {
170
197
  Root: Combobox.Root,