@wordpress/block-editor 14.8.0 → 14.8.1-next.cd6172eb0.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 (249) hide show
  1. package/build/autocompleters/block.js +2 -4
  2. package/build/autocompleters/block.js.map +1 -1
  3. package/build/autocompleters/link.js +2 -4
  4. package/build/autocompleters/link.js.map +1 -1
  5. package/build/components/block-canvas/index.js +3 -6
  6. package/build/components/block-canvas/index.js.map +1 -1
  7. package/build/components/block-list/block.js +6 -5
  8. package/build/components/block-list/block.js.map +1 -1
  9. package/build/components/block-list/index.js +0 -1
  10. package/build/components/block-list/index.js.map +1 -1
  11. package/build/components/block-list/use-block-props/index.js +7 -2
  12. package/build/components/block-list/use-block-props/index.js.map +1 -1
  13. package/build/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +34 -0
  14. package/build/components/block-list/use-block-props/use-firefox-draggable-compatibility.js.map +1 -0
  15. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +98 -5
  16. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  17. package/build/components/block-patterns-list/index.js +13 -4
  18. package/build/components/block-patterns-list/index.js.map +1 -1
  19. package/build/components/block-popover/inbetween.js +4 -0
  20. package/build/components/block-popover/inbetween.js.map +1 -1
  21. package/build/components/block-settings-menu/block-settings-dropdown.js +7 -4
  22. package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  23. package/build/components/block-settings-menu-controls/index.js +1 -1
  24. package/build/components/block-settings-menu-controls/index.js.map +1 -1
  25. package/build/components/block-switcher/index.js +12 -22
  26. package/build/components/block-switcher/index.js.map +1 -1
  27. package/build/components/block-switcher/use-transformed-patterns.js +0 -1
  28. package/build/components/block-switcher/use-transformed-patterns.js.map +1 -1
  29. package/build/components/block-switcher/utils.js +0 -1
  30. package/build/components/block-switcher/utils.js.map +1 -1
  31. package/build/components/block-toolbar/index.js +7 -6
  32. package/build/components/block-toolbar/index.js.map +1 -1
  33. package/build/components/block-variation-transforms/index.js +0 -1
  34. package/build/components/block-variation-transforms/index.js.map +1 -1
  35. package/build/components/date-format-picker/index.js +0 -1
  36. package/build/components/date-format-picker/index.js.map +1 -1
  37. package/build/components/font-appearance-control/index.js +1 -0
  38. package/build/components/font-appearance-control/index.js.map +1 -1
  39. package/build/components/font-family/index.js +10 -0
  40. package/build/components/font-family/index.js.map +1 -1
  41. package/build/components/global-styles/dimensions-panel.js +17 -16
  42. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  43. package/build/components/global-styles/get-global-styles-changes.js +0 -1
  44. package/build/components/global-styles/get-global-styles-changes.js.map +1 -1
  45. package/build/components/iframe/use-scale-canvas.js +68 -47
  46. package/build/components/iframe/use-scale-canvas.js.map +1 -1
  47. package/build/components/inserter/block-patterns-tab/index.js +0 -10
  48. package/build/components/inserter/block-patterns-tab/index.js.map +1 -1
  49. package/build/components/inserter/menu.js +2 -1
  50. package/build/components/inserter/menu.js.map +1 -1
  51. package/build/components/inserter-draggable-blocks/index.js +19 -10
  52. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  53. package/build/components/letter-spacing-control/index.js +10 -0
  54. package/build/components/letter-spacing-control/index.js.map +1 -1
  55. package/build/components/line-height-control/index.js +1 -0
  56. package/build/components/line-height-control/index.js.map +1 -1
  57. package/build/components/media-placeholder/index.js +18 -18
  58. package/build/components/media-placeholder/index.js.map +1 -1
  59. package/build/components/observe-typing/index.js +0 -1
  60. package/build/components/observe-typing/index.js.map +1 -1
  61. package/build/components/recursion-provider/index.js +0 -1
  62. package/build/components/recursion-provider/index.js.map +1 -1
  63. package/build/components/rich-text/index.js +5 -1
  64. package/build/components/rich-text/index.js.map +1 -1
  65. package/build/components/rich-text/native/use-format-types.js +0 -1
  66. package/build/components/rich-text/native/use-format-types.js.map +1 -1
  67. package/build/components/rich-text/use-format-types.js +0 -1
  68. package/build/components/rich-text/use-format-types.js.map +1 -1
  69. package/build/components/spacing-sizes-control/utils.js +0 -1
  70. package/build/components/spacing-sizes-control/utils.js.map +1 -1
  71. package/build/components/typewriter/index.js +0 -1
  72. package/build/components/typewriter/index.js.map +1 -1
  73. package/build/components/use-block-drop-zone/index.js +11 -2
  74. package/build/components/use-block-drop-zone/index.js.map +1 -1
  75. package/build/components/use-moving-animation/index.js +15 -2
  76. package/build/components/use-moving-animation/index.js.map +1 -1
  77. package/build/components/use-resize-canvas/index.js +1 -1
  78. package/build/components/use-resize-canvas/index.js.map +1 -1
  79. package/build/components/writing-flow/use-drag-selection.js +11 -0
  80. package/build/components/writing-flow/use-drag-selection.js.map +1 -1
  81. package/build/components/writing-flow/use-tab-nav.js +6 -2
  82. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  83. package/build/hooks/block-bindings.js +4 -3
  84. package/build/hooks/block-bindings.js.map +1 -1
  85. package/build/hooks/gap.js +1 -1
  86. package/build/hooks/gap.js.map +1 -1
  87. package/build/hooks/generated-class-name.js +0 -1
  88. package/build/hooks/generated-class-name.js.map +1 -1
  89. package/build/store/private-selectors.js +1 -7
  90. package/build/store/private-selectors.js.map +1 -1
  91. package/build/store/reducer.js +478 -2
  92. package/build/store/reducer.js.map +1 -1
  93. package/build/store/selectors.js +12 -55
  94. package/build/store/selectors.js.map +1 -1
  95. package/build/utils/object.js +0 -1
  96. package/build/utils/object.js.map +1 -1
  97. package/build-module/autocompleters/block.js +2 -4
  98. package/build-module/autocompleters/block.js.map +1 -1
  99. package/build-module/autocompleters/link.js +2 -4
  100. package/build-module/autocompleters/link.js.map +1 -1
  101. package/build-module/components/block-canvas/index.js +3 -6
  102. package/build-module/components/block-canvas/index.js.map +1 -1
  103. package/build-module/components/block-list/block.js +8 -7
  104. package/build-module/components/block-list/block.js.map +1 -1
  105. package/build-module/components/block-list/index.js +0 -1
  106. package/build-module/components/block-list/index.js.map +1 -1
  107. package/build-module/components/block-list/use-block-props/index.js +7 -2
  108. package/build-module/components/block-list/use-block-props/index.js.map +1 -1
  109. package/build-module/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +28 -0
  110. package/build-module/components/block-list/use-block-props/use-firefox-draggable-compatibility.js.map +1 -0
  111. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +97 -5
  112. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +1 -1
  113. package/build-module/components/block-patterns-list/index.js +13 -4
  114. package/build-module/components/block-patterns-list/index.js.map +1 -1
  115. package/build-module/components/block-popover/inbetween.js +4 -0
  116. package/build-module/components/block-popover/inbetween.js.map +1 -1
  117. package/build-module/components/block-settings-menu/block-settings-dropdown.js +7 -4
  118. package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
  119. package/build-module/components/block-settings-menu-controls/index.js +1 -1
  120. package/build-module/components/block-settings-menu-controls/index.js.map +1 -1
  121. package/build-module/components/block-switcher/index.js +13 -23
  122. package/build-module/components/block-switcher/index.js.map +1 -1
  123. package/build-module/components/block-switcher/use-transformed-patterns.js +0 -1
  124. package/build-module/components/block-switcher/use-transformed-patterns.js.map +1 -1
  125. package/build-module/components/block-switcher/utils.js +0 -1
  126. package/build-module/components/block-switcher/utils.js.map +1 -1
  127. package/build-module/components/block-toolbar/index.js +7 -6
  128. package/build-module/components/block-toolbar/index.js.map +1 -1
  129. package/build-module/components/block-variation-transforms/index.js +0 -1
  130. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  131. package/build-module/components/date-format-picker/index.js +0 -1
  132. package/build-module/components/date-format-picker/index.js.map +1 -1
  133. package/build-module/components/font-appearance-control/index.js +1 -0
  134. package/build-module/components/font-appearance-control/index.js.map +1 -1
  135. package/build-module/components/font-family/index.js +10 -0
  136. package/build-module/components/font-family/index.js.map +1 -1
  137. package/build-module/components/global-styles/dimensions-panel.js +17 -16
  138. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  139. package/build-module/components/global-styles/get-global-styles-changes.js +0 -1
  140. package/build-module/components/global-styles/get-global-styles-changes.js.map +1 -1
  141. package/build-module/components/iframe/use-scale-canvas.js +68 -47
  142. package/build-module/components/iframe/use-scale-canvas.js.map +1 -1
  143. package/build-module/components/inserter/block-patterns-tab/index.js +1 -11
  144. package/build-module/components/inserter/block-patterns-tab/index.js.map +1 -1
  145. package/build-module/components/inserter/menu.js +2 -1
  146. package/build-module/components/inserter/menu.js.map +1 -1
  147. package/build-module/components/inserter-draggable-blocks/index.js +20 -11
  148. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  149. package/build-module/components/letter-spacing-control/index.js +9 -0
  150. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  151. package/build-module/components/line-height-control/index.js +1 -0
  152. package/build-module/components/line-height-control/index.js.map +1 -1
  153. package/build-module/components/media-placeholder/index.js +18 -18
  154. package/build-module/components/media-placeholder/index.js.map +1 -1
  155. package/build-module/components/observe-typing/index.js +0 -1
  156. package/build-module/components/observe-typing/index.js.map +1 -1
  157. package/build-module/components/recursion-provider/index.js +0 -1
  158. package/build-module/components/recursion-provider/index.js.map +1 -1
  159. package/build-module/components/rich-text/index.js +5 -1
  160. package/build-module/components/rich-text/index.js.map +1 -1
  161. package/build-module/components/rich-text/native/use-format-types.js +0 -1
  162. package/build-module/components/rich-text/native/use-format-types.js.map +1 -1
  163. package/build-module/components/rich-text/use-format-types.js +0 -1
  164. package/build-module/components/rich-text/use-format-types.js.map +1 -1
  165. package/build-module/components/spacing-sizes-control/utils.js +0 -1
  166. package/build-module/components/spacing-sizes-control/utils.js.map +1 -1
  167. package/build-module/components/typewriter/index.js +0 -1
  168. package/build-module/components/typewriter/index.js.map +1 -1
  169. package/build-module/components/use-block-drop-zone/index.js +11 -2
  170. package/build-module/components/use-block-drop-zone/index.js.map +1 -1
  171. package/build-module/components/use-moving-animation/index.js +15 -2
  172. package/build-module/components/use-moving-animation/index.js.map +1 -1
  173. package/build-module/components/use-resize-canvas/index.js +1 -1
  174. package/build-module/components/use-resize-canvas/index.js.map +1 -1
  175. package/build-module/components/writing-flow/use-drag-selection.js +11 -0
  176. package/build-module/components/writing-flow/use-drag-selection.js.map +1 -1
  177. package/build-module/components/writing-flow/use-tab-nav.js +6 -2
  178. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  179. package/build-module/hooks/block-bindings.js +4 -3
  180. package/build-module/hooks/block-bindings.js.map +1 -1
  181. package/build-module/hooks/gap.js +1 -1
  182. package/build-module/hooks/gap.js.map +1 -1
  183. package/build-module/hooks/generated-class-name.js +0 -1
  184. package/build-module/hooks/generated-class-name.js.map +1 -1
  185. package/build-module/store/private-selectors.js +1 -6
  186. package/build-module/store/private-selectors.js.map +1 -1
  187. package/build-module/store/reducer.js +479 -3
  188. package/build-module/store/reducer.js.map +1 -1
  189. package/build-module/store/selectors.js +12 -55
  190. package/build-module/store/selectors.js.map +1 -1
  191. package/build-module/utils/object.js +0 -1
  192. package/build-module/utils/object.js.map +1 -1
  193. package/build-style/content-rtl.css +17 -4
  194. package/build-style/content.css +17 -4
  195. package/build-style/style-rtl.css +21 -16
  196. package/build-style/style.css +21 -16
  197. package/package.json +32 -32
  198. package/src/autocompleters/block.js +2 -4
  199. package/src/autocompleters/link.js +2 -4
  200. package/src/components/alignment-control/stories/aliginment-toolbar.story.js +47 -0
  201. package/src/components/alignment-control/stories/index.story.js +51 -0
  202. package/src/components/alignment-control/test/__snapshots__/index.js.snap +5 -5
  203. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +4 -4
  204. package/src/components/block-canvas/index.js +3 -5
  205. package/src/components/block-draggable/content.scss +11 -5
  206. package/src/components/block-list/block.js +7 -13
  207. package/src/components/block-list/content.scss +6 -0
  208. package/src/components/block-list/use-block-props/index.js +7 -0
  209. package/src/components/block-list/use-block-props/use-firefox-draggable-compatibility.js +25 -0
  210. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +112 -8
  211. package/src/components/block-patterns-list/index.js +12 -1
  212. package/src/components/block-patterns-list/style.scss +16 -5
  213. package/src/components/block-popover/inbetween.js +4 -0
  214. package/src/components/block-settings-menu/block-settings-dropdown.js +6 -1
  215. package/src/components/block-settings-menu-controls/index.js +2 -1
  216. package/src/components/block-switcher/index.js +19 -21
  217. package/src/components/block-switcher/style.scss +0 -9
  218. package/src/components/block-title/test/index.js +2 -0
  219. package/src/components/block-toolbar/index.js +8 -6
  220. package/src/components/block-tools/style.scss +5 -0
  221. package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +3 -3
  222. package/src/components/font-appearance-control/index.js +1 -0
  223. package/src/components/font-family/index.js +10 -0
  224. package/src/components/font-family/style.scss +5 -0
  225. package/src/components/global-styles/dimensions-panel.js +16 -16
  226. package/src/components/iframe/content.scss +6 -1
  227. package/src/components/iframe/use-scale-canvas.js +103 -81
  228. package/src/components/inserter/block-patterns-tab/index.js +1 -17
  229. package/src/components/inserter/menu.js +8 -1
  230. package/src/components/inserter-draggable-blocks/index.js +19 -29
  231. package/src/components/letter-spacing-control/README.md +2 -1
  232. package/src/components/letter-spacing-control/index.js +17 -0
  233. package/src/components/line-height-control/index.js +1 -0
  234. package/src/components/media-placeholder/index.js +25 -28
  235. package/src/components/rich-text/index.js +5 -0
  236. package/src/components/use-block-drop-zone/index.js +18 -1
  237. package/src/components/use-moving-animation/index.js +15 -0
  238. package/src/components/use-resize-canvas/index.js +1 -1
  239. package/src/components/writing-flow/use-drag-selection.js +11 -0
  240. package/src/components/writing-flow/use-tab-nav.js +9 -6
  241. package/src/hooks/block-bindings.js +8 -4
  242. package/src/hooks/gap.js +1 -1
  243. package/src/store/private-selectors.js +2 -17
  244. package/src/store/reducer.js +639 -2
  245. package/src/store/selectors.js +19 -69
  246. package/src/store/test/private-selectors.js +1 -0
  247. package/src/store/test/reducer.js +849 -0
  248. package/src/store/test/selectors.js +4 -110
  249. package/src/style.scss +1 -0
