@kubohiroya/turbowarp-extension-security-dialog 0.9.0 → 0.9.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.
Files changed (54) hide show
  1. package/EDITOR-MIGRATION.md +5 -0
  2. package/README.ja.md +30 -9
  3. package/README.md +24 -9
  4. package/dist/build-info.json +2 -2
  5. package/dist/catalog-library.cjs +400 -0
  6. package/dist/catalog-library.d.ts +108 -0
  7. package/dist/catalog-library.mjs +372 -0
  8. package/dist/embedded-extension-name.d.ts +2 -0
  9. package/dist/index.cjs +38 -8
  10. package/dist/index.mjs +38 -8
  11. package/dist/load-errors.cjs +56 -0
  12. package/dist/load-errors.d.ts +10 -0
  13. package/dist/load-errors.mjs +35 -0
  14. package/dist/permission-ui.cjs +395 -0
  15. package/dist/permission-ui.d.ts +29 -0
  16. package/dist/permission-ui.mjs +372 -0
  17. package/dist/project-review-channel.cjs +38 -0
  18. package/dist/project-review-channel.d.ts +13 -0
  19. package/dist/project-review-channel.mjs +17 -0
  20. package/dist/project-review.cjs +6631 -0
  21. package/dist/project-review.d.ts +65 -0
  22. package/dist/project-review.mjs +6606 -0
  23. package/dist/react.cjs +110 -28
  24. package/dist/react.mjs +110 -28
  25. package/dist/review.d.ts +2 -1
  26. package/package.json +38 -5
  27. package/src/catalog-library.css +76 -0
  28. package/src/catalog-library.tsx +227 -0
  29. package/src/catalog.ts +175 -0
  30. package/src/decisions.ts +128 -0
  31. package/src/display-urls.ts +39 -0
  32. package/src/embedded-extension-name.ts +76 -0
  33. package/src/extension-row.tsx +137 -0
  34. package/src/index.ts +9 -0
  35. package/src/inline-name.ts +56 -0
  36. package/src/linked-text.tsx +49 -0
  37. package/src/load-errors.ts +38 -0
  38. package/src/messages.ts +145 -0
  39. package/src/metadata.ts +189 -0
  40. package/src/permission-ui.ts +163 -0
  41. package/src/preview.tsx +98 -0
  42. package/src/project-review-channel.ts +40 -0
  43. package/src/project-review.css +19 -0
  44. package/src/project-review.tsx +233 -0
  45. package/src/react.tsx +40 -0
  46. package/src/review-types.ts +100 -0
  47. package/src/review.css +111 -0
  48. package/src/review.tsx +513 -0
  49. package/src/selection.ts +78 -0
  50. package/src/storage.ts +157 -0
  51. package/src/turbowarp.ts +256 -0
  52. package/src/wait-dialog.ts +135 -0
  53. package/styles.css +21 -0
  54. package/webpack4.css +21 -0
@@ -0,0 +1,5 @@
1
+ # Editor 独自実装の移管
2
+
3
+ 元: kubohiroya/turbowarp-plus-editor `fd11930fa10eaad70b8332eb76b34f9888a59157`。
4
+ 2026-11-19 に著作権者から、対象の Editor 独自コードを MPL-2.0 でも提供する承認を得た。
5
+ 本家 GUI のソース・コンポーネント・CSS モジュールは移していない。ホスト固有の値は接続口から受け取る。
package/README.ja.md CHANGED
@@ -32,7 +32,7 @@ VM は機能拡張を1つずつ読み込み、そのたびに尋ねます。作
32
32
 
33
33
  **作品を開く。** この SB3 には Camera Source 0.19.4、Asset Cache 0.3.2、Bubble 0.13.5 を
34
34
  `data:` URL として保存しています。3件ともサンドボックスなしを必須と申告しているため、
35
- 実行方法はその選択肢だけが選択済みになり、OK またはキャンセルを待ちます。
35
+ 以下の旧版の図では、実行方法を選択してOKまたはキャンセルを待ちます。
36
36
  図版の時点では、どの拡張もまだ実行していません。
37
37
 
38
38
  ![公開 Editor の作品を開く確認画面。3件の必須拡張でサンドボックスなしを選択済み](./assets/screenshots/public-review-open-ja-20261106.png)
@@ -66,16 +66,18 @@ import '@kubohiroya/turbowarp-extension-security-dialog/styles.css';
66
66
  />
