| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module engine/view/emptyelement
- */
- import Element from './element';
- import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
- import Node from './node';
- /**
- * 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 module:utils/ckeditorerror~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, children ) {
- super( name, attributes, children );
- /**
- * Returns `null` because filler is not needed for EmptyElements.
- *
- * @method #getFillerOffset
- * @returns {null} Always returns null.
- */
- this.getFillerOffset = getFillerOffset;
- }
- /**
- * @inheritDoc
- */
- is( type, name = null ) {
- if ( !name ) {
- return type == 'emptyElement' || super.is( type );
- } else {
- return ( type == 'emptyElement' && name == this.name ) || super.is( type, name );
- }
- }
- /**
- * Overrides {@link module:engine/view/element~Element#insertChildren} method.
- * Throws {@link module:utils/ckeditorerror~CKEditorError CKEditorError} `view-emptyelement-cannot-add` to prevent
- * adding any child nodes to EmptyElement.
- */
- insertChildren( index, nodes ) {
- if ( nodes && ( nodes instanceof Node || Array.from( nodes ).length > 0 ) ) {
- /**
- * Cannot add children to {@link module:engine/view/emptyelement~EmptyElement}.
- *
- * @error view-emptyelement-cannot-add
- */
- throw new CKEditorError( 'view-emptyelement-cannot-add: Cannot add child nodes to EmptyElement instance.' );
- }
- }
- }
- // Returns `null` because block filler is not needed for EmptyElements.
- //
- // @returns {null}
- function getFillerOffset() {
- return null;
- }
|