@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,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.PositionEdit = PositionEdit;
|
|
9
|
+
exports.getPositionCSS = getPositionCSS;
|
|
10
|
+
exports.hasFixedPositionSupport = hasFixedPositionSupport;
|
|
11
|
+
exports.hasPositionSupport = hasPositionSupport;
|
|
12
|
+
exports.hasPositionValue = hasPositionValue;
|
|
13
|
+
exports.hasStickyOrFixedPositionValue = hasStickyOrFixedPositionValue;
|
|
14
|
+
exports.hasStickyPositionSupport = hasStickyPositionSupport;
|
|
15
|
+
exports.resetPosition = resetPosition;
|
|
16
|
+
exports.useIsPositionDisabled = useIsPositionDisabled;
|
|
17
|
+
exports.withPositionStyles = exports.withInspectorControls = void 0;
|
|
18
|
+
|
|
19
|
+
var _element = require("@wordpress/element");
|
|
20
|
+
|
|
21
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
22
|
+
|
|
23
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
24
|
+
|
|
25
|
+
var _i18n = require("@wordpress/i18n");
|
|
26
|
+
|
|
27
|
+
var _blocks = require("@wordpress/blocks");
|
|
28
|
+
|
|
29
|
+
var _components = require("@wordpress/components");
|
|
30
|
+
|
|
31
|
+
var _compose = require("@wordpress/compose");
|
|
32
|
+
|
|
33
|
+
var _hooks = require("@wordpress/hooks");
|
|
34
|
+
|
|
35
|
+
var _blockList = _interopRequireDefault(require("../components/block-list"));
|
|
36
|
+
|
|
37
|
+
var _useSetting = _interopRequireDefault(require("../components/use-setting"));
|
|
38
|
+
|
|
39
|
+
var _inspectorControls = _interopRequireDefault(require("../components/inspector-controls"));
|
|
40
|
+
|
|
41
|
+
var _utils = require("./utils");
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* External dependencies
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* WordPress dependencies
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Internal dependencies
|
|
53
|
+
*/
|
|
54
|
+
const POSITION_SUPPORT_KEY = 'position';
|
|
55
|
+
const OPTION_CLASSNAME = 'block-editor-hooks__position-selection__select-control__option';
|
|
56
|
+
const DEFAULT_OPTION = {
|
|
57
|
+
key: 'default',
|
|
58
|
+
value: '',
|
|
59
|
+
name: (0, _i18n.__)('Default'),
|
|
60
|
+
className: OPTION_CLASSNAME
|
|
61
|
+
};
|
|
62
|
+
const STICKY_OPTION = {
|
|
63
|
+
key: 'sticky',
|
|
64
|
+
value: 'sticky',
|
|
65
|
+
name: (0, _i18n.__)('Sticky'),
|
|
66
|
+
className: OPTION_CLASSNAME,
|
|
67
|
+
__experimentalHint: (0, _i18n.__)('The block will stick to the top of the window instead of scrolling.')
|
|
68
|
+
};
|
|
69
|
+
const FIXED_OPTION = {
|
|
70
|
+
key: 'fixed',
|
|
71
|
+
value: 'fixed',
|
|
72
|
+
name: (0, _i18n.__)('Fixed'),
|
|
73
|
+
className: OPTION_CLASSNAME,
|
|
74
|
+
__experimentalHint: (0, _i18n.__)('The block will not move when the page is scrolled.')
|
|
75
|
+
};
|
|
76
|
+
const POSITION_SIDES = ['top', 'right', 'bottom', 'left'];
|
|
77
|
+
const VALID_POSITION_TYPES = ['sticky', 'fixed'];
|
|
78
|
+
/**
|
|
79
|
+
* Get calculated position CSS.
|
|
80
|
+
*
|
|
81
|
+
* @param {Object} props Component props.
|
|
82
|
+
* @param {string} props.selector Selector to use.
|
|
83
|
+
* @param {Object} props.style Style object.
|
|
84
|
+
* @return {string} The generated CSS rules.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
function getPositionCSS(_ref) {
|
|
88
|
+
let {
|
|
89
|
+
selector,
|
|
90
|
+
style
|
|
91
|
+
} = _ref;
|
|
92
|
+
let output = '';
|
|
93
|
+
const {
|
|
94
|
+
type: positionType
|
|
95
|
+
} = (style === null || style === void 0 ? void 0 : style.position) || {};
|
|
96
|
+
|
|
97
|
+
if (!VALID_POSITION_TYPES.includes(positionType)) {
|
|
98
|
+
return output;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
output += `${selector} {`;
|
|
102
|
+
output += `position: ${positionType};`;
|
|
103
|
+
POSITION_SIDES.forEach(side => {
|
|
104
|
+
var _style$position;
|
|
105
|
+
|
|
106
|
+
if ((style === null || style === void 0 ? void 0 : (_style$position = style.position) === null || _style$position === void 0 ? void 0 : _style$position[side]) !== undefined) {
|
|
107
|
+
output += `${side}: ${style.position[side]};`;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (positionType === 'sticky' || positionType === 'fixed') {
|
|
112
|
+
// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.
|
|
113
|
+
output += `z-index: 10`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
output += `}`;
|
|
117
|
+
return output;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Determines if there is sticky position support.
|
|
121
|
+
*
|
|
122
|
+
* @param {string|Object} blockType Block name or Block Type object.
|
|
123
|
+
*
|
|
124
|
+
* @return {boolean} Whether there is support.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
function hasStickyPositionSupport(blockType) {
|
|
129
|
+
const support = (0, _blocks.getBlockSupport)(blockType, POSITION_SUPPORT_KEY);
|
|
130
|
+
return !!(true === support || support !== null && support !== void 0 && support.sticky);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Determines if there is fixed position support.
|
|
134
|
+
*
|
|
135
|
+
* @param {string|Object} blockType Block name or Block Type object.
|
|
136
|
+
*
|
|
137
|
+
* @return {boolean} Whether there is support.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
function hasFixedPositionSupport(blockType) {
|
|
142
|
+
const support = (0, _blocks.getBlockSupport)(blockType, POSITION_SUPPORT_KEY);
|
|
143
|
+
return !!(true === support || support !== null && support !== void 0 && support.fixed);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Determines if there is position support.
|
|
147
|
+
*
|
|
148
|
+
* @param {string|Object} blockType Block name or Block Type object.
|
|
149
|
+
*
|
|
150
|
+
* @return {boolean} Whether there is support.
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
function hasPositionSupport(blockType) {
|
|
155
|
+
const support = (0, _blocks.getBlockSupport)(blockType, POSITION_SUPPORT_KEY);
|
|
156
|
+
return !!support;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Checks if there is a current value in the position block support attributes.
|
|
160
|
+
*
|
|
161
|
+
* @param {Object} props Block props.
|
|
162
|
+
* @return {boolean} Whether or not the block has a position value set.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
function hasPositionValue(props) {
|
|
167
|
+
var _props$attributes$sty, _props$attributes$sty2;
|
|
168
|
+
|
|
169
|
+
return ((_props$attributes$sty = props.attributes.style) === null || _props$attributes$sty === void 0 ? void 0 : (_props$attributes$sty2 = _props$attributes$sty.position) === null || _props$attributes$sty2 === void 0 ? void 0 : _props$attributes$sty2.type) !== undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Checks if the block is currently set to a sticky or fixed position.
|
|
173
|
+
* This check is helpful for determining how to position block toolbars or other elements.
|
|
174
|
+
*
|
|
175
|
+
* @param {Object} attributes Block attributes.
|
|
176
|
+
* @return {boolean} Whether or not the block is set to a sticky or fixed position.
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
function hasStickyOrFixedPositionValue(attributes) {
|
|
181
|
+
var _attributes$style, _attributes$style$pos;
|
|
182
|
+
|
|
183
|
+
const positionType = (_attributes$style = attributes.style) === null || _attributes$style === void 0 ? void 0 : (_attributes$style$pos = _attributes$style.position) === null || _attributes$style$pos === void 0 ? void 0 : _attributes$style$pos.type;
|
|
184
|
+
return positionType === 'sticky' || positionType === 'fixed';
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Resets the position block support attributes. This can be used when disabling
|
|
188
|
+
* the position support controls for a block via a `ToolsPanel`.
|
|
189
|
+
*
|
|
190
|
+
* @param {Object} props Block props.
|
|
191
|
+
* @param {Object} props.attributes Block's attributes.
|
|
192
|
+
* @param {Object} props.setAttributes Function to set block's attributes.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
function resetPosition(_ref2) {
|
|
197
|
+
let {
|
|
198
|
+
attributes = {},
|
|
199
|
+
setAttributes
|
|
200
|
+
} = _ref2;
|
|
201
|
+
const {
|
|
202
|
+
style = {}
|
|
203
|
+
} = attributes;
|
|
204
|
+
setAttributes({
|
|
205
|
+
style: (0, _utils.cleanEmptyObject)({ ...style,
|
|
206
|
+
position: { ...(style === null || style === void 0 ? void 0 : style.position),
|
|
207
|
+
type: undefined,
|
|
208
|
+
top: undefined,
|
|
209
|
+
right: undefined,
|
|
210
|
+
bottom: undefined,
|
|
211
|
+
left: undefined
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Custom hook that checks if position settings have been disabled.
|
|
218
|
+
*
|
|
219
|
+
* @param {string} name The name of the block.
|
|
220
|
+
*
|
|
221
|
+
* @return {boolean} Whether padding setting is disabled.
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
function useIsPositionDisabled() {
|
|
226
|
+
let {
|
|
227
|
+
name: blockName
|
|
228
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
229
|
+
const allowFixed = (0, _useSetting.default)('position.fixed');
|
|
230
|
+
const allowSticky = (0, _useSetting.default)('position.sticky');
|
|
231
|
+
const isDisabled = !allowFixed && !allowSticky;
|
|
232
|
+
return !hasPositionSupport(blockName) || isDisabled;
|
|
233
|
+
}
|
|
234
|
+
/*
|
|
235
|
+
* Position controls to be rendered in an inspector control panel.
|
|
236
|
+
*
|
|
237
|
+
* @param {Object} props
|
|
238
|
+
*
|
|
239
|
+
* @return {WPElement} Padding edit element.
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
function PositionEdit(props) {
|
|
244
|
+
var _style$position2;
|
|
245
|
+
|
|
246
|
+
const {
|
|
247
|
+
attributes: {
|
|
248
|
+
style = {}
|
|
249
|
+
},
|
|
250
|
+
name: blockName,
|
|
251
|
+
setAttributes
|
|
252
|
+
} = props;
|
|
253
|
+
const allowFixed = hasFixedPositionSupport(blockName);
|
|
254
|
+
const allowSticky = hasStickyPositionSupport(blockName);
|
|
255
|
+
const value = style === null || style === void 0 ? void 0 : (_style$position2 = style.position) === null || _style$position2 === void 0 ? void 0 : _style$position2.type;
|
|
256
|
+
const options = (0, _element.useMemo)(() => {
|
|
257
|
+
const availableOptions = [DEFAULT_OPTION];
|
|
258
|
+
|
|
259
|
+
if (allowSticky || value === STICKY_OPTION.value) {
|
|
260
|
+
availableOptions.push(STICKY_OPTION);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (allowFixed || value === FIXED_OPTION.value) {
|
|
264
|
+
availableOptions.push(FIXED_OPTION);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return availableOptions;
|
|
268
|
+
}, [allowFixed, allowSticky, value]);
|
|
269
|
+
|
|
270
|
+
const onChangeType = next => {
|
|
271
|
+
// For now, use a hard-coded `0px` value for the position.
|
|
272
|
+
// `0px` is preferred over `0` as it can be used in `calc()` functions.
|
|
273
|
+
// In the future, it could be useful to allow for an offset value.
|
|
274
|
+
const placementValue = '0px';
|
|
275
|
+
const newStyle = { ...style,
|
|
276
|
+
position: { ...(style === null || style === void 0 ? void 0 : style.position),
|
|
277
|
+
type: next,
|
|
278
|
+
top: next === 'sticky' || next === 'fixed' ? placementValue : undefined
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
setAttributes({
|
|
282
|
+
style: (0, _utils.cleanEmptyObject)(newStyle)
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const selectedOption = value ? options.find(option => option.value === value) || DEFAULT_OPTION : DEFAULT_OPTION;
|
|
287
|
+
return _element.Platform.select({
|
|
288
|
+
web: (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_components.BaseControl, {
|
|
289
|
+
className: "block-editor-hooks__position-selection"
|
|
290
|
+
}, (0, _element.createElement)(_components.CustomSelectControl, {
|
|
291
|
+
__nextUnconstrainedWidth: true,
|
|
292
|
+
__next36pxDefaultSize: true,
|
|
293
|
+
className: "block-editor-hooks__position-selection__select-control",
|
|
294
|
+
label: (0, _i18n.__)('Position'),
|
|
295
|
+
hideLabelFromVision: true,
|
|
296
|
+
describedBy: (0, _i18n.sprintf)( // translators: %s: Currently selected font size.
|
|
297
|
+
(0, _i18n.__)('Currently selected position: %s'), selectedOption.name),
|
|
298
|
+
options: options,
|
|
299
|
+
value: selectedOption,
|
|
300
|
+
__experimentalShowSelectedHint: true,
|
|
301
|
+
onChange: _ref3 => {
|
|
302
|
+
let {
|
|
303
|
+
selectedItem
|
|
304
|
+
} = _ref3;
|
|
305
|
+
onChangeType(selectedItem.value);
|
|
306
|
+
},
|
|
307
|
+
size: '__unstable-large'
|
|
308
|
+
}))),
|
|
309
|
+
native: null
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Override the default edit UI to include position controls.
|
|
314
|
+
*
|
|
315
|
+
* @param {Function} BlockEdit Original component.
|
|
316
|
+
*
|
|
317
|
+
* @return {Function} Wrapped component.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
const withInspectorControls = (0, _compose.createHigherOrderComponent)(BlockEdit => props => {
|
|
322
|
+
const {
|
|
323
|
+
name: blockName
|
|
324
|
+
} = props;
|
|
325
|
+
const positionSupport = (0, _blocks.hasBlockSupport)(blockName, POSITION_SUPPORT_KEY);
|
|
326
|
+
const showPositionControls = positionSupport && !useIsPositionDisabled(props);
|
|
327
|
+
return [showPositionControls && (0, _element.createElement)(_inspectorControls.default, {
|
|
328
|
+
key: "position",
|
|
329
|
+
__experimentalGroup: "position"
|
|
330
|
+
}, (0, _element.createElement)(PositionEdit, props)), (0, _element.createElement)(BlockEdit, (0, _extends2.default)({
|
|
331
|
+
key: "edit"
|
|
332
|
+
}, props))];
|
|
333
|
+
}, 'withInspectorControls');
|
|
334
|
+
/**
|
|
335
|
+
* Override the default block element to add the position styles.
|
|
336
|
+
*
|
|
337
|
+
* @param {Function} BlockListBlock Original component.
|
|
338
|
+
*
|
|
339
|
+
* @return {Function} Wrapped component.
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
exports.withInspectorControls = withInspectorControls;
|
|
343
|
+
const withPositionStyles = (0, _compose.createHigherOrderComponent)(BlockListBlock => props => {
|
|
344
|
+
const {
|
|
345
|
+
name,
|
|
346
|
+
attributes
|
|
347
|
+
} = props;
|
|
348
|
+
const hasPositionBlockSupport = (0, _blocks.hasBlockSupport)(name, POSITION_SUPPORT_KEY);
|
|
349
|
+
const allowPositionStyles = hasPositionBlockSupport && !useIsPositionDisabled(props);
|
|
350
|
+
const id = (0, _compose.useInstanceId)(BlockListBlock);
|
|
351
|
+
const element = (0, _element.useContext)(_blockList.default.__unstableElementContext); // Higher specificity to override defaults in editor UI.
|
|
352
|
+
|
|
353
|
+
const positionSelector = `.wp-container-${id}.wp-container-${id}`; // Get CSS string for the current position values.
|
|
354
|
+
|
|
355
|
+
let css;
|
|
356
|
+
|
|
357
|
+
if (allowPositionStyles) {
|
|
358
|
+
css = getPositionCSS({
|
|
359
|
+
selector: positionSelector,
|
|
360
|
+
style: attributes === null || attributes === void 0 ? void 0 : attributes.style
|
|
361
|
+
}) || '';
|
|
362
|
+
} // Attach a `wp-container-` id-based class name.
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
const className = (0, _classnames.default)(props === null || props === void 0 ? void 0 : props.className, {
|
|
366
|
+
[`wp-container-${id}`]: allowPositionStyles && !!css // Only attach a container class if there is generated CSS to be attached.
|
|
367
|
+
|
|
368
|
+
});
|
|
369
|
+
return (0, _element.createElement)(_element.Fragment, null, allowPositionStyles && element && !!css && (0, _element.createPortal)((0, _element.createElement)("style", null, css), element), (0, _element.createElement)(BlockListBlock, (0, _extends2.default)({}, props, {
|
|
370
|
+
className: className
|
|
371
|
+
})));
|
|
372
|
+
});
|
|
373
|
+
exports.withPositionStyles = withPositionStyles;
|
|
374
|
+
(0, _hooks.addFilter)('editor.BlockListBlock', 'core/editor/position/with-position-styles', withPositionStyles);
|
|
375
|
+
(0, _hooks.addFilter)('editor.BlockEdit', 'core/editor/position/with-inspector-controls', withInspectorControls);
|
|
376
|
+
//# sourceMappingURL=position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/hooks/position.js"],"names":["POSITION_SUPPORT_KEY","OPTION_CLASSNAME","DEFAULT_OPTION","key","value","name","className","STICKY_OPTION","__experimentalHint","FIXED_OPTION","POSITION_SIDES","VALID_POSITION_TYPES","getPositionCSS","selector","style","output","type","positionType","position","includes","forEach","side","undefined","hasStickyPositionSupport","blockType","support","sticky","hasFixedPositionSupport","fixed","hasPositionSupport","hasPositionValue","props","attributes","hasStickyOrFixedPositionValue","resetPosition","setAttributes","top","right","bottom","left","useIsPositionDisabled","blockName","allowFixed","allowSticky","isDisabled","PositionEdit","options","availableOptions","push","onChangeType","next","placementValue","newStyle","selectedOption","find","option","Platform","select","web","selectedItem","native","withInspectorControls","BlockEdit","positionSupport","showPositionControls","withPositionStyles","BlockListBlock","hasPositionBlockSupport","allowPositionStyles","id","element","BlockList","__unstableElementContext","positionSelector","css"],"mappings":";;;;;;;;;;;;;;;;;;AAYA;;;;AATA;;A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EkB,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAElB;AAFJ,KAAF,CAAd,IAGO,EAJR;AAKA,GAvBiC,CAyBlC;;;AACA,QAAMR,SAAS,GAAG,yBAAYyB,KAAZ,aAAYA,KAAZ,uBAAYA,KAAK,CAAEzB,SAAnB,EAA8B;AAC/C,KAAG,gBAAgB+D,EAAI,EAAvB,GAA4BD,mBAAmB,IAAI,CAAC,CAAEM,GADP,CACY;;AADZ,GAA9B,CAAlB;AAIA,SACC,qDACGN,mBAAmB,IACpBE,OADC,IAED,CAAC,CAAEI,GAFF,IAGD,2BAAc,2CAASA,GAAT,CAAd,EAAsCJ,OAAtC,CAJF,EAKC,4BAAC,cAAD,6BAAqBvC,KAArB;AAA6B,IAAA,SAAS,EAAGzB;AAAzC,KALD,CADD;AASA,CAxCgC,CAA3B;;AA2CP,sBACC,uBADD,EAEC,2CAFD,EAGC2D,kBAHD;AAKA,sBACC,kBADD,EAEC,8CAFD,EAGCJ,qBAHD","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { BaseControl, CustomSelectControl } from '@wordpress/components';\nimport { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';\nimport {\n\tuseContext,\n\tuseMemo,\n\tcreatePortal,\n\tPlatform,\n} from '@wordpress/element';\nimport { addFilter } from '@wordpress/hooks';\n\n/**\n * Internal dependencies\n */\nimport BlockList from '../components/block-list';\nimport useSetting from '../components/use-setting';\nimport InspectorControls from '../components/inspector-controls';\nimport { cleanEmptyObject } from './utils';\n\nconst POSITION_SUPPORT_KEY = 'position';\n\nconst OPTION_CLASSNAME =\n\t'block-editor-hooks__position-selection__select-control__option';\n\nconst DEFAULT_OPTION = {\n\tkey: 'default',\n\tvalue: '',\n\tname: __( 'Default' ),\n\tclassName: OPTION_CLASSNAME,\n};\n\nconst STICKY_OPTION = {\n\tkey: 'sticky',\n\tvalue: 'sticky',\n\tname: __( 'Sticky' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will stick to the top of the window instead of scrolling.'\n\t),\n};\n\nconst FIXED_OPTION = {\n\tkey: 'fixed',\n\tvalue: 'fixed',\n\tname: __( 'Fixed' ),\n\tclassName: OPTION_CLASSNAME,\n\t__experimentalHint: __(\n\t\t'The block will not move when the page is scrolled.'\n\t),\n};\n\nconst POSITION_SIDES = [ 'top', 'right', 'bottom', 'left' ];\nconst VALID_POSITION_TYPES = [ 'sticky', 'fixed' ];\n\n/**\n * Get calculated position CSS.\n *\n * @param {Object} props Component props.\n * @param {string} props.selector Selector to use.\n * @param {Object} props.style Style object.\n * @return {string} The generated CSS rules.\n */\nexport function getPositionCSS( { selector, style } ) {\n\tlet output = '';\n\n\tconst { type: positionType } = style?.position || {};\n\n\tif ( ! VALID_POSITION_TYPES.includes( positionType ) ) {\n\t\treturn output;\n\t}\n\n\toutput += `${ selector } {`;\n\toutput += `position: ${ positionType };`;\n\n\tPOSITION_SIDES.forEach( ( side ) => {\n\t\tif ( style?.position?.[ side ] !== undefined ) {\n\t\t\toutput += `${ side }: ${ style.position[ side ] };`;\n\t\t}\n\t} );\n\n\tif ( positionType === 'sticky' || positionType === 'fixed' ) {\n\t\t// TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.\n\t\toutput += `z-index: 10`;\n\t}\n\toutput += `}`;\n\n\treturn output;\n}\n\n/**\n * Determines if there is sticky position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasStickyPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.sticky );\n}\n\n/**\n * Determines if there is fixed position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasFixedPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! ( true === support || support?.fixed );\n}\n\n/**\n * Determines if there is position support.\n *\n * @param {string|Object} blockType Block name or Block Type object.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasPositionSupport( blockType ) {\n\tconst support = getBlockSupport( blockType, POSITION_SUPPORT_KEY );\n\treturn !! support;\n}\n\n/**\n * Checks if there is a current value in the position block support attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a position value set.\n */\nexport function hasPositionValue( props ) {\n\treturn props.attributes.style?.position?.type !== undefined;\n}\n\n/**\n * Checks if the block is currently set to a sticky or fixed position.\n * This check is helpful for determining how to position block toolbars or other elements.\n *\n * @param {Object} attributes Block attributes.\n * @return {boolean} Whether or not the block is set to a sticky or fixed position.\n */\nexport function hasStickyOrFixedPositionValue( attributes ) {\n\tconst positionType = attributes.style?.position?.type;\n\treturn positionType === 'sticky' || positionType === 'fixed';\n}\n\n/**\n * Resets the position block support attributes. This can be used when disabling\n * the position support controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetPosition( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: undefined,\n\t\t\t\ttop: undefined,\n\t\t\t\tright: undefined,\n\t\t\t\tbottom: undefined,\n\t\t\t\tleft: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\n/**\n * Custom hook that checks if position settings have been disabled.\n *\n * @param {string} name The name of the block.\n *\n * @return {boolean} Whether padding setting is disabled.\n */\nexport function useIsPositionDisabled( { name: blockName } = {} ) {\n\tconst allowFixed = useSetting( 'position.fixed' );\n\tconst allowSticky = useSetting( 'position.sticky' );\n\tconst isDisabled = ! allowFixed && ! allowSticky;\n\n\treturn ! hasPositionSupport( blockName ) || isDisabled;\n}\n\n/*\n * Position controls to be rendered in an inspector control panel.\n *\n * @param {Object} props\n *\n * @return {WPElement} Padding edit element.\n */\nexport function PositionEdit( props ) {\n\tconst {\n\t\tattributes: { style = {} },\n\t\tname: blockName,\n\t\tsetAttributes,\n\t} = props;\n\n\tconst allowFixed = hasFixedPositionSupport( blockName );\n\tconst allowSticky = hasStickyPositionSupport( blockName );\n\tconst value = style?.position?.type;\n\n\tconst options = useMemo( () => {\n\t\tconst availableOptions = [ DEFAULT_OPTION ];\n\t\tif ( allowSticky || value === STICKY_OPTION.value ) {\n\t\t\tavailableOptions.push( STICKY_OPTION );\n\t\t}\n\t\tif ( allowFixed || value === FIXED_OPTION.value ) {\n\t\t\tavailableOptions.push( FIXED_OPTION );\n\t\t}\n\t\treturn availableOptions;\n\t}, [ allowFixed, allowSticky, value ] );\n\n\tconst onChangeType = ( next ) => {\n\t\t// For now, use a hard-coded `0px` value for the position.\n\t\t// `0px` is preferred over `0` as it can be used in `calc()` functions.\n\t\t// In the future, it could be useful to allow for an offset value.\n\t\tconst placementValue = '0px';\n\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tposition: {\n\t\t\t\t...style?.position,\n\t\t\t\ttype: next,\n\t\t\t\ttop:\n\t\t\t\t\tnext === 'sticky' || next === 'fixed'\n\t\t\t\t\t\t? placementValue\n\t\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t} );\n\t};\n\n\tconst selectedOption = value\n\t\t? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION\n\t\t: DEFAULT_OPTION;\n\n\treturn Platform.select( {\n\t\tweb: (\n\t\t\t<>\n\t\t\t\t<BaseControl className=\"block-editor-hooks__position-selection\">\n\t\t\t\t\t<CustomSelectControl\n\t\t\t\t\t\t__nextUnconstrainedWidth\n\t\t\t\t\t\t__next36pxDefaultSize\n\t\t\t\t\t\tclassName=\"block-editor-hooks__position-selection__select-control\"\n\t\t\t\t\t\tlabel={ __( 'Position' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\tdescribedBy={ sprintf(\n\t\t\t\t\t\t\t// translators: %s: Currently selected font size.\n\t\t\t\t\t\t\t__( 'Currently selected position: %s' ),\n\t\t\t\t\t\t\tselectedOption.name\n\t\t\t\t\t\t) }\n\t\t\t\t\t\toptions={ options }\n\t\t\t\t\t\tvalue={ selectedOption }\n\t\t\t\t\t\t__experimentalShowSelectedHint\n\t\t\t\t\t\tonChange={ ( { selectedItem } ) => {\n\t\t\t\t\t\t\tonChangeType( selectedItem.value );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tsize={ '__unstable-large' }\n\t\t\t\t\t/>\n\t\t\t\t</BaseControl>\n\t\t\t</>\n\t\t),\n\t\tnative: null,\n\t} );\n}\n\n/**\n * Override the default edit UI to include position controls.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withInspectorControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name: blockName } = props;\n\t\tconst positionSupport = hasBlockSupport(\n\t\t\tblockName,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst showPositionControls =\n\t\t\tpositionSupport && ! useIsPositionDisabled( props );\n\n\t\treturn [\n\t\t\tshowPositionControls && (\n\t\t\t\t<InspectorControls\n\t\t\t\t\tkey=\"position\"\n\t\t\t\t\t__experimentalGroup=\"position\"\n\t\t\t\t>\n\t\t\t\t\t<PositionEdit { ...props } />\n\t\t\t\t</InspectorControls>\n\t\t\t),\n\t\t\t<BlockEdit key=\"edit\" { ...props } />,\n\t\t];\n\t},\n\t'withInspectorControls'\n);\n\n/**\n * Override the default block element to add the position styles.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withPositionStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst hasPositionBlockSupport = hasBlockSupport(\n\t\t\tname,\n\t\t\tPOSITION_SUPPORT_KEY\n\t\t);\n\t\tconst allowPositionStyles =\n\t\t\thasPositionBlockSupport && ! useIsPositionDisabled( props );\n\n\t\tconst id = useInstanceId( BlockListBlock );\n\t\tconst element = useContext( BlockList.__unstableElementContext );\n\n\t\t// Higher specificity to override defaults in editor UI.\n\t\tconst positionSelector = `.wp-container-${ id }.wp-container-${ id }`;\n\n\t\t// Get CSS string for the current position values.\n\t\tlet css;\n\t\tif ( allowPositionStyles ) {\n\t\t\tcss =\n\t\t\t\tgetPositionCSS( {\n\t\t\t\t\tselector: positionSelector,\n\t\t\t\t\tstyle: attributes?.style,\n\t\t\t\t} ) || '';\n\t\t}\n\n\t\t// Attach a `wp-container-` id-based class name.\n\t\tconst className = classnames( props?.className, {\n\t\t\t[ `wp-container-${ id }` ]: allowPositionStyles && !! css, // Only attach a container class if there is generated CSS to be attached.\n\t\t} );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ allowPositionStyles &&\n\t\t\t\t\telement &&\n\t\t\t\t\t!! css &&\n\t\t\t\t\tcreatePortal( <style>{ css }</style>, element ) }\n\t\t\t\t<BlockListBlock { ...props } className={ className } />\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/position/with-position-styles',\n\twithPositionStyles\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/position/with-inspector-controls',\n\twithInspectorControls\n);\n"]}
|