@wordpress/block-editor 8.0.8 → 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 (294) 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/control.js +1 -0
  33. package/build/components/colors-gradients/control.js.map +1 -1
  34. package/build/components/colors-gradients/panel-color-gradient-settings.js +51 -10
  35. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  36. package/build/components/default-block-appender/index.js +16 -19
  37. package/build/components/default-block-appender/index.js.map +1 -1
  38. package/build/components/default-style-picker/index.js +18 -3
  39. package/build/components/default-style-picker/index.js.map +1 -1
  40. package/build/components/iframe/index.js +3 -4
  41. package/build/components/iframe/index.js.map +1 -1
  42. package/build/components/index.js +17 -10
  43. package/build/components/index.js.map +1 -1
  44. package/build/components/inner-blocks/default-block-appender.js +2 -4
  45. package/build/components/inner-blocks/default-block-appender.js.map +1 -1
  46. package/build/components/inserter/index.native.js +1 -1
  47. package/build/components/inserter/index.native.js.map +1 -1
  48. package/build/components/inserter/tabs.native.js +7 -4
  49. package/build/components/inserter/tabs.native.js.map +1 -1
  50. package/build/components/inspector-controls/block-support-slot-container.js +2 -1
  51. package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
  52. package/build/components/inspector-controls/fill.native.js +3 -5
  53. package/build/components/inspector-controls/fill.native.js.map +1 -1
  54. package/build/components/inspector-controls/groups.js +2 -0
  55. package/build/components/inspector-controls/groups.js.map +1 -1
  56. package/build/components/inspector-controls/slot.js +1 -3
  57. package/build/components/inspector-controls/slot.js.map +1 -1
  58. package/build/components/letter-spacing-control/index.js +6 -6
  59. package/build/components/letter-spacing-control/index.js.map +1 -1
  60. package/build/components/list-view/block-select-button.js +23 -3
  61. package/build/components/list-view/block-select-button.js.map +1 -1
  62. package/build/components/media-placeholder/index.js +2 -0
  63. package/build/components/media-placeholder/index.js.map +1 -1
  64. package/build/components/media-replace-flow/index.js +2 -0
  65. package/build/components/media-replace-flow/index.js.map +1 -1
  66. package/build/components/rich-text/file-paste-handler.js +1 -1
  67. package/build/components/rich-text/file-paste-handler.js.map +1 -1
  68. package/build/components/rich-text/prevent-event-discovery.js +33 -0
  69. package/build/components/rich-text/prevent-event-discovery.js.map +1 -0
  70. package/build/components/rich-text/use-input-rules.js +3 -1
  71. package/build/components/rich-text/use-input-rules.js.map +1 -1
  72. package/build/components/selection-scroll-into-view/index.js +2 -1
  73. package/build/components/selection-scroll-into-view/index.js.map +1 -1
  74. package/build/components/use-display-block-controls/index.native.js +45 -0
  75. package/build/components/use-display-block-controls/index.native.js.map +1 -0
  76. package/build/components/use-on-block-drop/index.js +7 -3
  77. package/build/components/use-on-block-drop/index.js.map +1 -1
  78. package/build/components/writing-flow/use-multi-selection.js +3 -1
  79. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  80. package/build/hooks/border-color.js +63 -5
  81. package/build/hooks/border-color.js.map +1 -1
  82. package/build/hooks/border-radius.js +47 -0
  83. package/build/hooks/border-radius.js.map +1 -1
  84. package/build/hooks/border-style.js +41 -0
  85. package/build/hooks/border-style.js.map +1 -1
  86. package/build/hooks/border-width.js +70 -31
  87. package/build/hooks/border-width.js.map +1 -1
  88. package/build/hooks/border.js +81 -11
  89. package/build/hooks/border.js.map +1 -1
  90. package/build/hooks/letter-spacing.js +1 -1
  91. package/build/hooks/letter-spacing.js.map +1 -1
  92. package/build/hooks/typography.js +1 -1
  93. package/build/hooks/typography.js.map +1 -1
  94. package/build/store/actions.js +1 -2
  95. package/build/store/actions.js.map +1 -1
  96. package/build/store/defaults.js +5 -1
  97. package/build/store/defaults.js.map +1 -1
  98. package/build/store/reducer.js +10 -82
  99. package/build/store/reducer.js.map +1 -1
  100. package/build/store/selectors.js +25 -7
  101. package/build/store/selectors.js.map +1 -1
  102. package/build/utils/get-paste-event-data.js +1 -1
  103. package/build/utils/get-paste-event-data.js.map +1 -1
  104. package/build/utils/parse-css-unit-to-px.js +1 -1
  105. package/build/utils/parse-css-unit-to-px.js.map +1 -1
  106. package/build/utils/transform-styles/index.js +2 -3
  107. package/build/utils/transform-styles/index.js.map +1 -1
  108. package/build-module/components/block-caption/index.native.js +13 -3
  109. package/build-module/components/block-caption/index.native.js.map +1 -1
  110. package/build-module/components/block-inspector/index.js +12 -23
  111. package/build-module/components/block-inspector/index.js.map +1 -1
  112. package/build-module/components/block-list-appender/index.js +3 -10
  113. package/build-module/components/block-list-appender/index.js.map +1 -1
  114. package/build-module/components/block-preview/auto.js +10 -2
  115. package/build-module/components/block-preview/auto.js.map +1 -1
  116. package/build-module/components/block-preview/index.js +46 -0
  117. package/build-module/components/block-preview/index.js.map +1 -1
  118. package/build-module/components/block-settings/container.native.js +2 -1
  119. package/build-module/components/block-settings/container.native.js.map +1 -1
  120. package/build-module/components/block-styles/index.js +112 -133
  121. package/build-module/components/block-styles/index.js.map +1 -1
  122. package/build-module/components/block-styles/menu-items.js +50 -0
  123. package/build-module/components/block-styles/menu-items.js.map +1 -0
  124. package/build-module/components/block-styles/preview-panel.js +35 -0
  125. package/build-module/components/block-styles/preview-panel.js.map +1 -0
  126. package/build-module/components/block-styles/use-styles-for-block.js +107 -0
  127. package/build-module/components/block-styles/use-styles-for-block.js.map +1 -0
  128. package/build-module/components/block-styles/utils.js +34 -0
  129. package/build-module/components/block-styles/utils.js.map +1 -1
  130. package/build-module/components/block-switcher/block-styles-menu.js +3 -21
  131. package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
  132. package/build-module/components/block-tools/back-compat.js +2 -1
  133. package/build-module/components/block-tools/back-compat.js.map +1 -1
  134. package/build-module/components/block-tools/insertion-point.js +11 -1
  135. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  136. package/build-module/components/button-block-appender/index.js +2 -1
  137. package/build-module/components/button-block-appender/index.js.map +1 -1
  138. package/build-module/components/colors-gradients/control.js +1 -0
  139. package/build-module/components/colors-gradients/control.js.map +1 -1
  140. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +54 -13
  141. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  142. package/build-module/components/default-block-appender/index.js +15 -18
  143. package/build-module/components/default-block-appender/index.js.map +1 -1
  144. package/build-module/components/default-style-picker/index.js +17 -3
  145. package/build-module/components/default-style-picker/index.js.map +1 -1
  146. package/build-module/components/iframe/index.js +3 -4
  147. package/build-module/components/iframe/index.js.map +1 -1
  148. package/build-module/components/index.js +2 -2
  149. package/build-module/components/index.js.map +1 -1
  150. package/build-module/components/inner-blocks/default-block-appender.js +2 -4
  151. package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
  152. package/build-module/components/inserter/index.native.js +2 -2
  153. package/build-module/components/inserter/index.native.js.map +1 -1
  154. package/build-module/components/inserter/tabs.native.js +7 -4
  155. package/build-module/components/inserter/tabs.native.js.map +1 -1
  156. package/build-module/components/inspector-controls/block-support-slot-container.js +2 -1
  157. package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
  158. package/build-module/components/inspector-controls/fill.native.js +3 -5
  159. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  160. package/build-module/components/inspector-controls/groups.js +2 -0
  161. package/build-module/components/inspector-controls/groups.js.map +1 -1
  162. package/build-module/components/inspector-controls/slot.js +1 -3
  163. package/build-module/components/inspector-controls/slot.js.map +1 -1
  164. package/build-module/components/letter-spacing-control/index.js +6 -6
  165. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  166. package/build-module/components/list-view/block-select-button.js +22 -3
  167. package/build-module/components/list-view/block-select-button.js.map +1 -1
  168. package/build-module/components/media-placeholder/index.js +2 -0
  169. package/build-module/components/media-placeholder/index.js.map +1 -1
  170. package/build-module/components/media-replace-flow/index.js +2 -0
  171. package/build-module/components/media-replace-flow/index.js.map +1 -1
  172. package/build-module/components/rich-text/file-paste-handler.js +1 -1
  173. package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
  174. package/build-module/components/rich-text/prevent-event-discovery.js +25 -0
  175. package/build-module/components/rich-text/prevent-event-discovery.js.map +1 -0
  176. package/build-module/components/rich-text/use-input-rules.js +2 -1
  177. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  178. package/build-module/components/selection-scroll-into-view/index.js +2 -1
  179. package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
  180. package/build-module/components/use-display-block-controls/index.native.js +34 -0
  181. package/build-module/components/use-display-block-controls/index.native.js.map +1 -0
  182. package/build-module/components/use-on-block-drop/index.js +7 -3
  183. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  184. package/build-module/components/writing-flow/use-multi-selection.js +3 -4
  185. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  186. package/build-module/hooks/border-color.js +61 -7
  187. package/build-module/hooks/border-color.js.map +1 -1
  188. package/build-module/hooks/border-radius.js +42 -0
  189. package/build-module/hooks/border-radius.js.map +1 -1
  190. package/build-module/hooks/border-style.js +36 -0
  191. package/build-module/hooks/border-style.js.map +1 -1
  192. package/build-module/hooks/border-width.js +66 -32
  193. package/build-module/hooks/border-width.js.map +1 -1
  194. package/build-module/hooks/border.js +80 -12
  195. package/build-module/hooks/border.js.map +1 -1
  196. package/build-module/hooks/letter-spacing.js +1 -1
  197. package/build-module/hooks/letter-spacing.js.map +1 -1
  198. package/build-module/hooks/typography.js +1 -1
  199. package/build-module/hooks/typography.js.map +1 -1
  200. package/build-module/store/actions.js +1 -2
  201. package/build-module/store/actions.js.map +1 -1
  202. package/build-module/store/defaults.js +5 -1
  203. package/build-module/store/defaults.js.map +1 -1
  204. package/build-module/store/reducer.js +11 -83
  205. package/build-module/store/reducer.js.map +1 -1
  206. package/build-module/store/selectors.js +24 -7
  207. package/build-module/store/selectors.js.map +1 -1
  208. package/build-module/utils/get-paste-event-data.js +1 -1
  209. package/build-module/utils/get-paste-event-data.js.map +1 -1
  210. package/build-module/utils/parse-css-unit-to-px.js +1 -1
  211. package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
  212. package/build-module/utils/transform-styles/index.js +2 -3
  213. package/build-module/utils/transform-styles/index.js.map +1 -1
  214. package/build-style/style-rtl.css +229 -182
  215. package/build-style/style.css +229 -182
  216. package/package.json +27 -27
  217. package/src/components/block-caption/index.native.js +22 -4
  218. package/src/components/block-inspector/index.js +14 -17
  219. package/src/components/block-list-appender/index.js +5 -21
  220. package/src/components/block-preview/auto.js +7 -2
  221. package/src/components/block-preview/index.js +60 -0
  222. package/src/components/block-preview/style.scss +23 -0
  223. package/src/components/block-preview/test/index.js +114 -0
  224. package/src/components/block-settings/container.native.js +1 -0
  225. package/src/components/block-styles/index.js +125 -145
  226. package/src/components/block-styles/menu-items.js +49 -0
  227. package/src/components/block-styles/preview-panel.js +36 -0
  228. package/src/components/block-styles/style.scss +59 -51
  229. package/src/components/block-styles/test/{index.js → utils.js} +60 -1
  230. package/src/components/block-styles/use-styles-for-block.js +99 -0
  231. package/src/components/block-styles/utils.js +39 -0
  232. package/src/components/block-switcher/block-styles-menu.js +3 -38
  233. package/src/components/block-tools/back-compat.js +1 -0
  234. package/src/components/block-tools/insertion-point.js +10 -1
  235. package/src/components/border-style-control/style.scss +3 -3
  236. package/src/components/button-block-appender/index.js +1 -0
  237. package/src/components/color-palette/test/__snapshots__/control.js.snap +1 -0
  238. package/src/components/colors-gradients/control.js +3 -0
  239. package/src/components/colors-gradients/panel-color-gradient-settings.js +75 -19
  240. package/src/components/colors-gradients/style.scss +42 -5
  241. package/src/components/default-block-appender/index.js +17 -24
  242. package/src/components/default-block-appender/style.scss +4 -0
  243. package/src/components/default-block-appender/test/__snapshots__/index.js.snap +12 -24
  244. package/src/components/default-block-appender/test/index.js +4 -14
  245. package/src/components/default-style-picker/index.js +18 -6
  246. package/src/components/iframe/index.js +6 -3
  247. package/src/components/index.js +5 -2
  248. package/src/components/inner-blocks/README.md +2 -0
  249. package/src/components/inner-blocks/default-block-appender.js +2 -7
  250. package/src/components/inserter/index.native.js +2 -2
  251. package/src/components/inserter/tabs.native.js +5 -4
  252. package/src/components/inspector-controls/block-support-slot-container.js +3 -1
  253. package/src/components/inspector-controls/fill.native.js +4 -3
  254. package/src/components/inspector-controls/groups.js +2 -0
  255. package/src/components/inspector-controls/slot.js +2 -7
  256. package/src/components/letter-spacing-control/index.js +6 -6
  257. package/src/components/link-control/README.md +1 -1
  258. package/src/components/link-control/test/index.js +2 -0
  259. package/src/components/list-view/block-select-button.js +20 -1
  260. package/src/components/media-placeholder/index.js +2 -0
  261. package/src/components/media-replace-flow/index.js +2 -0
  262. package/src/components/rich-text/file-paste-handler.js +3 -1
  263. package/src/components/rich-text/prevent-event-discovery.js +23 -0
  264. package/src/components/rich-text/use-input-rules.js +2 -1
  265. package/src/components/selection-scroll-into-view/index.js +1 -0
  266. package/src/components/url-input/README.md +5 -0
  267. package/src/components/use-display-block-controls/index.native.js +38 -0
  268. package/src/components/use-on-block-drop/index.js +7 -3
  269. package/src/components/writing-flow/test/use-multi-selection.js +36 -0
  270. package/src/components/writing-flow/use-multi-selection.js +12 -9
  271. package/src/hooks/border-color.js +55 -3
  272. package/src/hooks/border-radius.js +32 -0
  273. package/src/hooks/border-style.js +26 -0
  274. package/src/hooks/border-width.js +56 -32
  275. package/src/hooks/border.js +115 -20
  276. package/src/hooks/border.scss +3 -17
  277. package/src/hooks/dimensions.scss +5 -0
  278. package/src/hooks/letter-spacing.js +1 -1
  279. package/src/hooks/typography.js +1 -1
  280. package/src/store/actions.js +1 -2
  281. package/src/store/defaults.js +2 -0
  282. package/src/store/reducer.js +13 -104
  283. package/src/store/selectors.js +37 -7
  284. package/src/style.scss +4 -3
  285. package/src/utils/get-paste-event-data.js +1 -1
  286. package/src/utils/parse-css-unit-to-px.js +1 -1
  287. package/src/utils/test/parse-css-unit-to-px.js +1 -0
  288. package/src/utils/transform-styles/index.js +13 -16
  289. package/tsconfig.tsbuildinfo +1 -1
  290. package/build/components/use-canvas-click-redirect/index.js +0 -66
  291. package/build/components/use-canvas-click-redirect/index.js.map +0 -1
  292. package/build-module/components/use-canvas-click-redirect/index.js +0 -54
  293. package/build-module/components/use-canvas-click-redirect/index.js.map +0 -1
  294. package/src/components/use-canvas-click-redirect/index.js +0 -57
