From 1437953b7a6399ebddf02fbbb7aa3f67a7db7340 Mon Sep 17 00:00:00 2001 From: dwelle <5153846+dwelle@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:07:06 +0100 Subject: [PATCH] wip --- .github/workflows/autorelease-fork.yml | 2 +- package.json | 1 - packages/excalidraw/components/App.tsx | 57 ++++++++++--------- .../excalidraw/components/TTDDialog/common.ts | 16 ++++-- packages/excalidraw/index.tsx | 4 ++ packages/excalidraw/main.js | 12 +++- packages/utils/export.test.ts | 3 +- packages/utils/export.ts | 2 +- scripts/autorelease-fork.js | 2 +- 9 files changed, 60 insertions(+), 39 deletions(-) diff --git a/.github/workflows/autorelease-fork.yml b/.github/workflows/autorelease-fork.yml index 874cdf6a3209..58fcc0b4209c 100644 --- a/.github/workflows/autorelease-fork.yml +++ b/.github/workflows/autorelease-fork.yml @@ -23,5 +23,5 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Auto release run: | - yarn add @actions/core + yarn add -W @actions/core yarn autorelease-fork diff --git a/package.json b/package.json index 74db5fd5e95a..118afa577c36 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "homepage": ".", "prettier": "@excalidraw/prettier-config", "scripts": { - "setup": "yarn && cd src/packages/excalidraw && yarn", "build-node": "node ./scripts/build-node.js", "build:app:docker": "cross-env VITE_APP_DISABLE_SENTRY=true VITE_APP_DISABLE_TRACKING=true vite build", "build:app": "cross-env VITE_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA vite build", diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index fe388531a6fd..bad9c80df691 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -1430,7 +1430,6 @@ class App extends React.Component { } UIOptions={this.props.UIOptions} onExportImage={this.onExportImage} - onImageAction={this.onImageAction} renderWelcomeScreen={ !this.state.isLoading && this.state.showWelcomeScreen && @@ -1773,14 +1772,18 @@ class App extends React.Component { }); const blob = await exportToBlob({ - elements: this.scene.getNonDeletedElements(), - appState: { - ...this.state, - exportBackground: true, - viewBackgroundColor: this.state.viewBackgroundColor, + data: { + elements: this.scene.getNonDeletedElements(), + appState: { + ...this.state, + exportBackground: true, + viewBackgroundColor: this.state.viewBackgroundColor, + }, + files: this.files, + }, + config: { + exportingFrame: magicFrame, }, - exportingFrame: magicFrame, - files: this.files, }); const dataURL = await getDataURL(blob); @@ -2392,25 +2395,25 @@ class App extends React.Component { this.onChangeEmitter.destroy(); - this.scene = new Scene(); - this.history = new History(); - this.actionManager = new ActionManager( - this.syncActionResult, - () => this.state, - () => this.scene.getElementsIncludingDeleted(), - this, - ); - this.library = new Library(this); - // @ts-ignore - this.canvas = null; - this.interactiveCanvas = null; - // @ts-ignore - this.rc = null; - - // @ts-ignore - this.excalidrawContainerRef.current = undefined; - this.nearestScrollableContainer = undefined; - this.excalidrawContainerValue = { container: null, id: "unmounted" }; + if (import.meta.env.mode === ENV.PRODUCTION) { + this.history = new History(); + this.library = new Library(this); + this.actionManager = new ActionManager( + this.syncActionResult, + () => this.state, + () => this.scene.getElementsIncludingDeleted(), + this, + ); + // @ts-ignore + this.canvas = null; + this.interactiveCanvas = null; + // @ts-ignore + this.rc = null; + // @ts-ignore + this.excalidrawContainerRef.current = undefined; + this.nearestScrollableContainer = undefined; + this.excalidrawContainerValue = { container: null, id: "unmounted" }; + } clearTimeout(touchTimeout); isSomeElementSelected.clearCache(); diff --git a/packages/excalidraw/components/TTDDialog/common.ts b/packages/excalidraw/components/TTDDialog/common.ts index 636d160a8560..969d28fc83df 100644 --- a/packages/excalidraw/components/TTDDialog/common.ts +++ b/packages/excalidraw/components/TTDDialog/common.ts @@ -99,12 +99,16 @@ export const convertMermaidToExcalidraw = async ({ }; const canvas = await exportToCanvas({ - elements: data.current.elements, - files: data.current.files, - exportPadding: DEFAULT_EXPORT_PADDING, - maxWidthOrHeight: - Math.max(parent.offsetWidth, parent.offsetHeight) * - window.devicePixelRatio, + data: { + elements: data.current.elements, + files: data.current.files, + }, + config: { + padding: DEFAULT_EXPORT_PADDING, + maxWidthOrHeight: + Math.max(parent.offsetWidth, parent.offsetHeight) * + window.devicePixelRatio, + }, }); // if converting to blob fails, there's some problem that will // likely prevent preview and export (e.g. canvas too big) diff --git a/packages/excalidraw/index.tsx b/packages/excalidraw/index.tsx index bd305d901aec..87eac4f47df0 100644 --- a/packages/excalidraw/index.tsx +++ b/packages/excalidraw/index.tsx @@ -283,3 +283,7 @@ export { exportToCanvas } from "./scene/export"; export * as icons from "./components/icons"; export * as actions from "./actions/index"; + +export { duplicateElements, duplicateElement } from "./element/newElement"; + +export { parseMermaidToExcalidraw } from "@excalidraw/mermaid-to-excalidraw"; diff --git a/packages/excalidraw/main.js b/packages/excalidraw/main.js index 4588361175d5..853bb70f8927 100644 --- a/packages/excalidraw/main.js +++ b/packages/excalidraw/main.js @@ -1 +1,11 @@ -module.exports = require("./dist/excalidraw.production.min.js"); +if (process.env.IS_PREACT === "true") { + if (process.env.NODE_ENV === "production") { + module.exports = require("./dist/excalidraw-with-preact.production.min.js"); + } else { + module.exports = require("./dist/excalidraw-with-preact.development.js"); + } +} else if (process.env.NODE_ENV === "production") { + module.exports = require("./dist/excalidraw.production.min.js"); +} else { + module.exports = require("./dist/excalidraw.development.js"); +} diff --git a/packages/utils/export.test.ts b/packages/utils/export.test.ts index 4323c3e74e0d..6aca6afb4f3c 100644 --- a/packages/utils/export.test.ts +++ b/packages/utils/export.test.ts @@ -5,7 +5,8 @@ import * as mockedSceneExportUtils from "../excalidraw/scene/export"; import { MIME_TYPES } from "../excalidraw/constants"; -import { exportToCanvas } from "../../scene/export"; +const { exportToCanvas } = mockedSceneExportUtils; + const exportToSvgSpy = vi.spyOn(mockedSceneExportUtils, "exportToSvg"); describe("exportToCanvas", async () => { diff --git a/packages/utils/export.ts b/packages/utils/export.ts index c39080c94d29..06a6a6c2f9cd 100644 --- a/packages/utils/export.ts +++ b/packages/utils/export.ts @@ -13,7 +13,7 @@ import { copyTextToSystemClipboard, copyToClipboard, } from "../excalidraw/clipboard"; -import { getNonDeletedElements } from "../excalidraw"; +import { getNonDeletedElements } from "../excalidraw/element"; export { MIME_TYPES }; diff --git a/scripts/autorelease-fork.js b/scripts/autorelease-fork.js index 03ccda51c8dc..06bfd7bfc7c7 100644 --- a/scripts/autorelease-fork.js +++ b/scripts/autorelease-fork.js @@ -2,7 +2,7 @@ const fs = require("fs"); const { execSync } = require("child_process"); const core = require("@actions/core"); -const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; +const excalidrawDir = `${__dirname}/../packages/excalidraw`; const excalidrawPackage = `${excalidrawDir}/package.json`; const pkg = require(excalidrawPackage);