Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
RT.getActiveFormat(VALUE, 'foo');
//
// getActiveObject
//
RT.getActiveObject(VALUE);
//
// getTextContent
//
RT.getTextContent(VALUE);
//
// insert
//
RT.insert(VALUE, VALUE);
RT.insert(VALUE, VALUE, 10);
RT.insert(VALUE, VALUE, 10, 20);
//
// insertObject
//
RT.insertObject(VALUE, FORMAT);
//
// isCollapsed
//
RT.isCollapsed(VALUE);
//
// isEmpty
//
if (formats.length > 0) {
for (const format of formats) {
format.attributes = format.attributes || {};
format.attributes = {
...format.attributes,
items: mergeItems(selectedItems, format.attributes.items),
};
}
onChange(value);
}
// Otherwise just insert a new citation format.
else {
const newValue = create({
html: CitationElement.create(selectedItems),
});
onChange(insert(value, newValue));
}
}
return parseCitations();
}
const { inputValue, opensInNewWindow, text } = this.state;
const url = prependHTTP( inputValue );
const linkText = text || inputValue;
const format = createLinkFormat( {
url,
opensInNewWindow,
text: linkText,
} );
if ( isCollapsed( value ) && ! isActive ) { // insert link
const toInsert = applyFormat( create( { text: linkText } ), format, 0, linkText.length );
const newAttributes = insert( value, toInsert );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else if ( text !== getTextContent( slice( value ) ) ) { // edit text in selected link
const toInsert = applyFormat( create( { text } ), format, 0, text.length );
const newAttributes = insert( value, toInsert, value.start, value.end );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else { // transform selected text into link
const newAttributes = applyFormat( value, format );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
}
if ( ! isValidHref( url ) ) {
speak( __( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' );
} else if ( isActive ) {
speak( __( 'Link edited.' ), 'assertive' );
} else {
speak( __( 'Link inserted' ), 'assertive' );
}
this.props.onClose();
}
submitLink() {
const { isActive, onChange, speak, value } = this.props;
const { inputValue, opensInNewWindow, text } = this.state;
const url = prependHTTP( inputValue );
const linkText = text || inputValue;
const format = createLinkFormat( {
url,
opensInNewWindow,
text: linkText,
} );
if ( isCollapsed( value ) && ! isActive ) { // insert link
const toInsert = applyFormat( create( { text: linkText } ), format, 0, linkText.length );
const newAttributes = insert( value, toInsert );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else if ( text !== getTextContent( slice( value ) ) ) { // edit text in selected link
const toInsert = applyFormat( create( { text } ), format, 0, text.length );
const newAttributes = insert( value, toInsert, value.start, value.end );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
} else { // transform selected text into link
const newAttributes = applyFormat( value, format );
onChange( { ...newAttributes, needsSelectionUpdate: true } );
}
if ( ! isValidHref( url ) ) {
speak( __( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' );
} else if ( isActive ) {
speak( __( 'Link edited.' ), 'assertive' );
} else {
speak( __( 'Link inserted' ), 'assertive' );
insertCompletion( replacement ) {
const { open, query } = this.state;
const { record, onChange } = this.props;
const end = record.start;
const start = end - open.triggerPrefix.length - query.length;
const toInsert = create( { html: renderToString( replacement ) } );
onChange( insert( record, toInsert, start, end ) );
}
onPaste( { value, onChange, plainText } ) {
const content = pasteHandler( {
plainText,
mode: 'INLINE',
tagName: 'p',
} );
if ( typeof content === 'string' ) {
const valueToInsert = create( { html: content } );
onChange( insert( value, valueToInsert ) );
}
}
onSubmit={note => {
setIsOpen(false);
const footnote = create({
html: FootnoteElement.create(note),
});
onChange(insert(value, footnote));
parseFootnotes();
}}
/>
submitLink( event ) {
const { isActive, value, onChange, speak } = this.props;
const { inputValue, opensInNewWindow } = this.state;
const url = prependHTTP( inputValue );
const selectedText = getTextContent( slice( value ) );
const format = createLinkFormat( {
url,
opensInNewWindow,
text: selectedText,
} );
event.preventDefault();
if ( isCollapsed( value ) && ! isActive ) {
const toInsert = applyFormat( create( { text: url } ), format, 0, url.length );
onChange( insert( value, toInsert ) );
} else {
onChange( applyFormat( value, format ) );
}
this.resetState();
if ( ! isValidHref( url ) ) {
speak( __( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' );
} else if ( isActive ) {
speak( __( 'Link edited.' ), 'assertive' );
} else {
speak( __( 'Link inserted.' ), 'assertive' );
}
}