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

Restrict copy/paste of a block in the editor when supports.multiple = false and supports.removal = false #53471

Open
Michelleeby opened this issue Aug 9, 2023 · 3 comments
Labels
[Feature] Blocks Overall functionality of blocks Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.

Comments

@Michelleeby
Copy link

What problem does this address?

Hello folks 👋🏼 we have a custom block that should always be on the page, should not be moved, and should not be removed. To accomplish this, supports.removal = false and supports.multiple = false in block.json. As well, the block pattern that provides the custom block to all posts restricts removing and moving the block.

The problem is that you are still able to copy and paste the block. This leads to a strange user experience. Since multiple is false, a message is given to the user after they paste the block that only 1 of the block is supported. However, because removal isn’t supported, the user cannot delete the pasted block. Only Undo seems to work.

What is your proposed solution?

It could be helpful for this issue if the combination of supports.multiple = false and supports.removal = false meant Copy and Paste of the block is not supported in the editor.

Right now, with those settings, copy and paste is still enabled and available via menu, and this seems expected when viewing the source.

<CopyMenuItem
blocks={ blocks }
onCopy={ onCopy }
/>

{ canDuplicate && (
<MenuItem
onClick={ pipe(
onClose,
onDuplicate,
updateSelectionAfterDuplicate
) }
shortcut={ shortcuts.duplicate }
>
{ __( 'Duplicate' ) }
</MenuItem>
) }

Notice canDuplicate is only influencing the Duplicate button and the CopyMenuItem exists without condition. I thought maybe a conditional existed earlier, but I checked onCopy and that doesn’t seem to be the case either.

onCopy() {
const selectedBlockClientIds = blocks.map(
( { clientId } ) => clientId
);
if ( blocks.length === 1 ) {
flashBlock( selectedBlockClientIds[ 0 ] );
}
notifyCopy( 'copy', selectedBlockClientIds );
},

So that’s what brings me here today. I’m curious if it would be as simple as adding a check on the copy button that is influenced by the supports.multiple in block.json. Similar to how it seems to work for Duplicate support.

Anyways, thanks for your time and I look forward to working together on this issue 😁

@Mamaduka Mamaduka added [Feature] Blocks Overall functionality of blocks Needs Technical Feedback Needs testing from a developer perspective. labels Aug 9, 2023
@gziolo gziolo mentioned this issue Aug 11, 2023
58 tasks
@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Aug 30, 2023
@1337rout
Copy link

1337rout commented Nov 7, 2023

+1 to this. Anything with multiple: false in it's supports should not be able to be copy-pasted in.

@1337rout
Copy link

1337rout commented Nov 23, 2023

I see the use case in having the copy still be available as copy-paste works between windows, but I'd at least like the option to turn it off with a new supports variable. Maybe something like supports: { copy: false } to turn off copy functionality.

@jg314
Copy link
Contributor

jg314 commented Jun 10, 2024

+1 on this issue. We have a block with supports.multiple = false that's being added with locking turned on so the block can't be removed. Here's what the attributes look like with the block in the editor:

<!-- wp:wired-impact/hero {"lock":{"remove":true,"move":true}} /-->

It's still possible to copy and paste the block, which generates the "This block can only be used once." message shown below. The issue is that because the block is locked, clicking the "Remove" button does nothing in the UI. A console error is also thrown in this situation.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants