@wordpress/block-editor 8.6.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +4 -2
- package/build/components/block-alignment-control/constants.js +48 -0
- package/build/components/block-alignment-control/constants.js.map +1 -0
- package/build/components/block-alignment-control/ui.js +9 -40
- package/build/components/block-alignment-control/ui.js.map +1 -1
- package/build/components/block-alignment-control/ui.native.js +92 -0
- package/build/components/block-alignment-control/ui.native.js.map +1 -0
- package/build/components/block-list/use-block-props/use-block-class-names.js +1 -7
- package/build/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build/components/block-navigation/dropdown.js +11 -5
- package/build/components/block-navigation/dropdown.js.map +1 -1
- package/build/components/block-popover/index.js +20 -5
- package/build/components/block-popover/index.js.map +1 -1
- package/build/components/color-style-selector/index.js +9 -0
- package/build/components/color-style-selector/index.js.map +1 -1
- package/build/components/index.js +0 -9
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/index.js +21 -7
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/index.native.js +1 -1
- package/build/components/inserter/index.native.js.map +1 -1
- package/build/components/inserter/quick-inserter.js +4 -5
- package/build/components/inserter/quick-inserter.js.map +1 -1
- package/build/components/list-view/block.js +15 -15
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/branch.js +9 -13
- package/build/components/list-view/branch.js.map +1 -1
- package/build/components/list-view/context.js +1 -4
- package/build/components/list-view/context.js.map +1 -1
- package/build/components/list-view/index.js +15 -32
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/url-input/index.js +7 -3
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/use-setting/index.js +42 -18
- package/build/components/use-setting/index.js.map +1 -1
- package/build/components/writing-flow/use-click-selection.js +1 -3
- package/build/components/writing-flow/use-click-selection.js.map +1 -1
- package/build/components/writing-flow/use-selection-observer.js +49 -8
- package/build/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build/hooks/dimensions.js +2 -2
- package/build/hooks/dimensions.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/margin.js +64 -12
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +60 -12
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/settings.js +32 -0
- package/build/hooks/settings.js.map +1 -0
- package/build/store/defaults.js +0 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/selectors.js +14 -12
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-alignment-control/constants.js +36 -0
- package/build-module/components/block-alignment-control/constants.js.map +1 -0
- package/build-module/components/block-alignment-control/ui.js +4 -35
- package/build-module/components/block-alignment-control/ui.js.map +1 -1
- package/build-module/components/block-alignment-control/ui.native.js +78 -0
- package/build-module/components/block-alignment-control/ui.native.js.map +1 -0
- package/build-module/components/block-list/use-block-props/use-block-class-names.js +1 -7
- package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +1 -1
- package/build-module/components/block-navigation/dropdown.js +10 -5
- package/build-module/components/block-navigation/dropdown.js.map +1 -1
- package/build-module/components/block-popover/index.js +21 -5
- package/build-module/components/block-popover/index.js.map +1 -1
- package/build-module/components/color-style-selector/index.js +6 -0
- package/build-module/components/color-style-selector/index.js.map +1 -1
- package/build-module/components/index.js +0 -1
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/index.js +21 -7
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/index.native.js +1 -1
- package/build-module/components/inserter/index.native.js.map +1 -1
- package/build-module/components/inserter/quick-inserter.js +4 -5
- package/build-module/components/inserter/quick-inserter.js.map +1 -1
- package/build-module/components/list-view/block.js +15 -16
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/branch.js +9 -13
- package/build-module/components/list-view/branch.js.map +1 -1
- package/build-module/components/list-view/context.js +1 -4
- package/build-module/components/list-view/context.js.map +1 -1
- package/build-module/components/list-view/index.js +15 -31
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/url-input/index.js +7 -3
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/use-setting/index.js +43 -19
- package/build-module/components/use-setting/index.js.map +1 -1
- package/build-module/components/writing-flow/use-click-selection.js +1 -3
- package/build-module/components/writing-flow/use-click-selection.js.map +1 -1
- package/build-module/components/writing-flow/use-selection-observer.js +49 -8
- package/build-module/components/writing-flow/use-selection-observer.js.map +1 -1
- package/build-module/hooks/dimensions.js +5 -5
- package/build-module/hooks/dimensions.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/margin.js +61 -13
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +57 -13
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/settings.js +29 -0
- package/build-module/hooks/settings.js.map +1 -0
- package/build-module/store/defaults.js +0 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/selectors.js +14 -12
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +17 -31
- package/build-style/style.css +17 -31
- package/package.json +28 -28
- package/src/components/block-alignment-control/constants.js +45 -0
- package/src/components/block-alignment-control/ui.js +69 -109
- package/src/components/block-alignment-control/ui.native.js +86 -0
- package/src/components/block-content-overlay/style.scss +0 -1
- package/src/components/block-list/style.scss +7 -18
- package/src/components/block-list/use-block-props/use-block-class-names.js +1 -11
- package/src/components/block-navigation/dropdown.js +12 -8
- package/src/components/block-popover/index.js +20 -3
- package/src/components/block-popover/style.scss +3 -0
- package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -1
- package/src/components/color-style-selector/index.js +18 -9
- package/src/components/image-size-control/README.md +1 -1
- package/src/components/index.js +0 -1
- package/src/components/inserter/index.js +20 -0
- package/src/components/inserter/index.native.js +1 -1
- package/src/components/inserter/quick-inserter.js +3 -11
- package/src/components/inserter/style.native.scss +1 -0
- package/src/components/list-view/block.js +24 -34
- package/src/components/list-view/branch.js +10 -20
- package/src/components/list-view/context.js +1 -4
- package/src/components/list-view/index.js +11 -41
- package/src/components/url-input/index.js +6 -3
- package/src/components/use-setting/index.js +57 -21
- package/src/components/writing-flow/use-click-selection.js +1 -4
- package/src/components/writing-flow/use-selection-observer.js +55 -10
- package/src/hooks/dimensions.js +44 -38
- package/src/hooks/index.js +1 -0
- package/src/hooks/margin.js +64 -15
- package/src/hooks/padding.js +60 -15
- package/src/hooks/padding.scss +12 -0
- package/src/hooks/settings.js +32 -0
- package/src/hooks/test/settings.js +48 -0
- package/src/store/defaults.js +0 -1
- package/src/store/selectors.js +14 -12
- package/src/store/test/selectors.js +17 -0
- package/src/style.scss +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/border-style-control/index.js +0 -60
- package/build/components/border-style-control/index.js.map +0 -1
- package/build-module/components/border-style-control/index.js +0 -50
- package/build-module/components/border-style-control/index.js.map +0 -1
- package/src/components/border-style-control/index.js +0 -47
- package/src/components/border-style-control/style.scss +0 -18
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deprecated from '@wordpress/deprecated';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -36,10 +41,12 @@ function BlockNavigationDropdownToggle( {
|
|
|
36
41
|
);
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
function BlockNavigationDropdown(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
function BlockNavigationDropdown( { isDisabled, ...props }, ref ) {
|
|
45
|
+
deprecated( 'wp.blockEditor.BlockNavigationDropdown', {
|
|
46
|
+
since: '6.1',
|
|
47
|
+
alternative: 'wp.components.Dropdown and wp.blockEditor.ListView',
|
|
48
|
+
} );
|
|
49
|
+
|
|
43
50
|
const hasBlocks = useSelect(
|
|
44
51
|
( select ) => !! select( blockEditorStore ).getBlockCount(),
|
|
45
52
|
[]
|
|
@@ -65,10 +72,7 @@ function BlockNavigationDropdown(
|
|
|
65
72
|
{ __( 'List view' ) }
|
|
66
73
|
</p>
|
|
67
74
|
|
|
68
|
-
<ListView
|
|
69
|
-
showNestedBlocks
|
|
70
|
-
__experimentalFeatures={ __experimentalFeatures }
|
|
71
|
-
/>
|
|
75
|
+
<ListView />
|
|
72
76
|
</div>
|
|
73
77
|
) }
|
|
74
78
|
/>
|
|
@@ -8,6 +8,7 @@ import classnames from 'classnames';
|
|
|
8
8
|
*/
|
|
9
9
|
import { Popover } from '@wordpress/components';
|
|
10
10
|
import { getScrollContainer } from '@wordpress/dom';
|
|
11
|
+
import { useMemo } from '@wordpress/element';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
@@ -19,6 +20,8 @@ export default function BlockPopover( {
|
|
|
19
20
|
clientId,
|
|
20
21
|
bottomClientId,
|
|
21
22
|
children,
|
|
23
|
+
__unstableRefreshSize,
|
|
24
|
+
__unstableCoverTarget = false,
|
|
22
25
|
__unstablePopoverSlot,
|
|
23
26
|
__unstableContentRef,
|
|
24
27
|
...props
|
|
@@ -26,6 +29,17 @@ export default function BlockPopover( {
|
|
|
26
29
|
const selectedElement = useBlockElement( clientId );
|
|
27
30
|
const lastSelectedElement = useBlockElement( bottomClientId ?? clientId );
|
|
28
31
|
const popoverScrollRef = usePopoverScroll( __unstableContentRef );
|
|
32
|
+
const style = useMemo( () => {
|
|
33
|
+
if ( ! selectedElement || lastSelectedElement !== selectedElement ) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
position: 'absolute',
|
|
39
|
+
width: selectedElement.offsetWidth,
|
|
40
|
+
height: selectedElement.offsetHeight,
|
|
41
|
+
};
|
|
42
|
+
}, [ selectedElement, lastSelectedElement, __unstableRefreshSize ] );
|
|
29
43
|
|
|
30
44
|
if ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {
|
|
31
45
|
return null;
|
|
@@ -50,24 +64,27 @@ export default function BlockPopover( {
|
|
|
50
64
|
position="top right left"
|
|
51
65
|
focusOnMount={ false }
|
|
52
66
|
anchorRef={ anchorRef }
|
|
53
|
-
__unstableStickyBoundaryElement={
|
|
67
|
+
__unstableStickyBoundaryElement={
|
|
68
|
+
__unstableCoverTarget ? undefined : stickyBoundaryElement
|
|
69
|
+
}
|
|
54
70
|
// Render in the old slot if needed for backward compatibility,
|
|
55
71
|
// otherwise render in place (not in the the default popover slot).
|
|
56
72
|
__unstableSlotName={ __unstablePopoverSlot || null }
|
|
57
73
|
__unstableBoundaryParent
|
|
58
74
|
// Observe movement for block animations (especially horizontal).
|
|
59
75
|
__unstableObserveElement={ selectedElement }
|
|
60
|
-
shouldAnchorIncludePadding
|
|
61
76
|
// Used to safeguard sticky position behavior against cases where it would permanently
|
|
62
77
|
// obscure specific sections of a block.
|
|
63
78
|
__unstableEditorCanvasWrapper={ __unstableContentRef?.current }
|
|
79
|
+
__unstableForcePosition={ __unstableCoverTarget }
|
|
64
80
|
{ ...props }
|
|
65
81
|
className={ classnames(
|
|
66
82
|
'block-editor-block-popover',
|
|
67
83
|
props.className
|
|
68
84
|
) }
|
|
69
85
|
>
|
|
70
|
-
{ children }
|
|
86
|
+
{ __unstableCoverTarget && <div style={ style }>{ children }</div> }
|
|
87
|
+
{ ! __unstableCoverTarget && children }
|
|
71
88
|
</Popover>
|
|
72
89
|
);
|
|
73
90
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
.components-popover.block-editor-block-popover {
|
|
3
3
|
z-index: z-index(".block-editor-block-popover");
|
|
4
4
|
position: absolute;
|
|
5
|
+
// Shouldn't be needed but it looks
|
|
6
|
+
// like the popover is impacted by the block gap margin.
|
|
7
|
+
margin: 0 !important;
|
|
5
8
|
|
|
6
9
|
.components-popover__content {
|
|
7
10
|
margin: 0 !important;
|
|
@@ -231,7 +231,7 @@ exports[`ColorPaletteControl matches the snapshot 1`] = `
|
|
|
231
231
|
>
|
|
232
232
|
<button
|
|
233
233
|
aria-describedby={null}
|
|
234
|
-
className="components-button components-circular-option-picker__clear is-
|
|
234
|
+
className="components-button components-circular-option-picker__clear is-tertiary"
|
|
235
235
|
onClick={[Function]}
|
|
236
236
|
type="button"
|
|
237
237
|
>
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from '@wordpress/components';
|
|
11
11
|
import { __ } from '@wordpress/i18n';
|
|
12
12
|
import { DOWN } from '@wordpress/keycodes';
|
|
13
|
+
import deprecated from '@wordpress/deprecated';
|
|
13
14
|
|
|
14
15
|
const ColorSelectorSVGIcon = () => (
|
|
15
16
|
<SVG xmlns="https://www.w3.org/2000/svg" viewBox="0 0 20 20">
|
|
@@ -78,14 +79,22 @@ const renderToggleComponent = ( { TextColor, BackgroundColor } ) => ( {
|
|
|
78
79
|
);
|
|
79
80
|
};
|
|
80
81
|
|
|
81
|
-
const BlockColorsStyleSelector = ( { children, ...other } ) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
const BlockColorsStyleSelector = ( { children, ...other } ) => {
|
|
83
|
+
deprecated( `wp.blockEditor.BlockColorsStyleSelector`, {
|
|
84
|
+
alternative: 'block supports API',
|
|
85
|
+
since: '6.1',
|
|
86
|
+
version: '6.3',
|
|
87
|
+
} );
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Dropdown
|
|
91
|
+
position="bottom right"
|
|
92
|
+
className="block-library-colors-selector"
|
|
93
|
+
contentClassName="block-library-colors-selector__popover"
|
|
94
|
+
renderToggle={ renderToggleComponent( other ) }
|
|
95
|
+
renderContent={ () => children }
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
90
99
|
|
|
91
100
|
export default BlockColorsStyleSelector;
|
package/src/components/index.js
CHANGED
|
@@ -33,7 +33,6 @@ export {
|
|
|
33
33
|
BlockVerticalAlignmentControl,
|
|
34
34
|
} from './block-vertical-alignment-control';
|
|
35
35
|
export { default as __experimentalBorderRadiusControl } from './border-radius-control';
|
|
36
|
-
export { default as __experimentalBorderStyleControl } from './border-style-control';
|
|
37
36
|
export {
|
|
38
37
|
// This is a typo, but kept here for back-compat.
|
|
39
38
|
ButtonBlockerAppender,
|
|
@@ -30,6 +30,7 @@ const defaultRenderToggle = ( {
|
|
|
30
30
|
blockTitle,
|
|
31
31
|
hasSingleBlockType,
|
|
32
32
|
toggleProps = {},
|
|
33
|
+
prioritizePatterns,
|
|
33
34
|
} ) => {
|
|
34
35
|
let label;
|
|
35
36
|
if ( hasSingleBlockType ) {
|
|
@@ -38,6 +39,8 @@ const defaultRenderToggle = ( {
|
|
|
38
39
|
_x( 'Add %s', 'directly add the only allowed block' ),
|
|
39
40
|
blockTitle
|
|
40
41
|
);
|
|
42
|
+
} else if ( prioritizePatterns ) {
|
|
43
|
+
label = __( 'Add pattern' );
|
|
41
44
|
} else {
|
|
42
45
|
label = _x( 'Add block', 'Generic label for block inserter button' );
|
|
43
46
|
}
|
|
@@ -106,6 +109,7 @@ class Inserter extends Component {
|
|
|
106
109
|
toggleProps,
|
|
107
110
|
hasItems,
|
|
108
111
|
renderToggle = defaultRenderToggle,
|
|
112
|
+
prioritizePatterns,
|
|
109
113
|
} = this.props;
|
|
110
114
|
|
|
111
115
|
return renderToggle( {
|
|
@@ -116,6 +120,7 @@ class Inserter extends Component {
|
|
|
116
120
|
hasSingleBlockType,
|
|
117
121
|
directInsertBlock,
|
|
118
122
|
toggleProps,
|
|
123
|
+
prioritizePatterns,
|
|
119
124
|
} );
|
|
120
125
|
}
|
|
121
126
|
|
|
@@ -138,6 +143,7 @@ class Inserter extends Component {
|
|
|
138
143
|
// This prop is experimental to give some time for the quick inserter to mature
|
|
139
144
|
// Feel free to make them stable after a few releases.
|
|
140
145
|
__experimentalIsQuick: isQuick,
|
|
146
|
+
prioritizePatterns,
|
|
141
147
|
} = this.props;
|
|
142
148
|
|
|
143
149
|
if ( isQuick ) {
|
|
@@ -149,6 +155,7 @@ class Inserter extends Component {
|
|
|
149
155
|
rootClientId={ rootClientId }
|
|
150
156
|
clientId={ clientId }
|
|
151
157
|
isAppender={ isAppender }
|
|
158
|
+
prioritizePatterns={ prioritizePatterns }
|
|
152
159
|
/>
|
|
153
160
|
);
|
|
154
161
|
}
|
|
@@ -206,7 +213,11 @@ export default compose( [
|
|
|
206
213
|
hasInserterItems,
|
|
207
214
|
__experimentalGetAllowedBlocks,
|
|
208
215
|
__experimentalGetDirectInsertBlock,
|
|
216
|
+
getBlockIndex,
|
|
217
|
+
getBlockCount,
|
|
218
|
+
getSettings,
|
|
209
219
|
} = select( blockEditorStore );
|
|
220
|
+
|
|
210
221
|
const { getBlockVariations } = select( blocksStore );
|
|
211
222
|
|
|
212
223
|
rootClientId =
|
|
@@ -218,6 +229,10 @@ export default compose( [
|
|
|
218
229
|
rootClientId
|
|
219
230
|
);
|
|
220
231
|
|
|
232
|
+
const index = getBlockIndex( clientId );
|
|
233
|
+
const blockCount = getBlockCount();
|
|
234
|
+
const settings = getSettings();
|
|
235
|
+
|
|
221
236
|
const hasSingleBlockType =
|
|
222
237
|
size( allowedBlocks ) === 1 &&
|
|
223
238
|
size(
|
|
@@ -236,6 +251,11 @@ export default compose( [
|
|
|
236
251
|
allowedBlockType,
|
|
237
252
|
directInsertBlock,
|
|
238
253
|
rootClientId,
|
|
254
|
+
prioritizePatterns:
|
|
255
|
+
settings.__experimentalPreferPatternsOnRoot &&
|
|
256
|
+
! rootClientId &&
|
|
257
|
+
index > 0 &&
|
|
258
|
+
( index < blockCount || blockCount === 0 ),
|
|
239
259
|
};
|
|
240
260
|
} ),
|
|
241
261
|
withDispatch( ( dispatch, ownProps, { select } ) => {
|
|
@@ -30,6 +30,7 @@ export default function QuickInserter( {
|
|
|
30
30
|
rootClientId,
|
|
31
31
|
clientId,
|
|
32
32
|
isAppender,
|
|
33
|
+
prioritizePatterns,
|
|
33
34
|
} ) {
|
|
34
35
|
const [ filterValue, setFilterValue ] = useState( '' );
|
|
35
36
|
const [ destinationRootClientId, onInsertBlocks ] = useInsertionPoint( {
|
|
@@ -48,11 +49,7 @@ export default function QuickInserter( {
|
|
|
48
49
|
destinationRootClientId
|
|
49
50
|
);
|
|
50
51
|
|
|
51
|
-
const {
|
|
52
|
-
setInserterIsOpened,
|
|
53
|
-
insertionIndex,
|
|
54
|
-
prioritizePatterns,
|
|
55
|
-
} = useSelect(
|
|
52
|
+
const { setInserterIsOpened, insertionIndex } = useSelect(
|
|
56
53
|
( select ) => {
|
|
57
54
|
const { getSettings, getBlockIndex, getBlockCount } = select(
|
|
58
55
|
blockEditorStore
|
|
@@ -63,15 +60,10 @@ export default function QuickInserter( {
|
|
|
63
60
|
|
|
64
61
|
return {
|
|
65
62
|
setInserterIsOpened: settings.__experimentalSetIsInserterOpened,
|
|
66
|
-
prioritizePatterns:
|
|
67
|
-
settings.__experimentalPreferPatternsOnRoot &&
|
|
68
|
-
! rootClientId &&
|
|
69
|
-
index > 0 &&
|
|
70
|
-
( index < blockCount || blockCount === 0 ),
|
|
71
63
|
insertionIndex: index === -1 ? blockCount : index,
|
|
72
64
|
};
|
|
73
65
|
},
|
|
74
|
-
[ clientId
|
|
66
|
+
[ clientId ]
|
|
75
67
|
);
|
|
76
68
|
|
|
77
69
|
const showPatterns =
|
|
@@ -6,6 +6,7 @@ import classnames from 'classnames';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
+
import { hasBlockSupport } from '@wordpress/blocks';
|
|
9
10
|
import {
|
|
10
11
|
__experimentalTreeGridCell as TreeGridCell,
|
|
11
12
|
__experimentalTreeGridItem as TreeGridItem,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
useCallback,
|
|
20
21
|
memo,
|
|
21
22
|
} from '@wordpress/element';
|
|
22
|
-
import { useDispatch } from '@wordpress/data';
|
|
23
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
23
24
|
import { sprintf, __ } from '@wordpress/i18n';
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -66,6 +67,19 @@ function ListViewBlock( {
|
|
|
66
67
|
const { toggleBlockHighlight } = useDispatch( blockEditorStore );
|
|
67
68
|
|
|
68
69
|
const blockInformation = useBlockDisplayInformation( clientId );
|
|
70
|
+
const blockName = useSelect(
|
|
71
|
+
( select ) => select( blockEditorStore ).getBlockName( clientId ),
|
|
72
|
+
[ clientId ]
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// When a block hides its toolbar it also hides the block settings menu,
|
|
76
|
+
// since that menu is part of the toolbar in the editor canvas.
|
|
77
|
+
// List View respects this by also hiding the block settings menu.
|
|
78
|
+
const showBlockActions = hasBlockSupport(
|
|
79
|
+
blockName,
|
|
80
|
+
'__experimentalToolbar',
|
|
81
|
+
true
|
|
82
|
+
);
|
|
69
83
|
const { isLocked } = useBlockLock( clientId );
|
|
70
84
|
const instanceId = useInstanceId( ListViewBlock );
|
|
71
85
|
const descriptionId = `list-view-block-select-button__${ instanceId }`;
|
|
@@ -98,14 +112,7 @@ function ListViewBlock( {
|
|
|
98
112
|
)
|
|
99
113
|
: __( 'Options' );
|
|
100
114
|
|
|
101
|
-
const {
|
|
102
|
-
__experimentalFeatures: withExperimentalFeatures,
|
|
103
|
-
__experimentalPersistentListViewFeatures: withExperimentalPersistentListViewFeatures,
|
|
104
|
-
__experimentalHideContainerBlockActions: hideContainerBlockActions,
|
|
105
|
-
isTreeGridMounted,
|
|
106
|
-
expand,
|
|
107
|
-
collapse,
|
|
108
|
-
} = useListViewContext();
|
|
115
|
+
const { isTreeGridMounted, expand, collapse } = useListViewContext();
|
|
109
116
|
|
|
110
117
|
const hasSiblings = siblingBlockCount > 0;
|
|
111
118
|
const hasRenderedMovers = showBlockMovers && hasSiblings;
|
|
@@ -123,27 +130,19 @@ function ListViewBlock( {
|
|
|
123
130
|
// only focus the selected list item on mount; otherwise the list would always
|
|
124
131
|
// try to steal the focus from the editor canvas.
|
|
125
132
|
useEffect( () => {
|
|
126
|
-
if (
|
|
127
|
-
withExperimentalPersistentListViewFeatures &&
|
|
128
|
-
! isTreeGridMounted &&
|
|
129
|
-
isSelected
|
|
130
|
-
) {
|
|
133
|
+
if ( ! isTreeGridMounted && isSelected ) {
|
|
131
134
|
cellRef.current.focus();
|
|
132
135
|
}
|
|
133
136
|
}, [] );
|
|
134
137
|
|
|
135
|
-
const highlightBlock = withExperimentalPersistentListViewFeatures
|
|
136
|
-
? toggleBlockHighlight
|
|
137
|
-
: () => {};
|
|
138
|
-
|
|
139
138
|
const onMouseEnter = useCallback( () => {
|
|
140
139
|
setIsHovered( true );
|
|
141
|
-
|
|
142
|
-
}, [ clientId, setIsHovered,
|
|
140
|
+
toggleBlockHighlight( clientId, true );
|
|
141
|
+
}, [ clientId, setIsHovered, toggleBlockHighlight ] );
|
|
143
142
|
const onMouseLeave = useCallback( () => {
|
|
144
143
|
setIsHovered( false );
|
|
145
|
-
|
|
146
|
-
}, [ clientId, setIsHovered,
|
|
144
|
+
toggleBlockHighlight( clientId, false );
|
|
145
|
+
}, [ clientId, setIsHovered, toggleBlockHighlight ] );
|
|
147
146
|
|
|
148
147
|
const selectEditorBlock = useCallback(
|
|
149
148
|
( event ) => {
|
|
@@ -174,18 +173,10 @@ function ListViewBlock( {
|
|
|
174
173
|
[ clientId, expand, collapse, isExpanded ]
|
|
175
174
|
);
|
|
176
175
|
|
|
177
|
-
const showBlockActions =
|
|
178
|
-
withExperimentalFeatures &&
|
|
179
|
-
// hide actions for blocks like core/widget-areas
|
|
180
|
-
( ! hideContainerBlockActions ||
|
|
181
|
-
( hideContainerBlockActions && level > 1 ) );
|
|
182
|
-
|
|
183
|
-
const hideBlockActions = withExperimentalFeatures && ! showBlockActions;
|
|
184
|
-
|
|
185
176
|
let colSpan;
|
|
186
177
|
if ( hasRenderedMovers ) {
|
|
187
178
|
colSpan = 2;
|
|
188
|
-
} else if (
|
|
179
|
+
} else if ( ! showBlockActions ) {
|
|
189
180
|
colSpan = 3;
|
|
190
181
|
}
|
|
191
182
|
|
|
@@ -193,10 +184,9 @@ function ListViewBlock( {
|
|
|
193
184
|
'is-selected': isSelected,
|
|
194
185
|
'is-first-selected': isFirstSelectedBlock,
|
|
195
186
|
'is-last-selected': isLastSelectedBlock,
|
|
196
|
-
'is-branch-selected':
|
|
197
|
-
withExperimentalPersistentListViewFeatures && isBranchSelected,
|
|
187
|
+
'is-branch-selected': isBranchSelected,
|
|
198
188
|
'is-dragging': isDragged,
|
|
199
|
-
'has-single-cell':
|
|
189
|
+
'has-single-cell': ! showBlockActions,
|
|
200
190
|
} );
|
|
201
191
|
|
|
202
192
|
// Only include all selected blocks if the currently clicked on block
|
|
@@ -85,21 +85,16 @@ function ListViewBranch( props ) {
|
|
|
85
85
|
blocks,
|
|
86
86
|
selectBlock,
|
|
87
87
|
showBlockMovers,
|
|
88
|
-
showNestedBlocks,
|
|
89
88
|
selectedClientIds,
|
|
90
89
|
level = 1,
|
|
91
90
|
path = '',
|
|
92
91
|
isBranchSelected = false,
|
|
93
92
|
listPosition = 0,
|
|
94
93
|
fixedListWindow,
|
|
95
|
-
|
|
94
|
+
isExpanded,
|
|
96
95
|
} = props;
|
|
97
96
|
|
|
98
|
-
const {
|
|
99
|
-
expandedState,
|
|
100
|
-
draggedClientIds,
|
|
101
|
-
__experimentalPersistentListViewFeatures,
|
|
102
|
-
} = useListViewContext();
|
|
97
|
+
const { expandedState, draggedClientIds } = useListViewContext();
|
|
103
98
|
|
|
104
99
|
const filteredBlocks = compact( blocks );
|
|
105
100
|
const blockCount = filteredBlocks.length;
|
|
@@ -115,26 +110,22 @@ function ListViewBranch( props ) {
|
|
|
115
110
|
filteredBlocks[ index - 1 ],
|
|
116
111
|
expandedState,
|
|
117
112
|
draggedClientIds,
|
|
118
|
-
|
|
113
|
+
isExpanded
|
|
119
114
|
);
|
|
120
115
|
}
|
|
121
116
|
|
|
122
|
-
const usesWindowing = __experimentalPersistentListViewFeatures;
|
|
123
|
-
|
|
124
117
|
const { itemInView } = fixedListWindow;
|
|
125
|
-
const blockInView =
|
|
126
|
-
! usesWindowing || itemInView( nextPosition );
|
|
118
|
+
const blockInView = itemInView( nextPosition );
|
|
127
119
|
|
|
128
120
|
const position = index + 1;
|
|
129
121
|
const updatedPath =
|
|
130
122
|
path.length > 0
|
|
131
123
|
? `${ path }_${ position }`
|
|
132
124
|
: `${ position }`;
|
|
133
|
-
const hasNestedBlocks =
|
|
134
|
-
showNestedBlocks && !! innerBlocks && !! innerBlocks.length;
|
|
125
|
+
const hasNestedBlocks = !! innerBlocks?.length;
|
|
135
126
|
|
|
136
|
-
const
|
|
137
|
-
? expandedState[ clientId ] ??
|
|
127
|
+
const shouldExpand = hasNestedBlocks
|
|
128
|
+
? expandedState[ clientId ] ?? isExpanded
|
|
138
129
|
: undefined;
|
|
139
130
|
|
|
140
131
|
const isDragged = !! draggedClientIds?.includes( clientId );
|
|
@@ -164,7 +155,7 @@ function ListViewBranch( props ) {
|
|
|
164
155
|
siblingBlockCount={ blockCount }
|
|
165
156
|
showBlockMovers={ showBlockMovers }
|
|
166
157
|
path={ updatedPath }
|
|
167
|
-
isExpanded={
|
|
158
|
+
isExpanded={ shouldExpand }
|
|
168
159
|
listPosition={ nextPosition }
|
|
169
160
|
selectedClientIds={ selectedClientIds }
|
|
170
161
|
/>
|
|
@@ -174,19 +165,18 @@ function ListViewBranch( props ) {
|
|
|
174
165
|
<td className="block-editor-list-view-placeholder" />
|
|
175
166
|
</tr>
|
|
176
167
|
) }
|
|
177
|
-
{ hasNestedBlocks &&
|
|
168
|
+
{ hasNestedBlocks && shouldExpand && ! isDragged && (
|
|
178
169
|
<ListViewBranch
|
|
179
170
|
blocks={ innerBlocks }
|
|
180
171
|
selectBlock={ selectBlock }
|
|
181
172
|
showBlockMovers={ showBlockMovers }
|
|
182
|
-
showNestedBlocks={ showNestedBlocks }
|
|
183
173
|
level={ level + 1 }
|
|
184
174
|
path={ updatedPath }
|
|
185
175
|
listPosition={ nextPosition + 1 }
|
|
186
176
|
fixedListWindow={ fixedListWindow }
|
|
187
177
|
isBranchSelected={ isSelectedBranch }
|
|
188
178
|
selectedClientIds={ selectedClientIds }
|
|
189
|
-
|
|
179
|
+
isExpanded={ isExpanded }
|
|
190
180
|
/>
|
|
191
181
|
) }
|
|
192
182
|
</AsyncModeProvider>
|
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createContext, useContext } from '@wordpress/element';
|
|
5
5
|
|
|
6
|
-
export const ListViewContext = createContext( {
|
|
7
|
-
__experimentalFeatures: false,
|
|
8
|
-
__experimentalPersistentListViewFeatures: false,
|
|
9
|
-
} );
|
|
6
|
+
export const ListViewContext = createContext( {} );
|
|
10
7
|
|
|
11
8
|
export const useListViewContext = () => useContext( ListViewContext );
|
|
@@ -48,33 +48,17 @@ const expanded = ( state, action ) => {
|
|
|
48
48
|
export const BLOCK_LIST_ITEM_HEIGHT = 36;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
* recursive component (it renders itself), so this ensures TreeGrid is only
|
|
53
|
-
* present at the very top of the navigation grid.
|
|
51
|
+
* Show a hierarchical list of blocks.
|
|
54
52
|
*
|
|
55
|
-
* @param {Object} props
|
|
56
|
-
* @param {
|
|
57
|
-
* @param {
|
|
58
|
-
* @param {boolean} props.showBlockMovers
|
|
59
|
-
* @param {boolean} props.
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {boolean} props.__experimentalHideContainerBlockActions Flag to hide actions of top level blocks (like core/widget-area)
|
|
62
|
-
* @param {string} props.id Unique identifier for the root list element (primarily for a11y purposes).
|
|
63
|
-
* @param {boolean} props.expandNested Flag to determine whether nested levels are expanded by default.
|
|
64
|
-
* @param {Object} ref Forwarded ref
|
|
53
|
+
* @param {Object} props Components props.
|
|
54
|
+
* @param {string} props.id An HTML element id for the root element of ListView.
|
|
55
|
+
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
|
|
56
|
+
* @param {boolean} props.showBlockMovers Flag to enable block movers
|
|
57
|
+
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
|
|
58
|
+
* @param {Object} ref Forwarded ref
|
|
65
59
|
*/
|
|
66
60
|
function ListView(
|
|
67
|
-
{
|
|
68
|
-
blocks,
|
|
69
|
-
__experimentalFeatures,
|
|
70
|
-
__experimentalPersistentListViewFeatures,
|
|
71
|
-
__experimentalHideContainerBlockActions,
|
|
72
|
-
showNestedBlocks,
|
|
73
|
-
showBlockMovers,
|
|
74
|
-
id,
|
|
75
|
-
expandNested = false,
|
|
76
|
-
...props
|
|
77
|
-
},
|
|
61
|
+
{ id, blocks, showBlockMovers = false, isExpanded = false },
|
|
78
62
|
ref
|
|
79
63
|
) {
|
|
80
64
|
const {
|
|
@@ -131,7 +115,7 @@ function ListView(
|
|
|
131
115
|
BLOCK_LIST_ITEM_HEIGHT,
|
|
132
116
|
visibleBlockCount,
|
|
133
117
|
{
|
|
134
|
-
useWindowing:
|
|
118
|
+
useWindowing: true,
|
|
135
119
|
windowOverscan: 40,
|
|
136
120
|
}
|
|
137
121
|
);
|
|
@@ -181,25 +165,13 @@ function ListView(
|
|
|
181
165
|
|
|
182
166
|
const contextValue = useMemo(
|
|
183
167
|
() => ( {
|
|
184
|
-
__experimentalFeatures,
|
|
185
|
-
__experimentalPersistentListViewFeatures,
|
|
186
|
-
__experimentalHideContainerBlockActions,
|
|
187
168
|
isTreeGridMounted: isMounted.current,
|
|
188
169
|
draggedClientIds,
|
|
189
170
|
expandedState,
|
|
190
171
|
expand,
|
|
191
172
|
collapse,
|
|
192
173
|
} ),
|
|
193
|
-
[
|
|
194
|
-
__experimentalFeatures,
|
|
195
|
-
__experimentalPersistentListViewFeatures,
|
|
196
|
-
__experimentalHideContainerBlockActions,
|
|
197
|
-
isMounted.current,
|
|
198
|
-
draggedClientIds,
|
|
199
|
-
expandedState,
|
|
200
|
-
expand,
|
|
201
|
-
collapse,
|
|
202
|
-
]
|
|
174
|
+
[ isMounted.current, draggedClientIds, expandedState, expand, collapse ]
|
|
203
175
|
);
|
|
204
176
|
|
|
205
177
|
return (
|
|
@@ -221,12 +193,10 @@ function ListView(
|
|
|
221
193
|
<ListViewBranch
|
|
222
194
|
blocks={ clientIdsTree }
|
|
223
195
|
selectBlock={ selectEditorBlock }
|
|
224
|
-
showNestedBlocks={ showNestedBlocks }
|
|
225
196
|
showBlockMovers={ showBlockMovers }
|
|
226
197
|
fixedListWindow={ fixedListWindow }
|
|
227
198
|
selectedClientIds={ selectedClientIds }
|
|
228
|
-
|
|
229
|
-
{ ...props }
|
|
199
|
+
isExpanded={ isExpanded }
|
|
230
200
|
/>
|
|
231
201
|
</ListViewContext.Provider>
|
|
232
202
|
</TreeGrid>
|
|
@@ -418,7 +418,7 @@ class URLInput extends Component {
|
|
|
418
418
|
|
|
419
419
|
renderControl() {
|
|
420
420
|
const {
|
|
421
|
-
label,
|
|
421
|
+
label = null,
|
|
422
422
|
className,
|
|
423
423
|
isFullWidth,
|
|
424
424
|
instanceId,
|
|
@@ -435,8 +435,10 @@ class URLInput extends Component {
|
|
|
435
435
|
suggestionOptionIdPrefix,
|
|
436
436
|
} = this.state;
|
|
437
437
|
|
|
438
|
+
const inputId = `url-input-control-${ instanceId }`;
|
|
439
|
+
|
|
438
440
|
const controlProps = {
|
|
439
|
-
id:
|
|
441
|
+
id: inputId, // Passes attribute to label for the for attribute
|
|
440
442
|
label,
|
|
441
443
|
className: classnames( 'block-editor-url-input', className, {
|
|
442
444
|
'is-full-width': isFullWidth,
|
|
@@ -444,6 +446,7 @@ class URLInput extends Component {
|
|
|
444
446
|
};
|
|
445
447
|
|
|
446
448
|
const inputProps = {
|
|
449
|
+
id: inputId,
|
|
447
450
|
value,
|
|
448
451
|
required: true,
|
|
449
452
|
className: 'block-editor-url-input__input',
|
|
@@ -453,7 +456,7 @@ class URLInput extends Component {
|
|
|
453
456
|
placeholder,
|
|
454
457
|
onKeyDown: this.onKeyDown,
|
|
455
458
|
role: 'combobox',
|
|
456
|
-
'aria-label': __( 'URL' ),
|
|
459
|
+
'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label
|
|
457
460
|
'aria-expanded': showSuggestions,
|
|
458
461
|
'aria-autocomplete': 'list',
|
|
459
462
|
'aria-owns': suggestionsListboxId,
|