refactoring
This commit is contained in:
@@ -14,7 +14,7 @@ import { nunjucksCompletionSource } from '@/lib/nunjucksAutocomplete'
|
||||
import { plantumlLanguage } from '@/lib/plantumlLanguage'
|
||||
import { useTheme } from '@/lib/themeContext'
|
||||
import {
|
||||
CONFIG_TYPES,
|
||||
getConfigTypes,
|
||||
getConfigContent,
|
||||
getConfigType,
|
||||
getConfigTypeId,
|
||||
@@ -261,7 +261,7 @@ function ConfigNodeComponent({ id, data, width, height, selected }: Props) {
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{CONFIG_TYPES.map((t) => (
|
||||
{getConfigTypes().map((t) => (
|
||||
<SelectItem key={t.id} value={t.id} className="text-xs">
|
||||
{t.label}
|
||||
</SelectItem>
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
import nunjucks from 'nunjucks'
|
||||
import type { ResolvedContentResult, SourceRenderingLogicContext } from '@/lib/graph/rendering'
|
||||
import { getConfigContent, getConfigType, getConfigTypeId, type ConfigTypeId } from '@/lib/graph/rendering'
|
||||
import { isReachable, resolveExtendsRef, getTemplateRefs } from '@/lib/graph/templateRefs'
|
||||
|
||||
type Node = { id: string; type?: string; data?: unknown }
|
||||
type Edge = { id: string; source: string; target: string }
|
||||
import { isReachable, resolveExtendsRef, getTemplateRefs, type NodeLike } from '@/lib/graph/templateRefs'
|
||||
|
||||
export async function getResolvedContentForConfig(context: SourceRenderingLogicContext): Promise<ResolvedContentResult> {
|
||||
const { nodes, edges, sourceNodeId, renderNodeId } = context
|
||||
@@ -24,11 +21,11 @@ export async function getResolvedContentForConfig(context: SourceRenderingLogicC
|
||||
const configIdsUsed = new Set<string>()
|
||||
|
||||
const addConfigAndRefs = (templateName: string, visited = new Set<string>()) => {
|
||||
const refId = resolveExtendsRef(nodes as { id: string; data?: unknown }[], templateName)
|
||||
const refId = resolveExtendsRef(nodes, templateName)
|
||||
if (visited.has(refId)) throw new Error(`Circular reference detected: ${templateName}`)
|
||||
const node = nodes.find((n) => n.id === refId && n.type === 'config')
|
||||
if (!node) throw new Error(`Config not found: ${templateName}`)
|
||||
if (refId !== srcId && !isReachable(edges as { source: string; target: string }[], refId, id))
|
||||
if (refId !== srcId && !isReachable(edges, refId, id))
|
||||
throw new Error(`Referenced config not connected to renderer: ${templateName}`)
|
||||
visited.add(refId)
|
||||
configIdsUsed.add(refId)
|
||||
@@ -40,10 +37,10 @@ export async function getResolvedContentForConfig(context: SourceRenderingLogicC
|
||||
|
||||
const configLoader = {
|
||||
getSource: (name: string): { src: string; path: string } | null => {
|
||||
const refId = resolveExtendsRef(nodes as { id: string; data?: unknown }[], name)
|
||||
const refId = resolveExtendsRef(nodes, name)
|
||||
const node = nodes.find((n) => n.id === refId && n.type === 'config')
|
||||
if (!node) return null
|
||||
if (refId !== srcId && !isReachable(edges as { source: string; target: string }[], refId, id))
|
||||
if (refId !== srcId && !isReachable(edges, refId, id))
|
||||
throw new Error(`Referenced config not connected to renderer: ${name}`)
|
||||
return {
|
||||
src: getConfigContent((node.data ?? undefined) as Record<string, unknown> | undefined),
|
||||
@@ -53,7 +50,7 @@ export async function getResolvedContentForConfig(context: SourceRenderingLogicC
|
||||
}
|
||||
|
||||
const nunjucksContext = Object.create(null) as Record<string, unknown>
|
||||
const setVarInContext = (src: Node) => {
|
||||
const setVarInContext = (src: NodeLike) => {
|
||||
const v = (src.data as Record<string, unknown>)?.value
|
||||
const str = v === undefined || v === null ? '' : String(v)
|
||||
nunjucksContext[src.id] =
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
processSvgDisplay,
|
||||
stripTemplateSyntax,
|
||||
} from '@/lib/graph/rendering'
|
||||
import { buildSourceSignatures } from '@/lib/graph/renderingSignatures'
|
||||
import { buildSourceSignatures, type NodeLike, type EdgeLike } from '@/lib/graph/renderingSignatures'
|
||||
import type { ConfigTypeId, SourceRenderingLogicContext } from '@/lib/graph/rendering'
|
||||
|
||||
export type RenderingNodeData = {
|
||||
@@ -137,13 +137,7 @@ export function useRenderingNodeState(
|
||||
: ''
|
||||
|
||||
const signatures = useMemo(
|
||||
() =>
|
||||
buildSourceSignatures(
|
||||
nodes as { id: string; type?: string; data?: unknown }[],
|
||||
edges as { source: string; target: string }[],
|
||||
id,
|
||||
incomingIds
|
||||
),
|
||||
() => buildSourceSignatures(nodes as NodeLike[], edges as EdgeLike[], id, incomingIds),
|
||||
[nodes, edges, id, incomingIds]
|
||||
)
|
||||
const {
|
||||
|
||||
Reference in New Issue
Block a user