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