@agent-native/core 0.42.0 → 0.43.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.
- package/README.md +17 -56
- package/dist/cli/recap.d.ts.map +1 -1
- package/dist/cli/recap.js +24 -13
- package/dist/cli/recap.js.map +1 -1
- package/dist/cli/skills.d.ts +2 -6
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +8 -66
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/blocks/index.d.ts +11 -0
- package/dist/client/blocks/index.d.ts.map +1 -1
- package/dist/client/blocks/index.js +11 -0
- package/dist/client/blocks/index.js.map +1 -1
- package/dist/client/blocks/library/AnnotatedCodeBlock.d.ts.map +1 -1
- package/dist/client/blocks/library/AnnotatedCodeBlock.js +2 -2
- package/dist/client/blocks/library/AnnotatedCodeBlock.js.map +1 -1
- package/dist/client/blocks/library/DiffBlock.d.ts.map +1 -1
- package/dist/client/blocks/library/DiffBlock.js +86 -21
- package/dist/client/blocks/library/DiffBlock.js.map +1 -1
- package/dist/client/blocks/library/FileTreeBlock.d.ts.map +1 -1
- package/dist/client/blocks/library/FileTreeBlock.js +27 -4
- package/dist/client/blocks/library/FileTreeBlock.js.map +1 -1
- package/dist/client/blocks/library/JsonExplorerBlock.js +1 -1
- package/dist/client/blocks/library/JsonExplorerBlock.js.map +1 -1
- package/dist/client/blocks/library/MermaidBlock.js +1 -1
- package/dist/client/blocks/library/MermaidBlock.js.map +1 -1
- package/dist/client/blocks/library/annotation-rail.d.ts +19 -0
- package/dist/client/blocks/library/annotation-rail.d.ts.map +1 -1
- package/dist/client/blocks/library/annotation-rail.js +19 -0
- package/dist/client/blocks/library/annotation-rail.js.map +1 -1
- package/dist/client/blocks/library/callout.config.d.ts +29 -0
- package/dist/client/blocks/library/callout.config.d.ts.map +1 -0
- package/dist/client/blocks/library/callout.config.js +33 -0
- package/dist/client/blocks/library/callout.config.js.map +1 -0
- package/dist/client/blocks/library/callout.d.ts +20 -0
- package/dist/client/blocks/library/callout.d.ts.map +1 -0
- package/dist/client/blocks/library/callout.js +61 -0
- package/dist/client/blocks/library/callout.js.map +1 -0
- package/dist/client/blocks/library/checklist.d.ts.map +1 -1
- package/dist/client/blocks/library/checklist.js +3 -3
- package/dist/client/blocks/library/checklist.js.map +1 -1
- package/dist/client/blocks/library/decision.config.d.ts +37 -0
- package/dist/client/blocks/library/decision.config.d.ts.map +1 -0
- package/dist/client/blocks/library/decision.config.js +32 -0
- package/dist/client/blocks/library/decision.config.js.map +1 -0
- package/dist/client/blocks/library/decision.d.ts +19 -0
- package/dist/client/blocks/library/decision.d.ts.map +1 -0
- package/dist/client/blocks/library/decision.js +119 -0
- package/dist/client/blocks/library/decision.js.map +1 -0
- package/dist/client/blocks/library/diagram.config.d.ts +64 -0
- package/dist/client/blocks/library/diagram.config.d.ts.map +1 -0
- package/dist/client/blocks/library/diagram.config.js +111 -0
- package/dist/client/blocks/library/diagram.config.js.map +1 -0
- package/dist/client/blocks/library/diagram.d.ts +16 -0
- package/dist/client/blocks/library/diagram.d.ts.map +1 -0
- package/dist/client/blocks/library/diagram.js +261 -0
- package/dist/client/blocks/library/diagram.js.map +1 -0
- package/dist/client/blocks/library/question-form.config.d.ts +69 -0
- package/dist/client/blocks/library/question-form.config.d.ts.map +1 -0
- package/dist/client/blocks/library/question-form.config.js +58 -0
- package/dist/client/blocks/library/question-form.config.js.map +1 -0
- package/dist/client/blocks/library/question-form.d.ts +20 -0
- package/dist/client/blocks/library/question-form.d.ts.map +1 -0
- package/dist/client/blocks/library/question-form.js +286 -0
- package/dist/client/blocks/library/question-form.js.map +1 -0
- package/dist/client/blocks/library/sanitize-html.d.ts +5 -0
- package/dist/client/blocks/library/sanitize-html.d.ts.map +1 -0
- package/dist/client/blocks/library/sanitize-html.js +240 -0
- package/dist/client/blocks/library/sanitize-html.js.map +1 -0
- package/dist/client/blocks/library/server-specs.d.ts.map +1 -1
- package/dist/client/blocks/library/server-specs.js +59 -0
- package/dist/client/blocks/library/server-specs.js.map +1 -1
- package/dist/client/blocks/library/specs.d.ts.map +1 -1
- package/dist/client/blocks/library/specs.js +11 -0
- package/dist/client/blocks/library/specs.js.map +1 -1
- package/dist/client/blocks/library/tabs.d.ts.map +1 -1
- package/dist/client/blocks/library/tabs.js +12 -12
- package/dist/client/blocks/library/tabs.js.map +1 -1
- package/dist/client/blocks/library/wireframe-kit.d.ts +260 -0
- package/dist/client/blocks/library/wireframe-kit.d.ts.map +1 -0
- package/dist/client/blocks/library/wireframe-kit.js +920 -0
- package/dist/client/blocks/library/wireframe-kit.js.map +1 -0
- package/dist/client/blocks/library/wireframe.config.d.ts +123 -0
- package/dist/client/blocks/library/wireframe.config.d.ts.map +1 -0
- package/dist/client/blocks/library/wireframe.config.js +294 -0
- package/dist/client/blocks/library/wireframe.config.js.map +1 -0
- package/dist/client/blocks/library/wireframe.d.ts +15 -0
- package/dist/client/blocks/library/wireframe.d.ts.map +1 -0
- package/dist/client/blocks/library/wireframe.js +206 -0
- package/dist/client/blocks/library/wireframe.js.map +1 -0
- package/dist/client/blocks/registry.d.ts +9 -0
- package/dist/client/blocks/registry.d.ts.map +1 -1
- package/dist/client/blocks/registry.js +12 -5
- package/dist/client/blocks/registry.js.map +1 -1
- package/dist/client/blocks/server.d.ts +1 -0
- package/dist/client/blocks/server.d.ts.map +1 -1
- package/dist/client/blocks/server.js +1 -0
- package/dist/client/blocks/server.js.map +1 -1
- package/dist/client/blocks/types.d.ts +8 -0
- package/dist/client/blocks/types.d.ts.map +1 -1
- package/dist/client/blocks/types.js.map +1 -1
- package/dist/client/rich-markdown-editor/DragHandle.d.ts.map +1 -1
- package/dist/client/rich-markdown-editor/DragHandle.js +77 -12
- package/dist/client/rich-markdown-editor/DragHandle.js.map +1 -1
- package/dist/styles/agent-native.css +1 -0
- package/dist/styles/blocks.css +1380 -0
- package/docs/content/plan-plugin.md +8 -8
- package/docs/content/pr-visual-recap.md +2 -2
- package/docs/content/template-plan.md +94 -17
- package/package.json +2 -1
- package/docs/content/visual-plans.md +0 -82
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../../../../src/client/blocks/library/decision.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,GACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EACL,WAAW,EACX,cAAc,GAGf,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,IAAI,EACJ,OAAO,EACP,KAAK,GACwB;IAC7B,OAAO,CACL,mBAAS,SAAS,EAAC,qBAAqB,mBAAgB,OAAO,aAC5D,KAAK,IAAI,cAAK,SAAS,EAAC,iCAAiC,YAAE,KAAK,GAAO,EACxE,YAAG,SAAS,EAAC,wDAAwD,YAClE,IAAI,CAAC,QAAQ,GACZ,EACJ,cAAK,SAAS,EAAC,gCAAgC,YAC5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAC5B,mBAEE,SAAS,EAAE,EAAE,CACX,8CAA8C,EAC9C,MAAM,CAAC,WAAW;wBAChB,CAAC,CAAC,yCAAyC;wBAC3C,CAAC,CAAC,YAAY,CACjB,aAED,eAAK,SAAS,EAAC,wCAAwC,aACrD,aAAI,SAAS,EAAC,sDAAsD,YACjE,MAAM,CAAC,KAAK,GACV,EACJ,MAAM,CAAC,WAAW,IAAI,CACrB,eAAM,SAAS,EAAC,yHAAyH,4BAElI,CACR,IACG,EACL,MAAM,CAAC,MAAM,IAAI,CAChB,YAAG,SAAS,EAAC,8CAA8C,YACxD,MAAM,CAAC,MAAM,GACZ,CACL,KA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AA+E;IAC/E,iFAAiF;IACjF,iFAAiF;IACjF,iFAAiF;IACjF,WAAW,EAAE,OAAO;IACpB,KAAK,EAAE,UAAU;IACjB,WAAW,EACT,wKAAwK;IAC1K,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QACZ,QAAQ,EAAE,gDAAgD;QAC1D,OAAO,EAAE;YACP;gBACE,EAAE,EAAE,aAAa;gBACjB,KAAK,EAAE,kBAAkB;gBACzB,MAAM,EAAE,4CAA4C;gBACpD,WAAW,EAAE,IAAI;aAClB;YACD;gBACE,EAAE,EAAE,aAAa;gBACjB,KAAK,EAAE,aAAa;gBACpB,MAAM,EAAE,0CAA0C;aACnD;SACF;KACF,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { useState } from \"react\";\nimport {\n IconCheck,\n IconPencil,\n IconPlus,\n IconTrash,\n} from \"@tabler/icons-react\";\nimport { cn } from \"../../utils.js\";\nimport { defineBlock } from \"../types.js\";\nimport type { BlockReadProps, BlockEditProps } from \"../types.js\";\nimport {\n decisionMdx,\n decisionSchema,\n type DecisionData,\n type DecisionOption,\n} from \"./decision.config.js\";\n\n/**\n * Standard `decision` block — a decision prompt with inline-editable option\n * cards and one authored \"recommended\" choice. Lives in core so any app can\n * register it (it originated in the plan template).\n *\n * The root `<section>` keeps the app-neutral `an-block` class (document-flow\n * spacing hook) alongside the legacy `plan-block` class (styled by the plan\n * template's own stylesheet), so plan renders as before and any other app gets\n * theme-token styling. All inner color comes from shadcn theme tokens\n * (`text-muted-foreground`, `text-foreground`, `bg-muted`, `bg-background`,\n * `border-border`, `ring`), so it reads correctly in any template palette.\n */\nexport function DecisionBlock({\n data,\n blockId,\n title,\n}: BlockReadProps<DecisionData>) {\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 <p className=\"mt-3 max-w-3xl text-lg leading-8 text-muted-foreground\">\n {data.question}\n </p>\n <div className=\"mt-6 grid gap-3 md:grid-cols-2\">\n {data.options.map((option) => (\n <article\n key={option.id}\n className={cn(\n \"rounded-xl border border-border bg-muted p-4\",\n option.recommended\n ? \"shadow-[inset_3px_0_0_hsl(var(--ring))]\"\n : \"opacity-85\",\n )}\n >\n <div className=\"flex items-start justify-between gap-3\">\n <h3 className=\"text-lg font-semibold tracking-tight text-foreground\">\n {option.label}\n </h3>\n {option.recommended && (\n <span className=\"rounded-full border border-border px-2 py-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground\">\n Recommended\n </span>\n )}\n </div>\n {option.detail && (\n <p className=\"mt-3 text-sm leading-6 text-muted-foreground\">\n {option.detail}\n </p>\n )}\n </article>\n ))}\n </div>\n </section>\n );\n}\n\nconst inlineInputClass =\n \"w-full rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground shadow-sm outline-none transition-colors placeholder:text-muted-foreground focus:border-ring\";\nconst inlineTextareaClass =\n \"w-full resize-y rounded-md border border-border bg-background px-3 py-2 text-sm leading-6 text-foreground shadow-sm outline-none transition-colors placeholder:text-muted-foreground focus:border-ring\";\nconst inlineLabelClass =\n \"text-[11px] font-semibold uppercase tracking-[0.08em] text-muted-foreground\";\n\nfunction newLocalId(prefix: string): string {\n return `${prefix}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nexport function DecisionBlockEdit({\n data,\n onChange,\n editable,\n blockId,\n title,\n summary,\n ctx,\n}: BlockEditProps<DecisionData>) {\n const updateOption = (optionId: string, patch: Partial<DecisionOption>) =>\n onChange({\n ...data,\n options: data.options.map((option) =>\n option.id === optionId ? { ...option, ...patch } : option,\n ),\n });\n\n const removeOption = (optionId: string) => {\n if (data.options.length <= 1) return;\n onChange({\n ...data,\n options: data.options.filter((option) => option.id !== optionId),\n });\n };\n\n const addOption = () => {\n if (data.options.length >= 20) return;\n onChange({\n ...data,\n options: [\n ...data.options,\n { id: newLocalId(\"option\"), label: \"New option\" },\n ],\n });\n };\n\n const settings = editable\n ? (ctx.renderEditSurface?.({\n title: \"Decision\",\n blockId,\n blockType: \"decision\",\n blockTitle: title,\n blockSummary: summary,\n blockData: data,\n trigger: (\n <button\n type=\"button\"\n data-plan-interactive\n aria-label=\"Edit decision options\"\n className=\"flex size-9 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground\"\n >\n <IconPencil className=\"size-4\" />\n </button>\n ),\n children: (\n <DecisionSettings\n options={data.options}\n onToggleRecommended={(option) =>\n updateOption(option.id, { recommended: !option.recommended })\n }\n onRemove={removeOption}\n onAdd={addOption}\n />\n ),\n }) ?? (\n // No panel surface provided by the host: fall back to a plain inline\n // settings card so option management still works.\n <DecisionInlineSettings\n options={data.options}\n onToggleRecommended={(option) =>\n updateOption(option.id, { recommended: !option.recommended })\n }\n onRemove={removeOption}\n onAdd={addOption}\n />\n ))\n : null;\n\n return (\n <div className=\"grid gap-5\" data-plan-interactive>\n <div className=\"flex items-start gap-3\">\n <label className=\"grid min-w-0 flex-1 gap-1.5\">\n <span className={inlineLabelClass}>Question</span>\n <textarea\n className={inlineTextareaClass}\n rows={2}\n value={data.question}\n disabled={!editable}\n onChange={(event) =>\n onChange({ ...data, question: event.target.value })\n }\n />\n </label>\n {settings}\n </div>\n <div className=\"grid gap-3\">\n {data.options.map((option) => (\n <article\n key={option.id}\n className={cn(\n \"rounded-lg border border-border bg-muted p-4\",\n option.recommended &&\n \"border-ring/60 shadow-[inset_3px_0_0_hsl(var(--ring))]\",\n )}\n >\n <div className=\"grid gap-3\">\n <label className=\"grid gap-1.5\">\n <span className={inlineLabelClass}>Option</span>\n <input\n className={inlineInputClass}\n value={option.label}\n disabled={!editable}\n onChange={(event) =>\n updateOption(option.id, { label: event.target.value })\n }\n />\n </label>\n </div>\n <label className=\"mt-3 grid gap-1.5\">\n <span className={inlineLabelClass}>Detail</span>\n <textarea\n className={inlineTextareaClass}\n rows={2}\n value={option.detail ?? \"\"}\n disabled={!editable}\n onChange={(event) =>\n updateOption(option.id, {\n detail: event.target.value || undefined,\n })\n }\n />\n </label>\n </article>\n ))}\n </div>\n </div>\n );\n}\n\n/** Option-management controls rendered inside the host's edit surface popover. */\nfunction DecisionSettings({\n options,\n onToggleRecommended,\n onRemove,\n onAdd,\n}: {\n options: DecisionOption[];\n onToggleRecommended: (option: DecisionOption) => void;\n onRemove: (optionId: string) => void;\n onAdd: () => void;\n}) {\n return (\n <div className=\"grid gap-3\">\n <div className=\"text-sm font-semibold text-foreground\">\n Decision settings\n </div>\n <div className=\"grid gap-2\">\n {options.map((option, index) => (\n <div\n key={option.id}\n className=\"grid gap-2 rounded-md border border-border bg-muted/20 p-2\"\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"min-w-0 truncate text-xs font-medium text-foreground\">\n {option.label.trim() || `Option ${index + 1}`}\n </span>\n {option.recommended && (\n <span className=\"shrink-0 rounded-full border border-border px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground\">\n Recommended\n </span>\n )}\n </div>\n <div className=\"flex items-center gap-2\">\n <button\n type=\"button\"\n data-plan-interactive\n onClick={() => onToggleRecommended(option)}\n className={cn(\n \"inline-flex h-8 flex-1 items-center justify-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors\",\n option.recommended\n ? \"bg-background text-foreground shadow-sm\"\n : \"text-muted-foreground hover:bg-background/70 hover:text-foreground\",\n )}\n >\n {option.recommended && <IconCheck className=\"size-3.5\" />}\n {option.recommended ? \"Recommended\" : \"Mark recommended\"}\n </button>\n <button\n type=\"button\"\n data-plan-interactive\n aria-label={`Delete ${option.label || `option ${index + 1}`}`}\n disabled={options.length <= 1}\n onClick={() => onRemove(option.id)}\n className=\"inline-flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-destructive transition-colors hover:bg-destructive/10 disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <IconTrash className=\"size-3.5\" />\n </button>\n </div>\n </div>\n ))}\n </div>\n <button\n type=\"button\"\n data-plan-interactive\n disabled={options.length >= 20}\n onClick={onAdd}\n className=\"inline-flex h-8 items-center justify-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50\"\n >\n <IconPlus className=\"size-3.5\" />\n Add option\n </button>\n </div>\n );\n}\n\n/**\n * Fallback for hosts that do not provide `ctx.renderEditSurface`: a plain\n * disclosure button that reveals the same settings inline (no overlay primitive,\n * so core stays shadcn-free).\n */\nfunction DecisionInlineSettings(props: {\n options: DecisionOption[];\n onToggleRecommended: (option: DecisionOption) => void;\n onRemove: (optionId: string) => void;\n onAdd: () => void;\n}) {\n const [open, setOpen] = useState(false);\n return (\n <div className=\"grid gap-2\">\n <button\n type=\"button\"\n data-plan-interactive\n aria-label=\"Edit decision options\"\n aria-expanded={open}\n onClick={() => setOpen((value) => !value)}\n className=\"flex size-9 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground\"\n >\n <IconPencil className=\"size-4\" />\n </button>\n {open && (\n <div className=\"w-80 rounded-md border border-border bg-background p-3 shadow-sm\">\n <DecisionSettings {...props} />\n </div>\n )}\n </div>\n );\n}\n\n/** Full client spec for the shared `decision` block (schema + MDX + Read/Edit). */\nexport const decisionBlock = defineBlock<DecisionData>({\n type: \"decision\",\n schema: decisionSchema,\n mdx: decisionMdx,\n Read: DecisionBlock,\n Edit: DecisionBlockEdit,\n placement: [\"block\"],\n // `panel`: the document shows the clean read view (question + option cards with\n // the recommended pick highlighted), and the corner pencil opens the editor in\n // a popover. NOT `inline` — an inline schema-editing form (question + per-option\n // textareas) rendered straight into the doc reads as a confusing data-entry wall\n // rather than a decision. Mirrors how `question-form` / `visual-questions` edit.\n editSurface: \"panel\",\n label: \"Decision\",\n description:\n \"A decision prompt with option cards and an authored recommended choice. Shows a clean read view in the document; edit the question and options from the corner pencil.\",\n empty: () => ({\n question: \"Which implementation direction should we take?\",\n options: [\n {\n id: \"recommended\",\n label: \"Recommended path\",\n detail: \"Smallest useful slice with clear rollback.\",\n recommended: true,\n },\n {\n id: \"alternative\",\n label: \"Alternative\",\n detail: \"Broader pass that touches more surfaces.\",\n },\n ],\n }),\n});\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { BlockMdxConfig } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Pure (React-free) part of the shared `diagram` block: its data schema and MDX
|
|
5
|
+
* round-trip config. Lives in core so BOTH apps' server/shared registries
|
|
6
|
+
* (`plan-block-registry.ts`, `nfm-registry.ts`) and the client spec
|
|
7
|
+
* (`diagram.tsx`) consume one definition. Keeping it React-free means importing
|
|
8
|
+
* it into a server module never pulls React into the Nitro/SSR bundle.
|
|
9
|
+
*
|
|
10
|
+
* The MDX `tag` + attribute shape MUST match the legacy `<Diagram … data={…} />`
|
|
11
|
+
* encoding — the whole `data` object is serialized as one JSON `data` prop — so
|
|
12
|
+
* stored `.mdx` round-trips byte-compatibly (the block originated in the plan
|
|
13
|
+
* template before moving here).
|
|
14
|
+
*/
|
|
15
|
+
export interface DiagramNode {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
detail?: string;
|
|
19
|
+
x?: number;
|
|
20
|
+
y?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface DiagramEdge {
|
|
23
|
+
from: string;
|
|
24
|
+
to: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface DiagramNote {
|
|
28
|
+
id: string;
|
|
29
|
+
text: string;
|
|
30
|
+
x?: number;
|
|
31
|
+
y?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface DiagramData {
|
|
34
|
+
/**
|
|
35
|
+
* Preferred authoring path for architecture/code diagrams: a scoped, inert
|
|
36
|
+
* HTML/SVG fragment. Use .diagram-* primitives and --wf-* tokens; the
|
|
37
|
+
* renderer supplies theme-token-backed styling plus sketch/clean style hooks.
|
|
38
|
+
*/
|
|
39
|
+
html?: string;
|
|
40
|
+
css?: string;
|
|
41
|
+
caption?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Legacy compatibility path for older/simple node graphs. New plans should use
|
|
44
|
+
* `html`/`css` when layout quality matters.
|
|
45
|
+
*/
|
|
46
|
+
nodes?: DiagramNode[];
|
|
47
|
+
edges?: DiagramEdge[];
|
|
48
|
+
notes?: DiagramNote[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The block can be a flexible HTML/SVG fragment or a legacy positional
|
|
52
|
+
* node/edge/note graph, so it ships a custom `Edit` rather than relying on the
|
|
53
|
+
* schema auto-editor. Editing stays comment/patch-driven.
|
|
54
|
+
*/
|
|
55
|
+
export declare const diagramSchema: z.ZodType<DiagramData>;
|
|
56
|
+
/**
|
|
57
|
+
* MDX config: the entire `data` object is serialized as one JSON `data` prop and
|
|
58
|
+
* the element is self-closing — exactly the legacy `<Diagram id … data={…} />`
|
|
59
|
+
* form. `toAttrs` returns `{ data }`; `fromAttrs` reads the `data` object,
|
|
60
|
+
* mirroring the legacy `dataAttr(node, "data") ?? { nodes: [], edges: [] }`
|
|
61
|
+
* default so plans missing the prop still parse.
|
|
62
|
+
*/
|
|
63
|
+
export declare const diagramMdx: BlockMdxConfig<DiagramData>;
|
|
64
|
+
//# sourceMappingURL=diagram.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagram.config.d.ts","sourceRoot":"","sources":["../../../../src/client/blocks/library/diagram.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;CACvB;AAoED;;;;GAIG;AACH,eAAO,MAAM,aAAa,EA8BP,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1C;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,WAAW,CAWlD,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const idSchema = z.string().trim().min(1).max(120);
|
|
3
|
+
const unsafeDiagramHtmlPattern = /(?:<!doctype|<\/?(?:html|head|body|script|style|iframe|object|embed|link|meta|base|form|math|foreignObject|noscript|frame|frameset|applet|portal|marquee)[\s>/]|@(?:import|font-face|keyframes|page|namespace|charset)\b|\b(?:java\s*script|vb\s*script|data\s*:\s*(?:text\/html|image\/svg\+xml))\s*:?\s*|\bsrcdoc\s*=|(?:^|\s)(?:on[a-z][\w:-]*|@[\w:.-]+|x-on:[\w:.-]+|:on[a-z][\w:-]*|x-bind:on[a-z][\w:-]*|:style|x-bind:style)\s*=|expression\s*\(|url\s*\(\s*['"]?\s*(?:java\s*script|vb\s*script|data\s*:\s*(?:text\/html|image\/svg\+xml)))/i;
|
|
4
|
+
const unsafeViewportCssPattern = /(?:^|[;{\s])position\s*:\s*(?:fixed|sticky)\b|(?:^|[;{\s])z-index\s*:\s*[1-9]\d{4,}\b/i;
|
|
5
|
+
function decodeSafetyEntities(value) {
|
|
6
|
+
return value
|
|
7
|
+
.replace(/&#(x[0-9a-f]+|\d+);?/gi, (_, code) => {
|
|
8
|
+
const point = code.toLowerCase().startsWith("x")
|
|
9
|
+
? Number.parseInt(code.slice(1), 16)
|
|
10
|
+
: Number.parseInt(code, 10);
|
|
11
|
+
return Number.isFinite(point) ? String.fromCodePoint(point) : "";
|
|
12
|
+
})
|
|
13
|
+
.replace(/&(colon|tab|newline);/gi, (_, name) => {
|
|
14
|
+
if (name.toLowerCase() === "colon")
|
|
15
|
+
return ":";
|
|
16
|
+
if (name.toLowerCase() === "tab")
|
|
17
|
+
return "\t";
|
|
18
|
+
return "\n";
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function decodeCssSafetyEscapes(value) {
|
|
22
|
+
return value.replace(/\\([0-9a-fA-F]{1,6}\s?|.)/g, (_match, escaped) => {
|
|
23
|
+
const hex = String(escaped).match(/^[0-9a-fA-F]{1,6}/)?.[0];
|
|
24
|
+
if (hex) {
|
|
25
|
+
const point = Number.parseInt(hex, 16);
|
|
26
|
+
return Number.isFinite(point) ? String.fromCodePoint(point) : "";
|
|
27
|
+
}
|
|
28
|
+
return String(escaped)[0] ?? "";
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function noActiveDiagramText(value) {
|
|
32
|
+
const decoded = decodeCssSafetyEscapes(decodeSafetyEntities(value));
|
|
33
|
+
const compact = decoded.toLowerCase().replace(/[\u0000-\u0020]+/g, "");
|
|
34
|
+
return (!unsafeDiagramHtmlPattern.test(value) &&
|
|
35
|
+
!unsafeDiagramHtmlPattern.test(decoded) &&
|
|
36
|
+
!unsafeViewportCssPattern.test(decoded) &&
|
|
37
|
+
!/(?:javascript|vbscript):|data:(?:text\/html|image\/svg\+xml)|expression\(|url\(['"]?(?:javascript|vbscript|data:(?:text\/html|image\/svg\+xml))/.test(compact));
|
|
38
|
+
}
|
|
39
|
+
const diagramNodeSchema = z.object({
|
|
40
|
+
id: idSchema,
|
|
41
|
+
label: z.string().trim().min(1).max(160),
|
|
42
|
+
detail: z.string().trim().max(500).optional(),
|
|
43
|
+
x: z.number().min(0).max(100).optional(),
|
|
44
|
+
y: z.number().min(0).max(100).optional(),
|
|
45
|
+
});
|
|
46
|
+
const diagramEdgeSchema = z.object({
|
|
47
|
+
from: idSchema,
|
|
48
|
+
to: idSchema,
|
|
49
|
+
label: z.string().trim().max(100).optional(),
|
|
50
|
+
});
|
|
51
|
+
const diagramNoteSchema = z.object({
|
|
52
|
+
id: idSchema,
|
|
53
|
+
text: z.string().trim().min(1).max(500),
|
|
54
|
+
x: z.number().min(0).max(100).optional(),
|
|
55
|
+
y: z.number().min(0).max(100).optional(),
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* The block can be a flexible HTML/SVG fragment or a legacy positional
|
|
59
|
+
* node/edge/note graph, so it ships a custom `Edit` rather than relying on the
|
|
60
|
+
* schema auto-editor. Editing stays comment/patch-driven.
|
|
61
|
+
*/
|
|
62
|
+
export const diagramSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
html: z
|
|
65
|
+
.string()
|
|
66
|
+
.trim()
|
|
67
|
+
.max(100_000)
|
|
68
|
+
.refine(noActiveDiagramText, {
|
|
69
|
+
message: "Diagram html must be an inert fragment; SVG is allowed, scripts/events are not.",
|
|
70
|
+
})
|
|
71
|
+
.optional(),
|
|
72
|
+
css: z
|
|
73
|
+
.string()
|
|
74
|
+
.max(50_000)
|
|
75
|
+
.refine(noActiveDiagramText, {
|
|
76
|
+
message: "Diagram css must not include document or script tags.",
|
|
77
|
+
})
|
|
78
|
+
.optional(),
|
|
79
|
+
caption: z.string().trim().max(600).optional(),
|
|
80
|
+
nodes: z.array(diagramNodeSchema).max(80).optional(),
|
|
81
|
+
edges: z.array(diagramEdgeSchema).max(120).optional(),
|
|
82
|
+
notes: z.array(diagramNoteSchema).max(40).optional(),
|
|
83
|
+
})
|
|
84
|
+
.superRefine((data, ctx) => {
|
|
85
|
+
if (data.html?.trim() || (data.nodes?.length ?? 0) > 0)
|
|
86
|
+
return;
|
|
87
|
+
ctx.addIssue({
|
|
88
|
+
code: "custom",
|
|
89
|
+
path: ["html"],
|
|
90
|
+
message: "Diagram block requires html or at least one node.",
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* MDX config: the entire `data` object is serialized as one JSON `data` prop and
|
|
95
|
+
* the element is self-closing — exactly the legacy `<Diagram id … data={…} />`
|
|
96
|
+
* form. `toAttrs` returns `{ data }`; `fromAttrs` reads the `data` object,
|
|
97
|
+
* mirroring the legacy `dataAttr(node, "data") ?? { nodes: [], edges: [] }`
|
|
98
|
+
* default so plans missing the prop still parse.
|
|
99
|
+
*/
|
|
100
|
+
export const diagramMdx = {
|
|
101
|
+
tag: "Diagram",
|
|
102
|
+
// The whole data object becomes one JSON `data` prop. Cast to the
|
|
103
|
+
// structured-attr member of `MdxAttrValue` — `DiagramData` is a closed
|
|
104
|
+
// interface without an index signature, which the union member requires.
|
|
105
|
+
toAttrs: (data) => ({ data: data }),
|
|
106
|
+
fromAttrs: (attrs) => (attrs.object("data") ?? {
|
|
107
|
+
nodes: [],
|
|
108
|
+
edges: [],
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=diagram.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagram.config.js","sourceRoot":"","sources":["../../../../src/client/blocks/library/diagram.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuDxB,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CA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,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IAC9C,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;IACpD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;IACrD,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;CACrD,CAAC;KACD,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IACzB,IAAI,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC;QAAE,OAAO;IAC/D,GAAG,CAAC,QAAQ,CAAC;QACX,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,CAAC,MAAM,CAAC;QACd,OAAO,EAAE,mDAAmD;KAC7D,CAAC,CAAC;AACL,CAAC,CAAsC,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAgC;IACrD,GAAG,EAAE,SAAS;IACd,kEAAkE;IAClE,uEAAuE;IACvE,yEAAyE;IACzE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAA0C,EAAE,CAAC;IACzE,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,CAAC,KAAK,CAAC,MAAM,CAAc,MAAM,CAAC,IAAI;QACpC,KAAK,EAAE,EAAE;QACT,KAAK,EAAE,EAAE;KACV,CAAgB;CACpB,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { BlockMdxConfig } from \"../types.js\";\n\n/**\n * Pure (React-free) part of the shared `diagram` block: its data schema and MDX\n * round-trip config. Lives in core so BOTH apps' server/shared registries\n * (`plan-block-registry.ts`, `nfm-registry.ts`) and the client spec\n * (`diagram.tsx`) consume one definition. Keeping it React-free means importing\n * it into a server module never pulls React into the Nitro/SSR bundle.\n *\n * The MDX `tag` + attribute shape MUST match the legacy `<Diagram … data={…} />`\n * encoding — the whole `data` object is serialized as one JSON `data` prop — so\n * stored `.mdx` round-trips byte-compatibly (the block originated in the plan\n * template before moving here).\n */\n\nexport interface DiagramNode {\n id: string;\n label: string;\n detail?: string;\n x?: number;\n y?: number;\n}\n\nexport interface DiagramEdge {\n from: string;\n to: string;\n label?: string;\n}\n\nexport interface DiagramNote {\n id: string;\n text: string;\n x?: number;\n y?: number;\n}\n\nexport interface DiagramData {\n /**\n * Preferred authoring path for architecture/code diagrams: a scoped, inert\n * HTML/SVG fragment. Use .diagram-* primitives and --wf-* tokens; the\n * renderer supplies theme-token-backed styling plus sketch/clean style hooks.\n */\n html?: string;\n css?: string;\n caption?: string;\n /**\n * Legacy compatibility path for older/simple node graphs. New plans should use\n * `html`/`css` when layout quality matters.\n */\n nodes?: DiagramNode[];\n edges?: DiagramEdge[];\n notes?: DiagramNote[];\n}\n\nconst idSchema = z.string().trim().min(1).max(120);\nconst unsafeDiagramHtmlPattern =\n /(?:<!doctype|<\\/?(?:html|head|body|script|style|iframe|object|embed|link|meta|base|form|math|foreignObject|noscript|frame|frameset|applet|portal|marquee)[\\s>/]|@(?:import|font-face|keyframes|page|namespace|charset)\\b|\\b(?:java\\s*script|vb\\s*script|data\\s*:\\s*(?:text\\/html|image\\/svg\\+xml))\\s*:?\\s*|\\bsrcdoc\\s*=|(?:^|\\s)(?:on[a-z][\\w:-]*|@[\\w:.-]+|x-on:[\\w:.-]+|:on[a-z][\\w:-]*|x-bind:on[a-z][\\w:-]*|:style|x-bind:style)\\s*=|expression\\s*\\(|url\\s*\\(\\s*['\"]?\\s*(?:java\\s*script|vb\\s*script|data\\s*:\\s*(?:text\\/html|image\\/svg\\+xml)))/i;\nconst unsafeViewportCssPattern =\n /(?:^|[;{\\s])position\\s*:\\s*(?:fixed|sticky)\\b|(?:^|[;{\\s])z-index\\s*:\\s*[1-9]\\d{4,}\\b/i;\n\nfunction decodeSafetyEntities(value: string): string {\n return value\n .replace(/&#(x[0-9a-f]+|\\d+);?/gi, (_, code: string) => {\n const point = code.toLowerCase().startsWith(\"x\")\n ? Number.parseInt(code.slice(1), 16)\n : Number.parseInt(code, 10);\n return Number.isFinite(point) ? String.fromCodePoint(point) : \"\";\n })\n .replace(/&(colon|tab|newline);/gi, (_, name: string) => {\n if (name.toLowerCase() === \"colon\") return \":\";\n if (name.toLowerCase() === \"tab\") return \"\\t\";\n return \"\\n\";\n });\n}\n\nfunction decodeCssSafetyEscapes(value: string): string {\n return value.replace(/\\\\([0-9a-fA-F]{1,6}\\s?|.)/g, (_match, escaped) => {\n const hex = String(escaped).match(/^[0-9a-fA-F]{1,6}/)?.[0];\n if (hex) {\n const point = Number.parseInt(hex, 16);\n return Number.isFinite(point) ? String.fromCodePoint(point) : \"\";\n }\n return String(escaped)[0] ?? \"\";\n });\n}\n\nfunction noActiveDiagramText(value: string) {\n const decoded = decodeCssSafetyEscapes(decodeSafetyEntities(value));\n const compact = decoded.toLowerCase().replace(/[\\u0000-\\u0020]+/g, \"\");\n return (\n !unsafeDiagramHtmlPattern.test(value) &&\n !unsafeDiagramHtmlPattern.test(decoded) &&\n !unsafeViewportCssPattern.test(decoded) &&\n !/(?:javascript|vbscript):|data:(?:text\\/html|image\\/svg\\+xml)|expression\\(|url\\(['\"]?(?:javascript|vbscript|data:(?:text\\/html|image\\/svg\\+xml))/.test(\n compact,\n )\n );\n}\n\nconst diagramNodeSchema = z.object({\n id: idSchema,\n label: z.string().trim().min(1).max(160),\n detail: z.string().trim().max(500).optional(),\n x: z.number().min(0).max(100).optional(),\n y: z.number().min(0).max(100).optional(),\n}) as z.ZodType<DiagramNode>;\n\nconst diagramEdgeSchema = z.object({\n from: idSchema,\n to: idSchema,\n label: z.string().trim().max(100).optional(),\n}) as z.ZodType<DiagramEdge>;\n\nconst diagramNoteSchema = z.object({\n id: idSchema,\n text: z.string().trim().min(1).max(500),\n x: z.number().min(0).max(100).optional(),\n y: z.number().min(0).max(100).optional(),\n}) as z.ZodType<DiagramNote>;\n\n/**\n * The block can be a flexible HTML/SVG fragment or a legacy positional\n * node/edge/note graph, so it ships a custom `Edit` rather than relying on the\n * schema auto-editor. Editing stays comment/patch-driven.\n */\nexport const diagramSchema = z\n .object({\n html: z\n .string()\n .trim()\n .max(100_000)\n .refine(noActiveDiagramText, {\n message:\n \"Diagram html must be an inert fragment; SVG is allowed, scripts/events are not.\",\n })\n .optional(),\n css: z\n .string()\n .max(50_000)\n .refine(noActiveDiagramText, {\n message: \"Diagram css must not include document or script tags.\",\n })\n .optional(),\n caption: z.string().trim().max(600).optional(),\n nodes: z.array(diagramNodeSchema).max(80).optional(),\n edges: z.array(diagramEdgeSchema).max(120).optional(),\n notes: z.array(diagramNoteSchema).max(40).optional(),\n })\n .superRefine((data, ctx) => {\n if (data.html?.trim() || (data.nodes?.length ?? 0) > 0) return;\n ctx.addIssue({\n code: \"custom\",\n path: [\"html\"],\n message: \"Diagram block requires html or at least one node.\",\n });\n }) as unknown as z.ZodType<DiagramData>;\n\n/**\n * MDX config: the entire `data` object is serialized as one JSON `data` prop and\n * the element is self-closing — exactly the legacy `<Diagram id … data={…} />`\n * form. `toAttrs` returns `{ data }`; `fromAttrs` reads the `data` object,\n * mirroring the legacy `dataAttr(node, \"data\") ?? { nodes: [], edges: [] }`\n * default so plans missing the prop still parse.\n */\nexport const diagramMdx: BlockMdxConfig<DiagramData> = {\n tag: \"Diagram\",\n // The whole data object becomes one JSON `data` prop. Cast to the\n // structured-attr member of `MdxAttrValue` — `DiagramData` is a closed\n // interface without an index signature, which the union member requires.\n toAttrs: (data) => ({ data: data as unknown as Record<string, unknown> }),\n fromAttrs: (attrs) =>\n (attrs.object<DiagramData>(\"data\") ?? {\n nodes: [],\n edges: [],\n }) as DiagramData,\n};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BlockReadProps, BlockEditProps } from "../types.js";
|
|
2
|
+
import { type DiagramData } from "./diagram.config.js";
|
|
3
|
+
/** Read-only renderer: the diagram body wrapped in the standard titled block. */
|
|
4
|
+
export declare function DiagramRead({ data, blockId, title, summary, ctx, }: BlockReadProps<DiagramData>): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
/**
|
|
6
|
+
* Edit form (panel surface). The block can be an HTML/SVG fragment or a legacy
|
|
7
|
+
* node/edge/note graph, so this exposes html/css/caption plus a collapsible
|
|
8
|
+
* legacy node-graph JSON editor, each with an AI-edit affordance via
|
|
9
|
+
* `ctx.renderAiFieldAction` (through `AiEditableFieldLabel`). `editSurface:
|
|
10
|
+
* "panel"` means the registry renders the `Read` view with a corner edit button
|
|
11
|
+
* that opens this form in the app-provided popover.
|
|
12
|
+
*/
|
|
13
|
+
export declare function DiagramEdit({ data, onChange, editable, blockId, title, summary, ctx, }: BlockEditProps<DiagramData>): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
/** Full client spec for the shared `diagram` block (schema + MDX + Read/Edit). */
|
|
15
|
+
export declare const diagramBlock: import("../types.js").BlockSpec<DiagramData>;
|
|
16
|
+
//# sourceMappingURL=diagram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagram.d.ts","sourceRoot":"","sources":["../../../../src/client/blocks/library/diagram.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EAEf,MAAM,aAAa,CAAC;AAQrB,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,qBAAqB,CAAC;AAkX7B,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,OAAO,EACP,KAAK,EACL,OAAO,EACP,GAAG,GACJ,EAAE,cAAc,CAAC,WAAW,CAAC,2CAQ7B;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,OAAO,EACP,GAAG,GACJ,EAAE,cAAc,CAAC,WAAW,CAAC,2CAkL7B;AAED,kFAAkF;AAClF,eAAO,MAAM,YAAY,8CAgBvB,CAAC"}
|
|
@@ -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
|