@anjianshi/utils 3.0.4 → 3.0.5
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/env-react/emotion.d.ts +8 -2
- package/env-react/emotion.jsx +13 -3
- package/package.json +5 -5
package/env-react/emotion.d.ts
CHANGED
|
@@ -5,17 +5,23 @@
|
|
|
5
5
|
* 使用前提:
|
|
6
6
|
* 1. 只支持浏览器渲染
|
|
7
7
|
* 2. 安装 @emotion/serialize、@emotion/utils
|
|
8
|
-
*
|
|
8
|
+
* 3. 调用 registerEmotionFunctions() 注册 @emotion/serialize 的 serializeStyles() 和 @emotion/utils 的 insertStyles() 函数
|
|
9
|
+
* 4. 用 EmotionCacheProvider 包裹 App 根元素
|
|
9
10
|
*
|
|
10
11
|
* 来自:
|
|
11
12
|
* https://github.com/emotion-js/emotion/issues/1853#issuecomment-623349622
|
|
12
13
|
*/
|
|
13
14
|
import { type EmotionCache } from '@emotion/react';
|
|
14
|
-
import {
|
|
15
|
+
import type { CSSInterpolation, serializeStyles as serializeStylesT } from '@emotion/serialize';
|
|
16
|
+
import type { insertStyles as insertStylesT } from '@emotion/utils';
|
|
15
17
|
export declare const useEmotionCache: () => EmotionCache | undefined;
|
|
16
18
|
export declare const EmotionCacheProvider: import("react").FC<{
|
|
17
19
|
children: React.ReactNode;
|
|
18
20
|
} & import("react").RefAttributes<any>> | import("react").ForwardRefExoticComponent<{
|
|
19
21
|
children: React.ReactNode;
|
|
20
22
|
} & import("react").RefAttributes<any>>;
|
|
23
|
+
declare let serializeStyles: typeof serializeStylesT | null;
|
|
24
|
+
declare let insertStyles: typeof insertStylesT | null;
|
|
25
|
+
export declare function registerEmotionFunctions(serializeStylesFn: typeof serializeStyles, insertStylesFn: typeof insertStyles): void;
|
|
21
26
|
export declare function useEmotionClassName(): (...args: CSSInterpolation[]) => string;
|
|
27
|
+
export {};
|
package/env-react/emotion.jsx
CHANGED
|
@@ -5,29 +5,39 @@
|
|
|
5
5
|
* 使用前提:
|
|
6
6
|
* 1. 只支持浏览器渲染
|
|
7
7
|
* 2. 安装 @emotion/serialize、@emotion/utils
|
|
8
|
-
*
|
|
8
|
+
* 3. 调用 registerEmotionFunctions() 注册 @emotion/serialize 的 serializeStyles() 和 @emotion/utils 的 insertStyles() 函数
|
|
9
|
+
* 4. 用 EmotionCacheProvider 包裹 App 根元素
|
|
9
10
|
*
|
|
10
11
|
* 来自:
|
|
11
12
|
* https://github.com/emotion-js/emotion/issues/1853#issuecomment-623349622
|
|
12
13
|
*/
|
|
13
14
|
import { withEmotionCache } from '@emotion/react';
|
|
14
|
-
import { serializeStyles } from '@emotion/serialize';
|
|
15
|
-
import { insertStyles } from '@emotion/utils';
|
|
16
15
|
import { createContext, useContext, useCallback } from 'react';
|
|
17
16
|
const CacheContext = createContext(undefined);
|
|
18
17
|
export const useEmotionCache = () => useContext(CacheContext);
|
|
19
18
|
export const EmotionCacheProvider = withEmotionCache(({ children }, cache) => {
|
|
20
19
|
return <CacheContext.Provider value={cache}>{children}</CacheContext.Provider>;
|
|
21
20
|
});
|
|
21
|
+
let serializeStyles = null;
|
|
22
|
+
let insertStyles = null;
|
|
23
|
+
export function registerEmotionFunctions(serializeStylesFn, insertStylesFn) {
|
|
24
|
+
serializeStyles = serializeStylesFn;
|
|
25
|
+
insertStyles = insertStylesFn;
|
|
26
|
+
}
|
|
22
27
|
export function useEmotionClassName() {
|
|
23
28
|
const cache = useEmotionCache();
|
|
24
29
|
return useCallback((...args) => {
|
|
25
30
|
if (!cache) {
|
|
26
31
|
if (process.env.NODE_ENV === 'production') {
|
|
32
|
+
console.error('useEmotionClassName: emotion-cache-missing');
|
|
27
33
|
return 'emotion-cache-missing';
|
|
28
34
|
}
|
|
29
35
|
throw new Error('No emotion cache found!');
|
|
30
36
|
}
|
|
37
|
+
if (!serializeStyles || !insertStyles) {
|
|
38
|
+
console.error('useEmotionClassName: need register serializeStyles() and insertStyles() functions first.');
|
|
39
|
+
return 'emotion-functions-missing';
|
|
40
|
+
}
|
|
31
41
|
const serialized = serializeStyles(args, cache.registered);
|
|
32
42
|
insertStyles(cache, serialized, false);
|
|
33
43
|
return cache.key + '-' + serialized.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anjianshi/utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Common JavaScript Utils",
|
|
5
5
|
"homepage": "https://github.com/anjianshi/js-packages/utils",
|
|
6
6
|
"bugs": {
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"redis": "^5.5.6",
|
|
32
32
|
"typescript": "^5.8.3",
|
|
33
33
|
"vconsole": "^3.15.1",
|
|
34
|
-
"@anjianshi/presets-eslint-node": "6.0.0",
|
|
35
|
-
"@anjianshi/presets-eslint-base": "6.0.0",
|
|
36
34
|
"@anjianshi/presets-eslint-react": "6.0.0",
|
|
35
|
+
"@anjianshi/presets-eslint-base": "6.0.0",
|
|
36
|
+
"@anjianshi/presets-eslint-node": "6.0.0",
|
|
37
37
|
"@anjianshi/presets-eslint-typescript": "6.0.0",
|
|
38
|
-
"@anjianshi/presets-
|
|
39
|
-
"@anjianshi/presets-
|
|
38
|
+
"@anjianshi/presets-prettier": "3.0.5",
|
|
39
|
+
"@anjianshi/presets-typescript": "3.2.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@emotion/react": "^11.14.0",
|