@joplo-app/core 0.2.18 → 0.3.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/actions.d.ts +6 -0
- package/dist/actions.js +34 -0
- package/dist/agent-skill.d.ts +9 -15
- package/dist/agent-skill.js +41 -44
- package/dist/auto-caption.d.ts +3 -0
- package/dist/auto-caption.js +33 -0
- package/dist/catalog.d.ts +39 -42
- package/dist/catalog.js +27 -329
- package/dist/compile.d.ts +2 -8
- package/dist/compile.js +225 -393
- package/dist/content-i18n.js +27 -16
- package/dist/feature-diff.d.ts +9 -9
- package/dist/feature-diff.js +28 -6
- package/dist/focus.d.ts +3 -1
- package/dist/focus.js +16 -34
- package/dist/guide.d.ts +10 -12
- package/dist/guide.js +363 -591
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/media.d.ts +10 -0
- package/dist/media.js +43 -0
- package/dist/node.d.ts +1 -2
- package/dist/node.js +1 -2
- package/dist/outline.js +1 -1
- package/dist/pace.d.ts +4 -1
- package/dist/pace.js +7 -3
- package/dist/player.d.ts +8 -41
- package/dist/player.js +83 -147
- package/dist/playground.d.ts +38 -0
- package/dist/playground.js +111 -0
- package/dist/plugin-data.d.ts +11 -0
- package/dist/plugin-data.js +96 -0
- package/dist/plugins/compiler.d.ts +66 -0
- package/dist/plugins/compiler.js +428 -0
- package/dist/plugins/data.d.ts +12 -0
- package/dist/plugins/data.js +120 -0
- package/dist/result.d.ts +1 -1
- package/dist/result.js +1 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.js +18 -0
- package/dist/schema.d.ts +590 -112
- package/dist/schema.js +60 -52
- package/dist/scope.js +14 -5
- package/dist/step-identity.d.ts +1 -1
- package/dist/step-identity.js +1 -1
- package/dist/themes.d.ts +7 -0
- package/dist/themes.js +5 -0
- package/dist/traits.d.ts +7 -0
- package/dist/traits.js +26 -0
- package/dist/validate.js +17 -4
- package/package.json +7 -4
- package/dist/diagram/elk.d.ts +0 -6
- package/dist/diagram/elk.js +0 -56
- package/dist/diagram/graph-layout.d.ts +0 -123
- package/dist/diagram/graph-layout.js +0 -620
- package/dist/diagram/index.d.ts +0 -41
- package/dist/diagram/index.js +0 -92
- package/dist/diagram/model.d.ts +0 -217
- package/dist/diagram/model.js +0 -189
- package/dist/diagram/sequence-layout.d.ts +0 -12
- package/dist/diagram/sequence-layout.js +0 -185
package/dist/compile.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { validActionData, pluginActionSpec } from "./actions.js";
|
|
1
2
|
/**
|
|
2
3
|
* 编译:作者的源文件(经 @joplo-app/kit 收集成数据)→ IR v2。组件词汇对齐 Mantine(D35),见 catalog.ts。
|
|
3
4
|
*
|
|
@@ -8,13 +9,14 @@
|
|
|
8
9
|
* - review 模式(评审版,D63):画面与场景同 dev(所有功能的所有方案),创作侧信息按 publish 的规则去掉。
|
|
9
10
|
*/
|
|
10
11
|
import { isBind, isNode, bindPath, toCondition } from '@joplo-app/kit/node';
|
|
11
|
-
import { BUILTIN_THEMES, COMPONENT_TYPES, DIRECTOR_LAYER,
|
|
12
|
+
import { BUILTIN_THEMES, COMPONENT_TYPES, DIRECTOR_LAYER, PAGE_LAYER, isInteractiveType, matchChoice, nodeLabel, pluginSpec, splitPluginType } from "./catalog.js";
|
|
12
13
|
import { HOLD_MAX_SECONDS, HOLD_MIN_SECONDS, inShotFrame } from "./focus.js";
|
|
13
14
|
import { cameraAt, choicesOf, commonPrefix, stateAt } from "./player.js";
|
|
14
|
-
import { CALLOUT_SIDES, LAYER_ICONS, Project, SCHEMA_VERSION } from "./schema.js";
|
|
15
|
+
import { Action, Effect, CALLOUT_SIDES, LAYER_ICONS, Project, SCHEMA_VERSION } from "./schema.js";
|
|
15
16
|
import { schemaDiagnostics } from "./schema-issues.js";
|
|
16
17
|
import { CONTENT_LOCALES, collectMessages, isContentLocale, nearestKey, pruneMessages } from "./content-i18n.js";
|
|
17
|
-
import {
|
|
18
|
+
import { PluginCompiler } from "./plugins/compiler.js";
|
|
19
|
+
import { materialize, errorMessage } from "./plugins/data.js";
|
|
18
20
|
const KNOWN = new Set(COMPONENT_TYPES);
|
|
19
21
|
const OVERLAY = 'overlay';
|
|
20
22
|
const MOCK_LABEL = { success: 'Mock success', failure: 'Mock failure', denied: 'Mock permission denied', other: 'Mock' };
|
|
@@ -60,6 +62,12 @@ export function compile(src, mode, opts = {}) {
|
|
|
60
62
|
scenarios: {},
|
|
61
63
|
issues: {},
|
|
62
64
|
};
|
|
65
|
+
// ---------- 0. 插件(D86):只取清单里的组件声明,运行时代码不进 IR ----------
|
|
66
|
+
const host = new PluginCompiler(src.config.plugins, report, src.config.source ?? `${src.config.file}:1:1`, opts);
|
|
67
|
+
const plugins = host.info;
|
|
68
|
+
if (Object.keys(plugins).length)
|
|
69
|
+
out.plugins = plugins;
|
|
70
|
+
const nodeCtx = { plugins, host, report, rel };
|
|
63
71
|
// ---------- 1. 选出参与的方案 ----------
|
|
64
72
|
// 排序只在编译时决定;显式列表不依赖对象键的枚举顺序,发布模式也保留这份演示内容。
|
|
65
73
|
for (const [fid, f] of Object.entries(src.features)) {
|
|
@@ -205,10 +213,13 @@ export function compile(src, mode, opts = {}) {
|
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
215
|
const base = tree;
|
|
208
|
-
const rootJ = { ...base, type: base.type
|
|
216
|
+
const rootJ = { ...base, type: base.type, children: [...base.children, ...overlays] };
|
|
209
217
|
const ids = new Map();
|
|
210
|
-
const root = toSceneNode(rootJ, 'root', ids,
|
|
211
|
-
|
|
218
|
+
const root = toSceneNode(rootJ, 'root', ids, nodeCtx, null);
|
|
219
|
+
const scene = { id: sceneId, optionId: ctx?.qid ?? null, route: route.path, name: `${page.title}${ctx ? ` · ${ctx.def.name}` : ''}`, viewport: page.viewport ?? 'desktop', root };
|
|
220
|
+
if (!diags.some(d => d.severity === 'error'))
|
|
221
|
+
host.derive(scene);
|
|
222
|
+
return scene;
|
|
212
223
|
};
|
|
213
224
|
if (src.config.voice !== undefined && !voiceConfigOf(src.config.voice, true))
|
|
214
225
|
err('VOICE_CONFIG_INVALID', `config({ voice }) must be { profile?: string, narrator?: string, roles?: { [roleKey]: string }, locales?: { [locale]: { narrator?: string, roles?: { [roleKey]: string } } } } with non-empty strings; got ${JSON.stringify(src.config.voice)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
@@ -220,7 +231,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
220
231
|
// 主题(D51):config.theme 必须是内置主题或 themes/<name>.css
|
|
221
232
|
{
|
|
222
233
|
const t = src.config.theme ?? 'sketch';
|
|
223
|
-
const authorThemes = Object.keys(
|
|
234
|
+
const authorThemes = [...Object.keys(out.themes), ...Object.keys(host.themes)];
|
|
224
235
|
if (!BUILTIN_THEMES.includes(t) && !authorThemes.includes(t))
|
|
225
236
|
err('THEME_UNKNOWN', `config({ theme: '${t}' }) is not a built-in theme (${BUILTIN_THEMES.join(', ')}), and the project has no themes/${t}.css${authorThemes.length ? ` (author themes: ${authorThemes.join(', ')})` : ''}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
226
237
|
}
|
|
@@ -277,11 +288,13 @@ export function compile(src, mode, opts = {}) {
|
|
|
277
288
|
err('LAYER_UNKNOWN', `Layer "${ld.title}" has no content: layer(title, <Page />)`, at);
|
|
278
289
|
continue;
|
|
279
290
|
}
|
|
280
|
-
const rootJ = nodes.length === 1 ? nodes[0] : { ...nodes[0], type: '
|
|
291
|
+
const rootJ = nodes.length === 1 ? nodes[0] : { ...nodes[0], type: '#fragment', props: {}, children: nodes };
|
|
281
292
|
const ids = new Map();
|
|
282
|
-
const root = toSceneNode(rootJ, `layer_${lk}`, ids,
|
|
293
|
+
const root = toSceneNode(rootJ, `layer_${lk}`, ids, nodeCtx, null);
|
|
283
294
|
const sceneId = `${qid}~${lk}`;
|
|
284
295
|
const scene = { id: sceneId, optionId: qid, route: layerRoute, name: `${ld.title} · ${def.name}`, viewport: ld.viewport ?? 'desktop', root, layer: lk };
|
|
296
|
+
if (!diags.some(d => d.severity === 'error'))
|
|
297
|
+
host.derive(scene);
|
|
285
298
|
addScene(scene);
|
|
286
299
|
layerScenes.push({ key: lk, scene });
|
|
287
300
|
if (ld.role !== undefined && !roleKeys.has(ld.role))
|
|
@@ -296,93 +309,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
296
309
|
/** 元素在哪些层级里(多层都有同名 id 时都算)。 */
|
|
297
310
|
const layersWith = (id) => layerScenes.filter((l) => findIn(l.scene.root, id)).map((l) => l.key);
|
|
298
311
|
const layerSceneWith = (id) => layerScenes.find((l) => findIn(l.scene.root, id))?.scene;
|
|
299
|
-
|
|
300
|
-
const diagrams = [...layerScenes.map((l) => l.scene), ...[...sceneFor.values()].filter((x) => x.optionId === qid || x.optionId === null || x.optionId === undefined)].flatMap((x) => diagramsIn(x.root));
|
|
301
|
-
const resolveTrace = (ids, tmode, at) => {
|
|
302
|
-
const shown = `trace(${ids.map((x) => JSON.stringify(x)).join(', ')})`;
|
|
303
|
-
if (!ids.length) {
|
|
304
|
-
err('TRACE_UNKNOWN', `${shown} requires at least one node or edge id`, at);
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
const has = (d, t) => d.nodes.has(t) || d.edges.some((e) => e.id === t);
|
|
308
|
-
const d = diagrams.find((x) => ids.every((t) => has(x, t)));
|
|
309
|
-
if (!d) {
|
|
310
|
-
const missing = ids.find((t) => !diagrams.some((x) => has(x, t)));
|
|
311
|
-
err('TRACE_UNKNOWN', missing ? `${shown} contains "${missing}", which is not a node, group, edge, state, transition, actor or message id in any Diagram / StateMachine / Sequence` : `${shown} mixes elements from different diagrams; trace one diagram at a time`, at);
|
|
312
|
-
return null;
|
|
313
|
-
}
|
|
314
|
-
const nodes = [];
|
|
315
|
-
const edges = [];
|
|
316
|
-
const addNode = (n) => {
|
|
317
|
-
if (!nodes.includes(n))
|
|
318
|
-
nodes.push(n);
|
|
319
|
-
};
|
|
320
|
-
/** 节点(或分组)自己是分组时连同它算进去,再加上它的各级父分组。 */
|
|
321
|
-
const groupsOfNode = (n) => [...(d.groupIds.has(n) ? [n] : []), ...(d.groupsOf.get(n) ?? [])];
|
|
322
|
-
const finishTrace = () => {
|
|
323
|
-
if (tmode === 'skip')
|
|
324
|
-
return { mode: tmode, nodes, edges, ...(d.type === 'Sequence' ? { targets: [] } : {}) };
|
|
325
|
-
const all = [...new Set(nodes.flatMap(groupsOfNode))];
|
|
326
|
-
const last = nodes[nodes.length - 1];
|
|
327
|
-
// 失败只标红终点所在的最内层分组(终点本身是分组时就是它);外层分组照常 active,不把整个云账号都标红
|
|
328
|
-
const errorGroups = tmode === 'fail' && last ? groupsOfNode(last).slice(0, 1) : [];
|
|
329
|
-
return {
|
|
330
|
-
mode: tmode,
|
|
331
|
-
nodes,
|
|
332
|
-
edges,
|
|
333
|
-
...(all.some((g) => !errorGroups.includes(g)) ? { groups: all.filter((g) => !errorGroups.includes(g)) } : {}),
|
|
334
|
-
...(errorGroups.length ? { errorGroups } : {}),
|
|
335
|
-
// 时序图的镜头对准消息所在的行(参与者头部在最上面,对准它们会把镜头拉离正在讲的那一行)
|
|
336
|
-
...(d.type === 'Sequence' ? { targets: edges.map((e) => e.id) } : {}),
|
|
337
|
-
};
|
|
338
|
-
};
|
|
339
|
-
// trace.skip 标记“这次没被调用”的一组元素,不是路径:节点和连线各自 dim,不要求彼此相连
|
|
340
|
-
if (tmode === 'skip') {
|
|
341
|
-
for (const t of ids) {
|
|
342
|
-
if (d.nodes.has(t))
|
|
343
|
-
addNode(t);
|
|
344
|
-
else
|
|
345
|
-
edges.push({ id: t, reverse: false });
|
|
346
|
-
}
|
|
347
|
-
return finishTrace();
|
|
348
|
-
}
|
|
349
|
-
const kind = d.type === 'Sequence' ? 'Sequence.Message' : d.type === 'StateMachine' ? 'StateMachine.Transition' : 'Diagram.Edge';
|
|
350
|
-
let prev = null;
|
|
351
|
-
for (const t of ids) {
|
|
352
|
-
const edge = d.edges.find((e) => e.id === t);
|
|
353
|
-
if (edge) {
|
|
354
|
-
// 写连线 id:方向由上一个节点决定(从 to 端接上时逆向走);时序图的消息各自独立,连续写几条消息 id 不要求首尾相接
|
|
355
|
-
const reverse = prev !== null && prev === edge.to && prev !== edge.from;
|
|
356
|
-
if (d.type !== 'Sequence' && prev !== null && prev !== edge.from && prev !== edge.to) {
|
|
357
|
-
err('TRACE_UNKNOWN', `${shown}: edge "${t}"(${edge.from} → ${edge.to}) is not connected to the previous node "${prev}"`, at);
|
|
358
|
-
return null;
|
|
359
|
-
}
|
|
360
|
-
edges.push({ id: edge.id, reverse });
|
|
361
|
-
addNode(reverse ? edge.to : edge.from);
|
|
362
|
-
addNode(reverse ? edge.from : edge.to);
|
|
363
|
-
prev = reverse ? edge.from : edge.to;
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
if (prev !== null && prev !== t) {
|
|
367
|
-
// 一段:先找同向的连线,没有再找反向的;同一方向有多条时要写连线 id
|
|
368
|
-
const fwd = d.edges.filter((e) => e.from === prev && e.to === t);
|
|
369
|
-
const back = d.edges.filter((e) => e.from === t && e.to === prev);
|
|
370
|
-
const pick = fwd.length ? fwd : back;
|
|
371
|
-
if (pick.length > 1) {
|
|
372
|
-
err('TRACE_AMBIGUOUS', `${shown}: "${prev}" and "${t}" have ${pick.length} ${d.type === 'Sequence' ? 'messages' : 'edges'} (${pick.map((e) => e.id).join(', ')}), use an id instead, for example trace('${pick[0].id}')`, at);
|
|
373
|
-
return null;
|
|
374
|
-
}
|
|
375
|
-
if (!pick.length) {
|
|
376
|
-
err('TRACE_UNKNOWN', `${shown}: "${prev}" and "${t}" have no connecting ${kind} (each segment needs one in the same diagram; either direction is allowed)`, at);
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
edges.push({ id: pick[0].id, reverse: !fwd.length });
|
|
380
|
-
}
|
|
381
|
-
addNode(t);
|
|
382
|
-
prev = t;
|
|
383
|
-
}
|
|
384
|
-
return finishTrace();
|
|
385
|
-
};
|
|
312
|
+
const effectRoots = [...layerScenes.map(l => l.scene), ...[...sceneFor.values()].filter(x => x.optionId === qid || x.optionId == null)];
|
|
386
313
|
const scenarioIds = {};
|
|
387
314
|
// flow({ from }) 接力:按依赖顺序编译,被接的场景先编译,记下它结尾的路径与导演层;
|
|
388
315
|
// 接力场景的逐步校验(页面里找目标、焦点提示、镜头、自动字幕)都从那里开始,而不是默认起点
|
|
@@ -451,11 +378,14 @@ export function compile(src, mode, opts = {}) {
|
|
|
451
378
|
const explains = [];
|
|
452
379
|
const says = [];
|
|
453
380
|
const narrates = [];
|
|
454
|
-
const
|
|
381
|
+
const ext = {};
|
|
382
|
+
const references = [];
|
|
383
|
+
const pluginFocus = [];
|
|
384
|
+
const directorTargets = [];
|
|
455
385
|
const forks = [];
|
|
456
386
|
const marks = [];
|
|
457
|
-
/**
|
|
458
|
-
const
|
|
387
|
+
/** 每个插件效果贡献的节点(作为镜头目标,与 shot 合并)。 */
|
|
388
|
+
const pluginTargets = new Map();
|
|
459
389
|
for (const e of st.effects) {
|
|
460
390
|
if (e.type === 'go') {
|
|
461
391
|
if (!ctxRoutes.has(e.route))
|
|
@@ -475,7 +405,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
475
405
|
effects.push({ type: 'stream', path: e.path, value: e.value });
|
|
476
406
|
else if (e.type === 'toast')
|
|
477
407
|
effects.push({ type: 'toast', text: e.text, tone: e.tone });
|
|
478
|
-
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold'
|
|
408
|
+
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold')
|
|
479
409
|
continue; // 镜头与焦点提示不是状态变化,下面单独归类
|
|
480
410
|
else if (e.type === 'say') {
|
|
481
411
|
if (typeof e.text === 'string' && e.text.trim())
|
|
@@ -493,42 +423,34 @@ export function compile(src, mode, opts = {}) {
|
|
|
493
423
|
if (e.text.trim())
|
|
494
424
|
explains.push(e.text.trim());
|
|
495
425
|
}
|
|
496
|
-
else if (e.type === '
|
|
497
|
-
const
|
|
498
|
-
if (
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
426
|
+
else if (e.type === 'plugin') {
|
|
427
|
+
const lowered = host.effect(e, effectRoots.filter(scene => scene.layer || scene.id === sceneOf(stepRouteBefore(fl.steps, i + 1, start))), ext[e.plugin], st.source);
|
|
428
|
+
if (lowered) {
|
|
429
|
+
effects.push(...(lowered.writes ?? []).map(w => ({ type: 'set', path: w.path, value: w.value })));
|
|
430
|
+
if (lowered.directorTarget)
|
|
431
|
+
directorTargets.push(lowered.directorTarget);
|
|
432
|
+
if (lowered.media?.length) {
|
|
433
|
+
const key = `${sid}#${i + 1}`;
|
|
434
|
+
host.mediaCommands.set(key, [...(host.mediaCommands.get(key) ?? []), ...lowered.media]);
|
|
435
|
+
}
|
|
436
|
+
if (lowered.data !== undefined)
|
|
437
|
+
ext[e.plugin] = lowered.data;
|
|
438
|
+
if (lowered.targets?.length) {
|
|
439
|
+
pluginTargets.set(e, lowered.targets);
|
|
440
|
+
pluginFocus.push(...lowered.targets);
|
|
441
|
+
}
|
|
442
|
+
references.push(...lowered.references ?? []);
|
|
503
443
|
}
|
|
504
444
|
}
|
|
505
|
-
else
|
|
445
|
+
else if (e.type === 'complete')
|
|
506
446
|
effects.push({ type: 'complete', text: e.text, outcome: e.outcome });
|
|
447
|
+
else
|
|
448
|
+
err('EFFECT_INVALID', 'Unknown step effect; use a documented effect helper instead of constructing effect objects', st.source);
|
|
507
449
|
}
|
|
508
450
|
const sceneBefore = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i, start)));
|
|
509
451
|
const sceneAfter = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i + 1, start)));
|
|
510
452
|
const actionTarget = 'target' in st.action ? st.action.target : null;
|
|
511
|
-
|
|
512
|
-
const cameraTargets = [];
|
|
513
|
-
for (const e of st.effects) {
|
|
514
|
-
if (e.type !== 'camera')
|
|
515
|
-
continue;
|
|
516
|
-
const bad = (k, v, lo, hi) => v !== undefined && (typeof v !== 'number' || !Number.isFinite(v) || v < lo || v > hi) ? `${k} must be a number from ${lo} to ${hi}` : null;
|
|
517
|
-
const problem = bad('pad', e.pad, 0, 2000) ?? bad('zoom', e.zoom, 0.1, 10) ?? bad('ms', e.ms, 0, 10_000);
|
|
518
|
-
if (problem) {
|
|
519
|
-
err('CAMERA_INVALID', `camera(…): ${problem}`, st.source);
|
|
520
|
-
continue;
|
|
521
|
-
}
|
|
522
|
-
const missing = e.targets.filter((id) => (hasLayers ? !layersWith(id).length : !(sceneAfter && findIn(sceneAfter.root, id))));
|
|
523
|
-
if (missing.length) {
|
|
524
|
-
err('CAMERA_UNKNOWN', `camera(${missing.map((m) => JSON.stringify(m)).join(', ')}) target is not in ${hasLayers ? 'any layer' : 'the stage for this step'}; aim it at elements inside a <Canvas>`, st.source);
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
for (const id of e.targets)
|
|
528
|
-
if (!cameraTargets.includes(id))
|
|
529
|
-
cameraTargets.push(id);
|
|
530
|
-
effects.push({ type: 'set', path: 'ui.__camera', value: { targets: [...e.targets], ...(e.pad !== undefined ? { pad: e.pad } : {}), ...(e.zoom !== undefined ? { zoom: e.zoom } : {}), ...(e.ms !== undefined ? { ms: e.ms } : {}) } });
|
|
531
|
-
}
|
|
453
|
+
validateNewAction(st.action, hasLayers ? layerScenes.map(l => l.scene) : sceneBefore ? [sceneBefore] : [], out, (code, message) => err(code, message, st.source));
|
|
532
454
|
for (const e of st.effects) {
|
|
533
455
|
if (e.type === 'fork') {
|
|
534
456
|
if (!Object.hasOwn(def.scenarios, e.scenario) || e.scenario === skey)
|
|
@@ -599,10 +521,10 @@ export function compile(src, mode, opts = {}) {
|
|
|
599
521
|
const perLayer = new Map();
|
|
600
522
|
let directorLayer = null;
|
|
601
523
|
for (const e of st.effects) {
|
|
602
|
-
if (e.type !== 'shot' && !
|
|
524
|
+
if (e.type !== 'shot' && !pluginTargets.has(e))
|
|
603
525
|
continue;
|
|
604
|
-
const
|
|
605
|
-
const targets = e.type === 'shot' ? e.targets :
|
|
526
|
+
const fromPlugin = e.type !== 'shot';
|
|
527
|
+
const targets = e.type === 'shot' ? e.targets : pluginTargets.get(e);
|
|
606
528
|
if (targets.length === 0) {
|
|
607
529
|
// shot():导演所在层回到整体(不推近)
|
|
608
530
|
const lk = hasLayers ? DIRECTOR_LAYER : PAGE_LAYER;
|
|
@@ -612,8 +534,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
612
534
|
for (const id of targets) {
|
|
613
535
|
const where = hasLayers ? layersWith(id) : [sceneAfter, sceneBefore].some((sc) => sc && findIn(sc.root, id)) ? [PAGE_LAYER] : [];
|
|
614
536
|
if (!where.length) {
|
|
615
|
-
if (
|
|
616
|
-
continue; //
|
|
537
|
+
if (fromPlugin)
|
|
538
|
+
continue; // 插件目标已经校验过;不在这一步的画面里时不移动镜头
|
|
617
539
|
err('SHOT_UNKNOWN', hasLayers ? `shot("${id}") references an element absent from all layers (layers: ${Object.keys(layers).join(', ')})` : `shot("${id}") references an element absent from this step's stage (${sceneAfter?.route ?? sceneBefore?.route ?? '?'})`, st.source);
|
|
618
540
|
continue;
|
|
619
541
|
}
|
|
@@ -626,9 +548,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
626
548
|
}
|
|
627
549
|
}
|
|
628
550
|
}
|
|
629
|
-
//
|
|
630
|
-
if (hasLayers && !directorLayer &&
|
|
631
|
-
directorLayer = layersWith(
|
|
551
|
+
// 插件的导演目标只选择层,不自动加入聚焦框或推进视角。
|
|
552
|
+
if (hasLayers && !directorLayer && directorTargets.length)
|
|
553
|
+
directorLayer = layersWith(directorTargets[0])[0] ?? null;
|
|
632
554
|
// 没写 shot、写了焦点提示(D70):导演切到第一个提示目标所在的层(提示要被看见)
|
|
633
555
|
if (hasLayers && !directorLayer && focusTargets.length)
|
|
634
556
|
directorLayer = layersWith(focusTargets[0])[0] ?? null;
|
|
@@ -662,7 +584,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
662
584
|
director = directorLayer;
|
|
663
585
|
for (const s of shots)
|
|
664
586
|
frame.set(s.layer === DIRECTOR_LAYER ? director : s.layer, [...s.targets]);
|
|
665
|
-
const generated = st.caption === undefined ? autoCaption(st, (hasLayers && actionTarget ? layerSceneWith(actionTarget) : undefined) ?? sceneBefore) : null;
|
|
587
|
+
const generated = st.caption === undefined ? autoCaption(st, (hasLayers && actionTarget ? layerSceneWith(actionTarget) : undefined) ?? sceneBefore, out) : null;
|
|
666
588
|
return {
|
|
667
589
|
id: `${sid}#${i + 1}`,
|
|
668
590
|
...(st.key !== undefined ? { key: st.key } : {}),
|
|
@@ -675,7 +597,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
675
597
|
shots,
|
|
676
598
|
directorLayer,
|
|
677
599
|
...(explains.length ? { explain: explains.join('\n') } : {}),
|
|
678
|
-
|
|
600
|
+
...(Object.keys(ext).length ? { ext } : {}),
|
|
601
|
+
...(references.length ? { references: [...new Set(references)] } : {}),
|
|
602
|
+
...(pluginFocus.length ? { focusTargets: [...new Set(pluginFocus)] } : {}),
|
|
679
603
|
forks,
|
|
680
604
|
marks,
|
|
681
605
|
...(cues.length ? { cues } : {}),
|
|
@@ -694,9 +618,11 @@ export function compile(src, mode, opts = {}) {
|
|
|
694
618
|
const outcome = fl.opts.outcome ?? fromDone ?? 'success';
|
|
695
619
|
const state = mergeState(def.state, fl.opts.state);
|
|
696
620
|
const sc = {
|
|
621
|
+
...(fl.opts.actionEntry !== undefined ? { actionEntry: fl.opts.actionEntry } : {}),
|
|
697
622
|
id: sid,
|
|
698
623
|
optionId: qid,
|
|
699
624
|
name: fl.name,
|
|
625
|
+
...(fl.opts.autoplay !== undefined ? { autoplay: fl.opts.autoplay } : {}),
|
|
700
626
|
description: fl.opts.description ?? '',
|
|
701
627
|
caseIds: strip ? [] : (fl.opts.cases ?? []).filter((c) => fdef.cases?.[c]).map((c) => `${fid}.${c}`),
|
|
702
628
|
mock: { label: fl.opts.mock ?? MOCK_LABEL[outcome], outcome, ...(fl.opts.mock === undefined ? { auto: true } : {}) },
|
|
@@ -747,7 +673,40 @@ export function compile(src, mode, opts = {}) {
|
|
|
747
673
|
if (!fdef.cases?.[ck])
|
|
748
674
|
err('UNKNOWN_CASE', `Option ${qid} coverage declares unknown case "${ck}"`, def.source);
|
|
749
675
|
}
|
|
676
|
+
const free = {};
|
|
677
|
+
for (const [key, reaction] of Object.entries(def.free ?? {})) {
|
|
678
|
+
const a = Action.safeParse(reaction.action);
|
|
679
|
+
if (!a.success || !('target' in reaction.action)) {
|
|
680
|
+
err('FREE_ACTION_INVALID', `Free reaction ${key} needs a targeted action`, reaction.source);
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const roots = effectRoots.filter(scene => scene.optionId === qid || mode === 'publish' && scene.optionId === null);
|
|
684
|
+
const target = reaction.action.target;
|
|
685
|
+
if (!roots.some(scene => findIn(scene.root, target)))
|
|
686
|
+
err('FREE_TARGET_MISSING', `Free reaction ${key}: target ${reaction.action.target} is not in option ${qid}`, reaction.source);
|
|
687
|
+
const targets = roots.map(scene => findIn(scene.root, target)).filter((n) => !!n);
|
|
688
|
+
if (reaction.action.type === 'click' && targets.length && !targets.some(n => isInteractiveType(n.type, out.plugins)))
|
|
689
|
+
err('FREE_ACTION_INVALID', `Free reaction ${key}: ${target} is not interactive`, reaction.source);
|
|
690
|
+
if (['type', 'toggle', 'select'].includes(reaction.action.type) && targets.length && !targets.some(n => n.traits?.input))
|
|
691
|
+
err('FREE_ACTION_INVALID', `Free reaction ${key}: ${target} cannot accept values`, reaction.source);
|
|
692
|
+
validateNewAction(reaction.action, roots, out, (code, message) => err(code, message, reaction.source));
|
|
693
|
+
const effects = [];
|
|
694
|
+
for (const effect of reaction.effects) {
|
|
695
|
+
if (!['set', 'append', 'toast'].includes(effect.type)) {
|
|
696
|
+
err('FREE_EFFECT_INVALID', `Free reaction ${key}: ${effect.type} is not local state. Use set, append or toast; navigation, completion and timeline animation belong in steps`, reaction.source);
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const { kind: _kind, ...raw } = effect;
|
|
700
|
+
const parsed = Effect.safeParse(raw);
|
|
701
|
+
if (!parsed.success || 'path' in raw && (!/^(ui|data|inputs)\.[A-Za-z0-9_.-]+$/.test(String(raw.path)) || String(raw.path).split('.').some(k => ['__proto__', 'constructor', 'prototype'].includes(k))))
|
|
702
|
+
err('FREE_EFFECT_INVALID', `Free reaction ${key}: invalid local effect`, reaction.source);
|
|
703
|
+
else
|
|
704
|
+
effects.push(parsed.data);
|
|
705
|
+
}
|
|
706
|
+
free[key] = { action: a.data, effects, ...(reaction.source ? { source: rel(reaction.source) } : {}) };
|
|
707
|
+
}
|
|
750
708
|
out.options[qid] = {
|
|
709
|
+
...(Object.keys(free).length ? { free } : {}),
|
|
751
710
|
id: qid,
|
|
752
711
|
featureId: fid,
|
|
753
712
|
key: o.key,
|
|
@@ -771,32 +730,6 @@ export function compile(src, mode, opts = {}) {
|
|
|
771
730
|
err('UNKNOWN_CASE', `Rule "${r.text}" links unknown case ${c}`, r.source);
|
|
772
731
|
}
|
|
773
732
|
}
|
|
774
|
-
// ---------- 7. 图表布局(D69):每张图在编译期布局一次,写进 IR;同一结构只算一次(引擎自带缓存) ----------
|
|
775
|
-
if (!diags.some((d) => d.severity === 'error')) {
|
|
776
|
-
const failed = new Set();
|
|
777
|
-
for (const sc of Object.values(out.scenes))
|
|
778
|
-
attachLayouts(sc.root, opts.layout, (n, m) => {
|
|
779
|
-
if (failed.has(`${n.source}|${n.id}`))
|
|
780
|
-
return;
|
|
781
|
-
failed.add(`${n.source}|${n.id}`);
|
|
782
|
-
warn('DIAGRAM_LAYOUT_FAILED', `<${n.type}> "${n.id}" could not be laid out (${m}); showing a simple grid instead. Check the edges and groups of this diagram`, n.source, { kind: 'element', id: n.id });
|
|
783
|
-
}, sc.viewport);
|
|
784
|
-
}
|
|
785
|
-
// ---------- 8. 发布视图与评审版:去掉设计备注与源位置 ----------
|
|
786
|
-
if (strip) {
|
|
787
|
-
for (const s of Object.values(out.scenes))
|
|
788
|
-
stripNotes(s.root);
|
|
789
|
-
stripSources(out);
|
|
790
|
-
}
|
|
791
|
-
if (diags.some((d) => d.severity === 'error'))
|
|
792
|
-
return { project: null, diagnostics: diags };
|
|
793
|
-
const parsed = Project.safeParse(out);
|
|
794
|
-
if (!parsed.success) {
|
|
795
|
-
// 同一根因(共享的 JSX)在多个画面展开时合并成一条,定位到作者元素(schema-issues.ts)
|
|
796
|
-
diags.push(...schemaDiagnostics(out, parsed.error.issues, { limit: 20, rel }));
|
|
797
|
-
return { project: null, diagnostics: diags };
|
|
798
|
-
}
|
|
799
|
-
const project = pruneMessages(parsed.data);
|
|
800
733
|
// flow({ from }) 接力:初始状态 = 被接的场景最后一步之后的状态(路径、ui / data / inputs、导演层),再叠上本场景写的 state。
|
|
801
734
|
// 链式接力按依赖顺序解析;成环或被接的场景回放失败时报错。
|
|
802
735
|
if (pendingFrom.size) {
|
|
@@ -815,16 +748,17 @@ export function compile(src, mode, opts = {}) {
|
|
|
815
748
|
visiting.delete(sid);
|
|
816
749
|
if (!ok)
|
|
817
750
|
return false;
|
|
818
|
-
const target =
|
|
819
|
-
const prev =
|
|
751
|
+
const target = out.scenarios[sid];
|
|
752
|
+
const prev = out.scenarios[p.from];
|
|
820
753
|
if (!target || !prev)
|
|
821
754
|
return false;
|
|
822
755
|
try {
|
|
823
|
-
const end = stateAt(
|
|
824
|
-
const hasLayers = Object.keys(
|
|
825
|
-
const layer = p.layer ?? (hasLayers ? cameraAt(
|
|
756
|
+
const end = stateAt(out, p.from, prev.steps.length);
|
|
757
|
+
const hasLayers = Object.keys(out.options[target.optionId]?.layers ?? {}).length > 0;
|
|
758
|
+
const layer = p.layer ?? (hasLayers ? cameraAt(out, p.from, prev.steps.length).directorLayer : undefined);
|
|
826
759
|
const merged = mergeState({ ui: end.ui, data: end.data, inputs: end.inputs }, p.state);
|
|
827
760
|
target.initial = { sceneId: end.sceneId, ui: merged.ui, data: merged.data, inputs: merged.inputs, ...(layer ? { layer } : {}) };
|
|
761
|
+
target.from = p.from;
|
|
828
762
|
}
|
|
829
763
|
catch (e) {
|
|
830
764
|
err('FROM_FAILED', `Scenario ${sid} continues from ${p.from}, which does not replay: ${e.message}`, p.at);
|
|
@@ -838,10 +772,41 @@ export function compile(src, mode, opts = {}) {
|
|
|
838
772
|
if (diags.some((d) => d.severity === 'error'))
|
|
839
773
|
return { project: null, diagnostics: diags };
|
|
840
774
|
}
|
|
775
|
+
// 逐步派生数据只在编译期计算,播放器读取快照。
|
|
776
|
+
if (!diags.some(d => d.severity === 'error'))
|
|
777
|
+
host.frames(out);
|
|
778
|
+
if (diags.some(d => d.severity === 'error'))
|
|
779
|
+
return { project: null, diagnostics: diags };
|
|
780
|
+
// ---------- 8. 发布视图与评审版:去掉设计备注与源位置 ----------
|
|
781
|
+
if (strip) {
|
|
782
|
+
for (const s of Object.values(out.scenes))
|
|
783
|
+
stripNotes(s.root);
|
|
784
|
+
stripSources(out);
|
|
785
|
+
}
|
|
786
|
+
if (diags.some((d) => d.severity === 'error'))
|
|
787
|
+
return { project: null, diagnostics: diags };
|
|
788
|
+
const parsed = Project.safeParse(out);
|
|
789
|
+
if (!parsed.success) {
|
|
790
|
+
// 同一根因(共享的 JSX)在多个画面展开时合并成一条,定位到作者元素(schema-issues.ts)
|
|
791
|
+
diags.push(...schemaDiagnostics(out, parsed.error.issues, { limit: 20, rel }));
|
|
792
|
+
return { project: null, diagnostics: diags };
|
|
793
|
+
}
|
|
794
|
+
let project = pruneMessages(parsed.data);
|
|
841
795
|
if (mode === 'dev' && project.i18n) {
|
|
842
796
|
const stale = localeDiagnostics(project, src, diags);
|
|
843
797
|
project.i18n = { ...project.i18n, stale };
|
|
844
798
|
}
|
|
799
|
+
// A slot can fit on its own but exceed the public reader's limit once wrapped in
|
|
800
|
+
// scenes/scenarios/steps/ext. Validate that final depth before reporting success.
|
|
801
|
+
if (mode === 'publish') {
|
|
802
|
+
try {
|
|
803
|
+
project = materialize(project);
|
|
804
|
+
}
|
|
805
|
+
catch (e) {
|
|
806
|
+
err('PLUGIN_DATA_INVALID', `Published IR is not readable JSON data: ${errorMessage(e)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
807
|
+
return { project: null, diagnostics: diags };
|
|
808
|
+
}
|
|
809
|
+
}
|
|
845
810
|
return { project, diagnostics: diags };
|
|
846
811
|
}
|
|
847
812
|
/** config.locales(D84):非空、不重复、都是支持的语言;第一个是默认语言。没写时为 null。 */
|
|
@@ -972,36 +937,34 @@ function expandSlots(n, fill, outlet) {
|
|
|
972
937
|
function tagFrom(n, from) {
|
|
973
938
|
return { ...n, props: { ...n.props, __from: from } };
|
|
974
939
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
940
|
+
function toSceneNode(n, fallbackId, ids, nc, parentType) {
|
|
941
|
+
const { report: err, rel } = nc;
|
|
942
|
+
n = { ...n, props: n.props ?? {}, children: n.children ?? [] };
|
|
943
|
+
n = { ...n, type: nc.host.intrinsic.get(n.type) ?? n.type };
|
|
944
|
+
n = inheritProps(n, nc.host.inherits.get(n.type) ?? []);
|
|
945
|
+
const children = flatten(n.children).map((c, i) => isNode(c) ? toSceneNode(c, `${fallbackId}_${i}`, ids, nc, n.type) : textNode(c, `${fallbackId}_${i}`));
|
|
946
|
+
n = nc.host.node(n, ids);
|
|
980
947
|
const { id: rawId, when, disabled, disabledReason, unmodeled, note, redact, __from, ...rest } = n.props;
|
|
981
948
|
const at = n.source;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
949
|
+
const plug = splitPluginType(n.type);
|
|
950
|
+
if (plug) {
|
|
951
|
+
const spec = pluginSpec(nc.plugins, n.type);
|
|
952
|
+
if (!nc.plugins[plug.plugin])
|
|
953
|
+
err('UNKNOWN_PLUGIN', `<${n.type}> comes from plugin ${plug.plugin}, which is not enabled: ${n.packageName ? `install ${n.packageName}; import plugin from ${JSON.stringify(n.packageName)}; ` : `install its author package; `}add plugin to config({ plugins: [plugin] }) in joplo.config.ts (npx joplo skill plugins)`, at);
|
|
954
|
+
else if (!spec)
|
|
955
|
+
err('UNKNOWN_COMPONENT', `Plugin ${plug.plugin} has no component ${plug.name} (available: ${Object.keys(nc.plugins[plug.plugin].components).join(', ')}; npx joplo skill ${plug.plugin})`, at);
|
|
956
|
+
else if (spec.parent && parentType !== `${plug.plugin}:${spec.parent}`)
|
|
957
|
+
err('PLUGIN_PARENT', `<${n.type}> must be written directly inside <${plug.plugin}:${spec.parent}> (npx joplo skill ${plug.plugin})`, at);
|
|
958
|
+
}
|
|
959
|
+
else if (!KNOWN.has(n.type))
|
|
960
|
+
err('UNKNOWN_COMPONENT', `No enabled plugin declares <${n.type}>. Install a plugin that provides this element and list it in config.plugins; run joplo skill to discover the installed plugin guides`, at);
|
|
961
|
+
const interactive = isInteractiveType(n.type, nc.plugins);
|
|
985
962
|
if (interactive && typeof rawId !== 'string')
|
|
986
963
|
err('MISSING_ID', `Interactive component <${n.type}> "${labelOf(n)}" requires an id for steps and selection`, at);
|
|
987
|
-
const
|
|
988
|
-
if (needsId && typeof rawId !== 'string')
|
|
989
|
-
err('MISSING_ID',
|
|
990
|
-
|
|
991
|
-
checkDiagramRoot(n, err);
|
|
992
|
-
if (n.type === 'Image')
|
|
993
|
-
checkImage(n, err);
|
|
994
|
-
// 连线没写 id 时用「from->to」:⌥+单击检查与 rules 的 elements 都能引用它。
|
|
995
|
-
// 状态机的转换与时序图的消息常有同一对端点的多条(请求、重试、回复),重复的依次加「~2」「~3」。
|
|
996
|
-
const linkLike = n.type === 'Diagram.Edge' || n.type === 'StateMachine.Transition' || n.type === 'Sequence.Message';
|
|
997
|
-
let edgeId = linkLike && typeof rest.from === 'string' && typeof rest.to === 'string' ? `${rest.from}->${rest.to}` : null;
|
|
998
|
-
if (edgeId && n.type !== 'Diagram.Edge' && ids.has(edgeId)) {
|
|
999
|
-
let k = 2;
|
|
1000
|
-
while (ids.has(`${edgeId}~${k}`))
|
|
1001
|
-
k++;
|
|
1002
|
-
edgeId = `${edgeId}~${k}`;
|
|
1003
|
-
}
|
|
1004
|
-
const id = typeof rawId === 'string' ? rawId : (edgeId ?? `_${fallbackId}`);
|
|
964
|
+
const spec = pluginSpec(nc.plugins, n.type);
|
|
965
|
+
if (spec?.needsId && typeof rawId !== 'string' && !interactive)
|
|
966
|
+
err('MISSING_ID', `<${n.type}> "${labelOf(n)}" requires an id`, at);
|
|
967
|
+
const id = typeof rawId === 'string' ? rawId : `_${fallbackId}`;
|
|
1005
968
|
if (ids.has(id))
|
|
1006
969
|
err('DUPLICATE_ID', `Duplicate id "${id}" in the same stage (other location: ${rel(ids.get(id)) ?? 'unknown'})`, at);
|
|
1007
970
|
ids.set(id, at);
|
|
@@ -1020,6 +983,11 @@ function toSceneNode(n, fallbackId, ids, err, rel) {
|
|
|
1020
983
|
props[k] = toPropValue(v);
|
|
1021
984
|
}
|
|
1022
985
|
const node = { id, type: n.type };
|
|
986
|
+
if (spec?.traits) {
|
|
987
|
+
const { text: _text, textPaths: _paths, ...runtime } = spec.traits;
|
|
988
|
+
if (Object.keys(runtime).length)
|
|
989
|
+
node.traits = runtime;
|
|
990
|
+
}
|
|
1023
991
|
if (Object.keys(props).length)
|
|
1024
992
|
node.props = props;
|
|
1025
993
|
if (children.length)
|
|
@@ -1053,202 +1021,26 @@ function toSceneNode(n, fallbackId, ids, err, rel) {
|
|
|
1053
1021
|
node.source = s;
|
|
1054
1022
|
return node;
|
|
1055
1023
|
}
|
|
1056
|
-
/**
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
*/
|
|
1073
|
-
function menuWithOpened(menu) {
|
|
1074
|
-
const opened = menu.props.opened;
|
|
1075
|
-
if (opened === undefined)
|
|
1076
|
-
return menu;
|
|
1077
|
-
const visit = (c) => {
|
|
1078
|
-
if (Array.isArray(c))
|
|
1079
|
-
return c.map(visit);
|
|
1080
|
-
if (!isNode(c) || c.type === 'Menu')
|
|
1081
|
-
return c;
|
|
1082
|
-
if (c.type === 'Menu.Dropdown')
|
|
1083
|
-
return c.props.opened === undefined ? { ...c, props: { ...c.props, opened } } : c;
|
|
1084
|
-
return { ...c, children: c.children.map(visit) };
|
|
1085
|
-
};
|
|
1086
|
-
return { ...menu, children: menu.children.map(visit) };
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* 关系类图表的校验(D69):在作者元素上报错,带源位置。
|
|
1090
|
-
* - Diagram / StateMachine:连线两端必须是同一张图里的节点或(有 id 的)分组;group="…" 必须引用存在的分组、与嵌套不矛盾、不成环;
|
|
1091
|
-
* 连线不能连到包含它端点的分组;icon / tone / pin 取预设值。节点多却没有分组时给一条 info(D69:按业务域分组)。
|
|
1092
|
-
* - Sequence:消息两端必须是参与者;Sequence.Group 里只放参与者,Sequence.Block 里只放消息或片段。
|
|
1093
|
-
* 嵌套的另一张图表自成一体,不参与本图的校验。
|
|
1094
|
-
*/
|
|
1095
|
-
function checkDiagramRoot(d, err) {
|
|
1096
|
-
const type = d.type;
|
|
1097
|
-
const strOf = (v) => (typeof v === 'string' ? v : String(v));
|
|
1098
|
-
const oneOf = (el, prop, allowed, severity = 'error') => {
|
|
1099
|
-
const v = el.props[prop];
|
|
1100
|
-
if (v !== undefined && (typeof v !== 'string' || !allowed.includes(v)))
|
|
1101
|
-
err(prop === 'icon' ? 'ICON_UNKNOWN' : 'INVALID_DIAGRAM_PROP', `<${el.type}> ${prop}="${strOf(v)}" is not supported (available: ${allowed.join(', ')})${severity === 'warning' ? '; it is drawn as the default' : ''}`, el.source, severity);
|
|
1102
|
-
};
|
|
1103
|
-
if (type === 'Sequence') {
|
|
1104
|
-
const actors = new Set();
|
|
1105
|
-
const messages = [];
|
|
1106
|
-
const walk = (cs, inside) => {
|
|
1107
|
-
for (const c of flatten(cs)) {
|
|
1108
|
-
if (!isNode(c) || isDiagramRoot(c.type))
|
|
1109
|
-
continue;
|
|
1110
|
-
if (c.type === SEQUENCE_FAMILY.actor) {
|
|
1111
|
-
if (inside === 'block')
|
|
1112
|
-
err('INVALID_DIAGRAM_CHILD', `<Sequence.Actor> "${labelOf(c)}" cannot be inside <Sequence.Block>; declare participants at the top (optionally in <Sequence.Group>) and put messages in blocks`, c.source);
|
|
1113
|
-
if (typeof c.props.id === 'string')
|
|
1114
|
-
actors.add(c.props.id);
|
|
1115
|
-
}
|
|
1116
|
-
else if (c.type === SEQUENCE_FAMILY.message) {
|
|
1117
|
-
if (inside === 'group')
|
|
1118
|
-
err('INVALID_DIAGRAM_CHILD', '<Sequence.Message> cannot be inside <Sequence.Group> (a group boxes participants); put it after the participants, or in a <Sequence.Block>', c.source);
|
|
1119
|
-
messages.push(c);
|
|
1120
|
-
}
|
|
1121
|
-
else if (c.type === SEQUENCE_FAMILY.group) {
|
|
1122
|
-
if (inside !== 'root')
|
|
1123
|
-
err('INVALID_DIAGRAM_CHILD', '<Sequence.Group> must be a direct child of <Sequence>', c.source);
|
|
1124
|
-
oneOf(c, 'icon', DIAGRAM_GROUP_ICONS);
|
|
1125
|
-
walk(c.children, 'group');
|
|
1126
|
-
}
|
|
1127
|
-
else if (c.type === SEQUENCE_FAMILY.block) {
|
|
1128
|
-
if (inside === 'group')
|
|
1129
|
-
err('INVALID_DIAGRAM_CHILD', '<Sequence.Block> cannot be inside <Sequence.Group>', c.source);
|
|
1130
|
-
oneOf(c, 'kind', SEQUENCE_BLOCK_KINDS);
|
|
1131
|
-
walk(c.children, 'block');
|
|
1132
|
-
}
|
|
1133
|
-
else if (c.type.startsWith('Diagram.') || c.type.startsWith('StateMachine.')) {
|
|
1134
|
-
err('INVALID_DIAGRAM_CHILD', `<${c.type}> cannot be used inside <Sequence>; use Sequence.Actor / Sequence.Message / Sequence.Group / Sequence.Block`, c.source);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
1138
|
-
walk(d.children, 'root');
|
|
1139
|
-
const known = [...actors].join(', ') || '(no participants)';
|
|
1140
|
-
for (const m of messages)
|
|
1141
|
-
for (const k of ['from', 'to']) {
|
|
1142
|
-
const v = m.props[k];
|
|
1143
|
-
if (typeof v !== 'string' || !actors.has(v))
|
|
1144
|
-
err('UNKNOWN_DIAGRAM_NODE', `<Sequence.Message> ${k} "${strOf(v)}" is not a participant id in this Sequence (available: ${known})`, m.source);
|
|
1145
|
-
}
|
|
1146
|
-
return;
|
|
1147
|
-
}
|
|
1148
|
-
const fam = GRAPH_FAMILY[type];
|
|
1149
|
-
const nodes = new Set();
|
|
1150
|
-
const groups = new Map();
|
|
1151
|
-
/** 元素 → 它的父分组(嵌套或 group= 引用);记录嵌套父分组,用来查冲突。 */
|
|
1152
|
-
const parentOf = new Map();
|
|
1153
|
-
const edges = [];
|
|
1154
|
-
const refs = [];
|
|
1155
|
-
let nodeCount = 0;
|
|
1156
|
-
const walk = (cs, nested) => {
|
|
1157
|
-
for (const c of flatten(cs)) {
|
|
1158
|
-
if (!isNode(c) || isDiagramRoot(c.type))
|
|
1159
|
-
continue;
|
|
1160
|
-
const id = typeof c.props.id === 'string' ? c.props.id : null;
|
|
1161
|
-
const ref = typeof c.props.group === 'string' ? c.props.group : null;
|
|
1162
|
-
if (c.props.group !== undefined && ref === null)
|
|
1163
|
-
err('UNKNOWN_DIAGRAM_GROUP', `<${c.type}> group must be a group id string`, c.source);
|
|
1164
|
-
if (c.type === fam.node) {
|
|
1165
|
-
nodeCount++;
|
|
1166
|
-
if (id) {
|
|
1167
|
-
nodes.add(id);
|
|
1168
|
-
parentOf.set(id, ref ?? nested);
|
|
1169
|
-
}
|
|
1170
|
-
if (ref)
|
|
1171
|
-
refs.push({ el: c, ref, nested });
|
|
1172
|
-
oneOf(c, 'pin', DIAGRAM_PINS);
|
|
1173
|
-
// kind 以前没有校验(未知值画成 service):保持兼容,只给 warning
|
|
1174
|
-
if (type === 'Diagram')
|
|
1175
|
-
oneOf(c, 'kind', DIAGRAM_NODE_KINDS, 'warning');
|
|
1176
|
-
}
|
|
1177
|
-
else if (c.type === fam.group) {
|
|
1178
|
-
if (id) {
|
|
1179
|
-
groups.set(id, c);
|
|
1180
|
-
parentOf.set(id, ref ?? nested);
|
|
1181
|
-
}
|
|
1182
|
-
if (ref)
|
|
1183
|
-
refs.push({ el: c, ref, nested });
|
|
1184
|
-
oneOf(c, 'icon', DIAGRAM_GROUP_ICONS);
|
|
1185
|
-
oneOf(c, 'tone', DIAGRAM_TONES);
|
|
1186
|
-
oneOf(c, 'pin', DIAGRAM_PINS);
|
|
1187
|
-
walk(c.children, id ?? nested);
|
|
1188
|
-
}
|
|
1189
|
-
else if (c.type === fam.edge) {
|
|
1190
|
-
edges.push(c);
|
|
1191
|
-
}
|
|
1192
|
-
else if (c.type.startsWith('Diagram.') || c.type.startsWith('StateMachine.') || c.type.startsWith('Sequence.')) {
|
|
1193
|
-
err('INVALID_DIAGRAM_CHILD', `<${c.type}> cannot be used inside <${type}>; use ${fam.node} / ${fam.edge} / ${fam.group}`, c.source);
|
|
1194
|
-
}
|
|
1024
|
+
/** Forward declared properties before descending; nested owners establish their own scope. */
|
|
1025
|
+
function inheritProps(owner, declarations) {
|
|
1026
|
+
if (!declarations.length)
|
|
1027
|
+
return owner;
|
|
1028
|
+
const visit = (child) => {
|
|
1029
|
+
if (Array.isArray(child))
|
|
1030
|
+
return child.map(visit);
|
|
1031
|
+
if (!isNode(child) || child.type === owner.type)
|
|
1032
|
+
return child;
|
|
1033
|
+
const spec = declarations.find(d => d.target === child.type);
|
|
1034
|
+
if (spec) {
|
|
1035
|
+
const props = { ...child.props };
|
|
1036
|
+
for (const key of spec.props)
|
|
1037
|
+
if (props[key] === undefined && owner.props[key] !== undefined)
|
|
1038
|
+
props[key] = owner.props[key];
|
|
1039
|
+
return { ...child, props };
|
|
1195
1040
|
}
|
|
1041
|
+
return { ...child, children: child.children.map(visit) };
|
|
1196
1042
|
};
|
|
1197
|
-
|
|
1198
|
-
const groupList = [...groups.keys()].join(', ') || '(no groups with an id)';
|
|
1199
|
-
for (const { el, ref, nested } of refs) {
|
|
1200
|
-
if (!groups.has(ref))
|
|
1201
|
-
err('UNKNOWN_DIAGRAM_GROUP', `<${el.type}> group="${ref}" is not a ${fam.group} id in this ${type} (available: ${groupList})`, el.source);
|
|
1202
|
-
else if (nested && nested !== ref)
|
|
1203
|
-
err('DIAGRAM_GROUP_CONFLICT', `<${el.type}> is nested in group "${nested}" but declares group="${ref}"; use one of the two`, el.source);
|
|
1204
|
-
}
|
|
1205
|
-
// 分组成环(只可能来自 group= 引用)
|
|
1206
|
-
const reported = new Set();
|
|
1207
|
-
for (const gid of groups.keys()) {
|
|
1208
|
-
const seen = [gid];
|
|
1209
|
-
for (let q = parentOf.get(gid) ?? null; q && groups.has(q); q = parentOf.get(q) ?? null) {
|
|
1210
|
-
if (seen.includes(q)) {
|
|
1211
|
-
const cycle = seen.slice(seen.indexOf(q));
|
|
1212
|
-
const key = [...cycle].sort().join(',');
|
|
1213
|
-
if (!reported.has(key)) {
|
|
1214
|
-
reported.add(key);
|
|
1215
|
-
err('DIAGRAM_GROUP_CYCLE', `Groups ${[...cycle, q].map((x) => `"${x}"`).join(' → ')} contain each other; remove one group= reference`, groups.get(gid).source);
|
|
1216
|
-
}
|
|
1217
|
-
break;
|
|
1218
|
-
}
|
|
1219
|
-
seen.push(q);
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
const ancestors = (id) => {
|
|
1223
|
-
const out = [];
|
|
1224
|
-
for (let q = parentOf.get(id) ?? null; q && !out.includes(q); q = parentOf.get(q) ?? null)
|
|
1225
|
-
out.push(q);
|
|
1226
|
-
return out;
|
|
1227
|
-
};
|
|
1228
|
-
const known = [...nodes, ...groups.keys()].join(', ') || '(no nodes)';
|
|
1229
|
-
for (const e of edges) {
|
|
1230
|
-
let ok = true;
|
|
1231
|
-
for (const k of ['from', 'to']) {
|
|
1232
|
-
const v = e.props[k];
|
|
1233
|
-
if (typeof v !== 'string' || (!nodes.has(v) && !groups.has(v))) {
|
|
1234
|
-
ok = false;
|
|
1235
|
-
err('UNKNOWN_DIAGRAM_NODE', `<${fam.edge}> ${k} "${strOf(v)}" is not a ${type === 'StateMachine' ? 'state' : 'node'} or group id in this ${type} (available: ${known})`, e.source);
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
if (!ok)
|
|
1239
|
-
continue;
|
|
1240
|
-
const from = e.props.from;
|
|
1241
|
-
const to = e.props.to;
|
|
1242
|
-
if (ancestors(from).includes(to) || ancestors(to).includes(from))
|
|
1243
|
-
err('DIAGRAM_EDGE_INTO_OWN_GROUP', `<${fam.edge}> ${from} → ${to} connects an element to a group that contains it; connect to another element inside the group, or to a group outside`, e.source);
|
|
1244
|
-
}
|
|
1245
|
-
// 按业务域分组的提示:节点多,却没有分组(或只有一个把所有节点都包起来的分组)
|
|
1246
|
-
if (type === 'Diagram' && nodeCount >= 6) {
|
|
1247
|
-
const top = [...groups.values()].filter((g) => !parentOf.get(String(g.props.id)));
|
|
1248
|
-
const allInOne = groups.size === 1 && top.length === 1 && [...nodes].every((n) => parentOf.get(n) === String(top[0].props.id));
|
|
1249
|
-
if (groups.size === 0 || allInOne)
|
|
1250
|
-
err('DIAGRAM_UNGROUPED', `<Diagram> has ${nodeCount} nodes but ${groups.size === 0 ? 'no groups' : 'a single group around all of them'}; group nodes by business domain (gateway, runtime, storage…) with <Diagram.Group label icon> so viewers can tell what belongs where. See npx joplo skill diagram`, d.source, 'info');
|
|
1251
|
-
}
|
|
1043
|
+
return { ...owner, children: owner.children.map(visit) };
|
|
1252
1044
|
}
|
|
1253
1045
|
/** 展开数组与 Fragment(含插槽展开后的 Fragment),丢弃 null/布尔。 */
|
|
1254
1046
|
function flatten(cs) {
|
|
@@ -1319,12 +1111,16 @@ function findIn(node, id) {
|
|
|
1319
1111
|
}
|
|
1320
1112
|
const NO_STATE = { ui: {}, data: {}, inputs: {} };
|
|
1321
1113
|
/** 自动字幕:元素名取 Mantine 的 label 属性(其次 title / aria-label / placeholder / 文字);select 显示选项的 label。 */
|
|
1322
|
-
function autoCaption(st, scene) {
|
|
1114
|
+
function autoCaption(st, scene, project) {
|
|
1323
1115
|
const a = st.action;
|
|
1324
1116
|
const node = 'target' in a && scene ? findIn(scene.root, a.target) : null;
|
|
1325
1117
|
const label = node ? nodeLabel(node) : 'target' in a ? a.target : '';
|
|
1326
1118
|
const result = (kind, caption, extra = {}) => ({ caption, captionAuto: { kind, label, ...extra } });
|
|
1327
1119
|
switch (a.type) {
|
|
1120
|
+
case 'drag': return result('drag', `Drag “${label}” to ${typeof a.to === 'string' ? a.to : `${a.to.x}, ${a.to.y}`}`, { value: typeof a.to === 'string' ? (scene && findIn(scene.root, a.to) ? nodeLabel(findIn(scene.root, a.to)) : a.to) : `${a.to.x}, ${a.to.y}` });
|
|
1121
|
+
case 'hover': return result('hover', `Hover over “${label}”`);
|
|
1122
|
+
case 'scroll': return result('scroll', `Scroll “${label}” to ${typeof a.to === 'string' ? a.to : `${a.to.x}, ${a.to.y}`}`, { value: typeof a.to === 'string' ? (scene && findIn(scene.root, a.to) ? nodeLabel(findIn(scene.root, a.to)) : a.to) : `${a.to.x}, ${a.to.y}` });
|
|
1123
|
+
case 'plugin': return { caption: (pluginActionSpec(project, a.name)?.caption ?? a.name).replaceAll('{label}', label).replace(/\{data\.([A-Za-z0-9_-]+)\}/g, (_, k) => String(a.data[k] ?? '')) };
|
|
1328
1124
|
case 'click': return result('click', `Click “${label}”`);
|
|
1329
1125
|
case 'type': return result('type', `Type “${a.value}” in “${label}”`, { value: a.value });
|
|
1330
1126
|
case 'select': {
|
|
@@ -1333,7 +1129,7 @@ function autoCaption(st, scene) {
|
|
|
1333
1129
|
return result('select', `Select “${value}” in “${label}”`, { value });
|
|
1334
1130
|
}
|
|
1335
1131
|
case 'toggle': {
|
|
1336
|
-
const kind = node?.
|
|
1132
|
+
const kind = node?.traits?.toggleCaption === 'check' ? (a.value ? 'check' : 'uncheck') : (a.value ? 'switch_on' : 'switch_off');
|
|
1337
1133
|
const verb = { check: 'Check', uncheck: 'Uncheck', switch_on: 'Turn on', switch_off: 'Turn off' }[kind];
|
|
1338
1134
|
return result(kind, `${verb} “${label}”`);
|
|
1339
1135
|
}
|
|
@@ -1343,12 +1139,48 @@ function autoCaption(st, scene) {
|
|
|
1343
1139
|
case 'card': return { caption: a.title };
|
|
1344
1140
|
}
|
|
1345
1141
|
}
|
|
1142
|
+
/** Validate extension actions while all scene anchors and enabled declarations are available. */
|
|
1143
|
+
function validateNewAction(action, scenes, project, report) {
|
|
1144
|
+
if (!['drag', 'hover', 'scroll', 'plugin'].includes(action.type))
|
|
1145
|
+
return;
|
|
1146
|
+
const parsed = Action.safeParse(action);
|
|
1147
|
+
if (!parsed.success) {
|
|
1148
|
+
report('ACTION_INVALID', `Invalid ${action.type} action: ${parsed.error.message}`);
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
if (!('target' in action))
|
|
1152
|
+
return;
|
|
1153
|
+
const nodes = scenes.map(s => findIn(s.root, action.target)).filter((n) => !!n);
|
|
1154
|
+
if (!nodes.length)
|
|
1155
|
+
report('MISSING_TARGET', `Action target ${action.target} is not in the current stage`);
|
|
1156
|
+
if (action.type === 'drag' || action.type === 'scroll') {
|
|
1157
|
+
if (typeof action.to === 'string' && !scenes.some(s => findIn(s.root, action.target) && findIn(s.root, action.to)))
|
|
1158
|
+
report('ACTION_DESTINATION_MISSING', `${action.type} destination ${action.to} must be in the same stage as ${action.target}`);
|
|
1159
|
+
else if (action.type === 'scroll' && typeof action.to === 'string' && !nodes.some(n => findIn(n, action.to)))
|
|
1160
|
+
report('ACTION_DESTINATION_INVALID', `Scroll destination ${action.to} must be inside ${action.target}`);
|
|
1161
|
+
}
|
|
1162
|
+
if (action.type === 'plugin') {
|
|
1163
|
+
const spec = pluginActionSpec(project, action.name);
|
|
1164
|
+
if (!spec)
|
|
1165
|
+
report('ACTION_UNKNOWN', `Plugin action ${action.name} is not declared by an enabled plugin`);
|
|
1166
|
+
else {
|
|
1167
|
+
if (!validActionData(spec, action.data))
|
|
1168
|
+
report('ACTION_DATA_INVALID', `Plugin action ${action.name} payload does not match its declared fields`);
|
|
1169
|
+
if (spec.targets && nodes.some(n => !spec.targets.includes(n.type)))
|
|
1170
|
+
report('ACTION_TARGET_INVALID', `Plugin action ${action.name} does not accept this target type`);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1346
1174
|
function stripSources(o) {
|
|
1347
1175
|
if (Array.isArray(o))
|
|
1348
1176
|
return o.forEach(stripSources);
|
|
1349
1177
|
if (o && typeof o === 'object') {
|
|
1350
1178
|
delete o.source;
|
|
1351
|
-
|
|
1179
|
+
// Plugin slots are already validated public data. Stripping their own fields would
|
|
1180
|
+
// invalidate the plugin schema after validation (e.g. a public provenance `source`).
|
|
1181
|
+
for (const [key, value] of Object.entries(o))
|
|
1182
|
+
if (key !== 'ext')
|
|
1183
|
+
stripSources(value);
|
|
1352
1184
|
}
|
|
1353
1185
|
}
|
|
1354
1186
|
function stripNotes(n) {
|