@wordpress/block-editor 12.15.0 → 12.16.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 (500) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +9 -4
  3. package/build/components/block-canvas/index.js +22 -6
  4. package/build/components/block-canvas/index.js.map +1 -1
  5. package/build/components/block-card/index.js +1 -1
  6. package/build/components/block-card/index.js.map +1 -1
  7. package/build/components/block-controls/hook.js +3 -23
  8. package/build/components/block-controls/hook.js.map +1 -1
  9. package/build/components/block-edit/context.js +5 -1
  10. package/build/components/block-edit/context.js.map +1 -1
  11. package/build/components/block-edit/index.js +18 -9
  12. package/build/components/block-edit/index.js.map +1 -1
  13. package/build/components/block-info-slot-fill/index.js +3 -4
  14. package/build/components/block-info-slot-fill/index.js.map +1 -1
  15. package/build/components/block-list/block.js +28 -9
  16. package/build/components/block-list/block.js.map +1 -1
  17. package/build/components/block-list/block.native.js +14 -5
  18. package/build/components/block-list/block.native.js.map +1 -1
  19. package/build/components/block-list/use-block-props/index.js +61 -18
  20. package/build/components/block-list/use-block-props/index.js.map +1 -1
  21. package/build/components/block-list/use-block-props/use-focus-first-element.js +4 -29
  22. package/build/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  23. package/build/components/block-list/use-block-props/use-is-hovered.js +4 -14
  24. package/build/components/block-list/use-block-props/use-is-hovered.js.map +1 -1
  25. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +4 -2
  26. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  27. package/build/components/block-patterns-list/index.js +1 -1
  28. package/build/components/block-patterns-list/index.js.map +1 -1
  29. package/build/components/block-removal-warning-modal/index.js +2 -9
  30. package/build/components/block-removal-warning-modal/index.js.map +1 -1
  31. package/build/components/block-rename/modal.js +3 -0
  32. package/build/components/block-rename/modal.js.map +1 -1
  33. package/build/components/block-settings/container.native.js +6 -4
  34. package/build/components/block-settings/container.native.js.map +1 -1
  35. package/build/components/block-styles/index.js +1 -1
  36. package/build/components/block-styles/index.js.map +1 -1
  37. package/build/components/block-styles/index.native.js +3 -2
  38. package/build/components/block-styles/index.native.js.map +1 -1
  39. package/build/components/block-toolbar/index.js +89 -27
  40. package/build/components/block-toolbar/index.js.map +1 -1
  41. package/build/components/block-tools/block-toolbar-breadcrumb.js +49 -0
  42. package/build/components/block-tools/block-toolbar-breadcrumb.js.map +1 -0
  43. package/build/components/block-tools/block-toolbar-popover.js +86 -0
  44. package/build/components/block-tools/block-toolbar-popover.js.map +1 -0
  45. package/build/components/block-tools/index.js +27 -24
  46. package/build/components/block-tools/index.js.map +1 -1
  47. package/build/components/block-types-list/index.native.js +4 -3
  48. package/build/components/block-types-list/index.native.js.map +1 -1
  49. package/build/components/block-variation-picker/index.native.js +2 -1
  50. package/build/components/block-variation-picker/index.native.js.map +1 -1
  51. package/build/components/colors-gradients/control.js +28 -17
  52. package/build/components/colors-gradients/control.js.map +1 -1
  53. package/build/components/duotone-control/index.js +1 -4
  54. package/build/components/duotone-control/index.js.map +1 -1
  55. package/build/components/global-styles/color-panel.js +22 -20
  56. package/build/components/global-styles/color-panel.js.map +1 -1
  57. package/build/components/global-styles/filters-panel.js +9 -3
  58. package/build/components/global-styles/filters-panel.js.map +1 -1
  59. package/build/components/global-styles/typography-panel.js +20 -31
  60. package/build/components/global-styles/typography-panel.js.map +1 -1
  61. package/build/components/image-link-destinations/index.native.js +118 -0
  62. package/build/components/image-link-destinations/index.native.js.map +1 -0
  63. package/build/components/index.native.js +8 -0
  64. package/build/components/index.native.js.map +1 -1
  65. package/build/components/inserter/media-tab/media-panel.js +2 -2
  66. package/build/components/inserter/media-tab/media-panel.js.map +1 -1
  67. package/build/components/inserter/menu.js +14 -7
  68. package/build/components/inserter/menu.js.map +1 -1
  69. package/build/components/inserter/preview-panel.js +2 -2
  70. package/build/components/inserter/preview-panel.js.map +1 -1
  71. package/build/components/inserter-button/index.native.js +98 -0
  72. package/build/components/inserter-button/index.native.js.map +1 -0
  73. package/build/components/inserter-button/sparkles.js +23 -0
  74. package/build/components/inserter-button/sparkles.js.map +1 -0
  75. package/build/components/inserter-draggable-blocks/index.js +8 -4
  76. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  77. package/build/components/inspector-controls/fill.js +3 -3
  78. package/build/components/inspector-controls/fill.js.map +1 -1
  79. package/build/components/inspector-controls/fill.native.js +3 -3
  80. package/build/components/inspector-controls/fill.native.js.map +1 -1
  81. package/build/components/navigable-toolbar/index.js +2 -2
  82. package/build/components/navigable-toolbar/index.js.map +1 -1
  83. package/build/components/preview-options/index.js +6 -62
  84. package/build/components/preview-options/index.js.map +1 -1
  85. package/build/components/rich-text/content.js +26 -23
  86. package/build/components/rich-text/content.js.map +1 -1
  87. package/build/components/rich-text/get-rich-text-values.js +2 -1
  88. package/build/components/rich-text/get-rich-text-values.js.map +1 -1
  89. package/build/components/rich-text/index.js +2 -30
  90. package/build/components/rich-text/index.js.map +1 -1
  91. package/build/components/rich-text/index.native.js +9 -16
  92. package/build/components/rich-text/index.native.js.map +1 -1
  93. package/build/components/rich-text/native/get-format-colors.native.js +22 -24
  94. package/build/components/rich-text/native/get-format-colors.native.js.map +1 -1
  95. package/build/components/rich-text/native/index.native.js +7 -34
  96. package/build/components/rich-text/native/index.native.js.map +1 -1
  97. package/build/components/rich-text/use-input-rules.js +5 -1
  98. package/build/components/rich-text/use-input-rules.js.map +1 -1
  99. package/build/components/rich-text/with-deprecations.js +50 -0
  100. package/build/components/rich-text/with-deprecations.js.map +1 -0
  101. package/build/components/use-block-drop-zone/index.js +70 -8
  102. package/build/components/use-block-drop-zone/index.js.map +1 -1
  103. package/build/components/use-on-block-drop/index.js +1 -1
  104. package/build/components/use-on-block-drop/index.js.map +1 -1
  105. package/build/components/use-resize-canvas/index.js +4 -1
  106. package/build/components/use-resize-canvas/index.js.map +1 -1
  107. package/build/components/use-settings/index.js +14 -0
  108. package/build/components/use-settings/index.js.map +1 -1
  109. package/build/hooks/align.js +20 -68
  110. package/build/hooks/align.js.map +1 -1
  111. package/build/hooks/align.native.js +11 -1
  112. package/build/hooks/align.native.js.map +1 -1
  113. package/build/hooks/anchor.js +13 -29
  114. package/build/hooks/anchor.js.map +1 -1
  115. package/build/hooks/background.js +28 -31
  116. package/build/hooks/background.js.map +1 -1
  117. package/build/hooks/block-hooks.js +24 -32
  118. package/build/hooks/block-hooks.js.map +1 -1
  119. package/build/hooks/block-renaming.js +18 -22
  120. package/build/hooks/block-renaming.js.map +1 -1
  121. package/build/hooks/border.js +58 -80
  122. package/build/hooks/border.js.map +1 -1
  123. package/build/hooks/color.js +76 -89
  124. package/build/hooks/color.js.map +1 -1
  125. package/build/hooks/content-lock-ui.js +29 -29
  126. package/build/hooks/content-lock-ui.js.map +1 -1
  127. package/build/hooks/custom-class-name.js +12 -29
  128. package/build/hooks/custom-class-name.js.map +1 -1
  129. package/build/hooks/custom-fields.js +24 -38
  130. package/build/hooks/custom-fields.js.map +1 -1
  131. package/build/hooks/dimensions.js +21 -17
  132. package/build/hooks/dimensions.js.map +1 -1
  133. package/build/hooks/duotone.js +31 -61
  134. package/build/hooks/duotone.js.map +1 -1
  135. package/build/hooks/font-family.js +16 -25
  136. package/build/hooks/font-family.js.map +1 -1
  137. package/build/hooks/font-size.js +51 -119
  138. package/build/hooks/font-size.js.map +1 -1
  139. package/build/hooks/index.js +25 -14
  140. package/build/hooks/index.js.map +1 -1
  141. package/build/hooks/index.native.js +10 -3
  142. package/build/hooks/index.native.js.map +1 -1
  143. package/build/hooks/layout-child.js +68 -0
  144. package/build/hooks/layout-child.js.map +1 -0
  145. package/build/hooks/layout.js +16 -101
  146. package/build/hooks/layout.js.map +1 -1
  147. package/build/hooks/padding.js +2 -2
  148. package/build/hooks/padding.js.map +1 -1
  149. package/build/hooks/position.js +40 -62
  150. package/build/hooks/position.js.map +1 -1
  151. package/build/hooks/style.js +51 -88
  152. package/build/hooks/style.js.map +1 -1
  153. package/build/hooks/typography.js +34 -14
  154. package/build/hooks/typography.js.map +1 -1
  155. package/build/hooks/utils.js +154 -7
  156. package/build/hooks/utils.js.map +1 -1
  157. package/build/private-apis.js +0 -2
  158. package/build/private-apis.js.map +1 -1
  159. package/build/store/private-actions.js +8 -0
  160. package/build/store/private-actions.js.map +1 -1
  161. package/build/store/private-selectors.js +34 -0
  162. package/build/store/private-selectors.js.map +1 -1
  163. package/build/store/reducer.js +8 -0
  164. package/build/store/reducer.js.map +1 -1
  165. package/build/store/selectors.js +10 -60
  166. package/build/store/selectors.js.map +1 -1
  167. package/build/store/utils.js +66 -0
  168. package/build/store/utils.js.map +1 -0
  169. package/build/utils/object.js +21 -61
  170. package/build/utils/object.js.map +1 -1
  171. package/build/utils/selection.js +9 -1
  172. package/build/utils/selection.js.map +1 -1
  173. package/build-module/components/block-canvas/index.js +23 -7
  174. package/build-module/components/block-canvas/index.js.map +1 -1
  175. package/build-module/components/block-card/index.js +1 -1
  176. package/build-module/components/block-card/index.js.map +1 -1
  177. package/build-module/components/block-controls/hook.js +4 -24
  178. package/build-module/components/block-controls/hook.js.map +1 -1
  179. package/build-module/components/block-edit/context.js +2 -0
  180. package/build-module/components/block-edit/context.js.map +1 -1
  181. package/build-module/components/block-edit/index.js +19 -10
  182. package/build-module/components/block-edit/index.js.map +1 -1
  183. package/build-module/components/block-info-slot-fill/index.js +3 -3
  184. package/build-module/components/block-info-slot-fill/index.js.map +1 -1
  185. package/build-module/components/block-list/block.js +29 -10
  186. package/build-module/components/block-list/block.js.map +1 -1
  187. package/build-module/components/block-list/block.native.js +14 -5
  188. package/build-module/components/block-list/block.native.js.map +1 -1
  189. package/build-module/components/block-list/use-block-props/index.js +62 -19
  190. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  191. package/build-module/components/block-list/use-block-props/use-focus-first-element.js +4 -29
  192. package/build-module/components/block-list/use-block-props/use-focus-first-element.js.map +1 -1
  193. package/build-module/components/block-list/use-block-props/use-is-hovered.js +4 -14
  194. package/build-module/components/block-list/use-block-props/use-is-hovered.js.map +1 -1
  195. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +4 -2
  196. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  197. package/build-module/components/block-patterns-list/index.js +1 -1
  198. package/build-module/components/block-patterns-list/index.js.map +1 -1
  199. package/build-module/components/block-removal-warning-modal/index.js +3 -10
  200. package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
  201. package/build-module/components/block-rename/modal.js +3 -0
  202. package/build-module/components/block-rename/modal.js.map +1 -1
  203. package/build-module/components/block-settings/container.native.js +4 -2
  204. package/build-module/components/block-settings/container.native.js.map +1 -1
  205. package/build-module/components/block-styles/index.js +1 -1
  206. package/build-module/components/block-styles/index.js.map +1 -1
  207. package/build-module/components/block-styles/index.native.js +3 -2
  208. package/build-module/components/block-styles/index.native.js.map +1 -1
  209. package/build-module/components/block-toolbar/index.js +88 -25
  210. package/build-module/components/block-toolbar/index.js.map +1 -1
  211. package/build-module/components/block-tools/block-toolbar-breadcrumb.js +41 -0
  212. package/build-module/components/block-tools/block-toolbar-breadcrumb.js.map +1 -0
  213. package/build-module/components/block-tools/block-toolbar-popover.js +76 -0
  214. package/build-module/components/block-tools/block-toolbar-popover.js.map +1 -0
  215. package/build-module/components/block-tools/index.js +27 -24
  216. package/build-module/components/block-tools/index.js.map +1 -1
  217. package/build-module/components/block-types-list/index.native.js +2 -1
  218. package/build-module/components/block-types-list/index.native.js.map +1 -1
  219. package/build-module/components/block-variation-picker/index.native.js +2 -1
  220. package/build-module/components/block-variation-picker/index.native.js.map +1 -1
  221. package/build-module/components/colors-gradients/control.js +29 -18
  222. package/build-module/components/colors-gradients/control.js.map +1 -1
  223. package/build-module/components/duotone-control/index.js +1 -4
  224. package/build-module/components/duotone-control/index.js.map +1 -1
  225. package/build-module/components/global-styles/color-panel.js +23 -21
  226. package/build-module/components/global-styles/color-panel.js.map +1 -1
  227. package/build-module/components/global-styles/filters-panel.js +10 -4
  228. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  229. package/build-module/components/global-styles/typography-panel.js +20 -31
  230. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  231. package/build-module/components/image-link-destinations/index.native.js +109 -0
  232. package/build-module/components/image-link-destinations/index.native.js.map +1 -0
  233. package/build-module/components/index.native.js +1 -0
  234. package/build-module/components/index.native.js.map +1 -1
  235. package/build-module/components/inserter/media-tab/media-panel.js +1 -1
  236. package/build-module/components/inserter/media-tab/media-panel.js.map +1 -1
  237. package/build-module/components/inserter/menu.js +14 -7
  238. package/build-module/components/inserter/menu.js.map +1 -1
  239. package/build-module/components/inserter/preview-panel.js +2 -2
  240. package/build-module/components/inserter/preview-panel.js.map +1 -1
  241. package/build-module/components/inserter-button/index.native.js +89 -0
  242. package/build-module/components/inserter-button/index.native.js.map +1 -0
  243. package/build-module/components/inserter-button/sparkles.js +15 -0
  244. package/build-module/components/inserter-button/sparkles.js.map +1 -0
  245. package/build-module/components/inserter-draggable-blocks/index.js +9 -5
  246. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  247. package/build-module/components/inspector-controls/fill.js +3 -3
  248. package/build-module/components/inspector-controls/fill.js.map +1 -1
  249. package/build-module/components/inspector-controls/fill.native.js +3 -3
  250. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  251. package/build-module/components/navigable-toolbar/index.js +2 -2
  252. package/build-module/components/navigable-toolbar/index.js.map +1 -1
  253. package/build-module/components/preview-options/index.js +6 -62
  254. package/build-module/components/preview-options/index.js.map +1 -1
  255. package/build-module/components/rich-text/content.js +25 -21
  256. package/build-module/components/rich-text/content.js.map +1 -1
  257. package/build-module/components/rich-text/get-rich-text-values.js +2 -1
  258. package/build-module/components/rich-text/get-rich-text-values.js.map +1 -1
  259. package/build-module/components/rich-text/index.js +4 -32
  260. package/build-module/components/rich-text/index.js.map +1 -1
  261. package/build-module/components/rich-text/index.native.js +10 -18
  262. package/build-module/components/rich-text/index.native.js.map +1 -1
  263. package/build-module/components/rich-text/native/get-format-colors.native.js +22 -24
  264. package/build-module/components/rich-text/native/get-format-colors.native.js.map +1 -1
  265. package/build-module/components/rich-text/native/index.native.js +7 -34
  266. package/build-module/components/rich-text/native/index.native.js.map +1 -1
  267. package/build-module/components/rich-text/use-input-rules.js +5 -1
  268. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  269. package/build-module/components/rich-text/with-deprecations.js +42 -0
  270. package/build-module/components/rich-text/with-deprecations.js.map +1 -0
  271. package/build-module/components/use-block-drop-zone/index.js +69 -8
  272. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  273. package/build-module/components/use-on-block-drop/index.js +1 -1
  274. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  275. package/build-module/components/use-resize-canvas/index.js +4 -1
  276. package/build-module/components/use-resize-canvas/index.js.map +1 -1
  277. package/build-module/components/use-settings/index.js +13 -1
  278. package/build-module/components/use-settings/index.js.map +1 -1
  279. package/build-module/hooks/align.js +19 -66
  280. package/build-module/hooks/align.js.map +1 -1
  281. package/build-module/hooks/align.native.js +1 -0
  282. package/build-module/hooks/align.native.js.map +1 -1
  283. package/build-module/hooks/anchor.js +11 -26
  284. package/build-module/hooks/anchor.js.map +1 -1
  285. package/build-module/hooks/background.js +26 -28
  286. package/build-module/hooks/background.js.map +1 -1
  287. package/build-module/hooks/block-hooks.js +22 -30
  288. package/build-module/hooks/block-hooks.js.map +1 -1
  289. package/build-module/hooks/block-renaming.js +17 -21
  290. package/build-module/hooks/block-renaming.js.map +1 -1
  291. package/build-module/hooks/border.js +57 -78
  292. package/build-module/hooks/border.js.map +1 -1
  293. package/build-module/hooks/color.js +74 -86
  294. package/build-module/hooks/color.js.map +1 -1
  295. package/build-module/hooks/content-lock-ui.js +27 -27
  296. package/build-module/hooks/content-lock-ui.js.map +1 -1
  297. package/build-module/hooks/custom-class-name.js +11 -27
  298. package/build-module/hooks/custom-class-name.js.map +1 -1
  299. package/build-module/hooks/custom-fields.js +20 -39
  300. package/build-module/hooks/custom-fields.js.map +1 -1
  301. package/build-module/hooks/dimensions.js +21 -16
  302. package/build-module/hooks/dimensions.js.map +1 -1
  303. package/build-module/hooks/duotone.js +30 -61
  304. package/build-module/hooks/duotone.js.map +1 -1
  305. package/build-module/hooks/font-family.js +14 -23
  306. package/build-module/hooks/font-family.js.map +1 -1
  307. package/build-module/hooks/font-size.js +49 -119
  308. package/build-module/hooks/font-size.js.map +1 -1
  309. package/build-module/hooks/index.js +18 -14
  310. package/build-module/hooks/index.js.map +1 -1
  311. package/build-module/hooks/index.native.js +5 -3
  312. package/build-module/hooks/index.native.js.map +1 -1
  313. package/build-module/hooks/layout-child.js +60 -0
  314. package/build-module/hooks/layout-child.js.map +1 -0
  315. package/build-module/hooks/layout.js +13 -98
  316. package/build-module/hooks/layout.js.map +1 -1
  317. package/build-module/hooks/padding.js +2 -2
  318. package/build-module/hooks/padding.js.map +1 -1
  319. package/build-module/hooks/position.js +38 -59
  320. package/build-module/hooks/position.js.map +1 -1
  321. package/build-module/hooks/style.js +51 -84
  322. package/build-module/hooks/style.js.map +1 -1
  323. package/build-module/hooks/typography.js +33 -12
  324. package/build-module/hooks/typography.js.map +1 -1
  325. package/build-module/hooks/utils.js +149 -6
  326. package/build-module/hooks/utils.js.map +1 -1
  327. package/build-module/private-apis.js +0 -2
  328. package/build-module/private-apis.js.map +1 -1
  329. package/build-module/store/private-actions.js +7 -0
  330. package/build-module/store/private-actions.js.map +1 -1
  331. package/build-module/store/private-selectors.js +33 -1
  332. package/build-module/store/private-selectors.js.map +1 -1
  333. package/build-module/store/reducer.js +8 -0
  334. package/build-module/store/reducer.js.map +1 -1
  335. package/build-module/store/selectors.js +3 -53
  336. package/build-module/store/selectors.js.map +1 -1
  337. package/build-module/store/utils.js +56 -0
  338. package/build-module/store/utils.js.map +1 -0
  339. package/build-module/utils/object.js +21 -60
  340. package/build-module/utils/object.js.map +1 -1
  341. package/build-module/utils/selection.js +9 -1
  342. package/build-module/utils/selection.js.map +1 -1
  343. package/build-style/style-rtl.css +113 -293
  344. package/build-style/style.css +113 -293
  345. package/package.json +31 -31
  346. package/src/components/block-canvas/index.js +31 -17
  347. package/src/components/block-caption/README.md +2 -2
  348. package/src/components/block-card/index.js +5 -3
  349. package/src/components/block-card/style.scss +7 -3
  350. package/src/components/block-controls/hook.js +8 -30
  351. package/src/components/block-controls/test/index.js +3 -3
  352. package/src/components/block-edit/context.js +3 -0
  353. package/src/components/block-edit/index.js +36 -10
  354. package/src/components/block-info-slot-fill/index.js +6 -3
  355. package/src/components/block-inspector/style.scss +0 -4
  356. package/src/components/block-list/block.js +39 -5
  357. package/src/components/block-list/block.native.js +18 -4
  358. package/src/components/block-list/use-block-props/index.js +74 -21
  359. package/src/components/block-list/use-block-props/use-focus-first-element.js +1 -34
  360. package/src/components/block-list/use-block-props/use-is-hovered.js +2 -13
  361. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +1 -5
  362. package/src/components/block-patterns-list/index.js +1 -1
  363. package/src/components/block-removal-warning-modal/index.js +7 -14
  364. package/src/components/block-rename/modal.js +7 -1
  365. package/src/components/block-settings/container.native.js +3 -5
  366. package/src/components/block-styles/index.js +1 -1
  367. package/src/components/block-styles/index.native.js +4 -2
  368. package/src/components/block-styles/style.scss +0 -11
  369. package/src/components/block-switcher/test/__snapshots__/index.js.snap +3 -1
  370. package/src/components/block-toolbar/index.js +180 -95
  371. package/src/components/block-toolbar/style.scss +50 -66
  372. package/src/components/block-tools/block-toolbar-breadcrumb.js +46 -0
  373. package/src/components/block-tools/block-toolbar-popover.js +90 -0
  374. package/src/components/block-tools/index.js +42 -29
  375. package/src/components/block-tools/style.scss +60 -172
  376. package/src/components/block-types-list/index.native.js +2 -1
  377. package/src/components/block-variation-picker/index.native.js +1 -1
  378. package/src/components/colors-gradients/control.js +49 -30
  379. package/src/components/colors-gradients/style.scss +0 -7
  380. package/src/components/duotone-control/index.js +2 -5
  381. package/src/components/duotone-control/style.scss +1 -6
  382. package/src/components/global-styles/color-panel.js +34 -25
  383. package/src/components/global-styles/filters-panel.js +8 -4
  384. package/src/components/global-styles/typography-panel.js +23 -43
  385. package/src/components/image-link-destinations/index.native.js +152 -0
  386. package/src/components/image-link-destinations/style.native.scss +16 -0
  387. package/src/components/index.native.js +1 -0
  388. package/src/components/inner-blocks/README.md +13 -2
  389. package/src/components/inserter/media-tab/media-panel.js +1 -1
  390. package/src/components/inserter/menu.js +16 -8
  391. package/src/components/inserter/preview-panel.js +2 -2
  392. package/src/components/inserter/style.scss +15 -17
  393. package/src/components/inserter-button/README.md +62 -0
  394. package/src/components/inserter-button/index.native.js +116 -0
  395. package/src/components/inserter-button/sparkles.js +15 -0
  396. package/src/components/inserter-button/style.native.scss +72 -0
  397. package/src/components/inserter-draggable-blocks/index.js +18 -5
  398. package/src/components/inspector-controls/fill.js +6 -3
  399. package/src/components/inspector-controls/fill.native.js +6 -3
  400. package/src/components/link-control/style.scss +1 -1
  401. package/src/components/link-control/test/index.js +1 -1
  402. package/src/components/navigable-toolbar/README.md +2 -0
  403. package/src/components/navigable-toolbar/index.js +2 -2
  404. package/src/components/preview-options/index.js +6 -86
  405. package/src/components/rich-text/content.js +27 -20
  406. package/src/components/rich-text/get-rich-text-values.js +6 -1
  407. package/src/components/rich-text/index.js +5 -46
  408. package/src/components/rich-text/index.native.js +8 -25
  409. package/src/components/rich-text/native/get-format-colors.native.js +33 -40
  410. package/src/components/rich-text/native/index.native.js +7 -48
  411. package/src/components/rich-text/use-input-rules.js +6 -1
  412. package/src/components/rich-text/with-deprecations.js +51 -0
  413. package/src/components/use-block-drop-zone/index.js +114 -14
  414. package/src/components/use-on-block-drop/index.js +2 -1
  415. package/src/components/use-resize-canvas/README.md +3 -3
  416. package/src/components/use-resize-canvas/index.js +4 -1
  417. package/src/components/use-settings/index.js +15 -1
  418. package/src/hooks/align.js +15 -76
  419. package/src/hooks/align.native.js +1 -0
  420. package/src/hooks/anchor.js +13 -33
  421. package/src/hooks/background.js +28 -23
  422. package/src/hooks/block-hooks.js +22 -51
  423. package/src/hooks/block-renaming.js +23 -37
  424. package/src/hooks/border.js +67 -118
  425. package/src/hooks/color.js +100 -132
  426. package/src/hooks/content-lock-ui.js +110 -122
  427. package/src/hooks/custom-class-name.js +8 -40
  428. package/src/hooks/custom-fields.js +20 -47
  429. package/src/hooks/dimensions.js +20 -16
  430. package/src/hooks/duotone.js +70 -127
  431. package/src/hooks/font-family.js +10 -29
  432. package/src/hooks/font-size.js +66 -162
  433. package/src/hooks/index.js +42 -14
  434. package/src/hooks/index.native.js +6 -3
  435. package/src/hooks/layout-child.js +53 -0
  436. package/src/hooks/layout.js +13 -102
  437. package/src/hooks/padding.js +2 -2
  438. package/src/hooks/position.js +50 -90
  439. package/src/hooks/style.js +117 -187
  440. package/src/hooks/test/align.js +1 -178
  441. package/src/hooks/typography.js +20 -16
  442. package/src/hooks/utils.js +187 -6
  443. package/src/private-apis.js +0 -2
  444. package/src/store/private-actions.js +8 -0
  445. package/src/store/private-selectors.js +45 -0
  446. package/src/store/reducer.js +8 -0
  447. package/src/store/selectors.js +5 -69
  448. package/src/store/utils.js +74 -0
  449. package/src/style.scss +0 -2
  450. package/src/utils/object.js +18 -69
  451. package/src/utils/selection.js +9 -2
  452. package/build/components/block-list/use-block-props/use-block-class-names.js +0 -67
  453. package/build/components/block-list/use-block-props/use-block-class-names.js.map +0 -1
  454. package/build/components/block-list/use-block-props/use-block-custom-class-name.js +0 -46
  455. package/build/components/block-list/use-block-props/use-block-custom-class-name.js.map +0 -1
  456. package/build/components/block-list/use-block-props/use-block-default-class-name.js +0 -37
  457. package/build/components/block-list/use-block-props/use-block-default-class-name.js.map +0 -1
  458. package/build/components/block-tools/back-compat.js +0 -45
  459. package/build/components/block-tools/back-compat.js.map +0 -1
  460. package/build/components/block-tools/block-contextual-toolbar.js +0 -91
  461. package/build/components/block-tools/block-contextual-toolbar.js.map +0 -1
  462. package/build/components/block-tools/selected-block-tools.js +0 -113
  463. package/build/components/block-tools/selected-block-tools.js.map +0 -1
  464. package/build/components/inserter/hooks/use-debounced-input.js +0 -22
  465. package/build/components/inserter/hooks/use-debounced-input.js.map +0 -1
  466. package/build/components/use-display-block-controls/index.js +0 -39
  467. package/build/components/use-display-block-controls/index.js.map +0 -1
  468. package/build/components/use-display-block-controls/index.native.js +0 -39
  469. package/build/components/use-display-block-controls/index.native.js.map +0 -1
  470. package/build-module/components/block-list/use-block-props/use-block-class-names.js +0 -60
  471. package/build-module/components/block-list/use-block-props/use-block-class-names.js.map +0 -1
  472. package/build-module/components/block-list/use-block-props/use-block-custom-class-name.js +0 -40
  473. package/build-module/components/block-list/use-block-props/use-block-custom-class-name.js.map +0 -1
  474. package/build-module/components/block-list/use-block-props/use-block-default-class-name.js +0 -31
  475. package/build-module/components/block-list/use-block-props/use-block-default-class-name.js.map +0 -1
  476. package/build-module/components/block-tools/back-compat.js +0 -35
  477. package/build-module/components/block-tools/back-compat.js.map +0 -1
  478. package/build-module/components/block-tools/block-contextual-toolbar.js +0 -83
  479. package/build-module/components/block-tools/block-contextual-toolbar.js.map +0 -1
  480. package/build-module/components/block-tools/selected-block-tools.js +0 -105
  481. package/build-module/components/block-tools/selected-block-tools.js.map +0 -1
  482. package/build-module/components/inserter/hooks/use-debounced-input.js +0 -15
  483. package/build-module/components/inserter/hooks/use-debounced-input.js.map +0 -1
  484. package/build-module/components/use-display-block-controls/index.js +0 -32
  485. package/build-module/components/use-display-block-controls/index.js.map +0 -1
  486. package/build-module/components/use-display-block-controls/index.native.js +0 -32
  487. package/build-module/components/use-display-block-controls/index.native.js.map +0 -1
  488. package/src/components/block-list/use-block-props/use-block-class-names.js +0 -66
  489. package/src/components/block-list/use-block-props/use-block-custom-class-name.js +0 -44
  490. package/src/components/block-list/use-block-props/use-block-default-class-name.js +0 -35
  491. package/src/components/block-parent-selector/style.scss +0 -11
  492. package/src/components/block-tools/back-compat.js +0 -35
  493. package/src/components/block-tools/block-contextual-toolbar.js +0 -100
  494. package/src/components/block-tools/selected-block-tools.js +0 -127
  495. package/src/components/inserter/hooks/use-debounced-input.js +0 -18
  496. package/src/components/preview-options/README.md +0 -94
  497. package/src/components/preview-options/style.scss +0 -64
  498. package/src/components/use-display-block-controls/index.js +0 -36
  499. package/src/components/use-display-block-controls/index.native.js +0 -37
  500. package/src/hooks/test/color.js +0 -112
