@joplo-app/core 0.2.17 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/actions.d.ts +6 -0
  2. package/dist/actions.js +34 -0
  3. package/dist/agent-skill.d.ts +10 -13
  4. package/dist/agent-skill.js +52 -31
  5. package/dist/auto-caption.d.ts +22 -0
  6. package/dist/auto-caption.js +166 -0
  7. package/dist/catalog.d.ts +38 -41
  8. package/dist/catalog.js +26 -317
  9. package/dist/compile.d.ts +2 -8
  10. package/dist/compile.js +302 -353
  11. package/dist/content-i18n.js +27 -16
  12. package/dist/feature-diff.d.ts +3 -3
  13. package/dist/feature-diff.js +28 -6
  14. package/dist/focus.d.ts +3 -1
  15. package/dist/focus.js +16 -34
  16. package/dist/guide.d.ts +10 -12
  17. package/dist/guide.js +419 -519
  18. package/dist/index.d.ts +4 -1
  19. package/dist/index.js +4 -1
  20. package/dist/media.d.ts +10 -0
  21. package/dist/media.js +43 -0
  22. package/dist/node.d.ts +1 -2
  23. package/dist/node.js +1 -2
  24. package/dist/outline.d.ts +1 -1
  25. package/dist/outline.js +3 -3
  26. package/dist/pace.d.ts +9 -1
  27. package/dist/pace.js +23 -3
  28. package/dist/player.d.ts +8 -41
  29. package/dist/player.js +85 -148
  30. package/dist/playground.d.ts +38 -0
  31. package/dist/playground.js +111 -0
  32. package/dist/plugin-data.d.ts +11 -0
  33. package/dist/plugin-data.js +96 -0
  34. package/dist/plugins/compiler.d.ts +66 -0
  35. package/dist/plugins/compiler.js +428 -0
  36. package/dist/plugins/data.d.ts +12 -0
  37. package/dist/plugins/data.js +120 -0
  38. package/dist/result.d.ts +1 -1
  39. package/dist/result.js +1 -0
  40. package/dist/runtime.d.ts +22 -0
  41. package/dist/runtime.js +18 -0
  42. package/dist/schema.d.ts +566 -82
  43. package/dist/schema.js +65 -53
  44. package/dist/scope.js +14 -5
  45. package/dist/step-identity.d.ts +1 -1
  46. package/dist/step-identity.js +1 -1
  47. package/dist/themes.d.ts +7 -0
  48. package/dist/themes.js +5 -0
  49. package/dist/traits.d.ts +7 -0
  50. package/dist/traits.js +26 -0
  51. package/dist/validate.js +17 -4
  52. package/dist/voice.d.ts +8 -2
  53. package/dist/voice.js +14 -2
  54. package/package.json +7 -4
  55. package/dist/diagram/elk.d.ts +0 -6
  56. package/dist/diagram/elk.js +0 -56
  57. package/dist/diagram/graph-layout.d.ts +0 -123
  58. package/dist/diagram/graph-layout.js +0 -620
  59. package/dist/diagram/index.d.ts +0 -41
  60. package/dist/diagram/index.js +0 -92
  61. package/dist/diagram/model.d.ts +0 -217
  62. package/dist/diagram/model.js +0 -189
  63. package/dist/diagram/sequence-layout.d.ts +0 -12
  64. package/dist/diagram/sequence-layout.js +0 -185
package/dist/catalog.d.ts CHANGED
@@ -1,35 +1,39 @@
1
- /**
2
- * 组件目录 v3(D35):名称与属性对齐 Mantine(数据表对齐 mantine-datatable),另加少量 AI 交互组件、
3
- * HTML 兜底标签和 Joplo 专用组件。复合组件用点语法:`<AppShell.Header>` 编译出的节点 type 就是 'AppShell.Header'。
4
- *
5
- * 目录是唯一来源:@joplo-app/kit/ui 的导出、渲染器(@joplo-app/web)的实现、COMPONENT_DOCS 都必须与 COMPONENT_TYPES 一致
6
- * (packages/core/test/catalog.test.ts 与渲染器的类型检查保证)。目录之外的名称在编译时报错,不会被静默渲染。
7
- * 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
8
- */
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", "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"];
1
+ import type { PluginDataSpec, ElementTraits } from '@joplo-app/kit/plugin';
2
+ export declare const COMPONENT_TYPES: readonly ["Custom", "#text", "#fragment"];
11
3
  export type ComponentType = (typeof COMPONENT_TYPES)[number];
