@joplo-app/core 0.2.2 → 0.2.5
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/agent-skill.d.ts +25 -0
- package/dist/agent-skill.js +112 -0
- package/dist/catalog.d.ts +1 -0
- package/dist/catalog.js +4 -1
- package/dist/compile.d.ts +2 -1
- package/dist/compile.js +41 -17
- package/dist/embed.d.ts +28 -0
- package/dist/embed.js +31 -0
- package/dist/features.d.ts +5 -0
- package/dist/features.js +4 -0
- package/dist/guide.d.ts +5 -5
- package/dist/guide.js +120 -13
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/player.d.ts +2 -1
- package/dist/player.js +2 -1
- package/dist/result.d.ts +2 -0
- package/dist/review.d.ts +91 -0
- package/dist/review.js +119 -0
- package/dist/schema-issues.d.ts +25 -0
- package/dist/schema-issues.js +63 -0
- package/dist/schema.d.ts +37 -4
- package/dist/schema.js +14 -3
- package/dist/validate.js +6 -15
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 技能的唯一模板(D64):
|
|
3
|
+
* - 仓库根目录的官方技能 `skills/<name>/SKILL.md`(`npx skills add Joplo-app/Joplo` 安装),
|
|
4
|
+
* - `joplo skill install` 写进项目的 `.claude/skills/<name>/SKILL.md` 与 AGENTS.md 托管段,
|
|
5
|
+
* - `joplo skill`(无主题)总览开头的心智模型与起步顺序,
|
|
6
|
+
* 都由这里生成。版本标记与哈希由 CLI 加上(packages/cli/src/skill.ts,需要 node:crypto)。
|
|
7
|
+
* 原则:薄技能——只放心智模型、起步顺序和最常见的坑,具体 API 指向 `npx joplo skill <主题>`(与项目安装的版本一致)。
|
|
8
|
+
*/
|
|
9
|
+
/** 心智模型:所有入口最先读到的几句话。 */
|
|
10
|
+
export declare const MENTAL_MODEL: readonly ["Joplo is a player for pre-declared scenarios, not a free-form app prototype.", "Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.", "Clicking the highlighted element plays the next declared step; other clicks only show a hint.", "Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.", "Options (A/B) and cases (edge cases) are compared in the local board; only the picked option is published."];
|
|
11
|
+
/** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
|
|
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
|
+
/** 最常见的坑:一句话 + 详细主题。 */
|
|
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"]];
|
|
15
|
+
export type AgentSkill = {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
body: string;
|
|
19
|
+
};
|
|
20
|
+
/** 官方技能与 `joplo skill install` 共用的两个技能(顺序即写入顺序)。 */
|
|
21
|
+
export declare function agentSkills(): AgentSkill[];
|
|
22
|
+
/** SKILL.md 正文(不含版本标记):frontmatter + 正文,以换行结尾。 */
|
|
23
|
+
export declare function skillMarkdown(skill: AgentSkill): string;
|
|
24
|
+
/** AGENTS.md 托管段(不含起止标记):心智模型、起步顺序、最常见的坑,细节指向主题。 */
|
|
25
|
+
export declare function agentsBlock(): string;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent 技能的唯一模板(D64):
|
|
3
|
+
* - 仓库根目录的官方技能 `skills/<name>/SKILL.md`(`npx skills add Joplo-app/Joplo` 安装),
|
|
4
|
+
* - `joplo skill install` 写进项目的 `.claude/skills/<name>/SKILL.md` 与 AGENTS.md 托管段,
|
|
5
|
+
* - `joplo skill`(无主题)总览开头的心智模型与起步顺序,
|
|
6
|
+
* 都由这里生成。版本标记与哈希由 CLI 加上(packages/cli/src/skill.ts,需要 node:crypto)。
|
|
7
|
+
* 原则:薄技能——只放心智模型、起步顺序和最常见的坑,具体 API 指向 `npx joplo skill <主题>`(与项目安装的版本一致)。
|
|
8
|
+
*/
|
|
9
|
+
/** 心智模型:所有入口最先读到的几句话。 */
|
|
10
|
+
export const MENTAL_MODEL = [
|
|
11
|
+
'Joplo is a player for pre-declared scenarios, not a free-form app prototype.',
|
|
12
|
+
'Inputs show the sample value typed by the current step (read-only); viewers cannot type their own.',
|
|
13
|
+
'Clicking the highlighted element plays the next declared step; other clicks only show a hint.',
|
|
14
|
+
'Results and errors come from scenario effects (set, toast, done), not from real logic or a backend.',
|
|
15
|
+
'Options (A/B) and cases (edge cases) are compared in the local board; only the picked option is published.',
|
|
16
|
+
];
|
|
17
|
+
/** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
|
|
18
|
+
export const START_ORDER = [
|
|
19
|
+
'Read npx joplo skill authoring; read cases before asking the user about edge cases; demo and components as needed.',
|
|
20
|
+
'With minimal code, write one happy path and one error-and-recovery scenario.',
|
|
21
|
+
'Run npx joplo check, then npx joplo dev; confirm typing, clicks, and layers really behave as intended in the board.',
|
|
22
|
+
'Extend to every option and every case agreed with the user; run check until 0 errors.',
|
|
23
|
+
'Give the user the board URL and a short list of what to check, then wait for their feedback.',
|
|
24
|
+
];
|
|
25
|
+
/** 最常见的坑:一句话 + 详细主题。 */
|
|
26
|
+
export const PITFALLS = [
|
|
27
|
+
['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'],
|
|
28
|
+
['Only catalog components and the listed HTML tags exist; <br/> is UNKNOWN_COMPONENT, so write \'Line 1\\nLine 2\' inside <Text>', 'components'],
|
|
29
|
+
['Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE', 'check'],
|
|
30
|
+
['No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)', 'authoring'],
|
|
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'],
|
|
33
|
+
['Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user', 'cases'],
|
|
34
|
+
['Never share or deploy without the user\'s go-ahead; free share links expire after 1 hour', 'publish'],
|
|
35
|
+
];
|
|
36
|
+
/** 中文触发词:技能 description 里的匹配文本,不是 CLI 界面文案(english-output 测试的白名单)。 */
|
|
37
|
+
const ZH_JOPLO = '功能原型、可交互演示、方案对比、给产品 / 设计 / 评审看的演示';
|
|
38
|
+
const ZH_FEEDBACK = '评审有结论了、按评审意见修改演示';
|
|
39
|
+
const JOPLO_DESCRIPTION = `Build clickable, replayable feature demos with Joplo (scripted scenarios in TSX, viewed in a local board) when the user wants a feature prototype, an interactive or clickable demo, an A/B comparison of options or edge cases, or a demo for product, design, or review (${ZH_JOPLO}), including in a repo without joplo.config.ts.`;
|
|
40
|
+
const FEEDBACK_DESCRIPTION = `Apply Joplo review results when reviewers have commented on or decided about a Joplo review link and the user says the review has conclusions or asks to update the demo as reviewed (${ZH_FEEDBACK}); pulls decisions with npx joplo feedback and writes them back into the source.`;
|
|
41
|
+
const list = (items) => items.map((s, i) => `${i + 1}. ${s}`);
|
|
42
|
+
function joploBody() {
|
|
43
|
+
return [
|
|
44
|
+
'# Joplo',
|
|
45
|
+
'',
|
|
46
|
+
...MENTAL_MODEL,
|
|
47
|
+
'',
|
|
48
|
+
'## When to use',
|
|
49
|
+
'- The user wants to think a feature through before building it: a prototype, clickable demo, A/B options, edge cases, or a walkthrough for product, design, or review.',
|
|
50
|
+
'- Not for production UI code, real backends, or demos where viewers type free input.',
|
|
51
|
+
'',
|
|
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.',
|
|
54
|
+
...list(START_ORDER).map(line => line.replace(/^(\d+)/, (_, n) => String(Number(n) + 1))),
|
|
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
|
+
'',
|
|
57
|
+
'## Common pitfalls',
|
|
58
|
+
...PITFALLS.map(([text, topic]) => `- ${text}. See npx joplo skill ${topic}.`),
|
|
59
|
+
'',
|
|
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
|
+
'After the user Alt+clicks a board element, run npx joplo selection and edit only that location.',
|
|
62
|
+
].join('\n');
|
|
63
|
+
}
|
|
64
|
+
function feedbackBody() {
|
|
65
|
+
return [
|
|
66
|
+
'# Joplo review feedback',
|
|
67
|
+
'',
|
|
68
|
+
'Reviewers open the review link from npx joplo share --review, compare every option, comment, and the owner decides. Decisions come back to you; apply them to the source.',
|
|
69
|
+
'',
|
|
70
|
+
'## When to use',
|
|
71
|
+
'- The user says the review has conclusions, or asks you to update the Joplo demo according to the review.',
|
|
72
|
+
'- Requires a project that was shared (.joplo/cloud.json) or a share id from the user.',
|
|
73
|
+
'',
|
|
74
|
+
'## Steps',
|
|
75
|
+
'1. npx joplo feedback --format json. It reads the review share in .joplo/cloud.json, else the main share; pass --share <id> for another. data.decisions are decisions not yet applied (id, kind, featureId, targetId, note); data.comments are unresolved comments with scenario, step, stepId, and element.',
|
|
76
|
+
'2. Apply each decision to the source:',
|
|
77
|
+
' - pick: set pick in features/<feature>/feature.ts to the option file name (targetId without the "<feature>." prefix).',
|
|
78
|
+
' - confirm_rule: set that rule to origin: \'user\', status: \'confirmed\'.',
|
|
79
|
+
' - reject_rule: rewrite the rule as the note says. If the note does not say what to do instead, set status: \'conflict\' and ask the user; do not guess.',
|
|
80
|
+
' - answer: delete the question and add a rule stating the answer with origin: \'user\', status: \'confirmed\'.',
|
|
81
|
+
' - Comments are discussion input only; change the source from a comment only when the user asks.',
|
|
82
|
+
'3. npx joplo check until 0 errors.',
|
|
83
|
+
'4. Republish when the user wants: npx joplo share --review --format json updates the review version (every option); npx joplo share --format json publishes picked options only.',
|
|
84
|
+
'5. npx joplo feedback --applied <decision ids, comma-separated> --ref <git commit sha>. Mark only decisions you actually wrote back.',
|
|
85
|
+
'',
|
|
86
|
+
'AUTH_REQUIRED or AUTH_EXPIRED (exit 3): ask the user to run npx joplo login in their own terminal; never log in or out for them.',
|
|
87
|
+
'Details: npx joplo skill publish (Review and feedback).',
|
|
88
|
+
].join('\n');
|
|
89
|
+
}
|
|
90
|
+
/** 官方技能与 `joplo skill install` 共用的两个技能(顺序即写入顺序)。 */
|
|
91
|
+
export function agentSkills() {
|
|
92
|
+
return [
|
|
93
|
+
{ name: 'joplo', description: JOPLO_DESCRIPTION, body: joploBody() },
|
|
94
|
+
{ name: 'joplo-feedback', description: FEEDBACK_DESCRIPTION, body: feedbackBody() },
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
/** SKILL.md 正文(不含版本标记):frontmatter + 正文,以换行结尾。 */
|
|
98
|
+
export function skillMarkdown(skill) {
|
|
99
|
+
return `---\nname: ${skill.name}\ndescription: ${skill.description}\n---\n${skill.body}\n`;
|
|
100
|
+
}
|
|
101
|
+
/** AGENTS.md 托管段(不含起止标记):心智模型、起步顺序、最常见的坑,细节指向主题。 */
|
|
102
|
+
export function agentsBlock() {
|
|
103
|
+
return [
|
|
104
|
+
'## Joplo',
|
|
105
|
+
'This project designs features as Joplo demos (joplo.config.ts). Read npx joplo skill first, then the relevant topics: authoring for pages/options/scenarios, components, cases before asking about edge cases, demo for layers, shots, traces, and captions.',
|
|
106
|
+
`Mental model: ${MENTAL_MODEL.slice(0, 4).join(' ')}`,
|
|
107
|
+
`Start: ${START_ORDER.map((s, i) => `(${i + 1}) ${s}`).join(' ')}`,
|
|
108
|
+
'Pitfalls:',
|
|
109
|
+
...PITFALLS.slice(0, 6).map(([text, topic]) => `- ${text} (npx joplo skill ${topic}).`),
|
|
110
|
+
'After editing, run npx joplo check. After a board selection, run npx joplo selection and edit only that location. Review results: npx joplo feedback (npx joplo skill publish).',
|
|
111
|
+
].join('\n');
|
|
112
|
+
}
|
package/dist/catalog.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* (packages/core/test/catalog.test.ts 与渲染器的类型检查保证)。目录之外的名称在编译时报错,不会被静默渲染。
|
|
7
7
|
* 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
|
|
8
8
|
*/
|
|
9
|
+
export declare const HTML_TAGS: readonly string[];
|
|
9
10
|
export declare const COMPONENT_TYPES: readonly ["AppShell", "AppShell.Header", "AppShell.Navbar", "AppShell.Main", "AppShell.Aside", "AppShell.Footer", "Container", "Stack", "Group", "Flex", "Grid", "Grid.Col", "SimpleGrid", "Center", "Box", "Space", "Paper", "Card", "Card.Section", "Divider", "ScrollArea", "Title", "Text", "Code", "Kbd", "Blockquote", "List", "List.Item", "Badge", "Avatar", "Image", "ThemeIcon", "Indicator", "Timeline", "Timeline.Item", "Table", "Table.Thead", "Table.Tbody", "Table.Tr", "Table.Th", "Table.Td", "DataTable", "Accordion", "Accordion.Item", "Accordion.Panel", "Radio", "Tabs.List", "Tabs.Panel", "Breadcrumbs", "Stepper", "Stepper.Step", "Alert", "Loader", "Progress", "RingProgress", "Skeleton", "Notification", "Modal", "Drawer", "ChatMessage", "ToolCall", "Thinking", "Artifact", "Email", "DataCard", "StateFlow", "Terminal", "Terminal.Command", "Terminal.Output", "Phone", "Diagram", "Diagram.Group", "Diagram.Node", "Diagram.Edge", "div", "span", "p", "h1", "h2", "h3", "h4", "main", "section", "header", "footer", "nav", "aside", "ul", "ol", "li", "strong", "em", "small", "code", "Placeholder", "Custom", "#text", "Button", "ActionIcon", "CloseButton", "Anchor", "a", "NavLink", "Burger", "TextInput", "PasswordInput", "NumberInput", "Textarea", "Select", "MultiSelect", "Checkbox", "Radio.Group", "Switch", "SegmentedControl", "FileInput", "Tabs", "Tabs.Tab", "Accordion.Control", "Pagination", "PromptInput", "Terminal.Input", "Artifact.Ref"];
|
|
10
11
|
export type ComponentType = (typeof COMPONENT_TYPES)[number];
|
|
11
12
|
export declare const INTERACTIVE_TYPES: ReadonlySet<string>;
|
package/dist/catalog.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* (packages/core/test/catalog.test.ts 与渲染器的类型检查保证)。目录之外的名称在编译时报错,不会被静默渲染。
|
|
7
7
|
* 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
|
|
8
8
|
*/
|
|
9
|
+
/** HTML 兜底标签(不可操作);`a` 在 INTERACTIVE 里。目录之外的标签(br、img、button、input…)报 UNKNOWN_COMPONENT。 */
|
|
10
|
+
const HTML = ['div', 'span', 'p', 'h1', 'h2', 'h3', 'h4', 'main', 'section', 'header', 'footer', 'nav', 'aside', 'ul', 'ol', 'li', 'strong', 'em', 'small', 'code'];
|
|
11
|
+
export const HTML_TAGS = [...HTML, 'a'];
|
|
9
12
|
/** 布局、展示与容器:不可操作。 */
|
|
10
13
|
const STRUCTURE = [
|
|
11
14
|
// 布局
|
|
@@ -29,7 +32,7 @@ const STRUCTURE = [
|
|
|
29
32
|
// 架构图(Joplo 自有,D41):节点与连线的 state 绑定 $.ui,由 flow 步骤驱动
|
|
30
33
|
'Diagram', 'Diagram.Group', 'Diagram.Node', 'Diagram.Edge',
|
|
31
34
|
// HTML 兜底
|
|
32
|
-
|
|
35
|
+
...HTML,
|
|
33
36
|
// Joplo
|
|
34
37
|
'Placeholder', // props: label, h —— 图片/图表等占位
|
|
35
38
|
'Custom', // props: kind —— 逃生口:目录没有的组件,渲染为带说明的占位框
|
package/dist/compile.d.ts
CHANGED
|
@@ -28,7 +28,8 @@ export type CompileResult = {
|
|
|
28
28
|
project: Project | null;
|
|
29
29
|
diagnostics: Diagnostic[];
|
|
30
30
|
};
|
|
31
|
-
export
|
|
31
|
+
export type CompileMode = 'dev' | 'publish' | 'review';
|
|
32
|
+
export declare function compile(src: AuthoringProject, mode: CompileMode): CompileResult;
|
|
32
33
|
/** 角色的颜色(D56):没写 color 时按声明顺序取。 */
|
|
33
34
|
export declare const ROLE_COLORS: readonly ["#E8590C", "#1971C2", "#2F9E44", "#9C36B5", "#C2255C", "#0C8599"];
|
|
34
35
|
export declare function relSource(root: string, s: string): string;
|
package/dist/compile.js
CHANGED
|
@@ -5,15 +5,20 @@
|
|
|
5
5
|
* - dev 模式:每个方案在每个路径上各有一个画面 `<方案>@<路径>`,其中其他功能取选定方案,本功能取该方案;
|
|
6
6
|
* 另有发布视图 `@<路径>`(全部取选定方案)。
|
|
7
7
|
* - publish 模式:只有发布视图;只含选定方案的场景;去掉规则、情况、问题等创作侧信息(D33)。
|
|
8
|
+
* - review 模式(评审版,D63):画面与场景同 dev(所有功能的所有方案),创作侧信息按 publish 的规则去掉。
|
|
8
9
|
*/
|
|
9
10
|
import { isBind, isNode, bindPath, toCondition } from '@joplo-app/kit/node';
|
|
10
11
|
import { BUILTIN_THEMES, COMPONENT_TYPES, DIRECTOR_LAYER, INTERACTIVE_TYPES, PAGE_LAYER, matchChoice, nodeLabel } from "./catalog.js";
|
|
11
12
|
import { choicesOf, commonPrefix } from "./player.js";
|
|
12
|
-
import { Project, SCHEMA_VERSION } from "./schema.js";
|
|
13
|
+
import { LAYER_ICONS, Project, SCHEMA_VERSION } from "./schema.js";
|
|
14
|
+
import { schemaDiagnostics } from "./schema-issues.js";
|
|
13
15
|
const KNOWN = new Set(COMPONENT_TYPES);
|
|
14
16
|
const OVERLAY = 'overlay';
|
|
15
17
|
const MOCK_LABEL = { success: 'Mock success', failure: 'Mock failure', denied: 'Mock permission denied', other: 'Mock' };
|
|
16
18
|
export function compile(src, mode) {
|
|
19
|
+
/** 所有方案都参与(dev、review);创作侧信息要去掉(publish、review)。 */
|
|
20
|
+
const allOpts = mode !== 'publish';
|
|
21
|
+
const strip = mode !== 'dev';
|
|
17
22
|
const diags = [];
|
|
18
23
|
const rel = (s) => (s ? relSource(src.root, s) : undefined);
|
|
19
24
|
const err = (code, message, at, ref) => diags.push({ severity: 'error', code, message, source: 'reference', ...(at ? { at: rel(at) } : {}), ...(ref ? { ref } : {}) });
|
|
@@ -27,6 +32,7 @@ export function compile(src, mode) {
|
|
|
27
32
|
mode,
|
|
28
33
|
routes: {},
|
|
29
34
|
features: {},
|
|
35
|
+
featureIds: [],
|
|
30
36
|
cases: {},
|
|
31
37
|
options: {},
|
|
32
38
|
rules: {},
|
|
@@ -34,9 +40,22 @@ export function compile(src, mode) {
|
|
|
34
40
|
scenarios: {},
|
|
35
41
|
issues: {},
|
|
36
42
|
};
|
|
43
|
+
// ---------- 1. 选出参与的方案 ----------
|
|
44
|
+
// 排序只在编译时决定;显式列表不依赖对象键的枚举顺序,发布模式也保留这份演示内容。
|
|
45
|
+
for (const [fid, f] of Object.entries(src.features)) {
|
|
46
|
+
if (f.def.order !== undefined && (typeof f.def.order !== 'number' || !Number.isFinite(f.def.order)))
|
|
47
|
+
err('FEATURE_ORDER_INVALID', `Feature ${fid} order must be a finite number; omit it for folder-name order`, f.def.source ?? `${f.def.file}:1:1`, { kind: 'feature', id: fid });
|
|
48
|
+
}
|
|
49
|
+
if (diags.some(d => d.severity === 'error'))
|
|
50
|
+
return { project: null, diagnostics: diags };
|
|
51
|
+
const natural = new Intl.Collator('en', { numeric: true });
|
|
52
|
+
const features = Object.entries(src.features).sort(([a, af], [b, bf]) => {
|
|
53
|
+
const ao = af.def.order ?? Infinity, bo = bf.def.order ?? Infinity;
|
|
54
|
+
return ao !== bo ? ao - bo : natural.compare(a, b);
|
|
55
|
+
});
|
|
37
56
|
const allOptions = [];
|
|
38
57
|
const picked = new Map(); // fid -> 选定方案
|
|
39
|
-
for (const [fid, f] of
|
|
58
|
+
for (const [fid, f] of features) {
|
|
40
59
|
for (const [key, def] of sortedEntries(f.options))
|
|
41
60
|
allOptions.push({ fid, key, qid: `${fid}.${key}`, def });
|
|
42
61
|
const pick = f.def.pick ?? null;
|
|
@@ -50,7 +69,7 @@ export function compile(src, mode) {
|
|
|
50
69
|
else if (mode === 'publish')
|
|
51
70
|
warn('NOT_PICKED', `Feature "${f.def.name}" has no picked option and will not be published`, f.def.source);
|
|
52
71
|
}
|
|
53
|
-
const included =
|
|
72
|
+
const included = allOpts ? allOptions : [...picked.values()];
|
|
54
73
|
const baseRoutes = new Map();
|
|
55
74
|
for (const [path, p] of sortedEntries(src.routes))
|
|
56
75
|
baseRoutes.set(path, { path, page: p });
|
|
@@ -97,10 +116,11 @@ export function compile(src, mode) {
|
|
|
97
116
|
};
|
|
98
117
|
}
|
|
99
118
|
// ---------- 3. 功能、情况、规则、问题 ----------
|
|
100
|
-
for (const [fid, f] of
|
|
119
|
+
for (const [fid, f] of features) {
|
|
101
120
|
const fdef = f.def;
|
|
102
121
|
if (mode === 'publish' && !picked.has(fid))
|
|
103
122
|
continue;
|
|
123
|
+
out.featureIds.push(fid);
|
|
104
124
|
const caseIds = Object.keys(fdef.cases ?? {}).map((k) => `${fid}.${k}`);
|
|
105
125
|
out.features[fid] = {
|
|
106
126
|
id: fid,
|
|
@@ -108,12 +128,12 @@ export function compile(src, mode) {
|
|
|
108
128
|
goal: fdef.goal,
|
|
109
129
|
roles: rolesOf(fdef.roles),
|
|
110
130
|
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
|
-
caseIds:
|
|
131
|
+
caseIds: strip ? [] : caseIds,
|
|
112
132
|
optionIds: included.filter((o) => o.fid === fid).map((o) => o.qid),
|
|
113
133
|
pick: picked.get(fid)?.qid ?? null,
|
|
114
134
|
...(fdef.source ? { source: rel(fdef.source) } : {}),
|
|
115
135
|
};
|
|
116
|
-
if (
|
|
136
|
+
if (strip)
|
|
117
137
|
continue;
|
|
118
138
|
for (const [k, c] of Object.entries(fdef.cases ?? {}))
|
|
119
139
|
out.cases[`${fid}.${k}`] = caseOf(`${fid}.${k}`, fid, c, rel(fdef.source));
|
|
@@ -184,7 +204,7 @@ export function compile(src, mode) {
|
|
|
184
204
|
};
|
|
185
205
|
for (const r of routesIn(null))
|
|
186
206
|
addScene(composeScene(r, null));
|
|
187
|
-
if (
|
|
207
|
+
if (allOpts)
|
|
188
208
|
for (const o of included)
|
|
189
209
|
for (const r of routesIn(o))
|
|
190
210
|
addScene(composeScene(r, o));
|
|
@@ -197,7 +217,7 @@ export function compile(src, mode) {
|
|
|
197
217
|
for (const p of Object.keys(def.on ?? {}))
|
|
198
218
|
if (!ctxRoutes.has(p))
|
|
199
219
|
err('UNKNOWN_ROUTE', `Option ${qid} adds elements to an unknown route ${p}`, def.source);
|
|
200
|
-
const sceneOf = (path) => (
|
|
220
|
+
const sceneOf = (path) => (allOpts ? `${qid}@${path}` : `@${path}`);
|
|
201
221
|
if (mode === 'dev') {
|
|
202
222
|
for (const [k, r] of Object.entries(def.rules ?? {}))
|
|
203
223
|
out.rules[`${qid}.${k}`] = ruleOf(`${qid}.${k}`, fid, qid, r, rel);
|
|
@@ -239,7 +259,11 @@ export function compile(src, mode) {
|
|
|
239
259
|
layerScenes.push({ key: lk, scene });
|
|
240
260
|
if (ld.role !== undefined && !roleKeys.has(ld.role))
|
|
241
261
|
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
|
-
|
|
262
|
+
const icon = ld.icon;
|
|
263
|
+
const iconOk = icon !== undefined && LAYER_ICONS.includes(icon);
|
|
264
|
+
if (icon !== undefined && !iconOk)
|
|
265
|
+
err('ICON_UNKNOWN', `Layer "${ld.title}" icon "${icon}" is not a preset icon (available: ${LAYER_ICONS.join(', ')})`, at);
|
|
266
|
+
layers[lk] = { title: ld.title, sceneId, ...(ld.role !== undefined && roleKeys.has(ld.role) ? { role: ld.role } : {}), ...(iconOk ? { icon: icon } : {}) };
|
|
243
267
|
}
|
|
244
268
|
const hasLayers = layerScenes.length > 0;
|
|
245
269
|
/** 元素在哪些层级里(多层都有同名 id 时都算)。 */
|
|
@@ -442,7 +466,7 @@ export function compile(src, mode) {
|
|
|
442
466
|
caption: st.caption ?? generated.caption,
|
|
443
467
|
...(generated?.captionAuto ? { captionAuto: generated.captionAuto } : {}),
|
|
444
468
|
effects,
|
|
445
|
-
ruleIds:
|
|
469
|
+
ruleIds: strip ? [] : ruleIds,
|
|
446
470
|
shots,
|
|
447
471
|
directorLayer,
|
|
448
472
|
...(explains.length ? { explain: explains.join('\n') } : {}),
|
|
@@ -459,7 +483,7 @@ export function compile(src, mode) {
|
|
|
459
483
|
optionId: qid,
|
|
460
484
|
name: fl.name,
|
|
461
485
|
description: fl.opts.description ?? '',
|
|
462
|
-
caseIds:
|
|
486
|
+
caseIds: strip ? [] : (fl.opts.cases ?? []).filter((c) => fdef.cases?.[c]).map((c) => `${fid}.${c}`),
|
|
463
487
|
mock: { label: fl.opts.mock ?? MOCK_LABEL[outcome], outcome, ...(fl.opts.mock === undefined ? { auto: true } : {}) },
|
|
464
488
|
initial: { sceneId: sceneOf(start), ui: state.ui, data: state.data, inputs: state.inputs },
|
|
465
489
|
steps,
|
|
@@ -501,8 +525,8 @@ export function compile(src, mode) {
|
|
|
501
525
|
key: o.key,
|
|
502
526
|
name: def.name,
|
|
503
527
|
idea: def.idea,
|
|
504
|
-
decisionFocus:
|
|
505
|
-
tradeoffs:
|
|
528
|
+
decisionFocus: strip ? '' : (def.focus ?? ''),
|
|
529
|
+
tradeoffs: strip ? [] : (def.tradeoffs ?? []),
|
|
506
530
|
routes: touched,
|
|
507
531
|
coverage,
|
|
508
532
|
layers,
|
|
@@ -519,8 +543,8 @@ export function compile(src, mode) {
|
|
|
519
543
|
err('UNKNOWN_CASE', `Rule "${r.text}" links unknown case ${c}`, r.source);
|
|
520
544
|
}
|
|
521
545
|
}
|
|
522
|
-
// ---------- 7.
|
|
523
|
-
if (
|
|
546
|
+
// ---------- 7. 发布视图与评审版:去掉设计备注与源位置 ----------
|
|
547
|
+
if (strip) {
|
|
524
548
|
for (const s of Object.values(out.scenes))
|
|
525
549
|
stripNotes(s.root);
|
|
526
550
|
stripSources(out);
|
|
@@ -529,8 +553,8 @@ export function compile(src, mode) {
|
|
|
529
553
|
return { project: null, diagnostics: diags };
|
|
530
554
|
const parsed = Project.safeParse(out);
|
|
531
555
|
if (!parsed.success) {
|
|
532
|
-
|
|
533
|
-
|
|
556
|
+
// 同一根因(共享的 JSX)在多个画面展开时合并成一条,定位到作者元素(schema-issues.ts)
|
|
557
|
+
diags.push(...schemaDiagnostics(out, parsed.error.issues, { limit: 20, rel }));
|
|
534
558
|
return { project: null, diagnostics: diags };
|
|
535
559
|
}
|
|
536
560
|
return { project: parsed.data, diagnostics: diags };
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 嵌入模式(发布站 `?embed=1`)与 `joplo share` 预览图共用的场景选择(纯函数)。
|
|
3
|
+
*
|
|
4
|
+
* - 可播放的场景:按功能在 IR 里的顺序,每个功能的选定方案(没有选定时用第一个方案)的场景,按场景在 IR 里的顺序;
|
|
5
|
+
* - 默认场景是其中第一个;`scenario` 参数指向列表里的场景时从它开始,写错(不存在、为空、不是字符串)时退回默认,不报错。
|
|
6
|
+
*
|
|
7
|
+
* 只读 features / options / scenarios 的少量字段,所以既能用于完整 IR,也能用于发布站内联的发布 IR。
|
|
8
|
+
*/
|
|
9
|
+
type EmbedProject = {
|
|
10
|
+
featureIds?: readonly string[];
|
|
11
|
+
features: Record<string, {
|
|
12
|
+
id: string;
|
|
13
|
+
optionIds: readonly string[];
|
|
14
|
+
pick?: string | null;
|
|
15
|
+
}>;
|
|
16
|
+
options: Record<string, {
|
|
17
|
+
id: string;
|
|
18
|
+
}>;
|
|
19
|
+
scenarios: Record<string, {
|
|
20
|
+
id: string;
|
|
21
|
+
optionId: string;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
/** 嵌入模式里可以播放和切换的场景 ID(有序、不重复)。 */
|
|
25
|
+
export declare function embedScenarioIds(project: EmbedProject): string[];
|
|
26
|
+
/** 嵌入从哪个场景开始:requested 合法时用它,否则用默认场景;项目没有场景时为 null。 */
|
|
27
|
+
export declare function embedStartScenario(project: EmbedProject, requested?: unknown): string | null;
|
|
28
|
+
export {};
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 嵌入模式(发布站 `?embed=1`)与 `joplo share` 预览图共用的场景选择(纯函数)。
|
|
3
|
+
*
|
|
4
|
+
* - 可播放的场景:按功能在 IR 里的顺序,每个功能的选定方案(没有选定时用第一个方案)的场景,按场景在 IR 里的顺序;
|
|
5
|
+
* - 默认场景是其中第一个;`scenario` 参数指向列表里的场景时从它开始,写错(不存在、为空、不是字符串)时退回默认,不报错。
|
|
6
|
+
*
|
|
7
|
+
* 只读 features / options / scenarios 的少量字段,所以既能用于完整 IR,也能用于发布站内联的发布 IR。
|
|
8
|
+
*/
|
|
9
|
+
import { orderedFeatures } from "./features.js";
|
|
10
|
+
/** 嵌入模式里可以播放和切换的场景 ID(有序、不重复)。 */
|
|
11
|
+
export function embedScenarioIds(project) {
|
|
12
|
+
const ids = [];
|
|
13
|
+
const scenarios = Object.values(project.scenarios ?? {});
|
|
14
|
+
for (const f of orderedFeatures(project)) {
|
|
15
|
+
const optionIds = (f.optionIds ?? []).filter((id) => project.options?.[id]);
|
|
16
|
+
const optionId = f.pick && project.options?.[f.pick] ? f.pick : optionIds[0];
|
|
17
|
+
if (!optionId)
|
|
18
|
+
continue;
|
|
19
|
+
for (const s of scenarios)
|
|
20
|
+
if (s.optionId === optionId && !ids.includes(s.id))
|
|
21
|
+
ids.push(s.id);
|
|
22
|
+
}
|
|
23
|
+
return ids;
|
|
24
|
+
}
|
|
25
|
+
/** 嵌入从哪个场景开始:requested 合法时用它,否则用默认场景;项目没有场景时为 null。 */
|
|
26
|
+
export function embedStartScenario(project, requested) {
|
|
27
|
+
const ids = embedScenarioIds(project);
|
|
28
|
+
if (typeof requested === 'string' && requested && ids.includes(requested))
|
|
29
|
+
return requested;
|
|
30
|
+
return ids[0] ?? null;
|
|
31
|
+
}
|
package/dist/features.js
ADDED
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: "Mental model, first steps, page / option / flow syntax, when conditions, a form example";
|
|
4
4
|
}, {
|
|
5
5
|
readonly name: "demo";
|
|
6
|
-
readonly description: "Layers, shots,
|
|
6
|
+
readonly description: "Layers, shots, captions, full-height layout, deep links, and screenshots";
|
|
7
7
|
}, {
|
|
8
8
|
readonly name: "components";
|
|
9
|
-
readonly description: "Component catalog
|
|
9
|
+
readonly description: "Component catalog, supported HTML tags, line breaks, and props";
|
|
10
10
|
}, {
|
|
11
11
|
readonly name: "cases";
|
|
12
12
|
readonly description: "Case dimensions: ask the user before starting";
|
|
13
13
|
}, {
|
|
14
14
|
readonly name: "check";
|
|
15
|
-
readonly description: "Read diagnostics and fix the indicated file and line";
|
|
15
|
+
readonly description: "Read diagnostics, UNBOUND_INTERACTIVE, and fix the indicated file and line";
|
|
16
16
|
}, {
|
|
17
17
|
readonly name: "selection";
|
|
18
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, build,
|
|
21
|
+
readonly description: "pick, build, share, review version, feedback write-back, deployment";
|
|
22
22
|
}];
|
|
23
23
|
export type SkillTopic = (typeof SKILL_TOPICS)[number]['name'];
|
|
24
24
|
/** CLI 传入其 package.json 版本;行数来自同一次生成的主题正文。 */
|