@ququ-jiaxk/dsh-plugin-center 0.1.44 → 0.1.45

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.44" : "0.0.0";
39
+ var PLUGIN_VERSION = true ? "0.1.45" : "0.0.0";
40
40
  var PANEL_ID = "plugin-center";
41
41
  var inject = ["slots", "remote", "remote.pluginManager"];
42
42
  var hostCtx = null;
@@ -370,44 +370,63 @@ function InstalledList({
370
370
  centerItems,
371
371
  query,
372
372
  onOpen,
373
- onUninstall
373
+ onUninstall,
374
+ onToggle,
375
+ onInstall
374
376
  }) {
375
377
  const center = new Map(centerItems.map((item) => [item.packageName, item]));
376
378
  const keyword = query.trim().toLowerCase();
377
- const list = bundles.filter((bundle) => {
379
+ const list = bundles.filter((bundle) => bundle.listedByDefault !== false || bundle.enabled).filter((bundle) => {
378
380
  if (!keyword) return true;
379
381
  const display = center.get(bundle.name)?.displayName ?? "";
380
382
  return bundle.name.toLowerCase().includes(keyword) || display.toLowerCase().includes(keyword);
381
- });
383
+ }).sort((left, right) => Number(right.enabled) - Number(left.enabled) || left.name.localeCompare(right.name));
382
384
  if (list.length === 0) {
383
385
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-empty", children: [
384
386
  keyword ? "\u6CA1\u6709\u5339\u914D\u7684\u672C\u673A\u63D2\u4EF6" : "\u672C\u673A\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6",
385
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty-hint", children: "\u8FD9\u91CC\u5217\u51FA DSH \u63D2\u4EF6\u7BA1\u7406\u5668\u626B\u63CF\u5230\u7684\u672C\u673A\u63D2\u4EF6\uFF0C\u5305\u542B\u672A\u5728\u4E2D\u5FC3\u4E0A\u67B6\u7684" })
387
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-empty-hint", children: "\u8FD9\u91CC\u5217\u51FA DSH \u63D2\u4EF6\u7BA1\u7406\u5668\u626B\u63CF\u5230\u7684\u672C\u673A\u63D2\u4EF6\uFF0C\u5305\u542B\u5185\u7F6E\u3001\u5B9E\u9A8C\u6027\u548C\u672A\u5728\u4E2D\u5FC3\u4E0A\u67B6\u7684" })
386
388
  ] });
387
389
  }
388
390
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-grid", children: list.map((bundle) => {
389
391
  const item = center.get(bundle.name);
392
+ const missing = bundle.availability === "missing";
390
393
  const localInstall = !bundle.source || /(?:^|[^a-z0-9])(?:file|link):/iu.test(bundle.source);
