Ver código fonte

Update docs for View, and replace trig with regexp in is() method.

Mateusz Samsel 6 anos atrás
pai
commit
fdb2726473

+ 1 - 1
packages/ckeditor5-engine/src/view/containerelement.js

@@ -54,7 +54,7 @@ export default class ContainerElement extends Element {
 	 * @inheritDoc
 	 */
 	is( type, name = null ) {
-		const cutType = type && type.replace( 'view:', '' );
+		const cutType = type && type.replace( /^view:/, '' );
 		if ( !name ) {
 			return cutType == 'containerElement' || super.is( type );
 		} else {

+ 8 - 2
packages/ckeditor5-engine/src/view/documentfragment.js

@@ -94,8 +94,14 @@ export default class DocumentFragment {
 	}
 
 	/**
-	 * Checks whether given view tree 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: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.
+	 *
+	 * 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}

+ 8 - 13
packages/ckeditor5-engine/src/view/documentselection.js

@@ -275,19 +275,14 @@ 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()`}.
-	 *
-	 *		const selection = new DocumentSelection( ... );
-	 *
-	 *		selection.is( 'selection' ); // true
-	 *		selection.is( 'view:selection' ); // true
-	 *		selection.is( 'documentSelection' ); // true
-	 *		selection.is( 'view:documentSelection' ); // true
-	 *		selection.is( 'node' ); // false
-	 *		selection.is( 'view:node' ); // false
-	 *		selection.is( 'model:selection' ); // false
-	 *		selection.is( 'element' ); // false
+	 * 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.
+	 *
+	 * Acceptable types for this class are `selection` and `documentSelection` and its prefixed version.
+	 *
+	 * See also: {@link module:engine/view/node~Node#is `Node#is()`}.
 	 *
 	 * @param {String} type
 	 * @returns {Boolean}

+ 1 - 1
packages/ckeditor5-engine/src/view/editableelement.js

@@ -70,7 +70,7 @@ export default class EditableElement extends ContainerElement {
 	 * @inheritDoc
 	 */
 	is( type, name = null ) {
-		const cutType = type && type.replace( 'view:', '' );
+		const cutType = type && type.replace( /^view:/, '' );
 		if ( !name ) {
 			return cutType == 'editableElement' || super.is( type );
 		} else {

+ 13 - 3
packages/ckeditor5-engine/src/view/element.js

@@ -147,22 +147,32 @@ 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:', '' );
+		const cutType = type.replace( /^view:/, '' );
 		if ( !name ) {
 			return cutType == 'element' || cutType == this.name || super.is( type );
 		} else {

+ 1 - 1
packages/ckeditor5-engine/src/view/emptyelement.js

@@ -47,7 +47,7 @@ export default class EmptyElement extends Element {
 	 * @inheritDoc
 	 */
 	is( type, name = null ) {
-		const cutType = type.replace( 'view:', '' );
+		const cutType = type.replace( /^view:/, '' );
 		if ( !name ) {
 			return cutType == 'emptyElement' || super.is( type );
 		} else {

+ 2 - 0
packages/ckeditor5-engine/src/view/node.js

@@ -314,6 +314,8 @@ export default class Node {
 	 *		obj.is( 'view:text' ); // true for text node, false for element and document fragment
 	 *
 	 *
+	 * Acceptable types for this class is `node` and its prefixed version.
+	 *
 	 * @param {String} type
 	 * @returns {Boolean}
 	 */

+ 8 - 2
packages/ckeditor5-engine/src/view/position.js

@@ -207,8 +207,14 @@ export default class Position {
 	}
 
 	/**
-	 * Checks whether given object is of `position` 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: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}

+ 8 - 2
packages/ckeditor5-engine/src/view/range.js

@@ -395,8 +395,14 @@ export default class Range {
 	}
 
 	/**
-	 * Checks whether given object is of `range` 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: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}

+ 1 - 1
packages/ckeditor5-engine/src/view/rooteditableelement.js

@@ -41,7 +41,7 @@ export default class RootEditableElement extends EditableElement {
 	 * @inheritDoc
 	 */
 	is( type, name = null ) {
-		const cutType = type.replace( 'view:', '' );
+		const cutType = type.replace( /^view:/, '' );
 		if ( !name ) {
 			return cutType == 'rootElement' || super.is( type );
 		} else {

+ 9 - 2
packages/ckeditor5-engine/src/view/selection.js

@@ -598,8 +598,10 @@ 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( ... );
 	 *
@@ -608,6 +610,11 @@ export default class Selection {
 	 *		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}
 	 */

+ 8 - 2
packages/ckeditor5-engine/src/view/textproxy.js

@@ -141,8 +141,14 @@ export default class TextProxy {
 	}
 
 	/**
-	 * Checks whether given view tree 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: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.
+	 *
+	 * 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}

+ 1 - 1
packages/ckeditor5-engine/src/view/uielement.js

@@ -60,7 +60,7 @@ export default class UIElement extends Element {
 	 * @inheritDoc
 	 */
 	is( type, name = null ) {
-		const cutType = type.replace( 'view:', '' );
+		const cutType = type.replace( /^view:/, '' );
 		if ( !name ) {
 			return cutType == 'uiElement' || super.is( type );
 		} else {