diff --git a/src/model/documentfragment.js b/src/model/documentfragment.js index f6eff72d2..301a64f63 100644 --- a/src/model/documentfragment.js +++ b/src/model/documentfragment.js @@ -116,15 +116,20 @@ export default class DocumentFragment { } /** - * Checks whether given model tree object is of given type. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:documentFragment`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * - * Read more in {@link module:engine/model/node~Node#is}. + * Acceptable type for this class is `documentFragment` and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'documentFragment'; + return type == 'documentFragment' || type == 'model:documentFragment'; } /** diff --git a/src/model/documentselection.js b/src/model/documentselection.js index 6cd82e7dd..605ce09c4 100644 --- a/src/model/documentselection.js +++ b/src/model/documentselection.js @@ -367,21 +367,34 @@ export default class DocumentSelection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/model/node~Node#is `Node#is()`}. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:selection`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * * const selection = new DocumentSelection( ... ); * * selection.is( 'selection' ); // true + * selection.is( 'model:selection' ); // true * selection.is( 'documentSelection' ); // true + * selection.is( 'model:documentSelection' ); // true + * selection.is( 'view:selection' ); // false * selection.is( 'node' ); // false + * selection.is( 'model:node' ); // false * selection.is( 'element' ); // false * + * Acceptable type for this class is `selection` and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. + * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection' || type == 'documentSelection'; + return type == 'selection' || + type == 'model:selection' || + type == 'documentSelection' || + type == 'model:documentSelection'; } /** diff --git a/src/model/element.js b/src/model/element.js index 412575782..1d9cfce31 100644 --- a/src/model/element.js +++ b/src/model/element.js @@ -89,18 +89,31 @@ export default class Element extends Node { } /** - * Checks whether this model object is of the given type. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:element`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. + * + * There is also possibility to check element's {@link #name} rather than just type. Name might be provided as second attribute + * or might replace the type. * * obj.name; // 'listItem' * obj instanceof Element; // true * * obj.is( 'element' ); // true + * obj.is( 'model:element' ); // true * obj.is( 'listItem' ); // true + * obj.is( 'model:listItem' ); // true * obj.is( 'element', 'listItem' ); // true + * obj.is( 'model:element', 'listItem' ); // true * obj.is( 'text' ); // false + * obj.is( 'model:text' ); // false + * obj.is( 'view:element' ); // false * obj.is( 'element', 'image' ); // false * - * Read more in {@link module:engine/model/node~Node#is `Node#is()`}. + * Acceptable type for this class is `element` and its prefixed version, element's name or combination of both arguments. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. * * @param {String} type Type to check when `name` parameter is present. * Otherwise, it acts like the `name` parameter. @@ -108,10 +121,12 @@ export default class Element extends Node { * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^model:/, '' ); + if ( !name ) { - return type == 'element' || type == this.name || super.is( type ); + return cutType == 'element' || cutType == this.name || super.is( type ); } else { - return type == 'element' && name == this.name; + return cutType == 'element' && name == this.name; } } diff --git a/src/model/liveposition.js b/src/model/liveposition.js index fba8d41c1..4bfbbffd2 100644 --- a/src/model/liveposition.js +++ b/src/model/liveposition.js @@ -63,6 +63,13 @@ export default class LivePosition extends Position { this.stopListening(); } + /** + * @inheritDoc + */ + is( type ) { + return type == 'livePosition' || type == 'model:livePosition' || super.is( type ); + } + /** * Creates a {@link module:engine/model/position~Position position instance}, which is equal to this live position. * diff --git a/src/model/liverange.js b/src/model/liverange.js index 62385ea0b..98b57b781 100644 --- a/src/model/liverange.js +++ b/src/model/liverange.js @@ -40,6 +40,13 @@ export default class LiveRange extends Range { this.stopListening(); } + /** + * @inheritDoc + */ + is( type ) { + return type == 'liveRange' || type == 'model:liveRange' || super.is( type ); + } + /** * Creates a {@link module:engine/model/range~Range range instance} that is equal to this live range. * diff --git a/src/model/markercollection.js b/src/model/markercollection.js index 8909026b4..7e01d1ce4 100644 --- a/src/model/markercollection.js +++ b/src/model/markercollection.js @@ -448,6 +448,23 @@ class Marker { return this._liveRange.toRange(); } + /** + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:marker`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. + * + * Acceptable type for this class is `marker` and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'marker' || type == 'model:marker'; + } + /** * Binds new live range to the marker and detach the old one if is attached. * diff --git a/src/model/node.js b/src/model/node.js index feb9cba38..5d03f9725 100644 --- a/src/model/node.js +++ b/src/model/node.js @@ -467,6 +467,12 @@ export default class Node { * This method is useful when processing model tree objects that are of unknown type. For example, a function * may return {@link module:engine/model/documentfragment~DocumentFragment} or {@link module:engine/model/node~Node} * that can be either text node or element. This method can be used to check what kind of object is returned. + * All checked types might be prefixed with `model:` to narrow search exclusively to model's objects. + * That should prevent of situation where `view:node` accidentally might be considered as `model:node`. + * Types are defined as name of the class written in [camelCase](https://en.wikipedia.org/wiki/Camel_case) notation. + * E.g. class `LiveRange` will get type `liveRange`. + * + * There is more classes in model which follows similar naming convention. Check corresponding elements documentation for more details. * * obj.is( 'node' ); // true for any node, false for document fragment and text fragment * obj.is( 'documentFragment' ); // true for document fragment, false for any node @@ -476,12 +482,14 @@ export default class Node { * obj.is( 'text' ); // true for text node, false for element and document fragment * obj.is( 'textProxy' ); // true for text proxy object * + * Acceptable types for this class is `node` and its prefixed version. + * * @method #is - * @param {'element'|'rootElement'|'text'|'textProxy'|'documentFragment'} type + * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'node'; + return type == 'node' || type == 'model:node'; } } diff --git a/src/model/position.js b/src/model/position.js index 861ad9ea5..c5be603d1 100644 --- a/src/model/position.js +++ b/src/model/position.js @@ -502,6 +502,24 @@ export default class Position { } } + /** + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:position`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. + * + * Acceptable type for this class is `position` and its prefixed version. + * For {@link module:engine/model/liveposition~LivePosition} class there also acceptable `livePosition` type and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'position' || type == 'model:position'; + } + /** * Checks if two positions are in the same parent. * diff --git a/src/model/range.js b/src/model/range.js index 2e7af53da..91ce5e193 100644 --- a/src/model/range.js +++ b/src/model/range.js @@ -143,6 +143,24 @@ export default class Range { return this.containsPosition( pos ) || this.start.isEqual( pos ); } + /** + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:range`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. + * + * Acceptable type for this class is `range` and its prefixed version. + * For {@link module:engine/model/liverange~LiveRange} class there also acceptable `liveRange` type and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'range' || type == 'model:range'; + } + /** * Two ranges are equal if their {@link #start} and {@link #end} positions are equal. * diff --git a/src/model/rootelement.js b/src/model/rootelement.js index 72e002d3e..62bd3b45c 100644 --- a/src/model/rootelement.js +++ b/src/model/rootelement.js @@ -58,10 +58,11 @@ export default class RootElement extends Element { * @inheritDoc */ is( type, name ) { + const cutType = type.replace( 'model:', '' ); if ( !name ) { - return type == 'rootElement' || super.is( type ); + return cutType == 'rootElement' || super.is( type ); } else { - return ( type == 'rootElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'rootElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/model/selection.js b/src/model/selection.js index 83ee0bc44..4985b62cf 100644 --- a/src/model/selection.js +++ b/src/model/selection.js @@ -623,20 +623,27 @@ export default class Selection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/model/node~Node#is `Node#is()`}. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:selection`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * * const selection = new Selection( ... ); * * selection.is( 'selection' ); // true + * selection.is( 'model:selection' ); // true * selection.is( 'node' ); // false * selection.is( 'element' ); // false + * selection.is( 'view:selection' ); // false * + * Acceptable type for this class is `selection` and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection'; + return type == 'selection' || type == 'model:selection'; } /** diff --git a/src/model/text.js b/src/model/text.js index afc7560bc..ea487552f 100644 --- a/src/model/text.js +++ b/src/model/text.js @@ -66,7 +66,7 @@ export default class Text extends Node { * @inheritDoc */ is( type ) { - return type == 'text' || super.is( type ); + return type == 'text' || type == 'model:text' || super.is( type ); } /** diff --git a/src/model/textproxy.js b/src/model/textproxy.js index a59e99df4..fc6e1048f 100644 --- a/src/model/textproxy.js +++ b/src/model/textproxy.js @@ -173,15 +173,20 @@ export default class TextProxy { } /** - * Checks whether given model tree object is of given type. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `model:` string, + * for example `model:textProxy`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * - * Read more in {@link module:engine/model/node~Node#is}. + * Acceptable type for this class is `textProxy` and its prefixed version. + * + * See also: {@link module:engine/model/node~Node#is `Node#is()`}. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'textProxy'; + return type == 'textProxy' || type == 'model:textProxy'; } /** diff --git a/src/view/attributeelement.js b/src/view/attributeelement.js index 01e63195d..9fa77c815 100644 --- a/src/view/attributeelement.js +++ b/src/view/attributeelement.js @@ -128,10 +128,12 @@ export default class AttributeElement extends Element { * @inheritDoc */ is( type, name = null ) { + const cutType = type && type.replace( /^view:/, '' ); + if ( !name ) { - return type == 'attributeElement' || super.is( type ); + return cutType == 'attributeElement' || super.is( type ); } else { - return ( type == 'attributeElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'attributeElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/containerelement.js b/src/view/containerelement.js index 8333b9362..1d1d8ff31 100644 --- a/src/view/containerelement.js +++ b/src/view/containerelement.js @@ -54,10 +54,11 @@ export default class ContainerElement extends Element { * @inheritDoc */ is( type, name = null ) { + const cutType = type && type.replace( /^view:/, '' ); if ( !name ) { - return type == 'containerElement' || super.is( type ); + return cutType == 'containerElement' || super.is( type ); } else { - return ( type == 'containerElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'containerElement' && name == this.name ) || super.is( type, name ); } } } diff --git a/src/view/documentfragment.js b/src/view/documentfragment.js index 447086b64..7b469c248 100644 --- a/src/view/documentfragment.js +++ b/src/view/documentfragment.js @@ -94,15 +94,20 @@ export default class DocumentFragment { } /** - * Checks whether given view tree object is of given type. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:documentFragment`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * - * Read more in {@link module:engine/view/node~Node#is}. + * Acceptable type for this class is `documentFragment` and its prefixed version. + * + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'documentFragment'; + return type == 'documentFragment' || type == 'view:documentFragment'; } /** diff --git a/src/view/documentselection.js b/src/view/documentselection.js index f287f4d66..290a9c618 100644 --- a/src/view/documentselection.js +++ b/src/view/documentselection.js @@ -275,21 +275,23 @@ export default class DocumentSelection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/view/node~Node#is `Node#is()`}. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:selection`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * - * const selection = new DocumentSelection( ... ); + * Acceptable types for this class are `selection` and `documentSelection` and its prefixed version. * - * selection.is( 'selection' ); // true - * selection.is( 'documentSelection' ); // true - * selection.is( 'node' ); // false - * selection.is( 'element' ); // false + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection' || type == 'documentSelection'; + return type == 'selection' || + type == 'documentSelection' || + type == 'view:selection' || + type == 'view:documentSelection'; } /** diff --git a/src/view/editableelement.js b/src/view/editableelement.js index c1ce04409..5c7323486 100644 --- a/src/view/editableelement.js +++ b/src/view/editableelement.js @@ -70,10 +70,11 @@ export default class EditableElement extends ContainerElement { * @inheritDoc */ is( type, name = null ) { + const cutType = type && type.replace( /^view:/, '' ); if ( !name ) { - return type == 'editableElement' || super.is( type ); + return cutType == 'editableElement' || super.is( type ); } else { - return ( type == 'editableElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'editableElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/element.js b/src/view/element.js index 2965bfe0b..113842048 100644 --- a/src/view/element.js +++ b/src/view/element.js @@ -147,25 +147,36 @@ export default class Element extends Node { } /** - * Checks whether this view object is of the given type. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:element`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * + * There is also possibility to check element's {@link #name} rather than just type. Name might be provided as second attribute + * or might replace the type. + * + * // obj is a `li` element * obj.is( 'element' ); // true + * obj.is( 'view:element' ); // true * obj.is( 'li' ); // true * obj.is( 'element', 'li' ); // true * obj.is( 'text' ); // false * obj.is( 'element', 'img' ); // false * - * Read more in {@link module:engine/view/node~Node#is `Node#is()`}. + * Acceptable type for this class is `element` and its prefixed version, element's name or combination of both arguments. + * + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. * * @param {String} type * @param {String} [name] Element name. * @returns {Boolean} */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'element' || type == this.name || super.is( type ); + return cutType == 'element' || cutType == this.name || super.is( type ); } else { - return type == 'element' && name == this.name; + return cutType == 'element' && name == this.name; } } diff --git a/src/view/emptyelement.js b/src/view/emptyelement.js index 8973cb1c9..2cb2603db 100644 --- a/src/view/emptyelement.js +++ b/src/view/emptyelement.js @@ -47,10 +47,11 @@ export default class EmptyElement extends Element { * @inheritDoc */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'emptyElement' || super.is( type ); + return cutType == 'emptyElement' || super.is( type ); } else { - return ( type == 'emptyElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'emptyElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/node.js b/src/view/node.js index 6b9361d86..71e8ebe85 100644 --- a/src/view/node.js +++ b/src/view/node.js @@ -295,20 +295,32 @@ export default class Node { * This method is useful when processing view tree objects that are of unknown type. For example, a function * may return {@link module:engine/view/documentfragment~DocumentFragment} or {@link module:engine/view/node~Node} * that can be either text node or element. This method can be used to check what kind of object is returned. + * All checked types might be prefixed with `view:` to narrow search exclusively to view's objects. + * That should prevent of situation where `model:node` accidentally might be considered as `view:node`. + * Types are defined as name of the class written in [camelCase](https://en.wikipedia.org/wiki/Camel_case) notation. + * E.g. class `RootEditableElement` will get type `rootEditableElement`. * * obj.is( 'node' ); // true for any node, false for document fragment and text fragment + * obj.is( 'view:node' ); // true for any node, false for document fragment and text fragment * obj.is( 'documentFragment' ); // true for document fragment, false for any node + * obj.is( 'view:documentFragment' ); // true for document fragment, false for any node * obj.is( 'element' ); // true for any element, false for text node or document fragment + * obj.is( 'view:element' ); // true for any element, false for text node or document fragment * obj.is( 'element', 'p' ); // true only for element which name is 'p' + * obj.is( 'view:element', 'p' ); // true only for element which name is 'p' * obj.is( 'p' ); // shortcut for obj.is( 'element', 'p' ) + * obj.is( 'view:p' ); // shortcut for obj.is( 'view:element', 'p' ) * obj.is( 'text' ); // true for text node, false for element and document fragment + * obj.is( 'view:text' ); // true for text node, false for element and document fragment * - * @param {'element'|'containerElement'|'attributeElement'|'emptyElement'|'uiElement'| - * 'rootElement'|'documentFragment'|'text'|'textProxy'} type + * + * Acceptable types for this class is `node` and its prefixed version. + * + * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'node'; + return type == 'node' || type == 'view:node'; } /** diff --git a/src/view/position.js b/src/view/position.js index d44ddc8f7..ca7ee7fce 100644 --- a/src/view/position.js +++ b/src/view/position.js @@ -206,6 +206,23 @@ export default class Position { return i === 0 ? null : ancestorsA[ i - 1 ]; } + /** + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:position`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. + * + * Acceptable type for this class is `position` and its prefixed version. + * + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'position' || type == 'view:position'; + } + /** * Checks whether this position equals given position. * diff --git a/src/view/range.js b/src/view/range.js index e392ab307..37308709c 100644 --- a/src/view/range.js +++ b/src/view/range.js @@ -394,6 +394,23 @@ export default class Range { } } + /** + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:range`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. + * + * Acceptable type for this class is `range` and its prefixed version. + * + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. + * + * @param {String} type + * @returns {Boolean} + */ + is( type ) { + return type == 'range' || type == 'view:range'; + } + /** * Checks and returns whether this range intersects with the given range. * diff --git a/src/view/rooteditableelement.js b/src/view/rooteditableelement.js index 78d9e2f63..c4de2e411 100644 --- a/src/view/rooteditableelement.js +++ b/src/view/rooteditableelement.js @@ -41,10 +41,11 @@ export default class RootEditableElement extends EditableElement { * @inheritDoc */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'rootElement' || super.is( type ); + return cutType == 'rootElement' || super.is( type ); } else { - return ( type == 'rootElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'rootElement' && name == this.name ) || super.is( type, name ); } } diff --git a/src/view/selection.js b/src/view/selection.js index 0d23cd90d..2c267ffc7 100644 --- a/src/view/selection.js +++ b/src/view/selection.js @@ -598,20 +598,28 @@ export default class Selection { } /** - * Checks whether object is of given type following the convention set by - * {@link module:engine/view/node~Node#is `Node#is()`}. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:selection`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * * const selection = new Selection( ... ); * * selection.is( 'selection' ); // true + * selection.is( 'view:selection' ); // true * selection.is( 'node' ); // false * selection.is( 'element' ); // false + * + * Acceptable type for this class is `selection` and its prefixed version. + * + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. + * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'selection'; + return type == 'selection' || type == 'view:selection'; } /** diff --git a/src/view/text.js b/src/view/text.js index 1d044bf62..906fe9c22 100644 --- a/src/view/text.js +++ b/src/view/text.js @@ -45,7 +45,7 @@ export default class Text extends Node { * @inheritDoc */ is( type ) { - return type == 'text' || super.is( type ); + return type == 'text' || type == 'view:text' || super.is( type ); } /** diff --git a/src/view/textproxy.js b/src/view/textproxy.js index 8c463bc5c..a30ac01e4 100644 --- a/src/view/textproxy.js +++ b/src/view/textproxy.js @@ -141,15 +141,20 @@ export default class TextProxy { } /** - * Checks whether given view tree object is of given type. + * Method verifies if the checked object belongs to a given a type. Type's name might be prefixed with a `view:` string, + * for example `view:textProxy`. Type is a string which usually equal to a name of the class written in camelCase convention. + * If the object is a class instance, which has a parent class with `is()` method, then type verification returns `true` + * for any type match for an entire child-parent chain. * - * Read more in {@link module:engine/view/node~Node#is}. + * Acceptable type for this class is `textProxy` and its prefixed version. + * + * See also: {@link module:engine/view/node~Node#is `Node#is()`}. * * @param {String} type * @returns {Boolean} */ is( type ) { - return type == 'textProxy'; + return type == 'textProxy' || type == 'view:textProxy'; } /** diff --git a/src/view/uielement.js b/src/view/uielement.js index 663d63c23..bdae99965 100644 --- a/src/view/uielement.js +++ b/src/view/uielement.js @@ -60,10 +60,11 @@ export default class UIElement extends Element { * @inheritDoc */ is( type, name = null ) { + const cutType = type.replace( /^view:/, '' ); if ( !name ) { - return type == 'uiElement' || super.is( type ); + return cutType == 'uiElement' || super.is( type ); } else { - return ( type == 'uiElement' && name == this.name ) || super.is( type, name ); + return ( cutType == 'uiElement' && name == this.name ) || super.is( type, name ); } } diff --git a/tests/model/documentfragment.js b/tests/model/documentfragment.js index e9c07e797..a2eb870e8 100644 --- a/tests/model/documentfragment.js +++ b/tests/model/documentfragment.js @@ -61,7 +61,7 @@ describe( 'DocumentFragment', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let frag; before( () => { @@ -70,14 +70,16 @@ describe( 'DocumentFragment', () => { it( 'should return true for documentFragment', () => { expect( frag.is( 'documentFragment' ) ).to.be.true; + expect( frag.is( 'model:documentFragment' ) ).to.be.true; } ); - it( 'should return false for other accept values', () => { + it( 'should return false for other values', () => { expect( frag.is( 'node' ) ).to.be.false; expect( frag.is( 'text' ) ).to.be.false; expect( frag.is( 'textProxy' ) ).to.be.false; expect( frag.is( 'element' ) ).to.be.false; expect( frag.is( 'rootElement' ) ).to.be.false; + expect( frag.is( 'view:documentFragment' ) ).to.be.false; } ); } ); diff --git a/tests/model/documentselection.js b/tests/model/documentselection.js index b73cb4912..fd7a70627 100644 --- a/tests/model/documentselection.js +++ b/tests/model/documentselection.js @@ -485,21 +485,27 @@ describe( 'DocumentSelection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( selection.is( 'selection' ) ).to.be.true; + expect( selection.is( 'model:selection' ) ).to.be.true; } ); it( 'should return true for documentSelection', () => { expect( selection.is( 'documentSelection' ) ).to.be.true; + expect( selection.is( 'model:documentSelection' ) ).to.be.true; } ); it( 'should return false for other values', () => { expect( selection.is( 'node' ) ).to.be.false; + expect( selection.is( 'model:node' ) ).to.be.false; expect( selection.is( 'text' ) ).to.be.false; expect( selection.is( 'textProxy' ) ).to.be.false; expect( selection.is( 'element' ) ).to.be.false; + expect( selection.is( 'element', 'paragraph' ) ).to.be.false; expect( selection.is( 'rootElement' ) ).to.be.false; + expect( selection.is( 'view:selection' ) ).to.be.false; + expect( selection.is( 'view:documentSelection' ) ).to.be.false; } ); } ); diff --git a/tests/model/element.js b/tests/model/element.js index cac079910..8e448303d 100644 --- a/tests/model/element.js +++ b/tests/model/element.js @@ -38,7 +38,7 @@ describe( 'Element', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let element; before( () => { @@ -47,18 +47,29 @@ describe( 'Element', () => { it( 'should return true for node, element, element with same name and element name', () => { expect( element.is( 'node' ) ).to.be.true; + expect( element.is( 'model:node' ) ).to.be.true; expect( element.is( 'element' ) ).to.be.true; + expect( element.is( 'model:element' ) ).to.be.true; expect( element.is( 'element', 'paragraph' ) ).to.be.true; + expect( element.is( 'model:element', 'paragraph' ) ).to.be.true; expect( element.is( 'paragraph' ) ).to.be.true; + expect( element.is( 'model:paragraph' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( element.is( 'element', 'image' ) ).to.be.false; + expect( element.is( 'model:element', 'image' ) ).to.be.false; expect( element.is( 'image' ) ).to.be.false; + expect( element.is( 'model:image' ) ).to.be.false; expect( element.is( 'text' ) ).to.be.false; + expect( element.is( 'model:text' ) ).to.be.false; expect( element.is( 'textProxy' ) ).to.be.false; expect( element.is( 'documentFragment' ) ).to.be.false; expect( element.is( 'rootElement' ) ).to.be.false; + expect( element.is( 'model:rootElement' ) ).to.be.false; + expect( element.is( 'view:node' ) ).to.be.false; + expect( element.is( 'view:element' ) ).to.be.false; + expect( element.is( 'view:element' ) ).to.be.false; } ); } ); diff --git a/tests/model/liveposition.js b/tests/model/liveposition.js index e2115d904..bb10dae63 100644 --- a/tests/model/liveposition.js +++ b/tests/model/liveposition.js @@ -41,6 +41,29 @@ describe( 'LivePosition', () => expect( live ).to.be.instanceof( Position ); } ); + describe( 'is()', () => { + let live; + + beforeEach( () => { + live = new LivePosition( root, [ 0 ] ); + live.detach(); + } ); + + it( 'should return true for "livePosition" and "position"', () => { + expect( live.is( 'livePosition' ) ).to.be.true; + expect( live.is( 'model:livePosition' ) ).to.be.true; + expect( live.is( 'position' ) ).to.be.true; + expect( live.is( 'model:position' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( live.is( 'model' ) ).to.be.false; + expect( live.is( 'model:node' ) ).to.be.false; + expect( live.is( 'text' ) ).to.be.false; + expect( live.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + it( 'should throw if given root is not a RootElement', () => { const docFrag = new DocumentFragment(); diff --git a/tests/model/liverange.js b/tests/model/liverange.js index 67e8a53cf..e5ade9da0 100644 --- a/tests/model/liverange.js +++ b/tests/model/liverange.js @@ -183,6 +183,29 @@ describe( 'LiveRange', () => { expect( spy.args[ 1 ][ 2 ].deletionPosition.isEqual( new Position( root, [ 0 ] ) ) ).to.be.true; } ); + describe( 'is()', () => { + let live; + + beforeEach( () => { + live = new LiveRange( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ); + live.detach(); + } ); + + it( 'should return true for "liveRange" and "range"', () => { + expect( live.is( 'liveRange' ) ).to.be.true; + expect( live.is( 'model:liveRange' ) ).to.be.true; + expect( live.is( 'range' ) ).to.be.true; + expect( live.is( 'model:range' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( live.is( 'model' ) ).to.be.false; + expect( live.is( 'model:node' ) ).to.be.false; + expect( live.is( 'text' ) ).to.be.false; + expect( live.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'should get transformed and fire change:range if', () => { let live, spy; diff --git a/tests/model/markercollection.js b/tests/model/markercollection.js index a5e730677..bec4dd670 100644 --- a/tests/model/markercollection.js +++ b/tests/model/markercollection.js @@ -410,4 +410,25 @@ describe( 'Marker', () => { expect( marker.affectsData ).to.be.false; } ); + + describe( 'is()', () => { + let marker; + + beforeEach( () => { + const range = new Range( Position._createAt( root, 1 ), Position._createAt( root, 2 ) ); + marker = model.markers._set( 'name', range ); + } ); + + it( 'should return true for "marker"', () => { + expect( marker.is( 'marker' ) ).to.be.true; + expect( marker.is( 'model:marker' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( marker.is( 'model' ) ).to.be.false; + expect( marker.is( 'model:node' ) ).to.be.false; + expect( marker.is( 'text' ) ).to.be.false; + expect( marker.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); } ); diff --git a/tests/model/node.js b/tests/model/node.js index 54bd6f545..a0d9baf82 100644 --- a/tests/model/node.js +++ b/tests/model/node.js @@ -165,6 +165,14 @@ describe( 'Node', () => { describe( 'is()', () => { it( 'should return true for node', () => { expect( node.is( 'node' ) ).to.be.true; + expect( node.is( 'model:node' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( node.is( 'model' ) ).to.be.false; + expect( node.is( 'model:text' ) ).to.be.false; + expect( node.is( 'text' ) ).to.be.false; + expect( node.is( 'element', 'paragraph' ) ).to.be.false; } ); } ); diff --git a/tests/model/position.js b/tests/model/position.js index 3f7bb9c5b..454984156 100644 --- a/tests/model/position.js +++ b/tests/model/position.js @@ -128,6 +128,26 @@ describe( 'Position', () => { } ); } ); + describe( 'is()', () => { + let position; + + beforeEach( () => { + position = new Position( root, [ 0 ] ); + } ); + + it( 'should return true for "position"', () => { + expect( position.is( 'position' ) ).to.be.true; + expect( position.is( 'model:position' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( position.is( 'model' ) ).to.be.false; + expect( position.is( 'model:node' ) ).to.be.false; + expect( position.is( 'text' ) ).to.be.false; + expect( position.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'static creators', () => { describe( '_createAt()', () => { it( 'should throw if no offset is passed', () => { diff --git a/tests/model/range.js b/tests/model/range.js index 7409c0617..a15deeafd 100644 --- a/tests/model/range.js +++ b/tests/model/range.js @@ -50,6 +50,20 @@ describe( 'Range', () => { } ); } ); + describe( 'is()', () => { + it( 'should return true for "range"', () => { + expect( range.is( 'range' ) ).to.be.true; + expect( range.is( 'model:range' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( range.is( 'model' ) ).to.be.false; + expect( range.is( 'model:node' ) ).to.be.false; + expect( range.is( 'text' ) ).to.be.false; + expect( range.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'root', () => { it( 'should be equal to start position root', () => { expect( range.root ).to.equal( start.root ); diff --git a/tests/model/rootelement.js b/tests/model/rootelement.js index 2bed59cac..6d90626aa 100644 --- a/tests/model/rootelement.js +++ b/tests/model/rootelement.js @@ -22,7 +22,7 @@ describe( 'RootElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let root; before( () => { @@ -34,19 +34,29 @@ describe( 'RootElement', () => { it( 'should return true for rootElement, element, element with same name and element name', () => { expect( root.is( 'element', '$root' ) ).to.be.true; + expect( root.is( 'model:element', '$root' ) ).to.be.true; expect( root.is( 'element' ) ).to.be.true; + expect( root.is( 'model:element' ) ).to.be.true; expect( root.is( '$root' ) ).to.be.true; + expect( root.is( 'model:$root' ) ).to.be.true; expect( root.is( 'rootElement', '$root' ) ).to.be.true; + expect( root.is( 'model:rootElement', '$root' ) ).to.be.true; expect( root.is( 'rootElement' ) ).to.be.true; + expect( root.is( 'model:rootElement' ) ).to.be.true; + expect( root.is( 'node' ) ).to.be.true; + expect( root.is( 'model:node' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( root.is( 'element', '$graveyard' ) ).to.be.false; + expect( root.is( 'model:element', '$graveyard' ) ).to.be.false; expect( root.is( 'rootElement', '$graveyard' ) ).to.be.false; + expect( root.is( 'model:rootElement', '$graveyard' ) ).to.be.false; expect( root.is( '$graveyard' ) ).to.be.false; expect( root.is( 'text' ) ).to.be.false; expect( root.is( 'textProxy' ) ).to.be.false; expect( root.is( 'documentFragment' ) ).to.be.false; + expect( root.is( 'view:element' ) ).to.be.false; } ); } ); } ); diff --git a/tests/model/selection.js b/tests/model/selection.js index 4586001fc..5897da938 100644 --- a/tests/model/selection.js +++ b/tests/model/selection.js @@ -127,6 +127,26 @@ describe( 'Selection', () => { } ); } ); + describe( 'is()', () => { + let selection; + + beforeEach( () => { + selection = new Selection(); + } ); + + it( 'should return true for "selection"', () => { + expect( selection.is( 'selection' ) ).to.be.true; + expect( selection.is( 'model:selection' ) ).to.be.true; + } ); + + it( 'should return false for incorrect values', () => { + expect( selection.is( 'model' ) ).to.be.false; + expect( selection.is( 'model:node' ) ).to.be.false; + expect( selection.is( 'text' ) ).to.be.false; + expect( selection.is( 'element', 'paragraph' ) ).to.be.false; + } ); + } ); + describe( 'isCollapsed', () => { it( 'should return false for empty selection', () => { expect( selection.isCollapsed ).to.be.false; @@ -806,7 +826,7 @@ describe( 'Selection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( selection.is( 'selection' ) ).to.be.true; } ); diff --git a/tests/model/text.js b/tests/model/text.js index 16973c119..86c93b748 100644 --- a/tests/model/text.js +++ b/tests/model/text.js @@ -32,7 +32,7 @@ describe( 'Text', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let text; before( () => { @@ -41,12 +41,15 @@ describe( 'Text', () => { it( 'should return true for node, text', () => { expect( text.is( 'node' ) ).to.be.true; + expect( text.is( 'model:node' ) ).to.be.true; expect( text.is( 'text' ) ).to.be.true; + expect( text.is( 'model:text' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( text.is( 'textProxy' ) ).to.be.false; expect( text.is( 'element' ) ).to.be.false; + expect( text.is( 'model:element' ) ).to.be.false; expect( text.is( 'rootElement' ) ).to.be.false; expect( text.is( 'documentFragment' ) ).to.be.false; } ); diff --git a/tests/model/textproxy.js b/tests/model/textproxy.js index 3602f7b72..a6cff835f 100644 --- a/tests/model/textproxy.js +++ b/tests/model/textproxy.js @@ -102,15 +102,18 @@ describe( 'TextProxy', () => { }, /model-textproxy-wrong-length/, model ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for textProxy', () => { expect( textProxy.is( 'textProxy' ) ).to.be.true; + expect( textProxy.is( 'model:textProxy' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( textProxy.is( 'node' ) ).to.be.false; + expect( textProxy.is( 'model:node' ) ).to.be.false; expect( textProxy.is( 'text' ) ).to.be.false; expect( textProxy.is( 'element' ) ).to.be.false; + expect( textProxy.is( 'model:element', 'image' ) ).to.be.false; expect( textProxy.is( 'documentFragment' ) ).to.be.false; expect( textProxy.is( 'rootElement' ) ).to.be.false; } ); diff --git a/tests/view/attributeelement.js b/tests/view/attributeelement.js index 3ae6870de..224325ff6 100644 --- a/tests/view/attributeelement.js +++ b/tests/view/attributeelement.js @@ -21,7 +21,7 @@ describe( 'AttributeElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -30,16 +30,24 @@ describe( 'AttributeElement', () => { it( 'should return true for attributeElement/element, also with correct name and element name', () => { expect( el.is( 'attributeElement' ) ).to.be.true; + expect( el.is( 'view:attributeElement' ) ).to.be.true; expect( el.is( 'attributeElement', 'span' ) ).to.be.true; + expect( el.is( 'view:attributeElement', 'span' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'span' ) ).to.be.true; + expect( el.is( 'view:element', 'span' ) ).to.be.true; expect( el.is( 'span' ) ).to.be.true; + expect( el.is( 'view:span' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'attributeElement', 'p' ) ).to.be.false; + expect( el.is( 'view:attributeElement', 'p' ) ).to.be.false; expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; diff --git a/tests/view/containerelement.js b/tests/view/containerelement.js index b7fa31152..7a8cd2302 100644 --- a/tests/view/containerelement.js +++ b/tests/view/containerelement.js @@ -18,7 +18,7 @@ describe( 'ContainerElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -27,16 +27,24 @@ describe( 'ContainerElement', () => { it( 'should return true for containerElement/element, also with correct name and element name', () => { expect( el.is( 'containerElement' ) ).to.be.true; + expect( el.is( 'view:containerElement' ) ).to.be.true; expect( el.is( 'containerElement', 'p' ) ).to.be.true; + expect( el.is( 'view:containerElement', 'p' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'p' ) ).to.be.true; + expect( el.is( 'view:element', 'p' ) ).to.be.true; expect( el.is( 'p' ) ).to.be.true; + expect( el.is( 'view:p' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'containerElement', 'span' ) ).to.be.false; + expect( el.is( 'view:containerElement', 'span' ) ).to.be.false; expect( el.is( 'element', 'span' ) ).to.be.false; + expect( el.is( 'view:element', 'span' ) ).to.be.false; expect( el.is( 'span' ) ).to.be.false; + expect( el.is( 'view:span' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; diff --git a/tests/view/documentfragment.js b/tests/view/documentfragment.js index 9d88f5a0d..0dc35368f 100644 --- a/tests/view/documentfragment.js +++ b/tests/view/documentfragment.js @@ -71,7 +71,7 @@ describe( 'DocumentFragment', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let frag; before( () => { @@ -80,13 +80,16 @@ describe( 'DocumentFragment', () => { it( 'should return true for documentFragment', () => { expect( frag.is( 'documentFragment' ) ).to.be.true; + expect( frag.is( 'view:documentFragment' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( frag.is( 'node' ) ).to.be.false; + expect( frag.is( 'view:node' ) ).to.be.false; expect( frag.is( 'text' ) ).to.be.false; expect( frag.is( 'textProxy' ) ).to.be.false; expect( frag.is( 'element' ) ).to.be.false; + expect( frag.is( 'view:element' ) ).to.be.false; expect( frag.is( 'containerElement' ) ).to.be.false; expect( frag.is( 'attributeElement' ) ).to.be.false; expect( frag.is( 'uiElement' ) ).to.be.false; diff --git a/tests/view/documentselection.js b/tests/view/documentselection.js index fdc1fb0f5..e9e2d5a04 100644 --- a/tests/view/documentselection.js +++ b/tests/view/documentselection.js @@ -725,21 +725,27 @@ describe( 'DocumentSelection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( documentSelection.is( 'selection' ) ).to.be.true; + expect( documentSelection.is( 'view:selection' ) ).to.be.true; } ); it( 'should return true for documentSelection', () => { expect( documentSelection.is( 'documentSelection' ) ).to.be.true; + expect( documentSelection.is( 'view:documentSelection' ) ).to.be.true; } ); it( 'should return false for other values', () => { expect( documentSelection.is( 'node' ) ).to.be.false; + expect( documentSelection.is( 'view:node' ) ).to.be.false; expect( documentSelection.is( 'text' ) ).to.be.false; + expect( documentSelection.is( 'view:text' ) ).to.be.false; expect( documentSelection.is( 'textProxy' ) ).to.be.false; expect( documentSelection.is( 'element' ) ).to.be.false; expect( documentSelection.is( 'rootElement' ) ).to.be.false; + expect( documentSelection.is( 'model:selection' ) ).to.be.false; + expect( documentSelection.is( 'model:documentSelection' ) ).to.be.false; } ); } ); diff --git a/tests/view/editableelement.js b/tests/view/editableelement.js index 3e519204b..17d191091 100644 --- a/tests/view/editableelement.js +++ b/tests/view/editableelement.js @@ -5,16 +5,58 @@ import createDocumentMock from '../../tests/view/_utils/createdocumentmock'; -import RootEditableElement from '../../src/view/rooteditableelement'; +import EditableElement from '../../src/view/editableelement'; import Range from '../../src/view/range'; import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; describe( 'EditableElement', () => { + describe( 'is', () => { + let el; + + before( () => { + el = new EditableElement( 'div' ); + } ); + + it( 'should return true for containerElement/editable/element, also with correct name and element name', () => { + expect( el.is( 'containerElement' ) ).to.be.true; + expect( el.is( 'view:containerElement' ) ).to.be.true; + expect( el.is( 'containerElement', 'div' ) ).to.be.true; + expect( el.is( 'view:containerElement', 'div' ) ).to.be.true; + expect( el.is( 'editableElement' ) ).to.be.true; + expect( el.is( 'view:editableElement' ) ).to.be.true; + expect( el.is( 'editableElement', 'div' ) ).to.be.true; + expect( el.is( 'view:editableElement', 'div' ) ).to.be.true; + expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; + expect( el.is( 'element', 'div' ) ).to.be.true; + expect( el.is( 'view:element', 'div' ) ).to.be.true; + expect( el.is( 'div' ) ).to.be.true; + expect( el.is( 'view:div' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( el.is( 'rootElement', 'p' ) ).to.be.false; + expect( el.is( 'view:rootElement', 'p' ) ).to.be.false; + expect( el.is( 'containerElement', 'p' ) ).to.be.false; + expect( el.is( 'view:containerElement', 'p' ) ).to.be.false; + expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; + expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; + expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'textProxy' ) ).to.be.false; + expect( el.is( 'attributeElement' ) ).to.be.false; + expect( el.is( 'uiElement' ) ).to.be.false; + expect( el.is( 'emptyElement' ) ).to.be.false; + expect( el.is( 'documentFragment' ) ).to.be.false; + } ); + } ); + describe( 'document', () => { let element, docMock; beforeEach( () => { - element = new RootEditableElement( 'div' ); + element = new EditableElement( 'div' ); docMock = createDocumentMock(); } ); @@ -51,16 +93,16 @@ describe( 'EditableElement', () => { beforeEach( () => { docMock = createDocumentMock(); - viewMain = new RootEditableElement( 'div' ); + viewMain = new EditableElement( 'div' ); viewMain._document = docMock; - viewHeader = new RootEditableElement( 'h1' ); + viewHeader = new EditableElement( 'h1' ); viewHeader._document = docMock; viewHeader.rootName = 'header'; } ); it( 'should be observable', () => { - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = createDocumentMock(); expect( root.isFocused ).to.be.false; @@ -114,7 +156,7 @@ describe( 'EditableElement', () => { describe( 'isReadOnly', () => { it( 'should be observable', () => { - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = createDocumentMock(); expect( root.isReadOnly ).to.be.false; @@ -131,7 +173,7 @@ describe( 'EditableElement', () => { } ); it( 'should be bound to the document#isReadOnly', () => { - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = createDocumentMock(); root.document.isReadOnly = false; @@ -147,7 +189,7 @@ describe( 'EditableElement', () => { describe( 'getDocument', () => { it( 'should return document', () => { const docMock = createDocumentMock(); - const root = new RootEditableElement( 'div' ); + const root = new EditableElement( 'div' ); root._document = docMock; expect( root.document ).to.equal( docMock ); diff --git a/tests/view/element.js b/tests/view/element.js index f05ed1832..1f161e163 100644 --- a/tests/view/element.js +++ b/tests/view/element.js @@ -82,7 +82,7 @@ describe( 'Element', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -91,21 +91,30 @@ describe( 'Element', () => { it( 'should return true for node, element, element with correct name and element name', () => { expect( el.is( 'node' ) ).to.be.true; + expect( el.is( 'view:node' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'p' ) ).to.be.true; + expect( el.is( 'view:element', 'p' ) ).to.be.true; expect( el.is( 'p' ) ).to.be.true; + expect( el.is( 'view:p' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'element', 'span' ) ).to.be.false; + expect( el.is( 'view:element', 'span' ) ).to.be.false; expect( el.is( 'span' ) ).to.be.false; + expect( el.is( 'view:span' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'view:text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; expect( el.is( 'uiElement' ) ).to.be.false; expect( el.is( 'emptyElement' ) ).to.be.false; + expect( el.is( 'view:emptyElement' ) ).to.be.false; expect( el.is( 'rootElement' ) ).to.be.false; + expect( el.is( 'view:ootElement' ) ).to.be.false; expect( el.is( 'documentFragment' ) ).to.be.false; } ); } ); diff --git a/tests/view/emptyelement.js b/tests/view/emptyelement.js index b216edd8e..695ddd881 100644 --- a/tests/view/emptyelement.js +++ b/tests/view/emptyelement.js @@ -20,7 +20,7 @@ describe( 'EmptyElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -29,17 +29,26 @@ describe( 'EmptyElement', () => { it( 'should return true for emptyElement/element, also with correct name and element name', () => { expect( el.is( 'emptyElement' ) ).to.be.true; + expect( el.is( 'view:emptyElement' ) ).to.be.true; expect( el.is( 'emptyElement', 'p' ) ).to.be.true; + expect( el.is( 'view:emptyElement', 'p' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'p' ) ).to.be.true; + expect( el.is( 'view:element', 'p' ) ).to.be.true; expect( el.is( 'p' ) ).to.be.true; + expect( el.is( 'view:p' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'emptyElement', 'span' ) ).to.be.false; + expect( el.is( 'view:emptyElement', 'span' ) ).to.be.false; expect( el.is( 'element', 'span' ) ).to.be.false; + expect( el.is( 'view:element', 'span' ) ).to.be.false; expect( el.is( 'span' ) ).to.be.false; + expect( el.is( 'view:span' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'view:text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; diff --git a/tests/view/node.js b/tests/view/node.js index f40d6588a..d56a841a4 100644 --- a/tests/view/node.js +++ b/tests/view/node.js @@ -31,10 +31,28 @@ describe( 'Node', () => { } ); describe( 'is()', () => { - it( 'should return true for node', () => { - const node = new Node(); + let node; + beforeEach( () => { + node = new Node(); + } ); + + it( 'should return true for node', () => { expect( node.is( 'node' ) ).to.be.true; + expect( node.is( 'view:node' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( node.is( 'rootElement' ) ).to.be.false; + expect( node.is( 'containerElement' ) ).to.be.false; + expect( node.is( 'element' ) ).to.be.false; + expect( node.is( 'p' ) ).to.be.false; + expect( node.is( 'text' ) ).to.be.false; + expect( node.is( 'textProxy' ) ).to.be.false; + expect( node.is( 'attributeElement' ) ).to.be.false; + expect( node.is( 'uiElement' ) ).to.be.false; + expect( node.is( 'emptyElement' ) ).to.be.false; + expect( node.is( 'documentFragment' ) ).to.be.false; } ); } ); diff --git a/tests/view/position.js b/tests/view/position.js index 13405951c..7e5ea011e 100644 --- a/tests/view/position.js +++ b/tests/view/position.js @@ -24,10 +24,37 @@ describe( 'Position', () => { describe( 'constructor()', () => { it( 'should create element without attributes', () => { - const elem = new Position( parentMock, 5 ); + const position = new Position( parentMock, 5 ); - expect( elem ).to.have.property( 'parent' ).that.equals( parentMock ); - expect( elem ).to.have.property( 'offset' ).that.equals( 5 ); + expect( position ).to.have.property( 'parent' ).that.equals( parentMock ); + expect( position ).to.have.property( 'offset' ).that.equals( 5 ); + } ); + } ); + + describe( 'is()', () => { + let position; + + beforeEach( () => { + position = new Position( parentMock, 5 ); + } ); + + it( 'should return true for "position"', () => { + expect( position.is( 'position' ) ).to.be.true; + expect( position.is( 'view:position' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( position.is( 'rootElement' ) ).to.be.false; + expect( position.is( 'containerElement' ) ).to.be.false; + expect( position.is( 'element' ) ).to.be.false; + expect( position.is( 'p' ) ).to.be.false; + expect( position.is( 'text' ) ).to.be.false; + expect( position.is( 'textProxy' ) ).to.be.false; + expect( position.is( 'attributeElement' ) ).to.be.false; + expect( position.is( 'uiElement' ) ).to.be.false; + expect( position.is( 'emptyElement' ) ).to.be.false; + expect( position.is( 'documentFragment' ) ).to.be.false; + expect( position.is( 'model:position' ) ).to.be.false; } ); } ); diff --git a/tests/view/range.js b/tests/view/range.js index c1320282e..8588e4228 100644 --- a/tests/view/range.js +++ b/tests/view/range.js @@ -43,6 +43,34 @@ describe( 'Range', () => { } ); } ); + describe( 'is()', () => { + let range; + + before( () => { + const start = new Position( {}, 1 ); + range = new Range( start ); + } ); + + it( 'should return true for "range"', () => { + expect( range.is( 'range' ) ).to.be.true; + expect( range.is( 'view:range' ) ).to.be.true; + } ); + + it( 'should return false for other accept values', () => { + expect( range.is( 'rootElement' ) ).to.be.false; + expect( range.is( 'containerElement' ) ).to.be.false; + expect( range.is( 'element' ) ).to.be.false; + expect( range.is( 'p' ) ).to.be.false; + expect( range.is( 'text' ) ).to.be.false; + expect( range.is( 'textProxy' ) ).to.be.false; + expect( range.is( 'attributeElement' ) ).to.be.false; + expect( range.is( 'uiElement' ) ).to.be.false; + expect( range.is( 'emptyElement' ) ).to.be.false; + expect( range.is( 'documentFragment' ) ).to.be.false; + expect( range.is( 'model:range' ) ).to.be.false; + } ); + } ); + describe( 'iterator', () => { it( 'should iterate over the range returning tree walker values', () => { const range = getRange( '

fo{o

bar

xy}z

' ); diff --git a/tests/view/rooteditableelement.js b/tests/view/rooteditableelement.js index a3cfa2e57..17b8b31e5 100644 --- a/tests/view/rooteditableelement.js +++ b/tests/view/rooteditableelement.js @@ -38,7 +38,7 @@ describe( 'RootEditableElement', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let el; before( () => { @@ -47,27 +47,42 @@ describe( 'RootEditableElement', () => { it( 'should return true for rootElement/containerElement/editable/element, also with correct name and element name', () => { expect( el.is( 'rootElement' ) ).to.be.true; + expect( el.is( 'view:rootElement' ) ).to.be.true; expect( el.is( 'rootElement', 'div' ) ).to.be.true; + expect( el.is( 'view:rootElement', 'div' ) ).to.be.true; expect( el.is( 'containerElement' ) ).to.be.true; + expect( el.is( 'view:containerElement' ) ).to.be.true; expect( el.is( 'containerElement', 'div' ) ).to.be.true; + expect( el.is( 'view:containerElement', 'div' ) ).to.be.true; expect( el.is( 'editableElement' ) ).to.be.true; + expect( el.is( 'view:editableElement' ) ).to.be.true; expect( el.is( 'editableElement', 'div' ) ).to.be.true; + expect( el.is( 'view:editableElement', 'div' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; expect( el.is( 'element', 'div' ) ).to.be.true; + expect( el.is( 'view:element', 'div' ) ).to.be.true; expect( el.is( 'div' ) ).to.be.true; + expect( el.is( 'view:div' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'rootElement', 'p' ) ).to.be.false; + expect( el.is( 'view:rootElement', 'p' ) ).to.be.false; expect( el.is( 'containerElement', 'p' ) ).to.be.false; + expect( el.is( 'view:containerElement', 'p' ) ).to.be.false; expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; + expect( el.is( 'view:text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'attributeElement' ) ).to.be.false; expect( el.is( 'uiElement' ) ).to.be.false; expect( el.is( 'emptyElement' ) ).to.be.false; expect( el.is( 'documentFragment' ) ).to.be.false; + expect( el.is( 'model:rootElement' ) ).to.be.false; } ); } ); diff --git a/tests/view/selection.js b/tests/view/selection.js index 260efe0a5..891f9dee6 100644 --- a/tests/view/selection.js +++ b/tests/view/selection.js @@ -600,18 +600,21 @@ describe( 'Selection', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for selection', () => { expect( selection.is( 'selection' ) ).to.be.true; + expect( selection.is( 'view:selection' ) ).to.be.true; } ); it( 'should return false for other values', () => { expect( selection.is( 'documentSelection' ) ).to.be.false; + expect( selection.is( 'view:documentSelection' ) ).to.be.false; expect( selection.is( 'node' ) ).to.be.false; expect( selection.is( 'text' ) ).to.be.false; expect( selection.is( 'textProxy' ) ).to.be.false; expect( selection.is( 'element' ) ).to.be.false; expect( selection.is( 'rootElement' ) ).to.be.false; + expect( selection.is( 'model:selection' ) ).to.be.false; } ); } ); diff --git a/tests/view/text.js b/tests/view/text.js index c0069830f..b3eb9e315 100644 --- a/tests/view/text.js +++ b/tests/view/text.js @@ -17,7 +17,7 @@ describe( 'Text', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { let text; before( () => { @@ -26,18 +26,24 @@ describe( 'Text', () => { it( 'should return true for node, text', () => { expect( text.is( 'node' ) ).to.be.true; + expect( text.is( 'view:node' ) ).to.be.true; expect( text.is( 'text' ) ).to.be.true; + expect( text.is( 'view:text' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( text.is( 'textProxy' ) ).to.be.false; + expect( text.is( 'view:textProxy' ) ).to.be.false; expect( text.is( 'element' ) ).to.be.false; + expect( text.is( 'view:element' ) ).to.be.false; expect( text.is( 'containerElement' ) ).to.be.false; expect( text.is( 'attributeElement' ) ).to.be.false; expect( text.is( 'uiElement' ) ).to.be.false; expect( text.is( 'emptyElement' ) ).to.be.false; expect( text.is( 'rootElement' ) ).to.be.false; expect( text.is( 'documentFragment' ) ).to.be.false; + expect( text.is( 'model:text' ) ).to.be.false; + expect( text.is( 'model:node' ) ).to.be.false; } ); } ); diff --git a/tests/view/textproxy.js b/tests/view/textproxy.js index 0c43f0816..08a4b318f 100644 --- a/tests/view/textproxy.js +++ b/tests/view/textproxy.js @@ -61,14 +61,17 @@ describe( 'TextProxy', () => { } ); } ); - describe( 'is', () => { + describe( 'is()', () => { it( 'should return true for textProxy', () => { expect( textProxy.is( 'textProxy' ) ).to.be.true; + expect( textProxy.is( 'view:textProxy' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( textProxy.is( 'node' ) ).to.be.false; + expect( textProxy.is( 'view:node' ) ).to.be.false; expect( textProxy.is( 'text' ) ).to.be.false; + expect( textProxy.is( 'view:text' ) ).to.be.false; expect( textProxy.is( 'element' ) ).to.be.false; expect( textProxy.is( 'containerElement' ) ).to.be.false; expect( textProxy.is( 'attributeElement' ) ).to.be.false; @@ -76,6 +79,7 @@ describe( 'TextProxy', () => { expect( textProxy.is( 'emptyElement' ) ).to.be.false; expect( textProxy.is( 'rootElement' ) ).to.be.false; expect( textProxy.is( 'documentFragment' ) ).to.be.false; + expect( textProxy.is( 'model:textProxy' ) ).to.be.false; } ); } ); diff --git a/tests/view/uielement.js b/tests/view/uielement.js index 65d591371..92eeda258 100644 --- a/tests/view/uielement.js +++ b/tests/view/uielement.js @@ -46,16 +46,26 @@ describe( 'UIElement', () => { it( 'should return true for uiElement/element, also with correct name and element name', () => { expect( el.is( 'uiElement' ) ).to.be.true; + expect( el.is( 'view:uiElement' ) ).to.be.true; expect( el.is( 'uiElement', 'span' ) ).to.be.true; + expect( el.is( 'view:uiElement', 'span' ) ).to.be.true; expect( el.is( 'element' ) ).to.be.true; + expect( el.is( 'view:element' ) ).to.be.true; + expect( el.is( 'node' ) ).to.be.true; + expect( el.is( 'view:node' ) ).to.be.true; expect( el.is( 'element', 'span' ) ).to.be.true; + expect( el.is( 'view:element', 'span' ) ).to.be.true; expect( el.is( 'span' ) ).to.be.true; + expect( el.is( 'view:span' ) ).to.be.true; } ); it( 'should return false for other accept values', () => { expect( el.is( 'uiElement', 'p' ) ).to.be.false; + expect( el.is( 'view:uiElement', 'p' ) ).to.be.false; expect( el.is( 'element', 'p' ) ).to.be.false; + expect( el.is( 'view:element', 'p' ) ).to.be.false; expect( el.is( 'p' ) ).to.be.false; + expect( el.is( 'view:p' ) ).to.be.false; expect( el.is( 'text' ) ).to.be.false; expect( el.is( 'textProxy' ) ).to.be.false; expect( el.is( 'containerElement' ) ).to.be.false; @@ -63,6 +73,9 @@ describe( 'UIElement', () => { expect( el.is( 'emptyElement' ) ).to.be.false; expect( el.is( 'rootElement' ) ).to.be.false; expect( el.is( 'documentFragment' ) ).to.be.false; + expect( el.is( 'model:element' ) ).to.be.false; + expect( el.is( 'model:span' ) ).to.be.false; + expect( el.is( 'model:node' ) ).to.be.false; } ); } );