@wordpress/edit-site 5.10.0 → 5.11.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 (252) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/{add-custom-generic-template-modal.js → add-custom-generic-template-modal-content.js} +7 -22
  3. package/build/components/add-new-template/add-custom-generic-template-modal-content.js.map +1 -0
  4. package/build/components/add-new-template/{add-custom-template-modal.js → add-custom-template-modal-content.js} +11 -21
  5. package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -0
  6. package/build/components/add-new-template/new-template.js +98 -65
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/block-editor/index.js +1 -3
  9. package/build/components/block-editor/index.js.map +1 -1
  10. package/build/components/create-template-part-modal/index.js +6 -7
  11. package/build/components/create-template-part-modal/index.js.map +1 -1
  12. package/build/components/editor/index.js +15 -40
  13. package/build/components/editor/index.js.map +1 -1
  14. package/build/components/editor-canvas-container/index.js +10 -3
  15. package/build/components/editor-canvas-container/index.js.map +1 -1
  16. package/build/components/global-styles/screen-block.js +80 -3
  17. package/build/components/global-styles/screen-block.js.map +1 -1
  18. package/build/components/global-styles/screen-revisions/index.js +3 -10
  19. package/build/components/global-styles/screen-revisions/index.js.map +1 -1
  20. package/build/components/global-styles/screen-revisions/revisions-buttons.js +16 -18
  21. package/build/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
  22. package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js +15 -24
  23. package/build/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
  24. package/build/components/global-styles/screen-root.js +4 -4
  25. package/build/components/global-styles/screen-root.js.map +1 -1
  26. package/build/components/global-styles/style-variations-container.js +6 -10
  27. package/build/components/global-styles/style-variations-container.js.map +1 -1
  28. package/build/components/global-styles/ui.js +9 -9
  29. package/build/components/global-styles/ui.js.map +1 -1
  30. package/build/components/header-edit-mode/document-actions/index.js +28 -103
  31. package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
  32. package/build/components/header-edit-mode/index.js +14 -1
  33. package/build/components/header-edit-mode/index.js.map +1 -1
  34. package/build/components/layout/hooks.js +54 -0
  35. package/build/components/layout/hooks.js.map +1 -0
  36. package/build/components/layout/index.js +45 -98
  37. package/build/components/layout/index.js.map +1 -1
  38. package/build/components/list/actions/index.js +5 -2
  39. package/build/components/list/actions/index.js.map +1 -1
  40. package/build/components/resizable-frame/index.js +242 -0
  41. package/build/components/resizable-frame/index.js.map +1 -0
  42. package/build/components/revisions/index.js +2 -1
  43. package/build/components/revisions/index.js.map +1 -1
  44. package/build/components/secondary-sidebar/list-view-sidebar.js +4 -3
  45. package/build/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  46. package/build/components/sidebar/index.js +4 -4
  47. package/build/components/sidebar/index.js.map +1 -1
  48. package/build/components/sidebar-edit-mode/template-revisions/index.js +1 -1
  49. package/build/components/sidebar-edit-mode/template-revisions/index.js.map +1 -1
  50. package/build/components/sidebar-navigation-screen-global-styles/index.js +75 -11
  51. package/build/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  52. package/build/components/sidebar-navigation-screen-main/index.js +24 -33
  53. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  54. package/build/components/sidebar-navigation-screen-navigation-menu/index.js +162 -0
  55. package/build/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -0
  56. package/build/components/sidebar-navigation-screen-navigation-menus/constants.js +17 -0
  57. package/build/components/sidebar-navigation-screen-navigation-menus/constants.js.map +1 -0
  58. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +53 -103
  59. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  60. package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +87 -0
  61. package/build/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -0
  62. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +14 -71
  63. package/build/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -1
  64. package/build/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +53 -0
  65. package/build/components/sidebar-navigation-screen-navigation-menus/navigator-button.js.map +1 -0
  66. package/build/components/sidebar-navigation-screen-templates/index.js +36 -11
  67. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  68. package/build/components/site-hub/index.js +1 -3
  69. package/build/components/site-hub/index.js.map +1 -1
  70. package/build/components/style-book/index.js +93 -19
  71. package/build/components/style-book/index.js.map +1 -1
  72. package/build/components/use-edited-entity-record/index.js +8 -4
  73. package/build/components/use-edited-entity-record/index.js.map +1 -1
  74. package/build/hooks/commands/use-edit-mode-commands.js +105 -0
  75. package/build/hooks/commands/use-edit-mode-commands.js.map +1 -0
  76. package/build/store/actions.js +5 -3
  77. package/build/store/actions.js.map +1 -1
  78. package/build-module/components/add-new-template/{add-custom-generic-template-modal.js → add-custom-generic-template-modal-content.js} +8 -20
  79. package/build-module/components/add-new-template/add-custom-generic-template-modal-content.js.map +1 -0
  80. package/build-module/components/add-new-template/{add-custom-template-modal.js → add-custom-template-modal-content.js} +13 -22
  81. package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -0
  82. package/build-module/components/add-new-template/new-template.js +98 -67
  83. package/build-module/components/add-new-template/new-template.js.map +1 -1
  84. package/build-module/components/block-editor/index.js +1 -3
  85. package/build-module/components/block-editor/index.js.map +1 -1
  86. package/build-module/components/create-template-part-modal/index.js +7 -8
  87. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  88. package/build-module/components/editor/index.js +16 -43
  89. package/build-module/components/editor/index.js.map +1 -1
  90. package/build-module/components/editor-canvas-container/index.js +7 -3
  91. package/build-module/components/editor-canvas-container/index.js.map +1 -1
  92. package/build-module/components/global-styles/screen-block.js +82 -4
  93. package/build-module/components/global-styles/screen-block.js.map +1 -1
  94. package/build-module/components/global-styles/screen-revisions/index.js +3 -10
  95. package/build-module/components/global-styles/screen-revisions/index.js.map +1 -1
  96. package/build-module/components/global-styles/screen-revisions/revisions-buttons.js +16 -19
  97. package/build-module/components/global-styles/screen-revisions/revisions-buttons.js.map +1 -1
  98. package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js +15 -24
  99. package/build-module/components/global-styles/screen-revisions/use-global-styles-revisions.js.map +1 -1
  100. package/build-module/components/global-styles/screen-root.js +4 -4
  101. package/build-module/components/global-styles/screen-root.js.map +1 -1
  102. package/build-module/components/global-styles/style-variations-container.js +7 -11
  103. package/build-module/components/global-styles/style-variations-container.js.map +1 -1
  104. package/build-module/components/global-styles/ui.js +10 -10
  105. package/build-module/components/global-styles/ui.js.map +1 -1
  106. package/build-module/components/header-edit-mode/document-actions/index.js +31 -107
  107. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
  108. package/build-module/components/header-edit-mode/index.js +14 -2
  109. package/build-module/components/header-edit-mode/index.js.map +1 -1
  110. package/build-module/components/layout/hooks.js +41 -0
  111. package/build-module/components/layout/hooks.js.map +1 -0
  112. package/build-module/components/layout/index.js +46 -101
  113. package/build-module/components/layout/index.js.map +1 -1
  114. package/build-module/components/list/actions/index.js +6 -3
  115. package/build-module/components/list/actions/index.js.map +1 -1
  116. package/build-module/components/resizable-frame/index.js +228 -0
  117. package/build-module/components/resizable-frame/index.js.map +1 -0
  118. package/build-module/components/revisions/index.js +2 -1
  119. package/build-module/components/revisions/index.js.map +1 -1
  120. package/build-module/components/secondary-sidebar/list-view-sidebar.js +3 -3
  121. package/build-module/components/secondary-sidebar/list-view-sidebar.js.map +1 -1
  122. package/build-module/components/sidebar/index.js +3 -3
  123. package/build-module/components/sidebar/index.js.map +1 -1
  124. package/build-module/components/sidebar-edit-mode/template-revisions/index.js +1 -1
  125. package/build-module/components/sidebar-edit-mode/template-revisions/index.js.map +1 -1
  126. package/build-module/components/sidebar-navigation-screen-global-styles/index.js +70 -14
  127. package/build-module/components/sidebar-navigation-screen-global-styles/index.js.map +1 -1
  128. package/build-module/components/sidebar-navigation-screen-main/index.js +21 -32
  129. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  130. package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js +141 -0
  131. package/build-module/components/sidebar-navigation-screen-navigation-menu/index.js.map +1 -0
  132. package/build-module/components/sidebar-navigation-screen-navigation-menus/constants.js +10 -0
  133. package/build-module/components/sidebar-navigation-screen-navigation-menus/constants.js.map +1 -0
  134. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +52 -103
  135. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  136. package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +71 -0
  137. package/build-module/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js.map +1 -0
  138. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +12 -71
  139. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js.map +1 -1
  140. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +40 -0
  141. package/build-module/components/sidebar-navigation-screen-navigation-menus/navigator-button.js.map +1 -0
  142. package/build-module/components/sidebar-navigation-screen-templates/index.js +35 -11
  143. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  144. package/build-module/components/site-hub/index.js +1 -3
  145. package/build-module/components/site-hub/index.js.map +1 -1
  146. package/build-module/components/style-book/index.js +93 -20
  147. package/build-module/components/style-book/index.js.map +1 -1
  148. package/build-module/components/use-edited-entity-record/index.js +8 -4
  149. package/build-module/components/use-edited-entity-record/index.js.map +1 -1
  150. package/build-module/hooks/commands/use-edit-mode-commands.js +86 -0
  151. package/build-module/hooks/commands/use-edit-mode-commands.js.map +1 -0
  152. package/build-module/store/actions.js +5 -3
  153. package/build-module/store/actions.js.map +1 -1
  154. package/build-style/style-rtl.css +233 -210
  155. package/build-style/style.css +234 -210
  156. package/package.json +37 -37
  157. package/src/components/add-new-template/add-custom-generic-template-modal-content.js +82 -0
  158. package/src/components/add-new-template/{add-custom-template-modal.js → add-custom-template-modal-content.js} +13 -26
  159. package/src/components/add-new-template/new-template.js +139 -153
  160. package/src/components/add-new-template/style.scss +79 -66
  161. package/src/components/block-editor/index.js +2 -3
  162. package/src/components/create-template-part-modal/index.js +19 -25
  163. package/src/components/editor/index.js +16 -45
  164. package/src/components/editor/style.scss +21 -6
  165. package/src/components/editor-canvas-container/index.js +28 -19
  166. package/src/components/global-styles/screen-block.js +74 -3
  167. package/src/components/global-styles/screen-revisions/index.js +3 -11
  168. package/src/components/global-styles/screen-revisions/revisions-buttons.js +33 -25
  169. package/src/components/global-styles/screen-revisions/style.scss +3 -2
  170. package/src/components/global-styles/screen-revisions/test/use-global-styles-revisions.js +16 -3
  171. package/src/components/global-styles/screen-revisions/use-global-styles-revisions.js +15 -19
  172. package/src/components/global-styles/screen-root.js +5 -3
  173. package/src/components/global-styles/style-variations-container.js +13 -18
  174. package/src/components/global-styles/style.scss +3 -0
  175. package/src/components/global-styles/ui.js +11 -9
  176. package/src/components/header-edit-mode/document-actions/index.js +26 -129
  177. package/src/components/header-edit-mode/document-actions/style.scss +28 -59
  178. package/src/components/header-edit-mode/index.js +18 -0
  179. package/src/components/header-edit-mode/style.scss +1 -0
  180. package/src/components/layout/hooks.js +46 -0
  181. package/src/components/layout/index.js +56 -125
  182. package/src/components/layout/style.scss +8 -2
  183. package/src/components/list/actions/index.js +12 -5
  184. package/src/components/list/style.scss +1 -0
  185. package/src/components/resizable-frame/index.js +253 -0
  186. package/src/components/resizable-frame/style.scss +69 -0
  187. package/src/components/revisions/index.js +1 -0
  188. package/src/components/secondary-sidebar/list-view-sidebar.js +2 -1
  189. package/src/components/sidebar/index.js +4 -4
  190. package/src/components/sidebar-edit-mode/template-revisions/index.js +1 -2
  191. package/src/components/sidebar-navigation-item/style.scss +9 -0
  192. package/src/components/sidebar-navigation-screen/style.scss +1 -2
  193. package/src/components/sidebar-navigation-screen-global-styles/index.js +106 -21
  194. package/src/components/sidebar-navigation-screen-main/index.js +35 -52
  195. package/src/components/sidebar-navigation-screen-navigation-menu/index.js +157 -0
  196. package/src/components/sidebar-navigation-screen-navigation-menus/constants.js +9 -0
  197. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +63 -117
  198. package/src/components/sidebar-navigation-screen-navigation-menus/leaf-more-menu.js +83 -0
  199. package/src/components/sidebar-navigation-screen-navigation-menus/navigation-menu-content.js +6 -72
  200. package/src/components/sidebar-navigation-screen-navigation-menus/navigator-button.js +47 -0
  201. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +6 -20
  202. package/src/components/sidebar-navigation-screen-templates/index.js +53 -14
  203. package/src/components/site-hub/index.js +8 -9
  204. package/src/components/start-template-options/style.scss +20 -21
  205. package/src/components/style-book/index.js +132 -43
  206. package/src/components/style-book/style.scss +19 -0
  207. package/src/components/use-edited-entity-record/index.js +12 -3
  208. package/src/hooks/commands/use-edit-mode-commands.js +79 -0
  209. package/src/store/actions.js +4 -5
  210. package/src/store/test/utils.js +15 -5
  211. package/src/style.scss +1 -1
  212. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +0 -1
  213. package/build/components/add-new-template/add-custom-template-modal.js.map +0 -1
  214. package/build/components/global-styles/border-panel.js +0 -135
  215. package/build/components/global-styles/border-panel.js.map +0 -1
  216. package/build/components/navigate-to-link/index.js +0 -51
  217. package/build/components/navigate-to-link/index.js.map +0 -1
  218. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js +0 -19
  219. package/build/components/sidebar-navigation-screen-navigation-menus/loader.js.map +0 -1
  220. package/build/components/template-details/edit-template-title.js +0 -42
  221. package/build/components/template-details/edit-template-title.js.map +0 -1
  222. package/build/components/template-details/index.js +0 -103
  223. package/build/components/template-details/index.js.map +0 -1
  224. package/build/components/template-details/template-areas.js +0 -166
  225. package/build/components/template-details/template-areas.js.map +0 -1
  226. package/build/components/template-details/template-part-area-selector.js +0 -48
  227. package/build/components/template-details/template-part-area-selector.js.map +0 -1
  228. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +0 -1
  229. package/build-module/components/add-new-template/add-custom-template-modal.js.map +0 -1
  230. package/build-module/components/global-styles/border-panel.js +0 -125
  231. package/build-module/components/global-styles/border-panel.js.map +0 -1
  232. package/build-module/components/navigate-to-link/index.js +0 -39
  233. package/build-module/components/navigate-to-link/index.js.map +0 -1
  234. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js +0 -11
  235. package/build-module/components/sidebar-navigation-screen-navigation-menus/loader.js.map +0 -1
  236. package/build-module/components/template-details/edit-template-title.js +0 -33
  237. package/build-module/components/template-details/edit-template-title.js.map +0 -1
  238. package/build-module/components/template-details/index.js +0 -83
  239. package/build-module/components/template-details/index.js.map +0 -1
  240. package/build-module/components/template-details/template-areas.js +0 -145
  241. package/build-module/components/template-details/template-areas.js.map +0 -1
  242. package/build-module/components/template-details/template-part-area-selector.js +0 -36
  243. package/build-module/components/template-details/template-part-area-selector.js.map +0 -1
  244. package/src/components/add-new-template/add-custom-generic-template-modal.js +0 -101
  245. package/src/components/global-styles/border-panel.js +0 -114
  246. package/src/components/navigate-to-link/index.js +0 -46
  247. package/src/components/sidebar-navigation-screen-navigation-menus/loader.js +0 -9
  248. package/src/components/template-details/edit-template-title.js +0 -41
  249. package/src/components/template-details/index.js +0 -113
  250. package/src/components/template-details/style.scss +0 -72
  251. package/src/components/template-details/template-areas.js +0 -167
  252. package/src/components/template-details/template-part-area-selector.js +0 -39
