@wordpress/block-editor 12.9.1-next.5a1d1283.0 → 12.10.1

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 (448) 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 +28 -8
  8. package/build/components/block-patterns-list/index.js.map +1 -1
  9. package/build/components/block-patterns-paging/index.js +68 -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 +45 -22
  61. package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
  62. package/build/components/inserter/block-patterns-explorer/sidebar.js +9 -9
  63. package/build/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
  64. package/build/components/inserter/block-patterns-filter.js +137 -0
  65. package/build/components/inserter/block-patterns-filter.js.map +1 -0
  66. package/build/components/inserter/block-patterns-tab.js +128 -42
  67. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  68. package/build/components/inserter/hooks/use-patterns-paging.js +61 -0
  69. package/build/components/inserter/hooks/use-patterns-paging.js.map +1 -0
  70. package/build/components/inserter/hooks/use-patterns-state.js +21 -10
  71. package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
  72. package/build/components/inserter/menu.js +13 -11
  73. package/build/components/inserter/menu.js.map +1 -1
  74. package/build/components/inserter/search-results.js +4 -3
  75. package/build/components/inserter/search-results.js.map +1 -1
  76. package/build/components/inserter/tabs.js +1 -12
  77. package/build/components/inserter/tabs.js.map +1 -1
  78. package/build/components/inspector-controls/block-support-slot-container.js +12 -1
  79. package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
  80. package/build/components/inspector-controls/fill.js +24 -13
  81. package/build/components/inspector-controls/fill.js.map +1 -1
  82. package/build/components/inspector-controls/groups.js +5 -3
  83. package/build/components/inspector-controls/groups.js.map +1 -1
  84. package/build/components/inspector-controls/slot.js +13 -0
  85. package/build/components/inspector-controls/slot.js.map +1 -1
  86. package/build/components/inspector-controls-tabs/styles-tab.js +3 -0
  87. package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  88. package/build/components/link-control/index.js +12 -2
  89. package/build/components/link-control/index.js.map +1 -1
  90. package/build/components/list-view/block-select-button.js +1 -3
  91. package/build/components/list-view/block-select-button.js.map +1 -1
  92. package/build/components/list-view/block.js +13 -1
  93. package/build/components/list-view/block.js.map +1 -1
  94. package/build/components/list-view/use-block-selection.js +29 -24
  95. package/build/components/list-view/use-block-selection.js.map +1 -1
  96. package/build/components/media-placeholder/index.js +2 -2
  97. package/build/components/media-placeholder/index.js.map +1 -1
  98. package/build/components/media-placeholder/index.native.js +11 -11
  99. package/build/components/media-placeholder/index.native.js.map +1 -1
  100. package/build/components/media-replace-flow/index.js +2 -3
  101. package/build/components/media-replace-flow/index.js.map +1 -1
  102. package/build/components/media-upload/constants.js +30 -0
  103. package/build/components/media-upload/constants.js.map +1 -0
  104. package/build/components/media-upload/index.native.js +63 -53
  105. package/build/components/media-upload/index.native.js.map +1 -1
  106. package/build/components/preview-options/index.js +1 -1
  107. package/build/components/preview-options/index.js.map +1 -1
  108. package/build/components/rich-text/index.js +34 -35
  109. package/build/components/rich-text/index.js.map +1 -1
  110. package/build/components/rich-text/index.native.js +14 -32
  111. package/build/components/rich-text/index.native.js.map +1 -1
  112. package/build/components/rich-text/multiline.js +95 -0
  113. package/build/components/rich-text/multiline.js.map +1 -0
  114. package/build/components/rich-text/split-value.js +10 -16
  115. package/build/components/rich-text/split-value.js.map +1 -1
  116. package/build/components/rich-text/use-enter.js +31 -40
  117. package/build/components/rich-text/use-enter.js.map +1 -1
  118. package/build/components/rich-text/use-paste-handler.js +18 -33
  119. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  120. package/build/components/spacing-sizes-control/utils.js +1 -1
  121. package/build/components/spacing-sizes-control/utils.js.map +1 -1
  122. package/build/components/use-block-commands/index.js +30 -18
  123. package/build/components/use-block-commands/index.js.map +1 -1
  124. package/build/components/use-block-display-information/index.js +5 -2
  125. package/build/components/use-block-display-information/index.js.map +1 -1
  126. package/build/hooks/background.js +263 -0
  127. package/build/hooks/background.js.map +1 -0
  128. package/build/hooks/block-hooks.js +188 -0
  129. package/build/hooks/block-hooks.js.map +1 -0
  130. package/build/hooks/block-rename-ui.js +161 -0
  131. package/build/hooks/block-rename-ui.js.map +1 -0
  132. package/build/hooks/duotone.js +29 -42
  133. package/build/hooks/duotone.js.map +1 -1
  134. package/build/hooks/index.js +2 -2
  135. package/build/hooks/index.js.map +1 -1
  136. package/build/hooks/layout.js +31 -14
  137. package/build/hooks/layout.js.map +1 -1
  138. package/build/hooks/position.js +4 -2
  139. package/build/hooks/position.js.map +1 -1
  140. package/build/hooks/style.js +10 -3
  141. package/build/hooks/style.js.map +1 -1
  142. package/build/private-apis.js +2 -0
  143. package/build/private-apis.js.map +1 -1
  144. package/build/store/actions.js +33 -10
  145. package/build/store/actions.js.map +1 -1
  146. package/build/store/private-actions.js +42 -8
  147. package/build/store/private-actions.js.map +1 -1
  148. package/build/store/private-selectors.js +25 -3
  149. package/build/store/private-selectors.js.map +1 -1
  150. package/build/store/reducer.js +43 -1
  151. package/build/store/reducer.js.map +1 -1
  152. package/build/store/selectors.js +84 -23
  153. package/build/store/selectors.js.map +1 -1
  154. package/build/store/utils.js +0 -4
  155. package/build/store/utils.js.map +1 -1
  156. package/build-module/components/block-canvas/index.js +97 -0
  157. package/build-module/components/block-canvas/index.js.map +1 -0
  158. package/build-module/components/block-inspector/index.js +4 -1
  159. package/build-module/components/block-inspector/index.js.map +1 -1
  160. package/build-module/components/block-patterns-list/index.js +30 -10
  161. package/build-module/components/block-patterns-list/index.js.map +1 -1
  162. package/build-module/components/block-patterns-paging/index.js +61 -0
  163. package/build-module/components/block-patterns-paging/index.js.map +1 -0
  164. package/build-module/components/block-settings-menu/block-settings-dropdown.js +28 -0
  165. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  166. package/build-module/components/block-settings-menu-controls/index.js +4 -7
  167. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  168. package/build-module/components/block-styles/index.js +1 -0
  169. package/build-module/components/block-styles/index.js.map +1 -1
  170. package/build-module/components/block-toolbar/block-toolbar-menu.native.js +3 -7
  171. package/build-module/components/block-toolbar/block-toolbar-menu.native.js.map +1 -1
  172. package/build-module/components/block-tools/block-contextual-toolbar.js +18 -7
  173. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  174. package/build-module/components/block-tools/block-selection-button.js +5 -1
  175. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  176. package/build-module/components/border-radius-control/input-controls.js +1 -1
  177. package/build-module/components/border-radius-control/input-controls.js.map +1 -1
  178. package/build-module/components/border-radius-control/linked-button.js +2 -4
  179. package/build-module/components/border-radius-control/linked-button.js.map +1 -1
  180. package/build-module/components/colors/with-colors.js.map +1 -1
  181. package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -21
  182. package/build-module/components/convert-to-group-buttons/use-convert-to-group-button-props.js.map +1 -1
  183. package/build-module/components/default-block-appender/index.native.js +20 -1
  184. package/build-module/components/default-block-appender/index.native.js.map +1 -1
  185. package/build-module/components/duotone/utils.js +65 -0
  186. package/build-module/components/duotone/utils.js.map +1 -1
  187. package/build-module/components/editor-styles/index.js +28 -9
  188. package/build-module/components/editor-styles/index.js.map +1 -1
  189. package/build-module/components/global-styles/hooks.js +3 -100
  190. package/build-module/components/global-styles/hooks.js.map +1 -1
  191. package/build-module/components/global-styles/image-settings-panel.js +53 -0
  192. package/build-module/components/global-styles/image-settings-panel.js.map +1 -0
  193. package/build-module/components/global-styles/index.js +2 -2
  194. package/build-module/components/global-styles/index.js.map +1 -1
  195. package/build-module/components/global-styles/use-global-styles-output.js +18 -16
  196. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  197. package/build-module/components/global-styles/utils.js +1 -1
  198. package/build-module/components/global-styles/utils.js.map +1 -1
  199. package/build-module/components/iframe/index.js +66 -33
  200. package/build-module/components/iframe/index.js.map +1 -1
  201. package/build-module/components/image-editor/use-save-image.js +2 -5
  202. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  203. package/build-module/components/image-editor/use-transform-image.js +9 -9
  204. package/build-module/components/image-editor/use-transform-image.js.map +1 -1
  205. package/build-module/components/index.js +1 -1
  206. package/build-module/components/index.js.map +1 -1
  207. package/build-module/components/index.native.js +2 -1
  208. package/build-module/components/index.native.js.map +1 -1
  209. package/build-module/components/inner-blocks/use-nested-settings-update.js +14 -8
  210. package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  211. package/build-module/components/inserter/block-patterns-explorer/explorer.js +12 -6
  212. package/build-module/components/inserter/block-patterns-explorer/explorer.js.map +1 -1
  213. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +47 -24
  214. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
  215. package/build-module/components/inserter/block-patterns-explorer/sidebar.js +9 -9
  216. package/build-module/components/inserter/block-patterns-explorer/sidebar.js.map +1 -1
  217. package/build-module/components/inserter/block-patterns-filter.js +128 -0
  218. package/build-module/components/inserter/block-patterns-filter.js.map +1 -0
  219. package/build-module/components/inserter/block-patterns-tab.js +125 -44
  220. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  221. package/build-module/components/inserter/hooks/use-patterns-paging.js +54 -0
  222. package/build-module/components/inserter/hooks/use-patterns-paging.js.map +1 -0
  223. package/build-module/components/inserter/hooks/use-patterns-state.js +22 -10
  224. package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
  225. package/build-module/components/inserter/menu.js +13 -11
  226. package/build-module/components/inserter/menu.js.map +1 -1
  227. package/build-module/components/inserter/search-results.js +4 -3
  228. package/build-module/components/inserter/search-results.js.map +1 -1
  229. package/build-module/components/inserter/tabs.js +1 -12
  230. package/build-module/components/inserter/tabs.js.map +1 -1
  231. package/build-module/components/inspector-controls/block-support-slot-container.js +13 -2
  232. package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
  233. package/build-module/components/inspector-controls/fill.js +25 -14
  234. package/build-module/components/inspector-controls/fill.js.map +1 -1
  235. package/build-module/components/inspector-controls/groups.js +5 -3
  236. package/build-module/components/inspector-controls/groups.js.map +1 -1
  237. package/build-module/components/inspector-controls/slot.js +15 -1
  238. package/build-module/components/inspector-controls/slot.js.map +1 -1
  239. package/build-module/components/inspector-controls-tabs/styles-tab.js +3 -0
  240. package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
  241. package/build-module/components/link-control/index.js +12 -2
  242. package/build-module/components/link-control/index.js.map +1 -1
  243. package/build-module/components/list-view/block-select-button.js +1 -3
  244. package/build-module/components/list-view/block-select-button.js.map +1 -1
  245. package/build-module/components/list-view/block.js +13 -1
  246. package/build-module/components/list-view/block.js.map +1 -1
  247. package/build-module/components/list-view/use-block-selection.js +30 -25
  248. package/build-module/components/list-view/use-block-selection.js.map +1 -1
  249. package/build-module/components/media-placeholder/index.js +2 -2
  250. package/build-module/components/media-placeholder/index.js.map +1 -1
  251. package/build-module/components/media-placeholder/index.native.js +7 -7
  252. package/build-module/components/media-placeholder/index.native.js.map +1 -1
  253. package/build-module/components/media-replace-flow/index.js +2 -3
  254. package/build-module/components/media-replace-flow/index.js.map +1 -1
  255. package/build-module/components/media-upload/constants.js +14 -0
  256. package/build-module/components/media-upload/constants.js.map +1 -0
  257. package/build-module/components/media-upload/index.native.js +53 -34
  258. package/build-module/components/media-upload/index.native.js.map +1 -1
  259. package/build-module/components/preview-options/index.js +1 -1
  260. package/build-module/components/preview-options/index.js.map +1 -1
  261. package/build-module/components/rich-text/index.js +35 -37
  262. package/build-module/components/rich-text/index.js.map +1 -1
  263. package/build-module/components/rich-text/index.native.js +15 -33
  264. package/build-module/components/rich-text/index.native.js.map +1 -1
  265. package/build-module/components/rich-text/multiline.js +87 -0
  266. package/build-module/components/rich-text/multiline.js.map +1 -0
  267. package/build-module/components/rich-text/split-value.js +10 -16
  268. package/build-module/components/rich-text/split-value.js.map +1 -1
  269. package/build-module/components/rich-text/use-enter.js +33 -42
  270. package/build-module/components/rich-text/use-enter.js.map +1 -1
  271. package/build-module/components/rich-text/use-paste-handler.js +19 -34
  272. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  273. package/build-module/components/spacing-sizes-control/utils.js +2 -2
  274. package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
  275. package/build-module/components/use-block-commands/index.js +28 -16
  276. package/build-module/components/use-block-commands/index.js.map +1 -1
  277. package/build-module/components/use-block-display-information/index.js +5 -2
  278. package/build-module/components/use-block-display-information/index.js.map +1 -1
  279. package/build-module/hooks/background.js +249 -0
  280. package/build-module/hooks/background.js.map +1 -0
  281. package/build-module/hooks/block-hooks.js +181 -0
  282. package/build-module/hooks/block-hooks.js.map +1 -0
  283. package/build-module/hooks/block-rename-ui.js +154 -0
  284. package/build-module/hooks/block-rename-ui.js.map +1 -0
  285. package/build-module/hooks/duotone.js +26 -39
  286. package/build-module/hooks/duotone.js.map +1 -1
  287. package/build-module/hooks/index.js +2 -2
  288. package/build-module/hooks/index.js.map +1 -1
  289. package/build-module/hooks/layout.js +33 -16
  290. package/build-module/hooks/layout.js.map +1 -1
  291. package/build-module/hooks/position.js +4 -2
  292. package/build-module/hooks/position.js.map +1 -1
  293. package/build-module/hooks/style.js +10 -3
  294. package/build-module/hooks/style.js.map +1 -1
  295. package/build-module/private-apis.js +2 -0
  296. package/build-module/private-apis.js.map +1 -1
  297. package/build-module/store/actions.js +33 -10
  298. package/build-module/store/actions.js.map +1 -1
  299. package/build-module/store/private-actions.js +39 -8
  300. package/build-module/store/private-actions.js.map +1 -1
  301. package/build-module/store/private-selectors.js +23 -3
  302. package/build-module/store/private-selectors.js.map +1 -1
  303. package/build-module/store/reducer.js +41 -1
  304. package/build-module/store/reducer.js.map +1 -1
  305. package/build-module/store/selectors.js +78 -22
  306. package/build-module/store/selectors.js.map +1 -1
  307. package/build-module/store/utils.js +0 -4
  308. package/build-module/store/utils.js.map +1 -1
  309. package/build-style/content-rtl.css +0 -1
  310. package/build-style/content.css +0 -1
  311. package/build-style/style-rtl.css +201 -131
  312. package/build-style/style.css +201 -131
  313. package/package.json +32 -32
  314. package/src/components/block-canvas/index.js +108 -0
  315. package/src/components/block-inspector/index.js +5 -1
  316. package/src/components/block-list/content.scss +0 -1
  317. package/src/components/block-patterns-list/index.js +53 -19
  318. package/src/components/block-patterns-list/style.scss +26 -9
  319. package/src/components/block-patterns-paging/index.js +92 -0
  320. package/src/components/block-patterns-paging/style.scss +45 -0
  321. package/src/components/block-settings-menu/block-settings-dropdown.js +44 -0
  322. package/src/components/block-settings-menu-controls/index.js +4 -9
  323. package/src/components/block-styles/index.js +1 -0
  324. package/src/components/block-styles/style.scss +3 -3
  325. package/src/components/block-toolbar/block-toolbar-menu.native.js +1 -6
  326. package/src/components/block-tools/block-contextual-toolbar.js +16 -5
  327. package/src/components/block-tools/block-selection-button.js +9 -1
  328. package/src/components/block-tools/style.scss +0 -98
  329. package/src/components/border-radius-control/input-controls.js +1 -1
  330. package/src/components/border-radius-control/linked-button.js +8 -11
  331. package/src/components/color-palette/test/__snapshots__/control.js.snap +34 -21
  332. package/src/components/colors/with-colors.js +3 -2
  333. package/src/components/convert-to-group-buttons/use-convert-to-group-button-props.js +8 -35
  334. package/src/components/default-block-appender/index.native.js +26 -3
  335. package/src/components/duotone/utils.js +65 -0
  336. package/src/components/editor-styles/index.js +32 -23
  337. package/src/components/global-styles/hooks.js +4 -112
  338. package/src/components/global-styles/image-settings-panel.js +71 -0
  339. package/src/components/global-styles/index.js +4 -3
  340. package/src/components/global-styles/use-global-styles-output.js +25 -16
  341. package/src/components/global-styles/utils.js +1 -2
  342. package/src/components/iframe/index.js +72 -33
  343. package/src/components/image-editor/use-save-image.js +2 -9
  344. package/src/components/image-editor/use-transform-image.js +9 -9
  345. package/src/components/index.js +1 -1
  346. package/src/components/index.native.js +2 -2
  347. package/src/components/inner-blocks/use-nested-settings-update.js +15 -10
  348. package/src/components/inserter/block-patterns-explorer/explorer.js +17 -5
  349. package/src/components/inserter/block-patterns-explorer/patterns-list.js +68 -43
  350. package/src/components/inserter/block-patterns-explorer/sidebar.js +8 -8
  351. package/src/components/inserter/block-patterns-filter.js +183 -0
  352. package/src/components/inserter/block-patterns-tab.js +217 -58
  353. package/src/components/inserter/hooks/use-patterns-paging.js +76 -0
  354. package/src/components/inserter/hooks/use-patterns-state.js +27 -16
  355. package/src/components/inserter/menu.js +15 -17
  356. package/src/components/inserter/search-results.js +6 -4
  357. package/src/components/inserter/style.scss +36 -7
  358. package/src/components/inserter/tabs.js +2 -12
  359. package/src/components/inserter/test/index.native.js +8 -12
  360. package/src/components/inspector-controls/block-support-slot-container.js +19 -3
  361. package/src/components/inspector-controls/fill.js +28 -14
  362. package/src/components/inspector-controls/groups.js +6 -2
  363. package/src/components/inspector-controls/slot.js +28 -3
  364. package/src/components/inspector-controls-tabs/styles-tab.js +4 -0
  365. package/src/components/link-control/index.js +13 -0
  366. package/src/components/link-control/style.scss +23 -2
  367. package/src/components/link-control/test/index.js +88 -6
  368. package/src/components/list-view/block-select-button.js +1 -3
  369. package/src/components/list-view/block.js +19 -1
  370. package/src/components/list-view/style.scss +1 -2
  371. package/src/components/list-view/use-block-selection.js +38 -32
  372. package/src/components/media-placeholder/README.md +2 -2
  373. package/src/components/media-placeholder/index.js +2 -2
  374. package/src/components/media-placeholder/index.native.js +11 -12
  375. package/src/components/media-replace-flow/index.js +2 -2
  376. package/src/components/media-replace-flow/test/index.js +5 -23
  377. package/src/components/media-upload/README.md +3 -2
  378. package/src/components/media-upload/constants.js +15 -0
  379. package/src/components/media-upload/index.native.js +66 -40
  380. package/src/components/media-upload/style.native.scss +4 -0
  381. package/src/components/media-upload/test/index.native.js +2 -2
  382. package/src/components/preview-options/README.md +7 -0
  383. package/src/components/preview-options/index.js +1 -1
  384. package/src/components/rich-text/index.js +48 -44
  385. package/src/components/rich-text/index.native.js +14 -42
  386. package/src/components/rich-text/multiline.js +121 -0
  387. package/src/components/rich-text/split-value.js +10 -35
  388. package/src/components/rich-text/use-enter.js +32 -42
  389. package/src/components/rich-text/use-paste-handler.js +16 -40
  390. package/src/components/spacing-sizes-control/style.scss +5 -7
  391. package/src/components/spacing-sizes-control/utils.js +1 -2
  392. package/src/components/use-block-commands/index.js +28 -20
  393. package/src/components/use-block-display-information/index.js +3 -0
  394. package/src/hooks/background.js +299 -0
  395. package/src/hooks/background.scss +75 -0
  396. package/src/hooks/block-hooks.js +257 -0
  397. package/src/hooks/block-hooks.scss +16 -0
  398. package/src/hooks/block-rename-ui.js +231 -0
  399. package/src/hooks/block-rename-ui.scss +3 -0
  400. package/src/hooks/duotone.js +42 -43
  401. package/src/hooks/index.js +2 -2
  402. package/src/hooks/layout.js +31 -33
  403. package/src/hooks/position.js +4 -3
  404. package/src/hooks/style.js +11 -2
  405. package/src/hooks/test/align.native.js +4 -3
  406. package/src/private-apis.js +2 -0
  407. package/src/store/actions.js +52 -10
  408. package/src/store/private-actions.js +37 -6
  409. package/src/store/private-selectors.js +28 -3
  410. package/src/store/reducer.js +38 -0
  411. package/src/store/selectors.js +107 -26
  412. package/src/store/test/actions.js +19 -8
  413. package/src/store/test/private-actions.js +17 -0
  414. package/src/store/test/reducer.js +25 -0
  415. package/src/store/test/selectors.js +130 -123
  416. package/src/store/utils.js +3 -10
  417. package/src/style.scss +4 -0
  418. package/build/components/duotone/components.js +0 -135
  419. package/build/components/duotone/components.js.map +0 -1
  420. package/build/components/duotone/index.js +0 -38
  421. package/build/components/duotone/index.js.map +0 -1
  422. package/build/components/global-styles/behaviors-panel.js +0 -64
  423. package/build/components/global-styles/behaviors-panel.js.map +0 -1
  424. package/build/components/inserter/reusable-blocks-tab.js +0 -85
  425. package/build/components/inserter/reusable-blocks-tab.js.map +0 -1
  426. package/build/hooks/auto-inserting-blocks.js +0 -174
  427. package/build/hooks/auto-inserting-blocks.js.map +0 -1
  428. package/build/hooks/behaviors.js +0 -173
  429. package/build/hooks/behaviors.js.map +0 -1
  430. package/build-module/components/duotone/components.js +0 -126
  431. package/build-module/components/duotone/components.js.map +0 -1
  432. package/build-module/components/duotone/index.js +0 -3
  433. package/build-module/components/duotone/index.js.map +0 -1
  434. package/build-module/components/global-styles/behaviors-panel.js +0 -57
  435. package/build-module/components/global-styles/behaviors-panel.js.map +0 -1
  436. package/build-module/components/inserter/reusable-blocks-tab.js +0 -76
  437. package/build-module/components/inserter/reusable-blocks-tab.js.map +0 -1
  438. package/build-module/hooks/auto-inserting-blocks.js +0 -167
  439. package/build-module/hooks/auto-inserting-blocks.js.map +0 -1
  440. package/build-module/hooks/behaviors.js +0 -166
  441. package/build-module/hooks/behaviors.js.map +0 -1
  442. package/src/components/duotone/components.js +0 -133
  443. package/src/components/duotone/index.js +0 -7
  444. package/src/components/global-styles/behaviors-panel.js +0 -71
  445. package/src/components/inserter/reusable-blocks-tab.js +0 -84
  446. package/src/components/inserter/test/reusable-blocks-tab.js +0 -73
  447. package/src/hooks/auto-inserting-blocks.js +0 -232
  448. package/src/hooks/behaviors.js +0 -206
