// 便利贴节点:可换色、可编辑、可衍生文本节点(演示 applyOps 与其他节点交互)。 export default function stickyNotePlugin(runtime) { const { React } = runtime; const { useState } = React; const COLORS = ["#fde68a", "#fca5a5", "#a7f3d0", "#bfdbfe", "#ddd6fe"]; function StickyContent({ ctx }) { const [editing, setEditing] = useState(false); const color = ctx.node.metadata?.pluginColor || COLORS[0]; const text = ctx.node.metadata?.content || ""; const cycleColor = () => { const next = COLORS[(COLORS.indexOf(color) + 1) % COLORS.length]; ctx.updateMetadata({ pluginColor: next }); }; // 演示与其他节点交互:用画布指令集派生一个连到自己的文本节点 const spawnText = () => { const id = `sticky-${ctx.node.id}-${ctx.getNodes().length}`; ctx.applyOps([ { type: "add_node", id, nodeType: "text", title: "便利贴衍生", x: ctx.node.position?.x ?? 0, y: (ctx.node.position?.y ?? 0) + 260, metadata: { content: text, status: "success" } }, { type: "connect_nodes", fromNodeId: ctx.node.id, toNodeId: id }, ]); }; const btn = { width: 26, height: 26, borderRadius: 8, border: "none", cursor: "pointer", background: "rgba(0,0,0,.08)", fontSize: 13 }; return (