Skip to content

Commit

Permalink
Removed warning from elementToElement() helper logged when multiple c…
Browse files Browse the repository at this point in the history
…hildren were produced as a workaround for elementToStructure() disallowing conversion of model elements with $text.
  • Loading branch information
oleq committed Feb 8, 2022
1 parent 50dd19a commit 5c4c1fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 36 deletions.
29 changes: 0 additions & 29 deletions packages/ckeditor5-engine/src/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import ConversionHelpers from './conversionhelpers';
import { cloneDeep } from 'lodash-es';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import toArray from '@ckeditor/ckeditor5-utils/src/toarray';
import { logWarning } from '@ckeditor/ckeditor5-utils';

/**
* Downcast conversion helper functions.
Expand Down Expand Up @@ -1042,9 +1041,6 @@ export function insertElement( elementCreator, consumer = defaultConsumer ) {
return;
}

// Check if only one element has been created.
validateChildren( viewElement );

// Consume an element insertion and all present attributes that are specified as a reconversion triggers.
consumer( data.item, conversionApi.consumable );

Expand Down Expand Up @@ -2163,31 +2159,6 @@ function createConsumer( model ) {
};
}

// Check if given element children list contains only UI elements and warns otherwise.
//
// @param {module:engine/view/element~Element} viewElement.
function validateChildren( viewElement ) {
const children = Array.from( viewElement.getChildren() );
const hasNonUiChildren = children.some( element => !element.is( 'uiElement' ) );

if ( hasNonUiChildren ) {
/**
* Only one container element without any children elements other than
* {@link module:engine/view/uielement~UIElement `UIElement`}s should be created in
* {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement} function.
*
* Please make sure you don't create more than one element in
* {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement} and if you need
* to create multiple elements use {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure}
* instead.
*
* @error conversion-element-to-element-created-multiple-elements
* @param {module:engine/model/element~Element} viewElement
*/
logWarning( 'conversion-element-to-element-created-multiple-elements', { viewElement } );
}
}

// Creates a function that create view slots.
//
// @param {module:engine/model/element~Element} element
Expand Down
9 changes: 2 additions & 7 deletions packages/ckeditor5-engine/tests/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ describe( 'DowncastHelpers', () => {
} );

describe( 'with multiple child elements', () => {
it( 'warns if multiple child elements are created', () => {
it( 'does not warn if multiple child elements are created', () => {
let viewElement;

testUtils.sinon.stub( console, 'warn' );
Expand All @@ -828,12 +828,7 @@ describe( 'DowncastHelpers', () => {
writer.insertElement( 'multiItemBox', null, modelRoot, 0 );
} );

sinon.assert.calledOnce( console.warn );
sinon.assert.calledWithExactly( console.warn,
sinon.match( /^conversion-element-to-element-created-multiple-elements/ ),
{ viewElement },
sinon.match.string // Link to the documentation
);
sinon.assert.notCalled( console.warn );
} );

it( 'does not warn if multiple child UI elements are created', () => {
Expand Down

0 comments on commit 5c4c1fb

Please sign in to comment.