@wordpress/block-editor 8.0.12 → 8.0.16
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/build/components/block-preview/auto.js +20 -4
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-tools/index.js +9 -0
- package/build/components/block-tools/index.js.map +1 -1
- package/build/components/font-appearance-control/index.js +11 -11
- package/build/components/font-appearance-control/index.js.map +1 -1
- package/build/components/gradients/use-gradient.js +4 -4
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/iframe/index.js +2 -4
- package/build/components/iframe/index.js.map +1 -1
- package/build/hooks/color.js +6 -5
- package/build/hooks/color.js.map +1 -1
- package/build/hooks/layout.js +2 -1
- package/build/hooks/layout.js.map +1 -1
- package/build/hooks/style.js +2 -1
- package/build/hooks/style.js.map +1 -1
- package/build/layouts/flex.js +6 -2
- package/build/layouts/flex.js.map +1 -1
- package/build/layouts/flow.js +10 -6
- package/build/layouts/flow.js.map +1 -1
- package/build/store/selectors.js +25 -7
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-preview/auto.js +21 -4
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-tools/index.js +9 -0
- package/build-module/components/block-tools/index.js.map +1 -1
- package/build-module/components/font-appearance-control/index.js +12 -12
- package/build-module/components/font-appearance-control/index.js.map +1 -1
- package/build-module/components/gradients/use-gradient.js +4 -3
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/iframe/index.js +2 -4
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/hooks/color.js +6 -5
- package/build-module/hooks/color.js.map +1 -1
- package/build-module/hooks/layout.js +2 -1
- package/build-module/hooks/layout.js.map +1 -1
- package/build-module/hooks/style.js +2 -1
- package/build-module/hooks/style.js.map +1 -1
- package/build-module/layouts/flex.js +6 -2
- package/build-module/layouts/flex.js.map +1 -1
- package/build-module/layouts/flow.js +10 -6
- package/build-module/layouts/flow.js.map +1 -1
- package/build-module/store/selectors.js +24 -7
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +4 -4
- package/src/components/block-preview/auto.js +26 -1
- package/src/components/block-tools/index.js +11 -0
- package/src/components/font-appearance-control/index.js +12 -12
- package/src/components/gradients/use-gradient.js +7 -7
- package/src/components/iframe/index.js +3 -7
- package/src/hooks/color.js +13 -14
- package/src/hooks/layout.js +1 -0
- package/src/hooks/style.js +2 -1
- package/src/hooks/test/style.js +0 -2
- package/src/layouts/flex.js +4 -6
- package/src/layouts/flow.js +8 -6
- package/src/store/selectors.js +37 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.16",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@wordpress/blob": "^3.2.2",
|
|
39
39
|
"@wordpress/block-serialization-default-parser": "^4.2.3",
|
|
40
40
|
"@wordpress/blocks": "^11.1.5",
|
|
41
|
-
"@wordpress/components": "^19.
|
|
41
|
+
"@wordpress/components": "^19.2.2",
|
|
42
42
|
"@wordpress/compose": "^5.0.7",
|
|
43
43
|
"@wordpress/data": "^6.1.5",
|
|
44
44
|
"@wordpress/deprecated": "^3.2.3",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@wordpress/keyboard-shortcuts": "^3.0.7",
|
|
53
53
|
"@wordpress/keycodes": "^3.2.4",
|
|
54
54
|
"@wordpress/notices": "^3.2.8",
|
|
55
|
-
"@wordpress/rich-text": "^5.0.
|
|
55
|
+
"@wordpress/rich-text": "^5.0.8",
|
|
56
56
|
"@wordpress/shortcode": "^3.2.3",
|
|
57
57
|
"@wordpress/token-list": "^2.2.2",
|
|
58
58
|
"@wordpress/url": "^3.3.1",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "cac1a1f3c854fc282d67b91a74936c3fe42d7d0a"
|
|
79
79
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Disabled } from '@wordpress/components';
|
|
5
5
|
import { useResizeObserver, pure, useRefEffect } from '@wordpress/compose';
|
|
6
6
|
import { useSelect } from '@wordpress/data';
|
|
7
|
+
import { useMemo } from '@wordpress/element';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
@@ -16,6 +17,8 @@ import { store } from '../../store';
|
|
|
16
17
|
// This is used to avoid rendering the block list if the sizes change.
|
|
17
18
|
let MemoizedBlockList;
|
|
18
19
|
|
|
20
|
+
const MAX_HEIGHT = 2000;
|
|
21
|
+
|
|
19
22
|
function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
|
|
20
23
|
const [
|
|
21
24
|
containerResizeListener,
|
|
@@ -29,6 +32,21 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
|
|
|
29
32
|
return select( store ).getSettings().styles;
|
|
30
33
|
}, [] );
|
|
31
34
|
|
|
35
|
+
// Avoid scrollbars for pattern previews.
|
|
36
|
+
const editorStyles = useMemo( () => {
|
|
37
|
+
if ( styles ) {
|
|
38
|
+
return [
|
|
39
|
+
...styles,
|
|
40
|
+
{
|
|
41
|
+
css: 'body{height:auto;overflow:hidden;}',
|
|
42
|
+
__unstableType: 'presets',
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return styles;
|
|
48
|
+
}, [ styles ] );
|
|
49
|
+
|
|
32
50
|
// Initialize on render instead of module top level, to avoid circular dependency issues.
|
|
33
51
|
MemoizedBlockList = MemoizedBlockList || pure( BlockList );
|
|
34
52
|
|
|
@@ -42,10 +60,14 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
|
|
|
42
60
|
style={ {
|
|
43
61
|
transform: `scale(${ scale })`,
|
|
44
62
|
height: contentHeight * scale,
|
|
63
|
+
maxHeight:
|
|
64
|
+
contentHeight > MAX_HEIGHT
|
|
65
|
+
? MAX_HEIGHT * scale
|
|
66
|
+
: undefined,
|
|
45
67
|
} }
|
|
46
68
|
>
|
|
47
69
|
<Iframe
|
|
48
|
-
head={ <EditorStyles styles={
|
|
70
|
+
head={ <EditorStyles styles={ editorStyles } /> }
|
|
49
71
|
contentRef={ useRefEffect( ( bodyElement ) => {
|
|
50
72
|
const {
|
|
51
73
|
ownerDocument: { documentElement },
|
|
@@ -65,6 +87,9 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
|
|
|
65
87
|
width: viewportWidth,
|
|
66
88
|
height: contentHeight,
|
|
67
89
|
pointerEvents: 'none',
|
|
90
|
+
// This is a catch-all max-height for patterns.
|
|
91
|
+
// See: https://github.com/WordPress/gutenberg/pull/38175.
|
|
92
|
+
maxHeight: MAX_HEIGHT,
|
|
68
93
|
} }
|
|
69
94
|
>
|
|
70
95
|
{ contentResizeListener }
|
|
@@ -95,6 +95,17 @@ export default function BlockTools( {
|
|
|
95
95
|
} else if (
|
|
96
96
|
isMatch( 'core/block-editor/delete-multi-selection', event )
|
|
97
97
|
) {
|
|
98
|
+
/**
|
|
99
|
+
* Check if the target element is a text area, input or
|
|
100
|
+
* event.defaultPrevented and return early. In all these
|
|
101
|
+
* cases backspace could be handled elsewhere.
|
|
102
|
+
*/
|
|
103
|
+
if (
|
|
104
|
+
[ 'INPUT', 'TEXTAREA' ].includes( event.target.nodeName ) ||
|
|
105
|
+
event.defaultPrevented
|
|
106
|
+
) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
98
109
|
const clientIds = getSelectedBlockClientIds();
|
|
99
110
|
if ( clientIds.length > 1 ) {
|
|
100
111
|
event.preventDefault();
|
|
@@ -3,54 +3,54 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { CustomSelectControl } from '@wordpress/components';
|
|
5
5
|
import { useMemo } from '@wordpress/element';
|
|
6
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
+
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
7
7
|
|
|
8
8
|
const FONT_STYLES = [
|
|
9
9
|
{
|
|
10
|
-
name:
|
|
10
|
+
name: _x( 'Regular', 'font style' ),
|
|
11
11
|
value: 'normal',
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
|
-
name:
|
|
14
|
+
name: _x( 'Italic', 'font style' ),
|
|
15
15
|
value: 'italic',
|
|
16
16
|
},
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
const FONT_WEIGHTS = [
|
|
20
20
|
{
|
|
21
|
-
name:
|
|
21
|
+
name: _x( 'Thin', 'font weight' ),
|
|
22
22
|
value: '100',
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
name:
|
|
25
|
+
name: _x( 'Extra Light', 'font weight' ),
|
|
26
26
|
value: '200',
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
name:
|
|
29
|
+
name: _x( 'Light', 'font weight' ),
|
|
30
30
|
value: '300',
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
name:
|
|
33
|
+
name: _x( 'Regular', 'font weight' ),
|
|
34
34
|
value: '400',
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
name:
|
|
37
|
+
name: _x( 'Medium', 'font weight' ),
|
|
38
38
|
value: '500',
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
name:
|
|
41
|
+
name: _x( 'Semi Bold', 'font weight' ),
|
|
42
42
|
value: '600',
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
name:
|
|
45
|
+
name: _x( 'Bold', 'font weight' ),
|
|
46
46
|
value: '700',
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
|
-
name:
|
|
49
|
+
name: _x( 'Extra Bold', 'font weight' ),
|
|
50
50
|
value: '800',
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
|
-
name:
|
|
53
|
+
name: _x( 'Black', 'font weight' ),
|
|
54
54
|
value: '900',
|
|
55
55
|
},
|
|
56
56
|
];
|
|
@@ -59,22 +59,22 @@ export function getGradientSlugByValue( gradients, value ) {
|
|
|
59
59
|
return gradient && gradient.slug;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const EMPTY_OBJECT = {};
|
|
63
|
-
|
|
64
62
|
export function __experimentalUseGradient( {
|
|
65
63
|
gradientAttribute = 'gradient',
|
|
66
64
|
customGradientAttribute = 'customGradient',
|
|
67
65
|
} = {} ) {
|
|
68
66
|
const { clientId } = useBlockEditContext();
|
|
69
67
|
|
|
70
|
-
const
|
|
68
|
+
const userGradientPalette = useSetting( 'color.gradients.custom' );
|
|
69
|
+
const themeGradientPalette = useSetting( 'color.gradients.theme' );
|
|
70
|
+
const defaultGradientPalette = useSetting( 'color.gradients.default' );
|
|
71
71
|
const allGradients = useMemo(
|
|
72
72
|
() => [
|
|
73
|
-
...(
|
|
74
|
-
...(
|
|
75
|
-
...(
|
|
73
|
+
...( userGradientPalette || [] ),
|
|
74
|
+
...( themeGradientPalette || [] ),
|
|
75
|
+
...( defaultGradientPalette || [] ),
|
|
76
76
|
],
|
|
77
|
-
[
|
|
77
|
+
[ userGradientPalette, themeGradientPalette, defaultGradientPalette ]
|
|
78
78
|
);
|
|
79
79
|
const { gradient, customGradient } = useSelect(
|
|
80
80
|
( select ) => {
|
|
@@ -75,13 +75,9 @@ function styleSheetsCompat( doc ) {
|
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
if ( isMatch && ! doc.getElementById( ownerNode.id ) ) {
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
For blocks, use the block API's style (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#style) or editorStyle (https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#editor-style).
|
|
82
|
-
For themes, use add_editor_style (https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#editor-styles).`,
|
|
83
|
-
ownerNode.outerHTML
|
|
84
|
-
);
|
|
78
|
+
// Display warning once we have a way to add style dependencies to the editor.
|
|
79
|
+
// See: https://github.com/WordPress/gutenberg/pull/37466.
|
|
80
|
+
|
|
85
81
|
doc.head.appendChild( ownerNode.cloneNode( true ) );
|
|
86
82
|
|
|
87
83
|
// Add inline styles belonging to the stylesheet.
|
package/src/hooks/color.js
CHANGED
|
@@ -32,8 +32,6 @@ import useSetting from '../components/use-setting';
|
|
|
32
32
|
|
|
33
33
|
export const COLOR_SUPPORT_KEY = 'color';
|
|
34
34
|
|
|
35
|
-
const EMPTY_OBJECT = {};
|
|
36
|
-
|
|
37
35
|
const hasColorSupport = ( blockType ) => {
|
|
38
36
|
const colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );
|
|
39
37
|
return (
|
|
@@ -232,7 +230,17 @@ export function ColorEdit( props ) {
|
|
|
232
230
|
],
|
|
233
231
|
[ userPalette, themePalette, defaultPalette ]
|
|
234
232
|
);
|
|
235
|
-
const
|
|
233
|
+
const userGradientPalette = useSetting( 'color.gradients.custom' );
|
|
234
|
+
const themeGradientPalette = useSetting( 'color.gradients.theme' );
|
|
235
|
+
const defaultGradientPalette = useSetting( 'color.gradients.default' );
|
|
236
|
+
const allGradients = useMemo(
|
|
237
|
+
() => [
|
|
238
|
+
...( userGradientPalette || [] ),
|
|
239
|
+
...( themeGradientPalette || [] ),
|
|
240
|
+
...( defaultGradientPalette || [] ),
|
|
241
|
+
],
|
|
242
|
+
[ userGradientPalette, themeGradientPalette, defaultGradientPalette ]
|
|
243
|
+
);
|
|
236
244
|
const areCustomSolidsEnabled = useSetting( 'color.custom' );
|
|
237
245
|
const areCustomGradientsEnabled = useSetting( 'color.customGradient' );
|
|
238
246
|
const isBackgroundEnabled = useSetting( 'color.background' );
|
|
@@ -244,17 +252,8 @@ export function ColorEdit( props ) {
|
|
|
244
252
|
|
|
245
253
|
const gradientsEnabled =
|
|
246
254
|
areCustomGradientsEnabled ||
|
|
247
|
-
!
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const allGradients = useMemo(
|
|
251
|
-
() => [
|
|
252
|
-
...( gradientsPerOrigin?.custom || [] ),
|
|
253
|
-
...( gradientsPerOrigin?.theme || [] ),
|
|
254
|
-
...( gradientsPerOrigin?.default || [] ),
|
|
255
|
-
],
|
|
256
|
-
[ gradientsPerOrigin ]
|
|
257
|
-
);
|
|
255
|
+
! themeGradientPalette ||
|
|
256
|
+
themeGradientPalette?.length > 0;
|
|
258
257
|
|
|
259
258
|
// Shouldn't be needed but right now the ColorGradientsPanel
|
|
260
259
|
// can trigger both onChangeColor and onChangeBackground
|
package/src/hooks/layout.js
CHANGED
package/src/hooks/style.js
CHANGED
|
@@ -74,6 +74,7 @@ function compileStyleValue( uncompiledValue ) {
|
|
|
74
74
|
* @return {Object} Flattened CSS variables declaration.
|
|
75
75
|
*/
|
|
76
76
|
export function getInlineStyles( styles = {} ) {
|
|
77
|
+
const ignoredStyles = [ 'spacing.blockGap' ];
|
|
77
78
|
const output = {};
|
|
78
79
|
Object.keys( STYLE_PROPERTY ).forEach( ( propKey ) => {
|
|
79
80
|
const path = STYLE_PROPERTY[ propKey ].value;
|
|
@@ -93,7 +94,7 @@ export function getInlineStyles( styles = {} ) {
|
|
|
93
94
|
output[ name ] = compileStyleValue( value );
|
|
94
95
|
}
|
|
95
96
|
} );
|
|
96
|
-
} else {
|
|
97
|
+
} else if ( ! ignoredStyles.includes( path.join( '.' ) ) ) {
|
|
97
98
|
output[ propKey ] = compileStyleValue( get( styles, path ) );
|
|
98
99
|
}
|
|
99
100
|
}
|
package/src/hooks/test/style.js
CHANGED
|
@@ -30,7 +30,6 @@ describe( 'getInlineStyles', () => {
|
|
|
30
30
|
},
|
|
31
31
|
} )
|
|
32
32
|
).toEqual( {
|
|
33
|
-
'--wp--style--block-gap': '1em',
|
|
34
33
|
backgroundColor: 'black',
|
|
35
34
|
borderColor: '#21759b',
|
|
36
35
|
borderRadius: '10px',
|
|
@@ -104,7 +103,6 @@ describe( 'getInlineStyles', () => {
|
|
|
104
103
|
},
|
|
105
104
|
} )
|
|
106
105
|
).toEqual( {
|
|
107
|
-
'--wp--style--block-gap': '1em',
|
|
108
106
|
margin: '10px',
|
|
109
107
|
padding: '20px',
|
|
110
108
|
} );
|
package/src/layouts/flex.js
CHANGED
|
@@ -84,10 +84,12 @@ export default {
|
|
|
84
84
|
</BlockControls>
|
|
85
85
|
);
|
|
86
86
|
},
|
|
87
|
-
save: function FlexLayoutStyle( { selector, layout } ) {
|
|
87
|
+
save: function FlexLayoutStyle( { selector, layout, style } ) {
|
|
88
88
|
const { orientation = 'horizontal' } = layout;
|
|
89
89
|
const blockGapSupport = useSetting( 'spacing.blockGap' );
|
|
90
90
|
const hasBlockGapStylesSupport = blockGapSupport !== null;
|
|
91
|
+
const blockGapValue =
|
|
92
|
+
style?.spacing?.blockGap ?? 'var( --wp--style--block-gap, 0.5em )';
|
|
91
93
|
const justifyContent =
|
|
92
94
|
justifyContentMap[ layout.justifyContent ] ||
|
|
93
95
|
justifyContentMap.left;
|
|
@@ -110,11 +112,7 @@ export default {
|
|
|
110
112
|
<style>{ `
|
|
111
113
|
${ appendSelectors( selector ) } {
|
|
112
114
|
display: flex;
|
|
113
|
-
gap: ${
|
|
114
|
-
hasBlockGapStylesSupport
|
|
115
|
-
? 'var( --wp--style--block-gap, 0.5em )'
|
|
116
|
-
: '0.5em'
|
|
117
|
-
};
|
|
115
|
+
gap: ${ hasBlockGapStylesSupport ? blockGapValue : '0.5em' };
|
|
118
116
|
flex-wrap: ${ flexWrap };
|
|
119
117
|
${ orientation === 'horizontal' ? rowOrientation : columnOrientation }
|
|
120
118
|
}
|
package/src/layouts/flow.js
CHANGED
|
@@ -105,12 +105,14 @@ export default {
|
|
|
105
105
|
toolBarControls: function DefaultLayoutToolbarControls() {
|
|
106
106
|
return null;
|
|
107
107
|
},
|
|
108
|
-
save: function DefaultLayoutStyle( { selector, layout = {} } ) {
|
|
108
|
+
save: function DefaultLayoutStyle( { selector, layout = {}, style } ) {
|
|
109
109
|
const { contentSize, wideSize } = layout;
|
|
110
110
|
const blockGapSupport = useSetting( 'spacing.blockGap' );
|
|
111
111
|
const hasBlockGapStylesSupport = blockGapSupport !== null;
|
|
112
|
+
const blockGapValue =
|
|
113
|
+
style?.spacing?.blockGap ?? 'var( --wp--style--block-gap )';
|
|
112
114
|
|
|
113
|
-
let
|
|
115
|
+
let output =
|
|
114
116
|
!! contentSize || !! wideSize
|
|
115
117
|
? `
|
|
116
118
|
${ appendSelectors( selector, '> *' ) } {
|
|
@@ -129,7 +131,7 @@ export default {
|
|
|
129
131
|
`
|
|
130
132
|
: '';
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
output += `
|
|
133
135
|
${ appendSelectors( selector, '> [data-align="left"]' ) } {
|
|
134
136
|
float: left;
|
|
135
137
|
margin-right: 2em;
|
|
@@ -143,18 +145,18 @@ export default {
|
|
|
143
145
|
`;
|
|
144
146
|
|
|
145
147
|
if ( hasBlockGapStylesSupport ) {
|
|
146
|
-
|
|
148
|
+
output += `
|
|
147
149
|
${ appendSelectors( selector, '> *' ) } {
|
|
148
150
|
margin-top: 0;
|
|
149
151
|
margin-bottom: 0;
|
|
150
152
|
}
|
|
151
153
|
${ appendSelectors( selector, '> * + *' ) } {
|
|
152
|
-
margin-top:
|
|
154
|
+
margin-top: ${ blockGapValue };
|
|
153
155
|
}
|
|
154
156
|
`;
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
return <style>{
|
|
159
|
+
return <style>{ output }</style>;
|
|
158
160
|
},
|
|
159
161
|
getOrientation() {
|
|
160
162
|
return 'vertical';
|
package/src/store/selectors.js
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
parse,
|
|
31
31
|
} from '@wordpress/blocks';
|
|
32
32
|
import { Platform } from '@wordpress/element';
|
|
33
|
+
import { applyFilters } from '@wordpress/hooks';
|
|
33
34
|
import { symbol } from '@wordpress/icons';
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -826,6 +827,7 @@ export const isAncestorMultiSelected = createSelector(
|
|
|
826
827
|
state.selection.selectionEnd.clientId,
|
|
827
828
|
]
|
|
828
829
|
);
|
|
830
|
+
|
|
829
831
|
/**
|
|
830
832
|
* Returns the client ID of the block which begins the multi-selection set, or
|
|
831
833
|
* null if there is no multi-selection.
|
|
@@ -1259,15 +1261,43 @@ const canInsertBlockTypeUnmemoized = (
|
|
|
1259
1261
|
parentName
|
|
1260
1262
|
);
|
|
1261
1263
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1264
|
+
const canInsert =
|
|
1265
|
+
( hasParentAllowedBlock === null && hasBlockAllowedParent === null ) ||
|
|
1266
|
+
hasParentAllowedBlock === true ||
|
|
1267
|
+
hasBlockAllowedParent === true;
|
|
1268
|
+
|
|
1269
|
+
if ( ! canInsert ) {
|
|
1270
|
+
return canInsert;
|
|
1268
1271
|
}
|
|
1269
1272
|
|
|
1270
|
-
|
|
1273
|
+
/**
|
|
1274
|
+
* This filter is an ad-hoc solution to prevent adding template parts inside post content.
|
|
1275
|
+
* Conceptually, having a filter inside a selector is bad pattern so this code will be
|
|
1276
|
+
* replaced by a declarative API that doesn't the following drawbacks:
|
|
1277
|
+
*
|
|
1278
|
+
* Filters are not reactive: Upon switching between "template mode" and non "template mode",
|
|
1279
|
+
* the filter and selector won't necessarily be executed again. For now, it doesn't matter much
|
|
1280
|
+
* because you can't switch between the two modes while the inserter stays open.
|
|
1281
|
+
*
|
|
1282
|
+
* Filters are global: Once they're defined, they will affect all editor instances and all registries.
|
|
1283
|
+
* An ideal API would only affect specific editor instances.
|
|
1284
|
+
*/
|
|
1285
|
+
return applyFilters(
|
|
1286
|
+
'blockEditor.__unstableCanInsertBlockType',
|
|
1287
|
+
canInsert,
|
|
1288
|
+
blockType,
|
|
1289
|
+
rootClientId,
|
|
1290
|
+
{
|
|
1291
|
+
// Pass bound selectors of the current registry. If we're in a nested
|
|
1292
|
+
// context, the data will differ from the one selected from the root
|
|
1293
|
+
// registry.
|
|
1294
|
+
getBlock: getBlock.bind( null, state ),
|
|
1295
|
+
getBlockParentsByBlockName: getBlockParentsByBlockName.bind(
|
|
1296
|
+
null,
|
|
1297
|
+
state
|
|
1298
|
+
),
|
|
1299
|
+
}
|
|
1300
|
+
);
|
|
1271
1301
|
};
|
|
1272
1302
|
|
|
1273
1303
|
/**
|