antd-img-crop 4.17.0 → 4.18.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.
@@ -188,7 +188,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
188
188
  // https://ant.design/components/upload-cn#api
189
189
  // https://github.com/ant-design/ant-design/blob/master/components/upload/Upload.tsx#L152-L178
190
190
  const result = yield beforeUpload(file, [file]);
191
- pass(result !== true ? result : rawFile);
191
+ pass((result !== true && result) || rawFile);
192
192
  }
193
193
  catch (err) {
194
194
  fail(err);
@@ -197,25 +197,29 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
197
197
  const getNewBeforeUpload = react.useCallback((beforeUpload) => {
198
198
  return ((file, fileList) => {
199
199
  return new Promise((resolve, reject) => tslib.__awaiter(void 0, void 0, void 0, function* () {
200
+ let processFile = file;
200
201
  if (typeof cb.current.beforeCrop === 'function') {
201
202
  try {
202
203
  const result = yield cb.current.beforeCrop(file, fileList);
203
204
  if (result === false) {
204
205
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
205
206
  }
207
+ if (result !== true) {
208
+ processFile = result || file;
209
+ }
206
210
  }
207
211
  catch (err) {
208
212
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
209
213
  }
210
214
  }
211
- // get file result
215
+ // read file
212
216
  const reader = new FileReader();
213
217
  reader.addEventListener('load', () => {
214
218
  if (typeof reader.result === 'string') {
215
219
  setModalImage(reader.result); // open modal
216
220
  }
217
221
  });
218
- reader.readAsDataURL(file);
222
+ reader.readAsDataURL(processFile);
219
223
  // on modal cancel
220
224
  onCancel.current = () => {
221
225
  var _a, _b;
@@ -229,7 +233,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
229
233
  setModalImage('');
230
234
  easyCropRef.current.onReset();
231
235
  const canvas = getCropCanvas(event.target);
232
- const { type, name, uid } = file;
236
+ const { type, name, uid } = processFile;
233
237
  canvas.toBlob((blob) => tslib.__awaiter(void 0, void 0, void 0, function* () {
234
238
  const newFile = new File([blob], name, { type });
235
239
  Object.assign(newFile, { uid });
@@ -186,7 +186,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
186
186
  // https://ant.design/components/upload-cn#api
187
187
  // https://github.com/ant-design/ant-design/blob/master/components/upload/Upload.tsx#L152-L178
188
188
  const result = yield beforeUpload(file, [file]);
189
- pass(result !== true ? result : rawFile);
189
+ pass((result !== true && result) || rawFile);
190
190
  }
191
191
  catch (err) {
192
192
  fail(err);
@@ -195,25 +195,29 @@ const ImgCrop = forwardRef((props, cropperRef) => {
195
195
  const getNewBeforeUpload = useCallback((beforeUpload) => {
196
196
  return ((file, fileList) => {
197
197
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
198
+ let processFile = file;
198
199
  if (typeof cb.current.beforeCrop === 'function') {
199
200
  try {
200
201
  const result = yield cb.current.beforeCrop(file, fileList);
201
202
  if (result === false) {
202
203
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
203
204
  }
205
+ if (result !== true) {
206
+ processFile = result || file;
207
+ }
204
208
  }
205
209
  catch (err) {
206
210
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
207
211
  }
208
212
  }
209
- // get file result
213
+ // read file
210
214
  const reader = new FileReader();
211
215
  reader.addEventListener('load', () => {
212
216
  if (typeof reader.result === 'string') {
213
217
  setModalImage(reader.result); // open modal
214
218
  }
215
219
  });
216
- reader.readAsDataURL(file);
220
+ reader.readAsDataURL(processFile);
217
221
  // on modal cancel
218
222
  onCancel.current = () => {
219
223
  var _a, _b;
@@ -227,7 +231,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
227
231
  setModalImage('');
228
232
  easyCropRef.current.onReset();
229
233
  const canvas = getCropCanvas(event.target);
230
- const { type, name, uid } = file;
234
+ const { type, name, uid } = processFile;
231
235
  canvas.toBlob((blob) => __awaiter(void 0, void 0, void 0, function* () {
232
236
  const newFile = new File([blob], name, { type });
233
237
  Object.assign(newFile, { uid });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-img-crop",
3
- "version": "4.17.0",
3
+ "version": "4.18.0",
4
4
  "description": "An image cropper for Ant Design Upload",
5
5
  "keywords": [
6
6
  "react",
@@ -38,26 +38,26 @@
38
38
  "devDependencies": {
39
39
  "@rollup/plugin-replace": "^5.0.5",
40
40
  "@rollup/plugin-typescript": "^11.1.5",
41
- "@types/node": "^20.9.0",
42
- "@types/react": "^18.2.37",
43
- "@types/react-dom": "^18.2.15",
44
- "@vitejs/plugin-react": "^4.1.1",
45
- "antd": "^5.11.0",
41
+ "@types/node": "^20.10.0",
42
+ "@types/react": "^18.2.39",
43
+ "@types/react-dom": "^18.2.17",
44
+ "@vitejs/plugin-react": "^4.2.0",
45
+ "antd": "^5.11.5",
46
46
  "autoprefixer": "^10.4.16",
47
- "eslint": "^8.53.0",
47
+ "eslint": "^8.54.0",
48
48
  "eslint-config-prettier": "^9.0.0",
49
49
  "eslint-config-react-app": "^7.0.1",
50
50
  "postcss": "^8.4.31",
51
- "prettier": "^3.0.3",
52
- "prettier-plugin-organize-imports": "^3.2.3",
51
+ "prettier": "^3.1.0",
52
+ "prettier-plugin-organize-imports": "^3.2.4",
53
53
  "prettier-plugin-tailwindcss": "^0.5.7",
54
54
  "react": "^18.2.0",
55
55
  "react-dom": "^18.2.0",
56
- "rollup": "4.3.0",
56
+ "rollup": "4.6.0",
57
57
  "rollup-plugin-dts": "^6.1.0",
58
58
  "rollup-plugin-postcss": "^4.0.2",
59
59
  "tailwindcss": "^3.3.5",
60
- "typescript": "^5.2.2",
61
- "vite": "^4.5.0"
60
+ "typescript": "^5.3.2",
61
+ "vite": "^5.0.3"
62
62
  }
63
63
  }