@celljs/ta-extensions 4.7.0 → 4.9.0

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/web-src/market.ts DELETED
@@ -1,232 +0,0 @@
1
- import { type MarketDetail, type MarketPackage, type MarketPage, MarketUtil } from './market-util';
2
-
3
- export type Fetch = (url: string, init?: { signal?: AbortSignal; headers?: Record<string, string> }) => Promise<Response>;
4
-
5
- interface Cached<T> {
6
- at: number;
7
- value: Promise<T>;
8
- }
9
-
10
- /** The keyword by which pi's gallery finds packages on npm. */
11
- const KEYWORD = 'pi-package';
12
- /** npm keeps its answers to searches for five minutes; so does the market. */
13
- const TTL = 5 * 60_000;
14
- const LIMIT = 100;
15
- const TIMEOUT = 15_000;
16
- /** A README is a nicety: the page shows the package without it rather than wait. */
17
- const TEXT_TIMEOUT = 8_000;
18
- /** A README longer than this is cut: the page is to choose a package, not to read a book. */
19
- const README_MAX = 80_000;
20
- export const PAGE_SIZE = 24;
21
-
22
- /**
23
- * The market of extensions: the pi packages of npm, as pi's gallery (pi.dev/packages) finds them, by the
24
- * keyword `pi-package`. Asked on the server, which installs them too, and kept a few minutes.
25
- */
26
- export class NpmMarket {
27
- protected readonly cache = new Map<string, Cached<unknown>>();
28
-
29
- constructor(
30
- protected readonly fetch: Fetch = globalThis.fetch,
31
- protected readonly registry = 'https://registry.npmjs.org',
32
- protected readonly now: () => number = Date.now,
33
- protected readonly cdn = 'https://cdn.jsdelivr.net/npm',
34
- protected readonly downloadsApi = 'https://api.npmjs.org',
35
- ) {}
36
-
37
- /**
38
- * Packages that match `query` (all of them without one), the best first, from `from` (MarketPage.next).
39
- * npm ranks every package of the keyword, those that do not match the words last: they are left out,
40
- * and the search ends where they begin.
41
- */
42
- search(query: string, from = 0): Promise<MarketPage> {
43
- const words = String(query ?? '').trim();
44
- const text = `${words} keywords:${KEYWORD}`.trim();
45
- const start = Math.max(0, Math.floor(Number(from) || 0));
46
- const url = `${this.registry}/-/v1/search?text=${encodeURIComponent(text)}&size=${PAGE_SIZE}&from=${start}`;
47
- return this.remember(url, async () => {
48
- const body = (await this.json(url)) as { total?: number; objects?: SearchObject[] };
49
- const objects = body.objects ?? [];
50
- const all = objects.flatMap(object => {
51
- const pkg = this.toPackage(object);
52
- return pkg ? [{ pkg, keywords: object.package?.keywords }] : [];
53
- });
54
- const packages = all.filter(({ pkg, keywords }) => !words || MarketUtil.matches({ ...pkg, keywords }, words)).map(({ pkg }) => pkg);
55
- const full = objects.length === PAGE_SIZE && packages.length === all.length;
56
- return {
57
- total: words ? undefined : body.total,
58
- packages,
59
- next: full ? start + objects.length : undefined,
60
- };
61
- });
62
- }
63
-
64
- /**
65
- * A package with its README and previews, by its name on npm. Not from npm's document of the package,
66
- * which holds every version (tens of megabytes for some): its latest manifest, its downloads, and its
67
- * README as published, from jsDelivr, or else from its repository on GitHub.
68
- */
69
- detail(name: string): Promise<MarketDetail> {
70
- if (typeof name !== 'string' || !/^(@[a-z0-9][\w.-]*\/)?[a-z0-9][\w.-]*$/i.test(name)) {
71
- return Promise.reject(new Error(`${String(name)} is not the name of an npm package.`));
72
- }
73
- const url = `${this.registry}/${name.replace('/', '%2f')}/latest`;
74
- return this.remember(url, async () => {
75
- const [manifest, downloads] = await Promise.all([this.json(url) as Promise<Manifest>, this.downloads(name)]);
76
- const repository = MarketUtil.repositoryUrl(manifest.repository);
77
- const readme = await this.readme(name, manifest, repository);
78
- return this.toDetail(manifest, repository, readme, downloads);
79
- });
80
- }
81
-
82
- protected toPackage(object: SearchObject): MarketPackage | undefined {
83
- const pkg = object.package;
84
- if (!pkg?.name || !pkg.version) {
85
- return undefined;
86
- }
87
- return {
88
- name: pkg.name,
89
- version: pkg.version,
90
- description: pkg.description || undefined,
91
- publisher: MarketUtil.person(pkg.maintainers?.[0]?.username, pkg.publisher?.username),
92
- downloads: object.downloads?.monthly,
93
- date: pkg.date,
94
- kinds: MarketUtil.kindsOf(pkg.keywords),
95
- links: {
96
- npm: pkg.links?.npm ?? `https://www.npmjs.com/package/${pkg.name}`,
97
- repository: MarketUtil.repositoryUrl(pkg.links?.repository),
98
- homepage: pkg.links?.homepage,
99
- },
100
- };
101
- }
102
-
103
- protected toDetail(manifest: Manifest, repository: string | undefined, readme: string | undefined, downloads: number | undefined): MarketDetail {
104
- if (!manifest.name || !manifest.version) {
105
- throw new Error('npm has no published version of this package.');
106
- }
107
- const pi = (manifest.pi ?? {}) as Record<string, unknown>;
108
- const resources = (['extensions', 'web', 'skills', 'prompts', 'themes'] as const).filter(key => key in pi);
109
- return {
110
- name: manifest.name,
111
- version: manifest.version,
112
- description: manifest.description || undefined,
113
- publisher: MarketUtil.person(manifest.maintainers?.[0]?.name, manifest._npmUser?.name),
114
- downloads,
115
- kinds: MarketUtil.kindsOf(manifest.keywords),
116
- links: {
117
- npm: `https://www.npmjs.com/package/${manifest.name}`,
118
- repository,
119
- homepage: typeof manifest.homepage === 'string' ? manifest.homepage : undefined,
120
- },
121
- license: typeof manifest.license === 'string' ? manifest.license : undefined,
122
- readme: readme && MarketUtil.readableReadme(readme.length > README_MAX ? `${readme.slice(0, README_MAX)}\n\n…` : readme, repository),
123
- image: this.web(pi.image),
124
- video: this.web(pi.video),
125
- resources,
126
- };
127
- }
128
-
129
- /** The README of the version, as npm got it; or the one of its repository; undefined when neither answers. */
130
- protected async readme(name: string, manifest: Manifest, repository: string | undefined): Promise<string | undefined> {
131
- const files = [...new Set([manifest.readmeFilename, 'README.md', 'readme.md'].filter((file): file is string => !!file && /^[\w.-]+$/.test(file)))];
132
- const urls = files.map(file => `${this.cdn}/${name}@${manifest.version}/${file}`);
133
- const github = repository && /^https:\/\/github\.com\/([^/]+\/[^/#?]+)/.exec(repository)?.[1];
134
- if (github) {
135
- const directory =
136
- typeof manifest.repository === 'object' && typeof (manifest.repository as { directory?: unknown }).directory === 'string'
137
- ? `${(manifest.repository as { directory: string }).directory.replace(/^\/|\/$/g, '')}/`
138
- : '';
139
- urls.push(`https://raw.githubusercontent.com/${github}/HEAD/${directory}README.md`);
140
- }
141
- for (const url of urls) {
142
- const text = await this.text(url);
143
- if (text?.trim()) {
144
- return text;
145
- }
146
- }
147
- return undefined;
148
- }
149
-
150
- protected async downloads(name: string): Promise<number | undefined> {
151
- try {
152
- const body = (await this.json(`${this.downloadsApi}/downloads/point/last-month/${name}`)) as { downloads?: unknown };
153
- return typeof body.downloads === 'number' ? body.downloads : undefined;
154
- } catch {
155
- return undefined;
156
- }
157
- }
158
-
159
- protected async text(url: string): Promise<string | undefined> {
160
- try {
161
- const response = await this.fetch(url, { signal: AbortSignal.timeout(TEXT_TIMEOUT) });
162
- return response.ok ? await response.text() : undefined;
163
- } catch {
164
- return undefined;
165
- }
166
- }
167
-
168
- /** Only pages of the web: the page shows them. */
169
- protected web(url: unknown): string | undefined {
170
- return typeof url === 'string' && /^https:\/\//.test(url) ? url : undefined;
171
- }
172
-
173
- protected async json(url: string): Promise<unknown> {
174
- let response: Response;
175
- try {
176
- response = await this.fetch(url, { signal: AbortSignal.timeout(TIMEOUT), headers: { accept: 'application/json' } });
177
- } catch (error) {
178
- throw new Error(`npm cannot be reached: ${error instanceof Error ? error.message : String(error)}`);
179
- }
180
- if (response.status === 404) {
181
- throw new Error('npm has no such package.');
182
- }
183
- if (!response.ok) {
184
- throw new Error(`npm answered ${response.status} ${response.statusText}`.trim());
185
- }
186
- return response.json();
187
- }
188
-
189
- /** One request for many callers; a failure is not kept. */
190
- protected remember<T>(key: string, load: () => Promise<T>): Promise<T> {
191
- const now = this.now();
192
- const cached = this.cache.get(key);
193
- if (cached && now - cached.at < TTL) {
194
- return cached.value as Promise<T>;
195
- }
196
- const value = load();
197
- this.cache.set(key, { at: now, value });
198
- value.catch(() => this.cache.get(key)?.value === value && this.cache.delete(key));
199
- if (this.cache.size > LIMIT) {
200
- this.cache.delete(this.cache.keys().next().value as string);
201
- }
202
- return value;
203
- }
204
- }
205
-
206
- interface SearchObject {
207
- downloads?: { monthly?: number };
208
- package?: {
209
- name?: string;
210
- version?: string;
211
- description?: string;
212
- keywords?: string[];
213
- date?: string;
214
- publisher?: { username?: string };
215
- maintainers?: { username?: string }[];
216
- links?: { npm?: string; repository?: string; homepage?: string };
217
- };
218
- }
219
-
220
- interface Manifest {
221
- name?: string;
222
- version?: string;
223
- readmeFilename?: string;
224
- maintainers?: { name?: string }[];
225
- description?: string;
226
- keywords?: string[];
227
- license?: unknown;
228
- homepage?: unknown;
229
- repository?: unknown;
230
- pi?: unknown;
231
- _npmUser?: { name?: string };
232
- }
package/web-src/page.tsx DELETED
@@ -1,278 +0,0 @@
1
- import type { TaPackageInfo } from '@celljs/ta-protocol';
2
- import type { WebExtensionAPI } from '@celljs/ta-web/lib/browser/extension/web-extension-api';
3
- import type { ExtensionActions } from './actions';
4
- import { type ExtensionsContext, type ExtensionsTab, icon } from './context';
5
- import { ExtensionsUtil } from './extensions-util';
6
- import { ExtensionWords } from './i18n';
7
- import { ImportDialog } from './import-dialog';
8
- import { MarketView } from './market-view';
9
- import { KindPicture } from './pictures';
10
- import { React } from './react';
11
-
12
- /**
13
- * The page of extensions, in two tabs: the user's own, and the market where more are found. A file
14
- * dropped anywhere on it imports.
15
- */
16
- export function ExtensionsPage({ context }: { context: ExtensionsContext }): React.ReactElement {
17
- const { pi, store, actions, importing } = context;
18
- const words = actions.words;
19
- const tab = context.tab.use();
20
- const dialog = importing.use();
21
- const [dragging, setDragging] = React.useState(false);
22
- React.useEffect(() => {
23
- void store.load();
24
- }, [store]);
25
- const tabs: { key: ExtensionsTab; label: string; icon: string }[] = [
26
- { key: 'mine', label: words.tabMine, icon: 'Puzzle' },
27
- { key: 'market', label: words.tabMarket, icon: 'Store' },
28
- ];
29
- const files = (event: React.DragEvent) => Array.from(event.dataTransfer.types).includes('Files');
30
- return (
31
- <section
32
- aria-label={words.title}
33
- className="tax-page"
34
- onDragOver={event => {
35
- if (files(event) && !dialog) {
36
- event.preventDefault();
37
- setDragging(true);
38
- }
39
- }}
40
- onDragLeave={event => {
41
- if (event.currentTarget === event.target) {
42
- setDragging(false);
43
- }
44
- }}
45
- onDrop={event => {
46
- if (files(event) && !dialog) {
47
- event.preventDefault();
48
- setDragging(false);
49
- const file = event.dataTransfer.files[0];
50
- if (file) {
51
- void actions.importFile(file);
52
- }
53
- }
54
- }}
55
- >
56
- <div className="tax-body">
57
- <div className="tax-tabs" role="tablist" aria-label={words.title}>
58
- {tabs.map(item => {
59
- const TabIcon = icon(pi, item.icon, 'PackageOpen');
60
- return (
61
- <button
62
- key={item.key}
63
- type="button"
64
- role="tab"
65
- aria-selected={tab === item.key}
66
- className={`tax-tab${tab === item.key ? ' tax-active' : ''}`}
67
- onClick={() => {
68
- context.tab.set(item.key);
69
- context.selected.set(undefined);
70
- }}
71
- >
72
- <TabIcon size={15} /> {item.label}
73
- </button>
74
- );
75
- })}
76
- </div>
77
- {tab === 'market' ? <MarketView context={context} /> : <MineView context={context} />}
78
- </div>
79
- {dragging && <div className="tax-drop-overlay">{words.dropToImport}</div>}
80
- {dialog && <ImportDialog pi={pi} actions={actions} onClose={() => importing.set(false)} />}
81
- </section>
82
- );
83
- }
84
-
85
- /**
86
- * The user's own: a sentence makes one, each kind shown by a picture; the extensions of the user to turn
87
- * on or off, change, hand on or remove; and, in three steps, how others take one in.
88
- */
89
- function MineView({ context }: { context: ExtensionsContext }): React.ReactElement {
90
- const { pi, store, actions, importing } = context;
91
- const words = actions.words;
92
- const { packages } = React.useSyncExternalStore(
93
- listener => store.subscribe(listener),
94
- () => store.state,
95
- );
96
- const [starting, setStarting] = React.useState(false);
97
- const groups = ExtensionsUtil.group(packages ?? []);
98
- const Composer = pi.ui.Composer;
99
- const Sparkles = icon(pi, 'Sparkles');
100
- const Upload = icon(pi, 'Upload');
101
- const Store = icon(pi, 'Store', 'PackageOpen');
102
- const make = async (text: string) => {
103
- setStarting(true);
104
- try {
105
- await actions.make(text);
106
- } finally {
107
- setStarting(false);
108
- }
109
- };
110
- return (
111
- <>
112
- <section className="tax-hero">
113
- <h1>
114
- <Sparkles size={20} /> {words.heroTitle}
115
- </h1>
116
- <p>{words.heroText}</p>
117
- <Composer placeholder={words.placeholder} onSend={make} />
118
- <div className="tax-kinds">
119
- {words.examples.map(example => (
120
- <button key={example.kind} type="button" className="tax-kind" disabled={starting} onClick={() => void make(example.text)}>
121
- <KindPicture kind={example.kind} />
122
- <span className="tax-kind-label">
123
- <strong>{example.label}</strong>
124
- <span>{example.example}</span>
125
- </span>
126
- </button>
127
- ))}
128
- </div>
129
- </section>
130
- <section className="tax-section">
131
- <div className="tax-section-head">
132
- <h2>
133
- {words.mine}
134
- {groups.mine.length > 0 && <span className="tax-count">{groups.mine.length}</span>}
135
- </h2>
136
- <button type="button" className="tax-button" onClick={() => importing.set(true)}>
137
- <Upload size={14} /> {words.import}
138
- </button>
139
- </div>
140
- {packages === undefined ? (
141
- <div className="tax-empty">{words.loading}</div>
142
- ) : groups.mine.length === 0 ? (
143
- <div className="tax-empty tax-empty-action">
144
- <span>{words.mineEmpty}</span>
145
- <button type="button" className="tax-button" onClick={() => context.tab.set('market')}>
146
- <Store size={14} /> {words.browseMarket}
147
- </button>
148
- </div>
149
- ) : (
150
- <div className="tax-list">
151
- {groups.mine.map(pkg => (
152
- <PackageRow key={pkg.id} pi={pi} actions={actions} pkg={pkg} />
153
- ))}
154
- </div>
155
- )}
156
- </section>
157
- {groups.installed.length > 0 && (
158
- <section className="tax-section">
159
- <div className="tax-section-head">
160
- <h2>
161
- {words.installed}
162
- <span className="tax-count">{groups.installed.length}</span>
163
- </h2>
164
- </div>
165
- <div className="tax-list">
166
- {groups.installed.map(pkg => (
167
- <PackageRow key={pkg.id} pi={pi} actions={actions} pkg={pkg} />
168
- ))}
169
- </div>
170
- </section>
171
- )}
172
- <section className="tax-section">
173
- <div className="tax-section-head">
174
- <h2>{words.shareTitle}</h2>
175
- </div>
176
- <ShareSteps pi={pi} actions={actions} />
177
- </section>
178
- </>
179
- );
180
- }
181
-
182
- /** Export, send the file, import: in pictures, with one line for the other ways. */
183
- function ShareSteps({ pi, actions }: { pi: WebExtensionAPI; actions: ExtensionActions }): React.ReactElement {
184
- const words = actions.words;
185
- const steps = [icon(pi, 'Download'), icon(pi, 'FileArchive', 'File'), icon(pi, 'Upload')];
186
- const Arrow = icon(pi, 'ArrowRight');
187
- return (
188
- <div className="tax-share">
189
- <div className="tax-steps">
190
- {steps.map((Step, index) => (
191
- <React.Fragment key={words.shareSteps[index]}>
192
- {index > 0 && (
193
- <span className="tax-step-arrow">
194
- <Arrow size={16} />
195
- </span>
196
- )}
197
- <div className="tax-step">
198
- <span className="tax-step-icon">
199
- <Step size={20} />
200
- </span>
201
- <span>{words.shareSteps[index]}</span>
202
- </div>
203
- </React.Fragment>
204
- ))}
205
- </div>
206
- <div className="tax-note">{words.shareMore}</div>
207
- </div>
208
- );
209
- }
210
-
211
- interface PackageRowProps {
212
- pi: WebExtensionAPI;
213
- actions: ExtensionActions;
214
- pkg: TaPackageInfo;
215
- }
216
-
217
- /** One extension: what it is and holds, a switch; on hover, what can be done with it. */
218
- function PackageRow({ pi, actions, pkg }: PackageRowProps): React.ReactElement {
219
- const words = actions.words;
220
- const mine = pkg.origin === 'directory';
221
- const Icon = icon(pi, mine ? 'Puzzle' : 'PackageOpen');
222
- const tags = [...pkg.resources.map(type => words.kinds[type]), ...(pkg.scope === 'project' ? [words.project] : [])];
223
- const buttons: { key: string; label: string; icon: string; danger?: boolean; run(): Promise<void> }[] = mine
224
- ? [
225
- { key: 'change', label: words.change, icon: 'Pencil', run: () => actions.change(pkg) },
226
- { key: 'export', label: words.export, icon: 'Download', run: () => actions.exportPackage(pkg) },
227
- { key: 'remove', label: words.remove, icon: 'Trash2', danger: true, run: () => actions.remove(pkg) },
228
- ]
229
- : [
230
- { key: 'copy', label: words.copySource, icon: 'Copy', run: () => actions.copySource(pkg) },
231
- { key: 'remove', label: words.remove, icon: 'Trash2', danger: true, run: () => actions.remove(pkg) },
232
- ];
233
- return (
234
- <div className={`tax-row${pkg.enabled ? '' : ' tax-off'}`}>
235
- <span className="tax-icon">
236
- <Icon size={17} />
237
- </span>
238
- <div className="tax-main">
239
- <div className="tax-name">
240
- <span>{pkg.name}</span>
241
- {pkg.version && <span className="tax-version">{pkg.version}</span>}
242
- {tags.map(tag => (
243
- <span key={tag} className="tax-tag">
244
- {tag}
245
- </span>
246
- ))}
247
- </div>
248
- {(pkg.description || !mine) && <div className="tax-description">{pkg.description || pkg.source}</div>}
249
- </div>
250
- <div className="tax-actions">
251
- {buttons.map(button => {
252
- const ButtonIcon = icon(pi, button.icon);
253
- return (
254
- <button
255
- key={button.key}
256
- type="button"
257
- className={`tax-action${button.danger ? ' tax-danger' : ''}`}
258
- title={button.label}
259
- aria-label={button.label}
260
- onClick={() => void button.run()}
261
- >
262
- <ButtonIcon size={15} />
263
- </button>
264
- );
265
- })}
266
- </div>
267
- <input
268
- type="checkbox"
269
- role="switch"
270
- className="tax-switch"
271
- aria-label={ExtensionWords.fill(words.turnOn, { name: pkg.name })}
272
- aria-checked={pkg.enabled}
273
- checked={pkg.enabled}
274
- onChange={event => void actions.setEnabled(pkg, event.target.checked)}
275
- />
276
- </div>
277
- );
278
- }
@@ -1,87 +0,0 @@
1
- // biome-ignore lint/style/useImportType: the JSX below compiles to React.createElement (jsxFactory)
2
- import { React } from './react';
3
-
4
- /** What an extension can be: each kind has its picture and an example to make. */
5
- export type KindName = 'card' | 'page' | 'command' | 'skill';
6
-
7
- const Frame = () => <rect className="tax-pic-frame" x="1" y="1" width="158" height="94" rx="9" />;
8
- const Line = ({ x, y, w }: { x: number; y: number; w: number }) => <rect className="tax-pic-line" x={x} y={y} width={w} height="5" rx="2.5" />;
9
-
10
- /** A card beside the conversation. */
11
- function Card() {
12
- return (
13
- <>
14
- <Frame />
15
- <Line x={12} y={16} w={58} />
16
- <Line x={12} y={27} w={74} />
17
- <Line x={12} y={38} w={46} />
18
- <rect className="tax-pic-pane" x="100" y="1" width="59" height="94" />
19
- <rect className="tax-pic-accent" x="108" y="14" width="43" height="38" rx="6" />
20
- <circle className="tax-pic-mark" cx="129.5" cy="33" r="10" />
21
- <path className="tax-pic-hand" d="M129.5 27v6l4 3" />
22
- <Line x={108} y={62} w={34} />
23
- <rect className="tax-pic-box" x="12" y="72" width="78" height="13" rx="6.5" />
24
- </>
25
- );
26
- }
27
-
28
- /** A page of its own. */
29
- function Page() {
30
- return (
31
- <>
32
- <Frame />
33
- <rect className="tax-pic-pane" x="1" y="1" width="20" height="94" />
34
- <circle className="tax-pic-line" cx="11" cy="16" r="3.5" />
35
- <circle className="tax-pic-mark" cx="11" cy="30" r="3.5" />
36
- <circle className="tax-pic-line" cx="11" cy="44" r="3.5" />
37
- <rect className="tax-pic-accent" x="31" y="13" width="118" height="70" rx="6" />
38
- {[18, 30, 24, 42, 34, 50].map((height, i) => (
39
- <rect key={height} className="tax-pic-mark" x={42 + i * 17} y={73 - height} width="9" height={height} rx="2" />
40
- ))}
41
- </>
42
- );
43
- }
44
-
45
- /** A command for Ta. */
46
- function Command() {
47
- return (
48
- <>
49
- <Frame />
50
- <rect className="tax-pic-line" x="70" y="12" width="76" height="14" rx="7" />
51
- <Line x={12} y={36} w={84} />
52
- <Line x={12} y={47} w={60} />
53
- <rect className="tax-pic-box" x="10" y="64" width="140" height="21" rx="10.5" />
54
- <rect className="tax-pic-accent" x="16" y="68.5" width="50" height="12" rx="6" />
55
- <text className="tax-pic-text" x="22" y="78">
56
- /standup
57
- </text>
58
- </>
59
- );
60
- }
61
-
62
- /** A skill: Ta does something new when asked in words. */
63
- function Skill() {
64
- return (
65
- <>
66
- <Frame />
67
- <rect className="tax-pic-line" x="74" y="12" width="72" height="14" rx="7" />
68
- <rect className="tax-pic-accent" x="12" y="34" width="96" height="30" rx="8" />
69
- <rect className="tax-pic-mark tax-pic-soft" x="20" y="42" width="58" height="5" rx="2.5" />
70
- <rect className="tax-pic-mark tax-pic-soft" x="20" y="51" width="40" height="5" rx="2.5" />
71
- <path className="tax-pic-mark" d="M126 34l3.2 8.3 8.3 3.2-8.3 3.2-3.2 8.3-3.2-8.3-8.3-3.2 8.3-3.2z" />
72
- <path className="tax-pic-mark tax-pic-soft" d="M141 60l1.6 4 4 1.6-4 1.6-1.6 4-1.6-4-4-1.6 4-1.6z" />
73
- <rect className="tax-pic-box" x="12" y="74" width="136" height="12" rx="6" />
74
- </>
75
- );
76
- }
77
-
78
- const PICTURES: Record<KindName, () => React.ReactElement> = { card: Card, page: Page, command: Command, skill: Skill };
79
-
80
- export function KindPicture({ kind }: { kind: KindName }): React.ReactElement {
81
- const Picture = PICTURES[kind];
82
- return (
83
- <svg className="tax-pic" viewBox="0 0 160 96" aria-hidden="true">
84
- <Picture />
85
- </svg>
86
- );
87
- }
package/web-src/react.ts DELETED
@@ -1,11 +0,0 @@
1
- import type * as ReactModule from 'react';
2
-
3
- /**
4
- * The React of the page, which a web extension cannot import: `activate` binds it before anything
5
- * renders. The JSX of this package compiles to `React.createElement` (tsconfig.json).
6
- */
7
- export let React: typeof ReactModule;
8
-
9
- export function bind(react: typeof ReactModule): void {
10
- React = react;
11
- }
package/web-src/signal.ts DELETED
@@ -1,34 +0,0 @@
1
- import { React } from './react';
2
-
3
- /** A value the page and the menu of the view share: who sets it, and who renders it. */
4
- export class Signal<T> {
5
- protected readonly listeners = new Set<() => void>();
6
-
7
- constructor(protected value: T) {}
8
-
9
- get(): T {
10
- return this.value;
11
- }
12
-
13
- set(value: T): void {
14
- if (!Object.is(value, this.value)) {
15
- this.value = value;
16
- for (const listener of this.listeners) {
17
- listener();
18
- }
19
- }
20
- }
21
-
22
- subscribe(listener: () => void): () => void {
23
- this.listeners.add(listener);
24
- return () => this.listeners.delete(listener);
25
- }
26
-
27
- /** A React hook: the value, rendered again when it changes. */
28
- use(): T {
29
- return React.useSyncExternalStore(
30
- listener => this.subscribe(listener),
31
- () => this.value,
32
- );
33
- }
34
- }