UNPKG

@atlaskit/adf-schema

Version:

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

50 lines (47 loc) 1.41 kB
import { bodiedRuleStage0 as bodiedRuleFactory } from '../../next-schema/generated/nodeTypes'; import { uuid } from '../../utils/uuid'; /** * @name bodiedRule_node */ /** * @name bodiedRule_root_only_node */ const getAttrs = domNode => { // eslint-disable-next-line @atlaskit/editor/no-as-casting const dom = domNode; const weight = dom.getAttribute('data-weight'); return { alignment: dom.getAttribute('data-alignment') || undefined, color: dom.getAttribute('data-color') || undefined, localId: dom.getAttribute('data-local-id') || uuid.generate(), style: dom.getAttribute('data-style') || undefined, weight: weight === null || weight === '' ? undefined : Number(weight) }; }; export const bodiedRule = bodiedRuleFactory({ parseDOM: [{ tag: 'div[data-node-type="bodied-rule"]', getAttrs }], toDOM(node) { const { alignment, color, localId, style, weight } = node.attrs; return ['div', { 'data-node-type': 'bodied-rule', 'data-alignment': alignment || undefined, 'data-color': color || undefined, 'data-local-id': localId || undefined, 'data-style': style || undefined, 'data-weight': weight !== null && weight !== void 0 ? weight : undefined }, 0]; } }); export const bodiedRuleRootOnlyStage0 = { ...bodiedRule, marks: 'breakout unsupportedMark unsupportedNodeAttribute' };