From ce2713ecdbe158565411eec0cd63ebae1f66a113 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Wed, 13 May 2026 18:49:38 +0200 Subject: [PATCH] fixed any vs. ExcalidrawImperativeAPI --- src/core/managers/CommandManager.ts | 4 +- src/core/managers/ObserverManager.ts | 2 +- src/shared/Dialogs/EmbeddableSettings.ts | 2 +- src/shared/Dialogs/ExportDialog.ts | 2 +- src/shared/Dialogs/InsertPDFModal.ts | 2 +- .../Dialogs/UniversalInsertFileModal.ts | 2 +- src/shared/ExcalidrawAutomate.ts | 20 ++--- src/utils/dynamicStyling.ts | 4 +- src/utils/excalidrawViewUtils.ts | 12 +-- src/utils/getElementAtPointer.ts | 14 ++-- src/utils/screenshot.ts | 2 +- src/view/ExcalidrawView.ts | 76 +++++++++---------- .../components/menu/EmbeddableActionsMenu.tsx | 4 +- src/view/components/menu/ToolsPanel.tsx | 2 +- 14 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/core/managers/CommandManager.ts b/src/core/managers/CommandManager.ts index f1667db4..0a0e045f 100644 --- a/src/core/managers/CommandManager.ts +++ b/src/core/managers/CommandManager.ts @@ -338,7 +338,7 @@ export class CommandManager { } if(checking) return true; const ea = getEA(view) as ExcalidrawAutomate; - const api = ea.getExcalidrawAPI() as ExcalidrawImperativeAPI; + const api = ea.getExcalidrawAPI(); ea.copyViewElementsToEAforEditing(els); const scale = 1/api.getAppState().zoom.value; ea.getElements().forEach((el: Mutable)=>{ @@ -1026,7 +1026,7 @@ export class CommandManager { if(DEVICE.isMobile) return false; if(this.app.workspace.getActiveViewOfType(ExcalidrawView)) { const view = this.app.workspace.getActiveViewOfType(ExcalidrawView); - const api = view?.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view?.excalidrawAPI; if(!api || !api.isTrayModeEnabled()) return false; return true; } diff --git a/src/core/managers/ObserverManager.ts b/src/core/managers/ObserverManager.ts index 0c7559b3..9e8617e9 100644 --- a/src/core/managers/ObserverManager.ts +++ b/src/core/managers/ObserverManager.ts @@ -244,7 +244,7 @@ export class ObserverManager { return; } - const { errorMessage } = (view.excalidrawAPI as ExcalidrawImperativeAPI).getAppState(); + const { errorMessage } = (view.excalidrawAPI).getAppState(); if (!errorMessage) this.plugin.activeExcalidrawView.save(); }; diff --git a/src/shared/Dialogs/EmbeddableSettings.ts b/src/shared/Dialogs/EmbeddableSettings.ts index 5b2279e7..70c15a10 100644 --- a/src/shared/Dialogs/EmbeddableSettings.ts +++ b/src/shared/Dialogs/EmbeddableSettings.ts @@ -114,7 +114,7 @@ export class EmbeddableSettings extends Modal { button .setButtonText(t("ES_ZOOM_100")) .onClick(() => { - const api = this.view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.view.excalidrawAPI; this.zoomValue = 1/api.getAppState().zoom.value; zoomSetting.setDesc(zoomValue()); }) diff --git a/src/shared/Dialogs/ExportDialog.ts b/src/shared/Dialogs/ExportDialog.ts index dc488f39..1e01cba2 100644 --- a/src/shared/Dialogs/ExportDialog.ts +++ b/src/shared/Dialogs/ExportDialog.ts @@ -56,7 +56,7 @@ export class ExportDialog extends Modal { ) { super(plugin.app); this.ea = getEA(this.view); - this.api = this.ea.getExcalidrawAPI() as ExcalidrawImperativeAPI; + this.api = this.ea.getExcalidrawAPI(); this.padding = getExportPadding(this.plugin,this.file); this.scale = getPNGScale(this.plugin,this.file) this.theme = getExportTheme(this.plugin, this.file, (this.api).getAppState().theme) diff --git a/src/shared/Dialogs/InsertPDFModal.ts b/src/shared/Dialogs/InsertPDFModal.ts index 9a51bc34..fca4ae6b 100644 --- a/src/shared/Dialogs/InsertPDFModal.ts +++ b/src/shared/Dialogs/InsertPDFModal.ts @@ -516,7 +516,7 @@ export class InsertPDFModal extends Modal { ea.addToGroup(ids); } await ea.addElementsToView(true,true,false); - const api = ea.getExcalidrawAPI() as ExcalidrawImperativeAPI; + const api = ea.getExcalidrawAPI(); const ids = ea.getElements().map(el => el.id); const viewElements = ea.getViewElements().filter(el => ids.includes(el.id)); api.selectElements(viewElements); diff --git a/src/shared/Dialogs/UniversalInsertFileModal.ts b/src/shared/Dialogs/UniversalInsertFileModal.ts index a3e9bfdb..13b3bc9b 100644 --- a/src/shared/Dialogs/UniversalInsertFileModal.ts +++ b/src/shared/Dialogs/UniversalInsertFileModal.ts @@ -21,7 +21,7 @@ export class UniversalInsertFileModal extends Modal { private view: ExcalidrawView, ) { super(plugin.app); - const appState = (view.excalidrawAPI as ExcalidrawImperativeAPI).getAppState(); + const appState = (view.excalidrawAPI).getAppState(); const containerRect = view.containerEl.getBoundingClientRect(); const viewportWidth = window.innerWidth || document.documentElement.clientWidth; const viewportHeight = window.innerHeight || document.documentElement.clientHeight; diff --git a/src/shared/ExcalidrawAutomate.ts b/src/shared/ExcalidrawAutomate.ts index 430803be..0c5ca2d4 100644 --- a/src/shared/ExcalidrawAutomate.ts +++ b/src/shared/ExcalidrawAutomate.ts @@ -806,7 +806,7 @@ export class ExcalidrawAutomate { errorMessage("targetView not set", "getExcalidrawAPI()"); return null; } - const st = (this.getExcalidrawAPI() as ExcalidrawImperativeAPI).getAppState(); + const st = (this.getExcalidrawAPI()).getAppState(); if (!st) return null; const zoom = st.zoom?.value ?? 1; @@ -2751,9 +2751,9 @@ export class ExcalidrawAutomate { /** * Returns the Excalidraw API for the current view. - * @returns {any} The Excalidraw API. + * @returns {ExcalidrawImperativeAPI} The Excalidraw API. */ - getExcalidrawAPI(): any { + getExcalidrawAPI(): ExcalidrawImperativeAPI { if (!this.targetView || !this.targetView?._loaded) { errorMessage("targetView not set", "getExcalidrawAPI()"); return null; @@ -2763,9 +2763,9 @@ export class ExcalidrawAutomate { /** * Gets elements in the current view. - * @returns {ExcalidrawElement[]} Array of elements in the view. + * @returns {readonly ExcalidrawElement[]} Array of elements in the view. */ - getViewElements(): ExcalidrawElement[] { + getViewElements(): readonly ExcalidrawElement[] { if (!this.targetView || !this.targetView?._loaded) { errorMessage("targetView not set", "getViewElements()"); return []; @@ -2783,7 +2783,7 @@ export class ExcalidrawAutomate { errorMessage("targetView not set", "deleteViewElements()"); return false; } - const api = this.targetView?.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.targetView?.excalidrawAPI; if (!api) { return false; } @@ -3595,7 +3595,7 @@ export class ExcalidrawAutomate { * @param {ExcalidrawElement[]} elements - Array of elements to get the bounding box for. * @returns {{topX: number; topY: number; width: number; height: number}} The bounding box of the elements. */ - getBoundingBox(elements: ExcalidrawElement[]): { + getBoundingBox(elements: readonly ExcalidrawElement[]): { topX: number; topY: number; width: number; @@ -3687,7 +3687,7 @@ export class ExcalidrawAutomate { */ getElementsInTheSameGroupWithElement( element: ExcalidrawElement, - elements: ExcalidrawElement[], + elements: readonly NonDeletedExcalidrawElement[], includeFrameElements: boolean = false, ): ExcalidrawElement[] { if(!element || !elements) return []; @@ -3734,7 +3734,7 @@ export class ExcalidrawAutomate { */ getElementsInFrame( frameElement: ExcalidrawElement, - elements: ExcalidrawElement[], + elements: readonly NonDeletedExcalidrawElement[], shouldIncludeFrame: boolean = false, ): ExcalidrawElement[] { if(!frameElement || !elements || frameElement.type !== "frame") return []; @@ -3976,7 +3976,7 @@ export class ExcalidrawAutomate { return; } const API = this.getExcalidrawAPI(); - const elements = this.getViewElements(); + const elements = this.getViewElements() as Mutable[]; const elementToMove = elements.filter((el: any) => el.id === elementId); if (elementToMove.length === 0) { errorMessage( diff --git a/src/utils/dynamicStyling.ts b/src/utils/dynamicStyling.ts index e9e9ae31..d1c535d9 100644 --- a/src/utils/dynamicStyling.ts +++ b/src/utils/dynamicStyling.ts @@ -153,7 +153,7 @@ export const setDynamicStyle = ( } window.setTimeout(()=>{ - const api = view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view.excalidrawAPI; if(!api) { view = null; ea = null; @@ -178,7 +178,7 @@ export const setDynamicStyle = ( ) { return; } - (view.excalidrawAPI as ExcalidrawImperativeAPI).mutateElement(e,{customData: f.customData}); + (view.excalidrawAPI).mutateElement(e,{customData: f.customData}); }); view.updateScene({ diff --git a/src/utils/excalidrawViewUtils.ts b/src/utils/excalidrawViewUtils.ts index 034538a5..d130ab2b 100644 --- a/src/utils/excalidrawViewUtils.ts +++ b/src/utils/excalidrawViewUtils.ts @@ -4,7 +4,7 @@ import { App,Modal,Notice,TFile } from "obsidian"; import { ExcalidrawAutomate } from "src/shared/ExcalidrawAutomate"; import { REGEX_LINK,REG_LINKINDEX_HYPERLINK,getExcalidrawMarkdownHeaderSection,REGEX_TAGS } from "../shared/ExcalidrawData"; import ExcalidrawView from "src/view/ExcalidrawView"; -import { ExcalidrawElement,ExcalidrawFrameElement,ExcalidrawImageElement } from "@zsviczian/excalidraw/types/element/src/types"; +import { ExcalidrawElement,ExcalidrawFrameElement,ExcalidrawImageElement, NonDeletedExcalidrawElement } from "@zsviczian/excalidraw/types/element/src/types"; import { getEmbeddedFilenameParts,getLinkParts,isImagePartRef } from "./utils"; import { getAudioElementHeight } from "./obsidianUtils"; import { cleanSectionHeading } from "./pathUtils"; @@ -60,7 +60,7 @@ export async function insertEmbeddableToView ( shouldInsertToView: boolean = true, ):Promise { if(shouldInsertToView) {ea.clear();} - const api = ea.getExcalidrawAPI() as ExcalidrawImperativeAPI; + const api = ea.getExcalidrawAPI(); const st = api.getAppState(); if(ea.plugin.settings.embeddableMarkdownDefaults.backgroundMatchElement) { @@ -147,7 +147,7 @@ function isInternalLink(link:string):boolean { return true; } -export function sceneRemoveInternalLinks(scene: {elements: ExcalidrawElement[]}): ExcalidrawElement[] { +export function sceneRemoveInternalLinks(scene: {elements: readonly ExcalidrawElement[]}): ExcalidrawElement[] { const elements: ExcalidrawElement[] = JSON.parse(JSON.stringify(scene.elements)); elements.forEach(el => { if(!el.link) return; @@ -244,7 +244,7 @@ export function getExcalidrawFileForwardLinks ( export function getFrameBasedOnFrameNameOrId( frameName: string, - elements: ExcalidrawElement[], + elements: readonly NonDeletedExcalidrawElement[], ): ExcalidrawFrameElement | null { const frames = elements .filter((el: ExcalidrawElement)=>el.type==="frame") @@ -309,7 +309,7 @@ export async function addBackOfTheNoteCard( ); await ea.addElementsToView(!center, false, true); - const api = view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view.excalidrawAPI; const el = ea.getViewElements().find(el=>el.id === id); api.selectElements([el]); if(activate) { @@ -536,7 +536,7 @@ export function getViewColorPalette( return getDefaultColorPalette() as (string[] | string)[]; } - const api = view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view.excalidrawAPI; const {colorPalette} = api.getAppState(); if (!colorPalette || !colorPalette.hasOwnProperty(palette)) { return getDefaultColorPalette() as (string[] | string)[]; diff --git a/src/utils/getElementAtPointer.ts b/src/utils/getElementAtPointer.ts index 513918d2..ee1e645f 100644 --- a/src/utils/getElementAtPointer.ts +++ b/src/utils/getElementAtPointer.ts @@ -1,13 +1,13 @@ -import { ExcalidrawElement,ExcalidrawImageElement,ExcalidrawTextElement } from "@zsviczian/excalidraw/types/element/src/types"; -import { REGEX_LINK,REG_LINKINDEX_HYPERLINK } from "../shared/ExcalidrawData"; -import { TextMode } from "src/shared/TextMode"; -import type ExcalidrawView from "src/view/ExcalidrawView"; -import { rotatedDimensions } from "./utils"; -import { getBoundTextElementId } from "src/utils/excalidrawViewHelpers"; +import { ExcalidrawElement,ExcalidrawImageElement,ExcalidrawTextElement } from "@zsviczian/excalidraw/types/element/src/types"; +import { REGEX_LINK,REG_LINKINDEX_HYPERLINK } from "../shared/ExcalidrawData"; +import { TextMode } from "src/shared/TextMode"; +import type ExcalidrawView from "src/view/ExcalidrawView"; +import { rotatedDimensions } from "./utils"; +import { getBoundTextElementId } from "src/utils/excalidrawViewHelpers"; export const getElementsAtPointer = ( pointer: any, - elements: ExcalidrawElement[], + elements: readonly ExcalidrawElement[], type?: string, ): ExcalidrawElement[] => { return elements.filter((e: ExcalidrawElement) => { diff --git a/src/utils/screenshot.ts b/src/utils/screenshot.ts index 0ed8577e..ae7752ba 100644 --- a/src/utils/screenshot.ts +++ b/src/utils/screenshot.ts @@ -23,7 +23,7 @@ export async function captureScreenshot(view: ExcalidrawView, options: Screensho if (!wasFullscreen) { view.gotoFullscreen(); } - const api = view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view.excalidrawAPI; api.setForceRenderAllEmbeddables(true); options.selectedOnly = options.selectedOnly && (view.getViewSelectedElements().length > 0); const remote = window.require("electron").remote; diff --git a/src/view/ExcalidrawView.ts b/src/view/ExcalidrawView.ts index 9f4e905a..10afbe41 100644 --- a/src/view/ExcalidrawView.ts +++ b/src/view/ExcalidrawView.ts @@ -296,7 +296,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ public excalidrawData: ExcalidrawData; //public excalidrawRef: React.MutableRefObject = null; public excalidrawRoot: any; - public excalidrawAPI:any = null; + public excalidrawAPI:ExcalidrawImperativeAPI = null; public excalidrawWrapperRef: React.MutableRefObject | null = null; public toolsPanelRef: React.MutableRefObject | null = null; public embeddableMenuRef: React.MutableRefObject | null = null; @@ -544,7 +544,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } private async loadFilesForExport(exportTheme: string): Promise | null> { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api || !this.excalidrawData) { return null; } @@ -1188,13 +1188,13 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } toggleFrameRendering() { - const frameRenderingSt = (this.excalidrawAPI as ExcalidrawImperativeAPI).getAppState().frameRendering; + const frameRenderingSt = (this.excalidrawAPI).getAppState().frameRendering; this.updateScene({appState: {frameRendering: {...frameRenderingSt, enabled: !frameRenderingSt.enabled}}, captureUpdate: CaptureUpdateAction.NEVER,}); new Notice(frameRenderingSt.enabled ? t("FRAME_CLIPPING_ENABLED") : t("FRAME_CLIPPING_DISABLED")); } toggleFrameClipping() { - const frameRenderingSt = (this.excalidrawAPI as ExcalidrawImperativeAPI).getAppState().frameRendering; + const frameRenderingSt = (this.excalidrawAPI).getAppState().frameRendering; this.updateScene({appState: {frameRendering: {...frameRenderingSt, clip: !frameRenderingSt.clip}}, captureUpdate: CaptureUpdateAction.NEVER,}); new Notice(frameRenderingSt.clip ? "Frame Clipping: Enabled" : "Frame Clipping: Disabled"); } @@ -1499,7 +1499,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } if (this.excalidrawData.hasMermaid(selectedImage.fileId) || getMermaidText(imageElement)) { if(shouldRenderMermaid) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; api.updateScene({appState: {openDialog: { name: "ttd", tab: "mermaid" }}, captureUpdate: CaptureUpdateAction.NEVER }) } return; @@ -1661,7 +1661,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } excalidrawGetSceneVersion: (elements: ExcalidrawElement[]) => number; - getSceneVersion (elements: ExcalidrawElement[]):number { + getSceneVersion (elements: readonly NonDeletedExcalidrawElement[]):number { if(!this.excalidrawGetSceneVersion) { this.excalidrawGetSceneVersion = this.packages.excalidrawLib.getSceneVersion; } @@ -1814,7 +1814,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ if(!this.excalidrawAPI || !this.excalidrawData.loaded || !this.isDirty()) { return; } - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; const st = api.getAppState(); if(st.activeTool.type !== "image" && st.activeEmbeddable?.state !== "active") { this.forceSave(true); @@ -3512,7 +3512,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public setCurrentPositionToCenter(){ - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return; } @@ -3694,7 +3694,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ alias: string, originalLink?: string, ) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; const st = api.getAppState(); if( !st.selectedElementIds || @@ -3734,7 +3734,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ fontFamily?: 1 | 2 | 3 | 4, save: boolean = true ): Promise { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return; } @@ -3792,7 +3792,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ shouldRestoreElements?: boolean; captureUpdate?: CaptureUpdateActionType; }): Promise { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return false; } @@ -3946,7 +3946,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ if (!api) { return null; } - const el: ExcalidrawElement[] = selectedOnly ? this.getViewSelectedElements() : api.getSceneElements(); + const el: readonly NonDeletedExcalidrawElement[] = selectedOnly ? this.getViewSelectedElements() : api.getSceneElements(); const st: AppState = api.getAppState(); const files = {...api.getFiles()}; @@ -4283,7 +4283,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ if (!this.plugin.settings.allowCtrlClick && !isWinMETAorMacCTRL(e)) { return; } - if (Boolean((this.excalidrawAPI as ExcalidrawImperativeAPI)?.getAppState().contextMenu)) { + if (Boolean((this.excalidrawAPI)?.getAppState().contextMenu)) { return; } //added setTimeout when I changed onClick(e: MouseEvent) to onPointerDown() in 1.7.9. @@ -4359,7 +4359,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ this.blockOnMouseButtonDown = false; } if (isWinCTRLorMacCMD(this.modifierKeyDown) || - (this.excalidrawAPI.getAppState().isViewModeEnabled && + (this.excalidrawAPI.getAppState().viewModeEnabled && this.plugin.settings.hoverPreviewWithoutCTRL)) { this.showHoverPreview(); @@ -4368,7 +4368,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ public updateGridColor(canvasColor?: string, st?: any) { if(!canvasColor) { - st = (this.excalidrawAPI as ExcalidrawImperativeAPI).getAppState(); + st = (this.excalidrawAPI).getAppState(); canvasColor = canvasColor ?? st.viewBackgroundColor === "transparent" ? "white" : st.viewBackgroundColor; } window.setTimeout(()=>{ @@ -4415,7 +4415,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } } - private checkSceneVersion(et: ExcalidrawElement[]) { + private checkSceneVersion(et: readonly NonDeletedExcalidrawElement[]) { const sceneVersion = this.getSceneVersion(et); if ( ((sceneVersion > 0 || @@ -4525,7 +4525,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } private onPaste (data: ClipboardData, event: ClipboardEvent | null, files: ParsedDataTransferFile[]) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; const ea = this.getHookServer(); if (files?.length || (data?.mixedContent && data.mixedContent.some(d=>d.type==="imageUrl"))) { @@ -4753,7 +4753,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ //returns the raw text of the element which is the original text without parsing //in compatibility mode, returns the original text, and for backward compatibility the text if originalText is not available private onBeforeTextEdit (textElement: ExcalidrawTextElement, isExistingElement: boolean): string { - /*const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + /*const api = this.excalidrawAPI; const st = api.getAppState(); setDynamicStyle( this.plugin.ea, @@ -4818,7 +4818,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ const WARNING = t("WARNING_PASTING_ELEMENT_AS_TEXT"); if(nextOriginalText.startsWith(FORBIDDEN_TEXT)) { window.setTimeout(()=>{ - const elements = this.excalidrawAPI.getSceneElements(); + const elements = this.excalidrawAPI.getSceneElements() as Mutable[]; const el = elements.filter((el:ExcalidrawElement)=>el.id === textElement.id); if(el.length === 1) { const clone = cloneElement(el[0]); @@ -4841,7 +4841,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ // 1 2 if(isTextImageTransclusion(nextOriginalText, this, (link, file)=>{ window.setTimeout(async ()=>{ - const elements = this.excalidrawAPI.getSceneElements(); + const elements = this.excalidrawAPI.getSceneElements() as Mutable[]; const el = elements.filter((el:ExcalidrawElement)=>el.id === textElement.id) as ExcalidrawTextElement[]; if(el.length === 1) { const center = {x: el[0].x, y: el[0].y }; @@ -4890,10 +4890,10 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ //this callback function will only be invoked if quick parse fails, i.e. there is a transclusion in the raw text if(this.textMode === TextMode.raw) return; - const elements = this.excalidrawAPI.getSceneElements(); + const elements = this.excalidrawAPI.getSceneElements() as Mutable[]; const elementsMap = arrayToMap(elements); const el = elements.filter((el:ExcalidrawElement)=>el.id === textElement.id); - if(el.length === 1) { + if(el.length === 1 && el[0].type === "text") { const container = getContainerElement(el[0],elementsMap); const clone = cloneElement(el[0]); if(!el[0]?.isDeleted) { @@ -5196,7 +5196,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ dataURL: dataURL as DataURL, created: embeddedFile.mtime, }); - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; api.addFiles(files); await ea.addElementsToView(false,true); ea.destroy(); @@ -5215,7 +5215,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ private onContextMenu(elements: readonly ExcalidrawElement[], appState: AppState, onClose: (callback?: () => void) => void) { const React = this.packages.react; const contextMenuActions = []; - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; const selectedElementIds = Object.keys(api.getAppState().selectedElementIds); const areElementsSelected = selectedElementIds.length > 0; @@ -5273,7 +5273,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ t("SELECT_TEXTELEMENT_ONLY"), () => { window.setTimeout(() => - (this.excalidrawAPI as ExcalidrawImperativeAPI).selectElements([selectedTextElement]) + (this.excalidrawAPI).selectElements([selectedTextElement]) ); }, onClose, @@ -5958,7 +5958,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } private scheduleBatchedResize(currentDeltaHeight: number) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api || !api.isTouchScreen) return; if (!this.resizeBatchTimer) { @@ -5991,7 +5991,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ private onExcalidrawResize() { try { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if(!api) return; const width = this.contentEl.clientWidth; const height = this.contentEl.clientHeight; @@ -6311,7 +6311,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public updatePinnedScripts() { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return false; } @@ -6322,7 +6322,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public updatePinnedCustomPens() { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return false; } @@ -6335,7 +6335,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public updatePinchZoom() { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return false; } @@ -6346,7 +6346,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public updateWheelZoom() { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return false; } @@ -6357,7 +6357,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public toggleEnableContextMenu() { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return; } @@ -6366,7 +6366,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ } public setUIMode(mode: UIMode) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; api.setDesktopUIMode(mode); } @@ -6434,7 +6434,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ selectResult: boolean, elements: ExcalidrawElement[] ) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) return; const zoomLevel = this.plugin.settings.zoomToFitMaxLevel; @@ -6444,7 +6444,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ api.zoomToFit(elements, zoomLevel, 0.05); } - public getViewElements(): ExcalidrawElement[] { + public getViewElements(): readonly ExcalidrawElement[] { const api = this.excalidrawAPI; if (!api) { return []; @@ -6458,7 +6458,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ * @returns */ public getViewSelectedElements(includFrameChildren: boolean = true): ExcalidrawElement[] { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return []; } @@ -6525,7 +6525,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ }, shouldRestore: boolean = false, ) { - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; if (!api) { return; } @@ -6621,7 +6621,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ public getActiveEmbeddable ():{leaf: WorkspaceLeaf; node?: ObsidianCanvasNode; editNode?: Function}|null { if(!this.excalidrawAPI) return null; - const api = this.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.excalidrawAPI; const st = api.getAppState(); if(!st.activeEmbeddable || st.activeEmbeddable.state !== "active" ) return null; return this.getEmbeddableLeafElementById(st.activeEmbeddable?.element?.id); diff --git a/src/view/components/menu/EmbeddableActionsMenu.tsx b/src/view/components/menu/EmbeddableActionsMenu.tsx index 3079eab8..a3511364 100644 --- a/src/view/components/menu/EmbeddableActionsMenu.tsx +++ b/src/view/components/menu/EmbeddableActionsMenu.tsx @@ -200,7 +200,7 @@ export class EmbeddableMenu { private actionZoomToElement (element: ExcalidrawEmbeddableElement, maxLevel?: number) { if(!element) return; - const api = this.view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = this.view.excalidrawAPI; api.zoomToFit([element], maxLevel ?? this.view.plugin.settings.zoomToFitMaxLevel, 0.1); } @@ -235,7 +235,7 @@ export class EmbeddableMenu { renderButtons(appState: AppState) { const view = this.view; - const api = view?.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view?.excalidrawAPI; if(!api) return null; if(!view.file) return null; const disableFrameButtons = appState.viewModeEnabled && !view.allowFrameButtonsInViewMode; diff --git a/src/view/components/menu/ToolsPanel.tsx b/src/view/components/menu/ToolsPanel.tsx index e2fb782a..3613080a 100644 --- a/src/view/components/menu/ToolsPanel.tsx +++ b/src/view/components/menu/ToolsPanel.tsx @@ -425,7 +425,7 @@ export class ToolsPanel extends React.Component { const view = this.getView(); const plugin = view?.plugin; if (!view || !plugin) return; - const api = view.excalidrawAPI as ExcalidrawImperativeAPI; + const api = view.excalidrawAPI; await plugin.loadSettings(); const index = plugin.settings.pinnedScripts.indexOf(key) if(index > -1) {