|
2 | 2 | import { onMount, onDestroy, setContext } from "svelte"; |
3 | 3 |
|
4 | 4 | import type { Editor } from "@graphite/editor"; |
5 | | - import { createClipboardManager } from "@graphite/io-managers/clipboard"; |
6 | | - import { createHyperlinkManager } from "@graphite/io-managers/hyperlink"; |
7 | | - import { createInputManager } from "@graphite/io-managers/input"; |
8 | | - import { createLocalizationManager } from "@graphite/io-managers/localization"; |
9 | | - import { createPanicManager } from "@graphite/io-managers/panic"; |
10 | | - import { createPersistenceManager } from "@graphite/io-managers/persistence"; |
11 | | - import { createAppWindowState } from "@graphite/state-providers/app-window"; |
12 | | - import { createDialogState } from "@graphite/state-providers/dialog"; |
13 | | - import { createDocumentState } from "@graphite/state-providers/document"; |
14 | | - import { createFontsManager } from "/src/io-managers/fonts"; |
15 | | - import { createFullscreenState } from "@graphite/state-providers/fullscreen"; |
16 | | - import { createNodeGraphState } from "@graphite/state-providers/node-graph"; |
17 | | - import { createPortfolioState } from "@graphite/state-providers/portfolio"; |
18 | | - import { createTooltipState } from "@graphite/state-providers/tooltip"; |
| 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"; |
19 | 19 |
|
20 | 20 | import MainWindow from "@graphite/components/window/MainWindow.svelte"; |
21 | 21 |
|
22 | 22 | // Graphite Wasm editor |
23 | 23 | export let editor: Editor; |
24 | 24 | setContext("editor", editor); |
25 | 25 |
|
26 | | - // State provider systems |
27 | | - let dialog = createDialogState(editor); |
28 | | - setContext("dialog", dialog); |
29 | | - let tooltip = createTooltipState(editor); |
30 | | - setContext("tooltip", tooltip); |
31 | | - let document = createDocumentState(editor); |
32 | | - setContext("document", document); |
33 | | - let fullscreen = createFullscreenState(editor); |
34 | | - setContext("fullscreen", fullscreen); |
35 | | - let nodeGraph = createNodeGraphState(editor); |
36 | | - setContext("nodeGraph", nodeGraph); |
37 | | - let portfolio = createPortfolioState(editor); |
38 | | - setContext("portfolio", portfolio); |
39 | | - let appWindow = createAppWindowState(editor); |
40 | | - setContext("appWindow", appWindow); |
41 | | -
|
42 | | - // Initialize managers, which are isolated systems that subscribe to backend messages to link them to browser API functionality (like JS events, IndexedDB, etc.) |
43 | | - const clipboardManagerDestructor = createClipboardManager(editor); |
44 | | - const hyperlinkManagerDestructor = createHyperlinkManager(editor); |
45 | | - const localizationManagerDestructor = createLocalizationManager(editor); |
46 | | - const panicManagerDestructor = createPanicManager(editor, dialog); |
47 | | - const persistenceManagerDestructor = createPersistenceManager(editor, portfolio); |
48 | | - const fontsManagerDestructor = createFontsManager(editor); |
49 | | - const inputManagerDestructor = createInputManager(editor, dialog, portfolio, document, fullscreen); |
| 26 | + const stores = { |
| 27 | + dialog: createDialogStore(editor), |
| 28 | + tooltip: createTooltipStore(editor), |
| 29 | + document: createDocumentStore(editor), |
| 30 | + fullscreen: createFullscreenStore(editor), |
| 31 | + nodeGraph: createNodeGraphStore(editor), |
| 32 | + portfolio: createPortfolioStore(editor), |
| 33 | + appWindow: createAppWindowStore(editor), |
| 34 | + }; |
| 35 | + Object.entries(stores).forEach(([key, store]) => setContext(key, store)); |
| 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 | + }; |
50 | 46 |
|
51 | 47 | onMount(() => { |
52 | 48 | // Initialize certain setup tasks required by the editor backend to be ready for the user now that the frontend is ready. |
|
55 | 51 | }); |
56 | 52 |
|
57 | 53 | onDestroy(() => { |
58 | | - // Call the destructor for each manager |
59 | | - clipboardManagerDestructor(); |
60 | | - hyperlinkManagerDestructor(); |
61 | | - localizationManagerDestructor(); |
62 | | - panicManagerDestructor(); |
63 | | - persistenceManagerDestructor(); |
64 | | - fontsManagerDestructor(); |
65 | | - inputManagerDestructor(); |
66 | | - // Clean up state provider subscriptions and event listeners |
67 | | - dialog.destroy(); |
68 | | - tooltip.destroy(); |
69 | | - document.destroy(); |
70 | | - fullscreen.destroy(); |
71 | | - nodeGraph.destroy(); |
72 | | - portfolio.destroy(); |
73 | | - appWindow.destroy(); |
| 54 | + [...Object.values(stores), ...Object.values(managers)].forEach(({ destroy }) => destroy()); |
74 | 55 | }); |
75 | 56 | </script> |
76 | 57 |
|
|
0 commit comments