@@ -2,17 +2,28 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { getBlockSupport } from '@wordpress/blocks';
5
- import { useMemo, useEffect, useId } from '@wordpress/element';
5
+ import { useMemo, useEffect, useId, useState } from '@wordpress/element';
6
6
  import { useDispatch } from '@wordpress/data';
7
+ import { createHigherOrderComponent, pure } from '@wordpress/compose';
8
+ import { addFilter } from '@wordpress/hooks';
7
9
 
8
10
  /**
9
11
  * Internal dependencies
10
12
  */
13
+ import {
14
+ useBlockEditContext,
15
+ mayDisplayControlsKey,
16
+ mayDisplayParentControlsKey,
17
+ } from '../components/block-edit/context';
11
18
  import { useSettings } from '../components';
12
19
  import { useSettingsForBlockElement } from '../components/global-styles/hooks';
13
20
  import { getValueFromObjectPath, setImmutably } from '../utils/object';
14
21
  import { store as blockEditorStore } from '../store';
15
22
  import { unlock } from '../lock-unlock';
23
+ /**
24
+ * External dependencies
25
+ */
26
+ import classnames from 'classnames';
16
27
 
17
28
  /**
18
29
  * Removed falsy values from nested object.
@@ -101,14 +112,18 @@ export function transformStyles(
101
112
  * Check whether serialization of specific block support feature or set should
102
113
  * be skipped.
103
114
  *
104
- * @param {string|Object} blockType Block name or block type object.
105
- * @param {string} featureSet Name of block support feature set.
106
- * @param {string} feature Name of the individual feature to check.
115
+ * @param {string|Object} blockNameOrType Block name or block type object.
116
+ * @param {string} featureSet Name of block support feature set.
117
+ * @param {string} feature Name of the individual feature to check.
107
118
  *
108
119
  * @return {boolean} Whether serialization should occur.
109
120
  */
