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

Copy to clipboard: Removed ClipboardJS dependency #2784

Merged

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Mar 5, 2021

This removes Copy to clipboard's dependency on ClipboardJS.

ClipboardJS has been replaced with a few functions that behave similarly. The actual copying is implemented by the Async + fallback combo here. This alone should give us very good browser compatibility (works in IE11).

Older FF versions do not support copying text to the clipboard at all. For these browsers, we use the same trick as ClipboardJS: we just select the text to copy and ask the user to press Ctrl+C. It's implemented slightly differently, however. ClipboardJS creates a temporary invisible element and selects the text of that but we can just select the text of the <code> element we want to copy (makes everything a lot easier).
This may scroll the code block but I didn't give this much consideration since it will only affect a very small portion of our users.

Prism now has 0 required (runtime) dependencies on other libraries.


This resolves #2783
This resolves #2565
This resolves #2286

@RunDevelopment RunDevelopment added enhancement plugins needs review dependencies Pull requests that update a dependency file labels Mar 5, 2021
@github-actions
Copy link

github-actions bot commented Mar 5, 2021

JS File Size Changes (gzipped)

A total of 1 files have changed, with a combined diff of +38 B (+6.0%).

file master pull size diff % diff
plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js 632 B 670 B +38 B +6.0%

Generated by 🚫 dangerJS against a89058b

@RunDevelopment
Copy link
Member Author

The +38B in bundle size should be viewed in the context that we don't have to download the 3kB of ClipboardJS anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement needs review plugins
Projects
None yet
1 participant