@wordpress/edit-site 5.3.6 → 5.5.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 (217) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/add-new-template/new-template.js +1 -20
  3. package/build/components/add-new-template/new-template.js.map +1 -1
  4. package/build/components/app/index.js.map +1 -1
  5. package/build/components/block-editor/editor-canvas.js +1 -0
  6. package/build/components/block-editor/editor-canvas.js.map +1 -1
  7. package/build/components/editor/index.js +3 -1
  8. package/build/components/editor/index.js.map +1 -1
  9. package/build/components/global-styles/border-panel.js +5 -5
  10. package/build/components/global-styles/border-panel.js.map +1 -1
  11. package/build/components/global-styles/color-palette-panel.js +5 -2
  12. package/build/components/global-styles/color-palette-panel.js.map +1 -1
  13. package/build/components/global-styles/color-utils.js +1 -1
  14. package/build/components/global-styles/color-utils.js.map +1 -1
  15. package/build/components/global-styles/context-menu.js +22 -6
  16. package/build/components/global-styles/context-menu.js.map +1 -1
  17. package/build/components/global-styles/custom-css.js +1 -1
  18. package/build/components/global-styles/custom-css.js.map +1 -1
  19. package/build/components/global-styles/dimensions-panel.js +41 -486
  20. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  21. package/build/components/global-styles/duotone-panel.js +78 -0
  22. package/build/components/global-styles/duotone-panel.js.map +1 -0
  23. package/build/components/global-styles/filter-utils.js +17 -0
  24. package/build/components/global-styles/filter-utils.js.map +1 -0
  25. package/build/components/global-styles/gradients-palette-panel.js +8 -3
  26. package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
  27. package/build/components/global-styles/header.js +3 -1
  28. package/build/components/global-styles/header.js.map +1 -1
  29. package/build/components/global-styles/hooks.js +14 -51
  30. package/build/components/global-styles/hooks.js.map +1 -1
  31. package/build/components/global-styles/palette.js +3 -1
  32. package/build/components/global-styles/palette.js.map +1 -1
  33. package/build/components/global-styles/preview.js +9 -5
  34. package/build/components/global-styles/preview.js.map +1 -1
  35. package/build/components/global-styles/screen-background-color.js +3 -2
  36. package/build/components/global-styles/screen-background-color.js.map +1 -1
  37. package/build/components/global-styles/screen-block-list.js +13 -6
  38. package/build/components/global-styles/screen-block-list.js.map +1 -1
  39. package/build/components/global-styles/screen-button-color.js +7 -5
  40. package/build/components/global-styles/screen-button-color.js.map +1 -1
  41. package/build/components/global-styles/screen-colors.js +8 -6
  42. package/build/components/global-styles/screen-colors.js.map +1 -1
  43. package/build/components/global-styles/screen-filters.js +46 -0
  44. package/build/components/global-styles/screen-filters.js.map +1 -0
  45. package/build/components/global-styles/screen-heading-color.js +8 -6
  46. package/build/components/global-styles/screen-heading-color.js.map +1 -1
  47. package/build/components/global-styles/screen-layout.js +13 -5
  48. package/build/components/global-styles/screen-layout.js.map +1 -1
  49. package/build/components/global-styles/screen-link-color.js +3 -2
  50. package/build/components/global-styles/screen-link-color.js.map +1 -1
  51. package/build/components/global-styles/screen-text-color.js +3 -2
  52. package/build/components/global-styles/screen-text-color.js.map +1 -1
  53. package/build/components/global-styles/screen-typography.js +3 -1
  54. package/build/components/global-styles/screen-typography.js.map +1 -1
  55. package/build/components/global-styles/shadow-panel.js +2 -3
  56. package/build/components/global-styles/shadow-panel.js.map +1 -1
  57. package/build/components/global-styles/subtitle.js +3 -2
  58. package/build/components/global-styles/subtitle.js.map +1 -1
  59. package/build/components/global-styles/typography-panel.js +23 -303
  60. package/build/components/global-styles/typography-panel.js.map +1 -1
  61. package/build/components/global-styles/ui.js +6 -0
  62. package/build/components/global-styles/ui.js.map +1 -1
  63. package/build/components/keyboard-shortcut-help-modal/config.js +12 -0
  64. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  65. package/build/components/keyboard-shortcuts/index.js +67 -0
  66. package/build/components/keyboard-shortcuts/index.js.map +1 -1
  67. package/build/components/navigation-inspector/index.js +0 -29
  68. package/build/components/navigation-inspector/index.js.map +1 -1
  69. package/build/components/navigation-inspector/navigation-menu.js +22 -5
  70. package/build/components/navigation-inspector/navigation-menu.js.map +1 -1
  71. package/build/components/sidebar-edit-mode/index.js +1 -1
  72. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  73. package/build/components/sidebar-edit-mode/template-card/index.js +9 -2
  74. package/build/components/sidebar-edit-mode/template-card/index.js.map +1 -1
  75. package/build/components/sidebar-edit-mode/template-card/last-revision.js +84 -0
  76. package/build/components/sidebar-edit-mode/template-card/last-revision.js.map +1 -0
  77. package/build/components/sidebar-navigation-screen-navigation-menus/index.js +9 -1
  78. package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  79. package/build/components/start-template-options/index.js +175 -0
  80. package/build/components/start-template-options/index.js.map +1 -0
  81. package/build/hooks/push-changes-to-global-styles/index.js +5 -4
  82. package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
  83. package/build/store/actions.js +2 -2
  84. package/build/store/actions.js.map +1 -1
  85. package/build-module/components/add-new-template/new-template.js +1 -18
  86. package/build-module/components/add-new-template/new-template.js.map +1 -1
  87. package/build-module/components/app/index.js.map +1 -1
  88. package/build-module/components/block-editor/editor-canvas.js +1 -0
  89. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  90. package/build-module/components/editor/index.js +2 -1
  91. package/build-module/components/editor/index.js.map +1 -1
  92. package/build-module/components/global-styles/border-panel.js +6 -6
  93. package/build-module/components/global-styles/border-panel.js.map +1 -1
  94. package/build-module/components/global-styles/color-palette-panel.js +5 -2
  95. package/build-module/components/global-styles/color-palette-panel.js.map +1 -1
  96. package/build-module/components/global-styles/color-utils.js +2 -2
  97. package/build-module/components/global-styles/color-utils.js.map +1 -1
  98. package/build-module/components/global-styles/context-menu.js +20 -6
  99. package/build-module/components/global-styles/context-menu.js.map +1 -1
  100. package/build-module/components/global-styles/custom-css.js +1 -1
  101. package/build-module/components/global-styles/custom-css.js.map +1 -1
  102. package/build-module/components/global-styles/dimensions-panel.js +43 -479
  103. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  104. package/build-module/components/global-styles/duotone-panel.js +67 -0
  105. package/build-module/components/global-styles/duotone-panel.js.map +1 -0
  106. package/build-module/components/global-styles/filter-utils.js +9 -0
  107. package/build-module/components/global-styles/filter-utils.js.map +1 -0
  108. package/build-module/components/global-styles/gradients-palette-panel.js +8 -3
  109. package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
  110. package/build-module/components/global-styles/header.js +3 -1
  111. package/build-module/components/global-styles/header.js.map +1 -1
  112. package/build-module/components/global-styles/hooks.js +12 -49
  113. package/build-module/components/global-styles/hooks.js.map +1 -1
  114. package/build-module/components/global-styles/palette.js +3 -1
  115. package/build-module/components/global-styles/palette.js.map +1 -1
  116. package/build-module/components/global-styles/preview.js +10 -6
  117. package/build-module/components/global-styles/preview.js.map +1 -1
  118. package/build-module/components/global-styles/screen-background-color.js +4 -3
  119. package/build-module/components/global-styles/screen-background-color.js.map +1 -1
  120. package/build-module/components/global-styles/screen-block-list.js +12 -5
  121. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  122. package/build-module/components/global-styles/screen-button-color.js +8 -6
  123. package/build-module/components/global-styles/screen-button-color.js.map +1 -1
  124. package/build-module/components/global-styles/screen-colors.js +9 -7
  125. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  126. package/build-module/components/global-styles/screen-filters.js +33 -0
  127. package/build-module/components/global-styles/screen-filters.js.map +1 -0
  128. package/build-module/components/global-styles/screen-heading-color.js +9 -7
  129. package/build-module/components/global-styles/screen-heading-color.js.map +1 -1
  130. package/build-module/components/global-styles/screen-layout.js +11 -2
  131. package/build-module/components/global-styles/screen-layout.js.map +1 -1
  132. package/build-module/components/global-styles/screen-link-color.js +4 -3
  133. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  134. package/build-module/components/global-styles/screen-text-color.js +4 -3
  135. package/build-module/components/global-styles/screen-text-color.js.map +1 -1
  136. package/build-module/components/global-styles/screen-typography.js +3 -1
  137. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  138. package/build-module/components/global-styles/shadow-panel.js +3 -4
  139. package/build-module/components/global-styles/shadow-panel.js.map +1 -1
  140. package/build-module/components/global-styles/subtitle.js +3 -2
  141. package/build-module/components/global-styles/subtitle.js.map +1 -1
  142. package/build-module/components/global-styles/typography-panel.js +24 -300
  143. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  144. package/build-module/components/global-styles/ui.js +5 -0
  145. package/build-module/components/global-styles/ui.js.map +1 -1
  146. package/build-module/components/keyboard-shortcut-help-modal/config.js +12 -0
  147. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  148. package/build-module/components/keyboard-shortcuts/index.js +65 -0
  149. package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
  150. package/build-module/components/navigation-inspector/index.js +0 -27
  151. package/build-module/components/navigation-inspector/index.js.map +1 -1
  152. package/build-module/components/navigation-inspector/navigation-menu.js +25 -8
  153. package/build-module/components/navigation-inspector/navigation-menu.js.map +1 -1
  154. package/build-module/components/sidebar-edit-mode/index.js +1 -1
  155. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  156. package/build-module/components/sidebar-edit-mode/template-card/index.js +9 -4
  157. package/build-module/components/sidebar-edit-mode/template-card/index.js.map +1 -1
  158. package/build-module/components/sidebar-edit-mode/template-card/last-revision.js +70 -0
  159. package/build-module/components/sidebar-edit-mode/template-card/last-revision.js.map +1 -0
  160. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +9 -1
  161. package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
  162. package/build-module/components/start-template-options/index.js +156 -0
  163. package/build-module/components/start-template-options/index.js.map +1 -0
  164. package/build-module/hooks/push-changes-to-global-styles/index.js +6 -5
  165. package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
  166. package/build-module/store/actions.js +2 -2
  167. package/build-module/store/actions.js.map +1 -1
  168. package/build-style/style-rtl.css +73 -4
  169. package/build-style/style.css +73 -4
  170. package/package.json +31 -31
  171. package/src/components/add-new-template/new-template.js +1 -16
  172. package/src/components/app/index.js +0 -1
  173. package/src/components/block-editor/editor-canvas.js +1 -0
  174. package/src/components/editor/index.js +2 -0
  175. package/src/components/global-styles/border-panel.js +6 -6
  176. package/src/components/global-styles/color-palette-panel.js +3 -0
  177. package/src/components/global-styles/color-utils.js +2 -3
  178. package/src/components/global-styles/context-menu.js +25 -4
  179. package/src/components/global-styles/custom-css.js +1 -1
  180. package/src/components/global-styles/dimensions-panel.js +43 -573
  181. package/src/components/global-styles/duotone-panel.js +82 -0
  182. package/src/components/global-styles/filter-utils.js +9 -0
  183. package/src/components/global-styles/gradients-palette-panel.js +4 -1
  184. package/src/components/global-styles/header.js +7 -1
  185. package/src/components/global-styles/hooks.js +17 -90
  186. package/src/components/global-styles/palette.js +1 -1
  187. package/src/components/global-styles/preview.js +155 -140
  188. package/src/components/global-styles/screen-background-color.js +3 -2
  189. package/src/components/global-styles/screen-block-list.js +16 -5
  190. package/src/components/global-styles/screen-button-color.js +8 -6
  191. package/src/components/global-styles/screen-colors.js +7 -7
  192. package/src/components/global-styles/screen-filters.js +27 -0
  193. package/src/components/global-styles/screen-heading-color.js +9 -7
  194. package/src/components/global-styles/screen-layout.js +9 -2
  195. package/src/components/global-styles/screen-link-color.js +3 -2
  196. package/src/components/global-styles/screen-text-color.js +3 -2
  197. package/src/components/global-styles/screen-typography.js +1 -1
  198. package/src/components/global-styles/shadow-panel.js +6 -3
  199. package/src/components/global-styles/style.scss +5 -0
  200. package/src/components/global-styles/subtitle.js +5 -2
  201. package/src/components/global-styles/typography-panel.js +29 -395
  202. package/src/components/global-styles/ui.js +5 -0
  203. package/src/components/keyboard-shortcut-help-modal/config.js +10 -0
  204. package/src/components/keyboard-shortcuts/index.js +70 -0
  205. package/src/components/navigation-inspector/index.js +0 -32
  206. package/src/components/navigation-inspector/navigation-menu.js +24 -6
  207. package/src/components/sidebar-edit-mode/index.js +1 -1
  208. package/src/components/sidebar-edit-mode/template-card/index.js +24 -14
  209. package/src/components/sidebar-edit-mode/template-card/last-revision.js +75 -0
  210. package/src/components/sidebar-edit-mode/template-card/style.scss +4 -0
  211. package/src/components/sidebar-navigation-screen-navigation-menus/index.js +7 -1
  212. package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +0 -4
  213. package/src/components/start-template-options/index.js +171 -0
  214. package/src/components/start-template-options/style.scss +76 -0
  215. package/src/hooks/push-changes-to-global-styles/index.js +26 -21
  216. package/src/store/actions.js +2 -2
  217. package/src/style.scss +1 -0
