|
57 | 57 | import ContextMenu from "./ContextMenu.svelte";
|
58 | 58 | import { showInfo } from "./InfoModal.svelte";
|
59 | 59 | import interact from "interactjs";
|
| 60 | + import NodeInputsUI from "./NodeInputs.svelte"; |
| 61 | + import NodeOutputsUI from "./NodeOutputs.svelte"; |
60 | 62 |
|
61 | 63 | export let id: string;
|
62 | 64 | export let type: string;
|
|
108 | 110 |
|
109 | 111 | function updateIOCoords(elements: IOElements, io: { [key: string]: LiveIO }) {
|
110 | 112 | for (const [name, elm] of Object.entries(elements)) {
|
| 113 | + console.log(name) |
111 | 114 | const displayCoords = getCenterCoords(elm);
|
112 | 115 | const { x, y } = displayToEditorCoords(displayCoords);
|
113 | 116 | io[name].x = x;
|
|
145 | 148 | updateCoords();
|
146 | 149 | });
|
147 | 150 |
|
148 |
| - function onOutputPointerdown(e: PointerEvent, name: string) { |
149 |
| - if (e.pointerType !== "mouse" || e.buttons === 1) { |
150 |
| - e.stopPropagation(); |
151 |
| -
|
152 |
| - pseudoConnection.update((val) => { |
153 |
| - val.from = [id, name]; |
154 |
| - return val; |
155 |
| - }); |
156 |
| - } |
157 |
| - } |
158 |
| -
|
159 |
| - function onInputPointerup(e: Event, name: string) { |
160 |
| - pseudoConnection.update((val) => { |
161 |
| - if (val.from) { |
162 |
| - createConnection(val.from[0], val.from[1], [id, name]); |
163 |
| - val.from = undefined; |
164 |
| - } |
165 |
| - return val; |
166 |
| - }); |
167 |
| - } |
168 |
| -
|
169 |
| - function onInputPointerdown(e: PointerEvent, name: string) { |
170 |
| - if (e.pointerType !== "mouse" || e.buttons === 1) { |
171 |
| - e.stopPropagation(); |
172 |
| -
|
173 |
| - function onInputPointerleave(e: PointerEvent) { |
174 |
| - if (e.pointerType !== "mouse" || e.buttons === 1) { |
175 |
| - e.stopPropagation(); |
176 |
| - let outputNode, outputName; |
177 |
| - instances.update((val: LiveInstances) => { |
178 |
| - for (const node of Object.entries(val)) { |
179 |
| - for (const output of Object.entries(node[1].outputs)) { |
180 |
| - for (const connection of output[1].connections) { |
181 |
| - if (connection[0] === id && connection[1] === name) { |
182 |
| - outputNode = node[0]; |
183 |
| - outputName = output[0]; |
184 |
| - } |
185 |
| - } |
186 |
| - } |
187 |
| - } |
188 |
| - return val; |
189 |
| - }); |
190 |
| - if (outputNode) { |
191 |
| - destroyConnection(outputNode, outputName, [id, name]); |
192 |
| - pseudoConnection.update((val) => { |
193 |
| - val.from = [outputNode, outputName]; |
194 |
| - return val; |
195 |
| - }); |
196 |
| - } |
197 |
| - } |
198 |
| - } |
199 |
| -
|
200 |
| - e.target.addEventListener("pointerleave", onInputPointerleave); |
201 |
| -
|
202 |
| - window.addEventListener("pointerup", () => { |
203 |
| - e.target.removeEventListener("pointerleave", onInputPointerleave); |
204 |
| - }); |
205 |
| - } |
206 |
| - } |
207 |
| -
|
208 | 151 | let showContextMenu: boolean = false;
|
209 | 152 | let contextMenuCoords: Point;
|
210 | 153 |
|
|
250 | 193 | bind:this={node}
|
251 | 194 | >
|
252 | 195 | <div class="inputs">
|
253 |
| - {#each Object.entries(liveInputs) as [name]} |
254 |
| - <div class="input"> |
255 |
| - <div |
256 |
| - class={name} |
257 |
| - bind:this={inputElements[name]} |
258 |
| - on:pointerup={(e) => { |
259 |
| - onInputPointerup(e, name); |
260 |
| - }} |
261 |
| - on:pointerdown|stopPropagation={(e) => onInputPointerdown(e, name)} |
262 |
| - > |
263 |
| - <span>{name}</span> |
264 |
| - </div> |
265 |
| - </div> |
266 |
| - {/each} |
| 196 | + <NodeInputsUI {id} inputs={Object.keys(liveInputs)} bind:handles={inputElements}/> |
267 | 197 | </div>
|
268 | 198 |
|
269 | 199 | <div class="body">
|
|
283 | 213 | </div>
|
284 | 214 |
|
285 | 215 | <div class="outputs">
|
286 |
| - {#each Object.entries(liveOutputs) as [name]} |
287 |
| - <div class="output"> |
288 |
| - <div |
289 |
| - class={name} |
290 |
| - bind:this={outputElements[name]} |
291 |
| - on:pointerdown={(e) => { |
292 |
| - onOutputPointerdown(e, name); |
293 |
| - }} |
294 |
| - > |
295 |
| - <span>{name}</span> |
296 |
| - </div> |
297 |
| - </div> |
298 |
| - {/each} |
| 216 | + <NodeOutputsUI {id} inputs={Object.keys(liveOutputs)} bind:handles={outputElements}/> |
299 | 217 | </div>
|
300 | 218 | </div>
|
301 | 219 |
|
|
336 | 254 | padding: 4px 12px;
|
337 | 255 | }
|
338 | 256 |
|
339 |
| - /* text */ |
340 |
| -
|
341 |
| - :is(div.output, div.input) { |
342 |
| - writing-mode: vertical-lr; |
343 |
| - color: black; |
344 |
| - font-size: 12px; |
345 |
| - margin: 4px 0px; |
346 |
| - padding: 0px; |
347 |
| - width: 24px; |
348 |
| - } |
349 |
| -
|
350 |
| - /* socket */ |
351 |
| -
|
352 |
| - :is(div.output, div.input) > div { |
353 |
| - padding: 6px 4px; |
354 |
| - background: white; |
355 |
| - } |
356 |
| -
|
357 |
| - div.input > div { |
358 |
| - border-radius: 6px 0 0 6px; |
359 |
| - } |
360 |
| -
|
361 |
| - div.output > div { |
362 |
| - border-radius: 0 6px 6px 0; |
363 |
| - } |
364 |
| -
|
365 |
| - /* hover effect */ |
366 |
| -
|
367 |
| - :is(div.input, div.output) > div:hover { |
368 |
| - background: hsl(0 0% 10%) !important; |
369 |
| - color: white; |
370 |
| - } |
371 |
| -
|
372 |
| - /* special colors */ |
373 |
| -
|
374 |
| - :is(div.output, div.input) > div.MIDI { |
375 |
| - background: hsl(160 90% 60%); |
376 |
| - } |
377 | 257 | </style>
|
0 commit comments