@wordpress/block-editor 12.16.1-next.79a6196f.0 → 12.18.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 (376) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +32 -0
  3. package/build/components/block-draggable/index.js +11 -3
  4. package/build/components/block-draggable/index.js.map +1 -1
  5. package/build/components/block-edit/context.js +3 -1
  6. package/build/components/block-edit/context.js.map +1 -1
  7. package/build/components/block-edit/index.js +4 -2
  8. package/build/components/block-edit/index.js.map +1 -1
  9. package/build/components/block-editing-mode/index.js +6 -3
  10. package/build/components/block-editing-mode/index.js.map +1 -1
  11. package/build/components/block-inspector/index.js +5 -2
  12. package/build/components/block-inspector/index.js.map +1 -1
  13. package/build/components/block-list/block.js +4 -3
  14. package/build/components/block-list/block.js.map +1 -1
  15. package/build/components/block-list/block.native.js +9 -5
  16. package/build/components/block-list/block.native.js.map +1 -1
  17. package/build/components/block-list/index.js +30 -4
  18. package/build/components/block-list/index.js.map +1 -1
  19. package/build/components/block-list/private-block-context.js +1 -1
  20. package/build/components/block-list/private-block-context.js.map +1 -1
  21. package/build/components/block-list/use-in-between-inserter.js +1 -1
  22. package/build/components/block-list/use-in-between-inserter.js.map +1 -1
  23. package/build/components/block-popover/inbetween.js +15 -3
  24. package/build/components/block-popover/inbetween.js.map +1 -1
  25. package/build/components/block-preview/auto.js +1 -1
  26. package/build/components/block-preview/auto.js.map +1 -1
  27. package/build/components/block-removal-warning-modal/index.js +3 -2
  28. package/build/components/block-removal-warning-modal/index.js.map +1 -1
  29. package/build/components/block-settings-menu/block-settings-dropdown.js +2 -4
  30. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  31. package/build/components/block-switcher/block-transformations-menu.js +12 -1
  32. package/build/components/block-switcher/block-transformations-menu.js.map +1 -1
  33. package/build/components/block-switcher/index.js +119 -90
  34. package/build/components/block-switcher/index.js.map +1 -1
  35. package/build/components/block-tools/insertion-point.js +10 -3
  36. package/build/components/block-tools/insertion-point.js.map +1 -1
  37. package/build/components/font-sizes/fluid-utils.js +7 -1
  38. package/build/components/font-sizes/fluid-utils.js.map +1 -1
  39. package/build/components/global-styles/border-panel.js +5 -14
  40. package/build/components/global-styles/border-panel.js.map +1 -1
  41. package/build/components/global-styles/effects-panel.js +7 -1
  42. package/build/components/global-styles/effects-panel.js.map +1 -1
  43. package/build/components/iframe/get-compatibility-styles.js +99 -0
  44. package/build/components/iframe/get-compatibility-styles.js.map +1 -0
  45. package/build/components/iframe/index.js +2 -3
  46. package/build/components/iframe/index.js.map +1 -1
  47. package/build/components/index.js +16 -2
  48. package/build/components/index.js.map +1 -1
  49. package/build/components/index.native.js +16 -2
  50. package/build/components/index.native.js.map +1 -1
  51. package/build/components/inspector-controls/groups.js +2 -0
  52. package/build/components/inspector-controls/groups.js.map +1 -1
  53. package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
  54. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  55. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
  56. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  57. package/build/components/link-control/link-preview.js +30 -26
  58. package/build/components/link-control/link-preview.js.map +1 -1
  59. package/build/components/link-control/search-input.js +1 -9
  60. package/build/components/link-control/search-input.js.map +1 -1
  61. package/build/components/list-view/block-contents.js +3 -1
  62. package/build/components/list-view/block-contents.js.map +1 -1
  63. package/build/components/list-view/block.js +10 -1
  64. package/build/components/list-view/block.js.map +1 -1
  65. package/build/components/list-view/branch.js +29 -8
  66. package/build/components/list-view/branch.js.map +1 -1
  67. package/build/components/list-view/drop-indicator.js +100 -32
  68. package/build/components/list-view/drop-indicator.js.map +1 -1
  69. package/build/components/list-view/index.js +52 -4
  70. package/build/components/list-view/index.js.map +1 -1
  71. package/build/components/list-view/leaf.js +2 -2
  72. package/build/components/list-view/leaf.js.map +1 -1
  73. package/build/components/list-view/use-list-view-block-indexes.js +30 -0
  74. package/build/components/list-view/use-list-view-block-indexes.js.map +1 -0
  75. package/build/components/list-view/use-list-view-drop-zone.js +56 -5
  76. package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
  77. package/build/components/list-view/utils.js +92 -0
  78. package/build/components/list-view/utils.js.map +1 -1
  79. package/build/components/provider/index.js +1 -1
  80. package/build/components/provider/index.js.map +1 -1
  81. package/build/components/recursion-provider/index.js +21 -0
  82. package/build/components/recursion-provider/index.js.map +1 -1
  83. package/build/components/rich-text/index.js +30 -6
  84. package/build/components/rich-text/index.js.map +1 -1
  85. package/build/components/rich-text/native/index.native.js +9 -9
  86. package/build/components/rich-text/native/index.native.js.map +1 -1
  87. package/build/components/use-block-drop-zone/index.js +30 -7
  88. package/build/components/use-block-drop-zone/index.js.map +1 -1
  89. package/build/components/use-on-block-drop/index.js +50 -8
  90. package/build/components/use-on-block-drop/index.js.map +1 -1
  91. package/build/hooks/block-hooks.js +5 -14
  92. package/build/hooks/block-hooks.js.map +1 -1
  93. package/build/hooks/content-lock-ui.js +17 -42
  94. package/build/hooks/content-lock-ui.js.map +1 -1
  95. package/build/hooks/effects.js +66 -0
  96. package/build/hooks/effects.js.map +1 -0
  97. package/build/hooks/index.js +14 -0
  98. package/build/hooks/index.js.map +1 -1
  99. package/build/hooks/index.native.js +13 -0
  100. package/build/hooks/index.native.js.map +1 -1
  101. package/build/hooks/style.js +6 -2
  102. package/build/hooks/style.js.map +1 -1
  103. package/build/hooks/supports.js +2 -1
  104. package/build/hooks/supports.js.map +1 -1
  105. package/build/hooks/typography.native.js +2 -2
  106. package/build/hooks/typography.native.js.map +1 -1
  107. package/build/hooks/use-bindings-attributes.js +115 -0
  108. package/build/hooks/use-bindings-attributes.js.map +1 -0
  109. package/build/hooks/use-shadow-props.js +46 -0
  110. package/build/hooks/use-shadow-props.js.map +1 -0
  111. package/build/hooks/utils.js +7 -6
  112. package/build/hooks/utils.js.map +1 -1
  113. package/build/index.js +14 -0
  114. package/build/index.js.map +1 -1
  115. package/build/store/actions.js +10 -6
  116. package/build/store/actions.js.map +1 -1
  117. package/build/store/index.js +2 -0
  118. package/build/store/index.js.map +1 -1
  119. package/build/store/private-actions.js +37 -0
  120. package/build/store/private-actions.js.map +1 -1
  121. package/build/store/private-selectors.js +60 -9
  122. package/build/store/private-selectors.js.map +1 -1
  123. package/build/store/reducer.js +44 -3
  124. package/build/store/reducer.js.map +1 -1
  125. package/build/store/resolvers.js +27 -0
  126. package/build/store/resolvers.js.map +1 -0
  127. package/build/store/selectors.js +94 -56
  128. package/build/store/selectors.js.map +1 -1
  129. package/build/store/utils.js +5 -26
  130. package/build/store/utils.js.map +1 -1
  131. package/build/utils/index.js +0 -16
  132. package/build/utils/index.js.map +1 -1
  133. package/build/utils/math.js +13 -0
  134. package/build/utils/math.js.map +1 -1
  135. package/build/utils/transform-styles/index.js +37 -27
  136. package/build/utils/transform-styles/index.js.map +1 -1
  137. package/build-module/components/block-draggable/index.js +11 -3
  138. package/build-module/components/block-draggable/index.js.map +1 -1
  139. package/build-module/components/block-edit/context.js +1 -0
  140. package/build-module/components/block-edit/context.js.map +1 -1
  141. package/build-module/components/block-edit/index.js +5 -3
  142. package/build-module/components/block-edit/index.js.map +1 -1
  143. package/build-module/components/block-editing-mode/index.js +7 -4
  144. package/build-module/components/block-editing-mode/index.js.map +1 -1
  145. package/build-module/components/block-inspector/index.js +5 -2
  146. package/build-module/components/block-inspector/index.js.map +1 -1
  147. package/build-module/components/block-list/block.js +6 -5
  148. package/build-module/components/block-list/block.js.map +1 -1
  149. package/build-module/components/block-list/block.native.js +11 -7
  150. package/build-module/components/block-list/block.native.js.map +1 -1
  151. package/build-module/components/block-list/index.js +31 -5
  152. package/build-module/components/block-list/index.js.map +1 -1
  153. package/build-module/components/block-list/private-block-context.js +1 -1
  154. package/build-module/components/block-list/private-block-context.js.map +1 -1
  155. package/build-module/components/block-list/use-in-between-inserter.js +1 -1
  156. package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
  157. package/build-module/components/block-popover/inbetween.js +15 -3
  158. package/build-module/components/block-popover/inbetween.js.map +1 -1
  159. package/build-module/components/block-preview/auto.js +3 -3
  160. package/build-module/components/block-preview/auto.js.map +1 -1
  161. package/build-module/components/block-removal-warning-modal/index.js +3 -2
  162. package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
  163. package/build-module/components/block-settings-menu/block-settings-dropdown.js +2 -4
  164. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  165. package/build-module/components/block-switcher/block-transformations-menu.js +12 -1
  166. package/build-module/components/block-switcher/block-transformations-menu.js.map +1 -1
  167. package/build-module/components/block-switcher/index.js +116 -86
  168. package/build-module/components/block-switcher/index.js.map +1 -1
  169. package/build-module/components/block-tools/insertion-point.js +10 -3
  170. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  171. package/build-module/components/font-sizes/fluid-utils.js +7 -1
  172. package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
  173. package/build-module/components/global-styles/border-panel.js +5 -14
  174. package/build-module/components/global-styles/border-panel.js.map +1 -1
  175. package/build-module/components/global-styles/effects-panel.js +7 -1
  176. package/build-module/components/global-styles/effects-panel.js.map +1 -1
  177. package/build-module/components/iframe/get-compatibility-styles.js +93 -0
  178. package/build-module/components/iframe/get-compatibility-styles.js.map +1 -0
  179. package/build-module/components/iframe/index.js +2 -3
  180. package/build-module/components/iframe/index.js.map +1 -1
  181. package/build-module/components/index.js +1 -1
  182. package/build-module/components/index.js.map +1 -1
  183. package/build-module/components/index.native.js +1 -1
  184. package/build-module/components/index.native.js.map +1 -1
  185. package/build-module/components/inspector-controls/groups.js +2 -0
  186. package/build-module/components/inspector-controls/groups.js.map +1 -1
  187. package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
  188. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  189. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +3 -2
  190. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +1 -1
  191. package/build-module/components/link-control/link-preview.js +32 -28
  192. package/build-module/components/link-control/link-preview.js.map +1 -1
  193. package/build-module/components/link-control/search-input.js +1 -8
  194. package/build-module/components/link-control/search-input.js.map +1 -1
  195. package/build-module/components/list-view/block-contents.js +3 -1
  196. package/build-module/components/list-view/block-contents.js.map +1 -1
  197. package/build-module/components/list-view/block.js +10 -1
  198. package/build-module/components/list-view/block.js.map +1 -1
  199. package/build-module/components/list-view/branch.js +30 -9
  200. package/build-module/components/list-view/branch.js.map +1 -1
  201. package/build-module/components/list-view/drop-indicator.js +99 -32
  202. package/build-module/components/list-view/drop-indicator.js.map +1 -1
  203. package/build-module/components/list-view/index.js +54 -6
  204. package/build-module/components/list-view/index.js.map +1 -1
  205. package/build-module/components/list-view/leaf.js +2 -2
  206. package/build-module/components/list-view/leaf.js.map +1 -1
  207. package/build-module/components/list-view/use-list-view-block-indexes.js +23 -0
  208. package/build-module/components/list-view/use-list-view-block-indexes.js.map +1 -0
  209. package/build-module/components/list-view/use-list-view-drop-zone.js +58 -7
  210. package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
  211. package/build-module/components/list-view/utils.js +91 -0
  212. package/build-module/components/list-view/utils.js.map +1 -1
  213. package/build-module/components/provider/index.js +1 -1
  214. package/build-module/components/provider/index.js.map +1 -1
  215. package/build-module/components/recursion-provider/index.js +17 -0
  216. package/build-module/components/recursion-provider/index.js.map +1 -1
  217. package/build-module/components/rich-text/index.js +30 -6
  218. package/build-module/components/rich-text/index.js.map +1 -1
  219. package/build-module/components/rich-text/native/index.native.js +9 -9
  220. package/build-module/components/rich-text/native/index.native.js.map +1 -1
  221. package/build-module/components/use-block-drop-zone/index.js +31 -8
  222. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  223. package/build-module/components/use-on-block-drop/index.js +51 -9
  224. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  225. package/build-module/hooks/block-hooks.js +5 -14
  226. package/build-module/hooks/block-hooks.js.map +1 -1
  227. package/build-module/hooks/content-lock-ui.js +19 -43
  228. package/build-module/hooks/content-lock-ui.js.map +1 -1
  229. package/build-module/hooks/effects.js +51 -0
  230. package/build-module/hooks/effects.js.map +1 -0
  231. package/build-module/hooks/index.js +2 -0
  232. package/build-module/hooks/index.js.map +1 -1
  233. package/build-module/hooks/index.native.js +1 -0
  234. package/build-module/hooks/index.native.js.map +1 -1
  235. package/build-module/hooks/style.js +6 -2
  236. package/build-module/hooks/style.js.map +1 -1
  237. package/build-module/hooks/supports.js +2 -1
  238. package/build-module/hooks/supports.js.map +1 -1
  239. package/build-module/hooks/typography.native.js +2 -2
  240. package/build-module/hooks/typography.native.js.map +1 -1
  241. package/build-module/hooks/use-bindings-attributes.js +112 -0
  242. package/build-module/hooks/use-bindings-attributes.js.map +1 -0
  243. package/build-module/hooks/use-shadow-props.js +39 -0
  244. package/build-module/hooks/use-shadow-props.js.map +1 -0
  245. package/build-module/hooks/utils.js +9 -8
  246. package/build-module/hooks/utils.js.map +1 -1
  247. package/build-module/index.js +1 -1
  248. package/build-module/index.js.map +1 -1
  249. package/build-module/store/actions.js +10 -6
  250. package/build-module/store/actions.js.map +1 -1
  251. package/build-module/store/index.js +2 -0
  252. package/build-module/store/index.js.map +1 -1
  253. package/build-module/store/private-actions.js +35 -0
  254. package/build-module/store/private-actions.js.map +1 -1
  255. package/build-module/store/private-selectors.js +53 -8
  256. package/build-module/store/private-selectors.js.map +1 -1
  257. package/build-module/store/reducer.js +43 -3
  258. package/build-module/store/reducer.js.map +1 -1
  259. package/build-module/store/resolvers.js +20 -0
  260. package/build-module/store/resolvers.js.map +1 -0
  261. package/build-module/store/selectors.js +89 -52
  262. package/build-module/store/selectors.js.map +1 -1
  263. package/build-module/store/utils.js +3 -23
  264. package/build-module/store/utils.js.map +1 -1
  265. package/build-module/utils/index.js +0 -1
  266. package/build-module/utils/index.js.map +1 -1
  267. package/build-module/utils/math.js +12 -0
  268. package/build-module/utils/math.js.map +1 -1
  269. package/build-module/utils/transform-styles/index.js +36 -27
  270. package/build-module/utils/transform-styles/index.js.map +1 -1
  271. package/build-style/content-rtl.css +33 -16
  272. package/build-style/content.css +33 -16
  273. package/build-style/default-editor-styles-rtl.css +1 -1
  274. package/build-style/default-editor-styles.css +1 -1
  275. package/build-style/style-rtl.css +169 -114
  276. package/build-style/style.css +169 -114
  277. package/package.json +31 -31
  278. package/src/components/block-canvas/style.scss +8 -1
  279. package/src/components/block-draggable/index.js +16 -5
  280. package/src/components/block-edit/context.js +1 -0
  281. package/src/components/block-edit/index.js +4 -0
  282. package/src/components/block-editing-mode/index.js +12 -7
  283. package/src/components/block-inspector/index.js +5 -2
  284. package/src/components/block-list/block.js +5 -4
  285. package/src/components/block-list/block.native.js +13 -3
  286. package/src/components/block-list/content.scss +34 -5
  287. package/src/components/block-list/index.js +52 -16
  288. package/src/components/block-list/private-block-context.js +1 -1
  289. package/src/components/block-list/use-in-between-inserter.js +1 -2
  290. package/src/components/block-popover/inbetween.js +22 -2
  291. package/src/components/block-preview/auto.js +3 -3
  292. package/src/components/block-removal-warning-modal/index.js +3 -2
  293. package/src/components/block-settings-menu/block-settings-dropdown.js +2 -7
  294. package/src/components/block-switcher/block-transformations-menu.js +18 -1
  295. package/src/components/block-switcher/index.js +133 -111
  296. package/src/components/block-switcher/style.scss +6 -4
  297. package/src/components/block-switcher/test/index.js +113 -230
  298. package/src/components/block-toolbar/style.scss +22 -18
  299. package/src/components/block-tools/insertion-point.js +15 -2
  300. package/src/components/block-tools/style.scss +8 -7
  301. package/src/components/font-sizes/fluid-utils.js +8 -2
  302. package/src/components/font-sizes/test/fluid-utils.js +9 -0
  303. package/src/components/global-styles/border-panel.js +7 -17
  304. package/src/components/global-styles/effects-panel.js +16 -1
  305. package/src/components/iframe/get-compatibility-styles.js +120 -0
  306. package/src/components/iframe/index.js +2 -3
  307. package/src/components/index.js +4 -2
  308. package/src/components/index.native.js +4 -2
  309. package/src/components/inspector-controls/groups.js +2 -0
  310. package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
  311. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +2 -0
  312. package/src/components/link-control/link-preview.js +31 -55
  313. package/src/components/link-control/search-input.js +1 -9
  314. package/src/components/link-control/style.scss +31 -85
  315. package/src/components/link-control/test/index.js +2 -1
  316. package/src/components/list-view/block-contents.js +5 -1
  317. package/src/components/list-view/block.js +9 -0
  318. package/src/components/list-view/branch.js +30 -10
  319. package/src/components/list-view/drop-indicator.js +139 -46
  320. package/src/components/list-view/index.js +74 -3
  321. package/src/components/list-view/leaf.js +2 -2
  322. package/src/components/list-view/style.scss +102 -13
  323. package/src/components/list-view/test/use-list-view-drop-zone.js +4 -0
  324. package/src/components/list-view/test/utils.js +218 -1
  325. package/src/components/list-view/use-list-view-block-indexes.js +29 -0
  326. package/src/components/list-view/use-list-view-drop-zone.js +78 -6
  327. package/src/components/list-view/utils.js +116 -0
  328. package/src/components/provider/index.js +3 -1
  329. package/src/components/recursion-provider/README.md +2 -2
  330. package/src/components/recursion-provider/index.js +17 -0
  331. package/src/components/rich-text/index.js +48 -10
  332. package/src/components/rich-text/native/index.native.js +10 -10
  333. package/src/components/use-block-drop-zone/index.js +60 -19
  334. package/src/components/use-block-drop-zone/test/index.js +32 -61
  335. package/src/components/use-on-block-drop/index.js +92 -11
  336. package/src/hooks/block-hooks.js +5 -17
  337. package/src/hooks/content-lock-ui.js +15 -55
  338. package/src/hooks/effects.js +57 -0
  339. package/src/hooks/index.js +2 -0
  340. package/src/hooks/index.native.js +1 -0
  341. package/src/hooks/style.js +8 -0
  342. package/src/hooks/supports.js +2 -0
  343. package/src/hooks/test/effects.js +39 -0
  344. package/src/hooks/typography.native.js +2 -2
  345. package/src/hooks/use-bindings-attributes.js +148 -0
  346. package/src/hooks/use-shadow-props.js +37 -0
  347. package/src/hooks/utils.js +10 -6
  348. package/src/index.js +2 -0
  349. package/src/store/actions.js +9 -4
  350. package/src/store/index.js +2 -0
  351. package/src/store/private-actions.js +32 -0
  352. package/src/store/private-selectors.js +78 -21
  353. package/src/store/reducer.js +49 -2
  354. package/src/store/resolvers.js +17 -0
  355. package/src/store/selectors.js +169 -161
  356. package/src/store/test/registry-selectors.js +431 -0
  357. package/src/store/test/selectors.js +14 -400
  358. package/src/store/utils.js +10 -33
  359. package/src/style.scss +0 -1
  360. package/src/utils/index.js +0 -1
  361. package/src/utils/math.js +12 -0
  362. package/src/utils/transform-styles/index.js +52 -37
  363. package/tsconfig.tsbuildinfo +1 -1
  364. package/build/components/iframe/use-compatibility-styles.js +0 -100
  365. package/build/components/iframe/use-compatibility-styles.js.map +0 -1
  366. package/build/utils/block-variation-transforms.js +0 -42
  367. package/build/utils/block-variation-transforms.js.map +0 -1
  368. package/build-module/components/iframe/use-compatibility-styles.js +0 -94
  369. package/build-module/components/iframe/use-compatibility-styles.js.map +0 -1
  370. package/build-module/utils/block-variation-transforms.js +0 -35
  371. package/build-module/utils/block-variation-transforms.js.map +0 -1
  372. package/src/components/block-switcher/test/__snapshots__/index.js.snap +0 -116
  373. package/src/components/contrast-checker/style.scss +0 -3
  374. package/src/components/iframe/use-compatibility-styles.js +0 -122
  375. package/src/utils/block-variation-transforms.js +0 -38
  376. package/src/utils/test/block-variation-transforms.js +0 -94
