MarkMindCkm / obsidian-enhancing-mindmap

obsidian plugin editable mindmap,you can edit mindmap on markdown file
MIT License
575 stars 51 forks source link

[Feature suggestion] Drag and drop from folder explorer #92

Open goodhobak opened 2 years ago

goodhobak commented 2 years ago

Hi, MarkMindCkm. I really appreciate your awesome plug-in! This plugin is the one that I used almost every day to plan and execute my to-dos.

However, I'd love that there is a feature drag and drop-ing a md file from folder tree directly. I just modify some code blocks from your codes. It works well for me, but it is not clean code, because I'm new in obsidian plug-in api.

So, I think you could make this code better for everyone who want this feature.

Thanks a lot. yangho.

appDrop(evt: any) of mindmap.ts (line 755)

        if (evt.target instanceof HTMLElement) {
            if (evt.target.closest('.mm-node')) {
                evt.preventDefault();
                var dropNodeId = evt.target.closest('.mm-node').getAttribute('data-id');
                var dropNode = this.getNodeById(dropNodeId);

                if(app.dragManager.draggable != null && app.dragManager.draggable.file){

                    var d = {
                      id: uuid(),
                      text: "[[" + app.dragManager.draggable.title +"]]",
                      children: []
                    }
                    var _node = new Node(d, this);

                    this.containEl = document.createElement('div');
                    this.containEl.classList.add('mm-node');
                    this.containEl.setAttribute('contentEditable', 'true');
                    this.containEl.setAttribute('tabIndex', '-1');
                    this.containEl.setAttribute('data-id', d.id);
                    this.containEl.setAttribute('draggable', 'true');
                    this.contentEl = document.createElement('div');
                    this.contentEl.classList.add('mm-node-content');
                    this.containEl.appendChild(this.contentEl);
                    this.containEl.textContent = d.text;
                    this.addNode(_node, dropNode);

                    this.moveNode(_node, dropNode, this._dragType);

                    setTimeout(() => {
                      this.mindMapChange();
                      this.refresh();
                    }, 100);
                  }
                  else if (this._dragNode != undefined && !this._dragNode.isRoot) {
                    //console.log('move node.');
                    this.moveNode(this._dragNode, dropNode, this._dragType);
                  }
            }
        }
goodhobak commented 2 years ago

file : js file

https://user-images.githubusercontent.com/7983689/186110634-8db445bc-e36c-4322-af22-158622ea0443.mp4