@ckeditor/ckeditor5-utils
Advanced tools
Comparing version 26.0.0 to 27.0.0
{ | ||
"name": "@ckeditor/ckeditor5-utils", | ||
"version": "26.0.0", | ||
"version": "27.0.0", | ||
"description": "Miscellaneous utils used by CKEditor 5.", | ||
@@ -17,6 +17,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-build-classic": "^26.0.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^26.0.0", | ||
"@ckeditor/ckeditor5-core": "^26.0.0", | ||
"@ckeditor/ckeditor5-engine": "^26.0.0", | ||
"@ckeditor/ckeditor5-build-classic": "^27.0.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^27.0.0", | ||
"@ckeditor/ckeditor5-core": "^27.0.0", | ||
"@ckeditor/ckeditor5-engine": "^27.0.0", | ||
"assertion-error": "^1.1.0", | ||
@@ -23,0 +23,0 @@ "js-beautify": "^1.11.0" |
@@ -112,30 +112,3 @@ /** | ||
// Finally register the callback to the event. | ||
createEventNamespace( emitter, event ); | ||
const lists = getCallbacksListsForNamespace( emitter, event ); | ||
const priority = priorities.get( options.priority ); | ||
const callbackDefinition = { | ||
callback, | ||
priority | ||
}; | ||
// Add the callback to all callbacks list. | ||
for ( const callbacks of lists ) { | ||
// Add the callback to the list in the right priority position. | ||
let added = false; | ||
for ( let i = 0; i < callbacks.length; i++ ) { | ||
if ( callbacks[ i ].priority < priority ) { | ||
callbacks.splice( i, 0, callbackDefinition ); | ||
added = true; | ||
break; | ||
} | ||
} | ||
// Add at the end, if right place was not found. | ||
if ( !added ) { | ||
callbacks.push( callbackDefinition ); | ||
} | ||
} | ||
addEventListener( this, emitter, event, callback, options ); | ||
}, | ||
@@ -159,3 +132,3 @@ | ||
if ( callback ) { | ||
removeCallback( emitter, event, callback ); | ||
removeEventListener( this, emitter, event, callback ); | ||
@@ -170,3 +143,3 @@ // We must remove callbacks as well in order to prevent memory leaks. | ||
} else { | ||
removeCallback( emitter, event, callback ); | ||
removeEventListener( this, emitter, event, callback ); | ||
} | ||
@@ -178,3 +151,3 @@ } | ||
while ( ( callback = eventCallbacks.pop() ) ) { | ||
removeCallback( emitter, event, callback ); | ||
removeEventListener( this, emitter, event, callback ); | ||
} | ||
@@ -232,3 +205,3 @@ | ||
removeCallback( this, event, callbacks[ i ].callback ); | ||
this._removeEventListener( event, callbacks[ i ].callback ); | ||
} | ||
@@ -309,2 +282,54 @@ | ||
} | ||
}, | ||
/** | ||
* @inheritDoc | ||
*/ | ||
_addEventListener( event, callback, options ) { | ||
createEventNamespace( this, event ); | ||
const lists = getCallbacksListsForNamespace( this, event ); | ||
const priority = priorities.get( options.priority ); | ||
const callbackDefinition = { | ||
callback, | ||
priority | ||
}; | ||
// Add the callback to all callbacks list. | ||
for ( const callbacks of lists ) { | ||
// Add the callback to the list in the right priority position. | ||
let added = false; | ||
for ( let i = 0; i < callbacks.length; i++ ) { | ||
if ( callbacks[ i ].priority < priority ) { | ||
callbacks.splice( i, 0, callbackDefinition ); | ||
added = true; | ||
break; | ||
} | ||
} | ||
// Add at the end, if right place was not found. | ||
if ( !added ) { | ||
callbacks.push( callbackDefinition ); | ||
} | ||
} | ||
}, | ||
/** | ||
* @inheritDoc | ||
*/ | ||
_removeEventListener( event, callback ) { | ||
const lists = getCallbacksListsForNamespace( this, event ); | ||
for ( const callbacks of lists ) { | ||
for ( let i = 0; i < callbacks.length; i++ ) { | ||
if ( callbacks[ i ].callback == callback ) { | ||
// Remove the callback from the list (fixing the next index). | ||
callbacks.splice( i, 1 ); | ||
i--; | ||
} | ||
} | ||
} | ||
} | ||
@@ -453,2 +478,24 @@ }; | ||
/** | ||
* Adds callback to emitter for given event. | ||
* | ||
* @protected | ||
* @method #_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. | ||
*/ | ||
/** | ||
* Removes callback from emitter for given event. | ||
* | ||
* @protected | ||
* @method #_removeEventListener | ||
* @param {String} event The name of the event. | ||
* @param {Function} callback The function to stop being called. | ||
*/ | ||
/** | ||
* Checks if `listeningEmitter` listens to an emitter with given `listenedToEmitterId` and if so, returns that emitter. | ||
@@ -648,18 +695,21 @@ * If not, returns `null`. | ||
// Removes callback from emitter for given event. | ||
// | ||
// @param {module:utils/emittermixin~Emitter} emitter | ||
// @param {String} event | ||
// @param {Function} callback | ||
function removeCallback( emitter, event, callback ) { | ||
const lists = getCallbacksListsForNamespace( emitter, event ); | ||
// Helper for registering event callback on the emitter. | ||
function addEventListener( listener, emitter, event, callback, options ) { | ||
if ( emitter._addEventListener ) { | ||
emitter._addEventListener( event, callback, options ); | ||
} else { | ||
// Allow listening on objects that do not implement Emitter interface. | ||
// This is needed in some tests that are using mocks instead of the real objects with EmitterMixin mixed. | ||
listener._addEventListener.call( emitter, event, callback, options ); | ||
} | ||
} | ||
for ( const callbacks of lists ) { | ||
for ( let i = 0; i < callbacks.length; i++ ) { | ||
if ( callbacks[ i ].callback == callback ) { | ||
// Remove the callback from the list (fixing the next index). | ||
callbacks.splice( i, 1 ); | ||
i--; | ||
} | ||
} | ||
// Helper for removing event callback from the emitter. | ||
function removeEventListener( listener, emitter, event, callback ) { | ||
if ( emitter._removeEventListener ) { | ||
emitter._removeEventListener( event, callback ); | ||
} else { | ||
// Allow listening on objects that do not implement Emitter interface. | ||
// This is needed in some tests that are using mocks instead of the real objects with EmitterMixin mixed. | ||
listener._removeEventListener.call( emitter, event, callback ); | ||
} | ||
@@ -666,0 +716,0 @@ } |
@@ -31,2 +31,3 @@ /** | ||
export * from './keyboard'; | ||
export * from './language'; | ||
export { default as Locale } from './locale'; | ||
@@ -33,0 +34,0 @@ export { default as Collection } from './collection'; |
@@ -258,3 +258,3 @@ /** | ||
function splitKeystrokeText( keystroke ) { | ||
return keystroke.split( /\s*\+\s*/ ); | ||
return keystroke.split( '+' ).map( key => key.trim() ); | ||
} | ||
@@ -261,0 +261,0 @@ |
@@ -14,5 +14,4 @@ /** | ||
import { _translate } from './translation-service'; | ||
import { getLanguageDirection } from './language'; | ||
const RTL_LANGUAGE_CODES = [ 'ar', 'fa', 'he', 'ku', 'ug' ]; | ||
/** | ||
@@ -179,9 +178,1 @@ * Represents the localization services. | ||
} | ||
// Helps determine whether a language is LTR or RTL. | ||
// | ||
// @param {String} language The ISO 639-1 language code. | ||
// @returns {String} 'ltr' or 'rtl | ||
function getLanguageDirection( languageCode ) { | ||
return RTL_LANGUAGE_CODES.includes( languageCode ) ? 'rtl' : 'ltr'; | ||
} |
@@ -18,2 +18,5 @@ /** | ||
const _decoratedMethods = Symbol( 'decoratedMethods' ); | ||
const _decoratedOriginal = Symbol( 'decoratedOriginal' ); | ||
/** | ||
@@ -262,2 +265,10 @@ * A mixin that injects the "observable properties" and data binding functionality described in the | ||
}; | ||
this[ methodName ][ _decoratedOriginal ] = originalMethod; | ||
if ( !this[ _decoratedMethods ] ) { | ||
this[ _decoratedMethods ] = []; | ||
} | ||
this[ _decoratedMethods ].push( methodName ); | ||
} | ||
@@ -268,2 +279,20 @@ }; | ||
// Override the EmitterMixin stopListening method to be able to clean (and restore) decorated methods. | ||
// This is needed in case of: | ||
// 1. Have x.foo() decorated. | ||
// 2. Call x.stopListening() | ||
// 3. Call x.foo(). Problem: nothing happens (the original foo() method is not executed) | ||
ObservableMixin.stopListening = function( emitter, event, callback ) { | ||
// Removing all listeners so let's clean the decorated methods to the original state. | ||
if ( !emitter && this[ _decoratedMethods ] ) { | ||
for ( const methodName of this[ _decoratedMethods ] ) { | ||
this[ methodName ] = this[ methodName ][ _decoratedOriginal ]; | ||
} | ||
delete this[ _decoratedMethods ]; | ||
} | ||
EmitterMixin.stopListening.call( this, emitter, event, callback ); | ||
}; | ||
export default ObservableMixin; | ||
@@ -270,0 +299,0 @@ |
@@ -14,3 +14,3 @@ /** | ||
const version = '26.0.0'; | ||
const version = '27.0.0'; | ||
@@ -17,0 +17,0 @@ export default version; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
276242
59
6735