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(image-upload): dispatch event for intercepting image upload flow #249

Merged
merged 5 commits into from
May 23, 2023

Conversation

giamir
Copy link
Contributor

@giamir giamir commented May 16, 2023

Summary

Dispatch a custom event on image upload to allow plugin authors to pause the upload flow and decide to either abort or resume it based on async operations.

How to test

  • Visit http://localhost:8080/plugins.html or the PR deploy preview
  • Upload an image in rich-text or commonmark mode
  • A confirmation dialog should appear saying that code was detected in the image
  • Click ok and observe a codeblock being inserted in the editor as opposed to the image being uploaded

Open Todos

  • review solution design
  • write unit tests
  • cleanup demo plugin showcasing the feature

@netlify
Copy link

netlify bot commented May 16, 2023

Deploy Preview for stacks-editor ready!

Name Link
🔨 Latest commit 824744d
🔍 Latest deploy log https://app.netlify.com/sites/stacks-editor/deploys/6464cc3f9b16920008c49059
😎 Deploy Preview https://deploy-preview-249--stacks-editor.netlify.app/plugins
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@giamir giamir changed the title [WIP] feat(image-upload): dispatch event for intercepting image upload flow feat(image-upload): dispatch event for intercepting image upload flow May 17, 2023
@giamir giamir marked this pull request as ready for review May 17, 2023 12:18
@giamir giamir requested review from yellis and dancormier May 17, 2023 12:19
@yellis
Copy link
Contributor

yellis commented May 21, 2023

This looks great. Only thing that missing that we would probably need is the ability to inject a modal workflow into the place where you have the confirmation js. Basically, we will want to intercept the image, upload it to extract the code, and then show the code (with syntax highlighting) to the user before adding it (which can be done in a modal). If we can have some sort of a callback that we could hook into where we would put in a function that would open the modal, and then be able to either exit the process or give code to inject, would be ideal.

@giamir
Copy link
Contributor Author

giamir commented May 22, 2023

@yellis Our recommendation would be for your team to own and author the code-detection plugin. The code-detection.ts file you see in this PR is just an example of how you could author the plugin and leverage the new event API we created in the image-upload core plugin.
Our team will be happy to support you to create the plugin in the core codebase. In this playground we wanted to keep things rather simple but swapping the confirmation dialog over a modal would be a pretty straightforward operation (it would just make the example a bit more verbose).
Essentially the only source code changes we plan to make on the editor are the one in the image-upload.ts file.
Happy to discuss this further if necessary. 🙂

@giamir giamir merged commit a0d83c9 into main May 23, 2023
4 checks passed
@giamir giamir deleted the STACKS-310/intercept-image-upload branch May 23, 2023 14:05
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