394
+ const experimental = bundle.name.includes("experimental") || Boolean(bundle.optional);
391
395
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "pcx-card", children: [
392
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-main", onClick: () => onOpen(bundle.name), children: [
393
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-top", children: [
394
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(item?.displayName ?? bundle.name) }),
395
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
396
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
397
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
398
- /* @__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" }),
399
- bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
400
- item ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" })
396
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
397
+ "div",
398
+ {
399
+ className: "pcx-card-main",
400
+ style: missing ? { cursor: "default" } : void 0,
401
+ onClick: missing ? void 0 : () => onOpen(bundle.name),
402
+ children: [
403
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-top", children: [
404
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-icon", children: iconLetter(item?.displayName ?? bundle.name) }),
405
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-titles", children: [
406
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-row", children: [
407
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-name", children: item?.displayName ?? bundle.name }),
408
+ 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" }),
409
+ bundle.availability === "installation" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5185\u7F6E" }) : null,
410
+ experimental ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u5B9E\u9A8C\u6027" }) : null,
411
+ bundle.optional ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u53EF\u9009" }) : null,
412
+ bundle.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge pcx-badge-danger", children: "\u8BFB\u53D6\u5F02\u5E38" }) : null,
413
+ item ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-badge", children: "\u672A\u4E0A\u67B6" })
414
+ ] }),
415
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
416
+ ] })
401
417
  ] }),
402
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pcx-pkg", children: bundle.name })
403
- ] })
404
- ] }),
405
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-foot", children: [
406
- /* @__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" }),
407
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pcx-foot-meta", children: bundle.version ? `v${bundle.version}` : "\u7248\u672C\u672A\u77E5" })
408
- ] })
409
- ] }),
410
- 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
418
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-foot", children: [
419
+ /* @__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" }),
420
+ /* @__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" })
421
+ ] })
422
+ ]
423
+ }
424
+ ),
425
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pcx-card-actions", children: [
426
+ missing && bundle.installTarget ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-primary pcx-btn-sm", onClick: () => onInstall(bundle.name), children: "\u5B89\u88C5" }) : null,
427
+ !missing && bundle.name !== "@ququ-jiaxk/dsh-plugin-center" && (bundle.optional || bundle.installed) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-sm", onClick: () => onToggle(bundle.name, !bundle.enabled), children: bundle.enabled ? "\u505C\u7528" : "\u542F\u7528" }) : null,
428
+ bundle.removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { className: "pcx-btn pcx-btn-sm pcx-btn-danger", onClick: () => onUninstall(bundle.name), children: "\u5378\u8F7D" }) : null
429
+ ] })
411
430
  ] }, bundle.name);
412
431
  }) });
413
432
  }
@@ -782,6 +801,27 @@ function Panel() {
782
801
  }
783
802
  });
784
803
  }
804
+ async function toggleBundle(packageName, enabled) {
805
+ setError("");
806
+ try {
807
+ await api("/bundle-enabled", { method: "POST", body: { name: packageName, enabled } });
808
+ setNotice(`${enabled ? "\u5DF2\u542F\u7528" : "\u5DF2\u505C\u7528"} ${packageName}`);
809
+ await load(scope, category, query);
810
+ } catch (err) {
811
+ setError(err.message);
812
+ }
813
+ }
814
+ async function installDshBundle(packageName) {
815
+ setError("");
816
+ setNotice(`\u6B63\u5728\u5B89\u88C5 ${packageName}\u2026`);
817
+ try {
818
+ await api("/bundle-install", { method: "POST", body: { name: packageName } });
819
+ setNotice(`\u5DF2\u5B89\u88C5 ${packageName}`);
820
+ await load(scope, category, query);
821
+ } catch (err) {
822
+ setError(err.message);
823
+ }
824
+ }
785
825
  async function install(packageName, version) {
786
826
  setNotice(`\u6B63\u5728\u5B89\u88C5 ${packageName}${version ? `@${version}` : ""}\u2026`);
787
827
  setError("");
@@ -1244,11 +1284,11 @@ function Panel() {
1244
1284
  "button",
1245
1285
  {
1246
1286
  className: `pcx-tab ${scope === "installed" ? "pcx-tab-active" : ""}`,
1247
- title: "\u626B\u63CF\u672C\u673A DSH \u5DF2\u5B89\u88C5\u7684\u63D2\u4EF6\uFF08\u542B\u672A\u5728\u4E2D\u5FC3\u4E0A\u67B6\u7684\uFF09",
1287
+ title: "\u626B\u63CF\u672C\u673A DSH \u7684\u63D2\u4EF6\uFF1A\u5185\u7F6E\u3001\u5B9E\u9A8C\u6027\u3001\u53EF\u9009\u4E0E\u5DF2\u5B89\u88C5\u7684\u7B2C\u4E09\u65B9\u63D2\u4EF6",
1248
1288
  onClick: () => applyFilters({ scope: "installed" }),
1249
1289
  children: [
1250
- "\u5DF2\u88C5",
1251
- state?.installed?.length ? ` \xB7 ${state.installed.length}` : ""
1290
+ "\u672C\u673A",
1291
+ state?.bundles?.length ? ` \xB7 ${state.bundles.length}` : ""
1252
1292
  ]
1253
1293
  }
1254
1294
  )
@@ -1291,14 +1331,16 @@ function Panel() {
1291
1331
  scope === "installed" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1292
1332
  InstalledList,
1293
1333
  {
1294
- bundles: state?.installed ?? [],
1334
+ bundles: state?.bundles ?? state?.installed ?? [],
1295
1335
  centerItems: items,
1296
1336
  query,
1297
1337
  onOpen: (name) => {
1298
1338
  if (items.some((plugin) => plugin.packageName === name)) void openDetail(name);
1299
1339
  else void openLocalDetail(name);
1300
1340
  },
1301
- onUninstall: uninstallLocal
1341
+ onUninstall: uninstallLocal,
1342
+ onToggle: (name, enabled) => void toggleBundle(name, enabled),
1343
+ onInstall: (name) => void installDshBundle(name)
1302
1344
  }
1303
1345
  ) : 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: [
1304
1346
  scope === "mine" ? "\u4F60\u8FD8\u6CA1\u6709\u4E0A\u4F20\u8FC7\u63D2\u4EF6" : "\u6CA1\u6709\u627E\u5230\u63D2\u4EF6",
package/lib/index.js CHANGED
@@ -384,10 +384,11 @@ export function apply(ctx) {
384
384
  source: null,
385
385
  }
386
386
  const manager = ctx.get('pluginManager')
387
+ let bundles = []
387
388
  if (manager) {
388
389
  try {
389
- const bundles = await manager.listBundles()
390
- installed = bundles
390
+ const list = await manager.listBundles()
391
+ installed = list
391
392
  .filter((bundle) => bundle.installed)
392
393
  .map((bundle) => ({
393
394
  name: bundle.name,
@@ -399,7 +400,24 @@ export function apply(ctx) {
399
400
  source: bundle.source ?? null,
400
401
  error: bundle.error?.code ?? null,
401
402
  }))
402
- const own = bundles.find((bundle) => bundle.name === SELF_PACKAGE)
403
+ // DSH 内置 / 实验性 / 可选 bundle 不一定在 profile 依赖里(availability: installation),
404
+ // 单独给一份完整清单,供「本机」视图展示和启用。
405
+ bundles = list.map((bundle) => ({
406
+ name: bundle.name,
407
+ version: bundle.version ?? null,
408
+ enabled: bundle.enabled,
409
+ installed: Boolean(bundle.installed),
410
+ availability: bundle.availability ?? null,
411
+ official: Boolean(bundle.official),
412
+ optional: Boolean(bundle.optional),
413
+ removable: Boolean(bundle.removable),
414
+ source: bundle.source ?? null,
415
+ error: bundle.error?.code ?? null,
416
+ description: bundle.description ?? null,
417
+ listedByDefault: bundle.listedByDefault !== false,
418
+ installTarget: bundle.installTarget ?? null,
419
+ }))
420
+ const own = list.find((bundle) => bundle.name === SELF_PACKAGE)
403
421
  if (own) {
404
422
  self = {
405
423
  name: own.name,
@@ -423,12 +441,63 @@ export function apply(ctx) {
423
441
  hostVersion: HOST_VERSION,
424
442
  user,
425
443
  installed,
444
+ bundles,
426
445
  self,
427
446
  selfUpdate: readSelfUpdateRecord(),
428
447
  selfUpdateSupported: selfUpdateCapability(manager).supported,
429
448
  })
430
449
  }
431
450
 
451
+ // 启用/停用本机 bundle(含 DSH 内置、实验性、可选插件)。
452
+ if (req.method === 'POST' && path === '/bundle-enabled') {
453
+ const body = await readJson(req)
454
+ const name = String(body.name ?? '')
455
+ if (!name) return send(res, 400, { error: '缺少 name 参数' })
456
+ const manager = ctx.get('pluginManager')
457
+ if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用' })
458
+ if (typeof manager.setBundleEnabled !== 'function') {
459
+ return send(res, 409, { error: '当前 DSH 版本不支持启用/停用 bundle' })
460
+ }
461
+
462
+ const result = await manager.setBundleEnabled(name, Boolean(body.enabled))
463
+ if (result?.error) {
464
+ const detail =
465
+ typeof result.error === 'string' ? result.error : (result.error.message ?? result.error.code)
466
+ return send(res, 400, { error: detail ?? '操作失败', code: result.error.code ?? null })
467
+ }
468
+ logInstall(`bundle-enabled name=${name} enabled=${Boolean(body.enabled)}`)
469
+ return send(res, 200, {
470
+ ok: true,
471
+ name,
472
+ enabled: Boolean(body.enabled),
473
+ application: result?.application ?? null,
474
+ })
475
+ }
476
+
477
+ // 安装 DSH 自带的可选 / 实验性 bundle(listBundles 里带 installTarget 的条目)。
478
+ if (req.method === 'POST' && path === '/bundle-install') {
479
+ const body = await readJson(req)
480
+ const name = String(body.name ?? '')
481
+ if (!name) return send(res, 400, { error: '缺少 name 参数' })
482
+ const manager = ctx.get('pluginManager')
483
+ if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用' })
484
+
485
+ const list = await manager.listBundles()
486
+ const bundle = list.find((item) => item.name === name)
487
+ if (!bundle) return send(res, 404, { error: `没有找到 ${name}` })
488
+ const spec = bundle.installTarget?.spec
489
+ if (!spec) return send(res, 400, { error: '该插件没有可用的安装来源(不是 DSH 自带的可选插件)' })
490
+
491
+ const result = await manager.installBundle(spec, { enabled: true })
492
+ if (result?.error) {
493
+ const detail =
494
+ typeof result.error === 'string' ? result.error : (result.error.message ?? result.error.code)
495
+ return send(res, 400, { error: detail ?? '安装失败', code: result.error.code ?? null })
496
+ }
497
+ logInstall(`bundle-install name=${name} spec=${spec}`)
498
+ return send(res, 200, { ok: true, name, version: result?.version ?? bundle.installTarget?.version ?? null })
499
+ }
500
+
432
501
  if (req.method === 'GET' && path === '/self/update-check') {
433
502
  const manager = ctx.get('pluginManager')
434
503
  if (!manager) return send(res, 503, { error: 'DSH 插件管理器不可用(当前不是 profile 模式)' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-plugin-center",
3
- "version": "0.1.44",
3
+ "version": "0.1.45",
4
4
  "description": "小趣插件中心:浏览、安装、更新和发布远端插件中心的插件",
5
5
  "icon": "logo.svg",
6
6
  "type": "module",