12
- export declare const INTERACTIVE_TYPES: ReadonlySet<string>;
13
- /** 可接收输入值;type/select/toggle 动作写入 state.inputs[nodeId]。 */
14
- export declare const VALUE_TYPES: ReadonlySet<string>;
15
- /**
16
- * 只有 opened(兼容旧写法 open)为真时自身和子节点才可见的浮层。
17
- * Menu.Dropdown(D68):作者把 opened 写在 Menu 上(与 Mantine 一致),编译器把它抄到菜单里的 Menu.Dropdown 上。
18
- */
19
- export declare const GATED_CONTAINERS: ReadonlySet<string>;
20
- /** Joplo 在 Mantine 属性之外追加的属性,编译器会从 props 中取出,放到节点字段上。 */
4
+ export type ComponentInfo = {
5
+ interactive?: boolean;
6
+ parent?: string;
7
+ needsId?: boolean;
8
+ selfEvident?: boolean;
9
+ traits?: ElementTraits;
10
+ };
21
11
  export declare const JOPLO_PROPS: readonly ["id", "when", "disabledReason", "unmodeled", "note", "redact"];
22
- /**
23
- * 每个组件一行常用属性提示(`joplo skill components` 由此生成)。所有组件另外都接受:
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,
25
- * 响应式写成 { base, xs, sm, md, lg, xl };visibleFrom / hiddenFrom;以及 Joplo 属性 id/when/disabled/disabledReason/unmodeled/note。
26
- */
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>>;
12
+ /** 插件组件的类型名:`<插件 id>:<组件名>`(例如 scene3d:Target)。目录组件的名字里没有冒号。 */
13
+ export declare const PLUGIN_TYPE: RegExp;
14
+ export type PluginComponentType = `${string}:${string}`;
15
+ export declare const isPluginType: (type: string) => type is PluginComponentType;
16
+ /** 插件 id 与组件名:scene3d:Scene.Part → { plugin: 'scene3d', name: 'Scene.Part' }。 */
17
+ export declare const splitPluginType: (type: string) => {
18
+ plugin: string;
19
+ name: string;
20
+ } | null;
21
+ /** IR 里记录的插件信息(编译自插件清单;发布站保留,不含运行时路径)。 */
22
+ export type PluginInfo = {
23
+ actions?: Record<string, import('@joplo-app/kit/plugin').PluginActionSpec>;
24
+ themes?: Record<string, string>;
25
+ properties?: Record<string, import('@joplo-app/kit/plugin').PluginPropertySpec>;
26
+ data?: PluginDataSpec;
27
+ id: string;
28
+ title: string;
29
+ version?: string;
30
+ components: Record<string, ComponentInfo>;
31
+ };
32
+ export type PluginTable = Readonly<Record<string, PluginInfo>> | undefined;
33
+ /** 插件组件的声明;不是插件类型或插件没启用时为 null。 */
34
+ export declare function pluginSpec(plugins: PluginTable, type: string): ComponentInfo | null;
35
+ /** 可操作的类型:声明了 interactive 的插件组件。 */
36
+ export declare function isInteractiveType(type: string, plugins?: PluginTable): boolean;
33
37
  /** Mantine 默认断点:36/48/62/75/88em,按 16px 换算。 */
