antd-img-crop 4.6.0 → 4.8.0

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/README.md CHANGED
@@ -61,45 +61,25 @@ const Demo = () => (
61
61
  | onUploadFail | `function` | - | Call when upload failed |
62
62
  | cropperProps | `object` | - | Props of [react-easy-crop] (\* [existing props] cannot be overridden) |
63
63
 
64
- ## Before antd v5
64
+ ### `ConfigProvider` not work?
65
65
 
66
- ### No style?
67
-
68
- If you use `babel-plugin-import` and no `Modal` or `Slider` were imported, please import the styles manually:
66
+ Try to set `libraryDirectory`(`'es'` or `'lib'`) to `babel-plugin-import` config, see which one will work.
69
67
 
70
68
  ```js
71
- import 'antd/es/modal/style';
72
- import 'antd/es/slider/style';
73
- ```
74
-
75
- ### ConfigProvider not work?
76
-
77
- If using `craco-antd`, please try to add `libraryDirectory: 'es'` to `craco.config.js`:
78
-
79
- ```diff
80
69
  module.exports = {
81
70
  plugins: [
82
- {
83
- plugin: CracoAntDesignPlugin,
84
- options: {
85
- // other options...
86
- + babelPluginImportOptions: {
87
- + libraryDirectory: 'es',
88
- + },
89
- },
90
- },
71
+ ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
91
72
  ],
92
73
  };
93
74
  ```
94
75
 
95
- Or if configuring `babel-plugin-import` manually, please try to set `libraryDirectory: 'es'` to `.babelrc.js`:
76
+ ## No style? (only `antd<=v4`)
77
+
78
+ If you use `antd<=v4` + `babel-plugin-import`, and no `Modal` or `Slider` were imported, please import these styles manually:
96
79
 
97
80
  ```js
98
- module.exports = {
99
- plugins: [
100
- ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
101
- ],
102
- };
81
+ import 'antd/es/modal/style';
82
+ import 'antd/es/slider/style';
103
83
  ```
104
84
 
105
85
  ## License
@@ -114,3 +94,7 @@ module.exports = {
114
94
  Try [**FUTAKE**](https://sotake.com/futake) in WeChat. A mini app for your inspiration moments. 🌈
115
95
 
116
96
  ![](https://s3.bmp.ovh/imgs/2022/07/21/452dd47aeb790abd.png)
97
+
98
+ ```
99
+
100
+ ```
package/README.zh-CN.md CHANGED
@@ -61,45 +61,32 @@ const Demo = () => (
61
61
  | onUploadFail | `function` | - | 上传失败时的回调 |
62
62
  | cropperProps | `object` | - | [react-easy-crop] 的 props(\* [已有 props] 无法重写) |
63
63
 
64
- ## antd v5 之前
65
-
66
- ### 没有样式?
64
+ ### `ConfigProvider` 无效?
67
65
 
68
- 若项目使用 `babel-plugin-import` 且未引入 `Modal` 或 `Slider`,请手动引入样式:
66
+ 尝试设置 `libraryDirectory`(`'es'` 或 `'lib'`)到 `babel-plugin-import` 的配置项,看看哪个会生效。
69
67
 
70
68
  ```js
71
- import 'antd/es/modal/style';
72
- import 'antd/es/slider/style';
73
- ```
74
-
75
- ### ConfigProvider 未生效?
76
-
77
- 若使用 `craco-antd`,请在 `craco.config.js` 中添加 `libraryDirectory: 'es'`:
78
-
79
- ```diff
80
69
  module.exports = {
81
70
  plugins: [
82
- {
83
- plugin: CracoAntDesignPlugin,
84
- options: {
85
- // 其它配置...
86
- + babelPluginImportOptions: {
87
- + libraryDirectory: 'es',
88
- + },
89
- },
90
- },
71
+ ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
91
72
  ],
92
73
  };
93
74
  ```
94
75
 
95
- 若手动配置 `babel-plugin-import`,请在 `.babelrc.js` 中设置 `libraryDirectory: 'es'`:
76
+ ## 没有样式?(仅 `antd<=v4`)
77
+
78
+ 若使用 `antd<=v4` + `babel-plugin-import`,且未引入 `Modal` 或 `Slider`,请手动引入这些样式:
96
79
 
97
80
  ```js
98
- module.exports = {
99
- plugins: [
100
- ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
101
- ],
102
- };
81
+ import 'antd/es/modal/style';
82
+ import 'antd/es/slider/style';
83
+ ```
84
+
85
+ ## 在 antd v5 之前
86
+
87
+ ```js
88
+ import 'antd/es/modal/style';
89
+ import 'antd/es/slider/style';
103
90
  ```
104
91
 
105
92
  ## 协议
@@ -18,7 +18,6 @@ var tslib = require('tslib');
18
18
  var jsxRuntime = require('react/jsx-runtime');
19
19
  var react = require('react');
20
20
  var antd = require('antd');
21
- var LocaleReceiver = require('antd/lib/locale-provider/LocaleReceiver');
22
21
  var AntModal = require('antd/lib/modal');
23
22
  var AntUpload = require('antd/lib/upload');
24
23
  var compareVersions = require('compare-versions');
@@ -79,7 +78,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
79
78
  cb.current.beforeCrop = beforeCrop;
80
79
  cb.current.onUploadFail = onUploadFail;
81
80
  /**
82
- * Upload
81
+ * upload
83
82
  */
84
83
  const [image, setImage] = react.useState('');
85
84
  const fileRef = react.useRef({});
@@ -120,11 +119,11 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
120
119
  } }) });
