@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.
Files changed (201) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE.md +1 -1
  3. package/build/components/block-actions/index.js +9 -0
  4. package/build/components/block-actions/index.js.map +1 -1
  5. package/build/components/block-inspector/index.js +4 -2
  6. package/build/components/block-inspector/index.js.map +1 -1
  7. package/build/components/block-preview/auto.js +1 -4
  8. package/build/components/block-preview/auto.js.map +1 -1
  9. package/build/components/block-settings-menu/block-settings-dropdown.js +4 -1
  10. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  11. package/build/components/block-styles/index.js +3 -1
  12. package/build/components/block-styles/index.js.map +1 -1
  13. package/build/components/block-tools/use-block-toolbar-popover-props.js +43 -10
  14. package/build/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
  15. package/build/components/default-style-picker/index.js +1 -0
  16. package/build/components/default-style-picker/index.js.map +1 -1
  17. package/build/components/font-sizes/with-font-sizes.js +5 -8
  18. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  19. package/build/components/iframe/index.js +37 -8
  20. package/build/components/iframe/index.js.map +1 -1
  21. package/build/components/iframe/use-compatibility-styles.js +6 -1
  22. package/build/components/iframe/use-compatibility-styles.js.map +1 -1
  23. package/build/components/image-size-control/index.js +1 -0
  24. package/build/components/image-size-control/index.js.map +1 -1
  25. package/build/components/inserter/block-patterns-tab.js +4 -4
  26. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  27. package/build/components/inserter/index.js +3 -2
  28. package/build/components/inserter/index.js.map +1 -1
  29. package/build/components/inserter/menu.js +11 -5
  30. package/build/components/inserter/menu.js.map +1 -1
  31. package/build/components/inspector-controls/groups.js +3 -1
  32. package/build/components/inspector-controls/groups.js.map +1 -1
  33. package/build/components/inspector-controls-tabs/position-controls-panel.js +46 -0
  34. package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
  35. package/build/components/inspector-controls-tabs/settings-tab.js +3 -1
  36. package/build/components/inspector-controls-tabs/settings-tab.js.map +1 -1
  37. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -11
  38. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  39. package/build/components/link-control/search-input.js +1 -0
  40. package/build/components/link-control/search-input.js.map +1 -1
  41. package/build/components/off-canvas-editor/appender.js +2 -38
  42. package/build/components/off-canvas-editor/appender.js.map +1 -1
  43. package/build/components/off-canvas-editor/block-contents.js +38 -5
  44. package/build/components/off-canvas-editor/block-contents.js.map +1 -1
  45. package/build/components/off-canvas-editor/block.js +7 -25
  46. package/build/components/off-canvas-editor/block.js.map +1 -1
  47. package/build/components/off-canvas-editor/index.js +7 -4
  48. package/build/components/off-canvas-editor/index.js.map +1 -1
  49. package/build/components/provider/index.js +3 -1
  50. package/build/components/provider/index.js.map +1 -1
  51. package/build/components/rich-text/use-enter.js +4 -5
  52. package/build/components/rich-text/use-enter.js.map +1 -1
  53. package/build/components/url-input/button.js +1 -0
  54. package/build/components/url-input/button.js.map +1 -1
  55. package/build/components/url-input/index.js +15 -1
  56. package/build/components/url-input/index.js.map +1 -1
  57. package/build/components/url-popover/link-editor.js +1 -0
  58. package/build/components/url-popover/link-editor.js.map +1 -1
  59. package/build/components/use-paste-styles/index.js +188 -0
  60. package/build/components/use-paste-styles/index.js.map +1 -0
  61. package/build/components/writing-flow/use-arrow-nav.js +22 -29
  62. package/build/components/writing-flow/use-arrow-nav.js.map +1 -1
  63. package/build/hooks/index.js +2 -0
  64. package/build/hooks/index.js.map +1 -1
  65. package/build/hooks/metadata.js +1 -1
  66. package/build/hooks/metadata.js.map +1 -1
  67. package/build/hooks/position.js +376 -0
  68. package/build/hooks/position.js.map +1 -0
  69. package/build/hooks/supports.js +328 -0
  70. package/build/hooks/supports.js.map +1 -0
  71. package/build/store/reducer.js +6 -2
  72. package/build/store/reducer.js.map +1 -1
  73. package/build/store/selectors.js +8 -6
  74. package/build/store/selectors.js.map +1 -1
  75. package/build-module/components/block-actions/index.js +6 -0
  76. package/build-module/components/block-actions/index.js.map +1 -1
  77. package/build-module/components/block-inspector/index.js +3 -2
  78. package/build-module/components/block-inspector/index.js.map +1 -1
  79. package/build-module/components/block-preview/auto.js +1 -4
  80. package/build-module/components/block-preview/auto.js.map +1 -1
  81. package/build-module/components/block-settings-menu/block-settings-dropdown.js +4 -1
  82. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  83. package/build-module/components/block-styles/index.js +2 -1
  84. package/build-module/components/block-styles/index.js.map +1 -1
  85. package/build-module/components/block-tools/use-block-toolbar-popover-props.js +42 -11
  86. package/build-module/components/block-tools/use-block-toolbar-popover-props.js.map +1 -1
  87. package/build-module/components/default-style-picker/index.js +1 -0
  88. package/build-module/components/default-style-picker/index.js.map +1 -1
  89. package/build-module/components/font-sizes/with-font-sizes.js +5 -7
  90. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  91. package/build-module/components/iframe/index.js +36 -9
  92. package/build-module/components/iframe/index.js.map +1 -1
  93. package/build-module/components/iframe/use-compatibility-styles.js +6 -1
  94. package/build-module/components/iframe/use-compatibility-styles.js.map +1 -1
  95. package/build-module/components/image-size-control/index.js +1 -0
  96. package/build-module/components/image-size-control/index.js.map +1 -1
  97. package/build-module/components/inserter/block-patterns-tab.js +4 -4
  98. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  99. package/build-module/components/inserter/index.js +3 -2
  100. package/build-module/components/inserter/index.js.map +1 -1
  101. package/build-module/components/inserter/menu.js +11 -5
  102. package/build-module/components/inserter/menu.js.map +1 -1
  103. package/build-module/components/inspector-controls/groups.js +3 -1
  104. package/build-module/components/inspector-controls/groups.js.map +1 -1
  105. package/build-module/components/inspector-controls-tabs/position-controls-panel.js +33 -0
  106. package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -0
  107. package/build-module/components/inspector-controls-tabs/settings-tab.js +2 -1
  108. package/build-module/components/inspector-controls-tabs/settings-tab.js.map +1 -1
  109. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +4 -11
  110. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  111. package/build-module/components/link-control/search-input.js +1 -0
  112. package/build-module/components/link-control/search-input.js.map +1 -1
  113. package/build-module/components/off-canvas-editor/appender.js +3 -36
  114. package/build-module/components/off-canvas-editor/appender.js.map +1 -1
  115. package/build-module/components/off-canvas-editor/block-contents.js +37 -7
  116. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
  117. package/build-module/components/off-canvas-editor/block.js +9 -27
  118. package/build-module/components/off-canvas-editor/block.js.map +1 -1
  119. package/build-module/components/off-canvas-editor/index.js +7 -4
  120. package/build-module/components/off-canvas-editor/index.js.map +1 -1
  121. package/build-module/components/provider/index.js +3 -1
  122. package/build-module/components/provider/index.js.map +1 -1
  123. package/build-module/components/rich-text/use-enter.js +4 -5
  124. package/build-module/components/rich-text/use-enter.js.map +1 -1
  125. package/build-module/components/url-input/button.js +1 -0
  126. package/build-module/components/url-input/button.js.map +1 -1
  127. package/build-module/components/url-input/index.js +14 -1
  128. package/build-module/components/url-input/index.js.map +1 -1
  129. package/build-module/components/url-popover/link-editor.js +1 -0
  130. package/build-module/components/url-popover/link-editor.js.map +1 -1
  131. package/build-module/components/use-paste-styles/index.js +174 -0
  132. package/build-module/components/use-paste-styles/index.js.map +1 -0
  133. package/build-module/components/writing-flow/use-arrow-nav.js +22 -29
  134. package/build-module/components/writing-flow/use-arrow-nav.js.map +1 -1
  135. package/build-module/hooks/index.js +1 -0
  136. package/build-module/hooks/index.js.map +1 -1
  137. package/build-module/hooks/metadata.js +1 -1
  138. package/build-module/hooks/metadata.js.map +1 -1
  139. package/build-module/hooks/position.js +337 -0
  140. package/build-module/hooks/position.js.map +1 -0
  141. package/build-module/hooks/supports.js +257 -0
  142. package/build-module/hooks/supports.js.map +1 -0
  143. package/build-module/store/reducer.js +6 -2
  144. package/build-module/store/reducer.js.map +1 -1
  145. package/build-module/store/selectors.js +7 -5
  146. package/build-module/store/selectors.js.map +1 -1
  147. package/build-style/content-rtl.css +57 -0
  148. package/build-style/content.css +57 -0
  149. package/build-style/style-rtl.css +27 -58
  150. package/build-style/style.css +27 -58
  151. package/package.json +29 -29
  152. package/src/components/block-actions/index.js +5 -0
  153. package/src/components/block-inspector/index.js +3 -1
  154. package/src/components/block-preview/auto.js +2 -4
  155. package/src/components/block-settings-menu/block-settings-dropdown.js +4 -0
  156. package/src/components/block-styles/index.js +4 -1
  157. package/src/components/block-tools/use-block-toolbar-popover-props.js +68 -12
  158. package/src/components/button-block-appender/{style.scss → content.scss} +0 -0
  159. package/src/components/default-style-picker/index.js +1 -0
  160. package/src/components/font-sizes/with-font-sizes.js +33 -33
  161. package/src/components/iframe/index.js +52 -19
  162. package/src/components/iframe/use-compatibility-styles.js +6 -0
  163. package/src/components/image-size-control/index.js +1 -0
  164. package/src/components/inserter/block-patterns-tab.js +7 -4
  165. package/src/components/inserter/index.js +46 -41
  166. package/src/components/inserter/menu.js +8 -4
  167. package/src/components/inserter/test/__snapshots__/index.native.js.snap +117 -0
  168. package/src/components/inserter/test/index.native.js +255 -1
  169. package/src/components/inspector-controls/groups.js +2 -0
  170. package/src/components/inspector-controls-tabs/position-controls-panel.js +37 -0
  171. package/src/components/inspector-controls-tabs/settings-tab.js +2 -0
  172. package/src/components/inspector-controls-tabs/style.scss +15 -0
  173. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -8
  174. package/src/components/link-control/search-input.js +1 -0
  175. package/src/components/link-control/style.scss +1 -0
  176. package/src/components/list-view/style.scss +13 -3
  177. package/src/components/off-canvas-editor/appender.js +2 -52
  178. package/src/components/off-canvas-editor/block-contents.js +84 -23
  179. package/src/components/off-canvas-editor/block.js +28 -60
  180. package/src/components/off-canvas-editor/index.js +12 -2
  181. package/src/components/provider/index.js +4 -1
  182. package/src/components/rich-text/use-enter.js +4 -4
  183. package/src/components/url-input/README.md +5 -0
  184. package/src/components/url-input/button.js +1 -0
  185. package/src/components/url-input/index.js +15 -1
  186. package/src/components/url-popover/link-editor.js +1 -0
  187. package/src/components/use-paste-styles/index.js +230 -0
  188. package/src/components/writing-flow/use-arrow-nav.js +20 -28
  189. package/src/content.scss +1 -0
  190. package/src/hooks/index.js +1 -0
  191. package/src/hooks/metadata.js +1 -2
  192. package/src/hooks/position.js +375 -0
  193. package/src/hooks/position.scss +18 -0
  194. package/src/hooks/supports.js +302 -0
  195. package/src/hooks/test/__snapshots__/align.native.js.snap +73 -0
  196. package/src/hooks/test/align.native.js +133 -0
  197. package/src/store/reducer.js +7 -2
  198. package/src/store/selectors.js +5 -5
  199. package/src/store/test/reducer.js +45 -3
  200. package/src/store/test/selectors.js +12 -9
  201. package/src/style.scss +2 -1
