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:
parent
5da3207633
commit
7d1fddc144
@ -1193,9 +1193,13 @@ class App extends React.Component<AppProps, AppState> {
|
||||
}
|
||||
const data = await parseClipboard(event);
|
||||
if (this.props.onPaste) {
|
||||
if (await this.props.onPaste(data, event)) {
|
||||
try {
|
||||
if ((await this.props.onPaste(data, event)) === false) {
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
if (data.errorMessage) {
|
||||
this.setState({ errorMessage: data.errorMessage });
|
||||
|
@ -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)
|
||||
|
@ -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 ?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user