@ckeditor/ckeditor5-utils
Advanced tools
Comparing version 14.0.0 to 15.0.0
Changelog | ||
========= | ||
## [15.0.0](https://github.com/ckeditor/ckeditor5-utils/compare/v14.0.0...v15.0.0) (2019-10-23) | ||
### Features | ||
* Implemented the `getResizeObserver()` helper that offers an entry to the native `ResizeObserver` API (see [ckeditor/ckeditor5#416](https://github.com/ckeditor/ckeditor5/issues/416)). ([875d5a4](https://github.com/ckeditor/ckeditor5-utils/commit/875d5a4)) | ||
* Introduced `assertEqualMarkup()` test util method. Closes [ckeditor/ckeditor5-paste-from-office#14](https://github.com/ckeditor/ckeditor5-paste-from-office/issues/14). ([ee1655f](https://github.com/ckeditor/ckeditor5-utils/commit/ee1655f)) | ||
* Introduced support for creating elements in other XML namespaces. See [ckeditor/ckeditor5#1842](https://github.com/ckeditor/ckeditor5/issues/1842). ([37fbcb9](https://github.com/ckeditor/ckeditor5-utils/commit/37fbcb9)) | ||
Thanks [@Sebobo](https://github.com/Sebobo)! | ||
### Bug fixes | ||
* `Rect#excludeScrollbarsAndBorders` should support RTL environments. Fixed incorrect output of the method. Closes [#297](https://github.com/ckeditor/ckeditor5-utils/issues/297). ([35f34fc](https://github.com/ckeditor/ckeditor5-utils/commit/35f34fc)) | ||
### Other changes | ||
* Introduced the `CKEditorError.rethrowUnexpectedError()` helper. Added custom error handling for the `Emitter#fire()` function. Part of [ckeditor/ckeditor5#1304](https://github.com/ckeditor/ckeditor5/issues/1304). ([1d84705](https://github.com/ckeditor/ckeditor5-utils/commit/1d84705)) | ||
## [14.0.0](https://github.com/ckeditor/ckeditor5-utils/compare/v13.0.1...v14.0.0) (2019-08-26) | ||
@@ -5,0 +24,0 @@ |
{ | ||
"name": "@ckeditor/ckeditor5-utils", | ||
"version": "14.0.0", | ||
"version": "15.0.0", | ||
"description": "Miscellaneous utils used by CKEditor 5.", | ||
@@ -12,13 +12,15 @@ "keywords": [ | ||
"dependencies": { | ||
"ckeditor5": "^12.4.0", | ||
"ckeditor5": "^15.0.0", | ||
"lodash-es": "^4.17.10" | ||
}, | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-build-classic": "^12.4.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^12.1.4", | ||
"@ckeditor/ckeditor5-core": "^12.3.0", | ||
"@ckeditor/ckeditor5-engine": "^14.0.0", | ||
"@ckeditor/ckeditor5-build-classic": "^15.0.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^15.0.0", | ||
"@ckeditor/ckeditor5-core": "^15.0.0", | ||
"@ckeditor/ckeditor5-engine": "^15.0.0", | ||
"assertion-error": "^1.1.0", | ||
"eslint": "^5.5.0", | ||
"eslint-config-ckeditor5": "^2.0.0", | ||
"husky": "^1.3.1", | ||
"js-beautify": "^1.10.2", | ||
"lint-staged": "^7.0.0" | ||
@@ -25,0 +27,0 @@ }, |
CKEditor 5 utilities | ||
======================================== | ||
[![Join the chat at https://gitter.im/ckeditor/ckeditor5](https://badges.gitter.im/ckeditor/ckeditor5.svg)](https://gitter.im/ckeditor/ckeditor5?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-utils.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-utils) | ||
@@ -6,0 +5,0 @@ [![Build Status](https://travis-ci.org/ckeditor/ckeditor5-utils.svg?branch=master)](https://travis-ci.org/ckeditor/ckeditor5-utils) |
@@ -94,2 +94,34 @@ /** | ||
} | ||
/** | ||
* A utility that ensures the the thrown error is a {@link module:utils/ckeditorerror~CKEditorError} one. | ||
* It is uesful when combined with the {@link module:watchdog/watchdog~Watchdog} feature, which can restart the editor in case | ||
* of a {@link module:utils/ckeditorerror~CKEditorError} error. | ||
* | ||
* @param {Error} err An error. | ||
* @param {Object} context An object conected through properties with the editor instance. This context will be used | ||
* by the watchdog to verify which editor should be restarted. | ||
*/ | ||
static rethrowUnexpectedError( err, context ) { | ||
if ( err.is && err.is( 'CKEditorError' ) ) { | ||
throw err; | ||
} | ||
/** | ||
* An unexpected error occurred inside the CKEditor 5 codebase. The `error.data.originalError` property | ||
* shows the original error properties. | ||
* | ||
* This error is only useful when the editor is initialized using the {@link module:watchdog/watchdog~Watchdog} feature. | ||
* In case of such error (or any {@link module:utils/ckeditorerror~CKEditorError} error) the wathcdog should restart the editor. | ||
* | ||
* @error unexpected-error | ||
*/ | ||
throw new CKEditorError( 'unexpected-error', context, { | ||
originalError: { | ||
message: err.message, | ||
stack: err.stack, | ||
name: err.name | ||
} | ||
} ); | ||
} | ||
} | ||
@@ -96,0 +128,0 @@ |
@@ -29,3 +29,4 @@ /** | ||
export default function createElement( doc, name, attributes = {}, children = [] ) { | ||
const element = doc.createElement( name ); | ||
const namespace = attributes && attributes.xmlns; | ||
const element = namespace ? doc.createElementNS( namespace, name ) : doc.createElement( name ); | ||
@@ -32,0 +33,0 @@ for ( const key in attributes ) { |
@@ -313,3 +313,3 @@ /** | ||
const source = this._source; | ||
let scrollBarWidth, scrollBarHeight; | ||
let scrollBarWidth, scrollBarHeight, direction; | ||
@@ -319,15 +319,26 @@ if ( isWindow( source ) ) { | ||
scrollBarHeight = source.innerHeight - source.document.documentElement.clientHeight; | ||
direction = source.getComputedStyle( source.document.documentElement ).direction; | ||
} else { | ||
const borderWidths = getBorderWidths( this._source ); | ||
scrollBarWidth = source.offsetWidth - source.clientWidth; | ||
scrollBarHeight = source.offsetHeight - source.clientHeight; | ||
scrollBarWidth = source.offsetWidth - source.clientWidth - borderWidths.left - borderWidths.right; | ||
scrollBarHeight = source.offsetHeight - source.clientHeight - borderWidths.top - borderWidths.bottom; | ||
direction = source.ownerDocument.defaultView.getComputedStyle( source ).direction; | ||
this.moveBy( borderWidths.left, borderWidths.top ); | ||
this.left += borderWidths.left; | ||
this.top += borderWidths.top; | ||
this.right -= borderWidths.right; | ||
this.bottom -= borderWidths.bottom; | ||
this.width = this.right - this.left; | ||
this.height = this.bottom - this.top; | ||
} | ||
// Assuming LTR scrollbars. TODO: RTL. | ||
this.width -= scrollBarWidth; | ||
this.right -= scrollBarWidth; | ||
if ( direction === 'ltr' ) { | ||
this.right -= scrollBarWidth; | ||
} else { | ||
this.left += scrollBarWidth; | ||
} | ||
this.height -= scrollBarHeight; | ||
@@ -334,0 +345,0 @@ this.bottom -= scrollBarHeight; |
@@ -16,2 +16,3 @@ /** | ||
import './version'; | ||
import CKEditorError from './ckeditorerror'; | ||
@@ -188,54 +189,58 @@ const _listeningTo = Symbol( 'listeningTo' ); | ||
fire( eventOrInfo, ...args ) { | ||
const eventInfo = eventOrInfo instanceof EventInfo ? eventOrInfo : new EventInfo( this, eventOrInfo ); | ||
const event = eventInfo.name; | ||
let callbacks = getCallbacksForEvent( this, event ); | ||
try { | ||
const eventInfo = eventOrInfo instanceof EventInfo ? eventOrInfo : new EventInfo( this, eventOrInfo ); | ||
const event = eventInfo.name; | ||
let callbacks = getCallbacksForEvent( this, event ); | ||
// Record that the event passed this emitter on its path. | ||
eventInfo.path.push( this ); | ||
// Record that the event passed this emitter on its path. | ||
eventInfo.path.push( this ); | ||
// Handle event listener callbacks first. | ||
if ( callbacks ) { | ||
// Arguments passed to each callback. | ||
const callbackArgs = [ eventInfo, ...args ]; | ||
// Handle event listener callbacks first. | ||
if ( callbacks ) { | ||
// Arguments passed to each callback. | ||
const callbackArgs = [ eventInfo, ...args ]; | ||
// Copying callbacks array is the easiest and most secure way of preventing infinite loops, when event callbacks | ||
// are added while processing other callbacks. Previous solution involved adding counters (unique ids) but | ||
// failed if callbacks were added to the queue before currently processed callback. | ||
// If this proves to be too inefficient, another method is to change `.on()` so callbacks are stored if same | ||
// event is currently processed. Then, `.fire()` at the end, would have to add all stored events. | ||
callbacks = Array.from( callbacks ); | ||
// Copying callbacks array is the easiest and most secure way of preventing infinite loops, when event callbacks | ||
// are added while processing other callbacks. Previous solution involved adding counters (unique ids) but | ||
// failed if callbacks were added to the queue before currently processed callback. | ||
// If this proves to be too inefficient, another method is to change `.on()` so callbacks are stored if same | ||
// event is currently processed. Then, `.fire()` at the end, would have to add all stored events. | ||
callbacks = Array.from( callbacks ); | ||
for ( let i = 0; i < callbacks.length; i++ ) { | ||
callbacks[ i ].callback.apply( this, callbackArgs ); | ||
for ( let i = 0; i < callbacks.length; i++ ) { | ||
callbacks[ i ].callback.apply( this, callbackArgs ); | ||
// Remove the callback from future requests if off() has been called. | ||
if ( eventInfo.off.called ) { | ||
// Remove the called mark for the next calls. | ||
delete eventInfo.off.called; | ||
// Remove the callback from future requests if off() has been called. | ||
if ( eventInfo.off.called ) { | ||
// Remove the called mark for the next calls. | ||
delete eventInfo.off.called; | ||
removeCallback( this, event, callbacks[ i ].callback ); | ||
} | ||
removeCallback( this, event, callbacks[ i ].callback ); | ||
} | ||
// Do not execute next callbacks if stop() was called. | ||
if ( eventInfo.stop.called ) { | ||
break; | ||
// Do not execute next callbacks if stop() was called. | ||
if ( eventInfo.stop.called ) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
// Delegate event to other emitters if needed. | ||
if ( this._delegations ) { | ||
const destinations = this._delegations.get( event ); | ||
const passAllDestinations = this._delegations.get( '*' ); | ||
// Delegate event to other emitters if needed. | ||
if ( this._delegations ) { | ||
const destinations = this._delegations.get( event ); | ||
const passAllDestinations = this._delegations.get( '*' ); | ||
if ( destinations ) { | ||
fireDelegatedEvents( destinations, eventInfo, args ); | ||
if ( destinations ) { | ||
fireDelegatedEvents( destinations, eventInfo, args ); | ||
} | ||
if ( passAllDestinations ) { | ||
fireDelegatedEvents( passAllDestinations, eventInfo, args ); | ||
} | ||
} | ||
if ( passAllDestinations ) { | ||
fireDelegatedEvents( passAllDestinations, eventInfo, args ); | ||
} | ||
return eventInfo.return; | ||
} catch ( err ) { | ||
CKEditorError.rethrowUnexpectedError( err, this ); | ||
} | ||
return eventInfo.return; | ||
}, | ||
@@ -604,3 +609,4 @@ | ||
// @private | ||
// * @param {Map.<utils.Emitter>} destinations A map containing `[ {@link utils.Emitter}, "event name" ]` pair destinations. | ||
// * @param {Map.<utils.Emitter>} destinations A map containing | ||
// `[ {@link module:utils/emittermixin~Emitter}, "event name" ]` pair destinations. | ||
// * @param {utils.EventInfo} eventInfo The original event info object. | ||
@@ -607,0 +613,0 @@ // * @param {Array.<*>} fireArgs Arguments the original event was fired with. |
@@ -336,7 +336,8 @@ /** | ||
// Object that stores which properties of this observable are bound and how. It shares | ||
// the binding objects (`{ observable: A, property: 'a', to: ... }`) with {@link utils.ObservableMixin#_boundObservables}. | ||
// This data structure is a reverse of {@link utils.ObservableMixin#_boundObservables} and it is helpful for | ||
// {@link utils.ObservableMixin#unbind}. | ||
// the binding objects (`{ observable: A, property: 'a', to: ... }`) with | ||
// {@link module:utils/observablemixin~ObservableMixin#_boundObservables}. This data structure is | ||
// a reverse of {@link module:utils/observablemixin~ObservableMixin#_boundObservables} and it is helpful for | ||
// {@link module:utils/observablemixin~ObservableMixin#unbind}. | ||
// | ||
// See {@link utils.ObservableMixin#bind}. | ||
// See {@link module:utils/observablemixin~ObservableMixin#bind}. | ||
// | ||
@@ -751,3 +752,3 @@ // A.bind( 'a', 'b', 'c' ).to( B, 'x', 'y', 'x' ); | ||
/** | ||
* Binds {@link #set obvervable properties} to other objects implementing the | ||
* Binds {@link #set observable properties} to other objects implementing the | ||
* {@link module:utils/observablemixin~Observable} interface. | ||
@@ -758,3 +759,3 @@ * | ||
* | ||
* Let's consider two objects: a `button` and an associated `command` (both `Observable`). | ||
* Consider two objects: a `button` and an associated `command` (both `Observable`). | ||
* | ||
@@ -774,3 +775,3 @@ * A simple property binding could be as follows: | ||
* | ||
* **Note**: To release the binding use {@link module:utils/observablemixin~Observable#unbind}. | ||
* **Note**: To release the binding, use {@link module:utils/observablemixin~Observable#unbind}. | ||
* | ||
@@ -803,3 +804,3 @@ * You can also "rename" the property in the binding by specifying the new name in the `to()` chain: | ||
* @method #bind | ||
* @param {...String} bindProperties Observable properties that will be bound to another observable(s). | ||
* @param {...String} bindProperties Observable properties that will be bound to other observable(s). | ||
* @returns {Object} The bind chain with the `to()` and `toMany()` methods. | ||
@@ -819,3 +820,3 @@ */ | ||
* @param {...String} [unbindProperties] Observable properties to be unbound. All the bindings will | ||
* be released if no properties provided. | ||
* be released if no properties are provided. | ||
*/ | ||
@@ -822,0 +823,0 @@ |
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
235376
56
5909
10
20
+ Addedckeditor5@15.0.0(transitive)
- Removedckeditor5@12.4.0(transitive)
Updatedckeditor5@^15.0.0