@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
@@ -33,7 +33,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
33
33
  fontSize: '30px',
34
34
  } );
35
35
  expect( fluidTypographyValues ).toBe(
36
- 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 2.704), 45px)'
36
+ 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 0.901), 30px)'
37
37
  );
38
38
  } );
39
39
 
@@ -42,7 +42,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
42
42
  fontSize: '30px',
43
43
  } );
44
44
  expect( fluidTypographyValues ).toBe(
45
- 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 2.704), 45px)'
45
+ 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 0.901), 30px)'
46
46
  );
47
47
  } );
48
48
 
@@ -53,7 +53,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
53
53
  maximumViewPortWidth: '1000px',
54
54
  } );
55
55
  expect( fluidTypographyValues ).toBe(
56
- 'clamp(22.5px, 1.406rem + ((1vw - 5px) * 4.5), 45px)'
56
+ 'clamp(22.5px, 1.406rem + ((1vw - 5px) * 1.5), 30px)'
57
57
  );
58
58
  } );
59
59
 
@@ -63,7 +63,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
63
63
  scaleFactor: '2',
64
64
  } );
65
65
  expect( fluidTypographyValues ).toBe(
66
- 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 5.409), 45px)'
66
+ 'clamp(22.5px, 1.406rem + ((1vw - 7.68px) * 1.803), 30px)'
67
67
  );
68
68
  } );
69
69
 
@@ -74,7 +74,7 @@ describe( 'getComputedFluidTypographyValue()', () => {
74
74
  maximumFontSizeFactor: '2',
75
75
  } );
76
76
  expect( fluidTypographyValues ).toBe(
77
- 'clamp(15px, 0.938rem + ((1vw - 7.68px) * 5.409), 60px)'
77
+ 'clamp(15px, 0.938rem + ((1vw - 7.68px) * 1.803), 30px)'
78
78
  );
79
79
  } );
