switch-ext-kit 0.0.0-stage → 0.2.1

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,810 @@
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
+ /**
177
+ * A document its extension reads: in a chat or a space, a line that opens it; in a window of its
178
+ * own (its `widget` with `{ doc }`), the reader, its words a section at a time from `tools.content`
179
+ * (`{ doc }` gives `{ sections: [{ label?, markdown }] }`), a selection's lookup from `tools.define`
180
+ * (`{ term | url, doc }`), threads asked with `tools.ask` (`{ doc, thread, question, quote? }`) and
181
+ * highlights with `tools.highlight` and `tools.unhighlight`. A passage (`quote`) is
182
+ * `{ section, exact, prefix?, suffix? }`.
183
+ */
184
+ export interface Document {
185
+ readonly doc: Bound<string>
186
+ readonly title: Bound<string>
187
+ /** Its kind (`pdf` numbers its pages). */
188
+ readonly format?: Bound<string>
189
+ /** Its size, in a few words. */
190
+ readonly detail?: Bound<string>
191
+ /** Moves when its words change, so they're read again. */
192
+ readonly version?: Bound<number>
193
+ readonly highlights?: Bound<readonly unknown[]>
194
+ readonly threads?: Bound<readonly unknown[]>
195
+ /** A thread to show open. */
196
+ readonly open?: Bound<string>
197
+ readonly threadCount?: Bound<number>
198
+ /** The widget that is the document in its own window. */
199
+ readonly widget: string
200
+ readonly tools: {
201
+ readonly content: string
202
+ readonly define?: string
203
+ readonly ask?: string
204
+ readonly highlight?: string
205
+ readonly unhighlight?: string
206
+ }
207
+ }
208
+
209
+ /** A line to write in: Enter calls `action` with `args` and the words under `field`. */
210
+ export interface Entry {
211
+ readonly placeholder?: Bound<string>
212
+ readonly action: string
213
+ readonly args?: Bound<Readonly<Record<string, unknown>>>
214
+ readonly field: string
215
+ }
216
+
217
+ // ---- Charts: plain data in, drawn in a fixed palette (never cycled) in the house look
218
+
219
+ /** How a chart's figures read: a prefix and a suffix round each ("$", "%", " kg"). */
220
+ export interface Figures {
221
+ readonly prefix?: string
222
+ readonly suffix?: string
223
+ }
224
+
225
+ /** A named series: a value for each label, or null for none. */
226
+ export interface Series {
227
+ readonly name: string
228
+ readonly values: readonly (number | null)[]
229
+ }
230
+
231
+ /** Bars for each label: a series each, side by side or stacked; columns, or rows when horizontal. */
232
+ export interface BarChart extends Figures {
233
+ readonly labels: Bound<readonly string[]>
234
+ /** One to eight. */
235
+ readonly series: Bound<readonly Series[]>
236
+ readonly stacked?: boolean
237
+ readonly horizontal?: boolean
238
+ /** Px, else its own. */
239
+ readonly height?: number
240
+ }
241
+
242
+ /** A line per series over labels evenly spaced along the bottom (days, months). */
243
+ export interface LineChart extends Figures {
244
+ readonly labels: Bound<readonly string[]>
245
+ /** One to eight. */
246
+ readonly series: Bound<readonly Series[]>
247
+ readonly height?: number
248
+ }
249
+
250
+ /** A line chart filled under each line, or stacked. */
251
+ export interface AreaChart extends LineChart {
252
+ readonly stacked?: boolean
253
+ }
254
+
255
+ /** A trend as one small line, its latest point marked: a line's height unless `height`. */
256
+ export interface Sparkline {
257
+ readonly values: Bound<readonly number[]>
258
+ readonly height?: number
259
+ }
260
+
261
+ export interface Slice {
262
+ readonly label: string
263
+ readonly value: number
264
+ }
265
+
266
+ /** Parts of a whole, round a ring with the total in it; six slices at most read at a glance. */
267
+ export interface DonutChart extends Figures {
268
+ readonly slices: Bound<readonly Slice[]>
269
+ }
270
+
271
+ export interface Points {
272
+ readonly name: string
273
+ /** `[x, y]` each. */
274
+ readonly points: readonly (readonly [number, number])[]
275
+ }
276
+
277
+ /** Points by two measures; three series at most stay apart. */
278
+ export interface ScatterChart {
279
+ readonly series: Bound<readonly Points[]>
280
+ readonly xLabel?: string
281
+ readonly yLabel?: string
282
+ readonly height?: number
283
+ }
284
+
285
+ /** How raw values spread, counted into `bins` (else its own) bars. */
286
+ export interface Histogram extends Figures {
287
+ readonly values: Bound<readonly number[]>
288
+ readonly bins?: number
289
+ readonly height?: number
290
+ }
291
+
292
+ export interface Day {
293
+ /** `YYYY-MM-DD`. */
294
+ readonly date: string
295
+ readonly value: number
296
+ }
297
+
298
+ /** A value per day, as weeks of squares, darker for more. */
299
+ export interface CalendarHeatmap extends Figures {
300
+ readonly days: Bound<readonly Day[]>
301
+ }
302
+
303
+ /** How full something is: a line with its label, a track filled to `value` of `max` (100), and the figure. */
304
+ export interface Meter extends Figures {
305
+ readonly label?: Bound<string>
306
+ readonly value: Bound<number>
307
+ readonly max?: number
308
+ }
309
+
310
+ /** Every part of Switch's catalog, by name. */
311
+ export interface SwitchParts {
312
+ readonly Line: Line
313
+ readonly Slot: Slot
314
+ readonly Field: Field
315
+ readonly Title: Title
316
+ readonly Row: Row
317
+ readonly Pick: Pick
318
+ readonly Feed: Feed
319
+ readonly Gallery: Gallery
320
+ readonly Check: Check
321
+ readonly Entry: Entry
322
+ readonly Playing: Playing
323
+ readonly Document: Document
324
+ readonly BarChart: BarChart
325
+ readonly LineChart: LineChart
326
+ readonly AreaChart: AreaChart
327
+ readonly Sparkline: Sparkline
328
+ readonly DonutChart: DonutChart
329
+ readonly ScatterChart: ScatterChart
330
+ readonly Histogram: Histogram
331
+ readonly CalendarHeatmap: CalendarHeatmap
332
+ readonly Meter: Meter
333
+ }
334
+
335
+ /** A component of Switch's catalog: its id, its part and the part's properties. */
336
+ export type SwitchComponent = {
337
+ readonly [K in keyof SwitchParts]: { readonly id: string; readonly component: K } & SwitchParts[K]
338
+ }[keyof SwitchParts]
339
+
340
+ const action = {
341
+ action: Schema.String,
342
+ args: Schema.optionalKey(bound(Schema.Record(Schema.String, Schema.Unknown))),
343
+ }
344
+ const figures = {
345
+ prefix: Schema.optionalKey(Schema.String),
346
+ suffix: Schema.optionalKey(Schema.String),
347
+ }
348
+ const series = bound(
349
+ Schema.Array(
350
+ Schema.Struct({ name: Schema.String, values: Schema.Array(Schema.NullOr(Schema.Finite)) }),
351
+ ).check(Schema.isMinLength(1), Schema.isMaxLength(8)),
352
+ )
353
+ const lines = {
354
+ ...figures,
355
+ labels: bound(Schema.Array(Schema.String)),
356
+ series,
357
+ height: Schema.optionalKey(px),
358
+ }
359
+
360
+ /** Each part's properties, to check a component by. */
361
+ export const SWITCH_PARTS: { readonly [K in keyof SwitchParts]: Schema.Codec<SwitchParts[K]> } = {
362
+ Line: Schema.Struct({
363
+ label: text,
364
+ running: Schema.optionalKey(flag),
365
+ ringing: Schema.optionalKey(flag),
366
+ left: Schema.optionalKey(number),
367
+ elapsed: Schema.optionalKey(number),
368
+ asOf: Schema.optionalKey(number),
369
+ }),
370
+ Slot: Schema.Struct({
371
+ time: text,
372
+ title: text,
373
+ running: Schema.optionalKey(flag),
374
+ needsYou: Schema.optionalKey(flag),
375
+ conflict: Schema.optionalKey(flag),
376
+ }),
377
+ Field: Schema.Struct({ label: text, value: text, alert: Schema.optionalKey(flag) }),
378
+ Title: Schema.Struct({ label: text, needsYou: Schema.optionalKey(flag) }),
379
+ Row: Schema.Struct({
380
+ label: text,
381
+ mark: Schema.optionalKey(text),
382
+ detail: Schema.optionalKey(text),
383
+ alert: Schema.optionalKey(flag),
384
+ values: Schema.optionalKey(bound(Schema.Array(Schema.String))),
385
+ progress: Schema.optionalKey(bound(Schema.NullOr(Schema.Finite))),
386
+ endsAt: Schema.optionalKey(bound(Schema.NullOr(Schema.Finite))),
387
+ children: Schema.optionalKey(children),
388
+ url: Schema.optionalKey(text),
389
+ }),
390
+ Pick: Schema.Struct({
391
+ label: text,
392
+ swatch: Schema.optionalKey(text),
393
+ strong: Schema.optionalKey(flag),
394
+ title: Schema.optionalKey(text),
395
+ groups: Schema.Array(
396
+ Schema.Struct({
397
+ key: Schema.String,
398
+ choices: Schema.Array(Schema.String),
399
+ swatches: Schema.optionalKey(Schema.Boolean),
400
+ }),
401
+ ),
402
+ current: Schema.optionalKey(bound(Schema.Record(Schema.String, Schema.Unknown))),
403
+ ...action,
404
+ }),
405
+ Feed: Schema.Struct({
406
+ ...action,
407
+ every: Schema.optionalKey(px),
408
+ ratio: Schema.optionalKey(px),
409
+ }),
410
+ Gallery: Schema.Struct({
411
+ images: bound(
412
+ Schema.Array(
413
+ Schema.Struct({ url: Schema.String, description: Schema.optionalKey(Schema.String) }),
414
+ ),
415
+ ),
416
+ }),
417
+ Check: Schema.Struct({
418
+ label: text,
419
+ detail: Schema.optionalKey(text),
420
+ done: Schema.optionalKey(flag),
421
+ ...action,
422
+ }),
423
+ Entry: Schema.Struct({ placeholder: Schema.optionalKey(text), field: Schema.String, ...action }),
424
+ Playing: Schema.Struct({
425
+ title: text,
426
+ by: Schema.optionalKey(text),
427
+ art: Schema.optionalKey(text),
428
+ playing: flag,
429
+ at: Schema.optionalKey(number),
430
+ length: Schema.optionalKey(number),
431
+ asOf: Schema.optionalKey(number),
432
+ back: Schema.String,
433
+ toggle: Schema.String,
434
+ next: Schema.String,
435
+ }),
436
+ Document: Schema.Struct({
437
+ doc: text,
438
+ title: text,
439
+ format: Schema.optionalKey(text),
440
+ detail: Schema.optionalKey(text),
441
+ version: Schema.optionalKey(number),
442
+ highlights: Schema.optionalKey(bound(Schema.Array(Schema.Unknown))),
443
+ threads: Schema.optionalKey(bound(Schema.Array(Schema.Unknown))),
444
+ open: Schema.optionalKey(text),
445
+ threadCount: Schema.optionalKey(number),
446
+ widget: Schema.String,
447
+ tools: Schema.Struct({
448
+ content: Schema.String,
449
+ define: Schema.optionalKey(Schema.String),
450
+ ask: Schema.optionalKey(Schema.String),
451
+ highlight: Schema.optionalKey(Schema.String),
452
+ unhighlight: Schema.optionalKey(Schema.String),
453
+ }),
454
+ }),
455
+ BarChart: Schema.Struct({
456
+ ...lines,
457
+ stacked: Schema.optionalKey(Schema.Boolean),
458
+ horizontal: Schema.optionalKey(Schema.Boolean),
459
+ }),
460
+ LineChart: Schema.Struct(lines),
461
+ AreaChart: Schema.Struct({ ...lines, stacked: Schema.optionalKey(Schema.Boolean) }),
462
+ Sparkline: Schema.Struct({
463
+ values: bound(Schema.Array(Schema.Finite)),
464
+ height: Schema.optionalKey(px),
465
+ }),
466
+ DonutChart: Schema.Struct({
467
+ ...figures,
468
+ slices: bound(Schema.Array(Schema.Struct({ label: Schema.String, value: Schema.Finite }))),
469
+ }),
470
+ ScatterChart: Schema.Struct({
471
+ series: bound(
472
+ Schema.Array(
473
+ Schema.Struct({
474
+ name: Schema.String,
475
+ points: Schema.Array(Schema.Tuple([Schema.Finite, Schema.Finite])),
476
+ }),
477
+ ).check(Schema.isMinLength(1), Schema.isMaxLength(3)),
478
+ ),
479
+ xLabel: Schema.optionalKey(Schema.String),
480
+ yLabel: Schema.optionalKey(Schema.String),
481
+ height: Schema.optionalKey(px),
482
+ }),
483
+ Histogram: Schema.Struct({
484
+ ...figures,
485
+ values: bound(Schema.Array(Schema.Finite)),
486
+ bins: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
487
+ height: Schema.optionalKey(px),
488
+ }),
489
+ CalendarHeatmap: Schema.Struct({
490
+ ...figures,
491
+ days: bound(
492
+ Schema.Array(
493
+ Schema.Struct({
494
+ date: Schema.String.check(Schema.isPattern(/^\d{4}-\d{2}-\d{2}$/u)),
495
+ value: Schema.Finite,
496
+ }),
497
+ ),
498
+ ),
499
+ }),
500
+ Meter: Schema.Struct({
501
+ ...figures,
502
+ label: Schema.optionalKey(text),
503
+ value: number,
504
+ max: Schema.optionalKey(px),
505
+ }),
506
+ }
507
+
508
+ // ---- A2UI's basic catalog (`BASIC_CATALOG`), v1.0: its parts as the spec declares them
509
+
510
+ /** The basic catalog's icons by name. */
511
+ export const ICONS: readonly string[] = [
512
+ "accountCircle",
513
+ "add",
514
+ "arrowBack",
515
+ "arrowForward",
516
+ "attachFile",
517
+ "calendarToday",
518
+ "call",
519
+ "camera",
520
+ "check",
521
+ "close",
522
+ "delete",
523
+ "download",
524
+ "edit",
525
+ "event",
526
+ "error",
527
+ "fastForward",
528
+ "favorite",
529
+ "favoriteOff",
530
+ "folder",
531
+ "help",
532
+ "home",
533
+ "info",
534
+ "locationOn",
535
+ "lock",
536
+ "lockOpen",
537
+ "mail",
538
+ "menu",
539
+ "moreVert",
540
+ "moreHoriz",
541
+ "notificationsOff",
542
+ "notifications",
543
+ "pause",
544
+ "payment",
545
+ "person",
546
+ "phone",
547
+ "photo",
548
+ "play",
549
+ "print",
550
+ "refresh",
551
+ "rewind",
552
+ "search",
553
+ "send",
554
+ "settings",
555
+ "share",
556
+ "shoppingCart",
557
+ "skipNext",
558
+ "skipPrevious",
559
+ "star",
560
+ "starHalf",
561
+ "starOff",
562
+ "stop",
563
+ "upload",
564
+ "visibility",
565
+ "visibilityOff",
566
+ "volumeDown",
567
+ "volumeMute",
568
+ "volumeOff",
569
+ "volumeUp",
570
+ "warning",
571
+ ]
572
+ interface Weighted {
573
+ readonly weight?: number
574
+ }
575
+ /** What a Button does: an event the host handles, or a catalog function. */
576
+ export type Action =
577
+ | {
578
+ readonly event: {
579
+ readonly name: string
580
+ readonly userMessage?: Bound<string>
581
+ readonly context?: Readonly<Record<string, unknown>>
582
+ }
583
+ }
584
+ | { readonly functionCall: FunctionCall }
585
+ /** A check an input runs: a condition, and what's wrong when it fails. */
586
+ export interface CheckRule {
587
+ readonly condition: DataBinding | FunctionCall
588
+ readonly message?: string
589
+ }
590
+ type Checked = Weighted & { readonly checks?: readonly CheckRule[] }
591
+ type Justify =
592
+ | "start"
593
+ | "center"
594
+ | "end"
595
+ | "spaceBetween"
596
+ | "spaceAround"
597
+ | "spaceEvenly"
598
+ | "stretch"
599
+ type Align = "start" | "center" | "end" | "stretch"
600
+
601
+ /** Every part of A2UI's basic catalog, by name. */
602
+ export interface BasicParts {
603
+ readonly Text: Weighted & { readonly text: Bound<string>; readonly variant?: "caption" | "body" }
604
+ readonly Image: Weighted & {
605
+ readonly url: Bound<string>
606
+ readonly description?: Bound<string>
607
+ readonly fit?: "contain" | "cover" | "fill" | "none" | "scaleDown"
608
+ readonly variant?:
609
+ | "icon"
610
+ | "avatar"
611
+ | "smallFeature"
612
+ | "mediumFeature"
613
+ | "largeFeature"
614
+ | "header"
615
+ }
616
+ readonly Icon: Weighted & {
617
+ readonly name: string | { readonly svgPath: Bound<string> } | DataBinding
618
+ }
619
+ readonly Video: Weighted & { readonly url: Bound<string>; readonly posterUrl?: Bound<string> }
620
+ readonly AudioPlayer: Weighted & {
621
+ readonly url: Bound<string>
622
+ readonly description?: Bound<string>
623
+ }
624
+ readonly Row: Weighted & {
625
+ readonly children: ChildList
626
+ readonly justify?: Justify
627
+ readonly align?: Align
628
+ }
629
+ readonly Column: Weighted & {
630
+ readonly children: ChildList
631
+ readonly justify?: Justify
632
+ readonly align?: Align
633
+ }
634
+ readonly List: Weighted & {
635
+ readonly children: ChildList
636
+ readonly direction?: "vertical" | "horizontal"
637
+ readonly align?: Align
638
+ }
639
+ readonly Card: Weighted & { readonly child: string }
640
+ readonly Tabs: Weighted & {
641
+ readonly tabs: readonly { readonly title: Bound<string>; readonly child: string }[]
642
+ }
643
+ readonly Modal: Weighted & { readonly trigger: string; readonly content: string }
644
+ readonly Divider: Weighted & { readonly axis?: "horizontal" | "vertical" }
645
+ readonly Button: Checked & {
646
+ readonly child: string
647
+ readonly variant?: "default" | "primary" | "borderless"
648
+ readonly action: Action
649
+ }
650
+ readonly TextField: Checked & {
651
+ readonly label: Bound<string>
652
+ readonly value?: Bound<string>
653
+ readonly placeholder?: Bound<string>
654
+ readonly variant?: "longText" | "number" | "shortText" | "obscured"
655
+ }
656
+ readonly CheckBox: Checked & { readonly label: Bound<string>; readonly value: Bound<boolean> }
657
+ readonly ChoicePicker: Checked & {
658
+ readonly label?: Bound<string>
659
+ readonly variant?: "multipleSelection" | "mutuallyExclusive"
660
+ readonly options: readonly { readonly label: Bound<string>; readonly value: string }[]
661
+ readonly value: Bound<readonly string[]>
662
+ readonly displayStyle?: "checkbox" | "chips"
663
+ readonly filterable?: boolean
664
+ }
665
+ readonly Slider: Checked & {
666
+ readonly label?: Bound<string>
667
+ readonly min?: number
668
+ readonly max: number
669
+ readonly value: Bound<number>
670
+ readonly steps?: number
671
+ }
672
+ readonly DateTimeInput: Checked & {
673
+ readonly value: Bound<string>
674
+ readonly enableDate?: boolean
675
+ readonly enableTime?: boolean
676
+ readonly min?: Bound<string>
677
+ readonly max?: Bound<string>
678
+ readonly label?: Bound<string>
679
+ }
680
+ }
681
+
682
+ const weighted = { weight: Schema.optionalKey(Schema.Finite) }
683
+ const checked = {
684
+ ...weighted,
685
+ checks: Schema.optionalKey(
686
+ Schema.Array(
687
+ Schema.Struct({
688
+ condition: Schema.Union([binding, call]),
689
+ message: Schema.optionalKey(Schema.String),
690
+ }),
691
+ ),
692
+ ),
693
+ }
694
+ const justify = Schema.optionalKey(
695
+ Schema.Literals([
696
+ "start",
697
+ "center",
698
+ "end",
699
+ "spaceBetween",
700
+ "spaceAround",
701
+ "spaceEvenly",
702
+ "stretch",
703
+ ]),
704
+ )
705
+ const align = Schema.optionalKey(Schema.Literals(["start", "center", "end", "stretch"]))
706
+ const textList = bound(Schema.Array(Schema.String))
707
+
708
+ /** Each basic part's properties, to check a component by. */
709
+ export const BASIC_PARTS: { readonly [K in keyof BasicParts]: Schema.Codec<BasicParts[K]> } = {
710
+ Text: Schema.Struct({
711
+ ...weighted,
712
+ text,
713
+ variant: Schema.optionalKey(Schema.Literals(["caption", "body"])),
714
+ }),
715
+ Image: Schema.Struct({
716
+ ...weighted,
717
+ url: text,
718
+ description: Schema.optionalKey(text),
719
+ fit: Schema.optionalKey(Schema.Literals(["contain", "cover", "fill", "none", "scaleDown"])),
720
+ variant: Schema.optionalKey(
721
+ Schema.Literals([
722
+ "icon",
723
+ "avatar",
724
+ "smallFeature",
725
+ "mediumFeature",
726
+ "largeFeature",
727
+ "header",
728
+ ]),
729
+ ),
730
+ }),
731
+ Icon: Schema.Struct({
732
+ ...weighted,
733
+ name: Schema.Union([
734
+ Schema.String.check(Schema.makeFilter((n: string) => ICONS.includes(n) || `No icon ${n}`)),
735
+ Schema.Struct({ svgPath: text }),
736
+ binding,
737
+ ]),
738
+ }),
739
+ Video: Schema.Struct({ ...weighted, url: text, posterUrl: Schema.optionalKey(text) }),
740
+ AudioPlayer: Schema.Struct({ ...weighted, url: text, description: Schema.optionalKey(text) }),
741
+ Row: Schema.Struct({ ...weighted, children, justify, align }),
742
+ Column: Schema.Struct({ ...weighted, children, justify, align }),
743
+ List: Schema.Struct({
744
+ ...weighted,
745
+ children,
746
+ direction: Schema.optionalKey(Schema.Literals(["vertical", "horizontal"])),
747
+ align,
748
+ }),
749
+ Card: Schema.Struct({ ...weighted, child: Schema.String }),
750
+ Tabs: Schema.Struct({
751
+ ...weighted,
752
+ tabs: Schema.Array(Schema.Struct({ title: text, child: Schema.String })).check(
753
+ Schema.isMinLength(1),
754
+ ),
755
+ }),
756
+ Modal: Schema.Struct({ ...weighted, trigger: Schema.String, content: Schema.String }),
757
+ Divider: Schema.Struct({
758
+ ...weighted,
759
+ axis: Schema.optionalKey(Schema.Literals(["horizontal", "vertical"])),
760
+ }),
761
+ Button: Schema.Struct({
762
+ ...checked,
763
+ child: Schema.String,
764
+ variant: Schema.optionalKey(Schema.Literals(["default", "primary", "borderless"])),
765
+ action: Schema.Union([
766
+ Schema.Struct({
767
+ event: Schema.Struct({
768
+ name: Schema.String,
769
+ userMessage: Schema.optionalKey(text),
770
+ context: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
771
+ }),
772
+ }),
773
+ Schema.Struct({ functionCall: call }),
774
+ ]),
775
+ }),
776
+ TextField: Schema.Struct({
777
+ ...checked,
778
+ label: text,
779
+ value: Schema.optionalKey(text),
780
+ placeholder: Schema.optionalKey(text),
781
+ variant: Schema.optionalKey(Schema.Literals(["longText", "number", "shortText", "obscured"])),
782
+ }),
783
+ CheckBox: Schema.Struct({ ...checked, label: text, value: flag }),
784
+ ChoicePicker: Schema.Struct({
785
+ ...checked,
786
+ label: Schema.optionalKey(text),
787
+ variant: Schema.optionalKey(Schema.Literals(["multipleSelection", "mutuallyExclusive"])),
788
+ options: Schema.Array(Schema.Struct({ label: text, value: Schema.String })),
789
+ value: textList,
790
+ displayStyle: Schema.optionalKey(Schema.Literals(["checkbox", "chips"])),
791
+ filterable: Schema.optionalKey(Schema.Boolean),
792
+ }),
793
+ Slider: Schema.Struct({
794
+ ...checked,
795
+ label: Schema.optionalKey(text),
796
+ min: Schema.optionalKey(Schema.Finite),
797
+ max: Schema.Finite,
798
+ value: number,
799
+ steps: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThanOrEqualTo(1))),
800
+ }),
801
+ DateTimeInput: Schema.Struct({
802
+ ...checked,
803
+ value: text,
804
+ enableDate: Schema.optionalKey(Schema.Boolean),
805
+ enableTime: Schema.optionalKey(Schema.Boolean),
806
+ min: Schema.optionalKey(text),
807
+ max: Schema.optionalKey(text),
808
+ label: Schema.optionalKey(text),
809
+ }),
810
+ }