@dxos/react-ui-form 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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.
- package/README.md +0 -1
- package/dist/lib/browser/index.mjs +2315 -2116
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +2315 -2116
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +8 -7
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +82 -5
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +84 -25
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +127 -55
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +43 -0
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +77 -0
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts +9 -0
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts +18 -0
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +18 -0
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts +16 -0
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts +10 -0
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +5 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +82 -0
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts +6 -0
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/index.d.ts +12 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/index.d.ts +2 -4
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +54 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +85 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts +2 -0
- package/dist/types/src/components/ObjectPicker/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +39 -0
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts +81 -0
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -0
- package/dist/types/src/components/Settings/index.d.ts +2 -0
- package/dist/types/src/components/Settings/index.d.ts.map +1 -0
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +22 -10
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +84 -8
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +4 -3
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -3
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts +82 -0
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts +6 -0
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +63 -54
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field.d.ts +3 -3
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts +2 -2
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +7 -0
- package/dist/types/src/util/properties.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +3 -3
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +52 -43
- package/src/components/FieldEditor/FieldEditor.stories.tsx +51 -32
- package/src/components/FieldEditor/FieldEditor.test.tsx +3 -2
- package/src/components/FieldEditor/FieldEditor.tsx +87 -83
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +154 -219
- package/src/components/Form/Form.tsx +314 -97
- package/src/components/Form/FormField.tsx +305 -0
- package/src/components/Form/FormFieldComponent.stories.tsx +65 -0
- package/src/components/Form/FormFieldComponent.tsx +171 -0
- package/src/components/Form/FormFieldSet.tsx +129 -0
- package/src/components/Form/README.md +3 -0
- package/src/components/Form/fields/ArrayField.tsx +154 -0
- package/src/components/Form/fields/BooleanField.tsx +22 -0
- package/src/components/Form/fields/GeoPointField.tsx +120 -0
- package/src/components/Form/fields/MarkdownField.tsx +78 -0
- package/src/components/Form/fields/NumberField.tsx +39 -0
- package/src/components/Form/fields/RefField.tsx +199 -0
- package/src/components/Form/fields/SelectField.tsx +65 -0
- package/src/components/Form/fields/SelectOptionField.stories.tsx +64 -0
- package/src/components/Form/{custom/SelectOptionsInput.tsx → fields/SelectOptionField.tsx} +49 -45
- package/src/components/Form/fields/TextAreaField.tsx +38 -0
- package/src/components/Form/fields/TextField.tsx +38 -0
- package/src/components/Form/{custom/TupleInput.tsx → fields/TupleField.tsx} +17 -10
- package/src/components/Form/fields/index.ts +15 -0
- package/src/components/Form/index.ts +3 -4
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +210 -0
- package/src/components/ObjectPicker/ObjectPicker.tsx +186 -0
- package/src/components/{ControlSection → ObjectPicker}/index.ts +1 -1
- package/src/components/Settings/Settings.stories.tsx +56 -0
- package/src/components/Settings/Settings.tsx +129 -0
- package/src/components/Settings/index.ts +5 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +141 -63
- package/src/components/ViewEditor/ViewEditor.test.tsx +17 -18
- package/src/components/ViewEditor/ViewEditor.tsx +353 -203
- package/src/components/index.ts +2 -3
- package/src/components/testing.tsx +33 -13
- package/src/hooks/index.ts +2 -3
- package/src/hooks/useFormHandler.ts +380 -0
- package/src/hooks/useKeyHandler.tsx +37 -0
- package/src/translations.ts +66 -58
- package/src/util/field.ts +33 -43
- package/src/util/formatting.ts +22 -22
- package/src/util/index.ts +1 -1
- package/src/util/properties.ts +18 -0
- package/src/util/refs.ts +17 -19
- package/dist/types/src/components/ControlSection/ControlSection.d.ts +0 -23
- package/dist/types/src/components/ControlSection/ControlSection.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts +0 -8
- package/dist/types/src/components/ControlSection/ControlSection.stories.d.ts.map +0 -1
- package/dist/types/src/components/ControlSection/index.d.ts +0 -2
- package/dist/types/src/components/ControlSection/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/ArrayField.d.ts +0 -16
- package/dist/types/src/components/Form/ArrayField.d.ts.map +0 -1
- package/dist/types/src/components/Form/Defaults.d.ts +0 -14
- package/dist/types/src/components/Form/Defaults.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormActions.d.ts +0 -9
- package/dist/types/src/components/Form/FormActions.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContent.d.ts +0 -57
- package/dist/types/src/components/Form/FormContent.d.ts.map +0 -1
- package/dist/types/src/components/Form/FormContext.d.ts +0 -23
- package/dist/types/src/components/Form/FormContext.d.ts.map +0 -1
- package/dist/types/src/components/Form/Input.d.ts +0 -26
- package/dist/types/src/components/Form/Input.d.ts.map +0 -1
- package/dist/types/src/components/Form/RefField.d.ts +0 -12
- package/dist/types/src/components/Form/RefField.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/GeoPointInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts +0 -4
- package/dist/types/src/components/Form/custom/SelectOptionsInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts +0 -7
- package/dist/types/src/components/Form/custom/SelectOptionsInput.stories.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/TupleInput.d.ts +0 -6
- package/dist/types/src/components/Form/custom/TupleInput.d.ts.map +0 -1
- package/dist/types/src/components/Form/custom/index.d.ts +0 -4
- package/dist/types/src/components/Form/custom/index.d.ts.map +0 -1
- package/dist/types/src/components/Form/factory.d.ts +0 -8
- package/dist/types/src/components/Form/factory.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.d.ts +0 -15
- package/dist/types/src/components/deprecated/Form.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/Form.stories.d.ts +0 -13
- package/dist/types/src/components/deprecated/Form.stories.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/FormInput.d.ts +0 -16
- package/dist/types/src/components/deprecated/FormInput.d.ts.map +0 -1
- package/dist/types/src/components/deprecated/index.d.ts +0 -2
- package/dist/types/src/components/deprecated/index.d.ts.map +0 -1
- package/dist/types/src/hooks/useForm.d.ts +0 -67
- package/dist/types/src/hooks/useForm.d.ts.map +0 -1
- package/dist/types/src/hooks/useQueryRefOptions.d.ts +0 -23
- package/dist/types/src/hooks/useQueryRefOptions.d.ts.map +0 -1
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts +0 -8
- package/dist/types/src/hooks/useRefQueryLookupHandler.d.ts.map +0 -1
- package/dist/types/src/util/schema.d.ts +0 -3
- package/dist/types/src/util/schema.d.ts.map +0 -1
- package/src/components/ControlSection/ControlSection.stories.tsx +0 -41
- package/src/components/ControlSection/ControlSection.tsx +0 -139
- package/src/components/Form/ArrayField.tsx +0 -124
- package/src/components/Form/Defaults.tsx +0 -203
- package/src/components/Form/FormActions.tsx +0 -53
- package/src/components/Form/FormContent.tsx +0 -240
- package/src/components/Form/FormContext.tsx +0 -110
- package/src/components/Form/Input.tsx +0 -51
- package/src/components/Form/RefField.tsx +0 -213
- package/src/components/Form/custom/GeoPointInput.tsx +0 -72
- package/src/components/Form/custom/SelectOptionsInput.stories.tsx +0 -61
- package/src/components/Form/custom/index.ts +0 -7
- package/src/components/Form/factory.tsx +0 -31
- package/src/components/deprecated/Form.stories.tsx +0 -62
- package/src/components/deprecated/Form.tsx +0 -119
- package/src/components/deprecated/FormInput.tsx +0 -71
- package/src/components/deprecated/index.ts +0 -5
- package/src/hooks/useForm.ts +0 -291
- package/src/hooks/useQueryRefOptions.ts +0 -53
- package/src/hooks/useRefQueryLookupHandler.ts +0 -39
- package/src/util/schema.ts +0 -14
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
import React, { type KeyboardEvent, forwardRef, useCallback, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { type Palette, Popover, type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
import { Combobox, useSearchListInput, useSearchListResults } from '@dxos/react-ui-search';
|
|
10
|
+
|
|
11
|
+
import { translationKey } from '../../translations';
|
|
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
|
+
};
|
|
20
|
+
|
|
21
|
+
export type ObjectPickerContentProps = ThemedClassName<{
|
|
22
|
+
options: RefOption[];
|
|
23
|
+
selectedIds?: string[];
|
|
24
|
+
createOptionLabel?: [string, { ns: string }];
|
|
25
|
+
createOptionIcon?: string;
|
|
26
|
+
createSchema?: Schema.Schema.AnyNoContext;
|
|
27
|
+
createInitialValuePath?: string;
|
|
28
|
+
createFieldMap?: FormFieldMap;
|
|
29
|
+
onCreate?: (values: any) => void;
|
|
30
|
+
onSelect: (id: string) => void;
|
|
31
|
+
}>;
|
|
32
|
+
|
|
33
|
+
const ObjectPickerContent = forwardRef<HTMLDivElement, ObjectPickerContentProps>(
|
|
34
|
+
(
|
|
35
|
+
{
|
|
36
|
+
options,
|
|
37
|
+
selectedIds,
|
|
38
|
+
createSchema,
|
|
39
|
+
createOptionLabel,
|
|
40
|
+
createOptionIcon,
|
|
41
|
+
createInitialValuePath,
|
|
42
|
+
createFieldMap,
|
|
43
|
+
onSelect,
|
|
44
|
+
onCreate,
|
|
45
|
+
...props
|
|
46
|
+
},
|
|
47
|
+
forwardedRef,
|
|
48
|
+
) => {
|
|
49
|
+
const { t } = useTranslation(translationKey);
|
|
50
|
+
const [showForm, setShowForm] = useState(false);
|
|
51
|
+
const [formInitialValue, setFormInitialValue] = useState<string>('');
|
|
52
|
+
|
|
53
|
+
const { results, handleSearch } = useSearchListResults({
|
|
54
|
+
items: options,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const handleFormSave = useCallback(
|
|
58
|
+
(values: any) => {
|
|
59
|
+
onCreate?.(values);
|
|
60
|
+
setShowForm(false);
|
|
61
|
+
setFormInitialValue('');
|
|
62
|
+
},
|
|
63
|
+
[onCreate],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const handleFormCancel = useCallback(() => {
|
|
67
|
+
setShowForm(false);
|
|
68
|
+
setFormInitialValue('');
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
const handleKeyDown = useCallback(
|
|
72
|
+
(event: KeyboardEvent) => {
|
|
73
|
+
if (
|
|
74
|
+
event.key === 'Enter' &&
|
|
75
|
+
createSchema &&
|
|
76
|
+
(event.currentTarget as HTMLElement).querySelector(
|
|
77
|
+
'[role="option"][aria-selected="true"][data-value="__create__"]',
|
|
78
|
+
)
|
|
79
|
+
) {
|
|
80
|
+
event.stopPropagation();
|
|
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
|
+
setShowForm(true);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
[createSchema],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (showForm && createSchema) {
|
|
93
|
+
return (
|
|
94
|
+
<Combobox.Content {...props} onSearch={handleSearch} onKeyDownCapture={handleKeyDown} ref={forwardedRef}>
|
|
95
|
+
<Popover.Viewport>
|
|
96
|
+
<Form.Root
|
|
97
|
+
testId='create-referenced-object-form'
|
|
98
|
+
schema={createSchema}
|
|
99
|
+
defaultValues={createInitialValuePath ? { [createInitialValuePath]: formInitialValue } : {}}
|
|
100
|
+
fieldMap={createFieldMap}
|
|
101
|
+
onSave={handleFormSave}
|
|
102
|
+
onCancel={handleFormCancel}
|
|
103
|
+
>
|
|
104
|
+
<Form.Viewport>
|
|
105
|
+
<Form.Content>
|
|
106
|
+
<Form.FieldSet />
|
|
107
|
+
<Form.Actions />
|
|
108
|
+
</Form.Content>
|
|
109
|
+
</Form.Viewport>
|
|
110
|
+
</Form.Root>
|
|
111
|
+
</Popover.Viewport>
|
|
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
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
141
|
+
</Combobox.List>
|
|
142
|
+
<Combobox.Arrow />
|
|
143
|
+
</Combobox.Content>
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
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';
|
|
179
|
+
|
|
180
|
+
export const ObjectPicker = {
|
|
181
|
+
Root: Combobox.Root,
|
|
182
|
+
Portal: Combobox.Portal,
|
|
183
|
+
Trigger: Combobox.Trigger,
|
|
184
|
+
VirtualTrigger: Combobox.VirtualTrigger,
|
|
185
|
+
Content: ObjectPickerContent,
|
|
186
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { faker } 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
|
+
|
|
14
|
+
import { Settings } from './Settings';
|
|
15
|
+
|
|
16
|
+
faker.seed(132);
|
|
17
|
+
|
|
18
|
+
const DefaultStory = () => {
|
|
19
|
+
return (
|
|
20
|
+
<Settings.Viewport>
|
|
21
|
+
<Settings.Section title='Settings' description={faker.lorem.paragraphs(1)}>
|
|
22
|
+
<Settings.Item title={faker.lorem.sentence(2)} description={faker.lorem.paragraphs(1)}>
|
|
23
|
+
<Input.TextInput placeholder='Input' />
|
|
24
|
+
</Settings.Item>
|
|
25
|
+
<Settings.Item title={faker.lorem.sentence(2)} description={faker.lorem.paragraphs(2)}>
|
|
26
|
+
<Input.Switch />
|
|
27
|
+
</Settings.Item>
|
|
28
|
+
<Settings.Item title={faker.lorem.sentence(3)} description={faker.lorem.paragraphs(2)}>
|
|
29
|
+
<Button>Test</Button>
|
|
30
|
+
</Settings.Item>
|
|
31
|
+
</Settings.Section>
|
|
32
|
+
<Settings.Section title='Panel Example'>
|
|
33
|
+
<Settings.Panel>
|
|
34
|
+
<h3 className='text-lg mb-2'>Members</h3>
|
|
35
|
+
<p className='text-description'>Content inside a panel.</p>
|
|
36
|
+
</Settings.Panel>
|
|
37
|
+
</Settings.Section>
|
|
38
|
+
</Settings.Viewport>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const meta = {
|
|
43
|
+
title: 'ui/react-ui-form/Settings',
|
|
44
|
+
render: DefaultStory,
|
|
45
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
46
|
+
parameters: {
|
|
47
|
+
layout: 'fullscreen',
|
|
48
|
+
translations,
|
|
49
|
+
},
|
|
50
|
+
} satisfies Meta;
|
|
51
|
+
|
|
52
|
+
export default meta;
|
|
53
|
+
|
|
54
|
+
type Story = StoryObj<typeof meta>;
|
|
55
|
+
|
|
56
|
+
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,125 +2,203 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import
|
|
9
|
-
import React, { useCallback, useMemo,
|
|
10
|
-
|
|
11
|
-
import { Obj, Type } from '@dxos/echo';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
|
|
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';
|
|
12
|
+
import { useQuery } from '@dxos/react-client/echo';
|
|
13
|
+
import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
|
|
15
14
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
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';
|
|
18
18
|
|
|
19
|
-
import { ViewEditor, type ViewEditorProps } from './ViewEditor';
|
|
20
19
|
import { translations } from '../../translations';
|
|
21
|
-
import { TestLayout,
|
|
20
|
+
import { TestLayout, VIEW_EDITOR_DEBUG_SYMBOL } from '../testing';
|
|
21
|
+
|
|
22
|
+
import { ViewEditor, type ViewEditorProps } from './ViewEditor';
|
|
23
|
+
|
|
24
|
+
const types = [
|
|
25
|
+
// TODO(burdon): Get label from annotation.
|
|
26
|
+
{ value: Organization.Organization.typename, label: 'Organization' },
|
|
27
|
+
{ value: Person.Person.typename, label: 'Person' },
|
|
28
|
+
{ value: Pipeline.Pipeline.typename, label: 'Project' },
|
|
29
|
+
{ value: Employer.Employer.typename, label: 'Employer' },
|
|
30
|
+
];
|
|
22
31
|
|
|
23
32
|
// Type definition for debug objects exposed to tests.
|
|
24
33
|
export type ViewEditorDebugObjects = {
|
|
25
34
|
schema: EchoSchema;
|
|
26
|
-
view:
|
|
35
|
+
view: View.View;
|
|
27
36
|
projection: ProjectionModel;
|
|
28
37
|
};
|
|
29
38
|
|
|
30
|
-
type
|
|
39
|
+
type DefaultStoryProps = Pick<ViewEditorProps, 'readonly' | 'mode'>;
|
|
31
40
|
|
|
32
|
-
const DefaultStory = (props:
|
|
33
|
-
const space =
|
|
41
|
+
const DefaultStory = (props: DefaultStoryProps) => {
|
|
42
|
+
const { space } = useClientStory();
|
|
34
43
|
const [schema, setSchema] = useState<EchoSchema>();
|
|
35
|
-
const [view, setView] = useState<
|
|
36
|
-
const
|
|
44
|
+
const [view, setView] = useState<View.View>();
|
|
45
|
+
const projectionRef = useRef<ProjectionModel>(null);
|
|
46
|
+
|
|
47
|
+
const tags = useQuery(space?.db, Filter.type(Tag.Tag));
|
|
48
|
+
|
|
37
49
|
useAsyncEffect(async () => {
|
|
38
50
|
if (space) {
|
|
39
|
-
|
|
51
|
+
const TestSchema = Schema.Struct({
|
|
40
52
|
name: Schema.String,
|
|
41
53
|
email: Format.Email,
|
|
42
54
|
salary: Format.Currency(),
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
}).pipe(
|
|
56
|
+
Type.object({
|
|
57
|
+
typename: 'com.example.type.test',
|
|
58
|
+
version: '0.1.0',
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const AlternateSchema = Schema.Struct({
|
|
63
|
+
title: Schema.String,
|
|
64
|
+
description: Schema.String,
|
|
65
|
+
completed: Schema.Boolean,
|
|
66
|
+
}).pipe(
|
|
67
|
+
Type.object({
|
|
68
|
+
typename: 'com.example.type.alternate',
|
|
69
|
+
version: '0.1.0',
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const [testSchema] = await space.db.schemaRegistry.register([TestSchema, AlternateSchema]);
|
|
74
|
+
const view = ViewModel.make({
|
|
47
75
|
name: 'Test',
|
|
48
|
-
|
|
49
|
-
jsonSchema: toJsonSchema(TestSchema),
|
|
50
|
-
presentation: Obj.make(Type.Expando, {}),
|
|
76
|
+
query: Query.select(Filter.type(TestSchema)),
|
|
77
|
+
jsonSchema: JsonSchema.toJsonSchema(TestSchema),
|
|
51
78
|
});
|
|
52
|
-
const projection = new ProjectionModel(schema.jsonSchema, view.projection);
|
|
53
79
|
|
|
54
|
-
setSchema(
|
|
80
|
+
setSchema(testSchema);
|
|
55
81
|
setView(view);
|
|
56
|
-
setProjection(projection);
|
|
57
82
|
}
|
|
58
83
|
}, [space]);
|
|
59
84
|
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(newTypename: string) => {
|
|
64
|
-
if (!schema) {
|
|
85
|
+
const updateViewQuery = useCallback(
|
|
86
|
+
async (newQuery: QueryAST.Query, target?: string) => {
|
|
87
|
+
if (!schema || !view || !space) {
|
|
65
88
|
return;
|
|
66
89
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
|
|
91
|
+
if (props.mode === 'tag') {
|
|
92
|
+
const queue = target && DXN.tryParse(target) ? target : undefined;
|
|
93
|
+
const query = queue ? Query.fromAst(newQuery).from({ queues: [queue] }) : Query.fromAst(newQuery);
|
|
94
|
+
Obj.change(view, (obj) => {
|
|
95
|
+
obj.query.ast = query.ast as Mutable<typeof query.ast>;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const typename = getTypenameFromQuery(query.ast);
|
|
99
|
+
const [newSchema] = await space.db.schemaRegistry.query({ typename }).run();
|
|
100
|
+
if (!newSchema) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const newView = ViewModel.make({
|
|
105
|
+
query,
|
|
106
|
+
jsonSchema: newSchema.jsonSchema,
|
|
107
|
+
});
|
|
108
|
+
Obj.change(view, (obj) => {
|
|
109
|
+
obj.projection = Obj.getSnapshot(newView).projection as Mutable<typeof obj.projection>;
|
|
110
|
+
});
|
|
111
|
+
setSchema(() => newSchema);
|
|
112
|
+
} else {
|
|
113
|
+
Obj.change(view, (obj) => {
|
|
114
|
+
obj.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
115
|
+
});
|
|
116
|
+
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
70
117
|
}
|
|
71
|
-
schema.updateTypename(newTypename);
|
|
72
118
|
},
|
|
73
|
-
[
|
|
119
|
+
[view, schema],
|
|
74
120
|
);
|
|
75
121
|
|
|
76
|
-
const handleDelete = useCallback(
|
|
122
|
+
const handleDelete = useCallback(
|
|
123
|
+
(property: string) => projectionRef.current?.deleteFieldProjection(property),
|
|
124
|
+
[projectionRef],
|
|
125
|
+
);
|
|
77
126
|
|
|
78
127
|
// Expose objects on window for test access.
|
|
79
128
|
useEffect(() => {
|
|
80
|
-
if (typeof window !== 'undefined' && schema && view &&
|
|
81
|
-
(window as any)[VIEW_EDITOR_DEBUG_SYMBOL] = {
|
|
129
|
+
if (typeof window !== 'undefined' && schema && view && projectionRef.current) {
|
|
130
|
+
(window as any)[VIEW_EDITOR_DEBUG_SYMBOL] = {
|
|
131
|
+
schema,
|
|
132
|
+
view,
|
|
133
|
+
projection: projectionRef.current,
|
|
134
|
+
} satisfies ViewEditorDebugObjects;
|
|
82
135
|
}
|
|
83
|
-
}, [schema, view
|
|
136
|
+
}, [schema, view]);
|
|
84
137
|
|
|
85
138
|
// NOTE(ZaymonFC): This looks awkward but it resolves an infinite parsing issue with sb.
|
|
86
139
|
const json = useMemo(
|
|
87
|
-
() => JSON.parse(JSON.stringify({ schema, view, projection })),
|
|
88
|
-
[JSON.stringify(schema), JSON.stringify(view)
|
|
140
|
+
() => JSON.parse(JSON.stringify({ schema, view, projection: projectionRef.current })),
|
|
141
|
+
[JSON.stringify(schema), JSON.stringify(view)],
|
|
89
142
|
);
|
|
90
143
|
|
|
91
|
-
if (!schema || !view
|
|
144
|
+
if (!schema || !view) {
|
|
92
145
|
return <div />;
|
|
93
146
|
}
|
|
94
147
|
|
|
95
148
|
return (
|
|
96
149
|
<TestLayout json={json}>
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
150
|
+
<ViewEditor
|
|
151
|
+
ref={projectionRef}
|
|
152
|
+
schema={schema}
|
|
153
|
+
view={view}
|
|
154
|
+
registry={space?.db.schemaRegistry}
|
|
155
|
+
mode={props.mode}
|
|
156
|
+
readonly={props.readonly}
|
|
157
|
+
types={types}
|
|
158
|
+
tags={tags}
|
|
159
|
+
onQueryChanged={updateViewQuery}
|
|
160
|
+
onDelete={handleDelete}
|
|
161
|
+
/>
|
|
107
162
|
</TestLayout>
|
|
108
163
|
);
|
|
109
164
|
};
|
|
110
165
|
|
|
111
|
-
const meta
|
|
166
|
+
const meta = {
|
|
112
167
|
title: 'ui/react-ui-form/ViewEditor',
|
|
113
168
|
render: DefaultStory,
|
|
114
|
-
decorators: [
|
|
115
|
-
|
|
116
|
-
|
|
169
|
+
decorators: [
|
|
170
|
+
withClientProvider({
|
|
171
|
+
createSpace: true,
|
|
172
|
+
types: [Tag.Tag],
|
|
173
|
+
onCreateSpace: ({ space }) => {
|
|
174
|
+
space.db.add(Tag.make({ label: 'Important' }));
|
|
175
|
+
space.db.add(Tag.make({ label: 'Investor' }));
|
|
176
|
+
space.db.add(Tag.make({ label: 'New' }));
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
withTheme(),
|
|
180
|
+
withLayout({ layout: 'fullscreen' }),
|
|
181
|
+
],
|
|
182
|
+
parameters: {
|
|
183
|
+
layout: 'fullscreen',
|
|
184
|
+
translations,
|
|
185
|
+
},
|
|
186
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
117
187
|
|
|
118
188
|
export default meta;
|
|
119
189
|
|
|
120
|
-
type Story = StoryObj<
|
|
190
|
+
type Story = StoryObj<typeof meta>;
|
|
121
191
|
|
|
122
192
|
export const Default: Story = {};
|
|
123
193
|
|
|
124
194
|
export const Readonly: Story = {
|
|
125
|
-
args: {
|
|
195
|
+
args: {
|
|
196
|
+
readonly: true,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const TagQueryMode: Story = {
|
|
201
|
+
args: {
|
|
202
|
+
mode: 'tag',
|
|
203
|
+
},
|
|
126
204
|
};
|