@@ -0,0 +1,337 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { createElement, Fragment } from "@wordpress/element";
3
+
4
+ /**
5
+ * External dependencies
6
+ */
7
+ import classnames from 'classnames';
8
+ /**
9
+ * WordPress dependencies
10
+ */
11
+
12
+ import { __, sprintf } from '@wordpress/i18n';
13
+ import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
14
+ import { BaseControl, CustomSelectControl } from '@wordpress/components';
15
+ import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
16
+ import { useContext, useMemo, createPortal, Platform } from '@wordpress/element';
17
+ import { addFilter } from '@wordpress/hooks';
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+
22
+ import BlockList from '../components/block-list';
23
+ import useSetting from '../components/use-setting';
24
+ import InspectorControls from '../components/inspector-controls';
25
+ import { cleanEmptyObject } from './utils';
26
+ const POSITION_SUPPORT_KEY = 'position';
27
+ const OPTION_CLASSNAME = 'block-editor-hooks__position-selection__select-control__option';
28
+ const DEFAULT_OPTION = {
29
+ key: 'default',
30
+ value: '',
31
+ name: __('Default'),
32
+ className: OPTION_CLASSNAME
33
+ };
34
+ const STICKY_OPTION = {
35
+ key: 'sticky',
36
+ value: 'sticky',
37
+ name: __('Sticky'),
38
+ className: OPTION_CLASSNAME,
39
+ __experimentalHint: __('The block will stick to the top of the window instead of scrolling.')
40
+ };
41
+ const FIXED_OPTION = {
42
+ key: 'fixed',
43
+ value: 'fixed',
44
+ name: __('Fixed'),
45
+ className: OPTION_CLASSNAME,
46
+ __experimentalHint: __('The block will not move when the page is scrolled.')
47
+ };
48
+ const POSITION_SIDES = ['top', 'right', 'bottom', 'left'];
49
+ const VALID_POSITION_TYPES = ['sticky', 'fixed'];
50
+ /**
51
+ * Get calculated position CSS.
52
+ *
53
+ * @param {Object} props Component props.
54
+ * @param {string} props.selector Selector to use.
55
+ * @param {Object} props.style Style object.
56
+ * @return {string} The generated CSS rules.
57
+ */
58
+
59
+ export function getPositionCSS(_ref) {
60
+ let {
61
+ selector,
62
+ style
63
+ } = _ref;
64
+ let output = '';
65
+ const {
66
+ type: positionType
67
+ } = (style === null || style === void 0 ? void 0 : style.position) || {};
68
+
69
+ if (!VALID_POSITION_TYPES.includes(positionType)) {
70
+ return output;
71
+ }
72
+
73
+ output += `${selector} {`;
74
+ output += `position: ${positionType};`;
75
+ POSITION_SIDES.forEach(side => {
76
+ var _style$position;
77
+
78
+ if ((style === null || style === void 0 ? void 0 : (_style$position = style.position) === null || _style$position === void 0 ? void 0 : _style$position[side]) !== undefined) {
79
+ output += `${side}: ${style.position[side]};`;
80
+ }
81
+ });
82
+
83
+ if (positionType === 'sticky' || positionType === 'fixed') {
84
+ // TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.
85
+ output += `z-index: 10`;
86
+ }
87
+
88
+ output += `}`;
89
+ return output;
90
+ }
91
+ /**
92
+ * Determines if there is sticky position support.
93
+ *
94
+ * @param {string|Object} blockType Block name or Block Type object.
95
+ *
96
+ * @return {boolean} Whether there is support.
97
+ */
98
+
99
+ export function hasStickyPositionSupport(blockType) {
100
+ const support = getBlockSupport(blockType, POSITION_SUPPORT_KEY);
101
+ return !!(true === support || support !== null && support !== void 0 && support.sticky);
102
+ }
103
+ /**
104
+ * Determines if there is fixed position support.
105
+ *
106
+ * @param {string|Object} blockType Block name or Block Type object.
107
+ *
108
+ * @return {boolean} Whether there is support.
109
+ */
110
+
111
+ export function hasFixedPositionSupport(blockType) {
112
+ const support = getBlockSupport(blockType, POSITION_SUPPORT_KEY);
113
+ return !!(true === support || support !== null && support !== void 0 && support.fixed);
114
+ }
115
+ /**
116
+ * Determines if there is position support.
117
+ *
118
+ * @param {string|Object} blockType Block name or Block Type object.
119
+ *
120
+ * @return {boolean} Whether there is support.
121
+ */
122
+
123
+ export function hasPositionSupport(blockType) {
124
+ const support = getBlockSupport(blockType, POSITION_SUPPORT_KEY);
125
+ return !!support;
126
+ }
127
+ /**
128
+ * Checks if there is a current value in the position block support attributes.
129
+ *
130
+ * @param {Object} props Block props.
131
+ * @return {boolean} Whether or not the block has a position value set.
132
+ */
133
+
134
+ export function hasPositionValue(props) {
135
+ var _props$attributes$sty, _props$attributes$sty2;
136
+
137
+ 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;
138
+ }
139
+ /**
140
+ * Checks if the block is currently set to a sticky or fixed position.
141
+ * This check is helpful for determining how to position block toolbars or other elements.
142
+ *
143
+ * @param {Object} attributes Block attributes.
144
+ * @return {boolean} Whether or not the block is set to a sticky or fixed position.
145
+ */
146
+
147
+ export function hasStickyOrFixedPositionValue(attributes) {
148
+ var _attributes$style, _attributes$style$pos;
149
+
150
+ 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;
151
+ return positionType === 'sticky' || positionType === 'fixed';
152
+ }
153
+ /**
154
+ * Resets the position block support attributes. This can be used when disabling
155
+ * the position support controls for a block via a `ToolsPanel`.
156
+ *
157
+ * @param {Object} props Block props.
158
+ * @param {Object} props.attributes Block's attributes.
159
+ * @param {Object} props.setAttributes Function to set block's attributes.
160
+ */
161
+
162
+ export function resetPosition(_ref2) {
163
+ let {
164
+ attributes = {},
165
+ setAttributes
166
+ } = _ref2;
167
+ const {
168
+ style = {}
169
+ } = attributes;
170
+ setAttributes({
171
+ style: cleanEmptyObject({ ...style,
172
+ position: { ...(style === null || style === void 0 ? void 0 : style.position),
173
+ type: undefined,
174
+ top: undefined,
175
+ right: undefined,
176
+ bottom: undefined,
177
+ left: undefined
178
+ }
179
+ })
180
+ });
181
+ }
182
+ /**
183
+ * Custom hook that checks if position settings have been disabled.
184
+ *
185
+ * @param {string} name The name of the block.
186
+ *
187
+ * @return {boolean} Whether padding setting is disabled.
188
+ */
189
+
190
+ export function useIsPositionDisabled() {
191
+ let {
192
+ name: blockName
193
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
194
+ const allowFixed = useSetting('position.fixed');
195
+ const allowSticky = useSetting('position.sticky');
196
+ const isDisabled = !allowFixed && !allowSticky;
197
+ return !hasPositionSupport(blockName) || isDisabled;
198
+ }
199
+ /*
200
+ * Position controls to be rendered in an inspector control panel.
201
+ *
202
+ * @param {Object} props
203
+ *
204
+ * @return {WPElement} Padding edit element.
205
+ */
206
+
207
+ export function PositionEdit(props) {
208
+ var _style$position2;
209
+
210
+ const {
211
+ attributes: {
212
+ style = {}
213
+ },
214
+ name: blockName,
215
+ setAttributes
216
+ } = props;
217
+ const allowFixed = hasFixedPositionSupport(blockName);
218
+ const allowSticky = hasStickyPositionSupport(blockName);
219
+ const value = style === null || style === void 0 ? void 0 : (_style$position2 = style.position) === null || _style$position2 === void 0 ? void 0 : _style$position2.type;
220
+ const options = useMemo(() => {
221
+ const availableOptions = [DEFAULT_OPTION];
222
+
223
+ if (allowSticky || value === STICKY_OPTION.value) {
224
+ availableOptions.push(STICKY_OPTION);
225
+ }
226
+
227
+ if (allowFixed || value === FIXED_OPTION.value) {
228
+ availableOptions.push(FIXED_OPTION);
229
+ }
230
+
231
+ return availableOptions;
232
+ }, [allowFixed, allowSticky, value]);
233
+
234
+ const onChangeType = next => {
235
+ // For now, use a hard-coded `0px` value for the position.
236
+ // `0px` is preferred over `0` as it can be used in `calc()` functions.
237
+ // In the future, it could be useful to allow for an offset value.
238
+ const placementValue = '0px';
239
+ const newStyle = { ...style,
240
+ position: { ...(style === null || style === void 0 ? void 0 : style.position),
241
+ type: next,
242
+ top: next === 'sticky' || next === 'fixed' ? placementValue : undefined
243
+ }
244
+ };
245
+ setAttributes({
246
+ style: cleanEmptyObject(newStyle)
247
+ });
248
+ };
249
+
250
+ const selectedOption = value ? options.find(option => option.value === value) || DEFAULT_OPTION : DEFAULT_OPTION;
251
+ return Platform.select({
252
+ web: createElement(Fragment, null, createElement(BaseControl, {
253
+ className: "block-editor-hooks__position-selection"
254
+ }, createElement(CustomSelectControl, {
255
+ __nextUnconstrainedWidth: true,
256
+ __next36pxDefaultSize: true,
257
+ className: "block-editor-hooks__position-selection__select-control",
258
+ label: __('Position'),
259
+ hideLabelFromVision: true,
260
+ describedBy: sprintf( // translators: %s: Currently selected font size.
261
+ __('Currently selected position: %s'), selectedOption.name),
262
+ options: options,
263
+ value: selectedOption,
264
+ __experimentalShowSelectedHint: true,
265
+ onChange: _ref3 => {
266
+ let {
267
+ selectedItem
268
+ } = _ref3;
269
+ onChangeType(selectedItem.value);
270
+ },
271
+ size: '__unstable-large'
272
+ }))),
273
+ native: null
274
+ });
275
+ }
276
+ /**
277
+ * Override the default edit UI to include position controls.
278
+ *
279
+ * @param {Function} BlockEdit Original component.
280
+ *
281
+ * @return {Function} Wrapped component.
282
+ */
283
+
284
+ export const withInspectorControls = createHigherOrderComponent(BlockEdit => props => {
285
+ const {
286
+ name: blockName
287
+ } = props;
288
+ const positionSupport = hasBlockSupport(blockName, POSITION_SUPPORT_KEY);
289
+ const showPositionControls = positionSupport && !useIsPositionDisabled(props);
290
+ return [showPositionControls && createElement(InspectorControls, {
291
+ key: "position",
292
+ __experimentalGroup: "position"
293
+ }, createElement(PositionEdit, props)), createElement(BlockEdit, _extends({
294
+ key: "edit"
295
+ }, props))];
296
+ }, 'withInspectorControls');
297
+ /**
298
+ * Override the default block element to add the position styles.
299
+ *
300
+ * @param {Function} BlockListBlock Original component.
301
+ *
302
+ * @return {Function} Wrapped component.
303
+ */
304
+
305
+ export const withPositionStyles = createHigherOrderComponent(BlockListBlock => props => {
306
+ const {
307
+ name,
308
+ attributes
309
+ } = props;
310
+ const hasPositionBlockSupport = hasBlockSupport(name, POSITION_SUPPORT_KEY);
311
+ const allowPositionStyles = hasPositionBlockSupport && !useIsPositionDisabled(props);
312
+ const id = useInstanceId(BlockListBlock);
313
+ const element = useContext(BlockList.__unstableElementContext); // Higher specificity to override defaults in editor UI.
314
+
315
+ const positionSelector = `.wp-container-${id}.wp-container-${id}`; // Get CSS string for the current position values.
316
+
317
+ let css;
318
+
319
+ if (allowPositionStyles) {
320
+ css = getPositionCSS({
321
+ selector: positionSelector,
322
+ style: attributes === null || attributes === void 0 ? void 0 : attributes.style
323
+ }) || '';
324
+ } // Attach a `wp-container-` id-based class name.
325
+
326
+
327
+ const className = classnames(props === null || props === void 0 ? void 0 : props.className, {
328
+ [`wp-container-${id}`]: allowPositionStyles && !!css // Only attach a container class if there is generated CSS to be attached.
329
+
330
+ });
331
+ return createElement(Fragment, null, allowPositionStyles && element && !!css && createPortal(createElement("style", null, css), element), createElement(BlockListBlock, _extends({}, props, {
332
+ className: className
333
+ })));
334
+ });
335
+ addFilter('editor.BlockListBlock', 'core/editor/position/with-position-styles', withPositionStyles);
336
+ addFilter('editor.BlockEdit', 'core/editor/position/with-inspector-controls', withInspectorControls);
337
+ //# sourceMappingURL=position.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/position.js"],"names":["classnames","__","sprintf","getBlockSupport","hasBlockSupport","BaseControl","CustomSelectControl","createHigherOrderComponent","useInstanceId","useContext","useMemo","createPortal","Platform","addFilter","BlockList","useSetting","InspectorControls","cleanEmptyObject","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","select","web","selectedItem","native","withInspectorControls","BlockEdit","positionSupport","showPositionControls","withPositionStyles","BlockListBlock","hasPositionBlockSupport","allowPositionStyles","id","element","__unstableElementContext","positionSelector","css"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,eAAT,EAA0BC,eAA1B,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,mBAAtB,QAAiD,uBAAjD;AACA,SAASC,0BAAT,EAAqCC,aAArC,QAA0D,oBAA1D;AACA,SACCC,UADD,EAECC,OAFD,EAGCC,YAHD,EAICC,QAJD,QAKO,oBALP;AAMA,SAASC,SAAT,QAA0B,kBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,SAAP,MAAsB,0BAAtB;AACA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,OAAOC,iBAAP,MAA8B,kCAA9B;AACA,SAASC,gBAAT,QAAiC,SAAjC;AAEA,MAAMC,oBAAoB,GAAG,UAA7B;AAEA,MAAMC,gBAAgB,GACrB,gEADD;AAGA,MAAMC,cAAc,GAAG;AACtBC,EAAAA,GAAG,EAAE,SADiB;AAEt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B,UAAF,aAAEA,UAAF,uBAAEA,UAAU,CAAElB;AAFJ,KAAF,CAAd,IAGO,EAJR;AAKA,GAvBiC,CAyBlC;;;AACA,QAAMR,SAAS,GAAGxB,UAAU,CAAEiD,KAAF,aAAEA,KAAF,uBAAEA,KAAK,CAAEzB,SAAT,EAAoB;AAC/C,KAAG,gBAAgB8D,EAAI,EAAvB,GAA4BD,mBAAmB,IAAI,CAAC,CAAEK,GADP,CACY;;AADZ,GAApB,CAA5B;AAIA,SACC,8BACGL,mBAAmB,IACpBE,OADC,IAED,CAAC,CAAEG,GAFF,IAGD/E,YAAY,CAAE,6BAAS+E,GAAT,CAAF,EAA0BH,OAA1B,CAJd,EAKC,cAAC,cAAD,eAAqBtC,KAArB;AAA6B,IAAA,SAAS,EAAGzB;AAAzC,KALD,CADD;AASA,CAxC0D,CAArD;AA2CPX,SAAS,CACR,uBADQ,EAER,2CAFQ,EAGRqE,kBAHQ,CAAT;AAKArE,SAAS,CACR,kBADQ,EAER,8CAFQ,EAGRiE,qBAHQ,CAAT","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"]}
@@ -0,0 +1,257 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
5
+ import { Platform } from '@wordpress/element';
6
+ const ALIGN_SUPPORT_KEY = 'align';
7
+ const ALIGN_WIDE_SUPPORT_KEY = 'alignWide';
8
+ const BORDER_SUPPORT_KEY = '__experimentalBorder';
9
+ const COLOR_SUPPORT_KEY = 'color';
10
+ const CUSTOM_CLASS_NAME_SUPPORT_KEY = 'customClassName';
11
+ const FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';
12
+ const FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';
13
+ const LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';
14
+ /**
15
+ * Key within block settings' support array indicating support for font style.
16
+ */
17
+
18
+ const FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';
19
+ /**
20
+ * Key within block settings' support array indicating support for font weight.
21
+ */
22
+
23
+ const FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';
24
+ /**
25
+ * Key within block settings' supports array indicating support for text
26
+ * decorations e.g. settings found in `block.json`.
27
+ */
28
+
29
+ const TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';
30
+ /**
31
+ * Key within block settings' supports array indicating support for text
32
+ * transforms e.g. settings found in `block.json`.
33
+ */
34
+
35
+ const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
36
+ /**
37
+ * Key within block settings' supports array indicating support for letter-spacing
38
+ * e.g. settings found in `block.json`.
39
+ */
40
+
41
+ const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
42
+ const LAYOUT_SUPPORT_KEY = '__experimentalLayout';
43
+ const TYPOGRAPHY_SUPPORT_KEYS = [LINE_HEIGHT_SUPPORT_KEY, FONT_SIZE_SUPPORT_KEY, FONT_STYLE_SUPPORT_KEY, FONT_WEIGHT_SUPPORT_KEY, FONT_FAMILY_SUPPORT_KEY, TEXT_DECORATION_SUPPORT_KEY, TEXT_TRANSFORM_SUPPORT_KEY, LETTER_SPACING_SUPPORT_KEY];
44
+ const SPACING_SUPPORT_KEY = 'spacing';
45
+ const styleSupportKeys = [...TYPOGRAPHY_SUPPORT_KEYS, BORDER_SUPPORT_KEY, COLOR_SUPPORT_KEY, SPACING_SUPPORT_KEY];
46
+ /**
47
+ * Returns true if the block defines support for align.
48
+ *
49
+ * @param {string|Object} nameOrType Block name or type object.
50
+ * @return {boolean} Whether the block supports the feature.
51
+ */
52
+
53
+ export const hasAlignSupport = nameOrType => hasBlockSupport(nameOrType, ALIGN_SUPPORT_KEY);
54
+ /**
55
+ * Returns the block support value for align, if defined.
56
+ *
57
+ * @param {string|Object} nameOrType Block name or type object.
58
+ * @return {unknown} The block support value.
59
+ */
60
+
61
+ export const getAlignSupport = nameOrType => getBlockSupport(nameOrType, ALIGN_SUPPORT_KEY);
62
+ /**
63
+ * Returns true if the block defines support for align wide.
64
+ *
65
+ * @param {string|Object} nameOrType Block name or type object.
66
+ * @return {boolean} Whether the block supports the feature.
67
+ */
68
+
69
+ export const hasAlignWideSupport = nameOrType => hasBlockSupport(nameOrType, ALIGN_WIDE_SUPPORT_KEY);
70
+ /**
71
+ * Returns the block support value for align wide, if defined.
72
+ *
73
+ * @param {string|Object} nameOrType Block name or type object.
74
+ * @return {unknown} The block support value.
75
+ */
76
+
77
+ export const getAlignWideSupport = nameOrType => getBlockSupport(nameOrType, ALIGN_WIDE_SUPPORT_KEY);
78
+ /**
79
+ * Determine whether there is block support for border properties.
80
+ *
81
+ * @param {string|Object} nameOrType Block name or type object.
82
+ * @param {string} feature Border feature to check support for.
83
+ *
84
+ * @return {boolean} Whether there is support.
85
+ */
86
+
87
+ export function hasBorderSupport(nameOrType) {
88
+ let feature = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'any';
89
+
90
+ if (Platform.OS !== 'web') {
91
+ return false;
92
+ }
93
+
94
+ const support = getBlockSupport(nameOrType, BORDER_SUPPORT_KEY);
95
+
96
+ if (support === true) {
97
+ return true;
98
+ }
99
+
100
+ if (feature === 'any') {
101
+ return !!(support !== null && support !== void 0 && support.color || support !== null && support !== void 0 && support.radius || support !== null && support !== void 0 && support.width || support !== null && support !== void 0 && support.style);
102
+ }
103
+
104
+ return !!(support !== null && support !== void 0 && support[feature]);
105
+ }
106
+ /**
107
+ * Get block support for border properties.
108
+ *
109
+ * @param {string|Object} nameOrType Block name or type object.
110
+ * @param {string} feature Border feature to get.
111
+ *
112
+ * @return {unknown} The block support.
113
+ */
114
+
115
+ export const getBorderSupport = (nameOrType, feature) => getBlockSupport(nameOrType, [BORDER_SUPPORT_KEY, feature]);
116
+ /**
117
+ * Returns true if the block defines support for color.
118
+ *
119
+ * @param {string|Object} nameOrType Block name or type object.
120
+ * @return {boolean} Whether the block supports the feature.
121
+ */
122
+
123
+ export const hasColorSupport = nameOrType => {
124
+ const colorSupport = getBlockSupport(nameOrType, COLOR_SUPPORT_KEY);
125
+ return colorSupport && (colorSupport.link === true || colorSupport.gradient === true || colorSupport.background !== false || colorSupport.text !== false);
126
+ };
127
+ /**
128
+ * Returns true if the block defines support for link color.
129
+ *
130
+ * @param {string|Object} nameOrType Block name or type object.
131
+ * @return {boolean} Whether the block supports the feature.
132
+ */
133
+
134
+ export const hasLinkColorSupport = nameOrType => {
135
+ if (Platform.OS !== 'web') {
136
+ return false;
137
+ }
138
+
139
+ const colorSupport = getBlockSupport(nameOrType, COLOR_SUPPORT_KEY);
140
+ return colorSupport !== null && typeof colorSupport === 'object' && !!colorSupport.link;
141
+ };
142
+ /**
143
+ * Returns true if the block defines support for gradient color.
144
+ *
145
+ * @param {string|Object} nameOrType Block name or type object.
146
+ * @return {boolean} Whether the block supports the feature.
147
+ */
148
+
149
+ export const hasGradientSupport = nameOrType => {
150
+ const colorSupport = getBlockSupport(nameOrType, COLOR_SUPPORT_KEY);
151
+ return colorSupport !== null && typeof colorSupport === 'object' && !!colorSupport.gradients;
152
+ };
153
+ /**
154
+ * Returns true if the block defines support for background color.
155
+ *
156
+ * @param {string|Object} nameOrType Block name or type object.
157
+ * @return {boolean} Whether the block supports the feature.
158
+ */
159
+
160
+ export const hasBackgroundColorSupport = nameOrType => {
161
+ const colorSupport = getBlockSupport(nameOrType, COLOR_SUPPORT_KEY);
162
+ return colorSupport && colorSupport.background !== false;
163
+ };
164
+ /**
165
+ * Returns true if the block defines support for background color.
166
+ *
167
+ * @param {string|Object} nameOrType Block name or type object.
168
+ * @return {boolean} Whether the block supports the feature.
169
+ */
170
+
171
+ export const hasTextColorSupport = nameOrType => {
172
+ const colorSupport = getBlockSupport(nameOrType, COLOR_SUPPORT_KEY);
173
+ return colorSupport && colorSupport.text !== false;
174
+ };
175
+ /**
176
+ * Get block support for color properties.
177
+ *
178
+ * @param {string|Object} nameOrType Block name or type object.
179
+ * @param {string} feature Color feature to get.
180
+ *
181
+ * @return {unknown} The block support.
182
+ */
183
+
184
+ export const getColorSupport = (nameOrType, feature) => getBlockSupport(nameOrType, [COLOR_SUPPORT_KEY, feature]);
185
+ /**
186
+ * Returns true if the block defines support for custom class name.
187
+ *
188
+ * @param {string|Object} nameOrType Block name or type object.
189
+ * @return {boolean} Whether the block supports the feature.
190
+ */
191
+
192
+ export const hasCustomClassNameSupport = nameOrType => hasBlockSupport(nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true);
193
+ /**
194
+ * Returns the block support value for custom class name, if defined.
195
+ *
196
+ * @param {string|Object} nameOrType Block name or type object.
197
+ * @return {unknown} The block support value.
198
+ */
199
+
200
+ export const getCustomClassNameSupport = nameOrType => getBlockSupport(nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true);
201
+ /**
202
+ * Returns true if the block defines support for font family.
203
+ *
204
+ * @param {string|Object} nameOrType Block name or type object.
205
+ * @return {boolean} Whether the block supports the feature.
206
+ */
207
+
208
+ export const hasFontFamilySupport = nameOrType => hasBlockSupport(nameOrType, FONT_FAMILY_SUPPORT_KEY);
209
+ /**
210
+ * Returns the block support value for font family, if defined.
211
+ *
212
+ * @param {string|Object} nameOrType Block name or type object.
213
+ * @return {unknown} The block support value.
214
+ */
215
+
216
+ export const getFontFamilySupport = nameOrType => getBlockSupport(nameOrType, FONT_FAMILY_SUPPORT_KEY);
217
+ /**
218
+ * Returns true if the block defines support for font size.
219
+ *
220
+ * @param {string|Object} nameOrType Block name or type object.
221
+ * @return {boolean} Whether the block supports the feature.
222
+ */
223
+
224
+ export const hasFontSizeSupport = nameOrType => hasBlockSupport(nameOrType, FONT_SIZE_SUPPORT_KEY);
225
+ /**
226
+ * Returns the block support value for font size, if defined.
227
+ *
228
+ * @param {string|Object} nameOrType Block name or type object.
229
+ * @return {unknown} The block support value.
230
+ */
231
+
232
+ export const getFontSizeSupport = nameOrType => getBlockSupport(nameOrType, FONT_SIZE_SUPPORT_KEY);
233
+ /**
234
+ * Returns true if the block defines support for layout.
235
+ *
236
+ * @param {string|Object} nameOrType Block name or type object.
237
+ * @return {boolean} Whether the block supports the feature.
238
+ */
239
+
240
+ export const hasLayoutSupport = nameOrType => hasBlockSupport(nameOrType, LAYOUT_SUPPORT_KEY);
241
+ /**
242
+ * Returns the block support value for layout, if defined.
243
+ *
244
+ * @param {string|Object} nameOrType Block name or type object.
245
+ * @return {unknown} The block support value.
246
+ */
247
+
248
+ export const getLayoutSupport = nameOrType => getBlockSupport(nameOrType, LAYOUT_SUPPORT_KEY);
249
+ /**
250
+ * Returns true if the block defines support for style.
251
+ *
252
+ * @param {string|Object} nameOrType Block name or type object.
253
+ * @return {boolean} Whether the block supports the feature.
254
+ */
255
+
256
+ export const hasStyleSupport = nameOrType => styleSupportKeys.some(key => hasBlockSupport(nameOrType, key));
257
+ //# sourceMappingURL=supports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/supports.js"],"names":["getBlockSupport","hasBlockSupport","Platform","ALIGN_SUPPORT_KEY","ALIGN_WIDE_SUPPORT_KEY","BORDER_SUPPORT_KEY","COLOR_SUPPORT_KEY","CUSTOM_CLASS_NAME_SUPPORT_KEY","FONT_FAMILY_SUPPORT_KEY","FONT_SIZE_SUPPORT_KEY","LINE_HEIGHT_SUPPORT_KEY","FONT_STYLE_SUPPORT_KEY","FONT_WEIGHT_SUPPORT_KEY","TEXT_DECORATION_SUPPORT_KEY","TEXT_TRANSFORM_SUPPORT_KEY","LETTER_SPACING_SUPPORT_KEY","LAYOUT_SUPPORT_KEY","TYPOGRAPHY_SUPPORT_KEYS","SPACING_SUPPORT_KEY","styleSupportKeys","hasAlignSupport","nameOrType","getAlignSupport","hasAlignWideSupport","getAlignWideSupport","hasBorderSupport","feature","OS","support","color","radius","width","style","getBorderSupport","hasColorSupport","colorSupport","link","gradient","background","text","hasLinkColorSupport","hasGradientSupport","gradients","hasBackgroundColorSupport","hasTextColorSupport","getColorSupport","hasCustomClassNameSupport","getCustomClassNameSupport","hasFontFamilySupport","getFontFamilySupport","hasFontSizeSupport","getFontSizeSupport","hasLayoutSupport","getLayoutSupport","hasStyleSupport","some","key"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,EAA0BC,eAA1B,QAAiD,mBAAjD;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA,MAAMC,iBAAiB,GAAG,OAA1B;AACA,MAAMC,sBAAsB,GAAG,WAA/B;AACA,MAAMC,kBAAkB,GAAG,sBAA3B;AACA,MAAMC,iBAAiB,GAAG,OAA1B;AACA,MAAMC,6BAA6B,GAAG,iBAAtC;AACA,MAAMC,uBAAuB,GAAG,qCAAhC;AACA,MAAMC,qBAAqB,GAAG,qBAA9B;AACA,MAAMC,uBAAuB,GAAG,uBAAhC;AACA;AACA;AACA;;AACA,MAAMC,sBAAsB,GAAG,oCAA/B;AACA;AACA;AACA;;AACA,MAAMC,uBAAuB,GAAG,qCAAhC;AACA;AACA;AACA;AACA;;AACA,MAAMC,2BAA2B,GAAG,yCAApC;AACA;AACA;AACA;AACA;;AACA,MAAMC,0BAA0B,GAAG,wCAAnC;AACA;AACA;AACA;AACA;;AACA,MAAMC,0BAA0B,GAAG,wCAAnC;AACA,MAAMC,kBAAkB,GAAG,sBAA3B;AACA,MAAMC,uBAAuB,GAAG,CAC/BP,uBAD+B,EAE/BD,qBAF+B,EAG/BE,sBAH+B,EAI/BC,uBAJ+B,EAK/BJ,uBAL+B,EAM/BK,2B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,UAAF,IACjCpB,eAAe,CAAEoB,UAAF,EAAcZ,qBAAd,CADT;AAGP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAM0C,kBAAkB,GAAK9B,UAAF,IACjCrB,eAAe,CAAEqB,UAAF,EAAcZ,qBAAd,CADT;AAGP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAM2C,gBAAgB,GAAK/B,UAAF,IAC/BpB,eAAe,CAAEoB,UAAF,EAAcL,kBAAd,CADT;AAGP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMqC,gBAAgB,GAAKhC,UAAF,IAC/BrB,eAAe,CAAEqB,UAAF,EAAcL,kBAAd,CADT;AAGP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMsC,eAAe,GAAKjC,UAAF,IAC9BF,gBAAgB,CAACoC,IAAjB,CAAyBC,GAAF,IAAWvD,eAAe,CAAEoB,UAAF,EAAcmC,GAAd,CAAjD,CADM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';\nimport { Platform } from '@wordpress/element';\n\nconst ALIGN_SUPPORT_KEY = 'align';\nconst ALIGN_WIDE_SUPPORT_KEY = 'alignWide';\nconst BORDER_SUPPORT_KEY = '__experimentalBorder';\nconst COLOR_SUPPORT_KEY = 'color';\nconst CUSTOM_CLASS_NAME_SUPPORT_KEY = 'customClassName';\nconst FONT_FAMILY_SUPPORT_KEY = 'typography.__experimentalFontFamily';\nconst FONT_SIZE_SUPPORT_KEY = 'typography.fontSize';\nconst LINE_HEIGHT_SUPPORT_KEY = 'typography.lineHeight';\n/**\n * Key within block settings' support array indicating support for font style.\n */\nconst FONT_STYLE_SUPPORT_KEY = 'typography.__experimentalFontStyle';\n/**\n * Key within block settings' support array indicating support for font weight.\n */\nconst FONT_WEIGHT_SUPPORT_KEY = 'typography.__experimentalFontWeight';\n/**\n * Key within block settings' supports array indicating support for text\n * decorations e.g. settings found in `block.json`.\n */\nconst TEXT_DECORATION_SUPPORT_KEY = 'typography.__experimentalTextDecoration';\n/**\n * Key within block settings' supports array indicating support for text\n * transforms e.g. settings found in `block.json`.\n */\nconst TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';\n/**\n * Key within block settings' supports array indicating support for letter-spacing\n * e.g. settings found in `block.json`.\n */\nconst LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';\nconst LAYOUT_SUPPORT_KEY = '__experimentalLayout';\nconst TYPOGRAPHY_SUPPORT_KEYS = [\n\tLINE_HEIGHT_SUPPORT_KEY,\n\tFONT_SIZE_SUPPORT_KEY,\n\tFONT_STYLE_SUPPORT_KEY,\n\tFONT_WEIGHT_SUPPORT_KEY,\n\tFONT_FAMILY_SUPPORT_KEY,\n\tTEXT_DECORATION_SUPPORT_KEY,\n\tTEXT_TRANSFORM_SUPPORT_KEY,\n\tLETTER_SPACING_SUPPORT_KEY,\n];\nconst SPACING_SUPPORT_KEY = 'spacing';\nconst styleSupportKeys = [\n\t...TYPOGRAPHY_SUPPORT_KEYS,\n\tBORDER_SUPPORT_KEY,\n\tCOLOR_SUPPORT_KEY,\n\tSPACING_SUPPORT_KEY,\n];\n\n/**\n * Returns true if the block defines support for align.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasAlignSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, ALIGN_SUPPORT_KEY );\n\n/**\n * Returns the block support value for align, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getAlignSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, ALIGN_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for align wide.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasAlignWideSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, ALIGN_WIDE_SUPPORT_KEY );\n\n/**\n * Returns the block support value for align wide, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getAlignWideSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, ALIGN_WIDE_SUPPORT_KEY );\n\n/**\n * Determine whether there is block support for border properties.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @param {string} feature Border feature to check support for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBorderSupport( nameOrType, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( nameOrType, BORDER_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! (\n\t\t\tsupport?.color ||\n\t\t\tsupport?.radius ||\n\t\t\tsupport?.width ||\n\t\t\tsupport?.style\n\t\t);\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Get block support for border properties.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @param {string} feature Border feature to get.\n *\n * @return {unknown} The block support.\n */\nexport const getBorderSupport = ( nameOrType, feature ) =>\n\tgetBlockSupport( nameOrType, [ BORDER_SUPPORT_KEY, feature ] );\n\n/**\n * Returns true if the block defines support for color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasColorSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\treturn (\n\t\tcolorSupport &&\n\t\t( colorSupport.link === true ||\n\t\t\tcolorSupport.gradient === true ||\n\t\t\tcolorSupport.background !== false ||\n\t\t\tcolorSupport.text !== false )\n\t);\n};\n\n/**\n * Returns true if the block defines support for link color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasLinkColorSupport = ( nameOrType ) => {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.link\n\t);\n};\n\n/**\n * Returns true if the block defines support for gradient color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasGradientSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn (\n\t\tcolorSupport !== null &&\n\t\ttypeof colorSupport === 'object' &&\n\t\t!! colorSupport.gradients\n\t);\n};\n\n/**\n * Returns true if the block defines support for background color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasBackgroundColorSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.background !== false;\n};\n\n/**\n * Returns true if the block defines support for background color.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasTextColorSupport = ( nameOrType ) => {\n\tconst colorSupport = getBlockSupport( nameOrType, COLOR_SUPPORT_KEY );\n\n\treturn colorSupport && colorSupport.text !== false;\n};\n\n/**\n * Get block support for color properties.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @param {string} feature Color feature to get.\n *\n * @return {unknown} The block support.\n */\nexport const getColorSupport = ( nameOrType, feature ) =>\n\tgetBlockSupport( nameOrType, [ COLOR_SUPPORT_KEY, feature ] );\n\n/**\n * Returns true if the block defines support for custom class name.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasCustomClassNameSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true );\n\n/**\n * Returns the block support value for custom class name, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getCustomClassNameSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, CUSTOM_CLASS_NAME_SUPPORT_KEY, true );\n\n/**\n * Returns true if the block defines support for font family.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasFontFamilySupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, FONT_FAMILY_SUPPORT_KEY );\n\n/**\n * Returns the block support value for font family, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getFontFamilySupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, FONT_FAMILY_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for font size.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasFontSizeSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, FONT_SIZE_SUPPORT_KEY );\n\n/**\n * Returns the block support value for font size, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getFontSizeSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, FONT_SIZE_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for layout.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasLayoutSupport = ( nameOrType ) =>\n\thasBlockSupport( nameOrType, LAYOUT_SUPPORT_KEY );\n\n/**\n * Returns the block support value for layout, if defined.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {unknown} The block support value.\n */\nexport const getLayoutSupport = ( nameOrType ) =>\n\tgetBlockSupport( nameOrType, LAYOUT_SUPPORT_KEY );\n\n/**\n * Returns true if the block defines support for style.\n *\n * @param {string|Object} nameOrType Block name or type object.\n * @return {boolean} Whether the block supports the feature.\n */\nexport const hasStyleSupport = ( nameOrType ) =>\n\tstyleSupportKeys.some( ( key ) => hasBlockSupport( nameOrType, key ) );\n"]}