feat: refactoring rendering
This commit is contained in:
@@ -2,12 +2,62 @@ import React from 'react'
|
||||
import { ScrollText } from 'lucide-react'
|
||||
import { createNodeTypeBuilder } from '@/lib/graph/nodeTypeBuilder'
|
||||
import { NODE_HELP } from '@/lib/graph/nodeHelp'
|
||||
import { getResolvedContentForConfig, getOutputMenuDescriptorForConfig } from './renderingLogic'
|
||||
import { getConfigType } from '@/lib/graph/rendering'
|
||||
import {
|
||||
MenubarItem,
|
||||
MenubarSeparator,
|
||||
MenubarSub,
|
||||
MenubarSubContent,
|
||||
MenubarSubTrigger,
|
||||
} from '@/components/ui/menubar'
|
||||
import { getResolvedContentForConfig } from './renderingLogic'
|
||||
import type { NodeTypeDescriptor } from '@/lib/graph/nodeRegistry'
|
||||
import ConfigNode from './ConfigNode'
|
||||
import { createImageExportHandlers, type OutputMenuContext } from '@/components/nodes/render/outputMenuRegistry'
|
||||
|
||||
const ICON_CLASS = 'mr-2 h-4 w-4'
|
||||
|
||||
function configOutputMenuContent(outputTypeId: string, ctx: unknown): React.ReactNode {
|
||||
const c = ctx as OutputMenuContext
|
||||
const configType = getConfigType(outputTypeId as 'plantuml' | 'markdown' | 'wireframe')
|
||||
const descriptor = configType?.outputMenuDescriptor
|
||||
if (!descriptor?.items?.length) return null
|
||||
const disabled = !c.state.isSvgOutput
|
||||
const handlers = createImageExportHandlers(c)
|
||||
return (
|
||||
<>
|
||||
<MenubarSeparator />
|
||||
<MenubarSub>
|
||||
<MenubarSubTrigger className="text-xs" disabled={disabled}>
|
||||
{descriptor.submenuLabel ?? 'Export'}
|
||||
</MenubarSubTrigger>
|
||||
<MenubarSubContent className="min-w-[10rem]" aria-label={descriptor.submenuLabel ?? 'Export'}>
|
||||
{descriptor.items.map((item) => {
|
||||
const handler =
|
||||
item.action === 'downloadSvg'
|
||||
? handlers.downloadSvg
|
||||
: item.action === 'downloadPng'
|
||||
? handlers.downloadPng
|
||||
: item.action === 'copySvg'
|
||||
? handlers.copySvg
|
||||
: handlers.copyPng
|
||||
return (
|
||||
<MenubarItem
|
||||
key={item.id}
|
||||
className="text-xs"
|
||||
onClick={handler}
|
||||
disabled={disabled}
|
||||
>
|
||||
{item.label}
|
||||
</MenubarItem>
|
||||
)
|
||||
})}
|
||||
</MenubarSubContent>
|
||||
</MenubarSub>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function getConfigNodeDescriptor(): NodeTypeDescriptor {
|
||||
return createNodeTypeBuilder(
|
||||
'config',
|
||||
@@ -37,7 +87,7 @@ export function getConfigNodeDescriptor(): NodeTypeDescriptor {
|
||||
.sourceRenderingLogic({
|
||||
defaultUpdateMode: 'auto',
|
||||
getResolvedContent: getResolvedContentForConfig,
|
||||
getOutputMenuDescriptor: getOutputMenuDescriptorForConfig,
|
||||
})
|
||||
.outputMenuContent(configOutputMenuContent)
|
||||
.build()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user