minor cleanup

This commit is contained in:
Zsolt Viczian
2022-06-23 18:16:27 +02:00
parent 73528596d2
commit 108293ae5c
4 changed files with 22 additions and 15 deletions

View File

@@ -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],
])

View File

@@ -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",
{

View File

@@ -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)) {

3
src/types.d.ts vendored
View File

@@ -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 {