-
Notifications
You must be signed in to change notification settings - Fork 57
TT | 3471 | "Introduce allow-list and disallow-list for blocks." #3811
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
53c70a0
a64514c
52d5d05
4dd35e1
039d0ac
8fdbde5
b0080b0
a6fe710
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,120 @@ | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * WordPress dependencies | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| import { dispatch } from '@wordpress/data'; | ||||||||||||||||||||
| import { getBlockTypes } from '@wordpress/blocks'; | ||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Internal dependencies | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| import { JETPACK_DATA_PATH } from '../jetpack/projects/plugins/jetpack/extensions/shared/get-jetpack-data'; | ||||||||||||||||||||
| import { registerBlock as registerJetpackLayoutGridBlock } from '../block-experiments/blocks/layout-grid/src'; | ||||||||||||||||||||
| import { | ||||||||||||||||||||
| registerContactInfoBlock as registerJetpackContactInfoBlock, | ||||||||||||||||||||
| registerStoryBlock as registerJetpackStoryBlock, | ||||||||||||||||||||
fluiddot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| } from '../jetpack/projects/plugins/jetpack/extensions/editor.native'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Please also consider updating ./block-support/supported-blocks.json | ||||||||||||||||||||
| const availableJetpackBlocks = { | ||||||||||||||||||||
| 'contact-info': { available: true }, | ||||||||||||||||||||
| 'layout-grid': { available: true }, | ||||||||||||||||||||
fluiddot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| story: { available: true }, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const mapToJetpackData = ( { | ||||||||||||||||||||
| isJetpackActive = false, | ||||||||||||||||||||
| userData: tracksUserData = null, | ||||||||||||||||||||
| siteFragment = null, | ||||||||||||||||||||
| blogId: wpcomBlogId = 1, | ||||||||||||||||||||
fluiddot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
| } ) => { | ||||||||||||||||||||
| return { | ||||||||||||||||||||
| siteFragment, | ||||||||||||||||||||
| tracksUserData, | ||||||||||||||||||||
| wpcomBlogId, | ||||||||||||||||||||
| jetpack: { is_active: isJetpackActive }, | ||||||||||||||||||||
| available_blocks: availableJetpackBlocks, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const registerJetpackBlocksIfCapable = ( props = {} ) => { | ||||||||||||||||||||
| const { | ||||||||||||||||||||
| capabilities: { | ||||||||||||||||||||
| layoutGridBlock = false, | ||||||||||||||||||||
| mediaFilesCollectionBlock = false, | ||||||||||||||||||||
| contactInfoBlock = false, | ||||||||||||||||||||
| } = {}, | ||||||||||||||||||||
| } = props; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( layoutGridBlock ) { | ||||||||||||||||||||
| registerJetpackLayoutGridBlock(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
fluiddot marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( mediaFilesCollectionBlock ) { | ||||||||||||||||||||
| registerJetpackStoryBlock(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( contactInfoBlock ) { | ||||||||||||||||||||
| registerJetpackContactInfoBlock(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+51
to
+57
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 noticed that originally we were hiding these blocks instead of preventing registering them: gutenberg-mobile/src/jetpack-editor-setup.js Lines 68 to 69 in 6fea169
gutenberg-mobile/src/jetpack-editor-setup.js Lines 47 to 53 in 6fea169
From my POV, I think it makes sense to register them conditionally to the props but I'm wondering if there was a reason to do it that way. @illusaen do you have any insights regarding this topic? |
||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const setupJetpackBlocks = ( props = {} ) => { | ||||||||||||||||||||
| const { jetpackState = { blogId: 1, isJetpackActive: true } } = props; | ||||||||||||||||||||
| const { isJetpackActive = false } = jetpackState; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( isJetpackActive ) { | ||||||||||||||||||||
| global.window[ JETPACK_DATA_PATH ] = mapToJetpackData( jetpackState ); | ||||||||||||||||||||
| registerJetpackBlocksIfCapable( props ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const setupAllowedBlocks = ( props = {} ) => { | ||||||||||||||||||||
| const registeredBlocks = getBlockTypes().map( ( { name } ) => name ); | ||||||||||||||||||||
| const { showBlocks = registeredBlocks, hideBlocks = [] } = props; | ||||||||||||||||||||
| const wereShowBlocksProvided = showBlocks !== registeredBlocks; | ||||||||||||||||||||
| const uniqueRegisteredHideBlocks = hideBlocks.filter( ( name, index ) => { | ||||||||||||||||||||
| return ( | ||||||||||||||||||||
| // Is Unique? | ||||||||||||||||||||
| hideBlocks.indexOf( name ) === index && | ||||||||||||||||||||
| // Is Unambiguous? | ||||||||||||||||||||
| ( ! wereShowBlocksProvided || ! showBlocks.includes( name ) ) && | ||||||||||||||||||||
| // Is Registered? | ||||||||||||||||||||
| registeredBlocks.includes( name ) | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } ); | ||||||||||||||||||||
| const uniqueRegisteredShowBlocks = ! wereShowBlocksProvided | ||||||||||||||||||||
| ? showBlocks | ||||||||||||||||||||
| : showBlocks.filter( ( name, index ) => { | ||||||||||||||||||||
| return ( | ||||||||||||||||||||
| // Is Unique? | ||||||||||||||||||||
| showBlocks.indexOf( name ) === index && | ||||||||||||||||||||
| // Is Unambiguous? | ||||||||||||||||||||
| ! hideBlocks.includes( name ) && | ||||||||||||||||||||
| // Is Registered? | ||||||||||||||||||||
| registeredBlocks.includes( name ) | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } ); | ||||||||||||||||||||
| const wereShowBlocksFilteredDownToAnEmptySet = | ||||||||||||||||||||
| wereShowBlocksProvided && | ||||||||||||||||||||
| showBlocks.length > 0 && | ||||||||||||||||||||
| uniqueRegisteredShowBlocks.length === 0; | ||||||||||||||||||||
| const invertRegisteredShowBlocks = wereShowBlocksFilteredDownToAnEmptySet | ||||||||||||||||||||
| ? [] | ||||||||||||||||||||
| : registeredBlocks.filter( ( name ) => { | ||||||||||||||||||||
| return ! uniqueRegisteredShowBlocks.includes( name ); | ||||||||||||||||||||
| } ); | ||||||||||||||||||||
| const hiddenBlockTypes = [ | ||||||||||||||||||||
| ...uniqueRegisteredHideBlocks, | ||||||||||||||||||||
| ...invertRegisteredShowBlocks, | ||||||||||||||||||||
| ]; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if ( hiddenBlockTypes.length > 0 ) { | ||||||||||||||||||||
| dispatch( 'core/edit-post' ).hideBlockTypes( [ | ||||||||||||||||||||
| ...new Set( hiddenBlockTypes ), | ||||||||||||||||||||
| ] ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const setupBlocks = ( props = {} ) => { | ||||||||||||||||||||
| setupJetpackBlocks( props ); | ||||||||||||||||||||
| setupAllowedBlocks( props ); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.