@nextcloud/vue
Version:
Nextcloud vue components
35 lines (34 loc) • 1.35 kB
TypeScript
import { Component } from 'vue';
type ComponentProps<T extends Component> = T extends new (...args: any) => {
$props: infer P;
} ? P : never;
type DialogComponent<T extends Component> = 'onClose' extends keyof ComponentProps<T> ? T : 'Please provide a Dialog Component that supports `@close` event';
/**
* Event payload array normalized to a single value when payload has only one argument,
* including one optional argument
*/
type NormalizedPayload<T> = T extends [] ? void : T extends [infer F] ? F : T extends {
length: 0 | 1;
0?: infer F;
} ? F | undefined : T;
type ClosePayload<T> = T extends {
onClose?: (...args: infer P) => any;
} ? P : never;
type SpawnDialogOptions = {
/**
* Container to mount the dialog to
*
* @default document.body
*/
container?: Element | string;
};
/**
* Spawn a single-use Vue dialog instance to get the result when it is closed
*
* @param dialog - Dialog component to spawn
* @param props - Props to pass to the dialog instance
* @param options - Spawning options
* @return Promise resolved with the `close` event payload
*/
export declare function spawnDialog<C extends Component, E extends ClosePayload<ComponentProps<C>>>(dialog: DialogComponent<C>, props?: Partial<ComponentProps<C>>, options?: SpawnDialogOptions): Promise<NormalizedPayload<E>>;
export {};