@wordpress/block-editor 8.0.11 → 8.0.14
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-inspector/index.js +12 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/block.js +1 -1
- package/build/components/block-list/block.js.map +1 -1
- package/build/components/block-list/block.native.js +2 -3
- package/build/components/block-list/block.native.js.map +1 -1
- package/build/components/block-list/use-block-props/index.js +1 -3
- package/build/components/block-list/use-block-props/index.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +1 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
- package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build/components/block-mover/button.js +2 -2
- package/build/components/block-mover/button.js.map +1 -1
- package/build/components/block-mover/index.js +2 -2
- package/build/components/block-mover/index.js.map +1 -1
- package/build/components/block-mover/index.native.js +2 -2
- package/build/components/block-mover/index.native.js.map +1 -1
- package/build/components/block-preview/index.js +51 -0
- package/build/components/block-preview/index.js.map +1 -1
- package/build/components/block-tools/block-selection-button.js +3 -3
- package/build/components/block-tools/block-selection-button.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/gradients/use-gradient.js +4 -4
- package/build/components/gradients/use-gradient.js.map +1 -1
- package/build/components/index.js +8 -1
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/hooks/use-insertion-point.js +2 -2
- package/build/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build/components/inserter/index.js +2 -2
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/index.native.js +2 -2
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +1 -1
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/inspector-controls/block-support-tools-panel.js +50 -22
- package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/provider/use-block-sync.js +37 -10
- package/build/components/provider/use-block-sync.js.map +1 -1
- package/build/components/use-on-block-drop/index.js +1 -1
- package/build/components/use-on-block-drop/index.js.map +1 -1
- package/build/components/use-setting/index.js +7 -0
- package/build/components/use-setting/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 +9 -29
- 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/actions.js +3 -3
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +24 -1
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +27 -9
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-inspector/index.js +12 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/block.js +1 -1
- package/build-module/components/block-list/block.js.map +1 -1
- package/build-module/components/block-list/block.native.js +2 -3
- package/build-module/components/block-list/block.native.js.map +1 -1
- package/build-module/components/block-list/use-block-props/index.js +1 -3
- package/build-module/components/block-list/use-block-props/index.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +2 -2
- package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
- package/build-module/components/block-mover/button.js +2 -2
- package/build-module/components/block-mover/button.js.map +1 -1
- package/build-module/components/block-mover/index.js +2 -2
- package/build-module/components/block-mover/index.js.map +1 -1
- package/build-module/components/block-mover/index.native.js +2 -2
- package/build-module/components/block-mover/index.native.js.map +1 -1
- package/build-module/components/block-preview/index.js +46 -0
- package/build-module/components/block-preview/index.js.map +1 -1
- package/build-module/components/block-tools/block-selection-button.js +3 -3
- package/build-module/components/block-tools/block-selection-button.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/gradients/use-gradient.js +4 -3
- package/build-module/components/gradients/use-gradient.js.map +1 -1
- package/build-module/components/index.js +1 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/hooks/use-insertion-point.js +2 -2
- package/build-module/components/inserter/hooks/use-insertion-point.js.map +1 -1
- package/build-module/components/inserter/index.js +2 -2
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +2 -2
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +1 -1
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/inspector-controls/block-support-tools-panel.js +50 -22
- package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/provider/use-block-sync.js +41 -14
- package/build-module/components/provider/use-block-sync.js.map +1 -1
- package/build-module/components/use-on-block-drop/index.js +1 -1
- package/build-module/components/use-on-block-drop/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +7 -0
- package/build-module/components/use-setting/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 +9 -29
- 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/actions.js +3 -3
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +24 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +26 -9
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +14 -0
- package/build-style/style.css +14 -0
- package/package.json +9 -9
- package/src/components/block-inspector/index.js +17 -1
- package/src/components/block-list/block.js +1 -1
- package/src/components/block-list/block.native.js +2 -2
- package/src/components/block-list/use-block-props/index.js +1 -3
- package/src/components/block-list/use-in-between-inserter.js +1 -1
- package/src/components/block-mobile-toolbar/block-actions-menu.native.js +2 -5
- package/src/components/block-mover/button.js +2 -6
- package/src/components/block-mover/index.js +2 -5
- package/src/components/block-mover/index.native.js +2 -5
- package/src/components/block-preview/index.js +60 -0
- package/src/components/block-preview/style.scss +23 -0
- package/src/components/block-preview/test/index.js +114 -0
- package/src/components/block-tools/block-selection-button.js +3 -9
- package/src/components/block-tools/index.js +11 -0
- package/src/components/gradients/use-gradient.js +7 -7
- package/src/components/index.js +4 -1
- package/src/components/inserter/hooks/use-insertion-point.js +2 -9
- package/src/components/inserter/index.js +2 -2
- package/src/components/inserter/index.native.js +2 -5
- package/src/components/inserter/quick-inserter.js +1 -1
- package/src/components/inspector-controls/block-support-tools-panel.js +57 -21
- package/src/components/list-view/use-list-view-drop-zone.js +1 -1
- package/src/components/provider/use-block-sync.js +45 -11
- package/src/components/use-on-block-drop/index.js +1 -4
- package/src/components/use-setting/index.js +9 -0
- 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 +8 -31
- package/src/layouts/flow.js +8 -6
- package/src/store/actions.js +3 -4
- package/src/store/reducer.js +23 -1
- package/src/store/selectors.js +39 -9
- package/src/store/test/reducer.js +35 -0
- package/src/store/test/selectors.js +1 -1
|
@@ -1188,6 +1188,20 @@
|
|
|
1188
1188
|
display: none;
|
|
1189
1189
|
}
|
|
1190
1190
|
|
|
1191
|
+
.block-editor-block-preview__live-content * {
|
|
1192
|
+
pointer-events: none;
|
|
1193
|
+
}
|
|
1194
|
+
.block-editor-block-preview__live-content .block-list-appender {
|
|
1195
|
+
display: none;
|
|
1196
|
+
}
|
|
1197
|
+
.block-editor-block-preview__live-content .components-button:disabled {
|
|
1198
|
+
opacity: initial;
|
|
1199
|
+
}
|
|
1200
|
+
.block-editor-block-preview__live-content .components-placeholder,
|
|
1201
|
+
.block-editor-block-preview__live-content .block-editor-block-list__block[data-empty=true] {
|
|
1202
|
+
display: none;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1191
1205
|
.block-editor-block-settings-menu__popover .components-dropdown-menu__menu {
|
|
1192
1206
|
padding: 0;
|
|
1193
1207
|
}
|
package/build-style/style.css
CHANGED
|
@@ -1188,6 +1188,20 @@
|
|
|
1188
1188
|
display: none;
|
|
1189
1189
|
}
|
|
1190
1190
|
|
|
1191
|
+
.block-editor-block-preview__live-content * {
|
|
1192
|
+
pointer-events: none;
|
|
1193
|
+
}
|
|
1194
|
+
.block-editor-block-preview__live-content .block-list-appender {
|
|
1195
|
+
display: none;
|
|
1196
|
+
}
|
|
1197
|
+
.block-editor-block-preview__live-content .components-button:disabled {
|
|
1198
|
+
opacity: initial;
|
|
1199
|
+
}
|
|
1200
|
+
.block-editor-block-preview__live-content .components-placeholder,
|
|
1201
|
+
.block-editor-block-preview__live-content .block-editor-block-list__block[data-empty=true] {
|
|
1202
|
+
display: none;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1191
1205
|
.block-editor-block-settings-menu__popover .components-dropdown-menu__menu {
|
|
1192
1206
|
padding: 0;
|
|
1193
1207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.14",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"@wordpress/api-fetch": "^5.2.6",
|
|
38
38
|
"@wordpress/blob": "^3.2.2",
|
|
39
39
|
"@wordpress/block-serialization-default-parser": "^4.2.3",
|
|
40
|
-
"@wordpress/blocks": "^11.1.
|
|
41
|
-
"@wordpress/components": "^19.1
|
|
42
|
-
"@wordpress/compose": "^5.0.
|
|
43
|
-
"@wordpress/data": "^6.1.
|
|
40
|
+
"@wordpress/blocks": "^11.1.5",
|
|
41
|
+
"@wordpress/components": "^19.2.1",
|
|
42
|
+
"@wordpress/compose": "^5.0.7",
|
|
43
|
+
"@wordpress/data": "^6.1.5",
|
|
44
44
|
"@wordpress/deprecated": "^3.2.3",
|
|
45
45
|
"@wordpress/dom": "^3.2.7",
|
|
46
46
|
"@wordpress/element": "^4.0.4",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"@wordpress/i18n": "^4.2.4",
|
|
50
50
|
"@wordpress/icons": "^6.1.1",
|
|
51
51
|
"@wordpress/is-shallow-equal": "^4.2.1",
|
|
52
|
-
"@wordpress/keyboard-shortcuts": "^3.0.
|
|
52
|
+
"@wordpress/keyboard-shortcuts": "^3.0.7",
|
|
53
53
|
"@wordpress/keycodes": "^3.2.4",
|
|
54
|
-
"@wordpress/notices": "^3.2.
|
|
55
|
-
"@wordpress/rich-text": "^5.0.
|
|
54
|
+
"@wordpress/notices": "^3.2.8",
|
|
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": "04883dd8275ee52245a45c8899eb720b91055c50"
|
|
79
79
|
}
|
|
@@ -69,7 +69,19 @@ const BlockInspector = ( {
|
|
|
69
69
|
return (
|
|
70
70
|
<div className="block-editor-block-inspector">
|
|
71
71
|
<MultiSelectionInspector />
|
|
72
|
-
<InspectorControls.Slot
|
|
72
|
+
<InspectorControls.Slot />
|
|
73
|
+
<InspectorControls.Slot
|
|
74
|
+
__experimentalGroup="typography"
|
|
75
|
+
label={ __( 'Typography' ) }
|
|
76
|
+
/>
|
|
77
|
+
<InspectorControls.Slot
|
|
78
|
+
__experimentalGroup="dimensions"
|
|
79
|
+
label={ __( 'Dimensions' ) }
|
|
80
|
+
/>
|
|
81
|
+
<InspectorControls.Slot
|
|
82
|
+
__experimentalGroup="border"
|
|
83
|
+
label={ __( 'Border' ) }
|
|
84
|
+
/>
|
|
73
85
|
</div>
|
|
74
86
|
);
|
|
75
87
|
}
|
|
@@ -139,6 +151,10 @@ const BlockInspectorSingleBlock = ( {
|
|
|
139
151
|
bubblesVirtually={ bubblesVirtually }
|
|
140
152
|
label={ __( 'Dimensions' ) }
|
|
141
153
|
/>
|
|
154
|
+
<InspectorControls.Slot
|
|
155
|
+
__experimentalGroup="border"
|
|
156
|
+
label={ __( 'Border' ) }
|
|
157
|
+
/>
|
|
142
158
|
<div>
|
|
143
159
|
<AdvancedControls bubblesVirtually={ bubblesVirtually } />
|
|
144
160
|
</div>
|
|
@@ -259,7 +259,7 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, { select } ) => {
|
|
|
259
259
|
onInsertBlocksAfter( blocks ) {
|
|
260
260
|
const { clientId, rootClientId } = ownProps;
|
|
261
261
|
const { getBlockIndex } = select( blockEditorStore );
|
|
262
|
-
const index = getBlockIndex( clientId
|
|
262
|
+
const index = getBlockIndex( clientId );
|
|
263
263
|
insertBlocks( blocks, index + 1, rootClientId );
|
|
264
264
|
},
|
|
265
265
|
onMerge( forward ) {
|
|
@@ -302,7 +302,7 @@ function getWrapperProps( value, getWrapperPropsFunction ) {
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
export default compose( [
|
|
305
|
-
withSelect( ( select, { clientId
|
|
305
|
+
withSelect( ( select, { clientId } ) => {
|
|
306
306
|
const {
|
|
307
307
|
getBlockIndex,
|
|
308
308
|
getSettings,
|
|
@@ -314,7 +314,7 @@ export default compose( [
|
|
|
314
314
|
hasSelectedInnerBlock,
|
|
315
315
|
} = select( blockEditorStore );
|
|
316
316
|
|
|
317
|
-
const order = getBlockIndex( clientId
|
|
317
|
+
const order = getBlockIndex( clientId );
|
|
318
318
|
const isSelected = isBlockSelected( clientId );
|
|
319
319
|
const isInnerBlockSelected = hasSelectedInnerBlock( clientId );
|
|
320
320
|
const block = getBlock( clientId );
|
|
@@ -75,7 +75,6 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
|
|
|
75
75
|
} = useSelect(
|
|
76
76
|
( select ) => {
|
|
77
77
|
const {
|
|
78
|
-
getBlockRootClientId,
|
|
79
78
|
getBlockIndex,
|
|
80
79
|
getBlockMode,
|
|
81
80
|
getBlockName,
|
|
@@ -91,11 +90,10 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
|
|
|
91
90
|
isBlockMultiSelected( clientId ) ||
|
|
92
91
|
isAncestorMultiSelected( clientId );
|
|
93
92
|
const blockName = getBlockName( clientId );
|
|
94
|
-
const rootClientId = getBlockRootClientId( clientId );
|
|
95
93
|
const blockType = getBlockType( blockName );
|
|
96
94
|
|
|
97
95
|
return {
|
|
98
|
-
index: getBlockIndex( clientId
|
|
96
|
+
index: getBlockIndex( clientId ),
|
|
99
97
|
mode: getBlockMode( clientId ),
|
|
100
98
|
name: blockName,
|
|
101
99
|
blockApiVersion: blockType?.apiVersion || 1,
|
|
@@ -144,7 +144,7 @@ export function useInBetweenInserter() {
|
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
const index = getBlockIndex( clientId
|
|
147
|
+
const index = getBlockIndex( clientId );
|
|
148
148
|
|
|
149
149
|
// Don't show the in-between inserter before the first block in
|
|
150
150
|
// the list (preserves the original behaviour).
|
|
@@ -316,11 +316,8 @@ export default compose(
|
|
|
316
316
|
const rootClientId = getBlockRootClientId( firstClientId );
|
|
317
317
|
const blockOrder = getBlockOrder( rootClientId );
|
|
318
318
|
|
|
319
|
-
const firstIndex = getBlockIndex( firstClientId
|
|
320
|
-
const lastIndex = getBlockIndex(
|
|
321
|
-
last( normalizedClientIds ),
|
|
322
|
-
rootClientId
|
|
323
|
-
);
|
|
319
|
+
const firstIndex = getBlockIndex( firstClientId );
|
|
320
|
+
const lastIndex = getBlockIndex( last( normalizedClientIds ) );
|
|
324
321
|
|
|
325
322
|
const innerBlocks = getBlocksByClientId( clientIds );
|
|
326
323
|
|
|
@@ -84,13 +84,9 @@ const BlockMoverButton = forwardRef(
|
|
|
84
84
|
const normalizedClientIds = castArray( clientIds );
|
|
85
85
|
const firstClientId = first( normalizedClientIds );
|
|
86
86
|
const blockRootClientId = getBlockRootClientId( firstClientId );
|
|
87
|
-
const firstBlockIndex = getBlockIndex(
|
|
88
|
-
firstClientId,
|
|
89
|
-
blockRootClientId
|
|
90
|
-
);
|
|
87
|
+
const firstBlockIndex = getBlockIndex( firstClientId );
|
|
91
88
|
const lastBlockIndex = getBlockIndex(
|
|
92
|
-
last( normalizedClientIds )
|
|
93
|
-
blockRootClientId
|
|
89
|
+
last( normalizedClientIds )
|
|
94
90
|
);
|
|
95
91
|
const blockOrder = getBlockOrder( blockRootClientId );
|
|
96
92
|
const block = getBlock( firstClientId );
|
|
@@ -108,11 +108,8 @@ export default withSelect( ( select, { clientIds } ) => {
|
|
|
108
108
|
const firstClientId = first( normalizedClientIds );
|
|
109
109
|
const block = getBlock( firstClientId );
|
|
110
110
|
const rootClientId = getBlockRootClientId( first( normalizedClientIds ) );
|
|
111
|
-
const firstIndex = getBlockIndex( firstClientId
|
|
112
|
-
const lastIndex = getBlockIndex(
|
|
113
|
-
last( normalizedClientIds ),
|
|
114
|
-
rootClientId
|
|
115
|
-
);
|
|
111
|
+
const firstIndex = getBlockIndex( firstClientId );
|
|
112
|
+
const lastIndex = getBlockIndex( last( normalizedClientIds ) );
|
|
116
113
|
const blockOrder = getBlockOrder( rootClientId );
|
|
117
114
|
const isFirst = firstIndex === 0;
|
|
118
115
|
const isLast = lastIndex === blockOrder.length - 1;
|
|
@@ -138,11 +138,8 @@ export default compose(
|
|
|
138
138
|
const firstClientId = first( normalizedClientIds );
|
|
139
139
|
const rootClientId = getBlockRootClientId( firstClientId );
|
|
140
140
|
const blockOrder = getBlockOrder( rootClientId );
|
|
141
|
-
const firstIndex = getBlockIndex( firstClientId
|
|
142
|
-
const lastIndex = getBlockIndex(
|
|
143
|
-
last( normalizedClientIds ),
|
|
144
|
-
rootClientId
|
|
145
|
-
);
|
|
141
|
+
const firstIndex = getBlockIndex( firstClientId );
|
|
142
|
+
const lastIndex = getBlockIndex( last( normalizedClientIds ) );
|
|
146
143
|
|
|
147
144
|
return {
|
|
148
145
|
firstIndex,
|
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { castArray } from 'lodash';
|
|
5
|
+
import classnames from 'classnames';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* WordPress dependencies
|
|
8
9
|
*/
|
|
10
|
+
import {
|
|
11
|
+
__experimentalUseDisabled as useDisabled,
|
|
12
|
+
useMergeRefs,
|
|
13
|
+
} from '@wordpress/compose';
|
|
9
14
|
import { useSelect } from '@wordpress/data';
|
|
10
15
|
import { memo, useMemo } from '@wordpress/element';
|
|
11
16
|
|
|
@@ -16,6 +21,7 @@ import BlockEditorProvider from '../provider';
|
|
|
16
21
|
import LiveBlockPreview from './live';
|
|
17
22
|
import AutoHeightBlockPreview from './auto';
|
|
18
23
|
import { store as blockEditorStore } from '../../store';
|
|
24
|
+
import { BlockListItems } from '../block-list';
|
|
19
25
|
|
|
20
26
|
export function BlockPreview( {
|
|
21
27
|
blocks,
|
|
@@ -63,3 +69,57 @@ export function BlockPreview( {
|
|
|
63
69
|
* @return {WPComponent} The component to be rendered.
|
|
64
70
|
*/
|
|
65
71
|
export default memo( BlockPreview );
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* This hook is used to lightly mark an element as a block preview wrapper
|
|
75
|
+
* element. Call this hook and pass the returned props to the element to mark as
|
|
76
|
+
* a block preview wrapper, automatically rendering inner blocks as children. If
|
|
77
|
+
* you define a ref for the element, it is important to pass the ref to this
|
|
78
|
+
* hook, which the hook in turn will pass to the component through the props it
|
|
79
|
+
* returns. Optionally, you can also pass any other props through this hook, and
|
|
80
|
+
* they will be merged and returned.
|
|
81
|
+
*
|
|
82
|
+
* @param {Object} options Preview options.
|
|
83
|
+
* @param {WPBlock[]} options.blocks Block objects.
|
|
84
|
+
* @param {Object} options.props Optional. Props to pass to the element. Must contain
|
|
85
|
+
* the ref if one is defined.
|
|
86
|
+
* @param {Object} options.__experimentalLayout Layout settings to be used in the preview.
|
|
87
|
+
*
|
|
88
|
+
*/
|
|
89
|
+
export function useBlockPreview( {
|
|
90
|
+
blocks,
|
|
91
|
+
props = {},
|
|
92
|
+
__experimentalLayout,
|
|
93
|
+
} ) {
|
|
94
|
+
const originalSettings = useSelect(
|
|
95
|
+
( select ) => select( blockEditorStore ).getSettings(),
|
|
96
|
+
[]
|
|
97
|
+
);
|
|
98
|
+
const disabledRef = useDisabled();
|
|
99
|
+
const ref = useMergeRefs( [ props.ref, disabledRef ] );
|
|
100
|
+
const settings = useMemo(
|
|
101
|
+
() => ( { ...originalSettings, __experimentalBlockPatterns: [] } ),
|
|
102
|
+
[ originalSettings ]
|
|
103
|
+
);
|
|
104
|
+
const renderedBlocks = useMemo( () => castArray( blocks ), [ blocks ] );
|
|
105
|
+
|
|
106
|
+
const children = (
|
|
107
|
+
<BlockEditorProvider value={ renderedBlocks } settings={ settings }>
|
|
108
|
+
<BlockListItems
|
|
109
|
+
renderAppender={ false }
|
|
110
|
+
__experimentalLayout={ __experimentalLayout }
|
|
111
|
+
/>
|
|
112
|
+
</BlockEditorProvider>
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
...props,
|
|
117
|
+
ref,
|
|
118
|
+
className: classnames(
|
|
119
|
+
props.className,
|
|
120
|
+
'block-editor-block-preview__live-content',
|
|
121
|
+
'components-disabled'
|
|
122
|
+
),
|
|
123
|
+
children: blocks?.length ? children : null,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -41,3 +41,26 @@
|
|
|
41
41
|
.block-editor-block-preview__content-iframe .block-list-appender {
|
|
42
42
|
display: none;
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
.block-editor-block-preview__live-content {
|
|
46
|
+
* {
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Hide the block appender, as the block is not editable in this context.
|
|
51
|
+
.block-list-appender {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Revert button disable styles to ensure that button styles render as they will on the
|
|
56
|
+
// front end of the site. For example, this ensures that Social Links icons display correctly.
|
|
57
|
+
.components-button:disabled {
|
|
58
|
+
opacity: initial;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Hide placeholders.
|
|
62
|
+
.components-placeholder,
|
|
63
|
+
.block-editor-block-list__block[data-empty="true"] {
|
|
64
|
+
display: none;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
registerBlockType,
|
|
11
|
+
unregisterBlockType,
|
|
12
|
+
createBlock,
|
|
13
|
+
} from '@wordpress/blocks';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
import { useBlockPreview } from '../';
|
|
19
|
+
|
|
20
|
+
jest.mock( '@wordpress/dom', () => {
|
|
21
|
+
const focus = jest.requireActual( '../../../../../dom/src' ).focus;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
focus: {
|
|
25
|
+
...focus,
|
|
26
|
+
focusable: {
|
|
27
|
+
...focus.focusable,
|
|
28
|
+
find( context ) {
|
|
29
|
+
// In JSDOM, all elements have zero'd widths and height.
|
|
30
|
+
// This is a metric for focusable's `isVisible`, so find
|
|
31
|
+
// and apply an arbitrary non-zero width.
|
|
32
|
+
Array.from( context.querySelectorAll( '*' ) ).forEach(
|
|
33
|
+
( element ) => {
|
|
34
|
+
Object.defineProperties( element, {
|
|
35
|
+
offsetWidth: {
|
|
36
|
+
get: () => 1,
|
|
37
|
+
configurable: true,
|
|
38
|
+
},
|
|
39
|
+
} );
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return focus.focusable.find( ...arguments );
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
describe( 'useBlockPreview', () => {
|
|
51
|
+
beforeAll( () => {
|
|
52
|
+
registerBlockType( 'core/test-block', {
|
|
53
|
+
save: () => (
|
|
54
|
+
<div>
|
|
55
|
+
Test block save view
|
|
56
|
+
<button>Button</button>
|
|
57
|
+
</div>
|
|
58
|
+
),
|
|
59
|
+
edit: () => (
|
|
60
|
+
<div>
|
|
61
|
+
Test block edit view
|
|
62
|
+
<button>Button</button>
|
|
63
|
+
</div>
|
|
64
|
+
),
|
|
65
|
+
category: 'text',
|
|
66
|
+
title: 'test block',
|
|
67
|
+
} );
|
|
68
|
+
} );
|
|
69
|
+
|
|
70
|
+
afterAll( () => {
|
|
71
|
+
unregisterBlockType( 'core/test-block' );
|
|
72
|
+
} );
|
|
73
|
+
|
|
74
|
+
function BlockPreviewComponent( { blocks, className } ) {
|
|
75
|
+
const blockPreviewProps = useBlockPreview( {
|
|
76
|
+
blocks,
|
|
77
|
+
props: { className },
|
|
78
|
+
} );
|
|
79
|
+
return <div { ...blockPreviewProps } />;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
it( 'will render a block preview with minimal nesting', async () => {
|
|
83
|
+
const blocks = [];
|
|
84
|
+
blocks.push( createBlock( 'core/test-block' ) );
|
|
85
|
+
|
|
86
|
+
const { container } = render(
|
|
87
|
+
<BlockPreviewComponent
|
|
88
|
+
className="test-container-classname"
|
|
89
|
+
blocks={ blocks }
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// Test block and block contents are rendered.
|
|
94
|
+
const previewedBlock = screen.getByLabelText( 'Block: test block' );
|
|
95
|
+
const previewedBlockContents = screen.getByText(
|
|
96
|
+
'Test block edit view'
|
|
97
|
+
);
|
|
98
|
+
expect( previewedBlockContents ).toBeInTheDocument();
|
|
99
|
+
|
|
100
|
+
// Test elements within block contents are disabled.
|
|
101
|
+
await waitFor( () => {
|
|
102
|
+
const button = screen.getByText( 'Button' );
|
|
103
|
+
expect( button.hasAttribute( 'disabled' ) ).toBe( true );
|
|
104
|
+
} );
|
|
105
|
+
|
|
106
|
+
// Ensure the block preview class names are merged with the component's class name.
|
|
107
|
+
expect( container.firstChild.className ).toBe(
|
|
108
|
+
'test-container-classname block-editor-block-preview__live-content components-disabled'
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Ensure there is no nesting between the parent component and rendered blocks.
|
|
112
|
+
expect( container.firstChild.firstChild ).toBe( previewedBlock );
|
|
113
|
+
} );
|
|
114
|
+
} );
|
|
@@ -59,7 +59,7 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
|
|
|
59
59
|
hasBlockMovingClientId,
|
|
60
60
|
getBlockListSettings,
|
|
61
61
|
} = select( blockEditorStore );
|
|
62
|
-
const index = getBlockIndex( clientId
|
|
62
|
+
const index = getBlockIndex( clientId );
|
|
63
63
|
const { name, attributes } = getBlock( clientId );
|
|
64
64
|
const blockMovingMode = hasBlockMovingClientId();
|
|
65
65
|
return {
|
|
@@ -169,14 +169,8 @@ function BlockSelectionButton( { clientId, rootClientId, blockElement } ) {
|
|
|
169
169
|
if ( ( isEnter || isSpace ) && startingBlockClientId ) {
|
|
170
170
|
const sourceRoot = getBlockRootClientId( startingBlockClientId );
|
|
171
171
|
const destRoot = getBlockRootClientId( selectedBlockClientId );
|
|
172
|
-
const sourceBlockIndex = getBlockIndex(
|
|
173
|
-
|
|
174
|
-
sourceRoot
|
|
175
|
-
);
|
|
176
|
-
let destinationBlockIndex = getBlockIndex(
|
|
177
|
-
selectedBlockClientId,
|
|
178
|
-
destRoot
|
|
179
|
-
);
|
|
172
|
+
const sourceBlockIndex = getBlockIndex( startingBlockClientId );
|
|
173
|
+
let destinationBlockIndex = getBlockIndex( selectedBlockClientId );
|
|
180
174
|
if (
|
|
181
175
|
sourceBlockIndex < destinationBlockIndex &&
|
|
182
176
|
sourceRoot === destRoot
|
|
@@ -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();
|
|
@@ -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 ) => {
|
package/src/components/index.js
CHANGED
|
@@ -103,7 +103,10 @@ export { default as BlockList } from './block-list';
|
|
|
103
103
|
export { useBlockProps } from './block-list/use-block-props';
|
|
104
104
|
export { LayoutStyle as __experimentalLayoutStyle } from './block-list/layout';
|
|
105
105
|
export { default as BlockMover } from './block-mover';
|
|
106
|
-
export {
|
|
106
|
+
export {
|
|
107
|
+
default as BlockPreview,
|
|
108
|
+
useBlockPreview as __experimentalUseBlockPreview,
|
|
109
|
+
} from './block-preview';
|
|
107
110
|
export {
|
|
108
111
|
default as BlockSelectionClearer,
|
|
109
112
|
useBlockSelectionClearer as __unstableUseBlockSelectionClearer,
|
|
@@ -64,19 +64,12 @@ function useInsertionPoint( {
|
|
|
64
64
|
_destinationIndex = insertionIndex;
|
|
65
65
|
} else if ( clientId ) {
|
|
66
66
|
// Insert after a specific client ID.
|
|
67
|
-
_destinationIndex = getBlockIndex(
|
|
68
|
-
clientId,
|
|
69
|
-
_destinationRootClientId
|
|
70
|
-
);
|
|
67
|
+
_destinationIndex = getBlockIndex( clientId );
|
|
71
68
|
} else if ( ! isAppender && selectedBlockClientId ) {
|
|
72
69
|
_destinationRootClientId = getBlockRootClientId(
|
|
73
70
|
selectedBlockClientId
|
|
74
71
|
);
|
|
75
|
-
_destinationIndex =
|
|
76
|
-
getBlockIndex(
|
|
77
|
-
selectedBlockClientId,
|
|
78
|
-
_destinationRootClientId
|
|
79
|
-
) + 1;
|
|
72
|
+
_destinationIndex = getBlockIndex( selectedBlockClientId ) + 1;
|
|
80
73
|
} else {
|
|
81
74
|
// Insert at the end of the list.
|
|
82
75
|
_destinationIndex = getBlockOrder( _destinationRootClientId )
|
|
@@ -265,7 +265,7 @@ export default compose( [
|
|
|
265
265
|
|
|
266
266
|
// If the clientId is defined, we insert at the position of the block.
|
|
267
267
|
if ( clientId ) {
|
|
268
|
-
return getBlockIndex( clientId
|
|
268
|
+
return getBlockIndex( clientId );
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
// If there a selected block, we insert after the selected block.
|
|
@@ -275,7 +275,7 @@ export default compose( [
|
|
|
275
275
|
end &&
|
|
276
276
|
getBlockRootClientId( end ) === rootClientId
|
|
277
277
|
) {
|
|
278
|
-
return getBlockIndex( end
|
|
278
|
+
return getBlockIndex( end ) + 1;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// Otherwise, we insert at the end of the current rootClientId
|
|
@@ -343,10 +343,7 @@ export default compose( [
|
|
|
343
343
|
const destinationRootClientId = isAnyBlockSelected
|
|
344
344
|
? getBlockRootClientId( end )
|
|
345
345
|
: rootClientId;
|
|
346
|
-
const selectedBlockIndex = getBlockIndex(
|
|
347
|
-
end,
|
|
348
|
-
destinationRootClientId
|
|
349
|
-
);
|
|
346
|
+
const selectedBlockIndex = getBlockIndex( end );
|
|
350
347
|
const endOfRootIndex = getBlockOrder( rootClientId ).length;
|
|
351
348
|
const isSelectedUnmodifiedDefaultBlock = isAnyBlockSelected
|
|
352
349
|
? isUnmodifiedDefaultBlock( getBlock( end ) )
|
|
@@ -364,7 +361,7 @@ export default compose( [
|
|
|
364
361
|
|
|
365
362
|
// If the clientId is defined, we insert at the position of the block.
|
|
366
363
|
if ( clientId ) {
|
|
367
|
-
return getBlockIndex( clientId
|
|
364
|
+
return getBlockIndex( clientId );
|
|
368
365
|
}
|
|
369
366
|
|
|
370
367
|
// If there is a selected block,
|
|
@@ -56,7 +56,7 @@ export default function QuickInserter( {
|
|
|
56
56
|
const { getSettings, getBlockIndex, getBlockCount } = select(
|
|
57
57
|
blockEditorStore
|
|
58
58
|
);
|
|
59
|
-
const index = getBlockIndex( clientId
|
|
59
|
+
const index = getBlockIndex( clientId );
|
|
60
60
|
return {
|
|
61
61
|
setInserterIsOpened: getSettings()
|
|
62
62
|
.__experimentalSetIsInserterOpened,
|