feat(excalidraw): support .excalidraw.md (Obsidian plugin format) with lz-string decompression
CI / lint (push) Failing after 14s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / e2e (push) Has been skipped
CI / security (push) Successful in 13s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
CI / lint (push) Failing after 14s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / e2e (push) Has been skipped
CI / security (push) Successful in 13s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
This commit is contained in:
@@ -107,6 +107,7 @@
|
||||
<script type="module">
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { decompressFromBase64 } from "https://esm.sh/[email protected]";
|
||||
import * as ExcalidrawLib from "https://esm.sh/@excalidraw/[email protected]?alias=react:[email protected],react-dom:[email protected]";
|
||||
|
||||
window.React = React;
|
||||
@@ -223,11 +224,25 @@
|
||||
switch (msg.type) {
|
||||
case "init":
|
||||
if (msg.data) {
|
||||
const initialData = {
|
||||
elements: msg.data.elements || [],
|
||||
appState: msg.data.appState || {},
|
||||
files: msg.data.files || {},
|
||||
};
|
||||
let elements, appState, files;
|
||||
// Handle compressed .excalidraw.md format
|
||||
if (msg.data.compressed) {
|
||||
try {
|
||||
const decompressed = decompressFromBase64(msg.data.compressed);
|
||||
const parsed = JSON.parse(decompressed);
|
||||
elements = parsed.elements || [];
|
||||
appState = parsed.appState || {};
|
||||
files = parsed.files || {};
|
||||
} catch(e) {
|
||||
console.error("Failed to decompress Excalidraw data:", e);
|
||||
elements = []; appState = {}; files = {};
|
||||
}
|
||||
} else {
|
||||
elements = msg.data.elements || [];
|
||||
appState = msg.data.appState || {};
|
||||
files = msg.data.files || {};
|
||||
}
|
||||
const initialData = { elements, appState, files };
|
||||
currentTheme = msg.theme || "light";
|
||||
setTheme(currentTheme);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user