import { BlueRain } from '../index'; import MapRegistry from './MapRegistry'; import React from 'react'; export declare type ComponentRegistryHocItem = (...args: any[]) => React.ComponentType; export interface ComponentSource { type: 'plugin' | 'app' | 'custom'; slug: string; } export interface ComponentRegistryItem { rawComponent: React.ComponentType; hocs: ComponentRegistryHocItem[]; source?: ComponentSource; } /** * All system components are stored in this registry * @property {Map, hocs: Array>}>} data Storage * of all components */ declare class ComponentRegistry extends MapRegistry { BR: BlueRain; [key: string]: any; constructor(ctx: BlueRain); /** * Register a component with a name, a raw component than can be extended * and one or more optional higher order components. * * @param {String} name The name of the component to register. * @param {React.ComponentType} rawComponent Interchangeable/extendable component. * @param {Array} hocs The HOCs to compose with the raw component. * * Note: when a component is registered without higher order component, `hocs` will be * an empty array, and it's ok! * See https://lodash.com/docs/4.17.4#flowRight */ add(name: string, rawComponent: React.ComponentType, ...hocs: ComponentRegistryHocItem[]): void; /** * Replace a component with the same name with a new component or * an extension of the raw component and one or more optional higher order components. * This function keeps track of the previous HOCs and wrap the new HOCs around previous ones * * @param {String} name The name of the component to register. * @param {React.ComponentType} rawComponent Interchangeable/extendable component. * @param {...Function} hocs The HOCs to compose with the raw component. * @returns {Function|React.ComponentType} A component callable with Components[name] * * Note: when a component is registered without higher order component, `hocs` will be * an empty array, and it's ok! * See https://lodash.com/docs/4.17.4#flowRight */ replace(name: string, newComponent: React.ComponentType, ...newHocs: ComponentRegistryHocItem[]): void; /** * Set or Replace an item in the Registry. * * @param {string} key The key of the item * @param {React.ComponentType} item The item to add */ set(key: string, rawComponent: React.ComponentType, ...hocs: ComponentRegistryHocItem[]): void; /** * Adds higher order component to the registered component * @param {string} name The name of the registered component to whom hocs are to added * @param {Array} hocs The HOCs to compose with the raw component. */ addHocs(name: string, ...hocs: ComponentRegistryHocItem[]): void; /** * Get a component registered with set(name, component, ...hocs). * Its accepts multiple component names.It iterates arguments and returns first found registered component. * * @param {String} name The name of the component to get. * @returns {Function|React.ComponentType} A (wrapped) React component */ get(...name: string[]): React.ComponentType; /** * Get the **raw** (original) component registered with registerComponent * without the possible HOCs wrapping it. * * @param {String} name The name of the component to get. * @returns {Function|React.ComponentType} An interchangeable/extendable React component */ getRawComponent(name: string): React.ComponentType; setSource(key: string, source: ComponentSource): void; getSource(key: string): ComponentSource | undefined; } export default ComponentRegistry;