dsh-m 0.0.3 → 0.1.1
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/DESIGN.md +140 -0
- package/README.en.md +89 -0
- package/README.md +78 -11
- package/cordis.patch.yml +3 -0
- package/lib/.keep +0 -0
- package/lib/cli.js +196 -0
- package/lib/client.js +1159 -0
- package/lib/core/dsh-cli.js +320 -0
- package/lib/core/env.js +18 -0
- package/lib/core/httpx.js +94 -0
- package/lib/core/installed.js +186 -0
- package/lib/core/live-plugin.js +42 -0
- package/lib/core/market.js +198 -0
- package/lib/core/progress.js +113 -0
- package/lib/core/registry.js +167 -0
- package/lib/core/restart.js +213 -0
- package/lib/core/versions.js +75 -0
- package/lib/host.js +199 -0
- package/lib/tools.js +341 -0
- package/package.json +58 -7
- package/registry.json +92 -0
- package/index.js +0 -9
package/lib/client.js
ADDED
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-m",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
"use strict";
|
|
5
|
+
|
|
6
|
+
// src/client/main.jsx
|
|
7
|
+
var React = require("react");
|
|
8
|
+
var rd = require("react-dom");
|
|
9
|
+
var h = React.createElement;
|
|
10
|
+
var { useState, useEffect, useCallback, useMemo } = React;
|
|
11
|
+
var PLUGIN_ID = "dsh-m";
|
|
12
|
+
var API = "/dshm";
|
|
13
|
+
var ZH = {
|
|
14
|
+
"market.title": "\u63D2\u4EF6\u5E02\u573A",
|
|
15
|
+
"tab.market": "\u5E02\u573A",
|
|
16
|
+
"tab.installed": "\u5DF2\u88C5",
|
|
17
|
+
"tab.settings": "\u8BBE\u7F6E",
|
|
18
|
+
"cat.all": "\u5168\u90E8",
|
|
19
|
+
"cat.market": "\u5E02\u573A",
|
|
20
|
+
"cat.tools": "\u5DE5\u5177",
|
|
21
|
+
"cat.ui": "\u754C\u9762",
|
|
22
|
+
"cat.search": "\u641C\u7D22",
|
|
23
|
+
"cat.media": "\u591A\u5A92\u4F53",
|
|
24
|
+
"cat.other": "\u5176\u4ED6",
|
|
25
|
+
"search.ph": "\u641C\u7D22\u540D\u79F0 / \u63CF\u8FF0 / \u6807\u7B7E\u2026",
|
|
26
|
+
"common.refresh": "\u5237\u65B0",
|
|
27
|
+
"common.close": "\u5173\u95ED",
|
|
28
|
+
"common.later": "\u7A0D\u540E",
|
|
29
|
+
"common.ok": "\u77E5\u9053\u4E86",
|
|
30
|
+
"common.none": "\u2014",
|
|
31
|
+
"market.loading": "\u52A0\u8F7D\u6536\u5F55\u6E05\u5355\u4E2D\u2026 ",
|
|
32
|
+
"market.empty": "\u6CA1\u6709\u5339\u914D\u7684\u6536\u5F55\u6761\u76EE",
|
|
33
|
+
"installed.loading": "\u8BFB\u53D6 web profile \u4E2D\u2026 ",
|
|
34
|
+
"installed.empty": "web profile \u5C1A\u672A\u5B89\u88C5\u4EFB\u4F55 dsh \u63D2\u4EF6",
|
|
35
|
+
"installed.none": "\u672A\u5B89\u88C5",
|
|
36
|
+
"installed.others": "\u53E6\u6709 {n} \u4E2A\u975E dsh \u4F9D\u8D56\uFF08\u672A\u8BC6\u522B\u4E3A\u63D2\u4EF6\uFF09\uFF0C\u5DF2\u9ED8\u8BA4\u6298\u53E0\u3002",
|
|
37
|
+
"badge.installed": "\u5DF2\u5B89\u88C5",
|
|
38
|
+
"badge.update": "\u53EF\u5347\u7EA7",
|
|
39
|
+
"badge.market": "\u5E02\u573A\u5B89\u88C5",
|
|
40
|
+
"badge.nonmarket": "\u975E\u5E02\u573A\u5B89\u88C5",
|
|
41
|
+
"action.install": "\u5B89\u88C5",
|
|
42
|
+
"action.upgrade": "\u5347\u7EA7",
|
|
43
|
+
"action.uninstall": "\u5378\u8F7D",
|
|
44
|
+
"confirm.uninstall": "\u786E\u8BA4\u5378\u8F7D\uFF1F",
|
|
45
|
+
"confirm.unlink": "\u786E\u8BA4\u79FB\u9664\u672C\u5730\u5F15\u7528\uFF1F",
|
|
46
|
+
"confirm.core": "\u26A0\uFE0F \u786E\u8BA4\u5378\u8F7D\u6838\u5FC3\u5305\uFF1F",
|
|
47
|
+
"detail.id": "\u6536\u5F55 id",
|
|
48
|
+
"detail.source": "\u6765\u6E90",
|
|
49
|
+
"detail.latest": "\u6700\u65B0",
|
|
50
|
+
"detail.installed": "\u5DF2\u88C5",
|
|
51
|
+
"detail.tags": "\u6807\u7B7E",
|
|
52
|
+
"detail.pkg": "\u5305\u540D",
|
|
53
|
+
"detail.spec": "\u5B89\u88C5 spec",
|
|
54
|
+
"detail.listed": "\u6536\u5F55",
|
|
55
|
+
"detail.listed.no": "\u4E0D\u5728\u6536\u5F55\u6E05\u5355\u4E2D",
|
|
56
|
+
"detail.path": "\u8DEF\u5F84",
|
|
57
|
+
"detail.note": "\u6CE8\u610F",
|
|
58
|
+
"manage.hint": "\u5DF2\u5B89\u88C5\uFF0C\u53EF\u5728\u300C\u5DF2\u88C5\u300D\u9875\u7BA1\u7406",
|
|
59
|
+
"version.failed": "\u7248\u672C\u67E5\u8BE2\u5931\u8D25",
|
|
60
|
+
"src.npm": "npm",
|
|
61
|
+
"src.github": "github",
|
|
62
|
+
"src.link": "\u672C\u5730 link",
|
|
63
|
+
"src.file": "\u672C\u5730 file",
|
|
64
|
+
"src.unknown": "\u672A\u77E5",
|
|
65
|
+
"sub.latest": "\u6700\u65B0 v{v}",
|
|
66
|
+
"sub.head": "HEAD {sha}",
|
|
67
|
+
"sub.installed": "\u5DF2\u88C5 v{v}",
|
|
68
|
+
"settings.registry": "\u6536\u5F55\u6E05\u5355\uFF08registry\uFF09",
|
|
69
|
+
"settings.source": "\u5F53\u524D\u6765\u6E90",
|
|
70
|
+
"settings.updated": "\u66F4\u65B0\u65F6\u95F4",
|
|
71
|
+
"settings.count": "\u6761\u76EE\u6570",
|
|
72
|
+
"settings.count.v": "{n} \u6761",
|
|
73
|
+
"settings.policy": "\u7F13\u5B58\u7B56\u7565",
|
|
74
|
+
"settings.policy.v": "TTL 60 \u5206\u949F\uFF1B\u8BBE\u7F6E registryUrl \u53EF\u8986\u76D6\u6E90",
|
|
75
|
+
"settings.remotehint": "\u8FDC\u7AEF\u63D0\u793A",
|
|
76
|
+
"settings.force": "\u5F3A\u5236\u5237\u65B0",
|
|
77
|
+
"settings.self": "dsh-m \u81EA\u8EAB",
|
|
78
|
+
"settings.current": "\u5F53\u524D\u7248\u672C",
|
|
79
|
+
"settings.npmlatest": "npm \u6700\u65B0",
|
|
80
|
+
"settings.lookupfailed": "\u67E5\u8BE2\u5931\u8D25\uFF1A{err}",
|
|
81
|
+
"settings.upgradeself": "\u5347\u7EA7 dsh-m",
|
|
82
|
+
"settings.upgradehint": "\u5347\u7EA7\u540E\u540C\u6837\u9700\u8981\u91CD\u542F\u751F\u6548",
|
|
83
|
+
"settings.about": "\u5173\u4E8E",
|
|
84
|
+
"settings.about.text": "DSH Marketplace\uFF08dsh-m\uFF09\u2014 \u4E2A\u4EBA\u81EA\u7528\u7684 DeepSeek Harness \u63D2\u4EF6\u5E02\u573A\u3002\u6536\u5F55\u3001\u5B89\u88C5\u3001\u5378\u8F7D\u3001\u5347\u7EA7\uFF0C\u5168\u90E8\u672C\u673A\u5B8C\u6210\u3002",
|
|
85
|
+
"src.override": "\u81EA\u5B9A\u4E49\u6E90",
|
|
86
|
+
"src.jsdelivr": "jsDelivr\uFF08@main\uFF09",
|
|
87
|
+
"src.raw": "raw.githubusercontent\uFF08@main\uFF09",
|
|
88
|
+
"src.cache": "\u672C\u5730\u7F13\u5B58",
|
|
89
|
+
"src.bundled": "\u5305\u5185\u5FEB\u7167\uFF08\u515C\u5E95\uFF09",
|
|
90
|
+
"self.upgraded": "dsh-m \u5DF2\u66F4\u65B0\u5230 v{v}\uFF0C\u91CD\u542F\u540E\u751F\u6548",
|
|
91
|
+
"self.failed": "\u81EA\u66F4\u65B0\u5931\u8D25\uFF1A{err}",
|
|
92
|
+
"registry.refreshed": "\u6536\u5F55\u6E05\u5355\u5DF2\u5F3A\u5236\u5237\u65B0",
|
|
93
|
+
"notify.installed": "\u5DF2\u5B89\u88C5 {pkg}{version}",
|
|
94
|
+
"notify.allowbuilds": "\uFF08\u6CE8\u610F\uFF1A\u8BE5\u63D2\u4EF6\u6267\u884C\u4E86\u6784\u5EFA\u811A\u672C\uFF0C\u5DF2\u6309\u7B56\u7565\u653E\u884C\uFF09",
|
|
95
|
+
"notify.uninstalled": "\u5DF2\u5378\u8F7D {pkg}",
|
|
96
|
+
"notify.livedisabled": "\uFF08\u5DF2\u5148\u4E0B\u7EBF\u8FD0\u884C\u4E2D\u7684\u754C\u9762\uFF09",
|
|
97
|
+
"notify.leftovers": "\uFF1B\u68C0\u6D4B\u5230\u7591\u4F3C\u6B8B\u7559\u6570\u636E\uFF1A{paths}",
|
|
98
|
+
"notify.upgraded": "\u5DF2\u5347\u7EA7 {pkg}\uFF08{from} \u2192 {to}\uFF09",
|
|
99
|
+
"notify.upgradehint": "\uFF08\u6CE8\u610F\uFF1A\u8BE5\u63D2\u4EF6\u6267\u884C\u4E86\u6784\u5EFA\u811A\u672C\uFF09",
|
|
100
|
+
"failed.install": "\u5B89\u88C5\u5931\u8D25\uFF1A{err}",
|
|
101
|
+
"failed.uninstall": "\u5378\u8F7D\u5931\u8D25\uFF1A{err}",
|
|
102
|
+
"failed.upgrade": "\u5347\u7EA7\u5931\u8D25\uFF1A{err}",
|
|
103
|
+
"failed.selfupdate": "\u81EA\u66F4\u65B0\u5931\u8D25\uFF1A{err}",
|
|
104
|
+
"failed.load": "\u52A0\u8F7D\u5931\u8D25\uFF1A{err}",
|
|
105
|
+
"failed.read": "\u8BFB\u53D6\u5931\u8D25\uFF1A{err}",
|
|
106
|
+
"failed.open": "\u6253\u5F00\u5E02\u573A\u9762\u677F\u5931\u8D25:",
|
|
107
|
+
"banner.done": "\u53D8\u66F4\u5B8C\u6210\uFF0C\u9700\u8981\u91CD\u542F DSH Web \u540E\u751F\u6548\u3002",
|
|
108
|
+
"restart.doing": "\u6B63\u5728\u8BF7\u6C42\u91CD\u542F\u2026",
|
|
109
|
+
"restart.waiting": "\u5DF2\u8BF7\u6C42\u91CD\u542F\uFF0C\u7B49\u5F85 DSH Web \u6062\u590D\u2026",
|
|
110
|
+
"restart.now": "\u26A1 \u4E00\u952E\u91CD\u542F",
|
|
111
|
+
"restart.failed": "\u91CD\u542F\u5931\u8D25\uFF1A{err}",
|
|
112
|
+
"restart.timeout": "\u91CD\u542F\u8D85\u65F6\uFF0C\u8BF7\u624B\u52A8\u68C0\u67E5 dsh web \u670D\u52A1\u72B6\u6001",
|
|
113
|
+
"restart.hint.done": "\u5DF2\u8BF7\u6C42\u91CD\u542F DSH web\uFF08via {via}\uFF09\u3002\u670D\u52A1\u51E0\u79D2\u5185\u6062\u590D\uFF0C\u4E4B\u540E\u8BA9\u7528\u6237\u5237\u65B0\u9875\u9762\u5373\u53EF\u3002",
|
|
114
|
+
"phase.resolving": "\u89E3\u6790\u4F9D\u8D56",
|
|
115
|
+
"phase.downloading": "\u4E0B\u8F7D",
|
|
116
|
+
"phase.linking": "\u94FE\u63A5\u5B89\u88C5",
|
|
117
|
+
"phase.building": "\u6784\u5EFA\u811A\u672C",
|
|
118
|
+
"phase.ready": "\u51C6\u5907\u4E2D",
|
|
119
|
+
"readme.show": "\u{1F4D6} README",
|
|
120
|
+
"readme.hide": "\u6536\u8D77 README",
|
|
121
|
+
"readme.loading": "\u52A0\u8F7D README\u2026 ",
|
|
122
|
+
"readme.none": "\uFF08\u8BE5\u63D2\u4EF6\u6CA1\u6709 README\uFF09",
|
|
123
|
+
"readme.truncated": "\n\n\u2026\uFF08\u8D85\u8FC7 64KB \u5DF2\u622A\u65AD\uFF0C\u5B8C\u6574\u5185\u5BB9\u89C1\u63D2\u4EF6\u76EE\u5F55\uFF09",
|
|
124
|
+
"warn.unlink": "\u5378\u8F7D\u53EA\u79FB\u9664 profile \u5BF9\u672C\u5730\u76EE\u5F55\u7684\u5F15\u7528\uFF08{path}\uFF09\uFF0C\u4E0D\u4F1A\u5220\u9664\u76EE\u5F55\u672C\u8EAB\u3002",
|
|
125
|
+
"warn.core": "\u8FD9\u662F file: \u5B89\u88C5\u7684\u6838\u5FC3/\u5F52\u6863\u5305\uFF0C\u5378\u8F7D\u53EF\u80FD\u5F71\u54CD DSH \u529F\u80FD\uFF0C\u4E14\u9700\u8981\u624B\u52A8\u6062\u590D\u3002",
|
|
126
|
+
"profile.hint": "web profile\uFF1A{path}",
|
|
127
|
+
"title.panel": "\u63D2\u4EF6\u5E02\u573A",
|
|
128
|
+
"title.full": "DeepSeek Harness \u63D2\u4EF6\u5E02\u573A"
|
|
129
|
+
};
|
|
130
|
+
var EN = {
|
|
131
|
+
"market.title": "Plugin Marketplace",
|
|
132
|
+
"title.panel": "Plugin Marketplace",
|
|
133
|
+
"title.full": "DeepSeek Harness Plugin Marketplace",
|
|
134
|
+
"tab.market": "Market",
|
|
135
|
+
"tab.installed": "Installed",
|
|
136
|
+
"tab.settings": "Settings",
|
|
137
|
+
"cat.all": "All",
|
|
138
|
+
"cat.market": "Market",
|
|
139
|
+
"cat.tools": "Tools",
|
|
140
|
+
"cat.ui": "UI",
|
|
141
|
+
"cat.search": "Search",
|
|
142
|
+
"cat.media": "Media",
|
|
143
|
+
"cat.other": "Other",
|
|
144
|
+
"search.ph": "Search name, description, tags\u2026",
|
|
145
|
+
"common.refresh": "Refresh",
|
|
146
|
+
"common.close": "Close",
|
|
147
|
+
"common.later": "Later",
|
|
148
|
+
"common.ok": "OK",
|
|
149
|
+
"common.none": "\u2014",
|
|
150
|
+
"market.loading": "Loading listings\u2026 ",
|
|
151
|
+
"market.empty": "No matching listings",
|
|
152
|
+
"installed.loading": "Reading web profile\u2026 ",
|
|
153
|
+
"installed.empty": "No DSH plugins installed in this web profile",
|
|
154
|
+
"installed.none": "Not installed",
|
|
155
|
+
"installed.others": "{n} non-DSH dependencies (not recognized as plugins) are collapsed.",
|
|
156
|
+
"badge.installed": "Installed",
|
|
157
|
+
"badge.update": "Update",
|
|
158
|
+
"badge.market": "Via market",
|
|
159
|
+
"badge.nonmarket": "Non-market",
|
|
160
|
+
"action.install": "Install",
|
|
161
|
+
"action.upgrade": "Upgrade",
|
|
162
|
+
"action.uninstall": "Uninstall",
|
|
163
|
+
"confirm.uninstall": "Confirm uninstall?",
|
|
164
|
+
"confirm.unlink": "Confirm remove link?",
|
|
165
|
+
"confirm.core": "\u26A0\uFE0F Remove core package?",
|
|
166
|
+
"detail.id": "Listing id",
|
|
167
|
+
"detail.source": "Source",
|
|
168
|
+
"detail.latest": "Latest",
|
|
169
|
+
"detail.installed": "Installed",
|
|
170
|
+
"detail.tags": "Tags",
|
|
171
|
+
"detail.pkg": "Package",
|
|
172
|
+
"detail.spec": "Spec",
|
|
173
|
+
"detail.listed": "Listed",
|
|
174
|
+
"detail.listed.no": "Not in the registry",
|
|
175
|
+
"detail.path": "Path",
|
|
176
|
+
"detail.note": "Note",
|
|
177
|
+
"manage.hint": "Installed \u2014 manage it on the Installed tab",
|
|
178
|
+
"version.failed": "version lookup failed",
|
|
179
|
+
"src.npm": "npm",
|
|
180
|
+
"src.github": "github",
|
|
181
|
+
"src.link": "local link",
|
|
182
|
+
"src.file": "local file",
|
|
183
|
+
"src.unknown": "unknown",
|
|
184
|
+
"sub.latest": "Latest v{v}",
|
|
185
|
+
"sub.head": "HEAD {sha}",
|
|
186
|
+
"sub.installed": "Installed v{v}",
|
|
187
|
+
"settings.registry": "Registry",
|
|
188
|
+
"settings.source": "Source",
|
|
189
|
+
"settings.updated": "Updated",
|
|
190
|
+
"settings.count": "Listings",
|
|
191
|
+
"settings.count.v": "{n} listings",
|
|
192
|
+
"settings.policy": "Caching",
|
|
193
|
+
"settings.policy.v": "60 min TTL; override via registryUrl",
|
|
194
|
+
"settings.remotehint": "Remote notice",
|
|
195
|
+
"settings.force": "Force refresh",
|
|
196
|
+
"settings.self": "dsh-m itself",
|
|
197
|
+
"settings.current": "Current version",
|
|
198
|
+
"settings.npmlatest": "npm latest",
|
|
199
|
+
"settings.lookupfailed": "lookup failed: {err}",
|
|
200
|
+
"settings.upgradeself": "Upgrade dsh-m",
|
|
201
|
+
"settings.upgradehint": "A restart is required after upgrading",
|
|
202
|
+
"settings.about": "About",
|
|
203
|
+
"settings.about.text": "DSH Marketplace (dsh-m) \u2014 your personal DeepSeek Harness plugin marketplace. Browse, install, uninstall and upgrade, all local.",
|
|
204
|
+
"src.override": "Custom source",
|
|
205
|
+
"src.jsdelivr": "jsDelivr (@main)",
|
|
206
|
+
"src.raw": "raw.githubusercontent (@main)",
|
|
207
|
+
"src.cache": "Local cache",
|
|
208
|
+
"src.bundled": "Bundled snapshot (fallback)",
|
|
209
|
+
"self.upgraded": "dsh-m updated to v{v} \u2014 restart to take effect",
|
|
210
|
+
"self.failed": "Self-update failed: {err}",
|
|
211
|
+
"registry.refreshed": "Registry force-refreshed",
|
|
212
|
+
"notify.installed": "Installed {pkg}{version}",
|
|
213
|
+
"notify.allowbuilds": " (note: this plugin ran build scripts, allowed by policy)",
|
|
214
|
+
"notify.uninstalled": "Uninstalled {pkg}",
|
|
215
|
+
"notify.livedisabled": " (live UI disabled first)",
|
|
216
|
+
"notify.leftovers": "; possible leftover data: {paths}",
|
|
217
|
+
"notify.upgraded": "Upgraded {pkg} ({from} \u2192 {to})",
|
|
218
|
+
"notify.upgradehint": " (note: this plugin ran build scripts)",
|
|
219
|
+
"failed.install": "Install failed: {err}",
|
|
220
|
+
"failed.uninstall": "Uninstall failed: {err}",
|
|
221
|
+
"failed.upgrade": "Upgrade failed: {err}",
|
|
222
|
+
"failed.selfupdate": "Self-update failed: {err}",
|
|
223
|
+
"failed.load": "Load failed: {err}",
|
|
224
|
+
"failed.read": "Read failed: {err}",
|
|
225
|
+
"failed.open": "Failed to open the marketplace panel:",
|
|
226
|
+
"banner.done": "Changes applied. Restart DSH Web to take effect.",
|
|
227
|
+
"restart.doing": "Requesting restart\u2026",
|
|
228
|
+
"restart.waiting": "Restart requested, waiting for DSH Web\u2026",
|
|
229
|
+
"restart.now": "\u26A1 Restart",
|
|
230
|
+
"restart.failed": "Restart failed: {err}",
|
|
231
|
+
"restart.timeout": "Restart timed out \u2014 check the dsh web service manually",
|
|
232
|
+
"restart.hint.done": "Restart requested (via {via}). The service will be back in seconds; ask the user to refresh afterwards.",
|
|
233
|
+
"phase.resolving": "Resolving",
|
|
234
|
+
"phase.downloading": "Downloading",
|
|
235
|
+
"phase.linking": "Linking",
|
|
236
|
+
"phase.building": "Building",
|
|
237
|
+
"phase.ready": "Preparing",
|
|
238
|
+
"readme.show": "\u{1F4D6} README",
|
|
239
|
+
"readme.hide": "Hide README",
|
|
240
|
+
"readme.loading": "Loading README\u2026 ",
|
|
241
|
+
"readme.none": "(No README)",
|
|
242
|
+
"readme.truncated": "\n\n\u2026(truncated at 64KB \u2014 see the plugin directory for full content)",
|
|
243
|
+
"warn.unlink": "Uninstalling only removes the profile's reference to the local directory ({path}); the directory itself is kept.",
|
|
244
|
+
"warn.core": "This is a core/archive package installed via file:. Uninstalling may affect DSH features and requires manual restore.",
|
|
245
|
+
"profile.hint": "web profile: {path}",
|
|
246
|
+
"title.panel": "Plugin Marketplace",
|
|
247
|
+
"title.full": "DeepSeek Harness Plugin Marketplace"
|
|
248
|
+
};
|
|
249
|
+
function browserLang() {
|
|
250
|
+
const lang = typeof document !== "undefined" && document.documentElement.lang || typeof navigator !== "undefined" && navigator.language || "zh";
|
|
251
|
+
return /^en\b/i.test(String(lang)) ? "en" : "zh";
|
|
252
|
+
}
|
|
253
|
+
function interpolate(tpl, params) {
|
|
254
|
+
if (!params) return String(tpl);
|
|
255
|
+
return String(tpl).replace(/\{(\w+)\}/g, (_, k) => params[k] != null ? String(params[k]) : `{${k}}`);
|
|
256
|
+
}
|
|
257
|
+
function lookup(key, params) {
|
|
258
|
+
const dict = browserLang() === "en" ? EN : ZH;
|
|
259
|
+
return interpolate(dict[key] ?? ZH[key] ?? key, params);
|
|
260
|
+
}
|
|
261
|
+
var CATEGORIES = ["market", "tools", "ui", "search", "media", "other"];
|
|
262
|
+
var CSS = `
|
|
263
|
+
.dshm-overlay{position:fixed;inset:0;z-index:2147483000;background:var(--dsw-alias-bg-mask-3,rgba(15,23,42,.48));display:flex;align-items:center;justify-content:center;padding:24px 16px;box-sizing:border-box}
|
|
264
|
+
.dshm-panel{width:min(920px,100%);height:min(680px,86vh);display:flex;flex-direction:column;background:var(--dsw-alias-bg-overlay,var(--dsw-alias-bg-layer-3,#fff));border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:14px;box-shadow:0 18px 48px rgba(2,6,23,.25);overflow:hidden;font-family:inherit;color:var(--dsw-alias-label-primary,inherit)}
|
|
265
|
+
.dshm-head{display:flex;align-items:center;gap:8px;padding:10px 14px;border-bottom:1px solid var(--dsw-alias-border-l2,#e5e7eb)}
|
|
266
|
+
.dshm-title{font-weight:700;font-size:15px;margin-right:6px}
|
|
267
|
+
.dshm-seg{display:inline-flex;align-items:center;gap:2px;padding:2px;border:1px solid var(--dsw-alias-border-l2,#e2e4e8);border-radius:9px;background:var(--dsw-alias-bg-layer-1,#f5f6f8)}
|
|
268
|
+
.dshm-seg button{appearance:none;border:0;background:transparent;height:28px;padding:0 14px;border-radius:7px;font:inherit;font-size:12px;color:var(--dsw-alias-label-tertiary,#7b8088);cursor:pointer;display:inline-flex;align-items:center;gap:6px;transition:background .15s,color .15s,box-shadow .15s}
|
|
269
|
+
.dshm-seg button:hover{color:var(--dsw-alias-label-secondary,#4b5058)}
|
|
270
|
+
.dshm-seg button.on{background:var(--dsw-alias-bg-layer-3,#fff);color:var(--dsw-alias-label-primary,#17191c);font-weight:600;box-shadow:var(--dsw-shadow-lv1,0 2px 8px rgb(20 24 32 / 8%))}
|
|
271
|
+
.dshm-seg .dshm-count{font-size:11px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-caption,#9ca3af);margin:0}
|
|
272
|
+
.dshm-seg button.on .dshm-count{color:var(--dsw-alias-state-business-primary,#4d6bfe)}
|
|
273
|
+
.dshm-spacer{flex:1}
|
|
274
|
+
.dshm-body{flex:1;overflow:auto;padding:14px;display:flex;flex-direction:column;gap:12px}
|
|
275
|
+
.dshm-hint{color:var(--dsw-alias-label-caption,#6b7280);font-size:12px;line-height:18px;margin:0}
|
|
276
|
+
.dshm-err{color:var(--dsw-alias-state-error-primary,#b91c1c);font-size:12px;line-height:18px}
|
|
277
|
+
.dshm-btn{border:1px solid var(--dsw-alias-border-l2,#e5e7eb);background:var(--dsw-alias-bg-layer-3,#fff);color:var(--dsw-alias-label-primary,inherit);border-radius:8px;padding:5px 12px;font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}
|
|
278
|
+
.dshm-btn:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(38,49,72,.06))}
|
|
279
|
+
.dshm-btn:disabled{opacity:.5;cursor:default}
|
|
280
|
+
.dshm-btn.primary{background:var(--dsw-alias-interactive-bg-selected,#4f46e5);border-color:var(--dsw-alias-interactive-bg-selected,#4f46e5);color:#fff}
|
|
281
|
+
.dshm-btn.primary:hover{filter:brightness(1.08)}
|
|
282
|
+
.dshm-btn.danger{color:var(--dsw-alias-state-error-primary,#b91c1c);border-color:var(--dsw-alias-state-error-primary,#b91c1c)}
|
|
283
|
+
.dshm-btn.sm{padding:3px 9px;font-size:11px}
|
|
284
|
+
.dshm-input{flex:1;min-width:120px;border:1px solid var(--dsw-alias-border-l2,#c7d2fe);background:var(--dsw-alias-bg-layer-2,transparent);color:var(--dsw-alias-label-primary,inherit);border-radius:8px;padding:6px 10px;font:inherit;font-size:13px;outline:none}
|
|
285
|
+
.dshm-input:focus{border-color:var(--dsw-alias-interactive-bg-selected,#4f46e5)}
|
|
286
|
+
.dshm-chips{display:flex;flex-wrap:wrap;gap:6px}
|
|
287
|
+
.dshm-chip{border:1px solid var(--dsw-alias-border-l2,#e5e7eb);background:transparent;color:var(--dsw-alias-label-secondary,#4b5563);border-radius:999px;padding:2px 10px;font:inherit;font-size:11px;cursor:pointer}
|
|
288
|
+
.dshm-chip:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(38,49,72,.06))}
|
|
289
|
+
.dshm-chip.on{background:var(--dsw-specific-sidebar-nav-item-active,rgba(38,49,72,.08));border-color:transparent;color:var(--dsw-alias-label-primary,inherit);font-weight:500}
|
|
290
|
+
.dshm-cards{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
|
|
291
|
+
@media (max-width:680px){.dshm-cards{grid-template-columns:1fr}}
|
|
292
|
+
.dshm-card{display:flex;gap:12px;align-items:flex-start;background:var(--dsw-alias-bg-layer-2,rgba(38,49,72,.04));border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:12px;padding:12px;cursor:pointer;text-align:left;width:100%;box-sizing:border-box;min-width:0;font:inherit;color:var(--dsw-alias-label-primary,inherit);transition:border-color .16s,background .16s}
|
|
293
|
+
.dshm-card:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(38,49,72,.06));border-color:var(--dsw-alias-label-dimmed,#c7d2fe)}
|
|
294
|
+
.dshm-icon{width:40px;height:40px;border-radius:10px;object-fit:cover;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);flex-shrink:0;background:linear-gradient(135deg,#c7d2fe,#fbcfe8);display:grid;place-items:center;font-weight:700;font-size:16px;color:#374151}
|
|
295
|
+
.dshm-meta{min-width:0;flex:1;display:flex;flex-direction:column;gap:2px}
|
|
296
|
+
.dshm-top{display:flex;align-items:center;gap:8px;min-width:0}
|
|
297
|
+
.dshm-name{flex:1;min-width:0;font-weight:600;font-size:14px;line-height:20px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
298
|
+
.dshm-badge{flex:none;font-size:11px;line-height:16px;padding:0 6px;border-radius:999px;background:var(--dsw-alias-state-success-tertiary,#ecfdf5);color:var(--dsw-alias-state-success-primary,#047857)}
|
|
299
|
+
.dshm-badge.warn{background:var(--dsw-alias-state-warn-tertiary,#fffbeb);color:var(--dsw-alias-state-warn-primary,#b45309)}
|
|
300
|
+
.dshm-badge.info{background:var(--dsw-alias-state-business-tertiary,#eef2ff);color:var(--dsw-alias-state-business-primary,#4338ca)}
|
|
301
|
+
.dshm-badge.err{background:var(--dsw-alias-state-error-secondary,#fee2e2);color:var(--dsw-alias-state-error-primary,#b91c1c)}
|
|
302
|
+
.dshm-desc{color:var(--dsw-alias-label-tertiary,#6b7280);font-size:12px;line-height:18px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
|
|
303
|
+
.dshm-sub{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--dsw-alias-label-caption,#6b7280)}
|
|
304
|
+
.dshm-detail{margin-top:8px;border-top:1px dashed var(--dsw-alias-border-l2,#e5e7eb);padding-top:8px;display:flex;flex-direction:column;gap:6px;font-size:12px;color:var(--dsw-alias-label-secondary,#4b5563)}
|
|
305
|
+
.dshm-actions{display:flex;gap:6px;flex-wrap:wrap;margin-top:4px}
|
|
306
|
+
.dshm-banner{display:flex;align-items:center;gap:10px;padding:10px 14px;border-top:1px solid var(--dsw-alias-border-l2,#e5e7eb);background:var(--dsw-alias-state-warn-tertiary,#fffbeb);color:var(--dsw-alias-state-warn-primary,#b45309);font-size:12px}
|
|
307
|
+
.dshm-banner .dshm-banner-text{flex:1}
|
|
308
|
+
.dshm-row{display:flex;align-items:center;gap:8px}
|
|
309
|
+
.dshm-kv{display:grid;grid-template-columns:110px 1fr;gap:4px 10px;font-size:12px}
|
|
310
|
+
.dshm-kv .k{color:var(--dsw-alias-label-caption,#6b7280)}
|
|
311
|
+
.dshm-spin{display:inline-block;width:12px;height:12px;border:2px solid var(--dsw-alias-border-l2,#c7d2fe);border-top-color:var(--dsw-alias-interactive-bg-selected,#4f46e5);border-radius:50%;animation:dshm-rot .8s linear infinite;vertical-align:-2px}
|
|
312
|
+
@keyframes dshm-rot{to{transform:rotate(360deg)}}
|
|
313
|
+
.dshm-others{display:flex;align-items:center;gap:8px;padding:10px 12px;border:1px dashed var(--dsw-alias-border-l2,#e2e4e8);border-radius:10px;color:var(--dsw-alias-label-caption,#9ca3af);font-size:12px;line-height:18px}
|
|
314
|
+
.dshm-readme{max-height:240px;overflow:auto;white-space:pre-wrap;word-break:break-word;background:var(--dsw-alias-bg-layer-2,rgba(38,49,72,.04));border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:8px;padding:10px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#4b5563);margin:0;font-family:ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
315
|
+
.dshm-prog{display:flex;align-items:center;gap:8px;padding:8px 10px;border:1px solid var(--dsw-alias-border-l2,#e5e7eb);border-radius:8px;font-size:12px;color:var(--dsw-alias-label-secondary,#4b5563)}
|
|
316
|
+
.dshm-prog .bar{flex:1;height:6px;border-radius:3px;background:var(--dsw-alias-bg-layer-2,rgba(38,49,72,.08));overflow:hidden;min-width:80px}
|
|
317
|
+
.dshm-prog .bar i{display:block;height:100%;background:var(--dsw-alias-interactive-bg-selected,#4f46e5);transition:width .3s}
|
|
318
|
+
.dshm-entry{box-sizing:border-box;display:flex;align-items:center;gap:8px;width:calc(100% + 4px);height:42px;margin:4px -2px;padding:0 10px 0 8px;border:0;border-radius:12px;background:transparent;color:var(--dsw-alias-label-primary,inherit);font:inherit;font-size:14px;line-height:22px;cursor:pointer;overflow:hidden}
|
|
319
|
+
.dshm-entry:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(38,49,72,.06))}
|
|
320
|
+
.dshm-entry svg{flex:none;width:16px;height:16px}
|
|
321
|
+
.dshm-entry span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
322
|
+
[data-slot="sidebar.footer.action"]{display:flex!important;flex-direction:column;width:100%;min-width:0}
|
|
323
|
+
[data-slot="sidebar.footer.action"]>*{flex:none;min-width:0}
|
|
324
|
+
.dshm-empty{text-align:center;color:var(--dsw-alias-label-caption,#6b7280);font-size:13px;padding:32px 0}
|
|
325
|
+
`;
|
|
326
|
+
function ensureCss() {
|
|
327
|
+
if (typeof document === "undefined" || document.getElementById("dshm-css")) return;
|
|
328
|
+
const el = document.createElement("style");
|
|
329
|
+
el.id = "dshm-css";
|
|
330
|
+
el.textContent = CSS;
|
|
331
|
+
document.head.appendChild(el);
|
|
332
|
+
}
|
|
333
|
+
async function api(method, params) {
|
|
334
|
+
const res = await fetch(API, {
|
|
335
|
+
method: "POST",
|
|
336
|
+
headers: { "content-type": "application/json" },
|
|
337
|
+
body: JSON.stringify({ method, ...params || {} })
|
|
338
|
+
});
|
|
339
|
+
const data = await res.json().catch(() => ({}));
|
|
340
|
+
if (!res.ok || data.ok === false) throw new Error(data.error || `API ${res.status}`);
|
|
341
|
+
return data;
|
|
342
|
+
}
|
|
343
|
+
function fmtDate(iso) {
|
|
344
|
+
if (!iso) return "\u2014";
|
|
345
|
+
const d = new Date(iso);
|
|
346
|
+
return Number.isFinite(d.getTime()) ? d.toLocaleString("zh-CN", { hour12: false }) : "\u2014";
|
|
347
|
+
}
|
|
348
|
+
function useAsync(fn, deps) {
|
|
349
|
+
const [state, setState] = useState({ loading: true, data: null, error: null });
|
|
350
|
+
const run = useCallback((force) => {
|
|
351
|
+
setState((s) => ({ ...s, loading: true, error: null }));
|
|
352
|
+
return fn(force).then((data) => setState({ loading: false, data, error: null })).catch((err) => setState({ loading: false, data: null, error: String(err && err.message || err) }));
|
|
353
|
+
}, deps);
|
|
354
|
+
useEffect(() => {
|
|
355
|
+
run(false);
|
|
356
|
+
}, [run]);
|
|
357
|
+
return { ...state, reload: run };
|
|
358
|
+
}
|
|
359
|
+
function Icon({ entry }) {
|
|
360
|
+
const [broken, setBroken] = useState(false);
|
|
361
|
+
const letter = String(entry.name || entry.id || "?").charAt(0).toUpperCase();
|
|
362
|
+
const url = entry.icon || (entry.github ? `https://github.com/${entry.github.split("/")[0]}.png?size=64` : null);
|
|
363
|
+
if (!url || broken) {
|
|
364
|
+
return h("div", { className: "dshm-icon", "aria-hidden": "true" }, letter);
|
|
365
|
+
}
|
|
366
|
+
return h("img", {
|
|
367
|
+
className: "dshm-icon",
|
|
368
|
+
src: url,
|
|
369
|
+
alt: "",
|
|
370
|
+
onError: () => setBroken(true),
|
|
371
|
+
referrerPolicy: "no-referrer"
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
function Spin() {
|
|
375
|
+
return h("span", { className: "dshm-spin" });
|
|
376
|
+
}
|
|
377
|
+
function TwoStepButton({ label, confirmLabel, className, onConfirm, disabled }) {
|
|
378
|
+
const [arm, setArm] = useState(false);
|
|
379
|
+
useEffect(() => {
|
|
380
|
+
if (!arm) return;
|
|
381
|
+
const t = setTimeout(() => setArm(false), 4e3);
|
|
382
|
+
return () => clearTimeout(t);
|
|
383
|
+
}, [arm]);
|
|
384
|
+
return h(
|
|
385
|
+
"button",
|
|
386
|
+
{
|
|
387
|
+
className: `${className || "dshm-btn"} ${arm ? "danger" : ""}`.trim(),
|
|
388
|
+
disabled,
|
|
389
|
+
onClick: (e) => {
|
|
390
|
+
e.stopPropagation();
|
|
391
|
+
if (!arm) {
|
|
392
|
+
setArm(true);
|
|
393
|
+
} else {
|
|
394
|
+
setArm(false);
|
|
395
|
+
onConfirm();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
arm ? confirmLabel : label
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
function RestartBanner({ note, onDone }) {
|
|
403
|
+
const [phase, setPhase] = useState("idle");
|
|
404
|
+
const [err, setErr] = useState(null);
|
|
405
|
+
const restart = useCallback(async () => {
|
|
406
|
+
setErr(null);
|
|
407
|
+
setPhase("restarting");
|
|
408
|
+
try {
|
|
409
|
+
const ping0 = await api("ping");
|
|
410
|
+
await api("restart");
|
|
411
|
+
setPhase("waiting");
|
|
412
|
+
const deadline = Date.now() + 9e4;
|
|
413
|
+
for (; ; ) {
|
|
414
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
415
|
+
if (Date.now() > deadline) throw new Error(lookup("restart.timeout"));
|
|
416
|
+
try {
|
|
417
|
+
const ping = await api("ping");
|
|
418
|
+
if (ping.boot !== ping0.boot) break;
|
|
419
|
+
} catch {
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
setPhase("idle");
|
|
423
|
+
onDone(true);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
setPhase("idle");
|
|
426
|
+
setErr(String(e && e.message || e));
|
|
427
|
+
}
|
|
428
|
+
}, [onDone]);
|
|
429
|
+
return h(
|
|
430
|
+
"div",
|
|
431
|
+
{ className: "dshm-banner" },
|
|
432
|
+
h(
|
|
433
|
+
"span",
|
|
434
|
+
{ className: "dshm-banner-text" },
|
|
435
|
+
phase === "restarting" ? lookup("restart.doing") : phase === "waiting" ? lookup("restart.waiting") : err ? lookup("restart.failed", { err }) : note || lookup("banner.done")
|
|
436
|
+
),
|
|
437
|
+
phase === "idle" && !err ? h("button", { className: "dshm-btn primary sm", onClick: restart }, lookup("restart.now")) : null,
|
|
438
|
+
phase === "restarting" || phase === "waiting" ? Spin() : null,
|
|
439
|
+
phase === "idle" && err ? h("button", { className: "dshm-btn sm", onClick: () => onDone(false) }, lookup("common.ok")) : null,
|
|
440
|
+
phase === "idle" && !err ? h("button", { className: "dshm-btn sm", onClick: () => onDone(false) }, lookup("common.later")) : null
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
function MarketTab({ notify, onCount }) {
|
|
444
|
+
const { loading, data, error, reload } = useAsync((force) => api("market", force ? { force: true } : {}), []);
|
|
445
|
+
const [q, setQ] = useState("");
|
|
446
|
+
const [cat, setCat] = useState(null);
|
|
447
|
+
const [openId, setOpenId] = useState(null);
|
|
448
|
+
const [busyId, setBusyId] = useState(null);
|
|
449
|
+
const items = useMemo(() => {
|
|
450
|
+
const list = data && data.items || [];
|
|
451
|
+
const kw = q.trim().toLowerCase();
|
|
452
|
+
return list.filter((it) => {
|
|
453
|
+
if (cat && it.category !== cat) return false;
|
|
454
|
+
if (!kw) return true;
|
|
455
|
+
const hay = `${it.id} ${it.name} ${it.description} ${(it.tags || []).join(" ")}`.toLowerCase();
|
|
456
|
+
return hay.includes(kw);
|
|
457
|
+
});
|
|
458
|
+
}, [data, q, cat]);
|
|
459
|
+
const doInstall = async (it, version) => {
|
|
460
|
+
setBusyId(it.id);
|
|
461
|
+
try {
|
|
462
|
+
const res = await api("install", { id: it.id, ...version ? { version } : {} });
|
|
463
|
+
notify({
|
|
464
|
+
kind: "ok",
|
|
465
|
+
text: lookup("notify.installed", { pkg: res.pkg, version: res.version ? ` v${res.version}` : "" }) + (res.usedAllowAllBuilds ? lookup("notify.allowbuilds") : "")
|
|
466
|
+
});
|
|
467
|
+
await reload(false);
|
|
468
|
+
} catch (e) {
|
|
469
|
+
notify({ kind: "err", text: lookup("failed.install", { err: e && e.message || e }) });
|
|
470
|
+
} finally {
|
|
471
|
+
setBusyId(null);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
return h(
|
|
475
|
+
React.Fragment,
|
|
476
|
+
null,
|
|
477
|
+
h(
|
|
478
|
+
"div",
|
|
479
|
+
{ className: "dshm-row" },
|
|
480
|
+
h("input", {
|
|
481
|
+
className: "dshm-input",
|
|
482
|
+
placeholder: lookup("search.ph"),
|
|
483
|
+
value: q,
|
|
484
|
+
onChange: (e) => setQ(e.target.value)
|
|
485
|
+
}),
|
|
486
|
+
h("button", { className: "dshm-btn", onClick: () => reload(true), title: lookup("settings.policy.v") }, loading ? Spin() : `\u21BB ${lookup("common.refresh")}`)
|
|
487
|
+
),
|
|
488
|
+
h(
|
|
489
|
+
"div",
|
|
490
|
+
{ className: "dshm-chips" },
|
|
491
|
+
h("button", { className: `dshm-chip${cat === null ? " on" : ""}`, onClick: () => setCat(null) }, lookup("cat.all")),
|
|
492
|
+
CATEGORIES.map((key) => {
|
|
493
|
+
const n = (data && data.items || []).filter((it) => it.category === key).length;
|
|
494
|
+
return h(
|
|
495
|
+
"button",
|
|
496
|
+
{ key, className: `dshm-chip${cat === key ? " on" : ""}`, onClick: () => setCat(cat === key ? null : key) },
|
|
497
|
+
`${lookup("cat." + key)}${n ? ` ${n}` : ""}`
|
|
498
|
+
);
|
|
499
|
+
})
|
|
500
|
+
),
|
|
501
|
+
busyId ? h(ProgressLine, { key: "prog" }) : null,
|
|
502
|
+
loading && !data ? h("div", { className: "dshm-empty" }, lookup("market.loading"), Spin()) : error ? h("div", { className: "dshm-err" }, lookup("failed.load", { err: error })) : items.length === 0 ? h("div", { className: "dshm-empty" }, lookup("market.empty")) : h(
|
|
503
|
+
"div",
|
|
504
|
+
{ className: "dshm-cards" },
|
|
505
|
+
items.map((it) => Card({
|
|
506
|
+
key: it.id,
|
|
507
|
+
icon: h(Icon, { entry: it }),
|
|
508
|
+
name: it.name,
|
|
509
|
+
badges: [
|
|
510
|
+
it.outdated ? h("span", { className: "dshm-badge warn", key: "u" }, lookup("badge.update")) : null,
|
|
511
|
+
it.installed ? h("span", { className: "dshm-badge", key: "i" }, lookup("badge.installed")) : null,
|
|
512
|
+
h("span", { className: "dshm-badge info", key: "s" }, it.source === "npm" ? "npm" : "github")
|
|
513
|
+
],
|
|
514
|
+
desc: it.description,
|
|
515
|
+
sub: [
|
|
516
|
+
it.latestVersion ? lookup("sub.latest", { v: it.latestVersion }) : it.latestTag ? it.latestTag : it.latestSha ? lookup("sub.head", { sha: it.latestSha.slice(0, 7) }) : null,
|
|
517
|
+
it.installedVersion ? lookup("sub.installed", { v: it.installedVersion }) : null,
|
|
518
|
+
it.latestError ? lookup("version.failed") : null
|
|
519
|
+
].filter(Boolean).join(" \xB7 "),
|
|
520
|
+
open: openId === it.id,
|
|
521
|
+
onToggle: () => setOpenId(openId === it.id ? null : it.id),
|
|
522
|
+
detail: DetailRows([
|
|
523
|
+
[lookup("detail.id"), it.id],
|
|
524
|
+
[lookup("detail.source"), it.source === "npm" ? `npm \xB7 ${it.npm}` : `GitHub \xB7 ${it.github}`],
|
|
525
|
+
[lookup("detail.latest"), it.latestVersion ? `v${it.latestVersion}` : it.latestTag ? it.latestTag : it.latestSha ? it.latestSha : it.latestError || "\u2014"],
|
|
526
|
+
[lookup("detail.installed"), it.installedPkg ? `${it.installedPkg} v${it.installedVersion || "?"}` : lookup("installed.none")],
|
|
527
|
+
[lookup("detail.tags"), (it.tags || []).join(", ") || "\u2014"],
|
|
528
|
+
it.latestError ? [lookup("version.failed"), it.latestError] : null
|
|
529
|
+
]),
|
|
530
|
+
actions: [
|
|
531
|
+
it.installed ? h("span", { className: "dshm-hint", key: "hint" }, lookup("manage.hint")) : h(
|
|
532
|
+
"button",
|
|
533
|
+
{
|
|
534
|
+
key: "install",
|
|
535
|
+
className: "dshm-btn primary sm",
|
|
536
|
+
disabled: busyId === it.id,
|
|
537
|
+
onClick: (e) => {
|
|
538
|
+
e.stopPropagation();
|
|
539
|
+
doInstall(it);
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
busyId === it.id ? h(Spin) : lookup("action.install")
|
|
543
|
+
)
|
|
544
|
+
]
|
|
545
|
+
}))
|
|
546
|
+
)
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
var PHASE_LABEL = { resolving: "phase.resolving", downloading: "phase.downloading", linking: "phase.linking", building: "phase.building" };
|
|
550
|
+
function ProgressLine() {
|
|
551
|
+
const [st, setSt] = useState(null);
|
|
552
|
+
useEffect(() => {
|
|
553
|
+
let live = true;
|
|
554
|
+
const tick = async () => {
|
|
555
|
+
try {
|
|
556
|
+
const d = await api("status");
|
|
557
|
+
if (live) setSt(d);
|
|
558
|
+
} catch {
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
tick();
|
|
562
|
+
const iv = setInterval(tick, 1e3);
|
|
563
|
+
return () => {
|
|
564
|
+
live = false;
|
|
565
|
+
clearInterval(iv);
|
|
566
|
+
};
|
|
567
|
+
}, []);
|
|
568
|
+
if (!st) return null;
|
|
569
|
+
const pct = st.total ? Math.min(100, Math.round(st.done / st.total * 100)) : null;
|
|
570
|
+
const phaseLabel = lookup(PHASE_LABEL[st.phase] || "phase.ready");
|
|
571
|
+
return h(
|
|
572
|
+
"div",
|
|
573
|
+
{ className: "dshm-prog" },
|
|
574
|
+
Spin(),
|
|
575
|
+
h("span", null, `${st.target} \xB7 ${phaseLabel}${st.done ? ` ${st.done}${st.total ? "/" + st.total : ""}` : ""}`),
|
|
576
|
+
pct !== null ? h("span", { className: "bar" }, h("i", { style: { width: pct + "%" } })) : null,
|
|
577
|
+
st.currentPackage ? h("span", { className: "dshm-hint" }, String(st.currentPackage).slice(0, 44)) : null
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
function ReadmeBlock({ pkg }) {
|
|
581
|
+
const [state, setState] = useState({ loading: true, text: "", err: "", truncated: false });
|
|
582
|
+
useEffect(() => {
|
|
583
|
+
let live = true;
|
|
584
|
+
api("readme", { pkg }).then((d) => live && setState({ loading: false, text: d.readme, err: "", truncated: d.truncated })).catch((e) => live && setState({ loading: false, text: "", err: String(e && e.message || e) }));
|
|
585
|
+
return () => {
|
|
586
|
+
live = false;
|
|
587
|
+
};
|
|
588
|
+
}, [pkg]);
|
|
589
|
+
if (state.loading) return h("div", { className: "dshm-hint" }, "\u52A0\u8F7D README\u2026 ", Spin());
|
|
590
|
+
if (state.err) return h("div", { className: "dshm-err" }, state.err);
|
|
591
|
+
if (!state.text) return h("div", { className: "dshm-hint" }, "\uFF08\u8BE5\u63D2\u4EF6\u6CA1\u6709 README\uFF09");
|
|
592
|
+
return h("pre", { className: "dshm-readme" }, state.text + (state.truncated ? "\n\n\u2026\uFF08\u8D85\u8FC7 64KB \u5DF2\u622A\u65AD\uFF0C\u5B8C\u6574\u5185\u5BB9\u89C1\u63D2\u4EF6\u76EE\u5F55\uFF09" : ""));
|
|
593
|
+
}
|
|
594
|
+
function uninstallGuard(it) {
|
|
595
|
+
if (it.source === "link") {
|
|
596
|
+
return {
|
|
597
|
+
confirm: lookup("confirm.unlink"),
|
|
598
|
+
warn: lookup("warn.unlink", { path: it.path })
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
if (it.source === "file") {
|
|
602
|
+
return { confirm: lookup("confirm.core"), warn: lookup("warn.core") };
|
|
603
|
+
}
|
|
604
|
+
return { confirm: lookup("confirm.uninstall"), warn: null };
|
|
605
|
+
}
|
|
606
|
+
function InstalledTab({ notify, installed }) {
|
|
607
|
+
const { loading, data, error, reload } = installed;
|
|
608
|
+
const [openPkg, setOpenPkg] = useState(null);
|
|
609
|
+
const [readmePkg, setReadmePkg] = useState(null);
|
|
610
|
+
const [busyPkg, setBusyPkg] = useState(null);
|
|
611
|
+
const doUninstall = async (it) => {
|
|
612
|
+
setBusyPkg(it.pkg);
|
|
613
|
+
try {
|
|
614
|
+
const res = await api("uninstall", { pkg: it.pkg });
|
|
615
|
+
notify({
|
|
616
|
+
kind: "ok",
|
|
617
|
+
text: lookup("notify.uninstalled", { pkg: res.pkg }) + (res.liveDisabled ? lookup("notify.livedisabled") : "") + (res.leftovers && res.leftovers.length ? lookup("notify.leftovers", { paths: res.leftovers.join(", ") }) : "")
|
|
618
|
+
});
|
|
619
|
+
await reload();
|
|
620
|
+
} catch (e) {
|
|
621
|
+
notify({ kind: "err", text: lookup("failed.uninstall", { err: e && e.message || e }) });
|
|
622
|
+
} finally {
|
|
623
|
+
setBusyPkg(null);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
const doUpgrade = async (it) => {
|
|
627
|
+
setBusyPkg(it.pkg);
|
|
628
|
+
try {
|
|
629
|
+
const res = await api("upgrade", { pkg: it.pkg });
|
|
630
|
+
notify({
|
|
631
|
+
kind: "ok",
|
|
632
|
+
text: lookup("notify.upgraded", {
|
|
633
|
+
pkg: res.pkg,
|
|
634
|
+
from: res.fromVersion ? `v${res.fromVersion}` : "\u2014",
|
|
635
|
+
to: res.version ? `v${res.version}` : res.sha ? res.sha.slice(0, 7) : "latest"
|
|
636
|
+
}) + (res.usedAllowAllBuilds ? lookup("notify.upgradehint") : "")
|
|
637
|
+
});
|
|
638
|
+
await reload();
|
|
639
|
+
} catch (e) {
|
|
640
|
+
notify({ kind: "err", text: lookup("failed.upgrade", { err: e && e.message || e }) });
|
|
641
|
+
} finally {
|
|
642
|
+
setBusyPkg(null);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
if (loading && !data) return h("div", { className: "dshm-empty" }, lookup("installed.loading"), Spin());
|
|
646
|
+
if (error) return h("div", { className: "dshm-err" }, lookup("failed.read", { err: error }));
|
|
647
|
+
const items = data && data.items || [];
|
|
648
|
+
if (!items.length) return h("div", { className: "dshm-empty" }, `${lookup("installed.empty")} (${data.profileDir})`);
|
|
649
|
+
return h(
|
|
650
|
+
React.Fragment,
|
|
651
|
+
null,
|
|
652
|
+
h("div", { className: "dshm-hint" }, lookup("profile.hint", { path: data.profileDir })),
|
|
653
|
+
data.others > 0 ? h("div", { className: "dshm-others" }, lookup("installed.others", { n: data.others })) : null,
|
|
654
|
+
busyPkg ? h(ProgressLine, { key: "prog" }) : null,
|
|
655
|
+
h(
|
|
656
|
+
"div",
|
|
657
|
+
{ className: "dshm-cards" },
|
|
658
|
+
items.map((it) => {
|
|
659
|
+
const guard = uninstallGuard(it);
|
|
660
|
+
return Card({
|
|
661
|
+
key: it.pkg,
|
|
662
|
+
icon: h(Icon, { entry: { name: it.name, github: it.registryGithub || it.githubRepo || (it.spec.startsWith("github:") ? it.spec.slice(7).split("#")[0] : null), icon: null } }),
|
|
663
|
+
name: it.name,
|
|
664
|
+
badges: [
|
|
665
|
+
it.outdated ? h("span", { className: "dshm-badge warn", key: "u" }, `\u2B06 ${it.latestTag || (it.latestVersion ? `v${it.latestVersion}` : "")}`.trim()) : null,
|
|
666
|
+
it.registryId ? h("span", { className: "dshm-badge", key: "r" }, lookup("badge.market")) : h("span", { className: "dshm-badge info", key: "r" }, lookup("badge.nonmarket"))
|
|
667
|
+
],
|
|
668
|
+
desc: it.description || "\uFF08\u65E0\u63CF\u8FF0\uFF09",
|
|
669
|
+
sub: [
|
|
670
|
+
`v${it.version || "?"}`,
|
|
671
|
+
{ npm: lookup("src.npm"), github: lookup("src.github"), link: lookup("src.link"), file: lookup("src.file"), unknown: lookup("src.unknown") }[it.source] || it.source
|
|
672
|
+
].join(" \xB7 "),
|
|
673
|
+
open: openPkg === it.pkg,
|
|
674
|
+
onToggle: () => setOpenPkg(openPkg === it.pkg ? null : it.pkg),
|
|
675
|
+
detail: readmePkg === it.pkg ? h(ReadmeBlock, { pkg: it.pkg }) : DetailRows([
|
|
676
|
+
[lookup("detail.pkg"), it.pkg],
|
|
677
|
+
[lookup("detail.spec"), it.spec],
|
|
678
|
+
[lookup("detail.latest"), it.latestTag || (it.latestVersion ? `v${it.latestVersion}` : "\u2014")],
|
|
679
|
+
[lookup("detail.listed"), it.registryId || lookup("detail.listed.no")],
|
|
680
|
+
[lookup("detail.path"), it.path],
|
|
681
|
+
guard.warn ? [lookup("detail.note"), guard.warn] : null
|
|
682
|
+
]),
|
|
683
|
+
actions: [
|
|
684
|
+
h("button", {
|
|
685
|
+
key: "rd",
|
|
686
|
+
className: "dshm-btn sm",
|
|
687
|
+
onClick: (e) => {
|
|
688
|
+
e.stopPropagation();
|
|
689
|
+
setReadmePkg(readmePkg === it.pkg ? null : it.pkg);
|
|
690
|
+
}
|
|
691
|
+
}, readmePkg === it.pkg ? lookup("readme.hide") : lookup("readme.show")),
|
|
692
|
+
it.outdated ? h(
|
|
693
|
+
"button",
|
|
694
|
+
{
|
|
695
|
+
key: "up",
|
|
696
|
+
className: "dshm-btn primary sm",
|
|
697
|
+
disabled: busyPkg === it.pkg,
|
|
698
|
+
onClick: (e) => {
|
|
699
|
+
e.stopPropagation();
|
|
700
|
+
doUpgrade(it);
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
busyPkg === it.pkg ? h(Spin) : lookup("action.upgrade")
|
|
704
|
+
) : null,
|
|
705
|
+
h(TwoStepButton, {
|
|
706
|
+
key: "un",
|
|
707
|
+
label: lookup("action.uninstall"),
|
|
708
|
+
confirmLabel: guard.confirm,
|
|
709
|
+
className: "dshm-btn sm",
|
|
710
|
+
disabled: busyPkg === it.pkg,
|
|
711
|
+
onConfirm: () => doUninstall(it)
|
|
712
|
+
})
|
|
713
|
+
]
|
|
714
|
+
});
|
|
715
|
+
})
|
|
716
|
+
)
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
function SettingsTab({ notify }) {
|
|
720
|
+
const reg = useAsync((force) => api("registry", force ? { force: true } : {}), []);
|
|
721
|
+
const self = useAsync(() => api("self-check"), []);
|
|
722
|
+
const [busy, setBusy] = useState(false);
|
|
723
|
+
const [upgrading, setUpgrading] = useState(false);
|
|
724
|
+
const refresh = async () => {
|
|
725
|
+
setBusy(true);
|
|
726
|
+
try {
|
|
727
|
+
await reg.reload(true);
|
|
728
|
+
notify({ kind: "ok", text: lookup("registry.refreshed") });
|
|
729
|
+
} finally {
|
|
730
|
+
setBusy(false);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
const upgradeSelf = async () => {
|
|
734
|
+
setUpgrading(true);
|
|
735
|
+
try {
|
|
736
|
+
const res = await api("self-upgrade");
|
|
737
|
+
notify({ kind: "ok", text: lookup("self.upgraded", { v: res.version }) });
|
|
738
|
+
await self.reload();
|
|
739
|
+
} catch (e) {
|
|
740
|
+
notify({ kind: "err", text: lookup("failed.selfupdate", { err: e && e.message || e }) });
|
|
741
|
+
} finally {
|
|
742
|
+
setUpgrading(false);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
return h(
|
|
746
|
+
React.Fragment,
|
|
747
|
+
null,
|
|
748
|
+
Section(
|
|
749
|
+
lookup("settings.registry"),
|
|
750
|
+
h(
|
|
751
|
+
"div",
|
|
752
|
+
{ className: "dshm-kv" },
|
|
753
|
+
h("span", { className: "k" }, lookup("settings.source")),
|
|
754
|
+
h("span", null, regSourceLabel(reg.data)),
|
|
755
|
+
h("span", { className: "k" }, lookup("settings.updated")),
|
|
756
|
+
h("span", null, fmtDate(reg.data && reg.data.fetchedAt)),
|
|
757
|
+
h("span", { className: "k" }, lookup("settings.count")),
|
|
758
|
+
h("span", null, reg.data ? lookup("settings.count.v", { n: reg.data.plugins.length }) : "\u2014"),
|
|
759
|
+
h("span", { className: "k" }, lookup("settings.policy")),
|
|
760
|
+
h("span", null, lookup("settings.policy.v"))
|
|
761
|
+
),
|
|
762
|
+
reg.data && reg.data.errors && reg.data.errors.length ? h("div", { className: "dshm-err" }, `${lookup("settings.remotehint")}\uFF1A${reg.data.errors.join("\uFF1B")}`) : null,
|
|
763
|
+
h(
|
|
764
|
+
"div",
|
|
765
|
+
{ className: "dshm-actions" },
|
|
766
|
+
h("button", { className: "dshm-btn sm", disabled: busy || reg.loading, onClick: refresh }, busy || reg.loading ? h(Spin) : lookup("settings.force"))
|
|
767
|
+
)
|
|
768
|
+
),
|
|
769
|
+
Section(
|
|
770
|
+
lookup("settings.self"),
|
|
771
|
+
h(
|
|
772
|
+
"div",
|
|
773
|
+
{ className: "dshm-kv" },
|
|
774
|
+
h("span", { className: "k" }, lookup("settings.current")),
|
|
775
|
+
h("span", null, self.data ? `v${self.data.current}` : "\u2014"),
|
|
776
|
+
h("span", { className: "k" }, lookup("settings.npmlatest")),
|
|
777
|
+
h("span", null, self.data ? self.data.latest ? `v${self.data.latest}` : lookup("settings.lookupfailed", { err: self.data.error || "" }) : "\u2026")
|
|
778
|
+
),
|
|
779
|
+
self.data && self.data.outdated ? h(
|
|
780
|
+
"div",
|
|
781
|
+
{ className: "dshm-actions" },
|
|
782
|
+
h("button", { className: "dshm-btn primary sm", disabled: upgrading, onClick: upgradeSelf }, upgrading ? h(Spin) : lookup("settings.upgradeself")),
|
|
783
|
+
h("span", { className: "dshm-hint" }, lookup("settings.upgradehint"))
|
|
784
|
+
) : null
|
|
785
|
+
),
|
|
786
|
+
Section(
|
|
787
|
+
lookup("settings.about"),
|
|
788
|
+
h("div", { className: "dshm-hint" }, lookup("settings.about.text"))
|
|
789
|
+
)
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
function regSourceLabel(data) {
|
|
793
|
+
if (!data) return "\u2014";
|
|
794
|
+
const map = { override: "src.override", jsdelivr: "src.jsdelivr", raw: "src.raw", cache: "src.cache", bundled: "src.bundled" };
|
|
795
|
+
return lookup(map[data.source] || data.source);
|
|
796
|
+
}
|
|
797
|
+
function Section(title, ...children) {
|
|
798
|
+
return h(
|
|
799
|
+
"div",
|
|
800
|
+
{ style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
801
|
+
h("div", { style: { fontWeight: 600, fontSize: "13px" } }, title),
|
|
802
|
+
...children
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
function DetailRows(rows) {
|
|
806
|
+
const list = rows.filter(Boolean);
|
|
807
|
+
return h(
|
|
808
|
+
"div",
|
|
809
|
+
{ className: "dshm-kv" },
|
|
810
|
+
list.flatMap(([k, v]) => [
|
|
811
|
+
h("span", { className: "k", key: `${k}-k` }, k),
|
|
812
|
+
h("span", { key: `${k}-v`, style: { wordBreak: "break-all" } }, String(v))
|
|
813
|
+
])
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
function Card({ icon, name, badges, desc, sub, open, onToggle, detail, actions }) {
|
|
817
|
+
return h(
|
|
818
|
+
"div",
|
|
819
|
+
{
|
|
820
|
+
className: "dshm-card",
|
|
821
|
+
role: "button",
|
|
822
|
+
tabIndex: 0,
|
|
823
|
+
onClick: onToggle,
|
|
824
|
+
onKeyDown: (e) => {
|
|
825
|
+
if (e.key === "Enter" || e.key === " ") onToggle();
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
icon,
|
|
829
|
+
h(
|
|
830
|
+
"div",
|
|
831
|
+
{ className: "dshm-meta" },
|
|
832
|
+
h("div", { className: "dshm-top" }, h("span", { className: "dshm-name" }, name), ...badges.filter(Boolean)),
|
|
833
|
+
h("div", { className: "dshm-desc", style: open ? { WebkitLineClamp: "unset" } : null }, desc),
|
|
834
|
+
sub ? h("div", { className: "dshm-sub" }, sub) : null,
|
|
835
|
+
open ? h("div", { className: "dshm-detail" }, detail) : null,
|
|
836
|
+
open && actions && actions.length ? h("div", { className: "dshm-actions" }, ...actions) : null
|
|
837
|
+
)
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
var TABS = [
|
|
841
|
+
["market", "tab.market", "market"],
|
|
842
|
+
["installed", "tab.installed", "installed"],
|
|
843
|
+
["settings", "tab.settings", null]
|
|
844
|
+
];
|
|
845
|
+
function MarketPanel({ onClose }) {
|
|
846
|
+
const [tab, setTab] = useState("market");
|
|
847
|
+
const market = useAsync((force) => api("market", force ? { force: true } : {}), []);
|
|
848
|
+
const installed = useAsync(() => api("installed"), []);
|
|
849
|
+
const counts = {
|
|
850
|
+
market: market.data ? market.data.items.length : null,
|
|
851
|
+
installed: installed.data ? installed.data.items.length : null
|
|
852
|
+
};
|
|
853
|
+
const [banner, setBanner] = useState(null);
|
|
854
|
+
const [toast, setToast] = useState(null);
|
|
855
|
+
useEffect(() => {
|
|
856
|
+
const onKey = (e) => {
|
|
857
|
+
if (e.key === "Escape" && onClose) onClose();
|
|
858
|
+
};
|
|
859
|
+
document.addEventListener("keydown", onKey);
|
|
860
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
861
|
+
}, [onClose]);
|
|
862
|
+
useEffect(() => {
|
|
863
|
+
if (!toast) return;
|
|
864
|
+
const t = setTimeout(() => setToast(null), 6e3);
|
|
865
|
+
return () => clearTimeout(t);
|
|
866
|
+
}, [toast]);
|
|
867
|
+
const notify = useCallback(({ kind, text }) => {
|
|
868
|
+
setToast({ kind, text });
|
|
869
|
+
if (kind === "ok") setBanner({ text: lookup("banner.done") });
|
|
870
|
+
}, []);
|
|
871
|
+
return h(
|
|
872
|
+
"div",
|
|
873
|
+
{ className: "dshm-overlay", onClick: onClose },
|
|
874
|
+
h(
|
|
875
|
+
"div",
|
|
876
|
+
{ className: "dshm-panel", onClick: (e) => e.stopPropagation() },
|
|
877
|
+
h(
|
|
878
|
+
"div",
|
|
879
|
+
{ className: "dshm-head" },
|
|
880
|
+
h("span", { className: "dshm-title" }, lookup("title.full")),
|
|
881
|
+
h(
|
|
882
|
+
"div",
|
|
883
|
+
{ className: "dshm-seg", role: "tablist" },
|
|
884
|
+
TABS.map(
|
|
885
|
+
([key, labelKey, countKey]) => h(
|
|
886
|
+
"button",
|
|
887
|
+
{
|
|
888
|
+
key,
|
|
889
|
+
type: "button",
|
|
890
|
+
role: "tab",
|
|
891
|
+
"aria-selected": tab === key,
|
|
892
|
+
className: tab === key ? "on" : "",
|
|
893
|
+
onClick: () => setTab(key)
|
|
894
|
+
},
|
|
895
|
+
lookup(labelKey),
|
|
896
|
+
countKey && counts[countKey] != null ? h("span", { className: "dshm-count" }, String(counts[countKey])) : null
|
|
897
|
+
)
|
|
898
|
+
)
|
|
899
|
+
),
|
|
900
|
+
h("span", { className: "dshm-spacer" }),
|
|
901
|
+
h("button", { className: "dshm-btn", onClick: onClose }, lookup("common.close"))
|
|
902
|
+
),
|
|
903
|
+
h(
|
|
904
|
+
"div",
|
|
905
|
+
{ className: "dshm-body" },
|
|
906
|
+
tab === "market" ? h(MarketTab, { notify, market }) : null,
|
|
907
|
+
tab === "installed" ? h(InstalledTab, { notify, installed }) : null,
|
|
908
|
+
tab === "settings" ? h(SettingsTab, { notify }) : null
|
|
909
|
+
),
|
|
910
|
+
toast ? h(
|
|
911
|
+
"div",
|
|
912
|
+
{ className: `dshm-banner`, style: toast.kind === "err" ? { background: "var(--dsw-alias-state-error-secondary,#fee2e2)", color: "var(--dsw-alias-state-error-primary,#b91c1c)" } : null },
|
|
913
|
+
h("span", { className: "dshm-banner-text" }, toast.text)
|
|
914
|
+
) : null,
|
|
915
|
+
banner ? h(RestartBanner, { note: banner.text, onDone: () => setBanner(null) }) : null
|
|
916
|
+
)
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
function mountPanel() {
|
|
920
|
+
if (typeof document === "undefined") return;
|
|
921
|
+
ensureCss();
|
|
922
|
+
if (document.getElementById("dshm-panel-root")) return;
|
|
923
|
+
const container = document.createElement("div");
|
|
924
|
+
container.id = "dshm-panel-root";
|
|
925
|
+
document.body.appendChild(container);
|
|
926
|
+
const rdom = rd && rd.default && (rd.default.createRoot || rd.default.render) ? rd.default : rd;
|
|
927
|
+
let root = null;
|
|
928
|
+
const close = () => {
|
|
929
|
+
try {
|
|
930
|
+
if (root && typeof root.unmount === "function") root.unmount();
|
|
931
|
+
else if (rdom && typeof rdom.unmountComponentAtNode === "function") rdom.unmountComponentAtNode(container);
|
|
932
|
+
} catch {
|
|
933
|
+
}
|
|
934
|
+
container.remove();
|
|
935
|
+
};
|
|
936
|
+
if (rdom && typeof rdom.createRoot === "function") {
|
|
937
|
+
root = rdom.createRoot(container);
|
|
938
|
+
root.render(h(MarketPanel, { onClose: close }));
|
|
939
|
+
} else if (rdom && typeof rdom.render === "function") {
|
|
940
|
+
rdom.render(h(MarketPanel, { onClose: close }), container);
|
|
941
|
+
} else {
|
|
942
|
+
container.remove();
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
function MarketIcon() {
|
|
946
|
+
return h(
|
|
947
|
+
"svg",
|
|
948
|
+
{ viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true" },
|
|
949
|
+
h("rect", { x: "1.75", y: "1.75", width: "5.5", height: "5.5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.4" }),
|
|
950
|
+
h("rect", { x: "8.75", y: "1.75", width: "5.5", height: "5.5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.4" }),
|
|
951
|
+
h("rect", { x: "1.75", y: "8.75", width: "5.5", height: "5.5", rx: "1.2", stroke: "currentColor", strokeWidth: "1.4" }),
|
|
952
|
+
// 右下:放大镜(收一点,光学尺寸与其他宫格图标一致)
|
|
953
|
+
h("circle", { cx: "10.5", cy: "10.5", r: "2.9", stroke: "currentColor", strokeWidth: "1.4" }),
|
|
954
|
+
h("path", { d: "M12.6 12.6 14.3 14.3", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" })
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
function MarketEntry(props) {
|
|
958
|
+
useEffect(() => ensureCss(), []);
|
|
959
|
+
return h(
|
|
960
|
+
"button",
|
|
961
|
+
{
|
|
962
|
+
className: "dshm-entry",
|
|
963
|
+
onClick: () => {
|
|
964
|
+
try {
|
|
965
|
+
mountPanel();
|
|
966
|
+
} catch (e) {
|
|
967
|
+
console.error("[dsh-m] \u6253\u5F00\u5E02\u573A\u9762\u677F\u5931\u8D25:", e);
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
title: "\u63D2\u4EF6\u5E02\u573A"
|
|
971
|
+
},
|
|
972
|
+
h(MarketIcon),
|
|
973
|
+
props && props.wide ? h("span", null, lookup("market.title")) : null
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
function registerSlot(slots, options, component) {
|
|
977
|
+
const next = { ...options };
|
|
978
|
+
if (next.id == null && next.key != null) next.id = String(next.key);
|
|
979
|
+
if (next.key == null && next.id != null) next.key = next.id;
|
|
980
|
+
return slots.register(next, component);
|
|
981
|
+
}
|
|
982
|
+
function pickPayload(props) {
|
|
983
|
+
const found = [];
|
|
984
|
+
const visit = (node, depth) => {
|
|
985
|
+
if (!node || depth > 6) return;
|
|
986
|
+
if (typeof node === "string") {
|
|
987
|
+
const t = node.trim();
|
|
988
|
+
if ((t.startsWith("{") || t.startsWith("[")) && t.length > 8) {
|
|
989
|
+
try {
|
|
990
|
+
visit(JSON.parse(t), depth + 1);
|
|
991
|
+
} catch {
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
if (typeof node !== "object") return;
|
|
997
|
+
if (Array.isArray(node)) {
|
|
998
|
+
for (const x of node) visit(x, depth + 1);
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
if (Array.isArray(node.items)) found.push(node);
|
|
1002
|
+
for (const key of ["block", "meta", "result", "resultView", "view", "data", "value", "payload", "content", "message"]) {
|
|
1003
|
+
if (node[key] != null) visit(node[key], depth + 1);
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
visit(props, 0);
|
|
1007
|
+
return found.find((x) => x && Array.isArray(x.items)) || null;
|
|
1008
|
+
}
|
|
1009
|
+
function parseToolArgs(props) {
|
|
1010
|
+
const block = props?.block;
|
|
1011
|
+
const raw = (block && "kind" in block ? block.call?.argsRaw : block?.argsRaw) || "";
|
|
1012
|
+
if (!raw || typeof raw !== "string") return {};
|
|
1013
|
+
try {
|
|
1014
|
+
return JSON.parse(raw);
|
|
1015
|
+
} catch {
|
|
1016
|
+
return {};
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function ToolCardRow({ it, onInstalled }) {
|
|
1020
|
+
const [busy, setBusy] = useState(false);
|
|
1021
|
+
const install = async (e) => {
|
|
1022
|
+
e.stopPropagation();
|
|
1023
|
+
setBusy(true);
|
|
1024
|
+
try {
|
|
1025
|
+
const res = await api("install", { id: it.id });
|
|
1026
|
+
onInstalled({ ...it, installed: true, installedPkg: res.pkg, installedVersion: res.version });
|
|
1027
|
+
} catch {
|
|
1028
|
+
} finally {
|
|
1029
|
+
setBusy(false);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
return h(
|
|
1033
|
+
"div",
|
|
1034
|
+
{ className: "dshm-card", style: { cursor: "default" } },
|
|
1035
|
+
h(Icon, { entry: it }),
|
|
1036
|
+
h(
|
|
1037
|
+
"div",
|
|
1038
|
+
{ className: "dshm-meta" },
|
|
1039
|
+
h(
|
|
1040
|
+
"div",
|
|
1041
|
+
{ className: "dshm-top" },
|
|
1042
|
+
h("span", { className: "dshm-name" }, it.name),
|
|
1043
|
+
h("span", { className: "dshm-badge info" }, it.source === "npm" ? "npm" : "github"),
|
|
1044
|
+
it.installed ? h("span", { className: "dshm-badge" }, "\u5DF2\u5B89\u88C5") : null
|
|
1045
|
+
),
|
|
1046
|
+
h("div", { className: "dshm-desc" }, it.description),
|
|
1047
|
+
h("div", { className: "dshm-sub" }, `${it.id} \xB7 ${(it.tags || []).join("\u3001") || it.category}`),
|
|
1048
|
+
h(
|
|
1049
|
+
"div",
|
|
1050
|
+
{ className: "dshm-actions" },
|
|
1051
|
+
!it.installed ? h("button", { className: "dshm-btn primary sm", disabled: busy, onClick: install }, busy ? h(Spin) : "\u5B89\u88C5") : null
|
|
1052
|
+
)
|
|
1053
|
+
)
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
function SearchToolView(props) {
|
|
1057
|
+
useEffect(() => ensureCss(), []);
|
|
1058
|
+
const payload = pickPayload(props);
|
|
1059
|
+
const args = parseToolArgs(props);
|
|
1060
|
+
const query = String(payload?.query || args.query || "").trim();
|
|
1061
|
+
const fromTool = Array.isArray(payload?.items) && payload.items.length ? payload.items : null;
|
|
1062
|
+
const running = !!(props?.block && !("kind" in props.block));
|
|
1063
|
+
const [items, setItems] = useState(fromTool || []);
|
|
1064
|
+
const [err, setErr] = useState("");
|
|
1065
|
+
useEffect(() => {
|
|
1066
|
+
if (fromTool) setItems(fromTool);
|
|
1067
|
+
}, [fromTool]);
|
|
1068
|
+
useEffect(() => {
|
|
1069
|
+
if (fromTool || running) return;
|
|
1070
|
+
let live = true;
|
|
1071
|
+
api("search", { query, category: args.category, limit: args.limit }).then((d) => {
|
|
1072
|
+
if (live) setItems(d.items || []);
|
|
1073
|
+
}).catch((e) => {
|
|
1074
|
+
if (live) {
|
|
1075
|
+
setItems([]);
|
|
1076
|
+
setErr(e && e.message || String(e));
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
return () => {
|
|
1080
|
+
live = false;
|
|
1081
|
+
};
|
|
1082
|
+
}, [query, running, !!fromTool]);
|
|
1083
|
+
if (running) return null;
|
|
1084
|
+
if (!items.length) return err ? h("div", { className: "dshm-err" }, err) : null;
|
|
1085
|
+
return h(
|
|
1086
|
+
"div",
|
|
1087
|
+
{ style: { display: "flex", flexDirection: "column", gap: "8px" } },
|
|
1088
|
+
items.map(
|
|
1089
|
+
(it) => h(ToolCardRow, {
|
|
1090
|
+
key: it.id,
|
|
1091
|
+
it,
|
|
1092
|
+
onInstalled: (next) => setItems((cur) => cur.map((x) => x.id === next.id ? next : x))
|
|
1093
|
+
})
|
|
1094
|
+
)
|
|
1095
|
+
);
|
|
1096
|
+
}
|
|
1097
|
+
function ListToolView(props) {
|
|
1098
|
+
useEffect(() => ensureCss(), []);
|
|
1099
|
+
const payload = pickPayload(props);
|
|
1100
|
+
const items = Array.isArray(payload?.items) ? payload.items : [];
|
|
1101
|
+
if (!items.length) return null;
|
|
1102
|
+
return h(
|
|
1103
|
+
"div",
|
|
1104
|
+
{ style: { display: "flex", flexDirection: "column", gap: "4px", fontSize: "12px" } },
|
|
1105
|
+
items.map(
|
|
1106
|
+
(it) => h(
|
|
1107
|
+
"div",
|
|
1108
|
+
{ key: it.pkg, className: "dshm-row" },
|
|
1109
|
+
h("span", { style: { fontWeight: 600 } }, it.name),
|
|
1110
|
+
h("span", { className: "dshm-hint" }, `(${it.pkg})`),
|
|
1111
|
+
h("span", { className: "dshm-hint" }, `v${it.version || "?"}`),
|
|
1112
|
+
it.registryId ? h("span", { className: "dshm-badge" }, "\u5E02\u573A") : h("span", { className: "dshm-badge info" }, "\u975E\u5E02\u573A"),
|
|
1113
|
+
it.outdated ? h("span", { className: "dshm-badge warn" }, `\u53EF\u5347\u7EA7${it.latestVersion ? ` \u2192 v${it.latestVersion}` : ""}`) : null
|
|
1114
|
+
)
|
|
1115
|
+
)
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
var inject = ["slots"];
|
|
1119
|
+
function apply(ctx) {
|
|
1120
|
+
const slots = ctx.slots;
|
|
1121
|
+
if (!slots) return;
|
|
1122
|
+
ctx.effect(() => ensureCss(), "dshm-style");
|
|
1123
|
+
ctx.inject(["locale"], (c) => {
|
|
1124
|
+
if (!c.locale || typeof c.locale.register !== "function") return;
|
|
1125
|
+
c.effect(() => {
|
|
1126
|
+
try {
|
|
1127
|
+
return c.locale.register("dshm", { zh: ZH, en: EN });
|
|
1128
|
+
} catch {
|
|
1129
|
+
return () => {
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
}, "dshm-locale");
|
|
1133
|
+
});
|
|
1134
|
+
slots.inject(
|
|
1135
|
+
"sidebar.footer.action",
|
|
1136
|
+
() => slots.register(
|
|
1137
|
+
{ name: "sidebar.footer.action", id: "dshm-market", key: "dshm-market", order: 9, locale: "dshm", label: () => lookup("market.title") },
|
|
1138
|
+
function DshmMarketEntry(actionProps) {
|
|
1139
|
+
return h(MarketEntry, actionProps);
|
|
1140
|
+
}
|
|
1141
|
+
)
|
|
1142
|
+
);
|
|
1143
|
+
slots.inject(
|
|
1144
|
+
"tool.call.toolview",
|
|
1145
|
+
() => registerSlot(slots, { name: "tool.call.toolview", key: "dshm_search" }, SearchToolView)
|
|
1146
|
+
);
|
|
1147
|
+
slots.inject(
|
|
1148
|
+
"tool.call.toolview",
|
|
1149
|
+
() => registerSlot(slots, { name: "tool.call.toolview", key: "dshm_list" }, ListToolView)
|
|
1150
|
+
);
|
|
1151
|
+
slots.inject(
|
|
1152
|
+
"tool.call.toolview",
|
|
1153
|
+
() => registerSlot(slots, { name: "tool.call.toolview", key: "dshm_outdated" }, ListToolView)
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
return { inject, apply };
|
|
1157
|
+
},
|
|
1158
|
+
});
|
|
1159
|
+
|