@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
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { rpcErrorText } from '@snap-rail/connection';
3
3
  import { useEffect, useState } from 'react';
4
- import { Badge, Button, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, EmptyState, IconButton, Input, Page, Stack, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/index.js";
4
+ import { Alert, Badge, Button, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, EmptyState, IconButton, Input, Page, Stack, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../components/index.js";
5
5
  /** The preload's zip→path bridge (`webUtils.getPathForFile`); null outside
6
6
  * Electron or in tests. Inlined rather than imported from the app-internal
7
7
  * kernel package: it never ships in the installer, and the packaged-app gate
@@ -294,7 +294,7 @@ export function PluginsPage({ ctx }) {
294
294
  spans.set(index, end - index);
295
295
  index = end;
296
296
  }
297
- return (_jsxs(Page, { title: "\u63D2\u4EF6\u7BA1\u7406", titleExtra: _jsx(IconButton, { icon: _jsx(PlusIcon, {}), label: "\u5B89\u88C5\u63D2\u4EF6", onClick: openInstall }), actions: restartNeeded ? _jsx(Button, { intent: "primary", onClick: restart, children: "\u91CD\u542F\u751F\u6548" }) : undefined, children: [_jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx("div", { role: "alert", style: { color: 'var(--snap-color-danger)' }, children: error }), rows.length === 0
297
+ return (_jsxs(Page, { title: "\u63D2\u4EF6\u7BA1\u7406", titleExtra: _jsx(IconButton, { icon: _jsx(PlusIcon, {}), label: "\u5B89\u88C5\u63D2\u4EF6", onClick: openInstall }), actions: restartNeeded ? _jsx(Button, { intent: "primary", onClick: restart, children: "\u91CD\u542F\u751F\u6548" }) : undefined, children: [_jsxs(Stack, { gap: "lg", children: [error !== undefined && _jsx(Alert, { intent: "danger", children: error }), rows.length === 0
298
298
  ? (_jsx(EmptyState, { title: "\u8FD8\u6CA1\u6709\u5B89\u88C5\u63D2\u4EF6", action: _jsx(Button, { intent: "primary", onClick: openInstall, children: "\u5B89\u88C5\u63D2\u4EF6" }) }))
299
299
  : (_jsxs(Table, { "data-plugins-table": true, children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { style: { width: '6em' }, children: "\u5206\u7C7B" }), _jsx(TableHead, { children: "\u540D\u79F0" }), _jsx(TableHead, { children: "\u7C7B\u578B" }), _jsx(TableHead, { children: "\u7248\u672C" }), _jsx(TableHead, { children: "\u72B6\u6001" }), _jsx(TableHead, { children: "\u64CD\u4F5C" })] }) }), _jsx(TableBody, { children: rows.map((row, index) => {
300
300
  const update = updates.get(row.packageName);
@@ -6,7 +6,13 @@
6
6
  */
7
7
  /** Join truthy class names. */
8
8
  export declare function cn(...values: ReadonlyArray<string | false | null | undefined>): string;
9
- /** The anatomy attributes every semantic component renders. */
9
+ /**
10
+ * The anatomy attributes every semantic component renders. The identity is
11
+ * component-owned: components spread these AFTER caller props so a composite
12
+ * can never mask a host part (a masked `button.root` loses every skin rule
13
+ * and falls back to the UA default look). Composites tag their own wrappers
14
+ * instead of pushing `part()` into a child component's props.
15
+ */
10
16
  export declare function part(component: string, name: string): Record<string, string>;
11
17
  /** Map a semantic size token to a control-height CSS variable. */
12
18
  export declare function controlHeight(size: 'sm' | 'md' | 'lg'): string;
@@ -8,7 +8,13 @@
8
8
  export function cn(...values) {
9
9
  return values.filter((value) => typeof value === 'string' && value.length > 0).join(' ');
10
10
  }
11
- /** The anatomy attributes every semantic component renders. */
11
+ /**
12
+ * The anatomy attributes every semantic component renders. The identity is
13
+ * component-owned: components spread these AFTER caller props so a composite
14
+ * can never mask a host part (a masked `button.root` loses every skin rule
15
+ * and falls back to the UA default look). Composites tag their own wrappers
16
+ * instead of pushing `part()` into a child component's props.
17
+ */
12
18
  export function part(component, name) {
13
19
  return {
14
20
  'data-snap-component': component,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snap-rail/ui",
3
3
  "description": "The built-in UI substrate: semantic components, typed region slots, skins, settings and renderer runtime",
4
- "version": "0.1.1",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -62,16 +62,23 @@
62
62
  ],
63
63
  "license": "Apache-2.0",
64
64
  "dependencies": {
65
+ "@hookform/resolvers": "^7.0.2",
65
66
  "@radix-ui/react-checkbox": "^1.1.3",
66
67
  "@radix-ui/react-dialog": "^1.1.6",
68
+ "@radix-ui/react-dropdown-menu": "^2.2.1",
67
69
  "@radix-ui/react-label": "^2.1.2",
70
+ "@radix-ui/react-popover": "^1.3.1",
68
71
  "@radix-ui/react-radio-group": "^1.2.3",
69
72
  "@radix-ui/react-scroll-area": "^1.2.18",
70
73
  "@radix-ui/react-select": "^2.2.6",
74
+ "@radix-ui/react-separator": "^1.2.0",
75
+ "@radix-ui/react-slider": "^1.6.1",
71
76
  "@radix-ui/react-slot": "^1.3.3",
72
77
  "@radix-ui/react-switch": "^1.3.7",
73
78
  "@radix-ui/react-tabs": "^1.1.13",
74
- "@radix-ui/react-tooltip": "^1.2.16"
79
+ "@radix-ui/react-toast": "^1.3.1",
80
+ "@radix-ui/react-tooltip": "^1.2.16",
81
+ "react-hook-form": "^7.91.0"
75
82
  },
76
83
  "peerDependencies": {
77
84
  "react": ">=19",
@@ -79,8 +86,8 @@
79
86
  "zod": "^4.4.3",
80
87
  "@snap-rail/connection": "^0.1.0",
81
88
  "@snap-rail/cordis": "^4.0.3",
82
- "@snap-rail/protocol": "^0.1.3",
83
- "@snap-rail/shell": "^0.2.3"
89
+ "@snap-rail/shell": "^0.2.4",
90
+ "@snap-rail/protocol": "^0.1.3"
84
91
  },
85
92
  "devDependencies": {
86
93
  "@types/react": "^19.2.14",
@@ -92,13 +99,13 @@
92
99
  "typescript": "^6.0.3",
93
100
  "vitest": "^4.1.8",
94
101
  "zod": "^4.4.3",
95
- "@snap-rail/app-boot": "^0.1.3",
96
- "@snap-rail/connection": "^0.1.0",
97
102
  "@snap-rail/client-kernel": "^0.1.2",
103
+ "@snap-rail/connection": "^0.1.0",
98
104
  "@snap-rail/cordis": "^4.0.3",
99
105
  "@snap-rail/cordis-plugin-timer": "^1.1.3",
106
+ "@snap-rail/app-boot": "^0.1.3",
100
107
  "@snap-rail/protocol": "^0.1.3",
101
- "@snap-rail/shell": "^0.2.3",
108
+ "@snap-rail/shell": "^0.2.4",
102
109
  "@snap-rail/station-rpc": "^0.1.0"
103
110
  },
104
111
  "snapRail": {
@@ -92,7 +92,9 @@
92
92
  }
93
93
 
94
94
  [data-snap-component='select'] {
95
- display: inline-flex;
95
+ display: flex;
96
+ width: 100%;
97
+ min-width: 0;
96
98
  }
97
99
 
98
100
  [data-snap-part='select.trigger'] {
@@ -176,6 +178,12 @@
176
178
  text-align: left;
177
179
  }
178
180
 
181
+ /* Headers never wrap: narrow panes get a wider scrollable table instead of
182
+ * vertically stacked glyphs. */
183
+ [data-snap-part='table.head'] {
184
+ white-space: nowrap;
185
+ }
186
+
179
187
  [data-snap-part='card.root'],
180
188
  [data-snap-part='panel.root'] {
181
189
  display: flex;
@@ -210,13 +218,49 @@
210
218
  min-width: 0;
211
219
  }
212
220
 
213
- [data-snap-part='form.root'],
214
- [data-snap-part='form.fields'] {
221
+ /* Horizontal fields put the label beside the control; help/error drop
222
+ * under the control column. */
223
+ [data-snap-part='field.root'][data-orientation='horizontal'] {
224
+ flex-direction: row;
225
+ align-items: flex-start;
226
+ flex-wrap: wrap;
227
+ }
228
+
229
+ [data-snap-part='field.root'][data-orientation='horizontal'] > [data-snap-part='field.label'] {
230
+ line-height: var(--snap-control-height-md);
231
+ }
232
+
233
+ [data-snap-part='field.root'][data-orientation='horizontal'] > [data-snap-part='field.control'] {
234
+ flex: 1;
235
+ min-width: 0;
236
+ }
237
+
238
+ [data-snap-part='field.root'][data-orientation='horizontal'] > [data-snap-part='field.help'],
239
+ [data-snap-part='field.root'][data-orientation='horizontal'] > [data-snap-part='field.error'] {
240
+ flex-basis: 100%;
241
+ }
242
+
243
+ [data-snap-part='form.root'] {
215
244
  display: flex;
216
245
  flex-direction: column;
217
246
  gap: var(--snap-space-md);
218
247
  }
219
248
 
249
+ [data-snap-part='form.root'][data-orientation='inline'] {
250
+ flex-direction: row;
251
+ flex-wrap: wrap;
252
+ align-items: flex-end;
253
+ }
254
+
255
+ [data-snap-part='form.root'][data-orientation='inline'] > [data-snap-part='form.fields'] {
256
+ flex: 1;
257
+ min-width: 0;
258
+ }
259
+
260
+ [data-snap-part='form.root'][data-orientation='inline'] > [data-snap-part='form.actions'] {
261
+ flex-shrink: 0;
262
+ }
263
+
220
264
  [data-snap-part='form.actions'] {
221
265
  display: flex;
222
266
  align-items: center;
@@ -257,7 +301,6 @@
257
301
  text-align: center;
258
302
  }
259
303
 
260
- [data-snap-part='visualization.root'],
261
304
  [data-snap-part='chart-frame.root'] {
262
305
  display: flex;
263
306
  flex-direction: column;
@@ -310,12 +353,279 @@
310
353
  text-align: left;
311
354
  }
312
355
 
313
- [data-snap-part='visualization.body'],
314
356
  [data-snap-part='chart-frame.body'] {
315
357
  flex: 1;
316
358
  min-height: 0;
317
359
  }
318
360
 
361
+ /* TouchSelect fills its container like every other form control (the
362
+ * Input family defaults to width:100%); parts anchor the layout because
363
+ * the trigger/sheet wrappers also carry the component tag. */
364
+ [data-snap-part='touch-select.root'] {
365
+ display: flex;
366
+ width: 100%;
367
+ min-width: 0;
368
+ }
369
+
370
+ [data-snap-part='touch-select.trigger'] {
371
+ display: flex;
372
+ flex: 1;
373
+ min-width: 0;
374
+ }
375
+
376
+ [data-snap-part='touch-select.trigger'] > [data-snap-component='button'] {
377
+ width: 100%;
378
+ }
379
+
380
+ [data-snap-part='touch-select.sheet'] {
381
+ display: flex;
382
+ flex: 1;
383
+ flex-direction: column;
384
+ gap: var(--snap-space-sm);
385
+ min-height: 0;
386
+ }
387
+
388
+ [data-snap-part='radio-group.block'] {
389
+ display: flex;
390
+ flex-direction: column;
391
+ gap: var(--snap-space-xs);
392
+ min-width: 0;
393
+ }
394
+
395
+ .snap-number-input-steps {
396
+ display: flex;
397
+ flex-direction: column;
398
+ flex-shrink: 0;
399
+ }
400
+
401
+ [data-snap-part='number-input.step-up'],
402
+ [data-snap-part='number-input.step-down'] {
403
+ display: inline-flex;
404
+ align-items: center;
405
+ justify-content: center;
406
+ border: 0;
407
+ background: transparent;
408
+ cursor: pointer;
409
+ padding: 0 var(--snap-space-xs);
410
+ }
411
+
412
+ [data-snap-part='number-input.step-up']:disabled,
413
+ [data-snap-part='number-input.step-down']:disabled {
414
+ cursor: default;
415
+ }
416
+
417
+ [data-snap-part='drag-scroll.root'] {
418
+ cursor: grab;
419
+ }
420
+
421
+ [data-snap-part='drag-scroll.root'][data-dragging='true'] {
422
+ cursor: grabbing;
423
+ user-select: none;
424
+ }
425
+
426
+ [data-snap-part='tooltip.content'],
427
+ [data-snap-part='popover.content'],
428
+ [data-snap-part='menu.content'] {
429
+ z-index: var(--snap-z-overlay);
430
+ }
431
+
432
+ /* A popover tracks its anchor: at least as wide, wider when content asks
433
+ * (the popper exposes the anchor width as a CSS variable). */
434
+ [data-snap-part='popover.content'] {
435
+ min-width: var(--radix-popper-anchor-width);
436
+ }
437
+
438
+ [data-snap-part='combobox.root'] {
439
+ display: flex;
440
+ width: 100%;
441
+ min-width: 0;
442
+ }
443
+
444
+ [data-snap-part='combobox.anchor'] {
445
+ display: block;
446
+ flex: 1;
447
+ min-width: 0;
448
+ }
449
+
450
+ [data-snap-part='combobox.list'] {
451
+ display: flex;
452
+ flex-direction: column;
453
+ max-height: 320px;
454
+ overflow: auto;
455
+ }
456
+
457
+ [data-snap-part='combobox.option'] {
458
+ display: flex;
459
+ align-items: center;
460
+ min-height: var(--snap-control-height-md);
461
+ padding-inline: var(--snap-space-md);
462
+ cursor: pointer;
463
+ }
464
+
465
+ [data-snap-part='combobox.option'][data-disabled] {
466
+ color: var(--snap-color-muted);
467
+ cursor: default;
468
+ }
469
+
470
+ [data-snap-part='combobox.empty'] {
471
+ padding: var(--snap-space-sm) var(--snap-space-md);
472
+ color: var(--snap-color-muted);
473
+ }
474
+
475
+ [data-snap-part='menu.item'],
476
+ [data-snap-part='menu.checkbox-item'] {
477
+ display: flex;
478
+ align-items: center;
479
+ gap: var(--snap-space-sm);
480
+ cursor: pointer;
481
+ }
482
+
483
+ [data-snap-part='menu.separator'] {
484
+ height: var(--snap-border-width);
485
+ background: var(--snap-color-border);
486
+ }
487
+
488
+ [data-snap-part='toast.viewport'] {
489
+ position: fixed;
490
+ right: 0;
491
+ bottom: 0;
492
+ z-index: var(--snap-z-modal);
493
+ display: flex;
494
+ flex-direction: column;
495
+ gap: var(--snap-space-sm);
496
+ margin: 0;
497
+ padding: var(--snap-space-md);
498
+ list-style: none;
499
+ }
500
+
501
+ [data-snap-part='toast.root'] {
502
+ display: flex;
503
+ flex-direction: column;
504
+ gap: var(--snap-space-xs);
505
+ }
506
+
507
+ [data-snap-part='alert.root'] {
508
+ display: flex;
509
+ flex-direction: column;
510
+ gap: var(--snap-space-xs);
511
+ }
512
+
513
+ [data-snap-part='separator.root'] {
514
+ flex-shrink: 0;
515
+ }
516
+
517
+ [data-snap-part='skeleton.root'] {
518
+ border-radius: var(--snap-radius-sm);
519
+ background: var(--snap-color-surface);
520
+ }
521
+
522
+ [data-snap-part='skeleton.root'][data-variant='text'] {
523
+ height: 1em;
524
+ }
525
+
526
+ [data-snap-part='skeleton.root'][data-variant='circle'] {
527
+ border-radius: var(--snap-radius-full);
528
+ aspect-ratio: 1;
529
+ }
530
+
531
+ [data-snap-part='list.root'] {
532
+ display: flex;
533
+ flex-direction: column;
534
+ margin: 0;
535
+ padding: 0;
536
+ list-style: none;
537
+ min-width: 0;
538
+ }
539
+
540
+ [data-snap-part='list.root'][data-divided] > [data-snap-part='list.item'] {
541
+ border-bottom: var(--snap-border-width) solid var(--snap-color-border);
542
+ }
543
+
544
+ [data-snap-part='list.root'][data-divided] > [data-snap-part='list.item']:last-child {
545
+ border-bottom: 0;
546
+ }
547
+
548
+ [data-snap-part='list.item'] {
549
+ display: flex;
550
+ align-items: center;
551
+ gap: var(--snap-space-sm);
552
+ padding-inline: var(--snap-space-md);
553
+ min-height: var(--snap-control-height-md);
554
+ min-width: 0;
555
+ }
556
+
557
+ [data-snap-part='list.item'][data-interactive] {
558
+ cursor: pointer;
559
+ }
560
+
561
+ [data-snap-part='list.item'][data-disabled] {
562
+ color: var(--snap-color-muted);
563
+ }
564
+
565
+ [data-snap-part='slider.root'] {
566
+ display: flex;
567
+ align-items: center;
568
+ touch-action: none;
569
+ user-select: none;
570
+ min-height: var(--snap-control-height-lg);
571
+ }
572
+
573
+ [data-snap-part='slider.track'] {
574
+ position: relative;
575
+ flex: 1;
576
+ min-width: 0;
577
+ }
578
+
579
+ [data-snap-part='slider.thumb'] {
580
+ display: block;
581
+ }
582
+
583
+ [data-snap-part='slider.thumb']:focus-visible {
584
+ outline: 2px solid var(--snap-color-focus);
585
+ outline-offset: 2px;
586
+ }
587
+
588
+ [data-snap-component='scroll-area'] {
589
+ display: flex;
590
+ flex-direction: column;
591
+ min-height: 0;
592
+ }
593
+
594
+ [data-snap-part='scroll-area.viewport'] {
595
+ width: 100%;
596
+ flex: 1;
597
+ min-height: 0;
598
+ }
599
+
600
+ [data-snap-part='scroll-area.scrollbar'] {
601
+ display: flex;
602
+ touch-action: none;
603
+ user-select: none;
604
+ padding: 2px;
605
+ background: transparent;
606
+ transition: background 160ms ease-out;
607
+ }
608
+
609
+ [data-snap-part='scroll-area.scrollbar'][data-orientation='vertical'] {
610
+ width: 10px;
611
+ flex-direction: column;
612
+ }
613
+
614
+ [data-snap-part='scroll-area.scrollbar'][data-orientation='horizontal'] {
615
+ flex-direction: row;
616
+ height: 10px;
617
+ }
618
+
619
+ [data-snap-part='scroll-area.thumb'] {
620
+ flex: 1;
621
+ border-radius: var(--snap-radius-full);
622
+ background: var(--snap-color-border);
623
+ }
624
+
625
+ [data-snap-part='scroll-area.thumb']:hover {
626
+ background: var(--snap-color-muted);
627
+ }
628
+
319
629
  [data-snap-component='button']:focus-visible,
320
630
  [data-snap-component='icon-button']:focus-visible,
321
631
  [data-snap-part='select.trigger']:focus-visible,