@4399ywkf/core 5.0.20 → 5.0.21
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.js +35 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3659,11 +3659,13 @@ function buildImports(opts) {
|
|
|
3659
3659
|
"useCallback",
|
|
3660
3660
|
"useEffect",
|
|
3661
3661
|
"useMemo",
|
|
3662
|
+
"useState",
|
|
3662
3663
|
...opts.cssVar ? ["useLayoutEffect", "useRef"] : [],
|
|
3663
3664
|
"type ReactNode"
|
|
3664
3665
|
];
|
|
3665
3666
|
const antdStyleImports = [
|
|
3666
3667
|
"ThemeProvider as AntdThemeProvider",
|
|
3668
|
+
"StyleProvider",
|
|
3667
3669
|
"type GetAntdTheme",
|
|
3668
3670
|
...opts.globalReset ? ["createGlobalStyle", "css"] : []
|
|
3669
3671
|
];
|
|
@@ -3904,9 +3906,21 @@ function buildWrapperCode(opts) {
|
|
|
3904
3906
|
const childrenSlot = cssVar ? `<div ref={containerRef} style={{ display: "contents" }}>
|
|
3905
3907
|
{children}
|
|
3906
3908
|
</div>` : "{children}";
|
|
3909
|
+
const antdProvider = `<AntdThemeProvider
|
|
3910
|
+
prefixCls={RUNTIME_PREFIX_CLS}
|
|
3911
|
+
appearance={resolvedAppearance}
|
|
3912
|
+
themeMode={appearance}
|
|
3913
|
+
theme={theme}${cssVar ? "\n customToken={{ cssVar: true }}" : ""}
|
|
3914
|
+
>
|
|
3915
|
+
${globalReset ? "<GlobalReset />" : ""}
|
|
3916
|
+
${childrenSlot}
|
|
3917
|
+
</AntdThemeProvider>`;
|
|
3907
3918
|
return `
|
|
3908
3919
|
// \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
|
|
3909
3920
|
|
|
3921
|
+
// \u8FD0\u884C\u65F6\u5224\u65AD\u662F\u5426\u5904\u4E8E Garfish \u5B50\u5E94\u7528\u73AF\u5883\uFF0C\u540C\u4E00 bundle \u652F\u6301\u72EC\u7ACB\u90E8\u7F72\u4E0E\u5FAE\u524D\u7AEF\u4E24\u79CD\u6A21\u5F0F\u3002
|
|
3922
|
+
const IS_MICRO_APP = typeof window !== "undefined" && !!(window as any).__GARFISH__;
|
|
3923
|
+
|
|
3910
3924
|
const RUNTIME_PREFIX_CLS = typeof process !== "undefined"
|
|
3911
3925
|
&& process.env?.YWKF_PREFIX_CLS
|
|
3912
3926
|
|| "${prefixCls}";
|
|
@@ -3921,6 +3935,21 @@ export function ThemeWrapper({ children }: ThemeWrapperProps) {${refLine}
|
|
|
3921
3935
|
shallow,
|
|
3922
3936
|
);${cssVarSyncLine}${appearanceSyncLine}${externalThemeLine}
|
|
3923
3937
|
|
|
3938
|
+
// \u5FAE\u524D\u7AEF\u6A21\u5F0F\u4E0B\uFF0C\u5C06 CSS-in-JS \u6837\u5F0F\u6CE8\u5165\u5230 Garfish \u5B50\u5E94\u7528\u5BB9\u5668\u800C\u975E document.head\uFF0C
|
|
3939
|
+
// \u907F\u514D\u4E0E\u4E3B\u5E94\u7528\u5171\u4EAB\u7684 @ant-design/cssinjs StyleContext \u4EA7\u751F\u51B2\u7A81\u3002
|
|
3940
|
+
// useState lazy initializer \u540C\u6B65\u8BFB\u53D6\uFF08Garfish \u6302\u8F7D\u65F6\u5BB9\u5668\u5DF2\u63D0\u524D\u521B\u5EFA\uFF09\uFF0C
|
|
3941
|
+
// useEffect \u515C\u5E95\u5904\u7406\u6781\u7AEF\u7ADE\u6001\uFF08\u5982 SSR hydration\uFF09\u3002
|
|
3942
|
+
const [styleContainer, setStyleContainer] = useState<HTMLElement | undefined>(() => {
|
|
3943
|
+
if (!IS_MICRO_APP || typeof document === "undefined") return undefined;
|
|
3944
|
+
return document.getElementById(RUNTIME_PREFIX_CLS)?.parentElement ?? undefined;
|
|
3945
|
+
});
|
|
3946
|
+
|
|
3947
|
+
useEffect(() => {
|
|
3948
|
+
if (!IS_MICRO_APP) return;
|
|
3949
|
+
const el = document.getElementById(RUNTIME_PREFIX_CLS)?.parentElement;
|
|
3950
|
+
if (el) setStyleContainer(el);
|
|
3951
|
+
}, []);
|
|
3952
|
+
|
|
3924
3953
|
const resolvedAppearance = useMemo(() => {
|
|
3925
3954
|
if (appearance !== "auto") return appearance;
|
|
3926
3955
|
if (typeof window === "undefined") return "light";
|
|
@@ -3936,17 +3965,13 @@ export function ThemeWrapper({ children }: ThemeWrapperProps) {${refLine}
|
|
|
3936
3965
|
[primaryColor, neutralColor],
|
|
3937
3966
|
);
|
|
3938
3967
|
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
prefixCls={RUNTIME_PREFIX_CLS}
|
|
3942
|
-
appearance={resolvedAppearance}
|
|
3943
|
-
themeMode={appearance}
|
|
3944
|
-
theme={theme}${cssVar ? "\n customToken={{ cssVar: true }}" : ""}
|
|
3945
|
-
>
|
|
3946
|
-
${globalReset ? "<GlobalReset />" : ""}
|
|
3947
|
-
${childrenSlot}
|
|
3948
|
-
</AntdThemeProvider>
|
|
3968
|
+
const provider = (
|
|
3969
|
+
${antdProvider}
|
|
3949
3970
|
);
|
|
3971
|
+
|
|
3972
|
+
return IS_MICRO_APP && styleContainer ? (
|
|
3973
|
+
<StyleProvider container={styleContainer}>{provider}</StyleProvider>
|
|
3974
|
+
) : provider;
|
|
3950
3975
|
}
|
|
3951
3976
|
|
|
3952
3977
|
export default ThemeWrapper;
|