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

Commit

Permalink
Other: Removed deprecated config.table.toolbar configuration option…
Browse files Browse the repository at this point in the history
…. Closes #167.

BREAKING CHANGE: `config.table.toolbar` is now removed from code. Use `config.table.contentToolbar`instead.
  • Loading branch information
mlewand authored May 20, 2019
2 parents 900c178 + d64c087 commit 5d024ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 106 deletions.
29 changes: 3 additions & 26 deletions src/tabletoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ import WidgetToolbarRepository from '@ckeditor/ckeditor5-widget/src/widgettoolba
* The table toolbar class. It creates toolbars for the table feature and its content (for now only for a table cell content).
*
* Table toolbar shows up when a table widget is selected. Its components (e.g. buttons) are created based on the
* {@link module:table/table~TableConfig#toolbar `table.tableToolbar` configuration option}.
* {@link module:table/table~TableConfig#tableToolbar `table.tableToolbar` configuration option}.
*
* Table content toolbar shows up when the selection is inside the content of a table. It creates its component based on the
* {@link module:table/table~TableConfig#contentToolbar `table.contentToolbar` configuration option}.
*
* Note that the old {@link module:table/table~TableConfig#toolbar `table.toolbar` configuration option} is deprecated
* and will be removed in the next major release.
*
* @extends module:core/plugin~Plugin
*/
export default class TableToolbar extends Plugin {
Expand All @@ -48,21 +45,12 @@ export default class TableToolbar extends Plugin {
const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );

const tableContentToolbarItems = editor.config.get( 'table.contentToolbar' );
const deprecatedTableContentToolbarItems = editor.config.get( 'table.toolbar' );

const tableToolbarItems = editor.config.get( 'table.tableToolbar' );

if ( deprecatedTableContentToolbarItems ) {
// eslint-disable-next-line
console.warn(
'`config.table.toolbar` is deprecated and will be removed in the next major release.' +
' Use `config.table.contentToolbar` instead.'
);
}

if ( tableContentToolbarItems || deprecatedTableContentToolbarItems ) {
if ( tableContentToolbarItems ) {
widgetToolbarRepository.register( 'tableContent', {
items: tableContentToolbarItems || deprecatedTableContentToolbarItems,
items: tableContentToolbarItems,
getRelatedElement: getTableWidgetAncestor
} );
}
Expand All @@ -76,17 +64,6 @@ export default class TableToolbar extends Plugin {
}
}

/**
* Items to be placed in the table content toolbar.
*
* **Note:** This configuration option is deprecated! Use {@link module:table/table~TableConfig#contentToolbar} instead.
*
* Read more about configuring toolbar in {@link module:core/editor/editorconfig~EditorConfig#toolbar}.
*
* @deprecated
* @member {Array.<String>} module:table/table~TableConfig#toolbar
*/

/**
* Items to be placed in the table content toolbar.
* The {@link module:table/tabletoolbar~TableToolbar} plugin is required to make this toolbar working.
Expand Down
82 changes: 2 additions & 80 deletions tests/tabletoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* global document, window */
/* global document */

import ClassicTestEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import TableToolbar from '../src/tabletoolbar';
Expand Down Expand Up @@ -77,7 +77,7 @@ describe( 'TableToolbar', () => {
} );

describe( 'toolbar', () => {
it( 'should use the config.table.toolbar to create items', () => {
it( 'should use the config.table.contenToolbar to create items', () => {
expect( toolbar.items ).to.have.length( 1 );
expect( toolbar.items.get( 0 ).label ).to.equal( 'fake button' );
} );
Expand Down Expand Up @@ -238,69 +238,6 @@ describe( 'TableToolbar', () => {
} );
} );

describe( 'deprecated toolbar', () => {
let editor, editorElement, warnMock;

it( 'table.toolbar should work as table.contentToolbar', () => {
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );
warnMock = sinon.stub( window.console, 'warn' );

return ClassicTestEditor
.create( editorElement, {
plugins: [ Paragraph, Table, TableToolbar, FakeButton ],
table: {
toolbar: [ 'fake_button' ]
}
} )
.then( newEditor => {
editor = newEditor;

const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
const toolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'tableContent' ).view;

expect( toolbarView.items ).to.have.length( 1 );
expect( toolbarView.items.get( 0 ).label ).to.equal( 'fake button' );

sinon.assert.calledWith(
warnMock,
'`config.table.toolbar` is deprecated and will be removed in the next major release.' +
' Use `config.table.contentToolbar` instead.'
);
} );
} );

it( 'table.contentToolbar should be used if both toolbars options are provided', () => {
editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );
warnMock = sinon.stub( window.console, 'warn' );

return ClassicTestEditor
.create( editorElement, {
plugins: [ Paragraph, Table, TableToolbar, FakeButton, FooButton ],
table: {
toolbar: [ 'fake_button' ],
contentToolbar: [ 'foo_button' ],
}
} )
.then( newEditor => {
editor = newEditor;

const widgetToolbarRepository = editor.plugins.get( WidgetToolbarRepository );
const toolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'tableContent' ).view;

expect( toolbarView.items ).to.have.length( 1 );
expect( toolbarView.items.get( 0 ).label ).to.equal( 'foo button' );
} );
} );

afterEach( () => {
editorElement.remove();

return editor.destroy();
} );
} );

describe( 'tableToolbar', () => {
let editor, element, widgetToolbarRepository, balloon, toolbar, model;

Expand Down Expand Up @@ -482,18 +419,3 @@ class FakeButton extends Plugin {
} );
}
}

// Plugin that adds foo_button to editor's component factory.
class FooButton extends Plugin {
init() {
this.editor.ui.componentFactory.add( 'foo_button', locale => {
const view = new ButtonView( locale );

view.set( {
label: 'foo button'
} );

return view;
} );
}
}

0 comments on commit 5d024ce

Please sign in to comment.