From adab31d3ee279358dbdd3f7f2446dd38c2d90e3f Mon Sep 17 00:00:00 2001 From: zsviczian Date: Sat, 28 Sep 2024 13:11:29 +0200 Subject: [PATCH] 0.17.1-obsidian-56 --- packages/excalidraw/actions/actionCanvas.tsx | 15 ++++-- packages/excalidraw/components/App.tsx | 49 ++++++++++++++++---- packages/excalidraw/obsidianUtils.ts | 4 ++ packages/excalidraw/package.json | 2 +- yarn.lock | 21 --------- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/packages/excalidraw/actions/actionCanvas.tsx b/packages/excalidraw/actions/actionCanvas.tsx index bd1bc09de5e2..70bea00f5400 100644 --- a/packages/excalidraw/actions/actionCanvas.tsx +++ b/packages/excalidraw/actions/actionCanvas.tsx @@ -44,6 +44,7 @@ import type { SceneBounds } from "../element/bounds"; import { setCursor } from "../cursor"; import { StoreAction } from "../store"; import { clamp, roundToStep } from "../../math"; +import { getMaxZoom } from "../obsidianUtils"; export const actionChangeViewBackgroundColor = register({ name: "changeViewBackgroundColor", @@ -267,8 +268,12 @@ const zoomValueToFitBoundsOnViewport = ( bounds: SceneBounds, viewportDimensions: { width: number; height: number }, viewportZoomFactor: number = 1, // default to 1 if not provided - maxZoom: number = 1, //zsviczian + maxZoom?: number, //zsviczian ) => { + if (typeof maxZoom === "undefined") { + //zsviczian + maxZoom = getMaxZoom(); + } const [x1, y1, x2, y2] = bounds; const commonBoundsWidth = x2 - x1; const zoomValueForWidth = viewportDimensions.width / commonBoundsWidth; @@ -631,9 +636,13 @@ export const zoomToFitElements = ( appState: Readonly, zoomToSelection: boolean, app: AppClassProperties, //zsviczian - maxZoom: number = 1, //zsviczian + maxZoom?: number, //zsviczian margin: number = 0, //zsviczian ) => { + if (typeof maxZoom === "undefined") { + //zsviczian + maxZoom = getMaxZoom(); + } const nonDeletedElements = getNonDeletedElements(elements); const selectedElements = app.scene.getSelectedElements(appState); @@ -654,7 +663,7 @@ export const zoomToFitElements = ( }, 1, maxZoom, - ) + ), ), }; diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index c85a733c84b3..747d1186fd5e 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -434,8 +434,8 @@ import { getRenderOpacity } from "../renderer/renderElement"; import { allowDoubleTapEraser, getExcalidrawContentEl, + getMaxZoom, hideFreedrawPenmodeCursor, - hostPlugin, initializeObsidianUtils, } from "../obsidianUtils"; import { @@ -3892,9 +3892,13 @@ class App extends React.Component { //zsviczian zoomToFit = ( target: readonly ExcalidrawElement[] = this.scene.getNonDeletedElements(), - maxZoom: number = 1, //null will zoom to max based on viewport + maxZoom?: number, //null will zoom to max based on viewport margin: number = 0.03, //percentage of viewport width&height ) => { + if (typeof maxZoom === "undefined") { + //zsviczian + maxZoom = getMaxZoom(); + } if (!target) { target = this.scene.getNonDeletedElements(); } @@ -4206,40 +4210,53 @@ class App extends React.Component { public getEditorUIOffsets = (): Offsets => { const toolbarBottom = - this.excalidrawContainerRef?.current + (this.excalidrawContainerRef?.current ?.querySelector(".App-toolbar") - ?.getBoundingClientRect()?.bottom ?? 0; + ?.getBoundingClientRect()?.bottom ?? 0) - this.state.offsetTop; const sidebarRect = this.excalidrawContainerRef?.current ?.querySelector(".sidebar") ?.getBoundingClientRect(); const propertiesPanelRect = this.excalidrawContainerRef?.current ?.querySelector(".App-menu__left") ?.getBoundingClientRect(); - const PADDING = 16; + const adjustRectValueForOffset = ( //zsviczian https://github.com/excalidraw/excalidraw/issues/8561 + value: number | undefined, + fallback: number, + ) => (value ?? fallback + this.state.offsetLeft) - this.state.offsetLeft; + return getLanguage().rtl ? { top: toolbarBottom + PADDING, right: Math.max( this.state.width - - (propertiesPanelRect?.left ?? this.state.width), + adjustRectValueForOffset( //zsivczian + propertiesPanelRect?.left, + this.state.width, + ), 0, ) + PADDING, bottom: PADDING, - left: Math.max(sidebarRect?.right ?? 0, 0) + PADDING, + left: //zsivczian + Math.max(adjustRectValueForOffset(sidebarRect?.right, 0), 0) + + PADDING, } : { top: toolbarBottom + PADDING, right: Math.max( this.state.width - - (sidebarRect?.left ?? this.state.width) + + adjustRectValueForOffset(sidebarRect?.left, this.state.width) + //zsivczian PADDING, 0, ), bottom: PADDING, - left: Math.max(propertiesPanelRect?.right ?? 0, 0) + PADDING, + left: //zsivczian + Math.max( + adjustRectValueForOffset(propertiesPanelRect?.right, 0), + 0, + ) + PADDING, }; }; @@ -5187,6 +5204,20 @@ class App extends React.Component { newElement: null, editingTextElement: null, }); + + //zsviczian + //when closing the color palette color picker popup while editing a text element + //sometimes even though setState was executed here successfully, there is a race condition + //resulting in editingTexElement not being set to null + //if this happens, this workaround will force it to null + setTimeout(() => { + if (this.state.editingTextElement) { + this.setState({ + newElement: null, + editingTextElement: null, + }); + } + }); if (this.state.activeTool.locked) { setCursorForShape(this.interactiveCanvas, this.state); } diff --git a/packages/excalidraw/obsidianUtils.ts b/packages/excalidraw/obsidianUtils.ts index e2803d646d61..a92198bb4b5c 100644 --- a/packages/excalidraw/obsidianUtils.ts +++ b/packages/excalidraw/obsidianUtils.ts @@ -28,6 +28,10 @@ export function allowDoubleTapEraser() { return hostPlugin.settings.penModeDoubleTapEraser; } +export function getMaxZoom(): number { + return hostPlugin.settings.zoomToFitMaxLevel ?? 1; +} + export function isExcaliBrainView() { const excalidrawView = hostPlugin.activeExcalidrawView; if (!excalidrawView) { diff --git a/packages/excalidraw/package.json b/packages/excalidraw/package.json index 821fa30b0fe9..d81af7a2f7f8 100644 --- a/packages/excalidraw/package.json +++ b/packages/excalidraw/package.json @@ -1,6 +1,6 @@ { "name": "@zsviczian/excalidraw", - "version": "0.17.1-obsidian-55", + "version": "0.17.1-obsidian-56", "main": "main.js", "types": "types/excalidraw/index.d.ts", "files": [ diff --git a/yarn.lock b/yarn.lock index 8da6a2b6fd55..064a26f7e644 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6262,13 +6262,6 @@ form-data@^4.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" -formdata-polyfill@^4.0.10: - version "4.0.10" - resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" - integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== - dependencies: - fetch-blob "^3.1.2" - forwarded@0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811" @@ -7981,15 +7974,6 @@ node-fetch@2.6.7: dependencies: whatwg-url "^5.0.0" -node-fetch@3.3.2: - version "3.3.2" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b" - integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA== - dependencies: - data-uri-to-buffer "^4.0.0" - fetch-blob "^3.1.4" - formdata-polyfill "^4.0.10" - node-forge@^1: version "1.3.1" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3" @@ -10501,11 +10485,6 @@ wbuf@^1.1.0, wbuf@^1.7.3: dependencies: minimalistic-assert "^1.0.0" -web-streams-polyfill@^3.0.3: - version "3.3.3" - resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz#2073b91a2fdb1fbfbd401e7de0ac9f8214cecb4b" - integrity sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw== - webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"