-
Notifications
You must be signed in to change notification settings - Fork 4.7k
contentOnly patterns: Allow re-entry into contentOnly mode after 'Edit contents' #72044
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
Changes from all commits
e6ae609
9c93c04
92c9cb0
4447fe9
6916cc2
76ed09d
7cf99a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { Button, __experimentalVStack as VStack } from '@wordpress/components'; | ||
| import { useDispatch, useSelect } from '@wordpress/data'; | ||
| import { __ } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { store as blockEditorStore } from '../../store'; | ||
| import { unlock } from '../../lock-unlock'; | ||
|
|
||
| export default function EditContents( { clientId } ) { | ||
| const { editContentOnlySection, stopEditingContentOnlySection } = unlock( | ||
| useDispatch( blockEditorStore ) | ||
| ); | ||
| const { isWithinSection, isWithinEditedSection, editedContentOnlySection } = | ||
| useSelect( | ||
| ( select ) => { | ||
| const { | ||
| isSectionBlock, | ||
| getParentSectionBlock, | ||
| getEditedContentOnlySection, | ||
| isWithinEditedContentOnlySection, | ||
| } = unlock( select( blockEditorStore ) ); | ||
|
|
||
| return { | ||
| isWithinSection: | ||
| isSectionBlock( clientId ) || | ||
| !! getParentSectionBlock( clientId ), | ||
| isWithinEditedSection: | ||
| isWithinEditedContentOnlySection( clientId ), | ||
| editedContentOnlySection: getEditedContentOnlySection(), | ||
| }; | ||
| }, | ||
| [ clientId ] | ||
| ); | ||
|
|
||
|
Member
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. Wondering if we should stop editing blocks when this component unmounts too? E.g., useEffect( () => {
return () => {
stopEditingAsBlocks();
};
}, [ stopEditingAsBlocks ] );
Contributor
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 guess a problem with doing that would be that if we close the sidebar, then we'd stop editing blocks, which mightn't be desired? |
||
| if ( ! isWithinSection && ! isWithinEditedSection ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <VStack className="block-editor-block-inspector-edit-contents" expanded> | ||
| <Button | ||
| className="block-editor-block-inspector-edit-contents__button" | ||
| __next40pxDefaultSize | ||
| variant="secondary" | ||
| onClick={ () => { | ||
| if ( ! editedContentOnlySection ) { | ||
| editContentOnlySection( clientId ); | ||
| } else { | ||
| stopEditingContentOnlySection(); | ||
| } | ||
| } } | ||
| > | ||
| { editedContentOnlySection | ||
| ? __( 'Lock design' ) | ||
| : __( 'Unlock design' ) } | ||
| </Button> | ||
| </VStack> | ||
| ); | ||
| } | ||
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.
Since we're flattening the structure, could "go to parent" be enough? (Not a blocker for now, of course)
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.
Ended up removing this, it's from an earlier iteration!