@dxos/react-ui-form 0.8.4-main.70d3990 → 0.8.4-main.74a063c4e0

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 (183) hide show
  1. package/README.md +0 -1
  2. package/dist/lib/browser/index.mjs +2319 -2347
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/node-esm/index.mjs +2319 -2347
  6. package/dist/lib/node-esm/index.mjs.map +4 -4
  7. package/dist/lib/node-esm/meta.json +1 -1
  8. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +8 -7
  9. package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
  10. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +66 -60
  11. package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
  12. package/dist/types/src/components/Form/Form.d.ts +87 -27
  13. package/dist/types/src/components/Form/Form.d.ts.map +1 -1
  14. package/dist/types/src/components/Form/Form.stories.d.ts +111 -150
  15. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
  16. package/dist/types/src/components/Form/FormField.d.ts +43 -0
  17. package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
  18. package/dist/types/src/components/Form/FormFieldComponent.d.ts +77 -0
  19. package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
  20. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
  21. package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
  22. package/dist/types/src/components/Form/FormFieldSet.d.ts +18 -0
  23. package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
  24. package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
  25. package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
  26. package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
  27. package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
  28. package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
  29. package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
  30. package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
  31. package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
  32. package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
  33. package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
  34. package/dist/types/src/components/Form/fields/RefField.d.ts +16 -0
  35. package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
  36. package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
  37. package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
  38. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
  39. package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
  40. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +82 -0
  41. package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
  42. package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
  43. package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
  44. package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
  45. package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
  46. package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
  47. package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
  48. package/dist/types/src/components/Form/fields/index.d.ts +12 -0
  49. package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
  50. package/dist/types/src/components/Form/index.d.ts +2 -4
  51. package/dist/types/src/components/Form/index.d.ts.map +1 -1
  52. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +23 -10
  53. package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
  54. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +62 -59
  55. package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
  56. package/dist/types/src/components/Settings/Settings.d.ts +39 -0
  57. package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
  58. package/dist/types/src/components/Settings/Settings.stories.d.ts +81 -0
  59. package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
  60. package/dist/types/src/components/Settings/index.d.ts +2 -0
  61. package/dist/types/src/components/Settings/index.d.ts.map +1 -0
  62. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +9 -11
  63. package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
  64. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +66 -62
  65. package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
  66. package/dist/types/src/components/index.d.ts +1 -1
  67. package/dist/types/src/components/index.d.ts.map +1 -1
  68. package/dist/types/src/components/testing.d.ts +0 -2
  69. package/dist/types/src/components/testing.d.ts.map +1 -1
  70. package/dist/types/src/hooks/index.d.ts +2 -3
  71. package/dist/types/src/hooks/index.d.ts.map +1 -1
  72. package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
  73. package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
  74. package/dist/types/src/hooks/useKeyHandler.d.ts +7 -0
  75. package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
  76. package/dist/types/src/translations.d.ts +63 -60
  77. package/dist/types/src/translations.d.ts.map +1 -1
  78. package/dist/types/src/util/index.d.ts +1 -1
  79. package/dist/types/src/util/index.d.ts.map +1 -1
  80. package/dist/types/src/util/properties.d.ts +7 -0
  81. package/dist/types/src/util/properties.d.ts.map +1 -0
  82. package/dist/types/src/util/refs.d.ts +2 -2
  83. package/dist/types/src/util/refs.d.ts.map +1 -1
  84. package/dist/types/tsconfig.tsbuildinfo +1 -1
  85. package/package.json +51 -48
  86. package/src/components/FieldEditor/FieldEditor.stories.tsx +43 -25
  87. package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
  88. package/src/components/FieldEditor/FieldEditor.tsx +73 -77
  89. package/src/components/Form/AUDIT.md +17 -0
  90. package/src/components/Form/Form.stories.tsx +147 -249
  91. package/src/components/Form/Form.tsx +324 -110
  92. package/src/components/Form/FormField.tsx +304 -0
  93. package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
  94. package/src/components/Form/FormFieldComponent.tsx +171 -0
  95. package/src/components/Form/FormFieldSet.tsx +128 -0
  96. package/src/components/Form/README.md +3 -0
  97. package/src/components/Form/fields/ArrayField.tsx +154 -0
  98. package/src/components/Form/fields/BooleanField.tsx +22 -0
  99. package/src/components/Form/fields/GeoPointField.tsx +120 -0
  100. package/src/components/Form/fields/MarkdownField.tsx +78 -0
  101. package/src/components/Form/fields/NumberField.tsx +39 -0
  102. package/src/components/Form/fields/RefField.tsx +198 -0
  103. package/src/components/Form/fields/SelectField.tsx +65 -0
  104. package/src/components/Form/{custom/SelectOptionsInput.stories.tsx → fields/SelectOptionField.stories.tsx} +19 -17
  105. package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +29 -24
  106. package/src/components/Form/fields/TextAreaField.tsx +38 -0
  107. package/src/components/Form/fields/TextField.tsx +38 -0
  108. package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +16 -9
  109. package/src/components/Form/fields/index.ts +15 -0
  110. package/src/components/Form/index.ts +3 -4
  111. package/src/components/ObjectPicker/ObjectPicker.stories.tsx +18 -16
  112. package/src/components/ObjectPicker/ObjectPicker.tsx +103 -78
  113. package/src/components/Settings/Settings.stories.tsx +55 -0
  114. package/src/components/Settings/Settings.tsx +129 -0
  115. package/src/components/{ControlSection → Settings}/index.ts +1 -1
  116. package/src/components/ViewEditor/ViewEditor.stories.tsx +44 -39
  117. package/src/components/ViewEditor/ViewEditor.test.tsx +5 -5
  118. package/src/components/ViewEditor/ViewEditor.tsx +295 -197
  119. package/src/components/index.ts +1 -1
  120. package/src/components/testing.tsx +23 -9
  121. package/src/hooks/index.ts +2 -3
  122. package/src/hooks/useFormHandler.ts +380 -0
  123. package/src/hooks/useKeyHandler.tsx +37 -0
  124. package/src/translations.ts +66 -65
  125. package/src/util/index.ts +1 -1
  126. package/src/util/properties.ts +18 -0
  127. package/src/util/refs.ts +13 -15
  128. package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
  129. package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
  130. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -84
  131. package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
  132. package/dist/types/src/components/ControlSection/index.d.ts +0 -2
  133. package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
  134. package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
  135. package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
  136. package/dist/types/src/components/Form/Defaults.d.ts +0 -14
  137. package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
  138. package/dist/types/src/components/Form/FormActions.d.ts +0 -9
  139. package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
  140. package/dist/types/src/components/Form/FormContent.d.ts +0 -63
  141. package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
  142. package/dist/types/src/components/Form/FormContext.d.ts +0 -23
  143. package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
  144. package/dist/types/src/components/Form/Input.d.ts +0 -29
  145. package/dist/types/src/components/Form/Input.d.ts.map +0 -1
  146. package/dist/types/src/components/Form/RefField.d.ts +0 -22
  147. package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
  148. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
  149. package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
  150. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
  151. package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
  152. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -79
  153. package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
  154. package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
  155. package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
  156. package/dist/types/src/components/Form/custom/index.d.ts +0 -4
  157. package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
  158. package/dist/types/src/components/Form/factory.d.ts +0 -8
  159. package/dist/types/src/components/Form/factory.d.ts.map +0 -1
  160. package/dist/types/src/hooks/useForm.d.ts +0 -67
  161. package/dist/types/src/hooks/useForm.d.ts.map +0 -1
  162. package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -29
  163. package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
  164. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
  165. package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
  166. package/dist/types/src/util/schema.d.ts +0 -3
  167. package/dist/types/src/util/schema.d.ts.map +0 -1
  168. package/src/components/ControlSection/ControlSection.stories.tsx +0 -38
  169. package/src/components/ControlSection/ControlSection.tsx +0 -153
  170. package/src/components/Form/ArrayField.tsx +0 -127
  171. package/src/components/Form/Defaults.tsx +0 -205
  172. package/src/components/Form/FormActions.tsx +0 -59
  173. package/src/components/Form/FormContent.tsx +0 -362
  174. package/src/components/Form/FormContext.tsx +0 -110
  175. package/src/components/Form/Input.tsx +0 -54
  176. package/src/components/Form/RefField.tsx +0 -283
  177. package/src/components/Form/custom/GeoPointInput.tsx +0 -80
  178. package/src/components/Form/custom/index.ts +0 -7
  179. package/src/components/Form/factory.tsx +0 -34
  180. package/src/hooks/useForm.ts +0 -296
  181. package/src/hooks/useQueryRefOptions.ts +0 -62
  182. package/src/hooks/useRefQueryLookupHandler.ts +0 -39
  183. package/src/util/schema.ts +0 -12
