You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

11 months ago
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
require('../../tokens/index.js');
var util = require('../../utils/util.js');
var error = require('../../utils/error.js');
var configProvider = require('../../tokens/config-provider.js');
var shared = require('@vue/shared');
const cache = vue.ref({});
function useGlobalConfig(key) {
const config = vue.inject(configProvider.configProviderContextKey, cache);
if (key) {
return shared.isObject(config.value) && shared.hasOwn(config.value, key) ? vue.computed(() => config.value[key]) : vue.ref(void 0);
} else {
return config;
}
}
const provideGlobalConfig = (config, app) => {
var _a;
const inSetup = !!vue.getCurrentInstance();
const oldConfig = inSetup ? useGlobalConfig() : void 0;
const provideFn = (_a = app == null ? void 0 : app.provide) != null ? _a : inSetup ? vue.provide : void 0;
if (!provideFn) {
error.debugWarn("provideGlobalConfig", "provideGlobalConfig() can only be used inside setup().");
return;
}
const context = vue.computed(() => {
const cfg = vue.unref(config);
if (!oldConfig)
return cfg;
return util.merge(oldConfig.value, cfg);
});
provideFn(configProvider.configProviderContextKey, context);
cache.value = context.value;
return context;
};
exports.provideGlobalConfig = provideGlobalConfig;
exports.useGlobalConfig = useGlobalConfig;
//# sourceMappingURL=index.js.map