完全跑通1.0版本
This commit is contained in:
39
frontend/node_modules/element-plus/es/components/config-provider/src/hooks/use-global-config.d.ts
generated
vendored
Normal file
39
frontend/node_modules/element-plus/es/components/config-provider/src/hooks/use-global-config.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { LocaleContext } from "../../../../hooks/use-locale/index.js";
|
||||
import { ConfigProviderProps } from "../config-provider-props.js";
|
||||
import { ConfigProviderContext } from "../constants.js";
|
||||
import * as _$vue from "vue";
|
||||
import { App, MaybeRef, Ref } from "vue";
|
||||
|
||||
//#region ../../packages/components/config-provider/src/hooks/use-global-config.d.ts
|
||||
declare function useGlobalConfig<K extends keyof ConfigProviderContext, D extends ConfigProviderContext[K]>(key: K, defaultValue?: D): Ref<Exclude<ConfigProviderContext[K], undefined> | D>;
|
||||
declare function useGlobalConfig(): Ref<ConfigProviderContext>;
|
||||
declare function useGlobalComponentSettings(block: string, sizeFallback?: MaybeRef<ConfigProviderContext['size']>): {
|
||||
ns: {
|
||||
namespace: _$vue.ComputedRef<string>;
|
||||
b: (blockSuffix?: string) => string;
|
||||
e: (element?: string) => string;
|
||||
m: (modifier?: string) => string;
|
||||
be: (blockSuffix?: string, element?: string) => string;
|
||||
em: (element?: string, modifier?: string) => string;
|
||||
bm: (blockSuffix?: string, modifier?: string) => string;
|
||||
bem: (blockSuffix?: string, element?: string, modifier?: string) => string;
|
||||
is: {
|
||||
(name: string, state: boolean | undefined): string;
|
||||
(name: string): string;
|
||||
};
|
||||
cssVar: (object: Record<string, string>) => Record<string, string>;
|
||||
cssVarName: (name: string) => string;
|
||||
cssVarBlock: (object: Record<string, string>) => Record<string, string>;
|
||||
cssVarBlockName: (name: string) => string;
|
||||
};
|
||||
locale: LocaleContext;
|
||||
zIndex: {
|
||||
initialZIndex: _$vue.ComputedRef<number>;
|
||||
currentZIndex: _$vue.ComputedRef<number>;
|
||||
nextZIndex: () => number;
|
||||
};
|
||||
size: _$vue.ComputedRef<"" | "default" | "small" | "large">;
|
||||
};
|
||||
declare const provideGlobalConfig: (config: MaybeRef<ConfigProviderContext>, app?: App, global?: boolean) => _$vue.ComputedRef<Partial<ConfigProviderProps>> | undefined;
|
||||
//#endregion
|
||||
export { provideGlobalConfig, useGlobalComponentSettings, useGlobalConfig };
|
||||
65
frontend/node_modules/element-plus/es/components/config-provider/src/hooks/use-global-config.mjs
generated
vendored
Normal file
65
frontend/node_modules/element-plus/es/components/config-provider/src/hooks/use-global-config.mjs
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import { keysOf } from "../../../../utils/objects.mjs";
|
||||
import { debugWarn } from "../../../../utils/error.mjs";
|
||||
import { localeContextKey, useLocale } from "../../../../hooks/use-locale/index.mjs";
|
||||
import { namespaceContextKey, useNamespace } from "../../../../hooks/use-namespace/index.mjs";
|
||||
import { useZIndex, zIndexContextKey } from "../../../../hooks/use-z-index/index.mjs";
|
||||
import { SIZE_INJECTION_KEY } from "../../../../hooks/use-size/index.mjs";
|
||||
import { emptyValuesContextKey } from "../../../../hooks/use-empty-values/index.mjs";
|
||||
import { configProviderContextKey } from "../constants.mjs";
|
||||
import { computed, getCurrentInstance, inject, provide, ref, unref } from "vue";
|
||||
//#region ../../packages/components/config-provider/src/hooks/use-global-config.ts
|
||||
const globalConfig = ref();
|
||||
function useGlobalConfig(key, defaultValue = void 0) {
|
||||
const config = getCurrentInstance() ? inject(configProviderContextKey, globalConfig) : globalConfig;
|
||||
if (key) return computed(() => config.value?.[key] ?? defaultValue);
|
||||
else return config;
|
||||
}
|
||||
function useGlobalComponentSettings(block, sizeFallback) {
|
||||
const config = useGlobalConfig();
|
||||
const ns = useNamespace(block, computed(() => config.value?.namespace || "el"));
|
||||
const locale = useLocale(computed(() => config.value?.locale));
|
||||
const zIndex = useZIndex(computed(() => config.value?.zIndex || 2e3));
|
||||
const size = computed(() => unref(sizeFallback) || config.value?.size || "");
|
||||
provideGlobalConfig(computed(() => unref(config) || {}));
|
||||
return {
|
||||
ns,
|
||||
locale,
|
||||
zIndex,
|
||||
size
|
||||
};
|
||||
}
|
||||
const provideGlobalConfig = (config, app, global = false) => {
|
||||
const inSetup = !!getCurrentInstance();
|
||||
const oldConfig = inSetup ? useGlobalConfig() : void 0;
|
||||
const provideFn = app?.provide ?? (inSetup ? provide : void 0);
|
||||
if (!provideFn) {
|
||||
debugWarn("provideGlobalConfig", "provideGlobalConfig() can only be used inside setup().");
|
||||
return;
|
||||
}
|
||||
const context = computed(() => {
|
||||
const cfg = unref(config);
|
||||
if (!oldConfig?.value) return cfg;
|
||||
return mergeConfig(oldConfig.value, cfg);
|
||||
});
|
||||
provideFn(configProviderContextKey, context);
|
||||
provideFn(localeContextKey, computed(() => context.value.locale));
|
||||
provideFn(namespaceContextKey, computed(() => context.value.namespace));
|
||||
provideFn(zIndexContextKey, computed(() => context.value.zIndex));
|
||||
provideFn(SIZE_INJECTION_KEY, { size: computed(() => context.value.size || "") });
|
||||
provideFn(emptyValuesContextKey, computed(() => ({
|
||||
emptyValues: context.value.emptyValues,
|
||||
valueOnClear: context.value.valueOnClear
|
||||
})));
|
||||
if (global || !globalConfig.value) globalConfig.value = context.value;
|
||||
return context;
|
||||
};
|
||||
const mergeConfig = (a, b) => {
|
||||
const keys = [...new Set([...keysOf(a), ...keysOf(b)])];
|
||||
const obj = {};
|
||||
for (const key of keys) obj[key] = b[key] !== void 0 ? b[key] : a[key];
|
||||
return obj;
|
||||
};
|
||||
//#endregion
|
||||
export { provideGlobalConfig, useGlobalComponentSettings, useGlobalConfig };
|
||||
|
||||
//# sourceMappingURL=use-global-config.mjs.map
|
||||
1
frontend/node_modules/element-plus/es/components/config-provider/src/hooks/use-global-config.mjs.map
generated
vendored
Normal file
1
frontend/node_modules/element-plus/es/components/config-provider/src/hooks/use-global-config.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user