@wordpress/block-editor 12.13.0 → 12.15.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 (528) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/build/components/block-heading-level-dropdown/index.js +1 -1
  4. package/build/components/block-heading-level-dropdown/index.js.map +1 -1
  5. package/build/components/block-list/block.native.js +2 -0
  6. package/build/components/block-list/block.native.js.map +1 -1
  7. package/build/components/block-list/index.js +2 -9
  8. package/build/components/block-list/index.js.map +1 -1
  9. package/build/components/block-list-appender/index.js +16 -3
  10. package/build/components/block-list-appender/index.js.map +1 -1
  11. package/build/components/block-parent-selector/index.js +1 -1
  12. package/build/components/block-parent-selector/index.js.map +1 -1
  13. package/build/components/block-pattern-setup/index.js +25 -16
  14. package/build/components/block-pattern-setup/index.js.map +1 -1
  15. package/build/components/block-pattern-setup/setup-toolbar.js +4 -2
  16. package/build/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  17. package/build/components/block-patterns-list/index.js +36 -19
  18. package/build/components/block-patterns-list/index.js.map +1 -1
  19. package/build/components/block-quick-navigation/index.js +6 -4
  20. package/build/components/block-quick-navigation/index.js.map +1 -1
  21. package/build/components/block-rename/index.js +28 -0
  22. package/build/components/block-rename/index.js.map +1 -0
  23. package/build/components/block-rename/is-empty-string.js +10 -0
  24. package/build/components/block-rename/is-empty-string.js.map +1 -0
  25. package/build/components/block-rename/modal.js +87 -0
  26. package/build/components/block-rename/modal.js.map +1 -0
  27. package/build/components/block-rename/rename-control.js +74 -0
  28. package/build/components/block-rename/rename-control.js.map +1 -0
  29. package/build/components/block-rename/use-block-rename.js +17 -0
  30. package/build/components/block-rename/use-block-rename.js.map +1 -0
  31. package/build/components/block-settings-menu/block-settings-dropdown.js +33 -20
  32. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  33. package/build/components/block-settings-menu-controls/index.js +7 -0
  34. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  35. package/build/components/block-styles/index.js +0 -8
  36. package/build/components/block-styles/index.js.map +1 -1
  37. package/build/components/block-switcher/pattern-transformations-menu.js +18 -14
  38. package/build/components/block-switcher/pattern-transformations-menu.js.map +1 -1
  39. package/build/components/block-toolbar/block-toolbar-menu.native.js +1 -1
  40. package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
  41. package/build/components/block-tools/back-compat.js +2 -2
  42. package/build/components/block-tools/back-compat.js.map +1 -1
  43. package/build/components/block-tools/block-contextual-toolbar.js +11 -81
  44. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  45. package/build/components/block-tools/empty-block-inserter.js +56 -0
  46. package/build/components/block-tools/empty-block-inserter.js.map +1 -0
  47. package/build/components/block-tools/index.js +48 -9
  48. package/build/components/block-tools/index.js.map +1 -1
  49. package/build/components/block-tools/selected-block-tools.js +113 -0
  50. package/build/components/block-tools/selected-block-tools.js.map +1 -0
  51. package/build/components/block-tools/use-selected-block-tool-props.js +56 -0
  52. package/build/components/block-tools/use-selected-block-tool-props.js.map +1 -0
  53. package/build/components/block-types-list/index.js +6 -2
  54. package/build/components/block-types-list/index.js.map +1 -1
  55. package/build/components/date-format-picker/index.js +8 -1
  56. package/build/components/date-format-picker/index.js.map +1 -1
  57. package/build/components/editable-text/index.js +1 -2
  58. package/build/components/editable-text/index.js.map +1 -1
  59. package/build/components/global-styles/advanced-panel.js +1 -1
  60. package/build/components/global-styles/advanced-panel.js.map +1 -1
  61. package/build/components/iframe/index.js +4 -3
  62. package/build/components/iframe/index.js.map +1 -1
  63. package/build/components/image-size-control/index.js +0 -5
  64. package/build/components/image-size-control/index.js.map +1 -1
  65. package/build/components/inner-blocks/index.js +3 -1
  66. package/build/components/inner-blocks/index.js.map +1 -1
  67. package/build/components/inner-blocks/warning-max-depth-exceeded.native.js +29 -31
  68. package/build/components/inner-blocks/warning-max-depth-exceeded.native.js.map +1 -1
  69. package/build/components/inserter/block-patterns-explorer/{explorer.js → index.js} +7 -7
  70. package/build/components/inserter/block-patterns-explorer/index.js.map +1 -0
  71. package/build/components/inserter/block-patterns-explorer/{sidebar.js → pattern-explorer-sidebar.js} +1 -1
  72. package/build/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js.map +1 -0
  73. package/build/components/inserter/block-patterns-explorer/{patterns-list.js → pattern-list.js} +4 -4
  74. package/build/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -0
  75. package/build/components/inserter/block-patterns-tab/index.js +75 -0
  76. package/build/components/inserter/block-patterns-tab/index.js.map +1 -0
  77. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +48 -0
  78. package/build/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -0
  79. package/build/components/inserter/block-patterns-tab/pattern-category-previews.js +108 -0
  80. package/build/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -0
  81. package/build/components/inserter/{block-patterns-filter.js → block-patterns-tab/patterns-filter.js} +18 -34
  82. package/build/components/inserter/block-patterns-tab/patterns-filter.js.map +1 -0
  83. package/build/components/inserter/block-patterns-tab/use-pattern-categories.js +55 -0
  84. package/build/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -0
  85. package/build/components/inserter/block-patterns-tab/utils.js +69 -0
  86. package/build/components/inserter/block-patterns-tab/utils.js.map +1 -0
  87. package/build/components/inserter/hooks/use-patterns-state.js +2 -1
  88. package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
  89. package/build/components/inserter/media-tab/media-list.js +9 -5
  90. package/build/components/inserter/media-tab/media-list.js.map +1 -1
  91. package/build/components/inserter/media-tab/media-preview.js +15 -12
  92. package/build/components/inserter/media-tab/media-preview.js.map +1 -1
  93. package/build/components/inserter/menu.js +3 -4
  94. package/build/components/inserter/menu.js.map +1 -1
  95. package/build/components/inserter-listbox/index.js +11 -6
  96. package/build/components/inserter-listbox/index.js.map +1 -1
  97. package/build/components/inserter-listbox/item.js +24 -23
  98. package/build/components/inserter-listbox/item.js.map +1 -1
  99. package/build/components/inserter-listbox/row.js +5 -5
  100. package/build/components/inserter-listbox/row.js.map +1 -1
  101. package/build/components/link-control/index.js +6 -5
  102. package/build/components/link-control/index.js.map +1 -1
  103. package/build/components/list-view/block-select-button.js +39 -0
  104. package/build/components/list-view/block-select-button.js.map +1 -1
  105. package/build/components/list-view/block.js +16 -3
  106. package/build/components/list-view/block.js.map +1 -1
  107. package/build/components/list-view/index.js +3 -2
  108. package/build/components/list-view/index.js.map +1 -1
  109. package/build/components/list-view/use-list-view-expand-selected-item.js +2 -3
  110. package/build/components/list-view/use-list-view-expand-selected-item.js.map +1 -1
  111. package/build/components/navigable-toolbar/index.js +69 -18
  112. package/build/components/navigable-toolbar/index.js.map +1 -1
  113. package/build/components/preview-options/index.js +4 -2
  114. package/build/components/preview-options/index.js.map +1 -1
  115. package/build/components/provider/use-block-sync.js +1 -14
  116. package/build/components/provider/use-block-sync.js.map +1 -1
  117. package/build/components/rich-text/index.js +0 -1
  118. package/build/components/rich-text/index.js.map +1 -1
  119. package/build/components/rich-text/index.native.js +4 -2
  120. package/build/components/rich-text/index.native.js.map +1 -1
  121. package/build/components/rich-text/native/format-edit.js +45 -0
  122. package/build/components/rich-text/native/format-edit.js.map +1 -0
  123. package/build/components/rich-text/native/get-format-colors.native.js +41 -0
  124. package/build/components/rich-text/native/get-format-colors.native.js.map +1 -0
  125. package/build/components/rich-text/native/index.js +9 -0
  126. package/build/components/rich-text/native/index.js.map +1 -0
  127. package/build/components/rich-text/native/index.native.js +1189 -0
  128. package/build/components/rich-text/native/index.native.js.map +1 -0
  129. package/build/components/rich-text/native/toolbar-button-with-options.native.js +58 -0
  130. package/build/components/rich-text/native/toolbar-button-with-options.native.js.map +1 -0
  131. package/build/components/rich-text/native/use-format-types.js +111 -0
  132. package/build/components/rich-text/native/use-format-types.js.map +1 -0
  133. package/build/components/rich-text/use-input-rules.js +30 -1
  134. package/build/components/rich-text/use-input-rules.js.map +1 -1
  135. package/build/components/rich-text/use-paste-handler.js +2 -5
  136. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  137. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
  138. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  139. package/build/components/url-popover/image-url-input-ui.js +2 -1
  140. package/build/components/url-popover/image-url-input-ui.js.map +1 -1
  141. package/build/components/use-block-drop-zone/index.js +4 -1
  142. package/build/components/use-block-drop-zone/index.js.map +1 -1
  143. package/build/components/use-moving-animation/index.js +2 -1
  144. package/build/components/use-moving-animation/index.js.map +1 -1
  145. package/build/components/use-settings/index.js +2 -2
  146. package/build/components/use-settings/index.js.map +1 -1
  147. package/build/components/writing-flow/use-tab-nav.js +7 -3
  148. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  149. package/build/hooks/align.js +10 -10
  150. package/build/hooks/align.js.map +1 -1
  151. package/build/hooks/align.native.js +2 -2
  152. package/build/hooks/align.native.js.map +1 -1
  153. package/build/hooks/anchor.js +7 -6
  154. package/build/hooks/anchor.js.map +1 -1
  155. package/build/hooks/background.js +16 -4
  156. package/build/hooks/background.js.map +1 -1
  157. package/build/hooks/block-hooks.js +7 -8
  158. package/build/hooks/block-hooks.js.map +1 -1
  159. package/build/hooks/block-renaming.js +42 -0
  160. package/build/hooks/block-renaming.js.map +1 -1
  161. package/build/hooks/content-lock-ui.js +5 -5
  162. package/build/hooks/content-lock-ui.js.map +1 -1
  163. package/build/hooks/custom-class-name.js +8 -7
  164. package/build/hooks/custom-class-name.js.map +1 -1
  165. package/build/hooks/custom-fields.js +57 -52
  166. package/build/hooks/custom-fields.js.map +1 -1
  167. package/build/hooks/duotone.js +9 -20
  168. package/build/hooks/duotone.js.map +1 -1
  169. package/build/hooks/index.js +0 -1
  170. package/build/hooks/index.js.map +1 -1
  171. package/build/hooks/layout.js +103 -93
  172. package/build/hooks/layout.js.map +1 -1
  173. package/build/hooks/position.js +10 -9
  174. package/build/hooks/position.js.map +1 -1
  175. package/build/hooks/style.js +10 -13
  176. package/build/hooks/style.js.map +1 -1
  177. package/build/hooks/utils.js +30 -0
  178. package/build/hooks/utils.js.map +1 -1
  179. package/build/layouts/constrained.js +4 -3
  180. package/build/layouts/constrained.js.map +1 -1
  181. package/build/private-apis.js +3 -0
  182. package/build/private-apis.js.map +1 -1
  183. package/build/store/actions.js +30 -37
  184. package/build/store/actions.js.map +1 -1
  185. package/build/store/reducer.js +18 -0
  186. package/build/store/reducer.js.map +1 -1
  187. package/build/store/selectors.js +18 -13
  188. package/build/store/selectors.js.map +1 -1
  189. package/build/utils/transform-styles/index.js +26 -6
  190. package/build/utils/transform-styles/index.js.map +1 -1
  191. package/build-module/components/block-heading-level-dropdown/index.js +1 -1
  192. package/build-module/components/block-heading-level-dropdown/index.js.map +1 -1
  193. package/build-module/components/block-list/block.native.js +2 -0
  194. package/build-module/components/block-list/block.native.js.map +1 -1
  195. package/build-module/components/block-list/index.js +3 -10
  196. package/build-module/components/block-list/index.js.map +1 -1
  197. package/build-module/components/block-list-appender/index.js +16 -3
  198. package/build-module/components/block-list-appender/index.js.map +1 -1
  199. package/build-module/components/block-parent-selector/index.js +1 -1
  200. package/build-module/components/block-parent-selector/index.js.map +1 -1
  201. package/build-module/components/block-pattern-setup/index.js +24 -15
  202. package/build-module/components/block-pattern-setup/index.js.map +1 -1
  203. package/build-module/components/block-pattern-setup/setup-toolbar.js +4 -2
  204. package/build-module/components/block-pattern-setup/setup-toolbar.js.map +1 -1
  205. package/build-module/components/block-patterns-list/index.js +36 -19
  206. package/build-module/components/block-patterns-list/index.js.map +1 -1
  207. package/build-module/components/block-quick-navigation/index.js +7 -5
  208. package/build-module/components/block-quick-navigation/index.js.map +1 -1
  209. package/build-module/components/block-rename/index.js +4 -0
  210. package/build-module/components/block-rename/index.js.map +1 -0
  211. package/build-module/components/block-rename/is-empty-string.js +4 -0
  212. package/build-module/components/block-rename/is-empty-string.js.map +1 -0
  213. package/build-module/components/block-rename/modal.js +79 -0
  214. package/build-module/components/block-rename/modal.js.map +1 -0
  215. package/build-module/components/block-rename/rename-control.js +66 -0
  216. package/build-module/components/block-rename/rename-control.js.map +1 -0
  217. package/build-module/components/block-rename/use-block-rename.js +10 -0
  218. package/build-module/components/block-rename/use-block-rename.js.map +1 -0
  219. package/build-module/components/block-settings-menu/block-settings-dropdown.js +34 -21
  220. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  221. package/build-module/components/block-settings-menu-controls/index.js +7 -0
  222. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  223. package/build-module/components/block-styles/index.js +0 -8
  224. package/build-module/components/block-styles/index.js.map +1 -1
  225. package/build-module/components/block-switcher/pattern-transformations-menu.js +17 -13
  226. package/build-module/components/block-switcher/pattern-transformations-menu.js.map +1 -1
  227. package/build-module/components/block-toolbar/block-toolbar-menu.native.js +1 -1
  228. package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
  229. package/build-module/components/block-tools/back-compat.js +1 -1
  230. package/build-module/components/block-tools/back-compat.js.map +1 -1
  231. package/build-module/components/block-tools/block-contextual-toolbar.js +11 -80
  232. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  233. package/build-module/components/block-tools/empty-block-inserter.js +48 -0
  234. package/build-module/components/block-tools/empty-block-inserter.js.map +1 -0
  235. package/build-module/components/block-tools/index.js +48 -9
  236. package/build-module/components/block-tools/index.js.map +1 -1
  237. package/build-module/components/block-tools/selected-block-tools.js +105 -0
  238. package/build-module/components/block-tools/selected-block-tools.js.map +1 -0
  239. package/build-module/components/block-tools/use-selected-block-tool-props.js +50 -0
  240. package/build-module/components/block-tools/use-selected-block-tool-props.js.map +1 -0
  241. package/build-module/components/block-types-list/index.js +6 -2
  242. package/build-module/components/block-types-list/index.js.map +1 -1
  243. package/build-module/components/date-format-picker/index.js +8 -1
  244. package/build-module/components/date-format-picker/index.js.map +1 -1
  245. package/build-module/components/editable-text/index.js +1 -2
  246. package/build-module/components/editable-text/index.js.map +1 -1
  247. package/build-module/components/global-styles/advanced-panel.js +1 -1
  248. package/build-module/components/global-styles/advanced-panel.js.map +1 -1
  249. package/build-module/components/iframe/index.js +4 -3
  250. package/build-module/components/iframe/index.js.map +1 -1
  251. package/build-module/components/image-size-control/index.js +0 -5
  252. package/build-module/components/image-size-control/index.js.map +1 -1
  253. package/build-module/components/inner-blocks/index.js +3 -1
  254. package/build-module/components/inner-blocks/index.js.map +1 -1
  255. package/build-module/components/inner-blocks/warning-max-depth-exceeded.native.js +30 -32
  256. package/build-module/components/inner-blocks/warning-max-depth-exceeded.native.js.map +1 -1
  257. package/build-module/components/inserter/block-patterns-explorer/{explorer.js → index.js} +5 -5
  258. package/build-module/components/inserter/block-patterns-explorer/index.js.map +1 -0
  259. package/build-module/components/inserter/block-patterns-explorer/{sidebar.js → pattern-explorer-sidebar.js} +1 -1
  260. package/build-module/components/inserter/block-patterns-explorer/pattern-explorer-sidebar.js.map +1 -0
  261. package/build-module/components/inserter/block-patterns-explorer/{patterns-list.js → pattern-list.js} +3 -3
  262. package/build-module/components/inserter/block-patterns-explorer/pattern-list.js.map +1 -0
  263. package/build-module/components/inserter/block-patterns-tab/index.js +66 -0
  264. package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -0
  265. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +42 -0
  266. package/build-module/components/inserter/block-patterns-tab/pattern-category-preview-panel.js.map +1 -0
  267. package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js +100 -0
  268. package/build-module/components/inserter/block-patterns-tab/pattern-category-previews.js.map +1 -0
  269. package/build-module/components/inserter/{block-patterns-filter.js → block-patterns-tab/patterns-filter.js} +7 -20
  270. package/build-module/components/inserter/block-patterns-tab/patterns-filter.js.map +1 -0
  271. package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js +47 -0
  272. package/build-module/components/inserter/block-patterns-tab/use-pattern-categories.js.map +1 -0
  273. package/build-module/components/inserter/block-patterns-tab/utils.js +57 -0
  274. package/build-module/components/inserter/block-patterns-tab/utils.js.map +1 -0
  275. package/build-module/components/inserter/hooks/use-patterns-state.js +2 -1
  276. package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
  277. package/build-module/components/inserter/media-tab/media-list.js +9 -5
  278. package/build-module/components/inserter/media-tab/media-list.js.map +1 -1
  279. package/build-module/components/inserter/media-tab/media-preview.js +15 -12
  280. package/build-module/components/inserter/media-tab/media-preview.js.map +1 -1
  281. package/build-module/components/inserter/menu.js +4 -3
  282. package/build-module/components/inserter/menu.js.map +1 -1
  283. package/build-module/components/inserter-listbox/index.js +13 -8
  284. package/build-module/components/inserter-listbox/index.js.map +1 -1
  285. package/build-module/components/inserter-listbox/item.js +25 -23
  286. package/build-module/components/inserter-listbox/item.js.map +1 -1
  287. package/build-module/components/inserter-listbox/row.js +6 -5
  288. package/build-module/components/inserter-listbox/row.js.map +1 -1
  289. package/build-module/components/link-control/index.js +7 -6
  290. package/build-module/components/link-control/index.js.map +1 -1
  291. package/build-module/components/list-view/block-select-button.js +39 -0
  292. package/build-module/components/list-view/block-select-button.js.map +1 -1
  293. package/build-module/components/list-view/block.js +16 -3
  294. package/build-module/components/list-view/block.js.map +1 -1
  295. package/build-module/components/list-view/index.js +3 -2
  296. package/build-module/components/list-view/index.js.map +1 -1
  297. package/build-module/components/list-view/use-list-view-expand-selected-item.js +2 -3
  298. package/build-module/components/list-view/use-list-view-expand-selected-item.js.map +1 -1
  299. package/build-module/components/navigable-toolbar/index.js +69 -17
  300. package/build-module/components/navigable-toolbar/index.js.map +1 -1
  301. package/build-module/components/preview-options/index.js +4 -2
  302. package/build-module/components/preview-options/index.js.map +1 -1
  303. package/build-module/components/provider/use-block-sync.js +1 -14
  304. package/build-module/components/provider/use-block-sync.js.map +1 -1
  305. package/build-module/components/rich-text/index.js +0 -1
  306. package/build-module/components/rich-text/index.js.map +1 -1
  307. package/build-module/components/rich-text/index.native.js +4 -2
  308. package/build-module/components/rich-text/index.native.js.map +1 -1
  309. package/build-module/components/rich-text/native/format-edit.js +38 -0
  310. package/build-module/components/rich-text/native/format-edit.js.map +1 -0
  311. package/build-module/components/rich-text/native/get-format-colors.native.js +34 -0
  312. package/build-module/components/rich-text/native/get-format-colors.native.js.map +1 -0
  313. package/build-module/components/rich-text/native/index.js +2 -0
  314. package/build-module/components/rich-text/native/index.js.map +1 -0
  315. package/build-module/components/rich-text/native/index.native.js +1179 -0
  316. package/build-module/components/rich-text/native/index.native.js.map +1 -0
  317. package/build-module/components/rich-text/native/toolbar-button-with-options.native.js +51 -0
  318. package/build-module/components/rich-text/native/toolbar-button-with-options.native.js.map +1 -0
  319. package/build-module/components/rich-text/native/use-format-types.js +104 -0
  320. package/build-module/components/rich-text/native/use-format-types.js.map +1 -0
  321. package/build-module/components/rich-text/use-input-rules.js +31 -2
  322. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  323. package/build-module/components/rich-text/use-paste-handler.js +2 -5
  324. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  325. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
  326. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  327. package/build-module/components/url-popover/image-url-input-ui.js +2 -1
  328. package/build-module/components/url-popover/image-url-input-ui.js.map +1 -1
  329. package/build-module/components/use-block-drop-zone/index.js +4 -1
  330. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  331. package/build-module/components/use-moving-animation/index.js +2 -1
  332. package/build-module/components/use-moving-animation/index.js.map +1 -1
  333. package/build-module/components/use-settings/index.js +2 -2
  334. package/build-module/components/use-settings/index.js.map +1 -1
  335. package/build-module/components/writing-flow/use-tab-nav.js +7 -3
  336. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  337. package/build-module/hooks/align.js +8 -8
  338. package/build-module/hooks/align.js.map +1 -1
  339. package/build-module/hooks/align.native.js +2 -2
  340. package/build-module/hooks/align.native.js.map +1 -1
  341. package/build-module/hooks/anchor.js +5 -4
  342. package/build-module/hooks/anchor.js.map +1 -1
  343. package/build-module/hooks/background.js +17 -5
  344. package/build-module/hooks/background.js.map +1 -1
  345. package/build-module/hooks/block-hooks.js +5 -6
  346. package/build-module/hooks/block-hooks.js.map +1 -1
  347. package/build-module/hooks/block-renaming.js +40 -0
  348. package/build-module/hooks/block-renaming.js.map +1 -1
  349. package/build-module/hooks/content-lock-ui.js +3 -3
  350. package/build-module/hooks/content-lock-ui.js.map +1 -1
  351. package/build-module/hooks/custom-class-name.js +6 -5
  352. package/build-module/hooks/custom-class-name.js.map +1 -1
  353. package/build-module/hooks/custom-fields.js +57 -52
  354. package/build-module/hooks/custom-fields.js.map +1 -1
  355. package/build-module/hooks/duotone.js +10 -21
  356. package/build-module/hooks/duotone.js.map +1 -1
  357. package/build-module/hooks/index.js +0 -1
  358. package/build-module/hooks/index.js.map +1 -1
  359. package/build-module/hooks/layout.js +103 -93
  360. package/build-module/hooks/layout.js.map +1 -1
  361. package/build-module/hooks/position.js +11 -10
  362. package/build-module/hooks/position.js.map +1 -1
  363. package/build-module/hooks/style.js +10 -13
  364. package/build-module/hooks/style.js.map +1 -1
  365. package/build-module/hooks/utils.js +30 -1
  366. package/build-module/hooks/utils.js.map +1 -1
  367. package/build-module/layouts/constrained.js +4 -3
  368. package/build-module/layouts/constrained.js.map +1 -1
  369. package/build-module/private-apis.js +4 -1
  370. package/build-module/private-apis.js.map +1 -1
  371. package/build-module/store/actions.js +29 -37
  372. package/build-module/store/actions.js.map +1 -1
  373. package/build-module/store/reducer.js +17 -0
  374. package/build-module/store/reducer.js.map +1 -1
  375. package/build-module/store/selectors.js +17 -13
  376. package/build-module/store/selectors.js.map +1 -1
  377. package/build-module/utils/transform-styles/index.js +24 -7
  378. package/build-module/utils/transform-styles/index.js.map +1 -1
  379. package/build-style/content-rtl.css +6 -6
  380. package/build-style/content.css +6 -6
  381. package/build-style/style-rtl.css +26 -20
  382. package/build-style/style.css +26 -20
  383. package/package.json +31 -31
  384. package/src/components/block-heading-level-dropdown/index.js +1 -1
  385. package/src/components/block-list/block.native.js +2 -0
  386. package/src/components/block-list/index.js +4 -18
  387. package/src/components/block-list-appender/index.js +20 -4
  388. package/src/components/block-parent-selector/index.js +1 -1
  389. package/src/components/block-pattern-setup/index.js +38 -22
  390. package/src/components/block-pattern-setup/setup-toolbar.js +2 -0
  391. package/src/components/block-pattern-setup/style.scss +4 -1
  392. package/src/components/block-patterns-list/README.md +4 -4
  393. package/src/components/block-patterns-list/index.js +60 -34
  394. package/src/components/block-patterns-list/style.scss +7 -0
  395. package/src/components/block-quick-navigation/index.js +11 -5
  396. package/src/components/block-rename/index.js +3 -0
  397. package/src/components/block-rename/is-empty-string.js +3 -0
  398. package/src/components/block-rename/modal.js +115 -0
  399. package/src/components/block-rename/rename-control.js +80 -0
  400. package/src/components/block-rename/use-block-rename.js +10 -0
  401. package/src/components/block-settings-menu/block-settings-dropdown.js +38 -34
  402. package/src/components/block-settings-menu-controls/index.js +9 -0
  403. package/src/components/block-styles/index.js +0 -10
  404. package/src/components/block-switcher/pattern-transformations-menu.js +20 -14
  405. package/src/components/block-toolbar/block-toolbar-menu.native.js +1 -4
  406. package/src/components/block-toolbar/style.scss +8 -0
  407. package/src/components/block-tools/back-compat.js +1 -1
  408. package/src/components/block-tools/block-contextual-toolbar.js +11 -134
  409. package/src/components/block-tools/empty-block-inserter.js +56 -0
  410. package/src/components/block-tools/index.js +72 -16
  411. package/src/components/block-tools/selected-block-tools.js +127 -0
  412. package/src/components/block-tools/style.scss +0 -10
  413. package/src/components/block-tools/use-selected-block-tool-props.js +66 -0
  414. package/src/components/block-types-list/index.js +5 -4
  415. package/src/components/button-block-appender/content.scss +2 -2
  416. package/src/components/date-format-picker/index.js +7 -0
  417. package/src/components/editable-text/README.md +0 -36
  418. package/src/components/editable-text/index.js +1 -8
  419. package/src/components/global-styles/advanced-panel.js +1 -1
  420. package/src/components/iframe/index.js +4 -3
  421. package/src/components/image-size-control/index.js +0 -6
  422. package/src/components/inner-blocks/index.js +6 -2
  423. package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +57 -33
  424. package/src/components/inserter/block-patterns-explorer/{explorer.js → index.js} +4 -4
  425. package/src/components/inserter/block-patterns-explorer/{patterns-list.js → pattern-list.js} +9 -2
  426. package/src/components/inserter/block-patterns-tab/index.js +118 -0
  427. package/src/components/inserter/block-patterns-tab/pattern-category-preview-panel.js +48 -0
  428. package/src/components/inserter/block-patterns-tab/pattern-category-previews.js +179 -0
  429. package/src/components/inserter/{block-patterns-filter.js → block-patterns-tab/patterns-filter.js} +15 -21
  430. package/src/components/inserter/block-patterns-tab/use-pattern-categories.js +101 -0
  431. package/src/components/inserter/block-patterns-tab/utils.js +78 -0
  432. package/src/components/inserter/hooks/use-patterns-state.js +3 -1
  433. package/src/components/inserter/media-tab/media-list.js +7 -7
  434. package/src/components/inserter/media-tab/media-preview.js +27 -22
  435. package/src/components/inserter/menu.js +4 -5
  436. package/src/components/inserter-listbox/index.js +11 -7
  437. package/src/components/inserter-listbox/item.js +11 -12
  438. package/src/components/inserter-listbox/row.js +6 -12
  439. package/src/components/link-control/README.md +2 -2
  440. package/src/components/link-control/index.js +15 -6
  441. package/src/components/link-control/style.scss +8 -5
  442. package/src/components/list-view/block-select-button.js +44 -1
  443. package/src/components/list-view/block.js +11 -11
  444. package/src/components/list-view/index.js +2 -0
  445. package/src/components/list-view/use-list-view-expand-selected-item.js +7 -8
  446. package/src/components/media-replace-flow/style.scss +2 -2
  447. package/src/components/navigable-toolbar/index.js +71 -25
  448. package/src/components/plain-text/README.md +2 -30
  449. package/src/components/preview-options/index.js +2 -0
  450. package/src/components/provider/use-block-sync.js +2 -21
  451. package/src/components/rich-text/README.md +6 -63
  452. package/src/components/rich-text/index.js +0 -1
  453. package/src/components/rich-text/index.native.js +4 -2
  454. package/src/components/rich-text/native/format-edit.js +44 -0
  455. package/src/components/rich-text/native/get-format-colors.native.js +54 -0
  456. package/src/components/rich-text/native/index.js +1 -0
  457. package/src/components/rich-text/native/index.native.js +1406 -0
  458. package/src/components/rich-text/native/style.native.scss +28 -0
  459. package/src/components/rich-text/native/test/__snapshots__/index.native.js.snap +79 -0
  460. package/src/components/rich-text/native/test/index.native.js +278 -0
  461. package/src/components/rich-text/native/test/performance/rich-text.native.js +44 -0
  462. package/src/components/rich-text/native/toolbar-button-with-options.native.js +61 -0
  463. package/src/components/rich-text/native/use-format-types.js +146 -0
  464. package/src/components/rich-text/use-input-rules.js +30 -2
  465. package/src/components/rich-text/use-paste-handler.js +1 -6
  466. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +1 -1
  467. package/src/components/url-input/README.md +1 -74
  468. package/src/components/url-popover/image-url-input-ui.js +1 -0
  469. package/src/components/use-block-drop-zone/index.js +4 -1
  470. package/src/components/use-moving-animation/index.js +1 -1
  471. package/src/components/use-settings/index.js +2 -2
  472. package/src/components/use-settings/test/index.js +1 -1
  473. package/src/components/writing-flow/use-tab-nav.js +8 -3
  474. package/src/hooks/align.js +8 -8
  475. package/src/hooks/align.native.js +2 -2
  476. package/src/hooks/anchor.js +21 -23
  477. package/src/hooks/background.js +28 -6
  478. package/src/hooks/block-hooks.js +20 -16
  479. package/src/hooks/block-renaming.js +47 -0
  480. package/src/hooks/content-lock-ui.js +3 -3
  481. package/src/hooks/custom-class-name.js +7 -6
  482. package/src/hooks/custom-fields.js +73 -70
  483. package/src/hooks/duotone.js +23 -33
  484. package/src/hooks/index.js +0 -1
  485. package/src/hooks/layout.js +126 -113
  486. package/src/hooks/position.js +8 -21
  487. package/src/hooks/style.js +17 -31
  488. package/src/hooks/test/__snapshots__/align.native.js.snap +5 -5
  489. package/src/hooks/test/align.js +4 -4
  490. package/src/hooks/utils.js +33 -1
  491. package/src/layouts/constrained.js +57 -50
  492. package/src/private-apis.js +4 -1
  493. package/src/store/actions.js +26 -72
  494. package/src/store/reducer.js +19 -0
  495. package/src/store/selectors.js +15 -19
  496. package/src/style.scss +1 -1
  497. package/src/utils/test/transform-styles.js +49 -0
  498. package/src/utils/transform-styles/index.js +39 -13
  499. package/build/components/block-tools/selected-block-popover.js +0 -221
  500. package/build/components/block-tools/selected-block-popover.js.map +0 -1
  501. package/build/components/inserter/block-patterns-explorer/explorer.js.map +0 -1
  502. package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +0 -1
  503. package/build/components/inserter/block-patterns-explorer/sidebar.js.map +0 -1
  504. package/build/components/inserter/block-patterns-filter.js.map +0 -1
  505. package/build/components/inserter/block-patterns-tab.js +0 -270
  506. package/build/components/inserter/block-patterns-tab.js.map +0 -1
  507. package/build/hooks/block-rename-ui.js +0 -165
  508. package/build/hooks/block-rename-ui.js.map +0 -1
  509. package/build/store/utils.js +0 -22
  510. package/build/store/utils.js.map +0 -1
  511. package/build-module/components/block-tools/selected-block-popover.js +0 -213
  512. package/build-module/components/block-tools/selected-block-popover.js.map +0 -1
  513. package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +0 -1
  514. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +0 -1
  515. package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +0 -1
  516. package/build-module/components/inserter/block-patterns-filter.js.map +0 -1
  517. package/build-module/components/inserter/block-patterns-tab.js +0 -254
  518. package/build-module/components/inserter/block-patterns-tab.js.map +0 -1
  519. package/build-module/hooks/block-rename-ui.js +0 -157
  520. package/build-module/hooks/block-rename-ui.js.map +0 -1
  521. package/build-module/store/utils.js +0 -16
  522. package/build-module/store/utils.js.map +0 -1
  523. package/src/components/block-tools/selected-block-popover.js +0 -265
  524. package/src/components/inserter/block-patterns-tab.js +0 -448
  525. package/src/hooks/block-rename-ui.js +0 -226
  526. package/src/store/utils.js +0 -12
  527. /package/src/{hooks/block-rename-ui.scss → components/block-rename/style.scss} +0 -0
  528. /package/src/components/inserter/block-patterns-explorer/{sidebar.js → pattern-explorer-sidebar.js} +0 -0
