@wordpress/block-editor 10.4.0 → 10.5.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 (254) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +0 -1
  3. package/build/components/block-lock/menu-item.js +1 -1
  4. package/build/components/block-lock/menu-item.js.map +1 -1
  5. package/build/components/block-lock/modal.js +16 -9
  6. package/build/components/block-lock/modal.js.map +1 -1
  7. package/build/components/block-styles/utils.js +3 -3
  8. package/build/components/block-styles/utils.js.map +1 -1
  9. package/build/components/block-switcher/index.js +19 -4
  10. package/build/components/block-switcher/index.js.map +1 -1
  11. package/build/components/block-tools/selected-block-popover.js +27 -4
  12. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  13. package/build/components/colors/with-colors.js +4 -3
  14. package/build/components/colors/with-colors.js.map +1 -1
  15. package/build/components/font-sizes/fluid-utils.js +24 -40
  16. package/build/components/font-sizes/fluid-utils.js.map +1 -1
  17. package/build/components/font-sizes/with-font-sizes.js +7 -5
  18. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  19. package/build/components/index.js +9 -0
  20. package/build/components/index.js.map +1 -1
  21. package/build/components/inner-blocks/index.js +5 -3
  22. package/build/components/inner-blocks/index.js.map +1 -1
  23. package/build/components/inserter/reusable-blocks-tab.js +4 -1
  24. package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
  25. package/build/components/link-control/index.js +18 -34
  26. package/build/components/link-control/index.js.map +1 -1
  27. package/build/components/link-control/search-input.js +1 -1
  28. package/build/components/link-control/search-input.js.map +1 -1
  29. package/build/components/link-control/use-internal-input-value.js +26 -0
  30. package/build/components/link-control/use-internal-input-value.js.map +1 -0
  31. package/build/components/list-view/block.js +5 -3
  32. package/build/components/list-view/block.js.map +1 -1
  33. package/build/components/list-view/branch.js +9 -3
  34. package/build/components/list-view/branch.js.map +1 -1
  35. package/build/components/off-canvas-editor/block-contents.js +100 -0
  36. package/build/components/off-canvas-editor/block-contents.js.map +1 -0
  37. package/build/components/off-canvas-editor/block-select-button.js +119 -0
  38. package/build/components/off-canvas-editor/block-select-button.js.map +1 -0
  39. package/build/components/off-canvas-editor/block.js +292 -0
  40. package/build/components/off-canvas-editor/block.js.map +1 -0
  41. package/build/components/off-canvas-editor/branch.js +181 -0
  42. package/build/components/off-canvas-editor/branch.js.map +1 -0
  43. package/build/components/off-canvas-editor/context.js +19 -0
  44. package/build/components/off-canvas-editor/context.js.map +1 -0
  45. package/build/components/off-canvas-editor/drop-indicator.js +118 -0
  46. package/build/components/off-canvas-editor/drop-indicator.js.map +1 -0
  47. package/build/components/off-canvas-editor/expander.js +41 -0
  48. package/build/components/off-canvas-editor/expander.js.map +1 -0
  49. package/build/components/off-canvas-editor/index.js +204 -0
  50. package/build/components/off-canvas-editor/index.js.map +1 -0
  51. package/build/components/off-canvas-editor/leaf.js +60 -0
  52. package/build/components/off-canvas-editor/leaf.js.map +1 -0
  53. package/build/components/off-canvas-editor/use-block-selection.js +139 -0
  54. package/build/components/off-canvas-editor/use-block-selection.js.map +1 -0
  55. package/build/components/off-canvas-editor/use-list-view-client-ids.js +33 -0
  56. package/build/components/off-canvas-editor/use-list-view-client-ids.js.map +1 -0
  57. package/build/components/off-canvas-editor/use-list-view-drop-zone.js +235 -0
  58. package/build/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -0
  59. package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js +60 -0
  60. package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +1 -0
  61. package/build/components/off-canvas-editor/utils.js +60 -0
  62. package/build/components/off-canvas-editor/utils.js.map +1 -0
  63. package/build/components/url-popover/index.js +31 -2
  64. package/build/components/url-popover/index.js.map +1 -1
  65. package/build/components/use-setting/index.js +1 -1
  66. package/build/components/use-setting/index.js.map +1 -1
  67. package/build/hooks/color-panel.js +17 -1
  68. package/build/hooks/color-panel.js.map +1 -1
  69. package/build/hooks/color.js +1 -1
  70. package/build/hooks/color.js.map +1 -1
  71. package/build/hooks/content-lock-ui.js +13 -6
  72. package/build/hooks/content-lock-ui.js.map +1 -1
  73. package/build/hooks/dimensions.js +44 -13
  74. package/build/hooks/dimensions.js.map +1 -1
  75. package/build/hooks/layout.js +2 -2
  76. package/build/hooks/layout.js.map +1 -1
  77. package/build/hooks/margin.js +4 -2
  78. package/build/hooks/margin.js.map +1 -1
  79. package/build/hooks/min-height.js +145 -0
  80. package/build/hooks/min-height.js.map +1 -0
  81. package/build/hooks/padding.js +4 -2
  82. package/build/hooks/padding.js.map +1 -1
  83. package/build/hooks/style.js +3 -2
  84. package/build/hooks/style.js.map +1 -1
  85. package/build/layouts/flex.js +22 -21
  86. package/build/layouts/flex.js.map +1 -1
  87. package/build/store/actions.js +26 -0
  88. package/build/store/actions.js.map +1 -1
  89. package/build/store/reducer.js +46 -14
  90. package/build/store/reducer.js.map +1 -1
  91. package/build/store/selectors.js +16 -2
  92. package/build/store/selectors.js.map +1 -1
  93. package/build-module/components/block-lock/menu-item.js +2 -2
  94. package/build-module/components/block-lock/menu-item.js.map +1 -1
  95. package/build-module/components/block-lock/modal.js +17 -10
  96. package/build-module/components/block-lock/modal.js.map +1 -1
  97. package/build-module/components/block-styles/utils.js +3 -3
  98. package/build-module/components/block-styles/utils.js.map +1 -1
  99. package/build-module/components/block-switcher/index.js +19 -4
  100. package/build-module/components/block-switcher/index.js.map +1 -1
  101. package/build-module/components/block-tools/selected-block-popover.js +27 -5
  102. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  103. package/build-module/components/colors/with-colors.js +5 -4
  104. package/build-module/components/colors/with-colors.js.map +1 -1
  105. package/build-module/components/font-sizes/fluid-utils.js +24 -40
  106. package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
  107. package/build-module/components/font-sizes/with-font-sizes.js +8 -6
  108. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  109. package/build-module/components/index.js +1 -0
  110. package/build-module/components/index.js.map +1 -1
  111. package/build-module/components/inner-blocks/index.js +5 -3
  112. package/build-module/components/inner-blocks/index.js.map +1 -1
  113. package/build-module/components/inserter/reusable-blocks-tab.js +3 -1
  114. package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
  115. package/build-module/components/link-control/index.js +17 -34
  116. package/build-module/components/link-control/index.js.map +1 -1
  117. package/build-module/components/link-control/search-input.js +1 -1
  118. package/build-module/components/link-control/search-input.js.map +1 -1
  119. package/build-module/components/link-control/use-internal-input-value.js +18 -0
  120. package/build-module/components/link-control/use-internal-input-value.js.map +1 -0
  121. package/build-module/components/list-view/block.js +5 -3
  122. package/build-module/components/list-view/block.js.map +1 -1
  123. package/build-module/components/list-view/branch.js +9 -3
  124. package/build-module/components/list-view/branch.js.map +1 -1
  125. package/build-module/components/off-canvas-editor/block-contents.js +85 -0
  126. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -0
  127. package/build-module/components/off-canvas-editor/block-select-button.js +101 -0
  128. package/build-module/components/off-canvas-editor/block-select-button.js.map +1 -0
  129. package/build-module/components/off-canvas-editor/block.js +268 -0
  130. package/build-module/components/off-canvas-editor/block.js.map +1 -0
  131. package/build-module/components/off-canvas-editor/branch.js +165 -0
  132. package/build-module/components/off-canvas-editor/branch.js.map +1 -0
  133. package/build-module/components/off-canvas-editor/context.js +7 -0
  134. package/build-module/components/off-canvas-editor/context.js.map +1 -0
  135. package/build-module/components/off-canvas-editor/drop-indicator.js +111 -0
  136. package/build-module/components/off-canvas-editor/drop-indicator.js.map +1 -0
  137. package/build-module/components/off-canvas-editor/expander.js +32 -0
  138. package/build-module/components/off-canvas-editor/expander.js.map +1 -0
  139. package/build-module/components/off-canvas-editor/index.js +181 -0
  140. package/build-module/components/off-canvas-editor/index.js.map +1 -0
  141. package/build-module/components/off-canvas-editor/leaf.js +45 -0
  142. package/build-module/components/off-canvas-editor/leaf.js.map +1 -0
  143. package/build-module/components/off-canvas-editor/use-block-selection.js +124 -0
  144. package/build-module/components/off-canvas-editor/use-block-selection.js.map +1 -0
  145. package/build-module/components/off-canvas-editor/use-list-view-client-ids.js +24 -0
  146. package/build-module/components/off-canvas-editor/use-list-view-client-ids.js.map +1 -0
  147. package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js +220 -0
  148. package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -0
  149. package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js +50 -0
  150. package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +1 -0
  151. package/build-module/components/off-canvas-editor/utils.js +44 -0
  152. package/build-module/components/off-canvas-editor/utils.js.map +1 -0
  153. package/build-module/components/url-popover/index.js +30 -3
  154. package/build-module/components/url-popover/index.js.map +1 -1
  155. package/build-module/components/use-setting/index.js +1 -1
  156. package/build-module/components/use-setting/index.js.map +1 -1
  157. package/build-module/hooks/color-panel.js +17 -1
  158. package/build-module/hooks/color-panel.js.map +1 -1
  159. package/build-module/hooks/color.js +1 -1
  160. package/build-module/hooks/color.js.map +1 -1
  161. package/build-module/hooks/content-lock-ui.js +15 -8
  162. package/build-module/hooks/content-lock-ui.js.map +1 -1
  163. package/build-module/hooks/dimensions.js +39 -12
  164. package/build-module/hooks/dimensions.js.map +1 -1
  165. package/build-module/hooks/layout.js +2 -2
  166. package/build-module/hooks/layout.js.map +1 -1
  167. package/build-module/hooks/margin.js +4 -2
  168. package/build-module/hooks/margin.js.map +1 -1
  169. package/build-module/hooks/min-height.js +122 -0
  170. package/build-module/hooks/min-height.js.map +1 -0
  171. package/build-module/hooks/padding.js +4 -2
  172. package/build-module/hooks/padding.js.map +1 -1
  173. package/build-module/hooks/style.js +4 -3
  174. package/build-module/hooks/style.js.map +1 -1
  175. package/build-module/layouts/flex.js +23 -22
  176. package/build-module/layouts/flex.js.map +1 -1
  177. package/build-module/store/actions.js +22 -0
  178. package/build-module/store/actions.js.map +1 -1
  179. package/build-module/store/reducer.js +44 -14
  180. package/build-module/store/reducer.js.map +1 -1
  181. package/build-module/store/selectors.js +13 -2
  182. package/build-module/store/selectors.js.map +1 -1
  183. package/build-style/style-rtl.css +39 -26
  184. package/build-style/style.css +39 -26
  185. package/package.json +28 -28
  186. package/src/components/alignment-control/README.md +1 -1
  187. package/src/components/block-alignment-control/test/index.native.js +4 -4
  188. package/src/components/block-draggable/test/helpers.native.js +3 -3
  189. package/src/components/block-draggable/test/index.native.js +27 -27
  190. package/src/components/block-list/style.scss +10 -5
  191. package/src/components/block-lock/menu-item.js +5 -2
  192. package/src/components/block-lock/modal.js +19 -36
  193. package/src/components/block-lock/style.scss +8 -17
  194. package/src/components/block-mover/style.scss +0 -1
  195. package/src/components/block-popover/style.scss +1 -1
  196. package/src/components/block-styles/utils.js +3 -3
  197. package/src/components/block-switcher/index.js +19 -4
  198. package/src/components/block-tools/selected-block-popover.js +80 -34
  199. package/src/components/block-tools/style.scss +15 -0
  200. package/src/components/colors/with-colors.js +13 -23
  201. package/src/components/default-block-appender/style.scss +1 -0
  202. package/src/components/font-sizes/fluid-utils.js +37 -64
  203. package/src/components/font-sizes/test/fluid-utils.js +5 -5
  204. package/src/components/font-sizes/with-font-sizes.js +14 -11
  205. package/src/components/index.js +1 -0
  206. package/src/components/inner-blocks/index.js +7 -4
  207. package/src/components/inserter/reusable-blocks-tab.js +4 -2
  208. package/src/components/inserter/style.scss +8 -7
  209. package/src/components/inserter/test/reusable-blocks-tab.js +14 -57
  210. package/src/components/link-control/index.js +23 -39
  211. package/src/components/link-control/search-input.js +1 -1
  212. package/src/components/link-control/test/index.js +272 -241
  213. package/src/components/link-control/use-internal-input-value.js +22 -0
  214. package/src/components/list-view/block.js +4 -3
  215. package/src/components/list-view/branch.js +11 -6
  216. package/src/components/off-canvas-editor/README.md +5 -0
  217. package/src/components/off-canvas-editor/block-contents.js +89 -0
  218. package/src/components/off-canvas-editor/block-select-button.js +113 -0
  219. package/src/components/off-canvas-editor/block.js +335 -0
  220. package/src/components/off-canvas-editor/branch.js +210 -0
  221. package/src/components/off-canvas-editor/context.js +8 -0
  222. package/src/components/off-canvas-editor/drop-indicator.js +126 -0
  223. package/src/components/off-canvas-editor/expander.js +26 -0
  224. package/src/components/off-canvas-editor/index.js +216 -0
  225. package/src/components/off-canvas-editor/leaf.js +48 -0
  226. package/src/components/off-canvas-editor/style.scss +397 -0
  227. package/src/components/off-canvas-editor/test/utils.js +50 -0
  228. package/src/components/off-canvas-editor/use-block-selection.js +169 -0
  229. package/src/components/off-canvas-editor/use-list-view-client-ids.js +29 -0
  230. package/src/components/off-canvas-editor/use-list-view-drop-zone.js +260 -0
  231. package/src/components/off-canvas-editor/use-list-view-expand-selected-item.js +58 -0
  232. package/src/components/off-canvas-editor/utils.js +58 -0
  233. package/src/components/responsive-block-control/test/index.js +69 -92
  234. package/src/components/url-popover/README.md +12 -3
  235. package/src/components/url-popover/index.js +33 -3
  236. package/src/components/use-setting/index.js +7 -1
  237. package/src/hooks/color-panel.js +13 -1
  238. package/src/hooks/color.js +2 -0
  239. package/src/hooks/content-lock-ui.js +46 -34
  240. package/src/hooks/dimensions.js +76 -16
  241. package/src/hooks/layout.js +2 -3
  242. package/src/hooks/margin.js +4 -3
  243. package/src/hooks/min-height.js +121 -0
  244. package/src/hooks/padding.js +4 -3
  245. package/src/hooks/style.js +10 -2
  246. package/src/hooks/test/style.js +4 -0
  247. package/src/hooks/test/use-typography-props.js +1 -1
  248. package/src/layouts/flex.js +43 -38
  249. package/src/store/actions.js +22 -0
  250. package/src/store/reducer.js +50 -40
  251. package/src/store/selectors.js +16 -9
  252. package/src/store/test/actions.js +18 -0
  253. package/src/store/test/reducer.js +40 -0
  254. package/src/store/test/selectors.js +19 -0
