@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/settings.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Component, createContext, useContext, useEffect, useState, useSyncExternalStore } from "react";
3
+ import "@radix-ui/react-separator";
3
4
  import { Slot } from "@radix-ui/react-slot";
5
+ import "@radix-ui/react-dropdown-menu";
6
+ import "@radix-ui/react-popover";
7
+ import "@radix-ui/react-toast";
8
+ import "@radix-ui/react-tooltip";
4
9
  import "@radix-ui/react-checkbox";
5
10
  import "@radix-ui/react-label";
6
11
  import "@radix-ui/react-radio-group";
@@ -8,6 +13,10 @@ import "@radix-ui/react-select";
8
13
  import * as SwitchPrimitive from "@radix-ui/react-switch";
9
14
  import * as TabsPrimitive from "@radix-ui/react-tabs";
10
15
  import * as DialogPrimitive from "@radix-ui/react-dialog";
16
+ import "react-hook-form";
17
+ import "@hookform/resolvers/zod";
18
+ import "@radix-ui/react-scroll-area";
19
+ import "@radix-ui/react-slider";
11
20
  import { rpcErrorText } from "@snap-rail/connection";
12
21
  import "@snap-rail/client-kernel";
13
22
  import "@snap-rail/station-rpc/contract";
@@ -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,46 @@ 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
128
196
  //#region lib/types/components/dialog.js
129
197
  /**
130
198
  * Dialog/sheet semantics over Radix's focus trap and portal. The skin chooses
@@ -142,11 +210,11 @@ function DialogContent({ children, className, presentation = "auto", size = "md"
142
210
  ...part("dialog", "overlay"),
143
211
  className: "snap-dialog-overlay"
144
212
  }), jsxs(DialogPrimitive.Content, {
145
- ...part("dialog", "panel"),
146
213
  className: cn("snap-dialog-panel", className),
147
214
  "data-presentation": resolved,
148
215
  "data-size": size,
149
216
  ...rest,
217
+ ...part("dialog", "panel"),
150
218
  children: [children, showClose && jsx(DialogPrimitive.Close, {
151
219
  ...part("dialog", "close"),
152
220
  className: "snap-dialog-close",
@@ -198,40 +266,62 @@ function DialogFooter({ children, className }) {
198
266
  //#endregion
199
267
  //#region lib/types/components/controls.js
200
268
  /** The tabs root. */
201
- const Tabs = TabsPrimitive.Root;
269
+ function Tabs({ className, children, ...props }) {
270
+ return jsx(TabsPrimitive.Root, {
271
+ className: cn("snap-tabs", className),
272
+ ...props,
273
+ ...part("tabs", "root"),
274
+ children
275
+ });
276
+ }
202
277
  /** The tabs list. */
203
278
  function TabsList({ className, children, ...props }) {
204
279
  return jsx(TabsPrimitive.List, {
205
- ...part("tabs", "list"),
206
280
  className: cn("snap-tabs-list", className),
207
281
  ...props,
282
+ ...part("tabs", "list"),
208
283
  children
209
284
  });
210
285
  }
211
286
  /** A tab trigger. */
212
287
  function TabsTrigger({ className, children, ...props }) {
213
288
  return jsx(TabsPrimitive.Trigger, {
214
- ...part("tabs", "trigger"),
215
289
  className: cn("snap-tabs-trigger", className),
216
290
  ...props,
291
+ ...part("tabs", "trigger"),
217
292
  children
218
293
  });
219
294
  }
