8
0

utils.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module ui/toolbar/utils
  7. */
  8. import ToolbarSeparatorView from './toolbarseparatorview';
  9. /**
  10. * An utility which expands a plain toolbar configuration into a collection
  11. * of {@link module:ui/view~View views} using a given factory.
  12. *
  13. * @param {Object} config The toolbar config.
  14. * @param {module:utils/collection~Collection} collection A collection into which the config
  15. * is expanded.
  16. * @param {module:ui/componentfactory~ComponentFactory} factory A factory producing toolbar items.
  17. * @returns {Promise} A promise resolved when all toolbar items are initialized.
  18. */
  19. export function getItemsFromConfig( config, collection, factory ) {
  20. let promises = [];
  21. if ( config ) {
  22. promises = config.map( name => {
  23. const component = name == '|' ? new ToolbarSeparatorView() : factory.create( name );
  24. return collection.add( component );
  25. } );
  26. }
  27. return Promise.all( promises );
  28. }