@snap-rail/ui 0.1.0 → 0.2.0
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/charts.js +6 -29
- package/lib/contract.js +119 -78
- package/lib/fallback.js +11 -1
- package/lib/index.js +2466 -735
- package/lib/runtime.js +1552 -490
- package/lib/settings.js +1162 -244
- package/lib/skins.js +163 -189
- package/lib/types/charts.d.ts +1 -1
- package/lib/types/charts.js +5 -5
- package/lib/types/components/alert.d.ts +57 -0
- package/lib/types/components/alert.js +46 -0
- package/lib/types/components/controls.d.ts +74 -11
- package/lib/types/components/controls.js +60 -17
- package/lib/types/components/dialog.d.ts +5 -5
- package/lib/types/components/dialog.js +2 -2
- package/lib/types/components/form-rhf.d.ts +56 -0
- package/lib/types/components/form-rhf.js +74 -0
- package/lib/types/components/form.d.ts +33 -5
- package/lib/types/components/form.js +22 -6
- package/lib/types/components/index.d.ts +7 -0
- package/lib/types/components/index.js +7 -0
- package/lib/types/components/input.d.ts +16 -7
- package/lib/types/components/input.js +39 -9
- package/lib/types/components/layout.d.ts +32 -7
- package/lib/types/components/layout.js +88 -15
- package/lib/types/components/overlay.d.ts +95 -0
- package/lib/types/components/overlay.js +138 -0
- package/lib/types/components/schema-form.d.ts +16 -4
- package/lib/types/components/schema-form.js +69 -40
- package/lib/types/components/slider.d.ts +18 -0
- package/lib/types/components/slider.js +15 -0
- package/lib/types/contract.d.ts +49 -37
- package/lib/types/contract.js +49 -33
- package/lib/types/fallback.js +1 -1
- package/lib/types/runtime.d.ts +23 -1
- package/lib/types/runtime.js +77 -20
- package/lib/types/settings-pages/appearance.d.ts +6 -4
- package/lib/types/settings-pages/appearance.js +33 -36
- package/lib/types/settings-pages/plugin-feed.d.ts +17 -0
- package/lib/types/settings-pages/plugin-feed.js +66 -0
- package/lib/types/settings-pages/plugins.d.ts +10 -5
- package/lib/types/settings-pages/plugins.js +284 -21
- package/lib/types/settings.d.ts +1 -0
- package/lib/types/settings.js +14 -8
- package/lib/types/skins.d.ts +38 -44
- package/lib/types/skins.js +172 -169
- package/package.json +16 -9
- package/src/styles/base.css +251 -5
- package/src/styles/default.css +315 -136
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Component, createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { Component, createContext, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
|
3
4
|
import { Slot as Slot$1 } from "@radix-ui/react-slot";
|
|
4
5
|
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
5
6
|
import * as LabelPrimitive from "@radix-ui/react-label";
|
|
@@ -8,13 +9,22 @@ import * as SelectPrimitive from "@radix-ui/react-select";
|
|
|
8
9
|
import * as SwitchPrimitive from "@radix-ui/react-switch";
|
|
9
10
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
10
11
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
12
|
+
import { Controller, Controller as Controller$1, FormProvider, FormProvider as FormProvider$1, useController, useFieldArray, useForm, useFormContext, useFormState, useFormState as useFormState$1, useWatch } from "react-hook-form";
|
|
13
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
14
|
+
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
|
15
|
+
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
16
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
17
|
+
import * as ToastPrimitive from "@radix-ui/react-toast";
|
|
18
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
19
|
+
import * as SliderPrimitive from "@radix-ui/react-slider";
|
|
20
|
+
import { attachBallDrag as attachBallDrag$1 } from "@snap-rail/client-kernel";
|
|
11
21
|
import { rpcErrorText, subscribeFrame } from "@snap-rail/connection";
|
|
12
22
|
import { settingsChangedSchema } from "@snap-rail/station-rpc/contract";
|
|
13
23
|
import { Context } from "@snap-rail/cordis";
|
|
14
24
|
import { TimerService } from "@snap-rail/cordis-plugin-timer";
|
|
15
25
|
import { shellContract } from "@snap-rail/shell/contract";
|
|
16
26
|
import { createRoot } from "react-dom/client";
|
|
17
|
-
import "@snap-rail/app-boot/contract";
|
|
27
|
+
import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
|
|
18
28
|
//#region lib/types/contract.js
|
|
19
29
|
/**
|
|
20
30
|
* The semantic UI contract: component names, region-slot ids, scoped slot
|
|
@@ -123,7 +133,8 @@ const UI_COMPONENTS = {
|
|
|
123
133
|
props: [
|
|
124
134
|
"size",
|
|
125
135
|
"invalid",
|
|
126
|
-
"disabled"
|
|
136
|
+
"disabled",
|
|
137
|
+
"fieldClassName"
|
|
127
138
|
]
|
|
128
139
|
},
|
|
129
140
|
textarea: {
|
|
@@ -131,7 +142,8 @@ const UI_COMPONENTS = {
|
|
|
131
142
|
props: [
|
|
132
143
|
"size",
|
|
133
144
|
"invalid",
|
|
134
|
-
"disabled"
|
|
145
|
+
"disabled",
|
|
146
|
+
"fieldClassName"
|
|
135
147
|
]
|
|
136
148
|
},
|
|
137
149
|
"number-input": {
|
|
@@ -158,12 +170,14 @@ const UI_COMPONENTS = {
|
|
|
158
170
|
"select.item-indicator",
|
|
159
171
|
"select.empty"
|
|
160
172
|
],
|
|
161
|
-
slots: ["empty"],
|
|
173
|
+
slots: ["empty", "children"],
|
|
162
174
|
props: [
|
|
163
175
|
"size",
|
|
164
176
|
"invalid",
|
|
165
177
|
"disabled",
|
|
166
|
-
"
|
|
178
|
+
"defaultValue",
|
|
179
|
+
"side",
|
|
180
|
+
"align"
|
|
167
181
|
]
|
|
168
182
|
},
|
|
169
183
|
"touch-select": {
|
|
@@ -178,34 +192,49 @@ const UI_COMPONENTS = {
|
|
|
178
192
|
checkbox: {
|
|
179
193
|
parts: [
|
|
180
194
|
"checkbox.root",
|
|
181
|
-
"checkbox.box",
|
|
182
195
|
"checkbox.indicator",
|
|
183
|
-
"checkbox.label"
|
|
196
|
+
"checkbox.label",
|
|
197
|
+
"checkbox.field",
|
|
198
|
+
"checkbox.description"
|
|
184
199
|
],
|
|
185
|
-
slots: ["label"],
|
|
200
|
+
slots: ["label", "description"],
|
|
186
201
|
props: [
|
|
187
202
|
"checked",
|
|
188
203
|
"invalid",
|
|
189
|
-
"disabled"
|
|
204
|
+
"disabled",
|
|
205
|
+
"labelPosition"
|
|
190
206
|
]
|
|
191
207
|
},
|
|
192
208
|
switch: {
|
|
193
209
|
parts: [
|
|
194
210
|
"switch.root",
|
|
195
211
|
"switch.thumb",
|
|
196
|
-
"switch.label"
|
|
212
|
+
"switch.label",
|
|
213
|
+
"switch.field",
|
|
214
|
+
"switch.description"
|
|
197
215
|
],
|
|
198
|
-
slots: ["label"],
|
|
199
|
-
props: [
|
|
216
|
+
slots: ["label", "description"],
|
|
217
|
+
props: [
|
|
218
|
+
"checked",
|
|
219
|
+
"disabled",
|
|
220
|
+
"labelPosition"
|
|
221
|
+
]
|
|
200
222
|
},
|
|
201
223
|
"radio-group": {
|
|
202
224
|
parts: [
|
|
203
225
|
"radio-group.root",
|
|
204
226
|
"radio-group.item",
|
|
205
227
|
"radio-group.indicator",
|
|
206
|
-
"radio-group.label"
|
|
228
|
+
"radio-group.label",
|
|
229
|
+
"radio-group.block",
|
|
230
|
+
"radio-group.description"
|
|
207
231
|
],
|
|
208
|
-
props: [
|
|
232
|
+
props: [
|
|
233
|
+
"value",
|
|
234
|
+
"disabled",
|
|
235
|
+
"label",
|
|
236
|
+
"description"
|
|
237
|
+
]
|
|
209
238
|
},
|
|
210
239
|
tabs: {
|
|
211
240
|
parts: [
|
|
@@ -215,7 +244,7 @@ const UI_COMPONENTS = {
|
|
|
215
244
|
"tabs.content"
|
|
216
245
|
],
|
|
217
246
|
slots: ["list", "content"],
|
|
218
|
-
props: ["value"
|
|
247
|
+
props: ["value"]
|
|
219
248
|
},
|
|
220
249
|
table: {
|
|
221
250
|
parts: [
|
|
@@ -263,7 +292,6 @@ const UI_COMPONENTS = {
|
|
|
263
292
|
},
|
|
264
293
|
dialog: {
|
|
265
294
|
parts: [
|
|
266
|
-
"dialog.root",
|
|
267
295
|
"dialog.overlay",
|
|
268
296
|
"dialog.panel",
|
|
269
297
|
"dialog.header",
|
|
@@ -288,12 +316,13 @@ const UI_COMPONENTS = {
|
|
|
288
316
|
},
|
|
289
317
|
sheet: {
|
|
290
318
|
parts: [
|
|
291
|
-
"
|
|
292
|
-
"
|
|
293
|
-
"
|
|
294
|
-
"
|
|
295
|
-
"
|
|
296
|
-
"
|
|
319
|
+
"dialog.overlay",
|
|
320
|
+
"dialog.panel",
|
|
321
|
+
"dialog.header",
|
|
322
|
+
"dialog.title",
|
|
323
|
+
"dialog.description",
|
|
324
|
+
"dialog.body",
|
|
325
|
+
"dialog.footer"
|
|
297
326
|
],
|
|
298
327
|
slots: [
|
|
299
328
|
"header",
|
|
@@ -303,27 +332,20 @@ const UI_COMPONENTS = {
|
|
|
303
332
|
props: ["open", "presentation"]
|
|
304
333
|
},
|
|
305
334
|
popover: {
|
|
306
|
-
parts: [
|
|
307
|
-
"popover.root",
|
|
308
|
-
"popover.trigger",
|
|
309
|
-
"popover.content"
|
|
310
|
-
],
|
|
335
|
+
parts: ["popover.trigger", "popover.content"],
|
|
311
336
|
slots: ["trigger", "content"]
|
|
312
337
|
},
|
|
313
338
|
tooltip: {
|
|
314
|
-
parts: [
|
|
315
|
-
"tooltip.root",
|
|
316
|
-
"tooltip.trigger",
|
|
317
|
-
"tooltip.content"
|
|
318
|
-
],
|
|
339
|
+
parts: ["tooltip.trigger", "tooltip.content"],
|
|
319
340
|
slots: ["trigger", "content"]
|
|
320
341
|
},
|
|
321
342
|
menu: {
|
|
322
343
|
parts: [
|
|
323
|
-
"menu.root",
|
|
324
344
|
"menu.trigger",
|
|
325
345
|
"menu.content",
|
|
326
346
|
"menu.item",
|
|
347
|
+
"menu.checkbox-item",
|
|
348
|
+
"menu.item-indicator",
|
|
327
349
|
"menu.separator"
|
|
328
350
|
],
|
|
329
351
|
slots: ["trigger", "content"]
|
|
@@ -334,7 +356,8 @@ const UI_COMPONENTS = {
|
|
|
334
356
|
"toast.title",
|
|
335
357
|
"toast.description",
|
|
336
358
|
"toast.action",
|
|
337
|
-
"toast.close"
|
|
359
|
+
"toast.close",
|
|
360
|
+
"toast.viewport"
|
|
338
361
|
],
|
|
339
362
|
slots: ["action"]
|
|
340
363
|
},
|
|
@@ -348,6 +371,52 @@ const UI_COMPONENTS = {
|
|
|
348
371
|
parts: ["led.root", "led.halo"],
|
|
349
372
|
props: ["tone"]
|
|
350
373
|
},
|
|
374
|
+
alert: {
|
|
375
|
+
parts: [
|
|
376
|
+
"alert.root",
|
|
377
|
+
"alert.title",
|
|
378
|
+
"alert.description"
|
|
379
|
+
],
|
|
380
|
+
slots: ["title", "description"],
|
|
381
|
+
props: ["intent"]
|
|
382
|
+
},
|
|
383
|
+
separator: {
|
|
384
|
+
parts: ["separator.root"],
|
|
385
|
+
props: ["orientation"]
|
|
386
|
+
},
|
|
387
|
+
skeleton: {
|
|
388
|
+
parts: ["skeleton.root"],
|
|
389
|
+
props: ["variant"]
|
|
390
|
+
},
|
|
391
|
+
list: {
|
|
392
|
+
parts: [
|
|
393
|
+
"list.root",
|
|
394
|
+
"list.item",
|
|
395
|
+
"list.leading",
|
|
396
|
+
"list.content",
|
|
397
|
+
"list.trailing"
|
|
398
|
+
],
|
|
399
|
+
slots: ["leading", "trailing"],
|
|
400
|
+
props: [
|
|
401
|
+
"divided",
|
|
402
|
+
"selected",
|
|
403
|
+
"disabled"
|
|
404
|
+
]
|
|
405
|
+
},
|
|
406
|
+
slider: {
|
|
407
|
+
parts: [
|
|
408
|
+
"slider.root",
|
|
409
|
+
"slider.track",
|
|
410
|
+
"slider.range",
|
|
411
|
+
"slider.thumb"
|
|
412
|
+
],
|
|
413
|
+
props: [
|
|
414
|
+
"value",
|
|
415
|
+
"min",
|
|
416
|
+
"max",
|
|
417
|
+
"step"
|
|
418
|
+
]
|
|
419
|
+
},
|
|
351
420
|
spinner: { parts: ["spinner.root"] },
|
|
352
421
|
"empty-state": {
|
|
353
422
|
parts: [
|
|
@@ -370,7 +439,13 @@ const UI_COMPONENTS = {
|
|
|
370
439
|
"form.fields",
|
|
371
440
|
"form.actions"
|
|
372
441
|
],
|
|
373
|
-
slots: ["fields", "actions"]
|
|
442
|
+
slots: ["fields", "actions"],
|
|
443
|
+
props: [
|
|
444
|
+
"orientation",
|
|
445
|
+
"gap",
|
|
446
|
+
"columns",
|
|
447
|
+
"form"
|
|
448
|
+
]
|
|
374
449
|
},
|
|
375
450
|
field: {
|
|
376
451
|
parts: [
|
|
@@ -389,12 +464,15 @@ const UI_COMPONENTS = {
|
|
|
389
464
|
props: [
|
|
390
465
|
"invalid",
|
|
391
466
|
"required",
|
|
392
|
-
"
|
|
467
|
+
"orientation",
|
|
468
|
+
"labelWidth",
|
|
469
|
+
"labelAlign"
|
|
393
470
|
]
|
|
394
471
|
},
|
|
395
472
|
"schema-form": {
|
|
396
473
|
parts: ["schema-form.root", "schema-form.field"],
|
|
397
|
-
slots: ["fields"]
|
|
474
|
+
slots: ["fields"],
|
|
475
|
+
props: ["columns"]
|
|
398
476
|
},
|
|
399
477
|
"app-shell": {
|
|
400
478
|
parts: [
|
|
@@ -447,6 +525,7 @@ const UI_COMPONENTS = {
|
|
|
447
525
|
parts: [
|
|
448
526
|
"toolbar.root",
|
|
449
527
|
"toolbar.start",
|
|
528
|
+
"toolbar.center",
|
|
450
529
|
"toolbar.end"
|
|
451
530
|
],
|
|
452
531
|
slots: ["start", "end"]
|
|
@@ -487,23 +566,26 @@ const UI_COMPONENTS = {
|
|
|
487
566
|
"scroll-area": { parts: [
|
|
488
567
|
"scroll-area.root",
|
|
489
568
|
"scroll-area.viewport",
|
|
490
|
-
"scroll-area.scrollbar"
|
|
569
|
+
"scroll-area.scrollbar",
|
|
570
|
+
"scroll-area.thumb"
|
|
491
571
|
] },
|
|
492
572
|
"drag-scroll": { parts: ["drag-scroll.root", "drag-scroll.viewport"] },
|
|
493
|
-
|
|
573
|
+
"chart-frame": {
|
|
494
574
|
parts: [
|
|
495
|
-
"
|
|
496
|
-
"
|
|
497
|
-
"
|
|
498
|
-
"
|
|
499
|
-
"
|
|
500
|
-
"
|
|
501
|
-
"
|
|
502
|
-
"
|
|
575
|
+
"chart-frame.root",
|
|
576
|
+
"chart-frame.header",
|
|
577
|
+
"chart-frame.title",
|
|
578
|
+
"chart-frame.description",
|
|
579
|
+
"chart-frame.actions",
|
|
580
|
+
"chart-frame.body",
|
|
581
|
+
"chart-frame.loading",
|
|
582
|
+
"chart-frame.empty",
|
|
583
|
+
"chart-frame.error"
|
|
503
584
|
],
|
|
504
585
|
slots: [
|
|
505
586
|
"header",
|
|
506
587
|
"title",
|
|
588
|
+
"description",
|
|
507
589
|
"actions",
|
|
508
590
|
"body",
|
|
509
591
|
"empty",
|
|
@@ -512,21 +594,6 @@ const UI_COMPONENTS = {
|
|
|
512
594
|
],
|
|
513
595
|
props: ["state"]
|
|
514
596
|
},
|
|
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
597
|
settings: { parts: [
|
|
531
598
|
"settings.root",
|
|
532
599
|
"settings.header",
|
|
@@ -540,22 +607,6 @@ const UI_COMPONENTS = {
|
|
|
540
607
|
"settings.content"
|
|
541
608
|
] }
|
|
542
609
|
};
|
|
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
610
|
//#endregion
|
|
560
611
|
//#region lib/types/utils.js
|
|
561
612
|
/**
|
|
@@ -575,165 +626,170 @@ function part(component, name) {
|
|
|
575
626
|
"data-snap-part": `${component}.${name}`
|
|
576
627
|
};
|
|
577
628
|
}
|
|
629
|
+
/** Map a semantic size token to a control-height CSS variable. */
|
|
630
|
+
function controlHeight(size) {
|
|
631
|
+
return `var(--snap-control-height-${size})`;
|
|
632
|
+
}
|
|
578
633
|
/** Map a semantic spacing token to a CSS variable. */
|
|
579
634
|
function space(token) {
|
|
580
635
|
return `var(--snap-space-${token})`;
|
|
581
636
|
}
|
|
582
637
|
//#endregion
|
|
583
638
|
//#region lib/types/skins.js
|
|
584
|
-
/** The
|
|
585
|
-
const
|
|
586
|
-
/** The
|
|
587
|
-
const
|
|
588
|
-
/** The
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
639
|
+
/** The factory day theme id (cobalt palette, light surfaces). */
|
|
640
|
+
const DEFAULT_LIGHT_ID = "default-light";
|
|
641
|
+
/** The factory night theme id (cobalt palette, dark surfaces). */
|
|
642
|
+
const DEFAULT_DARK_ID = "default-dark";
|
|
643
|
+
/** The contributor label for the factory themes. */
|
|
644
|
+
const FACTORY_CALLER = "@snap-rail/ui";
|
|
645
|
+
const COBALT_DARK_TOKENS = {
|
|
646
|
+
colorBg: "#0b0f14",
|
|
647
|
+
colorSurface: "#11161d",
|
|
648
|
+
colorSurfaceRaised: "#161b22",
|
|
649
|
+
colorText: "#ced8e3",
|
|
650
|
+
colorMuted: "#8b949e",
|
|
651
|
+
colorPrimary: "#4a6cff",
|
|
652
|
+
colorOnPrimary: "#ffffff",
|
|
653
|
+
colorDanger: "#f85149",
|
|
654
|
+
colorSuccess: "#3fb950",
|
|
655
|
+
colorWarning: "#d29922",
|
|
656
|
+
colorBorder: "#1f2933",
|
|
657
|
+
colorFocus: "#4a6cff",
|
|
658
|
+
chart1: "#4a6cff",
|
|
659
|
+
chart2: "#3147a1",
|
|
660
|
+
chart3: "#667fcd",
|
|
661
|
+
chart4: "#7d8fa5",
|
|
662
|
+
chart5: "#55677c",
|
|
663
|
+
chart6: "#33414f",
|
|
664
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
665
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
666
|
+
textXs: "13px",
|
|
667
|
+
textSm: "15px",
|
|
668
|
+
textMd: "17px",
|
|
669
|
+
textLg: "20px",
|
|
670
|
+
textXl: "24px",
|
|
671
|
+
weightNormal: "400",
|
|
672
|
+
weightMedium: "500",
|
|
673
|
+
weightStrong: "600",
|
|
674
|
+
leadingTight: "1.2",
|
|
675
|
+
leadingNormal: "1.55",
|
|
676
|
+
spaceXs: "4px",
|
|
677
|
+
spaceSm: "8px",
|
|
678
|
+
spaceMd: "12px",
|
|
679
|
+
spaceLg: "20px",
|
|
680
|
+
spaceXl: "32px",
|
|
681
|
+
radiusSm: "6px",
|
|
682
|
+
radiusMd: "8px",
|
|
683
|
+
radiusLg: "12px",
|
|
684
|
+
radiusFull: "999px",
|
|
685
|
+
borderWidth: "1px",
|
|
686
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.25)",
|
|
687
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.28)",
|
|
688
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.36)",
|
|
689
|
+
durationFast: "120ms",
|
|
690
|
+
durationNormal: "180ms",
|
|
691
|
+
durationSlow: "280ms",
|
|
692
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
693
|
+
zOverlay: "50",
|
|
694
|
+
zModal: "60",
|
|
695
|
+
zToast: "70",
|
|
696
|
+
controlHeightSm: "40px",
|
|
697
|
+
controlHeightMd: "48px",
|
|
698
|
+
controlHeightLg: "56px",
|
|
699
|
+
density: "comfortable"
|
|
700
|
+
};
|
|
701
|
+
/** The factory day theme. Always registered; never the first paint though — the night theme is. */
|
|
702
|
+
const DEFAULT_LIGHT = {
|
|
703
|
+
id: DEFAULT_LIGHT_ID,
|
|
704
|
+
title: "钴蓝·白天",
|
|
598
705
|
tokens: {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
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
|
-
}
|
|
706
|
+
colorBg: "#e4e9ef",
|
|
707
|
+
colorSurface: "#f3f6f9",
|
|
708
|
+
colorSurfaceRaised: "#ffffff",
|
|
709
|
+
colorText: "#26323e",
|
|
710
|
+
colorMuted: "#5d6d7e",
|
|
711
|
+
colorPrimary: "#3857e8",
|
|
712
|
+
colorOnPrimary: "#ffffff",
|
|
713
|
+
colorDanger: "#dc2626",
|
|
714
|
+
colorSuccess: "#15803d",
|
|
715
|
+
colorWarning: "#b45309",
|
|
716
|
+
colorBorder: "#c7d0da",
|
|
717
|
+
colorFocus: "#3857e8",
|
|
718
|
+
chart1: "#3857e8",
|
|
719
|
+
chart2: "#7088ee",
|
|
720
|
+
chart3: "#667dd0",
|
|
721
|
+
chart4: "#94a3b8",
|
|
722
|
+
chart5: "#b3c0cd",
|
|
723
|
+
chart6: "#ccd6e0",
|
|
724
|
+
fontSans: "system-ui, \"Segoe UI\", \"Microsoft YaHei\", sans-serif",
|
|
725
|
+
fontMono: "\"Cascadia Code\", \"Cascadia Mono\", Consolas, ui-monospace, monospace",
|
|
726
|
+
textXs: "13px",
|
|
727
|
+
textSm: "15px",
|
|
728
|
+
textMd: "17px",
|
|
729
|
+
textLg: "20px",
|
|
730
|
+
textXl: "24px",
|
|
731
|
+
weightNormal: "400",
|
|
732
|
+
weightMedium: "500",
|
|
733
|
+
weightStrong: "600",
|
|
734
|
+
leadingTight: "1.2",
|
|
735
|
+
leadingNormal: "1.55",
|
|
736
|
+
spaceXs: "4px",
|
|
737
|
+
spaceSm: "8px",
|
|
738
|
+
spaceMd: "12px",
|
|
739
|
+
spaceLg: "20px",
|
|
740
|
+
spaceXl: "32px",
|
|
741
|
+
radiusSm: "6px",
|
|
742
|
+
radiusMd: "8px",
|
|
743
|
+
radiusLg: "12px",
|
|
744
|
+
radiusFull: "999px",
|
|
745
|
+
borderWidth: "1px",
|
|
746
|
+
shadowSm: "0 1px 2px rgb(0 0 0 / 0.08)",
|
|
747
|
+
shadowMd: "0 8px 24px rgb(0 0 0 / 0.12)",
|
|
748
|
+
shadowLg: "0 24px 64px rgb(0 0 0 / 0.18)",
|
|
749
|
+
durationFast: "120ms",
|
|
750
|
+
durationNormal: "180ms",
|
|
751
|
+
durationSlow: "280ms",
|
|
752
|
+
easeStandard: "cubic-bezier(0.2, 0, 0, 1)",
|
|
753
|
+
zOverlay: "50",
|
|
754
|
+
zModal: "60",
|
|
755
|
+
zToast: "70",
|
|
756
|
+
controlHeightSm: "40px",
|
|
757
|
+
controlHeightMd: "48px",
|
|
758
|
+
controlHeightLg: "56px",
|
|
759
|
+
density: "comfortable"
|
|
711
760
|
}
|
|
712
761
|
};
|
|
762
|
+
/** The factory night theme and the registry's fallback. */
|
|
763
|
+
const DEFAULT_DARK = {
|
|
764
|
+
id: DEFAULT_DARK_ID,
|
|
765
|
+
title: "钴蓝·黑夜",
|
|
766
|
+
tokens: COBALT_DARK_TOKENS
|
|
767
|
+
};
|
|
713
768
|
/** Turn a token key into its CSS custom property (`chart1` → `--snap-chart-1`). */
|
|
714
769
|
function skinTokenVar(key) {
|
|
715
770
|
return `--snap-${key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`).replace(/(\d+)$/, "-$1")}`;
|
|
716
771
|
}
|
|
717
|
-
/** Apply the active
|
|
718
|
-
function applySkin(skin
|
|
772
|
+
/** Apply the active theme to the document root. */
|
|
773
|
+
function applySkin(skin) {
|
|
719
774
|
if (typeof document === "undefined") return;
|
|
720
775
|
const root = document.documentElement;
|
|
721
776
|
root.dataset["snapSkin"] = skin.id;
|
|
722
|
-
|
|
723
|
-
const tokens = skin.tokens[mode];
|
|
724
|
-
for (const [key, value] of Object.entries(tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
777
|
+
for (const [key, value] of Object.entries(skin.tokens)) root.style.setProperty(skinTokenVar(key), value);
|
|
725
778
|
}
|
|
726
779
|
/** Mount the `ctx.skins` registry. */
|
|
727
780
|
const skinsPlugin = {
|
|
728
781
|
name: "snap-rail ui skins",
|
|
729
782
|
apply(ctx) {
|
|
730
783
|
const skins = /* @__PURE__ */ new Map();
|
|
784
|
+
const callers = /* @__PURE__ */ new Map();
|
|
731
785
|
const listeners = /* @__PURE__ */ new Set();
|
|
732
786
|
const styleTags = /* @__PURE__ */ new Map();
|
|
733
|
-
let activeId =
|
|
734
|
-
let mode = "dark";
|
|
787
|
+
let activeId = DEFAULT_DARK_ID;
|
|
735
788
|
let revision = 0;
|
|
736
|
-
skins.set(
|
|
789
|
+
skins.set(DEFAULT_LIGHT_ID, DEFAULT_LIGHT);
|
|
790
|
+
callers.set(DEFAULT_LIGHT_ID, FACTORY_CALLER);
|
|
791
|
+
skins.set(DEFAULT_DARK_ID, DEFAULT_DARK);
|
|
792
|
+
callers.set(DEFAULT_DARK_ID, FACTORY_CALLER);
|
|
737
793
|
const notify = () => {
|
|
738
794
|
revision += 1;
|
|
739
795
|
for (const listener of listeners) listener();
|
|
@@ -749,48 +805,52 @@ const skinsPlugin = {
|
|
|
749
805
|
styleTags.set(skin.id, tag);
|
|
750
806
|
};
|
|
751
807
|
const refresh = () => {
|
|
752
|
-
const skin = skins.get(activeId) ??
|
|
808
|
+
const skin = skins.get(activeId) ?? DEFAULT_DARK;
|
|
753
809
|
activeId = skin.id;
|
|
754
810
|
ensureStyleTag(skin);
|
|
755
|
-
applySkin(skin
|
|
811
|
+
applySkin(skin);
|
|
756
812
|
notify();
|
|
757
813
|
};
|
|
758
814
|
ctx.provide("skins", {
|
|
759
815
|
register(caller, skin) {
|
|
760
816
|
skins.set(skin.id, skin);
|
|
761
|
-
|
|
817
|
+
callers.set(skin.id, caller.fiber.name);
|
|
762
818
|
refresh();
|
|
763
819
|
const remove = () => {
|
|
764
820
|
if (!skins.delete(skin.id)) return;
|
|
821
|
+
callers.delete(skin.id);
|
|
765
822
|
const tag = styleTags.get(skin.id);
|
|
766
823
|
if (tag !== void 0) {
|
|
767
824
|
tag.remove();
|
|
768
825
|
styleTags.delete(skin.id);
|
|
769
826
|
}
|
|
770
|
-
if (activeId === skin.id) activeId =
|
|
827
|
+
if (activeId === skin.id) activeId = DEFAULT_DARK_ID;
|
|
771
828
|
refresh();
|
|
772
829
|
};
|
|
773
830
|
caller.effect(() => remove);
|
|
774
831
|
return remove;
|
|
775
832
|
},
|
|
776
|
-
activate(
|
|
777
|
-
|
|
778
|
-
|
|
833
|
+
activate(selection) {
|
|
834
|
+
let next = skins.has(selection) ? selection : void 0;
|
|
835
|
+
if (next === void 0) {
|
|
836
|
+
for (const [id, owner] of callers) if (id !== selection && owner === selection && skins.has(id)) {
|
|
837
|
+
next = id;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (next === void 0) return false;
|
|
842
|
+
if (next === activeId) return true;
|
|
843
|
+
activeId = next;
|
|
779
844
|
refresh();
|
|
780
845
|
return true;
|
|
781
846
|
},
|
|
782
|
-
list: () => [
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
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],
|
|
847
|
+
list: () => [...skins.values()].map((skin) => ({
|
|
848
|
+
id: skin.id,
|
|
849
|
+
title: skin.title,
|
|
850
|
+
caller: callers.get(skin.id) ?? FACTORY_CALLER
|
|
851
|
+
})),
|
|
852
|
+
active: () => skins.get(activeId) ?? DEFAULT_DARK,
|
|
853
|
+
tokens: () => (skins.get(activeId) ?? DEFAULT_DARK).tokens,
|
|
794
854
|
subscribe(listener) {
|
|
795
855
|
listeners.add(listener);
|
|
796
856
|
return () => {
|
|
@@ -817,17 +877,17 @@ function useSkins() {
|
|
|
817
877
|
if (service === null) throw new Error("useSkins: no SkinsProvider in the tree");
|
|
818
878
|
return service;
|
|
819
879
|
}
|
|
820
|
-
/** Re-render on
|
|
880
|
+
/** Re-render on theme changes and return the active token set. */
|
|
821
881
|
function useSkinTokens() {
|
|
822
882
|
const service = useSkins();
|
|
823
883
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
824
884
|
return service.tokens();
|
|
825
885
|
}
|
|
826
|
-
/** Re-render on
|
|
827
|
-
function
|
|
886
|
+
/** Re-render on theme changes and return the active theme id. */
|
|
887
|
+
function useSkinId() {
|
|
828
888
|
const service = useSkins();
|
|
829
889
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
830
|
-
return service.
|
|
890
|
+
return service.active().id;
|
|
831
891
|
}
|
|
832
892
|
//#endregion
|
|
833
893
|
//#region lib/types/charts.js
|
|
@@ -845,6 +905,7 @@ function ChartFrame({ title, description, actions, state = "ready", empty, error
|
|
|
845
905
|
...part("chart-frame", "title"),
|
|
846
906
|
children: title
|
|
847
907
|
}), description !== void 0 && jsx("div", {
|
|
908
|
+
...part("chart-frame", "description"),
|
|
848
909
|
className: "snap-chart-frame-description",
|
|
849
910
|
children: description
|
|
850
911
|
})] }), actions !== void 0 && jsx("div", {
|
|
@@ -856,20 +917,20 @@ function ChartFrame({ title, description, actions, state = "ready", empty, error
|
|
|
856
917
|
className: "snap-chart-frame-body",
|
|
857
918
|
"data-state": state,
|
|
858
919
|
children: state === "loading" ? loading ?? jsx("div", {
|
|
859
|
-
...part("
|
|
920
|
+
...part("chart-frame", "loading"),
|
|
860
921
|
children: "加载中…"
|
|
861
922
|
}) : state === "empty" ? empty ?? jsx("div", {
|
|
862
|
-
...part("
|
|
923
|
+
...part("chart-frame", "empty"),
|
|
863
924
|
children: "暂无数据"
|
|
864
925
|
}) : state === "error" ? error ?? jsx("div", {
|
|
865
|
-
...part("
|
|
926
|
+
...part("chart-frame", "error"),
|
|
866
927
|
role: "alert",
|
|
867
928
|
children: "图表加载失败"
|
|
868
929
|
}) : children
|
|
869
930
|
})]
|
|
870
931
|
});
|
|
871
932
|
}
|
|
872
|
-
/**
|
|
933
|
+
/** An alias of {@link ChartFrame} for pages that prefer the generic name. */
|
|
873
934
|
function Visualization(props) {
|
|
874
935
|
return jsx(ChartFrame, { ...props });
|
|
875
936
|
}
|
|
@@ -910,6 +971,116 @@ function useChartTheme() {
|
|
|
910
971
|
return chartThemeOf(useSkinTokens());
|
|
911
972
|
}
|
|
912
973
|
//#endregion
|
|
974
|
+
//#region lib/types/components/alert.js
|
|
975
|
+
/**
|
|
976
|
+
* Attention surfaces: alerts (inline banners), separators, skeletons, and
|
|
977
|
+
* lists. Read-only primitives; the skin owns their visuals through the
|
|
978
|
+
* `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
|
|
979
|
+
*
|
|
980
|
+
* @module @snap-rail/ui/components/alert
|
|
981
|
+
*/
|
|
982
|
+
/** An inline status banner for results and failures. */
|
|
983
|
+
function Alert({ intent = "neutral", className, children, ...props }) {
|
|
984
|
+
return jsx("div", {
|
|
985
|
+
...part("alert", "root"),
|
|
986
|
+
role: "alert",
|
|
987
|
+
className: cn("snap-alert", className),
|
|
988
|
+
"data-intent": intent,
|
|
989
|
+
...props,
|
|
990
|
+
children
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
/** The alert heading line. */
|
|
994
|
+
function AlertTitle({ className, children, ...props }) {
|
|
995
|
+
return jsx("h5", {
|
|
996
|
+
...part("alert", "title"),
|
|
997
|
+
className: cn("snap-alert-title", className),
|
|
998
|
+
...props,
|
|
999
|
+
children
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
/** The alert body text. */
|
|
1003
|
+
function AlertDescription({ className, children, ...props }) {
|
|
1004
|
+
return jsx("div", {
|
|
1005
|
+
...part("alert", "description"),
|
|
1006
|
+
className: cn("snap-alert-description", className),
|
|
1007
|
+
...props,
|
|
1008
|
+
children
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
/** A themed rule between sections. */
|
|
1012
|
+
function Separator({ orientation = "horizontal", className, ...props }) {
|
|
1013
|
+
return jsx(SeparatorPrimitive.Root, {
|
|
1014
|
+
...part("separator", "root"),
|
|
1015
|
+
orientation,
|
|
1016
|
+
className: cn("snap-separator", className),
|
|
1017
|
+
...props
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
/** A neutral loading placeholder shaped by the skin. */
|
|
1021
|
+
function Skeleton({ variant = "block", className, ...props }) {
|
|
1022
|
+
return jsx("div", {
|
|
1023
|
+
...part("skeleton", "root"),
|
|
1024
|
+
className: cn("snap-skeleton", className),
|
|
1025
|
+
"data-variant": variant,
|
|
1026
|
+
"aria-hidden": "true",
|
|
1027
|
+
...props
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
/** A vertical collection of {@link ListItem} rows. */
|
|
1031
|
+
function List({ divided = false, className, children, ...props }) {
|
|
1032
|
+
return jsx("ul", {
|
|
1033
|
+
...part("list", "root"),
|
|
1034
|
+
className: cn("snap-list", className),
|
|
1035
|
+
"data-divided": divided || void 0,
|
|
1036
|
+
...props,
|
|
1037
|
+
children
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
/** One list row with leading/trailing slots. */
|
|
1041
|
+
function ListItem({ leading, trailing, selected = false, disabled = false, onClick, className, children, ...props }) {
|
|
1042
|
+
const interactive = onClick !== void 0 && !disabled;
|
|
1043
|
+
const activate = (event) => {
|
|
1044
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1045
|
+
event.preventDefault();
|
|
1046
|
+
onClick?.();
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
return jsxs("li", {
|
|
1050
|
+
...part("list", "item"),
|
|
1051
|
+
className: cn("snap-list-item", className),
|
|
1052
|
+
"data-selected": selected || void 0,
|
|
1053
|
+
"data-interactive": interactive || void 0,
|
|
1054
|
+
"data-disabled": disabled || void 0,
|
|
1055
|
+
"aria-disabled": disabled || void 0,
|
|
1056
|
+
...interactive ? {
|
|
1057
|
+
role: "button",
|
|
1058
|
+
tabIndex: 0,
|
|
1059
|
+
onClick,
|
|
1060
|
+
onKeyDown: activate
|
|
1061
|
+
} : {},
|
|
1062
|
+
...props,
|
|
1063
|
+
children: [
|
|
1064
|
+
leading !== void 0 && jsx("span", {
|
|
1065
|
+
...part("list", "leading"),
|
|
1066
|
+
children: leading
|
|
1067
|
+
}),
|
|
1068
|
+
jsx("span", {
|
|
1069
|
+
...part("list", "content"),
|
|
1070
|
+
style: {
|
|
1071
|
+
flex: 1,
|
|
1072
|
+
minWidth: 0
|
|
1073
|
+
},
|
|
1074
|
+
children
|
|
1075
|
+
}),
|
|
1076
|
+
trailing !== void 0 && jsx("span", {
|
|
1077
|
+
...part("list", "trailing"),
|
|
1078
|
+
children: trailing
|
|
1079
|
+
})
|
|
1080
|
+
]
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
//#endregion
|
|
913
1084
|
//#region lib/types/components/button.js
|
|
914
1085
|
/**
|
|
915
1086
|
* Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
|
|
@@ -1011,7 +1182,7 @@ const DialogTrigger = DialogPrimitive.Trigger;
|
|
|
1011
1182
|
/** The dialog close. */
|
|
1012
1183
|
const DialogClose = DialogPrimitive.Close;
|
|
1013
1184
|
/** The portalled dialog content. */
|
|
1014
|
-
function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true }) {
|
|
1185
|
+
function DialogContent({ children, className, presentation = "auto", size = "md", showClose = true, ...rest }) {
|
|
1015
1186
|
const resolved = presentation === "auto" ? "modal" : presentation;
|
|
1016
1187
|
return jsxs(DialogPrimitive.Portal, { children: [jsx(DialogPrimitive.Overlay, {
|
|
1017
1188
|
...part("dialog", "overlay"),
|
|
@@ -1021,6 +1192,7 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
|
|
|
1021
1192
|
className: cn("snap-dialog-panel", className),
|
|
1022
1193
|
"data-presentation": resolved,
|
|
1023
1194
|
"data-size": size,
|
|
1195
|
+
...rest,
|
|
1024
1196
|
children: [children, showClose && jsx(DialogPrimitive.Close, {
|
|
1025
1197
|
...part("dialog", "close"),
|
|
1026
1198
|
className: "snap-dialog-close",
|
|
@@ -1094,7 +1266,14 @@ function Label({ className, children, ...props }) {
|
|
|
1094
1266
|
});
|
|
1095
1267
|
}
|
|
1096
1268
|
/** The tabs root. */
|
|
1097
|
-
|
|
1269
|
+
function Tabs({ className, children, ...props }) {
|
|
1270
|
+
return jsx(TabsPrimitive.Root, {
|
|
1271
|
+
...part("tabs", "root"),
|
|
1272
|
+
className: cn("snap-tabs", className),
|
|
1273
|
+
...props,
|
|
1274
|
+
children
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1098
1277
|
/** The tabs list. */
|
|
1099
1278
|
function TabsList({ className, children, ...props }) {
|
|
1100
1279
|
return jsx(TabsPrimitive.List, {
|
|
@@ -1122,51 +1301,101 @@ function TabsContent({ className, children, ...props }) {
|
|
|
1122
1301
|
children
|
|
1123
1302
|
});
|
|
1124
1303
|
}
|
|
1125
|
-
/** A boolean switch. */
|
|
1126
|
-
function Switch({ className, label, ...props }) {
|
|
1127
|
-
|
|
1304
|
+
/** A boolean switch with an optional label on either side. */
|
|
1305
|
+
function Switch({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
|
|
1306
|
+
const labelNode = label !== void 0 && jsx("span", {
|
|
1307
|
+
...part("switch", "label"),
|
|
1308
|
+
children: label
|
|
1309
|
+
});
|
|
1310
|
+
const row = jsxs("label", {
|
|
1128
1311
|
className: "snap-switch-label",
|
|
1129
|
-
children: [
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
...
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1312
|
+
children: [
|
|
1313
|
+
labelPosition === "start" && labelNode,
|
|
1314
|
+
jsx(SwitchPrimitive.Root, {
|
|
1315
|
+
...part("switch", "root"),
|
|
1316
|
+
className: cn("snap-switch", className),
|
|
1317
|
+
...props,
|
|
1318
|
+
children: jsx(SwitchPrimitive.Thumb, {
|
|
1319
|
+
...part("switch", "thumb"),
|
|
1320
|
+
className: "snap-switch-thumb"
|
|
1321
|
+
})
|
|
1322
|
+
}),
|
|
1323
|
+
labelPosition === "end" && labelNode
|
|
1324
|
+
]
|
|
1325
|
+
});
|
|
1326
|
+
if (description === void 0) return row;
|
|
1327
|
+
return jsxs("span", {
|
|
1328
|
+
...part("switch", "field"),
|
|
1329
|
+
className: cn("snap-switch-field", containerClassName),
|
|
1330
|
+
children: [row, jsx("span", {
|
|
1331
|
+
...part("switch", "description"),
|
|
1332
|
+
className: "snap-field-help",
|
|
1333
|
+
children: description
|
|
1140
1334
|
})]
|
|
1141
1335
|
});
|
|
1142
1336
|
}
|
|
1143
|
-
/** A tri-state checkbox with an
|
|
1144
|
-
function Checkbox({ className, label, ...props }) {
|
|
1145
|
-
|
|
1337
|
+
/** A tri-state checkbox with an optional label on either side. */
|
|
1338
|
+
function Checkbox({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
|
|
1339
|
+
const labelNode = label !== void 0 && jsx("span", {
|
|
1340
|
+
...part("checkbox", "label"),
|
|
1341
|
+
children: label
|
|
1342
|
+
});
|
|
1343
|
+
const row = jsxs("label", {
|
|
1146
1344
|
className: "snap-checkbox-label",
|
|
1147
|
-
children: [
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
...
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1345
|
+
children: [
|
|
1346
|
+
labelPosition === "start" && labelNode,
|
|
1347
|
+
jsx(CheckboxPrimitive.Root, {
|
|
1348
|
+
...part("checkbox", "root"),
|
|
1349
|
+
className: cn("snap-checkbox", className),
|
|
1350
|
+
...props,
|
|
1351
|
+
children: jsx(CheckboxPrimitive.Indicator, {
|
|
1352
|
+
...part("checkbox", "indicator"),
|
|
1353
|
+
className: "snap-checkbox-indicator",
|
|
1354
|
+
children: "✓"
|
|
1355
|
+
})
|
|
1356
|
+
}),
|
|
1357
|
+
labelPosition === "end" && labelNode
|
|
1358
|
+
]
|
|
1359
|
+
});
|
|
1360
|
+
if (description === void 0) return row;
|
|
1361
|
+
return jsxs("span", {
|
|
1362
|
+
...part("checkbox", "field"),
|
|
1363
|
+
className: cn("snap-checkbox-field", containerClassName),
|
|
1364
|
+
children: [row, jsx("span", {
|
|
1365
|
+
...part("checkbox", "description"),
|
|
1366
|
+
className: "snap-field-help",
|
|
1367
|
+
children: description
|
|
1159
1368
|
})]
|
|
1160
1369
|
});
|
|
1161
1370
|
}
|
|
1162
|
-
/**
|
|
1163
|
-
function RadioGroup({ className, children, ...props }) {
|
|
1164
|
-
|
|
1371
|
+
/** A labelled group of radio items. */
|
|
1372
|
+
function RadioGroup({ className, label, description, children, ...props }) {
|
|
1373
|
+
const labelId = useId();
|
|
1374
|
+
const group = jsx(RadioGroupPrimitive.Root, {
|
|
1165
1375
|
...part("radio-group", "root"),
|
|
1166
1376
|
className: cn("snap-radio-group", className),
|
|
1377
|
+
...label !== void 0 ? { "aria-labelledby": labelId } : {},
|
|
1167
1378
|
...props,
|
|
1168
1379
|
children
|
|
1169
1380
|
});
|
|
1381
|
+
if (label === void 0 && description === void 0) return group;
|
|
1382
|
+
return jsxs("div", {
|
|
1383
|
+
...part("radio-group", "block"),
|
|
1384
|
+
className: "snap-radio-group-block",
|
|
1385
|
+
children: [
|
|
1386
|
+
label !== void 0 && jsx(Label, {
|
|
1387
|
+
id: labelId,
|
|
1388
|
+
...part("radio-group", "label"),
|
|
1389
|
+
children: label
|
|
1390
|
+
}),
|
|
1391
|
+
group,
|
|
1392
|
+
description !== void 0 && jsx("div", {
|
|
1393
|
+
...part("radio-group", "description"),
|
|
1394
|
+
className: "snap-field-help",
|
|
1395
|
+
children: description
|
|
1396
|
+
})
|
|
1397
|
+
]
|
|
1398
|
+
});
|
|
1170
1399
|
}
|
|
1171
1400
|
/** One radio item. */
|
|
1172
1401
|
function RadioGroupItem({ className, ...props }) {
|
|
@@ -1184,101 +1413,165 @@ function RadioGroupItem({ className, ...props }) {
|
|
|
1184
1413
|
function TouchSelect({ value, onValueChange, options, placeholder = "请选择", disabled = false, invalid = false, size = "md", className, "aria-label": ariaLabel, title }) {
|
|
1185
1414
|
const [open, setOpen] = useState(false);
|
|
1186
1415
|
const selected = options.find((option) => option.value === value);
|
|
1187
|
-
return jsxs(
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1416
|
+
return jsxs("span", {
|
|
1417
|
+
...part("touch-select", "root"),
|
|
1418
|
+
className: "snap-touch-select",
|
|
1419
|
+
children: [jsxs(Button, {
|
|
1420
|
+
type: "button",
|
|
1421
|
+
size,
|
|
1422
|
+
emphasis: "outline",
|
|
1423
|
+
className,
|
|
1424
|
+
disabled,
|
|
1425
|
+
"aria-label": ariaLabel,
|
|
1426
|
+
"aria-invalid": invalid || void 0,
|
|
1427
|
+
"aria-haspopup": "dialog",
|
|
1428
|
+
onClick: () => setOpen(true),
|
|
1429
|
+
...part("touch-select", "trigger"),
|
|
1430
|
+
children: [jsx("span", {
|
|
1431
|
+
style: {
|
|
1432
|
+
flex: 1,
|
|
1433
|
+
textAlign: "left"
|
|
1434
|
+
},
|
|
1435
|
+
children: selected?.label ?? placeholder
|
|
1436
|
+
}), jsx("span", {
|
|
1437
|
+
"aria-hidden": "true",
|
|
1438
|
+
children: "▾"
|
|
1439
|
+
})]
|
|
1440
|
+
}), jsx(Dialog, {
|
|
1441
|
+
open,
|
|
1442
|
+
onOpenChange: setOpen,
|
|
1443
|
+
children: jsxs(DialogContent, {
|
|
1444
|
+
presentation: "modal",
|
|
1445
|
+
size: "sm",
|
|
1446
|
+
...part("touch-select", "sheet"),
|
|
1447
|
+
children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: title ?? ariaLabel ?? "请选择" }) }), jsxs("div", {
|
|
1448
|
+
...part("touch-select", "options"),
|
|
1449
|
+
style: {
|
|
1450
|
+
display: "flex",
|
|
1451
|
+
flexDirection: "column",
|
|
1452
|
+
gap: "var(--snap-space-sm)"
|
|
1453
|
+
},
|
|
1454
|
+
children: [options.map((option) => jsx(Button, {
|
|
1455
|
+
type: "button",
|
|
1456
|
+
size: "lg",
|
|
1457
|
+
emphasis: option.value === value ? "solid" : "outline",
|
|
1458
|
+
intent: option.value === value ? "primary" : "neutral",
|
|
1459
|
+
disabled: option.disabled === true,
|
|
1460
|
+
onClick: () => {
|
|
1461
|
+
onValueChange?.(option.value);
|
|
1462
|
+
setOpen(false);
|
|
1463
|
+
},
|
|
1464
|
+
...part("touch-select", "option"),
|
|
1465
|
+
children: option.label
|
|
1466
|
+
}, option.value)), options.length === 0 && jsx("span", {
|
|
1467
|
+
style: { color: "var(--snap-color-muted)" },
|
|
1468
|
+
children: "无可选项"
|
|
1469
|
+
})]
|
|
1470
|
+
})]
|
|
1471
|
+
})
|
|
1472
|
+
})]
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
/** The select trigger; composes a {@link SelectValue} inside. */
|
|
1476
|
+
function SelectTrigger({ className, size = "md", invalid = false, disabled = false, children, ...props }) {
|
|
1477
|
+
return jsxs(SelectPrimitive.Trigger, {
|
|
1478
|
+
...part("select", "trigger"),
|
|
1479
|
+
className: cn("snap-select-trigger", className),
|
|
1480
|
+
"data-size": size,
|
|
1481
|
+
"data-invalid": invalid || void 0,
|
|
1482
|
+
"data-disabled": disabled || void 0,
|
|
1194
1483
|
"aria-invalid": invalid || void 0,
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
flex: 1,
|
|
1200
|
-
textAlign: "left"
|
|
1201
|
-
},
|
|
1202
|
-
children: selected?.label ?? placeholder
|
|
1203
|
-
}), jsx("span", {
|
|
1204
|
-
"aria-hidden": "true",
|
|
1484
|
+
...props,
|
|
1485
|
+
children: [children, jsx(SelectPrimitive.Icon, {
|
|
1486
|
+
...part("select", "chevron"),
|
|
1487
|
+
className: "snap-select-chevron",
|
|
1205
1488
|
children: "▾"
|
|
1206
1489
|
})]
|
|
1207
|
-
})
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
/** The selected-value slot of a trigger. */
|
|
1493
|
+
function SelectValue(props) {
|
|
1494
|
+
return jsx(SelectPrimitive.Value, {
|
|
1495
|
+
...part("select", "value"),
|
|
1496
|
+
...props
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
/** The portalled option list. */
|
|
1500
|
+
function SelectContent({ side = "bottom", align = "start", sideOffset = 4, className, children, ...props }) {
|
|
1501
|
+
return jsx(SelectPrimitive.Portal, { children: jsx(SelectPrimitive.Content, {
|
|
1502
|
+
...part("select", "content"),
|
|
1503
|
+
className: cn("snap-select-content", className),
|
|
1504
|
+
position: "popper",
|
|
1505
|
+
side,
|
|
1506
|
+
align,
|
|
1507
|
+
sideOffset,
|
|
1508
|
+
...props,
|
|
1509
|
+
children: jsx(SelectPrimitive.Viewport, { children })
|
|
1510
|
+
}) });
|
|
1511
|
+
}
|
|
1512
|
+
/** One option row. */
|
|
1513
|
+
function SelectItem({ className, children, ...props }) {
|
|
1514
|
+
return jsxs(SelectPrimitive.Item, {
|
|
1515
|
+
...part("select", "item"),
|
|
1516
|
+
className: cn("snap-select-item", className),
|
|
1517
|
+
...props,
|
|
1518
|
+
children: [jsx(SelectPrimitive.ItemText, { children }), jsx(SelectPrimitive.ItemIndicator, {
|
|
1519
|
+
...part("select", "item-indicator"),
|
|
1520
|
+
className: "snap-select-item-indicator",
|
|
1521
|
+
children: "✓"
|
|
1522
|
+
})]
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
/** A labelled group of options. */
|
|
1526
|
+
function SelectGroup(props) {
|
|
1527
|
+
return jsx(SelectPrimitive.Group, { ...props });
|
|
1528
|
+
}
|
|
1529
|
+
/** A group heading. */
|
|
1530
|
+
function SelectLabel({ className, ...props }) {
|
|
1531
|
+
return jsx(SelectPrimitive.Label, {
|
|
1532
|
+
className: cn("snap-select-label", className),
|
|
1533
|
+
...props
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
/** A popover select: data-driven via `options`, or composed from
|
|
1537
|
+
* {@link SelectItem} children for full layout control. */
|
|
1538
|
+
function Select({ value, defaultValue, onValueChange, options, children, placeholder = "请选择", disabled = false, invalid = false, required, name, id, size = "md", side = "bottom", align = "start", sideOffset = 4, className, contentClassName, "aria-label": ariaLabel }) {
|
|
1539
|
+
const composite = children !== void 0;
|
|
1540
|
+
const empty = !composite && (options ?? []).length === 0;
|
|
1541
|
+
return jsx("span", {
|
|
1542
|
+
...part("select", "root"),
|
|
1543
|
+
className: "snap-select",
|
|
1544
|
+
children: jsxs(SelectPrimitive.Root, {
|
|
1545
|
+
...value !== void 0 ? { value } : {},
|
|
1546
|
+
...defaultValue !== void 0 ? { defaultValue } : {},
|
|
1547
|
+
...onValueChange !== void 0 ? { onValueChange } : {},
|
|
1548
|
+
disabled,
|
|
1549
|
+
...name !== void 0 ? { name } : {},
|
|
1550
|
+
...required !== void 0 ? { required } : {},
|
|
1551
|
+
children: [jsx(SelectTrigger, {
|
|
1552
|
+
id,
|
|
1553
|
+
size,
|
|
1554
|
+
invalid,
|
|
1555
|
+
disabled,
|
|
1556
|
+
className,
|
|
1557
|
+
"aria-label": ariaLabel,
|
|
1558
|
+
children: jsx(SelectValue, { placeholder })
|
|
1559
|
+
}), jsxs(SelectContent, {
|
|
1560
|
+
side,
|
|
1561
|
+
align,
|
|
1562
|
+
sideOffset,
|
|
1563
|
+
className: contentClassName,
|
|
1564
|
+
children: [composite ? children : (options ?? []).map((option) => jsx(SelectItem, {
|
|
1565
|
+
value: option.value,
|
|
1225
1566
|
disabled: option.disabled === true,
|
|
1226
|
-
onClick: () => {
|
|
1227
|
-
onValueChange?.(option.value);
|
|
1228
|
-
setOpen(false);
|
|
1229
|
-
},
|
|
1230
1567
|
children: option.label
|
|
1231
|
-
}, option.value)),
|
|
1232
|
-
|
|
1568
|
+
}, option.value)), empty && jsx("div", {
|
|
1569
|
+
...part("select", "empty"),
|
|
1570
|
+
className: "snap-select-empty",
|
|
1233
1571
|
children: "无可选项"
|
|
1234
1572
|
})]
|
|
1235
1573
|
})]
|
|
1236
1574
|
})
|
|
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
1575
|
});
|
|
1283
1576
|
}
|
|
1284
1577
|
//#endregion
|
|
@@ -1357,17 +1650,26 @@ function EmptyState({ title, description, icon, action, className }) {
|
|
|
1357
1650
|
//#endregion
|
|
1358
1651
|
//#region lib/types/components/form.js
|
|
1359
1652
|
/** A labelled form row. */
|
|
1360
|
-
function Field({ label, htmlFor, help, error, invalid = false, required = false, children, className }) {
|
|
1653
|
+
function Field({ label, htmlFor, help, error, invalid = false, required = false, orientation = "vertical", labelWidth, labelAlign = "start", children, className, style }) {
|
|
1361
1654
|
const bad = invalid || error !== void 0;
|
|
1362
1655
|
return jsxs("div", {
|
|
1363
1656
|
...part("field", "root"),
|
|
1364
1657
|
className: cn("snap-field", className),
|
|
1365
1658
|
"data-invalid": bad || void 0,
|
|
1366
1659
|
"data-required": required || void 0,
|
|
1660
|
+
"data-orientation": orientation,
|
|
1661
|
+
style,
|
|
1367
1662
|
children: [
|
|
1368
1663
|
label !== void 0 && jsxs(Label, {
|
|
1369
1664
|
...htmlFor !== void 0 ? { htmlFor } : {},
|
|
1370
1665
|
...part("field", "label"),
|
|
1666
|
+
style: {
|
|
1667
|
+
...labelWidth !== void 0 ? {
|
|
1668
|
+
width: typeof labelWidth === "number" ? `${labelWidth}px` : labelWidth,
|
|
1669
|
+
flexShrink: 0
|
|
1670
|
+
} : {},
|
|
1671
|
+
...labelAlign !== "start" ? { textAlign: labelAlign } : {}
|
|
1672
|
+
},
|
|
1371
1673
|
children: [label, required && jsx("span", {
|
|
1372
1674
|
"aria-hidden": "true",
|
|
1373
1675
|
children: " *"
|
|
@@ -1392,29 +1694,163 @@ function Field({ label, htmlFor, help, error, invalid = false, required = false,
|
|
|
1392
1694
|
});
|
|
1393
1695
|
}
|
|
1394
1696
|
/** A form with a fields region and an actions region. */
|
|
1395
|
-
function Form({ children, actions, onSubmit, className }) {
|
|
1396
|
-
|
|
1697
|
+
function Form({ children, actions, onSubmit, className, orientation = "stack", gap = "md", columns = 2, form, onValid, onInvalid }) {
|
|
1698
|
+
const fieldsStyle = orientation === "grid" ? {
|
|
1699
|
+
display: "grid",
|
|
1700
|
+
gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
|
|
1701
|
+
gap: space(gap)
|
|
1702
|
+
} : orientation === "inline" ? {
|
|
1703
|
+
display: "flex",
|
|
1704
|
+
flexDirection: "row",
|
|
1705
|
+
flexWrap: "wrap",
|
|
1706
|
+
gap: space(gap)
|
|
1707
|
+
} : {
|
|
1708
|
+
display: "flex",
|
|
1709
|
+
flexDirection: "column",
|
|
1710
|
+
gap: space(gap)
|
|
1711
|
+
};
|
|
1712
|
+
const body = jsxs(Fragment, { children: [jsx("div", {
|
|
1713
|
+
...part("form", "fields"),
|
|
1714
|
+
className: "snap-form-fields",
|
|
1715
|
+
style: fieldsStyle,
|
|
1716
|
+
children
|
|
1717
|
+
}), actions !== void 0 && jsx("div", {
|
|
1718
|
+
...part("form", "actions"),
|
|
1719
|
+
className: "snap-form-actions",
|
|
1720
|
+
children: actions
|
|
1721
|
+
})] });
|
|
1722
|
+
const submit = form !== void 0 && onValid !== void 0 ? form.handleSubmit(onValid, onInvalid) : onSubmit;
|
|
1723
|
+
if (form === void 0) return jsx("form", {
|
|
1397
1724
|
...part("form", "root"),
|
|
1398
1725
|
className: cn("snap-form", className),
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1726
|
+
"data-orientation": orientation,
|
|
1727
|
+
onSubmit: submit,
|
|
1728
|
+
children: body
|
|
1729
|
+
});
|
|
1730
|
+
return jsx(FormProvider$1, {
|
|
1731
|
+
...form,
|
|
1732
|
+
children: jsx("form", {
|
|
1733
|
+
...part("form", "root"),
|
|
1734
|
+
className: cn("snap-form", className),
|
|
1735
|
+
"data-orientation": orientation,
|
|
1736
|
+
onSubmit: submit,
|
|
1737
|
+
children: body
|
|
1738
|
+
})
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
//#endregion
|
|
1742
|
+
//#region lib/types/components/form-rhf.js
|
|
1743
|
+
/**
|
|
1744
|
+
* React Hook Form integration in the shadcn composite shape: `FormField`
|
|
1745
|
+
* binds a controller, `FormItem`/`FormLabel`/`FormControl`/
|
|
1746
|
+
* `FormDescription`/`FormMessage` render the same `field.*` anatomy the plain
|
|
1747
|
+
* {@link Field} uses, driven by the form state. The RHF hooks and
|
|
1748
|
+
* `zodResolver` are re-exported so plugin bundles consume the seed's single
|
|
1749
|
+
* module instance — RHF context is module-scoped, and a copy bundled inside a
|
|
1750
|
+
* plugin zip would never see the form state.
|
|
1751
|
+
*
|
|
1752
|
+
* @module @snap-rail/ui/components/form-rhf
|
|
1753
|
+
*/
|
|
1754
|
+
const FormFieldContext = createContext(null);
|
|
1755
|
+
const FormItemContext = createContext(null);
|
|
1756
|
+
/** Read the enclosing field binding; fails loud outside a {@link FormField}. */
|
|
1757
|
+
function useFormField() {
|
|
1758
|
+
const field = useContext(FormFieldContext);
|
|
1759
|
+
const item = useContext(FormItemContext);
|
|
1760
|
+
if (field === null || item === null) throw new Error("表单字段部件必须渲染在 FormField 内");
|
|
1761
|
+
return {
|
|
1762
|
+
id: item.id,
|
|
1763
|
+
name: field.name
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
/** Bind a controller and expose its name to the anatomy parts inside. */
|
|
1767
|
+
function FormField(props) {
|
|
1768
|
+
const name = props.name;
|
|
1769
|
+
return jsx(FormFieldContext.Provider, {
|
|
1770
|
+
value: { name },
|
|
1771
|
+
children: jsx(Controller$1, {
|
|
1772
|
+
...props,
|
|
1773
|
+
name,
|
|
1774
|
+
render: props.render
|
|
1775
|
+
})
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
/** The field row: owns the shared id every aria attribute anchors to. */
|
|
1779
|
+
function FormItem({ children, className, orientation = "vertical" }) {
|
|
1780
|
+
const id = useId();
|
|
1781
|
+
return jsx(FormItemContext.Provider, {
|
|
1782
|
+
value: { id },
|
|
1783
|
+
children: jsx("div", {
|
|
1784
|
+
...part("field", "root"),
|
|
1785
|
+
className: cn("snap-field", className),
|
|
1786
|
+
"data-orientation": orientation,
|
|
1403
1787
|
children
|
|
1404
|
-
})
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1788
|
+
})
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
/** The field label; carries `data-invalid` when the field has an error. */
|
|
1792
|
+
function FormLabel({ className, children }) {
|
|
1793
|
+
const { id, name } = useFormField();
|
|
1794
|
+
const invalid = useFormState$1({ name }).errors[name] !== void 0;
|
|
1795
|
+
return jsx(Label, {
|
|
1796
|
+
htmlFor: id,
|
|
1797
|
+
...part("field", "label"),
|
|
1798
|
+
className: cn("snap-form-label", className),
|
|
1799
|
+
"data-invalid": invalid || void 0,
|
|
1800
|
+
children
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
/** Merges the field binding onto the single control child it wraps. */
|
|
1804
|
+
function FormControl({ children }) {
|
|
1805
|
+
const { id, name } = useFormField();
|
|
1806
|
+
const invalid = useFormState$1({ name }).errors[name] !== void 0;
|
|
1807
|
+
return jsx(Slot$1, {
|
|
1808
|
+
id,
|
|
1809
|
+
"aria-invalid": invalid || void 0,
|
|
1810
|
+
"aria-describedby": `${id}-description ${id}-message`,
|
|
1811
|
+
children
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
/** Helper text under the control; linked as `aria-describedby`. */
|
|
1815
|
+
function FormDescription({ className, children }) {
|
|
1816
|
+
const { id } = useFormField();
|
|
1817
|
+
return jsx("div", {
|
|
1818
|
+
...part("field", "help"),
|
|
1819
|
+
id: `${id}-description`,
|
|
1820
|
+
className: cn("snap-field-help", className),
|
|
1821
|
+
children
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
/** The validation message for the bound field. */
|
|
1825
|
+
function FormMessage({ message, children, className }) {
|
|
1826
|
+
const { id, name } = useFormField();
|
|
1827
|
+
const raw = useFormState$1({ name }).errors[name]?.message;
|
|
1828
|
+
const body = message ?? (typeof raw === "string" || typeof raw === "number" || typeof raw === "bigint" || typeof raw === "boolean" ? String(raw) : void 0) ?? children;
|
|
1829
|
+
if (body === void 0 || body === "") return null;
|
|
1830
|
+
return jsx("div", {
|
|
1831
|
+
...part("field", "error"),
|
|
1832
|
+
id: `${id}-message`,
|
|
1833
|
+
className: cn("snap-field-error", className),
|
|
1834
|
+
role: "alert",
|
|
1835
|
+
children: body
|
|
1409
1836
|
});
|
|
1410
1837
|
}
|
|
1411
1838
|
//#endregion
|
|
1412
1839
|
//#region lib/types/components/input.js
|
|
1413
|
-
/**
|
|
1414
|
-
|
|
1840
|
+
/**
|
|
1841
|
+
* Text-entry semantics: the wrapper owns the anatomy (prefix/suffix/clear),
|
|
1842
|
+
* the native field keeps keyboard and IME behaviour. Skins style the parts.
|
|
1843
|
+
*
|
|
1844
|
+
* @module @snap-rail/ui/components/input
|
|
1845
|
+
*/
|
|
1846
|
+
/** A single-line text field with semantic prefix/suffix slots. Layout
|
|
1847
|
+
* `style`/`className` dress the wrapper — the visible control; the native
|
|
1848
|
+
* field already stretches inside it. */
|
|
1849
|
+
function Input({ size = "md", invalid = false, prefix, suffix, onClear, fieldClassName, componentName = "input", className, style, disabled, ...props }) {
|
|
1415
1850
|
return jsxs("div", {
|
|
1416
1851
|
...part(componentName, "root"),
|
|
1417
1852
|
className: cn("snap-input", className),
|
|
1853
|
+
style,
|
|
1418
1854
|
"data-size": size,
|
|
1419
1855
|
"data-invalid": invalid || void 0,
|
|
1420
1856
|
"data-disabled": disabled === true || void 0,
|
|
@@ -1425,7 +1861,7 @@ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componen
|
|
|
1425
1861
|
}),
|
|
1426
1862
|
jsx("input", {
|
|
1427
1863
|
...part(componentName, "field"),
|
|
1428
|
-
className: "snap-input-field",
|
|
1864
|
+
className: cn("snap-input-field", fieldClassName),
|
|
1429
1865
|
disabled,
|
|
1430
1866
|
"aria-invalid": invalid || void 0,
|
|
1431
1867
|
...props
|
|
@@ -1445,37 +1881,95 @@ function Input({ size = "md", invalid = false, prefix, suffix, onClear, componen
|
|
|
1445
1881
|
]
|
|
1446
1882
|
});
|
|
1447
1883
|
}
|
|
1448
|
-
/** A multi-line text field.
|
|
1449
|
-
|
|
1884
|
+
/** A multi-line text field. Like {@link Input}, layout `style`/`className`
|
|
1885
|
+
* dress the wrapper; the field stretches inside it. */
|
|
1886
|
+
function Textarea({ size = "md", invalid = false, fieldClassName, className, style, disabled, ...props }) {
|
|
1450
1887
|
return jsx("div", {
|
|
1451
1888
|
...part("textarea", "root"),
|
|
1452
1889
|
className: cn("snap-textarea", className),
|
|
1890
|
+
style,
|
|
1453
1891
|
"data-size": size,
|
|
1454
1892
|
"data-invalid": invalid || void 0,
|
|
1455
1893
|
"data-disabled": disabled === true || void 0,
|
|
1456
1894
|
children: jsx("textarea", {
|
|
1457
1895
|
...part("textarea", "field"),
|
|
1458
|
-
className: "snap-textarea-field",
|
|
1896
|
+
className: cn("snap-textarea-field", fieldClassName),
|
|
1459
1897
|
disabled,
|
|
1460
1898
|
"aria-invalid": invalid || void 0,
|
|
1461
1899
|
...props
|
|
1462
1900
|
})
|
|
1463
1901
|
});
|
|
1464
1902
|
}
|
|
1465
|
-
/** A numeric field with
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1903
|
+
/** A numeric field with touch steppers: `step-up`/`step-down` commit through
|
|
1904
|
+
* the normal `onChange` (a native input event on the field), clamped to
|
|
1905
|
+
* `min`/`max`. */
|
|
1906
|
+
function NumberInput({ min, max, step = 1, size = "md", invalid = false, fieldClassName, className, style, disabled, value, onChange, ...props }) {
|
|
1907
|
+
const fieldRef = useRef(null);
|
|
1908
|
+
const current = typeof value === "number" ? value : void 0;
|
|
1909
|
+
const stepBy = (delta) => {
|
|
1910
|
+
const field = fieldRef.current;
|
|
1911
|
+
if (field === null || disabled === true) return;
|
|
1912
|
+
const parsed = typeof value === "number" ? value : Number(field.value);
|
|
1913
|
+
let next = (Number.isFinite(parsed) ? parsed : min ?? 0) + delta * step;
|
|
1914
|
+
if (min !== void 0 && next < min) next = min;
|
|
1915
|
+
if (max !== void 0 && next > max) next = max;
|
|
1916
|
+
(Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set)?.call(field, String(next));
|
|
1917
|
+
field.dispatchEvent(new Event("input", { bubbles: true }));
|
|
1918
|
+
};
|
|
1919
|
+
return jsxs("div", {
|
|
1920
|
+
...part("number-input", "root"),
|
|
1921
|
+
className: cn("snap-input", "snap-number-input", className),
|
|
1922
|
+
style,
|
|
1923
|
+
"data-size": size,
|
|
1924
|
+
"data-invalid": invalid || void 0,
|
|
1925
|
+
"data-disabled": disabled === true || void 0,
|
|
1926
|
+
children: [jsx("input", {
|
|
1927
|
+
ref: fieldRef,
|
|
1928
|
+
...part("number-input", "field"),
|
|
1929
|
+
className: cn("snap-input-field", fieldClassName),
|
|
1930
|
+
type: "number",
|
|
1931
|
+
inputMode: "decimal",
|
|
1932
|
+
disabled,
|
|
1933
|
+
"aria-invalid": invalid || void 0,
|
|
1934
|
+
value,
|
|
1935
|
+
onChange,
|
|
1936
|
+
...min !== void 0 ? { min } : {},
|
|
1937
|
+
...max !== void 0 ? { max } : {},
|
|
1938
|
+
...step !== void 0 ? { step } : {},
|
|
1939
|
+
...props
|
|
1940
|
+
}), jsxs("span", {
|
|
1941
|
+
className: "snap-number-input-steps",
|
|
1942
|
+
children: [jsx("button", {
|
|
1943
|
+
...part("number-input", "step-up"),
|
|
1944
|
+
type: "button",
|
|
1945
|
+
tabIndex: -1,
|
|
1946
|
+
className: "snap-number-input-step",
|
|
1947
|
+
"aria-label": "增大",
|
|
1948
|
+
disabled: disabled === true || current !== void 0 && max !== void 0 && current >= max,
|
|
1949
|
+
onClick: () => stepBy(1),
|
|
1950
|
+
children: "+"
|
|
1951
|
+
}), jsx("button", {
|
|
1952
|
+
...part("number-input", "step-down"),
|
|
1953
|
+
type: "button",
|
|
1954
|
+
tabIndex: -1,
|
|
1955
|
+
className: "snap-number-input-step",
|
|
1956
|
+
"aria-label": "减小",
|
|
1957
|
+
disabled: disabled === true || current !== void 0 && min !== void 0 && current <= min,
|
|
1958
|
+
onClick: () => stepBy(-1),
|
|
1959
|
+
children: "-"
|
|
1960
|
+
})]
|
|
1961
|
+
})]
|
|
1475
1962
|
});
|
|
1476
1963
|
}
|
|
1477
1964
|
//#endregion
|
|
1478
1965
|
//#region lib/types/components/layout.js
|
|
1966
|
+
/**
|
|
1967
|
+
* Semantic layout primitives. Pages compose these instead of raw flex/grid
|
|
1968
|
+
* utility classes; the structural rules are inline (so layout survives
|
|
1969
|
+
* without a skin) while spacing/density values ride skin tokens.
|
|
1970
|
+
*
|
|
1971
|
+
* @module @snap-rail/ui/components/layout
|
|
1972
|
+
*/
|
|
1479
1973
|
/** A vertical flow. */
|
|
1480
1974
|
function Stack({ gap = "md", padding, align, className, style, children }) {
|
|
1481
1975
|
return jsx("div", {
|
|
@@ -1606,7 +2100,7 @@ function AppShell({ header, sidebar, footer, className, style, children }) {
|
|
|
1606
2100
|
});
|
|
1607
2101
|
}
|
|
1608
2102
|
/** A page body with its own header/actions anatomy. */
|
|
1609
|
-
function Page({ header, actions, title, description, className, style, children }) {
|
|
2103
|
+
function Page({ header, actions, title, titleExtra, description, className, style, children }) {
|
|
1610
2104
|
return jsxs("div", {
|
|
1611
2105
|
...part("page", "root"),
|
|
1612
2106
|
className: cn("snap-page", className),
|
|
@@ -1632,9 +2126,19 @@ function Page({ header, actions, title, description, className, style, children
|
|
|
1632
2126
|
justifyContent: "space-between",
|
|
1633
2127
|
gap: space("md")
|
|
1634
2128
|
},
|
|
1635
|
-
children: [
|
|
1636
|
-
|
|
1637
|
-
|
|
2129
|
+
children: [jsxs("div", {
|
|
2130
|
+
style: {
|
|
2131
|
+
display: "flex",
|
|
2132
|
+
alignItems: "center",
|
|
2133
|
+
gap: space("sm")
|
|
2134
|
+
},
|
|
2135
|
+
children: [title !== void 0 && jsx("div", {
|
|
2136
|
+
...part("page", "title"),
|
|
2137
|
+
children: title
|
|
2138
|
+
}), titleExtra !== void 0 && jsx("div", {
|
|
2139
|
+
...part("page", "title-extra"),
|
|
2140
|
+
children: titleExtra
|
|
2141
|
+
})]
|
|
1638
2142
|
}), actions !== void 0 && jsx("div", {
|
|
1639
2143
|
...part("page", "actions"),
|
|
1640
2144
|
children: actions
|
|
@@ -1690,8 +2194,8 @@ function Section({ title, description, actions, className, style, children }) {
|
|
|
1690
2194
|
})]
|
|
1691
2195
|
});
|
|
1692
2196
|
}
|
|
1693
|
-
/** A compact action bar. */
|
|
1694
|
-
function Toolbar({ start, end, className, style }) {
|
|
2197
|
+
/** A compact action bar; `children` renders between the start and end groups. */
|
|
2198
|
+
function Toolbar({ start, end, children, className, style }) {
|
|
1695
2199
|
return jsxs("div", {
|
|
1696
2200
|
...part("toolbar", "root"),
|
|
1697
2201
|
className: cn("snap-toolbar", className),
|
|
@@ -1702,47 +2206,149 @@ function Toolbar({ start, end, className, style }) {
|
|
|
1702
2206
|
gap: space("sm"),
|
|
1703
2207
|
...style
|
|
1704
2208
|
},
|
|
1705
|
-
children: [
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
2209
|
+
children: [
|
|
2210
|
+
jsx("div", {
|
|
2211
|
+
...part("toolbar", "start"),
|
|
2212
|
+
style: {
|
|
2213
|
+
display: "flex",
|
|
2214
|
+
alignItems: "center",
|
|
2215
|
+
gap: space("sm"),
|
|
2216
|
+
minWidth: 0
|
|
2217
|
+
},
|
|
2218
|
+
children: start
|
|
2219
|
+
}),
|
|
2220
|
+
children !== void 0 && jsx("div", {
|
|
2221
|
+
...part("toolbar", "center"),
|
|
2222
|
+
style: {
|
|
2223
|
+
display: "flex",
|
|
2224
|
+
alignItems: "center",
|
|
2225
|
+
gap: space("sm"),
|
|
2226
|
+
minWidth: 0
|
|
2227
|
+
},
|
|
2228
|
+
children
|
|
2229
|
+
}),
|
|
2230
|
+
jsx("div", {
|
|
2231
|
+
...part("toolbar", "end"),
|
|
2232
|
+
style: {
|
|
2233
|
+
display: "flex",
|
|
2234
|
+
alignItems: "center",
|
|
2235
|
+
gap: space("sm"),
|
|
2236
|
+
flexShrink: 0
|
|
2237
|
+
},
|
|
2238
|
+
children: end
|
|
2239
|
+
})
|
|
2240
|
+
]
|
|
1724
2241
|
});
|
|
1725
2242
|
}
|
|
1726
|
-
/** A
|
|
1727
|
-
|
|
1728
|
-
|
|
2243
|
+
/** A scroll container with themed, overlay-style scrollbars over the Radix
|
|
2244
|
+
* viewport. The anatomy stays `scroll-area.root/viewport` plus the
|
|
2245
|
+
* `scroll-area.scrollbar/thumb` parts the skin styles. */
|
|
2246
|
+
function ScrollArea({ direction = "vertical", scrollbarType = "hover", className, style, children }) {
|
|
2247
|
+
return jsxs(ScrollAreaPrimitive.Root, {
|
|
1729
2248
|
...part("scroll-area", "root"),
|
|
1730
2249
|
className: cn("snap-scroll-area", className),
|
|
2250
|
+
type: scrollbarType,
|
|
1731
2251
|
style: {
|
|
1732
|
-
overflowY: direction === "horizontal" ? "hidden" : "auto",
|
|
1733
|
-
overflowX: direction === "vertical" ? "hidden" : "auto",
|
|
1734
2252
|
minHeight: 0,
|
|
2253
|
+
...direction === "horizontal" ? { height: "100%" } : {},
|
|
1735
2254
|
...style
|
|
1736
2255
|
},
|
|
1737
|
-
children:
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
2256
|
+
children: [
|
|
2257
|
+
jsx(ScrollAreaPrimitive.Viewport, {
|
|
2258
|
+
...part("scroll-area", "viewport"),
|
|
2259
|
+
className: "snap-scroll-area-viewport",
|
|
2260
|
+
children
|
|
2261
|
+
}),
|
|
2262
|
+
direction !== "horizontal" && jsx(ScrollAreaPrimitive.Scrollbar, {
|
|
2263
|
+
...part("scroll-area", "scrollbar"),
|
|
2264
|
+
className: "snap-scroll-area-scrollbar",
|
|
2265
|
+
orientation: "vertical",
|
|
2266
|
+
children: jsx(ScrollAreaPrimitive.Thumb, {
|
|
2267
|
+
...part("scroll-area", "thumb"),
|
|
2268
|
+
className: "snap-scroll-area-thumb"
|
|
2269
|
+
})
|
|
2270
|
+
}),
|
|
2271
|
+
direction !== "vertical" && jsx(ScrollAreaPrimitive.Scrollbar, {
|
|
2272
|
+
...part("scroll-area", "scrollbar"),
|
|
2273
|
+
className: "snap-scroll-area-scrollbar",
|
|
2274
|
+
orientation: "horizontal",
|
|
2275
|
+
children: jsx(ScrollAreaPrimitive.Thumb, {
|
|
2276
|
+
...part("scroll-area", "thumb"),
|
|
2277
|
+
className: "snap-scroll-area-thumb"
|
|
2278
|
+
})
|
|
2279
|
+
})
|
|
2280
|
+
]
|
|
1741
2281
|
});
|
|
1742
2282
|
}
|
|
1743
|
-
/**
|
|
2283
|
+
/**
|
|
2284
|
+
* Wire an element as a drag-pan surface over its own scroll viewport. Touch
|
|
2285
|
+
* pointers keep native scrolling; mouse/stylus presses pan `scrollLeft`/
|
|
2286
|
+
* `scrollTop` directly once the pointer travels past `threshold`, so child
|
|
2287
|
+
* clicks survive a press-release. While panning the element carries
|
|
2288
|
+
* `data-dragging="true"`. Returns the disposer removing every listener.
|
|
2289
|
+
*/
|
|
2290
|
+
function attachDragPan(element, options = {}) {
|
|
2291
|
+
const direction = options.direction ?? "vertical";
|
|
2292
|
+
const threshold = options.threshold ?? 4;
|
|
2293
|
+
let anchor = null;
|
|
2294
|
+
let panned = false;
|
|
2295
|
+
const onPointerDown = (event) => {
|
|
2296
|
+
if (event.pointerType === "touch" || event.button !== 0) return;
|
|
2297
|
+
anchor = {
|
|
2298
|
+
x: event.clientX,
|
|
2299
|
+
y: event.clientY,
|
|
2300
|
+
left: element.scrollLeft,
|
|
2301
|
+
top: element.scrollTop
|
|
2302
|
+
};
|
|
2303
|
+
panned = false;
|
|
2304
|
+
};
|
|
2305
|
+
const onPointerMove = (event) => {
|
|
2306
|
+
if (anchor === null) return;
|
|
2307
|
+
const dx = event.clientX - anchor.x;
|
|
2308
|
+
const dy = event.clientY - anchor.y;
|
|
2309
|
+
if (!panned && Math.hypot(dx, dy) < threshold) return;
|
|
2310
|
+
panned = true;
|
|
2311
|
+
element.setAttribute("data-dragging", "true");
|
|
2312
|
+
if (direction !== "vertical") element.scrollLeft = anchor.left - dx;
|
|
2313
|
+
if (direction !== "horizontal") element.scrollTop = anchor.top - dy;
|
|
2314
|
+
};
|
|
2315
|
+
const endPan = () => {
|
|
2316
|
+
anchor = null;
|
|
2317
|
+
element.removeAttribute("data-dragging");
|
|
2318
|
+
};
|
|
2319
|
+
const onClickCapture = (event) => {
|
|
2320
|
+
if (!panned) return;
|
|
2321
|
+
panned = false;
|
|
2322
|
+
event.preventDefault();
|
|
2323
|
+
event.stopPropagation();
|
|
2324
|
+
};
|
|
2325
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
2326
|
+
element.addEventListener("pointermove", onPointerMove);
|
|
2327
|
+
element.addEventListener("pointerup", endPan);
|
|
2328
|
+
element.addEventListener("pointercancel", endPan);
|
|
2329
|
+
element.addEventListener("pointerleave", endPan);
|
|
2330
|
+
element.addEventListener("click", onClickCapture, true);
|
|
2331
|
+
return () => {
|
|
2332
|
+
element.removeEventListener("pointerdown", onPointerDown);
|
|
2333
|
+
element.removeEventListener("pointermove", onPointerMove);
|
|
2334
|
+
element.removeEventListener("pointerup", endPan);
|
|
2335
|
+
element.removeEventListener("pointercancel", endPan);
|
|
2336
|
+
element.removeEventListener("pointerleave", endPan);
|
|
2337
|
+
element.removeEventListener("click", onClickCapture, true);
|
|
2338
|
+
};
|
|
2339
|
+
}
|
|
2340
|
+
/** A scroll container any pointer can pan by dragging; touch keeps native
|
|
2341
|
+
* scrolling, mouse/stylus drags pan the viewport past a small travel
|
|
2342
|
+
* threshold, and child clicks survive a press-release. */
|
|
1744
2343
|
function DragScroll({ direction = "vertical", className, style, children }) {
|
|
2344
|
+
const rootRef = useRef(null);
|
|
2345
|
+
useEffect(() => {
|
|
2346
|
+
const root = rootRef.current;
|
|
2347
|
+
if (root === null) return;
|
|
2348
|
+
return attachDragPan(root, { direction });
|
|
2349
|
+
}, [direction]);
|
|
1745
2350
|
return jsx("div", {
|
|
2351
|
+
ref: rootRef,
|
|
1746
2352
|
...part("drag-scroll", "root"),
|
|
1747
2353
|
className: cn("snap-drag-scroll", className),
|
|
1748
2354
|
style: {
|
|
@@ -1758,12 +2364,258 @@ function DragScroll({ direction = "vertical", className, style, children }) {
|
|
|
1758
2364
|
});
|
|
1759
2365
|
}
|
|
1760
2366
|
//#endregion
|
|
2367
|
+
//#region lib/types/components/overlay.js
|
|
2368
|
+
/**
|
|
2369
|
+
* Overlay semantics over Radix: tooltips, popovers, dropdown menus, and
|
|
2370
|
+
* toasts. Behaviour/keyboard/focus handling stays here; skins target the
|
|
2371
|
+
* stable parts (`tooltip.*`, `popover.*`, `menu.*`, `toast.*`) and state
|
|
2372
|
+
* attributes. The imperative toast() helper pairs with the <Toaster/> the
|
|
2373
|
+
* runtime mounts in every surface root.
|
|
2374
|
+
*
|
|
2375
|
+
* @module @snap-rail/ui/components/overlay
|
|
2376
|
+
*/
|
|
2377
|
+
/** The tooltip root; wraps `TooltipTrigger`/`TooltipContent` and owns delay. */
|
|
2378
|
+
function Tooltip({ delayDuration, ...props }) {
|
|
2379
|
+
return jsx(TooltipPrimitive.Root, {
|
|
2380
|
+
...props,
|
|
2381
|
+
delayDuration: delayDuration ?? 300
|
|
2382
|
+
});
|
|
2383
|
+
}
|
|
2384
|
+
/** The tooltip provider; the runtime mounts one, pages only need it standalone. */
|
|
2385
|
+
function TooltipProvider(props) {
|
|
2386
|
+
return jsx(TooltipPrimitive.Provider, { ...props });
|
|
2387
|
+
}
|
|
2388
|
+
/** The tooltip trigger; wraps its child and anchors the bubble. */
|
|
2389
|
+
function TooltipTrigger(props) {
|
|
2390
|
+
return jsx(TooltipPrimitive.Trigger, {
|
|
2391
|
+
...part("tooltip", "trigger"),
|
|
2392
|
+
...props
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
/** The portalled tooltip bubble. */
|
|
2396
|
+
function TooltipContent({ side = "top", sideOffset = 6, className, children, ...props }) {
|
|
2397
|
+
return jsx(TooltipPrimitive.Portal, { children: jsx(TooltipPrimitive.Content, {
|
|
2398
|
+
...part("tooltip", "content"),
|
|
2399
|
+
className: cn("snap-tooltip", className),
|
|
2400
|
+
side,
|
|
2401
|
+
sideOffset,
|
|
2402
|
+
...props,
|
|
2403
|
+
children
|
|
2404
|
+
}) });
|
|
2405
|
+
}
|
|
2406
|
+
/** The popover root. */
|
|
2407
|
+
const Popover = PopoverPrimitive.Root;
|
|
2408
|
+
/** The popover trigger; wraps its child and toggles the panel. */
|
|
2409
|
+
function PopoverTrigger(props) {
|
|
2410
|
+
return jsx(PopoverPrimitive.Trigger, {
|
|
2411
|
+
...part("popover", "trigger"),
|
|
2412
|
+
...props
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
/** An element the panel positions against without toggling it. */
|
|
2416
|
+
const PopoverAnchor = PopoverPrimitive.Anchor;
|
|
2417
|
+
/** Closes the popover from inside the panel. */
|
|
2418
|
+
function PopoverClose(props) {
|
|
2419
|
+
return jsx(PopoverPrimitive.Close, { ...props });
|
|
2420
|
+
}
|
|
2421
|
+
/** The portalled popover panel. */
|
|
2422
|
+
function PopoverContent({ side = "bottom", align = "center", sideOffset = 6, className, children, ...props }) {
|
|
2423
|
+
return jsx(PopoverPrimitive.Portal, { children: jsx(PopoverPrimitive.Content, {
|
|
2424
|
+
...part("popover", "content"),
|
|
2425
|
+
className: cn("snap-popover", className),
|
|
2426
|
+
side,
|
|
2427
|
+
align,
|
|
2428
|
+
sideOffset,
|
|
2429
|
+
...props,
|
|
2430
|
+
children
|
|
2431
|
+
}) });
|
|
2432
|
+
}
|
|
2433
|
+
/** The dropdown menu root. */
|
|
2434
|
+
const Menu = DropdownMenuPrimitive.Root;
|
|
2435
|
+
/** The menu trigger; wraps its child and toggles the dropdown. */
|
|
2436
|
+
function MenuTrigger(props) {
|
|
2437
|
+
return jsx(DropdownMenuPrimitive.Trigger, {
|
|
2438
|
+
...part("menu", "trigger"),
|
|
2439
|
+
...props
|
|
2440
|
+
});
|
|
2441
|
+
}
|
|
2442
|
+
/** The portalled dropdown list. */
|
|
2443
|
+
function MenuContent({ side = "bottom", align = "start", sideOffset = 4, className, children, ...props }) {
|
|
2444
|
+
return jsx(DropdownMenuPrimitive.Portal, { children: jsx(DropdownMenuPrimitive.Content, {
|
|
2445
|
+
...part("menu", "content"),
|
|
2446
|
+
className: cn("snap-menu", className),
|
|
2447
|
+
side,
|
|
2448
|
+
align,
|
|
2449
|
+
sideOffset,
|
|
2450
|
+
...props,
|
|
2451
|
+
children
|
|
2452
|
+
}) });
|
|
2453
|
+
}
|
|
2454
|
+
/** One menu action. */
|
|
2455
|
+
function MenuItem({ className, children, ...props }) {
|
|
2456
|
+
return jsx(DropdownMenuPrimitive.Item, {
|
|
2457
|
+
...part("menu", "item"),
|
|
2458
|
+
className: cn("snap-menu-item", className),
|
|
2459
|
+
...props,
|
|
2460
|
+
children
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
/** A checkable menu action with an indicator slot. */
|
|
2464
|
+
function MenuCheckboxItem({ className, children, ...props }) {
|
|
2465
|
+
return jsxs(DropdownMenuPrimitive.CheckboxItem, {
|
|
2466
|
+
...part("menu", "checkbox-item"),
|
|
2467
|
+
className: cn("snap-menu-item", className),
|
|
2468
|
+
...props,
|
|
2469
|
+
children: [jsx(DropdownMenuPrimitive.ItemIndicator, {
|
|
2470
|
+
...part("menu", "item-indicator"),
|
|
2471
|
+
className: "snap-menu-indicator",
|
|
2472
|
+
children: "✓"
|
|
2473
|
+
}), children]
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2476
|
+
/** A non-interactive group heading. */
|
|
2477
|
+
function MenuLabel({ className, children, ...props }) {
|
|
2478
|
+
return jsx(DropdownMenuPrimitive.Label, {
|
|
2479
|
+
className: cn("snap-menu-label", className),
|
|
2480
|
+
...props,
|
|
2481
|
+
children
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2484
|
+
/** A group container for items. */
|
|
2485
|
+
function MenuGroup(props) {
|
|
2486
|
+
return jsx(DropdownMenuPrimitive.Group, { ...props });
|
|
2487
|
+
}
|
|
2488
|
+
/** A horizontal rule between menu sections. */
|
|
2489
|
+
function MenuSeparator({ className, ...props }) {
|
|
2490
|
+
return jsx(DropdownMenuPrimitive.Separator, {
|
|
2491
|
+
...part("menu", "separator"),
|
|
2492
|
+
className: cn("snap-menu-separator", className),
|
|
2493
|
+
...props
|
|
2494
|
+
});
|
|
2495
|
+
}
|
|
2496
|
+
let toastNextId = 1;
|
|
2497
|
+
let toastRecords = [];
|
|
2498
|
+
const toastListeners = /* @__PURE__ */ new Set();
|
|
2499
|
+
function toastEmit() {
|
|
2500
|
+
for (const listener of toastListeners) listener();
|
|
2501
|
+
}
|
|
2502
|
+
function toastDismiss(id) {
|
|
2503
|
+
toastRecords = toastRecords.filter((record) => record.id !== id);
|
|
2504
|
+
toastEmit();
|
|
2505
|
+
}
|
|
2506
|
+
/** Enqueue a toast on the runtime-mounted {@link Toaster}s. */
|
|
2507
|
+
function toast(entry) {
|
|
2508
|
+
const id = toastNextId++;
|
|
2509
|
+
toastRecords = [...toastRecords, {
|
|
2510
|
+
...entry,
|
|
2511
|
+
id
|
|
2512
|
+
}];
|
|
2513
|
+
toastEmit();
|
|
2514
|
+
return id;
|
|
2515
|
+
}
|
|
2516
|
+
/** Dismiss a queued toast by id. */
|
|
2517
|
+
function dismissToast(id) {
|
|
2518
|
+
toastDismiss(id);
|
|
2519
|
+
}
|
|
2520
|
+
/** The runtime-mounted viewport: renders the shared toast queue. Pages never
|
|
2521
|
+
* mount this themselves — the runtime provides one per surface root. */
|
|
2522
|
+
function Toaster(props) {
|
|
2523
|
+
const records = useSyncExternalStore((onStoreChange) => {
|
|
2524
|
+
toastListeners.add(onStoreChange);
|
|
2525
|
+
return () => toastListeners.delete(onStoreChange);
|
|
2526
|
+
}, () => toastRecords, () => toastRecords);
|
|
2527
|
+
return jsxs(ToastPrimitive.Provider, {
|
|
2528
|
+
...props,
|
|
2529
|
+
children: [records.map((record) => jsxs(ToastPrimitive.Root, {
|
|
2530
|
+
...part("toast", "root"),
|
|
2531
|
+
className: "snap-toast",
|
|
2532
|
+
"data-intent": record.intent ?? "neutral",
|
|
2533
|
+
duration: record.duration ?? 5e3,
|
|
2534
|
+
onOpenChange: (open) => {
|
|
2535
|
+
if (!open) toastDismiss(record.id);
|
|
2536
|
+
},
|
|
2537
|
+
children: [
|
|
2538
|
+
jsx(ToastTitle, { children: record.title }),
|
|
2539
|
+
record.description !== void 0 && jsx(ToastDescription, { children: record.description }),
|
|
2540
|
+
jsx(ToastClose, { "aria-label": "关闭" })
|
|
2541
|
+
]
|
|
2542
|
+
}, record.id)), jsx(ToastViewport, {})]
|
|
2543
|
+
});
|
|
2544
|
+
}
|
|
2545
|
+
/** The raw toast root for pages that manage their own open state. */
|
|
2546
|
+
const Toast = ToastPrimitive.Root;
|
|
2547
|
+
/** A toast title with its part tag. */
|
|
2548
|
+
function ToastTitle({ className, children, ...props }) {
|
|
2549
|
+
return jsx(ToastPrimitive.Title, {
|
|
2550
|
+
...part("toast", "title"),
|
|
2551
|
+
className: cn("snap-toast-title", className),
|
|
2552
|
+
...props,
|
|
2553
|
+
children
|
|
2554
|
+
});
|
|
2555
|
+
}
|
|
2556
|
+
/** A toast description with its part tag. */
|
|
2557
|
+
function ToastDescription({ className, children, ...props }) {
|
|
2558
|
+
return jsx(ToastPrimitive.Description, {
|
|
2559
|
+
...part("toast", "description"),
|
|
2560
|
+
className: cn("snap-toast-description", className),
|
|
2561
|
+
...props,
|
|
2562
|
+
children
|
|
2563
|
+
});
|
|
2564
|
+
}
|
|
2565
|
+
/** An interactive toast action (confirm/retry affordances). */
|
|
2566
|
+
function ToastAction({ className, children, ...props }) {
|
|
2567
|
+
return jsx(ToastPrimitive.Action, {
|
|
2568
|
+
...part("toast", "action"),
|
|
2569
|
+
className: cn("snap-toast-action", className),
|
|
2570
|
+
...props,
|
|
2571
|
+
children
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
/** A toast dismissal button. */
|
|
2575
|
+
function ToastClose({ className, children, ...props }) {
|
|
2576
|
+
return jsx(ToastPrimitive.Close, {
|
|
2577
|
+
...part("toast", "close"),
|
|
2578
|
+
className: cn("snap-toast-close", className),
|
|
2579
|
+
...props,
|
|
2580
|
+
children: children ?? jsx("span", {
|
|
2581
|
+
"aria-hidden": "true",
|
|
2582
|
+
children: "×"
|
|
2583
|
+
})
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
/** The toast viewport; only the runtime's {@link Toaster} mounts one. */
|
|
2587
|
+
function ToastViewport({ className, ...props }) {
|
|
2588
|
+
return jsx(ToastPrimitive.Viewport, {
|
|
2589
|
+
...part("toast", "viewport"),
|
|
2590
|
+
className: cn("snap-toast-viewport", className),
|
|
2591
|
+
...props
|
|
2592
|
+
});
|
|
2593
|
+
}
|
|
2594
|
+
//#endregion
|
|
1761
2595
|
//#region lib/types/components/schema-form.js
|
|
2596
|
+
/** The closed literal set a property may take: its `enum`, or — for a union of
|
|
2597
|
+
* scalar literals — the flattened `const` values of the `anyOf` branches, in
|
|
2598
|
+
* declaration order. `undefined` when the property is not a closed literal set
|
|
2599
|
+
* (open unions, non-scalar consts, absent both fields). */
|
|
2600
|
+
function literalValuesOf(property) {
|
|
2601
|
+
if (Array.isArray(property.enum)) return property.enum;
|
|
2602
|
+
const branches = property.anyOf;
|
|
2603
|
+
if (!Array.isArray(branches) || branches.length === 0) return void 0;
|
|
2604
|
+
const values = [];
|
|
2605
|
+
for (const branch of branches) {
|
|
2606
|
+
if (branch === null || typeof branch !== "object" || branch.anyOf !== void 0) return void 0;
|
|
2607
|
+
if (!("const" in branch)) return void 0;
|
|
2608
|
+
const value = branch.const;
|
|
2609
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return void 0;
|
|
2610
|
+
values.push(value);
|
|
2611
|
+
}
|
|
2612
|
+
return values;
|
|
2613
|
+
}
|
|
1762
2614
|
function asRecord(value) {
|
|
1763
2615
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1764
2616
|
}
|
|
1765
2617
|
/** Render a flat JSON-Schema object as semantic fields. */
|
|
1766
|
-
function SchemaForm({ schema, value, onChange, idPrefix = "schema" }) {
|
|
2618
|
+
function SchemaForm({ schema, value, onChange, idPrefix = "schema", columns }) {
|
|
1767
2619
|
const properties = schema.properties ?? {};
|
|
1768
2620
|
const required = new Set(schema.required ?? []);
|
|
1769
2621
|
const update = (key, next) => {
|
|
@@ -1772,84 +2624,94 @@ function SchemaForm({ schema, value, onChange, idPrefix = "schema" }) {
|
|
|
1772
2624
|
[key]: next
|
|
1773
2625
|
});
|
|
1774
2626
|
};
|
|
2627
|
+
const renderField = (key, property) => {
|
|
2628
|
+
const id = `${idPrefix}-${key}`;
|
|
2629
|
+
const current = value[key] ?? property.default;
|
|
2630
|
+
const label = property.title ?? key;
|
|
2631
|
+
const common = {
|
|
2632
|
+
label,
|
|
2633
|
+
htmlFor: id,
|
|
2634
|
+
...property.description !== void 0 ? { help: property.description } : {},
|
|
2635
|
+
...required.has(key) ? { required: true } : {}
|
|
2636
|
+
};
|
|
2637
|
+
const values = literalValuesOf(property);
|
|
2638
|
+
if (values !== void 0) {
|
|
2639
|
+
const options = values.map((item) => ({
|
|
2640
|
+
value: String(item),
|
|
2641
|
+
label: String(item)
|
|
2642
|
+
}));
|
|
2643
|
+
return jsx(Field, {
|
|
2644
|
+
...common,
|
|
2645
|
+
children: jsx(TouchSelect, {
|
|
2646
|
+
...current !== void 0 ? { value: String(current) } : {},
|
|
2647
|
+
options,
|
|
2648
|
+
onValueChange: (next) => {
|
|
2649
|
+
update(key, values.find((item) => String(item) === next) ?? next);
|
|
2650
|
+
},
|
|
2651
|
+
"aria-label": String(label)
|
|
2652
|
+
})
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2655
|
+
if (property.type === "boolean") return jsx(Field, {
|
|
2656
|
+
...common,
|
|
2657
|
+
children: jsx(Switch, {
|
|
2658
|
+
checked: current === true,
|
|
2659
|
+
onCheckedChange: (next) => update(key, next),
|
|
2660
|
+
"aria-label": String(label)
|
|
2661
|
+
})
|
|
2662
|
+
});
|
|
2663
|
+
if (property.type === "number" || property.type === "integer") return jsx(Field, {
|
|
2664
|
+
...common,
|
|
2665
|
+
children: jsx(NumberInput, {
|
|
2666
|
+
id,
|
|
2667
|
+
value: typeof current === "number" ? current : "",
|
|
2668
|
+
...property.minimum !== void 0 ? { min: property.minimum } : {},
|
|
2669
|
+
...property.maximum !== void 0 ? { max: property.maximum } : {},
|
|
2670
|
+
onChange: (event) => {
|
|
2671
|
+
const raw = event.target.value;
|
|
2672
|
+
update(key, raw === "" ? void 0 : Number(raw));
|
|
2673
|
+
}
|
|
2674
|
+
})
|
|
2675
|
+
});
|
|
2676
|
+
if (property.type === "object" || property.type === "array") return jsx(Field, {
|
|
2677
|
+
...common,
|
|
2678
|
+
help: property.description ?? "JSON 值",
|
|
2679
|
+
children: jsx(Textarea, {
|
|
2680
|
+
id,
|
|
2681
|
+
rows: 4,
|
|
2682
|
+
defaultValue: JSON.stringify(current ?? (property.type === "array" ? [] : {}), null, 2),
|
|
2683
|
+
onBlur: (event) => {
|
|
2684
|
+
try {
|
|
2685
|
+
update(key, JSON.parse(event.target.value));
|
|
2686
|
+
} catch {}
|
|
2687
|
+
}
|
|
2688
|
+
})
|
|
2689
|
+
});
|
|
2690
|
+
return jsx(Field, {
|
|
2691
|
+
...common,
|
|
2692
|
+
children: jsx(Input, {
|
|
2693
|
+
id,
|
|
2694
|
+
value: typeof current === "string" || typeof current === "number" ? String(current) : "",
|
|
2695
|
+
onChange: (event) => update(key, event.target.value)
|
|
2696
|
+
})
|
|
2697
|
+
});
|
|
2698
|
+
};
|
|
1775
2699
|
return jsxs("div", {
|
|
1776
|
-
|
|
2700
|
+
...part("schema-form", "root"),
|
|
2701
|
+
className: "snap-schema-form",
|
|
2702
|
+
style: columns !== void 0 ? {
|
|
2703
|
+
display: "grid",
|
|
2704
|
+
gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
|
|
2705
|
+
gap: "var(--snap-space-md)"
|
|
2706
|
+
} : {
|
|
1777
2707
|
display: "flex",
|
|
1778
2708
|
flexDirection: "column",
|
|
1779
2709
|
gap: "var(--snap-space-md)"
|
|
1780
2710
|
},
|
|
1781
|
-
children: [Object.entries(properties).map(([key, property]) => {
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
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", {
|
|
2711
|
+
children: [Object.entries(properties).map(([key, property]) => jsx("div", {
|
|
2712
|
+
...part("schema-form", "field"),
|
|
2713
|
+
children: renderField(key, property)
|
|
2714
|
+
}, key)), Object.keys(properties).length === 0 && jsx("span", {
|
|
1853
2715
|
style: { color: "var(--snap-color-muted)" },
|
|
1854
2716
|
children: "该驱动没有额外配置项。"
|
|
1855
2717
|
})]
|
|
@@ -1860,6 +2722,40 @@ function schemaNodeOf(value) {
|
|
|
1860
2722
|
return asRecord(value);
|
|
1861
2723
|
}
|
|
1862
2724
|
//#endregion
|
|
2725
|
+
//#region lib/types/components/slider.js
|
|
2726
|
+
/**
|
|
2727
|
+
* Coarse value adjustment for touch operation: a Radix slider with the
|
|
2728
|
+
* semantic anatomy (`slider.root/track/range/thumb`). Thumb size rides the
|
|
2729
|
+
* skin's control tokens so gloved operation keeps a real target.
|
|
2730
|
+
*
|
|
2731
|
+
* @module @snap-rail/ui/components/slider
|
|
2732
|
+
*/
|
|
2733
|
+
/** A ranged control with a large touch target and keyboard stepping. */
|
|
2734
|
+
function Slider({ label, className, children, ...props }) {
|
|
2735
|
+
return jsxs(SliderPrimitive.Root, {
|
|
2736
|
+
...part("slider", "root"),
|
|
2737
|
+
className: cn("snap-slider", className),
|
|
2738
|
+
"aria-label": label,
|
|
2739
|
+
...props,
|
|
2740
|
+
children: [
|
|
2741
|
+
jsx(SliderPrimitive.Track, {
|
|
2742
|
+
...part("slider", "track"),
|
|
2743
|
+
className: "snap-slider-track",
|
|
2744
|
+
children: jsx(SliderPrimitive.Range, {
|
|
2745
|
+
...part("slider", "range"),
|
|
2746
|
+
className: "snap-slider-range"
|
|
2747
|
+
})
|
|
2748
|
+
}),
|
|
2749
|
+
jsx(SliderPrimitive.Thumb, {
|
|
2750
|
+
...part("slider", "thumb"),
|
|
2751
|
+
className: "snap-slider-thumb",
|
|
2752
|
+
"aria-label": label
|
|
2753
|
+
}),
|
|
2754
|
+
children
|
|
2755
|
+
]
|
|
2756
|
+
});
|
|
2757
|
+
}
|
|
2758
|
+
//#endregion
|
|
1863
2759
|
//#region lib/types/components/surface.js
|
|
1864
2760
|
/** A content card. */
|
|
1865
2761
|
function Card({ className, children, ...props }) {
|
|
@@ -2376,7 +3272,6 @@ function FallbackShell(props) {
|
|
|
2376
3272
|
},
|
|
2377
3273
|
children: jsx(EmptyState, {
|
|
2378
3274
|
title: "尚未激活业务套件",
|
|
2379
|
-
description: "打开设置的「插件管理」页,安装并启用一个业务套件;驱动也在同一处安装。",
|
|
2380
3275
|
action: jsx(Button, {
|
|
2381
3276
|
intent: "primary",
|
|
2382
3277
|
onClick: () => props.ctx.settings.open("plugins"),
|
|
@@ -2467,24 +3362,21 @@ async function writeSetting(link, key, value) {
|
|
|
2467
3362
|
/** The appearance/display page. */
|
|
2468
3363
|
function AppearancePage() {
|
|
2469
3364
|
const { link } = useClient();
|
|
2470
|
-
const
|
|
3365
|
+
const skins = useSkins();
|
|
3366
|
+
const activeId = useSkinId();
|
|
3367
|
+
const [packages, setPackages] = useState([]);
|
|
2471
3368
|
const [windowPreset, setWindowPreset] = useState(void 0);
|
|
2472
3369
|
const [ballSize, setBallSize] = useState(128);
|
|
2473
3370
|
const [ballEnabled, setBallEnabled] = useState(true);
|
|
2474
|
-
const [ballDockable, setBallDockable] = useState(true);
|
|
2475
3371
|
const [ballCollapse, setBallCollapse] = useState(true);
|
|
2476
|
-
const [skins, setSkins] = useState([]);
|
|
2477
3372
|
const [error, setError] = useState(void 0);
|
|
2478
3373
|
const [busy, setBusy] = useState(false);
|
|
2479
3374
|
useEffect(() => {
|
|
2480
3375
|
Promise.all([
|
|
2481
|
-
readSetting(link, THEME_KEY),
|
|
2482
3376
|
readSetting(link, WINDOW_KEY),
|
|
2483
3377
|
readSetting(link, BALL_KEY),
|
|
2484
3378
|
link.call("plugins.list", {})
|
|
2485
|
-
]).then(([
|
|
2486
|
-
const themeMode = theme?.mode;
|
|
2487
|
-
if (themeMode === "system" || themeMode === "light" || themeMode === "dark") setMode(themeMode);
|
|
3379
|
+
]).then(([windowRow, ballRow, plugins]) => {
|
|
2488
3380
|
const windowProfile = windowRow;
|
|
2489
3381
|
if (windowProfile !== null && windowProfile !== void 0 && typeof windowProfile.width === "number" && typeof windowProfile.height === "number") {
|
|
2490
3382
|
const preset = WINDOW_PRESETS.find((item) => item.width === windowProfile.width && item.height === windowProfile.height);
|
|
@@ -2493,9 +3385,8 @@ function AppearancePage() {
|
|
|
2493
3385
|
const ballProfile = ballRow;
|
|
2494
3386
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.size === "number") setBallSize(ballProfile.size);
|
|
2495
3387
|
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
3388
|
if (ballProfile !== null && ballProfile !== void 0 && typeof ballProfile.collapse === "boolean") setBallCollapse(ballProfile.collapse);
|
|
2498
|
-
if (plugins.ok)
|
|
3389
|
+
if (plugins.ok) setPackages(plugins.value.plugins.filter((plugin) => plugin.kind === "skin" && plugin.source !== "builtin").map((plugin) => ({
|
|
2499
3390
|
name: plugin.packageName,
|
|
2500
3391
|
title: plugin.title ?? plugin.packageName,
|
|
2501
3392
|
enabled: plugin.enabled
|
|
@@ -2503,19 +3394,7 @@ function AppearancePage() {
|
|
|
2503
3394
|
}).catch((cause) => {
|
|
2504
3395
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
2505
3396
|
});
|
|
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
3397
|
}, [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
3398
|
const saveWindow = (width, height, label) => {
|
|
2520
3399
|
setWindowPreset(label);
|
|
2521
3400
|
writeSetting(link, WINDOW_KEY, {
|
|
@@ -2537,31 +3416,45 @@ function AppearancePage() {
|
|
|
2537
3416
|
const next = {
|
|
2538
3417
|
size: patch.size ?? ballSize,
|
|
2539
3418
|
enabled: patch.enabled ?? ballEnabled,
|
|
2540
|
-
dockable: patch.dockable ?? ballDockable,
|
|
2541
3419
|
collapse: patch.collapse ?? ballCollapse
|
|
2542
3420
|
};
|
|
2543
3421
|
if (patch.size !== void 0) setBallSize(patch.size);
|
|
2544
3422
|
if (patch.enabled !== void 0) setBallEnabled(patch.enabled);
|
|
2545
|
-
if (patch.dockable !== void 0) setBallDockable(patch.dockable);
|
|
2546
3423
|
if (patch.collapse !== void 0) setBallCollapse(patch.collapse);
|
|
2547
3424
|
writeSetting(link, BALL_KEY, next).catch((cause) => {
|
|
2548
3425
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
2549
3426
|
});
|
|
2550
3427
|
};
|
|
2551
|
-
const
|
|
3428
|
+
const tabs = [...skins.list().map((row) => ({
|
|
3429
|
+
id: row.id,
|
|
3430
|
+
title: row.title
|
|
3431
|
+
})), ...packages.filter((pkg) => !pkg.enabled).map((pkg) => ({
|
|
3432
|
+
id: pkg.name,
|
|
3433
|
+
title: pkg.title,
|
|
3434
|
+
enable: pkg.name
|
|
3435
|
+
}))];
|
|
3436
|
+
const selectTheme = (tab) => {
|
|
3437
|
+
if (busy) return;
|
|
3438
|
+
if (tab.enable === void 0) {
|
|
3439
|
+
writeSetting(link, THEME_KEY, { id: tab.id }).catch((cause) => {
|
|
3440
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
3441
|
+
});
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
2552
3444
|
setBusy(true);
|
|
2553
3445
|
link.call("plugins.set-enabled", {
|
|
2554
|
-
name:
|
|
2555
|
-
enabled:
|
|
3446
|
+
name: tab.enable,
|
|
3447
|
+
enabled: true
|
|
2556
3448
|
}).then((result) => {
|
|
2557
3449
|
if (!result.ok) {
|
|
2558
3450
|
setError(rpcErrorText(result.error));
|
|
2559
3451
|
return;
|
|
2560
3452
|
}
|
|
2561
|
-
|
|
2562
|
-
...
|
|
2563
|
-
enabled:
|
|
2564
|
-
} :
|
|
3453
|
+
setPackages((current) => current.map((pkg) => pkg.name === tab.enable ? {
|
|
3454
|
+
...pkg,
|
|
3455
|
+
enabled: true
|
|
3456
|
+
} : pkg));
|
|
3457
|
+
return writeSetting(link, THEME_KEY, { id: tab.id });
|
|
2565
3458
|
}).catch((cause) => {
|
|
2566
3459
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
2567
3460
|
}).finally(() => {
|
|
@@ -2570,83 +3463,34 @@ function AppearancePage() {
|
|
|
2570
3463
|
};
|
|
2571
3464
|
return jsx(Page, {
|
|
2572
3465
|
title: "外观与显示",
|
|
2573
|
-
description: "
|
|
3466
|
+
description: "主题、主窗口尺寸和悬浮球外观。",
|
|
2574
3467
|
children: jsxs(Stack, {
|
|
2575
3468
|
gap: "lg",
|
|
2576
3469
|
children: [
|
|
2577
|
-
error !== void 0 && jsx(
|
|
2578
|
-
|
|
2579
|
-
style: { color: "var(--snap-color-danger)" },
|
|
3470
|
+
error !== void 0 && jsx(Alert, {
|
|
3471
|
+
intent: "danger",
|
|
2580
3472
|
children: error
|
|
2581
3473
|
}),
|
|
2582
3474
|
jsx(Section, {
|
|
2583
|
-
title: "
|
|
3475
|
+
title: "主题",
|
|
2584
3476
|
children: jsx(Tabs, {
|
|
2585
|
-
value:
|
|
2586
|
-
onValueChange: (value) =>
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
}),
|
|
2598
|
-
jsx(TabsTrigger, {
|
|
2599
|
-
value: "dark",
|
|
2600
|
-
children: "黑夜"
|
|
2601
|
-
})
|
|
2602
|
-
]
|
|
3477
|
+
value: activeId,
|
|
3478
|
+
onValueChange: (value) => {
|
|
3479
|
+
const tab = tabs.find((item) => item.id === value);
|
|
3480
|
+
if (tab !== void 0) selectTheme(tab);
|
|
3481
|
+
},
|
|
3482
|
+
children: jsx(TabsList, {
|
|
3483
|
+
"aria-label": "主题",
|
|
3484
|
+
children: tabs.map((tab) => jsx(TabsTrigger, {
|
|
3485
|
+
value: tab.id,
|
|
3486
|
+
disabled: busy,
|
|
3487
|
+
children: tab.title
|
|
3488
|
+
}, tab.id))
|
|
2603
3489
|
})
|
|
2604
3490
|
})
|
|
2605
3491
|
}),
|
|
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
3492
|
jsx(Section, {
|
|
2648
3493
|
title: "主窗口",
|
|
2649
|
-
description: "布局/套件会声明推荐尺寸;这里的选择会覆盖布局推荐。",
|
|
2650
3494
|
children: jsxs(Stack, {
|
|
2651
3495
|
gap: "sm",
|
|
2652
3496
|
children: [jsxs(Row, {
|
|
@@ -2675,7 +3519,7 @@ function AppearancePage() {
|
|
|
2675
3519
|
}),
|
|
2676
3520
|
jsx(Section, {
|
|
2677
3521
|
title: "悬浮球",
|
|
2678
|
-
description: "
|
|
3522
|
+
description: "球面尺寸与停泊行为。",
|
|
2679
3523
|
children: jsxs(Stack, {
|
|
2680
3524
|
gap: "md",
|
|
2681
3525
|
children: [jsx(Row, {
|
|
@@ -2693,23 +3537,15 @@ function AppearancePage() {
|
|
|
2693
3537
|
gap: "lg",
|
|
2694
3538
|
wrap: true,
|
|
2695
3539
|
align: "center",
|
|
2696
|
-
children: [
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
onCheckedChange: (dockable) => saveBall({ dockable })
|
|
2706
|
-
}),
|
|
2707
|
-
jsx(Switch, {
|
|
2708
|
-
label: "贴边后收起",
|
|
2709
|
-
checked: ballCollapse,
|
|
2710
|
-
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
2711
|
-
})
|
|
2712
|
-
]
|
|
3540
|
+
children: [jsx(Switch, {
|
|
3541
|
+
label: "启用悬浮球",
|
|
3542
|
+
checked: ballEnabled,
|
|
3543
|
+
onCheckedChange: (enabled) => saveBall({ enabled })
|
|
3544
|
+
}), jsx(Switch, {
|
|
3545
|
+
label: "允许贴边收起",
|
|
3546
|
+
checked: ballCollapse,
|
|
3547
|
+
onCheckedChange: (collapse) => saveBall({ collapse })
|
|
3548
|
+
})]
|
|
2713
3549
|
})]
|
|
2714
3550
|
})
|
|
2715
3551
|
})
|
|
@@ -2718,7 +3554,157 @@ function AppearancePage() {
|
|
|
2718
3554
|
});
|
|
2719
3555
|
}
|
|
2720
3556
|
//#endregion
|
|
3557
|
+
//#region lib/types/settings-pages/plugin-feed.js
|
|
3558
|
+
/** The feed-source editor dialog; the open state lives with the opener. */
|
|
3559
|
+
function PluginFeedDialog(props) {
|
|
3560
|
+
const { open } = props;
|
|
3561
|
+
const link = props.ctx.client.link;
|
|
3562
|
+
const [urls, setUrls] = useState([]);
|
|
3563
|
+
const [draft, setDraft] = useState("");
|
|
3564
|
+
const [error, setError] = useState(void 0);
|
|
3565
|
+
useEffect(() => {
|
|
3566
|
+
if (!open) return;
|
|
3567
|
+
link.call("settings.get", { key: PLUGINS_FEED_URLS_KEY }).then((result) => {
|
|
3568
|
+
if (result.ok && Array.isArray(result.value.value)) setUrls(result.value.value.filter((entry) => typeof entry === "string"));
|
|
3569
|
+
}).catch(() => void 0);
|
|
3570
|
+
}, [open, link]);
|
|
3571
|
+
const save = () => {
|
|
3572
|
+
for (const url of urls) try {
|
|
3573
|
+
const parsed = new URL(url);
|
|
3574
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
3575
|
+
} catch {
|
|
3576
|
+
setError("插件源地址需要以 http(s) 开头");
|
|
3577
|
+
return;
|
|
3578
|
+
}
|
|
3579
|
+
setError(void 0);
|
|
3580
|
+
link.call("settings.set", {
|
|
3581
|
+
key: PLUGINS_FEED_URLS_KEY,
|
|
3582
|
+
value: urls
|
|
3583
|
+
}).then((result) => {
|
|
3584
|
+
if (!result.ok) {
|
|
3585
|
+
setError(rpcErrorText(result.error));
|
|
3586
|
+
return;
|
|
3587
|
+
}
|
|
3588
|
+
props.onOpenChange(false);
|
|
3589
|
+
}).catch((cause) => setError(String(cause)));
|
|
3590
|
+
};
|
|
3591
|
+
const append = () => {
|
|
3592
|
+
const value = draft.trim();
|
|
3593
|
+
if (value === "") return;
|
|
3594
|
+
try {
|
|
3595
|
+
const parsed = new URL(value);
|
|
3596
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error("protocol");
|
|
3597
|
+
} catch {
|
|
3598
|
+
setError("请填写 http(s) 开头的插件源地址");
|
|
3599
|
+
return;
|
|
3600
|
+
}
|
|
3601
|
+
setError(void 0);
|
|
3602
|
+
setDraft("");
|
|
3603
|
+
setUrls((current) => current.includes(value) ? current : [...current, value]);
|
|
3604
|
+
};
|
|
3605
|
+
return jsx(Dialog, {
|
|
3606
|
+
open,
|
|
3607
|
+
onOpenChange: props.onOpenChange,
|
|
3608
|
+
children: jsxs(DialogContent, {
|
|
3609
|
+
presentation: "modal",
|
|
3610
|
+
"aria-describedby": void 0,
|
|
3611
|
+
children: [
|
|
3612
|
+
jsx(DialogHeader, { children: jsx(DialogTitle, { children: "插件源" }) }),
|
|
3613
|
+
jsx(DialogBody, { children: jsxs(Stack, {
|
|
3614
|
+
gap: "sm",
|
|
3615
|
+
children: [
|
|
3616
|
+
urls.length === 0 && jsx("div", {
|
|
3617
|
+
style: {
|
|
3618
|
+
fontSize: "var(--snap-text-xs)",
|
|
3619
|
+
color: "var(--snap-color-muted)"
|
|
3620
|
+
},
|
|
3621
|
+
children: "尚未添加自定义源(当前使用出厂默认源)。"
|
|
3622
|
+
}),
|
|
3623
|
+
urls.map((url, index) => jsxs("div", {
|
|
3624
|
+
style: {
|
|
3625
|
+
display: "flex",
|
|
3626
|
+
gap: "var(--snap-space-sm)",
|
|
3627
|
+
alignItems: "center"
|
|
3628
|
+
},
|
|
3629
|
+
children: [jsx("span", {
|
|
3630
|
+
style: {
|
|
3631
|
+
flex: 1,
|
|
3632
|
+
minWidth: 0,
|
|
3633
|
+
overflow: "hidden",
|
|
3634
|
+
textOverflow: "ellipsis",
|
|
3635
|
+
whiteSpace: "nowrap",
|
|
3636
|
+
fontSize: "var(--snap-text-xs)"
|
|
3637
|
+
},
|
|
3638
|
+
children: url
|
|
3639
|
+
}), jsx(Button, {
|
|
3640
|
+
intent: "neutral",
|
|
3641
|
+
emphasis: "ghost",
|
|
3642
|
+
size: "sm",
|
|
3643
|
+
"aria-label": `移除 ${url}`,
|
|
3644
|
+
onClick: () => setUrls((current) => current.filter((_, at) => at !== index)),
|
|
3645
|
+
children: "✕"
|
|
3646
|
+
})]
|
|
3647
|
+
}, url)),
|
|
3648
|
+
jsxs("div", {
|
|
3649
|
+
style: {
|
|
3650
|
+
display: "flex",
|
|
3651
|
+
gap: "var(--snap-space-sm)",
|
|
3652
|
+
width: "100%"
|
|
3653
|
+
},
|
|
3654
|
+
children: [jsx(Input, {
|
|
3655
|
+
value: draft,
|
|
3656
|
+
placeholder: "https://…",
|
|
3657
|
+
style: {
|
|
3658
|
+
flex: 1,
|
|
3659
|
+
minWidth: 0
|
|
3660
|
+
},
|
|
3661
|
+
onChange: (event) => setDraft(event.target.value),
|
|
3662
|
+
onKeyDown: (event) => {
|
|
3663
|
+
if (event.key === "Enter") append();
|
|
3664
|
+
}
|
|
3665
|
+
}), jsx(Button, {
|
|
3666
|
+
intent: "neutral",
|
|
3667
|
+
emphasis: "outline",
|
|
3668
|
+
onClick: append,
|
|
3669
|
+
children: "添加源"
|
|
3670
|
+
})]
|
|
3671
|
+
}),
|
|
3672
|
+
error !== void 0 && jsx("div", {
|
|
3673
|
+
role: "alert",
|
|
3674
|
+
style: {
|
|
3675
|
+
color: "var(--snap-color-danger)",
|
|
3676
|
+
fontSize: "var(--snap-text-sm)"
|
|
3677
|
+
},
|
|
3678
|
+
children: error
|
|
3679
|
+
})
|
|
3680
|
+
]
|
|
3681
|
+
}) }),
|
|
3682
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
3683
|
+
intent: "neutral",
|
|
3684
|
+
emphasis: "outline",
|
|
3685
|
+
onClick: () => props.onOpenChange(false),
|
|
3686
|
+
children: "取消"
|
|
3687
|
+
}), jsx(Button, {
|
|
3688
|
+
intent: "primary",
|
|
3689
|
+
"data-plugins-feed-save": true,
|
|
3690
|
+
onClick: save,
|
|
3691
|
+
children: "保存"
|
|
3692
|
+
})] })
|
|
3693
|
+
]
|
|
3694
|
+
})
|
|
3695
|
+
});
|
|
3696
|
+
}
|
|
3697
|
+
//#endregion
|
|
2721
3698
|
//#region lib/types/settings-pages/plugins.js
|
|
3699
|
+
/** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
|
|
3700
|
+
* Electron or in tests. Inlined rather than imported from the app-internal
|
|
3701
|
+
* kernel package: it never ships in the installer, and the packaged-app gate
|
|
3702
|
+
* refuses any shipped `@snap-rail/ui` lib that requires it. */
|
|
3703
|
+
function droppedZipPath(file) {
|
|
3704
|
+
const zipPathOf = globalThis.snapRail?.zipPathOf;
|
|
3705
|
+
if (typeof zipPathOf !== "function") return null;
|
|
3706
|
+
return zipPathOf(file);
|
|
3707
|
+
}
|
|
2722
3708
|
/** Human labels for the package kinds. */
|
|
2723
3709
|
const KIND_LABELS = {
|
|
2724
3710
|
skin: "界面风格",
|
|
@@ -2731,6 +3717,22 @@ const PROFILE_LABELS = {
|
|
|
2731
3717
|
integrated: "图表桥接",
|
|
2732
3718
|
custom: "自定义界面"
|
|
2733
3719
|
};
|
|
3720
|
+
/** Search rows shown before the tail is folded into a counter. */
|
|
3721
|
+
const SEARCH_ROW_CAP = 20;
|
|
3722
|
+
/** The plus glyph for the page's install entry. */
|
|
3723
|
+
function PlusIcon() {
|
|
3724
|
+
return jsx("svg", {
|
|
3725
|
+
viewBox: "0 0 24 24",
|
|
3726
|
+
width: "18",
|
|
3727
|
+
height: "18",
|
|
3728
|
+
fill: "none",
|
|
3729
|
+
stroke: "currentColor",
|
|
3730
|
+
strokeWidth: "2.4",
|
|
3731
|
+
strokeLinecap: "round",
|
|
3732
|
+
"aria-hidden": "true",
|
|
3733
|
+
children: jsx("path", { d: "M12 5v14M5 12h14" })
|
|
3734
|
+
});
|
|
3735
|
+
}
|
|
2734
3736
|
/** Collapse entry rows into package rows (one master switch per package). */
|
|
2735
3737
|
function packageRows(plugins) {
|
|
2736
3738
|
const byPackage = /* @__PURE__ */ new Map();
|
|
@@ -2756,15 +3758,44 @@ function packageRows(plugins) {
|
|
|
2756
3758
|
}
|
|
2757
3759
|
return [...byPackage.values()].sort((a, b) => a.category.localeCompare(b.category) || a.title.localeCompare(b.title));
|
|
2758
3760
|
}
|
|
3761
|
+
/** The preview's signature line (one row in the confirm card). */
|
|
3762
|
+
function signatureText(signature, viaUrl) {
|
|
3763
|
+
if (signature.state === "verified") return {
|
|
3764
|
+
text: `✓ 已验证 · ${signature.publisher ?? signature.keyId}`,
|
|
3765
|
+
warning: false
|
|
3766
|
+
};
|
|
3767
|
+
const detail = signature.keyId !== void 0 ? `⚠ 未验证 · keyId ${signature.keyId}(未登记)` : "⚠ 未签名";
|
|
3768
|
+
return {
|
|
3769
|
+
text: viaUrl ? `${detail} · 直链无完整性校验` : detail,
|
|
3770
|
+
warning: true
|
|
3771
|
+
};
|
|
3772
|
+
}
|
|
3773
|
+
/** Does the input name an http(s) address? */
|
|
3774
|
+
const isHttpUrl = (text) => /^https?:\/\//i.test(text);
|
|
3775
|
+
/** Does the input look like a filesystem path (drive letter, UNC, posix
|
|
3776
|
+
* root, or a .zip name with a separator in it)? */
|
|
3777
|
+
const looksLikePath = (text) => /^[a-zA-Z]:[\\/]/.test(text) || text.startsWith("\\\\") || text.startsWith("/") || /\.zip$/i.test(text) && /[/\\]/.test(text);
|
|
2759
3778
|
/** The plugin management page. */
|
|
2760
3779
|
function PluginsPage({ ctx }) {
|
|
2761
3780
|
const [rows, setRows] = useState([]);
|
|
2762
3781
|
const [error, setError] = useState(void 0);
|
|
2763
3782
|
const [busy, setBusy] = useState(void 0);
|
|
2764
3783
|
const [touched, setTouched] = useState(/* @__PURE__ */ new Set());
|
|
3784
|
+
const [restartNeeded, setRestartNeeded] = useState(false);
|
|
3785
|
+
const [installOpen, setInstallOpen] = useState(false);
|
|
3786
|
+
const [phase, setPhase] = useState({ kind: "idle" });
|
|
3787
|
+
const [message, setMessage] = useState(void 0);
|
|
3788
|
+
const [updates, setUpdates] = useState(/* @__PURE__ */ new Map());
|
|
3789
|
+
const [updatingName, setUpdatingName] = useState(void 0);
|
|
3790
|
+
const [keyChange, setKeyChange] = useState(void 0);
|
|
3791
|
+
const [query, setQuery] = useState("");
|
|
3792
|
+
const [searchResults, setSearchResults] = useState(void 0);
|
|
3793
|
+
const [searching, setSearching] = useState(false);
|
|
3794
|
+
const [dragging, setDragging] = useState(false);
|
|
3795
|
+
const link = ctx.client.link;
|
|
2765
3796
|
const load = () => {
|
|
2766
3797
|
setError(void 0);
|
|
2767
|
-
|
|
3798
|
+
link.call("plugins.list", {}).then((result) => {
|
|
2768
3799
|
if (!result.ok) {
|
|
2769
3800
|
setError(rpcErrorText(result.error));
|
|
2770
3801
|
return;
|
|
@@ -2773,11 +3804,30 @@ function PluginsPage({ ctx }) {
|
|
|
2773
3804
|
}).catch((cause) => {
|
|
2774
3805
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
2775
3806
|
});
|
|
3807
|
+
link.call("plugins.updates-check", {}).then((result) => {
|
|
3808
|
+
if (result.ok) setUpdates(new Map(result.value.updates.map((update) => [update.name, update])));
|
|
3809
|
+
}).catch(() => void 0);
|
|
3810
|
+
};
|
|
3811
|
+
useEffect(() => {
|
|
3812
|
+
load();
|
|
3813
|
+
}, [link]);
|
|
3814
|
+
const openInstall = () => {
|
|
3815
|
+
setQuery("");
|
|
3816
|
+
setSearchResults(void 0);
|
|
3817
|
+
setMessage(void 0);
|
|
3818
|
+
setDragging(false);
|
|
3819
|
+
setInstallOpen(true);
|
|
3820
|
+
};
|
|
3821
|
+
const closeInstall = () => {
|
|
3822
|
+
setInstallOpen(false);
|
|
3823
|
+
setQuery("");
|
|
3824
|
+
setSearchResults(void 0);
|
|
3825
|
+
setMessage(void 0);
|
|
3826
|
+
setDragging(false);
|
|
2776
3827
|
};
|
|
2777
|
-
useEffect(load, []);
|
|
2778
3828
|
const toggle = (row, enabled) => {
|
|
2779
3829
|
setBusy(row.packageName);
|
|
2780
|
-
|
|
3830
|
+
link.call("plugins.set-enabled", {
|
|
2781
3831
|
name: row.packageName,
|
|
2782
3832
|
enabled
|
|
2783
3833
|
}).then((result) => {
|
|
@@ -2799,12 +3849,13 @@ function PluginsPage({ ctx }) {
|
|
|
2799
3849
|
const uninstall = (row) => {
|
|
2800
3850
|
if (!window.confirm(`卸载 ${row.title}?该包的数据也会一起删除。`)) return;
|
|
2801
3851
|
setBusy(row.packageName);
|
|
2802
|
-
|
|
3852
|
+
link.call("plugins.uninstall", { name: row.packageName }).then((result) => {
|
|
2803
3853
|
if (!result.ok) {
|
|
2804
3854
|
setError(rpcErrorText(result.error));
|
|
2805
3855
|
return;
|
|
2806
3856
|
}
|
|
2807
3857
|
setTouched((current) => new Set(current).add(row.packageName));
|
|
3858
|
+
setRestartNeeded(true);
|
|
2808
3859
|
load();
|
|
2809
3860
|
}).catch((cause) => {
|
|
2810
3861
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
@@ -2812,100 +3863,689 @@ function PluginsPage({ ctx }) {
|
|
|
2812
3863
|
setBusy(void 0);
|
|
2813
3864
|
});
|
|
2814
3865
|
};
|
|
2815
|
-
const
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
3866
|
+
const inspectPath = (zipPath) => {
|
|
3867
|
+
setMessage(void 0);
|
|
3868
|
+
link.call("plugins.inspect", { zipPath }).then((result) => {
|
|
3869
|
+
if (!result.ok) {
|
|
3870
|
+
setPhase({
|
|
3871
|
+
kind: "error",
|
|
3872
|
+
message: `读取插件包失败:${rpcErrorText(result.error)}`
|
|
3873
|
+
});
|
|
3874
|
+
return;
|
|
3875
|
+
}
|
|
3876
|
+
setPhase({
|
|
3877
|
+
kind: "confirm",
|
|
3878
|
+
zipPath,
|
|
3879
|
+
archive: result.value.archive,
|
|
3880
|
+
viaUrl: false,
|
|
3881
|
+
risk: false
|
|
3882
|
+
});
|
|
3883
|
+
}).catch((cause) => setPhase({
|
|
3884
|
+
kind: "error",
|
|
3885
|
+
message: String(cause)
|
|
3886
|
+
}));
|
|
3887
|
+
};
|
|
3888
|
+
const inspectFromUrl = (url) => {
|
|
3889
|
+
setMessage(void 0);
|
|
3890
|
+
link.call("plugins.inspect-from-url", { url }).then((result) => {
|
|
3891
|
+
if (!result.ok) {
|
|
3892
|
+
setPhase({
|
|
3893
|
+
kind: "error",
|
|
3894
|
+
message: `下载或读取插件包失败:${rpcErrorText(result.error)}`
|
|
3895
|
+
});
|
|
3896
|
+
return;
|
|
3897
|
+
}
|
|
3898
|
+
setPhase({
|
|
3899
|
+
kind: "confirm",
|
|
3900
|
+
zipPath: result.value.zipPath,
|
|
3901
|
+
archive: result.value.archive,
|
|
3902
|
+
viaUrl: true,
|
|
3903
|
+
risk: false
|
|
3904
|
+
});
|
|
3905
|
+
}).catch((cause) => setPhase({
|
|
3906
|
+
kind: "error",
|
|
3907
|
+
message: String(cause)
|
|
3908
|
+
}));
|
|
3909
|
+
};
|
|
3910
|
+
const runInstall = (zipPath, archive) => {
|
|
3911
|
+
setPhase({ kind: "installing" });
|
|
3912
|
+
(archive.kind === "combo" ? link.call("plugins.install-combo", { zipPath }) : link.call("plugins.install", { zipPath })).then((result) => {
|
|
3913
|
+
if (!result.ok) {
|
|
3914
|
+
setPhase({
|
|
3915
|
+
kind: "error",
|
|
3916
|
+
message: `安装失败:${rpcErrorText(result.error)}`
|
|
3917
|
+
});
|
|
3918
|
+
return;
|
|
3919
|
+
}
|
|
3920
|
+
setPhase({ kind: "idle" });
|
|
3921
|
+
closeInstall();
|
|
3922
|
+
setRestartNeeded(true);
|
|
3923
|
+
load();
|
|
3924
|
+
}).catch((cause) => setPhase({
|
|
3925
|
+
kind: "error",
|
|
3926
|
+
message: String(cause)
|
|
3927
|
+
}));
|
|
3928
|
+
};
|
|
3929
|
+
/** The update pill's click: a plain update installs directly; a key
|
|
3930
|
+
* change confirmation intercepts first. */
|
|
3931
|
+
const requestUpdate = (update) => {
|
|
3932
|
+
if (update.keyChanged === true) {
|
|
3933
|
+
setKeyChange(update);
|
|
3934
|
+
return;
|
|
3935
|
+
}
|
|
3936
|
+
updateNow(update.name);
|
|
3937
|
+
};
|
|
3938
|
+
/** The update itself: the feed's entry, no preview. */
|
|
3939
|
+
const updateNow = (name) => {
|
|
3940
|
+
setKeyChange(void 0);
|
|
3941
|
+
setUpdatingName(name);
|
|
3942
|
+
setMessage(void 0);
|
|
3943
|
+
link.call("plugins.remote-install", { name }).then((result) => {
|
|
3944
|
+
setUpdatingName(void 0);
|
|
3945
|
+
if (!result.ok) {
|
|
3946
|
+
setMessage({
|
|
3947
|
+
kind: "error",
|
|
3948
|
+
text: rpcErrorText(result.error)
|
|
3949
|
+
});
|
|
3950
|
+
return;
|
|
3951
|
+
}
|
|
3952
|
+
setRestartNeeded(true);
|
|
3953
|
+
load();
|
|
3954
|
+
}).catch(() => setUpdatingName(void 0));
|
|
3955
|
+
};
|
|
3956
|
+
/** The tri-form input: address/path → inspect, anything else → feed search. */
|
|
3957
|
+
const submitQuery = () => {
|
|
3958
|
+
const text = query.trim();
|
|
3959
|
+
if (text === "") return;
|
|
3960
|
+
setMessage(void 0);
|
|
3961
|
+
if (isHttpUrl(text)) {
|
|
3962
|
+
inspectFromUrl(text);
|
|
3963
|
+
return;
|
|
3964
|
+
}
|
|
3965
|
+
if (looksLikePath(text)) {
|
|
3966
|
+
inspectPath(text);
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
runSearch(text);
|
|
3970
|
+
};
|
|
3971
|
+
const runSearch = (text) => {
|
|
3972
|
+
setSearching(true);
|
|
3973
|
+
setSearchResults(void 0);
|
|
3974
|
+
link.call("plugins.remote-list", {}).then((result) => {
|
|
3975
|
+
setSearching(false);
|
|
3976
|
+
if (!result.ok) {
|
|
3977
|
+
setMessage({
|
|
3978
|
+
kind: "error",
|
|
3979
|
+
text: `搜索失败:${rpcErrorText(result.error)}`
|
|
3980
|
+
});
|
|
3981
|
+
return;
|
|
3982
|
+
}
|
|
3983
|
+
const needle = text.toLowerCase();
|
|
3984
|
+
setSearchResults(result.value.plugins.filter((item) => item.name.toLowerCase().includes(needle) || (item.title ?? "").toLowerCase().includes(needle) || (item.description ?? "").toLowerCase().includes(needle)));
|
|
3985
|
+
}).catch((cause) => {
|
|
3986
|
+
setSearching(false);
|
|
3987
|
+
setMessage({
|
|
3988
|
+
kind: "error",
|
|
3989
|
+
text: String(cause)
|
|
3990
|
+
});
|
|
3991
|
+
});
|
|
3992
|
+
};
|
|
3993
|
+
/** A search-result entry that is not installed yet: preview first. The
|
|
3994
|
+
* entry's own coordinates decide where the zip comes from — a federation
|
|
3995
|
+
* row downloads from the author's release, a same-directory row from its
|
|
3996
|
+
* feed base. */
|
|
3997
|
+
const previewRemote = (item) => {
|
|
3998
|
+
if (item.url !== void 0) {
|
|
3999
|
+
inspectFromUrl(item.url);
|
|
4000
|
+
return;
|
|
4001
|
+
}
|
|
4002
|
+
if (item.feedUrl === void 0 || item.file === void 0) return;
|
|
4003
|
+
const base = item.feedUrl.endsWith("/") ? item.feedUrl : `${item.feedUrl}/`;
|
|
4004
|
+
inspectFromUrl(`${base}${item.file}`);
|
|
4005
|
+
};
|
|
4006
|
+
const onDrop = (event) => {
|
|
4007
|
+
event.preventDefault();
|
|
4008
|
+
setDragging(false);
|
|
4009
|
+
const file = event.dataTransfer.files[0];
|
|
4010
|
+
if (file === void 0) return;
|
|
4011
|
+
if (!file.name.toLowerCase().endsWith(".zip")) {
|
|
4012
|
+
setMessage({
|
|
4013
|
+
kind: "error",
|
|
4014
|
+
text: "只支持 .zip 插件包或组合包"
|
|
4015
|
+
});
|
|
4016
|
+
return;
|
|
4017
|
+
}
|
|
4018
|
+
const zipPath = droppedZipPath(file);
|
|
4019
|
+
if (zipPath === null) {
|
|
4020
|
+
setMessage({
|
|
4021
|
+
kind: "error",
|
|
4022
|
+
text: "当前环境不支持拖拽安装(缺少路径桥)"
|
|
4023
|
+
});
|
|
4024
|
+
return;
|
|
4025
|
+
}
|
|
4026
|
+
inspectPath(zipPath);
|
|
4027
|
+
};
|
|
4028
|
+
const restart = () => {
|
|
4029
|
+
link.call("window.relaunch", {});
|
|
4030
|
+
};
|
|
4031
|
+
const visibleResults = searchResults?.slice(0, SEARCH_ROW_CAP);
|
|
4032
|
+
const spans = /* @__PURE__ */ new Map();
|
|
4033
|
+
for (let index = 0; index < rows.length;) {
|
|
4034
|
+
const category = rows[index].category;
|
|
4035
|
+
let end = index + 1;
|
|
4036
|
+
while (end < rows.length && rows[end].category === category) end += 1;
|
|
4037
|
+
spans.set(index, end - index);
|
|
4038
|
+
index = end;
|
|
2820
4039
|
}
|
|
2821
|
-
return
|
|
4040
|
+
return jsxs(Page, {
|
|
2822
4041
|
title: "插件管理",
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
onClick: load,
|
|
2828
|
-
children: "刷新"
|
|
4042
|
+
titleExtra: jsx(IconButton, {
|
|
4043
|
+
icon: jsx(PlusIcon, {}),
|
|
4044
|
+
label: "安装插件",
|
|
4045
|
+
onClick: openInstall
|
|
2829
4046
|
}),
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
jsx(
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
4047
|
+
actions: restartNeeded ? jsx(Button, {
|
|
4048
|
+
intent: "primary",
|
|
4049
|
+
onClick: restart,
|
|
4050
|
+
children: "重启生效"
|
|
4051
|
+
}) : void 0,
|
|
4052
|
+
children: [
|
|
4053
|
+
jsxs(Stack, {
|
|
4054
|
+
gap: "lg",
|
|
4055
|
+
children: [error !== void 0 && jsx(Alert, {
|
|
4056
|
+
intent: "danger",
|
|
4057
|
+
children: error
|
|
4058
|
+
}), rows.length === 0 ? jsx(EmptyState, {
|
|
4059
|
+
title: "还没有安装插件",
|
|
4060
|
+
action: jsx(Button, {
|
|
4061
|
+
intent: "primary",
|
|
4062
|
+
onClick: openInstall,
|
|
4063
|
+
children: "安装插件"
|
|
4064
|
+
})
|
|
4065
|
+
}) : jsxs(Table, {
|
|
4066
|
+
"data-plugins-table": true,
|
|
4067
|
+
children: [jsx(TableHeader, { children: jsxs(TableRow, { children: [
|
|
4068
|
+
jsx(TableHead, {
|
|
4069
|
+
style: { width: "6em" },
|
|
4070
|
+
children: "分类"
|
|
4071
|
+
}),
|
|
4072
|
+
jsx(TableHead, { children: "名称" }),
|
|
4073
|
+
jsx(TableHead, { children: "类型" }),
|
|
4074
|
+
jsx(TableHead, { children: "版本" }),
|
|
4075
|
+
jsx(TableHead, { children: "状态" }),
|
|
4076
|
+
jsx(TableHead, { children: "操作" })
|
|
4077
|
+
] }) }), jsx(TableBody, { children: rows.map((row, index) => {
|
|
4078
|
+
const update = updates.get(row.packageName);
|
|
4079
|
+
const span = spans.get(index);
|
|
4080
|
+
return jsxs(TableRow, { children: [
|
|
4081
|
+
span !== void 0 && jsx(TableCell, {
|
|
4082
|
+
rowSpan: span,
|
|
4083
|
+
style: {
|
|
4084
|
+
verticalAlign: "middle",
|
|
4085
|
+
color: "var(--snap-color-muted)",
|
|
4086
|
+
fontWeight: 600
|
|
4087
|
+
},
|
|
4088
|
+
children: row.category
|
|
4089
|
+
}),
|
|
4090
|
+
jsx(TableCell, { children: jsxs("div", {
|
|
4091
|
+
style: {
|
|
4092
|
+
display: "flex",
|
|
4093
|
+
flexDirection: "column"
|
|
4094
|
+
},
|
|
4095
|
+
children: [jsxs("span", {
|
|
4096
|
+
style: {
|
|
4097
|
+
display: "flex",
|
|
4098
|
+
alignItems: "center",
|
|
4099
|
+
gap: "var(--snap-space-sm)"
|
|
4100
|
+
},
|
|
4101
|
+
children: [row.title, row.builtinDefault && jsx(Badge, {
|
|
4102
|
+
intent: "neutral",
|
|
4103
|
+
children: "内置默认"
|
|
4104
|
+
})]
|
|
4105
|
+
}), jsx("span", {
|
|
4106
|
+
style: {
|
|
4107
|
+
color: "var(--snap-color-muted)",
|
|
4108
|
+
fontSize: "var(--snap-text-xs)"
|
|
4109
|
+
},
|
|
4110
|
+
children: row.packageName
|
|
4111
|
+
})]
|
|
4112
|
+
}) }),
|
|
4113
|
+
jsxs(TableCell, { children: [KIND_LABELS[row.kind] ?? row.kind, row.uiProfile !== void 0 && jsx(Badge, {
|
|
2860
4114
|
intent: "neutral",
|
|
2861
|
-
children:
|
|
2862
|
-
})]
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
children: "
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
4115
|
+
children: PROFILE_LABELS[row.uiProfile] ?? row.uiProfile
|
|
4116
|
+
})] }),
|
|
4117
|
+
jsx(TableCell, { children: update !== void 0 ? jsx(Button, {
|
|
4118
|
+
intent: "primary",
|
|
4119
|
+
emphasis: "ghost",
|
|
4120
|
+
size: "sm",
|
|
4121
|
+
title: update.keyChanged === true ? `当前 ${update.installedVersion} → ${update.feedVersion} · 发布者密钥已变更` : `当前 ${update.installedVersion} → ${update.feedVersion}`,
|
|
4122
|
+
disabled: updatingName === row.packageName,
|
|
4123
|
+
onClick: () => requestUpdate(update),
|
|
4124
|
+
children: updatingName === row.packageName ? "更新中…" : `⟳ ${update.feedVersion}`
|
|
4125
|
+
}) : row.version ?? "—" }),
|
|
4126
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx(Switch, {
|
|
4127
|
+
checked: true,
|
|
4128
|
+
disabled: true,
|
|
4129
|
+
"aria-label": `启用 ${row.title}`
|
|
4130
|
+
}) : jsxs("div", {
|
|
4131
|
+
style: {
|
|
4132
|
+
display: "flex",
|
|
4133
|
+
alignItems: "center",
|
|
4134
|
+
gap: "var(--snap-space-sm)"
|
|
4135
|
+
},
|
|
4136
|
+
children: [jsx(Switch, {
|
|
4137
|
+
checked: row.enabled,
|
|
4138
|
+
disabled: busy === row.packageName,
|
|
4139
|
+
onCheckedChange: (next) => toggle(row, next),
|
|
4140
|
+
"aria-label": `启用 ${row.title}`
|
|
4141
|
+
}), touched.has(row.packageName) && jsx(Badge, {
|
|
4142
|
+
intent: "warning",
|
|
4143
|
+
children: "待重启"
|
|
4144
|
+
})]
|
|
4145
|
+
}) }),
|
|
4146
|
+
jsx(TableCell, { children: row.builtinDefault ? jsx("span", {
|
|
4147
|
+
style: { color: "var(--snap-color-muted)" },
|
|
4148
|
+
children: "内置默认不可卸载"
|
|
4149
|
+
}) : jsx(Button, {
|
|
4150
|
+
intent: "danger",
|
|
4151
|
+
emphasis: "ghost",
|
|
4152
|
+
size: "sm",
|
|
4153
|
+
disabled: busy === row.packageName,
|
|
4154
|
+
onClick: () => uninstall(row),
|
|
4155
|
+
children: "卸载"
|
|
4156
|
+
}) })
|
|
4157
|
+
] }, row.packageName);
|
|
4158
|
+
}) })]
|
|
4159
|
+
})]
|
|
4160
|
+
}),
|
|
4161
|
+
jsx(Dialog, {
|
|
4162
|
+
open: installOpen,
|
|
4163
|
+
onOpenChange: (next) => {
|
|
4164
|
+
if (!next) closeInstall();
|
|
4165
|
+
},
|
|
4166
|
+
children: jsxs(DialogContent, {
|
|
4167
|
+
presentation: "modal",
|
|
4168
|
+
size: "lg",
|
|
4169
|
+
"data-plugins-dropzone": true,
|
|
4170
|
+
"aria-describedby": void 0,
|
|
4171
|
+
onDragOver: (event) => {
|
|
4172
|
+
event.preventDefault();
|
|
4173
|
+
setDragging(true);
|
|
4174
|
+
},
|
|
4175
|
+
onDragLeave: (event) => {
|
|
4176
|
+
if (event.relatedTarget === null || !event.currentTarget.contains(event.relatedTarget)) setDragging(false);
|
|
4177
|
+
},
|
|
4178
|
+
onDrop,
|
|
4179
|
+
children: [jsx(DialogHeader, { children: jsx(DialogTitle, { children: "安装插件" }) }), jsx(DialogBody, { children: jsxs(Stack, {
|
|
4180
|
+
gap: "sm",
|
|
4181
|
+
children: [
|
|
4182
|
+
jsx("div", {
|
|
4183
|
+
"data-plugins-drop-hint": true,
|
|
4184
|
+
style: {
|
|
4185
|
+
height: "calc(var(--snap-control-height-md) * 3)",
|
|
4186
|
+
display: "flex",
|
|
4187
|
+
alignItems: "center",
|
|
4188
|
+
justifyContent: "center",
|
|
4189
|
+
border: `1px dashed ${dragging ? "var(--snap-color-accent)" : "var(--snap-color-border)"}`,
|
|
4190
|
+
borderRadius: "var(--snap-radius-md)",
|
|
4191
|
+
background: dragging ? "color-mix(in srgb, var(--snap-color-accent) 10%, transparent)" : "transparent",
|
|
4192
|
+
color: "var(--snap-color-muted)",
|
|
4193
|
+
fontSize: "var(--snap-text-sm)"
|
|
4194
|
+
},
|
|
4195
|
+
children: dragging ? "释放以安装" : "拖入 .zip 安装"
|
|
4196
|
+
}),
|
|
4197
|
+
jsxs("div", {
|
|
4198
|
+
style: {
|
|
4199
|
+
display: "flex",
|
|
4200
|
+
gap: "var(--snap-space-sm)"
|
|
4201
|
+
},
|
|
4202
|
+
children: [jsx(Input, {
|
|
4203
|
+
value: query,
|
|
4204
|
+
placeholder: "本地路径 / https://… / 插件名",
|
|
4205
|
+
style: {
|
|
4206
|
+
flex: 1,
|
|
4207
|
+
minWidth: 0
|
|
4208
|
+
},
|
|
4209
|
+
onChange: (event) => setQuery(event.target.value),
|
|
4210
|
+
onKeyDown: (event) => {
|
|
4211
|
+
if (event.key === "Enter") submitQuery();
|
|
4212
|
+
}
|
|
4213
|
+
}), jsx(Button, {
|
|
4214
|
+
intent: "neutral",
|
|
4215
|
+
emphasis: "outline",
|
|
4216
|
+
disabled: searching,
|
|
4217
|
+
onClick: submitQuery,
|
|
4218
|
+
children: searching ? "搜索中…" : "搜索"
|
|
4219
|
+
})]
|
|
4220
|
+
}),
|
|
4221
|
+
message !== void 0 && jsx("div", {
|
|
4222
|
+
role: message.kind === "error" ? "alert" : "status",
|
|
4223
|
+
style: {
|
|
4224
|
+
fontSize: "var(--snap-text-xs)",
|
|
4225
|
+
color: message.kind === "error" ? "var(--snap-color-danger)" : "var(--snap-color-muted)"
|
|
4226
|
+
},
|
|
4227
|
+
children: message.text
|
|
4228
|
+
}),
|
|
4229
|
+
visibleResults !== void 0 && jsxs(Stack, {
|
|
4230
|
+
gap: "sm",
|
|
4231
|
+
children: [
|
|
4232
|
+
jsxs("div", {
|
|
4233
|
+
style: {
|
|
4234
|
+
display: "flex",
|
|
4235
|
+
justifyContent: "space-between",
|
|
4236
|
+
alignItems: "center"
|
|
4237
|
+
},
|
|
4238
|
+
children: [jsxs("span", {
|
|
4239
|
+
style: {
|
|
4240
|
+
fontSize: "var(--snap-text-sm)",
|
|
4241
|
+
color: "var(--snap-color-muted)"
|
|
4242
|
+
},
|
|
4243
|
+
children: [
|
|
4244
|
+
"搜索“",
|
|
4245
|
+
query.trim(),
|
|
4246
|
+
"”(",
|
|
4247
|
+
searchResults?.length ?? 0,
|
|
4248
|
+
")"
|
|
4249
|
+
]
|
|
4250
|
+
}), jsx(Button, {
|
|
4251
|
+
intent: "neutral",
|
|
4252
|
+
emphasis: "ghost",
|
|
4253
|
+
size: "sm",
|
|
4254
|
+
onClick: () => setSearchResults(void 0),
|
|
4255
|
+
children: "✕"
|
|
4256
|
+
})]
|
|
4257
|
+
}),
|
|
4258
|
+
visibleResults.length === 0 && jsx("div", {
|
|
4259
|
+
style: {
|
|
4260
|
+
padding: "12px 0",
|
|
4261
|
+
textAlign: "center",
|
|
4262
|
+
color: "var(--snap-color-muted)",
|
|
4263
|
+
fontSize: "var(--snap-text-sm)"
|
|
4264
|
+
},
|
|
4265
|
+
children: "没有匹配的插件。"
|
|
4266
|
+
}),
|
|
4267
|
+
visibleResults.map((item) => {
|
|
4268
|
+
const installed = item.installed !== void 0;
|
|
4269
|
+
return jsxs("div", {
|
|
4270
|
+
style: {
|
|
4271
|
+
display: "flex",
|
|
4272
|
+
gap: "var(--snap-space-md)",
|
|
4273
|
+
alignItems: "center",
|
|
4274
|
+
justifyContent: "space-between",
|
|
4275
|
+
borderBottom: "1px solid var(--snap-color-border)",
|
|
4276
|
+
paddingBottom: "var(--snap-space-sm)"
|
|
4277
|
+
},
|
|
4278
|
+
children: [jsxs("div", {
|
|
4279
|
+
style: { minWidth: 0 },
|
|
4280
|
+
children: [jsxs("div", {
|
|
4281
|
+
style: {
|
|
4282
|
+
display: "flex",
|
|
4283
|
+
gap: "var(--snap-space-sm)",
|
|
4284
|
+
alignItems: "center"
|
|
4285
|
+
},
|
|
4286
|
+
children: [item.title ?? item.name, item.source !== void 0 && jsx(Badge, {
|
|
4287
|
+
intent: "neutral",
|
|
4288
|
+
children: item.source
|
|
4289
|
+
})]
|
|
4290
|
+
}), jsxs("div", {
|
|
4291
|
+
style: {
|
|
4292
|
+
fontSize: "var(--snap-text-xs)",
|
|
4293
|
+
color: "var(--snap-color-muted)"
|
|
4294
|
+
},
|
|
4295
|
+
children: [
|
|
4296
|
+
item.name,
|
|
4297
|
+
" · ",
|
|
4298
|
+
item.version
|
|
4299
|
+
]
|
|
4300
|
+
})]
|
|
4301
|
+
}), item.action === "install" ? jsx(Button, {
|
|
4302
|
+
intent: "primary",
|
|
4303
|
+
emphasis: "outline",
|
|
4304
|
+
size: "sm",
|
|
4305
|
+
onClick: () => previewRemote(item),
|
|
4306
|
+
children: "安装"
|
|
4307
|
+
}) : item.action === "update" && installed ? jsx(Button, {
|
|
4308
|
+
intent: "primary",
|
|
4309
|
+
emphasis: "ghost",
|
|
4310
|
+
size: "sm",
|
|
4311
|
+
title: `当前 ${item.installed?.version} → ${item.version}`,
|
|
4312
|
+
disabled: updatingName === item.name,
|
|
4313
|
+
onClick: () => requestUpdate({
|
|
4314
|
+
name: item.name,
|
|
4315
|
+
installedVersion: item.installed?.version ?? "",
|
|
4316
|
+
feedVersion: item.version
|
|
4317
|
+
}),
|
|
4318
|
+
children: updatingName === item.name ? "更新中…" : `⟳ ${item.version}`
|
|
4319
|
+
}) : jsx("span", {
|
|
4320
|
+
style: {
|
|
4321
|
+
fontSize: "var(--snap-text-xs)",
|
|
4322
|
+
color: "var(--snap-color-muted)"
|
|
4323
|
+
},
|
|
4324
|
+
children: item.action === "current" ? "已是最新" : "本地更新"
|
|
4325
|
+
})]
|
|
4326
|
+
}, item.name);
|
|
4327
|
+
}),
|
|
4328
|
+
(searchResults?.length ?? 0) > SEARCH_ROW_CAP && jsxs("div", {
|
|
4329
|
+
style: {
|
|
4330
|
+
fontSize: "var(--snap-text-xs)",
|
|
4331
|
+
color: "var(--snap-color-muted)"
|
|
4332
|
+
},
|
|
4333
|
+
children: [
|
|
4334
|
+
"已显示前 ",
|
|
4335
|
+
SEARCH_ROW_CAP,
|
|
4336
|
+
" 条,共 ",
|
|
4337
|
+
searchResults?.length,
|
|
4338
|
+
" 条。"
|
|
4339
|
+
]
|
|
4340
|
+
})
|
|
4341
|
+
]
|
|
4342
|
+
})
|
|
4343
|
+
]
|
|
4344
|
+
}) })]
|
|
4345
|
+
})
|
|
4346
|
+
}),
|
|
4347
|
+
jsx(Dialog, {
|
|
4348
|
+
open: phase.kind === "confirm" || phase.kind === "installing" || phase.kind === "error",
|
|
4349
|
+
onOpenChange: (next) => {
|
|
4350
|
+
if (!next && phase.kind !== "installing") setPhase({ kind: "idle" });
|
|
4351
|
+
},
|
|
4352
|
+
children: jsxs(DialogContent, {
|
|
4353
|
+
presentation: "modal",
|
|
4354
|
+
"aria-describedby": void 0,
|
|
4355
|
+
children: [
|
|
4356
|
+
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}` })] }),
|
|
4357
|
+
jsxs(DialogBody, { children: [
|
|
4358
|
+
phase.kind === "error" && jsx("div", {
|
|
4359
|
+
style: {
|
|
4360
|
+
color: "var(--snap-color-danger)",
|
|
4361
|
+
whiteSpace: "pre-wrap",
|
|
4362
|
+
fontSize: "var(--snap-text-sm)"
|
|
4363
|
+
},
|
|
4364
|
+
children: phase.message
|
|
4365
|
+
}),
|
|
4366
|
+
phase.kind === "confirm" && phase.archive.kind === "combo" && jsxs(Stack, {
|
|
4367
|
+
gap: "sm",
|
|
4368
|
+
children: [
|
|
4369
|
+
phase.archive.combo.description !== void 0 && jsx("div", {
|
|
4370
|
+
style: {
|
|
4371
|
+
color: "var(--snap-color-muted)",
|
|
4372
|
+
fontSize: "var(--snap-text-sm)"
|
|
4373
|
+
},
|
|
4374
|
+
children: phase.archive.combo.description
|
|
4375
|
+
}),
|
|
4376
|
+
jsxs("div", {
|
|
4377
|
+
style: {
|
|
4378
|
+
display: "grid",
|
|
4379
|
+
gap: "var(--snap-space-xs)",
|
|
4380
|
+
fontSize: "var(--snap-text-sm)"
|
|
4381
|
+
},
|
|
4382
|
+
children: [jsxs("div", { children: [
|
|
4383
|
+
"插件(",
|
|
4384
|
+
phase.archive.combo.plugins.length,
|
|
4385
|
+
")"
|
|
4386
|
+
] }), phase.archive.combo.plugins.map((plugin) => {
|
|
4387
|
+
const line = signatureText(plugin.signature, phase.viaUrl);
|
|
4388
|
+
const action = plugin.action === "install" ? "安装" : plugin.action === "update" ? "更新" : "保留";
|
|
4389
|
+
return jsxs("div", {
|
|
4390
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
4391
|
+
children: [
|
|
4392
|
+
plugin.title ?? plugin.name,
|
|
4393
|
+
" ",
|
|
4394
|
+
plugin.version,
|
|
4395
|
+
" · ",
|
|
4396
|
+
action,
|
|
4397
|
+
line.warning ? " · ⚠ 未验证" : ""
|
|
4398
|
+
]
|
|
4399
|
+
}, plugin.name);
|
|
4400
|
+
})]
|
|
4401
|
+
}),
|
|
4402
|
+
phase.archive.combo.missing.length > 0 && jsxs("div", {
|
|
4403
|
+
style: {
|
|
4404
|
+
color: "var(--snap-color-danger)",
|
|
4405
|
+
fontSize: "var(--snap-text-sm)"
|
|
4406
|
+
},
|
|
4407
|
+
children: ["缺少依赖:", phase.archive.combo.missing.join("、")]
|
|
4408
|
+
})
|
|
4409
|
+
]
|
|
4410
|
+
}),
|
|
4411
|
+
phase.kind === "confirm" && phase.archive.kind === "plugin" && jsxs(Stack, {
|
|
4412
|
+
gap: "sm",
|
|
4413
|
+
children: [
|
|
4414
|
+
phase.risk ? jsx("div", {
|
|
4415
|
+
"data-plugins-risk": true,
|
|
4416
|
+
style: {
|
|
4417
|
+
color: "var(--snap-color-warning)",
|
|
4418
|
+
fontWeight: 600
|
|
4419
|
+
},
|
|
4420
|
+
children: "⚠ 此插件未经发布者验证"
|
|
4421
|
+
}) : void 0,
|
|
4422
|
+
!phase.risk && jsxs(Stack, {
|
|
4423
|
+
gap: "sm",
|
|
4424
|
+
children: [
|
|
4425
|
+
phase.archive.plugin.title !== void 0 && jsxs("div", { children: ["名称:", phase.archive.plugin.title] }),
|
|
4426
|
+
jsxs("div", { children: ["包名:", phase.archive.plugin.name] }),
|
|
4427
|
+
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] })
|
|
4428
|
+
]
|
|
4429
|
+
}),
|
|
4430
|
+
(() => {
|
|
4431
|
+
const line = signatureText(phase.archive.plugin.signature, phase.viaUrl);
|
|
4432
|
+
return jsxs("div", {
|
|
4433
|
+
"data-plugins-signature": phase.archive.plugin.signature.state,
|
|
4434
|
+
style: { color: line.warning ? "var(--snap-color-warning)" : void 0 },
|
|
4435
|
+
children: ["签名:", line.text]
|
|
4436
|
+
});
|
|
4437
|
+
})(),
|
|
4438
|
+
!phase.risk && jsxs(Stack, {
|
|
4439
|
+
gap: "sm",
|
|
4440
|
+
children: [
|
|
4441
|
+
jsxs("div", { children: ["权限:", phase.archive.plugin.permissions.length === 0 ? "无" : phase.archive.plugin.permissions.join("、")] }),
|
|
4442
|
+
phase.archive.plugin.missing.length > 0 && jsxs("div", {
|
|
4443
|
+
style: {
|
|
4444
|
+
color: "var(--snap-color-danger)",
|
|
4445
|
+
fontSize: "var(--snap-text-sm)"
|
|
4446
|
+
},
|
|
4447
|
+
children: ["缺少依赖:", phase.archive.plugin.missing.join("、")]
|
|
4448
|
+
}),
|
|
4449
|
+
phase.archive.plugin.action === "blocked" && jsxs("div", {
|
|
4450
|
+
style: {
|
|
4451
|
+
color: "var(--snap-color-danger)",
|
|
4452
|
+
fontSize: "var(--snap-text-sm)"
|
|
4453
|
+
},
|
|
4454
|
+
children: [
|
|
4455
|
+
"已安装 v",
|
|
4456
|
+
phase.archive.plugin.installed?.version,
|
|
4457
|
+
",安装包 v",
|
|
4458
|
+
phase.archive.plugin.version,
|
|
4459
|
+
" 不高于已装版本,无法覆盖。"
|
|
4460
|
+
]
|
|
4461
|
+
})
|
|
4462
|
+
]
|
|
4463
|
+
}),
|
|
4464
|
+
phase.risk && jsx("div", {
|
|
4465
|
+
style: {
|
|
4466
|
+
color: "var(--snap-color-muted)",
|
|
4467
|
+
fontSize: "var(--snap-text-sm)"
|
|
4468
|
+
},
|
|
4469
|
+
children: phase.archive.plugin.signature.keyId !== void 0 ? `签名 keyId ${phase.archive.plugin.signature.keyId} 不在本机信任名单中,无法验证发布者。` : "这个包没有携带任何签名,也没有任何完整性校验。"
|
|
4470
|
+
})
|
|
4471
|
+
]
|
|
4472
|
+
})
|
|
4473
|
+
] }),
|
|
4474
|
+
jsxs(DialogFooter, { children: [
|
|
4475
|
+
phase.kind === "error" && jsx(Button, {
|
|
4476
|
+
intent: "neutral",
|
|
4477
|
+
emphasis: "outline",
|
|
4478
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
4479
|
+
children: "返回"
|
|
4480
|
+
}),
|
|
4481
|
+
phase.kind === "confirm" && jsxs(Fragment, { children: [jsx(Button, {
|
|
4482
|
+
intent: "neutral",
|
|
4483
|
+
emphasis: "outline",
|
|
4484
|
+
onClick: () => setPhase({ kind: "idle" }),
|
|
4485
|
+
children: "取消"
|
|
4486
|
+
}), phase.risk ? jsx(Button, {
|
|
4487
|
+
intent: "primary",
|
|
4488
|
+
"data-plugins-risk-confirm": true,
|
|
4489
|
+
onClick: () => runInstall(phase.zipPath, phase.archive),
|
|
4490
|
+
children: "我知晓风险,仍要安装"
|
|
4491
|
+
}) : jsx(Button, {
|
|
4492
|
+
intent: "primary",
|
|
4493
|
+
"data-plugins-install-confirm": true,
|
|
4494
|
+
disabled: phase.archive.kind === "plugin" && phase.archive.plugin.action === "blocked",
|
|
4495
|
+
onClick: () => {
|
|
4496
|
+
if (phase.archive.kind === "plugin" && phase.archive.plugin.signature.state === "unverified") {
|
|
4497
|
+
setPhase({
|
|
4498
|
+
...phase,
|
|
4499
|
+
risk: true
|
|
4500
|
+
});
|
|
4501
|
+
return;
|
|
4502
|
+
}
|
|
4503
|
+
runInstall(phase.zipPath, phase.archive);
|
|
4504
|
+
},
|
|
4505
|
+
children: phase.archive.kind === "combo" ? "安装组合" : phase.archive.plugin.action === "update" ? "更新" : "安装"
|
|
4506
|
+
})] }),
|
|
4507
|
+
phase.kind === "installing" && jsx("span", {
|
|
4508
|
+
style: { color: "var(--snap-color-muted)" },
|
|
4509
|
+
children: "正在安装…"
|
|
4510
|
+
})
|
|
4511
|
+
] })
|
|
4512
|
+
]
|
|
4513
|
+
})
|
|
4514
|
+
}),
|
|
4515
|
+
jsx(Dialog, {
|
|
4516
|
+
open: keyChange !== void 0,
|
|
4517
|
+
onOpenChange: (next) => {
|
|
4518
|
+
if (!next) setKeyChange(void 0);
|
|
4519
|
+
},
|
|
4520
|
+
children: jsxs(DialogContent, {
|
|
4521
|
+
presentation: "modal",
|
|
4522
|
+
children: [
|
|
4523
|
+
jsxs(DialogHeader, { children: [jsx(DialogTitle, { children: "发布者密钥已变更" }), jsxs(DialogDescription, { children: [keyChange?.name, " 的新版本由不同的密钥签名。"] })] }),
|
|
4524
|
+
jsx(DialogBody, { children: keyChange !== void 0 && jsxs("div", {
|
|
4525
|
+
style: { fontSize: "var(--snap-text-sm)" },
|
|
4526
|
+
children: [
|
|
4527
|
+
"已安装 v",
|
|
4528
|
+
keyChange.installedVersion,
|
|
4529
|
+
" → 源上 v",
|
|
4530
|
+
keyChange.feedVersion,
|
|
4531
|
+
"。"
|
|
4532
|
+
]
|
|
4533
|
+
}) }),
|
|
4534
|
+
jsxs(DialogFooter, { children: [jsx(Button, {
|
|
4535
|
+
intent: "neutral",
|
|
4536
|
+
emphasis: "outline",
|
|
4537
|
+
onClick: () => setKeyChange(void 0),
|
|
4538
|
+
children: "取消"
|
|
4539
|
+
}), jsx(Button, {
|
|
4540
|
+
intent: "primary",
|
|
4541
|
+
"data-plugins-keychange-confirm": true,
|
|
4542
|
+
onClick: () => keyChange !== void 0 && updateNow(keyChange.name),
|
|
4543
|
+
children: "仍要更新"
|
|
4544
|
+
})] })
|
|
4545
|
+
]
|
|
4546
|
+
})
|
|
4547
|
+
})
|
|
4548
|
+
]
|
|
2909
4549
|
});
|
|
2910
4550
|
}
|
|
2911
4551
|
//#endregion
|
|
@@ -2947,6 +4587,19 @@ function GearIcon() {
|
|
|
2947
4587
|
}), 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
4588
|
});
|
|
2949
4589
|
}
|
|
4590
|
+
/** The close glyph used by the surface's dismiss control. */
|
|
4591
|
+
function CloseIcon() {
|
|
4592
|
+
return jsx("svg", {
|
|
4593
|
+
viewBox: "0 0 24 24",
|
|
4594
|
+
width: "18",
|
|
4595
|
+
height: "18",
|
|
4596
|
+
fill: "none",
|
|
4597
|
+
stroke: "currentColor",
|
|
4598
|
+
strokeWidth: "1.8",
|
|
4599
|
+
"aria-hidden": "true",
|
|
4600
|
+
children: jsx("path", { d: "M6 6l12 12M18 6L6 18" })
|
|
4601
|
+
});
|
|
4602
|
+
}
|
|
2950
4603
|
/** The default settings trigger; the layout decides placement/presentation. */
|
|
2951
4604
|
function SettingsEntry(props) {
|
|
2952
4605
|
if (props.presentation === "label") return jsx(Button, {
|
|
@@ -2965,12 +4618,13 @@ function SettingsEntry(props) {
|
|
|
2965
4618
|
}
|
|
2966
4619
|
/** The default settings surface. */
|
|
2967
4620
|
function SettingsSurface(props) {
|
|
2968
|
-
const { service } = props;
|
|
4621
|
+
const { service, ctx } = props;
|
|
2969
4622
|
useSyncExternalStore(service.subscribe, service.version, service.version);
|
|
2970
4623
|
const open = service.isOpen();
|
|
2971
4624
|
const pages = service.listPages();
|
|
2972
4625
|
const activeId = service.activePage();
|
|
2973
4626
|
const active = pages.find((page) => page.id === activeId);
|
|
4627
|
+
const [feedOpen, setFeedOpen] = useState(false);
|
|
2974
4628
|
const groups = /* @__PURE__ */ new Map();
|
|
2975
4629
|
for (const page of pages) {
|
|
2976
4630
|
const group = page.group ?? "其他";
|
|
@@ -2978,7 +4632,7 @@ function SettingsSurface(props) {
|
|
|
2978
4632
|
if (bucket === void 0) groups.set(group, [page]);
|
|
2979
4633
|
else bucket.push(page);
|
|
2980
4634
|
}
|
|
2981
|
-
return jsx(Dialog, {
|
|
4635
|
+
return jsxs(Fragment, { children: [jsx(Dialog, {
|
|
2982
4636
|
open,
|
|
2983
4637
|
onOpenChange: (next) => {
|
|
2984
4638
|
if (!next) service.close();
|
|
@@ -2992,11 +4646,21 @@ function SettingsSurface(props) {
|
|
|
2992
4646
|
children: [jsxs("header", {
|
|
2993
4647
|
...part("settings", "header"),
|
|
2994
4648
|
className: "snap-settings-header",
|
|
2995
|
-
children: [jsx(DialogTitle, { children: "设置" }),
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
4649
|
+
children: [jsx(DialogTitle, { children: "设置" }), jsxs("div", {
|
|
4650
|
+
style: {
|
|
4651
|
+
display: "flex",
|
|
4652
|
+
alignItems: "center",
|
|
4653
|
+
gap: 4
|
|
4654
|
+
},
|
|
4655
|
+
children: [jsx(IconButton, {
|
|
4656
|
+
icon: jsx(GearIcon, {}),
|
|
4657
|
+
label: "配置插件源",
|
|
4658
|
+
onClick: () => setFeedOpen(true)
|
|
4659
|
+
}), jsx(IconButton, {
|
|
4660
|
+
icon: jsx(CloseIcon, {}),
|
|
4661
|
+
label: "关闭",
|
|
4662
|
+
onClick: () => service.close()
|
|
4663
|
+
})]
|
|
3000
4664
|
})]
|
|
3001
4665
|
}), jsxs("div", {
|
|
3002
4666
|
...part("settings", "body"),
|
|
@@ -3029,10 +4693,7 @@ function SettingsSurface(props) {
|
|
|
3029
4693
|
...part("settings", "content"),
|
|
3030
4694
|
className: "snap-settings-content",
|
|
3031
4695
|
"data-active-page": activeId,
|
|
3032
|
-
children: active === void 0 ? jsx(EmptyState, {
|
|
3033
|
-
title: "暂无设置页",
|
|
3034
|
-
description: "安装或启用一个带设置页的插件后,它会出现在这里。"
|
|
3035
|
-
}) : jsx(SettingsPageBoundary, {
|
|
4696
|
+
children: active === void 0 ? jsx(EmptyState, { title: "暂无设置页" }) : jsx(SettingsPageBoundary, {
|
|
3036
4697
|
page: active.id,
|
|
3037
4698
|
children: active.render()
|
|
3038
4699
|
})
|
|
@@ -3040,7 +4701,11 @@ function SettingsSurface(props) {
|
|
|
3040
4701
|
})]
|
|
3041
4702
|
})
|
|
3042
4703
|
})
|
|
3043
|
-
})
|
|
4704
|
+
}), jsx(PluginFeedDialog, {
|
|
4705
|
+
ctx,
|
|
4706
|
+
open: feedOpen,
|
|
4707
|
+
onOpenChange: setFeedOpen
|
|
4708
|
+
})] });
|
|
3044
4709
|
}
|
|
3045
4710
|
/** Mount the settings registry and its default slot contributions. */
|
|
3046
4711
|
const settingsPlugin = {
|
|
@@ -3144,7 +4809,10 @@ const settingsPlugin = {
|
|
|
3144
4809
|
ctx.ui.contribute(ctx, UI_SLOT_IDS.settingsSurface, {
|
|
3145
4810
|
id: "settings.default-surface",
|
|
3146
4811
|
order: 0,
|
|
3147
|
-
render: () => jsx(SettingsSurface, {
|
|
4812
|
+
render: () => jsx(SettingsSurface, {
|
|
4813
|
+
service,
|
|
4814
|
+
ctx
|
|
4815
|
+
})
|
|
3148
4816
|
});
|
|
3149
4817
|
}
|
|
3150
4818
|
};
|
|
@@ -3159,6 +4827,15 @@ function settingsPageInfo(page) {
|
|
|
3159
4827
|
}
|
|
3160
4828
|
//#endregion
|
|
3161
4829
|
//#region lib/types/runtime.js
|
|
4830
|
+
/**
|
|
4831
|
+
* The built-in renderer runtime: it takes over the kernel root, mounts the
|
|
4832
|
+
* core services, the skins, the layout/page plugins, and finally the fallback
|
|
4833
|
+
* layout. There is no framework row and no framework seed: the substrate is
|
|
4834
|
+
* always present, so a fresh install has a usable UI before any plugin is
|
|
4835
|
+
* installed.
|
|
4836
|
+
*
|
|
4837
|
+
* @module @snap-rail/ui/runtime
|
|
4838
|
+
*/
|
|
3162
4839
|
/** The React context carrying the host link/surface into builtin pages. */
|
|
3163
4840
|
const ClientContext = createContext(null);
|
|
3164
4841
|
/** Provide the client services to builtin page components. */
|
|
@@ -3174,6 +4851,14 @@ function useClient() {
|
|
|
3174
4851
|
if (service === null) throw new Error("useClient: no ClientProvider in the tree");
|
|
3175
4852
|
return service;
|
|
3176
4853
|
}
|
|
4854
|
+
/**
|
|
4855
|
+
* Wire an element as a ball face's single drag/click surface. Past the travel
|
|
4856
|
+
* threshold the face only signals `shell.ball.move` `begin`/`end`; the host
|
|
4857
|
+
* anchors the grab from the OS cursor and runs the dock settle, so the face
|
|
4858
|
+
* never streams coordinates. A press-release inside the threshold is the
|
|
4859
|
+
* click. Returns the disposer removing every listener.
|
|
4860
|
+
*/
|
|
4861
|
+
const attachBallDrag = attachBallDrag$1;
|
|
3177
4862
|
/** Re-render on settings open/page changes. */
|
|
3178
4863
|
function useSettingsVersion(ctx) {
|
|
3179
4864
|
return useSyncExternalStore(ctx.settings.subscribe, ctx.settings.version, ctx.settings.version);
|
|
@@ -3231,7 +4916,7 @@ function SettingsFallbackHost(props) {
|
|
|
3231
4916
|
/** The operator-window root. */
|
|
3232
4917
|
function MainRoot(props) {
|
|
3233
4918
|
const layout = useActiveLayout();
|
|
3234
|
-
return
|
|
4919
|
+
return jsx(Fragment, { children: jsxs(TooltipProvider, { children: [
|
|
3235
4920
|
jsx(StageProfiles, {
|
|
3236
4921
|
ctx: props.ctx,
|
|
3237
4922
|
layout
|
|
@@ -3241,32 +4926,81 @@ function MainRoot(props) {
|
|
|
3241
4926
|
children: "没有已加载的布局插件。"
|
|
3242
4927
|
}) : layout.render(),
|
|
3243
4928
|
jsx(OverlayHost, { ctx: props.ctx }),
|
|
3244
|
-
jsx(SettingsFallbackHost, { ctx: props.ctx })
|
|
3245
|
-
|
|
4929
|
+
jsx(SettingsFallbackHost, { ctx: props.ctx }),
|
|
4930
|
+
jsx(Toaster, {})
|
|
4931
|
+
] }) });
|
|
3246
4932
|
}
|
|
3247
|
-
/**
|
|
4933
|
+
/**
|
|
4934
|
+
* The fallback ball face used when no plugin occupies `shell.ball`: a themed
|
|
4935
|
+
* disc that follows the active skin tokens (visible on any colour mode). The
|
|
4936
|
+
* whole ball is one drag/click surface ({@link attachBallDrag}): press-move
|
|
4937
|
+
* drags the window over `shell.ball.move`, a press-release summons the
|
|
4938
|
+
* operator window — the same anatomy the kernel's crash fallback paints.
|
|
4939
|
+
*/
|
|
3248
4940
|
function BallRoot(props) {
|
|
3249
4941
|
useUiVersion(props.ctx.ui);
|
|
3250
4942
|
const occupant = props.ctx.ui.list(UI_SLOT_IDS.ball)[0];
|
|
3251
|
-
|
|
4943
|
+
const link = props.ctx.client.link;
|
|
4944
|
+
const hasOccupant = occupant !== void 0;
|
|
4945
|
+
const rootRef = useRef(null);
|
|
4946
|
+
useEffect(() => {
|
|
4947
|
+
if (hasOccupant) return void 0;
|
|
4948
|
+
const element = rootRef.current;
|
|
4949
|
+
if (element === null) return void 0;
|
|
4950
|
+
return attachBallDrag(element, {
|
|
4951
|
+
link,
|
|
4952
|
+
onClick: () => {
|
|
4953
|
+
link.call("shell.surface.present", { surface: "main" });
|
|
4954
|
+
}
|
|
4955
|
+
});
|
|
4956
|
+
}, [hasOccupant, link]);
|
|
4957
|
+
if (occupant !== void 0) return jsxs(TooltipProvider, { children: [jsx("div", {
|
|
3252
4958
|
style: {
|
|
3253
4959
|
width: "100%",
|
|
3254
4960
|
height: "100%"
|
|
3255
4961
|
},
|
|
3256
4962
|
children: occupant.render({ surface: "ball" })
|
|
3257
|
-
});
|
|
4963
|
+
}), jsx(Toaster, {})] });
|
|
3258
4964
|
return jsx("div", {
|
|
4965
|
+
ref: rootRef,
|
|
3259
4966
|
"data-snap-part": "ball.root",
|
|
3260
4967
|
style: {
|
|
3261
4968
|
display: "flex",
|
|
3262
4969
|
alignItems: "center",
|
|
3263
4970
|
justifyContent: "center",
|
|
3264
4971
|
width: "100%",
|
|
3265
|
-
height: "100%"
|
|
3266
|
-
color: "var(--snap-color-muted)",
|
|
3267
|
-
fontSize: "var(--snap-text-xs)"
|
|
4972
|
+
height: "100%"
|
|
3268
4973
|
},
|
|
3269
|
-
children: "
|
|
4974
|
+
children: jsx("div", {
|
|
4975
|
+
"data-snap-part": "ball.orb",
|
|
4976
|
+
style: {
|
|
4977
|
+
display: "flex",
|
|
4978
|
+
alignItems: "center",
|
|
4979
|
+
justifyContent: "center",
|
|
4980
|
+
width: "calc(100% - 16px)",
|
|
4981
|
+
height: "calc(100% - 16px)",
|
|
4982
|
+
borderRadius: "50%",
|
|
4983
|
+
background: "var(--snap-color-surface-raised)",
|
|
4984
|
+
border: "var(--snap-border-width) solid var(--snap-color-border)"
|
|
4985
|
+
},
|
|
4986
|
+
children: jsx("button", {
|
|
4987
|
+
type: "button",
|
|
4988
|
+
"data-snap-part": "ball.core",
|
|
4989
|
+
title: "打开主窗口",
|
|
4990
|
+
style: {
|
|
4991
|
+
width: "calc(100% - 16px)",
|
|
4992
|
+
height: "calc(100% - 16px)",
|
|
4993
|
+
borderRadius: "50%",
|
|
4994
|
+
border: "none",
|
|
4995
|
+
background: "var(--snap-color-surface)",
|
|
4996
|
+
color: "var(--snap-color-text)",
|
|
4997
|
+
fontSize: "var(--snap-text-xs)",
|
|
4998
|
+
fontWeight: "var(--snap-weight-medium)",
|
|
4999
|
+
cursor: "default"
|
|
5000
|
+
},
|
|
5001
|
+
children: "snap-rail"
|
|
5002
|
+
})
|
|
5003
|
+
})
|
|
3270
5004
|
});
|
|
3271
5005
|
}
|
|
3272
5006
|
/** The root that mounts the layout (or the ball face) and the global overlays. */
|
|
@@ -3301,12 +5035,9 @@ async function createClientRuntime(handle, options) {
|
|
|
3301
5035
|
await ctx.plugin(skinsPlugin);
|
|
3302
5036
|
await ctx.plugin(settingsPlugin);
|
|
3303
5037
|
const applyThemeRow = (value) => {
|
|
3304
|
-
const
|
|
3305
|
-
const
|
|
3306
|
-
|
|
3307
|
-
const resolved = choice === "system" ? prefersLight ? "light" : "dark" : choice;
|
|
3308
|
-
ctx.skins.setMode(resolved);
|
|
3309
|
-
if (typeof document !== "undefined") document.documentElement.dataset["mode"] = resolved;
|
|
5038
|
+
const row = value;
|
|
5039
|
+
const selection = typeof row?.id === "string" && row.id !== "" ? row.id : row?.mode === "light" ? DEFAULT_LIGHT_ID : DEFAULT_DARK_ID;
|
|
5040
|
+
if (!ctx.skins.activate(selection)) ctx.skins.activate(DEFAULT_DARK_ID);
|
|
3310
5041
|
};
|
|
3311
5042
|
handle.link.call("settings.get", { key: "ui.theme" }).then((result) => {
|
|
3312
5043
|
if (result.ok) applyThemeRow(result.value.value);
|
|
@@ -3342,4 +5073,4 @@ async function createClientRuntime(handle, options) {
|
|
|
3342
5073
|
};
|
|
3343
5074
|
}
|
|
3344
5075
|
//#endregion
|
|
3345
|
-
export { AppShell, Badge, Button, CUSTOM_SLOT_PATTERN, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartFrame, Checkbox, ClientProvider,
|
|
5076
|
+
export { Alert, AlertDescription, AlertTitle, AppShell, Badge, Button, CUSTOM_SLOT_PATTERN, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, ChartFrame, Checkbox, ClientProvider, Controller, DEFAULT_DARK, DEFAULT_DARK_ID, DEFAULT_LIGHT, DEFAULT_LIGHT_ID, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, DragScroll, EmptyState, Field, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, FormProvider, Grid, IconButton, Input, Label, Led, List, ListItem, Menu, MenuCheckboxItem, MenuContent, MenuGroup, MenuItem, MenuLabel, MenuSeparator, MenuTrigger, NumberInput, Page, Panel, Popover, PopoverAnchor, PopoverClose, PopoverContent, PopoverTrigger, Progress, RadioGroup, RadioGroupItem, Row, SchemaForm, ScrollArea, Section, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, Separator, SettingsEntry, SettingsSurface, Sheet, Skeleton, SkinsProvider, Slider, Slot, Spinner, Split, Stack, Switch, Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toast, ToastAction, ToastClose, ToastDescription, ToastTitle, ToastViewport, Toaster, Toolbar, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TouchSelect, UI_COMPONENTS, UI_DIAGNOSTIC_KINDS, UI_PROFILES, UI_SLOT_IDS, UI_SLOT_MODES, UiProvider, Visualization, attachBallDrag, attachDragPan, chartThemeOf, cn, controlHeight, createClientRuntime, dismissToast, fallbackPlugin, isValidSlotId, literalValuesOf, pagesPlugin, part, schemaNodeOf, settingsPageInfo, settingsPlugin, skinTokenVar, skinsPlugin, slotsPlugin, space, toast, useActiveLayout, useChartTheme, useClient, useController, useFieldArray, useForm, useFormContext, useFormState, usePagesVersion, useSkinId, useSkinTokens, useSkins, useUi, useUiVersion, useWatch, zodResolver };
|