This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
407 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import Element from './element.js'; | ||
import CKEditorError from '../../utils/ckeditorerror.js'; | ||
|
||
/** | ||
* EmptyElement class. It is used to represent elements that cannot contain any child nodes. | ||
*/ | ||
export default class EmptyElement extends Element { | ||
/** | ||
* Creates new instance of EmptyElement. | ||
* | ||
* Throws {@link utils.CKEditorError CKEditorError} `view-emptyelement-cannot-add` when third parameter is passed, | ||
* to inform that usage of EmptyElement is incorrect (adding child nodes to EmptyElement is forbidden). | ||
* | ||
* @param {String} name Node name. | ||
* @param {Object|Iterable} [attributes] Collection of attributes. | ||
*/ | ||
constructor( name, attributes ) { | ||
super( name, attributes ); | ||
|
||
if ( arguments.length > 2 ) { | ||
throwCannotAdd(); | ||
} | ||
} | ||
|
||
/** | ||
* Clones provided element. Overrides {@link engine.view.Element#clone} method, as it's forbidden to pass child | ||
* nodes to EmptyElement's constructor. | ||
* | ||
* @returns {envine.view.EmptyElement} Clone of this element. | ||
*/ | ||
clone() { | ||
const cloned = new this.constructor( this.name, this._attrs ); | ||
|
||
// Classes and styles are cloned separately - this solution is faster than adding them back to attributes and | ||
// parse once again in constructor. | ||
cloned._classes = new Set( this._classes ); | ||
cloned._styles = new Map( this._styles ); | ||
|
||
return cloned; | ||
} | ||
|
||
/** | ||
* Overrides {@link engine.view.Element#appendChildren} method. | ||
* Throws {@link utils.CKEditorError CKEditorError} `view-emptyelement-cannot-add` to prevent adding any child nodes | ||
* to EmptyElement. | ||
*/ | ||
appendChildren() { | ||
throwCannotAdd(); | ||
} | ||
|
||
/** | ||
* Overrides {@link engine.view.Element#insertChildren} method. | ||
* Throws {@link utils.CKEditorError CKEditorError} `view-emptyelement-cannot-add` to prevent adding any child nodes | ||
* to EmptyElement. | ||
*/ | ||
insertChildren() { | ||
throwCannotAdd(); | ||
} | ||
|
||
/** | ||
* Returns `null` because block filler is not needed. | ||
* | ||
* @returns {null} | ||
*/ | ||
getFillerOffset() { | ||
return null; | ||
} | ||
} | ||
|
||
function throwCannotAdd() { | ||
/** | ||
* Cannot add children to {@link engine.view.EmptyElement}. | ||
* | ||
* @error view-emptyelement-cannot-add | ||
*/ | ||
throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' ); | ||
} |
Oops, something went wrong.