@joplo-app/core 0.2.6 → 0.2.7

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.
@@ -11,7 +11,7 @@ export declare const MENTAL_MODEL: readonly ["Joplo is a player for pre-declared
11
11
  /** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
12
12
  export declare const START_ORDER: readonly ["Read npx joplo skill authoring; read cases before asking the user about edge cases; demo and components as needed.", "With minimal code, write one happy path and one error-and-recovery scenario.", "Run npx joplo check, then npx joplo dev; confirm typing, clicks, and layers really behave as intended in the board.", "Extend to every option and every case agreed with the user; run check until 0 errors.", "Give the user the board URL and a short list of what to check, then wait for their feedback."];
13
13
  /** 最常见的坑:一句话 + 详细主题。 */
14
- export declare const PITFALLS: readonly [readonly ["when takes a condition, not a boolean: when={eq($.ui.mode, 'code')}, never when={mode === 'code'}; for values known while writing use {flag && <X/>}", "authoring"], readonly ["Only catalog components and the listed HTML tags exist; <br/> is UNKNOWN_COMPONENT, so write 'Line 1\\nLine 2' inside <Text>", "components"], readonly ["Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE", "check"], readonly ["No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)", "authoring"], readonly ["Full-height layouts squeeze tables and forms: rows exist in the DOM but are cut off on screen; show 5–8 rows or move the table to its own layer", "demo"], readonly ["Deep links use short params ?o=&c=&s=&step=&l= (l is the layer key; layer= is ignored); wait for rendering before screenshots", "demo"], readonly ["Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user", "cases"], readonly ["Never share or deploy without the user's go-ahead; free share links expire after 1 hour", "publish"]];
14
+ export declare const PITFALLS: readonly [readonly ["when takes a condition, not a boolean: when={eq($.ui.mode, 'code')}, never when={mode === 'code'}; for values known while writing use {flag && <X/>}", "authoring"], readonly ["Only catalog components and the listed HTML tags exist; <br/> is UNKNOWN_COMPONENT, so write 'Line 1\\nLine 2' inside <Text>", "components"], readonly ["Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE", "check"], readonly ["No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)", "authoring"], readonly ["Full-height layouts squeeze tables and forms: rows exist in the DOM but are cut off on screen; show 5–8 rows or move the table to its own layer", "demo"], readonly ["Deep links use short params ?o=&c=&s=&step=&l= (l is the layer key and pins that layer, so later steps stop switching layers; layer= is ignored); wait for rendering before screenshots", "demo"], readonly ["Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user", "cases"], readonly ["Never share or deploy without the user's go-ahead; free share links expire after 1 hour", "publish"]];
15
15
  export type AgentSkill = {
16
16
  name: string;
17
17
  description: string;
@@ -29,7 +29,7 @@ export const PITFALLS = [
29
29
  ['Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE', 'check'],
30
30
  ['No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)', 'authoring'],
31
31
  ['Full-height layouts squeeze tables and forms: rows exist in the DOM but are cut off on screen; show 5–8 rows or move the table to its own layer', 'demo'],
32
- ['Deep links use short params ?o=&c=&s=&step=&l= (l is the layer key; layer= is ignored); wait for rendering before screenshots', 'demo'],
32
+ ['Deep links use short params ?o=&c=&s=&step=&l= (l is the layer key and pins that layer, so later steps stop switching layers; layer= is ignored); wait for rendering before screenshots', 'demo'],
33
33
  ['Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user', 'cases'],
34
34
  ['Never share or deploy without the user\'s go-ahead; free share links expire after 1 hour', 'publish'],
35
35
  ];
@@ -50,7 +50,7 @@ function joploBody() {
50
50
  '- Not for production UI code, real backends, or demos where viewers type free input.',
51
51
  '',
52
52
  '## Workflow',
53
- '1. No joplo.config.ts yet: npx joplo@latest init <dir>, then npm install in that directory (versions are pinned). In an existing Joplo project, use its installed npx joplo.',
53
+ '1. No joplo.config.ts yet: npx joplo@latest init <dir>, or npx joplo@latest init . for the current directory, then npm install there (versions are pinned). Agent and Git files (.git, .gitignore, .agents, .claude, AGENTS.md, skills-lock.json) do not count as content; other existing files need init . --keep, which only adds missing files. init skips these skills when the same version is already installed and never overwrites edited ones. In an existing Joplo project, use its installed npx joplo.',
54
54
  ...list(START_ORDER).map(line => line.replace(/^(\d+)/, (_, n) => String(Number(n) + 1))),
55
55
  `${START_ORDER.length + 2}. After the user agrees: npx joplo share --format json (picked options), or npx joplo share --review for reviewers comparing every option. Apply review results with the joplo-feedback skill.`,
56
56
  '',
@@ -59,6 +59,7 @@ function joploBody() {
59
59
  '',
60
60
  'Exact APIs: npx joplo skill <topic> prints guidance matching the installed version (authoring, demo, components, cases, check, selection, publish). Run npx joplo skill for the overview.',
61
61
  'After the user Alt+clicks a board element, run npx joplo selection and edit only that location.',
62
+ 'Pin these skills to a release: npx skills add https://github.com/Joplo-app/Joplo/tree/v<version> (Joplo-app/Joplo@v<version> does not work).',
62
63
  ].join('\n');
63
64
  }
64
65
  function feedbackBody() {
package/dist/compile.js CHANGED
@@ -476,7 +476,12 @@ export function compile(src, mode) {
476
476
  ...(st.source ? { source: rel(st.source) } : {}),
477
477
  };
478
478
  });
479
- const outcome = fl.opts.outcome ?? 'success';
479
+ // 结局(D65):flow 的 outcome 优先;没写时取 done(…, outcome) 的第二个参数(cancelled 记为 other)
480
+ const doneOutcome = [...fl.steps].reverse().flatMap((st) => [...st.effects].reverse()).find((e) => e.type === 'complete')?.outcome;
481
+ const fromDone = doneOutcome === undefined ? undefined : doneOutcome === 'cancelled' ? 'other' : doneOutcome;
482
+ if (fl.opts.outcome !== undefined && fromDone !== undefined && fl.opts.outcome !== fromDone)
483
+ warn('OUTCOME_MISMATCH', `Scenario ${sid} has flow outcome '${fl.opts.outcome}' but ends with done(…, '${doneOutcome}'); the board shows '${fl.opts.outcome}'. Make them agree: change done's second argument, or write flow(…, { outcome: '${fromDone}' })`, fl.source);
484
+ const outcome = fl.opts.outcome ?? fromDone ?? 'success';
480
485
  const state = mergeState(def.state, fl.opts.state);
481
486
  const sc = {
482
487
  id: sid,
@@ -669,8 +674,13 @@ function toSceneNode(n, fallbackId, ids, err, rel) {
669
674
  node.when = toCondition(when);
670
675
  if (disabled !== undefined)
671
676
  node.disabled = (typeof disabled === 'boolean' ? disabled : toCondition(disabled));
677
+ // disabledReason:字面量,或整值绑定(和 disabled 一样跟着状态变,D65);其他值不会被显示,直接报错并给出写法
672
678
  if (typeof disabledReason === 'string')
673
679
  node.disabledReason = disabledReason;
680
+ else if (isBind(disabledReason))
681
+ node.disabledReason = `$${bindPath(disabledReason)}`;
682
+ else if (disabledReason !== undefined && disabledReason !== null)
683
+ err('INVALID_DISABLED_REASON', `<${n.type}> "${labelOf(n)}" disabledReason must be a string or a state binding, got ${typeof disabledReason === 'object' ? 'an object' : typeof disabledReason}. Write disabledReason="Only admins can invite" or disabledReason={$.ui.sendHint}; for text that changes during the demo, set() it into state and bind it`, at);
674
684
  if (unmodeled === true)
675
685
  node.unmodeled = true;
676
686
  if (typeof note === 'string')
@@ -747,12 +757,23 @@ function labelOf(n) {
747
757
  const t = flatten(n.children).filter((c) => typeof c === 'string').join('');
748
758
  return t || n.type;
749
759
  }
760
+ /**
761
+ * 第 i 步执行之前所在的路径。与播放器(player.applyStep)同一个顺序:back 动作先回到上一页,
762
+ * 再按效果顺序处理 go(当前页入栈)。0.2.6 之前忽略了 back,返回后的 mark / shot / 自动字幕都按返回前的页面解析。
763
+ */
750
764
  function stepRouteBefore(steps, i, start) {
751
765
  let route = start;
752
- for (let k = 0; k < i; k++)
753
- for (const e of steps[k].effects)
754
- if (e.type === 'go')
766
+ const stack = [];
767
+ for (let k = 0; k < i; k++) {
768
+ const st = steps[k];
769
+ if (st.action.type === 'back')
770
+ route = stack.pop() ?? route;
771
+ for (const e of st.effects)
772
+ if (e.type === 'go') {
773
+ stack.push(route);
755
774
  route = e.route;
775
+ }
776
+ }
756
777
  return route;
757
778
  }
758
779
  function findIn(node, id) {
package/dist/guide.js CHANGED
@@ -109,12 +109,14 @@ Read only the topics needed, usually one or two at a time. See components for co
109
109
  - page({ title, layout?: string|false, viewport?: 'desktop'|'mobile' }, tree). See demo for devices and stages.
110
110
  - feature({ name, goal, cases, order?, roles?, constraints?, rules?, questions?, pick? }).
111
111
  - Do not number feature names by hand; use finite numeric order. The compiler writes featureIds into IR (including publish): ascending order first, then natural folder-name order for ties or omitted values. All views read that list.
112
- - option({ name, idea, on?, routes?, state?, rules?, questions?, coverage?, scenarios }).
112
+ - option({ name, idea, focus?, tradeoffs?, on?, routes?, layers?, state?, rules?, questions?, coverage?, scenarios }).
113
+ - focus: one sentence naming the design decision this option changes; tradeoffs: ['Faster to scan', 'Needs a second click'], shown in the option's hover card in the board. Both stay out of published and review builds.
113
114
  - on: { '/members': { actions: <Button id="invite">Invite</Button> } }: add elements to a slot on an existing route.
114
115
  - routes: { '/members/new': page({ title: 'New member' }, <Stack>…</Stack>) }: add a route for this option.
115
116
  - state: { ui: { ready: false }, data: {}, inputs: {} }: initial option state.
116
117
  - scenarios: { happy: flow('Success', { cases: ['happy'], start: '/members' }).click('invite', done('Completed')) }.
117
- - flow options also accept state, description, expected, mock, outcome to override initial state or describe mock results.
118
+ - flow(name, { cases?, start?, state?, description?, expected?, mock?, outcome? }): state overrides the option's initial state; description and expected describe the scenario.
119
+ - outcome: 'success' | 'failure' | 'denied' | 'other' is the board's result badge ("Mock failure"). Without it, the badge follows done's second argument, else success. mock: 'Mock: link expired' replaces the badge text.
118
120
  - See cases for case and coverage declarations; publish for pick and publishing.
119
121
 
120
122
  ## flow: Put behavior in steps
@@ -125,8 +127,8 @@ Read only the topics needed, usually one or two at a time. See components for co
125
127
  - set($.ui.ready, true): replace state; push($.data.rows, row): append an array item.
126
128
  - toast('Message') / toast.success/error/info('Message'): a message for the current step.
127
129
  - go('/members'): change route within the current option; back returns to the previous route.
128
- - done('Result', 'success'|'failure'|'cancelled'): end the scenario; default is success.
129
- - uses('rule_key', ...): link rules from this option or feature.
130
+ - done('Result', 'success'|'failure'|'cancelled'): end the scenario; default is success. It also sets the result badge (cancelled shows as other) unless flow({ outcome }) is written; if both are written they must agree, otherwise check warns OUTCOME_MISMATCH.
131
+ - uses('rule_key', ...): an effect that links rules from this option or feature, passed like set(): .click('send', uses('admin_only'), done('Sent')). It is not a flow method; .uses(...) is not a function.
130
132
 
131
133
  ## Bindings and conditions
132
134
  - $.ui.x / $.data.x / $.inputs.x bind whole values; arbitrary expressions are not evaluated. $.inputs.<id> is the value typed into element <id>.
@@ -140,6 +142,7 @@ Read only the topics needed, usually one or two at a time. See components for co
140
142
  - Value known while writing (a prop of your own component, a loop variable, an option-specific flag): render conditionally in your code instead, {mode === 'code' && <CodeForm/>}. false, null, and undefined children are dropped.
141
143
  - Value that changes during the demo: keep it in option state and change it with set() in a step.
142
144
  - disabled accepts true/false or a condition: disabled={$.ui.sending} disabledReason="Sending…".
145
+ - disabledReason is a string or a whole-value binding like disabled: disabledReason={$.ui.sendHint} shows the current state value. Anything else (a number, a condition, an expression) is INVALID_DISABLED_REASON.
143
146
 
144
147
  ## Layout and responsiveness (Mantine names and props; no className)
145
148
  - Use Stack / Group / SimpleGrid / Grid props: <Group justify="space-between">, <SimpleGrid cols={{ base: 1, md: 3 }}>.
@@ -194,6 +197,8 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
194
197
  - Declare layers in an option: layers: { client: layer('Client view', <ClientView/>), backend: layer('Backend flow', <Diagram>…</Diagram>) }.
195
198
  - layer(title, <tree/>) owns a JSX tree, renders independently, and fills the stage; it is not a crop of one large page.
196
199
  - Layers share ui / data / inputs. Switching layers does not change the step. Declaring layers makes the demo show these independent pages.
200
+ - routes / on and layers work together, but once an option declares layers the stage shows only its layers: route pages are not drawn during the demo. Routes still give flow start, go(), and back() their state, and step targets are found in the layers first (then the route page).
201
+ - To show a route page as well, render the same component in a layer: layers: { app: layer('App', <MembersPage/>), backend: layer('Backend', <Arch/>) }.
197
202
  - No automatic overview layer. Declare overview: layer('Overview', <Overview/>) when needed.
198
203
  - Put long notes in a separate explanation layer, such as why: layer('Design rationale', <Why/>), then switch to it with a shot.
199
204
 
@@ -202,7 +207,7 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
202
207
  - Each id resolves in the layer containing it. The same id can affect multiple layers; the first shot determines the director layer.
203
208
  - Example: .click('app_send', shot('msg_user'), shot('app', 'biz')) follows the client view first, then sets a backend shot.
204
209
  - shot() restores the whole director layer. Without a shot, keep the previous one; a plain click can follow the layer containing the button.
205
- - During playback, the director switches layers, zooms, and highlights. Switching layers manually pauses following; resume Follow director or replay only one layer.
210
+ - During playback, the director switches layers, zooms, and highlights. Clicking a layer tab, or opening a deep link with l=, pins that layer: Follow director turns off and later steps stay on the pinned layer, even when their shot or action is on another layer (the shot still happens there, you just do not see it). Turn Follow director back on (the switch next to the layer tabs) or drop l= from the URL to follow again; you can also replay only one layer.
206
211
  - Viewers can zoom with wheel/pinch, drag to pan, and fit the stage to see the whole view. The next director shot takes over again.
207
212
 
208
213
  ## Diagram and traces
@@ -239,14 +244,16 @@ See authoring for directories, state, and flow syntax. Import layer, shot, trace
239
244
  ## Deep links and screenshots
240
245
  - Board: http://127.0.0.1:<port>/#/<project>/f/<feature>?o=<option>&c=<case>&s=<scenario>&step=<n>&l=<layer>&speed=<0.5|1.5>. Copy the project part from the board URL.
241
246
  - Published site: <site>/#/f/<feature>?s=<scenario>&step=<n>&l=<layer>. Embeds use ?embed=1&scenario=<scenario>&autoplay=1 (see publish).
242
- - Ids are qualified: option invite.a-modal, case invite.no_permission, scenario invite.a-modal.happy. step=n is the state after n steps (0 = initial). l is the layer key from layers: { … }; it turns Follow director off.
247
+ - Ids are qualified: option invite.a-modal, case invite.no_permission, scenario invite.a-modal.happy. step=n is the state after n steps (0 = initial). l is the layer key from layers: { … }; it pins that layer and turns Follow director off, so later steps do not switch layers. Omit l to follow the director.
243
248
  - Other parameters (layer=, option=, scenario= in the hash) are ignored; the board logs a console warning naming them.
244
- - Screenshot one step: npx joplo render --scenario-id invite.a-modal.happy --step-id 'invite.a-modal.happy#2' --out shot.png. It waits for fonts, layout, and the camera, and needs Playwright (npx playwright install chromium).
249
+ - Screenshot one step: npx joplo render --scenario-id invite.a-modal.happy --step-id 'invite.a-modal.happy#2' --out shot.png. It waits for fonts, layout, and the camera.
250
+ - render needs the Joplo export component (Playwright + Chromium, about 100 MB, installed once under ~/.joplo, never into the project). Without it render exits 4 with EXPORT_COMPONENT_MISSING and downloads nothing. It is a large download, so confirm with the user, then run npx joplo setup export (npx joplo setup export --status checks without installing). Writing demos, dev, check, build, and share do not need it.
245
251
  - In a browser, open the deep link, wait for [data-jcamera][data-camera-settled="1"] plus two animation frames, then capture. During autoplay or typing animations the DOM can be ahead of the pixels; pause first.
246
252
 
247
253
  ## Transition cards, roles, and Agent output (D56)
248
254
  - .card('Title', { sub?, points?, role? }, ...effects): one large sentence filling the stage, as a step. Use for openings, endings, time jumps, and role switches.
249
255
  - Open with why this matters; end with points listing what was confirmed. For time jumps, use .card('3 days later', set($.data.invite, 'expired')).
256
+ - While a card covers the stage, the stage behind it is inert: nothing on it is clickable. Viewers continue with Next (or the → key), or by autoplay; a card step has no target to click.
250
257
  - Roles: declare roles: { ajie: role('Ajie', { desc: 'Invited friend' }) } in the feature; use layer('Ajie mobile', <AjieView/>, { role: 'ajie' }) for the layer.
251
258
  - A layer with a role shows a name badge at the bottom left and an avatar in its tab. After .card('Now Ajie', { role: 'ajie' }), the director switches to Ajie's layer.
252
259
  - Show one person at a time. For side-by-side views, draw two sections in the same layer.
@@ -402,7 +409,7 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
402
409
  - ROLE_UNKNOWN: A layer or card role is not in feature.roles. Declare roles as { key: role('Name') }; see demo.
403
410
  - ICON_UNKNOWN: A layer icon is not a preset. Use one of ${LAYER_ICONS.join(', ')}; see demo.
404
411
  - FORK_UNKNOWN: fork must target another scenario key in the same option; it cannot reference itself.
405
- - MARK_UNKNOWN: The mark target is absent from this step's route stage and all layers. Check the element id; currently hidden targets are valid references.
412
+ - MARK_UNKNOWN: The mark target is absent from this step's route stage (after go() and back() in earlier steps) or, with layers, from every layer. Check the element id; currently hidden targets are valid references.
406
413
  - SHOT_UNKNOWN: The shot target is absent from this step's stage and all layers. Check its id and layer; see demo.
407
414
  - LAYER_UNKNOWN: Invalid layer key or missing content. Use letters/digits/underscores/hyphens, do not start with @, and provide nonempty JSX.
408
415
  - TRACE_UNKNOWN: Empty trace, unknown id, multiple Diagrams, or disconnected path. Use connected node/edge ids in one Diagram.
@@ -413,7 +420,9 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
413
420
  - ASSUMPTION_CONFIRMED: Keep AI assumptions \`pending\`. After user confirmation, record the actual origin; do not change only status.
414
421
  - UNBOUND_INTERACTIVE: see the section below.
415
422
  - INVALID_CONDITION: when got a plain boolean, number, or string (when={!x}, when={mode === 'code'}). Use a condition such as when={eq($.ui.mode, 'code')}, or render conditionally in your code: {flag && <X/>}. See authoring.
416
- - DISABLED_WITHOUT_REASON: Add disabledReason explaining why the element cannot be used.
423
+ - DISABLED_WITHOUT_REASON: Add disabledReason explaining why the element cannot be used: a string, disabledReason="Only admins can invite", or a binding, disabledReason={$.ui.sendHint}.
424
+ - INVALID_DISABLED_REASON: disabledReason got a number, condition, or other value. Use a string or a whole-value binding; for text that changes, set() it into state and bind it.
425
+ - OUTCOME_MISMATCH: flow({ outcome }) and done(…, outcome) disagree; the badge uses flow's. Make them agree (cancelled corresponds to other).
417
426
  - CASE_NOT_COVERED: Add a scenario or declare coverage truthfully. Ask about missing behavior first.
418
427
  - EXPRESSED_WITHOUT_SCENARIO / COVERAGE_WITHOUT_REASON: Add a scenario or a reason for \`not_applicable\`/\`excluded\`.
419
428
  - RULE_ELEMENT_NOT_FOUND: Check rule.elements against element ids in the related option stages.
@@ -472,7 +481,8 @@ Compare cases and options in the board, then decide which option to publish for
472
481
  - Layer switching, Follow director, replaying one layer, shot focus, and captions all work on the published site. See demo for syntax.
473
482
  - Fullscreen works on the published site: F enters/toggles, Space plays/pauses, ←/→ steps back/forward, Esc exits.
474
483
  - Fullscreen keeps only the stage and captions. Playback controls float below and hide automatically.
475
- - Both local and published views can export images. Video export is local only and requires local Playwright/Chromium.
484
+ - Both local and published views can export images. Video export is local only.
485
+ - Local image and video export use the Joplo export component (Playwright + Chromium, kept under ~/.joplo, not in the project). If it is missing, the board's Export menu offers Install export component (about 100 MB) and continues the export after installing; in a terminal, run npx joplo setup export.
476
486
 
477
487
  ## Deploy
478
488
  Use your own Wrangler environment and account in the project directory:
@@ -490,7 +500,7 @@ Deploy only dist output, not author source files. MCP, comments, and collaborati
490
500
  - Free links expire after 1 hour; read data.expiresAt for the exact time. Pro permanent links have expiresAt: null.
491
501
  - Successful share JSON includes data.embed: { iframe, markdown, badge, preview }. To add the demo to a README, write data.embed.markdown as is; do not build badge links yourself. For a free link, tell the user the badge shows "expired" after data.expiresAt.
492
502
  - data.embed.iframe embeds a player for blogs and docs: it shows a cover first; append &scenario=<scenario id> to pick the start or &autoplay=1 to skip the cover.
493
- - share also uploads a 1200x630 preview image of the default scenario when local Playwright is installed; without it, share still succeeds and prints one "Skipped the preview image" line.
503
+ - share also uploads a 1200x630 preview image of the default scenario when the export component is installed (npx joplo setup export, or Playwright already in the project); without it, share still succeeds, prints one "Skipped the preview image" line, and never downloads anything.
494
504
  - Pro share updates the same-server link in .joplo/cloud.json; --new creates another link and --title sets its title.
495
505
  - The review version is a separate share (review: { shareId, url } in .joplo/cloud.json); it never replaces the main link. If the cloud rejects the review manifest, plain share retries once without it and still publishes.
496
506
  - npx joplo whoami --format json shows the account, plan, and limits; npx joplo logout signs out.
package/dist/player.d.ts CHANGED
@@ -121,6 +121,8 @@ export type ClickVerdict = {
121
121
  } | {
122
122
  kind: 'static';
123
123
  };
124
+ /** 禁用原因的当前文字:字面量原样返回;绑定(`$ui.x`)读当前状态;空或不是文字时为 null(界面用默认说明)。 */
125
+ export declare function disabledReasonOf(node: SceneNode, state: Pick<PlayState, 'ui' | 'data' | 'inputs'>): string | null;
124
126
  /**
125
127
  * 演示模式下用户点击了某个元素:判断应推进步骤,还是提示“当前演示未覆盖”(PRD 8.2、AC-19)。
126
128
  * 流程外点击绝不能被解释为成功。
package/dist/player.js CHANGED
@@ -446,6 +446,11 @@ function toDiagnostic(e, ref) {
446
446
  return e.diagnostics[0];
447
447
  return { severity: 'error', code: e instanceof JoploError ? e.code : 'PLAYBACK_FAILED', message: e instanceof Error ? e.message : String(e), source: 'replay', ref };
448
448
  }
449
+ /** 禁用原因的当前文字:字面量原样返回;绑定(`$ui.x`)读当前状态;空或不是文字时为 null(界面用默认说明)。 */
450
+ export function disabledReasonOf(node, state) {
451
+ const v = node.disabledReason === undefined ? undefined : resolveValue(node.disabledReason, state);
452
+ return typeof v === 'string' && v.trim() ? v : typeof v === 'number' ? String(v) : null;
453
+ }
449
454
  /**
450
455
  * 演示模式下用户点击了某个元素:判断应推进步骤,还是提示“当前演示未覆盖”(PRD 8.2、AC-19)。
451
456
  * 流程外点击绝不能被解释为成功。
@@ -460,7 +465,7 @@ export function explainClick(project, state, nodeId, sceneId) {
460
465
  const { node } = hit;
461
466
  const label = nodeLabel(node);
462
467
  if (isNodeDisabled(node, state))
463
- return { kind: 'disabled', reason: node.disabledReason ?? null };
468
+ return { kind: 'disabled', reason: disabledReasonOf(node, state) };
464
469
  const current = sc.steps[state.position];
465
470
  const targetOf = (s) => ('target' in s.action ? s.action.target : null);
466
471
  if (current && !state.completed && targetOf(current) === nodeId && checkStep(project, sc, state, current) === null)
package/dist/result.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** 所有入口共享的领域结果、诊断与错误分类(PRD 12.5)。 */
2
- export declare const ERROR_CODES: readonly ["INVALID_SCHEMA", "NOT_FOUND", "REVISION_CONFLICT", "INVALID_REFERENCE", "UNSUPPORTED_ACTION", "PLAYBACK_FAILED", "RENDER_FAILED", "EXPORT_FAILED", "UNSUPPORTED_SCHEMA_VERSION", "PERMISSION_DENIED", "IDEMPOTENCY_MISMATCH", "USAGE"];
2
+ export declare const ERROR_CODES: readonly ["INVALID_SCHEMA", "NOT_FOUND", "REVISION_CONFLICT", "INVALID_REFERENCE", "UNSUPPORTED_ACTION", "PLAYBACK_FAILED", "RENDER_FAILED", "EXPORT_FAILED", "EXPORT_COMPONENT_MISSING", "UNSUPPORTED_SCHEMA_VERSION", "PERMISSION_DENIED", "IDEMPOTENCY_MISMATCH", "USAGE"];
3
3
  export type ErrorCode = (typeof ERROR_CODES)[number];
4
4
  export type Severity = 'error' | 'warning' | 'info';
5
5
  export type DiagnosticSource = 'schema' | 'reference' | 'structure' | 'replay' | 'render';
package/dist/result.js CHANGED
@@ -8,6 +8,8 @@ export const ERROR_CODES = [
8
8
  'PLAYBACK_FAILED',
9
9
  'RENDER_FAILED',
10
10
  'EXPORT_FAILED',
11
+ /** 导出组件(Playwright + Chromium,D66)没有安装;CLI 以退出码 4 结束。 */
12
+ 'EXPORT_COMPONENT_MISSING',
11
13
  'UNSUPPORTED_SCHEMA_VERSION',
12
14
  'PERMISSION_DENIED',
13
15
  'IDEMPOTENCY_MISMATCH',
package/dist/validate.js CHANGED
@@ -139,7 +139,7 @@ export function validate(project, opts = { mode: 'all' }) {
139
139
  emit('error', 'DUPLICATE_ELEMENT', `Duplicate element ID in stage: ${n.id}`, n.source, r, 'reference');
140
140
  ids.add(n.id);
141
141
  if (n.disabled !== undefined && n.disabled !== false && !n.disabledReason?.trim())
142
- emit('warning', 'DISABLED_WITHOUT_REASON', `Disabled element has no reason: ${n.id}`, n.source, r);
142
+ emit('warning', 'DISABLED_WITHOUT_REASON', `Disabled element has no reason: ${n.id}. Add disabledReason="…" (for example disabledReason="Only admins can invite"), or bind it to state like disabled: disabledReason={$.ui.sendHint}`, n.source, r);
143
143
  if (INTERACTIVE_TYPES.has(n.type) && !bound.has(identity(n)) && !(n.disabled === true && n.disabledReason?.trim()) && !n.unmodeled)
144
144
  emit('warning', 'UNBOUND_INTERACTIVE', `Interactive element has no demo step: ${n.id}; bind a step, disable with a reason, or mark unmodeled`, n.source, r);
145
145
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/core",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Joplo 编译器、校验器与播放器(IR v2)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@joplo-app/kit": "0.2.6",
22
+ "@joplo-app/kit": "0.2.7",
23
23
  "zod": "4.6.7"
24
24
  },
25
25
  "engines": {