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