Socket
Socket
Sign inDemoInstall

@ckeditor/ckeditor5-utils

Package Overview
Dependencies
Maintainers
1
Versions
647
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-utils - npm Package Compare versions

Comparing version 20.0.0 to 21.0.0

10

package.json
{
"name": "@ckeditor/ckeditor5-utils",
"version": "20.0.0",
"version": "21.0.0",
"description": "Miscellaneous utils used by CKEditor 5.",

@@ -15,6 +15,6 @@ "keywords": [

"devDependencies": {
"@ckeditor/ckeditor5-build-classic": "^20.0.0",
"@ckeditor/ckeditor5-editor-classic": "^20.0.0",
"@ckeditor/ckeditor5-core": "^20.0.0",
"@ckeditor/ckeditor5-engine": "^20.0.0",
"@ckeditor/ckeditor5-build-classic": "^21.0.0",
"@ckeditor/ckeditor5-editor-classic": "^21.0.0",
"@ckeditor/ckeditor5-core": "^21.0.0",
"@ckeditor/ckeditor5-engine": "^21.0.0",
"assertion-error": "^1.1.0",

@@ -21,0 +21,0 @@ "js-beautify": "^1.11.0"

@@ -182,7 +182,20 @@ /**

* @fires add
* @fires change
*/
add( item, index ) {
const itemId = this._getItemIdBeforeAdding( item );
return this.addMany( [ item ], index );
}
// TODO: Use ES6 default function argument.
/**
* Adds multiple items into the collection.
*
* Any item not containing an id will get an automatically generated one.
*
* @chainable
* @param {Iterable.<Object>} item
* @param {Number} [index] The position of the insertion. Items will be appended if no `index` is specified.
* @fires add
* @fires change
*/
addMany( items, index ) {
if ( index === undefined ) {

@@ -199,8 +212,19 @@ index = this._items.length;

this._items.splice( index, 0, item );
for ( let offset = 0; offset < items.length; offset++ ) {
const item = items[ offset ];
const itemId = this._getItemIdBeforeAdding( item );
const currentItemIndex = index + offset;
this._itemMap.set( itemId, item );
this._items.splice( currentItemIndex, 0, item );
this._itemMap.set( itemId, item );
this.fire( 'add', item, index );
this.fire( 'add', item, currentItemIndex );
}
this.fire( 'change', {
added: items,
removed: [],
index
} );
return this;

@@ -276,49 +300,13 @@ }

* @fires remove
* @fires change
*/
remove( subject ) {
let index, id, item;
let itemDoesNotExist = false;
const idProperty = this._idProperty;
const [ item, index ] = this._remove( subject );
if ( typeof subject == 'string' ) {
id = subject;
item = this._itemMap.get( id );
itemDoesNotExist = !item;
this.fire( 'change', {
added: [],
removed: [ item ],
index
} );
if ( item ) {
index = this._items.indexOf( item );
}
} else if ( typeof subject == 'number' ) {
index = subject;
item = this._items[ index ];
itemDoesNotExist = !item;
if ( item ) {
id = item[ idProperty ];
}
} else {
item = subject;
id = item[ idProperty ];
index = this._items.indexOf( item );
itemDoesNotExist = ( index == -1 || !this._itemMap.get( id ) );
}
if ( itemDoesNotExist ) {
/**
* Item not found.
*
* @error collection-remove-404
*/
throw new CKEditorError( 'collection-remove-404: Item not found.', this );
}
this._items.splice( index, 1 );
this._itemMap.delete( id );
const externalItem = this._bindToInternalToExternalMap.get( item );
this._bindToInternalToExternalMap.delete( item );
this._bindToExternalToInternalMap.delete( externalItem );
this.fire( 'remove', item, index );
return item;

@@ -369,2 +357,5 @@ }

* {@link #bindTo}.
*
* @fires remove
* @fires change
*/

@@ -377,5 +368,13 @@ clear() {

const removedItems = Array.from( this._items );
while ( this.length ) {
this.remove( 0 );
this._remove( 0 );
}
this.fire( 'change', {
added: [],
removed: removedItems,
index: 0
} );
}

@@ -673,2 +672,61 @@

/**
* Core {@link #remove} method implementation shared in other functions.
*
* In contrast this method **does not** fire the {@link #event:change} event.
*
* @private
* @param {Object} subject The item to remove, its id or index in the collection.
* @returns {Array} Returns an array with the removed item and its index.
* @fires remove
*/
_remove( subject ) {
let index, id, item;
let itemDoesNotExist = false;
const idProperty = this._idProperty;
if ( typeof subject == 'string' ) {
id = subject;
item = this._itemMap.get( id );
itemDoesNotExist = !item;
if ( item ) {
index = this._items.indexOf( item );
}
} else if ( typeof subject == 'number' ) {
index = subject;
item = this._items[ index ];
itemDoesNotExist = !item;
if ( item ) {
id = item[ idProperty ];
}
} else {
item = subject;
id = item[ idProperty ];
index = this._items.indexOf( item );
itemDoesNotExist = ( index == -1 || !this._itemMap.get( id ) );
}
if ( itemDoesNotExist ) {
/**
* Item not found.
*
* @error collection-remove-404
*/
throw new CKEditorError( 'collection-remove-404: Item not found.', this );
}
this._items.splice( index, 1 );
this._itemMap.delete( id );
const externalItem = this._bindToInternalToExternalMap.get( item );
this._bindToInternalToExternalMap.delete( item );
this._bindToExternalToInternalMap.delete( externalItem );
this.fire( 'remove', item, index );
return [ item, index ];
}
/**
* Iterable interface.

@@ -690,2 +748,11 @@ *

/**
* Fired when the collection was changed due to adding or removing items.
*
* @event change
* @param {Iterable.<Object>} added A list of added items.
* @param {Iterable.<Object>} removed A list of removed items.
* @param {Number} index An index where the addition or removal occurred.
*/
/**
* Fired when an item is removed from the collection.

@@ -692,0 +759,0 @@ *

@@ -80,3 +80,3 @@ /**

* Parses keystroke and returns a keystroke code that will match the code returned by
* link {@link module:utils/keyboard.getCode} for a corresponding {@link module:utils/keyboard~KeystrokeInfo keystroke info}.
* link {@link module:utils/keyboard~getCode} for a corresponding {@link module:utils/keyboard~KeystrokeInfo keystroke info}.
*

@@ -83,0 +83,0 @@ * The keystroke can be passed in two formats:

@@ -14,3 +14,3 @@ /**

const version = '20.0.0';
const version = '21.0.0';

@@ -17,0 +17,0 @@ /* istanbul ignore next */

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc