|
14 | 14 | // Speed dial imports
|
15 | 15 | import { fly } from "svelte/transition";
|
16 | 16 | import { SpeedDial, SpeedDialButton } from 'flowbite-svelte';
|
17 |
| - import { AdjustmentsHorizontalSolid, DrawSquareSolid, DotsHorizontalOutline, PauseSolid, PlaySolid, UploadSolid, ReplySolid } from 'flowbite-svelte-icons'; |
| 17 | + import { AdjustmentsHorizontalSolid, DrawSquareSolid, DotsHorizontalOutline, PauseSolid, PlaySolid, UploadSolid, ReplySolid, ObjectsColumnSolid, } from 'flowbite-svelte-icons'; |
18 | 18 |
|
19 | 19 | // Select imports
|
20 | 20 | import { Label, Select, Range } from "flowbite-svelte";
|
|
26 | 26 |
|
27 | 27 | let currentState = States.SIMULATING;
|
28 | 28 |
|
| 29 | + let editorComponent; |
| 30 | +
|
29 | 31 | let graph;
|
30 | 32 | let layoutInstance;
|
31 | 33 |
|
32 | 34 | let selectedLayoutName = "viva";
|
33 | 35 |
|
| 36 | + let usePrecomputedPositions = true; |
| 37 | +
|
34 | 38 | $: selectedLayout = layoutSettings.find((l) => l.value === selectedLayoutName);
|
35 | 39 | $: if (graph) {
|
36 | 40 | let settings = {};
|
|
61 | 65 | }
|
62 | 66 |
|
63 | 67 | function toggleEditorMode() {
|
64 |
| - $isEditorMode = !$isEditorMode; |
65 |
| - if ($isEditorMode) $isSimulationRunning = false; |
66 |
| - currentState = $isEditorMode ? States.EDITING : States.SIMULATING; |
| 68 | + if ($isEditorMode) { |
| 69 | + // Discarding active selection is just an easy way to avoid transforming |
| 70 | + // the relative selection coordinates to canvas coordinates |
| 71 | + editorComponent.discardActiveSelection(); |
| 72 | + $isSimulationRunning = false; |
| 73 | + $isEditorMode = false; |
| 74 | + currentState = States.SIMULATING; |
| 75 | + } else { |
| 76 | + $isEditorMode = true; |
| 77 | + currentState = States.EDITING; |
| 78 | + } |
67 | 79 | }
|
68 | 80 |
|
69 | 81 | let sidebarExpanded = true;
|
|
74 | 86 |
|
75 | 87 | function transmitCoordinatesBackToShiny() {
|
76 | 88 | let coordinates = [];
|
| 89 | +
|
| 90 | + if ($isEditorMode) editorComponent.persistNodePositions(); |
| 91 | +
|
77 | 92 | graph.forEachNode(function(node) {
|
78 | 93 | var pos = layoutInstance.getNodePosition(node.id);
|
79 | 94 | coordinates.push({ x: pos.x, y: pos.y });
|
|
94 | 109 | });
|
95 | 110 | </script>
|
96 | 111 |
|
97 |
| -{#if sidebarExpanded} |
| 112 | +{#if sidebarExpanded && !$isEditorMode} |
98 | 113 | <aside
|
99 | 114 | id="expanded-sidebar"
|
100 | 115 | class="fixed top-0 left-0 z-40 w-48 h-screen overflow-hidden"
|
|
158 | 173 | <div class="flex flex-grow bg-slate-50">
|
159 | 174 | {#if graph && !$isEditorMode}
|
160 | 175 | {#key selectedLayoutName}
|
161 |
| - <Graph {graph} layout={layoutInstance} /> |
| 176 | + <Graph {graph} layout={layoutInstance} bind:usePrecomputedPositions /> |
162 | 177 | {/key}
|
163 | 178 | {:else if $isEditorMode}
|
164 |
| - <Editor {graph} /> |
| 179 | + <Editor {graph} layout={layoutInstance} bind:this={editorComponent}/> |
165 | 180 | {:else}
|
166 | 181 | <p>Loading graph....</p>
|
167 | 182 | {/if}
|
|
185 | 200 | <SpeedDialButton name="Simulation" on:click={toggleEditorMode}>
|
186 | 201 | <ReplySolid class="w-6 h-6" />
|
187 | 202 | </SpeedDialButton>
|
| 203 | + <SpeedDialButton name="Pack components" on:click={editorComponent.packComponents}> |
| 204 | + <ObjectsColumnSolid class="w-6 h-6" /> |
| 205 | + </SpeedDialButton> |
188 | 206 | {:else}
|
189 | 207 | <SpeedDialButton name="Edit" on:click={toggleEditorMode}>
|
190 | 208 | <DrawSquareSolid class="w-6 h-6" />
|
|
0 commit comments