@wordpress/block-editor 14.3.5 → 14.3.7
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/README.md +6 -2
- package/build/components/block-list/block.js +0 -3
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -4
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +14 -6
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js +9 -12
- package/build/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build/components/block-list/zoom-out-separator.js +10 -7
- package/build/components/block-list/zoom-out-separator.js.map +1 -1
- package/build/components/block-popover/index.js +1 -1
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/block-toolbar/index.js +28 -16
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-toolbar/use-has-block-toolbar.js +3 -3
- package/build/components/block-toolbar/use-has-block-toolbar.js.map +1 -1
- package/build/components/block-tools/index.js +1 -6
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/block-tools/use-show-block-tools.js +4 -6
- package/build/components/block-tools/use-show-block-tools.js.map +1 -1
- package/build/components/block-tools/zoom-out-mode-inserters.js +22 -36
- package/build/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build/components/iframe/index.js +45 -10
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab/index.js +4 -0
- package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build/components/inserter/hooks/use-insertion-point.js +16 -4
- package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build/components/inserter/media-tab/media-tab.js +4 -0
- package/build/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build/components/inserter/menu.js +8 -2
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/tool-selector/index.js +5 -1
- package/build/components/tool-selector/index.js.map +1 -1
- package/build/components/use-resize-canvas/index.js +1 -2
- package/build/components/use-resize-canvas/index.js.map +1 -1
- package/build/hooks/block-bindings.js +12 -1
- package/build/hooks/block-bindings.js.map +1 -1
- package/build/hooks/grid-visualizer.js +13 -11
- package/build/hooks/grid-visualizer.js.map +1 -1
- package/build/hooks/layout-child.js +41 -3
- package/build/hooks/layout-child.js.map +1 -1
- package/build/hooks/use-zoom-out.js +24 -16
- package/build/hooks/use-zoom-out.js.map +1 -1
- package/build/private-apis.js +2 -0
- package/build/private-apis.js.map +1 -1
- package/build/store/private-selectors.js +37 -2
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/selectors.js +15 -8
- package/build/store/selectors.js.map +1 -1
- package/build/utils/block-bindings.js +9 -6
- package/build/utils/block-bindings.js.map +1 -1
- package/build-module/components/block-list/block.js +0 -3
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -4
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +14 -6
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js +9 -12
- package/build-module/components/block-list/use-block-props/use-zoom-out-mode-exit.js.map +1 -1
- package/build-module/components/block-list/zoom-out-separator.js +10 -7
- package/build-module/components/block-list/zoom-out-separator.js.map +1 -1
- package/build-module/components/block-popover/index.js +1 -1
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +30 -18
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-toolbar/use-has-block-toolbar.js +3 -3
- package/build-module/components/block-toolbar/use-has-block-toolbar.js.map +1 -1
- package/build-module/components/block-tools/index.js +1 -6
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/block-tools/use-show-block-tools.js +4 -6
- package/build-module/components/block-tools/use-show-block-tools.js.map +1 -1
- package/build-module/components/block-tools/zoom-out-mode-inserters.js +22 -36
- package/build-module/components/block-tools/zoom-out-mode-inserters.js.map +1 -1
- package/build-module/components/iframe/index.js +45 -10
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab/index.js +5 -1
- package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
- package/build-module/components/inserter/hooks/use-insertion-point.js +16 -4
- package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build-module/components/inserter/media-tab/media-tab.js +5 -1
- package/build-module/components/inserter/media-tab/media-tab.js.map +1 -1
- package/build-module/components/inserter/menu.js +8 -2
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/tool-selector/index.js +5 -1
- package/build-module/components/tool-selector/index.js.map +1 -1
- package/build-module/components/use-resize-canvas/index.js +1 -2
- package/build-module/components/use-resize-canvas/index.js.map +1 -1
- package/build-module/hooks/block-bindings.js +13 -2
- package/build-module/hooks/block-bindings.js.map +1 -1
- package/build-module/hooks/grid-visualizer.js +13 -11
- package/build-module/hooks/grid-visualizer.js.map +1 -1
- package/build-module/hooks/layout-child.js +41 -3
- package/build-module/hooks/layout-child.js.map +1 -1
- package/build-module/hooks/use-zoom-out.js +24 -17
- package/build-module/hooks/use-zoom-out.js.map +1 -1
- package/build-module/private-apis.js +2 -0
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/private-selectors.js +35 -2
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/selectors.js +15 -8
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/block-bindings.js +9 -6
- package/build-module/utils/block-bindings.js.map +1 -1
- package/build-style/content-rtl.css +19 -26
- package/build-style/content.css +19 -26
- package/build-style/style-rtl.css +36 -21
- package/build-style/style.css +36 -21
- package/package.json +6 -6
- package/src/components/block-canvas/style.scss +1 -0
- package/src/components/block-list/block.js +0 -3
- package/src/components/block-list/content.scss +3 -2
- package/src/components/block-list/use-block-props/index.js +1 -2
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +25 -4
- package/src/components/block-list/use-block-props/use-zoom-out-mode-exit.js +19 -11
- package/src/components/block-list/zoom-out-separator.js +8 -6
- package/src/components/block-popover/index.js +2 -2
- package/src/components/block-toolbar/index.js +37 -24
- package/src/components/block-toolbar/style.scss +10 -1
- package/src/components/block-toolbar/use-has-block-toolbar.js +19 -28
- package/src/components/block-tools/index.js +0 -9
- package/src/components/block-tools/style.scss +2 -26
- package/src/components/block-tools/use-show-block-tools.js +2 -10
- package/src/components/block-tools/zoom-out-mode-inserters.js +26 -50
- package/src/components/iframe/content.scss +23 -32
- package/src/components/iframe/index.js +60 -13
- package/src/components/iframe/style.scss +18 -0
- package/src/components/inserter/block-patterns-tab/index.js +6 -1
- package/src/components/inserter/hooks/use-insertion-point.js +23 -5
- package/src/components/inserter/media-tab/media-tab.js +6 -1
- package/src/components/inserter/menu.js +12 -1
- package/src/components/inserter/style.scss +6 -0
- package/src/components/list-view/style.scss +9 -0
- package/src/components/rich-text/style.scss +5 -0
- package/src/components/tool-selector/index.js +5 -2
- package/src/components/use-resize-canvas/index.js +1 -3
- package/src/hooks/block-bindings.js +40 -23
- package/src/hooks/grid-visualizer.js +23 -9
- package/src/hooks/layout-child.js +48 -3
- package/src/hooks/use-zoom-out.js +36 -20
- package/src/private-apis.js +2 -0
- package/src/store/private-selectors.js +40 -1
- package/src/store/selectors.js +16 -8
- package/src/style.scss +1 -0
- package/src/utils/block-bindings.js +9 -6
- package/src/utils/test/use-block-bindings-utils.js +174 -0
- package/build/components/block-tools/zoom-out-popover.js +0 -57
- package/build/components/block-tools/zoom-out-popover.js.map +0 -1
- package/build/components/block-tools/zoom-out-toolbar.js +0 -159
- package/build/components/block-tools/zoom-out-toolbar.js.map +0 -1
- package/build-module/components/block-tools/zoom-out-popover.js +0 -48
- package/build-module/components/block-tools/zoom-out-popover.js.map +0 -1
- package/build-module/components/block-tools/zoom-out-toolbar.js +0 -152
- package/build-module/components/block-tools/zoom-out-toolbar.js.map +0 -1
- package/src/components/block-tools/zoom-out-popover.js +0 -46
- package/src/components/block-tools/zoom-out-toolbar.js +0 -167
|
@@ -9,39 +9,55 @@ import { useEffect, useRef } from '@wordpress/element';
|
|
|
9
9
|
*/
|
|
10
10
|
import { store as blockEditorStore } from '../store';
|
|
11
11
|
import { unlock } from '../lock-unlock';
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
|
-
* A hook used to set the zoomed out
|
|
13
|
+
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
|
|
15
14
|
*
|
|
16
|
-
* @param {boolean} zoomOut If we should
|
|
15
|
+
* @param {boolean} zoomOut If we should enter into zoomOut mode or not
|
|
17
16
|
*/
|
|
18
17
|
export function useZoomOut( zoomOut = true ) {
|
|
19
|
-
const { setZoomLevel } = unlock(
|
|
20
|
-
|
|
18
|
+
const { __unstableSetEditorMode, setZoomLevel } = unlock(
|
|
19
|
+
useDispatch( blockEditorStore )
|
|
20
|
+
);
|
|
21
|
+
const { __unstableGetEditorMode } = unlock( useSelect( blockEditorStore ) );
|
|
21
22
|
|
|
22
|
-
const
|
|
23
|
+
const originalEditingModeRef = useRef( null );
|
|
24
|
+
const mode = __unstableGetEditorMode();
|
|
23
25
|
|
|
24
26
|
useEffect( () => {
|
|
25
27
|
// Only set this on mount so we know what to return to when we unmount.
|
|
26
|
-
if ( !
|
|
27
|
-
|
|
28
|
+
if ( ! originalEditingModeRef.current ) {
|
|
29
|
+
originalEditingModeRef.current = mode;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
return () => {
|
|
33
|
+
// We need to use __unstableGetEditorMode() here and not `mode`, as mode may not update on unmount
|
|
34
|
+
if (
|
|
35
|
+
__unstableGetEditorMode() === 'zoom-out' &&
|
|
36
|
+
__unstableGetEditorMode() !== originalEditingModeRef.current
|
|
37
|
+
) {
|
|
38
|
+
__unstableSetEditorMode( originalEditingModeRef.current );
|
|
39
|
+
setZoomLevel( 100 );
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}, [] );
|
|
43
|
+
|
|
44
|
+
// The effect opens the zoom-out view if we want it open and it's not currently in zoom-out mode.
|
|
45
|
+
useEffect( () => {
|
|
46
|
+
if ( zoomOut && mode !== 'zoom-out' ) {
|
|
47
|
+
__unstableSetEditorMode( 'zoom-out' );
|
|
32
48
|
setZoomLevel( 50 );
|
|
33
49
|
} else if (
|
|
34
50
|
! zoomOut &&
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
__unstableGetEditorMode() === 'zoom-out' &&
|
|
52
|
+
originalEditingModeRef.current !== mode
|
|
37
53
|
) {
|
|
38
|
-
|
|
54
|
+
__unstableSetEditorMode( originalEditingModeRef.current );
|
|
55
|
+
setZoomLevel( 100 );
|
|
39
56
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}, [ isZoomOut, setZoomLevel, zoomOut ] );
|
|
57
|
+
}, [
|
|
58
|
+
__unstableGetEditorMode,
|
|
59
|
+
__unstableSetEditorMode,
|
|
60
|
+
zoomOut,
|
|
61
|
+
setZoomLevel,
|
|
62
|
+
] ); // Mode is deliberately excluded from the dependencies so that the effect does not run when mode changes.
|
|
47
63
|
}
|
package/src/private-apis.js
CHANGED
|
@@ -32,6 +32,7 @@ import { usesContextKey } from './components/rich-text/format-edit';
|
|
|
32
32
|
import { ExperimentalBlockCanvas } from './components/block-canvas';
|
|
33
33
|
import { getDuotoneFilter } from './components/duotone/utils';
|
|
34
34
|
import { useFlashEditableBlocks } from './components/use-flash-editable-blocks';
|
|
35
|
+
import { useZoomOutModeExit } from './components/block-list/use-block-props/use-zoom-out-mode-exit';
|
|
35
36
|
import {
|
|
36
37
|
selectBlockPatternsKey,
|
|
37
38
|
reusableBlocksSelectKey,
|
|
@@ -78,6 +79,7 @@ lock( privateApis, {
|
|
|
78
79
|
TextAlignmentControl,
|
|
79
80
|
usesContextKey,
|
|
80
81
|
useFlashEditableBlocks,
|
|
82
|
+
useZoomOutModeExit,
|
|
81
83
|
globalStylesDataKey,
|
|
82
84
|
globalStylesLinksDataKey,
|
|
83
85
|
selectBlockPatternsKey,
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
getBlockName,
|
|
16
16
|
getTemplateLock,
|
|
17
17
|
getClientIdsWithDescendants,
|
|
18
|
+
isNavigationMode,
|
|
19
|
+
__unstableGetEditorMode,
|
|
18
20
|
} from './selectors';
|
|
19
21
|
import {
|
|
20
22
|
checkAllowListRecursive,
|
|
@@ -545,7 +547,7 @@ export const getBlockStyles = createSelector(
|
|
|
545
547
|
* @return {boolean} Is zoom out mode enabled.
|
|
546
548
|
*/
|
|
547
549
|
export function isZoomOutMode( state ) {
|
|
548
|
-
return state
|
|
550
|
+
return __unstableGetEditorMode( state ) === 'zoom-out';
|
|
549
551
|
}
|
|
550
552
|
|
|
551
553
|
/**
|
|
@@ -580,3 +582,40 @@ export function getZoomLevel( state ) {
|
|
|
580
582
|
export function isZoomOut( state ) {
|
|
581
583
|
return getZoomLevel( state ) < 100;
|
|
582
584
|
}
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Retrieves the client ID of the parent section block.
|
|
588
|
+
*
|
|
589
|
+
* @param {Object} state Global application state.
|
|
590
|
+
* @param {string} clientId Client Id of the block.
|
|
591
|
+
*
|
|
592
|
+
* @return {?string} Client ID of the ancestor block that is content locking the block.
|
|
593
|
+
*/
|
|
594
|
+
export const getParentSectionBlock = ( state, clientId ) => {
|
|
595
|
+
let current = clientId;
|
|
596
|
+
let result;
|
|
597
|
+
while ( ! result && ( current = state.blocks.parents.get( current ) ) ) {
|
|
598
|
+
if ( isSectionBlock( state, current ) ) {
|
|
599
|
+
result = current;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return result;
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Retrieves the client ID is a content locking parent
|
|
607
|
+
*
|
|
608
|
+
* @param {Object} state Global application state.
|
|
609
|
+
* @param {string} clientId Client Id of the block.
|
|
610
|
+
*
|
|
611
|
+
* @return {boolean} Whether the block is a content locking parent.
|
|
612
|
+
*/
|
|
613
|
+
export function isSectionBlock( state, clientId ) {
|
|
614
|
+
const sectionRootClientId = getSectionRootClientId( state );
|
|
615
|
+
const sectionClientIds = getBlockOrder( state, sectionRootClientId );
|
|
616
|
+
return (
|
|
617
|
+
getBlockName( state, clientId ) === 'core/block' ||
|
|
618
|
+
getTemplateLock( state, clientId ) === 'contentOnly' ||
|
|
619
|
+
( isNavigationMode( state ) && sectionClientIds.includes( clientId ) )
|
|
620
|
+
);
|
|
621
|
+
}
|
package/src/store/selectors.js
CHANGED
|
@@ -2363,6 +2363,21 @@ const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) => [
|
|
|
2363
2363
|
...getInsertBlockTypeDependants( state, rootClientId ),
|
|
2364
2364
|
];
|
|
2365
2365
|
|
|
2366
|
+
const patternsWithParsedBlocks = new WeakMap();
|
|
2367
|
+
function enhancePatternWithParsedBlocks( pattern ) {
|
|
2368
|
+
let enhancedPattern = patternsWithParsedBlocks.get( pattern );
|
|
2369
|
+
if ( ! enhancedPattern ) {
|
|
2370
|
+
enhancedPattern = {
|
|
2371
|
+
...pattern,
|
|
2372
|
+
get blocks() {
|
|
2373
|
+
return getParsedPattern( pattern ).blocks;
|
|
2374
|
+
},
|
|
2375
|
+
};
|
|
2376
|
+
patternsWithParsedBlocks.set( pattern, enhancedPattern );
|
|
2377
|
+
}
|
|
2378
|
+
return enhancedPattern;
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2366
2381
|
/**
|
|
2367
2382
|
* Returns the list of allowed patterns for inner blocks children.
|
|
2368
2383
|
*
|
|
@@ -2379,14 +2394,7 @@ export const __experimentalGetAllowedPatterns = createRegistrySelector(
|
|
|
2379
2394
|
const { allowedBlockTypes } = getSettings( state );
|
|
2380
2395
|
const parsedPatterns = patterns
|
|
2381
2396
|
.filter( ( { inserter = true } ) => !! inserter )
|
|
2382
|
-
.map(
|
|
2383
|
-
return {
|
|
2384
|
-
...pattern,
|
|
2385
|
-
get blocks() {
|
|
2386
|
-
return getParsedPattern( pattern ).blocks;
|
|
2387
|
-
},
|
|
2388
|
-
};
|
|
2389
|
-
} );
|
|
2397
|
+
.map( enhancePatternWithParsedBlocks );
|
|
2390
2398
|
|
|
2391
2399
|
const availableParsedPatterns = parsedPatterns.filter(
|
|
2392
2400
|
( pattern ) =>
|
package/src/style.scss
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
@import "./components/global-styles/style.scss";
|
|
31
31
|
@import "./components/grid/style.scss";
|
|
32
32
|
@import "./components/height-control/style.scss";
|
|
33
|
+
@import "./components/iframe/style.scss";
|
|
33
34
|
@import "./components/image-size-control/style.scss";
|
|
34
35
|
@import "./components/inserter-list-item/style.scss";
|
|
35
36
|
@import "./components/inspector-controls-tabs/style.scss";
|
|
@@ -30,6 +30,8 @@ function isObjectEmpty( object ) {
|
|
|
30
30
|
* - `updateBlockBindings`: Updates the value of the bindings connected to block attributes. It can be used to remove a specific binding by setting the value to `undefined`.
|
|
31
31
|
* - `removeAllBlockBindings`: Removes the bindings property of the `metadata` attribute.
|
|
32
32
|
*
|
|
33
|
+
* @param {?string} clientId Optional block client ID. If not set, it will use the current block client ID from the context.
|
|
34
|
+
*
|
|
33
35
|
* @return {?WPBlockBindingsUtils} Object containing the block bindings utils.
|
|
34
36
|
*
|
|
35
37
|
* @example
|
|
@@ -60,8 +62,9 @@ function isObjectEmpty( object ) {
|
|
|
60
62
|
* removeAllBlockBindings();
|
|
61
63
|
* ```
|
|
62
64
|
*/
|
|
63
|
-
export function useBlockBindingsUtils() {
|
|
64
|
-
const { clientId } = useBlockEditContext();
|
|
65
|
+
export function useBlockBindingsUtils( clientId ) {
|
|
66
|
+
const { clientId: contextClientId } = useBlockEditContext();
|
|
67
|
+
const blockClientId = clientId || contextClientId;
|
|
65
68
|
const { updateBlockAttributes } = useDispatch( blockEditorStore );
|
|
66
69
|
const { getBlockAttributes } = useRegistry().select( blockEditorStore );
|
|
67
70
|
|
|
@@ -96,7 +99,7 @@ export function useBlockBindingsUtils() {
|
|
|
96
99
|
*/
|
|
97
100
|
const updateBlockBindings = ( bindings ) => {
|
|
98
101
|
const { metadata: { bindings: currentBindings, ...metadata } = {} } =
|
|
99
|
-
getBlockAttributes(
|
|
102
|
+
getBlockAttributes( blockClientId );
|
|
100
103
|
const newBindings = { ...currentBindings };
|
|
101
104
|
|
|
102
105
|
Object.entries( bindings ).forEach( ( [ attribute, binding ] ) => {
|
|
@@ -116,7 +119,7 @@ export function useBlockBindingsUtils() {
|
|
|
116
119
|
delete newMetadata.bindings;
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
updateBlockAttributes(
|
|
122
|
+
updateBlockAttributes( blockClientId, {
|
|
120
123
|
metadata: isObjectEmpty( newMetadata ) ? undefined : newMetadata,
|
|
121
124
|
} );
|
|
122
125
|
};
|
|
@@ -134,8 +137,8 @@ export function useBlockBindingsUtils() {
|
|
|
134
137
|
*/
|
|
135
138
|
const removeAllBlockBindings = () => {
|
|
136
139
|
const { metadata: { bindings, ...metadata } = {} } =
|
|
137
|
-
getBlockAttributes(
|
|
138
|
-
updateBlockAttributes(
|
|
140
|
+
getBlockAttributes( blockClientId );
|
|
141
|
+
updateBlockAttributes( blockClientId, {
|
|
139
142
|
metadata: isObjectEmpty( metadata ) ? undefined : metadata,
|
|
140
143
|
} );
|
|
141
144
|
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { renderHook } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
10
|
+
import { dispatch, select } from '@wordpress/data';
|
|
11
|
+
import {
|
|
12
|
+
createBlock,
|
|
13
|
+
getBlockTypes,
|
|
14
|
+
unregisterBlockType,
|
|
15
|
+
} from '@wordpress/blocks';
|
|
16
|
+
import { registerCoreBlocks } from '@wordpress/block-library';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
import { useBlockBindingsUtils } from '../';
|
|
22
|
+
|
|
23
|
+
describe( 'useBlockBindingsUtils', () => {
|
|
24
|
+
beforeAll( () => {
|
|
25
|
+
// Register all core blocks
|
|
26
|
+
registerCoreBlocks();
|
|
27
|
+
} );
|
|
28
|
+
|
|
29
|
+
let clientId;
|
|
30
|
+
beforeEach( async () => {
|
|
31
|
+
const block = createBlock( 'core/paragraph', {
|
|
32
|
+
metadata: {
|
|
33
|
+
name: 'Block name',
|
|
34
|
+
bindings: {
|
|
35
|
+
prop1: {
|
|
36
|
+
source: 'core/post-meta',
|
|
37
|
+
args: {
|
|
38
|
+
key: 'initial_key',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
prop2: {
|
|
42
|
+
source: 'core/post-meta',
|
|
43
|
+
args: {
|
|
44
|
+
key: 'initial_key',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
} );
|
|
50
|
+
await dispatch( blockEditorStore ).resetBlocks( [ block ] );
|
|
51
|
+
clientId = block.clientId;
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
afterAll( () => {
|
|
55
|
+
// Remove blocks after all tests.
|
|
56
|
+
dispatch( blockEditorStore ).resetBlocks( [] );
|
|
57
|
+
|
|
58
|
+
// Clean up registered blocks
|
|
59
|
+
getBlockTypes().forEach( ( block ) => {
|
|
60
|
+
unregisterBlockType( block.name );
|
|
61
|
+
} );
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
it( 'should be possible to update just one connection', async () => {
|
|
65
|
+
renderHook( () => {
|
|
66
|
+
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
67
|
+
updateBlockBindings( {
|
|
68
|
+
prop1: {
|
|
69
|
+
source: 'core/post-meta',
|
|
70
|
+
args: {
|
|
71
|
+
key: 'new_key',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
} );
|
|
75
|
+
} );
|
|
76
|
+
const { metadata } =
|
|
77
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
78
|
+
expect( metadata ).toMatchObject( {
|
|
79
|
+
// Other metadata properties shouldn't change.
|
|
80
|
+
name: 'Block name',
|
|
81
|
+
bindings: {
|
|
82
|
+
prop1: {
|
|
83
|
+
source: 'core/post-meta',
|
|
84
|
+
args: {
|
|
85
|
+
key: 'new_key',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
prop2: {
|
|
89
|
+
source: 'core/post-meta',
|
|
90
|
+
args: {
|
|
91
|
+
key: 'initial_key',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
} );
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
it( 'should be possible to update multiple connections at once', async () => {
|
|
99
|
+
renderHook( () => {
|
|
100
|
+
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
101
|
+
updateBlockBindings( {
|
|
102
|
+
prop1: {
|
|
103
|
+
source: 'core/post-meta',
|
|
104
|
+
args: {
|
|
105
|
+
key: 'new_key',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
prop2: {
|
|
109
|
+
source: 'core/post-meta',
|
|
110
|
+
args: {
|
|
111
|
+
key: 'new_key',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
} );
|
|
115
|
+
} );
|
|
116
|
+
const { metadata } =
|
|
117
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
118
|
+
expect( metadata ).toMatchObject( {
|
|
119
|
+
// Other metadata properties shouldn't change.
|
|
120
|
+
name: 'Block name',
|
|
121
|
+
bindings: {
|
|
122
|
+
prop1: {
|
|
123
|
+
source: 'core/post-meta',
|
|
124
|
+
args: {
|
|
125
|
+
key: 'new_key',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
prop2: {
|
|
129
|
+
source: 'core/post-meta',
|
|
130
|
+
args: {
|
|
131
|
+
key: 'new_key',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
} );
|
|
136
|
+
} );
|
|
137
|
+
|
|
138
|
+
it( 'should be possible to remove connections', async () => {
|
|
139
|
+
renderHook( () => {
|
|
140
|
+
const { updateBlockBindings } = useBlockBindingsUtils( clientId );
|
|
141
|
+
updateBlockBindings( {
|
|
142
|
+
prop2: undefined,
|
|
143
|
+
} );
|
|
144
|
+
} );
|
|
145
|
+
const { metadata } =
|
|
146
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
147
|
+
expect( metadata ).toMatchObject( {
|
|
148
|
+
// Other metadata properties shouldn't change.
|
|
149
|
+
name: 'Block name',
|
|
150
|
+
bindings: {
|
|
151
|
+
prop1: {
|
|
152
|
+
source: 'core/post-meta',
|
|
153
|
+
args: {
|
|
154
|
+
key: 'initial_key',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
} );
|
|
159
|
+
} );
|
|
160
|
+
|
|
161
|
+
it( 'should be possible to remove all connections', async () => {
|
|
162
|
+
renderHook( () => {
|
|
163
|
+
const { removeAllBlockBindings } =
|
|
164
|
+
useBlockBindingsUtils( clientId );
|
|
165
|
+
removeAllBlockBindings();
|
|
166
|
+
} );
|
|
167
|
+
const { metadata } =
|
|
168
|
+
await select( blockEditorStore ).getBlockAttributes( clientId );
|
|
169
|
+
expect( metadata ).toMatchObject( {
|
|
170
|
+
// Other metadata properties shouldn't change.
|
|
171
|
+
name: 'Block name',
|
|
172
|
+
} );
|
|
173
|
+
} );
|
|
174
|
+
} );
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = ZoomOutPopover;
|
|
8
|
-
var _clsx = _interopRequireDefault(require("clsx"));
|
|
9
|
-
var _blockPopover = _interopRequireDefault(require("../block-popover"));
|
|
10
|
-
var _useBlockToolbarPopoverProps = _interopRequireDefault(require("./use-block-toolbar-popover-props"));
|
|
11
|
-
var _useSelectedBlockToolProps = _interopRequireDefault(require("./use-selected-block-tool-props"));
|
|
12
|
-
var _zoomOutToolbar = _interopRequireDefault(require("./zoom-out-toolbar"));
|
|
13
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
/**
|
|
15
|
-
* External dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
function ZoomOutPopover({
|
|
23
|
-
clientId,
|
|
24
|
-
__unstableContentRef
|
|
25
|
-
}) {
|
|
26
|
-
const {
|
|
27
|
-
capturingClientId,
|
|
28
|
-
isInsertionPointVisible,
|
|
29
|
-
lastClientId
|
|
30
|
-
} = (0, _useSelectedBlockToolProps.default)(clientId);
|
|
31
|
-
const popoverProps = (0, _useBlockToolbarPopoverProps.default)({
|
|
32
|
-
contentElement: __unstableContentRef?.current,
|
|
33
|
-
clientId
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Override some of the popover props for the zoom-out toolbar.
|
|
37
|
-
const props = {
|
|
38
|
-
...popoverProps,
|
|
39
|
-
placement: 'left-start',
|
|
40
|
-
flip: false,
|
|
41
|
-
shift: true
|
|
42
|
-
};
|
|
43
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockPopover.default, {
|
|
44
|
-
clientId: capturingClientId || clientId,
|
|
45
|
-
bottomClientId: lastClientId,
|
|
46
|
-
className: (0, _clsx.default)('zoom-out-toolbar-popover', {
|
|
47
|
-
'is-insertion-point-visible': isInsertionPointVisible
|
|
48
|
-
}),
|
|
49
|
-
resize: false,
|
|
50
|
-
...props,
|
|
51
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_zoomOutToolbar.default, {
|
|
52
|
-
__unstableContentRef: __unstableContentRef,
|
|
53
|
-
clientId: clientId
|
|
54
|
-
})
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=zoom-out-popover.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_blockPopover","_useBlockToolbarPopoverProps","_useSelectedBlockToolProps","_zoomOutToolbar","_jsxRuntime","ZoomOutPopover","clientId","__unstableContentRef","capturingClientId","isInsertionPointVisible","lastClientId","useSelectedBlockToolProps","popoverProps","useBlockToolbarPopoverProps","contentElement","current","props","placement","flip","shift","jsx","default","bottomClientId","className","clsx","resize","children"],"sources":["@wordpress/block-editor/src/components/block-tools/zoom-out-popover.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * Internal dependencies\n */\nimport BlockPopover from '../block-popover';\nimport useBlockToolbarPopoverProps from './use-block-toolbar-popover-props';\nimport useSelectedBlockToolProps from './use-selected-block-tool-props';\nimport ZoomOutToolbar from './zoom-out-toolbar';\n\nexport default function ZoomOutPopover( { clientId, __unstableContentRef } ) {\n\tconst { capturingClientId, isInsertionPointVisible, lastClientId } =\n\t\tuseSelectedBlockToolProps( clientId );\n\n\tconst popoverProps = useBlockToolbarPopoverProps( {\n\t\tcontentElement: __unstableContentRef?.current,\n\t\tclientId,\n\t} );\n\n\t// Override some of the popover props for the zoom-out toolbar.\n\tconst props = {\n\t\t...popoverProps,\n\t\tplacement: 'left-start',\n\t\tflip: false,\n\t\tshift: true,\n\t};\n\n\treturn (\n\t\t<BlockPopover\n\t\t\tclientId={ capturingClientId || clientId }\n\t\t\tbottomClientId={ lastClientId }\n\t\t\tclassName={ clsx( 'zoom-out-toolbar-popover', {\n\t\t\t\t'is-insertion-point-visible': isInsertionPointVisible,\n\t\t\t} ) }\n\t\t\tresize={ false }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t<ZoomOutToolbar\n\t\t\t\t__unstableContentRef={ __unstableContentRef }\n\t\t\t\tclientId={ clientId }\n\t\t\t/>\n\t\t</BlockPopover>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,4BAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,0BAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,eAAA,GAAAL,sBAAA,CAAAC,OAAA;AAAgD,IAAAK,WAAA,GAAAL,OAAA;AAVhD;AACA;AACA;;AAEA;AACA;AACA;;AAMe,SAASM,cAAcA,CAAE;EAAEC,QAAQ;EAAEC;AAAqB,CAAC,EAAG;EAC5E,MAAM;IAAEC,iBAAiB;IAAEC,uBAAuB;IAAEC;EAAa,CAAC,GACjE,IAAAC,kCAAyB,EAAEL,QAAS,CAAC;EAEtC,MAAMM,YAAY,GAAG,IAAAC,oCAA2B,EAAE;IACjDC,cAAc,EAAEP,oBAAoB,EAAEQ,OAAO;IAC7CT;EACD,CAAE,CAAC;;EAEH;EACA,MAAMU,KAAK,GAAG;IACb,GAAGJ,YAAY;IACfK,SAAS,EAAE,YAAY;IACvBC,IAAI,EAAE,KAAK;IACXC,KAAK,EAAE;EACR,CAAC;EAED,oBACC,IAAAf,WAAA,CAAAgB,GAAA,EAACpB,aAAA,CAAAqB,OAAY;IACZf,QAAQ,EAAGE,iBAAiB,IAAIF,QAAU;IAC1CgB,cAAc,EAAGZ,YAAc;IAC/Ba,SAAS,EAAG,IAAAC,aAAI,EAAE,0BAA0B,EAAE;MAC7C,4BAA4B,EAAEf;IAC/B,CAAE,CAAG;IACLgB,MAAM,EAAG,KAAO;IAAA,GACXT,KAAK;IAAAU,QAAA,eAEV,IAAAtB,WAAA,CAAAgB,GAAA,EAACjB,eAAA,CAAAkB,OAAc;MACdd,oBAAoB,EAAGA,oBAAsB;MAC7CD,QAAQ,EAAGA;IAAU,CACrB;EAAC,CACW,CAAC;AAEjB","ignoreList":[]}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = ZoomOutToolbar;
|
|
8
|
-
var _clsx = _interopRequireDefault(require("clsx"));
|
|
9
|
-
var _icons = require("@wordpress/icons");
|
|
10
|
-
var _components = require("@wordpress/components");
|
|
11
|
-
var _data = require("@wordpress/data");
|
|
12
|
-
var _blocks = require("@wordpress/blocks");
|
|
13
|
-
var _i18n = require("@wordpress/i18n");
|
|
14
|
-
var _store = require("../../store");
|
|
15
|
-
var _blockDraggable = _interopRequireDefault(require("../block-draggable"));
|
|
16
|
-
var _blockMover = _interopRequireDefault(require("../block-mover"));
|
|
17
|
-
var _shuffle = _interopRequireDefault(require("../block-toolbar/shuffle"));
|
|
18
|
-
var _navigableToolbar = _interopRequireDefault(require("../navigable-toolbar"));
|
|
19
|
-
var _lockUnlock = require("../../lock-unlock");
|
|
20
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
|
-
/**
|
|
22
|
-
* External dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* WordPress dependencies
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Internal dependencies
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
function ZoomOutToolbar({
|
|
34
|
-
clientId,
|
|
35
|
-
__unstableContentRef
|
|
36
|
-
}) {
|
|
37
|
-
const selected = (0, _data.useSelect)(select => {
|
|
38
|
-
const {
|
|
39
|
-
getBlock,
|
|
40
|
-
hasBlockMovingClientId,
|
|
41
|
-
getNextBlockClientId,
|
|
42
|
-
getPreviousBlockClientId,
|
|
43
|
-
canRemoveBlock,
|
|
44
|
-
canMoveBlock,
|
|
45
|
-
getSettings
|
|
46
|
-
} = select(_store.store);
|
|
47
|
-
const {
|
|
48
|
-
__experimentalSetIsInserterOpened: setIsInserterOpened
|
|
49
|
-
} = getSettings();
|
|
50
|
-
const {
|
|
51
|
-
getBlockType
|
|
52
|
-
} = select(_blocks.store);
|
|
53
|
-
const {
|
|
54
|
-
name
|
|
55
|
-
} = getBlock(clientId);
|
|
56
|
-
const blockType = getBlockType(name);
|
|
57
|
-
const isBlockTemplatePart = blockType?.name === 'core/template-part';
|
|
58
|
-
let isNextBlockTemplatePart = false;
|
|
59
|
-
const nextClientId = getNextBlockClientId();
|
|
60
|
-
if (nextClientId) {
|
|
61
|
-
const {
|
|
62
|
-
name: nextName
|
|
63
|
-
} = getBlock(nextClientId);
|
|
64
|
-
const nextBlockType = getBlockType(nextName);
|
|
65
|
-
isNextBlockTemplatePart = nextBlockType?.name === 'core/template-part';
|
|
66
|
-
}
|
|
67
|
-
let isPrevBlockTemplatePart = false;
|
|
68
|
-
const prevClientId = getPreviousBlockClientId();
|
|
69
|
-
if (prevClientId) {
|
|
70
|
-
const {
|
|
71
|
-
name: prevName
|
|
72
|
-
} = getBlock(prevClientId);
|
|
73
|
-
const prevBlockType = getBlockType(prevName);
|
|
74
|
-
isPrevBlockTemplatePart = prevBlockType?.name === 'core/template-part';
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
blockMovingMode: hasBlockMovingClientId(),
|
|
78
|
-
isBlockTemplatePart,
|
|
79
|
-
isNextBlockTemplatePart,
|
|
80
|
-
isPrevBlockTemplatePart,
|
|
81
|
-
canRemove: canRemoveBlock(clientId),
|
|
82
|
-
canMove: canMoveBlock(clientId),
|
|
83
|
-
setIsInserterOpened
|
|
84
|
-
};
|
|
85
|
-
}, [clientId]);
|
|
86
|
-
const {
|
|
87
|
-
blockMovingMode,
|
|
88
|
-
isBlockTemplatePart,
|
|
89
|
-
isNextBlockTemplatePart,
|
|
90
|
-
isPrevBlockTemplatePart,
|
|
91
|
-
canRemove,
|
|
92
|
-
canMove,
|
|
93
|
-
setIsInserterOpened
|
|
94
|
-
} = selected;
|
|
95
|
-
const {
|
|
96
|
-
removeBlock,
|
|
97
|
-
__unstableSetEditorMode,
|
|
98
|
-
resetZoomLevel
|
|
99
|
-
} = (0, _lockUnlock.unlock)((0, _data.useDispatch)(_store.store));
|
|
100
|
-
const classNames = (0, _clsx.default)('zoom-out-toolbar', {
|
|
101
|
-
'is-block-moving-mode': !!blockMovingMode
|
|
102
|
-
});
|
|
103
|
-
const showBlockDraggable = canMove && !isBlockTemplatePart;
|
|
104
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_navigableToolbar.default, {
|
|
105
|
-
className: classNames
|
|
106
|
-
/* translators: accessibility text for the block toolbar */,
|
|
107
|
-
"aria-label": (0, _i18n.__)('Block tools')
|
|
108
|
-
// The variant is applied as "toolbar" when undefined, which is the black border style of the dropdown from the toolbar popover.
|
|
109
|
-
,
|
|
110
|
-
variant: "unstyled",
|
|
111
|
-
orientation: "vertical",
|
|
112
|
-
children: [showBlockDraggable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockDraggable.default, {
|
|
113
|
-
clientIds: [clientId],
|
|
114
|
-
children: draggableProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
115
|
-
icon: _icons.dragHandle,
|
|
116
|
-
className: "block-selection-button_drag-handle zoom-out-toolbar-button",
|
|
117
|
-
label: (0, _i18n.__)('Drag'),
|
|
118
|
-
iconSize: 24,
|
|
119
|
-
size: "compact"
|
|
120
|
-
// Should not be able to tab to drag handle as this
|
|
121
|
-
// button can only be used with a pointer device.
|
|
122
|
-
,
|
|
123
|
-
tabIndex: "-1",
|
|
124
|
-
...draggableProps
|
|
125
|
-
})
|
|
126
|
-
}), !isBlockTemplatePart && /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockMover.default, {
|
|
127
|
-
clientIds: [clientId],
|
|
128
|
-
hideDragHandle: true,
|
|
129
|
-
isBlockMoverUpButtonDisabled: isPrevBlockTemplatePart,
|
|
130
|
-
isBlockMoverDownButtonDisabled: isNextBlockTemplatePart,
|
|
131
|
-
iconSize: 24,
|
|
132
|
-
size: "compact"
|
|
133
|
-
}), canMove && canRemove && /*#__PURE__*/(0, _jsxRuntime.jsx)(_shuffle.default, {
|
|
134
|
-
clientId: clientId,
|
|
135
|
-
as: _components.ToolbarButton
|
|
136
|
-
}), !isBlockTemplatePart && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
|
|
137
|
-
className: "zoom-out-toolbar-button",
|
|
138
|
-
icon: _icons.edit,
|
|
139
|
-
label: (0, _i18n.__)('Edit'),
|
|
140
|
-
onClick: () => {
|
|
141
|
-
// Setting may be undefined.
|
|
142
|
-
if (typeof setIsInserterOpened === 'function') {
|
|
143
|
-
setIsInserterOpened(false);
|
|
144
|
-
}
|
|
145
|
-
__unstableSetEditorMode('edit');
|
|
146
|
-
resetZoomLevel();
|
|
147
|
-
__unstableContentRef.current?.focus();
|
|
148
|
-
}
|
|
149
|
-
}), canRemove && !isBlockTemplatePart && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
|
|
150
|
-
className: "zoom-out-toolbar-button",
|
|
151
|
-
icon: _icons.trash,
|
|
152
|
-
label: (0, _i18n.__)('Delete'),
|
|
153
|
-
onClick: () => {
|
|
154
|
-
removeBlock(clientId);
|
|
155
|
-
}
|
|
156
|
-
})]
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
//# sourceMappingURL=zoom-out-toolbar.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_icons","_components","_data","_blocks","_i18n","_store","_blockDraggable","_blockMover","_shuffle","_navigableToolbar","_lockUnlock","_jsxRuntime","ZoomOutToolbar","clientId","__unstableContentRef","selected","useSelect","select","getBlock","hasBlockMovingClientId","getNextBlockClientId","getPreviousBlockClientId","canRemoveBlock","canMoveBlock","getSettings","blockEditorStore","__experimentalSetIsInserterOpened","setIsInserterOpened","getBlockType","blocksStore","name","blockType","isBlockTemplatePart","isNextBlockTemplatePart","nextClientId","nextName","nextBlockType","isPrevBlockTemplatePart","prevClientId","prevName","prevBlockType","blockMovingMode","canRemove","canMove","removeBlock","__unstableSetEditorMode","resetZoomLevel","unlock","useDispatch","classNames","clsx","showBlockDraggable","jsxs","default","className","__","variant","orientation","children","jsx","clientIds","draggableProps","Button","icon","dragHandle","label","iconSize","size","tabIndex","hideDragHandle","isBlockMoverUpButtonDisabled","isBlockMoverDownButtonDisabled","as","ToolbarButton","edit","onClick","current","focus","trash"],"sources":["@wordpress/block-editor/src/components/block-tools/zoom-out-toolbar.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { dragHandle, trash, edit } from '@wordpress/icons';\nimport { Button, ToolbarButton } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport BlockDraggable from '../block-draggable';\nimport BlockMover from '../block-mover';\nimport Shuffle from '../block-toolbar/shuffle';\nimport NavigableToolbar from '../navigable-toolbar';\nimport { unlock } from '../../lock-unlock';\n\nexport default function ZoomOutToolbar( { clientId, __unstableContentRef } ) {\n\tconst selected = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlock,\n\t\t\t\thasBlockMovingClientId,\n\t\t\t\tgetNextBlockClientId,\n\t\t\t\tgetPreviousBlockClientId,\n\t\t\t\tcanRemoveBlock,\n\t\t\t\tcanMoveBlock,\n\t\t\t\tgetSettings,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\tconst { __experimentalSetIsInserterOpened: setIsInserterOpened } =\n\t\t\t\tgetSettings();\n\n\t\t\tconst { getBlockType } = select( blocksStore );\n\t\t\tconst { name } = getBlock( clientId );\n\t\t\tconst blockType = getBlockType( name );\n\t\t\tconst isBlockTemplatePart =\n\t\t\t\tblockType?.name === 'core/template-part';\n\n\t\t\tlet isNextBlockTemplatePart = false;\n\t\t\tconst nextClientId = getNextBlockClientId();\n\t\t\tif ( nextClientId ) {\n\t\t\t\tconst { name: nextName } = getBlock( nextClientId );\n\t\t\t\tconst nextBlockType = getBlockType( nextName );\n\t\t\t\tisNextBlockTemplatePart =\n\t\t\t\t\tnextBlockType?.name === 'core/template-part';\n\t\t\t}\n\n\t\t\tlet isPrevBlockTemplatePart = false;\n\t\t\tconst prevClientId = getPreviousBlockClientId();\n\t\t\tif ( prevClientId ) {\n\t\t\t\tconst { name: prevName } = getBlock( prevClientId );\n\t\t\t\tconst prevBlockType = getBlockType( prevName );\n\t\t\t\tisPrevBlockTemplatePart =\n\t\t\t\t\tprevBlockType?.name === 'core/template-part';\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tblockMovingMode: hasBlockMovingClientId(),\n\t\t\t\tisBlockTemplatePart,\n\t\t\t\tisNextBlockTemplatePart,\n\t\t\t\tisPrevBlockTemplatePart,\n\t\t\t\tcanRemove: canRemoveBlock( clientId ),\n\t\t\t\tcanMove: canMoveBlock( clientId ),\n\t\t\t\tsetIsInserterOpened,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst {\n\t\tblockMovingMode,\n\t\tisBlockTemplatePart,\n\t\tisNextBlockTemplatePart,\n\t\tisPrevBlockTemplatePart,\n\t\tcanRemove,\n\t\tcanMove,\n\t\tsetIsInserterOpened,\n\t} = selected;\n\n\tconst { removeBlock, __unstableSetEditorMode, resetZoomLevel } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\n\tconst classNames = clsx( 'zoom-out-toolbar', {\n\t\t'is-block-moving-mode': !! blockMovingMode,\n\t} );\n\n\tconst showBlockDraggable = canMove && ! isBlockTemplatePart;\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tclassName={ classNames }\n\t\t\t/* translators: accessibility text for the block toolbar */\n\t\t\taria-label={ __( 'Block tools' ) }\n\t\t\t// The variant is applied as \"toolbar\" when undefined, which is the black border style of the dropdown from the toolbar popover.\n\t\t\tvariant=\"unstyled\"\n\t\t\torientation=\"vertical\"\n\t\t>\n\t\t\t{ showBlockDraggable && (\n\t\t\t\t<BlockDraggable clientIds={ [ clientId ] }>\n\t\t\t\t\t{ ( draggableProps ) => (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\ticon={ dragHandle }\n\t\t\t\t\t\t\tclassName=\"block-selection-button_drag-handle zoom-out-toolbar-button\"\n\t\t\t\t\t\t\tlabel={ __( 'Drag' ) }\n\t\t\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\t\t// Should not be able to tab to drag handle as this\n\t\t\t\t\t\t\t// button can only be used with a pointer device.\n\t\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\t\t{ ...draggableProps }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</BlockDraggable>\n\t\t\t) }\n\t\t\t{ ! isBlockTemplatePart && (\n\t\t\t\t<BlockMover\n\t\t\t\t\tclientIds={ [ clientId ] }\n\t\t\t\t\thideDragHandle\n\t\t\t\t\tisBlockMoverUpButtonDisabled={ isPrevBlockTemplatePart }\n\t\t\t\t\tisBlockMoverDownButtonDisabled={ isNextBlockTemplatePart }\n\t\t\t\t\ticonSize={ 24 }\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ canMove && canRemove && (\n\t\t\t\t<Shuffle clientId={ clientId } as={ ToolbarButton } />\n\t\t\t) }\n\n\t\t\t{ ! isBlockTemplatePart && (\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tclassName=\"zoom-out-toolbar-button\"\n\t\t\t\t\ticon={ edit }\n\t\t\t\t\tlabel={ __( 'Edit' ) }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t// Setting may be undefined.\n\t\t\t\t\t\tif ( typeof setIsInserterOpened === 'function' ) {\n\t\t\t\t\t\t\tsetIsInserterOpened( false );\n\t\t\t\t\t\t}\n\t\t\t\t\t\t__unstableSetEditorMode( 'edit' );\n\t\t\t\t\t\tresetZoomLevel();\n\t\t\t\t\t\t__unstableContentRef.current?.focus();\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\n\t\t\t{ canRemove && ! isBlockTemplatePart && (\n\t\t\t\t<ToolbarButton\n\t\t\t\t\tclassName=\"zoom-out-toolbar-button\"\n\t\t\t\t\ticon={ trash }\n\t\t\t\t\tlabel={ __( 'Delete' ) }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tremoveBlock( clientId );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</NavigableToolbar>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAKA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,WAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,QAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,iBAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,WAAA,GAAAX,OAAA;AAA2C,IAAAY,WAAA,GAAAZ,OAAA;AAtB3C;AACA;AACA;;AAGA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