Skip to content

Commit 45709e5

Browse files
committed
2.22.0-beta-1, 0.18.0-87
1 parent 5e9eb66 commit 45709e5

7 files changed

Lines changed: 166 additions & 212 deletions

File tree

manifest-beta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-excalidraw-plugin",
33
"name": "Excalidraw",
4-
"version": "2.21.2",
4+
"version": "2.22.0-beta-1",
55
"minAppVersion": "1.5.7",
66
"description": "Sketch Your Mind. An Obsidian plugin to edit and view Excalidraw drawings. Enter the world of 4D Visual PKM.",
77
"author": "Zsolt Viczian",

package-lock.json

Lines changed: 67 additions & 198 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"license": "MIT",
2626
"dependencies": {
2727
"@popperjs/core": "^2.11.8",
28-
"@zsviczian/excalidraw": "0.18.0-86",
28+
"@zsviczian/excalidraw": "0.18.0-87",
2929
"chroma-js": "^3.1.2",
3030
"clsx": "^2.0.0",
3131
"@zsviczian/colormaster": "^1.2.2",

src/shared/Dialogs/Messages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ I build this plugin in my free time, as a labor of love. Curious about the philo
2020
"2.22.0":`
2121
## Fixed
2222
- Tray-mode panel buttons get misaligned [#2718](https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/2718) 🙏[@heinrich26](https://github.com/heinrich26)
23+
- Improved loading of nested Excalidraw files in the Excalidraw scene, plus some limited performance improvement.
2324
2425
## New from Excalidraw.com
2526
- Various text element editing improvements, including handle on the right side of wrapped text to enable text auto-resizing (instead of having to open the context menu for this) [#10979](https://github.com/excalidraw/excalidraw/pull/10979)
2627
- Support for Mermaid state diagrams [#11031](https://github.com/excalidraw/excalidraw/pull/11031)
2728
29+
## New
30+
- (partial) support for embedding the [Sheet Plus](obsidian://show-plugin?id=sheet-plus) plugin as an active embedded element in Excalidraw.
2831
`,
2932
"2.21.2":`
3033
## Fixed

src/utils/fileUtils.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,45 @@ export const getExcalidrawEmbeddedFilesFiletree = (sourceFile: TFile, plugin: Ex
485485
}
486486

487487
export const hasExcalidrawEmbeddedImagesTreeChanged = (sourceFile: TFile, mtime:number, plugin: ExcalidrawPlugin):boolean => {
488-
const fileList = getExcalidrawEmbeddedFilesFiletree(sourceFile, plugin);
489-
return fileList.some(f=>f.stat.mtime > mtime);
488+
if(!sourceFile || !plugin.isExcalidrawFile(sourceFile)) {
489+
return false;
490+
}
491+
492+
const visited = new Set<TFile>();
493+
const stack: TFile[] = [sourceFile];
494+
const app = plugin.app;
495+
496+
while (stack.length > 0) {
497+
const currentFile = stack.pop();
498+
const resolvedLinks = app.metadataCache.resolvedLinks[currentFile.path];
499+
if (!resolvedLinks) {
500+
continue;
501+
}
502+
503+
const paths = Object.keys(resolvedLinks);
504+
for (let i = paths.length - 1; i >= 0; i--) {
505+
const file = app.vault.getAbstractFileByPath(paths[i]);
506+
if (!file || !(file instanceof TFile)) {
507+
continue;
508+
}
509+
510+
const isExcalidraw = plugin.isExcalidrawFile(file);
511+
if ((file.extension === "md" && !isExcalidraw) || visited.has(file)) {
512+
continue;
513+
}
514+
515+
visited.add(file);
516+
if (file.stat.mtime > mtime) {
517+
return true;
518+
}
519+
520+
if (isExcalidraw) {
521+
stack.push(file);
522+
}
523+
}
524+
}
525+
526+
return false;
490527
}
491528

492529
export async function exportImageToFile(view: ExcalidrawView, path: string, content: string | ArrayBuffer | Blob, extension: string): Promise<TFile> {

src/view/components/CustomEmbeddable.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export function renderWebView (src: string, view: ExcalidrawView, id: string, _:
339339
//Render WorkspaceLeaf or CanvasNode
340340
//--------------------------------------------------------------------------------
341341
function RenderObsidianView(
342-
{ mdProps, element, linkText, view, containerRef, activeEmbeddable, theme, canvasColor, selectedElementId }:{
342+
{ mdProps, element, linkText, view, containerRef, activeEmbeddable, theme, canvasColor, selectedElementId, sceneZoom }:{
343343
mdProps: EmbeddableMDCustomProps;
344344
element: ExcalidrawEmbeddableElement;
345345
linkText: string;
@@ -349,6 +349,7 @@ function RenderObsidianView(
349349
theme: string;
350350
canvasColor: string;
351351
selectedElementId: string;
352+
sceneZoom: number;
352353
}): JSX.Element {
353354

354355
const { subpath, file } = processLinkText(linkText, view);
@@ -364,7 +365,6 @@ function RenderObsidianView(
364365
const isActiveRef = React.useRef(false);
365366
const viewTypeRef = React.useRef("empty");
366367
const themeRef = React.useRef(theme);
367-
const elementRef = React.useRef(element);
368368
const pdfObserverRef = React.useRef(null);
369369
const pdfObserverDisabledRef = React.useRef(false);
370370
const mobilePatchCleanupRef = React.useRef(null);
@@ -374,11 +374,6 @@ function RenderObsidianView(
374374
React.useEffect(() => {
375375
themeRef.current = theme;
376376
}, [theme]);
377-
378-
// Update elementRef when element changes
379-
React.useEffect(() => {
380-
elementRef.current = element;
381-
}, [element]);
382377

383378
//--------------------------------------------------------------------------------
384379
//block propagation of events to the parent if the embeddable element is active
@@ -556,7 +551,24 @@ function RenderObsidianView(
556551
//--------------------------------------------------------------------------------
557552
//Set colors of the canvas node
558553
//--------------------------------------------------------------------------------
554+
function roundEmbeddableSize(value: number): number {
555+
return Math.round(value * 1000) / 1000;
556+
}
557+
558+
function setEmbeddableSizeVars(canvasNode: HTMLDivElement, element: ExcalidrawEmbeddableElement, sceneZoom: number) {
559+
const scaleX = Math.abs(element.scale?.[0] ?? 1);
560+
const scaleY = Math.abs(element.scale?.[1] ?? 1);
561+
const width = roundEmbeddableSize(element.width / scaleX);
562+
const height = roundEmbeddableSize(element.height / scaleY);
563+
canvasNode?.style.setProperty("--embeddable-width", `${width}px`);
564+
canvasNode?.style.setProperty("--embeddable-height", `${height}px`);
565+
canvasNode?.style.setProperty("--embeddable-scaleX", `${roundEmbeddableSize(scaleX)}`);
566+
canvasNode?.style.setProperty("--embeddable-scaleY", `${roundEmbeddableSize(scaleY)}`);
567+
canvasNode?.style.setProperty("--scene-zoom", `${roundEmbeddableSize(sceneZoom ?? 1)}`);
568+
}
569+
559570
function setColors (canvasNode: HTMLDivElement, element: ExcalidrawEmbeddableElement, mdProps: EmbeddableMDCustomProps, canvasColor: string, viewType: string) {
571+
setEmbeddableSizeVars(canvasNode, element, sceneZoom);
560572
if(!mdProps) return;
561573
if (!leafRef.current?.hasOwnProperty("node")) return;
562574

@@ -647,7 +659,6 @@ function RenderObsidianView(
647659
if(!containerRef.current) {
648660
return;
649661
}
650-
const element = elementRef.current;
651662
const canvasNode = containerRef.current;
652663
if(!canvasNode.hasClass("canvas-node")) return;
653664
setColors(canvasNode, element, mdProps, canvasColor, viewTypeRef.current);
@@ -660,12 +671,25 @@ function RenderObsidianView(
660671
mdProps?.borderMatchElement,
661672
mdProps?.borderColor,
662673
mdProps?.borderOpacity,
663-
elementRef.current,
674+
element.backgroundColor,
675+
element.strokeColor,
676+
element.width,
677+
element.height,
678+
element.scale?.[0],
679+
element.scale?.[1],
680+
sceneZoom,
664681
containerRef.current,
665682
canvasColor,
666683
viewTypeRef.current,
667684
])
668685

686+
React.useEffect(() => {
687+
if(!containerRef.current) {
688+
return;
689+
}
690+
setEmbeddableSizeVars(containerRef.current, element, sceneZoom);
691+
}, [element.width, element.height, element.scale?.[0], element.scale?.[1], sceneZoom]);
692+
669693
//--------------------------------------------------------------------------------
670694
//Switch to preview mode when the iframe is not active
671695
//--------------------------------------------------------------------------------
@@ -886,6 +910,7 @@ export const CustomEmbeddable: React.FC<{element: ExcalidrawEmbeddableElement; v
886910
theme={appState.theme}
887911
canvasColor={appState.viewBackgroundColor}
888912
selectedElementId={selectedElementIds.length === 1 ? selectedElementIds[0] : null}
913+
sceneZoom={appState.zoom.value}
889914
/>
890915
</div>
891916
)

styles.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,4 +1181,24 @@ textarea.excalidraw-wysiwyg, .excalidraw input {
11811181

11821182
.is-mobile .excalidraw.excalidraw--mobile .FixedSideContainer.FixedSideContainer_side_top.App-top-bar {
11831183
margin-top: 1rem
1184-
}
1184+
}
1185+
1186+
/*
1187+
Obsidian Sheets Plus support
1188+
*/
1189+
.excalidraw__embeddable__outer .lj-content-view {
1190+
width: var(--embeddable-width);
1191+
height: var(--embeddable-height);
1192+
}
1193+
1194+
.excalidraw__embeddable__outer #sheet-box {
1195+
height: calc(var(--embeddable-height) - var(--lj-toolbar-height) + 40px);
1196+
}
1197+
1198+
.excalidraw__embeddable__outer .lj-univer .univer-relative.univer-grid {
1199+
width: var(--embeddable-width);
1200+
}
1201+
1202+
/*
1203+
End Obsidian Sheets Plus support
1204+
*/

0 commit comments

Comments
 (0)