antd-img-crop 4.16.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.
@@ -179,15 +179,16 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
179
179
  const onCancel = react.useRef();
180
180
  const onOk = react.useRef();
181
181
  const runRawBeforeUpload = react.useCallback((beforeUpload, file, pass, fail) => tslib.__awaiter(void 0, void 0, void 0, function* () {
182
+ const rawFile = file;
182
183
  if (typeof beforeUpload !== 'function') {
183
- pass(file);
184
+ pass(rawFile);
184
185
  return;
185
186
  }
186
187
  try {
187
188
  // https://ant.design/components/upload-cn#api
188
189
  // https://github.com/ant-design/ant-design/blob/master/components/upload/Upload.tsx#L152-L178
189
190
  const result = yield beforeUpload(file, [file]);
190
- pass(result !== true ? result : file);
191
+ pass((result !== true && result) || rawFile);
191
192
  }
192
193
  catch (err) {
193
194
  fail(err);
@@ -196,25 +197,29 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
196
197
  const getNewBeforeUpload = react.useCallback((beforeUpload) => {
197
198
  return ((file, fileList) => {
198
199
  return new Promise((resolve, reject) => tslib.__awaiter(void 0, void 0, void 0, function* () {
200
+ let processFile = file;
199
201
  if (typeof cb.current.beforeCrop === 'function') {
200
202
  try {
201
203
  const result = yield cb.current.beforeCrop(file, fileList);
202
204
  if (result === false) {
203
205
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
204
206
  }
207
+ if (result !== true) {
208
+ processFile = result || file;
209
+ }
205
210
  }
206
211
  catch (err) {
207
212
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
208
213
  }
209
214
  }
210
- // get file result
215
+ // read file
211
216
  const reader = new FileReader();
212
217
  reader.addEventListener('load', () => {
213
218
  if (typeof reader.result === 'string') {
214
219
  setModalImage(reader.result); // open modal
215
220
  }
216
221
  });
217
- reader.readAsDataURL(file);
222
+ reader.readAsDataURL(processFile);
218
223
  // on modal cancel
219
224
  onCancel.current = () => {
220
225
  var _a, _b;
@@ -228,7 +233,7 @@ const ImgCrop = react.forwardRef((props, cropperRef) => {
228
233
  setModalImage('');
229
234
  easyCropRef.current.onReset();
230
235
  const canvas = getCropCanvas(event.target);
231
- const { type, name, uid } = file;
236
+ const { type, name, uid } = processFile;
232
237
  canvas.toBlob((blob) => tslib.__awaiter(void 0, void 0, void 0, function* () {
233
238
  const newFile = new File([blob], name, { type });
234
239
  Object.assign(newFile, { uid });
@@ -177,15 +177,16 @@ const ImgCrop = forwardRef((props, cropperRef) => {
177
177
  const onCancel = useRef();
178
178
  const onOk = useRef();
179
179
  const runRawBeforeUpload = useCallback((beforeUpload, file, pass, fail) => __awaiter(void 0, void 0, void 0, function* () {
180
+ const rawFile = file;
180
181
  if (typeof beforeUpload !== 'function') {
181
- pass(file);
182
+ pass(rawFile);
182
183
  return;
183
184
  }
184
185
  try {
185
186
  // https://ant.design/components/upload-cn#api
186
187
  // https://github.com/ant-design/ant-design/blob/master/components/upload/Upload.tsx#L152-L178
187
188
  const result = yield beforeUpload(file, [file]);
188
- pass(result !== true ? result : file);
189
+ pass((result !== true && result) || rawFile);
189
190
  }
190
191
  catch (err) {
191
192
  fail(err);
@@ -194,25 +195,29 @@ const ImgCrop = forwardRef((props, cropperRef) => {
194
195
  const getNewBeforeUpload = useCallback((beforeUpload) => {
195
196
  return ((file, fileList) => {
196
197
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
198
+ let processFile = file;
197
199
  if (typeof cb.current.beforeCrop === 'function') {
198
200
  try {
199
201
  const result = yield cb.current.beforeCrop(file, fileList);
200
202
  if (result === false) {
201
203
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
202
204
  }
205
+ if (result !== true) {
206
+ processFile = result || file;
207
+ }
203
208
  }
204
209
  catch (err) {
205
210
  return runRawBeforeUpload(beforeUpload, file, resolve, reject);
206
211
  }
207
212
  }
208
- // get file result
213
+ // read file
209
214
  const reader = new FileReader();
210
215
  reader.addEventListener('load', () => {
211
216
  if (typeof reader.result === 'string') {
212
217
  setModalImage(reader.result); // open modal
213
218
  }
214
219
  });
215
- reader.readAsDataURL(file);
220
+ reader.readAsDataURL(processFile);
216
221
  // on modal cancel
217
222
  onCancel.current = () => {
218
223
  var _a, _b;
@@ -226,7 +231,7 @@ const ImgCrop = forwardRef((props, cropperRef) => {
226
231
  setModalImage('');
227
232
  easyCropRef.current.onReset();
228
233
  const canvas = getCropCanvas(event.target);
229
- const { type, name, uid } = file;
234
+ const { type, name, uid } = processFile;
230
235
  canvas.toBlob((blob) => __awaiter(void 0, void 0, void 0, function* () {
231
236
  const newFile = new File([blob], name, { type });
232
237
  Object.assign(newFile, { uid });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-img-crop",
3
- "version": "4.16.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
  }