import { router } from "@/router"; import { createVNode, reactive, render, watch, watchEffect } from "vue"; import Locale from "@/config/locale.vue"; import type { App, Ref, VNode } from "vue"; export type MountContext
= { props?: P; children?: unknown; element?: HTMLElement; app?: App; }; function mount
( component: Readonly
, { props, children, element, app }: MountContext
= {}
) {
let el = element;
let vNode: VNode | undefined = createVNode(
Locale,
{},
{
default: () => createVNode(component, props as any, children),
}
);
if (app && app._context) vNode.appContext = app._context;
if (el) {
render(vNode, el);
} else if (typeof document !== "undefined") {
render(vNode, (el = document.createElement("div")));
}
const destroy = () => {
if (el) render(null, el);
el = undefined;
vNode = undefined;
};
return { vNode, destroy, el };
}
let app: App;
export const setApp = (application: App) => (app = application);
export const extendProps = (
comp: ComponentConstructor ,
props: Mutable ,
children?: any
) => {
const element = document.createElement("div");
const { destroy: destroyRaw } = mount(comp, {
element,
props,
app: app,
children,
} as any);
const destroy = () => {
destroyRaw();
if (document.body.contains(element)) {
document.body.removeChild(element);
}
stopWatch();
};
const stopWatch = watch(() => router.currentRoute.value.name, destroy);
return destroy;
};
import Dialog from "@/components/dialog/index.vue";
import { DialogProps, dialogPropsKeys } from "@/components/dialog/type";
export type QuiskExpose = {
submit?: () => void;
quit?: () => void;
} & Partial<{ [key in keyof DialogProps]?: Ref (comp: ComponentConstructor , dprops: DialogProps) =>
,
dRef?: (expose: { quit: () => void; submit: () => void }) => void
): Promise