feat: bubble组件封装

This commit is contained in:
renxiaodong
2025-08-21 00:24:36 +08:00
parent 6e3158cdb4
commit 64621d9add
17 changed files with 911 additions and 5 deletions

View File

@ -0,0 +1,45 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-08-20 23:17:49
*/
import { computed, defineComponent, inject, provide, shallowRef, triggerRef, unref, watch } from "vue";
import type { ComputedRef, InjectionKey } from "vue";
import { objectType } from "@/utils/type";
import type { BubbleContextProps } from "./types";
const BubbleContextKey: InjectionKey<ComputedRef<BubbleContextProps>> =
Symbol('BubbleContext');
export const globalBubbleContextApi = shallowRef<BubbleContextProps>();
export const useBubbleContextProvider = (value: ComputedRef<BubbleContextProps>) => {
provide(BubbleContextKey, value);
watch(
value,
() => {
globalBubbleContextApi.value = unref(value);
triggerRef(globalBubbleContextApi);
},
{ immediate: true, deep: true },
);
};
export const useBubbleContextInject = () => {
return inject(
BubbleContextKey,
computed(() => globalBubbleContextApi.value || {}),
);
};
export const BubbleContextProvider = defineComponent({
props: {
value: objectType<BubbleContextProps>(),
},
setup(props, { slots }) {
useBubbleContextProvider(computed(() => props.value));
return () => {
return slots.default?.();
};
},
});
export default BubbleContextProvider;