feat(network): draw.io XML export

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-04-14 01:25:49 +00:00
parent c8f571db39
commit 2a4220b496
3 changed files with 125 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ import { AIAssistPanel } from '@/components/network/panels/AIAssistPanel'
import { CanvasEmptyPrompt } from '@/components/network/CanvasEmptyPrompt'
import { networkDiagramsApi, deviceTypesApi } from '@/api'
import { toast } from '@/lib/toast'
import { exportToDrawio } from '@/lib/drawio-export'
import type { DeviceTypeResponse, DeviceProperties, AIGenerateResponse, DiagramEdge, DiagramNode } from '@/types'
import type { DeviceNodeData } from '@/components/network/nodes/DeviceNode'
@@ -729,6 +730,21 @@ function DiagramEditorInner() {
}
}, [diagramId, name])
const handleExportDrawio = useCallback(() => {
if (nodes.length === 0) {
toast.warning('Add some devices to the diagram before exporting')
return
}
const xml = exportToDrawio(getNodes(), edges)
const blob = new Blob([xml], { type: 'application/xml' })
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `${name.replace(/[^a-zA-Z0-9-_ ]/g, '') || 'diagram'}.drawio`
a.click()
URL.revokeObjectURL(url)
}, [nodes, edges, getNodes, name])
if (loading) {
return (
<div className="flex h-full items-center justify-center">
@@ -752,6 +768,7 @@ function DiagramEditorInner() {
onExportSvg={handleExportSvg}
onExportPdf={handleExportPdf}
onExportJson={handleExportJson}
onExportDrawio={handleExportDrawio}
onUndo={undo}
onRedo={redo}
canUndo={canUndo}