67
67
  ```
68
68
 
69
- 追加と開くで違うのは、一覧に何が載るかと何を選べるかだけで、問いの立て方は同じです。だから
70
- 1つの部品です。
69
+ 追加と開くは同じ部品を使います。開くときは、まず説明と拡張ごとの情報を読み、
70
+ 「実行しない」「機能拡張を個別に確認」「すべて有効にして実行」から選びます。
71
+ 通常表示には選択コントロールを出しません。個別確認モードではアイコンなしの3連ボタンで
72
+ 実行方法を選び、「選んだ内容で実行」で確定します。モードの切り替えだけでは実行しません。
71
73
 
72
74
  | | `add` | `open` |
73
75
  | --- | --- | --- |
74
76
  | 一覧に載るもの | カタログの拡張。依存先は自動で選ばれる | 作品が使う拡張すべて |
75
77
  | 選ぶ | チェックで選ぶ | 無し。作品が既に名指ししている |
76
- | 動かし方 | サンドボックスの中で、またはサンドボックスなしで | 動かさない、サンドボックスの中で、サンドボックスなしで |
77
- | 読み込み元 | 4つの持ち方から選ぶ | `remote-cacheable` の行でキャッシュを残すかだけ。ほかの行は読み込み元を述べる |
78
- | 一括指定 | 両方 | 動かし方と、断れるキャッシュが1つでもあるときはそのキャッシュ |
78
+ | 動かし方 | サンドボックスの中で、またはサンドボックスなしで | 個別確認モードで、動かさない・様子を見るためにサンドボックス内で動かす・信頼してサンドボックスなしで動かす |
79
+ | 読み込み元 | 4つの持ち方から選ぶ | 個別確認モードで`remote-cacheable`のキャッシュを残すか選ぶ。通常表示は情報のみ |
80
+ | 一括指定 | 両方 | 通常表示は「すべて有効にして実行」。個別確認ではキャッシュを一括指定できる |
79
81
 
80
82
  ### 4つの持ち方
81
83
 
@@ -99,9 +101,18 @@ import '@kubohiroya/turbowarp-extension-security-dialog/styles.css';
99
101
  ### 実行方法・信頼済みの拡張・記憶した選択
100
102
 
101
103
  **作品を開くとき、全件がサンドボックスなしを必須と申告していれば、そのモードを選択済みにします。**
102
- 取得失敗がなく、空でない一覧のすべての申告が揃った場合だけ適用します。「動かさない」と
103
- 「サンドボックスの中で」、実行方法の一括指定は表示しません。OKで実行を承認するか、キャンセルで
104
- 中止します。OK前には実行しません。読み込み元やキャッシュを断る選択は別に保ちます。
104
+ 初期表示時に取得失敗がなく、空でない一覧のすべての申告が揃った場合だけ適用します。
105
+ 個別確認では「動かさない」やサンドボックス内での試行も選べます。必須の申告に反する
106
+ 試行には警告を表示し、後から届いた申告で選択を上書きしません。一括許可または個別確認後の確定まで実行しません。
107
+ 読み込み元やキャッシュを断る選択は別に保ちます。
108
+
109
+ Editorの接続は、通常の画面遷移で作品を開く場合、中止時には前の画面へ戻します。
110
+ URLを直接開いた場合は履歴を追加せず、中止画面で「前の画面に戻る」を無効化し、
111
+ 「確認画面に戻る」で同じ作品の確認をやり直せます。確認のタイトルは
112
+ 「確認: この作品は機能拡張を使います」です。GUIのモーダルには
113
+ `manageHistory: false`を渡し、ダイアログ表示だけで履歴が増えるのを防ぎます。
114
+ 別の作品は新しいタブで開き、元のタブに未保存の編集・Undo履歴・実行状態を残します。
115
+ 元の作品の自動退避や復元のための再読み込みは行いません。
105
116
 
106
117
  カタログからの追加、通常・未申告・任意指定・取得失敗が混ざる作品では、従来どおり
107
118
  サンドボックスの中を既定にし、実行方法を選べます。必須の申告に反する選択は警告します。
@@ -109,6 +120,11 @@ import '@kubohiroya/turbowarp-extension-security-dialog/styles.css';
109
120
  追加画面の各行は、左からチェックボックス、アイコン、拡張名の順に並べます。
110
121
  名前やアイコンをクリックしても選択できます。
111
122
 
123
+ 個別確認モードでは、上部の「機能拡張を個別に確認」を選択中の表示にして無効化します。
124
+ 画像はホストが渡すアイコンやソース内のバナー指定を使い、指定がない場合にだけ共通アイコンを表示します。
125
+ HTTP(S)のソースから説明を読み取り、相対バナーURLは取得後のソースURLを基準に解決します。
126
+ 画像のキャッシュ取得がCORSで拒否されても、画像として直接表示できる場合は表示します。
127
+
112
128
  「キャンセル」「追加」はダイアログ下部に常時表示します。案内・一括設定・一覧の領域だけを
113
129
  スクロールするので、最下部まで移動せずに追加やキャンセルができます。注意のスナックバーは
114
130
  操作ボタンの上に表示し、ボタンを覆いません。
@@ -274,3 +290,8 @@ React と React DOM は peerDependencies なので、ホストが用意します
274
290
  0.6.0でMPL-2.0へ書き直したときの設計の記録は [書き直しの設計](docs/mpl-rewrite.ja.md) にあります。
275
291
 
276
292
  npmが固定したGitHubアーカイブを`.git`なしでビルドする場合、インストーラーはlockfileと同じ完全SHAを`TWEXTSEC_SOURCE_REVISION`で渡します。`sourceState: "git-archive"`として記録し、完全SHAがなければビルドを拒否します。ホストはインストール後の記録をmanifest・lockfileと照合します。
293
+
294
+ ## Editor の実装との責務分担
295
+
296
+ Editor 独自実装の移管元とライセンス確認は [EDITOR-MIGRATION.md](EDITOR-MIGRATION.md) に記録しています。
297
+ 追加した公開 API は GUI モジュールを import せず、ホストから必要な値・データ・コールバックを受け取ります。
package/README.md CHANGED
@@ -30,7 +30,7 @@ stay visible as the list scrolls. Closing the warning keeps the selection.
30
30
 
31
31
  **Open a project.** This SB3 stores Camera Source 0.19.4, Asset Cache 0.3.2 and Bubble 0.13.5
32
32
  as `data:` URLs. All three declare that they require unsandboxed execution, so the dialog
33
- preselects the only execution option and waits for OK or Cancel. No extension has run at
33
+ preselects the execution mode. The older screenshot below waits for OK or Cancel. No extension has run at
34
34
  the point shown.
35
35
 
36
36
  ![Public Editor review with unsandboxed execution preselected for the three required extensions](./assets/screenshots/public-review-open-en-20261106.png)
@@ -64,16 +64,17 @@ import '@kubohiroya/turbowarp-extension-security-dialog/styles.css';
64
64
  />
65
65
  ```
