1- import { Plugin , Notice , TFolder , debounce , WorkspaceLeaf , setIcon } from "obsidian" ;
2- import type { Canvas } from "./types/canvas-internal" ;
1+ import { Plugin , Notice , TFile , TFolder , debounce , WorkspaceLeaf , setIcon } from "obsidian" ;
2+ import type { Canvas , CreateNodeOptions } from "./types/canvas-internal" ;
33import { CanvasAPI } from "./canvas/canvas-api" ;
44import { NodeOperations } from "./mindmap/node-operations" ;
55import { LayoutEngine } from "./mindmap/layout-engine" ;
@@ -45,7 +45,7 @@ export default class CanvasMindMapPlugin extends Plugin {
4545 /** Original canvas methods for unwrapping on cleanup. */
4646 private origCanvasMethods : {
4747 requestSave ?: ( ) => void ;
48- createGroupNode ?: ( options : any ) => any ;
48+ createGroupNode ?: ( options : CreateNodeOptions & { label ?: string } ) => import ( "./types/canvas-internal" ) . CanvasNode ;
4949 } = { } ;
5050 /** Set to true on unload to prevent deferred callbacks from running. */
5151 private unloaded = false ;
@@ -170,16 +170,17 @@ export default class CanvasMindMapPlugin extends Plugin {
170170 // Command: Toggle TOC panel
171171 this . addCommand ( {
172172 id : "mindmap-toggle-toc" ,
173- name : "Toggle Table of Contents " ,
174- callback : async ( ) => {
173+ name : "Toggle table of contents " ,
174+ callback : ( ) => {
175175 const leaves = this . app . workspace . getLeavesOfType ( TOC_VIEW_TYPE ) ;
176176 if ( leaves . length > 0 ) {
177177 leaves [ 0 ] . detach ( ) ;
178178 } else {
179179 const leaf = this . app . workspace . getRightLeaf ( false ) ;
180180 if ( leaf ) {
181- await leaf . setViewState ( { type : TOC_VIEW_TYPE } ) ;
182- this . app . workspace . revealLeaf ( leaf ) ;
181+ void leaf . setViewState ( { type : TOC_VIEW_TYPE } ) . then ( ( ) => {
182+ this . app . workspace . revealLeaf ( leaf ) ;
183+ } ) ;
183184 }
184185 }
185186 } ,
@@ -192,7 +193,7 @@ export default class CanvasMindMapPlugin extends Plugin {
192193 if ( ! ( file instanceof TFolder ) ) return ;
193194
194195 menu . addItem ( ( item ) => {
195- item . setTitle ( "Import FreeMind (.mm) to Canvas " )
196+ item . setTitle ( "Import FreeMind (.mm) to canvas " )
196197 . setIcon ( "file-input" )
197198 . onClick ( ( ) => this . importFreeMindFile ( file . path ) ) ;
198199 } ) ;
@@ -202,7 +203,7 @@ export default class CanvasMindMapPlugin extends Plugin {
202203 // Import FreeMind: command palette
203204 this . addCommand ( {
204205 id : "mindmap-import-freemind" ,
205- name : "Import FreeMind (.mm) file to Canvas " ,
206+ name : "Import FreeMind (.mm) file to canvas " ,
206207 callback : ( ) => this . importFreeMindFile ( ) ,
207208 } ) ;
208209
@@ -369,7 +370,7 @@ export default class CanvasMindMapPlugin extends Plugin {
369370 origSave ( ) ;
370371 this . debouncedTocRefresh ( ) ;
371372 } ;
372- canvas . createGroupNode = ( options : any ) => {
373+ canvas . createGroupNode = ( options : CreateNodeOptions & { label ?: string } ) => {
373374 const group = origCreateGroup ( options ) ;
374375 this . updateGroupBounds ( canvas ) ;
375376 return group ;
@@ -642,59 +643,61 @@ export default class CanvasMindMapPlugin extends Plugin {
642643 * Import a FreeMind .mm file and create a .canvas file.
643644 * @param folderPath Optional target folder; defaults to vault root.
644645 */
645- private async importFreeMindFile ( folderPath ?: string ) : Promise < void > {
646+ private importFreeMindFile ( folderPath ?: string ) : void {
646647 // Open native file picker for .mm files
647648 const input = document . createElement ( "input" ) ;
648649 input . type = "file" ;
649650 input . accept = ".mm" ;
650- const onChange = async ( ) => {
651- input . removeEventListener ( "change" , onChange ) ;
651+ const handler = ( ) => {
652+ input . removeEventListener ( "change" , handler ) ;
652653 const file = input . files ?. [ 0 ] ;
653654 if ( ! file ) return ;
654655
655- const xml = await file . text ( ) ;
656- const canvasData = freemindToCanvas ( xml , {
657- nodeWidth : this . settings . defaultNodeWidth ,
658- nodeHeight : this . settings . defaultNodeHeight ,
659- maxNodeHeight : this . settings . maxNodeHeight ,
660- horizontalGap : this . settings . horizontalGap ,
661- verticalGap : this . settings . verticalGap ,
662- } ) ;
656+ void ( async ( ) => {
657+ const xml = await file . text ( ) ;
658+ const canvasData = freemindToCanvas ( xml , {
659+ nodeWidth : this . settings . defaultNodeWidth ,
660+ nodeHeight : this . settings . defaultNodeHeight ,
661+ maxNodeHeight : this . settings . maxNodeHeight ,
662+ horizontalGap : this . settings . horizontalGap ,
663+ verticalGap : this . settings . verticalGap ,
664+ } ) ;
663665
664- if ( ! canvasData ) {
665- new Notice (
666- "Failed to parse FreeMind file. Make sure it is a valid .mm file."
667- ) ;
668- return ;
669- }
666+ if ( ! canvasData ) {
667+ new Notice (
668+ "Failed to parse FreeMind file. Make sure it is a valid .mm file."
669+ ) ;
670+ return ;
671+ }
670672
671- const baseName = file . name . replace ( / \. m m $ / i, "" ) ;
672- const folder = folderPath ? folderPath + "/" : "" ;
673- let canvasPath = `${ folder } ${ baseName } .canvas` ;
673+ const baseName = file . name . replace ( / \. m m $ / i, "" ) ;
674+ const folder = folderPath ? folderPath + "/" : "" ;
675+ let canvasPath = `${ folder } ${ baseName } .canvas` ;
674676
675- // Avoid overwriting existing files
676- let counter = 1 ;
677- while ( this . app . vault . getAbstractFileByPath ( canvasPath ) ) {
678- canvasPath = `${ folder } ${ baseName } ${ counter } .canvas` ;
679- counter ++ ;
680- }
677+ // Avoid overwriting existing files
678+ let counter = 1 ;
679+ while ( this . app . vault . getAbstractFileByPath ( canvasPath ) ) {
680+ canvasPath = `${ folder } ${ baseName } ${ counter } .canvas` ;
681+ counter ++ ;
682+ }
681683
682- await this . app . vault . create (
683- canvasPath ,
684- JSON . stringify ( canvasData , null , "\t" )
685- ) ;
684+ await this . app . vault . create (
685+ canvasPath ,
686+ JSON . stringify ( canvasData , null , "\t" )
687+ ) ;
686688
687- // Open the new canvas
688- const created = this . app . vault . getAbstractFileByPath ( canvasPath ) ;
689- if ( created ) {
690- await this . app . workspace . getLeaf ( false ) . openFile ( created as any ) ;
691- }
689+ // Open the new canvas
690+ const created = this . app . vault . getAbstractFileByPath ( canvasPath ) ;
691+ if ( created instanceof TFile ) {
692+ await this . app . workspace . getLeaf ( false ) . openFile ( created ) ;
693+ }
692694
693- new Notice (
694- `Imported "${ file . name } " as "${ canvasPath } "`
695- ) ;
695+ new Notice (
696+ `Imported "${ file . name } " as "${ canvasPath } "`
697+ ) ;
698+ } ) ( ) ;
696699 } ;
697- input . addEventListener ( "change" , onChange ) ;
700+ input . addEventListener ( "change" , handler ) ;
698701 input . click ( ) ;
699702 }
700703
@@ -707,7 +710,7 @@ export default class CanvasMindMapPlugin extends Plugin {
707710 private toggleMindmapMode ( canvas : Canvas ) : void {
708711 const data = canvas . getData ( ) ;
709712 const newValue = ! this . isMindmapCanvas ( canvas ) ;
710- ( data as any ) . mindmap = newValue ;
713+ data . mindmap = newValue ;
711714 canvas . setData ( data ) ;
712715 canvas . requestSave ( ) ;
713716
0 commit comments