@snap-rail/ui 0.1.0 → 0.1.1

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/settings.js CHANGED
@@ -8,13 +8,14 @@ import "@radix-ui/react-select";
8
8
  import * as SwitchPrimitive from "@radix-ui/react-switch";
9
9
  import * as TabsPrimitive from "@radix-ui/react-tabs";
10
10
  import * as DialogPrimitive from "@radix-ui/react-dialog";
11
- import { rpcErrorText, subscribeFrame } from "@snap-rail/connection";
12
- import { settingsChangedSchema } from "@snap-rail/station-rpc/contract";
11
+ import { rpcErrorText } from "@snap-rail/connection";
12
+ import "@snap-rail/client-kernel";
13
+ import "@snap-rail/station-rpc/contract";
13
14
  import "@snap-rail/cordis";
14
15
  import "@snap-rail/cordis-plugin-timer";
15
16
  import "@snap-rail/shell/contract";
16
17
  import "react-dom/client";
17
- import "@snap-rail/app-boot/contract";
18
+ import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
18
19
  //#region lib/types/utils.js
19
20
  /**
20
21
  * Small helpers shared by the headless semantic components: class merging and
@@ -135,7 +136,7 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
135
136
  /** The dialog root. */
136
137
  const Dialog = DialogPrimitive.Root;
137
138
  /** The portalled dialog content. */
138
- function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true }) {
139
+ function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
139
140
  const resolved = presentation === "auto" ? "modal" : presentation;
140
141
  return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
141
142
  ...part("dialog", "overlay"),
@@ -145,6 +146,7 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
145
146
  className: cn("snap-dialog-panel", className),
146
147
  "data-presentation": resolved,
147
148
  "data-size": size,
149
+ ...rest,
148
150
  children: [children, showClose && jsx(DialogPrimitive.Close, {
149
151
  ...part("dialog", "close"),
150
152
  className: "snap-dialog-close",
@@ -153,6 +155,14 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
153
155
  })]
154
156
  })] });
155
157
  }
158
+ /** The dialog header. */
159
+ function DialogHeader({ children, className }) {
160
+ return jsx("div", {
161
+ ...part("dialog", "header"),
162
+ className: cn("snap-dialog-header", className),
163
+ children
164
+ });
165
+ }
156
166
  /** The dialog title. */
157
167
  function DialogTitle({ children, className }) {
158
168
  return jsx(DialogPrimitive.Title, {
@@ -161,6 +171,30 @@ function DialogTitle({ children, className }) {
161
171
  children
162
172
  });
163
173
  }
174
+ /** The dialog description. */
175
+ function DialogDescription({ children, className }) {
176
+ return jsx(DialogPrimitive.Description, {
177
+ ...part("dialog", "description"),
178
+ className: cn("snap-dialog-description", className),
179
+ children
180
+ });
181
+ }
182
+ /** The dialog body. */
183
+ function DialogBody({ children, className }) {
184
+ return jsx("div", {
185
+ ...part("dialog", "body"),
186
+ className: cn("snap-dialog-body", className),
187
+ children
188
+ });
189
+ }
190
+ /** The dialog footer. */
191
+ function DialogFooter({ children, className }) {
192
+ return jsx("div", {
193
+ ...part("dialog", "footer"),
194
+ className: cn("snap-dialog-footer", className),
195
+ children
196
+ });
197
+ }
164
198
  //#endregion
165
199
  //#region lib/types/components/controls.js
166
200
  /** The tabs root. */
@@ -238,6 +272,46 @@ function EmptyState({ title, description, icon, action, className }) {
238
272
  });
239
273
  }
240
274
  //#endregion
275
+ //#region lib/types/components/input.js
276
+ /** A single-line text field with semantic prefix/suffix slots. Layout
277
+ * `style`/`className` dress the wrapper — the visible control; the native
278
+ * field already stretches inside it. */
279
+ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, style, disabled, ...props }) {
280
+ return jsxs("div", {
281
+ ...part(componentName, "root"),
282
+ className: cn("snap-input", className),
283
+ style,
284
+ "data-size": size,
285
+ "data-invalid": invalid || void 0,
286
+ "data-disabled": disabled === true || void 0,
287
+ children: [
288
+ prefix !== void 0 && jsx("span", {
289
+ ...part(componentName, "prefix"),
290
+ children: prefix
291
+ }),
292
+ jsx("input", {
293
+ ...part(componentName, "field"),
294
+ className: "snap-input-field",
295
+ disabled,
296
+ "aria-invalid": invalid || void 0,
297
+ ...props
298
+ }),
299
+ onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
300
+ ...part(componentName, "clear"),
301
+ type: "button",
302
+ className: "snap-input-clear",
303
+ "aria-label": "清除",
304
+ onClick: onClear,
305
+ children: "×"
306
+ }),
307
+ suffix !== void 0 && jsx("span", {
308
+ ...part(componentName, "suffix"),
309
+ children: suffix
310
+ })
311
+ ]
312
+ });
313
+ }
314
+ //#endregion
241
315
  //#region lib/types/components/layout.js
242
316
  /** A vertical flow. */
243
317
  function Stack({ gap = "md", padding, align, className, style, children }) {
@@ -274,7 +348,7 @@ function Row({ gap = "sm", padding, align, justify, wrap = false, className, sty
274
348
  });
275
349
  }
276
350
  /** A page body with its own header/actions anatomy. */
