@ququ-jiaxk/dsh-plugin-center 0.1.41 → 0.1.42
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/lib/client.js +98 -27
- package/lib/index.js +38 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -30,7 +30,7 @@ __export(client_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(client_exports);
|
|
31
31
|
var import_react = require("react");
|
|
32
32
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
-
var PLUGIN_VERSION = true ? "0.1.
|
|
33
|
+
var PLUGIN_VERSION = true ? "0.1.42" : "0.0.0";
|
|
34
34
|
var PANEL_ID = "plugin-center";
|
|
35
35
|
var inject = ["slots", "remote", "remote.pluginManager"];
|
|
36
36
|
var hostCtx = null;
|
|
@@ -233,36 +233,73 @@ function InstalledList({
|
|
|
233
233
|
const item = center.get(bundle.name);
|
|
234
234
|
const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
|
|
235
235
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "pcx-card", children: [
|
|
236
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
237
|
-
"div",
|
|
238
|
-
|
|
239
|
-
className: "pcx-card-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-
|
|
245
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
|
|
246
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
|
|
247
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
|
|
248
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `pcx-badge ${bundle.enabled ? "pcx-badge-ok" : "pcx-badge-warn"}`, children: bundle.enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u505C\u7528" }),
|
|
249
|
-
bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
|
|
250
|
-
item ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" })
|
|
251
|
-
] }),
|
|
252
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
|
|
253
|
-
] })
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-main", onClick: () => onOpen(bundle.name), children: [
|
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-top", children: [
|
|
238
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(item?.displayName ?? bundle.name) }),
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
|
|
240
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
|
|
241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
|
|
242
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `pcx-badge ${bundle.enabled ? "pcx-badge-ok" : "pcx-badge-warn"}`, children: bundle.enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u505C\u7528" }),
|
|
243
|
+
bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
|
|
244
|
+
item ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" })
|
|
254
245
|
] }),
|
|
255
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
246
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
|
|
247
|
+
] })
|
|
248
|
+
] }),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-foot", children: [
|
|
250
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-owner", children: bundle.official ? "\u968F DSH \u5B89\u88C5" : localInstall ? "\u672C\u5730\u5305\u5B89\u88C5" : "registry \u5B89\u88C5" }),
|
|
251
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-meta", children: bundle.version ? `v${bundle.version}` : "\u7248\u672C\u672A\u77E5" })
|
|
252
|
+
] })
|
|
253
|
+
] }),
|
|
262
254
|
bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-card-actions", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-sm pcx-btn-danger", onClick: () => onUninstall(bundle.name), children: "\u5378\u8F7D" }) }) : null
|
|
263
255
|
] }, bundle.name);
|
|
264
256
|
}) });
|
|
265
257
|
}
|
|
258
|
+
function LocalDetailView({
|
|
259
|
+
data,
|
|
260
|
+
onBack,
|
|
261
|
+
onOpenCenter,
|
|
262
|
+
onUninstall
|
|
263
|
+
}) {
|
|
264
|
+
const bundle = data.bundle;
|
|
265
|
+
const markdown = data.detail && data.detail.status === "found" ? data.detail.markdown : "";
|
|
266
|
+
const origin = data.detail && data.detail.status === "found" ? data.detail.path : "";
|
|
267
|
+
const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
|
|
268
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-root", children: [
|
|
269
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "pcx-back", onClick: onBack, children: "\u2190 \u8FD4\u56DE\u5217\u8868" }),
|
|
270
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-detail-head", children: [
|
|
271
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon pcx-icon-lg", children: iconLetter(bundle.displayName ?? bundle.name) }),
|
|
272
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-detail-titles", children: [
|
|
273
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
|
|
274
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { className: "pcx-title", children: bundle.displayName ?? bundle.name }),
|
|
275
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: `pcx-badge ${bundle.enabled ? "pcx-badge-ok" : "pcx-badge-warn"}`, children: bundle.enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u505C\u7528" }),
|
|
276
|
+
bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null
|
|
277
|
+
] }),
|
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name }),
|
|
279
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-desc pcx-desc-block", children: bundle.summary || "\u672C\u673A\u5B89\u88C5\u7684\u63D2\u4EF6" })
|
|
280
|
+
] })
|
|
281
|
+
] }),
|
|
282
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-actions pcx-actions-left", children: [
|
|
283
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "pcx-sub", children: [
|
|
284
|
+
bundle.version ? `v${bundle.version}` : "\u7248\u672C\u672A\u77E5",
|
|
285
|
+
" \xB7",
|
|
286
|
+
" ",
|
|
287
|
+
bundle.official ? "\u968F DSH \u5B89\u88C5" : localInstall ? "\u672C\u5730\u5305\u5B89\u88C5" : "registry \u5B89\u88C5",
|
|
288
|
+
bundle.source ? ` \xB7 ${bundle.source}` : ""
|
|
289
|
+
] }),
|
|
290
|
+
onOpenCenter ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn", onClick: onOpenCenter, children: "\u5728\u63D2\u4EF6\u4E2D\u5FC3\u67E5\u770B" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u5728\u63D2\u4EF6\u4E2D\u5FC3\u4E0A\u67B6" }),
|
|
291
|
+
bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-danger", onClick: onUninstall, children: "\u5378\u8F7D" }) : null
|
|
292
|
+
] }),
|
|
293
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
|
|
294
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u63D2\u4EF6\u8BE6\u60C5" }),
|
|
295
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-text", children: markdown || bundle.description || "\u8FD9\u4E2A\u63D2\u4EF6\u6CA1\u6709\u63D0\u4F9B README \u6216 locale \u8BE6\u60C5\u3002" })
|
|
296
|
+
] }),
|
|
297
|
+
origin ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
|
|
298
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u8BE6\u60C5\u6765\u6E90" }),
|
|
299
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-text", children: origin })
|
|
300
|
+
] }) : null
|
|
301
|
+
] });
|
|
302
|
+
}
|
|
266
303
|
function Panel() {
|
|
267
304
|
const cached = panelSnapshot;
|
|
268
305
|
const rootRef = (0, import_react.useRef)(null);
|
|
@@ -286,6 +323,7 @@ function Panel() {
|
|
|
286
323
|
const pushTrace = (line) => setTrace((current) => [...current.slice(-7), `${(/* @__PURE__ */ new Date()).toLocaleTimeString()} ${line}`]);
|
|
287
324
|
const [view, setView] = (0, import_react.useState)(cached?.view ?? "list");
|
|
288
325
|
const [detail, setDetail] = (0, import_react.useState)(cached?.detail ?? null);
|
|
326
|
+
const [localDetail, setLocalDetail] = (0, import_react.useState)(null);
|
|
289
327
|
const [binding, setBinding] = (0, import_react.useState)(false);
|
|
290
328
|
const [dialog, setDialog] = (0, import_react.useState)(null);
|
|
291
329
|
const [passwordOpen, setPasswordOpen] = (0, import_react.useState)(false);
|
|
@@ -582,6 +620,7 @@ function Panel() {
|
|
|
582
620
|
danger: true,
|
|
583
621
|
action: async () => {
|
|
584
622
|
await api("/uninstall", { method: "POST", body: { packageName } });
|
|
623
|
+
setLocalDetail(null);
|
|
585
624
|
setNotice(`\u5DF2\u5378\u8F7D ${packageName}`);
|
|
586
625
|
await load(scope, category, query);
|
|
587
626
|
}
|
|
@@ -754,6 +793,14 @@ function Panel() {
|
|
|
754
793
|
setError(err.message);
|
|
755
794
|
}
|
|
756
795
|
}
|
|
796
|
+
async function openLocalDetail(packageName) {
|
|
797
|
+
setError("");
|
|
798
|
+
try {
|
|
799
|
+
setLocalDetail(await api(`/local-detail?package=${encodeURIComponent(packageName)}`));
|
|
800
|
+
} catch (err) {
|
|
801
|
+
setError(err.message);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
757
804
|
async function afterUpload(packageName) {
|
|
758
805
|
setView("list");
|
|
759
806
|
await load(scope, category, query);
|
|
@@ -786,6 +833,27 @@ function Panel() {
|
|
|
786
833
|
}
|
|
787
834
|
);
|
|
788
835
|
}
|
|
836
|
+
if (localDetail) {
|
|
837
|
+
const centerItem = items.find((plugin) => plugin.packageName === localDetail.bundle.name);
|
|
838
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
839
|
+
notice ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-toast", children: notice }) : null,
|
|
840
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-toast pcx-toast-error", children: error }) : null,
|
|
841
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
842
|
+
LocalDetailView,
|
|
843
|
+
{
|
|
844
|
+
data: localDetail,
|
|
845
|
+
onBack: () => setLocalDetail(null),
|
|
846
|
+
onOpenCenter: centerItem ? () => {
|
|
847
|
+
const name = localDetail.bundle.name;
|
|
848
|
+
setLocalDetail(null);
|
|
849
|
+
void openDetail(name);
|
|
850
|
+
} : void 0,
|
|
851
|
+
onUninstall: () => uninstallLocal(localDetail.bundle.name)
|
|
852
|
+
}
|
|
853
|
+
),
|
|
854
|
+
dialog ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PromptDialog, { dialog, onClose: () => setDialog(null) }) : null
|
|
855
|
+
] });
|
|
856
|
+
}
|
|
789
857
|
if (detail) {
|
|
790
858
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
791
859
|
notice ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-toast", children: notice }) : null,
|
|
@@ -1070,7 +1138,10 @@ function Panel() {
|
|
|
1070
1138
|
bundles: state?.installed ?? [],
|
|
1071
1139
|
centerItems: items,
|
|
1072
1140
|
query,
|
|
1073
|
-
onOpen: (name) =>
|
|
1141
|
+
onOpen: (name) => {
|
|
1142
|
+
if (items.some((plugin) => plugin.packageName === name)) void openDetail(name);
|
|
1143
|
+
else void openLocalDetail(name);
|
|
1144
|
+
},
|
|
1074
1145
|
onUninstall: uninstallLocal
|
|
1075
1146
|
}
|
|
1076
1147
|
) : loading && items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty", children: "\u6B63\u5728\u52A0\u8F7D\u2026" }) : items.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-empty", children: [
|
package/lib/index.js
CHANGED
|
@@ -919,6 +919,44 @@ export function apply(ctx) {
|
|
|
919
919
|
return send(res, 200, detail)
|
|
920
920
|
}
|
|
921
921
|
|
|
922
|
+
// 本机已装插件的详情:即使没在中心上架,也能读到 README / locale 详情。
|
|
923
|
+
if (req.method === 'GET' && path === '/local-detail') {
|
|
924
|
+
const packageName = url.searchParams.get('package') ?? ''
|
|
925
|
+
if (!packageName) return send(res, 400, { error: '缺少 package 参数' })
|
|
926
|
+
const manager = ctx.get('pluginManager')
|
|
927
|
+
if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用' })
|
|
928
|
+
|
|
929
|
+
const bundle = (await manager.listBundles()).find((item) => item.name === packageName)
|
|
930
|
+
if (!bundle) return send(res, 404, { error: `本机没有安装 ${packageName}` })
|
|
931
|
+
|
|
932
|
+
const meta = bundle.meta && typeof bundle.meta === 'object' ? bundle.meta : {}
|
|
933
|
+
let detail = null
|
|
934
|
+
try {
|
|
935
|
+
if (typeof manager.readBundleDetail === 'function') {
|
|
936
|
+
detail = await manager.readBundleDetail(packageName, 'zh')
|
|
937
|
+
}
|
|
938
|
+
} catch {
|
|
939
|
+
detail = null
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
return send(res, 200, {
|
|
943
|
+
bundle: {
|
|
944
|
+
name: bundle.name,
|
|
945
|
+
displayName: typeof meta.name === 'string' ? meta.name : bundle.name,
|
|
946
|
+
summary: typeof meta.summary === 'string' ? meta.summary : (bundle.description ?? ''),
|
|
947
|
+
description: bundle.description ?? null,
|
|
948
|
+
version: bundle.version ?? null,
|
|
949
|
+
enabled: bundle.enabled,
|
|
950
|
+
official: Boolean(bundle.official),
|
|
951
|
+
availability: bundle.availability ?? null,
|
|
952
|
+
removable: Boolean(bundle.removable),
|
|
953
|
+
source: bundle.source ?? null,
|
|
954
|
+
error: bundle.error?.code ?? null,
|
|
955
|
+
},
|
|
956
|
+
detail,
|
|
957
|
+
})
|
|
958
|
+
}
|
|
959
|
+
|
|
922
960
|
if (req.method === 'GET' && path === '/install-progress') {
|
|
923
961
|
const packageName = url.searchParams.get('package') ?? ''
|
|
924
962
|
if (!packageName) return send(res, 400, { error: '缺少 package 参数' })
|