Skip to content

Commit

Permalink
Merge pull request #11211 from ckeditor/ck/10294/reconversion
Browse files Browse the repository at this point in the history
Feature (engine): The DowncastWriter#createContainerElement() should accept a list of children so bigger view structures can be created in one call. Closes #10714.

Feature (engine): The elementToElement downcast helper will log a console warning if multiple elements have been created. Closes #10610.

Feature (engine): The DowncastDispatcher will throw an error if any of the model items were not consumed while converting. Closes #10377.

Feature (engine): Introducing convertItem(), convertChildren() and convertAttributes() in the downcast conversion API interface.

Feature (engine): Added support for reconversion in DowncastHelpers#elementToElement() downcast helper. Closes #10359.

Feature (engine): Added DowncastHelpers#elementToStructure() downcast helper with reconversion support. Closes #10358.

Feature (engine): It's now possible to trigger a nested conversion while downcasting an element.

Docs (engine): Overhauled the conversion documentation and introduced the documentation for conversion helpers. Closes #10294.

Internal (engine): elementToStructure() should throw when invoked for an element that allows $text. Closes #11163.

Internal (engine): Replaced conversionApi.slotFor() in elementToStructure with writer.createSlot(). Closes #11179.

Internal (engine): Reconversion helpers can coexist with Differ#refreshItem() children.

Other (engine): Implemented the EditingController#reconvertMarker() method to be used instead of Writer#updateMarker() for marker reconversion purposes. Implemented the EditingController#reconvertItem() method to replace Differ#refreshItem(). Closes #10659.

Other (engine): The attribute and child nodes conversion events are fired by the lowest priority handler for the insert event instead of by DowncastDispatcher itself. Closes #10376.

Other (engine): Events are fired by the DowncastDispatcher even if they were previously consumed. It's the conversion handler's responsibility to check if it can be consumed or if it was already consumed by other converters.

Other (engine): The DowncastDispatcher#convert() method introduced as a replacement to previously used convertInsert(). The new method handles not only nodes conversion but also markers.

Internal (horizontal-line): The horizontalLine element downcast conversion has been changed from elementToElement to elementToStructure.

Internal (html-support): HTML elements downcast conversion have been changed from elementToElement to elementToStructure.

Internal (image): The imageBlock and imageInline elements downcast conversion have been changed from elementToElement to elementToStructure.

Internal (link): Link inlineWidget element downcast conversion has been changed from elementToElement to elementToStructure.

Internal (media-embed): The media element downcast conversion has been changed from elementToElement to elementToStructure.

Internal (page-break): The pageBreak element downcast conversion has been changed from elementToElement to elementToStructure.

Internal (widget): The blockWidget and inlineWidget elements downcast conversion have been changed from elementToElement to elementToStructure.

Internal (heading): Added missing consuming converter.

Internal (heading): Code adjusted to changes in DowncastDispatcher API.

Internal (html-embed): Code adjusted to the removal of triggerBy conversion option.

Other (list): The ckeditor5-list package was restructured into subdirectories. Closes #10811.

Other (list): Downcast conversion should consume downcasted attributes.

Other (table): Table downcast conversion migrated to elementToStructure() downcast helper. Closes #10502.

Tests (clipboard): Added missing downcast conversion.

Tests (image): Tests updated to properly handle non-consumed errors fired by the DowncastDispatcher.

Tests (alignment, autoformat, block-quote, engine, html-support, image, indent, table, word-count): Tests updated after list package restructuring.

Tests (html-support): Fixed test for checking if an attribute was consumed while converting.

Docs (ckeditor5): Links in the migration guide point to the new conversion documentation.

MAJOR BREAKING CHANGE (list): The ListEditing, ListUI, ListStyleEditing, ListStyleUI, TodoListEditing, TodoListUI plugins were moved to the dedicated subdirectories (list, liststyle, todolist).

MAJOR BREAKING CHANGE (engine): Removed the Differ#refreshItem() method from the public API. Replaced by EditingController#reconvertItem() (see #10659).