277
- function Page({ header, actions, title, description, className, style, children }) {
351
+ function Page({ header, actions, title, titleExtra, description, className, style, children }) {
278
352
  return jsxs("div", {
279
353
  ...part("page", "root"),
280
354
  className: cn("snap-page", className),
@@ -300,9 +374,19 @@ function Page({ header, actions, title, description, className, style, children
300
374
  justifyContent: "space-between",
301
375
  gap: space("md")
302
376
  },
303
- children: [title !== void 0 && jsx("div", {
304
- ...part("page", "title"),
305
- children: title
377
+ children: [jsxs("div", {
378
+ style: {
379
+ display: "flex",
380
+ alignItems: "center",
381
+ gap: space("sm")
382
+ },
383
+ children: [title !== void 0 && jsx("div", {
384
+ ...part("page", "title"),
385
+ children: title
386
+ }), titleExtra !== void 0 && jsx("div", {
387
+ ...part("page", "title-extra"),
388
+ children: titleExtra
389
+ })]
306
390
  }), actions !== void 0 && jsx("div", {
307
391
  ...part("page", "actions"),
308
392
  children: actions
@@ -440,7 +524,22 @@ const UI_SLOT_IDS = {
440
524
  settingsSurface: "settings.surface"
441
525
  };
442
526
  UI_SLOT_IDS.layout, UI_SLOT_IDS.titlebar, UI_SLOT_IDS.titlebarActions, UI_SLOT_IDS.sidebar, UI_SLOT_IDS.statusbar, UI_SLOT_IDS.overlay, UI_SLOT_IDS.ball, UI_SLOT_IDS.settingsEntry, UI_SLOT_IDS.settingsSurface;
443
- createContext(null);
527
+ //#endregion
528
+ //#region lib/types/skins.js
529
+ /** The React context carrying the skin service. */
530
+ const SkinsContext = createContext(null);
531
+ /** Read the skin service. */
532
+ function useSkins() {
533
+ const service = useContext(SkinsContext);
534
+ if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
535
+ return service;
536
+ }
537
+ /** Re-render on theme changes and return the active theme id. */
538
+ function useSkinId() {
539
+ const service = useSkins();
540
+ useSyncExternalStore(service.subscribe, service.version, service.version);
541
+ return service.active().id;
542
+ }
444
543
  createContext(null);
445
544
  //#endregion
446
545
  //#region lib/types/runtime.js
@@ -501,24 +600,21 @@ async function writeSetting(link, key, value) {
501
600
  /** The appearance/display page. */
502
601
  function AppearancePage() {
503
602
  const { link } = useClient();
504
- const [mode, setMode] = useState("dark");
603
+ const skins = useSkins();
604
+ const activeId = useSkinId();
605
+ const [packages, setPackages] = useState([]);
505
606
  const [windowPreset, setWindowPreset] = useState(void 0);
506
607
  const [ballSize, setBallSize] = useState(128);
507
608
  const [ballEnabled, setBallEnabled] = useState(true);
508
- const [ballDockable, setBallDockable] = useState(true);
509
609
  const [ballCollapse, setBallCollapse] = useState(true);
510
- const [skins, setSkins] = useState([]);
511
610
  const [error, setError] = useState(void 0);
512
611
  const [busy, setBusy] = useState(false);
513
612
  useEffect(() => {
514
613
  Promise.all([
515
- readSetting(link, THEME_KEY),
516
614
  readSetting(link, WINDOW_KEY),
517
615
  readSetting(link, BALL_KEY),
518
616
  link.call("plugins.list", {})
519
- ]).then(([theme, windowRow, ballRow, plugins]) => {
520
- const themeMode = theme?.mode;
521
- if (themeMode === "system" || themeMode === "light" || themeMode === "dark") setMode(themeMode);
617
+ ]).then(([windowRow, ballRow, plugins]) => {
522
618
  const windowProfile = windowRow;
523
619
  if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
524
620
  const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
@@ -527,9 +623,8 @@ function AppearancePage() {
527
623
  const ballProfile = ballRow;
528
624
  if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
529
625
  if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
530
- if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.dockable === "boolean") setBallDockable(ballProfile.dockable);
531
626
  if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
532
- if (plugins.ok) setSkins(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
627
+ if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
533
628
  name: plugin.packageName,
534
629
  title: plugin.title ?? plugin.packageName,
535
630
  enabled: plugin.enabled
@@ -537,19 +632,7 @@ function AppearancePage() {
537
632
  }).catch((cause) => {
538
633
  setError(cause instanceof Error ? cause.message : String(cause));
539
634
  });
540
- return subscribeFrame(link, "settings/changed", settingsChangedSchema, (change) => {
541
- if (change.key === THEME_KEY) {
542
- const next = change.value?.mode;
543
- if (next === "system" || next === "light" || next === "dark") setMode(next);
544
- }
545
- });
546
635
  }, [link]);
547
- const saveTheme = (next) => {
548
- setMode(next);
549
- writeSetting(link, THEME_KEY, { mode: next }).catch((cause) => {
550
- setError(cause instanceof Error ? cause.message : String(cause));
551
- });
552
- };
553
636
  const saveWindow = (width, height, label) => {
554
637
  setWindowPreset(label);
555
638
  writeSetting(link, WINDOW_KEY, {
@@ -571,31 +654,45 @@ function AppearancePage() {
571
654
  const next = {
572
655
  size: patch.size ?? ballSize,
573
656
  enabled: patch.enabled ?? ballEnabled,
574
- dockable: patch.dockable ?? ballDockable,
575
657
  collapse: patch.collapse ?? ballCollapse
576
658
  };
577
659
  if (patch.size !== void 0) setBallSize(patch.size);
578
660
  if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
579
- if (patch.dockable !== void 0) setBallDockable(patch.dockable);
580
661
  if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
581
662
  writeSetting(link, BALL_KEY, next).catch((cause) => {
582
663
  setError(cause instanceof Error ? cause.message : String(cause));
583
664
  });
584
665
  };
585
- const toggleSkin = (skin) => {
666
+ const tabs = [...skins.list().map((row) => ({
667
+ id: row.id,
668
+ title: row.title
669
+ })), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
670
+ id: pkg.name,
671
+ title: pkg.title,
672
+ enable: pkg.name
673
+ }))];
674
+ const selectTheme = (tab) => {
675
+ if (busy) return;
676
+ if (tab.enable === void 0) {
677
+ writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
678
+ setError(cause instanceof Error ? cause.message : String(cause));
679
+ });
680
+ return;
681
+ }
586
682
  setBusy(true);
587
683
  link.call("plugins.set-enabled", {
588
- name: skin.name,
589
- enabled: !skin.enabled
684
+ name: tab.enable,
685
+ enabled: true
590
686
  }).then((result) => {
591
687
  if (!result.ok) {
592
688
  setError(rpcErrorText(result.error));
593
689
  return;
594
690
  }
595
- setSkins((current) => current.map((item) => item.name === skin.name ? {
596
- ...item,
597
- enabled: !item.enabled
598
- } : item));
691
+ setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
692
+ ...pkg,
693
+ enabled: true
694
+ } : pkg));
695
+ return writeSetting(link, THEME_KEY, { id: tab.id });
599
696
  }).catch((cause) => {
600
697
  setError(cause instanceof Error ? cause.message : String(cause));
601
698
  }).finally(() => {
@@ -604,7 +701,7 @@ function AppearancePage() {
604
701
  };
605
702
  return jsx(Page, {
606
703
  title: "外观与显示",
607
- description: "主题、皮肤、主窗口尺寸和悬浮球外观;保存后立即生效。",
704
+ description: "主题、主窗口尺寸和悬浮球外观。",
608
705
  children: jsxs(Stack, {
609
706
  gap: "lg",
610
707
  children: [
@@ -614,73 +711,25 @@ function AppearancePage() {
614
711
  children: error
615
712
  }),
616
713
  jsx(Section, {
617
- title: "主题模式",
714
+ title: "主题",
618
715
  children: jsx(Tabs, {
619
- value: mode,
620
- onValueChange: (value) => saveTheme(value),
621
- children: jsxs(TabsList, {
622
- "aria-label": "主题模式",
623
- children: [
624
- jsx(TabsTrigger, {
625
- value: "system",
626
- children: "跟随系统"
627
- }),
628
- jsx(TabsTrigger, {
629
- value: "light",
630
- children: "白天"
631
- }),
632
- jsx(TabsTrigger, {
633
- value: "dark",
634
- children: "黑夜"
635
- })
636
- ]
716
+ value: activeId,
717
+ onValueChange: (value) => {
718
+ const tab = tabs.find((item) => item.id === value);
719
+ if (tab !== void 0) selectTheme(tab);
720
+ },
721
+ children: jsx(TabsList, {
722
+ "aria-label": "主题",
723
+ children: tabs.map((tab) => jsx(TabsTrigger, {
724
+ value: tab.id,
725
+ disabled: busy,
726
+ children: tab.title
727
+ }, tab.id))
637
728
  })
638
729
  })
639
730
  }),
640
- jsx(Section, {
641
- title: "界面皮肤",
642
- description: "皮肤由独立插件提供;启用后需要重启终端。",
643
- children: jsxs(Stack, {
644
- gap: "sm",
645
- children: [jsxs(Row, {
646
- gap: "sm",
647
- align: "center",
648
- children: [jsx(Badge, {
649
- intent: "success",
650
- children: "默认(内置)"
651
- }), jsx("span", {
652
- style: {
653
- color: "var(--snap-color-muted)",
654
- fontSize: "var(--snap-text-sm)"
655
- },
656
- children: "工业钴蓝,始终可用"
657
- })]
658
- }), skins.length === 0 ? jsx("span", {
659
- style: { color: "var(--snap-color-muted)" },
660
- children: "尚未安装其他皮肤插件。"
661
- }) : skins.map((skin) => jsxs(Row, {
662
- gap: "sm",
663
- align: "center",
664
- children: [
665
- jsx("span", { children: skin.title }),
666
- jsx(Badge, {
667
- intent: skin.enabled ? "success" : "neutral",
668
- children: skin.enabled ? "已启用" : "未启用"
669
- }),
670
- jsx(Button, {
671
- size: "sm",
672
- emphasis: "outline",
673
- disabled: busy,
674
- onClick: () => toggleSkin(skin),
675
- children: skin.enabled ? "停用" : "启用"
676
- })
677
- ]
678
- }, skin.name))]
679
- })
680
- }),
681
731
  jsx(Section, {
682
732
  title: "主窗口",
683
- description: "布局/套件会声明推荐尺寸;这里的选择会覆盖布局推荐。",
684
733
  children: jsxs(Stack, {
685
734
  gap: "sm",
686
735
  children: [jsxs(Row, {
@@ -709,7 +758,7 @@ function AppearancePage() {
709
758
  }),
710
759
  jsx(Section, {
711
760
  title: "悬浮球",
712
- description: "球面尺寸与停泊行为;球内显示内容由业务套件决定。",
761
+ description: "球面尺寸与停泊行为。",
713
762
  children: jsxs(Stack, {
714
763
  gap: "md",
715
764
  children: [jsx(Row, {
@@ -727,23 +776,15 @@ function AppearancePage() {
727
776
  gap: "lg",
728
777
  wrap: true,
729
778
  align: "center",
730
- children: [
731
- jsx(Switch, {
732
- label: "启用悬浮球",
733
- checked: ballEnabled,
734
- onCheckedChange: (enabled) => saveBall({ enabled })
735
- }),
736
- jsx(Switch, {
737
- label: "允许贴边",
738
- checked: ballDockable,
739
- onCheckedChange: (dockable) => saveBall({ dockable })
740
- }),
741
- jsx(Switch, {
742
- label: "贴边后收起",
743
- checked: ballCollapse,
744
- onCheckedChange: (collapse) => saveBall({ collapse })
745
- })
746
- ]
779
+ children: [jsx(Switch, {
780
+ label: "启用悬浮球",
781
+ checked: ballEnabled,
782
+ onCheckedChange: (enabled) => saveBall({ enabled })
783
+ }), jsx(Switch, {
784
+ label: "允许贴边收起",
785
+ checked: ballCollapse,
786
+ onCheckedChange: (collapse) => saveBall({ collapse })
787
+ })]
747
788
  })]
748
789
  })
749
790
  })
@@ -752,7 +793,157 @@ function AppearancePage() {
752
793
  });
753
794
  }
754
795
  //#endregion
796
+ //#region lib/types/settings-pages/plugin-feed.js
797
+ /** The feed-source editor dialog; the open state lives with the opener. */
798
+ function PluginFeedDialog(props) {
799
+ const { open } = props;
800
+ const link = props.ctx.client.link;
801
+ const [urls, setUrls] = useState([]);
802
+ const [draft, setDraft] = useState("");
803
+ const [error, setError] = useState(void 0);
804
+ useEffect(() => {
805
+ if (!open) return;
806
+ link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
807
+ if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
808
+ }).catch(() => void 0);
809
+ }, [open, link]);
810
+ const save = () => {
811
+ for (const url of urls) try {
812
+ const parsed = new URL(url);
813
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
814
+ } catch {
815
+ setError("插件源地址需要以 http(s) 开头");
816
+ return;
817
+ }
818
+ setError(void 0);
819
+ link.call("settings.set", {
820
+ key: PLUGINS_FEED_URLS_KEY,
821
+ value: urls
822
+ }).then((result) => {
823
+ if (!result.ok) {
824
+ setError(rpcErrorText(result.error));
825
+ return;
826
+ }
827
+ props.onOpenChange(false);
828
+ }).catch((cause) => setError(String(cause)));
829
+ };
830
+ const append = () => {
831
+ const value = draft.trim();
832
+ if (value === "") return;
833
+ try {
834
+ const parsed = new URL(value);
835
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
836
+ } catch {
837
+ setError("请填写 http(s) 开头的插件源地址");
838
+ return;
839
+ }
840
+ setError(void 0);
841
+ setDraft("");
842
+ setUrls((current) => current.includes(value) ? current : [...current, value]);
843
+ };
844
+ return jsx(Dialog, {
845
+ open,
846
+ onOpenChange: props.onOpenChange,
847
+ children: jsxs(DialogContent, {
848
+ presentation: "modal",
849
+ "aria-describedby": void 0,
850
+ children: [
851
+ jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
852
+ jsx(DialogBody, { children: jsxs(Stack, {
853
+ gap: "sm",
854
+ children: [
855
+ urls.length === 0 && jsx("div", {
856
+ style: {
857
+ fontSize: "var(--snap-text-xs)",
858
+ color: "var(--snap-color-muted)"
859
+ },
860
+ children: "尚未添加自定义源(当前使用出厂默认源)。"
861
+ }),
862
+ urls.map((url, index) => jsxs("div", {
863
+ style: {
864
+ display: "flex",
865
+ gap: "var(--snap-space-sm)",
866
+ alignItems: "center"
867
+ },
868
+ children: [jsx("span", {
869
+ style: {
870
+ flex: 1,
871
+ minWidth: 0,
872
+ overflow: "hidden",
873
+ textOverflow: "ellipsis",
874
+ whiteSpace: "nowrap",
875
+ fontSize: "var(--snap-text-xs)"
876
+ },
877
+ children: url
878
+ }), jsx(Button, {
879
+ intent: "neutral",
880
+ emphasis: "ghost",
881
+ size: "sm",
882
+ "aria-label": `移除 ${url}`,
883
+ onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
884
+ children: "✕"
885
+ })]
886
+ }, url)),
887
+ jsxs("div", {
888
+ style: {
889
+ display: "flex",
890
+ gap: "var(--snap-space-sm)",
891
+ width: "100%"
892
+ },
893
+ children: [jsx(Input, {
894
+ value: draft,
895
+ placeholder: "https://…",
896
+ style: {
897
+ flex: 1,
898
+ minWidth: 0
899
+ },
900
+ onChange: (event) => setDraft(event.target.value),
901
+ onKeyDown: (event) => {
902
+ if (event.key === "Enter") append();
903
+ }
904
+ }), jsx(Button, {
905
+ intent: "neutral",
906
+ emphasis: "outline",
907
+ onClick: append,
908
+ children: "添加源"
909
+ })]
910
+ }),
911
+ error !== void 0 && jsx("div", {
912
+ role: "alert",
913
+ style: {
914
+ color: "var(--snap-color-danger)",
915
+ fontSize: "var(--snap-text-sm)"
916
+ },
917
+ children: error
918
+ })
919
+ ]
920
+ }) }),
921
+ jsxs(DialogFooter, { children: [jsx(Button, {
922
+ intent: "neutral",
923
+ emphasis: "outline",
924
+ onClick: () => props.onOpenChange(false),
925
+ children: "取消"
926
+ }), jsx(Button, {
927
+ intent: "primary",
928
+ "data-plugins-feed-save": true,
929
+ onClick: save,
930
+ children: "保存"
931
+ })] })
932
+ ]
933
+ })
934
+ });
935
+ }
936
+ //#endregion
755
937
  //#region lib/types/settings-pages/plugins.js
938
+ /** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
939
+ * Electron or in tests. Inlined rather than imported from the app-internal
940
+ * kernel package: it never ships in the installer, and the packaged-app gate
941
+ * refuses any shipped `@snap-rail/ui` lib that requires it. */
942
+ function droppedZipPath(file) {
943
+ const zipPathOf = globalThis.snapRail?.zipPathOf;
944
+ if (typeof zipPathOf !== "function") return null;
945
+ return zipPathOf(file);
946
+ }
756
947
  /** Human labels for the package kinds. */
757
948
  const KIND_LABELS = {
758
949
  skin: "界面风格",
@@ -765,6 +956,22 @@ const PROFILE_LABELS = {
765
956
  integrated: "图表桥接",
766
957
  custom: "自定义界面"
767
958
  };
959
+ /** Search rows shown before the tail is folded into a counter. */
960
+ const SEARCH_ROW_CAP = 20;
961
+ /** The plus glyph for the page's install entry. */
962
+ function PlusIcon() {
963
+ return jsx("svg", {
964
+ viewBox: "0 0 24 24",
965
+ width: "18",
966
+ height: "18",
967
+ fill: "none",
968
+ stroke: "currentColor",
969
+ strokeWidth: "2.4",
970
+ strokeLinecap: "round",
971
+ "aria-hidden": "true",
972
+ children: jsx("path", { d: "M12 5v14M5 12h14" })
973
+ });
974
+ }
768
975
  /** Collapse entry rows into package rows (one master switch per package). */
769
976
  function packageRows(plugins) {
770
977
  const byPackage = /* @__PURE__ */ new Map();
@@ -790,15 +997,44 @@ function packageRows(plugins) {
790
997
  }
791
998
  return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
792
999
  }
1000
+ /** The preview's signature line (one row in the confirm card). */
1001
+ function signatureText(signature, viaUrl) {
1002
+ if (signature.state === "verified") return {
1003
+ text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
1004
+ warning: false
1005
+ };
1006
+ const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
1007
+ return {
1008
+ text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
1009
+ warning: true
1010
+ };
1011
+ }
1012
+ /** Does the input name an http(s) address? */
1013
+ const isHttpUrl = (text) => /^https?:\/\//i.test(text);
1014
+ /** Does the input look like a filesystem path (drive letter, UNC, posix
1015
+ * root, or a .zip name with a separator in it)? */
1016
+ const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
793
1017
  /** The plugin management page. */
794
1018
  function PluginsPage({ ctx }) {
795
1019
  const [rows, setRows] = useState([]);
796
1020
  const [error, setError] = useState(void 0);
797
1021
  const [busy, setBusy] = useState(void 0);
798
1022
  const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
1023
+ const [restartNeeded, setRestartNeeded] = useState(false);
1024
+ const [installOpen, setInstallOpen] = useState(false);
1025
+ const [phase, setPhase] = useState({ kind: "idle" });
1026
+ const [message, setMessage] = useState(void 0);
1027
+ const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
1028
+ const [updatingName, setUpdatingName] = useState(void 0);
1029
+ const [keyChange, setKeyChange] = useState(void 0);
1030
+ const [query, setQuery] = useState("");
1031
+ const [searchResults, setSearchResults] = useState(void 0);
1032
+ const [searching, setSearching] = useState(false);
1033
+ const [dragging, setDragging] = useState(false);
1034
+ const link = ctx.client.link;
799
1035
  const load = () => {
800
1036
  setError(void 0);
801
- ctx.client.link.call("plugins.list", {}).then((result) => {
1037
+ link.call("plugins.list", {}).then((result) => {
802
1038
  if (!result.ok) {
803
1039
  setError(rpcErrorText(result.error));
804
1040
  return;
@@ -807,11 +1043,30 @@ function PluginsPage({ ctx }) {
807
1043
  }).catch((cause) => {
808
1044
  setError(cause instanceof Error ? cause.message : String(cause));
809
1045
  });
1046
+ link.call("plugins.updates-check", {}).then((result) => {
1047
+ if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
1048
+ }).catch(() => void 0);
1049
+ };
1050
+ useEffect(() => {
1051
+ load();
1052
+ }, [link]);
1053
+ const openInstall = () => {
1054
+ setQuery("");
1055
+ setSearchResults(void 0);
1056
+ setMessage(void 0);
1057
+ setDragging(false);
1058
+ setInstallOpen(true);
1059
+ };
1060
+ const closeInstall = () => {
1061
+ setInstallOpen(false);
1062
+ setQuery("");
1063
+ setSearchResults(void 0);
1064
+ setMessage(void 0);
1065
+ setDragging(false);
810
1066
  };
811
- useEffect(load, []);
812
1067
  const toggle = (row, enabled) => {
813
1068
  setBusy(row.packageName);
814
- ctx.client.link.call("plugins.set-enabled", {
1069
+ link.call("plugins.set-enabled", {
815
1070
  name: row.packageName,
816
1071
  enabled
817
1072
  }).then((result) => {
@@ -833,12 +1088,13 @@ function PluginsPage({ ctx }) {
833
1088
  const uninstall = (row) => {
834
1089
  if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
835
1090
  setBusy(row.packageName);
836
- ctx.client.link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
1091
+ link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
837
1092
  if (!result.ok) {
838
1093
  setError(rpcErrorText(result.error));
839
1094
  return;
840
1095
  }
841
1096
  setTouched((current) => new Set(current).add(row.packageName));
1097
+ setRestartNeeded(true);
842
1098
  load();
843
1099
  }).catch((cause) => {
844
1100
  setError(cause instanceof Error ? cause.message : String(cause));
@@ -846,100 +1102,690 @@ function PluginsPage({ ctx }) {
846
1102
  setBusy(void 0);
847
1103
  });
848
1104
  };
849
- const groups = /* @__PURE__ */ new Map();
850
- for (const row of rows) {
851
- const bucket = groups.get(row.category);
852
- if (bucket === void 0) groups.set(row.category, [row]);
853
- else bucket.push(row);
1105
+ const inspectPath = (zipPath) => {
1106
+ setMessage(void 0);
1107
+ link.call("plugins.inspect", { zipPath }).then((result) => {
1108
+ if (!result.ok) {
1109
+ setPhase({
1110
+ kind: "error",
1111
+ message: `读取插件包失败:${rpcErrorText(result.error)}`
1112
+ });
1113
+ return;
1114
+ }
1115
+ setPhase({
1116
+ kind: "confirm",
1117
+ zipPath,
1118
+ archive: result.value.archive,
1119
+ viaUrl: false,
1120
+ risk: false
1121
+ });
1122
+ }).catch((cause) => setPhase({
1123
+ kind: "error",
1124
+ message: String(cause)
1125
+ }));
1126
+ };
1127
+ const inspectFromUrl = (url) => {
1128
+ setMessage(void 0);
1129
+ link.call("plugins.inspect-from-url", { url }).then((result) => {
1130
+ if (!result.ok) {
1131
+ setPhase({
1132
+ kind: "error",
1133
+ message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
1134
+ });
1135
+ return;
1136
+ }
1137
+ setPhase({
1138
+ kind: "confirm",
1139
+ zipPath: result.value.zipPath,
1140
+ archive: result.value.archive,
1141
+ viaUrl: true,
1142
+ risk: false
1143
+ });
1144
+ }).catch((cause) => setPhase({
1145
+ kind: "error",
1146
+ message: String(cause)
1147
+ }));
1148
+ };
1149
+ const runInstall = (zipPath, archive) => {
1150
+ setPhase({ kind: "installing" });
1151
+ (archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
1152
+ if (!result.ok) {
1153
+ setPhase({
1154
+ kind: "error",
1155
+ message: `安装失败:${rpcErrorText(result.error)}`
1156
+ });
1157
+ return;
1158
+ }
1159
+ setPhase({ kind: "idle" });
1160
+ closeInstall();
1161
+ setRestartNeeded(true);
1162
+ load();
1163
+ }).catch((cause) => setPhase({
1164
+ kind: "error",
1165
+ message: String(cause)
1166
+ }));
1167
+ };
1168
+ /** The update pill's click: a plain update installs directly; a key
1169
+ * change confirmation intercepts first. */
1170
+ const requestUpdate = (update) => {
1171
+ if (update.keyChanged === true) {
1172
+ setKeyChange(update);
1173
+ return;
1174
+ }
1175
+ updateNow(update.name);
1176
+ };
1177
+ /** The update itself: the feed's entry, no preview. */
1178
+ const updateNow = (name) => {
1179
+ setKeyChange(void 0);
1180
+ setUpdatingName(name);
1181
+ setMessage(void 0);
1182
+ link.call("plugins.remote-install", { name }).then((result) => {
1183
+ setUpdatingName(void 0);
1184
+ if (!result.ok) {
1185
+ setMessage({
1186
+ kind: "error",
1187
+ text: rpcErrorText(result.error)
1188
+ });
1189
+ return;
1190
+ }
1191
+ setRestartNeeded(true);
1192
+ load();
1193
+ }).catch(() => setUpdatingName(void 0));
1194
+ };
1195
+ /** The tri-form input: address/path → inspect, anything else → feed search. */
1196
+ const submitQuery = () => {
1197
+ const text = query.trim();
1198
+ if (text === "") return;
1199
+ setMessage(void 0);
1200
+ if (isHttpUrl(text)) {
1201
+ inspectFromUrl(text);
1202
+ return;
1203
+ }
1204
+ if (looksLikePath(text)) {
1205
+ inspectPath(text);
1206
+ return;
1207
+ }
1208
+ runSearch(text);
1209
+ };
1210
+ const runSearch = (text) => {
1211
+ setSearching(true);
1212
+ setSearchResults(void 0);
1213
+ link.call("plugins.remote-list", {}).then((result) => {
1214
+ setSearching(false);
1215
+ if (!result.ok) {
1216
+ setMessage({
1217
+ kind: "error",
1218
+ text: `搜索失败:${rpcErrorText(result.error)}`
1219
+ });
1220
+ return;
1221
+ }
1222
+ const needle = text.toLowerCase();
1223
+ setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
1224
+ }).catch((cause) => {
1225
+ setSearching(false);
1226
+ setMessage({
1227
+ kind: "error",
1228
+ text: String(cause)
1229
+ });
1230
+ });
1231
+ };
1232
+ /** A search-result entry that is not installed yet: preview first. The
1233
+ * entry's own coordinates decide where the zip comes from — a federation
1234
+ * row downloads from the author's release, a same-directory row from its
1235
+ * feed base. */
1236
+ const previewRemote = (item) => {
1237
+ if (item.url !== void 0) {
1238
+ inspectFromUrl(item.url);
1239
+ return;
1240
+ }
1241
+ if (item.feedUrl === void 0 || item.file === void 0) return;
1242
+ const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
1243
+ inspectFromUrl(`${base}${item.file}`);
1244
+ };
1245
+ const onDrop = (event) => {
1246
+ event.preventDefault();
1247
+ setDragging(false);
1248
+ const file = event.dataTransfer.files[0];
1249
+ if (file === void 0) return;
1250
+ if (!file.name.toLowerCase().endsWith(".zip")) {
1251
+ setMessage({
1252
+ kind: "error",
1253
+ text: "只支持 .zip 插件包或组合包"
1254
+ });
1255
+ return;
1256
+ }
1257
+ const zipPath = droppedZipPath(file);
1258
+ if (zipPath === null) {
1259
+ setMessage({
1260
+ kind: "error",
1261
+ text: "当前环境不支持拖拽安装(缺少路径桥)"
1262
+ });
1263
+ return;
1264
+ }
1265
+ inspectPath(zipPath);
1266
+ };
1267
+ const restart = () => {
1268
+ link.call("window.relaunch", {});
1269
+ };
1270
+ const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
1271
+ const spans = /* @__PURE__ */ new Map();
1272
+ for (let index = 0; index < rows.length;) {
1273
+ const category = rows[index].category;
1274
+ let end = index + 1;
1275
+ while (end < rows.length && rows[end].category === category) end += 1;
1276
+ spans.set(index, end - index);
1277
+ index = end;
854
1278
  }
855
- return jsx(Page, {
1279
+ return jsxs(Page, {
856
1280
  title: "插件管理",
857
- description: "安装驱动、业务页面和界面风格。启用/停用写入 plugins.yml,渲染端在下一次重启后生效。",
858
- actions: jsx(Button, {
859
- intent: "neutral",
860
- emphasis: "outline",
861
- onClick: load,
862
- children: "刷新"
1281
+ titleExtra: jsx(IconButton, {
1282
+ icon: jsx(PlusIcon, {}),
1283
+ label: "安装插件",
1284
+ onClick: openInstall
863
1285
  }),
864
- children: jsxs(Stack, {
865
- gap: "lg",
866
- children: [error !== void 0 && jsx("div", {
867
- role: "alert",
868
- style: { color: "var(--snap-color-danger)" },
869
- children: error
870
- }), rows.length === 0 ? jsx(EmptyState, {
871
- title: "还没有安装插件",
872
- description: "把插件 zip 拖入插件安装入口,或从插件源搜索安装。"
873
- }) : [...groups.entries()].map(([category, entries]) => jsx(Section, {
874
- title: category,
875
- children: jsxs(Table, { children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
876
- jsx(TableHead, { children: "名称" }),
877
- jsx(TableHead, { children: "类型" }),
878
- jsx(TableHead, { children: "版本" }),
879
- jsx(TableHead, { children: "状态" }),
880
- jsx(TableHead, { children: "操作" })
881
- ] }) }), jsx(TableBody, { children: entries.map((row) => jsxs(TableRow, { children: [
882
- jsx(TableCell, { children: jsxs("div", {
883
- style: {
884
- display: "flex",
885
- flexDirection: "column"
886
- },
887
- children: [jsxs("span", {
888
- style: {
889
- display: "flex",
890
- alignItems: "center",
891
- gap: "var(--snap-space-sm)"
892
- },
893
- children: [row.title, row.builtinDefault && jsx(Badge, {
1286
+ actions: restartNeeded ? jsx(Button, {
1287
+ intent: "primary",
1288
+ onClick: restart,
1289
+ children: "重启生效"
1290
+ }) : void 0,
1291
+ children: [
1292
+ jsxs(Stack, {
1293
+ gap: "lg",
1294
+ children: [error !== void 0 && jsx("div", {
1295
+ role: "alert",
1296
+ style: { color: "var(--snap-color-danger)" },
1297
+ children: error
1298
+ }), rows.length === 0 ? jsx(EmptyState, {
1299
+ title: "还没有安装插件",
1300
+ action: jsx(Button, {
1301
+ intent: "primary",
1302
+ onClick: openInstall,
1303
+ children: "安装插件"
1304
+ })
1305
+ }) : jsxs(Table, {
1306
+ "data-plugins-table": true,
1307
+ children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
1308
+ jsx(TableHead, {
1309
+ style: { width: "6em" },
1310
+ children: "分类"
1311
+ }),
1312
+ jsx(TableHead, { children: "名称" }),
1313
+ jsx(TableHead, { children: "类型" }),
1314
+ jsx(TableHead, { children: "版本" }),
1315
+ jsx(TableHead, { children: "状态" }),
1316
+ jsx(TableHead, { children: "操作" })
1317
+ ] }) }), jsx(TableBody, { children: rows.map((row, index) => {
1318
+ const update = updates.get(row.packageName);
1319
+ const span = spans.get(index);
1320
+ return jsxs(TableRow, { children: [
1321
+ span !== void 0 && jsx(TableCell, {
1322
+ rowSpan: span,
1323
+ style: {
1324
+ verticalAlign: "middle",
1325
+ color: "var(--snap-color-muted)",
1326
+ fontWeight: 600
1327
+ },
1328
+ children: row.category
1329
+ }),
1330
+ jsx(TableCell, { children: jsxs("div", {
1331
+ style: {
1332
+ display: "flex",
1333
+ flexDirection: "column"
1334
+ },
1335
+ children: [jsxs("span", {
1336
+ style: {
1337
+ display: "flex",
1338
+ alignItems: "center",
1339
+ gap: "var(--snap-space-sm)"
1340
+ },
1341
+ children: [row.title, row.builtinDefault && jsx(Badge, {
1342
+ intent: "neutral",
1343
+ children: "内置默认"
1344
+ })]
1345
+ }), jsx("span", {
1346
+ style: {
1347
+ color: "var(--snap-color-muted)",
1348
+ fontSize: "var(--snap-text-xs)"
1349
+ },
1350
+ children: row.packageName
1351
+ })]
1352
+ }) }),
1353
+ jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
894
1354
  intent: "neutral",
895
- children: "内置默认"
896
- })]
897
- }), jsx("span", {
898
- style: {
899
- color: "var(--snap-color-muted)",
900
- fontSize: "var(--snap-text-xs)"
901
- },
902
- children: row.packageName
903
- })]
904
- }) }),
905
- jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
906
- intent: "neutral",
907
- children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
908
- })] }),
909
- jsx(TableCell, { children: row.version ?? "—" }),
910
- jsx(TableCell, { children: row.builtinDefault ? jsx(Badge, {
911
- intent: "success",
912
- children: "始终随底座"
913
- }) : jsxs("div", {
914
- style: {
915
- display: "flex",
916
- alignItems: "center",
917
- gap: "var(--snap-space-sm)"
918
- },
919
- children: [jsx(Switch, {
920
- checked: row.enabled,
921
- disabled: busy === row.packageName,
922
- onCheckedChange: (next) => toggle(row, next),
923
- "aria-label": `启用 ${row.title}`
924
- }), touched.has(row.packageName) && jsx(Badge, {
925
- intent: "warning",
926
- children: "待重启"
927
- })]
928
- }) }),
929
- jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
930
- style: { color: "var(--snap-color-muted)" },
931
- children: "内置默认不可卸载"
932
- }) : jsx(Button, {
933
- intent: "danger",
934
- emphasis: "ghost",
935
- size: "sm",
936
- disabled: busy === row.packageName,
937
- onClick: () => uninstall(row),
938
- children: "卸载"
939
- }) })
940
- ] }, row.packageName)) })] })
941
- }, category))]
942
- })
1355
+ children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
1356
+ })] }),
1357
+ jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
1358
+ intent: "primary",
1359
+ emphasis: "ghost",
1360
+ size: "sm",
1361
+ title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
1362
+ disabled: updatingName === row.packageName,
1363
+ onClick: () => requestUpdate(update),
1364
+ children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
1365
+ }) : row.version ?? "—" }),
1366
+ jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
1367
+ checked: true,
1368
+ disabled: true,
1369
+ "aria-label": `启用 ${row.title}`
1370
+ }) : jsxs("div", {
1371
+ style: {
1372
+ display: "flex",
1373
+ alignItems: "center",
1374
+ gap: "var(--snap-space-sm)"
1375
+ },
1376
+ children: [jsx(Switch, {
1377
+ checked: row.enabled,
1378
+ disabled: busy === row.packageName,
1379
+ onCheckedChange: (next) => toggle(row, next),
1380
+ "aria-label": `启用 ${row.title}`
1381
+ }), touched.has(row.packageName) && jsx(Badge, {
1382
+ intent: "warning",
1383
+ children: "待重启"
1384
+ })]
1385
+ }) }),
1386
+ jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
1387
+ style: { color: "var(--snap-color-muted)" },
1388
+ children: "内置默认不可卸载"
1389
+ }) : jsx(Button, {
1390
+ intent: "danger",
1391
+ emphasis: "ghost",
1392
+ size: "sm",
1393
+ disabled: busy === row.packageName,
1394
+ onClick: () => uninstall(row),
1395
+ children: "卸载"
1396
+ }) })
1397
+ ] }, row.packageName);
1398
+ }) })]
1399
+ })]
1400
+ }),
1401
+ jsx(Dialog, {
1402
+ open: installOpen,
1403
+ onOpenChange: (next) => {
1404
+ if (!next) closeInstall();
1405
+ },
1406
+ children: jsxs(DialogContent, {
1407
+ presentation: "modal",
1408
+ size: "lg",
1409
+ "data-plugins-dropzone": true,
1410
+ "aria-describedby": void 0,
1411
+ onDragOver: (event) => {
1412
+ event.preventDefault();
1413
+ setDragging(true);
1414
+ },
1415
+ onDragLeave: (event) => {
1416
+ if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
1417
+ },
1418
+ onDrop,
1419
+ children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
1420
+ gap: "sm",
1421
+ children: [
1422
+ jsx("div", {
1423
+ "data-plugins-drop-hint": true,
1424
+ style: {
1425
+ height: "calc(var(--snap-control-height-md) * 3)",
1426
+ display: "flex",
1427
+ alignItems: "center",
1428
+ justifyContent: "center",
1429
+ border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
1430
+ borderRadius: "var(--snap-radius-md)",
1431
+ background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
1432
+ color: "var(--snap-color-muted)",
1433
+ fontSize: "var(--snap-text-sm)"
1434
+ },
1435
+ children: dragging ? "释放以安装" : "拖入 .zip 安装"
1436
+ }),
1437
+ jsxs("div", {
1438
+ style: {
1439
+ display: "flex",
1440
+ gap: "var(--snap-space-sm)"
1441
+ },
1442
+ children: [jsx(Input, {
1443
+ value: query,
1444
+ placeholder: "本地路径 / https://… / 插件名",
1445
+ style: {
1446
+ flex: 1,
1447
+ minWidth: 0
1448
+ },
1449
+ onChange: (event) => setQuery(event.target.value),
1450
+ onKeyDown: (event) => {
1451
+ if (event.key === "Enter") submitQuery();
1452
+ }
1453
+ }), jsx(Button, {
1454
+ intent: "neutral",
1455
+ emphasis: "outline",
1456
+ disabled: searching,
1457
+ onClick: submitQuery,
1458
+ children: searching ? "搜索中…" : "搜索"
1459
+ })]
1460
+ }),
1461
+ message !== void 0 && jsx("div", {
1462
+ role: message.kind === "error" ? "alert" : "status",
1463
+ style: {
1464
+ fontSize: "var(--snap-text-xs)",
1465
+ color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
1466
+ },
1467
+ children: message.text
1468
+ }),
1469
+ visibleResults !== void 0 && jsxs(Stack, {
1470
+ gap: "sm",
1471
+ children: [
1472
+ jsxs("div", {
1473
+ style: {
1474
+ display: "flex",
1475
+ justifyContent: "space-between",
1476
+ alignItems: "center"
1477
+ },
1478
+ children: [jsxs("span", {
1479
+ style: {
1480
+ fontSize: "var(--snap-text-sm)",
1481
+ color: "var(--snap-color-muted)"
1482
+ },
1483
+ children: [
1484
+ "搜索“",
1485
+ query.trim(),
1486
+ "”(",
1487
+ searchResults?.length ?? 0,
1488
+ ")"
1489
+ ]
1490
+ }), jsx(Button, {
1491
+ intent: "neutral",
1492
+ emphasis: "ghost",
1493
+ size: "sm",
1494
+ onClick: () => setSearchResults(void 0),
1495
+ children: "✕"
1496
+ })]
1497
+ }),
1498
+ visibleResults.length === 0 && jsx("div", {
1499
+ style: {
1500
+ padding: "12px 0",
1501
+ textAlign: "center",
1502
+ color: "var(--snap-color-muted)",
1503
+ fontSize: "var(--snap-text-sm)"
1504
+ },
1505
+ children: "没有匹配的插件。"
1506
+ }),
1507
+ visibleResults.map((item) => {
1508
+ const installed = item.installed !== void 0;
1509
+ return jsxs("div", {
1510
+ style: {
1511
+ display: "flex",
1512
+ gap: "var(--snap-space-md)",
1513
+ alignItems: "center",
1514
+ justifyContent: "space-between",
1515
+ borderBottom: "1px solid var(--snap-color-border)",
1516
+ paddingBottom: "var(--snap-space-sm)"
1517
+ },
1518
+ children: [jsxs("div", {
1519
+ style: { minWidth: 0 },
1520
+ children: [jsxs("div", {
1521
+ style: {
1522
+ display: "flex",
1523
+ gap: "var(--snap-space-sm)",
1524
+ alignItems: "center"
1525
+ },
1526
+ children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
1527
+ intent: "neutral",
1528
+ children: item.source
1529
+ })]
1530
+ }), jsxs("div", {
1531
+ style: {
1532
+ fontSize: "var(--snap-text-xs)",
1533
+ color: "var(--snap-color-muted)"
1534
+ },
1535
+ children: [
1536
+ item.name,
1537
+ " · ",
1538
+ item.version
1539
+ ]
1540
+ })]
1541
+ }), item.action === "install" ? jsx(Button, {
1542
+ intent: "primary",
1543
+ emphasis: "outline",
1544
+ size: "sm",
1545
+ onClick: () => previewRemote(item),
1546
+ children: "安装"
1547
+ }) : item.action === "update" && installed ? jsx(Button, {
1548
+ intent: "primary",
1549
+ emphasis: "ghost",
1550
+ size: "sm",
1551
+ title: `当前 ${item.installed?.version} → ${item.version}`,
1552
+ disabled: updatingName === item.name,
1553
+ onClick: () => requestUpdate({
1554
+ name: item.name,
1555
+ installedVersion: item.installed?.version ?? "",
1556
+ feedVersion: item.version
1557
+ }),
1558
+ children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
1559
+ }) : jsx("span", {
1560
+ style: {
1561
+ fontSize: "var(--snap-text-xs)",
1562
+ color: "var(--snap-color-muted)"
1563
+ },
1564
+ children: item.action === "current" ? "已是最新" : "本地更新"
1565
+ })]
1566
+ }, item.name);
1567
+ }),
1568
+ (searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
1569
+ style: {
1570
+ fontSize: "var(--snap-text-xs)",
1571
+ color: "var(--snap-color-muted)"
1572
+ },
1573
+ children: [
1574
+ "已显示前 ",
1575
+ SEARCH_ROW_CAP,
1576
+ " 条,共 ",
1577
+ searchResults?.length,
1578
+ " 条。"
1579
+ ]
1580
+ })
1581
+ ]
1582
+ })
1583
+ ]
1584
+ }) })]
1585
+ })
1586
+ }),
1587
+ jsx(Dialog, {
1588
+ open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
1589
+ onOpenChange: (next) => {
1590
+ if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
1591
+ },
1592
+ children: jsxs(DialogContent, {
1593
+ presentation: "modal",
1594
+ "aria-describedby": void 0,
1595
+ children: [
1596
+ jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: phase.kind === "confirm" ? phase.archive.kind === "combo" ? "安装组合套件" : phase.archive.plugin.action === "update" ? "更新插件" : "安装插件" : phase.kind === "error" ? "安装失败" : "正在安装…" }), phase.kind === "confirm" && phase.archive.kind === "combo" && jsx(DialogDescription, { children: `${phase.archive.combo.title} · ${phase.archive.combo.id}` })] }),
1597
+ jsxs(DialogBody, { children: [
1598
+ phase.kind === "error" && jsx("div", {
1599
+ style: {
1600
+ color: "var(--snap-color-danger)",
1601
+ whiteSpace: "pre-wrap",
1602
+ fontSize: "var(--snap-text-sm)"
1603
+ },
1604
+ children: phase.message
1605
+ }),
1606
+ phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
1607
+ gap: "sm",
1608
+ children: [
1609
+ phase.archive.combo.description !== void 0 && jsx("div", {
1610
+ style: {
1611
+ color: "var(--snap-color-muted)",
1612
+ fontSize: "var(--snap-text-sm)"
1613
+ },
1614
+ children: phase.archive.combo.description
1615
+ }),
1616
+ jsxs("div", {
1617
+ style: {
1618
+ display: "grid",
1619
+ gap: "var(--snap-space-xs)",
1620
+ fontSize: "var(--snap-text-sm)"
1621
+ },
1622
+ children: [jsxs("div", { children: [
1623
+ "插件(",
1624
+ phase.archive.combo.plugins.length,
1625
+ ")"
1626
+ ] }), phase.archive.combo.plugins.map((plugin) => {
1627
+ const line = signatureText(plugin.signature, phase.viaUrl);
1628
+ const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
1629
+ return jsxs("div", {
1630
+ style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
1631
+ children: [
1632
+ plugin.title ?? plugin.name,
1633
+ " ",
1634
+ plugin.version,
1635
+ " · ",
1636
+ action,
1637
+ line.warning ? " · ⚠ 未验证" : ""
1638
+ ]
1639
+ }, plugin.name);
1640
+ })]
1641
+ }),
1642
+ phase.archive.combo.missing.length > 0 && jsxs("div", {
1643
+ style: {
1644
+ color: "var(--snap-color-danger)",
1645
+ fontSize: "var(--snap-text-sm)"
1646
+ },
1647
+ children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
1648
+ })
1649
+ ]
1650
+ }),
1651
+ phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
1652
+ gap: "sm",
1653
+ children: [
1654
+ phase.risk ? jsx("div", {
1655
+ "data-plugins-risk": true,
1656
+ style: {
1657
+ color: "var(--snap-color-warning)",
1658
+ fontWeight: 600
1659
+ },
1660
+ children: "⚠ 此插件未经发布者验证"
1661
+ }) : void 0,
1662
+ !phase.risk && jsxs(Stack, {
1663
+ gap: "sm",
1664
+ children: [
1665
+ phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
1666
+ jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
1667
+ phase.archive.plugin.action === "update" ? jsxs(Fragment, { children: [jsxs("div", { children: ["已安装版本:", phase.archive.plugin.installed?.version] }), jsxs("div", { children: ["将更新至:", phase.archive.plugin.version] })] }) : jsxs("div", { children: ["版本:", phase.archive.plugin.version] })
1668
+ ]
1669
+ }),
1670
+ (() => {
1671
+ const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
1672
+ return jsxs("div", {
1673
+ "data-plugins-signature": phase.archive.plugin.signature.state,
1674
+ style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
1675
+ children: ["签名:", line.text]
1676
+ });
1677
+ })(),
1678
+ !phase.risk && jsxs(Stack, {
1679
+ gap: "sm",
1680
+ children: [
1681
+ jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
1682
+ phase.archive.plugin.missing.length > 0 && jsxs("div", {
1683
+ style: {
1684
+ color: "var(--snap-color-danger)",
1685
+ fontSize: "var(--snap-text-sm)"
1686
+ },
1687
+ children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
1688
+ }),
1689
+ phase.archive.plugin.action === "blocked" && jsxs("div", {
1690
+ style: {
1691
+ color: "var(--snap-color-danger)",
1692
+ fontSize: "var(--snap-text-sm)"
1693
+ },
1694
+ children: [
1695
+ "已安装 v",
1696
+ phase.archive.plugin.installed?.version,
1697
+ ",安装包 v",
1698
+ phase.archive.plugin.version,
1699
+ " 不高于已装版本,无法覆盖。"
1700
+ ]
1701
+ })
1702
+ ]
1703
+ }),
1704
+ phase.risk && jsx("div", {
1705
+ style: {
1706
+ color: "var(--snap-color-muted)",
1707
+ fontSize: "var(--snap-text-sm)"
1708
+ },
1709
+ children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
1710
+ })
1711
+ ]
1712
+ })
1713
+ ] }),
1714
+ jsxs(DialogFooter, { children: [
1715
+ phase.kind === "error" && jsx(Button, {
1716
+ intent: "neutral",
1717
+ emphasis: "outline",
1718
+ onClick: () => setPhase({ kind: "idle" }),
1719
+ children: "返回"
1720
+ }),
1721
+ phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
1722
+ intent: "neutral",
1723
+ emphasis: "outline",
1724
+ onClick: () => setPhase({ kind: "idle" }),
1725
+ children: "取消"
1726
+ }), phase.risk ? jsx(Button, {
1727
+ intent: "primary",
1728
+ "data-plugins-risk-confirm": true,
1729
+ onClick: () => runInstall(phase.zipPath, phase.archive),
1730
+ children: "我知晓风险,仍要安装"
1731
+ }) : jsx(Button, {
1732
+ intent: "primary",
1733
+ "data-plugins-install-confirm": true,
1734
+ disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
1735
+ onClick: () => {
1736
+ if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
1737
+ setPhase({
1738
+ ...phase,
1739
+ risk: true
1740
+ });
1741
+ return;
1742
+ }
1743
+ runInstall(phase.zipPath, phase.archive);
1744
+ },
1745
+ children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
1746
+ })] }),
1747
+ phase.kind === "installing" && jsx("span", {
1748
+ style: { color: "var(--snap-color-muted)" },
1749
+ children: "正在安装…"
1750
+ })
1751
+ ] })
1752
+ ]
1753
+ })
1754
+ }),
1755
+ jsx(Dialog, {
1756
+ open: keyChange !== void 0,
1757
+ onOpenChange: (next) => {
1758
+ if (!next) setKeyChange(void 0);
1759
+ },
1760
+ children: jsxs(DialogContent, {
1761
+ presentation: "modal",
1762
+ children: [
1763
+ jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
1764
+ jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
1765
+ style: { fontSize: "var(--snap-text-sm)" },
1766
+ children: [
1767
+ "已安装 v",
1768
+ keyChange.installedVersion,
1769
+ " → 源上 v",
1770
+ keyChange.feedVersion,
1771
+ "。"
1772
+ ]
1773
+ }) }),
1774
+ jsxs(DialogFooter, { children: [jsx(Button, {
1775
+ intent: "neutral",
1776
+ emphasis: "outline",
1777
+ onClick: () => setKeyChange(void 0),
1778
+ children: "取消"
1779
+ }), jsx(Button, {
1780
+ intent: "primary",
1781
+ "data-plugins-keychange-confirm": true,
1782
+ onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
1783
+ children: "仍要更新"
1784
+ })] })
1785
+ ]
1786
+ })
1787
+ })
1788
+ ]
943
1789
  });
