import React, { useState, useEffect, useRef } from 'react'; import { Input, Button, ColorPicker, Select } from 'antd'; import { FontSizeOutlined, BoldOutlined, LinkOutlined, } from '@ant-design/icons'; import type { MindElixirInstance, NodeObj } from 'mind-elixir'; const xmindColorPresets = [ // 经典16色 '#FFFFFF', '#F5F5F5', // 白色系 '#2196F3', '#1976D2', // 蓝色系 '#4CAF50', '#388E3C', // 绿色系 '#FF9800', '#F57C00', // 橙色系 '#F44336', '#D32F2F', // 红色系 '#9C27B0', '#7B1FA2', // 紫色系 '#424242', '#757575', // 灰色系 '#FFEB3B', '#FBC02D' // 黄色系 ]; interface NodeMenuProps { mind: MindElixirInstance; } const NodeMenu: React.FC = ({ mind }) => { const [isOpen, setIsOpen] = useState(false); const [selectedFontColor, setSelectedFontColor] = useState(''); const [selectedBgColor, setSelectedBgColor] = useState(''); const [selectedSize, setSelectedSize] = useState(''); const [isBold, setIsBold] = useState(false); const [url, setUrl] = useState(''); const containerRef = useRef(null); useEffect(() => { const handleSelectNode = (nodeObj: NodeObj) => { setIsOpen(true); const style = nodeObj.style || {}; setSelectedFontColor(style.color || ''); setSelectedBgColor(style.background || ''); setSelectedSize(style.fontSize || '24'); setIsBold(style.fontWeight === 'bold'); setUrl(nodeObj.hyperLink || ''); }; const handleUnselectNode = () => { setIsOpen(false); }; mind.bus.addListener('selectNode', handleSelectNode); mind.bus.addListener('unselectNode', handleUnselectNode); }, [mind]); useEffect(() => { if (containerRef.current && mind.container) { mind.container.appendChild(containerRef.current); } }, [mind.container]); const handleColorChange = (type: "font" | "background", color: string) => { if (type === 'font') { setSelectedFontColor(color); } else { setSelectedBgColor(color); } const patch = { style: {} as any }; if (type === 'font') { patch.style.color = color; } else { patch.style.background = color; } mind.reshapeNode(mind.currentNode, patch); }; const handleSizeChange = (size: string) => { setSelectedSize(size); mind.reshapeNode(mind.currentNode, { style: { fontSize: size } }); }; const handleBoldToggle = () => { const fontWeight = isBold ? '' : 'bold'; setIsBold(!isBold); mind.reshapeNode(mind.currentNode, { style: { fontWeight } }); }; const handleUrlChange = (e: React.ChangeEvent) => { const value = e.target.value; setUrl(value); mind.reshapeNode(mind.currentNode, { hyperLink: value }); }; return (
{/* Font Size Selector */}

文字样式

} /> {url && !/^https?:\/\/\S+$/.test(url) && (

请输入有效的URL地址

)}
); }; export default NodeMenu;