Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
RT.insert(VALUE, VALUE, 10, 20);
//
// insertObject
//
RT.insertObject(VALUE, FORMAT);
//
// isCollapsed
//
RT.isCollapsed(VALUE);
//
// isEmpty
//
RT.isEmpty(VALUE);
//
// join
//
RT.join([VALUE, VALUE]);
RT.join([], VALUE);
RT.join([], 'foo');
RT.join([VALUE], 'foo');
//
// registerFormatType
//
RT.registerFormatType('foo', {
tagName: 'span',
className: 'foo',
title: 'Foo',
value: before,
multilineTag,
} ) ) );
}
if ( hasPastedBlocks ) {
blocks.push( ...pastedBlocks );
} else if ( onSplitMiddle ) {
blocks.push( onSplitMiddle() );
}
// If there's pasted blocks, append a block with the content after the
// caret. Otherwise, do append and empty block if there is no
// `onSplitMiddle` prop, but if there is and the content is empty, the
// middle block is enough to set focus in.
if ( hasPastedBlocks || ! onSplitMiddle || ! isEmpty( after ) ) {
blocks.push( onSplit( toHTMLString( {
value: after,
multilineTag,
} ) ) );
}
// If there are pasted blocks, set the selection to the last one.
// Otherwise, set the selection to the second block.
const indexToSelect = hasPastedBlocks ? blocks.length - 1 : 1;
onReplace( blocks, indexToSelect );
}, [ onReplace, onSplit, multilineTag, onSplitMiddle ] );
const splitValue = useCallback( ( record, pastedBlocks = [] ) => {
if ( ! onReplace || ! onSplit ) {
return;
}
const blocks = [];
const [ before, after ] = split( record );
const hasPastedBlocks = pastedBlocks.length > 0;
// Create a block with the content before the caret if there's no pasted
// blocks, or if there are pasted blocks and the value is not empty.
// We do not want a leading empty block on paste, but we do if split
// with e.g. the enter key.
if ( ! hasPastedBlocks || ! isEmpty( before ) ) {
blocks.push( onSplit( toHTMLString( {
value: before,
multilineTag,
} ) ) );
}
if ( hasPastedBlocks ) {
blocks.push( ...pastedBlocks );
} else if ( onSplitMiddle ) {
blocks.push( onSplitMiddle() );
}
// If there's pasted blocks, append a block with the content after the
// caret. Otherwise, do append and empty block if there is no
// `onSplitMiddle` prop, but if there is and the content is empty, the
// middle block is enough to set focus in.
activeFormats,
} ) => {
// Only process file if no HTML is present.
// Note: a pasted file may have the URL as plain text.
if ( files && files.length && ! html ) {
const content = pasteHandler( {
HTML: filePasteHandler( files ),
mode: 'BLOCKS',
tagName,
} );
// Allows us to ask for this information when we get a report.
// eslint-disable-next-line no-console
window.console.log( 'Received items:\n\n', files );
if ( onReplace && isEmpty( value ) ) {
onReplace( content );
} else {
splitValue( value, content );
}
return;
}
let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';
if (
__unstableEmbedURLOnPaste &&
isEmpty( value ) &&
isURL( plainText.trim() )
) {
mode = 'BLOCKS';
window.console.log( 'Received items:\n\n', files );
if ( onReplace && isEmpty( value ) ) {
onReplace( content );
} else {
splitValue( value, content );
}
return;
}
let mode = onReplace && onSplit ? 'AUTO' : 'INLINE';
if (
__unstableEmbedURLOnPaste &&
isEmpty( value ) &&
isURL( plainText.trim() )
) {
mode = 'BLOCKS';
}
const content = pasteHandler( {
HTML: html,
plainText,
mode,
tagName,
canUserUseUnfilteredHTML,
} );
if ( typeof content === 'string' ) {
let valueToInsert = create( { html: content } );