@snap-rail/ui 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/runtime.js CHANGED
@@ -9,6 +9,10 @@ import { Component, createContext, useContext, useEffect, useRef, useState, useS
9
9
  import { createRoot } from "react-dom/client";
10
10
  import "@radix-ui/react-separator";
11
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 TooltipPrimitive from "@radix-ui/react-tooltip";
15
+ import { Toaster } from "sonner";
12
16
  import "@radix-ui/react-checkbox";
13
17
  import "@radix-ui/react-label";
14
18
  import "@radix-ui/react-radio-group";
@@ -19,10 +23,6 @@ import * as DialogPrimitive from "@radix-ui/react-dialog";
19
23
  import "react-hook-form";
20
24
  import "@hookform/resolvers/zod";
21
25
  import "@radix-ui/react-scroll-area";
22
- import "@radix-ui/react-dropdown-menu";
23
- import "@radix-ui/react-popover";
24
- import * as ToastPrimitive from "@radix-ui/react-toast";
25
- import * as TooltipPrimitive from "@radix-ui/react-tooltip";
26
26
  import "@radix-ui/react-slider";
27
27
  import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
28
28
  //#region lib/types/utils.js
@@ -36,7 +36,13 @@ import { PLUGINS_FEED_URLS_KEY } from "@snap-rail/app-boot/contract";
36
36
  function cn(...values) {
37
37
  return values.filter((value) => typeof value === "string" && value.length > 0).join(" ");
38
38
  }
39
- /** 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
+ */
40
46
  function part(component, name) {
41
47
  return {
42
48
  "data-snap-component": component,
@@ -52,11 +58,11 @@ function space(token) {
52
58
  /** An inline status banner for results and failures. */
53
59
  function Alert({ intent = "neutral", className, children, ...props }) {
54
60
  return jsx("div", {
55
- ...part("alert", "root"),
56
61
  role: "alert",
57
62
  className: cn("snap-alert", className),
58
63
  "data-intent": intent,
59
64
  ...props,
65
+ ...part("alert", "root"),
60
66
  children
61
67
  });
62
68
  }
@@ -112,7 +118,6 @@ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading =
112
118
  loading && jsx(Spinner, {})
113
119
  ] });
114
120
  return jsx(Component, {
115
- ...part("button", "root"),
116
121
  ...type !== void 0 ? { type } : !asChild ? { type: "button" } : {},
117
122
  className: cn("snap-button", className),
118
123
  "data-intent": intent,
@@ -123,13 +128,13 @@ function Button({ intent = "neutral", emphasis = "solid", size = "md", loading =
123
128
  "aria-busy": loading || void 0,
124
129
  disabled: !asChild ? disabled === true || loading : void 0,
125
130
  ...props,
131
+ ...part("button", "root"),
126
132
  children: content
127
133
  });
128
134
  }
129
135
  /** A square glyph button with a mandatory accessible label. */
130
136
  function IconButton({ icon, label, active = false, intent = "neutral", emphasis = "ghost", size = "md", className, ...props }) {
131
137
  return jsx("button", {
132
- ...part("icon-button", "root"),
133
138
  type: "button",
134
139
  className: cn("snap-icon-button", className),
135
140
  "data-intent": intent,
@@ -139,6 +144,7 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
139
144
  "aria-label": label,
140
145
  "aria-pressed": active || void 0,
141
146
  ...props,
147
+ ...part("icon-button", "root"),
142
148
  children: jsx("span", {
143
149
  ...part("icon-button", "icon"),
144
150
  "aria-hidden": "true",
@@ -147,6 +153,93 @@ function IconButton({ icon, label, active = false, intent = "neutral", emphasis
147
153
  });
148
154
  }
149
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
+ jsxs(Fragment, { children: [
202
+ jsx("circle", {
203
+ cx: "12",
204
+ cy: "12",
205
+ r: "10"
206
+ }),
207
+ jsx("path", { d: "M12 16v-4" }),
208
+ jsx("path", { d: "M12 8h.01" })
209
+ ] }), jsxs(Fragment, { children: [
210
+ jsx("circle", {
211
+ cx: "12",
212
+ cy: "12",
213
+ r: "10"
214
+ }),
215
+ jsx("path", { d: "M12 16v-4" }),
216
+ jsx("path", { d: "M12 8h.01" })
217
+ ] }), jsxs(Fragment, { children: [jsx("circle", {
218
+ cx: "12",
219
+ cy: "12",
220
+ r: "10"
221
+ }), jsx("path", { d: "m9 12 2 2 4-4" })] }), jsxs(Fragment, { children: [
222
+ jsx("path", { d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z" }),
223
+ jsx("path", { d: "M12 9v4" }),
224
+ jsx("path", { d: "M12 17h.01" })
225
+ ] }), jsxs(Fragment, { children: [
226
+ jsx("circle", {
227
+ cx: "12",
228
+ cy: "12",
229
+ r: "10"
230
+ }),
231
+ jsx("path", { d: "m15 9-6 6" }),
232
+ jsx("path", { d: "m9 9 6 6" })
233
+ ] });
234
+ /** The runtime-mounted viewport: renders the shared toast queue. Pages never
235
+ * mount this themselves — the runtime provides one per surface root. */
236
+ function Toaster$1() {
237
+ return jsx(Toaster, {
238
+ position: "bottom-right",
239
+ closeButton: true
240
+ });
241
+ }
242
+ //#endregion
150
243
  //#region lib/types/components/dialog.js
151
244
  /**
152
245
  * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
@@ -164,11 +257,11 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
164
257
  ...part("dialog", "overlay"),
165
258
  className: "snap-dialog-overlay"
166
259
  }), jsxs(DialogPrimitive.Content, {
167
- ...part("dialog", "panel"),
168
260
  className: cn("snap-dialog-panel", className),
169
261
  "data-presentation": resolved,
170
262
  "data-size": size,
171
263
  ...rest,
264
+ ...part("dialog", "panel"),
172
265
  children: [children, showClose && jsx(DialogPrimitive.Close, {
173
266
  ...part("dialog", "close"),
174
267
  className: "snap-dialog-close",
@@ -222,27 +315,27 @@ function DialogFooter({ children, className }) {
222
315
  /** The tabs root. */
223
316
  function Tabs({ className, children, ...props }) {
224
317
  return jsx(TabsPrimitive.Root, {
225
- ...part("tabs", "root"),
226
318
  className: cn("snap-tabs", className),
227
319
  ...props,
320
+ ...part("tabs", "root"),
228
321
  children
229
322
  });
230
323
  }
231
324
  /** The tabs list. */
232
325
  function TabsList({ className, children, ...props }) {
233
326
  return jsx(TabsPrimitive.List, {
234
- ...part("tabs", "list"),
235
327
  className: cn("snap-tabs-list", className),
236
328
  ...props,
329
+ ...part("tabs", "list"),
237
330
  children
238
331
  });
239
332
  }
240
333
  /** A tab trigger. */
241
334
  function TabsTrigger({ className, children, ...props }) {
242
335
  return jsx(TabsPrimitive.Trigger, {
243
- ...part("tabs", "trigger"),
244
336
  className: cn("snap-tabs-trigger", className),
245
337
  ...props,
338
+ ...part("tabs", "trigger"),
246
339
  children
247
340
  });
248
341
  }
@@ -257,9 +350,9 @@ function Switch({ className, label, labelPosition = "end", description, containe
257
350
  children: [
258
351
  labelPosition === "start" && labelNode,
259
352
  jsx(SwitchPrimitive.Root, {
260
- ...part("switch", "root"),
261
353
  className: cn("snap-switch", className),
262
354
  ...props,
355
+ ...part("switch", "root"),
263
356
  children: jsx(SwitchPrimitive.Thumb, {
264
357
  ...part("switch", "thumb"),
265
358
  className: "snap-switch-thumb"
@@ -318,46 +411,6 @@ function EmptyState({ title, description, icon, action, className }) {
318
411
  createContext(null);
319
412
  createContext(null);
320
413
  //#endregion
321
- //#region lib/types/components/input.js
322
- /** A single-line text field with semantic prefix/suffix slots. Layout
323
- * `style`/`className` dress the wrapper — the visible control; the native
324
- * field already stretches inside it. */
325
- function Input({ size = "md", invalid = false, prefix, suffix, onClear, fieldClassName, componentName = "input", className, style, disabled, ...props }) {
326
- return jsxs("div", {
327
- ...part(componentName, "root"),
328
- className: cn("snap-input", className),
329
- style,
330
- "data-size": size,
331
- "data-invalid": invalid || void 0,
332
- "data-disabled": disabled === true || void 0,
333
- children: [
334
- prefix !== void 0 && jsx("span", {
335
- ...part(componentName, "prefix"),
336
- children: prefix
337
- }),
338
- jsx("input", {
339
- ...part(componentName, "field"),
340
- className: cn("snap-input-field", fieldClassName),
341
- disabled,
342
- "aria-invalid": invalid || void 0,
343
- ...props
344
- }),
345
- onClear !== void 0 && typeof props.value === "string" && props.value !== "" && jsx("button", {
346
- ...part(componentName, "clear"),
347
- type: "button",
348
- className: "snap-input-clear",
349
- "aria-label": "清除",
350
- onClick: onClear,
351
- children: "×"
352
- }),
353
- suffix !== void 0 && jsx("span", {
354
- ...part(componentName, "suffix"),
355
- children: suffix
356
- })
357
- ]
358
- });
359
- }
360
- //#endregion
361
414
  //#region lib/types/components/layout.js
362
415
  /** A vertical flow. */
363
416
  function Stack({ gap = "md", padding, align, className, style, children }) {
@@ -539,84 +592,6 @@ function Section({ title, description, actions, className, style, children }) {
539
592
  });
540
593
  }
541
594
  //#endregion
542
- //#region lib/types/components/overlay.js
543
- /** The tooltip provider; the runtime mounts one, pages only need it standalone. */
544
- function TooltipProvider(props) {
545
- return jsx(TooltipPrimitive.Provider, { ...props });
546
- }
547
- let toastRecords = [];
548
- const toastListeners = /* @__PURE__ */ new Set();
549
- function toastEmit() {
550
- for (const listener of toastListeners) listener();
551
- }
552
- function toastDismiss(id) {
553
- toastRecords = toastRecords.filter((record) => record.id !== id);
554
- toastEmit();
555
- }
556
- /** The runtime-mounted viewport: renders the shared toast queue. Pages never
557
- * mount this themselves — the runtime provides one per surface root. */
558
- function Toaster(props) {
559
- const records = useSyncExternalStore((onStoreChange) => {
560
- toastListeners.add(onStoreChange);
561
- return () => toastListeners.delete(onStoreChange);
562
- }, () => toastRecords, () => toastRecords);
563
- return jsxs(ToastPrimitive.Provider, {
564
- ...props,
565
- children: [records.map((record) => jsxs(ToastPrimitive.Root, {
566
- ...part("toast", "root"),
567
- className: "snap-toast",
568
- "data-intent": record.intent ?? "neutral",
569
- duration: record.duration ?? 5e3,
570
- onOpenChange: (open) => {
571
- if (!open) toastDismiss(record.id);
572
- },
573
- children: [
574
- jsx(ToastTitle, { children: record.title }),
575
- record.description !== void 0 && jsx(ToastDescription, { children: record.description }),
576
- jsx(ToastClose, { "aria-label": "关闭" })
577
- ]
578
- }, record.id)), jsx(ToastViewport, {})]
579
- });
580
- }
581
- /** A toast title with its part tag. */
582
- function ToastTitle({ className, children, ...props }) {
583
- return jsx(ToastPrimitive.Title, {
584
- ...part("toast", "title"),
585
- className: cn("snap-toast-title", className),
586
- ...props,
587
- children
588
- });
589
- }
590
- /** A toast description with its part tag. */
591
- function ToastDescription({ className, children, ...props }) {
592
- return jsx(ToastPrimitive.Description, {
593
- ...part("toast", "description"),
594
- className: cn("snap-toast-description", className),
595
- ...props,
596
- children
597
- });
598
- }
599
- /** A toast dismissal button. */
600
- function ToastClose({ className, children, ...props }) {
601
- return jsx(ToastPrimitive.Close, {
602
- ...part("toast", "close"),
603
- className: cn("snap-toast-close", className),
604
- ...props,
605
- children: children ?? jsx("span", {
606
- "aria-hidden": "true",
607
- children: "×"
608
- })
609
- });
610
- }
611
- /** The toast viewport; only the runtime's {@link Toaster} mounts one. */
612
- function ToastViewport({ className, ...props }) {
613
- return jsx(ToastPrimitive.Viewport, {
614
- ...part("toast", "viewport"),
615
- className: cn("snap-toast-viewport", className),
616
- ...props
617
- });
618
- }
619
- //#endregion
620
595
  //#region lib/types/components/surface.js
621
596
  /** A semantic table. */
622
597
  function Table({ className, children, ...props }) {
@@ -632,45 +607,45 @@ function Table({ className, children, ...props }) {
632
607
  /** The table head. */
633
608
  function TableHeader({ className, children, ...props }) {
634
609
  return jsx("thead", {
635
- ...part("table", "header"),
636
610
  className: cn("snap-table-header", className),
637
611
  ...props,
612
+ ...part("table", "header"),
638
613
  children
639
614
  });
640
615
  }
641
616
  /** The table body. */
642
617
  function TableBody({ className, children, ...props }) {
643
618
  return jsx("tbody", {
644
- ...part("table", "body"),
645
619
  className: cn("snap-table-body", className),
646
620
  ...props,
621
+ ...part("table", "body"),
647
622
  children
648
623
  });
649
624
  }
650
625
  /** A table row. */
651
626
  function TableRow({ className, children, ...props }) {
652
627
  return jsx("tr", {
653
- ...part("table", "row"),
654
628
  className: cn("snap-table-row", className),
655
629
  ...props,
630
+ ...part("table", "row"),
656
631
  children
657
632
  });
658
633
  }
659
634
  /** A table header cell. */
660
635
  function TableHead({ className, children, ...props }) {
661
636
  return jsx("th", {
662
- ...part("table", "head"),
663
637
  className: cn("snap-table-head", className),
664
638
  ...props,
639
+ ...part("table", "head"),
665
640
  children
666
641
  });
667
642
  }
668
643
  /** A table body cell. */
669
644
  function TableCell({ className, children, ...props }) {
670
645
  return jsx("td", {
671
- ...part("table", "cell"),
672
646
  className: cn("snap-table-cell", className),
673
647
  ...props,
648
+ ...part("table", "cell"),
674
649
  children
675
650
  });
676
651
  }
@@ -2977,7 +2952,7 @@ function MainRoot(props) {
2977
2952
  }) : layout.render(),
2978
2953
  jsx(OverlayHost, { ctx: props.ctx }),
2979
2954
  jsx(SettingsFallbackHost, { ctx: props.ctx }),
2980
- jsx(Toaster, {})
2955
+ jsx(Toaster$1, {})
2981
2956
  ] }) });
2982
2957
  }
2983
2958
  /**
@@ -3010,7 +2985,7 @@ function BallRoot(props) {
3010
2985
  height: "100%"
3011
2986
  },
3012
2987
  children: occupant.render({ surface: "ball" })
3013
- }), jsx(Toaster, {})] });
2988
+ }), jsx(Toaster$1, {})] });
3014
2989
  return jsx("div", {
3015
2990
  ref: rootRef,
3016
2991
  "data-snap-part": "ball.root",