import React from 'react'; import { RealmNode } from './realm'; import type { ValuesForKeys, TypedRealm, System, RealmFactory, ValueForKey, SystemKeys, SystemDict, AnySystemSpec, SystemOfSpecs } from './realmFactory'; /** * Describes the mapping between the system streams and the component properties. * Each property uses the keys as the names of the properties and the values as the corresponding stream names. * @typeParam SS - the type of the system. */ export interface SystemPropsMap { /** * Specifies the required component properties. */ required?: D; /** * Specifies the optional component properties. */ optional?: D; /** * Specifies the component methods, if any. Streams are converted to methods with a single argument. * When invoked, the method publishes the value of the argument to the specified stream. */ methods?: D; /** * Specifies the component "event" properties, if any. * Event properties accept callback functions which get executed when the stream emits a new value. */ events?: D; } type StringKeys = Extract; /** @internal */ export type PropsFromPropMap> = { [K in StringKeys]: Map['required'][K] extends string ? Sys[Map['required'][K]] extends RealmNode ? R : never : never; } & { [K in StringKeys]?: Map['optional'][K] extends string ? Sys[Map['optional'][K]] extends RealmNode ? R : never : never; } & { [K in StringKeys]?: Map['events'][K] extends string ? Sys[Map['events'][K]] extends RealmNode ? (value: R) => void : never : never; }; /** @internal */ export type MethodsFromPropMap> = { [K in StringKeys]: Map['methods'][K] extends string ? Sys[Map['methods'][K]] extends RealmNode ? (value: R) => void : never : never; }; /** * @internal * Used to correctly specify type refs for system components. * * @example * ```tsx * const s = system(() => { return { a: statefulStream(0) } }) * const { Component } = systemToComponent(s) * * const App = () => { * const ref = useRef>() * return * } * ``` * * @typeParam T - the type of the component */ export type RefHandle = T extends React.ForwardRefExoticComponent> ? Handle : never; /** * Converts a system spec to React component by mapping the system streams to component properties, events and methods. Returns hooks for querying and modifying * the system streams from the component's child components. * @param realmFactory - The return value from a [[system]] call. * @param map - The streams to props / events / methods mapping Check [[SystemPropsMap]] for more details. * @param Root - The optional React component to render. By default, the resulting component renders nothing, acting as a logical wrapper for its children. * @returns an object containing the following: * - `Component`: the React component. * - `useEmitterValue`: a hook that lets child components use values emitted from the specified output stream. * - `useEmitter`: a hook that calls the provided callback whenever the specified stream emits a value. * - `usePublisher`: a hook which lets child components publish values to the specified stream. *
*/ export declare function realmFactoryToComponent, Sys extends System = RF extends RealmFactory ? S : never, Realm extends TypedRealm = TypedRealm, M extends SystemPropsMap = SystemPropsMap>(realmFactory: RF, map: M, Root?: RootComp): { useRealmContext: () => TypedRealm; useEmitter: >(key: K, callback: (value: ValueForKey) => void) => void; useEmitterValues: >(...keys: K_1) => ValuesForKeys; usePubKeys: () => (values: SystemDict) => void; usePublisher: (key: K_2) => (value: ValueForKey) => void; Component: React.ForwardRefExoticComponent]: M["required"][K_3] extends string ? Sys[M["required"][K_3]] extends RealmNode ? R : never : never; } & { [K_4 in Extract]?: (M["optional"][K_4] extends string ? Sys[M["optional"][K_4]] extends RealmNode ? R_1 : never : never) | undefined; } & { [K_5 in Extract]?: (M["events"][K_5] extends string ? Sys[M["events"][K_5]] extends RealmNode ? (value: R_2) => void : never : never) | undefined; } & (RootComp extends React.ComponentType ? RP : { children?: React.ReactNode; })> & React.RefAttributes>>; }; /** @internal */ export declare function sysHooks(): { useRealmContext: () => TypedRealm; useEmitter: >(key: K, callback: (value: ValueForKey) => void) => void; useEmitterValues: >(...keys: K_1) => ValuesForKeys; usePubKeys: () => (values: SystemDict) => void; usePublisher: (key: K_2) => (value: ValueForKey) => void; }; type SystemAndDependencies = SystemOfSpecs<[Spec]> & SystemOfSpecs; /** * The parameters of a plugin declaration. THe best way to understand what each one does is to examine the source code of the existing plugins. */ export interface RealmPluginParams { /** * The id of the plugin. Used to declare conditional features that are activated only if the plugin is present. */ id: string; /** * The ids of the plugins that this plugin depends on. The plugin will not be activated if any of the dependencies is not present. */ dependencies?: string[]; /** * The system spec of the plugin. Construct one using {@link system}. */ systemSpec: Spec; /** * The callback is executed every time the react component is re-rendered. */ applyParamsToSystem?: (realm: TypedRealm>, props: Params) => void; /** * Executed when the component mounts. Use this to register import/export visitors, add lexical nodes to the editor, etc. * @param realm - the realm instance * @param params - the parameters passed to the plugin in the component declaration * @param pluginIds - the ids of all the plugins that are present in the component declaration */ init?: (realm: TypedRealm>, params: Params, pluginIds: string[]) => void; } /** @internal */ export interface PluginConstructor { (params?: Params): { pluginParams?: Params; } & RealmPluginParams; } /** * Declares a new MDXEditor plugin. */ export declare function realmPlugin(params: RealmPluginParams): readonly [PluginConstructor, { useRealmContext: () => TypedRealm>; useEmitter: : never), string> | Extract, string>>(key: K, callback: (value: ValueForKey, K>) => void) => void; useEmitterValues: >>(...keys: K_1) => ValuesForKeys, K_1>; usePubKeys: () => (values: SystemDict>) => void; usePublisher: : never) | keyof SystemOfSpecs>(key: K_2) => (value: ValueForKey, K_2>) => void; }]; /** @internal */ export declare const RealmPluginInitializer:

)[]>({ plugins, children }: { plugins: P; children?: React.ReactNode; }) => React.FunctionComponentElement>>; /** @internal */ export declare function useHasPlugin(id: string): boolean; /** @internal */ export declare const RequirePlugin: React.FC<{ id: string; children: React.ReactNode; }>; export {};