@snap-rail/ui 0.2.0 → 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.
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 ToastPrimitive from "@radix-ui/react-toast";
15
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
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,124 @@ 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
+ 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
150
274
  //#region lib/types/components/dialog.js
151
275
  /**
152
276
  * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
@@ -164,11 +288,11 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
164
288
  ...part("dialog", "overlay"),
165
289
  className: "snap-dialog-overlay"
166
290
  }), jsxs(DialogPrimitive.Content, {
167
- ...part("dialog", "panel"),
168
291
  className: cn("snap-dialog-panel", className),
169
292
  "data-presentation": resolved,
170
293
  "data-size": size,
171
294
  ...rest,
295
+ ...part("dialog", "panel"),
172
296
  children: [children, showClose && jsx(DialogPrimitive.Close, {
173
297
  ...part("dialog", "close"),
174
298
  className: "snap-dialog-close",
@@ -222,27 +346,27 @@ function DialogFooter({ children, className }) {
222
346
  /** The tabs root. */
223
347
  function Tabs({ className, children, ...props }) {
224
348
  return jsx(TabsPrimitive.Root, {
225
- ...part("tabs", "root"),
226
349
  className: cn("snap-tabs", className),
227
350
  ...props,
351
+ ...part("tabs", "root"),
228
352
  children
229
353
  });
230
354
  }
231
355
  /** The tabs list. */
232
356
  function TabsList({ className, children, ...props }) {
233
357
  return jsx(TabsPrimitive.List, {
234
- ...part("tabs", "list"),
235
358
  className: cn("snap-tabs-list", className),
236
359
  ...props,
360
+ ...part("tabs", "list"),
237
361
  children
238
362
  });
239
363
  }
240
364
  /** A tab trigger. */
241
365
  function TabsTrigger({ className, children, ...props }) {
242
366
  return jsx(TabsPrimitive.Trigger, {
243
- ...part("tabs", "trigger"),
244
367
  className: cn("snap-tabs-trigger", className),
245
368
  ...props,
369
+ ...part("tabs", "trigger"),
246
370
  children
247
371
  });
248
372
  }
@@ -257,9 +381,9 @@ function Switch({ className, label, labelPosition = "end", description, containe
257
381
  children: [
258
382
  labelPosition === "start" && labelNode,
259
383
  jsx(SwitchPrimitive.Root, {
260
- ...part("switch", "root"),
261
384
  className: cn("snap-switch", className),
262
385
  ...props,
386
+ ...part("switch", "root"),
263
387
  children: jsx(SwitchPrimitive.Thumb, {
264
388
  ...part("switch", "thumb"),
265
389
  className: "snap-switch-thumb"
@@ -318,46 +442,6 @@ function EmptyState({ title, description, icon, action, className }) {
318
442
  createContext(null);
319
443
  createContext(null);
320
444
  //#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
445
  //#region lib/types/components/layout.js
362
446
  /** A vertical flow. */
363
447
  function Stack({ gap = "md", padding, align, className, style, children }) {
@@ -539,84 +623,6 @@ function Section({ title, description, actions, className, style, children }) {
539
623
  });
540
624
  }
541
625
  //#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
626
  //#region lib/types/components/surface.js
621
627
  /** A semantic table. */
622
628
  function Table({ className, children, ...props }) {
@@ -632,45 +638,45 @@ function Table({ className, children, ...props }) {
632
638
  /** The table head. */
633
639
  function TableHeader({ className, children, ...props }) {
634
640
  return jsx("thead", {
635
- ...part("table", "header"),
636
641
  className: cn("snap-table-header", className),
637
642
  ...props,
643
+ ...part("table", "header"),
638
644
  children
639
645
  });
640
646
  }
641
647
  /** The table body. */
642
648
  function TableBody({ className, children, ...props }) {
643
649
  return jsx("tbody", {
644
- ...part("table", "body"),
645
650
  className: cn("snap-table-body", className),
646
651
  ...props,
652
+ ...part("table", "body"),
647
653
  children
648
654
  });
649
655
  }
650
656
  /** A table row. */
651
657
  function TableRow({ className, children, ...props }) {
652
658
  return jsx("tr", {
653
- ...part("table", "row"),
654
659
  className: cn("snap-table-row", className),
655
660
  ...props,
661
+ ...part("table", "row"),
656
662
  children
657
663
  });
658
664
  }
659
665
  /** A table header cell. */
660
666
  function TableHead({ className, children, ...props }) {
661
667
  return jsx("th", {
662
- ...part("table", "head"),
663
668
  className: cn("snap-table-head", className),
664
669
  ...props,
670
+ ...part("table", "head"),
665
671
  children
666
672
  });
667
673
  }
668
674
  /** A table body cell. */
669
675
  function TableCell({ className, children, ...props }) {
670
676
  return jsx("td", {
671
- ...part("table", "cell"),
672
677
  className: cn("snap-table-cell", className),
673
678
  ...props,
679
+ ...part("table", "cell"),
674
680
  children
675
681
  });
676
682
  }