From 93188952884ea98e9e1de32db39ca31b214523d9 Mon Sep 17 00:00:00 2001 From: James R T Date: Mon, 11 Jul 2022 21:09:29 +0800 Subject: [PATCH 1/6] Add image editor cancel event --- packages/@uppy/image-editor/src/ImageEditor.jsx | 4 ++++ packages/@uppy/image-editor/types/index.d.ts | 2 ++ packages/@uppy/image-editor/types/index.test-d.ts | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/packages/@uppy/image-editor/src/ImageEditor.jsx b/packages/@uppy/image-editor/src/ImageEditor.jsx index 8549079a57..d6694f016d 100644 --- a/packages/@uppy/image-editor/src/ImageEditor.jsx +++ b/packages/@uppy/image-editor/src/ImageEditor.jsx @@ -121,6 +121,10 @@ export default class ImageEditor extends UIPlugin { } uninstall () { + const { currentImage } = this.getPluginState() + const file = this.uppy.getFile(currentImage.id) + this.uppy.emit('file-editor:cancel', file) + this.unmount() } diff --git a/packages/@uppy/image-editor/types/index.d.ts b/packages/@uppy/image-editor/types/index.d.ts index add9409836..c8eace6bd0 100644 --- a/packages/@uppy/image-editor/types/index.d.ts +++ b/packages/@uppy/image-editor/types/index.d.ts @@ -34,10 +34,12 @@ export default ImageEditor export type FileEditorStartCallback = (file: UppyFile) => void; export type FileEditorCompleteCallback = (updatedFile: UppyFile) => void; +export type FileEditorCancelCallback = (file: UppyFile) => void; declare module '@uppy/core' { export interface UppyEventMap { 'file-editor:start' : FileEditorStartCallback 'file-editor:complete': FileEditorCompleteCallback + 'file-editor:cancel': FileEditorCancelCallback } } diff --git a/packages/@uppy/image-editor/types/index.test-d.ts b/packages/@uppy/image-editor/types/index.test-d.ts index 790a466746..de8641a686 100644 --- a/packages/@uppy/image-editor/types/index.test-d.ts +++ b/packages/@uppy/image-editor/types/index.test-d.ts @@ -16,4 +16,8 @@ import ImageEditor from '..' // eslint-disable-next-line @typescript-eslint/no-unused-vars const fileName = file.name }) + uppy.on('file-editor:cancel', (file) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const fileName = file.name + }) } From 77f4b0de9248c7197ca4f82d58c0fdc3c8f946de Mon Sep 17 00:00:00 2001 From: James R T Date: Mon, 11 Jul 2022 23:18:45 +0800 Subject: [PATCH 2/6] Update image editor docs with cancel event --- website/src/docs/image-editor.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/website/src/docs/image-editor.md b/website/src/docs/image-editor.md index 31ba34f265..996da07e16 100644 --- a/website/src/docs/image-editor.md +++ b/website/src/docs/image-editor.md @@ -121,6 +121,16 @@ uppy.on('file-editor:complete', (updatedFile) => { }) ``` +### file-editor:cancel + +Emitted when `uninstall` is called. + +```js +uppy.on('file-editor:cancel', (file) => { + console.log(file) +}) +``` + ### `locale: {}` ```js From 0755cc66e80f1ca19f30530b89ed101ab9c9b05d Mon Sep 17 00:00:00 2001 From: James R T Date: Tue, 12 Jul 2022 10:42:54 +0800 Subject: [PATCH 3/6] Emit cancel event when current editing changes are discarded --- packages/@uppy/dashboard/src/components/FileCard/index.jsx | 2 ++ website/src/docs/image-editor.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/dashboard/src/components/FileCard/index.jsx b/packages/@uppy/dashboard/src/components/FileCard/index.jsx index 481b71a8c8..d40a525f3b 100644 --- a/packages/@uppy/dashboard/src/components/FileCard/index.jsx +++ b/packages/@uppy/dashboard/src/components/FileCard/index.jsx @@ -59,6 +59,8 @@ class FileCard extends Component { } handleCancel = () => { + const file = this.props.files[this.props.fileCardFor] + this.uppy.emit('file-editor:cancel', file) this.props.toggleFileCard(false) } diff --git a/website/src/docs/image-editor.md b/website/src/docs/image-editor.md index 996da07e16..e90e8426d3 100644 --- a/website/src/docs/image-editor.md +++ b/website/src/docs/image-editor.md @@ -123,7 +123,7 @@ uppy.on('file-editor:complete', (updatedFile) => { ### file-editor:cancel -Emitted when `uninstall` is called. +Emitted when `uninstall` is called or when the current image editing changes are discarded. ```js uppy.on('file-editor:cancel', (file) => { From e7a72e38e62d4dc27308379421fd27f86f8ce385 Mon Sep 17 00:00:00 2001 From: James R T Date: Tue, 12 Jul 2022 10:52:10 +0800 Subject: [PATCH 4/6] Fix reference to Uppy instance in FileCard component --- packages/@uppy/dashboard/src/components/FileCard/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@uppy/dashboard/src/components/FileCard/index.jsx b/packages/@uppy/dashboard/src/components/FileCard/index.jsx index d40a525f3b..d1a8d4e4a1 100644 --- a/packages/@uppy/dashboard/src/components/FileCard/index.jsx +++ b/packages/@uppy/dashboard/src/components/FileCard/index.jsx @@ -60,7 +60,7 @@ class FileCard extends Component { handleCancel = () => { const file = this.props.files[this.props.fileCardFor] - this.uppy.emit('file-editor:cancel', file) + this.props.uppy.emit('file-editor:cancel', file) this.props.toggleFileCard(false) } From 87972c72262c659cdb97b0802d64e5f58de5e055 Mon Sep 17 00:00:00 2001 From: James R T Date: Tue, 12 Jul 2022 18:03:29 +0800 Subject: [PATCH 5/6] Get currentImage from getPluginState() in FileCard Co-authored-by: Merlijn Vos --- packages/@uppy/dashboard/src/components/FileCard/index.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/@uppy/dashboard/src/components/FileCard/index.jsx b/packages/@uppy/dashboard/src/components/FileCard/index.jsx index d1a8d4e4a1..a07d191180 100644 --- a/packages/@uppy/dashboard/src/components/FileCard/index.jsx +++ b/packages/@uppy/dashboard/src/components/FileCard/index.jsx @@ -59,7 +59,8 @@ class FileCard extends Component { } handleCancel = () => { - const file = this.props.files[this.props.fileCardFor] + const { currentImage } = this.getPluginState() + const file = this.uppy.getFile(currentImage.id) this.props.uppy.emit('file-editor:cancel', file) this.props.toggleFileCard(false) } From 9c1e7e2f7011abd1e9b801b689016171600497a9 Mon Sep 17 00:00:00 2001 From: James R T Date: Tue, 12 Jul 2022 18:06:42 +0800 Subject: [PATCH 6/6] Align reference to Uppy instance using this.props --- packages/@uppy/dashboard/src/components/FileCard/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@uppy/dashboard/src/components/FileCard/index.jsx b/packages/@uppy/dashboard/src/components/FileCard/index.jsx index a07d191180..16d16344bf 100644 --- a/packages/@uppy/dashboard/src/components/FileCard/index.jsx +++ b/packages/@uppy/dashboard/src/components/FileCard/index.jsx @@ -60,7 +60,7 @@ class FileCard extends Component { handleCancel = () => { const { currentImage } = this.getPluginState() - const file = this.uppy.getFile(currentImage.id) + const file = this.props.uppy.getFile(currentImage.id) this.props.uppy.emit('file-editor:cancel', file) this.props.toggleFileCard(false) }