@ququ-jiaxk/dsh-plugin-center 0.1.49 → 0.1.51

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 +72 -29
  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.51" : "0.0.0";
40
40
  var PANEL_ID = "plugin-center";
41
41
  var inject = ["slots", "remote", "remote.pluginManager"];
42
42
  var hostCtx = null;
@@ -60,6 +60,9 @@ function localCategory(bundle) {
60
60
  if (bundle.availability === "installation") return "builtin";
61
61
  return "third";
62
62
  }
63
+ function isVisibleBundle(bundle) {
64
+ return (bundle.listedByDefault !== false || bundle.enabled || Boolean(bundle.installed)) && (Boolean(bundle.installed) || Boolean(bundle.official) || Boolean(bundle.error));
65
+ }
63
66
  var panelSnapshot = null;
64
67
  var selfUpdateTarget = null;
65
68
  var selfUpdatePolling = false;
@@ -209,7 +212,7 @@ function safeImageUrl(url) {
209
212
  const value = url.trim();
210
213
  return /^(https?:\/\/|data:image\/)/iu.test(value) ? value : null;
211
214
  }
212
- function renderInline(raw) {
215
+ function renderInline(raw, resolveImage) {
213
216
  let text = escapeHtml(String(raw ?? ""));
214
217
  const codes = [];
215
218
  text = text.replace(/`([^`]+)`/gu, (_match, code) => {
@@ -219,8 +222,8 @@ function renderInline(raw) {
219
222
  text = text.replace(
220
223
  /!\[([^\]]*)\]\(([^)\s]+)(?:\s+&quot;[^&]*?&quot;)?\)/gu,
221
224
  (_match, alt, url) => {
222
- const src = safeImageUrl(url);
223
- return src ? `<img src="${src}" alt="${alt}" loading="lazy">` : alt;
225
+ const resolved = safeImageUrl(url) ?? (resolveImage && !/^[a-z][a-z0-9+.-]*:/iu.test(url) ? resolveImage(url) : null);
226
+ return resolved ? `<img src="${resolved}" alt="${alt}" loading="lazy">` : alt;
224
227
  }
225
228
  );
226
229
  text = text.replace(
@@ -239,7 +242,7 @@ function renderInline(raw) {
239
242
  });
240
243
  return text;
241
244
  }
242
- function renderMarkdown(source) {
245
+ function renderMarkdown(source, resolveImage) {
243
246
  const lines = String(source ?? "").replace(/\r\n?/gu, "\n").split("\n");
244
247
  const out = [];
245
248
  let index = 0;
@@ -247,7 +250,7 @@ function renderMarkdown(source) {
247
250
  let list = null;
248
251
  const flushParagraph = () => {
249
252
  if (paragraph.length === 0) return;
250
- out.push(`<p>${paragraph.map((line) => renderInline(line)).join("<br>")}</p>`);
253
+ out.push(`<p>${paragraph.map((line) => renderInline(line, resolveImage)).join("<br>")}</p>`);
251
254
  paragraph = [];
252
255
  };
253
256
  const closeList = () => {
@@ -288,7 +291,7 @@ function renderMarkdown(source) {
288
291
  if (heading) {
289
292
  flush();
290
293
  const level = heading[1].length;
291
- out.push(`<h${level}>${renderInline(heading[2])}</h${level}>`);
294
+ out.push(`<h${level}>${renderInline(heading[2], resolveImage)}</h${level}>`);
292
295
  index += 1;
293
296
  continue;
294
297
  }
@@ -305,7 +308,7 @@ function renderMarkdown(source) {
305
308
  quote.push(lines[index].trim().replace(/^>\s?/u, ""));
306
309
  index += 1;
307
310
  }
308
- out.push(`<blockquote>${quote.map((item) => renderInline(item)).join("<br>")}</blockquote>`);
311
+ out.push(`<blockquote>${quote.map((item) => renderInline(item, resolveImage)).join("<br>")}</blockquote>`);
309
312
  continue;
310
313
  }
311
314
  if (trimmed.startsWith("|") && index + 1 < lines.length && /^\|?[\s:|-]+\|?$/u.test(lines[index + 1].trim()) && lines[index + 1].includes("-")) {
@@ -321,7 +324,7 @@ function renderMarkdown(source) {
321
324
  }
322
325
  const head = rows.shift() ?? [];
323
326
  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>`
327
+ `<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
328
  );
326
329
  continue;
327
330
  }
@@ -335,7 +338,7 @@ function renderMarkdown(source) {
335
338
  out.push(`<${kind}>`);
336
339
  list = kind;
337
340
  }
338
- out.push(`<li>${renderInline((unordered ?? ordered)[1])}</li>`);
341
+ out.push(`<li>${renderInline((unordered ?? ordered)[1], resolveImage)}</li>`);
339
342
  index += 1;
340
343
  continue;
341
344
  }
@@ -346,8 +349,11 @@ function renderMarkdown(source) {
346
349
  flush();
347
350
  return out.join("\n");
348
351
  }
349
- function Markdown({ text }) {
350
- const html = (0, import_react.useMemo)(() => renderMarkdown(text), [text]);
352
+ function Markdown({
353
+ text,
354
+ resolveImage
355
+ }) {
356
+ const html = (0, import_react.useMemo)(() => renderMarkdown(text, resolveImage), [text, resolveImage]);
351
357
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-md", dangerouslySetInnerHTML: { __html: html } });
352
358
  }
353
359
  function Badges({ plugin }) {
@@ -425,6 +431,7 @@ function InstalledList({
425
431
  experimental ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5B9E\u9A8C\u6027" }) : null,
426
432
  bundle.optional ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u53EF\u9009" }) : null,
427
433
  bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
434
+ isVisibleBundle(bundle) ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u9690\u85CF" }),
428
435
  centerItems.length > 0 && !item ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" }) : null
429
436
  ] }),
430
437
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
@@ -450,10 +457,20 @@ function LocalDetailView({
450
457
  data,
451
458
  onBack,
452
459
  onOpenCenter,
453
- onUninstall
460
+ onUninstall,
461
+ onToggle
454
462
  }) {
455
463
  const bundle = data.bundle;
456
464
  const markdown = data.detail && data.detail.status === "found" ? data.detail.markdown : "";
465
+ const imageResolver = (src) => {
466
+ if (!data.detail || data.detail.status !== "found") return null;
467
+ const params = new URLSearchParams({
468
+ bundle: bundle.name,
469
+ document: data.detail.path,
470
+ path: src
471
+ });
472
+ return `/api/plugin-manager/detail-file?${params.toString()}`;
473
+ };
457
474
  const origin = data.detail && data.detail.status === "found" ? data.detail.path : "";
458
475
  const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
459
476
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-root", children: [
@@ -479,11 +496,18 @@ function LocalDetailView({
479
496
  bundle.source ? ` \xB7 ${bundle.source}` : ""
480
497
  ] }),
481
498
  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" }),
499
+ 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
500
  bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-danger", onClick: onUninstall, children: "\u5378\u8F7D" }) : null
483
501
  ] }),
484
502
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
485
503
  /* @__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" })
504
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
505
+ Markdown,
506
+ {
507
+ text: markdown || bundle.description || "\u8FD9\u4E2A\u63D2\u4EF6\u6CA1\u6709\u63D0\u4F9B README \u6216 locale \u8BE6\u60C5\u3002",
508
+ resolveImage: imageResolver
509
+ }
510
+ )
487
511
  ] }),
488
512
  origin ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "pcx-section", children: [
489
513
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: "pcx-h2", children: "\u8BE6\u60C5\u6765\u6E90" }),
@@ -499,6 +523,7 @@ function Panel() {
499
523
  const [total, setTotal] = (0, import_react.useState)(cached?.total ?? 0);
500
524
  const [scope, setScope] = (0, import_react.useState)(cached?.scope ?? "public");
501
525
  const [localFilter, setLocalFilter] = (0, import_react.useState)("all");
526
+ const [localShowHidden, setLocalShowHidden] = (0, import_react.useState)(false);
502
527
  const [category, setCategory] = (0, import_react.useState)(cached?.category ?? "");
503
528
  const [query, setQuery] = (0, import_react.useState)(cached?.query ?? "");
504
529
  const [draft, setDraft] = (0, import_react.useState)(cached?.draft ?? "");
@@ -1061,7 +1086,12 @@ function Panel() {
1061
1086
  setLocalDetail(null);
1062
1087
  void openDetail(name);
1063
1088
  } : void 0,
1064
- onUninstall: () => uninstallLocal(localDetail.bundle.name)
1089
+ onUninstall: () => uninstallLocal(localDetail.bundle.name),
1090
+ onToggle: () => {
1091
+ const { name, enabled } = localDetail.bundle;
1092
+ setLocalDetail(null);
1093
+ void toggleBundle(name, !enabled);
1094
+ }
1065
1095
  }
1066
1096
  ),
1067
1097
  dialog ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PromptDialog, { dialog, onClose: () => setDialog(null) }) : null
@@ -1334,7 +1364,9 @@ function Panel() {
1334
1364
  )
1335
1365
  ] }),
1336
1366
  scope === "installed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-chips", children: (() => {
1337
- const bundles = state?.bundles ?? [];
1367
+ const allBundles = state?.bundles ?? [];
1368
+ const bundles = localShowHidden ? allBundles : allBundles.filter(isVisibleBundle);
1369
+ const hiddenCount = allBundles.length - allBundles.filter(isVisibleBundle).length;
1338
1370
  const counts = {
1339
1371
  all: bundles.length,
1340
1372
  third: 0,
@@ -1357,21 +1389,32 @@ function Panel() {
1357
1389
  ["offered", "\u53EF\u5B89\u88C5"],
1358
1390
  ["disabled", "\u5DF2\u505C\u7528"]
1359
1391
  ];
1360
- return chips.map(
1361
- ([key, label]) => counts[key] ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1392
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1393
+ chips.map(
1394
+ ([key, label]) => counts[key] ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1395
+ "button",
1396
+ {
1397
+ className: `pcx-chip ${localFilter === key ? "pcx-chip-active" : ""}`,
1398
+ onClick: () => setLocalFilter(key),
1399
+ children: [
1400
+ label,
1401
+ " \xB7 ",
1402
+ counts[key]
1403
+ ]
1404
+ },
1405
+ key
1406
+ ) : null
1407
+ ),
1408
+ hiddenCount > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1362
1409
  "button",
1363
1410
  {
1364
- className: `pcx-chip ${localFilter === key ? "pcx-chip-active" : ""}`,
1365
- onClick: () => setLocalFilter(key),
1366
- children: [
1367
- label,
1368
- " \xB7 ",
1369
- counts[key]
1370
- ]
1371
- },
1372
- key
1411
+ className: `pcx-chip ${localShowHidden ? "pcx-chip-active" : ""}`,
1412
+ title: "DSH \u81EA\u5E26 Plugins \u9875\u9ED8\u8BA4\u4E0D\u663E\u793A\u7684\u5185\u90E8/\u9690\u85CF bundle",
1413
+ onClick: () => setLocalShowHidden((value) => !value),
1414
+ children: localShowHidden ? "\u9690\u85CF\u5185\u90E8\u9879" : `\u663E\u793A\u9690\u85CF\u9879 \xB7 ${hiddenCount}`
1415
+ }
1373
1416
  ) : null
1374
- );
1417
+ ] });
1375
1418
  })() }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-chips", children: [
1376
1419
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: `pcx-chip ${!category ? "pcx-chip-active" : ""}`, onClick: () => applyFilters({ category: "" }), children: "\u5168\u90E8" }),
1377
1420
  CATEGORIES.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -1387,7 +1430,7 @@ function Panel() {
1387
1430
  scope === "installed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1388
1431
  InstalledList,
1389
1432
  {
1390
- bundles: state?.bundles ?? state?.installed ?? [],
1433
+ bundles: localShowHidden ? state?.bundles ?? state?.installed ?? [] : (state?.bundles ?? state?.installed ?? []).filter(isVisibleBundle),
1391
1434
  centerItems: items,
1392
1435
  query,
1393
1436
  filter: localFilter,
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.51",
4
4
  "description": "小趣插件中心:浏览、安装、更新和发布远端插件中心的插件",
5
5
  "icon": "logo.svg",
6
6
  "type": "module",