Skip to content

Commit

Permalink
2.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Mar 12, 2024
1 parent 146d04e commit d1ab6bb
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 15 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "2.0.23",
"version": "2.0.24",
"minAppVersion": "1.1.6",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "MIT",
"dependencies": {
"@popperjs/core": "^2.11.8",
"@zsviczian/excalidraw": "0.17.1-obsidian-16",
"@zsviczian/excalidraw": "0.17.1-obsidian-17",
"chroma-js": "^2.4.2",
"clsx": "^2.0.0",
"colormaster": "^1.2.1",
Expand Down
4 changes: 2 additions & 2 deletions src/EmbeddedFileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export class EmbeddedFilesLoader {
}
//files.push(fileData);
}
} else if (embeddedFile.isSVGwithBitmap) {
} /*else if (embeddedFile.isSVGwithBitmap) {
const fileData = {
mimeType: embeddedFile.mimeType,
id: entry.value[0],
Expand All @@ -580,7 +580,7 @@ export class EmbeddedFilesLoader {
catch(e) {
errorlog({ where: "EmbeddedFileLoader.loadSceneFiles", error: e });
}
}
}*/
}

let equation;
Expand Down
53 changes: 51 additions & 2 deletions src/ExcalidrawView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
obsidianToExcalidrawMap,
MAX_IMAGE_SIZE,
fileid,
sceneCoordsToViewportCoords,
} from "./constants/constants";
import ExcalidrawPlugin from "./main";
import {
Expand Down Expand Up @@ -134,8 +135,6 @@ import { nanoid } from "nanoid";
import { CustomMutationObserver, isDebugMode } from "./utils/DebugHelper";
import { extractCodeBlocks, postOpenAI } from "./utils/AIUtils";
import { Mutable } from "@zsviczian/excalidraw/types/excalidraw/utility-types";
import no from "./lang/locale/no";
import { carveOutImage } from "./utils/CarveOut";

declare const PLUGIN_VERSION:string;

Expand Down Expand Up @@ -261,6 +260,7 @@ export default class ExcalidrawView extends TextFileView {
public canvasNodeFactory: CanvasNodeFactory;
private embeddableRefs = new Map<ExcalidrawElement["id"], HTMLIFrameElement | HTMLWebViewElement>();
private embeddableLeafRefs = new Map<ExcalidrawElement["id"], any>();
// private scrollYBeforeKeyboard: number = null;

public semaphores: {
popoutUnload: boolean; //the unloaded Excalidraw view was the last leaf in the popout window
Expand Down Expand Up @@ -4471,6 +4471,7 @@ export default class ExcalidrawView extends TextFileView {
height: undefined,
});


React.useEffect(() => {
this.toolsPanelRef = toolsPanelRef;
this.embeddableMenuRef = embeddableMenuRef;
Expand All @@ -4479,6 +4480,7 @@ export default class ExcalidrawView extends TextFileView {
this.excalidrawWrapperRef = excalidrawWrapperRef;
}, []);


React.useEffect(() => {
setDimensions({
width: this.contentEl.clientWidth,
Expand All @@ -4490,7 +4492,54 @@ export default class ExcalidrawView extends TextFileView {
const width = this.contentEl.clientWidth;
const height = this.contentEl.clientHeight;
if(width === 0 || height === 0) return;

//this is an aweful hack to prevent the keyboard pushing the canvas out of view.
//The issue is that contrary to Excalidraw.com where the page is simply pushed up, in
//Obsidian the leaf has a fixed top. As a consequence the top of excalidrawWrapperDiv does not get pushed out of view
//but shirnks. But the text area is positioned relative to excalidrawWrapperDiv and consequently does not fit, which
//the distorts the whole layout.
//I hope to grow up one day and clean up this mess of a workaround, that resets the top of excalidrawWrapperDiv
//to a negative value, and manually scrolls back elements that were scrolled off screen
//I tried updating setDimensions with the value for top... but setting top and height using setDimensions did not do the trick
//I found that adding and removing this style solves the issue.
//...again, just aweful, but works.
const st = this.excalidrawAPI.getAppState();
const isKeyboardOutEvent = st.editingElement?.type === "text";
const isKeyboardBackEvent = this.semaphores.isEditingText && !isKeyboardOutEvent;
if(isKeyboardOutEvent) {
const self = this;
const appToolHeight = (self.contentEl.querySelector(".Island.App-toolbar") as HTMLElement)?.clientHeight ?? 0;
const editingElViewY = sceneCoordsToViewportCoords({sceneX:0, sceneY:st.editingElement.y}, st).y;
const scrollViewY = sceneCoordsToViewportCoords({sceneX:0, sceneY:-st.scrollY}, st).y;
const delta = editingElViewY - scrollViewY;
const isElementAboveKeyboard = height > (delta + appToolHeight*2)
const excalidrawWrapper = this.excalidrawWrapperRef.current;
console.log({isElementAboveKeyboard});
if(excalidrawWrapper && !isElementAboveKeyboard) {
excalidrawWrapper.style.top = `${-(st.height - height)}px`;
excalidrawWrapper.style.height = `${st.height}px`;
self.excalidrawContainer?.querySelector(".App-bottom-bar")?.scrollIntoView();
//@ts-ignore
self.headerEl?.scrollIntoView();
}
}
if(isKeyboardBackEvent) {
const excalidrawWrapper = this.excalidrawWrapperRef.current;
const appButtonBar = this.excalidrawContainer?.querySelector(".App-bottom-bar");
//@ts-ignore
const headerEl = this.headerEl;
if(excalidrawWrapper) {
excalidrawWrapper.style.top = "";
excalidrawWrapper.style.height = "";
appButtonBar?.scrollIntoView();
headerEl?.scrollIntoView();
}
}
//end of aweful hack


setDimensions({ width, height });

if (this.toolsPanelRef && this.toolsPanelRef.current) {
this.toolsPanelRef.current.updatePosition();
}
Expand Down
47 changes: 38 additions & 9 deletions src/MarkdownPostProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ let metadataCache: MetadataCache;
const getDefaultWidth = (plugin: ExcalidrawPlugin): string => {
const width = parseInt(plugin.settings.width);
if (isNaN(width) || width === 0 || width === null) {
if(getDefaultHeight(plugin)!=="") return "";
return "400";
}
return plugin.settings.width;
};

const getDefaultHeight = (plugin: ExcalidrawPlugin): string => {
const height = parseInt(plugin.settings.height);
if (isNaN(height) || height === 0 || height === null) {
return "";
}
return plugin.settings.height;
};

export const initializeMarkdownPostProcessor = (p: ExcalidrawPlugin) => {
plugin = p;
vault = p.app.vault;
Expand Down Expand Up @@ -123,9 +132,14 @@ const setStyle = ({element,imgAttributes,onCanvas}:{
onCanvas: boolean,
}
) => {
let style = `max-width:${imgAttributes.fwidth}${imgAttributes.fwidth.match(/\d$/) ? "px":""}; `; //width:100%;`; //removed !important https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/886
let style = "";
if(imgAttributes.fwidth) {
style = `max-width:${imgAttributes.fwidth}${imgAttributes.fwidth.match(/\d$/) ? "px":""}; `; //width:100%;`; //removed !important https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/886
} else {
style = "width: fit-content;"
}
if (imgAttributes.fheight) {
style += `height:${imgAttributes.fheight}px;`;
style += `${imgAttributes.fwidth?"min-":"max-"}height:${imgAttributes.fheight}px;`;
}
if(!onCanvas) element.setAttribute("style", style);
element.classList.add(...Array.from(imgAttributes.style))
Expand Down Expand Up @@ -363,7 +377,7 @@ const createImgElement = async (
const linkModifier = linkClickModifierType(ev);
if (plugin.isExcalidrawFile(f) && isMaskFile(plugin, f)) {
(async () => {
const linkString = `[[${f.path}${srcParts[2]?"#"+srcParts[2]:""}]] ${getExcalidrawFileForwardLinks(plugin.app, f)}`;
const linkString = `[[${f.path}${srcParts[2]?"#"+srcParts[2]:""}]] ${getExcalidrawFileForwardLinks(plugin.app, f, new Set<string>())}`;
const result = await linkPrompt(linkString, plugin.app);
if(!result) return;
const [file, linkText, subpath] = result;
Expand Down Expand Up @@ -510,9 +524,11 @@ const processInternalEmbed = async (internalEmbedEl: Element, file: TFile ):Prom
internalEmbedEl.addClass("image-embed");

attr.fwidth = internalEmbedEl.getAttribute("width")
? internalEmbedEl.getAttribute("width")
: getDefaultWidth(plugin);
attr.fheight = internalEmbedEl.getAttribute("height");
? internalEmbedEl.getAttribute("width")
: getDefaultWidth(plugin);
attr.fheight = internalEmbedEl.getAttribute("height")
? internalEmbedEl.getAttribute("height")
: getDefaultHeight(plugin);
let alt = internalEmbedEl.getAttribute("alt");
attr.style = ["excalidraw-svg"];
processAltText(src.split("#")[0],alt,attr);
Expand Down Expand Up @@ -596,7 +612,7 @@ const tmpObsidianWYSIWYG = async (

const attr: imgElementAttributes = {
fname: ctx.sourcePath,
fheight: "",
fheight: getDefaultHeight(plugin),
fwidth: getDefaultWidth(plugin),
style: ["excalidraw-svg"],
};
Expand All @@ -609,8 +625,21 @@ const tmpObsidianWYSIWYG = async (
//We are processing the markdown preview of an actual Excalidraw file
//the excalidraw file in markdown preview mode
const isFrontmatterDiv = Boolean(el.querySelector(".frontmatter"));
el.empty();
if(!isFrontmatterDiv) {
let areaPreview = false;
if(Boolean(ctx.frontmatter)) {
el.empty();
} else {
const warningEl = el.querySelector("div>h3[data-heading^='Unable to find section #^");
if(warningEl) {
const ref = warningEl.getAttr("data-heading").match(/Unable to find section (#\^(?:group=|area=|frame=)[^ ]*)/)?.[1];
if(ref) {
attr.fname = file.path + ref;
areaPreview = true;
}
}

}
if(!isFrontmatterDiv && !areaPreview) {
if(el.parentElement === containerEl) containerEl.removeChild(el);
return;
}
Expand Down
14 changes: 14 additions & 0 deletions src/dialogs/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ I develop this plugin as a hobby, spending my free time doing this. If you find
<div class="ex-coffee-div"><a href="https://ko-fi.com/zsolt"><img src="https://cdn.ko-fi.com/cdn/kofi3.png?v=3" height=45></a></div>
`,
"2.0.24":`
Quality of Life Fixes!
## Fixed
- Text editing issue on mobile devices with an on-screen keyboard is now fixed 🥳. Previously, Excalidraw's UI fell apart when the keyboard was activated, and often even after you stopped editing, the canvas positioning was off. I hope to have solved the issue (we'll see after your testing and feedback!). This is one of those cases that seems insignificant but took enormous effort. It took me 2.5 full days of net time to figure out the root cause and the solution (this is not an exaggeration).
- Tool buttons did not get selected on the first click.
- Images flicker on Forced Save.
- Hover preview fixes:
- ${String.fromCharCode(96)}area=${String.fromCharCode(96)}, ${String.fromCharCode(96)}group=${String.fromCharCode(96)}, ${String.fromCharCode(96)}frame=${String.fromCharCode(96)} references now display the part of the image as expected in hover preview (showed an empty preview until now).
- Block and section references to notes on the "back side of the drawing" now correctly show up in hover preview (showed an empty preview until now).
## New
- Default height setting in Plugin Settings. Thanks @leoccyao! [#1612](https://github.com/zsviczian/obsidian-excalidraw-plugin/pull/1612)
`,
"2.0.23":`
## New
- Additional arrowheads (Circle, Circle Outline, Diamond, Diamond Outline, Triangle Outline) are now available via element properties.
Expand Down
5 changes: 5 additions & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,11 @@ FILENAME_HEAD: "Filename",
"The default width of an embedded drawing. This applies to live preview edit and reading mode, as well as to hover previews. You can specify a custom " +
"width when embedding an image using the <code>![[drawing.excalidraw|100]]</code> or " +
"<code>[[drawing.excalidraw|100x100]]</code> format.",
EMBED_HEIGHT_NAME: "Default height of embedded (transcluded) image",
EMBED_HEIGHT_DESC:
"The default height of an embedded drawing. This applies to live preview edit and reading mode, as well as to hover previews. You can specify a custom " +
"height when embedding an image using the <code>![[drawing.excalidraw|100]]</code> or " +
"<code>[[drawing.excalidraw|100x100]]</code> format.",
EMBED_TYPE_NAME: "Type of file to insert into the document",
EMBED_TYPE_DESC:
"When you embed an image into a document using the command palette this setting will specify if Excalidraw should embed the original Excalidraw file " +
Expand Down
16 changes: 16 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface ExcalidrawSettings {
displayExportedImageIfAvailable: boolean;
previewMatchObsidianTheme: boolean;
width: string;
height: string;
dynamicStyling: DynamicStyle;
isLeftHanded: boolean;
iframeMatchExcalidrawTheme: boolean;
Expand Down Expand Up @@ -203,6 +204,7 @@ export const DEFAULT_SETTINGS: ExcalidrawSettings = {
displayExportedImageIfAvailable: false,
previewMatchObsidianTheme: false,
width: "400",
height: "",
dynamicStyling: "colorful",
isLeftHanded: false,
iframeMatchExcalidrawTheme: true,
Expand Down Expand Up @@ -1630,6 +1632,20 @@ export class ExcalidrawSettingTab extends PluginSettingTab {
}),
);

new Setting(detailsEl)
.setName(t("EMBED_HEIGHT_NAME"))
.setDesc(fragWithHTML(t("EMBED_HEIGHT_DESC")))
.addText((text) =>
text
.setPlaceholder("e.g.: 400")
.setValue(this.plugin.settings.height)
.onChange(async (value) => {
this.plugin.settings.height = value;
this.applySettingsUpdate();
this.requestEmbedUpdate = true;
}),
);

let scaleText: HTMLDivElement;

new Setting(detailsEl)
Expand Down

0 comments on commit d1ab6bb

Please sign in to comment.