@arkitektio/bsx 6.8.0 → 7.0.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 (155) hide show
  1. package/dist/bsx/declared.d.ts +25 -0
  2. package/dist/bsx/declared.d.ts.map +1 -1
  3. package/dist/bsx/declared.js +59 -0
  4. package/dist/bsx/declared.js.map +1 -1
  5. package/dist/bsx/infer.d.ts.map +1 -1
  6. package/dist/bsx/infer.js +4 -2
  7. package/dist/bsx/infer.js.map +1 -1
  8. package/dist/bsx/language.d.ts.map +1 -1
  9. package/dist/bsx/language.js +17 -12
  10. package/dist/bsx/language.js.map +1 -1
  11. package/dist/bsx/references.d.ts.map +1 -1
  12. package/dist/bsx/references.js +139 -37
  13. package/dist/bsx/references.js.map +1 -1
  14. package/dist/catalogs/index.d.ts +191 -98
  15. package/dist/catalogs/index.d.ts.map +1 -1
  16. package/dist/catalogs/parts/data.d.ts +2 -2
  17. package/dist/catalogs/parts/data.d.ts.map +1 -1
  18. package/dist/catalogs/parts/data.js +2 -3
  19. package/dist/catalogs/parts/data.js.map +1 -1
  20. package/dist/catalogs/parts/feedback.d.ts +6 -6
  21. package/dist/catalogs/parts/forms.d.ts +8 -8
  22. package/dist/catalogs/parts/icons.d.ts +4 -4
  23. package/dist/catalogs/parts/index.d.ts +48 -48
  24. package/dist/catalogs/parts/navigation.d.ts +8 -8
  25. package/dist/catalogs/parts/overlays.d.ts +22 -22
  26. package/dist/catalogs/parts/run.d.ts.map +1 -1
  27. package/dist/catalogs/parts/run.js +4 -5
  28. package/dist/catalogs/parts/run.js.map +1 -1
  29. package/dist/catalogs/parts/scene.d.ts.map +1 -1
  30. package/dist/catalogs/parts/scene.js +7 -14
  31. package/dist/catalogs/parts/scene.js.map +1 -1
  32. package/dist/catalogs/parts/structure.d.ts.map +1 -1
  33. package/dist/catalogs/parts/structure.js +2 -3
  34. package/dist/catalogs/parts/structure.js.map +1 -1
  35. package/dist/catalogs/parts/toast.d.ts.map +1 -1
  36. package/dist/catalogs/parts/toast.js +2 -1
  37. package/dist/catalogs/parts/toast.js.map +1 -1
  38. package/dist/catalogs/props.d.ts +23 -0
  39. package/dist/catalogs/props.d.ts.map +1 -1
  40. package/dist/catalogs/props.js +56 -4
  41. package/dist/catalogs/props.js.map +1 -1
  42. package/dist/catalogs/scene.d.ts +134 -127
  43. package/dist/catalogs/scene.d.ts.map +1 -1
  44. package/dist/catalogs/scene.js +5 -3
  45. package/dist/catalogs/scene.js.map +1 -1
  46. package/dist/catalogs/shadcn.d.ts +79 -41
  47. package/dist/catalogs/shadcn.d.ts.map +1 -1
  48. package/dist/catalogs/shadcn.js +13 -13
  49. package/dist/catalogs/shadcn.js.map +1 -1
  50. package/dist/catalogs/structure.d.ts +9 -2
  51. package/dist/catalogs/structure.d.ts.map +1 -1
  52. package/dist/catalogs/structure.js +1 -1
  53. package/dist/catalogs/structure.js.map +1 -1
  54. package/dist/catalogs/ui.d.ts +935 -892
  55. package/dist/catalogs/ui.d.ts.map +1 -1
  56. package/dist/catalogs/ui.js +16 -14
  57. package/dist/catalogs/ui.js.map +1 -1
  58. package/dist/catalogs/zodToPort.d.ts +9 -0
  59. package/dist/catalogs/zodToPort.d.ts.map +1 -0
  60. package/dist/catalogs/zodToPort.js +156 -0
  61. package/dist/catalogs/zodToPort.js.map +1 -0
  62. package/dist/catalogs.d.ts +4 -1
  63. package/dist/catalogs.d.ts.map +1 -1
  64. package/dist/catalogs.js +3 -0
  65. package/dist/catalogs.js.map +1 -1
  66. package/dist/index.d.ts +2 -0
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +2 -0
  69. package/dist/index.js.map +1 -1
  70. package/dist/ports/rekuest.d.ts +6 -0
  71. package/dist/ports/rekuest.d.ts.map +1 -1
  72. package/dist/ports/rekuest.js +6 -0
  73. package/dist/ports/rekuest.js.map +1 -1
  74. package/dist/renderer/bloks/control.d.ts +7 -1
  75. package/dist/renderer/bloks/control.d.ts.map +1 -1
  76. package/dist/renderer/bloks/control.js +20 -2
  77. package/dist/renderer/bloks/control.js.map +1 -1
  78. package/dist/renderer/bloks/data.d.ts +2 -2
  79. package/dist/renderer/bloks/feedback.d.ts +6 -6
  80. package/dist/renderer/bloks/forms.d.ts +8 -8
  81. package/dist/renderer/bloks/icons.d.ts +2 -2
  82. package/dist/renderer/bloks/index.d.ts +48 -48
  83. package/dist/renderer/bloks/navigation.d.ts +8 -8
  84. package/dist/renderer/bloks/overlays.d.ts +22 -22
  85. package/dist/renderer/runtime/components.d.ts +6 -8
  86. package/dist/renderer/runtime/components.d.ts.map +1 -1
  87. package/dist/renderer/runtime/components.js.map +1 -1
  88. package/dist/renderer/runtime/describe.d.ts +5 -12
  89. package/dist/renderer/runtime/describe.d.ts.map +1 -1
  90. package/dist/renderer/runtime/describe.js +25 -89
  91. package/dist/renderer/runtime/describe.js.map +1 -1
  92. package/dist/renderer/runtime/hooks.d.ts.map +1 -1
  93. package/dist/renderer/runtime/hooks.js +3 -1
  94. package/dist/renderer/runtime/hooks.js.map +1 -1
  95. package/dist/renderer/runtime/schemas.d.ts +8 -6
  96. package/dist/renderer/runtime/schemas.d.ts.map +1 -1
  97. package/dist/renderer/runtime/schemas.js +40 -16
  98. package/dist/renderer/runtime/schemas.js.map +1 -1
  99. package/dist/shadcn.d.ts +48 -48
  100. package/dist/spec/bsx_v2.json +1421 -19
  101. package/dist/spec/catalogs/base@4.json +18738 -5273
  102. package/dist/spec/catalogs/base@4.json.js +18738 -5273
  103. package/dist/spec/catalogs/orkestrator@1.json +532 -126
  104. package/dist/spec/catalogs/orkestrator@1.json.js +532 -126
  105. package/dist/spec/catalogs.d.ts +3 -11
  106. package/dist/spec/catalogs.d.ts.map +1 -1
  107. package/dist/spec/catalogs.js +13 -11
  108. package/dist/spec/catalogs.js.map +1 -1
  109. package/dist/spec/fit.d.ts +21 -0
  110. package/dist/spec/fit.d.ts.map +1 -0
  111. package/dist/spec/fit.js +114 -0
  112. package/dist/spec/fit.js.map +1 -0
  113. package/dist/spec/ports.d.ts +56 -0
  114. package/dist/spec/ports.d.ts.map +1 -0
  115. package/dist/spec/ports.js +174 -0
  116. package/dist/spec/ports.js.map +1 -0
  117. package/dist/spec/vocabulary.json +12 -5
  118. package/dist/spec/vocabulary.json.js +12 -5
  119. package/package.json +1 -1
  120. package/src/bsx/declared.ts +60 -0
  121. package/src/bsx/infer.test.ts +1 -1
  122. package/src/bsx/infer.ts +4 -2
  123. package/src/bsx/language.ts +16 -11
  124. package/src/bsx/logo.test.ts +47 -0
  125. package/src/bsx/references.ts +170 -39
  126. package/src/catalogs/parts/data.ts +3 -2
  127. package/src/catalogs/parts/run.ts +9 -7
  128. package/src/catalogs/parts/scene.ts +7 -14
  129. package/src/catalogs/parts/structure.ts +2 -3
  130. package/src/catalogs/parts/toast.ts +5 -1
  131. package/src/catalogs/props.ts +64 -4
  132. package/src/catalogs/scene.ts +5 -3
  133. package/src/catalogs/shadcn.ts +13 -13
  134. package/src/catalogs/structure.ts +1 -1
  135. package/src/catalogs/ui.ts +16 -14
  136. package/src/catalogs/zodToPort.test.ts +96 -0
  137. package/src/catalogs/zodToPort.ts +177 -0
  138. package/src/catalogs.ts +4 -1
  139. package/src/index.ts +2 -0
  140. package/src/ports/rekuest.ts +6 -0
  141. package/src/renderer/bloks/control.tsx +26 -2
  142. package/src/renderer/runtime/catalog.test.ts +12 -8
  143. package/src/renderer/runtime/components.tsx +5 -8
  144. package/src/renderer/runtime/describe.ts +25 -100
  145. package/src/renderer/runtime/hooks.ts +3 -1
  146. package/src/renderer/runtime/schemas.ts +51 -17
  147. package/src/spec/bsx_v2.json +1421 -19
  148. package/src/spec/catalogs/base@4.json +18738 -5273
  149. package/src/spec/catalogs/orkestrator@1.json +532 -126
  150. package/src/spec/catalogs.ts +14 -19
  151. package/src/spec/fit.test.ts +65 -0
  152. package/src/spec/fit.ts +114 -0
  153. package/src/spec/ports.ts +172 -0
  154. package/src/spec/spec.test.ts +5 -2
  155. package/src/spec/vocabulary.json +12 -5
