mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
32 lines
915 B
TypeScript
32 lines
915 B
TypeScript
/* eslint-disable max-classes-per-file */
|
|
|
|
import {tick} from "svelte";
|
|
import {writable} from "svelte/store";
|
|
|
|
import { type Editor } from "@/wasm-communication/editor";
|
|
import { UpdateNodeGraphVisibility } from "@/wasm-communication/messages";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
export function createWorkspaceState(editor: Editor) {
|
|
const { subscribe, update } = writable({
|
|
nodeGraphVisible: false,
|
|
});
|
|
|
|
// Set up message subscriptions on creation
|
|
editor.subscriptions.subscribeJsMessage(UpdateNodeGraphVisibility, async (updateNodeGraphVisibility) => {
|
|
update((state) => {
|
|
state.nodeGraphVisible = updateNodeGraphVisibility.visible;
|
|
return state;
|
|
});
|
|
|
|
// Update the viewport bounds
|
|
await tick();
|
|
window.dispatchEvent(new Event("resize"));
|
|
});
|
|
|
|
return {
|
|
subscribe,
|
|
};
|
|
}
|
|
export type WorkspaceState = ReturnType<typeof createWorkspaceState>;
|