@4399ywkf/core 5.0.21 → 5.0.23
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 +45 -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 = [
|
|
@@ -3791,7 +3797,6 @@ const GlobalReset = createGlobalStyle(({ theme }) => css\`
|
|
|
3791
3797
|
}
|
|
3792
3798
|
|
|
3793
3799
|
::selection {
|
|
3794
|
-
color: #000;
|
|
3795
3800
|
-webkit-text-fill-color: unset !important;
|
|
3796
3801
|
}
|
|
3797
3802
|
\`);`;
|
|
@@ -3898,23 +3903,50 @@ function useExternalTheme() {
|
|
|
3898
3903
|
}, []);
|
|
3899
3904
|
}`;
|
|
3900
3905
|
function buildWrapperCode(opts) {
|
|
3901
|
-
const { darkMode, cssVar, globalReset, externalTheme, prefixCls } = opts;
|
|
3902
|
-
const
|
|
3906
|
+
const { darkMode, cssVar, globalReset, externalTheme, prefixCls, scopePopupContainer } = opts;
|
|
3907
|
+
const cssVarRefLine = cssVar ? "\n const containerRef = useRef<HTMLDivElement>(null);" : "";
|
|
3908
|
+
const popupRefLine = scopePopupContainer ? "\n const popupContainerRef = useRef<HTMLDivElement>(null);" : "";
|
|
3903
3909
|
const cssVarSyncLine = cssVar ? "\n useCssVarSync(containerRef);" : "";
|
|
3904
3910
|
const appearanceSyncLine = darkMode ? "\n useAppearanceSync(appearance);" : "";
|
|
3905
3911
|
const externalThemeLine = externalTheme ? "\n useExternalTheme();" : "";
|
|
3912
|
+
const getPopupContainerLine = scopePopupContainer ? `
|
|
3913
|
+
// \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
|
|
3914
|
+
// \u5FAE\u524D\u7AEF\u6A21\u5F0F\u4E0B\u4F18\u5148\u4F7F\u7528 styleContainer\uFF08\u5B50\u5E94\u7528\u6839\u5BB9\u5668\uFF09\uFF0C
|
|
3915
|
+
// \u666E\u901A\u6A21\u5F0F\u4E0B\u4F7F\u7528 popupContainerRef \u6240\u6307\u5411\u7684\u5305\u88C5 div\u3002
|
|
3916
|
+
const getPopupContainer = useCallback(
|
|
3917
|
+
(): HTMLElement =>
|
|
3918
|
+
(IS_MICRO_APP ? styleContainer : popupContainerRef.current) ?? document.body,
|
|
3919
|
+
[styleContainer],
|
|
3920
|
+
);` : "";
|
|
3906
3921
|
const childrenSlot = cssVar ? `<div ref={containerRef} style={{ display: "contents" }}>
|
|
3907
3922
|
{children}
|
|
3908
3923
|
</div>` : "{children}";
|
|
3924
|
+
const getPopupContainerProp = scopePopupContainer ? "\n getPopupContainer={getPopupContainer}" : "";
|
|
3909
3925
|
const antdProvider = `<AntdThemeProvider
|
|
3910
3926
|
prefixCls={RUNTIME_PREFIX_CLS}
|
|
3911
3927
|
appearance={resolvedAppearance}
|
|
3912
3928
|
themeMode={appearance}
|
|
3913
|
-
theme={theme}${cssVar ? "\n customToken={{ cssVar: true }}" : ""}
|
|
3929
|
+
theme={theme}${cssVar ? "\n customToken={{ cssVar: true }}" : ""}${getPopupContainerProp}
|
|
3914
3930
|
>
|
|
3915
3931
|
${globalReset ? "<GlobalReset />" : ""}
|
|
3916
3932
|
${childrenSlot}
|
|
3917
3933
|
</AntdThemeProvider>`;
|
|
3934
|
+
const wrapperOpen = scopePopupContainer ? `<div
|
|
3935
|
+
ref={popupContainerRef}
|
|
3936
|
+
data-ywkf-root
|
|
3937
|
+
style={{ position: "relative", height: "100%" }}
|
|
3938
|
+
>` : "";
|
|
3939
|
+
const wrapperClose = scopePopupContainer ? `</div>` : "";
|
|
3940
|
+
const innerReturn = `IS_MICRO_APP && styleContainer ? (
|
|
3941
|
+
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3942
|
+
) : provider`;
|
|
3943
|
+
const returnBody = scopePopupContainer ? `(
|
|
3944
|
+
${wrapperOpen}
|
|
3945
|
+
{IS_MICRO_APP && styleContainer ? (
|
|
3946
|
+
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3947
|
+
) : provider}
|
|
3948
|
+
${wrapperClose}
|
|
3949
|
+
)` : `(${innerReturn})`;
|
|
3918
3950
|
return `
|
|
3919
3951
|
// \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
|
|
3920
3952
|
|
|
@@ -3929,7 +3961,7 @@ interface ThemeWrapperProps {
|
|
|
3929
3961
|
children: ReactNode;
|
|
3930
3962
|
}
|
|
3931
3963
|
|
|
3932
|
-
export function ThemeWrapper({ children }: ThemeWrapperProps) {${
|
|
3964
|
+
export function ThemeWrapper({ children }: ThemeWrapperProps) {${cssVarRefLine}${popupRefLine}
|
|
3933
3965
|
const { appearance, primaryColor, neutralColor } = useThemeStore(
|
|
3934
3966
|
(s) => ({ appearance: s.appearance, primaryColor: s.primaryColor, neutralColor: s.neutralColor }),
|
|
3935
3967
|
shallow,
|
|
@@ -3964,14 +3996,12 @@ export function ThemeWrapper({ children }: ThemeWrapperProps) {${refLine}
|
|
|
3964
3996
|
}),
|
|
3965
3997
|
[primaryColor, neutralColor],
|
|
3966
3998
|
);
|
|
3967
|
-
|
|
3999
|
+
${getPopupContainerLine}
|
|
3968
4000
|
const provider = (
|
|
3969
4001
|
${antdProvider}
|
|
3970
4002
|
);
|
|
3971
4003
|
|
|
3972
|
-
return
|
|
3973
|
-
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3974
|
-
) : provider;
|
|
4004
|
+
return ${returnBody};
|
|
3975
4005
|
}
|
|
3976
4006
|
|
|
3977
4007
|
export default ThemeWrapper;
|