@wordpress/block-editor 12.9.0 → 12.10.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 (463) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +33 -3
  3. package/build/components/block-canvas/index.js +107 -0
  4. package/build/components/block-canvas/index.js.map +1 -0
  5. package/build/components/block-inspector/index.js +4 -1
  6. package/build/components/block-inspector/index.js.map +1 -1
  7. package/build/components/block-patterns-list/index.js +19 -4
  8. package/build/components/block-patterns-list/index.js.map +1 -1
  9. package/build/components/block-patterns-paging/index.js +66 -0
  10. package/build/components/block-patterns-paging/index.js.map +1 -0
  11. package/build/components/block-settings-menu/block-settings-dropdown.js +28 -0
  12. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  13. package/build/components/block-settings-menu-controls/index.js +4 -7
  14. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  15. package/build/components/block-styles/index.js +1 -0
  16. package/build/components/block-styles/index.js.map +1 -1
  17. package/build/components/block-toolbar/block-toolbar-menu.native.js +3 -7
  18. package/build/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
  19. package/build/components/block-tools/block-contextual-toolbar.js +18 -7
  20. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  21. package/build/components/block-tools/block-selection-button.js +5 -1
  22. package/build/components/block-tools/block-selection-button.js.map +1 -1
  23. package/build/components/border-radius-control/input-controls.js +1 -1
  24. package/build/components/border-radius-control/input-controls.js.map +1 -1
  25. package/build/components/border-radius-control/linked-button.js +2 -4
  26. package/build/components/border-radius-control/linked-button.js.map +1 -1
  27. package/build/components/colors/with-colors.js.map +1 -1
  28. package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -21
  29. package/build/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
  30. package/build/components/default-block-appender/index.native.js +20 -1
  31. package/build/components/default-block-appender/index.native.js.map +1 -1
  32. package/build/components/duotone/utils.js +68 -0
  33. package/build/components/duotone/utils.js.map +1 -1
  34. package/build/components/editor-styles/index.js +28 -9
  35. package/build/components/editor-styles/index.js.map +1 -1
  36. package/build/components/global-styles/hooks.js +2 -101
  37. package/build/components/global-styles/hooks.js.map +1 -1
  38. package/build/components/global-styles/image-settings-panel.js +61 -0
  39. package/build/components/global-styles/image-settings-panel.js.map +1 -0
  40. package/build/components/global-styles/index.js +11 -17
  41. package/build/components/global-styles/index.js.map +1 -1
  42. package/build/components/global-styles/use-global-styles-output.js +19 -15
  43. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  44. package/build/components/global-styles/utils.js +1 -1
  45. package/build/components/global-styles/utils.js.map +1 -1
  46. package/build/components/iframe/index.js +67 -33
  47. package/build/components/iframe/index.js.map +1 -1
  48. package/build/components/image-editor/use-save-image.js +2 -5
  49. package/build/components/image-editor/use-save-image.js.map +1 -1
  50. package/build/components/image-editor/use-transform-image.js +9 -9
  51. package/build/components/image-editor/use-transform-image.js.map +1 -1
  52. package/build/components/index.js +8 -12
  53. package/build/components/index.js.map +1 -1
  54. package/build/components/index.native.js +6 -5
  55. package/build/components/index.native.js.map +1 -1
  56. package/build/components/inner-blocks/use-nested-settings-update.js +13 -7
  57. package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  58. package/build/components/inserter/block-patterns-explorer/explorer.js +12 -6
  59. package/build/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
  60. package/build/components/inserter/block-patterns-explorer/patterns-list.js +57 -23
  61. package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
  62. package/build/components/inserter/block-patterns-explorer/sidebar.js +24 -9
  63. package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
  64. package/build/components/inserter/block-patterns-source-filter.js +54 -0
  65. package/build/components/inserter/block-patterns-source-filter.js.map +1 -0
  66. package/build/components/inserter/block-patterns-sync-filter.js +46 -0
  67. package/build/components/inserter/block-patterns-sync-filter.js.map +1 -0
  68. package/build/components/inserter/block-patterns-tab.js +91 -45
  69. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  70. package/build/components/inserter/hooks/use-patterns-paging.js +57 -0
  71. package/build/components/inserter/hooks/use-patterns-paging.js.map +1 -0
  72. package/build/components/inserter/hooks/use-patterns-state.js +21 -10
  73. package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
  74. package/build/components/inserter/menu.js +13 -11
  75. package/build/components/inserter/menu.js.map +1 -1
  76. package/build/components/inserter/search-results.js +4 -3
  77. package/build/components/inserter/search-results.js.map +1 -1
  78. package/build/components/inserter/tabs.js +1 -12
  79. package/build/components/inserter/tabs.js.map +1 -1
  80. package/build/components/inspector-controls/block-support-slot-container.js +12 -1
  81. package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
  82. package/build/components/inspector-controls/fill.js +24 -13
  83. package/build/components/inspector-controls/fill.js.map +1 -1
  84. package/build/components/inspector-controls/groups.js +5 -3
  85. package/build/components/inspector-controls/groups.js.map +1 -1
  86. package/build/components/inspector-controls/slot.js +13 -0
  87. package/build/components/inspector-controls/slot.js.map +1 -1
  88. package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
  89. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  90. package/build/components/link-control/index.js +13 -2
  91. package/build/components/link-control/index.js.map +1 -1
  92. package/build/components/link-control/settings.js +2 -1
  93. package/build/components/link-control/settings.js.map +1 -1
  94. package/build/components/list-view/block-select-button.js +1 -3
  95. package/build/components/list-view/block-select-button.js.map +1 -1
  96. package/build/components/list-view/block.js +13 -1
  97. package/build/components/list-view/block.js.map +1 -1
  98. package/build/components/list-view/use-block-selection.js +29 -24
  99. package/build/components/list-view/use-block-selection.js.map +1 -1
  100. package/build/components/media-placeholder/index.js +2 -2
  101. package/build/components/media-placeholder/index.js.map +1 -1
  102. package/build/components/media-placeholder/index.native.js +11 -11
  103. package/build/components/media-placeholder/index.native.js.map +1 -1
  104. package/build/components/media-replace-flow/index.js +2 -3
  105. package/build/components/media-replace-flow/index.js.map +1 -1
  106. package/build/components/media-upload/constants.js +30 -0
  107. package/build/components/media-upload/constants.js.map +1 -0
  108. package/build/components/media-upload/index.native.js +63 -53
  109. package/build/components/media-upload/index.native.js.map +1 -1
  110. package/build/components/preview-options/index.js +1 -1
  111. package/build/components/preview-options/index.js.map +1 -1
  112. package/build/components/rich-text/index.js +34 -35
  113. package/build/components/rich-text/index.js.map +1 -1
  114. package/build/components/rich-text/index.native.js +14 -32
  115. package/build/components/rich-text/index.native.js.map +1 -1
  116. package/build/components/rich-text/multiline.js +95 -0
  117. package/build/components/rich-text/multiline.js.map +1 -0
  118. package/build/components/rich-text/split-value.js +10 -16
  119. package/build/components/rich-text/split-value.js.map +1 -1
  120. package/build/components/rich-text/use-enter.js +31 -40
  121. package/build/components/rich-text/use-enter.js.map +1 -1
  122. package/build/components/rich-text/use-paste-handler.js +18 -33
  123. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  124. package/build/components/spacing-sizes-control/utils.js +1 -1
  125. package/build/components/spacing-sizes-control/utils.js.map +1 -1
  126. package/build/components/use-block-commands/index.js +30 -18
  127. package/build/components/use-block-commands/index.js.map +1 -1
  128. package/build/components/use-block-display-information/index.js +5 -2
  129. package/build/components/use-block-display-information/index.js.map +1 -1
  130. package/build/hooks/background.js +258 -0
  131. package/build/hooks/background.js.map +1 -0
  132. package/build/hooks/block-hooks.js +188 -0
  133. package/build/hooks/block-hooks.js.map +1 -0
  134. package/build/hooks/block-rename-ui.js +160 -0
  135. package/build/hooks/block-rename-ui.js.map +1 -0
  136. package/build/hooks/duotone.js +29 -42
  137. package/build/hooks/duotone.js.map +1 -1
  138. package/build/hooks/index.js +2 -2
  139. package/build/hooks/index.js.map +1 -1
  140. package/build/hooks/layout.js +31 -14
  141. package/build/hooks/layout.js.map +1 -1
  142. package/build/hooks/position.js +4 -2
  143. package/build/hooks/position.js.map +1 -1
  144. package/build/hooks/style.js +74 -25
  145. package/build/hooks/style.js.map +1 -1
  146. package/build/hooks/utils.js +4 -0
  147. package/build/hooks/utils.js.map +1 -1
  148. package/build/private-apis.js +2 -0
  149. package/build/private-apis.js.map +1 -1
  150. package/build/store/actions.js +33 -10
  151. package/build/store/actions.js.map +1 -1
  152. package/build/store/private-actions.js +42 -8
  153. package/build/store/private-actions.js.map +1 -1
  154. package/build/store/private-selectors.js +23 -0
  155. package/build/store/private-selectors.js.map +1 -1
  156. package/build/store/reducer.js +43 -1
  157. package/build/store/reducer.js.map +1 -1
  158. package/build/store/selectors.js +84 -23
  159. package/build/store/selectors.js.map +1 -1
  160. package/build/store/utils.js +0 -4
  161. package/build/store/utils.js.map +1 -1
  162. package/build-module/components/block-canvas/index.js +97 -0
  163. package/build-module/components/block-canvas/index.js.map +1 -0
  164. package/build-module/components/block-inspector/index.js +4 -1
  165. package/build-module/components/block-inspector/index.js.map +1 -1
  166. package/build-module/components/block-patterns-list/index.js +20 -5
  167. package/build-module/components/block-patterns-list/index.js.map +1 -1
  168. package/build-module/components/block-patterns-paging/index.js +59 -0
  169. package/build-module/components/block-patterns-paging/index.js.map +1 -0
  170. package/build-module/components/block-settings-menu/block-settings-dropdown.js +28 -0
  171. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  172. package/build-module/components/block-settings-menu-controls/index.js +4 -7
  173. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  174. package/build-module/components/block-styles/index.js +1 -0
  175. package/build-module/components/block-styles/index.js.map +1 -1
  176. package/build-module/components/block-toolbar/block-toolbar-menu.native.js +3 -7
  177. package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
  178. package/build-module/components/block-tools/block-contextual-toolbar.js +18 -7
  179. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  180. package/build-module/components/block-tools/block-selection-button.js +5 -1
  181. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  182. package/build-module/components/border-radius-control/input-controls.js +1 -1
  183. package/build-module/components/border-radius-control/input-controls.js.map +1 -1
  184. package/build-module/components/border-radius-control/linked-button.js +2 -4
  185. package/build-module/components/border-radius-control/linked-button.js.map +1 -1
  186. package/build-module/components/colors/with-colors.js.map +1 -1
  187. package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -21
  188. package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
  189. package/build-module/components/default-block-appender/index.native.js +20 -1
  190. package/build-module/components/default-block-appender/index.native.js.map +1 -1
  191. package/build-module/components/duotone/utils.js +65 -0
  192. package/build-module/components/duotone/utils.js.map +1 -1
  193. package/build-module/components/editor-styles/index.js +28 -9
  194. package/build-module/components/editor-styles/index.js.map +1 -1
  195. package/build-module/components/global-styles/hooks.js +3 -100
  196. package/build-module/components/global-styles/hooks.js.map +1 -1
  197. package/build-module/components/global-styles/image-settings-panel.js +53 -0
  198. package/build-module/components/global-styles/image-settings-panel.js.map +1 -0
  199. package/build-module/components/global-styles/index.js +2 -2
  200. package/build-module/components/global-styles/index.js.map +1 -1
  201. package/build-module/components/global-styles/use-global-styles-output.js +18 -16
  202. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  203. package/build-module/components/global-styles/utils.js +1 -1
  204. package/build-module/components/global-styles/utils.js.map +1 -1
  205. package/build-module/components/iframe/index.js +66 -33
  206. package/build-module/components/iframe/index.js.map +1 -1
  207. package/build-module/components/image-editor/use-save-image.js +2 -5
  208. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  209. package/build-module/components/image-editor/use-transform-image.js +9 -9
  210. package/build-module/components/image-editor/use-transform-image.js.map +1 -1
  211. package/build-module/components/index.js +1 -1
  212. package/build-module/components/index.js.map +1 -1
  213. package/build-module/components/index.native.js +2 -1
  214. package/build-module/components/index.native.js.map +1 -1
  215. package/build-module/components/inner-blocks/use-nested-settings-update.js +14 -8
  216. package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  217. package/build-module/components/inserter/block-patterns-explorer/explorer.js +12 -6
  218. package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
  219. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +59 -25
  220. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
  221. package/build-module/components/inserter/block-patterns-explorer/sidebar.js +23 -9
  222. package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
  223. package/build-module/components/inserter/block-patterns-source-filter.js +44 -0
  224. package/build-module/components/inserter/block-patterns-source-filter.js.map +1 -0
  225. package/build-module/components/inserter/block-patterns-sync-filter.js +38 -0
  226. package/build-module/components/inserter/block-patterns-sync-filter.js.map +1 -0
  227. package/build-module/components/inserter/block-patterns-tab.js +87 -46
  228. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  229. package/build-module/components/inserter/hooks/use-patterns-paging.js +50 -0
  230. package/build-module/components/inserter/hooks/use-patterns-paging.js.map +1 -0
  231. package/build-module/components/inserter/hooks/use-patterns-state.js +22 -10
  232. package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
  233. package/build-module/components/inserter/menu.js +13 -11
  234. package/build-module/components/inserter/menu.js.map +1 -1
  235. package/build-module/components/inserter/search-results.js +4 -3
  236. package/build-module/components/inserter/search-results.js.map +1 -1
  237. package/build-module/components/inserter/tabs.js +1 -12
  238. package/build-module/components/inserter/tabs.js.map +1 -1
  239. package/build-module/components/inspector-controls/block-support-slot-container.js +13 -2
  240. package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
  241. package/build-module/components/inspector-controls/fill.js +25 -14
  242. package/build-module/components/inspector-controls/fill.js.map +1 -1
  243. package/build-module/components/inspector-controls/groups.js +5 -3
  244. package/build-module/components/inspector-controls/groups.js.map +1 -1
  245. package/build-module/components/inspector-controls/slot.js +15 -1
  246. package/build-module/components/inspector-controls/slot.js.map +1 -1
  247. package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
  248. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  249. package/build-module/components/link-control/index.js +13 -2
  250. package/build-module/components/link-control/index.js.map +1 -1
  251. package/build-module/components/link-control/settings.js +2 -1
  252. package/build-module/components/link-control/settings.js.map +1 -1
  253. package/build-module/components/list-view/block-select-button.js +1 -3
  254. package/build-module/components/list-view/block-select-button.js.map +1 -1
  255. package/build-module/components/list-view/block.js +13 -1
  256. package/build-module/components/list-view/block.js.map +1 -1
  257. package/build-module/components/list-view/use-block-selection.js +30 -25
  258. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  259. package/build-module/components/media-placeholder/index.js +2 -2
  260. package/build-module/components/media-placeholder/index.js.map +1 -1
  261. package/build-module/components/media-placeholder/index.native.js +7 -7
  262. package/build-module/components/media-placeholder/index.native.js.map +1 -1
  263. package/build-module/components/media-replace-flow/index.js +2 -3
  264. package/build-module/components/media-replace-flow/index.js.map +1 -1
  265. package/build-module/components/media-upload/constants.js +14 -0
  266. package/build-module/components/media-upload/constants.js.map +1 -0
  267. package/build-module/components/media-upload/index.native.js +53 -34
  268. package/build-module/components/media-upload/index.native.js.map +1 -1
  269. package/build-module/components/preview-options/index.js +1 -1
  270. package/build-module/components/preview-options/index.js.map +1 -1
  271. package/build-module/components/rich-text/index.js +35 -37
  272. package/build-module/components/rich-text/index.js.map +1 -1
  273. package/build-module/components/rich-text/index.native.js +15 -33
  274. package/build-module/components/rich-text/index.native.js.map +1 -1
  275. package/build-module/components/rich-text/multiline.js +87 -0
  276. package/build-module/components/rich-text/multiline.js.map +1 -0
  277. package/build-module/components/rich-text/split-value.js +10 -16
  278. package/build-module/components/rich-text/split-value.js.map +1 -1
  279. package/build-module/components/rich-text/use-enter.js +33 -42
  280. package/build-module/components/rich-text/use-enter.js.map +1 -1
  281. package/build-module/components/rich-text/use-paste-handler.js +19 -34
  282. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  283. package/build-module/components/spacing-sizes-control/utils.js +2 -2
  284. package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
  285. package/build-module/components/use-block-commands/index.js +28 -16
  286. package/build-module/components/use-block-commands/index.js.map +1 -1
  287. package/build-module/components/use-block-display-information/index.js +5 -2
  288. package/build-module/components/use-block-display-information/index.js.map +1 -1
  289. package/build-module/hooks/background.js +244 -0
  290. package/build-module/hooks/background.js.map +1 -0
  291. package/build-module/hooks/block-hooks.js +181 -0
  292. package/build-module/hooks/block-hooks.js.map +1 -0
  293. package/build-module/hooks/block-rename-ui.js +153 -0
  294. package/build-module/hooks/block-rename-ui.js.map +1 -0
  295. package/build-module/hooks/duotone.js +26 -39
  296. package/build-module/hooks/duotone.js.map +1 -1
  297. package/build-module/hooks/index.js +2 -2
  298. package/build-module/hooks/index.js.map +1 -1
  299. package/build-module/hooks/layout.js +33 -16
  300. package/build-module/hooks/layout.js.map +1 -1
  301. package/build-module/hooks/position.js +4 -2
  302. package/build-module/hooks/position.js.map +1 -1
  303. package/build-module/hooks/style.js +73 -24
  304. package/build-module/hooks/style.js.map +1 -1
  305. package/build-module/hooks/utils.js +4 -0
  306. package/build-module/hooks/utils.js.map +1 -1
  307. package/build-module/private-apis.js +2 -0
  308. package/build-module/private-apis.js.map +1 -1
  309. package/build-module/store/actions.js +33 -10
  310. package/build-module/store/actions.js.map +1 -1
  311. package/build-module/store/private-actions.js +39 -8
  312. package/build-module/store/private-actions.js.map +1 -1
  313. package/build-module/store/private-selectors.js +21 -0
  314. package/build-module/store/private-selectors.js.map +1 -1
  315. package/build-module/store/reducer.js +41 -1
  316. package/build-module/store/reducer.js.map +1 -1
  317. package/build-module/store/selectors.js +78 -22
  318. package/build-module/store/selectors.js.map +1 -1
  319. package/build-module/store/utils.js +0 -4
  320. package/build-module/store/utils.js.map +1 -1
  321. package/build-style/content-rtl.css +0 -1
  322. package/build-style/content.css +0 -1
  323. package/build-style/style-rtl.css +174 -131
  324. package/build-style/style.css +174 -131
  325. package/package.json +32 -32
  326. package/src/components/block-canvas/index.js +108 -0
  327. package/src/components/block-inspector/index.js +5 -1
  328. package/src/components/block-list/content.scss +0 -1
  329. package/src/components/block-patterns-list/index.js +32 -7
  330. package/src/components/block-patterns-list/style.scss +26 -9
  331. package/src/components/block-patterns-paging/index.js +92 -0
  332. package/src/components/block-patterns-paging/style.scss +42 -0
  333. package/src/components/block-settings-menu/block-settings-dropdown.js +44 -0
  334. package/src/components/block-settings-menu-controls/index.js +4 -9
  335. package/src/components/block-styles/index.js +1 -0
  336. package/src/components/block-styles/style.scss +3 -3
  337. package/src/components/block-toolbar/block-toolbar-menu.native.js +1 -6
  338. package/src/components/block-tools/block-contextual-toolbar.js +16 -5
  339. package/src/components/block-tools/block-selection-button.js +9 -1
  340. package/src/components/block-tools/style.scss +0 -98
  341. package/src/components/border-radius-control/input-controls.js +1 -1
  342. package/src/components/border-radius-control/linked-button.js +8 -11
  343. package/src/components/color-palette/test/__snapshots__/control.js.snap +34 -21
  344. package/src/components/colors/with-colors.js +3 -2
  345. package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -35
  346. package/src/components/default-block-appender/index.native.js +26 -3
  347. package/src/components/duotone/utils.js +65 -0
  348. package/src/components/editor-styles/index.js +32 -23
  349. package/src/components/global-styles/hooks.js +4 -112
  350. package/src/components/global-styles/image-settings-panel.js +71 -0
  351. package/src/components/global-styles/index.js +4 -3
  352. package/src/components/global-styles/use-global-styles-output.js +25 -16
  353. package/src/components/global-styles/utils.js +1 -2
  354. package/src/components/iframe/index.js +72 -33
  355. package/src/components/image-editor/use-save-image.js +2 -9
  356. package/src/components/image-editor/use-transform-image.js +9 -9
  357. package/src/components/index.js +1 -1
  358. package/src/components/index.native.js +2 -2
  359. package/src/components/inner-blocks/use-nested-settings-update.js +15 -10
  360. package/src/components/inserter/block-patterns-explorer/explorer.js +17 -5
  361. package/src/components/inserter/block-patterns-explorer/patterns-list.js +109 -40
  362. package/src/components/inserter/block-patterns-explorer/sidebar.js +23 -8
  363. package/src/components/inserter/block-patterns-source-filter.js +40 -0
  364. package/src/components/inserter/block-patterns-sync-filter.js +35 -0
  365. package/src/components/inserter/block-patterns-tab.js +168 -57
  366. package/src/components/inserter/hooks/use-patterns-paging.js +65 -0
  367. package/src/components/inserter/hooks/use-patterns-state.js +27 -16
  368. package/src/components/inserter/menu.js +15 -17
  369. package/src/components/inserter/search-results.js +6 -4
  370. package/src/components/inserter/style.scss +23 -2
  371. package/src/components/inserter/tabs.js +2 -12
  372. package/src/components/inserter/test/index.native.js +8 -12
  373. package/src/components/inspector-controls/block-support-slot-container.js +19 -3
  374. package/src/components/inspector-controls/fill.js +28 -14
  375. package/src/components/inspector-controls/groups.js +6 -2
  376. package/src/components/inspector-controls/slot.js +28 -3
  377. package/src/components/inspector-controls-tabs/styles-tab.js +4 -0
  378. package/src/components/link-control/index.js +14 -0
  379. package/src/components/link-control/settings.js +1 -0
  380. package/src/components/link-control/style.scss +28 -7
  381. package/src/components/link-control/test/index.js +88 -6
  382. package/src/components/list-view/block-select-button.js +1 -3
  383. package/src/components/list-view/block.js +19 -1
  384. package/src/components/list-view/style.scss +1 -2
  385. package/src/components/list-view/use-block-selection.js +38 -32
  386. package/src/components/media-placeholder/README.md +2 -2
  387. package/src/components/media-placeholder/index.js +2 -2
  388. package/src/components/media-placeholder/index.native.js +11 -12
  389. package/src/components/media-replace-flow/index.js +2 -2
  390. package/src/components/media-replace-flow/test/index.js +5 -23
  391. package/src/components/media-upload/README.md +3 -2
  392. package/src/components/media-upload/constants.js +15 -0
  393. package/src/components/media-upload/index.native.js +66 -40
  394. package/src/components/media-upload/style.native.scss +4 -0
  395. package/src/components/media-upload/test/index.native.js +2 -2
  396. package/src/components/preview-options/README.md +7 -0
  397. package/src/components/preview-options/index.js +1 -1
  398. package/src/components/rich-text/index.js +48 -44
  399. package/src/components/rich-text/index.native.js +14 -42
  400. package/src/components/rich-text/multiline.js +121 -0
  401. package/src/components/rich-text/split-value.js +10 -35
  402. package/src/components/rich-text/use-enter.js +32 -42
  403. package/src/components/rich-text/use-paste-handler.js +16 -40
  404. package/src/components/spacing-sizes-control/style.scss +5 -7
  405. package/src/components/spacing-sizes-control/utils.js +1 -2
  406. package/src/components/use-block-commands/index.js +28 -20
  407. package/src/components/use-block-display-information/index.js +3 -0
  408. package/src/hooks/background.js +288 -0
  409. package/src/hooks/background.scss +57 -0
  410. package/src/hooks/block-hooks.js +257 -0
  411. package/src/hooks/block-hooks.scss +16 -0
  412. package/src/hooks/block-rename-ui.js +230 -0
  413. package/src/hooks/block-rename-ui.scss +3 -0
  414. package/src/hooks/duotone.js +42 -43
  415. package/src/hooks/index.js +2 -2
  416. package/src/hooks/layout.js +31 -33
  417. package/src/hooks/position.js +4 -3
  418. package/src/hooks/style.js +96 -37
  419. package/src/hooks/test/align.native.js +4 -3
  420. package/src/hooks/utils.js +4 -0
  421. package/src/private-apis.js +2 -0
  422. package/src/store/actions.js +52 -10
  423. package/src/store/private-actions.js +37 -6
  424. package/src/store/private-selectors.js +21 -0
  425. package/src/store/reducer.js +38 -0
  426. package/src/store/selectors.js +107 -26
  427. package/src/store/test/actions.js +19 -8
  428. package/src/store/test/private-actions.js +17 -0
  429. package/src/store/test/reducer.js +25 -0
  430. package/src/store/test/selectors.js +130 -123
  431. package/src/store/utils.js +3 -10
  432. package/src/style.scss +4 -0
  433. package/build/components/duotone/components.js +0 -135
  434. package/build/components/duotone/components.js.map +0 -1
  435. package/build/components/duotone/index.js +0 -38
  436. package/build/components/duotone/index.js.map +0 -1
  437. package/build/components/global-styles/behaviors-panel.js +0 -64
  438. package/build/components/global-styles/behaviors-panel.js.map +0 -1
  439. package/build/components/inserter/reusable-blocks-tab.js +0 -85
  440. package/build/components/inserter/reusable-blocks-tab.js.map +0 -1
  441. package/build/hooks/auto-inserting-blocks.js +0 -174
  442. package/build/hooks/auto-inserting-blocks.js.map +0 -1
  443. package/build/hooks/behaviors.js +0 -173
  444. package/build/hooks/behaviors.js.map +0 -1
  445. package/build-module/components/duotone/components.js +0 -126
  446. package/build-module/components/duotone/components.js.map +0 -1
  447. package/build-module/components/duotone/index.js +0 -3
  448. package/build-module/components/duotone/index.js.map +0 -1
  449. package/build-module/components/global-styles/behaviors-panel.js +0 -57
  450. package/build-module/components/global-styles/behaviors-panel.js.map +0 -1
  451. package/build-module/components/inserter/reusable-blocks-tab.js +0 -76
  452. package/build-module/components/inserter/reusable-blocks-tab.js.map +0 -1
  453. package/build-module/hooks/auto-inserting-blocks.js +0 -167
  454. package/build-module/hooks/auto-inserting-blocks.js.map +0 -1
  455. package/build-module/hooks/behaviors.js +0 -166
  456. package/build-module/hooks/behaviors.js.map +0 -1
  457. package/src/components/duotone/components.js +0 -133
  458. package/src/components/duotone/index.js +0 -7
  459. package/src/components/global-styles/behaviors-panel.js +0 -71
  460. package/src/components/inserter/reusable-blocks-tab.js +0 -84
  461. package/src/components/inserter/test/reusable-blocks-tab.js +0 -73
  462. package/src/hooks/auto-inserting-blocks.js +0 -232
  463. package/src/hooks/behaviors.js +0 -206
