import * as mobx_view_model from 'mobx-view-model'; import { AnyViewModel, AnyViewModelSimple, ViewModelCreateConfig, ViewModelsConfig, ViewModelSimple, ViewModelLookup, ViewModelStore, ViewModel } from 'mobx-view-model'; import * as react from 'react'; import { Maybe, Class, IsPartial, AnyObject, IsAny, IsUnknown, Defined, EmptyObject, HasKey } from 'yummies/types'; type RComponentState = react.ComponentState; type RReactNode = react.ReactNode; type RForwardedRef = react.ForwardedRef; type RComponentType

= react.ComponentType

; type RLegacyRef = react.LegacyRef; type RComponentClass

= react.ComponentClass; /** Value accepted by React [`use()`](https://react.dev/reference/react/use). */ type RUsable = react.Usable; /** * This is a provider for the `ActiveViewModelContext`. * This HOC is not recommended for public usage. * Better to use `withViewModel` HOC. */ declare const ActiveViewModelProvider: RComponentType<{ value: AnyViewModel | AnyViewModelSimple; children?: RReactNode; }>; interface UseCreateViewModelConfig extends Pick, 'vmConfig' | 'ctx' | 'component' | 'anchors' | 'props'> { /** * Unique identifier for the view * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#id) */ id?: Maybe; /** * Function to generate an identifier for the view model * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#generateid) */ generateId?: ViewModelsConfig['generateId']; /** * Function to create an instance of the VM class * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#factory) */ factory?: ViewModelsConfig['factory']; } /** * Creates new instance of ViewModel * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/use-create-view-model.html) */ declare function useCreateViewModel(VM: Class, ...args: IsPartial extends true ? [ payload?: TViewModel['payload'], config?: UseCreateViewModelConfig ] : [ payload: TViewModel['payload'], config?: UseCreateViewModelConfig ]): TViewModel; /** * Creates new instance of ViewModelSimple * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/use-create-view-model.html) */ declare function useCreateViewModel>(VM: Class, ...args: IsPartial extends true ? [payload?: TPayload] : [payload: TPayload]): TViewModelSimple; /** * Creates new instance of ViewModelSimple * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/use-create-view-model.html) */ declare function useCreateViewModel(VM: Class): TViewModelSimple; /** * Get access to **already created** instance of ViewModel * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/use-view-model.html) */ declare const useViewModel: (vmLookup?: ViewModelLookup) => T; type OnlyViewModelProps = { model: Class; children?: RReactNode | ((model: TViewModel) => RReactNode); } & (IsPartial extends true ? { payload?: TViewModel['payload']; config?: UseCreateViewModelConfig; } : { payload: TViewModel['payload']; config?: UseCreateViewModelConfig; }); declare const OnlyViewModel: (({ model, config, payload, children, }: OnlyViewModelProps) => string | number | bigint | boolean | Iterable | Promise> | Iterable | null | undefined> | react.JSX.Element | null | undefined) & { displayName: string; }; declare const ViewModelsProvider: RComponentType<{ value: ViewModelStore; children?: RReactNode; }>; declare const ActiveViewModelContext: react.Context; /** * Context which contains the view models store instance. * This context is used to access the view models store inside the React components. * @see {@link ViewModelStore} */ declare const ViewModelsContext: react.Context>; type FixedComponentType

= /** * Fixes typings loss with use `withViewModel` with inline function component */ ((props: P) => RReactNode) | RComponentClass