@@ -4,9 +4,11 @@
4
4
  import { useCallback } from '@wordpress/element';
5
5
  import {
6
6
  cloneBlock,
7
+ createBlock,
7
8
  findTransform,
8
9
  getBlockTransforms,
9
10
  pasteHandler,
11
+ store as blocksStore,
10
12
  } from '@wordpress/blocks';
11
13
  import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
12
14
  import { getFilesFromDataTransfer } from '@wordpress/dom';
@@ -61,6 +63,8 @@ export function parseDropEvent( event ) {
61
63
  * @param {Function} moveBlocks A function that moves blocks.
62
64
  * @param {Function} insertOrReplaceBlocks A function that inserts or replaces blocks.
63
65
  * @param {Function} clearSelectedBlock A function that clears block selection.
66
+ * @param {string} operation The type of operation to perform on drop. Could be `insert` or `replace` or `group`.
67
+ * @param {Function} getBlock A function that returns a block given its client id.
64
68
  * @return {Function} The event handler for a block drop event.
65
69
  */
66
70
  export function onBlockDrop(
@@ -70,7 +74,9 @@ export function onBlockDrop(
70
74
  getClientIdsOfDescendants,
71
75
  moveBlocks,
72
76
  insertOrReplaceBlocks,
73
- clearSelectedBlock
77
+ clearSelectedBlock,
78
+ operation,
79
+ getBlock
74
80
  ) {
75
81
  return ( event ) => {
76
82
  const {
@@ -113,6 +119,21 @@ export function onBlockDrop(
113
119
  return;
114
120
  }
115
121
 
122
+ // If the user is dropping a block over another block, replace both blocks
123
+ // with a group block containing them
124
+ if ( operation === 'group' ) {
125
+ const blocksToInsert = sourceClientIds.map( ( clientId ) =>
126
+ getBlock( clientId )
127
+ );
128
+ insertOrReplaceBlocks(
129
+ blocksToInsert,
130
+ true,
131
+ null,
132
+ sourceClientIds
133
+ );
134
+ return;
135
+ }
136
+
116
137
  const isAtSameLevel = sourceRootClientId === targetRootClientId;
117
138
  const draggedBlockCount = sourceClientIds.length;
118
139
 
@@ -202,7 +223,7 @@ export default function useOnBlockDrop(
202
223
  targetBlockIndex,
203
224
  options = {}
204
225
  ) {
205
- const { operation = 'insert' } = options;
226
+ const { operation = 'insert', nearestSide = 'right' } = options;
206
227
  const {
207
228
  canInsertBlockType,
208
229
  getBlockIndex,
@@ -210,7 +231,10 @@ export default function useOnBlockDrop(
210
231
  getBlockOrder,
211
232
  getBlocksByClientId,
212
233
  getSettings,
234
+ getBlock,
235
+ isGroupable,
213
236
  } = useSelect( blockEditorStore );
237
+ const { getBlockType, getGroupingBlockName } = useSelect( blocksStore );
214
238
  const {
215
239
  insertBlocks,
216
240
  moveBlocksToPosition,
@@ -222,12 +246,63 @@ export default function useOnBlockDrop(
222
246
  const registry = useRegistry();
223
247
 
224
248
  const insertOrReplaceBlocks = useCallback(
225
- ( blocks, updateSelection = true, initialPosition = 0 ) => {
249
+ (
250
+ blocks,
251
+ updateSelection = true,
252
+ initialPosition = 0,
253
+ clientIdsToReplace = []
254
+ ) => {
255
+ const clientIds = getBlockOrder( targetRootClientId );
256
+ const clientId = clientIds[ targetBlockIndex ];
257
+ const blocksClientIds = blocks.map( ( block ) => block.clientId );
258
+ const areGroupableBlocks = isGroupable( [
259
+ ...blocksClientIds,
260
+ clientId,
261
+ ] );
226
262
  if ( operation === 'replace' ) {
227
- const clientIds = getBlockOrder( targetRootClientId );
228
- const clientId = clientIds[ targetBlockIndex ];
229
-
230
263
  replaceBlocks( clientId, blocks, undefined, initialPosition );
264
+ } else if ( operation === 'group' && areGroupableBlocks ) {
265
+ const targetBlock = getBlock( clientId );
266
+ if ( nearestSide === 'left' ) {
267
+ blocks.push( targetBlock );
268
+ } else {
269
+ blocks.unshift( targetBlock );
270
+ }
271
+
272
+ const groupInnerBlocks = blocks.map( ( block ) => {
273
+ return createBlock(
274
+ block.name,
275
+ block.attributes,
276
+ block.innerBlocks
277
+ );
278
+ } );
279
+
280
+ const areAllImages = blocks.every( ( block ) => {
281
+ return block.name === 'core/image';
282
+ } );
283
+
284
+ const galleryBlock = !! getBlockType( 'core/gallery' );
285
+
286
+ const wrappedBlocks = createBlock(
287
+ areAllImages && galleryBlock
288
+ ? 'core/gallery'
289
+ : getGroupingBlockName(),
290
+ {
291
+ layout: {
292
+ type: 'flex',
293
+ flexWrap: areAllImages ? null : 'nowrap',
294
+ },
295
+ },
296
+ groupInnerBlocks
297
+ );
298
+ // Need to make sure both the target block and the block being dragged are replaced
299
+ // otherwise the dragged block will be duplicated.
300
+ replaceBlocks(
301
+ [ clientId, ...clientIdsToReplace ],
302
+ wrappedBlocks,
303
+ undefined,
304
+ initialPosition
305
+ );
231
306
  } else {
232
307
  insertBlocks(
233
308
  blocks,
@@ -239,12 +314,16 @@ export default function useOnBlockDrop(
239
314
  }
240
315
  },
241
316
  [
242
- operation,
243
317
  getBlockOrder,
244
- insertBlocks,
245
- replaceBlocks,
246
- targetBlockIndex,
247
318
  targetRootClientId,
319
+ targetBlockIndex,
320
+ operation,
321
+ replaceBlocks,
322
+ getBlock,
323
+ nearestSide,
324
+ getBlockType,
325
+ getGroupingBlockName,
326
+ insertBlocks,
248
327
  ]
249
328
  );
250
329
 
@@ -297,7 +376,9 @@ export default function useOnBlockDrop(
297
376
  getClientIdsOfDescendants,
298
377
  moveBlocks,
299
378
  insertOrReplaceBlocks,
300
- clearSelectedBlock
379
+ clearSelectedBlock,
380
+ operation,
381
+ getBlock
301
382
  );
302
383
  const _onFilesDrop = onFilesDrop(
303
384
  targetRootClientId,
@@ -55,8 +55,7 @@ function BlockHooksControlPure( { name, clientId } ) {
55
55
  const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(
56
56
  ( clientIds, block ) => {
57
57
  // If the block doesn't exist anywhere in the block tree,
58
- // we know that we have to display the toggle for it, and set
59
- // it to disabled.
58
+ // we know that we have to set the toggle to disabled.
60
59
  if ( getGlobalBlockCount( block.name ) === 0 ) {
61
60
  return clientIds;
62
61
  }
@@ -83,7 +82,7 @@ function BlockHooksControlPure( { name, clientId } ) {
83
82
  }
84
83
 
85
84
  const hookedBlock = candidates?.find(
86
- ( candidate ) => name === candidate.name
85
+ ( candidate ) => candidate.name === block.name
87
86
  );
88
87
 
89
88
  // If the block exists in the designated location, we consider it hooked
@@ -96,13 +95,8 @@ function BlockHooksControlPure( { name, clientId } ) {
96
95
  }
97
96
 
98
97
  // If no hooked block was found in any of its designated locations,
99
- // but it exists elsewhere in the block tree, we consider it manually inserted.
100
- // In this case, we take note and will remove the corresponding toggle from the
101
- // block inspector panel.
102
- return {
103
- ...clientIds,
104
- [ block.name ]: false,
105
- };
98
+ // we set the toggle to disabled.
99
+ return clientIds;
106
100
  },
107
101
  {}
108
102
  );
@@ -118,13 +112,7 @@ function BlockHooksControlPure( { name, clientId } ) {
118
112
 
119
113
  const { insertBlock, removeBlock } = useDispatch( blockEditorStore );
120
114
 
121
- // Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
122
- const hookedBlocksForCurrentBlockIfNotPresentElsewhere =
123
- hookedBlocksForCurrentBlock?.filter(
124
- ( block ) => hookedBlockClientIds?.[ block.name ] !== false
125
- );
126
-
127
- if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {
115
+ if ( ! hookedBlocksForCurrentBlock.length ) {
128
116
  return null;
129
117
  }
130
118
 
@@ -4,40 +4,23 @@
4
4
  import { ToolbarButton, MenuItem } from '@wordpress/components';
5
5
  import { useDispatch, useSelect } from '@wordpress/data';
6
6
  import { __ } from '@wordpress/i18n';
7
- import { useEffect, useRef, useCallback } from '@wordpress/element';
7
+ import { useCallback } from '@wordpress/element';
8
8
 
9
9
  /**
10
10
  * Internal dependencies
11
11
  */
12
12
  import { store as blockEditorStore } from '../store';
13
13
  import { BlockControls, BlockSettingsMenuControls } from '../components';
14
+ import { unlock } from '../lock-unlock';
14
15
 
15
- function StopEditingAsBlocksOnOutsideSelect( {
16
- clientId,
17
- stopEditingAsBlock,
18
- } ) {
19
- const isBlockOrDescendantSelected = useSelect(
20
- ( select ) => {
21
- const { isBlockSelected, hasSelectedInnerBlock } =
22
- select( blockEditorStore );
23
- return (
24
- isBlockSelected( clientId ) ||
25
- hasSelectedInnerBlock( clientId, true )
26
- );
27
- },
28
- [ clientId ]
29
- );
30
- useEffect( () => {
31
- if ( ! isBlockOrDescendantSelected ) {
32
- stopEditingAsBlock();
33
- }
34
- }, [ isBlockOrDescendantSelected, stopEditingAsBlock ] );
35
- return null;
36
- }
16
+ // The implementation of content locking is mainly in this file, although the mechanism
17
+ // to stop temporarily editing as blocks when an outside block is selected is on component StopEditingAsBlocksOnOutsideSelect
18
+ // at block-editor/src/components/block-list/index.js.
19
+ // Besides the components on this file and the file referenced above the implementation
20
+ // also includes artifacts on the store (actions, reducers, and selector).
37
21
 
38
22
  function ContentLockControlsPure( { clientId, isSelected } ) {
39
23
  const { getBlockListSettings, getSettings } = useSelect( blockEditorStore );
40
- const focusModeToRevert = useRef();
41
24
  const { templateLock, isLockedByParent, isEditingAsBlocks } = useSelect(
42
25
  ( select ) => {
43
26
  const {
@@ -61,31 +44,15 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
61
44
  updateBlockListSettings,
62
45
  __unstableSetTemporarilyEditingAsBlocks,
63
46
  } = useDispatch( blockEditorStore );
47
+ const { stopEditingAsBlocks } = unlock( useDispatch( blockEditorStore ) );
64
48
  const isContentLocked =
65
49
  ! isLockedByParent && templateLock === 'contentOnly';
66
50
  const { __unstableMarkNextChangeAsNotPersistent, updateBlockAttributes } =
67
51
  useDispatch( blockEditorStore );
68
52
 
69
- const stopEditingAsBlock = useCallback( () => {
70
- __unstableMarkNextChangeAsNotPersistent();
71
- updateBlockAttributes( clientId, {
72
- templateLock: 'contentOnly',
73
- } );
74
- updateBlockListSettings( clientId, {
75
- ...getBlockListSettings( clientId ),
76
- templateLock: 'contentOnly',
77
- } );
78
- updateSettings( { focusMode: focusModeToRevert.current } );
79
- __unstableSetTemporarilyEditingAsBlocks();
80
- }, [
81
- clientId,
82
- updateSettings,
83
- updateBlockListSettings,
84
- getBlockListSettings,
85
- __unstableMarkNextChangeAsNotPersistent,
86
- updateBlockAttributes,
87
- __unstableSetTemporarilyEditingAsBlocks,
88
- ] );
53
+ const stopEditingAsBlockCallback = useCallback( () => {
54
+ stopEditingAsBlocks( clientId );
55
+ }, [ clientId, stopEditingAsBlocks ] );
89
56
 
90
57
  if ( ! isContentLocked && ! isEditingAsBlocks ) {
91
58
  return null;
@@ -99,16 +66,8 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
99
66
  <>
100
67
  { showStopEditingAsBlocks && (
101
68
  <>
102
- <StopEditingAsBlocksOnOutsideSelect
103
- clientId={ clientId }
104
- stopEditingAsBlock={ stopEditingAsBlock }
105
- />
106
69
  <BlockControls group="other">
107
- <ToolbarButton
108
- onClick={ () => {
109
- stopEditingAsBlock();
110
- } }
111
- >
70
+ <ToolbarButton onClick={ stopEditingAsBlockCallback }>
112
71
  { __( 'Done' ) }
113
72
  </ToolbarButton>
114
73
  </BlockControls>
@@ -127,11 +86,12 @@ function ContentLockControlsPure( { clientId, isSelected } ) {
127
86
  ...getBlockListSettings( clientId ),
128
87
  templateLock: false,
129
88
  } );
130
- focusModeToRevert.current =
89
+ const focusModeToRevert =
131
90
  getSettings().focusMode;
132
91
  updateSettings( { focusMode: true } );
133
92
  __unstableSetTemporarilyEditingAsBlocks(
134
- clientId
93
+ clientId,
94
+ focusModeToRevert
135
95
  );
136
96
  onClose();
137
97
  } }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { hasBlockSupport } from '@wordpress/blocks';
5
+ import { useSelect } from '@wordpress/data';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import StylesEffectsPanel, {
10
+ useHasEffectsPanel,
11
+ } from '../components/global-styles/effects-panel';
12
+ import { InspectorControls } from '../components';
13
+ import { store as blockEditorStore } from '../store';
14
+ import { cleanEmptyObject } from './utils';
15
+
16
+ export const SHADOW_SUPPORT_KEY = 'shadow';
17
+ export const EFFECTS_SUPPORT_KEYS = [ SHADOW_SUPPORT_KEY ];
18
+
19
+ export function hasEffectsSupport( blockName ) {
20
+ return EFFECTS_SUPPORT_KEYS.some( ( key ) =>
21
+ hasBlockSupport( blockName, key )
22
+ );
23
+ }
24
+
25
+ function EffectsInspectorControl( { children, resetAllFilter } ) {
26
+ return (
27
+ <InspectorControls group="effects" resetAllFilter={ resetAllFilter }>
28
+ { children }
29
+ </InspectorControls>
30
+ );
31
+ }
32
+ export function EffectsPanel( { clientId, setAttributes, settings } ) {
33
+ const isEnabled = useHasEffectsPanel( settings );
34
+ const value = useSelect(
35
+ ( select ) =>
36
+ select( blockEditorStore ).getBlockAttributes( clientId )?.style,
37
+ [ clientId ]
38
+ );
39
+
40
+ const onChange = ( newStyle ) => {
41
+ setAttributes( { style: cleanEmptyObject( newStyle ) } );
42
+ };
43
+
44
+ if ( ! isEnabled ) {
45
+ return null;
46
+ }
47
+
48
+ return (
49
+ <StylesEffectsPanel
50
+ as={ EffectsInspectorControl }
51
+ panelId={ clientId }
52
+ settings={ settings }
53
+ value={ value }
54
+ onChange={ onChange }
55
+ />
56
+ );
57
+ }
@@ -27,6 +27,7 @@ import contentLockUI from './content-lock-ui';
27
27
  import './metadata';
28
28
  import blockHooks from './block-hooks';
29
29
  import blockRenaming from './block-renaming';
30
+ import './use-bindings-attributes';
30
31
 
31
32
  createBlockEditFilter(
32
33
  [
@@ -68,6 +69,7 @@ createBlockSaveFilter( [
68
69
  export { useCustomSides } from './dimensions';
69
70
  export { useLayoutClasses, useLayoutStyles } from './layout';
70
71
  export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
72
+ export { getShadowClassesAndStyles, useShadowProps } from './use-shadow-props';
71
73
  export { getColorClassesAndStyles, useColorProps } from './use-color-props';
72
74
  export { getSpacingClassesAndStyles } from './use-spacing-props';
73
75
  export { getTypographyClassesAndStyles } from './use-typography-props';
@@ -28,6 +28,7 @@ createBlockSaveFilter( [
28
28
  ] );
29
29
 
30
30
  export { getBorderClassesAndStyles, useBorderProps } from './use-border-props';
31
+ export { getShadowClassesAndStyles, useShadowProps } from './use-shadow-props';
31
32
  export { getColorClassesAndStyles, useColorProps } from './use-color-props';
32
33
  export { getSpacingClassesAndStyles } from './use-spacing-props';
33
34
  export { useCachedTruthy } from './use-cached-truthy';
@@ -27,6 +27,11 @@ import {
27
27
  SPACING_SUPPORT_KEY,
28
28
  DimensionsPanel,
29
29
  } from './dimensions';
30
+ import {
31
+ EFFECTS_SUPPORT_KEYS,
32
+ SHADOW_SUPPORT_KEY,
33
+ EffectsPanel,
34
+ } from './effects';
30
35
  import {
31
36
  shouldSkipSerialization,
32
37
  useStyleOverride,
@@ -37,6 +42,7 @@ import { useBlockEditingMode } from '../components/block-editing-mode';
37
42
 
38
43
  const styleSupportKeys = [
39
44
  ...TYPOGRAPHY_SUPPORT_KEYS,
45
+ ...EFFECTS_SUPPORT_KEYS,
40
46
  BORDER_SUPPORT_KEY,
41
47
  COLOR_SUPPORT_KEY,
42
48
  DIMENSIONS_SUPPORT_KEY,
@@ -110,6 +116,7 @@ const skipSerializationPathsEdit = {
110
116
  [ `${ SPACING_SUPPORT_KEY }.__experimentalSkipSerialization` ]: [
111
117
  SPACING_SUPPORT_KEY,
112
118
  ],
119
+ [ `${ SHADOW_SUPPORT_KEY }` ]: [ SHADOW_SUPPORT_KEY ],
113
120
  };
114
121
 
115
122
  /**
@@ -336,6 +343,7 @@ function BlockStyleControls( {
336
343
  <TypographyPanel { ...passedProps } />
337
344
  <BorderPanel { ...passedProps } />
338
345
  <DimensionsPanel { ...passedProps } />
346
+ <EffectsPanel { ...passedProps } />
339
347
  </>
340
348
  );
341
349
  }
@@ -59,8 +59,10 @@ const TYPOGRAPHY_SUPPORT_KEYS = [
59
59
  WRITING_MODE_SUPPORT_KEY,
60
60
  LETTER_SPACING_SUPPORT_KEY,
61
61
  ];
62
+ const EFFECTS_SUPPORT_KEYS = [ 'shadow' ];
62
63
  const SPACING_SUPPORT_KEY = 'spacing';
63
64
  const styleSupportKeys = [
65
+ ...EFFECTS_SUPPORT_KEYS,
64
66
  ...TYPOGRAPHY_SUPPORT_KEYS,
65
67
  BORDER_SUPPORT_KEY,
66
68
  COLOR_SUPPORT_KEY,
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { hasEffectsSupport } from '../effects';
5
+
6
+ describe( 'effects', () => {
7
+ describe( 'hasEffectsSupport', () => {
8
+ it( 'should return false if the block does not support effects', () => {
9
+ const settings = {
10
+ supports: {
11
+ shadow: false,
12
+ },
13
+ };
14
+
15
+ expect( hasEffectsSupport( settings ) ).toBe( false );
16
+ } );
17
+
18
+ it( 'should return true if the block supports effects', () => {
19
+ const settings = {
20
+ supports: {
21
+ shadow: true,
22
+ },
23
+ };
24
+
25
+ expect( hasEffectsSupport( settings ) ).toBe( true );
26
+ } );
27
+
28
+ it( 'should return true if the block supports effects and other features', () => {
29
+ const settings = {
30
+ supports: {
31
+ shadow: true,
32
+ align: true,
33
+ },
34
+ };
35
+
36
+ expect( hasEffectsSupport( settings ) ).toBe( true );
37
+ } );
38
+ } );
39
+ } );
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useSelect } from '@wordpress/data';
5
- import { pure } from '@wordpress/compose';
5
+ import { memo } from '@wordpress/element';
6
6
  import { PanelBody } from '@wordpress/components';
7
7
  import { __ } from '@wordpress/i18n';
8
8
 
@@ -57,4 +57,4 @@ function TypographyPanelPure( { clientId, setAttributes, settings } ) {
57
57
  // We don't want block controls to re-render when typing inside a block. `pure`
58
58
  // will prevent re-renders unless props change, so only pass the needed props
59
59
  // and not the whole attributes object.
60
- export const TypographyPanel = pure( TypographyPanelPure );
60
+ export const TypographyPanel = memo( TypographyPanelPure );
@@ -0,0 +1,148 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { getBlockType } from '@wordpress/blocks';
5
+ import { createHigherOrderComponent } from '@wordpress/compose';
6
+ import { useRegistry, useSelect } from '@wordpress/data';
7
+ import { addFilter } from '@wordpress/hooks';
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { store as blockEditorStore } from '../store';
12
+ import { useBlockEditContext } from '../components/block-edit/context';
13
+ import { unlock } from '../lock-unlock';
14
+
15
+ /** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
16
+ /** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */
17
+
18
+ /**
19
+ * Given a binding of block attributes, returns a higher order component that
20
+ * overrides its `attributes` and `setAttributes` props to sync any changes needed.
21
+ *
22
+ * @return {WPHigherOrderComponent} Higher-order component.
23
+ */
24
+
25
+ const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
26
+ 'core/paragraph': [ 'content' ],
27
+ 'core/heading': [ 'content' ],
28
+ 'core/image': [ 'url', 'title', 'alt' ],
29
+ 'core/button': [ 'url', 'text', 'linkTarget' ],
30
+ };
31
+
32
+ const createEditFunctionWithBindingsAttribute = () =>
33
+ createHigherOrderComponent(
34
+ ( BlockEdit ) => ( props ) => {
35
+ const { clientId, name: blockName } = useBlockEditContext();
36
+ const { getBlockBindingsSource } = unlock(
37
+ useSelect( blockEditorStore )
38
+ );
39
+ const { getBlockAttributes, updateBlockAttributes } =
40
+ useSelect( blockEditorStore );
41
+
42
+ const updatedAttributes = getBlockAttributes( clientId );
43
+ if ( updatedAttributes?.metadata?.bindings ) {
44
+ Object.entries( updatedAttributes.metadata.bindings ).forEach(
45
+ ( [ attributeName, settings ] ) => {
46
+ const source = getBlockBindingsSource(
47
+ settings.source.name
48
+ );
49
+
50
+ if ( source ) {
51
+ // Second argument (`updateMetaValue`) will be used to update the value in the future.
52
+ const {
53
+ placeholder,
54
+ useValue: [ metaValue = null ] = [],
55
+ } = source.useSource(
56
+ props,
57
+ settings.source.attributes
58
+ );
59
+
60
+ if ( placeholder && ! metaValue ) {
61
+ // If the attribute is `src` or `href`, a placeholder can't be used because it is not a valid url.
62
+ // Adding this workaround until attributes and metadata fields types are improved and include `url`.
63
+ const htmlAttribute =
64
+ getBlockType( blockName ).attributes[
65
+ attributeName
66
+ ].attribute;
67
+ if (
68
+ htmlAttribute === 'src' ||
69
+ htmlAttribute === 'href'
70
+ ) {
71
+ updatedAttributes[ attributeName ] = null;
72
+ } else {
73
+ updatedAttributes[ attributeName ] =
74
+ placeholder;
75
+ }
76
+ }
77
+
78
+ if ( metaValue ) {
79
+ updatedAttributes[ attributeName ] = metaValue;
80
+ }
81
+ }
82
+ }
83
+ );
84
+ }
85
+
86
+ const registry = useRegistry();
87
+
88
+ return (
89
+ <>
90
+ <BlockEdit
91
+ key="edit"
92
+ attributes={ updatedAttributes }
93
+ setAttributes={ ( newAttributes, blockId ) =>
94
+ registry.batch( () =>
95
+ updateBlockAttributes( blockId, newAttributes )
96
+ )
97
+ }
98
+ { ...props }
99
+ />
100
+ </>
101
+ );
102
+ },
103
+ 'useBoundAttributes'
104
+ );
105
+
106
+ /**
107
+ * Filters a registered block's settings to enhance a block's `edit` component
108
+ * to upgrade bound attributes.
109
+ *
110
+ * @param {WPBlockSettings} settings Registered block settings.
111
+ *
112
+ * @return {WPBlockSettings} Filtered block settings.
113
+ */
114
+ function shimAttributeSource( settings ) {
115
+ if ( ! ( settings.name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {
116
+ return settings;
117
+ }
118
+ settings.edit = createEditFunctionWithBindingsAttribute()( settings.edit );
119
+
120
+ return settings;
121
+ }
122
+
123
+ addFilter(
124
+ 'blocks.registerBlockType',
125
+ 'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',
126
+ shimAttributeSource
127
+ );
128
+
129
+ // Add the context to all blocks.
130
+ addFilter(
131
+ 'blocks.registerBlockType',
132
+ 'core/block-bindings-ui',
133
+ ( settings, name ) => {
134
+ if ( ! ( name in BLOCK_BINDINGS_ALLOWED_BLOCKS ) ) {
135
+ return settings;
136
+ }
137
+ const contextItems = [ 'postId', 'postType', 'queryId' ];
138
+ const usesContextArray = settings.usesContext;
139
+ const oldUsesContextArray = new Set( usesContextArray );
140
+ contextItems.forEach( ( item ) => {
141
+ if ( ! oldUsesContextArray.has( item ) ) {
142
+ usesContextArray.push( item );
143
+ }
144
+ } );
145
+ settings.usesContext = usesContextArray;
146
+ return settings;
147
+ }
148
+ );