@plone/registry
Version:
Add-on and configuration registry for Plone and for JavaScript and TypeScript-based apps.
127 lines (124 loc) • 5.87 kB
TypeScript
import { SettingsConfig, BlocksConfig, ViewsConfig, WidgetsConfig, AddonReducersConfig, AddonRoutesConfig, ReactRouterRouteEntry, SlotsConfig, ComponentsConfig, UtilitiesConfig, ExperimentalConfig, GetSlotArgs, GetSlotReturn, SlotPredicate, SlotComponent, UtilityTypeMap } from '@plone/types';
type ConfigData = {
settings: SettingsConfig | Record<string, never>;
blocks: BlocksConfig | Record<string, never>;
views: ViewsConfig | Record<string, never>;
widgets: WidgetsConfig;
addonReducers?: AddonReducersConfig;
addonRoutes?: AddonRoutesConfig;
routes?: Array<ReactRouterRouteEntry>;
slots: SlotsConfig | Record<string, never>;
components: ComponentsConfig | Record<string, never>;
utilities: UtilitiesConfig | Record<string, never>;
experimental?: ExperimentalConfig;
};
type GetComponentResult = {
component: React.ComponentType<any>;
};
type UtilityMethodFor<Type extends string> = Type extends keyof UtilityTypeMap ? UtilityTypeMap[Type] : (...args: any[]) => any;
type GetUtilityResult<Type extends string = string> = {
method: UtilityMethodFor<Type>;
};
type ConfigType = InstanceType<typeof Config>;
type MappableWidgetKeys = {
[K in keyof WidgetsConfig]: WidgetsConfig[K] extends Record<string, any> ? K : never;
}[keyof WidgetsConfig];
declare class Config {
_data: ConfigData | Record<string, never>;
static instance: ConfigType;
constructor();
set<RegistryKey extends keyof ConfigData>(registry: RegistryKey, item: ConfigData[RegistryKey]): void;
get(registry: keyof ConfigData): SettingsConfig | Record<string, never> | BlocksConfig | ViewsConfig | WidgetsConfig | AddonReducersConfig | AddonRoutesConfig | ReactRouterRouteEntry[] | SlotsConfig | ComponentsConfig | UtilitiesConfig | ExperimentalConfig | undefined;
get settings(): SettingsConfig | Record<string, never>;
set settings(settings: SettingsConfig | Record<string, never>);
get experimental(): ExperimentalConfig | undefined;
set experimental(experimental: ExperimentalConfig | undefined);
get blocks(): Record<string, never> | BlocksConfig;
set blocks(blocks: Record<string, never> | BlocksConfig);
get views(): Record<string, never> | ViewsConfig;
set views(views: Record<string, never> | ViewsConfig);
get widgets(): WidgetsConfig;
set widgets(widgets: WidgetsConfig);
get addonReducers(): AddonReducersConfig | undefined;
set addonReducers(addonReducers: AddonReducersConfig | undefined);
get addonRoutes(): AddonRoutesConfig | undefined;
set addonRoutes(addonRoutes: AddonRoutesConfig | undefined);
get routes(): ReactRouterRouteEntry[] | undefined;
set routes(routes: ReactRouterRouteEntry[] | undefined);
get slots(): Record<string, never> | SlotsConfig;
set slots(slots: Record<string, never> | SlotsConfig);
get components(): Record<string, never> | ComponentsConfig;
set components(components: Record<string, never> | ComponentsConfig);
get utilities(): Record<string, never> | UtilitiesConfig;
set utilities(utilities: Record<string, never> | UtilitiesConfig);
getComponent(options: {
name: string;
dependencies?: string[] | string;
} | string): GetComponentResult;
registerComponent(options: {
name: string;
dependencies?: string[] | string;
component: React.ComponentType;
}): void;
getSlot(name: string, args: GetSlotArgs): GetSlotReturn;
registerSlotComponent(options: {
slot: string;
name: string;
predicates?: SlotPredicate[];
component: SlotComponent['component'];
}): void;
getSlotComponent(slot: string, name: string): SlotComponent[];
getSlotComponents(slot: string): string[];
reorderSlotComponent({ slot, name, position, action, target, }: {
slot: string;
name: string;
position?: number;
action?: 'after' | 'before' | 'first' | 'last';
target?: string;
}): void;
unRegisterSlotComponent(slot: string, name: string, position: number): void;
registerUtility<Type extends string>(options: {
name: string;
type: Type;
dependencies?: Record<string, string>;
method: UtilityMethodFor<Type>;
}): void;
getUtility<Type extends string>(options: {
name: string;
type: Type;
dependencies?: Record<string, string>;
}): GetUtilityResult<Type> | Record<string, never>;
getUtilities<Type extends string>(options: {
type: Type;
dependencies?: Record<string, string>;
}): Array<GetUtilityResult<Type>> | [];
registerRoute(options: ReactRouterRouteEntry): void;
/**
* Registers a widget configuration into the registry.
*
* @template K - A key from the WidgetsConfig interface.
* @param options - An object containing the widget key and its corresponding implementation.
* @param options.key - The name of the widget configuration key (e.g., 'default', 'factory').
* @param options.definition - The actual widget configuration, which must match the expected structure of WidgetsConfig[K].
*
*/
registerWidget<K extends MappableWidgetKeys>(options: {
key: K;
definition: WidgetsConfig[K] extends Record<string, any> ? WidgetsConfig[K] : never;
}): void;
/**
* Registers a default widget configuration into the registry.
*
* @param component - The default widget component to register.
*
*/
registerDefaultWidget(component: React.ComponentType<any>): void;
/**
* Gets a widget configuration from the registry.
*
* @param key - A key from the WidgetsConfig interface.
*/
getWidget(key: string): React.ComponentType<any> | undefined;
}
declare const instance: Config;
export { type ConfigData, type ConfigType, instance as default };