mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2026-12-03 06:43:35 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19d668d956 |
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "obsidian-excalidraw-plugin",
|
||||
"name": "Excalidraw",
|
||||
"version": "2.25.0-beta.2",
|
||||
"version": "2.25.0-beta.3",
|
||||
"minAppVersion": "1.8.7",
|
||||
"description": "Sketch Your Mind. Edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
|
||||
"author": "Zsolt Viczian",
|
||||
|
||||
@@ -92,7 +92,7 @@ const discardImage = (el: Element | null) => {
|
||||
: Array.from(el.querySelectorAll("img"));
|
||||
images.forEach((img) => {
|
||||
if (img.src.startsWith("blob:")) {
|
||||
URL.revokeObjectURL(img.src);
|
||||
getImageCache().releaseObsidianURL(img.src);
|
||||
}
|
||||
// Instantly aborts the browser's background V8 image decoder task
|
||||
img.src = "";
|
||||
|
||||
@@ -18,7 +18,11 @@ import {
|
||||
mainDocument,
|
||||
} from "../constants/constants";
|
||||
import { createSVG } from "src/utils/excalidrawAutomateUtils";
|
||||
import { EquationItem, ExcalidrawData, getTransclusion } from "./ExcalidrawData";
|
||||
import {
|
||||
EquationItem,
|
||||
ExcalidrawData,
|
||||
getTransclusion,
|
||||
} from "./ExcalidrawData";
|
||||
import { t } from "../lang/helpers";
|
||||
import { tex2dataURL } from "./LaTeX";
|
||||
import ExcalidrawPlugin from "../core/main";
|
||||
@@ -996,10 +1000,7 @@ export class EmbeddedFilesLoader {
|
||||
const equations = excalidrawData.getEquationEntries();
|
||||
while (!(equationItem = equations.next()).done) {
|
||||
const eiValue = equationItem.value as [FileId, EquationItem];
|
||||
if (
|
||||
fileIDWhiteList &&
|
||||
!fileIDWhiteList.has(eiValue[0])
|
||||
) {
|
||||
if (fileIDWhiteList && !fileIDWhiteList.has(eiValue[0])) {
|
||||
continue;
|
||||
}
|
||||
const equation = eiValue[1];
|
||||
|
||||
@@ -477,6 +477,9 @@ class ImageCache {
|
||||
if (cacheData.svg) {
|
||||
return convertSVGStringToElement(cacheData.svg);
|
||||
}
|
||||
if (!cacheData.blob) {
|
||||
return undefined;
|
||||
}
|
||||
if (this.obsidanURLCache.has(key)) {
|
||||
return this.obsidanURLCache.get(key);
|
||||
}
|
||||
@@ -485,6 +488,22 @@ class ImageCache {
|
||||
return obsidianURL;
|
||||
}
|
||||
|
||||
public releaseObsidianURL(url: string): void {
|
||||
if (!url || !this.obsidanURLCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
const keysToDelete: string[] = [];
|
||||
this.obsidanURLCache.forEach((cachedUrl, key) => {
|
||||
if (cachedUrl === url) {
|
||||
keysToDelete.push(key);
|
||||
}
|
||||
});
|
||||
|
||||
keysToDelete.forEach((key) => this.obsidanURLCache.delete(key));
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
public async getBAKFromCache(filepath: string): Promise<BackupData | null> {
|
||||
if (!this.isReady()) {
|
||||
return null; // Database not initialized yet
|
||||
|
||||
@@ -477,7 +477,7 @@ export function renderWebView(
|
||||
view: ExcalidrawView,
|
||||
id: string,
|
||||
_: UIAppState,
|
||||
): JSX.Element {
|
||||
): React.JSX.Element {
|
||||
let isAllowed = false;
|
||||
try {
|
||||
const url = new URL(src);
|
||||
|
||||
@@ -5,7 +5,7 @@ type ButtonProps = {
|
||||
title: string;
|
||||
action: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||
longpress?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||
icon: JSX.Element;
|
||||
icon: React.JSX.Element;
|
||||
};
|
||||
|
||||
type ButtonState = {
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as React from "react";
|
||||
import { DEVICE } from "src/constants/constants";
|
||||
import { PenSettingsModal } from "src/shared/Dialogs/PenSettingsModal";
|
||||
import ExcalidrawView from "src/view/ExcalidrawView";
|
||||
import { PenStyle } from "src/types/penTypes";
|
||||
import { ExtendedFillStyle, PenStyle } from "src/types/penTypes";
|
||||
import { PENS } from "src/utils/pens";
|
||||
import ExcalidrawPlugin from "../../../core/main";
|
||||
import { ICONS, penIcon, stringToSVG } from "../../../constants/actionIcons";
|
||||
@@ -20,6 +20,17 @@ import {
|
||||
getAppStateStrokeWidthEntry,
|
||||
getFreedrawStrokeWidthByKey,
|
||||
} from "src/utils/excalidrawAutomateUtils";
|
||||
import { ToolsPanel } from "./ToolsPanel";
|
||||
|
||||
export type ResetCustomPenState = {
|
||||
currentItemStrokeWidthKey?: string;
|
||||
currentItemStrokeWidth?: number;
|
||||
currentItemStrokeVariability?: string;
|
||||
currentItemBackgroundColor?: string;
|
||||
currentItemStrokeColor?: string;
|
||||
currentItemFillStyle?: string;
|
||||
currentItemRoughness?: number;
|
||||
};
|
||||
|
||||
export function setPen(pen: PenStyle, api: ExcalidrawImperativeAPI) {
|
||||
const st = api.getAppState();
|
||||
@@ -27,74 +38,88 @@ export function setPen(pen: PenStyle, api: ExcalidrawImperativeAPI) {
|
||||
!pen.strokeWidth || pen.strokeWidth === 0
|
||||
? {}
|
||||
: getAppStateStrokeWidthEntry(undefined, pen.strokeWidth);
|
||||
|
||||
// Changed null to undefined so it neatly satisfies Partial<...>
|
||||
const currentItemStrokeWidthKey =
|
||||
"currentItemStrokeWidthKey" in strokeWidthEntry
|
||||
? strokeWidthEntry.currentItemStrokeWidthKey
|
||||
: null;
|
||||
: undefined;
|
||||
const currentItemStrokeWidth =
|
||||
"currentItemStrokeWidth" in strokeWidthEntry
|
||||
? strokeWidthEntry.currentItemStrokeWidth
|
||||
: null;
|
||||
: undefined;
|
||||
|
||||
// 1. Build the object and explicitly type it as your custom AppState
|
||||
const nextAppState: Partial<AppState> = {
|
||||
currentStrokeOptions: pen.penOptions,
|
||||
currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth,
|
||||
currentItemStrokeVariability: pen.penOptions.constantPressure
|
||||
? "constant"
|
||||
: "variable",
|
||||
...(pen.backgroundColor
|
||||
? { currentItemBackgroundColor: pen.backgroundColor }
|
||||
: null),
|
||||
...(pen.strokeColor ? { currentItemStrokeColor: pen.strokeColor } : null),
|
||||
...(pen.fillStyle === "" ? null : { currentItemFillStyle: pen.fillStyle }),
|
||||
...(pen.roughness !== null
|
||||
? { currentItemRoughness: pen.roughness }
|
||||
: null),
|
||||
...(pen.freedrawOnly && !st.resetCustomPen //switching from custom pen to next custom pen
|
||||
? {
|
||||
resetCustomPen: {
|
||||
currentItemStrokeWidthKey: st.currentItemStrokeWidthKey as
|
||||
| "extraThin"
|
||||
| "thin"
|
||||
| "medium"
|
||||
| "bold"
|
||||
| "extraBold",
|
||||
currentItemStrokeWidth: st.currentItemStrokeWidth,
|
||||
currentItemStrokeVariability: st.currentItemStrokeVariability as
|
||||
| "constant"
|
||||
| "variable",
|
||||
currentItemBackgroundColor: st.currentItemBackgroundColor,
|
||||
currentItemStrokeColor: st.currentItemStrokeColor,
|
||||
currentItemFillStyle: st.currentItemFillStyle as ExtendedFillStyle,
|
||||
currentItemRoughness: st.currentItemRoughness,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
};
|
||||
|
||||
// 2. Cast it back to Partial<AppState> here to satisfy Excalidraw's API
|
||||
api.updateScene({
|
||||
appState: {
|
||||
currentStrokeOptions: pen.penOptions,
|
||||
currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth,
|
||||
currentItemStrokeVariability: pen.penOptions.constantPressure
|
||||
? "constant"
|
||||
: "variable",
|
||||
...(pen.backgroundColor
|
||||
? { currentItemBackgroundColor: pen.backgroundColor }
|
||||
: null),
|
||||
...(pen.strokeColor ? { currentItemStrokeColor: pen.strokeColor } : null),
|
||||
...(pen.fillStyle === ""
|
||||
? null
|
||||
: { currentItemFillStyle: pen.fillStyle }),
|
||||
...(pen.roughness !== null
|
||||
? { currentItemRoughness: pen.roughness }
|
||||
: null),
|
||||
...(pen.freedrawOnly && !st.resetCustomPen //switching from custom pen to next custom pen
|
||||
? {
|
||||
resetCustomPen: {
|
||||
currentItemStrokeWidthKey: st.currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth: st.currentItemStrokeWidth,
|
||||
currentItemStrokeVariability: st.currentItemStrokeVariability,
|
||||
currentItemBackgroundColor: st.currentItemBackgroundColor,
|
||||
currentItemStrokeColor: st.currentItemStrokeColor,
|
||||
currentItemFillStyle: st.currentItemFillStyle,
|
||||
currentItemRoughness: st.currentItemRoughness,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
},
|
||||
appState: nextAppState as Pick<AppState, keyof AppState>,
|
||||
captureUpdate: CaptureUpdateAction.NEVER,
|
||||
});
|
||||
}
|
||||
|
||||
export function resetStrokeOptions(
|
||||
resetCustomPen: Partial<AppState> | null,
|
||||
resetCustomPen: ResetCustomPenState | null,
|
||||
api: ExcalidrawImperativeAPI,
|
||||
clearCurrentStrokeOptions: boolean,
|
||||
) {
|
||||
const appState = api.getAppState();
|
||||
// 1. Build the object and explicitly type it as your custom AppState
|
||||
const nextAppState: Partial<AppState> = {
|
||||
...(resetCustomPen
|
||||
? {
|
||||
currentItemStrokeWidthKey: resetCustomPen.currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth: resetCustomPen.currentItemStrokeWidth,
|
||||
currentItemBackgroundColor: resetCustomPen.currentItemBackgroundColor,
|
||||
currentItemStrokeColor: resetCustomPen.currentItemStrokeColor,
|
||||
currentItemFillStyle: resetCustomPen.currentItemFillStyle,
|
||||
currentItemRoughness: resetCustomPen.currentItemRoughness,
|
||||
currentItemStrokeVariability:
|
||||
resetCustomPen.currentItemStrokeVariability,
|
||||
}
|
||||
: null),
|
||||
resetCustomPen: null,
|
||||
...(clearCurrentStrokeOptions ? { currentStrokeOptions: null } : null),
|
||||
};
|
||||
|
||||
// 2. Cast it back to Partial<AppState> here to satisfy Excalidraw's API
|
||||
api.updateScene({
|
||||
appState: {
|
||||
...(resetCustomPen
|
||||
? {
|
||||
currentItemStrokeWidthKey: resetCustomPen.currentItemStrokeWidthKey,
|
||||
currentItemStrokeWidth: resetCustomPen.currentItemStrokeWidth,
|
||||
currentItemBackgroundColor:
|
||||
resetCustomPen.currentItemBackgroundColor,
|
||||
currentItemStrokeColor: resetCustomPen.currentItemStrokeColor,
|
||||
currentItemFillStyle: resetCustomPen.currentItemFillStyle,
|
||||
currentItemRoughness: resetCustomPen.currentItemRoughness,
|
||||
currentItemStrokeVariability:
|
||||
resetCustomPen.currentItemStrokeVariability,
|
||||
}
|
||||
: null),
|
||||
resetCustomPen: null,
|
||||
...(clearCurrentStrokeOptions ? { currentStrokeOptions: null } : null),
|
||||
},
|
||||
appState: nextAppState as Pick<AppState, keyof AppState>,
|
||||
captureUpdate: CaptureUpdateAction.NEVER,
|
||||
});
|
||||
}
|
||||
@@ -107,7 +132,7 @@ export class ObsidianMenu {
|
||||
constructor(
|
||||
private plugin: ExcalidrawPlugin,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ref instance is injected from ToolsPanel and carries imperative methods.
|
||||
private toolsRef: React.MutableRefObject<any>,
|
||||
private toolsRef: React.MutableRefObject<ToolsPanel>,
|
||||
private view: ExcalidrawView,
|
||||
) {
|
||||
this.clickTimestamp = Array.from(
|
||||
@@ -138,7 +163,7 @@ export class ObsidianMenu {
|
||||
st.currentStrokeOptions === pen.penOptions &&
|
||||
st.activeTool.type === "freedraw"
|
||||
) {
|
||||
resetStrokeOptions(st.resetCustomPen, api, true);
|
||||
resetStrokeOptions(st.resetCustomPen as ResetCustomPenState, api, true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -148,7 +173,7 @@ export class ObsidianMenu {
|
||||
api.setActiveTool({ type: "freedraw" });
|
||||
}
|
||||
|
||||
private actionScriptButtonPonterUp(index: number, key: string) {
|
||||
private actionScriptButtonPointerUp(index: number, key: string) {
|
||||
if (this.longpressTimeout[index]) {
|
||||
this.view.ownerWindow.clearTimeout(this.longpressTimeout[index]);
|
||||
this.longpressTimeout[index] = 0;
|
||||
@@ -166,7 +191,11 @@ export class ObsidianMenu {
|
||||
}
|
||||
}
|
||||
|
||||
private actionScriptButtonPointerDown(index: number, key: string) {
|
||||
private actionScriptButtonPointerDown(
|
||||
index: number,
|
||||
key: string,
|
||||
name: string,
|
||||
) {
|
||||
const now = Date.now();
|
||||
if (this.longpressTimeout[index] > 0) {
|
||||
this.view.ownerWindow.clearTimeout(this.longpressTimeout[index]);
|
||||
@@ -197,7 +226,7 @@ export class ObsidianMenu {
|
||||
}
|
||||
|
||||
private actionShowHideMenu(isMobile: boolean, appState: AppState) {
|
||||
this.toolsRef.current.setTheme(appState.theme);
|
||||
this.toolsRef.current.setTheme(appState.theme as "dark" | "light");
|
||||
this.toolsRef.current.toggleVisibility(appState.zenModeEnabled || isMobile);
|
||||
}
|
||||
|
||||
@@ -233,7 +262,7 @@ export class ObsidianMenu {
|
||||
) {
|
||||
window.setTimeout(() =>
|
||||
resetStrokeOptions(
|
||||
appState.resetCustomPen,
|
||||
appState.resetCustomPen as ResetCustomPenState,
|
||||
this.view.excalidrawAPI,
|
||||
false,
|
||||
),
|
||||
@@ -259,12 +288,18 @@ export class ObsidianMenu {
|
||||
) {
|
||||
const activePen = this.activePens[index] ?? { ...pen };
|
||||
activePen.strokeWidth = getFreedrawStrokeWidthByKey(
|
||||
appState.currentItemStrokeWidthKey,
|
||||
appState.currentItemStrokeWidthKey as
|
||||
| "extraThin"
|
||||
| "thin"
|
||||
| "medium"
|
||||
| "bold"
|
||||
| "extraBold",
|
||||
appState.currentItemStrokeWidth,
|
||||
);
|
||||
activePen.backgroundColor = appState.currentItemBackgroundColor;
|
||||
activePen.strokeColor = appState.currentItemStrokeColor;
|
||||
activePen.fillStyle = appState.currentItemFillStyle;
|
||||
activePen.fillStyle =
|
||||
appState.currentItemFillStyle as ExtendedFillStyle;
|
||||
activePen.roughness = appState.currentItemRoughness;
|
||||
this.activePens[index] = activePen;
|
||||
}
|
||||
@@ -275,7 +310,7 @@ export class ObsidianMenu {
|
||||
className={clsx("ToolIcon", "ToolIcon_size_medium", {
|
||||
"is-mobile": isMobile,
|
||||
})}
|
||||
onClick={this.actionCustomPenLabelClick.bind(this, index, pen)}
|
||||
onClick={() => this.actionCustomPenLabelClick(index, pen)}
|
||||
>
|
||||
<div
|
||||
className="ToolIcon__icon"
|
||||
@@ -311,12 +346,10 @@ export class ObsidianMenu {
|
||||
className={clsx("ToolIcon", "ToolIcon_size_medium", {
|
||||
"is-mobile": isMobile,
|
||||
})}
|
||||
onPointerUp={this.actionScriptButtonPonterUp.bind(this, index, key)}
|
||||
onPointerDown={this.actionScriptButtonPointerDown.bind(
|
||||
this,
|
||||
index,
|
||||
key,
|
||||
)}
|
||||
onPointerUp={() => this.actionScriptButtonPointerUp(index, key)}
|
||||
onPointerDown={() =>
|
||||
this.actionScriptButtonPointerDown(index, key, name)
|
||||
}
|
||||
>
|
||||
<div
|
||||
className="ToolIcon__icon"
|
||||
@@ -337,7 +370,7 @@ export class ObsidianMenu {
|
||||
className={clsx("ToolIcon", "ToolIcon_size_medium", {
|
||||
"is-mobile": isMobile,
|
||||
})}
|
||||
onClick={this.actionShowHideMenu.bind(this, isMobile, appState)}
|
||||
onClick={() => this.actionShowHideMenu(isMobile, appState)}
|
||||
>
|
||||
<div
|
||||
className="ToolIcon__icon"
|
||||
@@ -350,7 +383,7 @@ export class ObsidianMenu {
|
||||
className={clsx("ToolIcon", "ToolIcon_size_medium", {
|
||||
"is-mobile": isMobile,
|
||||
})}
|
||||
onClick={this.actionInsertAnyFile.bind(this)}
|
||||
onClick={() => this.actionInsertAnyFile()}
|
||||
>
|
||||
<div className="ToolIcon__icon" aria-label={t("UNIVERSAL_ADD_FILE")}>
|
||||
{ICONS["add-file"]}
|
||||
@@ -360,7 +393,7 @@ export class ObsidianMenu {
|
||||
className={clsx("ToolIcon", "ToolIcon_size_medium", {
|
||||
"is-mobile": isMobile,
|
||||
})}
|
||||
onClick={this.actionToggleFullscreen.bind(this)}
|
||||
onClick={() => this.actionToggleFullscreen()}
|
||||
>
|
||||
<div
|
||||
className="ToolIcon__icon"
|
||||
|
||||
+23
-5
@@ -1032,7 +1032,15 @@ End Obsidian Sheets Plus support
|
||||
}
|
||||
|
||||
.excalidraw-toolsPanel-island {
|
||||
width: 14.5rem;
|
||||
/*
|
||||
Width calculation:
|
||||
- 5 buttons: (var(--default-button-size) * 5)
|
||||
- 4 column gaps of 0.25rem: 1rem
|
||||
- standard left/right panel padding: ~1.5rem (0.75rem each side)
|
||||
- plus a tiny 0.1rem buffer to prevent accidental wrapping
|
||||
*/
|
||||
width: calc((var(--default-button-size) * 5) + 2.6rem);
|
||||
|
||||
height: fit-content;
|
||||
max-height: 400px;
|
||||
z-index: 5;
|
||||
@@ -1048,13 +1056,23 @@ End Obsidian Sheets Plus support
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .buttonList Button.ToolIcon_type_button {
|
||||
flex: 0 0 18%;
|
||||
/* Ensure tool buttons remain perfectly square and sized just like native Excalidraw.
|
||||
This overrides the old '18%' rule which was stretching the buttons. */
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .buttonList>.ToolIcon_type_button,
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .buttonList>.ToolIcon,
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .buttonList>label {
|
||||
flex: 0 0 auto !important;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Replicate the EXACT native Excalidraw property panel layout */
|
||||
.excalidraw .Island.excalidraw-toolsPanel-island .selected-shape-actions .buttonList {
|
||||
justify-content: space-between;
|
||||
column-gap: unset;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
/* Use standard gap shorthand: row-gap(0.5rem) column-gap(0.25rem).
|
||||
This perfectly matches the native panel spacing and avoids linter warnings! */
|
||||
gap: 0.5rem 0.25rem;
|
||||
}
|
||||
|
||||
.excalidraw .App-tray-menu {
|
||||
|
||||
Reference in new issue
Block a user