Преглед на файлове

Changed isVisible to whenVisible.

Maciej Bukowski преди 7 години
родител
ревизия
d0b91afa20
променени са 2 файла, в които са добавени 24 реда и са изтрити 24 реда
  1. 6 6
      packages/ckeditor5-widget/src/widgettoolbarrepository.js
  2. 18 18
      packages/ckeditor5-widget/tests/widgettoolbarrepository.js

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

@@ -26,7 +26,7 @@ import { isWidget } from './utils';
  *
  *				widgetToolbarRepository.add( {
  *					toolbarItems: editor.config.get( 'image.toolbar' )
- *					isVisible: isImageWidgetSelected
+ *					whenVisible: isImageWidgetSelected
  *				} );
  *			}
  *		}
@@ -87,7 +87,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
-	 * `isVisible` function. Toolbar items are gathered from `toolbarItems` array.
+	 * `whenVisible` 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
@@ -96,10 +96,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.isVisible Callback which specifies when the toolbar should be visible for the widget.
+	 * @param {Function} options.whenVisible 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, isVisible, balloonClassName = 'ck-toolbar-container' } ) {
+	register( toolbarId, { toolbarItems, whenVisible, balloonClassName = 'ck-toolbar-container' } ) {
 		const editor = this.editor;
 		const toolbarView = new ToolbarView();
 
@@ -117,7 +117,7 @@ export default class WidgetToolbarRepository extends Plugin {
 
 		this._toolbars.set( toolbarId, {
 			view: toolbarView,
-			isVisible,
+			whenVisible,
 			balloonClassName,
 		} );
 	}
@@ -160,7 +160,7 @@ export default class WidgetToolbarRepository extends Plugin {
 	 */
 	_updateToolbarsVisibility() {
 		for ( const toolbar of this._toolbars.values() ) {
-			if ( !this.editor.ui.focusTracker.isFocused || !toolbar.isVisible( this.editor.editing.view.document.selection ) ) {
+			if ( !this.editor.ui.focusTracker.isFocused || !toolbar.whenVisible( this.editor.editing.view.document.selection ) ) {
 				this._hideToolbar( toolbar );
 			} else {
 				this._showToolbar( toolbar );

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

@@ -59,7 +59,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should create a widget toolbar and add it to the collection', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: () => false,
+				whenVisible: () => false,
 			} );
 
 			expect( widgetToolbarRepository._toolbars.size ).to.equal( 1 );
@@ -69,13 +69,13 @@ describe( 'WidgetToolbar', () => {
 		it( 'should throw when adding two times widget with the same id', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: () => false
+				whenVisible: () => false
 			} );
 
 			expect( () => {
 				widgetToolbarRepository.register( 'fake', {
 					toolbarItems: editor.config.get( 'fake.toolbar' ),
-					isVisible: () => false
+					whenVisible: () => false
 				} );
 			} ).to.throw( /widget-toolbar-duplicated/ );
 		} );
@@ -85,7 +85,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should remove given widget toolbar', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: () => false
+				whenVisible: () => false
 			} );
 
 			widgetToolbarRepository.deregister( 'fake' );
@@ -96,7 +96,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should throw an error if a toolbar does not exist', () => {
 			widgetToolbarRepository.register( 'foo', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: () => false
+				whenVisible: () => false
 			} );
 
 			expect( () => {
@@ -109,7 +109,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'should return `true` when a toolbar with given id was added', () => {
 			widgetToolbarRepository.register( 'foo', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: () => false
+				whenVisible: () => false
 			} );
 
 			expect( widgetToolbarRepository.isRegistered( 'foo' ) ).to.be.true;
@@ -118,7 +118,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' ),
-				isVisible: () => false
+				whenVisible: () => false
 			} );
 
 			expect( widgetToolbarRepository.isRegistered( 'bar' ) ).to.be.false;
@@ -130,10 +130,10 @@ describe( 'WidgetToolbar', () => {
 			editor.ui.focusTracker.isFocused = true;
 		} );
 
-		it( 'toolbar should be visible when the `isVisible` callback returns true', () => {
+		it( 'toolbar should be visible when the `whenVisible` callback returns true', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: isFakeWidgetSelected
+				whenVisible: isFakeWidgetSelected
 			} );
 
 			setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
@@ -143,10 +143,10 @@ describe( 'WidgetToolbar', () => {
 			expect( balloon.visibleView ).to.equal( fakeWidgetToolbarView );
 		} );
 
-		it( 'toolbar should be hidden when the `isVisible` callback returns false', () => {
+		it( 'toolbar should be hidden when the `whenVisible` callback returns false', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: isFakeWidgetSelected
+				whenVisible: isFakeWidgetSelected
 			} );
 
 			setData( model, '[<paragraph>foo</paragraph>]<fake-widget></fake-widget>' );
@@ -154,10 +154,10 @@ describe( 'WidgetToolbar', () => {
 			expect( balloon.visibleView ).to.equal( null );
 		} );
 
-		it( 'toolbar should be hidden when the `isVisible` callback returns false #2', () => {
+		it( 'toolbar should be hidden when the `whenVisible` callback returns false #2', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: isFakeWidgetSelected
+				whenVisible: isFakeWidgetSelected
 			} );
 
 			setData( model, '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' );
@@ -173,7 +173,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'toolbar should update its position when other widget is selected', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: isFakeWidgetSelected
+				whenVisible: isFakeWidgetSelected
 			} );
 
 			setData( model, '[<fake-widget></fake-widget>]<fake-widget></fake-widget>' );
@@ -191,7 +191,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' ),
-				isVisible: isFakeWidgetContentSelected
+				whenVisible: isFakeWidgetContentSelected
 			} );
 
 			setData( model, '<fake-widget>[foo]</fake-widget>' );
@@ -204,7 +204,7 @@ describe( 'WidgetToolbar', () => {
 		it( 'toolbar should not engage when is in the balloon yet invisible', () => {
 			widgetToolbarRepository.register( 'fake', {
 				toolbarItems: editor.config.get( 'fake.toolbar' ),
-				isVisible: isFakeWidgetSelected
+				whenVisible: isFakeWidgetSelected
 			} );
 
 			const fakeWidgetToolbarView = widgetToolbarRepository._toolbars.get( 'fake' ).view;
@@ -270,7 +270,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' ),
-			isVisible: isFakeWidgetSelected,
+			whenVisible: isFakeWidgetSelected,
 		} );
 
 		const fakeWidgetToolbarView = widgetToolbarRepository._toolbars.get( 'fake' ).view;
@@ -285,7 +285,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' ),
-			isVisible: isFakeWidgetSelected
+			whenVisible: isFakeWidgetSelected
 		} );
 
 		setData( model, '<fake-widget></fake-widget><paragraph>[foo]</paragraph>' );