121
120
  }, [children]);
122
121
  /**
123
- * Crop
122
+ * crop
124
123
  */
125
124
  const easyCropRef = react.useRef({});
126
125
  /**
127
- * Modal
126
+ * modal
128
127
  */
129
128
  const modalProps = react.useMemo(() => {
130
129
  const obj = {
@@ -230,13 +229,15 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
230
229
  }
231
230
  }), type, quality);
232
231
  }), [fillColor, quality, rotate]);
233
- const getComponent = (titleOfModal) => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [uploadComponent, image && (jsxRuntime.jsx(AntModal, Object.assign({}, modalVisibleProp, { wrapClassName: `${PREFIX}-modal ${modalClassName || ''}`, title: titleOfModal, onOk: onOk, onCancel: onCancel, maskClosable: false, destroyOnClose: true }, modalProps, { children: jsxRuntime.jsx(EasyCrop$1, { ref: easyCropRef, cropperRef: cropperRef, image: image, aspect: aspect, shape: shape, grid: grid, zoom: zoom, rotate: rotate, minZoom: minZoom, maxZoom: maxZoom, cropperProps: cropperProps }) })))] }));
234
- if (modalTitle) {
235
- return getComponent(modalTitle);
236
- }
237
- return (jsxRuntime.jsx(LocaleReceiver, { children: (_, code) => {
238
- return getComponent(code === 'zh-cn' ? '编辑图片' : 'Edit image');
239
- } }));
232
+ const wrapClassName = `${PREFIX}-modal${modalClassName ? ` ${modalClassName}` : ''}`;
233
+ const title = react.useMemo(() => {
234
+ if (modalTitle) {
235
+ return modalTitle;
236
+ }
237
+ const lang = typeof window !== 'undefined' ? window.navigator.language : '';
238
+ return lang === 'zh-CN' ? '编辑图片' : 'Edit image';
239
+ }, [modalTitle]);
240
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [uploadComponent, image && (jsxRuntime.jsx(AntModal, Object.assign({}, modalVisibleProp, { wrapClassName: wrapClassName, title: title, onOk: onOk, onCancel: onCancel, maskClosable: false, destroyOnClose: true }, modalProps, { children: jsxRuntime.jsx(EasyCrop$1, { ref: easyCropRef, cropperRef: cropperRef, image: image, aspect: aspect, shape: shape, grid: grid, zoom: zoom, rotate: rotate, minZoom: minZoom, maxZoom: maxZoom, cropperProps: cropperProps }) })))] }));
240
241
  });
241
242
 
242
243
  module.exports = ImgCrop;
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
+ import { RcFile } from 'antd/es/upload/interface';
2
3
  import Cropper, { CropperProps } from 'react-easy-crop';
3
- import { RcFile } from 'antd/lib/upload/interface';
4
4
 
5
5
  type ImgCropProps = {
6
6
  aspect?: number;
@@ -14,12 +14,11 @@ import { __rest, __awaiter } from 'tslib';
14
14
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
15
15
  import { forwardRef, useState, useRef, useCallback, useImperativeHandle, memo, useMemo } from 'react';
16
16
  import { version } from 'antd';
17
- import LocaleReceiver from 'antd/lib/locale-provider/LocaleReceiver';
18
- import AntModal from 'antd/lib/modal';
19
- import AntUpload from 'antd/lib/upload';
17
+ import AntModal from 'antd/es/modal';
18
+ import AntUpload from 'antd/es/upload';
20
19
  import { compareVersions } from 'compare-versions';
21
20
  import Cropper from 'react-easy-crop';
22
- import AntSlider from 'antd/lib/slider';
21
+ import AntSlider from 'antd/es/slider';
23
22
 
24
23
  const PREFIX = 'img-crop';
25
24
  const INIT_ZOOM = 1;
@@ -75,7 +74,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
75
74
  cb.current.beforeCrop = beforeCrop;
76
75
  cb.current.onUploadFail = onUploadFail;
77
76
  /**
78
- * Upload
77
+ * upload
79
78
  */
80
79
  const [image, setImage] = useState('');
81
80
  const fileRef = useRef({});
@@ -116,11 +115,11 @@ const ImgCrop = forwardRef((props, cropperRef) => {
116
115
  } }) });
117
116
  }, [children]);