@@ -30,10 +30,7 @@ import BlockVariationTransforms from '../block-variation-transforms';
30
30
  import useBlockDisplayInformation from '../use-block-display-information';
31
31
  import { store as blockEditorStore } from '../../store';
32
32
 
33
- const BlockInspector = ( {
34
- showNoBlockSelectedMessage = true,
35
- bubblesVirtually = true,
36
- } ) => {
33
+ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
37
34
  const {
38
35
  count,
39
36
  hasBlockStyles,
@@ -69,7 +66,7 @@ const BlockInspector = ( {
69
66
  return (
70
67
  <div className="block-editor-block-inspector">
71
68
  <MultiSelectionInspector />
72
- <InspectorControls.Slot bubblesVirtually={ bubblesVirtually } />
69
+ <InspectorControls.Slot />
73
70
  </div>
74
71
  );
75
72
  }
@@ -100,7 +97,6 @@ const BlockInspector = ( {
100
97
  clientId={ selectedBlockClientId }
101
98
  blockName={ blockType.name }
102
99
  hasBlockStyles={ hasBlockStyles }
103
- bubblesVirtually={ bubblesVirtually }
104
100
  />
105
101
  );
106
102
  };
@@ -109,7 +105,6 @@ const BlockInspectorSingleBlock = ( {
109
105
  clientId,
110
106
  blockName,
111
107
  hasBlockStyles,
112
- bubblesVirtually,
113
108
  } ) => {
114
109
  const blockInformation = useBlockDisplayInformation( clientId );
115
110
  return (
@@ -119,7 +114,10 @@ const BlockInspectorSingleBlock = ( {
119
114
  { hasBlockStyles && (
120
115
  <div>
121
116
  <PanelBody title={ __( 'Styles' ) }>
122
- <BlockStyles clientId={ clientId } />
117
+ <BlockStyles
118
+ scope="core/block-inspector"
119
+ clientId={ clientId }
120
+ />
123
121
  { hasBlockSupport(
124
122
  blockName,
125
123
  'defaultStylePicker',
@@ -128,26 +126,28 @@ const BlockInspectorSingleBlock = ( {
128
126
  </PanelBody>
129
127
  </div>
130
128
  ) }
131
- <InspectorControls.Slot bubblesVirtually={ bubblesVirtually } />
129
+ <InspectorControls.Slot />
132
130
  <InspectorControls.Slot
133
131
  __experimentalGroup="typography"
134
- bubblesVirtually={ bubblesVirtually }
135
132
  label={ __( 'Typography' ) }
136
133
  />
134
+ <InspectorControls.Slot
135
+ __experimentalGroup="border"
136
+ label={ __( 'Border' ) }
137
+ />
137
138
  <InspectorControls.Slot
138
139
  __experimentalGroup="dimensions"
139
- bubblesVirtually={ bubblesVirtually }
140
140
  label={ __( 'Dimensions' ) }
141
141
  />
142
142
  <div>
143
- <AdvancedControls bubblesVirtually={ bubblesVirtually } />
143
+ <AdvancedControls />
144
144
  </div>
145
145
  <SkipToSelectedBlock key="back" />
146
146
  </div>
147
147
  );
148
148
  };
149
149
 
150
- const AdvancedControls = ( { bubblesVirtually } ) => {
150
+ const AdvancedControls = () => {
151
151
  const slot = useSlot( InspectorAdvancedControls.slotName );
152
152
  const hasFills = Boolean( slot.fills && slot.fills.length );
153
153
 
@@ -161,10 +161,7 @@ const AdvancedControls = ( { bubblesVirtually } ) => {
161
161
  title={ __( 'Advanced' ) }
162
162
  initialOpen={ false }
163
163
  >
164
- <InspectorControls.Slot
165
- __experimentalGroup="advanced"
166
- bubblesVirtually={ bubblesVirtually }
167
- />
164
+ <InspectorControls.Slot __experimentalGroup="advanced" />
168
165
  </PanelBody>
169
166
  );
170
167
  };
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { last } from 'lodash';
5
4
  import classnames from 'classnames';
6
5
 
7
6
  /**
@@ -18,7 +17,6 @@ import ButtonBlockAppender from '../button-block-appender';
18
17
  import { store as blockEditorStore } from '../../store';
19
18
 
20
19
  function BlockListAppender( {
21
- blockClientIds,
22
20
  rootClientId,
23
21
  canInsertDefaultBlock,
24
22
  isLocked,
@@ -36,30 +34,18 @@ function BlockListAppender( {
36
34
  // Prefer custom render prop if provided.
37
35
  appender = <CustomAppender />;
38
36
  } else {
39
- const isDocumentAppender = ! rootClientId;
40
- const isParentSelected = selectedBlockClientId === rootClientId;
41
- const isAnotherDefaultAppenderAlreadyDisplayed =
42
- selectedBlockClientId &&
43
- ! blockClientIds.includes( selectedBlockClientId );
37
+ const isParentSelected =
38
+ selectedBlockClientId === rootClientId ||
39
+ ( ! rootClientId && ! selectedBlockClientId );
44
40
 
45
- if (
46
- ! isDocumentAppender &&
47
- ! isParentSelected &&
48
- ( ! selectedBlockClientId ||
49
- isAnotherDefaultAppenderAlreadyDisplayed )
50
- ) {
41
+ if ( ! isParentSelected ) {
51
42
  return null;
52
43
  }
53
44
 
54
45
  if ( canInsertDefaultBlock ) {
55
46
  // Render the default block appender when renderAppender has not been
56
47
  // provided and the context supports use of the default appender.
57
- appender = (
58
- <DefaultBlockAppender
59
- rootClientId={ rootClientId }
60
- lastBlockClientId={ last( blockClientIds ) }
61
- />
62
- );
48
+ appender = <DefaultBlockAppender rootClientId={ rootClientId } />;
63
49
  } else {
64
50
  // Fallback in the case no renderAppender has been provided and the
65
51
  // default block can't be inserted.
@@ -103,7 +89,6 @@ function BlockListAppender( {
103
89
 
104
90
  export default withSelect( ( select, { rootClientId } ) => {
105
91
  const {
106
- getBlockOrder,
107
92
  canInsertBlockType,
108
93
  getTemplateLock,
109
94
  getSelectedBlockClientId,
@@ -111,7 +96,6 @@ export default withSelect( ( select, { rootClientId } ) => {
111
96
 
112
97
  return {
113
98
  isLocked: !! getTemplateLock( rootClientId ),
114
- blockClientIds: getBlockOrder( rootClientId ),
115
99
  canInsertDefaultBlock: canInsertBlockType(
116
100
  getDefaultBlockName(),
117
101
  rootClientId
@@ -25,8 +25,12 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
25
25
  contentResizeListener,
26
26
  { height: contentHeight },
27
27
  ] = useResizeObserver();
28
- const styles = useSelect( ( select ) => {
29
- return select( store ).getSettings().styles;
28
+ const { styles, assets } = useSelect( ( select ) => {
29
+ const settings = select( store ).getSettings();
30
+ return {
31
+ styles: settings.styles,
32
+ assets: settings.__unstableResolvedAssets,
33
+ };
30
34
  }, [] );
31
35
 
32
36
  // Initialize on render instead of module top level, to avoid circular dependency issues.
@@ -46,6 +50,7 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) {
46
50
  >
47
51
  <Iframe
48
52
  head={ <EditorStyles styles={ styles } /> }
53
+ assets={ assets }
49
54
  contentRef={ useRefEffect( ( bodyElement ) => {
50
55
  const {
51
56
  ownerDocument: { documentElement },
@@ -2,10 +2,15 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { castArray } from 'lodash';
5
+ import classnames from 'classnames';
5
6
 
6
7
  /**
7
8
  * WordPress dependencies
8
9
  */
10
+ import {
11
+ __experimentalUseDisabled as useDisabled,
12
+ useMergeRefs,
13
+ } from '@wordpress/compose';
9
14
  import { useSelect } from '@wordpress/data';
10
15
  import { memo, useMemo } from '@wordpress/element';
11
16
 
@@ -16,6 +21,7 @@ import BlockEditorProvider from '../provider';
16
21
  import LiveBlockPreview from './live';
17
22
  import AutoHeightBlockPreview from './auto';
18
23
  import { store as blockEditorStore } from '../../store';
24
+ import { BlockListItems } from '../block-list';
19
25
 
20
26
  export function BlockPreview( {
21
27
  blocks,
@@ -63,3 +69,57 @@ export function BlockPreview( {
63
69
  * @return {WPComponent} The component to be rendered.
64
70
  */
65
71
  export default memo( BlockPreview );
72
+
73
+ /**
74
+ * This hook is used to lightly mark an element as a block preview wrapper
75
+ * element. Call this hook and pass the returned props to the element to mark as
76
+ * a block preview wrapper, automatically rendering inner blocks as children. If
77
+ * you define a ref for the element, it is important to pass the ref to this
78
+ * hook, which the hook in turn will pass to the component through the props it
79
+ * returns. Optionally, you can also pass any other props through this hook, and
80
+ * they will be merged and returned.
81
+ *
82
+ * @param {Object} options Preview options.
83
+ * @param {WPBlock[]} options.blocks Block objects.
84
+ * @param {Object} options.props Optional. Props to pass to the element. Must contain
85
+ * the ref if one is defined.
86
+ * @param {Object} options.__experimentalLayout Layout settings to be used in the preview.
87
+ *
88
+ */
89
+ export function useBlockPreview( {
90
+ blocks,
91
+ props = {},
92
+ __experimentalLayout,
93
+ } ) {
94
+ const originalSettings = useSelect(
95
+ ( select ) => select( blockEditorStore ).getSettings(),
96
+ []
97
+ );
98
+ const disabledRef = useDisabled();
99
+ const ref = useMergeRefs( [ props.ref, disabledRef ] );
100
+ const settings = useMemo(
101
+ () => ( { ...originalSettings, __experimentalBlockPatterns: [] } ),
102
+ [ originalSettings ]
103
+ );
104
+ const renderedBlocks = useMemo( () => castArray( blocks ), [ blocks ] );
105
+
106
+ const children = (
107
+ <BlockEditorProvider value={ renderedBlocks } settings={ settings }>
108
+ <BlockListItems
109
+ renderAppender={ false }
110
+ __experimentalLayout={ __experimentalLayout }
111
+ />
112
+ </BlockEditorProvider>
113
+ );
114
+
115
+ return {
116
+ ...props,
117
+ ref,
118
+ className: classnames(
119
+ props.className,
120
+ 'block-editor-block-preview__live-content',
121
+ 'components-disabled'
122
+ ),
123
+ children: blocks?.length ? children : null,
124
+ };
125
+ }
@@ -41,3 +41,26 @@
41
41
  .block-editor-block-preview__content-iframe .block-list-appender {
42
42
  display: none;
43
43
  }
44
+
45
+ .block-editor-block-preview__live-content {
46
+ * {
47
+ pointer-events: none;
48
+ }
49
+
50
+ // Hide the block appender, as the block is not editable in this context.
51
+ .block-list-appender {
52
+ display: none;
53
+ }
54
+
55
+ // Revert button disable styles to ensure that button styles render as they will on the
56
+ // front end of the site. For example, this ensures that Social Links icons display correctly.
57
+ .components-button:disabled {
58
+ opacity: initial;
59
+ }
60
+
61
+ // Hide placeholders.
62
+ .components-placeholder,
63
+ .block-editor-block-list__block[data-empty="true"] {
64
+ display: none;
65
+ }
66
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen, waitFor } from '@testing-library/react';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import {
10
+ registerBlockType,
11
+ unregisterBlockType,
12
+ createBlock,
13
+ } from '@wordpress/blocks';
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+ import { useBlockPreview } from '../';
19
+
20
+ jest.mock( '@wordpress/dom', () => {
21
+ const focus = jest.requireActual( '../../../../../dom/src' ).focus;
22
+
23
+ return {
24
+ focus: {
25
+ ...focus,
26
+ focusable: {
27
+ ...focus.focusable,
28
+ find( context ) {
29
+ // In JSDOM, all elements have zero'd widths and height.
30
+ // This is a metric for focusable's `isVisible`, so find
31
+ // and apply an arbitrary non-zero width.
32
+ Array.from( context.querySelectorAll( '*' ) ).forEach(
33
+ ( element ) => {
34
+ Object.defineProperties( element, {
35
+ offsetWidth: {
36
+ get: () => 1,
37
+ configurable: true,
38
+ },
39
+ } );
40
+ }
41
+ );
42
+
43
+ return focus.focusable.find( ...arguments );
44
+ },
45
+ },
46
+ },
47
+ };
48
+ } );
49
+
50
+ describe( 'useBlockPreview', () => {
51
+ beforeAll( () => {
52
+ registerBlockType( 'core/test-block', {
53
+ save: () => (
54
+ <div>
55
+ Test block save view
56
+ <button>Button</button>
57
+ </div>
58
+ ),
59
+ edit: () => (
60
+ <div>
61
+ Test block edit view
62
+ <button>Button</button>
63
+ </div>
64
+ ),
65
+ category: 'text',
66
+ title: 'test block',
67
+ } );
68
+ } );
69
+
70
+ afterAll( () => {
71
+ unregisterBlockType( 'core/test-block' );
72
+ } );
73
+
74
+ function BlockPreviewComponent( { blocks, className } ) {
75
+ const blockPreviewProps = useBlockPreview( {
76
+ blocks,
77
+ props: { className },
78
+ } );
79
+ return <div { ...blockPreviewProps } />;
80
+ }
81
+
82
+ it( 'will render a block preview with minimal nesting', async () => {
83
+ const blocks = [];
84
+ blocks.push( createBlock( 'core/test-block' ) );
85
+
86
+ const { container } = render(
87
+ <BlockPreviewComponent
88
+ className="test-container-classname"
89
+ blocks={ blocks }
90
+ />
91
+ );
92
+
93
+ // Test block and block contents are rendered.
94
+ const previewedBlock = screen.getByLabelText( 'Block: test block' );
95
+ const previewedBlockContents = screen.getByText(
96
+ 'Test block edit view'
97
+ );
98
+ expect( previewedBlockContents ).toBeInTheDocument();
99
+
100
+ // Test elements within block contents are disabled.
101
+ await waitFor( () => {
102
+ const button = screen.getByText( 'Button' );
103
+ expect( button.hasAttribute( 'disabled' ) ).toBe( true );
104
+ } );
105
+
106
+ // Ensure the block preview class names are merged with the component's class name.
107
+ expect( container.firstChild.className ).toBe(
108
+ 'test-container-classname block-editor-block-preview__live-content components-disabled'
109
+ );
110
+
111
+ // Ensure there is no nesting between the parent component and rendered blocks.
112
+ expect( container.firstChild.firstChild ).toBe( previewedBlock );
113
+ } );
114
+ } );
@@ -43,6 +43,7 @@ function BottomSheetSettings( {
43
43
  hideHeader
44
44
  contentStyle={ styles.content }
45
45
  hasNavigation
46
+ testID="block-settings-modal"
46
47
  { ...props }
47
48
  >
48
49
  <BottomSheet.NavigationContainer animate main>