944
1790
  }
945
1791
  //#endregion
@@ -981,6 +1827,19 @@ function GearIcon() {
981
1827
  }), jsx("path", { d: "M19.4 15a1.7 1.7 0 0 0 .34 1.87l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.7 1.7 0 0 0-1.87-.34 1.7 1.7 0 0 0-1 1.55V21a2 2 0 1 1-4 0v-.09a1.7 1.7 0 0 0-1-1.55 1.7 1.7 0 0 0-1.87.34l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.7 1.7 0 0 0 .34-1.87 1.7 1.7 0 0 0-1.55-1H3a2 2 0 1 1 0-4h.09a1.7 1.7 0 0 0 1.55-1 1.7 1.7 0 0 0-.34-1.87l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.7 1.7 0 0 0 1.87.34h0a1.7 1.7 0 0 0 1-1.55V3a2 2 0 1 1 4 0v.09a1.7 1.7 0 0 0 1 1.55h0a1.7 1.7 0 0 0 1.87-.34l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.7 1.7 0 0 0-.34 1.87v0a1.7 1.7 0 0 0 1.55 1H21a2 2 0 1 1 0 4h-.09a1.7 1.7 0 0 0-1.55 1Z" })]
982
1828
  });
983
1829
  }
1830
+ /** The close glyph used by the surface's dismiss control. */
1831
+ function CloseIcon() {
1832
+ return jsx("svg", {
1833
+ viewBox: "0 0 24 24",
1834
+ width: "18",
1835
+ height: "18",
1836
+ fill: "none",
1837
+ stroke: "currentColor",
1838
+ strokeWidth: "1.8",
1839
+ "aria-hidden": "true",
1840
+ children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
1841
+ });
1842
+ }
984
1843
  /** The default settings trigger; the layout decides placement/presentation. */
