@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/index.js CHANGED
@@ -1,562 +1,14 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { Component, createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
3
- import { Slot as Slot$1 } from "@radix-ui/react-slot";
4
- import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
5
- import * as LabelPrimitive from "@radix-ui/react-label";
6
- import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
7
- import * as SelectPrimitive from "@radix-ui/react-select";
2
+ import { rpcErrorText } from "@snap-rail/connection";
3
+ import { useEffect, useState } from "react";
4
+ import { Slot } from "@radix-ui/react-slot";
5
+ import "@radix-ui/react-checkbox";
6
+ import "@radix-ui/react-label";
7
+ import "@radix-ui/react-radio-group";
8
+ import "@radix-ui/react-select";
8
9
  import * as SwitchPrimitive from "@radix-ui/react-switch";
9
- import * as TabsPrimitive from "@radix-ui/react-tabs";
10
+ import "@radix-ui/react-tabs";
10
11
  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";
13
- import { Context } from "@snap-rail/cordis";
14
- import { TimerService } from "@snap-rail/cordis-plugin-timer";
15
- import { shellContract } from "@snap-rail/shell/contract";
16
- import { createRoot } from "react-dom/client";
17
- import "@snap-rail/app-boot/contract";
18
- //#region lib/types/contract.js
19
- /**
20
- * The semantic UI contract: component names, region-slot ids, scoped slot
21
- * contexts, and the author-facing UI profile vocabulary. This module is pure
22
- * (types, constants, guards) so host and renderer faces can both import it
23
- * without dragging React or the renderer runtime into the host graph.
24
- *
25
- * @module @snap-rail/ui/contract
26
- */
27
- /** The author-declared relationship between a plugin and the skin contract. */
28
- const UI_PROFILES = [
29
- "native",
30
- "integrated",
31
- "custom"
32
- ];
33
- /** The stable region slots every layout may provide. */
34
- const UI_SLOT_IDS = {
35
- /** The one active layout of the operator window. */
36
- layout: "shell.layout",
37
- /** The operator titlebar. */
38
- titlebar: "shell.titlebar",
39
- /** Contributed titlebar actions. */
40
- titlebarActions: "shell.titlebar.actions",
41
- /** Sidebar extension area. */
42
- sidebar: "shell.sidebar",
43
- /** Statusbar extension area. */
44
- statusbar: "shell.statusbar",
45
- /** The global overlay stack (dialogs, confirms). */
46
- overlay: "shell.overlay",
47
- /** The floating ball surface face. */
48
- ball: "shell.ball",
49
- /** The settings trigger. */
50
- settingsEntry: "settings.entry",
51
- /** The settings surface itself. */
52
- settingsSurface: "settings.surface"
53
- };
54
- /** A named custom slot is owned by a publisher package. */
55
- const CUSTOM_SLOT_PATTERN = /^custom:[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-]*$/;
56
- /** Check a region-slot id at runtime. */
57
- function isValidSlotId(value) {
58
- return Object.values(UI_SLOT_IDS).includes(value) || CUSTOM_SLOT_PATTERN.test(value);
59
- }
60
- /** The occupancy mode of every built-in slot. */
61
- const UI_SLOT_MODES = {
62
- [UI_SLOT_IDS.layout]: "one",
63
- [UI_SLOT_IDS.titlebar]: "one",
64
- [UI_SLOT_IDS.titlebarActions]: "many",
65
- [UI_SLOT_IDS.sidebar]: "many",
66
- [UI_SLOT_IDS.statusbar]: "many",
67
- [UI_SLOT_IDS.overlay]: "many",
68
- [UI_SLOT_IDS.ball]: "one",
69
- [UI_SLOT_IDS.settingsEntry]: "one",
70
- [UI_SLOT_IDS.settingsSurface]: "one"
71
- };
72
- /** Diagnostic kinds surfaced by the UI registry. */
73
- const UI_DIAGNOSTIC_KINDS = [
74
- "unknown-slot",
75
- "missing-provider",
76
- "invalid-context",
77
- "duplicate-id",
78
- "render-failed",
79
- "declared-not-rendered"
80
- ];
81
- /**
82
- * The component catalog. It is the shared vocabulary for the gallery, skin
83
- * coverage checks, and author documentation; adding a component here is a
84
- * contract change, not an implementation detail.
85
- */
86
- const UI_COMPONENTS = {
87
- button: {
88
- parts: [
89
- "button.root",
90
- "button.label",
91
- "button.icon",
92
- "button.spinner"
93
- ],
94
- slots: ["label", "icon"],
95
- props: [
96
- "intent",
97
- "emphasis",
98
- "size",
99
- "loading",
100
- "disabled"
101
- ]
102
- },
103
- "icon-button": {
104
- parts: ["icon-button.root", "icon-button.icon"],
105
- slots: ["icon"],
106
- props: [
107
- "intent",
108
- "emphasis",
109
- "size",
110
- "active",
111
- "disabled"
112
- ]
113
- },
114
- input: {
115
- parts: [
116
- "input.root",
117
- "input.field",
118
- "input.prefix",
119
- "input.suffix",
120
- "input.clear"
121
- ],
122
- slots: ["prefix", "suffix"],
123
- props: [
124
- "size",
125
- "invalid",
126
- "disabled"
127
- ]
128
- },
129
- textarea: {
130
- parts: ["textarea.root", "textarea.field"],
131
- props: [
132
- "size",
133
- "invalid",
134
- "disabled"
135
- ]
136
- },
137
- "number-input": {
138
- parts: [
139
- "number-input.root",
140
- "number-input.field",
141
- "number-input.step-up",
142
- "number-input.step-down"
143
- ],
144
- props: [
145
- "size",
146
- "invalid",
147
- "disabled"
148
- ]
149
- },
150
- select: {
151
- parts: [
152
- "select.root",
153
- "select.trigger",
154
- "select.value",
155
- "select.chevron",
156
- "select.content",
157
- "select.item",
158
- "select.item-indicator",
159
- "select.empty"
160
- ],
161
- slots: ["empty"],
162
- props: [
163
- "size",
164
- "invalid",
165
- "disabled",
166
- "presentation"
167
- ]
168
- },
169
- "touch-select": {
170
- parts: [
171
- "touch-select.root",
172
- "touch-select.trigger",
173
- "touch-select.sheet",
174
- "touch-select.option"
175
- ],
176
- props: ["invalid", "disabled"]
177
- },
178
- checkbox: {
179
- parts: [
180
- "checkbox.root",
181
- "checkbox.box",
182
- "checkbox.indicator",
183
- "checkbox.label"
184
- ],
185
- slots: ["label"],
186
- props: [
187
- "checked",
188
- "invalid",
189
- "disabled"
190
- ]
191
- },
192
- switch: {
193
- parts: [
194
- "switch.root",
195
- "switch.thumb",
196
- "switch.label"
197
- ],
198
- slots: ["label"],
199
- props: ["checked", "disabled"]
200
- },
201
- "radio-group": {
202
- parts: [
203
- "radio-group.root",
204
- "radio-group.item",
205
- "radio-group.indicator",
206
- "radio-group.label"
207
- ],
208
- props: ["value", "disabled"]
209
- },
210
- tabs: {
211
- parts: [
212
- "tabs.root",
213
- "tabs.list",
214
- "tabs.trigger",
215
- "tabs.content"
216
- ],
217
- slots: ["list", "content"],
218
- props: ["value", "presentation"]
219
- },
220
- table: {
221
- parts: [
222
- "table.root",
223
- "table.header",
224
- "table.body",
225
- "table.row",
226
- "table.head",
227
- "table.cell",
228
- "table.empty"
229
- ],
230
- slots: ["empty"]
231
- },
232
- card: {
233
- parts: [
234
- "card.root",
235
- "card.header",
236
- "card.title",
237
- "card.description",
238
- "card.body",
239
- "card.footer"
240
- ],
241
- slots: [
242
- "header",
243
- "title",
244
- "description",
245
- "body",
246
- "footer"
247
- ]
248
- },
249
- panel: {
250
- parts: [
251
- "panel.root",
252
- "panel.header",
253
- "panel.title",
254
- "panel.body",
255
- "panel.footer"
256
- ],
257
- slots: [
258
- "header",
259
- "title",
260
- "body",
261
- "footer"
262
- ]
263
- },
264
- dialog: {
265
- parts: [
266
- "dialog.root",
267
- "dialog.overlay",
268
- "dialog.panel",
269
- "dialog.header",
270
- "dialog.title",
271
- "dialog.description",
272
- "dialog.body",
273
- "dialog.footer",
274
- "dialog.close"
275
- ],
276
- slots: [
277
- "header",
278
- "title",
279
- "description",
280
- "body",
281
- "footer"
282
- ],
283
- props: [
284
- "open",
285
- "presentation",
286
- "size"
287
- ]
288
- },
289
- sheet: {
290
- parts: [
291
- "sheet.root",
292
- "sheet.overlay",
293
- "sheet.panel",
294
- "sheet.header",
295
- "sheet.body",
296
- "sheet.footer"
297
- ],
298
- slots: [
299
- "header",
300
- "body",
301
- "footer"
302
- ],
303
- props: ["open", "presentation"]
304
- },
305
- popover: {
306
- parts: [
307
- "popover.root",
308
- "popover.trigger",
309
- "popover.content"
310
- ],
311
- slots: ["trigger", "content"]
312
- },
313
- tooltip: {
314
- parts: [
315
- "tooltip.root",
316
- "tooltip.trigger",
317
- "tooltip.content"
318
- ],
319
- slots: ["trigger", "content"]
320
- },
321
- menu: {
322
- parts: [
323
- "menu.root",
324
- "menu.trigger",
325
- "menu.content",
326
- "menu.item",
327
- "menu.separator"
328
- ],
329
- slots: ["trigger", "content"]
330
- },
331
- toast: {
332
- parts: [
333
- "toast.root",
334
- "toast.title",
335
- "toast.description",
336
- "toast.action",
337
- "toast.close"
338
- ],
339
- slots: ["action"]
340
- },
341
- progress: { parts: [
342
- "progress.root",
343
- "progress.track",
344
- "progress.indicator"
345
- ] },
346
- badge: { parts: ["badge.root"] },
347
- led: {
348
- parts: ["led.root", "led.halo"],
349
- props: ["tone"]
350
- },
351
- spinner: { parts: ["spinner.root"] },
352
- "empty-state": {
353
- parts: [
354
- "empty-state.root",
355
- "empty-state.icon",
356
- "empty-state.title",
357
- "empty-state.description",
358
- "empty-state.action"
359
- ],
360
- slots: [
361
- "icon",
362
- "title",
363
- "description",
364
- "action"
365
- ]
366
- },
367
- form: {
368
- parts: [
369
- "form.root",
370
- "form.fields",
371
- "form.actions"
372
- ],
373
- slots: ["fields", "actions"]
374
- },
375
- field: {
376
- parts: [
377
- "field.root",
378
- "field.label",
379
- "field.control",
380
- "field.help",
381
- "field.error"
382
- ],
383
- slots: [
384
- "label",
385
- "control",
386
- "help",
387
- "error"
388
- ],
389
- props: [
390
- "invalid",
391
- "required",
392
- "disabled"
393
- ]
394
- },
395
- "schema-form": {
396
- parts: ["schema-form.root", "schema-form.field"],
397
- slots: ["fields"]
398
- },
399
- "app-shell": {
400
- parts: [
401
- "app-shell.root",
402
- "app-shell.header",
403
- "app-shell.sidebar",
404
- "app-shell.main",
405
- "app-shell.footer"
406
- ],
407
- slots: [
408
- "header",
409
- "sidebar",
410
- "main",
411
- "footer"
412
- ]
413
- },
414
- page: {
415
- parts: [
416
- "page.root",
417
- "page.header",
418
- "page.title",
419
- "page.description",
420
- "page.actions",
421
- "page.body"
422
- ],
423
- slots: [
424
- "header",
425
- "title",
426
- "description",
427
- "actions",
428
- "body"
429
- ]
430
- },
431
- section: {
432
- parts: [
433
- "section.root",
434
- "section.header",
435
- "section.title",
436
- "section.actions",
437
- "section.body"
438
- ],
439
- slots: [
440
- "header",
441
- "title",
442
- "actions",
443
- "body"
444
- ]
445
- },
446
- toolbar: {
447
- parts: [
448
- "toolbar.root",
449
- "toolbar.start",
450
- "toolbar.end"
451
- ],
452
- slots: ["start", "end"]
453
- },
454
- stack: {
455
- parts: ["stack.root"],
456
- props: [
457
- "gap",
458
- "padding",
459
- "align"
460
- ]
461
- },
462
- row: {
463
- parts: ["row.root"],
464
- props: [
465
- "gap",
466
- "padding",
467
- "align",
468
- "justify"
469
- ]
470
- },
471
- grid: {
472
- parts: ["grid.root"],
473
- props: [
474
- "gap",
475
- "columns",
476
- "padding"
477
- ]
478
- },
479
- split: {
480
- parts: [
481
- "split.root",
482
- "split.start",
483
- "split.end"
484
- ],
485
- slots: ["start", "end"]
486
- },
487
- "scroll-area": { parts: [
488
- "scroll-area.root",
489
- "scroll-area.viewport",
490
- "scroll-area.scrollbar"
491
- ] },
492
- "drag-scroll": { parts: ["drag-scroll.root", "drag-scroll.viewport"] },
493
- visualization: {
494
- parts: [
495
- "visualization.root",
496
- "visualization.header",
497
- "visualization.title",
498
- "visualization.actions",
499
- "visualization.body",
500
- "visualization.empty",
501
- "visualization.error",
502
- "visualization.loading"
503
- ],
504
- slots: [
505
- "header",
506
- "title",
507
- "actions",
508
- "body",
509
- "empty",
510
- "error",
511
- "loading"
512
- ],
513
- props: ["state"]
514
- },
515
- "chart-frame": {
516
- parts: [
517
- "chart-frame.root",
518
- "chart-frame.header",
519
- "chart-frame.title",
520
- "chart-frame.actions",
521
- "chart-frame.body"
522
- ],
523
- slots: [
524
- "header",
525
- "title",
526
- "actions",
527
- "body"
528
- ]
529
- },
530
- settings: { parts: [
531
- "settings.root",
532
- "settings.header",
533
- "settings.title",
534
- "settings.body",
535
- "settings.nav",
536
- "settings.nav-item",
537
- "settings.nav-icon",
538
- "settings.group",
539
- "settings.group-title",
540
- "settings.content"
541
- ] }
542
- };
543
- /** The presentation targets a skin may tune. */
544
- const PRESENTATION_TARGETS = [
545
- "dialog",
546
- "select",
547
- "tabs",
548
- "toast"
549
- ];
550
- /** The presentation variants the core implements. */
551
- const PRESENTATION_VARIANTS = [
552
- "modal",
553
- "sheet",
554
- "fullscreen",
555
- "popover",
556
- "segmented",
557
- "inline"
558
- ];
559
- //#endregion
560
12
  //#region lib/types/utils.js
561
13
  /**
562
14
  * Small helpers shared by the headless semantic components: class merging and
@@ -580,336 +32,6 @@ function space(token) {
580
32
  return `var(--snap-space-${token})`;
581
33
  }
582
34
  //#endregion
583
- //#region lib/types/skins.js
584
- /** The two colour modes. */
585
- const SKIN_MODES = ["light", "dark"];
586
- /** The built-in default skin id. */
587
- const DEFAULT_SKIN_ID = "default";
588
- /** The factory cobalt/steel skin. Extra skins override it through the registry. */
589
- const DEFAULT_SKIN = {
590
- id: DEFAULT_SKIN_ID,
591
- title: "工业钴蓝",
592
- presentations: {
593
- dialog: "modal",
594
- select: "popover",
595
- tabs: "inline",
596
- toast: "inline"
597
- },
598
- tokens: {
599
- dark: {
600
- colorBg: "#0b0f14",
601
- colorSurface: "#11161d",
602
- colorSurfaceRaised: "#161b22",
603
- colorText: "#ced8e3",
604
- colorMuted: "#8b949e",
605
- colorPrimary: "#4a6cff",
606
- colorOnPrimary: "#ffffff",
607
- colorDanger: "#f85149",
608
- colorSuccess: "#3fb950",
609
- colorWarning: "#d29922",
610
- colorBorder: "#1f2933",
611
- colorFocus: "#4a6cff",
612
- chart1: "#4a6cff",
613
- chart2: "#3147a1",
614
- chart3: "#667fcd",
615
- chart4: "#7d8fa5",
616
- chart5: "#55677c",
617
- chart6: "#33414f",
618
- fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
619
- fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
620
- textXs: "13px",
621
- textSm: "15px",
622
- textMd: "17px",
623
- textLg: "20px",
624
- textXl: "24px",
625
- weightNormal: "400",
626
- weightMedium: "500",
627
- weightStrong: "600",
628
- leadingTight: "1.2",
629
- leadingNormal: "1.55",
630
- spaceXs: "4px",
631
- spaceSm: "8px",
632
- spaceMd: "12px",
633
- spaceLg: "20px",
634
- spaceXl: "32px",
635
- radiusSm: "6px",
636
- radiusMd: "8px",
637
- radiusLg: "12px",
638
- radiusFull: "999px",
639
- borderWidth: "1px",
640
- shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
641
- shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
642
- shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
643
- durationFast: "120ms",
644
- durationNormal: "180ms",
645
- durationSlow: "280ms",
646
- easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
647
- zOverlay: "50",
648
- zModal: "60",
649
- zToast: "70",
650
- controlHeightSm: "40px",
651
- controlHeightMd: "48px",
652
- controlHeightLg: "56px",
653
- density: "comfortable"
654
- },
655
- light: {
656
- colorBg: "#e4e9ef",
657
- colorSurface: "#f3f6f9",
658
- colorSurfaceRaised: "#ffffff",
659
- colorText: "#26323e",
660
- colorMuted: "#5d6d7e",
661
- colorPrimary: "#3857e8",
662
- colorOnPrimary: "#ffffff",
663
- colorDanger: "#dc2626",
664
- colorSuccess: "#15803d",
665
- colorWarning: "#b45309",
666
- colorBorder: "#c7d0da",
667
- colorFocus: "#3857e8",
668
- chart1: "#3857e8",
669
- chart2: "#7088ee",
670
- chart3: "#667dd0",
671
- chart4: "#94a3b8",
672
- chart5: "#b3c0cd",
673
- chart6: "#ccd6e0",
674
- fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
675
- fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
676
- textXs: "13px",
677
- textSm: "15px",
678
- textMd: "17px",
679
- textLg: "20px",
680
- textXl: "24px",
681
- weightNormal: "400",
682
- weightMedium: "500",
683
- weightStrong: "600",
684
- leadingTight: "1.2",
685
- leadingNormal: "1.55",
686
- spaceXs: "4px",
687
- spaceSm: "8px",
688
- spaceMd: "12px",
689
- spaceLg: "20px",
690
- spaceXl: "32px",
691
- radiusSm: "6px",
692
- radiusMd: "8px",
693
- radiusLg: "12px",
694
- radiusFull: "999px",
695
- borderWidth: "1px",
696
- shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
697
- shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
698
- shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
699
- durationFast: "120ms",
700
- durationNormal: "180ms",
701
- durationSlow: "280ms",
702
- easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
703
- zOverlay: "50",
704
- zModal: "60",
705
- zToast: "70",
706
- controlHeightSm: "40px",
707
- controlHeightMd: "48px",
708
- controlHeightLg: "56px",
709
- density: "comfortable"
710
- }
711
- }
712
- };
713
- /** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
714
- function skinTokenVar(key) {
715
- return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
716
- }
717
- /** Apply the active skin to the document root. */
718
- function applySkin(skin, mode) {
719
- if (typeof document === "undefined") return;
720
- const root = document.documentElement;
721
- root.dataset["snapSkin"] = skin.id;
722
- root.dataset["snapMode"] = mode;
723
- const tokens = skin.tokens[mode];
724
- for (const [key, value] of Object.entries(tokens)) root.style.setProperty(skinTokenVar(key), value);
725
- }
726
- /** Mount the `ctx.skins` registry. */
727
- const skinsPlugin = {
728
- name: "snap-rail ui skins",
729
- apply(ctx) {
730
- const skins = /* @__PURE__ */ new Map();
731
- const listeners = /* @__PURE__ */ new Set();
732
- const styleTags = /* @__PURE__ */ new Map();
733
- let activeId = DEFAULT_SKIN_ID;
734
- let mode = "dark";
735
- let revision = 0;
736
- skins.set(DEFAULT_SKIN_ID, DEFAULT_SKIN);
737
- const notify = () => {
738
- revision += 1;
739
- for (const listener of listeners) listener();
740
- ctx.emit("skins/changed");
741
- };
742
- const ensureStyleTag = (skin) => {
743
- if (typeof document === "undefined" || skin.css === void 0) return;
744
- if (styleTags.has(skin.id)) return;
745
- const tag = document.createElement("style");
746
- tag.dataset["snapSkinStyle"] = skin.id;
747
- tag.textContent = skin.css;
748
- document.head.append(tag);
749
- styleTags.set(skin.id, tag);
750
- };
751
- const refresh = () => {
752
- const skin = skins.get(activeId) ?? DEFAULT_SKIN;
753
- activeId = skin.id;
754
- ensureStyleTag(skin);
755
- applySkin(skin, mode);
756
- notify();
757
- };
758
- ctx.provide("skins", {
759
- register(caller, skin) {
760
- skins.set(skin.id, skin);
761
- if (skin.id !== "default") activeId = skin.id;
762
- refresh();
763
- const remove = () => {
764
- if (!skins.delete(skin.id)) return;
765
- const tag = styleTags.get(skin.id);
766
- if (tag !== void 0) {
767
- tag.remove();
768
- styleTags.delete(skin.id);
769
- }
770
- if (activeId === skin.id) activeId = DEFAULT_SKIN_ID;
771
- refresh();
772
- };
773
- caller.effect(() => remove);
774
- return remove;
775
- },
776
- activate(skinId) {
777
- if (!skins.has(skinId)) return false;
778
- activeId = skinId;
779
- refresh();
780
- return true;
781
- },
782
- list: () => [skins.get("default") ?? DEFAULT_SKIN, ...[...skins.values()].filter((skin) => skin.id !== DEFAULT_SKIN_ID)],
783
- active: () => skins.get(activeId) ?? DEFAULT_SKIN,
784
- setMode(next) {
785
- if (mode === next) return;
786
- mode = next;
787
- refresh();
788
- },
789
- mode: () => mode,
790
- presentation(target) {
791
- return (skins.get(activeId) ?? DEFAULT_SKIN).presentations?.[target];
792
- },
793
- tokens: () => (skins.get(activeId) ?? DEFAULT_SKIN).tokens[mode],
794
- subscribe(listener) {
795
- listeners.add(listener);
796
- return () => {
797
- listeners.delete(listener);
798
- };
799
- },
800
- version: () => revision
801
- });
802
- refresh();
803
- }
804
- };
805
- /** The React context carrying the skin service. */
806
- const SkinsContext = createContext(null);
807
- /** Provide the skin service to a renderer tree. */
808
- function SkinsProvider(props) {
809
- return jsx(SkinsContext.Provider, {
810
- value: props.service,
811
- children: props.children
812
- });
813
- }
814
- /** Read the skin service. */
815
- function useSkins() {
816
- const service = useContext(SkinsContext);
817
- if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
818
- return service;
819
- }
820
- /** Re-render on skin/mode changes and return the active token set. */
821
- function useSkinTokens() {
822
- const service = useSkins();
823
- useSyncExternalStore(service.subscribe, service.version, service.version);
824
- return service.tokens();
825
- }
826
- /** Re-render on skin/mode changes and return the active presentation default. */
827
- function usePresentation(target) {
828
- const service = useSkins();
829
- useSyncExternalStore(service.subscribe, service.version, service.version);
830
- return service.presentation(target);
831
- }
832
- //#endregion
833
- //#region lib/types/charts.js
834
- /** A semantic frame for a chart, gauge, map, or custom visualization. */
835
- function ChartFrame({ title, description, actions, state = "ready", empty, error, loading, children, className, style }) {
836
- return jsxs("section", {
837
- ...part("chart-frame", "root"),
838
- className: cn("snap-chart-frame", className),
839
- "data-state": state,
840
- style,
841
- children: [(title !== void 0 || description !== void 0 || actions !== void 0) && jsxs("header", {
842
- ...part("chart-frame", "header"),
843
- className: "snap-chart-frame-header",
844
- children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
845
- ...part("chart-frame", "title"),
846
- children: title
847
- }), description !== void 0 && jsx("div", {
848
- className: "snap-chart-frame-description",
849
- children: description
850
- })] }), actions !== void 0 && jsx("div", {
851
- ...part("chart-frame", "actions"),
852
- children: actions
853
- })]
854
- }), jsx("div", {
855
- ...part("chart-frame", "body"),
856
- className: "snap-chart-frame-body",
857
- "data-state": state,
858
- children: state === "loading" ? loading ?? jsx("div", {
859
- ...part("visualization", "loading"),
860
- children: "加载中…"
861
- }) : state === "empty" ? empty ?? jsx("div", {
862
- ...part("visualization", "empty"),
863
- children: "暂无数据"
864
- }) : state === "error" ? error ?? jsx("div", {
865
- ...part("visualization", "error"),
866
- role: "alert",
867
- children: "图表加载失败"
868
- }) : children
869
- })]
870
- });
871
- }
872
- /** A chart frame that exposes the `visualization.*` anatomy as well. */
873
- function Visualization(props) {
874
- return jsx(ChartFrame, { ...props });
875
- }
876
- /** Turn the active skin tokens into a chart-library theme. */
877
- function chartThemeOf(tokens) {
878
- return {
879
- color: [
880
- tokens.chart1,
881
- tokens.chart2,
882
- tokens.chart3,
883
- tokens.chart4,
884
- tokens.chart5,
885
- tokens.chart6
886
- ],
887
- backgroundColor: tokens.colorSurface,
888
- textStyle: {
889
- color: tokens.colorText,
890
- fontFamily: tokens.fontSans,
891
- fontSize: Number.parseInt(tokens.textSm, 10) || 14
892
- },
893
- axisLine: { lineStyle: { color: tokens.colorBorder } },
894
- splitLine: { lineStyle: {
895
- color: tokens.colorBorder,
896
- type: "dashed"
897
- } },
898
- tooltip: {
899
- backgroundColor: tokens.colorSurfaceRaised,
900
- borderColor: tokens.colorBorder,
901
- textStyle: {
902
- color: tokens.colorText,
903
- fontFamily: tokens.fontSans
904
- }
905
- }
906
- };
907
- }
908
- /** The active chart theme, re-derived whenever the skin/mode changes. */
909
- function useChartTheme() {
910
- return chartThemeOf(useSkinTokens());
911
- }
912
- //#endregion
913
35
  //#region lib/types/components/button.js
