Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In v12.0.0 classic editor build (latest version), the code structure changed. I don't know how to modify the following code #1626

Closed
gongzhiq opened this issue Mar 13, 2019 · 1 comment
Labels
type:question This issue asks a question (how to...).

Comments

@gongzhiq
Copy link

gongzhiq commented Mar 13, 2019

hello,How to modify this code so that it can run

import { downcastElementToElement, downcastAttributeToAttribute } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
import { upcastElementToElement, upcastAttributeToAttribute  } from '@ckeditor/ckeditor5-engine/src/conversion/upcast-converters';
class myWidget extends Plugin {
    init() {
        const editor = this.editor;
        const model = editor.model;
		
        model.schema.register( 'myWidget', {
            inheritAllFrom: '$block',
            isObject: true
        } );
		
		model.schema.register( 'myWidget2', {
            inheritAllFrom: '$block',
			allowIn: 'myWidget',
            isObject: true
        } );


        editor.conversion.for( 'dataDowncast' )
            .add( downcastElementToElement( {
                model: 'myWidget',
                view: ( modelItem, writer ) => {
                    return writer.createContainerElement( 'div', { class: "note_bookinfo_name" } );
                }
            } ) );

        editor.conversion.for( 'editingDowncast' )
            .add( downcastElementToElement( {
                model: 'myWidget',
                view: ( modelItem, writer ) => {
                    const div = writer.createContainerElement( 'div', { class: "note_bookinfo_name"} );
                    return toWidget( div, writer);
                }
            } ) );

        editor.conversion.for( 'upcast' )
            .add( upcastElementToElement( {
                view: {
                    name: 'div',
                    key: 'class'
                },
                model: 'myWidget'
            } ) );
			
	    editor.conversion.for( 'dataDowncast' )
            .add( downcastElementToElement( {
                model: 'myWidget2',
                view: ( modelItem, writer ) => {
                    return writer.createContainerElement( 'objectid', { class: "note_bookinfo_id" } );
                }
            } ) );

        editor.conversion.for( 'editingDowncast' )
            .add( downcastElementToElement( {
                model: 'myWidget2',
                view: ( modelItem, writer ) => {
                    const objectid = writer.createContainerElement( 'objectid', { class: "note_bookinfo_id"} );
                    return toWidget( objectid, writer);
                }
            } ) );

        editor.conversion.for( 'upcast' )
            .add( upcastElementToElement( {
                view: {
                    name: 'objectid',
                    key: 'class'
                },
                model: 'myWidget2'
            } ) );
    }
}

Thank you very much

@Reinmar
Copy link
Member

Reinmar commented Mar 13, 2019

Hi!

Sorry for the trouble with the API change. It's a change for good so, though, so I'm sure it was worth it :)

With every release we publish a changelog which describes all breaking changes. This time wasn't different – v12.0.0. In this changelog you will find a Migration guide with information how to update your code.

@Reinmar Reinmar closed this as completed Mar 13, 2019
@Reinmar Reinmar added type:question This issue asks a question (how to...). resolution:fixed labels Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question This issue asks a question (how to...).
Projects
None yet
Development

No branches or pull requests

2 participants