Split apart the frontend Editor type into SubscriptionsRouter and EditorHandle (#3923)

* Remove the unused Editor.raw/wasmMemory/wasmImport

* Split out Editor.subscriptions

* Replace editor.handle.* with editor.* (1 of 2)

* Replace editor.handle.* with editor.* (2 of 2)

* Replace Editor typedef with EditorHandle import

* Pluralize subscription-router and rename subscriptionsRef->subscriptionsRouter and editorRef->editorHandle

* Remove editor.ts

* Update the readme

* Fix demo art loading bug
This commit is contained in:
Keavon Chambers
2026-03-20 23:34:13 -07:00
committed by GitHub
parent 64fd12a1a0
commit ed7987c881
40 changed files with 549 additions and 584 deletions
+8 -8
View File
@@ -1,7 +1,7 @@
import { get, writable } from "svelte/store";
import type { Writable } from "svelte/store";
import type { Editor } from "@graphite/editor";
import type { SubscriptionsRouter } from "/src/subscriptions-router";
export type FullscreenStore = ReturnType<typeof createFullscreenStore>;
@@ -14,19 +14,19 @@ const initialState: FullscreenStoreState = {
keyboardLocked: false,
};
let editorRef: Editor | undefined = undefined;
let subscriptionsRouter: SubscriptionsRouter | undefined = undefined;
// Store state persisted across HMR to maintain reactive subscriptions in the component tree
const store: Writable<FullscreenStoreState> = import.meta.hot?.data?.store || writable<FullscreenStoreState>(initialState);
if (import.meta.hot) import.meta.hot.data.store = store;
const { subscribe, update } = store;
export function createFullscreenStore(editor: Editor) {
export function createFullscreenStore(subscriptions: SubscriptionsRouter) {
destroyFullscreenStore();
editorRef = editor;
subscriptionsRouter = subscriptions;
editor.subscriptions.subscribeFrontendMessage("WindowFullscreen", () => {
subscriptions.subscribeFrontendMessage("WindowFullscreen", () => {
toggleFullscreen();
});
@@ -34,10 +34,10 @@ export function createFullscreenStore(editor: Editor) {
}
export function destroyFullscreenStore() {
const editor = editorRef;
if (!editor) return;
const subscriptions = subscriptionsRouter;
if (!subscriptions) return;
editor.subscriptions.unsubscribeFrontendMessage("WindowFullscreen");
subscriptions.unsubscribeFrontendMessage("WindowFullscreen");
}
export function fullscreenModeChanged() {