MAJOR BREAKING CHANGE (engine): The DowncastDispatcher will throw an error if any of the model items were not consumed while converting. Read the conversion-model-consumable-not-consumed error documentation for more information.

MAJOR BREAKING CHANGE (engine): The DowncastDispatcher#conversionApi property is no longer available. The instances of DowncastConversionApi being created at the start of conversion.

MAJOR BREAKING CHANGE (engine): The support for the triggerBy option for downcast helpers is removed and replaced with the new elementToStructure() options.

MINOR BREAKING CHANGE (media-embed): The createMediaFigureElement helper function first argument has been changed from writer object to conversionApi object.

MINOR BREAKING CHANGE (table): The downcast converters of the table feature has been rewritten with the use of elementToStructure() and the re-conversion mechanism. See #10502.
  • Loading branch information
dawidurbanski authored Feb 9, 2022
2 parents 5d0a4eb + 91112d8 commit 9f17c59
Show file tree
Hide file tree
Showing 150 changed files with 7,691 additions and 4,762 deletions.
2 changes: 1 addition & 1 deletion docs/builds/guides/migration/migration-from-ckeditor-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Note: The number of options was reduced on purpose. We understood that configuri
<td>
<p>Extending the list of HTML tags or attributes that CKEditor should support can be achieved via the {@link features/general-html-support General HTML Support feature}. The GHS allows adding HTML markup not covered by official CKEditor 5 features into the editor's content. Such elements can be loaded, pasted, or output. It does not, however, provide a dedicated UI for the extended HTML markup.</p>
<p> Having full-fledged HTML support can be achieved by writing a plugin that (ideally) provides also means to control (insert, edit, delete) such markup. For more information on how to create plugins check the {@link framework/guides/creating-simple-plugin Creating a simple plugin} article. Looking at the source code of CKEditor 5 plugins may also give you a lot of inspiration.</p>
<p>Note that only content that is explicitly converted between the model and the view by the editor plugins will be preserved in CKEditor 5. Check the {@link framework/guides/deep-dive/conversion-introduction conversion tutorials} to learn how to extend the conversion rules.</p>
<p>Note that only content that is explicitly converted between the model and the view by the editor plugins will be preserved in CKEditor 5. Check the {@link framework/guides/deep-dive/conversion/intro conversion tutorials} to learn how to extend the conversion rules.</p>
</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/builds/guides/migration/migration-to-26.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Command name changes (before → after):
* `forwardDelete``deleteForward`
* `todoListCheck``checkTodoList`

The `TodoListCheckCommand` module was moved to {@link module:list/checktodolistcommand~CheckTodoListCommand `CheckTodoListCommand`}.
The `TodoListCheckCommand` module was moved to {@link module:list/todolist/checktodolistcommand~CheckTodoListCommand `CheckTodoListCommand`}.

The `ImageInsertCommand` module was moved to {@link module:image/image/insertimagecommand~InsertImageCommand `InsertImageCommand`}.

