1jQuery(document).on('PROSEMIRROR_API_INITIALIZED', () => {
2    // define diagrams schema
3    window.Prosemirror.pluginSchemas.push((nodes, marks) => {
4        nodes = nodes.addToEnd('diagrams', {
5            inline: true,
6            selectable: true,
7            attrs: {
8                url: {},
9                id: {},
10                type: {default: 'mediafile'},
11                title: {default: null},
12                width: {default: null},
13                height: {default: null},
14                align: {default: ''}
15            },
16            group: "inline",
17            draggable: true,
18
19            /**
20             * Render the node as HTML
21             *
22             * Maps node attributes to HTML attributes
23             *
24             * @param node
25             * @returns {[string,object]}  [tagname, attributes]
26             */
27            toDOM: function toDOM(node) {
28                let alignclass = node.attrs.align;
29                if (alignclass.length !== 0) {
30                    alignclass = ` media${alignclass}`;
31                }
32
33                return [
34                    'img',
35                    {
36                        class: 'media diagrams-svg' + alignclass,
37                        title: node.attrs.title,
38                        src: node.attrs.url,
39                        'data-id': node.attrs.id,
40                        'data-type': node.attrs.type,
41                        width: node.attrs.width,
42                        height: node.attrs.height,
43                    }
44                ]
45            }
46        });
47        return {nodes, marks};
48    });
49
50    // extend plugin menu
51    const AbstractMenuItemDispatcher = window.Prosemirror.classes.AbstractMenuItemDispatcher;
52    const MenuItem = window.Prosemirror.classes.MenuItem;
53    const KeyValueForm = window.Prosemirror.classes.KeyValueForm;
54    const AbstractNodeView = window.AbstractNodeView; // FIXME this should be moved to the prosemirror.classes namespace
55
56    /* DOKUWIKI:include script/DiagramsForm.js */
57    /* DOKUWIKI:include script/DiagramsView.js */
58    /* DOKUWIKI:include script/DiagramsMenuItemDispatcher.js */
59
60
61    window.Prosemirror.pluginNodeViews.diagrams = function diagrams(node, outerview, getPos) {
62        return new DiagramsView(node, outerview, getPos);
63    };
64
65    // noinspection JSBitwiseOperatorUsage
66    if (JSINFO.plugins.diagrams && (JSINFO.plugins.diagrams.mode & 1)) {
67        window.Prosemirror.pluginMenuItemDispatchers.push(DiagramsMenuItemDispatcherMediaFile);
68    }
69
70    // noinspection JSBitwiseOperatorUsage
71    if (JSINFO.plugins.diagrams && (JSINFO.plugins.diagrams.mode & 2)) {
72        window.Prosemirror.pluginMenuItemDispatchers.push(DiagramsMenuItemDispatcherEmbedded);
73    }
74});
75