@arkitektio/bsx 6.4.0 → 6.5.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/dist/bsx/references.d.ts +2 -0
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +28 -2
- package/dist/bsx/references.js.map +1 -1
- package/dist/ports/engine/defaultRegistry.d.ts.map +1 -1
- package/dist/ports/engine/defaultRegistry.js +2 -0
- package/dist/ports/engine/defaultRegistry.js.map +1 -1
- package/dist/ports/host.d.ts +6 -0
- package/dist/ports/host.d.ts.map +1 -1
- package/dist/ports/host.js.map +1 -1
- package/dist/ports/rekuest.d.ts +14 -1
- package/dist/ports/rekuest.d.ts.map +1 -1
- package/dist/ports/rekuest.js +1 -0
- package/dist/ports/rekuest.js.map +1 -1
- package/dist/ports/widgets/custom/PortBlokWidget.d.ts +30 -0
- package/dist/ports/widgets/custom/PortBlokWidget.d.ts.map +1 -0
- package/dist/ports/widgets/custom/PortBlokWidget.js +210 -0
- package/dist/ports/widgets/custom/PortBlokWidget.js.map +1 -0
- package/dist/ports.d.ts +2 -0
- package/dist/ports.d.ts.map +1 -1
- package/dist/ports.js +4 -0
- package/dist/ports.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +4 -1
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +5 -1
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/bloks/control.d.ts +5 -0
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +28 -1
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/port/host.d.ts +32 -0
- package/dist/renderer/bloks/port/host.d.ts.map +1 -0
- package/dist/renderer/bloks/port/host.js +14 -0
- package/dist/renderer/bloks/port/host.js.map +1 -0
- package/dist/renderer/runtime/context.d.ts +2 -0
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +4 -0
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +1 -0
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/resolution.d.ts +3 -0
- package/dist/renderer/runtime/resolution.d.ts.map +1 -1
- package/dist/renderer/runtime/resolution.js +17 -1
- package/dist/renderer/runtime/resolution.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +6 -0
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/renderer/runtime/types.js.map +1 -1
- package/dist/spec/bsx_v2.json +1285 -181
- package/dist/spec/catalogs/base@4.json +95 -2
- package/dist/spec/catalogs/base@4.json.js +95 -2
- package/dist/spec/vocabulary.d.ts +5 -1
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +4 -1
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +44 -10
- package/dist/spec/vocabulary.json.js +44 -10
- package/package.json +1 -1
- package/src/bsx/references.test.ts +1 -1
- package/src/bsx/references.ts +28 -2
- package/src/ports/engine/defaultRegistry.tsx +2 -0
- package/src/ports/host.tsx +6 -0
- package/src/ports/rekuest.ts +7 -1
- package/src/ports/widgets/custom/PortBlokWidget.test.tsx +88 -0
- package/src/ports/widgets/custom/PortBlokWidget.tsx +268 -0
- package/src/ports.ts +4 -0
- package/src/renderer/BlokRenderer.tsx +9 -0
- package/src/renderer/bloks/control.tsx +47 -1
- package/src/renderer/bloks/port/host.tsx +46 -0
- package/src/renderer/runtime/context.tsx +6 -0
- package/src/renderer/runtime/hooks.ts +1 -0
- package/src/renderer/runtime/resolution.ts +16 -1
- package/src/renderer/runtime/types.ts +6 -0
- package/src/spec/bsx_v2.json +1285 -181
- package/src/spec/catalogs/base@4.json +95 -2
- package/src/spec/spec.test.ts +7 -3
- package/src/spec/vocabulary.json +44 -10
- package/src/spec/vocabulary.ts +9 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default {
|
|
2
2
|
"vocab": 2,
|
|
3
|
-
"minor":
|
|
3
|
+
"minor": 5,
|
|
4
4
|
"description": "The blok language, version 2: what a blok may read, call and store. The spec's parser, the server (rekuest_core, takt) and the renderer (orkestrator) load this file or are generated from it. The design is the blok-vocab-v2 proposal of 2026-10-25. Three layers, each versioned on its own: this language (vocab, and minor for what it gained since); the base catalog, everything every renderer draws; and the app catalogs that extend it with what one frontend draws beyond (see catalogs). A server holds a blok to the language alone, never to a catalog: whoever draws a blok checks it against the catalog it has, and an author's tooling checks it when asked.",
|
|
5
5
|
"roots": {
|
|
6
6
|
"data": {
|
|
@@ -8,9 +8,10 @@ export default {
|
|
|
8
8
|
"deps": "deps.<key>: an agent bound to a dependency of the blok, a custom blok or an action.",
|
|
9
9
|
"queries": "queries.<name>: a declared query's record (status, value, error, refetching, fetching_more).",
|
|
10
10
|
"subscriptions": "subscriptions.<name>: a declared subscription's record (status, value, error); value is the latest payload, or the last `keep` payloads.",
|
|
11
|
-
"args": "args.<key>: what the blok is opened on: the item for an agent or custom blok, the task's args for a task or action blok.",
|
|
11
|
+
"args": "args.<key>: what the blok is opened on: the item for an agent or custom blok, the task's args for a task or action blok, the form's other arguments as they are filled in for a port blok (read only).",
|
|
12
12
|
"task": "The task this blok is about: the sending task, or the run. A task record.",
|
|
13
13
|
"assign": "The run an assign blok prepares: assign.given.<key> (true for an argument the caller decided, which is locked), assign.missing (the keys of required arguments still empty) and assign.ready (nothing is missing).",
|
|
14
|
+
"port": "The port a port blok is the widget of: its value (port.value, which a control writes through bind) and what the form knows of it. A port record.",
|
|
14
15
|
"event": "The payload a component hands its callback. Only inside a callback.",
|
|
15
16
|
"viewer": "{user, org, roles} of whoever is looking.",
|
|
16
17
|
"then": "The moment being viewed while time-travelling (an ISO 8601 datetime), null while live. A blok never reads the wall clock: a query passes then as an ordinary variable (variables={at: \"then\"}), <Time> measures relative time from it, and while it is set subscriptions pause (their history query, or the value at travel start, stale)."
|
|
@@ -22,7 +23,7 @@ export default {
|
|
|
22
23
|
"functions": ["cmp", "logic", "math", "str", "list", "obj", "val", "fmt", "time", "ui", "query"],
|
|
23
24
|
"future": ["mutations"]
|
|
24
25
|
},
|
|
25
|
-
"reserved": ["self", "deps", "queries", "subscriptions", "args", "task", "assign", "event", "viewer", "then", "error", "cmp", "logic", "math", "str", "list", "obj", "val", "fmt", "time", "ui", "query", "mutations"],
|
|
26
|
+
"reserved": ["self", "deps", "queries", "subscriptions", "args", "task", "assign", "port", "event", "viewer", "then", "error", "cmp", "logic", "math", "str", "list", "obj", "val", "fmt", "time", "ui", "query", "mutations"],
|
|
26
27
|
"agent_segments": {
|
|
27
28
|
"description": "What follows an agent (self or deps.<key>): .<state>.<field> is state, .tasks.<action> the latest task of that action, .assets.<name> one of the agent's assets; deps.<key>.<action>(...) calls it.",
|
|
28
29
|
"tasks": "tasks",
|
|
@@ -61,6 +62,13 @@ export default {
|
|
|
61
62
|
"roots": ["self", "deps", "args", "assign", "queries", "subscriptions", "viewer"],
|
|
62
63
|
"locals": true,
|
|
63
64
|
"contexts": ["PANEL", "SCENE"]
|
|
65
|
+
},
|
|
66
|
+
"port": {
|
|
67
|
+
"description": "A port's own widget, declared with the port: drawn in the action's form where the port's control would be. It is a field of that form: it reads the port, the form's other arguments as args and the state of the agents a run would get, and writes the port's value and nothing else. It calls no agent.",
|
|
68
|
+
"roots": ["self", "deps", "args", "port", "queries", "subscriptions", "viewer"],
|
|
69
|
+
"locals": true,
|
|
70
|
+
"contexts": ["PANEL"],
|
|
71
|
+
"calls": false
|
|
64
72
|
}
|
|
65
73
|
},
|
|
66
74
|
"contexts": {
|
|
@@ -72,7 +80,7 @@ export default {
|
|
|
72
80
|
"description": "Every blok is one <Blok> element that says what it is: its kind (what it reads, and where it may be mounted), its context (what host draws it), the catalog it is written for and whether the host draws its own chrome around it. What the blok owns is declared inside it (<local>, <query>, <subscription>); what its mount provides (deps, args, task, self's actions) is checked only where it is mounted.",
|
|
73
81
|
"component": "Blok",
|
|
74
82
|
"attributes": {
|
|
75
|
-
"kind": "Required: agent, custom, task, action or
|
|
83
|
+
"kind": "Required: agent, custom, task, action, assign or port (a row of kinds).",
|
|
76
84
|
"context": "Required: panel, scene or logo.",
|
|
77
85
|
"catalog": "The catalog it is written for (the address it is published at, or the name of one registered in the organization); the base catalog when left out.",
|
|
78
86
|
"chrome": "\"none\": the host draws none of its own interface around the blok (panel and scene only)."
|
|
@@ -152,6 +160,26 @@ export default {
|
|
|
152
160
|
{"key": "blocked", "kind": "STRING", "nullable": true, "description": "Why the run cannot start now, as a sentence (a dependency is not met, no agent fits); null when it can."}
|
|
153
161
|
]
|
|
154
162
|
},
|
|
163
|
+
"port": {
|
|
164
|
+
"description": "What a port blok knows of the port it draws: its value, what the port declares, and where it stands in the form. Everything but value is the form's to say: a port blok sets no error and no flag.",
|
|
165
|
+
"fields": [
|
|
166
|
+
{"key": "value", "kind": "ANY", "nullable": true, "description": "The port's value as the form holds it, typed as the port; null while nothing is given. The one thing a port blok writes: a control through bind={port.value}, a callback with port.set(...)."},
|
|
167
|
+
{"key": "key", "kind": "STRING", "description": "The port's key."},
|
|
168
|
+
{"key": "label", "kind": "STRING", "nullable": true, "description": "What the form calls the port."},
|
|
169
|
+
{"key": "description", "kind": "STRING", "nullable": true},
|
|
170
|
+
{"key": "kind", "kind": "STRING", "description": "The port's kind (FLOAT, STRUCTURE, ...)."},
|
|
171
|
+
{"key": "identifier", "kind": "STRING", "nullable": true, "description": "The structure's identifier, for a STRUCTURE port."},
|
|
172
|
+
{"key": "nullable", "kind": "BOOL", "description": "Whether the port may be left empty."},
|
|
173
|
+
{"key": "default", "kind": "ANY", "nullable": true, "description": "What port.reset() goes back to."},
|
|
174
|
+
{"key": "choices", "kind": "LIST", "description": "The choices the port declares, each {value, label, description}; empty when it declares none."},
|
|
175
|
+
{"key": "unit", "kind": "STRING", "nullable": true, "description": "The unit a QUANTITY port's value is in."},
|
|
176
|
+
{"key": "editable", "kind": "BOOL", "description": "False where the value is only shown: the caller decided it, the form is locked or sent. A control bound to the port is then disabled, and port.set does nothing."},
|
|
177
|
+
{"key": "error", "kind": "STRING", "nullable": true, "description": "What the form says is wrong with the value, by the port's own rules (required, its kind, its validators); null when nothing is, or nothing was checked yet."},
|
|
178
|
+
{"key": "invalid", "kind": "BOOL", "description": "True while error is set."},
|
|
179
|
+
{"key": "touched", "kind": "BOOL", "description": "True once the viewer left the field (a bound control lost focus, or port.touch())."},
|
|
180
|
+
{"key": "dirty", "kind": "BOOL", "description": "True once the value differs from what the form opened with."}
|
|
181
|
+
]
|
|
182
|
+
},
|
|
155
183
|
"viewer": {
|
|
156
184
|
"description": "Exposes nothing beyond what the viewer's own token says.",
|
|
157
185
|
"fields": [
|
|
@@ -187,7 +215,7 @@ export default {
|
|
|
187
215
|
]
|
|
188
216
|
},
|
|
189
217
|
"functions": {
|
|
190
|
-
"description": "Pure functions by namespace, snake_case. Positional arguments map onto params in order. `lazy`: arguments are read only as needed. `effect`: allowed only as a callback's one thing (ui.*, task.*, assign.start, query.*). `command`: an effect that changes the world (it acts on a task or starts one, and is recorded with it); an effect without it only changes what the viewer sees. A blok does nothing else: every other function is pure. `sees_status`: sees pending/failed instead of suspending. No function reads the wall clock. `null` says what the function does with a null argument (known absence); a missing path reads as null.",
|
|
218
|
+
"description": "Pure functions by namespace, snake_case. Positional arguments map onto params in order. `lazy`: arguments are read only as needed. `effect`: allowed only as a callback's one thing (ui.*, task.*, assign.start, port.*, query.*). `needs`: the root a blok's kind must read to hold the effect (port.set needs port). `command`: an effect that changes the world (it acts on a task or starts one, and is recorded with it); an effect without it only changes what the viewer sees. A blok does nothing else: every other function is pure. `sees_status`: sees pending/failed instead of suspending. No function reads the wall clock. `null` says what the function does with a null argument (known absence); a missing path reads as null.",
|
|
191
219
|
"cmp.eq": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "Deep JSON equality.", "null": "null equals only null"},
|
|
192
220
|
"cmp.ne": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "Not deep-equal.", "null": "null equals only null"},
|
|
193
221
|
"cmp.gt": {"params": [["a", "ANY"], ["b", "ANY"]], "returns": "BOOL", "description": "a > b, numbers or strings.", "null": "false"},
|
|
@@ -313,6 +341,10 @@ export default {
|
|
|
313
341
|
"task.step": {"params": [], "returns": "ANY", "effect": true, "command": true, "task_operation": true, "description": "Resumes the run `task` is about until its next breakpoint. Refused while `task.can.step` is false, and while the blok shows the past. Counts as a task operation.", "null": "takes no arguments"},
|
|
314
342
|
"task.interrupt": {"params": [], "returns": "ANY", "effect": true, "command": true, "task_operation": true, "description": "Interrupts the run `task` is about: stopped at once, without waiting for it to wind down. Refused while `task.can.interrupt` is false, and while the blok shows the past. Counts as a task operation.", "null": "takes no arguments"},
|
|
315
343
|
"assign.start": {"params": [], "returns": "ANY", "effect": true, "command": true, "description": "Starts the run an assign blok prepares, with the arguments as they are filled in and the agents the blok was shown (deps) pinned. An assign blok only.", "null": "starts the run"},
|
|
344
|
+
"port.set": {"params": [["value", "ANY"]], "returns": "ANY", "effect": true, "needs": "port", "description": "Sets the port's value, as a control bound to it would: the form marks it dirty and checks it. A port blok only.", "null": "sets the port to empty, as port.clear() does"},
|
|
345
|
+
"port.clear": {"params": [], "returns": "ANY", "effect": true, "needs": "port", "description": "Empties the port: nothing is given for it. A port blok only.", "null": "takes no arguments"},
|
|
346
|
+
"port.reset": {"params": [], "returns": "ANY", "effect": true, "needs": "port", "description": "Puts the port back to what the form opened with (port.default when nothing was given), and clears touched and dirty. A port blok only.", "null": "takes no arguments"},
|
|
347
|
+
"port.touch": {"params": [], "returns": "ANY", "effect": true, "needs": "port", "description": "Says the viewer left the field: what a bound control says itself when it loses focus, for a control drawn by hand. A port blok only.", "null": "takes no arguments"},
|
|
316
348
|
"query.refetch": {"params": [["query", "STRING"]], "returns": "ANY", "effect": true, "description": "Re-reads the declared query named by the literal `query`; never suspends, queries.<name>.refetching is true meanwhile. BSX writes it queries.<name>.refetch().", "null": "refused: the query is named by a literal"},
|
|
317
349
|
"query.fetch_more": {"params": [["query", "STRING"], ["variables", "DICT", false]], "returns": "ANY", "effect": true, "description": "Reads the next page of the declared query named by the literal `query`, its variables overridden by `variables`, and appends the page's list at the query's `more` field to what is shown; queries.<name>.fetching_more is true meanwhile. BSX writes it queries.<name>.fetch_more(name: value, ...). Refused on a query without `more`.", "null": "refused: the query is named by a literal; null variables fetch with the query's own"}
|
|
318
350
|
},
|
|
@@ -326,8 +358,8 @@ export default {
|
|
|
326
358
|
"calls": {
|
|
327
359
|
"description": "What a prop or an argument may hold besides a literal, a path or a util call.",
|
|
328
360
|
"kinds": {
|
|
329
|
-
"agent_call": "A task call: self.<action>(...) or deps.<key>.<action>(...), only as a callback's one thing, optionally named with `into <name>` (stored as the prop's declares_value).",
|
|
330
|
-
"util_call": "A pure function, or an effect (ui.copy, task.answer, assign.start, query.refetch, query.fetch_more) as a callback's one thing."
|
|
361
|
+
"agent_call": "A task call: self.<action>(...) or deps.<key>.<action>(...), only as a callback's one thing, optionally named with `into <name>` (stored as the prop's declares_value). A kind that says calls: false (a port blok) holds none.",
|
|
362
|
+
"util_call": "A pure function, or an effect (ui.copy, task.answer, assign.start, port.set, query.refetch, query.fetch_more) as a callback's one thing."
|
|
331
363
|
},
|
|
332
364
|
"reserved_kinds": {
|
|
333
365
|
"service_call": "Reserved for mutations, should they ever exist. Renderers refuse a call kind they do not know."
|
|
@@ -401,7 +433,7 @@ export default {
|
|
|
401
433
|
"name": "^[A-Za-z_][A-Za-z0-9_.-]*$",
|
|
402
434
|
"host_parts": {
|
|
403
435
|
"description": "Parts of the host's own interface a blok may place itself: placing one anywhere in the tree claims it, and the host then draws none of its own. The claim is read off the stored tree, so a part inside an inactive <if> still claims it (part.conditional). What a blok does not place, the host still draws, unless its root says chrome=\"none\".",
|
|
404
|
-
"parts": ["args", "arg", "deps", "dep", "ask", "returns", "status", "timeline"]
|
|
436
|
+
"parts": ["args", "arg", "deps", "dep", "ask", "returns", "status", "timeline", "label", "description", "message", "control", "field"]
|
|
405
437
|
}
|
|
406
438
|
},
|
|
407
439
|
"classes": {
|
|
@@ -444,7 +476,7 @@ export default {
|
|
|
444
476
|
"callback.positional": {"level": "error", "message": "{call}: a task call names its arguments (name: value)."},
|
|
445
477
|
"callback.into": {"level": "error", "message": "into names the record of a task call: `<call> into <name>`.", "hint": "Write `deps.<key>.<action>(name: value) into run`, then read run.running, run.returns.<port>."},
|
|
446
478
|
"callback.not_callback": {"level": "error", "message": "{key} of <{component}> is not a callback prop, so it cannot hold {what}.", "hint": "Use a callback prop of <{component}> (the catalog lists them as CALLBACK), or compute {key} without a call."},
|
|
447
|
-
"callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
|
|
479
|
+
"callback.unbound": {"level": "error", "message": "{key} of <{component}> is a callback prop: it holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start, port.set).", "hint": "Give {key} a task call (deps.<key>.<action>(name: value)) or one effect, not a value."},
|
|
448
480
|
"callback.event_field": {"level": "error", "message": "event has no field {field!r} in {key} of <{component}> (its fields: {fields}).", "hint": "Read one of the fields listed for {key}: {fields}."},
|
|
449
481
|
"roots.unknown": {"level": "error", "message": "{path} reads {root!r}, which is no root, local, loop variable or record of this blok.", "hint": "Read a root this blok has (deps.<key>, args.<key>, queries.<name>, ...), a declared local, a foreach let or index, or an into record."},
|
|
450
482
|
"roots.not_in_kind": {"level": "error", "message": "{path}: a{n} {kind} blok has no {root!r} (it reads {roots}).", "hint": "Read one of {roots} instead."},
|
|
@@ -462,6 +494,7 @@ export default {
|
|
|
462
494
|
"args.unknown": {"level": "error", "message": "{path} reads args.{key}, which the blok does not declare (declared: {keys}).", "hint": "Read one of the declared args, or declare args.{key} (only when the user asks what the blok is opened for)."},
|
|
463
495
|
"into.twice": {"level": "error", "message": "{name!r} is written by two calls: {first} and {second}. Each call site needs a record of its own."},
|
|
464
496
|
"local.unknown": {"level": "error", "message": "bind={{{path}}} writes {root!r}, which is no declared local.", "hint": "Declare {root!r} in locals (its default, or null), then bind it."},
|
|
497
|
+
"port.bind": {"level": "error", "message": "bind={{{path}}}: a port blok writes port.value and nothing else of its port.", "hint": "Write bind={{port.value}}; what the form knows of the port (its label, its error) is the form's to say."},
|
|
465
498
|
"local.bind": {"level": "error", "message": "bind holds a local's path ({{name}} or {{name.field}}), not {what}.", "hint": "Write bind={{name}} with a declared local's name."},
|
|
466
499
|
"local.default": {"level": "error", "message": "local {name!r}: its default {default!r} is not a {kind}.", "hint": "Give a default of that kind, or leave the kind out so the default sets it."},
|
|
467
500
|
"local.kind": {"level": "error", "message": "local {name!r}: type={type!r} is a name, not an annotation; give the type itself (int, list[str], a registered structure)."},
|
|
@@ -494,11 +527,12 @@ export default {
|
|
|
494
527
|
"foreach.position_key": {"level": "warning", "message": "<foreach let=\"{let}\"> has no key, so its items are keyed by their position; they are not scalars, so key them by a stable field (key={{{let}.id}})."},
|
|
495
528
|
"returns.unnamed": {"level": "warning", "message": "{path} reads {port}, a return the action left unnamed; name it in the action, as Annotated[T, Key(\"name\")] or as a field of a NamedTuple return, and read it by that name."},
|
|
496
529
|
"blok.root": {"level": "error", "message": "A blok is one <Blok kind=... context=...> element, not <{component}>.", "hint": "Wrap it: <Blok kind=\"agent\" context=\"panel\">...</Blok>."},
|
|
497
|
-
"blok.attribute": {"level": "error", "message": "<Blok> {problem}.", "hint": "Write kind=\"agent|custom|task|action|assign\" and context=\"panel|scene|logo\" as literals."},
|
|
530
|
+
"blok.attribute": {"level": "error", "message": "<Blok> {problem}.", "hint": "Write kind=\"agent|custom|task|action|assign|port\" and context=\"panel|scene|logo\" as literals."},
|
|
498
531
|
"blok.content": {"level": "error", "message": "A {context} blok holds {expected} beside its declarations, not {found}.", "hint": "Put everything inside one {expected}."},
|
|
499
532
|
"context.kind": {"level": "error", "message": "A{n} {kind} blok is drawn in {contexts}, not {context}."},
|
|
500
533
|
"kind.placement": {"level": "error", "message": "This is a{n} {kind} blok, but it is mounted as a{m} {expected} blok ({where}).", "hint": "Write kind=\"{expected}\" on its <Blok>, or mount it where a{n} {kind} blok goes."},
|
|
501
534
|
"chrome.context": {"level": "error", "message": "chrome is the host's interface around a panel or a scene, not a {context} blok's.", "hint": "Drop chrome."},
|
|
535
|
+
"calls.not_in_kind": {"level": "error", "message": "{path}: a{n} {kind} blok calls no agent.", "hint": "A port blok is a field of a form: read the agent's state and write the port (port.set(...), bind={{port.value}}). What starts a task belongs in the action's assign blok."},
|
|
502
536
|
"assign.kind": {"level": "error", "message": "{what} belongs to starting a run, so only an action's assign blok holds it, not a{n} {kind} blok.", "hint": "Make it <Blok kind=\"assign\"> in the action's bloks=[...]."},
|
|
503
537
|
"logo.complexity": {"level": "error", "message": "{detail}"},
|
|
504
538
|
"catalog.unknown_component": {"level": "warning", "message": "<{component}> is not in the catalog the blok is written for ({catalogs}).", "hint": "Look the component up in the catalog; names are case-sensitive."},
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ import type {BlokComponentNode} from '../renderer/runtime/types';
|
|
|
10
10
|
/** Where a corpus case is checked: the spec's `mount`, and whether a catalog is read at all. */
|
|
11
11
|
type CorpusMount = Omit<BlokCheckScope, 'catalog'> & {catalog: boolean};
|
|
12
12
|
|
|
13
|
-
const scopeOf = (mount: CorpusMount): BlokCheckScope => ({kinds: mount.kinds, dependencies: mount.dependencies, args: mount.args});
|
|
13
|
+
const scopeOf = (mount: CorpusMount): BlokCheckScope => ({kinds: mount.kinds, dependencies: mount.dependencies, args: mount.args, port: mount.port ?? null});
|
|
14
14
|
type CheckedCase = {
|
|
15
15
|
name: string;
|
|
16
16
|
source: string;
|
package/src/bsx/references.ts
CHANGED
|
@@ -177,6 +177,8 @@ export type BlokCheckScope = {
|
|
|
177
177
|
assets?: readonly string[] | null;
|
|
178
178
|
/** Preview data, for the logo's foreach limit. */
|
|
179
179
|
demo?: {deps?: unknown; args?: unknown; task?: unknown} | null;
|
|
180
|
+
/** The port a port blok is the widget of, as a match: what `port.value` is typed as. Null (or absent) leaves the value open. */
|
|
181
|
+
port?: BlokPortMatch | null;
|
|
180
182
|
};
|
|
181
183
|
|
|
182
184
|
/** A blok checked on its own, mounted nowhere: what an editor checks from the source alone. */
|
|
@@ -206,6 +208,10 @@ const DEPENDENCY_KEY_PROPS = new Set(['Placed.dep', 'Route.through']);
|
|
|
206
208
|
/** The kinds that have a run's dependencies: an action's own bloks, for a run and for starting one. */
|
|
207
209
|
const RUN_KINDS: readonly string[] = ['action', 'assign'];
|
|
208
210
|
const ASSIGN_KIND = 'assign';
|
|
211
|
+
/** The root of a port blok: the port it is the widget of. */
|
|
212
|
+
const PORT_ROOT = 'port';
|
|
213
|
+
/** The one field of `port` a control writes. */
|
|
214
|
+
const PORT_VALUE_FIELD = 'value';
|
|
209
215
|
const ASK_COMPONENT = 'ask';
|
|
210
216
|
const CHROME_NONE = 'none';
|
|
211
217
|
/** The language's elements whose children do not always show: a host part inside one still claims its slot. */
|
|
@@ -382,7 +388,7 @@ const DIGITS = /^[0-9]+$/;
|
|
|
382
388
|
* - an agent blok has none: ``agent bloks read only `self` ``.
|
|
383
389
|
*/
|
|
384
390
|
export const dependencyHint = (key: string, kind: BlokKind): string => {
|
|
385
|
-
if (kind === 'action' || kind === 'assign') return `add a dependency parameter \`${key}\` to the action`;
|
|
391
|
+
if (kind === 'action' || kind === 'assign' || kind === 'port') return `add a dependency parameter \`${key}\` to the action`;
|
|
386
392
|
if (kind === 'agent') return 'agent bloks read only `self`';
|
|
387
393
|
return `dependencies=[AgentDependencyInput(key="${key}")]`;
|
|
388
394
|
};
|
|
@@ -854,6 +860,11 @@ class Checker {
|
|
|
854
860
|
if (effect !== undefined && vocabulary.functions.get(effect)?.taskOperation && !this.kind.roots.includes('task')) {
|
|
855
861
|
this.notInKind(node.id, effect, 'task', prop.key);
|
|
856
862
|
}
|
|
863
|
+
// An effect that is a root's own (port.set) belongs to the kinds that read that root.
|
|
864
|
+
const needs = effect === undefined ? null : (vocabulary.functions.get(effect)?.needs ?? null);
|
|
865
|
+
if (effect !== undefined && needs !== null && !this.kind.roots.includes(needs)) {
|
|
866
|
+
this.notInKind(node.id, effect, needs, prop.key);
|
|
867
|
+
}
|
|
857
868
|
if (prop.key === BIND_PROP) {
|
|
858
869
|
const path = prop.dynamic_value?.path ?? null;
|
|
859
870
|
if (path === null) {
|
|
@@ -861,7 +872,11 @@ class Checker {
|
|
|
861
872
|
} else {
|
|
862
873
|
const root = path.split('.')[0];
|
|
863
874
|
const binding = scope.get(root);
|
|
864
|
-
if (!
|
|
875
|
+
if (root === PORT_ROOT && !scope.has(root) && this.kind.roots.includes(PORT_ROOT)) {
|
|
876
|
+
// The one thing besides a local a control writes: the value of the port a port blok
|
|
877
|
+
// stands for (and what is below it), never what the form says of it.
|
|
878
|
+
if (path.split('.')[1] !== PORT_VALUE_FIELD) this.add('port.bind', node.id, {path}, prop.key);
|
|
879
|
+
} else if (!isLocalBinding(binding)) this.add('local.unknown', node.id, {path, root}, prop.key);
|
|
865
880
|
else {
|
|
866
881
|
this.boundLocals.add(binding.node);
|
|
867
882
|
if (propSpec) this.checkBindKind(node, propSpec.kind, binding, path);
|
|
@@ -945,6 +960,11 @@ class Checker {
|
|
|
945
960
|
private visitAgentCall(call: BlokAgentCall, where: Where, scope: Scope): void {
|
|
946
961
|
const owner = whereText(where);
|
|
947
962
|
const action = actionKeyFor(call);
|
|
963
|
+
if (!this.kind.calls) {
|
|
964
|
+
const called = call.dependency === 'self' ? `self.${action}(...)` : `deps.${call.dependency}.${action}(...)`;
|
|
965
|
+
this.add('calls.not_in_kind', where.node.id, {path: called, n: article(this.kindName), kind: this.kindName}, where.key);
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
948
968
|
if (call.dependency === 'self') {
|
|
949
969
|
if (!this.kind.roots.includes('self')) {
|
|
950
970
|
this.notInKind(where.node.id, `self.${action}(...)`, 'self', where.key);
|
|
@@ -1198,6 +1218,12 @@ class Checker {
|
|
|
1198
1218
|
return {key: rest[1], kind: 'BOOL'};
|
|
1199
1219
|
}
|
|
1200
1220
|
return this.descend(recordMatch('assign', vocabulary.records.assign.fields), rest, path, nodeId, propKey);
|
|
1221
|
+
case PORT_ROOT: {
|
|
1222
|
+
// `port.value` is the port's own type where the mount says it; the rest is the record.
|
|
1223
|
+
const value = this.scope.port ?? null;
|
|
1224
|
+
const overrides = value === null ? undefined : {[PORT_VALUE_FIELD]: {...value, at: null, nullable: true}};
|
|
1225
|
+
return this.descend(recordMatch(PORT_ROOT, vocabulary.records.port.fields, overrides), rest, path, nodeId, propKey);
|
|
1226
|
+
}
|
|
1201
1227
|
case 'task':
|
|
1202
1228
|
this.checkReturns(path, rest, nodeId, propKey);
|
|
1203
1229
|
return this.descend(taskRecordMatch('task'), rest, path, nodeId, propKey);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ChoicesWidget } from "../widgets/custom/ChoicesWidget";
|
|
2
2
|
import { CustomWidget } from "../widgets/custom/CustomWidget";
|
|
3
|
+
import { PortBlokWidget } from "../widgets/custom/PortBlokWidget";
|
|
3
4
|
import { ProxyWidget } from "../widgets/custom/ProxyWidget";
|
|
4
5
|
import { SearchWidget } from "../widgets/custom/SearchWidget";
|
|
5
6
|
import { SliderWidget } from "../widgets/custom/SliderWidget";
|
|
@@ -90,6 +91,7 @@ export const createWidgetRegistry = (options: { canPick?: (identifier: string) =
|
|
|
90
91
|
registry.registerInputWidget("ProxyWidget", ProxyWidget);
|
|
91
92
|
registry.registerInputWidget("StringAssignWidget", StringWidget);
|
|
92
93
|
registry.registerInputWidget("CustomAssignWidget", CustomWidget);
|
|
94
|
+
registry.registerInputWidget("BlokAssignWidget", PortBlokWidget);
|
|
93
95
|
|
|
94
96
|
registry.registerReturnWidgetFallback(PortKind.Int, IntReturnWidget);
|
|
95
97
|
registry.registerReturnWidgetFallback(PortKind.Float, FloatReturnWidget);
|
package/src/ports/host.tsx
CHANGED
|
@@ -57,6 +57,12 @@ export type PortHost = {
|
|
|
57
57
|
StructureDisplay: React.ComponentType<StructureDisplayProps>;
|
|
58
58
|
StructureViewer: React.ComponentType<StructureViewerProps>;
|
|
59
59
|
useReportError: () => (error: unknown, title?: string) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Draws a port's own blok (a BLOK widget) with what this app knows beyond the form: the agents
|
|
62
|
+
* a run would get (`self`, `deps.<key>`) and the services its queries ask. Left out, a port
|
|
63
|
+
* blok is drawn with neither: its dependencies read unbound and its queries do not run.
|
|
64
|
+
*/
|
|
65
|
+
PortBlokRenderer?: React.ComponentType<import('./widgets/custom/PortBlokWidget').PortBlokRendererProps>;
|
|
60
66
|
};
|
|
61
67
|
|
|
62
68
|
const notConnected: ServiceQuery = async () => {
|
package/src/ports/rekuest.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/** The kind of assign widget. */
|
|
7
7
|
export const AssignWidgetKind = {
|
|
8
|
+
Blok: 'BLOK',
|
|
8
9
|
Choice: 'CHOICE',
|
|
9
10
|
Custom: 'CUSTOM',
|
|
10
11
|
Proxy: 'PROXY',
|
|
@@ -229,7 +230,12 @@ export type ArgPortFragment = { __typename: 'ArgPort', key: string, label?: stri
|
|
|
229
230
|
& ValidatorFragment
|
|
230
231
|
)> | null, requires?: Array<{ __typename?: 'Requires', key: string, operator: DescriptorOperator, value?: any | null }> | null };
|
|
231
232
|
|
|
232
|
-
|
|
233
|
+
/** A port blok as the port's widget: BSX (`<Blok kind="port">`) the form draws where the port's control would be. */
|
|
234
|
+
export type BlokAssignWidgetFragment = { __typename: 'BlokAssignWidget', kind: AssignWidgetKind, followValue?: string | null, source: string, vocab: number, fallback?: (
|
|
235
|
+
{ __typename: string, kind: AssignWidgetKind }
|
|
236
|
+
) | null };
|
|
237
|
+
|
|
238
|
+
export type AssignWidgetFragment = BlokAssignWidgetFragment | AssignWidget_ChoiceAssignWidget_Fragment | AssignWidget_CustomAssignWidget_Fragment | AssignWidget_ProxyWidget_Fragment | AssignWidget_SearchAssignWidget_Fragment | AssignWidget_SliderAssignWidget_Fragment | AssignWidget_StateChoiceAssignWidget_Fragment | AssignWidget_StringAssignWidget_Fragment;
|
|
233
239
|
|
|
234
240
|
type AssignWidget_ChoiceAssignWidget_Fragment = (
|
|
235
241
|
{ __typename: 'ChoiceAssignWidget', kind: AssignWidgetKind }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import {cleanup, fireEvent, render, screen} from '@testing-library/react';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {useForm, type FieldValues, type UseFormReturn} from 'react-hook-form';
|
|
5
|
+
import {afterEach, describe, expect, it} from 'vitest';
|
|
6
|
+
|
|
7
|
+
import BlokRenderer from '../../../renderer/BlokRenderer';
|
|
8
|
+
import {testCatalog} from '../../../renderer/bloks/testing';
|
|
9
|
+
import {Form} from '../../../vendor/core/ui/form';
|
|
10
|
+
import {createWidgetRegistry} from '../../engine/defaultRegistry';
|
|
11
|
+
import type {ArgPort} from '../../engine/types';
|
|
12
|
+
import {WidgetRegistryContext, type WidgetRegistryContextType} from '../../engine/WidgetsContext';
|
|
13
|
+
import {configurePortHost} from '../../host';
|
|
14
|
+
import {AssignWidgetKind, PortKind, type BlokAssignWidgetFragment} from '../../rekuest';
|
|
15
|
+
import {argsRead, PortBlokWidget, type PortBlokRendererProps} from './PortBlokWidget';
|
|
16
|
+
import {parseBsx} from '../../../bsx/parse';
|
|
17
|
+
|
|
18
|
+
afterEach(cleanup);
|
|
19
|
+
|
|
20
|
+
const SOURCE = `<Blok kind="port" context="panel">
|
|
21
|
+
<Input bind={port.value} placeholder="exposure" />
|
|
22
|
+
<p>{args.limit}</p>
|
|
23
|
+
<Button onClick={port.set(args.limit)}>Longest</Button>
|
|
24
|
+
<Button onClick={port.reset()}>Back</Button>
|
|
25
|
+
</Blok>`;
|
|
26
|
+
|
|
27
|
+
const port = {__typename: 'ArgPort', key: 'exposure', label: 'Exposure', kind: PortKind.Float, nullable: false, description: 'How long the shutter stays open'} as unknown as ArgPort;
|
|
28
|
+
const widget = (source: string): BlokAssignWidgetFragment => ({__typename: 'BlokAssignWidget', kind: AssignWidgetKind.Blok, source, vocab: 2, fallback: null});
|
|
29
|
+
|
|
30
|
+
/** The renderer an app provides: here with the test catalog, and no agents. */
|
|
31
|
+
const TestRenderer = ({tree, data, writePort, children}: PortBlokRendererProps) => (
|
|
32
|
+
<BlokRenderer uiComponents={[tree]} initialState={data} catalog={testCatalog()} writePort={writePort} chrome="none" sizing="intrinsic">
|
|
33
|
+
{children}
|
|
34
|
+
</BlokRenderer>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const Harness = ({source, held}: {source: string; held: {form?: UseFormReturn}}) => {
|
|
38
|
+
const form = useForm<FieldValues>({defaultValues: {exposure: 5, limit: 9, gain: 1}});
|
|
39
|
+
held.form = form;
|
|
40
|
+
const registry = React.useMemo(() => createWidgetRegistry() as unknown as WidgetRegistryContextType['registry'], []);
|
|
41
|
+
return (
|
|
42
|
+
<WidgetRegistryContext.Provider value={{registry, setRegistry: () => undefined}}>
|
|
43
|
+
<Form {...form}>
|
|
44
|
+
<PortBlokWidget port={port} widget={widget(source)} path={['exposure']} />
|
|
45
|
+
</Form>
|
|
46
|
+
</WidgetRegistryContext.Provider>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
describe('a port blok as a field of the form', () => {
|
|
51
|
+
it('reads only the arguments its tree names', () => {
|
|
52
|
+
expect(argsRead(parseBsx(SOURCE).tree)).toEqual(['limit']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('shows the port and the form, and writes the value of its port and nothing else', () => {
|
|
56
|
+
configurePortHost({PortBlokRenderer: TestRenderer});
|
|
57
|
+
const held: {form?: UseFormReturn} = {};
|
|
58
|
+
render(<Harness source={SOURCE} held={held} />);
|
|
59
|
+
|
|
60
|
+
// The form draws its own label and description around a blok that places none.
|
|
61
|
+
expect(screen.getByText('Exposure')).toBeTruthy();
|
|
62
|
+
expect(screen.getByText('How long the shutter stays open')).toBeTruthy();
|
|
63
|
+
const input = screen.getByPlaceholderText('exposure') as HTMLInputElement;
|
|
64
|
+
expect(input.value).toBe('5');
|
|
65
|
+
expect(screen.getByText('9')).toBeTruthy();
|
|
66
|
+
|
|
67
|
+
// A bound control writes the field, which the form then marks dirty.
|
|
68
|
+
fireEvent.change(input, {target: {value: '7'}});
|
|
69
|
+
expect(held.form?.getValues('exposure')).toBe('7');
|
|
70
|
+
expect(held.form?.getFieldState('exposure').isDirty).toBe(true);
|
|
71
|
+
expect(held.form?.getValues('limit')).toBe(9);
|
|
72
|
+
|
|
73
|
+
// port.set writes it from a callback; port.reset puts back what the form opened with.
|
|
74
|
+
fireEvent.click(screen.getByText('Longest'));
|
|
75
|
+
expect(held.form?.getValues('exposure')).toBe(9);
|
|
76
|
+
fireEvent.click(screen.getByText('Back'));
|
|
77
|
+
expect(held.form?.getValues('exposure')).toBe(5);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('falls back to the port’s own control where the source is no port blok', () => {
|
|
81
|
+
configurePortHost({PortBlokRenderer: TestRenderer});
|
|
82
|
+
const held: {form?: UseFormReturn} = {};
|
|
83
|
+
render(<Harness source={'<Blok kind="agent" context="panel"><Card /></Blok>'} held={held} />);
|
|
84
|
+
|
|
85
|
+
expect(screen.queryByPlaceholderText('exposure')).toBeNull();
|
|
86
|
+
expect(screen.getByText('Exposure')).toBeTruthy();
|
|
87
|
+
});
|
|
88
|
+
});
|