|
|
|
@ -1,6 +1,14 @@ |
|
|
|
import type { ExtendedModalApi, ModalApiOptions, ModalProps } from './modal'; |
|
|
|
|
|
|
|
import { defineComponent, h, inject, nextTick, provide, reactive } from 'vue'; |
|
|
|
import { |
|
|
|
defineComponent, |
|
|
|
h, |
|
|
|
inject, |
|
|
|
nextTick, |
|
|
|
provide, |
|
|
|
reactive, |
|
|
|
ref, |
|
|
|
} from 'vue'; |
|
|
|
|
|
|
|
import { useStore } from '@vben-core/shared/store'; |
|
|
|
|
|
|
|
@ -24,6 +32,7 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>( |
|
|
|
const { connectedComponent } = options; |
|
|
|
if (connectedComponent) { |
|
|
|
const extendedApi = reactive({}); |
|
|
|
const isModalReady = ref(true); |
|
|
|
const Modal = defineComponent( |
|
|
|
(props: TParentModalProps, { attrs, slots }) => { |
|
|
|
provide(USER_MODAL_INJECT_KEY, { |
|
|
|
@ -33,6 +42,11 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>( |
|
|
|
Object.setPrototypeOf(extendedApi, api); |
|
|
|
}, |
|
|
|
options, |
|
|
|
async reCreateModal() { |
|
|
|
isModalReady.value = false; |
|
|
|
await nextTick(); |
|
|
|
isModalReady.value = true; |
|
|
|
}, |
|
|
|
}); |
|
|
|
checkProps(extendedApi as ExtendedModalApi, { |
|
|
|
...props, |
|
|
|
@ -41,7 +55,7 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>( |
|
|
|
}); |
|
|
|
return () => |
|
|
|
h( |
|
|
|
connectedComponent, |
|
|
|
isModalReady.value ? connectedComponent : 'div', |
|
|
|
{ |
|
|
|
...props, |
|
|
|
...attrs, |
|
|
|
@ -70,6 +84,13 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>( |
|
|
|
injectData.options?.onOpenChange?.(isOpen); |
|
|
|
}; |
|
|
|
|
|
|
|
mergedOptions.onClosed = () => { |
|
|
|
options.onClosed?.(); |
|
|
|
if (options.destroyOnClose) { |
|
|
|
injectData.reCreateModal?.(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const api = new ModalApi(mergedOptions); |
|
|
|
|
|
|
|
const extendedApi: ExtendedModalApi = api as never; |
|
|
|
|