mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37e06efa43 |
Vendored
+2
-1
@@ -2,7 +2,7 @@ import { RestoredDataState } from "@zsviczian/excalidraw/types/excalidraw/data/r
|
||||
import { ImportedDataState } from "@zsviczian/excalidraw/types/excalidraw/data/types";
|
||||
import { BoundingBox } from "@zsviczian/excalidraw/types/excalidraw/element/bounds";
|
||||
import { ElementsMap, ExcalidrawBindableElement, ExcalidrawElement, ExcalidrawFrameElement, ExcalidrawFrameLikeElement, ExcalidrawTextContainer, ExcalidrawTextElement, FontFamilyValues, FontString, NonDeleted, NonDeletedExcalidrawElement, Theme } from "@zsviczian/excalidraw/types/excalidraw/element/types";
|
||||
import { FontMetadata } from "@zsviczian/excalidraw/types/excalidraw/fonts/metadata";
|
||||
import { FontMetadata } from "@zsviczian/excalidraw/types/excalidraw/fonts/FontMetadata";
|
||||
import { AppState, BinaryFiles, DataURL, GenerateDiagramToCode, Zoom } from "@zsviczian/excalidraw/types/excalidraw/types";
|
||||
import { Mutable } from "@zsviczian/excalidraw/types/excalidraw/utility-types";
|
||||
import { GlobalPoint } from "@zsviczian/excalidraw/types/math/types";
|
||||
@@ -220,5 +220,6 @@ declare namespace ExcalidrawLib {
|
||||
): string;
|
||||
function safelyParseJSON (json: string): Record<string, any> | null;
|
||||
function loadSceneFonts(elements: NonDeletedExcalidrawElement[]): Promise<void>;
|
||||
function loadMermaid(): Promise<any>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1521,7 +1521,6 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{
|
||||
if(!silent) new Notice("Save successful", 1000);
|
||||
}
|
||||
|
||||
|
||||
onload() {
|
||||
(process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.onload, "ExcalidrawView.onload");
|
||||
if(this.plugin.settings.overrideObsidianFontSize) {
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
import { updateExcalidrawLib } from "src/constants/constants";
|
||||
import { ExcalidrawLib } from "../ExcalidrawLib";
|
||||
import { Packages } from "../types/types";
|
||||
import { debug, DEBUGGING } from "../utils/DebugHelper";
|
||||
import { Notice } from "obsidian";
|
||||
import ExcalidrawPlugin from "src/main";
|
||||
|
||||
declare let REACT_PACKAGES:string;
|
||||
declare let react:any;
|
||||
declare let reactDOM:any;
|
||||
declare let excalidrawLib: typeof ExcalidrawLib;
|
||||
declare const unpackExcalidraw: Function;
|
||||
|
||||
export class PackageManager {
|
||||
private packageMap: Map<Window, Packages> = new Map<Window, Packages>();
|
||||
private EXCALIDRAW_PACKAGE: string;
|
||||
|
||||
constructor() {
|
||||
this.packageMap.set(window,{react, reactDOM, excalidrawLib});
|
||||
constructor(plugin: ExcalidrawPlugin) {
|
||||
try {
|
||||
this.EXCALIDRAW_PACKAGE = unpackExcalidraw();
|
||||
excalidrawLib = window.eval.call(window,`(function() {${this.EXCALIDRAW_PACKAGE};return ExcalidrawLib;})()`);
|
||||
updateExcalidrawLib();
|
||||
this.setPackage(window,{react, reactDOM, excalidrawLib});
|
||||
} catch (e) {
|
||||
new Notice("Error loading the Excalidraw package", 6000);
|
||||
console.error("Error loading the Excalidraw package", e);
|
||||
}
|
||||
plugin.logStartupEvent("Excalidraw package unpacked");
|
||||
}
|
||||
|
||||
public setPackage(window: Window, pkg: Packages) {
|
||||
@@ -76,5 +89,9 @@ export class PackageManager {
|
||||
delete p.react;
|
||||
});
|
||||
this.packageMap.clear();
|
||||
this.EXCALIDRAW_PACKAGE = "";
|
||||
react = null;
|
||||
reactDOM = null;
|
||||
excalidrawLib = null;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@ export let {
|
||||
refreshTextDimensions,
|
||||
getCSSFontDefinition,
|
||||
loadSceneFonts,
|
||||
loadMermaid,
|
||||
} = excalidrawLib;
|
||||
|
||||
export function updateExcalidrawLib() {
|
||||
@@ -130,6 +131,7 @@ export function updateExcalidrawLib() {
|
||||
refreshTextDimensions,
|
||||
getCSSFontDefinition,
|
||||
loadSceneFonts,
|
||||
loadMermaid,
|
||||
} = excalidrawLib);
|
||||
}
|
||||
|
||||
|
||||
@@ -315,7 +315,6 @@ function RenderObsidianView(
|
||||
const canvasNode = containerRef.current;
|
||||
if(!canvasNode.hasClass("canvas-node")) return;
|
||||
setColors(canvasNode, element, mdProps, canvasColor);
|
||||
console.log("Setting colors");
|
||||
}, [
|
||||
mdProps?.useObsidianDefaults,
|
||||
mdProps?.backgroundMatchCanvas,
|
||||
|
||||
+10
-21
@@ -36,6 +36,7 @@ import {
|
||||
FONTS_STYLE_ID,
|
||||
CJK_STYLE_ID,
|
||||
updateExcalidrawLib,
|
||||
loadMermaid,
|
||||
} from "./constants/constants";
|
||||
import { ExcalidrawSettings, DEFAULT_SETTINGS, ExcalidrawSettingTab } from "./settings";
|
||||
import { initExcalidrawAutomate, ExcalidrawAutomate } from "./ExcalidrawAutomate";
|
||||
@@ -87,12 +88,8 @@ import ExcalidrawView from "./ExcalidrawView";
|
||||
import { CommandManager } from "./Managers/CommandManager";
|
||||
import { EventManager } from "./Managers/EventManager";
|
||||
|
||||
declare const unpackExcalidraw: Function;
|
||||
declare const PLUGIN_VERSION:string;
|
||||
declare const INITIAL_TIMESTAMP: number;
|
||||
declare let react:any;
|
||||
declare let reactDOM:any;
|
||||
declare let excalidrawLib: typeof ExcalidrawLib;
|
||||
|
||||
export default class ExcalidrawPlugin extends Plugin {
|
||||
private fileManager: PluginFileManager;
|
||||
@@ -100,7 +97,6 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
private packageManager: PackageManager;
|
||||
private commandManager: CommandManager;
|
||||
private eventManager: EventManager;
|
||||
private EXCALIDRAW_PACKAGE: string;
|
||||
public eaInstances = new WeakArray<ExcalidrawAutomate>();
|
||||
public fourthFontLoaded: boolean = false;
|
||||
public excalidrawConfig: ExcalidrawConfig;
|
||||
@@ -213,6 +209,14 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
};
|
||||
}*/
|
||||
|
||||
/**
|
||||
* used by Excalidraw to getSharedMermaidInstance
|
||||
* @returns shared mermaid instance
|
||||
*/
|
||||
public async getMermaid() {
|
||||
return await loadMermaid();
|
||||
}
|
||||
|
||||
public isPenMode() {
|
||||
return this.wasPenModeActivePreviously ||
|
||||
(this.settings.defaultPenMode === "always") ||
|
||||
@@ -324,23 +328,12 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
await this.awaitSettings();
|
||||
this.logStartupEvent("Settings awaited");
|
||||
|
||||
this.packageManager = new PackageManager();
|
||||
this.packageManager = new PackageManager(this);
|
||||
this.fileManager = new PluginFileManager(this);
|
||||
this.eventManager = new EventManager(this);
|
||||
this.observerManager = new ObserverManager(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
|
||||
try {
|
||||
this.EXCALIDRAW_PACKAGE = unpackExcalidraw();
|
||||
excalidrawLib = window.eval.call(window,`(function() {${this.EXCALIDRAW_PACKAGE};return ExcalidrawLib;})()`);
|
||||
this.packageManager.setPackage(window,{react, reactDOM, excalidrawLib});
|
||||
updateExcalidrawLib();
|
||||
} catch (e) {
|
||||
new Notice("Error loading the Excalidraw package", 6000);
|
||||
console.error("Error loading the Excalidraw package", e);
|
||||
}
|
||||
this.logStartupEvent("Excalidraw package unpacked");
|
||||
|
||||
try {
|
||||
initCompressionWorker();
|
||||
} catch (e) {
|
||||
@@ -1197,7 +1190,6 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
|
||||
this.settings = null;
|
||||
clearMathJaxVariables();
|
||||
this.EXCALIDRAW_PACKAGE = "";
|
||||
//pluginPackages = null;
|
||||
//PLUGIN_VERSION = null;
|
||||
//@ts-ignore
|
||||
@@ -1205,9 +1197,6 @@ export default class ExcalidrawPlugin extends Plugin {
|
||||
this.packageManager.destroy();
|
||||
this.commandManager?.destroy();
|
||||
this.eventManager.destroy();
|
||||
react = null;
|
||||
reactDOM = null;
|
||||
excalidrawLib = null;
|
||||
terminateCompressionWorker();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user