@dxos/react-ui-form 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +2008 -840
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +83 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2008 -840
- 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 +85 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts +2 -2
- package/dist/types/src/components/FieldEditor/FieldEditor.d.ts.map +1 -1
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts +64 -61
- package/dist/types/src/components/FieldEditor/FieldEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.d.ts +71 -17
- package/dist/types/src/components/Form/Form.d.ts.map +1 -1
- package/dist/types/src/components/Form/Form.stories.d.ts +148 -86
- package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormField.d.ts +24 -8
- package/dist/types/src/components/Form/FormField.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormFieldComponent.d.ts +26 -13
- 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 +11 -9
- package/dist/types/src/components/Form/FormFieldSet.d.ts.map +1 -1
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts +19 -0
- package/dist/types/src/components/Form/FormTooltipsContext.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts +50 -0
- package/dist/types/src/components/Form/Layout/FormLayout.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts +119 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.stories.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/FormLayout.test.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts +30 -0
- package/dist/types/src/components/Form/Layout/annotation.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/index.d.ts +4 -0
- package/dist/types/src/components/Form/Layout/index.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts +31 -0
- package/dist/types/src/components/Form/Layout/parser.d.ts.map +1 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts +2 -0
- package/dist/types/src/components/Form/Layout/parser.test.d.ts.map +1 -0
- 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/DateField.d.ts +4 -0
- package/dist/types/src/components/Form/fields/DateField.d.ts.map +1 -0
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts +1 -1
- package/dist/types/src/components/Form/fields/GeoPointField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts +13 -0
- package/dist/types/src/components/Form/fields/InlineRefField.d.ts.map +1 -0
- 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 +85 -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 +12 -6
- package/dist/types/src/components/Form/fields/RefField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts +4 -1
- package/dist/types/src/components/Form/fields/SelectField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/SelectOptionField.d.ts +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 +64 -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 +1 -1
- package/dist/types/src/components/Form/fields/TupleField.d.ts.map +1 -1
- package/dist/types/src/components/Form/fields/index.d.ts +2 -0
- package/dist/types/src/components/Form/fields/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/index.d.ts +3 -0
- package/dist/types/src/components/Form/index.d.ts.map +1 -1
- package/dist/types/src/components/Form/meta-tags.d.ts +30 -0
- package/dist/types/src/components/Form/meta-tags.d.ts.map +1 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts +2 -0
- package/dist/types/src/components/Form/meta-tags.test.d.ts.map +1 -0
- package/dist/types/src/components/ObjectForm/ObjectForm.d.ts +8 -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 +28 -6
- package/dist/types/src/components/ObjectPicker/ObjectPicker.d.ts.map +1 -1
- package/dist/types/src/components/ObjectPicker/ObjectPicker.stories.d.ts +64 -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 +128 -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/ObjectTree/ObjectTree.d.ts +9 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts +87 -0
- package/dist/types/src/components/ObjectTree/ObjectTree.stories.d.ts.map +1 -0
- package/dist/types/src/components/ObjectTree/index.d.ts +2 -0
- package/dist/types/src/components/ObjectTree/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 +65 -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 +9 -11
- package/dist/types/src/components/ViewEditor/ViewEditor.d.ts.map +1 -1
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts +68 -66
- package/dist/types/src/components/ViewEditor/ViewEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +13 -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 +64 -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 +18 -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 +48 -41
- package/src/components/FieldEditor/FieldEditor.stories.tsx +4 -4
- package/src/components/FieldEditor/FieldEditor.test.tsx +4 -2
- package/src/components/FieldEditor/FieldEditor.tsx +23 -17
- package/src/components/Form/AUDIT.md +17 -0
- package/src/components/Form/Form.stories.tsx +46 -65
- package/src/components/Form/Form.tsx +176 -60
- package/src/components/Form/FormField.tsx +107 -38
- package/src/components/Form/FormFieldComponent.tsx +77 -20
- package/src/components/Form/FormFieldSet.tsx +128 -78
- package/src/components/Form/FormTooltipsContext.ts +25 -0
- package/src/components/Form/Layout/FormLayout.stories.test.tsx +51 -0
- package/src/components/Form/Layout/FormLayout.stories.tsx +422 -0
- package/src/components/Form/Layout/FormLayout.test.ts +59 -0
- package/src/components/Form/Layout/FormLayout.tsx +251 -0
- package/src/components/Form/Layout/annotation.ts +38 -0
- package/src/components/Form/Layout/index.ts +7 -0
- package/src/components/Form/Layout/parser.test.ts +120 -0
- package/src/components/Form/Layout/parser.ts +167 -0
- package/src/components/Form/fields/ArrayField.tsx +64 -35
- package/src/components/Form/fields/DateField.tsx +101 -0
- package/src/components/Form/fields/GeoPointField.tsx +12 -8
- package/src/components/Form/fields/InlineRefField.tsx +146 -0
- 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 +83 -42
- package/src/components/Form/fields/SelectField.tsx +17 -5
- package/src/components/Form/fields/SelectOptionField.stories.tsx +8 -6
- package/src/components/Form/fields/SelectOptionField.tsx +14 -13
- package/src/components/Form/fields/TextAreaField.tsx +1 -1
- package/src/components/Form/fields/TextField.tsx +2 -2
- package/src/components/Form/fields/TupleField.tsx +3 -2
- package/src/components/Form/fields/index.ts +2 -0
- package/src/components/Form/index.ts +3 -0
- package/src/components/Form/meta-tags.test.ts +47 -0
- package/src/components/Form/meta-tags.ts +33 -0
- package/src/components/ObjectForm/ObjectForm.tsx +109 -0
- package/src/components/ObjectForm/index.ts +5 -0
- package/src/components/ObjectPicker/ObjectPicker.stories.tsx +13 -11
- package/src/components/ObjectPicker/ObjectPicker.tsx +93 -66
- package/src/components/ObjectProperties/ObjectProperties.stories.tsx +350 -0
- package/src/components/ObjectProperties/ObjectProperties.test.tsx +111 -0
- package/src/components/ObjectProperties/ObjectProperties.tsx +144 -0
- package/src/components/ObjectProperties/index.ts +5 -0
- package/src/components/ObjectTree/ObjectTree.stories.tsx +134 -0
- package/src/components/ObjectTree/ObjectTree.tsx +190 -0
- package/src/components/ObjectTree/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 +32 -181
- 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 +45 -51
- package/src/components/ViewEditor/ViewEditor.test.tsx +11 -9
- package/src/components/ViewEditor/ViewEditor.tsx +45 -55
- package/src/components/index.ts +3 -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 +67 -63
- package/src/util/field-type.ts +60 -0
- package/src/util/index.ts +1 -0
- package/src/util/properties.test.ts +121 -0
- package/src/util/properties.ts +47 -4
- package/src/util/refs.ts +7 -3
- package/src/vite-env.d.ts +10 -0
|
@@ -4,213 +4,68 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type PropsWithChildren } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
type ButtonProps,
|
|
10
|
-
Input,
|
|
11
|
-
type Label,
|
|
12
|
-
ScrollArea,
|
|
13
|
-
type ThemedClassName,
|
|
14
|
-
toLocalizedString,
|
|
15
|
-
useTranslation,
|
|
16
|
-
} from '@dxos/react-ui';
|
|
7
|
+
import { type Label, ScrollArea, type ThemedClassName, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
8
|
+
import { composable, composableProps } from '@dxos/react-ui';
|
|
17
9
|
import { mx } from '@dxos/ui-theme';
|
|
18
10
|
|
|
19
|
-
import { translationKey } from '
|
|
11
|
+
import { translationKey } from '#translations';
|
|
12
|
+
|
|
13
|
+
import { SettingsFieldSet } from './SettingsFieldSet';
|
|
14
|
+
import { SettingsItem, SettingsPanel } from './SettingsItem';
|
|
20
15
|
|
|
21
16
|
const SETTINGS_ROOT_NAME = 'Settings.Root';
|
|
17
|
+
const SETTINGS_VIEWPORT_NAME = 'Settings.Viewport';
|
|
22
18
|
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
19
|
|
|
38
20
|
//
|
|
39
|
-
// Root
|
|
21
|
+
// Root (headless — no styling, no scroll).
|
|
40
22
|
//
|
|
41
23
|
|
|
42
|
-
type SettingsRootProps = PropsWithChildren
|
|
24
|
+
type SettingsRootProps = ThemedClassName<PropsWithChildren>;
|
|
43
25
|
|
|
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
|
-
);
|
|
26
|
+
const SettingsRoot = ({ children, classNames }: SettingsRootProps) => {
|
|
27
|
+
return <div className={mx('flex flex-col gap-2', classNames)}>{children}</div>;
|
|
50
28
|
};
|
|
51
29
|
|
|
52
30
|
SettingsRoot.displayName = SETTINGS_ROOT_NAME;
|
|
53
31
|
|
|
54
32
|
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
type SettingsSectionProps = PropsWithChildren<{
|
|
59
|
-
title: Label;
|
|
60
|
-
description?: Label;
|
|
61
|
-
}>;
|
|
62
|
-
|
|
63
|
-
const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
|
|
64
|
-
return (
|
|
65
|
-
<>
|
|
66
|
-
<SettingsSectionHeading title={title} description={description} />
|
|
67
|
-
<div className='w-full pt-trim-md space-y-trim-md'>{children}</div>
|
|
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
|
|
33
|
+
// Viewport (scroll area + padding + document layout).
|
|
102
34
|
//
|
|
103
35
|
|
|
104
|
-
|
|
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>) => {
|
|
36
|
+
const SettingsViewport = composable<HTMLDivElement>(({ children, ...props }, forwardedRef) => {
|
|
149
37
|
return (
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
'border border-separator rounded-md',
|
|
156
|
-
classNames,
|
|
157
|
-
])}
|
|
158
|
-
>
|
|
159
|
-
{children}
|
|
160
|
-
</div>
|
|
38
|
+
<ScrollArea.Root {...composableProps(props)} orientation='vertical' centered thin ref={forwardedRef}>
|
|
39
|
+
<ScrollArea.Viewport classNames='px-4 pointer-coarse:px-2'>
|
|
40
|
+
<div className='dx-document flex flex-col gap-2 py-4'>{children}</div>
|
|
41
|
+
</ScrollArea.Viewport>
|
|
42
|
+
</ScrollArea.Root>
|
|
161
43
|
);
|
|
162
|
-
};
|
|
44
|
+
});
|
|
163
45
|
|
|
164
|
-
|
|
46
|
+
SettingsViewport.displayName = SETTINGS_VIEWPORT_NAME;
|
|
165
47
|
|
|
166
48
|
//
|
|
167
|
-
//
|
|
49
|
+
// Section (title + optional description + children with spacing).
|
|
168
50
|
//
|
|
169
51
|
|
|
170
|
-
type
|
|
52
|
+
type SettingsSectionProps = PropsWithChildren<{
|
|
171
53
|
title: Label;
|
|
172
54
|
description?: Label;
|
|
173
55
|
}>;
|
|
174
56
|
|
|
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) => {
|
|
57
|
+
const SettingsSection = ({ title, description, children }: SettingsSectionProps) => {
|
|
196
58
|
const { t } = useTranslation(translationKey);
|
|
197
|
-
|
|
198
59
|
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>
|
|
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
|
+
</>
|
|
210
65
|
);
|
|
211
66
|
};
|
|
212
67
|
|
|
213
|
-
|
|
68
|
+
SettingsSection.displayName = SETTINGS_SECTION_NAME;
|
|
214
69
|
|
|
215
70
|
//
|
|
216
71
|
// Settings
|
|
@@ -218,13 +73,9 @@ SettingsItemInput.displayName = SETTINGS_ITEM_INPUT_NAME;
|
|
|
218
73
|
|
|
219
74
|
export const Settings = {
|
|
220
75
|
Root: SettingsRoot,
|
|
76
|
+
Viewport: SettingsViewport,
|
|
221
77
|
Section: SettingsSection,
|
|
222
|
-
|
|
223
|
-
Group: SettingsGroup,
|
|
224
|
-
GroupButton: SettingsGroupButton,
|
|
225
|
-
Container: SettingsContainer,
|
|
226
|
-
Frame: SettingsFrame,
|
|
227
|
-
FrameItem: SettingsFrameItem,
|
|
78
|
+
Panel: SettingsPanel,
|
|
228
79
|
Item: SettingsItem,
|
|
229
|
-
|
|
80
|
+
FieldSet: SettingsFieldSet,
|
|
230
81
|
};
|
|
@@ -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-fg 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;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { Select } from '@dxos/react-ui';
|
|
8
|
+
|
|
9
|
+
import { type SettingsFieldProps } from './SettingsFieldSet';
|
|
10
|
+
|
|
11
|
+
export type SelectFieldOption = {
|
|
12
|
+
value: string;
|
|
13
|
+
label?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type CreateSelectFieldOptions = {
|
|
17
|
+
/** Options to display. Strings are used as both value and label. */
|
|
18
|
+
options: ReadonlyArray<string | SelectFieldOption>;
|
|
19
|
+
/** Label for the sentinel option that maps to `undefined`. Defaults to `'Default'`. Pass `null` to omit. */
|
|
20
|
+
defaultLabel?: string | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Factory for a `SettingsFieldSet` `fieldMap` entry that renders a Select control
|
|
25
|
+
* over a fixed list of options, with an optional sentinel for `undefined`.
|
|
26
|
+
*/
|
|
27
|
+
export const createSelectField = ({
|
|
28
|
+
options,
|
|
29
|
+
defaultLabel = 'Default',
|
|
30
|
+
}: CreateSelectFieldOptions): React.FC<SettingsFieldProps<string | undefined>> => {
|
|
31
|
+
const normalized = options.map((option) => (typeof option === 'string' ? { value: option, label: option } : option));
|
|
32
|
+
const hasDefault = defaultLabel !== null;
|
|
33
|
+
// Per-instance sentinel avoids collisions with real option values; empty string when the
|
|
34
|
+
// sentinel is omitted so `undefined` maps to a value Select.Root treats as "no selection".
|
|
35
|
+
const sentinel = hasDefault ? `__default__${Math.random().toString(36).slice(2)}` : '';
|
|
36
|
+
|
|
37
|
+
return ({ value, onChange, readonly }) => (
|
|
38
|
+
<Select.Root
|
|
39
|
+
disabled={readonly}
|
|
40
|
+
value={value ?? sentinel}
|
|
41
|
+
onValueChange={(next) => onChange(hasDefault && next === sentinel ? undefined : next)}
|
|
42
|
+
>
|
|
43
|
+
<Select.TriggerButton disabled={readonly} />
|
|
44
|
+
<Select.Portal>
|
|
45
|
+
<Select.Content>
|
|
46
|
+
<Select.Viewport>
|
|
47
|
+
{hasDefault && <Select.Option value={sentinel}>{defaultLabel}</Select.Option>}
|
|
48
|
+
{normalized.map((option) => (
|
|
49
|
+
<Select.Option key={option.value} value={option.value}>
|
|
50
|
+
{option.label ?? option.value}
|
|
51
|
+
</Select.Option>
|
|
52
|
+
))}
|
|
53
|
+
</Select.Viewport>
|
|
54
|
+
<Select.Arrow />
|
|
55
|
+
</Select.Content>
|
|
56
|
+
</Select.Portal>
|
|
57
|
+
</Select.Root>
|
|
58
|
+
);
|
|
59
|
+
};
|