This commit is contained in:
2026-03-09 13:42:03 +01:00
parent 8556a80868
commit 76039bdd0e
6 changed files with 211 additions and 0 deletions

56
package-lock.json generated
View File

@@ -12,6 +12,7 @@
"@codemirror/lang-markdown": "^6.5.0",
"@radix-ui/react-context-menu": "^2.2.16",
"@radix-ui/react-menubar": "^1.1.16",
"@radix-ui/react-popover": "^1.1.15",
"@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-separator": "^1.1.8",
"@radix-ui/react-slot": "^1.2.4",
@@ -2047,6 +2048,61 @@
}
}
},
"node_modules/@radix-ui/react-popover": {
"version": "1.1.15",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.1.15.tgz",
"integrity": "sha512-kr0X2+6Yy/vJzLYJUPCZEc8SfQcf+1COFoAqauJm74umQhta9M7lNJHP7QQS3vkvcGLQUbWpMzwrXYwrYztHKA==",
"license": "MIT",
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-dismissable-layer": "1.1.11",
"@radix-ui/react-focus-guards": "1.1.3",
"@radix-ui/react-focus-scope": "1.1.7",
"@radix-ui/react-id": "1.1.1",
"@radix-ui/react-popper": "1.2.8",
"@radix-ui/react-portal": "1.1.9",
"@radix-ui/react-presence": "1.1.5",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-slot": "1.2.3",
"@radix-ui/react-use-controllable-state": "1.2.2",
"aria-hidden": "^1.2.4",
"react-remove-scroll": "^2.6.3"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-popover/node_modules/@radix-ui/react-slot": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.2.3.tgz",
"integrity": "sha512-aeNmHnBxbi2St0au6VBVC7JXFlhLlOnvIIlePNniyUNAClzmtAUEY8/pBiK3iHjufOlwA+c20/8jngo7xcrg8A==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-popper": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.8.tgz",

View File

@@ -12,6 +12,7 @@
"@codemirror/lang-markdown": "^6.5.0",
"@radix-ui/react-context-menu": "^2.2.16",
"@radix-ui/react-menubar": "^1.1.16",
"@radix-ui/react-popover": "^1.1.15",
"@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-separator": "^1.1.8",
"@radix-ui/react-slot": "^1.2.4",

View File

@@ -1,6 +1,7 @@
import React, { useContext, useMemo } from 'react'
import FlowContext from '../../lib/flowContext'
import { ArrowDownLeft, ArrowUpRight } from 'lucide-react'
import { NodeHelpPopover } from './NodeHelpPopover'
const NODE_HAS_INPUT: Record<string, boolean> = {
config: true,
@@ -58,6 +59,9 @@ export function NodeFooterEdgeIndicators({ nodeId, nodeType, children }: Props)
<span className="min-w-0 truncate">{children}</span>
</>
)}
<span className="shrink-0 ml-auto">
<NodeHelpPopover nodeType={nodeType} />
</span>
</div>
)
}

View File

@@ -0,0 +1,35 @@
import React from 'react'
import { HelpCircle } from 'lucide-react'
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover'
import { getNodeHelp, type NodeType } from '../../lib/nodeHelp'
import { cn } from '../../lib/utils'
type Props = {
nodeType: NodeType
className?: string
}
export function NodeHelpPopover({ nodeType, className }: Props) {
const { title, content } = getNodeHelp(nodeType)
return (
<Popover>
<PopoverTrigger
asChild
className={cn(
'shrink-0 rounded p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
className
)}
aria-label={`Help: ${title}`}
>
<button type="button">
<HelpCircle className="size-3.5" />
</button>
</PopoverTrigger>
<PopoverContent side="top" align="end" className="w-80 max-h-[70vh] overflow-y-auto">
<h3 className="text-sm font-semibold text-foreground">{title}</h3>
<div className="mt-2">{content}</div>
</PopoverContent>
</Popover>
)
}

View File

