Skip to content

Commit

Permalink
Checking alternative approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
niegowski committed May 12, 2022
1 parent 41d207d commit cc5c341
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
6 changes: 5 additions & 1 deletion packages/ckeditor5-engine/src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ export default class DataController {
const viewDocumentFragment = this.processor.toView( data );

// view -> model
return this.toModel( viewDocumentFragment, context );
const modelDocumentFragment = this.toModel( viewDocumentFragment, context );

this.processor.domConverter.clearBindings();

return modelDocumentFragment;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class HtmlDataProcessor {
const domFragment = this._toDom( data );

// Convert DOM DocumentFragment to view DocumentFragment.
return this.domConverter.domToView( domFragment );
return this.domConverter.domToView( domFragment, { bind: true } );
}

/**
Expand Down
9 changes: 9 additions & 0 deletions packages/ckeditor5-engine/src/view/domconverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ export default class DomConverter {
}
}

/**
* TODO
*/
clearBindings() {
this._domToViewMapping = new WeakMap();
this._viewToDomMapping = new WeakMap();
this._fakeSelectionMapping = new WeakMap();
}

/**
* Binds DOM and view document fragments, so it will be possible to get corresponding document fragments using
* {@link module:engine/view/domconverter~DomConverter#mapDomToView} and
Expand Down
19 changes: 6 additions & 13 deletions packages/ckeditor5-html-support/src/integrations/customelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import { Plugin } from 'ckeditor5/src/core';
import { UpcastWriter } from 'ckeditor5/src/engine';

import DataSchema from '../dataschema';
import DataFilter from '../datafilter';
Expand Down Expand Up @@ -67,21 +66,15 @@ export default class CustomElementSupport extends Plugin {
conversionApi.writer.setAttribute( 'htmlAttributes', htmlAttributes, modelElement );
}

const viewWriter = new UpcastWriter( viewElement.document );
const childNodes = [];
const domElement = editor.data.processor.domConverter.mapViewToDom( viewElement );
const rawContent = domElement.innerHTML;

// Replace filler offset so the block filler won't get injected.
for ( const node of Array.from( viewElement.getChildren() ) ) {
node.getFillerOffset = () => null;
childNodes.push( node );
if ( rawContent ) {
conversionApi.writer.setAttribute( 'htmlContent', rawContent, modelElement );
}

const documentFragment = viewWriter.createDocumentFragment( childNodes );

if ( !documentFragment.isEmpty ) {
const htmlContent = editor.data.processor.toData( documentFragment );

conversionApi.writer.setAttribute( 'htmlContent', htmlContent, modelElement );
for ( const node of viewElement.getChildren() ) {
conversionApi.consumable.consume( node, { name: true } );
}

if ( !unsafeElements.includes( viewElement.name ) ) {
Expand Down

0 comments on commit cc5c341

Please sign in to comment.