Serve the demo artwork in each build (#1494)

* Serve local demo artwork

* Disable restricted import lint

* Revert

* Switch approach to vite-multiple-assets plugin

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2023-12-11 09:06:00 +00:00 committed by GitHub
parent b60736c2c6
commit af4c793f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 85 additions and 22 deletions

View file

@ -47,15 +47,17 @@ export function createPortfolioState(editor: Editor) {
});
editor.subscriptions.subscribeJsMessage(TriggerFetchAndOpenDocument, async (triggerFetchAndOpenDocument) => {
try {
const url = new URL(triggerFetchAndOpenDocument.url);
const { name, filename } = triggerFetchAndOpenDocument;
const url = new URL(filename, document.location.href);
const data = await fetch(url);
const filename = url.pathname.split("/").pop() || "Untitled";
const content = await data.text();
editor.instance.openDocumentFile(filename, content);
editor.instance.openDocumentFile(name, content);
} catch {
editor.instance.errorDialog("Failed to open document", "The file could not be reached over the internet. You may be offline, or it may be missing.");
// Needs to be delayed until the end of the current call stack so the existing demo artwork dialog can be closed first, otherwise this dialog won't show
setTimeout(() => {
editor.instance.errorDialog("Failed to open document", "The file could not be reached over the internet. You may be offline, or it may be missing.");
}, 0);
}
});
editor.subscriptions.subscribeJsMessage(TriggerOpenDocument, async () => {

View file

@ -522,7 +522,9 @@ export class TriggerLoadAutoSaveDocuments extends JsMessage {}
export class TriggerLoadPreferences extends JsMessage {}
export class TriggerFetchAndOpenDocument extends JsMessage {
readonly url!: string;
readonly name!: string;
readonly filename!: string;
}
export class TriggerOpenDocument extends JsMessage {}