LocaleReceiver.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. exports.useLocaleReceiver = useLocaleReceiver;
  8. var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
  9. var _vue = require("vue");
  10. var _default2 = _interopRequireDefault(require("./default"));
  11. var _default = (0, _vue.defineComponent)({
  12. compatConfig: {
  13. MODE: 3
  14. },
  15. name: 'LocaleReceiver',
  16. props: {
  17. componentName: String,
  18. defaultLocale: {
  19. type: [Object, Function]
  20. },
  21. children: {
  22. type: Function
  23. }
  24. },
  25. setup: function setup(props, _ref) {
  26. var slots = _ref.slots;
  27. var localeData = (0, _vue.inject)('localeData', {});
  28. var locale = (0, _vue.computed)(function () {
  29. var _props$componentName = props.componentName,
  30. componentName = _props$componentName === void 0 ? 'global' : _props$componentName,
  31. defaultLocale = props.defaultLocale;
  32. var locale = defaultLocale || _default2.default[componentName || 'global'];
  33. var antLocale = localeData.antLocale;
  34. var localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
  35. return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, typeof locale === 'function' ? locale() : locale), localeFromContext || {});
  36. });
  37. var localeCode = (0, _vue.computed)(function () {
  38. var antLocale = localeData.antLocale;
  39. var localeCode = antLocale && antLocale.locale;
  40. // Had use LocaleProvide but didn't set locale
  41. if (antLocale && antLocale.exist && !localeCode) {
  42. return _default2.default.locale;
  43. }
  44. return localeCode;
  45. });
  46. return function () {
  47. var children = props.children || slots.default;
  48. var antLocale = localeData.antLocale;
  49. return children === null || children === void 0 ? void 0 : children(locale.value, localeCode.value, antLocale);
  50. };
  51. }
  52. });
  53. exports.default = _default;
  54. function useLocaleReceiver(componentName, defaultLocale, propsLocale) {
  55. var localeData = (0, _vue.inject)('localeData', {});
  56. var componentLocale = (0, _vue.computed)(function () {
  57. var antLocale = localeData.antLocale;
  58. var locale = (0, _vue.unref)(defaultLocale) || _default2.default[componentName || 'global'];
  59. var localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
  60. return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, typeof locale === 'function' ? locale() : locale), localeFromContext || {}), (0, _vue.unref)(propsLocale) || {});
  61. });
  62. return [componentLocale];
  63. }