Przeglądaj źródła

Added: Introduce `bindOneToMany()` binding helper.

Maciej Gołaszewski 8 lat temu
rodzic
commit
2e95fc5670
1 zmienionych plików z 9 dodań i 14 usunięć
  1. 9 14
      packages/ckeditor5-heading/src/heading.js

+ 9 - 14
packages/ckeditor5-heading/src/heading.js

@@ -12,9 +12,8 @@ import HeadingEngine from './headingengine';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import Model from '@ckeditor/ckeditor5-ui/src/model';
 import Model from '@ckeditor/ckeditor5-ui/src/model';
 
 
-import getBindingTargets from '@ckeditor/ckeditor5-ui/src/bindings/getbindingtargets';
+import bindOneToMany from '@ckeditor/ckeditor5-ui/src/bindings/bindonetomany';
 import addListViewToDropdown from '@ckeditor/ckeditor5-ui/src/dropdown/helpers/addlistviewtodropdown';
 import addListViewToDropdown from '@ckeditor/ckeditor5-ui/src/dropdown/helpers/addlistviewtodropdown';
-import enableModelIfOneIsEnabled from '@ckeditor/ckeditor5-ui/src/dropdown/helpers/enablemodelifoneisenabled';
 import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
 import { createDropdown } from '@ckeditor/ckeditor5-ui/src/dropdown/utils';
 
 
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
@@ -79,20 +78,16 @@ export default class Heading extends Plugin {
 			tooltip: dropdownTooltip
 			tooltip: dropdownTooltip
 		} );
 		} );
 
 
-		enableModelIfOneIsEnabled( dropdownModel, commands );
+		bindOneToMany( dropdownModel, 'isEnabled', commands, 'isEnabled', ( ...areEnabled ) => {
+			return areEnabled.some( isEnabled => isEnabled );
+		} );
 
 
-		// TODO: might be unified as above but require a callback
-		dropdownModel.bind( 'label' ).to(
-			// Bind to #value of each command...
-			...getBindingTargets( commands, 'value' ),
-			// ...and chose the title of the first one which #value is true.
-			( ...areActive ) => {
-				const index = areActive.findIndex( value => value );
+		bindOneToMany( dropdownModel, 'label', commands, 'value', ( ...areActive ) => {
+			const index = areActive.findIndex( value => value );
 
 
-				// If none of the commands is active, display default title.
-				return options[ index ] ? options[ index ].title : defaultTitle;
-			}
-		);
+			// If none of the commands is active, display default title.
+			return options[ index ] ? options[ index ].title : defaultTitle;
+		} );
 
 
 		// Register UI component.
 		// Register UI component.
 		editor.ui.componentFactory.add( 'headings', locale => {
 		editor.ui.componentFactory.add( 'headings', locale => {