@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
@@ -13,19 +13,15 @@ var _lodash = require("lodash");
13
13
 
14
14
  var _classnames = _interopRequireDefault(require("classnames"));
15
15
 
16
- var _data = require("@wordpress/data");
16
+ var _compose = require("@wordpress/compose");
17
17
 
18
18
  var _keycodes = require("@wordpress/keycodes");
19
19
 
20
- var _i18n = require("@wordpress/i18n");
20
+ var _components = require("@wordpress/components");
21
21
 
22
- var _blocks = require("@wordpress/blocks");
22
+ var _previewPanel = _interopRequireDefault(require("./preview-panel"));
23
23
 
24
- var _utils = require("./utils");
25
-
26
- var _blockPreview = _interopRequireDefault(require("../block-preview"));
27
-
28
- var _store = require("../../store");
24
+ var _useStylesForBlock = _interopRequireDefault(require("./use-styles-for-block"));
29
25
 
30
26
  /**
31
27
  * External dependencies
@@ -38,151 +34,131 @@ var _store = require("../../store");
38
34
  /**
39
35
  * Internal dependencies
40
36
  */
41
- const EMPTY_OBJECT = {};
42
-
43
- function useGenericPreviewBlock(block, type) {
44
- return (0, _element.useMemo)(() => {
45
- const example = type === null || type === void 0 ? void 0 : type.example;
46
- const blockName = type === null || type === void 0 ? void 0 : type.name;
47
-
48
- if (example && blockName) {
49
- return (0, _blocks.getBlockFromExample)(blockName, {
50
- attributes: example.attributes,
51
- innerBlocks: example.innerBlocks
52
- });
53
- }
54
-
55
- if (block) {
56
- return (0, _blocks.cloneBlock)(block);
57
- }
58
- }, [type !== null && type !== void 0 && type.example ? block === null || block === void 0 ? void 0 : block.name : block, type]);
37
+ function BlockStylesPreviewPanelSlot(_ref) {
38
+ let {
39
+ scope
40
+ } = _ref;
41
+ return (0, _element.createElement)(_components.Slot, {
42
+ name: `BlockStylesPreviewPanel/${scope}`
43
+ });
59
44
  }
60
45
 
61
- function BlockStyles(_ref) {
46
+ function BlockStylesPreviewPanelFill(_ref2) {
47
+ let {
48
+ children,
49
+ scope,
50
+ ...props
51
+ } = _ref2;
52
+ return (0, _element.createElement)(_components.Fill, {
53
+ name: `BlockStylesPreviewPanel/${scope}`
54
+ }, (0, _element.createElement)("div", props, children));
55
+ } // Top position (in px) of the Block Styles container
56
+ // relative to the editor pane.
57
+ // The value is the equivalent of the container's right position.
58
+
59
+
60
+ const DEFAULT_POSITION_TOP = 16; // Block Styles component for the Settings Sidebar.
61
+
62
+ function BlockStyles(_ref3) {
62
63
  let {
63
64
  clientId,
64
65
  onSwitch = _lodash.noop,
65
66
  onHoverClassName = _lodash.noop,
66
- itemRole
67
- } = _ref;
68
-
69
- const selector = select => {
70
- const {
71
- getBlock
72
- } = select(_store.store);
73
- const block = getBlock(clientId);
67
+ scope
68
+ } = _ref3;
69
+ const {
70
+ onSelect,
71
+ stylesToRender,
72
+ activeStyle,
73
+ genericPreviewBlock,
74
+ className: previewClassName
75
+ } = (0, _useStylesForBlock.default)({
76
+ clientId,
77
+ onSwitch
78
+ });
79
+ const [hoveredStyle, setHoveredStyle] = (0, _element.useState)(null);
80
+ const [containerScrollTop, setContainerScrollTop] = (0, _element.useState)(0);
81
+ const isMobileViewport = (0, _compose.useViewportMatch)('medium', '<');
82
+ (0, _element.useLayoutEffect)(() => {
83
+ const scrollContainer = document.querySelector('.interface-interface-skeleton__content');
84
+ const scrollTop = (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTop) || 0;
85
+ setContainerScrollTop(scrollTop + DEFAULT_POSITION_TOP);
86
+ }, [hoveredStyle]);
87
+
88
+ if (!stylesToRender || stylesToRender.length === 0) {
89
+ return null;
90
+ }
74
91
 
75
- if (!block) {
76
- return EMPTY_OBJECT;
77
- }
92
+ const debouncedSetHoveredStyle = (0, _lodash.debounce)(setHoveredStyle, 250);
78
93
 
79
- const blockType = (0, _blocks.getBlockType)(block.name);
80
- const {
81
- getBlockStyles
82
- } = select(_blocks.store);
83
- return {
84
- block,
85
- type: blockType,
86
- styles: getBlockStyles(block.name),
87
- className: block.attributes.className || ''
88
- };
94
+ const onSelectStylePreview = style => {
95
+ onSelect(style);
96
+ onHoverClassName(null);
97
+ setHoveredStyle(null);
98
+ debouncedSetHoveredStyle.cancel();
89
99
  };
90
100
 
91
- const {
92
- styles,
93
- block,
94
- type,
95
- className
96
- } = (0, _data.useSelect)(selector, [clientId]);
97
- const {
98
- updateBlockAttributes
99
- } = (0, _data.useDispatch)(_store.store);
100
- const genericPreviewBlock = useGenericPreviewBlock(block, type);
101
+ const styleItemHandler = item => {
102
+ var _item$name;
101
103
 
102
- if (!styles || styles.length === 0) {
103
- return null;
104
- }
104
+ if (hoveredStyle === item) {
105
+ debouncedSetHoveredStyle.cancel();
106
+ return;
107
+ }
108
+
109
+ debouncedSetHoveredStyle(item);
110
+ onHoverClassName((_item$name = item === null || item === void 0 ? void 0 : item.name) !== null && _item$name !== void 0 ? _item$name : null);
111
+ };
105
112
 
106
- const renderedStyles = (0, _lodash.find)(styles, 'isDefault') ? styles : [{
107
- name: 'default',
108
- label: (0, _i18n._x)('Default', 'block style'),
109
- isDefault: true
110
- }, ...styles];
111
- const activeStyle = (0, _utils.getActiveStyle)(renderedStyles, className);
112
113
  return (0, _element.createElement)("div", {
113
114
  className: "block-editor-block-styles"
114
- }, renderedStyles.map(style => {
115
- var _type$example$viewpor, _type$example;
116
-
117
- const styleClassName = (0, _utils.replaceActiveStyle)(className, activeStyle, style);
118
- return (0, _element.createElement)(BlockStyleItem, {
119
- genericPreviewBlock: genericPreviewBlock,
120
- 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,
121
- className: className,
122
- isActive: activeStyle === style,
115
+ }, (0, _element.createElement)("div", {
116
+ className: "block-editor-block-styles__variants"
117
+ }, stylesToRender.map(style => {
118
+ const buttonText = style.label || style.name;
119
+ return (0, _element.createElement)(_components.Button, {
120
+ className: (0, _classnames.default)('block-editor-block-styles__item', {
121
+ 'is-active': activeStyle.name === style.name
122
+ }),
123
123
  key: style.name,
124
- onSelect: () => {
125
- updateBlockAttributes(clientId, {
126
- className: styleClassName
127
- });
128
- onHoverClassName(null);
129
- onSwitch();
124
+ variant: "secondary",
125
+ label: buttonText,
126
+ onMouseEnter: () => styleItemHandler(style),
127
+ onFocus: () => styleItemHandler(style),
128
+ onMouseLeave: () => styleItemHandler(null),
129
+ onBlur: () => styleItemHandler(null),
130
+ onKeyDown: event => {
131
+ if (_keycodes.ENTER === event.keyCode || _keycodes.SPACE === event.keyCode) {
132
+ event.preventDefault();
133
+ onSelectStylePreview(style);
134
+ }
130
135
  },
131
- onBlur: () => onHoverClassName(null),
132
- onHover: () => onHoverClassName(styleClassName),
133
- style: style,
134
- styleClassName: styleClassName,
135
- itemRole: itemRole
136
- });
137
- }));
138
- }
139
-
140
- function BlockStyleItem(_ref2) {
141
- let {
142
- genericPreviewBlock,
143
- viewportWidth,
144
- style,
145
- isActive,
146
- onBlur,
147
- onHover,
148
- onSelect,
149
- styleClassName,
150
- itemRole
151
- } = _ref2;
152
- const previewBlocks = (0, _element.useMemo)(() => {
153
- return { ...genericPreviewBlock,
154
- attributes: { ...genericPreviewBlock.attributes,
155
- className: styleClassName
156
- }
157
- };
158
- }, [genericPreviewBlock, styleClassName]);
159
- return (0, _element.createElement)("div", {
160
- key: style.name,
161
- className: (0, _classnames.default)('block-editor-block-styles__item', {
162
- 'is-active': isActive
163
- }),
164
- onClick: () => onSelect(),
165
- onKeyDown: event => {
166
- if (_keycodes.ENTER === event.keyCode || _keycodes.SPACE === event.keyCode) {
167
- event.preventDefault();
168
- onSelect();
169
- }
136
+ onClick: () => onSelectStylePreview(style),
137
+ role: "button",
138
+ tabIndex: "0"
139
+ }, (0, _element.createElement)(_components.__experimentalText, {
140
+ as: "span",
141
+ limit: 12,
142
+ ellipsizeMode: "tail",
143
+ className: "block-editor-block-styles__item-text",
144
+ truncate: true
145
+ }, buttonText));
146
+ })), hoveredStyle && !isMobileViewport && (0, _element.createElement)(BlockStylesPreviewPanelFill, {
147
+ scope: scope,
148
+ className: "block-editor-block-styles__preview-panel",
149
+ style: {
150
+ top: containerScrollTop
170
151
  },
171
- onMouseEnter: onHover,
172
- onMouseLeave: onBlur,
173
- role: itemRole || 'button',
174
- tabIndex: "0",
175
- "aria-label": style.label || style.name
176
- }, (0, _element.createElement)("div", {
177
- className: "block-editor-block-styles__item-preview"
178
- }, (0, _element.createElement)(_blockPreview.default, {
179
- viewportWidth: viewportWidth,
180
- blocks: previewBlocks
181
- })), (0, _element.createElement)("div", {
182
- className: "block-editor-block-styles__item-label"
183
- }, style.label || style.name));
152
+ onMouseLeave: () => styleItemHandler(null)
153
+ }, (0, _element.createElement)(_previewPanel.default, {
154
+ activeStyle: activeStyle,
155
+ className: previewClassName,
156
+ genericPreviewBlock: genericPreviewBlock,
157
+ style: hoveredStyle
158
+ })));
184
159
  }
185
160
 
161
+ BlockStyles.Slot = BlockStylesPreviewPanelSlot;
186
162
  var _default = BlockStyles;
187
163
  exports.default = _default;
188
164
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/index.js"],"names":["EMPTY_OBJECT","useGenericPreviewBlock","block","type","example","blockName","name","attributes","innerBlocks","BlockStyles","clientId","onSwitch","noop","onHoverClassName","itemRole","selector","select","getBlock","blockEditorStore","blockType","getBlockStyles","blocksStore","styles","className","updateBlockAttributes","genericPreviewBlock","length","renderedStyles","label","isDefault","activeStyle","map","style","styleClassName","viewportWidth","BlockStyleItem","isActive","onBlur","onHover","onSelect","previewBlocks","event","ENTER","keyCode","SPACE","preventDefault"],"mappings":";;;;;;;;;AASA;;AANA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AAzBA;AACA;AACA;;AAIA;AACA;AACA;;AAYA;AACA;AACA;AAKA,MAAMA,YAAY,GAAG,EAArB;;AAEA,SAASC,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SAAO,sBAAS,MAAM;AACrB,UAAMC,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,aAAO,iCAAqBA,SAArB,EAAgC;AACtCE,QAAAA,UAAU,EAAEH,OAAO,CAACG,UADkB;AAEtCC,QAAAA,WAAW,EAAEJ,OAAO,CAACI;AAFiB,OAAhC,CAAP;AAIA;;AAED,QAAKN,KAAL,EAAa;AACZ,aAAO,wBAAYA,KAAZ,CAAP;AACA;AACD,GAdM,EAcJ,CAAEC,IAAI,SAAJ,IAAAA,IAAI,WAAJ,IAAAA,IAAI,CAAEC,OAAN,GAAgBF,KAAhB,aAAgBA,KAAhB,uBAAgBA,KAAK,CAAEI,IAAvB,GAA8BJ,KAAhC,EAAuCC,IAAvC,CAdI,CAAP;AAeA;;AAED,SAASM,WAAT,OAKI;AAAA,MALkB;AACrBC,IAAAA,QADqB;AAErBC,IAAAA,QAAQ,GAAGC,YAFU;AAGrBC,IAAAA,gBAAgB,GAAGD,YAHE;AAIrBE,IAAAA;AAJqB,GAKlB;;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A,UAAU,EAAE,EACX,GAAGkB,mBAAmB,CAAClB,UADZ;AAEXgB,QAAAA,SAAS,EAAEU;AAFA;AAFN,KAAP;AAOA,GARqB,EAQnB,CAAER,mBAAF,EAAuBQ,cAAvB,CARmB,CAAtB;AAUA,SACC;AACC,IAAA,GAAG,EAAGD,KAAK,CAAC1B,IADb;AAEC,IAAA,SAAS,EAAG,yBAAY,iCAAZ,EAA+C;AAC1D,mBAAa8B;AAD6C,KAA/C,CAFb;AAKC,IAAA,OAAO,EAAG,MAAMG,QAAQ,EALzB;AAMC,IAAA,SAAS,EAAKE,KAAF,IAAa;AACxB,UAAKC,oBAAUD,KAAK,CAACE,OAAhB,IAA2BC,oBAAUH,KAAK,CAACE,OAAhD,EAA0D;AACzDF,QAAAA,KAAK,CAACI,cAAN;AACAN,QAAAA,QAAQ;AACR;AACD,KAXF;AAYC,IAAA,YAAY,EAAGD,OAZhB;AAaC,IAAA,YAAY,EAAGD,MAbhB;AAcC,IAAA,IAAI,EAAGvB,QAAQ,IAAI,QAdpB;AAeC,IAAA,QAAQ,EAAC,GAfV;AAgBC,kBAAakB,KAAK,CAACJ,KAAN,IAAeI,KAAK,CAAC1B;AAhBnC,KAkBC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,qBAAD;AACC,IAAA,aAAa,EAAG4B,aADjB;AAEC,IAAA,MAAM,EAAGM;AAFV,IADD,CAlBD,EAwBC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGR,KAAK,CAACJ,KAAN,IAAeI,KAAK,CAAC1B,IADxB,CAxBD,CADD;AA8BA;;eAEcG,W","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":["BlockStylesPreviewPanelSlot","scope","BlockStylesPreviewPanelFill","children","props","DEFAULT_POSITION_TOP","BlockStyles","clientId","onSwitch","noop","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","ENTER","keyCode","SPACE","preventDefault","top","Slot"],"mappings":";;;;;;;;;AASA;;AANA;;AACA;;AAMA;;AACA;;AACA;;AAUA;;AACA;;AAvBA;AACA;AACA;;AAIA;AACA;AACA;;AAWA;AACA;AACA;AAIA,SAASA,2BAAT,OAAkD;AAAA,MAAZ;AAAEC,IAAAA;AAAF,GAAY;AACjD,SAAO,4BAAC,gBAAD;AAAM,IAAA,IAAI,EAAI,2BAA2BA,KAAO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AE,IAAF,CAdhC;AAeC,MAAA,SAAS,EAAKM,KAAF,IAAa;AACxB,YACCC,oBAAUD,KAAK,CAACE,OAAhB,IACAC,oBAAUH,KAAK,CAACE,OAFjB,EAGE;AACDF,UAAAA,KAAK,CAACI,cAAN;AACAb,UAAAA,oBAAoB,CAAEC,KAAF,CAApB;AACA;AACD,OAvBF;AAwBC,MAAA,OAAO,EAAG,MAAMD,oBAAoB,CAAEC,KAAF,CAxBrC;AAyBC,MAAA,IAAI,EAAC,QAzBN;AA0BC,MAAA,QAAQ,EAAC;AA1BV,OA4BC,4BAAC,8BAAD;AACC,MAAA,EAAE,EAAC,MADJ;AAEC,MAAA,KAAK,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,4BAAC,2BAAD;AACC,IAAA,KAAK,EAAGpB,KADT;AAEC,IAAA,SAAS,EAAC,0CAFX;AAGC,IAAA,KAAK,EAAG;AAAEyC,MAAAA,GAAG,EAAEvB;AAAP,KAHT;AAIC,IAAA,YAAY,EAAG,MAAMY,gBAAgB,CAAE,IAAF;AAJtC,KAMC,4BAAC,qBAAD;AACC,IAAA,WAAW,EAAGlB,WADf;AAEC,IAAA,SAAS,EAAGG,gBAFb;AAGC,IAAA,mBAAmB,EAAGF,mBAHvB;AAIC,IAAA,KAAK,EAAGG;AAJT,IAND,CAhDF,CADD;AAiEA;;AAEDX,WAAW,CAACqC,IAAZ,GAAmB3C,2BAAnB;eACeM,W","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,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = BlockStylesMenuItems;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _lodash = require("lodash");
13
+
14
+ var _components = require("@wordpress/components");
15
+
16
+ var _icons = require("@wordpress/icons");
17
+
18
+ var _useStylesForBlock = _interopRequireDefault(require("./use-styles-for-block"));
19
+
20
+ /**
21
+ * External dependencies
22
+ */
23
+
24
+ /**
25
+ * WordPress dependencies
26
+ */
27
+
28
+ /**
29
+ * Internal dependencies
30
+ */
31
+ function BlockStylesMenuItems(_ref) {
32
+ let {
33
+ clientId,
34
+ onSwitch = _lodash.noop
35
+ } = _ref;
36
+ const {
37
+ onSelect,
38
+ stylesToRender,
39
+ activeStyle
40
+ } = (0, _useStylesForBlock.default)({
41
+ clientId,
42
+ onSwitch
43
+ });
44
+
45
+ if (!stylesToRender || stylesToRender.length === 0) {
46
+ return null;
47
+ }
48
+
49
+ return (0, _element.createElement)(_element.Fragment, null, stylesToRender.map(style => {
50
+ const menuItemText = style.label || style.name;
51
+ return (0, _element.createElement)(_components.MenuItem, {
52
+ key: style.name,
53
+ icon: activeStyle.name === style.name ? _icons.check : null,
54
+ onClick: () => onSelect(style)
55
+ }, (0, _element.createElement)(_components.__experimentalText, {
56
+ as: "span",
57
+ limit: 18,
58
+ ellipsizeMode: "tail",
59
+ truncate: true
60
+ }, menuItemText));
61
+ }));
62
+ }
63
+ //# sourceMappingURL=menu-items.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/menu-items.js"],"names":["BlockStylesMenuItems","clientId","onSwitch","noop","onSelect","stylesToRender","activeStyle","length","map","style","menuItemText","label","name","check"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAGe,SAASA,oBAAT,OAA+D;AAAA,MAAhC;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,QAAQ,GAAGC;AAAvB,GAAgC;AAC7E,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,cAAZ;AAA4BC,IAAAA;AAA5B,MAA4C,gCAAoB;AACrEL,IAAAA,QADqE;AAErEC,IAAAA;AAFqE,GAApB,CAAlD;;AAKA,MAAK,CAAEG,cAAF,IAAoBA,cAAc,CAACE,MAAf,KAA0B,CAAnD,EAAuD;AACtD,WAAO,IAAP;AACA;;AACD,SACC,qDACGF,cAAc,CAACG,GAAf,CAAsBC,KAAF,IAAa;AAClC,UAAMC,YAAY,GAAGD,KAAK,CAACE,KAAN,IAAeF,KAAK,CAACG,IAA1C;AACA,WACC,4BAAC,oBAAD;AACC,MAAA,GAAG,EAAGH,KAAK,CAACG,IADb;AAEC,MAAA,IAAI,EAAGN,WAAW,CAACM,IAAZ,KAAqBH,KAAK,CAACG,IAA3B,GAAkCC,YAAlC,GAA0C,IAFlD;AAGC,MAAA,OAAO,EAAG,MAAMT,QAAQ,CAAEK,KAAF;AAHzB,OAKC,4BAAC,8BAAD;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,45 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = BlockStylesPreviewPanel;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _previewPanel = _interopRequireDefault(require("../inserter/preview-panel"));
13
+
14
+ var _utils = require("./utils");
15
+
16
+ /**
17
+ * WordPress dependencies
18
+ */
19
+
20
+ /**
21
+ * Internal dependencies
22
+ */
23
+ function BlockStylesPreviewPanel(_ref) {
24
+ let {
25
+ genericPreviewBlock,
26
+ style,
27
+ className,
28
+ activeStyle
29
+ } = _ref;
30
+ const styleClassName = (0, _utils.replaceActiveStyle)(className, activeStyle, style);
31
+ const previewBlocks = (0, _element.useMemo)(() => {
32
+ return { ...genericPreviewBlock,
33
+ title: style.label || style.name,
34
+ description: style.description,
35
+ initialAttributes: { ...genericPreviewBlock.attributes,
36
+ className: styleClassName + ' block-editor-block-styles__block-preview-container'
37
+ }
38
+ };
39
+ }, [genericPreviewBlock, styleClassName]);
40
+ return (0, _element.createElement)(_previewPanel.default, {
41
+ item: previewBlocks,
42
+ isStylePreview: true
43
+ });
44
+ }
45
+ //# sourceMappingURL=preview-panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/block-styles/preview-panel.js"],"names":["BlockStylesPreviewPanel","genericPreviewBlock","style","className","activeStyle","styleClassName","previewBlocks","title","label","name","description","initialAttributes","attributes"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIe,SAASA,uBAAT,OAKX;AAAA,MAL6C;AAChDC,IAAAA,mBADgD;AAEhDC,IAAAA,KAFgD;AAGhDC,IAAAA,SAHgD;AAIhDC,IAAAA;AAJgD,GAK7C;AACH,QAAMC,cAAc,GAAG,+BAAoBF,SAApB,EAA+BC,WAA/B,EAA4CF,KAA5C,CAAvB;AACA,QAAMI,aAAa,GAAG,sBAAS,MAAM;AACpC,WAAO,EACN,GAAGL,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,GAZqB,EAYnB,CAAEJ,mBAAF,EAAuBI,cAAvB,CAZmB,CAAtB;AAcA,SACC,4BAAC,qBAAD;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,119 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = useStylesForBlocks;
7
+
8
+ var _data = require("@wordpress/data");
9
+
10
+ var _blocks = require("@wordpress/blocks");
11
+
12
+ var _element = require("@wordpress/element");
13
+
14
+ var _utils = require("./utils");
15
+
16
+ var _store = require("../../store");
17
+
18
+ /**
19
+ * WordPress dependencies
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+
26
+ /**
27
+ *
28
+ * @param {WPBlock} block Block object.
29
+ * @param {WPBlockType} type Block type settings.
30
+ * @return {WPBlock} A generic block ready for styles preview.
31
+ */
32
+ function useGenericPreviewBlock(block, type) {
33
+ return (0, _element.useMemo)(() => {
34
+ const example = type === null || type === void 0 ? void 0 : type.example;
35
+ const blockName = type === null || type === void 0 ? void 0 : type.name;
36
+
37
+ if (example && blockName) {
38
+ return (0, _blocks.getBlockFromExample)(blockName, {
39
+ attributes: example.attributes,
40
+ innerBlocks: example.innerBlocks
41
+ });
42
+ }
43
+
44
+ if (block) {
45
+ return (0, _blocks.cloneBlock)(block);
46
+ }
47
+ }, [type !== null && type !== void 0 && type.example ? block === null || block === void 0 ? void 0 : block.name : block, type]);
48
+ }
49
+ /**
50
+ * @typedef useStylesForBlocksArguments
51
+ * @property {string} clientId Block client ID.
52
+ * @property {() => void} onSwitch Block style switch callback function.
53
+ */
54
+
55
+ /**
56
+ *
57
+ * @param {useStylesForBlocksArguments} useStylesForBlocks arguments.
58
+ * @return {Object} Results of the select methods.
59
+ */
60
+
61
+
62
+ function useStylesForBlocks(_ref) {
63
+ let {
64
+ clientId,
65
+ onSwitch
66
+ } = _ref;
67
+
68
+ const selector = select => {
69
+ const {
70
+ getBlock
71
+ } = select(_store.store);
72
+ const block = getBlock(clientId);
73
+
74
+ if (!block) {
75
+ return {};
76
+ }
77
+
78
+ const blockType = (0, _blocks.getBlockType)(block.name);
79
+ const {
80
+ getBlockStyles
81
+ } = select(_blocks.store);
82
+ return {
83
+ block,
84
+ blockType,
85
+ styles: getBlockStyles(block.name),
86
+ className: block.attributes.className || ''
87
+ };
88
+ };
89
+
90
+ const {
91
+ styles,
92
+ block,
93
+ blockType,
94
+ className
95
+ } = (0, _data.useSelect)(selector, [clientId]);
96
+ const {
97
+ updateBlockAttributes
98
+ } = (0, _data.useDispatch)(_store.store);
99
+ const stylesToRender = (0, _utils.getRenderedStyles)(styles);
100
+ const activeStyle = (0, _utils.getActiveStyle)(stylesToRender, className);
101
+ const genericPreviewBlock = useGenericPreviewBlock(block, blockType);
102
+
103
+ const onSelect = style => {
104
+ const styleClassName = (0, _utils.replaceActiveStyle)(className, activeStyle, style);
105
+ updateBlockAttributes(clientId, {
106
+ className: styleClassName
107
+ });
108
+ onSwitch();
109
+ };
110
+
111
+ return {
112
+ onSelect,
113
+ stylesToRender,
114
+ activeStyle,
115
+ genericPreviewBlock,
116
+ className
117
+ };
118
+ }
119
+ //# 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":["useGenericPreviewBlock","block","type","example","blockName","name","attributes","innerBlocks","useStylesForBlocks","clientId","onSwitch","selector","select","getBlock","blockEditorStore","blockType","getBlockStyles","blocksStore","styles","className","updateBlockAttributes","stylesToRender","activeStyle","genericPreviewBlock","onSelect","style","styleClassName"],"mappings":";;;;;;;AAGA;;AACA;;AAMA;;AAKA;;AACA;;AAhBA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,sBAAT,CAAiCC,KAAjC,EAAwCC,IAAxC,EAA+C;AAC9C,SAAO,sBAAS,MAAM;AACrB,UAAMC,OAAO,GAAGD,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEC,OAAtB;AACA,UAAMC,SAAS,GAAGF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AUjB,IAAAA,KAAV;AAAiBc,IAAAA,SAAjB;AAA4BI,IAAAA;AAA5B,MAA0C,qBAAWR,QAAX,EAAqB,CACpEF,QADoE,CAArB,CAAhD;AAGA,QAAM;AAAEW,IAAAA;AAAF,MAA4B,uBAAaN,YAAb,CAAlC;AACA,QAAMO,cAAc,GAAG,8BAAmBH,MAAnB,CAAvB;AACA,QAAMI,WAAW,GAAG,2BAAgBD,cAAhB,EAAgCF,SAAhC,CAApB;AACA,QAAMI,mBAAmB,GAAGvB,sBAAsB,CAAEC,KAAF,EAASc,SAAT,CAAlD;;AAEA,QAAMS,QAAQ,GAAKC,KAAF,IAAa;AAC7B,UAAMC,cAAc,GAAG,+BACtBP,SADsB,EAEtBG,WAFsB,EAGtBG,KAHsB,CAAvB;AAKAL,IAAAA,qBAAqB,CAAEX,QAAF,EAAY;AAChCU,MAAAA,SAAS,EAAEO;AADqB,KAAZ,CAArB;AAGAhB,IAAAA,QAAQ;AACR,GAVD;;AAYA,SAAO;AACNc,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"]}