@@ -4,9 +4,11 @@
4
4
  import {
5
5
  privateApis as blockEditorPrivateApis,
6
6
  store as blockEditorStore,
7
+ BlockList,
8
+ BlockTools,
7
9
  } from '@wordpress/block-editor';
8
10
  import { useEffect } from '@wordpress/element';
9
- import { useDispatch } from '@wordpress/data';
11
+ import { useSelect, useDispatch } from '@wordpress/data';
10
12
 
11
13
  /**
12
14
  * Internal dependencies
@@ -34,9 +36,16 @@ const ALLOWED_BLOCKS = {
34
36
  'core/navigation-link',
35
37
  'core/navigation-submenu',
36
38
  ],
39
+ 'core/page-list': [ 'core/page-list-item' ],
37
40
  };
38
41
 
39
42
  export default function NavigationMenu( { innerBlocks, onSelect } ) {
43
+ const { clientIdsTree } = useSelect( ( select ) => {
44
+ const { __unstableGetClientIdsTree } = select( blockEditorStore );
45
+ return {
46
+ clientIdsTree: __unstableGetClientIdsTree(),
47
+ };
48
+ } );
40
49
  const { updateBlockListSettings } = useDispatch( blockEditorStore );
41
50
 
42
51
  const { OffCanvasEditor, LeafMoreMenu } = unlock( blockEditorPrivateApis );
@@ -56,11 +65,20 @@ export default function NavigationMenu( { innerBlocks, onSelect } ) {
56
65
  } );
57
66
  }, [ updateBlockListSettings, innerBlocks ] );
58
67
 
68
+ // The hidden block is needed because it makes block edit side effects trigger.
69
+ // For example a navigation page list load its items has an effect on edit to load its items.
59
70
  return (
60
- <OffCanvasEditor
61
- blocks={ innerBlocks }
62
- onSelect={ onSelect }
63
- LeafMoreMenu={ LeafMoreMenu }
64
- />
71
+ <>
72
+ <OffCanvasEditor
73
+ blocks={ clientIdsTree }
74
+ onSelect={ onSelect }
75
+ LeafMoreMenu={ LeafMoreMenu }
76
+ />
77
+ <div style={ { display: 'none' } }>
78
+ <BlockTools>
79
+ <BlockList />
80
+ </BlockTools>
81
+ </div>
82
+ </>
65
83
  );
66
84
  }
@@ -69,7 +69,7 @@ export function SidebarComplementaryAreaFills() {
69
69
  identifier={ sidebarName }
70
70
  title={ __( 'Settings' ) }
71
71
  icon={ isRTL() ? drawerLeft : drawerRight }
72
- closeLabel={ __( 'Close settings sidebar' ) }
72
+ closeLabel={ __( 'Close settings' ) }
73
73
  header={ <SettingsHeader sidebarName={ sidebarName } /> }
74
74
  headerClassName="edit-site-sidebar-edit-mode__panel-tabs"
75
75
  >
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
+ import { __ } from '@wordpress/i18n';
4
5
  import { useSelect } from '@wordpress/data';
5
- import { Icon } from '@wordpress/components';
6
+ import { PanelRow, Icon } from '@wordpress/components';
6
7
  import { store as editorStore } from '@wordpress/editor';
7
8
  import { store as coreStore } from '@wordpress/core-data';
8
9
  import { decodeEntities } from '@wordpress/html-entities';
@@ -13,6 +14,7 @@ import { decodeEntities } from '@wordpress/html-entities';
13
14
  import { store as editSiteStore } from '../../../store';
14
15
  import TemplateActions from './template-actions';
15
16
  import TemplateAreas from './template-areas';
17
+ import LastRevision from './last-revision';
16
18
 
17
19
  export default function TemplateCard() {
18
20
  const {
@@ -38,20 +40,28 @@ export default function TemplateCard() {
38
40
  }
39
41
 
40
42
  return (
41
- <div className="edit-site-template-card">
42
- <Icon className="edit-site-template-card__icon" icon={ icon } />
43
- <div className="edit-site-template-card__content">
44
- <div className="edit-site-template-card__header">
45
- <h2 className="edit-site-template-card__title">
46
- { decodeEntities( title ) }
47
- </h2>
48
- <TemplateActions template={ template } />
43
+ <>
44
+ <div className="edit-site-template-card">
45
+ <Icon className="edit-site-template-card__icon" icon={ icon } />
46
+ <div className="edit-site-template-card__content">
47
+ <div className="edit-site-template-card__header">
48
+ <h2 className="edit-site-template-card__title">
49
+ { decodeEntities( title ) }
50
+ </h2>
51
+ <TemplateActions template={ template } />
52
+ </div>
53
+ <div className="edit-site-template-card__description">
54
+ { decodeEntities( description ) }
55
+ </div>
56
+ <TemplateAreas />
49
57
  </div>
50
- <div className="edit-site-template-card__description">
51
- { decodeEntities( description ) }
52
- </div>
53
- <TemplateAreas />
54
58
  </div>
55
- </div>
59
+ <PanelRow
60
+ header={ __( 'Editing history' ) }
61
+ className="edit-site-template-revisions"
62
+ >
63
+ <LastRevision />
64
+ </PanelRow>
65
+ </>
56
66
  );
57
67
  }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Button } from '@wordpress/components';
5
+ import { sprintf, _n } from '@wordpress/i18n';
6
+ import { backup } from '@wordpress/icons';
7
+ import { addQueryArgs } from '@wordpress/url';
8
+ import { PostTypeSupportCheck } from '@wordpress/editor';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import useEditedEntityRecord from '../../use-edited-entity-record';
14
+
15
+ const useRevisionData = () => {
16
+ const { record: currentTemplate } = useEditedEntityRecord();
17
+
18
+ const lastRevisionId =
19
+ currentTemplate?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id ?? null;
20
+
21
+ const revisionsCount =
22
+ ( currentTemplate?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0 ) +
23
+ 1;
24
+
25
+ return {
26
+ currentTemplate,
27
+ lastRevisionId,
28
+ revisionsCount,
29
+ };
30
+ };
31
+
32
+ function PostLastRevisionCheck( { children } ) {
33
+ const { lastRevisionId, revisionsCount } = useRevisionData();
34
+
35
+ if ( ! lastRevisionId || revisionsCount < 2 ) {
36
+ return null;
37
+ }
38
+
39
+ return (
40
+ <PostTypeSupportCheck supportKeys="revisions">
41
+ { children }
42
+ </PostTypeSupportCheck>
43
+ );
44
+ }
45
+
46
+ const PostLastRevision = () => {
47
+ const { lastRevisionId, revisionsCount } = useRevisionData();
48
+
49
+ return (
50
+ <PostLastRevisionCheck>
51
+ <Button
52
+ href={ addQueryArgs( 'revision.php', {
53
+ revision: lastRevisionId,
54
+ gutenberg: true,
55
+ } ) }
56
+ className="edit-site-template-last-revision__title"
57
+ icon={ backup }
58
+ >
59
+ { sprintf(
60
+ /* translators: %d: number of revisions */
61
+ _n( '%d Revision', '%d Revisions', revisionsCount ),
62
+ revisionsCount
63
+ ) }
64
+ </Button>
65
+ </PostLastRevisionCheck>
66
+ );
67
+ };
68
+
69
+ export default function LastRevision() {
70
+ return (
71
+ <PostLastRevisionCheck>
72
+ <PostLastRevision />
73
+ </PostLastRevisionCheck>
74
+ );
75
+ }
@@ -59,6 +59,10 @@
59
59
  }