80
80
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { find, pickBy, reduce } from 'lodash';
4
+ import { find, pickBy } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -43,8 +43,7 @@ export default ( ...fontSizeNames ) => {
43
43
  * and the value is the custom font size attribute name.
44
44
  * Custom font size is automatically compted by appending custom followed by the font size attribute name in with the first letter capitalized.
45
45
  */
46
- const fontSizeAttributeNames = reduce(
47
- fontSizeNames,
46
+ const fontSizeAttributeNames = fontSizeNames.reduce(
48
47
  ( fontSizeAttributeNamesAccumulator, fontSizeAttributeName ) => {
49
48
  fontSizeAttributeNamesAccumulator[
50
49
  fontSizeAttributeName
@@ -81,12 +80,13 @@ export default ( ...fontSizeNames ) => {
81
80
  }
82
81
 
83
82
  createSetters() {
84
- return reduce(
85
- fontSizeAttributeNames,
83
+ return Object.entries( fontSizeAttributeNames ).reduce(
86
84
  (
87
85
  settersAccumulator,
88
- customFontSizeAttributeName,
89
- fontSizeAttributeName
86
+ [
87
+ fontSizeAttributeName,
88
+ customFontSizeAttributeName,
89
+ ]
90
90
  ) => {
91
91
  const upperFirstFontSizeAttributeName =
92
92
  upperFirst( fontSizeAttributeName );
@@ -159,15 +159,18 @@ export default ( ...fontSizeNames ) => {
159
159
  return null;
160
160
  }
161
161
 
162
- const newState = reduce(
162
+ const newState = Object.entries(
163
163
  pickBy(
164
164
  fontSizeAttributeNames,
165
165
  didAttributesChange
166
- ),
166
+ )
167
+ ).reduce(
167
168
  (
168
169
  newStateAccumulator,
169
- customFontSizeAttributeName,
170
- fontSizeAttributeName
170
+ [
171
+ fontSizeAttributeName,
172
+ customFontSizeAttributeName,
173
+ ]
171
174
  ) => {
172
175
  const fontSizeAttributeValue =
173
176
  attributes[ fontSizeAttributeName ];
@@ -73,6 +73,7 @@ export { default as __experimentalLinkControlSearchResults } from './link-contro
73
73
  export { default as __experimentalLinkControlSearchItem } from './link-control/search-item';
74
74
  export { default as LineHeightControl } from './line-height-control';
75
75
  export { default as __experimentalListView } from './list-view';
76
+ export { default as __experimentalOffCanvasEditor } from './off-canvas-editor';
76
77
  export { default as MediaReplaceFlow } from './media-replace-flow';
77
78
  export { default as MediaPlaceholder } from './media-placeholder';
78
79
  export { default as MediaUpload } from './media-upload';
@@ -150,7 +150,8 @@ const ForwardedInnerBlocks = forwardRef( ( props, ref ) => {
150
150
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inner-blocks/README.md
151
151
  */
152
152
  export function useInnerBlocksProps( props = {}, options = {} ) {
153
- const { __unstableDisableLayoutClassNames } = options;
153
+ const { __unstableDisableLayoutClassNames, __unstableDisableDropZone } =
154
+ options;
154
155
  const { clientId, __unstableLayoutClassNames: layoutClassNames = '' } =
155
156
  useBlockEditContext();
156
157
  const isSmallScreen = useViewportMatch( 'medium', '<' );
@@ -187,11 +188,13 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
187
188
  [ clientId, isSmallScreen ]
188
189
  );
189
190
 
191
+ const blockDropZoneRef = useBlockDropZone( {
192
+ rootClientId: clientId,
193
+ } );
194
+
190
195
  const ref = useMergeRefs( [
191
196
  props.ref,
192
- useBlockDropZone( {
193
- rootClientId: clientId,
194
- } ),
197
+ __unstableDisableDropZone ? null : blockDropZoneRef,
195
198
  ] );
196
199
 
197
200
  const innerBlocksProps = {
@@ -4,6 +4,7 @@
4
4
  import { useMemo } from '@wordpress/element';
5
5
  import { __ } from '@wordpress/i18n';
6
6
  import { addQueryArgs } from '@wordpress/url';
7
+ import { Button } from '@wordpress/components';
7
8
 
8
9
  /**
9
10
  * Internal dependencies
@@ -59,14 +60,15 @@ export function ReusableBlocksTab( { rootClientId, onInsert, onHover } ) {
59
60
  rootClientId={ rootClientId }
60
61
  />
61
62
  <div className="block-editor-inserter__manage-reusable-blocks-container">
62
- <a
63
+ <Button
63
64
  className="block-editor-inserter__manage-reusable-blocks"
65
+ variant="secondary"
64
66
  href={ addQueryArgs( 'edit.php', {
65
67
  post_type: 'wp_block',
66
68
  } ) }
67
69
  >
68
70
  { __( 'Manage Reusable blocks' ) }
69
- </a>
71
+ </Button>
70
72
  </div>
71
73
  </>
72
74
  );
@@ -174,9 +174,13 @@ $block-inserter-tabs-height: 44px;
174
174
  text-align: right;
175
175
  }
176
176
 
177
+ .block-editor-inserter__manage-reusable-blocks-container {
178
+ margin: auto $grid-unit-20 $grid-unit-20;
179
+ }
180
+
177
181
  .block-editor-inserter__manage-reusable-blocks {
178
- display: inline-block;
179
- margin: $grid-unit-20;
182
+ justify-content: center;
183
+ width: 100%;
180
184
  }
181
185
 
182
186
  .block-editor-inserter__no-results {
@@ -341,10 +345,6 @@ $block-inserter-tabs-height: 44px;
341
345
  position: relative; // prevents overscroll when block library is open
342
346
  }
343
347
 
344
- .block-editor-inserter__manage-reusable-blocks-container {
345
- padding: $grid-unit-20;
346
- }
347
-
348
348
  .block-editor-inserter__quick-inserter {
349
349
  width: 100%;
350
350
 
@@ -442,7 +442,8 @@ $block-inserter-tabs-height: 44px;
442
442
  }
443
443
 
444
444
  &__list {
445
- margin-left: $sidebar-width - $grid-unit-40;
445
+ margin-left: $sidebar-width;
446
+ padding: $grid-unit-30 0 $grid-unit-40;
446
447
  }
447
448
 
448
449
  .block-editor-block-patterns-list {
@@ -1,13 +1,12 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { render, fireEvent } from '@testing-library/react';
4
+ import { render, screen } from '@testing-library/react';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { registerBlockType, unregisterBlockType } from '@wordpress/blocks';
10
- import { useSelect } from '@wordpress/data';
11
10
 
12
11
  /**
13
12
  * Internal dependencies
@@ -22,35 +21,6 @@ jest.mock( '../hooks/use-block-types-state', () => {
22
21
  return mock;
23
22
  } );
24
23
 
25
- jest.mock( '@wordpress/data/src/components/use-select', () => {
26
- // This allows us to tweak the returned value on each test.
27
- const mock = jest.fn();
28
- return mock;
29
- } );
30
-
31
- jest.mock( '@wordpress/data/src/components/use-dispatch', () => {
32
- return {
33
- useDispatch: () => ( {} ),
34
- };
35
- } );
36
-
37
- const debouncedSpeak = jest.fn();
38
-
39
- function InserterBlockList( props ) {
40
- return <ReusableBlocksTab debouncedSpeak={ debouncedSpeak } { ...props } />;
41
- }
42
-
43
- const initializeAllClosedMenuState = ( propOverrides ) => {
44
- const { container } = render( <InserterBlockList { ...propOverrides } /> );
45
- const activeTabs = container.querySelectorAll(
46
- '.components-panel__body.is-opened button.components-panel__body-toggle'
47
- );
48
- activeTabs.forEach( ( tab ) => {
49
- fireEvent.click( tab );
50
- } );
51
- return container;
52
- };
53
-
54
24
  describe( 'InserterMenu', () => {
55
25
  beforeAll( () => {
56
26
  registerBlockType( 'core/block', {
@@ -59,19 +29,17 @@ describe( 'InserterMenu', () => {
59
29
  edit: () => {},
60
30
  } );
61
31
  } );
32
+
62
33
  afterAll( () => {
63
34
  unregisterBlockType( 'core/block' );
64
35
  } );
65
- beforeEach( () => {
66
- debouncedSpeak.mockClear();
67
36
 
37
+ beforeEach( () => {
68
38
  useBlockTypesState.mockImplementation( () => [
69
39
  items,
70
40
  categories,
71
41
  collections,
72
42
  ] );
73
-
74
- useSelect.mockImplementation( () => false );
75
43
  } );
76
44
 
77
45
  it( 'should show nothing if there are no items', () => {
@@ -81,36 +49,25 @@ describe( 'InserterMenu', () => {
81
49
  categories,
82
50
  collections,
83
51
  ] );
84
- const { container } = render(
85
- <InserterBlockList filterValue="random" />
86
- );
87
- const visibleBlocks = container.querySelector(
88
- '.block-editor-block-types-list__item'
89
- );
90
52
 
91
- expect( visibleBlocks ).toBe( null );
53
+ render( <ReusableBlocksTab filterValue="random" /> );
54
+
55
+ expect( screen.queryByRole( 'option' ) ).not.toBeInTheDocument();
92
56
  } );
93
57
 
94
58
  it( 'should list reusable blocks', () => {
95
- const container = initializeAllClosedMenuState();
96
- const blocks = container.querySelectorAll(
97
- '.block-editor-block-types-list__item-title'
98
- );
59
+ render( <ReusableBlocksTab /> );
99
60
 
100
- expect( blocks ).toHaveLength( 1 );
101
- expect( blocks[ 0 ] ).toHaveTextContent( 'My reusable block' );
61
+ expect(
62
+ screen.getByRole( 'option', { name: 'My reusable block' } )
63
+ ).toBeVisible();
102
64
  } );
103
65
 
104
66
  it( 'should trim whitespace of search terms', () => {
105
- const { container } = render(
106
- <InserterBlockList filterValue=" my reusable" />
107
- );
108
-
109
- const blocks = container.querySelectorAll(
110
- '.block-editor-block-types-list__item-title'
111
- );
67
+ render( <ReusableBlocksTab filterValue=" my reusable" /> );
112
68
 
113
- expect( blocks ).toHaveLength( 1 );
114
- expect( blocks[ 0 ] ).toHaveTextContent( 'My reusable block' );
69
+ expect(
70
+ screen.getByRole( 'option', { name: 'My reusable block' } )
71
+ ).toBeVisible();
115
72
  } );
116
73
  } );
@@ -20,6 +20,7 @@ import LinkControlSettingsDrawer from './settings-drawer';
20
20
  import LinkControlSearchInput from './search-input';
21
21
  import LinkPreview from './link-preview';
22
22
  import useCreatePage from './use-create-page';
23
+ import useInternalInputValue from './use-internal-input-value';
23
24
  import { ViewerFill } from './viewer-slot';
24
25
  import { DEFAULT_LINK_SETTINGS } from './constants';
25
26
 
@@ -132,22 +133,19 @@ function LinkControl( {
132
133
  const isMounting = useRef( true );
133
134
  const wrapperNode = useRef();
134
135
  const textInputRef = useRef();
136
+ const isEndingEditWithFocus = useRef( false );
137
+
138
+ const [ internalUrlInputValue, setInternalUrlInputValue ] =
139
+ useInternalInputValue( value?.url || '' );
140
+
141
+ const [ internalTextInputValue, setInternalTextInputValue ] =
142
+ useInternalInputValue( value?.title || '' );
135
143
 
136
- const [ internalInputValue, setInternalInputValue ] = useState(
137
- value?.url || ''
138
- );
139
- const [ internalTextValue, setInternalTextValue ] = useState(
140
- value?.title || ''
141
- );
142
- const currentInputValue = propInputValue || internalInputValue;
143
144
  const [ isEditingLink, setIsEditingLink ] = useState(
144
145
  forceIsEditingLink !== undefined
145
146
  ? forceIsEditingLink
146
147
  : ! value || ! value.url
147
148
  );
148
- const isEndingEditWithFocus = useRef( false );
149
-
150
- const currentInputIsEmpty = ! currentInputValue?.trim()?.length;
151
149
 
152
150
  const { createPage, isCreatingPage, errorMessage } =
153
151
  useCreatePage( createSuggestion );
@@ -191,53 +189,35 @@ function LinkControl( {
191
189
  isEndingEditWithFocus.current = false;
192
190
  }, [ isEditingLink, isCreatingPage ] );
193
191
 
194
- useEffect( () => {
195
- /**
196
- * If the value's `text` property changes then sync this
197
- * back up with state.
198
- */
199
- if ( value?.title && value.title !== internalTextValue ) {
200
- setInternalTextValue( value.title );
201
- }
202
-
203
- /**
204
- * Update the state value internalInputValue if the url value changes
205
- * for example when clicking on another anchor
206
- */
207
- if ( value?.url ) {
208
- setInternalInputValue( value.url );
209
- }
210
- }, [ value ] );
211
-
212
192
  /**
213
193
  * Cancels editing state and marks that focus may need to be restored after
214
194
  * the next render, if focus was within the wrapper when editing finished.
215
195
  */
216
- function stopEditing() {
196
+ const stopEditing = () => {
217
197
  isEndingEditWithFocus.current = !! wrapperNode.current?.contains(
218
198
  wrapperNode.current.ownerDocument.activeElement
219
199
  );
220
200
 
221
201
  setIsEditingLink( false );
222
- }
202
+ };
223
203
 
224
204
  const handleSelectSuggestion = ( updatedValue ) => {
225
205
  onChange( {
226
206
  ...updatedValue,
227
- title: internalTextValue || updatedValue?.title,
207
+ title: internalTextInputValue || updatedValue?.title,
228
208
  } );
229
209
  stopEditing();
230
210
  };
231
211
 
232
212
  const handleSubmit = () => {
233
213
  if (
234
- currentInputValue !== value?.url ||
235
- internalTextValue !== value?.title
214
+ currentUrlInputValue !== value?.url ||
215
+ internalTextInputValue !== value?.title
236
216
  ) {
237
217
  onChange( {
238
218
  ...value,
239
- url: currentInputValue,
240
- title: internalTextValue,
219
+ url: currentUrlInputValue,
220
+ title: internalTextInputValue,
241
221
  } );
242
222
  }
243
223
  stopEditing();
@@ -254,6 +234,10 @@ function LinkControl( {
254
234
  }
255
235
  };
256
236
 
237
+ const currentUrlInputValue = propInputValue || internalUrlInputValue;
238
+
239
+ const currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;
240
+
257
241
  const shownUnlinkControl =
258
242
  onRemove && value && ! isEditingLink && ! isCreatingPage;
259
243
 
@@ -289,8 +273,8 @@ function LinkControl( {
289
273
  ref={ textInputRef }
290
274
  className="block-editor-link-control__field block-editor-link-control__text-content"
291
275
  label="Text"
292
- value={ internalTextValue }
293
- onChange={ setInternalTextValue }
276
+ value={ internalTextInputValue }
277
+ onChange={ setInternalTextInputValue }
294
278
  onKeyDown={ handleSubmitWithEnter }
295
279
  />
296
280
  ) }
@@ -299,10 +283,10 @@ function LinkControl( {
299
283
  currentLink={ value }
300
284
  className="block-editor-link-control__field block-editor-link-control__search-input"
301
285
  placeholder={ searchInputPlaceholder }
302
- value={ currentInputValue }
286
+ value={ currentUrlInputValue }
303
287
  withCreateSuggestion={ withCreateSuggestion }
304
288
  onCreateSuggestion={ createPage }
305
- onChange={ setInternalInputValue }
289
+ onChange={ setInternalUrlInputValue }
306
290
  onSelect={ handleSelectSuggestion }
307
291
  showInitialSuggestions={ showInitialSuggestions }
308
292
  allowDirectEntry={ ! noDirectEntry }
@@ -111,7 +111,7 @@ const LinkControlSearchInput = forwardRef(
111
111
  allowDirectEntry ||
112
112
  ( suggestion && Object.keys( suggestion ).length >= 1 )
113
113
  ) {
114
- const { id, url, ...restLinkProps } = currentLink;
114
+ const { id, url, ...restLinkProps } = currentLink ?? {};
115
115
  onSelect(
116
116
  // Some direct entries don't have types or IDs, and we still need to clear the previous ones.
117
117
  { ...restLinkProps, ...suggestion },