@wordpress/block-editor 8.0.11 → 8.0.12-next.33ec3857e2.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 (278) hide show
  1. package/README.md +4 -0
  2. package/build/components/block-caption/index.native.js +14 -3
  3. package/build/components/block-caption/index.native.js.map +1 -1
  4. package/build/components/block-inspector/index.js +12 -23
  5. package/build/components/block-inspector/index.js.map +1 -1
  6. package/build/components/block-list-appender/index.js +3 -11
  7. package/build/components/block-list-appender/index.js.map +1 -1
  8. package/build/components/block-preview/auto.js +10 -2
  9. package/build/components/block-preview/auto.js.map +1 -1
  10. package/build/components/block-preview/index.js +51 -0
  11. package/build/components/block-preview/index.js.map +1 -1
  12. package/build/components/block-settings/container.native.js +2 -1
  13. package/build/components/block-settings/container.native.js.map +1 -1
  14. package/build/components/block-styles/index.js +110 -134
  15. package/build/components/block-styles/index.js.map +1 -1
  16. package/build/components/block-styles/menu-items.js +63 -0
  17. package/build/components/block-styles/menu-items.js.map +1 -0
  18. package/build/components/block-styles/preview-panel.js +45 -0
  19. package/build/components/block-styles/preview-panel.js.map +1 -0
  20. package/build/components/block-styles/use-styles-for-block.js +119 -0
  21. package/build/components/block-styles/use-styles-for-block.js.map +1 -0
  22. package/build/components/block-styles/utils.js +39 -0
  23. package/build/components/block-styles/utils.js.map +1 -1
  24. package/build/components/block-switcher/block-styles-menu.js +3 -23
  25. package/build/components/block-switcher/block-styles-menu.js.map +1 -1
  26. package/build/components/block-tools/back-compat.js +2 -1
  27. package/build/components/block-tools/back-compat.js.map +1 -1
  28. package/build/components/block-tools/insertion-point.js +11 -1
  29. package/build/components/block-tools/insertion-point.js.map +1 -1
  30. package/build/components/button-block-appender/index.js +2 -1
  31. package/build/components/button-block-appender/index.js.map +1 -1
  32. package/build/components/colors-gradients/panel-color-gradient-settings.js +51 -10
  33. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  34. package/build/components/default-block-appender/index.js +16 -19
  35. package/build/components/default-block-appender/index.js.map +1 -1
  36. package/build/components/default-style-picker/index.js +18 -3
  37. package/build/components/default-style-picker/index.js.map +1 -1
  38. package/build/components/iframe/index.js +3 -4
  39. package/build/components/iframe/index.js.map +1 -1
  40. package/build/components/index.js +17 -10
  41. package/build/components/index.js.map +1 -1
  42. package/build/components/inner-blocks/default-block-appender.js +2 -4
  43. package/build/components/inner-blocks/default-block-appender.js.map +1 -1
  44. package/build/components/inserter/index.native.js +1 -1
  45. package/build/components/inserter/index.native.js.map +1 -1
  46. package/build/components/inserter/tabs.native.js +7 -4
  47. package/build/components/inserter/tabs.native.js.map +1 -1
  48. package/build/components/inspector-controls/block-support-slot-container.js +2 -1
  49. package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
  50. package/build/components/inspector-controls/fill.native.js +3 -5
  51. package/build/components/inspector-controls/fill.native.js.map +1 -1
  52. package/build/components/inspector-controls/groups.js +2 -0
  53. package/build/components/inspector-controls/groups.js.map +1 -1
  54. package/build/components/inspector-controls/slot.js +1 -3
  55. package/build/components/inspector-controls/slot.js.map +1 -1
  56. package/build/components/letter-spacing-control/index.js +6 -6
  57. package/build/components/letter-spacing-control/index.js.map +1 -1
  58. package/build/components/list-view/block-select-button.js +23 -3
  59. package/build/components/list-view/block-select-button.js.map +1 -1
  60. package/build/components/media-placeholder/index.js +2 -0
  61. package/build/components/media-placeholder/index.js.map +1 -1
  62. package/build/components/media-replace-flow/index.js +2 -0
  63. package/build/components/media-replace-flow/index.js.map +1 -1
  64. package/build/components/rich-text/file-paste-handler.js +1 -1
  65. package/build/components/rich-text/file-paste-handler.js.map +1 -1
  66. package/build/components/rich-text/prevent-event-discovery.js +33 -0
  67. package/build/components/rich-text/prevent-event-discovery.js.map +1 -0
  68. package/build/components/rich-text/use-input-rules.js +3 -1
  69. package/build/components/rich-text/use-input-rules.js.map +1 -1
  70. package/build/components/selection-scroll-into-view/index.js +2 -1
  71. package/build/components/selection-scroll-into-view/index.js.map +1 -1
  72. package/build/components/use-display-block-controls/index.native.js +45 -0
  73. package/build/components/use-display-block-controls/index.native.js.map +1 -0
  74. package/build/components/use-on-block-drop/index.js +7 -3
  75. package/build/components/use-on-block-drop/index.js.map +1 -1
  76. package/build/components/writing-flow/use-multi-selection.js +3 -1
  77. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  78. package/build/hooks/border-color.js +63 -5
  79. package/build/hooks/border-color.js.map +1 -1
  80. package/build/hooks/border-radius.js +47 -0
  81. package/build/hooks/border-radius.js.map +1 -1
  82. package/build/hooks/border-style.js +41 -0
  83. package/build/hooks/border-style.js.map +1 -1
  84. package/build/hooks/border-width.js +70 -31
  85. package/build/hooks/border-width.js.map +1 -1
  86. package/build/hooks/border.js +81 -11
  87. package/build/hooks/border.js.map +1 -1
  88. package/build/hooks/letter-spacing.js +1 -1
  89. package/build/hooks/letter-spacing.js.map +1 -1
  90. package/build/hooks/typography.js +1 -1
  91. package/build/hooks/typography.js.map +1 -1
  92. package/build/store/actions.js +1 -2
  93. package/build/store/actions.js.map +1 -1
  94. package/build/store/defaults.js +5 -1
  95. package/build/store/defaults.js.map +1 -1
  96. package/build/store/selectors.js +25 -7
  97. package/build/store/selectors.js.map +1 -1
  98. package/build/utils/get-paste-event-data.js +1 -1
  99. package/build/utils/get-paste-event-data.js.map +1 -1
  100. package/build/utils/parse-css-unit-to-px.js +1 -1
  101. package/build/utils/parse-css-unit-to-px.js.map +1 -1
  102. package/build-module/components/block-caption/index.native.js +13 -3
  103. package/build-module/components/block-caption/index.native.js.map +1 -1
  104. package/build-module/components/block-inspector/index.js +12 -23
  105. package/build-module/components/block-inspector/index.js.map +1 -1
  106. package/build-module/components/block-list-appender/index.js +3 -10
  107. package/build-module/components/block-list-appender/index.js.map +1 -1
  108. package/build-module/components/block-preview/auto.js +10 -2
  109. package/build-module/components/block-preview/auto.js.map +1 -1
  110. package/build-module/components/block-preview/index.js +46 -0
  111. package/build-module/components/block-preview/index.js.map +1 -1
  112. package/build-module/components/block-settings/container.native.js +2 -1
  113. package/build-module/components/block-settings/container.native.js.map +1 -1
  114. package/build-module/components/block-styles/index.js +112 -133
  115. package/build-module/components/block-styles/index.js.map +1 -1
  116. package/build-module/components/block-styles/menu-items.js +50 -0
  117. package/build-module/components/block-styles/menu-items.js.map +1 -0
  118. package/build-module/components/block-styles/preview-panel.js +35 -0
  119. package/build-module/components/block-styles/preview-panel.js.map +1 -0
  120. package/build-module/components/block-styles/use-styles-for-block.js +107 -0
  121. package/build-module/components/block-styles/use-styles-for-block.js.map +1 -0
  122. package/build-module/components/block-styles/utils.js +34 -0
  123. package/build-module/components/block-styles/utils.js.map +1 -1
  124. package/build-module/components/block-switcher/block-styles-menu.js +3 -21
  125. package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
  126. package/build-module/components/block-tools/back-compat.js +2 -1
  127. package/build-module/components/block-tools/back-compat.js.map +1 -1
  128. package/build-module/components/block-tools/insertion-point.js +11 -1
  129. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  130. package/build-module/components/button-block-appender/index.js +2 -1
  131. package/build-module/components/button-block-appender/index.js.map +1 -1
  132. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +54 -13
  133. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  134. package/build-module/components/default-block-appender/index.js +15 -18
  135. package/build-module/components/default-block-appender/index.js.map +1 -1
  136. package/build-module/components/default-style-picker/index.js +17 -3
  137. package/build-module/components/default-style-picker/index.js.map +1 -1
  138. package/build-module/components/iframe/index.js +3 -4
  139. package/build-module/components/iframe/index.js.map +1 -1
  140. package/build-module/components/index.js +2 -2
  141. package/build-module/components/index.js.map +1 -1
  142. package/build-module/components/inner-blocks/default-block-appender.js +2 -4
  143. package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
  144. package/build-module/components/inserter/index.native.js +2 -2
  145. package/build-module/components/inserter/index.native.js.map +1 -1
  146. package/build-module/components/inserter/tabs.native.js +7 -4
  147. package/build-module/components/inserter/tabs.native.js.map +1 -1
  148. package/build-module/components/inspector-controls/block-support-slot-container.js +2 -1
  149. package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
  150. package/build-module/components/inspector-controls/fill.native.js +3 -5
  151. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  152. package/build-module/components/inspector-controls/groups.js +2 -0
  153. package/build-module/components/inspector-controls/groups.js.map +1 -1
  154. package/build-module/components/inspector-controls/slot.js +1 -3
  155. package/build-module/components/inspector-controls/slot.js.map +1 -1
  156. package/build-module/components/letter-spacing-control/index.js +6 -6
  157. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  158. package/build-module/components/list-view/block-select-button.js +22 -3
  159. package/build-module/components/list-view/block-select-button.js.map +1 -1
  160. package/build-module/components/media-placeholder/index.js +2 -0
  161. package/build-module/components/media-placeholder/index.js.map +1 -1
  162. package/build-module/components/media-replace-flow/index.js +2 -0
  163. package/build-module/components/media-replace-flow/index.js.map +1 -1
  164. package/build-module/components/rich-text/file-paste-handler.js +1 -1
  165. package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
  166. package/build-module/components/rich-text/prevent-event-discovery.js +25 -0
  167. package/build-module/components/rich-text/prevent-event-discovery.js.map +1 -0
  168. package/build-module/components/rich-text/use-input-rules.js +2 -1
  169. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  170. package/build-module/components/selection-scroll-into-view/index.js +2 -1
  171. package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
  172. package/build-module/components/use-display-block-controls/index.native.js +34 -0
  173. package/build-module/components/use-display-block-controls/index.native.js.map +1 -0
  174. package/build-module/components/use-on-block-drop/index.js +7 -3
  175. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  176. package/build-module/components/writing-flow/use-multi-selection.js +3 -4
  177. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  178. package/build-module/hooks/border-color.js +61 -7
  179. package/build-module/hooks/border-color.js.map +1 -1
  180. package/build-module/hooks/border-radius.js +42 -0
  181. package/build-module/hooks/border-radius.js.map +1 -1
  182. package/build-module/hooks/border-style.js +36 -0
  183. package/build-module/hooks/border-style.js.map +1 -1
  184. package/build-module/hooks/border-width.js +66 -32
  185. package/build-module/hooks/border-width.js.map +1 -1
  186. package/build-module/hooks/border.js +80 -12
  187. package/build-module/hooks/border.js.map +1 -1
  188. package/build-module/hooks/letter-spacing.js +1 -1
  189. package/build-module/hooks/letter-spacing.js.map +1 -1
  190. package/build-module/hooks/typography.js +1 -1
  191. package/build-module/hooks/typography.js.map +1 -1
  192. package/build-module/store/actions.js +1 -2
  193. package/build-module/store/actions.js.map +1 -1
  194. package/build-module/store/defaults.js +5 -1
  195. package/build-module/store/defaults.js.map +1 -1
  196. package/build-module/store/selectors.js +24 -7
  197. package/build-module/store/selectors.js.map +1 -1
  198. package/build-module/utils/get-paste-event-data.js +1 -1
  199. package/build-module/utils/get-paste-event-data.js.map +1 -1
  200. package/build-module/utils/parse-css-unit-to-px.js +1 -1
  201. package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
  202. package/build-style/style-rtl.css +226 -180
  203. package/build-style/style.css +226 -180
  204. package/package.json +27 -27
  205. package/src/components/block-caption/index.native.js +22 -4
  206. package/src/components/block-inspector/index.js +14 -17
  207. package/src/components/block-list-appender/index.js +5 -21
  208. package/src/components/block-preview/auto.js +7 -2
  209. package/src/components/block-preview/index.js +60 -0
  210. package/src/components/block-preview/style.scss +23 -0
  211. package/src/components/block-preview/test/index.js +114 -0
  212. package/src/components/block-settings/container.native.js +1 -0
  213. package/src/components/block-styles/index.js +125 -145
  214. package/src/components/block-styles/menu-items.js +49 -0
  215. package/src/components/block-styles/preview-panel.js +36 -0
  216. package/src/components/block-styles/style.scss +59 -51
  217. package/src/components/block-styles/test/{index.js → utils.js} +60 -1
  218. package/src/components/block-styles/use-styles-for-block.js +99 -0
  219. package/src/components/block-styles/utils.js +39 -0
  220. package/src/components/block-switcher/block-styles-menu.js +3 -38
  221. package/src/components/block-tools/back-compat.js +1 -0
  222. package/src/components/block-tools/insertion-point.js +10 -1
  223. package/src/components/border-style-control/style.scss +0 -1
  224. package/src/components/button-block-appender/index.js +1 -0
  225. package/src/components/colors-gradients/panel-color-gradient-settings.js +75 -19
  226. package/src/components/colors-gradients/style.scss +42 -5
  227. package/src/components/default-block-appender/index.js +17 -24
  228. package/src/components/default-block-appender/style.scss +4 -0
  229. package/src/components/default-block-appender/test/__snapshots__/index.js.snap +12 -24
  230. package/src/components/default-block-appender/test/index.js +4 -14
  231. package/src/components/default-style-picker/index.js +18 -6
  232. package/src/components/iframe/index.js +6 -3
  233. package/src/components/index.js +5 -2
  234. package/src/components/inner-blocks/README.md +2 -0
  235. package/src/components/inner-blocks/default-block-appender.js +2 -7
  236. package/src/components/inserter/index.native.js +2 -2
  237. package/src/components/inserter/tabs.native.js +5 -4
  238. package/src/components/inspector-controls/block-support-slot-container.js +3 -1
  239. package/src/components/inspector-controls/fill.native.js +4 -3
  240. package/src/components/inspector-controls/groups.js +2 -0
  241. package/src/components/inspector-controls/slot.js +2 -7
  242. package/src/components/letter-spacing-control/index.js +6 -6
  243. package/src/components/link-control/README.md +1 -1
  244. package/src/components/link-control/test/index.js +2 -0
  245. package/src/components/list-view/block-select-button.js +20 -1
  246. package/src/components/media-placeholder/index.js +2 -0
  247. package/src/components/media-replace-flow/index.js +2 -0
  248. package/src/components/rich-text/file-paste-handler.js +3 -1
  249. package/src/components/rich-text/prevent-event-discovery.js +23 -0
  250. package/src/components/rich-text/use-input-rules.js +2 -1
  251. package/src/components/selection-scroll-into-view/index.js +1 -0
  252. package/src/components/url-input/README.md +5 -0
  253. package/src/components/use-display-block-controls/index.native.js +38 -0
  254. package/src/components/use-on-block-drop/index.js +7 -3
  255. package/src/components/writing-flow/test/use-multi-selection.js +36 -0
  256. package/src/components/writing-flow/use-multi-selection.js +12 -9
  257. package/src/hooks/border-color.js +55 -3
  258. package/src/hooks/border-radius.js +32 -0
  259. package/src/hooks/border-style.js +26 -0
  260. package/src/hooks/border-width.js +56 -32
  261. package/src/hooks/border.js +115 -20
  262. package/src/hooks/border.scss +3 -17
  263. package/src/hooks/dimensions.scss +5 -0
  264. package/src/hooks/letter-spacing.js +1 -1
  265. package/src/hooks/typography.js +1 -1
  266. package/src/store/actions.js +1 -2
  267. package/src/store/defaults.js +2 -0
  268. package/src/store/selectors.js +37 -7
  269. package/src/style.scss +4 -3
  270. package/src/utils/get-paste-event-data.js +1 -1
  271. package/src/utils/parse-css-unit-to-px.js +1 -1
  272. package/src/utils/test/parse-css-unit-to-px.js +1 -0
  273. package/tsconfig.tsbuildinfo +1 -1
  274. package/build/components/use-canvas-click-redirect/index.js +0 -66
  275. package/build/components/use-canvas-click-redirect/index.js.map +0 -1
  276. package/build-module/components/use-canvas-click-redirect/index.js +0 -54
  277. package/build-module/components/use-canvas-click-redirect/index.js.map +0 -1
  278. package/src/components/use-canvas-click-redirect/index.js +0 -57
