ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

How to type dataprocessor when using a custom format not based on strings

Open Joel-Levi opened this issue 1 year ago • 5 comments

The docs state: Note: While the CKEditor 5 architecture supports changing the data format, in most scenarios we do recommend sticking to the default format which is HTML.

I have a custom format for rich text that is based on objects. I already got the editor to work with this format, i.e. I extended the DataProcessor and wrote my own toView and toData. The only 'problem' is that the typing of the DataController and the DataApiMixin will only accept strings or record<string,string> for their get/set data functions. Is this on purpose? Is there a reason I am not seeing that the set/get data can only be string or Record<string, string>? I would love use be able to set a type parameter or something in order to get rid of my'@ts-expect-errors

Joel-Levi avatar Feb 08 '24 09:02 Joel-Levi

Hi! This is interesting, I assume we always expected the editor to receive a string or setting per root:

dataController.set( { main: '<p>Foo</p>', title: '<h1>Bar</h1>' } ); // Sets data on the `main` and `title` roots as specified.

cc @arkflpc thoughts?

Witoso avatar Feb 09 '24 15:02 Witoso

We are discussing this. That can be very trivial change, or a very serious one.

arkflpc avatar Feb 20 '24 12:02 arkflpc

Any news on this? I could share code and some examples if that would help

Joel-Levi avatar Mar 29 '24 08:03 Joel-Levi

@arkflpc could you post the results of your discussion?

Dumluregn avatar May 24 '24 08:05 Dumluregn

Thank you for your feedback. Your approach was indeed valid before we migrated CKEditor 5 to TypeScript, as the data type was previously described as {*}, meaning any type. However, the data format is generally assumed to be string by most integrators, and you are the first to report an issue with using a custom data format. We are not sure if accommodating any data type into the TypeScript type system is straightforward without degrading CKEditor 5 typings for most use cases. To better understand and address your issue, we ask you to describe your use case in more detail, specifically how you are integrating CKEditor 5, how you use your custom data format, and what specific problems it solves for you. I apologize for the delayed response and appreciate your patience.

arkflpc avatar Jun 18 '24 11:06 arkflpc