@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
75 lines (72 loc) • 1.73 kB
JavaScript
/**
* @name expand_node
*/
/**
* @name expand_with_no_mark_node
*/
/**
* @name expand_with_breakout_mark_node
*/
function getExpandAttrs(domNode) {
var dom = domNode;
return {
title: dom.getAttribute('data-title'),
__expanded: true
};
}
export var expand = {
inline: false,
group: 'block',
marks: 'dataConsumer fragment unsupportedMark unsupportedNodeAttribute',
content: '(paragraph | panel | blockquote | orderedList | bulletList | rule | heading | codeBlock | mediaGroup | mediaSingle | decisionList | taskList | table | blockCard | embedCard | extension | unsupportedBlock)+',
isolating: true,
selectable: true,
attrs: {
title: {
default: ''
},
__expanded: {
default: true
}
},
parseDOM: [{
context: 'table//',
tag: 'div[data-node-type="expand"]',
getAttrs: getExpandAttrs
}, {
context: 'expand//',
tag: '[data-node-type="expand"]',
skip: true
}, {
context: 'nestedExpand//',
tag: '[data-node-type="expand"]',
skip: true
}, {
tag: '[data-node-type="nestedExpand"] button',
ignore: true
}, {
tag: '[data-node-type="expand"] button',
ignore: true
}, {
tag: 'div[data-node-type="expand"]',
getAttrs: getExpandAttrs
}],
toDOM: function toDOM(node) {
var attrs = {
'data-node-type': 'expand',
'data-title': node.attrs.title,
'data-expanded': node.attrs.__expanded
};
return ['div', attrs, 0];
}
};
export var toJSON = function toJSON(node) {
return {
attrs: Object.keys(node.attrs).filter(function (key) {
return !key.startsWith('__');
}).reduce(function (obj, key) {
obj[key] = node.attrs[key];
return obj;
}, {})
};
};