@wordpress/block-editor 12.22.0 → 12.23.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 (273) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +4 -0
  3. package/build/components/block-list/block.js +11 -3
  4. package/build/components/block-list/block.js.map +1 -1
  5. package/build/components/block-mover/button.js +4 -1
  6. package/build/components/block-mover/button.js.map +1 -1
  7. package/build/components/block-mover/index.js +5 -1
  8. package/build/components/block-mover/index.js.map +1 -1
  9. package/build/components/block-patterns-list/index.js +4 -1
  10. package/build/components/block-patterns-list/index.js.map +1 -1
  11. package/build/components/block-settings-menu/block-settings-dropdown.js +7 -3
  12. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  13. package/build/components/block-switcher/index.js +4 -3
  14. package/build/components/block-switcher/index.js.map +1 -1
  15. package/build/components/block-toolbar/index.js +5 -4
  16. package/build/components/block-toolbar/index.js.map +1 -1
  17. package/build/components/block-toolbar/shuffle.js +18 -9
  18. package/build/components/block-toolbar/shuffle.js.map +1 -1
  19. package/build/components/block-tools/block-selection-button.js +48 -8
  20. package/build/components/block-tools/block-selection-button.js.map +1 -1
  21. package/build/components/block-tools/index.js +14 -2
  22. package/build/components/block-tools/index.js.map +1 -1
  23. package/build/components/global-styles/advanced-panel.js +9 -2
  24. package/build/components/global-styles/advanced-panel.js.map +1 -1
  25. package/build/components/global-styles/background-panel.js +444 -0
  26. package/build/components/global-styles/background-panel.js.map +1 -0
  27. package/build/components/global-styles/color-panel.js +2 -1
  28. package/build/components/global-styles/color-panel.js.map +1 -1
  29. package/build/components/global-styles/get-global-styles-changes.js +3 -0
  30. package/build/components/global-styles/get-global-styles-changes.js.map +1 -1
  31. package/build/components/global-styles/hooks.js +1 -1
  32. package/build/components/global-styles/hooks.js.map +1 -1
  33. package/build/components/global-styles/index.js +13 -0
  34. package/build/components/global-styles/index.js.map +1 -1
  35. package/build/components/global-styles/use-global-styles-output.js +15 -14
  36. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  37. package/build/components/global-styles/utils.js +2 -1
  38. package/build/components/global-styles/utils.js.map +1 -1
  39. package/build/components/iframe/index.js +9 -4
  40. package/build/components/iframe/index.js.map +1 -1
  41. package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
  42. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
  43. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
  44. package/build/components/inserter/library.js +2 -0
  45. package/build/components/inserter/library.js.map +1 -1
  46. package/build/components/inserter/menu.js +8 -2
  47. package/build/components/inserter/menu.js.map +1 -1
  48. package/build/components/inserter/search-items.js +36 -15
  49. package/build/components/inserter/search-items.js.map +1 -1
  50. package/build/components/keyboard-shortcuts/index.js +11 -0
  51. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  52. package/build/components/list-view/block-select-button.js +16 -0
  53. package/build/components/list-view/block-select-button.js.map +1 -1
  54. package/build/components/list-view/block.js +1 -1
  55. package/build/components/list-view/block.js.map +1 -1
  56. package/build/components/list-view/index.js +17 -2
  57. package/build/components/list-view/index.js.map +1 -1
  58. package/build/components/list-view/use-list-view-collapse-items.js +47 -0
  59. package/build/components/list-view/use-list-view-collapse-items.js.map +1 -0
  60. package/build/components/rich-text/index.js +14 -11
  61. package/build/components/rich-text/index.js.map +1 -1
  62. package/build/components/rich-text/index.native.js +17 -11
  63. package/build/components/rich-text/index.native.js.map +1 -1
  64. package/build/components/rich-text/native/get-format-colors.native.js +1 -1
  65. package/build/components/rich-text/native/get-format-colors.native.js.map +1 -1
  66. package/build/components/rich-text/native/index.native.js +2 -2
  67. package/build/components/rich-text/native/index.native.js.map +1 -1
  68. package/build/components/rich-text/with-deprecations.js +0 -3
  69. package/build/components/rich-text/with-deprecations.js.map +1 -1
  70. package/build/components/url-popover/image-url-input-ui.js +50 -36
  71. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  72. package/build/components/use-block-display-information/index.js +4 -6
  73. package/build/components/use-block-display-information/index.js.map +1 -1
  74. package/build/hooks/anchor.js +2 -2
  75. package/build/hooks/anchor.js.map +1 -1
  76. package/build/hooks/background.js +70 -424
  77. package/build/hooks/background.js.map +1 -1
  78. package/build/hooks/index.js +7 -0
  79. package/build/hooks/index.js.map +1 -1
  80. package/build/hooks/use-zoom-out.js +47 -0
  81. package/build/hooks/use-zoom-out.js.map +1 -0
  82. package/build/index.js +7 -0
  83. package/build/index.js.map +1 -1
  84. package/build/private-apis.js +6 -1
  85. package/build/private-apis.js.map +1 -1
  86. package/build/private-apis.native.js +3 -1
  87. package/build/private-apis.native.js.map +1 -1
  88. package/build/store/private-actions.js +13 -0
  89. package/build/store/private-actions.js.map +1 -1
  90. package/build/store/private-keys.js +2 -1
  91. package/build/store/private-keys.js.map +1 -1
  92. package/build/store/private-selectors.js +24 -3
  93. package/build/store/private-selectors.js.map +1 -1
  94. package/build/store/reducer.js +22 -0
  95. package/build/store/reducer.js.map +1 -1
  96. package/build/store/selectors.js +34 -32
  97. package/build/store/selectors.js.map +1 -1
  98. package/build/store/utils.js +7 -1
  99. package/build/store/utils.js.map +1 -1
  100. package/build/utils/transform-styles/index.js +2 -1
  101. package/build/utils/transform-styles/index.js.map +1 -1
  102. package/build-module/components/block-list/block.js +11 -3
  103. package/build-module/components/block-list/block.js.map +1 -1
  104. package/build-module/components/block-mover/button.js +4 -1
  105. package/build-module/components/block-mover/button.js.map +1 -1
  106. package/build-module/components/block-mover/index.js +5 -1
  107. package/build-module/components/block-mover/index.js.map +1 -1
  108. package/build-module/components/block-patterns-list/index.js +4 -1
  109. package/build-module/components/block-patterns-list/index.js.map +1 -1
  110. package/build-module/components/block-settings-menu/block-settings-dropdown.js +7 -3
  111. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  112. package/build-module/components/block-switcher/index.js +4 -3
  113. package/build-module/components/block-switcher/index.js.map +1 -1
  114. package/build-module/components/block-toolbar/index.js +5 -4
  115. package/build-module/components/block-toolbar/index.js.map +1 -1
  116. package/build-module/components/block-toolbar/shuffle.js +18 -9
  117. package/build-module/components/block-toolbar/shuffle.js.map +1 -1
  118. package/build-module/components/block-tools/block-selection-button.js +50 -10
  119. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  120. package/build-module/components/block-tools/index.js +14 -2
  121. package/build-module/components/block-tools/index.js.map +1 -1
  122. package/build-module/components/global-styles/advanced-panel.js +9 -2
  123. package/build-module/components/global-styles/advanced-panel.js.map +1 -1
  124. package/build-module/components/global-styles/background-panel.js +430 -0
  125. package/build-module/components/global-styles/background-panel.js.map +1 -0
  126. package/build-module/components/global-styles/color-panel.js +2 -1
  127. package/build-module/components/global-styles/color-panel.js.map +1 -1
  128. package/build-module/components/global-styles/get-global-styles-changes.js +3 -0
  129. package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -1
  130. package/build-module/components/global-styles/hooks.js +1 -1
  131. package/build-module/components/global-styles/hooks.js.map +1 -1
  132. package/build-module/components/global-styles/index.js +1 -0
  133. package/build-module/components/global-styles/index.js.map +1 -1
  134. package/build-module/components/global-styles/use-global-styles-output.js +16 -15
  135. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  136. package/build-module/components/global-styles/utils.js +1 -0
  137. package/build-module/components/global-styles/utils.js.map +1 -1
  138. package/build-module/components/iframe/index.js +9 -4
  139. package/build-module/components/iframe/index.js.map +1 -1
  140. package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
  141. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
  142. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -1
  143. package/build-module/components/inserter/library.js +2 -0
  144. package/build-module/components/inserter/library.js.map +1 -1
  145. package/build-module/components/inserter/menu.js +8 -2
  146. package/build-module/components/inserter/menu.js.map +1 -1
  147. package/build-module/components/inserter/search-items.js +33 -15
  148. package/build-module/components/inserter/search-items.js.map +1 -1
  149. package/build-module/components/keyboard-shortcuts/index.js +11 -0
  150. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  151. package/build-module/components/list-view/block-select-button.js +16 -0
  152. package/build-module/components/list-view/block-select-button.js.map +1 -1
  153. package/build-module/components/list-view/block.js +1 -1
  154. package/build-module/components/list-view/block.js.map +1 -1
  155. package/build-module/components/list-view/index.js +17 -2
  156. package/build-module/components/list-view/index.js.map +1 -1
  157. package/build-module/components/list-view/use-list-view-collapse-items.js +40 -0
  158. package/build-module/components/list-view/use-list-view-collapse-items.js.map +1 -0
  159. package/build-module/components/rich-text/index.js +15 -12
  160. package/build-module/components/rich-text/index.js.map +1 -1
  161. package/build-module/components/rich-text/index.native.js +16 -11
  162. package/build-module/components/rich-text/index.native.js.map +1 -1
  163. package/build-module/components/rich-text/native/get-format-colors.native.js +1 -1
  164. package/build-module/components/rich-text/native/get-format-colors.native.js.map +1 -1
  165. package/build-module/components/rich-text/native/index.native.js +2 -2
  166. package/build-module/components/rich-text/native/index.native.js.map +1 -1
  167. package/build-module/components/rich-text/with-deprecations.js +0 -3
  168. package/build-module/components/rich-text/with-deprecations.js.map +1 -1
  169. package/build-module/components/url-popover/image-url-input-ui.js +50 -36
  170. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  171. package/build-module/components/use-block-display-information/index.js +5 -7
  172. package/build-module/components/use-block-display-information/index.js.map +1 -1
  173. package/build-module/hooks/anchor.js +2 -2
  174. package/build-module/hooks/anchor.js.map +1 -1
  175. package/build-module/hooks/background.js +67 -419
  176. package/build-module/hooks/background.js.map +1 -1
  177. package/build-module/hooks/index.js +1 -0
  178. package/build-module/hooks/index.js.map +1 -1
  179. package/build-module/hooks/use-zoom-out.js +41 -0
  180. package/build-module/hooks/use-zoom-out.js.map +1 -0
  181. package/build-module/index.js +1 -1
  182. package/build-module/index.js.map +1 -1
  183. package/build-module/private-apis.js +7 -2
  184. package/build-module/private-apis.js.map +1 -1
  185. package/build-module/private-apis.native.js +3 -1
  186. package/build-module/private-apis.native.js.map +1 -1
  187. package/build-module/store/private-actions.js +12 -0
  188. package/build-module/store/private-actions.js.map +1 -1
  189. package/build-module/store/private-keys.js +1 -0
  190. package/build-module/store/private-keys.js.map +1 -1
  191. package/build-module/store/private-selectors.js +22 -4
  192. package/build-module/store/private-selectors.js.map +1 -1
  193. package/build-module/store/reducer.js +21 -0
  194. package/build-module/store/reducer.js.map +1 -1
  195. package/build-module/store/selectors.js +35 -33
  196. package/build-module/store/selectors.js.map +1 -1
  197. package/build-module/store/utils.js +6 -1
  198. package/build-module/store/utils.js.map +1 -1
  199. package/build-module/utils/transform-styles/index.js +2 -1
  200. package/build-module/utils/transform-styles/index.js.map +1 -1
  201. package/build-style/content-rtl.css +4 -1
  202. package/build-style/content.css +4 -1
  203. package/build-style/style-rtl.css +84 -79
  204. package/build-style/style.css +84 -79
  205. package/package.json +31 -31
  206. package/src/components/block-list/block.js +19 -3
  207. package/src/components/block-mover/button.js +4 -1
  208. package/src/components/block-mover/index.js +8 -1
  209. package/src/components/block-patterns-list/index.js +22 -17
  210. package/src/components/block-preview/style.scss +28 -0
  211. package/src/components/block-settings-menu/block-settings-dropdown.js +8 -2
  212. package/src/components/block-switcher/index.js +5 -3
  213. package/src/components/block-switcher/style.scss +1 -1
  214. package/src/components/block-toolbar/index.js +22 -19
  215. package/src/components/block-toolbar/shuffle.js +19 -13
  216. package/src/components/block-toolbar/style.scss +1 -1
  217. package/src/components/block-tools/block-selection-button.js +66 -9
  218. package/src/components/block-tools/index.js +18 -1
  219. package/src/components/button-block-appender/content.scss +5 -1
  220. package/src/components/default-block-appender/content.scss +2 -2
  221. package/src/components/global-styles/advanced-panel.js +8 -2
  222. package/src/components/global-styles/background-panel.js +591 -0
  223. package/src/components/global-styles/color-panel.js +2 -1
  224. package/src/components/global-styles/get-global-styles-changes.js +3 -0
  225. package/src/components/global-styles/hooks.js +1 -0
  226. package/src/components/global-styles/index.js +4 -0
  227. package/src/components/global-styles/style.scss +78 -1
  228. package/src/{hooks/test/background.js → components/global-styles/test/background-panel.js} +36 -1
  229. package/src/components/global-styles/test/get-global-styles-changes.js +22 -3
  230. package/src/components/global-styles/test/use-global-styles-output.js +9 -9
  231. package/src/components/global-styles/use-global-styles-output.js +27 -16
  232. package/src/components/global-styles/utils.js +1 -0
  233. package/src/components/iframe/index.js +19 -9
  234. package/src/components/inserter/block-patterns-tab/index.js +1 -0
  235. package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +5 -0
  236. package/src/components/inserter/library.js +4 -0
  237. package/src/components/inserter/menu.js +8 -1
  238. package/src/components/inserter/search-items.js +37 -15
  239. package/src/components/inserter/style.scss +6 -12
  240. package/src/components/keyboard-shortcuts/index.js +11 -0
  241. package/src/components/list-view/block-select-button.js +13 -1
  242. package/src/components/list-view/block.js +1 -1
  243. package/src/components/list-view/index.js +18 -1
  244. package/src/components/list-view/style.scss +4 -4
  245. package/src/components/list-view/use-list-view-collapse-items.js +33 -0
  246. package/src/components/rich-text/index.js +30 -13
  247. package/src/components/rich-text/index.native.js +14 -11
  248. package/src/components/rich-text/native/get-format-colors.native.js +1 -1
  249. package/src/components/rich-text/native/index.native.js +2 -2
  250. package/src/components/rich-text/with-deprecations.js +0 -3
  251. package/src/components/url-popover/image-url-input-ui.js +68 -51
  252. package/src/components/use-block-display-information/index.js +8 -10
  253. package/src/hooks/anchor.js +11 -9
  254. package/src/hooks/background.js +77 -538
  255. package/src/hooks/index.js +1 -0
  256. package/src/hooks/use-zoom-out.js +36 -0
  257. package/src/index.js +1 -0
  258. package/src/private-apis.js +13 -1
  259. package/src/private-apis.native.js +2 -0
  260. package/src/store/private-actions.js +12 -0
  261. package/src/store/private-keys.js +1 -0
  262. package/src/store/private-selectors.js +54 -27
  263. package/src/store/reducer.js +22 -0
  264. package/src/store/selectors.js +195 -180
  265. package/src/store/test/private-actions.js +10 -0
  266. package/src/store/test/private-selectors.js +13 -0
  267. package/src/store/test/reducer.js +26 -0
  268. package/src/store/test/selectors.js +90 -199
  269. package/src/store/utils.js +13 -0
  270. package/src/style.scss +0 -2
  271. package/src/utils/transform-styles/index.js +2 -1
  272. package/src/hooks/anchor.scss +0 -4
  273. package/src/hooks/background.scss +0 -75
