UNPKG

@atlaskit/adf-schema

Version:

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

68 lines (63 loc) 1.94 kB
import { nestedExpand as nestedExpandFactory } from '../../next-schema/generated/nodeTypes'; import { uuid } from '../../utils/uuid'; /** * @name nestedExpand_content * @minItems 1 * @allowUnsupportedBlock true */ /** * @name nestedExpand_node */ /** * @name nestedExpand_with_no_marks_node */ function getExpandAttrs(domNode, generateLocalId) { const dom = domNode; return { title: dom.getAttribute('data-title'), __expanded: true, localId: generateLocalId ? uuid.generate() : undefined }; } const nestedExpandFactoryOptions = { parseDOM: [{ context: 'nestedExpand//', tag: '[data-node-type="nestedExpand"]', getAttrs: domNode => getExpandAttrs(domNode, false) }, { tag: '[data-node-type="nestedExpand"] button', ignore: true }, { tag: '[data-node-type="expand"] button', ignore: true }, { tag: 'div[data-node-type="nestedExpand"]', getAttrs: domNode => getExpandAttrs(domNode, false) }], toDOM(node) { var _node$attrs; const attrs = { 'data-node-type': 'nestedExpand', 'data-title': node.attrs.title, 'data-expanded': node.attrs.__expanded, 'data-local-id': (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId) || undefined }; return ['div', attrs, 0]; } }; /** * @name nestedExpand * @description an expand that can be nested (eg. inside table, layout). */ export const nestedExpand = nestedExpandFactory(nestedExpandFactoryOptions); export const nestedExpandWithLocalId = nestedExpandFactory({ ...nestedExpandFactoryOptions, parseDOM: [...nestedExpandFactoryOptions.parseDOM, { context: 'nestedExpand//', tag: '[data-node-type="nestedExpand"]', getAttrs: domNode => getExpandAttrs(domNode, true) }, { tag: '[data-node-type="nestedExpand"]', getAttrs: domNode => getExpandAttrs(domNode, true) }] });