fix: onPaste should return false to prevent paste action (#3974)

* Update App.tsx

* Update README_NEXT.md

* Update CHANGELOG.md

* Update App.tsx

* Update App.tsx

* Update src/packages/excalidraw/CHANGELOG.md

* fix lint

Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
zsviczian 2021-09-13 17:28:53 +02:00 committed by GitHub
parent 5da3207633
commit 7d1fddc144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -1193,8 +1193,12 @@ class App extends React.Component<AppProps, AppState> {
}
const data = await parseClipboard(event);
if (this.props.onPaste) {
if (await this.props.onPaste(data, event)) {
return;
try {
if ((await this.props.onPaste(data, event)) === false) {
return;
}
} catch (e) {
console.error(e);
}
}
if (data.errorMessage) {

View File

@ -21,6 +21,14 @@ Please add the latest change on the top under the correct section.
## Excalidraw API
### Fixes
- [`onPaste`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPaste) prop should return false to prevent the native excalidraw paste action.
#### BREAKING CHANGE
- Earlier the paste action was prevented when the prop [`onPaste`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#onPaste) returned true, but now it should return false to prevent the paste action. This was done to make it semantically more correct and intuitive.
### Docs
- Correct exportToBackend in README to onExportToBackend [#3952](https://github.com/excalidraw/excalidraw/pull/3952)

View File

@ -610,7 +610,7 @@ This callback is triggered if passed when something is pasted into the scene. Yo
This callback must return a `boolean` value or a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise) which resolves to a boolean value.
In case you want to prevent the excalidraw paste action you must return `true`, it will stop the native excalidraw clipboard management flow (nothing will be pasted into the scene).
In case you want to prevent the excalidraw paste action you must return `false`, it will stop the native excalidraw clipboard management flow (nothing will be pasted into the scene).
### Does it support collaboration ?