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

Commit 9f9486d

Browse files
author
Piotr Jasiun
authored
Merge pull request #120 from ckeditor/t/113
Feature: Introduced toolbar for the table widget, changed the toolbar configuration option from `table.toolbar` to `table.contentToolbar`. Closes #113. Closes #106. Other: `config.table.toolbar` is marked as depracted. Use `config.table.contentToolbar` instead.
2 parents cd6f5ff + 80509c0 commit 9f9486d

File tree

9 files changed

+468
-210
lines changed

9 files changed

+468
-210
lines changed

docs/features/table.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar';
2727

2828
ClassicEditor
2929
.create( document.querySelector( '#editor' ), {
30-
plugins: [ Table, TableToolbar, ... ],
30+
plugins: [ Table, TableToolbar, Bold, ... ],
3131
toolbar: [ 'insertTable', ... ]
3232
table: {
33-
toolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
33+
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
3434
}
3535
} )
3636
.then( ... )
@@ -68,7 +68,9 @@ And the following commands:
6868
* The `'splitTableCellVertically'` command implemented by {@link module:table/commands/splitcellcommand~SplitCellCommand}.
6969
* The `'splitTableCellHorizontally'` command implemented by {@link module:table/commands/splitcellcommand~SplitCellCommand}.
7070

