Skip to content

Commit bce4117

Browse files
committed
Merge branch 'trunk' into add/term-name-block
2 parents c334cd5 + 7e69ee6 commit bce4117

File tree

37 files changed

+614
-322
lines changed

37 files changed

+614
-322
lines changed

docs/reference-guides/core-blocks.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Displays an accordion panel. ([Source](https://github.com/WordPress/gutenberg/tr
4646
- **Name:** core/accordion-panel
4747
- **Category:** design
4848
- **Parent:** core/accordion-item
49-
- **Supports:** allowedBlocks, color (background, gradients, text), contentRole, interactivity, shadow, spacing (blockGap, padding), typography (fontSize, lineHeight), ~~blockVisibility~~, ~~html~~
49+
- **Supports:** allowedBlocks, color (background, gradients, text), contentRole, interactivity, layout (~~allowEditing~~), shadow, spacing (blockGap, padding), typography (fontSize, lineHeight), ~~blockVisibility~~, ~~html~~
5050
- **Attributes:** isSelected, openByDefault, templateLock
5151

5252
## Archives
@@ -1008,7 +1008,7 @@ Contains the block elements used to render a taxonomy term, like the name, descr
10081008
- **Experimental:** true
10091009
- **Category:** theme
10101010
- **Ancestor:** core/terms-query
1011-
- **Supports:** align (full, wide), color (background, gradients, link, text), interactivity (clientNavigation), layout (allowEditing, allowSwitching, default), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
1011+
- **Supports:** align (full, wide), color (background, gradients, link, text), interactivity (clientNavigation), layout, spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
10121012

10131013
## Terms Query
10141014

@@ -1017,8 +1017,7 @@ An advanced block that allows displaying taxonomy terms based on different query
10171017
- **Name:** core/terms-query
10181018
- **Experimental:** true
10191019
- **Category:** theme
1020-
- **Allowed Blocks:** core/term-template
1021-
- **Supports:** align (full, wide), interactivity, ~~html~~
1020+
- **Supports:** align (full, wide), interactivity, layout, ~~html~~
10221021
- **Attributes:** tagName, termQuery
10231022

10241023
## Text Columns (deprecated)

packages/block-editor/src/components/block-settings-menu/block-settings-dropdown.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,11 @@ export function BlockSettingsDropdown( {
334334
</MenuItem>
335335
</>
336336
) }
337-
<CommentIconSlotFill.Slot
338-
fillProps={ { onClose } }
339-
/>
337+
{ count === 1 && (
338+
<CommentIconSlotFill.Slot
339+
fillProps={ { onClose } }
340+
/>
341+
) }
340342
</MenuGroup>
341343
{ canCopyStyles && ! isContentOnly && (
342344
<MenuGroup>

packages/block-editor/src/components/block-tools/index.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { isTextField } from '@wordpress/dom';
66
import { Popover } from '@wordpress/components';
77
import { __unstableUseShortcutEventMatch as useShortcutEventMatch } from '@wordpress/keyboard-shortcuts';
88
import { useRef } from '@wordpress/element';
9-
import { switchToBlockType, store as blocksStore } from '@wordpress/blocks';
9+
import {
10+
switchToBlockType,
11+
store as blocksStore,
12+
hasBlockSupport,
13+
} from '@wordpress/blocks';
1014
import { speak } from '@wordpress/a11y';
1115
import { __, sprintf, _n } from '@wordpress/i18n';
1216

@@ -24,6 +28,7 @@ import usePopoverScroll from '../block-popover/use-popover-scroll';
2428
import ZoomOutModeInserters from './zoom-out-mode-inserters';
2529
import { useShowBlockTools } from './use-show-block-tools';
2630
import { unlock } from '../../lock-unlock';
31+
import { cleanEmptyObject } from '../../hooks/utils';
2732
import usePasteStyles from '../use-paste-styles';
2833

2934
function selector( select ) {
@@ -71,6 +76,7 @@ export default function BlockTools( {
7176
getSelectedBlockClientIds,
7277
getBlockRootClientId,
7378
isGroupable,
79+
getBlockName,
7480
} = useSelect( blockEditorStore );
7581
const { getGroupingBlockName } = useSelect( blocksStore );
7682
const { showEmptyBlockSideInserter, showBlockToolbarPopover } =
@@ -87,6 +93,7 @@ export default function BlockTools( {
8793
moveBlocksUp,
8894
moveBlocksDown,
8995
expandBlock,
96+
updateBlockAttributes,
9097
} = unlock( useDispatch( blockEditorStore ) );
9198

9299
function onKeyDown( event ) {
@@ -200,6 +207,44 @@ export default function BlockTools( {
200207
replaceBlocks( clientIds, newBlocks );
201208
speak( __( 'Selected blocks are grouped.' ) );
202209
}
210+
} else if (
211+
isMatch( 'core/block-editor/toggle-block-visibility', event )
212+
) {
213+
const clientIds = getSelectedBlockClientIds();
214+
if ( clientIds.length ) {
215+
event.preventDefault();
216+
const blocks = getBlocksByClientId( clientIds );
217+
const canToggleBlockVisibility = blocks.every( ( block ) =>
218+
hasBlockSupport(
219+
getBlockName( block.clientId ),
220+
'blockVisibility',
221+
true
222+
)
223+
);
224+
if ( ! canToggleBlockVisibility ) {
225+
return;
226+
}
227+
const hasHiddenBlock = blocks.some(
228+
( block ) =>
229+
block.attributes.metadata?.blockVisibility === false
230+
);
231+
const attributesByClientId = Object.fromEntries(
232+
blocks.map( ( { clientId: mapClientId, attributes } ) => [
233+
mapClientId,
234+
{
235+
metadata: cleanEmptyObject( {
236+
...attributes?.metadata,
237+
blockVisibility: hasHiddenBlock
238+
? undefined
239+
: false,
240+
} ),
241+
},
242+
] )
243+
);
244+
updateBlockAttributes( clientIds, attributesByClientId, {
245+
uniqueByBlock: true,
246+
} );
247+
}
203248
}
204249
}
205250
const blockToolbarRef = usePopoverScroll( __unstableContentRef );

packages/block-editor/src/components/keyboard-shortcuts/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ function KeyboardShortcutsRegister() {
197197
character: 'g',
198198
},
199199
} );
200+
201+
registerShortcut( {
202+
name: 'core/block-editor/toggle-block-visibility',
203+
category: 'block',
204+
description: __( 'Show or hide the selected block(s).' ),
205+
keyCombination: {
206+
modifier: 'primaryShift',
207+
character: 'h',
208+
},
209+
} );
200210
}, [ registerShortcut ] );
201211

202212
return null;

packages/block-editor/src/components/list-view/block.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { useBlockLock } from '../block-lock';
5353
import AriaReferencedText from './aria-referenced-text';
5454
import { unlock } from '../../lock-unlock';
5555
import usePasteStyles from '../use-paste-styles';
56+
import { cleanEmptyObject } from '../../hooks/utils';
5657

5758
function ListViewBlock( {
5859
block: { clientId },
@@ -96,6 +97,7 @@ function ListViewBlock( {
9697
insertAfterBlock,
9798
insertBeforeBlock,
9899
setOpenedBlockSettingsMenu,
100+
updateBlockAttributes,
99101
} = unlock( useDispatch( blockEditorStore ) );
100102
const debouncedToggleBlockHighlight = useDebounce(
101103
toggleBlockHighlight,
@@ -367,6 +369,36 @@ function ListViewBlock( {
367369
setOpenedBlockSettingsMenu( undefined );
368370
updateFocusAndSelection( newlySelectedBlocks[ 0 ], false );
369371
}
372+
} else if (
373+
isMatch( 'core/block-editor/toggle-block-visibility', event )
374+
) {
375+
event.preventDefault();
376+
const { blocksToUpdate } = getBlocksToUpdate();
377+
const blocks = getBlocksByClientId( blocksToUpdate );
378+
const canToggleBlockVisibility = blocks.every( ( blockToUpdate ) =>
379+
hasBlockSupport( blockToUpdate.name, 'blockVisibility', true )
380+
);
381+
if ( ! canToggleBlockVisibility ) {
382+
return;
383+
}
384+
const hasHiddenBlock = blocks.some(
385+
( blockToUpdate ) =>
386+
blockToUpdate.attributes.metadata?.blockVisibility === false
387+
);
388+
const attributesByClientId = Object.fromEntries(
389+
blocks.map( ( { clientId: mapClientId, attributes } ) => [
390+
mapClientId,
391+
{
392+
metadata: cleanEmptyObject( {
393+
...attributes?.metadata,
394+
blockVisibility: hasHiddenBlock ? undefined : false,
395+
} ),
396+
},
397+
] )
398+
);
399+
updateBlockAttributes( blocksToUpdate, attributesByClientId, {
400+
uniqueByBlock: true,
401+
} );
370402
}
371403
}
372404

packages/block-library/src/accordion-panel/block.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
}
4848
},
4949
"shadow": true,
50+
"layout": {
51+
"allowEditing": false
52+
},
5053
"blockVisibility": false,
5154
"contentRole": true,
5255
"allowedBlocks": true

packages/block-library/src/style.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
@import "./term-description/style.scss";
7474
@import "./term-name/style.scss";
7575
@import "./term-template/style.scss";
76-
@import "./terms-query/style.scss";
7776
@import "./text-columns/style.scss";
7877
@import "./verse/style.scss";
7978
@import "./video/style.scss";

packages/block-library/src/term-template/block.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
"reusable": false,
1414
"html": false,
1515
"align": [ "wide", "full" ],
16-
"layout": {
17-
"allowSwitching": true,
18-
"allowEditing": true,
19-
"default": {
20-
"type": "flex"
21-
}
22-
},
16+
"layout": true,
2317
"color": {
2418
"gradients": true,
2519
"link": true,
@@ -64,5 +58,5 @@
6458
}
6559
},
6660
"style": "wp-block-term-template",
67-
"variations": "file:./variations.js"
61+
"editorStyle": "wp-block-term-template-editor"
6862
}

0 commit comments

Comments
 (0)