-
-
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
Conversion utilities: abandon multiples values attribute converters #4275
Comments
I have doubts from the configuration POV only. I think that whole idea behind configuration based converters was to give a common way to allow in a convenient way to override plugin's conversion defaults. So the examples with callbacks are overkills for that matter. The The Some configuration examples: // Here the `model` is a model element
const headingConfig = [
{ model: 'heading1', view: 'h1', acceptsAlso: [ 'h2', 'h3', 'h4' ] },
{ model: 'heading2', view: { element: 'p', style: { 'font-weight': 'bold' } } }
];
// Here the `model` is a `fontSize` attribute
const fontSizeConfig = [
{ model: 'big', view: { class: 'font-big' } },
{ model: 'small', view: { class: 'font-small' } }
];
// Here there is no `model` as it is boolean type
const boldConfig = { view: 'strong' };
const anotherBoldConfig = { view: { element: 'span', style: { 'font-weight': 'bold' } } }; This way we do not enforce users to check whether it should be Now how the plugin converts configuration to a conversion utilities depends on the plugin itself. Probably in most of the cases it will be some callback for Also allowing existing markup to be cleaned up by the editor is by definition asymmetric as n view elements will be matched to 1 model value (element or attribute) but 1 model value will be always represented as 1 view element. In other words I would not enforce plugin configuration definition by how lower lever API is constructed. (my main thought on this) As In my opinion there will be majority of developers that will only need to adapt CKEditor input/output plugin markup then there will be developers writing plugins. So majority of them will not need to know how conversion helpers really work. So for the majority will be that for that config option ps.: Another option is to completely remove const headingConfig = [
{ heading: 'heading1', view: 'h1', acceptsAlso: [ 'h2', 'h3', 'h4' ] },
{ heading: 'heading2', view: { element: 'p', style: { 'font-weight': 'bold' } } }
];
const fontSizeConfig = [
{ size: 'big', view: { class: 'font-big' } },
{ size: 'small', view: { class: 'font-small' } }
]; |
As much as I agree, I have to mention two things that I had on my mind when leaving the API as it was in definition-based-converters:
Of course above aren't necessarily big enough issues to be deciders, but I had them on my mind. |
We agreed on a couple of design decisions:
PS. Some clarification regarding the typedef mentioned above:
|
BTW, this was an incorrect change: ckeditor/ckeditor5-heading@b62d5cb. It means that, according to the docs, right now you cannot use That's why we'll define the generic |
Some clarifications:
|
We'll close https://github.com/ckeditor/ckeditor5-engine/issues/1243 here as well. |
Other: Introduced several improvements to conversion helpers. Closes #1295. Closes #1293. Closes #1292. Closes #1291. Closes #1290. Closes #1305.
We based our conversion utils, among others, on definition-based-converters. This util was focused on the specific case, where the model attribute is an enum with several possible values. This lead to the API which is very inconvenient in other cases.
Refactoring converters we realized that attributes values come in 4 types:
Most of them need only a single converter (often a callback).
Because we focus on creating conversion utilities the way that you can define multiple values they look like this for boolean:
And like this for callbacks:
They are very unsymmetrical: in
downcastElementToElement
and allupcast*
methods you pass object withmodel
andview
properties, but fordowncastAttributeToElement
anddowncastAttributeToAttribute
parameters are very different. I updated multiple converters to the new API and had to check docs every time to be sure which one should be defined which way because as long as you do not use enum it is not natural to write converters like this.Also, since
upcastElementToAttribute
accepts only a single attribute value to be set, this does not solve any problem.My proposal is to do it this way.
For
downcastAttributeToElement
:Check the current API here: https://github.com/ckeditor/ckeditor5-engine/blob/fd128a1c7ee5aef3e5aab788726af89c88059b64/src/conversion/downcast-converters.js#L78-L122
For
downcastAttributeToAttribute
:Check the current API here: https://github.com/ckeditor/ckeditor5-engine/blob/fd128a1c7ee5aef3e5aab788726af89c88059b64/src/conversion/downcast-converters.js#L155-L195.
Then we have plugins configuration and two-way config.
Besides the problems mentioned above (inconvenient configuration for booleans, string and object attributes) there are 2 more issues. First, the config might be giant https://github.com/ckeditor/ckeditor5-engine/blob/fd128a1c7ee5aef3e5aab788726af89c88059b64/src/conversion/two-way-converters.js#L169-L230 or https://github.com/ckeditor/ckeditor5-engine/blob/fd128a1c7ee5aef3e5aab788726af89c88059b64/src/conversion/two-way-converters.js#L298-L327.
Second, is that if we will keep
model
string value to be the attribute key, we will get 2 confusing configuration:model
attributes key,model
attributes value.This is why, plugins configuration should be defined different way, to make it clear that this is attribute value and make it compatible with the
downcast*
configuration:Then, we may have a util to add
model.key
property to the configuration and execute it. As soon as someone finds a good name for such helper, I am fine with it, but since all it will do is:I think that all plugins which have to do so can do it directly in the plugin code.
Note that some plugins may do more and this code might be very specific with all normalization. Also, in some cases we need to define additionally
model.name
: https://github.com/ckeditor/ckeditor5-engine/issues/1290.The text was updated successfully, but these errors were encountered: