chore(svelte): use on:connect in custom node

This commit is contained in:
moklick
2023-08-21 18:12:29 +02:00
parent 208ee5b944
commit 8614297650
2 changed files with 23 additions and 5 deletions
@@ -10,7 +10,8 @@
Position, Position,
type Node, type Node,
type NodeTypes, type NodeTypes,
type Edge type Edge,
type Connection
} from '../../lib/index'; } from '../../lib/index';
import { CustomNode } from './CustomNode'; import { CustomNode } from './CustomNode';
@@ -102,9 +103,20 @@
animated: true animated: true
} }
]); ]);
const onConnect = (connection: Connection) => {
console.log('on connect', connection);
};
</script> </script>
<SvelteFlow {nodes} {edges} {nodeTypes} style="--bgcolor: {$bgColor}" fitView> <SvelteFlow
{nodes}
{edges}
{nodeTypes}
style="--bgcolor: {$bgColor}"
fitView
on:connect={onConnect}
>
<Controls /> <Controls />
<Background variant={BackgroundVariant.Dots} /> <Background variant={BackgroundVariant.Dots} />
<MiniMap /> <MiniMap />
@@ -6,10 +6,16 @@
export let data: { color: string; onChange: () => void } = { color: '#111', onChange: () => {} }; export let data: { color: string; onChange: () => void } = { color: '#111', onChange: () => {} };
</script> </script>
<Handle type="target" position={Position.Left} /> <Handle type="target" position={Position.Left} on:connect />
<div> <div>
Custom Color Picker Node: <strong>{data.color}</strong> Custom Color Picker Node: <strong>{data.color}</strong>
</div> </div>
<input class="nodrag" type="color" on:input={data.onChange} value={data.color} /> <input class="nodrag" type="color" on:input={data.onChange} value={data.color} />
<Handle type="source" position={Position.Right} id="a" style="top: 10px;" /> <Handle type="source" position={Position.Right} id="a" style="top: 10px;" on:connect />
<Handle type="source" position={Position.Right} id="b" style="top: auto; bottom: 10px;" /> <Handle
type="source"
position={Position.Right}
id="b"
style="top: auto; bottom: 10px;"
on:connect
/>