feat: enhance connection validation and node creation logic, improve type handling in various components

This commit is contained in:
2026-03-09 21:45:05 +01:00
parent 649d866bef
commit eb1413322f
14 changed files with 77 additions and 81 deletions

View File

@@ -34,6 +34,7 @@ export function FlowKeyboardShortcuts() {
}
const validIds = getRegisteredNodeTypeIds()
if (!raw || typeof raw.type !== 'string' || !validIds.includes(raw.type)) return
const nodeType = raw.type
const pane = document.querySelector('.react-flow__viewport')
const rect = pane?.getBoundingClientRect()
const center = rect
@@ -41,13 +42,14 @@ export function FlowKeyboardShortcuts() {
: { x: window.innerWidth / 2, y: window.innerHeight / 2 }
const position = screenToFlowPosition(center)
setNodes((nds: Node[]) => {
const newId = getNextNodeId(raw.type, nds.map((n) => n.id))
const existingIds = nds.map((n) => n.id).filter((id): id is string => id != null)
const newId = getNextNodeId(nodeType, existingIds)
const data: Record<string, unknown> =
raw.data != null && typeof raw.data === 'object'
? { ...raw.data }
: (getDefaultDataForType(raw.type, newId) as Record<string, unknown>)
if (raw.type === 'config') data.title = `config-${newId}`
const style = getDefaultStyle(raw.type)
: (getDefaultDataForType(nodeType, newId) as Record<string, unknown>)
if (nodeType === 'config') data.title = `config-${newId}`
const style = getDefaultStyle(nodeType)
const newNode: Node = {
id: newId,
type: raw.type as Node['type'],