@@ -3,168 +3,147 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
- import { find, noop } from 'lodash';
6
+ import { noop, debounce } from 'lodash';
7
7
  import classnames from 'classnames';
8
8
  /**
9
9
  * WordPress dependencies
10
10
  */
11
11
 
12
- import { useMemo } from '@wordpress/element';
13
- import { useSelect, useDispatch } from '@wordpress/data';
12
+ import { useState, useLayoutEffect } from '@wordpress/element';
13
+ import { useViewportMatch } from '@wordpress/compose';
14
14
  import { ENTER, SPACE } from '@wordpress/keycodes';
15
- import { _x } from '@wordpress/i18n';
16
- import { getBlockType, cloneBlock, getBlockFromExample, store as blocksStore } from '@wordpress/blocks';
15
+ import { Button, __experimentalText as Text, Slot, Fill } from '@wordpress/components';
17
16
  /**
18
17
  * Internal dependencies
19
18
  */
20
19
 
21
- import { getActiveStyle, replaceActiveStyle } from './utils';
22
- import BlockPreview from '../block-preview';
23
- import { store as blockEditorStore } from '../../store';
24
- const EMPTY_OBJECT = {};
25
-
26
- function useGenericPreviewBlock(block, type) {
27
- return useMemo(() => {
28
- const example = type === null || type === void 0 ? void 0 : type.example;
29
- const blockName = type === null || type === void 0 ? void 0 : type.name;
30
-
31
- if (example && blockName) {
32
- return getBlockFromExample(blockName, {
33
- attributes: example.attributes,
34
- innerBlocks: example.innerBlocks
35
- });
36
- }
20
+ import BlockStylesPreviewPanel from './preview-panel';
21
+ import useStylesForBlocks from './use-styles-for-block';
37
22
 
38
- if (block) {
39
- return cloneBlock(block);
40
- }
41
- }, [type !== null && type !== void 0 && type.example ? block === null || block === void 0 ? void 0 : block.name : block, type]);
23
+ function BlockStylesPreviewPanelSlot(_ref) {
24
+ let {
25
+ scope
26
+ } = _ref;
27
+ return createElement(Slot, {
28
+ name: `BlockStylesPreviewPanel/${scope}`
29
+ });
42
30
  }
43
31
 
44
- function BlockStyles(_ref) {
32
+ function BlockStylesPreviewPanelFill(_ref2) {
33
+ let {
34
+ children,
35
+ scope,
36
+ ...props
37
+ } = _ref2;
38
+ return createElement(Fill, {
39
+ name: `BlockStylesPreviewPanel/${scope}`
40
+ }, createElement("div", props, children));
41
+ } // Top position (in px) of the Block Styles container
42
+ // relative to the editor pane.
43
+ // The value is the equivalent of the container's right position.
44
+
45
+
46
+ const DEFAULT_POSITION_TOP = 16; // Block Styles component for the Settings Sidebar.
47
+
48
+ function BlockStyles(_ref3) {
45
49
  let {
46
50
  clientId,
47
51
  onSwitch = noop,
48
52
  onHoverClassName = noop,
49
- itemRole
50
- } = _ref;
51
-
52
- const selector = select => {
53
- const {
54
- getBlock
55
- } = select(blockEditorStore);
56
- const block = getBlock(clientId);
53
+ scope
54
+ } = _ref3;
55
+ const {
56
+ onSelect,
57
+ stylesToRender,
58
+ activeStyle,
59
+ genericPreviewBlock,
60
+ className: previewClassName
61
+ } = useStylesForBlocks({
62
+ clientId,
63
+ onSwitch
64
+ });
65
+ const [hoveredStyle, setHoveredStyle] = useState(null);
66
+ const [containerScrollTop, setContainerScrollTop] = useState(0);
67
+ const isMobileViewport = useViewportMatch('medium', '<');
68
+ useLayoutEffect(() => {
69
+ const scrollContainer = document.querySelector('.interface-interface-skeleton__content');
70
+ const scrollTop = (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTop) || 0;
71
+ setContainerScrollTop(scrollTop + DEFAULT_POSITION_TOP);
72
+ }, [hoveredStyle]);
73
+
74
+ if (!stylesToRender || stylesToRender.length === 0) {
75
+ return null;
76
+ }
57
77
 
58
- if (!block) {
59
- return EMPTY_OBJECT;
60
- }
78
+ const debouncedSetHoveredStyle = debounce(setHoveredStyle, 250);
61
79
 
62
- const blockType = getBlockType(block.name);
63
- const {
64
- getBlockStyles
65
- } = select(blocksStore);
66
- return {
67
- block,
68
- type: blockType,
69
- styles: getBlockStyles(block.name),
70
- className: block.attributes.className || ''
71
- };
80
+ const onSelectStylePreview = style => {
81
+ onSelect(style);
82
+ onHoverClassName(null);
83
+ setHoveredStyle(null);
84
+ debouncedSetHoveredStyle.cancel();
72
85
  };
73
86
 
74
- const {
75
- styles,
76
- block,
77
- type,
78
- className
79
- } = useSelect(selector, [clientId]);
80
- const {
81
- updateBlockAttributes
82
- } = useDispatch(blockEditorStore);
83
- const genericPreviewBlock = useGenericPreviewBlock(block, type);
87
+ const styleItemHandler = item => {
88
+ var _item$name;
84
89
 
85
- if (!styles || styles.length === 0) {
86
- return null;
87
- }
90
+ if (hoveredStyle === item) {
91
+ debouncedSetHoveredStyle.cancel();
92
+ return;
93
+ }
94
+
95
+ debouncedSetHoveredStyle(item);
96
+ onHoverClassName((_item$name = item === null || item === void 0 ? void 0 : item.name) !== null && _item$name !== void 0 ? _item$name : null);
97
+ };
88
98
 
89
- const renderedStyles = find(styles, 'isDefault') ? styles : [{
90
- name: 'default',
91
- label: _x('Default', 'block style'),
92
- isDefault: true
93
- }, ...styles];
94
- const activeStyle = getActiveStyle(renderedStyles, className);
95
99
  return createElement("div", {
96
100
  className: "block-editor-block-styles"
97
- }, renderedStyles.map(style => {
98
- var _type$example$viewpor, _type$example;
99
-
100
- const styleClassName = replaceActiveStyle(className, activeStyle, style);
101
- return createElement(BlockStyleItem, {
102
- genericPreviewBlock: genericPreviewBlock,
103
- viewportWidth: (_type$example$viewpor = (_type$example = type.example) === null || _type$example === void 0 ? void 0 : _type$example.viewportWidth) !== null && _type$example$viewpor !== void 0 ? _type$example$viewpor : 500,
104
- className: className,
105
- isActive: activeStyle === style,
101
+ }, createElement("div", {
102
+ className: "block-editor-block-styles__variants"
103
+ }, stylesToRender.map(style => {
104
+ const buttonText = style.label || style.name;
105
+ return createElement(Button, {
106
+ className: classnames('block-editor-block-styles__item', {
107
+ 'is-active': activeStyle.name === style.name
108
+ }),
106
109
  key: style.name,
107
- onSelect: () => {
108
- updateBlockAttributes(clientId, {
109
- className: styleClassName
110
- });
111
- onHoverClassName(null);
112
- onSwitch();
110
+ variant: "secondary",
111
+ label: buttonText,
112
+ onMouseEnter: () => styleItemHandler(style),
113
+ onFocus: () => styleItemHandler(style),
114
+ onMouseLeave: () => styleItemHandler(null),
115
+ onBlur: () => styleItemHandler(null),
116
+ onKeyDown: event => {
117
+ if (ENTER === event.keyCode || SPACE === event.keyCode) {
118
+ event.preventDefault();
119
+ onSelectStylePreview(style);
120
+ }
113
121
  },
114
- onBlur: () => onHoverClassName(null),
115
- onHover: () => onHoverClassName(styleClassName),
116
- style: style,
117
- styleClassName: styleClassName,
118
- itemRole: itemRole
119
- });
120
- }));
121
- }
122
-
123
- function BlockStyleItem(_ref2) {
124
- let {
125
- genericPreviewBlock,
126
- viewportWidth,
127
- style,
128
- isActive,
129
- onBlur,
130
- onHover,
131
- onSelect,
132
- styleClassName,
133
- itemRole
134
- } = _ref2;
135
- const previewBlocks = useMemo(() => {
136
- return { ...genericPreviewBlock,
137
- attributes: { ...genericPreviewBlock.attributes,
138
- className: styleClassName
139
- }
140
- };
141
- }, [genericPreviewBlock, styleClassName]);
142
- return createElement("div", {
143
- key: style.name,
144
- className: classnames('block-editor-block-styles__item', {
145
- 'is-active': isActive
146
- }),
147
- onClick: () => onSelect(),
148
- onKeyDown: event => {
149
- if (ENTER === event.keyCode || SPACE === event.keyCode) {
150
- event.preventDefault();
151
- onSelect();
152
- }
122
+ onClick: () => onSelectStylePreview(style),
123
+ role: "button",
124
+ tabIndex: "0"
125
+ }, createElement(Text, {
126
+ as: "span",
127
+ limit: 12,
128
+ ellipsizeMode: "tail",
129
+ className: "block-editor-block-styles__item-text",
130
+ truncate: true
131
+ }, buttonText));
132
+ })), hoveredStyle && !isMobileViewport && createElement(BlockStylesPreviewPanelFill, {
133
+ scope: scope,
134
+ className: "block-editor-block-styles__preview-panel",
135
+ style: {
136
+ top: containerScrollTop
153
137
  },
154
- onMouseEnter: onHover,
155
- onMouseLeave: onBlur,
156
- role: itemRole || 'button',
157
- tabIndex: "0",
158
- "aria-label": style.label || style.name
159
- }, createElement("div", {
160
- className: "block-editor-block-styles__item-preview"
161
- }, createElement(BlockPreview, {
162
- viewportWidth: viewportWidth,
163
- blocks: previewBlocks
164
- })), createElement("div", {
165
- className: "block-editor-block-styles__item-label"
166
- }, style.label || style.name));
138
+ onMouseLeave: () => styleItemHandler(null)
139
+ }, createElement(BlockStylesPreviewPanel, {
140
+ activeStyle: activeStyle,
141
+ className: previewClassName,
142
+ genericPreviewBlock: genericPreviewBlock,
143
+ style: hoveredStyle
144
+ })));
167
145
  }
168
146
 
147
+ BlockStyles.Slot = BlockStylesPreviewPanelSlot;
169
148
  export default BlockStyles;
170
149
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/index.js"],"names":["find","noop","classnames","useMemo","useSelect","useDispatch","ENTER","SPACE","_x","getBlockType","cloneBlock","getBlockFromExample","store","blocksStore","getActiveStyle","replaceActiveStyle","BlockPreview","blockEditorStore","EMPTY_OBJECT","useGenericPreviewBlock","block","type","example","blockName","name","attributes","innerBlocks","BlockStyles","clientId","onSwitch","onHoverClassName","itemRole","selector","select","getBlock","blockType","getBlockStyles","styles","className","updateBlockAttributes","genericPreviewBlock","length","renderedStyles","label","isDefault","activeStyle","map","style","styleClassName","viewportWidth","BlockStyleItem","isActive","onBlur","onHover","onSelect","previewBlocks","event","keyCode","preventDefault"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,IAAf,QAA2B,QAA3B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAT,EAAgBC,KAAhB,QAA6B,qBAA7B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,YADD,EAECC,UAFD,EAGCC,mBAHD,EAICC,KAAK,IAAIC,WAJV,QAKO,mBALP;AAOA;AACA;AACA;;AACA,SAASC,cAAT,EAAyBC,kBAAzB,QAAmD,SAAnD;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,SAASJ,KAAK,IAAIK,gBAAlB,QAA0C,aAA1C;AAEA,MAAMC,YAAY,GAAG,EAArB;;AAEA,SAASC,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SAAOlB,OAAO,CAAE,MAAM;AACrB,UAAMmB,OAAO,GAAGD,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEC,OAAtB;AACA,UAAMC,SAAS,GAAGF,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEG,IAAxB;;AAEA,QAAKF,OAAO,IAAIC,SAAhB,EAA4B;AAC3B,aAAOZ,mBAAmB,CAAEY,SAAF,EAAa;AACtCE,QAAAA,UAAU,EAAEH,OAAO,CAACG,UADkB;AAEtCC,QAAAA,WAAW,EAAEJ,OAAO,CAACI;AAFiB,OAAb,CAA1B;AAIA;;AAED,QAAKN,KAAL,EAAa;AACZ,aAAOV,UAAU,CAAEU,KAAF,CAAjB;AACA;AACD,GAda,EAcX,CAAEC,IAAI,SAAJ,IAAAA,IAAI,WAAJ,IAAAA,IAAI,CAAEC,OAAN,GAAgBF,KAAhB,aAAgB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AS,EAAC;AAAf,KACGR,KAAK,CAACJ,KAAN,IAAeI,KAAK,CAACvB,IADxB,CAxBD,CADD;AA8BA;;AAED,eAAeG,WAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { find, noop } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { ENTER, SPACE } from '@wordpress/keycodes';\nimport { _x } from '@wordpress/i18n';\nimport {\n\tgetBlockType,\n\tcloneBlock,\n\tgetBlockFromExample,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { getActiveStyle, replaceActiveStyle } from './utils';\nimport BlockPreview from '../block-preview';\nimport { store as blockEditorStore } from '../../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction useGenericPreviewBlock( block, type ) {\n\treturn useMemo( () => {\n\t\tconst example = type?.example;\n\t\tconst blockName = type?.name;\n\n\t\tif ( example && blockName ) {\n\t\t\treturn getBlockFromExample( blockName, {\n\t\t\t\tattributes: example.attributes,\n\t\t\t\tinnerBlocks: example.innerBlocks,\n\t\t\t} );\n\t\t}\n\n\t\tif ( block ) {\n\t\t\treturn cloneBlock( block );\n\t\t}\n\t}, [ type?.example ? block?.name : block, type ] );\n}\n\nfunction BlockStyles( {\n\tclientId,\n\tonSwitch = noop,\n\tonHoverClassName = noop,\n\titemRole,\n} ) {\n\tconst selector = ( select ) => {\n\t\tconst { getBlock } = select( blockEditorStore );\n\t\tconst block = getBlock( clientId );\n\n\t\tif ( ! block ) {\n\t\t\treturn EMPTY_OBJECT;\n\t\t}\n\n\t\tconst blockType = getBlockType( block.name );\n\t\tconst { getBlockStyles } = select( blocksStore );\n\t\treturn {\n\t\t\tblock,\n\t\t\ttype: blockType,\n\t\t\tstyles: getBlockStyles( block.name ),\n\t\t\tclassName: block.attributes.className || '',\n\t\t};\n\t};\n\n\tconst { styles, block, type, className } = useSelect( selector, [\n\t\tclientId,\n\t] );\n\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst genericPreviewBlock = useGenericPreviewBlock( block, type );\n\n\tif ( ! styles || styles.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst renderedStyles = find( styles, 'isDefault' )\n\t\t? styles\n\t\t: [\n\t\t\t\t{\n\t\t\t\t\tname: 'default',\n\t\t\t\t\tlabel: _x( 'Default', 'block style' ),\n\t\t\t\t\tisDefault: true,\n\t\t\t\t},\n\t\t\t\t...styles,\n\t\t ];\n\n\tconst activeStyle = getActiveStyle( renderedStyles, className );\n\treturn (\n\t\t<div className=\"block-editor-block-styles\">\n\t\t\t{ renderedStyles.map( ( style ) => {\n\t\t\t\tconst styleClassName = replaceActiveStyle(\n\t\t\t\t\tclassName,\n\t\t\t\t\tactiveStyle,\n\t\t\t\t\tstyle\n\t\t\t\t);\n\t\t\t\treturn (\n\t\t\t\t\t<BlockStyleItem\n\t\t\t\t\t\tgenericPreviewBlock={ genericPreviewBlock }\n\t\t\t\t\t\tviewportWidth={ type.example?.viewportWidth ?? 500 }\n\t\t\t\t\t\tclassName={ className }\n\t\t\t\t\t\tisActive={ activeStyle === style }\n\t\t\t\t\t\tkey={ style.name }\n\t\t\t\t\t\tonSelect={ () => {\n\t\t\t\t\t\t\tupdateBlockAttributes( clientId, {\n\t\t\t\t\t\t\t\tclassName: styleClassName,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tonHoverClassName( null );\n\t\t\t\t\t\t\tonSwitch();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonBlur={ () => onHoverClassName( null ) }\n\t\t\t\t\t\tonHover={ () => onHoverClassName( styleClassName ) }\n\t\t\t\t\t\tstyle={ style }\n\t\t\t\t\t\tstyleClassName={ styleClassName }\n\t\t\t\t\t\titemRole={ itemRole }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</div>\n\t);\n}\n\nfunction BlockStyleItem( {\n\tgenericPreviewBlock,\n\tviewportWidth,\n\tstyle,\n\tisActive,\n\tonBlur,\n\tonHover,\n\tonSelect,\n\tstyleClassName,\n\titemRole,\n} ) {\n\tconst previewBlocks = useMemo( () => {\n\t\treturn {\n\t\t\t...genericPreviewBlock,\n\t\t\tattributes: {\n\t\t\t\t...genericPreviewBlock.attributes,\n\t\t\t\tclassName: styleClassName,\n\t\t\t},\n\t\t};\n\t}, [ genericPreviewBlock, styleClassName ] );\n\n\treturn (\n\t\t<div\n\t\t\tkey={ style.name }\n\t\t\tclassName={ classnames( 'block-editor-block-styles__item', {\n\t\t\t\t'is-active': isActive,\n\t\t\t} ) }\n\t\t\tonClick={ () => onSelect() }\n\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\tif ( ENTER === event.keyCode || SPACE === event.keyCode ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tonSelect();\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonMouseEnter={ onHover }\n\t\t\tonMouseLeave={ onBlur }\n\t\t\trole={ itemRole || 'button' }\n\t\t\ttabIndex=\"0\"\n\t\t\taria-label={ style.label || style.name }\n\t\t>\n\t\t\t<div className=\"block-editor-block-styles__item-preview\">\n\t\t\t\t<BlockPreview\n\t\t\t\t\tviewportWidth={ viewportWidth }\n\t\t\t\t\tblocks={ previewBlocks }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div className=\"block-editor-block-styles__item-label\">\n\t\t\t\t{ style.label || style.name }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default BlockStyles;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/index.js"],"names":["noop","debounce","classnames","useState","useLayoutEffect","useViewportMatch","ENTER","SPACE","Button","__experimentalText","Text","Slot","Fill","BlockStylesPreviewPanel","useStylesForBlocks","BlockStylesPreviewPanelSlot","scope","BlockStylesPreviewPanelFill","children","props","DEFAULT_POSITION_TOP","BlockStyles","clientId","onSwitch","onHoverClassName","onSelect","stylesToRender","activeStyle","genericPreviewBlock","className","previewClassName","hoveredStyle","setHoveredStyle","containerScrollTop","setContainerScrollTop","isMobileViewport","scrollContainer","document","querySelector","scrollTop","length","debouncedSetHoveredStyle","onSelectStylePreview","style","cancel","styleItemHandler","item","name","map","buttonText","label","event","keyCode","preventDefault","top"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,QAA+B,QAA/B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,eAAnB,QAA0C,oBAA1C;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,KAAT,EAAgBC,KAAhB,QAA6B,qBAA7B;AACA,SACCC,MADD,EAECC,kBAAkB,IAAIC,IAFvB,EAGCC,IAHD,EAICC,IAJD,QAKO,uBALP;AAOA;AACA;AACA;;AACA,OAAOC,uBAAP,MAAoC,iBAApC;AACA,OAAOC,kBAAP,MAA+B,wBAA/B;;AAEA,SAASC,2BAAT,OAAkD;AAAA,MAAZ;AAAEC,IAAAA;AAAF,GAAY;AACjD,SAAO,cAAC,IAAD;AAAM,IAAA,IAAI,EAAI,2BAA2BA,KAAO;AAAhD,IAAP;AACA;;AAED,SAASC,2BAAT,QAAsE;AAAA,MAAhC;AAAEC,IAAAA,QAAF;AAAYF,IAAAA,KAAZ;AAAmB,OAAGG;AAAtB,GAAgC;AACrE,SACC,cAAC,IAAD;AAAM,IAAA,IAAI,EAAI,2BAA2BH,KAAO;AAAhD,KACC,qBAAUG,KAAV,EAAoBD,QAApB,CADD,CADD;AAKA,C,CAED;AACA;AACA;;;AACA,MAAME,oBAAoB,GAAG,EAA7B,C,CAEA;;AACA,SAASC,WAAT,QAKI;AAAA,MALkB;AACrBC,IAAAA,QADqB;AAErBC,IAAAA,QAAQ,GAAGvB,IAFU;AAGrBwB,IAAAA,gBAAgB,GAAGxB,IAHE;AAIrBgB,IAAAA;AAJqB,GAKlB;AACH,QAAM;AACLS,IAAAA,QADK;AAELC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AAK,EAAG,EAFT;AAGC,MAAA,aAAa,EAAC,MAHf;AAIC,MAAA,SAAS,EAAC,sCAJX;AAKC,MAAA,QAAQ;AALT,OAOGM,UAPH,CA5BD,CADD;AAwCA,GA3CC,CADH,CADD,EA+CGlB,YAAY,IAAI,CAAEI,gBAAlB,IACD,cAAC,2BAAD;AACC,IAAA,KAAK,EAAGnB,KADT;AAEC,IAAA,SAAS,EAAC,0CAFX;AAGC,IAAA,KAAK,EAAG;AAAEsC,MAAAA,GAAG,EAAErB;AAAP,KAHT;AAIC,IAAA,YAAY,EAAG,MAAMY,gBAAgB,CAAE,IAAF;AAJtC,KAMC,cAAC,uBAAD;AACC,IAAA,WAAW,EAAGlB,WADf;AAEC,IAAA,SAAS,EAAGG,gBAFb;AAGC,IAAA,mBAAmB,EAAGF,mBAHvB;AAIC,IAAA,KAAK,EAAGG;AAJT,IAND,CAhDF,CADD;AAiEA;;AAEDV,WAAW,CAACV,IAAZ,GAAmBI,2BAAnB;AACA,eAAeM,WAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { noop, debounce } from 'lodash';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { ENTER, SPACE } from '@wordpress/keycodes';\nimport {\n\tButton,\n\t__experimentalText as Text,\n\tSlot,\n\tFill,\n} from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport BlockStylesPreviewPanel from './preview-panel';\nimport useStylesForBlocks from './use-styles-for-block';\n\nfunction BlockStylesPreviewPanelSlot( { scope } ) {\n\treturn <Slot name={ `BlockStylesPreviewPanel/${ scope }` } />;\n}\n\nfunction BlockStylesPreviewPanelFill( { children, scope, ...props } ) {\n\treturn (\n\t\t<Fill name={ `BlockStylesPreviewPanel/${ scope }` }>\n\t\t\t<div { ...props }>{ children }</div>\n\t\t</Fill>\n\t);\n}\n\n// Top position (in px) of the Block Styles container\n// relative to the editor pane.\n// The value is the equivalent of the container's right position.\nconst DEFAULT_POSITION_TOP = 16;\n\n// Block Styles component for the Settings Sidebar.\nfunction BlockStyles( {\n\tclientId,\n\tonSwitch = noop,\n\tonHoverClassName = noop,\n\tscope,\n} ) {\n\tconst {\n\t\tonSelect,\n\t\tstylesToRender,\n\t\tactiveStyle,\n\t\tgenericPreviewBlock,\n\t\tclassName: previewClassName,\n\t} = useStylesForBlocks( {\n\t\tclientId,\n\t\tonSwitch,\n\t} );\n\tconst [ hoveredStyle, setHoveredStyle ] = useState( null );\n\tconst [ containerScrollTop, setContainerScrollTop ] = useState( 0 );\n\tconst isMobileViewport = useViewportMatch( 'medium', '<' );\n\n\tuseLayoutEffect( () => {\n\t\tconst scrollContainer = document.querySelector(\n\t\t\t'.interface-interface-skeleton__content'\n\t\t);\n\t\tconst scrollTop = scrollContainer?.scrollTop || 0;\n\t\tsetContainerScrollTop( scrollTop + DEFAULT_POSITION_TOP );\n\t}, [ hoveredStyle ] );\n\n\tif ( ! stylesToRender || stylesToRender.length === 0 ) {\n\t\treturn null;\n\t}\n\n\tconst debouncedSetHoveredStyle = debounce( setHoveredStyle, 250 );\n\n\tconst onSelectStylePreview = ( style ) => {\n\t\tonSelect( style );\n\t\tonHoverClassName( null );\n\t\tsetHoveredStyle( null );\n\t\tdebouncedSetHoveredStyle.cancel();\n\t};\n\n\tconst styleItemHandler = ( item ) => {\n\t\tif ( hoveredStyle === item ) {\n\t\t\tdebouncedSetHoveredStyle.cancel();\n\t\t\treturn;\n\t\t}\n\t\tdebouncedSetHoveredStyle( item );\n\t\tonHoverClassName( item?.name ?? null );\n\t};\n\n\treturn (\n\t\t<div className=\"block-editor-block-styles\">\n\t\t\t<div className=\"block-editor-block-styles__variants\">\n\t\t\t\t{ stylesToRender.map( ( style ) => {\n\t\t\t\t\tconst buttonText = style.label || style.name;\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-block-styles__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'is-active':\n\t\t\t\t\t\t\t\t\t\tactiveStyle.name === style.name,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tkey={ style.name }\n\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\tlabel={ buttonText }\n\t\t\t\t\t\t\tonMouseEnter={ () => styleItemHandler( style ) }\n\t\t\t\t\t\t\tonFocus={ () => styleItemHandler( style ) }\n\t\t\t\t\t\t\tonMouseLeave={ () => styleItemHandler( null ) }\n\t\t\t\t\t\t\tonBlur={ () => styleItemHandler( null ) }\n\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tENTER === event.keyCode ||\n\t\t\t\t\t\t\t\t\tSPACE === event.keyCode\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t\tonSelectStylePreview( style );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonClick={ () => onSelectStylePreview( style ) }\n\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\ttabIndex=\"0\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlimit={ 12 }\n\t\t\t\t\t\t\t\tellipsizeMode=\"tail\"\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-styles__item-text\"\n\t\t\t\t\t\t\t\ttruncate\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ buttonText }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</div>\n\t\t\t{ hoveredStyle && ! isMobileViewport && (\n\t\t\t\t<BlockStylesPreviewPanelFill\n\t\t\t\t\tscope={ scope }\n\t\t\t\t\tclassName=\"block-editor-block-styles__preview-panel\"\n\t\t\t\t\tstyle={ { top: containerScrollTop } }\n\t\t\t\t\tonMouseLeave={ () => styleItemHandler( null ) }\n\t\t\t\t>\n\t\t\t\t\t<BlockStylesPreviewPanel\n\t\t\t\t\t\tactiveStyle={ activeStyle }\n\t\t\t\t\t\tclassName={ previewClassName }\n\t\t\t\t\t\tgenericPreviewBlock={ genericPreviewBlock }\n\t\t\t\t\t\tstyle={ hoveredStyle }\n\t\t\t\t\t/>\n\t\t\t\t</BlockStylesPreviewPanelFill>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nBlockStyles.Slot = BlockStylesPreviewPanelSlot;\nexport default BlockStyles;\n"]}
@@ -0,0 +1,50 @@
1
+ import { createElement, Fragment } from "@wordpress/element";
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import { noop } from 'lodash';
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+
11
+ import { MenuItem, __experimentalText as Text } from '@wordpress/components';
12
+ import { check } from '@wordpress/icons';
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+
17
+ import useStylesForBlocks from './use-styles-for-block';
18
+ export default function BlockStylesMenuItems(_ref) {
19
+ let {
20
+ clientId,
21
+ onSwitch = noop
22
+ } = _ref;
23
+ const {
24
+ onSelect,
25
+ stylesToRender,
26
+ activeStyle
27
+ } = useStylesForBlocks({
28
+ clientId,
29
+ onSwitch
30
+ });
31
+
32
+ if (!stylesToRender || stylesToRender.length === 0) {
33
+ return null;
34
+ }
35
+
36
+ return createElement(Fragment, null, stylesToRender.map(style => {
37
+ const menuItemText = style.label || style.name;
38
+ return createElement(MenuItem, {
39
+ key: style.name,
40
+ icon: activeStyle.name === style.name ? check : null,
41
+ onClick: () => onSelect(style)
42
+ }, createElement(Text, {
43
+ as: "span",
44
+ limit: 18,
45
+ ellipsizeMode: "tail",
46
+ truncate: true
47
+ }, menuItemText));
48
+ }));
49
+ }
50
+ //# sourceMappingURL=menu-items.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/menu-items.js"],"names":["noop","MenuItem","__experimentalText","Text","check","useStylesForBlocks","BlockStylesMenuItems","clientId","onSwitch","onSelect","stylesToRender","activeStyle","length","map","style","menuItemText","label","name"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,kBAAkB,IAAIC,IAAzC,QAAqD,uBAArD;AACA,SAASC,KAAT,QAAsB,kBAAtB;AAEA;AACA;AACA;;AACA,OAAOC,kBAAP,MAA+B,wBAA/B;AAEA,eAAe,SAASC,oBAAT,OAA+D;AAAA,MAAhC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,QAAQ,GAAGR;AAAvB,GAAgC;AAC7E,QAAM;AAAES,IAAAA,QAAF;AAAYC,IAAAA,cAAZ;AAA4BC,IAAAA;AAA5B,MAA4CN,kBAAkB,CAAE;AACrEE,IAAAA,QADqE;AAErEC,IAAAA;AAFqE,GAAF,CAApE;;AAKA,MAAK,CAAEE,cAAF,IAAoBA,cAAc,CAACE,MAAf,KAA0B,CAAnD,EAAuD;AACtD,WAAO,IAAP;AACA;;AACD,SACC,8BACGF,cAAc,CAACG,GAAf,CAAsBC,KAAF,IAAa;AAClC,UAAMC,YAAY,GAAGD,KAAK,CAACE,KAAN,IAAeF,KAAK,CAACG,IAA1C;AACA,WACC,cAAC,QAAD;AACC,MAAA,GAAG,EAAGH,KAAK,CAACG,IADb;AAEC,MAAA,IAAI,EAAGN,WAAW,CAACM,IAAZ,KAAqBH,KAAK,CAACG,IAA3B,GAAkCb,KAAlC,GAA0C,IAFlD;AAGC,MAAA,OAAO,EAAG,MAAMK,QAAQ,CAAEK,KAAF;AAHzB,OAKC,cAAC,IAAD;AACC,MAAA,EAAE,EAAC,MADJ;AAEC,MAAA,KAAK,EAAG,EAFT;AAGC,MAAA,aAAa,EAAC,MAHf;AAIC,MAAA,QAAQ;AAJT,OAMGC,YANH,CALD,CADD;AAgBA,GAlBC,CADH,CADD;AAuBA","sourcesContent":["/**\n * External dependencies\n */\nimport { noop } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { MenuItem, __experimentalText as Text } from '@wordpress/components';\nimport { check } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport useStylesForBlocks from './use-styles-for-block';\n\nexport default function BlockStylesMenuItems( { clientId, onSwitch = noop } ) {\n\tconst { onSelect, stylesToRender, activeStyle } = useStylesForBlocks( {\n\t\tclientId,\n\t\tonSwitch,\n\t} );\n\n\tif ( ! stylesToRender || stylesToRender.length === 0 ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ stylesToRender.map( ( style ) => {\n\t\t\t\tconst menuItemText = style.label || style.name;\n\t\t\t\treturn (\n\t\t\t\t\t<MenuItem\n\t\t\t\t\t\tkey={ style.name }\n\t\t\t\t\t\ticon={ activeStyle.name === style.name ? check : null }\n\t\t\t\t\t\tonClick={ () => onSelect( style ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\tlimit={ 18 }\n\t\t\t\t\t\t\tellipsizeMode=\"tail\"\n\t\t\t\t\t\t\ttruncate\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ menuItemText }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t</MenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { createElement } from "@wordpress/element";
2
+
3
+ /**
4
+ * WordPress dependencies
5
+ */
6
+ import { useMemo } from '@wordpress/element';
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+
11
+ import InserterPreviewPanel from '../inserter/preview-panel';
12
+ import { replaceActiveStyle } from './utils';
13
+ export default function BlockStylesPreviewPanel(_ref) {
14
+ let {
15
+ genericPreviewBlock,
16
+ style,
17
+ className,
18
+ activeStyle
19
+ } = _ref;
20
+ const styleClassName = replaceActiveStyle(className, activeStyle, style);
21
+ const previewBlocks = useMemo(() => {
22
+ return { ...genericPreviewBlock,
23
+ title: style.label || style.name,
24
+ description: style.description,
25
+ initialAttributes: { ...genericPreviewBlock.attributes,
26
+ className: styleClassName + ' block-editor-block-styles__block-preview-container'
27
+ }
28
+ };
29
+ }, [genericPreviewBlock, styleClassName]);
30
+ return createElement(InserterPreviewPanel, {
31
+ item: previewBlocks,
32
+ isStylePreview: true
33
+ });
34
+ }
35
+ //# sourceMappingURL=preview-panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/preview-panel.js"],"names":["useMemo","InserterPreviewPanel","replaceActiveStyle","BlockStylesPreviewPanel","genericPreviewBlock","style","className","activeStyle","styleClassName","previewBlocks","title","label","name","description","initialAttributes","attributes"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,oBAAP,MAAiC,2BAAjC;AACA,SAASC,kBAAT,QAAmC,SAAnC;AAEA,eAAe,SAASC,uBAAT,OAKX;AAAA,MAL6C;AAChDC,IAAAA,mBADgD;AAEhDC,IAAAA,KAFgD;AAGhDC,IAAAA,SAHgD;AAIhDC,IAAAA;AAJgD,GAK7C;AACH,QAAMC,cAAc,GAAGN,kBAAkB,CAAEI,SAAF,EAAaC,WAAb,EAA0BF,KAA1B,CAAzC;AACA,QAAMI,aAAa,GAAGT,OAAO,CAAE,MAAM;AACpC,WAAO,EACN,GAAGI,mBADG;AAENM,MAAAA,KAAK,EAAEL,KAAK,CAACM,KAAN,IAAeN,KAAK,CAACO,IAFtB;AAGNC,MAAAA,WAAW,EAAER,KAAK,CAACQ,WAHb;AAINC,MAAAA,iBAAiB,EAAE,EAClB,GAAGV,mBAAmB,CAACW,UADL;AAElBT,QAAAA,SAAS,EACRE,cAAc,GACd;AAJiB;AAJb,KAAP;AAWA,GAZ4B,EAY1B,CAAEJ,mBAAF,EAAuBI,cAAvB,CAZ0B,CAA7B;AAcA,SACC,cAAC,oBAAD;AAAsB,IAAA,IAAI,EAAGC,aAA7B;AAA6C,IAAA,cAAc,EAAG;AAA9D,IADD;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport InserterPreviewPanel from '../inserter/preview-panel';\nimport { replaceActiveStyle } from './utils';\n\nexport default function BlockStylesPreviewPanel( {\n\tgenericPreviewBlock,\n\tstyle,\n\tclassName,\n\tactiveStyle,\n} ) {\n\tconst styleClassName = replaceActiveStyle( className, activeStyle, style );\n\tconst previewBlocks = useMemo( () => {\n\t\treturn {\n\t\t\t...genericPreviewBlock,\n\t\t\ttitle: style.label || style.name,\n\t\t\tdescription: style.description,\n\t\t\tinitialAttributes: {\n\t\t\t\t...genericPreviewBlock.attributes,\n\t\t\t\tclassName:\n\t\t\t\t\tstyleClassName +\n\t\t\t\t\t' block-editor-block-styles__block-preview-container',\n\t\t\t},\n\t\t};\n\t}, [ genericPreviewBlock, styleClassName ] );\n\n\treturn (\n\t\t<InserterPreviewPanel item={ previewBlocks } isStylePreview={ true } />\n\t);\n}\n"]}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useDispatch, useSelect } from '@wordpress/data';
5
+ import { cloneBlock, getBlockType, getBlockFromExample, store as blocksStore } from '@wordpress/blocks';
6
+ import { useMemo } from '@wordpress/element';
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+
11
+ import { getActiveStyle, getRenderedStyles, replaceActiveStyle } from './utils';
12
+ import { store as blockEditorStore } from '../../store';
13
+ /**
14
+ *
15
+ * @param {WPBlock} block Block object.
16
+ * @param {WPBlockType} type Block type settings.
17
+ * @return {WPBlock} A generic block ready for styles preview.
18
+ */
19
+
20
+ function useGenericPreviewBlock(block, type) {
21
+ return useMemo(() => {
22
+ const example = type === null || type === void 0 ? void 0 : type.example;
23
+ const blockName = type === null || type === void 0 ? void 0 : type.name;
24
+
25
+ if (example && blockName) {
26
+ return getBlockFromExample(blockName, {
27
+ attributes: example.attributes,
28
+ innerBlocks: example.innerBlocks
29
+ });
30
+ }
31
+
32
+ if (block) {
33
+ return cloneBlock(block);
34
+ }
35
+ }, [type !== null && type !== void 0 && type.example ? block === null || block === void 0 ? void 0 : block.name : block, type]);
36
+ }
37
+ /**
38
+ * @typedef useStylesForBlocksArguments
39
+ * @property {string} clientId Block client ID.
40
+ * @property {() => void} onSwitch Block style switch callback function.
41
+ */
42
+
43
+ /**
44
+ *
45
+ * @param {useStylesForBlocksArguments} useStylesForBlocks arguments.
46
+ * @return {Object} Results of the select methods.
47
+ */
48
+
49
+
50
+ export default function useStylesForBlocks(_ref) {
51
+ let {
52
+ clientId,
53
+ onSwitch
54
+ } = _ref;
55
+
56
+ const selector = select => {
57
+ const {
58
+ getBlock
59
+ } = select(blockEditorStore);
60
+ const block = getBlock(clientId);
61
+
62
+ if (!block) {
63
+ return {};
64
+ }
65
+
66
+ const blockType = getBlockType(block.name);
67
+ const {
68
+ getBlockStyles
69
+ } = select(blocksStore);
70
+ return {
71
+ block,
72
+ blockType,
73
+ styles: getBlockStyles(block.name),
74
+ className: block.attributes.className || ''
75
+ };
76
+ };
77
+
78
+ const {
79
+ styles,
80
+ block,
81
+ blockType,
82
+ className
83
+ } = useSelect(selector, [clientId]);
84
+ const {
85
+ updateBlockAttributes
86
+ } = useDispatch(blockEditorStore);
87
+ const stylesToRender = getRenderedStyles(styles);
88
+ const activeStyle = getActiveStyle(stylesToRender, className);
89
+ const genericPreviewBlock = useGenericPreviewBlock(block, blockType);
90
+
91
+ const onSelect = style => {
92
+ const styleClassName = replaceActiveStyle(className, activeStyle, style);
93
+ updateBlockAttributes(clientId, {
94
+ className: styleClassName
95
+ });
96
+ onSwitch();
97
+ };
98
+
99
+ return {
100
+ onSelect,
101
+ stylesToRender,
102
+ activeStyle,
103
+ genericPreviewBlock,
104
+ className
105
+ };
106
+ }
107
+ //# sourceMappingURL=use-styles-for-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/use-styles-for-block.js"],"names":["useDispatch","useSelect","cloneBlock","getBlockType","getBlockFromExample","store","blocksStore","useMemo","getActiveStyle","getRenderedStyles","replaceActiveStyle","blockEditorStore","useGenericPreviewBlock","block","type","example","blockName","name","attributes","innerBlocks","useStylesForBlocks","clientId","onSwitch","selector","select","getBlock","blockType","getBlockStyles","styles","className","updateBlockAttributes","stylesToRender","activeStyle","genericPreviewBlock","onSelect","style","styleClassName"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,UADD,EAECC,YAFD,EAGCC,mBAHD,EAICC,KAAK,IAAIC,WAJV,QAKO,mBALP;AAMA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,SAASC,cAAT,EAAyBC,iBAAzB,EAA4CC,kBAA5C,QAAsE,SAAtE;AACA,SAASL,KAAK,IAAIM,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SAAOP,OAAO,CAAE,MAAM;AACrB,UAAMQ,OAAO,GAAGD,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEC,OAAtB;AACA,UAAMC,SAAS,GAAGF,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEG,IAAxB;;AAEA,QAAKF,OAAO,IAAIC,SAAhB,EAA4B;AAC3B,aAAOZ,mBAAmB,CAAEY,SAAF,EAAa;AACtCE,QAAAA,UAAU,EAAEH,OAAO,CAACG,UADkB;AAEtCC,QAAAA,WAAW,EAAEJ,OAAO,CAACI;AAFiB,OAAb,CAA1B;AAIA;;AAED,QAAKN,KAAL,EAAa;AACZ,aAAOX,U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AAW,GAAGxB,cAAc,CAAEuB,cAAF,EAAkBF,SAAlB,CAAlC;AACA,QAAMI,mBAAmB,GAAGrB,sBAAsB,CAAEC,KAAF,EAASa,SAAT,CAAlD;;AAEA,QAAMQ,QAAQ,GAAKC,KAAF,IAAa;AAC7B,UAAMC,cAAc,GAAG1B,kBAAkB,CACxCmB,SADwC,EAExCG,WAFwC,EAGxCG,KAHwC,CAAzC;AAKAL,IAAAA,qBAAqB,CAAET,QAAF,EAAY;AAChCQ,MAAAA,SAAS,EAAEO;AADqB,KAAZ,CAArB;AAGAd,IAAAA,QAAQ;AACR,GAVD;;AAYA,SAAO;AACNY,IAAAA,QADM;AAENH,IAAAA,cAFM;AAGNC,IAAAA,WAHM;AAINC,IAAAA,mBAJM;AAKNJ,IAAAA;AALM,GAAP;AAOA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tcloneBlock,\n\tgetBlockType,\n\tgetBlockFromExample,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { getActiveStyle, getRenderedStyles, replaceActiveStyle } from './utils';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n *\n * @param {WPBlock} block Block object.\n * @param {WPBlockType} type Block type settings.\n * @return {WPBlock} A generic block ready for styles preview.\n */\nfunction useGenericPreviewBlock( block, type ) {\n\treturn useMemo( () => {\n\t\tconst example = type?.example;\n\t\tconst blockName = type?.name;\n\n\t\tif ( example && blockName ) {\n\t\t\treturn getBlockFromExample( blockName, {\n\t\t\t\tattributes: example.attributes,\n\t\t\t\tinnerBlocks: example.innerBlocks,\n\t\t\t} );\n\t\t}\n\n\t\tif ( block ) {\n\t\t\treturn cloneBlock( block );\n\t\t}\n\t}, [ type?.example ? block?.name : block, type ] );\n}\n\n/**\n * @typedef useStylesForBlocksArguments\n * @property {string} clientId Block client ID.\n * @property {() => void} onSwitch Block style switch callback function.\n */\n\n/**\n *\n * @param {useStylesForBlocksArguments} useStylesForBlocks arguments.\n * @return {Object} Results of the select methods.\n */\nexport default function useStylesForBlocks( { clientId, onSwitch } ) {\n\tconst selector = ( select ) => {\n\t\tconst { getBlock } = select( blockEditorStore );\n\t\tconst block = getBlock( clientId );\n\n\t\tif ( ! block ) {\n\t\t\treturn {};\n\t\t}\n\t\tconst blockType = getBlockType( block.name );\n\t\tconst { getBlockStyles } = select( blocksStore );\n\n\t\treturn {\n\t\t\tblock,\n\t\t\tblockType,\n\t\t\tstyles: getBlockStyles( block.name ),\n\t\t\tclassName: block.attributes.className || '',\n\t\t};\n\t};\n\tconst { styles, block, blockType, className } = useSelect( selector, [\n\t\tclientId,\n\t] );\n\tconst { updateBlockAttributes } = useDispatch( blockEditorStore );\n\tconst stylesToRender = getRenderedStyles( styles );\n\tconst activeStyle = getActiveStyle( stylesToRender, className );\n\tconst genericPreviewBlock = useGenericPreviewBlock( block, blockType );\n\n\tconst onSelect = ( style ) => {\n\t\tconst styleClassName = replaceActiveStyle(\n\t\t\tclassName,\n\t\t\tactiveStyle,\n\t\t\tstyle\n\t\t);\n\t\tupdateBlockAttributes( clientId, {\n\t\t\tclassName: styleClassName,\n\t\t} );\n\t\tonSwitch();\n\t};\n\n\treturn {\n\t\tonSelect,\n\t\tstylesToRender,\n\t\tactiveStyle,\n\t\tgenericPreviewBlock,\n\t\tclassName,\n\t};\n}\n"]}
@@ -7,6 +7,7 @@ import { find } from 'lodash';
7
7
  */
8
8
 
9
9
  import TokenList from '@wordpress/token-list';
10
+ import { _x } from '@wordpress/i18n';
10
11
  /**
11
12
  * Returns the active style from the given className.
12
13
  *
@@ -54,4 +55,37 @@ export function replaceActiveStyle(className, activeStyle, newStyle) {
54
55
  list.add('is-style-' + newStyle.name);
55
56
  return list.value;
56
57
  }
58
+ /**
59
+ * Returns a collection of styles that can be represented on the frontend.
60
+ * The function checks a style collection for a default style. If none is found, it adds one to
61
+ * act as a fallback for when there is no active style applied to a block. The default item also serves
62
+ * as a switch on the frontend to deactivate non-default styles.
63
+ *
64
+ * @param {Array} styles Block style variations.
65
+ *
66
+ * @return {Array<Object?>} The style collection.
67
+ */
68
+
69
+ export function getRenderedStyles(styles) {
70
+ if (!styles || styles.length === 0) {
71
+ return [];
72
+ }
73
+
74
+ return getDefaultStyle(styles) ? styles : [{
75
+ name: 'default',
76
+ label: _x('Default', 'block style'),
77
+ isDefault: true
78
+ }, ...styles];
79
+ }
80
+ /**
81
+ * Returns a style object from a collection of styles where that style object is the default block style.
82
+ *
83
+ * @param {Array} styles Block style variations.
84
+ *
85
+ * @return {Object?} The default style object, if found.
86
+ */
87
+
88
+ export function getDefaultStyle(styles) {
89
+ return find(styles, 'isDefault');
90
+ }
57
91
  //# sourceMappingURL=utils.js.map