darabos commited on
Commit
ba4663c
·
1 Parent(s): 0c44583

Allow only one input per plug.

Browse files
Files changed (1) hide show
  1. web/src/LynxKiteFlow.svelte +12 -3
web/src/LynxKiteFlow.svelte CHANGED
@@ -6,11 +6,12 @@
6
  Background,
7
  MiniMap,
8
  MarkerType,
9
- Position,
10
  useSvelteFlow,
11
  type XYPosition,
12
  type Node,
13
  type Edge,
 
 
14
  } from '@xyflow/svelte';
15
  import NodeWithParams from './NodeWithParams.svelte';
16
  import NodeWithGraphView from './NodeWithGraphView.svelte';
@@ -81,7 +82,7 @@
81
  let nodeSearchPos: XYPosition | undefined = undefined;
82
 
83
  const graph = derived([nodes, edges], ([nodes, edges]) => ({ nodes, edges }));
84
- let backendWorkspace;
85
  // Like JSON.stringify, but with keys sorted.
86
  function orderedJSON(obj: any) {
87
  const allKeys = new Set();
@@ -100,7 +101,7 @@
100
  }
101
  const ws = orderedJSON(g);
102
  if (ws === backendWorkspace) return;
103
- console.log('save', '\n' + ws, '\n' + backendWorkspace);
104
  backendWorkspace = ws;
105
  const res = await fetch('/api/save', {
106
  method: 'POST',
@@ -113,6 +114,13 @@
113
  backendWorkspace = orderedJSON(j);
114
  nodes.set(j.nodes);
115
  });
 
 
 
 
 
 
 
116
  </script>
117
 
118
  <div style:height="100%">
@@ -121,6 +129,7 @@
121
  proOptions={{ hideAttribution: true }}
122
  maxZoom={1.5}
123
  minZoom={0.3}
 
124
  >
125
  <Background patternColor="#39bcf3" />
126
  <Controls />
 
6
  Background,
7
  MiniMap,
8
  MarkerType,
 
9
  useSvelteFlow,
10
  type XYPosition,
11
  type Node,
12
  type Edge,
13
+ type Connection,
14
+ type NodeTypes,
15
  } from '@xyflow/svelte';
16
  import NodeWithParams from './NodeWithParams.svelte';
17
  import NodeWithGraphView from './NodeWithGraphView.svelte';
 
82
  let nodeSearchPos: XYPosition | undefined = undefined;
83
 
84
  const graph = derived([nodes, edges], ([nodes, edges]) => ({ nodes, edges }));
85
+ let backendWorkspace: string;
86
  // Like JSON.stringify, but with keys sorted.
87
  function orderedJSON(obj: any) {
88
  const allKeys = new Set();
 
101
  }
102
  const ws = orderedJSON(g);
103
  if (ws === backendWorkspace) return;
104
+ // console.log('save', '\n' + ws, '\n' + backendWorkspace);
105
  backendWorkspace = ws;
106
  const res = await fetch('/api/save', {
107
  method: 'POST',
 
114
  backendWorkspace = orderedJSON(j);
115
  nodes.set(j.nodes);
116
  });
117
+ function onconnect(connection: Connection) {
118
+ edges.update((edges) => {
119
+ // Only one source can connect to a given target.
120
+ return edges.filter((e) => e.source === connection.source || e.target !== connection.target);
121
+ });
122
+ }
123
+
124
  </script>
125
 
126
  <div style:height="100%">
 
129
  proOptions={{ hideAttribution: true }}
130
  maxZoom={1.5}
131
  minZoom={0.3}
132
+ onconnect={onconnect}
133
  >
134
  <Background patternColor="#39bcf3" />
135
  <Controls />