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