@@ -10,7 +10,14 @@ import {
10
10
  arrowRight,
11
11
  arrowDown,
12
12
  } from '@wordpress/icons';
13
- import { Button, ToggleControl, Flex, FlexItem } from '@wordpress/components';
13
+ import {
14
+ Button,
15
+ ToggleControl,
16
+ Flex,
17
+ FlexItem,
18
+ __experimentalToggleGroupControl as ToggleGroupControl,
19
+ __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
20
+ } from '@wordpress/components';
14
21
 
15
22
  /**
16
23
  * Internal dependencies
@@ -289,22 +296,23 @@ function FlexLayoutJustifyContentControl( {
289
296
  }
290
297
 
291
298
  return (
292
- <fieldset className="block-editor-hooks__flex-layout-justification-controls">
293
- <legend>{ __( 'Justification' ) }</legend>
294
- <div>
295
- { justificationOptions.map( ( { value, icon, label } ) => {
296
- return (
297
- <Button
298
- key={ value }
299
- label={ label }
300
- icon={ icon }
301
- isPressed={ justifyContent === value }
302
- onClick={ () => onJustificationChange( value ) }
303
- />
304
- );
305
- } ) }
306
- </div>
307
- </fieldset>
299
+ <ToggleGroupControl
300
+ label={ __( 'Justification' ) }
301
+ value={ justifyContent }
302
+ onChange={ onJustificationChange }
303
+ className="block-editor-hooks__flex-layout-justification-controls"
304
+ >
305
+ { justificationOptions.map( ( { value, icon, label } ) => {
306
+ return (
307
+ <ToggleGroupControlOptionIcon
308
+ key={ value }
309
+ value={ value }
310
+ icon={ icon }
311
+ label={ label }
312
+ />
313
+ );
314
+ } ) }
315
+ </ToggleGroupControl>
308
316
  );
309
317
  }
310
318
 
@@ -327,30 +335,27 @@ function FlexWrapControl( { layout, onChange } ) {
327
335
  function OrientationControl( { layout, onChange } ) {
328
336
  const { orientation = 'horizontal' } = layout;
329
337
  return (
330
- <fieldset className="block-editor-hooks__flex-layout-orientation-controls">
331
- <legend>{ __( 'Orientation' ) }</legend>
332
- <Button
333
- label={ __( 'Horizontal' ) }
338
+ <ToggleGroupControl
339
+ className="block-editor-hooks__flex-layout-orientation-controls"
340
+ label={ __( 'Orientation' ) }
341
+ value={ orientation }
342
+ onChange={ ( value ) =>
343
+ onChange( {
344
+ ...layout,
345
+ orientation: value,
346
+ } )
347
+ }
348
+ >
349
+ <ToggleGroupControlOptionIcon
334
350
  icon={ arrowRight }
335
- isPressed={ orientation === 'horizontal' }
336
- onClick={ () =>
337
- onChange( {
338
- ...layout,
339
- orientation: 'horizontal',
340
- } )
341
- }
351
+ value={ 'horizontal' }
352
+ label={ __( 'Horizontal' ) }
342
353
  />
343
- <Button
344
- label={ __( 'Vertical' ) }
354
+ <ToggleGroupControlOptionIcon
345
355
  icon={ arrowDown }
346
- isPressed={ orientation === 'vertical' }
347
- onClick={ () =>
348
- onChange( {
349
- ...layout,
350
- orientation: 'vertical',
351
- } )
352
- }
356
+ value={ 'vertical' }
357
+ label={ __( 'Vertical' ) }
353
358
  />
354
- </fieldset>
359
+ </ToggleGroupControl>
355
360
  );
356
361
  }
@@ -1263,6 +1263,28 @@ export function toggleBlockMode( clientId ) {
1263
1263
  };
1264
1264
  }
1265
1265
 
1266
+ /**
1267
+ * Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be hidden.
1268
+ *
1269
+ * @return {Object} Action object.
1270
+ */
1271
+ export function __experimentalHideBlockInterface() {
1272
+ return {
1273
+ type: 'HIDE_BLOCK_INTERFACE',
1274
+ };
1275
+ }
1276
+
1277
+ /**
1278
+ * Returns an action object used in signalling that the block interface, eg. toolbar, outline, etc. should be shown.
1279
+ *
1280
+ * @return {Object} Action object.
1281
+ */
1282
+ export function __experimentalShowBlockInterface() {
1283
+ return {
1284
+ type: 'SHOW_BLOCK_INTERFACE',
1285
+ };
1286
+ }
1287
+
1266
1288
  /**
1267
1289
  * Returns an action object used in signalling that the user has begun to type.
1268
1290
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { reduce, omit, mapValues, isEqual, isEmpty } from 'lodash';
4
+ import { omit, mapValues, isEqual, isEmpty } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -683,30 +683,22 @@ const withReplaceInnerBlocks = ( reducer ) => ( state, action ) => {
683
683
  // will be deleted entirely from its entity.
684
684
  stateAfterInsert.order = {
685
685
  ...stateAfterInsert.order,
686
- ...reduce(
687
- nestedControllers,
688
- ( result, value, key ) => {
689
- if ( state.order[ key ] ) {
690
- result[ key ] = state.order[ key ];
691
- }
692
- return result;
693
- },
694
- {}
695
- ),
686
+ ...Object.keys( nestedControllers ).reduce( ( result, key ) => {
687
+ if ( state.order[ key ] ) {
688
+ result[ key ] = state.order[ key ];
689
+ }
690
+ return result;
691
+ }, {} ),
696
692
  };
697
693
  stateAfterInsert.tree = {
698
694
  ...stateAfterInsert.tree,
699
- ...reduce(
700
- nestedControllers,
701
- ( result, value, _key ) => {
702
- const key = `controlled||${ _key }`;
703
- if ( state.tree[ key ] ) {
704
- result[ key ] = state.tree[ key ];
705
- }
706
- return result;
707
- },
708
- {}
709
- ),
695
+ ...Object.keys( nestedControllers ).reduce( ( result, _key ) => {
696
+ const key = `controlled||${ _key }`;
697
+ if ( state.tree[ key ] ) {
698
+ result[ key ] = state.tree[ key ];
699
+ }
700
+ return result;
701
+ }, {} ),
710
702
  };
711
703
  }
712
704
  return stateAfterInsert;
@@ -873,24 +865,22 @@ export const blocks = pipe(
873
865
  const next = action.clientIds.reduce(
874
866
  ( accumulator, id ) => ( {
875
867
  ...accumulator,
876
- [ id ]: reduce(
868
+ [ id ]: Object.entries(
877
869
  action.uniqueByBlock
878
870
  ? action.attributes[ id ]
879
- : action.attributes,
880
- ( result, value, key ) => {
881
- // Consider as updates only changed values.
882
- if ( value !== result[ key ] ) {
883
- result = getMutateSafeObject(
884
- state[ id ],
885
- result
886
- );
887
- result[ key ] = value;
888
- }
889
-
890
- return result;
891
- },
892
- state[ id ]
893
- ),
871
+ : action.attributes ?? {}
872
+ ).reduce( ( result, [ key, value ] ) => {
873
+ // Consider as updates only changed values.
874
+ if ( value !== result[ key ] ) {
875
+ result = getMutateSafeObject(
876
+ state[ id ],
877
+ result
878
+ );
879
+ result[ key ] = value;
880
+ }
881
+
882
+ return result;
883
+ }, state[ id ] ),
894
884
  } ),
895
885
  {}
896
886
  );
@@ -1056,8 +1046,7 @@ export const blocks = pipe(
1056
1046
  } ),
1057
1047
  ( nextState ) =>
1058
1048
  mapValues( nextState, ( subState ) =>
1059
- reduce(
1060
- subState,
1049
+ Object.values( subState ).reduce(
1061
1050
  ( result, clientId ) => {
1062
1051
  if ( clientId === clientIds[ 0 ] ) {
1063
1052
  return [
@@ -1160,6 +1149,26 @@ export const blocks = pipe(
1160
1149
  },
1161
1150
  } );
1162
1151
 
1152
+ /**
1153
+ * Reducer returning visibility status of block interface.
1154
+ *
1155
+ * @param {boolean} state Current state.
1156
+ * @param {Object} action Dispatched action.
1157
+ *
1158
+ * @return {boolean} Updated state.
1159
+ */
1160
+ export function isBlockInterfaceHidden( state = false, action ) {
1161
+ switch ( action.type ) {
1162
+ case 'HIDE_BLOCK_INTERFACE':
1163
+ return true;
1164
+
1165
+ case 'SHOW_BLOCK_INTERFACE':
1166
+ return false;
1167
+ }
1168
+
1169
+ return state;
1170
+ }
1171
+
1163
1172
  /**
1164
1173
  * Reducer returning typing state.
1165
1174
  *
@@ -1809,6 +1818,7 @@ export function temporarilyEditingAsBlocks( state = '', action ) {
1809
1818
  export default combineReducers( {
1810
1819
  blocks,
1811
1820
  isTyping,
1821
+ isBlockInterfaceHidden,
1812
1822
  draggedBlocks,
1813
1823
  selection,
1814
1824
  isMultiSelecting,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { map, reduce, find, filter, orderBy } from 'lodash';
4
+ import { map, find, filter, orderBy } from 'lodash';
5
5
  import createSelector from 'rememo';
6
6
 
7
7
  /**
@@ -273,14 +273,10 @@ export const getGlobalBlockCount = createSelector(
273
273
  if ( ! blockName ) {
274
274
  return clientIds.length;
275
275
  }
276
- return reduce(
277
- clientIds,
278
- ( accumulator, clientId ) => {
279
- const block = state.blocks.byClientId[ clientId ];
280
- return block.name === blockName ? accumulator + 1 : accumulator;
281
- },
282
- 0
283
- );
276
+ return clientIds.reduce( ( accumulator, clientId ) => {
277
+ const block = state.blocks.byClientId[ clientId ];
278
+ return block.name === blockName ? accumulator + 1 : accumulator;
279
+ }, 0 );
284
280
  },
285
281
  ( state ) => [ state.blocks.order, state.blocks.byClientId ]
286
282
  );
@@ -1274,6 +1270,17 @@ export function isTyping( state ) {
1274
1270
  return state.isTyping;
1275
1271
  }
1276
1272
 
1273
+ /**
1274
+ * Returns true if the the block interface should be hidden, or false otherwise.
1275
+ *
1276
+ * @param {Object} state Global application state.
1277
+ *
1278
+ * @return {boolean} Whether the block toolbar is hidden.
1279
+ */
1280
+ export function __experimentalIsBlockInterfaceHidden( state ) {
1281
+ return state.isBlockInterfaceHidden;
1282
+ }
1283
+
1277
1284
  /**
1278
1285
  * Returns true if the user is dragging blocks, or false otherwise.
1279
1286
  *
@@ -27,6 +27,7 @@ const noop = () => {};
27
27
 
28
28
  const {
29
29
  clearSelectedBlock,
30
+ __experimentalHideBlockInterface: hideBlockInterface,
30
31
  insertBlock,
31
32
  insertBlocks,
32
33
  mergeBlocks,
@@ -39,6 +40,7 @@ const {
39
40
  replaceInnerBlocks,
40
41
  resetBlocks,
41
42
  selectBlock,
43
+ __experimentalShowBlockInterface: showBlockInterface,
42
44
  showInsertionPoint,
43
45
  startMultiSelect,
44
46
  startTyping,
@@ -775,6 +777,22 @@ describe( 'actions', () => {
775
777
  } );
776
778
  } );
777
779
 
780
+ describe( 'hideBlockInterface', () => {
781
+ it( 'should return the HIDE_BLOCK_INTERFACE action', () => {
782
+ expect( hideBlockInterface() ).toEqual( {
783
+ type: 'HIDE_BLOCK_INTERFACE',
784
+ } );
785
+ } );
786
+ } );
787
+
788
+ describe( 'showBlockInterface', () => {
789
+ it( 'should return the SHOW_BLOCK_INTERFACE action', () => {
790
+ expect( showBlockInterface() ).toEqual( {
791
+ type: 'SHOW_BLOCK_INTERFACE',
792
+ } );
793
+ } );
794
+ } );
795
+
778
796
  describe( 'startTyping', () => {
779
797
  it( 'should return the START_TYPING action', () => {
780
798
  expect( startTyping() ).toEqual( {
@@ -19,6 +19,7 @@ import {
19
19
  hasSameKeys,
20
20
  isUpdatingSameBlockAttribute,
21
21
  blocks,
22
+ isBlockInterfaceHidden,
22
23
  isTyping,
23
24
  draggedBlocks,
24
25
  selection,
@@ -1894,6 +1895,27 @@ describe( 'state', () => {
1894
1895
 
1895
1896
  expect( state.attributes ).toBe( state.attributes );
1896
1897
  } );
1898
+
1899
+ it( 'should handle undefined attributes', () => {
1900
+ const original = deepFreeze(
1901
+ blocks( undefined, {
1902
+ type: 'RESET_BLOCKS',
1903
+ blocks: [
1904
+ {
1905
+ clientId: 'kumquat',
1906
+ attributes: {},
1907
+ innerBlocks: [],
1908
+ },
1909
+ ],
1910
+ } )
1911
+ );
1912
+ const state = blocks( original, {
1913
+ type: 'UPDATE_BLOCK_ATTRIBUTES',
1914
+ clientIds: [ 'kumquat' ],
1915
+ } );
1916
+
1917
+ expect( state.attributes.kumquat ).toEqual( {} );
1918
+ } );
1897
1919
  } );
1898
1920
 
1899
1921
  describe( 'isPersistentChange', () => {
@@ -2253,6 +2275,24 @@ describe( 'state', () => {
2253
2275
  } );
2254
2276
  } );
2255
2277
 
2278
+ describe( 'isBlockInterfaceHidden()', () => {
2279
+ it( 'should set the hide block interface flag to true', () => {
2280
+ const state = isBlockInterfaceHidden( false, {
2281
+ type: 'HIDE_BLOCK_INTERFACE',
2282
+ } );
2283
+
2284
+ expect( state ).toBe( true );
2285
+ } );
2286
+
2287
+ it( 'should set the hide block interface flag to false', () => {
2288
+ const state = isBlockInterfaceHidden( false, {
2289
+ type: 'SHOW_BLOCK_INTERFACE',
2290
+ } );
2291
+
2292
+ expect( state ).toBe( false );
2293
+ } );
2294
+ } );
2295
+
2256
2296
  describe( 'isTyping()', () => {
2257
2297
  it( 'should set the typing flag to true', () => {
2258
2298
  const state = isTyping( false, {
@@ -44,6 +44,7 @@ const {
44
44
  isBlockMultiSelected,
45
45
  isFirstMultiSelectedBlock,
46
46
  getBlockMode,
47
+ __experimentalIsBlockInterfaceHidden: isBlockInterfaceHidden,
47
48
  isTyping,
48
49
  isDraggingBlocks,
49
50
  getDraggedBlockClientIds,
@@ -1940,6 +1941,24 @@ describe( 'selectors', () => {
1940
1941
  } );
1941
1942
  } );
1942
1943
 
1944
+ describe( 'isBlockInterfaceHidden', () => {
1945
+ it( 'should return the true if toggled true in state', () => {
1946
+ const state = {
1947
+ isBlockInterfaceHidden: true,
1948
+ };
1949
+
1950
+ expect( isBlockInterfaceHidden( state ) ).toBe( true );
1951
+ } );
1952
+
1953
+ it( 'should return false if toggled false in state', () => {
1954
+ const state = {
1955
+ isBlockInterfaceHidden: false,
1956
+ };
1957
+
1958
+ expect( isBlockInterfaceHidden( state ) ).toBe( false );
1959
+ } );
1960
+ } );
1961
+
1943
1962
  describe( 'isTyping', () => {
1944
1963
  it( 'should return the isTyping flag if the block is selected', () => {
1945
1964
  const state = {