@arkitektio/bsx 6.3.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/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +4 -0
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.js +3 -3
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +1 -0
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +8 -1
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +2 -2
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +4 -0
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +47 -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 +41 -6
- 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 +1517 -179
- package/dist/spec/catalogs/base@4.json +103 -3
- package/dist/spec/catalogs/base@4.json.js +103 -3
- 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 +50 -15
- package/dist/spec/vocabulary.json.js +50 -15
- package/package.json +1 -1
- package/src/bsx/infer.ts +4 -0
- package/src/bsx/language.ts +3 -3
- package/src/bsx/parse.ts +7 -1
- package/src/bsx/print.ts +2 -1
- package/src/bsx/references.test.ts +1 -1
- package/src/bsx/references.ts +45 -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 +65 -5
- package/src/renderer/bloks/flow.test.tsx +11 -0
- 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 +1517 -179
- package/src/spec/catalogs/base@4.json +103 -3
- package/src/spec/spec.test.ts +8 -4
- package/src/spec/vocabulary.json +50 -15
- package/src/spec/vocabulary.ts +9 -2
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
type BlokSuspenseReporter,
|
|
22
22
|
} from '../runtime';
|
|
23
23
|
import {useBlokRunHost} from './run/host';
|
|
24
|
+
import {useBlokPortParts} from './port/host';
|
|
24
25
|
import {blokPlatform} from '../../platform';
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -31,7 +32,7 @@ import {blokPlatform} from '../../platform';
|
|
|
31
32
|
* - `<if when={...}>`: its children are the then-branch, then `<else when>`
|
|
32
33
|
* (else-if) and a last `<else>`; only the active branch is rendered and read.
|
|
33
34
|
* - `<foreach items={...} let="p" key={p.id}>`: once per item, keyed; without
|
|
34
|
-
* `key`, keyed by position.
|
|
35
|
+
* `key`, keyed by position. `index="i"` names the item's position, from 0.
|
|
35
36
|
* - `<match value={...}>` with `<case is={...}>` and `<default>`.
|
|
36
37
|
* - `<suspense>` with `<fallback>` and `<error>`: React's model, the error
|
|
37
38
|
* boundary folded in; a pending read inside shows the fallback, a failed
|
|
@@ -62,15 +63,23 @@ const ForeachIteration = (props: {
|
|
|
62
63
|
itemPath?: string;
|
|
63
64
|
/** The item itself, for sources that have no addressable path. */
|
|
64
65
|
item: unknown;
|
|
66
|
+
/** The name the item's position is read by (`index="i"`), when the foreach names one. */
|
|
67
|
+
indexName?: string;
|
|
68
|
+
/** The item's 0-based position in the list. */
|
|
69
|
+
index: number;
|
|
65
70
|
childIds: string[];
|
|
66
71
|
buildChild: (id: string, basePath?: string) => React.ReactNode;
|
|
67
72
|
}) => {
|
|
68
|
-
const {buildChild, childIds, item, itemKey, itemPath, scopeName} = props;
|
|
73
|
+
const {buildChild, childIds, index, indexName, item, itemKey, itemPath, scopeName} = props;
|
|
69
74
|
|
|
70
75
|
// A path-backed item aliases to its path, so a bound control inside the loop
|
|
71
76
|
// writes the real backing list. Without a path the item is handed down by value.
|
|
72
77
|
const aliases = React.useMemo(() => (itemPath ? {[scopeName]: itemPath} : undefined), [itemPath, scopeName]);
|
|
73
|
-
|
|
78
|
+
// The position has no path: it is always handed down by value.
|
|
79
|
+
const values = React.useMemo(() => {
|
|
80
|
+
const position = indexName ? {[indexName]: index} : undefined;
|
|
81
|
+
return itemPath ? position : {[scopeName]: item, ...position};
|
|
82
|
+
}, [index, indexName, item, itemPath, scopeName]);
|
|
74
83
|
|
|
75
84
|
return (
|
|
76
85
|
<BlokItemKeyProvider itemKey={itemKey}>
|
|
@@ -87,6 +96,7 @@ const foreachSchema = z
|
|
|
87
96
|
.object({
|
|
88
97
|
items: z.array(z.unknown()).nullish().describe('The list to iterate.'),
|
|
89
98
|
let: z.string().describe('The name each item is read by inside the loop (`let="p"`, read as `p.name`).'),
|
|
99
|
+
index: z.string().optional().describe('A name for the item\'s position, from 0 (`index="i"`), read bare inside the loop.'),
|
|
90
100
|
key: z
|
|
91
101
|
.unknown()
|
|
92
102
|
.optional()
|
|
@@ -136,6 +146,8 @@ export const Foreach = createBlokComponent(
|
|
|
136
146
|
const blok = useBlok(component, schema);
|
|
137
147
|
const items = useValue(blok.items);
|
|
138
148
|
const scopeName = blok['let'].prop?.declares_value ?? (typeof blok['let'].prop?.static_value === 'string' ? blok['let'].prop.static_value : '');
|
|
149
|
+
const indexProp = blok.index.prop;
|
|
150
|
+
const indexName = indexProp?.declares_value ?? (typeof indexProp?.static_value === 'string' ? indexProp.static_value : undefined);
|
|
139
151
|
const resolve = useScopedResolver();
|
|
140
152
|
const childIds = React.useMemo(() => component.children?.map(child => child.id) ?? [], [component]);
|
|
141
153
|
const scope = useBlokScope();
|
|
@@ -150,7 +162,8 @@ export const Foreach = createBlokComponent(
|
|
|
150
162
|
const keys = keyProp
|
|
151
163
|
? items.map((item, index) => {
|
|
152
164
|
const path = itemPath(index);
|
|
153
|
-
const
|
|
165
|
+
const position = indexName ? {[indexName]: index} : {};
|
|
166
|
+
const resolved = resolve(keyProp, path ? position : {[scopeName]: item, ...position}, path ? {[scopeName]: path} : undefined);
|
|
154
167
|
return resolved.ok ? resolved.value : null;
|
|
155
168
|
})
|
|
156
169
|
: null;
|
|
@@ -165,6 +178,8 @@ export const Foreach = createBlokComponent(
|
|
|
165
178
|
scopeName={scopeName}
|
|
166
179
|
itemPath={itemPath(index)}
|
|
167
180
|
item={item}
|
|
181
|
+
indexName={indexName || undefined}
|
|
182
|
+
index={index}
|
|
168
183
|
childIds={childIds}
|
|
169
184
|
buildChild={buildChild}
|
|
170
185
|
/>
|
|
@@ -287,7 +302,7 @@ export const Blok = createBlokComponent(
|
|
|
287
302
|
placement: {notDownstreamOf: [BLOK_COMPONENT]},
|
|
288
303
|
schema: z
|
|
289
304
|
.object({
|
|
290
|
-
kind: z.enum(['agent', 'custom', 'task', 'action', 'assign']).describe('What the blok is: what it reads, and where it may be mounted.'),
|
|
305
|
+
kind: z.enum(['agent', 'custom', 'task', 'action', 'assign', 'port']).describe('What the blok is: what it reads, and where it may be mounted.'),
|
|
291
306
|
context: z
|
|
292
307
|
.enum(['panel', 'scene', 'logo'])
|
|
293
308
|
.describe('What draws it: a panel (a flat rectangle the host lays out), a scene (a 3D view) or a logo (an SVG drawing).'),
|
|
@@ -653,6 +668,46 @@ export const Timeline = createBlokComponent(
|
|
|
653
668
|
() => <>{useBlokRunHost().renderTimeline?.() ?? null}</>,
|
|
654
669
|
);
|
|
655
670
|
|
|
671
|
+
/* -------------------------------------------------------------------------- */
|
|
672
|
+
/* a port blok's parts of the form */
|
|
673
|
+
/* -------------------------------------------------------------------------- */
|
|
674
|
+
|
|
675
|
+
export const PortLabel = createBlokComponent(
|
|
676
|
+
{name: 'label', schema: z.object({}).describe("The port's label, as the form draws it. The form draws its own above a port blok that places none.")},
|
|
677
|
+
() => <>{useBlokPortParts().renderLabel()}</>,
|
|
678
|
+
);
|
|
679
|
+
|
|
680
|
+
export const PortDescription = createBlokComponent(
|
|
681
|
+
{name: 'description', schema: z.object({}).describe("The port's description, as the form draws it.")},
|
|
682
|
+
() => <>{useBlokPortParts().renderDescription()}</>,
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
export const PortMessage = createBlokComponent(
|
|
686
|
+
{
|
|
687
|
+
name: 'message',
|
|
688
|
+
schema: z.object({}).describe("What the form says is wrong with the port's value (`port.error`), as the form draws it; nothing while the value is fine."),
|
|
689
|
+
},
|
|
690
|
+
() => <>{useBlokPortParts().renderMessage()}</>,
|
|
691
|
+
);
|
|
692
|
+
|
|
693
|
+
export const PortControl = createBlokComponent(
|
|
694
|
+
{
|
|
695
|
+
name: 'control',
|
|
696
|
+
schema: z.object({}).describe("The control the form would draw for this port without a blok, bound to the port: place it to draw around the standard control instead of replacing it."),
|
|
697
|
+
},
|
|
698
|
+
() => <>{useBlokPortParts().renderControl()}</>,
|
|
699
|
+
);
|
|
700
|
+
|
|
701
|
+
const fieldSchema = z
|
|
702
|
+
.object({key: z.string().describe('The key of the child port: `key="x"`.')})
|
|
703
|
+
.describe('One child port of the port (a field of a MODEL), as its own widget draws it, bound below the port\'s value.');
|
|
704
|
+
|
|
705
|
+
export const PortField = createBlokComponent({name: 'field', schema: fieldSchema}, ({component, schema}) => {
|
|
706
|
+
const key = useValue(useBlok(component, schema).key);
|
|
707
|
+
const parts = useBlokPortParts();
|
|
708
|
+
return <>{typeof key === 'string' ? parts.renderField(key) : null}</>;
|
|
709
|
+
});
|
|
710
|
+
|
|
656
711
|
export const controlBlokComponents = [
|
|
657
712
|
TextNode,
|
|
658
713
|
Foreach,
|
|
@@ -678,4 +733,9 @@ export const controlBlokComponents = [
|
|
|
678
733
|
Returns,
|
|
679
734
|
Status,
|
|
680
735
|
Timeline,
|
|
736
|
+
PortLabel,
|
|
737
|
+
PortDescription,
|
|
738
|
+
PortMessage,
|
|
739
|
+
PortControl,
|
|
740
|
+
PortField,
|
|
681
741
|
];
|
|
@@ -85,6 +85,17 @@ describe('foreach', () => {
|
|
|
85
85
|
expect([...document.querySelectorAll('p')].map(element => element.textContent)).toEqual(['one', 'two', 'three']);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
+
it('names each item\'s position with index, for a path-backed list and a computed one', () => {
|
|
89
|
+
render(
|
|
90
|
+
'<Card><foreach items={xs} let="x" index="i"><Text>{math.add(a: i, b: 1)}. {x}</Text></foreach><foreach items={list.reverse(xs)} let="y" index="j" key={j}><Text>r{j} {y}</Text></foreach></Card>',
|
|
91
|
+
{xs: ['one', 'two']},
|
|
92
|
+
);
|
|
93
|
+
expect(screen.queryByText('1. one')).not.toBeNull();
|
|
94
|
+
expect(screen.queryByText('2. two')).not.toBeNull();
|
|
95
|
+
expect(screen.queryByText('r0 two')).not.toBeNull();
|
|
96
|
+
expect(screen.queryByText('r1 one')).not.toBeNull();
|
|
97
|
+
});
|
|
98
|
+
|
|
88
99
|
describe('inside another foreach', () => {
|
|
89
100
|
const rows = [
|
|
90
101
|
{id: 'r1', cells: [{id: 'c1', name: 'One'}, {id: 'c2', name: 'Two'}]},
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a port blok needs from the form it is a field of.
|
|
5
|
+
*
|
|
6
|
+
* A port blok (`<Blok kind="port">`) is the widget of one port of an action's form. The blok
|
|
7
|
+
* core draws its tree; the form owns the field: its label, its description, what is wrong with
|
|
8
|
+
* its value, the control it would draw without a blok, and the child ports below it. A blok
|
|
9
|
+
* that places one of these parts (`<label />`, `<description />`, `<message />`, `<control />`,
|
|
10
|
+
* `<field key="..." />`) gets it drawn by the form through this context, and the form then
|
|
11
|
+
* draws none of its own for it.
|
|
12
|
+
*
|
|
13
|
+
* Outside a form nothing is drawn: the parts are empty.
|
|
14
|
+
*/
|
|
15
|
+
export type BlokPortParts = {
|
|
16
|
+
/** The port's label, as the form draws it (`<label />`). */
|
|
17
|
+
renderLabel: () => React.ReactNode;
|
|
18
|
+
/** The port's description, as the form draws it (`<description />`). */
|
|
19
|
+
renderDescription: () => React.ReactNode;
|
|
20
|
+
/** What the form says is wrong with the value (`<message />`); nothing while it is fine. */
|
|
21
|
+
renderMessage: () => React.ReactNode;
|
|
22
|
+
/** The control the form would draw for this port without a blok, bound to the port (`<control />`). */
|
|
23
|
+
renderControl: () => React.ReactNode;
|
|
24
|
+
/** One child port of the port, by key, as its own widget draws it (`<field key="x" />`). */
|
|
25
|
+
renderField: (key: string) => React.ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const DETACHED_PORT: BlokPortParts = {
|
|
29
|
+
renderLabel: () => null,
|
|
30
|
+
renderDescription: () => null,
|
|
31
|
+
renderMessage: () => null,
|
|
32
|
+
renderControl: () => null,
|
|
33
|
+
renderField: () => null,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const BlokPortPartsContext = React.createContext<BlokPortParts>(DETACHED_PORT);
|
|
37
|
+
|
|
38
|
+
export const BlokPortPartsProvider = BlokPortPartsContext.Provider;
|
|
39
|
+
|
|
40
|
+
export const useBlokPortParts = (): BlokPortParts => React.useContext(BlokPortPartsContext);
|
|
41
|
+
|
|
42
|
+
/** What a port blok does to its port from a callback (`port.set(...)`, `port.clear()`, `port.reset()`, `port.touch()`). */
|
|
43
|
+
export type BlokPortOperation = 'set' | 'clear' | 'reset' | 'touch';
|
|
44
|
+
|
|
45
|
+
/** The parts a port blok may place, as its stored tree names them. */
|
|
46
|
+
export const BLOK_PORT_PARTS = ['label', 'description', 'message', 'control', 'field'] as const;
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
BlokRuntimeStore,
|
|
17
17
|
} from './types';
|
|
18
18
|
import {invokeBlokFunction} from '../functions/v2/handler';
|
|
19
|
+
import type {BlokPortOperation} from '../bloks/port/host';
|
|
19
20
|
|
|
20
21
|
/** The blok language's functions (the vocabulary's): what a store calls unless its host says otherwise. */
|
|
21
22
|
const defaultInvokeFunction: BlokInvokeFunctionHandler = invokeBlokFunction;
|
|
@@ -159,6 +160,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
159
160
|
travelAt?: string | null;
|
|
160
161
|
answerTask?: (values: Record<string, unknown>) => unknown;
|
|
161
162
|
startRun?: () => unknown;
|
|
163
|
+
writePort?: (operation: BlokPortOperation, value?: unknown) => unknown;
|
|
162
164
|
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
163
165
|
}): BlokRuntimeStore => {
|
|
164
166
|
const initialDataModel = config?.initialDataModel;
|
|
@@ -184,6 +186,7 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
184
186
|
fetchMoreQuery: undefined,
|
|
185
187
|
answerTask: config?.answerTask,
|
|
186
188
|
startRun: config?.startRun,
|
|
189
|
+
writePort: config?.writePort,
|
|
187
190
|
controlTask: config?.controlTask,
|
|
188
191
|
setStatus: (path, status) => {
|
|
189
192
|
const key = canonicalStatusPath(path);
|
|
@@ -224,6 +227,9 @@ export const createBlokRuntimeStore = (config?: {
|
|
|
224
227
|
setStartRun: start => {
|
|
225
228
|
set({startRun: start});
|
|
226
229
|
},
|
|
230
|
+
setWritePort: write => {
|
|
231
|
+
set({writePort: write});
|
|
232
|
+
},
|
|
227
233
|
setControlTask: control => {
|
|
228
234
|
set({controlTask: control});
|
|
229
235
|
},
|
|
@@ -195,6 +195,7 @@ const createLiveResolutionContext = (
|
|
|
195
195
|
fetchMoreQuery: (name, variables) => store.getState().fetchMoreQuery?.(name, variables),
|
|
196
196
|
answerTask: values => store.getState().answerTask?.(values),
|
|
197
197
|
startRun: () => store.getState().startRun?.(),
|
|
198
|
+
writePort: store.getState().writePort ? (operation, value) => store.getState().writePort?.(operation, value) : undefined,
|
|
198
199
|
controlTask: store.getState().controlTask ? operation => store.getState().controlTask?.(operation) : undefined,
|
|
199
200
|
travelling: store.getState().travelAt !== null,
|
|
200
201
|
invokeFunction: (name, args, options) => store.getState().invokeFunction(name, args, options),
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
BlokRuntimeDependencies,
|
|
14
14
|
BlokUtilCall,
|
|
15
15
|
} from './types';
|
|
16
|
+
import type {BlokPortOperation} from '../bloks/port/host';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* How a prop's value is worked out from the data model: paths, literals and
|
|
@@ -392,6 +393,13 @@ const resolvePropValue = (
|
|
|
392
393
|
export const COPY_EFFECT = 'ui.copy';
|
|
393
394
|
export const ANSWER_EFFECT = 'task.answer';
|
|
394
395
|
export const START_EFFECT = 'assign.start';
|
|
396
|
+
/** The effects a port blok writes its port with, by the operation the form runs. */
|
|
397
|
+
export const PORT_EFFECTS: Readonly<Record<string, BlokPortOperation>> = {
|
|
398
|
+
'port.set': 'set',
|
|
399
|
+
'port.clear': 'clear',
|
|
400
|
+
'port.reset': 'reset',
|
|
401
|
+
'port.touch': 'touch',
|
|
402
|
+
};
|
|
395
403
|
/** `task.cancel()` and its kin: what the viewer does to the task the blok is about. */
|
|
396
404
|
const TASK_CONTROL_PREFIX = 'task.';
|
|
397
405
|
export const taskControlOf = (operation: string): BlokTaskControl | null => {
|
|
@@ -523,6 +531,13 @@ const runActionCall = (
|
|
|
523
531
|
// What the host returns (a promise, while the task takes it) keeps the control busy.
|
|
524
532
|
return {ok: true, value: context.controlTask(control)};
|
|
525
533
|
}
|
|
534
|
+
const portOperation = PORT_EFFECTS[operation];
|
|
535
|
+
if (portOperation !== undefined) {
|
|
536
|
+
if (context.travelling) return {ok: true, value: undefined};
|
|
537
|
+
if (!context.writePort) return {ok: false, error: `${operation}: this blok is the widget of no port.`};
|
|
538
|
+
// `port.set(null)` empties the port, as `port.clear()` does.
|
|
539
|
+
return {ok: true, value: context.writePort(portOperation, portOperation === 'set' ? resolvedArguments.value.value : undefined)};
|
|
540
|
+
}
|
|
526
541
|
if (operation === START_EFFECT) {
|
|
527
542
|
if (context.travelling) return {ok: true, value: undefined};
|
|
528
543
|
if (!context.startRun) return {ok: false, error: 'assign.start: nothing here starts a run.'};
|
|
@@ -531,7 +546,7 @@ const runActionCall = (
|
|
|
531
546
|
}
|
|
532
547
|
return {
|
|
533
548
|
ok: false,
|
|
534
|
-
error: `${operation} is not a callback's one thing: a callback holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start).`,
|
|
549
|
+
error: `${operation} is not a callback's one thing: a callback holds one task call or one effect (queries.<name>.refetch(), queries.<name>.fetch_more(...), ui.copy, task.answer, assign.start, port.set).`,
|
|
535
550
|
};
|
|
536
551
|
};
|
|
537
552
|
|
|
@@ -2,6 +2,7 @@ import type {StoreApi} from 'zustand/vanilla';
|
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
import type {BlokSourceStatus} from './status';
|
|
4
4
|
import type {BlokTaskAsk, BlokTaskBinding, BlokTaskControl} from './task';
|
|
5
|
+
import type {BlokPortOperation} from '../bloks/port/host';
|
|
5
6
|
|
|
6
7
|
export type ChildDescriptor = string | {id: string; basePath?: string};
|
|
7
8
|
|
|
@@ -221,6 +222,8 @@ export type BlokResolutionContext = {
|
|
|
221
222
|
answerTask?: (values: Record<string, unknown>) => unknown;
|
|
222
223
|
/** Starts the run an assign blok prepares (`assign.start()`); undefined where the host starts none. */
|
|
223
224
|
startRun?: () => unknown;
|
|
225
|
+
/** Writes the port a port blok is the widget of (`port.set(value)`, `port.clear()`, `port.reset()`, `port.touch()`); undefined outside a form. */
|
|
226
|
+
writePort?: (operation: BlokPortOperation, value?: unknown) => unknown;
|
|
224
227
|
/** Cancels, pauses, resumes, steps, interrupts or reruns `task` (`task.cancel()` and its kin); undefined where the host controls no task. */
|
|
225
228
|
controlTask?: (operation: BlokTaskControl) => unknown;
|
|
226
229
|
/** Set while the blok shows a moment in the past: no command runs. */
|
|
@@ -259,6 +262,8 @@ export type BlokRuntimeContext = {
|
|
|
259
262
|
answerTask: ((values: Record<string, unknown>) => unknown) | undefined;
|
|
260
263
|
/** Starts the run an assign blok prepares; set by a host that can start one. */
|
|
261
264
|
startRun: (() => unknown) | undefined;
|
|
265
|
+
/** Writes the port a port blok is the widget of; set by the form that holds the field. */
|
|
266
|
+
writePort: ((operation: BlokPortOperation, value?: unknown) => unknown) | undefined;
|
|
262
267
|
/** Controls `task`; set by a host that can. */
|
|
263
268
|
controlTask: ((operation: BlokTaskControl) => unknown) | undefined;
|
|
264
269
|
setStatus: (path: string, status: BlokSourceStatus | null) => void;
|
|
@@ -267,6 +272,7 @@ export type BlokRuntimeContext = {
|
|
|
267
272
|
setFetchMoreQuery: (fetchMore: ((name: string, variables: Record<string, unknown>) => void) | undefined) => void;
|
|
268
273
|
setAnswerTask: (answer: ((values: Record<string, unknown>) => unknown) | undefined) => void;
|
|
269
274
|
setStartRun: (start: (() => unknown) | undefined) => void;
|
|
275
|
+
setWritePort: (write: ((operation: BlokPortOperation, value?: unknown) => unknown) | undefined) => void;
|
|
270
276
|
setControlTask: (control: ((operation: BlokTaskControl) => unknown) | undefined) => void;
|
|
271
277
|
agentMappingStateUpdates: BlokAgentMappingStateUpdates;
|
|
272
278
|
invokeFunction: BlokInvokeFunctionHandler;
|