60
60
  }
61
61
 
62
+ .edit-site-template-revisions {
63
+ margin-left: math.div(-$grid-unit-10, 2);
64
+ }
65
+
62
66
  h3.edit-site-template-card__template-areas-title {
63
67
  font-weight: 500;
64
68
  margin: 0 0 $grid-unit-10;
@@ -15,7 +15,7 @@ export default function SidebarNavigationScreenNavigationMenus() {
15
15
  const history = useHistory();
16
16
  const onSelect = useCallback(
17
17
  ( selectedBlock ) => {
18
- const { attributes } = selectedBlock;
18
+ const { attributes, name } = selectedBlock;
19
19
  if (
20
20
  attributes.kind === 'post-type' &&
21
21
  attributes.id &&
@@ -27,6 +27,12 @@ export default function SidebarNavigationScreenNavigationMenus() {
27
27
  postId: attributes.id,
28
28
  } );
29
29
  }
30
+ if ( name === 'core/page-list-item' && attributes.id && history ) {
31
+ history.push( {
32
+ postType: 'page',
33
+ postId: attributes.id,
34
+ } );
35
+ }
30
36
  },
31
37
  [ history ]
32
38
  );
@@ -1,8 +1,4 @@
1
1
  .edit-site-sidebar-navigation-screen-navigation-menus {
2
- .block-editor-list-view-block__menu-edit,
3
- .edit-site-navigation-inspector__select-menu {
4
- display: none;
5
- }
6
2
  .offcanvas-editor-list-view-leaf {
7
3
  max-width: calc(100% - #{ $grid-unit-05 });
8
4
  }
@@ -0,0 +1,171 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Modal } from '@wordpress/components';
5
+ import { __ } from '@wordpress/i18n';
6
+ import { useState, useEffect, useMemo } from '@wordpress/element';
7
+ import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
8
+ import { useSelect } from '@wordpress/data';
9
+ import { useAsyncList } from '@wordpress/compose';
10
+ import { store as preferencesStore } from '@wordpress/preferences';
11
+ import { parse } from '@wordpress/blocks';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import { store as editSiteStore } from '../../store';
17
+ import { store as coreStore, useEntityBlockEditor } from '@wordpress/core-data';
18
+ import apiFetch from '@wordpress/api-fetch';
19
+ import { addQueryArgs } from '@wordpress/url';
20
+
21
+ function useFallbackTemplateContent( slug, isCustom = false ) {
22
+ const [ templateContent, setTemplateContent ] = useState( '' );
23
+
24
+ useEffect( () => {
25
+ apiFetch( {
26
+ path: addQueryArgs( '/wp/v2/templates/lookup', {
27
+ slug,
28
+ is_custom: isCustom,
29
+ ignore_empty: true,
30
+ } ),
31
+ } ).then( ( { content } ) => setTemplateContent( content.raw ) );
32
+ }, [ slug ] );
33
+ return templateContent;
34
+ }
35
+
36
+ const START_BLANK_TITLE = __( 'Start blank' );
37
+
38
+ function PatternSelection( { fallbackContent, onChoosePattern, postType } ) {
39
+ const [ , , onChange ] = useEntityBlockEditor( 'postType', postType );
40
+ const blockPatterns = useMemo(
41
+ () => [
42
+ {
43
+ name: 'fallback',
44
+ blocks: parse( fallbackContent ),
45
+ title: __( 'Fallback content' ),
46
+ },
47
+ {
48
+ name: 'start-blank',
49
+ blocks: parse(
50
+ '<!-- wp:paragraph --><p></p><!-- /wp:paragraph -->'
51
+ ),
52
+ title: START_BLANK_TITLE,
53
+ },
54
+ ],
55
+ [ fallbackContent ]
56
+ );
57
+ const shownBlockPatterns = useAsyncList( blockPatterns );
58
+
59
+ return (
60
+ <div
61
+ className="edit-site-start-template-options__pattern-container"
62
+ style={ {
63
+ '--wp-edit-site-start-template-options-start-blank': `"${ START_BLANK_TITLE }"`,
64
+ } }
65
+ >
66
+ <BlockPatternsList
67
+ blockPatterns={ blockPatterns }
68
+ shownPatterns={ shownBlockPatterns }
69
+ onClickPattern={ ( pattern, blocks ) => {
70
+ onChange( 'start-blank' === pattern.name ? [] : blocks, {
71
+ selection: undefined,
72
+ } );
73
+ onChoosePattern();
74
+ } }
75
+ />
76
+ </div>
77
+ );
78
+ }
79
+
80
+ function StartModal( { slug, isCustom, onClose, postType } ) {
81
+ const fallbackContent = useFallbackTemplateContent( slug, isCustom );
82
+ if ( ! fallbackContent ) {
83
+ return null;
84
+ }
85
+ return (
86
+ <Modal
87
+ className="edit-site-start-template-options__modal"
88
+ title={ __( 'Choose a pattern' ) }
89
+ closeLabel={ __( 'Cancel' ) }
90
+ focusOnMount="firstElement"
91
+ onRequestClose={ onClose }
92
+ >
93
+ <div className="edit-site-start-template-options__modal-content">
94
+ <PatternSelection
95
+ fallbackContent={ fallbackContent }
96
+ slug={ slug }
97
+ isCustom={ isCustom }
98
+ postType={ postType }
99
+ onChoosePattern={ () => {
100
+ onClose();
101
+ } }
102
+ />
103
+ </div>
104
+ </Modal>
105
+ );
106
+ }
107
+
108
+ const START_TEMPLATE_MODAL_STATES = {
109
+ INITIAL: 'INITIAL',
110
+ CLOSED: 'CLOSED',
111
+ };
112
+
113
+ export default function StartTemplateOptions() {
114
+ const [ modalState, setModalState ] = useState(
115
+ START_TEMPLATE_MODAL_STATES.INITIAL
116
+ );
117
+ const { shouldOpenModel, slug, isCustom, postType } = useSelect(
118
+ ( select ) => {
119
+ const { getEditedPostType, getEditedPostId } =
120
+ select( editSiteStore );
121
+ const _postType = getEditedPostType();
122
+ const postId = getEditedPostId();
123
+ const {
124
+ __experimentalGetDirtyEntityRecords,
125
+ getEditedEntityRecord,
126
+ } = select( coreStore );
127
+ const templateRecord = getEditedEntityRecord(
128
+ 'postType',
129
+ _postType,
130
+ postId
131
+ );
132
+
133
+ const hasDirtyEntityRecords =
134
+ __experimentalGetDirtyEntityRecords().length > 0;
135
+
136
+ return {
137
+ shouldOpenModel:
138
+ ! hasDirtyEntityRecords &&
139
+ '' === templateRecord.content &&
140
+ 'wp_template' === _postType &&
141
+ ! select( preferencesStore ).get(
142
+ 'core/edit-site',
143
+ 'welcomeGuide'
144
+ ),
145
+ slug: templateRecord.slug,
146
+ isCustom: templateRecord.is_custom,
147
+ postType: _postType,
148
+ };
149
+ },
150
+ []
151
+ );
152
+
153
+ if (
154
+ ( modalState === START_TEMPLATE_MODAL_STATES.INITIAL &&
155
+ ! shouldOpenModel ) ||
156
+ modalState === START_TEMPLATE_MODAL_STATES.CLOSED
157
+ ) {
158
+ return null;
159
+ }
160
+
161
+ return (
162
+ <StartModal
163
+ slug={ slug }
164
+ isCustom={ isCustom }
165
+ postType={ postType }
166
+ onClose={ () =>
167
+ setModalState( START_TEMPLATE_MODAL_STATES.CLOSED )
168
+ }
169
+ />
170
+ );
171
+ }
@@ -0,0 +1,76 @@
1
+ .edit-site-start-template-options__modal.components-modal__frame {
2
+ // To keep modal dimensions consistent as subsections are navigated, width
3
+ // and height are used instead of max-(width/height).
4
+ @include break-small() {
5
+ width: calc(100% - #{ $grid-unit-20 * 2 });
6
+ height: calc(100% - #{ $header-height * 2 });
7
+ }
8
+ @include break-medium() {
9
+ width: 50%;
10
+ }
11
+ @include break-large() {
12
+ height: fit-content;
13
+ }
14
+ }
15
+
16
+ .edit-site-start-template-options__modal-content .block-editor-block-patterns-list {
17
+ display: grid;
18
+ width: 100%;
19
+ margin-top: $grid-unit-05;
20
+ gap: $grid-unit-30;
21
+ grid-template-columns: repeat(auto-fit, minmax(min(100%/2, max(240px, 100%/10)), 1fr));
22
+ .block-editor-block-patterns-list__list-item {
23
+ break-inside: avoid-column;
24
+ margin-bottom: 0;
25
+ width: 100%;
26
+ aspect-ratio: 3/4;
27
+
28
+ .block-editor-block-preview__container {
29
+ height: 100%;
30
+ box-shadow: 0 0 0 1px $gray-300;
31
+ }
32
+
33
+ .block-editor-block-preview__content {
34
+ width: 100%;
35
+ position: absolute;
36
+ }
37
+
38
+ .block-editor-block-patterns-list__item-title {
39
+ display: none;
40
+ }
41
+
42
+ &:hover {
43
+ .block-editor-block-preview__container {
44
+ box-shadow: 0 0 0 2px var(--wp-admin-theme-color);
45
+ }
46
+ }
47
+
48
+ &:focus {
49
+ .block-editor-block-preview__container {
50
+ box-shadow: inset 0 0 0 1px $white, 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
51
+
52
+ // Windows High Contrast mode will show this outline, but not the box-shadow.
53
+ outline: 2px solid transparent;
54
+ }
55
+ }
56
+ }
57
+
58
+ // The start blank pattern is the last and we are selecting it.
59
+ .block-editor-block-patterns-list__list-item:nth-last-child(2) {
60
+ .block-editor-block-preview__container {
61
+ position: absolute;
62
+ padding: 0;
63
+ background: #f0f0f0;
64
+ &::after {
65
+ width: 100%;
66
+ top: 50%;
67
+ margin-top: -1em;
68
+ content: var(--wp-edit-site-start-template-options-start-blank);
69
+ text-align: center;
70
+ }
71
+ }
72
+ iframe {
73
+ display: none;
74
+ }
75
+ }
76
+ }
@@ -26,7 +26,7 @@ import { store as noticesStore } from '@wordpress/notices';
26
26
  /**
27
27
  * Internal dependencies
28
28
  */
29
- import { getSupportedGlobalStylesPanels } from '../../components/global-styles/hooks';
29
+ import { useSupportedStyles } from '../../components/global-styles/hooks';
30
30
  import { unlock } from '../../private-apis';
31
31
 
32
32
  const { GlobalStylesContext } = unlock( blockEditorPrivateApis );
@@ -90,22 +90,30 @@ const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
90
90
  'typography.fontFamily': 'fontFamily',
91
91
  };
92
92
 
93
- function getChangesToPush( name, attributes ) {
94
- return getSupportedGlobalStylesPanels( name ).flatMap( ( key ) => {
95
- if ( ! STYLE_PROPERTY[ key ] ) {
96
- return [];
97
- }
98
- const { value: path } = STYLE_PROPERTY[ key ];
99
- const presetAttributeKey = path.join( '.' );
100
- const presetAttributeValue =
101
- attributes[
102
- STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[ presetAttributeKey ]
103
- ];
104
- const value = presetAttributeValue
105
- ? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`
106
- : get( attributes.style, path );
107
- return value ? [ { path, value } ] : [];
108
- } );
93
+ function useChangesToPush( name, attributes ) {
94
+ const supports = useSupportedStyles( name );
95
+
96
+ return useMemo(
97
+ () =>
98
+ supports.flatMap( ( key ) => {
99
+ if ( ! STYLE_PROPERTY[ key ] ) {
100
+ return [];
101
+ }
102
+ const { value: path } = STYLE_PROPERTY[ key ];
103
+ const presetAttributeKey = path.join( '.' );
104
+ const presetAttributeValue =
105
+ attributes[
106
+ STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE[
107
+ presetAttributeKey
108
+ ]
109
+ ];
110
+ const value = presetAttributeValue
111
+ ? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`
112
+ : get( attributes.style, path );
113
+ return value ? [ { path, value } ] : [];
114
+ } ),
115
+ [ supports, name, attributes ]
116
+ );
109
117
  }
110
118
 
111
119
  function cloneDeep( object ) {
@@ -117,10 +125,7 @@ function PushChangesToGlobalStylesControl( {
117
125
  attributes,
118
126
  setAttributes,
119
127
  } ) {
120
- const changes = useMemo(
121
- () => getChangesToPush( name, attributes ),
122
- [ name, attributes ]
123
- );
128
+ const changes = useChangesToPush( name, attributes );
124
129
 
125
130
  const { user: userConfig, setUserConfig } =
126
131
  useContext( GlobalStylesContext );
@@ -526,7 +526,7 @@ export const switchEditorMode =
526
526
 
527
527
  if ( mode === 'visual' ) {
528
528
  speak( __( 'Visual editor selected' ), 'assertive' );
529
- } else if ( mode === 'mosaic' ) {
530
- speak( __( 'Mosaic view selected' ), 'assertive' );
529
+ } else if ( mode === 'text' ) {
530
+ speak( __( 'Code editor selected' ), 'assertive' );
531
531
  }
532
532
  };
package/src/style.scss CHANGED
@@ -17,6 +17,7 @@
17
17
  @import "./components/create-template-part-modal/style.scss";
18
18
  @import "./components/secondary-sidebar/style.scss";
19
19
  @import "./components/welcome-guide/style.scss";
20
+ @import "./components/start-template-options/style.scss";
20
21
  @import "./components/keyboard-shortcut-help-modal/style.scss";
21
22
  @import "./components/layout/style.scss";
22
23
  @import "./components/save-panel/style.scss";