@agent-native/core 0.42.0 → 0.44.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 (139) hide show
  1. package/README.md +17 -56
  2. package/dist/chat-threads/store.d.ts.map +1 -1
  3. package/dist/chat-threads/store.js +71 -10
  4. package/dist/chat-threads/store.js.map +1 -1
  5. package/dist/cli/pr-visual-recap-workflow.d.ts +1 -1
  6. package/dist/cli/pr-visual-recap-workflow.d.ts.map +1 -1
  7. package/dist/cli/pr-visual-recap-workflow.js +1 -1
  8. package/dist/cli/pr-visual-recap-workflow.js.map +1 -1
  9. package/dist/cli/recap.d.ts.map +1 -1
  10. package/dist/cli/recap.js +13 -13
  11. package/dist/cli/recap.js.map +1 -1
  12. package/dist/cli/skills.d.ts +2 -6
  13. package/dist/cli/skills.d.ts.map +1 -1
  14. package/dist/cli/skills.js +21 -79
  15. package/dist/cli/skills.js.map +1 -1
  16. package/dist/client/AssistantChat.d.ts.map +1 -1
  17. package/dist/client/AssistantChat.js +76 -18
  18. package/dist/client/AssistantChat.js.map +1 -1
  19. package/dist/client/blocks/index.d.ts +9 -0
  20. package/dist/client/blocks/index.d.ts.map +1 -1
  21. package/dist/client/blocks/index.js +9 -0
  22. package/dist/client/blocks/index.js.map +1 -1
  23. package/dist/client/blocks/library/AnnotatedCodeBlock.d.ts.map +1 -1
  24. package/dist/client/blocks/library/AnnotatedCodeBlock.js +3 -3
  25. package/dist/client/blocks/library/AnnotatedCodeBlock.js.map +1 -1
  26. package/dist/client/blocks/library/ApiEndpointBlock.d.ts.map +1 -1
  27. package/dist/client/blocks/library/ApiEndpointBlock.js +1 -1
  28. package/dist/client/blocks/library/ApiEndpointBlock.js.map +1 -1
  29. package/dist/client/blocks/library/DiffBlock.d.ts.map +1 -1
  30. package/dist/client/blocks/library/DiffBlock.js +128 -19
  31. package/dist/client/blocks/library/DiffBlock.js.map +1 -1
  32. package/dist/client/blocks/library/FileTreeBlock.d.ts.map +1 -1
  33. package/dist/client/blocks/library/FileTreeBlock.js +31 -4
  34. package/dist/client/blocks/library/FileTreeBlock.js.map +1 -1
  35. package/dist/client/blocks/library/JsonExplorerBlock.js +1 -1
  36. package/dist/client/blocks/library/JsonExplorerBlock.js.map +1 -1
  37. package/dist/client/blocks/library/MermaidBlock.js +1 -1
  38. package/dist/client/blocks/library/MermaidBlock.js.map +1 -1
  39. package/dist/client/blocks/library/callout.config.d.ts +29 -0
  40. package/dist/client/blocks/library/callout.config.d.ts.map +1 -0
  41. package/dist/client/blocks/library/callout.config.js +33 -0
  42. package/dist/client/blocks/library/callout.config.js.map +1 -0
  43. package/dist/client/blocks/library/callout.d.ts +20 -0
  44. package/dist/client/blocks/library/callout.d.ts.map +1 -0
  45. package/dist/client/blocks/library/callout.js +61 -0
  46. package/dist/client/blocks/library/callout.js.map +1 -0
  47. package/dist/client/blocks/library/checklist.d.ts.map +1 -1
  48. package/dist/client/blocks/library/checklist.js +3 -3
  49. package/dist/client/blocks/library/checklist.js.map +1 -1
  50. package/dist/client/blocks/library/code-tabs.js +1 -1
  51. package/dist/client/blocks/library/code-tabs.js.map +1 -1
  52. package/dist/client/blocks/library/diagram.config.d.ts +64 -0
  53. package/dist/client/blocks/library/diagram.config.d.ts.map +1 -0
  54. package/dist/client/blocks/library/diagram.config.js +111 -0
  55. package/dist/client/blocks/library/diagram.config.js.map +1 -0
  56. package/dist/client/blocks/library/diagram.d.ts +16 -0
  57. package/dist/client/blocks/library/diagram.d.ts.map +1 -0
  58. package/dist/client/blocks/library/diagram.js +261 -0
  59. package/dist/client/blocks/library/diagram.js.map +1 -0
  60. package/dist/client/blocks/library/question-form.config.d.ts +69 -0
  61. package/dist/client/blocks/library/question-form.config.d.ts.map +1 -0
  62. package/dist/client/blocks/library/question-form.config.js +58 -0
  63. package/dist/client/blocks/library/question-form.config.js.map +1 -0
  64. package/dist/client/blocks/library/question-form.d.ts +20 -0
  65. package/dist/client/blocks/library/question-form.d.ts.map +1 -0
  66. package/dist/client/blocks/library/question-form.js +286 -0
  67. package/dist/client/blocks/library/question-form.js.map +1 -0
  68. package/dist/client/blocks/library/sanitize-html.d.ts +5 -0
  69. package/dist/client/blocks/library/sanitize-html.d.ts.map +1 -0
  70. package/dist/client/blocks/library/sanitize-html.js +240 -0
  71. package/dist/client/blocks/library/sanitize-html.js.map +1 -0
  72. package/dist/client/blocks/library/server-specs.d.ts.map +1 -1
  73. package/dist/client/blocks/library/server-specs.js +49 -0
  74. package/dist/client/blocks/library/server-specs.js.map +1 -1
  75. package/dist/client/blocks/library/specs.d.ts.map +1 -1
  76. package/dist/client/blocks/library/specs.js +9 -0
  77. package/dist/client/blocks/library/specs.js.map +1 -1
  78. package/dist/client/blocks/library/tabs.d.ts.map +1 -1
  79. package/dist/client/blocks/library/tabs.js +12 -12
  80. package/dist/client/blocks/library/tabs.js.map +1 -1
  81. package/dist/client/blocks/library/wireframe-kit.d.ts +260 -0
  82. package/dist/client/blocks/library/wireframe-kit.d.ts.map +1 -0
  83. package/dist/client/blocks/library/wireframe-kit.js +920 -0
  84. package/dist/client/blocks/library/wireframe-kit.js.map +1 -0
  85. package/dist/client/blocks/library/wireframe.config.d.ts +123 -0
  86. package/dist/client/blocks/library/wireframe.config.d.ts.map +1 -0
  87. package/dist/client/blocks/library/wireframe.config.js +311 -0
  88. package/dist/client/blocks/library/wireframe.config.js.map +1 -0
  89. package/dist/client/blocks/library/wireframe.d.ts +15 -0
  90. package/dist/client/blocks/library/wireframe.d.ts.map +1 -0
  91. package/dist/client/blocks/library/wireframe.js +206 -0
  92. package/dist/client/blocks/library/wireframe.js.map +1 -0
  93. package/dist/client/blocks/mdx.d.ts.map +1 -1
  94. package/dist/client/blocks/mdx.js +11 -0
  95. package/dist/client/blocks/mdx.js.map +1 -1
  96. package/dist/client/blocks/registry.d.ts +9 -0
  97. package/dist/client/blocks/registry.d.ts.map +1 -1
  98. package/dist/client/blocks/registry.js +12 -5
  99. package/dist/client/blocks/registry.js.map +1 -1
  100. package/dist/client/blocks/server.d.ts +1 -0
  101. package/dist/client/blocks/server.d.ts.map +1 -1
  102. package/dist/client/blocks/server.js +1 -0
  103. package/dist/client/blocks/server.js.map +1 -1
  104. package/dist/client/blocks/types.d.ts +8 -0
  105. package/dist/client/blocks/types.d.ts.map +1 -1
  106. package/dist/client/blocks/types.js.map +1 -1
  107. package/dist/client/rich-markdown-editor/DragHandle.d.ts.map +1 -1
  108. package/dist/client/rich-markdown-editor/DragHandle.js +112 -84
  109. package/dist/client/rich-markdown-editor/DragHandle.js.map +1 -1
  110. package/dist/client/rich-markdown-editor/RegistryBlockNode.d.ts.map +1 -1
  111. package/dist/client/rich-markdown-editor/RegistryBlockNode.js +1 -1
  112. package/dist/client/rich-markdown-editor/RegistryBlockNode.js.map +1 -1
  113. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts +9 -1
  114. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts.map +1 -1
  115. package/dist/client/rich-markdown-editor/SharedRichEditor.js +3 -1
  116. package/dist/client/rich-markdown-editor/SharedRichEditor.js.map +1 -1
  117. package/dist/client/rich-markdown-editor/extensions.d.ts +13 -1
  118. package/dist/client/rich-markdown-editor/extensions.d.ts.map +1 -1
  119. package/dist/client/rich-markdown-editor/extensions.js +4 -2
  120. package/dist/client/rich-markdown-editor/extensions.js.map +1 -1
  121. package/dist/client/rich-markdown-editor/useCollabReconcile.d.ts.map +1 -1
  122. package/dist/client/rich-markdown-editor/useCollabReconcile.js +11 -1
  123. package/dist/client/rich-markdown-editor/useCollabReconcile.js.map +1 -1
  124. package/dist/server/poll.d.ts.map +1 -1
  125. package/dist/server/poll.js +30 -14
  126. package/dist/server/poll.js.map +1 -1
  127. package/dist/styles/agent-native.css +1 -0
  128. package/dist/styles/blocks.css +1388 -0
  129. package/dist/templates/default/.agents/skills/storing-data/SKILL.md +2 -0
  130. package/dist/templates/workspace-core/.agents/skills/performance/SKILL.md +141 -0
  131. package/dist/templates/workspace-core/.agents/skills/storing-data/SKILL.md +2 -0
  132. package/docs/content/plan-plugin.md +8 -8
  133. package/docs/content/pr-visual-recap.md +2 -2
  134. package/docs/content/template-plan.md +94 -17
  135. package/package.json +2 -1
  136. package/src/templates/default/.agents/skills/storing-data/SKILL.md +2 -0
  137. package/src/templates/workspace-core/.agents/skills/performance/SKILL.md +141 -0
  138. package/src/templates/workspace-core/.agents/skills/storing-data/SKILL.md +2 -0
  139. package/docs/content/visual-plans.md +0 -82
