@wordpress/block-editor 11.1.0 → 11.2.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/LICENSE.md +1 -1
- package/build/components/block-actions/index.js +9 -0
- package/build/components/block-actions/index.js.map +1 -1
- package/build/components/block-inspector/index.js +4 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-preview/auto.js +1 -4
- package/build/components/block-preview/auto.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-styles/index.js +3 -1
- package/build/components/block-styles/index.js.map +1 -1
- package/build/components/block-tools/use-block-toolbar-popover-props.js +43 -10
- package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build/components/default-style-picker/index.js +1 -0
- package/build/components/default-style-picker/index.js.map +1 -1
- package/build/components/font-sizes/with-font-sizes.js +5 -8
- package/build/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build/components/iframe/index.js +37 -8
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/iframe/use-compatibility-styles.js +6 -1
- package/build/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build/components/image-size-control/index.js +1 -0
- package/build/components/image-size-control/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +4 -4
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/index.js +3 -2
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/menu.js +11 -5
- package/build/components/inserter/menu.js.map +1 -1
- package/build/components/inspector-controls/groups.js +3 -1
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/position-controls-panel.js +46 -0
- package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
- package/build/components/inspector-controls-tabs/settings-tab.js +3 -1
- package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -11
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build/components/link-control/search-input.js +1 -0
- package/build/components/link-control/search-input.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +2 -38
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +38 -5
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/block.js +7 -25
- package/build/components/off-canvas-editor/block.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +7 -4
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/provider/index.js +3 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/rich-text/use-enter.js +4 -5
- package/build/components/rich-text/use-enter.js.map +1 -1
- package/build/components/url-input/button.js +1 -0
- package/build/components/url-input/button.js.map +1 -1
- package/build/components/url-input/index.js +15 -1
- package/build/components/url-input/index.js.map +1 -1
- package/build/components/url-popover/link-editor.js +1 -0
- package/build/components/url-popover/link-editor.js.map +1 -1
- package/build/components/use-paste-styles/index.js +188 -0
- package/build/components/use-paste-styles/index.js.map +1 -0
- package/build/components/writing-flow/use-arrow-nav.js +22 -29
- package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +1 -1
- package/build/hooks/position.js +376 -0
- package/build/hooks/position.js.map +1 -0
- package/build/hooks/supports.js +328 -0
- package/build/hooks/supports.js.map +1 -0
- package/build/store/reducer.js +6 -2
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +8 -6
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-actions/index.js +6 -0
- package/build-module/components/block-actions/index.js.map +1 -1
- package/build-module/components/block-inspector/index.js +3 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-preview/auto.js +1 -4
- package/build-module/components/block-preview/auto.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-styles/index.js +2 -1
- package/build-module/components/block-styles/index.js.map +1 -1
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js +42 -11
- package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
- package/build-module/components/default-style-picker/index.js +1 -0
- package/build-module/components/default-style-picker/index.js.map +1 -1
- package/build-module/components/font-sizes/with-font-sizes.js +5 -7
- package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
- package/build-module/components/iframe/index.js +36 -9
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/iframe/use-compatibility-styles.js +6 -1
- package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
- package/build-module/components/image-size-control/index.js +1 -0
- package/build-module/components/image-size-control/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +4 -4
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/index.js +3 -2
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/menu.js +11 -5
- package/build-module/components/inserter/menu.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +3 -1
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js +33 -0
- package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
- package/build-module/components/inspector-controls-tabs/settings-tab.js +2 -1
- package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -11
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
- package/build-module/components/link-control/search-input.js +1 -0
- package/build-module/components/link-control/search-input.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +3 -36
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +37 -7
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/block.js +9 -27
- package/build-module/components/off-canvas-editor/block.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +7 -4
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/provider/index.js +3 -1
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/rich-text/use-enter.js +4 -5
- package/build-module/components/rich-text/use-enter.js.map +1 -1
- package/build-module/components/url-input/button.js +1 -0
- package/build-module/components/url-input/button.js.map +1 -1
- package/build-module/components/url-input/index.js +14 -1
- package/build-module/components/url-input/index.js.map +1 -1
- package/build-module/components/url-popover/link-editor.js +1 -0
- package/build-module/components/url-popover/link-editor.js.map +1 -1
- package/build-module/components/use-paste-styles/index.js +174 -0
- package/build-module/components/use-paste-styles/index.js.map +1 -0
- package/build-module/components/writing-flow/use-arrow-nav.js +22 -29
- package/build-module/components/writing-flow/use-arrow-nav.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/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +1 -1
- package/build-module/hooks/position.js +337 -0
- package/build-module/hooks/position.js.map +1 -0
- package/build-module/hooks/supports.js +257 -0
- package/build-module/hooks/supports.js.map +1 -0
- package/build-module/store/reducer.js +6 -2
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +7 -5
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/content-rtl.css +57 -0
- package/build-style/content.css +57 -0
- package/build-style/style-rtl.css +27 -58
- package/build-style/style.css +27 -58
- package/package.json +29 -29
- package/src/components/block-actions/index.js +5 -0
- package/src/components/block-inspector/index.js +3 -1
- package/src/components/block-preview/auto.js +2 -4
- package/src/components/block-settings-menu/block-settings-dropdown.js +4 -0
- package/src/components/block-styles/index.js +4 -1
- package/src/components/block-tools/use-block-toolbar-popover-props.js +68 -12
- package/src/components/button-block-appender/{style.scss → content.scss} +0 -0
- package/src/components/default-style-picker/index.js +1 -0
- package/src/components/font-sizes/with-font-sizes.js +33 -33
- package/src/components/iframe/index.js +52 -19
- package/src/components/iframe/use-compatibility-styles.js +6 -0
- package/src/components/image-size-control/index.js +1 -0
- package/src/components/inserter/block-patterns-tab.js +7 -4
- package/src/components/inserter/index.js +46 -41
- package/src/components/inserter/menu.js +8 -4
- package/src/components/inserter/test/__snapshots__/index.native.js.snap +117 -0
- package/src/components/inserter/test/index.native.js +255 -1
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/position-controls-panel.js +37 -0
- package/src/components/inspector-controls-tabs/settings-tab.js +2 -0
- package/src/components/inspector-controls-tabs/style.scss +15 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -8
- package/src/components/link-control/search-input.js +1 -0
- package/src/components/link-control/style.scss +1 -0
- package/src/components/list-view/style.scss +13 -3
- package/src/components/off-canvas-editor/appender.js +2 -52
- package/src/components/off-canvas-editor/block-contents.js +84 -23
- package/src/components/off-canvas-editor/block.js +28 -60
- package/src/components/off-canvas-editor/index.js +12 -2
- package/src/components/provider/index.js +4 -1
- package/src/components/rich-text/use-enter.js +4 -4
- package/src/components/url-input/README.md +5 -0
- package/src/components/url-input/button.js +1 -0
- package/src/components/url-input/index.js +15 -1
- package/src/components/url-popover/link-editor.js +1 -0
- package/src/components/use-paste-styles/index.js +230 -0
- package/src/components/writing-flow/use-arrow-nav.js +20 -28
- package/src/content.scss +1 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/metadata.js +1 -2
- package/src/hooks/position.js +375 -0
- package/src/hooks/position.scss +18 -0
- package/src/hooks/supports.js +302 -0
- package/src/hooks/test/__snapshots__/align.native.js.snap +73 -0
- package/src/hooks/test/align.native.js +133 -0
- package/src/store/reducer.js +7 -2
- package/src/store/selectors.js +5 -5
- package/src/store/test/reducer.js +45 -3
- package/src/store/test/selectors.js +12 -9
- package/src/style.scss +2 -1
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
10
|
+
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
|
|
11
|
+
import { BaseControl, CustomSelectControl } from '@wordpress/components';
|
|
12
|
+
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
|
|
13
|
+
import {
|
|
14
|
+
useContext,
|
|
15
|
+
useMemo,
|
|
16
|
+
createPortal,
|
|
17
|
+
Platform,
|
|
18
|
+
} from '@wordpress/element';
|
|
19
|
+
import { addFilter } from '@wordpress/hooks';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Internal dependencies
|
|
23
|
+
*/
|
|
24
|
+
import BlockList from '../components/block-list';
|
|
25
|
+
import useSetting from '../components/use-setting';
|
|
26
|
+
import InspectorControls from '../components/inspector-controls';
|
|
27
|
+
import { cleanEmptyObject } from './utils';
|
|
28
|
+
|
|
29
|
+
const POSITION_SUPPORT_KEY = 'position';
|
|
30
|
+
|
|
31
|
+
const OPTION_CLASSNAME =
|
|
32
|
+
'block-editor-hooks__position-selection__select-control__option';
|
|
33
|
+
|
|
34
|
+
const DEFAULT_OPTION = {
|
|
35
|
+
key: 'default',
|
|
36
|
+
value: '',
|
|
37
|
+
name: __( 'Default' ),
|
|
38
|
+
className: OPTION_CLASSNAME,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const STICKY_OPTION = {
|
|
42
|
+
key: 'sticky',
|
|
43
|
+
value: 'sticky',
|
|
44
|
+
name: __( 'Sticky' ),
|
|
45
|
+
className: OPTION_CLASSNAME,
|
|
46
|
+
__experimentalHint: __(
|
|
47
|
+
'The block will stick to the top of the window instead of scrolling.'
|
|
48
|
+
),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const FIXED_OPTION = {
|
|
52
|
+
key: 'fixed',
|
|
53
|
+
value: 'fixed',
|
|
54
|
+
name: __( 'Fixed' ),
|
|
55
|
+
className: OPTION_CLASSNAME,
|
|
56
|
+
__experimentalHint: __(
|
|
57
|
+
'The block will not move when the page is scrolled.'
|
|
58
|
+
),
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];
|
|
62
|
+
const VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get calculated position CSS.
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} props Component props.
|
|
68
|
+
* @param {string} props.selector Selector to use.
|
|
69
|
+
* @param {Object} props.style Style object.
|
|
70
|
+
* @return {string} The generated CSS rules.
|
|
71
|
+
*/
|
|
72
|
+
export function getPositionCSS( { selector, style } ) {
|
|
73
|
+
let output = '';
|
|
74
|
+
|
|
75
|
+
const { type: positionType } = style?.position || {};
|
|
76
|
+
|
|
77
|
+
if ( ! VALID_POSITION_TYPES.includes( positionType ) ) {
|
|
78
|
+
return output;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
output += `${ selector } {`;
|
|
82
|
+
output += `position: ${ positionType };`;
|
|
83
|
+
|
|
84
|
+
POSITION_SIDES.forEach( ( side ) => {
|
|
85
|
+
if ( style?.position?.[ side ] !== undefined ) {
|
|
86
|
+
output += `${ side }: ${ style.position[ side ] };`;
|
|
87
|
+
}
|
|
88
|
+
} );
|
|
89
|
+
|
|
90
|
+
if ( positionType === 'sticky' || positionType === 'fixed' ) {
|
|
91
|
+
// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.
|
|
92
|
+
output += `z-index: 10`;
|
|
93
|
+
}
|
|
94
|
+
output += `}`;
|
|
95
|
+
|
|
96
|
+
return output;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Determines if there is sticky position support.
|
|
101
|
+
*
|
|
102
|
+
* @param {string|Object} blockType Block name or Block Type object.
|
|
103
|
+
*
|
|
104
|
+
* @return {boolean} Whether there is support.
|
|
105
|
+
*/
|
|
106
|
+
export function hasStickyPositionSupport( blockType ) {
|
|
107
|
+
const support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );
|
|
108
|
+
return !! ( true === support || support?.sticky );
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Determines if there is fixed position support.
|
|
113
|
+
*
|
|
114
|
+
* @param {string|Object} blockType Block name or Block Type object.
|
|
115
|
+
*
|
|
116
|
+
* @return {boolean} Whether there is support.
|
|
117
|
+
*/
|
|
118
|
+
export function hasFixedPositionSupport( blockType ) {
|
|
119
|
+
const support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );
|
|
120
|
+
return !! ( true === support || support?.fixed );
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Determines if there is position support.
|
|
125
|
+
*
|
|
126
|
+
* @param {string|Object} blockType Block name or Block Type object.
|
|
127
|
+
*
|
|
128
|
+
* @return {boolean} Whether there is support.
|
|
129
|
+
*/
|
|
130
|
+
export function hasPositionSupport( blockType ) {
|
|
131
|
+
const support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );
|
|
132
|
+
return !! support;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Checks if there is a current value in the position block support attributes.
|
|
137
|
+
*
|
|
138
|
+
* @param {Object} props Block props.
|
|
139
|
+
* @return {boolean} Whether or not the block has a position value set.
|
|
140
|
+
*/
|
|
141
|
+
export function hasPositionValue( props ) {
|
|
142
|
+
return props.attributes.style?.position?.type !== undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Checks if the block is currently set to a sticky or fixed position.
|
|
147
|
+
* This check is helpful for determining how to position block toolbars or other elements.
|
|
148
|
+
*
|
|
149
|
+
* @param {Object} attributes Block attributes.
|
|
150
|
+
* @return {boolean} Whether or not the block is set to a sticky or fixed position.
|
|
151
|
+
*/
|
|
152
|
+
export function hasStickyOrFixedPositionValue( attributes ) {
|
|
153
|
+
const positionType = attributes.style?.position?.type;
|
|
154
|
+
return positionType === 'sticky' || positionType === 'fixed';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Resets the position block support attributes. This can be used when disabling
|
|
159
|
+
* the position support controls for a block via a `ToolsPanel`.
|
|
160
|
+
*
|
|
161
|
+
* @param {Object} props Block props.
|
|
162
|
+
* @param {Object} props.attributes Block's attributes.
|
|
163
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
164
|
+
*/
|
|
165
|
+
export function resetPosition( { attributes = {}, setAttributes } ) {
|
|
166
|
+
const { style = {} } = attributes;
|
|
167
|
+
|
|
168
|
+
setAttributes( {
|
|
169
|
+
style: cleanEmptyObject( {
|
|
170
|
+
...style,
|
|
171
|
+
position: {
|
|
172
|
+
...style?.position,
|
|
173
|
+
type: undefined,
|
|
174
|
+
top: undefined,
|
|
175
|
+
right: undefined,
|
|
176
|
+
bottom: undefined,
|
|
177
|
+
left: undefined,
|
|
178
|
+
},
|
|
179
|
+
} ),
|
|
180
|
+
} );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Custom hook that checks if position settings have been disabled.
|
|
185
|
+
*
|
|
186
|
+
* @param {string} name The name of the block.
|
|
187
|
+
*
|
|
188
|
+
* @return {boolean} Whether padding setting is disabled.
|
|
189
|
+
*/
|
|
190
|
+
export function useIsPositionDisabled( { name: blockName } = {} ) {
|
|
191
|
+
const allowFixed = useSetting( 'position.fixed' );
|
|
192
|
+
const allowSticky = useSetting( 'position.sticky' );
|
|
193
|
+
const isDisabled = ! allowFixed && ! allowSticky;
|
|
194
|
+
|
|
195
|
+
return ! hasPositionSupport( blockName ) || isDisabled;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/*
|
|
199
|
+
* Position controls to be rendered in an inspector control panel.
|
|
200
|
+
*
|
|
201
|
+
* @param {Object} props
|
|
202
|
+
*
|
|
203
|
+
* @return {WPElement} Padding edit element.
|
|
204
|
+
*/
|
|
205
|
+
export function PositionEdit( props ) {
|
|
206
|
+
const {
|
|
207
|
+
attributes: { style = {} },
|
|
208
|
+
name: blockName,
|
|
209
|
+
setAttributes,
|
|
210
|
+
} = props;
|
|
211
|
+
|
|
212
|
+
const allowFixed = hasFixedPositionSupport( blockName );
|
|
213
|
+
const allowSticky = hasStickyPositionSupport( blockName );
|
|
214
|
+
const value = style?.position?.type;
|
|
215
|
+
|
|
216
|
+
const options = useMemo( () => {
|
|
217
|
+
const availableOptions = [ DEFAULT_OPTION ];
|
|
218
|
+
if ( allowSticky || value === STICKY_OPTION.value ) {
|
|
219
|
+
availableOptions.push( STICKY_OPTION );
|
|
220
|
+
}
|
|
221
|
+
if ( allowFixed || value === FIXED_OPTION.value ) {
|
|
222
|
+
availableOptions.push( FIXED_OPTION );
|
|
223
|
+
}
|
|
224
|
+
return availableOptions;
|
|
225
|
+
}, [ allowFixed, allowSticky, value ] );
|
|
226
|
+
|
|
227
|
+
const onChangeType = ( next ) => {
|
|
228
|
+
// For now, use a hard-coded `0px` value for the position.
|
|
229
|
+
// `0px` is preferred over `0` as it can be used in `calc()` functions.
|
|
230
|
+
// In the future, it could be useful to allow for an offset value.
|
|
231
|
+
const placementValue = '0px';
|
|
232
|
+
|
|
233
|
+
const newStyle = {
|
|
234
|
+
...style,
|
|
235
|
+
position: {
|
|
236
|
+
...style?.position,
|
|
237
|
+
type: next,
|
|
238
|
+
top:
|
|
239
|
+
next === 'sticky' || next === 'fixed'
|
|
240
|
+
? placementValue
|
|
241
|
+
: undefined,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
setAttributes( {
|
|
246
|
+
style: cleanEmptyObject( newStyle ),
|
|
247
|
+
} );
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const selectedOption = value
|
|
251
|
+
? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION
|
|
252
|
+
: DEFAULT_OPTION;
|
|
253
|
+
|
|
254
|
+
return Platform.select( {
|
|
255
|
+
web: (
|
|
256
|
+
<>
|
|
257
|
+
<BaseControl className="block-editor-hooks__position-selection">
|
|
258
|
+
<CustomSelectControl
|
|
259
|
+
__nextUnconstrainedWidth
|
|
260
|
+
__next36pxDefaultSize
|
|
261
|
+
className="block-editor-hooks__position-selection__select-control"
|
|
262
|
+
label={ __( 'Position' ) }
|
|
263
|
+
hideLabelFromVision
|
|
264
|
+
describedBy={ sprintf(
|
|
265
|
+
// translators: %s: Currently selected font size.
|
|
266
|
+
__( 'Currently selected position: %s' ),
|
|
267
|
+
selectedOption.name
|
|
268
|
+
) }
|
|
269
|
+
options={ options }
|
|
270
|
+
value={ selectedOption }
|
|
271
|
+
__experimentalShowSelectedHint
|
|
272
|
+
onChange={ ( { selectedItem } ) => {
|
|
273
|
+
onChangeType( selectedItem.value );
|
|
274
|
+
} }
|
|
275
|
+
size={ '__unstable-large' }
|
|
276
|
+
/>
|
|
277
|
+
</BaseControl>
|
|
278
|
+
</>
|
|
279
|
+
),
|
|
280
|
+
native: null,
|
|
281
|
+
} );
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Override the default edit UI to include position controls.
|
|
286
|
+
*
|
|
287
|
+
* @param {Function} BlockEdit Original component.
|
|
288
|
+
*
|
|
289
|
+
* @return {Function} Wrapped component.
|
|
290
|
+
*/
|
|
291
|
+
export const withInspectorControls = createHigherOrderComponent(
|
|
292
|
+
( BlockEdit ) => ( props ) => {
|
|
293
|
+
const { name: blockName } = props;
|
|
294
|
+
const positionSupport = hasBlockSupport(
|
|
295
|
+
blockName,
|
|
296
|
+
POSITION_SUPPORT_KEY
|
|
297
|
+
);
|
|
298
|
+
const showPositionControls =
|
|
299
|
+
positionSupport && ! useIsPositionDisabled( props );
|
|
300
|
+
|
|
301
|
+
return [
|
|
302
|
+
showPositionControls && (
|
|
303
|
+
<InspectorControls
|
|
304
|
+
key="position"
|
|
305
|
+
__experimentalGroup="position"
|
|
306
|
+
>
|
|
307
|
+
<PositionEdit { ...props } />
|
|
308
|
+
</InspectorControls>
|
|
309
|
+
),
|
|
310
|
+
<BlockEdit key="edit" { ...props } />,
|
|
311
|
+
];
|
|
312
|
+
},
|
|
313
|
+
'withInspectorControls'
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Override the default block element to add the position styles.
|
|
318
|
+
*
|
|
319
|
+
* @param {Function} BlockListBlock Original component.
|
|
320
|
+
*
|
|
321
|
+
* @return {Function} Wrapped component.
|
|
322
|
+
*/
|
|
323
|
+
export const withPositionStyles = createHigherOrderComponent(
|
|
324
|
+
( BlockListBlock ) => ( props ) => {
|
|
325
|
+
const { name, attributes } = props;
|
|
326
|
+
const hasPositionBlockSupport = hasBlockSupport(
|
|
327
|
+
name,
|
|
328
|
+
POSITION_SUPPORT_KEY
|
|
329
|
+
);
|
|
330
|
+
const allowPositionStyles =
|
|
331
|
+
hasPositionBlockSupport && ! useIsPositionDisabled( props );
|
|
332
|
+
|
|
333
|
+
const id = useInstanceId( BlockListBlock );
|
|
334
|
+
const element = useContext( BlockList.__unstableElementContext );
|
|
335
|
+
|
|
336
|
+
// Higher specificity to override defaults in editor UI.
|
|
337
|
+
const positionSelector = `.wp-container-${ id }.wp-container-${ id }`;
|
|
338
|
+
|
|
339
|
+
// Get CSS string for the current position values.
|
|
340
|
+
let css;
|
|
341
|
+
if ( allowPositionStyles ) {
|
|
342
|
+
css =
|
|
343
|
+
getPositionCSS( {
|
|
344
|
+
selector: positionSelector,
|
|
345
|
+
style: attributes?.style,
|
|
346
|
+
} ) || '';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Attach a `wp-container-` id-based class name.
|
|
350
|
+
const className = classnames( props?.className, {
|
|
351
|
+
[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.
|
|
352
|
+
} );
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<>
|
|
356
|
+
{ allowPositionStyles &&
|
|
357
|
+
element &&
|
|
358
|
+
!! css &&
|
|
359
|
+
createPortal( <style>{ css }</style>, element ) }
|
|
360
|
+
<BlockListBlock { ...props } className={ className } />
|
|
361
|
+
</>
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
addFilter(
|
|
367
|
+
'editor.BlockListBlock',
|
|
368
|
+
'core/editor/position/with-position-styles',
|
|
369
|
+
withPositionStyles
|
|
370
|
+
);
|
|
371
|
+
addFilter(
|
|
372
|
+
'editor.BlockEdit',
|
|
373
|
+
'core/editor/position/with-inspector-controls',
|
|
374
|
+
withInspectorControls
|
|
375
|
+
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.block-editor-hooks__position-selection__select-control {
|
|
2
|
+
.components-custom-select-control__hint {
|
|
3
|
+
display: none;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.block-editor-hooks__position-selection__select-control__option {
|
|
8
|
+
&.has-hint {
|
|
9
|
+
grid-template-columns: auto 30px;
|
|
10
|
+
line-height: $default-line-height;
|
|
11
|
+
margin-bottom: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.components-custom-select-control__item-hint {
|
|
15
|
+
grid-row: 2;
|
|
16
|
+
text-align: left;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
|
|
5
|
+
import { Platform } from '@wordpress/element';
|
|
6
|
+
|
|
7
|
+
const ALIGN_SUPPORT_KEY = 'align';
|
|
8
|
+
const ALIGN_WIDE_SUPPORT_KEY = 'alignWide';
|
|
9
|
+
const BORDER_SUPPORT_KEY = '__experimentalBorder';
|
|
10
|
+
const COLOR_SUPPORT_KEY = 'color';
|
|
11
|
+
const CUSTOM_CLASS_NAME_SUPPORT_KEY = 'customClassName';
|
|
12
|
+
const FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';
|
|
13
|
+
const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';
|
|
14
|
+
const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
|
|
15
|
+
/**
|
|
16
|
+
* Key within block settings' support array indicating support for font style.
|
|
17
|
+
*/
|
|
18
|
+
const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
|
|
19
|
+
/**
|
|
20
|
+
* Key within block settings' support array indicating support for font weight.
|
|
21
|
+
*/
|
|
22
|
+
const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';
|
|
23
|
+
/**
|
|
24
|
+
* Key within block settings' supports array indicating support for text
|
|
25
|
+
* decorations e.g. settings found in `block.json`.
|
|
26
|
+
*/
|
|
27
|
+
const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
|
|
28
|
+
/**
|
|
29
|
+
* Key within block settings' supports array indicating support for text
|
|
30
|
+
* transforms e.g. settings found in `block.json`.
|
|
31
|
+
*/
|
|
32
|
+
const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
|
|
33
|
+
/**
|
|
34
|
+
* Key within block settings' supports array indicating support for letter-spacing
|
|
35
|
+
* e.g. settings found in `block.json`.
|
|
36
|
+
*/
|
|
37
|
+
const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
|
|
38
|
+
const LAYOUT_SUPPORT_KEY = '__experimentalLayout';
|
|
39
|
+
const TYPOGRAPHY_SUPPORT_KEYS = [
|
|
40
|
+
LINE_HEIGHT_SUPPORT_KEY,
|
|
41
|
+
FONT_SIZE_SUPPORT_KEY,
|
|
42
|
+
FONT_STYLE_SUPPORT_KEY,
|
|
43
|
+
FONT_WEIGHT_SUPPORT_KEY,
|
|
44
|
+
FONT_FAMILY_SUPPORT_KEY,
|
|
45
|
+
TEXT_DECORATION_SUPPORT_KEY,
|
|
46
|
+
TEXT_TRANSFORM_SUPPORT_KEY,
|
|
47
|
+
LETTER_SPACING_SUPPORT_KEY,
|
|
48
|
+
];
|
|
49
|
+
const SPACING_SUPPORT_KEY = 'spacing';
|
|
50
|
+
const styleSupportKeys = [
|
|
51
|
+
...TYPOGRAPHY_SUPPORT_KEYS,
|
|
52
|
+
BORDER_SUPPORT_KEY,
|
|
53
|
+
COLOR_SUPPORT_KEY,
|
|
54
|
+
SPACING_SUPPORT_KEY,
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns true if the block defines support for align.
|
|
59
|
+
*
|
|
60
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
61
|
+
* @return {boolean} Whether the block supports the feature.
|
|
62
|
+
*/
|
|
63
|
+
export const hasAlignSupport = ( nameOrType ) =>
|
|
64
|
+
hasBlockSupport( nameOrType, ALIGN_SUPPORT_KEY );
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns the block support value for align, if defined.
|
|
68
|
+
*
|
|
69
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
70
|
+
* @return {unknown} The block support value.
|
|
71
|
+
*/
|
|
72
|
+
export const getAlignSupport = ( nameOrType ) =>
|
|
73
|
+
getBlockSupport( nameOrType, ALIGN_SUPPORT_KEY );
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns true if the block defines support for align wide.
|
|
77
|
+
*
|
|
78
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
79
|
+
* @return {boolean} Whether the block supports the feature.
|
|
80
|
+
*/
|
|
81
|
+
export const hasAlignWideSupport = ( nameOrType ) =>
|
|
82
|
+
hasBlockSupport( nameOrType, ALIGN_WIDE_SUPPORT_KEY );
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the block support value for align wide, if defined.
|
|
86
|
+
*
|
|
87
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
88
|
+
* @return {unknown} The block support value.
|
|
89
|
+
*/
|
|
90
|
+
export const getAlignWideSupport = ( nameOrType ) =>
|
|
91
|
+
getBlockSupport( nameOrType, ALIGN_WIDE_SUPPORT_KEY );
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Determine whether there is block support for border properties.
|
|
95
|
+
*
|
|
96
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
97
|
+
* @param {string} feature Border feature to check support for.
|
|
98
|
+
*
|
|
99
|
+
* @return {boolean} Whether there is support.
|
|
100
|
+
*/
|
|
101
|
+
export function hasBorderSupport( nameOrType, feature = 'any' ) {
|
|
102
|
+
if ( Platform.OS !== 'web' ) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const support = getBlockSupport( nameOrType, BORDER_SUPPORT_KEY );
|
|
107
|
+
|
|
108
|
+
if ( support === true ) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if ( feature === 'any' ) {
|
|
113
|
+
return !! (
|
|
114
|
+
support?.color ||
|
|
115
|
+
support?.radius ||
|
|
116
|
+
support?.width ||
|
|
117
|
+
support?.style
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return !! support?.[ feature ];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get block support for border properties.
|
|
126
|
+
*
|
|
127
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
128
|
+
* @param {string} feature Border feature to get.
|
|
129
|
+
*
|
|
130
|
+
* @return {unknown} The block support.
|
|
131
|
+
*/
|
|
132
|
+
export const getBorderSupport = ( nameOrType, feature ) =>
|
|
133
|
+
getBlockSupport( nameOrType, [ BORDER_SUPPORT_KEY, feature ] );
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Returns true if the block defines support for color.
|
|
137
|
+
*
|
|
138
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
139
|
+
* @return {boolean} Whether the block supports the feature.
|
|
140
|
+
*/
|
|
141
|
+
export const hasColorSupport = ( nameOrType ) => {
|
|
142
|
+
const colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );
|
|
143
|
+
return (
|
|
144
|
+
colorSupport &&
|
|
145
|
+
( colorSupport.link === true ||
|
|
146
|
+
colorSupport.gradient === true ||
|
|
147
|
+
colorSupport.background !== false ||
|
|
148
|
+
colorSupport.text !== false )
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Returns true if the block defines support for link color.
|
|
154
|
+
*
|
|
155
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
156
|
+
* @return {boolean} Whether the block supports the feature.
|
|
157
|
+
*/
|
|
158
|
+
export const hasLinkColorSupport = ( nameOrType ) => {
|
|
159
|
+
if ( Platform.OS !== 'web' ) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
colorSupport !== null &&
|
|
167
|
+
typeof colorSupport === 'object' &&
|
|
168
|
+
!! colorSupport.link
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Returns true if the block defines support for gradient color.
|
|
174
|
+
*
|
|
175
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
176
|
+
* @return {boolean} Whether the block supports the feature.
|
|
177
|
+
*/
|
|
178
|
+
export const hasGradientSupport = ( nameOrType ) => {
|
|
179
|
+
const colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
colorSupport !== null &&
|
|
183
|
+
typeof colorSupport === 'object' &&
|
|
184
|
+
!! colorSupport.gradients
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Returns true if the block defines support for background color.
|
|
190
|
+
*
|
|
191
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
192
|
+
* @return {boolean} Whether the block supports the feature.
|
|
193
|
+
*/
|
|
194
|
+
export const hasBackgroundColorSupport = ( nameOrType ) => {
|
|
195
|
+
const colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );
|
|
196
|
+
|
|
197
|
+
return colorSupport && colorSupport.background !== false;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns true if the block defines support for background color.
|
|
202
|
+
*
|
|
203
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
204
|
+
* @return {boolean} Whether the block supports the feature.
|
|
205
|
+
*/
|
|
206
|
+
export const hasTextColorSupport = ( nameOrType ) => {
|
|
207
|
+
const colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );
|
|
208
|
+
|
|
209
|
+
return colorSupport && colorSupport.text !== false;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Get block support for color properties.
|
|
214
|
+
*
|
|
215
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
216
|
+
* @param {string} feature Color feature to get.
|
|
217
|
+
*
|
|
218
|
+
* @return {unknown} The block support.
|
|
219
|
+
*/
|
|
220
|
+
export const getColorSupport = ( nameOrType, feature ) =>
|
|
221
|
+
getBlockSupport( nameOrType, [ COLOR_SUPPORT_KEY, feature ] );
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Returns true if the block defines support for custom class name.
|
|
225
|
+
*
|
|
226
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
227
|
+
* @return {boolean} Whether the block supports the feature.
|
|
228
|
+
*/
|
|
229
|
+
export const hasCustomClassNameSupport = ( nameOrType ) =>
|
|
230
|
+
hasBlockSupport( nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true );
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Returns the block support value for custom class name, if defined.
|
|
234
|
+
*
|
|
235
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
236
|
+
* @return {unknown} The block support value.
|
|
237
|
+
*/
|
|
238
|
+
export const getCustomClassNameSupport = ( nameOrType ) =>
|
|
239
|
+
getBlockSupport( nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true );
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Returns true if the block defines support for font family.
|
|
243
|
+
*
|
|
244
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
245
|
+
* @return {boolean} Whether the block supports the feature.
|
|
246
|
+
*/
|
|
247
|
+
export const hasFontFamilySupport = ( nameOrType ) =>
|
|
248
|
+
hasBlockSupport( nameOrType, FONT_FAMILY_SUPPORT_KEY );
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Returns the block support value for font family, if defined.
|
|
252
|
+
*
|
|
253
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
254
|
+
* @return {unknown} The block support value.
|
|
255
|
+
*/
|
|
256
|
+
export const getFontFamilySupport = ( nameOrType ) =>
|
|
257
|
+
getBlockSupport( nameOrType, FONT_FAMILY_SUPPORT_KEY );
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Returns true if the block defines support for font size.
|
|
261
|
+
*
|
|
262
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
263
|
+
* @return {boolean} Whether the block supports the feature.
|
|
264
|
+
*/
|
|
265
|
+
export const hasFontSizeSupport = ( nameOrType ) =>
|
|
266
|
+
hasBlockSupport( nameOrType, FONT_SIZE_SUPPORT_KEY );
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Returns the block support value for font size, if defined.
|
|
270
|
+
*
|
|
271
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
272
|
+
* @return {unknown} The block support value.
|
|
273
|
+
*/
|
|
274
|
+
export const getFontSizeSupport = ( nameOrType ) =>
|
|
275
|
+
getBlockSupport( nameOrType, FONT_SIZE_SUPPORT_KEY );
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Returns true if the block defines support for layout.
|
|
279
|
+
*
|
|
280
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
281
|
+
* @return {boolean} Whether the block supports the feature.
|
|
282
|
+
*/
|
|
283
|
+
export const hasLayoutSupport = ( nameOrType ) =>
|
|
284
|
+
hasBlockSupport( nameOrType, LAYOUT_SUPPORT_KEY );
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Returns the block support value for layout, if defined.
|
|
288
|
+
*
|
|
289
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
290
|
+
* @return {unknown} The block support value.
|
|
291
|
+
*/
|
|
292
|
+
export const getLayoutSupport = ( nameOrType ) =>
|
|
293
|
+
getBlockSupport( nameOrType, LAYOUT_SUPPORT_KEY );
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns true if the block defines support for style.
|
|
297
|
+
*
|
|
298
|
+
* @param {string|Object} nameOrType Block name or type object.
|
|
299
|
+
* @return {boolean} Whether the block supports the feature.
|
|
300
|
+
*/
|
|
301
|
+
export const hasStyleSupport = ( nameOrType ) =>
|
|
302
|
+
styleSupportKeys.some( ( key ) => hasBlockSupport( nameOrType, key ) );
|