@anjianshi/utils 3.0.6 → 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.
@@ -4,16 +4,19 @@
4
4
  *
5
5
  * 使用前提:
6
6
  * 1. 只支持浏览器渲染
7
- * 2. 调用 getEmotionCacheProvider(),传入来自 @emotion/react withEmotionCache 函数,
8
- * 并用得到的 EmotionCacheProvider 组件包裹 App 根元素
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
9
12
  *
10
13
  * 来自:
11
14
  * https://github.com/emotion-js/emotion/issues/1853#issuecomment-623349622
12
15
  */
13
- import type { EmotionCache, withEmotionCache as withEmotionCacheT } from '@emotion/react';
16
+ import { type EmotionCache } from '@emotion/react';
14
17
  import { type CSSInterpolation } from '@emotion/serialize';
15
18
  export declare const useEmotionCache: () => EmotionCache | undefined;
16
- export declare function getEmotionCacheProvider(withEmotionCache: typeof withEmotionCacheT): import("react").FC<{
19
+ export declare const EmotionCacheProvider: import("react").FC<{
17
20
  children: React.ReactNode;
18
21
  } & import("react").RefAttributes<any>> | import("react").ForwardRefExoticComponent<{
19
22
  children: React.ReactNode;
@@ -1,13 +1,27 @@
1
+ /**
2
+ * 通过 React Hook 把 emotion css 转换成 className
3
+ * (不再需要 <ClassName>)
4
+ *
5
+ * 使用前提:
6
+ * 1. 只支持浏览器渲染
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
12
+ *
13
+ * 来自:
14
+ * https://github.com/emotion-js/emotion/issues/1853#issuecomment-623349622
15
+ */
16
+ import { withEmotionCache } from '@emotion/react';
1
17
  import { serializeStyles } from '@emotion/serialize';
2
18
  import { insertStyles } from '@emotion/utils';
3
19
  import { createContext, useContext, useCallback } from 'react';
4
20
  const CacheContext = createContext(undefined);
5
21
  export const useEmotionCache = () => useContext(CacheContext);
6
- export function getEmotionCacheProvider(withEmotionCache) {
7
- return withEmotionCache(({ children }, cache) => {
8
- return <CacheContext.Provider value={cache}>{children}</CacheContext.Provider>;
9
- });
10
- }
22
+ export const EmotionCacheProvider = withEmotionCache(({ children }, cache) => {
23
+ return <CacheContext.Provider value={cache}>{children}</CacheContext.Provider>;
24
+ });
11
25
  export function useEmotionClassName() {
12
26
  const cache = useEmotionCache();
13
27
  return useCallback((...args) => {
@@ -1,4 +1,4 @@
1
- import { useRef, useCallback } from 'react';
1
+ import { useState, useEffect, useRef, useCallback } from 'react';
2
2
  /**
3
3
  * 生成一个 state 以及与其值同步的 ref
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anjianshi/utils",
3
- "version": "3.0.6",
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-eslint-node": "6.0.0",
35
34
  "@anjianshi/presets-prettier": "3.0.5",
36
- "@anjianshi/presets-eslint-typescript": "6.0.0",
35
+ "@anjianshi/presets-eslint-node": "6.0.0",
37
36
  "@anjianshi/presets-eslint-react": "6.0.0",
37
+ "@anjianshi/presets-typescript": "3.2.5",
38
38
  "@anjianshi/presets-eslint-base": "6.0.0",
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",