@bridgebrew/plugin-manager 0.0.1 → 0.0.2

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.
@@ -0,0 +1,139 @@
1
+ // The Dependencies tab of a plugin's page, the same from the Installed and the Marketplace tab (research-043 U2):
2
+ // the contracts it requires and what provides each, the plugins that use it, and the contracts it provides.
3
+ import * as React from 'react';
4
+ import { Button, Icon, Section, cn } from '@bridge/ui';
5
+ import { dependencyRows } from './marketplace-model.ts';
6
+ import type { CatalogEntry } from './marketplace-model.ts';
7
+
8
+ /** A contract, in mono. */
9
+ export function Contract({
10
+ children,
11
+ missing,
12
+ }: {
13
+ children: React.ReactNode;
14
+ missing?: boolean | undefined;
15
+ }) {
16
+ return (
17
+ <code
18
+ className={cn(
19
+ 'w-fit rounded-sm px-1.5 py-px font-mono text-[11px]',
20
+ missing ? 'bg-destructive-subtle text-destructive' : 'bg-hover text-secondary',
21
+ )}
22
+ >
23
+ {children}
24
+ </code>
25
+ );
26
+ }
27
+
28
+ export function PluginDependencies({
29
+ requires,
30
+ implemented,
31
+ installed,
32
+ catalog,
33
+ openInstalled,
34
+ openEntry,
35
+ usedBy,
36
+ }: {
37
+ requires: string[];
38
+ implemented: string[];
39
+ /** The plugins installed in the workspace, with the contracts each implements. */
40
+ installed: { id: string; title: string; icon?: string | undefined; implements: string[] }[];
41
+ catalog: CatalogEntry[];
42
+ openInstalled: (id: string) => void;
43
+ /** Opens a marketplace entry by its id (`entryId`); absent outside the marketplace: its name is plain text. */
44
+ openEntry?: ((id: string) => void) | undefined;
45
+ /** The plugins requiring what it provides; only for an installed plugin. */
46
+ usedBy?: { id: string; key: string; title: string; icon?: string | undefined }[] | undefined;
47
+ }) {
48
+ const rows = dependencyRows(requires, installed, catalog);
49
+ return (
50
+ <div className="flex flex-col gap-5">
51
+ <Section title="Requires">
52
+ {rows.length ? (
53
+ <ul className="m-0 flex list-none flex-col gap-1.5 p-0">
54
+ {rows.map((row) => (
55
+ <li
56
+ key={row.contract}
57
+ data-requires={row.contract}
58
+ data-status={row.status}
59
+ className="flex flex-wrap items-center gap-2 text-[13px]"
60
+ >
61
+ <Contract missing={row.status === 'missing'}>{row.contract}</Contract>
62
+ {row.status === 'missing' && (
63
+ <span className="text-destructive">Missing: nothing provides it</span>
64
+ )}
65
+ {row.status === 'provided' && <span className="text-muted">provided by</span>}
66
+ {row.status === 'available' && <span className="text-muted">available from</span>}
67
+ {row.by.map((each) =>
68
+ row.status === 'provided' ? (
69
+ <Button
70
+ key={each.id}
71
+ type="button"
72
+ variant="property"
73
+ size="sm"
74
+ data-provided-by={each.id}
75
+ onClick={() => openInstalled(each.id)}
76
+ >
77
+ {each.title}
78
+ </Button>
79
+ ) : openEntry ? (
80
+ <Button
81
+ key={each.id}
82
+ type="button"
83
+ variant="property"
84
+ size="sm"
85
+ data-available-from={each.id}
86
+ onClick={() => openEntry(each.id)}
87
+ >
88
+ {each.title}
89
+ </Button>
90
+ ) : (
91
+ <span key={each.id} className="text-secondary">
92
+ {each.title}
93
+ </span>
94
+ ),
95
+ )}
96
+ </li>
97
+ ))}
98
+ </ul>
99
+ ) : (
100
+ <p className="text-[13px] text-muted">Nothing</p>
101
+ )}
102
+ </Section>
103
+ {usedBy && (
104
+ <Section title="Used by">
105
+ {usedBy.length ? (
106
+ <span className="flex flex-wrap gap-1.5">
107
+ {usedBy.map((each) => (
108
+ <Button
109
+ key={each.id}
110
+ type="button"
111
+ variant="property"
112
+ size="sm"
113
+ data-used-by={each.key}
114
+ onClick={() => openInstalled(each.id)}
115
+ >
116
+ {each.icon && <Icon name={each.icon} size={12} />}
117
+ {each.title}
118
+ </Button>
119
+ ))}
120
+ </span>
121
+ ) : (
122
+ <p className="text-[13px] text-muted">No plugin</p>
123
+ )}
124
+ </Section>
125
+ )}
126
+ <Section title="Provides">
127
+ {implemented.length ? (
128
+ <span className="flex flex-wrap gap-1.5">
129
+ {implemented.map((name) => (
130
+ <Contract key={name}>{name}</Contract>
131
+ ))}
132
+ </span>
133
+ ) : (
134
+ <p className="text-[13px] text-muted">Nothing</p>
135
+ )}
136
+ </Section>
137
+ </div>
138
+ );
139
+ }
@@ -0,0 +1,142 @@
1
+ // A plugin's Docs tab (research-027 P4): the pages of its `docs/` folder, which the docs plugin reads as collection
2
+ // `plugin:<key>` (`GET /<slug>/api/docs/tree`), each opened in the Documentation screen by Bridge's click rule
3
+ // (research-048: here, ⌘ or middle beside, ⌥ on a new desk). Without the docs plugin
4
+ // in the workspace, or a `docs/` folder in the plugin, it says so.
5
+ import * as React from 'react';
6
+ import { Icon, gestureOf, type FollowEvent } from '@bridge/ui';
7
+ import type { Context } from 'cordis';
8
+
9
+ interface PageEntry {
10
+ path: string;
11
+ title: string;
12
+ description?: string;
13
+ error?: string;
14
+ ancestors?: { path: string; title: string }[];
15
+ }
16
+ type Found =
17
+ | { pages: PageEntry[] }
18
+ | { none: 'no-docs-plugin' | 'no-docs' | 'host' }
19
+ | { failure: string };
20
+
21
+ export function PluginDocs({
22
+ ctx,
23
+ slug,
24
+ plugin,
25
+ title,
26
+ }: {
27
+ ctx: Context;
28
+ slug: string;
29
+ plugin: string;
30
+ title: string;
31
+ }) {
32
+ const { workspace, shell } = ctx;
33
+ const [found, setFound] = React.useState<Found>();
34
+ /** A page by Bridge's click rule; a modified click without a window manager, nothing. */
35
+ const open = (path: string, event: FollowEvent) => {
36
+ const gesture = gestureOf(event);
37
+ if (gesture === undefined || (gesture !== 'here' && !shell.managed())) return;
38
+ shell.openItem(
39
+ 'docs',
40
+ `${collection}/${path}`,
41
+ gesture === 'here' ? { show: true } : gesture === 'desk' ? { desk: true } : { beside: true },
42
+ );
43
+ };
44
+ const collection = `plugin:${plugin}`;
45
+ React.useEffect(() => {
46
+ // `_host`'s plugins run in no workspace the docs plugin reads.
47
+ if (slug !== workspace.slug) return void setFound({ none: 'host' });
48
+ let live = true;
49
+ void workspace
50
+ .fetch(
51
+ `/${encodeURIComponent(slug)}/api/docs/tree?collection=${encodeURIComponent(collection)}`,
52
+ { headers: { 'x-bridge-node': 'root' }, cache: 'no-store' },
53
+ )
54
+ .then(
55
+ async (res) => {
56
+ const body = (await res.json().catch(() => undefined)) as
57
+ | PageEntry[]
58
+ | { error?: { code?: string; message?: string } }
59
+ | undefined;
60
+ if (res.ok && Array.isArray(body)) return { pages: body };
61
+ const code = body && !Array.isArray(body) ? body.error?.code : undefined;
62
+ if (code === 'collection_unknown') return { none: 'no-docs' as const };
63
+ if (res.status === 404) return { none: 'no-docs-plugin' as const };
64
+ return {
65
+ failure: (body && !Array.isArray(body) && body.error?.message) || `HTTP ${res.status}`,
66
+ };
67
+ },
68
+ (cause: Error) => ({ failure: cause.message }),
69
+ )
70
+ .then((result) => {
71
+ if (live) setFound(result);
72
+ });
73
+ return () => {
74
+ live = false;
75
+ };
76
+ }, [slug, plugin]);
77
+
78
+ if (!found)
79
+ return (
80
+ <p className="flex items-center gap-2 text-[13px] text-secondary">
81
+ <Icon name="loader-circle" size={13} className="animate-spin motion-reduce:animate-none" />
82
+ Looking for its documentation…
83
+ </p>
84
+ );
85
+ if ('failure' in found)
86
+ return (
87
+ <p role="alert" className="text-sm text-destructive">
88
+ The documentation could not be read: {found.failure}
89
+ </p>
90
+ );
91
+ if ('none' in found) {
92
+ const text =
93
+ found.none === 'no-docs'
94
+ ? `${title} has no documentation: its folder has no docs/ folder.`
95
+ : found.none === 'no-docs-plugin'
96
+ ? 'The Documentation plugin is not installed in this workspace.'
97
+ : `${title} runs for all of Bridge: its documentation is not read here.`;
98
+ return (
99
+ <p data-docs-none={found.none} className="text-[13px] text-secondary">
100
+ {text}
101
+ </p>
102
+ );
103
+ }
104
+ if (!found.pages.length)
105
+ return (
106
+ <p data-docs-none="empty" className="text-[13px] text-secondary">
107
+ {title}'s docs/ folder has no page.
108
+ </p>
109
+ );
110
+ return (
111
+ <ul aria-label={`${title} documentation`} className="m-0 flex list-none flex-col gap-px p-0">
112
+ {found.pages.map((page) => (
113
+ <li key={page.path} style={{ paddingLeft: (page.ancestors?.length ?? 0) * 16 }}>
114
+ <button
115
+ type="button"
116
+ data-docs-page={page.path}
117
+ disabled={page.error !== undefined}
118
+ onClick={(event) => open(page.path, event)}
119
+ onAuxClick={(event) => {
120
+ if (event.button !== 1) return;
121
+ event.preventDefault();
122
+ open(page.path, event);
123
+ }}
124
+ className="flex w-full cursor-pointer items-start gap-2.5 rounded-control border-0 bg-transparent px-2 py-2 text-left font-[inherit] outline-hidden hover:bg-hover focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default disabled:opacity-60"
125
+ >
126
+ <Icon name="file-text" size={14} className="mt-0.5 shrink-0 text-muted" />
127
+ <span className="flex min-w-0 flex-col gap-0.5">
128
+ <span className="text-sm text-foreground">{page.title}</span>
129
+ {(page.error ?? page.description) && (
130
+ <span
131
+ className={page.error ? 'text-xs text-destructive' : 'text-xs text-secondary'}
132
+ >
133
+ {page.error ?? page.description}
134
+ </span>
135
+ )}
136
+ </span>
137
+ </button>
138
+ </li>
139
+ ))}
140
+ </ul>
141
+ );
142
+ }