@joplo-app/core 0.1.3 → 0.2.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/catalog.d.ts +1 -1
- package/dist/catalog.js +112 -105
- package/dist/compile.d.ts +2 -0
- package/dist/compile.js +109 -50
- package/dist/guide.d.ts +7 -7
- package/dist/guide.js +347 -296
- package/dist/load.js +5 -5
- package/dist/player.d.ts +39 -1
- package/dist/player.js +104 -19
- package/dist/schema.d.ts +181 -2
- package/dist/schema.js +25 -6
- package/dist/validate.js +34 -34
- package/package.json +2 -2
package/dist/compile.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { isBind, isNode, bindPath, toCondition } from '@joplo-app/kit/node';
|
|
10
10
|
import { BUILTIN_THEMES, COMPONENT_TYPES, DIRECTOR_LAYER, INTERACTIVE_TYPES, PAGE_LAYER, matchChoice, nodeLabel } from "./catalog.js";
|
|
11
|
-
import { choicesOf } from "./player.js";
|
|
11
|
+
import { choicesOf, commonPrefix } from "./player.js";
|
|
12
12
|
import { Project, SCHEMA_VERSION } from "./schema.js";
|
|
13
13
|
const KNOWN = new Set(COMPONENT_TYPES);
|
|
14
14
|
const OVERLAY = 'overlay';
|
|
15
|
-
const MOCK_LABEL = { success: '
|
|
15
|
+
const MOCK_LABEL = { success: 'Mock success', failure: 'Mock failure', denied: 'Mock permission denied', other: 'Mock' };
|
|
16
16
|
export function compile(src, mode) {
|
|
17
17
|
const diags = [];
|
|
18
18
|
const rel = (s) => (s ? relSource(src.root, s) : undefined);
|
|
@@ -45,10 +45,10 @@ export function compile(src, mode) {
|
|
|
45
45
|
if (o)
|
|
46
46
|
picked.set(fid, o);
|
|
47
47
|
else
|
|
48
|
-
err('UNKNOWN_PICK',
|
|
48
|
+
err('UNKNOWN_PICK', `Feature ${fid} pick "${pick}" is not an option under options/`, f.def.source);
|
|
49
49
|
}
|
|
50
50
|
else if (mode === 'publish')
|
|
51
|
-
warn('NOT_PICKED',
|
|
51
|
+
warn('NOT_PICKED', `Feature "${f.def.name}" has no picked option and will not be published`, f.def.source);
|
|
52
52
|
}
|
|
53
53
|
const included = mode === 'dev' ? allOptions : [...picked.values()];
|
|
54
54
|
const baseRoutes = new Map();
|
|
@@ -58,9 +58,9 @@ export function compile(src, mode) {
|
|
|
58
58
|
for (const o of allOptions) {
|
|
59
59
|
for (const [path, p] of Object.entries(o.def.routes ?? {})) {
|
|
60
60
|
if (!path.startsWith('/'))
|
|
61
|
-
err('BAD_ROUTE',
|
|
61
|
+
err('BAD_ROUTE', `Route must start with /: ${path}`, o.def.source);
|
|
62
62
|
if (baseRoutes.has(path))
|
|
63
|
-
err('ROUTE_EXISTS',
|
|
63
|
+
err('ROUTE_EXISTS', `Option ${o.qid} adds route ${path} which already exists in routes/; use on to add elements instead`, p.source ?? o.def.source);
|
|
64
64
|
addedRoutes.set(`${o.qid}|${path}`, { path, page: { ...p, file: o.def.file }, addedBy: o });
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -80,7 +80,7 @@ export function compile(src, mode) {
|
|
|
80
80
|
for (const r of [...baseRoutes.values(), ...[...addedRoutes.values()].filter((r) => included.some((o) => o.qid === r.addedBy.qid))]) {
|
|
81
81
|
const lid = layoutOf(r.page);
|
|
82
82
|
if (lid && !src.layouts[lid])
|
|
83
|
-
err('UNKNOWN_LAYOUT',
|
|
83
|
+
err('UNKNOWN_LAYOUT', `Page ${r.path} uses an unknown layout "${lid}"`, r.page.source);
|
|
84
84
|
if (out.routes[r.path])
|
|
85
85
|
continue;
|
|
86
86
|
const slots = new Set();
|
|
@@ -106,7 +106,7 @@ export function compile(src, mode) {
|
|
|
106
106
|
id: fid,
|
|
107
107
|
name: fdef.name,
|
|
108
108
|
goal: fdef.goal,
|
|
109
|
-
roles: fdef.roles
|
|
109
|
+
roles: rolesOf(fdef.roles),
|
|
110
110
|
constraints: Object.entries(fdef.constraints ?? {}).map(([id, c]) => (typeof c === 'string' ? { id, text: c, hard: true } : { id, text: c.text, hard: c.hard ?? true })),
|
|
111
111
|
caseIds: mode === 'publish' ? [] : caseIds,
|
|
112
112
|
optionIds: included.filter((o) => o.fid === fid).map((o) => o.qid),
|
|
@@ -158,7 +158,7 @@ export function compile(src, mode) {
|
|
|
158
158
|
if (!used.has(slot)) {
|
|
159
159
|
const from = contribs.get(slot)[0].from;
|
|
160
160
|
const o = allOptions.find((x) => x.qid === from);
|
|
161
|
-
err('UNKNOWN_SLOT',
|
|
161
|
+
err('UNKNOWN_SLOT', `Option ${from} adds elements to route ${route.path} slot "${slot}", but the page and layout have no <Slot name="${slot}" />`, o?.def.source, {
|
|
162
162
|
kind: 'option',
|
|
163
163
|
id: from,
|
|
164
164
|
});
|
|
@@ -175,7 +175,7 @@ export function compile(src, mode) {
|
|
|
175
175
|
const t = src.config.theme ?? 'sketch';
|
|
176
176
|
const authorThemes = Object.keys(src.themes ?? {});
|
|
177
177
|
if (!BUILTIN_THEMES.includes(t) && !authorThemes.includes(t))
|
|
178
|
-
err('THEME_UNKNOWN', `config({ theme: '${t}' })
|
|
178
|
+
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`);
|
|
179
179
|
}
|
|
180
180
|
const sceneFor = new Map();
|
|
181
181
|
const addScene = (s) => {
|
|
@@ -196,7 +196,7 @@ export function compile(src, mode) {
|
|
|
196
196
|
const touched = [...Object.keys(def.on ?? {}), ...Object.keys(def.routes ?? {})];
|
|
197
197
|
for (const p of Object.keys(def.on ?? {}))
|
|
198
198
|
if (!ctxRoutes.has(p))
|
|
199
|
-
err('UNKNOWN_ROUTE',
|
|
199
|
+
err('UNKNOWN_ROUTE', `Option ${qid} adds elements to an unknown route ${p}`, def.source);
|
|
200
200
|
const sceneOf = (path) => (mode === 'dev' ? `${qid}@${path}` : `@${path}`);
|
|
201
201
|
if (mode === 'dev') {
|
|
202
202
|
for (const [k, r] of Object.entries(def.rules ?? {}))
|
|
@@ -209,9 +209,11 @@ export function compile(src, mode) {
|
|
|
209
209
|
return `${qid}.${key}`;
|
|
210
210
|
if (fdef.rules?.[key])
|
|
211
211
|
return `${fid}.${key}`;
|
|
212
|
-
err('UNKNOWN_RULE', `uses("${key}")
|
|
212
|
+
err('UNKNOWN_RULE', `uses("${key}") references an unknown rule (use a key from option.rules or feature.rules)`, at);
|
|
213
213
|
return null;
|
|
214
214
|
};
|
|
215
|
+
/** 可被引用的角色键(D56):feature.roles 写成 { 键: role('名字') } 时才有。 */
|
|
216
|
+
const roleKeys = new Set(fdef.roles && !Array.isArray(fdef.roles) ? Object.keys(fdef.roles) : []);
|
|
215
217
|
// ---------- 层级(T-layers):每层一个完全独立的画面,单独编译、单独渲染 ----------
|
|
216
218
|
const layers = {};
|
|
217
219
|
const layerScenes = [];
|
|
@@ -219,13 +221,13 @@ export function compile(src, mode) {
|
|
|
219
221
|
for (const [lk, ld] of Object.entries(def.layers ?? {})) {
|
|
220
222
|
const at = ld.source ?? def.source;
|
|
221
223
|
if (!/^[A-Za-z_][\w-]*$/.test(lk)) {
|
|
222
|
-
err('LAYER_UNKNOWN',
|
|
224
|
+
err('LAYER_UNKNOWN', `Layer key "${lk}" must use letters, digits, underscores, and hyphens and must not start with @`, at);
|
|
223
225
|
continue;
|
|
224
226
|
}
|
|
225
227
|
const tree = flatten(Array.isArray(ld.tree) ? ld.tree : [ld.tree]);
|
|
226
228
|
const nodes = tree.filter(isNode);
|
|
227
229
|
if (!nodes.length) {
|
|
228
|
-
err('LAYER_UNKNOWN',
|
|
230
|
+
err('LAYER_UNKNOWN', `Layer "${ld.title}" has no content: layer(title, <Page />)`, at);
|
|
229
231
|
continue;
|
|
230
232
|
}
|
|
231
233
|
const rootJ = nodes.length === 1 ? nodes[0] : { ...nodes[0], type: 'div', props: {}, children: nodes };
|
|
@@ -235,7 +237,9 @@ export function compile(src, mode) {
|
|
|
235
237
|
const scene = { id: sceneId, optionId: qid, route: layerRoute, name: `${ld.title} · ${def.name}`, viewport: ld.viewport ?? 'desktop', root, layer: lk };
|
|
236
238
|
addScene(scene);
|
|
237
239
|
layerScenes.push({ key: lk, scene });
|
|
238
|
-
|
|
240
|
+
if (ld.role !== undefined && !roleKeys.has(ld.role))
|
|
241
|
+
err('ROLE_UNKNOWN', `Layer "${ld.title}" role "${ld.role}" is not in feature.roles${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ' (feature.roles must use { key: role(\'Name\') })'}`, at);
|
|
242
|
+
layers[lk] = { title: ld.title, sceneId, ...(ld.role !== undefined && roleKeys.has(ld.role) ? { role: ld.role } : {}) };
|
|
239
243
|
}
|
|
240
244
|
const hasLayers = layerScenes.length > 0;
|
|
241
245
|
/** 元素在哪些层级里(多层都有同名 id 时都算)。 */
|
|
@@ -246,14 +250,14 @@ export function compile(src, mode) {
|
|
|
246
250
|
const resolveTrace = (ids, tmode, at) => {
|
|
247
251
|
const shown = `trace(${ids.map((x) => JSON.stringify(x)).join(', ')})`;
|
|
248
252
|
if (!ids.length) {
|
|
249
|
-
err('TRACE_UNKNOWN', `${shown}
|
|
253
|
+
err('TRACE_UNKNOWN', `${shown} requires at least one node or edge id`, at);
|
|
250
254
|
return null;
|
|
251
255
|
}
|
|
252
256
|
const has = (d, t) => d.nodes.has(t) || d.edges.some((e) => e.id === t);
|
|
253
257
|
const d = diagrams.find((x) => ids.every((t) => has(x, t)));
|
|
254
258
|
if (!d) {
|
|
255
259
|
const missing = ids.find((t) => !diagrams.some((x) => has(x, t)));
|
|
256
|
-
err('TRACE_UNKNOWN', missing ? `${shown}
|
|
260
|
+
err('TRACE_UNKNOWN', missing ? `${shown} contains "${missing}", which is not a node or edge id in any Diagram` : `${shown} has nodes from different Diagrams`, at);
|
|
257
261
|
return null;
|
|
258
262
|
}
|
|
259
263
|
const nodes = [];
|
|
@@ -279,7 +283,7 @@ export function compile(src, mode) {
|
|
|
279
283
|
// 写连线 id:方向由上一个节点决定(从 to 端接上时逆向走)
|
|
280
284
|
const reverse = prev !== null && prev === edge.to && prev !== edge.from;
|
|
281
285
|
if (prev !== null && prev !== edge.from && prev !== edge.to) {
|
|
282
|
-
err('TRACE_UNKNOWN', `${shown}
|
|
286
|
+
err('TRACE_UNKNOWN', `${shown}: edge "${t}"(${edge.from} → ${edge.to}) is not connected to the previous node "${prev}"`, at);
|
|
283
287
|
return null;
|
|
284
288
|
}
|
|
285
289
|
edges.push({ id: edge.id, reverse });
|
|
@@ -294,11 +298,11 @@ export function compile(src, mode) {
|
|
|
294
298
|
const back = d.edges.filter((e) => e.from === t && e.to === prev);
|
|
295
299
|
const pick = fwd.length ? fwd : back;
|
|
296
300
|
if (pick.length > 1) {
|
|
297
|
-
err('TRACE_AMBIGUOUS', `${shown}
|
|
301
|
+
err('TRACE_AMBIGUOUS', `${shown}: "${prev}" and "${t}" have ${pick.length} edges (${pick.map((e) => e.id).join(', ')}), use an edge id instead, for example trace('${pick[0].id}')`, at);
|
|
298
302
|
return null;
|
|
299
303
|
}
|
|
300
304
|
if (!pick.length) {
|
|
301
|
-
err('TRACE_UNKNOWN', `${shown}
|
|
305
|
+
err('TRACE_UNKNOWN', `${shown}: "${prev}" and "${t}" have no connecting edge (each segment needs a Diagram.Edge in the same Diagram; either direction is allowed)`, at);
|
|
302
306
|
return null;
|
|
303
307
|
}
|
|
304
308
|
edges.push({ id: pick[0].id, reverse: !fwd.length });
|
|
@@ -313,12 +317,12 @@ export function compile(src, mode) {
|
|
|
313
317
|
const sid = `${qid}.${skey}`;
|
|
314
318
|
const start = fl.opts.start ?? touched[0] ?? src.config.home ?? [...ctxRoutes][0];
|
|
315
319
|
if (!start || !ctxRoutes.has(start)) {
|
|
316
|
-
err('UNKNOWN_ROUTE',
|
|
320
|
+
err('UNKNOWN_ROUTE', `Scenario ${sid} starts at unknown route ${start ?? '(none)'}`, fl.source);
|
|
317
321
|
continue;
|
|
318
322
|
}
|
|
319
323
|
for (const c of fl.opts.cases ?? []) {
|
|
320
324
|
if (!fdef.cases?.[c])
|
|
321
|
-
err('UNKNOWN_CASE',
|
|
325
|
+
err('UNKNOWN_CASE', `Scenario ${sid} covers case "${c}", which is not in feature.cases`, fl.source);
|
|
322
326
|
else
|
|
323
327
|
(scenarioIds[c] ??= []).push(sid);
|
|
324
328
|
}
|
|
@@ -327,12 +331,14 @@ export function compile(src, mode) {
|
|
|
327
331
|
const ruleIds = [];
|
|
328
332
|
const explains = [];
|
|
329
333
|
const traces = [];
|
|
334
|
+
const forks = [];
|
|
335
|
+
const marks = [];
|
|
330
336
|
/** 每个 trace 效果解析出的节点(作为镜头目标,与 shot 合并)。 */
|
|
331
337
|
const traceTargets = new Map();
|
|
332
338
|
for (const e of st.effects) {
|
|
333
339
|
if (e.type === 'go') {
|
|
334
340
|
if (!ctxRoutes.has(e.route))
|
|
335
|
-
err('UNKNOWN_ROUTE', `go("${e.route}")
|
|
341
|
+
err('UNKNOWN_ROUTE', `go("${e.route}") navigates to an unknown route`, st.source);
|
|
336
342
|
effects.push({ type: 'navigate', sceneId: sceneOf(e.route) });
|
|
337
343
|
}
|
|
338
344
|
else if (e.type === 'uses') {
|
|
@@ -344,9 +350,11 @@ export function compile(src, mode) {
|
|
|
344
350
|
}
|
|
345
351
|
else if (e.type === 'set' || e.type === 'append')
|
|
346
352
|
effects.push({ type: e.type, path: e.path, value: e.value });
|
|
353
|
+
else if (e.type === 'stream')
|
|
354
|
+
effects.push({ type: 'stream', path: e.path, value: e.value });
|
|
347
355
|
else if (e.type === 'toast')
|
|
348
356
|
effects.push({ type: 'toast', text: e.text, tone: e.tone });
|
|
349
|
-
else if (e.type === 'shot')
|
|
357
|
+
else if (e.type === 'shot' || e.type === 'mark' || e.type === 'fork')
|
|
350
358
|
continue; // 镜头不是状态变化,下面单独归类
|
|
351
359
|
else if (e.type === 'explain') {
|
|
352
360
|
if (e.text.trim())
|
|
@@ -367,6 +375,21 @@ export function compile(src, mode) {
|
|
|
367
375
|
const sceneBefore = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i, start)));
|
|
368
376
|
const sceneAfter = sceneFor.get(sceneOf(stepRouteBefore(fl.steps, i + 1, start)));
|
|
369
377
|
const actionTarget = 'target' in st.action ? st.action.target : null;
|
|
378
|
+
for (const e of st.effects) {
|
|
379
|
+
if (e.type === 'fork') {
|
|
380
|
+
if (!Object.hasOwn(def.scenarios, e.scenario) || e.scenario === skey)
|
|
381
|
+
err('FORK_UNKNOWN', `Fork target "${e.scenario}" must be another scenario key in the same option`, st.source);
|
|
382
|
+
else if (e.label.trim())
|
|
383
|
+
forks.push({ label: e.label.trim(), scenarioId: `${qid}.${e.scenario}`, at: 0 });
|
|
384
|
+
}
|
|
385
|
+
if (e.type === 'mark') {
|
|
386
|
+
const exists = hasLayers ? layersWith(e.target).length > 0 : !!sceneAfter && !!findIn(sceneAfter.root, e.target);
|
|
387
|
+
if (!exists)
|
|
388
|
+
err('MARK_UNKNOWN', `mark("${e.target}") target is not in ${hasLayers ? 'any layer' : 'the stage for this step'}`, st.source);
|
|
389
|
+
else
|
|
390
|
+
marks.push({ target: e.target, kind: e.kindOf, ...(e.note ? { note: e.note } : {}) });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
370
393
|
// 镜头:每个 id 在包含它的层级里解析;第一个 shot 的第一个元素所在层级就是这一步的导演层。
|
|
371
394
|
// 没有声明 layers 的方案:在路径页面里聚焦(伪层级 @page)。
|
|
372
395
|
const perLayer = new Map();
|
|
@@ -387,7 +410,7 @@ export function compile(src, mode) {
|
|
|
387
410
|
if (!where.length) {
|
|
388
411
|
if (fromTrace)
|
|
389
412
|
continue; // trace 的节点已在 Diagram 里校验过;不在这一步的画面里时不移动镜头
|
|
390
|
-
err('SHOT_UNKNOWN', hasLayers ? `shot("${id}")
|
|
413
|
+
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);
|
|
391
414
|
continue;
|
|
392
415
|
}
|
|
393
416
|
for (const lk of where) {
|
|
@@ -402,18 +425,30 @@ export function compile(src, mode) {
|
|
|
402
425
|
// 没写 shot 的操作步骤:导演切到操作目标所在的层(播放时观众看得到要点的东西)
|
|
403
426
|
if (hasLayers && !directorLayer && actionTarget)
|
|
404
427
|
directorLayer = layersWith(actionTarget)[0] ?? null;
|
|
428
|
+
// 换人的过渡卡(D56):卡片后面导演切到这个人的层级(卡片淡出时已经是 TA 的画面)
|
|
429
|
+
if (st.action.type === 'card' && st.action.role !== undefined) {
|
|
430
|
+
const r = st.action.role;
|
|
431
|
+
if (!roleKeys.has(r))
|
|
432
|
+
err('ROLE_UNKNOWN', `card("${st.action.title}") role "${r}" is not in feature.roles${roleKeys.size ? ` (available: ${[...roleKeys].join(', ')})` : ''}`, st.source);
|
|
433
|
+
else if (hasLayers && !directorLayer)
|
|
434
|
+
directorLayer = Object.entries(layers).find(([, l]) => l.role === r)?.[0] ?? null;
|
|
435
|
+
}
|
|
405
436
|
const shots = [...perLayer].map(([layer, targets]) => ({ layer, targets }));
|
|
437
|
+
const generated = st.caption === undefined ? autoCaption(st, (hasLayers && actionTarget ? layerSceneWith(actionTarget) : undefined) ?? sceneBefore) : null;
|
|
406
438
|
return {
|
|
407
439
|
id: `${sid}#${i + 1}`,
|
|
408
440
|
kind: st.kind,
|
|
409
441
|
action: st.action,
|
|
410
|
-
caption: st.caption ??
|
|
442
|
+
caption: st.caption ?? generated.caption,
|
|
443
|
+
...(generated?.captionAuto ? { captionAuto: generated.captionAuto } : {}),
|
|
411
444
|
effects,
|
|
412
445
|
ruleIds: mode === 'publish' ? [] : ruleIds,
|
|
413
446
|
shots,
|
|
414
447
|
directorLayer,
|
|
415
448
|
...(explains.length ? { explain: explains.join('\n') } : {}),
|
|
416
449
|
traces,
|
|
450
|
+
forks,
|
|
451
|
+
marks,
|
|
417
452
|
...(st.source ? { source: rel(st.source) } : {}),
|
|
418
453
|
};
|
|
419
454
|
});
|
|
@@ -425,7 +460,7 @@ export function compile(src, mode) {
|
|
|
425
460
|
name: fl.name,
|
|
426
461
|
description: fl.opts.description ?? '',
|
|
427
462
|
caseIds: mode === 'publish' ? [] : (fl.opts.cases ?? []).filter((c) => fdef.cases?.[c]).map((c) => `${fid}.${c}`),
|
|
428
|
-
mock: { label: fl.opts.mock ?? MOCK_LABEL[outcome], outcome },
|
|
463
|
+
mock: { label: fl.opts.mock ?? MOCK_LABEL[outcome], outcome, ...(fl.opts.mock === undefined ? { auto: true } : {}) },
|
|
429
464
|
initial: { sceneId: sceneOf(start), ui: state.ui, data: state.data, inputs: state.inputs },
|
|
430
465
|
steps,
|
|
431
466
|
expected: fl.opts.expected ?? '',
|
|
@@ -433,6 +468,17 @@ export function compile(src, mode) {
|
|
|
433
468
|
};
|
|
434
469
|
out.scenarios[sid] = sc;
|
|
435
470
|
}
|
|
471
|
+
// 所有场景完成后再解析分叉(允许向后声明的场景),不把创作信息参与前缀比较。
|
|
472
|
+
for (const sc of Object.values(out.scenarios)) {
|
|
473
|
+
if (sc.optionId !== qid)
|
|
474
|
+
continue;
|
|
475
|
+
for (const st of sc.steps)
|
|
476
|
+
for (const f of st.forks) {
|
|
477
|
+
const target = out.scenarios[f.scenarioId];
|
|
478
|
+
if (target)
|
|
479
|
+
f.at = commonPrefix(sc.steps, target.steps);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
436
482
|
const coverage = {};
|
|
437
483
|
if (mode === 'dev') {
|
|
438
484
|
for (const ck of Object.keys(fdef.cases ?? {})) {
|
|
@@ -443,11 +489,11 @@ export function compile(src, mode) {
|
|
|
443
489
|
else if (sids.length)
|
|
444
490
|
coverage[`${fid}.${ck}`] = { status: 'expressed', scenarioIds: sids, basis: 'derived' };
|
|
445
491
|
else
|
|
446
|
-
coverage[`${fid}.${ck}`] = { status: 'missing', scenarioIds: [],
|
|
492
|
+
coverage[`${fid}.${ck}`] = { status: 'missing', scenarioIds: [], basis: 'derived' };
|
|
447
493
|
}
|
|
448
494
|
for (const ck of Object.keys(def.coverage ?? {}))
|
|
449
495
|
if (!fdef.cases?.[ck])
|
|
450
|
-
err('UNKNOWN_CASE',
|
|
496
|
+
err('UNKNOWN_CASE', `Option ${qid} coverage declares unknown case "${ck}"`, def.source);
|
|
451
497
|
}
|
|
452
498
|
out.options[qid] = {
|
|
453
499
|
id: qid,
|
|
@@ -467,10 +513,10 @@ export function compile(src, mode) {
|
|
|
467
513
|
if (mode === 'dev') {
|
|
468
514
|
for (const r of Object.values(out.rules)) {
|
|
469
515
|
if (r.origin === 'ai_assumption' && r.confirmation === 'confirmed')
|
|
470
|
-
err('ASSUMPTION_CONFIRMED',
|
|
516
|
+
err('ASSUMPTION_CONFIRMED', `Rule "${r.text}" is an AI assumption and cannot be Confirmed; use pending, or set origin to user after user confirmation`, r.source);
|
|
471
517
|
for (const c of r.caseIds)
|
|
472
518
|
if (!out.cases[c])
|
|
473
|
-
err('UNKNOWN_CASE',
|
|
519
|
+
err('UNKNOWN_CASE', `Rule "${r.text}" links unknown case ${c}`, r.source);
|
|
474
520
|
}
|
|
475
521
|
}
|
|
476
522
|
// ---------- 7. 发布视图:去掉设计备注 ----------
|
|
@@ -490,6 +536,16 @@ export function compile(src, mode) {
|
|
|
490
536
|
return { project: parsed.data, diagnostics: diags };
|
|
491
537
|
}
|
|
492
538
|
// ---------- 帮助函数 ----------
|
|
539
|
+
/** 角色的颜色(D56):没写 color 时按声明顺序取。 */
|
|
540
|
+
export const ROLE_COLORS = ['#E8590C', '#1971C2', '#2F9E44', '#9C36B5', '#C2255C', '#0C8599'];
|
|
541
|
+
function rolesOf(roles) {
|
|
542
|
+
if (!roles)
|
|
543
|
+
return [];
|
|
544
|
+
const color = (i, c) => c ?? ROLE_COLORS[i % ROLE_COLORS.length];
|
|
545
|
+
if (Array.isArray(roles))
|
|
546
|
+
return roles.map((name, i) => ({ name, desc: '', color: color(i) }));
|
|
547
|
+
return Object.entries(roles).map(([id, r], i) => ({ id, name: r.name, desc: r.desc ?? '', color: color(i, r.color) }));
|
|
548
|
+
}
|
|
493
549
|
function sortedEntries(o) {
|
|
494
550
|
return Object.entries(o).sort(([a], [b]) => a.localeCompare(b));
|
|
495
551
|
}
|
|
@@ -552,30 +608,30 @@ function toSceneNode(n, fallbackId, ids, err, rel) {
|
|
|
552
608
|
const { id: rawId, when, disabled, disabledReason, unmodeled, note, __from, ...rest } = n.props;
|
|
553
609
|
const at = n.source;
|
|
554
610
|
if (!KNOWN.has(n.type))
|
|
555
|
-
err('UNKNOWN_COMPONENT',
|
|
611
|
+
err('UNKNOWN_COMPONENT', `Component <${n.type}> is not in the catalog (use Mantine component names; run joplo skill components to list them; use <Custom kind="…"> as a placeholder for missing components)`, at);
|
|
556
612
|
const interactive = INTERACTIVE_TYPES.has(n.type);
|
|
557
613
|
if (interactive && typeof rawId !== 'string')
|
|
558
|
-
err('MISSING_ID',
|
|
614
|
+
err('MISSING_ID', `Interactive component <${n.type}> "${labelOf(n)}" requires an id for steps and selection`, at);
|
|
559
615
|
if (n.type === 'Diagram.Node' && typeof rawId !== 'string')
|
|
560
|
-
err('MISSING_ID',
|
|
616
|
+
err('MISSING_ID', `Diagram node <Diagram.Node> "${labelOf(n)}" requires an id for edge from / to`, at);
|
|
561
617
|
if (n.type === 'Diagram')
|
|
562
618
|
checkDiagram(n, err);
|
|
563
619
|
// 连线没写 id 时用「from->to」:⌥+单击检查与 rules 的 elements 都能引用它
|
|
564
620
|
const edgeId = n.type === 'Diagram.Edge' && typeof rest.from === 'string' && typeof rest.to === 'string' ? `${rest.from}->${rest.to}` : null;
|
|
565
621
|
const id = typeof rawId === 'string' ? rawId : (edgeId ?? `_${fallbackId}`);
|
|
566
622
|
if (ids.has(id))
|
|
567
|
-
err('DUPLICATE_ID',
|
|
623
|
+
err('DUPLICATE_ID', `Duplicate id "${id}" in the same stage (other location: ${rel(ids.get(id)) ?? 'unknown'})`, at);
|
|
568
624
|
ids.set(id, at);
|
|
569
625
|
const props = {};
|
|
570
626
|
for (const [k, v] of Object.entries(rest)) {
|
|
571
627
|
if (v === undefined)
|
|
572
628
|
continue; // 写了属性但值是 undefined(如 description={cond ? '…' : undefined})= 没写
|
|
573
629
|
if (typeof v === 'function' && !isBind(v)) {
|
|
574
|
-
err('FUNCTION_PROP', `<${n.type}>
|
|
630
|
+
err('FUNCTION_PROP', `<${n.type}> prop ${k} is a function. Put behavior in the option's flow steps instead of event callbacks`, at);
|
|
575
631
|
continue;
|
|
576
632
|
}
|
|
577
633
|
if (isNode(v)) {
|
|
578
|
-
err('ELEMENT_PROP', `<${n.type}>
|
|
634
|
+
err('ELEMENT_PROP', `<${n.type}> prop ${k} is an element. Props accept only strings, numbers, booleans, and objects; use characters for icons (for example leftSection="+") and children for content`, at);
|
|
579
635
|
continue;
|
|
580
636
|
}
|
|
581
637
|
props[k] = toPropValue(v);
|
|
@@ -621,12 +677,12 @@ function checkDiagram(d, err) {
|
|
|
621
677
|
}
|
|
622
678
|
};
|
|
623
679
|
walk(d.children);
|
|
624
|
-
const known = [...nodes].join('
|
|
680
|
+
const known = [...nodes].join(', ') || '(no nodes)';
|
|
625
681
|
for (const e of edges) {
|
|
626
682
|
for (const k of ['from', 'to']) {
|
|
627
683
|
const v = e.props[k];
|
|
628
684
|
if (typeof v !== 'string' || !nodes.has(v))
|
|
629
|
-
err('UNKNOWN_DIAGRAM_NODE', `<Diagram.Edge>
|
|
685
|
+
err('UNKNOWN_DIAGRAM_NODE', `<Diagram.Edge> ${k} "${typeof v === 'string' ? v : String(v)}" is not a node id in this Diagram (available: ${known})`, e.source);
|
|
630
686
|
}
|
|
631
687
|
}
|
|
632
688
|
}
|
|
@@ -691,21 +747,24 @@ function autoCaption(st, scene) {
|
|
|
691
747
|
const a = st.action;
|
|
692
748
|
const node = 'target' in a && scene ? findIn(scene.root, a.target) : null;
|
|
693
749
|
const label = node ? nodeLabel(node) : 'target' in a ? a.target : '';
|
|
750
|
+
const result = (kind, caption, extra = {}) => ({ caption, captionAuto: { kind, label, ...extra } });
|
|
694
751
|
switch (a.type) {
|
|
695
|
-
case 'click':
|
|
696
|
-
|
|
697
|
-
case 'type':
|
|
698
|
-
return `在「${label}」中输入“${a.value}”`;
|
|
752
|
+
case 'click': return result('click', `Click “${label}”`);
|
|
753
|
+
case 'type': return result('type', `Type “${a.value}” in “${label}”`, { value: a.value });
|
|
699
754
|
case 'select': {
|
|
700
755
|
const choices = node ? choicesOf(node, NO_STATE) : null;
|
|
701
|
-
|
|
756
|
+
const value = (choices && matchChoice(choices, a.value)?.label) ?? a.value;
|
|
757
|
+
return result('select', `Select “${value}” in “${label}”`, { value });
|
|
758
|
+
}
|
|
759
|
+
case 'toggle': {
|
|
760
|
+
const kind = node?.type === 'Checkbox' ? (a.value ? 'check' : 'uncheck') : (a.value ? 'switch_on' : 'switch_off');
|
|
761
|
+
const verb = { check: 'Check', uncheck: 'Uncheck', switch_on: 'Turn on', switch_off: 'Turn off' }[kind];
|
|
762
|
+
return result(kind, `${verb} “${label}”`);
|
|
702
763
|
}
|
|
703
|
-
case '
|
|
704
|
-
|
|
705
|
-
case '
|
|
706
|
-
|
|
707
|
-
case 'event':
|
|
708
|
-
return a.name;
|
|
764
|
+
case 'press': return result('press', a.keys.trim() ? `Press ${a.keys}` : 'Press a key', { keys: a.keys });
|
|
765
|
+
case 'back': return result('back', 'Go back');
|
|
766
|
+
case 'event': return { caption: a.name };
|
|
767
|
+
case 'card': return { caption: a.title };
|
|
709
768
|
}
|
|
710
769
|
}
|
|
711
770
|
function stripSources(o) {
|
package/dist/guide.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export declare const SKILL_TOPICS: readonly [{
|
|
2
2
|
readonly name: "authoring";
|
|
3
|
-
readonly description: "
|
|
3
|
+
readonly description: "Directory conventions; page / layout / option / flow syntax";
|
|
4
4
|
}, {
|
|
5
5
|
readonly name: "demo";
|
|
6
|
-
readonly description: "
|
|
6
|
+
readonly description: "Layers, shots, traces, and captions for clear demos";
|
|
7
7
|
}, {
|
|
8
8
|
readonly name: "components";
|
|
9
|
-
readonly description: "
|
|
9
|
+
readonly description: "Component catalog and props for this version";
|
|
10
10
|
}, {
|
|
11
11
|
readonly name: "cases";
|
|
12
|
-
readonly description: "
|
|
12
|
+
readonly description: "Case dimensions: ask the user before starting";
|
|
13
13
|
}, {
|
|
14
14
|
readonly name: "check";
|
|
15
|
-
readonly description: "
|
|
15
|
+
readonly description: "Read diagnostics and fix the indicated file and line";
|
|
16
16
|
}, {
|
|
17
17
|
readonly name: "selection";
|
|
18
|
-
readonly description: "
|
|
18
|
+
readonly description: "Edit only the element selected by the user in the board";
|
|
19
19
|
}, {
|
|
20
20
|
readonly name: "publish";
|
|
21
|
-
readonly description: "pick
|
|
21
|
+
readonly description: "pick, build, and static site deployment";
|
|
22
22
|
}];
|
|
23
23
|
export type SkillTopic = (typeof SKILL_TOPICS)[number]['name'];
|
|
24
24
|
/** CLI 传入其 package.json 版本;行数来自同一次生成的主题正文。 */
|