@@ -0,0 +1,244 @@
1
+ import { createElement } from "@wordpress/element";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { isBlobURL } from '@wordpress/blob';
6
+ import { getBlockSupport } from '@wordpress/blocks';
7
+ import { __experimentalToolsPanelItem as ToolsPanelItem, Button, DropZone, FlexItem, MenuItem, __experimentalItemGroup as ItemGroup, __experimentalHStack as HStack, __experimentalTruncate as Truncate } from '@wordpress/components';
8
+ import { useDispatch, useSelect } from '@wordpress/data';
9
+ import { Platform, useCallback } from '@wordpress/element';
10
+ import { __ } from '@wordpress/i18n';
11
+ import { store as noticesStore } from '@wordpress/notices';
12
+ import { getFilename } from '@wordpress/url';
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+ import InspectorControls from '../components/inspector-controls';
18
+ import MediaReplaceFlow from '../components/media-replace-flow';
19
+ import MediaUpload from '../components/media-upload';
20
+ import MediaUploadCheck from '../components/media-upload/check';
21
+ import useSetting from '../components/use-setting';
22
+ import { cleanEmptyObject } from './utils';
23
+ import { store as blockEditorStore } from '../store';
24
+ export const BACKGROUND_SUPPORT_KEY = 'background';
25
+ export const IMAGE_BACKGROUND_TYPE = 'image';
26
+
27
+ /**
28
+ * Checks if there is a current value in the background image block support
29
+ * attributes.
30
+ *
31
+ * @param {Object} props Block props.
32
+ * @return {boolean} Whether or not the block has a background image value set.
33
+ */
34
+ export function hasBackgroundImageValue(props) {
35
+ const hasValue = !!props.attributes.style?.background?.backgroundImage?.id || !!props.attributes.style?.background?.backgroundImage?.url;
36
+ return hasValue;
37
+ }
38
+
39
+ /**
40
+ * Determine whether there is block support for background.
41
+ *
42
+ * @param {string} blockName Block name.
43
+ * @param {string} feature Background image feature to check for.
44
+ *
45
+ * @return {boolean} Whether there is support.
46
+ */
47
+ export function hasBackgroundSupport(blockName, feature = 'any') {
48
+ if (Platform.OS !== 'web') {
49
+ return false;
50
+ }
51
+ const support = getBlockSupport(blockName, BACKGROUND_SUPPORT_KEY);
52
+ if (support === true) {
53
+ return true;
54
+ }
55
+ if (feature === 'any') {
56
+ return !!support?.backgroundImage;
57
+ }
58
+ return !!support?.[feature];
59
+ }
60
+
61
+ /**
62
+ * Resets the background image block support attributes. This can be used when disabling
63
+ * the background image controls for a block via a `ToolsPanel`.
64
+ *
65
+ * @param {Object} props Block props.
66
+ * @param {Object} props.attributes Block's attributes.
67
+ * @param {Object} props.setAttributes Function to set block's attributes.
68
+ */
69
+ export function resetBackgroundImage({
70
+ attributes = {},
71
+ setAttributes
72
+ }) {
73
+ const {
74
+ style = {}
75
+ } = attributes;
76
+ setAttributes({
77
+ style: cleanEmptyObject({
78
+ ...style,
79
+ background: {
80
+ ...style?.background,
81
+ backgroundImage: undefined
82
+ }
83
+ })
84
+ });
85
+ }
86
+ function InspectorImagePreview({
87
+ label,
88
+ url: imgUrl
89
+ }) {
90
+ const imgLabel = label || getFilename(imgUrl);
91
+ return createElement(ItemGroup, {
92
+ as: "span"
93
+ }, createElement(HStack, {
94
+ justify: "flex-start",
95
+ as: "span"
96
+ }, createElement("img", {
97
+ src: imgUrl,
98
+ alt: ""
99
+ }), createElement(FlexItem, {
100
+ as: "span"
101
+ }, createElement(Truncate, {
102
+ numberOfLines: 1,
103
+ className: "block-editor-hooks__background__inspector-media-replace-title"
104
+ }, imgLabel))));
105
+ }
106
+ function BackgroundImagePanelItem(props) {
107
+ const {
108
+ attributes,
109
+ clientId,
110
+ setAttributes
111
+ } = props;
112
+ const {
113
+ id,
114
+ title,
115
+ url
116
+ } = attributes.style?.background?.backgroundImage || {};
117
+ const {
118
+ mediaUpload
119
+ } = useSelect(select => {
120
+ return {
121
+ mediaUpload: select(blockEditorStore).getSettings().mediaUpload
122
+ };
123
+ });
124
+ const {
125
+ createErrorNotice
126
+ } = useDispatch(noticesStore);
127
+ const onUploadError = message => {
128
+ createErrorNotice(message, {
129
+ type: 'snackbar'
130
+ });
131
+ };
132
+ const onSelectMedia = media => {
133
+ if (!media || !media.url) {
134
+ const newStyle = {
135
+ ...attributes.style,
136
+ background: {
137
+ ...attributes.style?.background,
138
+ backgroundImage: undefined
139
+ }
140
+ };
141
+ const newAttributes = {
142
+ style: cleanEmptyObject(newStyle)
143
+ };
144
+ setAttributes(newAttributes);
145
+ return;
146
+ }
147
+ if (isBlobURL(media.url)) {
148
+ return;
149
+ }
150
+
151
+ // For media selections originated from a file upload.
152
+ if (media.media_type && media.media_type !== IMAGE_BACKGROUND_TYPE || !media.media_type && media.type && media.type !== IMAGE_BACKGROUND_TYPE) {
153
+ onUploadError(__('Only images can be used as a background image.'));
154
+ return;
155
+ }
156
+ const newStyle = {
157
+ ...attributes.style,
158
+ background: {
159
+ ...attributes.style?.background,
160
+ backgroundImage: {
161
+ url: media.url,
162
+ id: media.id,
163
+ source: 'file',
164
+ title: media.title || undefined
165
+ }
166
+ }
167
+ };
168
+ const newAttributes = {
169
+ style: cleanEmptyObject(newStyle)
170
+ };
171
+ setAttributes(newAttributes);
172
+ };
173
+ const onFilesDrop = filesList => {
174
+ mediaUpload({
175
+ allowedTypes: ['image'],
176
+ filesList,
177
+ onFileChange([image]) {
178
+ if (isBlobURL(image?.url)) {
179
+ return;
180
+ }
181
+ onSelectMedia(image);
182
+ },
183
+ onError: onUploadError
184
+ });
185
+ };
186
+ const resetAllFilter = useCallback(previousValue => {
187
+ return {
188
+ ...previousValue,
189
+ style: {
190
+ ...previousValue.style,
191
+ background: undefined
192
+ }
193
+ };
194
+ }, []);
195
+ return createElement(ToolsPanelItem, {
196
+ className: "single-column",
197
+ hasValue: () => hasBackgroundImageValue(props),
198
+ label: __('Background image'),
199
+ onDeselect: () => resetBackgroundImage(props),
200
+ isShownByDefault: true,
201
+ resetAllFilter: resetAllFilter,
202
+ panelId: clientId
203
+ }, createElement("div", {
204
+ className: "block-editor-hooks__background__inspector-media-replace-container"
205
+ }, !!url && createElement(MediaReplaceFlow, {
206
+ mediaId: id,
207
+ mediaURL: url,
208
+ allowedTypes: [IMAGE_BACKGROUND_TYPE],
209
+ accept: "image/*",
210
+ onSelect: onSelectMedia,
211
+ name: createElement(InspectorImagePreview, {
212
+ label: title,
213
+ url: url
214
+ }),
215
+ variant: "secondary"
216
+ }, createElement(MenuItem, {
217
+ onClick: () => resetBackgroundImage(props)
218
+ }, __('Reset '))), !url && createElement(MediaUploadCheck, null, createElement(MediaUpload, {
219
+ onSelect: onSelectMedia,
220
+ allowedTypes: [IMAGE_BACKGROUND_TYPE],
221
+ render: ({
222
+ open
223
+ }) => createElement("div", {
224
+ className: "block-editor-hooks__background__inspector-upload-container"
225
+ }, createElement(Button, {
226
+ onClick: open,
227
+ variant: "secondary"
228
+ }, __('Add background image')), createElement(DropZone, {
229
+ onFilesDrop: onFilesDrop
230
+ }))
231
+ }))));
232
+ }
233
+ export function BackgroundImagePanel(props) {
234
+ const isBackgroundImageSupported = useSetting('background.backgroundImage') && hasBackgroundSupport(props.name, 'backgroundImage');
235
+ if (!isBackgroundImageSupported) {
236
+ return null;
237
+ }
238
+ return createElement(InspectorControls, {
239
+ group: "background"
240
+ }, isBackgroundImageSupported && createElement(BackgroundImagePanelItem, {
241
+ ...props
242
+ }));
243
+ }
244
+ //# sourceMappingURL=background.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isBlobURL","getBlockSupport","__experimentalToolsPanelItem","ToolsPanelItem","Button","DropZone","FlexItem","MenuItem","__experimentalItemGroup","ItemGroup","__experimentalHStack","HStack","__experimentalTruncate","Truncate","useDispatch","useSelect","Platform","useCallback","__","store","noticesStore","getFilename","InspectorControls","MediaReplaceFlow","MediaUpload","MediaUploadCheck","useSetting","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","imgUrl","imgLabel","createElement","as","justify","src","alt","numberOfLines","className","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","render","open","BackgroundImagePanel","isBackgroundImageSupported","group"],"sources":["@wordpress/block-editor/src/hooks/background.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { isBlobURL } from '@wordpress/blob';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport {\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\tButton,\n\tDropZone,\n\tFlexItem,\n\tMenuItem,\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 { __ } 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 MediaUpload from '../components/media-upload';\nimport MediaUploadCheck from '../components/media-upload/check';\nimport useSetting from '../components/use-setting';\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, 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<img src={ imgUrl } alt=\"\" />\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</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{ !! url && (\n\t\t\t\t\t<MediaReplaceFlow\n\t\t\t\t\t\tmediaId={ id }\n\t\t\t\t\t\tmediaURL={ url }\n\t\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\t\taccept=\"image/*\"\n\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\tname={\n\t\t\t\t\t\t\t<InspectorImagePreview\n\t\t\t\t\t\t\t\tlabel={ title }\n\t\t\t\t\t\t\t\turl={ url }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t}\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => resetBackgroundImage( props ) }\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</MediaReplaceFlow>\n\t\t\t\t) }\n\t\t\t\t{ ! url && (\n\t\t\t\t\t<MediaUploadCheck>\n\t\t\t\t\t\t<MediaUpload\n\t\t\t\t\t\t\tonSelect={ onSelectMedia }\n\t\t\t\t\t\t\tallowedTypes={ [ IMAGE_BACKGROUND_TYPE ] }\n\t\t\t\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t\t\t\t<div className=\"block-editor-hooks__background__inspector-upload-container\">\n\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\tonClick={ open }\n\t\t\t\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __( 'Add background image' ) }\n\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t<DropZone onFilesDrop={ onFilesDrop } />\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</MediaUploadCheck>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</ToolsPanelItem>\n\t);\n}\n\nexport function BackgroundImagePanel( props ) {\n\tconst isBackgroundImageSupported =\n\t\tuseSetting( 'background.backgroundImage' ) &&\n\t\thasBackgroundSupport( props.name, 'backgroundImage' );\n\n\tif ( ! isBackgroundImageSupported ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<InspectorControls group=\"background\">\n\t\t\t{ is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Q;MAACsE,WAAW,EAAGA;IAAa,CAAE,CACnC;EACH,CACH,CACgB,CAEf,CACU,CAAC;AAEnB;AAEA,OAAO,SAASoB,oBAAoBA,CAAE/D,KAAK,EAAG;EAC7C,MAAMgE,0BAA0B,GAC/BtE,UAAU,CAAE,4BAA6B,CAAC,IAC1Cc,oBAAoB,CAAER,KAAK,CAAC0D,IAAI,EAAE,iBAAkB,CAAC;EAEtD,IAAK,CAAEM,0BAA0B,EAAG;IACnC,OAAO,IAAI;EACZ;EAEA,OACC5C,aAAA,CAAC9B,iBAAiB;IAAC2E,KAAK,EAAC;EAAY,GAClCD,0BAA0B,IAC3B5C,aAAA,CAACO,wBAAwB;IAAA,GAAM3B;EAAK,CAAI,CAEvB,CAAC;AAEtB"}
@@ -0,0 +1,181 @@
1
+ import { createElement } from "@wordpress/element";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { __ } from '@wordpress/i18n';
6
+ import { addFilter } from '@wordpress/hooks';
7
+ import { Fragment, useMemo } from '@wordpress/element';
8
+ import { __experimentalHStack as HStack, PanelBody, ToggleControl } from '@wordpress/components';
9
+ import { createHigherOrderComponent } from '@wordpress/compose';
10
+ import { createBlock, store as blocksStore } from '@wordpress/blocks';
11
+ import { useDispatch, useSelect } from '@wordpress/data';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { BlockIcon, InspectorControls } from '../components';
17
+ import { store as blockEditorStore } from '../store';
18
+ const EMPTY_OBJECT = {};
19
+ function BlockHooksControl(props) {
20
+ const blockTypes = useSelect(select => select(blocksStore).getBlockTypes(), []);
21
+ const hookedBlocksForCurrentBlock = useMemo(() => blockTypes?.filter(({
22
+ blockHooks
23
+ }) => blockHooks && props.blockName in blockHooks), [blockTypes, props.blockName]);
24
+ const {
25
+ blockIndex,
26
+ rootClientId,
27
+ innerBlocksLength
28
+ } = useSelect(select => {
29
+ const {
30
+ getBlock,
31
+ getBlockIndex,
32
+ getBlockRootClientId
33
+ } = select(blockEditorStore);
34
+ return {
35
+ blockIndex: getBlockIndex(props.clientId),
36
+ innerBlocksLength: getBlock(props.clientId)?.innerBlocks?.length,
37
+ rootClientId: getBlockRootClientId(props.clientId)
38
+ };
39
+ }, [props.clientId]);
40
+ const hookedBlockClientIds = useSelect(select => {
41
+ const {
42
+ getBlock,
43
+ getGlobalBlockCount
44
+ } = select(blockEditorStore);
45
+ const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce((clientIds, block) => {
46
+ // If the block doesn't exist anywhere in the block tree,
47
+ // we know that we have to display the toggle for it, and set
48
+ // it to disabled.
49
+ if (getGlobalBlockCount(block.name) === 0) {
50
+ return clientIds;
51
+ }
52
+ const relativePosition = block?.blockHooks?.[props.blockName];
53
+ let candidates;
54
+ switch (relativePosition) {
55
+ case 'before':
56
+ case 'after':
57
+ // Any of the current block's siblings (with the right block type) qualifies
58
+ // as a hooked block (inserted `before` or `after` the current one), as the block
59
+ // might've been automatically inserted and then moved around a bit by the user.
60
+ candidates = getBlock(rootClientId)?.innerBlocks;
61
+ break;
62
+ case 'first_child':
63
+ case 'last_child':
64
+ // Any of the current block's child blocks (with the right block type) qualifies
65
+ // as a hooked first or last child block, as the block might've been automatically
66
+ // inserted and then moved around a bit by the user.
67
+ candidates = getBlock(props.clientId).innerBlocks;
68
+ break;
69
+ }
70
+ const hookedBlock = candidates?.find(({
71
+ name
72
+ }) => name === block.name);
73
+
74
+ // If the block exists in the designated location, we consider it hooked
75
+ // and show the toggle as enabled.
76
+ if (hookedBlock) {
77
+ return {
78
+ ...clientIds,
79
+ [block.name]: hookedBlock.clientId
80
+ };
81
+ }
82
+
83
+ // If no hooked block was found in any of its designated locations,
84
+ // but it exists elsewhere in the block tree, we consider it manually inserted.
85
+ // In this case, we take note and will remove the corresponding toggle from the
86
+ // block inspector panel.
87
+ return {
88
+ ...clientIds,
89
+ [block.name]: false
90
+ };
91
+ }, {});
92
+ if (Object.values(_hookedBlockClientIds).length > 0) {
93
+ return _hookedBlockClientIds;
94
+ }
95
+ return EMPTY_OBJECT;
96
+ }, [hookedBlocksForCurrentBlock, props.blockName, props.clientId, rootClientId]);
97
+ const {
98
+ insertBlock,
99
+ removeBlock
100
+ } = useDispatch(blockEditorStore);
101
+
102
+ // Remove toggle if block isn't present in the designated location but elsewhere in the block tree.
103
+ const hookedBlocksForCurrentBlockIfNotPresentElsewhere = hookedBlocksForCurrentBlock?.filter(block => hookedBlockClientIds?.[block.name] !== false);
104
+ if (!hookedBlocksForCurrentBlockIfNotPresentElsewhere.length) {
105
+ return null;
106
+ }
107
+
108
+ // Group by block namespace (i.e. prefix before the slash).
109
+ const groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce((groups, block) => {
110
+ const [namespace] = block.name.split('/');
111
+ if (!groups[namespace]) {
112
+ groups[namespace] = [];
113
+ }
114
+ groups[namespace].push(block);
115
+ return groups;
116
+ }, {});
117
+ const insertBlockIntoDesignatedLocation = (block, relativePosition) => {
118
+ switch (relativePosition) {
119
+ case 'before':
120
+ case 'after':
121
+ insertBlock(block, relativePosition === 'after' ? blockIndex + 1 : blockIndex, rootClientId,
122
+ // Insert as a child of the current block's parent
123
+ false);
124
+ break;
125
+ case 'first_child':
126
+ case 'last_child':
127
+ insertBlock(block,
128
+ // TODO: It'd be great if insertBlock() would accept negative indices for insertion.
129
+ relativePosition === 'first_child' ? 0 : innerBlocksLength, props.clientId,
130
+ // Insert as a child of the current block.
131
+ false);
132
+ break;
133
+ }
134
+ };
135
+ return createElement(InspectorControls, null, createElement(PanelBody, {
136
+ className: "block-editor-hooks__block-hooks",
137
+ title: __('Plugins'),
138
+ initialOpen: true
139
+ }, Object.keys(groupedHookedBlocks).map(vendor => {
140
+ return createElement(Fragment, {
141
+ key: vendor
142
+ }, createElement("h3", null, vendor), groupedHookedBlocks[vendor].map(block => {
143
+ const checked = (block.name in hookedBlockClientIds);
144
+ return createElement(ToggleControl, {
145
+ checked: checked,
146
+ key: block.title,
147
+ label: createElement(HStack, {
148
+ justify: "flex-start"
149
+ }, createElement(BlockIcon, {
150
+ icon: block.icon
151
+ }), createElement("span", null, block.title)),
152
+ onChange: () => {
153
+ if (!checked) {
154
+ // Create and insert block.
155
+ const relativePosition = block.blockHooks[props.blockName];
156
+ insertBlockIntoDesignatedLocation(createBlock(block.name), relativePosition);
157
+ return;
158
+ }
159
+
160
+ // Remove block.
161
+ const clientId = hookedBlockClientIds[block.name];
162
+ removeBlock(clientId, false);
163
+ }
164
+ });
165
+ }));
166
+ })));
167
+ }
168
+ export const withBlockHooks = createHigherOrderComponent(BlockEdit => {
169
+ return props => {
170
+ const blockEdit = createElement(BlockEdit, {
171
+ key: "edit",
172
+ ...props
173
+ });
174
+ return createElement(Fragment, null, blockEdit, createElement(BlockHooksControl, {
175
+ blockName: props.name,
176
+ clientId: props.clientId
177
+ }));
178
+ };
179
+ }, 'withBlockHooks');
180
+ addFilter('editor.BlockEdit', 'core/block-hooks/with-inspector-control', withBlockHooks);
181
+ //# sourceMappingURL=block-hooks.js.map
@@ -0,0 +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\t);\n\t};\n}, 'withBlockHooks' );\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/block-hooks/with-inspector-control',\n\twithBlockHooks\n);\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,QAAQ,EAAEC,OAAO,QAAQ,oBAAoB;AAC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AAIgE,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"}
@@ -0,0 +1,153 @@
1
+ import { createElement, Fragment } from "@wordpress/element";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
6
+ import { addFilter } from '@wordpress/hooks';
7
+ import { __, sprintf } from '@wordpress/i18n';
8
+ import { getBlockSupport } from '@wordpress/blocks';
9
+ import { MenuItem, __experimentalHStack as HStack, __experimentalVStack as VStack, Button, TextControl, Modal } from '@wordpress/components';
10
+ import { useState } from '@wordpress/element';
11
+ import { speak } from '@wordpress/a11y';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { BlockSettingsMenuControls, useBlockDisplayInformation, InspectorControls } from '../components';
17
+ const emptyString = testString => testString?.trim()?.length === 0;
18
+ function RenameModal({
19
+ blockName,
20
+ originalBlockName,
21
+ onClose,
22
+ onSave
23
+ }) {
24
+ const [editedBlockName, setEditedBlockName] = useState(blockName);
25
+ const nameHasChanged = editedBlockName !== blockName;
26
+ const nameIsOriginal = editedBlockName === originalBlockName;
27
+ const nameIsEmpty = emptyString(editedBlockName);
28
+ const isNameValid = nameHasChanged || nameIsOriginal;
29
+ const autoSelectInputText = event => event.target.select();
30
+ const dialogDescription = useInstanceId(RenameModal, `block-editor-rename-modal__description`);
31
+ const handleSubmit = () => {
32
+ // Must be assertive to immediately announce change.
33
+ speak(sprintf( /* translators: %1$s: type of update (either reset of changed). %2$s: new name/label for the block */
34
+ __('Block name %1$s to: "%2$s".'), nameIsOriginal || nameIsEmpty ? __('reset') : __('changed'), editedBlockName), 'assertive');
35
+ onSave(editedBlockName);
36
+
37
+ // Immediate close avoids ability to hit save multiple times.
38
+ onClose();
39
+ };
40
+ return createElement(Modal, {
41
+ title: __('Rename'),
42
+ onRequestClose: onClose,
43
+ overlayClassName: "block-editor-block-rename-modal",
44
+ aria: {
45
+ describedby: dialogDescription
46
+ }
47
+ }, createElement("p", {
48
+ id: dialogDescription
49
+ }, __('Enter a custom name for this block.')), createElement("form", {
50
+ onSubmit: e => {
51
+ e.preventDefault();
52
+ if (!isNameValid) {
53
+ return;
54
+ }
55
+ handleSubmit();
56
+ }
57
+ }, createElement(VStack, {
58
+ spacing: "3"
59
+ }, createElement(TextControl, {
60
+ __nextHasNoMarginBottom: true,
61
+ value: editedBlockName,
62
+ label: __('Block name'),
63
+ hideLabelFromVision: true,
64
+ placeholder: originalBlockName,
65
+ onChange: setEditedBlockName,
66
+ onFocus: autoSelectInputText
67
+ }), createElement(HStack, {
68
+ justify: "right"
69
+ }, createElement(Button, {
70
+ variant: "tertiary",
71
+ onClick: onClose
72
+ }, __('Cancel')), createElement(Button, {
73
+ "aria-disabled": !isNameValid,
74
+ variant: "primary",
75
+ type: "submit"
76
+ }, __('Save'))))));
77
+ }
78
+ function BlockRenameControl(props) {
79
+ const [renamingBlock, setRenamingBlock] = useState(false);
80
+ const {
81
+ clientId,
82
+ customName,
83
+ onChange
84
+ } = props;
85
+ const blockInformation = useBlockDisplayInformation(clientId);
86
+ return createElement(Fragment, null, createElement(InspectorControls, {
87
+ group: "advanced"
88
+ }, createElement(TextControl, {
89
+ __nextHasNoMarginBottom: true,
90
+ label: __('Block name'),
91
+ value: customName || '',
92
+ onChange: onChange
93
+ })), createElement(BlockSettingsMenuControls, null, ({
94
+ selectedClientIds
95
+ }) => {
96
+ // Only enabled for single selections.
97
+ const canRename = selectedClientIds.length === 1 && clientId === selectedClientIds[0];
98
+
99
+ // This check ensures the `BlockSettingsMenuControls` fill
100
+ // doesn't render multiple times and also that it renders for
101
+ // the block from which the menu was triggered.
102
+ if (!canRename) {
103
+ return null;
104
+ }
105
+ return createElement(MenuItem, {
106
+ onClick: () => {
107
+ setRenamingBlock(true);
108
+ },
109
+ "aria-expanded": renamingBlock,
110
+ "aria-haspopup": "dialog"
111
+ }, __('Rename'));
112
+ }), renamingBlock && createElement(RenameModal, {
113
+ blockName: customName || '',
114
+ originalBlockName: blockInformation?.title,
115
+ onClose: () => setRenamingBlock(false),
116
+ onSave: newName => {
117
+ // If the new value is the block's original name (e.g. `Group`)
118
+ // or it is an empty string then assume the intent is to reset
119
+ // the value. Therefore reset the metadata.
120
+ if (newName === blockInformation?.title || emptyString(newName)) {
121
+ newName = undefined;
122
+ }
123
+ onChange(newName);
124
+ }
125
+ }));
126
+ }
127
+ export const withBlockRenameControl = createHigherOrderComponent(BlockEdit => props => {
128
+ const {
129
+ clientId,
130
+ name,
131
+ attributes,
132
+ setAttributes
133
+ } = props;
134
+ const metaDataSupport = getBlockSupport(name, '__experimentalMetadata', false);
135
+ const supportsBlockNaming = !!(true === metaDataSupport || metaDataSupport?.name);
136
+ return createElement(Fragment, null, supportsBlockNaming && createElement(Fragment, null, createElement(BlockRenameControl, {
137
+ clientId: clientId,
138
+ customName: attributes?.metadata?.name,
139
+ onChange: newName => {
140
+ setAttributes({
141
+ metadata: {
142
+ ...(attributes?.metadata && attributes?.metadata),
143
+ name: newName
144
+ }
145
+ });
146
+ }
147
+ })), createElement(BlockEdit, {
148
+ key: "edit",
149
+ ...props
150
+ }));
151
+ }, 'withToolbarControls');
152
+ addFilter('editor.BlockEdit', 'core/block-rename-ui/with-block-rename-control', withBlockRenameControl);
153
+ //# sourceMappingURL=block-rename-ui.js.map