前端初始化
This commit is contained in:
Generated
Vendored
+39
@@ -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 };
|
||||
Generated
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
require("../../../../_virtual/_rolldown/runtime.js");
|
||||
const require_objects = require("../../../../utils/objects.js");
|
||||
const require_error = require("../../../../utils/error.js");
|
||||
const require_index = require("../../../../hooks/use-locale/index.js");
|
||||
const require_index$1 = require("../../../../hooks/use-namespace/index.js");
|
||||
const require_index$2 = require("../../../../hooks/use-z-index/index.js");
|
||||
const require_index$3 = require("../../../../hooks/use-size/index.js");
|
||||
const require_index$4 = require("../../../../hooks/use-empty-values/index.js");
|
||||
const require_constants = require("../constants.js");
|
||||
let lodash_unified = require("lodash-unified");
|
||||
let vue = require("vue");
|
||||
//#region ../../packages/components/config-provider/src/hooks/use-global-config.ts
|
||||
const globalConfig = (0, vue.ref)();
|
||||
function useGlobalConfig(key, defaultValue = void 0) {
|
||||
const config = (0, vue.getCurrentInstance)() ? (0, vue.inject)(require_constants.configProviderContextKey, globalConfig) : globalConfig;
|
||||
if (key) return (0, vue.computed)(() => config.value?.[key] ?? defaultValue);
|
||||
else return config;
|
||||
}
|
||||
function useGlobalComponentSettings(block, sizeFallback) {
|
||||
const config = useGlobalConfig();
|
||||
const ns = require_index$1.useNamespace(block, (0, vue.computed)(() => config.value?.namespace || "el"));
|
||||
const locale = require_index.useLocale((0, vue.computed)(() => config.value?.locale));
|
||||
const zIndex = require_index$2.useZIndex((0, vue.computed)(() => {
|
||||
const zIndex = config.value?.zIndex;
|
||||
return (0, lodash_unified.isNil)(zIndex) || Number.isNaN(zIndex) ? require_index$2.defaultInitialZIndex : zIndex;
|
||||
}));
|
||||
const size = (0, vue.computed)(() => (0, vue.unref)(sizeFallback) || config.value?.size || "");
|
||||
provideGlobalConfig((0, vue.computed)(() => (0, vue.unref)(config) || {}));
|
||||
return {
|
||||
ns,
|
||||
locale,
|
||||
zIndex,
|
||||
size
|
||||
};
|
||||
}
|
||||
const provideGlobalConfig = (config, app, global = false) => {
|
||||
const inSetup = !!(0, vue.getCurrentInstance)();
|
||||
const oldConfig = inSetup ? useGlobalConfig() : void 0;
|
||||
const provideFn = app?.provide ?? (inSetup ? vue.provide : void 0);
|
||||
if (!provideFn) {
|
||||
require_error.debugWarn("provideGlobalConfig", "provideGlobalConfig() can only be used inside setup().");
|
||||
return;
|
||||
}
|
||||
const context = (0, vue.computed)(() => {
|
||||
const cfg = (0, vue.unref)(config);
|
||||
if (!oldConfig?.value) return cfg;
|
||||
return mergeConfig(oldConfig.value, cfg);
|
||||
});
|
||||
provideFn(require_constants.configProviderContextKey, context);
|
||||
provideFn(require_index.localeContextKey, (0, vue.computed)(() => context.value.locale));
|
||||
provideFn(require_index$1.namespaceContextKey, (0, vue.computed)(() => context.value.namespace));
|
||||
provideFn(require_index$2.zIndexContextKey, (0, vue.computed)(() => context.value.zIndex));
|
||||
provideFn(require_index$3.SIZE_INJECTION_KEY, { size: (0, vue.computed)(() => context.value.size || "") });
|
||||
provideFn(require_index$4.emptyValuesContextKey, (0, vue.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([...require_objects.keysOf(a), ...require_objects.keysOf(b)])];
|
||||
const obj = {};
|
||||
for (const key of keys) obj[key] = b[key] !== void 0 ? b[key] : a[key];
|
||||
return obj;
|
||||
};
|
||||
//#endregion
|
||||
exports.provideGlobalConfig = provideGlobalConfig;
|
||||
exports.useGlobalComponentSettings = useGlobalComponentSettings;
|
||||
exports.useGlobalConfig = useGlobalConfig;
|
||||
|
||||
//# sourceMappingURL=use-global-config.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user