-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
upcastStyleToAttribute() helper is called in wrong context #9536
Comments
After changing the conversion to event-based, everything works as I expected: export function upcastStyleToAttribute( conversion, options ) {
const {
viewElementName,
modelAttribute,
styleName,
defaultValue
} = options;
conversion.for( 'upcast' ).add( dispatcher => dispatcher.on( 'element:' + viewElementName, ( evt, data, conversionApi ) => {
if ( !data.modelRange ) {
return;
}
if ( !data.viewItem.hasStyle( styleName ) ) {
return;
}
const matcherPattern = {
styles: [ styleName ]
};
// Try to consume appropriate values from consumable values list.
if ( !conversionApi.consumable.test( data.viewItem, matcherPattern ) ) {
return;
}
const modelElement = [ ...data.modelRange.getItems( { shallow: true } ) ].pop();
const value = data.viewItem.getNormalizedStyle( styleName );
conversionApi.consumable.consume( data.viewItem, matcherPattern );
if ( value !== defaultValue ) {
conversionApi.writer.setAttribute( modelAttribute, value, modelElement );
}
} ) );
} |
The event-based conversion resolves my case, but it does not fix the issue. Please, look at the code: ckeditor5/packages/ckeditor5-engine/src/conversion/upcasthelpers.js Lines 871 to 878 in 41bf7a3
Moving the above code below ckeditor5/packages/ckeditor5-engine/src/conversion/upcasthelpers.js Lines 871 to 890 in 41bf7a3
|
Feature (table): Support for the default table properties. Read more about [the feature in the documentation](https://ckeditor.com/docs/ckeditor5/latest/features/table.html). Closes #8502. Closes #9219. Fix (engine): The conversion upcast `elementToAttribute()` and `attributeToAttribute()` functions should not call the `model.value()` callback if the element will not be converted. Closes #9536. MINOR BREAKING CHANGE (table): Clases `TableAlignmentCommand`, `TableBackgroundColorCommand`, `TableBorderColorCommand`, `TableBorderStyleCommand`, `TableBorderWidthCommand`, `TableHeightCommand`, `TablePropertyCommand`, `TableWidthCommand` requires the second argument called `defaultValue` which is the default value for the command. MINOR BREAKING CHANGE (table): The `TablePropertiesView` class requires additional property in the object as the second constructor argument (`options.defaultTableProperties`).
📝 Provide detailed reproduction steps (if any)
ckeditor5/packages/ckeditor5-table/src/converters/tableproperties.js
Lines 10 to 37 in 2eb5c73
Replace the
model.value
function with the snippet:Then, open the table properties manual test and set the editor data with the following table:
The helper function is used for upcasting all table and table cell properties. I'd like to focus on a single property, e.g. "width".
✔️ Expected result
I'd expect two logs for the
width
property.{viewElementName: "td", modelElementToSet: "tableCell", modelAttributeToSet: "width", attributeValue: "100px"}
{viewElementName: "table", modelElementToSet: "table", modelAttributeToSet: "width", attributeValue: "300px"}
These logs are displayed in proper context: when upcasting the
table
(view) element, set thetable
(model) element. When upcasting thetd
(view) element, set the thetableCell
(model) element.Combinations (view->model):
td->table
andtable->tableCell
are invalid and should not be logged.❌ Actual result
"width" property
Full log
📃 Other details
While working on the default table properties, I wanted to disallow upcasting properties if their values are equal to default properties specified in the editor configuration.
So, I passed the default value for each property and updated the
console.log
:Input data:
Just a single table cell. And filtred console.logs calls (only
width
property is displayed):The main question is – why the converter was called for the
tableCell
element if the input data does not contain any "style" attribute?If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: