Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/image-editor: Add image editor cancel event #3875

Merged
merged 6 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/@uppy/dashboard/src/components/FileCard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class FileCard extends Component {
}

handleCancel = () => {
const file = this.props.files[this.props.fileCardFor]
jamestiotio marked this conversation as resolved.
Show resolved Hide resolved
this.props.uppy.emit('file-editor:cancel', file)
this.props.toggleFileCard(false)
}

Expand Down
4 changes: 4 additions & 0 deletions packages/@uppy/image-editor/src/ImageEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/image-editor/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export default ImageEditor

export type FileEditorStartCallback<TMeta> = (file: UppyFile<TMeta>) => void;
export type FileEditorCompleteCallback<TMeta> = (updatedFile: UppyFile<TMeta>) => void;
export type FileEditorCancelCallback<TMeta> = (file: UppyFile<TMeta>) => void;

declare module '@uppy/core' {
export interface UppyEventMap<TMeta> {
'file-editor:start' : FileEditorStartCallback<TMeta>
'file-editor:complete': FileEditorCompleteCallback<TMeta>
'file-editor:cancel': FileEditorCancelCallback<TMeta>
}
}
4 changes: 4 additions & 0 deletions packages/@uppy/image-editor/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
10 changes: 10 additions & 0 deletions website/src/docs/image-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ uppy.on('file-editor:complete', (updatedFile) => {
})
```

### file-editor:cancel

Emitted when `uninstall` is called or when the current image editing changes are discarded.

```js
uppy.on('file-editor:cancel', (file) => {
console.log(file)
})
```

### `locale: {}`

```js
Expand Down