@wordpress/block-editor 15.23.0 → 16.0.1-next.v.202607070741.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 (363) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/autocompleters/block.cjs +10 -2
  3. package/build/autocompleters/block.cjs.map +2 -2
  4. package/build/components/background-image-control/index.cjs +0 -2
  5. package/build/components/background-image-control/index.cjs.map +2 -2
  6. package/build/components/block-inspector/edit-contents.cjs +3 -0
  7. package/build/components/block-inspector/edit-contents.cjs.map +3 -3
  8. package/build/components/block-inspector/index.cjs +2 -3
  9. package/build/components/block-inspector/index.cjs.map +2 -2
  10. package/build/components/block-list/block-invalid-warning.cjs +8 -19
  11. package/build/components/block-list/block-invalid-warning.cjs.map +2 -2
  12. package/build/components/block-styles/use-styles-for-block.cjs +2 -1
  13. package/build/components/block-styles/use-styles-for-block.cjs.map +2 -2
  14. package/build/components/block-title/use-block-display-title.cjs +7 -2
  15. package/build/components/block-title/use-block-display-title.cjs.map +2 -2
  16. package/build/components/block-toolbar/block-toolbar-icon.cjs +10 -14
  17. package/build/components/block-toolbar/block-toolbar-icon.cjs.map +2 -2
  18. package/build/components/block-variation-transforms/index.cjs +0 -1
  19. package/build/components/block-variation-transforms/index.cjs.map +2 -2
  20. package/build/components/child-layout-control/index.cjs +0 -2
  21. package/build/components/child-layout-control/index.cjs.map +2 -2
  22. package/build/components/colors-gradients/control.cjs +5 -5
  23. package/build/components/colors-gradients/control.cjs.map +2 -2
  24. package/build/components/date-format-picker/index.cjs +0 -1
  25. package/build/components/date-format-picker/index.cjs.map +2 -2
  26. package/build/components/dimensions-tool/aspect-ratio-tool.cjs +1 -2
  27. package/build/components/dimensions-tool/aspect-ratio-tool.cjs.map +2 -2
  28. package/build/components/dimensions-tool/scale-tool.cjs +0 -1
  29. package/build/components/dimensions-tool/scale-tool.cjs.map +2 -2
  30. package/build/components/dimensions-tool/width-height-tool.cjs +2 -4
  31. package/build/components/dimensions-tool/width-height-tool.cjs.map +2 -2
  32. package/build/components/font-appearance-control/index.cjs +6 -25
  33. package/build/components/font-appearance-control/index.cjs.map +3 -3
  34. package/build/components/font-family/index.cjs +6 -15
  35. package/build/components/font-family/index.cjs.map +3 -3
  36. package/build/components/font-sizes/font-size-picker.cjs +1 -2
  37. package/build/components/font-sizes/font-size-picker.cjs.map +2 -2
  38. package/build/components/global-styles/border-panel.cjs +0 -1
  39. package/build/components/global-styles/border-panel.cjs.map +2 -2
  40. package/build/components/global-styles/dimensions-panel.cjs +0 -3
  41. package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
  42. package/build/components/global-styles/typography-panel.cjs +4 -10
  43. package/build/components/global-styles/typography-panel.cjs.map +2 -2
  44. package/build/components/height-control/index.cjs +0 -2
  45. package/build/components/height-control/index.cjs.map +2 -2
  46. package/build/components/html-element-control/index.cjs +0 -1
  47. package/build/components/html-element-control/index.cjs.map +2 -2
  48. package/build/components/image-editor/index.cjs +5 -0
  49. package/build/components/image-editor/index.cjs.map +3 -3
  50. package/build/components/image-editor/zoom-dropdown.cjs +0 -1
  51. package/build/components/image-editor/zoom-dropdown.cjs.map +2 -2
  52. package/build/components/image-size-control/index.cjs +1 -3
  53. package/build/components/image-size-control/index.cjs.map +2 -2
  54. package/build/components/inner-content/index.cjs +107 -0
  55. package/build/components/inner-content/index.cjs.map +7 -0
  56. package/build/components/inserter/hooks/use-block-types-state.cjs +10 -2
  57. package/build/components/inserter/hooks/use-block-types-state.cjs.map +2 -2
  58. package/build/components/inserter/media-tab/hooks.cjs +34 -6
  59. package/build/components/inserter/media-tab/hooks.cjs.map +2 -2
  60. package/build/components/inserter/media-tab/media-list.cjs +3 -1
  61. package/build/components/inserter/media-tab/media-list.cjs.map +2 -2
  62. package/build/components/inserter/media-tab/media-panel.cjs +224 -27
  63. package/build/components/inserter/media-tab/media-panel.cjs.map +3 -3
  64. package/build/components/inserter/media-tab/media-preview.cjs +32 -17
  65. package/build/components/inserter/media-tab/media-preview.cjs.map +2 -2
  66. package/build/components/inserter/media-tab/media-tab.cjs +26 -6
  67. package/build/components/inserter/media-tab/media-tab.cjs.map +2 -2
  68. package/build/components/inserter/mobile-tab-navigation.cjs +6 -1
  69. package/build/components/inserter/mobile-tab-navigation.cjs.map +2 -2
  70. package/build/components/inserter/no-results.cjs +2 -2
  71. package/build/components/inserter/no-results.cjs.map +2 -2
  72. package/build/components/inserter/preview-panel.cjs +2 -1
  73. package/build/components/inserter/preview-panel.cjs.map +2 -2
  74. package/build/components/inserter-list-item/index.cjs +8 -2
  75. package/build/components/inserter-list-item/index.cjs.map +2 -2
  76. package/build/components/letter-spacing-control/index.cjs +0 -24
  77. package/build/components/letter-spacing-control/index.cjs.map +3 -3
  78. package/build/components/line-height-control/index.cjs +7 -22
  79. package/build/components/line-height-control/index.cjs.map +3 -3
  80. package/build/components/list-view/block-select-button.cjs +90 -84
  81. package/build/components/list-view/block-select-button.cjs.map +2 -2
  82. package/build/components/list-view/block.cjs +51 -20
  83. package/build/components/list-view/block.cjs.map +2 -2
  84. package/build/components/list-view/expander.cjs +1 -1
  85. package/build/components/list-view/expander.cjs.map +2 -2
  86. package/build/components/list-view/use-list-view-client-ids.cjs +2 -2
  87. package/build/components/list-view/use-list-view-client-ids.cjs.map +2 -2
  88. package/build/components/observe-typing/index.cjs +4 -3
  89. package/build/components/observe-typing/index.cjs.map +2 -2
  90. package/build/components/preset-input-control/custom-value-controls.cjs +1 -3
  91. package/build/components/preset-input-control/custom-value-controls.cjs.map +2 -2
  92. package/build/components/preset-input-control/index.cjs +1 -3
  93. package/build/components/preset-input-control/index.cjs.map +2 -2
  94. package/build/components/resolution-tool/index.cjs +1 -2
  95. package/build/components/resolution-tool/index.cjs.map +2 -2
  96. package/build/components/text-alignment-control/index.cjs +0 -1
  97. package/build/components/text-alignment-control/index.cjs.map +2 -2
  98. package/build/components/text-decoration-control/index.cjs +0 -1
  99. package/build/components/text-decoration-control/index.cjs.map +2 -2
  100. package/build/components/text-indent-control/index.cjs +0 -8
  101. package/build/components/text-indent-control/index.cjs.map +2 -2
  102. package/build/components/text-transform-control/index.cjs +0 -1
  103. package/build/components/text-transform-control/index.cjs.map +2 -2
  104. package/build/components/use-block-display-information/index.cjs +10 -8
  105. package/build/components/use-block-display-information/index.cjs.map +2 -2
  106. package/build/components/use-on-block-drop/index.cjs +3 -7
  107. package/build/components/use-on-block-drop/index.cjs.map +2 -2
  108. package/build/components/writing-mode-control/index.cjs +0 -1
  109. package/build/components/writing-mode-control/index.cjs.map +2 -2
  110. package/build/hooks/font-size.cjs +1 -2
  111. package/build/hooks/font-size.cjs.map +2 -2
  112. package/build/hooks/layout.cjs +5 -3
  113. package/build/hooks/layout.cjs.map +2 -2
  114. package/build/hooks/position.cjs +36 -16
  115. package/build/hooks/position.cjs.map +2 -2
  116. package/build/hooks/states.cjs +6 -9
  117. package/build/hooks/states.cjs.map +2 -2
  118. package/build/layouts/constrained.cjs +21 -21
  119. package/build/layouts/constrained.cjs.map +2 -2
  120. package/build/layouts/flex.cjs +0 -3
  121. package/build/layouts/flex.cjs.map +2 -2
  122. package/build/layouts/grid.cjs +51 -9
  123. package/build/layouts/grid.cjs.map +2 -2
  124. package/build/private-apis.cjs +4 -1
  125. package/build/private-apis.cjs.map +3 -3
  126. package/build/store/actions.cjs.map +2 -2
  127. package/build/store/private-keys.cjs +3 -0
  128. package/build/store/private-keys.cjs.map +2 -2
  129. package/build/store/private-selectors.cjs +72 -4
  130. package/build/store/private-selectors.cjs.map +2 -2
  131. package/build/store/selectors.cjs +13 -0
  132. package/build/store/selectors.cjs.map +2 -2
  133. package/build-module/autocompleters/block.mjs +10 -2
  134. package/build-module/autocompleters/block.mjs.map +2 -2
  135. package/build-module/components/background-image-control/index.mjs +0 -2
  136. package/build-module/components/background-image-control/index.mjs.map +2 -2
  137. package/build-module/components/block-inspector/edit-contents.mjs +4 -1
  138. package/build-module/components/block-inspector/edit-contents.mjs.map +2 -2
  139. package/build-module/components/block-inspector/index.mjs +2 -3
  140. package/build-module/components/block-inspector/index.mjs.map +2 -2
  141. package/build-module/components/block-list/block-invalid-warning.mjs +8 -19
  142. package/build-module/components/block-list/block-invalid-warning.mjs.map +2 -2
  143. package/build-module/components/block-styles/use-styles-for-block.mjs +2 -1
  144. package/build-module/components/block-styles/use-styles-for-block.mjs.map +2 -2
  145. package/build-module/components/block-title/use-block-display-title.mjs +7 -2
  146. package/build-module/components/block-title/use-block-display-title.mjs.map +2 -2
  147. package/build-module/components/block-toolbar/block-toolbar-icon.mjs +10 -14
  148. package/build-module/components/block-toolbar/block-toolbar-icon.mjs.map +2 -2
  149. package/build-module/components/block-variation-transforms/index.mjs +0 -1
  150. package/build-module/components/block-variation-transforms/index.mjs.map +2 -2
  151. package/build-module/components/child-layout-control/index.mjs +0 -2
  152. package/build-module/components/child-layout-control/index.mjs.map +2 -2
  153. package/build-module/components/colors-gradients/control.mjs +5 -5
  154. package/build-module/components/colors-gradients/control.mjs.map +2 -2
  155. package/build-module/components/date-format-picker/index.mjs +0 -1
  156. package/build-module/components/date-format-picker/index.mjs.map +2 -2
  157. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs +1 -2
  158. package/build-module/components/dimensions-tool/aspect-ratio-tool.mjs.map +2 -2
  159. package/build-module/components/dimensions-tool/scale-tool.mjs +0 -1
  160. package/build-module/components/dimensions-tool/scale-tool.mjs.map +2 -2
  161. package/build-module/components/dimensions-tool/width-height-tool.mjs +2 -4
  162. package/build-module/components/dimensions-tool/width-height-tool.mjs.map +2 -2
  163. package/build-module/components/font-appearance-control/index.mjs +6 -15
  164. package/build-module/components/font-appearance-control/index.mjs.map +2 -2
  165. package/build-module/components/font-family/index.mjs +6 -15
  166. package/build-module/components/font-family/index.mjs.map +2 -2
  167. package/build-module/components/font-sizes/font-size-picker.mjs +1 -2
  168. package/build-module/components/font-sizes/font-size-picker.mjs.map +2 -2
  169. package/build-module/components/global-styles/border-panel.mjs +0 -1
  170. package/build-module/components/global-styles/border-panel.mjs.map +2 -2
  171. package/build-module/components/global-styles/dimensions-panel.mjs +0 -3
  172. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  173. package/build-module/components/global-styles/typography-panel.mjs +4 -10
  174. package/build-module/components/global-styles/typography-panel.mjs.map +2 -2
  175. package/build-module/components/height-control/index.mjs +0 -2
  176. package/build-module/components/height-control/index.mjs.map +2 -2
  177. package/build-module/components/html-element-control/index.mjs +0 -1
  178. package/build-module/components/html-element-control/index.mjs.map +2 -2
  179. package/build-module/components/image-editor/index.mjs +5 -0
  180. package/build-module/components/image-editor/index.mjs.map +2 -2
  181. package/build-module/components/image-editor/zoom-dropdown.mjs +0 -1
  182. package/build-module/components/image-editor/zoom-dropdown.mjs.map +2 -2
  183. package/build-module/components/image-size-control/index.mjs +1 -3
  184. package/build-module/components/image-size-control/index.mjs.map +2 -2
  185. package/build-module/components/inner-content/index.mjs +82 -0
  186. package/build-module/components/inner-content/index.mjs.map +7 -0
  187. package/build-module/components/inserter/hooks/use-block-types-state.mjs +10 -2
  188. package/build-module/components/inserter/hooks/use-block-types-state.mjs.map +2 -2
  189. package/build-module/components/inserter/media-tab/hooks.mjs +33 -6
  190. package/build-module/components/inserter/media-tab/hooks.mjs.map +2 -2
  191. package/build-module/components/inserter/media-tab/media-list.mjs +3 -1
  192. package/build-module/components/inserter/media-tab/media-list.mjs.map +2 -2
  193. package/build-module/components/inserter/media-tab/media-panel.mjs +227 -30
  194. package/build-module/components/inserter/media-tab/media-panel.mjs.map +2 -2
  195. package/build-module/components/inserter/media-tab/media-preview.mjs +33 -18
  196. package/build-module/components/inserter/media-tab/media-preview.mjs.map +2 -2
  197. package/build-module/components/inserter/media-tab/media-tab.mjs +27 -7
  198. package/build-module/components/inserter/media-tab/media-tab.mjs.map +2 -2
  199. package/build-module/components/inserter/mobile-tab-navigation.mjs +6 -1
  200. package/build-module/components/inserter/mobile-tab-navigation.mjs.map +2 -2
  201. package/build-module/components/inserter/no-results.mjs +2 -2
  202. package/build-module/components/inserter/no-results.mjs.map +2 -2
  203. package/build-module/components/inserter/preview-panel.mjs +2 -1
  204. package/build-module/components/inserter/preview-panel.mjs.map +2 -2
  205. package/build-module/components/inserter-list-item/index.mjs +8 -2
  206. package/build-module/components/inserter-list-item/index.mjs.map +2 -2
  207. package/build-module/components/letter-spacing-control/index.mjs +0 -14
  208. package/build-module/components/letter-spacing-control/index.mjs.map +2 -2
  209. package/build-module/components/line-height-control/index.mjs +7 -12
  210. package/build-module/components/line-height-control/index.mjs.map +2 -2
  211. package/build-module/components/list-view/block-select-button.mjs +90 -84
  212. package/build-module/components/list-view/block-select-button.mjs.map +2 -2
  213. package/build-module/components/list-view/block.mjs +51 -20
  214. package/build-module/components/list-view/block.mjs.map +2 -2
  215. package/build-module/components/list-view/expander.mjs +1 -1
  216. package/build-module/components/list-view/expander.mjs.map +2 -2
  217. package/build-module/components/list-view/use-list-view-client-ids.mjs +2 -2
  218. package/build-module/components/list-view/use-list-view-client-ids.mjs.map +2 -2
  219. package/build-module/components/observe-typing/index.mjs +4 -3
  220. package/build-module/components/observe-typing/index.mjs.map +2 -2
  221. package/build-module/components/preset-input-control/custom-value-controls.mjs +1 -3
  222. package/build-module/components/preset-input-control/custom-value-controls.mjs.map +2 -2
  223. package/build-module/components/preset-input-control/index.mjs +1 -3
  224. package/build-module/components/preset-input-control/index.mjs.map +2 -2
  225. package/build-module/components/resolution-tool/index.mjs +1 -2
  226. package/build-module/components/resolution-tool/index.mjs.map +2 -2
  227. package/build-module/components/text-alignment-control/index.mjs +0 -1
  228. package/build-module/components/text-alignment-control/index.mjs.map +2 -2
  229. package/build-module/components/text-decoration-control/index.mjs +0 -1
  230. package/build-module/components/text-decoration-control/index.mjs.map +2 -2
  231. package/build-module/components/text-indent-control/index.mjs +0 -8
  232. package/build-module/components/text-indent-control/index.mjs.map +2 -2
  233. package/build-module/components/text-transform-control/index.mjs +0 -1
  234. package/build-module/components/text-transform-control/index.mjs.map +2 -2
  235. package/build-module/components/use-block-display-information/index.mjs +10 -8
  236. package/build-module/components/use-block-display-information/index.mjs.map +2 -2
  237. package/build-module/components/use-on-block-drop/index.mjs +4 -7
  238. package/build-module/components/use-on-block-drop/index.mjs.map +2 -2
  239. package/build-module/components/writing-mode-control/index.mjs +0 -1
  240. package/build-module/components/writing-mode-control/index.mjs.map +2 -2
  241. package/build-module/hooks/font-size.mjs +1 -2
  242. package/build-module/hooks/font-size.mjs.map +2 -2
  243. package/build-module/hooks/layout.mjs +4 -3
  244. package/build-module/hooks/layout.mjs.map +2 -2
  245. package/build-module/hooks/position.mjs +38 -18
  246. package/build-module/hooks/position.mjs.map +2 -2
  247. package/build-module/hooks/states.mjs +6 -9
  248. package/build-module/hooks/states.mjs.map +2 -2
  249. package/build-module/layouts/constrained.mjs +21 -21
  250. package/build-module/layouts/constrained.mjs.map +2 -2
  251. package/build-module/layouts/flex.mjs +0 -3
  252. package/build-module/layouts/flex.mjs.map +2 -2
  253. package/build-module/layouts/grid.mjs +52 -9
  254. package/build-module/layouts/grid.mjs.map +2 -2
  255. package/build-module/private-apis.mjs +5 -1
  256. package/build-module/private-apis.mjs.map +2 -2
  257. package/build-module/store/actions.mjs.map +2 -2
  258. package/build-module/store/private-keys.mjs +2 -0
  259. package/build-module/store/private-keys.mjs.map +2 -2
  260. package/build-module/store/private-selectors.mjs +71 -4
  261. package/build-module/store/private-selectors.mjs.map +2 -2
  262. package/build-module/store/selectors.mjs +13 -0
  263. package/build-module/store/selectors.mjs.map +2 -2
  264. package/build-style/content-rtl.css +11 -5
  265. package/build-style/content.css +11 -5
  266. package/build-style/style-rtl.css +113 -3
  267. package/build-style/style.css +113 -3
  268. package/package.json +43 -41
  269. package/src/autocompleters/block.js +10 -3
  270. package/src/autocompleters/test/block.js +53 -0
  271. package/src/components/background-image-control/index.js +0 -2
  272. package/src/components/block-inspector/edit-contents.js +5 -1
  273. package/src/components/block-inspector/index.js +3 -2
  274. package/src/components/block-list/block-invalid-warning.js +8 -19
  275. package/src/components/block-patterns-list/stories/index.story.jsx +1 -1
  276. package/src/components/block-styles/use-styles-for-block.js +1 -0
  277. package/src/components/block-title/use-block-display-title.js +7 -2
  278. package/src/components/block-toolbar/block-toolbar-icon.js +11 -16
  279. package/src/components/block-toolbar/test/block-toolbar-icon.js +32 -9
  280. package/src/components/block-variation-transforms/index.js +0 -1
  281. package/src/components/child-layout-control/index.js +0 -2
  282. package/src/components/color-palette/test/__snapshots__/control.js.snap +11 -106
  283. package/src/components/colors-gradients/control.js +4 -4
  284. package/src/components/colors-gradients/style.scss +2 -2
  285. package/src/components/date-format-picker/index.js +0 -1
  286. package/src/components/dimensions-tool/aspect-ratio-tool.js +0 -1
  287. package/src/components/dimensions-tool/scale-tool.js +0 -1
  288. package/src/components/dimensions-tool/width-height-tool.js +0 -2
  289. package/src/components/font-appearance-control/index.js +6 -19
  290. package/src/components/font-family/README.md +0 -9
  291. package/src/components/font-family/index.js +6 -19
  292. package/src/components/font-family/stories/index.story.jsx +0 -1
  293. package/src/components/font-sizes/font-size-picker.js +0 -1
  294. package/src/components/global-styles/border-panel.js +0 -1
  295. package/src/components/global-styles/dimensions-panel.js +0 -3
  296. package/src/components/global-styles/typography-panel.js +0 -6
  297. package/src/components/height-control/index.js +0 -2
  298. package/src/components/html-element-control/index.js +0 -1
  299. package/src/components/iframe/content.scss +3 -3
  300. package/src/components/image-editor/index.js +22 -0
  301. package/src/components/image-editor/zoom-dropdown.js +0 -1
  302. package/src/components/image-size-control/index.js +0 -2
  303. package/src/components/inner-content/index.js +119 -0
  304. package/src/components/inner-content/test/index.js +81 -0
  305. package/src/components/inserter/hooks/use-block-types-state.js +10 -2
  306. package/src/components/inserter/media-tab/hooks.js +59 -9
  307. package/src/components/inserter/media-tab/media-list.js +2 -0
  308. package/src/components/inserter/media-tab/media-panel.js +256 -17
  309. package/src/components/inserter/media-tab/media-preview.js +34 -17
  310. package/src/components/inserter/media-tab/media-tab.js +20 -2
  311. package/src/components/inserter/media-tab/test/hooks.js +204 -0
  312. package/src/components/inserter/mobile-tab-navigation.js +6 -1
  313. package/src/components/inserter/no-results.js +2 -2
  314. package/src/components/inserter/preview-panel.js +1 -0
  315. package/src/components/inserter/style.scss +110 -1
  316. package/src/components/inserter-list-item/index.js +8 -2
  317. package/src/components/letter-spacing-control/README.md +0 -8
  318. package/src/components/letter-spacing-control/index.js +5 -23
  319. package/src/components/letter-spacing-control/stories/index.story.jsx +0 -12
  320. package/src/components/line-height-control/README.md +0 -8
  321. package/src/components/line-height-control/index.js +7 -16
  322. package/src/components/line-height-control/stories/index.story.jsx +0 -1
  323. package/src/components/line-height-control/test/index.js +1 -7
  324. package/src/components/link-picker/test/index.js +3 -1
  325. package/src/components/list-view/block-select-button.js +5 -1
  326. package/src/components/list-view/block.js +57 -20
  327. package/src/components/list-view/expander.js +5 -1
  328. package/src/components/list-view/style.scss +19 -0
  329. package/src/components/list-view/use-list-view-client-ids.js +2 -2
  330. package/src/components/observe-typing/index.js +9 -4
  331. package/src/components/preset-input-control/custom-value-controls.js +0 -2
  332. package/src/components/preset-input-control/index.js +0 -2
  333. package/src/components/resolution-tool/index.js +0 -1
  334. package/src/components/responsive-block-control/test/index.js +1 -5
  335. package/src/components/text-alignment-control/index.js +0 -1
  336. package/src/components/text-decoration-control/index.js +0 -1
  337. package/src/components/text-indent-control/index.js +7 -16
  338. package/src/components/text-transform-control/index.js +0 -1
  339. package/src/components/use-block-display-information/index.js +9 -13
  340. package/src/components/use-block-display-information/test/index.js +47 -9
  341. package/src/components/use-on-block-drop/index.js +4 -7
  342. package/src/components/writing-mode-control/index.js +0 -1
  343. package/src/hooks/block-hooks.scss +15 -0
  344. package/src/hooks/font-size.js +0 -1
  345. package/src/hooks/layout.js +5 -4
  346. package/src/hooks/position.js +44 -23
  347. package/src/hooks/states.js +6 -12
  348. package/src/hooks/test/cross-origin-isolation.js +0 -4
  349. package/src/hooks/test/layout.js +75 -1
  350. package/src/layouts/constrained.js +51 -28
  351. package/src/layouts/flex.js +0 -3
  352. package/src/layouts/grid.js +59 -7
  353. package/src/layouts/test/constrained.js +91 -0
  354. package/src/layouts/test/grid.js +71 -0
  355. package/src/private-apis.js +4 -0
  356. package/src/store/actions.js +1 -0
  357. package/src/store/private-keys.js +1 -0
  358. package/src/store/private-selectors.js +141 -4
  359. package/src/store/selectors.js +41 -0
  360. package/src/store/test/private-selectors.js +422 -0
  361. package/src/store/test/reducer.js +11 -11
  362. package/src/store/test/selectors.js +133 -0
  363. package/src/style.scss +1 -0
