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

feat: implemented onDrop callback function #3960

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

zsviczian
Copy link
Collaborator

Very similar to onPaste callback.

@vercel
Copy link

vercel bot commented Sep 4, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/excalidraw/excalidraw/765e5L4ZcKoGZW4i2y51bFLCCS8j
✅ Preview: https://excalidraw-git-fork-zsviczian-ondropevent-excalidraw.vercel.app

@zsviczian
Copy link
Collaborator Author

@dwelle, I don't disagree with you, however, I took onPaste as the template. https://www.npmjs.com/package/@excalidraw/excalidraw#onPaste

@dwelle
Copy link
Member

dwelle commented Sep 9, 2021

Ok, so it seems you're more aware of some of our codebase than I am.

It seems I've approved the PR (#3420), but missed this.

@ad1992 thoughts? My opinion: => boolean | void, not require return values, and only consider false as "prevent default". It'd be a breaking change for onPaste, but I think it'll be fine.

Comment on lines 3832 to 3833
await this.props.onDrop(event);
return;
Copy link
Member

@ad1992 ad1992 Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like right now the drop action will always be prevented (since we just return ) if present which is incorrect.
Right now we are preventing paste action if the onPaste returns true but I do agree with @dwelle we should allow false instead to prevent to be semantically more correct.
We can make the onPaste change in a separate PR, let's fix the onDrop in this PR.

@@ -184,6 +184,9 @@ export interface ExcalidrawProps {
data: ClipboardData,
event: ClipboardEvent | null,
) => Promise<boolean> | boolean;
onDrop?: (
event: React.DragEvent<HTMLDivElement>,
) => Promise<boolean> | boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) => Promise<boolean> | boolean;
) => Promise<boolean | void> | boolean | void;

@dwelle
Copy link
Member

dwelle commented Sep 20, 2021

@zsviczian I think you've mistakenly merged in the zoomToFit code into this PR

This reverts commit f286b86, reversing
changes made to 0f1df5e.
@ad1992
Copy link
Member

ad1992 commented Sep 1, 2022

@zsviczian whats the status of this PR ?

@zsviczian
Copy link
Collaborator Author

I've implemented this in the Obsidian fork and have been using this since last year september... I still think this should be part of the official package.

https://github.com/zsviczian/excalidraw/blob/3384fb3b7d6034f17da0e8ade3a9b30126bb47b0/src/components/App.tsx#L5749-L5758

@ad1992
Copy link
Member

ad1992 commented Sep 1, 2022

@zsviczian could you rebase the PR with latest master and. clean up the PR as it contains some unnecessary changes like upgrading deps, editing README_NEXT ? Or best would be if you could create a fresh PR and close this one ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants