@wordpress/block-editor 12.8.0 → 12.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +30 -12
- package/build/components/block-controls/slot.js +1 -1
- package/build/components/block-controls/slot.js.map +1 -1
- package/build/components/block-controls/slot.native.js +1 -1
- package/build/components/block-controls/slot.native.js.map +1 -1
- package/build/components/block-controls/use-has-block-controls.js +1 -1
- package/build/components/block-controls/use-has-block-controls.js.map +1 -1
- package/build/components/block-list/block-outline.native.js +4 -3
- package/build/components/block-list/block-outline.native.js.map +1 -1
- package/build/components/block-list/index.js +4 -3
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +27 -1
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-nav-mode-exit.js +1 -1
- package/build/components/block-list/use-block-props/use-nav-mode-exit.js.map +1 -1
- package/build/components/block-lock/menu-item.js +3 -1
- package/build/components/block-lock/menu-item.js.map +1 -1
- package/build/components/block-lock/toolbar.js +3 -1
- package/build/components/block-lock/toolbar.js.map +1 -1
- package/build/components/block-popover/inbetween.js +4 -5
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-popover/index.js +3 -2
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/color-style-selector/index.js +1 -1
- package/build/components/color-style-selector/index.js.map +1 -1
- package/build/components/iframe/index.js +1 -0
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/reusable-blocks-tab.native.js +7 -4
- package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build/components/inserter/search-results.native.js +10 -8
- package/build/components/inserter/search-results.native.js.map +1 -1
- package/build/components/inspector-controls/fill.js +1 -1
- package/build/components/inspector-controls/fill.js.map +1 -1
- package/build/components/inspector-controls/fill.native.js +1 -1
- package/build/components/inspector-controls/fill.native.js.map +1 -1
- package/build/components/inspector-controls/slot.js +1 -1
- package/build/components/inspector-controls/slot.js.map +1 -1
- package/build/components/inspector-controls/slot.native.js +1 -1
- package/build/components/inspector-controls/slot.native.js.map +1 -1
- package/build/components/link-control/index.js +1 -7
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/list-view/block-select-button.js +48 -7
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +3 -3
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +14 -8
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/use-list-view-images.js +5 -4
- package/build/components/list-view/use-list-view-images.js.map +1 -1
- package/build/components/preview-options/index.js +3 -1
- package/build/components/preview-options/index.js.map +1 -1
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/rich-text/use-remove-browser-shortcuts.js +1 -1
- package/build/components/rich-text/use-remove-browser-shortcuts.js.map +1 -1
- package/build/components/use-block-commands/index.js +74 -63
- package/build/components/use-block-commands/index.js.map +1 -1
- package/build/components/warning/index.js +1 -1
- package/build/components/warning/index.js.map +1 -1
- package/build/hooks/auto-inserting-blocks.js +174 -0
- package/build/hooks/auto-inserting-blocks.js.map +1 -0
- package/build/hooks/index.js +1 -0
- package/build/hooks/index.js.map +1 -1
- package/build/store/selectors.js +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-controls/slot.js +1 -1
- package/build-module/components/block-controls/slot.js.map +1 -1
- package/build-module/components/block-controls/slot.native.js +1 -1
- package/build-module/components/block-controls/slot.native.js.map +1 -1
- package/build-module/components/block-controls/use-has-block-controls.js +1 -1
- package/build-module/components/block-controls/use-has-block-controls.js.map +1 -1
- package/build-module/components/block-list/block-outline.native.js +4 -3
- package/build-module/components/block-list/block-outline.native.js.map +1 -1
- package/build-module/components/block-list/index.js +4 -3
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +27 -1
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-nav-mode-exit.js +1 -1
- package/build-module/components/block-list/use-block-props/use-nav-mode-exit.js.map +1 -1
- package/build-module/components/block-lock/menu-item.js +3 -1
- package/build-module/components/block-lock/menu-item.js.map +1 -1
- package/build-module/components/block-lock/toolbar.js +3 -1
- package/build-module/components/block-lock/toolbar.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +4 -5
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-popover/index.js +3 -2
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/color-style-selector/index.js +1 -1
- package/build-module/components/color-style-selector/index.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -0
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/reusable-blocks-tab.native.js +8 -4
- package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
- package/build-module/components/inserter/search-results.native.js +11 -8
- package/build-module/components/inserter/search-results.native.js.map +1 -1
- package/build-module/components/inspector-controls/fill.js +1 -1
- package/build-module/components/inspector-controls/fill.js.map +1 -1
- package/build-module/components/inspector-controls/fill.native.js +1 -1
- package/build-module/components/inspector-controls/fill.native.js.map +1 -1
- package/build-module/components/inspector-controls/slot.js +1 -1
- package/build-module/components/inspector-controls/slot.js.map +1 -1
- package/build-module/components/inspector-controls/slot.native.js +1 -1
- package/build-module/components/inspector-controls/slot.native.js.map +1 -1
- package/build-module/components/link-control/index.js +1 -7
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +48 -7
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +3 -3
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +14 -8
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/use-list-view-images.js +5 -4
- package/build-module/components/list-view/use-list-view-images.js.map +1 -1
- package/build-module/components/preview-options/index.js +3 -1
- package/build-module/components/preview-options/index.js.map +1 -1
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/rich-text/use-remove-browser-shortcuts.js +1 -1
- package/build-module/components/rich-text/use-remove-browser-shortcuts.js.map +1 -1
- package/build-module/components/use-block-commands/index.js +74 -63
- package/build-module/components/use-block-commands/index.js.map +1 -1
- package/build-module/components/warning/index.js +2 -2
- package/build-module/components/warning/index.js.map +1 -1
- package/build-module/hooks/auto-inserting-blocks.js +167 -0
- package/build-module/hooks/auto-inserting-blocks.js.map +1 -0
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +8 -7
- package/build-style/content.css +8 -7
- package/build-style/style-rtl.css +0 -3
- package/build-style/style.css +0 -3
- package/package.json +32 -32
- package/src/components/block-icon/test/index.js +2 -2
- package/src/components/block-list/block-outline.native.js +5 -2
- package/src/components/block-list/content.scss +2 -3
- package/src/components/block-list/index.js +4 -3
- package/src/components/block-list/use-block-props/index.js +26 -0
- package/src/components/block-list/use-block-props/use-nav-mode-exit.js +1 -1
- package/src/components/block-lock/menu-item.js +2 -0
- package/src/components/block-lock/toolbar.js +3 -1
- package/src/components/block-popover/inbetween.js +4 -3
- package/src/components/block-popover/index.js +3 -2
- package/src/components/block-styles/style.scss +0 -3
- package/src/components/button-block-appender/content.scss +8 -0
- package/src/components/color-style-selector/index.js +1 -1
- package/src/components/iframe/index.js +1 -0
- package/src/components/inserter/reusable-blocks-tab.native.js +7 -2
- package/src/components/inserter/search-results.native.js +13 -9
- package/src/components/link-control/index.js +1 -5
- package/src/components/link-control/test/index.js +1 -0
- package/src/components/list-view/block-select-button.js +67 -15
- package/src/components/list-view/drop-indicator.js +4 -5
- package/src/components/list-view/index.js +19 -13
- package/src/components/list-view/use-list-view-images.js +8 -4
- package/src/components/observe-typing/README.md +2 -2
- package/src/components/preview-options/index.js +2 -0
- package/src/components/provider/index.js +8 -1
- package/src/components/rich-text/use-remove-browser-shortcuts.js +1 -1
- package/src/components/use-block-commands/index.js +92 -88
- package/src/components/warning/index.js +2 -2
- package/src/hooks/auto-inserting-blocks.js +232 -0
- package/src/hooks/index.js +1 -0
- package/src/store/selectors.js +1 -1
- package/build/utils/pre-parse-patterns.js +0 -68
- package/build/utils/pre-parse-patterns.js.map +0 -1
- package/build-module/utils/pre-parse-patterns.js +0 -61
- package/build-module/utils/pre-parse-patterns.js.map +0 -1
- package/src/components/url-popover/test/__snapshots__/index.js.snap +0 -133
- package/src/components/url-popover/test/index.js +0 -75
- package/src/utils/pre-parse-patterns.js +0 -69
|
@@ -6,6 +6,7 @@ import classnames from 'classnames';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
+
import { hasBlockSupport } from '@wordpress/blocks';
|
|
9
10
|
import {
|
|
10
11
|
Button,
|
|
11
12
|
__experimentalHStack as HStack,
|
|
@@ -55,13 +56,15 @@ function ListViewBlockSelectButton(
|
|
|
55
56
|
} );
|
|
56
57
|
const { isLocked } = useBlockLock( clientId );
|
|
57
58
|
const {
|
|
59
|
+
canInsertBlockType,
|
|
58
60
|
getSelectedBlockClientIds,
|
|
59
61
|
getPreviousBlockClientId,
|
|
60
62
|
getBlockRootClientId,
|
|
61
63
|
getBlockOrder,
|
|
64
|
+
getBlocksByClientId,
|
|
62
65
|
canRemoveBlocks,
|
|
63
66
|
} = useSelect( blockEditorStore );
|
|
64
|
-
const { removeBlocks } = useDispatch( blockEditorStore );
|
|
67
|
+
const { duplicateBlocks, removeBlocks } = useDispatch( blockEditorStore );
|
|
65
68
|
const isMatch = useShortcutEventMatch();
|
|
66
69
|
const isSticky = blockInformation?.positionType === 'sticky';
|
|
67
70
|
const images = useListViewImages( { clientId, isExpanded } );
|
|
@@ -83,10 +86,35 @@ function ListViewBlockSelectButton(
|
|
|
83
86
|
onDragStart?.( event );
|
|
84
87
|
};
|
|
85
88
|
|
|
89
|
+
// Determine which blocks to update:
|
|
90
|
+
// If the current (focused) block is part of the block selection, use the whole selection.
|
|
91
|
+
// If the focused block is not part of the block selection, only update the focused block.
|
|
92
|
+
function getBlocksToUpdate() {
|
|
93
|
+
const selectedBlockClientIds = getSelectedBlockClientIds();
|
|
94
|
+
const isUpdatingSelectedBlocks =
|
|
95
|
+
selectedBlockClientIds.includes( clientId );
|
|
96
|
+
const firstBlockClientId = isUpdatingSelectedBlocks
|
|
97
|
+
? selectedBlockClientIds[ 0 ]
|
|
98
|
+
: clientId;
|
|
99
|
+
const firstBlockRootClientId =
|
|
100
|
+
getBlockRootClientId( firstBlockClientId );
|
|
101
|
+
|
|
102
|
+
const blocksToUpdate = isUpdatingSelectedBlocks
|
|
103
|
+
? selectedBlockClientIds
|
|
104
|
+
: [ clientId ];
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
blocksToUpdate,
|
|
108
|
+
firstBlockClientId,
|
|
109
|
+
firstBlockRootClientId,
|
|
110
|
+
selectedBlockClientIds,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
86
114
|
/**
|
|
87
115
|
* @param {KeyboardEvent} event
|
|
88
116
|
*/
|
|
89
|
-
function onKeyDownHandler( event ) {
|
|
117
|
+
async function onKeyDownHandler( event ) {
|
|
90
118
|
if ( event.keyCode === ENTER || event.keyCode === SPACE ) {
|
|
91
119
|
onClick( event );
|
|
92
120
|
} else if (
|
|
@@ -94,18 +122,12 @@ function ListViewBlockSelectButton(
|
|
|
94
122
|
event.keyCode === DELETE ||
|
|
95
123
|
isMatch( 'core/block-editor/remove', event )
|
|
96
124
|
) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const firstBlockRootClientId =
|
|
104
|
-
getBlockRootClientId( firstBlockClientId );
|
|
105
|
-
|
|
106
|
-
const blocksToDelete = isDeletingSelectedBlocks
|
|
107
|
-
? selectedBlockClientIds
|
|
108
|
-
: [ clientId ];
|
|
125
|
+
const {
|
|
126
|
+
blocksToUpdate: blocksToDelete,
|
|
127
|
+
firstBlockClientId,
|
|
128
|
+
firstBlockRootClientId,
|
|
129
|
+
selectedBlockClientIds,
|
|
130
|
+
} = getBlocksToUpdate();
|
|
109
131
|
|
|
110
132
|
// Don't update the selection if the blocks cannot be deleted.
|
|
111
133
|
if ( ! canRemoveBlocks( blocksToDelete, firstBlockRootClientId ) ) {
|
|
@@ -131,6 +153,36 @@ function ListViewBlockSelectButton(
|
|
|
131
153
|
}
|
|
132
154
|
|
|
133
155
|
updateFocusAndSelection( blockToFocus, shouldUpdateSelection );
|
|
156
|
+
} else if ( isMatch( 'core/block-editor/duplicate', event ) ) {
|
|
157
|
+
if ( event.defaultPrevented ) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
|
|
162
|
+
const { blocksToUpdate, firstBlockRootClientId } =
|
|
163
|
+
getBlocksToUpdate();
|
|
164
|
+
|
|
165
|
+
const canDuplicate = getBlocksByClientId( blocksToUpdate ).every(
|
|
166
|
+
( block ) => {
|
|
167
|
+
return (
|
|
168
|
+
!! block &&
|
|
169
|
+
hasBlockSupport( block.name, 'multiple', true ) &&
|
|
170
|
+
canInsertBlockType( block.name, firstBlockRootClientId )
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
if ( canDuplicate ) {
|
|
176
|
+
const updatedBlocks = await duplicateBlocks(
|
|
177
|
+
blocksToUpdate,
|
|
178
|
+
false
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if ( updatedBlocks?.length ) {
|
|
182
|
+
// If blocks have been duplicated, focus the first duplicated block.
|
|
183
|
+
updateFocusAndSelection( updatedBlocks[ 0 ], false );
|
|
184
|
+
}
|
|
185
|
+
}
|
|
134
186
|
}
|
|
135
187
|
}
|
|
136
188
|
|
|
@@ -194,7 +246,7 @@ function ListViewBlockSelectButton(
|
|
|
194
246
|
{ images.map( ( image, index ) => (
|
|
195
247
|
<span
|
|
196
248
|
className="block-editor-list-view-block-select-button__image"
|
|
197
|
-
key={
|
|
249
|
+
key={ image.clientId }
|
|
198
250
|
style={ {
|
|
199
251
|
backgroundImage: `url(${ image.url })`,
|
|
200
252
|
zIndex: images.length - index, // Ensure the first image is on top, and subsequent images are behind.
|
|
@@ -159,10 +159,8 @@ export default function ListViewDropIndicator( {
|
|
|
159
159
|
return undefined;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
const ownerDocument = targetElement.ownerDocument;
|
|
163
|
-
|
|
164
162
|
return {
|
|
165
|
-
|
|
163
|
+
contextElement: targetElement,
|
|
166
164
|
getBoundingClientRect() {
|
|
167
165
|
const rect = targetElement.getBoundingClientRect();
|
|
168
166
|
const indent = getDropIndicatorIndent( rect );
|
|
@@ -189,9 +187,10 @@ export default function ListViewDropIndicator( {
|
|
|
189
187
|
'horizontal'
|
|
190
188
|
);
|
|
191
189
|
|
|
190
|
+
const doc = targetElement.ownerDocument;
|
|
192
191
|
const windowScroll =
|
|
193
|
-
scrollContainer ===
|
|
194
|
-
scrollContainer ===
|
|
192
|
+
scrollContainer === doc.body ||
|
|
193
|
+
scrollContainer === doc.documentElement;
|
|
195
194
|
|
|
196
195
|
// If the scroll container is not the window, offset the left position, if need be.
|
|
197
196
|
if ( scrollContainer && ! windowScroll ) {
|
|
@@ -159,19 +159,6 @@ function ListViewComponent(
|
|
|
159
159
|
isMounted.current = true;
|
|
160
160
|
}, [] );
|
|
161
161
|
|
|
162
|
-
// List View renders a fixed number of items and relies on each having a fixed item height of 36px.
|
|
163
|
-
// If this value changes, we should also change the itemHeight value set in useFixedWindowList.
|
|
164
|
-
// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.
|
|
165
|
-
const [ fixedListWindow ] = useFixedWindowList(
|
|
166
|
-
elementRef,
|
|
167
|
-
BLOCK_LIST_ITEM_HEIGHT,
|
|
168
|
-
visibleBlockCount,
|
|
169
|
-
{
|
|
170
|
-
useWindowing: true,
|
|
171
|
-
windowOverscan: 40,
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
|
|
175
162
|
const expand = useCallback(
|
|
176
163
|
( clientId ) => {
|
|
177
164
|
if ( ! clientId ) {
|
|
@@ -242,6 +229,25 @@ function ListViewComponent(
|
|
|
242
229
|
]
|
|
243
230
|
);
|
|
244
231
|
|
|
232
|
+
// List View renders a fixed number of items and relies on each having a fixed item height of 36px.
|
|
233
|
+
// If this value changes, we should also change the itemHeight value set in useFixedWindowList.
|
|
234
|
+
// See: https://github.com/WordPress/gutenberg/pull/35230 for additional context.
|
|
235
|
+
const [ fixedListWindow ] = useFixedWindowList(
|
|
236
|
+
elementRef,
|
|
237
|
+
BLOCK_LIST_ITEM_HEIGHT,
|
|
238
|
+
visibleBlockCount,
|
|
239
|
+
{
|
|
240
|
+
// Ensure that the windowing logic is recalculated when the expanded state changes.
|
|
241
|
+
// This is necessary because expanding a collapsed block in a short list view can
|
|
242
|
+
// switch the list view to a tall list view with a scrollbar, and vice versa.
|
|
243
|
+
// When this happens, the windowing logic needs to be recalculated to ensure that
|
|
244
|
+
// the correct number of blocks are rendered, by rechecking for a scroll container.
|
|
245
|
+
expandedState,
|
|
246
|
+
useWindowing: true,
|
|
247
|
+
windowOverscan: 40,
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
|
|
245
251
|
// If there are no blocks to show and we're not showing the appender, do not render the list view.
|
|
246
252
|
if ( ! clientIdsTree.length && ! showAppender ) {
|
|
247
253
|
return null;
|
|
@@ -12,13 +12,17 @@ import { store as blockEditorStore } from '../../store';
|
|
|
12
12
|
// Maximum number of images to display in a list view row.
|
|
13
13
|
const MAX_IMAGES = 3;
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function getImage( block ) {
|
|
16
16
|
if ( block.name !== 'core/image' ) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
if ( block.attributes?.url ) {
|
|
21
|
-
return {
|
|
21
|
+
return {
|
|
22
|
+
url: block.attributes.url,
|
|
23
|
+
alt: block.attributes.alt,
|
|
24
|
+
clientId: block.clientId,
|
|
25
|
+
};
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
|
|
@@ -30,7 +34,7 @@ function getImagesFromGallery( block ) {
|
|
|
30
34
|
const images = [];
|
|
31
35
|
|
|
32
36
|
for ( const innerBlock of block.innerBlocks ) {
|
|
33
|
-
const img =
|
|
37
|
+
const img = getImage( innerBlock );
|
|
34
38
|
if ( img ) {
|
|
35
39
|
images.push( img );
|
|
36
40
|
}
|
|
@@ -43,7 +47,7 @@ function getImagesFromGallery( block ) {
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
function getImagesFromBlock( block, isExpanded ) {
|
|
46
|
-
const img =
|
|
50
|
+
const img = getImage( block );
|
|
47
51
|
if ( img ) {
|
|
48
52
|
return [ img ];
|
|
49
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Observe Typing
|
|
2
2
|
|
|
3
|
-
`<ObserveTyping />` is a component used in managing the editor's internal typing flag. When used to wrap content
|
|
3
|
+
`<ObserveTyping />` is a component used in managing the editor's internal typing flag. When used to wrap content, it observes keyboard and mouse events to set and unset the typing flag. The typing flag is used in considering whether the block border and controls should be visible. While typing, these elements are hidden for a distraction-free experience.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ Wrap the component where blocks are to be rendered with `<ObserveTyping />`:
|
|
|
10
10
|
function VisualEditor() {
|
|
11
11
|
return (
|
|
12
12
|
<ObserveTyping>
|
|
13
|
-
<
|
|
13
|
+
<MyInput />
|
|
14
14
|
</ObserveTyping>
|
|
15
15
|
);
|
|
16
16
|
}
|
|
@@ -33,6 +33,7 @@ export default function PreviewOptions( {
|
|
|
33
33
|
const toggleProps = {
|
|
34
34
|
className: 'block-editor-post-preview__button-toggle',
|
|
35
35
|
disabled: ! isEnabled,
|
|
36
|
+
__experimentalIsFocusable: ! isEnabled,
|
|
36
37
|
children: viewLabel,
|
|
37
38
|
};
|
|
38
39
|
const menuProps = {
|
|
@@ -53,6 +54,7 @@ export default function PreviewOptions( {
|
|
|
53
54
|
menuProps={ menuProps }
|
|
54
55
|
icon={ deviceIcons[ deviceType.toLowerCase() ] }
|
|
55
56
|
label={ label || __( 'Preview' ) }
|
|
57
|
+
disableOpenOnArrowDown={ ! isEnabled }
|
|
56
58
|
>
|
|
57
59
|
{ ( renderProps ) => (
|
|
58
60
|
<>
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useDispatch } from '@wordpress/data';
|
|
5
5
|
import { useEffect } from '@wordpress/element';
|
|
6
|
+
import { SlotFillProvider } from '@wordpress/components';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
@@ -12,6 +13,7 @@ import useBlockSync from './use-block-sync';
|
|
|
12
13
|
import { store as blockEditorStore } from '../../store';
|
|
13
14
|
import { BlockRefsProvider } from './block-refs-provider';
|
|
14
15
|
import { unlock } from '../../lock-unlock';
|
|
16
|
+
import KeyboardShortcuts from '../keyboard-shortcuts';
|
|
15
17
|
|
|
16
18
|
/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */
|
|
17
19
|
|
|
@@ -42,7 +44,12 @@ export const ExperimentalBlockEditorProvider = withRegistryProvider(
|
|
|
42
44
|
// Syncs the entity provider with changes in the block-editor store.
|
|
43
45
|
useBlockSync( props );
|
|
44
46
|
|
|
45
|
-
return
|
|
47
|
+
return (
|
|
48
|
+
<SlotFillProvider>
|
|
49
|
+
<KeyboardShortcuts.Register />
|
|
50
|
+
<BlockRefsProvider>{ children }</BlockRefsProvider>
|
|
51
|
+
</SlotFillProvider>
|
|
52
|
+
);
|
|
46
53
|
}
|
|
47
54
|
);
|
|
48
55
|
|
|
@@ -126,28 +126,12 @@ const useActionsCommands = () => {
|
|
|
126
126
|
getBlocksByClientId,
|
|
127
127
|
canMoveBlocks,
|
|
128
128
|
canRemoveBlocks,
|
|
129
|
+
getBlockCount,
|
|
129
130
|
} = useSelect( blockEditorStore );
|
|
130
131
|
const { getDefaultBlockName, getGroupingBlockName } =
|
|
131
132
|
useSelect( blocksStore );
|
|
132
133
|
|
|
133
134
|
const blocks = getBlocksByClientId( clientIds );
|
|
134
|
-
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
|
|
135
|
-
|
|
136
|
-
const canDuplicate = blocks.every( ( block ) => {
|
|
137
|
-
return (
|
|
138
|
-
!! block &&
|
|
139
|
-
hasBlockSupport( block.name, 'multiple', true ) &&
|
|
140
|
-
canInsertBlockType( block.name, rootClientId )
|
|
141
|
-
);
|
|
142
|
-
} );
|
|
143
|
-
|
|
144
|
-
const canInsertDefaultBlock = canInsertBlockType(
|
|
145
|
-
getDefaultBlockName(),
|
|
146
|
-
rootClientId
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const canMove = canMoveBlocks( clientIds, rootClientId );
|
|
150
|
-
const canRemove = canRemoveBlocks( clientIds, rootClientId );
|
|
151
135
|
|
|
152
136
|
const {
|
|
153
137
|
removeBlocks,
|
|
@@ -160,42 +144,6 @@ const useActionsCommands = () => {
|
|
|
160
144
|
selectBlock,
|
|
161
145
|
} = useDispatch( blockEditorStore );
|
|
162
146
|
|
|
163
|
-
const onDuplicate = () => {
|
|
164
|
-
if ( ! canDuplicate ) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
return duplicateBlocks( clientIds, true );
|
|
168
|
-
};
|
|
169
|
-
const onRemove = () => {
|
|
170
|
-
if ( ! canRemove ) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
return removeBlocks( clientIds, true );
|
|
174
|
-
};
|
|
175
|
-
const onAddBefore = () => {
|
|
176
|
-
if ( ! canInsertDefaultBlock ) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const clientId = Array.isArray( clientIds ) ? clientIds[ 0 ] : clientId;
|
|
180
|
-
insertBeforeBlock( clientId );
|
|
181
|
-
};
|
|
182
|
-
const onAddAfter = () => {
|
|
183
|
-
if ( ! canInsertDefaultBlock ) {
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const clientId = Array.isArray( clientIds )
|
|
187
|
-
? clientIds[ clientIds.length - 1 ]
|
|
188
|
-
: clientId;
|
|
189
|
-
insertAfterBlock( clientId );
|
|
190
|
-
};
|
|
191
|
-
const onMoveTo = () => {
|
|
192
|
-
if ( ! canMove ) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
setNavigationMode( true );
|
|
196
|
-
selectBlock( clientIds[ 0 ] );
|
|
197
|
-
setBlockMovingClientId( clientIds[ 0 ] );
|
|
198
|
-
};
|
|
199
147
|
const onGroup = () => {
|
|
200
148
|
if ( ! blocks.length ) {
|
|
201
149
|
return;
|
|
@@ -229,47 +177,103 @@ const useActionsCommands = () => {
|
|
|
229
177
|
return { isLoading: false, commands: [] };
|
|
230
178
|
}
|
|
231
179
|
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
180
|
+
const rootClientId = getBlockRootClientId( clientIds[ 0 ] );
|
|
181
|
+
const canInsertDefaultBlock = canInsertBlockType(
|
|
182
|
+
getDefaultBlockName(),
|
|
183
|
+
rootClientId
|
|
184
|
+
);
|
|
185
|
+
const canDuplicate = blocks.every( ( block ) => {
|
|
186
|
+
return (
|
|
187
|
+
!! block &&
|
|
188
|
+
hasBlockSupport( block.name, 'multiple', true ) &&
|
|
189
|
+
canInsertBlockType( block.name, rootClientId )
|
|
190
|
+
);
|
|
191
|
+
} );
|
|
192
|
+
const canRemove = canRemoveBlocks( clientIds, rootClientId );
|
|
193
|
+
const canMove =
|
|
194
|
+
canMoveBlocks( clientIds, rootClientId ) &&
|
|
195
|
+
getBlockCount( rootClientId ) !== 1;
|
|
240
196
|
|
|
241
197
|
const commands = [
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
198
|
+
{
|
|
199
|
+
name: 'ungroup',
|
|
200
|
+
label: __( 'Ungroup' ),
|
|
201
|
+
callback: onUngroup,
|
|
202
|
+
icon: ungroup,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: 'Group',
|
|
206
|
+
label: __( 'Group' ),
|
|
207
|
+
callback: onGroup,
|
|
208
|
+
icon: group,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
if ( canInsertDefaultBlock ) {
|
|
212
|
+
commands.push(
|
|
213
|
+
{
|
|
214
|
+
name: 'add-after',
|
|
215
|
+
label: __( 'Add after' ),
|
|
216
|
+
callback: () => {
|
|
217
|
+
const clientId = Array.isArray( clientIds )
|
|
218
|
+
? clientIds[ clientIds.length - 1 ]
|
|
219
|
+
: clientId;
|
|
220
|
+
insertAfterBlock( clientId );
|
|
221
|
+
},
|
|
222
|
+
icon: add,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: 'add-before',
|
|
226
|
+
label: __( 'Add before' ),
|
|
227
|
+
callback: () => {
|
|
228
|
+
const clientId = Array.isArray( clientIds )
|
|
229
|
+
? clientIds[ 0 ]
|
|
230
|
+
: clientId;
|
|
231
|
+
insertBeforeBlock( clientId );
|
|
232
|
+
},
|
|
233
|
+
icon: add,
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
if ( canRemove ) {
|
|
238
|
+
commands.push( {
|
|
239
|
+
name: 'remove',
|
|
240
|
+
label: __( 'Remove' ),
|
|
241
|
+
callback: () => removeBlocks( clientIds, true ),
|
|
242
|
+
icon: remove,
|
|
243
|
+
} );
|
|
244
|
+
}
|
|
245
|
+
if ( canDuplicate ) {
|
|
246
|
+
commands.push( {
|
|
247
|
+
name: 'duplicate',
|
|
248
|
+
label: __( 'Duplicate' ),
|
|
249
|
+
callback: () => duplicateBlocks( clientIds, true ),
|
|
250
|
+
icon: copy,
|
|
251
|
+
} );
|
|
252
|
+
}
|
|
253
|
+
if ( canMove ) {
|
|
254
|
+
commands.push( {
|
|
255
|
+
name: 'move-to',
|
|
256
|
+
label: __( 'Move to' ),
|
|
257
|
+
callback: () => {
|
|
258
|
+
setNavigationMode( true );
|
|
259
|
+
selectBlock( clientIds[ 0 ] );
|
|
260
|
+
setBlockMovingClientId( clientIds[ 0 ] );
|
|
261
|
+
},
|
|
262
|
+
icon: move,
|
|
263
|
+
} );
|
|
264
|
+
}
|
|
253
265
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
callback.name
|
|
260
|
-
.replace( 'on', '' )
|
|
261
|
-
.match( /[A-Z]{1}[a-z]*/ )
|
|
262
|
-
.toString()
|
|
263
|
-
.toLowerCase()
|
|
264
|
-
],
|
|
266
|
+
return {
|
|
267
|
+
isLoading: false,
|
|
268
|
+
commands: commands.map( ( command ) => ( {
|
|
269
|
+
...command,
|
|
270
|
+
name: 'core/block-editor/action-' + command.name,
|
|
265
271
|
callback: ( { close } ) => {
|
|
266
|
-
callback();
|
|
272
|
+
command.callback();
|
|
267
273
|
close();
|
|
268
274
|
},
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return { isLoading: false, commands };
|
|
275
|
+
} ) ),
|
|
276
|
+
};
|
|
273
277
|
};
|
|
274
278
|
|
|
275
279
|
export const useBlockCommands = () => {
|
|
@@ -9,7 +9,7 @@ import classnames from 'classnames';
|
|
|
9
9
|
import { Children } from '@wordpress/element';
|
|
10
10
|
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
|
-
import {
|
|
12
|
+
import { moreVertical } from '@wordpress/icons';
|
|
13
13
|
|
|
14
14
|
function Warning( { className, actions, children, secondaryActions } ) {
|
|
15
15
|
return (
|
|
@@ -34,7 +34,7 @@ function Warning( { className, actions, children, secondaryActions } ) {
|
|
|
34
34
|
{ secondaryActions && (
|
|
35
35
|
<DropdownMenu
|
|
36
36
|
className="block-editor-warning__secondary"
|
|
37
|
-
icon={
|
|
37
|
+
icon={ moreVertical }
|
|
38
38
|
label={ __( 'More options' ) }
|
|
39
39
|
popoverProps={ {
|
|
40
40
|
position: 'bottom left',
|