feat: support importing scene from url (#2726)

This commit is contained in:
David Luzar 2021-03-08 16:37:26 +01:00 committed by GitHub
parent 9b58efd363
commit beffc290fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 7 deletions

View file

@ -6,6 +6,7 @@ import { ExcalidrawElement } from "../element/types";
import { AppState } from "../types";
import { loadFromBlob } from "./blob";
import { Library } from "./library";
import { ImportedDataState } from "./types";
export const serializeAsJSON = (
elements: readonly ExcalidrawElement[],
@ -53,6 +54,19 @@ export const loadFromJSON = async (localAppState: AppState) => {
return loadFromBlob(blob, localAppState);
};
export const isValidExcalidrawData = (data?: {
type?: any;
elements?: any;
appState?: any;
}): data is ImportedDataState => {
return (
data?.type === "excalidraw" &&
(!data.elements ||
(Array.isArray(data.elements) &&
(!data.appState || typeof data.appState === "object")))
);
};
export const isValidLibrary = (json: any) => {
return (
typeof json === "object" &&