@@ -9,6 +9,18 @@ import {blokViewFor, defaultBlokView, type BlokView, type SpecComponent} from '.
9
9
  import {PICK_FUNCTION, TEXT_NODE} from './parse';
10
10
  import {AGENTS_ROOT, PICK_VERB, REFERENCE_SEPARATOR} from './expr';
11
11
  import {valueFitsPort} from '../spec/locals';
12
+ import {bindingFits, fitOk, fits, literalPort} from '../spec/fit';
13
+ import {
14
+ ASSET,
15
+ bindingWrites,
16
+ CALLBACK,
17
+ CATALOG_ONLY_KINDS,
18
+ OPEN_PORT,
19
+ PORT_KINDS,
20
+ portSummary,
21
+ pythonRepr,
22
+ type SpecPort,
23
+ } from '../spec/ports';
12
24
  import {LOCAL_ANY, localDeclared, resolveLocals, type ResolvedLocal} from './infer';
13
25
  import {
14
26
  blokCatalog,
@@ -27,6 +39,8 @@ import {
27
39
  iterWithParents,
28
40
  LIKE_PROP,
29
41
  LOCAL_COMPONENT,
42
+ LOGO_COMPONENT,
43
+ blokLogoTree,
30
44
  localName,
31
45
  localProblem,
32
46
  QUERY_COMPONENT,
@@ -328,8 +342,6 @@ const SUSPENSE = 'suspense';
328
342
  const ERROR_SLOT = 'error';
329
343
  const WHEN_PROP = 'when';
330
344
  const BIND_PROP = 'bind';
331
- const CALLBACK_KIND = 'CALLBACK';
332
- const ASSET_KIND = 'ASSET';
333
345
  const REFETCH_FUNCTION = 'query.refetch';
334
346
  const FETCH_MORE_FUNCTION = 'query.fetch_more';
335
347
  /** Per query effect, the method BSX writes it as. */
@@ -365,6 +377,39 @@ const structureMatch = (structure: BlokPortMatch): BlokPortMatch => ({
365
377
  nullable: structure.nullable ?? null,
366
378
  });
367
379
 
380
+ /** What a resolved path holds, as a catalog port: open where its shape is not known (`match_port`). */
381
+ const matchPort = (match: Match): SpecPort => {
382
+ if (match === null || isOpen(match) || match.kind == null) return OPEN_PORT;
383
+ return {
384
+ kind: match.kind,
385
+ ...(match.identifier ? {identifier: match.identifier} : {}),
386
+ ...(match.nullable ? {nullable: true} : {}),
387
+ ...(match.children?.length ? {children: match.children.map(child => ({key: child.key || ITEM, ...matchPort(child)}))} : {}),
388
+ };
389
+ };
390
+
391
+ /** A local's port (or a field's) as a catalog port; open for ANY or none (`arg_port`). */
392
+ const localSpecPort = (port: BlokScopeLocalPort | null): SpecPort => {
393
+ if (port === null || port.kind === LOCAL_ANY) return OPEN_PORT;
394
+ return {
395
+ kind: port.kind,
396
+ ...(port.identifier ? {identifier: port.identifier} : {}),
397
+ ...(port.nullable ? {nullable: true} : {}),
398
+ ...(port.choices?.length ? {choices: port.choices.map(choice => ({value: choice.value}))} : {}),
399
+ ...(port.children?.length ? {children: port.children.map(child => ({key: child.key, ...localSpecPort(child)}))} : {}),
400
+ };
401
+ };
402
+
403
+ /** A catalog port as what a path below it may read: an event's payload field (`catalog_match`). */
404
+ const catalogMatch = (key: string, port: SpecPort): BlokPortMatch => {
405
+ if (port.kind === null || !PORT_KINDS.includes(port.kind) || CATALOG_ONLY_KINDS.has(port.kind)) return openMatch(key);
406
+ if (OPAQUE_KINDS.has(port.kind) && port.kind !== 'UNION') {
407
+ return {key, kind: port.kind, identifier: port.identifier ?? null, nullable: port.nullable || null};
408
+ }
409
+ const children = (port.children ?? []).map(child => catalogMatch(child.key, child));
410
+ return {key, kind: port.kind, nullable: port.nullable || null, children: children.length ? children : null};
411
+ };
412
+
368
413
  const taskRecordMatch = (key: string, returns?: readonly BlokPortMatch[] | null): BlokPortMatch =>
369
414
  recordMatch(
370
415
  key,
@@ -504,14 +549,6 @@ const pythonFloat = (value: number): string => {
504
549
 
505
550
  const article = (kind: string): string => ('aeiou'.includes(kind[0] ?? '') ? 'n' : '');
506
551
 
507
- const pythonRepr = (value: unknown): string => {
508
- if (typeof value === 'string') return `'${value}'`;
509
- if (value === null || value === undefined) return 'None';
510
- if (value === true) return 'True';
511
- if (value === false) return 'False';
512
- return JSON.stringify(value);
513
- };
514
-
515
552
  const what = (prop: BlokComponentProp): string => {
516
553
  if (prop.agent_call) return 'a task call';
517
554
  if (prop.util_call) return prop.util_call.operation;
@@ -616,6 +653,32 @@ class Checker {
616
653
 
617
654
  /* -- declarations -- */
618
655
 
656
+ /**
657
+ * The blok's own `<logo>`: a child of its `<Blok>`, one, in a blok that is no logo, and a fixed
658
+ * drawing. What it draws is checked as a logo blok (`checkBlokTree`). The port of the spec's
659
+ * `check_logo_declaration`.
660
+ */
661
+ checkLogoDeclaration(tree: BlokComponentNode): void {
662
+ let own = 0;
663
+ for (const [node, ancestors] of iterWithParents(tree)) {
664
+ if (node.component !== LOGO_COMPONENT) continue;
665
+ if (ancestors.length !== 1) {
666
+ this.add('logo.misplaced', node.id);
667
+ continue;
668
+ }
669
+ own += 1;
670
+ if (own > 1) this.add('logo.twice', node.id);
671
+ else if (this.header.context === LOGO) this.add('logo.in_logo', node.id);
672
+ for (const [drawn] of iterWithParents(node)) {
673
+ for (const prop of drawn.props ?? []) {
674
+ if (prop.dynamic_value || prop.agent_call || prop.util_call) {
675
+ this.add('logo.dynamic', drawn.id, {component: drawn.component, prop: prop.key});
676
+ }
677
+ }
678
+ }
679
+ }
680
+ }
681
+
619
682
  checkDeclarations(tree: BlokComponentNode): void {
620
683
  const {vocabulary, header} = this;
621
684
  const kind = this.kindName;
@@ -640,6 +703,7 @@ class Checker {
640
703
  this.checkDependencies(tree);
641
704
  this.checkLocalPositions(tree);
642
705
  this.checkQueries(tree);
706
+ this.checkLogoDeclaration(tree);
643
707
  for (const [name, sites] of intoSites(tree)) {
644
708
  this.into.add(name);
645
709
  if (vocabulary.reserved.has(name)) this.add('roots.reserved', sites[0].site, {name});
@@ -944,12 +1008,18 @@ class Checker {
944
1008
  const name = localDeclared(child);
945
1009
  if (name !== null) inner.set(name, this.bindLocal(name, child, new Map(inner)));
946
1010
  }
947
- for (const child of children) this.walkNode(child, inner, [...ancestors, node], inSlot);
1011
+ for (const child of children) {
1012
+ // A blok's own <logo> draws nothing in it and reads nothing: it is checked as a logo blok
1013
+ // of its own (`blokLogoTree`), never as part of the blok it stands for.
1014
+ if (child.component === LOGO_COMPONENT) continue;
1015
+ this.walkNode(child, inner, [...ancestors, node], inSlot);
1016
+ }
948
1017
  }
949
1018
 
950
1019
  private walkProp(node: BlokComponentNode, prop: BlokComponentProp, scope: Scope, inError: boolean): void {
951
1020
  const where: Where = {node, key: prop.key, callback: isCallbackValue(prop), inError};
952
- if (prop.dynamic_value?.path != null) this.resolve(prop.dynamic_value.path, where, scope, whereText(where));
1021
+ const path = prop.dynamic_value?.path;
1022
+ if (path != null) this.checkValueType(where, path, this.resolve(path, where, scope, whereText(where)));
953
1023
  if (prop.agent_call) {
954
1024
  this.visitAgentCall(prop.agent_call, where, scope);
955
1025
  prop.agent_call.arguments?.forEach(argument => this.walkArgument(argument, scope, where));
@@ -1076,20 +1146,14 @@ class Checker {
1076
1146
  const hasValue =
1077
1147
  prop.static_value != null || prop.dynamic_value != null || prop.util_call != null || prop.agent_call != null;
1078
1148
  if (propSpec) {
1079
- if (propSpec.kind === CALLBACK_KIND && hasValue && !holds) {
1149
+ const kind = propSpec.port.kind;
1150
+ if (kind === CALLBACK && hasValue && !holds) {
1080
1151
  this.add('callback.unbound', node.id, {key: prop.key, component: node.component}, prop.key);
1081
- } else if (propSpec.kind !== CALLBACK_KIND && holds) {
1152
+ } else if (kind !== CALLBACK && holds) {
1082
1153
  this.add('callback.not_callback', node.id, {key: prop.key, component: node.component, what: what(prop)}, prop.key);
1083
1154
  }
1084
- if (LITERAL_KINDS.includes(propSpec.kind) && typeof prop.static_value === 'string' && prop.key !== BIND_PROP) {
1085
- this.add(
1086
- 'props.literal_type',
1087
- node.id,
1088
- {component: node.component, key: prop.key, value: prop.static_value, kind: propSpec.kind, hint: literalHint(prop.key, prop.static_value, propSpec.kind)},
1089
- prop.key,
1090
- );
1091
- }
1092
- if (propSpec.kind === ASSET_KIND) {
1155
+ if (prop.static_value != null && prop.key !== BIND_PROP && !CATALOG_ONLY_KINDS.has(kind ?? '')) this.checkLiteral(node, prop, propSpec.port);
1156
+ if (kind === ASSET) {
1093
1157
  const parts = (prop.dynamic_value?.path ?? '').split('.');
1094
1158
  const agent = parts[0] === 'self' ? parts.slice(1) : parts[0] === 'deps' ? parts.slice(2) : [];
1095
1159
  if (agent.length !== 2 || agent[0] !== vocabulary.agentSegments.assets) {
@@ -1121,7 +1185,7 @@ class Checker {
1121
1185
  } else if (!isLocalBinding(binding)) this.add('local.unknown', node.id, {path, root}, prop.key);
1122
1186
  else {
1123
1187
  this.boundLocals.add(binding.node);
1124
- if (propSpec) this.checkBindKind(node, propSpec.kind, binding, path);
1188
+ if (propSpec) this.checkBindKind(node, bindingWrites(propSpec.port), binding, path);
1125
1189
  }
1126
1190
  }
1127
1191
  }
@@ -1143,17 +1207,72 @@ class Checker {
1143
1207
  }
1144
1208
  }
1145
1209
 
1146
- /** The local a control writes is of a kind the control writes (`Slider`: FLOAT or INT). */
1147
- private checkBindKind(node: BlokComponentNode, propKind: string, binding: LocalBinding, path: string): void {
1148
- const allowed = this.vocabulary.locals.bindKinds[propKind];
1149
- const port = this.localPort(binding, path);
1150
- if (!allowed || port === null) return;
1151
- if (!allowed.includes(port.kind)) {
1210
+ /** The local a control writes takes what the control writes (`Slider`: FLOAT or INT). */
1211
+ private checkBindKind(node: BlokComponentNode, writes: SpecPort, binding: LocalBinding, path: string): void {
1212
+ const local = localSpecPort(this.localPort(binding, path));
1213
+ const {bindKinds} = this.vocabulary.locals;
1214
+ if (fitOk(bindingFits(local, writes, bindKinds))) return;
1215
+ const allowed = bindKinds[writes.kind ?? ''];
1216
+ this.add(
1217
+ 'local.bind_kind',
1218
+ node.id,
1219
+ {
1220
+ key: BIND_PROP,
1221
+ component: node.component,
1222
+ prop_kind: portSummary(writes),
1223
+ path,
1224
+ kind: portSummary(local),
1225
+ kinds: allowed ? [...allowed].sort().join(', ') : portSummary(writes),
1226
+ },
1227
+ BIND_PROP,
1228
+ );
1229
+ }
1230
+
1231
+ /** A literal fits the prop's port: its kind (`fullWidth="true"` is a string), then its choices. */
1232
+ private checkLiteral(node: BlokComponentNode, prop: BlokComponentProp, target: SpecPort): void {
1233
+ const value = prop.static_value;
1234
+ const literal = literalPort(value);
1235
+ const kindOnly: SpecPort = {kind: literal.kind, ...(literal.nullable ? {nullable: true} : {})};
1236
+ const kindFit = fits(kindOnly, target);
1237
+ if (fitOk(kindFit)) {
1238
+ if (!fitOk(fits(literal, target)) && target.choices) {
1239
+ this.add(
1240
+ 'catalog.value',
1241
+ node.id,
1242
+ {component: node.component, key: prop.key, value: value as string, values: target.choices.map(choice => String(choice.value)).join(', ')},
1243
+ prop.key,
1244
+ );
1245
+ }
1246
+ return;
1247
+ }
1248
+ if (typeof value === 'string' && target.kind !== null && LITERAL_KINDS.includes(target.kind)) {
1152
1249
  this.add(
1153
- 'local.bind_kind',
1250
+ 'props.literal_type',
1154
1251
  node.id,
1155
- {key: BIND_PROP, component: node.component, prop_kind: propKind, path, kind: port.kind, kinds: [...allowed].sort().join(', ')},
1156
- BIND_PROP,
1252
+ {component: node.component, key: prop.key, value, kind: target.kind, hint: literalHint(prop.key, value, target.kind)},
1253
+ prop.key,
1254
+ );
1255
+ return;
1256
+ }
1257
+ this.add(
1258
+ 'props.type',
1259
+ node.id,
1260
+ {component: node.component, key: prop.key, value: pythonRepr(value), expected: portSummary(target), reason: kindFit.reason ?? ''},
1261
+ prop.key,
1262
+ );
1263
+ }
1264
+
1265
+ /** A path that is a prop's whole value holds what the prop takes. */
1266
+ private checkValueType(where: Where, path: string, match: Match): void {
1267
+ const propSpec = this.view?.components.get(where.node.component)?.props.find(candidate => candidate.key === where.key);
1268
+ if (!propSpec || match === null || where.key === BIND_PROP || CATALOG_ONLY_KINDS.has(propSpec.port.kind ?? '')) return;
1269
+ const fit = fits(matchPort(match), propSpec.port);
1270
+ if (fit.status === 'mismatch') {
1271
+ this.add(
1272
+ 'props.type',
1273
+ where.node.id,
1274
+ {component: where.node.component, key: where.key, value: path, expected: portSummary(propSpec.port), reason: fit.reason ?? ''},
1275
+ where.key,
1157
1276
  );
1158
1277
  }
1159
1278
  }
@@ -1410,7 +1529,7 @@ class Checker {
1410
1529
  report('roots.event_outside_callback', {path});
1411
1530
  return null;
1412
1531
  }
1413
- return this.eventField(rest, where);
1532
+ return this.eventField(rest, path, where);
1414
1533
  }
1415
1534
  if (root === 'error') {
1416
1535
  if (!where || !where.inError) {
@@ -1528,11 +1647,13 @@ class Checker {
1528
1647
  }
1529
1648
  }
1530
1649
 
1531
- private eventField(rest: readonly string[], where: Where): Match {
1650
+ private eventField(rest: readonly string[], path: string, where: Where): Match {
1532
1651
  const prop = this.view?.components.get(where.node.component)?.props.find(candidate => candidate.key === where.key);
1533
- if (!prop || prop.event === null || !rest.length) return openMatch('event');
1534
- const fields = prop.event.map(field => field.key);
1535
- if (!fields.includes(rest[0])) {
1652
+ if (!prop || prop.port.kind !== CALLBACK || !rest.length) return openMatch('event');
1653
+ const children = prop.port.children ?? [];
1654
+ const fields = children.map(field => field.key);
1655
+ const field = children.find(candidate => candidate.key === rest[0]);
1656
+ if (!field) {
1536
1657
  this.add(
1537
1658
  'callback.event_field',
1538
1659
  where.node.id,
@@ -1541,7 +1662,7 @@ class Checker {
1541
1662
  );
1542
1663
  return null;
1543
1664
  }
1544
- return openMatch(rest[0]);
1665
+ return this.descend(catalogMatch(field.key, field), rest.slice(1), path, where.node.id, where.key);
1545
1666
  }
1546
1667
 
1547
1668
  /** What a path below an agent (`self`, `deps.<key>`) holds. */
@@ -1729,6 +1850,16 @@ export const checkBlokTree = (
1729
1850
  checker.checkDeclarations(tree);
1730
1851
  checker.walk(tree);
1731
1852
  if (header.context === LOGO) checker.findings.push(...checkLogo(tree, scope.demo));
1853
+ else {
1854
+ // The blok's own <logo>, drawn and checked as the logo blok it stands for: the pens, the
1855
+ // logo catalog, the logo limits.
1856
+ const logo = blokLogoTree(tree);
1857
+ if (logo !== null) checker.findings.push(...checkBlokTree(logo, unmountedBlokScope(), logoView(view)));
1858
+ }
1732
1859
  checker.finish();
1733
1860
  return checker.findings;
1734
1861
  };
1862
+
1863
+ /** The view a `<logo>` is drawn against: the blok's when it draws logos, else the base one. */
1864
+ const logoView = (view: BlokView | null): BlokView | null =>
1865
+ view === null || view.components.has('Logo') ? view : defaultBlokView();
@@ -13,6 +13,8 @@ import {
13
13
  numberSchema,
14
14
  spacingSchema,
15
15
  textAlignSchema,
16
+ CHART_ROWS_PORT,
17
+ typedAs,
16
18
  } from '../props';
17
19
  import {iconNameSchema} from './icons';
18
20
 
@@ -205,8 +207,7 @@ export const dataContracts = {
205
207
  .enum(['line', 'bar', 'area', 'pie'])
206
208
  .optional()
207
209
  .describe('Chart kind. Defaults to "line".'),
208
- data: z
209
- .array(z.record(z.string(), z.unknown()))
210
+ data: typedAs(z.array(z.record(z.string(), z.unknown())), CHART_ROWS_PORT)
210
211
  .optional()
211
212
  .describe('One object per point, keyed by category and series key.'),
212
213
  categoryKey: z
@@ -1,6 +1,6 @@
1
1
  import * as z from 'zod';
2
2
  import type {BlokComponentContracts} from '../../renderer/runtime/catalog';
3
- import {describedString} from '../props';
3
+ import {describedString, KEYS_PORT, MATRIX_PORT, typedAs} from '../props';
4
4
  import {sceneSchema} from './scene';
5
5
 
6
6
  /**
@@ -35,8 +35,7 @@ export const placedSchema = z
35
35
  blok: describedString(
36
36
  'The scene blok of that agent to draw it with, by name. Its default scene blok when left out.',
37
37
  ),
38
- matrix: z
39
- .unknown()
38
+ matrix: typedAs(z.unknown(), MATRIX_PORT)
40
39
  .optional()
41
40
  .describe(
42
41
  'Where it stands until someone moves it: a 4x4 affine matrix as four rows, in meters with Y up. The room\'s origin when left out.',
@@ -48,10 +47,13 @@ export const placedSchema = z
48
47
 
49
48
  export const routeSchema = z
50
49
  .object({
51
- through: z
52
- .unknown()
53
- .refine(value => value !== undefined, 'A Route runs through dependencies.')
54
- .describe('The dependency keys the line runs through, in order: `through={["robot", "frame", "robot"]}`.'),
50
+ through: typedAs(
51
+ z
52
+ .unknown()
53
+ .refine(value => value !== undefined, 'A Route runs through dependencies.')
54
+ .describe('The dependency keys the line runs through, in order: `through={["robot", "frame", "robot"]}`.'),
55
+ KEYS_PORT,
56
+ ),
55
57
  progress: z
56
58
  .number()
57
59
  .nullish()
@@ -2,7 +2,7 @@ import * as z from 'zod';
2
2
  import type {BlokComponentContracts} from '../../renderer/runtime/catalog';
3
3
  import type {BlokComponentPlacement} from '../../renderer/runtime/components';
4
4
  import {markBindSchema} from '../../renderer/runtime/schemas';
5
- import {actionProp, bindSchema, describedString} from '../props';
5
+ import {actionProp, AMOUNT_PORT, bindSchema, describedString, JOINTS_PORT, MATRIX_PORT, PER_JOINT_PORT, typedAs} from '../props';
6
6
 
7
7
  /**
8
8
  * The 3D vocabulary: three containers place models, a transform places what
@@ -55,9 +55,7 @@ export const modelSchema = z
55
55
  'Places one GLB model in the scene. Its children bind the model\'s named nodes to state. A model that is missing or refused renders a placeholder that says why.',
56
56
  );
57
57
 
58
- const jointValues = z
59
- .record(z.string(), z.unknown())
60
- .optional();
58
+ const jointValues = typedAs(z.record(z.string(), z.unknown()), JOINTS_PORT).optional();
61
59
 
62
60
  export const robotSchema = z
63
61
  .object({
@@ -66,12 +64,10 @@ export const robotSchema = z
66
64
  'Where each joint is: a map of joint name to radians (revolute, continuous) or meters (prismatic). A joint left out keeps its last value.',
67
65
  ),
68
66
  animateTo: jointValues.describe('Where each joint is going. Joints named here move at speed, or over duration.'),
69
- speed: z
70
- .unknown()
67
+ speed: typedAs(z.unknown(), PER_JOINT_PORT)
71
68
  .optional()
72
69
  .describe('How fast joints move to animateTo, in rad/s or m/s: one number for all joints or a map by joint name.'),
73
- duration: z
74
- .unknown()
70
+ duration: typedAs(z.unknown(), PER_JOINT_PORT)
75
71
  .optional()
76
72
  .describe('How long a move to animateTo takes, in seconds: one number or a map by joint name. Ignored where speed is given.'),
77
73
  onJointChange: actionProp(
@@ -90,8 +86,7 @@ const MODEL_PROP_KINDS = {src: 'ASSET'} as const;
90
86
 
91
87
  export const transformSchema = z
92
88
  .object({
93
- matrix: z
94
- .unknown()
89
+ matrix: typedAs(z.unknown(), MATRIX_PORT)
95
90
  .optional()
96
91
  .describe(
97
92
  'Where the children stand: a 4x4 affine matrix as four rows, in meters with Y up (as a space placement keeps it). The identity when absent or malformed.',
@@ -131,12 +126,10 @@ const motionShape = (unit: string, rate: string) => ({
131
126
  axis: z
132
127
  .string()
133
128
  .describe('The axis in the node\'s own frame: "x", "y", "z" or a vector as "x y z".'),
134
- value: z
135
- .unknown()
129
+ value: typedAs(z.unknown(), AMOUNT_PORT)
136
130
  .optional()
137
131
  .describe(`Where the part is, in ${unit} from the pose the model was authored in. A quantity ({magnitude, unit}) is converted.`),
138
- animateTo: z
139
- .unknown()
132
+ animateTo: typedAs(z.unknown(), AMOUNT_PORT)
140
133
  .optional()
141
134
  .describe('Where the part is going. With it, the view moves there at speed (or over duration) and value corrects it.'),
142
135
  speed: z.number().optional().describe(`How fast it moves to animateTo, in ${rate}.`),
@@ -1,7 +1,7 @@
1
1
  import * as z from 'zod';
2
2
  import type {BlokComponentContracts} from '../../renderer/runtime/catalog';
3
3
  import {BlokPropSchemas} from '../../renderer/runtime/schemas';
4
- import {actionProp, bindSchema, boolSchema, classNameSchema, disabledSchema, sizeSchema, structureValueSchema} from '../props';
4
+ import {actionProp, bindSchema, boolSchema, classNameSchema, disabledSchema, sizeSchema, structureValueSchema, typedAs, VARIABLES_PORT} from '../props';
5
5
 
6
6
  /**
7
7
  * the structure family: bloks over other modules' objects, by structure identifier. The
@@ -35,8 +35,7 @@ export const structureContracts = {
35
35
  .string()
36
36
  .optional()
37
37
  .describe('The service that runs `query`, by its key, e.g. "mikro".'),
38
- variables: z
39
- .record(z.string(), z.unknown())
38
+ variables: typedAs(z.record(z.string(), z.unknown()), VARIABLES_PORT)
40
39
  .nullish()
41
40
  .describe('Values for the variables `query` declares beyond the ones the picker supplies.'),
42
41
  placeholder: BlokPropSchemas.DynamicString.optional().describe(
@@ -1,12 +1,16 @@
1
1
  import * as z from 'zod';
2
2
  import type {BlokComponentContracts} from '../../renderer/runtime/catalog';
3
3
  import {BlokPropSchemas} from '../../renderer/runtime/schemas';
4
+ import {TASK_PORT, typedAs} from '../props';
4
5
 
5
6
  /** `<Toast task={move}>` (the ui family) and its outcome slots `done`, `failed`, `cancelled`. */
6
7
 
7
8
  const toastSchema = z
8
9
  .object({
9
- task: z.unknown().refine(value => value !== undefined, 'A Toast follows a task.').describe('The task record to follow: an `into` name of this blok (`task={move}`), or `task`.'),
10
+ task: typedAs(
11
+ z.unknown().refine(value => value !== undefined, 'A Toast follows a task.').describe('The task record to follow: an `into` name of this blok (`task={move}`), or `task`.'),
12
+ TASK_PORT,
13
+ ),
10
14
  })
11
15
  .describe('A notification when a task settles, once per task: its `done`, `failed` and `cancelled` slots hold the text.');
12
16
 
@@ -1,4 +1,5 @@
1
- import {BlokPropSchemas, markBindSchema} from '../renderer/runtime/schemas';
1
+ import {BlokPropSchemas, markBindSchema, markPortSchema, markStructureSchema} from '../renderer/runtime/schemas';
2
+ import {ITEM_KEY, TEXT_PORT, type SpecPort} from '../spec/ports';
2
3
  import * as z from 'zod';
3
4
 
4
5
  /**
@@ -166,11 +167,13 @@ export const bindSchema = markBindSchema(
166
167
  * A reference to one object of some module, the shape structure ports carry.
167
168
  * Nullish: an unset state field or form value is `null`, not absent.
168
169
  */
169
- export const structureValueSchema = z
170
- .object({
170
+ export const structureValueSchema = markStructureSchema(
171
+ z.object({
171
172
  object: z.union([z.string(), z.number()]),
172
173
  __identifier: z.string(),
173
- })
174
+ }),
175
+ '*',
176
+ )
174
177
  .nullish()
175
178
  .describe('A structure reference: {"object": "<id>", "__identifier": "@mikro/arraydataset"}.');
176
179
 
@@ -212,3 +215,60 @@ export const textFields = {
212
215
  italic: boolSchema.describe('Render italic.'),
213
216
  truncate: boolSchema.describe('Truncate to a single line with an ellipsis.'),
214
217
  };
218
+
219
+ /** What an accordion or a toggle group has open or pressed: one value, or a list when multiple. */
220
+ export const openValuesSchema = z.union([z.string(), z.array(z.string())]);
221
+
222
+ /** A 4x4 affine matrix as four rows. */
223
+ export const matrixSchema = z.array(z.array(z.number()));
224
+
225
+ const listOf = (item: SpecPort): SpecPort => ({kind: 'LIST', children: [{key: ITEM_KEY, ...item}]});
226
+ const dictOf = (item: SpecPort): SpecPort => ({kind: 'DICT', children: [{key: ITEM_KEY, ...item}]});
227
+ const FLOAT: SpecPort = {kind: 'FLOAT'};
228
+
229
+ /** A matrix as four rows, read leniently: a malformed one is the identity. */
230
+ export const MATRIX_PORT: SpecPort = listOf(listOf(FLOAT));
231
+ /** Dependency keys, in order. */
232
+ export const KEYS_PORT: SpecPort = listOf({kind: 'STRING'});
233
+ /** A number, or a quantity (`{magnitude, unit}`) that is converted. */
234
+ export const AMOUNT_PORT: SpecPort = {
235
+ kind: 'UNION',
236
+ children: [
237
+ {key: '0', kind: 'FLOAT'},
238
+ {key: '1', kind: 'DICT', children: [{key: 'magnitude', kind: 'FLOAT'}, {key: 'unit', kind: 'STRING'}]},
239
+ ],
240
+ };
241
+ /** A value per joint name. */
242
+ export const JOINTS_PORT: SpecPort = dictOf(FLOAT);
243
+ /** One number for all joints, or one per joint name. */
244
+ export const PER_JOINT_PORT: SpecPort = {kind: 'UNION', children: [{key: '0', ...FLOAT}, {key: '1', ...JOINTS_PORT}]};
245
+ /** What a blok reads of a task record: its scalar fields (a DICT, so a record path fits). */
246
+ export const TASK_PORT: SpecPort = {
247
+ kind: 'DICT',
248
+ children: [
249
+ {key: 'id', kind: 'STRING', nullable: true},
250
+ {key: 'status', kind: 'STRING', choices: ['idle', 'queued', 'running', 'asking', 'paused', 'done', 'failed', 'cancelled'].map(value => ({value}))},
251
+ {key: 'running', kind: 'BOOL'},
252
+ {key: 'paused', kind: 'BOOL'},
253
+ {key: 'done', kind: 'BOOL'},
254
+ {key: 'failed', kind: 'BOOL'},
255
+ {key: 'progress', kind: 'INT'},
256
+ {key: 'message', kind: 'STRING', nullable: true},
257
+ {key: 'error', kind: 'STRING', nullable: true},
258
+ ],
259
+ };
260
+ /** Values of GraphQL variables: scalars, ids, lists of ids, structures. */
261
+ export const VARIABLES_PORT: SpecPort = dictOf({
262
+ kind: 'UNION',
263
+ nullable: true,
264
+ children: [
265
+ ...(TEXT_PORT.children ?? []),
266
+ {key: '4', ...listOf({kind: 'STRING'})},
267
+ {key: '5', kind: 'STRUCTURE', identifier: '*'},
268
+ ],
269
+ });
270
+ /** Chart rows: a category label and numbers by series key. */
271
+ export const CHART_ROWS_PORT: SpecPort = listOf(dictOf({kind: 'UNION', nullable: true, children: [{key: '0', kind: 'STRING'}, {key: '1', ...FLOAT}]}));
272
+
273
+ /** `schema` as it parses, published as `port`: a value the renderer reads leniently. Mark last: `.refine()`/`.describe()` clone. */
274
+ export const typedAs = <TSchema extends z.ZodTypeAny>(schema: TSchema, port: SpecPort): TSchema => markPortSchema(schema, port);
@@ -1,5 +1,7 @@
1
1
  import {BASE_CATALOG_REF, defineBlokCatalog} from '../renderer/runtime/catalog';
2
+ import * as z from 'zod';
2
3
  import {parts} from './parts';
4
+ import {matrixSchema} from './props';
3
5
 
4
6
  /** The `scene` family of the base catalog. */
5
7
  export const sceneCatalog = defineBlokCatalog({
@@ -13,16 +15,16 @@ export const sceneCatalog = defineBlokCatalog({
13
15
  Glow: parts.Glow,
14
16
  Model: parts.Model,
15
17
  Move: parts.Move,
16
- OnClick: {...parts.OnClick, events: {onClick: [{key: "node", kind: "STRING", description: "The node that was clicked."}, {key: "point", kind: "LIST", description: "Where it was hit: [x, y, z] in meters."}]}},
18
+ OnClick: {...parts.OnClick, events: {onClick: [{key: "node", port: {kind: "STRING"}, description: "The node that was clicked."}, {key: "point", port: z.array(z.number()), description: "Where it was hit: [x, y, z] in meters."}]}},
17
19
  Placed: parts.Placed,
18
20
  Popout: parts.Popout,
19
- Robot: {...parts.Robot, events: {onJointChange: [{key: "name", kind: "STRING", description: "The joint the viewer set."}, {key: "value", kind: "FLOAT", description: "Its new value."}]}},
21
+ Robot: {...parts.Robot, events: {onJointChange: [{key: "name", port: {kind: "STRING"}, description: "The joint the viewer set."}, {key: "value", port: {kind: "FLOAT"}, description: "Its new value."}]}},
20
22
  Rotate: parts.Rotate,
21
23
  Route: parts.Route,
22
24
  Scene: parts.Scene,
23
25
  Space: parts.Space,
24
26
  Tint: parts.Tint,
25
- Transform: {...parts.Transform, bindKinds: {bind: "ANY"}},
27
+ Transform: {...parts.Transform, bindKinds: {bind: matrixSchema}},
26
28
  Visible: parts.Visible,
27
29
  },
28
30
  });