34
38
  export declare const BREAKPOINTS: {
35
39
  readonly xs: 576;
@@ -93,17 +97,10 @@ export declare const SCENARIO_MS_MAX = 90000;
93
97
  export declare const PAGE_LAYER = "@page";
94
98
  /** shot()(不带 id)在有层级的方案里:作用于“当时导演所在的层”,让它回到整体。 */
95
99
  export declare const DIRECTOR_LAYER = "@director";
96
- /** Diagram 节点与连线的 state(D41);节点 kind 等见 diagram/model.ts。 */
97
- export declare const DIAGRAM_STATES: readonly ["idle", "active", "ok", "error", "dim"];
98
- /** 横放的 Phone(landscape)内容区尺寸:844 × 390 的屏幕扣掉安全区(左侧刘海、底部横条)。 */
99
- export declare const PHONE_LANDSCAPE: {
100
- readonly width: 772;
101
- readonly height: 358;
102
- };
103
- /** 子节点排版用的宽度:Phone 内部按手机宽度(横放按横屏宽度;响应式取值、visibleFrom / hiddenFrom、AppShell 收起都按它算),其余节点沿用外部宽度。 */
104
- export declare function childWidth(type: string, width: number, props?: {
105
- landscape?: unknown;
106
- }): number;
100
+ /** Child viewport width is declared by the plugin, never inferred from a type name. */
101
+ export declare function childWidth(node: {
102
+ traits?: ElementTraits;
103
+ }, width: number, props?: Record<string, unknown>): number;
107
104
  /** 是否为响应式对象 `{ base, sm, md }`:普通对象,至少一个键,且全部键都是断点名。 */
108
105
  export declare function isResponsive(v: unknown): v is Partial<Record<(typeof BP_KEYS)[number], unknown>>;
109
106
  /** 按舞台宽度取响应式属性的值:取不超过宽度的最大断点;都不满足时取 base;非响应式值原样返回。 */
package/dist/catalog.js CHANGED
@@ -1,313 +1,25 @@
1
- /**
2
- * 组件目录 v3(D35):名称与属性对齐 Mantine(数据表对齐 mantine-datatable),另加少量 AI 交互组件、
3
- * HTML 兜底标签和 Joplo 专用组件。复合组件用点语法:`<AppShell.Header>` 编译出的节点 type 就是 'AppShell.Header'。
4
- *
5
- * 目录是唯一来源:@joplo-app/kit/ui 的导出、渲染器(@joplo-app/web)的实现、COMPONENT_DOCS 都必须与 COMPONENT_TYPES 一致
6
- * (packages/core/test/catalog.test.ts 与渲染器的类型检查保证)。目录之外的名称在编译时报错,不会被静默渲染。
7
- * 只换词汇,不换渲染:运行时不引入 Mantine,仍由 Joplo 渲染成低保真风格。
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'];
12
- /** 布局、展示与容器:不可操作。 */
13
- const STRUCTURE = [
14
- // 布局
15
- 'AppShell', 'AppShell.Header', 'AppShell.Navbar', 'AppShell.Main', 'AppShell.Aside', 'AppShell.Footer',
16
- 'Container', 'Stack', 'Group', 'Flex', 'Grid', 'Grid.Col', 'SimpleGrid', 'Center', 'Box', 'Space',
17
- 'Paper', 'Card', 'Card.Section', 'Divider', 'ScrollArea',
18
- // 文字与展示
19
- 'Title', 'Text', 'Code', 'Kbd', 'Blockquote', 'List', 'List.Item', 'Badge', 'Avatar', 'Image', 'ThemeIcon', 'Indicator',
20
- 'Timeline', 'Timeline.Item',
21
- 'Table', 'Table.Thead', 'Table.Tbody', 'Table.Tr', 'Table.Th', 'Table.Td', 'DataTable',
22
- 'Accordion', 'Accordion.Item', 'Accordion.Panel',
23
- 'Radio',
24
- // 导航
25
- 'Tabs.List', 'Tabs.Panel', 'Breadcrumbs', 'Stepper', 'Stepper.Step',
26
- // 反馈与浮层
27
- 'Alert', 'Loader', 'Progress', 'RingProgress', 'Skeleton', 'Notification', 'Modal', 'Drawer',
28
- // AI 交互(Joplo 自有)
29
- 'ChatMessage', 'ToolCall', 'Thinking', 'Artifact', 'Email', 'DataCard', 'StateFlow',
30
- // 设备外框(Joplo 自有):终端与手机
31
- 'Terminal', 'Terminal.Command', 'Terminal.Output', 'Phone',
32
- // 关系类图表(Joplo 自有,D41 / D69):布局在编译期算好;节点与连线的状态由 flow 步骤的 trace() 推算
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',
39
- // HTML 兜底
40
- ...HTML,
41
- // Joplo
42
- 'Placeholder', // props: label, h —— 图片/图表等占位
43
- 'Custom', // props: kind —— 逃生口:目录没有的组件,渲染为带说明的占位框
44
- '#text', // 编译器生成的文本节点:props.text 为字面量或 `$ui.x` 绑定
45
- ];
46
- /** 看起来可操作:必须有演示行为、明确禁用并说明原因,或标记 unmodeled。 */
47
- const INTERACTIVE = [
48
- 'Button', 'ActionIcon', 'CloseButton', 'Anchor', 'a', 'NavLink', 'Burger',
49
- 'TextInput', 'PasswordInput', 'NumberInput', 'Textarea', 'Select', 'MultiSelect', 'Checkbox', 'Radio.Group', 'Switch',
50
- 'SegmentedControl', 'FileInput', 'Tabs', 'Tabs.Tab', 'Accordion.Control', 'Pagination', 'PromptInput', 'Terminal.Input',
51
- 'Artifact.Ref',
52
- // 产品界面(D68)
53
- 'Menu.Item', 'TabBar',
54
- ];
55
- export const COMPONENT_TYPES = [...STRUCTURE, ...INTERACTIVE];
56
- export const INTERACTIVE_TYPES = new Set(INTERACTIVE);
57
- /** 可接收输入值;type/select/toggle 动作写入 state.inputs[nodeId]。 */
58
- export const VALUE_TYPES = new Set([
59
- 'TextInput', 'PasswordInput', 'NumberInput', 'Textarea', 'Select', 'MultiSelect', 'Checkbox', 'Radio.Group', 'Switch',
60
- 'SegmentedControl', 'FileInput', 'Tabs', 'Accordion', 'Pagination', 'PromptInput', 'Terminal.Input', 'TabBar',
61
- ]);
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']);
67
- /** Joplo 在 Mantine 属性之外追加的属性,编译器会从 props 中取出,放到节点字段上。 */
1
+ export const COMPONENT_TYPES = ['Custom', '#text', '#fragment'];
68
2
  export const JOPLO_PROPS = ['id', 'when', 'disabledReason', 'unmodeled', 'note', 'redact'];
69
- /**
70
- * 每个组件一行常用属性提示(`joplo skill components` 由此生成)。所有组件另外都接受:
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,
72
- * 响应式写成 { base, xs, sm, md, lg, xl };visibleFrom / hiddenFrom;以及 Joplo 属性 id/when/disabled/disabledReason/unmodeled/note。
73
- */
74
- export const COMPONENT_DOCS = {
75
- AppShell: 'header={{ height }}, navbar={{ width, breakpoint, collapsed: { mobile, desktop } }}, aside={{ width, breakpoint, collapsed }}, footer={{ height }}, padding; navigation collapses below breakpoint and shows Burger',
76
- 'AppShell.Header': 'Header; p, px',
77
- 'AppShell.Navbar': 'Navigation sidebar; p; contains NavLink',
78
- 'AppShell.Main': 'Main content; contains <Outlet />',
79
- 'AppShell.Aside': 'Right sidebar; p',
80
- 'AppShell.Footer': 'Footer; p',
81
- Container: 'size: xs|sm|md|lg|xl|number (default md), fluid',
82
- Stack: 'gap (default md), align, justify; vertical layout',
83
- Group: 'gap (default md), justify, align (default center), wrap, grow; horizontal layout',
84
- Flex: 'direction, gap, rowGap, columnGap, align, justify, wrap; all responsive',
85
- Grid: 'columns (default 12), gutter, justify, align, grow; Grid.Col children',
86
- 'Grid.Col': 'span: number|"auto"|"content"|{ base, md }, offset',
87
- SimpleGrid: 'cols={{ base: 1, md: 3 }}, spacing, verticalSpacing',
88
- Center: 'inline; centers content',
89
- Box: 'Generic container; style props only',
90
- Space: 'h, w; blank space',
91
- Paper: 'p, withBorder, shadow, radius',
92
- Card: 'padding (default md), withBorder, shadow, radius; Card.Section for edge-to-edge sections',
93
- 'Card.Section': 'withBorder, inheritPadding',
94
- Divider: 'label, labelPosition: left|center|right, orientation, my',
95
- ScrollArea: 'h, mah',
96
- Title: 'order: 1-6; text in children',
97
- Text: 'size: xs|sm|md|lg|xl, c: dimmed|red|green|…, fw, ta, truncate, lineClamp, span; preserves newlines',
98
- Code: 'block (multiline code block), color',
99
- Kbd: 'Keyboard key',
100
- Blockquote: 'cite, color',
101
- List: 'type: ordered|unordered, spacing; List.Item children',
102
- 'List.Item': 'List item',
103
- Badge: 'color, variant: filled|light|outline|dot|default, size',
104
- Avatar: 'name (shows first character), src, color, radius, size',
105
- Image: 'src={asset("./photo.jpg")} (embeds a project image), alt, h, w, radius, fit: cover|contain (default cover), position (e.g. "center 20%"); other src values draw a placeholder with alt',
106
- ThemeIcon: 'color, variant, size, radius; one character as child',
107
- Indicator: 'label, color, disabled (hides the badge; can be a condition), processing; wraps one element with a corner badge',
108
- Timeline: 'active (completed item index), bulletSize; Timeline.Item children',
109
- 'Timeline.Item': 'title, bullet; description in children',
110
- Table: 'data={{ head: [...], body: [[...]] }} or Table.Thead/Tbody/Tr/Th/Td; striped, withTableBorder',
111
- 'Table.Thead': 'Table head',
112
- 'Table.Tbody': 'Table body',
113
- 'Table.Tr': 'Row',
114
- 'Table.Th': 'Header cell',
115
- 'Table.Td': 'Cell',
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',
117
- Accordion: 'value / defaultValue (expanded item); select sets the expanded item; Accordion.Item children',
118
- 'Accordion.Item': 'value; contains Accordion.Control and Accordion.Panel',
119
- 'Accordion.Panel': 'Content shown when expanded',
120
- Radio: 'value, label; place inside Radio.Group',
121
- 'Tabs.List': 'Tab bar; contains Tabs.Tab',
122
- 'Tabs.Panel': 'value; current tab content',
123
- Breadcrumbs: 'separator; Anchor or text children',
124
- Stepper: 'active (zero-based); Stepper.Step children',
125
- 'Stepper.Step': 'label, description; step content in children (only current step shown)',
126
- Alert: 'title, color (default blue), variant, icon (character), withCloseButton; description in children',
127
- Loader: 'size, color, type; optional child text',
128
- Progress: 'value 0-100, color, size, striped',
129
- RingProgress: 'sections: [{ value, color }], label, size, thickness',
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)',
132
- Modal: 'opened (gated, usually opened={$.ui.open}), title, size, centered, fullScreen',
133
- Drawer: 'opened (gated), title, position: left|right|top|bottom (default left), size',
134
- ChatMessage: "from: 'user'|'assistant', name; message content in children (preserves newlines)",
135
- ToolCall: "title, state: 'running'|'done'|'error'; call details in children",
136
- Email: 'from, to, subject, time; simple email card, body in children; can contain Button',
137
- DataCard: 'title, value (object or state binding), fields?: [{ key, label }]; lists all keys by default; rows changed this step show old value → new value',
138
- StateFlow: 'value (current state binding), states: string[], labels?: { state: name }; earlier states are completed, current state highlighted',
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',
140
- Artifact: "title, kind: 'doc'|'code'|'sheet'|'web'|'image', status: 'generating'|'ready'|'error', version; Agent artifact side panel, content in children",
141
- Terminal: 'title; terminal window (CLI prototype), Terminal.Command / Terminal.Output / Terminal.Input children; scrolls internally when content exceeds h or mah',
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",
155
- 'Terminal.Command': 'prompt (default "$"); command text in children',
156
- 'Terminal.Output': "tone: 'plain'|'ok'|'warn'|'error' (default plain); output text in children (preserves newlines)",
157
- Phone: 'scale (visual scale, default 1), h (screen height, default 844), landscape (turned sideways: content 772 × 358, notch on the left; use it for video-style or landscape mobile screens); 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',
158
- div: 'HTML fallback; prefer Box/Stack/Group',
159
- span: 'HTML fallback; prefer Text span',
160
- p: 'HTML fallback; prefer Text',
161
- h1: 'HTML fallback; prefer Title order={1}',
162
- h2: 'HTML fallback; prefer Title order={2}',
163
- h3: 'HTML fallback; prefer Title order={3}',
164
- h4: 'HTML fallback; prefer Title order={4}',
165
- main: 'HTML fallback; prefer AppShell.Main',
166
- section: 'HTML fallback; prefer Box',
167
- header: 'HTML fallback; prefer AppShell.Header',
168
- footer: 'HTML fallback; prefer AppShell.Footer',
169
- nav: 'HTML fallback; prefer AppShell.Navbar',
170
- aside: 'HTML fallback; prefer AppShell.Aside',
171
- ul: 'HTML fallback; prefer List',
172
- ol: 'HTML fallback; prefer List type="ordered"',
173
- li: 'HTML fallback; prefer List.Item',
174
- strong: 'HTML fallback; prefer Text fw={700} span',
175
- em: 'HTML fallback; prefer Text fs="italic" span',
176
- small: 'HTML fallback; prefer Text size="xs"',
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',
191
- Placeholder: 'label, h; placeholder for images, charts, etc.',
192
- Custom: 'kind; component absent from the catalog, rendered as a labeled placeholder box',
193
- '#text': 'Compiler-generated text node (do not use directly)',
194
- Button: 'variant: filled|light|outline|subtle|default|white, color, size, fullWidth, loading, leftSection / rightSection (character)',
195
- ActionIcon: "Icon button: aria-label (required as name), variant, color, size; one character child such as '+'",
196
- CloseButton: 'aria-label, size',
197
- Anchor: 'href is display-only; clicking never navigates; use go() in the step; c, underline',
198
- a: 'HTML fallback; prefer Anchor',
199
- NavLink: 'label, description, href (highlighted when equal to current route), active, leftSection / rightSection (character or short text); nested NavLink allowed',
200
- Burger: 'opened, aria-label; narrow-screen navigation toggle, usually with hiddenFrom="sm"',
201
- TextInput: 'label, placeholder, description, error, withAsterisk, type; type action writes the value',
202
- PasswordInput: 'label, placeholder, description, error; type action writes the value, shown as dots',
203
- NumberInput: 'label, placeholder, min, max, suffix, prefix; type action writes the value',
204
- Textarea: 'label, placeholder, description, error, minRows, autosize; type action writes the value',
205
- Select: 'label, data: string[] | { value, label }[], placeholder, description; select accepts value or label',
206
- MultiSelect: 'label, data, placeholder; each select toggles one option',
207
- Checkbox: 'label, description, checked; toggle action writes the value',
208
- 'Radio.Group': 'label, value; Radio value/label children; select accepts value or label',
209
- Switch: 'label, description, checked; toggle action writes the value',
210
- SegmentedControl: 'data: string[] | { value, label }[], fullWidth; select accepts value or label',
211
- FileInput: 'label, placeholder, accept; type action writes the filename',
212
- Tabs: 'value / defaultValue; Tabs.Tab inside Tabs.List, content in Tabs.Panel; select switches tabs',
213
- 'Tabs.Tab': 'value, leftSection (character), rightSection (count or short text, e.g. 3)',
214
- 'Accordion.Control': 'Clickable heading (requires id)',
215
- Pagination: 'total, value / defaultValue; select action writes the page number',
216
- PromptInput: 'placeholder; AI input, type action writes the value; use ActionIcon or Button to send',
217
- 'Artifact.Ref': "title, kind, status; card linking to an artifact in the conversation (requires id; clickable)",
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
- Image: `<Image src={asset('../../assets/capitol.jpg')} alt="U.S. Capitol" h={240} fit="cover" position="center 40%" radius="md" />
255
- // import { asset } from '@joplo-app/kit'; the path is relative to this file. jpg/png/gif/webp/avif/svg, up to 2 MB each; compress first.
256
- // The image is embedded, so the board, build and share show it offline. For a tinted or full-bleed background, use style={{ backgroundImage: \`url(\${asset('./bg.jpg')})\` }}.`,
257
- BarChart: `<BarChart h={220} dataKey="week" unit="" data={$.data.weeks} series={[{ name: 'signups', label: 'Signups' }, { name: 'churn', label: 'Churn', color: 'red' }]} />
258
- // state: data: { weeks: [{ week: 'W1', signups: 40, churn: 4 }, { week: 'W2', signups: 52, churn: 6 }] }; set() a new array to animate`,
259
- LineChart: `<LineChart h={200} dataKey="day" data={[{ day: 'Mon', p95: 320 }, { day: 'Tue', p95: 280 }]} series={[{ name: 'p95', label: 'p95 latency' }]} unit="ms" />`,
260
- DataTable: `<DataTable idAccessor="id" records={$.data.members} selectedRecords={$.ui.selected} fetching={$.ui.loading}
261
- sortStatus={{ columnAccessor: 'joined', direction: 'desc' }}
262
- columns={[{ accessor: 'name', title: 'Name', avatar: true }, { accessor: 'status', title: 'Status', badge: { Active: 'green', Pending: 'yellow', Expired: 'gray' } }, { accessor: 'joined', title: 'Joined', sortable: true }]} />`,
263
- Notification: `<Notification when={$.ui.deleted} position="bottom" title="Invite revoked" icon="↺" withCloseButton={false}>
264
- <Group justify="space-between">Ana can no longer join<Button id="undo" variant="subtle" size="xs">Undo</Button></Group>
265
- </Notification>`,
266
- 'Radio.Card': `<Radio.Group id="plan" label="Plan">
267
- <Stack gap="xs">
268
- <Radio.Card value="team" label="Team" description="Up to 10 seats" leftSection="👥" />
269
- <Radio.Card value="pro" label="Pro" description="Unlimited seats" leftSection="★" />
270
- </Stack>
271
- </Radio.Group>
272
- // steps: .select('plan', 'pro')`,
273
- 'Avatar.Group': `<Avatar.Group><Avatar name="Ana Lee" /><Avatar name="Bo Chen" /><Avatar name="+3" /></Avatar.Group>`,
274
- // 关系类图表(D69):npx joplo components Diagram / Sequence / StateMachine 也给一个能直接用的例子;分组、布局、取景的细节在 npx joplo skill diagram
275
- Diagram: `<Diagram id="arch" direction="right" h={420}>
276
- <Diagram.Group id="g_gw" label="Gateway" icon="gateway" tone="blue">
277
- <Diagram.Node id="api" label="API" description="auth · rate limit" />
278
- </Diagram.Group>
279
- <Diagram.Group id="g_run" label="Runtime" icon="service" tone="purple">
280
- <Diagram.Node id="kernel" label="Kernel" description="model + tool loop" />
281
- </Diagram.Group>
282
- <Diagram.Group id="g_data" label="Storage" icon="database">
283
- <Diagram.Node id="pg" label="PostgreSQL" kind="database" />
284
- </Diagram.Group>
285
- <Diagram.Edge from="api" to="kernel" label="run" />
286
- <Diagram.Edge from="kernel" to="pg" label="commit" async />
287
- </Diagram>
288
- // steps: .system('Run starts', trace('api', 'kernel', 'pg'), shot('kernel')); groups, layout, framing: npx joplo skill diagram`,
289
- Sequence: `<Sequence id="login">
290
- <Sequence.Actor id="web" label="Web" kind="client" />
291
- <Sequence.Actor id="api" label="API" />
292
- <Sequence.Actor id="db" label="DB" kind="database" />
293
- <Sequence.Message id="m_req" from="web" to="api" label="POST /login" />
294
- <Sequence.Message id="m_q" from="api" to="db" label="find user" />
295
- <Sequence.Message id="m_ok" from="api" to="web" label="200 + session" reply />
296
- </Sequence>
297
- // steps: .system('Sign in', trace('m_req')).system('Look up the user', trace('m_q'))`,
298
- StateMachine: `<StateMachine id="order_sm" value={$.data.order.status}>
299
- <StateMachine.State id="created" label="Created" initial />
300
- <StateMachine.State id="paid" label="Paid" />
301
- <StateMachine.State id="closed" label="Closed" final />
302
- <StateMachine.Transition from="created" to="paid" label="pay" />
303
- <StateMachine.Transition from="created" to="closed" label="timeout 30 min" />
304
- </StateMachine>
305
- // steps: .system('Payment received', set($.data.order.status, 'paid')) lights created → paid`,
306
- Modal: `<Modal id="confirm" opened={$.ui.confirm} title="Revoke this invite?" size="sm">
307
- <Text>Ana's link stops working right away. You can invite her again later.</Text>
308
- <Group justify="flex-end"><Button id="cancel_revoke" variant="default">Cancel</Button><Button id="do_revoke" color="red">Revoke</Button></Group>
309
- </Modal>`,
3
+ // ---------- 插件组件(D86)----------
4
+ /** 插件组件的类型名:`<插件 id>:<组件名>`(例如 scene3d:Target)。目录组件的名字里没有冒号。 */
5
+ export const PLUGIN_TYPE = /^[a-z][a-z0-9-]*:[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)*$/;
6
+ export const isPluginType = (type) => PLUGIN_TYPE.test(type);
7
+ /** 插件 id 与组件名:scene3d:Scene.Part → { plugin: 'scene3d', name: 'Scene.Part' }。 */
8
+ export const splitPluginType = (type) => {
9
+ if (!isPluginType(type))
10
+ return null;
11
+ const i = type.indexOf(':');
12
+ return { plugin: type.slice(0, i), name: type.slice(i + 1) };
310
13
  };
14
+ /** 插件组件的声明;不是插件类型或插件没启用时为 null。 */
15
+ export function pluginSpec(plugins, type) {
16
+ const t = splitPluginType(type);
17
+ return (t && plugins?.[t.plugin]?.components[t.name]) || null;
18
+ }
19
+ /** 可操作的类型:声明了 interactive 的插件组件。 */
20
+ export function isInteractiveType(type, plugins) {
21
+ return pluginSpec(plugins, type)?.interactive === true;
22
+ }
311
23
  // ---------- 响应式(Mantine 默认断点,按舞台宽度取值) ----------
312
24
  /** Mantine 默认断点:36/48/62/75/88em,按 16px 换算。 */
313
25
  export const BREAKPOINTS = { xs: 576, sm: 768, md: 992, lg: 1200, xl: 1408 };
@@ -362,15 +74,12 @@ export const SCENARIO_MS_MAX = 90_000;
362
74
  export const PAGE_LAYER = '@page';
363
75
  /** shot()(不带 id)在有层级的方案里:作用于“当时导演所在的层”,让它回到整体。 */
364
76
  export const DIRECTOR_LAYER = '@director';
365
- /** Diagram 节点与连线的 state(D41);节点 kind 等见 diagram/model.ts。 */
366
- export const DIAGRAM_STATES = ['idle', 'active', 'ok', 'error', 'dim'];
367
- /** 横放的 Phone(landscape)内容区尺寸:844 × 390 的屏幕扣掉安全区(左侧刘海、底部横条)。 */
368
- export const PHONE_LANDSCAPE = { width: 772, height: 358 };
369
- /** 子节点排版用的宽度:Phone 内部按手机宽度(横放按横屏宽度;响应式取值、visibleFrom / hiddenFrom、AppShell 收起都按它算),其余节点沿用外部宽度。 */
370
- export function childWidth(type, width, props) {
371
- if (type !== 'Phone')
77
+ /** Child viewport width is declared by the plugin, never inferred from a type name. */
78
+ export function childWidth(node, width, props) {
79
+ const spec = node.traits?.childWidth;
80
+ if (!spec)
372
81
  return width;
373
- return props?.landscape === true ? PHONE_LANDSCAPE.width : VIEWPORT_SIZE.mobile.width;
82
+ return spec.when && props?.[spec.when.prop] === spec.when.value ? spec.when.width : spec.value;
374
83
  }
375
84
  /** 是否为响应式对象 `{ base, sm, md }`:普通对象,至少一个键,且全部键都是断点名。 */
376
85
  export function isResponsive(v) {
@@ -451,7 +160,7 @@ export function nodeLabel(node) {
451
160
  return v;
452
161
  }
453
162
  // 没有 label 的连线 / 转换 / 消息:「from → to」
454
- if ((node.type === 'Diagram.Edge' || node.type === 'StateMachine.Transition' || node.type === 'Sequence.Message') && typeof p.from === 'string' && typeof p.to === 'string')
163
+ if (typeof p.from === 'string' && typeof p.to === 'string')
455
164
  return `${p.from} → ${p.to}`;
456
165
  const text = collectText(node).trim();
457
166
  return text || node.type;
package/dist/compile.d.ts CHANGED
@@ -1,7 +1,8 @@
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
+ import { type CompileOptions } from './plugins/compiler.js';
5
+ export type { CompileOptions } from './plugins/compiler.js';
5
6
  export type AuthoringProject = {
6
7
  /** 项目根目录绝对路径,用于把源位置改成相对路径。 */
7
8
  root: string;
@@ -33,13 +34,6 @@ export type CompileResult = {
33
34
  diagnostics: Diagnostic[];
34
35
  };
35
36
  export type CompileMode = 'dev' | 'publish' | 'review';
36
- export type CompileOptions = {
37
- /**
38
- * 图表布局引擎(D69):Node 端传 `elkLayout`(@joplo-app/core/node)。不传时图表退化为网格排列(engine = 'grid'),
39
- * 只用于测试或不关心布局的调用方;dev、build、check 都传 ELK。
40
- */
41
- layout?: GraphLayoutEngine;
42
- };
43
37
  export declare function compile(src: AuthoringProject, mode: CompileMode, opts?: CompileOptions): CompileResult;
44
38
  /** 角色的颜色(D56):没写 color 时按声明顺序取。 */
45
39
  export declare const ROLE_COLORS: readonly ["#E8590C", "#1971C2", "#2F9E44", "#9C36B5", "#C2255C", "#0C8599"];