1 | function getExpandAttrs(domNode) {
|
2 | var dom = domNode;
|
3 | return {
|
4 | title: dom.getAttribute('data-title'),
|
5 | __expanded: true,
|
6 | };
|
7 | }
|
8 | export var expand = {
|
9 | inline: false,
|
10 | group: 'block',
|
11 | content: '(paragraph | panel | blockquote | orderedList | bulletList | rule | heading | codeBlock | mediaGroup | mediaSingle | decisionList | taskList | table | blockCard | extension | unsupportedBlock)+',
|
12 | isolating: true,
|
13 | selectable: true,
|
14 | attrs: {
|
15 | title: { default: '' },
|
16 | __expanded: { default: true },
|
17 | },
|
18 | parseDOM: [
|
19 | {
|
20 | context: 'table//',
|
21 | tag: 'div[data-node-type="expand"]',
|
22 | getAttrs: getExpandAttrs,
|
23 | },
|
24 | {
|
25 | context: 'expand//',
|
26 | tag: '[data-node-type="expand"]',
|
27 | skip: true,
|
28 | },
|
29 | {
|
30 | context: 'nestedExpand//',
|
31 | tag: '[data-node-type="expand"]',
|
32 | skip: true,
|
33 | },
|
34 | {
|
35 | tag: '[data-node-type="nestedExpand"] button',
|
36 | ignore: true,
|
37 | },
|
38 | {
|
39 | tag: '[data-node-type="expand"] button',
|
40 | ignore: true,
|
41 | },
|
42 | {
|
43 | tag: 'div[data-node-type="expand"]',
|
44 | getAttrs: getExpandAttrs,
|
45 | },
|
46 | ],
|
47 | toDOM: function (node) {
|
48 | var attrs = {
|
49 | 'data-node-type': 'expand',
|
50 | 'data-title': node.attrs.title,
|
51 | 'data-expanded': node.attrs.__expanded,
|
52 | };
|
53 | return ['div', attrs, 0];
|
54 | },
|
55 | };
|
56 | export var toJSON = function (node) { return ({
|
57 | attrs: Object.keys(node.attrs)
|
58 | .filter(function (key) { return !key.startsWith('__'); })
|
59 | .reduce(function (obj, key) {
|
60 | obj[key] = node.attrs[key];
|
61 | return obj;
|
62 | }, {}),
|
63 | }); };
|
64 |
|
\ | No newline at end of file |