UNPKG

@atlaskit/editor-plugin-paste

Version:

Paste plugin for @atlaskit/editor-core

40 lines 1.75 kB
import { timestampToString } from '@atlaskit/editor-common/utils'; /** * Returns a plain text serialization of a given slice. This is used for populating the plain text * section of the clipboard on copy. * The current implementation is bare bones - only inlineCards, blockCards and mentions are tested (they * previously were empty on plain text copy). * * By default (without this function passed to the editor), the editor uses * `slice.content.textBetween(0, slice.content.size, "\n\n")` * (see https://prosemirror.net/docs/ref/#view.EditorProps.clipboardTextSerializer) */ export function createClipboardTextSerializer(intl) { return slice => { const blockSeparator = '\n\n'; return slice.content.textBetween(0, slice.content.size, blockSeparator, leafNode => { var _leafNode$text; switch (leafNode.type.name) { case 'hardBreak': return '\n'; case 'text': return leafNode.text; case 'inlineCard': return leafNode.attrs.url; case 'blockCard': return leafNode.attrs.url; // Note: Due to relying on an async fetch of the Mention name by the Node's React component, // pasting a mention does not actually work for the in-product Mention implementation. // However, this is also true of the previous implementation. // Bug ticket: https://product-fabric.atlassian.net/browse/ED-23076 case 'mention': return leafNode.attrs.text; case 'date': return timestampToString(leafNode.attrs.timestamp, intl); default: // Unsupported node return (_leafNode$text = leafNode.text) !== null && _leafNode$text !== void 0 ? _leafNode$text : ''; } }); }; }