diff --git a/rollup.config.js b/rollup.config.js index 2cbe2db..933c68b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -14,7 +14,6 @@ import LZString from 'lz-string'; import postprocess from 'rollup-plugin-postprocess'; const isProd = (process.env.NODE_ENV === "production"); -console.log("Is production", isProd); const excalidraw_pkg = isProd ? fs.readFileSync("./node_modules/@zsviczian/excalidraw/dist/excalidraw.production.min.js", "utf8") @@ -71,15 +70,17 @@ const BUILD_CONFIG = { commonjs(), nodeResolve({ browser: true, preferBuiltins: false }), typescript({inlineSources: !isProd}), - ...isProd ? [ + ...isProd + ? [ terser({toplevel: false, compress: {passes: 2}}), - //!postprocess: + //!postprocess - the version available on npmjs does not work, need this update: // npm install brettz9/rollup-plugin-postprocess#update --save-dev // https://github.com/developit/rollup-plugin-postprocess/issues/10 postprocess([ [/,React=require\("react"\);/, packageString], ]) - ] : [ + ] + : [ postprocess([ [/var React = require\('react'\);/, packageString], ]) diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 357a426..9ba77fd 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -888,13 +888,12 @@ export default class ExcalidrawView extends TextFileView { diskIcon: HTMLElement; onload() { - //app.workspace.onLayoutReady(()=>{ - const doc = app.isMobile?document:this.containerEl.ownerDocument; - this.ownerDocument = doc; - this.ownerWindow = this.ownerDocument.defaultView; - this.plugin.getPackage(this.ownerWindow); - this.semaphores.scriptsReady = true; - //}); + const doc = app.isMobile?document:this.containerEl.ownerDocument; + this.ownerDocument = doc; + this.ownerWindow = this.ownerDocument.defaultView; + this.plugin.getPackage(this.ownerWindow); + this.semaphores.scriptsReady = true; + this.addAction(SCRIPTENGINE_ICON_NAME, t("INSTALL_SCRIPT_BUTTON"), () => { new ScriptInstallPrompt(this.plugin).open(); }); @@ -2454,8 +2453,12 @@ export default class ExcalidrawView extends TextFileView { }, 400); } }; - const Excalidraw = this.plugin.getPackage(this.ownerWindow).excalidrawLib.Excalidraw; - const getSceneVersion = this.plugin.getPackage(this.ownerWindow).excalidrawLib.getSceneVersion; + + const { + Excalidraw, + getSceneVersion, + } = this.plugin.getPackage(this.ownerWindow).excalidrawLib; + const excalidrawDiv = React.createElement( "div", { diff --git a/src/main.ts b/src/main.ts index 615db81..aae0a8c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,6 +119,9 @@ declare module "obsidian" { } declare const EXCALIDRAW_PACKAGES:string; +declare const react:any; +declare const reactDOM:any; +declare const excalidrawLib: any; declare const PLUGIN_VERSION:string; export default class ExcalidrawPlugin extends Plugin { @@ -168,7 +171,6 @@ export default class ExcalidrawPlugin extends Plugin { public getPackage(win:Window):Packages { if(win===window) { - //@ts-ignore return {react, reactDOM, excalidrawLib}; } if(this.packageMap.has(win)) { diff --git a/src/types.d.ts b/src/types.d.ts index 50f4763..38fa15e 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -6,12 +6,13 @@ import { ExcalidrawAutomate } from "./ExcalidrawAutomate"; import ExcalidrawView, { ExportSettings } from "./ExcalidrawView"; import ExcalidrawPlugin from "./main"; + export type ConnectionPoint = "top" | "bottom" | "left" | "right" | null; export type Packages = { react: any, reactDOM: any, - excalidrawLib: any + excalidrawLib: any, } export interface ExcalidrawAutomateInterface {