@dxos/plugin-settings 0.6.8-main.046e6cf
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 +8 -0
- package/README.md +15 -0
- package/dist/lib/browser/chunk-JKQMH66V.mjs +11 -0
- package/dist/lib/browser/chunk-JKQMH66V.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +253 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/meta.mjs +9 -0
- package/dist/lib/browser/meta.mjs.map +7 -0
- package/dist/lib/node/chunk-LZVHLML4.cjs +34 -0
- package/dist/lib/node/chunk-LZVHLML4.cjs.map +7 -0
- package/dist/lib/node/index.cjs +274 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.cjs +30 -0
- package/dist/lib/node/meta.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/types/src/SettingsPlugin.d.ts +7 -0
- package/dist/types/src/SettingsPlugin.d.ts.map +1 -0
- package/dist/types/src/components/SettingsDialog.d.ts +6 -0
- package/dist/types/src/components/SettingsDialog.d.ts.map +1 -0
- package/dist/types/src/components/SettingsValue.d.ts +9 -0
- package/dist/types/src/components/SettingsValue.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +6 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +12 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/package.json +62 -0
- package/src/SettingsPlugin.tsx +124 -0
- package/src/components/SettingsDialog.tsx +120 -0
- package/src/components/SettingsValue.tsx +49 -0
- package/src/components/index.ts +6 -0
- package/src/index.ts +13 -0
- package/src/meta.ts +9 -0
- package/src/translations.ts +18 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Gear, type IconProps } from '@phosphor-icons/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type IntentResolverProvides,
|
|
10
|
+
type PluginDefinition,
|
|
11
|
+
type SurfaceProvides,
|
|
12
|
+
parseIntentPlugin,
|
|
13
|
+
resolvePlugin,
|
|
14
|
+
LayoutAction,
|
|
15
|
+
SettingsAction,
|
|
16
|
+
type GraphBuilderProvides,
|
|
17
|
+
type TranslationsProvides,
|
|
18
|
+
} from '@dxos/app-framework';
|
|
19
|
+
import { LocalStorageStore } from '@dxos/local-storage';
|
|
20
|
+
import { createExtension, type Node } from '@dxos/plugin-graph';
|
|
21
|
+
|
|
22
|
+
import { SettingsDialog } from './components';
|
|
23
|
+
import meta, { SETTINGS_PLUGIN } from './meta';
|
|
24
|
+
import translations from './translations';
|
|
25
|
+
|
|
26
|
+
const DEFAULT_PLUGIN = 'dxos.org/plugin/registry';
|
|
27
|
+
|
|
28
|
+
export type SettingsPluginProvides = SurfaceProvides &
|
|
29
|
+
IntentResolverProvides &
|
|
30
|
+
GraphBuilderProvides &
|
|
31
|
+
TranslationsProvides;
|
|
32
|
+
|
|
33
|
+
type SettingsSettingsProps = {
|
|
34
|
+
selected: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Plugin for aggregating and rendering plugin settings.
|
|
39
|
+
*/
|
|
40
|
+
export const SettingsPlugin = (): PluginDefinition<SettingsPluginProvides> => {
|
|
41
|
+
const settings = new LocalStorageStore<SettingsSettingsProps>(SETTINGS_PLUGIN, { selected: DEFAULT_PLUGIN });
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
meta,
|
|
45
|
+
ready: async () => {
|
|
46
|
+
settings.prop({ key: 'selected', type: LocalStorageStore.string() });
|
|
47
|
+
},
|
|
48
|
+
provides: {
|
|
49
|
+
surface: {
|
|
50
|
+
component: ({ data }) => {
|
|
51
|
+
switch (data.component) {
|
|
52
|
+
case `${SETTINGS_PLUGIN}/Settings`:
|
|
53
|
+
return (
|
|
54
|
+
<SettingsDialog
|
|
55
|
+
selected={settings.values.selected}
|
|
56
|
+
onSelected={(selected) => (settings.values.selected = selected)}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
default:
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
intent: {
|
|
66
|
+
resolver: (intent) => {
|
|
67
|
+
switch (intent.action) {
|
|
68
|
+
case SettingsAction.OPEN: {
|
|
69
|
+
if (intent.data?.plugin) {
|
|
70
|
+
settings.values.selected = intent.data?.plugin;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
intents: [
|
|
75
|
+
[
|
|
76
|
+
{
|
|
77
|
+
action: LayoutAction.SET_LAYOUT,
|
|
78
|
+
data: {
|
|
79
|
+
element: 'dialog',
|
|
80
|
+
component: `${SETTINGS_PLUGIN}/Settings`,
|
|
81
|
+
dialogBlockAlign: 'start',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
graph: {
|
|
92
|
+
builder: (plugins) => {
|
|
93
|
+
const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
|
|
94
|
+
|
|
95
|
+
return createExtension({
|
|
96
|
+
id: SETTINGS_PLUGIN,
|
|
97
|
+
filter: (node): node is Node<null> => node.id === 'root',
|
|
98
|
+
actions: () => [
|
|
99
|
+
{
|
|
100
|
+
id: SETTINGS_PLUGIN,
|
|
101
|
+
data: async () => {
|
|
102
|
+
await intentPlugin?.provides.intent.dispatch({
|
|
103
|
+
plugin: SETTINGS_PLUGIN,
|
|
104
|
+
action: SettingsAction.OPEN,
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
properties: {
|
|
108
|
+
label: ['open settings label', { ns: SETTINGS_PLUGIN }],
|
|
109
|
+
icon: (props: IconProps) => <Gear {...props} />,
|
|
110
|
+
iconSymbol: 'ph--gear--regular',
|
|
111
|
+
keyBinding: {
|
|
112
|
+
macos: 'meta+,',
|
|
113
|
+
windows: 'alt+,',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
translations,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Plugin, Surface, usePlugins } from '@dxos/app-framework';
|
|
8
|
+
import { Button, Dialog, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
import { Tabs, type TabsActivePart } from '@dxos/react-ui-tabs';
|
|
10
|
+
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
11
|
+
import { nonNullable } from '@dxos/util';
|
|
12
|
+
|
|
13
|
+
import { SETTINGS_PLUGIN } from '../meta';
|
|
14
|
+
|
|
15
|
+
export const SettingsDialog = ({
|
|
16
|
+
selected,
|
|
17
|
+
onSelected,
|
|
18
|
+
}: {
|
|
19
|
+
selected: string;
|
|
20
|
+
onSelected: (plugin: string) => void;
|
|
21
|
+
}) => {
|
|
22
|
+
const { t } = useTranslation(SETTINGS_PLUGIN);
|
|
23
|
+
const { plugins, enabled } = usePlugins();
|
|
24
|
+
|
|
25
|
+
// TODO(burdon): Factor out common defs?
|
|
26
|
+
const core = [
|
|
27
|
+
'dxos.org/plugin/layout',
|
|
28
|
+
'dxos.org/plugin/deck',
|
|
29
|
+
'dxos.org/plugin/files',
|
|
30
|
+
'dxos.org/plugin/space',
|
|
31
|
+
'dxos.org/plugin/stack',
|
|
32
|
+
'dxos.org/plugin/observability',
|
|
33
|
+
'dxos.org/plugin/registry',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const corePlugins = core.map((id) => plugins.find((plugin) => plugin.meta.id === id)?.meta).filter(nonNullable);
|
|
37
|
+
|
|
38
|
+
const filteredPlugins = enabled
|
|
39
|
+
.filter((id) => !core.includes(id))
|
|
40
|
+
.map((id) => plugins.find((plugin) => plugin.meta.id === id))
|
|
41
|
+
.filter((plugin) => (plugin?.provides as any)?.settings)
|
|
42
|
+
.map((plugin) => plugin!.meta)
|
|
43
|
+
.sort(({ name: a }, { name: b }) => a?.localeCompare(b ?? '') ?? 0);
|
|
44
|
+
|
|
45
|
+
const [tabsActivePart, setTabsActivePart] = useState<TabsActivePart>('list');
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Dialog.Content classNames='p-0 bs-content max-bs-full md:max-is-[40rem] overflow-hidden'>
|
|
49
|
+
<div role='none' className='flex justify-between mbe-1 pbs-3 pis-2 pie-3 @md:pbs-4 @md:pis-4 @md:pie-5'>
|
|
50
|
+
<Dialog.Title
|
|
51
|
+
onClick={() => setTabsActivePart('list')}
|
|
52
|
+
aria-description={t('click to return to tablist description')}
|
|
53
|
+
classNames='flex cursor-pointer items-center group/title'
|
|
54
|
+
>
|
|
55
|
+
<svg className={mx('@md:hidden', getSize(4), tabsActivePart === 'list' && 'invisible')}>
|
|
56
|
+
<use href='/icons.svg#ph--caret-left--regular' />
|
|
57
|
+
</svg>
|
|
58
|
+
<span
|
|
59
|
+
className={
|
|
60
|
+
tabsActivePart !== 'list'
|
|
61
|
+
? 'group-hover/title:underline @md:group-hover/title:no-underline underline-offset-4 decoration-1'
|
|
62
|
+
: ''
|
|
63
|
+
}
|
|
64
|
+
>
|
|
65
|
+
{t('settings dialog title')}
|
|
66
|
+
</span>
|
|
67
|
+
</Dialog.Title>
|
|
68
|
+
<Dialog.Close asChild>
|
|
69
|
+
<Button density='fine' variant='ghost' autoFocus>
|
|
70
|
+
<svg className={mx(getSize(3))}>
|
|
71
|
+
<use href={'/icons.svg#ph--x--regular'} />
|
|
72
|
+
</svg>
|
|
73
|
+
</Button>
|
|
74
|
+
</Dialog.Close>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<Tabs.Root
|
|
78
|
+
orientation='vertical'
|
|
79
|
+
value={selected}
|
|
80
|
+
onValueChange={(nextSelected) => onSelected(nextSelected)}
|
|
81
|
+
activePart={tabsActivePart}
|
|
82
|
+
onActivePartChange={setTabsActivePart}
|
|
83
|
+
classNames='flex flex-col flex-1 mbs-2'
|
|
84
|
+
>
|
|
85
|
+
<Tabs.Viewport classNames='flex-1 min-bs-0'>
|
|
86
|
+
<div role='none' className='overflow-y-auto pli-3 @md:pis-2 @md:pie-0 mbe-4 border-r separator-separator'>
|
|
87
|
+
<Tabs.Tablist classNames='max-bs-none overflow-y-visible'>
|
|
88
|
+
<PluginList title='Options' plugins={corePlugins} />
|
|
89
|
+
{filteredPlugins.length > 0 && <PluginList title='Plugins' plugins={filteredPlugins} gap />}
|
|
90
|
+
</Tabs.Tablist>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
{corePlugins.map((plugin) => (
|
|
94
|
+
<Tabs.Tabpanel key={plugin.id} value={plugin.id} classNames='pli-3 @md:pli-5 max-bs-dvh overflow-y-auto'>
|
|
95
|
+
<Surface role='settings' data={{ plugin: plugin.id }} />
|
|
96
|
+
</Tabs.Tabpanel>
|
|
97
|
+
))}
|
|
98
|
+
{filteredPlugins.map((plugin) => (
|
|
99
|
+
<Tabs.Tabpanel key={plugin.id} value={plugin.id} classNames='pli-3 @md:pli-5 max-bs-dvh overflow-y-auto'>
|
|
100
|
+
<Surface role='settings' data={{ plugin: plugin.id }} />
|
|
101
|
+
</Tabs.Tabpanel>
|
|
102
|
+
))}
|
|
103
|
+
</Tabs.Viewport>
|
|
104
|
+
</Tabs.Root>
|
|
105
|
+
</Dialog.Content>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const PluginList = ({ title, plugins, gap }: { title: string; plugins: Plugin['meta'][]; gap?: boolean }) => {
|
|
110
|
+
return (
|
|
111
|
+
<>
|
|
112
|
+
<Tabs.TabGroupHeading classNames={gap ? 'mbs-4' : 'mbs-4 @md:mbs-2'}>{title}</Tabs.TabGroupHeading>
|
|
113
|
+
{plugins.map((plugin) => (
|
|
114
|
+
<Tabs.Tab key={plugin.id} value={plugin.id}>
|
|
115
|
+
{plugin.name}
|
|
116
|
+
</Tabs.Tab>
|
|
117
|
+
))}
|
|
118
|
+
</>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type JSX, type PropsWithChildren } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Input } from '@dxos/react-ui';
|
|
8
|
+
|
|
9
|
+
type SettingValueProps = {
|
|
10
|
+
label: string;
|
|
11
|
+
description?: JSX.Element;
|
|
12
|
+
secondary?: JSX.Element;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const SettingsValue = ({ label, description, secondary, children }: PropsWithChildren<SettingValueProps>) => {
|
|
16
|
+
const primary = (
|
|
17
|
+
<div role='none' className='flex w-full gap-4 py-1'>
|
|
18
|
+
<Input.Root>
|
|
19
|
+
<div role='none' className='flex flex-col w-full'>
|
|
20
|
+
{/* TODO(burdon): Consistent height for controls (e.g., Select, Textbox, and Checkbox are all different). */}
|
|
21
|
+
<Input.Label classNames='flex min-h-[40px] items-center'>{label}</Input.Label>
|
|
22
|
+
{description && (
|
|
23
|
+
<Input.DescriptionAndValidation classNames='mbs-0.5'>
|
|
24
|
+
<Input.Description>{description}</Input.Description>
|
|
25
|
+
</Input.DescriptionAndValidation>
|
|
26
|
+
)}
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<div role='none'>
|
|
30
|
+
<div role='none' className='flex min-h-[40px] items-center'>
|
|
31
|
+
{children}
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</Input.Root>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (secondary) {
|
|
39
|
+
// console.log(secondary);
|
|
40
|
+
return (
|
|
41
|
+
<div role='none' className='flex flex-col w-full'>
|
|
42
|
+
{primary}
|
|
43
|
+
{secondary}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return primary;
|
|
49
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { SettingsPlugin } from './SettingsPlugin';
|
|
6
|
+
|
|
7
|
+
export default SettingsPlugin;
|
|
8
|
+
|
|
9
|
+
export * from './SettingsPlugin';
|
|
10
|
+
|
|
11
|
+
// TODO(wittjosiah): Remove.
|
|
12
|
+
// Settings should be exposed from plugins as state and intents rather than components.
|
|
13
|
+
export * from './components';
|
package/src/meta.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { SETTINGS_PLUGIN } from './meta';
|
|
6
|
+
|
|
7
|
+
export default [
|
|
8
|
+
{
|
|
9
|
+
'en-US': {
|
|
10
|
+
[SETTINGS_PLUGIN]: {
|
|
11
|
+
'open settings label': 'Show settings',
|
|
12
|
+
'settings dialog title': 'Settings',
|
|
13
|
+
'back label': 'Back',
|
|
14
|
+
'click to return to tablist description': 'Click the title to return to the settings menu',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
];
|