浏览代码

Warn about rect-source-not-in-dom only in CK_DEBUG mode.

Piotr Jasiun 6 年之前
父节点
当前提交
aee2e94059
共有 2 个文件被更改,包括 10 次插入45 次删除
  1. 10 22
      packages/ckeditor5-utils/src/dom/rect.js
  2. 0 23
      packages/ckeditor5-utils/tests/dom/rect.js

+ 10 - 22
packages/ckeditor5-utils/src/dom/rect.js

@@ -7,14 +7,11 @@
  * @module utils/dom/rect
  */
 
-/* globals console */
-
 import isRange from './isrange';
 import isWindow from './iswindow';
 import getBorderWidths from './getborderwidths';
 import isText from './istext';
 import { isElement } from 'lodash-es';
-import { attachLinkToDocumentation } from '../ckeditorerror';
 
 const rectProperties = [ 'top', 'right', 'bottom', 'left', 'width', 'height' ];
 
@@ -69,25 +66,16 @@ export default class Rect {
 		} );
 
 		if ( isElement( source ) || isSourceRange ) {
-			const sourceNode = isSourceRange ? source.startContainer : source;
-
-			if ( !sourceNode.ownerDocument || !sourceNode.ownerDocument.body.contains( sourceNode ) ) {
-				/**
-				 * The `Rect` class depends on `getBoundingClientRect` and `getClientRects` DOM methods.
-				 * If the {@link #constructor source} of a rect in an HTML element or a DOM range but it does
-				 * not belong to any rendered DOM tree, these methods will fail to obtain the geometry and
-				 * the rect instance makes little sense to the features using it.
-				 *
-				 * To get rid of this warning make sure the source passed to the constructor
-				 * is a descendant of `window.document.body`.
-				 *
-				 * @error rect-source-not-in-dom
-				 * @param {String} source The source of the Rect instance.
-				 */
-				console.warn( attachLinkToDocumentation(
-					'rect-source-not-in-dom: The source of this rect does not belong to any rendered DOM tree.',
-				), { source } );
-			}
+			// The `Rect` class depends on `getBoundingClientRect` and `getClientRects` DOM methods. If the source
+			// of a rect in an HTML element or a DOM range but it does not belong to any rendered DOM tree, these methods
+			// will fail to obtain the geometry and the rect instance makes little sense to the features using it.
+			// To get rid of this warning make sure the source passed to the constructor is a descendant of `window.document.body`.
+			// @if CK_DEBUG // const sourceNode = isSourceRange ? source.startContainer : source;
+			// @if CK_DEBUG // if ( !sourceNode.ownerDocument || !sourceNode.ownerDocument.body.contains( sourceNode ) ) {
+			// @if CK_DEBUG // 	console.warn(
+			// @if CK_DEBUG // 		'rect-source-not-in-dom: The source of this rect does not belong to any rendered DOM tree.',
+			// @if CK_DEBUG // 		{ source } );
+			// @if CK_DEBUG // }
 
 			if ( isSourceRange ) {
 				copyRectProperties( this, Rect.getDomRangeRects( source )[ 0 ] );

+ 0 - 23
packages/ckeditor5-utils/tests/dom/rect.js

@@ -161,29 +161,6 @@ describe( 'Rect', () => {
 
 			assertRect( geometry, sourceGeometry );
 		} );
-
-		it( 'should warn if the source does not belong to rendered DOM tree (HTML element)', () => {
-			const element = document.createElement( 'div' );
-
-			sinon.stub( element, 'getBoundingClientRect' ).returns( geometry );
-
-			const rect = new Rect( element );
-			sinon.assert.calledOnce( console.warn );
-			sinon.assert.calledWithExactly( console.warn, sinon.match( /^rect-source-not-in-dom/ ), { source: element } );
-			assertRect( rect, geometry );
-		} );
-
-		it( 'should warn if the source does not belong to rendered DOM tree (DOM Range)', () => {
-			const range = document.createRange();
-
-			range.collapse();
-			sinon.stub( range, 'getClientRects' ).returns( [ geometry ] );
-
-			const rect = new Rect( range );
-			sinon.assert.calledOnce( console.warn );
-			sinon.assert.calledWithExactly( console.warn, sinon.match( /^rect-source-not-in-dom/ ), { source: range } );
-			assertRect( rect, geometry );
-		} );
 	} );
 
 	describe( 'clone()', () => {