@@ -1 +1 @@
1
- {"version":3,"names":["_memize","_interopRequireDefault","require","_i18n","_blocks","globalStylesChangesCache","Map","EMPTY_ARRAY","translationMap","caption","__","link","button","heading","h1","h2","h3","h4","h5","h6","getBlockNames","memoize","getBlockTypes","reduce","accumulator","name","title","isObject","obj","getTranslation","key","keyArray","split","blockName","undefined","deepCompare","changedObject","originalObject","parentPath","slice","join","allKeys","Set","Object","keys","diffs","path","changedPath","concat","getGlobalStylesChangelist","next","previous","cacheKey","JSON","stringify","has","get","changedValueTree","styles","background","color","typography","spacing","blocks","elements","settings","length","set","result","acc","curr","translation","push","getGlobalStylesChanges","options","changeList","changesLength","maxResults","entries","group","includes","map","changeValues","changeValuesLength","joinedChangesValue","sprintf","_n"],"sources":["@wordpress/block-editor/src/components/global-styles/get-global-styles-changes.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { getBlockTypes } from '@wordpress/blocks';\n\nconst globalStylesChangesCache = new Map();\nconst EMPTY_ARRAY = [];\nconst translationMap = {\n\tcaption: __( 'Caption' ),\n\tlink: __( 'Link' ),\n\tbutton: __( 'Button' ),\n\theading: __( 'Heading' ),\n\th1: __( 'H1' ),\n\th2: __( 'H2' ),\n\th3: __( 'H3' ),\n\th4: __( 'H4' ),\n\th5: __( 'H5' ),\n\th6: __( 'H6' ),\n\t'settings.color': __( 'Color' ),\n\t'settings.typography': __( 'Typography' ),\n\t'styles.color': __( 'Colors' ),\n\t'styles.spacing': __( 'Spacing' ),\n\t'styles.background': __( 'Background' ),\n\t'styles.typography': __( 'Typography' ),\n};\nconst getBlockNames = memoize( () =>\n\tgetBlockTypes().reduce( ( accumulator, { name, title } ) => {\n\t\taccumulator[ name ] = title;\n\t\treturn accumulator;\n\t}, {} )\n);\nconst isObject = ( obj ) => obj !== null && typeof obj === 'object';\n\n/**\n * Get the translation for a given global styles key.\n * @param {string} key A key representing a path to a global style property or setting.\n * @return {string|undefined} A translated key or undefined if no translation exists.\n */\nfunction getTranslation( key ) {\n\tif ( translationMap[ key ] ) {\n\t\treturn translationMap[ key ];\n\t}\n\n\tconst keyArray = key.split( '.' );\n\n\tif ( keyArray?.[ 0 ] === 'blocks' ) {\n\t\tconst blockName = getBlockNames()?.[ keyArray[ 1 ] ];\n\t\treturn blockName || keyArray[ 1 ];\n\t}\n\n\tif ( keyArray?.[ 0 ] === 'elements' ) {\n\t\treturn translationMap[ keyArray[ 1 ] ] || keyArray[ 1 ];\n\t}\n\n\treturn undefined;\n}\n\n/**\n * A deep comparison of two objects, optimized for comparing global styles.\n * @param {Object} changedObject The changed object to compare.\n * @param {Object} originalObject The original object to compare against.\n * @param {string} parentPath A key/value pair object of block names and their rendered titles.\n * @return {string[]} An array of paths whose values have changed.\n */\nfunction deepCompare( changedObject, originalObject, parentPath = '' ) {\n\t// We have two non-object values to compare.\n\tif ( ! isObject( changedObject ) && ! isObject( originalObject ) ) {\n\t\t/*\n\t\t * Only return a path if the value has changed.\n\t\t * And then only the path name up to 2 levels deep.\n\t\t */\n\t\treturn changedObject !== originalObject\n\t\t\t? parentPath.split( '.' ).slice( 0, 2 ).join( '.' )\n\t\t\t: undefined;\n\t}\n\n\t// Enable comparison when an object doesn't have a corresponding property to compare.\n\tchangedObject = isObject( changedObject ) ? changedObject : {};\n\toriginalObject = isObject( originalObject ) ? originalObject : {};\n\n\tconst allKeys = new Set( [\n\t\t...Object.keys( changedObject ),\n\t\t...Object.keys( originalObject ),\n\t] );\n\n\tlet diffs = [];\n\tfor ( const key of allKeys ) {\n\t\tconst path = parentPath ? parentPath + '.' + key : key;\n\t\tconst changedPath = deepCompare(\n\t\t\tchangedObject[ key ],\n\t\t\toriginalObject[ key ],\n\t\t\tpath\n\t\t);\n\t\tif ( changedPath ) {\n\t\t\tdiffs = diffs.concat( changedPath );\n\t\t}\n\t}\n\treturn diffs;\n}\n\n/**\n * Returns an array of translated summarized global styles changes.\n * Results are cached using a Map() key of `JSON.stringify( { next, previous } )`.\n *\n * @param {Object} next The changed object to compare.\n * @param {Object} previous The original object to compare against.\n * @return {Array[]} A 2-dimensional array of tuples: [ \"group\", \"translated change\" ].\n */\nexport function getGlobalStylesChangelist( next, previous ) {\n\tconst cacheKey = JSON.stringify( { next, previous } );\n\n\tif ( globalStylesChangesCache.has( cacheKey ) ) {\n\t\treturn globalStylesChangesCache.get( cacheKey );\n\t}\n\n\t/*\n\t * Compare the two changesets with normalized keys.\n\t * The order of these keys determines the order in which\n\t * they'll appear in the results.\n\t */\n\tconst changedValueTree = deepCompare(\n\t\t{\n\t\t\tstyles: {\n\t\t\t\tbackground: next?.styles?.background,\n\t\t\t\tcolor: next?.styles?.color,\n\t\t\t\ttypography: next?.styles?.typography,\n\t\t\t\tspacing: next?.styles?.spacing,\n\t\t\t},\n\t\t\tblocks: next?.styles?.blocks,\n\t\t\telements: next?.styles?.elements,\n\t\t\tsettings: next?.settings,\n\t\t},\n\t\t{\n\t\t\tstyles: {\n\t\t\t\tbackground: previous?.styles?.background,\n\t\t\t\tcolor: previous?.styles?.color,\n\t\t\t\ttypography: previous?.styles?.typography,\n\t\t\t\tspacing: previous?.styles?.spacing,\n\t\t\t},\n\t\t\tblocks: previous?.styles?.blocks,\n\t\t\telements: previous?.styles?.elements,\n\t\t\tsettings: previous?.settings,\n\t\t}\n\t);\n\n\tif ( ! changedValueTree.length ) {\n\t\tglobalStylesChangesCache.set( cacheKey, EMPTY_ARRAY );\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\t// Remove duplicate results.\n\tconst result = [ ...new Set( changedValueTree ) ]\n\t\t/*\n\t\t * Translate the keys.\n\t\t * Remove empty translations.\n\t\t */\n\t\t.reduce( ( acc, curr ) => {\n\t\t\tconst translation = getTranslation( curr );\n\t\t\tif ( translation ) {\n\t\t\t\tacc.push( [ curr.split( '.' )[ 0 ], translation ] );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\tglobalStylesChangesCache.set( cacheKey, result );\n\n\treturn result;\n}\n\n/**\n * From a getGlobalStylesChangelist() result, returns an array of translated global styles changes, grouped by type.\n * The types are 'blocks', 'elements', 'settings', and 'styles'.\n *\n * @param {Object} next The changed object to compare.\n * @param {Object} previous The original object to compare against.\n * @param {{maxResults:number}} options Options. maxResults: results to return before truncating.\n * @return {string[]} An array of translated changes.\n */\nexport default function getGlobalStylesChanges( next, previous, options = {} ) {\n\tlet changeList = getGlobalStylesChangelist( next, previous );\n\tconst changesLength = changeList.length;\n\tconst { maxResults } = options;\n\n\tif ( changesLength ) {\n\t\t// Truncate to `n` results if necessary.\n\t\tif ( !! maxResults && changesLength > maxResults ) {\n\t\t\tchangeList = changeList.slice( 0, maxResults );\n\t\t}\n\t\treturn Object.entries(\n\t\t\tchangeList.reduce( ( acc, curr ) => {\n\t\t\t\tconst group = acc[ curr[ 0 ] ] || [];\n\t\t\t\tif ( ! group.includes( curr[ 1 ] ) ) {\n\t\t\t\t\tacc[ curr[ 0 ] ] = [ ...group, curr[ 1 ] ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} )\n\t\t).map( ( [ key, changeValues ] ) => {\n\t\t\tconst changeValuesLength = changeValues.length;\n\t\t\tconst joinedChangesValue = changeValues.join(\n\t\t\t\t/* translators: Used between list items, there is a space after the comma. */\n\t\t\t\t__( ', ' ) // eslint-disable-line @wordpress/i18n-no-flanking-whitespace\n\t\t\t);\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of block names separated by a comma.\n\t\t\t\t\t\t_n( '%s block.', '%s blocks.', changeValuesLength ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase 'elements': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of element names separated by a comma.\n\t\t\t\t\t\t_n( '%s element.', '%s elements.', changeValuesLength ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase 'settings': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of theme.json setting labels separated by a comma.\n\t\t\t\t\t\t__( '%s settings.' ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase 'styles': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of theme.json top-level styles labels separated by a comma.\n\t\t\t\t\t\t__( '%s styles.' ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of global styles changes separated by a comma.\n\t\t\t\t\t\t__( '%s.' ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\treturn EMPTY_ARRAY;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA,MAAMG,wBAAwB,GAAG,IAAIC,GAAG,CAAC,CAAC;AAC1C,MAAMC,WAAW,GAAG,EAAE;AACtB,MAAMC,cAAc,GAAG;EACtBC,OAAO,EAAE,IAAAC,QAAE,EAAE,SAAU,CAAC;EACxBC,IAAI,EAAE,IAAAD,QAAE,EAAE,MAAO,CAAC;EAClBE,MAAM,EAAE,IAAAF,QAAE,EAAE,QAAS,CAAC;EACtBG,OAAO,EAAE,IAAAH,QAAE,EAAE,SAAU,CAAC;EACxBI,EAAE,EAAE,IAAAJ,QAAE,EAAE,IAAK,CAAC;EACdK,EAAE,EAAE,IAAAL,QAAE,EAAE,IAAK,CAAC;EACdM,EAAE,EAAE,IAAAN,QAAE,EAAE,IAAK,CAAC;EACdO,EAAE,EAAE,IAAAP,QAAE,EAAE,IAAK,CAAC;EACdQ,EAAE,EAAE,IAAAR,QAAE,EAAE,IAAK,CAAC;EACdS,EAAE,EAAE,IAAAT,QAAE,EAAE,I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AC,CAAG,CAAC,EAAG;QACpCD,GAAG,CAAEC,IAAI,CAAE,CAAC,CAAE,CAAE,GAAG,CAAE,GAAGS,KAAK,EAAET,IAAI,CAAE,CAAC,CAAE,CAAE;MAC3C;MACA,OAAOD,GAAG;IACX,CAAC,EAAE,CAAC,CAAE,CACP,CAAC,CAACY,GAAG,CAAE,CAAE,CAAEnD,GAAG,EAAEoD,YAAY,CAAE,KAAM;MACnC,MAAMC,kBAAkB,GAAGD,YAAY,CAAChB,MAAM;MAC9C,MAAMkB,kBAAkB,GAAGF,YAAY,CAAC1C,IAAI,CAC3C;MACA,IAAA9B,QAAE,EAAE,IAAK,CAAC,CAAC;MACZ,CAAC;MACD,QAASoB,GAAG;QACX,KAAK,QAAQ;UAAE;YACd,OAAO,IAAAuD,aAAO;YACb;YACA,IAAAC,QAAE,EAAE,WAAW,EAAE,YAAY,EAAEH,kBAAmB,CAAC,EACnDC,kBACD,CAAC;UACF;QACA,KAAK,UAAU;UAAE;YAChB,OAAO,IAAAC,aAAO;YACb;YACA,IAAAC,QAAE,EAAE,aAAa,EAAE,cAAc,EAAEH,kBAAmB,CAAC,EACvDC,kBACD,CAAC;UACF;QACA,KAAK,UAAU;UAAE;YAChB,OAAO,IAAAC,aAAO;YACb;YACA,IAAA3E,QAAE,EAAE,cAAe,CAAC,EACpB0E,kBACD,CAAC;UACF;QACA,KAAK,QAAQ;UAAE;YACd,OAAO,IAAAC,aAAO;YACb;YACA,IAAA3E,QAAE,EAAE,YAAa,CAAC,EAClB0E,kBACD,CAAC;UACF;QACA;UAAS;YACR,OAAO,IAAAC,aAAO;YACb;YACA,IAAA3E,QAAE,EAAE,KAAM,CAAC,EACX0E,kBACD,CAAC;UACF;MACD;IACD,CAAE,CAAC;EACJ;EAEA,OAAO7E,WAAW;AACnB","ignoreList":[]}
1
+ {"version":3,"names":["_memize","_interopRequireDefault","require","_i18n","_blocks","globalStylesChangesCache","Map","EMPTY_ARRAY","translationMap","caption","__","link","button","heading","h1","h2","h3","h4","h5","h6","getBlockNames","memoize","getBlockTypes","reduce","accumulator","name","title","isObject","obj","getTranslation","key","keyArray","split","blockName","undefined","deepCompare","changedObject","originalObject","parentPath","slice","join","allKeys","Set","Object","keys","diffs","path","changedPath","concat","getGlobalStylesChangelist","next","previous","cacheKey","JSON","stringify","has","get","changedValueTree","styles","background","color","typography","spacing","blocks","elements","settings","length","set","result","acc","curr","translation","push","getGlobalStylesChanges","options","changeList","changesLength","maxResults","entries","group","includes","map","changeValues","changeValuesLength","joinedChangesValue","sprintf","_n"],"sources":["@wordpress/block-editor/src/components/global-styles/get-global-styles-changes.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n/**\n * WordPress dependencies\n */\nimport { __, _n, sprintf } from '@wordpress/i18n';\nimport { getBlockTypes } from '@wordpress/blocks';\n\nconst globalStylesChangesCache = new Map();\nconst EMPTY_ARRAY = [];\nconst translationMap = {\n\tcaption: __( 'Caption' ),\n\tlink: __( 'Link' ),\n\tbutton: __( 'Button' ),\n\theading: __( 'Heading' ),\n\th1: __( 'H1' ),\n\th2: __( 'H2' ),\n\th3: __( 'H3' ),\n\th4: __( 'H4' ),\n\th5: __( 'H5' ),\n\th6: __( 'H6' ),\n\t'settings.color': __( 'Color' ),\n\t'settings.typography': __( 'Typography' ),\n\t'styles.color': __( 'Colors' ),\n\t'styles.spacing': __( 'Spacing' ),\n\t'styles.background': __( 'Background' ),\n\t'styles.typography': __( 'Typography' ),\n};\nconst getBlockNames = memoize( () =>\n\tgetBlockTypes().reduce( ( accumulator, { name, title } ) => {\n\t\taccumulator[ name ] = title;\n\t\treturn accumulator;\n\t}, {} )\n);\nconst isObject = ( obj ) => obj !== null && typeof obj === 'object';\n\n/**\n * Get the translation for a given global styles key.\n * @param {string} key A key representing a path to a global style property or setting.\n * @return {string|undefined} A translated key or undefined if no translation exists.\n */\nfunction getTranslation( key ) {\n\tif ( translationMap[ key ] ) {\n\t\treturn translationMap[ key ];\n\t}\n\n\tconst keyArray = key.split( '.' );\n\n\tif ( keyArray?.[ 0 ] === 'blocks' ) {\n\t\tconst blockName = getBlockNames()?.[ keyArray[ 1 ] ];\n\t\treturn blockName || keyArray[ 1 ];\n\t}\n\n\tif ( keyArray?.[ 0 ] === 'elements' ) {\n\t\treturn translationMap[ keyArray[ 1 ] ] || keyArray[ 1 ];\n\t}\n\n\treturn undefined;\n}\n\n/**\n * A deep comparison of two objects, optimized for comparing global styles.\n * @param {Object} changedObject The changed object to compare.\n * @param {Object} originalObject The original object to compare against.\n * @param {string} parentPath A key/value pair object of block names and their rendered titles.\n * @return {string[]} An array of paths whose values have changed.\n */\nfunction deepCompare( changedObject, originalObject, parentPath = '' ) {\n\t// We have two non-object values to compare.\n\tif ( ! isObject( changedObject ) && ! isObject( originalObject ) ) {\n\t\t/*\n\t\t * Only return a path if the value has changed.\n\t\t * And then only the path name up to 2 levels deep.\n\t\t */\n\t\treturn changedObject !== originalObject\n\t\t\t? parentPath.split( '.' ).slice( 0, 2 ).join( '.' )\n\t\t\t: undefined;\n\t}\n\n\t// Enable comparison when an object doesn't have a corresponding property to compare.\n\tchangedObject = isObject( changedObject ) ? changedObject : {};\n\toriginalObject = isObject( originalObject ) ? originalObject : {};\n\n\tconst allKeys = new Set( [\n\t\t...Object.keys( changedObject ),\n\t\t...Object.keys( originalObject ),\n\t] );\n\n\tlet diffs = [];\n\tfor ( const key of allKeys ) {\n\t\tconst path = parentPath ? parentPath + '.' + key : key;\n\t\tconst changedPath = deepCompare(\n\t\t\tchangedObject[ key ],\n\t\t\toriginalObject[ key ],\n\t\t\tpath\n\t\t);\n\t\tif ( changedPath ) {\n\t\t\tdiffs = diffs.concat( changedPath );\n\t\t}\n\t}\n\treturn diffs;\n}\n\n/**\n * Returns an array of translated summarized global styles changes.\n * Results are cached using a Map() key of `JSON.stringify( { next, previous } )`.\n *\n * @param {Object} next The changed object to compare.\n * @param {Object} previous The original object to compare against.\n * @return {Array[]} A 2-dimensional array of tuples: [ \"group\", \"translated change\" ].\n */\nexport function getGlobalStylesChangelist( next, previous ) {\n\tconst cacheKey = JSON.stringify( { next, previous } );\n\n\tif ( globalStylesChangesCache.has( cacheKey ) ) {\n\t\treturn globalStylesChangesCache.get( cacheKey );\n\t}\n\n\t/*\n\t * Compare the two changesets with normalized keys.\n\t * The order of these keys determines the order in which\n\t * they'll appear in the results.\n\t */\n\tconst changedValueTree = deepCompare(\n\t\t{\n\t\t\tstyles: {\n\t\t\t\tbackground: next?.styles?.background,\n\t\t\t\tcolor: next?.styles?.color,\n\t\t\t\ttypography: next?.styles?.typography,\n\t\t\t\tspacing: next?.styles?.spacing,\n\t\t\t},\n\t\t\tblocks: next?.styles?.blocks,\n\t\t\telements: next?.styles?.elements,\n\t\t\tsettings: next?.settings,\n\t\t},\n\t\t{\n\t\t\tstyles: {\n\t\t\t\tbackground: previous?.styles?.background,\n\t\t\t\tcolor: previous?.styles?.color,\n\t\t\t\ttypography: previous?.styles?.typography,\n\t\t\t\tspacing: previous?.styles?.spacing,\n\t\t\t},\n\t\t\tblocks: previous?.styles?.blocks,\n\t\t\telements: previous?.styles?.elements,\n\t\t\tsettings: previous?.settings,\n\t\t}\n\t);\n\n\tif ( ! changedValueTree.length ) {\n\t\tglobalStylesChangesCache.set( cacheKey, EMPTY_ARRAY );\n\t\treturn EMPTY_ARRAY;\n\t}\n\n\t// Remove duplicate results.\n\tconst result = [ ...new Set( changedValueTree ) ]\n\t\t/*\n\t\t * Translate the keys.\n\t\t * Remove empty translations.\n\t\t */\n\t\t.reduce( ( acc, curr ) => {\n\t\t\tconst translation = getTranslation( curr );\n\t\t\tif ( translation ) {\n\t\t\t\tacc.push( [ curr.split( '.' )[ 0 ], translation ] );\n\t\t\t}\n\t\t\treturn acc;\n\t\t}, [] );\n\n\tglobalStylesChangesCache.set( cacheKey, result );\n\n\treturn result;\n}\n\n/**\n * From a getGlobalStylesChangelist() result, returns an array of translated global styles changes, grouped by type.\n * The types are 'blocks', 'elements', 'settings', and 'styles'.\n *\n * @param {Object} next The changed object to compare.\n * @param {Object} previous The original object to compare against.\n * @param {{maxResults:number}} options Options. maxResults: results to return before truncating.\n * @return {string[]} An array of translated changes.\n */\nexport default function getGlobalStylesChanges( next, previous, options = {} ) {\n\tlet changeList = getGlobalStylesChangelist( next, previous );\n\tconst changesLength = changeList.length;\n\tconst { maxResults } = options;\n\n\tif ( changesLength ) {\n\t\t// Truncate to `n` results if necessary.\n\t\tif ( !! maxResults && changesLength > maxResults ) {\n\t\t\tchangeList = changeList.slice( 0, maxResults );\n\t\t}\n\t\treturn Object.entries(\n\t\t\tchangeList.reduce( ( acc, curr ) => {\n\t\t\t\tconst group = acc[ curr[ 0 ] ] || [];\n\t\t\t\tif ( ! group.includes( curr[ 1 ] ) ) {\n\t\t\t\t\tacc[ curr[ 0 ] ] = [ ...group, curr[ 1 ] ];\n\t\t\t\t}\n\t\t\t\treturn acc;\n\t\t\t}, {} )\n\t\t).map( ( [ key, changeValues ] ) => {\n\t\t\tconst changeValuesLength = changeValues.length;\n\t\t\tconst joinedChangesValue = changeValues.join(\n\t\t\t\t/* translators: Used between list items, there is a space after the comma. */\n\t\t\t\t__( ', ' ) // eslint-disable-line @wordpress/i18n-no-flanking-whitespace\n\t\t\t);\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of block names separated by a comma.\n\t\t\t\t\t\t_n( '%s block.', '%s blocks.', changeValuesLength ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase 'elements': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of element names separated by a comma.\n\t\t\t\t\t\t_n( '%s element.', '%s elements.', changeValuesLength ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase 'settings': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of theme.json setting labels separated by a comma.\n\t\t\t\t\t\t__( '%s settings.' ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcase 'styles': {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of theme.json top-level styles labels separated by a comma.\n\t\t\t\t\t\t__( '%s styles.' ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn sprintf(\n\t\t\t\t\t\t// translators: %s: a list of global styles changes separated by a comma.\n\t\t\t\t\t\t__( '%s.' ),\n\t\t\t\t\t\tjoinedChangesValue\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\treturn EMPTY_ARRAY;\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA,MAAMG,wBAAwB,GAAG,IAAIC,GAAG,CAAC,CAAC;AAC1C,MAAMC,WAAW,GAAG,EAAE;AACtB,MAAMC,cAAc,GAAG;EACtBC,OAAO,EAAE,IAAAC,QAAE,EAAE,SAAU,CAAC;EACxBC,IAAI,EAAE,IAAAD,QAAE,EAAE,MAAO,CAAC;EAClBE,MAAM,EAAE,IAAAF,QAAE,EAAE,QAAS,CAAC;EACtBG,OAAO,EAAE,IAAAH,QAAE,EAAE,SAAU,CAAC;EACxBI,EAAE,EAAE,IAAAJ,QAAE,EAAE,IAAK,CAAC;EACdK,EAAE,EAAE,IAAAL,QAAE,EAAE,IAAK,CAAC;EACdM,EAAE,EAAE,IAAAN,QAAE,EAAE,IAAK,CAAC;EACdO,EAAE,EAAE,IAAAP,QAAE,EAAE,IAAK,CAAC;EACdQ,EAAE,EAAE,IAAAR,QAAE,EAAE,IAAK,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* @typedef {Object} TransitionState
15
- * @property {number} scaleValue Scale of the canvas.
16
- * @property {number} frameSize Size of the frame/offset around the canvas.
17
- * @property {number} clientHeight ClientHeight of the iframe.
18
- * @property {number} scrollTop ScrollTop of the iframe.
19
- * @property {number} scrollHeight ScrollHeight of the iframe.
15
+ * @property {number} scaleValue Scale of the canvas.
16
+ * @property {number} frameSize Size of the frame/offset around the canvas.
17
+ * @property {number} containerHeight containerHeight of the iframe.
18
+ * @property {number} scrollTop ScrollTop of the iframe.
19
+ * @property {number} scrollHeight ScrollHeight of the iframe.
20
20
  */
21
21
 
22
22
  /**
@@ -38,6 +38,25 @@ function calculateScale({
38
38
  return (Math.min(containerWidth, maxContainerWidth) - frameSize * 2) / scaleContainerWidth;
39
39
  }
40
40
 
41
+ /**
42
+ * Compute the next scrollHeight based on the transition states.
43
+ *
44
+ * @param {TransitionState} transitionFrom Starting point of the transition
45
+ * @param {TransitionState} transitionTo Ending state of the transition
46
+ * @return {number} Next scrollHeight based on scale and frame value changes.
47
+ */
48
+ function computeScrollHeightNext(transitionFrom, transitionTo) {
49
+ const {
50
+ scaleValue: prevScale,
51
+ scrollHeight: prevScrollHeight
52
+ } = transitionFrom;
53
+ const {
54
+ frameSize,
55
+ scaleValue
56
+ } = transitionTo;
57
+ return prevScrollHeight * (scaleValue / prevScale) + frameSize * 2;
58
+ }
59
+
41
60
  /**
42
61
  * Compute the next scrollTop position after scaling the iframe content.
43
62
  *
@@ -47,37 +66,37 @@ function calculateScale({
47
66
  */
48
67
  function computeScrollTopNext(transitionFrom, transitionTo) {
49
68
  const {
50
- clientHeight: prevClientHeight,
69
+ containerHeight: prevContainerHeight,
51
70
  frameSize: prevFrameSize,
52
71
  scaleValue: prevScale,
53
- scrollTop,
54
- scrollHeight
72
+ scrollTop: prevScrollTop
55
73
  } = transitionFrom;
56
74
  const {
57
- clientHeight,
75
+ containerHeight,
58
76
  frameSize,
59
- scaleValue
77
+ scaleValue,
78
+ scrollHeight
60
79
  } = transitionTo;
61
80
  // Step 0: Start with the current scrollTop.
62
- let scrollTopNext = scrollTop;
81
+ let scrollTopNext = prevScrollTop;
63
82
  // Step 1: Undo the effects of the previous scale and frame around the
64
83
  // midpoint of the visible area.
65
- scrollTopNext = (scrollTopNext + prevClientHeight / 2 - prevFrameSize) / prevScale - prevClientHeight / 2;
84
+ scrollTopNext = (scrollTopNext + prevContainerHeight / 2 - prevFrameSize) / prevScale - prevContainerHeight / 2;
66
85
 
67
86
  // Step 2: Apply the new scale and frame around the midpoint of the
68
87
  // visible area.
69
- scrollTopNext = (scrollTopNext + clientHeight / 2) * scaleValue + frameSize - clientHeight / 2;
88
+ scrollTopNext = (scrollTopNext + containerHeight / 2) * scaleValue + frameSize - containerHeight / 2;
70
89
 
71
90
  // Step 3: Handle an edge case so that you scroll to the top of the
72
91
  // iframe if the top of the iframe content is visible in the container.
73
92
  // The same edge case for the bottom is skipped because changing content
74
93
  // makes calculating it impossible.
75
- scrollTopNext = scrollTop <= prevFrameSize ? 0 : scrollTopNext;
94
+ scrollTopNext = prevScrollTop <= prevFrameSize ? 0 : scrollTopNext;
76
95
 
77
96
  // This is the scrollTop value if you are scrolled to the bottom of the
78
97
  // iframe. We can't just let the browser handle it because we need to
79
98
  // animate the scaling.
80
- const maxScrollTop = scrollHeight * (scaleValue / prevScale) + frameSize * 2 - clientHeight;
99
+ const maxScrollTop = scrollHeight - containerHeight;
81
100
 
82
101
  // Step 4: Clamp the scrollTopNext between the minimum and maximum
83
102
  // possible scrollTop positions. Round the value to avoid subpixel
@@ -145,7 +164,8 @@ function useScaleCanvas({
145
164
  height: contentHeight
146
165
  }] = (0, _compose.useResizeObserver)();
147
166
  const [containerResizeListener, {
148
- width: containerWidth
167
+ width: containerWidth,
168
+ height: containerHeight
149
169
  }] = (0, _compose.useResizeObserver)();
150
170
  const initialContainerWidthRef = (0, _element.useRef)(0);
151
171
  const isZoomedOut = scale !== 1;
@@ -176,7 +196,7 @@ function useScaleCanvas({
176
196
  const transitionFromRef = (0, _element.useRef)({
177
197
  scaleValue,
178
198
  frameSize,
179
- clientHeight: 0,
199
+ containerHeight: 0,
180
200
  scrollTop: 0,
181
201
  scrollHeight: 0
182
202
  });
@@ -188,7 +208,7 @@ function useScaleCanvas({
188
208
  const transitionToRef = (0, _element.useRef)({
189
209
  scaleValue,
190
210
  frameSize,
191
- clientHeight: 0,
211
+ containerHeight: 0,
192
212
  scrollTop: 0,
193
213
  scrollHeight: 0
194
214
  });
@@ -208,6 +228,9 @@ function useScaleCanvas({
208
228
  } = transitionToRef.current;
209
229
  iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scroll-top', `${scrollTop}px`);
210
230
  iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scroll-top-next', `${scrollTopNext}px`);
231
+
232
+ // If the container has a scrolllbar, force a scrollbar to prevent the content from shifting while animating.
233
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-overflow-behavior', transitionFromRef.current.scrollHeight === transitionFromRef.current.containerHeight ? 'auto' : 'scroll');
211
234
  iframeDocument.documentElement.classList.add('zoom-out-animation');
212
235
  return iframeDocument.documentElement.animate(getAnimationKeyframes(transitionFromRef.current, transitionToRef.current), {
213
236
  easing: 'cubic-bezier(0.46, 0.03, 0.52, 0.96)',
@@ -240,10 +263,12 @@ function useScaleCanvas({
240
263
  iframeDocument.documentElement.scrollTop = transitionToRef.current.scrollTop;
241
264
  iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scroll-top');
242
265
  iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scroll-top-next');
266
+ iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-overflow-behavior');
243
267
 
244
268
  // Update previous values.
245
269
  transitionFromRef.current = transitionToRef.current;
246
270
  }, [iframeDocument]);
271
+ const previousIsZoomedOut = (0, _element.useRef)(false);
247
272
 
248
273
  /**
249
274
  * Runs when zoom out mode is toggled, and sets the startAnimation flag
@@ -252,13 +277,16 @@ function useScaleCanvas({
252
277
  * changes due to the container resizing.
253
278
  */
254
279
  (0, _element.useEffect)(() => {
255
- if (!iframeDocument) {
280
+ const trigger = iframeDocument && previousIsZoomedOut.current !== isZoomedOut;
281
+ previousIsZoomedOut.current = isZoomedOut;
282
+ if (!trigger) {
256
283
  return;
257
284
  }
258
- if (isZoomedOut) {
259
- iframeDocument.documentElement.classList.add('is-zoomed-out');
260
- }
261
285
  startAnimationRef.current = true;
286
+ if (!isZoomedOut) {
287
+ return;
288
+ }
289
+ iframeDocument.documentElement.classList.add('is-zoomed-out');
262
290
  return () => {
263
291
  iframeDocument.documentElement.classList.remove('is-zoomed-out');
264
292
  };
@@ -286,20 +314,20 @@ function useScaleCanvas({
286
314
  scaleContainerWidth: containerWidth
287
315
  });
288
316
  }
289
-
290
- // If we are not going to animate the transition, set the scale and frame size directly.
291
- // If we are animating, these values will be set when the animation is finished.
292
- // Example: Opening sidebars that reduce the scale of the canvas, but we don't want to
293
- // animate the transition.
294
- if (!startAnimationRef.current) {
295
- iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale', scaleValue);
296
- iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-frame-size', `${frameSize}px`);
317
+ if (scaleValue < 1) {
318
+ // If we are not going to animate the transition, set the scale and frame size directly.
319
+ // If we are animating, these values will be set when the animation is finished.
320
+ // Example: Opening sidebars that reduce the scale of the canvas, but we don't want to
321
+ // animate the transition.
322
+ if (!startAnimationRef.current) {
323
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale', scaleValue);
324
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-frame-size', `${frameSize}px`);
325
+ }
326
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-content-height', `${contentHeight}px`);
327
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-inner-height', `${containerHeight}px`);
328
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-container-width', `${containerWidth}px`);
329
+ iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale-container-width', `${scaleContainerWidth}px`);
297
330
  }
298
- iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-content-height', `${contentHeight}px`);
299
- const clientHeight = iframeDocument.documentElement.clientHeight;
300
- iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-inner-height', `${clientHeight}px`);
301
- iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-container-width', `${containerWidth}px`);
302
- iframeDocument.documentElement.style.setProperty('--wp-block-editor-iframe-zoom-out-scale-container-width', `${scaleContainerWidth}px`);
303
331
 
304
332
  /**
305
333
  * Handle the zoom out animation:
@@ -328,7 +356,6 @@ function useScaleCanvas({
328
356
  transitionFromRef.current = tempTransitionTo;
329
357
  transitionToRef.current = tempTransitionFrom;
330
358
  } else {
331
- var _transitionFromRef$cu;
332
359
  /**
333
360
  * Start a new zoom animation.
334
361
  */
@@ -339,14 +366,16 @@ function useScaleCanvas({
339
366
  // the iframe at this point when we're about to animate the zoom out.
340
367
  // The iframe scrollTop, scrollHeight, and clientHeight will all be
341
368
  // the most accurate.
342
- transitionFromRef.current.clientHeight = (_transitionFromRef$cu = transitionFromRef.current.clientHeight) !== null && _transitionFromRef$cu !== void 0 ? _transitionFromRef$cu : clientHeight;
343
369
  transitionFromRef.current.scrollTop = iframeDocument.documentElement.scrollTop;
344
370
  transitionFromRef.current.scrollHeight = iframeDocument.documentElement.scrollHeight;
371
+ // Use containerHeight, as it's the previous container height before the zoom out animation starts.
372
+ transitionFromRef.current.containerHeight = containerHeight;
345
373
  transitionToRef.current = {
346
374
  scaleValue,
347
375
  frameSize,
348
- clientHeight
376
+ containerHeight: iframeDocument.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.
349
377
  };
378
+ transitionToRef.current.scrollHeight = computeScrollHeightNext(transitionFromRef.current, transitionToRef.current);
350
379
  transitionToRef.current.scrollTop = computeScrollTopNext(transitionFromRef.current, transitionToRef.current);
351
380
  animationRef.current = startZoomOutAnimation();
352
381
 
@@ -358,15 +387,7 @@ function useScaleCanvas({
358
387
  }
359
388
  }
360
389
  }
361
- return () => {
362
- iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scale');
363
- iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-frame-size');
364
- iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-content-height');
365
- iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-inner-height');
366
- iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-container-width');
367
- iframeDocument.documentElement.style.removeProperty('--wp-block-editor-iframe-zoom-out-scale-container-width');
368
- };
369
- }, [startZoomOutAnimation, finishZoomOutAnimation, prefersReducedMotion, isAutoScaled, scaleValue, frameSize, iframeDocument, contentHeight, containerWidth, maxContainerWidth, scaleContainerWidth]);
390
+ }, [startZoomOutAnimation, finishZoomOutAnimation, prefersReducedMotion, isAutoScaled, scaleValue, frameSize, iframeDocument, contentHeight, containerWidth, containerHeight, maxContainerWidth, scaleContainerWidth]);
370
391
  return {
371
392
  isZoomedOut,
372
393
  scaleContainerWidth,
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_compose","calculateScale","frameSize","containerWidth","maxContainerWidth","scaleContainerWidth","Math","min","computeScrollTopNext","transitionFrom","transitionTo","clientHeight","prevClientHeight","prevFrameSize","scaleValue","prevScale","scrollTop","scrollHeight","scrollTopNext","maxScrollTop","round","max","getAnimationKeyframes","translate","scale","paddingTop","paddingBottom","useScaleCanvas","iframeDocument","contentResizeListener","height","contentHeight","useResizeObserver","containerResizeListener","width","initialContainerWidthRef","useRef","isZoomedOut","prefersReducedMotion","useReducedMotion","isAutoScaled","startAnimationRef","animationRef","useEffect","current","transitionFromRef","transitionToRef","startZoomOutAnimation","useCallback","documentElement","style","setProperty","classList","add","animate","easing","duration","finishZoomOutAnimation","remove","removeProperty","reverse","tempTransitionFrom","tempTransitionTo","_transitionFromRef$cu","onfinish"],"sources":["@wordpress/block-editor/src/components/iframe/use-scale-canvas.js"],"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} clientHeight ClientHeight 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 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\tclientHeight: prevClientHeight,\n\t\tframeSize: prevFrameSize,\n\t\tscaleValue: prevScale,\n\t\tscrollTop,\n\t\tscrollHeight,\n\t} = transitionFrom;\n\tconst { clientHeight, frameSize, scaleValue } = transitionTo;\n\t// Step 0: Start with the current scrollTop.\n\tlet scrollTopNext = scrollTop;\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 + prevClientHeight / 2 - prevFrameSize ) / prevScale -\n\t\tprevClientHeight / 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 + clientHeight / 2 ) * scaleValue +\n\t\tframeSize -\n\t\tclientHeight / 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 = scrollTop <= 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 =\n\t\tscrollHeight * ( scaleValue / prevScale ) +\n\t\tframeSize * 2 -\n\t\tclientHeight;\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 [ containerResizeListener, { width: containerWidth } ] =\n\t\tuseResizeObserver();\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 {import('react').RefObject<TransitionState>}\n\t */\n\tconst transitionFromRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tclientHeight: 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 {import('react').RefObject<TransitionState>}\n\t */\n\tconst transitionToRef = useRef( {\n\t\tscaleValue,\n\t\tframeSize,\n\t\tclientHeight: 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\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\t// Set the final scroll position that was just animated to.\n\t\t// Disable reason: Eslint isn't smart enough to know that this is a\n\t\t// DOM element. https://github.com/facebook/react/issues/31483\n\t\t// eslint-disable-next-line react-compiler/react-compiler\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\n\t\t// Update previous values.\n\t\ttransitionFromRef.current = transitionToRef.current;\n\t}, [ iframeDocument ] );\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\tif ( ! iframeDocument ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isZoomedOut ) {\n\t\t\tiframeDocument.documentElement.classList.add( 'is-zoomed-out' );\n\t\t}\n\n\t\tstartAnimationRef.current = true;\n\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\t// If we are not going to animate the transition, set the scale and frame size directly.\n\t\t// If we are animating, these values will be set when the animation is finished.\n\t\t// Example: Opening sidebars that reduce the scale of the canvas, but we don't want to\n\t\t// animate the transition.\n\t\tif ( ! startAnimationRef.current ) {\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale',\n\t\t\t\tscaleValue\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size',\n\t\t\t\t`${ frameSize }px`\n\t\t\t);\n\t\t}\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-content-height',\n\t\t\t`${ contentHeight }px`\n\t\t);\n\n\t\tconst clientHeight = iframeDocument.documentElement.clientHeight;\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height',\n\t\t\t`${ clientHeight }px`\n\t\t);\n\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-container-width',\n\t\t\t`${ containerWidth }px`\n\t\t);\n\t\tiframeDocument.documentElement.style.setProperty(\n\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width',\n\t\t\t`${ scaleContainerWidth }px`\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.clientHeight =\n\t\t\t\t\ttransitionFromRef.current.clientHeight ?? clientHeight;\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\n\t\t\t\ttransitionToRef.current = {\n\t\t\t\t\tscaleValue,\n\t\t\t\t\tframeSize,\n\t\t\t\t\tclientHeight,\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\n\t\treturn () => {\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-frame-size'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-content-height'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-inner-height'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-container-width'\n\t\t\t);\n\t\t\tiframeDocument.documentElement.style.removeProperty(\n\t\t\t\t'--wp-block-editor-iframe-zoom-out-scale-container-width'\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\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"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,cAAcA,CAAE;EACxBC,SAAS;EACTC,cAAc;EACdC,iBAAiB;EACjBC;AACD,CAAC,EAAG;EACH,OACC,CAAEC,IAAI,CAACC,GAAG,CAAEJ,cAAc,EAAEC,iBAAkB,CAAC,GAAGF,SAAS,GAAG,CAAC,IAC/DG,mBAAmB;AAErB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,oBAAoBA,CAAEC,cAAc,EAAEC,YAAY,EAAG;EAC7D,MAAM;IACLC,YAAY,EAAEC,gBAAgB;IAC9BV,SAAS,EAAEW,aAAa;IACxBC,UAAU,EAAEC,SAAS;IACrBC,SAAS;IACTC;EACD,CAAC,GAAGR,cAAc;EAClB,MAAM;IAAEE,YAAY;IAAET,SAAS;IAAEY;EAAW,CAAC,GAAGJ,YAAY;EAC5D;EACA,IAAIQ,aAAa,GAAGF,SAAS;EAC7B;EACA;EACAE,aAAa,GACZ,CAAEA,aAAa,GAAGN,gBAAgB,GAAG,CAAC,GAAGC,aAAa,IAAKE,SAAS,GACpEH,gBAAgB,GAAG,CAAC;;EAErB;EACA;EACAM,aAAa,GAC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Ac,CAClD,yDACD,CAAC;IACF,CAAC;EACF,CAAC,EAAE,CACFZ,qBAAqB,EACrBU,sBAAsB,EACtBnB,oBAAoB,EACpBE,YAAY,EACZ1B,UAAU,EACVZ,SAAS,EACT0B,cAAc,EACdG,aAAa,EACb5B,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,CAClB,CAAC;EAEH,OAAO;IACNgC,WAAW;IACXhC,mBAAmB;IACnBwB,qBAAqB;IACrBI;EACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_compose","calculateScale","frameSize","containerWidth","maxContainerWidth","scaleContainerWidth","Math","min","computeScrollHeightNext","transitionFrom","transitionTo","scaleValue","prevScale","scrollHeight","prevScrollHeight","computeScrollTopNext","containerHeight","prevContainerHeight","prevFrameSize","scrollTop","prevScrollTop","scrollTopNext","maxScrollTop","round","max","getAnimationKeyframes","translate","scale","paddingTop","paddingBottom","useScaleCanvas","iframeDocument","contentResizeListener","height","contentHeight","useResizeObserver","containerResizeListener","width","initialContainerWidthRef","useRef","isZoomedOut","prefersReducedMotion","useReducedMotion","isAutoScaled","startAnimationRef","animationRef","useEffect","current","transitionFromRef","transitionToRef","startZoomOutAnimation","useCallback","documentElement","style","setProperty","classList","add","animate","easing","duration","finishZoomOutAnimation","remove","removeProperty","previousIsZoomedOut","trigger","reverse","tempTransitionFrom","tempTransitionTo","clientHeight","onfinish"],"sources":["@wordpress/block-editor/src/components/iframe/use-scale-canvas.js"],"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 {import('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 {import('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\t// Set the final scroll position that was just animated to.\n\t\t// Disable reason: Eslint isn't smart enough to know that this is a\n\t\t// DOM element. https://github.com/facebook/react/issues/31483\n\t\t// eslint-disable-next-line react-compiler/react-compiler\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"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,cAAcA,CAAE;EACxBC,SAAS;EACTC,cAAc;EACdC,iBAAiB;EACjBC;AACD,CAAC,EAAG;EACH,OACC,CAAEC,IAAI,CAACC,GAAG,CAAEJ,cAAc,EAAEC,iBAAkB,CAAC,GAAGF,SAAS,GAAG,CAAC,IAC/DG,mBAAmB;AAErB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,uBAAuBA,CAAEC,cAAc,EAAEC,YAAY,EAAG;EAChE,MAAM;IAAEC,UAAU,EAAEC,SAAS;IAAEC,YAAY,EAAEC;EAAiB,CAAC,GAC9DL,cAAc;EACf,MAAM;IAAEP,SAAS;IAAES;EAAW,CAAC,GAAGD,YAAY;EAE9C,OAAOI,gBAAgB,IAAKH,UAAU,GAAGC,SAAS,CAAE,GAAGV,SAAS,GAAG,CAAC;AACrE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASa,oBAAoBA,CAAEN,cAAc,EAAEC,YAAY,EAAG;EAC7D,MAAM;IACLM,eAAe,EAAEC,mBAAmB;IACpCf,SAAS,EAAEgB,aAA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,CAAClC,YAAY,GAAGL,uBAAuB,CAC7DwC,iBAAiB,CAACD,OAAO,EACzBE,eAAe,CAACF,OACjB,CAAC;QACDE,eAAe,CAACF,OAAO,CAAC5B,SAAS,GAAGJ,oBAAoB,CACvDiC,iBAAiB,CAACD,OAAO,EACzBE,eAAe,CAACF,OACjB,CAAC;QAEDF,YAAY,CAACE,OAAO,GAAGG,qBAAqB,CAAC,CAAC;;QAE9C;QACA,IAAKT,oBAAoB,EAAG;UAC3BmB,sBAAsB,CAAC,CAAC;QACzB,CAAC,MAAM;UACNf,YAAY,CAACE,OAAO,CAACsB,QAAQ,GAAGT,sBAAsB;QACvD;MACD;IACD;EACD,CAAC,EAAE,CACFV,qBAAqB,EACrBU,sBAAsB,EACtBnB,oBAAoB,EACpBE,YAAY,EACZhC,UAAU,EACVT,SAAS,EACT6B,cAAc,EACdG,aAAa,EACb/B,cAAc,EACda,eAAe,EACfZ,iBAAiB,EACjBC,mBAAmB,CAClB,CAAC;EAEH,OAAO;IACNmC,WAAW;IACXnC,mBAAmB;IACnB2B,qBAAqB;IACrBI;EACD,CAAC;AACF","ignoreList":[]}
@@ -9,15 +9,12 @@ var _element = require("@wordpress/element");
9
9
  var _compose = require("@wordpress/compose");
10
10
  var _components = require("@wordpress/components");
11
11
  var _i18n = require("@wordpress/i18n");
12
- var _data = require("@wordpress/data");
13
12
  var _blockPatternsExplorer = _interopRequireDefault(require("../block-patterns-explorer"));
14
13
  var _mobileTabNavigation = _interopRequireDefault(require("../mobile-tab-navigation"));
15
14
  var _patternCategoryPreviews = require("./pattern-category-previews");
16
15
  var _usePatternCategories = require("./use-pattern-categories");
17
16
  var _categoryTabs = _interopRequireDefault(require("../category-tabs"));
18
17
  var _noResults = _interopRequireDefault(require("../no-results"));
19
- var _store = require("../../../store");
20
- var _lockUnlock = require("../../../lock-unlock");
21
18
  var _jsxRuntime = require("react/jsx-runtime");
22
19
  /**
23
20
  * WordPress dependencies
@@ -37,13 +34,6 @@ function BlockPatternsTab({
37
34
  const [showPatternsExplorer, setShowPatternsExplorer] = (0, _element.useState)(false);
38
35
  const categories = (0, _usePatternCategories.usePatternCategories)(rootClientId);
39
36
  const isMobile = (0, _compose.useViewportMatch)('medium', '<');
40
- const isResolvingPatterns = (0, _data.useSelect)(select => (0, _lockUnlock.unlock)(select(_store.store)).isResolvingPatterns(), []);
41
- if (isResolvingPatterns) {
42
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
43
- className: "block-editor-inserter__patterns-loading",
44
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Spinner, {})
45
- });
46
- }
47
37
  if (!categories.length) {
48
38
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_noResults.default, {});
49
39
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_compose","_components","_i18n","_data","_blockPatternsExplorer","_interopRequireDefault","_mobileTabNavigation","_patternCategoryPreviews","_usePatternCategories","_categoryTabs","_noResults","_store","_lockUnlock","_jsxRuntime","BlockPatternsTab","onSelectCategory","selectedCategory","onInsert","rootClientId","children","showPatternsExplorer","setShowPatternsExplorer","useState","categories","usePatternCategories","isMobile","useViewportMatch","isResolvingPatterns","useSelect","select","unlock","blockEditorStore","jsx","className","Spinner","length","default","jsxs","Fragment","Button","__next40pxDefaultSize","onClick","variant","__","category","PatternCategoryPreviews","name","initialCategory","patternCategories","onModalClose","_default","exports"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Button, Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport PatternsExplorerModal from '../block-patterns-explorer';\nimport MobileTabNavigation from '../mobile-tab-navigation';\nimport { PatternCategoryPreviews } from './pattern-category-previews';\nimport { usePatternCategories } from './use-pattern-categories';\nimport CategoryTabs from '../category-tabs';\nimport InserterNoResults from '../no-results';\nimport { store as blockEditorStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nfunction BlockPatternsTab( {\n\tonSelectCategory,\n\tselectedCategory,\n\tonInsert,\n\trootClientId,\n\tchildren,\n} ) {\n\tconst [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );\n\n\tconst categories = usePatternCategories( rootClientId );\n\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\tconst isResolvingPatterns = useSelect(\n\t\t( select ) =>\n\t\t\tunlock( select( blockEditorStore ) ).isResolvingPatterns(),\n\t\t[]\n\t);\n\n\tif ( isResolvingPatterns ) {\n\t\treturn (\n\t\t\t<div className=\"block-editor-inserter__patterns-loading\">\n\t\t\t\t<Spinner />\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( ! categories.length ) {\n\t\treturn <InserterNoResults />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className=\"block-editor-inserter__block-patterns-tabs-container\">\n\t\t\t\t\t<CategoryTabs\n\t\t\t\t\t\tcategories={ categories }\n\t\t\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\t\t\tonSelectCategory={ onSelectCategory }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</CategoryTabs>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-explore-button\"\n\t\t\t\t\t\tonClick={ () => setShowPatternsExplorer( true ) }\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Explore all patterns' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isMobile && (\n\t\t\t\t<MobileTabNavigation categories={ categories }>\n\t\t\t\t\t{ ( category ) => (\n\t\t\t\t\t\t<div className=\"block-editor-inserter__category-panel\">\n\t\t\t\t\t\t\t<PatternCategoryPreviews\n\t\t\t\t\t\t\t\tkey={ category.name }\n\t\t\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t</MobileTabNavigation>\n\t\t\t) }\n\t\t\t{ showPatternsExplorer && (\n\t\t\t\t<PatternsExplorerModal\n\t\t\t\t\tinitialCategory={ selectedCategory || categories[ 0 ] }\n\t\t\t\t\tpatternCategories={ categories }\n\t\t\t\t\tonModalClose={ () => setShowPatternsExplorer( false ) }\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default BlockPatternsTab;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,sBAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAD,sBAAA,CAAAN,OAAA;AACA,IAAAQ,wBAAA,GAAAR,OAAA;AACA,IAAAS,qBAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAJ,sBAAA,CAAAN,OAAA;AACA,IAAAW,UAAA,GAAAL,sBAAA,CAAAN,OAAA;AACA,IAAAY,MAAA,GAAAZ,OAAA;AACA,IAAAa,WAAA,GAAAb,OAAA;AAA8C,IAAAc,WAAA,GAAAd,OAAA;AAnB9C;AACA;AACA;;AAOA;AACA;AACA;;AAUA,SAASe,gBAAgBA,CAAE;EAC1BC,gBAAgB;EAChBC,gBAAgB;EAChBC,QAAQ;EACRC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,oBAAoB,EAAEC,uBAAuB,CAAE,GAAG,IAAA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A,EAEjB,IAAAwB,QAAE,EAAE,sBAAuB;MAAC,CACvB,CAAC;IAAA,CACL,CACL,EACClB,QAAQ,iBACT,IAAAZ,WAAA,CAAAmB,GAAA,EAAC1B,oBAAA,CAAA8B,OAAmB;MAACb,UAAU,EAAGA,UAAY;MAAAJ,QAAA,EACzCyB,QAAQ,iBACX,IAAA/B,WAAA,CAAAmB,GAAA;QAAKC,SAAS,EAAC,uCAAuC;QAAAd,QAAA,eACrD,IAAAN,WAAA,CAAAmB,GAAA,EAACzB,wBAAA,CAAAsC,uBAAuB;UAEvB5B,QAAQ,EAAGA,QAAU;UACrBC,YAAY,EAAGA,YAAc;UAC7B0B,QAAQ,EAAGA;QAAU,GAHfA,QAAQ,CAACE,IAIf;MAAC,CACE;IACL,CACmB,CACrB,EACC1B,oBAAoB,iBACrB,IAAAP,WAAA,CAAAmB,GAAA,EAAC5B,sBAAA,CAAAgC,OAAqB;MACrBW,eAAe,EAAG/B,gBAAgB,IAAIO,UAAU,CAAE,CAAC,CAAI;MACvDyB,iBAAiB,EAAGzB,UAAY;MAChC0B,YAAY,EAAGA,CAAA,KAAM5B,uBAAuB,CAAE,KAAM,CAAG;MACvDH,YAAY,EAAGA;IAAc,CAC7B,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAAgC,QAAA,GAAAC,OAAA,CAAAf,OAAA,GAEctB,gBAAgB","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_compose","_components","_i18n","_blockPatternsExplorer","_interopRequireDefault","_mobileTabNavigation","_patternCategoryPreviews","_usePatternCategories","_categoryTabs","_noResults","_jsxRuntime","BlockPatternsTab","onSelectCategory","selectedCategory","onInsert","rootClientId","children","showPatternsExplorer","setShowPatternsExplorer","useState","categories","usePatternCategories","isMobile","useViewportMatch","length","jsx","default","jsxs","Fragment","className","Button","__next40pxDefaultSize","onClick","variant","__","category","PatternCategoryPreviews","name","initialCategory","patternCategories","onModalClose","_default","exports"],"sources":["@wordpress/block-editor/src/components/inserter/block-patterns-tab/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport PatternsExplorerModal from '../block-patterns-explorer';\nimport MobileTabNavigation from '../mobile-tab-navigation';\nimport { PatternCategoryPreviews } from './pattern-category-previews';\nimport { usePatternCategories } from './use-pattern-categories';\nimport CategoryTabs from '../category-tabs';\nimport InserterNoResults from '../no-results';\n\nfunction BlockPatternsTab( {\n\tonSelectCategory,\n\tselectedCategory,\n\tonInsert,\n\trootClientId,\n\tchildren,\n} ) {\n\tconst [ showPatternsExplorer, setShowPatternsExplorer ] = useState( false );\n\n\tconst categories = usePatternCategories( rootClientId );\n\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tif ( ! categories.length ) {\n\t\treturn <InserterNoResults />;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ ! isMobile && (\n\t\t\t\t<div className=\"block-editor-inserter__block-patterns-tabs-container\">\n\t\t\t\t\t<CategoryTabs\n\t\t\t\t\t\tcategories={ categories }\n\t\t\t\t\t\tselectedCategory={ selectedCategory }\n\t\t\t\t\t\tonSelectCategory={ onSelectCategory }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ children }\n\t\t\t\t\t</CategoryTabs>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tclassName=\"block-editor-inserter__patterns-explore-button\"\n\t\t\t\t\t\tonClick={ () => setShowPatternsExplorer( true ) }\n\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Explore all patterns' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ isMobile && (\n\t\t\t\t<MobileTabNavigation categories={ categories }>\n\t\t\t\t\t{ ( category ) => (\n\t\t\t\t\t\t<div className=\"block-editor-inserter__category-panel\">\n\t\t\t\t\t\t\t<PatternCategoryPreviews\n\t\t\t\t\t\t\t\tkey={ category.name }\n\t\t\t\t\t\t\t\tonInsert={ onInsert }\n\t\t\t\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t\t\t\t\tcategory={ category }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t) }\n\t\t\t\t</MobileTabNavigation>\n\t\t\t) }\n\t\t\t{ showPatternsExplorer && (\n\t\t\t\t<PatternsExplorerModal\n\t\t\t\t\tinitialCategory={ selectedCategory || categories[ 0 ] }\n\t\t\t\t\tpatternCategories={ categories }\n\t\t\t\t\tonModalClose={ () => setShowPatternsExplorer( false ) }\n\t\t\t\t\trootClientId={ rootClientId }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nexport default BlockPatternsTab;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,sBAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,oBAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,wBAAA,GAAAP,OAAA;AACA,IAAAQ,qBAAA,GAAAR,OAAA;AACA,IAAAS,aAAA,GAAAJ,sBAAA,CAAAL,OAAA;AACA,IAAAU,UAAA,GAAAL,sBAAA,CAAAL,OAAA;AAA8C,IAAAW,WAAA,GAAAX,OAAA;AAhB9C;AACA;AACA;;AAMA;AACA;AACA;;AAQA,SAASY,gBAAgBA,CAAE;EAC1BC,gBAAgB;EAChBC,gBAAgB;EAChBC,QAAQ;EACRC,YAAY;EACZC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,oBAAoB,EAAEC,uBAAuB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAE3E,MAAMC,UAAU,GAAG,IA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QAAU,GAHfA,QAAQ,CAACE,IAIf;MAAC,CACE;IACL,CACmB,CACrB,EACCpB,oBAAoB,iBACrB,IAAAP,WAAA,CAAAe,GAAA,EAACtB,sBAAA,CAAAuB,OAAqB;MACrBY,eAAe,EAAGzB,gBAAgB,IAAIO,UAAU,CAAE,CAAC,CAAI;MACvDmB,iBAAiB,EAAGnB,UAAY;MAChCoB,YAAY,EAAGA,CAAA,KAAMtB,uBAAuB,CAAE,KAAM,CAAG;MACvDH,YAAY,EAAGA;IAAc,CAC7B,CACD;EAAA,CACA,CAAC;AAEL;AAAC,IAAA0B,QAAA,GAAAC,OAAA,CAAAhB,OAAA,GAEcf,gBAAgB","ignoreList":[]}
@@ -53,6 +53,7 @@ function InserterMenu({
53
53
  __experimentalInitialCategory
54
54
  }, ref) {
55
55
  const isZoomOutMode = (0, _data.useSelect)(select => (0, _lockUnlock.unlock)(select(_store.store)).isZoomOut(), []);
56
+ const hasSectionRootClientId = (0, _data.useSelect)(select => !!(0, _lockUnlock.unlock)(select(_store.store)).getSectionRootClientId(), []);
56
57
  const [filterValue, setFilterValue, delayedFilterValue] = (0, _compose.useDebouncedInput)(__experimentalFilterValue);
57
58
  const [hoveredItem, setHoveredItem] = (0, _element.useState)(null);
58
59
  const [selectedPatternCategory, setSelectedPatternCategory] = (0, _element.useState)(__experimentalInitialCategory);
@@ -68,7 +69,7 @@ function InserterMenu({
68
69
  }
69
70
  }
70
71
  const [selectedTab, setSelectedTab] = (0, _element.useState)(getInitialTab());
71
- const shouldUseZoomOut = selectedTab === 'patterns' || selectedTab === 'media';
72
+ const shouldUseZoomOut = hasSectionRootClientId && (selectedTab === 'patterns' || selectedTab === 'media');
72
73
  (0, _useZoomOut.useZoomOut)(shouldUseZoomOut && isLargeViewport);
73
74
  const [destinationRootClientId, onInsertBlocks, onToggleInsertionPoint] = (0, _useInsertionPoint.default)({
74
75
  rootClientId,