@wordpress/block-editor 15.19.1-next.v.202605131032.0 → 15.20.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 (352) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/build/components/block-card/index.cjs +51 -41
  3. package/build/components/block-card/index.cjs.map +3 -3
  4. package/build/components/block-heading-level-dropdown/heading-level-icon.cjs.map +3 -3
  5. package/build/components/block-icon/index.cjs +7 -1
  6. package/build/components/block-icon/index.cjs.map +3 -3
  7. package/build/components/block-inspector/index.cjs +156 -11
  8. package/build/components/block-inspector/index.cjs.map +3 -3
  9. package/build/components/block-inspector/inspector-pre-tabs-slot-fill.cjs +38 -0
  10. package/build/components/block-inspector/inspector-pre-tabs-slot-fill.cjs.map +7 -0
  11. package/build/components/block-list/use-block-props/index.cjs +1 -1
  12. package/build/components/block-list/use-block-props/index.cjs.map +2 -2
  13. package/build/components/block-list/use-block-props/use-focus-handler.cjs +3 -4
  14. package/build/components/block-list/use-block-props/use-focus-handler.cjs.map +3 -3
  15. package/build/components/block-list/use-block-props/use-is-hovered.cjs +24 -14
  16. package/build/components/block-list/use-block-props/use-is-hovered.cjs.map +3 -3
  17. package/build/components/block-lock/modal.cjs.map +3 -3
  18. package/build/components/block-patterns-list/index.cjs +13 -2
  19. package/build/components/block-patterns-list/index.cjs.map +2 -2
  20. package/build/components/block-popover/index.cjs +13 -3
  21. package/build/components/block-popover/index.cjs.map +2 -2
  22. package/build/components/block-toolbar/switch-section-style.cjs.map +3 -3
  23. package/build/components/block-visibility/modal.cjs.map +3 -3
  24. package/build/components/block-visibility/viewport-visibility-info.cjs.map +3 -3
  25. package/build/components/colors-gradients/control.cjs +7 -4
  26. package/build/components/colors-gradients/control.cjs.map +2 -2
  27. package/build/components/global-styles/advanced-panel.cjs +24 -22
  28. package/build/components/global-styles/advanced-panel.cjs.map +3 -3
  29. package/build/components/global-styles/color-panel.cjs +95 -58
  30. package/build/components/global-styles/color-panel.cjs.map +2 -2
  31. package/build/components/global-styles/dimensions-panel.cjs +11 -5
  32. package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
  33. package/build/components/global-styles/index.cjs +3 -0
  34. package/build/components/global-styles/index.cjs.map +2 -2
  35. package/build/components/global-styles/shadow-panel-components.cjs +38 -26
  36. package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
  37. package/build/components/global-styles/state-control-badges.cjs +69 -0
  38. package/build/components/global-styles/state-control-badges.cjs.map +7 -0
  39. package/build/components/global-styles/state-control.cjs +54 -63
  40. package/build/components/global-styles/state-control.cjs.map +3 -3
  41. package/build/components/iframe/index.cjs +0 -3
  42. package/build/components/iframe/index.cjs.map +2 -2
  43. package/build/components/iframe/use-scale-canvas.cjs +4 -1
  44. package/build/components/iframe/use-scale-canvas.cjs.map +2 -2
  45. package/build/components/inserter/hooks/use-patterns-state.cjs +4 -6
  46. package/build/components/inserter/hooks/use-patterns-state.cjs.map +2 -2
  47. package/build/components/inserter/index.cjs +1 -0
  48. package/build/components/inserter/index.cjs.map +2 -2
  49. package/build/components/inserter/media-tab/media-preview.cjs +27 -18
  50. package/build/components/inserter/media-tab/media-preview.cjs.map +2 -2
  51. package/build/components/inserter/media-tab/utils.cjs +1 -1
  52. package/build/components/inserter/media-tab/utils.cjs.map +2 -2
  53. package/build/components/inserter/panel.cjs.map +3 -3
  54. package/build/components/inspector-controls/block-support-tools-panel.cjs +10 -2
  55. package/build/components/inspector-controls/block-support-tools-panel.cjs.map +2 -2
  56. package/build/components/inspector-controls/fill.cjs +14 -4
  57. package/build/components/inspector-controls/fill.cjs.map +2 -2
  58. package/build/components/inspector-controls/groups.cjs +2 -0
  59. package/build/components/inspector-controls/groups.cjs.map +2 -2
  60. package/build/components/inspector-controls-tabs/index.cjs +13 -8
  61. package/build/components/inspector-controls-tabs/index.cjs.map +3 -3
  62. package/build/components/inspector-controls-tabs/settings-tab.cjs +1 -4
  63. package/build/components/inspector-controls-tabs/settings-tab.cjs.map +3 -3
  64. package/build/components/inspector-controls-tabs/styles-tab.cjs +9 -0
  65. package/build/components/inspector-controls-tabs/styles-tab.cjs.map +3 -3
  66. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs +11 -5
  67. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.cjs.map +2 -2
  68. package/build/components/list-view/block-select-button.cjs +20 -8
  69. package/build/components/list-view/block-select-button.cjs.map +2 -2
  70. package/build/components/list-view/block.cjs +2 -1
  71. package/build/components/list-view/block.cjs.map +2 -2
  72. package/build/components/preset-input-control/custom-value-controls.cjs +10 -1
  73. package/build/components/preset-input-control/custom-value-controls.cjs.map +2 -2
  74. package/build/components/preset-input-control/index.cjs.map +3 -3
  75. package/build/components/provider/use-media-upload-settings.cjs +1 -0
  76. package/build/components/provider/use-media-upload-settings.cjs.map +2 -2
  77. package/build/components/rich-text/event-listeners/enter.cjs +9 -2
  78. package/build/components/rich-text/event-listeners/enter.cjs.map +3 -3
  79. package/build/components/rich-text/event-listeners/paste-handler.cjs +4 -4
  80. package/build/components/rich-text/event-listeners/paste-handler.cjs.map +3 -3
  81. package/build/hooks/background.cjs +13 -3
  82. package/build/hooks/background.cjs.map +2 -2
  83. package/build/hooks/block-fields/link/index.cjs.map +3 -3
  84. package/build/hooks/block-fields/media/index.cjs.map +3 -3
  85. package/build/hooks/block-style-state.cjs +112 -0
  86. package/build/hooks/block-style-state.cjs.map +7 -0
  87. package/build/hooks/border.cjs +13 -3
  88. package/build/hooks/border.cjs.map +2 -2
  89. package/build/hooks/color.cjs +28 -9
  90. package/build/hooks/color.cjs.map +2 -2
  91. package/build/hooks/dimensions.cjs +15 -6
  92. package/build/hooks/dimensions.cjs.map +2 -2
  93. package/build/hooks/layout-child.cjs +147 -61
  94. package/build/hooks/layout-child.cjs.map +2 -2
  95. package/build/hooks/layout.cjs +263 -56
  96. package/build/hooks/layout.cjs.map +3 -3
  97. package/build/hooks/state-utils.cjs +94 -0
  98. package/build/hooks/state-utils.cjs.map +7 -0
  99. package/build/hooks/states.cjs +124 -0
  100. package/build/hooks/states.cjs.map +7 -0
  101. package/build/hooks/style.cjs +304 -17
  102. package/build/hooks/style.cjs.map +3 -3
  103. package/build/hooks/typography.cjs +14 -5
  104. package/build/hooks/typography.cjs.map +2 -2
  105. package/build/layouts/constrained.cjs +128 -55
  106. package/build/layouts/constrained.cjs.map +3 -3
  107. package/build/layouts/flex.cjs +119 -31
  108. package/build/layouts/flex.cjs.map +3 -3
  109. package/build/layouts/grid.cjs +103 -40
  110. package/build/layouts/grid.cjs.map +3 -3
  111. package/build/private-apis.cjs +2 -0
  112. package/build/private-apis.cjs.map +2 -2
  113. package/build/store/private-actions.cjs +18 -0
  114. package/build/store/private-actions.cjs.map +2 -2
  115. package/build/store/private-keys.cjs +10 -2
  116. package/build/store/private-keys.cjs.map +2 -2
  117. package/build/store/private-selectors.cjs +26 -2
  118. package/build/store/private-selectors.cjs.map +2 -2
  119. package/build/store/reducer.cjs +70 -1
  120. package/build/store/reducer.cjs.map +2 -2
  121. package/build/store/utils.cjs +1 -1
  122. package/build/store/utils.cjs.map +2 -2
  123. package/build/utils/color-values.cjs +44 -0
  124. package/build/utils/color-values.cjs.map +7 -0
  125. package/build-module/components/block-card/index.mjs +52 -45
  126. package/build-module/components/block-card/index.mjs.map +2 -2
  127. package/build-module/components/block-heading-level-dropdown/heading-level-icon.mjs +2 -2
  128. package/build-module/components/block-heading-level-dropdown/heading-level-icon.mjs.map +2 -2
  129. package/build-module/components/block-icon/index.mjs +8 -2
  130. package/build-module/components/block-icon/index.mjs.map +2 -2
  131. package/build-module/components/block-inspector/index.mjs +166 -13
  132. package/build-module/components/block-inspector/index.mjs.map +2 -2
  133. package/build-module/components/block-inspector/inspector-pre-tabs-slot-fill.mjs +12 -0
  134. package/build-module/components/block-inspector/inspector-pre-tabs-slot-fill.mjs.map +7 -0
  135. package/build-module/components/block-list/use-block-props/index.mjs +1 -1
  136. package/build-module/components/block-list/use-block-props/index.mjs.map +2 -2
  137. package/build-module/components/block-list/use-block-props/use-focus-handler.mjs +7 -5
  138. package/build-module/components/block-list/use-block-props/use-focus-handler.mjs.map +2 -2
  139. package/build-module/components/block-list/use-block-props/use-is-hovered.mjs +28 -15
  140. package/build-module/components/block-list/use-block-props/use-is-hovered.mjs.map +2 -2
  141. package/build-module/components/block-lock/modal.mjs +4 -4
  142. package/build-module/components/block-lock/modal.mjs.map +2 -2
  143. package/build-module/components/block-patterns-list/index.mjs +14 -4
  144. package/build-module/components/block-patterns-list/index.mjs.map +2 -2
  145. package/build-module/components/block-popover/index.mjs +13 -3
  146. package/build-module/components/block-popover/index.mjs.map +2 -2
  147. package/build-module/components/block-toolbar/switch-section-style.mjs +2 -2
  148. package/build-module/components/block-toolbar/switch-section-style.mjs.map +2 -2
  149. package/build-module/components/block-visibility/modal.mjs +2 -2
  150. package/build-module/components/block-visibility/modal.mjs.map +2 -2
  151. package/build-module/components/block-visibility/viewport-visibility-info.mjs +2 -2
  152. package/build-module/components/block-visibility/viewport-visibility-info.mjs.map +2 -2
  153. package/build-module/components/colors-gradients/control.mjs +7 -4
  154. package/build-module/components/colors-gradients/control.mjs.map +2 -2
  155. package/build-module/components/global-styles/advanced-panel.mjs +25 -27
  156. package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
  157. package/build-module/components/global-styles/color-panel.mjs +96 -59
  158. package/build-module/components/global-styles/color-panel.mjs.map +2 -2
  159. package/build-module/components/global-styles/dimensions-panel.mjs +14 -5
  160. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  161. package/build-module/components/global-styles/index.mjs +2 -0
  162. package/build-module/components/global-styles/index.mjs.map +2 -2
  163. package/build-module/components/global-styles/shadow-panel-components.mjs +39 -28
  164. package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
  165. package/build-module/components/global-styles/state-control-badges.mjs +48 -0
  166. package/build-module/components/global-styles/state-control-badges.mjs.map +7 -0
  167. package/build-module/components/global-styles/state-control.mjs +57 -71
  168. package/build-module/components/global-styles/state-control.mjs.map +2 -2
  169. package/build-module/components/iframe/index.mjs +0 -3
  170. package/build-module/components/iframe/index.mjs.map +2 -2
  171. package/build-module/components/iframe/use-scale-canvas.mjs +4 -1
  172. package/build-module/components/iframe/use-scale-canvas.mjs.map +2 -2
  173. package/build-module/components/inserter/hooks/use-patterns-state.mjs +8 -7
  174. package/build-module/components/inserter/hooks/use-patterns-state.mjs.map +2 -2
  175. package/build-module/components/inserter/index.mjs +1 -0
  176. package/build-module/components/inserter/index.mjs.map +2 -2
  177. package/build-module/components/inserter/media-tab/media-preview.mjs +27 -19
  178. package/build-module/components/inserter/media-tab/media-preview.mjs.map +2 -2
  179. package/build-module/components/inserter/media-tab/utils.mjs +1 -1
  180. package/build-module/components/inserter/media-tab/utils.mjs.map +2 -2
  181. package/build-module/components/inserter/panel.mjs +2 -2
  182. package/build-module/components/inserter/panel.mjs.map +2 -2
  183. package/build-module/components/inspector-controls/block-support-tools-panel.mjs +10 -2
  184. package/build-module/components/inspector-controls/block-support-tools-panel.mjs.map +2 -2
  185. package/build-module/components/inspector-controls/fill.mjs +18 -5
  186. package/build-module/components/inspector-controls/fill.mjs.map +2 -2
  187. package/build-module/components/inspector-controls/groups.mjs +2 -0
  188. package/build-module/components/inspector-controls/groups.mjs.map +2 -2
  189. package/build-module/components/inspector-controls-tabs/index.mjs +14 -10
  190. package/build-module/components/inspector-controls-tabs/index.mjs.map +2 -2
  191. package/build-module/components/inspector-controls-tabs/settings-tab.mjs +1 -4
  192. package/build-module/components/inspector-controls-tabs/settings-tab.mjs.map +2 -2
  193. package/build-module/components/inspector-controls-tabs/styles-tab.mjs +9 -0
  194. package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
  195. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs +11 -5
  196. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.mjs.map +2 -2
  197. package/build-module/components/list-view/block-select-button.mjs +20 -9
  198. package/build-module/components/list-view/block-select-button.mjs.map +2 -2
  199. package/build-module/components/list-view/block.mjs +2 -1
  200. package/build-module/components/list-view/block.mjs.map +2 -2
  201. package/build-module/components/preset-input-control/custom-value-controls.mjs +10 -2
  202. package/build-module/components/preset-input-control/custom-value-controls.mjs.map +2 -2
  203. package/build-module/components/preset-input-control/index.mjs +2 -2
  204. package/build-module/components/preset-input-control/index.mjs.map +2 -2
  205. package/build-module/components/provider/use-media-upload-settings.mjs +1 -0
  206. package/build-module/components/provider/use-media-upload-settings.mjs.map +2 -2
  207. package/build-module/components/rich-text/event-listeners/enter.mjs +9 -2
  208. package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
  209. package/build-module/components/rich-text/event-listeners/paste-handler.mjs +4 -4
  210. package/build-module/components/rich-text/event-listeners/paste-handler.mjs.map +2 -2
  211. package/build-module/hooks/background.mjs +18 -3
  212. package/build-module/hooks/background.mjs.map +2 -2
  213. package/build-module/hooks/block-fields/link/index.mjs +3 -3
  214. package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
  215. package/build-module/hooks/block-fields/media/index.mjs +3 -3
  216. package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
  217. package/build-module/hooks/block-style-state.mjs +79 -0
  218. package/build-module/hooks/block-style-state.mjs.map +7 -0
  219. package/build-module/hooks/border.mjs +18 -3
  220. package/build-module/hooks/border.mjs.map +2 -2
  221. package/build-module/hooks/color.mjs +33 -9
  222. package/build-module/hooks/color.mjs.map +2 -2
  223. package/build-module/hooks/dimensions.mjs +20 -6
  224. package/build-module/hooks/dimensions.mjs.map +2 -2
  225. package/build-module/hooks/layout-child.mjs +141 -61
  226. package/build-module/hooks/layout-child.mjs.map +2 -2
  227. package/build-module/hooks/layout.mjs +270 -58
  228. package/build-module/hooks/layout.mjs.map +2 -2
  229. package/build-module/hooks/state-utils.mjs +64 -0
  230. package/build-module/hooks/state-utils.mjs.map +7 -0
  231. package/build-module/hooks/states.mjs +85 -0
  232. package/build-module/hooks/states.mjs.map +7 -0
  233. package/build-module/hooks/style.mjs +309 -18
  234. package/build-module/hooks/style.mjs.map +2 -2
  235. package/build-module/hooks/typography.mjs +19 -5
  236. package/build-module/hooks/typography.mjs.map +2 -2
  237. package/build-module/layouts/constrained.mjs +130 -57
  238. package/build-module/layouts/constrained.mjs.map +2 -2
  239. package/build-module/layouts/flex.mjs +123 -35
  240. package/build-module/layouts/flex.mjs.map +2 -2
  241. package/build-module/layouts/grid.mjs +105 -42
  242. package/build-module/layouts/grid.mjs.map +2 -2
  243. package/build-module/private-apis.mjs +4 -0
  244. package/build-module/private-apis.mjs.map +2 -2
  245. package/build-module/store/private-actions.mjs +16 -0
  246. package/build-module/store/private-actions.mjs.map +2 -2
  247. package/build-module/store/private-keys.mjs +7 -1
  248. package/build-module/store/private-keys.mjs.map +2 -2
  249. package/build-module/store/private-selectors.mjs +25 -2
  250. package/build-module/store/private-selectors.mjs.map +2 -2
  251. package/build-module/store/reducer.mjs +69 -1
  252. package/build-module/store/reducer.mjs.map +2 -2
  253. package/build-module/store/utils.mjs +5 -2
  254. package/build-module/store/utils.mjs.map +2 -2
  255. package/build-module/utils/color-values.mjs +19 -0
  256. package/build-module/utils/color-values.mjs.map +7 -0
  257. package/build-style/content-rtl.css +18 -3
  258. package/build-style/content.css +18 -3
  259. package/build-style/style-rtl.css +14 -17
  260. package/build-style/style.css +14 -17
  261. package/package.json +41 -41
  262. package/src/components/audio-player/index.native.js +7 -3
  263. package/src/components/block-card/index.js +67 -60
  264. package/src/components/block-heading-level-dropdown/heading-level-icon.js +2 -2
  265. package/src/components/block-icon/index.js +5 -2
  266. package/src/components/block-icon/index.native.js +2 -2
  267. package/src/components/block-inspector/index.js +153 -7
  268. package/src/components/block-inspector/inspector-pre-tabs-slot-fill.js +11 -0
  269. package/src/components/block-list/block-selection-button.native.js +3 -3
  270. package/src/components/block-list/content.scss +0 -6
  271. package/src/components/block-list/use-block-props/index.js +1 -1
  272. package/src/components/block-list/use-block-props/use-focus-handler.js +8 -6
  273. package/src/components/block-list/use-block-props/use-is-hovered.js +32 -15
  274. package/src/components/block-lock/modal.js +4 -4
  275. package/src/components/block-patterns-list/index.js +14 -5
  276. package/src/components/block-patterns-list/stories/index.story.jsx +2 -0
  277. package/src/components/block-patterns-list/style.scss +0 -1
  278. package/src/components/block-popover/index.js +20 -10
  279. package/src/components/block-toolbar/switch-section-style.js +2 -2
  280. package/src/components/block-visibility/modal.js +2 -2
  281. package/src/components/block-visibility/viewport-visibility-info.js +2 -2
  282. package/src/components/colors/test/with-colors.js +1 -1
  283. package/src/components/colors-gradients/control.js +10 -8
  284. package/src/components/colors-gradients/test/control.js +98 -1
  285. package/src/components/global-styles/advanced-panel.js +44 -39
  286. package/src/components/global-styles/color-panel.js +133 -60
  287. package/src/components/global-styles/dimensions-panel.js +17 -4
  288. package/src/components/global-styles/index.js +1 -0
  289. package/src/components/global-styles/shadow-panel-components.js +29 -19
  290. package/src/components/global-styles/state-control-badges.js +58 -0
  291. package/src/components/global-styles/state-control.js +28 -36
  292. package/src/components/global-styles/test/color-panel.js +135 -0
  293. package/src/components/iframe/index.js +0 -3
  294. package/src/components/iframe/use-scale-canvas.js +8 -2
  295. package/src/components/inserter/hooks/use-patterns-state.js +12 -7
  296. package/src/components/inserter/index.js +1 -0
  297. package/src/components/inserter/media-tab/media-preview.js +29 -20
  298. package/src/components/inserter/media-tab/utils.js +1 -1
  299. package/src/components/inserter/panel.js +2 -2
  300. package/src/components/inserter/style.scss +1 -0
  301. package/src/components/inserter-button/index.native.js +5 -2
  302. package/src/components/inspector-controls/block-support-tools-panel.js +10 -2
  303. package/src/components/inspector-controls/fill.js +18 -5
  304. package/src/components/inspector-controls/groups.js +2 -0
  305. package/src/components/inspector-controls-tabs/index.js +9 -5
  306. package/src/components/inspector-controls-tabs/settings-tab.js +1 -7
  307. package/src/components/inspector-controls-tabs/styles-tab.js +6 -0
  308. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +13 -7
  309. package/src/components/list-view/block-select-button.js +19 -9
  310. package/src/components/list-view/block.js +6 -1
  311. package/src/components/media-replace-flow/style.scss +0 -18
  312. package/src/components/preset-input-control/custom-value-controls.js +13 -6
  313. package/src/components/preset-input-control/index.js +2 -2
  314. package/src/components/provider/use-media-upload-settings.js +1 -0
  315. package/src/components/rich-text/event-listeners/enter.js +14 -2
  316. package/src/components/rich-text/event-listeners/paste-handler.js +5 -4
  317. package/src/components/unsupported-block-details/index.native.js +6 -2
  318. package/src/components/video-player/index.native.js +2 -2
  319. package/src/components/warning/index.native.js +2 -2
  320. package/src/hooks/background.js +59 -37
  321. package/src/hooks/block-fields/link/index.js +3 -3
  322. package/src/hooks/block-fields/media/index.js +3 -3
  323. package/src/hooks/block-style-state.js +127 -0
  324. package/src/hooks/border.js +25 -6
  325. package/src/hooks/color.js +40 -18
  326. package/src/hooks/dimensions.js +32 -11
  327. package/src/hooks/layout-child.js +179 -62
  328. package/src/hooks/layout.js +349 -75
  329. package/src/hooks/layout.scss +6 -0
  330. package/src/hooks/state-utils.js +158 -0
  331. package/src/hooks/states.js +109 -0
  332. package/src/hooks/style.js +456 -19
  333. package/src/hooks/test/block-style-state.js +270 -0
  334. package/src/hooks/test/layout.js +185 -0
  335. package/src/hooks/test/state-utils.js +193 -0
  336. package/src/hooks/test/style.js +301 -1
  337. package/src/hooks/typography.js +33 -14
  338. package/src/layouts/constrained.js +182 -95
  339. package/src/layouts/flex.js +141 -36
  340. package/src/layouts/grid.js +122 -32
  341. package/src/layouts/test/flex.js +57 -20
  342. package/src/private-apis.js +4 -0
  343. package/src/store/private-actions.js +32 -0
  344. package/src/store/private-keys.js +4 -0
  345. package/src/store/private-selectors.js +44 -2
  346. package/src/store/reducer.js +105 -1
  347. package/src/store/test/private-actions.js +26 -0
  348. package/src/store/test/private-selectors.js +90 -0
  349. package/src/store/test/reducer.js +363 -0
  350. package/src/store/utils.js +6 -2
  351. package/src/utils/color-values.js +28 -0
  352. package/src/utils/test/color-values.js +78 -0
