Skip to content
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

Support for default table (and cells) properties #9393

Closed
wants to merge 26 commits into from
Closed

Support for default table (and cells) properties #9393

wants to merge 26 commits into from

Conversation

pomek
Copy link
Member

@pomek pomek commented Mar 31, 2021

Suggested merge commit message (convention)

Feature (table): The TablePropertiesEditing plugin allows specifying default properties for the new inserted tables. Closes #8502. Closes #9219.

Feature (table): The TableCellPropertiesEditing plugin allows specifying default properties of all cells when inserting the new table.

Other (table): The TableUtils#createTable() is now decorated and fires an event when executing the function. Read more about decorating object methods.

Other (table): The TableUtils#insertRows() and TableUtils#insertColumns() returns an array that contains the created model elements.

@Mgsy
Copy link
Member

Mgsy commented Mar 31, 2021

PR is ready for testing @ckeditor/qa-team.

@FilipTokarski
Copy link
Member

Looks ok 👍

@jacekbogdanski jacekbogdanski self-requested a review April 1, 2021 10:42
packages/ckeditor5-table/src/tableutils.js Outdated Show resolved Hide resolved
packages/ckeditor5-table/src/tableutils.js Outdated Show resolved Hide resolved
packages/ckeditor5-table/src/tableutils.js Outdated Show resolved Hide resolved
packages/ckeditor5-table/docs/features/table.md Outdated Show resolved Hide resolved
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting some error when merging cells with default properties:

Screen.Recording.2021-04-06.at.14.42.19.mov

packages/ckeditor5-table/tests/_utils/utils.js Outdated Show resolved Hide resolved
@pomek
Copy link
Member Author

pomek commented Apr 8, 2021

Today we discussed another approach to have default table/cell properties. Instead of modifying the current commands, let's try to decorate them and apply the properties.

@pomek
Copy link
Member Author

pomek commented Apr 8, 2021

Problem to solve: single undo step after creating a table with applied styles. As for now, we have three steps:

  1. created table
  2. applied table properties
  3. applied cell properties

@pomek
Copy link
Member Author

pomek commented Apr 9, 2021

I'm getting some error when merging cells with default properties:

After redesigning the feature to decorate commands/plugins, the error does not occur anymore.

@pomek pomek requested a review from niegowski April 9, 2021 14:59
@pomek
Copy link
Member Author

pomek commented Apr 9, 2021

The PR is ready for review once again.

Now, the proposed solution uses decorated methods from the TableUtils plugin. Thanks to that, table commands do not have to know about table/cell properties. The TableProperties and TableCellProperties listen to proper events and modify the table before inserting it into the document.

Splitting a column does not inherit "the parent" properties but it should be resolved in another issue – #7246.

cc: @niegowski

Copy link
Contributor

@niegowski niegowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented below.

@@ -78,6 +78,10 @@ export default class InsertColumnCommand extends Command {
const column = insertBefore ? columnIndexes.first : columnIndexes.last;
const table = affectedTableCells[ 0 ].findAncestor( 'table' );

tableUtils.insertColumns( table, { columns: 1, at: insertBefore ? column : column + 1 } );
// The `TableUtils` plugin fires the `#insertColumns` event. In order to having a single undo step,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The `TableUtils` plugin fires the `#insertColumns` event. In order to having a single undo step,
// The `TableUtils` plugin fires the `#insertColumns` event. In order to have a single undo step,

@@ -77,6 +77,10 @@ export default class InsertRowCommand extends Command {
const row = insertAbove ? rowIndexes.first : rowIndexes.last;
const table = affectedTableCells[ 0 ].findAncestor( 'table' );

tableUtils.insertRows( table, { at: insertAbove ? row : row + 1, copyStructureFromAbove: !insertAbove } );
// The `TableUtils` plugin fires the `#insertRows` event. In order to having a single undo step,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The `TableUtils` plugin fires the `#insertRows` event. In order to having a single undo step,
// The `TableUtils` plugin fires the `#insertRows` event. In order to have a single undo step,

Comment on lines +108 to +112
this.listenTo( tableUtils, 'createTable', ( evt, [ writer ] ) => {
const tableElement = evt.return;

writer.setAttributes( tableProperties, tableElement );
}, { priority: 'low' } );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.listenTo( tableUtils, 'createTable', ( evt, [ writer ] ) => {
const tableElement = evt.return;
writer.setAttributes( tableProperties, tableElement );
}, { priority: 'low' } );
this.listenTo( tableUtils, 'createTable', evt => {
const tableElement = evt.return;
editor.model.change( writer => {
writer.setAttributes( tableProperties, tableElement );
} );
}, { priority: 'low' } );

Let's not use the writer from the event data.


this._enableDefaultCellProperties();

injectTableCellDefaultPropertiesPostFixer( editor );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not pass the whole editor, we should pass only needed parameters, in this case, I would pass the model instance and the default cell attributes object.

const tableUtils = editor.plugins.get( TableUtils );

// Apply default cell properties while creating a new table.
this.listenTo( tableUtils, 'createTable', ( evt, [ writer ] ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use the writer from the event's data. We should have here a change block.

@@ -14,14 +14,15 @@ import TableSelection from '../../src/tableselection';
import { assertSelectedCells, modelTable } from '../_utils/utils';

import InsertRowCommand from '../../src/commands/insertrowcommand';
import { UndoEditing } from '@ckeditor/ckeditor5-undo';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the order of imports.

@@ -308,6 +309,44 @@ describe( 'InsertRowCommand', () => {
[ '10', '11', '12' ]
] ) );
} );

it( 'should create a single undo step when inserting a column', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it( 'should create a single undo step when inserting a column', () => {
it( 'should create a single undo step when inserting a row', () => {

Comment on lines +12 to +13
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the order of imports.

Comment on lines +22 to +26
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
import { assertTableCellStyle, assertTRBLAttribute } from '../_utils/utils';
import { assertTableCellStyle, assertTRBLAttribute, modelTable } from '../_utils/utils';
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
import TableUtils from '../../src/tableutils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the order of imports.

Comment on lines 20 to +24
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
import { assertTableStyle, assertTRBLAttribute } from '../_utils/utils';
import { assertTableStyle, assertTRBLAttribute, modelTable } from '../_utils/utils';
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
import TableUtils from '../../src/tableutils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the order of imports.

@pomek
Copy link
Member Author

pomek commented Apr 21, 2021

See: #8502 (comment).

@pomek
Copy link
Member Author

pomek commented Apr 30, 2021

Closing in favor of #9555.

@pomek pomek closed this Apr 30, 2021
@pomek pomek deleted the i/8502 branch April 30, 2021 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default table properties via configuration No way to set default alignment for images or tables.
5 participants