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

Add button to copy data #17

Closed
salcode opened this issue Feb 2, 2022 · 4 comments
Closed

Add button to copy data #17

salcode opened this issue Feb 2, 2022 · 4 comments

Comments

@salcode
Copy link
Owner

salcode commented Feb 2, 2022

This feedback seems like a good idea.

One missing feature that I would like to see is a copy button. For nested blocks, the output can be lengthy to copy with a mouse, and having a quick way to grab and paste it in my code editor would save some effort on my part.

from WPTavern's Look Under the Hood With the Block X-Ray WordPress Plugin

@salcode
Copy link
Owner Author

salcode commented Feb 25, 2022

According to the Gutenberg changelog:

The hook useCopyToClipboard was added in 10.3.0 (WordPress 5.8.x*)

Compose: Add new useCopyToClipboard hook. (29643)

The hook UseCopyOnClick was added in 8.2.0 (WordPress 5.5.x*)

Add new React hook UseCopyOnClick as an alternative to the ClipboardButton component. (22224)

and deprecated in 5.8 (source from packages/compose/src/hooks/use-copy-on-click/index.js)

deprecated( 'wp.compose.useCopyOnClick', {
	since: '5.8',
	alternative: 'wp.compose.useCopyToClipboard',
} );

The ClipboardButton component was added in 6.7.0 (WordPress 5.4.x*)

Add ClipboardButton component.

and deprecated in 10.3 (source from packages/components/src/clipboard-button/index.js)

deprecated( 'wp.components.ClipboardButton', {
	since: '5.8',
	alternative: 'wp.compose.useCopyToClipboard',
} );

* WordPress versions based on Block Editor Handbook Versions in WordPress

@salcode
Copy link
Owner Author

salcode commented Feb 25, 2022

Since we're saying this plugin requires at least WordPress 5.5, it seems we should use useCopyToClipboard if it is available and fallback to UseCopyOnClick (though we should confirm this hook is available in WordPress 5.5).

In the absence of UseCopyOnClick, we should not render a copy button.

@salcode
Copy link
Owner Author

salcode commented Feb 25, 2022

Now that I'm reflecting on this further, since we are using the import files (not getting things from the wp global), it shouldn't matter what version of Gutenberg / WordPress is being used.

@salcode
Copy link
Owner Author

salcode commented Feb 25, 2022

Nope, looks like I was wrong in my last comment.

Reverting to WordPress 5.5 the editor crashes when I try to use useCopyToClipboard

image

salcode added a commit that referenced this issue Feb 25, 2022
@salcode salcode mentioned this issue Feb 25, 2022
salcode added a commit that referenced this issue Apr 29, 2022
Add "Copy Block Data" button

Resolves #17
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

No branches or pull requests

1 participant