66
66
 
67
- Adding and opening differ in what is on the list and what can be chosen, not in how the question
68
- is put, so they are the same component.
67
+ Adding and opening share the component. Opening first presents information and three actions:
68
+ Do not run, Review each extension, and Enable all and run. Individual review shows exclusive
69
+ pressed buttons without execution icons and a separate final confirmation. Changing mode grants no permission.
69
70
 
70
71
  | | `add` | `open` |
71
72
  | --- | --- | --- |
72
73
  | What is listed | Catalog entries; dependencies are selected for you | Every extension the project uses |
73
74
  | Picking | Tick to choose | None: the project already names them |
74
- | How it runs | In the sandbox, or without it | Do not run, in the sandbox, or without it |
75
- | Where it loads from | Any of the four forms | Only whether a `remote-cacheable` row keeps its copy; every other row states how it loads |
76
- | All at once | Both choices | How they all run, and the copy where at least one row has one to decline |
75
+ | How it runs | In the sandbox, or without it | In individual review: Do not run, Run in the sandbox to try it out, Trust and run without the sandbox |
76
+ | Where it loads from | Any of the four forms | Information in the overview; cache choices in individual review |
77
+ | All at once | Both choices | Enable all and run; cache choices remain available in individual review |
77
78
 
78
79
  ### The four loading forms
79
80
 
@@ -99,9 +100,18 @@ screen states it instead of asking.
99
100
  ### Execution, trust and remembered choices
100
101
 
101
102
  **When opening a project whose extensions all declare unsandboxed execution required, that mode is preselected.**
102
- This applies only to a non-empty list with every declaration available and no failed row. The other two
103
- execution choices and the execution bulk control are hidden. OK approves execution; Cancel stops it.
104
- Nothing runs before OK. Loading-source and cache-decline choices remain independent.
103
+ This applies only to a non-empty list with every declaration initially available and no failed row.
104
+ Individual review still permits denial or a sandbox trial, with a warning for a contradictory trial.
105
+ Late declarations do not overwrite the selected mode. Nothing runs before explicit bulk or individual
106
+ confirmation. Loading-source and cache-decline choices remain independent.
107
+
108
+ For ordinary page navigation, the Editor goes back to the preceding page on cancellation. Its GUI
109
+ modal receives `manageHistory: false` to avoid another entry just for showing the dialog. Another
110
+ project opens in a new tab, leaving unsaved edits, undo history and running state in the original tab.
111
+ It does not automatically snapshot or reload the original project.
112
+ Direct project URLs do not insert a start page into history. Their stopped screen disables Back
113
+ when no previous page is available and offers an explicit action to return to confirmation for
114
+ the same project. The dialog title explicitly identifies it as a confirmation.
105
115
 
106
116
  Adding from the catalog, or opening a mixed, optional, undeclared or failed batch, keeps the sandbox
107
117
  as the default and leaves the execution choices available. A choice contradicting a declaration is warned about.