; type ExtractReactRef = Defined extends RForwardedRef ? TForwardedRef : Defined extends RLegacyRef ? TRef : T; /** * This type is needed to declare prop types for your View component wrapped into `withViewModel` HOC * * Use second generic type add typings for `forwardedRef` prop */ type ViewModelProps = IsAny extends true ? { model: VM; forwardedRef?: RForwardedRef; } : IsUnknown extends true ? { model: VM; } : { model: VM; forwardedRef?: RForwardedRef; }; type ViewModelPropsChargedProps = HasKey extends true ? Omit & ViewModelProps> : HasKey extends true ? TComponentOriginProps : TComponentOriginProps & ViewModelProps extends true ? any : TForwardedRef>; type VMInputPayloadPropObj = VM extends ViewModel ? TPayload extends EmptyObject ? {} : IsPartial extends true ? { payload?: TPayload; } : { payload: TPayload; } : VM extends ViewModelSimple ? TPayload extends EmptyObject ? {} : IsPartial extends true ? { payload?: TPayload; } : { payload: TPayload; } : {}; type WithViewModelReactHook = (allProps: AnyObject, ctx: AnyObject, viewModels: Maybe, ref?: any) => void; interface ViewModelHocConfig extends Omit, 'component' | 'componentProps'> { /** * Component to render if the view model initialization takes too long * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#fallback) */ fallback?: RComponentType; /** * Function to invoke additional React hooks in the resulting component * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#reacthook) */ reactHook?: WithViewModelReactHook; /** * Function that should return the payload for the VM * by default, it is - (props) => props.payload * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#getpayload) */ getPayload?: (allProps: any) => any; /** * Forwards ref using `RforwardRef` but pass it to props as prop `ref` * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#forwardref) */ forwardRef?: boolean; /** * Additional component anchors for the same VM instance. * useViewModel(AnchorComponent) will return this VM when the connected component is mounted. */ anchors?: RComponentType[]; } interface ViewModelSimpleHocConfig<_VM> { /** * Component to render if the view model initialization takes too long * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#fallback) */ fallback?: RComponentType; /** * Function to invoke additional React hooks in the resulting component * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#reacthook) */ reactHook?: WithViewModelReactHook; /** * Function that should return the payload for the VM * by default, it is - (props) => props.payload * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#getpayload) */ getPayload?: (allProps: any) => any; /** * Forwards ref using `RforwardRef` but pass it to props as prop `ref` * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html#forwardref) */ forwardRef?: boolean; /** * Additional component anchors for the same VM instance. * useViewModel(AnchorComponent) will return this VM when the connected component is mounted. */ anchors?: RComponentType[]; } type AllViewModelPropsKeys = keyof Required>; type VMComponentProps = Omit & VMInputPayloadPropObj & (HasKey extends true ? {} : HasKey extends true ? Required['forwardedRef'] extends RLegacyRef ? { ref?: TComponentOriginProps['forwardedRef']; } : Pick : IsUnknown extends true ? {} : { ref?: RLegacyRef; }); interface VMComponent { (props: VMComponentProps): RReactNode; /** * Registers an anchor component for the same VM instance. * `useViewModel(anchor)` will return this VM when the connected component is mounted. * Anchors are stored in config.anchors and passed to the store's link() during processCreateConfig. * @param anchor - React component to use as lookup key for useViewModel */ connect(anchor: RComponentType): VMComponent; } /** * A Higher-Order Component that connects React components to their ViewModels, providing seamless MobX integration. * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html) */ declare function withViewModel(model: Class, component: RComponentType>, config?: ViewModelHocConfig): VMComponent; /** * A Higher-Order Component that connects React components to their ViewModels, providing seamless MobX integration. * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html) */ declare function withViewModel(model: Class, config?: ViewModelHocConfig): >(Component?: RComponentType>) => VMComponent; /** * A Higher-Order Component that connects React components to their ViewModels, providing seamless MobX integration. * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html) */ declare function withViewModel(model: Class, config?: ViewModelSimpleHocConfig): >(Component?: FixedComponentType>) => VMComponent; /** * A Higher-Order Component that connects React components to their ViewModels, providing seamless MobX integration. * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html) */ declare function withViewModel(model: Class, component: FixedComponentType>, config?: ViewModelSimpleHocConfig): VMComponent; /** * A Higher-Order Component that connects React components to their ViewModels, providing seamless MobX integration. * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-view-model.html) */ declare function withViewModel, TForwardedRef = unknown>(model: Class, component: FixedComponentType>, config?: ViewModelSimpleHocConfig): VMComponent; type InferPropsViewModelPayload = TViewModel extends AnyViewModel ? TViewModel['payload'] : TViewModel extends { setPayload(payload: infer TPayload extends AnyObject): any; } ? TPayload : TViewModel extends ViewModelSimple ? TPayload : EmptyObject; type ExtractVMPayload = InferPropsViewModelPayload; type PropsVMComponentProps, TForwardedRef = unknown> = ExtractVMPayload & Omit> & (HasKey extends true ? {} : HasKey extends true ? Required['forwardedRef'] extends RForwardedRef ? { ref?: RLegacyRef; } : Required['forwardedRef'] extends RLegacyRef ? { ref?: TComponentOriginProps['forwardedRef']; } : Pick : IsUnknown extends true ? {} : { ref?: RLegacyRef; }); interface PropsVMComponent, TForwardedRef = unknown> { (props: PropsVMComponentProps): RReactNode; connect(anchor: RComponentType): PropsVMComponent; } type PropsViewModelHocConfig = Omit, 'getPayload'>; type PropsViewModelSimpleHocConfig = Omit, 'getPayload'>; /** * Like `withViewModel`, but treats all component props as the ViewModel payload. * The resulting component does not require a separate `payload` prop. * * [**Documentation**](https://js2me.github.io/mobx-view-model/react/api/with-props-view-model.html) */ declare function withPropsViewModel, TForwardedRef = unknown>(model: Class, component: FixedComponentType>, config?: TViewModel extends AnyViewModel ? PropsViewModelHocConfig : PropsViewModelSimpleHocConfig): PropsVMComponent; export { ActiveViewModelContext, ActiveViewModelProvider, OnlyViewModel, ViewModelsContext, ViewModelsProvider, useCreateViewModel, useViewModel, withPropsViewModel, withViewModel }; export type { AllViewModelPropsKeys, ExtractReactRef, FixedComponentType, OnlyViewModelProps, PropsVMComponent, PropsVMComponentProps, PropsViewModelHocConfig, PropsViewModelSimpleHocConfig, RComponentClass, RComponentState, RComponentType, RForwardedRef, RLegacyRef, RReactNode, RUsable, UseCreateViewModelConfig, VMComponent, VMComponentProps, ViewModelHocConfig, ViewModelProps, ViewModelPropsChargedProps, ViewModelSimpleHocConfig, WithViewModelReactHook };