mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-24 12:08:13 +08:00
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:
@@ -1,3 +1,5 @@
|
||||
import type { EditorHandle } from "@graphite/../wasm/pkg/graphite_wasm";
|
||||
|
||||
export type RequestResult = { body: string; status: number };
|
||||
|
||||
// Special implementation using the legacy XMLHttpRequest API that provides callbacks to get:
|
||||
@@ -31,3 +33,23 @@ export function requestWithUploadDownloadProgress(
|
||||
|
||||
return [promise, xhrValue];
|
||||
}
|
||||
|
||||
// If the URL hash fragment contains a demo artwork path (e.g. #demo/isometric-light), fetch and open it
|
||||
export async function loadDemoArtwork(editor: EditorHandle) {
|
||||
const demoArtwork = window.location.hash.trim().match(/#demo\/(.*)/)?.[1];
|
||||
if (!demoArtwork) return;
|
||||
|
||||
try {
|
||||
const url = new URL(`/demo-artwork/${demoArtwork}.${editor.fileExtension()}`, document.location.href);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error();
|
||||
|
||||
const filename = url.pathname.split("/").pop() || `Untitled.${editor.fileExtension()}`;
|
||||
const content = await response.bytes();
|
||||
editor.openFile(filename, content);
|
||||
|
||||
history.replaceState("", "", `${window.location.pathname}${window.location.search}`);
|
||||
} catch {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user