@@ -30,6 +30,7 @@ import {
30
30
  checkAllowListRecursive,
31
31
  checkAllowList,
32
32
  getAllPatternsDependants,
33
+ getInsertBlockTypeDependants,
33
34
  } from './utils';
34
35
  import { orderBy } from '../utils/sorting';
35
36
  import { STORE_NAME } from './constants';
@@ -1235,11 +1236,22 @@ export function isBlockSelected( state, clientId ) {
1235
1236
  * @return {boolean} Whether the block has an inner block selected
1236
1237
  */
1237
1238
  export function hasSelectedInnerBlock( state, clientId, deep = false ) {
1238
- return getBlockOrder( state, clientId ).some(
1239
- ( innerClientId ) =>
1240
- isBlockSelected( state, innerClientId ) ||
1241
- isBlockMultiSelected( state, innerClientId ) ||
1242
- ( deep && hasSelectedInnerBlock( state, innerClientId, deep ) )
1239
+ const selectedBlockClientIds = getSelectedBlockClientIds( state );
1240
+
1241
+ if ( ! selectedBlockClientIds.length ) {
1242
+ return false;
1243
+ }
1244
+
1245
+ if ( deep ) {
1246
+ return selectedBlockClientIds.some( ( id ) =>
1247
+ // Pass true because we don't care about order and it's more
1248
+ // performant.
1249
+ getBlockParents( state, id, true ).includes( clientId )
1250
+ );
1251
+ }
1252
+
1253
+ return selectedBlockClientIds.some(
1254
+ ( id ) => getBlockRootClientId( state, id ) === clientId
1243
1255
  );
1244
1256
  }
1245
1257
 
@@ -1666,13 +1678,8 @@ const canInsertBlockTypeUnmemoized = (
1666
1678
  */
1667
1679
  export const canInsertBlockType = createSelector(
1668
1680
  canInsertBlockTypeUnmemoized,
1669
- ( state, blockName, rootClientId ) => [
1670
- state.blockListSettings[ rootClientId ],
1671
- state.blocks.byClientId.get( rootClientId ),
1672
- state.settings.allowedBlockTypes,
1673
- state.settings.templateLock,
1674
- state.blockEditingModes,
1675
- ]
1681
+ ( state, blockName, rootClientId ) =>
1682
+ getInsertBlockTypeDependants( state, rootClientId )
1676
1683
  );
1677
1684
 
1678
1685
  /**
@@ -1977,95 +1984,108 @@ const buildBlockTypeItem =
1977
1984
  * this item.
1978
1985
  * @property {number} frecency Heuristic that combines frequency and recency.
1979
1986
  */
1980
- export const getInserterItems = createSelector(
1981
- ( state, rootClientId = null ) => {
1982
- const buildReusableBlockInserterItem = ( reusableBlock ) => {
1983
- const icon = ! reusableBlock.wp_pattern_sync_status
1984
- ? {
1985
- src: symbol,
1986
- foreground: 'var(--wp-block-synced-color)',
1987
- }
1988
- : symbol;
1989
- const id = `core/block/${ reusableBlock.id }`;
1990
- const { time, count = 0 } = getInsertUsage( state, id ) || {};
1991
- const frecency = calculateFrecency( time, count );
1992
-
1993
- return {
1994
- id,
1995
- name: 'core/block',
1996
- initialAttributes: { ref: reusableBlock.id },
1997
- title: reusableBlock.title?.raw,
1998
- icon,
1999
- category: 'reusable',
2000
- keywords: [ 'reusable' ],
2001
- isDisabled: false,
2002
- utility: 1, // Deprecated.
2003
- frecency,
2004
- content: reusableBlock.content?.raw,
2005
- syncStatus: reusableBlock.wp_pattern_sync_status,
1987
+ export const getInserterItems = createRegistrySelector( ( select ) =>
1988
+ createSelector(
1989
+ ( state, rootClientId = null ) => {
1990
+ const buildReusableBlockInserterItem = ( reusableBlock ) => {
1991
+ const icon = ! reusableBlock.wp_pattern_sync_status
1992
+ ? {
1993
+ src: symbol,
1994
+ foreground: 'var(--wp-block-synced-color)',
1995
+ }
1996
+ : symbol;
1997
+ const id = `core/block/${ reusableBlock.id }`;
1998
+ const { time, count = 0 } = getInsertUsage( state, id ) || {};
1999
+ const frecency = calculateFrecency( time, count );
2000
+
2001
+ return {
2002
+ id,
2003
+ name: 'core/block',
2004
+ initialAttributes: { ref: reusableBlock.id },
2005
+ title: reusableBlock.title?.raw,
2006
+ icon,
2007
+ category: 'reusable',
2008
+ keywords: [ 'reusable' ],
2009
+ isDisabled: false,
2010
+ utility: 1, // Deprecated.
2011
+ frecency,
2012
+ content: reusableBlock.content?.raw,
2013
+ syncStatus: reusableBlock.wp_pattern_sync_status,
2014
+ };
2006
2015
  };
2007
- };
2008
-
2009
- const syncedPatternInserterItems = canInsertBlockTypeUnmemoized(
2010
- state,
2011
- 'core/block',
2012
- rootClientId
2013
- )
2014
- ? getReusableBlocks( state ).map( buildReusableBlockInserterItem )
2015
- : [];
2016
2016
 
2017
- const buildBlockTypeInserterItem = buildBlockTypeItem( state, {
2018
- buildScope: 'inserter',
2019
- } );
2020
-
2021
- const blockTypeInserterItems = getBlockTypes()
2022
- .filter( ( blockType ) =>
2023
- canIncludeBlockTypeInInserter( state, blockType, rootClientId )
2017
+ const syncedPatternInserterItems = canInsertBlockTypeUnmemoized(
2018
+ state,
2019
+ 'core/block',
2020
+ rootClientId
2024
2021
  )
2025
- .map( buildBlockTypeInserterItem );
2022
+ ? unlock( select( STORE_NAME ) )
2023
+ .getReusableBlocks()
2024
+ .map( buildReusableBlockInserterItem )
2025
+ : [];
2026
2026
 
2027
- const items = blockTypeInserterItems.reduce( ( accumulator, item ) => {
2028
- const { variations = [] } = item;
2029
- // Exclude any block type item that is to be replaced by a default variation.
2030
- if ( ! variations.some( ( { isDefault } ) => isDefault ) ) {
2031
- accumulator.push( item );
2032
- }
2033
- if ( variations.length ) {
2034
- const variationMapper = getItemFromVariation( state, item );
2035
- accumulator.push( ...variations.map( variationMapper ) );
2036
- }
2037
- return accumulator;
2038
- }, [] );
2027
+ const buildBlockTypeInserterItem = buildBlockTypeItem( state, {
2028
+ buildScope: 'inserter',
2029
+ } );
2039
2030
 
2040
- // Ensure core blocks are prioritized in the returned results,
2041
- // because third party blocks can be registered earlier than
2042
- // the core blocks (usually by using the `init` action),
2043
- // thus affecting the display order.
2044
- // We don't sort reusable blocks as they are handled differently.
2045
- const groupByType = ( blocks, block ) => {
2046
- const { core, noncore } = blocks;
2047
- const type = block.name.startsWith( 'core/' ) ? core : noncore;
2048
-
2049
- type.push( block );
2050
- return blocks;
2051
- };
2052
- const { core: coreItems, noncore: nonCoreItems } = items.reduce(
2053
- groupByType,
2054
- { core: [], noncore: [] }
2055
- );
2056
- const sortedBlockTypes = [ ...coreItems, ...nonCoreItems ];
2057
- return [ ...sortedBlockTypes, ...syncedPatternInserterItems ];
2058
- },
2059
- ( state, rootClientId ) => [
2060
- state.blockListSettings[ rootClientId ],
2061
- state.blocks.byClientId.get( rootClientId ),
2062
- state.blocks.order,
2063
- state.preferences.insertUsage,
2064
- state.settings.allowedBlockTypes,
2065
- state.settings.templateLock,
2066
- getReusableBlocks( state ),
2067
- getBlockTypes(),
2068
- ]
2031
+ const blockTypeInserterItems = getBlockTypes()
2032
+ .filter( ( blockType ) =>
2033
+ canIncludeBlockTypeInInserter(
2034
+ state,
2035
+ blockType,
2036
+ rootClientId
2037
+ )
2038
+ )
2039
+ .map( buildBlockTypeInserterItem );
2040
+
2041
+ const items = blockTypeInserterItems.reduce(
2042
+ ( accumulator, item ) => {
2043
+ const { variations = [] } = item;
2044
+ // Exclude any block type item that is to be replaced by a default variation.
2045
+ if ( ! variations.some( ( { isDefault } ) => isDefault ) ) {
2046
+ accumulator.push( item );
2047
+ }
2048
+ if ( variations.length ) {
2049
+ const variationMapper = getItemFromVariation(
2050
+ state,
2051
+ item
2052
+ );
2053
+ accumulator.push(
2054
+ ...variations.map( variationMapper )
2055
+ );
2056
+ }
2057
+ return accumulator;
2058
+ },
2059
+ []
2060
+ );
2061
+
2062
+ // Ensure core blocks are prioritized in the returned results,
2063
+ // because third party blocks can be registered earlier than
2064
+ // the core blocks (usually by using the `init` action),
2065
+ // thus affecting the display order.
2066
+ // We don't sort reusable blocks as they are handled differently.
2067
+ const groupByType = ( blocks, block ) => {
2068
+ const { core, noncore } = blocks;
2069
+ const type = block.name.startsWith( 'core/' ) ? core : noncore;
2070
+
2071
+ type.push( block );
2072
+ return blocks;
2073
+ };
2074
+ const { core: coreItems, noncore: nonCoreItems } = items.reduce(
2075
+ groupByType,
2076
+ { core: [], noncore: [] }
2077
+ );
2078
+ const sortedBlockTypes = [ ...coreItems, ...nonCoreItems ];
2079
+ return [ ...sortedBlockTypes, ...syncedPatternInserterItems ];
2080
+ },
2081
+ ( state, rootClientId ) => [
2082
+ getBlockTypes(),
2083
+ unlock( select( STORE_NAME ) ).getReusableBlocks(),
2084
+ state.blocks.order,
2085
+ state.preferences.insertUsage,
2086
+ ...getInsertBlockTypeDependants( state, rootClientId ),
2087
+ ]
2088
+ )
2069
2089
  );
2070
2090
 
2071
2091
  /**
@@ -2128,12 +2148,9 @@ export const getBlockTransformItems = createSelector(
2128
2148
  );
2129
2149
  },
2130
2150
  ( state, blocks, rootClientId ) => [
2131
- state.blockListSettings[ rootClientId ],
2132
- state.blocks.byClientId.get( rootClientId ),
2133
- state.preferences.insertUsage,
2134
- state.settings.allowedBlockTypes,
2135
- state.settings.templateLock,
2136
2151
  getBlockTypes(),
2152
+ state.preferences.insertUsage,
2153
+ ...getInsertBlockTypeDependants( state, rootClientId ),
2137
2154
  ]
2138
2155
  );
2139
2156
 
@@ -2145,28 +2162,25 @@ export const getBlockTransformItems = createSelector(
2145
2162
  *
2146
2163
  * @return {boolean} Items that appear in inserter.
2147
2164
  */
2148
- export const hasInserterItems = createSelector(
2149
- ( state, rootClientId = null ) => {
2150
- const hasBlockType = getBlockTypes().some( ( blockType ) =>
2151
- canIncludeBlockTypeInInserter( state, blockType, rootClientId )
2152
- );
2153
- if ( hasBlockType ) {
2154
- return true;
2155
- }
2156
- const hasReusableBlock =
2157
- canInsertBlockTypeUnmemoized( state, 'core/block', rootClientId ) &&
2158
- getReusableBlocks( state ).length > 0;
2165
+ export const hasInserterItems = createRegistrySelector(
2166
+ ( select ) =>
2167
+ ( state, rootClientId = null ) => {
2168
+ const hasBlockType = getBlockTypes().some( ( blockType ) =>
2169
+ canIncludeBlockTypeInInserter( state, blockType, rootClientId )
2170
+ );
2171
+ if ( hasBlockType ) {
2172
+ return true;
2173
+ }
2174
+ const hasReusableBlock =
2175
+ canInsertBlockTypeUnmemoized(
2176
+ state,
2177
+ 'core/block',
2178
+ rootClientId
2179
+ ) &&
2180
+ unlock( select( STORE_NAME ) ).getReusableBlocks().length > 0;
2159
2181
 
2160
- return hasReusableBlock;
2161
- },
2162
- ( state, rootClientId ) => [
2163
- state.blockListSettings[ rootClientId ],
2164
- state.blocks.byClientId.get( rootClientId ),
2165
- state.settings.allowedBlockTypes,
2166
- state.settings.templateLock,
2167
- getReusableBlocks( state ),
2168
- getBlockTypes(),
2169
- ]
2182
+ return hasReusableBlock;
2183
+ }
2170
2184
  );
2171
2185
 
2172
2186
  /**
@@ -2177,34 +2191,37 @@ export const hasInserterItems = createSelector(
2177
2191
  *
2178
2192
  * @return {Array?} The list of allowed block types.
2179
2193
  */
2180
- export const getAllowedBlocks = createSelector(
2181
- ( state, rootClientId = null ) => {
2182
- if ( ! rootClientId ) {
2183
- return;
2184
- }
2194
+ export const getAllowedBlocks = createRegistrySelector( ( select ) =>
2195
+ createSelector(
2196
+ ( state, rootClientId = null ) => {
2197
+ if ( ! rootClientId ) {
2198
+ return;
2199
+ }
2185
2200
 
2186
- const blockTypes = getBlockTypes().filter( ( blockType ) =>
2187
- canIncludeBlockTypeInInserter( state, blockType, rootClientId )
2188
- );
2201
+ const blockTypes = getBlockTypes().filter( ( blockType ) =>
2202
+ canIncludeBlockTypeInInserter( state, blockType, rootClientId )
2203
+ );
2189
2204
 
2190
- const hasReusableBlock =
2191
- canInsertBlockTypeUnmemoized( state, 'core/block', rootClientId ) &&
2192
- getReusableBlocks( state ).length > 0;
2205
+ const hasReusableBlock =
2206
+ canInsertBlockTypeUnmemoized(
2207
+ state,
2208
+ 'core/block',
2209
+ rootClientId
2210
+ ) &&
2211
+ unlock( select( STORE_NAME ) ).getReusableBlocks().length > 0;
2193
2212
 
2194
- if ( hasReusableBlock ) {
2195
- blockTypes.push( 'core/block' );
2196
- }
2213
+ if ( hasReusableBlock ) {
2214
+ blockTypes.push( 'core/block' );
2215
+ }
2197
2216
 
2198
- return blockTypes;
2199
- },
2200
- ( state, rootClientId ) => [
2201
- state.blockListSettings[ rootClientId ],
2202
- state.blocks.byClientId.get( rootClientId ),
2203
- state.settings.allowedBlockTypes,
2204
- state.settings.templateLock,
2205
- getReusableBlocks( state ),
2206
- getBlockTypes(),
2207
- ]
2217
+ return blockTypes;
2218
+ },
2219
+ ( state, rootClientId ) => [
2220
+ getBlockTypes(),
2221
+ unlock( select( STORE_NAME ) ).getReusableBlocks(),
2222
+ ...getInsertBlockTypeDependants( state, rootClientId ),
2223
+ ]
2224
+ )
2208
2225
  );
2209
2226
 
2210
2227
  export const __experimentalGetAllowedBlocks = createSelector(
@@ -2220,9 +2237,8 @@ export const __experimentalGetAllowedBlocks = createSelector(
2220
2237
  );
2221
2238
  return getAllowedBlocks( state, rootClientId );
2222
2239
  },
2223
- ( state, rootClientId ) => [
2224
- ...getAllowedBlocks.getDependants( state, rootClientId ),
2225
- ]
2240
+ ( state, rootClientId ) =>
2241
+ getAllowedBlocks.getDependants( state, rootClientId )
2226
2242
  );
2227
2243
 
2228
2244
  /**
@@ -2287,6 +2303,10 @@ export const __experimentalGetParsedPattern = createRegistrySelector(
2287
2303
  metadata: {
2288
2304
  ...( blocks[ 0 ].attributes.metadata || {} ),
2289
2305
  categories: pattern.categories,
2306
+ patternName: pattern.name,
2307
+ name:
2308
+ blocks[ 0 ].attributes.metadata?.name ||
2309
+ pattern.title,
2290
2310
  },
2291
2311
  };
2292
2312
  }
@@ -2297,15 +2317,10 @@ export const __experimentalGetParsedPattern = createRegistrySelector(
2297
2317
  }, getAllPatternsDependants( select ) )
2298
2318
  );
2299
2319
 
2300
- const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) => {
2301
- return [
2302
- ...getAllPatternsDependants( select )( state ),
2303
- state.settings.allowedBlockTypes,
2304
- state.settings.templateLock,
2305
- state.blockListSettings[ rootClientId ],
2306
- state.blocks.byClientId.get( rootClientId ),
2307
- ];
2308
- };
2320
+ const getAllowedPatternsDependants = ( select ) => ( state, rootClientId ) => [
2321
+ ...getAllPatternsDependants( select )( state ),
2322
+ ...getInsertBlockTypeDependants( state, rootClientId ),
2323
+ ];
2309
2324
 
2310
2325
  /**
2311
2326
  * Returns the list of allowed patterns for inner blocks children.
@@ -2526,18 +2541,29 @@ export const __experimentalGetBlockListSettingsForBlocks = createSelector(
2526
2541
  *
2527
2542
  * @return {string} The reusable block saved title.
2528
2543
  */
2529
- export const __experimentalGetReusableBlockTitle = createSelector(
2530
- ( state, ref ) => {
2531
- const reusableBlock = getReusableBlocks( state ).find(
2532
- ( block ) => block.id === ref
2533
- );
2534
- if ( ! reusableBlock ) {
2535
- return null;
2536
- }
2544
+ export const __experimentalGetReusableBlockTitle = createRegistrySelector(
2545
+ ( select ) =>
2546
+ createSelector(
2547
+ ( state, ref ) => {
2548
+ deprecated(
2549
+ "wp.data.select( 'core/block-editor' ).__experimentalGetReusableBlockTitle",
2550
+ {
2551
+ since: '6.6',
2552
+ version: '6.8',
2553
+ }
2554
+ );
2537
2555
 
2538
- return reusableBlock.title?.raw;
2539
- },
2540
- ( state ) => [ getReusableBlocks( state ) ]
2556
+ const reusableBlock = unlock( select( STORE_NAME ) )
2557
+ .getReusableBlocks()
2558
+ .find( ( block ) => block.id === ref );
2559
+ if ( ! reusableBlock ) {
2560
+ return null;
2561
+ }
2562
+
2563
+ return reusableBlock.title?.raw;
2564
+ },
2565
+ () => [ unlock( select( STORE_NAME ) ).getReusableBlocks() ]
2566
+ )
2541
2567
  );
2542
2568
 
2543
2569
  /**
@@ -2571,17 +2597,6 @@ export function __experimentalGetLastBlockAttributeChanges( state ) {
2571
2597
  return state.lastBlockAttributesChange;
2572
2598
  }
2573
2599
 
2574
- /**
2575
- * Returns the available reusable blocks
2576
- *
2577
- * @param {Object} state Global application state.
2578
- *
2579
- * @return {Array} Reusable blocks
2580
- */
2581
- function getReusableBlocks( state ) {
2582
- return state.settings.__experimentalReusableBlocks ?? EMPTY_ARRAY;
2583
- }
2584
-
2585
2600
  /**
2586
2601
  * Returns whether the navigation mode is enabled.
2587
2602
  *
@@ -4,6 +4,7 @@
4
4
  import {
5
5
  hideBlockInterface,
6
6
  showBlockInterface,
7
+ expandBlock,
7
8
  __experimentalUpdateSettings,
8
9
  setOpenedBlockSettingsMenu,
9
10
  startDragging,
@@ -113,4 +114,13 @@ describe( 'private actions', () => {
113
114
  } );
114
115
  } );
115
116
  } );
117
+
118
+ describe( 'expandBlock', () => {
119
+ it( 'should return the SET_BLOCK_EXPANDED_IN_LIST_VIEW action', () => {
120
+ expect( expandBlock( 'block-1' ) ).toEqual( {
121
+ type: 'SET_BLOCK_EXPANDED_IN_LIST_VIEW',
122
+ clientId: 'block-1',
123
+ } );
124
+ } );
125
+ } );
116
126
  } );
@@ -7,6 +7,7 @@ import {
7
7
  isBlockSubtreeDisabled,
8
8
  getEnabledClientIdsTree,
9
9
  getEnabledBlockParents,
10
+ getExpandedBlock,
10
11
  isDragging,
11
12
  } from '../private-selectors';
12
13
  import { getBlockEditingMode } from '../selectors';
@@ -496,4 +497,16 @@ describe( 'private selectors', () => {
496
497
  expect( isDragging( state ) ).toBe( false );
497
498
  } );
498
499
  } );
500
+
501
+ describe( 'getExpandedBlock', () => {
502
+ it( 'should return the expanded block', () => {
503
+ const state = {
504
+ expandedBlock: '9b9c5c3f-2e46-4f02-9e14-9fe9515b958f',
505
+ };
506
+
507
+ expect( getExpandedBlock( state ) ).toBe(
508
+ '9b9c5c3f-2e46-4f02-9e14-9fe9515b958f'
509
+ );
510
+ } );
511
+ } );
499
512
  } );
@@ -35,6 +35,7 @@ import {
35
35
  lastBlockInserted,
36
36
  blockEditingModes,
37
37
  openedBlockSettingsMenu,
38
+ expandedBlock,
38
39
  } from '../reducer';
39
40
 
40
41
  const noop = () => {};
@@ -3459,4 +3460,29 @@ describe( 'state', () => {
3459
3460
  expect( state ).toBe( null );
3460
3461
  } );
3461
3462
  } );
3463
+
3464
+ describe( 'expandedBlock', () => {
3465
+ it( 'should return null by default', () => {
3466
+ expect( expandedBlock( undefined, {} ) ).toBe( null );
3467
+ } );
3468
+
3469
+ it( 'should set client id for expanded block', () => {
3470
+ const state = expandedBlock( null, {
3471
+ type: 'SET_BLOCK_EXPANDED_IN_LIST_VIEW',
3472
+ clientId: '14501cc2-90a6-4f52-aa36-ab6e896135d1',
3473
+ } );
3474
+ expect( state ).toBe( '14501cc2-90a6-4f52-aa36-ab6e896135d1' );
3475
+ } );
3476
+
3477
+ it( 'should clear the state when a block is selected', () => {
3478
+ const state = expandedBlock(
3479
+ '14501cc2-90a6-4f52-aa36-ab6e896135d1',
3480
+ {
3481
+ type: 'SELECT_BLOCK',
3482
+ clientId: 'a-different-block',
3483
+ }
3484
+ );
3485
+ expect( state ).toBe( null );
3486
+ } );
3487
+ } );
3462
3488
  } );