-
-
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
One-way elementToElement() converters could have access to conversionApi #7334
Comments
I was pretty sure this is available in the callback. Check if it is available in downcasting. |
AFAIR most of the one-way converters has a minimal set of information in the callback. For instance attribute converters do not have access to the model element on which this attribute is set. This might be similar story in element to element converters. ps.: maybe a simplified use-case for your converter could be helpful to check what we can do there? |
Actually, I was wrong – there's no method for consuming all children. So the solution needs to be a bit different – not calling Still, this issue could be valid because I might've wanted to call |
Conclusion: Make |
Looks it is a way to do this: #7336 (comment). |
IntroCurrent element-to-element upcast converter lacks simple, but powerful addition that would allow for a simpler upcast converters (check the example of editor.conversion.for( 'upcast' ).elementToElement( {
view: 'div',
model: ( viewElement, writer ) => {
return writer.createElement( 'div' );
}
} ); So we need to add whole OptionsOption 1: Backwards compatible editor.conversion.for( 'upcast' ).elementToElement( {
view: 'div',
model: ( viewElement, writer, conversionApi ) => {
// API usage
conversionApi.consumable.consume( viewElement );
// Ambigous writer usage:
return writer.createElement( 'div' ); // or
return conversionApi.writer.createElement( 'div' );
}
} ); Option 2: Backwards in-compatible // Using object destructuring:
editor.conversion.for( 'upcast' ).elementToElement( {
view: 'div',
model: ( viewElement, { writer, consumabe } ) => {
consumable.consume( viewElement );
return writer.createElement( 'div' );
}
} );
// Old-fashined objects:
editor.conversion.for( 'upcast' ).elementToElement( {
view: 'div',
model: ( viewElement, conversionApi ) => {
conversionApi.consumable.consume( viewElement );
return conversionApi.writer.createElement( 'div' );
}
} ); Pros & cons of optionsOption 1 (Backwards compatible):
Option 2 (Backwards in-compatible):
|
I'd see option 2 to be implemented, but backwards incompatibility and some additional work is need. |
I also like 2 the most. It's simple and future-proof (if more tools/steps arrive to the conversion pipeline). What I'm worried about, though, is the backwards compatibility issue. Upgrading to this editor version will certainly require some work if an integration brings its own editing plugins. That's a huge cost (although the migration path is simple). |
What do other callbacks (`view/model`) in other converters accept? If we change it here, we'll need to change it in other places as well. Does it make sense in all those examples? |
@Reinmar - as for now I see that we could unify upcast/downcast for element conversion: Downcast
Upcast
|
In the topic: #7774. |
I also vote for the option 2 for all of both upcast and downcast helpers. If we have a green light I can handle it. |
How about having Downcast
Upcast
OTOH, I don't see anything wrong with breaking change either. The change is cosmetic, people should be able to change their custom code easily. Hm. Now, as I look at it, I actually like having a breaking change more :D. BTW. Don't forget about markers conversion. We might want to have |
To sum up:
AFAICS, markers callbacks are similar, so adding |
The simplest upgrade path is to use Object destructuring for existing callbacks: Before: editor.conversion.for( 'downcast' ).attributeToElement( {
model: 'attribute',
view: ( attributeValue, writer ) => {
return writer.createAttributeElement( 'span', { style: 'color:blue' } );
}
} ); After: editor.conversion.for( 'downcast' ).attributeToElement( {
model: 'attribute',
view: ( attributeValue, { writer } ) => {
return writer.createAttributeElement( 'span', { style: 'color:blue' } );
}
} ); Or using variable name: editor.conversion.for( 'downcast' ).attributeToElement( {
model: 'attribute',
view: ( attributeValue, { writer: viewWriter } ) => {
return viewWriter.createAttributeElement( 'span', { style: 'color:blue' } );
}
} ); |
Feature (engine): Added conversion API to upcast and downcast helpers. Closes #7334. MAJOR BREAKING CHANGE (engine): `config.view` callback of `DowncastHelpers` takes `DowncastConversionApi` instead of `DowncastWriter`. See #7334. MAJOR BREAKING CHANGE (engine): `config.model` callback of `UpcastHelpers` takes `UpcastConversionApi` instead of `ModelWriter`. See #7334.
📝 Provide a description of the improvement
I'm writing an upcast converter that needs to consume all children of the element being converted to ensure that they are skipped.
I could use
for( 'upcast' ).elementToElement()
converter with a callback for themodel
property, but I don't have the access to the conversion API there. This detail forces me to write an event-based converter which is a pity.There may be more things that the higher-level converters could know about.
If you'd like to see this improvement implemented, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: