@snap-rail/ui 0.1.1 → 0.3.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.
Files changed (45) hide show
  1. package/lib/charts.js +12 -5
  2. package/lib/components/index.js +2195 -0
  3. package/lib/contract.js +138 -62
  4. package/lib/fallback.js +21 -4
  5. package/lib/index.js +4287 -261
  6. package/lib/runtime.js +206 -77
  7. package/lib/settings-pages/index.js +1326 -0
  8. package/lib/settings.js +122 -72
  9. package/lib/types/charts.d.ts +1 -1
  10. package/lib/types/charts.js +5 -5
  11. package/lib/types/components/alert.d.ts +57 -0
  12. package/lib/types/components/alert.js +46 -0
  13. package/lib/types/components/button.js +2 -2
  14. package/lib/types/components/combobox.d.ts +45 -0
  15. package/lib/types/components/combobox.js +108 -0
  16. package/lib/types/components/controls.d.ts +74 -11
  17. package/lib/types/components/controls.js +67 -24
  18. package/lib/types/components/dialog.js +1 -1
  19. package/lib/types/components/form-rhf.d.ts +56 -0
  20. package/lib/types/components/form-rhf.js +74 -0
  21. package/lib/types/components/form.d.ts +33 -5
  22. package/lib/types/components/form.js +22 -6
  23. package/lib/types/components/index.d.ts +8 -0
  24. package/lib/types/components/index.js +8 -0
  25. package/lib/types/components/input.d.ts +11 -5
  26. package/lib/types/components/input.js +34 -7
  27. package/lib/types/components/layout.d.ts +28 -6
  28. package/lib/types/components/layout.js +86 -13
  29. package/lib/types/components/overlay.d.ts +110 -0
  30. package/lib/types/components/overlay.js +185 -0
  31. package/lib/types/components/schema-form.d.ts +3 -1
  32. package/lib/types/components/schema-form.js +46 -40
  33. package/lib/types/components/slider.d.ts +18 -0
  34. package/lib/types/components/slider.js +15 -0
  35. package/lib/types/components/surface.js +12 -12
  36. package/lib/types/contract.d.ts +55 -30
  37. package/lib/types/contract.js +55 -30
  38. package/lib/types/runtime.js +3 -2
  39. package/lib/types/settings-pages/appearance.js +2 -2
  40. package/lib/types/settings-pages/plugins.js +2 -2
  41. package/lib/types/utils.d.ts +7 -1
  42. package/lib/types/utils.js +7 -1
  43. package/package.json +14 -7
  44. package/src/styles/base.css +315 -5
  45. package/src/styles/default.css +194 -6
package/lib/runtime.js CHANGED
@@ -7,7 +7,12 @@ import { TimerService } from "@snap-rail/cordis-plugin-timer";
7
7
  import { shellContract } from "@snap-rail/shell/contract";