@@ -83,8 +83,8 @@ export function addAttribute(settings) {
83
83
  ...settings.attributes,
84
84
  align: {
85
85
  type: 'string',
86
- // Allow for '' since it is used by updateAlignment function
87
- // in withToolbarControls for special cases with defined default values.
86
+ // Allow for '' since it is used by the `updateAlignment` function
87
+ // in toolbar controls for special cases with defined default values.
88
88
  enum: [...ALL_ALIGNMENTS, '']
89
89
  }
90
90
  };
@@ -98,7 +98,7 @@ function BlockEditAlignmentToolbarControls({
98
98
  }) {
99
99
  // Compute the block valid alignments by taking into account,
100
100
  // if the theme supports wide alignments or not and the layout's
101
- // availble alignments. We do that for conditionally rendering
101
+ // available alignments. We do that for conditionally rendering
102
102
  // Slot.
103
103
  const blockAllowedAlignments = getValidAlignments(getBlockSupport(blockName, 'align'), hasBlockSupport(blockName, 'alignWide', true));
104
104
  const validAlignments = useAvailableAlignments(blockAllowedAlignments).map(({
@@ -138,7 +138,7 @@ function BlockEditAlignmentToolbarControls({
138
138
  *
139
139
  * @return {Function} Wrapped component.
140
140
  */
141
- export const withToolbarControls = createHigherOrderComponent(BlockEdit => props => {
141
+ export const withAlignmentControls = createHigherOrderComponent(BlockEdit => props => {
142
142
  const hasAlignmentSupport = hasBlockSupport(props.name, 'align', false);
143
143
  return createElement(Fragment, null, hasAlignmentSupport && createElement(BlockEditAlignmentToolbarControls, {
144
144
  blockName: props.name,
@@ -148,7 +148,7 @@ export const withToolbarControls = createHigherOrderComponent(BlockEdit => props
148
148
  key: "edit",
149
149
  ...props
150
150
  }));
151
- }, 'withToolbarControls');
151
+ }, 'withAlignmentControls');
152
152
  function BlockListBlockWithDataAlign({
153
153
  block: BlockListBlock,
154
154
  props
@@ -222,8 +222,8 @@ export function addAssignedAlign(props, blockType, attributes) {
222
222
  }
223
223
  return props;
224
224
  }
225
- addFilter('blocks.registerBlockType', 'core/align/addAttribute', addAttribute);
225
+ addFilter('blocks.registerBlockType', 'core/editor/align/addAttribute', addAttribute);
226
226
  addFilter('editor.BlockListBlock', 'core/editor/align/with-data-align', withDataAlign);
227
- addFilter('editor.BlockEdit', 'core/editor/align/with-toolbar-controls', withToolbarControls);
228
- addFilter('blocks.getSaveContent.extraProps', 'core/align/addAssignedAlign', addAssignedAlign);
227
+ addFilter('editor.BlockEdit', 'core/editor/align/with-toolbar-controls', withAlignmentControls);
228
+ addFilter('blocks.getSaveContent.extraProps', 'core/editor/align/addAssignedAlign', addAssignedAlign);
229
229
  //# sourceMappingURL=align.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["classnames","createHigherOrderComponent","addFilter","getBlockSupport","getBlockType","hasBlockSupport","BlockControls","BlockAlignmentControl","useAvailableAlignments","useBlockEditingMode","ALL_ALIGNMENTS","WIDE_ALIGNMENTS","getValidAlignments","blockAlign","hasWideBlockSupport","hasWideEnabled","validAlignments","Array","isArray","filter","value","includes","alignment","addAttribute","settings","_settings$attributes$","attributes","align","type","enum","BlockEditAlignmentToolbarControls","blockName","setAttributes","blockAllowedAlignments","map","name","blockEditingMode","length","updateAlignment","nextAlign","blockType","blockDefaultAlign","default","createElement","group","__experimentalShareWithChildBlocks","onChange","controls","withToolbarControls","BlockEdit","props","hasAlignmentSupport","Fragment","key","BlockListBlockWithDataAlign","block","BlockListBlock","wrapperProps","some","withDataAlign","undefined","addAssignedAlign","isAlignValid","className"],"sources":["@wordpress/block-editor/src/hooks/align.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockSupport,\n\tgetBlockType,\n\thasBlockSupport,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { BlockControls, BlockAlignmentControl } from '../components';\nimport useAvailableAlignments from '../components/block-alignment-control/use-available-alignments';\nimport { useBlockEditingMode } from '../components/block-editing-mode';\n\n/**\n * An array which includes all possible valid alignments,\n * used to validate if an alignment is valid or not.\n *\n * @constant\n * @type {string[]}\n */\nconst ALL_ALIGNMENTS = [ 'left', 'center', 'right', 'wide', 'full' ];\n\n/**\n * An array which includes all wide alignments.\n * In order for this alignments to be valid they need to be supported by the block,\n * and by the theme.\n *\n * @constant\n * @type {string[]}\n */\nconst WIDE_ALIGNMENTS = [ 'wide', 'full' ];\n\n/**\n * Returns the valid alignments.\n * Takes into consideration the aligns supported by a block, if the block supports wide controls or not and if theme supports wide controls or not.\n * Exported just for testing purposes, not exported outside the module.\n *\n * @param {?boolean|string[]} blockAlign Aligns supported by the block.\n * @param {?boolean} hasWideBlockSupport True if block supports wide alignments. And False otherwise.\n * @param {?boolean} hasWideEnabled True if theme supports wide alignments. And False otherwise.\n *\n * @return {string[]} Valid alignments.\n */\nexport function getValidAlignments(\n\tblockAlign,\n\thasWideBlockSupport = true,\n\thasWideEnabled = true\n) {\n\tlet validAlignments;\n\tif ( Array.isArray( blockAlign ) ) {\n\t\tvalidAlignments = ALL_ALIGNMENTS.filter( ( value ) =>\n\t\t\tblockAlign.includes( value )\n\t\t);\n\t} else if ( blockAlign === true ) {\n\t\t// `true` includes all alignments...\n\t\tvalidAlignments = [ ...ALL_ALIGNMENTS ];\n\t} else {\n\t\tvalidAlignments = [];\n\t}\n\n\tif (\n\t\t! hasWideEnabled ||\n\t\t( blockAlign === true && ! hasWideBlockSupport )\n\t) {\n\t\treturn validAlignments.filter(\n\t\t\t( alignment ) => ! WIDE_ALIGNMENTS.includes( alignment )\n\t\t);\n\t}\n\n\treturn validAlignments;\n}\n\n/**\n * Filters registered block settings, extending attributes to include `align`.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( 'type' in ( settings.attributes?.align ?? {} ) ) {\n\t\treturn settings;\n\t}\n\tif ( hasBlockSupport( settings, 'align' ) ) {\n\t\t// Gracefully handle if settings.attributes is undefined.\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\talign: {\n\t\t\t\ttype: 'string',\n\t\t\t\t// Allow for '' since it is used by updateAlignment function\n\t\t\t\t// in withToolbarControls for special cases with defined default values.\n\t\t\t\tenum: [ ...ALL_ALIGNMENTS, '' ],\n\t\t\t},\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nfunction BlockEditAlignmentToolbarControls( {\n\tblockName,\n\tattributes,\n\tsetAttributes,\n} ) {\n\t// Compute the block valid alignments by taking into account,\n\t// if the theme supports wide alignments or not and the layout's\n\t// availble alignments. We do that for conditionally rendering\n\t// Slot.\n\tconst blockAllowedAlignments = getValidAlignments(\n\t\tgetBlockSupport( blockName, 'align' ),\n\t\thasBlockSupport( blockName, 'alignWide', true )\n\t);\n\n\tconst validAlignments = useAvailableAlignments(\n\t\tblockAllowedAlignments\n\t).map( ( { name } ) => name );\n\tconst blockEditingMode = useBlockEditingMode();\n\tif ( ! validAlignments.length || blockEditingMode !== 'default' ) {\n\t\treturn null;\n\t}\n\n\tconst updateAlignment = ( nextAlign ) => {\n\t\tif ( ! nextAlign ) {\n\t\t\tconst blockType = getBlockType( blockName );\n\t\t\tconst blockDefaultAlign = blockType?.attributes?.align?.default;\n\t\t\tif ( blockDefaultAlign ) {\n\t\t\t\tnextAlign = '';\n\t\t\t}\n\t\t}\n\t\tsetAttributes( { align: nextAlign } );\n\t};\n\n\treturn (\n\t\t<BlockControls group=\"block\" __experimentalShareWithChildBlocks>\n\t\t\t<BlockAlignmentControl\n\t\t\t\tvalue={ attributes.align }\n\t\t\t\tonChange={ updateAlignment }\n\t\t\t\tcontrols={ validAlignments }\n\t\t\t/>\n\t\t</BlockControls>\n\t);\n}\n\n/**\n * Override the default edit UI to include new toolbar controls for block\n * alignment, if block defines support.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withToolbarControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst hasAlignmentSupport = hasBlockSupport(\n\t\t\tprops.name,\n\t\t\t'align',\n\t\t\tfalse\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ hasAlignmentSupport && (\n\t\t\t\t\t<BlockEditAlignmentToolbarControls\n\t\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\t\tattributes={ props.attributes }\n\t\t\t\t\t\tsetAttributes={ props.setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\nfunction BlockListBlockWithDataAlign( { block: BlockListBlock, props } ) {\n\tconst { name, attributes } = props;\n\tconst { align } = attributes;\n\tconst blockAllowedAlignments = getValidAlignments(\n\t\tgetBlockSupport( name, 'align' ),\n\t\thasBlockSupport( name, 'alignWide', true )\n\t);\n\tconst validAlignments = useAvailableAlignments( blockAllowedAlignments );\n\n\tlet wrapperProps = props.wrapperProps;\n\tif ( validAlignments.some( ( alignment ) => alignment.name === align ) ) {\n\t\twrapperProps = { ...wrapperProps, 'data-align': align };\n\t}\n\n\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n}\n\n/**\n * Override the default block element to add alignment wrapper props.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withDataAlign = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\t// If an alignment is not assigned, there's no need to go through the\n\t\t// effort to validate or assign its value.\n\t\tif ( props.attributes.align === undefined ) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\treturn (\n\t\t\t<BlockListBlockWithDataAlign\n\t\t\t\tblock={ BlockListBlock }\n\t\t\t\tprops={ props }\n\t\t\t/>\n\t\t);\n\t},\n\t'withDataAlign'\n);\n\n/**\n * Override props assigned to save component to inject alignment class name if\n * block supports it.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addAssignedAlign( props, blockType, attributes ) {\n\tconst { align } = attributes;\n\tconst blockAlign = getBlockSupport( blockType, 'align' );\n\tconst hasWideBlockSupport = hasBlockSupport( blockType, 'alignWide', true );\n\n\t// Compute valid alignments without taking into account if\n\t// the theme supports wide alignments or not.\n\t// This way changing themes does not impact the block save.\n\tconst isAlignValid = getValidAlignments(\n\t\tblockAlign,\n\t\thasWideBlockSupport\n\t).includes( align );\n\tif ( isAlignValid ) {\n\t\tprops.className = classnames( `align${ align }`, props.className );\n\t}\n\n\treturn props;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/align/addAttribute',\n\taddAttribute\n);\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/align/with-data-align',\n\twithDataAlign\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/align/with-toolbar-controls',\n\twithToolbarControls\n);\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/align/addAssignedAlign',\n\taddAssignedAlign\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SACCC,eAAe,EACfC,YAAY,EACZC,eAAe,QACT,mBAAmB;;AAE1B;AACA;AACA;AACA,SAASC,aAAa,EAAEC,qBAAqB,QAAQ,eAAe;AACpE,OAAOC,sBAAsB,MAAM,gEAAgE;AACnG,SAASC,mBAAmB,QAAQ,kCAAkC;;AAEtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,cAAc,GAAG,CAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAE;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,eAAe,GAAG,CAAE,MAAM,EAAE,MAAM,CAAE;;AAE1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CACjCC,UAAU,EACVC,mBAAmB,GAAG,IAAI,EAC1BC,cAAc,GAAG,IAAI,EACpB;EACD,IAAIC,eAAe;EACnB,IAAK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KAAK,EAAGA;EAAO,CACf,CAAC;AAEJ,CAAC,EACD,eACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASW,gBAAgBA,CAAEX,KAAK,EAAEV,SAAS,EAAEd,UAAU,EAAG;EAChE,MAAM;IAAEC;EAAM,CAAC,GAAGD,UAAU;EAC5B,MAAMb,UAAU,GAAGV,eAAe,CAAEqC,SAAS,EAAE,OAAQ,CAAC;EACxD,MAAM1B,mBAAmB,GAAGT,eAAe,CAAEmC,SAAS,EAAE,WAAW,EAAE,IAAK,CAAC;;EAE3E;EACA;EACA;EACA,MAAMsB,YAAY,GAAGlD,kBAAkB,CACtCC,UAAU,EACVC,mBACD,CAAC,CAACO,QAAQ,CAAEM,KAAM,CAAC;EACnB,IAAKmC,YAAY,EAAG;IACnBZ,KAAK,CAACa,SAAS,GAAG/D,UAAU,CAAG,QAAQ2B,KAAO,EAAC,EAAEuB,KAAK,CAACa,SAAU,CAAC;EACnE;EAEA,OAAOb,KAAK;AACb;AAEAhD,SAAS,CACR,0BAA0B,EAC1B,yBAAyB,EACzBqB,YACD,CAAC;AACDrB,SAAS,CACR,uBAAuB,EACvB,mCAAmC,EACnCyD,aACD,CAAC;AACDzD,SAAS,CACR,kBAAkB,EAClB,yCAAyC,EACzC8C,mBACD,CAAC;AACD9C,SAAS,CACR,kCAAkC,EAClC,6BAA6B,EAC7B2D,gBACD,CAAC"}
1
+ {"version":3,"names":["classnames","createHigherOrderComponent","addFilter","getBlockSupport","getBlockType","hasBlockSupport","BlockControls","BlockAlignmentControl","useAvailableAlignments","useBlockEditingMode","ALL_ALIGNMENTS","WIDE_ALIGNMENTS","getValidAlignments","blockAlign","hasWideBlockSupport","hasWideEnabled","validAlignments","Array","isArray","filter","value","includes","alignment","addAttribute","settings","_settings$attributes$","attributes","align","type","enum","BlockEditAlignmentToolbarControls","blockName","setAttributes","blockAllowedAlignments","map","name","blockEditingMode","length","updateAlignment","nextAlign","blockType","blockDefaultAlign","default","createElement","group","__experimentalShareWithChildBlocks","onChange","controls","withAlignmentControls","BlockEdit","props","hasAlignmentSupport","Fragment","key","BlockListBlockWithDataAlign","block","BlockListBlock","wrapperProps","some","withDataAlign","undefined","addAssignedAlign","isAlignValid","className"],"sources":["@wordpress/block-editor/src/hooks/align.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\nimport {\n\tgetBlockSupport,\n\tgetBlockType,\n\thasBlockSupport,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { BlockControls, BlockAlignmentControl } from '../components';\nimport useAvailableAlignments from '../components/block-alignment-control/use-available-alignments';\nimport { useBlockEditingMode } from '../components/block-editing-mode';\n\n/**\n * An array which includes all possible valid alignments,\n * used to validate if an alignment is valid or not.\n *\n * @constant\n * @type {string[]}\n */\nconst ALL_ALIGNMENTS = [ 'left', 'center', 'right', 'wide', 'full' ];\n\n/**\n * An array which includes all wide alignments.\n * In order for this alignments to be valid they need to be supported by the block,\n * and by the theme.\n *\n * @constant\n * @type {string[]}\n */\nconst WIDE_ALIGNMENTS = [ 'wide', 'full' ];\n\n/**\n * Returns the valid alignments.\n * Takes into consideration the aligns supported by a block, if the block supports wide controls or not and if theme supports wide controls or not.\n * Exported just for testing purposes, not exported outside the module.\n *\n * @param {?boolean|string[]} blockAlign Aligns supported by the block.\n * @param {?boolean} hasWideBlockSupport True if block supports wide alignments. And False otherwise.\n * @param {?boolean} hasWideEnabled True if theme supports wide alignments. And False otherwise.\n *\n * @return {string[]} Valid alignments.\n */\nexport function getValidAlignments(\n\tblockAlign,\n\thasWideBlockSupport = true,\n\thasWideEnabled = true\n) {\n\tlet validAlignments;\n\tif ( Array.isArray( blockAlign ) ) {\n\t\tvalidAlignments = ALL_ALIGNMENTS.filter( ( value ) =>\n\t\t\tblockAlign.includes( value )\n\t\t);\n\t} else if ( blockAlign === true ) {\n\t\t// `true` includes all alignments...\n\t\tvalidAlignments = [ ...ALL_ALIGNMENTS ];\n\t} else {\n\t\tvalidAlignments = [];\n\t}\n\n\tif (\n\t\t! hasWideEnabled ||\n\t\t( blockAlign === true && ! hasWideBlockSupport )\n\t) {\n\t\treturn validAlignments.filter(\n\t\t\t( alignment ) => ! WIDE_ALIGNMENTS.includes( alignment )\n\t\t);\n\t}\n\n\treturn validAlignments;\n}\n\n/**\n * Filters registered block settings, extending attributes to include `align`.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( 'type' in ( settings.attributes?.align ?? {} ) ) {\n\t\treturn settings;\n\t}\n\tif ( hasBlockSupport( settings, 'align' ) ) {\n\t\t// Gracefully handle if settings.attributes is undefined.\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\talign: {\n\t\t\t\ttype: 'string',\n\t\t\t\t// Allow for '' since it is used by the `updateAlignment` function\n\t\t\t\t// in toolbar controls for special cases with defined default values.\n\t\t\t\tenum: [ ...ALL_ALIGNMENTS, '' ],\n\t\t\t},\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nfunction BlockEditAlignmentToolbarControls( {\n\tblockName,\n\tattributes,\n\tsetAttributes,\n} ) {\n\t// Compute the block valid alignments by taking into account,\n\t// if the theme supports wide alignments or not and the layout's\n\t// available alignments. We do that for conditionally rendering\n\t// Slot.\n\tconst blockAllowedAlignments = getValidAlignments(\n\t\tgetBlockSupport( blockName, 'align' ),\n\t\thasBlockSupport( blockName, 'alignWide', true )\n\t);\n\n\tconst validAlignments = useAvailableAlignments(\n\t\tblockAllowedAlignments\n\t).map( ( { name } ) => name );\n\tconst blockEditingMode = useBlockEditingMode();\n\tif ( ! validAlignments.length || blockEditingMode !== 'default' ) {\n\t\treturn null;\n\t}\n\n\tconst updateAlignment = ( nextAlign ) => {\n\t\tif ( ! nextAlign ) {\n\t\t\tconst blockType = getBlockType( blockName );\n\t\t\tconst blockDefaultAlign = blockType?.attributes?.align?.default;\n\t\t\tif ( blockDefaultAlign ) {\n\t\t\t\tnextAlign = '';\n\t\t\t}\n\t\t}\n\t\tsetAttributes( { align: nextAlign } );\n\t};\n\n\treturn (\n\t\t<BlockControls group=\"block\" __experimentalShareWithChildBlocks>\n\t\t\t<BlockAlignmentControl\n\t\t\t\tvalue={ attributes.align }\n\t\t\t\tonChange={ updateAlignment }\n\t\t\t\tcontrols={ validAlignments }\n\t\t\t/>\n\t\t</BlockControls>\n\t);\n}\n\n/**\n * Override the default edit UI to include new toolbar controls for block\n * alignment, if block defines support.\n *\n * @param {Function} BlockEdit Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withAlignmentControls = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst hasAlignmentSupport = hasBlockSupport(\n\t\t\tprops.name,\n\t\t\t'align',\n\t\t\tfalse\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ hasAlignmentSupport && (\n\t\t\t\t\t<BlockEditAlignmentToolbarControls\n\t\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\t\tattributes={ props.attributes }\n\t\t\t\t\t\tsetAttributes={ props.setAttributes }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withAlignmentControls'\n);\n\nfunction BlockListBlockWithDataAlign( { block: BlockListBlock, props } ) {\n\tconst { name, attributes } = props;\n\tconst { align } = attributes;\n\tconst blockAllowedAlignments = getValidAlignments(\n\t\tgetBlockSupport( name, 'align' ),\n\t\thasBlockSupport( name, 'alignWide', true )\n\t);\n\tconst validAlignments = useAvailableAlignments( blockAllowedAlignments );\n\n\tlet wrapperProps = props.wrapperProps;\n\tif ( validAlignments.some( ( alignment ) => alignment.name === align ) ) {\n\t\twrapperProps = { ...wrapperProps, 'data-align': align };\n\t}\n\n\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n}\n\n/**\n * Override the default block element to add alignment wrapper props.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withDataAlign = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\t// If an alignment is not assigned, there's no need to go through the\n\t\t// effort to validate or assign its value.\n\t\tif ( props.attributes.align === undefined ) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\treturn (\n\t\t\t<BlockListBlockWithDataAlign\n\t\t\t\tblock={ BlockListBlock }\n\t\t\t\tprops={ props }\n\t\t\t/>\n\t\t);\n\t},\n\t'withDataAlign'\n);\n\n/**\n * Override props assigned to save component to inject alignment class name if\n * block supports it.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addAssignedAlign( props, blockType, attributes ) {\n\tconst { align } = attributes;\n\tconst blockAlign = getBlockSupport( blockType, 'align' );\n\tconst hasWideBlockSupport = hasBlockSupport( blockType, 'alignWide', true );\n\n\t// Compute valid alignments without taking into account if\n\t// the theme supports wide alignments or not.\n\t// This way changing themes does not impact the block save.\n\tconst isAlignValid = getValidAlignments(\n\t\tblockAlign,\n\t\thasWideBlockSupport\n\t).includes( align );\n\tif ( isAlignValid ) {\n\t\tprops.className = classnames( `align${ align }`, props.className );\n\t}\n\n\treturn props;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/editor/align/addAttribute',\n\taddAttribute\n);\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/editor/align/with-data-align',\n\twithDataAlign\n);\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/align/with-toolbar-controls',\n\twithAlignmentControls\n);\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/editor/align/addAssignedAlign',\n\taddAssignedAlign\n);\n"],"mapp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nB,IAAKmC,YAAY,EAAG;IACnBZ,KAAK,CAACa,SAAS,GAAG/D,UAAU,CAAG,QAAQ2B,KAAO,EAAC,EAAEuB,KAAK,CAACa,SAAU,CAAC;EACnE;EAEA,OAAOb,KAAK;AACb;AAEAhD,SAAS,CACR,0BAA0B,EAC1B,gCAAgC,EAChCqB,YACD,CAAC;AACDrB,SAAS,CACR,uBAAuB,EACvB,mCAAmC,EACnCyD,aACD,CAAC;AACDzD,SAAS,CACR,kBAAkB,EAClB,yCAAyC,EACzC8C,qBACD,CAAC;AACD9C,SAAS,CACR,kCAAkC,EAClC,oCAAoC,EACpC2D,gBACD,CAAC"}
@@ -20,8 +20,8 @@ addFilter('blocks.registerBlockType', 'core/react-native-editor/align', (setting
20
20
  ...settings.attributes,
21
21
  align: {
22
22
  type: 'string',
23
- // Allow for '' since it is used by updateAlignment function
24
- // in withToolbarControls for special cases with defined default values.
23
+ // Allow for '' since it is used by the `updateAlignment` function
24
+ // in toolbar controls for special cases with defined default values.
25
25
  enum: [...ALIGNMENTS, '']
26
26
  }
27
27
  };
@@ -1 +1 @@
1
- {"version":3,"names":["addFilter","hasBlockSupport","WIDE_ALIGNMENTS","ALIGNMENTS","settings","name","excludeBlocks","includes","blockAlign","supports","align","Array","isArray","filter","alignment","Object","values","alignments","alignWide","attributes","type","enum"],"sources":["@wordpress/block-editor/src/hooks/align.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { WIDE_ALIGNMENTS } from '@wordpress/components';\n\nconst ALIGNMENTS = [ 'left', 'center', 'right' ];\n\nexport * from './align.js';\n\n// Used to filter out blocks that don't support wide/full alignment on mobile\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/react-native-editor/align',\n\t( settings, name ) => {\n\t\tif (\n\t\t\tWIDE_ALIGNMENTS.excludeBlocks.includes( name ) &&\n\t\t\thasBlockSupport( settings, 'align' )\n\t\t) {\n\t\t\tconst blockAlign = settings.supports.align;\n\n\t\t\tsettings.supports = {\n\t\t\t\t...settings.supports,\n\t\t\t\talign: Array.isArray( blockAlign )\n\t\t\t\t\t? blockAlign.filter(\n\t\t\t\t\t\t\t( alignment ) =>\n\t\t\t\t\t\t\t\t! Object.values(\n\t\t\t\t\t\t\t\t\tWIDE_ALIGNMENTS.alignments\n\t\t\t\t\t\t\t\t).includes( alignment )\n\t\t\t\t\t )\n\t\t\t\t\t: blockAlign,\n\t\t\t\talignWide: false,\n\t\t\t};\n\t\t\tsettings.attributes = {\n\t\t\t\t...settings.attributes,\n\t\t\t\talign: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\t// Allow for '' since it is used by updateAlignment function\n\t\t\t\t\t// in withToolbarControls for special cases with defined default values.\n\t\t\t\t\tenum: [ ...ALIGNMENTS, '' ],\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn settings;\n\t}\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,eAAe,QAAQ,uBAAuB;AAEvD,MAAMC,UAAU,GAAG,CAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAE;AAEhD,cAAc,YAAY;;AAE1B;AACAH,SAAS,CACR,0BAA0B,EAC1B,gCAAgC,EAChC,CAAEI,QAAQ,EAAEC,IAAI,KAAM;EACrB,IACCH,eAAe,CAACI,aAAa,CAACC,QAAQ,CAAEF,IAAK,CAAC,IAC9CJ,eAAe,CAAEG,QAAQ,EAAE,OAAQ,CAAC,EACnC;IACD,MAAMI,UAAU,GAAGJ,QAAQ,CAACK,QAAQ,CAACC,KAAK;IAE1CN,QAAQ,CAACK,QAAQ,GAAG;MACnB,GAAGL,QAAQ,CAACK,QAAQ;MACpBC,KAAK,EAAEC,KAAK,CAACC,OAAO,CAAEJ,UAAW,CAAC,GAC/BA,UAAU,CAACK,MAAM,CACfC,SAAS,IACV,CAAEC,MAAM,CAACC,MAAM,CACdd,eAAe,CAACe,UACjB,CAAC,CAACV,QAAQ,CAAEO,SAAU,CACvB,CAAC,GACDN,UAAU;MACbU,SAAS,EAAE;IACZ,CAAC;IACDd,QAAQ,CAACe,UAAU,GAAG;MACrB,GAAGf,QAAQ,CAACe,UAAU;MACtBT,KAAK,EAAE;QACNU,IAAI,EAAE,QAAQ;QACd;QACA;QACAC,IAAI,EAAE,CAAE,GAAGlB,UAAU,EAAE,EAAE;MAC1B;IACD,CAAC;EACF;EAEA,OAAOC,QAAQ;AAChB,CACD,CAAC"}
1
+ {"version":3,"names":["addFilter","hasBlockSupport","WIDE_ALIGNMENTS","ALIGNMENTS","settings","name","excludeBlocks","includes","blockAlign","supports","align","Array","isArray","filter","alignment","Object","values","alignments","alignWide","attributes","type","enum"],"sources":["@wordpress/block-editor/src/hooks/align.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { WIDE_ALIGNMENTS } from '@wordpress/components';\n\nconst ALIGNMENTS = [ 'left', 'center', 'right' ];\n\nexport * from './align.js';\n\n// Used to filter out blocks that don't support wide/full alignment on mobile\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/react-native-editor/align',\n\t( settings, name ) => {\n\t\tif (\n\t\t\tWIDE_ALIGNMENTS.excludeBlocks.includes( name ) &&\n\t\t\thasBlockSupport( settings, 'align' )\n\t\t) {\n\t\t\tconst blockAlign = settings.supports.align;\n\n\t\t\tsettings.supports = {\n\t\t\t\t...settings.supports,\n\t\t\t\talign: Array.isArray( blockAlign )\n\t\t\t\t\t? blockAlign.filter(\n\t\t\t\t\t\t\t( alignment ) =>\n\t\t\t\t\t\t\t\t! Object.values(\n\t\t\t\t\t\t\t\t\tWIDE_ALIGNMENTS.alignments\n\t\t\t\t\t\t\t\t).includes( alignment )\n\t\t\t\t\t )\n\t\t\t\t\t: blockAlign,\n\t\t\t\talignWide: false,\n\t\t\t};\n\t\t\tsettings.attributes = {\n\t\t\t\t...settings.attributes,\n\t\t\t\talign: {\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\t// Allow for '' since it is used by the `updateAlignment` function\n\t\t\t\t\t// in toolbar controls for special cases with defined default values.\n\t\t\t\t\tenum: [ ...ALIGNMENTS, '' ],\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn settings;\n\t}\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,eAAe,QAAQ,uBAAuB;AAEvD,MAAMC,UAAU,GAAG,CAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAE;AAEhD,cAAc,YAAY;;AAE1B;AACAH,SAAS,CACR,0BAA0B,EAC1B,gCAAgC,EAChC,CAAEI,QAAQ,EAAEC,IAAI,KAAM;EACrB,IACCH,eAAe,CAACI,aAAa,CAACC,QAAQ,CAAEF,IAAK,CAAC,IAC9CJ,eAAe,CAAEG,QAAQ,EAAE,OAAQ,CAAC,EACnC;IACD,MAAMI,UAAU,GAAGJ,QAAQ,CAACK,QAAQ,CAACC,KAAK;IAE1CN,QAAQ,CAACK,QAAQ,GAAG;MACnB,GAAGL,QAAQ,CAACK,QAAQ;MACpBC,KAAK,EAAEC,KAAK,CAACC,OAAO,CAAEJ,UAAW,CAAC,GAC/BA,UAAU,CAACK,MAAM,CACfC,SAAS,IACV,CAAEC,MAAM,CAACC,MAAM,CACdd,eAAe,CAACe,UACjB,CAAC,CAACV,QAAQ,CAAEO,SAAU,CACvB,CAAC,GACDN,UAAU;MACbU,SAAS,EAAE;IACZ,CAAC;IACDd,QAAQ,CAACe,UAAU,GAAG;MACrB,GAAGf,QAAQ,CAACe,UAAU;MACtBT,KAAK,EAAE;QACNU,IAAI,EAAE,QAAQ;QACd;QACA;QACAC,IAAI,EAAE,CAAE,GAAGlB,UAAU,EAAE,EAAE;MAC1B;IACD,CAAC;EACF;EAEA,OAAOC,QAAQ;AAChB,CACD,CAAC"}
@@ -60,6 +60,7 @@ function BlockEditAnchorControl({
60
60
  const isWeb = Platform.OS === 'web';
61
61
  const textControl = createElement(TextControl, {
62
62
  __nextHasNoMarginBottom: true,
63
+ __next40pxDefaultSize: true,
63
64
  className: "html-anchor-control",
64
65
  label: __('HTML anchor'),
65
66
  help: createElement(Fragment, null, __('Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'), isWeb && createElement(ExternalLink, {
@@ -91,7 +92,7 @@ function BlockEditAnchorControl({
91
92
  *
92
93
  * @return {Component} Wrapped component.
93
94
  */
94
- export const withInspectorControl = createHigherOrderComponent(BlockEdit => {
95
+ export const withAnchorControls = createHigherOrderComponent(BlockEdit => {
95
96
  return props => {
96
97
  return createElement(Fragment, null, createElement(BlockEdit, {
97
98
  ...props
@@ -101,7 +102,7 @@ export const withInspectorControl = createHigherOrderComponent(BlockEdit => {
101
102
  setAttributes: props.setAttributes
102
103
  }));
103
104
  };
104
- }, 'withInspectorControl');
105
+ }, 'withAnchorControls');
105
106
 
106
107
  /**
107
108
  * Override props assigned to save component to inject anchor ID, if block
@@ -121,6 +122,6 @@ export function addSaveProps(extraProps, blockType, attributes) {
121
122
  return extraProps;
122
123
  }
123
124
  addFilter('blocks.registerBlockType', 'core/anchor/attribute', addAttribute);
124
- addFilter('editor.BlockEdit', 'core/editor/anchor/with-inspector-control', withInspectorControl);
125
- addFilter('blocks.getSaveContent.extraProps', 'core/anchor/save-props', addSaveProps);
125
+ addFilter('editor.BlockEdit', 'core/editor/anchor/with-inspector-controls', withAnchorControls);
126
+ addFilter('blocks.getSaveContent.extraProps', 'core/editor/anchor/save-props', addSaveProps);
126
127
  //# sourceMappingURL=anchor.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["addFilter","PanelBody","TextControl","ExternalLink","__","hasBlockSupport","createHigherOrderComponent","Platform","InspectorControls","useBlockEditingMode","ANCHOR_REGEX","ANCHOR_SCHEMA","type","source","attribute","selector","addAttribute","settings","_settings$attributes$","attributes","anchor","BlockEditAnchorControl","blockName","setAttributes","blockEditingMode","isWeb","OS","textControl","createElement","__nextHasNoMarginBottom","className","label","help","Fragment","href","value","placeholder","onChange","nextValue","replace","autoCapitalize","autoComplete","group","title","withInspectorControl","BlockEdit","props","isSelected","name","addSaveProps","extraProps","blockType","id"],"sources":["@wordpress/block-editor/src/hooks/anchor.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { PanelBody, TextControl, ExternalLink } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { Platform } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { InspectorControls } from '../components';\nimport { useBlockEditingMode } from '../components/block-editing-mode';\n\n/**\n * Regular expression matching invalid anchor characters for replacement.\n *\n * @type {RegExp}\n */\nconst ANCHOR_REGEX = /[\\s#]/g;\n\nconst ANCHOR_SCHEMA = {\n\ttype: 'string',\n\tsource: 'attribute',\n\tattribute: 'id',\n\tselector: '*',\n};\n\n/**\n * Filters registered block settings, extending attributes with anchor using ID\n * of the first node.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( 'type' in ( settings.attributes?.anchor ?? {} ) ) {\n\t\treturn settings;\n\t}\n\tif ( hasBlockSupport( settings, 'anchor' ) ) {\n\t\t// Gracefully handle if settings.attributes is undefined.\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\tanchor: ANCHOR_SCHEMA,\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nfunction BlockEditAnchorControl( { blockName, attributes, setAttributes } ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst isWeb = Platform.OS === 'web';\n\tconst textControl = (\n\t\t<TextControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\tclassName=\"html-anchor-control\"\n\t\t\tlabel={ __( 'HTML anchor' ) }\n\t\t\thelp={\n\t\t\t\t<>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ isWeb && (\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t'https://wordpress.org/documentation/article/page-jumps/'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Learn more about anchors' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t}\n\t\t\tvalue={ attributes.anchor || '' }\n\t\t\tplaceholder={ ! isWeb ? __( 'Add an anchor' ) : null }\n\t\t\tonChange={ ( nextValue ) => {\n\t\t\t\tnextValue = nextValue.replace( ANCHOR_REGEX, '-' );\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tanchor: nextValue,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tautoCapitalize=\"none\"\n\t\t\tautoComplete=\"off\"\n\t\t/>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ isWeb && blockEditingMode === 'default' && (\n\t\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t\t{ textControl }\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * We plan to remove scoping anchors to 'core/heading' to support\n\t\t\t * anchors for all eligble blocks. Additionally we plan to explore\n\t\t\t * leveraging InspectorAdvancedControls instead of a custom\n\t\t\t * PanelBody title. https://github.com/WordPress/gutenberg/issues/28363\n\t\t\t */ }\n\t\t\t{ ! isWeb && blockName === 'core/heading' && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Heading settings' ) }>\n\t\t\t\t\t\t{ textControl }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning the anchor ID, if block supports anchor.\n *\n * @param {Component} BlockEdit Original component.\n *\n * @return {Component} Wrapped component.\n */\nexport const withInspectorControl = createHigherOrderComponent(\n\t( BlockEdit ) => {\n\t\treturn ( props ) => {\n\t\t\treturn (\n\t\t\t\t<>\n\t\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t\t{ props.isSelected &&\n\t\t\t\t\t\thasBlockSupport( props.name, 'anchor' ) && (\n\t\t\t\t\t\t\t<BlockEditAnchorControl\n\t\t\t\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\t\t\t\tattributes={ props.attributes }\n\t\t\t\t\t\t\t\tsetAttributes={ props.setAttributes }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t);\n\t\t};\n\t},\n\t'withInspectorControl'\n);\n\n/**\n * Override props assigned to save component to inject anchor ID, if block\n * supports anchor. This is only applied if the block's save result is an\n * element and not a markup string.\n *\n * @param {Object} extraProps Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Current block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( extraProps, blockType, attributes ) {\n\tif ( hasBlockSupport( blockType, 'anchor' ) ) {\n\t\textraProps.id = attributes.anchor === '' ? null : attributes.anchor;\n\t}\n\n\treturn extraProps;\n}\n\naddFilter( 'blocks.registerBlockType', 'core/anchor/attribute', addAttribute );\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/anchor/with-inspector-control',\n\twithInspectorControl\n);\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/anchor/save-props',\n\taddSaveProps\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAAS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CpB,aAAA,CAACP,sBAAsB;MACtBC,SAAS,EAAGwB,KAAK,CAACE,IAAM;MACxB7B,UAAU,EAAG2B,KAAK,CAAC3B,UAAY;MAC/BI,aAAa,EAAGuB,KAAK,CAACvB;IAAe,CACrC,CAEF,CAAC;EAEL,CAAC;AACF,CAAC,EACD,sBACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS0B,YAAYA,CAAEC,UAAU,EAAEC,SAAS,EAAEhC,UAAU,EAAG;EACjE,IAAKd,eAAe,CAAE8C,SAAS,EAAE,QAAS,CAAC,EAAG;IAC7CD,UAAU,CAACE,EAAE,GAAGjC,UAAU,CAACC,MAAM,KAAK,EAAE,GAAG,IAAI,GAAGD,UAAU,CAACC,MAAM;EACpE;EAEA,OAAO8B,UAAU;AAClB;AAEAlD,SAAS,CAAE,0BAA0B,EAAE,uBAAuB,EAAEgB,YAAa,CAAC;AAC9EhB,SAAS,CACR,kBAAkB,EAClB,2CAA2C,EAC3C4C,oBACD,CAAC;AACD5C,SAAS,CACR,kCAAkC,EAClC,wBAAwB,EACxBiD,YACD,CAAC"}
1
+ {"version":3,"names":["addFilter","PanelBody","TextControl","ExternalLink","__","hasBlockSupport","createHigherOrderComponent","Platform","InspectorControls","useBlockEditingMode","ANCHOR_REGEX","ANCHOR_SCHEMA","type","source","attribute","selector","addAttribute","settings","_settings$attributes$","attributes","anchor","BlockEditAnchorControl","blockName","setAttributes","blockEditingMode","isWeb","OS","textControl","createElement","__nextHasNoMarginBottom","__next40pxDefaultSize","className","label","help","Fragment","href","value","placeholder","onChange","nextValue","replace","autoCapitalize","autoComplete","group","title","withAnchorControls","BlockEdit","props","isSelected","name","addSaveProps","extraProps","blockType","id"],"sources":["@wordpress/block-editor/src/hooks/anchor.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { PanelBody, TextControl, ExternalLink } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { Platform } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { InspectorControls } from '../components';\nimport { useBlockEditingMode } from '../components/block-editing-mode';\n\n/**\n * Regular expression matching invalid anchor characters for replacement.\n *\n * @type {RegExp}\n */\nconst ANCHOR_REGEX = /[\\s#]/g;\n\nconst ANCHOR_SCHEMA = {\n\ttype: 'string',\n\tsource: 'attribute',\n\tattribute: 'id',\n\tselector: '*',\n};\n\n/**\n * Filters registered block settings, extending attributes with anchor using ID\n * of the first node.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addAttribute( settings ) {\n\t// Allow blocks to specify their own attribute definition with default values if needed.\n\tif ( 'type' in ( settings.attributes?.anchor ?? {} ) ) {\n\t\treturn settings;\n\t}\n\tif ( hasBlockSupport( settings, 'anchor' ) ) {\n\t\t// Gracefully handle if settings.attributes is undefined.\n\t\tsettings.attributes = {\n\t\t\t...settings.attributes,\n\t\t\tanchor: ANCHOR_SCHEMA,\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nfunction BlockEditAnchorControl( { blockName, attributes, setAttributes } ) {\n\tconst blockEditingMode = useBlockEditingMode();\n\n\tconst isWeb = Platform.OS === 'web';\n\tconst textControl = (\n\t\t<TextControl\n\t\t\t__nextHasNoMarginBottom\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName=\"html-anchor-control\"\n\t\t\tlabel={ __( 'HTML anchor' ) }\n\t\t\thelp={\n\t\t\t\t<>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Enter a word or two — without spaces — to make a unique web address just for this block, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'\n\t\t\t\t\t) }\n\n\t\t\t\t\t{ isWeb && (\n\t\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t\t'https://wordpress.org/documentation/article/page-jumps/'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Learn more about anchors' ) }\n\t\t\t\t\t\t</ExternalLink>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t}\n\t\t\tvalue={ attributes.anchor || '' }\n\t\t\tplaceholder={ ! isWeb ? __( 'Add an anchor' ) : null }\n\t\t\tonChange={ ( nextValue ) => {\n\t\t\t\tnextValue = nextValue.replace( ANCHOR_REGEX, '-' );\n\t\t\t\tsetAttributes( {\n\t\t\t\t\tanchor: nextValue,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tautoCapitalize=\"none\"\n\t\t\tautoComplete=\"off\"\n\t\t/>\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ isWeb && blockEditingMode === 'default' && (\n\t\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t\t{ textControl }\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t{ /*\n\t\t\t * We plan to remove scoping anchors to 'core/heading' to support\n\t\t\t * anchors for all eligble blocks. Additionally we plan to explore\n\t\t\t * leveraging InspectorAdvancedControls instead of a custom\n\t\t\t * PanelBody title. https://github.com/WordPress/gutenberg/issues/28363\n\t\t\t */ }\n\t\t\t{ ! isWeb && blockName === 'core/heading' && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Heading settings' ) }>\n\t\t\t\t\t\t{ textControl }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\n/**\n * Override the default edit UI to include a new block inspector control for\n * assigning the anchor ID, if block supports anchor.\n *\n * @param {Component} BlockEdit Original component.\n *\n * @return {Component} Wrapped component.\n */\nexport const withAnchorControls = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn ( props ) => {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit { ...props } />\n\t\t\t\t{ props.isSelected &&\n\t\t\t\t\thasBlockSupport( props.name, 'anchor' ) && (\n\t\t\t\t\t\t<BlockEditAnchorControl\n\t\t\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\t\t\tattributes={ props.attributes }\n\t\t\t\t\t\t\tsetAttributes={ props.setAttributes }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t};\n}, 'withAnchorControls' );\n\n/**\n * Override props assigned to save component to inject anchor ID, if block\n * supports anchor. This is only applied if the block's save result is an\n * element and not a markup string.\n *\n * @param {Object} extraProps Additional props applied to save element.\n * @param {Object} blockType Block type.\n * @param {Object} attributes Current block attributes.\n *\n * @return {Object} Filtered props applied to save element.\n */\nexport function addSaveProps( extraProps, blockType, attributes ) {\n\tif ( hasBlockSupport( blockType, 'anchor' ) ) {\n\t\textraProps.id = attributes.anchor === '' ? null : attributes.anchor;\n\t}\n\n\treturn extraProps;\n}\n\naddFilter( 'blocks.registerBlockType', 'core/anchor/attribute', addAttribute );\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/anchor/with-inspector-controls',\n\twithAnchorControls\n);\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/editor/anchor/save-props',\n\taddSaveProps\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,SAAS,EAAEC,WAAW,EAAEC,YAAY,QAAQ,uBAAuB;AAC5E,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,QAAQ,QAAQ,oBAAoB;;AAE7C;AACA;AACA;AACA,SAASC,iBAAiB,QAAQ,eAAe;AACjD,SAASC,mBAAmB,QAAQ,kCAAkC;;AAEtE;AACA;AACA;AACA;AACA;AACA,MAAMC,YAAY,GAAG,QAAQ;AAE7B,MAAMC,aAAa,GAAG;EACrBC,IAAI,EAAE,QAAQ;EACdC,MAAM,EAAE,WAAW;EACnBC,S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,UAAU,CAACE,EAAE,GAAGlC,UAAU,CAACC,MAAM,KAAK,EAAE,GAAG,IAAI,GAAGD,UAAU,CAACC,MAAM;EACpE;EAEA,OAAO+B,UAAU;AAClB;AAEAnD,SAAS,CAAE,0BAA0B,EAAE,uBAAuB,EAAEgB,YAAa,CAAC;AAC9EhB,SAAS,CACR,kBAAkB,EAClB,4CAA4C,EAC5C6C,kBACD,CAAC;AACD7C,SAAS,CACR,kCAAkC,EAClC,+BAA+B,EAC/BkD,YACD,CAAC"}
@@ -9,9 +9,10 @@ import classnames from 'classnames';
9
9
  */
10
10
  import { isBlobURL } from '@wordpress/blob';
11
11
  import { getBlockSupport } from '@wordpress/blocks';
12
+ import { focus } from '@wordpress/dom';
12
13
  import { __experimentalToolsPanelItem as ToolsPanelItem, DropZone, FlexItem, MenuItem, VisuallyHidden, __experimentalItemGroup as ItemGroup, __experimentalHStack as HStack, __experimentalTruncate as Truncate } from '@wordpress/components';
13
14
  import { useDispatch, useSelect } from '@wordpress/data';
14
- import { Platform, useCallback } from '@wordpress/element';
15
+ import { Platform, useCallback, useRef } from '@wordpress/element';
15
16
  import { __, sprintf } from '@wordpress/i18n';
16
17
  import { store as noticesStore } from '@wordpress/notices';
17
18
  import { getFilename } from '@wordpress/url';
@@ -128,6 +129,7 @@ function BackgroundImagePanelItem(props) {
128
129
  title,
129
130
  url
130
131
  } = attributes.style?.background?.backgroundImage || {};
132
+ const replaceContainerRef = useRef();
131
133
  const {
132
134
  mediaUpload
133
135
  } = useSelect(select => {
@@ -206,16 +208,18 @@ function BackgroundImagePanelItem(props) {
206
208
  }
207
209
  };
208
210
  }, []);
211
+ const hasValue = hasBackgroundImageValue(props);
209
212
  return createElement(ToolsPanelItem, {
210
213
  className: "single-column",
211
- hasValue: () => hasBackgroundImageValue(props),
214
+ hasValue: () => hasValue,
212
215
  label: __('Background image'),
213
216
  onDeselect: () => resetBackgroundImage(props),
214
217
  isShownByDefault: true,
215
218
  resetAllFilter: resetAllFilter,
216
219
  panelId: clientId
217
220
  }, createElement("div", {
218
- className: "block-editor-hooks__background__inspector-media-replace-container"
221
+ className: "block-editor-hooks__background__inspector-media-replace-container",
222
+ ref: replaceContainerRef
219
223
  }, createElement(MediaReplaceFlow, {
220
224
  mediaId: id,
221
225
  mediaURL: url,
@@ -228,8 +232,16 @@ function BackgroundImagePanelItem(props) {
228
232
  url: url
229
233
  }),
230
234
  variant: "secondary"
231
- }, createElement(MenuItem, {
232
- onClick: () => resetBackgroundImage(props)
235
+ }, hasValue && createElement(MenuItem, {
236
+ onClick: () => {
237
+ const [toggleButton] = focus.tabbable.find(replaceContainerRef.current);
238
+ // Focus the toggle button and close the dropdown menu.
239
+ // This ensures similar behaviour as to selecting an image, where the dropdown is
240
+ // closed and focus is redirected to the dropdown toggle button.
241
+ toggleButton?.focus();
242
+ toggleButton?.click();
243
+ resetBackgroundImage(props);
244
+ }
233
245
  }, __('Reset '))), createElement(DropZone, {
234
246
  onFilesDrop: onFilesDrop,
235
247
  label: __('Drop to upload')
@@ -1 +1 @@
1
- {"version":3,"names":["classnames","isBlobURL","getBlockSupport","__experimentalToolsPanelItem","ToolsPanelItem","DropZone","FlexItem","MenuItem","VisuallyHidden","__experimentalItemGroup","ItemGroup","__experimentalHStack","HStack","__experimentalTruncate","Truncate","useDispatch","useSelect","Platform","useCallback","__","sprintf","store","noticesStore","getFilename","InspectorControls","MediaReplaceFlow","useSettings","cleanEmptyObject","blockEditorStore","BACKGROUND_SUPPORT_KEY","IMAGE_BACKGROUND_TYPE","hasBackgroundImageValue","props","hasValue","attributes","style","background","backgroundImage","id","url","hasBackgroundSupport","blockName","feature","OS","support","resetBackgroundImage","setAttributes","undefined","InspectorImagePreview","label","filename","imgUrl","imgLabel","createElement","as","justify","className","numberOfLines","BackgroundImagePanelItem","clientId","title","mediaUpload","select","getSettings","createErrorNotice","onUploadError","message","type","onSelectMedia","media","newStyle","newAttributes","media_type","source","onFilesDrop","filesList","allowedTypes","onFileChange","image","onError","resetAllFilter","previousValue","onDeselect","isShownByDefault","panelId","mediaId","mediaURL","accept","onSelect","name","variant","onClick","BackgroundImagePanel","group"],"sources":["@wordpress/block-editor/src/hooks/background.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { isBlobURL } from '@wordpress/blob';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tDropZone,\n\tFlexItem,\n\tMenuItem,\n\tVisuallyHidden,\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { Platform, useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getFilename } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport MediaReplaceFlow from '../components/media-replace-flow';\nimport { useSettings } from '../components/use-settings';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nexport const BACKGROUND_SUPPORT_KEY = 'background';\nexport const IMAGE_BACKGROUND_TYPE = 'image';\n\n/**\n * Checks if there is a current value in the background image block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a background image value set.\n */\nexport function hasBackgroundImageValue( props ) {\n\tconst hasValue =\n\t\t!! props.attributes.style?.background?.backgroundImage?.id ||\n\t\t!! props.attributes.style?.background?.backgroundImage?.url;\n\n\treturn hasValue;\n}\n\n/**\n * Determine whether there is block support for background.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBackgroundSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BACKGROUND_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! support?.backgroundImage;\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Resets the background image block support attributes. This can be used when disabling\n * the background image controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBackgroundImage( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tbackground: {\n\t\t\t\t...style?.background,\n\t\t\t\tbackgroundImage: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction InspectorImagePreview( { label, filename, url: imgUrl } ) {\n\tconst imgLabel = label || getFilename( imgUrl );\n\treturn (\n\t\t<ItemGroup as=\"span\">\n\t\t\t<HStack justify=\"flex-start\" as=\"span\">\n\t\t\t\t<span\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'block-editor-hooks__background__inspector-image-indicator-wrapper',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'has-image': imgUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-hidden\n\t\t\t\t>\n\t\t\t\t\t{ imgUrl && (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-image-indicator\"\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\tbackgroundImage: `url(${ imgUrl })`,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</span>\n\t\t\t\t<FlexItem as=\"span\">\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-media-replace-title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ imgLabel }\n\t\t\t\t\t</Truncate>\n\t\t\t\t\t<VisuallyHidden as=\"span\">\n\t\t\t\t\t\t{ filename\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: file name */\n\t\t\t\t\t\t\t\t\t__( 'Selected image: %s' ),\n\t\t\t\t\t\t\t\t\tfilename\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __( 'No image selected' ) }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</ItemGroup>\n\t);\n}\n\nfunction BackgroundImagePanelItem( props ) {\n\tconst { attributes, clientId, setAttributes } = props;\n\n\tconst { id, title, url } =\n\t\tattributes.style?.background?.backgroundImage || {};\n\n\tconst { mediaUpload } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tmediaUpload: select( blockEditorStore ).getSettings().mediaUpload,\n\t\t};\n\t} );\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst onUploadError = ( message ) => {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t};\n\n\tconst onSelectMedia = ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tconst newStyle = {\n\t\t\t\t...attributes.style,\n\t\t\t\tbackground: {\n\t\t\t\t\t...attributes.style?.background,\n\t\t\t\t\tbackgroundImage: undefined,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst newAttributes = {\n\t\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\t};\n\n\t\t\tsetAttributes( newAttributes );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For media selections originated from a file upload.\n\t\tif (\n\t\t\t( media.media_type &&\n\t\t\t\tmedia.media_type !== IMAGE_BACKGROUND_TYPE ) ||\n\t\t\t( ! media.media_type &&\n\t\t\t\tmedia.type &&\n\t\t\t\tmedia.type !== IMAGE_BACKGROUND_TYPE )\n\t\t) {\n\t\t\tonUploadError(\n\t\t\t\t__( 'Only images can be used as a background image.' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStyle = {\n\t\t\t...attributes.style,\n\t\t\tbackground: {\n\t\t\t\t...attributes.style?.background,\n\t\t\t\tbackgroundImage: {\n\t\t\t\t\turl: media.url,\n\t\t\t\t\tid: media.id,\n\t\t\t\t\tsource: 'file',\n\t\t\t\t\ttitle: media.title || undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tconst newAttributes = {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t};\n\n\t\tsetAttributes( newAttributes );\n\t};\n\n\tconst onFilesDrop = ( filesList ) => {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonSelectMedia( image );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst resetAllFilter = useCallback( ( previousValue ) => {\n\t\treturn {\n\t\t\t...previousValue,\n\t\t\tstyle: {\n\t\t\t\t...previousValue.style,\n\t\t\t\tbackground: undefined,\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\tclassName=\"single-column\"\n\t\t\thasValue={ () => hasBackgroundImageValue( props ) }\n\t\t\tlabel={ __( 'Background image' ) }\n\t\t\tonDeselect={ () => resetBackgroundImage( props ) }\n\t\t\tisShownByDefault={ true }\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<div className=\"block-editor-hooks__background__inspector-media-replace-container\">\n\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\tmediaId={ id }\n\t\t\t\t\tmediaURL={ url }\n\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\taccept=\"image/*\"\n\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\tname={\n\t\t\t\t\t\t<InspectorImagePreview\n\t\t\t\t\t\t\tlabel={ __( 'Background image' ) }\n\t\t\t\t\t\t\tfilename={ title }\n\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t>\n\t\t\t\t\t<MenuItem onClick={ () => resetBackgroundImage( props ) }>\n\t\t\t\t\t\t{ __( 'Reset ' ) }\n\t\t\t\t\t</MenuItem>\n\t\t\t\t</MediaReplaceFlow>\n\t\t\t\t<DropZone\n\t\t\t\t\tonFilesDrop={ onFilesDrop }\n\t\t\t\t\tlabel={ __( 'Drop to upload' ) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport function BackgroundImagePanel( props ) {\n\tconst [ backgroundImage ] = useSettings( 'background.backgroundImage' );\n\tif (\n\t\t! backgroundImage ||\n\t\t! hasBackgroundSupport( props.name, 'backgroundImage' )\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"background\">\n\t\t\t<BackgroundImagePanelItem { ...props } />\n\t\t</InspectorControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SACCC,4BAA4B,IAAIC,cAAc,EAC9CC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,uBAAuB,IAAIC,SAAS,EACpCC,oBAAoB,IAAIC,MAAM,EAC9BC,sBAAsB,IAAIC,QAAQ,QAC5B,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;AAC1D,SAASC,EAAE,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entalToolsPanelItem","ToolsPanelItem","DropZone","FlexItem","MenuItem","VisuallyHidden","__experimentalItemGroup","ItemGroup","__experimentalHStack","HStack","__experimentalTruncate","Truncate","useDispatch","useSelect","Platform","useCallback","useRef","__","sprintf","store","noticesStore","getFilename","InspectorControls","MediaReplaceFlow","useSettings","cleanEmptyObject","blockEditorStore","BACKGROUND_SUPPORT_KEY","IMAGE_BACKGROUND_TYPE","hasBackgroundImageValue","props","hasValue","attributes","style","background","backgroundImage","id","url","hasBackgroundSupport","blockName","feature","OS","support","resetBackgroundImage","setAttributes","undefined","InspectorImagePreview","label","filename","imgUrl","imgLabel","createElement","as","justify","className","numberOfLines","BackgroundImagePanelItem","clientId","title","replaceContainerRef","mediaUpload","select","getSettings","createErrorNotice","onUploadError","message","type","onSelectMedia","media","newStyle","newAttributes","media_type","source","onFilesDrop","filesList","allowedTypes","onFileChange","image","onError","resetAllFilter","previousValue","onDeselect","isShownByDefault","panelId","ref","mediaId","mediaURL","accept","onSelect","name","variant","onClick","toggleButton","tabbable","find","current","click","BackgroundImagePanel","group"],"sources":["@wordpress/block-editor/src/hooks/background.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { isBlobURL } from '@wordpress/blob';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { focus } from '@wordpress/dom';\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tDropZone,\n\tFlexItem,\n\tMenuItem,\n\tVisuallyHidden,\n\t__experimentalItemGroup as ItemGroup,\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { Platform, useCallback, useRef } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { getFilename } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport InspectorControls from '../components/inspector-controls';\nimport MediaReplaceFlow from '../components/media-replace-flow';\nimport { useSettings } from '../components/use-settings';\nimport { cleanEmptyObject } from './utils';\nimport { store as blockEditorStore } from '../store';\n\nexport const BACKGROUND_SUPPORT_KEY = 'background';\nexport const IMAGE_BACKGROUND_TYPE = 'image';\n\n/**\n * Checks if there is a current value in the background image block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a background image value set.\n */\nexport function hasBackgroundImageValue( props ) {\n\tconst hasValue =\n\t\t!! props.attributes.style?.background?.backgroundImage?.id ||\n\t\t!! props.attributes.style?.background?.backgroundImage?.url;\n\n\treturn hasValue;\n}\n\n/**\n * Determine whether there is block support for background.\n *\n * @param {string} blockName Block name.\n * @param {string} feature Background image feature to check for.\n *\n * @return {boolean} Whether there is support.\n */\nexport function hasBackgroundSupport( blockName, feature = 'any' ) {\n\tif ( Platform.OS !== 'web' ) {\n\t\treturn false;\n\t}\n\n\tconst support = getBlockSupport( blockName, BACKGROUND_SUPPORT_KEY );\n\n\tif ( support === true ) {\n\t\treturn true;\n\t}\n\n\tif ( feature === 'any' ) {\n\t\treturn !! support?.backgroundImage;\n\t}\n\n\treturn !! support?.[ feature ];\n}\n\n/**\n * Resets the background image block support attributes. This can be used when disabling\n * the background image controls for a block via a `ToolsPanel`.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBackgroundImage( { attributes = {}, setAttributes } ) {\n\tconst { style = {} } = attributes;\n\n\tsetAttributes( {\n\t\tstyle: cleanEmptyObject( {\n\t\t\t...style,\n\t\t\tbackground: {\n\t\t\t\t...style?.background,\n\t\t\t\tbackgroundImage: undefined,\n\t\t\t},\n\t\t} ),\n\t} );\n}\n\nfunction InspectorImagePreview( { label, filename, url: imgUrl } ) {\n\tconst imgLabel = label || getFilename( imgUrl );\n\treturn (\n\t\t<ItemGroup as=\"span\">\n\t\t\t<HStack justify=\"flex-start\" as=\"span\">\n\t\t\t\t<span\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'block-editor-hooks__background__inspector-image-indicator-wrapper',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t'has-image': imgUrl,\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t\taria-hidden\n\t\t\t\t>\n\t\t\t\t\t{ imgUrl && (\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-image-indicator\"\n\t\t\t\t\t\t\tstyle={ {\n\t\t\t\t\t\t\t\tbackgroundImage: `url(${ imgUrl })`,\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</span>\n\t\t\t\t<FlexItem as=\"span\">\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t\tclassName=\"block-editor-hooks__background__inspector-media-replace-title\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ imgLabel }\n\t\t\t\t\t</Truncate>\n\t\t\t\t\t<VisuallyHidden as=\"span\">\n\t\t\t\t\t\t{ filename\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: file name */\n\t\t\t\t\t\t\t\t\t__( 'Selected image: %s' ),\n\t\t\t\t\t\t\t\t\tfilename\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __( 'No image selected' ) }\n\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t</FlexItem>\n\t\t\t</HStack>\n\t\t</ItemGroup>\n\t);\n}\n\nfunction BackgroundImagePanelItem( props ) {\n\tconst { attributes, clientId, setAttributes } = props;\n\n\tconst { id, title, url } =\n\t\tattributes.style?.background?.backgroundImage || {};\n\n\tconst replaceContainerRef = useRef();\n\n\tconst { mediaUpload } = useSelect( ( select ) => {\n\t\treturn {\n\t\t\tmediaUpload: select( blockEditorStore ).getSettings().mediaUpload,\n\t\t};\n\t} );\n\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst onUploadError = ( message ) => {\n\t\tcreateErrorNotice( message, { type: 'snackbar' } );\n\t};\n\n\tconst onSelectMedia = ( media ) => {\n\t\tif ( ! media || ! media.url ) {\n\t\t\tconst newStyle = {\n\t\t\t\t...attributes.style,\n\t\t\t\tbackground: {\n\t\t\t\t\t...attributes.style?.background,\n\t\t\t\t\tbackgroundImage: undefined,\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst newAttributes = {\n\t\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\t};\n\n\t\t\tsetAttributes( newAttributes );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isBlobURL( media.url ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For media selections originated from a file upload.\n\t\tif (\n\t\t\t( media.media_type &&\n\t\t\t\tmedia.media_type !== IMAGE_BACKGROUND_TYPE ) ||\n\t\t\t( ! media.media_type &&\n\t\t\t\tmedia.type &&\n\t\t\t\tmedia.type !== IMAGE_BACKGROUND_TYPE )\n\t\t) {\n\t\t\tonUploadError(\n\t\t\t\t__( 'Only images can be used as a background image.' )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst newStyle = {\n\t\t\t...attributes.style,\n\t\t\tbackground: {\n\t\t\t\t...attributes.style?.background,\n\t\t\t\tbackgroundImage: {\n\t\t\t\t\turl: media.url,\n\t\t\t\t\tid: media.id,\n\t\t\t\t\tsource: 'file',\n\t\t\t\t\ttitle: media.title || undefined,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\tconst newAttributes = {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t};\n\n\t\tsetAttributes( newAttributes );\n\t};\n\n\tconst onFilesDrop = ( filesList ) => {\n\t\tmediaUpload( {\n\t\t\tallowedTypes: [ 'image' ],\n\t\t\tfilesList,\n\t\t\tonFileChange( [ image ] ) {\n\t\t\t\tif ( isBlobURL( image?.url ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tonSelectMedia( image );\n\t\t\t},\n\t\t\tonError: onUploadError,\n\t\t} );\n\t};\n\n\tconst resetAllFilter = useCallback( ( previousValue ) => {\n\t\treturn {\n\t\t\t...previousValue,\n\t\t\tstyle: {\n\t\t\t\t...previousValue.style,\n\t\t\t\tbackground: undefined,\n\t\t\t},\n\t\t};\n\t}, [] );\n\n\tconst hasValue = hasBackgroundImageValue( props );\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\tclassName=\"single-column\"\n\t\t\thasValue={ () => hasValue }\n\t\t\tlabel={ __( 'Background image' ) }\n\t\t\tonDeselect={ () => resetBackgroundImage( props ) }\n\t\t\tisShownByDefault={ true }\n\t\t\tresetAllFilter={ resetAllFilter }\n\t\t\tpanelId={ clientId }\n\t\t>\n\t\t\t<div\n\t\t\t\tclassName=\"block-editor-hooks__background__inspector-media-replace-container\"\n\t\t\t\tref={ replaceContainerRef }\n\t\t\t>\n\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\tmediaId={ id }\n\t\t\t\t\tmediaURL={ url }\n\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\taccept=\"image/*\"\n\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\tname={\n\t\t\t\t\t\t<InspectorImagePreview\n\t\t\t\t\t\t\tlabel={ __( 'Background image' ) }\n\t\t\t\t\t\t\tfilename={ title }\n\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t>\n\t\t\t\t\t{ hasValue && (\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst [ toggleButton ] = focus.tabbable.find(\n\t\t\t\t\t\t\t\t\treplaceContainerRef.current\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t// Focus the toggle button and close the dropdown menu.\n\t\t\t\t\t\t\t\t// This ensures similar behaviour as to selecting an image, where the dropdown is\n\t\t\t\t\t\t\t\t// closed and focus is redirected to the dropdown toggle button.\n\t\t\t\t\t\t\t\ttoggleButton?.focus();\n\t\t\t\t\t\t\t\ttoggleButton?.click();\n\t\t\t\t\t\t\t\tresetBackgroundImage( props );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Reset ' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t) }\n\t\t\t\t</MediaReplaceFlow>\n\t\t\t\t<DropZone\n\t\t\t\t\tonFilesDrop={ onFilesDrop }\n\t\t\t\t\tlabel={ __( 'Drop to upload' ) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport function BackgroundImagePanel( props ) {\n\tconst [ backgroundImage ] = useSettings( 'background.backgroundImage' );\n\tif (\n\t\t! backgroundImage ||\n\t\t! hasBackgroundSupport( props.name, 'backgroundImage' )\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"background\">\n\t\t\t<BackgroundImagePanelItem { ...props } />\n\t\t</InspectorControls>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;;AAEnC;AACA;AACA;AACA,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SACCC,4BAA4B,IAAIC,cAAc,EAC9CC,QAAQ,EACRC,QAAQ,EACRC,QAAQ,EACRC,cAAc,EACdC,uBAAuB,IAAIC,SAAS,EACpCC,oBAAoB,IAAIC,MAAM,EAC9BC,sBAAsB,IAAIC,QAAQ,QAC5B,uBAAuB;AAC9B,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,QAAQ,EAAEC,WAAW,EAAEC,MAAM,QAAQ,oBAAoB;AAClE,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;A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,CAAE,4BAA6B,CAAC;EACvE,IACC,CAAEW,eAAe,IACjB,CAAEG,oBAAoB,CAAER,KAAK,CAAC2D,IAAI,EAAE,iBAAkB,CAAC,EACtD;IACD,OAAO,IAAI;EACZ;EAEA,OACCtC,aAAA,CAAC7B,iBAAiB;IAAC4E,KAAK,EAAC;EAAY,GACpC/C,aAAA,CAACK,wBAAwB;IAAA,GAAM1B;EAAK,CAAI,CACtB,CAAC;AAEtB"}
@@ -165,17 +165,16 @@ function BlockHooksControl(props) {
165
165
  }));
166
166
  })));
167
167
  }
168
- export const withBlockHooks = createHigherOrderComponent(BlockEdit => {
168
+ export const withBlockHooksControls = createHigherOrderComponent(BlockEdit => {
169
169
  return props => {
170
- const blockEdit = createElement(BlockEdit, {
170
+ return createElement(Fragment, null, createElement(BlockEdit, {
171
171
  key: "edit",
172
172
  ...props
173
- });
174
- return createElement(Fragment, null, blockEdit, createElement(BlockHooksControl, {
173
+ }), props.isSelected && createElement(BlockHooksControl, {
175
174
  blockName: props.name,
176
175
  clientId: props.clientId
177
176
  }));
178
177
  };
179
- }, 'withBlockHooks');
180
- addFilter('editor.BlockEdit', 'core/block-hooks/with-inspector-control', withBlockHooks);
178
+ }, 'withBlockHooksControls');
179
+ addFilter('editor.BlockEdit', 'core/editor/block-hooks/with-inspector-controls', withBlockHooksControls);
181
180
  //# sourceMappingURL=block-hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["__","addFilter","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createHigherOrderComponent","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControl","props","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockHooks","blockName","blockIndex","rootClientId","innerBlocksLength","getBlock","getBlockIndex","getBlockRootClientId","clientId","innerBlocks","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","name","relativePosition","candidates","hookedBlock","find","Object","values","insertBlock","removeBlock","hookedBlocksForCurrentBlockIfNotPresentElsewhere","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","withBlockHooks","BlockEdit","blockEdit"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { addFilter } from '@wordpress/hooks';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControl( props ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) =>\n\t\t\t\t\tblockHooks && props.blockName in blockHooks\n\t\t\t),\n\t\t[ blockTypes, props.blockName ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( props.clientId ),\n\t\t\t\tinnerBlocksLength: getBlock( props.clientId )?.innerBlocks\n\t\t\t\t\t?.length,\n\t\t\t\trootClientId: getBlockRootClientId( props.clientId ),\n\t\t\t};\n\t\t},\n\t\t[ props.clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to display the toggle for it, and set\n\t\t\t\t\t// it to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\tblock?.blockHooks?.[ props.blockName ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( rootClientId )?.innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( props.clientId ).innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( { name } ) => name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// but it exists elsewhere in the block tree, we consider it manually inserted.\n\t\t\t\t\t// In this case, we take note and will remove the corresponding toggle from the\n\t\t\t\t\t// block inspector panel.\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t[ block.name ]: false,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[\n\t\t\thookedBlocksForCurrentBlock,\n\t\t\tprops.blockName,\n\t\t\tprops.clientId,\n\t\t\trootClientId,\n\t\t]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\t// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.\n\tconst hookedBlocksForCurrentBlockIfNotPresentElsewhere =\n\t\thookedBlocksForCurrentBlock?.filter(\n\t\t\t( block ) => hookedBlockClientIds?.[ block.name ] !== false\n\t\t);\n\n\tif ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tprops.clientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tprops.blockName\n\t\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tconst clientId =\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock( clientId, false );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport const withBlockHooks = createHigherOrderComponent( ( BlockEdit ) => {\n\treturn ( props ) => {\n\t\tconst blockEdit = <BlockEdit key=\"edit\" { ...props } />;\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ blockEdit }\n\t\t\t\t<BlockHooksControl\n\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t/>\n\t\t\t</>\n\t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AEA;UACA,MAAMV,QAAQ,GACbG,oBAAoB,CACnBK,KAAK,CAACC,IAAI,CACV;UACFQ,WAAW,CAAEjB,QAAQ,EAAE,KAAM,CAAC;QAC/B;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,OAAO,MAAMsC,cAAc,GAAG/D,0BAA0B,CAAIgE,SAAS,IAAM;EAC1E,OAASrD,KAAK,IAAM;IACnB,MAAMsD,SAAS,GAAGf,aAAA,CAACc,SAAS;MAACP,GAAG,EAAC,MAAM;MAAA,GAAM9C;IAAK,CAAI,CAAC;IACvD,OACCuC,aAAA,CAAAxD,QAAA,QACGuE,SAAS,EACXf,aAAA,CAACxC,iBAAiB;MACjBQ,SAAS,EAAGP,KAAK,CAACuB,IAAM;MACxBT,QAAQ,EAAGd,KAAK,CAACc;IAAU,CAC3B,CACA,CAAC;EAEL,CAAC;AACF,CAAC,EAAE,gBAAiB,CAAC;AAErBhC,SAAS,CACR,kBAAkB,EAClB,yCAAyC,EACzCsE,cACD,CAAC"}
1
+ {"version":3,"names":["__","addFilter","Fragment","useMemo","__experimentalHStack","HStack","PanelBody","ToggleControl","createHigherOrderComponent","createBlock","store","blocksStore","useDispatch","useSelect","BlockIcon","InspectorControls","blockEditorStore","EMPTY_OBJECT","BlockHooksControl","props","blockTypes","select","getBlockTypes","hookedBlocksForCurrentBlock","filter","blockHooks","blockName","blockIndex","rootClientId","innerBlocksLength","getBlock","getBlockIndex","getBlockRootClientId","clientId","innerBlocks","length","hookedBlockClientIds","getGlobalBlockCount","_hookedBlockClientIds","reduce","clientIds","block","name","relativePosition","candidates","hookedBlock","find","Object","values","insertBlock","removeBlock","hookedBlocksForCurrentBlockIfNotPresentElsewhere","groupedHookedBlocks","groups","namespace","split","push","insertBlockIntoDesignatedLocation","createElement","className","title","initialOpen","keys","map","vendor","key","checked","label","justify","icon","onChange","withBlockHooksControls","BlockEdit","isSelected"],"sources":["@wordpress/block-editor/src/hooks/block-hooks.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { addFilter } from '@wordpress/hooks';\nimport { Fragment, useMemo } from '@wordpress/element';\nimport {\n\t__experimentalHStack as HStack,\n\tPanelBody,\n\tToggleControl,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { createBlock, store as blocksStore } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { BlockIcon, InspectorControls } from '../components';\nimport { store as blockEditorStore } from '../store';\n\nconst EMPTY_OBJECT = {};\n\nfunction BlockHooksControl( props ) {\n\tconst blockTypes = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockTypes(),\n\t\t[]\n\t);\n\n\tconst hookedBlocksForCurrentBlock = useMemo(\n\t\t() =>\n\t\t\tblockTypes?.filter(\n\t\t\t\t( { blockHooks } ) =>\n\t\t\t\t\tblockHooks && props.blockName in blockHooks\n\t\t\t),\n\t\t[ blockTypes, props.blockName ]\n\t);\n\n\tconst { blockIndex, rootClientId, innerBlocksLength } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getBlockIndex, getBlockRootClientId } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tblockIndex: getBlockIndex( props.clientId ),\n\t\t\t\tinnerBlocksLength: getBlock( props.clientId )?.innerBlocks\n\t\t\t\t\t?.length,\n\t\t\t\trootClientId: getBlockRootClientId( props.clientId ),\n\t\t\t};\n\t\t},\n\t\t[ props.clientId ]\n\t);\n\n\tconst hookedBlockClientIds = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlock, getGlobalBlockCount } =\n\t\t\t\tselect( blockEditorStore );\n\n\t\t\tconst _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce(\n\t\t\t\t( clientIds, block ) => {\n\t\t\t\t\t// If the block doesn't exist anywhere in the block tree,\n\t\t\t\t\t// we know that we have to display the toggle for it, and set\n\t\t\t\t\t// it to disabled.\n\t\t\t\t\tif ( getGlobalBlockCount( block.name ) === 0 ) {\n\t\t\t\t\t\treturn clientIds;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\tblock?.blockHooks?.[ props.blockName ];\n\t\t\t\t\tlet candidates;\n\n\t\t\t\t\tswitch ( relativePosition ) {\n\t\t\t\t\t\tcase 'before':\n\t\t\t\t\t\tcase 'after':\n\t\t\t\t\t\t\t// Any of the current block's siblings (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked block (inserted `before` or `after` the current one), as the block\n\t\t\t\t\t\t\t// might've been automatically inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( rootClientId )?.innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tcase 'first_child':\n\t\t\t\t\t\tcase 'last_child':\n\t\t\t\t\t\t\t// Any of the current block's child blocks (with the right block type) qualifies\n\t\t\t\t\t\t\t// as a hooked first or last child block, as the block might've been automatically\n\t\t\t\t\t\t\t// inserted and then moved around a bit by the user.\n\t\t\t\t\t\t\tcandidates = getBlock( props.clientId ).innerBlocks;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst hookedBlock = candidates?.find(\n\t\t\t\t\t\t( { name } ) => name === block.name\n\t\t\t\t\t);\n\n\t\t\t\t\t// If the block exists in the designated location, we consider it hooked\n\t\t\t\t\t// and show the toggle as enabled.\n\t\t\t\t\tif ( hookedBlock ) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t\t[ block.name ]: hookedBlock.clientId,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// If no hooked block was found in any of its designated locations,\n\t\t\t\t\t// but it exists elsewhere in the block tree, we consider it manually inserted.\n\t\t\t\t\t// In this case, we take note and will remove the corresponding toggle from the\n\t\t\t\t\t// block inspector panel.\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...clientIds,\n\t\t\t\t\t\t[ block.name ]: false,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tif ( Object.values( _hookedBlockClientIds ).length > 0 ) {\n\t\t\t\treturn _hookedBlockClientIds;\n\t\t\t}\n\n\t\t\treturn EMPTY_OBJECT;\n\t\t},\n\t\t[\n\t\t\thookedBlocksForCurrentBlock,\n\t\t\tprops.blockName,\n\t\t\tprops.clientId,\n\t\t\trootClientId,\n\t\t]\n\t);\n\n\tconst { insertBlock, removeBlock } = useDispatch( blockEditorStore );\n\n\t// Remove toggle if block isn't present in the designated location but elsewhere in the block tree.\n\tconst hookedBlocksForCurrentBlockIfNotPresentElsewhere =\n\t\thookedBlocksForCurrentBlock?.filter(\n\t\t\t( block ) => hookedBlockClientIds?.[ block.name ] !== false\n\t\t);\n\n\tif ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) {\n\t\treturn null;\n\t}\n\n\t// Group by block namespace (i.e. prefix before the slash).\n\tconst groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce(\n\t\t( groups, block ) => {\n\t\t\tconst [ namespace ] = block.name.split( '/' );\n\t\t\tif ( ! groups[ namespace ] ) {\n\t\t\t\tgroups[ namespace ] = [];\n\t\t\t}\n\t\t\tgroups[ namespace ].push( block );\n\t\t\treturn groups;\n\t\t},\n\t\t{}\n\t);\n\n\tconst insertBlockIntoDesignatedLocation = ( block, relativePosition ) => {\n\t\tswitch ( relativePosition ) {\n\t\t\tcase 'before':\n\t\t\tcase 'after':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\trelativePosition === 'after' ? blockIndex + 1 : blockIndex,\n\t\t\t\t\trootClientId, // Insert as a child of the current block's parent\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\n\t\t\tcase 'first_child':\n\t\t\tcase 'last_child':\n\t\t\t\tinsertBlock(\n\t\t\t\t\tblock,\n\t\t\t\t\t// TODO: It'd be great if insertBlock() would accept negative indices for insertion.\n\t\t\t\t\trelativePosition === 'first_child' ? 0 : innerBlocksLength,\n\t\t\t\t\tprops.clientId, // Insert as a child of the current block.\n\t\t\t\t\tfalse\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t}\n\t};\n\n\treturn (\n\t\t<InspectorControls>\n\t\t\t<PanelBody\n\t\t\t\tclassName=\"block-editor-hooks__block-hooks\"\n\t\t\t\ttitle={ __( 'Plugins' ) }\n\t\t\t\tinitialOpen={ true }\n\t\t\t>\n\t\t\t\t{ Object.keys( groupedHookedBlocks ).map( ( vendor ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Fragment key={ vendor }>\n\t\t\t\t\t\t\t<h3>{ vendor }</h3>\n\t\t\t\t\t\t\t{ groupedHookedBlocks[ vendor ].map( ( block ) => {\n\t\t\t\t\t\t\t\tconst checked =\n\t\t\t\t\t\t\t\t\tblock.name in hookedBlockClientIds;\n\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\t\t\tchecked={ checked }\n\t\t\t\t\t\t\t\t\t\tkey={ block.title }\n\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t<HStack justify=\"flex-start\">\n\t\t\t\t\t\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon={ block.icon }\n\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t<span>{ block.title }</span>\n\t\t\t\t\t\t\t\t\t\t\t</HStack>\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\tif ( ! checked ) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Create and insert block.\n\t\t\t\t\t\t\t\t\t\t\t\tconst relativePosition =\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.blockHooks[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tprops.blockName\n\t\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\t\tinsertBlockIntoDesignatedLocation(\n\t\t\t\t\t\t\t\t\t\t\t\t\tcreateBlock( block.name ),\n\t\t\t\t\t\t\t\t\t\t\t\t\trelativePosition\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// Remove block.\n\t\t\t\t\t\t\t\t\t\t\tconst clientId =\n\t\t\t\t\t\t\t\t\t\t\t\thookedBlockClientIds[\n\t\t\t\t\t\t\t\t\t\t\t\t\tblock.name\n\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\tremoveBlock( clientId, false );\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</Fragment>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</PanelBody>\n\t\t</InspectorControls>\n\t);\n}\n\nexport const withBlockHooksControls = createHigherOrderComponent(\n\t( BlockEdit ) => {\n\t\treturn ( props ) => {\n\t\t\treturn (\n\t\t\t\t<>\n\t\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t\t{ props.isSelected && (\n\t\t\t\t\t\t<BlockHooksControl\n\t\t\t\t\t\t\tblockName={ props.name }\n\t\t\t\t\t\t\tclientId={ props.clientId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t);\n\t\t};\n\t},\n\t'withBlockHooksControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/editor/block-hooks/with-inspector-controls',\n\twithBlockHooksControls\n);\n"],"mappings":";AAAA;AACA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B;MAAG,CACH,CAAC;IAEJ,CAAE,CACO,CAAC;EAEb,CAAE,CACQ,CACO,CAAC;AAEtB;AAEA,OAAO,MAAMsC,sBAAsB,GAAG/D,0BAA0B,CAC7DgE,SAAS,IAAM;EAChB,OAASrD,KAAK,IAAM;IACnB,OACCuC,aAAA,CAAAxD,QAAA,QACCwD,aAAA,CAACc,SAAS;MAACP,GAAG,EAAC,MAAM;MAAA,GAAM9C;IAAK,CAAI,CAAC,EACnCA,KAAK,CAACsD,UAAU,IACjBf,aAAA,CAACxC,iBAAiB;MACjBQ,SAAS,EAAGP,KAAK,CAACuB,IAAM;MACxBT,QAAQ,EAAGd,KAAK,CAACc;IAAU,CAC3B,CAED,CAAC;EAEL,CAAC;AACF,CAAC,EACD,wBACD,CAAC;AAEDhC,SAAS,CACR,kBAAkB,EAClB,iDAAiD,EACjDsE,sBACD,CAAC"}
@@ -1,8 +1,18 @@
1
+ import { createElement, Fragment } from "react";
1
2
  /**
2
3
  * WordPress dependencies
3
4
  */
4
5
  import { addFilter } from '@wordpress/hooks';
5
6
  import { hasBlockSupport } from '@wordpress/blocks';
7
+ import { createHigherOrderComponent } from '@wordpress/compose';
8
+ import { __ } from '@wordpress/i18n';
9
+ import { TextControl } from '@wordpress/components';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import { InspectorControls } from '../components';
15
+ import { useBlockRename } from '../components/block-rename';
6
16
 
7
17
  /**
8
18
  * Filters registered block settings, adding an `__experimentalLabel` callback if one does not already exist.
@@ -36,5 +46,35 @@ export function addLabelCallback(settings) {
36
46
  }
37
47
  return settings;
38
48
  }
49
+ export const withBlockRenameControl = createHigherOrderComponent(BlockEdit => props => {
50
+ const {
51
+ name,
52
+ attributes,
53
+ setAttributes,
54
+ isSelected
55
+ } = props;
56
+ const {
57
+ canRename
58
+ } = useBlockRename(name);
59
+ return createElement(Fragment, null, isSelected && canRename && createElement(InspectorControls, {
60
+ group: "advanced"
61
+ }, createElement(TextControl, {
62
+ __nextHasNoMarginBottom: true,
63
+ label: __('Block name'),
64
+ value: attributes?.metadata?.name || '',
65
+ onChange: newName => {
66
+ setAttributes({
67
+ metadata: {
68
+ ...attributes?.metadata,
69
+ name: newName
70
+ }
71
+ });
72
+ }
73
+ })), createElement(BlockEdit, {
74
+ key: "edit",
75
+ ...props
76
+ }));
77
+ }, 'withToolbarControls');
78
+ addFilter('editor.BlockEdit', 'core/block-rename-ui/with-block-rename-control', withBlockRenameControl);
39
79
  addFilter('blocks.registerBlockType', 'core/metadata/addLabelCallback', addLabelCallback);
40
80
  //# sourceMappingURL=block-renaming.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["addFilter","hasBlockSupport","addLabelCallback","settings","__experimentalLabel","supportsBlockNaming","attributes","context","metadata","name"],"sources":["@wordpress/block-editor/src/hooks/block-renaming.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Filters registered block settings, adding an `__experimentalLabel` callback if one does not already exist.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addLabelCallback( settings ) {\n\t// If blocks provide their own label callback, do not override it.\n\tif ( settings.__experimentalLabel ) {\n\t\treturn settings;\n\t}\n\n\tconst supportsBlockNaming = hasBlockSupport(\n\t\tsettings,\n\t\t'renaming',\n\t\ttrue // default value\n\t);\n\n\t// Check whether block metadata is supported before using it.\n\tif ( supportsBlockNaming ) {\n\t\tsettings.__experimentalLabel = ( attributes, { context } ) => {\n\t\t\tconst { metadata } = attributes;\n\n\t\t\t// In the list view, use the block's name attribute as the label.\n\t\t\tif ( context === 'list-view' && metadata?.name ) {\n\t\t\t\treturn metadata.name;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn settings;\n}\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/metadata/addLabelCallback',\n\taddLabelCallback\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,eAAe,QAAQ,mBAAmB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAAEC,QAAQ,EAAG;EAC5C;EACA,IAAKA,QAAQ,CAACC,mBAAmB,EAAG;IACnC,OAAOD,QAAQ;EAChB;EAEA,MAAME,mBAAmB,GAAGJ,eAAe,CAC1CE,QAAQ,EACR,UAAU,EACV,IAAI,CAAC;EACN,CAAC;;EAED;EACA,IAAKE,mBAAmB,EAAG;IAC1BF,QAAQ,CAACC,mBAAmB,GAAG,CAAEE,UAAU,EAAE;MAAEC;IAAQ,CAAC,KAAM;MAC7D,MAAM;QAAEC;MAAS,CAAC,GAAGF,UAAU;;MAE/B;MACA,IAAKC,OAAO,KAAK,WAAW,IAAIC,QAAQ,EAAEC,IAAI,EAAG;QAChD,OAAOD,QAAQ,CAACC,IAAI;MACrB;IACD,CAAC;EACF;EAEA,OAAON,QAAQ;AAChB;AAEAH,SAAS,CACR,0BAA0B,EAC1B,gCAAgC,EAChCE,gBACD,CAAC"}
1
+ {"version":3,"names":["addFilter","hasBlockSupport","createHigherOrderComponent","__","TextControl","InspectorControls","useBlockRename","addLabelCallback","settings","__experimentalLabel","supportsBlockNaming","attributes","context","metadata","name","withBlockRenameControl","BlockEdit","props","setAttributes","isSelected","canRename","createElement","Fragment","group","__nextHasNoMarginBottom","label","value","onChange","newName","key"],"sources":["@wordpress/block-editor/src/hooks/block-renaming.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { hasBlockSupport } from '@wordpress/blocks';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { TextControl } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { InspectorControls } from '../components';\nimport { useBlockRename } from '../components/block-rename';\n\n/**\n * Filters registered block settings, adding an `__experimentalLabel` callback if one does not already exist.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nexport function addLabelCallback( settings ) {\n\t// If blocks provide their own label callback, do not override it.\n\tif ( settings.__experimentalLabel ) {\n\t\treturn settings;\n\t}\n\n\tconst supportsBlockNaming = hasBlockSupport(\n\t\tsettings,\n\t\t'renaming',\n\t\ttrue // default value\n\t);\n\n\t// Check whether block metadata is supported before using it.\n\tif ( supportsBlockNaming ) {\n\t\tsettings.__experimentalLabel = ( attributes, { context } ) => {\n\t\t\tconst { metadata } = attributes;\n\n\t\t\t// In the list view, use the block's name attribute as the label.\n\t\t\tif ( context === 'list-view' && metadata?.name ) {\n\t\t\t\treturn metadata.name;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn settings;\n}\n\nexport const withBlockRenameControl = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { name, attributes, setAttributes, isSelected } = props;\n\n\t\tconst { canRename } = useBlockRename( name );\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ isSelected && canRename && (\n\t\t\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\tlabel={ __( 'Block name' ) }\n\t\t\t\t\t\t\tvalue={ attributes?.metadata?.name || '' }\n\t\t\t\t\t\t\tonChange={ ( newName ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\t\t\t...attributes?.metadata,\n\t\t\t\t\t\t\t\t\t\tname: newName,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</InspectorControls>\n\t\t\t\t) }\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t</>\n\t\t);\n\t},\n\t'withToolbarControls'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/block-rename-ui/with-block-rename-control',\n\twithB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BAAiB;IAACkB,KAAK,EAAC;EAAU,GAClCF,aAAA,CAACjB,WAAW;IACXoB,uBAAuB;IACvBC,KAAK,EAAGtB,EAAE,CAAE,YAAa,CAAG;IAC5BuB,KAAK,EAAGf,UAAU,EAAEE,QAAQ,EAAEC,IAAI,IAAI,EAAI;IAC1Ca,QAAQ,EAAKC,OAAO,IAAM;MACzBV,aAAa,CAAE;QACdL,QAAQ,EAAE;UACT,GAAGF,UAAU,EAAEE,QAAQ;UACvBC,IAAI,EAAEc;QACP;MACD,CAAE,CAAC;IACJ;EAAG,CACH,CACiB,CACnB,EACDP,aAAA,CAACL,SAAS;IAACa,GAAG,EAAC,MAAM;IAAA,GAAMZ;EAAK,CAAI,CACnC,CAAC;AAEL,CAAC,EACD,qBACD,CAAC;AAEDjB,SAAS,CACR,kBAAkB,EAClB,gDAAgD,EAChDe,sBACD,CAAC;AAEDf,SAAS,CACR,0BAA0B,EAC1B,gCAAgC,EAChCO,gBACD,CAAC"}
@@ -32,7 +32,7 @@ function StopEditingAsBlocksOnOutsideSelect({
32
32
  }, [isBlockOrDescendantSelected, stopEditingAsBlock]);
33
33
  return null;
34
34
  }
35
- export const withBlockControls = createHigherOrderComponent(BlockEdit => props => {
35
+ export const withContentLockControls = createHigherOrderComponent(BlockEdit => props => {
36
36
  const {
37
37
  getBlockListSettings,
38
38
  getSettings
@@ -118,6 +118,6 @@ export const withBlockControls = createHigherOrderComponent(BlockEdit => props =
118
118
  key: "edit",
119
119
  ...props
120
120
  }));
121
- }, 'withToolbarControls');
122
- addFilter('editor.BlockEdit', 'core/content-lock-ui/with-block-controls', withBlockControls);
121
+ }, 'withContentLockControls');
122
+ addFilter('editor.BlockEdit', 'core/content-lock-ui/with-block-controls', withContentLockControls);
123
123
  //# sourceMappingURL=content-lock-ui.js.map