UNPKG

@flatbiz/antd

Version:
133 lines (124 loc) 4.22 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { _ as _objectWithoutProperties, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BspM60Sw.js'; import { useMemo } from 'react'; import { ConfigProvider } from 'antd'; import enUS from 'antd/es/locale/en_US.js'; import zhCN from 'antd/es/locale/zh_CN.js'; import dayjs from 'dayjs'; import advancedFormat from 'dayjs/plugin/advancedFormat.js'; import customParseFormat from 'dayjs/plugin/customParseFormat.js'; import localeData from 'dayjs/plugin/localeData.js'; import dayjsUtc from 'dayjs/plugin/utc.js'; import weekday from 'dayjs/plugin/weekday.js'; import weekOfYear from 'dayjs/plugin/weekOfYear.js'; import weekYear from 'dayjs/plugin/weekYear.js'; import { extend } from '@dimjs/utils/extend/extend'; import { fbaHooks } from './fba-hooks/index.js'; import { f as fbaUtils } from './fba-utils-CusZeveq.js'; import 'dayjs/locale/en.js'; import 'dayjs/locale/zh-cn.js'; import { jsx } from 'react/jsx-runtime'; var en = { TreeWrapper: { /** 数据加载异常,默认文案 */ requestError: '数据加载异常...' }, FbaDialogModal: { cancelText: 'cancel' } }; var zhCn = { TreeWrapper: { /** 数据加载异常,默认文案 */ requestError: '数据加载异常...' }, FbaDialogModal: { cancelText: '取消' } }; /** * 设置 @flatbiz/antd中的国际化语言 * @param locale * @param customLocaleMessage */ var setFbaLocaleMessage = function setFbaLocaleMessage(locale, customLocaleMessage) { var localeMessage = zhCn; if (locale === 'en') { localeMessage = en; } window['__fba_locale_message'] = extend(true, {}, localeMessage, customLocaleMessage); }; /** * 读取 @flatbiz/antd中的国际化语言 * @param key * @returns */ var getFbaLocaleMessage = function getFbaLocaleMessage() { var localeMessage = window['__fba_locale_message']; return localeMessage || {}; }; var _excluded = ["locale"]; dayjs.extend(customParseFormat); dayjs.extend(advancedFormat); dayjs.extend(weekday); dayjs.extend(localeData); dayjs.extend(weekOfYear); dayjs.extend(weekYear); dayjs.extend(dayjsUtc); var localeMap = { en: { dayjs: 'en', antd: enUS }, 'zh-cn': { dayjs: 'zh-cn', antd: zhCN } }; /** * antd ConfigProvider 扩展类 * ``` * 1. 新增监听辅助行为,移除复制文本中前后空格能力 * ``` */ var ConfigProviderWrapper = function ConfigProviderWrapper(props) { var locale = props.locale, otherProps = _objectWithoutProperties(props, _excluded); var localeNew = locale || 'zh-cn'; fbaHooks.useEffectCustom(function () { setFbaLocaleMessage(localeNew, props.customLocaleMessage); dayjs.locale(localeMap[localeNew].dayjs || localeMap['zh-cn'].dayjs); }, []); fbaHooks.useCopyRemoveSpace({ ignoreClass: props.copyOperateIgnoreClass }); var otherPropsNew = useMemo(function () { var _otherProps$theme, _otherProps$theme2; var customAntdTheme = fbaUtils.getCustomAntdTheme(); if (!customAntdTheme) { return otherProps; } var token = (otherProps === null || otherProps === void 0 || (_otherProps$theme = otherProps.theme) === null || _otherProps$theme === void 0 ? void 0 : _otherProps$theme.token) || customAntdTheme.token; var components = (otherProps === null || otherProps === void 0 || (_otherProps$theme2 = otherProps.theme) === null || _otherProps$theme2 === void 0 ? void 0 : _otherProps$theme2.components) || customAntdTheme.components; if (!token && !components) { return otherProps; } return _objectSpread2(_objectSpread2({}, otherProps), {}, { theme: _objectSpread2(_objectSpread2({}, otherProps === null || otherProps === void 0 ? void 0 : otherProps.theme), {}, { token: token, components: components }) }); }, [otherProps]); return /*#__PURE__*/jsx(ConfigProvider, _objectSpread2(_objectSpread2({ componentSize: 'middle', space: { size: 'middle' } }, otherPropsNew), {}, { locale: localeMap[localeNew].antd || localeMap['zh-cn'].antd, children: props.children })); }; export { ConfigProviderWrapper as C, getFbaLocaleMessage as g }; //# sourceMappingURL=config-provider-wrapper-Bxh9JdL4.js.map