@@ -3,24 +3,31 @@
3
3
  //
4
4
 
5
5
  import type * as Schema from 'effect/Schema';
6
- import React, { type KeyboardEvent, type MouseEvent, forwardRef, useCallback, useMemo, useState } from 'react';
6
+ import React, { type KeyboardEvent, forwardRef, useCallback, useState } from 'react';
7
7
 
8
- import { Icon, Popover, type ThemedClassName, useTranslation } from '@dxos/react-ui';
9
- import { Combobox } from '@dxos/react-ui-searchlist';
8
+ import { type Palette, Popover, type ThemedClassName, useTranslation } from '@dxos/react-ui';
9
+ import { Combobox, useSearchListInput, useSearchListResults } from '@dxos/react-ui-search';
10
10
 
11
- import { type QueryTag } from '../../hooks';
12
11
  import { translationKey } from '../../translations';
13
12
  import { Form } from '../Form';
13
+ import { type FormFieldMap } from '../Form/FormFieldComponent';
14
+
15
+ export type RefOption = {
16
+ id: string;
17
+ label: string;
18
+ hue?: Palette;
19
+ };
14
20
 
15
21
  export type ObjectPickerContentProps = ThemedClassName<{
16
- options: QueryTag[];
22
+ options: RefOption[];
17
23
  selectedIds?: string[];
18
- createSchema?: Schema.Schema.AnyNoContext;
19
24
  createOptionLabel?: [string, { ns: string }];
20
25
  createOptionIcon?: string;
26
+ createSchema?: Schema.Schema.AnyNoContext;
21
27
  createInitialValuePath?: string;
22
- onSelect: (id: string) => void;
28
+ createFieldMap?: FormFieldMap;
23
29
  onCreate?: (values: any) => void;
30
+ onSelect: (id: string) => void;
24
31
  }>;
