UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

71 lines (68 loc) 1.65 kB
/** * @name expand_node */ /** * @name expand_with_no_mark_node */ /** * @name expand_with_breakout_mark_node */ function getExpandAttrs(domNode) { const dom = domNode; return { title: dom.getAttribute('data-title'), __expanded: true }; } export const 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(node) { const attrs = { 'data-node-type': 'expand', 'data-title': node.attrs.title, 'data-expanded': node.attrs.__expanded }; return ['div', attrs, 0]; } }; export const toJSON = node => ({ attrs: Object.keys(node.attrs).filter(key => !key.startsWith('__')).reduce((obj, key) => { obj[key] = node.attrs[key]; return obj; }, {}) });