@@ -0,0 +1,249 @@
1
+ import { createElement } from "@wordpress/element";
2
+ /**
3
+ * External dependencies
4
+ */
5
+ import classnames from 'classnames';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { isBlobURL } from '@wordpress/blob';
11
+ import { getBlockSupport } from '@wordpress/blocks';
12
+ import { __experimentalToolsPanelItem as ToolsPanelItem, DropZone, FlexItem, MenuItem, VisuallyHidden, __experimentalItemGroup as ItemGroup, __experimentalHStack as HStack, __experimentalTruncate as Truncate } from '@wordpress/components';
13
+ import { useDispatch, useSelect } from '@wordpress/data';
14
+ import { Platform, useCallback } from '@wordpress/element';
15
+ import { __, sprintf } from '@wordpress/i18n';
16
+ import { store as noticesStore } from '@wordpress/notices';
17
+ import { getFilename } from '@wordpress/url';
18
+
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+ import InspectorControls from '../components/inspector-controls';
23
+ import MediaReplaceFlow from '../components/media-replace-flow';
24
+ import useSetting from '../components/use-setting';
25
+ import { cleanEmptyObject } from './utils';
26
+ import { store as blockEditorStore } from '../store';
27
+ export const BACKGROUND_SUPPORT_KEY = 'background';
28
+ export const IMAGE_BACKGROUND_TYPE = 'image';
29
+
30
+ /**
31
+ * Checks if there is a current value in the background image block support
32
+ * attributes.
33
+ *
34
+ * @param {Object} props Block props.
35
+ * @return {boolean} Whether or not the block has a background image value set.
36
+ */
37
+ export function hasBackgroundImageValue(props) {
38
+ const hasValue = !!props.attributes.style?.background?.backgroundImage?.id || !!props.attributes.style?.background?.backgroundImage?.url;
39
+ return hasValue;
40
+ }
41
+
42
+ /**
43
+ * Determine whether there is block support for background.
44
+ *
45
+ * @param {string} blockName Block name.
46
+ * @param {string} feature Background image feature to check for.
47
+ *
48
+ * @return {boolean} Whether there is support.
49
+ */
50
+ export function hasBackgroundSupport(blockName, feature = 'any') {
51
+ if (Platform.OS !== 'web') {
52
+ return false;
53
+ }
54
+ const support = getBlockSupport(blockName, BACKGROUND_SUPPORT_KEY);
55
+ if (support === true) {
56
+ return true;
57
+ }
58
+ if (feature === 'any') {
59
+ return !!support?.backgroundImage;
60
+ }
61
+ return !!support?.[feature];
62
+ }
63
+
64
+ /**
65
+ * Resets the background image block support attributes. This can be used when disabling
66
+ * the background image controls for a block via a `ToolsPanel`.
67
+ *
68
+ * @param {Object} props Block props.
69
+ * @param {Object} props.attributes Block's attributes.
70
+ * @param {Object} props.setAttributes Function to set block's attributes.
71
+ */
72
+ export function resetBackgroundImage({
73
+ attributes = {},
74
+ setAttributes
75
+ }) {
76
+ const {
77
+ style = {}
78
+ } = attributes;
79
+ setAttributes({
80
+ style: cleanEmptyObject({
81
+ ...style,
82
+ background: {
83
+ ...style?.background,
84
+ backgroundImage: undefined
85
+ }
86
+ })
87
+ });
88
+ }
89
+ function InspectorImagePreview({
90
+ label,
91
+ filename,
92
+ url: imgUrl
93
+ }) {
94
+ const imgLabel = label || getFilename(imgUrl);
95
+ return createElement(ItemGroup, {
96
+ as: "span"
97
+ }, createElement(HStack, {
98
+ justify: "flex-start",
99
+ as: "span"
100
+ }, createElement("span", {
101
+ className: classnames('block-editor-hooks__background__inspector-image-indicator-wrapper', {
102
+ 'has-image': imgUrl
103
+ }),
104
+ "aria-hidden": true
105
+ }, imgUrl && createElement("span", {
106
+ className: "block-editor-hooks__background__inspector-image-indicator",
107
+ style: {
108
+ backgroundImage: `url(${imgUrl})`
109
+ }
110
+ })), createElement(FlexItem, {
111
+ as: "span"
112
+ }, createElement(Truncate, {
113
+ numberOfLines: 1,
114
+ className: "block-editor-hooks__background__inspector-media-replace-title"
115
+ }, imgLabel), createElement(VisuallyHidden, {
116
+ as: "span"
117
+ }, filename ? sprintf( /* translators: %s: file name */
118
+ __('Selected image: %s'), filename) : __('No image selected')))));
119
+ }
120
+ function BackgroundImagePanelItem(props) {
121
+ const {
122
+ attributes,
123
+ clientId,
124
+ setAttributes
125
+ } = props;
126
+ const {
127
+ id,
128
+ title,
129
+ url
130
+ } = attributes.style?.background?.backgroundImage || {};
131
+ const {
132
+ mediaUpload
133
+ } = useSelect(select => {
134
+ return {
135
+ mediaUpload: select(blockEditorStore).getSettings().mediaUpload
136
+ };
137
+ });
138
+ const {
139
+ createErrorNotice
140
+ } = useDispatch(noticesStore);
141
+ const onUploadError = message => {
142
+ createErrorNotice(message, {
143
+ type: 'snackbar'
144
+ });
145
+ };
146
+ const onSelectMedia = media => {
147
+ if (!media || !media.url) {
148
+ const newStyle = {
149
+ ...attributes.style,
150
+ background: {
151
+ ...attributes.style?.background,
152
+ backgroundImage: undefined
153
+ }
154
+ };
155
+ const newAttributes = {
156
+ style: cleanEmptyObject(newStyle)
157
+ };
158
+ setAttributes(newAttributes);
159
+ return;
160
+ }
161
+ if (isBlobURL(media.url)) {
162
+ return;
163
+ }
164
+
165
+ // For media selections originated from a file upload.
166
+ if (media.media_type && media.media_type !== IMAGE_BACKGROUND_TYPE || !media.media_type && media.type && media.type !== IMAGE_BACKGROUND_TYPE) {
167
+ onUploadError(__('Only images can be used as a background image.'));
168
+ return;
169
+ }
170
+ const newStyle = {
171
+ ...attributes.style,
172
+ background: {
173
+ ...attributes.style?.background,
174
+ backgroundImage: {
175
+ url: media.url,
176
+ id: media.id,
177
+ source: 'file',
178
+ title: media.title || undefined
179
+ }
180
+ }
181
+ };
182
+ const newAttributes = {
183
+ style: cleanEmptyObject(newStyle)
184
+ };
185
+ setAttributes(newAttributes);
186
+ };
187
+ const onFilesDrop = filesList => {
188
+ mediaUpload({
189
+ allowedTypes: ['image'],
190
+ filesList,
191
+ onFileChange([image]) {
192
+ if (isBlobURL(image?.url)) {
193
+ return;
194
+ }
195
+ onSelectMedia(image);
196
+ },
197
+ onError: onUploadError
198
+ });
199
+ };
200
+ const resetAllFilter = useCallback(previousValue => {
201
+ return {
202
+ ...previousValue,
203
+ style: {
204
+ ...previousValue.style,
205
+ background: undefined
206
+ }
207
+ };
208
+ }, []);
209
+ return createElement(ToolsPanelItem, {
210
+ className: "single-column",
211
+ hasValue: () => hasBackgroundImageValue(props),
212
+ label: __('Background image'),
213
+ onDeselect: () => resetBackgroundImage(props),
214
+ isShownByDefault: true,
215
+ resetAllFilter: resetAllFilter,
216
+ panelId: clientId
217
+ }, createElement("div", {
218
+ className: "block-editor-hooks__background__inspector-media-replace-container"
219
+ }, createElement(MediaReplaceFlow, {
220
+ mediaId: id,
221
+ mediaURL: url,
222
+ allowedTypes: [IMAGE_BACKGROUND_TYPE],
223
+ accept: "image/*",
224
+ onSelect: onSelectMedia,
225
+ name: createElement(InspectorImagePreview, {
226
+ label: __('Background image'),
227
+ filename: title,
228
+ url: url
229
+ }),
230
+ variant: "secondary"
231
+ }, createElement(MenuItem, {
232
+ onClick: () => resetBackgroundImage(props)
233
+ }, __('Reset '))), createElement(DropZone, {
234
+ onFilesDrop: onFilesDrop,
235
+ label: __('Drop to upload')
236
+ })));
237
+ }
238
+ export function BackgroundImagePanel(props) {
239
+ const isBackgroundImageSupported = useSetting('background.backgroundImage') && hasBackgroundSupport(props.name, 'backgroundImage');
240
+ if (!isBackgroundImageSupported) {
241
+ return null;
242
+ }
243
+ return createElement(InspectorControls, {
244
+ group: "background"
245
+ }, isBackgroundImageSupported && createElement(BackgroundImagePanelItem, {
246
+ ...props
247
+ }));
248
+ }
249
+ //# sourceMappingURL=background.js.map
@@ -0,0 +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","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","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","isBackgroundImageSupported","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 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, 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 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{ isBackgroundImageSupported && (\n\t\t\t\t<BackgroundImagePanelItem { ...props } />\n\t\t\t) }\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,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IACnC,OAAO,IAAI;EACZ;EAEA,OACCxC,aAAA,CAAC7B,iBAAiB;IAACsE,KAAK,EAAC;EAAY,GAClCD,0BAA0B,IAC3BxC,aAAA,CAACK,wBAAwB;IAAA,GAAM1B;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;AACtD,SACCC,oBAAoB,IAAIC,MAAM,EAC9BC,SAAS,EACTC,aAAa,QACP,uBAAuB;AAC9B,SAASC,0BAA0B,QAAQ,oBAAoB;AAC/D,SAASC,WAAW,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACrE,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe;AAC5D,SAASL,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AACc;IAAU,CAC3B,CACA,CAAC;EAEL,CAAC;AACF,CAAC,EAAE,gBAAiB,CAAC;AAErBhC,SAAS,CACR,kBAAkB,EAClB,yCAAyC,EACzCsE,cACD,CAAC"}
@@ -0,0 +1,154 @@
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
+ focusOnMount: "firstContentElement"
48
+ }, createElement("p", {
49
+ id: dialogDescription
50
+ }, __('Enter a custom name for this block.')), createElement("form", {
51
+ onSubmit: e => {
52
+ e.preventDefault();
53
+ if (!isNameValid) {
54
+ return;
55
+ }
56
+ handleSubmit();
57
+ }
58
+ }, createElement(VStack, {
59
+ spacing: "3"
60
+ }, createElement(TextControl, {
61
+ __nextHasNoMarginBottom: true,
62
+ value: editedBlockName,
63
+ label: __('Block name'),
64
+ hideLabelFromVision: true,
65
+ placeholder: originalBlockName,
66
+ onChange: setEditedBlockName,
67
+ onFocus: autoSelectInputText
68
+ }), createElement(HStack, {
69
+ justify: "right"
70
+ }, createElement(Button, {
71
+ variant: "tertiary",
72
+ onClick: onClose
73
+ }, __('Cancel')), createElement(Button, {
74
+ "aria-disabled": !isNameValid,
75
+ variant: "primary",
76
+ type: "submit"
77
+ }, __('Save'))))));
78
+ }
79
+ function BlockRenameControl(props) {
80
+ const [renamingBlock, setRenamingBlock] = useState(false);
81
+ const {
82
+ clientId,
83
+ customName,
84
+ onChange
85
+ } = props;
86
+ const blockInformation = useBlockDisplayInformation(clientId);
87
+ return createElement(Fragment, null, createElement(InspectorControls, {
88
+ group: "advanced"
89
+ }, createElement(TextControl, {
90
+ __nextHasNoMarginBottom: true,
91
+ label: __('Block name'),
92
+ value: customName || '',
93
+ onChange: onChange
94
+ })), createElement(BlockSettingsMenuControls, null, ({
95
+ selectedClientIds
96
+ }) => {
97
+ // Only enabled for single selections.
98
+ const canRename = selectedClientIds.length === 1 && clientId === selectedClientIds[0];
99
+
100
+ // This check ensures the `BlockSettingsMenuControls` fill
101
+ // doesn't render multiple times and also that it renders for
102
+ // the block from which the menu was triggered.
103
+ if (!canRename) {
104
+ return null;
105
+ }
106
+ return createElement(MenuItem, {
107
+ onClick: () => {
108
+ setRenamingBlock(true);
109
+ },
110
+ "aria-expanded": renamingBlock,
111
+ "aria-haspopup": "dialog"
112
+ }, __('Rename'));
113
+ }), renamingBlock && createElement(RenameModal, {
114
+ blockName: customName || '',
115
+ originalBlockName: blockInformation?.title,
116
+ onClose: () => setRenamingBlock(false),
117
+ onSave: newName => {
118
+ // If the new value is the block's original name (e.g. `Group`)
119
+ // or it is an empty string then assume the intent is to reset
120
+ // the value. Therefore reset the metadata.
121
+ if (newName === blockInformation?.title || emptyString(newName)) {
122
+ newName = undefined;
123
+ }
124
+ onChange(newName);
125
+ }
126
+ }));
127
+ }
128
+ export const withBlockRenameControl = createHigherOrderComponent(BlockEdit => props => {
129
+ const {
130
+ clientId,
131
+ name,
132
+ attributes,
133
+ setAttributes
134
+ } = props;
135
+ const metaDataSupport = getBlockSupport(name, '__experimentalMetadata', false);
136
+ const supportsBlockNaming = !!(true === metaDataSupport || metaDataSupport?.name);
137
+ return createElement(Fragment, null, supportsBlockNaming && createElement(Fragment, null, createElement(BlockRenameControl, {
138
+ clientId: clientId,
139
+ customName: attributes?.metadata?.name,
140
+ onChange: newName => {
141
+ setAttributes({
142
+ metadata: {
143
+ ...(attributes?.metadata && attributes?.metadata),
144
+ name: newName
145
+ }
146
+ });
147
+ }
148
+ })), createElement(BlockEdit, {
149
+ key: "edit",
150
+ ...props
151
+ }));
152
+ }, 'withToolbarControls');
153
+ addFilter('editor.BlockEdit', 'core/block-rename-ui/with-block-rename-control', withBlockRenameControl);
154
+ //# sourceMappingURL=block-rename-ui.js.map