mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Fix #304
This commit is contained in:
parent
8344490906
commit
8fbf999df4
2 changed files with 17 additions and 22 deletions
|
|
@ -1,19 +1,29 @@
|
|||
import type { WorkspaceLeaf, App } from 'obsidian';
|
||||
import type { WorkspaceLeaf, App, TFile } from 'obsidian';
|
||||
|
||||
interface ExcalidrawPlugin {
|
||||
setExcalidrawView(leaf: WorkspaceLeaf): void;
|
||||
openDrawing(file: TFile): void;
|
||||
getBlankDrawing(): Promise<string>;
|
||||
}
|
||||
|
||||
export async function openExcalidrawView(
|
||||
app: App,
|
||||
leaf: WorkspaceLeaf,
|
||||
file: TFile,
|
||||
): Promise<void> {
|
||||
const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(app);
|
||||
if (excalidrawEnabled && excalidraw) {
|
||||
excalidraw.setExcalidrawView(leaf);
|
||||
excalidraw.openDrawing(file);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDefaultTemplate(app: App): Promise<string> {
|
||||
const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(app);
|
||||
if (excalidrawEnabled && excalidraw) {
|
||||
return excalidraw.getBlankDrawing();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export async function getExcalidrawPlugin(
|
||||
app: App,
|
||||
): Promise<{ excalidraw: ExcalidrawPlugin | null; excalidrawEnabled: boolean }> {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import {
|
|||
updateExcludedFolder,
|
||||
} from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from '../ExcludeFolders/ExcludeFolder';
|
||||
import { openExcalidrawView } from './excalidraw';
|
||||
import { getDefaultTemplate, openExcalidrawView } from './excalidraw';
|
||||
import { AskForExtensionModal } from 'src/modals/AskForExtension';
|
||||
import {
|
||||
addCSSClassToFileExplorerEl,
|
||||
|
|
@ -35,21 +35,6 @@ import {
|
|||
} from 'src/functions/utils';
|
||||
|
||||
|
||||
const defaultExcalidrawTemplate = `---
|
||||
|
||||
excalidraw-plugin: parsed
|
||||
tags: [excalidraw]
|
||||
|
||||
---
|
||||
==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==
|
||||
|
||||
|
||||
%%
|
||||
# Drawing
|
||||
\`\`\`json
|
||||
{'type":"excalidraw","version":2,"source":"https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.9.20","elements":[],"appState":{"gridSize":null,"viewBackgroundColor":"#ffffff'}}
|
||||
\`\`\`
|
||||
%%`;
|
||||
|
||||
export async function createFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
|
|
@ -121,7 +106,7 @@ export async function createFolderNote(
|
|||
}
|
||||
await leaf.openFile(folderNote);
|
||||
if (plugin.settings.folderNoteType === '.excalidraw' || extension === '.excalidraw') {
|
||||
openExcalidrawView(plugin.app, leaf);
|
||||
openExcalidrawView(plugin.app, folderNote);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +177,7 @@ async function handleCreateFolderNote(plugin: FolderNotesPlugin, folderNoteType:
|
|||
'==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==',
|
||||
)
|
||||
) {
|
||||
content = defaultExcalidrawTemplate;
|
||||
content = await getDefaultTemplate(plugin.app);
|
||||
}
|
||||
} else {
|
||||
plugin.app.vault.readBinary(templateFile).then(async (data) => {
|
||||
|
|
@ -208,7 +193,7 @@ async function handleCreateFolderNote(plugin: FolderNotesPlugin, folderNoteType:
|
|||
plugin.settings.folderNoteType === '.excalidraw' ||
|
||||
extension === '.excalidraw'
|
||||
) {
|
||||
content = defaultExcalidrawTemplate;
|
||||
content = await getDefaultTemplate(plugin.app);
|
||||
} else if (plugin.settings.folderNoteType === '.canvas') {
|
||||
content = '{}';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue