@dxos/plugin-registry 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33
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/dist/lib/browser/cli/index.mjs +179 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +37 -63
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +35 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +181 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +47 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/translations.mjs +37 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/RegistryPlugin.d.ts +2 -1
- package/dist/types/src/RegistryPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +6 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/capabilities/state.d.ts +7 -0
- package/dist/types/src/capabilities/state.d.ts.map +1 -0
- package/dist/types/src/cli/commands/disable.d.ts +11 -0
- package/dist/types/src/cli/commands/disable.d.ts.map +1 -0
- package/dist/types/src/cli/commands/enable.d.ts +11 -0
- package/dist/types/src/cli/commands/enable.d.ts.map +1 -0
- package/dist/types/src/cli/commands/index.d.ts +3 -0
- package/dist/types/src/cli/commands/index.d.ts.map +1 -0
- package/dist/types/src/cli/commands/list.d.ts +7 -0
- package/dist/types/src/cli/commands/list.d.ts.map +1 -0
- package/dist/types/src/cli/commands/util.d.ts +11 -0
- package/dist/types/src/cli/commands/util.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +3 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/plugin.d.ts +3 -0
- package/dist/types/src/cli/plugin.d.ts.map +1 -0
- package/dist/types/src/cli/storage.d.ts +18 -0
- package/dist/types/src/cli/storage.d.ts.map +1 -0
- package/dist/types/src/components/PluginDetail/PluginDetail.d.ts +22 -0
- package/dist/types/src/components/PluginDetail/PluginDetail.d.ts.map +1 -0
- package/dist/types/src/components/PluginDetail/PluginDetail.stories.d.ts +42 -0
- package/dist/types/src/components/PluginDetail/PluginDetail.stories.d.ts.map +1 -0
- package/dist/types/src/components/PluginDetail/index.d.ts +2 -0
- package/dist/types/src/components/PluginDetail/index.d.ts.map +1 -0
- package/dist/types/src/components/PluginList/PluginItem.d.ts +26 -0
- package/dist/types/src/components/PluginList/PluginItem.d.ts.map +1 -0
- package/dist/types/src/components/PluginList/PluginList.d.ts +13 -0
- package/dist/types/src/components/PluginList/PluginList.d.ts.map +1 -0
- package/dist/types/src/components/PluginList/PluginList.stories.d.ts +41 -0
- package/dist/types/src/components/PluginList/PluginList.stories.d.ts.map +1 -0
- package/dist/types/src/components/PluginList/index.d.ts +2 -0
- package/dist/types/src/components/PluginList/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/CommunityRegistry/CommunityRegistry.d.ts +8 -0
- package/dist/types/src/containers/CommunityRegistry/CommunityRegistry.d.ts.map +1 -0
- package/dist/types/src/containers/CommunityRegistry/index.d.ts +2 -0
- package/dist/types/src/containers/CommunityRegistry/index.d.ts.map +1 -0
- package/dist/types/src/containers/LoadPluginDialog/LoadPluginDialog.d.ts +4 -0
- package/dist/types/src/containers/LoadPluginDialog/LoadPluginDialog.d.ts.map +1 -0
- package/dist/types/src/containers/LoadPluginDialog/index.d.ts +2 -0
- package/dist/types/src/containers/LoadPluginDialog/index.d.ts.map +1 -0
- package/dist/types/src/containers/PluginArticle/PluginArticle.d.ts +7 -0
- package/dist/types/src/containers/PluginArticle/PluginArticle.d.ts.map +1 -0
- package/dist/types/src/containers/PluginArticle/index.d.ts +2 -0
- package/dist/types/src/containers/PluginArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/PluginRegistry/PluginRegistry.d.ts +14 -0
- package/dist/types/src/containers/PluginRegistry/PluginRegistry.d.ts.map +1 -0
- package/dist/types/src/containers/PluginRegistry/index.d.ts +2 -0
- package/dist/types/src/containers/PluginRegistry/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +7 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/use-auto-tags.d.ts +20 -0
- package/dist/types/src/hooks/use-auto-tags.d.ts.map +1 -0
- package/dist/types/src/hooks/use-community-plugins.d.ts +16 -0
- package/dist/types/src/hooks/use-community-plugins.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +7 -4
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/open-plugin-registry.d.ts +5 -0
- package/dist/types/src/operations/open-plugin-registry.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +22 -16
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +14 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +71 -37
- package/src/RegistryPlugin.tsx +17 -27
- package/src/capabilities/app-graph-builder.ts +173 -135
- package/src/capabilities/index.ts +9 -4
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +108 -78
- package/src/capabilities/state.ts +40 -0
- package/src/cli/commands/disable.ts +47 -0
- package/src/cli/commands/enable.ts +44 -0
- package/src/cli/commands/index.ts +14 -0
- package/src/cli/commands/list.ts +41 -0
- package/src/cli/commands/util.ts +24 -0
- package/src/cli/index.ts +6 -0
- package/src/cli/plugin.ts +17 -0
- package/src/cli/storage.ts +50 -0
- package/src/components/PluginDetail/PluginDetail.stories.tsx +44 -0
- package/src/components/PluginDetail/PluginDetail.tsx +106 -0
- package/src/components/PluginDetail/index.ts +5 -0
- package/src/components/PluginList/PluginItem.tsx +187 -0
- package/src/components/PluginList/PluginList.stories.tsx +87 -0
- package/src/components/PluginList/PluginList.tsx +29 -0
- package/src/components/PluginList/index.ts +5 -0
- package/src/components/index.ts +0 -1
- package/src/containers/CommunityRegistry/CommunityRegistry.tsx +181 -0
- package/src/containers/CommunityRegistry/index.ts +5 -0
- package/src/containers/LoadPluginDialog/LoadPluginDialog.tsx +86 -0
- package/src/containers/LoadPluginDialog/index.ts +5 -0
- package/src/containers/PluginArticle/PluginArticle.tsx +73 -0
- package/src/containers/PluginArticle/index.ts +5 -0
- package/src/containers/PluginRegistry/PluginRegistry.tsx +98 -0
- package/src/containers/PluginRegistry/index.ts +5 -0
- package/src/containers/index.ts +11 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/use-auto-tags.ts +52 -0
- package/src/hooks/use-community-plugins.ts +35 -0
- package/src/meta.ts +19 -9
- package/src/operations/index.ts +7 -0
- package/src/operations/open-plugin-registry.ts +21 -0
- package/src/translations.ts +22 -15
- package/src/types.ts +30 -1
- package/dist/lib/browser/app-graph-builder-6JQNRTEQ.mjs +0 -161
- package/dist/lib/browser/app-graph-builder-6JQNRTEQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-AEBASNOI.mjs +0 -16
- package/dist/lib/browser/chunk-AEBASNOI.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-UGDFPMAG.mjs +0 -23
- package/dist/lib/browser/intent-resolver-UGDFPMAG.mjs.map +0 -7
- package/dist/lib/browser/react-surface-BQPO3F3E.mjs +0 -333
- package/dist/lib/browser/react-surface-BQPO3F3E.mjs.map +0 -7
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/Icon.stories.d.ts +0 -6
- package/dist/types/src/components/Icon.stories.d.ts.map +0 -1
- package/dist/types/src/components/PluginDetail.d.ts +0 -9
- package/dist/types/src/components/PluginDetail.d.ts.map +0 -1
- package/dist/types/src/components/PluginDetail.stories.d.ts +0 -8
- package/dist/types/src/components/PluginDetail.stories.d.ts.map +0 -1
- package/dist/types/src/components/PluginItem.d.ts +0 -13
- package/dist/types/src/components/PluginItem.d.ts.map +0 -1
- package/dist/types/src/components/PluginList.d.ts +0 -8
- package/dist/types/src/components/PluginList.d.ts.map +0 -1
- package/dist/types/src/components/PluginList.stories.d.ts +0 -11
- package/dist/types/src/components/PluginList.stories.d.ts.map +0 -1
- package/dist/types/src/components/RegistryContainer.d.ts +0 -7
- package/dist/types/src/components/RegistryContainer.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -27
- package/src/components/Icon.stories.tsx +0 -108
- package/src/components/PluginDetail.stories.tsx +0 -46
- package/src/components/PluginDetail.tsx +0 -63
- package/src/components/PluginItem.tsx +0 -119
- package/src/components/PluginList.stories.tsx +0 -83
- package/src/components/PluginList.tsx +0 -26
- package/src/components/RegistryContainer.tsx +0 -84
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type MouseEvent, useCallback, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
8
|
+
import {
|
|
9
|
+
Button,
|
|
10
|
+
type ChromaticPalette,
|
|
11
|
+
Icon,
|
|
12
|
+
IconButton,
|
|
13
|
+
Input,
|
|
14
|
+
Link,
|
|
15
|
+
ListItem,
|
|
16
|
+
type NeutralPalette,
|
|
17
|
+
Tag,
|
|
18
|
+
useTranslation,
|
|
19
|
+
} from '@dxos/react-ui';
|
|
20
|
+
import { mx } from '@dxos/ui-theme';
|
|
21
|
+
import { getStyles } from '@dxos/ui-theme';
|
|
22
|
+
|
|
23
|
+
import { meta } from '#meta';
|
|
24
|
+
import { type RegistryTagType } from '#types';
|
|
25
|
+
|
|
26
|
+
export type PluginItemProps = {
|
|
27
|
+
plugin: Plugin.Plugin;
|
|
28
|
+
/** Ids of plugins currently installed (loaded into the manager). */
|
|
29
|
+
installed?: readonly string[];
|
|
30
|
+
/** Ids of plugins whose install is in flight. */
|
|
31
|
+
installing?: readonly string[];
|
|
32
|
+
enabled?: readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* Derived tags (e.g. `community`, `local`) to display alongside the plugin's own meta.tags.
|
|
35
|
+
* Not persisted to plugin meta; computed per-render by the container.
|
|
36
|
+
*/
|
|
37
|
+
extraTags?: readonly string[];
|
|
38
|
+
onClick?: (id: string) => void;
|
|
39
|
+
onChange?: (id: string, enabled: boolean) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Install handler. When provided and the plugin is not installed, an Install button
|
|
42
|
+
* is rendered in place of the enable switch.
|
|
43
|
+
*/
|
|
44
|
+
onInstall?: (id: string) => void;
|
|
45
|
+
hasSettings?: (id: string) => boolean;
|
|
46
|
+
onSettings?: (id: string) => void;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const PluginItem = ({
|
|
50
|
+
plugin,
|
|
51
|
+
installed,
|
|
52
|
+
installing,
|
|
53
|
+
enabled = [],
|
|
54
|
+
extraTags,
|
|
55
|
+
onClick,
|
|
56
|
+
onChange,
|
|
57
|
+
onInstall,
|
|
58
|
+
hasSettings: hasSettingsProp,
|
|
59
|
+
onSettings,
|
|
60
|
+
}: PluginItemProps) => {
|
|
61
|
+
const { t } = useTranslation(meta.id);
|
|
62
|
+
const { id, name, description, tags, icon = 'ph--circle--regular', iconHue = 'neutral' } = plugin.meta;
|
|
63
|
+
const displayTags = useMemo(() => {
|
|
64
|
+
if (!extraTags || extraTags.length === 0) {
|
|
65
|
+
return tags ?? [];
|
|
66
|
+
}
|
|
67
|
+
const set = new Set<string>(tags ?? []);
|
|
68
|
+
for (const tag of extraTags) {
|
|
69
|
+
set.add(tag);
|
|
70
|
+
}
|
|
71
|
+
return Array.from(set);
|
|
72
|
+
}, [tags, extraTags]);
|
|
73
|
+
const isEnabled = enabled.includes(id);
|
|
74
|
+
const isInstalled = installed ? installed.includes(id) : true;
|
|
75
|
+
const isInstalling = installing?.includes(id) ?? false;
|
|
76
|
+
const showInstallButton = !!onInstall && !isInstalled;
|
|
77
|
+
const inputId = `${id}-input`;
|
|
78
|
+
const labelId = `${id}-label`;
|
|
79
|
+
const descriptionId = `${id}-description`;
|
|
80
|
+
const handleClick = useCallback(() => onClick?.(id), [id, onClick]);
|
|
81
|
+
|
|
82
|
+
const handleChange = useCallback(
|
|
83
|
+
(event: MouseEvent) => {
|
|
84
|
+
event.stopPropagation();
|
|
85
|
+
onChange?.(id, !isEnabled);
|
|
86
|
+
},
|
|
87
|
+
[id, isEnabled, onChange],
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const handleInstall = useCallback(
|
|
91
|
+
(event: MouseEvent) => {
|
|
92
|
+
event.stopPropagation();
|
|
93
|
+
onInstall?.(id);
|
|
94
|
+
},
|
|
95
|
+
[id, onInstall],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const hasSettings = hasSettingsProp?.(id) ?? false;
|
|
99
|
+
const handleSettings = useCallback(() => onSettings?.(id), [id, onSettings]);
|
|
100
|
+
const styles = getStyles(iconHue);
|
|
101
|
+
const gridCols = 'grid grid-cols-[5rem_1fr]';
|
|
102
|
+
const gridRows = 'grid grid-rows-[40px_1fr_min-content_40px]';
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<ListItem.Root
|
|
106
|
+
key={id}
|
|
107
|
+
labelId={labelId}
|
|
108
|
+
data-testid={`pluginList.${id}`}
|
|
109
|
+
aria-describedby={descriptionId}
|
|
110
|
+
classNames={mx(gridCols, 'h-[14rem] w-full gap-3 pe-2 bg-modal-surface rounded-md overflow-hidden')}
|
|
111
|
+
>
|
|
112
|
+
<div className={mx(gridRows, 'justify-center rounded-l-md', styles.surface)}>
|
|
113
|
+
<Icon
|
|
114
|
+
classNames={mx('row-start-2 cursor-pointer', styles.surfaceText)}
|
|
115
|
+
icon={icon}
|
|
116
|
+
size={14}
|
|
117
|
+
onClick={handleClick}
|
|
118
|
+
/>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<div className={mx(gridRows)}>
|
|
122
|
+
<div className='flex items-center overflow-hidden cursor-pointer' onClick={handleClick}>
|
|
123
|
+
<span className='text-lg truncate'>{name ?? id}</span>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<div>
|
|
127
|
+
<p className={mx('text-description', 'line-clamp-4 min-w-0')}>{description}</p>
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
<div className='flex -ms-0.5 overflow-x-auto scrollbar-none'>
|
|
131
|
+
{displayTags.map((tag) => (
|
|
132
|
+
<Tag key={tag} palette={tagColors[tag as RegistryTagType]} classNames='text-xs uppercase font-thin'>
|
|
133
|
+
{tag}
|
|
134
|
+
</Tag>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<div className='flex gap-2 items-center text-sm'>
|
|
139
|
+
<IconButton
|
|
140
|
+
aria-describedby={descriptionId}
|
|
141
|
+
classNames='cursor-pointer'
|
|
142
|
+
icon='ph--gear--regular'
|
|
143
|
+
label={t('plugin-settings.label')}
|
|
144
|
+
iconOnly
|
|
145
|
+
size={4}
|
|
146
|
+
onClick={handleSettings}
|
|
147
|
+
disabled={!hasSettings}
|
|
148
|
+
/>
|
|
149
|
+
|
|
150
|
+
<Link aria-describedby={descriptionId} classNames='text-description cursor-pointer' onClick={handleClick}>
|
|
151
|
+
{t('details.label')}
|
|
152
|
+
</Link>
|
|
153
|
+
|
|
154
|
+
<div className='grow' />
|
|
155
|
+
<div className='pe-1'>
|
|
156
|
+
{showInstallButton ? (
|
|
157
|
+
<Button
|
|
158
|
+
aria-describedby={descriptionId}
|
|
159
|
+
density='fine'
|
|
160
|
+
variant='primary'
|
|
161
|
+
disabled={isInstalling}
|
|
162
|
+
onClick={handleInstall}
|
|
163
|
+
>
|
|
164
|
+
{isInstalling ? t('installing.label') : t('install.label')}
|
|
165
|
+
</Button>
|
|
166
|
+
) : (
|
|
167
|
+
<Input.Root id={inputId}>
|
|
168
|
+
<Input.Switch classNames='self-center' checked={isEnabled} onClick={handleChange} />
|
|
169
|
+
</Input.Root>
|
|
170
|
+
)}
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
</ListItem.Root>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const tagColors: Record<RegistryTagType, ChromaticPalette | NeutralPalette> = {
|
|
179
|
+
new: 'rose',
|
|
180
|
+
beta: 'teal',
|
|
181
|
+
labs: 'blue',
|
|
182
|
+
popular: 'green',
|
|
183
|
+
featured: 'pink',
|
|
184
|
+
experimental: 'amber',
|
|
185
|
+
community: 'indigo',
|
|
186
|
+
local: 'neutral',
|
|
187
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { type Plugin, Plugin as PluginNS } from '@dxos/app-framework';
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { ScrollArea } from '@dxos/react-ui';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
|
+
import { getHashHue } from '@dxos/ui-theme';
|
|
13
|
+
|
|
14
|
+
import { translations } from '#translations';
|
|
15
|
+
import { RegistryTagType } from '#types';
|
|
16
|
+
|
|
17
|
+
import { PluginList } from './PluginList';
|
|
18
|
+
|
|
19
|
+
random.seed(1);
|
|
20
|
+
|
|
21
|
+
const icons = [
|
|
22
|
+
'ph--bug--regular',
|
|
23
|
+
'ph--compass--regular',
|
|
24
|
+
'ph--kanban--regular',
|
|
25
|
+
'ph--table--regular',
|
|
26
|
+
'ph--gear--regular',
|
|
27
|
+
'ph--github-logo--regular',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const DefaultStory = () => {
|
|
31
|
+
const [plugins] = useState<Plugin.Plugin[]>(
|
|
32
|
+
random.helpers.multiple(
|
|
33
|
+
() =>
|
|
34
|
+
PluginNS.define({
|
|
35
|
+
id: `org.dxos.plugin.plugin-${random.string.uuid()}`,
|
|
36
|
+
name: `${random.commerce.productName()}`,
|
|
37
|
+
description: random.lorem.sentences(Math.ceil(Math.random() * 3)),
|
|
38
|
+
tags: random.helpers.uniqueArray(RegistryTagType.literals as any, Math.floor(Math.random() * 3)),
|
|
39
|
+
icon: random.helpers.arrayElement(icons),
|
|
40
|
+
iconHue: getHashHue(random.string.uuid()),
|
|
41
|
+
homePage: random.datatype.boolean({ probability: 0.5 }) ? random.internet.url() : undefined,
|
|
42
|
+
source: random.internet.url(),
|
|
43
|
+
}).pipe(PluginNS.make)(),
|
|
44
|
+
{ count: 32 },
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const [enabled, setEnabled] = useState<string[]>([]);
|
|
48
|
+
|
|
49
|
+
const handleChange = (id: string, enabled: boolean) => {
|
|
50
|
+
setEnabled((plugins) => (enabled ? [...plugins, id] : plugins.filter((plugin) => plugin === id)));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<ScrollArea.Root orientation='vertical'>
|
|
55
|
+
<ScrollArea.Viewport>
|
|
56
|
+
<PluginList plugins={plugins} enabled={enabled} onChange={handleChange} hasSettings={() => true} />
|
|
57
|
+
</ScrollArea.Viewport>
|
|
58
|
+
</ScrollArea.Root>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const meta = {
|
|
63
|
+
title: 'plugins/plugin-registry/components/PluginList',
|
|
64
|
+
component: PluginList,
|
|
65
|
+
render: DefaultStory,
|
|
66
|
+
parameters: {
|
|
67
|
+
translations,
|
|
68
|
+
},
|
|
69
|
+
} satisfies Meta<typeof PluginList>;
|
|
70
|
+
|
|
71
|
+
export default meta;
|
|
72
|
+
|
|
73
|
+
type Story = StoryObj<typeof meta>;
|
|
74
|
+
|
|
75
|
+
export const Default: Story = {
|
|
76
|
+
decorators: [withTheme(), withLayout({ layout: 'column', classNames: 'bg-deck-surface' })],
|
|
77
|
+
parameters: {
|
|
78
|
+
layout: 'fullscreen',
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const FullScreen: Story = {
|
|
83
|
+
decorators: [withTheme(), withLayout({ scroll: true })],
|
|
84
|
+
parameters: {
|
|
85
|
+
layout: 'fullscreen',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
8
|
+
import { List } from '@dxos/react-ui';
|
|
9
|
+
|
|
10
|
+
import { PluginItem, type PluginItemProps } from './PluginItem';
|
|
11
|
+
|
|
12
|
+
export type PluginListProps = Omit<PluginItemProps, 'plugin' | 'extraTags'> & {
|
|
13
|
+
plugins?: readonly Plugin.Plugin[];
|
|
14
|
+
/**
|
|
15
|
+
* Map from plugin id → extra tags to display (e.g. `community`, `local`).
|
|
16
|
+
* Computed by the container; not persisted to plugin meta.
|
|
17
|
+
*/
|
|
18
|
+
extraTagsById?: Record<string, readonly string[]>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const PluginList = ({ plugins = [], extraTagsById, ...props }: PluginListProps) => {
|
|
22
|
+
return (
|
|
23
|
+
<List classNames='grid grid-cols-[repeat(auto-fill,minmax(18rem,1fr))] auto-rows-[max-content] gap-4 p-4'>
|
|
24
|
+
{plugins.map((plugin) => (
|
|
25
|
+
<PluginItem key={plugin.meta.id} plugin={plugin} extraTags={extraTagsById?.[plugin.meta.id]} {...props} />
|
|
26
|
+
))}
|
|
27
|
+
</List>
|
|
28
|
+
);
|
|
29
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Plugin, UrlLoader } from '@dxos/app-framework';
|
|
10
|
+
import { useCapabilities, useOperationInvoker, usePluginManager } from '@dxos/app-framework/ui';
|
|
11
|
+
import { AppCapabilities, LayoutOperation, SettingsOperation } from '@dxos/app-toolkit';
|
|
12
|
+
import { runAndForwardErrors } from '@dxos/effect';
|
|
13
|
+
import { ObservabilityOperation } from '@dxos/plugin-observability/operations';
|
|
14
|
+
import { type PluginEntry } from '@dxos/protocols';
|
|
15
|
+
import { ScrollArea, useTranslation } from '@dxos/react-ui';
|
|
16
|
+
import { composable, composableProps } from '@dxos/ui-theme';
|
|
17
|
+
|
|
18
|
+
import { PluginList } from '#components';
|
|
19
|
+
import { getPluginPath, meta } from '#meta';
|
|
20
|
+
|
|
21
|
+
import { useAutoTags, useCommunityPlugins } from '../../hooks';
|
|
22
|
+
|
|
23
|
+
const sortEntries = (a: PluginEntry, b: PluginEntry) =>
|
|
24
|
+
(a.meta.name ?? a.meta.id).localeCompare(b.meta.name ?? b.meta.id);
|
|
25
|
+
|
|
26
|
+
const sortPlugins = (a: Plugin.Plugin, b: Plugin.Plugin) =>
|
|
27
|
+
(a.meta.name ?? a.meta.id).localeCompare(b.meta.name ?? b.meta.id);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Turns a community manifest entry into a minimal Plugin object so we can reuse
|
|
31
|
+
* {@link PluginList} for rendering. The synthesized plugin has no modules — it
|
|
32
|
+
* exists only for display until the user installs it.
|
|
33
|
+
*/
|
|
34
|
+
const toDisplayPlugin = (entry: PluginEntry): Plugin.Plugin =>
|
|
35
|
+
({
|
|
36
|
+
[Plugin.PluginTypeId]: Plugin.PluginTypeId,
|
|
37
|
+
meta: entry.meta,
|
|
38
|
+
modules: [],
|
|
39
|
+
}) as Plugin.Plugin;
|
|
40
|
+
|
|
41
|
+
export type CommunityRegistryProps = {
|
|
42
|
+
id: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const CommunityRegistry = composable<HTMLDivElement, CommunityRegistryProps>(
|
|
46
|
+
({ id, ...props }, forwardedRef) => {
|
|
47
|
+
const { t } = useTranslation(meta.id);
|
|
48
|
+
const manager = usePluginManager();
|
|
49
|
+
const { invoke, invokePromise } = useOperationInvoker();
|
|
50
|
+
const { entries, loading, error } = useCommunityPlugins();
|
|
51
|
+
const enabled = useAtomValue(manager.enabled);
|
|
52
|
+
const plugins = useAtomValue(manager.plugins);
|
|
53
|
+
const installedIds = useMemo(() => plugins.map((plugin) => plugin.meta.id), [plugins]);
|
|
54
|
+
const allSettings = useCapabilities(AppCapabilities.Settings);
|
|
55
|
+
const extraTagsById = useAutoTags(entries);
|
|
56
|
+
|
|
57
|
+
// Snapshot of installed plugin ids at mount time. Used to sort installed
|
|
58
|
+
// plugins to the top without having newly-installed rows jump up mid-session.
|
|
59
|
+
const [installedSnapshot] = useState<ReadonlySet<string>>(
|
|
60
|
+
() => new Set(manager.getPlugins().map((plugin) => plugin.meta.id)),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const [installingIds, setInstallingIds] = useState<readonly string[]>([]);
|
|
64
|
+
|
|
65
|
+
const sortedEntries = useMemo(() => [...entries].sort(sortEntries), [entries]);
|
|
66
|
+
const moduleUrlById = useMemo(() => {
|
|
67
|
+
const map: Record<string, string> = {};
|
|
68
|
+
for (const entry of sortedEntries) {
|
|
69
|
+
map[entry.meta.id] = entry.moduleUrl;
|
|
70
|
+
}
|
|
71
|
+
return map;
|
|
72
|
+
}, [sortedEntries]);
|
|
73
|
+
|
|
74
|
+
// Single list with installed-at-mount plugins sorted to the top. Sort order
|
|
75
|
+
// is based on the mount-time snapshot so rows don't jump as the user
|
|
76
|
+
// installs plugins during the session.
|
|
77
|
+
const items = useMemo(() => {
|
|
78
|
+
const catalogIds = new Set(sortedEntries.map((entry) => entry.meta.id));
|
|
79
|
+
const remoteIds = new Set(UrlLoader.getRemoteEntries().map((entry) => entry.id));
|
|
80
|
+
const fromCatalog = sortedEntries.map(toDisplayPlugin);
|
|
81
|
+
const fromUrlOnly = plugins.filter((plugin) => remoteIds.has(plugin.meta.id) && !catalogIds.has(plugin.meta.id));
|
|
82
|
+
const installedFirst = [...fromCatalog, ...fromUrlOnly].sort((a, b) => {
|
|
83
|
+
const aInstalled = installedSnapshot.has(a.meta.id);
|
|
84
|
+
const bInstalled = installedSnapshot.has(b.meta.id);
|
|
85
|
+
if (aInstalled !== bInstalled) {
|
|
86
|
+
return aInstalled ? -1 : 1;
|
|
87
|
+
}
|
|
88
|
+
return sortPlugins(a, b);
|
|
89
|
+
});
|
|
90
|
+
return installedFirst;
|
|
91
|
+
}, [sortedEntries, installedSnapshot, plugins]);
|
|
92
|
+
|
|
93
|
+
const handleChange = useCallback(
|
|
94
|
+
(pluginId: string, nextEnabled: boolean) =>
|
|
95
|
+
Effect.gen(function* () {
|
|
96
|
+
if (nextEnabled) {
|
|
97
|
+
yield* manager.enable(pluginId);
|
|
98
|
+
} else {
|
|
99
|
+
yield* manager.disable(pluginId);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
yield* invoke(ObservabilityOperation.SendEvent, {
|
|
103
|
+
name: 'plugins.toggle',
|
|
104
|
+
properties: { plugin: pluginId, enabled: nextEnabled, source: 'community' },
|
|
105
|
+
});
|
|
106
|
+
}).pipe(runAndForwardErrors),
|
|
107
|
+
[invoke, manager],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const handleInstall = useCallback(
|
|
111
|
+
(pluginId: string) => {
|
|
112
|
+
const moduleUrl = moduleUrlById[pluginId];
|
|
113
|
+
if (!moduleUrl) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
setInstallingIds((prev) => (prev.includes(pluginId) ? prev : [...prev, pluginId]));
|
|
117
|
+
void void Effect.gen(function* () {
|
|
118
|
+
const plugin = yield* manager.add(moduleUrl);
|
|
119
|
+
yield* manager.enable(plugin.meta.id);
|
|
120
|
+
yield* invoke(ObservabilityOperation.SendEvent, {
|
|
121
|
+
name: 'plugins.install',
|
|
122
|
+
properties: { plugin: plugin.meta.id, source: 'community' },
|
|
123
|
+
});
|
|
124
|
+
}).pipe(
|
|
125
|
+
Effect.ensuring(Effect.sync(() => setInstallingIds((prev) => prev.filter((pid) => pid !== pluginId)))),
|
|
126
|
+
runAndForwardErrors,
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
[invoke, manager, moduleUrlById],
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const handleClick = useCallback(
|
|
133
|
+
(pluginId: string) =>
|
|
134
|
+
invokePromise(LayoutOperation.Open, {
|
|
135
|
+
subject: [getPluginPath(pluginId)],
|
|
136
|
+
pivotId: id,
|
|
137
|
+
positioning: 'end',
|
|
138
|
+
}),
|
|
139
|
+
[invokePromise, id],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const hasSettings = useCallback(
|
|
143
|
+
(pluginId: string) => allSettings.some((setting) => setting.prefix === pluginId),
|
|
144
|
+
[allSettings],
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const handleSettings = useCallback(
|
|
148
|
+
(pluginId: string) => invokePromise(SettingsOperation.Open, { plugin: pluginId }),
|
|
149
|
+
[invokePromise],
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<ScrollArea.Root {...composableProps(props)} orientation='vertical' ref={forwardedRef}>
|
|
154
|
+
<ScrollArea.Viewport>
|
|
155
|
+
{items.length > 0 ? (
|
|
156
|
+
<PluginList
|
|
157
|
+
plugins={items}
|
|
158
|
+
installed={installedIds}
|
|
159
|
+
installing={installingIds}
|
|
160
|
+
enabled={enabled}
|
|
161
|
+
extraTagsById={extraTagsById}
|
|
162
|
+
onClick={handleClick}
|
|
163
|
+
onChange={handleChange}
|
|
164
|
+
onInstall={handleInstall}
|
|
165
|
+
hasSettings={hasSettings}
|
|
166
|
+
onSettings={handleSettings}
|
|
167
|
+
/>
|
|
168
|
+
) : error ? (
|
|
169
|
+
<div className='p-4 text-description'>Failed to load community plugins: {error.message}</div>
|
|
170
|
+
) : loading ? (
|
|
171
|
+
<div className='p-4 text-description'>{t('loading.label')}</div>
|
|
172
|
+
) : (
|
|
173
|
+
<div className='p-4 text-description'>No community plugins available.</div>
|
|
174
|
+
)}
|
|
175
|
+
</ScrollArea.Viewport>
|
|
176
|
+
</ScrollArea.Root>
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
CommunityRegistry.displayName = 'CommunityRegistry';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { usePluginManager } from '@dxos/app-framework/ui';
|
|
9
|
+
import { runAndForwardErrors } from '@dxos/effect';
|
|
10
|
+
import { Button, Dialog, Input, useTranslation } from '@dxos/react-ui';
|
|
11
|
+
|
|
12
|
+
import { meta } from '../../meta';
|
|
13
|
+
|
|
14
|
+
export const LOAD_PLUGIN_DIALOG = `${meta.id}.LoadPluginDialog`;
|
|
15
|
+
|
|
16
|
+
export const LoadPluginDialog = () => {
|
|
17
|
+
const manager = usePluginManager();
|
|
18
|
+
const { t } = useTranslation(meta.id);
|
|
19
|
+
const [url, setUrl] = useState('');
|
|
20
|
+
const [loading, setLoading] = useState(false);
|
|
21
|
+
const [error, setError] = useState<string | null>(null);
|
|
22
|
+
const closeRef = useRef<HTMLButtonElement | null>(null);
|
|
23
|
+
|
|
24
|
+
const handleLoad = useCallback(() => {
|
|
25
|
+
if (!url.trim()) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setLoading(true);
|
|
30
|
+
setError(null);
|
|
31
|
+
|
|
32
|
+
void Effect.gen(function* () {
|
|
33
|
+
const plugin = yield* manager.add(url.trim());
|
|
34
|
+
yield* manager.enable(plugin.meta.id);
|
|
35
|
+
closeRef.current?.click();
|
|
36
|
+
}).pipe(
|
|
37
|
+
Effect.catchAll((err) =>
|
|
38
|
+
Effect.sync(() => {
|
|
39
|
+
setError(String(err));
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
Effect.tap(() => Effect.sync(() => setLoading(false))),
|
|
43
|
+
runAndForwardErrors,
|
|
44
|
+
);
|
|
45
|
+
}, [url, manager]);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Dialog.Content>
|
|
49
|
+
<Dialog.Header>
|
|
50
|
+
<Dialog.Title>{t('load-by-url-dialog.title')}</Dialog.Title>
|
|
51
|
+
<Dialog.Close asChild>
|
|
52
|
+
<Dialog.CloseIconButton ref={closeRef} />
|
|
53
|
+
</Dialog.Close>
|
|
54
|
+
</Dialog.Header>
|
|
55
|
+
<Dialog.Body>
|
|
56
|
+
{/* TODO(burdon): Form section. */}
|
|
57
|
+
<div className='flex flex-col gap-4'>
|
|
58
|
+
<Input.Root validationValence={error ? 'error' : undefined}>
|
|
59
|
+
<Input.Label>{t('plugin-url.label')}</Input.Label>
|
|
60
|
+
<Input.TextInput
|
|
61
|
+
placeholder='https://example.com/plugin.mjs'
|
|
62
|
+
value={url}
|
|
63
|
+
onChange={(event) => {
|
|
64
|
+
setUrl(event.target.value);
|
|
65
|
+
setError(null);
|
|
66
|
+
}}
|
|
67
|
+
onKeyDown={(event) => {
|
|
68
|
+
if (event.key === 'Enter') {
|
|
69
|
+
handleLoad();
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
72
|
+
disabled={loading}
|
|
73
|
+
autoFocus
|
|
74
|
+
/>
|
|
75
|
+
{error && <Input.DescriptionAndValidation>{error}</Input.DescriptionAndValidation>}
|
|
76
|
+
</Input.Root>
|
|
77
|
+
<div className='flex justify-end'>
|
|
78
|
+
<Button variant='primary' disabled={!url.trim() || loading} onClick={handleLoad}>
|
|
79
|
+
{loading ? t('loading.label') : t('load-plugin.label')}
|
|
80
|
+
</Button>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</Dialog.Body>
|
|
84
|
+
</Dialog.Content>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
10
|
+
import { usePluginManager } from '@dxos/app-framework/ui';
|
|
11
|
+
import { runAndForwardErrors } from '@dxos/effect';
|
|
12
|
+
|
|
13
|
+
import { PluginDetail } from '#components';
|
|
14
|
+
|
|
15
|
+
import { useCommunityPlugins, useRemotePluginIds } from '../../hooks';
|
|
16
|
+
|
|
17
|
+
// TODO(burdon): Convert to ECHO type.
|
|
18
|
+
export type PluginArticleProps = { subject: Plugin.Plugin };
|
|
19
|
+
|
|
20
|
+
export const PluginArticle = ({ subject: plugin }: PluginArticleProps) => {
|
|
21
|
+
const manager = usePluginManager();
|
|
22
|
+
const plugins = useAtomValue(manager.plugins);
|
|
23
|
+
const { entries } = useCommunityPlugins();
|
|
24
|
+
const remotePluginIds = useRemotePluginIds();
|
|
25
|
+
const [installing, setInstalling] = useState(false);
|
|
26
|
+
|
|
27
|
+
const enabled = manager.getEnabled().includes(plugin.meta.id);
|
|
28
|
+
const isInstalled = useMemo(
|
|
29
|
+
() => plugins.some((candidate) => candidate.meta.id === plugin.meta.id),
|
|
30
|
+
[plugins, plugin.meta.id],
|
|
31
|
+
);
|
|
32
|
+
const isCore = manager.getCore().includes(plugin.meta.id);
|
|
33
|
+
const canUninstall = isInstalled && !isCore && remotePluginIds.has(plugin.meta.id);
|
|
34
|
+
|
|
35
|
+
const moduleUrl = useMemo(
|
|
36
|
+
() => entries.find((entry) => entry.meta.id === plugin.meta.id)?.moduleUrl,
|
|
37
|
+
[entries, plugin.meta.id],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const handleEnableChange = useCallback(
|
|
41
|
+
(enabled: boolean) =>
|
|
42
|
+
enabled
|
|
43
|
+
? runAndForwardErrors(manager.enable(plugin.meta.id))
|
|
44
|
+
: runAndForwardErrors(manager.disable(plugin.meta.id)),
|
|
45
|
+
[manager, plugin.meta.id],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const handleUninstall = useCallback(() => {
|
|
49
|
+
void runAndForwardErrors(manager.remove(plugin.meta.id));
|
|
50
|
+
}, [manager, plugin.meta.id]);
|
|
51
|
+
|
|
52
|
+
const handleInstall = useCallback(() => {
|
|
53
|
+
if (!moduleUrl) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
setInstalling(true);
|
|
57
|
+
void Effect.gen(function* () {
|
|
58
|
+
const added = yield* manager.add(moduleUrl);
|
|
59
|
+
yield* manager.enable(added.meta.id);
|
|
60
|
+
}).pipe(Effect.ensuring(Effect.sync(() => setInstalling(false))), runAndForwardErrors);
|
|
61
|
+
}, [manager, moduleUrl]);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<PluginDetail
|
|
65
|
+
plugin={plugin}
|
|
66
|
+
enabled={enabled}
|
|
67
|
+
onEnabledChange={handleEnableChange}
|
|
68
|
+
onInstall={!isInstalled && moduleUrl ? handleInstall : undefined}
|
|
69
|
+
installing={installing}
|
|
70
|
+
onUninstall={canUninstall ? handleUninstall : undefined}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
};
|