@@ -1,23 +1,18 @@
1
1
  // packages/block-editor/src/components/global-styles/state-control.js
2
- import { __ } from "@wordpress/i18n";
3
- import { check, chevronDown } from "@wordpress/icons";
4
- import {
5
- DropdownMenu,
6
- MenuGroup,
7
- MenuItem,
8
- privateApis as componentsPrivateApis
9
- } from "@wordpress/components";
2
+ import { __, sprintf } from "@wordpress/i18n";
3
+ import { check, chevronDown, moreVertical } from "@wordpress/icons";
4
+ import { DropdownMenu, MenuGroup, MenuItem } from "@wordpress/components";
10
5
  import { Stack } from "@wordpress/ui";
11
- import { unlock } from "../../lock-unlock.mjs";
12
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
13
- var { Badge: WCBadge } = unlock(componentsPrivateApis);
14
7
  function StateControl({
15
8
  viewportStates = [],
16
9
  pseudoStates = [],
17
10
  viewportValue = "default",
18
11
  pseudoStateValue = "default",
19
12
  onChangeViewport,
20
- onChangePseudoState
13
+ onChangePseudoState,
14
+ showText = true,
15
+ popoverProps = {}
21
16
  }) {
22
17
  if (!viewportStates.length && !pseudoStates.length) {
23
18
  return null;
@@ -62,74 +57,65 @@ function StateControl({
62
57
  });
63
58
  }
64
59
  }
