@joplo-app/core 0.2.18 → 0.4.1
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 -47
- package/dist/catalog.js +27 -334
- package/dist/compile.d.ts +2 -8
- package/dist/compile.js +230 -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 +6 -2
- package/dist/focus.js +28 -36
- package/dist/guide.d.ts +10 -12
- package/dist/guide.js +372 -594
- 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 +67 -0
- package/dist/plugins/compiler.js +434 -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 +593 -112
- package/dist/schema.js +62 -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,16 @@ export function compile(src, mode, opts = {}) {
|
|
|
451
378
|
const explains = [];
|
|
452
379
|
const says = [];
|
|
453
380
|
const narrates = [];
|
|
454
|
-
|
|
381
|
+
/** 插件效果声明的最短停留(D98):同一步取最大值。 */
|
|
382
|
+
let effectHoldMs = 0;
|
|
383
|
+
const ext = {};
|
|
384
|
+
const references = [];
|
|
385
|
+
const pluginFocus = [];
|
|
386
|
+
const directorTargets = [];
|
|
455
387
|
const forks = [];
|
|
456
388
|
const marks = [];
|
|
457
|
-
/**
|
|
458
|
-
const
|
|
389
|
+
/** 每个插件效果贡献的节点(作为镜头目标,与 shot 合并)。 */
|
|
390
|
+
const pluginTargets = new Map();
|
|
459
391
|
for (const e of st.effects) {
|
|
460
392
|
if (e.type === 'go') {
|
|
461
393
|
if (!ctxRoutes.has(e.route))
|
|
@@ -475,7 +407,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
475
407
|
effects.push({ type: 'stream', path: e.path, value: e.value });
|
|
476
408
|
else if (e.type === 'toast')
|
|
477
409
|
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'
|
|
410
|
+
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork' || e.type === 'cue' || e.type === 'callout' || e.type === 'hold')
|
|
479
411
|
continue; // 镜头与焦点提示不是状态变化,下面单独归类
|
|
480
412
|
else if (e.type === 'say') {
|
|
481
413
|
if (typeof e.text === 'string' && e.text.trim())
|
|
@@ -493,42 +425,36 @@ export function compile(src, mode, opts = {}) {
|
|
|
493
425
|
if (e.text.trim())
|
|
494
426
|
explains.push(e.text.trim());
|
|
495
427
|
}
|
|
496
|
-
else if (e.type === '
|
|
497
|
-
const
|
|
498
|
-
if (
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
428
|
+
else if (e.type === 'plugin') {
|
|
429
|
+
const lowered = host.effect(e, effectRoots.filter(scene => scene.layer || scene.id === sceneOf(stepRouteBefore(fl.steps, i + 1, start))), ext[e.plugin], st.source);
|
|
430
|
+
if (lowered) {
|
|
431
|
+
effects.push(...(lowered.writes ?? []).map(w => ({ type: 'set', path: w.path, value: w.value })));
|
|
432
|
+
if (lowered.directorTarget)
|
|
433
|
+
directorTargets.push(lowered.directorTarget);
|
|
434
|
+
if (lowered.holdMs)
|
|
435
|
+
effectHoldMs = Math.max(effectHoldMs, lowered.holdMs);
|
|
436
|
+
if (lowered.media?.length) {
|
|
437
|
+
const key = `${sid}#${i + 1}`;
|
|
438
|
+
host.mediaCommands.set(key, [...(host.mediaCommands.get(key) ?? []), ...lowered.media]);
|
|
439
|
+
}
|
|
440
|
+
if (lowered.data !== undefined)
|
|
441
|
+
ext[e.plugin] = lowered.data;
|
|
442
|
+
if (lowered.targets?.length) {
|
|
443
|
+
pluginTargets.set(e, lowered.targets);
|
|
444
|
+
pluginFocus.push(...lowered.targets);
|
|
445
|
+
}
|
|
446
|
+
references.push(...lowered.references ?? []);
|
|
503
447
|
}
|
|
504
448
|
}
|
|
505
|
-
else
|
|
449
|
+
else if (e.type === 'complete')
|
|
506
450
|
effects.push({ type: 'complete', text: e.text, outcome: e.outcome });
|
|
451
|
+
else
|
|
452
|
+
err('EFFECT_INVALID', 'Unknown step effect; use a documented effect helper instead of constructing effect objects', st.source);
|
|
507
453
|
}
|
|
508
454
|
const sceneBefore = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i, start)));
|
|
509
455
|
const sceneAfter = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i + 1, start)));
|
|
510
456
|
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
|
-
}
|
|
457
|
+
validateNewAction(st.action, hasLayers ? layerScenes.map(l => l.scene) : sceneBefore ? [sceneBefore] : [], out, (code, message) => err(code, message, st.source));
|
|
532
458
|
for (const e of st.effects) {
|
|
533
459
|
if (e.type === 'fork') {
|
|
534
460
|
if (!Object.hasOwn(def.scenarios, e.scenario) || e.scenario === skey)
|
|
@@ -599,10 +525,10 @@ export function compile(src, mode, opts = {}) {
|
|
|
599
525
|
const perLayer = new Map();
|
|
600
526
|
let directorLayer = null;
|
|
601
527
|
for (const e of st.effects) {
|
|
602
|
-
if (e.type !== 'shot' && !
|
|
528
|
+
if (e.type !== 'shot' && !pluginTargets.has(e))
|
|
603
529
|
continue;
|
|
604
|
-
const
|
|
605
|
-
const targets = e.type === 'shot' ? e.targets :
|
|
530
|
+
const fromPlugin = e.type !== 'shot';
|
|
531
|
+
const targets = e.type === 'shot' ? e.targets : pluginTargets.get(e);
|
|
606
532
|
if (targets.length === 0) {
|
|
607
533
|
// shot():导演所在层回到整体(不推近)
|
|
608
534
|
const lk = hasLayers ? DIRECTOR_LAYER : PAGE_LAYER;
|
|
@@ -612,8 +538,8 @@ export function compile(src, mode, opts = {}) {
|
|
|
612
538
|
for (const id of targets) {
|
|
613
539
|
const where = hasLayers ? layersWith(id) : [sceneAfter, sceneBefore].some((sc) => sc && findIn(sc.root, id)) ? [PAGE_LAYER] : [];
|
|
614
540
|
if (!where.length) {
|
|
615
|
-
if (
|
|
616
|
-
continue; //
|
|
541
|
+
if (fromPlugin)
|
|
542
|
+
continue; // 插件目标已经校验过;不在这一步的画面里时不移动镜头
|
|
617
543
|
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
544
|
continue;
|
|
619
545
|
}
|
|
@@ -626,9 +552,9 @@ export function compile(src, mode, opts = {}) {
|
|
|
626
552
|
}
|
|
627
553
|
}
|
|
628
554
|
}
|
|
629
|
-
//
|
|
630
|
-
if (hasLayers && !directorLayer &&
|
|
631
|
-
directorLayer = layersWith(
|
|
555
|
+
// 插件的导演目标只选择层,不自动加入聚焦框或推进视角。
|
|
556
|
+
if (hasLayers && !directorLayer && directorTargets.length)
|
|
557
|
+
directorLayer = layersWith(directorTargets[0])[0] ?? null;
|
|
632
558
|
// 没写 shot、写了焦点提示(D70):导演切到第一个提示目标所在的层(提示要被看见)
|
|
633
559
|
if (hasLayers && !directorLayer && focusTargets.length)
|
|
634
560
|
directorLayer = layersWith(focusTargets[0])[0] ?? null;
|
|
@@ -662,7 +588,7 @@ export function compile(src, mode, opts = {}) {
|
|
|
662
588
|
director = directorLayer;
|
|
663
589
|
for (const s of shots)
|
|
664
590
|
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;
|
|
591
|
+
const generated = st.caption === undefined ? autoCaption(st, (hasLayers && actionTarget ? layerSceneWith(actionTarget) : undefined) ?? sceneBefore, out) : null;
|
|
666
592
|
return {
|
|
667
593
|
id: `${sid}#${i + 1}`,
|
|
668
594
|
...(st.key !== undefined ? { key: st.key } : {}),
|
|
@@ -675,12 +601,15 @@ export function compile(src, mode, opts = {}) {
|
|
|
675
601
|
shots,
|
|
676
602
|
directorLayer,
|
|
677
603
|
...(explains.length ? { explain: explains.join('\n') } : {}),
|
|
678
|
-
|
|
604
|
+
...(Object.keys(ext).length ? { ext } : {}),
|
|
605
|
+
...(references.length ? { references: [...new Set(references)] } : {}),
|
|
606
|
+
...(pluginFocus.length ? { focusTargets: [...new Set(pluginFocus)] } : {}),
|
|
679
607
|
forks,
|
|
680
608
|
marks,
|
|
681
609
|
...(cues.length ? { cues } : {}),
|
|
682
610
|
...(callouts.length ? { callouts } : {}),
|
|
683
611
|
...(holdMs !== undefined ? { hold: holdMs } : {}),
|
|
612
|
+
...(effectHoldMs > 0 ? { effectHold: effectHoldMs } : {}),
|
|
684
613
|
...(says.length ? { say: says.join(' ') } : {}),
|
|
685
614
|
...(narrates.length ? { narrate: narrates.join(' ') } : {}),
|
|
686
615
|
...(st.source ? { source: rel(st.source) } : {}),
|
|
@@ -694,9 +623,11 @@ export function compile(src, mode, opts = {}) {
|
|
|
694
623
|
const outcome = fl.opts.outcome ?? fromDone ?? 'success';
|
|
695
624
|
const state = mergeState(def.state, fl.opts.state);
|
|
696
625
|
const sc = {
|
|
626
|
+
...(fl.opts.actionEntry !== undefined ? { actionEntry: fl.opts.actionEntry } : {}),
|
|
697
627
|
id: sid,
|
|
698
628
|
optionId: qid,
|
|
699
629
|
name: fl.name,
|
|
630
|
+
...(fl.opts.autoplay !== undefined ? { autoplay: fl.opts.autoplay } : {}),
|
|
700
631
|
description: fl.opts.description ?? '',
|
|
701
632
|
caseIds: strip ? [] : (fl.opts.cases ?? []).filter((c) => fdef.cases?.[c]).map((c) => `${fid}.${c}`),
|
|
702
633
|
mock: { label: fl.opts.mock ?? MOCK_LABEL[outcome], outcome, ...(fl.opts.mock === undefined ? { auto: true } : {}) },
|
|
@@ -747,7 +678,40 @@ export function compile(src, mode, opts = {}) {
|
|
|
747
678
|
if (!fdef.cases?.[ck])
|
|
748
679
|
err('UNKNOWN_CASE', `Option ${qid} coverage declares unknown case "${ck}"`, def.source);
|
|
749
680
|
}
|
|
681
|
+
const free = {};
|
|
682
|
+
for (const [key, reaction] of Object.entries(def.free ?? {})) {
|
|
683
|
+
const a = Action.safeParse(reaction.action);
|
|
684
|
+
if (!a.success || !('target' in reaction.action)) {
|
|
685
|
+
err('FREE_ACTION_INVALID', `Free reaction ${key} needs a targeted action`, reaction.source);
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
const roots = effectRoots.filter(scene => scene.optionId === qid || mode === 'publish' && scene.optionId === null);
|
|
689
|
+
const target = reaction.action.target;
|
|
690
|
+
if (!roots.some(scene => findIn(scene.root, target)))
|
|
691
|
+
err('FREE_TARGET_MISSING', `Free reaction ${key}: target ${reaction.action.target} is not in option ${qid}`, reaction.source);
|
|
692
|
+
const targets = roots.map(scene => findIn(scene.root, target)).filter((n) => !!n);
|
|
693
|
+
if (reaction.action.type === 'click' && targets.length && !targets.some(n => isInteractiveType(n.type, out.plugins)))
|
|
694
|
+
err('FREE_ACTION_INVALID', `Free reaction ${key}: ${target} is not interactive`, reaction.source);
|
|
695
|
+
if (['type', 'toggle', 'select'].includes(reaction.action.type) && targets.length && !targets.some(n => n.traits?.input))
|
|
696
|
+
err('FREE_ACTION_INVALID', `Free reaction ${key}: ${target} cannot accept values`, reaction.source);
|
|
697
|
+
validateNewAction(reaction.action, roots, out, (code, message) => err(code, message, reaction.source));
|
|
698
|
+
const effects = [];
|
|
699
|
+
for (const effect of reaction.effects) {
|
|
700
|
+
if (!['set', 'append', 'toast'].includes(effect.type)) {
|
|
701
|
+
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);
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
const { kind: _kind, ...raw } = effect;
|
|
705
|
+
const parsed = Effect.safeParse(raw);
|
|
706
|
+
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))))
|
|
707
|
+
err('FREE_EFFECT_INVALID', `Free reaction ${key}: invalid local effect`, reaction.source);
|
|
708
|
+
else
|
|
709
|
+
effects.push(parsed.data);
|
|
710
|
+
}
|
|
711
|
+
free[key] = { action: a.data, effects, ...(reaction.source ? { source: rel(reaction.source) } : {}) };
|
|
712
|
+
}
|
|
750
713
|
out.options[qid] = {
|
|
714
|
+
...(Object.keys(free).length ? { free } : {}),
|
|
751
715
|
id: qid,
|
|
752
716
|
featureId: fid,
|
|
753
717
|
key: o.key,
|
|
@@ -771,32 +735,6 @@ export function compile(src, mode, opts = {}) {
|
|
|
771
735
|
err('UNKNOWN_CASE', `Rule "${r.text}" links unknown case ${c}`, r.source);
|
|
772
736
|
}
|
|
773
737
|
}
|
|
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
738
|
// flow({ from }) 接力:初始状态 = 被接的场景最后一步之后的状态(路径、ui / data / inputs、导演层),再叠上本场景写的 state。
|
|
801
739
|
// 链式接力按依赖顺序解析;成环或被接的场景回放失败时报错。
|
|
802
740
|
if (pendingFrom.size) {
|
|
@@ -815,16 +753,17 @@ export function compile(src, mode, opts = {}) {
|
|
|
815
753
|
visiting.delete(sid);
|
|
816
754
|
if (!ok)
|
|
817
755
|
return false;
|
|
818
|
-
const target =
|
|
819
|
-
const prev =
|
|
756
|
+
const target = out.scenarios[sid];
|
|
757
|
+
const prev = out.scenarios[p.from];
|
|
820
758
|
if (!target || !prev)
|
|
821
759
|
return false;
|
|
822
760
|
try {
|
|
823
|
-
const end = stateAt(
|
|
824
|
-
const hasLayers = Object.keys(
|
|
825
|
-
const layer = p.layer ?? (hasLayers ? cameraAt(
|
|
761
|
+
const end = stateAt(out, p.from, prev.steps.length);
|
|
762
|
+
const hasLayers = Object.keys(out.options[target.optionId]?.layers ?? {}).length > 0;
|
|
763
|
+
const layer = p.layer ?? (hasLayers ? cameraAt(out, p.from, prev.steps.length).directorLayer : undefined);
|
|
826
764
|
const merged = mergeState({ ui: end.ui, data: end.data, inputs: end.inputs }, p.state);
|
|
827
765
|
target.initial = { sceneId: end.sceneId, ui: merged.ui, data: merged.data, inputs: merged.inputs, ...(layer ? { layer } : {}) };
|
|
766
|
+
target.from = p.from;
|
|
828
767
|
}
|
|
829
768
|
catch (e) {
|
|
830
769
|
err('FROM_FAILED', `Scenario ${sid} continues from ${p.from}, which does not replay: ${e.message}`, p.at);
|
|
@@ -838,10 +777,41 @@ export function compile(src, mode, opts = {}) {
|
|
|
838
777
|
if (diags.some((d) => d.severity === 'error'))
|
|
839
778
|
return { project: null, diagnostics: diags };
|
|
840
779
|
}
|
|
780
|
+
// 逐步派生数据只在编译期计算,播放器读取快照。
|
|
781
|
+
if (!diags.some(d => d.severity === 'error'))
|
|
782
|
+
host.frames(out);
|
|
783
|
+
if (diags.some(d => d.severity === 'error'))
|
|
784
|
+
return { project: null, diagnostics: diags };
|
|
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
|
+
let project = pruneMessages(parsed.data);
|
|
841
800
|
if (mode === 'dev' && project.i18n) {
|
|
842
801
|
const stale = localeDiagnostics(project, src, diags);
|
|
843
802
|
project.i18n = { ...project.i18n, stale };
|
|
844
803
|
}
|
|
804
|
+
// A slot can fit on its own but exceed the public reader's limit once wrapped in
|
|
805
|
+
// scenes/scenarios/steps/ext. Validate that final depth before reporting success.
|
|
806
|
+
if (mode === 'publish') {
|
|
807
|
+
try {
|
|
808
|
+
project = materialize(project);
|
|
809
|
+
}
|
|
810
|
+
catch (e) {
|
|
811
|
+
err('PLUGIN_DATA_INVALID', `Published IR is not readable JSON data: ${errorMessage(e)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
812
|
+
return { project: null, diagnostics: diags };
|
|
813
|
+
}
|
|
814
|
+
}
|
|
845
815
|
return { project, diagnostics: diags };
|
|
846
816
|
}
|
|
847
817
|
/** config.locales(D84):非空、不重复、都是支持的语言;第一个是默认语言。没写时为 null。 */
|
|
@@ -972,36 +942,34 @@ function expandSlots(n, fill, outlet) {
|
|
|
972
942
|
function tagFrom(n, from) {
|
|
973
943
|
return { ...n, props: { ...n.props, __from: from } };
|
|
974
944
|
}
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
945
|
+
function toSceneNode(n, fallbackId, ids, nc, parentType) {
|
|
946
|
+
const { report: err, rel } = nc;
|
|
947
|
+
n = { ...n, props: n.props ?? {}, children: n.children ?? [] };
|
|
948
|
+
n = { ...n, type: nc.host.intrinsic.get(n.type) ?? n.type };
|
|
949
|
+
n = inheritProps(n, nc.host.inherits.get(n.type) ?? []);
|
|
950
|
+
const children = flatten(n.children).map((c, i) => isNode(c) ? toSceneNode(c, `${fallbackId}_${i}`, ids, nc, n.type) : textNode(c, `${fallbackId}_${i}`));
|
|
951
|
+
n = nc.host.node(n, ids);
|
|
980
952
|
const { id: rawId, when, disabled, disabledReason, unmodeled, note, redact, __from, ...rest } = n.props;
|
|
981
953
|
const at = n.source;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
954
|
+
const plug = splitPluginType(n.type);
|
|
955
|
+
if (plug) {
|
|
956
|
+
const spec = pluginSpec(nc.plugins, n.type);
|
|
957
|
+
if (!nc.plugins[plug.plugin])
|
|
958
|
+
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);
|
|
959
|
+
else if (!spec)
|
|
960
|
+
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);
|
|
961
|
+
else if (spec.parent && parentType !== `${plug.plugin}:${spec.parent}`)
|
|
962
|
+
err('PLUGIN_PARENT', `<${n.type}> must be written directly inside <${plug.plugin}:${spec.parent}> (npx joplo skill ${plug.plugin})`, at);
|
|
963
|
+
}
|
|
964
|
+
else if (!KNOWN.has(n.type))
|
|
965
|
+
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);
|
|
966
|
+
const interactive = isInteractiveType(n.type, nc.plugins);
|
|
985
967
|
if (interactive && typeof rawId !== 'string')
|
|
986
968
|
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}`);
|
|
969
|
+
const spec = pluginSpec(nc.plugins, n.type);
|
|
970
|
+
if (spec?.needsId && typeof rawId !== 'string' && !interactive)
|
|
971
|
+
err('MISSING_ID', `<${n.type}> "${labelOf(n)}" requires an id`, at);
|
|
972
|
+
const id = typeof rawId === 'string' ? rawId : `_${fallbackId}`;
|
|
1005
973
|
if (ids.has(id))
|
|
1006
974
|
err('DUPLICATE_ID', `Duplicate id "${id}" in the same stage (other location: ${rel(ids.get(id)) ?? 'unknown'})`, at);
|
|
1007
975
|
ids.set(id, at);
|
|
@@ -1020,6 +988,11 @@ function toSceneNode(n, fallbackId, ids, err, rel) {
|
|
|
1020
988
|
props[k] = toPropValue(v);
|
|
1021
989
|
}
|
|
1022
990
|
const node = { id, type: n.type };
|
|
991
|
+
if (spec?.traits) {
|
|
992
|
+
const { text: _text, textPaths: _paths, ...runtime } = spec.traits;
|
|
993
|
+
if (Object.keys(runtime).length)
|
|
994
|
+
node.traits = runtime;
|
|
995
|
+
}
|
|
1023
996
|
if (Object.keys(props).length)
|
|
1024
997
|
node.props = props;
|
|
1025
998
|
if (children.length)
|
|
@@ -1053,202 +1026,26 @@ function toSceneNode(n, fallbackId, ids, err, rel) {
|
|
|
1053
1026
|
node.source = s;
|
|
1054
1027
|
return node;
|
|
1055
1028
|
}
|
|
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
|
-
}
|
|
1029
|
+
/** Forward declared properties before descending; nested owners establish their own scope. */
|
|
1030
|
+
function inheritProps(owner, declarations) {
|
|
1031
|
+
if (!declarations.length)
|
|
1032
|
+
return owner;
|
|
1033
|
+
const visit = (child) => {
|
|
1034
|
+
if (Array.isArray(child))
|
|
1035
|
+
return child.map(visit);
|
|
1036
|
+
if (!isNode(child) || child.type === owner.type)
|
|
1037
|
+
return child;
|
|
1038
|
+
const spec = declarations.find(d => d.target === child.type);
|
|
1039
|
+
if (spec) {
|
|
1040
|
+
const props = { ...child.props };
|
|
1041
|
+
for (const key of spec.props)
|
|
1042
|
+
if (props[key] === undefined && owner.props[key] !== undefined)
|
|
1043
|
+
props[key] = owner.props[key];
|
|
1044
|
+
return { ...child, props };
|
|
1195
1045
|
}
|
|
1046
|
+
return { ...child, children: child.children.map(visit) };
|
|
1196
1047
|
};
|
|
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
|
-
}
|
|
1048
|
+
return { ...owner, children: owner.children.map(visit) };
|
|
1252
1049
|
}
|
|
1253
1050
|
/** 展开数组与 Fragment(含插槽展开后的 Fragment),丢弃 null/布尔。 */
|
|
1254
1051
|
function flatten(cs) {
|
|
@@ -1319,12 +1116,16 @@ function findIn(node, id) {
|
|
|
1319
1116
|
}
|
|
1320
1117
|
const NO_STATE = { ui: {}, data: {}, inputs: {} };
|
|
1321
1118
|
/** 自动字幕:元素名取 Mantine 的 label 属性(其次 title / aria-label / placeholder / 文字);select 显示选项的 label。 */
|
|
1322
|
-
function autoCaption(st, scene) {
|
|
1119
|
+
function autoCaption(st, scene, project) {
|
|
1323
1120
|
const a = st.action;
|
|
1324
1121
|
const node = 'target' in a && scene ? findIn(scene.root, a.target) : null;
|
|
1325
1122
|
const label = node ? nodeLabel(node) : 'target' in a ? a.target : '';
|
|
1326
1123
|
const result = (kind, caption, extra = {}) => ({ caption, captionAuto: { kind, label, ...extra } });
|
|
1327
1124
|
switch (a.type) {
|
|
1125
|
+
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}` });
|
|
1126
|
+
case 'hover': return result('hover', `Hover over “${label}”`);
|
|
1127
|
+
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}` });
|
|
1128
|
+
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
1129
|
case 'click': return result('click', `Click “${label}”`);
|
|
1329
1130
|
case 'type': return result('type', `Type “${a.value}” in “${label}”`, { value: a.value });
|
|
1330
1131
|
case 'select': {
|
|
@@ -1333,7 +1134,7 @@ function autoCaption(st, scene) {
|
|
|
1333
1134
|
return result('select', `Select “${value}” in “${label}”`, { value });
|
|
1334
1135
|
}
|
|
1335
1136
|
case 'toggle': {
|
|
1336
|
-
const kind = node?.
|
|
1137
|
+
const kind = node?.traits?.toggleCaption === 'check' ? (a.value ? 'check' : 'uncheck') : (a.value ? 'switch_on' : 'switch_off');
|
|
1337
1138
|
const verb = { check: 'Check', uncheck: 'Uncheck', switch_on: 'Turn on', switch_off: 'Turn off' }[kind];
|
|
1338
1139
|
return result(kind, `${verb} “${label}”`);
|
|
1339
1140
|
}
|
|
@@ -1343,12 +1144,48 @@ function autoCaption(st, scene) {
|
|
|
1343
1144
|
case 'card': return { caption: a.title };
|
|
1344
1145
|
}
|
|
1345
1146
|
}
|
|
1147
|
+
/** Validate extension actions while all scene anchors and enabled declarations are available. */
|
|
1148
|
+
function validateNewAction(action, scenes, project, report) {
|
|
1149
|
+
if (!['drag', 'hover', 'scroll', 'plugin'].includes(action.type))
|
|
1150
|
+
return;
|
|
1151
|
+
const parsed = Action.safeParse(action);
|
|
1152
|
+
if (!parsed.success) {
|
|
1153
|
+
report('ACTION_INVALID', `Invalid ${action.type} action: ${parsed.error.message}`);
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
if (!('target' in action))
|
|
1157
|
+
return;
|
|
1158
|
+
const nodes = scenes.map(s => findIn(s.root, action.target)).filter((n) => !!n);
|
|
1159
|
+
if (!nodes.length)
|
|
1160
|
+
report('MISSING_TARGET', `Action target ${action.target} is not in the current stage`);
|
|
1161
|
+
if (action.type === 'drag' || action.type === 'scroll') {
|
|
1162
|
+
if (typeof action.to === 'string' && !scenes.some(s => findIn(s.root, action.target) && findIn(s.root, action.to)))
|
|
1163
|
+
report('ACTION_DESTINATION_MISSING', `${action.type} destination ${action.to} must be in the same stage as ${action.target}`);
|
|
1164
|
+
else if (action.type === 'scroll' && typeof action.to === 'string' && !nodes.some(n => findIn(n, action.to)))
|
|
1165
|
+
report('ACTION_DESTINATION_INVALID', `Scroll destination ${action.to} must be inside ${action.target}`);
|
|
1166
|
+
}
|
|
1167
|
+
if (action.type === 'plugin') {
|
|
1168
|
+
const spec = pluginActionSpec(project, action.name);
|
|
1169
|
+
if (!spec)
|
|
1170
|
+
report('ACTION_UNKNOWN', `Plugin action ${action.name} is not declared by an enabled plugin`);
|
|
1171
|
+
else {
|
|
1172
|
+
if (!validActionData(spec, action.data))
|
|
1173
|
+
report('ACTION_DATA_INVALID', `Plugin action ${action.name} payload does not match its declared fields`);
|
|
1174
|
+
if (spec.targets && nodes.some(n => !spec.targets.includes(n.type)))
|
|
1175
|
+
report('ACTION_TARGET_INVALID', `Plugin action ${action.name} does not accept this target type`);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1346
1179
|
function stripSources(o) {
|
|
1347
1180
|
if (Array.isArray(o))
|
|
1348
1181
|
return o.forEach(stripSources);
|
|
1349
1182
|
if (o && typeof o === 'object') {
|
|
1350
1183
|
delete o.source;
|
|
1351
|
-
|
|
1184
|
+
// Plugin slots are already validated public data. Stripping their own fields would
|
|
1185
|
+
// invalidate the plugin schema after validation (e.g. a public provenance `source`).
|
|
1186
|
+
for (const [key, value] of Object.entries(o))
|
|
1187
|
+
if (key !== 'ext')
|
|
1188
|
+
stripSources(value);
|
|
1352
1189
|
}
|
|
1353
1190
|
}
|
|
1354
1191
|
function stripNotes(n) {
|