914
36
  /**
915
37
  * Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
@@ -944,7 +66,7 @@ function Spinner(props) {
944
66
  }
945
67
  /** A themed button; `asChild` composes the behaviour onto a child element. */
946
68
  function Button({ intent = "neutral", emphasis = "solid", size = "md", loading = false, icon, iconPosition = "start", asChild = false, disabled, className, children, type, ...props }) {
947
- const Component = asChild ? Slot$1 : "button";
69
+ const Component = asChild ? Slot : "button";
948
70
  const content = asChild ? children : jsxs(Fragment, { children: [
949
71
  icon !== void 0 && iconPosition === "start" && jsx("span", {
950
72
  ...part("button", "icon"),
@@ -1006,12 +128,8 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
1006
128
  */
1007
129
  /** The dialog root. */
1008
130
  const Dialog = DialogPrimitive.Root;
1009
- /** The dialog trigger. */
1010
- const DialogTrigger = DialogPrimitive.Trigger;
1011
- /** The dialog close. */
1012
- const DialogClose = DialogPrimitive.Close;
1013
131
  /** The portalled dialog content. */
1014
- function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true }) {
132
+ function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
1015
133
  const resolved = presentation === "auto" ? "modal" : presentation;
1016
134
  return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
1017
135
  ...part("dialog", "overlay"),
@@ -1021,6 +139,7 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
1021
139
  className: cn("snap-dialog-panel", className),
1022
140
  "data-presentation": resolved,
1023
141
  "data-size": size,
142
+ ...rest,
1024
143
  children: [children, showClose && jsx(DialogPrimitive.Close, {
1025
144
  ...part("dialog", "close"),
1026
145
  className: "snap-dialog-close",
@@ -1069,59 +188,8 @@ function DialogFooter({ children, className }) {
1069
188
  children
1070
189
  });
1071
190
  }
1072
- /** A sheet is a dialog with the `sheet` presentation by default. */
1073
- function Sheet(props) {
1074
- return jsx(DialogContent, {
1075
- ...props,
1076
- presentation: props.presentation ?? "sheet"
1077
- });
1078
- }
1079
191
  //#endregion
1080
192
  //#region lib/types/components/controls.js
1081
- /**
1082
- * Selection and toggle semantics over Radix: tabs, select, switch, checkbox,
1083
- * and radio groups. All behaviour/keyboard handling stays here; skins target
1084
- * the stable parts and state attributes.
1085
- *
1086
- * @module @snap-rail/ui/components/controls
1087
- */
1088
- /** A form label. */
1089
- function Label({ className, children, ...props }) {
1090
- return jsx(LabelPrimitive.Root, {
1091
- className: cn("snap-label", className),
1092
- ...props,
1093
- children
1094
- });
1095
- }
1096
- /** The tabs root. */
1097
- const Tabs = TabsPrimitive.Root;
1098
- /** The tabs list. */
1099
- function TabsList({ className, children, ...props }) {
1100
- return jsx(TabsPrimitive.List, {
1101
- ...part("tabs", "list"),
1102
- className: cn("snap-tabs-list", className),
1103
- ...props,
1104
- children
1105
- });
1106
- }
1107
- /** A tab trigger. */
1108
- function TabsTrigger({ className, children, ...props }) {
1109
- return jsx(TabsPrimitive.Trigger, {
1110
- ...part("tabs", "trigger"),
1111
- className: cn("snap-tabs-trigger", className),
1112
- ...props,
1113
- children
1114
- });
1115
- }
1116
- /** A tab panel. */
1117
- function TabsContent({ className, children, ...props }) {
1118
- return jsx(TabsPrimitive.Content, {
1119
- ...part("tabs", "content"),
1120
- className: cn("snap-tabs-content", className),
1121
- ...props,
1122
- children
1123
- });
1124
- }
1125
193
  /** A boolean switch. */
1126
194
  function Switch({ className, label, ...props }) {
1127
195
  return jsxs("label", {
@@ -1140,147 +208,6 @@ function Switch({ className, label, ...props }) {
1140
208
  })]
1141
209
  });
1142
210
  }
1143
- /** A tri-state checkbox with an inline indicator. */
1144
- function Checkbox({ className, label, ...props }) {
1145
- return jsxs("label", {
1146
- className: "snap-checkbox-label",
1147
- children: [jsx(CheckboxPrimitive.Root, {
1148
- ...part("checkbox", "root"),
1149
- className: cn("snap-checkbox", className),
1150
- ...props,
1151
- children: jsx(CheckboxPrimitive.Indicator, {
1152
- ...part("checkbox", "indicator"),
1153
- className: "snap-checkbox-indicator",
1154
- children: "✓"
1155
- })
1156
- }), label !== void 0 && jsx("span", {
1157
- ...part("checkbox", "label"),
1158
- children: label
1159
- })]
1160
- });
1161
- }
1162
- /** The radio group root. */
1163
- function RadioGroup({ className, children, ...props }) {
1164
- return jsx(RadioGroupPrimitive.Root, {
1165
- ...part("radio-group", "root"),
1166
- className: cn("snap-radio-group", className),
1167
- ...props,
1168
- children
1169
- });
1170
- }
1171
- /** One radio item. */
1172
- function RadioGroupItem({ className, ...props }) {
1173
- return jsx(RadioGroupPrimitive.Item, {
1174
- ...part("radio-group", "item"),
1175
- className: cn("snap-radio-item", className),
1176
- ...props,
1177
- children: jsx(RadioGroupPrimitive.Indicator, {
1178
- ...part("radio-group", "indicator"),
1179
- className: "snap-radio-indicator"
1180
- })
1181
- });
1182
- }
1183
- /** A modal option list; use on touch terminals in place of the popover select. */
1184
- function TouchSelect({ value, onValueChange, options, placeholder = "请选择", disabled = false, invalid = false, size = "md", className, "aria-label": ariaLabel, title }) {
1185
- const [open, setOpen] = useState(false);
1186
- const selected = options.find((option) => option.value === value);
1187
- return jsxs(Fragment, { children: [jsxs(Button, {
1188
- type: "button",
1189
- size,
1190
- emphasis: "outline",
1191
- className,
1192
- disabled,
1193
- "aria-label": ariaLabel,
1194
- "aria-invalid": invalid || void 0,
1195
- "aria-haspopup": "dialog",
1196
- onClick: () => setOpen(true),
1197
- children: [jsx("span", {
1198
- style: {
1199
- flex: 1,
1200
- textAlign: "left"
1201
- },
1202
- children: selected?.label ?? placeholder
1203
- }), jsx("span", {
1204
- "aria-hidden": "true",
1205
- children: "▾"
1206
- })]
1207
- }), jsx(Dialog, {
1208
- open,
1209
- onOpenChange: setOpen,
1210
- children: jsxs(DialogContent, {
1211
- presentation: "modal",
1212
- size: "sm",
1213
- children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: title ?? ariaLabel ?? "请选择" }) }), jsxs("div", {
1214
- ...part("touch-select", "options"),
1215
- style: {
1216
- display: "flex",
1217
- flexDirection: "column",
1218
- gap: "var(--snap-space-sm)"
1219
- },
1220
- children: [options.map((option) => jsx(Button, {
1221
- type: "button",
1222
- size: "lg",
1223
- emphasis: option.value === value ? "solid" : "outline",
1224
- intent: option.value === value ? "primary" : "neutral",
1225
- disabled: option.disabled === true,
1226
- onClick: () => {
1227
- onValueChange?.(option.value);
1228
- setOpen(false);
1229
- },
1230
- children: option.label
1231
- }, option.value)), options.length === 0 && jsx("span", {
1232
- style: { color: "var(--snap-color-muted)" },
1233
- children: "无可选项"
1234
- })]
1235
- })]
1236
- })
1237
- })] });
1238
- }
1239
- /** A popover select. */
1240
- function Select({ value, onValueChange, options, placeholder = "请选择", disabled = false, invalid = false, size = "md", className, "aria-label": ariaLabel }) {
1241
- return jsxs(SelectPrimitive.Root, {
1242
- ...value !== void 0 ? { value } : {},
1243
- ...onValueChange !== void 0 ? { onValueChange } : {},
1244
- disabled,
1245
- children: [jsxs(SelectPrimitive.Trigger, {
1246
- ...part("select", "trigger"),
1247
- className: cn("snap-select-trigger", className),
1248
- "data-size": size,
1249
- "data-invalid": invalid || void 0,
1250
- "data-disabled": disabled || void 0,
1251
- "aria-label": ariaLabel,
1252
- "aria-invalid": invalid || void 0,
1253
- children: [jsx(SelectPrimitive.Value, {
1254
- ...part("select", "value"),
1255
- placeholder
1256
- }), jsx(SelectPrimitive.Icon, {
1257
- ...part("select", "chevron"),
1258
- className: "snap-select-chevron",
1259
- children: "▾"
1260
- })]
1261
- }), jsx(SelectPrimitive.Portal, { children: jsx(SelectPrimitive.Content, {
1262
- ...part("select", "content"),
1263
- className: "snap-select-content",
1264
- position: "popper",
1265
- sideOffset: 4,
1266
- children: jsxs(SelectPrimitive.Viewport, { children: [options.map((option) => jsxs(SelectPrimitive.Item, {
1267
- ...part("select", "item"),
1268
- className: "snap-select-item",
1269
- value: option.value,
1270
- disabled: option.disabled === true,
1271
- children: [jsx(SelectPrimitive.ItemText, { children: option.label }), jsx(SelectPrimitive.ItemIndicator, {
1272
- ...part("select", "item-indicator"),
1273
- className: "snap-select-item-indicator",
1274
- children: "✓"
1275
- })]
1276
- }, option.value)), options.length === 0 && jsx("div", {
1277
- ...part("select", "empty"),
1278
- className: "snap-select-empty",
1279
- children: "无可选项"
1280
- })] })
1281
- }) })]
1282
- });
1283
- }
1284
211
  //#endregion