@@ -118,6 +128,11 @@ In add mode, the checkbox, preview icon and extension name appear together. The
118
128
  scrolls independently of Cancel and Add. Dismissing the unsandboxed notice preserves the selection
119
129
  and returns focus to the control that opened it.
120
130
 
131
+ Individual review keeps its top action visibly selected and disabled. Rows use the host's icon or
132
+ the source's declared banner; the common icon is only for rows without a picture declaration.
133
+ Display metadata can be read from HTTP(S), and relative banners resolve against the final source URL.
134
+ When CORS prevents caching an image, it can still be displayed directly by the browser.
135
+
121
136
  For trusted entries, the trust badge links to the extension page when provided. Supported
122
137
  GitHub versions link to their release notes. The description preserves line breaks and turns
123
138
  HTTP(S) URLs and email addresses into links. The creator's contact appears next to their name
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubohiroya/turbowarp-extension-security-dialog",
3
- "version": "0.9.0",
4
- "revision": "3b5531912d7999a85c96f2cfcfdc9d3fb2e222fb",
3
+ "version": "0.9.2",
4
+ "revision": "fb4b579ba5ea450cb2c7a61c5fe616ac33239bbb",
5
5
  "sourceState": "commit"
6
6
  }
@@ -0,0 +1,400 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // src/catalog-library.tsx
48
+ var catalog_library_exports = {};
49
+ __export(catalog_library_exports, {
50
+ createCatalogLibrary: () => createCatalogLibrary,
51
+ reviewRows: () => reviewRows
52
+ });
53
+ module.exports = __toCommonJS(catalog_library_exports);
54
+ var import_react = require("@kubohiroya/turbowarp-extension-security-dialog/react");
55
+
56
+ // src/display-urls.ts
57
+ var displayURL = (value, allowMail = false) => {
58
+ if (typeof value !== "string" || !value || /[\u0000-\u0020\u007f]/.test(value)) return null;
59
+ try {
60
+ const url = new URL(value);
61
+ if (url.username || url.password) return null;
62
+ if (url.protocol === "http:" || url.protocol === "https:") return value;
63
+ if (allowMail && url.protocol === "mailto:" && /^[^\s@]+@[^\s@]+$/.test(decodeURIComponent(url.pathname))) return value;
64
+ } catch (error) {
65
+ }
66
+ return null;
67
+ };
68
+ var contactURL = (value) => {
69
+ const address = displayURL(value, true);
70
+ if (!address || address.length > 2048 || new URL(address).hash) {
71
+ throw new Error("authorURL must be HTTP(S) or mailto without credentials or a fragment");
72
+ }
73
+ return address;
74
+ };
75
+
76
+ // src/catalog.ts
77
+ var ID = /^[A-Za-z0-9]+$/;
78
+ function fail(message) {
79
+ throw new Error(message);
80
+ }
81
+ var object = (value, what) => {
82
+ if (value === null || typeof value !== "object" || Array.isArray(value)) fail(`${what} must be an object`);
83
+ return value;
84
+ };
85
+ var string = (value, what, limit = 2048) => {
86
+ if (typeof value !== "string" || value.length === 0 || value.length > limit) fail(`${what} must be text`);
87
+ return value;
88
+ };
89
+ var reviewURL = (value, what = "URL", allowHTTP = false) => {
90
+ const text2 = string(value, what);
91
+ let url;
92
+ try {
93
+ url = new URL(text2);
94
+ } catch (error) {
95
+ fail(`${what} must be an absolute URL`);
96
+ }
97
+ const schemes = allowHTTP ? ["https:", "http:"] : ["https:"];
98
+ if (!schemes.includes(url.protocol) || url.username || url.password || url.hash) {
99
+ fail(`${what} must be ${allowHTTP ? "HTTP(S)" : "HTTPS"} without credentials or a fragment`);
100
+ }
101
+ return text2;
102
+ };
103
+ var metadataOf = (value) => {
104
+ const source = object(value, "metadata");
105
+ const result = {};
106
+ for (const key of [
107
+ "name",
108
+ "id",
109
+ "description",
110
+ "author",
111
+ "version",
112
+ "license",
113
+ "package",
114
+ "banner",
115
+ "unsandboxed",
116
+ "updatedAt"
117
+ ]) {
118
+ if (source[key] !== void 0) result[key] = string(source[key], key, 4096);
119
+ }
120
+ for (const key of ["repository", "docsURL"]) {
121
+ if (source[key] !== void 0) result[key] = reviewURL(source[key], key);
122
+ }
123
+ if (source.authorURL !== void 0) result.authorURL = contactURL(source.authorURL);
124
+ if (source.descriptions !== void 0) {
125
+ const descriptions = object(source.descriptions, "descriptions");
126
+ result.descriptions = {};
127
+ for (const [tag, text2] of Object.entries(descriptions)) {
128
+ if (!/^[a-z]{2}(-[A-Za-z0-9]+)*$/.test(tag)) fail("descriptions keys must be language tags");
129
+ result.descriptions[tag] = string(text2, "description", 4096);
130
+ }
131
+ }
132
+ return result;
133
+ };
134
+ var categoriesOf = (value) => {
135
+ const list = value === void 0 ? [] : value;
136
+ if (!Array.isArray(list)) fail("categories must be a list");
137
+ const byId = /* @__PURE__ */ new Map();
138
+ list.forEach((item, order) => {
139
+ const category = object(item, "category");
140
+ const id = string(category.id, "category id", 128);
141
+ if (byId.has(id)) fail(`Duplicate category ${id}`);
142
+ const resolved = { id, title: string(category.title, "category title", 256), order };
143
+ if (category.titleJa !== void 0) resolved.titleJa = string(category.titleJa, "category titleJa", 256);
144
+ byId.set(id, Object.freeze(resolved));
145
+ });
146
+ return byId;
147
+ };
148
+ function parseExtensionCatalog(data) {
149
+ const document = object(data, "catalog");
150
+ if (document.schemaVersion !== void 0 && document.schemaVersion !== 1) {
151
+ fail(`Unsupported catalog schema ${document.schemaVersion}`);
152
+ }
153
+ const categories = categoriesOf(document.categories);
154
+ const list = document.extensions;
155
+ if (!Array.isArray(list)) fail("catalog extensions must be a list");
156
+ const byId = /* @__PURE__ */ new Map();
157
+ const urls = /* @__PURE__ */ new Set();
158
+ const entries = list.map((item) => {
159
+ const source = object(item, "extension");
160
+ const id = string(source.id, "extension id", 128);
161
+ if (!ID.test(id)) fail(`Invalid extension id ${id}`);
162
+ if (byId.has(id)) fail(`Duplicate extension ${id}`);
163
+ const url = reviewURL(source.url, `${id} url`);
164
+ if (urls.has(url)) fail(`Duplicate extension URL ${url}`);
165
+ urls.add(url);
166
+ const dependencies = source.dependencies === void 0 ? [] : source.dependencies;
167
+ if (!Array.isArray(dependencies)) fail(`${id} dependencies must be a list`);
168
+ const entry = {
169
+ key: id,
170
+ id,
171
+ ids: [id],
172
+ url,
173
+ dependencies: Object.freeze(dependencies.map((value) => string(value, "dependency", 128))),
174
+ // The dashboard catalog states name, description, creator and banner beside the URL.
175
+ // A nested `metadata` object, the older shape, still wins where it says something.
176
+ metadata: Object.freeze(metadataOf(__spreadValues(__spreadValues({}, source), source.metadata === void 0 ? {} : object(source.metadata, "metadata"))))
177
+ };
178
+ if (source.sha256 !== void 0) {
179
+ entry.sha256 = string(source.sha256, "sha256", 64);
180
+ if (!/^[0-9a-f]{64}$/.test(entry.sha256)) fail(`Invalid sha256 for ${id}`);
181
+ }
182
+ if (source.category !== void 0) {
183
+ const category = string(source.category, "category", 128);
184
+ if (!categories.has(category)) fail(`Unknown category ${category}`);
185
+ entry.category = categories.get(category);
186
+ }
187
+ byId.set(id, entry);
188
+ return entry;
189
+ });
190
+ for (const entry of entries) {
191
+ for (const dependency of entry.dependencies) {
192
+ if (!byId.has(dependency)) fail(`${entry.id} depends on missing ${dependency}`);
193
+ }
194
+ }
195
+ const state = /* @__PURE__ */ new Map();
196
+ const walk = (id) => {
197
+ const mark = state.get(id);
198
+ if (mark === "done") return;
199
+ if (mark === "open") fail(`Dependency cycle at ${id}`);
200
+ state.set(id, "open");
201
+ for (const dependency of byId.get(id).dependencies) walk(dependency);
202
+ state.set(id, "done");
203
+ };
204
+ for (const entry of entries) walk(entry.id);
205
+ return entries.map((entry) => Object.freeze(entry));
206
+ }
207
+
208
+ // src/catalog-library.tsx
209
+ var import_react2 = __toESM(require("react"), 1);
210
+ var text = {
211
+ en: {
212
+ loading: "Loading TurboWarp Plus extensions\u2026",
213
+ failed: "The extension catalog could not be loaded.",
214
+ denied: "No extensions were loaded. Review the selected extensions and their permissions.",
215
+ retry: "Retry"
216
+ },
217
+ ja: {
218
+ loading: "TurboWarp Plus\u306E\u6A5F\u80FD\u62E1\u5F35\u3092\u53D6\u5F97\u3057\u3066\u3044\u307E\u3059\u2026",
219
+ failed: "\u6A5F\u80FD\u62E1\u5F35\u306E\u4E00\u89A7\u3092\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\u3002",
220
+ denied: "\u6A5F\u80FD\u62E1\u5F35\u306F\u8AAD\u307F\u8FBC\u307E\u308C\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u9078\u629E\u3068\u8AAD\u307F\u8FBC\u307F\u8A31\u53EF\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002",
221
+ retry: "\u518D\u8A66\u884C"
222
+ }
223
+ };
224
+ var reviewRows = (entries, vm, loader = true) => entries.map((entry) => ({
225
+ key: entry.id,
226
+ ids: [entry.id],
227
+ metadata: entry.metadata,
228
+ source: { kind: loader ? "catalog" : "legacy", url: entry.url },
229
+ dependencies: [...entry.dependencies || []],
230
+ state: { trusted: true, loaded: vm.extensionManager.isExtensionLoaded(entry.id) }
231
+ }));
232
+ function createCatalogLibrary({
233
+ catalog: plusCatalog,
234
+ readSettings: readPlusCatalogSettings,
235
+ applySettings: applyPlusCatalogSettings,
236
+ loadExtensions: loadPlusExtensions,
237
+ loaderEnabled: PLUS_EXTENSION_LOADER_ENABLED,
238
+ isRetryable: isWorthAskingAgain,
239
+ styles
240
+ }) {
241
+ class PlusLibrary extends import_react2.default.PureComponent {
242
+ constructor(props) {
243
+ super(props);
244
+ this.handleFetchCatalog = this.handleFetchCatalog.bind(this);
245
+ this.handleComplete = this.handleComplete.bind(this);
246
+ this.handleRetry = this.handleRetry.bind(this);
247
+ this.state = {
248
+ entries: null,
249
+ fetchError: false,
250
+ denied: false,
251
+ failure: null,
252
+ busy: false,
253
+ decisions: /* @__PURE__ */ new Map()
254
+ };
255
+ this.answered = null;
256
+ }
257
+ componentDidMount() {
258
+ this.alive = true;
259
+ this.handleFetchCatalog();
260
+ }
261
+ componentWillUnmount() {
262
+ this.alive = false;
263
+ if (this.controller) this.controller.abort();
264
+ }
265
+ async handleFetchCatalog() {
266
+ var _a, _b;
267
+ if (this.controller) this.controller.abort();
268
+ this.controller = new AbortController();
269
+ this.setState({ fetchError: false });
270
+ const timeout = setTimeout(() => {
271
+ var _a2;
272
+ return (_a2 = this.controller) == null ? void 0 : _a2.abort();
273
+ }, 15e3);
274
+ try {
275
+ const read = await plusCatalog.read((_b = (_a = this.controller) == null ? void 0 : _a.signal) != null ? _b : new AbortController().signal);
276
+ const entries = read.catalog ? parseExtensionCatalog(read.catalog) : [];
277
+ const icons = read.icons || {};
278
+ for (const entry of entries) {
279
+ if (Object.hasOwn(icons, entry.id)) {
280
+ entry.metadata = __spreadProps(__spreadValues({}, entry.metadata), { banner: icons[entry.id] });
281
+ }
282
+ }
283
+ const { decisions } = await readPlusCatalogSettings(this.props.vm, entries);
284
+ if (this.alive) this.setState({ entries, decisions });
285
+ } catch (error) {
286
+ if (this.alive) {
287
+ console.error(error);
288
+ this.setState({ fetchError: true });
289
+ }
290
+ } finally {
291
+ clearTimeout(timeout);
292
+ }
293
+ }
294
+ /**
295
+ * Act on the screen's answer: every chosen row, with how it runs and how it loads.
296
+ * @param {Map<string, object>|null} decisions The answer by extension ID, or null for no.
297
+ */
298
+ async handleComplete(decisions) {
299
+ if (decisions === null) {
300
+ this.props.onRequestClose();
301
+ return;
302
+ }
303
+ this.answered = decisions;
304
+ await this.apply(decisions);
305
+ }
306
+ /**
307
+ * Ask again with the answer that just failed, as the screen's "Try again" requests.
308
+ */
309
+ async handleRetry() {
310
+ if (this.answered && !this.state.busy) await this.apply(this.answered);
311
+ }
312
+ /**
313
+ * Load the chosen rows as answered, and keep how it failed for the screen to state.
314
+ * @param {Map<string, object>} decisions The answer by extension ID.
315
+ */
316
+ async apply(decisions) {
317
+ var _a, _b, _c;
318
+ const chosen = ((_a = this.state.entries) != null ? _a : []).filter((entry) => decisions.has(entry.id));
319
+ this.setState({ busy: true, denied: false, failure: null });
320
+ this.props.onBusyChange(true);
321
+ try {
322
+ const loaded = PLUS_EXTENSION_LOADER_ENABLED ? await applyPlusCatalogSettings(
323
+ this.props.vm,
324
+ { entries: chosen, decisions },
325
+ { signal: (_c = (_b = this.controller) == null ? void 0 : _b.signal) != null ? _c : new AbortController().signal }
326
+ ) : await loadPlusExtensions(
327
+ this.props.vm,
328
+ chosen,
329
+ new Map(chosen.map((entry) => {
330
+ var _a2, _b2;
331
+ return [entry.url, (_b2 = (_a2 = decisions.get(entry.id)) == null ? void 0 : _a2.execution) != null ? _b2 : "deny"];
332
+ })),
333
+ this.props.permissions
334
+ );
335
+ if (!this.alive) return;
336
+ if (loaded.length) {
337
+ this.props.onCategorySelected(loaded[loaded.length - 1]);
338
+ this.props.onRequestClose();
339
+ } else this.setState({ denied: true });
340
+ } catch (error) {
341
+ console.error(error);
342
+ if (this.alive) {
343
+ const failure = error;
344
+ this.setState({ failure: {
345
+ code: (failure == null ? void 0 : failure.code) || "LOAD_FAILED",
346
+ message: (failure == null ? void 0 : failure.message) || String(error),
347
+ retryable: isWorthAskingAgain(error)
348
+ } });
349
+ }
350
+ } finally {
351
+ if (this.alive) {
352
+ this.setState({ busy: false });
353
+ this.props.onBusyChange(false);
354
+ }
355
+ }
356
+ }
357
+ render() {
358
+ const t = text[this.props.locale.startsWith("ja") ? "ja" : "en"];
359
+ const { entries, busy, denied, failure, fetchError, decisions } = this.state;
360
+ if (!entries) {
361
+ return /* @__PURE__ */ import_react2.default.createElement(
362
+ "div",
363
+ {
364
+ className: styles.message,
365
+ role: fetchError ? "alert" : "status"
366
+ },
367
+ /* @__PURE__ */ import_react2.default.createElement("p", null, fetchError ? t.failed : t.loading),
368
+ fetchError && /* @__PURE__ */ import_react2.default.createElement(
369
+ "button",
370
+ {
371
+ type: "button",
372
+ onClick: this.handleFetchCatalog
373
+ },
374
+ t.retry
375
+ )
376
+ );
377
+ }
378
+ return /* @__PURE__ */ import_react2.default.createElement("div", { className: styles.root }, denied && /* @__PURE__ */ import_react2.default.createElement(
379
+ "p",
380
+ {
381
+ className: styles.error,
382
+ role: "alert"
383
+ },
384
+ t.denied
385
+ ), /* @__PURE__ */ import_react2.default.createElement("div", { hidden: busy }, /* @__PURE__ */ import_react2.default.createElement(
386
+ import_react.ExtensionReview,
387
+ {
388
+ mode: "add",
389
+ entries: reviewRows(entries, this.props.vm, PLUS_EXTENSION_LOADER_ENABLED),
390
+ initialDecisions: decisions,
391
+ locale: this.props.locale,
392
+ failure,
393
+ onRetry: this.handleRetry,
394
+ onComplete: this.handleComplete
395
+ }
396
+ )), busy && /* @__PURE__ */ import_react2.default.createElement("p", { role: "status" }, t.loading));
397
+ }
398
+ }
399
+ return PlusLibrary;
400
+ }
@@ -0,0 +1,108 @@
1
+ import type { CatalogEntry, ReviewDecision, ReviewEntry, ReviewFailure } from './index.js';
2
+ import React from 'react';
3
+ /**
4
+ * The catalog as rows of the review screen.
5
+ *
6
+ * With the Loader switched off there is nothing to write a form into — the extension loads by its
7
+ * address, as a custom extension does — so the rows say so and the screen offers no form.
8
+ * @param {Array<object>} entries Parsed catalog entries.
9
+ * @param {object} vm The VM, to say which are already running.
10
+ * @param {boolean} [loader] Whether the Loader writes the chosen form into the project.
11
+ * @returns {Array<object>} One `ReviewEntry` per catalog entry, keyed by its extension ID.
12
+ */
13
+ interface LibraryVM {
14
+ extensionManager: {
15
+ isExtensionLoaded(id: string): boolean;
16
+ securityManager: object;
17
+ loadExtensionURL(url: string): Promise<unknown>;
18
+ _loadedExtensions: ReadonlyMap<string, string>;
19
+ };
20
+ }
21
+ type Decisions = Map<string, ReviewDecision>;
22
+ interface LibraryProps {
23
+ vm: LibraryVM;
24
+ locale: string;
25
+ filterQuery?: string;
26
+ permissions: unknown;
27
+ onBusyChange(busy: boolean): void;
28
+ onCategorySelected(id: string): void;
29
+ onRequestClose(): void;
30
+ }
31
+ interface LibraryState {
32
+ entries: CatalogEntry[] | null;
33
+ fetchError: boolean;
34
+ denied: boolean;
35
+ failure: ReviewFailure | null;
36
+ busy: boolean;
37
+ decisions: Decisions;
38
+ }
39
+ export declare const reviewRows: (entries: CatalogEntry[], vm: LibraryVM, loader?: boolean) => ReviewEntry[];
40
+ export interface CatalogLibraryPorts {
41
+ catalog: {
42
+ read(signal: AbortSignal): Promise<{
43
+ catalog?: unknown;
44
+ icons?: Record<string, string>;
45
+ }>;
46
+ };
47
+ readSettings(vm: LibraryVM, entries: CatalogEntry[]): Promise<{
48
+ decisions: Decisions;
49
+ }>;
50
+ applySettings(vm: LibraryVM, selection: {
51
+ entries: CatalogEntry[];
52
+ decisions: Decisions;
53
+ }, options: {
54
+ signal: AbortSignal;
55
+ }): Promise<string[]>;
56
+ loadExtensions(vm: LibraryVM, entries: CatalogEntry[], modes: Map<string, string>, permissions: any): Promise<string[]>;
57
+ loaderEnabled: boolean;
58
+ isRetryable(error: unknown): boolean;
59
+ styles: Record<string, string>;
60
+ }
61
+ /** The host supplies its trusted catalog and loading ports, never GUI components. */
62
+ export declare function createCatalogLibrary({ catalog: plusCatalog, readSettings: readPlusCatalogSettings, applySettings: applyPlusCatalogSettings, loadExtensions: loadPlusExtensions, loaderEnabled: PLUS_EXTENSION_LOADER_ENABLED, isRetryable: isWorthAskingAgain, styles }: CatalogLibraryPorts): {
63
+ new (props: LibraryProps): {
64
+ controller?: AbortController;
65
+ answered: Decisions | null;
66
+ alive: boolean;
67
+ componentDidMount(): void;
68
+ componentWillUnmount(): void;
69
+ handleFetchCatalog(): Promise<void>;
70
+ /**
71
+ * Act on the screen's answer: every chosen row, with how it runs and how it loads.
72
+ * @param {Map<string, object>|null} decisions The answer by extension ID, or null for no.
73
+ */
74
+ handleComplete(decisions: Decisions | null): Promise<void>;
75
+ /**
76
+ * Ask again with the answer that just failed, as the screen's "Try again" requests.
77
+ */
78
+ handleRetry(): Promise<void>;
79
+ /**
80
+ * Load the chosen rows as answered, and keep how it failed for the screen to state.
81
+ * @param {Map<string, object>} decisions The answer by extension ID.
82
+ */
83
+ apply(decisions: Decisions): Promise<void>;
84
+ render(): React.JSX.Element;
85
+ context: any;
86
+ setState<K extends keyof LibraryState>(state: LibraryState | ((prevState: Readonly<LibraryState>, props: Readonly<LibraryProps>) => LibraryState | Pick<LibraryState, K> | null) | Pick<LibraryState, K> | null, callback?: (() => void) | undefined): void;
87
+ forceUpdate(callback?: (() => void) | undefined): void;
88
+ readonly props: Readonly<LibraryProps> & Readonly<{
89
+ children?: React.ReactNode | undefined;
90
+ }>;
91
+ state: Readonly<LibraryState>;
92
+ refs: {
93
+ [key: string]: React.ReactInstance;
94
+ };
95
+ shouldComponentUpdate?(nextProps: Readonly<LibraryProps>, nextState: Readonly<LibraryState>, nextContext: any): boolean;
96
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
97
+ getSnapshotBeforeUpdate?(prevProps: Readonly<LibraryProps>, prevState: Readonly<LibraryState>): any;
98
+ componentDidUpdate?(prevProps: Readonly<LibraryProps>, prevState: Readonly<LibraryState>, snapshot?: any): void;
99
+ componentWillMount?(): void;
100
+ UNSAFE_componentWillMount?(): void;
101
+ componentWillReceiveProps?(nextProps: Readonly<LibraryProps>, nextContext: any): void;
102
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<LibraryProps>, nextContext: any): void;
103
+ componentWillUpdate?(nextProps: Readonly<LibraryProps>, nextState: Readonly<LibraryState>, nextContext: any): void;
104
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<LibraryProps>, nextState: Readonly<LibraryState>, nextContext: any): void;
105
+ };
106
+ contextType?: React.Context<any> | undefined;
107
+ };
108
+ export {};