Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/9: Table feature #10

Merged
merged 136 commits into from
May 29, 2018
Merged

T/9: Table feature #10

merged 136 commits into from
May 29, 2018

Conversation

jodator
Copy link
Contributor

@jodator jodator commented May 10, 2018

Suggested merge commit message (convention)

Feature: Initial table support. Closes ckeditor/ckeditor5#3162, Closes ckeditor/ckeditor5#3165, Closes ckeditor/ckeditor5#3166.


Additional information

Based on @Reinmar's input I've updated the code from #6 and this PR introduces:

  • The upcast/downcast conversion.
  • Table as a widget with table cells as nested editables.
  • Full colspan and rowspan attributes handling.
  • Full commands implementation.
  • Arbitrary table headers rows/columns.

What this PR does not cover from MVP (ckeditor/ckeditor5#3163):

  • table styles
  • UI
  • the <p> inside table cell thingy
  • clipboad, copy-paste, etc
  • probably collaboration will break something
  • no caption

I think that there might be some small issues with commands - resulting in broken table in some situations (mostly related to rowspan/colspan) but those might be fixed after we start doing UI since using commands from console is not ideal.

@jodator
Copy link
Contributor Author

jodator commented May 23, 2018

@scofalik & @Reinmar I think that the code is ready to another review. I've tried to address most of the issues from the PR comments.

I do not touch splitCell things and other commands as they should work with Milestone 1 UI for now.

@Reinmar
Copy link
Member

Reinmar commented May 28, 2018

Why are tableRow and tableCell marked as isBlock? Was it necessary for some reason?

* @param {module:utils/eventinfo~EventInfo} eventInfo
* @param {module:engine/view/observer/domeventdata~DomEventData} domEventData
*/
_handleTabOnSelectedTable( eventInfo, domEventData ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS, Shift + Tab moves selection to the first cell as well. How about moving it to the last cell in that case? Then, you could traverse the table from the end using Shift + Tab. Looks to me like this could make some sense.

Copy link
Contributor Author

@jodator jodator May 28, 2018

Choose a reason for hiding this comment

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

@jodator
Copy link
Contributor Author

jodator commented May 28, 2018

Why are tableRow and tableCell marked as isBlock? Was it necessary for some reason

Probably it is not necessary - I've removed them and it looks like it works OK without isBlock = true.

const tableWalker = new TableWalker( table );

const tableAttributes = {
headingRows: parseInt( table.getAttribute( 'headingRows' ) || 0 ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is parseInt really needed here? Aren't attributes in model already numbers (or undefined)?

Copy link
Contributor Author

@jodator jodator May 28, 2018

Choose a reason for hiding this comment

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

Weren't there some problems with strings? I don't recall how it was working but I've managed to have colspan or other attributes as: "11111" in some places.

Copy link
Contributor

@scofalik scofalik May 28, 2018

Choose a reason for hiding this comment

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

That was probably in upcast. In DOM (and then probably also in the view) attributes are strings. Amirite?

In the model, attributes stay as set. You can even add objects as attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using a default converters here so the values are strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I've fixed this for headingRows & headingColumns - so table attributes. The colspan and rowspan parsing must use parseInt() for now.

headingColumns: parseInt( table.getAttribute( 'headingColumns' ) || 0 )
};

// We need to iterate over a table in order to get proper row & column values from a walker
Copy link
Contributor

@scofalik scofalik May 28, 2018

Choose a reason for hiding this comment

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

Can't we start iterating from the proper row already (get the row index straight from the model: data.item.parent.index)? Isn't it that rows are set even if there are rowspans?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, adding startRow & endRow will do the trick but anyway the tableWalkerValue is needed to properly calculate if this table cell is in heading section so the tableWalker is still required.

}

// Upcast table rows in proper order (heading rows first).
rows.forEach( row => conversionApi.convertItem( row, ModelPosition.createAt( table, 'end' ) ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that this will not do anything if rows.length == 0 but I'd put it into else for clarity reasons.

@jodator
Copy link
Contributor Author

jodator commented May 29, 2018

@Reinmar I think this PR is good to merge now. @scofalik AFAIK has no more issues then already reported as follow ups.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement table commands Table widget & table navigation Minimal table support
3 participants