71-
The {@link module:table/tabletoolbar~TableToolbar} plugin introduces the balloon toolbar for tables. The toolbar shows up when a table cell is selected and is anchored to the table. It is possible to {@link module:table/table~TableConfig#toolbar configure} its content. Normally, it contains the table-related tools such as `'tableColumn'`, `'tableRow'`, and `'mergeTableCells'` dropdowns.
71+
The {@link module:table/tabletoolbar~TableToolbar} plugin introduces two balloon toolbars for tables.
72+
* The content toolbar shows up when table cell is selected and is anchored to the table. It is possible to {@link module:table/table~TableConfig#contentToolbar configure} its content. Normally, it contains the table-related tools such as `'tableColumn'`, `'tableRow'`, and `'mergeTableCells'` dropdowns.
73+
* The table toolbar shows up when the whole table is selected, for instance using the widget handler. It is possible to {@link module:table/table~TableConfig#tableToolbar configure} its content.
7274

7375
## Contribute
7476

src/tabletoolbar.js

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
*/
99

1010
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11-
import { isTableContentSelected } from './utils';
11+
import { isTableContentSelected, isTableWidgetSelected } from './utils';
1212
import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolbarrepository';
1313

1414
/**
15-
* The table toolbar class. It creates a table toolbar that shows up when the table content is selected.
15+
* The table toolbar class. It creates toolbars for the table feature and its content (for now only for a table cell content).
1616
*
17-
* Instances of toolbar components (e.g. buttons) are created using the editor's
18-
* {@link module:ui/componentfactory~ComponentFactory component factory}
19-
* based on the {@link module:table/table~TableConfig#toolbar `table.toolbar` configuration option}.
17+
* Table toolbar shows up when a table widget is selected. Its components (e.g. buttons) are created based on the
18+
* {@link module:table/table~TableConfig#toolbar `table.tableToolbar` configuration option}.
2019
*
21-
* The toolbar uses the {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon} plugin.
20+
* Table content toolbar shows up when the selection is inside the content of a table. It creates its component based on the
21+
* {@link module:table/table~TableConfig#contentToolbar `table.contentToolbar` configuration option}.
22+
*
23+
* Note that the old {@link module:table/table~TableConfig#toolbar `table.toolbar` configuration option} is deprecated
24+
* and will be removed in the next major release.
2225
*
2326
* @extends module:core/plugin~Plugin
2427
*/
@@ -44,16 +47,49 @@ export default class TableToolbar extends Plugin {
4447
const editor = this.editor;
4548
const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
4649

47-
widgetToolbarRepository.register( 'table', {
48-
items: editor.config.get( 'table.toolbar' ) || [],
49-
visibleWhen: isTableContentSelected,
50-
} );
50+
const tableContentToolbarItems = editor.config.get( 'table.contentToolbar' );
51+
const deprecatedTableContentToolbarItems = editor.config.get( 'table.toolbar' );
52+
53+
const tableToolbarItems = editor.config.get( 'table.tableToolbar' );
54+
55+
if ( deprecatedTableContentToolbarItems ) {
56+
// eslint-disable-next-line
57+
console.warn(
58+
'`config.table.toolbar` is deprecated and will be removed in the next major release.' +
59+
' Use `config.table.contentToolbar` instead.'
60+
);
61+
}
62+
63+
if ( tableContentToolbarItems || deprecatedTableContentToolbarItems ) {
64+
widgetToolbarRepository.register( 'tableContent', {
65+
items: tableContentToolbarItems || deprecatedTableContentToolbarItems,
66+
visibleWhen: isTableContentSelected,
67+
} );
68+
}
69+
70+
if ( tableToolbarItems ) {
71+
widgetToolbarRepository.register( 'table', {
72+
items: tableToolbarItems,
73+
visibleWhen: isTableWidgetSelected,
74+
} );
75+
}
5176
}
5277
}
5378

5479
/**
55-
* Items to be placed in the table toolbar.
56-
* This option is used by the {@link module:table/tabletoolbar~TableToolbar} feature.
80+
* Items to be placed in the table content toolbar.
81+
*
82+
* **Note:** This is a deprecated configuration option! Use {@link module:table/table~TableConfig#contentToolbar} instead.
83+
*
84+
* Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
85+
*
86+
* @deprecated
87+
* @member {Array.<String>} module:table/table~TableConfig#toolbar
88+
*/
89+
90+
/**
91+
* Items to be placed in the table content toolbar.
92+
* The {@link module:table/tabletoolbar~TableToolbar} plugin is required to make this toolbar working.
5793
*
5894
* Assuming that you use the {@link module:table/tableui~TableUI} feature, the following toolbar items will be available
5995
* in {@link module:ui/componentfactory~ComponentFactory}:
@@ -65,13 +101,31 @@ export default class TableToolbar extends Plugin {
65101
* You can thus configure the toolbar like this:
66102
*
67103
* const tableConfig = {
68-
* toolbar: [ 'tableRow', 'tableColumn', 'mergeTableCells' ]
104+
* contentToolbar: [ 'tableRow', 'tableColumn', 'mergeTableCells' ]
69105
* };
70106
*
71107
* Of course, the same buttons can also be used in the
72108
* {@link module:core/editor/editorconfig~EditorConfig#toolbar main editor toolbar}.
73109
*
74110
* Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
75111
*
76-
* @member {Array.<String>} module:table/table~TableConfig#toolbar
112+
* @member {Array.<String>} module:table/table~TableConfig#contentToolbar
113+
*/
114+
115+
/**
116+
* Items to be placed in the table toolbar.
117+
* The {@link module:table/tabletoolbar~TableToolbar} plugin is required to make this toolbar working.
118+
*
119+
* You can thus configure the toolbar like this:
120+
*
121+
* const tableConfig = {
122+
* tableToolbar: [ 'blockQuote' ]
123+
* };
124+
*
125+
* Of course, the same buttons can also be used in the
126+
* {@link module:core/editor/editorconfig~EditorConfig#toolbar main editor toolbar}.
127+
*
128+
* Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
129+
*
130+
* @member {Array.<String>} module:table/table~TableConfig#tableToolbar
77131
*/

src/ui/utils.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/integration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Table from '../src/table';
1212
import TableToolbar from '../src/tabletoolbar';
1313
import View from '@ckeditor/ckeditor5-ui/src/view';
1414

15-
describe( 'TableToolbar integration', () => {
15+
describe( 'TableContentToolbar integration', () => {
1616
describe( 'with the BalloonToolbar', () => {
1717
let balloon, balloonToolbar, newEditor, editorElement;
1818

tests/manual/table.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ ClassicEditor
1717
'heading', '|', 'insertTable', '|', 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
1818
],
1919
table: {
20-
toolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
20+
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ],
21+
tableToolbar: [ 'bold', 'italic' ]
2122
}
2223
} )
2324
.then( editor => {

tests/manual/table.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
1. The data should be loaded with:
44
* a complex table with:
5-
- one heading row,
6-
- two heading columns,
5+
- one heading row,
6+
- two heading columns,
77
- merged cells in heading columns section,
88
* a table with 2 tbody sections in the DOM - should be rendered as a table with one tbody.
99
* a table with no tbody sections in the DOM - should be rendered as a table with one tbody.
1010
* a table with a thead section between two tbody sections in dom - should be rendered as a table with one thead and on tbody section in proper order: 1, 2, 3.
1111

1212
2. Main toolbar should have insert table dropdown.
13-
14-
3. While the table widget is selected there should be a toolbar attached to the table with 3 dropdowns:
13+
14+
3. While the table cell is selected there should be a toolbar attached to the table with 3 dropdowns:
1515
* column dropdown with items:
1616
- header column,
1717
- insert column before,
@@ -30,6 +30,8 @@
3030
- split cell vertically,
3131
- split cell horizontally,
3232

33+
4. While the table widget is selected there should be `bold` and `italic` buttons
34+
3335
### Testing
3436

3537
Inserting table:

tests/manual/tableblockcontent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ClassicEditor
1919
'alignment', '|', 'undo', 'redo'
2020
],
2121
table: {
22-
toolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
22+
contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
2323
}
2424
} )
2525
.then( editor => {

tests/manual/tableblockcontent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
### Testing
1515

16-
1. Use <kbd>Enter</kbd> in cells with single `<pargraph>`. When two `<paragraph>`'s are in one table cell they should be rendered as `<p>`.
16+
1. Use <kbd>Enter</kbd> in cells with single `<paragraph>`. When two `<paragraph>`'s are in one table cell they should be rendered as `<p>`.
1717
2. Undo previous step - the `<p>` element should be changed to `<span>` for single paragraph.
1818
3. Change `<heading>` to paragraph - it should be rendered as `<p>` element if there are other headings or other block content.
19-
4. Change one `<heading>` to paragraph and remove other headings. The `<paragraph>` should be rendered as `<span>`.
19+
4. Change one `<heading>` to paragraph and remove other headings. The `<paragraph>` should be rendered as `<span>`.

0 commit comments

Comments
 (0)