xref: /plugin/diagrams/script/prosemirror.js (revision d5285d5997d36d52df94bd6170b284d5e077218a)
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            contenteditable: true,
7            selectable: true,
8            attrs: {
9                data: {},
10                id: {},
11                title: {default: null},
12                width: {default: null},
13                height: {default: null},
14                align: {default: ''}
15            },
16            group: "inline",
17            draggable: false,
18            toDOM: function toDOM(node) {
19                const ref = node.attrs;
20                const data = ref.data;
21                const id = ref.id;
22                const width = ref.width;
23                const height = ref.height;
24                const title = ref.title;
25                let alignclass = ref.align;
26
27                if (alignclass.length != 0) {
28                    alignclass = ` media${alignclass}`;
29                }
30
31                return [
32                    'object',
33                    {
34                        type: 'image/svg+xml',
35                        class: 'media diagrams-svg' + alignclass,
36                        title: title,
37                        data: data,
38                        'data-id': id,
39                        width: width,
40                        height: height,
41                    }
42                ]
43            }
44        });
45        return {nodes, marks};
46    });
47
48    // extend plugin menu
49    const AbstractMenuItemDispatcher = window.Prosemirror.classes.AbstractMenuItemDispatcher;
50    const MenuItem = window.Prosemirror.classes.MenuItem;
51    const KeyValueForm = window.Prosemirror.classes.KeyValueForm;
52    const AbstractNodeView = window.AbstractNodeView;
53
54    /* DOKUWIKI:include script/DiagramsForm.js */
55    /* DOKUWIKI:include script/DiagramsView.js */
56    /* DOKUWIKI:include script/DiagramsMenuItemDispatcher.js */
57
58
59    window.Prosemirror.pluginNodeViews.diagrams = function diagrams(node, outerview, getPos) {
60        return new DiagramsView(node, outerview, getPos);
61    };
62
63    window.Prosemirror.pluginMenuItemDispatchers.push(DiagramsMenuItemDispatcher);
64});
65