UNPKG

@atlaskit/adf-schema

Version:

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

47 lines (43 loc) 1.48 kB
import { uuid } from '../../utils/uuid'; import { status as statusFactory } from '../../next-schema/generated/nodeTypes'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; /** * @name status_node */ export const status = statusFactory({ parseDOM: [{ tag: 'span[data-node-type="status"]', getAttrs: domNode => { // eslint-disable-next-line @atlaskit/editor/no-as-casting const dom = domNode; // @ts-ignore TS1501: This regular expression flag is only available when targeting 'es6' or later. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const textContent = dom.textContent.replace(/\n/u, '').trim(); // Prefer data-text attribute over textContent // When NodeView DOM is copied, inner text content may not be preserved const text = expValEquals('platform_editor_copy_paste_issue_fix', 'isEnabled', true) ? dom.getAttribute('data-text') || textContent : textContent; return { text, color: dom.getAttribute('data-color'), localId: uuid.generate(), style: dom.getAttribute('data-style') }; } }], toDOM(node) { const { text, color, localId, style } = node.attrs; const attrs = { 'data-node-type': 'status', 'data-color': color, 'data-local-id': localId, 'data-style': style, contenteditable: 'false' }; return ['span', attrs, text]; } });