@joplo-app/core 0.2.6 → 0.2.8

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.
@@ -9,9 +9,9 @@
9
9
  /** 心智模型:所有入口最先读到的几句话。 */
10
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
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."];
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.", "Plan before coding (npx joplo skill story): audience, one to three points, one line per scenario (Given → When → Then, how it opens and ends; a case's expected is its Then); show the plan to the user. A demo is a story, not a feature tour.", "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;
@@ -17,6 +17,7 @@ export const MENTAL_MODEL = [
17
17
  /** 推荐的起步顺序(X2:先做最小的一条正常流程 + 一条错误恢复流程,在看板里确认交互模型后再扩展)。 */
18
18
  export const START_ORDER = [
19
19
  'Read npx joplo skill authoring; read cases before asking the user about edge cases; demo and components as needed.',
20
+ 'Plan before coding (npx joplo skill story): audience, one to three points, one line per scenario (Given → When → Then, how it opens and ends; a case\'s expected is its Then); show the plan to the user. A demo is a story, not a feature tour.',
20
21
  'With minimal code, write one happy path and one error-and-recovery scenario.',
21
22
  'Run npx joplo check, then npx joplo dev; confirm typing, clicks, and layers really behave as intended in the board.',
22
23
  'Extend to every option and every case agreed with the user; run check until 0 errors.',
@@ -29,7 +30,7 @@ export const PITFALLS = [
29
30
  ['Every interactive element needs a flow step, disabled={true} with disabledReason, or unmodeled; otherwise check warns UNBOUND_INTERACTIVE', 'check'],
30
31
  ['No onClick or other function props: behavior lives in flow steps (.click/.type/.select) and effects (set, push, go, done)', 'authoring'],
31
32
  ['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
+ ['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
34
  ['Rules you assume stay origin ai_assumption, status pending; never mark them confirmed for the user', 'cases'],
34
35
  ['Never share or deploy without the user\'s go-ahead; free share links expire after 1 hour', 'publish'],
35
36
  ];
@@ -50,15 +51,16 @@ function joploBody() {
50
51
  '- Not for production UI code, real backends, or demos where viewers type free input.',
51
52
  '',
52
53
  '## 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
+ '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
55
  ...list(START_ORDER).map(line => line.replace(/^(\d+)/, (_, n) => String(Number(n) + 1))),
55
56
  `${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
  '',
57
58
  '## Common pitfalls',
58
59
  ...PITFALLS.map(([text, topic]) => `- ${text}. See npx joplo skill ${topic}.`),
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
+ 'Exact APIs: npx joplo skill <topic> prints guidance matching the installed version (authoring, story, demo, focus, diagram, components, cases, check, selection, publish). Run npx joplo skill for the overview; npx joplo components <Name> shows props and an example.',
61
62
  'After the user Alt+clicks a board element, run npx joplo selection and edit only that location.',
63
+ '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
64
  ].join('\n');
63
65
  }
64
66
  function feedbackBody() {
@@ -102,7 +104,7 @@ export function skillMarkdown(skill) {
102
104
  export function agentsBlock() {
103
105
  return [
104
106
  '## 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.',
107
+ 'This project designs features as Joplo demos (joplo.config.ts). Read npx joplo skill first, then the relevant topics: authoring for pages/options/scenarios, story for planning a demo and writing captions, components, cases before asking about edge cases, demo for layers, shots, traces, and captions, focus for where viewers look in each step, diagram for architecture, sequence, and state diagrams.',
106
108
  `Mental model: ${MENTAL_MODEL.slice(0, 4).join(' ')}`,
107
109
  `Start: ${START_ORDER.map((s, i) => `(${i + 1}) ${s}`).join(' ')}`,
108
110
  'Pitfalls:',
package/dist/catalog.d.ts CHANGED
@@ -7,21 +7,29 @@
7
7
  * 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
8
8
  */
9
9
  export declare const HTML_TAGS: readonly string[];
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
+ 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", "StateMachine", "StateMachine.Group", "StateMachine.State", "StateMachine.Transition", "Sequence", "Sequence.Group", "Sequence.Actor", "Sequence.Message", "Sequence.Block", "Avatar.Group", "Radio.Card", "EmptyState", "ListRow", "Stat", "KeyValue", "BarChart", "LineChart", "Menu", "Menu.Target", "Menu.Dropdown", "Menu.Label", "Menu.Divider", "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", "Menu.Item", "TabBar"];
11
11
  export type ComponentType = (typeof COMPONENT_TYPES)[number];
12
12
  export declare const INTERACTIVE_TYPES: ReadonlySet<string>;
13
13
  /** 可接收输入值;type/select/toggle 动作写入 state.inputs[nodeId]。 */
14
14
  export declare const VALUE_TYPES: ReadonlySet<string>;
15
- /** 只有 opened(兼容旧写法 open)为真时自身和子节点才可见的浮层。 */
15
+ /**
16
+ * 只有 opened(兼容旧写法 open)为真时自身和子节点才可见的浮层。
17
+ * Menu.Dropdown(D68):作者把 opened 写在 Menu 上(与 Mantine 一致),编译器把它抄到菜单里的 Menu.Dropdown 上。
18
+ */
16
19
  export declare const GATED_CONTAINERS: ReadonlySet<string>;
17
20
  /** Joplo 在 Mantine 属性之外追加的属性,编译器会从 props 中取出,放到节点字段上。 */
18
- export declare const JOPLO_PROPS: readonly ["id", "when", "disabledReason", "unmodeled", "note"];
21
+ export declare const JOPLO_PROPS: readonly ["id", "when", "disabledReason", "unmodeled", "note", "redact"];
19
22
  /**
20
23
  * 每个组件一行常用属性提示(`joplo skill components` 由此生成)。所有组件另外都接受:
21
24
  * 样式属性 m/mt/mb/ml/mr/mx/my、p/pt/pb/pl/pr/px/py、w/h/miw/maw/mih/mah、c/bg/fz/fw/ta/ff/lh/opacity,
22
25
  * 响应式写成 { base, xs, sm, md, lg, xl };visibleFrom / hiddenFrom;以及 Joplo 属性 id/when/disabled/disabledReason/unmodeled/note。
23
26
  */
24
27
  export declare const COMPONENT_DOCS: Record<ComponentType, string>;
28
+ /**
29
+ * 示例(D68,`npx joplo components <名字>` 输出):每个都能直接放进页面或层级里用;交互状态写成 $.ui / $.data 绑定,由步骤 set()。
30
+ * 只给最容易写错、或需要和步骤配合的组件;其余组件看 COMPONENT_DOCS 的一行提示就够。
31
+ */
32
+ export declare const COMPONENT_EXAMPLES: Partial<Record<ComponentType, string>>;
25
33
  /** Mantine 默认断点:36/48/62/75/88em,按 16px 换算。 */
26
34
  export declare const BREAKPOINTS: {
27
35
  readonly xs: 576;
@@ -70,12 +78,20 @@ export declare function captionLength(s: string): number;
70
78
  /** 说明 / explain 的建议上限(超过时 check 报 CAPTION_TOO_LONG / EXPLAIN_TOO_LONG)。 */
71
79
  export declare const CAPTION_MAX = 24;
72
80
  export declare const EXPLAIN_MAX = 48;
81
+ /**
82
+ * 叙事提示(D67,见 docs/research/storytelling-and-demos.md):
83
+ * - 封面说明(flow 的 description):D61 定为 30 字以内,超过时 DESCRIPTION_TOO_LONG;
84
+ * - 过渡卡:副标题与 explain 同上限、每条要点与说明同上限、最多 4 条要点,超过时 CARD_TEXT_TOO_LONG(info);
85
+ * - 单个场景按 1× 估算超过 90 秒时 SCENARIO_TOO_LONG(info):一个场景讲一件事,长流程拆成几个场景或用 fork。
86
+ */
87
+ export declare const DESCRIPTION_MAX = 30;
88
+ export declare const CARD_POINTS_MAX = 4;
89
+ export declare const SCENARIO_MS_MAX = 90000;
73
90
  /** 没有声明 layers 的方案:镜头作用在路径页面上,记为这个伪层级(不出现在层级栏)。作者的层级键不能以 @ 开头。 */
74
91
  export declare const PAGE_LAYER = "@page";
75
92
  /** shot()(不带 id)在有层级的方案里:作用于“当时导演所在的层”,让它回到整体。 */
76
93
  export declare const DIRECTOR_LAYER = "@director";
77
- /** Diagram.Node 的 kind 与 Node / Edge 的 state(D41)。 */
78
- export declare const DIAGRAM_NODE_KINDS: readonly ["client", "service", "model", "database", "queue", "storage", "external", "tool", "user"];
94
+ /** Diagram 节点与连线的 state(D41);节点 kind 等见 diagram/model.ts。 */
79
95
  export declare const DIAGRAM_STATES: readonly ["idle", "active", "ok", "error", "dim"];
80
96
  /** 子节点排版用的宽度:Phone 内部按手机宽度(响应式取值、visibleFrom / hiddenFrom、AppShell 收起都按它算),其余节点沿用外部宽度。 */
81
97
  export declare function childWidth(type: string, width: number): number;
package/dist/catalog.js CHANGED
@@ -29,8 +29,13 @@ const STRUCTURE = [
29
29
  'ChatMessage', 'ToolCall', 'Thinking', 'Artifact', 'Email', 'DataCard', 'StateFlow',
30
30
  // 设备外框(Joplo 自有):终端与手机
31
31
  'Terminal', 'Terminal.Command', 'Terminal.Output', 'Phone',
32
- // 架构图(Joplo 自有,D41):节点与连线的 state 绑定 $.ui,由 flow 步骤驱动
32
+ // 关系类图表(Joplo 自有,D41 / D69):布局在编译期算好;节点与连线的状态由 flow 步骤的 trace() 推算
33
33
  'Diagram', 'Diagram.Group', 'Diagram.Node', 'Diagram.Edge',
34
+ 'StateMachine', 'StateMachine.Group', 'StateMachine.State', 'StateMachine.Transition',
35
+ 'Sequence', 'Sequence.Group', 'Sequence.Actor', 'Sequence.Message', 'Sequence.Block',
36
+ // 产品界面(D68):官网示例里反复手拼的常见界面,名字能对齐 Mantine 的就对齐(Menu、Avatar.Group、Radio.Card、BarChart、LineChart)
37
+ 'Avatar.Group', 'Radio.Card', 'EmptyState', 'ListRow', 'Stat', 'KeyValue', 'BarChart', 'LineChart',
38
+ 'Menu', 'Menu.Target', 'Menu.Dropdown', 'Menu.Label', 'Menu.Divider',
34
39
  // HTML 兜底
35
40
  ...HTML,
36
41
  // Joplo
@@ -44,18 +49,23 @@ const INTERACTIVE = [
44
49
  'TextInput', 'PasswordInput', 'NumberInput', 'Textarea', 'Select', 'MultiSelect', 'Checkbox', 'Radio.Group', 'Switch',
45
50
  'SegmentedControl', 'FileInput', 'Tabs', 'Tabs.Tab', 'Accordion.Control', 'Pagination', 'PromptInput', 'Terminal.Input',
46
51
  'Artifact.Ref',
52
+ // 产品界面(D68)
53
+ 'Menu.Item', 'TabBar',
47
54
  ];
48
55
  export const COMPONENT_TYPES = [...STRUCTURE, ...INTERACTIVE];
49
56
  export const INTERACTIVE_TYPES = new Set(INTERACTIVE);
50
57
  /** 可接收输入值;type/select/toggle 动作写入 state.inputs[nodeId]。 */
51
58
  export const VALUE_TYPES = new Set([
52
59
  'TextInput', 'PasswordInput', 'NumberInput', 'Textarea', 'Select', 'MultiSelect', 'Checkbox', 'Radio.Group', 'Switch',
53
- 'SegmentedControl', 'FileInput', 'Tabs', 'Accordion', 'Pagination', 'PromptInput', 'Terminal.Input',
60
+ 'SegmentedControl', 'FileInput', 'Tabs', 'Accordion', 'Pagination', 'PromptInput', 'Terminal.Input', 'TabBar',
54
61
  ]);
55
- /** 只有 opened(兼容旧写法 open)为真时自身和子节点才可见的浮层。 */
56
- export const GATED_CONTAINERS = new Set(['Modal', 'Drawer']);
62
+ /**
63
+ * 只有 opened(兼容旧写法 open)为真时自身和子节点才可见的浮层。
64
+ * Menu.Dropdown(D68):作者把 opened 写在 Menu 上(与 Mantine 一致),编译器把它抄到菜单里的 Menu.Dropdown 上。
65
+ */
66
+ export const GATED_CONTAINERS = new Set(['Modal', 'Drawer', 'Menu.Dropdown']);
57
67
  /** Joplo 在 Mantine 属性之外追加的属性,编译器会从 props 中取出,放到节点字段上。 */
58
- export const JOPLO_PROPS = ['id', 'when', 'disabledReason', 'unmodeled', 'note'];
68
+ export const JOPLO_PROPS = ['id', 'when', 'disabledReason', 'unmodeled', 'note', 'redact'];
59
69
  /**
60
70
  * 每个组件一行常用属性提示(`joplo skill components` 由此生成)。所有组件另外都接受:
61
71
  * 样式属性 m/mt/mb/ml/mr/mx/my、p/pt/pb/pl/pr/px/py、w/h/miw/maw/mih/mah、c/bg/fz/fw/ta/ff/lh/opacity,
@@ -94,7 +104,7 @@ export const COMPONENT_DOCS = {
94
104
  Avatar: 'name (shows first character), src, color, radius, size',
95
105
  Image: 'src, alt, h, w, radius; renders a placeholder with alt',
96
106
  ThemeIcon: 'color, variant, size, radius; one character as child',
97
- Indicator: 'label, color, disabled; wraps one element with a corner badge',
107
+ Indicator: 'label, color, disabled (hides the badge; can be a condition), processing; wraps one element with a corner badge',
98
108
  Timeline: 'active (completed item index), bulletSize; Timeline.Item children',
99
109
  'Timeline.Item': 'title, bullet; description in children',
100
110
  Table: 'data={{ head: [...], body: [[...]] }} or Table.Thead/Tbody/Tr/Th/Td; striped, withTableBorder',
@@ -103,7 +113,7 @@ export const COMPONENT_DOCS = {
103
113
  'Table.Tr': 'Row',
104
114
  'Table.Th': 'Header cell',
105
115
  'Table.Td': 'Cell',
106
- DataTable: 'records (can bind $.data.x), columns: [{ accessor, title }], noRecordsText; matches mantine-datatable',
116
+ DataTable: 'records (can bind $.data.x), columns: [{ accessor, title, textAlign, width, sortable, badge: true | { value: color }, avatar: true }], sortStatus: { columnAccessor, direction: asc|desc } (arrow only; set sorted records yourself), selectedRecords (ids, checkbox column), idAccessor (default id), fetching (loading overlay), noRecordsText; matches mantine-datatable',
107
117
  Accordion: 'value / defaultValue (expanded item); select sets the expanded item; Accordion.Item children',
108
118
  'Accordion.Item': 'value; contains Accordion.Control and Accordion.Panel',
109
119
  'Accordion.Panel': 'Content shown when expanded',
@@ -113,12 +123,12 @@ export const COMPONENT_DOCS = {
113
123
  Breadcrumbs: 'separator; Anchor or text children',
114
124
  Stepper: 'active (zero-based); Stepper.Step children',
115
125
  'Stepper.Step': 'label, description; step content in children (only current step shown)',
116
- Alert: 'title, color (default blue), variant; description in children',
126
+ Alert: 'title, color (default blue), variant, icon (character), withCloseButton; description in children',
117
127
  Loader: 'size, color, type; optional child text',
118
128
  Progress: 'value 0-100, color, size, striped',
119
129
  RingProgress: 'sections: [{ value, color }], label, size, thickness',
120
- Skeleton: 'h, w, circle, radius, visible',
121
- Notification: 'title, color, loading, withCloseButton; inline notification (use step toast for temporary messages)',
130
+ Skeleton: 'h, w, circle, radius, visible (false shows children), animate (pulse, default true)',
131
+ Notification: 'title, color, icon (character), loading, withCloseButton, position: top|top-left|top-right|bottom|bottom-left|bottom-right (floats over the page; show it with when); inline without position; Buttons in children (e.g. Undo)',
122
132
  Modal: 'opened (gated, usually opened={$.ui.open}), title, size, centered, fullScreen',
123
133
  Drawer: 'opened (gated), title, position: left|right|top|bottom (default left), size',
124
134
  ChatMessage: "from: 'user'|'assistant', name; message content in children (preserves newlines)",
@@ -129,10 +139,19 @@ export const COMPONENT_DOCS = {
129
139
  Thinking: 'title (current thought; can bind $.ui.x), active (thinking: title pulses), duration (shows "Thought for …" when finished), opened (expands the process); thinking process in children',
130
140
  Artifact: "title, kind: 'doc'|'code'|'sheet'|'web'|'image', status: 'generating'|'ready'|'error', version; Agent artifact side panel, content in children",
131
141
  Terminal: 'title; terminal window (CLI prototype), Terminal.Command / Terminal.Output / Terminal.Input children; scrolls internally when content exceeds h or mah',
132
- Diagram: "direction: 'right'|'down' (default right), h (height, default 420); architecture diagram with Diagram.Group / Diagram.Node / Diagram.Edge children; automatic deterministic layout (state changes do not move nodes); scales the whole diagram to fit without scrolling; inspect details with shared demo zoom/pan (wheel / pinch / drag) or shots; orthogonal edges with port and parallel segment spacing ≥ 10px; a shot of 2+ nodes (or one edge) in the same diagram centers them in a compact focused subgraph; use direction='down' for many nodes in limited width. Progressive reveal: set when={$.ui.x} on Group / Node / Edge and set true in flow (layout precomputed from all elements, existing elements stay fixed); describe calls with step trace(), which derives node/edge state",
133
- 'Diagram.Group': 'label; titled group box with Diagram.Node or nested Diagram.Group children',
134
- 'Diagram.Node': "id (required for edges and trace), label, description (small second line), kind: 'client'|'service'|'model'|'database'|'queue'|'storage'|'external'|'tool'|'user', optional state: 'idle'|'active'|'ok'|'error'|'dim'; omitted state is derived from step trace(); explicit state overrides it",
135
- 'Diagram.Edge': "from, to (Node ids in the same Diagram), label, async (dashed), optional state: 'idle'|'active'|'ok'|'error'|'dim'; id defaults to \"from->to\". Use trace('app', 'biz') in steps (this edge becomes active, then ok), trace.fail(...) (error), trace.skip(...) (dim), without manual state; for multiple edges in the same direction use trace('edge_id')",
142
+ Diagram: "h (height, default 420; h=\"100%\" fills a layer), direction: 'right'|'down' (omit it: chosen to fit the stage), aspect (target width/height); architecture / relationship diagram. Layout is computed at compile time (ELK layered with groups, orthogonal edges), deterministic, and identical in every step: state, when and trace never move nodes. Group nodes by business domain with Diagram.Group. Details: npx joplo skill diagram",
143
+ 'Diagram.Group': "id (required when referenced), label, icon (preset: client|service|model|database|queue|storage|external|tool|user|cloud|gateway|lock|network|device|box|brain), tone: gray|blue|green|orange|red|purple|teal, group (parent group id, instead of nesting), pin: 'start'|'end'; nestable; edges may connect to a group; a trace through its nodes highlights it",
144
+ 'Diagram.Node': "id (required for edges and trace), label, description (small second line), kind: 'client'|'service'|'model'|'database'|'queue'|'storage'|'external'|'tool'|'user', group (group id, instead of nesting), pin: 'start'|'end' (first / last layer within its group); optional state: 'idle'|'active'|'ok'|'error'|'dim' (omit it: trace() derives state)",
145
+ 'Diagram.Edge': "from, to (Node or Group ids in the same Diagram), label, async (dashed), optional state; id defaults to \"from->to\". Use trace('app', 'biz') in steps (active, then ok), trace.fail(...) (error), trace.skip(...) (dim); for multiple edges in the same direction use trace('edge_id')",
146
+ StateMachine: "direction: 'right'|'down' (omit it: chosen to fit the stage), h, aspect, value (current state id, usually value={$.data.order.status}); lifecycle diagram with StateMachine.State / StateMachine.Transition / StateMachine.Group; the current state is highlighted and the transition taken this step lights up. Details: npx joplo skill diagram",
147
+ 'StateMachine.Group': 'id, label, icon, tone, group; composite state box (substates inside)',
148
+ 'StateMachine.State': 'id (required), label, description, initial (start dot points to it), final (double border), group, pin',
149
+ 'StateMachine.Transition': "from, to (state ids), label (event [guard] / action); id defaults to \"from->to\" (\"from->to~2\" for repeats); trace('paid', 'shipped') or trace('transition_id')",
150
+ Sequence: 'h, numbered (default true: messages numbered in source order); sequence diagram: lifelines in source order, one row per message; trace message ids to light rows. Details: npx joplo skill diagram',
151
+ 'Sequence.Group': 'id, label, icon; box around participant columns (business domain)',
152
+ 'Sequence.Actor': "id (required), label, description, kind (same kinds as Diagram.Node); a participant column",
153
+ 'Sequence.Message': "id (recommended for trace), from, to (actor ids; from === to is a self call), label, reply (dashed return), async (open arrow); rows follow source order",
154
+ 'Sequence.Block': "label, kind: 'alt'|'opt'|'loop'|'par'|'break'|'critical' (default opt); fragment box around the messages inside it; nestable",
136
155
  'Terminal.Command': 'prompt (default "$"); command text in children',
137
156
  'Terminal.Output': "tone: 'plain'|'ok'|'warn'|'error' (default plain); output text in children (preserves newlines)",
138
157
  Phone: 'scale (visual scale, default 1), h (screen height, default 844); phone frame, children laid out at mobile width 390 with breakpoints based on that width; viewport: "mobile" on a page adds it automatically; do not add Phone explicitly',
@@ -156,15 +175,28 @@ export const COMPONENT_DOCS = {
156
175
  em: 'HTML fallback; prefer Text fs="italic" span',
157
176
  small: 'HTML fallback; prefer Text size="xs"',
158
177
  code: 'HTML fallback; prefer Code',
178
+ 'Avatar.Group': 'spacing (overlap, default sm); Avatar children shown as an overlapping stack',
179
+ 'Radio.Card': 'value, label, description, leftSection (character); selectable card inside Radio.Group (select writes the group value)',
180
+ EmptyState: 'icon (character), title, description, withBorder, color; empty lists, 404 / expired / no-access pages, result pages; action Buttons in children',
181
+ ListRow: 'avatar (name) or icon (character), title, description, active, withBorder, color; list row with right-side content (Badge, Button, Text) in children; not clickable itself: use NavLink for a tappable row',
182
+ Stat: 'label, value, diff (e.g. "+12%", red when it starts with -), description, icon, color, progress (0-100); KPI card',
183
+ KeyValue: 'items: [{ label, value }] (values can bind $.data.x), total (bold last row), withDivider; order summary / details list',
184
+ BarChart: 'data: [{ month: "Jan", signups: 40 }] (can bind $.data.x), dataKey (x axis), series: [{ name, label?, color? }], h (default 220), unit, withLegend; low-fi bars, values animate when data changes',
185
+ LineChart: 'same props as BarChart; low-fi lines with points',
186
+ Menu: 'opened (usually opened={$.ui.menu}; dropdown shows only when true), position: bottom-start|bottom-end|top-start|top-end; Menu.Target + Menu.Dropdown children',
187
+ 'Menu.Target': 'Wraps the trigger (ActionIcon or Button with its own id)',
188
+ 'Menu.Dropdown': 'Menu items; visible only while the Menu is opened; floats above tables and cards',
189
+ 'Menu.Label': 'Section label inside Menu.Dropdown',
190
+ 'Menu.Divider': 'Divider inside Menu.Dropdown',
159
191
  Placeholder: 'label, h; placeholder for images, charts, etc.',
160
192
  Custom: 'kind; component absent from the catalog, rendered as a labeled placeholder box',
161
193
  '#text': 'Compiler-generated text node (do not use directly)',
162
- Button: 'variant: filled|light|outline|subtle|default|white, color, size, fullWidth, loading, leftSection (character)',
194
+ Button: 'variant: filled|light|outline|subtle|default|white, color, size, fullWidth, loading, leftSection / rightSection (character)',
163
195
  ActionIcon: "Icon button: aria-label (required as name), variant, color, size; one character child such as '+'",
164
196
  CloseButton: 'aria-label, size',
165
197
  Anchor: 'href is display-only; clicking never navigates; use go() in the step; c, underline',
166
198
  a: 'HTML fallback; prefer Anchor',
167
- NavLink: 'label, description, href (highlighted when equal to current route), active, leftSection (character); nested NavLink allowed',
199
+ NavLink: 'label, description, href (highlighted when equal to current route), active, leftSection / rightSection (character or short text); nested NavLink allowed',
168
200
  Burger: 'opened, aria-label; narrow-screen navigation toggle, usually with hiddenFrom="sm"',
169
201
  TextInput: 'label, placeholder, description, error, withAsterisk, type; type action writes the value',
170
202
  PasswordInput: 'label, placeholder, description, error; type action writes the value, shown as dots',
@@ -178,12 +210,100 @@ export const COMPONENT_DOCS = {
178
210
  SegmentedControl: 'data: string[] | { value, label }[], fullWidth; select accepts value or label',
179
211
  FileInput: 'label, placeholder, accept; type action writes the filename',
180
212
  Tabs: 'value / defaultValue; Tabs.Tab inside Tabs.List, content in Tabs.Panel; select switches tabs',
181
- 'Tabs.Tab': 'value, leftSection (character)',
213
+ 'Tabs.Tab': 'value, leftSection (character), rightSection (count or short text, e.g. 3)',
182
214
  'Accordion.Control': 'Clickable heading (requires id)',
183
215
  Pagination: 'total, value / defaultValue; select action writes the page number',
184
216
  PromptInput: 'placeholder; AI input, type action writes the value; use ActionIcon or Button to send',
185
217
  'Artifact.Ref': "title, kind, status; card linking to an artifact in the conversation (requires id; clickable)",
186
218
  'Terminal.Input': 'prompt (default "$"), placeholder; terminal input line (requires id), type action writes the value',
219
+ 'Menu.Item': 'leftSection (character), rightSection (text), color (red for destructive); clickable menu row (requires id)',
220
+ TabBar: 'data: string[] | [{ value, label, icon?, badge? }], value / defaultValue, aria-label; mobile bottom tab bar, select switches tabs; place it last in a full-height Stack',
221
+ };
222
+ /**
223
+ * 示例(D68,`npx joplo components <名字>` 输出):每个都能直接放进页面或层级里用;交互状态写成 $.ui / $.data 绑定,由步骤 set()。
224
+ * 只给最容易写错、或需要和步骤配合的组件;其余组件看 COMPONENT_DOCS 的一行提示就够。
225
+ */
226
+ export const COMPONENT_EXAMPLES = {
227
+ EmptyState: `<EmptyState icon="✉" title="No members yet" description="Invite teammates to start working together">
228
+ <Button id="invite_first">Invite members</Button>
229
+ </EmptyState>`,
230
+ ListRow: `<Stack gap={0}>
231
+ <ListRow avatar="Ana Lee" title="Ana Lee" description="ana@example.com"><Badge color="green" variant="light">Admin</Badge></ListRow>
232
+ <ListRow avatar="Bo Chen" title="Bo Chen" description={$.ui.boStatus} active={$.ui.boNew}><Button id="resend" variant="subtle">Resend</Button></ListRow>
233
+ </Stack>`,
234
+ Menu: `<Menu opened={$.ui.rowMenu} position="bottom-end">
235
+ <Menu.Target><ActionIcon id="row_more" aria-label="More actions">⋯</ActionIcon></Menu.Target>
236
+ <Menu.Dropdown>
237
+ <Menu.Item id="copy_link" leftSection="🔗">Copy invite link</Menu.Item>
238
+ <Menu.Divider />
239
+ <Menu.Item id="revoke" color="red" leftSection="✕">Revoke invite</Menu.Item>
240
+ </Menu.Dropdown>
241
+ </Menu>
242
+ // steps: .click('row_more', set($.ui.rowMenu, true)).click('revoke', set($.ui.rowMenu, false), set($.ui.confirm, true))`,
243
+ TabBar: `<Stack h="100%" gap={0}>
244
+ <ScrollArea style={{ flex: 1, minHeight: 0 }}>…page…</ScrollArea>
245
+ <TabBar id="tabs" aria-label="Bottom navigation" data={[{ value: 'home', label: 'Home', icon: '⌂' }, { value: 'trips', label: 'Trips', icon: '⛺', badge: 2 }, { value: 'me', label: 'Me', icon: '☺' }]} />
246
+ </Stack>
247
+ // steps: .select('tabs', 'trips', go('/trips'))`,
248
+ Stat: `<SimpleGrid cols={3}>
249
+ <Stat label="Signups this week" value={$.data.signups} diff="+12%" icon="↗" />
250
+ <Stat label="Seats used" value="8 / 10" progress={80} description="2 seats left" />
251
+ <Stat label="Failed payments" value="3" diff="-2" color="red" />
252
+ </SimpleGrid>`,
253
+ KeyValue: `<KeyValue withDivider total items={[{ label: 'Seats', value: '5 × $9' }, { label: 'Tax', value: '$4.50' }, { label: 'Total', value: $.data.total }]} />`,
254
+ BarChart: `<BarChart h={220} dataKey="week" unit="" data={$.data.weeks} series={[{ name: 'signups', label: 'Signups' }, { name: 'churn', label: 'Churn', color: 'red' }]} />
255
+ // state: data: { weeks: [{ week: 'W1', signups: 40, churn: 4 }, { week: 'W2', signups: 52, churn: 6 }] }; set() a new array to animate`,
256
+ LineChart: `<LineChart h={200} dataKey="day" data={[{ day: 'Mon', p95: 320 }, { day: 'Tue', p95: 280 }]} series={[{ name: 'p95', label: 'p95 latency' }]} unit="ms" />`,
257
+ DataTable: `<DataTable idAccessor="id" records={$.data.members} selectedRecords={$.ui.selected} fetching={$.ui.loading}
258
+ sortStatus={{ columnAccessor: 'joined', direction: 'desc' }}
259
+ columns={[{ accessor: 'name', title: 'Name', avatar: true }, { accessor: 'status', title: 'Status', badge: { Active: 'green', Pending: 'yellow', Expired: 'gray' } }, { accessor: 'joined', title: 'Joined', sortable: true }]} />`,
260
+ Notification: `<Notification when={$.ui.deleted} position="bottom" title="Invite revoked" icon="↺" withCloseButton={false}>
261
+ <Group justify="space-between">Ana can no longer join<Button id="undo" variant="subtle" size="xs">Undo</Button></Group>
262
+ </Notification>`,
263
+ 'Radio.Card': `<Radio.Group id="plan" label="Plan">
264
+ <Stack gap="xs">
265
+ <Radio.Card value="team" label="Team" description="Up to 10 seats" leftSection="👥" />
266
+ <Radio.Card value="pro" label="Pro" description="Unlimited seats" leftSection="★" />
267
+ </Stack>
268
+ </Radio.Group>
269
+ // steps: .select('plan', 'pro')`,
270
+ 'Avatar.Group': `<Avatar.Group><Avatar name="Ana Lee" /><Avatar name="Bo Chen" /><Avatar name="+3" /></Avatar.Group>`,
271
+ // 关系类图表(D69):npx joplo components Diagram / Sequence / StateMachine 也给一个能直接用的例子;分组、布局、取景的细节在 npx joplo skill diagram
272
+ Diagram: `<Diagram id="arch" direction="right" h={420}>
273
+ <Diagram.Group id="g_gw" label="Gateway" icon="gateway" tone="blue">
274
+ <Diagram.Node id="api" label="API" description="auth · rate limit" />
275
+ </Diagram.Group>
276
+ <Diagram.Group id="g_run" label="Runtime" icon="service" tone="purple">
277
+ <Diagram.Node id="kernel" label="Kernel" description="model + tool loop" />
278
+ </Diagram.Group>
279
+ <Diagram.Group id="g_data" label="Storage" icon="database">
280
+ <Diagram.Node id="pg" label="PostgreSQL" kind="database" />
281
+ </Diagram.Group>
282
+ <Diagram.Edge from="api" to="kernel" label="run" />
283
+ <Diagram.Edge from="kernel" to="pg" label="commit" async />
284
+ </Diagram>
285
+ // steps: .system('Run starts', trace('api', 'kernel', 'pg'), shot('kernel')); groups, layout, framing: npx joplo skill diagram`,
286
+ Sequence: `<Sequence id="login">
287
+ <Sequence.Actor id="web" label="Web" kind="client" />
288
+ <Sequence.Actor id="api" label="API" />
289
+ <Sequence.Actor id="db" label="DB" kind="database" />
290
+ <Sequence.Message id="m_req" from="web" to="api" label="POST /login" />
291
+ <Sequence.Message id="m_q" from="api" to="db" label="find user" />
292
+ <Sequence.Message id="m_ok" from="api" to="web" label="200 + session" reply />
293
+ </Sequence>
294
+ // steps: .system('Sign in', trace('m_req')).system('Look up the user', trace('m_q'))`,
295
+ StateMachine: `<StateMachine id="order_sm" value={$.data.order.status}>
296
+ <StateMachine.State id="created" label="Created" initial />
297
+ <StateMachine.State id="paid" label="Paid" />
298
+ <StateMachine.State id="closed" label="Closed" final />
299
+ <StateMachine.Transition from="created" to="paid" label="pay" />
300
+ <StateMachine.Transition from="created" to="closed" label="timeout 30 min" />
301
+ </StateMachine>
302
+ // steps: .system('Payment received', set($.data.order.status, 'paid')) lights created → paid`,
303
+ Modal: `<Modal id="confirm" opened={$.ui.confirm} title="Revoke this invite?" size="sm">
304
+ <Text>Ana's link stops working right away. You can invite her again later.</Text>
305
+ <Group justify="flex-end"><Button id="cancel_revoke" variant="default">Cancel</Button><Button id="do_revoke" color="red">Revoke</Button></Group>
306
+ </Modal>`,
187
307
  };
188
308
  // ---------- 响应式(Mantine 默认断点,按舞台宽度取值) ----------
189
309
  /** Mantine 默认断点:36/48/62/75/88em,按 16px 换算。 */
@@ -224,12 +344,20 @@ export function captionLength(s) {
224
344
  /** 说明 / explain 的建议上限(超过时 check 报 CAPTION_TOO_LONG / EXPLAIN_TOO_LONG)。 */
225
345
  export const CAPTION_MAX = 24;
226
346
  export const EXPLAIN_MAX = 48;
347
+ /**
348
+ * 叙事提示(D67,见 docs/research/storytelling-and-demos.md):
349
+ * - 封面说明(flow 的 description):D61 定为 30 字以内,超过时 DESCRIPTION_TOO_LONG;
350
+ * - 过渡卡:副标题与 explain 同上限、每条要点与说明同上限、最多 4 条要点,超过时 CARD_TEXT_TOO_LONG(info);
351
+ * - 单个场景按 1× 估算超过 90 秒时 SCENARIO_TOO_LONG(info):一个场景讲一件事,长流程拆成几个场景或用 fork。
352
+ */
353
+ export const DESCRIPTION_MAX = 30;
354
+ export const CARD_POINTS_MAX = 4;
355
+ export const SCENARIO_MS_MAX = 90_000;
227
356
  /** 没有声明 layers 的方案:镜头作用在路径页面上,记为这个伪层级(不出现在层级栏)。作者的层级键不能以 @ 开头。 */
228
357
  export const PAGE_LAYER = '@page';
229
358
  /** shot()(不带 id)在有层级的方案里:作用于“当时导演所在的层”,让它回到整体。 */
230
359
  export const DIRECTOR_LAYER = '@director';
231
- /** Diagram.Node 的 kind 与 Node / Edge 的 state(D41)。 */
232
- export const DIAGRAM_NODE_KINDS = ['client', 'service', 'model', 'database', 'queue', 'storage', 'external', 'tool', 'user'];
360
+ /** Diagram 节点与连线的 state(D41);节点 kind 等见 diagram/model.ts。 */
233
361
  export const DIAGRAM_STATES = ['idle', 'active', 'ok', 'error', 'dim'];
234
362
  /** 子节点排版用的宽度:Phone 内部按手机宽度(响应式取值、visibleFrom / hiddenFrom、AppShell 收起都按它算),其余节点沿用外部宽度。 */
235
363
  export function childWidth(type, width) {
@@ -313,8 +441,8 @@ export function nodeLabel(node) {
313
441
  if (typeof v === 'string' && v && !IS_BINDING.test(v))
314
442
  return v;
315
443
  }
316
- // 没有 label 的连线:「from → to」
317
- if (node.type === 'Diagram.Edge' && typeof p.from === 'string' && typeof p.to === 'string')
444
+ // 没有 label 的连线 / 转换 / 消息:「from → to」
445
+ if ((node.type === 'Diagram.Edge' || node.type === 'StateMachine.Transition' || node.type === 'Sequence.Message') && typeof p.from === 'string' && typeof p.to === 'string')
318
446
  return `${p.from} → ${p.to}`;
319
447
  const text = collectText(node).trim();
320
448
  return text || node.type;
package/dist/compile.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ConfigDef, FeatureDef, LayoutDef, OptionDef, PageDef } from '@joplo-app/kit';
2
2
  import { Project } from './schema.js';
3
3
  import type { Diagnostic } from './result.js';
4
+ import { type GraphLayoutEngine } from './diagram/index.js';
4
5
  export type AuthoringProject = {
5
6
  /** 项目根目录绝对路径,用于把源位置改成相对路径。 */
6
7
  root: string;
@@ -29,7 +30,14 @@ export type CompileResult = {
29
30
  diagnostics: Diagnostic[];
30
31
  };
31
32
  export type CompileMode = 'dev' | 'publish' | 'review';
32
- export declare function compile(src: AuthoringProject, mode: CompileMode): CompileResult;
33
+ export type CompileOptions = {
34
+ /**
35
+ * 图表布局引擎(D69):Node 端传 `elkLayout`(@joplo-app/core/node)。不传时图表退化为网格排列(engine = 'grid'),
36
+ * 只用于测试或不关心布局的调用方;dev、build、check 都传 ELK。
37
+ */
38
+ layout?: GraphLayoutEngine;
39
+ };
40
+ export declare function compile(src: AuthoringProject, mode: CompileMode, opts?: CompileOptions): CompileResult;
33
41
  /** 角色的颜色(D56):没写 color 时按声明顺序取。 */
34
42
  export declare const ROLE_COLORS: readonly ["#E8590C", "#1971C2", "#2F9E44", "#9C36B5", "#C2255C", "#0C8599"];
35
43
  export declare function relSource(root: string, s: string): string;