-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Custom Html Widget #5566
Comments
@jodator, can you take a look at it? |
So you can achieve this by using import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
editor.model.schema.register( 'customHtml', {
// Behaves like a self-contained object (e.g. an image).
isObject: true,
// Allow in places where other blocks are allowed (e.g. directly in the root).
allowWhere: '$block', // Do not allow other content inside so the children will not be converted.
allowAttributes: [ 'htmlContent' ]
} );
conversion.for( 'upcast' ).elementToElement( {
model: ( viewElement, writer ) => {
const stringifiedChildren = Array.from( viewElement.getChildren() ).map( child => stringify( child ) ).join( '' );
return writer.createElement( 'customHtml', {
htmlContent: stringifiedChildren
} );
},
view: {
name: 'div',
classes: 'custom-html'
}
} );
conversion.for( 'dataDowncast' ).elementToElement( {
model: 'customHtml',
view: ( modelElement, viewWriter ) => {
const div = viewWriter.createUIElement( 'div', {
class: 'custom-html'
}, function( domDocument ) {
const domElement = this.toDomElement( domDocument );
domElement.innerHTML = modelElement.getAttribute( 'htmlContent' );
return domElement;
} );
return div;
}
} );
conversion.for( 'editingDowncast' ).elementToElement( {
model: 'customHtml',
view: ( modelElement, viewWriter ) => {
const div = viewWriter.createUIElement( 'div', { class: 'custom-html' }, function( domDocument ) {
const domElement = this.toDomElement( domDocument );
domElement.innerHTML = modelElement.getAttribute( 'htmlContent' );
return domElement;
} );
return toWidget( div, viewWriter, {
label: 'CustomHtml'
} );
}
} ); The trick is to use |
@jodator Firstly thank you for the detailed example ! This helps me a great deal. You are right that the above approach will do what I want to achieve. I have copied your code into my plugin and it works except I can not perform "cut" on the widget. I can copy paste the widget but not cut it. If I attempt to cut the widget a greyed out widget exactly the same as the one I was attempting to cut will remain in place and will not be selectable. Does this issue sound familiar ? If not just let me know and produce an example pen or something where you can see. |
That would be helpful to check since I don't recall anything in particual that have to do with copy/paste. I suspect that the |
The repo and the source is here The pen is here: Btw this is not urgent. |
Hi @turigeza, I haven't got time to check this because we're focusing on the upcoming release. I still want to at least take a look at this since it looks like a nice example that could be added to our docs. |
Hi @jodator , Time has passed and I am kind of desperate for this feature. Is there anything I could do to promote the development of this Raw Element mentioned here ? The code example you gave above doesn't seem to work for me. I can not cut or delete the ui element. It might just be that I have messed something up ... ? The pen is still live at. Thank you, |
Hi @turigeza! I managed to workaround this by adding another container. My code is in https://github.com/ckeditor/ckeditor5/compare/i/5566-raw-html-poc and works fine (copy-paste works). But it's ugly. The issue that would need to be resolved to make this pretties is #4469. And #7336 too for that matter ;/ |
@Reinmar Thank you for that. I ended up using ProseMirror after all so I personally don't need this anymore. But maybe others find it helpful. |
📝 Provide a description of the new feature
A widget
@ckeditor/ckeditor5-widget
which could contain arbitrary text / html.What is the expected behavior of the proposed feature?
Let's say the source code contains the following html.
So currently I would end up with this in the editor.
I am importing old content and converting it so that I can use ckeditor5 with it.
Now for the most important things I have created (or will do so) models (plugins) which match the old content. Like for example for my layouts.
But there is some stuff which really is not worth describing as a model and I would be happy not to be able to edit it.
Can I achieve this already somehow ? This is how far I got following the docs. I was hoping I can do it with a non editable widget.
https://github.com/turigeza/ckeditor5-build-balloon-block/tree/master/src/CustomHTML
Thank you
If you'd like to see this feature implemented, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: