1 | /* -----------------------------------------------------------------------------
|
2 | | Copyright (c) Jupyter Development Team.
|
3 | | Distributed under the terms of the Modified BSD License.
|
4 | |----------------------------------------------------------------------------*/
|
5 | import { Token } from '@lumino/coreutils';
|
6 | /**
|
7 | * A registry for rendering fields used in the FormEditor component.
|
8 | */
|
9 | export class FormComponentRegistry {
|
10 | constructor() {
|
11 | this._renderers = {};
|
12 | }
|
13 | /**
|
14 | * Adds a renderer for a given id - if the id is already in use, returns false.
|
15 | * Otherwise, returns true.
|
16 | * @param id - Unique ID for the given renderer.
|
17 | * @param renderer - A function that takes props and returns a rendered component
|
18 | * @returns - Whether the renderer was added successfully. False if the id is already in use.
|
19 | */
|
20 | addRenderer(id, renderer) {
|
21 | if (this._renderers[id]) {
|
22 | return false;
|
23 | }
|
24 | this._renderers[id] = renderer;
|
25 | return true;
|
26 | }
|
27 | /**
|
28 | * Returns all registered renderers in dictionary form.
|
29 | * @returns - A dictionary that maps an id to a renderer.
|
30 | */
|
31 | get renderers() {
|
32 | return this._renderers;
|
33 | }
|
34 | /**
|
35 | * Returns the renderer for the given id
|
36 | * @param id - The unique id for the renderer.
|
37 | * @returns - A function that takes props and returns a rendered component.
|
38 | */
|
39 | getRenderer(id) {
|
40 | return this._renderers[id];
|
41 | }
|
42 | }
|
43 | export const IFormComponentRegistry = new Token('@jupyterlab/ui-components:ISettingEditorRegistry');
|
44 | //# sourceMappingURL=FormComponentRegistry.js.map |
\ | No newline at end of file |