1285
212
  //#region lib/types/components/feedback.js
1286
213
  /** A compact status/count label. */
@@ -1292,43 +219,6 @@ function Badge({ children, intent = "neutral", className }) {
1292
219
  children
1293
220
  });
1294
221
  }
1295
- /** A status light with a separate halo part for breathing/glow skins. */
1296
- function Led({ tone = "neutral", label, className }) {
1297
- return jsx("span", {
1298
- ...part("led", "root"),
1299
- className: cn("snap-led", className),
1300
- "data-tone": tone,
1301
- "aria-label": label,
1302
- role: label !== void 0 ? "img" : void 0,
1303
- children: jsx("span", {
1304
- ...part("led", "halo"),
1305
- "aria-hidden": "true"
1306
- })
1307
- });
1308
- }
1309
- /** A linear progress indicator. */
1310
- function Progress({ value, label, className }) {
1311
- const clamped = value === null ? null : Math.min(1, Math.max(0, value));
1312
- return jsx("div", {
1313
- ...part("progress", "root"),
1314
- className: cn("snap-progress", className),
1315
- role: "progressbar",
1316
- "aria-label": label,
1317
- "aria-valuemin": 0,
1318
- "aria-valuemax": 100,
1319
- ...clamped !== null ? { "aria-valuenow": Math.round(clamped * 100) } : {},
1320
- "data-indeterminate": clamped === null || void 0,
1321
- children: jsx("div", {
1322
- ...part("progress", "track"),
1323
- className: "snap-progress-track",
1324
- children: jsx("div", {
1325
- ...part("progress", "indicator"),
1326
- className: "snap-progress-indicator",
1327
- style: clamped === null ? void 0 : { width: `${Math.round(clamped * 100)}%` }
1328
- })
1329
- })
1330
- });
1331
- }
1332
222
  /** A centered empty/zero-state block. */
1333
223
  function EmptyState({ title, description, icon, action, className }) {
1334
224
  return jsxs("div", {
@@ -1355,66 +245,15 @@ function EmptyState({ title, description, icon, action, className }) {
1355
245
  });
1356
246
  }
1357
247
  //#endregion
1358
- //#region lib/types/components/form.js
1359
- /** A labelled form row. */
1360
- function Field({ label, htmlFor, help, error, invalid = false, required = false, children, className }) {
1361
- const bad = invalid || error !== void 0;
1362
- return jsxs("div", {
1363
- ...part("field", "root"),
1364
- className: cn("snap-field", className),
1365
- "data-invalid": bad || void 0,
1366
- "data-required": required || void 0,
1367
- children: [
1368
- label !== void 0 && jsxs(Label, {
1369
- ...htmlFor !== void 0 ? { htmlFor } : {},
1370
- ...part("field", "label"),
1371
- children: [label, required && jsx("span", {
1372
- "aria-hidden": "true",
1373
- children: " *"
1374
- })]
1375
- }),
1376
- jsx("div", {
1377
- ...part("field", "control"),
1378
- children
1379
- }),
1380
- help !== void 0 && error === void 0 && jsx("div", {
1381
- ...part("field", "help"),
1382
- className: "snap-field-help",
1383
- children: help
1384
- }),
1385
- error !== void 0 && jsx("div", {
1386
- ...part("field", "error"),
1387
- className: "snap-field-error",
1388
- role: "alert",
1389
- children: error
1390
- })
1391
- ]
1392
- });
1393
- }
1394
- /** A form with a fields region and an actions region. */
1395
- function Form({ children, actions, onSubmit, className }) {
1396
- return jsxs("form", {
1397
- ...part("form", "root"),
1398
- className: cn("snap-form", className),
1399
- onSubmit,
1400
- children: [jsx("div", {
1401
- ...part("form", "fields"),
1402
- className: "snap-form-fields",
1403
- children
1404
- }), actions !== void 0 && jsx("div", {
1405
- ...part("form", "actions"),
1406
- className: "snap-form-actions",
1407
- children: actions
1408
- })]
1409
- });
1410
- }
1411
- //#endregion
1412
248
  //#region lib/types/components/input.js
1413
- /** A single-line text field with semantic prefix/suffix slots. */
1414
- function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, disabled, ...props }) {
249
+ /** A single-line text field with semantic prefix/suffix slots. Layout
250
+ * `style`/`className` dress the wrapper — the visible control; the native
251
+ * field already stretches inside it. */
252
+ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, style, disabled, ...props }) {
1415
253
  return jsxs("div", {
1416
254
  ...part(componentName, "root"),
1417
255
  className: cn("snap-input", className),
256
+ style,
1418
257
  "data-size": size,
1419
258
  "data-invalid": invalid || void 0,
1420
259
  "data-disabled": disabled === true || void 0,
@@ -1445,35 +284,6 @@ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componen
1445
284
  ]
1446
285
  });
1447
286
  }
1448
- /** A multi-line text field. */
1449
- function Textarea({ size = "md", invalid = false, className, disabled, ...props }) {
1450
- return jsx("div", {
1451
- ...part("textarea", "root"),
1452
- className: cn("snap-textarea", className),
1453
- "data-size": size,
1454
- "data-invalid": invalid || void 0,
1455
- "data-disabled": disabled === true || void 0,
1456
- children: jsx("textarea", {
1457
- ...part("textarea", "field"),
1458
- className: "snap-textarea-field",
1459
- disabled,
1460
- "aria-invalid": invalid || void 0,
1461
- ...props
1462
- })
1463
- });
1464
- }
1465
- /** A numeric field with the numeric keyboard hint and native stepping. */
1466
- function NumberInput({ min, max, step, ...props }) {
1467
- return jsx(Input, {
1468
- ...props,
1469
- componentName: "number-input",
1470
- type: "number",
1471
- inputMode: "decimal",
1472
- ...min !== void 0 ? { min } : {},
1473
- ...max !== void 0 ? { max } : {},
1474
- ...step !== void 0 ? { step } : {}
1475
- });
1476
- }
1477
287
  //#endregion
1478
288
  //#region lib/types/components/layout.js
1479
289
  /** A vertical flow. */
@@ -1492,121 +302,8 @@ function Stack({ gap = "md", padding, align, className, style, children }) {
1492
302
  children
1493
303
  });
1494
304
  }
1495
- /** A horizontal flow. */
1496
- function Row({ gap = "sm", padding, align, justify, wrap = false, className, style, children }) {
1497
- return jsx("div", {
1498
- ...part("row", "root"),
1499
- className: cn("snap-row", className),
1500
- style: {
1501
- display: "flex",
1502
- flexDirection: "row",
1503
- gap: space(gap),
1504
- ...padding !== void 0 ? { padding: space(padding) } : {},
1505
- ...align !== void 0 ? { alignItems: align } : {},
1506
- ...justify !== void 0 ? { justifyContent: justify } : {},
1507
- ...wrap ? { flexWrap: "wrap" } : {},
1508
- ...style
1509
- },
1510
- children
1511
- });
1512
- }
1513
- /** A responsive grid. */
1514
- function Grid({ gap = "md", padding, columns = 2, minColumnWidth, className, style, children }) {
1515
- const template = typeof columns === "number" ? `repeat(${columns}, minmax(0, 1fr))` : columns;
1516
- return jsx("div", {
1517
- ...part("grid", "root"),
1518
- className: cn("snap-grid", className),
1519
- style: {
1520
- display: "grid",
1521
- gap: space(gap),
1522
- gridTemplateColumns: minColumnWidth !== void 0 ? `repeat(auto-fit, minmax(${minColumnWidth}, 1fr))` : template,
1523
- ...padding !== void 0 ? { padding: space(padding) } : {},
1524
- ...style
1525
- },
1526
- children
1527
- });
1528
- }
1529
- /** A two-pane split (sidebar + content, list + detail). */
1530
- function Split({ start, end, gap = "md", ratio = "minmax(0, 2fr) minmax(0, 3fr)", className, style }) {
1531
- return jsxs("div", {
1532
- ...part("split", "root"),
1533
- className: cn("snap-split", className),
1534
- style: {
1535
- display: "grid",
1536
- gridTemplateColumns: ratio,
1537
- gap: space(gap),
1538
- minHeight: 0,
1539
- ...style
1540
- },
1541
- children: [jsx("div", {
1542
- ...part("split", "start"),
1543
- style: {
1544
- minWidth: 0,
1545
- minHeight: 0
1546
- },
1547
- children: start
1548
- }), jsx("div", {
1549
- ...part("split", "end"),
1550
- style: {
1551
- minWidth: 0,
1552
- minHeight: 0
1553
- },
1554
- children: end
1555
- })]
1556
- });
1557
- }
1558
- /** The operator-window shell frame. */
1559
- function AppShell({ header, sidebar, footer, className, style, children }) {
1560
- return jsxs("div", {
1561
- ...part("app-shell", "root"),
1562
- className: cn("snap-app-shell", className),
1563
- style: {
1564
- display: "flex",
1565
- flexDirection: "column",
1566
- height: "100%",
1567
- minHeight: 0,
1568
- ...style
1569
- },
1570
- children: [
1571
- header !== void 0 && jsx("div", {
1572
- ...part("app-shell", "header"),
1573
- style: { flexShrink: 0 },
1574
- children: header
1575
- }),
1576
- jsxs("div", {
1577
- style: {
1578
- display: "flex",
1579
- flex: 1,
1580
- minHeight: 0
1581
- },
1582
- children: [sidebar !== void 0 && jsx("div", {
1583
- ...part("app-shell", "sidebar"),
1584
- style: {
1585
- flexShrink: 0,
1586
- minHeight: 0
1587
- },
1588
- children: sidebar
1589
- }), jsx("div", {
1590
- ...part("app-shell", "main"),
1591
- style: {
1592
- flex: 1,
1593
- minWidth: 0,
1594
- minHeight: 0,
1595
- overflow: "auto"
1596
- },
1597
- children
1598
- })]
1599
- }),
1600
- footer !== void 0 && jsx("div", {
1601
- ...part("app-shell", "footer"),
1602
- style: { flexShrink: 0 },
1603
- children: footer
1604
- })
1605
- ]
1606
- });
1607
- }
1608
305
  /** A page body with its own header/actions anatomy. */
