|
2 | 2 | import { onMount, onDestroy, setContext } from "svelte"; |
3 | 3 |
|
4 | 4 | import type { Editor } from "@graphite/editor"; |
5 | | - import { createClipboardManager } from "@graphite/managers/clipboard"; |
6 | | - import { createFontsManager } from "@graphite/managers/fonts"; |
7 | | - import { createHyperlinkManager } from "@graphite/managers/hyperlink"; |
8 | | - import { createInputManager } from "@graphite/managers/input"; |
9 | | - import { createLocalizationManager } from "@graphite/managers/localization"; |
10 | | - import { createPanicManager } from "@graphite/managers/panic"; |
11 | | - import { createPersistenceManager } from "@graphite/managers/persistence"; |
12 | | - import { createAppWindowStore } from "@graphite/stores/app-window"; |
13 | | - import { createDialogStore } from "@graphite/stores/dialog"; |
14 | | - import { createDocumentStore } from "@graphite/stores/document"; |
15 | | - import { createFullscreenStore } from "@graphite/stores/fullscreen"; |
16 | | - import { createNodeGraphStore } from "@graphite/stores/node-graph"; |
17 | | - import { createPortfolioStore } from "@graphite/stores/portfolio"; |
18 | | - import { createTooltipStore } from "@graphite/stores/tooltip"; |
| 5 | + import { createClipboardManager, destroyClipboardManager } from "@graphite/managers/clipboard"; |
| 6 | + import { createFontsManager, destroyFontsManager } from "@graphite/managers/fonts"; |
| 7 | + import { createHyperlinkManager, destroyHyperlinkManager } from "@graphite/managers/hyperlink"; |
| 8 | + import { createInputManager, destroyInputManager } from "@graphite/managers/input"; |
| 9 | + import { createLocalizationManager, destroyLocalizationManager } from "@graphite/managers/localization"; |
| 10 | + import { createPanicManager, destroyPanicManager } from "@graphite/managers/panic"; |
| 11 | + import { createPersistenceManager, destroyPersistenceManager } from "@graphite/managers/persistence"; |
| 12 | + import { createAppWindowStore, destroyAppWindowStore } from "@graphite/stores/app-window"; |
| 13 | + import { createDialogStore, destroyDialogStore } from "@graphite/stores/dialog"; |
| 14 | + import { createDocumentStore, destroyDocumentStore } from "@graphite/stores/document"; |
| 15 | + import { createFullscreenStore, destroyFullscreenStore } from "@graphite/stores/fullscreen"; |
| 16 | + import { createNodeGraphStore, destroyNodeGraphStore } from "@graphite/stores/node-graph"; |
| 17 | + import { createPortfolioStore, destroyPortfolioStore } from "@graphite/stores/portfolio"; |
| 18 | + import { createTooltipStore, destroyTooltipStore } from "@graphite/stores/tooltip"; |
19 | 19 |
|
20 | 20 | import MainWindow from "@graphite/components/window/MainWindow.svelte"; |
21 | 21 |
|
|
34 | 34 | }; |
35 | 35 | Object.entries(stores).forEach(([key, store]) => setContext(key, store)); |
36 | 36 |
|
37 | | - const managers = { |
38 | | - clipboard: createClipboardManager(editor), |
39 | | - hyperlink: createHyperlinkManager(editor), |
40 | | - localization: createLocalizationManager(editor), |
41 | | - panic: createPanicManager(editor), |
42 | | - persistence: createPersistenceManager(editor, stores.portfolio), |
43 | | - fonts: createFontsManager(editor), |
44 | | - input: createInputManager(editor, stores.dialog, stores.portfolio, stores.document, stores.fullscreen), |
45 | | - }; |
46 | | -
|
47 | 37 | onMount(() => { |
| 38 | + createClipboardManager(editor); |
| 39 | + createHyperlinkManager(editor); |
| 40 | + createLocalizationManager(editor); |
| 41 | + createPanicManager(editor); |
| 42 | + createPersistenceManager(editor, stores.portfolio); |
| 43 | + createFontsManager(editor); |
| 44 | + createInputManager(editor, stores.dialog, stores.portfolio, stores.document); |
| 45 | +
|
48 | 46 | // Initialize certain setup tasks required by the editor backend to be ready for the user now that the frontend is ready. |
49 | 47 | // The backend handles idempotency, so this is safe to call again during HMR re-mounts. |
50 | 48 | editor.handle.initAfterFrontendReady(); |
| 49 | +
|
| 50 | + // Re-send all UI layouts from Rust so the frontend has them after an HMR re-mount |
| 51 | + editor.handle.resendAllLayouts(); |
51 | 52 | }); |
52 | 53 |
|
53 | 54 | onDestroy(() => { |
54 | | - [...Object.values(stores), ...Object.values(managers)].forEach(({ destroy }) => destroy()); |
| 55 | + // Stores |
| 56 | + destroyDialogStore(); |
| 57 | + destroyTooltipStore(); |
| 58 | + destroyDocumentStore(); |
| 59 | + destroyFullscreenStore(); |
| 60 | + destroyNodeGraphStore(); |
| 61 | + destroyPortfolioStore(); |
| 62 | + destroyAppWindowStore(); |
| 63 | +
|
| 64 | + // Managers |
| 65 | + destroyClipboardManager(); |
| 66 | + destroyHyperlinkManager(); |
| 67 | + destroyLocalizationManager(); |
| 68 | + destroyPanicManager(); |
| 69 | + destroyPersistenceManager(); |
| 70 | + destroyFontsManager(); |
| 71 | + destroyInputManager(); |
55 | 72 | }); |
56 | 73 | </script> |
57 | 74 |
|
|
0 commit comments