Socket
Socket
Sign inDemoInstall

@ckeditor/ckeditor5-utils

Package Overview
Dependencies
Maintainers
1
Versions
613
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 31.0.0 to 31.1.0

12

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

@@ -17,8 +17,6 @@ "keywords": [

"devDependencies": {
"@ckeditor/ckeditor5-build-classic": "^31.0.0",
"@ckeditor/ckeditor5-editor-classic": "^31.0.0",
"@ckeditor/ckeditor5-core": "^31.0.0",
"@ckeditor/ckeditor5-engine": "^31.0.0",
"assertion-error": "^1.1.0",
"js-beautify": "^1.11.0"
"@ckeditor/ckeditor5-build-classic": "^31.1.0",
"@ckeditor/ckeditor5-editor-classic": "^31.1.0",
"@ckeditor/ckeditor5-core": "^31.1.0",
"@ckeditor/ckeditor5-engine": "^31.1.0"
},

@@ -25,0 +23,0 @@ "engines": {

@@ -55,15 +55,17 @@ /**

*/
listenTo( emitter, ...rest ) {
// Check if emitter is an instance of DOM Node. If so, replace the argument with
// corresponding ProxyEmitter (or create one if not existing).
listenTo( emitter, event, callback, options = {} ) {
// Check if emitter is an instance of DOM Node. If so, use corresponding ProxyEmitter (or create one if not existing).
if ( isNode( emitter ) || isWindow( emitter ) ) {
const proxy = this._getProxyEmitter( emitter ) || new ProxyEmitter( emitter );
const proxyOptions = {
capture: !!options.useCapture,
passive: !!options.usePassive
};
proxy.attach( ...rest );
const proxyEmitter = this._getProxyEmitter( emitter, proxyOptions ) || new ProxyEmitter( emitter, proxyOptions );
emitter = proxy;
this.listenTo( proxyEmitter, event, callback, options );
} else {
// Execute parent class method with Emitter (or ProxyEmitter) instance.
EmitterMixin.listenTo.call( this, emitter, event, callback, options );
}
// Execute parent class method with Emitter (or ProxyEmitter) instance.
EmitterMixin.listenTo.call( this, emitter, ...rest );
},

@@ -87,31 +89,45 @@

stopListening( emitter, event, callback ) {
// Check if emitter is an instance of DOM Node. If so, replace the argument with corresponding ProxyEmitter.
// Check if the emitter is an instance of DOM Node. If so, forward the call to the corresponding ProxyEmitters.
if ( isNode( emitter ) || isWindow( emitter ) ) {
const proxy = this._getProxyEmitter( emitter );
const proxyEmitters = this._getAllProxyEmitters( emitter );
// Element has no listeners.
if ( !proxy ) {
return;
for ( const proxy of proxyEmitters ) {
this.stopListening( proxy, event, callback );
}
emitter = proxy;
} else {
// Execute parent class method with Emitter (or ProxyEmitter) instance.
EmitterMixin.stopListening.call( this, emitter, event, callback );
}
},
// Execute parent class method with Emitter (or ProxyEmitter) instance.
EmitterMixin.stopListening.call( this, emitter, event, callback );
if ( emitter instanceof ProxyEmitter ) {
emitter.detach( event );
}
/**
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host and given options.
*
* @private
* @param {Node} node DOM Node of the ProxyEmitter.
* @param {Object} [options] Additional options.
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
* and prevents blocking browser's main thread by this event handler.
* @returns {module:utils/dom/emittermixin~ProxyEmitter|null} ProxyEmitter instance bound to the DOM Node.
*/
_getProxyEmitter( node, options ) {
return _getEmitterListenedTo( this, getProxyEmitterId( node, options ) );
},
/**
* Retrieves ProxyEmitter instance for given DOM Node residing in this Host.
* Retrieves all the ProxyEmitter instances for given DOM Node residing in this Host.
*
* @private
* @param {Node} node DOM Node of the ProxyEmitter.
* @returns {module:utils/dom/emittermixin~ProxyEmitter} ProxyEmitter instance or null.
* @returns {Array.<module:utils/dom/emittermixin~ProxyEmitter>}
*/
_getProxyEmitter( node ) {
return _getEmitterListenedTo( this, getNodeUID( node ) );
_getAllProxyEmitters( node ) {
return [
{ capture: false, passive: false },
{ capture: false, passive: true },
{ capture: true, passive: false },
{ capture: true, passive: true }
].map( options => this._getProxyEmitter( node, options ) ).filter( proxy => !!proxy );
}

@@ -125,2 +141,4 @@ } );

* and any Host listening to them. It is backwards compatible with {@link module:utils/emittermixin~EmitterMixin#on}.
* There is a separate instance for each combination of modes (useCapture & usePassive). The mode is concatenated with
* UID stored in HTMLElement to give each instance unique identifier.
*

@@ -134,3 +152,3 @@ * listenTo( click, ... )

* | _listeningTo: { | +----------v-------------+ |
* | UID: { | | ProxyEmitter | |
* | UID+mode: { | | ProxyEmitter | |
* | emitter: ProxyEmitter, | +------------------------+ +------------v----------+

@@ -142,3 +160,3 @@ * | callbacks: { | | events: { | | Node (HTMLElement) |

* | } | | _domListeners: {}, | |
* | +------------------------+ | | _emitterId: UID | |
* | +------------------------+ | | _emitterId: UID+mode | |
* | | DomEmitterMixin | | +--------------^---------+ |

@@ -158,10 +176,17 @@ * | +------------------------+ | | | |

* @param {Node} node DOM Node that fires events.
* @returns {Object} ProxyEmitter instance bound to the DOM Node.
* @param {Object} [options] Additional options.
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
* and prevents blocking browser's main thread by this event handler.
*/
constructor( node ) {
constructor( node, options ) {
// Set emitter ID to match DOM Node "expando" property.
_setEmitterId( this, getNodeUID( node ) );
_setEmitterId( this, getProxyEmitterId( node, options ) );
// Remember the DOM Node this ProxyEmitter is bound to.
this._domNode = node;
// And given options.
this._options = options;
}

@@ -184,12 +209,9 @@ }

*
* **Note**: This is automatically called by the
* {@link module:utils/emittermixin~EmitterMixin#listenTo `EmitterMixin#listenTo()`}.
*
* @method module:utils/dom/emittermixin~ProxyEmitter#attach
* @param {String} event The name of the event.
* @param {Function} callback The function to be called on event.
* @param {Object} [options={}] Additional options.
* @param {Boolean} [options.useCapture=false] Indicates that events of this type will be dispatched to the registered
* listener before being dispatched to any EventTarget beneath it in the DOM tree.
* @param {Boolean} [options.usePassive=false] Indicates that the function specified by listener will never call preventDefault()
* and prevents blocking browser's main thread by this event handler.
*/
attach( event, callback, options = {} ) {
attach( event ) {
// If the DOM Listener for given event already exist it is pointless

@@ -201,11 +223,6 @@ // to attach another one.

const listenerOptions = {
capture: !!options.useCapture,
passive: !!options.usePassive
};
const domListener = this._createDomListener( event );
const domListener = this._createDomListener( event, listenerOptions );
// Attach the native DOM listener to DOM Node.
this._domNode.addEventListener( event, domListener, listenerOptions );
this._domNode.addEventListener( event, domListener, this._options );

@@ -224,2 +241,5 @@ if ( !this._domListeners ) {

*
* **Note**: This is automatically called by the
* {@link module:utils/emittermixin~EmitterMixin#stopListening `EmitterMixin#stopListening()`}.
*
* @method module:utils/dom/emittermixin~ProxyEmitter#detach

@@ -241,2 +261,32 @@ * @param {String} event The name of the event.

/**
* Adds callback to emitter for given event.
*
* @protected
* @method module:utils/dom/emittermixin~ProxyEmitter#_addEventListener
* @param {String} event The name of the event.
* @param {Function} callback The function to be called on event.
* @param {Object} [options={}] Additional options.
* @param {module:utils/priorities~PriorityString|Number} [options.priority='normal'] The priority of this event callback. The higher
* the priority value the sooner the callback will be fired. Events having the same priority are called in the
* order they were added.
*/
_addEventListener( event, callback, options ) {
this.attach( event );
EmitterMixin._addEventListener.call( this, event, callback, options );
},
/**
* Removes callback from emitter for given event.
*
* @protected
* @method module:utils/dom/emittermixin~ProxyEmitter#_removeEventListener
* @param {String} event The name of the event.
* @param {Function} callback The function to stop being called.
*/
_removeEventListener( event, callback ) {
EmitterMixin._removeEventListener.call( this, event, callback );
this.detach( event );
},
/**
* Creates a native DOM listener callback. When the native DOM event

@@ -249,9 +299,5 @@ * is fired it will fire corresponding event on this ProxyEmitter.

* @param {String} event The name of the event.
* @param {Object} [options] Additional options.
* @param {Boolean} [options.capture=false] Indicates whether the listener was created for capturing event.
* @param {Boolean} [options.passive=false] Indicates that the function specified by listener will never call preventDefault()
* and prevents blocking browser's main thread by this event handler.
* @returns {Function} The DOM listener callback.
*/
_createDomListener( event, options ) {
_createDomListener( event ) {
const domListener = domEvt => {

@@ -265,3 +311,3 @@ this.fire( event, domEvt );

domListener.removeListener = () => {
this._domNode.removeEventListener( event, domListener, options );
this._domNode.removeEventListener( event, domListener, this._options );
delete this._domListeners[ event ];

@@ -283,2 +329,22 @@ };

// Gets id of the ProxyEmitter for the given node.
//
// Combines DOM Node identifier and additional options.
//
// @private
// @param {Node} node
// @param {Object} options Additional options.
// @returns {String} ProxyEmitter id.
function getProxyEmitterId( node, options ) {
let id = getNodeUID( node );
for ( const option of Object.keys( options ).sort() ) {
if ( options[ option ] ) {
id += '-' + option;
}
}
return id;
}
/**

@@ -285,0 +351,0 @@ * Interface representing classes which mix in {@link module:utils/dom/emittermixin~EmitterMixin}.

@@ -29,2 +29,10 @@ /**

/**
* Indicates that the application is running on Windows.
*
* @static
* @type {Boolean}
*/
isWindows: isWindows( userAgent ),
/**
* Indicates that the application is running in Firefox (Gecko).

@@ -46,2 +54,10 @@ *

/**
* Indicates the the application is running in iOS.
*
* @static
* @type {Boolean}
*/
isiOS: isiOS( userAgent ),
/**
* Indicates that the application is running on Android mobile device.

@@ -93,2 +109,12 @@ *

/**
* Checks if User Agent represented by the string is running on Windows.
*
* @param {String} userAgent **Lowercase** `navigator.userAgent` string.
* @returns {Boolean} Whether User Agent is running on Windows or not.
*/
export function isWindows( userAgent ) {
return userAgent.indexOf( 'windows' ) > -1;
}
/**
* Checks if User Agent represented by the string is Firefox (Gecko).

@@ -114,2 +140,13 @@ *

/**
* Checks if User Agent represented by the string is running in iOS.
*
* @param {String} userAgent **Lowercase** `navigator.userAgent` string.
* @returns {Boolean} Whether User Agent is running in iOS or not.
*/
export function isiOS( userAgent ) {
// "Request mobile site" || "Request desktop site".
return !!userAgent.match( /iphone|ipad/i ) || ( isMac( userAgent ) && navigator.maxTouchPoints > 0 );
}
/**
* Checks if User Agent represented by the string is Android mobile device.

@@ -116,0 +153,0 @@ *

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

const version = '31.0.0';
const version = '31.1.0';

@@ -17,0 +17,0 @@ export default version;

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