tdesign-mobile-vue
Version:
tdesign-mobile-vue
82 lines (78 loc) • 3.48 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { ref, getCurrentInstance, inject, computed, provide, h } from 'vue';
import isFunction from 'lodash/isFunction';
import cloneDeep from 'lodash/cloneDeep';
import isString from 'lodash/isString';
import { configProviderInjectKey, defaultGlobalConfig, mergeWith } from './context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-d5364bc4.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-eb734424.js';
import 'dayjs';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var globalConfigCopy = ref();
function useConfig() {
var componentName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : void 0;
var componentLocale = arguments.length > 1 ? arguments[1] : undefined;
var injectGlobalConfig = getCurrentInstance() ? inject(configProviderInjectKey, null) : globalConfigCopy;
var mergedGlobalConfig = computed(function () {
return (injectGlobalConfig === null || injectGlobalConfig === void 0 ? void 0 : injectGlobalConfig.value) || defaultGlobalConfig;
});
var globalConfig = computed(function () {
return Object.assign({}, mergedGlobalConfig.value[componentName], componentLocale);
});
var classPrefix = computed(function () {
return mergedGlobalConfig.value.classPrefix;
});
var t = function t(pattern) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var data = args[0];
if (isString(pattern)) {
if (!data) return pattern;
var regular = /\{\s*([\w-]+)\s*\}/g;
var translated = pattern.replace(regular, function (match, key) {
if (data) {
return String(data[key]);
}
return "";
});
return translated;
}
if (isFunction(pattern)) {
if (!args.length) return pattern(h);
return pattern.apply(void 0, args);
}
return "";
};
return {
t: t,
global: globalConfig,
globalConfig: globalConfig,
classPrefix: classPrefix
};
}
var provideConfig = function provideConfig(props) {
var defaultData = cloneDeep(defaultGlobalConfig);
var mergedGlobalConfig = computed(function () {
return _objectSpread({}, mergeWith(defaultData, props.globalConfig));
});
provide(configProviderInjectKey, mergedGlobalConfig);
if (!globalConfigCopy.value) {
globalConfigCopy.value = mergedGlobalConfig.value;
}
return mergedGlobalConfig;
};
export { provideConfig, useConfig };
//# sourceMappingURL=useConfig.js.map