8
0
Quellcode durchsuchen

Fixed option name.

Maciej Bukowski vor 7 Jahren
Ursprung
Commit
f1030cc6f9

+ 6 - 6
packages/ckeditor5-widget/src/widgettoolbarrepository.js

@@ -27,7 +27,7 @@ import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  *
  *				widgetToolbarRepository.add( {
  *					toolbarItems: editor.config.get( 'image.toolbar' )
- *					whenVisible: isImageWidgetSelected
+ *					visibleWhen: isImageWidgetSelected
  *				} );
  *			}
  *		}
@@ -88,7 +88,7 @@ export default class WidgetToolbarRepository extends Plugin {
 
 	/**
 	 * Registers toolbar in the WidgetToolbarRepository. It renders it in the `ContextualBalloon` based on the value of the invoked
-	 * `whenVisible` function. Toolbar items are gathered from `toolbarItems` array.
+	 * `visibleWhen` function. Toolbar items are gathered from `toolbarItems` array.
 	 * The balloon's CSS class is by default `ck-toolbar-container` and may be override with the `balloonClassName` option.
 	 *
 	 * Note: This method should be called in the {@link module:core/plugin/Plugin~afterInit} to make sure that plugins for toolbar items
@@ -97,10 +97,10 @@ export default class WidgetToolbarRepository extends Plugin {
 	 * @param {String} toolbarId An id for the toolbar. Used to
 	 * @param {Object} options
 	 * @param {Array.<String>} options.toolbarItems Array of toolbar items.
-	 * @param {Function} options.whenVisible Callback which specifies when the toolbar should be visible for the widget.
+	 * @param {Function} options.visibleWhen Callback which specifies when the toolbar should be visible for the widget.
 	 * @param {String} [options.balloonClassName='ck-toolbar-container'] CSS class for the widget balloon.
 	 */
-	register( toolbarId, { toolbarItems, whenVisible, balloonClassName = 'ck-toolbar-container' } ) {
+	register( toolbarId, { toolbarItems, visibleWhen, balloonClassName = 'ck-toolbar-container' } ) {
 		const editor = this.editor;
 		const toolbarView = new ToolbarView();
 
@@ -118,7 +118,7 @@ export default class WidgetToolbarRepository extends Plugin {
 
 		this._toolbars.set( toolbarId, {
 			view: toolbarView,
-			whenVisible,
+			visibleWhen,
 			balloonClassName,
 		} );
 	}
@@ -161,7 +161,7 @@ export default class WidgetToolbarRepository extends Plugin {
 	 */
 	_updateToolbarsVisibility() {
 		for ( const toolbar of this._toolbars.values() ) {
-			if ( !this.editor.ui.focusTracker.isFocused || !toolbar.whenVisible( this.editor.editing.view.document.selection ) ) {
+			if ( !this.editor.ui.focusTracker.isFocused || !toolbar.visibleWhen( this.editor.editing.view.document.selection ) ) {
 				this._hideToolbar( toolbar );
 			} else {
 				this._showToolbar( toolbar );

+ 18 - 18
packages/ckeditor5-widget/tests/widgettoolbarrepository.js

@@ -60,7 +60,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should create a widget toolbar and add it to the collection', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: () => false,
+				visibleWhen: () => false,
 			} );
 
 			expect( widgetToolbarRepository._toolbars.size ).to.equal( 1 );
@@ -70,13 +70,13 @@ describe( 'WidgetToolbar', () => {
 		it( 'should throw when adding two times widget with the same id', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: () => false
+				visibleWhen: () => false
 			} );
 
 			expect( () => {
 				widgetToolbarRepository.register( 'fake', {
 					toolbarItems: editor.config.get( 'fake.toolbar' ),
-					whenVisible: () => false
+					visibleWhen: () => false
 				} );
 			} ).to.throw( CKEditorError, /^widget-toolbar-duplicated/ );
 		} );
@@ -86,7 +86,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should remove given widget toolbar', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: () => false
+				visibleWhen: () => false
 			} );
 
 			widgetToolbarRepository.deregister( 'fake' );
@@ -97,7 +97,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should throw an error if a toolbar does not exist', () => {
 			widgetToolbarRepository.register( 'foo', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: () => false
+				visibleWhen: () => false
 			} );
 
 			expect( () => {
@@ -110,7 +110,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should return `true` when a toolbar with given id was added', () => {
 			widgetToolbarRepository.register( 'foo', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: () => false
+				visibleWhen: () => false
 			} );
 
 			expect( widgetToolbarRepository.isRegistered( 'foo' ) ).to.be.true;
@@ -119,7 +119,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should return `false` when a toolbar with given id was not added', () => {
 			widgetToolbarRepository.register( 'foo', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: () => false
+				visibleWhen: () => false
 			} );
 
 			expect( widgetToolbarRepository.isRegistered( 'bar' ) ).to.be.false;
@@ -131,10 +131,10 @@ describe( 'WidgetToolbar', () => {
 			editor.ui.focusTracker.isFocused = true;
 		} );
 
-		it( 'toolbar should be visible when the `whenVisible` callback returns true', () => {
+		it( 'toolbar should be visible when the `visibleWhen` callback returns true', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: isFakeWidgetSelected
+				visibleWhen: isFakeWidgetSelected
 			} );
 
 			setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
@@ -144,10 +144,10 @@ describe( 'WidgetToolbar', () => {
 			expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
 		} );
 
-		it( 'toolbar should be hidden when the `whenVisible` callback returns false', () => {
+		it( 'toolbar should be hidden when the `visibleWhen` callback returns false', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: isFakeWidgetSelected
+				visibleWhen: isFakeWidgetSelected
 			} );
 
 			setData( model, '[<paragraph>foo</paragraph>]<fake-widget></fake-widget>' );
@@ -155,10 +155,10 @@ describe( 'WidgetToolbar', () => {
 			expect( balloon.visibleView ).to.equal( null );
 		} );
 
-		it( 'toolbar should be hidden when the `whenVisible` callback returns false #2', () => {
+		it( 'toolbar should be hidden when the `visibleWhen` callback returns false #2', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: isFakeWidgetSelected
+				visibleWhen: isFakeWidgetSelected
 			} );
 
 			setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
@@ -174,7 +174,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'toolbar should update its position when other widget is selected', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: isFakeWidgetSelected
+				visibleWhen: isFakeWidgetSelected
 			} );
 
 			setData( model, '[<fake-widget></fake-widget>]<fake-widget></fake-widget>' );
@@ -192,7 +192,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'it should be possible to create a widget toolbar for content inside the widget', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: isFakeWidgetContentSelected
+				visibleWhen: isFakeWidgetContentSelected
 			} );
 
 			setData( model, '<fake-widget>[foo]</fake-widget>' );
@@ -205,7 +205,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'toolbar should not engage when is in the balloon yet invisible', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				whenVisible: isFakeWidgetSelected
+				visibleWhen: isFakeWidgetSelected
 			} );
 
 			const fakeWidgetToolbarView = widgetToolbarRepository._toolbars.get( 'fake' ).view;
@@ -271,7 +271,7 @@ describe( 'WidgetToolbarRepository - integration with the BalloonToolbar', () =>
 	it( 'balloon toolbar should be hidden when the widget is selected', () => {
 		widgetToolbarRepository.register( 'fake', {
 			toolbarItems: editor.config.get( 'fake.toolbar' ),
-			whenVisible: isFakeWidgetSelected,
+			visibleWhen: isFakeWidgetSelected,
 		} );
 
 		const fakeWidgetToolbarView = widgetToolbarRepository._toolbars.get( 'fake' ).view;
@@ -286,7 +286,7 @@ describe( 'WidgetToolbarRepository - integration with the BalloonToolbar', () =>
 	it( 'balloon toolbar should be visible when the widget is not selected', () => {
 		widgetToolbarRepository.register( 'fake', {
 			toolbarItems: editor.config.get( 'fake.toolbar' ),
-			whenVisible: isFakeWidgetSelected
+			visibleWhen: isFakeWidgetSelected
 		} );
 
 		setData( model, '<fake-widget></fake-widget><paragraph>[foo]</paragraph>' );