1609
- function Page({ header, actions, title, description, className, style, children }) {
306
+ function Page({ header, actions, title, titleExtra, description, className, style, children }) {
1610
307
  return jsxs("div", {
1611
308
  ...part("page", "root"),
1612
309
  className: cn("snap-page", className),
@@ -1632,9 +329,19 @@ function Page({ header, actions, title, description, className, style, children
1632
329
  justifyContent: "space-between",
1633
330
  gap: space("md")
1634
331
  },
1635
- children: [title !== void 0 && jsx("div", {
1636
- ...part("page", "title"),
1637
- children: title
332
+ children: [jsxs("div", {
333
+ style: {
334
+ display: "flex",
335
+ alignItems: "center",
336
+ gap: space("sm")
337
+ },
338
+ children: [title !== void 0 && jsx("div", {
339
+ ...part("page", "title"),
340
+ children: title
341
+ }), titleExtra !== void 0 && jsx("div", {
342
+ ...part("page", "title-extra"),
343
+ children: titleExtra
344
+ })]
1638
345
  }), actions !== void 0 && jsx("div", {
1639
346
  ...part("page", "actions"),
1640
347
  children: actions
@@ -1658,300 +365,17 @@ function Page({ header, actions, title, description, className, style, children
1658
365
  })]
1659
366
  });
1660
367
  }
1661
- /** A titled content section. */
1662
- function Section({ title, description, actions, className, style, children }) {
1663
- return jsxs("section", {
1664
- ...part("section", "root"),
1665
- className: cn("snap-section", className),
1666
- style: {
1667
- display: "flex",
1668
- flexDirection: "column",
1669
- gap: space("sm"),
1670
- ...style
1671
- },
1672
- children: [(title !== void 0 || actions !== void 0) && jsxs("div", {
1673
- ...part("section", "header"),
1674
- style: {
1675
- display: "flex",
1676
- alignItems: "center",
1677
- justifyContent: "space-between",
1678
- gap: space("md")
1679
- },
1680
- children: [jsxs("div", { children: [title !== void 0 && jsx("div", {
1681
- ...part("section", "title"),
1682
- children: title
1683
- }), description !== void 0 && jsx("div", { children: description })] }), actions !== void 0 && jsx("div", {
1684
- ...part("section", "actions"),
1685
- children: actions
1686
- })]
1687
- }), jsx("div", {
1688
- ...part("section", "body"),
368
+ //#endregion
369
+ //#region lib/types/components/surface.js
370
+ /** A semantic table. */
371
+ function Table({ className, children, ...props }) {
372
+ return jsx("div", {
373
+ ...part("table", "root"),
374
+ className: cn("snap-table", className),
375
+ children: jsx("table", {
376
+ ...props,
1689
377
  children
1690
- })]
1691
- });
1692
- }
1693
- /** A compact action bar. */
1694
- function Toolbar({ start, end, className, style }) {
1695
- return jsxs("div", {
1696
- ...part("toolbar", "root"),
1697
- className: cn("snap-toolbar", className),
1698
- style: {
1699
- display: "flex",
1700
- alignItems: "center",
1701
- justifyContent: "space-between",
1702
- gap: space("sm"),
1703
- ...style
1704
- },
1705
- children: [jsx("div", {
1706
- ...part("toolbar", "start"),
1707
- style: {
1708
- display: "flex",
1709
- alignItems: "center",
1710
- gap: space("sm"),
1711
- minWidth: 0
1712
- },
1713
- children: start
1714
- }), jsx("div", {
1715
- ...part("toolbar", "end"),
1716
- style: {
1717
- display: "flex",
1718
- alignItems: "center",
1719
- gap: space("sm"),
1720
- flexShrink: 0
1721
- },
1722
- children: end
1723
- })]
1724
- });
1725
- }
1726
- /** A native scroll container with a stable anatomy. */
1727
- function ScrollArea({ direction = "vertical", className, style, children }) {
1728
- return jsx("div", {
1729
- ...part("scroll-area", "root"),
1730
- className: cn("snap-scroll-area", className),
1731
- style: {
1732
- overflowY: direction === "horizontal" ? "hidden" : "auto",
1733
- overflowX: direction === "vertical" ? "hidden" : "auto",
1734
- minHeight: 0,
1735
- ...style
1736
- },
1737
- children: jsx("div", {
1738
- ...part("scroll-area", "viewport"),
1739
- children
1740
- })
1741
- });
1742
- }
1743
- /** A touch-friendly scroll container; pointer dragging pans the viewport. */
1744
- function DragScroll({ direction = "vertical", className, style, children }) {
1745
- return jsx("div", {
1746
- ...part("drag-scroll", "root"),
1747
- className: cn("snap-drag-scroll", className),
1748
- style: {
1749
- overflowY: direction === "horizontal" ? "hidden" : "auto",
1750
- overflowX: direction === "vertical" ? "hidden" : "auto",
1751
- minHeight: 0,
1752
- ...style
1753
- },
1754
- children: jsx("div", {
1755
- ...part("drag-scroll", "viewport"),
1756
- children
1757
- })
1758
- });
1759
- }
1760
- //#endregion
1761
- //#region lib/types/components/schema-form.js
1762
- function asRecord(value) {
1763
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
1764
- }
1765
- /** Render a flat JSON-Schema object as semantic fields. */
1766
- function SchemaForm({ schema, value, onChange, idPrefix = "schema" }) {
1767
- const properties = schema.properties ?? {};
1768
- const required = new Set(schema.required ?? []);
1769
- const update = (key, next) => {
1770
- onChange({
1771
- ...value,
1772
- [key]: next
1773
- });
1774
- };
1775
- return jsxs("div", {
1776
- style: {
1777
- display: "flex",
1778
- flexDirection: "column",
1779
- gap: "var(--snap-space-md)"
1780
- },
1781
- children: [Object.entries(properties).map(([key, property]) => {
1782
- const id = `${idPrefix}-${key}`;
1783
- const current = value[key] ?? property.default;
1784
- const label = property.title ?? key;
1785
- const common = {
1786
- label,
1787
- htmlFor: id,
1788
- ...property.description !== void 0 ? { help: property.description } : {},
1789
- ...required.has(key) ? { required: true } : {}
1790
- };
1791
- if (Array.isArray(property.enum)) {
1792
- const values = property.enum;
1793
- const options = values.map((item) => ({
1794
- value: String(item),
1795
- label: String(item)
1796
- }));
1797
- return jsx(Field, {
1798
- ...common,
1799
- children: jsx(TouchSelect, {
1800
- ...current !== void 0 ? { value: String(current) } : {},
1801
- options,
1802
- onValueChange: (next) => {
1803
- update(key, values.find((item) => String(item) === next) ?? next);
1804
- },
1805
- "aria-label": String(label)
1806
- })
1807
- }, key);
1808
- }
1809
- if (property.type === "boolean") return jsx(Field, {
1810
- ...common,
1811
- children: jsx(Switch, {
1812
- checked: current === true,
1813
- onCheckedChange: (next) => update(key, next),
1814
- label: current === true ? "开启" : "关闭"
1815
- })
1816
- }, key);
1817
- if (property.type === "number" || property.type === "integer") return jsx(Field, {
1818
- ...common,
1819
- children: jsx(NumberInput, {
1820
- id,
1821
- value: typeof current === "number" ? current : "",
1822
- ...property.minimum !== void 0 ? { min: property.minimum } : {},
1823
- ...property.maximum !== void 0 ? { max: property.maximum } : {},
1824
- onChange: (event) => {
1825
- const raw = event.target.value;
1826
- update(key, raw === "" ? void 0 : Number(raw));
1827
- }
1828
- })
1829
- }, key);
1830
- if (property.type === "object" || property.type === "array") return jsx(Field, {
1831
- ...common,
1832
- help: property.description ?? "JSON 值",
1833
- children: jsx(Textarea, {
1834
- id,
1835
- rows: 4,
1836
- defaultValue: JSON.stringify(current ?? (property.type === "array" ? [] : {}), null, 2),
1837
- onBlur: (event) => {
1838
- try {
1839
- update(key, JSON.parse(event.target.value));
1840
- } catch {}
1841
- }
1842
- })
1843
- }, key);
1844
- return jsx(Field, {
1845
- ...common,
1846
- children: jsx(Input, {
1847
- id,
1848
- value: typeof current === "string" || typeof current === "number" ? String(current) : "",
1849
- onChange: (event) => update(key, event.target.value)
1850
- })
1851
- }, key);
1852
- }), Object.keys(properties).length === 0 && jsx("span", {
1853
- style: { color: "var(--snap-color-muted)" },
1854
- children: "该驱动没有额外配置项。"
1855
- })]
1856
- });
1857
- }
1858
- /** Normalize a driver's JSON Schema (which may carry `$schema`). */
1859
- function schemaNodeOf(value) {
1860
- return asRecord(value);
1861
- }
1862
- //#endregion
1863
- //#region lib/types/components/surface.js
1864
- /** A content card. */
1865
- function Card({ className, children, ...props }) {
1866
- return jsx("div", {
1867
- ...part("card", "root"),
1868
- className: cn("snap-card", className),
1869
- ...props,
1870
- children
1871
- });
1872
- }
1873
- /** The card header region. */
1874
- function CardHeader({ className, children, ...props }) {
1875
- return jsx("div", {
1876
- ...part("card", "header"),
1877
- className: cn("snap-card-header", className),
1878
- ...props,
1879
- children
1880
- });
1881
- }
1882
- /** The card title. */
1883
- function CardTitle({ className, children, ...props }) {
1884
- return jsx("div", {
1885
- ...part("card", "title"),
1886
- className: cn("snap-card-title", className),
1887
- ...props,
1888
- children
1889
- });
1890
- }
1891
- /** The card description. */
1892
- function CardDescription({ className, children, ...props }) {
1893
- return jsx("div", {
1894
- ...part("card", "description"),
1895
- className: cn("snap-card-description", className),
1896
- ...props,
1897
- children
1898
- });
1899
- }
1900
- /** The card body. */
1901
- function CardContent({ className, children, ...props }) {
1902
- return jsx("div", {
1903
- ...part("card", "body"),
1904
- className: cn("snap-card-content", className),
1905
- ...props,
1906
- children
1907
- });
1908
- }
1909
- /** The card footer. */
1910
- function CardFooter({ className, children, ...props }) {
1911
- return jsx("div", {
1912
- ...part("card", "footer"),
1913
- className: cn("snap-card-footer", className),
1914
- ...props,
1915
- children
1916
- });
1917
- }
1918
- /** A bounded panel with optional header/footer. */
1919
- function Panel({ title, actions, footer, className, children, ...props }) {
1920
- return jsxs("div", {
1921
- ...part("panel", "root"),
1922
- className: cn("snap-panel", className),
1923
- ...props,
1924
- children: [
1925
- (title !== void 0 || actions !== void 0) && jsxs("div", {
1926
- ...part("panel", "header"),
1927
- className: "snap-panel-header",
1928
- children: [jsx("div", {
1929
- ...part("panel", "title"),
1930
- children: title
1931
- }), actions !== void 0 && jsx("div", { children: actions })]
1932
- }),
1933
- jsx("div", {
1934
- ...part("panel", "body"),
1935
- className: "snap-panel-body",
1936
- children
1937
- }),
1938
- footer !== void 0 && jsx("div", {
1939
- ...part("panel", "footer"),
1940
- className: "snap-panel-footer",
1941
- children: footer
1942
- })
1943
- ]
1944
- });
1945
- }
1946
- /** A semantic table. */
1947
- function Table({ className, children, ...props }) {
1948
- return jsx("div", {
1949
- ...part("table", "root"),
1950
- className: cn("snap-table", className),
1951
- children: jsx("table", {
1952
- ...props,
1953
- children
1954
- })
378
+ })
1955
379
  });
1956
380
  }
1957
381
  /** The table head. */
@@ -1999,726 +423,17 @@ function TableCell({ className, children, ...props }) {
1999
423
  children
2000
424
  });
2001
425
  }
2002
- /** A full-width empty row. */
2003
- function TableEmpty({ colSpan, children }) {
2004
- return jsx(TableRow, { children: jsx(TableCell, {
2005
- colSpan,
2006
- children: jsx("div", {
2007
- ...part("table", "empty"),
2008
- children
2009
- })
2010
- }) });
2011
- }
2012
- //#endregion
2013
- //#region lib/types/pages.js
2014
- /**
2015
- * The main-page registry: business views contribute a page, a layout renders
2016
- * the active one. This is deliberately separate from settings pages and from
2017
- * the chrome slots; gating/workflows can wrap it later without changing the
2018
- * page authoring surface.
2019
- *
2020
- * @module @snap-rail/ui/pages
2021
- */
2022
- /** Mount the page registry. */
2023
- const pagesPlugin = {
2024
- name: "snap-rail ui pages",
2025
- apply(ctx) {
2026
- const pages = /* @__PURE__ */ new Map();
2027
- const listeners = /* @__PURE__ */ new Set();
2028
- let revision = 0;
2029
- let seq = 0;
2030
- let activeId;
2031
- const ordered = () => [...pages.values()].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
2032
- const notify = () => {
2033
- revision += 1;
2034
- for (const listener of listeners) listener();
2035
- ctx.emit("pages/changed");
2036
- };
2037
- const service = {
2038
- registerPage(caller, page) {
2039
- pages.set(page.id, {
2040
- page,
2041
- seq: seq++
2042
- });
2043
- activeId ??= page.id;
2044
- notify();
2045
- const remove = () => {
2046
- if (!pages.delete(page.id)) return;
2047
- if (activeId === page.id) activeId = ordered()[0]?.id;
2048
- notify();
2049
- };
2050
- caller.effect(() => remove);
2051
- return remove;
2052
- },
2053
- list: ordered,
2054
- active() {
2055
- if (activeId === void 0) return void 0;
2056
- return pages.get(activeId)?.page ?? ordered()[0];
2057
- },
2058
- setActive(id) {
2059
- if (!pages.has(id) || activeId === id) return;
2060
- activeId = id;
2061
- notify();
2062
- },
2063
- subscribe(listener) {
2064
- listeners.add(listener);
2065
- return () => {
2066
- listeners.delete(listener);
2067
- };
2068
- },
2069
- version: () => revision
2070
- };
2071
- ctx.provide("pages", service);
2072
- }
2073
- };
2074
- /** Re-render a layout when the page registry or active page changes. */
2075
- function usePagesVersion(ctx) {
2076
- return useSyncExternalStore(ctx.pages.subscribe, ctx.pages.version, ctx.pages.version);
2077
- }
2078
- //#endregion
2079
- //#region lib/types/slots.js
2080
- const MAX_DIAGNOSTICS = 100;
2081
- /** The default definition of a built-in slot. */
2082
- function builtinDefinition(slot) {
2083
- return {
2084
- id: slot,
2085
- mode: UI_SLOT_MODES[slot] ?? "many"
2086
- };
2087
- }
2088
- /** Mount the `ctx.ui` registry. */
2089
- const slotsPlugin = {
2090
- name: "snap-rail ui slots",
2091
- apply(ctx) {
2092
- const entries = /* @__PURE__ */ new Map();
2093
- const layouts = /* @__PURE__ */ new Map();
2094
- const listeners = /* @__PURE__ */ new Set();
2095
- const diagnostics = [];
2096
- let revision = 0;
2097
- let layoutSeq = 0;
2098
- for (const slot of Object.values(UI_SLOT_IDS)) entries.set(slot, {
2099
- def: builtinDefinition(slot),
2100
- contributions: /* @__PURE__ */ new Map(),
2101
- nextSeq: 0
2102
- });
2103
- const notify = (slot) => {
2104
- revision += 1;
2105
- for (const listener of listeners) listener();
2106
- ctx.emit("ui/changed");
2107
- if (slot !== void 0) ctx.emit("ui/slot-changed", slot);
2108
- };
2109
- const diagnose = (diagnostic) => {
2110
- diagnostics.push({
2111
- ...diagnostic,
2112
- time: Date.now()
2113
- });
2114
- if (diagnostics.length > MAX_DIAGNOSTICS) diagnostics.shift();
2115
- };
2116
- const activeLayoutOf = () => {
2117
- return [...layouts.values()].sort((a, b) => {
2118
- const pa = a.layout.precedence ?? 0;
2119
- return (b.layout.precedence ?? 0) - pa || a.layout.order - b.layout.order || b.seq - a.seq;
2120
- })[0]?.layout;
2121
- };
2122
- const ensureEntry = (slot) => {
2123
- const existing = entries.get(slot);
2124
- if (existing !== void 0) return existing;
2125
- const entry = {
2126
- def: {
2127
- id: slot,
2128
- mode: "many"
2129
- },
2130
- contributions: /* @__PURE__ */ new Map(),
2131
- nextSeq: 0
2132
- };
2133
- entries.set(slot, entry);
2134
- return entry;
2135
- };
2136
- ctx.provide("ui", {
2137
- defineSlot(caller, def) {
2138
- if (!isValidSlotId(def.id)) {
2139
- diagnose({
2140
- kind: "unknown-slot",
2141
- slot: def.id,
2142
- message: `插槽 id 不合法:${def.id}`
2143
- });
2144
- return () => {};
2145
- }
2146
- if (Object.values(UI_SLOT_IDS).includes(def.id)) {
2147
- diagnose({
2148
- kind: "duplicate-id",
2149
- slot: def.id,
2150
- message: `内置插槽不能被重新定义:${def.id}`
2151
- });
2152
- return () => {};
2153
- }
2154
- const entry = ensureEntry(def.id);
2155
- entry.def = def;
2156
- notify(def.id);
2157
- const remove = () => {
2158
- if (entries.delete(def.id)) notify(def.id);
2159
- };
2160
- caller.effect(() => remove);
2161
- return remove;
2162
- },
2163
- registerLayout(caller, layout) {
2164
- for (const slot of layout.provides) if (!isValidSlotId(slot)) diagnose({
2165
- kind: "unknown-slot",
2166
- id: layout.id,
2167
- slot,
2168
- message: `布局 ${layout.id} 声明了非法插槽:${slot}`
2169
- });
2170
- else if (!entries.has(slot)) diagnose({
2171
- kind: "unknown-slot",
2172
- id: layout.id,
2173
- slot,
2174
- message: `布局 ${layout.id} 声明了未定义的插槽:${slot}`
2175
- });
2176
- layouts.set(layout.id, {
2177
- layout,
2178
- seq: layoutSeq++
2179
- });
2180
- notify();
2181
- const remove = () => {
2182
- if (layouts.delete(layout.id)) notify();
2183
- };
2184
- caller.effect(() => remove);
2185
- return remove;
2186
- },
2187
- contribute(caller, slot, contribution) {
2188
- if (!isValidSlotId(slot)) {
2189
- diagnose({
2190
- kind: "unknown-slot",
2191
- id: contribution.id,
2192
- slot,
2193
- message: `贡献 ${contribution.id} 指向非法插槽:${slot}`
2194
- });
2195
- return () => {};
2196
- }
2197
- const entry = entries.get(slot);
2198
- if (entry === void 0) diagnose({
2199
- kind: "unknown-slot",
2200
- id: contribution.id,
2201
- slot,
2202
- message: `贡献 ${contribution.id} 指向未定义的插槽:${slot}`
2203
- });
2204
- const target = entry ?? ensureEntry(slot);
2205
- target.contributions.set(contribution.id, {
2206
- contribution,
2207
- seq: target.nextSeq++
2208
- });
2209
- notify(slot);
2210
- const remove = () => {
2211
- if (target.contributions.delete(contribution.id)) notify(slot);
2212
- };
2213
- caller.effect(() => remove);
2214
- return remove;
2215
- },
2216
- list(slot) {
2217
- const entry = entries.get(slot);
2218
- if (entry === void 0) return [];
2219
- const ranked = [...entry.contributions.values()].sort((a, b) => a.contribution.order - b.contribution.order || a.seq - b.seq);
2220
- if (entry.def.mode !== "one" || ranked.length === 0) return ranked.map((item) => item.contribution);
2221
- return [ranked.reduce((best, item) => {
2222
- const delta = (item.contribution.precedence ?? 0) - (best.contribution.precedence ?? 0);
2223
- return delta > 0 || delta === 0 && item.seq > best.seq ? item : best;
2224
- }).contribution];
2225
- },
2226
- definition: (slot) => entries.get(slot)?.def,
2227
- activeLayout: activeLayoutOf,
2228
- hasProvider(slot) {
2229
- const active = activeLayoutOf();
2230
- return active !== void 0 && active.provides.includes(slot);
2231
- },
2232
- diagnostics: () => diagnostics,
2233
- subscribe(listener) {
2234
- listeners.add(listener);
2235
- return () => {
2236
- listeners.delete(listener);
2237
- };
2238
- },
2239
- version: () => revision
2240
- });
2241
- }
2242
- };
2243
- /** The React context carrying the active UI service. */
2244
- const UiContext = createContext(null);
2245
- /** Provide the UI service to a slot tree. */
2246
- function UiProvider(props) {
2247
- return jsx(UiContext.Provider, {
2248
- value: props.service,
2249
- children: props.children
2250
- });
2251
- }
2252
- /** Read the UI service; throws when a slot tree is mounted outside the runtime. */
2253
- function useUi() {
2254
- const service = useContext(UiContext);
2255
- if (service === null) throw new Error("useUi: no UiProvider in the tree");
2256
- return service;
2257
- }
2258
- /** Re-render on every registry change. */
2259
- function useUiVersion(service) {
2260
- return useSyncExternalStore(service.subscribe, service.version, service.version);
2261
- }
2262
- /** Keep one broken contribution from taking down the whole shell. */
2263
- var SlotBoundary = class extends Component {
2264
- state = { failed: false };
2265
- static getDerivedStateFromError() {
2266
- return { failed: true };
2267
- }
2268
- componentDidCatch(error) {
2269
- this.props.onError(error);
2270
- }
2271
- render() {
2272
- return this.state.failed ? null : this.props.children;
2273
- }
2274
- };
2275
- /** A region-slot outlet rendered by a layout. */
2276
- function Slot(props) {
2277
- const service = useUi();
2278
- useUiVersion(service);
2279
- const provided = service.hasProvider(props.name);
2280
- const entry = service.list(props.name);
2281
- const def = service.definition(props.name);
2282
- const context = props.context ?? {};
2283
- if (!provided) return null;
2284
- if (entry.length === 0) {
2285
- const fallback = def?.fallback;
2286
- return fallback?.(context) ?? null;
2287
- }
2288
- return jsx(Fragment, { children: entry.map((item) => jsx(SlotBoundary, {
2289
- onError: (error) => {
2290
- console.error(`[snap-rail ui] slot ${props.name} contribution ${item.id} failed`, error);
2291
- },
2292
- children: item.render(context)
2293
- }, item.id)) });
2294
- }
2295
- /** Re-render when the active layout changes. */
2296
- function useActiveLayout() {
2297
- const service = useUi();
2298
- useUiVersion(service);
2299
- return service.activeLayout();
2300
- }
2301
- //#endregion
2302
- //#region lib/types/fallback.js
2303
- /** A compact glyph for the window controls. */
2304
- function Glyph(props) {
2305
- return jsx("span", {
2306
- "aria-hidden": "true",
2307
- style: { lineHeight: 1 },
2308
- children: props.children
2309
- });
2310
- }
2311
- /** The fallback body. */
2312
- function FallbackShell(props) {
2313
- useUiVersion(props.ctx.ui);
2314
- usePagesVersion(props.ctx);
2315
- const active = props.ctx.pages.active();
2316
- const control = (action) => {
2317
- props.ctx.client.link.call("window.control", { action }).catch(() => {});
2318
- };
2319
- const header = jsxs("div", {
2320
- className: "snap-fallback-titlebar",
2321
- style: {
2322
- display: "flex",
2323
- alignItems: "center",
2324
- justifyContent: "space-between",
2325
- minHeight: 48,
2326
- paddingLeft: 16
2327
- },
2328
- children: [jsxs("span", {
2329
- style: {
2330
- color: "var(--snap-color-muted)",
2331
- fontSize: "var(--snap-text-sm)"
2332
- },
2333
- children: ["snap-rail", active !== void 0 ? ` · ${active.title}` : ""]
2334
- }), jsxs("div", {
2335
- style: {
2336
- display: "flex",
2337
- alignItems: "center",
2338
- gap: 4
2339
- },
2340
- children: [
2341
- jsx(Slot, {
2342
- name: UI_SLOT_IDS.settingsEntry,
2343
- context: {
2344
- presentation: "icon",
2345
- open: () => props.ctx.settings.open(),
2346
- isOpen: props.ctx.settings.isOpen()
2347
- }
2348
- }),
2349
- jsx(IconButton, {
2350
- icon: jsx(Glyph, { children: "—" }),
2351
- label: "最小化",
2352
- onClick: () => control("minimize")
2353
- }),
2354
- jsx(IconButton, {
2355
- icon: jsx(Glyph, { children: "□" }),
2356
- label: "最大化切换",
2357
- onClick: () => control("toggle-maximize")
2358
- }),
2359
- jsx(IconButton, {
2360
- icon: jsx(Glyph, { children: "×" }),
2361
- label: "关闭",
2362
- onClick: () => control("close")
2363
- })
2364
- ]
2365
- })]
2366
- });
2367
- return jsx(AppShell, {
2368
- header,
2369
- children: active !== void 0 ? active.render() : jsx("div", {
2370
- style: {
2371
- display: "flex",
2372
- minHeight: "100%",
2373
- alignItems: "center",
2374
- justifyContent: "center",
2375
- padding: 24
2376
- },
2377
- children: jsx(EmptyState, {
2378
- title: "尚未激活业务套件",
2379
- description: "打开设置的「插件管理」页,安装并启用一个业务套件;驱动也在同一处安装。",
2380
- action: jsx(Button, {
2381
- intent: "primary",
2382
- onClick: () => props.ctx.settings.open("plugins"),
2383
- children: "打开设置"
2384
- })
2385
- })
2386
- })
2387
- });
2388
- }
2389
- /** The fallback layout occupant. */
2390
- const fallbackPlugin = {
2391
- name: "snap-rail fallback layout",
2392
- inject: [
2393
- "ui",
2394
- "settings",
2395
- "pages",
2396
- "client"
2397
- ],
2398
- apply(ctx) {
2399
- ctx.ui.registerLayout(ctx, {
2400
- id: "fallback",
2401
- order: 200,
2402
- precedence: 0,
2403
- provides: [
2404
- UI_SLOT_IDS.titlebar,
2405
- UI_SLOT_IDS.titlebarActions,
2406
- UI_SLOT_IDS.sidebar,
2407
- UI_SLOT_IDS.statusbar,
2408
- UI_SLOT_IDS.settingsEntry
2409
- ],
2410
- window: {
2411
- width: 1280,
2412
- height: 800,
2413
- minWidth: 960,
2414
- minHeight: 600
2415
- },
2416
- ball: { size: 128 },
2417
- render: () => jsx(FallbackShell, { ctx })
2418
- });
2419
- }
2420
- };
2421
- //#endregion
2422
- //#region lib/types/settings-pages/appearance.js
2423
- const THEME_KEY = "ui.theme";
2424
- const WINDOW_KEY = "ui.window";
2425
- const BALL_KEY = "ui.ball";
2426
- const WINDOW_PRESETS = [
2427
- {
2428
- label: "1280 × 800",
2429
- width: 1280,
2430
- height: 800
2431
- },
2432
- {
2433
- label: "1440 × 900",
2434
- width: 1440,
2435
- height: 900
2436
- },
2437
- {
2438
- label: "1600 × 900",
2439
- width: 1600,
2440
- height: 900
2441
- },
2442
- {
2443
- label: "1920 × 1080",
2444
- width: 1920,
2445
- height: 1080
2446
- }
2447
- ];
2448
- const BALL_SIZES = [
2449
- 96,
2450
- 112,
2451
- 128,
2452
- 160,
2453
- 192
2454
- ];
2455
- /** Read a settings value through the host link. */
2456
- async function readSetting(link, key) {
2457
- const result = await link.call("settings.get", { key });
2458
- return result.ok ? result.value.value : void 0;
2459
- }
2460
- /** Write a settings value; `null` clears the row. */
2461
- async function writeSetting(link, key, value) {
2462
- await link.call("settings.set", {
2463
- key,
2464
- value
2465
- });
2466
- }
2467
- /** The appearance/display page. */
2468
- function AppearancePage() {
2469
- const { link } = useClient();
2470
- const [mode, setMode] = useState("dark");
2471
- const [windowPreset, setWindowPreset] = useState(void 0);
2472
- const [ballSize, setBallSize] = useState(128);
2473
- const [ballEnabled, setBallEnabled] = useState(true);
2474
- const [ballDockable, setBallDockable] = useState(true);
2475
- const [ballCollapse, setBallCollapse] = useState(true);
2476
- const [skins, setSkins] = useState([]);
2477
- const [error, setError] = useState(void 0);
2478
- const [busy, setBusy] = useState(false);
2479
- useEffect(() => {
2480
- Promise.all([
2481
- readSetting(link, THEME_KEY),
2482
- readSetting(link, WINDOW_KEY),
2483
- readSetting(link, BALL_KEY),
2484
- link.call("plugins.list", {})
2485
- ]).then(([theme, windowRow, ballRow, plugins]) => {
2486
- const themeMode = theme?.mode;
2487
- if (themeMode === "system" || themeMode === "light" || themeMode === "dark") setMode(themeMode);
2488
- const windowProfile = windowRow;
2489
- if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
2490
- const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
2491
- setWindowPreset(preset?.label);
2492
- }
2493
- const ballProfile = ballRow;
2494
- if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
2495
- if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.enabled === "boolean") setBallEnabled(ballProfile.enabled);
2496
- if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.dockable === "boolean") setBallDockable(ballProfile.dockable);
2497
- if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
2498
- if (plugins.ok) setSkins(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
2499
- name: plugin.packageName,
2500
- title: plugin.title ?? plugin.packageName,
2501
- enabled: plugin.enabled
2502
- })));
2503
- }).catch((cause) => {
2504
- setError(cause instanceof Error ? cause.message : String(cause));
2505
- });
2506
- return subscribeFrame(link, "settings/changed", settingsChangedSchema, (change) => {
2507
- if (change.key === THEME_KEY) {
2508
- const next = change.value?.mode;
2509
- if (next === "system" || next === "light" || next === "dark") setMode(next);
2510
- }
2511
- });
2512
- }, [link]);
2513
- const saveTheme = (next) => {
2514
- setMode(next);
2515
- writeSetting(link, THEME_KEY, { mode: next }).catch((cause) => {
2516
- setError(cause instanceof Error ? cause.message : String(cause));
2517
- });
2518
- };
2519
- const saveWindow = (width, height, label) => {
2520
- setWindowPreset(label);
2521
- writeSetting(link, WINDOW_KEY, {
2522
- width,
2523
- height,
2524
- minWidth: 960,
2525
- minHeight: 600
2526
- }).catch((cause) => {
2527
- setError(cause instanceof Error ? cause.message : String(cause));
2528
- });
2529
- };
2530
- const resetWindow = () => {
2531
- setWindowPreset(void 0);
2532
- writeSetting(link, WINDOW_KEY, null).catch((cause) => {
2533
- setError(cause instanceof Error ? cause.message : String(cause));
2534
- });
2535
- };
2536
- const saveBall = (patch) => {
2537
- const next = {
2538
- size: patch.size ?? ballSize,
2539
- enabled: patch.enabled ?? ballEnabled,
2540
- dockable: patch.dockable ?? ballDockable,
2541
- collapse: patch.collapse ?? ballCollapse
2542
- };
2543
- if (patch.size !== void 0) setBallSize(patch.size);
2544
- if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
2545
- if (patch.dockable !== void 0) setBallDockable(patch.dockable);
2546
- if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
2547
- writeSetting(link, BALL_KEY, next).catch((cause) => {
2548
- setError(cause instanceof Error ? cause.message : String(cause));
2549
- });
2550
- };
2551
- const toggleSkin = (skin) => {
2552
- setBusy(true);
2553
- link.call("plugins.set-enabled", {
2554
- name: skin.name,
2555
- enabled: !skin.enabled
2556
- }).then((result) => {
2557
- if (!result.ok) {
2558
- setError(rpcErrorText(result.error));
2559
- return;
2560
- }
2561
- setSkins((current) => current.map((item) => item.name === skin.name ? {
2562
- ...item,
2563
- enabled: !item.enabled
2564
- } : item));
2565
- }).catch((cause) => {
2566
- setError(cause instanceof Error ? cause.message : String(cause));
2567
- }).finally(() => {
2568
- setBusy(false);
2569
- });
2570
- };
2571
- return jsx(Page, {
2572
- title: "外观与显示",
2573
- description: "主题、皮肤、主窗口尺寸和悬浮球外观;保存后立即生效。",
2574
- children: jsxs(Stack, {
2575
- gap: "lg",
2576
- children: [
2577
- error !== void 0 && jsx("div", {
2578
- role: "alert",
2579
- style: { color: "var(--snap-color-danger)" },
2580
- children: error
2581
- }),
2582
- jsx(Section, {
2583
- title: "主题模式",
2584
- children: jsx(Tabs, {
2585
- value: mode,
2586
- onValueChange: (value) => saveTheme(value),
2587
- children: jsxs(TabsList, {
2588
- "aria-label": "主题模式",
2589
- children: [
2590
- jsx(TabsTrigger, {
2591
- value: "system",
2592
- children: "跟随系统"
2593
- }),
2594
- jsx(TabsTrigger, {
2595
- value: "light",
2596
- children: "白天"
2597
- }),
2598
- jsx(TabsTrigger, {
2599
- value: "dark",
2600
- children: "黑夜"
2601
- })
2602
- ]
2603
- })
2604
- })
2605
- }),
2606
- jsx(Section, {
2607
- title: "界面皮肤",
2608
- description: "皮肤由独立插件提供;启用后需要重启终端。",
2609
- children: jsxs(Stack, {
2610
- gap: "sm",
2611
- children: [jsxs(Row, {
2612
- gap: "sm",
2613
- align: "center",
2614
- children: [jsx(Badge, {
2615
- intent: "success",
2616
- children: "默认(内置)"
2617
- }), jsx("span", {
2618
- style: {
2619
- color: "var(--snap-color-muted)",
2620
- fontSize: "var(--snap-text-sm)"
2621
- },
2622
- children: "工业钴蓝,始终可用"
2623
- })]
2624
- }), skins.length === 0 ? jsx("span", {
2625
- style: { color: "var(--snap-color-muted)" },
2626
- children: "尚未安装其他皮肤插件。"
2627
- }) : skins.map((skin) => jsxs(Row, {
2628
- gap: "sm",
2629
- align: "center",
2630
- children: [
2631
- jsx("span", { children: skin.title }),
2632
- jsx(Badge, {
2633
- intent: skin.enabled ? "success" : "neutral",
2634
- children: skin.enabled ? "已启用" : "未启用"
2635
- }),
2636
- jsx(Button, {
2637
- size: "sm",
2638
- emphasis: "outline",
2639
- disabled: busy,
2640
- onClick: () => toggleSkin(skin),
2641
- children: skin.enabled ? "停用" : "启用"
2642
- })
2643
- ]
2644
- }, skin.name))]
2645
- })
2646
- }),
2647
- jsx(Section, {
2648
- title: "主窗口",
2649
- description: "布局/套件会声明推荐尺寸;这里的选择会覆盖布局推荐。",
2650
- children: jsxs(Stack, {
2651
- gap: "sm",
2652
- children: [jsxs(Row, {
2653
- gap: "sm",
2654
- wrap: true,
2655
- children: [WINDOW_PRESETS.map((preset) => jsx(Button, {
2656
- size: "sm",
2657
- intent: windowPreset === preset.label ? "primary" : "neutral",
2658
- emphasis: windowPreset === preset.label ? "solid" : "outline",
2659
- onClick: () => saveWindow(preset.width, preset.height, preset.label),
2660
- children: preset.label
2661
- }, preset.label)), jsx(Button, {
2662
- size: "sm",
2663
- emphasis: "ghost",
2664
- onClick: resetWindow,
2665
- children: "跟随布局"
2666
- })]
2667
- }), jsxs("span", {
2668
- style: {
2669
- color: "var(--snap-color-muted)",
2670
- fontSize: "var(--snap-text-sm)"
2671
- },
2672
- children: ["当前:", windowPreset ?? "跟随布局推荐 / 默认 1280 × 800"]
2673
- })]
2674
- })
2675
- }),
2676
- jsx(Section, {
2677
- title: "悬浮球",
2678
- description: "球面尺寸与停泊行为;球内显示内容由业务套件决定。",
2679
- children: jsxs(Stack, {
2680
- gap: "md",
2681
- children: [jsx(Row, {
2682
- gap: "sm",
2683
- wrap: true,
2684
- align: "center",
2685
- children: BALL_SIZES.map((size) => jsxs(Button, {
2686
- size: "sm",
2687
- intent: ballSize === size ? "primary" : "neutral",
2688
- emphasis: ballSize === size ? "solid" : "outline",
2689
- onClick: () => saveBall({ size }),
2690
- children: [size, "px"]
2691
- }, size))
2692
- }), jsxs(Row, {
2693
- gap: "lg",
2694
- wrap: true,
2695
- align: "center",
2696
- children: [
2697
- jsx(Switch, {
2698
- label: "启用悬浮球",
2699
- checked: ballEnabled,
2700
- onCheckedChange: (enabled) => saveBall({ enabled })
2701
- }),
2702
- jsx(Switch, {
2703
- label: "允许贴边",
2704
- checked: ballDockable,
2705
- onCheckedChange: (dockable) => saveBall({ dockable })
2706
- }),
2707
- jsx(Switch, {
2708
- label: "贴边后收起",
2709
- checked: ballCollapse,
2710
- onCheckedChange: (collapse) => saveBall({ collapse })
2711
- })
2712
- ]
2713
- })]
2714
- })
2715
- })
2716
- ]
2717
- })
2718
- });
2719
- }
2720
426
  //#endregion
2721
427
  //#region lib/types/settings-pages/plugins.js
428
+ /** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
429
+ * Electron or in tests. Inlined rather than imported from the app-internal
430
+ * kernel package: it never ships in the installer, and the packaged-app gate
431
+ * refuses any shipped `@snap-rail/ui` lib that requires it. */
432
+ function droppedZipPath(file) {
433
+ const zipPathOf = globalThis.snapRail?.zipPathOf;
434
+ if (typeof zipPathOf !== "function") return null;
435
+ return zipPathOf(file);
436
+ }
2722
437
  /** Human labels for the package kinds. */
2723
438
  const KIND_LABELS = {
2724
439
  skin: "界面风格",
@@ -2731,6 +446,22 @@ const PROFILE_LABELS = {
2731
446
  integrated: "图表桥接",
2732
447
  custom: "自定义界面"
2733
448
  };
449
+ /** Search rows shown before the tail is folded into a counter. */
450
+ const SEARCH_ROW_CAP = 20;
451
+ /** The plus glyph for the page's install entry. */
452
+ function PlusIcon() {
453
+ return jsx("svg", {
454
+ viewBox: "0 0 24 24",
455
+ width: "18",
456
+ height: "18",
457
+ fill: "none",
458
+ stroke: "currentColor",
459
+ strokeWidth: "2.4",
460
+ strokeLinecap: "round",
461
+ "aria-hidden": "true",
462
+ children: jsx("path", { d: "M12 5v14M5 12h14" })
463
+ });
464
+ }
2734
465
  /** Collapse entry rows into package rows (one master switch per package). */
2735
466
  function packageRows(plugins) {
2736
467
  const byPackage = /* @__PURE__ */ new Map();
@@ -2756,15 +487,44 @@ function packageRows(plugins) {
2756
487
  }
2757
488
  return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
2758
489
  }
490
+ /** The preview's signature line (one row in the confirm card). */
491
+ function signatureText(signature, viaUrl) {
492
+ if (signature.state === "verified") return {
493
+ text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
494
+ warning: false
495
+ };
496
+ const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
497
+ return {
498
+ text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
499
+ warning: true
500
+ };
501
+ }
502
+ /** Does the input name an http(s) address? */
503
+ const isHttpUrl = (text) => /^https?:\/\//i.test(text);
504
+ /** Does the input look like a filesystem path (drive letter, UNC, posix
505
+ * root, or a .zip name with a separator in it)? */
506
+ const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
2759
507
  /** The plugin management page. */
2760
508
  function PluginsPage({ ctx }) {
2761
509
  const [rows, setRows] = useState([]);
2762
510
  const [error, setError] = useState(void 0);
2763
511
  const [busy, setBusy] = useState(void 0);
2764
512
  const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
513
+ const [restartNeeded, setRestartNeeded] = useState(false);
514
+ const [installOpen, setInstallOpen] = useState(false);
515
+ const [phase, setPhase] = useState({ kind: "idle" });
516
+ const [message, setMessage] = useState(void 0);
517
+ const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
518
+ const [updatingName, setUpdatingName] = useState(void 0);
519
+ const [keyChange, setKeyChange] = useState(void 0);
520
+ const [query, setQuery] = useState("");
521
+ const [searchResults, setSearchResults] = useState(void 0);
522
+ const [searching, setSearching] = useState(false);
523
+ const [dragging, setDragging] = useState(false);
524
+ const link = ctx.client.link;
2765
525
  const load = () => {
2766
526
  setError(void 0);
2767
- ctx.client.link.call("plugins.list", {}).then((result) => {
527
+ link.call("plugins.list", {}).then((result) => {
2768
528
  if (!result.ok) {
2769
529
  setError(rpcErrorText(result.error));
2770
530
  return;
@@ -2773,11 +533,30 @@ function PluginsPage({ ctx }) {
2773
533
  }).catch((cause) => {
2774
534
  setError(cause instanceof Error ? cause.message : String(cause));
2775
535
  });
536
+ link.call("plugins.updates-check", {}).then((result) => {
537
+ if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
538
+ }).catch(() => void 0);
539
+ };
540
+ useEffect(() => {
541
+ load();
542
+ }, [link]);
543
+ const openInstall = () => {
544
+ setQuery("");
545
+ setSearchResults(void 0);
546
+ setMessage(void 0);
547
+ setDragging(false);
548
+ setInstallOpen(true);
549
+ };
550
+ const closeInstall = () => {
551
+ setInstallOpen(false);
552
+ setQuery("");
553
+ setSearchResults(void 0);
554
+ setMessage(void 0);
555
+ setDragging(false);
2776
556
  };
2777
- useEffect(load, []);
2778
557
  const toggle = (row, enabled) => {
2779
558
  setBusy(row.packageName);
2780
- ctx.client.link.call("plugins.set-enabled", {
559
+ link.call("plugins.set-enabled", {
2781
560
  name: row.packageName,
2782
561
  enabled
2783
562
  }).then((result) => {
@@ -2799,12 +578,13 @@ function PluginsPage({ ctx }) {
2799
578
  const uninstall = (row) => {
2800
579
  if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
2801
580
  setBusy(row.packageName);
2802
- ctx.client.link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
581
+ link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
2803
582
  if (!result.ok) {
2804
583
  setError(rpcErrorText(result.error));
2805
584
  return;
2806
585
  }
2807
586
  setTouched((current) => new Set(current).add(row.packageName));
587
+ setRestartNeeded(true);
2808
588
  load();
2809
589
  }).catch((cause) => {
2810
590
  setError(cause instanceof Error ? cause.message : String(cause));
@@ -2812,534 +592,691 @@ function PluginsPage({ ctx }) {
2812
592
  setBusy(void 0);
2813
593
  });
2814
594
  };
2815
- const groups = /* @__PURE__ */ new Map();
2816
- for (const row of rows) {
2817
- const bucket = groups.get(row.category);
2818
- if (bucket === void 0) groups.set(row.category, [row]);
2819
- else bucket.push(row);
2820
- }
2821
- return jsx(Page, {
2822
- title: "插件管理",
2823
- description: "安装驱动、业务页面和界面风格。启用/停用写入 plugins.yml,渲染端在下一次重启后生效。",
2824
- actions: jsx(Button, {
2825
- intent: "neutral",
2826
- emphasis: "outline",
2827
- onClick: load,
2828
- children: "刷新"
2829
- }),
2830
- children: jsxs(Stack, {
2831
- gap: "lg",
2832
- children: [error !== void 0 && jsx("div", {
2833
- role: "alert",
2834
- style: { color: "var(--snap-color-danger)" },
2835
- children: error
2836
- }), rows.length === 0 ? jsx(EmptyState, {
2837
- title: "还没有安装插件",
2838
- description: "把插件 zip 拖入插件安装入口,或从插件源搜索安装。"
2839
- }) : [...groups.entries()].map(([category, entries]) => jsx(Section, {
2840
- title: category,
2841
- children: jsxs(Table, { children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
2842
- jsx(TableHead, { children: "名称" }),
2843
- jsx(TableHead, { children: "类型" }),
2844
- jsx(TableHead, { children: "版本" }),
2845
- jsx(TableHead, { children: "状态" }),
2846
- jsx(TableHead, { children: "操作" })
2847
- ] }) }), jsx(TableBody, { children: entries.map((row) => jsxs(TableRow, { children: [
2848
- jsx(TableCell, { children: jsxs("div", {
2849
- style: {
2850
- display: "flex",
2851
- flexDirection: "column"
2852
- },
2853
- children: [jsxs("span", {
2854
- style: {
2855
- display: "flex",
2856
- alignItems: "center",
2857
- gap: "var(--snap-space-sm)"
2858
- },
2859
- children: [row.title, row.builtinDefault && jsx(Badge, {
2860
- intent: "neutral",
2861
- children: "内置默认"
2862
- })]
2863
- }), jsx("span", {
2864
- style: {
2865
- color: "var(--snap-color-muted)",
2866
- fontSize: "var(--snap-text-xs)"
2867
- },
2868
- children: row.packageName
2869
- })]
2870
- }) }),
2871
- jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
2872
- intent: "neutral",
2873
- children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
2874
- })] }),
2875
- jsx(TableCell, { children: row.version ?? "—" }),
2876
- jsx(TableCell, { children: row.builtinDefault ? jsx(Badge, {
2877
- intent: "success",
2878
- children: "始终随底座"
2879
- }) : jsxs("div", {
2880
- style: {
2881
- display: "flex",
2882
- alignItems: "center",
2883
- gap: "var(--snap-space-sm)"
2884
- },
2885
- children: [jsx(Switch, {
2886
- checked: row.enabled,
2887
- disabled: busy === row.packageName,
2888
- onCheckedChange: (next) => toggle(row, next),
2889
- "aria-label": `启用 ${row.title}`
2890
- }), touched.has(row.packageName) && jsx(Badge, {
2891
- intent: "warning",
2892
- children: "待重启"
2893
- })]
2894
- }) }),
2895
- jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
2896
- style: { color: "var(--snap-color-muted)" },
2897
- children: "内置默认不可卸载"
2898
- }) : jsx(Button, {
2899
- intent: "danger",
2900
- emphasis: "ghost",
2901
- size: "sm",
2902
- disabled: busy === row.packageName,
2903
- onClick: () => uninstall(row),
2904
- children: "卸载"
2905
- }) })
2906
- ] }, row.packageName)) })] })
2907
- }, category))]
2908
- })
2909
- });
2910
- }
2911
- //#endregion
2912
- //#region lib/types/settings.js
2913
- /** Sort pages by order, then registration time. */
2914
- function orderedPages(pages) {
2915
- return [...pages].sort((a, b) => a.page.order - b.page.order || a.seq - b.seq).map((entry) => entry.page);
2916
- }
2917
- /** A page-level boundary: one broken settings page must not take down the shell. */
2918
- var SettingsPageBoundary = class extends Component {
2919
- state = { failed: false };
2920
- static getDerivedStateFromError() {
2921
- return { failed: true };
2922
- }
2923
- componentDidCatch(error) {
2924
- console.error(`[snap-rail ui] settings page ${this.props.page} failed`, error);
2925
- }
2926
- render() {
2927
- return this.state.failed ? jsx(EmptyState, {
2928
- title: "设置页加载失败",
2929
- description: "该页面抛出了异常,其他设置页仍可使用。"
2930
- }) : this.props.children;
2931
- }
2932
- };
2933
- /** The gear glyph used by the default trigger. */
2934
- function GearIcon() {
2935
- return jsxs("svg", {
2936
- viewBox: "0 0 24 24",
2937
- width: "18",
2938
- height: "18",
2939
- fill: "none",
2940
- stroke: "currentColor",
2941
- strokeWidth: "1.8",
2942
- "aria-hidden": "true",
2943
- children: [jsx("circle", {
2944
- cx: "12",
2945
- cy: "12",
2946
- r: "3"
2947
- }), 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" })]
2948
- });
2949
- }
2950
- /** The default settings trigger; the layout decides placement/presentation. */
2951
- function SettingsEntry(props) {
2952
- if (props.presentation === "label") return jsx(Button, {
2953
- intent: "neutral",
2954
- emphasis: "ghost",
2955
- icon: jsx(GearIcon, {}),
2956
- onClick: props.open,
2957
- children: "设置"
2958
- });
2959
- return jsx(IconButton, {
2960
- icon: jsx(GearIcon, {}),
2961
- label: "设置",
2962
- active: props.isOpen,
2963
- onClick: props.open
2964
- });
2965
- }
2966
- /** The default settings surface. */
2967
- function SettingsSurface(props) {
2968
- const { service } = props;
2969
- useSyncExternalStore(service.subscribe, service.version, service.version);
2970
- const open = service.isOpen();
2971
- const pages = service.listPages();
2972
- const activeId = service.activePage();
2973
- const active = pages.find((page) => page.id === activeId);
2974
- const groups = /* @__PURE__ */ new Map();
2975
- for (const page of pages) {
2976
- const group = page.group ?? "其他";
2977
- const bucket = groups.get(group);
2978
- if (bucket === void 0) groups.set(group, [page]);
2979
- else bucket.push(page);
2980
- }
2981
- return jsx(Dialog, {
2982
- open,
2983
- onOpenChange: (next) => {
2984
- if (!next) service.close();
2985
- },
2986
- children: jsx(DialogContent, {
2987
- presentation: "fullscreen",
2988
- showClose: false,
2989
- children: jsxs("div", {
2990
- ...part("settings", "root"),
2991
- className: "snap-settings",
2992
- children: [jsxs("header", {
2993
- ...part("settings", "header"),
2994
- className: "snap-settings-header",
2995
- children: [jsx(DialogTitle, { children: "设置" }), jsx(Button, {
2996
- intent: "neutral",
2997
- emphasis: "ghost",
2998
- onClick: () => service.close(),
2999
- children: "关闭"
3000
- })]
3001
- }), jsxs("div", {
3002
- ...part("settings", "body"),
3003
- className: "snap-settings-body",
3004
- children: [jsx("nav", {
3005
- ...part("settings", "nav"),
3006
- className: "snap-settings-nav",
3007
- "aria-label": "设置页",
3008
- children: [...groups.entries()].map(([group, entries]) => jsxs("div", {
3009
- ...part("settings", "group"),
3010
- className: "snap-settings-group",
3011
- children: [jsx("div", {
3012
- ...part("settings", "group-title"),
3013
- className: "snap-settings-group-title",
3014
- children: group
3015
- }), entries.map((page) => jsxs("button", {
3016
- type: "button",
3017
- ...part("settings", "nav-item"),
3018
- className: cn("snap-settings-nav-item", page.id === activeId && "is-active"),
3019
- "data-active": page.id === activeId || void 0,
3020
- "aria-current": page.id === activeId ? "page" : void 0,
3021
- onClick: () => service.open(page.id),
3022
- children: [page.icon !== void 0 && jsx("span", {
3023
- ...part("settings", "nav-icon"),
3024
- children: page.icon
3025
- }), jsx("span", { children: page.title })]
3026
- }, page.id))]
3027
- }, group))
3028
- }), jsx("main", {
3029
- ...part("settings", "content"),
3030
- className: "snap-settings-content",
3031
- "data-active-page": activeId,
3032
- children: active === void 0 ? jsx(EmptyState, {
3033
- title: "暂无设置页",
3034
- description: "安装或启用一个带设置页的插件后,它会出现在这里。"
3035
- }) : jsx(SettingsPageBoundary, {
3036
- page: active.id,
3037
- children: active.render()
3038
- })
3039
- })]
3040
- })]
3041
- })
3042
- })
3043
- });
3044
- }
3045
- /** Mount the settings registry and its default slot contributions. */
3046
- const settingsPlugin = {
3047
- name: "snap-rail settings",
3048
- inject: ["ui"],
3049
- apply(ctx) {
3050
- const pages = /* @__PURE__ */ new Map();
3051
- const listeners = /* @__PURE__ */ new Set();
3052
- let open = false;
3053
- let requestedId;
3054
- let revision = 0;
3055
- let seq = 0;
3056
- const notify = (kind) => {
3057
- revision += 1;
3058
- for (const listener of listeners) listener();
3059
- ctx.emit(kind === "pages" ? "settings/pages-changed" : "settings/open-changed");
3060
- };
3061
- const firstId = () => orderedPages(pages.values())[0]?.id;
3062
- const activeId = () => {
3063
- if (!open) return void 0;
3064
- if (requestedId !== void 0 && pages.has(requestedId)) return requestedId;
3065
- return firstId();
3066
- };
3067
- const service = {
3068
- registerPage(caller, page) {
3069
- pages.set(page.id, {
3070
- page,
3071
- seq: seq++
595
+ const inspectPath = (zipPath) => {
596
+ setMessage(void 0);
597
+ link.call("plugins.inspect", { zipPath }).then((result) => {
598
+ if (!result.ok) {
599
+ setPhase({
600
+ kind: "error",
601
+ message: `读取插件包失败:${rpcErrorText(result.error)}`
3072
602
  });
3073
- notify("pages");
3074
- const remove = () => {
3075
- if (pages.delete(page.id)) notify("pages");
3076
- };
3077
- caller.effect(() => remove);
3078
- return remove;
3079
- },
3080
- listPages: () => orderedPages(pages.values()),
3081
- open(pageId) {
3082
- if (pageId !== void 0) requestedId = pageId;
3083
- if (open && pageId === void 0) return;
3084
- open = true;
3085
- notify("open");
3086
- },
3087
- close() {
3088
- if (!open) return;
3089
- open = false;
3090
- notify("open");
3091
- },
3092
- toggle() {
3093
- if (open) service.close();
3094
- else service.open();
3095
- },
3096
- isOpen: () => open,
3097
- activePage: activeId,
3098
- subscribe(listener) {
3099
- listeners.add(listener);
3100
- return () => {
3101
- listeners.delete(listener);
3102
- };
3103
- },
3104
- version: () => revision
3105
- };
3106
- ctx.provide("settings", service);
3107
- ctx.settings.registerPage(ctx, {
3108
- id: "plugins",
3109
- title: "插件管理",
3110
- group: "系统",
3111
- order: 0,
3112
- keywords: [
3113
- "安装",
3114
- "启用",
3115
- "卸载",
3116
- "驱动",
3117
- "皮肤"
3118
- ],
3119
- render: () => jsx(PluginsPage, { ctx })
3120
- });
3121
- ctx.settings.registerPage(ctx, {
3122
- id: "appearance",
3123
- title: "外观与显示",
3124
- group: "系统",
3125
- order: 1,
3126
- keywords: [
3127
- "主题",
3128
- "皮肤",
3129
- "窗口",
3130
- "悬浮球",
3131
- "尺寸"
3132
- ],
3133
- render: () => jsx(AppearancePage, {})
3134
- });
3135
- ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsEntry, {
3136
- id: "settings.default-entry",
3137
- order: 0,
3138
- render: (context) => jsx(SettingsEntry, {
3139
- presentation: context.presentation,
3140
- open: context.open,
3141
- isOpen: context.isOpen
3142
- })
3143
- });
3144
- ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
3145
- id: "settings.default-surface",
3146
- order: 0,
3147
- render: () => jsx(SettingsSurface, { service })
603
+ return;
604
+ }
605
+ setPhase({
606
+ kind: "confirm",
607
+ zipPath,
608
+ archive: result.value.archive,
609
+ viaUrl: false,
610
+ risk: false
611
+ });
612
+ }).catch((cause) => setPhase({
613
+ kind: "error",
614
+ message: String(cause)
615
+ }));
616
+ };
617
+ const inspectFromUrl = (url) => {
618
+ setMessage(void 0);
619
+ link.call("plugins.inspect-from-url", { url }).then((result) => {
620
+ if (!result.ok) {
621
+ setPhase({
622
+ kind: "error",
623
+ message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
624
+ });
625
+ return;
626
+ }
627
+ setPhase({
628
+ kind: "confirm",
629
+ zipPath: result.value.zipPath,
630
+ archive: result.value.archive,
631
+ viaUrl: true,
632
+ risk: false
633
+ });
634
+ }).catch((cause) => setPhase({
635
+ kind: "error",
636
+ message: String(cause)
637
+ }));
638
+ };
639
+ const runInstall = (zipPath, archive) => {
640
+ setPhase({ kind: "installing" });
641
+ (archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
642
+ if (!result.ok) {
643
+ setPhase({
644
+ kind: "error",
645
+ message: `安装失败:${rpcErrorText(result.error)}`
646
+ });
647
+ return;
648
+ }
649
+ setPhase({ kind: "idle" });
650
+ closeInstall();
651
+ setRestartNeeded(true);
652
+ load();
653
+ }).catch((cause) => setPhase({
654
+ kind: "error",
655
+ message: String(cause)
656
+ }));
657
+ };
658
+ /** The update pill's click: a plain update installs directly; a key
659
+ * change confirmation intercepts first. */
660
+ const requestUpdate = (update) => {
661
+ if (update.keyChanged === true) {
662
+ setKeyChange(update);
663
+ return;
664
+ }
665
+ updateNow(update.name);
666
+ };
667
+ /** The update itself: the feed's entry, no preview. */
668
+ const updateNow = (name) => {
669
+ setKeyChange(void 0);
670
+ setUpdatingName(name);
671
+ setMessage(void 0);
672
+ link.call("plugins.remote-install", { name }).then((result) => {
673
+ setUpdatingName(void 0);
674
+ if (!result.ok) {
675
+ setMessage({
676
+ kind: "error",
677
+ text: rpcErrorText(result.error)
678
+ });
679
+ return;
680
+ }
681
+ setRestartNeeded(true);
682
+ load();
683
+ }).catch(() => setUpdatingName(void 0));
684
+ };
685
+ /** The tri-form input: address/path → inspect, anything else → feed search. */
686
+ const submitQuery = () => {
687
+ const text = query.trim();
688
+ if (text === "") return;
689
+ setMessage(void 0);
690
+ if (isHttpUrl(text)) {
691
+ inspectFromUrl(text);
692
+ return;
693
+ }
694
+ if (looksLikePath(text)) {
695
+ inspectPath(text);
696
+ return;
697
+ }
698
+ runSearch(text);
699
+ };
700
+ const runSearch = (text) => {
701
+ setSearching(true);
702
+ setSearchResults(void 0);
703
+ link.call("plugins.remote-list", {}).then((result) => {
704
+ setSearching(false);
705
+ if (!result.ok) {
706
+ setMessage({
707
+ kind: "error",
708
+ text: `搜索失败:${rpcErrorText(result.error)}`
709
+ });
710
+ return;
711
+ }
712
+ const needle = text.toLowerCase();
713
+ setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
714
+ }).catch((cause) => {
715
+ setSearching(false);
716
+ setMessage({
717
+ kind: "error",
718
+ text: String(cause)
719
+ });
3148
720
  });
3149
- }
3150
- };
3151
- /** The settings page info the slot context exposes. */
3152
- function settingsPageInfo(page) {
3153
- return {
3154
- id: page.id,
3155
- title: page.title,
3156
- ...page.group !== void 0 ? { group: page.group } : {},
3157
- order: page.order
3158
721
  };
3159
- }
3160
- //#endregion
3161
- //#region lib/types/runtime.js
3162
- /** The React context carrying the host link/surface into builtin pages. */
3163
- const ClientContext = createContext(null);
3164
- /** Provide the client services to builtin page components. */
3165
- function ClientProvider(props) {
3166
- return jsx(ClientContext.Provider, {
3167
- value: props.service,
3168
- children: props.children
3169
- });
3170
- }
3171
- /** Read the client services (host link + surface) from a builtin page. */
3172
- function useClient() {
3173
- const service = useContext(ClientContext);
3174
- if (service === null) throw new Error("useClient: no ClientProvider in the tree");
3175
- return service;
3176
- }
3177
- /** Re-render on settings open/page changes. */
3178
- function useSettingsVersion(ctx) {
3179
- return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
3180
- }
3181
- /** Apply the active layout's stage profiles to the host. */
3182
- function StageProfiles(props) {
3183
- const link = props.ctx.client.link;
3184
- const layout = props.layout;
3185
- useEffect(() => {
3186
- if (layout?.window !== void 0) link.call("shell.window.configure", { profile: layout.window }).catch(() => {});
3187
- if (layout?.ball !== void 0) link.call("shell.ball.configure", { profile: layout.ball }).catch(() => {});
3188
- }, [layout?.id]);
3189
- return null;
3190
- }
3191
- /** The global overlay host: registry-owned surfaces do not depend on a layout. */
3192
- function OverlayHost(props) {
3193
- useUiVersion(props.ctx.ui);
3194
- useSettingsVersion(props.ctx);
3195
- const overlays = props.ctx.ui.list(UI_SLOT_IDS.overlay);
3196
- const settingsSurfaces = props.ctx.settings.isOpen() ? props.ctx.ui.list(UI_SLOT_IDS.settingsSurface) : [];
3197
- const context = {
3198
- pages: props.ctx.settings.listPages().map((page) => ({
3199
- id: page.id,
3200
- title: page.title,
3201
- ...page.group !== void 0 ? { group: page.group } : {},
3202
- order: page.order
3203
- })),
3204
- ...props.ctx.settings.activePage() !== void 0 ? { activeId: props.ctx.settings.activePage() } : {},
3205
- close: () => props.ctx.settings.close()
722
+ /** A search-result entry that is not installed yet: preview first. The
723
+ * entry's own coordinates decide where the zip comes from — a federation
724
+ * row downloads from the author's release, a same-directory row from its
725
+ * feed base. */
726
+ const previewRemote = (item) => {
727
+ if (item.url !== void 0) {
728
+ inspectFromUrl(item.url);
729
+ return;
730
+ }
731
+ if (item.feedUrl === void 0 || item.file === void 0) return;
732
+ const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
733
+ inspectFromUrl(`${base}${item.file}`);
3206
734
  };
3207
- return jsxs(Fragment, { children: [overlays.map((item) => jsx("span", { children: item.render({ surface: "main" }) }, item.id)), settingsSurfaces.map((item) => jsx("span", { children: item.render(context) }, item.id))] });
3208
- }
3209
- /** The floating settings fallback, rendered only when no layout provides the seat. */
3210
- function SettingsFallbackHost(props) {
3211
- useUiVersion(props.ctx.ui);
3212
- useSettingsVersion(props.ctx);
3213
- if (props.ctx.ui.hasProvider(UI_SLOT_IDS.settingsEntry)) return null;
3214
- const entry = props.ctx.ui.list(UI_SLOT_IDS.settingsEntry)[0];
3215
- if (entry === void 0) return null;
3216
- return jsx("div", {
3217
- "data-snap-part": "settings.fallback",
3218
- style: {
3219
- position: "fixed",
3220
- right: 16,
3221
- bottom: 16,
3222
- zIndex: "var(--snap-z-overlay)"
3223
- },
3224
- children: entry.render({
3225
- presentation: "icon",
3226
- open: () => props.ctx.settings.open(),
3227
- isOpen: props.ctx.settings.isOpen()
3228
- })
3229
- });
3230
- }
3231
- /** The operator-window root. */
3232
- function MainRoot(props) {
3233
- const layout = useActiveLayout();
3234
- return jsxs(Fragment, { children: [
3235
- jsx(StageProfiles, {
3236
- ctx: props.ctx,
3237
- layout
735
+ const onDrop = (event) => {
736
+ event.preventDefault();
737
+ setDragging(false);
738
+ const file = event.dataTransfer.files[0];
739
+ if (file === void 0) return;
740
+ if (!file.name.toLowerCase().endsWith(".zip")) {
741
+ setMessage({
742
+ kind: "error",
743
+ text: "只支持 .zip 插件包或组合包"
744
+ });
745
+ return;
746
+ }
747
+ const zipPath = droppedZipPath(file);
748
+ if (zipPath === null) {
749
+ setMessage({
750
+ kind: "error",
751
+ text: "当前环境不支持拖拽安装(缺少路径桥)"
752
+ });
753
+ return;
754
+ }
755
+ inspectPath(zipPath);
756
+ };
757
+ const restart = () => {
758
+ link.call("window.relaunch", {});
759
+ };
760
+ const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
761
+ const spans = /* @__PURE__ */ new Map();
762
+ for (let index = 0; index < rows.length;) {
763
+ const category = rows[index].category;
764
+ let end = index + 1;
765
+ while (end < rows.length && rows[end].category === category) end += 1;
766
+ spans.set(index, end - index);
767
+ index = end;
768
+ }
769
+ return jsxs(Page, {
770
+ title: "插件管理",
771
+ titleExtra: jsx(IconButton, {
772
+ icon: jsx(PlusIcon, {}),
773
+ label: "安装插件",
774
+ onClick: openInstall
3238
775
  }),
3239
- layout === void 0 ? jsx("div", {
3240
- style: { padding: 24 },
3241
- children: "没有已加载的布局插件。"
3242
- }) : layout.render(),
3243
- jsx(OverlayHost, { ctx: props.ctx }),
3244
- jsx(SettingsFallbackHost, { ctx: props.ctx })
3245
- ] });
3246
- }
3247
- /** The fallback ball face used when no plugin occupies `shell.ball`. */
3248
- function BallRoot(props) {
3249
- useUiVersion(props.ctx.ui);
3250
- const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
3251
- if (occupant !== void 0) return jsx("div", {
3252
- style: {
3253
- width: "100%",
3254
- height: "100%"
3255
- },
3256
- children: occupant.render({ surface: "ball" })
3257
- });
3258
- return jsx("div", {
3259
- "data-snap-part": "ball.root",
3260
- style: {
3261
- display: "flex",
3262
- alignItems: "center",
3263
- justifyContent: "center",
3264
- width: "100%",
3265
- height: "100%",
3266
- color: "var(--snap-color-muted)",
3267
- fontSize: "var(--snap-text-xs)"
3268
- },
3269
- children: "snap-rail"
3270
- });
3271
- }
3272
- /** The root that mounts the layout (or the ball face) and the global overlays. */
3273
- function UiRoot(props) {
3274
- return jsx(ClientProvider, {
3275
- service: props.ctx.client,
3276
- children: jsx(UiProvider, {
3277
- service: props.ctx.ui,
3278
- children: jsx(SkinsProvider, {
3279
- service: props.ctx.skins,
3280
- children: props.surface === "main" ? jsx(MainRoot, { ctx: props.ctx }) : jsx(BallRoot, { ctx: props.ctx })
776
+ actions: restartNeeded ? jsx(Button, {
777
+ intent: "primary",
778
+ onClick: restart,
779
+ children: "重启生效"
780
+ }) : void 0,
781
+ children: [
782
+ jsxs(Stack, {
783
+ gap: "lg",
784
+ children: [error !== void 0 && jsx("div", {
785
+ role: "alert",
786
+ style: { color: "var(--snap-color-danger)" },
787
+ children: error
788
+ }), rows.length === 0 ? jsx(EmptyState, {
789
+ title: "还没有安装插件",
790
+ action: jsx(Button, {
791
+ intent: "primary",
792
+ onClick: openInstall,
793
+ children: "安装插件"
794
+ })
795
+ }) : jsxs(Table, {
796
+ "data-plugins-table": true,
797
+ children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
798
+ jsx(TableHead, {
799
+ style: { width: "6em" },
800
+ children: "分类"
801
+ }),
802
+ jsx(TableHead, { children: "名称" }),
803
+ jsx(TableHead, { children: "类型" }),
804
+ jsx(TableHead, { children: "版本" }),
805
+ jsx(TableHead, { children: "状态" }),
806
+ jsx(TableHead, { children: "操作" })
807
+ ] }) }), jsx(TableBody, { children: rows.map((row, index) => {
808
+ const update = updates.get(row.packageName);
809
+ const span = spans.get(index);
810
+ return jsxs(TableRow, { children: [
811
+ span !== void 0 && jsx(TableCell, {
812
+ rowSpan: span,
813
+ style: {
814
+ verticalAlign: "middle",
815
+ color: "var(--snap-color-muted)",
816
+ fontWeight: 600
817
+ },
818
+ children: row.category
819
+ }),
820
+ jsx(TableCell, { children: jsxs("div", {
821
+ style: {
822
+ display: "flex",
823
+ flexDirection: "column"
824
+ },
825
+ children: [jsxs("span", {
826
+ style: {
827
+ display: "flex",
828
+ alignItems: "center",
829
+ gap: "var(--snap-space-sm)"
830
+ },
831
+ children: [row.title, row.builtinDefault && jsx(Badge, {
832
+ intent: "neutral",
833
+ children: "内置默认"
834
+ })]
835
+ }), jsx("span", {
836
+ style: {
837
+ color: "var(--snap-color-muted)",
838
+ fontSize: "var(--snap-text-xs)"
839
+ },
840
+ children: row.packageName
841
+ })]
842
+ }) }),
843
+ jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
844
+ intent: "neutral",
845
+ children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
846
+ })] }),
847
+ jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
848
+ intent: "primary",
849
+ emphasis: "ghost",
850
+ size: "sm",
851
+ title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
852
+ disabled: updatingName === row.packageName,
853
+ onClick: () => requestUpdate(update),
854
+ children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
855
+ }) : row.version ?? "—" }),
856
+ jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
857
+ checked: true,
858
+ disabled: true,
859
+ "aria-label": `启用 ${row.title}`
860
+ }) : jsxs("div", {
861
+ style: {
862
+ display: "flex",
863
+ alignItems: "center",
864
+ gap: "var(--snap-space-sm)"
865
+ },
866
+ children: [jsx(Switch, {
867
+ checked: row.enabled,
868
+ disabled: busy === row.packageName,
869
+ onCheckedChange: (next) => toggle(row, next),
870
+ "aria-label": `启用 ${row.title}`
871
+ }), touched.has(row.packageName) && jsx(Badge, {
872
+ intent: "warning",
873
+ children: "待重启"
874
+ })]
875
+ }) }),
876
+ jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
877
+ style: { color: "var(--snap-color-muted)" },
878
+ children: "内置默认不可卸载"
879
+ }) : jsx(Button, {
880
+ intent: "danger",
881
+ emphasis: "ghost",
882
+ size: "sm",
883
+ disabled: busy === row.packageName,
884
+ onClick: () => uninstall(row),
885
+ children: "卸载"
886
+ }) })
887
+ ] }, row.packageName);
888
+ }) })]
889
+ })]
890
+ }),
891
+ jsx(Dialog, {
892
+ open: installOpen,
893
+ onOpenChange: (next) => {
894
+ if (!next) closeInstall();
895
+ },
896
+ children: jsxs(DialogContent, {
897
+ presentation: "modal",
898
+ size: "lg",
899
+ "data-plugins-dropzone": true,
900
+ "aria-describedby": void 0,
901
+ onDragOver: (event) => {
902
+ event.preventDefault();
903
+ setDragging(true);
904
+ },
905
+ onDragLeave: (event) => {
906
+ if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
907
+ },
908
+ onDrop,
909
+ children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
910
+ gap: "sm",
911
+ children: [
912
+ jsx("div", {
913
+ "data-plugins-drop-hint": true,
914
+ style: {
915
+ height: "calc(var(--snap-control-height-md) * 3)",
916
+ display: "flex",
917
+ alignItems: "center",
918
+ justifyContent: "center",
919
+ border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
920
+ borderRadius: "var(--snap-radius-md)",
921
+ background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
922
+ color: "var(--snap-color-muted)",
923
+ fontSize: "var(--snap-text-sm)"
924
+ },
925
+ children: dragging ? "释放以安装" : "拖入 .zip 安装"
926
+ }),
927
+ jsxs("div", {
928
+ style: {
929
+ display: "flex",
930
+ gap: "var(--snap-space-sm)"
931
+ },
932
+ children: [jsx(Input, {
933
+ value: query,
934
+ placeholder: "本地路径 / https://… / 插件名",
935
+ style: {
936
+ flex: 1,
937
+ minWidth: 0
938
+ },
939
+ onChange: (event) => setQuery(event.target.value),
940
+ onKeyDown: (event) => {
941
+ if (event.key === "Enter") submitQuery();
942
+ }
943
+ }), jsx(Button, {
944
+ intent: "neutral",
945
+ emphasis: "outline",
946
+ disabled: searching,
947
+ onClick: submitQuery,
948
+ children: searching ? "搜索中…" : "搜索"
949
+ })]
950
+ }),
951
+ message !== void 0 && jsx("div", {
952
+ role: message.kind === "error" ? "alert" : "status",
953
+ style: {
954
+ fontSize: "var(--snap-text-xs)",
955
+ color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
956
+ },
957
+ children: message.text
958
+ }),
959
+ visibleResults !== void 0 && jsxs(Stack, {
960
+ gap: "sm",
961
+ children: [
962
+ jsxs("div", {
963
+ style: {
964
+ display: "flex",
965
+ justifyContent: "space-between",
966
+ alignItems: "center"
967
+ },
968
+ children: [jsxs("span", {
969
+ style: {
970
+ fontSize: "var(--snap-text-sm)",
971
+ color: "var(--snap-color-muted)"
972
+ },
973
+ children: [
974
+ "搜索“",
975
+ query.trim(),
976
+ "”(",
977
+ searchResults?.length ?? 0,
978
+ ")"
979
+ ]
980
+ }), jsx(Button, {
981
+ intent: "neutral",
982
+ emphasis: "ghost",
983
+ size: "sm",
984
+ onClick: () => setSearchResults(void 0),
985
+ children: "✕"
986
+ })]
987
+ }),
988
+ visibleResults.length === 0 && jsx("div", {
989
+ style: {
990
+ padding: "12px 0",
991
+ textAlign: "center",
992
+ color: "var(--snap-color-muted)",
993
+ fontSize: "var(--snap-text-sm)"
994
+ },
995
+ children: "没有匹配的插件。"
996
+ }),
997
+ visibleResults.map((item) => {
998
+ const installed = item.installed !== void 0;
999
+ return jsxs("div", {
1000
+ style: {
1001
+ display: "flex",
1002
+ gap: "var(--snap-space-md)",
1003
+ alignItems: "center",
1004
+ justifyContent: "space-between",
1005
+ borderBottom: "1px solid var(--snap-color-border)",
1006
+ paddingBottom: "var(--snap-space-sm)"
1007
+ },
1008
+ children: [jsxs("div", {
1009
+ style: { minWidth: 0 },
1010
+ children: [jsxs("div", {
1011
+ style: {
1012
+ display: "flex",
1013
+ gap: "var(--snap-space-sm)",
1014
+ alignItems: "center"
1015
+ },
1016
+ children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
1017
+ intent: "neutral",
1018
+ children: item.source
1019
+ })]
1020
+ }), jsxs("div", {
1021
+ style: {
1022
+ fontSize: "var(--snap-text-xs)",
1023
+ color: "var(--snap-color-muted)"
1024
+ },
1025
+ children: [
1026
+ item.name,
1027
+ " · ",
1028
+ item.version
1029
+ ]
1030
+ })]
1031
+ }), item.action === "install" ? jsx(Button, {
1032
+ intent: "primary",
1033
+ emphasis: "outline",
1034
+ size: "sm",
1035
+ onClick: () => previewRemote(item),
1036
+ children: "安装"
1037
+ }) : item.action === "update" && installed ? jsx(Button, {
1038
+ intent: "primary",
1039
+ emphasis: "ghost",
1040
+ size: "sm",
1041
+ title: `当前 ${item.installed?.version} → ${item.version}`,
1042
+ disabled: updatingName === item.name,
1043
+ onClick: () => requestUpdate({
1044
+ name: item.name,
1045
+ installedVersion: item.installed?.version ?? "",
1046
+ feedVersion: item.version
1047
+ }),
1048
+ children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
1049
+ }) : jsx("span", {
1050
+ style: {
1051
+ fontSize: "var(--snap-text-xs)",
1052
+ color: "var(--snap-color-muted)"
1053
+ },
1054
+ children: item.action === "current" ? "已是最新" : "本地更新"
1055
+ })]
1056
+ }, item.name);
1057
+ }),
1058
+ (searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
1059
+ style: {
1060
+ fontSize: "var(--snap-text-xs)",
1061
+ color: "var(--snap-color-muted)"
1062
+ },
1063
+ children: [
1064
+ "已显示前 ",
1065
+ SEARCH_ROW_CAP,
1066
+ " 条,共 ",
1067
+ searchResults?.length,
1068
+ " 条。"
1069
+ ]
1070
+ })
1071
+ ]
1072
+ })
1073
+ ]
1074
+ }) })]
1075
+ })
1076
+ }),
1077
+ jsx(Dialog, {
1078
+ open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
1079
+ onOpenChange: (next) => {
1080
+ if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
1081
+ },
1082
+ children: jsxs(DialogContent, {
1083
+ presentation: "modal",
1084
+ "aria-describedby": void 0,
1085
+ children: [
1086
+ 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}` })] }),
1087
+ jsxs(DialogBody, { children: [
1088
+ phase.kind === "error" && jsx("div", {
1089
+ style: {
1090
+ color: "var(--snap-color-danger)",
1091
+ whiteSpace: "pre-wrap",
1092
+ fontSize: "var(--snap-text-sm)"
1093
+ },
1094
+ children: phase.message
1095
+ }),
1096
+ phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
1097
+ gap: "sm",
1098
+ children: [
1099
+ phase.archive.combo.description !== void 0 && jsx("div", {
1100
+ style: {
1101
+ color: "var(--snap-color-muted)",
1102
+ fontSize: "var(--snap-text-sm)"
1103
+ },
1104
+ children: phase.archive.combo.description
1105
+ }),
1106
+ jsxs("div", {
1107
+ style: {
1108
+ display: "grid",
1109
+ gap: "var(--snap-space-xs)",
1110
+ fontSize: "var(--snap-text-sm)"
1111
+ },
1112
+ children: [jsxs("div", { children: [
1113
+ "插件(",
1114
+ phase.archive.combo.plugins.length,
1115
+ ")"
1116
+ ] }), phase.archive.combo.plugins.map((plugin) => {
1117
+ const line = signatureText(plugin.signature, phase.viaUrl);
1118
+ const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
1119
+ return jsxs("div", {
1120
+ style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
1121
+ children: [
1122
+ plugin.title ?? plugin.name,
1123
+ " ",
1124
+ plugin.version,
1125
+ " · ",
1126
+ action,
1127
+ line.warning ? " · ⚠ 未验证" : ""
1128
+ ]
1129
+ }, plugin.name);
1130
+ })]
1131
+ }),
1132
+ phase.archive.combo.missing.length > 0 && jsxs("div", {
1133
+ style: {
1134
+ color: "var(--snap-color-danger)",
1135
+ fontSize: "var(--snap-text-sm)"
1136
+ },
1137
+ children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
1138
+ })
1139
+ ]
1140
+ }),
1141
+ phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
1142
+ gap: "sm",
1143
+ children: [
1144
+ phase.risk ? jsx("div", {
1145
+ "data-plugins-risk": true,
1146
+ style: {
1147
+ color: "var(--snap-color-warning)",
1148
+ fontWeight: 600
1149
+ },
1150
+ children: "⚠ 此插件未经发布者验证"
1151
+ }) : void 0,
1152
+ !phase.risk && jsxs(Stack, {
1153
+ gap: "sm",
1154
+ children: [
1155
+ phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
1156
+ jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
1157
+ 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] })
1158
+ ]
1159
+ }),
1160
+ (() => {
1161
+ const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
1162
+ return jsxs("div", {
1163
+ "data-plugins-signature": phase.archive.plugin.signature.state,
1164
+ style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
1165
+ children: ["签名:", line.text]
1166
+ });
1167
+ })(),
1168
+ !phase.risk && jsxs(Stack, {
1169
+ gap: "sm",
1170
+ children: [
1171
+ jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
1172
+ phase.archive.plugin.missing.length > 0 && jsxs("div", {
1173
+ style: {
1174
+ color: "var(--snap-color-danger)",
1175
+ fontSize: "var(--snap-text-sm)"
1176
+ },
1177
+ children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
1178
+ }),
1179
+ phase.archive.plugin.action === "blocked" && jsxs("div", {
1180
+ style: {
1181
+ color: "var(--snap-color-danger)",
1182
+ fontSize: "var(--snap-text-sm)"
1183
+ },
1184
+ children: [
1185
+ "已安装 v",
1186
+ phase.archive.plugin.installed?.version,
1187
+ ",安装包 v",
1188
+ phase.archive.plugin.version,
1189
+ " 不高于已装版本,无法覆盖。"
1190
+ ]
1191
+ })
1192
+ ]
1193
+ }),
1194
+ phase.risk && jsx("div", {
1195
+ style: {
1196
+ color: "var(--snap-color-muted)",
1197
+ fontSize: "var(--snap-text-sm)"
1198
+ },
1199
+ children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
1200
+ })
1201
+ ]
1202
+ })
1203
+ ] }),
1204
+ jsxs(DialogFooter, { children: [
1205
+ phase.kind === "error" && jsx(Button, {
1206
+ intent: "neutral",
1207
+ emphasis: "outline",
1208
+ onClick: () => setPhase({ kind: "idle" }),
1209
+ children: "返回"
1210
+ }),
1211
+ phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
1212
+ intent: "neutral",
1213
+ emphasis: "outline",
1214
+ onClick: () => setPhase({ kind: "idle" }),
1215
+ children: "取消"
1216
+ }), phase.risk ? jsx(Button, {
1217
+ intent: "primary",
1218
+ "data-plugins-risk-confirm": true,
1219
+ onClick: () => runInstall(phase.zipPath, phase.archive),
1220
+ children: "我知晓风险,仍要安装"
1221
+ }) : jsx(Button, {
1222
+ intent: "primary",
1223
+ "data-plugins-install-confirm": true,
1224
+ disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
1225
+ onClick: () => {
1226
+ if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
1227
+ setPhase({
1228
+ ...phase,
1229
+ risk: true
1230
+ });
1231
+ return;
1232
+ }
1233
+ runInstall(phase.zipPath, phase.archive);
1234
+ },
1235
+ children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
1236
+ })] }),
1237
+ phase.kind === "installing" && jsx("span", {
1238
+ style: { color: "var(--snap-color-muted)" },
1239
+ children: "正在安装…"
1240
+ })
1241
+ ] })
1242
+ ]
1243
+ })
1244
+ }),
1245
+ jsx(Dialog, {
1246
+ open: keyChange !== void 0,
1247
+ onOpenChange: (next) => {
1248
+ if (!next) setKeyChange(void 0);
1249
+ },
1250
+ children: jsxs(DialogContent, {
1251
+ presentation: "modal",
1252
+ children: [
1253
+ jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
1254
+ jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
1255
+ style: { fontSize: "var(--snap-text-sm)" },
1256
+ children: [
1257
+ "已安装 v",
1258
+ keyChange.installedVersion,
1259
+ " → 源上 v",
1260
+ keyChange.feedVersion,
1261
+ "。"
1262
+ ]
1263
+ }) }),
1264
+ jsxs(DialogFooter, { children: [jsx(Button, {
1265
+ intent: "neutral",
1266
+ emphasis: "outline",
1267
+ onClick: () => setKeyChange(void 0),
1268
+ children: "取消"
1269
+ }), jsx(Button, {
1270
+ intent: "primary",
1271
+ "data-plugins-keychange-confirm": true,
1272
+ onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
1273
+ children: "仍要更新"
1274
+ })] })
1275
+ ]
1276
+ })
3281
1277
  })
3282
- })
3283
- });
3284
- }
3285
- /**
3286
- * Take over the kernel root and mount the UI substrate.
3287
- *
3288
- * @param handle - the kernel boot result.
3289
- * @param options - see {@link RuntimeOptions}.
3290
- */
3291
- async function createClientRuntime(handle, options) {
3292
- const surface = options.surface ?? "main";
3293
- const ctx = new Context();
3294
- ctx.provide("client", {
3295
- link: handle.link,
3296
- surface
3297
- });
3298
- await ctx.plugin(TimerService);
3299
- await ctx.plugin(slotsPlugin);
3300
- await ctx.plugin(pagesPlugin);
3301
- await ctx.plugin(skinsPlugin);
3302
- await ctx.plugin(settingsPlugin);
3303
- const applyThemeRow = (value) => {
3304
- const mode = value?.mode;
3305
- const choice = mode === "light" || mode === "dark" || mode === "system" ? mode : "dark";
3306
- const prefersLight = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: light)").matches;
3307
- const resolved = choice === "system" ? prefersLight ? "light" : "dark" : choice;
3308
- ctx.skins.setMode(resolved);
3309
- if (typeof document !== "undefined") document.documentElement.dataset["mode"] = resolved;
3310
- };
3311
- handle.link.call("settings.get", { key: "ui.theme" }).then((result) => {
3312
- if (result.ok) applyThemeRow(result.value.value);
3313
- }).catch(() => {});
3314
- const dropTheme = subscribeFrame(handle.link, "settings/changed", settingsChangedSchema, (change) => {
3315
- if (change.key === "ui.theme") applyThemeRow(change.value);
3316
- });
3317
- const dropOpenSettings = subscribeFrame(handle.link, "shell/settings-open-requested", shellContract.frames["shell/settings-open-requested"], () => {
3318
- ctx.settings.open();
3319
- });
3320
- ctx.effect(() => () => {
3321
- dropTheme();
3322
- dropOpenSettings();
1278
+ ]
3323
1279
  });
3324
- for (const page of options.builtinPages ?? []) ctx.settings.registerPage(ctx, page);
3325
- for (const seat of options.plugins) {
3326
- const spec = "plugin" in seat ? seat : { plugin: seat };
3327
- const plugin = spec.plugin;
3328
- await ctx.plugin(plugin, spec.config === void 0 ? {} : spec.config);
3329
- }
3330
- if (surface === "main") await ctx.plugin(fallbackPlugin);
3331
- handle.root.unmount();
3332
- const shellRoot = createRoot(handle.element);
3333
- shellRoot.render(jsx(UiRoot, {
3334
- ctx,
3335
- surface
3336
- }));
3337
- return {
3338
- ctx,
3339
- dispose: () => ctx.fiber.dispose().then(() => {
3340
- shellRoot.unmount();
3341
- })
3342
- };
3343
1280
  }
3344
1281
  //#endregion
3345
- export { AppShell, Badge, Button, CUSTOM_SLOT_PATTERN, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartFrame, Checkbox, ClientProvider, DEFAULT_SKIN, DEFAULT_SKIN_ID, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DragScroll, EmptyState, Field, Form, Grid, IconButton, Input, Label, Led, NumberInput, PRESENTATION_TARGETS, PRESENTATION_VARIANTS, Page, Panel, Progress, RadioGroup, RadioGroupItem, Row, SKIN_MODES, SchemaForm, ScrollArea, Section, Select, SettingsEntry, SettingsSurface, Sheet, SkinsProvider, Slot, Spinner, Split, Stack, Switch, Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toolbar, TouchSelect, UI_COMPONENTS, UI_DIAGNOSTIC_KINDS, UI_PROFILES, UI_SLOT_IDS, UI_SLOT_MODES, UiProvider, Visualization, chartThemeOf, createClientRuntime, fallbackPlugin, isValidSlotId, pagesPlugin, schemaNodeOf, settingsPageInfo, settingsPlugin, skinTokenVar, skinsPlugin, slotsPlugin, useActiveLayout, useChartTheme, useClient, usePagesVersion, usePresentation, useSkinTokens, useSkins, useUi, useUiVersion };
1282
+ export { PluginsPage };