UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

85 lines (84 loc) 5.4 kB
import { Component, ComponentPublicInstance, MaybeRef, Ref } from 'vue'; import { BModalProps, BPopoverProps, BToastProps, BTooltipProps } from './ComponentProps'; import { ContainerPosition } from './Alignment'; import { BModalSlots, BPopoverSlots, BToastSlots, BTooltipSlots } from './ComponentSlots'; import { BModalEmits, BPopoverEmits, BToastEmits, BTooltipEmits } from './ComponentEmits'; import { BvTriggerableEvent } from '../utils'; export type ControllerKey = symbol | string; type Prefix<P extends string, S extends string> = `${P}${S}`; export type CamelCase<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>; export type OrchestratorCreateOptions = { resolveOnHide?: boolean; }; export interface ComponentController<Component, Props extends Ref<OrchestratorArrayValue>> extends AsyncDisposable { id: ControllerKey; ref: ComponentPublicInstance<Component> | null; show: () => Promise<BvTriggerableEvent & AsyncDisposable>; hide: (trigger?: string) => void; toggle: () => void; set: (val: Partial<Props['value']['props']>) => void; get: () => Props | undefined; destroy: () => Promise<void>; } export type PromiseWithController<Component, Props extends Ref<OrchestratorArrayValue>> = { resolve: (value: BvTriggerableEvent) => void; controller: ComponentController<Component, Props>; }; type OrchestratorCreateBase<BaseComponentProps extends Record<string, any>, SuppliedComponentProps extends Record<string, any>, BaseComponentSlots extends Record<string, any>, BaseComponentEmits extends Record<string, any>> = BaseComponentProps & { options?: OrchestratorCreateOptions; component?: Readonly<Component>; slots?: { [K in keyof BaseComponentSlots]?: BaseComponentSlots[K] | Readonly<Component>; }; } & { [K in Extract<keyof BaseComponentEmits, string> as CamelCase<Prefix<'on-', K>>]?: (e: BaseComponentEmits[K][0]) => void; } & SuppliedComponentProps; type ArrayValue<BaseComponentProps extends Record<string, any>, BaseComponentSlots extends Record<string, any>, BaseComponentEmits extends Record<string, any>> = { component?: Readonly<Component>; options?: OrchestratorCreateOptions; slots?: { [K in keyof BaseComponentSlots]?: BaseComponentSlots[K] | Readonly<Component>; }; /** * If this is the prop that is passed in, it will be that * If the input is undefined, it will be a symbol stored in the Map<> */ id: string | symbol; fns: { resolve: (value: BvTriggerableEvent) => void; setRef: (v: ComponentPublicInstance) => void; destroy: () => Promise<void>; }; props: BaseComponentProps & { [K in keyof BaseComponentEmits as CamelCase<Prefix<'on-', Extract<K, string>>>]?: (e: BaseComponentEmits[K][0]) => void; } & Record<string, unknown>; }; export type ToastOrchestratorCreateParamBase<ComponentProps extends Record<string, any> = Record<string, any>> = OrchestratorCreateBase<BToastProps & { /** * Position * @default 'top-end' */ position?: ContainerPosition; /** * Sets whether the toast should be appended to the container * @default undefined Implicitly defaults to the BOrchestrator's appendToast value */ appendToast?: boolean; }, ComponentProps, BToastSlots, BToastEmits>; export type ToastOrchestratorCreateParam<ComponentProps extends Record<string, any> = Record<string, any>> = MaybeRef<ToastOrchestratorCreateParamBase<ComponentProps>>; type ToastArrayProps = BToastProps & { position?: ContainerPosition; appendToast?: boolean; }; export type ToastOrchestratorArrayValue = ArrayValue<ToastArrayProps, BToastSlots, BToastEmits>; export type TooltipOrchestratorCreateParamBase<ComponentProps extends Record<string, any> = Record<string, any>> = OrchestratorCreateBase<BTooltipProps, ComponentProps, Omit<BTooltipSlots, 'target'>, BTooltipEmits>; export type TooltipOrchestratorCreateParam<ComponentProps extends Record<string, any> = Record<string, any>> = MaybeRef<TooltipOrchestratorCreateParamBase<ComponentProps>>; export type TooltipOrchestratorArrayValue = ArrayValue<BTooltipProps, Omit<BTooltipSlots, 'target'>, BTooltipEmits>; export type PopoverOrchestratorCreateParamBase<ComponentProps extends Record<string, any> = Record<string, any>> = OrchestratorCreateBase<BPopoverProps, ComponentProps, Omit<BPopoverSlots, 'target'>, BPopoverEmits>; export type PopoverOrchestratorCreateParam<ComponentProps extends Record<string, any> = Record<string, any>> = MaybeRef<PopoverOrchestratorCreateParamBase<ComponentProps>>; export type PopoverOrchestratorArrayValue = ArrayValue<BPopoverProps, Omit<BPopoverSlots, 'target'>, BPopoverEmits>; export type ModalOrchestratorCreateParamBase<ComponentProps extends Record<string, any> = Record<string, any>> = OrchestratorCreateBase<BModalProps, ComponentProps, BModalSlots, BModalEmits>; export type ModalOrchestratorCreateParam<ComponentProps extends Record<string, any> = Record<string, any>> = MaybeRef<ModalOrchestratorCreateParamBase<ComponentProps>>; export type ModalOrchestratorArrayValue = ArrayValue<BModalProps, BModalSlots, BModalEmits>; export type OrchestratorArrayValue = ToastOrchestratorArrayValue | ModalOrchestratorArrayValue | PopoverOrchestratorArrayValue | TooltipOrchestratorArrayValue; export {};