Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// 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
//
RT.isEmpty(VALUE);
//
// join
//
RT.join([VALUE, VALUE]);
RT.join([], VALUE);
// It does not matter what this is, as long as it is unique per page.
const id = uuid();
const format = {
type: name,
attributes: {
href: `#${ id }`,
id: `${ id }-anchor`,
'data-core-footnotes-id': id,
},
};
let newValue;
if ( isCollapsed( value ) ) {
const prevStart = value.start;
newValue = insertObject( value, format );
newValue.start = prevStart;
} else {
newValue = applyFormat( value, format );
}
return newValue;
};
const addMarker = ( value, data ) => {
const id = nanoid( 8 );
const item = { ...data, id };
const format = {
type: 'ol/attributions',
attributes: {
href: `#ref-${ id }`,
id: `anchor-${ id }`,
},
};
// Add attribution.
dispatch( 'openlab/attributions' ).add( item );
const startIndex = isCollapsed( value ) ? value.start : value.end;
const newValue = insertObject( value, format, startIndex );
return newValue;
};
onSelect={ ( { id, url, alt, width } ) => {
this.closeModal();
onChange( insertObject( value, {
type: name,
attributes: {
className: `wp-image-${ id }`,
style: `width: ${ Math.min( width, 150 ) }px;`,
url,
alt,
},
} ) );
} }
onClose={ this.closeModal }