|
|
|
@ -1,5 +1,13 @@
|
|
|
|
|
import type { ShallowRef, ExtractPropTypes, InjectionKey, Ref } from 'vue'; |
|
|
|
|
import { provide, defineComponent, unref, inject, watch, shallowRef } from 'vue'; |
|
|
|
|
import { |
|
|
|
|
provide, |
|
|
|
|
defineComponent, |
|
|
|
|
unref, |
|
|
|
|
inject, |
|
|
|
|
watch, |
|
|
|
|
shallowRef, |
|
|
|
|
getCurrentInstance, |
|
|
|
|
} from 'vue'; |
|
|
|
|
import CacheEntity from './Cache'; |
|
|
|
|
import type { Linter } from './linters/interface'; |
|
|
|
|
import type { Transformer } from './transformers/interface'; |
|
|
|
@ -80,6 +88,27 @@ const StyleContextKey: InjectionKey<ShallowRef<Partial<StyleContextProps>>> =
|
|
|
|
|
Symbol('StyleContextKey'); |
|
|
|
|
|
|
|
|
|
export type UseStyleProviderProps = Partial<StyleContextProps> | Ref<Partial<StyleContextProps>>; |
|
|
|
|
|
|
|
|
|
// fix: https://github.com/vueComponent/ant-design-vue/issues/7023 |
|
|
|
|
const getCache = () => { |
|
|
|
|
const instance = getCurrentInstance(); |
|
|
|
|
let cache: CacheEntity; |
|
|
|
|
if (instance && instance.appContext) { |
|
|
|
|
const globalCache = instance.appContext?.config?.globalProperties?.__ANTDV_CSSINJS_CACHE__; |
|
|
|
|
if (globalCache) { |
|
|
|
|
cache = globalCache; |
|
|
|
|
} else { |
|
|
|
|
cache = createCache(); |
|
|
|
|
if (instance.appContext.config.globalProperties) { |
|
|
|
|
instance.appContext.config.globalProperties.__ANTDV_CSSINJS_CACHE__ = cache; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
cache = createCache(); |
|
|
|
|
} |
|
|
|
|
return cache; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const defaultStyleContext: StyleContextProps = { |
|
|
|
|
cache: createCache(), |
|
|
|
|
defaultCache: true, |
|
|
|
@ -87,7 +116,8 @@ const defaultStyleContext: StyleContextProps = {
|
|
|
|
|
}; |
|
|
|
|
// fix: https://github.com/vueComponent/ant-design-vue/issues/6912 |
|
|
|
|
export const useStyleInject = () => { |
|
|
|
|
return inject(StyleContextKey, shallowRef({ ...defaultStyleContext, cache: createCache() })); |
|
|
|
|
const cache = getCache(); |
|
|
|
|
return inject(StyleContextKey, shallowRef({ ...defaultStyleContext, cache })); |
|
|
|
|
}; |
|
|
|
|
export const useStyleProvider = (props: UseStyleProviderProps) => { |
|
|
|
|
const parentContext = useStyleInject(); |
|
|
|
|