@@ -0,0 +1,31 @@
import * as React from "react"
import * as PopoverPrimitive from "@radix-ui/react-popover"
import { cn } from "@/lib/utils"
const Popover = PopoverPrimitive.Root
const PopoverTrigger = PopoverPrimitive.Trigger
const PopoverAnchor = PopoverPrimitive.Anchor
const PopoverContent = React.forwardRef<
React.ElementRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-popover-content-transform-origin]",
className
)}
{...props}
/>
</PopoverPrimitive.Portal>
))
PopoverContent.displayName = PopoverPrimitive.Content.displayName
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }

84
src/lib/nodeHelp.tsx Normal file
View File

@@ -0,0 +1,84 @@
import type React from 'react'
export type NodeType = 'config' | 'render' | 'variable' | 'function'
export type NodeHelpEntry = {
title: string
content: React.ReactNode
}
const Code = ({ children }: { children: React.ReactNode }) => (
<code className="rounded bg-muted px-1 py-0.5 text-xs font-mono">{children}</code>
)
const Section = ({ title, children }: { title: string; children: React.ReactNode }) => (
<div className="mt-3 first:mt-0">
<h4 className="text-xs font-semibold text-foreground">{title}</h4>
<div className="mt-1 text-xs text-muted-foreground">{children}</div>
</div>
)
export const NODE_HELP: Record<NodeType, NodeHelpEntry> = {
config: {
title: 'Config node',
content: (
<>
<Section title="How to use">
<p>Config nodes hold PlantUML + Nunjucks template content. Connect one config to a Render node to display the diagram. Use the editor to write <Code>@startuml</Code> blocks and Nunjucks tags (<Code>{'{{ }}'}</Code>, <Code>{'{% %}'}</Code>).</p>
</Section>
<Section title="Using in another node">
<p>From another config, reference this template:</p>
<ul className="list-disc pl-4 mt-1 space-y-0.5">
<li><Code>{'{% extends "configId" %}'}</Code> inherit layout</li>
<li><Code>{'{% include "configId" %}'}</Code> inline content</li>
<li><Code>{'{% import "configId" as alias %}'}</Code> use as macro namespace</li>
</ul>
<p className="mt-2">Replace <Code>configId</Code> with this nodes id or its title. Connect variables/functions to this config; they are available as <Code>{'{{ varId }}'}</Code> and <Code>{'{{ x | fnId }}'}</Code> in the template.</p>
</Section>
</>
),
},
render: {
title: 'Renderer node',
content: (
<>
<Section title="How to use">
<p>Connect a single Config node (input) to this Render node. It resolves the configs PlantUML + Nunjucks (variables, function filters, extends/include), sends the result to the diagram service, and shows the SVG here.</p>
</Section>
<Section title="Using in another node">
<p>Renderer nodes are terminal: they only consume configs. They are not referenced from other nodes. To reuse a diagram, reference the Config node from another Config (extends/include), then connect that config to a Render node.</p>
</Section>
</>
),
},
variable: {
title: 'Variable node',
content: (
<>
<Section title="How to use">
<p>Variables hold a value (string, number, or boolean). Connect a Variable node to a Config node to expose it in that configs template.</p>
</Section>
<Section title="Using in another node">
<p>In a Config template connected to this variable, use <Code>{'{{ '}<em>nodeId</em>{' }}'}</Code> where <em>nodeId</em> is this nodes id. Example: if the variable node id is <Code>var_001</Code>, write <Code>{'{{ var_001 }}'}</Code> in the config.</p>
</Section>
</>
),
},
function: {
title: 'Function node',
content: (
<>
<Section title="How to use">
<p>Functions are Nunjucks custom filters. Write a body using either named parameters (<Code>function(num, x, kwargs) &#123; ... &#125;</Code>) or the <Code>args</Code> array. Connect this node to a Config to use the filter in that configs template.</p>
</Section>
<Section title="Using in another node">
<p>In a Config template, use the filter syntax: <Code>{'{{ value | '}<em>nodeId</em>{' }}'}</Code> or <Code>{'{{ value | '}<em>nodeId</em>{'(arg1, key=val) }}'}</Code>. The first argument is the value before <Code>|</Code>; extra arguments and keyword args are passed as in Nunjucks. Return a value or a Promise for async filters.</p>
</Section>
</>
),
},
}
export function getNodeHelp(nodeType: NodeType): NodeHelpEntry {
return NODE_HELP[nodeType] ?? { title: nodeType, content: null }
}