From 3ae59c85d254e563c1820547379179284fd37995 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Thu, 12 Sep 2024 09:07:43 +0000 Subject: [PATCH] Obsidian 1.7.2: rework getExcalidrawViews from leaves, fix tools panel width, fix math types --- src/ExcalidrawAutomate.ts | 25 +++++------------ src/Scripts.ts | 9 +++---- src/dialogs/PenSettingsModal.ts | 13 +++++---- src/index.ts | 2 +- src/main.ts | 28 +++++++++---------- src/menu/ObsidianMenu.tsx | 11 +++----- src/menu/ToolsPanel.tsx | 19 ++++++------- src/settings.ts | 48 +++++++++++---------------------- src/types/types.d.ts | 2 ++ src/utils/CarveOut.ts | 3 ++- src/utils/ObsidianUtils.ts | 8 +++++- 11 files changed, 69 insertions(+), 99 deletions(-) diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 671c787..c0bdc3d 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -21,7 +21,6 @@ import { ExcalidrawData, getMarkdownDrawingSection, REGEX_LINK } from "src/Excal import { FRONTMATTER, nanoid, - VIEW_TYPE_EXCALIDRAW, MAX_IMAGE_SIZE, COLOR_NAMES, fileid, @@ -55,14 +54,14 @@ import { wrapTextAtCharLength, arrayToMap, } from "src/utils/Utils"; -import { getAttachmentsFolderAndFilePath, getLeaf, getNewOrAdjacentLeaf, isObsidianThemeDark, mergeMarkdownFiles, openLeaf } from "src/utils/ObsidianUtils"; -import { AppState, BinaryFileData, DataURL, ExcalidrawImperativeAPI, Point } from "@zsviczian/excalidraw/types/excalidraw/types"; +import { getAttachmentsFolderAndFilePath, getExcalidrawViews, getLeaf, getNewOrAdjacentLeaf, isObsidianThemeDark, mergeMarkdownFiles, openLeaf } from "src/utils/ObsidianUtils"; +import { AppState, BinaryFileData, DataURL, ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/excalidraw/types"; import { EmbeddedFile, EmbeddedFilesLoader, FileData } from "src/EmbeddedFileLoader"; import { tex2dataURL } from "src/LaTeX"; import { GenericInputPrompt, NewFileActions } from "src/dialogs/Prompt"; import { t } from "src/lang/helpers"; import { ScriptEngine } from "src/Scripts"; -import { ConnectionPoint, DeviceType } from "src/types/types"; +import { ConnectionPoint, DeviceType, Point } from "src/types/types"; import CM, { ColorMaster, extendPlugins } from "@zsviczian/colormaster"; import HarmonyPlugin from "@zsviczian/colormaster/plugins/harmony"; import MixPlugin from "@zsviczian/colormaster/plugins/mix" @@ -1826,33 +1825,23 @@ export class ExcalidrawAutomate { */ setView(view?: ExcalidrawView | "first" | "active"): ExcalidrawView { if(!view) { - const v = app.workspace.getActiveViewOfType(ExcalidrawView); + const v = this.plugin.app.workspace.getActiveViewOfType(ExcalidrawView); if (v instanceof ExcalidrawView) { this.targetView = v; } else { - const leaves = - app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - if (!leaves || leaves.length == 0) { - return; - } - this.targetView = leaves[0].view as ExcalidrawView; + this.targetView = getExcalidrawViews(this.plugin.app)[0]; } } if (view == "active") { - const v = app.workspace.getActiveViewOfType(ExcalidrawView); + const v = this.plugin.app.workspace.getActiveViewOfType(ExcalidrawView); if (!(v instanceof ExcalidrawView)) { return; } this.targetView = v; } if (view == "first") { - const leaves = - app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - if (!leaves || leaves.length == 0) { - return; - } - this.targetView = leaves[0].view as ExcalidrawView; + this.targetView = getExcalidrawViews(this.plugin.app)[0]; } if (view instanceof ExcalidrawView) { this.targetView = view; diff --git a/src/Scripts.ts b/src/Scripts.ts index c12e67f..1c98271 100644 --- a/src/Scripts.ts +++ b/src/Scripts.ts @@ -5,7 +5,7 @@ import { TFile, WorkspaceLeaf, } from "obsidian"; -import { PLUGIN_ID, VIEW_TYPE_EXCALIDRAW } from "./constants/constants"; +import { PLUGIN_ID } from "./constants/constants"; import ExcalidrawView from "./ExcalidrawView"; import ExcalidrawPlugin from "./main"; import { ButtonDefinition, GenericInputPrompt, GenericSuggester } from "./dialogs/Prompt"; @@ -14,6 +14,7 @@ import { splitFolderAndFilename } from "./utils/FileUtils"; import { getEA } from "src"; import { ExcalidrawAutomate } from "./ExcalidrawAutomate"; import { WeakArray } from "./utils/WeakArray"; +import { getExcalidrawViews } from "./utils/ObsidianUtils"; export type ScriptIconMap = { [key: string]: { name: string; group: string; svgString: string }; @@ -303,10 +304,8 @@ export class ScriptEngine { } private updateToolPannels() { - const leaves = - this.plugin.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - leaves.forEach((leaf: WorkspaceLeaf) => { - const excalidrawView = leaf.view as ExcalidrawView; + const excalidrawViews = getExcalidrawViews(this.plugin.app); + excalidrawViews.forEach(excalidrawView => { excalidrawView.toolsPanelRef?.current?.updateScriptIconMap( this.scriptIconMap, ); diff --git a/src/dialogs/PenSettingsModal.ts b/src/dialogs/PenSettingsModal.ts index 803c251..351fb36 100644 --- a/src/dialogs/PenSettingsModal.ts +++ b/src/dialogs/PenSettingsModal.ts @@ -1,12 +1,13 @@ import { ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/excalidraw/types"; -import { ColorComponent, Modal, Setting, SliderComponent, TextComponent, ToggleComponent } from "obsidian"; -import { COLOR_NAMES, VIEW_TYPE_EXCALIDRAW } from "src/constants/constants"; +import { ColorComponent, Modal, Setting, TextComponent, ToggleComponent } from "obsidian"; +import { COLOR_NAMES } from "src/constants/constants"; import ExcalidrawView from "src/ExcalidrawView"; import ExcalidrawPlugin from "src/main"; import { setPen } from "src/menu/ObsidianMenu"; -import { ExtendedFillStyle, PenStyle, PenType } from "src/PenTypes"; +import { ExtendedFillStyle, PenType } from "src/PenTypes"; +import { getExcalidrawViews } from "src/utils/ObsidianUtils"; import { PENS } from "src/utils/Pens"; -import { fragWithHTML, getExportPadding, getExportTheme, getPNGScale, getWithBackground } from "src/utils/Utils"; +import { fragWithHTML } from "src/utils/Utils"; import { __values } from "tslib"; const EASINGFUNCTIONS: Record = { @@ -65,9 +66,7 @@ export class PenSettingsModal extends Modal { async onClose() { if(this.dirty) { - app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) v.view.updatePinnedCustomPens() - }) + getExcalidrawViews(this.app).forEach(excalidrawView=>excalidrawView.updatePinnedCustomPens()); this.plugin.saveSettings(); const pen = this.plugin.settings.customPens[this.pen] const api = this.view.excalidrawAPI; diff --git a/src/index.ts b/src/index.ts index acd3f56..38c6ae5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import "obsidian"; //export ExcalidrawAutomate from "./ExcalidrawAutomate"; //export {ExcalidrawAutomate} from "./ExcaildrawAutomate"; export type { ExcalidrawBindableElement, ExcalidrawElement, FileId, FillStyle, StrokeRoundness, StrokeStyle } from "@zsviczian/excalidraw/types/excalidraw/element/types"; -export type { Point } from "@zsviczian/excalidraw/types/excalidraw/types"; +export type { Point } from "src/types/types"; export const getEA = (view?:any): any => { try { return window.ExcalidrawAutomate.getAPI(view); diff --git a/src/main.ts b/src/main.ts index f3a2f96..970fdb1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -101,7 +101,7 @@ import { versionUpdateCheckTimer, getFontMetrics, } from "./utils/Utils"; -import { editorInsertText, extractSVGPNGFileName, foldExcalidrawSection, getActivePDFPageNumberFromPDFView, getAttachmentsFolderAndFilePath, getNewOrAdjacentLeaf, getParentOfClass, isObsidianThemeDark, mergeMarkdownFiles, openLeaf, setExcalidrawView } from "./utils/ObsidianUtils"; +import { editorInsertText, extractSVGPNGFileName, foldExcalidrawSection, getActivePDFPageNumberFromPDFView, getAttachmentsFolderAndFilePath, getExcalidrawViews, getNewOrAdjacentLeaf, getParentOfClass, isObsidianThemeDark, mergeMarkdownFiles, openLeaf, setExcalidrawView } from "./utils/ObsidianUtils"; import { ExcalidrawElement, ExcalidrawEmbeddableElement, ExcalidrawImageElement, ExcalidrawTextElement, FileId } from "@zsviczian/excalidraw/types/excalidraw/element/types"; import { ScriptEngine } from "./Scripts"; import { @@ -758,9 +758,8 @@ export default class ExcalidrawPlugin extends Plugin { setTimeout(()=>{ //run async to avoid blocking the UI const theme = isObsidianThemeDark() ? "dark" : "light"; - const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - leaves.forEach((leaf: WorkspaceLeaf) => { - const excalidrawView = leaf.view as ExcalidrawView; + const excalidrawViews = getExcalidrawViews(this.app); + excalidrawViews.forEach(excalidrawView => { if (excalidrawView.file && excalidrawView.excalidrawAPI) { excalidrawView.setTheme(theme); } @@ -1495,7 +1494,6 @@ export default class ExcalidrawPlugin extends Plugin { this.addCommand({ id: "toggle-lock", - hotkeys: [{ modifiers: ["Ctrl" || "Meta", "Shift"], key: "e" }], name: t("TOGGLE_LOCK"), checkCallback: (checking: boolean) => { if (checking) { @@ -1585,7 +1583,7 @@ export default class ExcalidrawPlugin extends Plugin { this.addCommand({ id: "insert-link", - hotkeys: [{ modifiers: ["Ctrl" || "Meta", "Shift"], key: "k" }], + hotkeys: [{ modifiers: ["Mod", "Shift"], key: "k" }], name: t("INSERT_LINK"), checkCallback: (checking: boolean) => { if (checking) { @@ -1618,7 +1616,6 @@ export default class ExcalidrawPlugin extends Plugin { this.addCommand({ id: "insert-link-to-element", - hotkeys: [{ modifiers: ["Ctrl" || "Meta", "Shift"], key: "k" }], name: t("INSERT_LINK_TO_ELEMENT_NORMAL"), checkCallback: (checking: boolean) => { if (checking) { @@ -2951,9 +2948,8 @@ export default class ExcalidrawPlugin extends Plugin { const modifyEventHandler = async (file: TFile) => { (process.env.NODE_ENV === 'development') && DEBUGGING && debug(modifyEventHandler,`ExcalidrawPlugin.modifyEventHandler`, file); - const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - leaves.forEach(async (leaf: WorkspaceLeaf) => { - const excalidrawView = leaf.view as ExcalidrawView; + const excalidrawViews = getExcalidrawViews(this.app); + excalidrawViews.forEach(async (excalidrawView) => { if(excalidrawView.semaphores?.viewunload) { return; } @@ -3013,10 +3009,10 @@ export default class ExcalidrawPlugin extends Plugin { } //close excalidraw view where this file is open - const leaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - for (let i = 0; i < leaves.length; i++) { - if ((leaves[i].view as ExcalidrawView).file.path == file.path) { - await leaves[i].setViewState({ + const excalidrawViews = getExcalidrawViews(this.app); + for (const excalidrawView of excalidrawViews) { + if (excalidrawView.file.path === file.path) { + await excalidrawView.leaf.setViewState({ type: VIEW_TYPE_EXCALIDRAW, state: { file: null }, }); @@ -3212,8 +3208,8 @@ export default class ExcalidrawPlugin extends Plugin { } onunload() { - const excalidrawLeaves = this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - excalidrawLeaves.forEach((leaf) => { + const excalidrawViews = getExcalidrawViews(this.app); + excalidrawViews.forEach(({leaf}) => { this.setMarkdownView(leaf); }); diff --git a/src/menu/ObsidianMenu.tsx b/src/menu/ObsidianMenu.tsx index 3e28abc..d417113 100644 --- a/src/menu/ObsidianMenu.tsx +++ b/src/menu/ObsidianMenu.tsx @@ -2,7 +2,7 @@ import { AppState, ExcalidrawImperativeAPI } from "@zsviczian/excalidraw/types/e import clsx from "clsx"; import { TFile } from "obsidian"; import * as React from "react"; -import { DEVICE, VIEW_TYPE_EXCALIDRAW } from "src/constants/constants"; +import { DEVICE } from "src/constants/constants"; import { PenSettingsModal } from "src/dialogs/PenSettingsModal"; import ExcalidrawView from "src/ExcalidrawView"; import { PenStyle } from "src/PenTypes"; @@ -11,8 +11,7 @@ import ExcalidrawPlugin from "../main"; import { ICONS, penIcon, stringToSVG } from "./ActionIcons"; import { UniversalInsertFileModal } from "src/dialogs/UniversalInsertFileModal"; import { t } from "src/lang/helpers"; - -declare const PLUGIN_VERSION:string; +import { getExcalidrawViews } from "src/utils/ObsidianUtils"; export function setPen (pen: PenStyle, api: any) { const st = api.getAppState(); @@ -134,10 +133,8 @@ export class ObsidianMenu { this.view.excalidrawAPI?.setToast({message:`Pin removed: ${name}`, duration: 3000, closable: true}); } await this.plugin.saveSettings(); - this.plugin.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) v.view.updatePinnedScripts() - }) - })() + getExcalidrawViews(this.plugin.app).forEach(excalidrawView=>excalidrawView.updatePinnedScripts()); + })() }, 1500 ) diff --git a/src/menu/ToolsPanel.tsx b/src/menu/ToolsPanel.tsx index 456f099..dc79498 100644 --- a/src/menu/ToolsPanel.tsx +++ b/src/menu/ToolsPanel.tsx @@ -3,7 +3,7 @@ import { Notice, TFile } from "obsidian"; import * as React from "react"; import { ActionButton } from "./ActionButton"; import { ICONS, saveIcon, stringToSVG } from "./ActionIcons"; -import { DEVICE, SCRIPT_INSTALL_FOLDER, VIEW_TYPE_EXCALIDRAW } from "../constants/constants"; +import { DEVICE, SCRIPT_INSTALL_FOLDER } from "../constants/constants"; import { insertLaTeXToView, search } from "../ExcalidrawAutomate"; import ExcalidrawView, { TextMode } from "../ExcalidrawView"; import { t } from "../lang/helpers"; @@ -18,10 +18,9 @@ import { openExternalLink } from "src/utils/ExcalidrawViewUtils"; import { UniversalInsertFileModal } from "src/dialogs/UniversalInsertFileModal"; import { DEBUGGING, debug } from "src/utils/DebugHelper"; import { REM_VALUE } from "src/utils/StylesManager"; +import { getExcalidrawViews } from "src/utils/ObsidianUtils"; declare const PLUGIN_VERSION:string; -const dark = ' REM_VALUE * 14.2; +const TOOLS_PANEL_WIDTH = () => REM_VALUE * 14.4; export class ToolsPanel extends React.Component { pos1: number = 0; @@ -367,11 +366,11 @@ export class ToolsPanel extends React.Component { async actionRunScript(key: string) { const view = this.view; const plugin = view.plugin; - const f = app.vault.getAbstractFileByPath(key); + const f = plugin.app.vault.getAbstractFileByPath(key); if (f && f instanceof TFile) { plugin.scriptEngine.executeScript( view, - await app.vault.read(f), + await plugin.app.vault.read(f), plugin.scriptEngine.getScriptName(f), f ); @@ -392,9 +391,7 @@ export class ToolsPanel extends React.Component { api?.setToast({message:`Pinned: ${scriptName}`, duration: 3000, closable: true}) } await plugin.saveSettings(); - plugin.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) v.view.updatePinnedScripts() - }) + getExcalidrawViews(plugin.app).forEach(excalidrawView=>excalidrawView.updatePinnedScripts()); } private islandOnClick(event: React.MouseEvent) { @@ -454,7 +451,7 @@ export class ToolsPanel extends React.Component { style={{ top: `${this.state.top}px`, left: `${this.state.left}px`, - width: `13.75rem`, + width: `14.4rem`, display: this.state.visible && !this.state.excalidrawViewMode ? "block" @@ -493,7 +490,7 @@ export class ToolsPanel extends React.Component { maxHeight: "350px", width: "initial", //@ts-ignore - "--padding": 2, + "--padding": "0.125rem", display: this.state.minimized ? "none" : "block", }} > diff --git a/src/settings.ts b/src/settings.ts index b6cab76..d5cad92 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -10,8 +10,7 @@ import { TextComponent, TFile, } from "obsidian"; -import { GITHUB_RELEASES, VIEW_TYPE_EXCALIDRAW } from "./constants/constants"; -import ExcalidrawView from "./ExcalidrawView"; +import { GITHUB_RELEASES } from "./constants/constants"; import { t } from "./lang/helpers"; import type ExcalidrawPlugin from "./main"; import { PenStyle } from "./PenTypes"; @@ -41,6 +40,7 @@ import { setDebugging } from "./utils/DebugHelper"; import { Rank } from "./menu/ActionIcons"; import { TAG_AUTOEXPORT, TAG_MDREADINGMODE, TAG_PDFEXPORT } from "src/constants/constSettingsTags"; import { HotkeyEditor } from "./dialogs/HotkeyEditor"; +import { getExcalidrawViews } from "./utils/ObsidianUtils"; export interface ExcalidrawSettings { folder: string; @@ -515,31 +515,25 @@ export class ExcalidrawSettingTab extends PluginSettingTab { } this.plugin.saveSettings(); if (this.requestUpdatePinnedPens) { - this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) v.view.updatePinnedCustomPens() - }) + getExcalidrawViews(this.app).forEach(excalidrawView => + excalidrawView.updatePinnedCustomPens() + ) } if (this.requestUpdateDynamicStyling) { - this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) { - setDynamicStyle(this.plugin.ea,v.view,v.view.previousBackgroundColor,this.plugin.settings.dynamicStyling); - } - - }) + getExcalidrawViews(this.app).forEach(excalidrawView => + setDynamicStyle(this.plugin.ea,excalidrawView,excalidrawView.previousBackgroundColor,this.plugin.settings.dynamicStyling) + ) } this.hotkeyEditor.unload(); if (this.hotkeyEditor.isDirty) { this.plugin.registerHotkeyOverrides(); } if (this.requestReloadDrawings) { - const exs = - this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - for (const v of exs) { - if (v.view instanceof ExcalidrawView) { - await v.view.save(false); - //debug({where:"ExcalidrawSettings.hide",file:v.view.file.name,before:"reload(true)"}) - await v.view.reload(true); - } + const excalidrawViews = getExcalidrawViews(this.app); + for (const excalidrawView of excalidrawViews) { + await excalidrawView.save(false); + //debug({where:"ExcalidrawSettings.hide",file:v.view.file.name,before:"reload(true)"}) + await excalidrawView.reload(true); } this.requestEmbedUpdate = true; } @@ -1247,9 +1241,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.allowPinchZoom) .onChange(async (value) => { this.plugin.settings.allowPinchZoom = value; - app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) v.view.updatePinchZoom() - }) + getExcalidrawViews(this.app).forEach(excalidrawView=>excalidrawView.updatePinchZoom()) this.applySettingsUpdate(); }), ); @@ -1263,9 +1255,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.allowWheelZoom) .onChange(async (value) => { this.plugin.settings.allowWheelZoom = value; - app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).forEach(v=> { - if (v.view instanceof ExcalidrawView) v.view.updateWheelZoom() - }) + getExcalidrawViews(this.app).forEach(excalidrawView=>excalidrawView.updateWheelZoom()); this.applySettingsUpdate(); }), ); @@ -1326,13 +1316,7 @@ export class ExcalidrawSettingTab extends PluginSettingTab { }); const updateGridColor = () => { - const exs = - this.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW); - for (const v of exs) { - if (v.view instanceof ExcalidrawView) { - v.view.updateGridColor(); - } - } + getExcalidrawViews(this.app).forEach(excalidrawView=>excalidrawView.updateGridColor()); }; // Dynamic color toggle diff --git a/src/types/types.d.ts b/src/types/types.d.ts index 74a75c0..b1ce820 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -31,6 +31,8 @@ export type DeviceType = { isAndroid: boolean, }; +export type Point = [number, number]; + declare global { interface Window { ExcalidrawAutomate: ExcalidrawAutomate; diff --git a/src/utils/CarveOut.ts b/src/utils/CarveOut.ts index d0d38e8..05a6552 100644 --- a/src/utils/CarveOut.ts +++ b/src/utils/CarveOut.ts @@ -4,6 +4,7 @@ import { getEA } from "src"; import { ExcalidrawAutomate } from "src/ExcalidrawAutomate"; import { getCropFileNameAndFolder, getListOfTemplateFiles, splitFolderAndFilename } from "./FileUtils"; import { Notice, TFile } from "obsidian"; +import { Radians } from "@zsviczian/excalidraw/types/math"; export const CROPPED_PREFIX = "cropped_"; export const ANNOTATED_PREFIX = "annotated_"; @@ -30,7 +31,7 @@ export const carveOutImage = async (sourceEA: ExcalidrawAutomate, viewImageEl: E const scale = newImage.scale; const angle = newImage.angle; newImage.scale = [1,1]; - newImage.angle = 0; + newImage.angle = 0 as Radians; const ef = sourceEA.targetView.excalidrawData.getFile(viewImageEl.fileId); let imageLink = ""; diff --git a/src/utils/ObsidianUtils.ts b/src/utils/ObsidianUtils.ts index c5e4b00..7a070c3 100644 --- a/src/utils/ObsidianUtils.ts +++ b/src/utils/ObsidianUtils.ts @@ -9,8 +9,9 @@ import ExcalidrawPlugin from "../main"; import { checkAndCreateFolder, splitFolderAndFilename } from "./FileUtils"; import { linkClickModifierType, ModifierKeys } from "./ModifierkeyHelper"; import { REG_BLOCK_REF_CLEAN, REG_SECTION_REF_CLEAN, VIEW_TYPE_EXCALIDRAW } from "src/constants/constants"; -import yaml, { Mark } from "js-yaml"; +import yaml from "js-yaml"; import { debug, DEBUGGING } from "./DebugHelper"; +import ExcalidrawView from "src/ExcalidrawView"; export const getParentOfClass = (element: Element, cssClass: string):HTMLElement | null => { let parent = element.parentElement; @@ -24,6 +25,11 @@ export const getParentOfClass = (element: Element, cssClass: string):HTMLElement return parent?.classList?.contains(cssClass) ? parent : null; }; +export function getExcalidrawViews(app: App): ExcalidrawView[] { + const leaves = app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW).filter(l=>l instanceof ExcalidrawView); + return leaves.map(l=>l.view as ExcalidrawView); +} + export const getLeaf = ( plugin: ExcalidrawPlugin, origo: WorkspaceLeaf,