Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge de6f1a2 into 44068ac
Browse files Browse the repository at this point in the history
  • Loading branch information
msamsel committed Aug 8, 2019
2 parents 44068ac + de6f1a2 commit 8c187db
Show file tree
Hide file tree
Showing 56 changed files with 657 additions and 89 deletions.
11 changes: 8 additions & 3 deletions src/model/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
19 changes: 16 additions & 3 deletions src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
23 changes: 19 additions & 4 deletions src/model/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,44 @@ 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.
* @param {String} [name] Element name.
* @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;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/model/liveposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
7 changes: 7 additions & 0 deletions src/model/liverange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
17 changes: 17 additions & 0 deletions src/model/markercollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 10 additions & 2 deletions src/model/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/model/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
18 changes: 18 additions & 0 deletions src/model/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 3 additions & 2 deletions src/model/rootelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/model/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/model/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/model/textproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/view/attributeelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/view/containerelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/view/documentfragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down

0 comments on commit 8c187db

Please sign in to comment.