25
32
 
26
33
  const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>(
@@ -32,46 +39,35 @@ const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>
32
39
  createOptionLabel,
33
40
  createOptionIcon,
34
41
  createInitialValuePath,
42
+ createFieldMap,
35
43
  onSelect,
36
44
  onCreate,
37
45
  ...props
38
46
  },
39
- ref,
47
+ forwardedRef,
40
48
  ) => {
41
49
  const { t } = useTranslation(translationKey);
42
-
43
- const [searchString, setSearchString] = useState('');
44
50
  const [showForm, setShowForm] = useState(false);
51
+ const [formInitialValue, setFormInitialValue] = useState<string>('');
52
+
53
+ const { results, handleSearch } = useSearchListResults({
54
+ items: options,
55
+ });
45
56
 
46
57
  const handleFormSave = useCallback(
47
58
  (values: any) => {
48
59
  onCreate?.(values);
49
60
  setShowForm(false);
50
- setSearchString('');
61
+ setFormInitialValue('');
51
62
  },
52
63
  [onCreate],
53
64
  );
54
65
 
55
66
  const handleFormCancel = useCallback(() => {
56
67
  setShowForm(false);
57
- setSearchString('');
68
+ setFormInitialValue('');
58
69
  }, []);
59
70
 
60
- // TODO(thure): The following click and keydown handlers are necessary because `onSelect` is called after the
61
- // Popover is already closed. Augment/refactor CmdK, if possible, to facilitate stopping event default
62
- // and propagation.
63
-
64
- const handleClick = useCallback(
65
- (event: MouseEvent) => {
66
- if (createSchema && (event.target as HTMLElement).closest('[data-value="__create__"]')) {
67
- event.stopPropagation();
68
- event.preventDefault();
69
- setShowForm(true);
70
- }
71
- },
72
- [createSchema],
73
- );
74
-
75
71
  const handleKeyDown = useCallback(
76
72
  (event: KeyboardEvent) => {
77
73
  if (
@@ -83,78 +79,107 @@ const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>
83
79
  ) {
84
80
  event.stopPropagation();
85
81
  event.preventDefault();
82
+ // Get the current query from the input element
83
+ const input = (event.currentTarget as HTMLElement).querySelector('input[type="text"]') as HTMLInputElement;
84
+ const currentQuery = input?.value || '';
85
+ setFormInitialValue(currentQuery);
86
86
  setShowForm(true);
87
87
  }
88
88
  },
89
89
  [createSchema],
90
90
  );
91
91
 
92
- const labelById = useMemo(
93
- () =>
94
- options.reduce((acc: Record<string, string>, option) => {
95
- acc[option.id.toLowerCase()] = option.label.toLowerCase();
96
- return acc;
97
- }, {}),
98
- [options],
99
- );
100
-
101
- return (
102
- <Combobox.Content
103
- {...props}
104
- ref={ref}
105
- filter={(value, search) => (value === '__create__' || labelById[value]?.includes(search.toLowerCase()) ? 1 : 0)}
106
- onClickCapture={handleClick}
107
- onKeyDownCapture={handleKeyDown}
108
- >
109
- {showForm && createSchema ? (
92
+ if (showForm && createSchema) {
93
+ return (
94
+ <Combobox.Content {...props} onSearch={handleSearch} onKeyDownCapture={handleKeyDown} ref={forwardedRef}>
110
95
  <Popover.Viewport>
111
- <Form
96
+ <Form.Root
97
+ testId='create-referenced-object-form'
112
98
  schema={createSchema}
113
- values={createInitialValuePath ? { [createInitialValuePath]: searchString } : {}}
99
+ defaultValues={createInitialValuePath ? { [createInitialValuePath]: formInitialValue } : {}}
100
+ fieldMap={createFieldMap}
114
101
  onSave={handleFormSave}
115
102
  onCancel={handleFormCancel}
116
- testId='create-referenced-object-form'
117
- />
103
+ >
104
+ <Form.Viewport>
105
+ <Form.Content>
106
+ <Form.FieldSet />
107
+ <Form.Actions />
108
+ </Form.Content>
109
+ </Form.Viewport>
110
+ </Form.Root>
118
111
  </Popover.Viewport>
119
- ) : (
120
- <>
121
- <Combobox.Input
122
- placeholder={t('ref field combobox input placeholder')}
123
- value={searchString}
124
- onValueChange={setSearchString}
125
- autoFocus
112
+ <Combobox.Arrow />
113
+ </Combobox.Content>
114
+ );
115
+ }
116
+
117
+ return (
118
+ <Combobox.Content {...props} onSearch={handleSearch} onKeyDownCapture={handleKeyDown} ref={forwardedRef}>
119
+ <Combobox.Input placeholder={t('ref-field-combobox-input.placeholder')} autoFocus />
120
+ <Combobox.List>
121
+ {results.map((option) => (
122
+ <Combobox.Item
123
+ key={option.id}
124
+ value={option.id}
125
+ label={option.label}
126
+ checked={selectedIds?.includes(option.id)}
127
+ onSelect={() => onSelect(option.id)}
128
+ classNames='flex items-center gap-2'
129
+ />
130
+ ))}
131
+ {createSchema && onCreate && (
132
+ <CreateItem
133
+ createOptionLabel={createOptionLabel}
134
+ createOptionIcon={createOptionIcon ?? 'ph--plus--regular'}
135
+ onCreateItemSelect={(query: string) => {
136
+ setFormInitialValue(query);
137
+ setShowForm(true);
138
+ }}
126
139
  />
127
- <Combobox.List>
128
- {options.map((option) => (
129
- <Combobox.Item
130
- key={option.id}
131
- value={option.id}
132
- onSelect={() => onSelect(option.id)}
133
- classNames='flex items-center gap-2'
134
- >
135
- <span className='grow'>{option.label}</span>
136
- {selectedIds?.includes(option.id) && <Icon icon='ph--check--regular' />}
137
- </Combobox.Item>
138
- ))}
139
- {searchString.length > 0 && createOptionLabel && createOptionIcon && createSchema && onCreate && (
140
- <Combobox.Item value='__create__' classNames='flex items-center gap-2'>
141
- <Icon icon={createOptionIcon} />
142
- {t(createOptionLabel[0], { ns: createOptionLabel[1].ns, text: searchString })}
143
- </Combobox.Item>
144
- )}
145
- </Combobox.List>
146
- </>
147
- )}
140
+ )}
141
+ </Combobox.List>
148
142
  <Combobox.Arrow />
149
143
  </Combobox.Content>
150
144
  );
151
145
  },
152
146
  );
