xref: /plugin/diagrams/script/prosemirror.js (revision 40d39aa2362c2e08a4d635ecb65d63385f1c5c63)
1jQuery(document).on('PROSEMIRROR_API_INITIALIZED', () => {
2    window.Prosemirror.pluginSchemas.push((nodes, marks) => {
3        nodes = nodes.addToEnd('diagrams', {
4            inline: true,
5            attrs: {
6                src: {},
7                id: {},
8                title: {default: null},
9                width: {default: null},
10                height: {default: null},
11                align: {default: ''}
12            },
13            group: "inline",
14            draggable: true,
15            toDOM: function toDOM(node) {
16                const ref = node.attrs;
17                const src = ref.src;
18                const id = ref.id;
19                const width = ref.width;
20                const height = ref.height;
21                const title = ref.title;
22                let alignclass = ref.align;
23
24                if (alignclass.length != 0) {
25                    alignclass = ` media${alignclass}`;
26                }
27
28                return [
29                    'object',
30                    {
31                        type: 'image/svg+xml',
32                        class: 'media diagrams-svg' + alignclass,
33                        title: title,
34                        data: src,
35                        'data-id': id,
36                        width: width,
37                        height: height,
38                    }
39                ]
40            }
41        });
42        return {nodes, marks};
43    });
44});
45