Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function normalize( nodes ) {
// Separate condition because string is iterable.
if ( typeof nodes == 'string' ) {
return [ new Text( nodes ) ];
}
if ( !isIterable( nodes ) ) {
nodes = [ nodes ];
}
// Array.from to enable .map() on non-arrays.
return Array.from( nodes )
.map( node => {
if ( typeof node == 'string' ) {
return new Text( node );
}
if ( node instanceof TextProxy ) {
return new Text( node.data, node.getAttributes() );
}
return node;
} );
function normalize( nodes ) {
// Separate condition because string is iterable.
if ( typeof nodes == 'string' ) {
return [ new Text( nodes ) ];
}
if ( !isIterable( nodes ) ) {
nodes = [ nodes ];
}
// Array.from to enable .map() on non-arrays.
return Array.from( nodes )
.map( node => {
if ( typeof node == 'string' ) {
return new Text( node );
}
if ( node instanceof TextProxy ) {
return new Text( node.data );
}
return node;
} );
function normalize( nodes ) {
// Separate condition because string is iterable.
if ( typeof nodes == 'string' ) {
return [ new Text( nodes ) ];
}
if ( !isIterable( nodes ) ) {
nodes = [ nodes ];
}
// Array.from to enable .map() on non-arrays.
return Array.from( nodes )
.map( node => {
if ( typeof node == 'string' ) {
return new Text( node );
}
if ( node instanceof TextProxy ) {
return new Text( node.data, node.getAttributes() );
}
return node;
} );
function normalize( nodes ) {
// Separate condition because string is iterable.
if ( typeof nodes == 'string' ) {
return [ new Text( nodes ) ];
}
if ( !isIterable( nodes ) ) {
nodes = [ nodes ];
}
// Array.from to enable .map() on non-arrays.
return Array.from( nodes )
.map( node => {
return typeof node == 'string' ? new Text( node ) : node;
} );
}
range = new Range( Position._createAt( selectable, placeOrOffset ) );
} else {
/**
* selection.setTo requires the second parameter when the first parameter is a node.
*
* @error model-selection-setTo-required-second-parameter
*/
throw new CKEditorError(
'model-selection-setTo-required-second-parameter: ' +
'selection.setTo requires the second parameter when the first parameter is a node.',
[ this, selectable ]
);
}
this._setRanges( [ range ], backward );
} else if ( isIterable( selectable ) ) {
// We assume that the selectable is an iterable of ranges.
this._setRanges( selectable, placeOrOffset && !!placeOrOffset.backward );
} else {
/**
* Cannot set the selection to the given place.
*
* Invalid parameters were specified when setting the selection. Common issues:
*
* * A {@link module:engine/model/textproxy~TextProxy} instance was passed instead of
* a real {@link module:engine/model/text~Text}.
* * View nodes were passed instead of model nodes.
* * `null`/`undefined` was passed.
*
* @error model-selection-setTo-not-selectable
*/
throw new CKEditorError(
insert( position, nodes ) {
nodes = isIterable( nodes ) ? [ ...nodes ] : [ nodes ];
// Check if nodes to insert are instances of AttributeElements, ContainerElements, EmptyElements, UIElements or Text.
validateNodesToInsert( nodes, this.document );
const container = getParentContainer( position );
if ( !container ) {
/**
* Position's parent container cannot be found.
*
* @error view-writer-invalid-position-container
*/
throw new CKEditorError( 'view-writer-invalid-position-container', this.document );
}
const insertionPosition = this._breakAttributes( position, true );
insert( position, nodes ) {
nodes = isIterable( nodes ) ? [ ...nodes ] : [ nodes ];
// Check if nodes to insert are instances of AttributeElements, ContainerElements, EmptyElements, UIElements or Text.
validateNodesToInsert( nodes, this.document );
const container = getParentContainer( position );
if ( !container ) {
/**
* Position's parent container cannot be found.
*
* @error view-writer-invalid-position-container
*/
throw new CKEditorError( 'view-writer-invalid-position-container', this.document );
}
const insertionPosition = this._breakAttributes( position, true );