-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically assign block ids to pattern blocks for use in partial s…
…ynching of pattern instances (#56495) * Automatically assign block ids * Downgrade package to fix tooling * Move to the editor package and allow core/button * Fix test resolver
- Loading branch information
1 parent
66ed476
commit fd0d8e3
Showing
13 changed files
with
270 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { privateApis } from '@wordpress/patterns'; | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
import { useBlockEditingMode } from '@wordpress/block-editor'; | ||
import { hasBlockSupport } from '@wordpress/blocks'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editorStore } from '../store'; | ||
import { unlock } from '../lock-unlock'; | ||
|
||
const { | ||
PartialSyncingControls, | ||
PATTERN_TYPES, | ||
PARTIAL_SYNCING_SUPPORTED_BLOCKS, | ||
} = unlock( privateApis ); | ||
|
||
/** | ||
* Override the default edit UI to include a new block inspector control for | ||
* assigning a partial syncing controls to supported blocks in the pattern editor. | ||
* Currently, only the `core/paragraph` block is supported. | ||
* | ||
* @param {Component} BlockEdit Original component. | ||
* | ||
* @return {Component} Wrapped component. | ||
*/ | ||
const withPartialSyncingControls = createHigherOrderComponent( | ||
( BlockEdit ) => ( props ) => { | ||
const blockEditingMode = useBlockEditingMode(); | ||
const hasCustomFieldsSupport = hasBlockSupport( | ||
props.name, | ||
'__experimentalConnections', | ||
false | ||
); | ||
const isEditingPattern = useSelect( | ||
( select ) => | ||
select( editorStore ).getCurrentPostType() === | ||
PATTERN_TYPES.user, | ||
[] | ||
); | ||
|
||
const shouldShowPartialSyncingControls = | ||
hasCustomFieldsSupport && | ||
props.isSelected && | ||
isEditingPattern && | ||
blockEditingMode === 'default' && | ||
Object.keys( PARTIAL_SYNCING_SUPPORTED_BLOCKS ).includes( | ||
props.name | ||
); | ||
|
||
return ( | ||
<> | ||
<BlockEdit { ...props } /> | ||
{ shouldShowPartialSyncingControls && ( | ||
<PartialSyncingControls { ...props } /> | ||
) } | ||
</> | ||
); | ||
} | ||
); | ||
|
||
if ( window.__experimentalConnections ) { | ||
addFilter( | ||
'editor.BlockEdit', | ||
'core/editor/with-partial-syncing-controls', | ||
withPartialSyncingControls | ||
); | ||
} |
This file contains 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
Oops, something went wrong.