153
147
 
154
- ObjectPickerContent.displayName = 'ObjectPickerContent';
148
+ const CreateItem = ({
149
+ createOptionLabel,
150
+ createOptionIcon,
151
+ onCreateItemSelect,
152
+ }: {
153
+ createOptionLabel?: [string, { ns: string }];
154
+ createOptionIcon: string;
155
+ onCreateItemSelect: (query: string) => void;
156
+ }) => {
157
+ const { t } = useTranslation(translationKey);
158
+ const { query } = useSearchListInput();
159
+
160
+ const label = createOptionLabel
161
+ ? t(createOptionLabel[0], { ns: createOptionLabel[1].ns, text: query })
162
+ : t('create-option.label');
163
+
164
+ return (
165
+ <Combobox.Item
166
+ value='__create__'
167
+ label={label}
168
+ icon={createOptionIcon}
169
+ classNames='flex items-center gap-2'
170
+ closeOnSelect={false}
171
+ onSelect={() => {
172
+ onCreateItemSelect(query);
173
+ }}
174
+ />
175
+ );
176
+ };
177
+
178
+ ObjectPickerContent.displayName = 'ObjectPicker.Content';
155
179
 
156
180
  export const ObjectPicker = {
157
181
  Root: Combobox.Root,
182
+ Portal: Combobox.Portal,
158
183
  Trigger: Combobox.Trigger,
159
184
  VirtualTrigger: Combobox.VirtualTrigger,
160
185
  Content: ObjectPickerContent,
@@ -0,0 +1,55 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React from 'react';
7
+
8
+ import { random } from '@dxos/random';
9
+ import { Button, Input } from '@dxos/react-ui';
10
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
11
+
12
+ import { translations } from '../../translations';
13
+ import { Settings } from './Settings';
14
+
15
+ random.seed(132);
16
+
17
+ const DefaultStory = () => {
18
+ return (
19
+ <Settings.Viewport>
20
+ <Settings.Section title='Settings' description={random.lorem.paragraphs(1)}>
21
+ <Settings.Item title={random.lorem.sentence(2)} description={random.lorem.paragraphs(1)}>
22
+ <Input.TextInput placeholder='Input' />
23
+ </Settings.Item>
24
+ <Settings.Item title={random.lorem.sentence(2)} description={random.lorem.paragraphs(2)}>
25
+ <Input.Switch />
26
+ </Settings.Item>
27
+ <Settings.Item title={random.lorem.sentence(3)} description={random.lorem.paragraphs(2)}>
28
+ <Button>Test</Button>
29
+ </Settings.Item>
30
+ </Settings.Section>
31
+ <Settings.Section title='Panel Example'>
32
+ <Settings.Panel>
33
+ <h3 className='text-lg mb-2'>Members</h3>
34
+ <p className='text-description'>Content inside a panel.</p>
35
+ </Settings.Panel>
36
+ </Settings.Section>
37
+ </Settings.Viewport>
38
+ );
39
+ };
40
+
41
+ const meta = {
42
+ title: 'ui/react-ui-form/Settings',
43
+ render: DefaultStory,
44
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
45
+ parameters: {
46
+ layout: 'fullscreen',
47
+ translations,
48
+ },
49
+ } satisfies Meta;
50
+
51
+ export default meta;
52
+
53
+ type Story = StoryObj<typeof meta>;
54
+
55
+ export const Default: Story = {};
@@ -0,0 +1,129 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { type PropsWithChildren } from 'react';
6
+
7
+ import { Input, type Label, ScrollArea, type ThemedClassName, toLocalizedString, useTranslation } from '@dxos/react-ui';
8
+ import { composable, composableProps, mx } from '@dxos/ui-theme';
9
+
10
+ import { translationKey } from '../../translations';
11
+
12
+ const SETTINGS_ROOT_NAME = 'Settings.Root';
13
+ const SETTINGS_VIEWPORT_NAME = 'Settings.Viewport';
14
+ const SETTINGS_SECTION_NAME = 'Settings.Section';
15
+ const SETTINGS_PANEL_NAME = 'Settings.Panel';
16
+ const SETTINGS_ITEM_NAME = 'Settings.Item';
17
+
18
+ //
19
+ // Root (headless — no styling, no scroll).
20
+ //
21
+
22
+ type SettingsRootProps = ThemedClassName<PropsWithChildren>;
23
+
24
+ const SettingsRoot = ({ children, classNames }: SettingsRootProps) => {
25
+ return <div className={mx('flex flex-col gap-2', classNames)}>{children}</div>;
26
+ };
27
+
28
+ SettingsRoot.displayName = SETTINGS_ROOT_NAME;
29
+
30
+ //
31
+ // Viewport (scroll area + padding + document layout).
32
+ //
33
+
34
+ const SettingsViewport = composable<HTMLDivElement>(({ children, ...props }, forwardedRef) => {
35
+ return (
36
+ <ScrollArea.Root {...composableProps(props)} orientation='vertical' centered thin ref={forwardedRef}>
37
+ <ScrollArea.Viewport classNames='px-4 pointer-coarse:px-2'>
38
+ <div role='none' className='dx-document flex flex-col gap-2 py-4'>
39
+ {children}
40
+ </div>
41
+ </ScrollArea.Viewport>
42
+ </ScrollArea.Root>
43
+ );
44
+ });
45
+
46
+ SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
47
+
48
+ //
49
+ // Section (title + optional description + children with spacing).
50
+ //
51
+
52
+ type SettingsSectionProps = PropsWithChildren<{
53
+ title: Label;
54
+ description?: Label;
55
+ }>;
56
+
57
+ const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
58
+ const { t } = useTranslation(translationKey);
59
+ return (
60
+ <>
61
+ <h2 className='px-trim-md mt-trim-md text-xl'>{toLocalizedString(title, t)}</h2>
62
+ {description && <p className='px-trim-md text-description'>{toLocalizedString(description, t)}</p>}
63
+ <div className='w-full pt-trim-md space-y-trim-md'>{children}</div>
64
+ </>
65
+ );
66
+ };
67
+
68
+ SettingsSection.displayName = SETTINGS_SECTION_NAME;
69
+
70
+ //
71
+ // Panel (bordered card container).
72
+ //
73
+
74
+ type SettingsPanelProps = ThemedClassName<PropsWithChildren>;
75
+
76
+ const SettingsPanel = ({ classNames, children }: SettingsPanelProps) => {
77
+ return (
78
+ <div role='none' className={mx('flex flex-col gap-3 p-trim-md border border-separator rounded-sm', classNames)}>
79
+ {children}
80
+ </div>
81
+ );
82
+ };
83
+
84
+ SettingsPanel.displayName = SETTINGS_PANEL_NAME;
85
+
86
+ //
87
+ // Item (label + optional description + control, proper label semantics).
88
+ //
89
+
90
+ type SettingsItemProps = PropsWithChildren<{
91
+ title: Label;
92
+ description?: Label;
93
+ }>;
94
+
95
+ const SettingsItem = ({ title, description = '', children }: SettingsItemProps) => {
96
+ const { t } = useTranslation(translationKey);
97
+
98
+ return (
99
+ <Input.Root>
100
+ <SettingsPanel classNames='grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0'>
101
+ <Input.Label classNames='pb-trim-md text-base-surface-text text-lg md:col-span-2'>
102
+ {toLocalizedString(title, t)}
103
+ </Input.Label>
104
+ <Input.DescriptionAndValidation>
105
+ <Input.Description classNames='text-base text-description'>
106
+ {toLocalizedString(description, t)}
107
+ </Input.Description>
108
+ </Input.DescriptionAndValidation>
109
+ <div role='none' className='text-end py-1'>
110
+ {children}
111
+ </div>
112
+ </SettingsPanel>
113
+ </Input.Root>
114
+ );
115
+ };
116
+
117
+ SettingsItem.displayName = SETTINGS_ITEM_NAME;
118
+
119
+ //
120
+ // Settings
121
+ //
122
+
123
+ export const Settings = {
124
+ Root: SettingsRoot,
125
+ Viewport: SettingsViewport,
126
+ Section: SettingsSection,
127
+ Panel: SettingsPanel,
128
+ Item: SettingsItem,
129
+ };
@@ -2,4 +2,4 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './ControlSection';
5
+ export * from './Settings';
@@ -6,25 +6,25 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import * as Schema from 'effect/Schema';
7
7
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
8
 