Expand Down
17 changes: 15 additions & 2 deletions docs/umberto.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
"framework/guides/ui/external-ui.html": "framework/guides/deep-dive/ui/external-ui.html",
"framework/guides/ui/theme-customization.html": "framework/guides/deep-dive/ui/theme-customization.html",
"framework/guides/creating-simple-plugin.html": "framework/guides/plugins/creating-simple-plugin.html",
"examples/builds/custom-build.html": "examples/builds-custom/full-featured-editor.html"
"examples/builds/custom-build.html": "examples/builds-custom/full-featured-editor.html",
"framework/guides/deep-dive/conversion/conversion-introduction.html": "framework/guides/deep-dive/conversion/intro.html",
"framework/guides/deep-dive/conversion/conversion-extending-output.html": "framework/guides/deep-dive/conversion/intro.html",
"framework/guides/deep-dive/conversion/conversion-preserving-custom-content.html": "framework/guides/deep-dive/conversion/intro.html",
"framework/guides/deep-dive/conversion/custom-element-conversion.html": "framework/guides/deep-dive/conversion/intro.html",
"framework/guides/deep-dive/conversion/element-reconversion.html": "framework/guides/deep-dive/conversion/intro.html"
},
"scripts": {
"snippet-adapter": "../scripts/docs/snippetadapter",
Expand Down Expand Up @@ -201,7 +206,15 @@
"name": "Conversion",
"id": "framework-deep-dive-conversion",
"slug": "conversion",
"order": 100
"order": 100,
"categories": [
{
"name": "Conversion helpers",
"id": "framework-deep-dive-conversion-helpers",
"slug": "helpers",
"order": 100
}
]
},
{
"name": "User interface",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@ckeditor/ckeditor5-dev-webpack-plugin": "^28.0.1",
"@ckeditor/ckeditor5-export-pdf": ">=1.0.0",
"@ckeditor/ckeditor5-export-word": ">=1.0.0",
"@ckeditor/ckeditor5-inspector": "^2.2.2",
"@ckeditor/ckeditor5-inspector": "^3.0.0",
"@ckeditor/ckeditor5-pagination": ">=1.0.0",
"@ckeditor/ckeditor5-react": "^3.0.0",
"@ckeditor/ckeditor5-real-time-collaboration": ">=28.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-alignment/tests/alignmentediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import AlignmentEditing from '../src/alignmentediting';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ImageCaptionEditing from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionediting';
import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
import ListEditing from '@ckeditor/ckeditor5-list/src/list/listediting';
import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-autoformat/tests/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import Autoformat from '../src/autoformat';

import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
import TodoListEditing from '@ckeditor/ckeditor5-list/src/todolistediting';
import ListEditing from '@ckeditor/ckeditor5-list/src/list/listediting';
import TodoListEditing from '@ckeditor/ckeditor5-list/src/todolist/todolistediting';
import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
import StrikethroughEditing from '@ckeditor/ckeditor5-basic-styles/src/strikethrough/strikethroughediting';
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-autoformat/tests/undointegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Autoformat from '../src/autoformat';

import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
import ListEditing from '@ckeditor/ckeditor5-list/src/list/listediting';
import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';
import CodeEditing from '@ckeditor/ckeditor5-basic-styles/src/code/codeediting';
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-block-quote/tests/blockquoteediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import BlockQuoteEditing from '../src/blockquoteediting';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import ListEditing from '@ckeditor/ckeditor5-list/src/listediting';
import ListEditing from '@ckeditor/ckeditor5-list/src/list/listediting';
import BoldEditing from '@ckeditor/ckeditor5-basic-styles/src/bold/boldediting';

import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
Expand Down
2 changes: 1 addition & 1 deletion packages/ckeditor5-clipboard/tests/pasteplaintext.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe( 'PastePlainText', () => {
isInline: true
} );

editor.conversion.for( 'upcast' ).elementToElement( {
editor.conversion.elementToElement( {
model: 'softBreak',
view: 'br'
} );
Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-code-block/src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export function modelToViewCodeBlockInsertion( model, languageDefs, useLabels =
preAttributes.spellcheck = 'false';
}

const pre = writer.createContainerElement( 'pre', preAttributes );
const code = writer.createContainerElement( 'code', {
class: languagesToClasses[ codeBlockLanguage ] || null
} );

writer.insert( writer.createPositionAt( pre, 0 ), code );
const pre = writer.createContainerElement( 'pre', preAttributes, code );

writer.insert( targetViewPosition, pre );
mapper.bindElements( data.item, code );
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="mini-inspector-bold" class="mini-inspector-editor">
<p><strong>Text in bold</strong></p>
</div>

<div id="mini-inspector-bold-container"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals DecoupledEditor, MiniCKEditorInspector, console, window, document */

DecoupledEditor
.create( document.querySelector( '#mini-inspector-bold' ) )
.then( editor => {
window.editor = editor;

MiniCKEditorInspector.attach(
editor,
document.querySelector( '#mini-inspector-bold-container' )
);
} )
.catch( err => {
console.error( err.stack );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div id="mini-inspector-heading-interactive" class="mini-inspector-editor">
<h1></h1>
</div>

<label class="mini-inspector-heading-level-dropdown">
<strong>Update heading level:</strong>
<select id="mini-inspector-heading-interactive-dropdown">
<option value="1">Level 1 (h1)</option>
<option value="2">Level 2 (h2)</option>
<option value="3">Level 3 (h3)</option>
<option value="4">Level 4 (h4)</option>
<option value="5">Level 5 (h5)</option>
<option value="6">Level 6 (h6)</option>
</select>
</label>

<div id="mini-inspector-heading-interactive-container"></div>

<style>
.mini-inspector-heading-level-dropdown {
display: block;
margin-bottom: 20px;
}

#mini-inspector-heading-interactive-dropdown {
padding: 5px;
}

#mini-inspector-heading-interactive-container .ck-mini-inspector > div:first-child .ck-inspector-tree-node__attribute {
background: #fdfd77;
}

#mini-inspector-heading-interactive-container .ck-mini-inspector > div:last-child .ck-inspector-tree-node__content .ck-inspector-tree-node__name {
display: inline;
background: #fdfd77;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals DecoupledEditor, MiniCKEditorInspector, Essentials, console, window, document */

function CustomHeading( editor ) {
editor.model.schema.register( 'heading', {
allowAttributes: [ 'level' ],
inheritAllFrom: '$block'
} );

editor.conversion.for( 'upcast' ).elementToElement( {
view: 'h1',
model: ( viewElement, { writer } ) => {
return writer.createElement( 'heading', { level: '1' } );
}
} );

editor.conversion.for( 'downcast' ).elementToElement( {
model: {
name: 'heading',
attributes: [ 'level' ]
},
view: ( modelElement, { writer } ) => {
return writer.createContainerElement(
'h' + modelElement.getAttribute( 'level' )
);
}
} );

const dropdown = document.getElementById(
'mini-inspector-heading-interactive-dropdown'
);

dropdown.addEventListener( 'change', event => {
editor.model.change( writer => {
writer.setAttribute(
'level',
event.target.value,
editor.model.document.getRoot().getChild( 0 )
);
} );
} );
}

DecoupledEditor.create( document.querySelector( '#mini-inspector-heading-interactive' ), {
plugins: [ Essentials, CustomHeading ]
} )
.then( editor => {
window.editor = editor;

MiniCKEditorInspector.attach(
editor,
document.querySelector( '#mini-inspector-heading-interactive-container' )
);
} )
.catch( err => {
console.error( err.stack );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="mini-inspector-heading" class="mini-inspector-editor">
<h1></h1>
</div>

<div id="mini-inspector-heading-container"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals DecoupledEditor, MiniCKEditorInspector, Essentials, console, window, document */

function CustomHeading( editor ) {
editor.model.schema.register( 'heading', {
allowAttributes: [ 'level' ],
inheritAllFrom: '$block'
} );

editor.conversion.elementToElement( {
model: 'heading',
view: 'h1'
} );
}

DecoupledEditor.create( document.querySelector( '#mini-inspector-heading' ), {
plugins: [ Essentials, CustomHeading ]
} )
.then( editor => {
window.editor = editor;

MiniCKEditorInspector.attach(
editor,
document.querySelector( '#mini-inspector-heading-container' )
);
} )
.catch( err => {
console.error( err.stack );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="mini-inspector-paragraph" class="mini-inspector-editor">
<p></p>
</div>

<div id="mini-inspector-paragraph-container"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals DecoupledEditor, MiniCKEditorInspector, console, window, document */

DecoupledEditor
.create( document.querySelector( '#mini-inspector-paragraph' ) )
.then( editor => {
window.editor = editor;

MiniCKEditorInspector.attach(
editor,
document.querySelector( '#mini-inspector-paragraph-container' )
);
} )
.catch( err => {
console.error( err.stack );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="mini-inspector-structure" class="mini-inspector-editor">
<div class="wrapper">
<div class="inner-wrapper">
<p>
Example structure
</p>
</div>
</div>
</div>

<div id="mini-inspector-structure-container"></div>
Loading

0 comments on commit 9f17c59

Please sign in to comment.