@@ -0,0 +1,261 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
3
+ import { cn } from "../../utils.js";
4
+ import { defineBlock } from "../types.js";
5
+ import { AiEditableFieldLabel } from "../AiEditableField.js";
6
+ import { RoughOverlay, useIsDark, useWireframeStyle } from "./wireframe-kit.js";
7
+ import { sanitizeDiagramHtml, sanitizeWireframeCss, scopeDesignCss, } from "./sanitize-html.js";
8
+ import { diagramMdx, diagramSchema, } from "./diagram.config.js";
9
+ /**
10
+ * Read + Edit renderers for the shared `diagram` block — a flexible inline
11
+ * architecture/code diagram. The preferred authoring path is a scoped, inert
12
+ * HTML/SVG fragment that leans on `.diagram-*` primitives and `--wf-*` tokens;
13
+ * a legacy positional / sequence node-graph path is kept for older/simple plans.
14
+ * Lives in core so any app can register it (it originated in the plan template).
15
+ *
16
+ * DECOUPLING from the plan original (mirrors the sibling `wireframe.tsx` port):
17
+ * - Theme: `useIsDark()` reads `document.documentElement.classList` instead of
18
+ * `next-themes`; `useWireframeStyle()` reads the viewer's sketchy/clean
19
+ * preference from the shared `plan-wireframe-style` localStorage key — both
20
+ * from `./wireframe-kit.js`, so core stays plan-free and shadcn-free.
21
+ * - HTML sanitize: the HTML/SVG fragment + CSS run through the app-injected
22
+ * `ctx.sanitizeHtml` at the render point (defense-in-depth against stored
23
+ * XSS). Without a sanitizer wired, the HTML path emits nothing — core never
24
+ * injects unsanitized author HTML. The React-free `diagramSchema` already
25
+ * rejects active markup before storage.
26
+ * - The rough.js sketch overlay reuses the kit's shared `RoughOverlay`, scoped
27
+ * with the diagram selector and `drawFrame={false}` (the same call the plan
28
+ * `HtmlDiagram` made). The `.plan-diagram-frame` / `.diagram-*` / `data-rough`
29
+ * class contract is preserved exactly so the theme-token CSS in core's
30
+ * `blocks.css` styles it in any app.
31
+ *
32
+ * The section carries the app-neutral `an-block` class plus the legacy
33
+ * `plan-block` class so plan renders byte-identically while any other app gets
34
+ * the theme-token treatment.
35
+ */
36
+ /* -------------------------------------------------------------------------- */
37
+ /* HTML/SVG diagram path */
38
+ /* -------------------------------------------------------------------------- */
39
+ /** The rough-overlay selector for diagram bordered boxes (mirrors the plan). */
40
+ const DIAGRAM_ROUGH_SELECTOR = "[data-rough],.diagram-panel,.diagram-node,.diagram-box,.diagram-pill,.diagram-card,[class*='card'],[class*='box'],[class*='panel'],[class*='pill'],[class*='chip'],[class*='badge'],hr";
41
+ function HtmlDiagram({ data, ctx, compact, }) {
42
+ const ref = useRef(null);
43
+ const isDark = useIsDark();
44
+ const style = useWireframeStyle();
45
+ const scopeId = useId().replace(/[^a-zA-Z0-9_-]/g, "");
46
+ // Sanitize author HTML/CSS at the render point (defense-in-depth against
47
+ // stored XSS). Self-contained in core via the shared block sanitizer (DOM-based
48
+ // in the browser, regex fallback on the server) so diagrams render in any app
49
+ // without the host wiring a sanitizer hook.
50
+ const safeHtml = useMemo(() => sanitizeDiagramHtml(data.html), [data.html]);
51
+ const scopedCss = useMemo(() => {
52
+ const safeCss = sanitizeWireframeCss(data.css);
53
+ // Scope every author selector under this diagram instance so global
54
+ // selectors (body, *, .app-shell, :root) can't escape and restyle the page.
55
+ return safeCss
56
+ ? scopeDesignCss(safeCss, `[data-plan-diagram-scope="${scopeId}"]`)
57
+ : "";
58
+ }, [data.css, scopeId]);
59
+ return (_jsxs("div", { ref: ref, className: cn("plan-diagram-shell", compact && "plan-diagram-compact"), children: [_jsxs("div", { className: "plan-diagram-frame", "data-theme": isDark ? "dark" : "light", "data-style": style, "data-plan-diagram-scope": scopeId, children: [scopedCss && _jsx("style", { children: scopedCss }), _jsx("div", { className: "plan-diagram-frame-content", dangerouslySetInnerHTML: { __html: safeHtml } })] }), _jsx(RoughOverlay, { scopeRef: ref, enabled: style === "sketchy", drawFrame: false, selector: DIAGRAM_ROUGH_SELECTOR }), data.caption && !compact && (_jsx("p", { className: "mt-3 text-sm leading-6 text-muted-foreground", children: data.caption }))] }));
60
+ }
61
+ /* -------------------------------------------------------------------------- */
62
+ /* Legacy node-graph paths */
63
+ /* -------------------------------------------------------------------------- */
64
+ function clampDiagramPercent(value) {
65
+ if (!Number.isFinite(value))
66
+ return 50;
67
+ return Math.max(4, Math.min(96, value));
68
+ }
69
+ function hasPositionedDiagramNodes(data) {
70
+ return (data.nodes ?? []).some((node) => typeof node.x === "number" && typeof node.y === "number");
71
+ }
72
+ function orderDiagramNodes(nodes, edges) {
73
+ if (nodes.length === 0)
74
+ return [];
75
+ const byId = new Map(nodes.map((node) => [node.id, node]));
76
+ const indegree = new Map(nodes.map((node) => [node.id, 0]));
77
+ for (const edge of edges) {
78
+ if (byId.has(edge.from) && byId.has(edge.to)) {
79
+ indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);
80
+ }
81
+ }
82
+ const start = nodes.find((node) => (indegree.get(node.id) ?? 0) === 0);
83
+ if (!start)
84
+ return nodes;
85
+ const ordered = [];
86
+ const seen = new Set();
87
+ let current = start;
88
+ while (current && !seen.has(current.id)) {
89
+ const node = current;
90
+ ordered.push(node);
91
+ seen.add(node.id);
92
+ const next = edges.find((edge) => edge.from === node.id);
93
+ current = next ? byId.get(next.to) : undefined;
94
+ }
95
+ for (const node of nodes)
96
+ if (!seen.has(node.id))
97
+ ordered.push(node);
98
+ return ordered;
99
+ }
100
+ function PositionedDiagram({ data, compact, markerId, }) {
101
+ const nodes = (data.nodes ?? []).map((node) => ({
102
+ ...node,
103
+ x: clampDiagramPercent(node.x ?? 50),
104
+ y: clampDiagramPercent(node.y ?? 50),
105
+ }));
106
+ const edges = data.edges ?? [];
107
+ const nodeById = new Map(nodes.map((node) => [node.id, node]));
108
+ const arrowId = `${markerId}-diagram-arrow`;
109
+ const nodeWidth = compact ? 150 : 190;
110
+ const canvasHeight = compact ? 280 : 430;
111
+ return (_jsxs("div", { className: "plan-sketch rounded-[16px] border border-border bg-muted p-5", children: [_jsxs("div", { className: "relative overflow-hidden rounded-xl border border-border bg-background", style: { minHeight: canvasHeight }, children: [_jsxs("svg", { className: "pointer-events-none absolute inset-0 z-0 h-full w-full", viewBox: "0 0 100 100", preserveAspectRatio: "none", "aria-hidden": "true", children: [_jsx("defs", { children: _jsx("marker", { id: arrowId, viewBox: "0 0 10 10", refX: "8", refY: "5", markerWidth: "5", markerHeight: "5", orient: "auto-start-reverse", children: _jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", className: "fill-muted-foreground" }) }) }), edges.map((edge, index) => {
112
+ const from = nodeById.get(edge.from);
113
+ const to = nodeById.get(edge.to);
114
+ if (!from || !to)
115
+ return null;
116
+ return (_jsx("line", { x1: from.x, y1: from.y, x2: to.x, y2: to.y, markerEnd: `url(#${arrowId})`, vectorEffect: "non-scaling-stroke", className: "stroke-border", strokeWidth: 2, strokeDasharray: edge.label ? "0" : "6 5" }, `${edge.from}-${edge.to}-${index}`));
117
+ })] }), !compact &&
118
+ edges.map((edge, index) => {
119
+ const from = nodeById.get(edge.from);
120
+ const to = nodeById.get(edge.to);
121
+ if (!edge.label || !from || !to)
122
+ return null;
123
+ return (_jsx("span", { className: "absolute z-10 max-w-[130px] -translate-x-1/2 -translate-y-1/2 rounded-full border border-border bg-background px-2 py-0.5 text-center text-[11px] font-semibold text-muted-foreground shadow-sm", style: {
124
+ left: `${(from.x + to.x) / 2}%`,
125
+ top: `${(from.y + to.y) / 2}%`,
126
+ }, children: edge.label }, `${edge.from}-${edge.to}-${index}-label`));
127
+ }), nodes.map((node, index) => (_jsxs("article", { className: "absolute z-20 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 border-border bg-background p-3 text-foreground shadow-sm", style: {
128
+ left: `${node.x}%`,
129
+ top: `${node.y}%`,
130
+ width: nodeWidth,
131
+ }, children: [_jsx("p", { className: "text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground", children: index + 1 }), _jsx("h3", { className: "mt-2 text-base font-semibold leading-tight", children: node.label }), node.detail && !compact && (_jsx("p", { className: "mt-2 text-xs leading-5 text-muted-foreground", children: node.detail }))] }, node.id)))] }), data.notes && data.notes.length > 0 && !compact && (_jsx("div", { className: "mt-4 grid gap-2 border-t border-border pt-4 text-sm text-muted-foreground md:grid-cols-2", children: data.notes.map((note) => (_jsx("p", { children: note.text }, note.id))) }))] }));
132
+ }
133
+ function SequenceDiagram({ data, compact, }) {
134
+ const edges = data.edges ?? [];
135
+ const nodes = orderDiagramNodes(data.nodes ?? [], edges);
136
+ if (nodes.length === 0) {
137
+ return (_jsx("div", { className: "rounded-[12px] border border-border bg-muted p-4 text-sm text-muted-foreground", children: "Diagram content is empty." }));
138
+ }
139
+ return (_jsxs("div", { className: "plan-sketch rounded-[16px] border border-border bg-muted p-5", children: [_jsx("div", { className: cn("flex gap-3 overflow-x-auto pb-2", compact ? "items-center" : "items-stretch"), children: nodes.map((node, index) => {
140
+ const next = nodes[index + 1];
141
+ const edge = next
142
+ ? edges.find((candidate) => candidate.from === node.id && candidate.to === next.id)
143
+ : undefined;
144
+ return (_jsxs("div", { className: "flex min-w-max items-center gap-3", children: [_jsxs("article", { className: cn("w-[180px] rounded-xl border-2 border-border bg-background p-3 text-foreground", compact && "w-[150px]"), children: [_jsx("p", { className: "text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground", children: index + 1 }), _jsx("h3", { className: "mt-2 text-base font-semibold leading-tight", children: node.label }), node.detail && !compact && (_jsx("p", { className: "mt-2 text-xs leading-5 text-muted-foreground", children: node.detail }))] }), next && (_jsxs("div", { className: "grid min-w-[72px] justify-items-center gap-1 text-muted-foreground", children: [edge?.label && (_jsx("span", { className: "max-w-[96px] truncate rounded-full border border-border px-2 py-0.5 text-[11px] font-semibold", children: edge.label })), _jsx("span", { className: "h-0.5 w-full rounded-full border-t-2 border-dashed border-border" })] }))] }, node.id));
145
+ }) }), data.notes && data.notes.length > 0 && !compact && (_jsx("div", { className: "mt-4 grid gap-2 border-t border-border pt-4 text-sm text-muted-foreground md:grid-cols-2", children: data.notes.map((note) => (_jsx("p", { children: note.text }, note.id))) }))] }));
146
+ }
147
+ /**
148
+ * The diagram body. Routes to the preferred HTML/SVG path (when `data.html` is
149
+ * set) and otherwise to a legacy node-graph path (positioned canvas when nodes
150
+ * carry x/y, else an ordered sequence).
151
+ */
152
+ function DiagramBody({ data, ctx, compact, }) {
153
+ const markerId = useId().replace(/:/g, "");
154
+ if (data.html?.trim()) {
155
+ return _jsx(HtmlDiagram, { data: data, ctx: ctx, compact: compact });
156
+ }
157
+ if (hasPositionedDiagramNodes(data)) {
158
+ return (_jsx(PositionedDiagram, { data: data, compact: compact, markerId: markerId }));
159
+ }
160
+ return _jsx(SequenceDiagram, { data: data, compact: compact });
161
+ }
162
+ /* -------------------------------------------------------------------------- */
163
+ /* Read + Edit */
164
+ /* -------------------------------------------------------------------------- */
165
+ /** Read-only renderer: the diagram body wrapped in the standard titled block. */
166
+ export function DiagramRead({ data, blockId, title, summary, ctx, }) {
167
+ return (_jsxs("section", { className: "an-block plan-block", "data-block-id": blockId, children: [title && _jsx("div", { className: "an-block-label plan-block-label", children: title }), _jsx(DiagramBody, { data: data, ctx: ctx }), summary && _jsx("p", { className: "mt-5 text-muted-foreground", children: summary })] }));
168
+ }
169
+ /**
170
+ * Edit form (panel surface). The block can be an HTML/SVG fragment or a legacy
171
+ * node/edge/note graph, so this exposes html/css/caption plus a collapsible
172
+ * legacy node-graph JSON editor, each with an AI-edit affordance via
173
+ * `ctx.renderAiFieldAction` (through `AiEditableFieldLabel`). `editSurface:
174
+ * "panel"` means the registry renders the `Read` view with a corner edit button
175
+ * that opens this form in the app-provided popover.
176
+ */
177
+ export function DiagramEdit({ data, onChange, editable, blockId, title, summary, ctx, }) {
178
+ const htmlId = useId();
179
+ const cssId = useId();
180
+ const captionId = useId();
181
+ const legacyId = useId();
182
+ const [html, setHtml] = useState(data.html ?? "");
183
+ const [css, setCss] = useState(data.css ?? "");
184
+ const [caption, setCaption] = useState(data.caption ?? "");
185
+ const [legacyJson, setLegacyJson] = useState(() => JSON.stringify({
186
+ nodes: data.nodes ?? [],
187
+ edges: data.edges ?? [],
188
+ notes: data.notes ?? [],
189
+ }, null, 2));
190
+ useEffect(() => {
191
+ setHtml(data.html ?? "");
192
+ setCss(data.css ?? "");
193
+ setCaption(data.caption ?? "");
194
+ setLegacyJson(JSON.stringify({
195
+ nodes: data.nodes ?? [],
196
+ edges: data.edges ?? [],
197
+ notes: data.notes ?? [],
198
+ }, null, 2));
199
+ }, [data]);
200
+ const saveHtmlDiagram = () => {
201
+ onChange({
202
+ html: html.trim() || undefined,
203
+ css: css.trim() || undefined,
204
+ caption: caption.trim() || undefined,
205
+ nodes: data.nodes,
206
+ edges: data.edges,
207
+ notes: data.notes,
208
+ });
209
+ };
210
+ const saveLegacyDiagram = () => {
211
+ const parsed = JSON.parse(legacyJson);
212
+ onChange({
213
+ ...data,
214
+ nodes: parsed.nodes ?? [],
215
+ edges: parsed.edges ?? [],
216
+ notes: parsed.notes ?? [],
217
+ });
218
+ };
219
+ const fieldAction = (field, value) => ({
220
+ blockId,
221
+ blockType: "diagram",
222
+ blockTitle: title,
223
+ blockSummary: summary,
224
+ fieldValue: value,
225
+ draftScope: `block:diagram:${blockId}:${field.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`,
226
+ disabled: !editable,
227
+ instructions: "Update the plan with update-visual-plan using a targeted update-block content patch for this diagram block id. Preserve unrelated diagram fields unless the requested edit requires changing them. Keep diagram HTML/CSS on renderer-owned .diagram-* primitives and --wf-* tokens; do not introduce custom font-family or hard-coded hex/rgb/hsl colors.",
228
+ companionFields: [
229
+ {
230
+ label: "HTML / SVG fragment",
231
+ value: html.trim() || "(empty)",
232
+ language: "html",
233
+ },
234
+ { label: "CSS", value: css.trim() || "(empty)", language: "css" },
235
+ {
236
+ label: "caption",
237
+ value: caption.trim() || "(empty)",
238
+ language: "text",
239
+ },
240
+ ],
241
+ });
242
+ return (_jsxs("div", { className: "grid gap-4", "data-plan-interactive": true, children: [_jsx("button", { type: "button", className: "inline-flex h-8 w-fit items-center justify-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground disabled:opacity-50", disabled: !editable, onClick: saveHtmlDiagram, children: "Save diagram" }), _jsxs("div", { className: "group/field grid gap-1.5", children: [_jsx(AiEditableFieldLabel, { htmlFor: htmlId, label: "HTML / SVG fragment", ctx: ctx, action: fieldAction("HTML / SVG fragment", html) }), _jsx("textarea", { id: htmlId, className: "min-h-48 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs leading-5 text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", value: html, disabled: !editable, onChange: (event) => setHtml(event.target.value), placeholder: "<div class='diagram'>...</div>" })] }), _jsxs("div", { className: "group/field grid gap-1.5", children: [_jsx(AiEditableFieldLabel, { htmlFor: cssId, label: "CSS", ctx: ctx, action: fieldAction("CSS", css) }), _jsx("textarea", { id: cssId, className: "min-h-32 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs leading-5 text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", value: css, disabled: !editable, onChange: (event) => setCss(event.target.value), placeholder: ".diagram { display: grid; }" })] }), _jsxs("div", { className: "group/field grid gap-1.5", children: [_jsx(AiEditableFieldLabel, { htmlFor: captionId, label: "Caption", ctx: ctx, action: fieldAction("caption", caption) }), _jsx("input", { id: captionId, className: "h-9 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", value: caption, disabled: !editable, onChange: (event) => setCaption(event.target.value) })] }), !data.html && (_jsxs("details", { className: "rounded-md border border-border p-3", children: [_jsx("summary", { className: "cursor-pointer text-xs font-semibold text-muted-foreground", children: "Legacy node graph data" }), _jsxs("div", { className: "group/field mt-3 grid gap-1.5", children: [_jsx(AiEditableFieldLabel, { htmlFor: legacyId, label: "JSON", ctx: ctx, action: fieldAction("legacy node graph JSON", legacyJson) }), _jsx("textarea", { id: legacyId, className: "min-h-44 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs leading-5 text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", value: legacyJson, disabled: !editable, onChange: (event) => setLegacyJson(event.target.value) })] }), _jsx("button", { type: "button", className: "mt-3 inline-flex h-8 items-center justify-center rounded-md border border-input px-3 text-xs font-medium text-foreground disabled:opacity-50", disabled: !editable, onClick: saveLegacyDiagram, children: "Save graph data" })] }))] }));
243
+ }
244
+ /** Full client spec for the shared `diagram` block (schema + MDX + Read/Edit). */
245
+ export const diagramBlock = defineBlock({
246
+ type: "diagram",
247
+ schema: diagramSchema,
248
+ mdx: diagramMdx,
249
+ Read: DiagramRead,
250
+ Edit: DiagramEdit,
251
+ placement: ["block"],
252
+ // Config-driven: the rendered diagram differs from its raw html/css source, so
253
+ // edit from a corner button + panel rather than inline.
254
+ editSurface: "panel",
255
+ label: "Diagram",
256
+ description: "A flexible inline architecture/code diagram. Prefer html/css with SVG or semantic HTML for polished two-dimensional layouts; use .diagram-* primitives and --wf-* tokens for theme/sketch compatibility. Legacy nodes/edges are only for simple previews.",
257
+ // Seed the legacy fallback shape so a fresh block validates while agents can
258
+ // replace it with html/css when layout quality matters.
259
+ empty: () => ({ nodes: [{ id: "n1", label: "Module" }], edges: [] }),
260
+ });
261
+ //# sourceMappingURL=diagram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagram.js","sourceRoot":"","sources":["../../../../src/client/blocks/library/diagram.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,M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xD,WAAW,EAAE,OAAO;IACpB,KAAK,EAAE,SAAS;IAChB,WAAW,EACT,2PAA2P;IAC7P,6EAA6E;IAC7E,wDAAwD;IACxD,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;CACrE,CAAC,CAAC","sourcesContent":["import { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"../../utils.js\";\nimport { defineBlock } from \"../types.js\";\nimport type {\n BlockReadProps,\n BlockEditProps,\n BlockRenderContext,\n} from \"../types.js\";\nimport { AiEditableFieldLabel } from \"../AiEditableField.js\";\nimport { RoughOverlay, useIsDark, useWireframeStyle } from \"./wireframe-kit.js\";\nimport {\n sanitizeDiagramHtml,\n sanitizeWireframeCss,\n scopeDesignCss,\n} from \"./sanitize-html.js\";\nimport {\n diagramMdx,\n diagramSchema,\n type DiagramData,\n type DiagramEdge,\n type DiagramNode,\n} from \"./diagram.config.js\";\n\n/**\n * Read + Edit renderers for the shared `diagram` block — a flexible inline\n * architecture/code diagram. The preferred authoring path is a scoped, inert\n * HTML/SVG fragment that leans on `.diagram-*` primitives and `--wf-*` tokens;\n * a legacy positional / sequence node-graph path is kept for older/simple plans.\n * Lives in core so any app can register it (it originated in the plan template).\n *\n * DECOUPLING from the plan original (mirrors the sibling `wireframe.tsx` port):\n * - Theme: `useIsDark()` reads `document.documentElement.classList` instead of\n * `next-themes`; `useWireframeStyle()` reads the viewer's sketchy/clean\n * preference from the shared `plan-wireframe-style` localStorage key — both\n * from `./wireframe-kit.js`, so core stays plan-free and shadcn-free.\n * - HTML sanitize: the HTML/SVG fragment + CSS run through the app-injected\n * `ctx.sanitizeHtml` at the render point (defense-in-depth against stored\n * XSS). Without a sanitizer wired, the HTML path emits nothing — core never\n * injects unsanitized author HTML. The React-free `diagramSchema` already\n * rejects active markup before storage.\n * - The rough.js sketch overlay reuses the kit's shared `RoughOverlay`, scoped\n * with the diagram selector and `drawFrame={false}` (the same call the plan\n * `HtmlDiagram` made). The `.plan-diagram-frame` / `.diagram-*` / `data-rough`\n * class contract is preserved exactly so the theme-token CSS in core's\n * `blocks.css` styles it in any app.\n *\n * The section carries the app-neutral `an-block` class plus the legacy\n * `plan-block` class so plan renders byte-identically while any other app gets\n * the theme-token treatment.\n */\n\n/* -------------------------------------------------------------------------- */\n/* HTML/SVG diagram path */\n/* -------------------------------------------------------------------------- */\n\n/** The rough-overlay selector for diagram bordered boxes (mirrors the plan). */\nconst DIAGRAM_ROUGH_SELECTOR =\n \"[data-rough],.diagram-panel,.diagram-node,.diagram-box,.diagram-pill,.diagram-card,[class*='card'],[class*='box'],[class*='panel'],[class*='pill'],[class*='chip'],[class*='badge'],hr\";\n\nfunction HtmlDiagram({\n data,\n ctx,\n compact,\n}: {\n data: DiagramData;\n ctx: BlockRenderContext;\n compact?: boolean;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n const isDark = useIsDark();\n const style = useWireframeStyle();\n const scopeId = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n // Sanitize author HTML/CSS at the render point (defense-in-depth against\n // stored XSS). Self-contained in core via the shared block sanitizer (DOM-based\n // in the browser, regex fallback on the server) so diagrams render in any app\n // without the host wiring a sanitizer hook.\n const safeHtml = useMemo(() => sanitizeDiagramHtml(data.html), [data.html]);\n const scopedCss = useMemo(() => {\n const safeCss = sanitizeWireframeCss(data.css);\n // Scope every author selector under this diagram instance so global\n // selectors (body, *, .app-shell, :root) can't escape and restyle the page.\n return safeCss\n ? scopeDesignCss(safeCss, `[data-plan-diagram-scope=\"${scopeId}\"]`)\n : \"\";\n }, [data.css, scopeId]);\n\n return (\n <div\n ref={ref}\n className={cn(\"plan-diagram-shell\", compact && \"plan-diagram-compact\")}\n >\n <div\n className=\"plan-diagram-frame\"\n data-theme={isDark ? \"dark\" : \"light\"}\n data-style={style}\n data-plan-diagram-scope={scopeId}\n >\n {scopedCss && <style>{scopedCss}</style>}\n <div\n className=\"plan-diagram-frame-content\"\n dangerouslySetInnerHTML={{ __html: safeHtml }}\n />\n </div>\n <RoughOverlay\n scopeRef={ref}\n enabled={style === \"sketchy\"}\n drawFrame={false}\n selector={DIAGRAM_ROUGH_SELECTOR}\n />\n {data.caption && !compact && (\n <p className=\"mt-3 text-sm leading-6 text-muted-foreground\">\n {data.caption}\n </p>\n )}\n </div>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Legacy node-graph paths */\n/* -------------------------------------------------------------------------- */\n\nfunction clampDiagramPercent(value: number) {\n if (!Number.isFinite(value)) return 50;\n return Math.max(4, Math.min(96, value));\n}\n\nfunction hasPositionedDiagramNodes(data: DiagramData): boolean {\n return (data.nodes ?? []).some(\n (node) => typeof node.x === \"number\" && typeof node.y === \"number\",\n );\n}\n\nfunction orderDiagramNodes(\n nodes: DiagramNode[],\n edges: DiagramEdge[],\n): DiagramNode[] {\n if (nodes.length === 0) return [];\n const byId = new Map(nodes.map((node) => [node.id, node]));\n const indegree = new Map(nodes.map((node) => [node.id, 0]));\n for (const edge of edges) {\n if (byId.has(edge.from) && byId.has(edge.to)) {\n indegree.set(edge.to, (indegree.get(edge.to) ?? 0) + 1);\n }\n }\n const start = nodes.find((node) => (indegree.get(node.id) ?? 0) === 0);\n if (!start) return nodes;\n const ordered: DiagramNode[] = [];\n const seen = new Set<string>();\n let current: DiagramNode | undefined = start;\n while (current && !seen.has(current.id)) {\n const node: DiagramNode = current;\n ordered.push(node);\n seen.add(node.id);\n const next = edges.find((edge) => edge.from === node.id);\n current = next ? byId.get(next.to) : undefined;\n }\n for (const node of nodes) if (!seen.has(node.id)) ordered.push(node);\n return ordered;\n}\n\nfunction PositionedDiagram({\n data,\n compact,\n markerId,\n}: {\n data: DiagramData;\n compact?: boolean;\n markerId: string;\n}) {\n const nodes = (data.nodes ?? []).map((node) => ({\n ...node,\n x: clampDiagramPercent(node.x ?? 50),\n y: clampDiagramPercent(node.y ?? 50),\n }));\n const edges = data.edges ?? [];\n const nodeById = new Map(nodes.map((node) => [node.id, node]));\n const arrowId = `${markerId}-diagram-arrow`;\n const nodeWidth = compact ? 150 : 190;\n const canvasHeight = compact ? 280 : 430;\n\n return (\n <div className=\"plan-sketch rounded-[16px] border border-border bg-muted p-5\">\n <div\n className=\"relative overflow-hidden rounded-xl border border-border bg-background\"\n style={{ minHeight: canvasHeight }}\n >\n <svg\n className=\"pointer-events-none absolute inset-0 z-0 h-full w-full\"\n viewBox=\"0 0 100 100\"\n preserveAspectRatio=\"none\"\n aria-hidden=\"true\"\n >\n <defs>\n <marker\n id={arrowId}\n viewBox=\"0 0 10 10\"\n refX=\"8\"\n refY=\"5\"\n markerWidth=\"5\"\n markerHeight=\"5\"\n orient=\"auto-start-reverse\"\n >\n <path\n d=\"M 0 0 L 10 5 L 0 10 z\"\n className=\"fill-muted-foreground\"\n />\n </marker>\n </defs>\n {edges.map((edge, index) => {\n const from = nodeById.get(edge.from);\n const to = nodeById.get(edge.to);\n if (!from || !to) return null;\n return (\n <line\n key={`${edge.from}-${edge.to}-${index}`}\n x1={from.x}\n y1={from.y}\n x2={to.x}\n y2={to.y}\n markerEnd={`url(#${arrowId})`}\n vectorEffect=\"non-scaling-stroke\"\n className=\"stroke-border\"\n strokeWidth={2}\n strokeDasharray={edge.label ? \"0\" : \"6 5\"}\n />\n );\n })}\n </svg>\n\n {!compact &&\n edges.map((edge, index) => {\n const from = nodeById.get(edge.from);\n const to = nodeById.get(edge.to);\n if (!edge.label || !from || !to) return null;\n return (\n <span\n key={`${edge.from}-${edge.to}-${index}-label`}\n className=\"absolute z-10 max-w-[130px] -translate-x-1/2 -translate-y-1/2 rounded-full border border-border bg-background px-2 py-0.5 text-center text-[11px] font-semibold text-muted-foreground shadow-sm\"\n style={{\n left: `${(from.x + to.x) / 2}%`,\n top: `${(from.y + to.y) / 2}%`,\n }}\n >\n {edge.label}\n </span>\n );\n })}\n\n {nodes.map((node, index) => (\n <article\n key={node.id}\n className=\"absolute z-20 -translate-x-1/2 -translate-y-1/2 rounded-xl border-2 border-border bg-background p-3 text-foreground shadow-sm\"\n style={{\n left: `${node.x}%`,\n top: `${node.y}%`,\n width: nodeWidth,\n }}\n >\n <p className=\"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground\">\n {index + 1}\n </p>\n <h3 className=\"mt-2 text-base font-semibold leading-tight\">\n {node.label}\n </h3>\n {node.detail && !compact && (\n <p className=\"mt-2 text-xs leading-5 text-muted-foreground\">\n {node.detail}\n </p>\n )}\n </article>\n ))}\n </div>\n {data.notes && data.notes.length > 0 && !compact && (\n <div className=\"mt-4 grid gap-2 border-t border-border pt-4 text-sm text-muted-foreground md:grid-cols-2\">\n {data.notes.map((note) => (\n <p key={note.id}>{note.text}</p>\n ))}\n </div>\n )}\n </div>\n );\n}\n\nfunction SequenceDiagram({\n data,\n compact,\n}: {\n data: DiagramData;\n compact?: boolean;\n}) {\n const edges = data.edges ?? [];\n const nodes = orderDiagramNodes(data.nodes ?? [], edges);\n if (nodes.length === 0) {\n return (\n <div className=\"rounded-[12px] border border-border bg-muted p-4 text-sm text-muted-foreground\">\n Diagram content is empty.\n </div>\n );\n }\n return (\n <div className=\"plan-sketch rounded-[16px] border border-border bg-muted p-5\">\n <div\n className={cn(\n \"flex gap-3 overflow-x-auto pb-2\",\n compact ? \"items-center\" : \"items-stretch\",\n )}\n >\n {nodes.map((node, index) => {\n const next = nodes[index + 1];\n const edge = next\n ? edges.find(\n (candidate) =>\n candidate.from === node.id && candidate.to === next.id,\n )\n : undefined;\n return (\n <div key={node.id} className=\"flex min-w-max items-center gap-3\">\n <article\n className={cn(\n \"w-[180px] rounded-xl border-2 border-border bg-background p-3 text-foreground\",\n compact && \"w-[150px]\",\n )}\n >\n <p className=\"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground\">\n {index + 1}\n </p>\n <h3 className=\"mt-2 text-base font-semibold leading-tight\">\n {node.label}\n </h3>\n {node.detail && !compact && (\n <p className=\"mt-2 text-xs leading-5 text-muted-foreground\">\n {node.detail}\n </p>\n )}\n </article>\n {next && (\n <div className=\"grid min-w-[72px] justify-items-center gap-1 text-muted-foreground\">\n {edge?.label && (\n <span className=\"max-w-[96px] truncate rounded-full border border-border px-2 py-0.5 text-[11px] font-semibold\">\n {edge.label}\n </span>\n )}\n <span className=\"h-0.5 w-full rounded-full border-t-2 border-dashed border-border\" />\n </div>\n )}\n </div>\n );\n })}\n </div>\n {data.notes && data.notes.length > 0 && !compact && (\n <div className=\"mt-4 grid gap-2 border-t border-border pt-4 text-sm text-muted-foreground md:grid-cols-2\">\n {data.notes.map((note) => (\n <p key={note.id}>{note.text}</p>\n ))}\n </div>\n )}\n </div>\n );\n}\n\n/**\n * The diagram body. Routes to the preferred HTML/SVG path (when `data.html` is\n * set) and otherwise to a legacy node-graph path (positioned canvas when nodes\n * carry x/y, else an ordered sequence).\n */\nfunction DiagramBody({\n data,\n ctx,\n compact,\n}: {\n data: DiagramData;\n ctx: BlockRenderContext;\n compact?: boolean;\n}) {\n const markerId = useId().replace(/:/g, \"\");\n if (data.html?.trim()) {\n return <HtmlDiagram data={data} ctx={ctx} compact={compact} />;\n }\n if (hasPositionedDiagramNodes(data)) {\n return (\n <PositionedDiagram data={data} compact={compact} markerId={markerId} />\n );\n }\n return <SequenceDiagram data={data} compact={compact} />;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Read + Edit */\n/* -------------------------------------------------------------------------- */\n\n/** Read-only renderer: the diagram body wrapped in the standard titled block. */\nexport function DiagramRead({\n data,\n blockId,\n title,\n summary,\n ctx,\n}: BlockReadProps<DiagramData>) {\n return (\n <section className=\"an-block plan-block\" data-block-id={blockId}>\n {title && <div className=\"an-block-label plan-block-label\">{title}</div>}\n <DiagramBody data={data} ctx={ctx} />\n {summary && <p className=\"mt-5 text-muted-foreground\">{summary}</p>}\n </section>\n );\n}\n\n/**\n * Edit form (panel surface). The block can be an HTML/SVG fragment or a legacy\n * node/edge/note graph, so this exposes html/css/caption plus a collapsible\n * legacy node-graph JSON editor, each with an AI-edit affordance via\n * `ctx.renderAiFieldAction` (through `AiEditableFieldLabel`). `editSurface:\n * \"panel\"` means the registry renders the `Read` view with a corner edit button\n * that opens this form in the app-provided popover.\n */\nexport function DiagramEdit({\n data,\n onChange,\n editable,\n blockId,\n title,\n summary,\n ctx,\n}: BlockEditProps<DiagramData>) {\n const htmlId = useId();\n const cssId = useId();\n const captionId = useId();\n const legacyId = useId();\n const [html, setHtml] = useState(data.html ?? \"\");\n const [css, setCss] = useState(data.css ?? \"\");\n const [caption, setCaption] = useState(data.caption ?? \"\");\n const [legacyJson, setLegacyJson] = useState(() =>\n JSON.stringify(\n {\n nodes: data.nodes ?? [],\n edges: data.edges ?? [],\n notes: data.notes ?? [],\n },\n null,\n 2,\n ),\n );\n\n useEffect(() => {\n setHtml(data.html ?? \"\");\n setCss(data.css ?? \"\");\n setCaption(data.caption ?? \"\");\n setLegacyJson(\n JSON.stringify(\n {\n nodes: data.nodes ?? [],\n edges: data.edges ?? [],\n notes: data.notes ?? [],\n },\n null,\n 2,\n ),\n );\n }, [data]);\n\n const saveHtmlDiagram = () => {\n onChange({\n html: html.trim() || undefined,\n css: css.trim() || undefined,\n caption: caption.trim() || undefined,\n nodes: data.nodes,\n edges: data.edges,\n notes: data.notes,\n });\n };\n\n const saveLegacyDiagram = () => {\n const parsed = JSON.parse(legacyJson) as Pick<\n DiagramData,\n \"nodes\" | \"edges\" | \"notes\"\n >;\n onChange({\n ...data,\n nodes: parsed.nodes ?? [],\n edges: parsed.edges ?? [],\n notes: parsed.notes ?? [],\n });\n };\n\n const fieldAction = (\n field: \"HTML / SVG fragment\" | \"CSS\" | \"caption\" | \"legacy node graph JSON\",\n value: string,\n ) => ({\n blockId,\n blockType: \"diagram\",\n blockTitle: title,\n blockSummary: summary,\n fieldValue: value,\n draftScope: `block:diagram:${blockId}:${field.toLowerCase().replace(/[^a-z0-9]+/g, \"-\")}`,\n disabled: !editable,\n instructions:\n \"Update the plan with update-visual-plan using a targeted update-block content patch for this diagram block id. Preserve unrelated diagram fields unless the requested edit requires changing them. Keep diagram HTML/CSS on renderer-owned .diagram-* primitives and --wf-* tokens; do not introduce custom font-family or hard-coded hex/rgb/hsl colors.\",\n companionFields: [\n {\n label: \"HTML / SVG fragment\",\n value: html.trim() || \"(empty)\",\n language: \"html\",\n },\n { label: \"CSS\", value: css.trim() || \"(empty)\", language: \"css\" },\n {\n label: \"caption\",\n value: caption.trim() || \"(empty)\",\n language: \"text\",\n },\n ],\n });\n\n return (\n <div className=\"grid gap-4\" data-plan-interactive>\n <button\n type=\"button\"\n className=\"inline-flex h-8 w-fit items-center justify-center rounded-md bg-primary px-3 text-xs font-medium text-primary-foreground disabled:opacity-50\"\n disabled={!editable}\n onClick={saveHtmlDiagram}\n >\n Save diagram\n </button>\n <div className=\"group/field grid gap-1.5\">\n <AiEditableFieldLabel\n htmlFor={htmlId}\n label=\"HTML / SVG fragment\"\n ctx={ctx}\n action={fieldAction(\"HTML / SVG fragment\", html)}\n />\n <textarea\n id={htmlId}\n className=\"min-h-48 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs leading-5 text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n value={html}\n disabled={!editable}\n onChange={(event) => setHtml(event.target.value)}\n placeholder=\"<div class='diagram'>...</div>\"\n />\n </div>\n <div className=\"group/field grid gap-1.5\">\n <AiEditableFieldLabel\n htmlFor={cssId}\n label=\"CSS\"\n ctx={ctx}\n action={fieldAction(\"CSS\", css)}\n />\n <textarea\n id={cssId}\n className=\"min-h-32 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs leading-5 text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n value={css}\n disabled={!editable}\n onChange={(event) => setCss(event.target.value)}\n placeholder=\".diagram { display: grid; }\"\n />\n </div>\n <div className=\"group/field grid gap-1.5\">\n <AiEditableFieldLabel\n htmlFor={captionId}\n label=\"Caption\"\n ctx={ctx}\n action={fieldAction(\"caption\", caption)}\n />\n <input\n id={captionId}\n className=\"h-9 w-full rounded-md border border-input bg-background px-3 text-sm text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n value={caption}\n disabled={!editable}\n onChange={(event) => setCaption(event.target.value)}\n />\n </div>\n {!data.html && (\n <details className=\"rounded-md border border-border p-3\">\n <summary className=\"cursor-pointer text-xs font-semibold text-muted-foreground\">\n Legacy node graph data\n </summary>\n <div className=\"group/field mt-3 grid gap-1.5\">\n <AiEditableFieldLabel\n htmlFor={legacyId}\n label=\"JSON\"\n ctx={ctx}\n action={fieldAction(\"legacy node graph JSON\", legacyJson)}\n />\n <textarea\n id={legacyId}\n className=\"min-h-44 w-full rounded-md border border-input bg-background px-3 py-2 font-mono text-xs leading-5 text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring\"\n value={legacyJson}\n disabled={!editable}\n onChange={(event) => setLegacyJson(event.target.value)}\n />\n </div>\n <button\n type=\"button\"\n className=\"mt-3 inline-flex h-8 items-center justify-center rounded-md border border-input px-3 text-xs font-medium text-foreground disabled:opacity-50\"\n disabled={!editable}\n onClick={saveLegacyDiagram}\n >\n Save graph data\n </button>\n </details>\n )}\n </div>\n );\n}\n\n/** Full client spec for the shared `diagram` block (schema + MDX + Read/Edit). */\nexport const diagramBlock = defineBlock<DiagramData>({\n type: \"diagram\",\n schema: diagramSchema,\n mdx: diagramMdx,\n Read: DiagramRead,\n Edit: DiagramEdit,\n placement: [\"block\"],\n // Config-driven: the rendered diagram differs from its raw html/css source, so\n // edit from a corner button + panel rather than inline.\n editSurface: \"panel\",\n label: \"Diagram\",\n description:\n \"A flexible inline architecture/code diagram. Prefer html/css with SVG or semantic HTML for polished two-dimensional layouts; use .diagram-* primitives and --wf-* tokens for theme/sketch compatibility. Legacy nodes/edges are only for simple previews.\",\n // Seed the legacy fallback shape so a fresh block validates while agents can\n // replace it with html/css when layout quality matters.\n empty: () => ({ nodes: [{ id: \"n1\", label: \"Module\" }], edges: [] }),\n});\n"]}
@@ -0,0 +1,69 @@
1
+ import { z } from "zod";
2
+ import type { BlockMdxConfig } from "../types.js";
3
+ /**
4
+ * Pure (React-free) part of the shared `question-form` and `visual-questions`
5
+ * blocks: their data schema and MDX round-trip config. Lives in core so any
6
+ * app's server/shared registry and the client spec (`question-form.tsx`)
7
+ * consume one definition. Keeping it React-free means importing it into a server
8
+ * module never pulls React into the Nitro/SSR bundle.
9
+ *
10
+ * `question-form` is the general-purpose respondent-facing form (Open Questions,
11
+ * single/multi/freeform answers, recommended options, optional inline
12
+ * wireframe/diagram previews). `visual-questions` is the same data shape and UI,
13
+ * branded for an explicit visual-intake flow before a plan. Both originated in
14
+ * the plan template (the data shape mirrors the legacy `visual-questions` block)
15
+ * before moving here, so their MDX `tag` + attribute encoding MUST match the
16
+ * historical `<QuestionForm questions submitLabel />` / `<VisualQuestions … />`
17
+ * forms so stored `.mdx` round-trips byte-compatibly.
18
+ *
19
+ * The per-option `wireframe`/`diagram` previews stay opaque (`unknown`) at the
20
+ * core layer: the core block renders them through `ctx.renderBlock` (the same
21
+ * nested-block seam tabs/columns use) so core never imports an app's wireframe
22
+ * or diagram renderer. Each app supplies the matching `wireframe`/`diagram`
23
+ * block spec and shape.
24
+ */
25
+ export type QuestionMode = "single" | "multi" | "freeform";
26
+ export interface QuestionFormOption {
27
+ id: string;
28
+ label: string;
29
+ detail?: string;
30
+ /** Authored recommendation only (not a runtime answer). */
31
+ recommended?: boolean;
32
+ /**
33
+ * Optional inline visual previews for this option. Kept opaque at the core
34
+ * layer; rendered via `ctx.renderBlock` as a nested `wireframe`/`diagram`
35
+ * block so core stays app-agnostic. Apps validate the concrete shape with
36
+ * their own wireframe/diagram schemas.
37
+ */
38
+ wireframe?: unknown;
39
+ diagram?: unknown;
40
+ }
41
+ export interface QuestionFormQuestion {
42
+ id: string;
43
+ title: string;
44
+ subtitle?: string;
45
+ mode: QuestionMode;
46
+ options?: QuestionFormOption[];
47
+ allowOther?: boolean;
48
+ placeholder?: string;
49
+ required?: boolean;
50
+ }
51
+ export interface QuestionFormData {
52
+ questions: QuestionFormQuestion[];
53
+ submitLabel?: string;
54
+ }
55
+ /** `visual-questions` shares the exact `question-form` data shape. */
56
+ export type VisualQuestionsData = QuestionFormData;
57
+ export declare const questionFormSchema: z.ZodType<QuestionFormData>;
58
+ /** `visual-questions` validates with the same schema as `question-form`. */
59
+ export declare const visualQuestionsSchema: z.ZodType<VisualQuestionsData>;
60
+ /**
61
+ * MDX config: `questions` and `submitLabel` are both attributes (the questions
62
+ * array is JSON-encoded by the shared `prop()` encoder). Mirrors the legacy
63
+ * `<QuestionForm questions={[…]} submitLabel="…" />` encoding so stored `.mdx`
64
+ * round-trips byte-compatibly.
65
+ */
66
+ export declare const questionFormMdx: BlockMdxConfig<QuestionFormData>;
67
+ /** `visual-questions` uses the historical `<VisualQuestions … />` tag. */
68
+ export declare const visualQuestionsMdx: BlockMdxConfig<VisualQuestionsData>;
69
+ //# sourceMappingURL=question-form.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-form.config.d.ts","sourceRoot":"","sources":["../../../../src/client/blocks/library/question-form.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AA0BnD,eAAO,MAAM,kBAAkB,EAGd,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE7C,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,EACC,CAAC,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,cAAc,CAAC,gBAAgB,CAU5D,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,mBAAmB,CAUlE,CAAC"}
@@ -0,0 +1,58 @@
1
+ import { z } from "zod";
2
+ const idSchema = z.string().trim().min(1).max(120);
3
+ const questionOptionSchema = z.object({
4
+ id: idSchema,
5
+ label: z.string().trim().min(1).max(220),
6
+ detail: z.string().trim().max(800).optional(),
7
+ recommended: z.boolean().optional(),
8
+ // Opaque at the core layer — the inline preview renders via `ctx.renderBlock`
9
+ // with the app's own wireframe/diagram block spec; the app validates the shape.
10
+ wireframe: z.unknown().optional(),
11
+ diagram: z.unknown().optional(),
12
+ });
13
+ const questionSchema = z.object({
14
+ id: idSchema,
15
+ title: z.string().trim().min(1).max(260),
16
+ subtitle: z.string().trim().max(700).optional(),
17
+ mode: z.enum(["single", "multi", "freeform"]),
18
+ options: z.array(questionOptionSchema).max(40).optional(),
19
+ allowOther: z.boolean().optional(),
20
+ placeholder: z.string().trim().max(240).optional(),
21
+ required: z.boolean().optional(),
22
+ });
23
+ export const questionFormSchema = z.object({
24
+ questions: z.array(questionSchema).min(1).max(40),
25
+ submitLabel: z.string().trim().max(80).optional(),
26
+ });
27
+ /** `visual-questions` validates with the same schema as `question-form`. */
28
+ export const visualQuestionsSchema = questionFormSchema;
29
+ /**
30
+ * MDX config: `questions` and `submitLabel` are both attributes (the questions
31
+ * array is JSON-encoded by the shared `prop()` encoder). Mirrors the legacy
32
+ * `<QuestionForm questions={[…]} submitLabel="…" />` encoding so stored `.mdx`
33
+ * round-trips byte-compatibly.
34
+ */
35
+ export const questionFormMdx = {
36
+ tag: "QuestionForm",
37
+ toAttrs: (data) => ({
38
+ questions: data.questions,
39
+ submitLabel: data.submitLabel,
40
+ }),
41
+ fromAttrs: (attrs) => ({
42
+ questions: attrs.array("questions") ?? [],
43
+ submitLabel: attrs.string("submitLabel"),
44
+ }),
45
+ };
46
+ /** `visual-questions` uses the historical `<VisualQuestions … />` tag. */
47
+ export const visualQuestionsMdx = {
48
+ tag: "VisualQuestions",
49
+ toAttrs: (data) => ({
50
+ questions: data.questions,
51
+ submitLabel: data.submitLabel,
52
+ }),
53
+ fromAttrs: (attrs) => ({
54
+ questions: attrs.array("questions") ?? [],
55
+ submitLabel: attrs.string("submitLabel"),
56
+ }),
57
+ };
58
+ //# sourceMappingURL=question-form.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-form.config.js","sourceRoot":"","sources":["../../../../src/client/blocks/library/question-form.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+DxB,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,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W,EAAE,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC;KACzC,CAAC;CACH,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { BlockMdxConfig } from \"../types.js\";\n\n/**\n * Pure (React-free) part of the shared `question-form` and `visual-questions`\n * blocks: their data schema and MDX round-trip config. Lives in core so any\n * app's server/shared registry and the client spec (`question-form.tsx`)\n * consume one definition. Keeping it React-free means importing it into a server\n * module never pulls React into the Nitro/SSR bundle.\n *\n * `question-form` is the general-purpose respondent-facing form (Open Questions,\n * single/multi/freeform answers, recommended options, optional inline\n * wireframe/diagram previews). `visual-questions` is the same data shape and UI,\n * branded for an explicit visual-intake flow before a plan. Both originated in\n * the plan template (the data shape mirrors the legacy `visual-questions` block)\n * before moving here, so their MDX `tag` + attribute encoding MUST match the\n * historical `<QuestionForm questions submitLabel />` / `<VisualQuestions … />`\n * forms so stored `.mdx` round-trips byte-compatibly.\n *\n * The per-option `wireframe`/`diagram` previews stay opaque (`unknown`) at the\n * core layer: the core block renders them through `ctx.renderBlock` (the same\n * nested-block seam tabs/columns use) so core never imports an app's wireframe\n * or diagram renderer. Each app supplies the matching `wireframe`/`diagram`\n * block spec and shape.\n */\n\nexport type QuestionMode = \"single\" | \"multi\" | \"freeform\";\n\nexport interface QuestionFormOption {\n id: string;\n label: string;\n detail?: string;\n /** Authored recommendation only (not a runtime answer). */\n recommended?: boolean;\n /**\n * Optional inline visual previews for this option. Kept opaque at the core\n * layer; rendered via `ctx.renderBlock` as a nested `wireframe`/`diagram`\n * block so core stays app-agnostic. Apps validate the concrete shape with\n * their own wireframe/diagram schemas.\n */\n wireframe?: unknown;\n diagram?: unknown;\n}\n\nexport interface QuestionFormQuestion {\n id: string;\n title: string;\n subtitle?: string;\n mode: QuestionMode;\n options?: QuestionFormOption[];\n allowOther?: boolean;\n placeholder?: string;\n required?: boolean;\n}\n\nexport interface QuestionFormData {\n questions: QuestionFormQuestion[];\n submitLabel?: string;\n}\n\n/** `visual-questions` shares the exact `question-form` data shape. */\nexport type VisualQuestionsData = QuestionFormData;\n\nconst idSchema = z.string().trim().min(1).max(120);\n\nconst questionOptionSchema = z.object({\n id: idSchema,\n label: z.string().trim().min(1).max(220),\n detail: z.string().trim().max(800).optional(),\n recommended: z.boolean().optional(),\n // Opaque at the core layer — the inline preview renders via `ctx.renderBlock`\n // with the app's own wireframe/diagram block spec; the app validates the shape.\n wireframe: z.unknown().optional(),\n diagram: z.unknown().optional(),\n}) as z.ZodType<QuestionFormOption>;\n\nconst questionSchema = z.object({\n id: idSchema,\n title: z.string().trim().min(1).max(260),\n subtitle: z.string().trim().max(700).optional(),\n mode: z.enum([\"single\", \"multi\", \"freeform\"]),\n options: z.array(questionOptionSchema).max(40).optional(),\n allowOther: z.boolean().optional(),\n placeholder: z.string().trim().max(240).optional(),\n required: z.boolean().optional(),\n}) as z.ZodType<QuestionFormQuestion>;\n\nexport const questionFormSchema = z.object({\n questions: z.array(questionSchema).min(1).max(40),\n submitLabel: z.string().trim().max(80).optional(),\n}) as unknown as z.ZodType<QuestionFormData>;\n\n/** `visual-questions` validates with the same schema as `question-form`. */\nexport const visualQuestionsSchema =\n questionFormSchema as unknown as z.ZodType<VisualQuestionsData>;\n\n/**\n * MDX config: `questions` and `submitLabel` are both attributes (the questions\n * array is JSON-encoded by the shared `prop()` encoder). Mirrors the legacy\n * `<QuestionForm questions={[…]} submitLabel=\"…\" />` encoding so stored `.mdx`\n * round-trips byte-compatibly.\n */\nexport const questionFormMdx: BlockMdxConfig<QuestionFormData> = {\n tag: \"QuestionForm\",\n toAttrs: (data) => ({\n questions: data.questions,\n submitLabel: data.submitLabel,\n }),\n fromAttrs: (attrs) => ({\n questions: attrs.array<QuestionFormQuestion>(\"questions\") ?? [],\n submitLabel: attrs.string(\"submitLabel\"),\n }),\n};\n\n/** `visual-questions` uses the historical `<VisualQuestions … />` tag. */\nexport const visualQuestionsMdx: BlockMdxConfig<VisualQuestionsData> = {\n tag: \"VisualQuestions\",\n toAttrs: (data) => ({\n questions: data.questions,\n submitLabel: data.submitLabel,\n }),\n fromAttrs: (attrs) => ({\n questions: attrs.array<QuestionFormQuestion>(\"questions\") ?? [],\n submitLabel: attrs.string(\"submitLabel\"),\n }),\n};\n"]}
@@ -0,0 +1,20 @@
1
+ import type { BlockReadProps, BlockEditProps } from "../types.js";
2
+ import { type QuestionFormData, type VisualQuestionsData } from "./question-form.config.js";
3
+ export declare function QuestionFormRead(props: BlockReadProps<QuestionFormData>): import("react/jsx-runtime").JSX.Element;
4
+ export declare function VisualQuestionsRead(props: BlockReadProps<VisualQuestionsData>): import("react/jsx-runtime").JSX.Element;
5
+ /** Shared editor for both `question-form` and `visual-questions`. */
6
+ export declare function QuestionFormEdit({ data, onChange, editable, }: BlockEditProps<QuestionFormData>): import("react/jsx-runtime").JSX.Element;
7
+ /**
8
+ * Full client spec for the shared `question-form` block. A respondent-facing
9
+ * intake form edited from the block panel (the schema-ish question shape lives
10
+ * behind the edit surface, not inline).
11
+ */
12
+ export declare const questionFormBlock: import("../types.js").BlockSpec<QuestionFormData>;
13
+ /**
14
+ * Full client spec for the shared `visual-questions` block — the same form UI
15
+ * and data shape as `question-form`, branded for explicit visual intake before a
16
+ * plan. Shares the Read/Edit internals; only the type, MDX tag, label, and seed
17
+ * differ.
18
+ */
19
+ export declare const visualQuestionsBlock: import("../types.js").BlockSpec<QuestionFormData>;
20
+ //# sourceMappingURL=question-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"question-form.d.ts","sourceRoot":"","sources":["../../../../src/client/blocks/library/question-form.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAGf,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,gBAAgB,EAIrB,KAAK,mBAAmB,EACzB,MAAM,2BAA2B,CAAC;AAoanC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,CAAC,gBAAgB,CAAC,2CAEvE;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,cAAc,CAAC,mBAAmB,CAAC,2CAG3C;AAaD,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,QAAQ,GACT,EAAE,cAAc,CAAC,gBAAgB,CAAC,2CAsTlC;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,mDAsB5B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,mDAmC/B,CAAC"}