-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextNode.jsx
61 lines (56 loc) · 1.65 KB
/
textNode.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { useState, useMemo } from "react"
import { Position, useUpdateNodeInternals } from "reactflow"
import { FileText, RefreshCw } from "lucide-react"
import { BaseNode } from "./baseNode"
import { EditableDiv } from "../components/EditableDiv"
export function TextNode({ id, data }) {
const [text, setText] = useState(data?.text || "")
const [variables, setVariables] = useState([])
const updateNodeInternals = useUpdateNodeInternals()
const handles = useMemo(() => {
const inputHandles = variables.map((variable, index) => ({
id: `${id}-${variable}`,
type: "target",
position: Position.Left,
label: variable,
style: { top: `${30 + index * 24}%` },
}))
return [
...inputHandles,
{
id: `${id}-output`,
type: "source",
position: Position.Right,
label: "output",
style: { top: "50%" },
},
]
}, [id, variables])
const handleVariablesChange = (newVariables) => {
setVariables(newVariables)
updateNodeInternals(id)
}
return (
<BaseNode
label={data?.label || "Text"}
icon={FileText}
handles={handles}
onDelete={() => data?.onDelete(id)}
headerExtra={
<button className="rounded p-1 hover:bg-gray-100" onClick={() => {}}>
<RefreshCw className="h-3.5 w-3.5 text-gray-500" />
</button>
}
>
<div className="space-y-1.5">
<label className="text-sm text-gray-600">Text</label>
<EditableDiv
value={text}
onChange={setText}
onVariablesChange={handleVariablesChange}
maxHeight={200}
/>
</div>
</BaseNode>
)
}