From 2eb5fc476c68ff51d330ba2bcb2877c511ebbf25 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 25 Jul 2023 23:07:34 +0200 Subject: [PATCH] 1.9.11 --- ea-scripts/Slideshow.md | 33 ++++- ea-scripts/directory-info.json | 2 +- manifest.json | 2 +- package.json | 2 +- src/ExcalidrawAutomate.ts | 3 +- src/ExcalidrawData.ts | 2 +- src/ExcalidrawLib.d.ts | 116 ++++++++++++++++++ src/ExcalidrawView.ts | 23 +++- src/constants.ts | 5 +- src/dialogs/Messages.ts | 2 + src/lang/locale/en.ts | 2 + src/main.ts | 37 ++++++ .../elements/ExcalidrawScene.ts | 1 + src/utils/Utils.ts | 3 +- 14 files changed, 216 insertions(+), 17 deletions(-) create mode 100644 src/ExcalidrawLib.d.ts diff --git a/ea-scripts/Slideshow.md b/ea-scripts/Slideshow.md index 5aa1cd1..fdbc1a8 100644 --- a/ea-scripts/Slideshow.md +++ b/ea-scripts/Slideshow.md @@ -50,8 +50,10 @@ const startFullscreen = !altKey; //For this reason event handlers are distributed between window and owner window depending on their role const ownerWindow = ea.targetView.ownerWindow; const excalidrawAPI = ea.getExcalidrawAPI(); +const frameRenderingOriginalState = excalidrawAPI.getAppState().frameRendering; const contentEl = ea.targetView.contentEl; const sleep = async (ms) => new Promise((resolve) => ownerWindow.setTimeout(resolve, ms)); +const getFrameName = (name, index) => name ?? `Frame ${(index+1).toString().padStart(2, '0')}`; //------------------------------- //clean up potential clutter from previous run @@ -63,9 +65,10 @@ let presentationPathLineEl = ea.getViewElements() .filter(el=>["line","arrow"].contains(el.type) && el.customData?.slideshow)[0]; let frames = ea.getViewElements() .filter(el=>el.type==="frame") - .map((f,i)=>[f,i]) //because frame.name is null until set - .sort((el1,el2)=>((el1[0].name??`Frame ${el1[1]}`)>(el2[0].name??`Frame ${el2[1]}`))?1:-1) + .map((frame,index)=>[frame,index]) //because frame.name is null until set + .sort((el1,el2)=> getFrameName(el1[0], el1[1]) > getFrameName(el2[0], el2[1]) ? -1:1) .map(el=>el[0]); + let presentationPathType = "line"; // "frame" const selectedEl = ea.getViewSelectedElement(); let shouldHideArrowAfterPresentation = true; //this controls if the hide arrow button is available in settings @@ -124,7 +127,16 @@ if(presentationPathType === "frame") { y2: frame.y + frame.height }); } - excalidrawAPI.updateScene({appState:{shouldRenderFrames:false}}); + if(frameRenderingOriginalState.enabled) { + excalidrawAPI.updateScene({ + appState: { + frameRendering: { + ...frameRenderingOriginalState, + enabled: false + } + } + }); + } } //--------------------------------------- @@ -406,7 +418,9 @@ const createPresentationNavigationPanel = () => { }, selectEl => { for (let i = 0; i < slides.length; i++) { const option = document.createElement("option"); - option.text = `Slide ${i + 1}/${slides.length}`; + option.text = (presentationPathType === "frame") + ? `${getFrameName(frames[i]?.name,i)}/${slides.length}` + : option.text = `Slide ${i + 1}/${slides.length}`; option.value = i + 1; selectEl.add(option); } @@ -647,7 +661,16 @@ const exitPresentation = async (openForEdit = false) => { ); } } else { - excalidrawAPI.updateScene({appState:{shouldRenderFrames:true}}); + if(frameRenderingOriginalState.enabled) { + excalidrawAPI.updateScene({ + appState: { + frameRendering: { + ...frameRenderingOriginalState, + enabled: true + } + } + }); + } } window.removePresentationEventHandlers?.(); ownerWindow.setTimeout(()=>{ diff --git a/ea-scripts/directory-info.json b/ea-scripts/directory-info.json index 62069b1..c338e95 100644 --- a/ea-scripts/directory-info.json +++ b/ea-scripts/directory-info.json @@ -1 +1 @@ -[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1688304760357},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1682228345043},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1674326971324},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1681665030892},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982},{"fname":"Palette loader.md","mtime":1686511890942},{"fname":"Palette loader.svg","mtime":1649614401982},{"fname":"Rename Image.md","mtime":1663678478785},{"fname":"Rename Image.svg","mtime":1663678478785},{"fname":"Text Arch.md","mtime":1664095143846},{"fname":"Text Arch.svg","mtime":1670403743278},{"fname":"Deconstruct selected elements into new drawing.md","mtime":1672672112439},{"fname":"Deconstruct selected elements into new drawing.svg","mtime":1668541145255},{"fname":"Slideshow.md","mtime":1689421229704},{"fname":"Slideshow.svg","mtime":1670017348333},{"fname":"Auto Layout.md","mtime":1670403743278},{"fname":"Auto Layout.svg","mtime":1670175947081},{"fname":"Uniform size.md","mtime":1670175947081},{"fname":"Uniform size.svg","mtime":1670175947081},{"fname":"Mindmap format.md","mtime":1684484694228},{"fname":"Mindmap format.svg","mtime":1674944958059},{"fname":"Text to Sticky Notes.md","mtime":1678537561724},{"fname":"Text to Sticky Notes.svg","mtime":1678537561724},{"fname":"Folder Note Core - Make Current Drawing a Folder.md","mtime":1678973697470},{"fname":"Folder Note Core - Make Current Drawing a Folder.svg","mtime":1678973697470},{"fname":"Invert colors.md","mtime":1678973697470},{"fname":"Invert colors.svg","mtime":1678973697470},{"fname":"Auto Draw for Pen.md","mtime":1680418321236},{"fname":"Auto Draw for Pen.svg","mtime":1680418321236},{"fname":"Hardware Eraser Support.md","mtime":1680418321236},{"fname":"Hardware Eraser Support.svg","mtime":1680418321236},{"fname":"PDF Page Text to Clipboard.md","mtime":1683984041712},{"fname":"PDF Page Text to Clipboard.svg","mtime":1680418321236},{"fname":"Excalidraw Collaboration Frame.md","mtime":1687881495985},{"fname":"Excalidraw Collaboration Frame.svg","mtime":1687881495985},{"fname":"Create DrawIO file.md","mtime":1688243858267},{"fname":"Create DrawIO file.svg","mtime":1688243858267},{"fname":"Ellipse Selected Elements.md","mtime":1690131476331},{"fname":"Ellipse Selected Elements.svg","mtime":1690131476331}] \ No newline at end of file +[{"fname":"Mindmap connector.md","mtime":1658686599427},{"fname":"Mindmap connector.svg","mtime":1658686599427},{"fname":"Add Connector Point.md","mtime":1645305706000},{"fname":"Add Connector Point.svg","mtime":1645944722000},{"fname":"Add Link to Existing File and Open.md","mtime":1647807918345},{"fname":"Add Link to Existing File and Open.svg","mtime":1645964261000},{"fname":"Add Link to New Page and Open.md","mtime":1654168862138},{"fname":"Add Link to New Page and Open.svg","mtime":1645960639000},{"fname":"Add Next Step in Process.md","mtime":1688304760357},{"fname":"Add Next Step in Process.svg","mtime":1645960639000},{"fname":"Box Each Selected Groups.md","mtime":1645305706000},{"fname":"Box Each Selected Groups.svg","mtime":1645967510000},{"fname":"Box Selected Elements.md","mtime":1645305706000},{"fname":"Box Selected Elements.svg","mtime":1645960639000},{"fname":"Change shape of selected elements.md","mtime":1652701169236},{"fname":"Change shape of selected elements.svg","mtime":1645960775000},{"fname":"Connect elements.md","mtime":1645305706000},{"fname":"Connect elements.svg","mtime":1645960639000},{"fname":"Convert freedraw to line.md","mtime":1645305706000},{"fname":"Convert freedraw to line.svg","mtime":1645960639000},{"fname":"Convert selected text elements to sticky notes.md","mtime":1670169501383},{"fname":"Convert selected text elements to sticky notes.svg","mtime":1645960639000},{"fname":"Convert text to link with folder and alias.md","mtime":1641639819000},{"fname":"Convert text to link with folder and alias.svg","mtime":1645960639000},{"fname":"Copy Selected Element Styles to Global.md","mtime":1642232088000},{"fname":"Copy Selected Element Styles to Global.svg","mtime":1645960639000},{"fname":"Create new markdown file and embed into active drawing.md","mtime":1640866935000},{"fname":"Create new markdown file and embed into active drawing.svg","mtime":1645960639000},{"fname":"Darken background color.md","mtime":1663059051059},{"fname":"Darken background color.svg","mtime":1645960639000},{"fname":"Elbow connectors.md","mtime":1671126911490},{"fname":"Elbow connectors.svg","mtime":1645960639000},{"fname":"Expand rectangles horizontally keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles horizontally keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles horizontally.md","mtime":1644950235000},{"fname":"Expand rectangles horizontally.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically keep text centered.md","mtime":1646563692000},{"fname":"Expand rectangles vertically keep text centered.svg","mtime":1645967510000},{"fname":"Expand rectangles vertically.md","mtime":1658686599427},{"fname":"Expand rectangles vertically.svg","mtime":1645967510000},{"fname":"Fixed horizontal distance between centers.md","mtime":1646743234000},{"fname":"Fixed horizontal distance between centers.svg","mtime":1645960639000},{"fname":"Fixed inner distance.md","mtime":1646743234000},{"fname":"Fixed inner distance.svg","mtime":1645960639000},{"fname":"Fixed spacing.md","mtime":1646743234000},{"fname":"Fixed spacing.svg","mtime":1645967510000},{"fname":"Fixed vertical distance between centers.md","mtime":1646743234000},{"fname":"Fixed vertical distance between centers.svg","mtime":1645967510000},{"fname":"Fixed vertical distance.md","mtime":1646743234000},{"fname":"Fixed vertical distance.svg","mtime":1645967510000},{"fname":"Lighten background color.md","mtime":1663059051059},{"fname":"Lighten background color.svg","mtime":1645959546000},{"fname":"Modify background color opacity.md","mtime":1644924415000},{"fname":"Modify background color opacity.svg","mtime":1645944722000},{"fname":"Normalize Selected Arrows.md","mtime":1670403743278},{"fname":"Normalize Selected Arrows.svg","mtime":1645960639000},{"fname":"Organic Line.md","mtime":1672920172531},{"fname":"Organic Line.svg","mtime":1645964261000},{"fname":"README.md","mtime":1645175700000},{"fname":"Repeat Elements.md","mtime":1663059051059},{"fname":"Repeat Elements.svg","mtime":1645960639000},{"fname":"Reverse arrows.md","mtime":1645305706000},{"fname":"Reverse arrows.svg","mtime":1645960639000},{"fname":"Scribble Helper.md","mtime":1682228345043},{"fname":"Scribble Helper.svg","mtime":1645944722000},{"fname":"Select Elements of Type.md","mtime":1643464321000},{"fname":"Select Elements of Type.svg","mtime":1645960639000},{"fname":"Set Dimensions.md","mtime":1645305706000},{"fname":"Set Dimensions.svg","mtime":1645944722000},{"fname":"Set Font Family.md","mtime":1645305706000},{"fname":"Set Font Family.svg","mtime":1645944722000},{"fname":"Set Grid.md","mtime":1674326971324},{"fname":"Set Grid.svg","mtime":1645960639000},{"fname":"Set Link Alias.md","mtime":1645305706000},{"fname":"Set Link Alias.svg","mtime":1645960639000},{"fname":"Set Stroke Width of Selected Elements.md","mtime":1645305706000},{"fname":"Set Stroke Width of Selected Elements.svg","mtime":1645960639000},{"fname":"Set Text Alignment.md","mtime":1645305706000},{"fname":"Set Text Alignment.svg","mtime":1645960639000},{"fname":"Set background color of unclosed line object by adding a shadow clone.md","mtime":1681665030892},{"fname":"Set background color of unclosed line object by adding a shadow clone.svg","mtime":1645960639000},{"fname":"Split text by lines.md","mtime":1645305706000},{"fname":"Split text by lines.svg","mtime":1645944722000},{"fname":"Zoom to Fit Selected Elements.md","mtime":1640770602000},{"fname":"Zoom to Fit Selected Elements.svg","mtime":1645960639000},{"fname":"directory-info.json","mtime":1646583437000},{"fname":"index-new.md","mtime":1645986149000},{"fname":"index.md","mtime":1645175700000},{"fname":"Grid Selected Images.md","mtime":1649614401982},{"fname":"Grid Selected Images.svg","mtime":1649614401982},{"fname":"Palette loader.md","mtime":1686511890942},{"fname":"Palette loader.svg","mtime":1649614401982},{"fname":"Rename Image.md","mtime":1663678478785},{"fname":"Rename Image.svg","mtime":1663678478785},{"fname":"Text Arch.md","mtime":1664095143846},{"fname":"Text Arch.svg","mtime":1670403743278},{"fname":"Deconstruct selected elements into new drawing.md","mtime":1672672112439},{"fname":"Deconstruct selected elements into new drawing.svg","mtime":1668541145255},{"fname":"Slideshow.md","mtime":1690319104444},{"fname":"Slideshow.svg","mtime":1670017348333},{"fname":"Auto Layout.md","mtime":1670403743278},{"fname":"Auto Layout.svg","mtime":1670175947081},{"fname":"Uniform size.md","mtime":1670175947081},{"fname":"Uniform size.svg","mtime":1670175947081},{"fname":"Mindmap format.md","mtime":1684484694228},{"fname":"Mindmap format.svg","mtime":1674944958059},{"fname":"Text to Sticky Notes.md","mtime":1678537561724},{"fname":"Text to Sticky Notes.svg","mtime":1678537561724},{"fname":"Folder Note Core - Make Current Drawing a Folder.md","mtime":1678973697470},{"fname":"Folder Note Core - Make Current Drawing a Folder.svg","mtime":1678973697470},{"fname":"Invert colors.md","mtime":1678973697470},{"fname":"Invert colors.svg","mtime":1678973697470},{"fname":"Auto Draw for Pen.md","mtime":1680418321236},{"fname":"Auto Draw for Pen.svg","mtime":1680418321236},{"fname":"Hardware Eraser Support.md","mtime":1680418321236},{"fname":"Hardware Eraser Support.svg","mtime":1680418321236},{"fname":"PDF Page Text to Clipboard.md","mtime":1683984041712},{"fname":"PDF Page Text to Clipboard.svg","mtime":1680418321236},{"fname":"Excalidraw Collaboration Frame.md","mtime":1687881495985},{"fname":"Excalidraw Collaboration Frame.svg","mtime":1687881495985},{"fname":"Create DrawIO file.md","mtime":1688243858267},{"fname":"Create DrawIO file.svg","mtime":1688243858267},{"fname":"Ellipse Selected Elements.md","mtime":1690131476331},{"fname":"Ellipse Selected Elements.svg","mtime":1690131476331}] \ No newline at end of file diff --git a/manifest.json b/manifest.json index 89b6143..30a7194 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.9.10", + "version": "1.9.11", "minAppVersion": "1.1.6", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/package.json b/package.json index 7209e2a..af4dae5 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "license": "MIT", "dependencies": { "@types/lz-string": "^1.3.34", - "@zsviczian/excalidraw": "0.15.2-obsidian-9", + "@zsviczian/excalidraw": "0.15.2-obsidian-10", "chroma-js": "^2.4.2", "clsx": "^1.2.1", "colormaster": "^1.2.1", diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 5d23f90..49fbebd 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -30,6 +30,7 @@ import { intersectElementWithLine, measureText, DEVICE, + restore, } from "src/Constants"; import { getDrawingFilename, getNewUniqueFilepath, } from "src/utils/FileUtils"; import { @@ -2607,7 +2608,7 @@ export function repositionElementsToCursor( element.y = element.y + offsetY; }); - return api.restore({elements}).elements; + return restore({elements}, null, null).elements; } function errorMessage(message: string, source: string) { diff --git a/src/ExcalidrawData.ts b/src/ExcalidrawData.ts index 2ffada6..2180c04 100644 --- a/src/ExcalidrawData.ts +++ b/src/ExcalidrawData.ts @@ -719,7 +719,7 @@ export class ExcalidrawData { wrapAt ? wrapText( originalText, getFontString({fontSize: te.fontSize, fontFamily: te.fontFamily}), - getBoundTextMaxWidth(container) + getBoundTextMaxWidth(container as any) ) : originalText, originalText, forceupdate, diff --git a/src/ExcalidrawLib.d.ts b/src/ExcalidrawLib.d.ts new file mode 100644 index 0000000..3eeef37 --- /dev/null +++ b/src/ExcalidrawLib.d.ts @@ -0,0 +1,116 @@ +import { RestoredDataState } from "@zsviczian/excalidraw/types/data/restore"; +import { ImportedDataState } from "@zsviczian/excalidraw/types/data/types"; +import { BoundingBox } from "@zsviczian/excalidraw/types/element/bounds"; +import { ExcalidrawBindableElement, ExcalidrawElement, ExcalidrawTextElement, FontFamilyValues, FontString, NonDeleted } from "@zsviczian/excalidraw/types/element/types"; +import { AppState, BinaryFiles, ExportOpts, Point, Zoom } from "@zsviczian/excalidraw/types/types"; +import { Mutable } from "@zsviczian/excalidraw/types/utility-types"; + +declare namespace ExcalidrawLib { + type ElementUpdate = Omit< + Partial, + "id" | "version" | "versionNonce" + >; + + type ExportOpts = { + elements: readonly NonDeleted[]; + appState?: Partial>; + files: BinaryFiles | null; + maxWidthOrHeight?: number; + getDimensions?: ( + width: number, + height: number, + ) => { width: number; height: number; scale?: number }; + }; + + function restore( + data: Pick | null, + localAppState: Partial | null | undefined, + localElements: readonly ExcalidrawElement[] | null | undefined, + elementsConfig?: { refreshDimensions?: boolean; repairBindings?: boolean }, + ): RestoredDataState; + + function exportToSvg(opts: Omit & { + elements: ExcalidrawElement[]; + appState?: AppState; + files?: any; + exportPadding?: number; + renderEmbeddables?: boolean; + }): Promise; + + function sceneCoordsToViewportCoords( + sceneCoords: { sceneX: number; sceneY: number }, + viewParams: { + zoom: Zoom; + offsetLeft: number; + offsetTop: number; + scrollX: number; + scrollY: number; + }, + ): { x: number; y: number }; + + function viewportCoordsToSceneCoords( + viewportCoords: { clientX: number; clientY: number }, + viewParams: { + zoom: Zoom; + offsetLeft: number; + offsetTop: number; + scrollX: number; + scrollY: number; + }, + ): { x: number; y: number }; + + function determineFocusDistance( + element: ExcalidrawBindableElement, + a: Point, + b: Point, + ): number; + + function intersectElementWithLine( + element: ExcalidrawBindableElement, + a: Point, + b: Point, + gap?: number, + ): Point[]; + + function getCommonBoundingBox( + elements: ExcalidrawElement[] | readonly NonDeleted[], + ): BoundingBox; + + function getMaximumGroups( + elements: ExcalidrawElement[], + ): ExcalidrawElement[][]; + + function measureText( + text: string, + font: FontString, + lineHeight: number, + ): { width: number; height: number; baseline: number }; + + function getDefaultLineHeight(fontFamily: FontFamilyValues): number; + + function wrapText(text: string, font: FontString, maxWidth: number): string; + + function getFontString({ + fontSize, + fontFamily, + }: { + fontSize: number; + fontFamily: FontFamilyValues; + }): FontString; + + function getBoundTextMaxWidth(container: ExcalidrawElement): number; + + function exportToBlob( + opts: ExportOpts & { + mimeType?: string; + quality?: number; + exportPadding?: number; + }, + ): Promise; + + function mutateElement>( + element: TElement, + updates: ElementUpdate, + informMutation?: boolean, + ): TElement; +} \ No newline at end of file diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index ad168ad..6a46218 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -9,7 +9,6 @@ import { MarkdownView, request, requireApiVersion, - WorkspaceSplit, } from "obsidian"; //import * as React from "react"; //import * as ReactDOM from "react-dom"; @@ -49,6 +48,7 @@ import { EXPORT_IMG_ICON_NAME, viewportCoordsToSceneCoords, ERROR_IFRAME_CONVERSION_CANCELED, + restore, } from "./Constants"; import ExcalidrawPlugin from "./main"; import { @@ -774,6 +774,18 @@ export default class ExcalidrawView extends TextFileView { new Notice(newState ? "Inverted Mode: Default arrow binding is now disabled. Use CTRL/CMD to temporarily enable binding when needed." : "Normal Mode: Arrow binding is now enabled. Use CTRL/CMD to temporarily disable binding when needed."); } + toggleFrameRendering() { + const frameRenderingSt = (this.excalidrawAPI as ExcalidrawImperativeAPI).getAppState().frameRendering; + this.updateScene({appState: {frameRendering: {...frameRenderingSt, enabled: !frameRenderingSt.enabled}}}); + new Notice(frameRenderingSt.enabled ? "Frame Rendering: Enabled" : "Frame Rendering: Disabled"); + } + + toggleFrameClipping() { + const frameRenderingSt = (this.excalidrawAPI as ExcalidrawImperativeAPI).getAppState().frameRendering; + this.updateScene({appState: {frameRendering: {...frameRenderingSt, clip: !frameRenderingSt.clip}}}); + new Notice(frameRenderingSt.clip ? "Frame Clipping: Enabled" : "Frame Clipping: Disabled"); + } + gotoFullscreen() { if(this.plugin.leafChangeTimeout) { clearTimeout(this.plugin.leafChangeTimeout); @@ -2773,6 +2785,7 @@ export default class ExcalidrawView extends TextFileView { colorPalette: st.colorPalette, currentStrokeOptions: st.currentStrokeOptions, previousGridSize: st.previousGridSize, + frameRendering: st.frameRendering, }, prevTextMode: this.prevTextMode, files, @@ -4337,15 +4350,15 @@ export default class ExcalidrawView extends TextFileView { files?: any; commitToHistory?: boolean; }, - restore: boolean = false, + shouldRestore: boolean = false, ) { const api = this.excalidrawAPI; if (!api) { return; } - const shouldRestoreElements = scene.elements && restore; + const shouldRestoreElements = scene.elements && shouldRestore; if (shouldRestoreElements) { - scene.elements = api.restore(scene).elements; + scene.elements = restore(scene, null, null).elements; } try { api.updateScene(scene); @@ -4360,7 +4373,7 @@ export default class ExcalidrawView extends TextFileView { if (!shouldRestoreElements) { //second attempt try { - scene.elements = api.restore(scene).elements; + scene.elements = restore(scene, null, null).elements; api.updateScene(scene); } catch (e) { errorlog({ diff --git a/src/constants.ts b/src/constants.ts index 073aa63..bf3514f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,11 +1,14 @@ import { customAlphabet } from "nanoid"; import { DeviceType } from "./types"; import { Platform } from "obsidian"; +import { ExcalidrawLib } from "./ExcalidrawLib"; //This is only for backward compatibility because an early version of obsidian included an encoding to avoid fantom links from littering Obsidian graph view declare const PLUGIN_VERSION:string; export const ERROR_IFRAME_CONVERSION_CANCELED = "iframe conversion canceled"; +declare const excalidrawLib: typeof ExcalidrawLib; + export const { sceneCoordsToViewportCoords, viewportCoordsToSceneCoords, @@ -21,7 +24,7 @@ export const { exportToSvg, exportToBlob, mutateElement, - //@ts-ignore + restore, } = excalidrawLib; export function JSON_parse(x: string): any { diff --git a/src/dialogs/Messages.ts b/src/dialogs/Messages.ts index 8d02e76..67d5eac 100644 --- a/src/dialogs/Messages.ts +++ b/src/dialogs/Messages.ts @@ -17,6 +17,8 @@ I develop this plugin as a hobby, spending my free time doing this. If you find
`, +"1.9.11":` +`, "1.9.10":` ## New - @mazurov added a new script: [Ellipse Selected Elements](https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/master/ea-scripts/Ellipse%20Selected%20Elements.md) diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index c6db856..9dbd176 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -507,6 +507,8 @@ FILENAME_HEAD: "Filename", EXIT_FULLSCREEN: "Exit fullscreen mode", TOGGLE_FULLSCREEN: "Toggle fullscreen mode", TOGGLE_DISABLEBINDING: "Toggle to invert default binding behavior", + TOGGLE_FRAME_RENDERING: "Toggle frame rendering", + TOGGLE_FRAME_CLIPPING: "Toggle frame clipping", OPEN_LINK_CLICK: "Navigate to selected element link", OPEN_LINK_PROPS: "Open markdown-embed properties or open link in new window", diff --git a/src/main.ts b/src/main.ts index 125f79b..8722b75 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1019,6 +1019,43 @@ export default class ExcalidrawPlugin extends Plugin { }, }); + this.addCommand({ + id: "disable-framerendering", + name: t("TOGGLE_FRAME_RENDERING"), + checkCallback: (checking: boolean) => { + if (checking) { + return ( + Boolean(this.app.workspace.getActiveViewOfType(ExcalidrawView)) + ); + } + const view = this.app.workspace.getActiveViewOfType(ExcalidrawView); + if (view) { + view.toggleFrameRendering(); + return true; + } + return false; + }, + }); + + this.addCommand({ + id: "disable-frameclipping", + name: t("TOGGLE_FRAME_CLIPPING"), + checkCallback: (checking: boolean) => { + if (checking) { + return ( + Boolean(this.app.workspace.getActiveViewOfType(ExcalidrawView)) + ); + } + const view = this.app.workspace.getActiveViewOfType(ExcalidrawView); + if (view) { + view.toggleFrameClipping(); + return true; + } + return false; + }, + }); + + this.addCommand({ id: "export-image", name: t("EXPORT_IMAGE"), diff --git a/src/svgToExcalidraw/elements/ExcalidrawScene.ts b/src/svgToExcalidraw/elements/ExcalidrawScene.ts index ce237eb..68e6bbd 100644 --- a/src/svgToExcalidraw/elements/ExcalidrawScene.ts +++ b/src/svgToExcalidraw/elements/ExcalidrawScene.ts @@ -1,5 +1,6 @@ import { GITHUB_RELEASES } from "src/Constants"; import { ExcalidrawGenericElement } from "./ExcalidrawElement"; + declare const PLUGIN_VERSION:string; class ExcalidrawScene { diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9643197..cc76bfc 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -25,9 +25,10 @@ import { ExcalidrawElement } from "@zsviczian/excalidraw/types/element/types"; import { ExportSettings } from "../ExcalidrawView"; import { compressToBase64, decompressFromBase64 } from "lz-string"; import { getDataURLFromURL, getIMGFilename, getMimeType, getURLImageExtension } from "./FileUtils"; -import ExcalidrawScene from "../svgToExcalidraw/elements/ExcalidrawScene"; import { IMAGE_TYPES } from "../Constants"; import { generateEmbeddableLink } from "./CustomEmbeddableUtils"; +import Scene from "@zsviczian/excalidraw/types/scene/Scene"; +import ExcalidrawScene from "src/svgToExcalidraw/elements/ExcalidrawScene"; declare const PLUGIN_VERSION:string;