@4399ywkf/core 5.0.22 → 5.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +13 -0
- package/dist/index.js +50 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -548,6 +548,19 @@ interface ThemePluginOptions {
|
|
|
548
548
|
* @default false
|
|
549
549
|
*/
|
|
550
550
|
externalTheme?: boolean;
|
|
551
|
+
/**
|
|
552
|
+
* 将 Tooltip / Dropdown / Modal 等弹层的挂载节点限定在 ThemeWrapper 容器内
|
|
553
|
+
*
|
|
554
|
+
* 解决问题:antd 弹层默认挂载到 document.body,在以下场景会导致样式失效:
|
|
555
|
+
* - 微前端子应用使用 StyleProvider 将样式注入到子应用容器,弹层挂载 body 后脱离样式范围
|
|
556
|
+
* - CSS 变量作用域被限定在特定容器,body 上的弹层无法继承
|
|
557
|
+
*
|
|
558
|
+
* 启用后会在 ThemeWrapper 内创建一个 `data-ywkf-root` 容器作为弹层挂载点,
|
|
559
|
+
* 该容器始终是 StyleProvider 的子孙节点,样式链路不会断裂。
|
|
560
|
+
*
|
|
561
|
+
* @default true
|
|
562
|
+
*/
|
|
563
|
+
scopePopupContainer?: boolean;
|
|
551
564
|
}
|
|
552
565
|
/**
|
|
553
566
|
* 响应式主题系统插件
|
package/dist/index.js
CHANGED
|
@@ -3546,7 +3546,8 @@ var themePlugin = createPlugin((options = {}) => ({
|
|
|
3546
3546
|
prefixCls = "ant",
|
|
3547
3547
|
cssVar = true,
|
|
3548
3548
|
globalReset = true,
|
|
3549
|
-
externalTheme = false
|
|
3549
|
+
externalTheme = false,
|
|
3550
|
+
scopePopupContainer = true
|
|
3550
3551
|
} = options;
|
|
3551
3552
|
const { logger } = context;
|
|
3552
3553
|
logger.info(
|
|
@@ -3577,7 +3578,8 @@ var themePlugin = createPlugin((options = {}) => ({
|
|
|
3577
3578
|
prefixCls,
|
|
3578
3579
|
cssVar,
|
|
3579
3580
|
globalReset,
|
|
3580
|
-
externalTheme
|
|
3581
|
+
externalTheme,
|
|
3582
|
+
scopePopupContainer
|
|
3581
3583
|
})
|
|
3582
3584
|
}
|
|
3583
3585
|
];
|
|
@@ -3629,11 +3631,12 @@ function generateThemeProvider(opts) {
|
|
|
3629
3631
|
prefixCls,
|
|
3630
3632
|
cssVar,
|
|
3631
3633
|
globalReset,
|
|
3632
|
-
externalTheme
|
|
3634
|
+
externalTheme,
|
|
3635
|
+
scopePopupContainer
|
|
3633
3636
|
} = opts;
|
|
3634
3637
|
const sections = [];
|
|
3635
3638
|
sections.push(`// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`);
|
|
3636
|
-
sections.push(buildImports({ globalReset, cssVar }));
|
|
3639
|
+
sections.push(buildImports({ globalReset, cssVar, scopePopupContainer }));
|
|
3637
3640
|
sections.push(TYPES_CODE);
|
|
3638
3641
|
sections.push(
|
|
3639
3642
|
buildStoreCode({ defaultAppearance, primaryColor, neutralColor })
|
|
@@ -3649,18 +3652,21 @@ function generateThemeProvider(opts) {
|
|
|
3649
3652
|
cssVar,
|
|
3650
3653
|
globalReset,
|
|
3651
3654
|
externalTheme,
|
|
3652
|
-
prefixCls
|
|
3655
|
+
prefixCls,
|
|
3656
|
+
scopePopupContainer
|
|
3653
3657
|
})
|
|
3654
3658
|
);
|
|
3655
3659
|
return sections.join("\n");
|
|
3656
3660
|
}
|
|
3657
3661
|
function buildImports(opts) {
|
|
3662
|
+
const needsRef = opts.cssVar || opts.scopePopupContainer;
|
|
3658
3663
|
const reactImports = [
|
|
3659
3664
|
"useCallback",
|
|
3660
3665
|
"useEffect",
|
|
3661
3666
|
"useMemo",
|
|
3662
3667
|
"useState",
|
|
3663
|
-
...opts.cssVar ? ["useLayoutEffect"
|
|
3668
|
+
...opts.cssVar ? ["useLayoutEffect"] : [],
|
|
3669
|
+
...needsRef ? ["useRef"] : [],
|
|
3664
3670
|
"type ReactNode"
|
|
3665
3671
|
];
|
|
3666
3672
|
const antdStyleImports = [
|
|
@@ -3671,6 +3677,7 @@ function buildImports(opts) {
|
|
|
3671
3677
|
];
|
|
3672
3678
|
return `
|
|
3673
3679
|
import React, { ${reactImports.join(", ")} } from "react";
|
|
3680
|
+
import { ConfigProvider } from "antd";
|
|
3674
3681
|
import { ${antdStyleImports.join(", ")} } from "antd-style";
|
|
3675
3682
|
import { createWithEqualityFn } from "zustand/traditional";
|
|
3676
3683
|
import { shallow } from "zustand/shallow";
|
|
@@ -3897,23 +3904,53 @@ function useExternalTheme() {
|
|
|
3897
3904
|
}, []);
|
|
3898
3905
|
}`;
|
|
3899
3906
|
function buildWrapperCode(opts) {
|
|
3900
|
-
const { darkMode, cssVar, globalReset, externalTheme, prefixCls } = opts;
|
|
3901
|
-
const
|
|
3907
|
+
const { darkMode, cssVar, globalReset, externalTheme, prefixCls, scopePopupContainer } = opts;
|
|
3908
|
+
const cssVarRefLine = cssVar ? "\n const containerRef = useRef<HTMLDivElement>(null);" : "";
|
|
3909
|
+
const popupRefLine = scopePopupContainer ? "\n const popupContainerRef = useRef<HTMLDivElement>(null);" : "";
|
|
3902
3910
|
const cssVarSyncLine = cssVar ? "\n useCssVarSync(containerRef);" : "";
|
|
3903
3911
|
const appearanceSyncLine = darkMode ? "\n useAppearanceSync(appearance);" : "";
|
|
3904
3912
|
const externalThemeLine = externalTheme ? "\n useExternalTheme();" : "";
|
|
3913
|
+
const getPopupContainerLine = scopePopupContainer ? `
|
|
3914
|
+
// \u5C06\u5F39\u5C42\u6302\u8F7D\u5230\u5BB9\u5668\u5185\u90E8\uFF0C\u786E\u4FDD\u80FD\u7EE7\u627F StyleProvider \u6CE8\u5165\u7684\u6837\u5F0F\u4E0E CSS \u53D8\u91CF\u3002
|
|
3915
|
+
// \u5FAE\u524D\u7AEF\u6A21\u5F0F\u4E0B\u4F18\u5148\u4F7F\u7528 styleContainer\uFF08\u5B50\u5E94\u7528\u6839\u5BB9\u5668\uFF09\uFF0C
|
|
3916
|
+
// \u666E\u901A\u6A21\u5F0F\u4E0B\u4F7F\u7528 popupContainerRef \u6240\u6307\u5411\u7684\u5305\u88C5 div\u3002
|
|
3917
|
+
const getPopupContainer = useCallback(
|
|
3918
|
+
(): HTMLElement =>
|
|
3919
|
+
(IS_MICRO_APP ? styleContainer : popupContainerRef.current) ?? document.body,
|
|
3920
|
+
[styleContainer],
|
|
3921
|
+
);` : "";
|
|
3905
3922
|
const childrenSlot = cssVar ? `<div ref={containerRef} style={{ display: "contents" }}>
|
|
3906
3923
|
{children}
|
|
3907
3924
|
</div>` : "{children}";
|
|
3925
|
+
const innerContent = scopePopupContainer ? `<ConfigProvider getPopupContainer={getPopupContainer}>
|
|
3926
|
+
${globalReset ? "<GlobalReset />" : ""}
|
|
3927
|
+
${childrenSlot}
|
|
3928
|
+
</ConfigProvider>` : `${globalReset ? "<GlobalReset />" : ""}
|
|
3929
|
+
${childrenSlot}`;
|
|
3908
3930
|
const antdProvider = `<AntdThemeProvider
|
|
3909
3931
|
prefixCls={RUNTIME_PREFIX_CLS}
|
|
3910
3932
|
appearance={resolvedAppearance}
|
|
3911
3933
|
themeMode={appearance}
|
|
3912
3934
|
theme={theme}${cssVar ? "\n customToken={{ cssVar: true }}" : ""}
|
|
3913
3935
|
>
|
|
3914
|
-
${
|
|
3915
|
-
${childrenSlot}
|
|
3936
|
+
${innerContent}
|
|
3916
3937
|
</AntdThemeProvider>`;
|
|
3938
|
+
const wrapperOpen = scopePopupContainer ? `<div
|
|
3939
|
+
ref={popupContainerRef}
|
|
3940
|
+
data-ywkf-root
|
|
3941
|
+
style={{ position: "relative", height: "100%" }}
|
|
3942
|
+
>` : "";
|
|
3943
|
+
const wrapperClose = scopePopupContainer ? `</div>` : "";
|
|
3944
|
+
const innerReturn = `IS_MICRO_APP && styleContainer ? (
|
|
3945
|
+
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3946
|
+
) : provider`;
|
|
3947
|
+
const returnBody = scopePopupContainer ? `(
|
|
3948
|
+
${wrapperOpen}
|
|
3949
|
+
{IS_MICRO_APP && styleContainer ? (
|
|
3950
|
+
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3951
|
+
) : provider}
|
|
3952
|
+
${wrapperClose}
|
|
3953
|
+
)` : `(${innerReturn})`;
|
|
3917
3954
|
return `
|
|
3918
3955
|
// \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 ThemeWrapper \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
3919
3956
|
|
|
@@ -3928,7 +3965,7 @@ interface ThemeWrapperProps {
|
|
|
3928
3965
|
children: ReactNode;
|
|
3929
3966
|
}
|
|
3930
3967
|
|
|
3931
|
-
export function ThemeWrapper({ children }: ThemeWrapperProps) {${
|
|
3968
|
+
export function ThemeWrapper({ children }: ThemeWrapperProps) {${cssVarRefLine}${popupRefLine}
|
|
3932
3969
|
const { appearance, primaryColor, neutralColor } = useThemeStore(
|
|
3933
3970
|
(s) => ({ appearance: s.appearance, primaryColor: s.primaryColor, neutralColor: s.neutralColor }),
|
|
3934
3971
|
shallow,
|
|
@@ -3963,14 +4000,12 @@ export function ThemeWrapper({ children }: ThemeWrapperProps) {${refLine}
|
|
|
3963
4000
|
}),
|
|
3964
4001
|
[primaryColor, neutralColor],
|
|
3965
4002
|
);
|
|
3966
|
-
|
|
4003
|
+
${getPopupContainerLine}
|
|
3967
4004
|
const provider = (
|
|
3968
4005
|
${antdProvider}
|
|
3969
4006
|
);
|
|
3970
4007
|
|
|
3971
|
-
return
|
|
3972
|
-
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3973
|
-
) : provider;
|
|
4008
|
+
return ${returnBody};
|
|
3974
4009
|
}
|
|
3975
4010
|
|
|
3976
4011
|
export default ThemeWrapper;
|