Skip to content

Commit

Permalink
0.17.1-obsidian-56
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Sep 28, 2024
1 parent a829d6f commit adab31d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 34 deletions.
15 changes: 12 additions & 3 deletions packages/excalidraw/actions/actionCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -631,9 +636,13 @@ export const zoomToFitElements = (
appState: Readonly<AppState>,
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);

Expand All @@ -654,7 +663,7 @@ export const zoomToFitElements = (
},
1,
maxZoom,
)
),
),
};

Expand Down
49 changes: 40 additions & 9 deletions packages/excalidraw/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ import { getRenderOpacity } from "../renderer/renderElement";
import {
allowDoubleTapEraser,
getExcalidrawContentEl,
getMaxZoom,
hideFreedrawPenmodeCursor,
hostPlugin,
initializeObsidianUtils,
} from "../obsidianUtils";
import {
Expand Down Expand Up @@ -3892,9 +3892,13 @@ class App extends React.Component<AppProps, AppState> {
//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();
}
Expand Down Expand Up @@ -4206,40 +4210,53 @@ class App extends React.Component<AppProps, AppState> {

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,
};
};

Expand Down Expand Up @@ -5187,6 +5204,20 @@ class App extends React.Component<AppProps, AppState> {
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);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/excalidraw/obsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/excalidraw/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
21 changes: 0 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected]:
version "0.2.0"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
Expand Down Expand Up @@ -7981,15 +7974,6 @@ [email protected]:
dependencies:
whatwg-url "^5.0.0"

[email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit adab31d

Please sign in to comment.