ComponentFactory (ui)
@ckeditor/ckeditor5-ui/src/componentfactory
A helper class implementing the UI component (view) factory.
It allows functions producing specific UI components to be registered under their unique names in the factory. A registered component can be then instantiated by providing its name. Note that the names are case insensitive.
// The editor provides localization tools for the factory.
const factory = new ComponentFactory( editor );
factory.add( 'foo', locale => new FooView( locale ) );
factory.add( 'bar', locale => new BarView( locale ) );
// An instance of FooView.
const fooInstance = factory.create( 'foo' );
// Names are case insensitive so this is also allowed:
const barInstance = factory.create( 'Bar' );
The editor locale is passed to the factory
function when create
is called.
Filtering
Properties
-
The editor instance that the factory belongs to.
-
private readonly
_components : Map<string, object>
module:ui/componentfactory~ComponentFactory#_components
Registered component factories.
Methods
-
constructor( editor )
module:ui/componentfactory~ComponentFactory#constructor
-
add( name, callback ) → void
module:ui/componentfactory~ComponentFactory#add
Registers a component factory function that will be used by the create method and called with the editor locale as an argument, allowing localization of the view.
Parameters
name : string
The name of the component.
callback : ( Locale ) => View<HTMLElement>
The callback that returns the component.
Returns
void
-
Creates an instance of a component registered in the factory under a specific name.
When called, the editor locale is passed to the previously added factory function, allowing localization of the view.
Parameters
name : string
The name of the component.
Returns
View<HTMLElement>
The instantiated component view.
-
has( name ) → boolean
module:ui/componentfactory~ComponentFactory#has
Checks if a component of a given name is registered in the factory.
Parameters
name : string
The name of the component.
Returns
boolean
-
names() → IterableIterator<string>
module:ui/componentfactory~ComponentFactory#names
Returns an iterator of registered component names. Names are returned in lower case.
Returns
IterableIterator<string>
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.