-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block API: Add role for 'internal' attributes not copied on duplication #34750
base: trunk
Are you sure you want to change the base?
Changes from all commits
0d180f0
17ab3e6
563bbb9
58e3490
d6666f2
b311d38
0b0ad99
677a0a0
235ac7a
d15a118
4088716
3b0e6ef
0c4673b
cbe7951
b31c072
3601ff3
2a1afa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,11 @@ import { useSelect } from '@wordpress/data'; | |
import { moreVertical } from '@wordpress/icons'; | ||
|
||
import { Children, cloneElement, useCallback } from '@wordpress/element'; | ||
import { serialize, store as blocksStore } from '@wordpress/blocks'; | ||
import { | ||
serialize, | ||
store as blocksStore, | ||
__experimentalCloneSanitizedBlock, | ||
} from '@wordpress/blocks'; | ||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; | ||
import { useCopyToClipboard } from '@wordpress/compose'; | ||
|
||
|
@@ -33,7 +37,12 @@ const POPOVER_PROPS = { | |
}; | ||
|
||
function CopyMenuItem( { blocks, onCopy } ) { | ||
const ref = useCopyToClipboard( () => serialize( blocks ), onCopy ); | ||
const ref = useCopyToClipboard( () => { | ||
blocks = blocks.map( ( block ) => | ||
__experimentalCloneSanitizedBlock( block ) | ||
); | ||
return serialize( blocks ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you explored whether we could move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, but I don't think we can move the logic up any higher. If we move In this file and in the copy-handler, I think it makes sense that when you want to make a copy of a block you should explicitly clone it before serializing. There is some danger that this could be missed with new functionality that involves block duplication, but I can't think of a way of enforcing it. |
||
}, onCopy ); | ||
return <MenuItem ref={ ref }>{ __( 'Copy' ) }</MenuItem>; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's my first time looking at this code in a few months and, reading this, I struggled to grok what
__experimentalCloneSanitizedBlock
does. In particular I didn't really understand it's relationship tocloneBlock
.I think that a better API might be to add optional settings to
cloneBlock
.This makes the parallels to
cloneBlock
very explicit. It's also clearer, I think, to avoid the word "sanitize" which could mean all sorts of things.These settings could also exist on
serialize
which would address @gziolo's comment.(Not a blocking comment—we can absolutely iterate on the API later.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this suggestion, especially because it provides a better answer than I was able to give @gziolo re: serialization. And +1 for concerns on 'sanitize'; I struggled to come up with a better name and would be much happier to avoid it!