220
- /** A boolean switch. */
221
- function Switch({ className, label, ...props }) {
222
- return jsxs("label", {
295
+ /** A boolean switch with an optional label on either side. */
296
+ function Switch({ className, label, labelPosition = "end", description, containerClassName, ...props }) {
297
+ const labelNode = label !== void 0 && jsx("span", {
298
+ ...part("switch", "label"),
299
+ children: label
300
+ });
301
+ const row = jsxs("label", {
223
302
  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
303
+ children: [
304
+ labelPosition === "start" && labelNode,
305
+ jsx(SwitchPrimitive.Root, {
306
+ className: cn("snap-switch", className),
307
+ ...props,
308
+ ...part("switch", "root"),
309
+ children: jsx(SwitchPrimitive.Thumb, {
310
+ ...part("switch", "thumb"),
311
+ className: "snap-switch-thumb"
312
+ })
313
+ }),
314
+ labelPosition === "end" && labelNode
315
+ ]
316
+ });
317
+ if (description === void 0) return row;
318
+ return jsxs("span", {
319
+ ...part("switch", "field"),
320
+ className: cn("snap-switch-field", containerClassName),
321
+ children: [row, jsx("span", {
322
+ ...part("switch", "description"),
323
+ className: "snap-field-help",
324
+ children: description
235
325
  })]
236
326
  });
237
327
  }
@@ -271,46 +361,8 @@ function EmptyState({ title, description, icon, action, className }) {
271
361
  ]
272
362
  });
273
363
  }
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
- }
364
+ createContext(null);
365
+ createContext(null);
314
366
  //#endregion
315
367
  //#region lib/types/components/layout.js
316
368
  /** A vertical flow. */
@@ -458,45 +510,45 @@ function Table({ className, children, ...props }) {
458
510
  /** The table head. */
459
511
  function TableHeader({ className, children, ...props }) {
460
512
  return jsx("thead", {
461
- ...part("table", "header"),
462
513
  className: cn("snap-table-header", className),
463
514
  ...props,
515
+ ...part("table", "header"),
464
516
  children
465
517
  });
466
518
  }
467
519
  /** The table body. */
468
520
  function TableBody({ className, children, ...props }) {
469
521
  return jsx("tbody", {
470
- ...part("table", "body"),
471
522
  className: cn("snap-table-body", className),
472
523
  ...props,
524
+ ...part("table", "body"),
473
525
  children
474
526
  });
475
527
  }
476
528
  /** A table row. */
477
529
  function TableRow({ className, children, ...props }) {
478
530
  return jsx("tr", {
479
- ...part("table", "row"),
480
531
  className: cn("snap-table-row", className),
481
532
  ...props,
533
+ ...part("table", "row"),
482
534
  children
483
535
  });
484
536
  }
485
537
  /** A table header cell. */
486
538
  function TableHead({ className, children, ...props }) {
487
539
  return jsx("th", {
488
- ...part("table", "head"),
489
540
  className: cn("snap-table-head", className),
490
541
  ...props,
542
+ ...part("table", "head"),
491
543
  children
492
544
  });
493
545
  }
494
546
  /** A table body cell. */
495
547
  function TableCell({ className, children, ...props }) {
496
548
  return jsx("td", {
497
- ...part("table", "cell"),
498
549
  className: cn("snap-table-cell", className),
499
550
  ...props,
551
+ ...part("table", "cell"),
500
552
  children
501
553
  });
502
554
  }
@@ -705,9 +757,8 @@ function AppearancePage() {
705
757
  children: jsxs(Stack, {
706
758
  gap: "lg",
707
759
  children: [
708
- error !== void 0 && jsx("div", {
709
- role: "alert",
710
- style: { color: "var(--snap-color-danger)" },
760
+ error !== void 0 && jsx(Alert, {
761
+ intent: "danger",
711
762
  children: error
712
763
  }),
713
764
  jsx(Section, {
@@ -1291,9 +1342,8 @@ function PluginsPage({ ctx }) {
1291
1342
  children: [
1292
1343
  jsxs(Stack, {
1293
1344
  gap: "lg",
1294
- children: [error !== void 0 && jsx("div", {
1295
- role: "alert",
1296
- style: { color: "var(--snap-color-danger)" },
1345
+ children: [error !== void 0 && jsx(Alert, {
1346
+ intent: "danger",
1297
1347
  children: error
1298
1348
  }), rows.length === 0 ? jsx(EmptyState, {
1299
1349
  title: "还没有安装插件",
@@ -24,7 +24,7 @@ export interface ChartFrameProps {
24
24
  }
25
25
  /** A semantic frame for a chart, gauge, map, or custom visualization. */
26
26
  export declare function ChartFrame({ title, description, actions, state, empty, error, loading, children, className, style, }: ChartFrameProps): ReactNode;
27
- /** A chart frame that exposes the `visualization.*` anatomy as well. */
27
+ /** An alias of {@link ChartFrame} for pages that prefer the generic name. */
28
28
  export declare function Visualization(props: ChartFrameProps): ReactNode;
29
29
  /** The theme object ECharts/D3 adapters can consume. */
30
30
  export interface ChartTheme {
@@ -3,15 +3,15 @@ import { cn, part } from "./utils.js";
3
3
  import { useSkinTokens } from "./skins.js";
4
4
  /** A semantic frame for a chart, gauge, map, or custom visualization. */
5
5
  export function ChartFrame({ title, description, actions, state = 'ready', empty, error, loading, children, className, style, }) {
6
- return (_jsxs("section", { ...part('chart-frame', 'root'), className: cn('snap-chart-frame', className), "data-state": state, style: style, children: [(title !== undefined || description !== undefined || actions !== undefined) && (_jsxs("header", { ...part('chart-frame', 'header'), className: "snap-chart-frame-header", children: [_jsxs("div", { children: [title !== undefined && _jsx("div", { ...part('chart-frame', 'title'), children: title }), description !== undefined && _jsx("div", { className: "snap-chart-frame-description", children: description })] }), actions !== undefined && _jsx("div", { ...part('chart-frame', 'actions'), children: actions })] })), _jsx("div", { ...part('chart-frame', 'body'), className: "snap-chart-frame-body", "data-state": state, children: state === 'loading'
7
- ? loading ?? _jsx("div", { ...part('visualization', 'loading'), children: "\u52A0\u8F7D\u4E2D\u2026" })
6
+ return (_jsxs("section", { ...part('chart-frame', 'root'), className: cn('snap-chart-frame', className), "data-state": state, style: style, children: [(title !== undefined || description !== undefined || actions !== undefined) && (_jsxs("header", { ...part('chart-frame', 'header'), className: "snap-chart-frame-header", children: [_jsxs("div", { children: [title !== undefined && _jsx("div", { ...part('chart-frame', 'title'), children: title }), description !== undefined && _jsx("div", { ...part('chart-frame', 'description'), className: "snap-chart-frame-description", children: description })] }), actions !== undefined && _jsx("div", { ...part('chart-frame', 'actions'), children: actions })] })), _jsx("div", { ...part('chart-frame', 'body'), className: "snap-chart-frame-body", "data-state": state, children: state === 'loading'
7
+ ? loading ?? _jsx("div", { ...part('chart-frame', 'loading'), children: "\u52A0\u8F7D\u4E2D\u2026" })
8
8
  : state === 'empty'
9
- ? empty ?? _jsx("div", { ...part('visualization', 'empty'), children: "\u6682\u65E0\u6570\u636E" })
9
+ ? empty ?? _jsx("div", { ...part('chart-frame', 'empty'), children: "\u6682\u65E0\u6570\u636E" })
10
10
  : state === 'error'
11
- ? error ?? _jsx("div", { ...part('visualization', 'error'), role: "alert", children: "\u56FE\u8868\u52A0\u8F7D\u5931\u8D25" })
11
+ ? error ?? _jsx("div", { ...part('chart-frame', 'error'), role: "alert", children: "\u56FE\u8868\u52A0\u8F7D\u5931\u8D25" })
12
12
  : children })] }));
13
13
  }
14
- /** A chart frame that exposes the `visualization.*` anatomy as well. */
14
+ /** An alias of {@link ChartFrame} for pages that prefer the generic name. */
15
15
  export function Visualization(props) {
16
16
  return _jsx(ChartFrame, { ...props });
17
17
  }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Attention surfaces: alerts (inline banners), separators, skeletons, and
3
+ * lists. Read-only primitives; the skin owns their visuals through the
4
+ * `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
5
+ *
6
+ * @module @snap-rail/ui/components/alert
7
+ */
8
+ import * as SeparatorPrimitive from '@radix-ui/react-separator';
9
+ import type { ComponentPropsWithoutRef, ReactNode } from 'react';
10
+ import type { ButtonIntent } from './button.tsx';
11
+ /** Props of {@link Alert}. */
12
+ export interface AlertProps extends ComponentPropsWithoutRef<'div'> {
13
+ /** The semantic tone; the skin maps it to colour like a button intent. */
14
+ intent?: ButtonIntent;
15
+ }
16
+ /** An inline status banner for results and failures. */
17
+ export declare function Alert({ intent, className, children, ...props }: AlertProps): ReactNode;
18
+ /** The alert heading line. */
19
+ export declare function AlertTitle({ className, children, ...props }: ComponentPropsWithoutRef<'h5'>): ReactNode;
20
+ /** The alert body text. */
21
+ export declare function AlertDescription({ className, children, ...props }: ComponentPropsWithoutRef<'div'>): ReactNode;
22
+ /** Props of {@link Separator}. */
23
+ export interface SeparatorProps extends ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root> {
24
+ orientation?: 'horizontal' | 'vertical';
25
+ }
26
+ /** A themed rule between sections. */
27
+ export declare function Separator({ orientation, className, ...props }: SeparatorProps): ReactNode;
28
+ /** Props of {@link Skeleton}. */
29
+ export interface SkeletonProps extends ComponentPropsWithoutRef<'div'> {
30
+ /** The shape variant; `text` matches the line height of body text. */
31
+ variant?: 'block' | 'text' | 'circle';
32
+ }
33
+ /** A neutral loading placeholder shaped by the skin. */
34
+ export declare function Skeleton({ variant, className, ...props }: SkeletonProps): ReactNode;
35
+ /** Props of {@link List}. */
36
+ export interface ListProps extends ComponentPropsWithoutRef<'ul'> {
37
+ /** Draw hairlines between items (default false). */
38
+ divided?: boolean;
39
+ }
40
+ /** A vertical collection of {@link ListItem} rows. */
41
+ export declare function List({ divided, className, children, ...props }: ListProps): ReactNode;
42
+ /** Props of {@link ListItem}. */
43
+ export interface ListItemProps extends Omit<ComponentPropsWithoutRef<'li'>, 'onClick' | 'disabled'> {
44
+ /** Leading glyph/figure slot (status LED, icon, thumbnail). */
45
+ leading?: ReactNode;
46
+ /** Trailing slot (badge, timestamp, action). */
47
+ trailing?: ReactNode;
48
+ /** Marks the row as the current selection. */
49
+ selected?: boolean;
50
+ /** Dim the row and ignore activation. */
51
+ disabled?: boolean;
52
+ /** Makes the row interactive (role=button, keyboard activation). */
53
+ onClick?: () => void;
54
+ }
55
+ /** One list row with leading/trailing slots. */
56
+ export declare function ListItem({ leading, trailing, selected, disabled, onClick, className, children, ...props }: ListItemProps): ReactNode;
57
+ //# sourceMappingURL=alert.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Attention surfaces: alerts (inline banners), separators, skeletons, and
4
+ * lists. Read-only primitives; the skin owns their visuals through the
5
+ * `alert.*`, `separator.*`, `skeleton.*`, and `list.*` parts.
6
+ *
7
+ * @module @snap-rail/ui/components/alert
8
+ */
9
+ import * as SeparatorPrimitive from '@radix-ui/react-separator';
10
+ import { cn, part } from "../utils.js";
11
+ /** An inline status banner for results and failures. */
12
+ export function Alert({ intent = 'neutral', className, children, ...props }) {
13
+ return (_jsx("div", { role: "alert", className: cn('snap-alert', className), "data-intent": intent, ...props, ...part('alert', 'root'), children: children }));
14
+ }
15
+ /** The alert heading line. */
16
+ export function AlertTitle({ className, children, ...props }) {
17
+ return _jsx("h5", { className: cn('snap-alert-title', className), ...props, ...part('alert', 'title'), children: children });
18
+ }
19
+ /** The alert body text. */
20
+ export function AlertDescription({ className, children, ...props }) {
21
+ return _jsx("div", { className: cn('snap-alert-description', className), ...props, ...part('alert', 'description'), children: children });
22
+ }
23
+ /** A themed rule between sections. */
24
+ export function Separator({ orientation = 'horizontal', className, ...props }) {
25
+ return (_jsx(SeparatorPrimitive.Root, { orientation: orientation, className: cn('snap-separator', className), ...props, ...part('separator', 'root') }));
26
+ }
27
+ /** A neutral loading placeholder shaped by the skin. */
28
+ export function Skeleton({ variant = 'block', className, ...props }) {
29
+ return _jsx("div", { className: cn('snap-skeleton', className), "data-variant": variant, "aria-hidden": "true", ...props, ...part('skeleton', 'root') });
30
+ }
31
+ /** A vertical collection of {@link ListItem} rows. */
32
+ export function List({ divided = false, className, children, ...props }) {
33
+ return (_jsx("ul", { className: cn('snap-list', className), "data-divided": divided || undefined, ...props, ...part('list', 'root'), children: children }));
34
+ }
35
+ /** One list row with leading/trailing slots. */
36
+ export function ListItem({ leading, trailing, selected = false, disabled = false, onClick, className, children, ...props }) {
37
+ const interactive = onClick !== undefined && !disabled;
38
+ const activate = (event) => {
39
+ if (event.key === 'Enter' || event.key === ' ') {
40
+ event.preventDefault();
41
+ onClick?.();
42
+ }
43
+ };
44
+ return (_jsxs("li", { className: cn('snap-list-item', className), "data-selected": selected || undefined, "data-interactive": interactive || undefined, "data-disabled": disabled || undefined, "aria-disabled": disabled || undefined, ...interactive ? { role: 'button', tabIndex: 0, onClick, onKeyDown: activate } : {}, ...props, ...part('list', 'item'), children: [leading !== undefined && _jsx("span", { ...part('list', 'leading'), children: leading }), _jsx("span", { ...part('list', 'content'), style: { flex: 1, minWidth: 0 }, children: children }), trailing !== undefined && _jsx("span", { ...part('list', 'trailing'), children: trailing })] }));
45
+ }
46
+ //# sourceMappingURL=alert.js.map
@@ -18,10 +18,10 @@ export function Button({ intent = 'neutral', emphasis = 'solid', size = 'md', lo
18
18
  const content = asChild
19
19
  ? children
20
20
  : (_jsxs(_Fragment, { children: [icon !== undefined && iconPosition === 'start' && _jsx("span", { ...part('button', 'icon'), children: icon }), children !== undefined && _jsx("span", { ...part('button', 'label'), children: children }), icon !== undefined && iconPosition === 'end' && _jsx("span", { ...part('button', 'icon'), children: icon }), loading && _jsx(Spinner, {})] }));
21
- return (_jsx(Component, { ...part('button', 'root'), ...type !== undefined ? { type } : !asChild ? { type: 'button' } : {}, className: cn('snap-button', className), "data-intent": intent, "data-emphasis": emphasis, "data-size": size, "data-loading": loading || undefined, "data-disabled": disabled === true || undefined, "aria-busy": loading || undefined, disabled: !asChild ? disabled === true || loading : undefined, ...props, children: content }));
21
+ return (_jsx(Component, { ...type !== undefined ? { type } : !asChild ? { type: 'button' } : {}, className: cn('snap-button', className), "data-intent": intent, "data-emphasis": emphasis, "data-size": size, "data-loading": loading || undefined, "data-disabled": disabled === true || undefined, "aria-busy": loading || undefined, disabled: !asChild ? disabled === true || loading : undefined, ...props, ...part('button', 'root'), children: content }));
22
22
  }
23
23
  /** A square glyph button with a mandatory accessible label. */
24
24
  export function IconButton({ icon, label, active = false, intent = 'neutral', emphasis = 'ghost', size = 'md', className, ...props }) {
25
- return (_jsx("button", { ...part('icon-button', 'root'), type: "button", className: cn('snap-icon-button', className), "data-intent": intent, "data-emphasis": emphasis, "data-size": size, "data-active": active || undefined, "aria-label": label, "aria-pressed": active || undefined, ...props, children: _jsx("span", { ...part('icon-button', 'icon'), "aria-hidden": "true", children: icon }) }));
25
+ return (_jsx("button", { type: "button", className: cn('snap-icon-button', className), "data-intent": intent, "data-emphasis": emphasis, "data-size": size, "data-active": active || undefined, "aria-label": label, "aria-pressed": active || undefined, ...props, ...part('icon-button', 'root'), children: _jsx("span", { ...part('icon-button', 'icon'), "aria-hidden": "true", children: icon }) }));
26
26
  }
27
27
  //# sourceMappingURL=button.js.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A text field with an anchored suggestion list: search pickers, filtered
3
+ * choosers, async candidate feeds (operator lookups, assignee search). The
4
+ * focus never leaves the field — keyboard navigation rides
5
+ * `aria-activedescendant`, pointer picks suppress the field's blur, and the
6
+ * panel opens without taking the focus — so typing keeps working through
7
+ * open, navigate, and select. The field is a regular {@link Input}; skins
8
+ * style the `combobox.*` parts around it.
9
+ *
10
+ * @module @snap-rail/ui/components/combobox
11
+ */
12
+ import { type ReactNode } from 'react';
13
+ import type { SelectOption } from './controls.tsx';
14
+ import { type InputSize } from './input.tsx';
15
+ /** Props of {@link Combobox}. */
16
+ export interface ComboboxProps {
17
+ /** Controlled selected value. */
18
+ value?: string;
19
+ /** Uncontrolled initial value. */
20
+ defaultValue?: string;
21
+ onValueChange?: (value: string) => void;
22
+ /** The field text changed. When set, `options` are taken as already
23
+ * matched (an async search feeds them); otherwise the list filters by
24
+ * label locally. */
25
+ onInputValueChange?: (text: string) => void;
26
+ options: readonly SelectOption[];
27
+ placeholder?: string;
28
+ disabled?: boolean;
29
+ invalid?: boolean;
30
+ size?: InputSize;
31
+ /** Candidates are being fetched (async search). */
32
+ loading?: boolean;
33
+ /** Shown when no option matches (default `无匹配项`). */
34
+ emptyText?: ReactNode;
35
+ /** The field's id; also wires a label's `htmlFor`. */
36
+ id?: string;
37
+ /** Dresses the field wrapper. */
38
+ className?: string;
39
+ /** Dresses the suggestion panel. */
40
+ contentClassName?: string;
41
+ 'aria-label'?: string;
42
+ }
43
+ /** A field with an anchored, keyboard-navigable suggestion list. */
44
+ export declare function Combobox({ value, defaultValue, onValueChange, onInputValueChange, options, placeholder, disabled, invalid, size, loading, emptyText, id, className, contentClassName, 'aria-label': ariaLabel, }: ComboboxProps): ReactNode;
45
+ //# sourceMappingURL=combobox.d.ts.map
@@ -0,0 +1,108 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A text field with an anchored suggestion list: search pickers, filtered
4
+ * choosers, async candidate feeds (operator lookups, assignee search). The
5
+ * focus never leaves the field — keyboard navigation rides
6
+ * `aria-activedescendant`, pointer picks suppress the field's blur, and the
7
+ * panel opens without taking the focus — so typing keeps working through
8
+ * open, navigate, and select. The field is a regular {@link Input}; skins
9
+ * style the `combobox.*` parts around it.
10
+ *
11
+ * @module @snap-rail/ui/components/combobox
12
+ */
13
+ import { useEffect, useId, useRef, useState } from 'react';
14
+ import { part } from "../utils.js";
15
+ import { Input } from "./input.js";
16
+ import { Popover, PopoverAnchor, PopoverContent } from "./overlay.js";
17
+ /** The text an option contributes to filtering and to the field once picked. */
18
+ function textOf(option) {
19
+ return typeof option.label === 'string' || typeof option.label === 'number' ? String(option.label) : option.value;
20
+ }
21
+ /** The next enabled row index from `from`, wrapping; -1 when none is enabled. */
22
+ function nextEnabled(rows, from, step) {
23
+ if (rows.length === 0)
24
+ return -1;
25
+ let index = from < 0 ? (step > 0 ? -1 : 0) : from;
26
+ for (let tries = 0; tries < rows.length; tries++) {
27
+ index = (index + step + rows.length) % rows.length;
28
+ if (rows[index]?.disabled !== true)
29
+ return index;
30
+ }
31
+ return -1;
32
+ }
33
+ /** A field with an anchored, keyboard-navigable suggestion list. */
34
+ export function Combobox({ value, defaultValue, onValueChange, onInputValueChange, options, placeholder, disabled = false, invalid = false, size = 'md', loading = false, emptyText = '无匹配项', id, className, contentClassName, 'aria-label': ariaLabel, }) {
35
+ const listId = useId();
36
+ const anchorRef = useRef(null);
37
+ const [uncontrolled, setUncontrolled] = useState(defaultValue);
38
+ const current = value !== undefined ? value : uncontrolled;
39
+ const selected = options.find(option => option.value === current);
40
+ const selectedText = selected !== undefined ? textOf(selected) : undefined;
41
+ const [text, setText] = useState(selectedText ?? '');
42
+ const [open, setOpen] = useState(false);
43
+ const [active, setActive] = useState(-1);
44
+ // An external value change (or async options delivering the selected row)
45
+ // re-dresses the field with the selected label.
46
+ useEffect(() => {
47
+ if (selectedText !== undefined)
48
+ setText(selectedText);
49
+ }, [selectedText]);
50
+ const query = text.trim().toLowerCase();
51
+ const rows = onInputValueChange !== undefined || query === '' || text === selectedText
52
+ ? options
53
+ : options.filter(option => textOf(option).toLowerCase().includes(query));
54
+ const optionId = (index) => `${listId}-${index}`;
55
+ useEffect(() => {
56
+ if (active < 0)
57
+ return;
58
+ document.getElementById(optionId(active))?.scrollIntoView?.({ block: 'nearest' });
59
+ });
60
+ const close = () => {
61
+ setOpen(false);
62
+ setActive(-1);
63
+ };
64
+ const choose = (option) => {
65
+ if (option.disabled === true)
66
+ return;
67
+ if (value === undefined)
68
+ setUncontrolled(option.value);
69
+ setText(textOf(option));
70
+ onValueChange?.(option.value);
71
+ close();
72
+ };
73
+ const onKeyDown = (event) => {
74
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
75
+ event.preventDefault();
76
+ if (!open) {
77
+ setOpen(true);
78
+ return;
79
+ }
80
+ setActive(index => nextEnabled(rows, index, event.key === 'ArrowDown' ? 1 : -1));
81
+ return;
82
+ }
83
+ if (event.key === 'Enter' && open && active >= 0) {
84
+ const option = rows[active];
85
+ if (option !== undefined) {
86
+ event.preventDefault();
87
+ choose(option);
88
+ }
89
+ return;
90
+ }
91
+ if (event.key === 'Escape' && open) {
92
+ event.preventDefault();
93
+ close();
94
+ }
95
+ };
96
+ return (_jsx("span", { ...part('combobox', 'root'), className: "snap-combobox", children: _jsxs(Popover, { open: open && !disabled, onOpenChange: next => { if (!next)
97
+ close(); }, children: [_jsx(PopoverAnchor, { asChild: true, children: _jsx("span", { ref: anchorRef, ...part('combobox', 'anchor'), children: _jsx(Input, { id: id, size: size, invalid: invalid, disabled: disabled, placeholder: placeholder, className: className, value: text, role: "combobox", autoComplete: "off", "aria-label": ariaLabel, "aria-expanded": open, "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": open && active >= 0 ? optionId(active) : undefined, onChange: event => {
98
+ setText(event.target.value);
99
+ setActive(-1);
100
+ setOpen(true);
101
+ onInputValueChange?.(event.target.value);
102
+ }, onFocus: () => setOpen(true), onBlur: close, onKeyDown: onKeyDown }) }) }), _jsx(PopoverContent, { align: "start", sideOffset: 4, autoFocusOnOpen: false, className: contentClassName, onInteractOutside: event => {
103
+ // A press on the field itself is not "outside": keep the list open.
104
+ if (anchorRef.current?.contains(event.target) === true)
105
+ event.preventDefault();
106
+ }, children: _jsxs("div", { ...part('combobox', 'list'), role: "listbox", id: listId, children: [rows.map((option, index) => (_jsx("div", { ...part('combobox', 'option'), id: optionId(index), role: "option", "aria-selected": option.value === current, "aria-disabled": option.disabled === true || undefined, "data-active": index === active || undefined, "data-disabled": option.disabled === true || undefined, onMouseDown: event => event.preventDefault(), onClick: () => choose(option), children: option.label }, option.value))), loading && _jsx("div", { ...part('combobox', 'empty'), children: "\u641C\u7D22\u4E2D\u2026" }), !loading && rows.length === 0 && _jsx("div", { ...part('combobox', 'empty'), children: emptyText })] }) })] }) }));
107
+ }
108
+ //# sourceMappingURL=combobox.js.map