浏览代码

Added warning for using old argument value for `node.is( 'text' )` and `node.is( 'textProxy' )`.

Kuba Niegowski 5 年之前
父节点
当前提交
ca9ae957fb

+ 18 - 0
packages/ckeditor5-engine/src/model/text.js

@@ -7,7 +7,10 @@
  * @module engine/model/text
  */
 
+/* global console */
+
 import Node from './node';
+import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 // @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
 
@@ -82,6 +85,21 @@ export default class Text extends Node {
 	 * @returns {Boolean}
 	 */
 	is( type ) {
+		if ( type === 'text' || type === 'model:text' ) {
+			/**
+			 * Usage of `node.is( 'text' )` was replaced in CKEditor 21.0.0 with `node.is( '$text' )`
+			 * due to conflicts with element's name. See {@link module:engine/model/text~Text}.
+			 *
+			 * @error model-text-node-deprecated-is-text-argument
+			 */
+			console.warn(
+				attachLinkToDocumentation(
+					'model-text-node-deprecated-is-text-argument: ' +
+					'"text" is deprecated value for testing text nodes, use "$text" instead.'
+				)
+			);
+		}
+
 		return type === '$text' || type === 'model:$text' ||
 			// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
 			type === 'node' || type === 'model:node';

+ 18 - 1
packages/ckeditor5-engine/src/model/textproxy.js

@@ -7,7 +7,9 @@
  * @module engine/model/textproxy
  */
 
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+/* global console */
+
+import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 // @if CK_DEBUG_ENGINE // const { convertMapToStringifiedObject } = require( '../dev-utils/utils' );
 
@@ -178,6 +180,21 @@ export default class TextProxy {
 	 * @returns {Boolean}
 	 */
 	is( type ) {
+		if ( type === 'textProxy' || type === 'model:textProxy' ) {
+			/**
+			 * Usage of `node.is( 'textProxy' )` was replaced in CKEditor 21.0.0 with `node.is( '$textProxy' )`
+			 * due to conflicts with element's name. See {@link module:engine/model/textproxy~TextProxy}.
+			 *
+			 * @error model-textProxy-deprecated-is-textProxy-argument
+			 */
+			console.warn(
+				attachLinkToDocumentation(
+					'model-textProxy-deprecated-is-textProxy-argument: ' +
+					'"textProxy" is deprecated value for testing TextProxy items, use "$textProxy" instead.'
+				)
+			);
+		}
+
 		return type === '$textProxy' || type === 'model:$textProxy';
 	}
 

+ 18 - 0
packages/ckeditor5-engine/src/view/text.js

@@ -7,7 +7,10 @@
  * @module engine/view/text
  */
 
+/* global console */
+
 import Node from './node';
+import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * Tree view text node.
@@ -60,6 +63,21 @@ export default class Text extends Node {
 	 * @returns {Boolean}
 	 */
 	is( type ) {
+		if ( type === 'text' || type === 'model:text' ) {
+			/**
+			 * Usage of `node.is( 'text' )` was replaced in CKEditor 21.0.0 with `node.is( '$text' )`
+			 * due to conflicts with element's name. See {@link module:engine/view/text~Text}.
+			 *
+			 * @error view-text-node-deprecated-is-text-argument
+			 */
+			console.warn(
+				attachLinkToDocumentation(
+					'view-text-node-deprecated-is-text-argument: ' +
+					'"text" is deprecated value for testing text nodes, use "$text" instead.'
+				)
+			);
+		}
+
 		return type === '$text' || type === 'view:$text' ||
 			// From super.is(). This is highly utilised method and cannot call super. See ckeditor/ckeditor5#6529.
 			type === 'node' || type === 'view:node';

+ 18 - 1
packages/ckeditor5-engine/src/view/textproxy.js

@@ -7,7 +7,9 @@
  * @module engine/view/textproxy
  */
 
-import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
+/* global console */
+
+import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * TextProxy is a wrapper for substring of {@link module:engine/view/text~Text}. Instance of this class is created by
@@ -156,6 +158,21 @@ export default class TextProxy {
 	 * @returns {Boolean}
 	 */
 	is( type ) {
+		if ( type === 'textProxy' || type === 'model:textProxy' ) {
+			/**
+			 * Usage of `node.is( 'textProxy' )` was replaced in CKEditor 21.0.0 with `node.is( '$textProxy' )`
+			 * due to conflicts with element's name. See {@link module:engine/model/textproxy~TextProxy}.
+			 *
+			 * @error view-textProxy-deprecated-is-textProxy-argument
+			 */
+			console.warn(
+				attachLinkToDocumentation(
+					'view-textProxy-deprecated-is-textProxy-argument: ' +
+					'"textProxy" is deprecated value for testing TextProxy items, use "$textProxy" instead.'
+				)
+			);
+		}
+
 		return type === '$textProxy' || type === 'view:$textProxy';
 	}