8
8
  import { Component, createContext, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
9
9
  import { createRoot } from "react-dom/client";
10
+ import "@radix-ui/react-separator";
10
11
  import { Slot as Slot$1 } from "@radix-ui/react-slot";
12
+ import "@radix-ui/react-dropdown-menu";
13
+ import "@radix-ui/react-popover";
14
+ import * as ToastPrimitive from "@radix-ui/react-toast";
15
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
11
16
  import "@radix-ui/react-checkbox";
12
17
  import "@radix-ui/react-label";
13
18
  import "@radix-ui/react-radio-group";
@@ -15,6 +20,10 @@ import "@radix-ui/react-select";
15
20
  import * as SwitchPrimitive from "@radix-ui/react-switch";
16
21
  import * as TabsPrimitive from "@radix-ui/react-tabs";
17
22
  import * as DialogPrimitive from "@radix-ui/react-dialog";
23
+ import "react-hook-form";
24
+ import "@hookform/resolvers/zod";
25
+ import "@radix-ui/react-scroll-area";
26
+ import "@radix-ui/react-slider";
18
27
  import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
19
28
  //#region lib/types/utils.js
20
29
  /**
@@ -27,7 +36,13 @@ import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
27
36
  function cn(...values) {
28
37
  return values.filter((value) => typeof value === "string" && value.length > 0).join(" ");
29
38
  }
30
- /** The anatomy attributes every semantic component renders. */
39
+ /**
40
+ * The anatomy attributes every semantic component renders. The identity is
41
+ * component-owned: components spread these AFTER caller props so a composite
42
+ * can never mask a host part (a masked `button.root` loses every skin rule
43
+ * and falls back to the UA default look). Composites tag their own wrappers
44
+ * instead of pushing `part()` into a child component's props.
45
+ */
31
46
  function part(component, name) {
32
47
  return {
33
48
  "data-snap-component": component,
@@ -39,6 +54,19 @@ function space(token) {
39
54
  return `var(--snap-space-${token})`;
40
55
  }
41
56
  //#endregion
57
+ //#region lib/types/components/alert.js
58
+ /** An inline status banner for results and failures. */
59
+ function Alert({ intent = "neutral", className, children, ...props }) {
60
+ return jsx("div", {
61
+ role: "alert",
62
+ className: cn("snap-alert", className),
63
+ "data-intent": intent,
64
+ ...props,
65
+ ...part("alert", "root"),
66
+ children
67
+ });
68
+ }
69
+ //#endregion
42
70
  //#region lib/types/components/button.js
43
71
  /**
44
72
  * Semantic buttons: one behaviour, skin-owned visuals. The DOM exposes
@@ -90,7 +118,6 @@ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading =
90
118
  loading && jsx(Spinner, {})
91
119
  ] });
92
120
  return jsx(Component, {
93
- ...part("button", "root"),
94
121
  ...type !== void 0 ? { type } : !asChild ? { type: "button" } : {},
95
122
  className: cn("snap-button", className),
96
123
  "data-intent": intent,
@@ -101,13 +128,13 @@ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading =
101
128
  "aria-busy": loading || void 0,
102
129
  disabled: !asChild ? disabled === true || loading : void 0,
103
130
  ...props,
131
+ ...part("button", "root"),
104
132
  children: content
105
133
  });
106
134
  }
107
135
  /** A square glyph button with a mandatory accessible label. */
108
136
  function IconButton({ icon, label, active = false, intent = "neutral", emphasis = "ghost", size = "md", className, ...props }) {
109
137
  return jsx("button", {
110
- ...part("icon-button", "root"),
111
138
  type: "button",
112
139
  className: cn("snap-icon-button", className),
113
140
  "data-intent": intent,
@@ -117,6 +144,7 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
117
144
  "aria-label": label,
118
145
  "aria-pressed": active || void 0,
119
146
  ...props,
147
+ ...part("icon-button", "root"),
120
148
  children: jsx("span", {
121
149
  ...part("icon-button", "icon"),
122
150
  "aria-hidden": "true",
@@ -125,6 +153,124 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
125
153
  });
126
154
  }
127
155
  //#endregion
156
+ //#region lib/types/components/input.js
157
+ /** A single-line text field with semantic prefix/suffix slots. Layout
158
+ * `style`/`className` dress the wrapper — the visible control; the native
159
+ * field already stretches inside it. */
160
+ function Input({ size = "md", invalid = false, prefix, suffix, onClear, fieldClassName, componentName = "input", className, style, disabled, ...props }) {
161
+ return jsxs("div", {
162
+ ...part(componentName, "root"),
163
+ className: cn("snap-input", className),
164
+ style,
165
+ "data-size": size,
166
+ "data-invalid": invalid || void 0,
167
+ "data-disabled": disabled === true || void 0,
168
+ children: [
169
+ prefix !== void 0 && jsx("span", {
170
+ ...part(componentName, "prefix"),
171
+ children: prefix
172
+ }),
173
+ jsx("input", {
174
+ className: cn("snap-input-field", fieldClassName),
175
+ disabled,
176
+ "aria-invalid": invalid || void 0,
177
+ ...props,
178
+ ...part(componentName, "field")
179
+ }),
180
+ onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
181
+ ...part(componentName, "clear"),
182
+ type: "button",
183
+ className: "snap-input-clear",
184
+ "aria-label": "清除",
185
+ onClick: onClear,
186
+ children: "×"
187
+ }),
188
+ suffix !== void 0 && jsx("span", {
189
+ ...part(componentName, "suffix"),
190
+ children: suffix
191
+ })
192
+ ]
193
+ });
194
+ }
195
+ //#endregion
196
+ //#region lib/types/components/overlay.js
197
+ /** The tooltip provider; the runtime mounts one, pages only need it standalone. */
198
+ function TooltipProvider(props) {
199
+ return jsx(TooltipPrimitive.Provider, { ...props });
200
+ }
201
+ let toastRecords = [];
202
+ const toastListeners = /* @__PURE__ */ new Set();
203
+ function toastEmit() {
204
+ for (const listener of toastListeners) listener();
205
+ }
206
+ function toastDismiss(id) {
207
+ toastRecords = toastRecords.filter((record) => record.id !== id);
208
+ toastEmit();
209
+ }
210
+ /** The runtime-mounted viewport: renders the shared toast queue. Pages never
211
+ * mount this themselves — the runtime provides one per surface root. */
212
+ function Toaster(props) {
213
+ const records = useSyncExternalStore((onStoreChange) => {
214
+ toastListeners.add(onStoreChange);
215
+ return () => toastListeners.delete(onStoreChange);
216
+ }, () => toastRecords, () => toastRecords);
217
+ return jsxs(ToastPrimitive.Provider, {
218
+ ...props,
219
+ children: [records.map((record) => jsxs(ToastPrimitive.Root, {
220
+ ...part("toast", "root"),
221
+ className: "snap-toast",
222
+ "data-intent": record.intent ?? "neutral",
223
+ duration: record.duration ?? 5e3,
224
+ onOpenChange: (open) => {
225
+ if (!open) toastDismiss(record.id);
226
+ },
227
+ children: [
228
+ jsx(ToastTitle, { children: record.title }),
229
+ record.description !== void 0 && jsx(ToastDescription, { children: record.description }),
230
+ jsx(ToastClose, { "aria-label": "关闭" })
231
+ ]
232
+ }, record.id)), jsx(ToastViewport, {})]
233
+ });
234
+ }
235
+ /** A toast title with its part tag. */
236
+ function ToastTitle({ className, children, ...props }) {
237
+ return jsx(ToastPrimitive.Title, {
238
+ className: cn("snap-toast-title", className),
239
+ ...props,
240
+ ...part("toast", "title"),
241
+ children
242
+ });
243
+ }
244
+ /** A toast description with its part tag. */
245
+ function ToastDescription({ className, children, ...props }) {
246
+ return jsx(ToastPrimitive.Description, {
247
+ className: cn("snap-toast-description", className),
248
+ ...props,
249
+ ...part("toast", "description"),
250
+ children
251
+ });
252
+ }
253
+ /** A toast dismissal button. */
254
+ function ToastClose({ className, children, ...props }) {
255
+ return jsx(ToastPrimitive.Close, {
256
+ className: cn("snap-toast-close", className),
257
+ ...props,
258
+ ...part("toast", "close"),
259
+ children: children ?? jsx("span", {
260
+ "aria-hidden": "true",
261
+ children: "×"
262
+ })
263
+ });
264
+ }
265
+ /** The toast viewport; only the runtime's {@link Toaster} mounts one. */
266
+ function ToastViewport({ className, ...props }) {
267
+ return jsx(ToastPrimitive.Viewport, {
268
+ className: cn("snap-toast-viewport", className),
269
+ ...props,
270
+ ...part("toast", "viewport")
271
+ });
272
+ }
273
+ //#endregion
128
274
  //#region lib/types/components/dialog.js
129
275
  /**
130
276
  * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
@@ -142,11 +288,11 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
142
288
  ...part("dialog", "overlay"),
143
289
  className: "snap-dialog-overlay"
144
290
  }), jsxs(DialogPrimitive.Content, {
145
- ...part("dialog", "panel"),
146
291
  className: cn("snap-dialog-panel", className),
147
292
  "data-presentation": resolved,
148
293
  "data-size": size,
149
294
  ...rest,
295
+ ...part("dialog", "panel"),
150
296
  children: [children, showClose && jsx(DialogPrimitive.Close, {
151
297
  ...part("dialog", "close"),
152
298
  className: "snap-dialog-close",
@@ -198,40 +344,62 @@ function DialogFooter({ children, className }) {
198
344
  //#endregion
199
345
  //#region lib/types/components/controls.js
200
346
  /** The tabs root. */
201
- const Tabs = TabsPrimitive.Root;
347
+ function Tabs({ className, children, ...props }) {
348
+ return jsx(TabsPrimitive.Root, {
349
+ className: cn("snap-tabs", className),
350
+ ...props,
351
+ ...part("tabs", "root"),
352
+ children
353
+ });
354
+ }
202
355
  /** The tabs list. */
203
356
  function TabsList({ className, children, ...props }) {
204
357
  return jsx(TabsPrimitive.List, {
205
- ...part("tabs", "list"),
206
358
  className: cn("snap-tabs-list", className),
207
359
  ...props,
360
+ ...part("tabs", "list"),
208
361
  children
209
362
  });
210
363
  }
211
364
  /** A tab trigger. */
212
365
  function TabsTrigger({ className, children, ...props }) {
213
366
  return jsx(TabsPrimitive.Trigger, {
214
- ...part("tabs", "trigger"),
215
367
  className: cn("snap-tabs-trigger", className),
216
368
  ...props,
369
+ ...part("tabs", "trigger"),
217
370
  children
218
371
  });
219
372
  }
220
- /** A boolean switch. */
221
- function Switch({ className, label, ...props }) {
222
- return jsxs("label", {
373
+ /** A boolean switch with an optional label on either side. */
374
+ function Switch({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
375
+ const labelNode = label !== void 0 && jsx("span", {
376
+ ...part("switch", "label"),
377
+ children: label
378
+ });
379
+ const row = jsxs("label", {
223
380
  className: "snap-switch-label",
224
- children: [jsx(SwitchPrimitive.Root, {
225
- ...part("switch", "root"),
226
- className: cn("snap-switch", className),
227
- ...props,
228
- children: jsx(SwitchPrimitive.Thumb, {
229
- ...part("switch", "thumb"),
230
- className: "snap-switch-thumb"
231
- })
232
- }), label !== void 0 && jsx("span", {
233
- ...part("switch", "label"),
234
- children: label
381
+ children: [
382
+ labelPosition === "start" && labelNode,
383
+ jsx(SwitchPrimitive.Root, {
384
+ className: cn("snap-switch", className),
385
+ ...props,
386
+ ...part("switch", "root"),
387
+ children: jsx(SwitchPrimitive.Thumb, {
388
+ ...part("switch", "thumb"),
389
+ className: "snap-switch-thumb"
390
+ })
391
+ }),
392
+ labelPosition === "end" && labelNode
393
+ ]
394
+ });
395
+ if (description === void 0) return row;
396
+ return jsxs("span", {
397
+ ...part("switch", "field"),
398
+ className: cn("snap-switch-field", containerClassName),
399
+ children: [row, jsx("span", {
400
+ ...part("switch", "description"),
401
+ className: "snap-field-help",
402
+ children: description
235
403
  })]
236
404
  });
237
405
  }
@@ -271,46 +439,8 @@ function EmptyState({ title, description, icon, action, className }) {
271
439
  ]
272
440
  });
273
441
  }
274
- //#endregion
275
- //#region lib/types/components/input.js
276
- /** A single-line text field with semantic prefix/suffix slots. Layout
277
- * `style`/`className` dress the wrapper — the visible control; the native
278
- * field already stretches inside it. */
279
- function Input({ size = "md", invalid = false, prefix, suffix, onClear, componentName = "input", className, style, disabled, ...props }) {
280
- return jsxs("div", {
281
- ...part(componentName, "root"),
282
- className: cn("snap-input", className),
283
- style,
284
- "data-size": size,
285
- "data-invalid": invalid || void 0,
286
- "data-disabled": disabled === true || void 0,
287
- children: [
288
- prefix !== void 0 && jsx("span", {
289
- ...part(componentName, "prefix"),
290
- children: prefix
291
- }),
292
- jsx("input", {
293
- ...part(componentName, "field"),
294
- className: "snap-input-field",
295
- disabled,
296
- "aria-invalid": invalid || void 0,
297
- ...props
298
- }),
299
- onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
300
- ...part(componentName, "clear"),
301
- type: "button",
302
- className: "snap-input-clear",
303
- "aria-label": "清除",
304
- onClick: onClear,
305
- children: "×"
306
- }),
307
- suffix !== void 0 && jsx("span", {
308
- ...part(componentName, "suffix"),
309
- children: suffix
310
- })
311
- ]
312
- });
313
- }
442
+ createContext(null);
443
+ createContext(null);
314
444
  //#endregion
315
445
  //#region lib/types/components/layout.js
316
446
  /** A vertical flow. */
@@ -508,45 +638,45 @@ function Table({ className, children, ...props }) {
508
638
  /** The table head. */
509
639
  function TableHeader({ className, children, ...props }) {
510
640
  return jsx("thead", {
511
- ...part("table", "header"),
512
641
  className: cn("snap-table-header", className),
513
642
  ...props,
643
+ ...part("table", "header"),
514
644
  children
515
645
  });
516
646
  }
517
647
  /** The table body. */
518
648
  function TableBody({ className, children, ...props }) {
519
649
  return jsx("tbody", {
520
- ...part("table", "body"),
521
650
  className: cn("snap-table-body", className),
522
651
  ...props,
652
+ ...part("table", "body"),
523
653
  children
524
654
  });
525
655
  }
526
656
  /** A table row. */
527
657
  function TableRow({ className, children, ...props }) {
528
658
  return jsx("tr", {
529
- ...part("table", "row"),
530
659
  className: cn("snap-table-row", className),
531
660
  ...props,
661
+ ...part("table", "row"),
532
662
  children
533
663
  });
534
664
  }
535
665
  /** A table header cell. */
536
666
  function TableHead({ className, children, ...props }) {
537
667
  return jsx("th", {
538
- ...part("table", "head"),
539
668
  className: cn("snap-table-head", className),
540
669
  ...props,
670
+ ...part("table", "head"),
541
671
  children
542
672
  });
543
673
  }
544
674
  /** A table body cell. */
545
675
  function TableCell({ className, children, ...props }) {
546
676
  return jsx("td", {
547
- ...part("table", "cell"),
548
677
  className: cn("snap-table-cell", className),
549
678
  ...props,
679
+ ...part("table", "cell"),
550
680
  children
551
681
  });
552
682
  }
@@ -1402,9 +1532,8 @@ function AppearancePage() {
1402
1532
  children: jsxs(Stack, {
1403
1533
  gap: "lg",
1404
1534
  children: [
1405
- error !== void 0 && jsx("div", {
1406
- role: "alert",
1407
- style: { color: "var(--snap-color-danger)" },
1535
+ error !== void 0 && jsx(Alert, {
1536
+ intent: "danger",
1408
1537
  children: error
1409
1538
  }),
1410
1539
  jsx(Section, {
@@ -1988,9 +2117,8 @@ function PluginsPage({ ctx }) {
1988
2117
  children: [
1989
2118
  jsxs(Stack, {
1990
2119
  gap: "lg",
1991
- children: [error !== void 0 && jsx("div", {
1992
- role: "alert",
1993
- style: { color: "var(--snap-color-danger)" },
2120
+ children: [error !== void 0 && jsx(Alert, {
2121
+ intent: "danger",
1994
2122
  children: error
1995
2123
  }), rows.length === 0 ? jsx(EmptyState, {
1996
2124
  title: "还没有安装插件",
@@ -2844,7 +2972,7 @@ function SettingsFallbackHost(props) {
2844
2972
  /** The operator-window root. */
2845
2973
  function MainRoot(props) {
2846
2974
  const layout = useActiveLayout();
2847
- return jsxs(Fragment, { children: [
2975
+ return jsx(Fragment, { children: jsxs(TooltipProvider, { children: [
2848
2976
  jsx(StageProfiles, {
2849
2977
  ctx: props.ctx,
2850
2978
  layout
@@ -2854,8 +2982,9 @@ function MainRoot(props) {
2854
2982
  children: "没有已加载的布局插件。"
2855
2983
  }) : layout.render(),
2856
2984
  jsx(OverlayHost, { ctx: props.ctx }),
2857
- jsx(SettingsFallbackHost, { ctx: props.ctx })
2858
- ] });
2985
+ jsx(SettingsFallbackHost, { ctx: props.ctx }),
2986
+ jsx(Toaster, {})
2987
+ ] }) });
2859
2988
  }
2860
2989
  /**
2861
2990
  * The fallback ball face used when no plugin occupies `shell.ball`: a themed
@@ -2881,13 +3010,13 @@ function BallRoot(props) {
2881
3010
  }
2882
3011
  });
2883
3012
  }, [hasOccupant, link]);
2884
- if (occupant !== void 0) return jsx("div", {
3013
+ if (occupant !== void 0) return jsxs(TooltipProvider, { children: [jsx("div", {
2885
3014
  style: {
2886
3015
  width: "100%",
2887
3016
  height: "100%"
2888
3017
  },
2889
3018
  children: occupant.render({ surface: "ball" })
2890
- });
3019
+ }), jsx(Toaster, {})] });
2891
3020
  return jsx("div", {
2892
3021
  ref: rootRef,
2893
3022
  "data-snap-part": "ball.root",