index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = exports.configConsumerProps = void 0;
  7. Object.defineProperty(exports, "defaultIconPrefixCls", {
  8. enumerable: true,
  9. get: function () {
  10. return _context.defaultIconPrefixCls;
  11. }
  12. });
  13. exports.globalConfigForApi = exports.globalConfig = exports.defaultPrefixCls = void 0;
  14. var _vue = require("vue");
  15. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  16. var _renderEmpty = _interopRequireDefault(require("./renderEmpty"));
  17. var _localeProvider = _interopRequireWildcard(require("../locale-provider"));
  18. var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));
  19. var _message = _interopRequireDefault(require("../message"));
  20. var _notification = _interopRequireDefault(require("../notification"));
  21. var _cssVariables = require("./cssVariables");
  22. var _en_US = _interopRequireDefault(require("../locale/en_US"));
  23. var _style = _interopRequireDefault(require("./style"));
  24. var _useTheme = _interopRequireDefault(require("./hooks/useTheme"));
  25. var _seed = _interopRequireDefault(require("../theme/themes/seed"));
  26. var _context = require("./context");
  27. var _SizeContext = require("./SizeContext");
  28. var _DisabledContext = require("./DisabledContext");
  29. var _cssinjs = require("../_util/cssinjs");
  30. var _internal = require("../theme/internal");
  31. function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
  32. function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
  33. var __rest = void 0 && (void 0).__rest || function (s, e) {
  34. var t = {};
  35. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  36. if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  37. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  38. }
  39. return t;
  40. };
  41. const defaultPrefixCls = exports.defaultPrefixCls = 'ant';
  42. function getGlobalPrefixCls() {
  43. return globalConfigForApi.prefixCls || defaultPrefixCls;
  44. }
  45. function getGlobalIconPrefixCls() {
  46. return globalConfigForApi.iconPrefixCls || _context.defaultIconPrefixCls;
  47. }
  48. const globalConfigBySet = (0, _vue.reactive)({}); // 权重最大
  49. const globalConfigForApi = exports.globalConfigForApi = (0, _vue.reactive)({});
  50. const configConsumerProps = exports.configConsumerProps = ['getTargetContainer', 'getPopupContainer', 'rootPrefixCls', 'getPrefixCls', 'renderEmpty', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader'];
  51. (0, _vue.watchEffect)(() => {
  52. (0, _extends2.default)(globalConfigForApi, globalConfigBySet);
  53. globalConfigForApi.prefixCls = getGlobalPrefixCls();
  54. globalConfigForApi.iconPrefixCls = getGlobalIconPrefixCls();
  55. globalConfigForApi.getPrefixCls = (suffixCls, customizePrefixCls) => {
  56. if (customizePrefixCls) return customizePrefixCls;
  57. return suffixCls ? `${globalConfigForApi.prefixCls}-${suffixCls}` : globalConfigForApi.prefixCls;
  58. };
  59. globalConfigForApi.getRootPrefixCls = () => {
  60. // If Global prefixCls provided, use this
  61. if (globalConfigForApi.prefixCls) {
  62. return globalConfigForApi.prefixCls;
  63. }
  64. // Fallback to default prefixCls
  65. return getGlobalPrefixCls();
  66. };
  67. });
  68. let stopWatchEffect;
  69. const setGlobalConfig = params => {
  70. if (stopWatchEffect) {
  71. stopWatchEffect();
  72. }
  73. stopWatchEffect = (0, _vue.watchEffect)(() => {
  74. (0, _extends2.default)(globalConfigBySet, (0, _vue.reactive)(params));
  75. (0, _extends2.default)(globalConfigForApi, (0, _vue.reactive)(params));
  76. });
  77. if (params.theme) {
  78. (0, _cssVariables.registerTheme)(getGlobalPrefixCls(), params.theme);
  79. }
  80. };
  81. const globalConfig = () => ({
  82. getPrefixCls: (suffixCls, customizePrefixCls) => {
  83. if (customizePrefixCls) return customizePrefixCls;
  84. return suffixCls ? `${getGlobalPrefixCls()}-${suffixCls}` : getGlobalPrefixCls();
  85. },
  86. getIconPrefixCls: getGlobalIconPrefixCls,
  87. getRootPrefixCls: () => {
  88. // If Global prefixCls provided, use this
  89. if (globalConfigForApi.prefixCls) {
  90. return globalConfigForApi.prefixCls;
  91. }
  92. // Fallback to default prefixCls
  93. return getGlobalPrefixCls();
  94. }
  95. });
  96. exports.globalConfig = globalConfig;
  97. const ConfigProvider = (0, _vue.defineComponent)({
  98. compatConfig: {
  99. MODE: 3
  100. },
  101. name: 'AConfigProvider',
  102. inheritAttrs: false,
  103. props: (0, _context.configProviderProps)(),
  104. setup(props, _ref) {
  105. let {
  106. slots
  107. } = _ref;
  108. const parentContext = (0, _context.useConfigContextInject)();
  109. const getPrefixCls = (suffixCls, customizePrefixCls) => {
  110. const {
  111. prefixCls = 'ant'
  112. } = props;
  113. if (customizePrefixCls) return customizePrefixCls;
  114. const mergedPrefixCls = prefixCls || parentContext.getPrefixCls('');
  115. return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls;
  116. };
  117. const iconPrefixCls = (0, _vue.computed)(() => props.iconPrefixCls || parentContext.iconPrefixCls.value || _context.defaultIconPrefixCls);
  118. const shouldWrapSSR = (0, _vue.computed)(() => iconPrefixCls.value !== parentContext.iconPrefixCls.value);
  119. const csp = (0, _vue.computed)(() => {
  120. var _a;
  121. return props.csp || ((_a = parentContext.csp) === null || _a === void 0 ? void 0 : _a.value);
  122. });
  123. const wrapSSR = (0, _style.default)(iconPrefixCls);
  124. const mergedTheme = (0, _useTheme.default)((0, _vue.computed)(() => props.theme), (0, _vue.computed)(() => {
  125. var _a;
  126. return (_a = parentContext.theme) === null || _a === void 0 ? void 0 : _a.value;
  127. }));
  128. const renderEmptyComponent = name => {
  129. const renderEmpty = props.renderEmpty || slots.renderEmpty || parentContext.renderEmpty || _renderEmpty.default;
  130. return renderEmpty(name);
  131. };
  132. const autoInsertSpaceInButton = (0, _vue.computed)(() => {
  133. var _a, _b;
  134. return (_a = props.autoInsertSpaceInButton) !== null && _a !== void 0 ? _a : (_b = parentContext.autoInsertSpaceInButton) === null || _b === void 0 ? void 0 : _b.value;
  135. });
  136. const locale = (0, _vue.computed)(() => {
  137. var _a;
  138. return props.locale || ((_a = parentContext.locale) === null || _a === void 0 ? void 0 : _a.value);
  139. });
  140. (0, _vue.watch)(locale, () => {
  141. globalConfigBySet.locale = locale.value;
  142. }, {
  143. immediate: true
  144. });
  145. const direction = (0, _vue.computed)(() => {
  146. var _a;
  147. return props.direction || ((_a = parentContext.direction) === null || _a === void 0 ? void 0 : _a.value);
  148. });
  149. const space = (0, _vue.computed)(() => {
  150. var _a, _b;
  151. return (_a = props.space) !== null && _a !== void 0 ? _a : (_b = parentContext.space) === null || _b === void 0 ? void 0 : _b.value;
  152. });
  153. const virtual = (0, _vue.computed)(() => {
  154. var _a, _b;
  155. return (_a = props.virtual) !== null && _a !== void 0 ? _a : (_b = parentContext.virtual) === null || _b === void 0 ? void 0 : _b.value;
  156. });
  157. const dropdownMatchSelectWidth = (0, _vue.computed)(() => {
  158. var _a, _b;
  159. return (_a = props.dropdownMatchSelectWidth) !== null && _a !== void 0 ? _a : (_b = parentContext.dropdownMatchSelectWidth) === null || _b === void 0 ? void 0 : _b.value;
  160. });
  161. const getTargetContainer = (0, _vue.computed)(() => {
  162. var _a;
  163. return props.getTargetContainer !== undefined ? props.getTargetContainer : (_a = parentContext.getTargetContainer) === null || _a === void 0 ? void 0 : _a.value;
  164. });
  165. const getPopupContainer = (0, _vue.computed)(() => {
  166. var _a;
  167. return props.getPopupContainer !== undefined ? props.getPopupContainer : (_a = parentContext.getPopupContainer) === null || _a === void 0 ? void 0 : _a.value;
  168. });
  169. const pageHeader = (0, _vue.computed)(() => {
  170. var _a;
  171. return props.pageHeader !== undefined ? props.pageHeader : (_a = parentContext.pageHeader) === null || _a === void 0 ? void 0 : _a.value;
  172. });
  173. const input = (0, _vue.computed)(() => {
  174. var _a;
  175. return props.input !== undefined ? props.input : (_a = parentContext.input) === null || _a === void 0 ? void 0 : _a.value;
  176. });
  177. const pagination = (0, _vue.computed)(() => {
  178. var _a;
  179. return props.pagination !== undefined ? props.pagination : (_a = parentContext.pagination) === null || _a === void 0 ? void 0 : _a.value;
  180. });
  181. const form = (0, _vue.computed)(() => {
  182. var _a;
  183. return props.form !== undefined ? props.form : (_a = parentContext.form) === null || _a === void 0 ? void 0 : _a.value;
  184. });
  185. const select = (0, _vue.computed)(() => {
  186. var _a;
  187. return props.select !== undefined ? props.select : (_a = parentContext.select) === null || _a === void 0 ? void 0 : _a.value;
  188. });
  189. const componentSize = (0, _vue.computed)(() => props.componentSize);
  190. const componentDisabled = (0, _vue.computed)(() => props.componentDisabled);
  191. const wave = (0, _vue.computed)(() => {
  192. var _a, _b;
  193. return (_a = props.wave) !== null && _a !== void 0 ? _a : (_b = parentContext.wave) === null || _b === void 0 ? void 0 : _b.value;
  194. });
  195. const configProvider = {
  196. csp,
  197. autoInsertSpaceInButton,
  198. locale,
  199. direction,
  200. space,
  201. virtual,
  202. dropdownMatchSelectWidth,
  203. getPrefixCls,
  204. iconPrefixCls,
  205. theme: (0, _vue.computed)(() => {
  206. var _a, _b;
  207. return (_a = mergedTheme.value) !== null && _a !== void 0 ? _a : (_b = parentContext.theme) === null || _b === void 0 ? void 0 : _b.value;
  208. }),
  209. renderEmpty: renderEmptyComponent,
  210. getTargetContainer,
  211. getPopupContainer,
  212. pageHeader,
  213. input,
  214. pagination,
  215. form,
  216. select,
  217. componentSize,
  218. componentDisabled,
  219. transformCellText: (0, _vue.computed)(() => props.transformCellText),
  220. wave
  221. };
  222. // ================================ Dynamic theme ================================
  223. const memoTheme = (0, _vue.computed)(() => {
  224. const _a = mergedTheme.value || {},
  225. {
  226. algorithm,
  227. token
  228. } = _a,
  229. rest = __rest(_a, ["algorithm", "token"]);
  230. const themeObj = algorithm && (!Array.isArray(algorithm) || algorithm.length > 0) ? (0, _cssinjs.createTheme)(algorithm) : undefined;
  231. return (0, _extends2.default)((0, _extends2.default)({}, rest), {
  232. theme: themeObj,
  233. token: (0, _extends2.default)((0, _extends2.default)({}, _seed.default), token)
  234. });
  235. });
  236. const validateMessagesRef = (0, _vue.computed)(() => {
  237. var _a, _b;
  238. // Additional Form provider
  239. let validateMessages = {};
  240. if (locale.value) {
  241. validateMessages = ((_a = locale.value.Form) === null || _a === void 0 ? void 0 : _a.defaultValidateMessages) || ((_b = _en_US.default.Form) === null || _b === void 0 ? void 0 : _b.defaultValidateMessages) || {};
  242. }
  243. if (props.form && props.form.validateMessages) {
  244. validateMessages = (0, _extends2.default)((0, _extends2.default)({}, validateMessages), props.form.validateMessages);
  245. }
  246. return validateMessages;
  247. });
  248. (0, _context.useConfigContextProvider)(configProvider);
  249. (0, _context.useProvideGlobalForm)({
  250. validateMessages: validateMessagesRef
  251. });
  252. (0, _SizeContext.useProviderSize)(componentSize);
  253. (0, _DisabledContext.useProviderDisabled)(componentDisabled);
  254. const renderProvider = legacyLocale => {
  255. var _a, _b;
  256. let childNode = shouldWrapSSR.value ? wrapSSR((_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)) : (_b = slots.default) === null || _b === void 0 ? void 0 : _b.call(slots);
  257. if (props.theme) {
  258. const _childNode = function () {
  259. return childNode;
  260. }();
  261. childNode = (0, _vue.createVNode)(_internal.DesignTokenProvider, {
  262. "value": memoTheme.value
  263. }, {
  264. default: () => [_childNode]
  265. });
  266. }
  267. return (0, _vue.createVNode)(_localeProvider.default, {
  268. "locale": locale.value || legacyLocale,
  269. "ANT_MARK__": _localeProvider.ANT_MARK
  270. }, {
  271. default: () => [childNode]
  272. });
  273. };
  274. (0, _vue.watchEffect)(() => {
  275. if (direction.value) {
  276. _message.default.config({
  277. rtl: direction.value === 'rtl'
  278. });
  279. _notification.default.config({
  280. rtl: direction.value === 'rtl'
  281. });
  282. }
  283. });
  284. return () => (0, _vue.createVNode)(_LocaleReceiver.default, {
  285. "children": (_, __, legacyLocale) => renderProvider(legacyLocale)
  286. }, null);
  287. }
  288. });
  289. ConfigProvider.config = setGlobalConfig;
  290. ConfigProvider.install = function (app) {
  291. app.component(ConfigProvider.name, ConfigProvider);
  292. };
  293. var _default = exports.default = ConfigProvider;