feat: add Clipboard API for browser clipboard access#23615
Draft
feat: add Clipboard API for browser clipboard access#23615
Conversation
Provide a server-side Java API for the browser Clipboard API via the Clipboard interface in com.vaadin.flow.component.page. Two categories of operations are supported: - Client-side copy (reliable): copyOnClick methods set up a click handler that writes to the clipboard directly in the browser event handler, satisfying the user gesture requirement in all browsers. Variants support static text, reading from a source component, copying images, and success/error callbacks. - Server-initiated operations: writeText, readText, and writeImage go through a server round-trip. These may not work in Firefox or Safari due to user gesture timeout constraints. Paste events are supported via addPasteListener, which handles text, HTML, and file data (files are uploaded to the server automatically). Copy and cut event listeners are also provided. All JavaScript logic lives in clipboard.js, loaded via @jsmodule on UI.java, exposing functions on window.Vaadin.Flow.clipboard.
f461868 to
f00593a
Compare
|
Collaborator
|
I did a test with the view at https://gist.github.com/mcollovati/0090b03502eacc0bf96a4336612a2424 Seems to work fine, except for EDIT: update the gist with a workaround for copy/cut listeners |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Provide a server-side Java API for the browser Clipboard API via the Clipboard interface in com.vaadin.flow.component.page.
Two categories of operations are supported:
Client-side copy (reliable): copyOnClick methods set up a click handler that writes to the clipboard directly in the browser event handler, satisfying the user gesture requirement in all browsers. Variants support static text, reading from a source component, copying images, and success/error callbacks.
Server-initiated operations: writeText, readText, and writeImage go through a server round-trip. These may not work in Firefox or Safari due to user gesture timeout constraints.
Paste events are supported via addPasteListener, which handles text, HTML, and file data (files are uploaded to the server automatically). Copy and cut event listeners are also provided.