(no title)
spellcard199 | 4 years ago
var editorUi;
Draw.loadPlugin(app => editorUi = app)
var editor = editorUi.editor
var graph = editor.graph
... then you can automate changes to the diagram using mxGraph's api [1] on the `graph' variable from the console.Around this plugin mechanism I wrote some dirty hacks for personal use to make the editor behave more to my likings [2] (some features stopped working with recent versions of the desktop app), and an even dirtier Emacs mode for editing labels and having the js REPL available directly from Emacs when I need to run some code to fix my diagrams programmatically [3] (based on Indium [4] + the fact that electron apps can be launched with --remote-debugging-port=...). It's not pretty, but works enough for me, and it's only thanks to the customizability that diagrams.net allows.
[1] https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGr...
[2] https://gitlab.com/spellcard199/drawio-plugin-eight-droves-o...
davidjgraph|4 years ago
spellcard199|4 years ago
CornCobs|4 years ago
spellcard199|4 years ago
Since it may be of interest I'll add some notes.
You can get a console also in the desktop app if you launch it from a terminal adding --remote-debugging-port=..., then opening http://127.0.0.1:<port> from a chromium-based web browser.
A couple of useful functions that allow to listen to events are graph.model.addListener and graph.selectionModel.addListener. They are documented in the mxGraph api page.
You can make your functions persistent between sessions by putting your code in a javascript file, clicking from the desktop app on Extras > Plugins > Add > Select File... Then restart the app. In the web app "Select File..." is replaced by "Custom..." and the file should be some reacheable url. The javascript file can contain arbitrary javascript code, doesn't need to have a specific format.
Finally, to customize the ui actions, keybindings and menus without touching the various event listeners, this answer on stackexchange [1] from user holroy is what initially guided me in the right direction.
[1] https://webapps.stackexchange.com/a/82379