@arkitektio/bsx 5.0.0 → 6.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.
- package/README.md +2 -2
- package/dist/bsx/analyze.d.ts +6 -5
- package/dist/bsx/analyze.d.ts.map +1 -1
- package/dist/bsx/analyze.js +12 -10
- package/dist/bsx/analyze.js.map +1 -1
- package/dist/bsx/declared.d.ts +111 -0
- package/dist/bsx/declared.d.ts.map +1 -0
- package/dist/bsx/declared.js +311 -0
- package/dist/bsx/declared.js.map +1 -0
- package/dist/bsx/index.d.ts +1 -0
- package/dist/bsx/index.d.ts.map +1 -1
- package/dist/bsx/index.js +1 -0
- package/dist/bsx/index.js.map +1 -1
- package/dist/bsx/infer.d.ts +40 -17
- package/dist/bsx/infer.d.ts.map +1 -1
- package/dist/bsx/infer.js +105 -49
- package/dist/bsx/infer.js.map +1 -1
- package/dist/bsx/language.d.ts +6 -2
- package/dist/bsx/language.d.ts.map +1 -1
- package/dist/bsx/language.js +65 -21
- package/dist/bsx/language.js.map +1 -1
- package/dist/bsx/parse.d.ts +6 -1
- package/dist/bsx/parse.d.ts.map +1 -1
- package/dist/bsx/parse.js +32 -3
- package/dist/bsx/parse.js.map +1 -1
- package/dist/bsx/print.d.ts.map +1 -1
- package/dist/bsx/print.js +3 -0
- package/dist/bsx/print.js.map +1 -1
- package/dist/bsx/references.d.ts +45 -51
- package/dist/bsx/references.d.ts.map +1 -1
- package/dist/bsx/references.js +265 -138
- package/dist/bsx/references.js.map +1 -1
- package/dist/catalogs/html.d.ts +2 -2
- package/dist/catalogs/index.d.ts +49 -71
- package/dist/catalogs/index.d.ts.map +1 -1
- package/dist/catalogs/index.js +1 -1
- package/dist/catalogs/logo.d.ts +14 -28
- package/dist/catalogs/logo.d.ts.map +1 -1
- package/dist/catalogs/logo.js +1 -2
- package/dist/catalogs/logo.js.map +1 -1
- package/dist/catalogs/parts/data.d.ts +1 -1
- package/dist/catalogs/parts/feedback.d.ts +3 -3
- package/dist/catalogs/parts/forms.d.ts +4 -4
- package/dist/catalogs/parts/html.d.ts +2 -2
- package/dist/catalogs/parts/icons.d.ts +2 -2
- package/dist/catalogs/parts/index.d.ts +35 -57
- package/dist/catalogs/parts/index.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.d.ts +10 -25
- package/dist/catalogs/parts/logo.d.ts.map +1 -1
- package/dist/catalogs/parts/logo.js +12 -14
- package/dist/catalogs/parts/logo.js.map +1 -1
- package/dist/catalogs/parts/navigation.d.ts +4 -4
- package/dist/catalogs/parts/overlays.d.ts +11 -11
- package/dist/catalogs/parts/run.d.ts +2 -10
- package/dist/catalogs/parts/run.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.d.ts +7 -15
- package/dist/catalogs/parts/scene.d.ts.map +1 -1
- package/dist/catalogs/parts/scene.js +1 -5
- package/dist/catalogs/parts/scene.js.map +1 -1
- package/dist/catalogs/parts/typography.d.ts +3 -3
- package/dist/catalogs/props.d.ts +2 -2
- package/dist/catalogs/scene.d.ts +5 -13
- package/dist/catalogs/scene.d.ts.map +1 -1
- package/dist/catalogs/shadcn.d.ts +11 -11
- package/dist/catalogs/ui.d.ts +16 -16
- package/dist/logo/actionLogoSource.d.ts +3 -3
- package/dist/logo/actionLogoSource.d.ts.map +1 -1
- package/dist/logo/actionLogoSource.js +4 -4
- package/dist/logo/actionLogoSource.js.map +1 -1
- package/dist/renderer/BlokRenderer.d.ts +10 -6
- package/dist/renderer/BlokRenderer.d.ts.map +1 -1
- package/dist/renderer/BlokRenderer.js +23 -9
- package/dist/renderer/BlokRenderer.js.map +1 -1
- package/dist/renderer/baseCatalog.d.ts +3 -3
- package/dist/renderer/baseCatalog.js +2 -2
- package/dist/renderer/bloks/control.d.ts +18 -2
- package/dist/renderer/bloks/control.d.ts.map +1 -1
- package/dist/renderer/bloks/control.js +85 -14
- package/dist/renderer/bloks/control.js.map +1 -1
- package/dist/renderer/bloks/data.d.ts +1 -1
- package/dist/renderer/bloks/feedback.d.ts +3 -3
- package/dist/renderer/bloks/forms.d.ts +4 -4
- package/dist/renderer/bloks/html.d.ts +2 -2
- package/dist/renderer/bloks/icons.d.ts +1 -1
- package/dist/renderer/bloks/index.d.ts +30 -37
- package/dist/renderer/bloks/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.d.ts +1 -8
- package/dist/renderer/bloks/logo/index.d.ts.map +1 -1
- package/dist/renderer/bloks/logo/index.js +1 -2
- package/dist/renderer/bloks/logo/index.js.map +1 -1
- package/dist/renderer/bloks/logo/logo.fixture.json +266 -250
- package/dist/renderer/bloks/navigation.d.ts +4 -4
- package/dist/renderer/bloks/overlays.d.ts +11 -11
- package/dist/renderer/bloks/run/components.d.ts +1 -5
- package/dist/renderer/bloks/run/components.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/index.d.ts +4 -8
- package/dist/renderer/bloks/scene/index.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.d.ts.map +1 -1
- package/dist/renderer/bloks/scene/interaction.js +3 -2
- package/dist/renderer/bloks/scene/interaction.js.map +1 -1
- package/dist/renderer/bloks/shared/props.d.ts +2 -2
- package/dist/renderer/bloks/typography.d.ts +3 -3
- package/dist/renderer/declarations.d.ts +40 -33
- package/dist/renderer/declarations.d.ts.map +1 -1
- package/dist/renderer/declarations.js +41 -56
- package/dist/renderer/declarations.js.map +1 -1
- package/dist/renderer/declare.js +4 -4
- package/dist/renderer/declare.js.map +1 -1
- package/dist/renderer/persist.d.ts +22 -13
- package/dist/renderer/persist.d.ts.map +1 -1
- package/dist/renderer/persist.js +40 -21
- package/dist/renderer/persist.js.map +1 -1
- package/dist/renderer/runtime/catalog.d.ts +4 -4
- package/dist/renderer/runtime/catalog.js +3 -3
- package/dist/renderer/runtime/components.d.ts +4 -4
- package/dist/renderer/runtime/components.d.ts.map +1 -1
- package/dist/renderer/runtime/components.js +5 -5
- package/dist/renderer/runtime/components.js.map +1 -1
- package/dist/renderer/runtime/context.d.ts +5 -5
- package/dist/renderer/runtime/context.d.ts.map +1 -1
- package/dist/renderer/runtime/context.js +11 -5
- package/dist/renderer/runtime/context.js.map +1 -1
- package/dist/renderer/runtime/describe.d.ts +3 -3
- package/dist/renderer/runtime/describe.d.ts.map +1 -1
- package/dist/renderer/runtime/describe.js +2 -2
- package/dist/renderer/runtime/describe.js.map +1 -1
- package/dist/renderer/runtime/hooks.d.ts.map +1 -1
- package/dist/renderer/runtime/hooks.js +8 -4
- package/dist/renderer/runtime/hooks.js.map +1 -1
- package/dist/renderer/runtime/index.d.ts +1 -0
- package/dist/renderer/runtime/index.d.ts.map +1 -1
- package/dist/renderer/runtime/index.js +1 -0
- package/dist/renderer/runtime/index.js.map +1 -1
- package/dist/renderer/runtime/locals.d.ts +57 -0
- package/dist/renderer/runtime/locals.d.ts.map +1 -0
- package/dist/renderer/runtime/locals.js +87 -0
- package/dist/renderer/runtime/locals.js.map +1 -0
- package/dist/renderer/runtime/scope.d.ts +14 -0
- package/dist/renderer/runtime/scope.d.ts.map +1 -1
- package/dist/renderer/runtime/scope.js +25 -3
- package/dist/renderer/runtime/scope.js.map +1 -1
- package/dist/renderer/runtime/tree.d.ts.map +1 -1
- package/dist/renderer/runtime/tree.js +7 -1
- package/dist/renderer/runtime/tree.js.map +1 -1
- package/dist/renderer/runtime/types.d.ts +8 -3
- package/dist/renderer/runtime/types.d.ts.map +1 -1
- package/dist/shadcn.d.ts +36 -43
- package/dist/shadcn.d.ts.map +1 -1
- package/dist/shadcn.js +1 -2
- package/dist/shadcn.js.map +1 -1
- package/dist/spec/bsx_v2.json +11067 -6321
- package/dist/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/dist/spec/catalogs/{base@3.json.js → base@4.json.js} +434 -288
- package/dist/spec/catalogs/orkestrator@1.json +10 -10
- package/dist/spec/catalogs/orkestrator@1.json.js +10 -10
- package/dist/spec/catalogs.d.ts +4 -4
- package/dist/spec/catalogs.d.ts.map +1 -1
- package/dist/spec/catalogs.js +7 -7
- package/dist/spec/catalogs.js.map +1 -1
- package/dist/spec/vocabulary.d.ts +25 -4
- package/dist/spec/vocabulary.d.ts.map +1 -1
- package/dist/spec/vocabulary.js +50 -5
- package/dist/spec/vocabulary.js.map +1 -1
- package/dist/spec/vocabulary.json +58 -32
- package/dist/spec/vocabulary.json.js +58 -32
- package/package.json +1 -1
- package/src/bsx/analyze.ts +14 -12
- package/src/bsx/bsx.test.ts +4 -4
- package/src/bsx/declared.ts +346 -0
- package/src/bsx/index.ts +1 -0
- package/src/bsx/infer.test.ts +42 -32
- package/src/bsx/infer.ts +128 -71
- package/src/bsx/language.test.ts +37 -25
- package/src/bsx/language.ts +72 -25
- package/src/bsx/parse.ts +34 -3
- package/src/bsx/print.ts +3 -0
- package/src/bsx/references.test.ts +82 -81
- package/src/bsx/references.ts +313 -178
- package/src/catalogs/catalogs.test.ts +3 -2
- package/src/catalogs/index.ts +1 -1
- package/src/catalogs/logo.ts +1 -2
- package/src/catalogs/parts/logo.ts +13 -17
- package/src/catalogs/parts/scene.ts +1 -7
- package/src/logo/actionLogoSource.ts +4 -4
- package/src/renderer/BlokComponentHost.test.tsx +5 -5
- package/src/renderer/BlokRenderer.tsx +46 -14
- package/src/renderer/addBlokComponents.test.tsx +1 -1
- package/src/renderer/baseCatalog.ts +2 -2
- package/src/renderer/bloks/control.tsx +119 -16
- package/src/renderer/bloks/logo/index.tsx +2 -3
- package/src/renderer/bloks/logo/logo.fixture.json +266 -250
- package/src/renderer/bloks/logo/logo.test.tsx +18 -7
- package/src/renderer/bloks/run/space.test.tsx +12 -4
- package/src/renderer/bloks/scene/interaction.tsx +11 -6
- package/src/renderer/bloks/scene/transform.test.ts +8 -7
- package/src/renderer/declarations.test.ts +38 -51
- package/src/renderer/declarations.ts +67 -88
- package/src/renderer/declare.test.ts +4 -4
- package/src/renderer/declare.ts +4 -4
- package/src/renderer/persist.test.ts +70 -49
- package/src/renderer/persist.ts +57 -34
- package/src/renderer/runtime/catalog.test.ts +2 -2
- package/src/renderer/runtime/catalog.ts +4 -4
- package/src/renderer/runtime/components.tsx +8 -8
- package/src/renderer/runtime/context.tsx +17 -10
- package/src/renderer/runtime/describe.ts +5 -5
- package/src/renderer/runtime/hooks.ts +6 -4
- package/src/renderer/runtime/index.ts +1 -0
- package/src/renderer/runtime/locals.tsx +105 -0
- package/src/renderer/runtime/scope.tsx +31 -3
- package/src/renderer/runtime/tree.tsx +16 -4
- package/src/renderer/runtime/types.ts +8 -3
- package/src/shadcn.ts +1 -2
- package/src/spec/bsx_v2.json +11067 -6321
- package/src/spec/catalogs/{base@3.json → base@4.json} +434 -288
- package/src/spec/catalogs/orkestrator@1.json +10 -10
- package/src/spec/catalogs.ts +8 -8
- package/src/spec/spec.test.ts +19 -16
- package/src/spec/vocabulary.json +58 -32
- package/src/spec/vocabulary.ts +69 -10
package/src/bsx/infer.ts
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import type {BlokActionArgument, BlokAgentCall, BlokComponentNode, BlokComponentProp} from '../renderer/runtime/types';
|
|
2
2
|
import type {BlokView} from '../spec/catalogs';
|
|
3
3
|
import {LOCAL_ANY_KIND} from '../spec/vocabulary';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
BlokPortMatch,
|
|
7
|
-
BlokScopeDependency,
|
|
8
|
-
BlokScopeLocal,
|
|
9
|
-
BlokScopeLocalPort,
|
|
10
|
-
ResolvedBlokLocal,
|
|
11
|
-
ResolvedBlokScope,
|
|
12
|
-
} from './references';
|
|
4
|
+
import {declaredLocal, iterWithParents, LOCAL_COMPONENT, localLike, NAME_PROP} from './declared';
|
|
5
|
+
import type {BlokPortMatch, BlokScopeDependency, BlokScopeLocal, BlokScopeLocalPort, ResolvedBlokLocal} from './references';
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
|
-
* Resolve what a blok leaves to its tree: the kinds of its
|
|
16
|
-
* of arkitekt-spec's
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* everywhere.
|
|
8
|
+
* Resolve what a blok leaves to its tree: the kinds of its `<local>`
|
|
9
|
+
* declarations. The port of arkitekt-spec's `declare/blok/infer.py`
|
|
10
|
+
* (`resolve_locals`); the server and takt resolve the same way on save, so a
|
|
11
|
+
* source blok sent without kinds is stored the same everywhere.
|
|
20
12
|
*
|
|
21
13
|
* **A local's kind**, when it is left out (a given kind, `ANY` included, is
|
|
22
14
|
* kept), is the first of:
|
|
@@ -29,8 +21,11 @@ import type {
|
|
|
29
21
|
* STRING, INT, FLOAT or BOOL;
|
|
30
22
|
* 4. else ANY: an untyped value, never an error.
|
|
31
23
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
24
|
+
* A given `kind` and `like="self.<action>.<arg>"` come before all of these
|
|
25
|
+
* (`like` is resolved only where the blok is mounted). Only uses in the
|
|
26
|
+
* local's scope (its parent's subtree) count. Every field the local sets wins
|
|
27
|
+
* over the inferred type, which only fills what it leaves out; a candidate
|
|
28
|
+
* that makes no valid port is skipped.
|
|
34
29
|
*
|
|
35
30
|
* Nothing else is inferred: every `deps.<key>` a blok reads, whatever its
|
|
36
31
|
* kind, must be declared (`deps.unknown` otherwise, its hint naming the
|
|
@@ -153,9 +148,15 @@ const toLocalPort = (port: InferredPort): BlokScopeLocalPort => ({
|
|
|
153
148
|
export const anyLocal = (local: BlokScopeLocal): ResolvedBlokLocal => ({...ownFields(local), kind: LOCAL_ANY});
|
|
154
149
|
|
|
155
150
|
/** `local` with its kind resolved by the rules above (a given kind is kept). */
|
|
156
|
-
export const resolveLocal = (
|
|
151
|
+
export const resolveLocal = (
|
|
152
|
+
local: BlokScopeLocal,
|
|
153
|
+
args: readonly InferredType[],
|
|
154
|
+
binds: readonly string[],
|
|
155
|
+
borrowed: InferredType | null = null,
|
|
156
|
+
): ResolvedBlokLocal => {
|
|
157
157
|
if (kindGiven(local)) return {...local, kind: local.kind ?? LOCAL_ANY};
|
|
158
158
|
const candidates: InferredType[] = [];
|
|
159
|
+
if (borrowed !== null) candidates.push(borrowed);
|
|
159
160
|
const fromDefault = defaultType(local.default);
|
|
160
161
|
if (fromDefault !== null) candidates.push(fromDefault);
|
|
161
162
|
candidates.push(...args);
|
|
@@ -173,21 +174,69 @@ export const resolveLocal = (local: BlokScopeLocal, args: readonly InferredType[
|
|
|
173
174
|
|
|
174
175
|
const actionKeyFor = (call: BlokAgentCall): string => call.operation.split('.').pop() ?? call.operation;
|
|
175
176
|
|
|
177
|
+
/** What a name in scope is bound to here: a `<local>`'s node id, or null for a `let` or an `into` name. */
|
|
178
|
+
type UseScope = ReadonlyMap<string, string | null>;
|
|
179
|
+
|
|
180
|
+
/** The local a `<local>` node declares by name: its `name` prop's `declares_value`. */
|
|
181
|
+
export const localDeclared = (node: BlokComponentNode): string | null => {
|
|
182
|
+
if (node.component !== LOCAL_COMPONENT) return null;
|
|
183
|
+
return node.props?.find(prop => prop.key === NAME_PROP && prop.declares_value)?.declares_value ?? null;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The type of an action's argument as the mount knows it: the arg match of a
|
|
188
|
+
* dependency's demand (`self` included); null when it does not tell.
|
|
189
|
+
*/
|
|
190
|
+
export const argumentType = (
|
|
191
|
+
dependency: string,
|
|
192
|
+
action: string,
|
|
193
|
+
argument: string,
|
|
194
|
+
dependencies: ReadonlyMap<string, BlokScopeDependency>,
|
|
195
|
+
): InferredType | null => {
|
|
196
|
+
const demand = dependencies.get(dependency)?.action_dependencies?.find(each => each.key === action)?.demand;
|
|
197
|
+
const match = demand?.arg_matches?.find(each => each.key === argument);
|
|
198
|
+
return match ? matchType(match) : null;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* What `like="self.<action>.<arg>"` / `"deps.<key>.<action>.<arg>"` borrows:
|
|
203
|
+
* the argument's type, or why it borrows nothing.
|
|
204
|
+
*/
|
|
205
|
+
export const borrowedType = (
|
|
206
|
+
like: string,
|
|
207
|
+
dependencies: ReadonlyMap<string, BlokScopeDependency>,
|
|
208
|
+
): {typed: InferredType | null; problem: string | null} => {
|
|
209
|
+
const parts = like.split('.');
|
|
210
|
+
let dependency: string;
|
|
211
|
+
let action: string;
|
|
212
|
+
let argument: string;
|
|
213
|
+
if (parts[0] === 'self' && parts.length === 3) [dependency, action, argument] = ['self', parts[1], parts[2]];
|
|
214
|
+
else if (parts[0] === 'deps' && parts.length === 4) [dependency, action, argument] = [parts[1], parts[2], parts[3]];
|
|
215
|
+
else return {typed: null, problem: 'is no argument: write self.<action>.<arg> or deps.<key>.<action>.<arg>'};
|
|
216
|
+
const declared = dependencies.get(dependency);
|
|
217
|
+
if (!declared && dependency !== 'self') {
|
|
218
|
+
return {typed: null, problem: `names the dependency '${dependency}', which the mount does not have (${[...dependencies.keys()].sort().join(', ') || 'none'})`};
|
|
219
|
+
}
|
|
220
|
+
const actions = (declared?.action_dependencies ?? []).map(each => each.key);
|
|
221
|
+
if (!actions.includes(action)) {
|
|
222
|
+
return {typed: null, problem: `names the action '${action}', which ${dependency} does not have (${[...new Set(actions)].sort().join(', ') || 'none'})`};
|
|
223
|
+
}
|
|
224
|
+
const typed = argumentType(dependency, action, argument, dependencies);
|
|
225
|
+
if (typed === null) return {typed: null, problem: `names the argument '${argument}', which ${dependency}.${action} does not have, or does not type`};
|
|
226
|
+
return {typed, problem: null};
|
|
227
|
+
};
|
|
228
|
+
|
|
176
229
|
class Uses {
|
|
230
|
+
/** Per local node id, the types of the task arguments it is passed to whole. */
|
|
177
231
|
readonly args = new Map<string, InferredType[]>();
|
|
232
|
+
/** Per local node id, the bind kinds of the controls bound to it whole. */
|
|
178
233
|
readonly binds = new Map<string, string[]>();
|
|
179
234
|
readonly deps = new Set<string>();
|
|
180
235
|
|
|
181
|
-
private readonly locals: ReadonlySet<string>;
|
|
182
236
|
private readonly dependencies: ReadonlyMap<string, BlokScopeDependency>;
|
|
183
237
|
private readonly view: BlokView | null;
|
|
184
238
|
|
|
185
|
-
constructor(
|
|
186
|
-
locals: ReadonlySet<string>,
|
|
187
|
-
dependencies: ReadonlyMap<string, BlokScopeDependency>,
|
|
188
|
-
view: BlokView | null,
|
|
189
|
-
) {
|
|
190
|
-
this.locals = locals;
|
|
239
|
+
constructor(dependencies: ReadonlyMap<string, BlokScopeDependency>, view: BlokView | null) {
|
|
191
240
|
this.dependencies = dependencies;
|
|
192
241
|
this.view = view;
|
|
193
242
|
}
|
|
@@ -198,69 +247,74 @@ class Uses {
|
|
|
198
247
|
}
|
|
199
248
|
|
|
200
249
|
walk(tree: BlokComponentNode): void {
|
|
201
|
-
const scope = new
|
|
250
|
+
const scope = new Map<string, string | null>();
|
|
202
251
|
const intoNames = (node: BlokComponentNode): void => {
|
|
203
|
-
for (const prop of node.props ?? []) if (prop.agent_call && prop.declares_value) scope.
|
|
252
|
+
for (const prop of node.props ?? []) if (prop.agent_call && prop.declares_value) scope.set(prop.declares_value, null);
|
|
204
253
|
node.children?.forEach(intoNames);
|
|
205
254
|
};
|
|
206
255
|
intoNames(tree);
|
|
207
256
|
this.node(tree, scope);
|
|
208
257
|
}
|
|
209
258
|
|
|
210
|
-
private node(node: BlokComponentNode, scope:
|
|
259
|
+
private node(node: BlokComponentNode, scope: UseScope): void {
|
|
211
260
|
this.component(node, scope);
|
|
212
261
|
const declared =
|
|
213
262
|
node.component === FOREACH ? node.props?.find(prop => prop.key === FOREACH_LET && prop.declares_value)?.declares_value ?? null : null;
|
|
214
|
-
const inner =
|
|
263
|
+
const inner = new Map(scope);
|
|
264
|
+
if (declared !== null) inner.set(declared, null);
|
|
215
265
|
for (const prop of node.props ?? []) this.prop(prop, declared !== null && prop.key === FOREACH_ITEMS ? scope : inner);
|
|
266
|
+
// Every local of a node is in scope in all of its children.
|
|
267
|
+
for (const child of node.children ?? []) {
|
|
268
|
+
const name = localDeclared(child);
|
|
269
|
+
if (name !== null) inner.set(name, child.id);
|
|
270
|
+
}
|
|
216
271
|
for (const child of node.children ?? []) this.node(child, inner);
|
|
217
272
|
}
|
|
218
273
|
|
|
219
|
-
private component(node: BlokComponentNode, scope:
|
|
274
|
+
private component(node: BlokComponentNode, scope: UseScope): void {
|
|
220
275
|
const bind = this.view?.components.get(node.component)?.props.find(prop => prop.key === BIND_PROP);
|
|
221
276
|
if (!bind) return;
|
|
222
277
|
for (const prop of node.props ?? []) {
|
|
223
278
|
const path = prop.key === BIND_PROP ? prop.dynamic_value?.path ?? null : null;
|
|
224
|
-
|
|
225
|
-
|
|
279
|
+
const local = path !== null ? scope.get(path) ?? null : null;
|
|
280
|
+
if (local !== null) {
|
|
281
|
+
const binds = this.binds.get(local) ?? [];
|
|
226
282
|
binds.push(bind.kind);
|
|
227
|
-
this.binds.set(
|
|
283
|
+
this.binds.set(local, binds);
|
|
228
284
|
}
|
|
229
285
|
}
|
|
230
286
|
}
|
|
231
287
|
|
|
232
|
-
private prop(prop: BlokComponentProp, scope:
|
|
288
|
+
private prop(prop: BlokComponentProp, scope: UseScope): void {
|
|
233
289
|
const path = prop.dynamic_value?.path;
|
|
234
290
|
if (path != null) this.path(path, scope);
|
|
235
291
|
if (prop.agent_call) this.agentCall(prop.agent_call, scope);
|
|
236
292
|
if (prop.util_call) prop.util_call.arguments?.forEach(argument => this.argument(argument, scope));
|
|
237
293
|
}
|
|
238
294
|
|
|
239
|
-
private path(path: string, scope:
|
|
295
|
+
private path(path: string, scope: UseScope): void {
|
|
240
296
|
if (!scope.has(path.split('.')[0])) this.read(path);
|
|
241
297
|
}
|
|
242
298
|
|
|
243
|
-
private argument(argument: BlokActionArgument, scope:
|
|
299
|
+
private argument(argument: BlokActionArgument, scope: UseScope): void {
|
|
244
300
|
if (argument.value_path != null) this.path(argument.value_path, scope);
|
|
245
301
|
if (argument.agent_call) this.agentCall(argument.agent_call, scope);
|
|
246
302
|
if (argument.util_call) argument.util_call.arguments?.forEach(nested => this.argument(nested, scope));
|
|
247
303
|
[...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(nested => this.argument(nested, scope));
|
|
248
304
|
}
|
|
249
305
|
|
|
250
|
-
private agentCall(call: BlokAgentCall, scope:
|
|
306
|
+
private agentCall(call: BlokAgentCall, scope: UseScope): void {
|
|
251
307
|
if (call.dependency !== 'self') this.deps.add(call.dependency);
|
|
252
308
|
const action = actionKeyFor(call);
|
|
253
|
-
const demand = this.dependencies.get(call.dependency)?.action_dependencies?.find(each => each.key === action)?.demand;
|
|
254
|
-
const matches = new Map((demand?.arg_matches ?? []).flatMap(match => (match.key != null ? [[match.key, match] as const] : [])));
|
|
255
309
|
for (const argument of call.arguments ?? []) {
|
|
256
310
|
const path = argument.value_path;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const typed =
|
|
311
|
+
const local = path != null ? scope.get(path) ?? null : null;
|
|
312
|
+
if (local !== null && argument.key != null) {
|
|
313
|
+
const typed = argumentType(call.dependency, action, argument.key, this.dependencies);
|
|
260
314
|
if (typed !== null) {
|
|
261
|
-
const found = this.args.get(
|
|
315
|
+
const found = this.args.get(local) ?? [];
|
|
262
316
|
found.push(typed);
|
|
263
|
-
this.args.set(
|
|
317
|
+
this.args.set(local, found);
|
|
264
318
|
}
|
|
265
319
|
}
|
|
266
320
|
this.argument(argument, scope);
|
|
@@ -268,41 +322,44 @@ class Uses {
|
|
|
268
322
|
}
|
|
269
323
|
}
|
|
270
324
|
|
|
271
|
-
/** Every path a list of arguments reads (a query's variables). */
|
|
272
|
-
const argumentPaths = (args: readonly BlokActionArgument[]): string[] => {
|
|
273
|
-
const paths: string[] = [];
|
|
274
|
-
const visit = (argument: BlokActionArgument): void => {
|
|
275
|
-
if (argument.value_path != null) paths.push(argument.value_path);
|
|
276
|
-
for (const call of [argument.util_call, argument.agent_call]) call?.arguments?.forEach(visit);
|
|
277
|
-
[...(argument.value_list ?? []), ...(argument.value_dict ?? [])].forEach(visit);
|
|
278
|
-
};
|
|
279
|
-
args.forEach(visit);
|
|
280
|
-
return paths;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
325
|
/**
|
|
284
|
-
* Every dependency key a tree (
|
|
285
|
-
* `self` aside, sorted: what a host checks against the
|
|
286
|
-
* (one it did not bind reads as failed, `deps.unbound`).
|
|
326
|
+
* Every dependency key a tree reads or calls (its queries' variables, `<var>`
|
|
327
|
+
* nodes, included), `self` aside, sorted: what a host checks against the
|
|
328
|
+
* agents it bound (one it did not bind reads as failed, `deps.unbound`).
|
|
287
329
|
*/
|
|
288
|
-
export const dependencyKeysRead = (roots: readonly BlokComponentNode[]
|
|
289
|
-
const uses = new Uses(new
|
|
330
|
+
export const dependencyKeysRead = (roots: readonly BlokComponentNode[]): string[] => {
|
|
331
|
+
const uses = new Uses(new Map(), null);
|
|
290
332
|
roots.forEach(root => uses.walk(root));
|
|
291
|
-
argumentPaths(variables).forEach(path => uses.read(path));
|
|
292
333
|
return [...uses.deps].filter(key => key !== 'self').sort();
|
|
293
334
|
};
|
|
294
335
|
|
|
336
|
+
/** A `<local>` with its kind resolved, and why its `like` borrows nothing (null when it borrows, has none, or the blok is not mounted). */
|
|
337
|
+
export type ResolvedLocal = {local: ResolvedBlokLocal; likeProblem: string | null};
|
|
338
|
+
|
|
295
339
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
340
|
+
* Every readable `<local>` of `tree` with its kind resolved (see the module),
|
|
341
|
+
* by node id, in tree order. `dependencies` null is a blok not mounted: a
|
|
342
|
+
* `like` then borrows nothing, and says nothing of it either.
|
|
298
343
|
*/
|
|
299
|
-
export const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
);
|
|
344
|
+
export const resolveLocals = (
|
|
345
|
+
tree: BlokComponentNode,
|
|
346
|
+
dependencies: readonly BlokScopeDependency[] | null,
|
|
347
|
+
view: BlokView | null,
|
|
348
|
+
): Map<string, ResolvedLocal> => {
|
|
349
|
+
const byKey = new Map((dependencies ?? []).map(dependency => [dependency.key, dependency]));
|
|
350
|
+
const uses = new Uses(byKey, view);
|
|
305
351
|
uses.walk(tree);
|
|
306
|
-
const
|
|
307
|
-
|
|
352
|
+
const resolved = new Map<string, ResolvedLocal>();
|
|
353
|
+
for (const [node] of iterWithParents(tree)) {
|
|
354
|
+
if (node.component !== LOCAL_COMPONENT) continue;
|
|
355
|
+
const local = declaredLocal(node);
|
|
356
|
+
if (local === null) continue;
|
|
357
|
+
const like = localLike(node);
|
|
358
|
+
const borrowed = like !== null && dependencies !== null ? borrowedType(like, byKey) : {typed: null, problem: null};
|
|
359
|
+
resolved.set(node.id, {
|
|
360
|
+
local: resolveLocal(local as BlokScopeLocal, uses.args.get(node.id) ?? [], uses.binds.get(node.id) ?? [], borrowed.typed),
|
|
361
|
+
likeProblem: borrowed.problem,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
return resolved;
|
|
308
365
|
};
|
package/src/bsx/language.test.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {describe, expect, it} from 'vitest';
|
|
2
2
|
import {analyzeBsx} from './analyze';
|
|
3
3
|
import {completeBsx, hoverBsx, scanCursor, signatureBsx, type BsxEnvironment} from './language';
|
|
4
|
-
import {
|
|
4
|
+
import {type BlokCheckScope} from './references';
|
|
5
5
|
|
|
6
|
+
/** Where the blok is mounted: its dependencies and args. What it is and owns is in its text. */
|
|
6
7
|
const scope: BlokCheckScope = {
|
|
7
|
-
|
|
8
|
+
kinds: [],
|
|
8
9
|
dependencies: [
|
|
9
10
|
{
|
|
10
11
|
key: 'stage',
|
|
@@ -12,22 +13,25 @@ const scope: BlokCheckScope = {
|
|
|
12
13
|
state_dependencies: [{key: 'position', demand: {matches: [{key: 'x', kind: 'FLOAT'}, {key: 'y', kind: 'FLOAT'}]}}],
|
|
13
14
|
},
|
|
14
15
|
],
|
|
15
|
-
locals: [
|
|
16
|
-
{key: 'speed', kind: 'INT', default: 1},
|
|
17
|
-
{key: 'form', kind: 'DICT', children: [{key: 'name', kind: 'STRING'}, {key: 'count', kind: 'INT'}]},
|
|
18
|
-
],
|
|
19
|
-
queries: [
|
|
20
|
-
{key: 'positions', service: 'mikro', document: 'query { positions { id } }'},
|
|
21
|
-
{key: 'pages', service: 'mikro', document: 'query { pages { id } }', more: 'pages'},
|
|
22
|
-
],
|
|
23
16
|
args: ['image'],
|
|
24
17
|
};
|
|
25
18
|
|
|
26
19
|
const env = (overrides: Partial<BlokCheckScope> = {}): BsxEnvironment => ({scope: {...scope, ...overrides}});
|
|
27
20
|
|
|
28
|
-
/**
|
|
29
|
-
const
|
|
30
|
-
|
|
21
|
+
/** The `<Blok>` (a panel of `kind`) and its declarations, written before the text under test. */
|
|
22
|
+
const prelude = (kind: string): string =>
|
|
23
|
+
`<Blok kind="${kind}" context="panel">` +
|
|
24
|
+
'<local name="speed" kind="INT" default={1} />' +
|
|
25
|
+
'<local name="form" kind="DICT" children={[{key: "name", kind: "STRING"}, {key: "count", kind: "INT"}]} />' +
|
|
26
|
+
'<query name="positions" service="mikro" document="query { positions { id } }" />' +
|
|
27
|
+
'<query name="pages" service="mikro" document="query { pages { id } }" more="pages" />';
|
|
28
|
+
|
|
29
|
+
/** Completions at `|` in the source as it stands. */
|
|
30
|
+
const atRaw = (marked: string, environment = env()) => completeBsx(marked.replace('|', ''), marked.indexOf('|'), environment);
|
|
31
|
+
/** Completions at `|` in the source, inside a custom blok (or one of `kind`) that declares two locals and two queries. */
|
|
32
|
+
const at = (marked: string, environment = env(), kind = 'custom') => atRaw(`${prelude(kind)}${marked}`, environment);
|
|
33
|
+
const labels = (marked: string, environment = env(), kind = 'custom') => at(marked, environment, kind).map(item => item.label);
|
|
34
|
+
const rawLabels = (marked: string) => atRaw(marked).map(item => item.label);
|
|
31
35
|
|
|
32
36
|
describe('scanCursor', () => {
|
|
33
37
|
it('knows where the cursor is', () => {
|
|
@@ -67,11 +71,18 @@ describe('completeBsx: components and props', () => {
|
|
|
67
71
|
expect(labels('<Card><|')).not.toContain('Model');
|
|
68
72
|
expect(labels('<Scene><Model><|')).toContain('OnClick');
|
|
69
73
|
expect(labels('<Scene><|')).not.toContain('OnClick');
|
|
70
|
-
|
|
71
|
-
expect(
|
|
72
|
-
|
|
73
|
-
expect(
|
|
74
|
-
expect(
|
|
74
|
+
// A blok starts with its <Blok>; what its root holds is what its context takes.
|
|
75
|
+
expect(rawLabels('<|')).toEqual(['Blok']);
|
|
76
|
+
const scene = rawLabels('<Blok kind="agent" context="scene"><|');
|
|
77
|
+
expect(scene).toEqual(expect.arrayContaining(['Scene', 'local', 'query']));
|
|
78
|
+
expect(scene).not.toContain('Space');
|
|
79
|
+
expect(scene).not.toContain('Card');
|
|
80
|
+
expect(rawLabels('<Blok kind="action" context="scene"><|')).toEqual(expect.arrayContaining(['Scene', 'Space']));
|
|
81
|
+
expect(rawLabels('<Blok kind="agent" context="logo"><|')).toContain('Logo');
|
|
82
|
+
expect(rawLabels('<Blok kind="agent" context="logo"><|')).not.toContain('Card');
|
|
83
|
+
expect(rawLabels('<Blok kind="agent" context="panel"><|')).toEqual(expect.arrayContaining(['Card', 'local', 'query']));
|
|
84
|
+
// Queries are children of the <Blok>, nowhere deeper.
|
|
85
|
+
expect(rawLabels('<Blok kind="agent" context="panel"><Card><|')).not.toContain('query');
|
|
75
86
|
});
|
|
76
87
|
|
|
77
88
|
it('offers the props not yet set, required first, then id and when', () => {
|
|
@@ -101,7 +112,7 @@ describe('completeBsx: expressions', () => {
|
|
|
101
112
|
expect(items).not.toContain('self');
|
|
102
113
|
expect(items).not.toContain('task');
|
|
103
114
|
expect(items).not.toContain('event');
|
|
104
|
-
expect(labels('<Text text={|', env(
|
|
115
|
+
expect(labels('<Text text={|', env(), 'agent')).toContain('self');
|
|
105
116
|
});
|
|
106
117
|
|
|
107
118
|
it('walks agents: states, tasks, assets, fields, and actions only in callbacks', () => {
|
|
@@ -146,7 +157,7 @@ describe('completeBsx: expressions', () => {
|
|
|
146
157
|
expect(labels('<Text text={str.|')).toEqual(expect.arrayContaining(['upper', 'template', 'classes']));
|
|
147
158
|
expect(labels('<Text text={|')).not.toContain('ui');
|
|
148
159
|
expect(labels('<Button onClick={ui.|')).toEqual(['copy']);
|
|
149
|
-
expect(labels('<Button onClick={task.|', env(
|
|
160
|
+
expect(labels('<Button onClick={task.|', env(), 'task')).toContain('answer');
|
|
150
161
|
});
|
|
151
162
|
|
|
152
163
|
it('offers into after a task call', () => {
|
|
@@ -162,7 +173,7 @@ describe('hover and signatures', () => {
|
|
|
162
173
|
const source = '<Text text={str.upper(deps.stage.id)} />';
|
|
163
174
|
expect(hoverBsx(source, source.indexOf('upper') + 1, env())?.contents).toContain('str.upper(value)');
|
|
164
175
|
expect(hoverBsx(source, source.indexOf('deps') + 1, env())?.contents).toContain('**deps**');
|
|
165
|
-
expect(hoverBsx('<Time value={then} relative />', 2, env())?.contents).toContain('base@
|
|
176
|
+
expect(hoverBsx('<Time value={then} relative />', 2, env())?.contents).toContain('base@4');
|
|
166
177
|
const then = '<Time value={then} />';
|
|
167
178
|
expect(hoverBsx(then, then.indexOf('then') + 1, env())?.contents).toContain('**then**');
|
|
168
179
|
});
|
|
@@ -181,7 +192,7 @@ describe('analyzeBsx', () => {
|
|
|
181
192
|
const analyze = (source: string, overrides: Partial<BlokCheckScope> = {}) => analyzeBsx(source, {scope: {...scope, ...overrides}});
|
|
182
193
|
|
|
183
194
|
it('marks a finding at its prop, with its code', () => {
|
|
184
|
-
const source = '<
|
|
195
|
+
const source = '<Blok kind="custom" context="panel"><Text text={deps.stage.speed} /></Blok>';
|
|
185
196
|
const {markers} = analyze(source);
|
|
186
197
|
expect(markers).toHaveLength(1);
|
|
187
198
|
expect(markers[0]).toMatchObject({code: 'deps.unknown_state', severity: 'error'});
|
|
@@ -189,12 +200,13 @@ describe('analyzeBsx', () => {
|
|
|
189
200
|
});
|
|
190
201
|
|
|
191
202
|
it('marks warnings as warnings', () => {
|
|
192
|
-
const {markers} = analyze('<
|
|
203
|
+
const {markers} = analyze('<Blok kind="custom" context="panel"><Badge className="bg-green-500" /></Blok>');
|
|
193
204
|
expect(markers).toMatchObject([{code: 'palette.raw_colour', severity: 'warning'}]);
|
|
194
205
|
});
|
|
195
206
|
|
|
196
|
-
it('marks a root
|
|
197
|
-
expect(analyze('<Card />'
|
|
207
|
+
it('marks a root that is no <Blok>, and a blok mounted where its kind does not go', () => {
|
|
208
|
+
expect(analyze('<Card />').markers.map(marker => marker.code)).toEqual(['blok.root']);
|
|
209
|
+
expect(analyze('<Blok kind="agent" context="panel"><Card /></Blok>', {kinds: ['action', 'assign']}).markers.map(marker => marker.code)).toEqual(['kind.placement']);
|
|
198
210
|
});
|
|
199
211
|
|
|
200
212
|
it('returns no tree for text that does not parse, and the refusal', () => {
|
package/src/bsx/language.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {defaultBlokView, innerContext, type BlokView, type SpecComponent, type SpecProp} from '../spec/catalogs';
|
|
2
|
-
import {loadVocabulary, type BlokContextName, type VocabFunction, type VocabRecordField} from '../spec/vocabulary';
|
|
2
|
+
import {BLOK_KINDS, kindIn, loadVocabulary, type BlokContextName, type BlokKind, type VocabFunction, type VocabRecordField} from '../spec/vocabulary';
|
|
3
|
+
import {BLOK_COMPONENT, declaredQueries, declaredSubscriptions, QUERY_COMPONENT, SUBSCRIPTION_COMPONENT} from './declared';
|
|
4
|
+
import {resolveLocals} from './infer';
|
|
3
5
|
import {FOREACH_COMPONENT, FOREACH_LET_PROP, INTO_KEYWORD} from './parse';
|
|
4
|
-
import {
|
|
6
|
+
import {parseBsxPartial} from './partial';
|
|
7
|
+
import {type BlokCheckScope, type BlokPortMatch, type BlokScopeDependency, type BlokScopeLocalPort, type ResolvedBlokLocal} from './references';
|
|
5
8
|
import type {BsxRange} from './source';
|
|
6
9
|
|
|
7
10
|
/**
|
|
@@ -12,8 +15,12 @@ import type {BsxRange} from './source';
|
|
|
12
15
|
*/
|
|
13
16
|
|
|
14
17
|
export type BsxEnvironment = {
|
|
15
|
-
/**
|
|
16
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Where the blok is mounted (its dependencies, args, ...); absent: mounted
|
|
20
|
+
* nowhere. What the blok is (kind, context) and owns (locals, queries,
|
|
21
|
+
* subscriptions) is read off its text.
|
|
22
|
+
*/
|
|
23
|
+
scope?: BlokCheckScope | null;
|
|
17
24
|
/** The catalogs that draw it; the Orkestrator's when left out. */
|
|
18
25
|
view?: BlokView;
|
|
19
26
|
};
|
|
@@ -53,6 +60,29 @@ const isSpace = (char: string | undefined) => char !== undefined && /\s/.test(ch
|
|
|
53
60
|
|
|
54
61
|
const viewOf = (env: BsxEnvironment): BlokView => env.view ?? defaultBlokView();
|
|
55
62
|
|
|
63
|
+
/** What the open `<Blok>` says of itself (its kind and context); an agent panel while it says nothing. */
|
|
64
|
+
const headerAt = (stack: readonly OpenElement[]): {kind: BlokKind; context: BlokContextName} => {
|
|
65
|
+
const root = stack[0]?.tag === BLOK_COMPONENT ? stack[0].attributes : null;
|
|
66
|
+
const unquote = (value: string | undefined) => (value ?? '').replace(/^["']|["']$/g, '');
|
|
67
|
+
const kind = unquote(root?.get('kind'));
|
|
68
|
+
const context = loadVocabulary().blok.contexts[unquote(root?.get('context'))];
|
|
69
|
+
return {kind: (BLOK_KINDS as readonly string[]).includes(kind) ? (kind as BlokKind) : 'agent', context: context ?? 'PANEL'};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const dependenciesOf = (env: BsxEnvironment): readonly BlokScopeDependency[] => env.scope?.dependencies ?? [];
|
|
73
|
+
|
|
74
|
+
/** What the text declares, as far as it parses: its locals (resolved), queries and subscriptions. */
|
|
75
|
+
const declaredIn = (env: BsxEnvironment, text: string) => {
|
|
76
|
+
const tree = parseBsxPartial(text, env.view).tree ?? null;
|
|
77
|
+
const locals = new Map<string, ResolvedBlokLocal>();
|
|
78
|
+
if (tree) {
|
|
79
|
+
for (const {local} of resolveLocals(tree, env.scope?.dependencies ?? null, viewOf(env)).values()) {
|
|
80
|
+
if (!locals.has(local.key)) locals.set(local.key, local);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {locals, queries: declaredQueries(tree), subscriptions: declaredSubscriptions(tree)};
|
|
84
|
+
};
|
|
85
|
+
|
|
56
86
|
/** The index of the `}` closing the brace at `start`, or -1 when it is not closed before `limit`. */
|
|
57
87
|
const closingBrace = (text: string, start: number, limit: number): number => {
|
|
58
88
|
let depth = 1;
|
|
@@ -246,10 +276,23 @@ const describeFunction = (fn: VocabFunction): string =>
|
|
|
246
276
|
|
|
247
277
|
const contextAt = (env: BsxEnvironment, stack: readonly OpenElement[]): BlokContextName => {
|
|
248
278
|
const view = viewOf(env);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
279
|
+
// The <Blok> says the context its content is in.
|
|
280
|
+
const inner = stack[0]?.tag === BLOK_COMPONENT ? stack.slice(1) : stack;
|
|
281
|
+
return inner.reduce<BlokContextName>((context, element) => innerContext(view.components.get(element.tag), context), headerAt(stack).context);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/** What starts a blok: its `<Blok>`. */
|
|
285
|
+
const blokCompletion = (from: number): BsxCompletion => {
|
|
286
|
+
const vocabulary = loadVocabulary();
|
|
287
|
+
return {
|
|
288
|
+
label: vocabulary.blok.component,
|
|
289
|
+
insertText: `${vocabulary.blok.component} kind="\${1|${Object.keys(vocabulary.kinds).join(',')}|}" context="\${2|${Object.keys(vocabulary.blok.contexts).join(',')}|}">\n\t$0\n</${vocabulary.blok.component}>`,
|
|
290
|
+
snippet: true,
|
|
291
|
+
kind: 'component',
|
|
292
|
+
detail: 'the blok: its kind and context',
|
|
293
|
+
documentation: vocabulary.blok.attributes ? Object.entries(vocabulary.blok.attributes).map(([key, text]) => `**${key}**: ${text}`).join('\n\n') : undefined,
|
|
294
|
+
from,
|
|
295
|
+
};
|
|
253
296
|
};
|
|
254
297
|
|
|
255
298
|
const fitsUnder = (component: SpecComponent, ancestors: readonly string[], context: BlokContextName): boolean => {
|
|
@@ -287,19 +330,21 @@ const completeTag = (env: BsxEnvironment, cursor: Extract<BsxCursor, {kind: 'tag
|
|
|
287
330
|
const view = viewOf(env);
|
|
288
331
|
const {stack, from} = cursor;
|
|
289
332
|
const components = [...view.components.values()];
|
|
290
|
-
if (stack.length === 0)
|
|
291
|
-
const context = drawnIn(env.scope) as BlokContextName;
|
|
292
|
-
// A Space places the run's dependencies: it starts only an action's own blok, which has a run.
|
|
293
|
-
const roots = blokRootsOf(env.scope.context).filter(root => root !== 'Space' || env.scope.kind === 'action');
|
|
294
|
-
const candidates = roots.length ? components.filter(component => roots.includes(component.name)) : components.filter(component => fitsUnder(component, [], context));
|
|
295
|
-
return candidates.map(component => componentCompletion(component, from));
|
|
296
|
-
}
|
|
333
|
+
if (stack.length === 0) return [blokCompletion(from)];
|
|
297
334
|
const parent = view.components.get(stack[stack.length - 1].tag);
|
|
298
335
|
if (parent && !parent.acceptsChildren) return [];
|
|
299
336
|
const ancestors = stack.map(element => element.tag);
|
|
337
|
+
const header = headerAt(stack);
|
|
338
|
+
const atRoot = stack.length === 1 && stack[0].tag === BLOK_COMPONENT;
|
|
339
|
+
const declarations = new Set(Object.keys(loadVocabulary().blok.declarations));
|
|
340
|
+
// A scene or a logo holds one element of its own (a Space only in an action's blok, which has a run).
|
|
341
|
+
const content = atRoot ? loadVocabulary().blok.content[header.context]?.filter(name => name !== 'Space' || header.kind === 'action') : undefined;
|
|
300
342
|
const context = contextAt(env, stack);
|
|
301
343
|
return components
|
|
302
|
-
.filter(component =>
|
|
344
|
+
.filter(component => component.name !== BLOK_COMPONENT)
|
|
345
|
+
// Queries and subscriptions are children of the <Blok>.
|
|
346
|
+
.filter(component => atRoot || (component.name !== QUERY_COMPONENT && component.name !== SUBSCRIPTION_COMPONENT))
|
|
347
|
+
.filter(component => (content ? content.includes(component.name) || declarations.has(component.name) : fitsUnder(component, ancestors, context)))
|
|
303
348
|
.map(component => ({
|
|
304
349
|
...componentCompletion(component, from),
|
|
305
350
|
// What can only sit here (a part of its parent) comes first.
|
|
@@ -447,13 +492,15 @@ const foreachLets = (stack: readonly OpenElement[]): string[] =>
|
|
|
447
492
|
.filter(Boolean);
|
|
448
493
|
|
|
449
494
|
const dependencyOf = (env: BsxEnvironment, key: string): BlokScopeDependency | undefined =>
|
|
450
|
-
env.
|
|
495
|
+
dependenciesOf(env).find(dependency => dependency.key === key);
|
|
451
496
|
|
|
452
497
|
const completeExpression = (env: BsxEnvironment, text: string, expression: string, end: number, place: ExpressionPlace): BsxCompletion[] => {
|
|
453
498
|
if (inString(expression)) return [];
|
|
454
499
|
const vocabulary = loadVocabulary();
|
|
455
500
|
const view = viewOf(env);
|
|
456
|
-
const
|
|
501
|
+
const header = headerAt(place.stack);
|
|
502
|
+
const roots = kindIn(vocabulary.kinds[header.kind], header.context).roots;
|
|
503
|
+
const declared = declaredIn(env, text);
|
|
457
504
|
const calls = place.callback !== null;
|
|
458
505
|
const depth = (expression.replace(/"[^"]*"|'[^']*'/g, '').match(/\(/g) ?? []).length - (expression.replace(/"[^"]*"|'[^']*'/g, '').match(/\)/g) ?? []).length;
|
|
459
506
|
// Only the callback's own one thing may be a call; arguments are values.
|
|
@@ -546,7 +593,7 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
|
|
|
546
593
|
for (const root of roots) items.push(item(root, 'keyword', 'root', vocabulary.dataRoots[root]));
|
|
547
594
|
if (calls) items.push(item('event', 'keyword', 'what the component hands its callback', vocabulary.dataRoots.event));
|
|
548
595
|
if (place.inErrorSlot) items.push(item('error', 'keyword', 'the error that made the boundary show', vocabulary.scopedRoots.error));
|
|
549
|
-
for (const local of
|
|
596
|
+
for (const local of declared.locals.keys()) items.push(item(local, 'path', 'local'));
|
|
550
597
|
for (const name of into) items.push(item(name, 'path', "a call's record"));
|
|
551
598
|
for (const name of lets) items.push(item(name, 'path', 'foreach item'));
|
|
552
599
|
for (const namespace of vocabulary.functionNamespaces) {
|
|
@@ -573,7 +620,7 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
|
|
|
573
620
|
const action = dependency?.action_dependencies?.find(candidate => candidate.key === call?.[2]);
|
|
574
621
|
return taskRecord(rest, action?.demand?.return_matches);
|
|
575
622
|
}
|
|
576
|
-
const local =
|
|
623
|
+
const local = declared.locals.get(first);
|
|
577
624
|
if (local) {
|
|
578
625
|
// A local is a port: complete the fields its port declares (a list's item is keyed `...`).
|
|
579
626
|
let port: Pick<BlokScopeLocalPort, 'children'> | undefined = local;
|
|
@@ -595,10 +642,10 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
|
|
|
595
642
|
case 'self':
|
|
596
643
|
return agent(dependencyOf(env, 'self'), rest);
|
|
597
644
|
case 'deps':
|
|
598
|
-
if (rest.length === 0) return env.
|
|
645
|
+
if (rest.length === 0) return dependenciesOf(env).filter(dependency => dependency.key !== 'self').map(dependency => item(dependency.key, 'dependency', 'dependency'));
|
|
599
646
|
return agent(dependencyOf(env, rest[0]), rest.slice(1));
|
|
600
647
|
case 'args':
|
|
601
|
-
return rest.length === 0 ? (env.scope
|
|
648
|
+
return rest.length === 0 ? (env.scope?.args ?? []).map(arg => item(arg, 'path', 'arg')) : [];
|
|
602
649
|
case 'task':
|
|
603
650
|
return taskRecord(rest, null);
|
|
604
651
|
case 'viewer': {
|
|
@@ -606,14 +653,14 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
|
|
|
606
653
|
return fields ? fieldItems(fields, 'viewer') : [];
|
|
607
654
|
}
|
|
608
655
|
case 'queries':
|
|
609
|
-
if (rest.length === 0) return
|
|
656
|
+
if (rest.length === 0) return declared.queries.map(query => item(query.key, 'path', `query · ${query.service ?? ''}`));
|
|
610
657
|
if (rest.length === 1) {
|
|
611
658
|
return [
|
|
612
659
|
...fieldItems(recordFields('query'), 'query record'),
|
|
613
660
|
...(topCall
|
|
614
661
|
? [
|
|
615
662
|
item('refetch', 'function', 'read it again (stale-while-revalidate)', undefined, 'refetch()'),
|
|
616
|
-
...(
|
|
663
|
+
...(declared.queries.find(query => query.key === rest[0])?.more
|
|
617
664
|
? [item('fetch_more', 'function', 'read the next page and append it', undefined, 'fetch_more($1)', true)]
|
|
618
665
|
: []),
|
|
619
666
|
]
|
|
@@ -622,7 +669,7 @@ const completeExpression = (env: BsxEnvironment, text: string, expression: strin
|
|
|
622
669
|
}
|
|
623
670
|
return [];
|
|
624
671
|
case 'subscriptions':
|
|
625
|
-
if (rest.length === 0) return
|
|
672
|
+
if (rest.length === 0) return declared.subscriptions.map(subscription => item(subscription.key, 'path', `subscription · ${subscription.service ?? ''}`));
|
|
626
673
|
return rest.length === 1 ? fieldItems(recordFields('subscription'), 'subscription record') : [];
|
|
627
674
|
default:
|
|
628
675
|
return [];
|