65
- return /* @__PURE__ */ jsxs(
60
+ const currentStateLabel = activeStates.length ? activeStates.map((state) => state.label).join(", ") : __("Default");
61
+ const icon = showText ? chevronDown : moreVertical;
62
+ const toggleProps = showText ? { size: "compact", variant: "tertiary", iconPosition: "right" } : { size: "compact", variant: "tertiary" };
63
+ return /* @__PURE__ */ jsx(
66
64
  Stack,
67
65
  {
68
66
  direction: "column",
69
67
  gap: "sm",
70
68
  align: "flex-end",
71
69
  className: "block-editor-global-styles-state-control",
72
- children: [
73
- /* @__PURE__ */ jsx(
74
- DropdownMenu,
75
- {
76
- icon: chevronDown,
77
- label: triggerLabel,
78
- popoverProps: {
79
- placement: "right-start"
80
- },
81
- text: triggerLabel,
82
- toggleProps: {
83
- size: "compact",
84
- variant: "tertiary",
85
- iconPosition: "right"
86
- },
87
- children: ({ onClose }) => /* @__PURE__ */ jsxs(Fragment, { children: [
88
- hasViewportOptions && /* @__PURE__ */ jsx(MenuGroup, { label: __("Viewport"), children: viewportOptions.map((option) => /* @__PURE__ */ jsx(
89
- MenuItem,
90
- {
91
- onClick: () => {
92
- onChangeViewport?.(option.value);
93
- if (!hasPseudoStateOptions) {
94
- onClose();
95
- }
96
- },
97
- icon: viewportValue === option.value ? check : null,
98
- children: option.label
70
+ children: /* @__PURE__ */ jsx(
71
+ DropdownMenu,
72
+ {
73
+ icon,
74
+ label: showText ? triggerLabel : sprintf(
75
+ /* translators: %s: Current state (e.g. "Hover", "Focus") */
76
+ __("State: %s"),
77
+ currentStateLabel
78
+ ),
79
+ popoverProps: {
80
+ placement: "right-start",
81
+ ...popoverProps
82
+ },
83
+ text: showText ? triggerLabel : void 0,
84
+ toggleProps,
85
+ children: ({ onClose }) => /* @__PURE__ */ jsxs(Fragment, { children: [
86
+ hasViewportOptions && /* @__PURE__ */ jsx(MenuGroup, { label: __("Viewport"), children: viewportOptions.map((option) => /* @__PURE__ */ jsx(
87
+ MenuItem,
88
+ {
89
+ onClick: () => {
90
+ onChangeViewport?.(option.value);
91
+ if (!hasPseudoStateOptions) {
92
+ onClose();
93
+ }
99
94
  },
100
- `viewport-${option.value}`
101
- )) }),
102
- hasPseudoStateOptions && /* @__PURE__ */ jsx(MenuGroup, { label: __("Pseudo state"), children: pseudoStateOptions.map((option) => /* @__PURE__ */ jsx(
103
- MenuItem,
104
- {
105
- onClick: () => {
106
- onChangePseudoState?.(
107
- option.value
108
- );
109
- if (!hasViewportOptions) {
110
- onClose();
111
- }
112
- },
113
- icon: pseudoStateValue === option.value ? check : null,
114
- children: option.label
95
+ icon: viewportValue === option.value ? check : null,
96
+ children: option.label
97
+ },
98
+ `viewport-${option.value}`
99
+ )) }),
100
+ hasPseudoStateOptions && /* @__PURE__ */ jsx(MenuGroup, { label: __("Pseudo state"), children: pseudoStateOptions.map((option) => /* @__PURE__ */ jsx(
101
+ MenuItem,
102
+ {
103
+ onClick: () => {
104
+ onChangePseudoState?.(
105
+ option.value
106
+ );
107
+ if (!hasViewportOptions) {
108
+ onClose();
109
+ }
115
110
  },
116
- `pseudo-${option.value}`
117
- )) })
118
- ] })
119
- }
120
- ),
121
- /* @__PURE__ */ jsx(
122
- Stack,
123
- {
124
- className: "block-editor-global-styles-state-control__badges",
125
- direction: "row",
126
- justify: "flex-start",
127
- gap: "xs",
128
- wrap: "wrap",
129
- children: activeStates.map((activeState) => /* @__PURE__ */ jsx(WCBadge, { intent: "info", children: activeState.label }, activeState.key))
130
- }
131
- )
132
- ]
111
+ icon: pseudoStateValue === option.value ? check : null,
112
+ children: option.label
113
+ },
114
+ `pseudo-${option.value}`
115
+ )) })
116
+ ] })
117
+ }
118
+ )
133
119
  }
134
120
  );
135
121
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/global-styles/state-control.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { check, chevronDown } from '@wordpress/icons';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst { Badge: WCBadge } = unlock( componentsPrivateApis );\n\n/**\n * State control for managing viewport and pseudo-state styles.\n * Displays a dropdown menu with separate groups for each selector.\n *\n * @param {Object} props Component props.\n * @param {Array} props.viewportStates Array of available viewport states.\n * @param {Array} props.pseudoStates Array of available pseudo states.\n * @param {string} props.viewportValue Currently selected viewport value.\n * @param {string} props.pseudoStateValue Currently selected pseudo state value.\n * @param {Function} props.onChangeViewport Callback when viewport selection changes.\n * @param {Function} props.onChangePseudoState Callback when pseudo state selection changes.\n * @return {Element|null} State control component.\n */\nexport default function StateControl( {\n\tviewportStates = [],\n\tpseudoStates = [],\n\tviewportValue = 'default',\n\tpseudoStateValue = 'default',\n\tonChangeViewport,\n\tonChangePseudoState,\n} ) {\n\tif ( ! viewportStates.length && ! pseudoStates.length ) {\n\t\treturn null;\n\t}\n\n\tconst viewportOptions = [\n\t\t{ label: __( 'Default' ), value: 'default' },\n\t\t...viewportStates.map( ( state ) => ( {\n\t\t\tlabel: state.label,\n\t\t\tvalue: state.value,\n\t\t} ) ),\n\t];\n\tconst pseudoStateOptions = [\n\t\t{ label: __( 'Default' ), value: 'default' },\n\t\t...pseudoStates.map( ( state ) => ( {\n\t\t\tlabel: state.label,\n\t\t\tvalue: state.value,\n\t\t} ) ),\n\t];\n\n\tconst hasViewportOptions = viewportStates.length > 0;\n\tconst hasPseudoStateOptions = pseudoStates.length > 0;\n\tconst triggerLabel = __( 'States' );\n\tconst activeStates = [];\n\n\tif ( hasViewportOptions && viewportValue !== 'default' ) {\n\t\tconst selectedViewport = viewportOptions.find(\n\t\t\t( option ) => option.value === viewportValue\n\t\t);\n\n\t\tif ( selectedViewport ) {\n\t\t\tactiveStates.push( {\n\t\t\t\tkey: `viewport-${ selectedViewport.value }`,\n\t\t\t\tlabel: selectedViewport.label,\n\t\t\t} );\n\t\t}\n\t}\n\n\tif ( hasPseudoStateOptions && pseudoStateValue !== 'default' ) {\n\t\tconst selectedPseudoState = pseudoStateOptions.find(\n\t\t\t( option ) => option.value === pseudoStateValue\n\t\t);\n\n\t\tif ( selectedPseudoState ) {\n\t\t\tactiveStates.push( {\n\t\t\t\tkey: `pseudo-${ selectedPseudoState.value }`,\n\t\t\t\tlabel: selectedPseudoState.label,\n\t\t\t} );\n\t\t}\n\t}\n\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"sm\"\n\t\t\talign=\"flex-end\"\n\t\t\tclassName=\"block-editor-global-styles-state-control\"\n\t\t>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ chevronDown }\n\t\t\t\tlabel={ triggerLabel }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tplacement: 'right-start',\n\t\t\t\t} }\n\t\t\t\ttext={ triggerLabel }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tsize: 'compact',\n\t\t\t\t\tvariant: 'tertiary',\n\t\t\t\t\ticonPosition: 'right',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ hasViewportOptions && (\n\t\t\t\t\t\t\t<MenuGroup label={ __( 'Viewport' ) }>\n\t\t\t\t\t\t\t\t{ viewportOptions.map( ( option ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ `viewport-${ option.value }` }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonChangeViewport?.( option.value );\n\t\t\t\t\t\t\t\t\t\t\tif ( ! hasPseudoStateOptions ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\tviewportValue === option.value\n\t\t\t\t\t\t\t\t\t\t\t\t? check\n\t\t\t\t\t\t\t\t\t\t\t\t: null\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\t\t{ option.label }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ hasPseudoStateOptions && (\n\t\t\t\t\t\t\t<MenuGroup label={ __( 'Pseudo state' ) }>\n\t\t\t\t\t\t\t\t{ pseudoStateOptions.map( ( option ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ `pseudo-${ option.value }` }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonChangePseudoState?.(\n\t\t\t\t\t\t\t\t\t\t\t\toption.value\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tif ( ! hasViewportOptions ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\tpseudoStateValue === option.value\n\t\t\t\t\t\t\t\t\t\t\t\t? check\n\t\t\t\t\t\t\t\t\t\t\t\t: null\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\t\t{ option.label }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t<Stack\n\t\t\t\tclassName=\"block-editor-global-styles-state-control__badges\"\n\t\t\t\tdirection=\"row\"\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tgap=\"xs\"\n\t\t\t\twrap=\"wrap\"\n\t\t\t>\n\t\t\t\t{ activeStates.map( ( activeState ) => (\n\t\t\t\t\t<WCBadge key={ activeState.key } intent=\"info\">\n\t\t\t\t\t\t{ activeState.label }\n\t\t\t\t\t</WCBadge>\n\t\t\t\t) ) }\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,OAAO,mBAAmB;AACnC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,OACT;AACP,SAAS,aAAa;AAKtB,SAAS,cAAc;AAgGlB,mBAII,KAJJ;AA9FL,IAAM,EAAE,OAAO,QAAQ,IAAI,OAAQ,qBAAsB;AAe1C,SAAR,aAA+B;AAAA,EACrC,iBAAiB,CAAC;AAA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3B,CACC;AAAA;AAAA,QACH;AAAA;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { check, chevronDown, moreVertical } from '@wordpress/icons';\nimport { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * State control for managing viewport and pseudo-state styles.\n * Displays a dropdown menu with separate groups for each selector.\n *\n * @param {Object} props Component props.\n * @param {Array} props.viewportStates Array of available viewport states.\n * @param {Array} props.pseudoStates Array of available pseudo states.\n * @param {string} props.viewportValue Currently selected viewport value.\n * @param {string} props.pseudoStateValue Currently selected pseudo state value.\n * @param {Function} props.onChangeViewport Callback when viewport selection changes.\n * @param {Function} props.onChangePseudoState Callback when pseudo state selection changes.\n * @param {boolean} props.showText Whether to show text label on the toggle. Default true.\n * @param {Object} props.popoverProps Popover props for the dropdown menu.\n * @return {Element|null} State control component.\n */\nexport default function StateControl( {\n\tviewportStates = [],\n\tpseudoStates = [],\n\tviewportValue = 'default',\n\tpseudoStateValue = 'default',\n\tonChangeViewport,\n\tonChangePseudoState,\n\tshowText = true,\n\tpopoverProps = {},\n} ) {\n\tif ( ! viewportStates.length && ! pseudoStates.length ) {\n\t\treturn null;\n\t}\n\n\tconst viewportOptions = [\n\t\t{ label: __( 'Default' ), value: 'default' },\n\t\t...viewportStates.map( ( state ) => ( {\n\t\t\tlabel: state.label,\n\t\t\tvalue: state.value,\n\t\t} ) ),\n\t];\n\tconst pseudoStateOptions = [\n\t\t{ label: __( 'Default' ), value: 'default' },\n\t\t...pseudoStates.map( ( state ) => ( {\n\t\t\tlabel: state.label,\n\t\t\tvalue: state.value,\n\t\t} ) ),\n\t];\n\n\tconst hasViewportOptions = viewportStates.length > 0;\n\tconst hasPseudoStateOptions = pseudoStates.length > 0;\n\tconst triggerLabel = __( 'States' );\n\tconst activeStates = [];\n\n\tif ( hasViewportOptions && viewportValue !== 'default' ) {\n\t\tconst selectedViewport = viewportOptions.find(\n\t\t\t( option ) => option.value === viewportValue\n\t\t);\n\n\t\tif ( selectedViewport ) {\n\t\t\tactiveStates.push( {\n\t\t\t\tkey: `viewport-${ selectedViewport.value }`,\n\t\t\t\tlabel: selectedViewport.label,\n\t\t\t} );\n\t\t}\n\t}\n\n\tif ( hasPseudoStateOptions && pseudoStateValue !== 'default' ) {\n\t\tconst selectedPseudoState = pseudoStateOptions.find(\n\t\t\t( option ) => option.value === pseudoStateValue\n\t\t);\n\n\t\tif ( selectedPseudoState ) {\n\t\t\tactiveStates.push( {\n\t\t\t\tkey: `pseudo-${ selectedPseudoState.value }`,\n\t\t\t\tlabel: selectedPseudoState.label,\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst currentStateLabel = activeStates.length\n\t\t? activeStates.map( ( state ) => state.label ).join( ', ' )\n\t\t: __( 'Default' );\n\tconst icon = showText ? chevronDown : moreVertical;\n\tconst toggleProps = showText\n\t\t? { size: 'compact', variant: 'tertiary', iconPosition: 'right' }\n\t\t: { size: 'compact', variant: 'tertiary' };\n\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"sm\"\n\t\t\talign=\"flex-end\"\n\t\t\tclassName=\"block-editor-global-styles-state-control\"\n\t\t>\n\t\t\t<DropdownMenu\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={\n\t\t\t\t\tshowText\n\t\t\t\t\t\t? triggerLabel\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: Current state (e.g. \"Hover\", \"Focus\") */\n\t\t\t\t\t\t\t\t__( 'State: %s' ),\n\t\t\t\t\t\t\t\tcurrentStateLabel\n\t\t\t\t\t\t )\n\t\t\t\t}\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tplacement: 'right-start',\n\t\t\t\t\t...popoverProps,\n\t\t\t\t} }\n\t\t\t\ttext={ showText ? triggerLabel : undefined }\n\t\t\t\ttoggleProps={ toggleProps }\n\t\t\t>\n\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ hasViewportOptions && (\n\t\t\t\t\t\t\t<MenuGroup label={ __( 'Viewport' ) }>\n\t\t\t\t\t\t\t\t{ viewportOptions.map( ( option ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ `viewport-${ option.value }` }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonChangeViewport?.( option.value );\n\t\t\t\t\t\t\t\t\t\t\tif ( ! hasPseudoStateOptions ) {\n\t\t\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\tviewportValue === option.value\n\t\t\t\t\t\t\t\t\t\t\t\t? check\n\t\t\t\t\t\t\t\t\t\t\t\t: null\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\t\t{ option.label }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ hasPseudoStateOptions && (\n\t\t\t\t\t\t\t<MenuGroup label={ __( 'Pseudo state' ) }>\n\t\t\t\t\t\t\t\t{ pseudoStateOptions.map( ( option ) => (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\tkey={ `pseudo-${ option.value }` }\n\t\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\t\tonChangePseudoState?.(\n\t\t\t\t\t\t\t\t\t\t\t\toption.value\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tif ( ! hasViewportOptions ) {\n\t\t\t\t\t\t\t\t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AAA,UACjC;AAAA,UAEE,WAAE,EAAE,QAAQ,MACb,iCACG;AAAA,kCACD,oBAAC,aAAU,OAAQ,GAAI,UAAW,GAC/B,0BAAgB,IAAK,CAAE,WACxB;AAAA,cAAC;AAAA;AAAA,gBAEA,SAAU,MAAM;AACf,qCAAoB,OAAO,KAAM;AACjC,sBAAK,CAAE,uBAAwB;AAC9B,4BAAQ;AAAA,kBACT;AAAA,gBACD;AAAA,gBACA,MACC,kBAAkB,OAAO,QACtB,QACA;AAAA,gBAGF,iBAAO;AAAA;AAAA,cAbH,YAAa,OAAO,KAAM;AAAA,YAcjC,CACC,GACH;AAAA,YAEC,yBACD,oBAAC,aAAU,OAAQ,GAAI,cAAe,GACnC,6BAAmB,IAAK,CAAE,WAC3B;AAAA,cAAC;AAAA;AAAA,gBAEA,SAAU,MAAM;AACf;AAAA,oBACC,OAAO;AAAA,kBACR;AACA,sBAAK,CAAE,oBAAqB;AAC3B,4BAAQ;AAAA,kBACT;AAAA,gBACD;AAAA,gBACA,MACC,qBAAqB,OAAO,QACzB,QACA;AAAA,gBAGF,iBAAO;AAAA;AAAA,cAfH,UAAW,OAAO,KAAM;AAAA,YAgB/B,CACC,GACH;AAAA,aAEF;AAAA;AAAA,MAEF;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -85,9 +85,6 @@ function getIframeSrc(resolvedAssets) {
85
85
  ${resolvedAssets.styles ?? ""}
86
86
  ${resolvedAssets.scripts ?? ""}
87
87
  </head>
88
- <body>
89
- <script>document.currentScript.parentElement.remove()</script>
90
- </body>
91
88
  </html>`;
92
89
  src = URL.createObjectURL(new Blob([html], { type: "text/html" }));
93
90
  iframeSrcCache.set(resolvedAssets, src);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/iframe/index.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useState, createPortal, forwardRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect, useDisabled } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useWritingFlow } from '../writing-flow';\nimport { getCompatibilityStyles } from './get-compatibility-styles';\nimport { useScaleCanvas } from './use-scale-canvas';\nimport { store as blockEditorStore } from '../../store';\n\nfunction bubbleEvent( event, Constructor, frame ) {\n\tconst init = {};\n\n\tfor ( const key in event ) {\n\t\tinit[ key ] = event[ key ];\n\t}\n\n\t// Check if the event is a MouseEvent generated within the iframe.\n\t// If so, adjust the coordinates to be relative to the position of\n\t// the iframe. This ensures that components such as Draggable\n\t// receive coordinates relative to the window, instead of relative\n\t// to the iframe. Without this, the Draggable event handler would\n\t// result in components \"jumping\" position as soon as the user\n\t// drags over the iframe.\n\tif ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {\n\t\tconst rect = frame.getBoundingClientRect();\n\t\tinit.clientX += rect.left;\n\t\tinit.clientY += rect.top;\n\t}\n\n\tconst newEvent = new Constructor( event.type, init );\n\tif ( init.defaultPrevented ) {\n\t\tnewEvent.preventDefault();\n\t}\n\tconst cancelled = ! frame.dispatchEvent( newEvent );\n\n\tif ( cancelled ) {\n\t\tevent.preventDefault();\n\t}\n}\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} iframeDocument Document to attach listeners to.\n */\nfunction useBubbleEvents( iframeDocument ) {\n\treturn useRefEffect( () => {\n\t\tconst { defaultView } = iframeDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { frameElement } = defaultView;\n\t\tconst html = iframeDocument.documentElement;\n\t\tconst eventTypes = [ 'dragover', 'mousemove' ];\n\t\tconst handlers = {};\n\t\tfor ( const name of eventTypes ) {\n\t\t\thandlers[ name ] = ( event ) => {\n\t\t\t\tconst prototype = Object.getPrototypeOf( event );\n\t\t\t\tconst constructorName = prototype.constructor.name;\n\t\t\t\tconst Constructor = window[ constructorName ];\n\t\t\t\tbubbleEvent( event, Constructor, frameElement );\n\t\t\t};\n\t\t\thtml.addEventListener( name, handlers[ name ] );\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor ( const name of eventTypes ) {\n\t\t\t\thtml.removeEventListener( name, handlers[ name ] );\n\t\t\t}\n\t\t};\n\t} );\n}\n\nconst iframeSrcCache = new WeakMap();\nconst iframeSrcCleanup = globalThis.FinalizationRegistry\n\t? new globalThis.FinalizationRegistry( ( url ) =>\n\t\t\tURL.revokeObjectURL( url )\n\t )\n\t: undefined;\n\nfunction getIframeSrc( resolvedAssets ) {\n\tlet src = iframeSrcCache.get( resolvedAssets );\n\tif ( src ) {\n\t\treturn src;\n\t}\n\n\t// Correct doctype is required to enable rendering in standards mode.\n\t// Also preload the styles to avoid a flash of unstyled content.\n\tconst html = `<!doctype html>\n<html>\n\t<head>\n\t\t<meta charset=\"utf-8\">\n\t\t<base href=\"${ window.location.href }\">\n\t\t<style>\n\t\t\thtml{\n\t\t\t\theight: auto !important;\n\t\t\t\tmin-height: 100%;\n\t\t\t}\n\t\t\t/* Lowest specificity to not override global styles */\n\t\t\t:where(body) {\n\t\t\t\tmargin: 0;\n\t\t\t\t/* Default background color in case zoom out mode background\n\t\t\t\tcolors the html element */\n\t\t\t\tbackground-color: white;\n\t\t\t}\n\t\t</style>\n\t\t${ resolvedAssets.styles ?? '' }\n\t\t${ resolvedAssets.scripts ?? '' }\n\t</head>\n\t<body>\n\t\t<script>document.currentScript.parentElement.remove()</script>\n\t</body>\n</html>`;\n\n\tsrc = URL.createObjectURL( new Blob( [ html ], { type: 'text/html' } ) );\n\tiframeSrcCache.set( resolvedAssets, src );\n\tiframeSrcCleanup?.register( resolvedAssets, src );\n\treturn src;\n}\n\nfunction Iframe( {\n\tcontentRef,\n\tchildren,\n\ttabIndex = 0,\n\tscale = 1,\n\tframeSize = 0,\n\treadonly,\n\tforwardedRef: ref,\n\ttitle = __( 'Editor canvas' ),\n\t...props\n} ) {\n\tconst { resolvedAssets, isPreviewMode } = useSelect( ( select ) => {\n\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tresolvedAssets: settings.__unstableResolvedAssets,\n\t\t\tisPreviewMode: settings.isPreviewMode,\n\t\t};\n\t}, [] );\n\t/** @type {[Document, React.Dispatch<Document>]} */\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tlet iFrameDocument;\n\t\t// Prevent the default browser action for files dropped outside of dropzones.\n\t\tfunction preventFileDropDefault( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t\t// Prevent clicks on link fragments from navigating away. Note that links\n\t\t// inside `contenteditable` are already disabled by the browser, so\n\t\t// this is for links in blocks outside of `contenteditable`.\n\t\tfunction interceptLinkClicks( event ) {\n\t\t\tif (\n\t\t\t\tevent.target.tagName === 'A' &&\n\t\t\t\tevent.target.getAttribute( 'href' )?.startsWith( '#' )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t// Manually handle link fragment navigation within the iframe. The iframe's\n\t\t\t\t// location is a blob URL, which can't be used to resolve relative links like\n\t\t\t\t// `#hash`. The relative link would be resolved against the iframe's base URL\n\t\t\t\t// or the parent frame's URL, causing the iframe to navigate to a completely\n\t\t\t\t// different page. Setting the `location.hash` works because it really sets the\n\t\t\t\t// blob URL's hash.\n\t\t\t\t//\n\t\t\t\t// Links with fragments are used for example with footnotes. Clicking on these\n\t\t\t\t// links will scroll smoothly to the anchors in the editor canvas.\n\t\t\t\tiFrameDocument.defaultView.location.hash = event.target\n\t\t\t\t\t.getAttribute( 'href' )\n\t\t\t\t\t.slice( 1 );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\n\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t// the server in the future (which will run the PHP filters).\n\t\tsetBodyClasses(\n\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t( name ) =>\n\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t)\n\t\t);\n\n\t\tfunction onLoad() {\n\t\t\tconst { contentDocument } = node;\n\t\t\tconst { documentElement } = contentDocument;\n\t\t\tiFrameDocument = contentDocument;\n\t\t\tsetIframeDocument( contentDocument );\n\n\t\t\tdocumentElement.classList.add( 'block-editor-iframe__html' );\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\n\t\t\tfor ( const compatStyle of getCompatibilityStyles() ) {\n\t\t\t\tif ( contentDocument.getElementById( compatStyle.id ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcontentDocument.head.appendChild(\n\t\t\t\t\tcompatStyle.cloneNode( true )\n\t\t\t\t);\n\n\t\t\t\tif ( ! isPreviewMode ) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,\n\t\t\t\t\t\tcompatStyle\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener( 'click', interceptLinkClicks );\n\t\t}\n\n\t\tnode.addEventListener( 'load', onLoad );\n\n\t\treturn () => {\n\t\t\tsetIframeDocument( undefined );\n\t\t\tnode.removeEventListener( 'load', onLoad );\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener( 'click', interceptLinkClicks );\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t} = useScaleCanvas( {\n\t\tscale,\n\t\tframeSize: parseInt( frameSize ),\n\t\tiframeDocument,\n\t} );\n\n\tconst disabledRef = useDisabled( { isDisabled: ! readonly } );\n\n\tconst unguardedBodyRef = useMergeRefs( [\n\t\tuseBubbleEvents( iframeDocument ),\n\t\tcontentRef,\n\t\twritingFlowRef,\n\t\tdisabledRef,\n\t] );\n\n\t// Attach the body ref only when the iframe document and window are available.\n\t// When an iframe element is moved in the DOM, like when reordering a list,\n\t// its `window` object is destroyed and recreated, and the `defaultView` field is\n\t// briefly `null`. We need to guard for such calls of the ref callbacks.\n\tconst bodyRef = useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( node.ownerDocument.defaultView ) {\n\t\t\t\tunguardedBodyRef( node );\n\t\t\t\treturn () => unguardedBodyRef( null );\n\t\t\t}\n\t\t\treturn () => {};\n\t\t},\n\t\t[ unguardedBodyRef ]\n\t);\n\n\tconst src = getIframeSrc( resolvedAssets );\n\n\t// Make sure to not render the before and after focusable div elements in view\n\t// mode. They're only needed to capture focus in edit mode.\n\tconst shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode;\n\n\tconst iframe = (\n\t\t<>\n\t\t\t{ shouldRenderFocusCaptureElements && before }\n\t\t\t{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...props.style,\n\t\t\t\t\theight: props.style?.height,\n\t\t\t\t\tborder: 0,\n\t\t\t\t} }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\tsrc={ src }\n\t\t\t\ttitle={ title }\n\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\tif ( props.onKeyDown ) {\n\t\t\t\t\t\tprops.onKeyDown( event );\n\t\t\t\t\t}\n\t\t\t\t\t// If the event originates from inside the iframe, it means\n\t\t\t\t\t// it bubbled through the portal, but only with React\n\t\t\t\t\t// events. We need to to bubble native events as well,\n\t\t\t\t\t// though by doing so we also trigger another React event,\n\t\t\t\t\t// so we need to stop the propagation of this event to avoid\n\t\t\t\t\t// duplication.\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.currentTarget.ownerDocument !==\n\t\t\t\t\t\tevent.target.ownerDocument\n\t\t\t\t\t) {\n\t\t\t\t\t\t// We should only stop propagation of the React event,\n\t\t\t\t\t\t// the native event should further bubble inside the\n\t\t\t\t\t\t// iframe to the document and window.\n\t\t\t\t\t\t// Alternatively, we could consider redispatching the\n\t\t\t\t\t\t// native event in the iframe.\n\t\t\t\t\t\tconst { stopPropagation } = event.nativeEvent;\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = () => {};\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = stopPropagation;\n\t\t\t\t\t\tbubbleEvent(\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\twindow.KeyboardEvent,\n\t\t\t\t\t\t\tevent.currentTarget\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<body\n\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'block-editor-iframe__body',\n\t\t\t\t\t\t\t\t'editor-styles-wrapper',\n\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t</body>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ shouldRenderFocusCaptureElements && after }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<div className=\"block-editor-iframe__container\">\n\t\t\t{ containerResizeListener }\n\t\t\t<div\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'block-editor-iframe__scale-container',\n\t\t\t\t\tisZoomedOut && 'is-zoomed-out'\n\t\t\t\t) }\n\t\t\t\tstyle={ {\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width':\n\t\t\t\t\t\tisZoomedOut && `${ scaleContainerWidth }px`,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ iframe }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction IframeIfReady( props, ref ) {\n\tconst isInitialised = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__internalIsInitialized,\n\t\t[]\n\t);\n\n\t// We shouldn't render the iframe until the editor settings are initialised.\n\t// The initial settings are needed to get the styles for the srcDoc, which\n\t// cannot be changed after the iframe is mounted. srcDoc is used to to set\n\t// the initial iframe HTML, which is required to avoid a flash of unstyled\n\t// content.\n\tif ( ! isInitialised ) {\n\t\treturn null;\n\t}\n\n\treturn <Iframe { ...props } forwardedRef={ ref } />;\n}\n\nexport default forwardRef( IframeIfReady );\n"],
5
- "mappings": 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BAAM,UAAW,KAAM;AAAA,UACxB;AAOA,cACC,MAAM,cAAc,kBACpB,MAAM,OAAO,eACZ;AAMD,kBAAM,EAAE,gBAAgB,IAAI,MAAM;AAClC,kBAAM,YAAY,kBAAkB,MAAM;AAAA,YAAC;AAC3C,kBAAM,gBAAgB;AACtB,kBAAM,YAAY,kBAAkB;AACpC;AAAA,cACC;AAAA,cACA,OAAO;AAAA,cACP,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,QAEE,4BACD;AAAA,UACC;AAAA,YAAC;AAAA;AAAA,cACA,KAAM;AAAA,cACN,WAAY;AAAA,gBACX;AAAA,gBACA;AAAA,gBACA,GAAG;AAAA,cACJ;AAAA,cAEE;AAAA;AAAA,gBACF,oBAAC,iBAAc,UAAW,gBACvB,UACH;AAAA;AAAA;AAAA,UACD;AAAA,UACA,eAAe;AAAA,QAChB;AAAA;AAAA,IACF;AAAA,IACE,oCAAoC;AAAA,KACvC;AAGD,SACC,qBAAC,SAAI,WAAU,kCACZ;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,WAAY;AAAA,UACX;AAAA,UACA,eAAe;AAAA,QAChB;AAAA,QACA,OAAQ;AAAA,UACP,2DACC,eAAe,GAAI,mBAAoB;AAAA,QACzC;AAAA,QAEE;AAAA;AAAA,IACH;AAAA,KACD;AAEF;AAEA,SAAS,cAAe,OAAO,KAAM;AACpC,QAAM,gBAAgB;AAAA,IACrB,CAAE,WACD,OAAQ,gBAAiB,EAAE,YAAY,EAAE;AAAA,IAC1C,CAAC;AAAA,EACF;AAOA,MAAK,CAAE,eAAgB;AACtB,WAAO;AAAA,EACR;AAEA,SAAO,oBAAC,UAAS,GAAG,OAAQ,cAAe,KAAM;AAClD;AAEA,IAAO,iBAAQ,WAAY,aAAc;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useState, createPortal, forwardRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect, useDisabled } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useWritingFlow } from '../writing-flow';\nimport { getCompatibilityStyles } from './get-compatibility-styles';\nimport { useScaleCanvas } from './use-scale-canvas';\nimport { store as blockEditorStore } from '../../store';\n\nfunction bubbleEvent( event, Constructor, frame ) {\n\tconst init = {};\n\n\tfor ( const key in event ) {\n\t\tinit[ key ] = event[ key ];\n\t}\n\n\t// Check if the event is a MouseEvent generated within the iframe.\n\t// If so, adjust the coordinates to be relative to the position of\n\t// the iframe. This ensures that components such as Draggable\n\t// receive coordinates relative to the window, instead of relative\n\t// to the iframe. Without this, the Draggable event handler would\n\t// result in components \"jumping\" position as soon as the user\n\t// drags over the iframe.\n\tif ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {\n\t\tconst rect = frame.getBoundingClientRect();\n\t\tinit.clientX += rect.left;\n\t\tinit.clientY += rect.top;\n\t}\n\n\tconst newEvent = new Constructor( event.type, init );\n\tif ( init.defaultPrevented ) {\n\t\tnewEvent.preventDefault();\n\t}\n\tconst cancelled = ! frame.dispatchEvent( newEvent );\n\n\tif ( cancelled ) {\n\t\tevent.preventDefault();\n\t}\n}\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} iframeDocument Document to attach listeners to.\n */\nfunction useBubbleEvents( iframeDocument ) {\n\treturn useRefEffect( () => {\n\t\tconst { defaultView } = iframeDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { frameElement } = defaultView;\n\t\tconst html = iframeDocument.documentElement;\n\t\tconst eventTypes = [ 'dragover', 'mousemove' ];\n\t\tconst handlers = {};\n\t\tfor ( const name of eventTypes ) {\n\t\t\thandlers[ name ] = ( event ) => {\n\t\t\t\tconst prototype = Object.getPrototypeOf( event );\n\t\t\t\tconst constructorName = prototype.constructor.name;\n\t\t\t\tconst Constructor = window[ constructorName ];\n\t\t\t\tbubbleEvent( event, Constructor, frameElement );\n\t\t\t};\n\t\t\thtml.addEventListener( name, handlers[ name ] );\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor ( const name of eventTypes ) {\n\t\t\t\thtml.removeEventListener( name, handlers[ name ] );\n\t\t\t}\n\t\t};\n\t} );\n}\n\nconst iframeSrcCache = new WeakMap();\nconst iframeSrcCleanup = globalThis.FinalizationRegistry\n\t? new globalThis.FinalizationRegistry( ( url ) =>\n\t\t\tURL.revokeObjectURL( url )\n\t )\n\t: undefined;\n\nfunction getIframeSrc( resolvedAssets ) {\n\tlet src = iframeSrcCache.get( resolvedAssets );\n\tif ( src ) {\n\t\treturn src;\n\t}\n\n\t// Correct doctype is required to enable rendering in standards mode.\n\t// Also preload the styles to avoid a flash of unstyled content.\n\tconst html = `<!doctype html>\n<html>\n\t<head>\n\t\t<meta charset=\"utf-8\">\n\t\t<base href=\"${ window.location.href }\">\n\t\t<style>\n\t\t\thtml{\n\t\t\t\theight: auto !important;\n\t\t\t\tmin-height: 100%;\n\t\t\t}\n\t\t\t/* Lowest specificity to not override global styles */\n\t\t\t:where(body) {\n\t\t\t\tmargin: 0;\n\t\t\t\t/* Default background color in case zoom out mode background\n\t\t\t\tcolors the html element */\n\t\t\t\tbackground-color: white;\n\t\t\t}\n\t\t</style>\n\t\t${ resolvedAssets.styles ?? '' }\n\t\t${ resolvedAssets.scripts ?? '' }\n\t</head>\n</html>`;\n\n\tsrc = URL.createObjectURL( new Blob( [ html ], { type: 'text/html' } ) );\n\tiframeSrcCache.set( resolvedAssets, src );\n\tiframeSrcCleanup?.register( resolvedAssets, src );\n\treturn src;\n}\n\nfunction Iframe( {\n\tcontentRef,\n\tchildren,\n\ttabIndex = 0,\n\tscale = 1,\n\tframeSize = 0,\n\treadonly,\n\tforwardedRef: ref,\n\ttitle = __( 'Editor canvas' ),\n\t...props\n} ) {\n\tconst { resolvedAssets, isPreviewMode } = useSelect( ( select ) => {\n\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tresolvedAssets: settings.__unstableResolvedAssets,\n\t\t\tisPreviewMode: settings.isPreviewMode,\n\t\t};\n\t}, [] );\n\t/** @type {[Document, React.Dispatch<Document>]} */\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tlet iFrameDocument;\n\t\t// Prevent the default browser action for files dropped outside of dropzones.\n\t\tfunction preventFileDropDefault( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t\t// Prevent clicks on link fragments from navigating away. Note that links\n\t\t// inside `contenteditable` are already disabled by the browser, so\n\t\t// this is for links in blocks outside of `contenteditable`.\n\t\tfunction interceptLinkClicks( event ) {\n\t\t\tif (\n\t\t\t\tevent.target.tagName === 'A' &&\n\t\t\t\tevent.target.getAttribute( 'href' )?.startsWith( '#' )\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\t// Manually handle link fragment navigation within the iframe. The iframe's\n\t\t\t\t// location is a blob URL, which can't be used to resolve relative links like\n\t\t\t\t// `#hash`. The relative link would be resolved against the iframe's base URL\n\t\t\t\t// or the parent frame's URL, causing the iframe to navigate to a completely\n\t\t\t\t// different page. Setting the `location.hash` works because it really sets the\n\t\t\t\t// blob URL's hash.\n\t\t\t\t//\n\t\t\t\t// Links with fragments are used for example with footnotes. Clicking on these\n\t\t\t\t// links will scroll smoothly to the anchors in the editor canvas.\n\t\t\t\tiFrameDocument.defaultView.location.hash = event.target\n\t\t\t\t\t.getAttribute( 'href' )\n\t\t\t\t\t.slice( 1 );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\n\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t// the server in the future (which will run the PHP filters).\n\t\tsetBodyClasses(\n\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t( name ) =>\n\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t)\n\t\t);\n\n\t\tfunction onLoad() {\n\t\t\tconst { contentDocument } = node;\n\t\t\tconst { documentElement } = contentDocument;\n\t\t\tiFrameDocument = contentDocument;\n\t\t\tsetIframeDocument( contentDocument );\n\n\t\t\tdocumentElement.classList.add( 'block-editor-iframe__html' );\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\n\t\t\tfor ( const compatStyle of getCompatibilityStyles() ) {\n\t\t\t\tif ( contentDocument.getElementById( compatStyle.id ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcontentDocument.head.appendChild(\n\t\t\t\t\tcompatStyle.cloneNode( true )\n\t\t\t\t);\n\n\t\t\t\tif ( ! isPreviewMode ) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,\n\t\t\t\t\t\tcompatStyle\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener( 'click', interceptLinkClicks );\n\t\t}\n\n\t\tnode.addEventListener( 'load', onLoad );\n\n\t\treturn () => {\n\t\t\tsetIframeDocument( undefined );\n\t\t\tnode.removeEventListener( 'load', onLoad );\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener( 'click', interceptLinkClicks );\n\t\t};\n\t}, [] );\n\n\tconst {\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t} = useScaleCanvas( {\n\t\tscale,\n\t\tframeSize: parseInt( frameSize ),\n\t\tiframeDocument,\n\t} );\n\n\tconst disabledRef = useDisabled( { isDisabled: ! readonly } );\n\n\tconst unguardedBodyRef = useMergeRefs( [\n\t\tuseBubbleEvents( iframeDocument ),\n\t\tcontentRef,\n\t\twritingFlowRef,\n\t\tdisabledRef,\n\t] );\n\n\t// Attach the body ref only when the iframe document and window are available.\n\t// When an iframe element is moved in the DOM, like when reordering a list,\n\t// its `window` object is destroyed and recreated, and the `defaultView` field is\n\t// briefly `null`. We need to guard for such calls of the ref callbacks.\n\tconst bodyRef = useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( node.ownerDocument.defaultView ) {\n\t\t\t\tunguardedBodyRef( node );\n\t\t\t\treturn () => unguardedBodyRef( null );\n\t\t\t}\n\t\t\treturn () => {};\n\t\t},\n\t\t[ unguardedBodyRef ]\n\t);\n\n\tconst src = getIframeSrc( resolvedAssets );\n\n\t// Make sure to not render the before and after focusable div elements in view\n\t// mode. They're only needed to capture focus in edit mode.\n\tconst shouldRenderFocusCaptureElements = tabIndex >= 0 && ! isPreviewMode;\n\n\tconst iframe = (\n\t\t<>\n\t\t\t{ shouldRenderFocusCaptureElements && before }\n\t\t\t{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...props.style,\n\t\t\t\t\theight: props.style?.height,\n\t\t\t\t\tborder: 0,\n\t\t\t\t} }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\tsrc={ src }\n\t\t\t\ttitle={ title }\n\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\tif ( props.onKeyDown ) {\n\t\t\t\t\t\tprops.onKeyDown( event );\n\t\t\t\t\t}\n\t\t\t\t\t// If the event originates from inside the iframe, it means\n\t\t\t\t\t// it bubbled through the portal, but only with React\n\t\t\t\t\t// events. We need to to bubble native events as well,\n\t\t\t\t\t// though by doing so we also trigger another React event,\n\t\t\t\t\t// so we need to stop the propagation of this event to avoid\n\t\t\t\t\t// duplication.\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.currentTarget.ownerDocument !==\n\t\t\t\t\t\tevent.target.ownerDocument\n\t\t\t\t\t) {\n\t\t\t\t\t\t// We should only stop propagation of the React event,\n\t\t\t\t\t\t// the native event should further bubble inside the\n\t\t\t\t\t\t// iframe to the document and window.\n\t\t\t\t\t\t// Alternatively, we could consider redispatching the\n\t\t\t\t\t\t// native event in the iframe.\n\t\t\t\t\t\tconst { stopPropagation } = event.nativeEvent;\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = () => {};\n\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\tevent.nativeEvent.stopPropagation = stopPropagation;\n\t\t\t\t\t\tbubbleEvent(\n\t\t\t\t\t\t\tevent,\n\t\t\t\t\t\t\twindow.KeyboardEvent,\n\t\t\t\t\t\t\tevent.currentTarget\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<body\n\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'block-editor-iframe__body',\n\t\t\t\t\t\t\t\t'editor-styles-wrapper',\n\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t</body>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ shouldRenderFocusCaptureElements && after }\n\t\t</>\n\t);\n\n\treturn (\n\t\t<div className=\"block-editor-iframe__container\">\n\t\t\t{ containerResizeListener }\n\t\t\t<div\n\t\t\t\tclassName={ clsx(\n\t\t\t\t\t'block-editor-iframe__scale-container',\n\t\t\t\t\tisZoomedOut && 'is-zoomed-out'\n\t\t\t\t) }\n\t\t\t\tstyle={ {\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width':\n\t\t\t\t\t\tisZoomedOut && `${ scaleContainerWidth }px`,\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ iframe }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nfunction IframeIfReady( props, ref ) {\n\tconst isInitialised = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__internalIsInitialized,\n\t\t[]\n\t);\n\n\t// We shouldn't render the iframe until the editor settings are initialised.\n\t// The initial settings are needed to get the styles for the srcDoc, which\n\t// cannot be changed after the iframe is mounted. srcDoc is used to to set\n\t// the initial iframe HTML, which is required to avoid a flash of unstyled\n\t// content.\n\tif ( ! isInitialised ) {\n\t\treturn null;\n\t}\n\n\treturn <Iframe { ...props } forwardedRef={ ref } />;\n}\n\nexport default forwardRef( IframeIfReady );\n"],
5
+ "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,UAAU,cAAc,kBAAkB;AACnD,SAAS,UAAU;A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,EAAE,gBAAgB,IAAI,MAAM;AAClC,kBAAM,YAAY,kBAAkB,MAAM;AAAA,YAAC;AAC3C,kBAAM,gBAAgB;AACtB,kBAAM,YAAY,kBAAkB;AACpC;AAAA,cACC;AAAA,cACA,OAAO;AAAA,cACP,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,QAEE,4BACD;AAAA,UACC;AAAA,YAAC;AAAA;AAAA,cACA,KAAM;AAAA,cACN,WAAY;AAAA,gBACX;AAAA,gBACA;AAAA,gBACA,GAAG;AAAA,cACJ;AAAA,cAEE;AAAA;AAAA,gBACF,oBAAC,iBAAc,UAAW,gBACvB,UACH;AAAA;AAAA;AAAA,UACD;AAAA,UACA,eAAe;AAAA,QAChB;AAAA;AAAA,IACF;AAAA,IACE,oCAAoC;AAAA,KACvC;AAGD,SACC,qBAAC,SAAI,WAAU,kCACZ;AAAA;AAAA,IACF;AAAA,MAAC;AAAA;AAAA,QACA,WAAY;AAAA,UACX;AAAA,UACA,eAAe;AAAA,QAChB;AAAA,QACA,OAAQ;AAAA,UACP,2DACC,eAAe,GAAI,mBAAoB;AAAA,QACzC;AAAA,QAEE;AAAA;AAAA,IACH;AAAA,KACD;AAEF;AAEA,SAAS,cAAe,OAAO,KAAM;AACpC,QAAM,gBAAgB;AAAA,IACrB,CAAE,WACD,OAAQ,gBAAiB,EAAE,YAAY,EAAE;AAAA,IAC1C,CAAC;AAAA,EACF;AAOA,MAAK,CAAE,eAAgB;AACtB,WAAO;AAAA,EACR;AAEA,SAAO,oBAAC,UAAS,GAAG,OAAQ,cAAe,KAAM;AAClD;AAEA,IAAO,iBAAQ,WAAY,aAAc;",
6
6
  "names": []
7
7
  }
@@ -152,7 +152,10 @@ function useScaleCanvas({
152
152
  }, [iframeDocument]);
153
153
  const previousIsZoomedOut = useRef(false);
154
154
  useEffect(() => {
155
- const trigger = iframeDocument && previousIsZoomedOut.current !== isZoomedOut;
155
+ if (!iframeDocument) {
156
+ return;
157
+ }
158
+ const trigger = previousIsZoomedOut.current !== isZoomedOut;
156
159
  previousIsZoomedOut.current = isZoomedOut;
157
160
  if (!trigger) {
158
161
  return;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/iframe/use-scale-canvas.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef, useCallback } from '@wordpress/element';\nimport { useReducedMotion, useResizeObserver } from '@wordpress/compose';\n\n/**\n * @typedef {Object} TransitionState\n * @property {number} scaleValue Scale of the canvas.\n * @property {number} frameSize Size of the frame/offset around the canvas.\n * @property {number} containerHeight containerHeight of the iframe.\n * @property {number} scrollTop ScrollTop of the iframe.\n * @property {number} scrollHeight ScrollHeight of the iframe.\n */\n\n/**\n * Calculate the scale of the canvas.\n *\n * @param {Object} options Object of options\n * @param {number} options.frameSize Size of the frame/offset around the canvas\n * @param {number} options.containerWidth Actual width of the canvas container\n * @param {number} options.maxContainerWidth Maximum width of the container to use for the scale calculation. This locks the canvas to a maximum width when zooming out.\n * @param {number} options.scaleContainerWidth Width the of the container wrapping the canvas container\n * @return {number} Scale value between 0 and/or equal to 1\n */\nfunction calculateScale( {\n\tframeSize,\n\tcontainerWidth,\n\tmaxContainerWidth,\n\tscaleContainerWidth,\n} ) {\n\treturn (\n\t\t( Math.min( containerWidth, maxContainerWidth ) - frameSize * 2 ) /\n\t\tscaleContainerWidth\n\t);\n}\n\n/**\n * Compute the next scrollHeight based on the transition states.\n *\n * @param {TransitionState} transitionFrom Starting point of the transition\n * @param {TransitionState} transitionTo Ending state of the transition\n * @return {number} Next scrollHeight based on scale and frame value changes.\n */\nfunction computeScrollHeightNext( transitionFrom, transitionTo ) {\n\tconst { scaleValue: prevScale, scrollHeight: prevScrollHeight } =\n\t\ttransitionFrom;\n\tconst { frameSize, scaleValue } = transitionTo;\n\n\treturn prevScrollHeight * ( scaleValue / prevScale ) + frameSize * 2;\n}\n\n/**\n * Compute the next scrollTop position after scaling the iframe content.\n *\n * @param {TransitionState} transitionFrom Starting point of the transition\n * @param {TransitionState} transitionTo Ending state of the transition\n * @return {number} Next scrollTop position after scaling the iframe content.\n */\nfunction computeScrollTopNext( transitionFrom, transitionTo ) {\n\tconst {\n\t\tcontainerHeight: prevContainerHeight,\n\t\tframeSize: prevFrameSize,\n\t\tscaleValue: prevScale,\n\t\tscrollTop: prevScrollTop,\n\t} = transitionFrom;\n\tconst { containerHeight, frameSize, scaleValue, scrollHeight } =\n\t\ttransitionTo;\n\t// Step 0: Start with the current scrollTop.\n\tlet scrollTopNext = prevScrollTop;\n\t// Step 1: Undo the effects of the previous scale and frame around the\n\t// midpoint of the visible area.\n\tscrollTopNext =\n\t\t( scrollTopNext + prevContainerHeight / 2 - prevFrameSize ) /\n\t\t\tprevScale -\n\t\tprevContainerHeight / 2;\n\n\t// Step 2: Apply the new scale and frame around the midpoint of the\n\t// visible area.\n\tscrollTopNext =\n\t\t( scrollTopNext + containerHeight / 2 ) * scaleValue +\n\t\tframeSize -\n\t\tcontainerHeight / 2;\n\n\t// Step 3: Handle an edge case so that you scroll to the top of the\n\t// iframe if the top of the iframe content is visible in the container.\n\t// The same edge case for the bottom is skipped because changing content\n\t// makes calculating it impossible.\n\tscrollTopNext = prevScrollTop <= prevFrameSize ? 0 : scrollTopNext;\n\n\t// This is the scrollTop value if you are scrolled to the bottom of the\n\t// iframe. We can't just let the browser handle it because we need to\n\t// animate the scaling.\n\tconst maxScrollTop = scrollHeight - containerHeight;\n\n\t// Step 4: Clamp the scrollTopNext between the minimum and maximum\n\t// possible scrollTop positions. Round the value to avoid subpixel\n\t// truncation by the browser which sometimes causes a 1px error.\n\treturn Math.round(\n\t\tMath.min( Math.max( 0, scrollTopNext ), Math.max( 0, maxScrollTop ) )\n\t);\n}\n\n/**\n * Generate the keyframes to use for the zoom out animation.\n *\n * @param {TransitionState} transitionFrom Starting transition state.\n * @param {TransitionState} transitionTo Ending transition state.\n * @return {Object[]} An array of keyframes to use for the animation.\n */\nfunction getAnimationKeyframes( transitionFrom, transitionTo ) {\n\tconst {\n\t\tscaleValue: prevScale,\n\t\tframeSize: prevFrameSize,\n\t\tscrollTop,\n\t} = transitionFrom;\n\tconst { scaleValue, frameSize, scrollTop: scrollTopNext } = transitionTo;\n\n\treturn [\n\t\t{\n\t\t\ttranslate: `0 0`,\n\t\t\tscale: prevScale,\n\t\t\tpaddingTop: `${ prevFrameSize / prevScale }px`,\n\t\t\tpaddingBottom: `${ prevFrameSize / prevScale }px`,\n\t\t},\n\t\t{\n\t\t\ttranslate: `0 ${ scrollTop - scrollTopNext }px`,\n\t\t\tscale: scaleValue,\n\t\t\tpaddingTop: `${ frameSize / scaleValue }px`,\n\t\t\tpaddingBottom: `${ frameSize / scaleValue }px`,\n\t\t},\n\t];\n}\n\n/**\n * @typedef {Object} ScaleCanvasResult\n * @property {boolean} isZoomedOut A boolean indicating if the canvas is zoomed out.\n * @property {number} scaleContainerWidth The width of the container used to calculate the scale.\n * @property {Object} contentResizeListener A resize observer for the content.\n * @property {Object} containerResizeListener A resize observer for the container.\n */\n\n/**\n * Handles scaling the canvas for the zoom out mode and animating between\n * the states.\n *\n * @param {Object} options Object of options.\n * @param {number} options.frameSize Size of the frame around the content.\n * @param {Document} options.iframeDocument Document of the iframe.\n * @param {number} options.maxContainerWidth Max width of the canvas to use as the starting scale point. Defaults to 750.\n * @param {number|string} options.scale Scale of the canvas. Can be an decimal between 0 and 1, 1, or 'auto-scaled'.\n * @return {ScaleCanvasResult} Properties of the result.\n */\nexport function useScaleCanvas( {\n\tframeSize,\n\tiframeDocument,\n\tmaxContainerWidth = 750,\n\tscale,\n} ) {\n\tconst [ contentResizeListener, { height: contentHeight } ] =\n\t\tuseResizeObserver();\n\tconst [\n\t\tcontainerResizeListener,\n\t\t{ width: containerWidth, height: containerHeight },\n\t] = useResizeObserver();\n\n\tconst initialContainerWidthRef = useRef( 0 );\n\tconst isZoomedOut = scale !== 1;\n\tconst prefersReducedMotion = useReducedMotion();\n\tconst isAutoScaled = scale === 'auto-scaled';\n\t// Track if the animation should start when the useEffect runs.\n\tconst startAnimationRef = useRef( false );\n\t// Track the animation so we know if we have an animation running,\n\t// and can cancel it, reverse it, call a finish event, etc.\n\tconst animationRef = useRef( null );\n\n\tuseEffect( () => {\n\t\tif ( ! isZoomedOut ) {\n\t\t\tinitialContainerWidthRef.current = containerWidth;\n\t\t}\n\t}, [ containerWidth, isZoomedOut ] );\n\n\tconst scaleContainerWidth = Math.max(\n\t\tinitialContainerWidthRef.current,\n\t\tcontainerWidth\n\t);\n\n\tconst scaleValue = isAutoScaled\n\t\t? calculateScale( {\n\t\t\t\tframeSize,\n\t\t\t\tcontainerWidth,\n\t\t\t\tmaxContainerWidth,\n\t\t\t\tscaleContainerWidth,\n\t\t } )\n\t\t: scale;\n\n\t/**\n\t * The starting transition state for the zoom out animation.\n\t * @type {React.RefObject<TransitionState>}\n\t */\n\tconst transitionFromRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tcontainerHeight: 0,\n\t\tscrollTop: 0,\n\t\tscrollHeight: 0,\n\t} );\n\n\t/**\n\t * The ending transition state for the zoom out animation.\n\t * @type {React.RefObject<TransitionState>}\n\t */\n\tconst transitionToRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tcontainerHeight: 0,\n\t\tscrollTop: 0,\n\t\tscrollHeight: 0,\n\t} );\n\n\t/**\n\t * Start the zoom out animation. This sets the necessary CSS variables\n\t * for animating the canvas and returns the Animation object.\n\t *\n\t * @return {Animation} The animation object for the zoom out animation.\n\t */\n\tconst startZoomOutAnimation = useCallback( () => {\n\t\tconst { scrollTop } = transitionFromRef.current;\n\t\tconst { scrollTop: scrollTopNext } = transitionToRef.current;\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top',\n\t\t\t`${ scrollTop }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top-next',\n\t\t\t`${ scrollTopNext }px`\n\t\t);\n\n\t\t// If the container has a scrolllbar, force a scrollbar to prevent the content from shifting while animating.\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-overflow-behavior',\n\t\t\ttransitionFromRef.current.scrollHeight ===\n\t\t\t\ttransitionFromRef.current.containerHeight\n\t\t\t\t? 'auto'\n\t\t\t\t: 'scroll'\n\t\t);\n\n\t\tiframeDocument.documentElement.classList.add( 'zoom-out-animation' );\n\n\t\treturn iframeDocument.documentElement.animate(\n\t\t\tgetAnimationKeyframes(\n\t\t\t\ttransitionFromRef.current,\n\t\t\t\ttransitionToRef.current\n\t\t\t),\n\t\t\t{\n\t\t\t\teasing: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)',\n\t\t\t\tduration: 400,\n\t\t\t}\n\t\t);\n\t}, [ iframeDocument ] );\n\n\t/**\n\t * Callback when the zoom out animation is finished.\n\t * - Cleans up animations refs.\n\t * - Adds final CSS vars for scale and frame size to preserve the state.\n\t * - Removes the 'zoom-out-animation' class (which has the fixed positioning).\n\t * - Sets the final scroll position after the canvas is no longer in fixed position.\n\t * - Removes CSS vars related to the animation.\n\t * - Sets the transitionFrom to the transitionTo state to be ready for the next animation.\n\t */\n\tconst finishZoomOutAnimation = useCallback( () => {\n\t\tstartAnimationRef.current = false;\n\t\tanimationRef.current = null;\n\n\t\t// Add our final scale and frame size now that the animation is done.\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\ttransitionToRef.current.scaleValue\n\t\t);\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t`${ transitionToRef.current.frameSize }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.classList.remove( 'zoom-out-animation' );\n\n\t\tiframeDocument.documentElement.scrollTop =\n\t\t\ttransitionToRef.current.scrollTop;\n\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top'\n\t\t);\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top-next'\n\t\t);\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-overflow-behavior'\n\t\t);\n\n\t\t// Update previous values.\n\t\ttransitionFromRef.current = transitionToRef.current;\n\t}, [ iframeDocument ] );\n\n\tconst previousIsZoomedOut = useRef( false );\n\n\t/**\n\t * Runs when zoom out mode is toggled, and sets the startAnimation flag\n\t * so the animation will start when the next useEffect runs. We _only_\n\t * want to animate when the zoom out mode is toggled, not when the scale\n\t * changes due to the container resizing.\n\t */\n\tuseEffect( () => {\n\t\tconst trigger =\n\t\t\tiframeDocument && previousIsZoomedOut.current !== isZoomedOut;\n\n\t\tpreviousIsZoomedOut.current = isZoomedOut;\n\n\t\tif ( ! trigger ) {\n\t\t\treturn;\n\t\t}\n\n\t\tstartAnimationRef.current = true;\n\n\t\tif ( ! isZoomedOut ) {\n\t\t\treturn;\n\t\t}\n\n\t\tiframeDocument.documentElement.classList.add( 'is-zoomed-out' );\n\t\treturn () => {\n\t\t\tiframeDocument.documentElement.classList.remove( 'is-zoomed-out' );\n\t\t};\n\t}, [ iframeDocument, isZoomedOut ] );\n\n\t/**\n\t * This handles:\n\t * 1. Setting the correct scale and vars of the canvas when zoomed out\n\t * 2. If zoom out mode has been toggled, runs the animation of zooming in/out\n\t */\n\tuseEffect( () => {\n\t\tif ( ! iframeDocument ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We need to update the appropriate scale to exit from. If sidebars have been opened since setting the\n\t\t// original scale, we will snap to a much smaller scale due to the scale container immediately changing sizes when exiting.\n\t\tif ( isAutoScaled && transitionFromRef.current.scaleValue !== 1 ) {\n\t\t\t// We use containerWidth as the divisor, as scaleContainerWidth will always match the containerWidth when\n\t\t\t// exiting.\n\t\t\ttransitionFromRef.current.scaleValue = calculateScale( {\n\t\t\t\tframeSize: transitionFromRef.current.frameSize,\n\t\t\t\tcontainerWidth,\n\t\t\t\tmaxContainerWidth,\n\t\t\t\tscaleContainerWidth: containerWidth,\n\t\t\t} );\n\t\t}\n\n\t\tif ( scaleValue < 1 ) {\n\t\t\t// If we are not going to animate the transition, set the scale and frame size directly.\n\t\t\t// If we are animating, these values will be set when the animation is finished.\n\t\t\t// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to\n\t\t\t// animate the transition.\n\t\t\tif ( ! startAnimationRef.current ) {\n\t\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\t\t\tscaleValue\n\t\t\t\t);\n\t\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t\t\t`${ frameSize }px`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-content-height',\n\t\t\t\t`${ contentHeight }px`\n\t\t\t);\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height',\n\t\t\t\t`${ containerHeight }px`\n\t\t\t);\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-container-width',\n\t\t\t\t`${ containerWidth }px`\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width',\n\t\t\t\t`${ scaleContainerWidth }px`\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Handle the zoom out animation:\n\t\t *\n\t\t * - Get the current scrollTop position.\n\t\t * - Calculate where the same scroll position is after scaling.\n\t\t * - Apply fixed positioning to the canvas with a transform offset\n\t\t * to keep the canvas centered.\n\t\t * - Animate the scale and padding to the new scale and frame size.\n\t\t * - After the animation is complete, remove the fixed positioning\n\t\t * and set the scroll position that keeps everything centered.\n\t\t */\n\t\tif ( startAnimationRef.current ) {\n\t\t\t// Don't allow a new transition to start again unless it was started by the zoom out mode changing.\n\t\t\tstartAnimationRef.current = false;\n\n\t\t\t/**\n\t\t\t * If we already have an animation running, reverse it.\n\t\t\t */\n\t\t\tif ( animationRef.current ) {\n\t\t\t\tanimationRef.current.reverse();\n\t\t\t\t// Swap the transition to/from refs so that we set the correct values when\n\t\t\t\t// finishZoomOutAnimation runs.\n\t\t\t\tconst tempTransitionFrom = transitionFromRef.current;\n\t\t\t\tconst tempTransitionTo = transitionToRef.current;\n\t\t\t\ttransitionFromRef.current = tempTransitionTo;\n\t\t\t\ttransitionToRef.current = tempTransitionFrom;\n\t\t\t} else {\n\t\t\t\t/**\n\t\t\t\t * Start a new zoom animation.\n\t\t\t\t */\n\n\t\t\t\t// We can't trust the set value from contentHeight, as it was measured\n\t\t\t\t// before the zoom out mode was changed. After zoom out mode is changed,\n\t\t\t\t// appenders may appear or disappear, so we need to get the height from\n\t\t\t\t// the iframe at this point when we're about to animate the zoom out.\n\t\t\t\t// The iframe scrollTop, scrollHeight, and clientHeight will all be\n\t\t\t\t// the most accurate.\n\t\t\t\ttransitionFromRef.current.scrollTop =\n\t\t\t\t\tiframeDocument.documentElement.scrollTop;\n\t\t\t\ttransitionFromRef.current.scrollHeight =\n\t\t\t\t\tiframeDocument.documentElement.scrollHeight;\n\t\t\t\t// Use containerHeight, as it's the previous container height before the zoom out animation starts.\n\t\t\t\ttransitionFromRef.current.containerHeight = containerHeight;\n\n\t\t\t\ttransitionToRef.current = {\n\t\t\t\t\tscaleValue,\n\t\t\t\t\tframeSize,\n\t\t\t\t\tcontainerHeight:\n\t\t\t\t\t\tiframeDocument.documentElement.clientHeight, // use clientHeight to get the actual height of the new container after zoom state changes have rendered, as it will be the most up-to-date.\n\t\t\t\t};\n\n\t\t\t\ttransitionToRef.current.scrollHeight = computeScrollHeightNext(\n\t\t\t\t\ttransitionFromRef.current,\n\t\t\t\t\ttransitionToRef.current\n\t\t\t\t);\n\t\t\t\ttransitionToRef.current.scrollTop = computeScrollTopNext(\n\t\t\t\t\ttransitionFromRef.current,\n\t\t\t\t\ttransitionToRef.current\n\t\t\t\t);\n\n\t\t\t\tanimationRef.current = startZoomOutAnimation();\n\n\t\t\t\t// If the user prefers reduced motion, finish the animation immediately and set the final state.\n\t\t\t\tif ( prefersReducedMotion ) {\n\t\t\t\t\tfinishZoomOutAnimation();\n\t\t\t\t} else {\n\t\t\t\t\tanimationRef.current.onfinish = finishZoomOutAnimation;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [\n\t\tstartZoomOutAnimation,\n\t\tfinishZoomOutAnimation,\n\t\tprefersReducedMotion,\n\t\tisAutoScaled,\n\t\tscaleValue,\n\t\tframeSize,\n\t\tiframeDocument,\n\t\tcontentHeight,\n\t\tcontainerWidth,\n\t\tcontainerHeight,\n\t\tmaxContainerWidth,\n\t\tscaleContainerWidth,\n\t] );\n\n\treturn {\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t};\n}\n"],
5
- "mappings": ";AAGA,SAAS,WAAW,QAAQ,mBAAmB;AAC/C,SAAS,kBAAkB,yBAAyB;AAqBpD,SAAS,eAAgB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,UACG,KAAK,IAAK,gBAAgB,iBAAkB,IAAI,YAAY,KAC9D;AAEF;AASA,SAAS,wBAAyB,gBAAgB,cAAe;AAChE,QAAM,EAAE,YAAY,WAAW,cAAc,iBAAiB,IAC7D;AACD,QAAM,EAAE,WAAW,WAAW,IAAI;AAElC,SAAO,oBAAqB,aAAa,aAAc,YAAY;AACpE;AASA,SAAS,qBAAsB,gBAAgB,cAAe;AAC7D,QAAM;AAAA,IACL,iBAAiB;AAAA,IACjB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,WA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IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef, useCallback } from '@wordpress/element';\nimport { useReducedMotion, useResizeObserver } from '@wordpress/compose';\n\n/**\n * @typedef {Object} TransitionState\n * @property {number} scaleValue Scale of the canvas.\n * @property {number} frameSize Size of the frame/offset around the canvas.\n * @property {number} containerHeight containerHeight of the iframe.\n * @property {number} scrollTop ScrollTop of the iframe.\n * @property {number} scrollHeight ScrollHeight of the iframe.\n */\n\n/**\n * Calculate the scale of the canvas.\n *\n * @param {Object} options Object of options\n * @param {number} options.frameSize Size of the frame/offset around the canvas\n * @param {number} options.containerWidth Actual width of the canvas container\n * @param {number} options.maxContainerWidth Maximum width of the container to use for the scale calculation. This locks the canvas to a maximum width when zooming out.\n * @param {number} options.scaleContainerWidth Width the of the container wrapping the canvas container\n * @return {number} Scale value between 0 and/or equal to 1\n */\nfunction calculateScale( {\n\tframeSize,\n\tcontainerWidth,\n\tmaxContainerWidth,\n\tscaleContainerWidth,\n} ) {\n\treturn (\n\t\t( Math.min( containerWidth, maxContainerWidth ) - frameSize * 2 ) /\n\t\tscaleContainerWidth\n\t);\n}\n\n/**\n * Compute the next scrollHeight based on the transition states.\n *\n * @param {TransitionState} transitionFrom Starting point of the transition\n * @param {TransitionState} transitionTo Ending state of the transition\n * @return {number} Next scrollHeight based on scale and frame value changes.\n */\nfunction computeScrollHeightNext( transitionFrom, transitionTo ) {\n\tconst { scaleValue: prevScale, scrollHeight: prevScrollHeight } =\n\t\ttransitionFrom;\n\tconst { frameSize, scaleValue } = transitionTo;\n\n\treturn prevScrollHeight * ( scaleValue / prevScale ) + frameSize * 2;\n}\n\n/**\n * Compute the next scrollTop position after scaling the iframe content.\n *\n * @param {TransitionState} transitionFrom Starting point of the transition\n * @param {TransitionState} transitionTo Ending state of the transition\n * @return {number} Next scrollTop position after scaling the iframe content.\n */\nfunction computeScrollTopNext( transitionFrom, transitionTo ) {\n\tconst {\n\t\tcontainerHeight: prevContainerHeight,\n\t\tframeSize: prevFrameSize,\n\t\tscaleValue: prevScale,\n\t\tscrollTop: prevScrollTop,\n\t} = transitionFrom;\n\tconst { containerHeight, frameSize, scaleValue, scrollHeight } =\n\t\ttransitionTo;\n\t// Step 0: Start with the current scrollTop.\n\tlet scrollTopNext = prevScrollTop;\n\t// Step 1: Undo the effects of the previous scale and frame around the\n\t// midpoint of the visible area.\n\tscrollTopNext =\n\t\t( scrollTopNext + prevContainerHeight / 2 - prevFrameSize ) /\n\t\t\tprevScale -\n\t\tprevContainerHeight / 2;\n\n\t// Step 2: Apply the new scale and frame around the midpoint of the\n\t// visible area.\n\tscrollTopNext =\n\t\t( scrollTopNext + containerHeight / 2 ) * scaleValue +\n\t\tframeSize -\n\t\tcontainerHeight / 2;\n\n\t// Step 3: Handle an edge case so that you scroll to the top of the\n\t// iframe if the top of the iframe content is visible in the container.\n\t// The same edge case for the bottom is skipped because changing content\n\t// makes calculating it impossible.\n\tscrollTopNext = prevScrollTop <= prevFrameSize ? 0 : scrollTopNext;\n\n\t// This is the scrollTop value if you are scrolled to the bottom of the\n\t// iframe. We can't just let the browser handle it because we need to\n\t// animate the scaling.\n\tconst maxScrollTop = scrollHeight - containerHeight;\n\n\t// Step 4: Clamp the scrollTopNext between the minimum and maximum\n\t// possible scrollTop positions. Round the value to avoid subpixel\n\t// truncation by the browser which sometimes causes a 1px error.\n\treturn Math.round(\n\t\tMath.min( Math.max( 0, scrollTopNext ), Math.max( 0, maxScrollTop ) )\n\t);\n}\n\n/**\n * Generate the keyframes to use for the zoom out animation.\n *\n * @param {TransitionState} transitionFrom Starting transition state.\n * @param {TransitionState} transitionTo Ending transition state.\n * @return {Object[]} An array of keyframes to use for the animation.\n */\nfunction getAnimationKeyframes( transitionFrom, transitionTo ) {\n\tconst {\n\t\tscaleValue: prevScale,\n\t\tframeSize: prevFrameSize,\n\t\tscrollTop,\n\t} = transitionFrom;\n\tconst { scaleValue, frameSize, scrollTop: scrollTopNext } = transitionTo;\n\n\treturn [\n\t\t{\n\t\t\ttranslate: `0 0`,\n\t\t\tscale: prevScale,\n\t\t\tpaddingTop: `${ prevFrameSize / prevScale }px`,\n\t\t\tpaddingBottom: `${ prevFrameSize / prevScale }px`,\n\t\t},\n\t\t{\n\t\t\ttranslate: `0 ${ scrollTop - scrollTopNext }px`,\n\t\t\tscale: scaleValue,\n\t\t\tpaddingTop: `${ frameSize / scaleValue }px`,\n\t\t\tpaddingBottom: `${ frameSize / scaleValue }px`,\n\t\t},\n\t];\n}\n\n/**\n * @typedef {Object} ScaleCanvasResult\n * @property {boolean} isZoomedOut A boolean indicating if the canvas is zoomed out.\n * @property {number} scaleContainerWidth The width of the container used to calculate the scale.\n * @property {Object} contentResizeListener A resize observer for the content.\n * @property {Object} containerResizeListener A resize observer for the container.\n */\n\n/**\n * Handles scaling the canvas for the zoom out mode and animating between\n * the states.\n *\n * @param {Object} options Object of options.\n * @param {number} options.frameSize Size of the frame around the content.\n * @param {Document} options.iframeDocument Document of the iframe.\n * @param {number} options.maxContainerWidth Max width of the canvas to use as the starting scale point. Defaults to 750.\n * @param {number|string} options.scale Scale of the canvas. Can be an decimal between 0 and 1, 1, or 'auto-scaled'.\n * @return {ScaleCanvasResult} Properties of the result.\n */\nexport function useScaleCanvas( {\n\tframeSize,\n\tiframeDocument,\n\tmaxContainerWidth = 750,\n\tscale,\n} ) {\n\tconst [ contentResizeListener, { height: contentHeight } ] =\n\t\tuseResizeObserver();\n\tconst [\n\t\tcontainerResizeListener,\n\t\t{ width: containerWidth, height: containerHeight },\n\t] = useResizeObserver();\n\n\tconst initialContainerWidthRef = useRef( 0 );\n\tconst isZoomedOut = scale !== 1;\n\tconst prefersReducedMotion = useReducedMotion();\n\tconst isAutoScaled = scale === 'auto-scaled';\n\t// Track if the animation should start when the useEffect runs.\n\tconst startAnimationRef = useRef( false );\n\t// Track the animation so we know if we have an animation running,\n\t// and can cancel it, reverse it, call a finish event, etc.\n\tconst animationRef = useRef( null );\n\n\tuseEffect( () => {\n\t\tif ( ! isZoomedOut ) {\n\t\t\tinitialContainerWidthRef.current = containerWidth;\n\t\t}\n\t}, [ containerWidth, isZoomedOut ] );\n\n\tconst scaleContainerWidth = Math.max(\n\t\tinitialContainerWidthRef.current,\n\t\tcontainerWidth\n\t);\n\n\tconst scaleValue = isAutoScaled\n\t\t? calculateScale( {\n\t\t\t\tframeSize,\n\t\t\t\tcontainerWidth,\n\t\t\t\tmaxContainerWidth,\n\t\t\t\tscaleContainerWidth,\n\t\t } )\n\t\t: scale;\n\n\t/**\n\t * The starting transition state for the zoom out animation.\n\t * @type {React.RefObject<TransitionState>}\n\t */\n\tconst transitionFromRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tcontainerHeight: 0,\n\t\tscrollTop: 0,\n\t\tscrollHeight: 0,\n\t} );\n\n\t/**\n\t * The ending transition state for the zoom out animation.\n\t * @type {React.RefObject<TransitionState>}\n\t */\n\tconst transitionToRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tcontainerHeight: 0,\n\t\tscrollTop: 0,\n\t\tscrollHeight: 0,\n\t} );\n\n\t/**\n\t * Start the zoom out animation. This sets the necessary CSS variables\n\t * for animating the canvas and returns the Animation object.\n\t *\n\t * @return {Animation} The animation object for the zoom out animation.\n\t */\n\tconst startZoomOutAnimation = useCallback( () => {\n\t\tconst { scrollTop } = transitionFromRef.current;\n\t\tconst { scrollTop: scrollTopNext } = transitionToRef.current;\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top',\n\t\t\t`${ scrollTop }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top-next',\n\t\t\t`${ scrollTopNext }px`\n\t\t);\n\n\t\t// If the container has a scrolllbar, force a scrollbar to prevent the content from shifting while animating.\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-overflow-behavior',\n\t\t\ttransitionFromRef.current.scrollHeight ===\n\t\t\t\ttransitionFromRef.current.containerHeight\n\t\t\t\t? 'auto'\n\t\t\t\t: 'scroll'\n\t\t);\n\n\t\tiframeDocument.documentElement.classList.add( 'zoom-out-animation' );\n\n\t\treturn iframeDocument.documentElement.animate(\n\t\t\tgetAnimationKeyframes(\n\t\t\t\ttransitionFromRef.current,\n\t\t\t\ttransitionToRef.current\n\t\t\t),\n\t\t\t{\n\t\t\t\teasing: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)',\n\t\t\t\tduration: 400,\n\t\t\t}\n\t\t);\n\t}, [ iframeDocument ] );\n\n\t/**\n\t * Callback when the zoom out animation is finished.\n\t * - Cleans up animations refs.\n\t * - Adds final CSS vars for scale and frame size to preserve the state.\n\t * - Removes the 'zoom-out-animation' class (which has the fixed positioning).\n\t * - Sets the final scroll position after the canvas is no longer in fixed position.\n\t * - Removes CSS vars related to the animation.\n\t * - Sets the transitionFrom to the transitionTo state to be ready for the next animation.\n\t */\n\tconst finishZoomOutAnimation = useCallback( () => {\n\t\tstartAnimationRef.current = false;\n\t\tanimationRef.current = null;\n\n\t\t// Add our final scale and frame size now that the animation is done.\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\ttransitionToRef.current.scaleValue\n\t\t);\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t`${ transitionToRef.current.frameSize }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.classList.remove( 'zoom-out-animation' );\n\n\t\tiframeDocument.documentElement.scrollTop =\n\t\t\ttransitionToRef.current.scrollTop;\n\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top'\n\t\t);\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scroll-top-next'\n\t\t);\n\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-overflow-behavior'\n\t\t);\n\n\t\t// Update previous values.\n\t\ttransitionFromRef.current = transitionToRef.current;\n\t}, [ iframeDocument ] );\n\n\tconst previousIsZoomedOut = useRef( false );\n\n\t/**\n\t * Runs when zoom out mode is toggled, and sets the startAnimation flag\n\t * so the animation will start when the next useEffect runs. We _only_\n\t * want to animate when the zoom out mode is toggled, not when the scale\n\t * changes due to the container resizing.\n\t */\n\tuseEffect( () => {\n\t\t// Wait for the iframe document so a zoom out state that is already\n\t\t// active on mount (e.g. when the canvas is remounted on a viewport\n\t\t// change) is still detected as a transition.\n\t\tif ( ! iframeDocument ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst trigger = previousIsZoomedOut.current !== isZoomedOut;\n\n\t\tpreviousIsZoomedOut.current = isZoomedOut;\n\n\t\tif ( ! trigger ) {\n\t\t\treturn;\n\t\t}\n\n\t\tstartAnimationRef.current = true;\n\n\t\tif ( ! isZoomedOut ) {\n\t\t\treturn;\n\t\t}\n\n\t\tiframeDocument.documentElement.classList.add( 'is-zoomed-out' );\n\t\treturn () => {\n\t\t\tiframeDocument.documentElement.classList.remove( 'is-zoomed-out' );\n\t\t};\n\t}, [ iframeDocument, isZoomedOut ] );\n\n\t/**\n\t * This handles:\n\t * 1. Setting the correct scale and vars of the canvas when zoomed out\n\t * 2. If zoom out mode has been toggled, runs the animation of zooming in/out\n\t */\n\tuseEffect( () => {\n\t\tif ( ! iframeDocument ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We need to update the appropriate scale to exit from. If sidebars have been opened since setting the\n\t\t// original scale, we will snap to a much smaller scale due to the scale container immediately changing sizes when exiting.\n\t\tif ( isAutoScaled && transitionFromRef.current.scaleValue !== 1 ) {\n\t\t\t// We use containerWidth as the divisor, as scaleContainerWidth will always match the containerWidth when\n\t\t\t// exiting.\n\t\t\ttransitionFromRef.current.scaleValue = calculateScale( {\n\t\t\t\tframeSize: transitionFromRef.current.frameSize,\n\t\t\t\tcontainerWidth,\n\t\t\t\tmaxContainerWidth,\n\t\t\t\tscaleContainerWidth: containerWidth,\n\t\t\t} );\n\t\t}\n\n\t\tif ( scaleValue < 1 ) {\n\t\t\t// If we are not going to animate the transition, set the scale and frame size directly.\n\t\t\t// If we are animating, these values will be set when the animation is finished.\n\t\t\t// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to\n\t\t\t// animate the transition.\n\t\t\tif ( ! startAnimationRef.current ) {\n\t\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\t\t\tscaleValue\n\t\t\t\t);\n\t\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t\t\t`${ frameSize }px`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-content-height',\n\t\t\t\t`${ contentHeight }px`\n\t\t\t);\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height',\n\t\t\t\t`${ containerHeight }px`\n\t\t\t);\n\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-container-width',\n\t\t\t\t`${ containerWidth }px`\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width',\n\t\t\t\t`${ scaleContainerWidth }px`\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Handle the zoom out animation:\n\t\t *\n\t\t * - Get the current scrollTop position.\n\t\t * - Calculate where the same scroll position is after scaling.\n\t\t * - Apply fixed positioning to the canvas with a transform offset\n\t\t * to keep the canvas centered.\n\t\t * - Animate the scale and padding to the new scale and frame size.\n\t\t * - After the animation is complete, remove the fixed positioning\n\t\t * and set the scroll position that keeps everything centered.\n\t\t */\n\t\tif ( startAnimationRef.current ) {\n\t\t\t// Don't allow a new transition to start again unless it was started by the zoom out mode changing.\n\t\t\tstartAnimationRef.current = false;\n\n\t\t\t/**\n\t\t\t * If we already have an animation running, reverse it.\n\t\t\t */\n\t\t\tif ( animationRef.current ) {\n\t\t\t\tanimationRef.current.reverse();\n\t\t\t\t// Swap the transition to/from refs so that we set the correct values when\n\t\t\t\t// finishZoomOutAnimation runs.\n\t\t\t\tconst tempTransitionFrom = transitionFromRef.current;\n\t\t\t\tconst tempTransitionTo = transitionToRef.current;\n\t\t\t\ttransitionFromRef.current = tempTransitionTo;\n\t\t\t\ttransitionToRef.current = tempTransitionFrom;\n\t\t\t} else {\n\t\t\t\t/**\n\t\t\t\t * Start a new zoom animation.\n\t\t\t\t */\n\n\t\t\t\t// We can't trust the set value from contentHeight, as it was measured\n\t\t\t\t// before the zoom out mode was changed. After zoom out mode is changed,\n\t\t\t\t// appenders may appear or disappear, so we need to get the height from\n\t\t\t\t// the iframe at this point when we're about to animate the zoom out.\n\t\t\t\t// The iframe scrollTop, scrollHeight, and clientHeight will all be\n\t\t\t\t// the most accurate.\n\t\t\t\ttransitionFromRef.current.scrollTop =\n\t\t\t\t\tiframeDocument.documentElement.scrollTop;\n\t\t\t\ttransitionFromRef.current.scrollHeight =\n\t\t\t\t\tiframeDocument.documentElement.scrollHeight;\n\t\t\t\t// Use containerHeight, as it's the previous container height before the zoom out animation starts.\n\t\t\t\ttransitionFromRef.current.containerHeight = containerHeight;\n\n\t\t\t\ttransitionToRef.current = {\n\t\t\t\t\tscaleValue,\n\t\t\t\t\tframeSize,\n\t\t\t\t\tcontainerHeight:\n\t\t\t\t\t\tiframeDocument.documentElement.clientHeight, // use clientHeight to get the actual height of the new container after zoom state changes have rendered, as it will be the most up-to-date.\n\t\t\t\t};\n\n\t\t\t\ttransitionToRef.current.scrollHeight = computeScrollHeightNext(\n\t\t\t\t\ttransitionFromRef.current,\n\t\t\t\t\ttransitionToRef.current\n\t\t\t\t);\n\t\t\t\ttransitionToRef.current.scrollTop = computeScrollTopNext(\n\t\t\t\t\ttransitionFromRef.current,\n\t\t\t\t\ttransitionToRef.current\n\t\t\t\t);\n\n\t\t\t\tanimationRef.current = startZoomOutAnimation();\n\n\t\t\t\t// If the user prefers reduced motion, finish the animation immediately and set the final state.\n\t\t\t\tif ( prefersReducedMotion ) {\n\t\t\t\t\tfinishZoomOutAnimation();\n\t\t\t\t} else {\n\t\t\t\t\tanimationRef.current.onfinish = finishZoomOutAnimation;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [\n\t\tstartZoomOutAnimation,\n\t\tfinishZoomOutAnimation,\n\t\tprefersReducedMotion,\n\t\tisAutoScaled,\n\t\tscaleValue,\n\t\tframeSize,\n\t\tiframeDocument,\n\t\tcontentHeight,\n\t\tcontainerWidth,\n\t\tcontainerHeight,\n\t\tmaxContainerWidth,\n\t\tscaleContainerWidth,\n\t] );\n\n\treturn {\n\t\tisZoomedOut,\n\t\tscaleContainerWidth,\n\t\tcontentResizeListener,\n\t\tcontainerResizeListener,\n\t};\n}\n"],
5
+ "mappings": ";AAGA,SAAS,WAAW,QAAQ,mBAAmB;AAC/C,SAAS,kBAAkB,yBAAyB;AAqBpD,SAAS,eAAgB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,UACG,KAAK,IAAK,gBAAgB,iBAAkB,IAAI,YAAY,KAC9D;AAEF;AASA,SAAS,wBAAyB,gBAAgB,cAAe;AAChE,QAAM,EAAE,YAAY,WAAW,cAAc,iBAAiB,IAC7D;AACD,QAAM,EAAE,WAAW,WAAW,IAAI;AAElC,SAAO,oBAAqB,aAAa,aAAc,YAAY;A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AC3B,iCAAuB;AAAA,QACxB,OAAO;AACN,uBAAa,QAAQ,WAAW;AAAA,QACjC;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -6,7 +6,10 @@ import { __, sprintf } from "@wordpress/i18n";
6
6
  import { store as noticesStore } from "@wordpress/notices";
7
7
  import { store as blockEditorStore } from "../../../store/index.mjs";
8
8
  import { unlock } from "../../../lock-unlock.mjs";
9
- import { isNavigationOverlayContextKey } from "../../../store/private-keys.mjs";
9
+ import {
10
+ isNavigationOverlayContextKey,
11
+ userPatternCategoriesSelectKey
12
+ } from "../../../store/private-keys.mjs";
10
13
  import { INSERTER_PATTERN_TYPES } from "../block-patterns-tab/utils.mjs";
11
14
  import { isFiltered } from "../../../store/utils.mjs";
12
15
  var usePatternsState = (onInsert, rootClientId, selectedCategory, isQuick) => {
@@ -24,17 +27,15 @@ var usePatternsState = (onInsert, rootClientId, selectedCategory, isQuick) => {
24
27
  const { getSettings, __experimentalGetAllowedPatterns } = unlock(
25
28
  select(blockEditorStore)
26
29
  );
27
- const {
28
- __experimentalUserPatternCategories,
29
- __experimentalBlockPatternCategories
30
- } = getSettings();
30
+ const settings = getSettings();
31
+ const userPatternCategoriesSelect = settings[userPatternCategoriesSelectKey];
31
32
  return {
32
33
  patterns: __experimentalGetAllowedPatterns(
33
34
  rootClientId,
34
35
  options
35
36
  ),
36
- userPatternCategories: __experimentalUserPatternCategories,
37
- patternCategories: __experimentalBlockPatternCategories
37
+ userPatternCategories: userPatternCategoriesSelect ? userPatternCategoriesSelect(select) : settings.__experimentalUserPatternCategories,
38
+ patternCategories: settings.__experimentalBlockPatternCategories
38
39
  };
39
40
  },
40
41
  [rootClientId, options]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/inserter/hooks/use-patterns-state.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { cloneBlock, createBlock } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\nimport { isNavigationOverlayContextKey } from '../../../store/private-keys';\nimport { INSERTER_PATTERN_TYPES } from '../block-patterns-tab/utils';\nimport { isFiltered } from '../../../store/utils';\n\n/**\n * Retrieves the block patterns inserter state.\n *\n * @param {Function} onInsert function called when inserter a list of blocks.\n * @param {string=} rootClientId Insertion's root client ID.\n * @param {string} selectedCategory The selected pattern category.\n * @param {boolean} isQuick For the quick inserter render only allowed patterns.\n *\n * @return {Array} Returns the patterns state. (patterns, categories, onSelect handler)\n */\nconst usePatternsState = (\n\tonInsert,\n\trootClientId,\n\tselectedCategory,\n\tisQuick\n) => {\n\tconst options = useMemo(\n\t\t() => ( { [ isFiltered ]: !! isQuick } ),\n\t\t[ isQuick ]\n\t);\n\n\t// Check if we're editing a navigation-overlay template part.\n\t// This information is passed through block editor settings to avoid\n\t// cross-package dependencies.\n\tconst isWithinNavigationOverlayContext = useSelect( ( select ) => {\n\t\tconst { getSettings } = unlock( select( blockEditorStore ) );\n\t\tconst settings = getSettings();\n\t\treturn settings[ isNavigationOverlayContextKey ] ?? false;\n\t}, [] );\n\n\tconst { patternCategories, patterns, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, __experimentalGetAllowedPatterns } = unlock(\n\t\t\t\tselect( blockEditorStore )\n\t\t\t);\n\t\t\tconst {\n\t\t\t\t__experimentalUserPatternCategories,\n\t\t\t\t__experimentalBlockPatternCategories,\n\t\t\t} = getSettings();\n\t\t\treturn {\n\t\t\t\tpatterns: __experimentalGetAllowedPatterns(\n\t\t\t\t\trootClientId,\n\t\t\t\t\toptions\n\t\t\t\t),\n\t\t\t\tuserPatternCategories: __experimentalUserPatternCategories,\n\t\t\t\tpatternCategories: __experimentalBlockPatternCategories,\n\t\t\t};\n\t\t},\n\t\t[ rootClientId, options ]\n\t);\n\n\t// Filter out patterns with \"navigation\" category unless we're in\n\t// navigation-overlay template part context.\n\t// TO DO: create an api for patterns to decide in which context they should be shown.\n\tconst filteredPatterns = useMemo( () => {\n\t\treturn patterns.filter( ( pattern ) => {\n\t\t\tconst hasNavigationCategory =\n\t\t\t\tpattern.categories?.includes( 'navigation' );\n\t\t\tif ( hasNavigationCategory && ! isWithinNavigationOverlayContext ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\t}, [ patterns, isWithinNavigationOverlayContext ] );\n\tconst { getClosestAllowedInsertionPointForPattern } = unlock(\n\t\tuseSelect( blockEditorStore )\n\t);\n\n\tconst allCategories = useMemo( () => {\n\t\tconst categories = [ ...patternCategories ];\n\t\tuserPatternCategories?.forEach( ( userCategory ) => {\n\t\t\tif (\n\t\t\t\t! categories.find(\n\t\t\t\t\t( existingCategory ) =>\n\t\t\t\t\t\texistingCategory.name === userCategory.name\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcategories.push( userCategory );\n\t\t\t}\n\t\t} );\n\t\treturn categories;\n\t}, [ patternCategories, userPatternCategories ] );\n\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst onClickPattern = useCallback(\n\t\t( pattern, blocks ) => {\n\t\t\tconst destinationRootClientId = isQuick\n\t\t\t\t? rootClientId\n\t\t\t\t: getClosestAllowedInsertionPointForPattern(\n\t\t\t\t\t\tpattern,\n\t\t\t\t\t\trootClientId\n\t\t\t\t );\n\t\t\tif ( destinationRootClientId === null ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst patternBlocks =\n\t\t\t\tpattern.type === INSERTER_PATTERN_TYPES.user &&\n\t\t\t\tpattern.syncStatus !== 'unsynced'\n\t\t\t\t\t? [ createBlock( 'core/block', { ref: pattern.id } ) ]\n\t\t\t\t\t: blocks;\n\t\t\tonInsert(\n\t\t\t\t( patternBlocks ?? [] ).map( ( block ) => {\n\t\t\t\t\tconst clonedBlock = cloneBlock( block );\n\t\t\t\t\tif (\n\t\t\t\t\t\tclonedBlock.attributes.metadata?.categories?.includes(\n\t\t\t\t\t\t\tselectedCategory\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tclonedBlock.attributes.metadata.categories = [\n\t\t\t\t\t\t\tselectedCategory,\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\t\t\t\t\treturn clonedBlock;\n\t\t\t\t} ),\n\t\t\t\tpattern.name,\n\t\t\t\tfalse,\n\t\t\t\tdestinationRootClientId\n\t\t\t);\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: block pattern title. */\n\t\t\t\t\t__( 'Block pattern \"%s\" inserted.' ),\n\t\t\t\t\tpattern.title\n\t\t\t\t),\n\t\t\t\t{\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\tcreateSuccessNotice,\n\t\t\tonInsert,\n\t\t\tselectedCategory,\n\t\t\trootClientId,\n\t\t\tgetClosestAllowedInsertionPointForPattern,\n\t\t\tisQuick,\n\t\t]\n\t);\n\n\treturn [ filteredPatterns, allCategories, onClickPattern ];\n};\n\nexport default usePatternsState;\n"],
5
- "mappings": ";AAGA,SAAS,aAAa,eAAe;AACrC,SAAS,YAAY,mBAAmB;AACxC,SAAS,aAAa,iBAAiB;AACvC,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,oBAAoB;AAKtC,SAAS,S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BAAkB;AACnD,UACC,CAAE,WAAW;AAAA,QACZ,CAAE,qBACD,iBAAiB,SAAS,aAAa;AAAA,MACzC,GACC;AACD,mBAAW,KAAM,YAAa;AAAA,MAC/B;AAAA,IACD,CAAE;AACF,WAAO;AAAA,EACR,GAAG,CAAE,mBAAmB,qBAAsB,CAAE;AAEhD,QAAM,EAAE,oBAAoB,IAAI,YAAa,YAAa;AAC1D,QAAM,iBAAiB;AAAA,IACtB,CAAE,SAAS,WAAY;AACtB,YAAM,0BAA0B,UAC7B,eACA;AAAA,QACA;AAAA,QACA;AAAA,MACA;AACH,UAAK,4BAA4B,MAAO;AACvC;AAAA,MACD;AACA,YAAM,gBACL,QAAQ,SAAS,uBAAuB,QACxC,QAAQ,eAAe,aACpB,CAAE,YAAa,cAAc,EAAE,KAAK,QAAQ,GAAG,CAAE,CAAE,IACnD;AACJ;AAAA,SACG,iBAAiB,CAAC,GAAI,IAAK,CAAE,UAAW;AACzC,gBAAM,cAAc,WAAY,KAAM;AACtC,cACC,YAAY,WAAW,UAAU,YAAY;AAAA,YAC5C;AAAA,UACD,GACC;AACD,wBAAY,WAAW,SAAS,aAAa;AAAA,cAC5C;AAAA,YACD;AAAA,UACD;AACA,iBAAO;AAAA,QACR,CAAE;AAAA,QACF,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,MACD;AACA;AAAA,QACC;AAAA;AAAA,UAEC,GAAI,8BAA+B;AAAA,UACnC,QAAQ;AAAA,QACT;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,IAAI;AAAA,QACL;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,SAAO,CAAE,kBAAkB,eAAe,cAAe;AAC1D;AAEA,IAAO,6BAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { cloneBlock, createBlock } from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\nimport {\n\tisNavigationOverlayContextKey,\n\tuserPatternCategoriesSelectKey,\n} from '../../../store/private-keys';\nimport { INSERTER_PATTERN_TYPES } from '../block-patterns-tab/utils';\nimport { isFiltered } from '../../../store/utils';\n\n/**\n * Retrieves the block patterns inserter state.\n *\n * @param {Function} onInsert function called when inserter a list of blocks.\n * @param {string=} rootClientId Insertion's root client ID.\n * @param {string} selectedCategory The selected pattern category.\n * @param {boolean} isQuick For the quick inserter render only allowed patterns.\n *\n * @return {Array} Returns the patterns state. (patterns, categories, onSelect handler)\n */\nconst usePatternsState = (\n\tonInsert,\n\trootClientId,\n\tselectedCategory,\n\tisQuick\n) => {\n\tconst options = useMemo(\n\t\t() => ( { [ isFiltered ]: !! isQuick } ),\n\t\t[ isQuick ]\n\t);\n\n\t// Check if we're editing a navigation-overlay template part.\n\t// This information is passed through block editor settings to avoid\n\t// cross-package dependencies.\n\tconst isWithinNavigationOverlayContext = useSelect( ( select ) => {\n\t\tconst { getSettings } = unlock( select( blockEditorStore ) );\n\t\tconst settings = getSettings();\n\t\treturn settings[ isNavigationOverlayContextKey ] ?? false;\n\t}, [] );\n\n\tconst { patternCategories, patterns, userPatternCategories } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, __experimentalGetAllowedPatterns } = unlock(\n\t\t\t\tselect( blockEditorStore )\n\t\t\t);\n\t\t\tconst settings = getSettings();\n\t\t\tconst userPatternCategoriesSelect =\n\t\t\t\tsettings[ userPatternCategoriesSelectKey ];\n\t\t\treturn {\n\t\t\t\tpatterns: __experimentalGetAllowedPatterns(\n\t\t\t\t\trootClientId,\n\t\t\t\t\toptions\n\t\t\t\t),\n\t\t\t\tuserPatternCategories: userPatternCategoriesSelect\n\t\t\t\t\t? userPatternCategoriesSelect( select )\n\t\t\t\t\t: settings.__experimentalUserPatternCategories,\n\t\t\t\tpatternCategories:\n\t\t\t\t\tsettings.__experimentalBlockPatternCategories,\n\t\t\t};\n\t\t},\n\t\t[ rootClientId, options ]\n\t);\n\n\t// Filter out patterns with \"navigation\" category unless we're in\n\t// navigation-overlay template part context.\n\t// TO DO: create an api for patterns to decide in which context they should be shown.\n\tconst filteredPatterns = useMemo( () => {\n\t\treturn patterns.filter( ( pattern ) => {\n\t\t\tconst hasNavigationCategory =\n\t\t\t\tpattern.categories?.includes( 'navigation' );\n\t\t\tif ( hasNavigationCategory && ! isWithinNavigationOverlayContext ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t} );\n\t}, [ patterns, isWithinNavigationOverlayContext ] );\n\tconst { getClosestAllowedInsertionPointForPattern } = unlock(\n\t\tuseSelect( blockEditorStore )\n\t);\n\n\tconst allCategories = useMemo( () => {\n\t\tconst categories = [ ...patternCategories ];\n\t\tuserPatternCategories?.forEach( ( userCategory ) => {\n\t\t\tif (\n\t\t\t\t! categories.find(\n\t\t\t\t\t( existingCategory ) =>\n\t\t\t\t\t\texistingCategory.name === userCategory.name\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcategories.push( userCategory );\n\t\t\t}\n\t\t} );\n\t\treturn categories;\n\t}, [ patternCategories, userPatternCategories ] );\n\n\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\tconst onClickPattern = useCallback(\n\t\t( pattern, blocks ) => {\n\t\t\tconst destinationRootClientId = isQuick\n\t\t\t\t? rootClientId\n\t\t\t\t: getClosestAllowedInsertionPointForPattern(\n\t\t\t\t\t\tpattern,\n\t\t\t\t\t\trootClientId\n\t\t\t\t );\n\t\t\tif ( destinationRootClientId === null ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst patternBlocks =\n\t\t\t\tpattern.type === INSERTER_PATTERN_TYPES.user &&\n\t\t\t\tpattern.syncStatus !== 'unsynced'\n\t\t\t\t\t? [ createBlock( 'core/block', { ref: pattern.id } ) ]\n\t\t\t\t\t: blocks;\n\t\t\tonInsert(\n\t\t\t\t( patternBlocks ?? [] ).map( ( block ) => {\n\t\t\t\t\tconst clonedBlock = cloneBlock( block );\n\t\t\t\t\tif (\n\t\t\t\t\t\tclonedBlock.attributes.metadata?.categories?.includes(\n\t\t\t\t\t\t\tselectedCategory\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tclonedBlock.attributes.metadata.categories = [\n\t\t\t\t\t\t\tselectedCategory,\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\t\t\t\t\treturn clonedBlock;\n\t\t\t\t} ),\n\t\t\t\tpattern.name,\n\t\t\t\tfalse,\n\t\t\t\tdestinationRootClientId\n\t\t\t);\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: %s: block pattern title. */\n\t\t\t\t\t__( 'Block pattern \"%s\" inserted.' ),\n\t\t\t\t\tpattern.title\n\t\t\t\t),\n\t\t\t\t{\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\tcreateSuccessNotice,\n\t\t\tonInsert,\n\t\t\tselectedCategory,\n\t\t\trootClientId,\n\t\t\tgetClosestAllowedInsertionPointForPattern,\n\t\t\tisQuick,\n\t\t]\n\t);\n\n\treturn [ filteredPatterns, allCategories, onClickPattern ];\n};\n\nexport default usePatternsState;\n"],
5
+ "mappings": ";AAGA,SAAS,aAAa,eAAe;AACrC,SAAS,YAAY,mBAAmB;AACxC,SAAS,aAAa,iBAAiB;AACvC,SAAS,IAAI,eAAe;AAC5B,SAAS,SAAS,oBAAoB;AAKtC,SAAS,SAAS,wBAAwB;AAC1C,SAAS,cAAc;AACvB;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,8BAA8B;AACvC,SAAS,kBAAkB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BAAiB,SAAS,aAAa;AAAA,MACzC,GACC;AACD,mBAAW,KAAM,YAAa;AAAA,MAC/B;AAAA,IACD,CAAE;AACF,WAAO;AAAA,EACR,GAAG,CAAE,mBAAmB,qBAAsB,CAAE;AAEhD,QAAM,EAAE,oBAAoB,IAAI,YAAa,YAAa;AAC1D,QAAM,iBAAiB;AAAA,IACtB,CAAE,SAAS,WAAY;AACtB,YAAM,0BAA0B,UAC7B,eACA;AAAA,QACA;AAAA,QACA;AAAA,MACA;AACH,UAAK,4BAA4B,MAAO;AACvC;AAAA,MACD;AACA,YAAM,gBACL,QAAQ,SAAS,uBAAuB,QACxC,QAAQ,eAAe,aACpB,CAAE,YAAa,cAAc,EAAE,KAAK,QAAQ,GAAG,CAAE,CAAE,IACnD;AACJ;AAAA,SACG,iBAAiB,CAAC,GAAI,IAAK,CAAE,UAAW;AACzC,gBAAM,cAAc,WAAY,KAAM;AACtC,cACC,YAAY,WAAW,UAAU,YAAY;AAAA,YAC5C;AAAA,UACD,GACC;AACD,wBAAY,WAAW,SAAS,aAAa;AAAA,cAC5C;AAAA,YACD;AAAA,UACD;AACA,iBAAO;AAAA,QACR,CAAE;AAAA,QACF,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,MACD;AACA;AAAA,QACC;AAAA;AAAA,UAEC,GAAI,8BAA+B;AAAA,UACnC,QAAQ;AAAA,QACT;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,IAAI;AAAA,QACL;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,SAAO,CAAE,kBAAkB,eAAe,cAAe;AAC1D;AAEA,IAAO,6BAAQ;",
6
6
  "names": []
7
7
  }
@@ -59,6 +59,7 @@ var defaultRenderToggle = ({
59
59
  className: "block-editor-inserter__toggle",
60
60
  "aria-haspopup": !hasSingleBlockType ? "true" : false,
61
61
  "aria-expanded": !hasSingleBlockType ? isOpen : false,
62
+ isPressed: !hasSingleBlockType && isOpen,
62
63
  disabled,
63
64
  ...rest
64
65
  }