@@ -0,0 +1,253 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useState, useRef, useEffect } from '@wordpress/element';
10
+ import {
11
+ ResizableBox,
12
+ __unstableMotion as motion,
13
+ } from '@wordpress/components';
14
+ import { useDispatch } from '@wordpress/data';
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ import { unlock } from '../../private-apis';
20
+ import { store as editSiteStore } from '../../store';
21
+
22
+ // Removes the inline styles in the drag handles.
23
+ const HANDLE_STYLES_OVERRIDE = {
24
+ position: undefined,
25
+ userSelect: undefined,
26
+ cursor: undefined,
27
+ width: undefined,
28
+ height: undefined,
29
+ top: undefined,
30
+ right: undefined,
31
+ bottom: undefined,
32
+ left: undefined,
33
+ };
34
+
35
+ // The minimum width of the frame (in px) while resizing.
36
+ const FRAME_MIN_WIDTH = 340;
37
+ // The reference width of the frame (in px) used to calculate the aspect ratio.
38
+ const FRAME_REFERENCE_WIDTH = 1300;
39
+ // 9 : 19.5 is the target aspect ratio enforced (when possible) while resizing.
40
+ const FRAME_TARGET_ASPECT_RATIO = 9 / 19.5;
41
+ // The minimum distance (in px) between the frame resize handle and the
42
+ // viewport's edge. If the frame is resized to be closer to the viewport's edge
43
+ // than this distance, then "canvas mode" will be enabled.
44
+ const SNAP_TO_EDIT_CANVAS_MODE_THRESHOLD = 200;
45
+
46
+ function calculateNewHeight( width, initialAspectRatio ) {
47
+ const lerp = ( a, b, amount ) => {
48
+ return a + ( b - a ) * amount;
49
+ };
50
+
51
+ // Calculate the intermediate aspect ratio based on the current width.
52
+ const lerpFactor =
53
+ 1 -
54
+ Math.max(
55
+ 0,
56
+ Math.min(
57
+ 1,
58
+ ( width - FRAME_MIN_WIDTH ) /
59
+ ( FRAME_REFERENCE_WIDTH - FRAME_MIN_WIDTH )
60
+ )
61
+ );
62
+
63
+ // Calculate the height based on the intermediate aspect ratio
64
+ // ensuring the frame arrives at the target aspect ratio.
65
+ const intermediateAspectRatio = lerp(
66
+ initialAspectRatio,
67
+ FRAME_TARGET_ASPECT_RATIO,
68
+ lerpFactor
69
+ );
70
+
71
+ return width / intermediateAspectRatio;
72
+ }
73
+
74
+ function ResizableFrame( {
75
+ isFullWidth,
76
+ isReady,
77
+ children,
78
+ oversizedClassName,
79
+ } ) {
80
+ const [ frameSize, setFrameSize ] = useState( {
81
+ width: '100%',
82
+ height: '100%',
83
+ } );
84
+ // The width of the resizable frame when a new resize gesture starts.
85
+ const [ startingWidth, setStartingWidth ] = useState();
86
+ const [ isResizing, setIsResizing ] = useState( false );
87
+ const [ isHovering, setIsHovering ] = useState( false );
88
+ const [ isOversized, setIsOversized ] = useState( false );
89
+ const [ resizeRatio, setResizeRatio ] = useState( 1 );
90
+ const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
91
+ const initialAspectRatioRef = useRef( null );
92
+ // The width of the resizable frame on initial render.
93
+ const initialComputedWidthRef = useRef( null );
94
+ const FRAME_TRANSITION = { type: 'tween', duration: isResizing ? 0 : 0.5 };
95
+ const frameRef = useRef( null );
96
+
97
+ // Remember frame dimensions on initial render.
98
+ useEffect( () => {
99
+ const { offsetWidth, offsetHeight } = frameRef.current.resizable;
100
+ initialComputedWidthRef.current = offsetWidth;
101
+ initialAspectRatioRef.current = offsetWidth / offsetHeight;
102
+ }, [] );
103
+
104
+ const handleResizeStart = ( _event, _direction, ref ) => {
105
+ // Remember the starting width so we don't have to get `ref.offsetWidth` on
106
+ // every resize event thereafter, which will cause layout thrashing.
107
+ setStartingWidth( ref.offsetWidth );
108
+ setIsResizing( true );
109
+ };
110
+
111
+ // Calculate the frame size based on the window width as its resized.
112
+ const handleResize = ( _event, _direction, _ref, delta ) => {
113
+ const normalizedDelta = delta.width / resizeRatio;
114
+ const deltaAbs = Math.abs( normalizedDelta );
115
+ const maxDoubledDelta =
116
+ delta.width < 0 // is shrinking
117
+ ? deltaAbs
118
+ : ( initialComputedWidthRef.current - startingWidth ) / 2;
119
+ const deltaToDouble = Math.min( deltaAbs, maxDoubledDelta );
120
+ const doubleSegment = deltaAbs === 0 ? 0 : deltaToDouble / deltaAbs;
121
+ const singleSegment = 1 - doubleSegment;
122
+
123
+ setResizeRatio( singleSegment + doubleSegment * 2 );
124
+
125
+ const updatedWidth = startingWidth + delta.width;
126
+
127
+ setIsOversized( updatedWidth > initialComputedWidthRef.current );
128
+
129
+ // Width will be controlled by the library (via `resizeRatio`),
130
+ // so we only need to update the height.
131
+ setFrameSize( {
132
+ height: isOversized
133
+ ? '100%'
134
+ : calculateNewHeight(
135
+ updatedWidth,
136
+ initialAspectRatioRef.current
137
+ ),
138
+ } );
139
+ };
140
+
141
+ const handleResizeStop = ( _event, _direction, ref ) => {
142
+ setIsResizing( false );
143
+
144
+ if ( ! isOversized ) {
145
+ return;
146
+ }
147
+
148
+ setIsOversized( false );
149
+
150
+ const remainingWidth =
151
+ ref.ownerDocument.documentElement.offsetWidth - ref.offsetWidth;
152
+
153
+ if ( remainingWidth > SNAP_TO_EDIT_CANVAS_MODE_THRESHOLD ) {
154
+ // Reset the initial aspect ratio if the frame is resized slightly
155
+ // above the sidebar but not far enough to trigger full screen.
156
+ setFrameSize( { width: '100%', height: '100%' } );
157
+ } else {
158
+ // Trigger full screen if the frame is resized far enough to the left.
159
+ setCanvasMode( 'edit' );
160
+ }
161
+ };
162
+
163
+ const frameAnimationVariants = {
164
+ default: {
165
+ flexGrow: 0,
166
+ height: frameSize.height,
167
+ },
168
+ fullWidth: {
169
+ flexGrow: 1,
170
+ height: frameSize.height,
171
+ },
172
+ };
173
+
174
+ return (
175
+ <ResizableBox
176
+ as={ motion.div }
177
+ ref={ frameRef }
178
+ initial={ false }
179
+ variants={ frameAnimationVariants }
180
+ animate={ isFullWidth ? 'fullWidth' : 'default' }
181
+ onAnimationComplete={ ( definition ) => {
182
+ if ( definition === 'fullWidth' )
183
+ setFrameSize( { width: '100%', height: '100%' } );
184
+ } }
185
+ transition={ FRAME_TRANSITION }
186
+ size={ frameSize }
187
+ enable={ {
188
+ top: false,
189
+ right: false,
190
+ bottom: false,
191
+ // Resizing will be disabled until the editor content is loaded.
192
+ left: isReady,
193
+ topRight: false,
194
+ bottomRight: false,
195
+ bottomLeft: false,
196
+ topLeft: false,
197
+ } }
198
+ resizeRatio={ resizeRatio }
199
+ handleClasses={ undefined }
200
+ handleStyles={ {
201
+ left: HANDLE_STYLES_OVERRIDE,
202
+ right: HANDLE_STYLES_OVERRIDE,
203
+ } }
204
+ minWidth={ FRAME_MIN_WIDTH }
205
+ maxWidth={ isFullWidth ? '100%' : '150%' }
206
+ maxHeight={ '100%' }
207
+ onMouseOver={ () => setIsHovering( true ) }
208
+ onMouseOut={ () => setIsHovering( false ) }
209
+ handleComponent={ {
210
+ left:
211
+ isHovering || isResizing ? (
212
+ <motion.div
213
+ key="handle"
214
+ className="edit-site-resizable-frame__handle"
215
+ title="Drag to resize"
216
+ initial={ {
217
+ opacity: 0,
218
+ left: 0,
219
+ } }
220
+ animate={ {
221
+ opacity: 1,
222
+ left: -15,
223
+ } }
224
+ exit={ {
225
+ opacity: 0,
226
+ left: 0,
227
+ } }
228
+ whileHover={ { scale: 1.1 } }
229
+ />
230
+ ) : null,
231
+ } }
232
+ onResizeStart={ handleResizeStart }
233
+ onResize={ handleResize }
234
+ onResizeStop={ handleResizeStop }
235
+ className={ classnames( 'edit-site-resizable-frame__inner', {
236
+ 'is-resizing': isResizing,
237
+ [ oversizedClassName ]: isOversized,
238
+ } ) }
239
+ >
240
+ <motion.div
241
+ className="edit-site-resizable-frame__inner-content"
242
+ animate={ {
243
+ borderRadius: isFullWidth ? 0 : 8,
244
+ } }
245
+ transition={ FRAME_TRANSITION }
246
+ >
247
+ { children }
248
+ </motion.div>
249
+ </ResizableBox>
250
+ );
251
+ }
252
+
253
+ export default ResizableFrame;
@@ -0,0 +1,69 @@
1
+ .edit-site-resizable-frame__inner {
2
+ position: relative;
3
+
4
+ &.is-resizing {
5
+ @at-root {
6
+ body:has(&) {
7
+ cursor: col-resize;
8
+ user-select: none;
9
+ -webkit-user-select: none;
10
+ }
11
+ }
12
+
13
+ &::before {
14
+ // This covers the whole content which ensures mouse up triggers
15
+ // even if the content is "inert".
16
+ position: absolute;
17
+ z-index: 1;
18
+ inset: 0;
19
+ content: "";
20
+ }
21
+ }
22
+ }
23
+
24
+ .edit-site-resizable-frame__inner-content {
25
+ position: absolute;
26
+ z-index: 0;
27
+ inset: 0;
28
+ }
29
+
30
+ .edit-site-resizable-frame__handle {
31
+ position: absolute;
32
+ width: 5px;
33
+ height: 50px;
34
+ background-color: rgba(255, 255, 255, 0.3);
35
+ z-index: 100;
36
+ border-radius: 5px;
37
+ cursor: col-resize;
38
+ display: flex;
39
+ align-items: center;
40
+ justify-content: flex-end;
41
+ top: 50%;
42
+ &::before {
43
+ position: absolute;
44
+ left: 100%;
45
+ height: 100%;
46
+ width: $grid-unit-30;
47
+ content: "";
48
+ }
49
+
50
+ &::after {
51
+ position: absolute;
52
+ right: 100%;
53
+ height: 100%;
54
+ width: $grid-unit-30;
55
+ content: "";
56
+ }
57
+
58
+ &:hover {
59
+ background-color: var(--wp-admin-theme-color);
60
+ }
61
+
62
+ .edit-site-resizable-frame__handle-label {
63
+ border-radius: 2px;
64
+ background: var(--wp-admin-theme-color);
65
+ padding: 4px 8px;
66
+ color: #fff;
67
+ margin-right: $grid-unit-10;
68
+ }
69
+ }
@@ -74,6 +74,7 @@ function Revisions( { onClose, userConfig, blocks } ) {
74
74
  title={ __( 'Revisions' ) }
75
75
  onClose={ onClose }
76
76
  closeButtonLabel={ __( 'Close revisions' ) }
77
+ enableResizing={ true }
77
78
  >
78
79
  <Iframe
79
80
  className="edit-site-revisions__iframe"
@@ -19,6 +19,8 @@ import { ESCAPE } from '@wordpress/keycodes';
19
19
  import { store as editSiteStore } from '../../store';
20
20
  import { unlock } from '../../private-apis';
21
21
 
22
+ const { PrivateListView } = unlock( blockEditorPrivateApis );
23
+
22
24
  export default function ListViewSidebar() {
23
25
  const { setIsListViewOpened } = useDispatch( editSiteStore );
24
26
 
@@ -31,7 +33,6 @@ export default function ListViewSidebar() {
31
33
  }
32
34
  }
33
35
 
34
- const { PrivateListView } = unlock( blockEditorPrivateApis );
35
36
  return (
36
37
  // eslint-disable-next-line jsx-a11y/no-static-element-interactions
37
38
  <div
@@ -18,10 +18,10 @@ import useSyncPathWithURL, {
18
18
  getPathFromURL,
19
19
  } from '../sync-state-with-url/use-sync-path-with-url';
20
20
  import SidebarNavigationScreenNavigationMenus from '../sidebar-navigation-screen-navigation-menus';
21
+ import SidebarNavigationScreenNavigationMenu from '../sidebar-navigation-screen-navigation-menu';
21
22
  import SidebarNavigationScreenGlobalStyles from '../sidebar-navigation-screen-global-styles';
22
23
  import SidebarNavigationScreenTemplatesBrowse from '../sidebar-navigation-screen-templates-browse';
23
24
  import SaveHub from '../save-hub';
24
- import SidebarNavigationScreenNavigationItem from '../sidebar-navigation-screen-navigation-item';
25
25
  import { unlock } from '../../private-apis';
26
26
  import SidebarNavigationScreenPages from '../sidebar-navigation-screen-pages';
27
27
  import SidebarNavigationScreenPage from '../sidebar-navigation-screen-page';
@@ -39,12 +39,12 @@ function SidebarScreens() {
39
39
  <NavigatorScreen path="/navigation">
40
40
  <SidebarNavigationScreenNavigationMenus />
41
41
  </NavigatorScreen>
42
+ <NavigatorScreen path="/navigation/:postType/:postId">
43
+ <SidebarNavigationScreenNavigationMenu />
44
+ </NavigatorScreen>
42
45
  <NavigatorScreen path="/wp_global_styles">
43
46
  <SidebarNavigationScreenGlobalStyles />
44
47
  </NavigatorScreen>
45
- <NavigatorScreen path="/navigation/:postType/:postId">
46
- <SidebarNavigationScreenNavigationItem />
47
- </NavigatorScreen>
48
48
  <NavigatorScreen path="/page">
49
49
  <SidebarNavigationScreenPages />
50
50
  </NavigatorScreen>
@@ -19,8 +19,7 @@ const useRevisionData = () => {
19
19
  currentTemplate?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;
20
20
 
21
21
  const revisionsCount =
22
- ( currentTemplate?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0 ) +
23
- 1;
22
+ currentTemplate?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
24
23
 
25
24
  return {
26
25
  currentTemplate,
@@ -19,6 +19,15 @@
19
19
  .edit-site-sidebar-navigation-item__drilldown-indicator {
20
20
  fill: $gray-700;
21
21
  }
22
+
23
+ &:is(a) {
24
+ text-decoration: none;
25
+
26
+ &:focus {
27
+ box-shadow: none;
28
+ outline: none;
29
+ }
30
+ }
22
31
  }
23
32
 
24
33
  .edit-site-sidebar-navigation-screen__content .block-editor-list-view-block-select-button {
@@ -6,7 +6,7 @@
6
6
  }
7
7
 
8
8
  .edit-site-sidebar-navigation-screen__content {
9
- margin: 0 $grid-unit-20 $grid-unit-20 $button-size;
9
+ margin: 0 0 $grid-unit-20 0;
10
10
  color: $gray-600;
11
11
  //z-index: z-index(".edit-site-sidebar-navigation-screen__content");
12
12
  }
@@ -34,7 +34,6 @@
34
34
  box-shadow: 0 $grid-unit-10 $grid-unit-20 $gray-900;
35
35
  margin-bottom: $grid-unit-10;
36
36
  padding-bottom: $grid-unit-10;
37
- padding-right: $grid-unit-20;
38
37
  z-index: z-index(".edit-site-sidebar-navigation-screen__title-icon");
39
38
  }
40
39
 
@@ -2,8 +2,11 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
- import { edit } from '@wordpress/icons';
6
- import { useDispatch } from '@wordpress/data';
5
+ import { edit, seen } from '@wordpress/icons';
6
+ import { useSelect, useDispatch } from '@wordpress/data';
7
+ import { store as coreStore } from '@wordpress/core-data';
8
+ import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components';
9
+ import { useViewportMatch } from '@wordpress/compose';
7
10
 
8
11
  /**
9
12
  * Internal dependencies
@@ -13,29 +16,111 @@ import StyleVariationsContainer from '../global-styles/style-variations-containe
13
16
  import { unlock } from '../../private-apis';
14
17
  import { store as editSiteStore } from '../../store';
15
18
  import SidebarButton from '../sidebar-button';
19
+ import SidebarNavigationItem from '../sidebar-navigation-item';
20
+ import StyleBook from '../style-book';
16
21
 
17
- export default function SidebarNavigationScreenGlobalStyles() {
22
+ export function SidebarNavigationItemGlobalStyles( props ) {
18
23
  const { openGeneralSidebar } = useDispatch( editSiteStore );
19
24
  const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
25
+ const hasGlobalStyleVariations = useSelect(
26
+ ( select ) =>
27
+ !! select(
28
+ coreStore
29
+ ).__experimentalGetCurrentThemeGlobalStylesVariations()?.length,
30
+ []
31
+ );
32
+ if ( hasGlobalStyleVariations ) {
33
+ return (
34
+ <NavigatorButton
35
+ { ...props }
36
+ as={ SidebarNavigationItem }
37
+ path="/wp_global_styles"
38
+ />
39
+ );
40
+ }
20
41
  return (
21
- <SidebarNavigationScreen
22
- title={ __( 'Styles' ) }
23
- description={ __(
24
- 'Choose a different style combination for the theme styles.'
25
- ) }
26
- content={ <StyleVariationsContainer /> }
27
- actions={
28
- <SidebarButton
29
- icon={ edit }
30
- label={ __( 'Edit styles' ) }
31
- onClick={ () => {
32
- // switch to edit mode.
33
- setCanvasMode( 'edit' );
34
- // open global styles sidebar.
35
- openGeneralSidebar( 'edit-site/global-styles' );
36
- } }
37
- />
38
- }
42
+ <SidebarNavigationItem
43
+ { ...props }
44
+ onClick={ () => {
45
+ // switch to edit mode.
46
+ setCanvasMode( 'edit' );
47
+ // open global styles sidebar.
48
+ openGeneralSidebar( 'edit-site/global-styles' );
49
+ } }
39
50
  />
40
51
  );
41
52
  }
53
+
54
+ export default function SidebarNavigationScreenGlobalStyles() {
55
+ const { openGeneralSidebar } = useDispatch( editSiteStore );
56
+ const isMobileViewport = useViewportMatch( 'medium', '<' );
57
+ const { setCanvasMode, setEditorCanvasContainerView } = unlock(
58
+ useDispatch( editSiteStore )
59
+ );
60
+
61
+ const isStyleBookOpened = useSelect(
62
+ ( select ) =>
63
+ 'style-book' ===
64
+ unlock( select( editSiteStore ) ).getEditorCanvasContainerView(),
65
+ []
66
+ );
67
+
68
+ const openGlobalStyles = async () =>
69
+ Promise.all( [
70
+ setCanvasMode( 'edit' ),
71
+ openGeneralSidebar( 'edit-site/global-styles' ),
72
+ ] );
73
+
74
+ const openStyleBook = async () => {
75
+ await openGlobalStyles();
76
+ // Open the Style Book once the canvas mode is set to edit,
77
+ // and the global styles sidebar is open. This ensures that
78
+ // the Style Book is not prematurely closed.
79
+ setEditorCanvasContainerView( 'style-book' );
80
+ };
81
+
82
+ return (
83
+ <>
84
+ <SidebarNavigationScreen
85
+ title={ __( 'Styles' ) }
86
+ description={ __(
87
+ 'Choose a different style combination for the theme styles.'
88
+ ) }
89
+ content={ <StyleVariationsContainer /> }
90
+ actions={
91
+ <div>
92
+ { ! isMobileViewport && (
93
+ <SidebarButton
94
+ icon={ seen }
95
+ label={ __( 'Style Book' ) }
96
+ onClick={ () =>
97
+ setEditorCanvasContainerView(
98
+ ! isStyleBookOpened
99
+ ? 'style-book'
100
+ : undefined
101
+ )
102
+ }
103
+ isPressed={ isStyleBookOpened }
104
+ />
105
+ ) }
106
+ <SidebarButton
107
+ icon={ edit }
108
+ label={ __( 'Edit styles' ) }
109
+ onClick={ async () => await openGlobalStyles() }
110
+ />
111
+ </div>
112
+ }
113
+ />
114
+ { isStyleBookOpened && ! isMobileViewport && (
115
+ <StyleBook
116
+ enableResizing={ false }
117
+ isSelected={ () => false }
118
+ onClick={ openStyleBook }
119
+ onSelect={ openStyleBook }
120
+ showCloseButton={ false }
121
+ showTabs={ false }
122
+ />
123
+ ) }
124
+ </>
125
+ );
126
+ }
@@ -7,46 +7,36 @@ import {
7
7
  } from '@wordpress/components';
8
8
  import { __ } from '@wordpress/i18n';
9
9
  import { layout, symbol, navigation, styles, page } from '@wordpress/icons';
10
- import { useSelect } from '@wordpress/data';
11
- import { store as coreStore } from '@wordpress/core-data';
10
+ import { useDispatch, useSelect } from '@wordpress/data';
11
+
12
+ import { useEffect } from '@wordpress/element';
12
13
 
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
16
17
  import SidebarNavigationScreen from '../sidebar-navigation-screen';
17
18
  import SidebarNavigationItem from '../sidebar-navigation-item';
19
+ import { SidebarNavigationItemGlobalStyles } from '../sidebar-navigation-screen-global-styles';
20
+ import { unlock } from '../../private-apis';
21
+ import { store as editSiteStore } from '../../store';
22
+ import SidebarNavigationScreenNavigationMenuButton from '../sidebar-navigation-screen-navigation-menus/navigator-button';
18
23
 
19
24
  export default function SidebarNavigationScreenMain() {
20
- const { hasNavigationMenus, hasGlobalStyleVariations } = useSelect(
21
- ( select ) => {
22
- const {
23
- getEntityRecords,
24
- __experimentalGetCurrentThemeGlobalStylesVariations,
25
- } = select( coreStore );
26
- // The query needs to be the same as in the "SidebarNavigationScreenNavigationMenus" component,
27
- // to avoid double network calls.
28
- const navigationMenus = getEntityRecords(
29
- 'postType',
30
- 'wp_navigation',
31
- {
32
- per_page: 1,
33
- status: 'publish',
34
- order: 'desc',
35
- orderby: 'date',
36
- }
37
- );
38
- return {
39
- hasNavigationMenus: !! navigationMenus?.length,
40
- hasGlobalStyleVariations:
41
- !! __experimentalGetCurrentThemeGlobalStylesVariations()
42
- ?.length,
43
- };
44
- },
45
- []
25
+ const editorCanvasContainerView = useSelect( ( select ) => {
26
+ return unlock( select( editSiteStore ) ).getEditorCanvasContainerView();
27
+ }, [] );
28
+
29
+ const { setEditorCanvasContainerView } = unlock(
30
+ useDispatch( editSiteStore )
46
31
  );
47
- const showNavigationScreen = process.env.IS_GUTENBERG_PLUGIN
48
- ? hasNavigationMenus
49
- : false;
32
+
33
+ // Clear the editor canvas container view when accessing the main navigation screen.
34
+ useEffect( () => {
35
+ if ( editorCanvasContainerView ) {
36
+ setEditorCanvasContainerView( undefined );
37
+ }
38
+ }, [ editorCanvasContainerView, setEditorCanvasContainerView ] );
39
+
50
40
  return (
51
41
  <SidebarNavigationScreen
52
42
  isRoot
@@ -56,27 +46,20 @@ export default function SidebarNavigationScreenMain() {
56
46
  ) }
57
47
  content={
58
48
  <ItemGroup>
59
- { showNavigationScreen && (
60
- <NavigatorButton
61
- as={ SidebarNavigationItem }
62
- path="/navigation"
63
- withChevron
64
- icon={ navigation }
65
- >
66
- { __( 'Navigation' ) }
67
- </NavigatorButton>
68
- ) }
69
- { hasGlobalStyleVariations && (
70
- <NavigatorButton
71
- as={ SidebarNavigationItem }
72
- path="/wp_global_styles"
73
- withChevron
74
- icon={ styles }
75
- >
76
- { __( 'Styles' ) }
77
- </NavigatorButton>
78
- ) }
49
+ <SidebarNavigationScreenNavigationMenuButton
50
+ withChevron
51
+ icon={ navigation }
52
+ as={ SidebarNavigationItem }
53
+ >
54
+ { __( 'Navigation' ) }
55
+ </SidebarNavigationScreenNavigationMenuButton>
79
56
 
57
+ <SidebarNavigationItemGlobalStyles
58
+ withChevron
59
+ icon={ styles }
60
+ >
61
+ { __( 'Styles' ) }
62
+ </SidebarNavigationItemGlobalStyles>
80
63
  <NavigatorButton
81
64
  as={ SidebarNavigationItem }
82
65
  path="/page"
@@ -99,7 +82,7 @@ export default function SidebarNavigationScreenMain() {
99
82
  withChevron
100
83
  icon={ symbol }
101
84
  >
102
- { __( 'Template Parts' ) }
85
+ { __( 'Library' ) }
103
86
  </NavigatorButton>
104
87
  </ItemGroup>
105
88
  }