9
- import { DXN, Filter, Obj, Query, type QueryAST, Tag, Type } from '@dxos/echo';
10
- import { type EchoSchema, Format } from '@dxos/echo/internal';
9
+ import { DXN, Filter, JsonSchema, Obj, Query, type QueryAST, Tag, Type } from '@dxos/echo';
10
+ import { type View } from '@dxos/echo';
11
+ import { type EchoSchema, Format, type Mutable } from '@dxos/echo/internal';
11
12
  import { useQuery } from '@dxos/react-client/echo';
12
- import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
13
+ import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
13
14
  import { useAsyncEffect } from '@dxos/react-ui';
14
- import { withTheme } from '@dxos/react-ui/testing';
15
- import { type ProjectionModel, View, getTypenameFromQuery } from '@dxos/schema';
16
- import { Employer, Organization, Person, Project } from '@dxos/types';
15
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
16
+ import { type ProjectionModel, ViewModel, getTypenameFromQuery } from '@dxos/schema';
17
+ import { Employer, Organization, Person, Pipeline } from '@dxos/types';
17
18
 
18
19
  import { translations } from '../../translations';
19
- import { TestLayout, TestPanel, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
20
-
20
+ import { TestLayout, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
21
21
  import { ViewEditor, type ViewEditorProps } from './ViewEditor';
22
22
 
23
23
  const types = [
24
24
  // TODO(burdon): Get label from annotation.
25
25
  { value: Organization.Organization.typename, label: 'Organization' },
26
26
  { value: Person.Person.typename, label: 'Person' },
27
- { value: Type.getTypename(Project.Project), label: 'Project' },
27
+ { value: Pipeline.Pipeline.typename, label: 'Project' },
28
28
  { value: Employer.Employer.typename, label: 'Employer' },
29
29
  ];
30
30
 
@@ -35,15 +35,15 @@ export type ViewEditorDebugObjects = {
35
35
  projection: ProjectionModel;
36
36
  };
37
37
 
38
- type StoryProps = Pick<ViewEditorProps, 'readonly' | 'mode'>;
38
+ type DefaultStoryProps = Pick<ViewEditorProps, 'readonly' | 'mode'>;
39
39
 
40
- const DefaultStory = (props: StoryProps) => {
41
- const { space } = useClientProvider();
40
+ const DefaultStory = (props: DefaultStoryProps) => {
41
+ const { space } = useClientStory();
42
42
  const [schema, setSchema] = useState<EchoSchema>();
43
43
  const [view, setView] = useState<View.View>();
44
44
  const projectionRef = useRef<ProjectionModel>(null);
45
45
 
46
- const tags = useQuery(space, Filter.type(Tag.Tag));
46
+ const tags = useQuery(space?.db, Filter.type(Tag.Tag));
47
47
 
48
48
  useAsyncEffect(async () => {
49
49
  if (space) {
@@ -52,8 +52,8 @@ const DefaultStory = (props: StoryProps) => {
52
52
  email: Format.Email,
53
53
  salary: Format.Currency(),
54
54
  }).pipe(
55
- Type.Obj({
56
- typename: 'example.com/type/Test',
55
+ Type.object({
56
+ typename: 'com.example.type.test',
57
57
  version: '0.1.0',
58
58
  }),
59
59
  );
@@ -63,17 +63,17 @@ const DefaultStory = (props: StoryProps) => {
63
63
  description: Schema.String,
64
64
  completed: Schema.Boolean,
65
65
  }).pipe(
66
- Type.Obj({
67
- typename: 'example.com/type/Alternate',
66
+ Type.object({
67
+ typename: 'com.example.type.alternate',
68
68
  version: '0.1.0',
69
69
  }),
70
70
  );
71
71
 
72
72
  const [testSchema] = await space.db.schemaRegistry.register([TestSchema, AlternateSchema]);
73
- const view = View.make({
73
+ const view = ViewModel.make({
74
74
  name: 'Test',
75
75
  query: Query.select(Filter.type(TestSchema)),
76
- jsonSchema: Type.toJsonSchema(TestSchema),
76
+ jsonSchema: JsonSchema.toJsonSchema(TestSchema),
77
77
  });
78
78
 
79
79
  setSchema(testSchema);
@@ -89,8 +89,10 @@ const DefaultStory = (props: StoryProps) => {
89
89
 
90
90
  if (props.mode === 'tag') {
91
91
  const queue = target && DXN.tryParse(target) ? target : undefined;
92
- const query = queue ? Query.fromAst(newQuery).options({ queues: [queue] }) : Query.fromAst(newQuery);
93
- view.query.ast = query.ast;
92
+ const query = queue ? Query.fromAst(newQuery).from({ queues: [queue] }) : Query.fromAst(newQuery);
93
+ Obj.change(view, (obj) => {
94
+ obj.query.ast = query.ast as Mutable<typeof query.ast>;
95
+ });
94
96
 
95
97
  const typename = getTypenameFromQuery(query.ast);
96
98
  const [newSchema] = await space.db.schemaRegistry.query({ typename }).run();
@@ -98,14 +100,18 @@ const DefaultStory = (props: StoryProps) => {
98
100
  return;
99
101
  }
100
102
 
101
- const newView = View.make({
103
+ const newView = ViewModel.make({
102
104
  query,
103
105
  jsonSchema: newSchema.jsonSchema,
104
106
  });
105
- view.projection = Obj.getSnapshot(newView).projection;
107
+ Obj.change(view, (obj) => {
108
+ obj.projection = Obj.getSnapshot(newView).projection as Mutable<typeof obj.projection>;
109
+ });
106
110
  setSchema(() => newSchema);
107
111
  } else {
108
- view.query.ast = newQuery;
112
+ Obj.change(view, (obj) => {
113
+ obj.query.ast = newQuery as Mutable<typeof newQuery>;
114
+ });
109
115
  schema.updateTypename(getTypenameFromQuery(newQuery));
110
116
  }
111
117
  },
@@ -140,20 +146,18 @@ const DefaultStory = (props: StoryProps) => {
140
146
 
141
147
  return (
142
148
  <TestLayout json={json}>
143
- <TestPanel>
144
- <ViewEditor
145
- ref={projectionRef}
146
- schema={schema}
147
- view={view}
148
- registry={space?.db.schemaRegistry}
149
- mode={props.mode}
150
- readonly={props.readonly}
151
- types={types}
152
- tags={tags}
153
- onQueryChanged={updateViewQuery}
154
- onDelete={handleDelete}
155
- />
156
- </TestPanel>
149
+ <ViewEditor
150
+ ref={projectionRef}
151
+ schema={schema}
152
+ view={view}
153
+ registry={space?.db.schemaRegistry}
154
+ mode={props.mode}
155
+ readonly={props.readonly}
156
+ types={types}
157
+ tags={tags}
158
+ onQueryChanged={updateViewQuery}
159
+ onDelete={handleDelete}
160
+ />
157
161
  </TestLayout>
158
162
  );
159
163
  };
@@ -171,7 +175,8 @@ const meta = {
171
175
  space.db.add(Tag.make({ label: 'New' }));
172
176
  },
173
177
  }),
174
- withTheme,
178
+ withTheme(),
179
+ withLayout({ layout: 'fullscreen' }),
175
180
  ],
176
181
  parameters: {
177
182
  layout: 'fullscreen',
@@ -6,11 +6,11 @@ import { composeStories } from '@storybook/react';
6
6
  import { cleanup, fireEvent, screen, waitFor } from '@testing-library/react';
7
7
  import { afterEach, describe, expect, test } from 'vitest';
8
8
 
9
+ import { View } from '@dxos/echo';
9
10
  import { EchoSchema, isInstanceOf } from '@dxos/echo/internal';
10
- import { ProjectionModel, View } from '@dxos/schema';
11
+ import { ProjectionModel } from '@dxos/schema';
11
12
 
12
13
  import { VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
13
-
14
14
  import * as stories from './ViewEditor.stories';
15
15
  import { type ViewEditorDebugObjects } from './ViewEditor.stories';
16
16
 
@@ -54,7 +54,7 @@ describe('ViewEditor', () => {
54
54
  const nameField = screen.getByText('name');
55
55
  fireEvent.click(nameField);
56
56
 
57
- const fieldInput = screen.getByPlaceholderText('Field name.');
57
+ const fieldInput = screen.getByPlaceholderText('Property name');
58
58
  fireEvent.change(fieldInput, { target: { value: 'new_property' } });
59
59
 
60
60
  fireEvent.click(screen.getByTestId('save-button'));
@@ -89,12 +89,12 @@ describe('ViewEditor', () => {
89
89
  await Default.run();
90
90
  await waitForViewEditor();
91
91
 
92
- // Click the add property button.
92
+ // Click the add property button. The new field is auto-expanded by handleAdd.
93
93
  const addButton = screen.getByText('Add property');
94
94
  fireEvent.click(addButton);
95
95
 
96
96
  // Fill out the property field.
97
- const fieldInput = screen.getByPlaceholderText('Field name.');
97
+ const fieldInput = screen.getByPlaceholderText('Property name');
98
98
  fireEvent.change(fieldInput, { target: { value: 'added_property' } });
99
99
 
100
100
  // Click the format combo box and select the first option.