UNPKG

@atlaskit/adf-schema

Version:

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

74 lines (69 loc) 1.57 kB
/** * @name mediaSingle_node * @additionalProperties true */ /** * @additionalProperties true */ /** * @name mediaSingle_caption_node */ /** * @additionalProperties true */ /** * @name mediaSingle_full_node */ export const defaultAttrs = { width: { default: null }, // null makes small images to have original size by default layout: { default: 'center' } }; export const mediaSingle = { inline: false, group: 'block', selectable: true, atom: true, content: 'media|unsupportedBlock+|media unsupportedBlock+', attrs: defaultAttrs, marks: 'unsupportedMark unsupportedNodeAttribute border link', parseDOM: [{ tag: 'div[data-node-type="mediaSingle"]', getAttrs: dom => ({ layout: dom.getAttribute('data-layout') || 'center', width: Number(dom.getAttribute('data-width')) || null }) }], toDOM(node) { const { layout, width } = node.attrs; const attrs = { 'data-node-type': 'mediaSingle', 'data-layout': layout, 'data-width': '' }; if (width) { attrs['data-width'] = isFinite(width) && Math.floor(width) === width ? width : width.toFixed(2); } return ['div', attrs, 0]; } }; export const mediaSingleWithCaption = { ...mediaSingle, atom: false, content: 'media|unsupportedBlock+|media (caption|unsupportedBlock) unsupportedBlock*' }; export const toJSON = node => ({ attrs: Object.keys(node.attrs).reduce((obj, key) => { if (node.attrs[key] !== null) { obj[key] = node.attrs[key]; } return obj; }, {}) });