110
- export function shouldSkipSerialization( blockType, featureSet, feature ) {
111
- const support = getBlockSupport( blockType, featureSet );
121
+ export function shouldSkipSerialization(
122
+ blockNameOrType,
123
+ featureSet,
124
+ feature
125
+ ) {
126
+ const support = getBlockSupport( blockNameOrType, featureSet );
112
127
  const skipSerialization = support?.__experimentalSkipSerialization;
113
128
 
114
129
  if ( Array.isArray( skipSerialization ) ) {
@@ -362,3 +377,169 @@ export function useBlockSettings( name, parentLayout ) {
362
377
 
363
378
  return useSettingsForBlockElement( rawSettings, name );
364
379
  }
380
+
381
+ export function createBlockEditFilter( features ) {
382
+ // We don't want block controls to re-render when typing inside a block.
383
+ // `pure` will prevent re-renders unless props change, so only pass the
384
+ // needed props and not the whole attributes object.
385
+ features = features.map( ( settings ) => {
386
+ return { ...settings, Edit: pure( settings.edit ) };
387
+ } );
388
+ const withBlockEditHooks = createHigherOrderComponent(
389
+ ( OriginalBlockEdit ) => ( props ) => {
390
+ const context = useBlockEditContext();
391
+ // CAUTION: code added before this line will be executed for all
392
+ // blocks, not just those that support the feature! Code added
393
+ // above this line should be carefully evaluated for its impact on
394
+ // performance.
395
+ return [
396
+ ...features.map( ( feature, i ) => {
397
+ const {
398
+ Edit,
399
+ hasSupport,
400
+ attributeKeys = [],
401
+ shareWithChildBlocks,
402
+ } = feature;
403
+ const shouldDisplayControls =
404
+ context[ mayDisplayControlsKey ] ||
405
+ ( context[ mayDisplayParentControlsKey ] &&
406
+ shareWithChildBlocks );
407
+
408
+ if (
409
+ ! shouldDisplayControls ||
410
+ ! hasSupport( props.name )
411
+ ) {
412
+ return null;
413
+ }
414
+
415
+ const neededProps = {};
416
+ for ( const key of attributeKeys ) {
417
+ if ( props.attributes[ key ] ) {
418
+ neededProps[ key ] = props.attributes[ key ];
419
+ }
420
+ }
421
+ return (
422
+ <Edit
423
+ // We can use the index because the array length
424
+ // is fixed per page load right now.
425
+ key={ i }
426
+ name={ props.name }
427
+ clientId={ props.clientId }
428
+ setAttributes={ props.setAttributes }
429
+ __unstableParentLayout={
430
+ props.__unstableParentLayout
431
+ }
432
+ // This component is pure, so only pass needed
433
+ // props!!!
434
+ { ...neededProps }
435
+ />
436
+ );
437
+ } ),
438
+ <OriginalBlockEdit key="edit" { ...props } />,
439
+ ];
440
+ },
441
+ 'withBlockEditHooks'
442
+ );
443
+ addFilter( 'editor.BlockEdit', 'core/editor/hooks', withBlockEditHooks );
444
+ }
445
+
446
+ function BlockProps( { index, useBlockProps, setAllWrapperProps, ...props } ) {
447
+ const wrapperProps = useBlockProps( props );
448
+ const setWrapperProps = ( next ) =>
449
+ setAllWrapperProps( ( prev ) => {
450
+ const nextAll = [ ...prev ];
451
+ nextAll[ index ] = next;
452
+ return nextAll;
453
+ } );
454
+ // Setting state after every render is fine because this component is
455
+ // pure and will only re-render when needed props change.
456
+ useEffect( () => {
457
+ // We could shallow compare the props, but since this component only
458
+ // changes when needed attributes change, the benefit is probably small.
459
+ setWrapperProps( wrapperProps );
460
+ return () => {
461
+ setWrapperProps( undefined );
462
+ };
463
+ } );
464
+ return null;
465
+ }
466
+
467
+ const BlockPropsPure = pure( BlockProps );
468
+
469
+ export function createBlockListBlockFilter( features ) {
470
+ const withBlockListBlockHooks = createHigherOrderComponent(
471
+ ( BlockListBlock ) => ( props ) => {
472
+ const [ allWrapperProps, setAllWrapperProps ] = useState(
473
+ Array( features.length ).fill( undefined )
474
+ );
475
+ return [
476
+ ...features.map( ( feature, i ) => {
477
+ const {
478
+ hasSupport,
479
+ attributeKeys = [],
480
+ useBlockProps,
481
+ } = feature;
482
+
483
+ const neededProps = {};
484
+ for ( const key of attributeKeys ) {
485
+ if ( props.attributes[ key ] ) {
486
+ neededProps[ key ] = props.attributes[ key ];
487
+ }
488
+ }
489
+
490
+ if (
491
+ ! hasSupport( props.name ) ||
492
+ // Skip rendering if none of the needed attributes are
493
+ // set.
494
+ ! Object.keys( neededProps ).length
495
+ ) {
496
+ return null;
497
+ }
498
+
499
+ return (
500
+ <BlockPropsPure
501
+ // We can use the index because the array length
502
+ // is fixed per page load right now.
503
+ key={ i }
504
+ index={ i }
505
+ useBlockProps={ useBlockProps }
506
+ // This component is pure, so we must pass a stable
507
+ // function reference.
508
+ setAllWrapperProps={ setAllWrapperProps }
509
+ name={ props.name }
510
+ // This component is pure, so only pass needed
511
+ // props!!!
512
+ { ...neededProps }
513
+ />
514
+ );
515
+ } ),
516
+ <BlockListBlock
517
+ key="edit"
518
+ { ...props }
519
+ wrapperProps={ allWrapperProps
520
+ .filter( Boolean )
521
+ .reduce( ( acc, wrapperProps ) => {
522
+ return {
523
+ ...acc,
524
+ ...wrapperProps,
525
+ className: classnames(
526
+ acc.className,
527
+ wrapperProps.className
528
+ ),
529
+ style: {
530
+ ...acc.style,
531
+ ...wrapperProps.style,
532
+ },
533
+ };
534
+ }, props.wrapperProps || {} ) }
535
+ />,
536
+ ];
537
+ },
538
+ 'withBlockListBlockHooks'
539
+ );
540
+ addFilter(
541
+ 'editor.BlockListBlock',
542
+ 'core/editor/hooks',
543
+ withBlockListBlockHooks
544
+ );
545
+ }
@@ -10,7 +10,6 @@ import ResizableBoxPopover from './components/resizable-box-popover';
10
10
  import { ComposedPrivateInserter as PrivateInserter } from './components/inserter';
11
11
  import { PrivateListView } from './components/list-view';
12
12
  import BlockInfo from './components/block-info-slot-fill';
13
- import BlockContextualToolbar from './components/block-tools/block-contextual-toolbar';
14
13
  import { useShouldContextualToolbarShow } from './utils/use-should-contextual-toolbar-show';
15
14
  import { cleanEmptyObject, useStyleOverride } from './hooks/utils';
16
15
  import BlockQuickNavigation from './components/block-quick-navigation';
@@ -42,7 +41,6 @@ lock( privateApis, {
42
41
  PrivateListView,
43
42
  ResizableBoxPopover,
44
43
  BlockInfo,
45
- BlockContextualToolbar,
46
44
  useShouldContextualToolbarShow,
47
45
  cleanEmptyObject,
48
46
  useStyleOverride,
@@ -290,3 +290,11 @@ export function deleteStyleOverride( id ) {
290
290
  id,
291
291
  };
292
292
  }
293
+
294
+ export function syncDerivedBlockAttributes( clientId, attributes ) {
295
+ return {
296
+ type: 'SYNC_DERIVED_BLOCK_ATTRIBUTES',
297
+ clientIds: [ clientId ],
298
+ attributes,
299
+ };
300
+ }
@@ -10,7 +10,12 @@ import {
10
10
  getBlockOrder,
11
11
  getBlockParents,
12
12
  getBlockEditingMode,
13
+ getSettings,
14
+ __experimentalGetParsedPattern,
15
+ canInsertBlockType,
16
+ __experimentalGetAllowedPatterns,
13
17
  } from './selectors';
18
+ import { getUserPatterns, checkAllowListRecursive } from './utils';
14
19
 
15
20
  /**
16
21
  * Returns true if the block interface is hidden, or false otherwise.
@@ -236,3 +241,43 @@ export const getInserterMediaCategories = createSelector(
236
241
  state.registeredInserterMediaCategories,
237
242
  ]
238
243
  );
244
+
245
+ /**
246
+ * Returns whether there is at least one allowed pattern for inner blocks children.
247
+ * This is useful for deferring the parsing of all patterns until needed.
248
+ *
249
+ * @param {Object} state Editor state.
250
+ * @param {string} [rootClientId=null] Target root client ID.
251
+ *
252
+ * @return {boolean} If there is at least one allowed pattern.
253
+ */
254
+ export const hasAllowedPatterns = createSelector(
255
+ ( state, rootClientId = null ) => {
256
+ const patterns = state.settings.__experimentalBlockPatterns;
257
+ const userPatterns = getUserPatterns( state );
258
+ const { allowedBlockTypes } = getSettings( state );
259
+ return [ ...userPatterns, ...patterns ].some(
260
+ ( { name, inserter = true } ) => {
261
+ if ( ! inserter ) {
262
+ return false;
263
+ }
264
+ const { blocks } = __experimentalGetParsedPattern(
265
+ state,
266
+ name
267
+ );
268
+ return (
269
+ checkAllowListRecursive( blocks, allowedBlockTypes ) &&
270
+ blocks.every( ( { name: blockName } ) =>
271
+ canInsertBlockType( state, blockName, rootClientId )
272
+ )
273
+ );
274
+ }
275
+ );
276
+ },
277
+ ( state, rootClientId ) => [
278
+ ...__experimentalGetAllowedPatterns.getDependants(
279
+ state,
280
+ rootClientId
281
+ ),
282
+ ]
283
+ );
@@ -283,6 +283,7 @@ const withBlockTree =
283
283
  false
284
284
  );
285
285
  break;
286
+ case 'SYNC_DERIVED_BLOCK_ATTRIBUTES':
286
287
  case 'UPDATE_BLOCK_ATTRIBUTES': {
287
288
  newState.tree = new Map( newState.tree );
288
289
  action.clientIds.forEach( ( clientId ) => {
@@ -456,6 +457,12 @@ function withPersistentBlockChange( reducer ) {
456
457
  return ( state, action ) => {
457
458
  let nextState = reducer( state, action );
458
459
 
460
+ if ( action.type === 'SYNC_DERIVED_BLOCK_ATTRIBUTES' ) {
461
+ return nextState.isPersistentChange
462
+ ? { ...nextState, isPersistentChange: false }
463
+ : nextState;
464
+ }
465
+
459
466
  const isExplicitPersistentChange =
460
467
  action.type === 'MARK_LAST_CHANGE_AS_PERSISTENT' ||
461
468
  markNextChangeAsNotPersistent;
@@ -860,6 +867,7 @@ export const blocks = pipe(
860
867
  return newState;
861
868
  }
862
869
 
870
+ case 'SYNC_DERIVED_BLOCK_ATTRIBUTES':
863
871
  case 'UPDATE_BLOCK_ATTRIBUTES': {
864
872
  // Avoid a state change if none of the block IDs are known.
865
873
  if ( action.clientIds.every( ( id ) => ! state.get( id ) ) ) {
@@ -26,8 +26,12 @@ import { createRegistrySelector } from '@wordpress/data';
26
26
  /**
27
27
  * Internal dependencies
28
28
  */
29
+ import {
30
+ getUserPatterns,
31
+ checkAllowListRecursive,
32
+ checkAllowList,
33
+ } from './utils';
29
34
  import { orderBy } from '../utils/sorting';
30
- import { PATTERN_TYPES } from '../components/inserter/block-patterns-tab/utils';
31
35
 
32
36
  /**
33
37
  * A block selection object.
@@ -1481,22 +1485,6 @@ export function getTemplateLock( state, rootClientId ) {
1481
1485
  return getBlockListSettings( state, rootClientId )?.templateLock ?? false;
1482
1486
  }
1483
1487
 
1484
- const checkAllowList = ( list, item, defaultResult = null ) => {
1485
- if ( typeof list === 'boolean' ) {
1486
- return list;
1487
- }
1488
- if ( Array.isArray( list ) ) {
1489
- // TODO: when there is a canonical way to detect that we are editing a post
1490
- // the following check should be changed to something like:
1491
- // if ( list.includes( 'core/post-content' ) && getEditorMode() === 'post-content' && item === null )
1492
- if ( list.includes( 'core/post-content' ) && item === null ) {
1493
- return true;
1494
- }
1495
- return list.includes( item );
1496
- }
1497
- return defaultResult;
1498
- };
1499
-
1500
1488
  /**
1501
1489
  * Determines if the given block type is allowed to be inserted into the block list.
1502
1490
  * This function is not exported and not memoized because using a memoized selector
@@ -2249,58 +2237,6 @@ export const __experimentalGetDirectInsertBlock = createSelector(
2249
2237
  ]
2250
2238
  );
2251
2239
 
2252
- const checkAllowListRecursive = ( blocks, allowedBlockTypes ) => {
2253
- if ( typeof allowedBlockTypes === 'boolean' ) {
2254
- return allowedBlockTypes;
2255
- }
2256
-
2257
- const blocksQueue = [ ...blocks ];
2258
- while ( blocksQueue.length > 0 ) {
2259
- const block = blocksQueue.shift();
2260
-
2261
- const isAllowed = checkAllowList(
2262
- allowedBlockTypes,
2263
- block.name || block.blockName,
2264
- true
2265
- );
2266
- if ( ! isAllowed ) {
2267
- return false;
2268
- }
2269
-
2270
- block.innerBlocks?.forEach( ( innerBlock ) => {
2271
- blocksQueue.push( innerBlock );
2272
- } );
2273
- }
2274
-
2275
- return true;
2276
- };
2277
-
2278
- function getUserPatterns( state ) {
2279
- const userPatterns =
2280
- state?.settings?.__experimentalReusableBlocks ?? EMPTY_ARRAY;
2281
- const userPatternCategories =
2282
- state?.settings?.__experimentalUserPatternCategories ?? [];
2283
- const categories = new Map();
2284
- userPatternCategories.forEach( ( userCategory ) =>
2285
- categories.set( userCategory.id, userCategory )
2286
- );
2287
- return userPatterns.map( ( userPattern ) => {
2288
- return {
2289
- name: `core/block/${ userPattern.id }`,
2290
- id: userPattern.id,
2291
- type: PATTERN_TYPES.user,
2292
- title: userPattern.title.raw,
2293
- categories: userPattern.wp_pattern_category.map( ( catId ) =>
2294
- categories && categories.get( catId )
2295
- ? categories.get( catId ).slug
2296
- : catId
2297
- ),
2298
- content: userPattern.content.raw,
2299
- syncStatus: userPattern.wp_pattern_sync_status,
2300
- };
2301
- } );
2302
- }
2303
-
2304
2240
  export const __experimentalUserPatternCategories = createSelector(
2305
2241
  ( state ) => {
2306
2242
  return state?.settings?.__experimentalUserPatternCategories;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { PATTERN_TYPES } from '../components/inserter/block-patterns-tab/utils';
5
+
6
+ const EMPTY_ARRAY = [];
7
+
8
+ export function getUserPatterns( state ) {
9
+ const userPatterns =
10
+ state?.settings?.__experimentalReusableBlocks ?? EMPTY_ARRAY;
11
+ const userPatternCategories =
12
+ state?.settings?.__experimentalUserPatternCategories ?? [];
13
+ const categories = new Map();
14
+ userPatternCategories.forEach( ( userCategory ) =>
15
+ categories.set( userCategory.id, userCategory )
16
+ );
17
+ return userPatterns.map( ( userPattern ) => {
18
+ return {
19
+ name: `core/block/${ userPattern.id }`,
20
+ id: userPattern.id,
21
+ type: PATTERN_TYPES.user,
22
+ title: userPattern.title.raw,
23
+ categories: userPattern.wp_pattern_category.map( ( catId ) =>
24
+ categories && categories.get( catId )
25
+ ? categories.get( catId ).slug
26
+ : catId
27
+ ),
28
+ content: userPattern.content.raw,
29
+ syncStatus: userPattern.wp_pattern_sync_status,
30
+ };
31
+ } );
32
+ }
33
+
34
+ export const checkAllowList = ( list, item, defaultResult = null ) => {
35
+ if ( typeof list === 'boolean' ) {
36
+ return list;
37
+ }
38
+ if ( Array.isArray( list ) ) {
39
+ // TODO: when there is a canonical way to detect that we are editing a post
40
+ // the following check should be changed to something like:
41
+ // if ( list.includes( 'core/post-content' ) && getEditorMode() === 'post-content' && item === null )
42
+ if ( list.includes( 'core/post-content' ) && item === null ) {
43
+ return true;
44
+ }
45
+ return list.includes( item );
46
+ }
47
+ return defaultResult;
48
+ };
49
+
50
+ export const checkAllowListRecursive = ( blocks, allowedBlockTypes ) => {
51
+ if ( typeof allowedBlockTypes === 'boolean' ) {
52
+ return allowedBlockTypes;
53
+ }
54
+
55
+ const blocksQueue = [ ...blocks ];
56
+ while ( blocksQueue.length > 0 ) {
57
+ const block = blocksQueue.shift();
58
+
59
+ const isAllowed = checkAllowList(
60
+ allowedBlockTypes,
61
+ block.name || block.blockName,
62
+ true
63
+ );
64
+ if ( ! isAllowed ) {
65
+ return false;
66
+ }
67
+
68
+ block.innerBlocks?.forEach( ( innerBlock ) => {
69
+ blocksQueue.push( innerBlock );
70
+ } );
71
+ }
72
+
73
+ return true;
74
+ };
package/src/style.scss CHANGED
@@ -10,7 +10,6 @@
10
10
  @import "./components/block-draggable/style.scss";
11
11
  @import "./components/block-mover/style.scss";
12
12
  @import "./components/block-navigation/style.scss";
13
- @import "./components/block-parent-selector/style.scss";
14
13
  @import "./components/block-patterns-list/style.scss";
15
14
  @import "./components/block-patterns-paging/style.scss";
16
15
  @import "./components/block-popover/style.scss";
@@ -60,7 +59,6 @@
60
59
 
61
60
  @import "./components/block-toolbar/style.scss";
62
61
  @import "./components/inserter/style.scss";
63
- @import "./components/preview-options/style.scss";
64
62
  @import "./components/spacing-sizes-control/style.scss";
65
63
 
66
64
  @include wordpress-admin-schemes();
@@ -2,28 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { paramCase } from 'change-case';
5
- import memoize from 'memize';
6
-
7
- /**
8
- * Converts a path to an array of its fragments.
9
- * Supports strings, numbers and arrays:
10
- *
11
- * 'foo' => [ 'foo' ]
12
- * 2 => [ '2' ]
13
- * [ 'foo', 'bar' ] => [ 'foo', 'bar' ]
14
- *
15
- * @param {string|number|Array} path Path
16
- * @return {Array} Normalized path.
17
- */
18
- function normalizePath( path ) {
19
- if ( Array.isArray( path ) ) {
20
- return path;
21
- } else if ( typeof path === 'number' ) {
22
- return [ path.toString() ];
23
- }
24
-
25
- return [ path ];
26
- }
27
5
 
28
6
  /**
29
7
  * Converts any string to kebab case.
@@ -55,33 +33,6 @@ export function kebabCase( str ) {
55
33
  } );
56
34
  }
57
35
 
58
- /**
59
- * Clones an object.
60
- * Arrays are also cloned as arrays.
61
- * Non-object values are returned unchanged.
62
- *
63
- * @param {*} object Object to clone.
64
- * @return {*} Cloned object, or original literal non-object value.
65
- */
66
- function cloneObject( object ) {
67
- if ( Array.isArray( object ) ) {
68
- return object.map( cloneObject );
69
- }
70
-
71
- if ( object && typeof object === 'object' ) {
72
- return {
73
- ...Object.fromEntries(
74
- Object.entries( object ).map( ( [ key, value ] ) => [
75
- key,
76
- cloneObject( value ),
77
- ] )
78
- ),
79
- };
80
- }
81
-
82
- return object;
83
- }
84
-
85
36
  /**
86
37
  * Immutably sets a value inside an object. Like `lodash#set`, but returning a
87
38
  * new object. Treats nullish initial values as empty objects. Clones any
@@ -93,27 +44,25 @@ function cloneObject( object ) {
93
44
  * @return {Object} Cloned object with the new value set.
94
45
  */
95
46
  export function setImmutably( object, path, value ) {
96
- const normalizedPath = normalizePath( path );
97
- const newObject = object ? cloneObject( object ) : {};
47
+ // Normalize path
48
+ path = Array.isArray( path ) ? [ ...path ] : [ path ];
98
49
 
99
- normalizedPath.reduce( ( acc, key, i ) => {
100
- if ( acc[ key ] === undefined ) {
101
- if ( Number.isInteger( path[ i + 1 ] ) ) {
102
- acc[ key ] = [];
103
- } else {
104
- acc[ key ] = {};
105
- }
106
- }
107
- if ( i === normalizedPath.length - 1 ) {
108
- acc[ key ] = value;
109
- }
110
- return acc[ key ];
111
- }, newObject );
50
+ // Shallowly clone the base of the object
51
+ object = Array.isArray( object ) ? [ ...object ] : { ...object };
112
52
 
113
- return newObject;
114
- }
53
+ const leaf = path.pop();
54
+
55
+ // Traverse object from root to leaf, shallowly cloning at each level
56
+ let prev = object;
57
+ for ( const key of path ) {
58
+ const lvl = prev[ key ];
59
+ prev = prev[ key ] = Array.isArray( lvl ) ? [ ...lvl ] : { ...lvl };
60
+ }
115
61
 
116
- const stringToPath = memoize( ( path ) => path.split( '.' ) );
62
+ prev[ leaf ] = value;
63
+
64
+ return object;
65
+ }
117
66
 
118
67
  /**
119
68
  * Helper util to return a value from a certain path of the object.
@@ -128,9 +77,9 @@ const stringToPath = memoize( ( path ) => path.split( '.' ) );
128
77
  * @return {*} Value of the object property at the specified path.
129
78
  */
130
79
  export const getValueFromObjectPath = ( object, path, defaultValue ) => {
131
- const normalizedPath = Array.isArray( path ) ? path : stringToPath( path );
80
+ const arrayPath = Array.isArray( path ) ? path : path.split( '.' );
132
81
  let value = object;
133
- normalizedPath.forEach( ( fieldName ) => {
82
+ arrayPath.forEach( ( fieldName ) => {
134
83
  value = value?.[ fieldName ];
135
84
  } );
136
85
  return value ?? defaultValue;
@@ -1,3 +1,8 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { RichTextData } from '@wordpress/rich-text';
5
+
1
6
  /**
2
7
  * A robust way to retain selection position through various
3
8
  * transforms is to insert a special character at the position and
@@ -19,8 +24,10 @@ export function retrieveSelectedAttribute( blockAttributes ) {
19
24
  return Object.keys( blockAttributes ).find( ( name ) => {
20
25
  const value = blockAttributes[ name ];
21
26
  return (
22
- typeof value === 'string' &&
23
- value.indexOf( START_OF_SELECTED_AREA ) !== -1
27
+ ( typeof value === 'string' || value instanceof RichTextData ) &&
28
+ // To do: refactor this to use rich text's selection instead, so we
29
+ // no longer have to use on this hack inserting a special character.
30
+ value.toString().indexOf( START_OF_SELECTED_AREA ) !== -1
24
31
  );
25
32
  } );
26
33
  }