@anjianshi/utils 3.0.5 → 3.0.7
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 +6 -9
- package/env-react/emotion.jsx +7 -13
- package/env-react/hooks.js +1 -1
- package/package.json +5 -5
package/env-react/emotion.d.ts
CHANGED
|
@@ -4,24 +4,21 @@
|
|
|
4
4
|
*
|
|
5
5
|
* 使用前提:
|
|
6
6
|
* 1. 只支持浏览器渲染
|
|
7
|
-
* 2.
|
|
8
|
-
* 3.
|
|
9
|
-
*
|
|
7
|
+
* 2. 使用 EmotionCacheProvider 组件包裹 App 根元素
|
|
8
|
+
* 3. vite config 需配置 `optimizeDeps: { extensions: ['.jsx'] }`。
|
|
9
|
+
* 因为此文件是 jsx 文件,@vitejs/plugin-react-swc 无法处理此文件对其他类库的引用,
|
|
10
|
+
* 需要 vite 对引用进行转换,不然会引不到类库内容。
|
|
11
|
+
* 详见:https://github.com/vitejs/vite/issues/12172
|
|
10
12
|
*
|
|
11
13
|
* 来自:
|
|
12
14
|
* https://github.com/emotion-js/emotion/issues/1853#issuecomment-623349622
|
|
13
15
|
*/
|
|
14
16
|
import { type EmotionCache } from '@emotion/react';
|
|
15
|
-
import type
|
|
16
|
-
import type { insertStyles as insertStylesT } from '@emotion/utils';
|
|
17
|
+
import { type CSSInterpolation } from '@emotion/serialize';
|
|
17
18
|
export declare const useEmotionCache: () => EmotionCache | undefined;
|
|
18
19
|
export declare const EmotionCacheProvider: import("react").FC<{
|
|
19
20
|
children: React.ReactNode;
|
|
20
21
|
} & import("react").RefAttributes<any>> | import("react").ForwardRefExoticComponent<{
|
|
21
22
|
children: React.ReactNode;
|
|
22
23
|
} & 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
24
|
export declare function useEmotionClassName(): (...args: CSSInterpolation[]) => string;
|
|
27
|
-
export {};
|
package/env-react/emotion.jsx
CHANGED
|
@@ -4,26 +4,24 @@
|
|
|
4
4
|
*
|
|
5
5
|
* 使用前提:
|
|
6
6
|
* 1. 只支持浏览器渲染
|
|
7
|
-
* 2.
|
|
8
|
-
* 3.
|
|
9
|
-
*
|
|
7
|
+
* 2. 使用 EmotionCacheProvider 组件包裹 App 根元素
|
|
8
|
+
* 3. vite config 需配置 `optimizeDeps: { extensions: ['.jsx'] }`。
|
|
9
|
+
* 因为此文件是 jsx 文件,@vitejs/plugin-react-swc 无法处理此文件对其他类库的引用,
|
|
10
|
+
* 需要 vite 对引用进行转换,不然会引不到类库内容。
|
|
11
|
+
* 详见:https://github.com/vitejs/vite/issues/12172
|
|
10
12
|
*
|
|
11
13
|
* 来自:
|
|
12
14
|
* https://github.com/emotion-js/emotion/issues/1853#issuecomment-623349622
|
|
13
15
|
*/
|
|
14
16
|
import { withEmotionCache } from '@emotion/react';
|
|
17
|
+
import { serializeStyles } from '@emotion/serialize';
|
|
18
|
+
import { insertStyles } from '@emotion/utils';
|
|
15
19
|
import { createContext, useContext, useCallback } from 'react';
|
|
16
20
|
const CacheContext = createContext(undefined);
|
|
17
21
|
export const useEmotionCache = () => useContext(CacheContext);
|
|
18
22
|
export const EmotionCacheProvider = withEmotionCache(({ children }, cache) => {
|
|
19
23
|
return <CacheContext.Provider value={cache}>{children}</CacheContext.Provider>;
|
|
20
24
|
});
|
|
21
|
-
let serializeStyles = null;
|
|
22
|
-
let insertStyles = null;
|
|
23
|
-
export function registerEmotionFunctions(serializeStylesFn, insertStylesFn) {
|
|
24
|
-
serializeStyles = serializeStylesFn;
|
|
25
|
-
insertStyles = insertStylesFn;
|
|
26
|
-
}
|
|
27
25
|
export function useEmotionClassName() {
|
|
28
26
|
const cache = useEmotionCache();
|
|
29
27
|
return useCallback((...args) => {
|
|
@@ -34,10 +32,6 @@ export function useEmotionClassName() {
|
|
|
34
32
|
}
|
|
35
33
|
throw new Error('No emotion cache found!');
|
|
36
34
|
}
|
|
37
|
-
if (!serializeStyles || !insertStyles) {
|
|
38
|
-
console.error('useEmotionClassName: need register serializeStyles() and insertStyles() functions first.');
|
|
39
|
-
return 'emotion-functions-missing';
|
|
40
|
-
}
|
|
41
35
|
const serialized = serializeStyles(args, cache.registered);
|
|
42
36
|
insertStyles(cache, serialized, false);
|
|
43
37
|
return cache.key + '-' + serialized.name;
|
package/env-react/hooks.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anjianshi/utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
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-prettier": "3.0.5",
|
|
35
|
+
"@anjianshi/presets-eslint-node": "6.0.0",
|
|
34
36
|
"@anjianshi/presets-eslint-react": "6.0.0",
|
|
37
|
+
"@anjianshi/presets-typescript": "3.2.5",
|
|
35
38
|
"@anjianshi/presets-eslint-base": "6.0.0",
|
|
36
|
-
"@anjianshi/presets-eslint-
|
|
37
|
-
"@anjianshi/presets-eslint-typescript": "6.0.0",
|
|
38
|
-
"@anjianshi/presets-prettier": "3.0.5",
|
|
39
|
-
"@anjianshi/presets-typescript": "3.2.5"
|
|
39
|
+
"@anjianshi/presets-eslint-typescript": "6.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@emotion/react": "^11.14.0",
|