@dxos/react-ui-form 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +1028 -625
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +82 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1028 -625
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +84 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +63 -61
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +40 -12
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +76 -74
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +11 -5
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +8 -7
- package/dist/types/src/components/Form/FormFieldComponent.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldSet.d.ts +5 -9
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/ArrayField.d.ts +4 -4
- package/dist/types/src/components/Form/fields/ArrayField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/BooleanField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts +8 -1
- package/dist/types/src/components/Form/fields/MarkdownField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts +84 -0
- package/dist/types/src/components/Form/fields/MarkdownField.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/NumberField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/RefField.d.ts +15 -7
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts +63 -61
- package/dist/types/src/components/Form/fields/SelectOptionField.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextAreaField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/TextField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +9 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/index.d.ts +2 -0
- package/dist/types/src/components/ObjectForm/index.d.ts.map +1 -0
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts +26 -4
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +63 -61
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts.map +1 -1
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts +9 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts +127 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/ObjectProperties.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts +2 -0
- package/dist/types/src/components/ObjectProperties/index.d.ts.map +1 -0
- package/dist/types/src/components/Settings/Settings.d.ts +28 -33
- package/dist/types/src/components/Settings/Settings.d.ts.map +1 -1
- package/dist/types/src/components/Settings/Settings.stories.d.ts +64 -61
- package/dist/types/src/components/Settings/Settings.stories.d.ts.map +1 -1
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts +43 -0
- package/dist/types/src/components/Settings/SettingsFieldSet.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts +16 -0
- package/dist/types/src/components/Settings/SettingsItem.d.ts.map +1 -0
- package/dist/types/src/components/Settings/SettingsSelectField.d.ts +18 -0
- package/dist/types/src/components/Settings/SettingsSelectField.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 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts +3 -4
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +65 -63
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +4 -4
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useFormHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts +2 -1
- package/dist/types/src/hooks/useKeyHandler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +63 -61
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/field-type.d.ts +19 -0
- package/dist/types/src/util/field-type.d.ts.map +1 -0
- package/dist/types/src/util/field.d.ts.map +1 -1
- package/dist/types/src/util/formatting.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/properties.d.ts +7 -1
- package/dist/types/src/util/properties.d.ts.map +1 -1
- package/dist/types/src/util/properties.test.d.ts +2 -0
- package/dist/types/src/util/properties.test.d.ts.map +1 -0
- package/dist/types/src/util/refs.d.ts +1 -0
- package/dist/types/src/util/refs.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -41
- package/src/components/FieldEditor/FieldEditor.stories.tsx +2 -2
- package/src/components/FieldEditor/FieldEditor.test.tsx +0 -1
- package/src/components/FieldEditor/FieldEditor.tsx +4 -3
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +25 -38
- package/src/components/Form/Form.tsx +77 -48
- package/src/components/Form/FormField.tsx +27 -15
- package/src/components/Form/FormFieldComponent.tsx +6 -4
- package/src/components/Form/FormFieldSet.tsx +98 -77
- package/src/components/Form/fields/ArrayField.tsx +14 -8
- package/src/components/Form/fields/GeoPointField.tsx +8 -7
- package/src/components/Form/fields/MarkdownField.stories.tsx +206 -0
- package/src/components/Form/fields/MarkdownField.tsx +135 -45
- package/src/components/Form/fields/RefField.tsx +79 -39
- package/src/components/Form/fields/SelectOptionField.stories.tsx +8 -6
- package/src/components/Form/fields/SelectOptionField.tsx +12 -12
- package/src/components/Form/fields/TextField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +1 -1
- package/src/components/ObjectForm/ObjectForm.tsx +114 -0
- package/src/components/ObjectForm/index.ts +5 -0
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +12 -10
- package/src/components/ObjectPicker/ObjectPicker.tsx +92 -65
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +362 -0
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +101 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +148 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/Settings/AUDIT.md +51 -0
- package/src/components/Settings/Settings.stories.tsx +69 -21
- package/src/components/Settings/Settings.tsx +33 -183
- package/src/components/Settings/SettingsFieldSet.tsx +257 -0
- package/src/components/Settings/SettingsItem.tsx +58 -0
- package/src/components/Settings/SettingsSelectField.tsx +59 -0
- package/src/components/Settings/index.ts +2 -0
- package/src/components/ViewEditor/ViewEditor.stories.tsx +14 -15
- package/src/components/ViewEditor/ViewEditor.test.tsx +0 -1
- package/src/components/ViewEditor/ViewEditor.tsx +40 -36
- package/src/components/index.ts +2 -0
- package/src/components/testing.tsx +19 -11
- package/src/hooks/useKeyHandler.tsx +7 -7
- package/src/index.ts +0 -4
- package/src/translations.ts +66 -63
- package/src/util/field-type.ts +60 -0
- package/src/util/index.ts +1 -0
- package/src/util/properties.test.ts +63 -0
- package/src/util/properties.ts +14 -3
- package/src/util/refs.ts +7 -3
|
@@ -3,39 +3,40 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
6
7
|
import React from 'react';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
9
10
|
import { Button, Input } from '@dxos/react-ui';
|
|
10
11
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
11
12
|
|
|
12
|
-
import { translations } from '
|
|
13
|
+
import { translations } from '#translations';
|
|
13
14
|
|
|
14
15
|
import { Settings } from './Settings';
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
random.seed(132);
|
|
17
18
|
|
|
18
19
|
const DefaultStory = () => {
|
|
19
20
|
return (
|
|
20
|
-
<Settings.
|
|
21
|
-
<Settings.Section title='Settings' description={
|
|
22
|
-
<Settings.
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
</Input.Root>
|
|
32
|
-
</Settings.ItemInput>
|
|
33
|
-
<Settings.ItemInput title={faker.lorem.sentence(3)} description={faker.lorem.paragraphs(2)}>
|
|
34
|
-
<Button>Test</Button>
|
|
35
|
-
</Settings.ItemInput>
|
|
36
|
-
</Settings.Group>
|
|
21
|
+
<Settings.Viewport>
|
|
22
|
+
<Settings.Section title='Settings' description={random.lorem.paragraphs(1)}>
|
|
23
|
+
<Settings.Item title={random.lorem.sentence(2)} description={random.lorem.paragraphs(1)}>
|
|
24
|
+
<Input.TextInput placeholder='Input' />
|
|
25
|
+
</Settings.Item>
|
|
26
|
+
<Settings.Item title={random.lorem.sentence(2)} description={random.lorem.paragraphs(2)}>
|
|
27
|
+
<Input.Switch />
|
|
28
|
+
</Settings.Item>
|
|
29
|
+
<Settings.Item title={random.lorem.sentence(3)} description={random.lorem.paragraphs(2)}>
|
|
30
|
+
<Button>Test</Button>
|
|
31
|
+
</Settings.Item>
|
|
37
32
|
</Settings.Section>
|
|
38
|
-
|
|
33
|
+
<Settings.Section title='Panel Example'>
|
|
34
|
+
<Settings.Panel>
|
|
35
|
+
<h3 className='text-lg mb-2'>Members</h3>
|
|
36
|
+
<p className='text-description'>Content inside a panel.</p>
|
|
37
|
+
</Settings.Panel>
|
|
38
|
+
</Settings.Section>
|
|
39
|
+
</Settings.Viewport>
|
|
39
40
|
);
|
|
40
41
|
};
|
|
41
42
|
|
|
@@ -54,3 +55,50 @@ export default meta;
|
|
|
54
55
|
type Story = StoryObj<typeof meta>;
|
|
55
56
|
|
|
56
57
|
export const Default: Story = {};
|
|
58
|
+
|
|
59
|
+
const TestViewModes = ['preview', 'readonly', 'source'] as const;
|
|
60
|
+
const TestViewMode = Schema.Union(...TestViewModes.map((mode) => Schema.Literal(mode)));
|
|
61
|
+
|
|
62
|
+
const TestSettings = Schema.mutable(
|
|
63
|
+
Schema.Struct({
|
|
64
|
+
viewMode: TestViewMode.annotations({ title: 'View mode', description: 'Default document view mode.' }),
|
|
65
|
+
toolbar: Schema.optional(
|
|
66
|
+
Schema.Boolean.annotations({ title: 'Show toolbar', description: 'Display formatting toolbar.' }),
|
|
67
|
+
),
|
|
68
|
+
fontSize: Schema.optional(
|
|
69
|
+
Schema.Number.annotations({ title: 'Font size', description: 'Editor font size in pixels.' }),
|
|
70
|
+
),
|
|
71
|
+
placeholder: Schema.optional(
|
|
72
|
+
Schema.String.annotations({ title: 'Placeholder', description: 'Default placeholder text.' }),
|
|
73
|
+
),
|
|
74
|
+
debug: Schema.optional(Schema.Boolean.annotations({ title: 'Debug mode', description: 'Enable debug features.' })),
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
type TestSettings = Schema.Schema.Type<typeof TestSettings>;
|
|
79
|
+
|
|
80
|
+
const FieldSetStory = () => {
|
|
81
|
+
const [values, setValues] = React.useState<TestSettings>({
|
|
82
|
+
viewMode: 'preview',
|
|
83
|
+
toolbar: true,
|
|
84
|
+
fontSize: 14,
|
|
85
|
+
debug: false,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Settings.Viewport>
|
|
90
|
+
<Settings.Section title='Plugin Settings (Auto-generated)'>
|
|
91
|
+
<Settings.FieldSet
|
|
92
|
+
schema={TestSettings}
|
|
93
|
+
values={values}
|
|
94
|
+
onValuesChanged={setValues}
|
|
95
|
+
visible={(path, values) => path !== 'placeholder' || !!values.debug}
|
|
96
|
+
/>
|
|
97
|
+
</Settings.Section>
|
|
98
|
+
</Settings.Viewport>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const FieldSet: Story = {
|
|
103
|
+
render: FieldSetStory,
|
|
104
|
+
};
|
|
@@ -4,213 +4,67 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
toLocalizedString,
|
|
15
|
-
useTranslation,
|
|
16
|
-
} from '@dxos/react-ui';
|
|
17
|
-
import { mx } from '@dxos/ui-theme';
|
|
18
|
-
|
|
19
|
-
import { translationKey } from '../../translations';
|
|
7
|
+
import { 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
|
+
import { SettingsFieldSet } from './SettingsFieldSet';
|
|
13
|
+
import { SettingsItem, SettingsPanel } from './SettingsItem';
|
|
20
14
|
|
|
21
15
|
const SETTINGS_ROOT_NAME = 'Settings.Root';
|
|
16
|
+
const SETTINGS_VIEWPORT_NAME = 'Settings.Viewport';
|
|
22
17
|
const SETTINGS_SECTION_NAME = 'Settings.Section';
|
|
23
|
-
const SETTINGS_SECTION_HEADING_NAME = 'Settings.SectionHeading';
|
|
24
|
-
const SETTINGS_GROUP_NAME = 'Settings.Group';
|
|
25
|
-
const SETTINGS_GROUP_BUTTON_NAME = 'Settings.GroupButton';
|
|
26
|
-
const SETTINGS_CONTAINER_NAME = 'Settings.Container';
|
|
27
|
-
const SETTINGS_FRAME_NAME = 'Settings.Frame';
|
|
28
|
-
const SETTINGS_FRAME_ITEM_NAME = 'Settings.FrameItem';
|
|
29
|
-
const SETTINGS_ITEM_NAME = 'Settings.Item';
|
|
30
|
-
const SETTINGS_ITEM_INPUT_NAME = 'Settings.ItemInput';
|
|
31
|
-
|
|
32
|
-
const styles = {
|
|
33
|
-
title: 'pb-trim-md text-base-surface-text text-lg',
|
|
34
|
-
description: 'text-base text-description',
|
|
35
|
-
grid: 'grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg',
|
|
36
|
-
};
|
|
37
18
|
|
|
38
19
|
//
|
|
39
|
-
// Root
|
|
20
|
+
// Root (headless — no styling, no scroll).
|
|
40
21
|
//
|
|
41
22
|
|
|
42
|
-
type SettingsRootProps = PropsWithChildren
|
|
23
|
+
type SettingsRootProps = ThemedClassName<PropsWithChildren>;
|
|
43
24
|
|
|
44
|
-
const SettingsRoot = ({ children }: SettingsRootProps) => {
|
|
45
|
-
return (
|
|
46
|
-
<ScrollArea.Root orientation='vertical' className='dx-article'>
|
|
47
|
-
<ScrollArea.Viewport classNames='p-trim-md'>{children}</ScrollArea.Viewport>
|
|
48
|
-
</ScrollArea.Root>
|
|
49
|
-
);
|
|
25
|
+
const SettingsRoot = ({ children, classNames }: SettingsRootProps) => {
|
|
26
|
+
return <div className={mx('flex flex-col gap-2', classNames)}>{children}</div>;
|
|
50
27
|
};
|
|
51
28
|
|
|
52
29
|
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
53
30
|
|
|
54
31
|
//
|
|
55
|
-
//
|
|
32
|
+
// Viewport (scroll area + padding + document layout).
|
|
56
33
|
//
|
|
57
34
|
|
|
58
|
-
|
|
59
|
-
title: Label;
|
|
60
|
-
description?: Label;
|
|
61
|
-
}>;
|
|
62
|
-
|
|
63
|
-
const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
|
|
35
|
+
const SettingsViewport = composable<HTMLDivElement>(({ children, ...props }, forwardedRef) => {
|
|
64
36
|
return (
|
|
65
|
-
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
// Section Heading
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
const SettingsSectionHeading = ({ title, description }: Omit<SettingsSectionProps, 'children'>) => {
|
|
79
|
-
const { t } = useTranslation(translationKey);
|
|
80
|
-
return (
|
|
81
|
-
<>
|
|
82
|
-
<h2 className='px-trim-md mt-trim-md mb-trim-md text-xl'>{toLocalizedString(title, t)}</h2>
|
|
83
|
-
{description && <p className='px-trim-md my-trim-md text-description'>{toLocalizedString(description, t)}</p>}
|
|
84
|
-
</>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
SettingsSectionHeading.displayName = SETTINGS_SECTION_HEADING_NAME;
|
|
89
|
-
|
|
90
|
-
//
|
|
91
|
-
// Group Button
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
const SettingsGroupButton = ({ classNames, ...props }: ButtonProps) => {
|
|
95
|
-
return <Button {...props} classNames={['md:col-span-2', classNames]} />;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
SettingsGroupButton.displayName = SETTINGS_GROUP_BUTTON_NAME;
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
// Group
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
type SettingsGroupProps = ThemedClassName<PropsWithChildren>;
|
|
105
|
-
|
|
106
|
-
const SettingsGroup = ({ children, classNames }: SettingsGroupProps) => (
|
|
107
|
-
<div role='none' className={mx('group space-y-trim-md', classNames)}>
|
|
108
|
-
{children}
|
|
109
|
-
</div>
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
SettingsGroup.displayName = SETTINGS_GROUP_NAME;
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
// Frame
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
const SettingsFrame = ({ children }: SettingsGroupProps) => (
|
|
119
|
-
<div role='none' className='p-trim-md border border-separator rounded-md'>
|
|
120
|
-
{children}
|
|
121
|
-
</div>
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
SettingsFrame.displayName = SETTINGS_FRAME_NAME;
|
|
125
|
-
|
|
126
|
-
//
|
|
127
|
-
// Frame Item
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
const SettingsFrameItem = ({ title, description, children }: SettingsItemProps) => {
|
|
131
|
-
const { t } = useTranslation(translationKey);
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div role='group' className='min-w-0'>
|
|
135
|
-
<h3 className='text-lg mb-2'>{toLocalizedString(title, t)}</h3>
|
|
136
|
-
{description && <p className='my-trim-sm md:mb-0 text-description'>{toLocalizedString(description, t)}</p>}
|
|
137
|
-
{children}
|
|
138
|
-
</div>
|
|
139
|
-
);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
SettingsFrameItem.displayName = SETTINGS_FRAME_ITEM_NAME;
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
// Container
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
const SettingsContainer = ({ classNames, children }: ThemedClassName<PropsWithChildren>) => {
|
|
149
|
-
return (
|
|
150
|
-
<div
|
|
151
|
-
role='none'
|
|
152
|
-
className={mx([
|
|
153
|
-
'dx-article',
|
|
154
|
-
'*:first:mt-0! *:last:mb-0! px-trim-md py-trim-md',
|
|
155
|
-
'border border-separator rounded-md',
|
|
156
|
-
classNames,
|
|
157
|
-
])}
|
|
158
|
-
>
|
|
159
|
-
{children}
|
|
160
|
-
</div>
|
|
37
|
+
<ScrollArea.Root {...composableProps(props)} orientation='vertical' centered thin ref={forwardedRef}>
|
|
38
|
+
<ScrollArea.Viewport classNames='px-4 pointer-coarse:px-2'>
|
|
39
|
+
<div className='dx-document flex flex-col gap-2 py-4'>{children}</div>
|
|
40
|
+
</ScrollArea.Viewport>
|
|
41
|
+
</ScrollArea.Root>
|
|
161
42
|
);
|
|
162
|
-
};
|
|
43
|
+
});
|
|
163
44
|
|
|
164
|
-
|
|
45
|
+
SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
|
|
165
46
|
|
|
166
47
|
//
|
|
167
|
-
//
|
|
48
|
+
// Section (title + optional description + children with spacing).
|
|
168
49
|
//
|
|
169
50
|
|
|
170
|
-
type
|
|
51
|
+
type SettingsSectionProps = PropsWithChildren<{
|
|
171
52
|
title: Label;
|
|
172
53
|
description?: Label;
|
|
173
54
|
}>;
|
|
174
55
|
|
|
175
|
-
const
|
|
176
|
-
const { t } = useTranslation(translationKey);
|
|
177
|
-
|
|
178
|
-
return (
|
|
179
|
-
<SettingsContainer classNames={styles.grid}>
|
|
180
|
-
<h3 className={mx(styles.title, 'md:col-span-2')}>{toLocalizedString(title, t)}</h3>
|
|
181
|
-
<p className={styles.description}>{toLocalizedString(description, t)}</p>
|
|
182
|
-
<div role='none' className='overflow-hidden text-end py-1'>
|
|
183
|
-
{children}
|
|
184
|
-
</div>
|
|
185
|
-
</SettingsContainer>
|
|
186
|
-
);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
// Item Input
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
const SettingsItemInput = ({ title, description = '', children }: SettingsItemProps) => {
|
|
56
|
+
const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
|
|
196
57
|
const { t } = useTranslation(translationKey);
|
|
197
|
-
|
|
198
58
|
return (
|
|
199
|
-
|
|
200
|
-
<
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
</Input.DescriptionAndValidation>
|
|
205
|
-
<div role='none' className='text-end py-1'>
|
|
206
|
-
{children}
|
|
207
|
-
</div>
|
|
208
|
-
</SettingsContainer>
|
|
209
|
-
</Input.Root>
|
|
59
|
+
<>
|
|
60
|
+
<h2 className='px-trim-md mt-trim-md text-xl'>{toLocalizedString(title, t)}</h2>
|
|
61
|
+
{description && <p className='px-trim-md text-description'>{toLocalizedString(description, t)}</p>}
|
|
62
|
+
<div className='w-full pt-trim-md space-y-trim-md'>{children}</div>
|
|
63
|
+
</>
|
|
210
64
|
);
|
|
211
65
|
};
|
|
212
66
|
|
|
213
|
-
|
|
67
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
214
68
|
|
|
215
69
|
//
|
|
216
70
|
// Settings
|
|
@@ -218,13 +72,9 @@ SettingsItemInput.displayName = SETTINGS_ITEM_INPUT_NAME;
|
|
|
218
72
|
|
|
219
73
|
export const Settings = {
|
|
220
74
|
Root: SettingsRoot,
|
|
75
|
+
Viewport: SettingsViewport,
|
|
221
76
|
Section: SettingsSection,
|
|
222
|
-
|
|
223
|
-
Group: SettingsGroup,
|
|
224
|
-
GroupButton: SettingsGroupButton,
|
|
225
|
-
Container: SettingsContainer,
|
|
226
|
-
Frame: SettingsFrame,
|
|
227
|
-
FrameItem: SettingsFrameItem,
|
|
77
|
+
Panel: SettingsPanel,
|
|
228
78
|
Item: SettingsItem,
|
|
229
|
-
|
|
79
|
+
FieldSet: SettingsFieldSet,
|
|
230
80
|
};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
|
+
import * as String from 'effect/String';
|
|
7
|
+
import React, { useCallback, useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
import { getAnnotation, type SchemaProperty } from '@dxos/effect';
|
|
10
|
+
import { Input, Select } from '@dxos/react-ui';
|
|
11
|
+
|
|
12
|
+
import { getFormProperties, type SelectOption, detectFieldType, getSelectOptionsFromAst } from '../../util';
|
|
13
|
+
import { SettingsItem } from './SettingsItem';
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// Types
|
|
17
|
+
//
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Props for a custom field renderer.
|
|
21
|
+
* The renderer provides the control only; SettingsItem wrapper is handled by FieldSet.
|
|
22
|
+
*/
|
|
23
|
+
export type SettingsFieldProps<T = any> = {
|
|
24
|
+
value: T;
|
|
25
|
+
onChange: (value: T) => void;
|
|
26
|
+
readonly?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Map of property names to either a custom field renderer or a nested field map for struct fields.
|
|
31
|
+
* When a value type `T` is provided, the map shape is checked against the schema's value type.
|
|
32
|
+
*/
|
|
33
|
+
export type SettingsFieldMap<T extends Record<string, any> = Record<string, any>> = {
|
|
34
|
+
[K in keyof T]?: NonNullable<T[K]> extends Record<string, any>
|
|
35
|
+
? SettingsFieldMap<NonNullable<T[K]>>
|
|
36
|
+
: React.FC<SettingsFieldProps<T[K]>>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type SettingsFieldSetProps<T extends Record<string, any> = Record<string, any>> = {
|
|
40
|
+
/** Effect Schema for the settings object. */
|
|
41
|
+
schema: { ast: SchemaAST.AST };
|
|
42
|
+
|
|
43
|
+
/** Current settings values. */
|
|
44
|
+
values: T;
|
|
45
|
+
|
|
46
|
+
/** Callback when any value changes. Receives a new complete object. */
|
|
47
|
+
onValuesChanged?: (values: T) => void;
|
|
48
|
+
|
|
49
|
+
/** When true, all controls are disabled. */
|
|
50
|
+
readonly?: boolean;
|
|
51
|
+
|
|
52
|
+
/** Map of property names to custom field renderers. Nested objects map to struct sub-fields. */
|
|
53
|
+
fieldMap?: SettingsFieldMap<T>;
|
|
54
|
+
|
|
55
|
+
/** Control field visibility. Receives the dotted path (e.g. `'modelDefaults.edge'`) at every level. */
|
|
56
|
+
visible?: (path: string, values: T) => boolean;
|
|
57
|
+
|
|
58
|
+
/** Override the order of fields. Fields not listed are appended in schema order. Applied per scope. */
|
|
59
|
+
sort?: string[];
|
|
60
|
+
|
|
61
|
+
/** Internal: dot-path prefix used by recursive struct rendering. */
|
|
62
|
+
pathPrefix?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//
|
|
66
|
+
// Component
|
|
67
|
+
//
|
|
68
|
+
|
|
69
|
+
export const SettingsFieldSet = <T extends Record<string, any>>({
|
|
70
|
+
schema,
|
|
71
|
+
values,
|
|
72
|
+
onValuesChanged,
|
|
73
|
+
readonly,
|
|
74
|
+
fieldMap,
|
|
75
|
+
visible,
|
|
76
|
+
sort,
|
|
77
|
+
pathPrefix = '',
|
|
78
|
+
}: SettingsFieldSetProps<T>) => {
|
|
79
|
+
const properties = useMemo(() => {
|
|
80
|
+
const props = getFormProperties(schema.ast);
|
|
81
|
+
if (!sort) {
|
|
82
|
+
return props;
|
|
83
|
+
}
|
|
84
|
+
const rank = (name: string) => {
|
|
85
|
+
const idx = sort.indexOf(name);
|
|
86
|
+
return idx === -1 ? Number.POSITIVE_INFINITY : idx;
|
|
87
|
+
};
|
|
88
|
+
return [...props].sort(({ name: a }, { name: b }) => rank(a.toString()) - rank(b.toString()));
|
|
89
|
+
}, [schema, sort]);
|
|
90
|
+
|
|
91
|
+
const handleChange = useCallback(
|
|
92
|
+
(name: string, value: unknown) => {
|
|
93
|
+
onValuesChanged?.({ ...values, [name]: value } as T);
|
|
94
|
+
},
|
|
95
|
+
[values, onValuesChanged],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
{properties.map((property) => {
|
|
101
|
+
const name = property.name.toString();
|
|
102
|
+
const path = pathPrefix ? `${pathPrefix}.${name}` : name;
|
|
103
|
+
if (visible && !visible(path, values)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const entry = fieldMap?.[name as keyof typeof fieldMap] as
|
|
108
|
+
| React.FC<SettingsFieldProps>
|
|
109
|
+
| SettingsFieldMap
|
|
110
|
+
| undefined;
|
|
111
|
+
return (
|
|
112
|
+
<SettingsFieldItem
|
|
113
|
+
key={name}
|
|
114
|
+
path={path}
|
|
115
|
+
property={property}
|
|
116
|
+
value={values[name]}
|
|
117
|
+
onChange={(value) => handleChange(name, value)}
|
|
118
|
+
readonly={readonly}
|
|
119
|
+
customField={typeof entry === 'function' ? entry : undefined}
|
|
120
|
+
nestedFieldMap={typeof entry === 'object' ? entry : undefined}
|
|
121
|
+
visible={visible as (path: string, values: any) => boolean}
|
|
122
|
+
sort={sort}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
})}
|
|
126
|
+
</>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
SettingsFieldSet.displayName = 'Settings.FieldSet';
|
|
131
|
+
|
|
132
|
+
//
|
|
133
|
+
// Internal: render a single settings field.
|
|
134
|
+
//
|
|
135
|
+
|
|
136
|
+
type SettingsFieldItemProps = {
|
|
137
|
+
property: SchemaProperty;
|
|
138
|
+
path: string;
|
|
139
|
+
value: any;
|
|
140
|
+
onChange: (value: any) => void;
|
|
141
|
+
readonly?: boolean;
|
|
142
|
+
customField?: React.FC<SettingsFieldProps>;
|
|
143
|
+
nestedFieldMap?: SettingsFieldMap;
|
|
144
|
+
visible?: (path: string, values: any) => boolean;
|
|
145
|
+
sort?: string[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const SettingsFieldItem = ({
|
|
149
|
+
property,
|
|
150
|
+
path,
|
|
151
|
+
value,
|
|
152
|
+
onChange,
|
|
153
|
+
readonly,
|
|
154
|
+
customField,
|
|
155
|
+
nestedFieldMap,
|
|
156
|
+
visible,
|
|
157
|
+
sort,
|
|
158
|
+
}: SettingsFieldItemProps) => {
|
|
159
|
+
const { type } = property;
|
|
160
|
+
const name = property.name.toString();
|
|
161
|
+
const title = getAnnotation<string>(SchemaAST.TitleAnnotationId)(type) ?? String.capitalize(name);
|
|
162
|
+
const description = getAnnotation<string>(SchemaAST.DescriptionAnnotationId)(type);
|
|
163
|
+
|
|
164
|
+
// Custom field renderer.
|
|
165
|
+
if (customField) {
|
|
166
|
+
const CustomField = customField;
|
|
167
|
+
return (
|
|
168
|
+
<SettingsItem title={title} description={description}>
|
|
169
|
+
<CustomField value={value} onChange={onChange} readonly={readonly} />
|
|
170
|
+
</SettingsItem>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const fieldType = detectFieldType(type);
|
|
175
|
+
|
|
176
|
+
switch (fieldType) {
|
|
177
|
+
case 'struct':
|
|
178
|
+
return (
|
|
179
|
+
<SettingsFieldSet
|
|
180
|
+
schema={{ ast: type }}
|
|
181
|
+
values={value ?? {}}
|
|
182
|
+
onValuesChanged={onChange}
|
|
183
|
+
readonly={readonly}
|
|
184
|
+
fieldMap={nestedFieldMap}
|
|
185
|
+
visible={visible}
|
|
186
|
+
sort={sort}
|
|
187
|
+
pathPrefix={path}
|
|
188
|
+
/>
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
case 'boolean':
|
|
192
|
+
return (
|
|
193
|
+
<SettingsItem title={title} description={description}>
|
|
194
|
+
<Input.Switch disabled={readonly} checked={!!value} onCheckedChange={(checked) => onChange(!!checked)} />
|
|
195
|
+
</SettingsItem>
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
case 'select': {
|
|
199
|
+
const options = getSelectOptionsFromAst(type) ?? [];
|
|
200
|
+
return (
|
|
201
|
+
<SettingsItem title={title} description={description}>
|
|
202
|
+
<Select.Root
|
|
203
|
+
disabled={readonly}
|
|
204
|
+
value={value == null ? '' : globalThis.String(value)}
|
|
205
|
+
onValueChange={(selected) => {
|
|
206
|
+
const matched = options.find((option) => globalThis.String(option.value) === selected);
|
|
207
|
+
onChange(matched?.value ?? selected);
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
<Select.TriggerButton disabled={readonly} />
|
|
211
|
+
<Select.Portal>
|
|
212
|
+
<Select.Content>
|
|
213
|
+
<Select.Viewport>
|
|
214
|
+
{options.map((option: SelectOption) => (
|
|
215
|
+
<Select.Option key={globalThis.String(option.value)} value={globalThis.String(option.value)}>
|
|
216
|
+
{option.label ?? globalThis.String(option.value)}
|
|
217
|
+
</Select.Option>
|
|
218
|
+
))}
|
|
219
|
+
</Select.Viewport>
|
|
220
|
+
<Select.Arrow />
|
|
221
|
+
</Select.Content>
|
|
222
|
+
</Select.Portal>
|
|
223
|
+
</Select.Root>
|
|
224
|
+
</SettingsItem>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
case 'string':
|
|
229
|
+
return (
|
|
230
|
+
<SettingsItem title={title} description={description}>
|
|
231
|
+
<Input.TextInput disabled={readonly} value={value ?? ''} onChange={(event) => onChange(event.target.value)} />
|
|
232
|
+
</SettingsItem>
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
case 'number':
|
|
236
|
+
return (
|
|
237
|
+
<SettingsItem title={title} description={description}>
|
|
238
|
+
<Input.TextInput
|
|
239
|
+
disabled={readonly}
|
|
240
|
+
type='number'
|
|
241
|
+
value={value ?? ''}
|
|
242
|
+
onChange={(event) => {
|
|
243
|
+
if (event.target.value === '') {
|
|
244
|
+
onChange(undefined);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const parsed = Number(event.target.value);
|
|
248
|
+
onChange(Number.isNaN(parsed) ? undefined : parsed);
|
|
249
|
+
}}
|
|
250
|
+
/>
|
|
251
|
+
</SettingsItem>
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
default:
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type PropsWithChildren } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Input, type Label, type ThemedClassName, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
|
+
import { mx } from '@dxos/ui-theme';
|
|
9
|
+
|
|
10
|
+
import { translationKey } from '#translations';
|
|
11
|
+
|
|
12
|
+
const SETTINGS_PANEL_NAME = 'Settings.Panel';
|
|
13
|
+
const SETTINGS_ITEM_NAME = 'Settings.Item';
|
|
14
|
+
|
|
15
|
+
//
|
|
16
|
+
// Panel (bordered card container).
|
|
17
|
+
//
|
|
18
|
+
|
|
19
|
+
type SettingsPanelProps = ThemedClassName<PropsWithChildren>;
|
|
20
|
+
|
|
21
|
+
export const SettingsPanel = ({ classNames, children }: SettingsPanelProps) => {
|
|
22
|
+
return (
|
|
23
|
+
<div className={mx('flex flex-col gap-3 p-trim-md border border-separator rounded-sm', classNames)}>{children}</div>
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
SettingsPanel.displayName = SETTINGS_PANEL_NAME;
|
|
28
|
+
|
|
29
|
+
//
|
|
30
|
+
// Item (label + optional description + control, proper label semantics).
|
|
31
|
+
//
|
|
32
|
+
|
|
33
|
+
type SettingsItemProps = PropsWithChildren<{
|
|
34
|
+
title: Label;
|
|
35
|
+
description?: Label;
|
|
36
|
+
}>;
|
|
37
|
+
|
|
38
|
+
export const SettingsItem = ({ title, description = '', children }: SettingsItemProps) => {
|
|
39
|
+
const { t } = useTranslation(translationKey);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Input.Root>
|
|
43
|
+
<SettingsPanel classNames='grid grid-cols-1 md:grid-cols-[1fr_1fr] gap-x-trim-lg gap-y-0'>
|
|
44
|
+
<Input.Label classNames='pb-trim-md text-base-foreground text-lg md:col-span-2'>
|
|
45
|
+
{toLocalizedString(title, t)}
|
|
46
|
+
</Input.Label>
|
|
47
|
+
<Input.DescriptionAndValidation>
|
|
48
|
+
<Input.Description classNames='text-base text-description'>
|
|
49
|
+
{toLocalizedString(description, t)}
|
|
50
|
+
</Input.Description>
|
|
51
|
+
</Input.DescriptionAndValidation>
|
|
52
|
+
<div className='text-end py-1'>{children}</div>
|
|
53
|
+
</SettingsPanel>
|
|
54
|
+
</Input.Root>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
SettingsItem.displayName = SETTINGS_ITEM_NAME;
|