118
117
  /**
119
- * Crop
118
+ * crop
120
119
  */
121
120
  const easyCropRef = useRef({});
122
121
  /**
123
- * Modal
122
+ * modal
124
123
  */
125
124
  const modalProps = useMemo(() => {
126
125
  const obj = {
@@ -226,13 +225,15 @@ const ImgCrop = forwardRef((props, cropperRef) => {
226
225
  }
227
226
  }), type, quality);
228
227
  }), [fillColor, quality, rotate]);
229
- const getComponent = (titleOfModal) => (jsxs(Fragment, { children: [uploadComponent, image && (jsx(AntModal, Object.assign({}, modalVisibleProp, { wrapClassName: `${PREFIX}-modal ${modalClassName || ''}`, title: titleOfModal, onOk: onOk, onCancel: onCancel, maskClosable: false, destroyOnClose: true }, modalProps, { children: jsx(EasyCrop$1, { ref: easyCropRef, cropperRef: cropperRef, image: image, aspect: aspect, shape: shape, grid: grid, zoom: zoom, rotate: rotate, minZoom: minZoom, maxZoom: maxZoom, cropperProps: cropperProps }) })))] }));
230
- if (modalTitle) {
231
- return getComponent(modalTitle);
232
- }
233
- return (jsx(LocaleReceiver, { children: (_, code) => {
234
- return getComponent(code === 'zh-cn' ? '编辑图片' : 'Edit image');
235
- } }));
228
+ const wrapClassName = `${PREFIX}-modal${modalClassName ? ` ${modalClassName}` : ''}`;
229
+ const title = useMemo(() => {
230
+ if (modalTitle) {
231
+ return modalTitle;
232
+ }
233
+ const lang = typeof window !== 'undefined' ? window.navigator.language : '';
234
+ return lang === 'zh-CN' ? '编辑图片' : 'Edit image';
235
+ }, [modalTitle]);
236
+ return (jsxs(Fragment, { children: [uploadComponent, image && (jsx(AntModal, Object.assign({}, modalVisibleProp, { wrapClassName: wrapClassName, title: title, onOk: onOk, onCancel: onCancel, maskClosable: false, destroyOnClose: true }, modalProps, { children: jsx(EasyCrop$1, { ref: easyCropRef, cropperRef: cropperRef, image: image, aspect: aspect, shape: shape, grid: grid, zoom: zoom, rotate: rotate, minZoom: minZoom, maxZoom: maxZoom, cropperProps: cropperProps }) })))] }));
236
237
  });
237
238
 
238
239
  export { ImgCrop as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-img-crop",
3
- "version": "4.6.0",
3
+ "version": "4.8.0",
4
4
  "description": "An image cropper for Ant Design Upload",
5
5
  "keywords": [
6
6
  "react",
@@ -29,29 +29,30 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "compare-versions": "6.0.0-rc.1",
32
- "react-easy-crop": "^4.6.3",
32
+ "react-easy-crop": "^4.7.4",
33
33
  "tslib": "^2.5.0"
34
34
  },
35
35
  "devDependencies": {
36
+ "@rollup/plugin-replace": "^5.0.2",
36
37
  "@rollup/plugin-typescript": "^11.0.0",
37
- "@trivago/prettier-plugin-sort-imports": "^4.0.0",
38
- "@types/node": "^18.11.18",
39
- "@types/react": "^18.0.27",
40
- "@types/react-dom": "^18.0.10",
38
+ "@trivago/prettier-plugin-sort-imports": "^4.1.1",
39
+ "@types/node": "^18.14.6",
40
+ "@types/react": "^18.0.28",
41
+ "@types/react-dom": "^18.0.11",
41
42
  "@types/rollup-plugin-less": "^1.1.2",
42
- "@vitejs/plugin-react": "^3.0.1",
43
- "antd": "^5.1.6",
44
- "eslint": "^8.32.0",
43
+ "@vitejs/plugin-react": "^3.1.0",
44
+ "antd": "^5.2.3",
45
+ "eslint": "^8.35.0",
45
46
  "eslint-config-prettier": "^8.6.0",
46
47
  "eslint-config-react-app": "^7.0.1",
47
- "prettier": "^2.8.3",
48
+ "prettier": "^2.8.4",
48
49
  "react": "^18.2.0",
49
50
  "react-dom": "^18.2.0",
50
- "rollup": "3.11.0",
51
- "rollup-plugin-dts": "^5.1.1",
51
+ "rollup": "3.18.0",
52
+ "rollup-plugin-dts": "^5.2.0",
52
53
  "rollup-plugin-less": "^1.1.3",
53
- "typescript": "^4.9.4",
54
- "vite": "^4.0.4"
54
+ "typescript": "^4.9.5",
55
+ "vite": "^4.1.4"
55
56
  },
56
57
  "scripts": {
57
58
  "build": "rm -rf dist && rollup -c --configPlugin @rollup/plugin-typescript"