switch-ext-kit 0.0.0-stage → 0.2.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/src/catalog.ts ADDED
@@ -0,0 +1,757 @@
1
+ // Switch's catalog (`SWITCH_CATALOG`): the house parts every client draws in Switch's look, beside
2
+ // A2UI's basic catalog, which clients draw in the same look. An extension's widget and a view the
3
+ // agent makes use either; a component names its catalog with `catalogId` when it isn't the
4
+ // surface's own. Each part is declared here, so what's written and what's drawn are one thing.
5
+ //
6
+ // A property that's `Bound` takes its value, or a binding to the surface's data model
7
+ // (`{ "@path": "/rows" }`), or a function call (`{ "@call": "formatString", "args": … }`).
8
+ import { Schema } from "effect"
9
+
10
+ /** A value from the surface's data model, by JSON Pointer. */
11
+ export interface DataBinding {
12
+ readonly "@path": string
13
+ }
14
+
15
+ /** A value a catalog function works out. */
16
+ export interface FunctionCall {
17
+ readonly "@call": string
18
+ readonly args?: Readonly<Record<string, unknown>>
19
+ /** The catalog whose function it is; none, the surface's catalog. */
20
+ readonly catalogId?: string
21
+ }
22
+
23
+ /** A value, or where it comes from. */
24
+ export type Bound<T> = T | DataBinding | FunctionCall
25
+
26
+ /** Children by id, or one component repeated for each item of a list in the data model. */
27
+ export type ChildList = readonly string[] | { readonly componentId: string; readonly path: string }
28
+
29
+ const binding = Schema.Struct({ "@path": Schema.String })
30
+ const call = Schema.Struct({
31
+ "@call": Schema.String,
32
+ args: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
33
+ catalogId: Schema.optionalKey(Schema.String),
34
+ })
35
+ const bound = <S extends Schema.Top>(s: S) => Schema.Union([s, binding, call])
36
+ const text = bound(Schema.String)
37
+ const flag = bound(Schema.Boolean)
38
+ const number = bound(Schema.Finite)
39
+ const children = Schema.Union([
40
+ Schema.Array(Schema.String),
41
+ Schema.Struct({ componentId: Schema.String, path: Schema.String }),
42
+ ])
43
+ const px = Schema.Finite.check(Schema.isGreaterThan(0))
44
+
45
+ // ---- Lines and rows
46
+
47
+ /** One line: its mark, its name, and a time that runs while it does (`left` down, `elapsed` up). */
48
+ export interface Line {
49
+ readonly label: Bound<string>
50
+ readonly running?: Bound<boolean>
51
+ readonly ringing?: Bound<boolean>
52
+ /** Ms left, counting down while it runs. */
53
+ readonly left?: Bound<number>
54
+ /** Ms gone, counting up while it runs. */
55
+ readonly elapsed?: Bound<number>
56
+ /** When the times were read, in ms. */
57
+ readonly asOf?: Bound<number>
58
+ }
59
+
60
+ /** A line in time: when, its live marks, what. */
61
+ export interface Slot {
62
+ readonly time: Bound<string>
63
+ readonly title: Bound<string>
64
+ readonly running?: Bound<boolean>
65
+ readonly needsYou?: Bound<boolean>
66
+ readonly conflict?: Bound<boolean>
67
+ }
68
+
69
+ /** A line of label and value, with a red triangle when it's worth a look. */
70
+ export interface Field {
71
+ readonly label: Bound<string>
72
+ readonly value: Bound<string>
73
+ readonly alert?: Bound<boolean>
74
+ }
75
+
76
+ /** What a card is about, in reading size, with a hand when it needs the user. */
77
+ export interface Title {
78
+ readonly label: Bound<string>
79
+ readonly needsYou?: Bound<boolean>
80
+ }
81
+
82
+ /**
83
+ * A line with its live mark, name and what's under it, figures at its end, a progress rule along
84
+ * its foot and a countdown to `endsAt`; its children under it, one equal column each.
85
+ */
86
+ export interface Row {
87
+ readonly label: Bound<string>
88
+ /** `running`, `needsYou`, `stop` or `warn`. */
89
+ readonly mark?: Bound<string>
90
+ readonly detail?: Bound<string>
91
+ /** The detail is what's wrong. */
92
+ readonly alert?: Bound<boolean>
93
+ readonly values?: Bound<readonly string[]>
94
+ /** 0 to 100, or null for none. */
95
+ readonly progress?: Bound<number | null>
96
+ /** When it ends, in ms, or null. */
97
+ readonly endsAt?: Bound<number | null>
98
+ readonly children?: ChildList
99
+ /** A page the whole row opens in the browser. */
100
+ readonly url?: Bound<string>
101
+ }
102
+
103
+ /** A group of choices a Pick offers: words, or RRGGBB colors as swatches. */
104
+ export interface Choices {
105
+ readonly key: string
106
+ readonly choices: readonly string[]
107
+ readonly swatches?: boolean
108
+ }
109
+
110
+ /** A key with its swatch and label, opening choices; Set calls `action` with `args` and the picks. */
111
+ export interface Pick {
112
+ readonly label: Bound<string>
113
+ readonly swatch?: Bound<string>
114
+ /** In use now. */
115
+ readonly strong?: Bound<boolean>
116
+ readonly title?: Bound<string>
117
+ readonly groups: readonly Choices[]
118
+ /** What each group holds now, by key. */
119
+ readonly current?: Bound<Readonly<Record<string, unknown>>>
120
+ readonly action: string
121
+ readonly args?: Bound<Readonly<Record<string, unknown>>>
122
+ }
123
+
124
+ /** A live picture, a frame from `action` with `args` every `every` ms, edge to edge at `ratio`. */
125
+ export interface Feed {
126
+ readonly action: string
127
+ readonly args?: Bound<Readonly<Record<string, unknown>>>
128
+ readonly every?: number
129
+ /** Width over height: 16 / 9. */
130
+ readonly ratio?: number
131
+ }
132
+
133
+ /** A picture of a Gallery: its link, and what it shows. */
134
+ export interface GalleryImage {
135
+ readonly url: string
136
+ readonly description?: string
137
+ }
138
+
139
+ /** Several pictures as a row that scrolls sideways, each at one height and its own width, opening on a click. */
140
+ export interface Gallery {
141
+ readonly images: Bound<readonly GalleryImage[]>
142
+ }
143
+
144
+ /** A line that ticks off: its ring calls `action` with `args`. */
145
+ export interface Check {
146
+ readonly label: Bound<string>
147
+ readonly detail?: Bound<string>
148
+ readonly done?: Bound<boolean>
149
+ readonly action: string
150
+ readonly args?: Bound<Readonly<Record<string, unknown>>>
151
+ }
152
+
153
+ /**
154
+ * What's playing: its art, title and who by, keys back, play or pause, and next, each calling its
155
+ * extension's tool, and a rule along its foot that runs while it plays. Paused, one quiet line:
156
+ * its title and the play key.
157
+ */
158
+ export interface Playing {
159
+ readonly title: Bound<string>
160
+ readonly by?: Bound<string>
161
+ /** The art's link. */
162
+ readonly art?: Bound<string>
163
+ readonly playing: Bound<boolean>
164
+ /** Ms in, as of `asOf`. */
165
+ readonly at?: Bound<number>
166
+ /** Ms long. */
167
+ readonly length?: Bound<number>
168
+ /** When `at` was read, in ms. */
169
+ readonly asOf?: Bound<number>
170
+ /** The tools the keys call, with no arguments. */
171
+ readonly back: string
172
+ readonly toggle: string
173
+ readonly next: string
174
+ }
175
+
176
+ /** A line to write in: Enter calls `action` with `args` and the words under `field`. */
177
+ export interface Entry {
178
+ readonly placeholder?: Bound<string>
179
+ readonly action: string
180
+ readonly args?: Bound<Readonly<Record<string, unknown>>>
181
+ readonly field: string
182
+ }
183
+
184
+ // ---- Charts: plain data in, drawn in a fixed palette (never cycled) in the house look
185
+
186
+ /** How a chart's figures read: a prefix and a suffix round each ("$", "%", " kg"). */
187
+ export interface Figures {
188
+ readonly prefix?: string
189
+ readonly suffix?: string
190
+ }
191
+
192
+ /** A named series: a value for each label, or null for none. */
193
+ export interface Series {
194
+ readonly name: string
195
+ readonly values: readonly (number | null)[]
196
+ }
197
+
198
+ /** Bars for each label: a series each, side by side or stacked; columns, or rows when horizontal. */
199
+ export interface BarChart extends Figures {
200
+ readonly labels: Bound<readonly string[]>
201
+ /** One to eight. */
202
+ readonly series: Bound<readonly Series[]>
203
+ readonly stacked?: boolean
204
+ readonly horizontal?: boolean
205
+ /** Px, else its own. */
206
+ readonly height?: number
207
+ }
208
+
209
+ /** A line per series over labels evenly spaced along the bottom (days, months). */
210
+ export interface LineChart extends Figures {
211
+ readonly labels: Bound<readonly string[]>
212
+ /** One to eight. */
213
+ readonly series: Bound<readonly Series[]>
214
+ readonly height?: number
215
+ }
216
+
217
+ /** A line chart filled under each line, or stacked. */
218
+ export interface AreaChart extends LineChart {
219
+ readonly stacked?: boolean
220
+ }
221
+
222
+ /** A trend as one small line, its latest point marked: a line's height unless `height`. */
223
+ export interface Sparkline {
224
+ readonly values: Bound<readonly number[]>
225
+ readonly height?: number
226
+ }
227
+
228
+ export interface Slice {
229
+ readonly label: string
230
+ readonly value: number
231
+ }
232
+
233
+ /** Parts of a whole, round a ring with the total in it; six slices at most read at a glance. */
234
+ export interface DonutChart extends Figures {
235
+ readonly slices: Bound<readonly Slice[]>
236
+ }
237
+
238
+ export interface Points {
239
+ readonly name: string
240
+ /** `[x, y]` each. */
241
+ readonly points: readonly (readonly [number, number])[]
242
+ }
243
+
244
+ /** Points by two measures; three series at most stay apart. */
245
+ export interface ScatterChart {
246
+ readonly series: Bound<readonly Points[]>
247
+ readonly xLabel?: string
248
+ readonly yLabel?: string
249
+ readonly height?: number
250
+ }
251
+
252
+ /** How raw values spread, counted into `bins` (else its own) bars. */
253
+ export interface Histogram extends Figures {
254
+ readonly values: Bound<readonly number[]>
255
+ readonly bins?: number
256
+ readonly height?: number
257
+ }
258
+
259
+ export interface Day {
260
+ /** `YYYY-MM-DD`. */
261
+ readonly date: string
262
+ readonly value: number
263
+ }
264
+
265
+ /** A value per day, as weeks of squares, darker for more. */
266
+ export interface CalendarHeatmap extends Figures {
267
+ readonly days: Bound<readonly Day[]>
268
+ }
269
+
270
+ /** How full something is: a line with its label, a track filled to `value` of `max` (100), and the figure. */
271
+ export interface Meter extends Figures {
272
+ readonly label?: Bound<string>
273
+ readonly value: Bound<number>
274
+ readonly max?: number
275
+ }
276
+
277
+ /** Every part of Switch's catalog, by name. */
278
+ export interface SwitchParts {
279
+ readonly Line: Line
280
+ readonly Slot: Slot
281
+ readonly Field: Field
282
+ readonly Title: Title
283
+ readonly Row: Row
284
+ readonly Pick: Pick
285
+ readonly Feed: Feed
286
+ readonly Gallery: Gallery
287
+ readonly Check: Check
288
+ readonly Entry: Entry
289
+ readonly Playing: Playing
290
+ readonly BarChart: BarChart
291
+ readonly LineChart: LineChart
292
+ readonly AreaChart: AreaChart
293
+ readonly Sparkline: Sparkline
294
+ readonly DonutChart: DonutChart
295
+ readonly ScatterChart: ScatterChart
296
+ readonly Histogram: Histogram
297
+ readonly CalendarHeatmap: CalendarHeatmap
298
+ readonly Meter: Meter
299
+ }
300
+
301
+ /** A component of Switch's catalog: its id, its part and the part's properties. */
302
+ export type SwitchComponent = {
303
+ readonly [K in keyof SwitchParts]: { readonly id: string; readonly component: K } & SwitchParts[K]
304
+ }[keyof SwitchParts]
305
+
306
+ const action = {
307
+ action: Schema.String,
308
+ args: Schema.optionalKey(bound(Schema.Record(Schema.String, Schema.Unknown))),
309
+ }
310
+ const figures = {
311
+ prefix: Schema.optionalKey(Schema.String),
312
+ suffix: Schema.optionalKey(Schema.String),
313
+ }
314
+ const series = bound(
315
+ Schema.Array(
316
+ Schema.Struct({ name: Schema.String, values: Schema.Array(Schema.NullOr(Schema.Finite)) }),
317
+ ).check(Schema.isMinLength(1), Schema.isMaxLength(8)),
318
+ )
319
+ const lines = {
320
+ ...figures,
321
+ labels: bound(Schema.Array(Schema.String)),
322
+ series,
323
+ height: Schema.optionalKey(px),
324
+ }
325
+
326
+ /** Each part's properties, to check a component by. */
327
+ export const SWITCH_PARTS: { readonly [K in keyof SwitchParts]: Schema.Codec<SwitchParts[K]> } = {
328
+ Line: Schema.Struct({
329
+ label: text,
330
+ running: Schema.optionalKey(flag),
331
+ ringing: Schema.optionalKey(flag),
332
+ left: Schema.optionalKey(number),
333
+ elapsed: Schema.optionalKey(number),
334
+ asOf: Schema.optionalKey(number),
335
+ }),
336
+ Slot: Schema.Struct({
337
+ time: text,
338
+ title: text,
339
+ running: Schema.optionalKey(flag),
340
+ needsYou: Schema.optionalKey(flag),
341
+ conflict: Schema.optionalKey(flag),
342
+ }),
343
+ Field: Schema.Struct({ label: text, value: text, alert: Schema.optionalKey(flag) }),
344
+ Title: Schema.Struct({ label: text, needsYou: Schema.optionalKey(flag) }),
345
+ Row: Schema.Struct({
346
+ label: text,
347
+ mark: Schema.optionalKey(text),
348
+ detail: Schema.optionalKey(text),
349
+ alert: Schema.optionalKey(flag),
350
+ values: Schema.optionalKey(bound(Schema.Array(Schema.String))),
351
+ progress: Schema.optionalKey(bound(Schema.NullOr(Schema.Finite))),
352
+ endsAt: Schema.optionalKey(bound(Schema.NullOr(Schema.Finite))),
353
+ children: Schema.optionalKey(children),
354
+ url: Schema.optionalKey(text),
355
+ }),
356
+ Pick: Schema.Struct({
357
+ label: text,
358
+ swatch: Schema.optionalKey(text),
359
+ strong: Schema.optionalKey(flag),
360
+ title: Schema.optionalKey(text),
361
+ groups: Schema.Array(
362
+ Schema.Struct({
363
+ key: Schema.String,
364
+ choices: Schema.Array(Schema.String),
365
+ swatches: Schema.optionalKey(Schema.Boolean),
366
+ }),
367
+ ),
368
+ current: Schema.optionalKey(bound(Schema.Record(Schema.String, Schema.Unknown))),
369
+ ...action,
370
+ }),
371
+ Feed: Schema.Struct({
372
+ ...action,
373
+ every: Schema.optionalKey(px),
374
+ ratio: Schema.optionalKey(px),
375
+ }),
376
+ Gallery: Schema.Struct({
377
+ images: bound(
378
+ Schema.Array(
379
+ Schema.Struct({ url: Schema.String, description: Schema.optionalKey(Schema.String) }),
380
+ ),
381
+ ),
382
+ }),
383
+ Check: Schema.Struct({
384
+ label: text,
385
+ detail: Schema.optionalKey(text),
386
+ done: Schema.optionalKey(flag),
387
+ ...action,
388
+ }),
389
+ Entry: Schema.Struct({ placeholder: Schema.optionalKey(text), field: Schema.String, ...action }),
390
+ Playing: Schema.Struct({
391
+ title: text,
392
+ by: Schema.optionalKey(text),
393
+ art: Schema.optionalKey(text),
394
+ playing: flag,
395
+ at: Schema.optionalKey(number),
396
+ length: Schema.optionalKey(number),
397
+ asOf: Schema.optionalKey(number),
398
+ back: Schema.String,
399
+ toggle: Schema.String,
400
+ next: Schema.String,
401
+ }),
402
+ BarChart: Schema.Struct({
403
+ ...lines,
404
+ stacked: Schema.optionalKey(Schema.Boolean),
405
+ horizontal: Schema.optionalKey(Schema.Boolean),
406
+ }),
407
+ LineChart: Schema.Struct(lines),
408
+ AreaChart: Schema.Struct({ ...lines, stacked: Schema.optionalKey(Schema.Boolean) }),
409
+ Sparkline: Schema.Struct({
410
+ values: bound(Schema.Array(Schema.Finite)),
411
+ height: Schema.optionalKey(px),
412
+ }),
413
+ DonutChart: Schema.Struct({
414
+ ...figures,
415
+ slices: bound(Schema.Array(Schema.Struct({ label: Schema.String, value: Schema.Finite }))),
416
+ }),
417
+ ScatterChart: Schema.Struct({
418
+ series: bound(
419
+ Schema.Array(
420
+ Schema.Struct({
421
+ name: Schema.String,
422
+ points: Schema.Array(Schema.Tuple([Schema.Finite, Schema.Finite])),
423
+ }),
424
+ ).check(Schema.isMinLength(1), Schema.isMaxLength(3)),
425
+ ),
426
+ xLabel: Schema.optionalKey(Schema.String),
427
+ yLabel: Schema.optionalKey(Schema.String),
428
+ height: Schema.optionalKey(px),
429
+ }),
430
+ Histogram: Schema.Struct({
431
+ ...figures,
432
+ values: bound(Schema.Array(Schema.Finite)),
433
+ bins: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
434
+ height: Schema.optionalKey(px),
435
+ }),
436
+ CalendarHeatmap: Schema.Struct({
437
+ ...figures,
438
+ days: bound(
439
+ Schema.Array(
440
+ Schema.Struct({
441
+ date: Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}$/u)),
442
+ value: Schema.Finite,
443
+ }),
444
+ ),
445
+ ),
446
+ }),
447
+ Meter: Schema.Struct({
448
+ ...figures,
449
+ label: Schema.optionalKey(text),
450
+ value: number,
451
+ max: Schema.optionalKey(px),
452
+ }),
453
+ }
454
+
455
+ // ---- A2UI's basic catalog (`BASIC_CATALOG`), v1.0: its parts as the spec declares them
456
+
457
+ /** The basic catalog's icons by name. */
458
+ export const ICONS: readonly string[] = [
459
+ "accountCircle",
460
+ "add",
461
+ "arrowBack",
462
+ "arrowForward",
463
+ "attachFile",
464
+ "calendarToday",
465
+ "call",
466
+ "camera",
467
+ "check",
468
+ "close",
469
+ "delete",
470
+ "download",
471
+ "edit",
472
+ "event",
473
+ "error",
474
+ "fastForward",
475
+ "favorite",
476
+ "favoriteOff",
477
+ "folder",
478
+ "help",
479
+ "home",
480
+ "info",
481
+ "locationOn",
482
+ "lock",
483
+ "lockOpen",
484
+ "mail",
485
+ "menu",
486
+ "moreVert",
487
+ "moreHoriz",
488
+ "notificationsOff",
489
+ "notifications",
490
+ "pause",
491
+ "payment",
492
+ "person",
493
+ "phone",
494
+ "photo",
495
+ "play",
496
+ "print",
497
+ "refresh",
498
+ "rewind",
499
+ "search",
500
+ "send",
501
+ "settings",
502
+ "share",
503
+ "shoppingCart",
504
+ "skipNext",
505
+ "skipPrevious",
506
+ "star",
507
+ "starHalf",
508
+ "starOff",
509
+ "stop",
510
+ "upload",
511
+ "visibility",
512
+ "visibilityOff",
513
+ "volumeDown",
514
+ "volumeMute",
515
+ "volumeOff",
516
+ "volumeUp",
517
+ "warning",
518
+ ]
519
+ interface Weighted {
520
+ readonly weight?: number
521
+ }
522
+ /** What a Button does: an event the host handles, or a catalog function. */
523
+ export type Action =
524
+ | {
525
+ readonly event: {
526
+ readonly name: string
527
+ readonly userMessage?: Bound<string>
528
+ readonly context?: Readonly<Record<string, unknown>>
529
+ }
530
+ }
531
+ | { readonly functionCall: FunctionCall }
532
+ /** A check an input runs: a condition, and what's wrong when it fails. */
533
+ export interface CheckRule {
534
+ readonly condition: DataBinding | FunctionCall
535
+ readonly message?: string
536
+ }
537
+ type Checked = Weighted & { readonly checks?: readonly CheckRule[] }
538
+ type Justify =
539
+ | "start"
540
+ | "center"
541
+ | "end"
542
+ | "spaceBetween"
543
+ | "spaceAround"
544
+ | "spaceEvenly"
545
+ | "stretch"
546
+ type Align = "start" | "center" | "end" | "stretch"
547
+
548
+ /** Every part of A2UI's basic catalog, by name. */
549
+ export interface BasicParts {
550
+ readonly Text: Weighted & { readonly text: Bound<string>; readonly variant?: "caption" | "body" }
551
+ readonly Image: Weighted & {
552
+ readonly url: Bound<string>
553
+ readonly description?: Bound<string>
554
+ readonly fit?: "contain" | "cover" | "fill" | "none" | "scaleDown"
555
+ readonly variant?:
556
+ | "icon"
557
+ | "avatar"
558
+ | "smallFeature"
559
+ | "mediumFeature"
560
+ | "largeFeature"
561
+ | "header"
562
+ }
563
+ readonly Icon: Weighted & {
564
+ readonly name: string | { readonly svgPath: Bound<string> } | DataBinding
565
+ }
566
+ readonly Video: Weighted & { readonly url: Bound<string>; readonly posterUrl?: Bound<string> }
567
+ readonly AudioPlayer: Weighted & {
568
+ readonly url: Bound<string>
569
+ readonly description?: Bound<string>
570
+ }
571
+ readonly Row: Weighted & {
572
+ readonly children: ChildList
573
+ readonly justify?: Justify
574
+ readonly align?: Align
575
+ }
576
+ readonly Column: Weighted & {
577
+ readonly children: ChildList
578
+ readonly justify?: Justify
579
+ readonly align?: Align
580
+ }
581
+ readonly List: Weighted & {
582
+ readonly children: ChildList
583
+ readonly direction?: "vertical" | "horizontal"
584
+ readonly align?: Align
585
+ }
586
+ readonly Card: Weighted & { readonly child: string }
587
+ readonly Tabs: Weighted & {
588
+ readonly tabs: readonly { readonly title: Bound<string>; readonly child: string }[]
589
+ }
590
+ readonly Modal: Weighted & { readonly trigger: string; readonly content: string }
591
+ readonly Divider: Weighted & { readonly axis?: "horizontal" | "vertical" }
592
+ readonly Button: Checked & {
593
+ readonly child: string
594
+ readonly variant?: "default" | "primary" | "borderless"
595
+ readonly action: Action
596
+ }
597
+ readonly TextField: Checked & {
598
+ readonly label: Bound<string>
599
+ readonly value?: Bound<string>
600
+ readonly placeholder?: Bound<string>
601
+ readonly variant?: "longText" | "number" | "shortText" | "obscured"
602
+ }
603
+ readonly CheckBox: Checked & { readonly label: Bound<string>; readonly value: Bound<boolean> }
604
+ readonly ChoicePicker: Checked & {
605
+ readonly label?: Bound<string>
606
+ readonly variant?: "multipleSelection" | "mutuallyExclusive"
607
+ readonly options: readonly { readonly label: Bound<string>; readonly value: string }[]
608
+ readonly value: Bound<readonly string[]>
609
+ readonly displayStyle?: "checkbox" | "chips"
610
+ readonly filterable?: boolean
611
+ }
612
+ readonly Slider: Checked & {
613
+ readonly label?: Bound<string>
614
+ readonly min?: number
615
+ readonly max: number
616
+ readonly value: Bound<number>
617
+ readonly steps?: number
618
+ }
619
+ readonly DateTimeInput: Checked & {
620
+ readonly value: Bound<string>
621
+ readonly enableDate?: boolean
622
+ readonly enableTime?: boolean
623
+ readonly min?: Bound<string>
624
+ readonly max?: Bound<string>
625
+ readonly label?: Bound<string>
626
+ }
627
+ }
628
+
629
+ const weighted = { weight: Schema.optionalKey(Schema.Finite) }
630
+ const checked = {
631
+ ...weighted,
632
+ checks: Schema.optionalKey(
633
+ Schema.Array(
634
+ Schema.Struct({
635
+ condition: Schema.Union([binding, call]),
636
+ message: Schema.optionalKey(Schema.String),
637
+ }),
638
+ ),
639
+ ),
640
+ }
641
+ const justify = Schema.optionalKey(
642
+ Schema.Literals([
643
+ "start",
644
+ "center",
645
+ "end",
646
+ "spaceBetween",
647
+ "spaceAround",
648
+ "spaceEvenly",
649
+ "stretch",
650
+ ]),
651
+ )
652
+ const align = Schema.optionalKey(Schema.Literals(["start", "center", "end", "stretch"]))
653
+ const textList = bound(Schema.Array(Schema.String))
654
+
655
+ /** Each basic part's properties, to check a component by. */
656
+ export const BASIC_PARTS: { readonly [K in keyof BasicParts]: Schema.Codec<BasicParts[K]> } = {
657
+ Text: Schema.Struct({
658
+ ...weighted,
659
+ text,
660
+ variant: Schema.optionalKey(Schema.Literals(["caption", "body"])),
661
+ }),
662
+ Image: Schema.Struct({
663
+ ...weighted,
664
+ url: text,
665
+ description: Schema.optionalKey(text),
666
+ fit: Schema.optionalKey(Schema.Literals(["contain", "cover", "fill", "none", "scaleDown"])),
667
+ variant: Schema.optionalKey(
668
+ Schema.Literals([
669
+ "icon",
670
+ "avatar",
671
+ "smallFeature",
672
+ "mediumFeature",
673
+ "largeFeature",
674
+ "header",
675
+ ]),
676
+ ),
677
+ }),
678
+ Icon: Schema.Struct({
679
+ ...weighted,
680
+ name: Schema.Union([
681
+ Schema.String.check(Schema.makeFilter((n: string) => ICONS.includes(n) || `No icon ${n}`)),
682
+ Schema.Struct({ svgPath: text }),
683
+ binding,
684
+ ]),
685
+ }),
686
+ Video: Schema.Struct({ ...weighted, url: text, posterUrl: Schema.optionalKey(text) }),
687
+ AudioPlayer: Schema.Struct({ ...weighted, url: text, description: Schema.optionalKey(text) }),
688
+ Row: Schema.Struct({ ...weighted, children, justify, align }),
689
+ Column: Schema.Struct({ ...weighted, children, justify, align }),
690
+ List: Schema.Struct({
691
+ ...weighted,
692
+ children,
693
+ direction: Schema.optionalKey(Schema.Literals(["vertical", "horizontal"])),
694
+ align,
695
+ }),
696
+ Card: Schema.Struct({ ...weighted, child: Schema.String }),
697
+ Tabs: Schema.Struct({
698
+ ...weighted,
699
+ tabs: Schema.Array(Schema.Struct({ title: text, child: Schema.String })).check(
700
+ Schema.isMinLength(1),
701
+ ),
702
+ }),
703
+ Modal: Schema.Struct({ ...weighted, trigger: Schema.String, content: Schema.String }),
704
+ Divider: Schema.Struct({
705
+ ...weighted,
706
+ axis: Schema.optionalKey(Schema.Literals(["horizontal", "vertical"])),
707
+ }),
708
+ Button: Schema.Struct({
709
+ ...checked,
710
+ child: Schema.String,
711
+ variant: Schema.optionalKey(Schema.Literals(["default", "primary", "borderless"])),
712
+ action: Schema.Union([
713
+ Schema.Struct({
714
+ event: Schema.Struct({
715
+ name: Schema.String,
716
+ userMessage: Schema.optionalKey(text),
717
+ context: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
718
+ }),
719
+ }),
720
+ Schema.Struct({ functionCall: call }),
721
+ ]),
722
+ }),
723
+ TextField: Schema.Struct({
724
+ ...checked,
725
+ label: text,
726
+ value: Schema.optionalKey(text),
727
+ placeholder: Schema.optionalKey(text),
728
+ variant: Schema.optionalKey(Schema.Literals(["longText", "number", "shortText", "obscured"])),
729
+ }),
730
+ CheckBox: Schema.Struct({ ...checked, label: text, value: flag }),
731
+ ChoicePicker: Schema.Struct({
732
+ ...checked,
733
+ label: Schema.optionalKey(text),
734
+ variant: Schema.optionalKey(Schema.Literals(["multipleSelection", "mutuallyExclusive"])),
735
+ options: Schema.Array(Schema.Struct({ label: text, value: Schema.String })),
736
+ value: textList,
737
+ displayStyle: Schema.optionalKey(Schema.Literals(["checkbox", "chips"])),
738
+ filterable: Schema.optionalKey(Schema.Boolean),
739
+ }),
740
+ Slider: Schema.Struct({
741
+ ...checked,
742
+ label: Schema.optionalKey(text),
743
+ min: Schema.optionalKey(Schema.Finite),
744
+ max: Schema.Finite,
745
+ value: number,
746
+ steps: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(1))),
747
+ }),
748
+ DateTimeInput: Schema.Struct({
749
+ ...checked,
750
+ value: text,
751
+ enableDate: Schema.optionalKey(Schema.Boolean),
752
+ enableTime: Schema.optionalKey(Schema.Boolean),
753
+ min: Schema.optionalKey(text),
754
+ max: Schema.optionalKey(text),
755
+ label: Schema.optionalKey(text),
756
+ }),
757
+ }