@@ -36,7 +36,14 @@ var useBlockTypesState = (rootClientId, onInsert, isQuick) => {
36
36
  return [getCategories(), getCollections()];
37
37
  }, []);
38
38
  const onSelectItem = useCallback(
39
- ({ name, initialAttributes, innerBlocks, syncStatus, content }, shouldFocusBlock) => {
39
+ ({
40
+ name,
41
+ initialAttributes,
42
+ innerBlocks,
43
+ innerContent,
44
+ syncStatus,
45
+ content
46
+ }, shouldFocusBlock) => {
40
47
  const destinationClientId = getClosestAllowedInsertionPoint(
41
48
  name,
42
49
  rootClientId
@@ -61,7 +68,8 @@ var useBlockTypesState = (rootClientId, onInsert, isQuick) => {
61
68
  }) : createBlock(
62
69
  name,
63
70
  initialAttributes,
64
- createBlocksFromInnerBlocksTemplate(innerBlocks)
71
+ createBlocksFromInnerBlocksTemplate(innerBlocks),
72
+ innerContent
65
73
  );
66
74
  onInsert(
67
75
  insertedBlock,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/inserter/hooks/use-block-types-state.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tgetBlockType,\n\tcreateBlock,\n\tcreateBlocksFromInnerBlocksTemplate,\n\tstore as blocksStore,\n\tparse,\n} from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { isFiltered } from '../../../store/utils';\nimport { unlock } from '../../../lock-unlock';\n\n/**\n * Retrieves the block types inserter state.\n *\n * @param {string=} rootClientId Insertion's root client ID.\n * @param {Function} onInsert function called when inserter a list of blocks.\n * @param {boolean} isQuick\n * @return {Array} Returns the block types state. (block types, categories, collections, onSelect handler)\n */\nconst useBlockTypesState = ( rootClientId, onInsert, isQuick ) => {\n\tconst options = useMemo(\n\t\t() => ( { [ isFiltered ]: !! isQuick } ),\n\t\t[ isQuick ]\n\t);\n\tconst [ items ] = useSelect(\n\t\t( select ) => [\n\t\t\tselect( blockEditorStore ).getInserterItems(\n\t\t\t\trootClientId,\n\t\t\t\toptions\n\t\t\t),\n\t\t],\n\t\t[ rootClientId, options ]\n\t);\n\tconst { getClosestAllowedInsertionPoint } = unlock(\n\t\tuseSelect( blockEditorStore )\n\t);\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst [ categories, collections ] = useSelect( ( select ) => {\n\t\tconst { getCategories, getCollections } = select( blocksStore );\n\t\treturn [ getCategories(), getCollections() ];\n\t}, [] );\n\n\tconst onSelectItem = useCallback(\n\t\t(\n\t\t\t{ name, initialAttributes, innerBlocks, syncStatus, content },\n\t\t\tshouldFocusBlock\n\t\t) => {\n\t\t\tconst destinationClientId = getClosestAllowedInsertionPoint(\n\t\t\t\tname,\n\t\t\t\trootClientId\n\t\t\t);\n\t\t\tif ( destinationClientId === null ) {\n\t\t\t\tconst title = getBlockType( name )?.title ?? name;\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: block pattern title. */\n\t\t\t\t\t\t__( 'Block \"%s\" can\\'t be inserted.' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'inserter-notice',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst insertedBlock =\n\t\t\t\tsyncStatus === 'unsynced'\n\t\t\t\t\t? parse( content, {\n\t\t\t\t\t\t\t__unstableSkipMigrationLogs: true,\n\t\t\t\t\t } )\n\t\t\t\t\t: createBlock(\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tinitialAttributes,\n\t\t\t\t\t\t\tcreateBlocksFromInnerBlocksTemplate( innerBlocks )\n\t\t\t\t\t );\n\t\t\tonInsert(\n\t\t\t\tinsertedBlock,\n\t\t\t\tundefined,\n\t\t\t\tshouldFocusBlock,\n\t\t\t\tdestinationClientId\n\t\t\t);\n\t\t},\n\t\t[\n\t\t\tgetClosestAllowedInsertionPoint,\n\t\t\trootClientId,\n\t\t\tonInsert,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\treturn [ items, categories, collections, onSelectItem ];\n};\n\nexport default useBlockTypesState;\n"],
5
- "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,WAAW,mBAAmB;AACvC,SAAS,aAAa,eAAe;AACrC,SAAS,SAAS,oBAAoB;AACtC,SAAS,IAAI,eAAe;AAK5B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AAUvB,IAAM,qBAAqB,CAAE,cAAc,UAAU,YAAa;AACjE,QAAM,UAAU;AAAA,IACf,OAAQ,EAAE,CAAE,UAAW,GAAG,CAAC,CAAE,QAAQ;AAAA,IACrC,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,CAAE,KAAM,IAAI;AAAA,IACjB,CAAE,WAAY;AAAA,MACb,OAAQ,gBAAiB,EAAE;AAAA,QAC1B;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,cAAc,OAAQ;AAAA,EACzB;AACA,QAAM,EAAE,gCAAgC,IAAI;AAAA,IAC3C,UAAW,gBAAiB;AAAA,EAC7B;AACA,QAAM,EAAE,kBAAkB,IAAI,YAAa,YAAa;AAExD,QAAM,CAAE,YAAY,WAAY,IAAI,UAAW,CAAE,WAAY;AAC5D,UAAM,EAAE,eAAe,eAAe,IAAI,OAAQ,WAAY;AAC9D,WAAO,CAAE,cAAc,GAAG,eAAe,CAAE;AAAA,EAC5C,GAAG,CAAC,CAAE;AAEN,QAAM,eAAe;AAAA,IACpB,CACC,EAAE,MAAM,mBAAmB,aAAa,YAAY,QAAQ,GAC5D,qBACI;AACJ,YAAM,sBAAsB;AAAA,QAC3B;AAAA,QACA;AAAA,MACD;AACA,UAAK,wBAAwB,MAAO;AACnC,cAAM,QAAQ,aAAc,IAAK,GAAG,SAAS;AAC7C;AAAA,UACC;AAAA;AAAA,YAEC,GAAI,+BAAiC;AAAA,YACrC;AAAA,UACD;AAAA,UACA;AAAA,YACC,MAAM;AAAA,YACN,IAAI;AAAA,UACL;AAAA,QACD;AACA;AAAA,MACD;AAEA,YAAM,gBACL,eAAe,aACZ,MAAO,SAAS;AAAA,QAChB,6BAA6B;AAAA,MAC7B,CAAE,IACF;AAAA,QACA;AAAA,QACA;AAAA,QACA,oCAAqC,WAAY;AAAA,MACjD;AACJ;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,SAAO,CAAE,OAAO,YAAY,aAAa,YAAa;AACvD;AAEA,IAAO,gCAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tgetBlockType,\n\tcreateBlock,\n\tcreateBlocksFromInnerBlocksTemplate,\n\tstore as blocksStore,\n\tparse,\n} from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { isFiltered } from '../../../store/utils';\nimport { unlock } from '../../../lock-unlock';\n\n/**\n * Retrieves the block types inserter state.\n *\n * @param {string=} rootClientId Insertion's root client ID.\n * @param {Function} onInsert function called when inserter a list of blocks.\n * @param {boolean} isQuick\n * @return {Array} Returns the block types state. (block types, categories, collections, onSelect handler)\n */\nconst useBlockTypesState = ( rootClientId, onInsert, isQuick ) => {\n\tconst options = useMemo(\n\t\t() => ( { [ isFiltered ]: !! isQuick } ),\n\t\t[ isQuick ]\n\t);\n\tconst [ items ] = useSelect(\n\t\t( select ) => [\n\t\t\tselect( blockEditorStore ).getInserterItems(\n\t\t\t\trootClientId,\n\t\t\t\toptions\n\t\t\t),\n\t\t],\n\t\t[ rootClientId, options ]\n\t);\n\tconst { getClosestAllowedInsertionPoint } = unlock(\n\t\tuseSelect( blockEditorStore )\n\t);\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tconst [ categories, collections ] = useSelect( ( select ) => {\n\t\tconst { getCategories, getCollections } = select( blocksStore );\n\t\treturn [ getCategories(), getCollections() ];\n\t}, [] );\n\n\tconst onSelectItem = useCallback(\n\t\t(\n\t\t\t{\n\t\t\t\tname,\n\t\t\t\tinitialAttributes,\n\t\t\t\tinnerBlocks,\n\t\t\t\tinnerContent,\n\t\t\t\tsyncStatus,\n\t\t\t\tcontent,\n\t\t\t},\n\t\t\tshouldFocusBlock\n\t\t) => {\n\t\t\tconst destinationClientId = getClosestAllowedInsertionPoint(\n\t\t\t\tname,\n\t\t\t\trootClientId\n\t\t\t);\n\t\t\tif ( destinationClientId === null ) {\n\t\t\t\tconst title = getBlockType( name )?.title ?? name;\n\t\t\t\tcreateErrorNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: block pattern title. */\n\t\t\t\t\t\t__( 'Block \"%s\" can\\'t be inserted.' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'inserter-notice',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst insertedBlock =\n\t\t\t\tsyncStatus === 'unsynced'\n\t\t\t\t\t? parse( content, {\n\t\t\t\t\t\t\t__unstableSkipMigrationLogs: true,\n\t\t\t\t\t } )\n\t\t\t\t\t: createBlock(\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tinitialAttributes,\n\t\t\t\t\t\t\tcreateBlocksFromInnerBlocksTemplate( innerBlocks ),\n\t\t\t\t\t\t\tinnerContent\n\t\t\t\t\t );\n\t\t\tonInsert(\n\t\t\t\tinsertedBlock,\n\t\t\t\tundefined,\n\t\t\t\tshouldFocusBlock,\n\t\t\t\tdestinationClientId\n\t\t\t);\n\t\t},\n\t\t[\n\t\t\tgetClosestAllowedInsertionPoint,\n\t\t\trootClientId,\n\t\t\tonInsert,\n\t\t\tcreateErrorNotice,\n\t\t]\n\t);\n\n\treturn [ items, categories, collections, onSelectItem ];\n};\n\nexport default useBlockTypesState;\n"],
5
+ "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,WAAW,mBAAmB;AACvC,SAAS,aAAa,eAAe;AACrC,SAAS,SAAS,oBAAoB;AACtC,SAAS,IAAI,eAAe;AAK5B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AAUvB,IAAM,qBAAqB,CAAE,cAAc,UAAU,YAAa;AACjE,QAAM,UAAU;AAAA,IACf,OAAQ,EAAE,CAAE,UAAW,GAAG,CAAC,CAAE,QAAQ;AAAA,IACrC,CAAE,OAAQ;AAAA,EACX;AACA,QAAM,CAAE,KAAM,IAAI;AAAA,IACjB,CAAE,WAAY;AAAA,MACb,OAAQ,gBAAiB,EAAE;AAAA,QAC1B;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,cAAc,OAAQ;AAAA,EACzB;AACA,QAAM,EAAE,gCAAgC,IAAI;AAAA,IAC3C,UAAW,gBAAiB;AAAA,EAC7B;AACA,QAAM,EAAE,kBAAkB,IAAI,YAAa,YAAa;AAExD,QAAM,CAAE,YAAY,WAAY,IAAI,UAAW,CAAE,WAAY;AAC5D,UAAM,EAAE,eAAe,eAAe,IAAI,OAAQ,WAAY;AAC9D,WAAO,CAAE,cAAc,GAAG,eAAe,CAAE;AAAA,EAC5C,GAAG,CAAC,CAAE;AAEN,QAAM,eAAe;AAAA,IACpB,CACC;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,GACA,qBACI;AACJ,YAAM,sBAAsB;AAAA,QAC3B;AAAA,QACA;AAAA,MACD;AACA,UAAK,wBAAwB,MAAO;AACnC,cAAM,QAAQ,aAAc,IAAK,GAAG,SAAS;AAC7C;AAAA,UACC;AAAA;AAAA,YAEC,GAAI,+BAAiC;AAAA,YACrC;AAAA,UACD;AAAA,UACA;AAAA,YACC,MAAM;AAAA,YACN,IAAI;AAAA,UACL;AAAA,QACD;AACA;AAAA,MACD;AAEA,YAAM,gBACL,eAAe,aACZ,MAAO,SAAS;AAAA,QAChB,6BAA6B;AAAA,MAC7B,CAAE,IACF;AAAA,QACA;AAAA,QACA;AAAA,QACA,oCAAqC,WAAY;AAAA,QACjD;AAAA,MACA;AACJ;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,SAAO,CAAE,OAAO,YAAY,aAAa,YAAa;AACvD;AAEA,IAAO,gCAAQ;",
6
6
  "names": []
7
7
  }
@@ -3,28 +3,54 @@ import { useEffect, useState, useRef } from "@wordpress/element";
3
3
  import { useSelect } from "@wordpress/data";
4
4
  import { store as blockEditorStore } from "../../../store/index.mjs";
5
5
  import { unlock } from "../../../lock-unlock.mjs";
6
- function useMediaResults(category, query = {}) {
6
+ function useMediaResults(category, query = {}, refreshKey) {
7
7
  const [mediaList, setMediaList] = useState();
8
8
  const [isLoading, setIsLoading] = useState(false);
9
9
  const lastRequestRef = useRef();
10
+ const lastQueryKeyRef = useRef();
11
+ const lastFetchRef = useRef();
10
12
  useEffect(() => {
11
13
  (async () => {
12
14
  const key = JSON.stringify({
13
15
  category: category.name,
14
16
  ...query
15
17
  });
16
- lastRequestRef.current = key;
18
+ const request = {};
19
+ lastRequestRef.current = request;
17
20
  setIsLoading(true);
18
- setMediaList([]);
21
+ if (lastQueryKeyRef.current !== key || lastFetchRef.current !== category.fetch) {
22
+ setMediaList([]);
23
+ }
24
+ lastQueryKeyRef.current = key;
25
+ lastFetchRef.current = category.fetch;
19
26
  const _media = await category.fetch?.(query);
20
- if (key === lastRequestRef.current) {
27
+ if (request === lastRequestRef.current) {
21
28
  setMediaList(_media);
22
29
  setIsLoading(false);
23
30
  }
24
31
  })();
25
- }, [category.name, ...Object.values(query)]);
32
+ }, [
33
+ category.name,
34
+ category.fetch,
35
+ ...Object.values(query),
36
+ refreshKey
37
+ ]);
26
38
  return { mediaList, isLoading };
27
39
  }
40
+ function useDelayedLoading(isLoading, delay = 400) {
41
+ const [showLoading, setShowLoading] = useState(false);
42
+ useEffect(() => {
43
+ if (!isLoading) {
44
+ return void 0;
45
+ }
46
+ const timeout = setTimeout(() => setShowLoading(true), delay);
47
+ return () => {
48
+ clearTimeout(timeout);
49
+ setShowLoading(false);
50
+ };
51
+ }, [isLoading, delay]);
52
+ return showLoading;
53
+ }
28
54
  function useMediaCategories(rootClientId) {
29
55
  const [categories, setCategories] = useState([]);
30
56
  const inserterMediaCategories = useSelect(
@@ -80,7 +106,7 @@ function useMediaCategories(rootClientId) {
80
106
  audio: canInsertAudio
81
107
  };
82
108
  inserterMediaCategories.forEach((category) => {
83
- if (canInsertMediaType[category.mediaType] && categoriesHaveMedia.get(category.name)) {
109
+ if (canInsertMediaType[category.mediaType] && (categoriesHaveMedia.get(category.name) || category.emptyMessage)) {
84
110
  _categories.push(category);
85
111
  }
86
112
  });
@@ -97,6 +123,7 @@ function useMediaCategories(rootClientId) {
97
123
  return categories;
98
124
  }
99
125
  export {
126
+ useDelayedLoading,
100
127
  useMediaCategories,
101
128
  useMediaResults
102
129
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/inserter/media-tab/hooks.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\n/** @typedef {import('../../../store/actions').InserterMediaRequest} InserterMediaRequest */\n/** @typedef {import('../../../store/actions').InserterMediaItem} InserterMediaItem */\n\n/**\n * Fetches media items based on the provided category.\n * Each media category is responsible for providing a `fetch` function.\n *\n * @param {Object} category The media category to fetch results for.\n * @param {InserterMediaRequest} query The query args to use for the request.\n * @return {InserterMediaItem[]} The media results.\n */\nexport function useMediaResults( category, query = {} ) {\n\tconst [ mediaList, setMediaList ] = useState();\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\t// We need to keep track of the last request made because\n\t// multiple request can be fired without knowing the order\n\t// of resolution, and we need to ensure we are showing\n\t// the results of the last request.\n\t// In the future we could use AbortController to cancel previous\n\t// requests, but we don't for now as it involves adding support\n\t// for this to `core-data` package.\n\tconst lastRequestRef = useRef();\n\tuseEffect( () => {\n\t\t( async () => {\n\t\t\tconst key = JSON.stringify( {\n\t\t\t\tcategory: category.name,\n\t\t\t\t...query,\n\t\t\t} );\n\t\t\tlastRequestRef.current = key;\n\t\t\tsetIsLoading( true );\n\t\t\tsetMediaList( [] ); // Empty the previous results.\n\t\t\tconst _media = await category.fetch?.( query );\n\t\t\tif ( key === lastRequestRef.current ) {\n\t\t\t\tsetMediaList( _media );\n\t\t\t\tsetIsLoading( false );\n\t\t\t}\n\t\t} )();\n\t}, [ category.name, ...Object.values( query ) ] );\n\treturn { mediaList, isLoading };\n}\n\nexport function useMediaCategories( rootClientId ) {\n\tconst [ categories, setCategories ] = useState( [] );\n\n\tconst inserterMediaCategories = useSelect(\n\t\t( select ) =>\n\t\t\tunlock( select( blockEditorStore ) ).getInserterMediaCategories(),\n\t\t[]\n\t);\n\tconst { canInsertImage, canInsertVideo, canInsertAudio } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canInsertBlockType } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\tcanInsertImage: canInsertBlockType(\n\t\t\t\t\t'core/image',\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t\tcanInsertVideo: canInsertBlockType(\n\t\t\t\t\t'core/video',\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t\tcanInsertAudio: canInsertBlockType(\n\t\t\t\t\t'core/audio',\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\tuseEffect( () => {\n\t\t( async () => {\n\t\t\tconst _categories = [];\n\t\t\t// If `inserterMediaCategories` is not defined in\n\t\t\t// block editor settings, do not show any media categories.\n\t\t\tif ( ! inserterMediaCategories ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Loop through categories to check if they have at least one media item.\n\t\t\tconst categoriesHaveMedia = new Map(\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tinserterMediaCategories.map( async ( category ) => {\n\t\t\t\t\t\t// Some sources are external and we don't need to make a request.\n\t\t\t\t\t\tif ( category.isExternalResource ) {\n\t\t\t\t\t\t\treturn [ category.name, true ];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet results = [];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tresults = await category.fetch( {\n\t\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// If the request fails, we shallow the error and just don't show\n\t\t\t\t\t\t\t// the category, in order to not break the media tab.\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn [ category.name, !! results.length ];\n\t\t\t\t\t} )\n\t\t\t\t)\n\t\t\t);\n\t\t\t// We need to filter out categories that don't have any media items or\n\t\t\t// whose corresponding block type is not allowed to be inserted, based\n\t\t\t// on the category's `mediaType`.\n\t\t\tconst canInsertMediaType = {\n\t\t\t\timage: canInsertImage,\n\t\t\t\tvideo: canInsertVideo,\n\t\t\t\taudio: canInsertAudio,\n\t\t\t};\n\t\t\tinserterMediaCategories.forEach( ( category ) => {\n\t\t\t\tif (\n\t\t\t\t\tcanInsertMediaType[ category.mediaType ] &&\n\t\t\t\t\tcategoriesHaveMedia.get( category.name )\n\t\t\t\t) {\n\t\t\t\t\t_categories.push( category );\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( !! _categories.length ) {\n\t\t\t\tsetCategories( _categories );\n\t\t\t}\n\t\t} )();\n\t}, [\n\t\tcanInsertImage,\n\t\tcanInsertVideo,\n\t\tcanInsertAudio,\n\t\tinserterMediaCategories,\n\t] );\n\treturn categories;\n}\n"],
5
- "mappings": ";AAGA,SAAS,WAAW,UAAU,cAAc;AAC5C,SAAS,iBAAiB;AAK1B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AAahB,SAAS,gBAAiB,UAAU,QAAQ,CAAC,GAAI;AACvD,QAAM,CAAE,WAAW,YAAa,IAAI,SAAS;AAC7C,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AAQpD,QAAM,iBAAiB,OAAO;AAC9B,YAAW,MAAM;AAChB,KAAE,YAAY;AACb,YAAM,MAAM,KAAK,UAAW;AAAA,QAC3B,UAAU,SAAS;AAAA,QACnB,GAAG;AAAA,MACJ,CAAE;AACF,qBAAe,UAAU;AACzB,mBAAc,IAAK;AACnB,mBAAc,CAAC,CAAE;AACjB,YAAM,SAAS,MAAM,SAAS,QAAS,KAAM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AAA,QACH;AAAA,MACD;AAIA,YAAM,qBAAqB;AAAA,QAC1B,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,MACR;AACA,8BAAwB,QAAS,CAAE,aAAc;AAChD,YACC,mBAAoB,SAAS,SAAU,KACvC,oBAAoB,IAAK,SAAS,IAAK,GACtC;AACD,sBAAY,KAAM,QAAS;AAAA,QAC5B;AAAA,MACD,CAAE;AACF,UAAK,CAAC,CAAE,YAAY,QAAS;AAC5B,sBAAe,WAAY;AAAA,MAC5B;AAAA,IACD,GAAI;AAAA,EACL,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useState, useRef } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\n/** @typedef {import('../../../store/actions').InserterMediaRequest} InserterMediaRequest */\n/** @typedef {import('../../../store/actions').InserterMediaItem} InserterMediaItem */\n\n/**\n * Fetches media items based on the provided category.\n * Each media category is responsible for providing a `fetch` function.\n *\n * @param {Object} category The media category to fetch results for.\n * @param {InserterMediaRequest} query The query args to use for the request.\n * @param {any} refreshKey Optional value that, when changed, forces\n * a refetch (e.g. after attaching/detaching).\n * @return {InserterMediaItem[]} The media results.\n */\nexport function useMediaResults( category, query = {}, refreshKey ) {\n\tconst [ mediaList, setMediaList ] = useState();\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\t// We need to keep track of the last request made because\n\t// multiple request can be fired without knowing the order\n\t// of resolution, and we need to ensure we are showing\n\t// the results of the last request.\n\t// In the future we could use AbortController to cancel previous\n\t// requests, but we don't for now as it involves adding support\n\t// for this to `core-data` package.\n\tconst lastRequestRef = useRef();\n\tconst lastQueryKeyRef = useRef();\n\tconst lastFetchRef = useRef();\n\tuseEffect( () => {\n\t\t( async () => {\n\t\t\tconst key = JSON.stringify( {\n\t\t\t\tcategory: category.name,\n\t\t\t\t...query,\n\t\t\t} );\n\t\t\t// Unique token so identical-query refreshes can't apply stale results.\n\t\t\tconst request = {};\n\t\t\tlastRequestRef.current = request;\n\t\t\tsetIsLoading( true );\n\t\t\t// Only clear the previous results when the category source or query\n\t\t\t// changes, not on a manual refresh (a `refreshKey` bump after\n\t\t\t// attach/detach). Keeping them lets the panel dim the existing grid\n\t\t\t// during the refetch instead of blanking it.\n\t\t\tif (\n\t\t\t\tlastQueryKeyRef.current !== key ||\n\t\t\t\tlastFetchRef.current !== category.fetch\n\t\t\t) {\n\t\t\t\tsetMediaList( [] );\n\t\t\t}\n\t\t\tlastQueryKeyRef.current = key;\n\t\t\tlastFetchRef.current = category.fetch;\n\t\t\tconst _media = await category.fetch?.( query );\n\t\t\tif ( request === lastRequestRef.current ) {\n\t\t\t\tsetMediaList( _media );\n\t\t\t\tsetIsLoading( false );\n\t\t\t}\n\t\t} )();\n\t}, [\n\t\tcategory.name,\n\t\tcategory.fetch,\n\t\t...Object.values( query ),\n\t\trefreshKey,\n\t] );\n\treturn { mediaList, isLoading };\n}\n\n/**\n * Delays surfacing a loading state until a request has been in flight for\n * `delay` ms, so brief operations (e.g. a quick attach/detach refetch) don't\n * flash a loading indicator at all. Mirrors the DataViews `useDelayedLoading`\n * hook.\n *\n * @param {boolean} isLoading Whether a request is currently in flight.\n * @param {number} delay Milliseconds to wait before showing the loader.\n * @return {boolean} Whether the loading state should be shown yet.\n */\nexport function useDelayedLoading( isLoading, delay = 400 ) {\n\tconst [ showLoading, setShowLoading ] = useState( false );\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst timeout = setTimeout( () => setShowLoading( true ), delay );\n\t\treturn () => {\n\t\t\tclearTimeout( timeout );\n\t\t\tsetShowLoading( false );\n\t\t};\n\t}, [ isLoading, delay ] );\n\treturn showLoading;\n}\n\nexport function useMediaCategories( rootClientId ) {\n\tconst [ categories, setCategories ] = useState( [] );\n\n\tconst inserterMediaCategories = useSelect(\n\t\t( select ) =>\n\t\t\tunlock( select( blockEditorStore ) ).getInserterMediaCategories(),\n\t\t[]\n\t);\n\tconst { canInsertImage, canInsertVideo, canInsertAudio } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { canInsertBlockType } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\tcanInsertImage: canInsertBlockType(\n\t\t\t\t\t'core/image',\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t\tcanInsertVideo: canInsertBlockType(\n\t\t\t\t\t'core/video',\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t\tcanInsertAudio: canInsertBlockType(\n\t\t\t\t\t'core/audio',\n\t\t\t\t\trootClientId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ rootClientId ]\n\t);\n\tuseEffect( () => {\n\t\t( async () => {\n\t\t\tconst _categories = [];\n\t\t\t// If `inserterMediaCategories` is not defined in\n\t\t\t// block editor settings, do not show any media categories.\n\t\t\tif ( ! inserterMediaCategories ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Loop through categories to check if they have at least one media item.\n\t\t\tconst categoriesHaveMedia = new Map(\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tinserterMediaCategories.map( async ( category ) => {\n\t\t\t\t\t\t// Some sources are external and we don't need to make a request.\n\t\t\t\t\t\tif ( category.isExternalResource ) {\n\t\t\t\t\t\t\treturn [ category.name, true ];\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet results = [];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tresults = await category.fetch( {\n\t\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// If the request fails, we shallow the error and just don't show\n\t\t\t\t\t\t\t// the category, in order to not break the media tab.\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn [ category.name, !! results.length ];\n\t\t\t\t\t} )\n\t\t\t\t)\n\t\t\t);\n\t\t\t// We need to filter out categories that don't have any media items or\n\t\t\t// whose corresponding block type is not allowed to be inserted, based\n\t\t\t// on the category's `mediaType`. A category that provides an\n\t\t\t// `emptyMessage` stays in the list even when empty, so it can show\n\t\t\t// that message (e.g. Attachments, to expose its \"Attach\" action).\n\t\t\tconst canInsertMediaType = {\n\t\t\t\timage: canInsertImage,\n\t\t\t\tvideo: canInsertVideo,\n\t\t\t\taudio: canInsertAudio,\n\t\t\t};\n\t\t\tinserterMediaCategories.forEach( ( category ) => {\n\t\t\t\tif (\n\t\t\t\t\tcanInsertMediaType[ category.mediaType ] &&\n\t\t\t\t\t( categoriesHaveMedia.get( category.name ) ||\n\t\t\t\t\t\tcategory.emptyMessage )\n\t\t\t\t) {\n\t\t\t\t\t_categories.push( category );\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( !! _categories.length ) {\n\t\t\t\tsetCategories( _categories );\n\t\t\t}\n\t\t} )();\n\t}, [\n\t\tcanInsertImage,\n\t\tcanInsertVideo,\n\t\tcanInsertAudio,\n\t\tinserterMediaCategories,\n\t] );\n\treturn categories;\n}\n"],
5
+ "mappings": ";AAGA,SAAS,WAAW,UAAU,cAAc;AAC5C,SAAS,iBAAiB;AAK1B,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AAehB,SAAS,gBAAiB,UAAU,QAAQ,CAAC,GAAG,YAAa;AACnE,QAAM,CAAE,WAAW,YAAa,IAAI,SAAS;AAC7C,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AAQpD,QAAM,iBAAiB,OAAO;AAC9B,QAAM,kBAAkB,OAAO;AAC/B,QAAM,eAAe,OAAO;AAC5B,YAAW,MAAM;AAChB,KAAE,YAAY;AACb,YAAM,MAAM,KAAK,UAAW;AAAA,QAC3B,UAAU,SAAS;AAAA,QACnB,GAAG;AAAA,MACJ,CAAE;AAEF,YAAM,UAAU,CAAC;AACjB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D;AAAA,QACA,gBAAgB;AAAA,UACf;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,YAAa;AAAA,EAChB;AACA,YAAW,MAAM;AAChB,KAAE,YAAY;AACb,YAAM,cAAc,CAAC;AAGrB,UAAK,CAAE,yBAA0B;AAChC;AAAA,MACD;AAEA,YAAM,sBAAsB,IAAI;AAAA,QAC/B,MAAM,QAAQ;AAAA,UACb,wBAAwB,IAAK,OAAQ,aAAc;AAElD,gBAAK,SAAS,oBAAqB;AAClC,qBAAO,CAAE,SAAS,MAAM,IAAK;AAAA,YAC9B;AACA,gBAAI,UAAU,CAAC;AACf,gBAAI;AACH,wBAAU,MAAM,SAAS,MAAO;AAAA,gBAC/B,UAAU;AAAA,cACX,CAAE;AAAA,YACH,QAAQ;AAAA,YAGR;AACA,mBAAO,CAAE,SAAS,MAAM,CAAC,CAAE,QAAQ,MAAO;AAAA,UAC3C,CAAE;AAAA,QACH;AAAA,MACD;AAMA,YAAM,qBAAqB;AAAA,QAC1B,OAAO;AAAA,QACP,OAAO;AAAA,QACP,OAAO;AAAA,MACR;AACA,8BAAwB,QAAS,CAAE,aAAc;AAChD,YACC,mBAAoB,SAAS,SAAU,MACrC,oBAAoB,IAAK,SAAS,IAAK,KACxC,SAAS,eACT;AACD,sBAAY,KAAM,QAAS;AAAA,QAC5B;AAAA,MACD,CAAE;AACF,UAAK,CAAC,CAAE,YAAY,QAAS;AAC5B,sBAAe,WAAY;AAAA,MAC5B;AAAA,IACD,GAAI;AAAA,EACL,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
6
6
  "names": []
7
7
  }
@@ -7,6 +7,7 @@ function MediaList({
7
7
  mediaList,
8
8
  category,
9
9
  onClick,
10
+ onDetach,
10
11
  label = __("Media List")
11
12
  }) {
12
13
  return /* @__PURE__ */ jsx(
@@ -20,7 +21,8 @@ function MediaList({
20
21
  {
21
22
  media,
22
23
  category,
23
- onClick
24
+ onClick,
25
+ onDetach
24
26
  },
25
27
  media.id || media.sourceId || index
26
28
  ))
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/inserter/media-tab/media-list.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Composite } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { MediaPreview } from './media-preview';\n\nfunction MediaList( {\n\tmediaList,\n\tcategory,\n\tonClick,\n\tlabel = __( 'Media List' ),\n} ) {\n\treturn (\n\t\t<Composite\n\t\t\trole=\"listbox\"\n\t\t\tclassName=\"block-editor-inserter__media-list\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ mediaList.map( ( media, index ) => (\n\t\t\t\t<MediaPreview\n\t\t\t\t\tkey={ media.id || media.sourceId || index }\n\t\t\t\t\tmedia={ media }\n\t\t\t\t\tcategory={ category }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Composite>\n\t);\n}\n\nexport default MediaList;\n"],
5
- "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AAKnB,SAAS,oBAAoB;AAezB;AAbJ,SAAS,UAAW;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,GAAI,YAAa;AAC1B,GAAI;AACH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACV,cAAa;AAAA,MAEX,oBAAU,IAAK,CAAE,OAAO,UACzB;AAAA,QAAC;AAAA;AAAA,UAEA;AAAA,UACA;AAAA,UACA;AAAA;AAAA,QAHM,MAAM,MAAM,MAAM,YAAY;AAAA,MAIrC,CACC;AAAA;AAAA,EACH;AAEF;AAEA,IAAO,qBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Composite } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { MediaPreview } from './media-preview';\n\nfunction MediaList( {\n\tmediaList,\n\tcategory,\n\tonClick,\n\tonDetach,\n\tlabel = __( 'Media List' ),\n} ) {\n\treturn (\n\t\t<Composite\n\t\t\trole=\"listbox\"\n\t\t\tclassName=\"block-editor-inserter__media-list\"\n\t\t\taria-label={ label }\n\t\t>\n\t\t\t{ mediaList.map( ( media, index ) => (\n\t\t\t\t<MediaPreview\n\t\t\t\t\tkey={ media.id || media.sourceId || index }\n\t\t\t\t\tmedia={ media }\n\t\t\t\t\tcategory={ category }\n\t\t\t\t\tonClick={ onClick }\n\t\t\t\t\tonDetach={ onDetach }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Composite>\n\t);\n}\n\nexport default MediaList;\n"],
5
+ "mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,UAAU;AAKnB,SAAS,oBAAoB;AAgBzB;AAdJ,SAAS,UAAW;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,GAAI,YAAa;AAC1B,GAAI;AACH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,MAAK;AAAA,MACL,WAAU;AAAA,MACV,cAAa;AAAA,MAEX,oBAAU,IAAK,CAAE,OAAO,UACzB;AAAA,QAAC;AAAA;AAAA,UAEA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA,QAJM,MAAM,MAAM,MAAM,YAAY;AAAA,MAKrC,CACC;AAAA;AAAA,EACH;AAEF;AAEA,IAAO,qBAAQ;",
6
6
  "names": []
7
7
  }
@@ -1,43 +1,240 @@
1
1
  // packages/block-editor/src/components/inserter/media-tab/media-panel.js
2
- import { Spinner, SearchControl } from "@wordpress/components";
3
- import { __ } from "@wordpress/i18n";
2
+ import clsx from "clsx";
3
+ import { Button, Modal, Spinner, SearchControl } from "@wordpress/components";
4
+ import { __, _n, sprintf } from "@wordpress/i18n";
5
+ import { useCallback, useMemo, useState } from "@wordpress/element";
4
6
  import { useDebouncedInput } from "@wordpress/compose";
7
+ import { useDispatch } from "@wordpress/data";
8
+ import { store as noticesStore } from "@wordpress/notices";
5
9
  import MediaList from "./media-list.mjs";
6
- import { useMediaResults } from "./hooks.mjs";
10
+ import MediaUpload from "../../media-upload/index.mjs";
11
+ import MediaUploadCheck from "../../media-upload/check.mjs";
12
+ import { useMediaResults, useDelayedLoading } from "./hooks.mjs";
7
13
  import InserterNoResults from "../no-results.mjs";
8
14
  import { jsx, jsxs } from "react/jsx-runtime";
9
15
  var INITIAL_MEDIA_ITEMS_PER_PAGE = 10;
16
+ var ATTACH_ALLOWED_TYPES = ["image"];
17
+ function AttachImagesButton({ onSelect }) {
18
+ return /* @__PURE__ */ jsx(MediaUploadCheck, { children: /* @__PURE__ */ jsx(
19
+ MediaUpload,
20
+ {
21
+ multiple: "add",
22
+ onSelect,
23
+ allowedTypes: ATTACH_ALLOWED_TYPES,
24
+ title: __("Attach images"),
25
+ render: ({ open }) => /* @__PURE__ */ jsx(
26
+ Button,
27
+ {
28
+ __next40pxDefaultSize: true,
29
+ className: "block-editor-inserter__media-panel-attach",
30
+ "data-unstable-ignore-focus-outside-for-relatedtarget": ".media-modal",
31
+ onClick: (event) => {
32
+ event.target.focus();
33
+ open();
34
+ },
35
+ variant: "secondary",
36
+ children: __("Attach images")
37
+ }
38
+ )
39
+ }
40
+ ) });
41
+ }
10
42
  function MediaCategoryPanel({ rootClientId, onInsert, category }) {
11
43
  const [search, setSearch, debouncedSearch] = useDebouncedInput();
12
- const { mediaList, isLoading } = useMediaResults(category, {
13
- per_page: !!debouncedSearch ? 20 : INITIAL_MEDIA_ITEMS_PER_PAGE,
14
- search: debouncedSearch
15
- });
16
- const baseCssClass = "block-editor-inserter__media-panel";
17
- const searchLabel = category.labels.search_items || __("Search");
18
- return /* @__PURE__ */ jsxs("div", { className: baseCssClass, children: [
19
- /* @__PURE__ */ jsx(
20
- SearchControl,
21
- {
22
- className: `${baseCssClass}-search`,
23
- onChange: setSearch,
24
- value: search,
25
- label: searchLabel,
26
- placeholder: searchLabel
44
+ const query = useMemo(
45
+ () => ({
46
+ per_page: !!debouncedSearch ? 20 : INITIAL_MEDIA_ITEMS_PER_PAGE,
47
+ search: debouncedSearch
48
+ }),
49
+ [debouncedSearch]
50
+ );
51
+ const [refreshKey, setRefreshKey] = useState(0);
52
+ const { mediaList, isLoading } = useMediaResults(
53
+ category,
54
+ query,
55
+ refreshKey
56
+ );
57
+ const { createErrorNotice, createSuccessNotice, createWarningNotice } = useDispatch(noticesStore);
58
+ const showRefreshing = useDelayedLoading(isLoading);
59
+ const refresh = useCallback(() => {
60
+ category.invalidate?.(query);
61
+ setRefreshKey((key) => key + 1);
62
+ }, [category, query]);
63
+ const handleAttach = useCallback(
64
+ async (selectedMedia) => {
65
+ try {
66
+ const attachedCount = await category.attach(selectedMedia);
67
+ if (!attachedCount) {
68
+ createWarningNotice(__("No images were attached."), {
69
+ type: "snackbar",
70
+ id: "inserter-notice"
71
+ });
72
+ return;
73
+ }
74
+ refresh();
75
+ createSuccessNotice(
76
+ category.postTypeLabel ? sprintf(
77
+ /* translators: %1$d: Number of images attached. %2$s: Name of the post type e.g: "Page". */
78
+ _n(
79
+ "%1$d image attached to %2$s.",
80
+ "%1$d images attached to %2$s.",
81
+ attachedCount
82
+ ),
83
+ attachedCount,
84
+ category.postTypeLabel
85
+ ) : sprintf(
86
+ /* translators: %d: Number of images attached to the post. */
87
+ _n(
88
+ "%d image attached to post.",
89
+ "%d images attached to post.",
90
+ attachedCount
91
+ ),
92
+ attachedCount
93
+ ),
94
+ { type: "snackbar", id: "inserter-notice" }
95
+ );
96
+ } catch {
97
+ createErrorNotice(__("Could not attach images."), {
98
+ type: "snackbar",
99
+ id: "inserter-notice"
100
+ });
27
101
  }
28
- ),
29
- isLoading && /* @__PURE__ */ jsx("div", { className: `${baseCssClass}-spinner`, children: /* @__PURE__ */ jsx(Spinner, {}) }),
30
- !isLoading && !mediaList?.length && /* @__PURE__ */ jsx(InserterNoResults, {}),
31
- !isLoading && !!mediaList?.length && /* @__PURE__ */ jsx(
32
- MediaList,
33
- {
34
- rootClientId,
35
- onClick: onInsert,
36
- mediaList,
37
- category
102
+ },
103
+ [
104
+ category,
105
+ refresh,
106
+ createErrorNotice,
107
+ createSuccessNotice,
108
+ createWarningNotice
109
+ ]
110
+ );
111
+ const handleDetach = useCallback(
112
+ async (media) => {
113
+ try {
114
+ await category.detach(media);
115
+ refresh();
116
+ createSuccessNotice(
117
+ category.postTypeLabel ? sprintf(
118
+ /* translators: %s: Name of the post type e.g: "Page". */
119
+ __("Image detached from %s."),
120
+ category.postTypeLabel
121
+ ) : __("Image detached from post."),
122
+ { type: "snackbar", id: "inserter-notice" }
123
+ );
124
+ } catch {
125
+ createErrorNotice(__("Could not detach image."), {
126
+ type: "snackbar",
127
+ id: "inserter-notice"
128
+ });
38
129
  }
39
- )
40
- ] });
130
+ },
131
+ [category, refresh, createErrorNotice, createSuccessNotice]
132
+ );
133
+ const [mediaPendingDetach, setMediaPendingDetach] = useState();
134
+ const confirmDetach = useCallback(() => {
135
+ const media = mediaPendingDetach;
136
+ setMediaPendingDetach(void 0);
137
+ handleDetach(media);
138
+ }, [handleDetach, mediaPendingDetach]);
139
+ const baseCssClass = "block-editor-inserter__media-panel";
140
+ const searchLabel = category.labels.search_items || __("Search");
141
+ return /* @__PURE__ */ jsxs(
142
+ "div",
143
+ {
144
+ className: clsx(baseCssClass, {
145
+ // The attach footer supplies the breathing room beneath the
146
+ // grid, so the list drops its own bottom padding (see styles).
147
+ "has-attach-footer": !!category.attach
148
+ }),
149
+ children: [
150
+ /* @__PURE__ */ jsx(
151
+ SearchControl,
152
+ {
153
+ className: `${baseCssClass}-search`,
154
+ onChange: setSearch,
155
+ value: search,
156
+ label: searchLabel,
157
+ placeholder: searchLabel
158
+ }
159
+ ),
160
+ isLoading && !mediaList?.length && /* @__PURE__ */ jsx("div", { className: `${baseCssClass}-spinner`, children: /* @__PURE__ */ jsx(Spinner, {}) }),
161
+ !isLoading && !mediaList?.length && /* @__PURE__ */ jsx(InserterNoResults, { children: category.emptyMessage && !debouncedSearch ? (
162
+ // For a source with a custom empty message (e.g.
163
+ // Attachments) and no active search, an empty result
164
+ // means nothing is attached yet — clearer than the
165
+ // generic "no results found".
166
+ category.emptyMessage
167
+ ) : __("No results found.") }),
168
+ !!mediaList?.length && // Keep the existing items visible while a refetch is in flight,
169
+ // dimming (and gently pulsing) them rather than clearing the grid,
170
+ // so it doesn't flicker or pop.
171
+ /* @__PURE__ */ jsx(
172
+ "div",
173
+ {
174
+ className: clsx(`${baseCssClass}-results`, {
175
+ "is-loading": showRefreshing
176
+ }),
177
+ "aria-busy": showRefreshing,
178
+ children: /* @__PURE__ */ jsx(
179
+ MediaList,
180
+ {
181
+ rootClientId,
182
+ onClick: onInsert,
183
+ onDetach: category.detach ? setMediaPendingDetach : void 0,
184
+ mediaList,
185
+ category
186
+ }
187
+ )
188
+ }
189
+ ),
190
+ category.attach && // Pinned to the bottom of the panel as a fixed footer so it lines
191
+ // up with the "Open Media Library" button in the adjacent column.
192
+ /* @__PURE__ */ jsx(AttachImagesButton, { onSelect: handleAttach }),
193
+ mediaPendingDetach && // A plain `Modal` (not `ConfirmDialog`) so we can pass
194
+ // `overlayClassName` and stack it above the options dropdown that
195
+ // opened it (see the z-index entry in `_z-index.scss`).
196
+ /* @__PURE__ */ jsxs(
197
+ Modal,
198
+ {
199
+ title: __("Detach image"),
200
+ onRequestClose: () => setMediaPendingDetach(void 0),
201
+ overlayClassName: `${baseCssClass}-detach-modal`,
202
+ children: [
203
+ /* @__PURE__ */ jsx("p", { children: category.postTypeLabel ? sprintf(
204
+ /* translators: %s: Name of the post type e.g: "Page". */
205
+ __(
206
+ "Detach this image from the current %s? The image will remain in the Media Library."
207
+ ),
208
+ category.postTypeLabel
209
+ ) : __(
210
+ "Detach this image from the current post? The image will remain in the Media Library."
211
+ ) }),
212
+ /* @__PURE__ */ jsxs("div", { className: `${baseCssClass}-detach-actions`, children: [
213
+ /* @__PURE__ */ jsx(
214
+ Button,
215
+ {
216
+ __next40pxDefaultSize: true,
217
+ variant: "tertiary",
218
+ onClick: () => setMediaPendingDetach(void 0),
219
+ children: __("Cancel")
220
+ }
221
+ ),
222
+ /* @__PURE__ */ jsx(
223
+ Button,
224
+ {
225
+ __next40pxDefaultSize: true,
226
+ variant: "primary",
227
+ onClick: confirmDetach,
228
+ children: __("Detach")
229
+ }
230
+ )
231
+ ] })
232
+ ]
233
+ }
234
+ )
235
+ ]
236
+ }
237
+ );
41
238
  }
42
239
  export {
43
240
  MediaCategoryPanel
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/inserter/media-tab/media-panel.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Spinner, SearchControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useDebouncedInput } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport MediaList from './media-list';\nimport { useMediaResults } from './hooks';\nimport InserterNoResults from '../no-results';\n\nconst INITIAL_MEDIA_ITEMS_PER_PAGE = 10;\n\nexport function MediaCategoryPanel( { rootClientId, onInsert, category } ) {\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst { mediaList, isLoading } = useMediaResults( category, {\n\t\tper_page: !! debouncedSearch ? 20 : INITIAL_MEDIA_ITEMS_PER_PAGE,\n\t\tsearch: debouncedSearch,\n\t} );\n\tconst baseCssClass = 'block-editor-inserter__media-panel';\n\tconst searchLabel = category.labels.search_items || __( 'Search' );\n\treturn (\n\t\t<div className={ baseCssClass }>\n\t\t\t<SearchControl\n\t\t\t\tclassName={ `${ baseCssClass }-search` }\n\t\t\t\tonChange={ setSearch }\n\t\t\t\tvalue={ search }\n\t\t\t\tlabel={ searchLabel }\n\t\t\t\tplaceholder={ searchLabel }\n\t\t\t/>\n\t\t\t{ isLoading && (\n\t\t\t\t<div className={ `${ baseCssClass }-spinner` }>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! isLoading && ! mediaList?.length && <InserterNoResults /> }\n\t\t\t{ ! isLoading && !! mediaList?.length && (\n\t\t\t\t<MediaList\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\tonClick={ onInsert }\n\t\t\t\t\tmediaList={ mediaList }\n\t\t\t\t\tcategory={ category }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,SAAS,qBAAqB;AACvC,SAAS,UAAU;AACnB,SAAS,yBAAyB;AAKlC,OAAO,eAAe;AACtB,SAAS,uBAAuB;AAChC,OAAO,uBAAuB;AAa5B,SACC,KADD;AAXF,IAAM,+BAA+B;AAE9B,SAAS,mBAAoB,EAAE,cAAc,UAAU,SAAS,GAAI;AAC1E,QAAM,CAAE,QAAQ,WAAW,eAAgB,IAAI,kBAAkB;AACjE,QAAM,EAAE,WAAW,UAAU,IAAI,gBAAiB,UAAU;AAAA,IAC3D,UAAU,CAAC,CAAE,kBAAkB,KAAK;AAAA,IACpC,QAAQ;AAAA,EACT,CAAE;AACF,QAAM,eAAe;AACrB,QAAM,cAAc,SAAS,OAAO,gBAAgB,GAAI,QAAS;AACjE,SACC,qBAAC,SAAI,WAAY,cAChB;AAAA;AAAA,MAAC;AAAA;AAAA,QACA,WAAY,GAAI,YAAa;AAAA,QAC7B,UAAW;AAAA,QACX,OAAQ;AAAA,QACR,OAAQ;AAAA,QACR,aAAc;AAAA;AAAA,IACf;AAAA,IACE,aACD,oBAAC,SAAI,WAAY,GAAI,YAAa,YACjC,8BAAC,WAAQ,GACV;AAAA,IAEC,CAAE,aAAa,CAAE,WAAW,UAAU,oBAAC,qBAAkB;AAAA,IACzD,CAAE,aAAa,CAAC,CAAE,WAAW,UAC9B;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,SAAU;AAAA,QACV;AAAA,QACA;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Button, Modal, Spinner, SearchControl } from '@wordpress/components';\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { useCallback, useMemo, useState } from '@wordpress/element';\nimport { useDebouncedInput } from '@wordpress/compose';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport MediaList from './media-list';\nimport MediaUpload from '../../media-upload';\nimport MediaUploadCheck from '../../media-upload/check';\nimport { useMediaResults, useDelayedLoading } from './hooks';\nimport InserterNoResults from '../no-results';\n\nconst INITIAL_MEDIA_ITEMS_PER_PAGE = 10;\n\n// The attach flow is image-only, so the picker is constrained to images.\nconst ATTACH_ALLOWED_TYPES = [ 'image' ];\n\n/**\n * Opens the Media Library to attach images to the current post. Only rendered\n * for media categories that expose an `attach` capability (i.e. the \"Attached\n * images\" source); other sources render the panel exactly as before.\n *\n * The picker opens fresh each time with no pre-selected value, so it is purely\n * additive: selecting images attaches them, and it does not imply that\n * deselecting would detach. Detaching is a separate, explicit per-item action.\n *\n * @param {Object} props\n * @param {Function} props.onSelect Called with the selected media items.\n */\nfunction AttachImagesButton( { onSelect } ) {\n\treturn (\n\t\t<MediaUploadCheck>\n\t\t\t<MediaUpload\n\t\t\t\tmultiple=\"add\"\n\t\t\t\tonSelect={ onSelect }\n\t\t\t\tallowedTypes={ ATTACH_ALLOWED_TYPES }\n\t\t\t\ttitle={ __( 'Attach images' ) }\n\t\t\t\trender={ ( { open } ) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"block-editor-inserter__media-panel-attach\"\n\t\t\t\t\t\tdata-unstable-ignore-focus-outside-for-relatedtarget=\".media-modal\"\n\t\t\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t\t\tevent.target.focus();\n\t\t\t\t\t\t\topen();\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{ __( 'Attach images' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t/>\n\t\t</MediaUploadCheck>\n\t);\n}\n\nexport function MediaCategoryPanel( { rootClientId, onInsert, category } ) {\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\tper_page: !! debouncedSearch ? 20 : INITIAL_MEDIA_ITEMS_PER_PAGE,\n\t\t\tsearch: debouncedSearch,\n\t\t} ),\n\t\t[ debouncedSearch ]\n\t);\n\tconst [ refreshKey, setRefreshKey ] = useState( 0 );\n\tconst { mediaList, isLoading } = useMediaResults(\n\t\tcategory,\n\t\tquery,\n\t\trefreshKey\n\t);\n\tconst { createErrorNotice, createSuccessNotice, createWarningNotice } =\n\t\tuseDispatch( noticesStore );\n\t// Dim (rather than blank) the populated grid while a refetch is in flight,\n\t// but only once it has run long enough to be worth signalling — quick\n\t// attach/detach refetches resolve before this and show nothing.\n\tconst showRefreshing = useDelayedLoading( isLoading );\n\n\t// Invalidate the cached results and force `useMediaResults` to refetch so\n\t// the grid reflects images that were just attached or detached.\n\tconst refresh = useCallback( () => {\n\t\tcategory.invalidate?.( query );\n\t\tsetRefreshKey( ( key ) => key + 1 );\n\t}, [ category, query ] );\n\n\tconst handleAttach = useCallback(\n\t\tasync ( selectedMedia ) => {\n\t\t\ttry {\n\t\t\t\tconst attachedCount = await category.attach( selectedMedia );\n\n\t\t\t\tif ( ! attachedCount ) {\n\t\t\t\t\t// This source only attaches images (the picker's \"Upload\n\t\t\t\t\t// files\" tab otherwise accepts any file type), so a selection\n\t\t\t\t\t// with no images attaches nothing.\n\t\t\t\t\tcreateWarningNotice( __( 'No images were attached.' ), {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t\tid: 'inserter-notice',\n\t\t\t\t\t} );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\trefresh();\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tcategory.postTypeLabel\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: %1$d: Number of images attached. %2$s: Name of the post type e.g: \"Page\". */\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'%1$d image attached to %2$s.',\n\t\t\t\t\t\t\t\t\t'%1$d images attached to %2$s.',\n\t\t\t\t\t\t\t\t\tattachedCount\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tattachedCount,\n\t\t\t\t\t\t\t\tcategory.postTypeLabel\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: %d: Number of images attached to the post. */\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'%d image attached to post.',\n\t\t\t\t\t\t\t\t\t'%d images attached to post.',\n\t\t\t\t\t\t\t\t\tattachedCount\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tattachedCount\n\t\t\t\t\t\t ),\n\t\t\t\t\t{ type: 'snackbar', id: 'inserter-notice' }\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\tcreateErrorNotice( __( 'Could not attach images.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'inserter-notice',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tcategory,\n\t\t\trefresh,\n\t\t\tcreateErrorNotice,\n\t\t\tcreateSuccessNotice,\n\t\t\tcreateWarningNotice,\n\t\t]\n\t);\n\n\tconst handleDetach = useCallback(\n\t\tasync ( media ) => {\n\t\t\ttry {\n\t\t\t\tawait category.detach( media );\n\t\t\t\trefresh();\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tcategory.postTypeLabel\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: Name of the post type e.g: \"Page\". */\n\t\t\t\t\t\t\t\t__( 'Image detached from %s.' ),\n\t\t\t\t\t\t\t\tcategory.postTypeLabel\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: __( 'Image detached from post.' ),\n\t\t\t\t\t{ type: 'snackbar', id: 'inserter-notice' }\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\tcreateErrorNotice( __( 'Could not detach image.' ), {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'inserter-notice',\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ category, refresh, createErrorNotice, createSuccessNotice ]\n\t);\n\n\t// Detaching is confirmed first: the dropdown sets the pending item, which\n\t// opens a modal, and only `confirmDetach` performs the detach.\n\tconst [ mediaPendingDetach, setMediaPendingDetach ] = useState();\n\tconst confirmDetach = useCallback( () => {\n\t\tconst media = mediaPendingDetach;\n\t\tsetMediaPendingDetach( undefined );\n\t\thandleDetach( media );\n\t}, [ handleDetach, mediaPendingDetach ] );\n\n\tconst baseCssClass = 'block-editor-inserter__media-panel';\n\tconst searchLabel = category.labels.search_items || __( 'Search' );\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( baseCssClass, {\n\t\t\t\t// The attach footer supplies the breathing room beneath the\n\t\t\t\t// grid, so the list drops its own bottom padding (see styles).\n\t\t\t\t'has-attach-footer': !! category.attach,\n\t\t\t} ) }\n\t\t>\n\t\t\t<SearchControl\n\t\t\t\tclassName={ `${ baseCssClass }-search` }\n\t\t\t\tonChange={ setSearch }\n\t\t\t\tvalue={ search }\n\t\t\t\tlabel={ searchLabel }\n\t\t\t\tplaceholder={ searchLabel }\n\t\t\t/>\n\t\t\t{ isLoading && ! mediaList?.length && (\n\t\t\t\t<div className={ `${ baseCssClass }-spinner` }>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! isLoading && ! mediaList?.length && (\n\t\t\t\t<InserterNoResults>\n\t\t\t\t\t{ category.emptyMessage && ! debouncedSearch\n\t\t\t\t\t\t? // For a source with a custom empty message (e.g.\n\t\t\t\t\t\t // Attachments) and no active search, an empty result\n\t\t\t\t\t\t // means nothing is attached yet — clearer than the\n\t\t\t\t\t\t // generic \"no results found\".\n\t\t\t\t\t\t category.emptyMessage\n\t\t\t\t\t\t: __( 'No results found.' ) }\n\t\t\t\t</InserterNoResults>\n\t\t\t) }\n\t\t\t{ !! mediaList?.length && (\n\t\t\t\t// Keep the existing items visible while a refetch is in flight,\n\t\t\t\t// dimming (and gently pulsing) them rather than clearing the grid,\n\t\t\t\t// so it doesn't flicker or pop.\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( `${ baseCssClass }-results`, {\n\t\t\t\t\t\t'is-loading': showRefreshing,\n\t\t\t\t\t} ) }\n\t\t\t\t\taria-busy={ showRefreshing }\n\t\t\t\t>\n\t\t\t\t\t<MediaList\n\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\tonClick={ onInsert }\n\t\t\t\t\t\tonDetach={\n\t\t\t\t\t\t\tcategory.detach ? setMediaPendingDetach : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmediaList={ mediaList }\n\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ category.attach && (\n\t\t\t\t// Pinned to the bottom of the panel as a fixed footer so it lines\n\t\t\t\t// up with the \"Open Media Library\" button in the adjacent column.\n\t\t\t\t<AttachImagesButton onSelect={ handleAttach } />\n\t\t\t) }\n\t\t\t{ mediaPendingDetach && (\n\t\t\t\t// A plain `Modal` (not `ConfirmDialog`) so we can pass\n\t\t\t\t// `overlayClassName` and stack it above the options dropdown that\n\t\t\t\t// opened it (see the z-index entry in `_z-index.scss`).\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Detach image' ) }\n\t\t\t\t\tonRequestClose={ () => setMediaPendingDetach( undefined ) }\n\t\t\t\t\toverlayClassName={ `${ baseCssClass }-detach-modal` }\n\t\t\t\t>\n\t\t\t\t\t<p>\n\t\t\t\t\t\t{ category.postTypeLabel\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t/* translators: %s: Name of the post type e.g: \"Page\". */\n\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t'Detach this image from the current %s? The image will remain in the Media Library.'\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\tcategory.postTypeLabel\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'Detach this image from the current post? The image will remain in the Media Library.'\n\t\t\t\t\t\t\t ) }\n\t\t\t\t\t</p>\n\t\t\t\t\t<div className={ `${ baseCssClass }-detach-actions` }>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => setMediaPendingDetach( undefined ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tonClick={ confirmDetach }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Detach' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</div>\n\t\t\t\t</Modal>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,QAAQ,OAAO,SAAS,qBAAqB;AACtD,SAAS,IAAI,IAAI,eAAe;AAChC,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,SAAS,oBAAoB;AAKtC,OAAO,eAAe;AACtB,OAAO,iBAAiB;AACxB,OAAO,sBAAsB;AAC7B,SAAS,iBAA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AA,kCAAC,OACE,mBAAS,gBACR;AAAA;AAAA,gBAEA;AAAA,kBACC;AAAA,gBACD;AAAA,gBACA,SAAS;AAAA,cACT,IACA;AAAA,gBACA;AAAA,cACA,GACJ;AAAA,cACA,qBAAC,SAAI,WAAY,GAAI,YAAa,mBACjC;AAAA;AAAA,kBAAC;AAAA;AAAA,oBACA,uBAAqB;AAAA,oBACrB,SAAQ;AAAA,oBACR,SAAU,MAAM,sBAAuB,MAAU;AAAA,oBAE/C,aAAI,QAAS;AAAA;AAAA,gBAChB;AAAA,gBACA;AAAA,kBAAC;AAAA;AAAA,oBACA,uBAAqB;AAAA,oBACrB,SAAQ;AAAA,oBACR,SAAU;AAAA,oBAER,aAAI,QAAS;AAAA;AAAA,gBAChB;AAAA,iBACD;AAAA;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF;AAEF;",
6
6
  "names": []
7
7
  }
@@ -15,7 +15,7 @@ import {
15
15
  import { __, sprintf } from "@wordpress/i18n";
16
16
  import { useMemo, useCallback, useState } from "@wordpress/element";
17
17
  import { cloneBlock } from "@wordpress/blocks";
18
- import { moreVertical, external } from "@wordpress/icons";
18
+ import { moreVertical, external, linkOff } from "@wordpress/icons";
19
19
  import { useSelect, useDispatch } from "@wordpress/data";
20
20
  import { store as noticesStore } from "@wordpress/notices";
21
21
  import { isBlobURL } from "@wordpress/blob";
@@ -30,11 +30,11 @@ var MEDIA_OPTIONS_POPOVER_PROPS = {
30
30
  placement: "bottom-end",
31
31
  className: "block-editor-inserter__media-list__item-preview-options__popover"
32
32
  };
33
- function MediaPreviewOptions({ category, media }) {
34
- if (!category.getReportUrl) {
33
+ function MediaPreviewOptions({ category, media, onDetach }) {
34
+ if (!category.getReportUrl && !onDetach) {
35
35
  return null;
36
36
  }
37
- const reportUrl = category.getReportUrl(media);
37
+ const reportUrl = category.getReportUrl?.(media);
38
38
  return /* @__PURE__ */ jsx(
39
39
  DropdownMenu,
40
40
  {
@@ -42,18 +42,32 @@ function MediaPreviewOptions({ category, media }) {
42
42
  label: __("Options"),
43
43
  popoverProps: MEDIA_OPTIONS_POPOVER_PROPS,
44
44
  icon: moreVertical,
45
- children: () => /* @__PURE__ */ jsx(MenuGroup, { children: /* @__PURE__ */ jsx(
46
- MenuItem,
47
- {
48
- onClick: () => window.open(reportUrl, "_blank").focus(),
49
- icon: external,
50
- children: sprintf(
51
- /* translators: %s: The media type to report e.g: "image", "video", "audio" */
52
- __("Report %s"),
53
- category.mediaType
54
- )
55
- }
56
- ) })
45
+ children: () => /* @__PURE__ */ jsxs(MenuGroup, { children: [
46
+ reportUrl && /* @__PURE__ */ jsx(
47
+ MenuItem,
48
+ {
49
+ onClick: () => window.open(reportUrl, "_blank").focus(),
50
+ icon: external,
51
+ children: sprintf(
52
+ /* translators: %s: The media type to report e.g: "image", "video", "audio" */
53
+ __("Report %s"),
54
+ category.mediaType
55
+ )
56
+ }
57
+ ),
58
+ onDetach && /* @__PURE__ */ jsx(
59
+ MenuItem,
60
+ {
61
+ onClick: () => onDetach(media),
62
+ icon: linkOff,
63
+ children: category.postTypeLabel ? sprintf(
64
+ /* translators: %s: Name of the post type e.g: "Page". */
65
+ __("Detach from %s"),
66
+ category.postTypeLabel
67
+ ) : __("Detach from post")
68
+ }
69
+ )
70
+ ] })
57
71
  }
58
72
  );
59
73
  }
@@ -105,7 +119,7 @@ function InsertExternalImageModal({ onClose, onSubmit }) {
105
119
  }
106
120
  );
107
121
  }
108
- function MediaPreview({ media, onClick, category }) {
122
+ function MediaPreview({ media, onClick, onDetach, category }) {
109
123
  const [showExternalUploadModal, setShowExternalUploadModal] = useState(false);
110
124
  const [isHovered, setIsHovered] = useState(false);
111
125
  const [isInserting, setIsInserting] = useState(false);
@@ -243,7 +257,8 @@ function MediaPreview({ media, onClick, category }) {
243
257
  MediaPreviewOptions,
244
258
  {
245
259
  category,
246
- media
260
+ media,
261
+ onDetach
247
262
  }
248
263
  )
249
264
  ]