985
1844
  function SettingsEntry(props) {
986
1845
  if (props.presentation === "label") return jsx(Button, {
@@ -999,12 +1858,13 @@ function SettingsEntry(props) {
999
1858
  }
1000
1859
  /** The default settings surface. */
1001
1860
  function SettingsSurface(props) {
1002
- const { service } = props;
1861
+ const { service, ctx } = props;
1003
1862
  useSyncExternalStore(service.subscribe, service.version, service.version);
1004
1863
  const open = service.isOpen();
1005
1864
  const pages = service.listPages();
1006
1865
  const activeId = service.activePage();
1007
1866
  const active = pages.find((page) => page.id === activeId);
1867
+ const [feedOpen, setFeedOpen] = useState(false);
1008
1868
  const groups = /* @__PURE__ */ new Map();
1009
1869
  for (const page of pages) {
1010
1870
  const group = page.group ?? "其他";
@@ -1012,7 +1872,7 @@ function SettingsSurface(props) {
1012
1872
  if (bucket === void 0) groups.set(group, [page]);
1013
1873
  else bucket.push(page);
1014
1874
  }
1015
- return jsx(Dialog, {
1875
+ return jsxs(Fragment, { children: [jsx(Dialog, {
1016
1876
  open,
1017
1877
  onOpenChange: (next) => {
1018
1878
  if (!next) service.close();
@@ -1026,11 +1886,21 @@ function SettingsSurface(props) {
1026
1886
  children: [jsxs("header", {
1027
1887
  ...part("settings", "header"),
1028
1888
  className: "snap-settings-header",
1029
- children: [jsx(DialogTitle, { children: "设置" }), jsx(Button, {
1030
- intent: "neutral",
1031
- emphasis: "ghost",
1032
- onClick: () => service.close(),
1033
- children: "关闭"
1889
+ children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
1890
+ style: {
1891
+ display: "flex",
1892
+ alignItems: "center",
1893
+ gap: 4
1894
+ },
1895
+ children: [jsx(IconButton, {
1896
+ icon: jsx(GearIcon, {}),
1897
+ label: "配置插件源",
1898
+ onClick: () => setFeedOpen(true)
1899
+ }), jsx(IconButton, {
1900
+ icon: jsx(CloseIcon, {}),
1901
+ label: "关闭",
1902
+ onClick: () => service.close()
1903
+ })]
1034
1904
  })]
1035
1905
  }), jsxs("div", {
1036
1906
  ...part("settings", "body"),
@@ -1063,10 +1933,7 @@ function SettingsSurface(props) {
1063
1933
  ...part("settings", "content"),
1064
1934
  className: "snap-settings-content",
1065
1935
  "data-active-page": activeId,
1066
- children: active === void 0 ? jsx(EmptyState, {
1067
- title: "暂无设置页",
1068
- description: "安装或启用一个带设置页的插件后,它会出现在这里。"
1069
- }) : jsx(SettingsPageBoundary, {
1936
+ children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
1070
1937
  page: active.id,
1071
1938
  children: active.render()
1072
1939
  })
@@ -1074,7 +1941,11 @@ function SettingsSurface(props) {
1074
1941
  })]
1075
1942
  })
1076
1943
  })
1077
- });
1944
+ }), jsx(PluginFeedDialog, {
1945
+ ctx,
1946
+ open: feedOpen,
1947
+ onOpenChange: setFeedOpen
1948
+ })] });
1078
1949
  }
1079
1950
  /** Mount the settings registry and its default slot contributions. */
1080
1951
  const settingsPlugin = {
@@ -1178,7 +2049,10 @@ const settingsPlugin = {
1178
2049
  ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
1179
2050
  id: "settings.default-surface",
1180
2051
  order: 0,
1181
- render: () => jsx(SettingsSurface, { service })
2052
+ render: () => jsx(SettingsSurface, {
2053
+ service,
2054
+ ctx
2055
+ })
1182
2056
  });
1183
2057
  }
1184
2058
  };