@ququ-jiaxk/dsh-plugin-center 0.1.49 → 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.
Files changed (2) hide show
  1. package/lib/client.js +40 -15
  2. package/package.json +1 -1
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.49" : "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 }) {
@@ -450,10 +453,20 @@ function LocalDetailView({
450
453
  data,
451
454
  onBack,
452
455
  onOpenCenter,
453
- onUninstall
456
+ onUninstall,
457
+ onToggle
454
458
  }) {
455
459
  const bundle = data.bundle;
456
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
+ };
457
470
  const origin = data.detail && data.detail.status === "found" ? data.detail.path : "";
458
471
  const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
459
472
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-root", children: [
@@ -479,11 +492,18 @@ function LocalDetailView({
479
492
  bundle.source ? ` \xB7 ${bundle.source}` : ""
480
493
  ] }),
481
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,
482
496
  bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-danger", onClick: onUninstall, children: "\u5378\u8F7D" }) : null
483
497
  ] }),
484
498
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
485
499
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u63D2\u4EF6\u8BE6\u60C5" }),
486
- /* @__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
+ )
487
507
  ] }),
488
508
  origin ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
489
509
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u8BE6\u60C5\u6765\u6E90" }),
@@ -1061,7 +1081,12 @@ function Panel() {
1061
1081
  setLocalDetail(null);
1062
1082
  void openDetail(name);
1063
1083
  } : void 0,
1064
- 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
+ }
1065
1090
  }
1066
1091
  ),
1067
1092
  dialog ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PromptDialog, { dialog, onClose: () => setDialog(null) }) : null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-plugin-center",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "小趣插件中心:浏览、安装、更新和发布远端插件中心的插件",
5
5
  "icon": "logo.svg",
6
6
  "type": "module",