@ququ-jiaxk/dsh-plugin-center 0.1.48 → 0.1.50

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 CHANGED
@@ -36,7 +36,7 @@ var logo_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" v
36
36
 
37
37
  // src/client.tsx
38
38
  var import_jsx_runtime = require("react/jsx-runtime");
39
- var PLUGIN_VERSION = true ? "0.1.48" : "0.0.0";
39
+ var PLUGIN_VERSION = true ? "0.1.50" : "0.0.0";
40
40
  var PANEL_ID = "plugin-center";
41
41
  var inject = ["slots", "remote", "remote.pluginManager"];
42
42
  var hostCtx = null;
@@ -209,7 +209,7 @@ function safeImageUrl(url) {
209
209
  const value = url.trim();
210
210
  return /^(https?:\/\/|data:image\/)/iu.test(value) ? value : null;
211
211
  }
212
- function renderInline(raw) {
212
+ function renderInline(raw, resolveImage) {
213
213
  let text = escapeHtml(String(raw ?? ""));
214
214
  const codes = [];
215
215
  text = text.replace(/`([^`]+)`/gu, (_match, code) => {
@@ -219,8 +219,8 @@ function renderInline(raw) {
219
219
  text = text.replace(
220
220
  /!\[([^\]]*)\]\(([^)\s]+)(?:\s+&quot;[^&]*?&quot;)?\)/gu,
221
221
  (_match, alt, url) => {
222
- const src = safeImageUrl(url);
223
- return src ? `<img src="${src}" alt="${alt}" loading="lazy">` : alt;
222
+ const resolved = safeImageUrl(url) ?? (resolveImage && !/^[a-z][a-z0-9+.-]*:/iu.test(url) ? resolveImage(url) : null);
223
+ return resolved ? `<img src="${resolved}" alt="${alt}" loading="lazy">` : alt;
224
224
  }
225
225
  );
226
226
  text = text.replace(
@@ -239,7 +239,7 @@ function renderInline(raw) {
239
239
  });
240
240
  return text;
241
241
  }
242
- function renderMarkdown(source) {
242
+ function renderMarkdown(source, resolveImage) {
243
243
  const lines = String(source ?? "").replace(/\r\n?/gu, "\n").split("\n");
244
244
  const out = [];
245
245
  let index = 0;
@@ -247,7 +247,7 @@ function renderMarkdown(source) {
247
247
  let list = null;
248
248
  const flushParagraph = () => {
249
249
  if (paragraph.length === 0) return;
250
- out.push(`<p>${paragraph.map((line) => renderInline(line)).join("<br>")}</p>`);
250
+ out.push(`<p>${paragraph.map((line) => renderInline(line, resolveImage)).join("<br>")}</p>`);
251
251
  paragraph = [];
252
252
  };
253
253
  const closeList = () => {
@@ -288,7 +288,7 @@ function renderMarkdown(source) {
288
288
  if (heading) {
289
289
  flush();
290
290
  const level = heading[1].length;
291
- out.push(`<h${level}>${renderInline(heading[2])}</h${level}>`);
291
+ out.push(`<h${level}>${renderInline(heading[2], resolveImage)}</h${level}>`);
292
292
  index += 1;
293
293
  continue;
294
294
  }
@@ -305,7 +305,7 @@ function renderMarkdown(source) {
305
305
  quote.push(lines[index].trim().replace(/^>\s?/u, ""));
306
306
  index += 1;
307
307
  }
308
- out.push(`<blockquote>${quote.map((item) => renderInline(item)).join("<br>")}</blockquote>`);
308
+ out.push(`<blockquote>${quote.map((item) => renderInline(item, resolveImage)).join("<br>")}</blockquote>`);
309
309
  continue;
310
310
  }
311
311
  if (trimmed.startsWith("|") && index + 1 < lines.length && /^\|?[\s:|-]+\|?$/u.test(lines[index + 1].trim()) && lines[index + 1].includes("-")) {
@@ -321,7 +321,7 @@ function renderMarkdown(source) {
321
321
  }
322
322
  const head = rows.shift() ?? [];
323
323
  out.push(
324
- `<table class="pcx-md-table"><thead><tr>${head.map((cell) => `<th>${renderInline(cell)}</th>`).join("")}</tr></thead><tbody>${rows.map((row) => `<tr>${row.map((cell) => `<td>${renderInline(cell)}</td>`).join("")}</tr>`).join("")}</tbody></table>`
324
+ `<table class="pcx-md-table"><thead><tr>${head.map((cell) => `<th>${renderInline(cell, resolveImage)}</th>`).join("")}</tr></thead><tbody>${rows.map((row) => `<tr>${row.map((cell) => `<td>${renderInline(cell, resolveImage)}</td>`).join("")}</tr>`).join("")}</tbody></table>`
325
325
  );
326
326
  continue;
327
327
  }
@@ -335,7 +335,7 @@ function renderMarkdown(source) {
335
335
  out.push(`<${kind}>`);
336
336
  list = kind;
337
337
  }
338
- out.push(`<li>${renderInline((unordered ?? ordered)[1])}</li>`);
338
+ out.push(`<li>${renderInline((unordered ?? ordered)[1], resolveImage)}</li>`);
339
339
  index += 1;
340
340
  continue;
341
341
  }
@@ -346,8 +346,11 @@ function renderMarkdown(source) {
346
346
  flush();
347
347
  return out.join("\n");
348
348
  }
349
- function Markdown({ text }) {
350
- const html = (0, import_react.useMemo)(() => renderMarkdown(text), [text]);
349
+ function Markdown({
350
+ text,
351
+ resolveImage
352
+ }) {
353
+ const html = (0, import_react.useMemo)(() => renderMarkdown(text, resolveImage), [text, resolveImage]);
351
354
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-md", dangerouslySetInnerHTML: { __html: html } });
352
355
  }
353
356
  function Badges({ plugin }) {
@@ -416,10 +419,10 @@ function InstalledList({
416
419
  onClick: missing ? void 0 : () => onOpen(bundle.name),
417
420
  children: [
418
421
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-top", children: [
419
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(item?.displayName ?? bundle.name) }),
422
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(bundle.title ?? item?.displayName ?? bundle.name) }),
420
423
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
421
424
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
422
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
425
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: bundle.title ?? item?.displayName ?? bundle.name }),
423
426
  missing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u5B89\u88C5" }) : /* @__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" }),
424
427
  bundle.availability === "installation" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5185\u7F6E" }) : null,
425
428
  experimental ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5B9E\u9A8C\u6027" }) : null,
@@ -430,6 +433,7 @@ function InstalledList({
430
433
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
431
434
  ] })
432
435
  ] }),
436
+ bundle.description || item?.summary ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pcx-desc pcx-desc-block", children: bundle.description ?? item?.summary }) : null,
433
437
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-foot", children: [
434
438
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-owner", children: missing ? "DSH \u81EA\u5E26\uFF0C\u53EF\u5B89\u88C5" : bundle.official ? "\u968F DSH \u5B89\u88C5" : localInstall ? "\u672C\u5730\u5305\u5B89\u88C5" : "registry \u5B89\u88C5" }),
435
439
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-meta", children: bundle.version ? `v${bundle.version}` : bundle.installTarget?.version ? `v${bundle.installTarget.version}` : "\u7248\u672C\u672A\u77E5" })
@@ -449,10 +453,20 @@ function LocalDetailView({
449
453
  data,
450
454
  onBack,
451
455
  onOpenCenter,
452
- onUninstall
456
+ onUninstall,
457
+ onToggle
453
458
  }) {
454
459
  const bundle = data.bundle;
455
460
  const markdown = data.detail && data.detail.status === "found" ? data.detail.markdown : "";
461
+ const imageResolver = (src) => {
462
+ if (!data.detail || data.detail.status !== "found") return null;
463
+ const params = new URLSearchParams({
464
+ bundle: bundle.name,
465
+ document: data.detail.path,
466
+ path: src
467
+ });
468
+ return `/api/plugin-manager/detail-file?${params.toString()}`;
469
+ };
456
470
  const origin = data.detail && data.detail.status === "found" ? data.detail.path : "";
457
471
  const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
458
472
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-root", children: [
@@ -478,11 +492,18 @@ function LocalDetailView({
478
492
  bundle.source ? ` \xB7 ${bundle.source}` : ""
479
493
  ] }),
480
494
  onOpenCenter ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn", onClick: onOpenCenter, children: "\u5728\u5C0F\u8DA3\u63D2\u4EF6\u4E2D\u5FC3\u67E5\u770B" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u5728\u5C0F\u8DA3\u63D2\u4EF6\u4E2D\u5FC3\u4E0A\u67B6" }),
495
+ bundle.name !== "@ququ-jiaxk/dsh-plugin-center" && (bundle.optional || bundle.installed) && onToggle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn", onClick: onToggle, children: bundle.enabled ? "\u505C\u7528" : "\u542F\u7528" }) : null,
481
496
  bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-danger", onClick: onUninstall, children: "\u5378\u8F7D" }) : null
482
497
  ] }),
483
498
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
484
499
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u63D2\u4EF6\u8BE6\u60C5" }),
485
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Markdown, { text: markdown || bundle.description || "\u8FD9\u4E2A\u63D2\u4EF6\u6CA1\u6709\u63D0\u4F9B README \u6216 locale \u8BE6\u60C5\u3002" })
500
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
501
+ Markdown,
502
+ {
503
+ text: markdown || bundle.description || "\u8FD9\u4E2A\u63D2\u4EF6\u6CA1\u6709\u63D0\u4F9B README \u6216 locale \u8BE6\u60C5\u3002",
504
+ resolveImage: imageResolver
505
+ }
506
+ )
486
507
  ] }),
487
508
  origin ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
488
509
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u8BE6\u60C5\u6765\u6E90" }),
@@ -1060,7 +1081,12 @@ function Panel() {
1060
1081
  setLocalDetail(null);
1061
1082
  void openDetail(name);
1062
1083
  } : void 0,
1063
- onUninstall: () => uninstallLocal(localDetail.bundle.name)
1084
+ onUninstall: () => uninstallLocal(localDetail.bundle.name),
1085
+ onToggle: () => {
1086
+ const { name, enabled } = localDetail.bundle;
1087
+ setLocalDetail(null);
1088
+ void toggleBundle(name, !enabled);
1089
+ }
1064
1090
  }
1065
1091
  ),
1066
1092
  dialog ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PromptDialog, { dialog, onClose: () => setDialog(null) }) : null
package/lib/index.js CHANGED
@@ -161,6 +161,20 @@ function selfUpdateBlockedInfo(own) {
161
161
  }
162
162
  }
163
163
 
164
+ /** DSH 的 meta.title / meta.description 可能是字符串,也可能是按语言索引的对象。 */
165
+ function localizedText(value) {
166
+ if (typeof value === 'string') return value || null
167
+ if (!value || typeof value !== 'object') return null
168
+ for (const key of ['zh', 'zh-cn', 'zh-hans', 'zh-hant', 'en']) {
169
+ const text = value[key]
170
+ if (typeof text === 'string' && text) return text
171
+ }
172
+ for (const text of Object.values(value)) {
173
+ if (typeof text === 'string' && text) return text
174
+ }
175
+ return null
176
+ }
177
+
164
178
  async function findSelfBundle(manager) {
165
179
  try {
166
180
  const bundles = await manager.listBundles()
@@ -404,6 +418,7 @@ export function apply(ctx) {
404
418
  // 单独给一份完整清单,供「本机」视图展示和启用。
405
419
  bundles = list.map((bundle) => ({
406
420
  name: bundle.name,
421
+ title: localizedText(bundle.meta?.title),
407
422
  version: bundle.version ?? null,
408
423
  enabled: bundle.enabled,
409
424
  installed: Boolean(bundle.installed),
@@ -413,7 +428,7 @@ export function apply(ctx) {
413
428
  removable: Boolean(bundle.removable),
414
429
  source: bundle.source ?? null,
415
430
  error: bundle.error?.code ?? null,
416
- description: bundle.description ?? null,
431
+ description: localizedText(bundle.meta?.description) ?? bundle.description ?? null,
417
432
  listedByDefault: bundle.listedByDefault !== false,
418
433
  installTarget: bundle.installTarget ?? null,
419
434
  }))
@@ -1011,10 +1026,10 @@ export function apply(ctx) {
1011
1026
  return send(res, 200, {
1012
1027
  bundle: {
1013
1028
  name: bundle.name,
1014
- displayName: typeof meta.name === 'string' ? meta.name : bundle.name,
1015
- summary: typeof meta.summary === 'string' ? meta.summary : (bundle.description ?? ''),
1029
+ displayName: localizedText(meta.title) ?? bundle.name,
1030
+ summary: localizedText(meta.description) ?? bundle.description ?? '',
1016
1031
  icon: typeof meta.icon === 'string' ? meta.icon : null,
1017
- description: bundle.description ?? null,
1032
+ description: localizedText(meta.description) ?? bundle.description ?? null,
1018
1033
  version: bundle.version ?? null,
1019
1034
  enabled: bundle.enabled,
1020
1035
  official: Boolean(bundle.official),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-plugin-center",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "description": "小趣插件中心:浏览、安装、更新和发布远端插件中心的插件",
5
5
  "icon": "logo.svg",
6
6
  "type": "module",