@wordpress/block-library 6.0.6 → 6.0.10

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 (187) hide show
  1. package/build/cover/edit.js +8 -3
  2. package/build/cover/edit.js.map +1 -1
  3. package/build/cover/transforms.js +2 -0
  4. package/build/cover/transforms.js.map +1 -1
  5. package/build/gallery/edit.js +1 -1
  6. package/build/gallery/edit.js.map +1 -1
  7. package/build/gallery/v1/update-gallery-modal.js +1 -1
  8. package/build/gallery/v1/update-gallery-modal.js.map +1 -1
  9. package/build/index.js +4 -3
  10. package/build/index.js.map +1 -1
  11. package/build/navigation/deprecated.js +118 -12
  12. package/build/navigation/deprecated.js.map +1 -1
  13. package/build/navigation/edit/index.js +59 -33
  14. package/build/navigation/edit/index.js.map +1 -1
  15. package/build/navigation/edit/inner-blocks.js +1 -1
  16. package/build/navigation/edit/inner-blocks.js.map +1 -1
  17. package/build/navigation/edit/navigation-menu-selector.js +2 -2
  18. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  19. package/build/navigation/edit/placeholder/index.js +16 -48
  20. package/build/navigation/edit/placeholder/index.js.map +1 -1
  21. package/build/navigation/edit/responsive-wrapper.js +5 -2
  22. package/build/navigation/edit/responsive-wrapper.js.map +1 -1
  23. package/build/navigation/edit/unsaved-inner-blocks.js +4 -35
  24. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  25. package/build/navigation/edit/use-create-navigation-menu.js +50 -0
  26. package/build/navigation/edit/use-create-navigation-menu.js.map +1 -0
  27. package/build/navigation/edit/use-generate-default-navigation-title.js +73 -0
  28. package/build/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
  29. package/build/navigation/index.js +1 -1
  30. package/build/navigation/save.js +2 -2
  31. package/build/navigation/save.js.map +1 -1
  32. package/build/navigation/use-navigation-menu.js +19 -8
  33. package/build/navigation/use-navigation-menu.js.map +1 -1
  34. package/build/navigation-area/edit.js +5 -0
  35. package/build/navigation-area/edit.js.map +1 -1
  36. package/build/page-list/edit.js +40 -42
  37. package/build/page-list/edit.js.map +1 -1
  38. package/build/pattern/index.js +1 -1
  39. package/build/post-featured-image/edit.js +53 -23
  40. package/build/post-featured-image/edit.js.map +1 -1
  41. package/build/post-terms/index.js +1 -1
  42. package/build/post-title/edit.js +2 -2
  43. package/build/post-title/edit.js.map +1 -1
  44. package/build/query-title/index.js +1 -1
  45. package/build/site-logo/index.js +1 -1
  46. package/build/site-tagline/index.js +1 -1
  47. package/build/site-title/index.js +1 -1
  48. package/build/template-part/edit/placeholder/index.js +1 -1
  49. package/build/template-part/edit/placeholder/index.js.map +1 -1
  50. package/build/template-part/index.js +2 -1
  51. package/build/template-part/index.js.map +1 -1
  52. package/build-module/cover/edit.js +8 -3
  53. package/build-module/cover/edit.js.map +1 -1
  54. package/build-module/cover/transforms.js +2 -0
  55. package/build-module/cover/transforms.js.map +1 -1
  56. package/build-module/gallery/edit.js +1 -1
  57. package/build-module/gallery/edit.js.map +1 -1
  58. package/build-module/gallery/v1/update-gallery-modal.js +1 -1
  59. package/build-module/gallery/v1/update-gallery-modal.js.map +1 -1
  60. package/build-module/index.js +4 -3
  61. package/build-module/index.js.map +1 -1
  62. package/build-module/navigation/deprecated.js +118 -12
  63. package/build-module/navigation/deprecated.js.map +1 -1
  64. package/build-module/navigation/edit/index.js +60 -33
  65. package/build-module/navigation/edit/index.js.map +1 -1
  66. package/build-module/navigation/edit/inner-blocks.js +1 -1
  67. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  68. package/build-module/navigation/edit/navigation-menu-selector.js +2 -2
  69. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  70. package/build-module/navigation/edit/placeholder/index.js +15 -45
  71. package/build-module/navigation/edit/placeholder/index.js.map +1 -1
  72. package/build-module/navigation/edit/responsive-wrapper.js +5 -2
  73. package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
  74. package/build-module/navigation/edit/unsaved-inner-blocks.js +6 -35
  75. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  76. package/build-module/navigation/edit/use-create-navigation-menu.js +36 -0
  77. package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -0
  78. package/build-module/navigation/edit/use-generate-default-navigation-title.js +57 -0
  79. package/build-module/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
  80. package/build-module/navigation/index.js +1 -1
  81. package/build-module/navigation/save.js +2 -2
  82. package/build-module/navigation/save.js.map +1 -1
  83. package/build-module/navigation/use-navigation-menu.js +19 -8
  84. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  85. package/build-module/navigation-area/edit.js +4 -0
  86. package/build-module/navigation-area/edit.js.map +1 -1
  87. package/build-module/page-list/edit.js +41 -43
  88. package/build-module/page-list/edit.js.map +1 -1
  89. package/build-module/pattern/index.js +1 -1
  90. package/build-module/post-featured-image/edit.js +55 -26
  91. package/build-module/post-featured-image/edit.js.map +1 -1
  92. package/build-module/post-terms/index.js +1 -1
  93. package/build-module/post-title/edit.js +2 -2
  94. package/build-module/post-title/edit.js.map +1 -1
  95. package/build-module/query-title/index.js +1 -1
  96. package/build-module/site-logo/index.js +1 -1
  97. package/build-module/site-tagline/index.js +1 -1
  98. package/build-module/site-title/index.js +1 -1
  99. package/build-module/template-part/edit/placeholder/index.js +2 -2
  100. package/build-module/template-part/edit/placeholder/index.js.map +1 -1
  101. package/build-module/template-part/index.js +2 -1
  102. package/build-module/template-part/index.js.map +1 -1
  103. package/build-style/code/theme-rtl.css +1 -1
  104. package/build-style/code/theme.css +1 -1
  105. package/build-style/cover/style-rtl.css +8 -2
  106. package/build-style/cover/style.css +8 -2
  107. package/build-style/editor-rtl.css +104 -53
  108. package/build-style/editor.css +104 -53
  109. package/build-style/gallery/editor-rtl.css +1 -0
  110. package/build-style/gallery/editor.css +1 -0
  111. package/build-style/navigation/style-rtl.css +40 -3
  112. package/build-style/navigation/style.css +40 -3
  113. package/build-style/post-comments-form/style-rtl.css +18 -0
  114. package/build-style/post-comments-form/style.css +18 -0
  115. package/build-style/post-featured-image/editor-rtl.css +100 -16
  116. package/build-style/post-featured-image/editor.css +100 -16
  117. package/build-style/site-logo/editor-rtl.css +2 -2
  118. package/build-style/site-logo/editor.css +2 -2
  119. package/build-style/social-links/editor-rtl.css +1 -35
  120. package/build-style/social-links/editor.css +1 -35
  121. package/build-style/style-rtl.css +66 -27
  122. package/build-style/style.css +66 -27
  123. package/build-style/theme-rtl.css +1 -1
  124. package/build-style/theme.css +1 -1
  125. package/package.json +8 -8
  126. package/src/calendar/index.php +3 -3
  127. package/src/code/theme.scss +1 -1
  128. package/src/cover/edit.js +8 -1
  129. package/src/cover/style.scss +9 -2
  130. package/src/cover/transforms.js +2 -0
  131. package/src/gallery/edit.js +1 -1
  132. package/src/gallery/editor.scss +1 -0
  133. package/src/gallery/index.php +1 -1
  134. package/src/gallery/v1/update-gallery-modal.js +1 -1
  135. package/src/home-link/index.php +1 -1
  136. package/src/image/index.php +1 -1
  137. package/src/index.js +28 -26
  138. package/src/navigation/block.json +1 -1
  139. package/src/navigation/deprecated.js +105 -4
  140. package/src/navigation/edit/index.js +68 -36
  141. package/src/navigation/edit/inner-blocks.js +2 -1
  142. package/src/navigation/edit/navigation-menu-selector.js +2 -2
  143. package/src/navigation/edit/placeholder/index.js +16 -62
  144. package/src/navigation/edit/responsive-wrapper.js +8 -1
  145. package/src/navigation/edit/unsaved-inner-blocks.js +6 -57
  146. package/src/navigation/edit/use-create-navigation-menu.js +39 -0
  147. package/src/navigation/edit/use-generate-default-navigation-title.js +79 -0
  148. package/src/navigation/index.php +173 -19
  149. package/src/navigation/save.js +2 -2
  150. package/src/navigation/style.scss +56 -5
  151. package/src/navigation/use-navigation-menu.js +20 -9
  152. package/src/navigation-area/edit.js +5 -0
  153. package/src/navigation-area/index.php +2 -1
  154. package/src/navigation-link/index.php +1 -1
  155. package/src/navigation-submenu/index.php +2 -8
  156. package/src/page-list/edit.js +35 -44
  157. package/src/page-list/index.php +10 -5
  158. package/src/pattern/block.json +1 -1
  159. package/src/post-comments-form/style.scss +20 -1
  160. package/src/post-featured-image/edit.js +58 -26
  161. package/src/post-featured-image/editor.scss +124 -20
  162. package/src/post-terms/block.json +1 -1
  163. package/src/post-title/edit.js +2 -2
  164. package/src/query-title/block.json +1 -1
  165. package/src/site-logo/block.json +1 -1
  166. package/src/site-logo/editor.scss +3 -2
  167. package/src/site-tagline/block.json +1 -1
  168. package/src/site-title/block.json +1 -1
  169. package/src/social-links/editor.scss +1 -47
  170. package/src/style.scss +0 -1
  171. package/src/table-of-contents/index.php +1 -1
  172. package/src/template-part/block.json +2 -1
  173. package/src/template-part/edit/placeholder/index.js +2 -2
  174. package/src/template-part/index.php +2 -1
  175. package/build/navigation/edit/navigation-menu-name-modal.js +0 -55
  176. package/build/navigation/edit/navigation-menu-name-modal.js.map +0 -1
  177. package/build/navigation/edit/navigation-menu-publish-button.js +0 -53
  178. package/build/navigation/edit/navigation-menu-publish-button.js.map +0 -1
  179. package/build-module/navigation/edit/navigation-menu-name-modal.js +0 -47
  180. package/build-module/navigation/edit/navigation-menu-name-modal.js.map +0 -1
  181. package/build-module/navigation/edit/navigation-menu-publish-button.js +0 -40
  182. package/build-module/navigation/edit/navigation-menu-publish-button.js.map +0 -1
  183. package/build-style/navigation-submenu/style-rtl.css +0 -97
  184. package/build-style/navigation-submenu/style.css +0 -97
  185. package/src/navigation/edit/navigation-menu-name-modal.js +0 -69
  186. package/src/navigation/edit/navigation-menu-publish-button.js +0 -57
  187. package/src/navigation-submenu/style.scss +0 -25
@@ -34,6 +34,7 @@ import {
34
34
  __experimentalToggleGroupControlOption as ToggleGroupControlOption,
35
35
  ToolbarGroup,
36
36
  ToolbarDropdownMenu,
37
+ Button,
37
38
  } from '@wordpress/components';
38
39
  import { __ } from '@wordpress/i18n';
39
40
 
@@ -48,7 +49,6 @@ import ResponsiveWrapper from './responsive-wrapper';
48
49
  import NavigationInnerBlocks from './inner-blocks';
49
50
  import NavigationMenuSelector from './navigation-menu-selector';
50
51
  import NavigationMenuNameControl from './navigation-menu-name-control';
51
- import NavigationMenuPublishButton from './navigation-menu-publish-button';
52
52
  import UnsavedInnerBlocks from './unsaved-inner-blocks';
53
53
  import NavigationMenuDeleteControl from './navigation-menu-delete-control';
54
54
 
@@ -118,13 +118,11 @@ function Navigation( {
118
118
 
119
119
  const navigationAreaMenu = areaMenu === 0 ? undefined : areaMenu;
120
120
 
121
- const navigationMenuId = navigationArea
122
- ? navigationAreaMenu
123
- : attributes.navigationMenuId;
121
+ const ref = navigationArea ? navigationAreaMenu : attributes.ref;
124
122
 
125
- const setNavigationMenuId = useCallback(
123
+ const setRef = useCallback(
126
124
  ( postId ) => {
127
- setAttributes( { navigationMenuId: postId } );
125
+ setAttributes( { ref: postId } );
128
126
  if ( navigationArea ) {
129
127
  setAreaMenu( postId );
130
128
  }
@@ -133,7 +131,7 @@ function Navigation( {
133
131
  );
134
132
 
135
133
  const [ hasAlreadyRendered, RecursionProvider ] = useNoRecursiveRenders(
136
- `navigationMenu/${ navigationMenuId }`
134
+ `navigationMenu/${ ref }`
137
135
  );
138
136
 
139
137
  const { innerBlocks, isInnerBlockSelected } = useSelect(
@@ -160,7 +158,7 @@ function Navigation( {
160
158
  setHasSavedUnsavedInnerBlocks,
161
159
  ] = useState( false );
162
160
 
163
- const isWithinUnassignedArea = navigationArea && ! navigationMenuId;
161
+ const isWithinUnassignedArea = navigationArea && ! ref;
164
162
 
165
163
  const [ isPlaceholderShown, setIsPlaceholderShown ] = useState(
166
164
  ! hasExistingNavItems || isWithinUnassignedArea
@@ -177,7 +175,7 @@ function Navigation( {
177
175
  hasResolvedNavigationMenus,
178
176
  navigationMenus,
179
177
  navigationMenu,
180
- } = useNavigationMenu( navigationMenuId );
178
+ } = useNavigationMenu( ref );
181
179
 
182
180
  const navRef = useRef();
183
181
  const isDraftNavigationMenu = navigationMenu?.status === 'draft';
@@ -212,6 +210,29 @@ function Navigation( {
212
210
  },
213
211
  } );
214
212
 
213
+ const overlayClassnames = classnames( {
214
+ 'has-text-color':
215
+ !! overlayTextColor.color || !! overlayTextColor?.class,
216
+ [ getColorClassName(
217
+ 'color',
218
+ overlayTextColor?.slug
219
+ ) ]: !! overlayTextColor?.slug,
220
+ 'has-background':
221
+ !! overlayBackgroundColor.color || overlayBackgroundColor?.class,
222
+ [ getColorClassName(
223
+ 'background-color',
224
+ overlayBackgroundColor?.slug
225
+ ) ]: !! overlayBackgroundColor?.slug,
226
+ } );
227
+
228
+ const overlayStyles = {
229
+ color: ! overlayTextColor?.slug && overlayTextColor?.color,
230
+ backgroundColor:
231
+ ! overlayBackgroundColor?.slug &&
232
+ overlayBackgroundColor?.color &&
233
+ overlayBackgroundColor.color,
234
+ };
235
+
215
236
  // Turn on contrast checker for web only since it's not supported on mobile yet.
216
237
  const enableContrastChecking = Platform.OS === 'web';
217
238
 
@@ -258,6 +279,27 @@ function Navigation( {
258
279
  setIsPlaceholderShown( ! isEntityAvailable );
259
280
  }, [ isEntityAvailable ] );
260
281
 
282
+ // If the ref no longer exists the reset the inner blocks
283
+ // to provide a clean slate.
284
+ useEffect( () => {
285
+ if ( ref === undefined && innerBlocks.length > 0 ) {
286
+ replaceInnerBlocks( clientId, [] );
287
+ }
288
+ // innerBlocks are intentionally not listed as deps. This function is only concerned
289
+ // with the snapshot from the time when ref became undefined.
290
+ }, [ clientId, ref, innerBlocks ] );
291
+
292
+ const startWithEmptyMenu = useCallback( () => {
293
+ if ( navigationArea ) {
294
+ setAreaMenu( 0 );
295
+ }
296
+ setAttributes( {
297
+ ref: undefined,
298
+ } );
299
+
300
+ setIsPlaceholderShown( true );
301
+ }, [ clientId ] );
302
+
261
303
  // If the block has inner blocks, but no menu id, this was an older
262
304
  // navigation block added before the block used a wp_navigation entity.
263
305
  // Either this block was saved in the content or inserted by a pattern.
@@ -277,7 +319,7 @@ function Navigation( {
277
319
  onSave={ ( post ) => {
278
320
  setHasSavedUnsavedInnerBlocks( true );
279
321
  // Switch to using the wp_navigation entity.
280
- setNavigationMenuId( post.id );
322
+ setRef( post.id );
281
323
  } }
282
324
  />
283
325
  );
@@ -285,13 +327,16 @@ function Navigation( {
285
327
 
286
328
  // Show a warning if the selected menu is no longer available.
287
329
  // TODO - the user should be able to select a new one?
288
- if ( navigationMenuId && isNavigationMenuMissing ) {
330
+ if ( ref && isNavigationMenuMissing ) {
289
331
  return (
290
332
  <div { ...blockProps }>
291
333
  <Warning>
292
334
  { __(
293
- 'Navigation menu has been deleted or is unavailable'
335
+ 'Navigation menu has been deleted or is unavailable. '
294
336
  ) }
337
+ <Button onClick={ startWithEmptyMenu } variant="link">
338
+ { __( 'Create a new menu?' ) }
339
+ </Button>
295
340
  </Warning>
296
341
  </div>
297
342
  );
@@ -312,11 +357,7 @@ function Navigation( {
312
357
  : Placeholder;
313
358
 
314
359
  return (
315
- <EntityProvider
316
- kind="postType"
317
- type="wp_navigation"
318
- id={ navigationMenuId }
319
- >
360
+ <EntityProvider kind="postType" type="wp_navigation" id={ ref }>
320
361
  <RecursionProvider>
321
362
  <BlockControls>
322
363
  { ! isDraftNavigationMenu && isEntityAvailable && (
@@ -329,29 +370,16 @@ function Navigation( {
329
370
  { ( { onClose } ) => (
330
371
  <NavigationMenuSelector
331
372
  onSelect={ ( { id } ) => {
332
- setNavigationMenuId( id );
373
+ setRef( id );
333
374
  onClose();
334
375
  } }
335
- onCreateNew={ () => {
336
- if ( navigationArea ) {
337
- setAreaMenu( 0 );
338
- }
339
- setAttributes( {
340
- navigationMenuId: undefined,
341
- } );
342
- setIsPlaceholderShown( true );
343
- } }
376
+ onCreateNew={ startWithEmptyMenu }
344
377
  />
345
378
  ) }
346
379
  </ToolbarDropdownMenu>
347
380
  </ToolbarGroup>
348
381
  ) }
349
382
  <ToolbarGroup>{ listViewToolbarButton }</ToolbarGroup>
350
- { isDraftNavigationMenu && (
351
- <ToolbarGroup>
352
- <NavigationMenuPublishButton />
353
- </ToolbarGroup>
354
- ) }
355
383
  </BlockControls>
356
384
  { listViewModal }
357
385
  <InspectorControls>
@@ -458,12 +486,11 @@ function Navigation( {
458
486
  <NavigationMenuNameControl />
459
487
  <NavigationMenuDeleteControl
460
488
  onDelete={ () => {
461
- replaceInnerBlocks( clientId, [] );
462
489
  if ( navigationArea ) {
463
490
  setAreaMenu( 0 );
464
491
  }
465
492
  setAttributes( {
466
- navigationMenuId: undefined,
493
+ ref: undefined,
467
494
  } );
468
495
  setIsPlaceholderShown( true );
469
496
  } }
@@ -471,17 +498,20 @@ function Navigation( {
471
498
  </InspectorControls>
472
499
  ) }
473
500
  <nav { ...blockProps }>
474
- { ! isEntityAvailable && isPlaceholderShown && (
501
+ { isPlaceholderShown && (
475
502
  <PlaceholderComponent
476
503
  onFinish={ ( post ) => {
477
504
  setIsPlaceholderShown( false );
478
- setNavigationMenuId( post.id );
505
+ if ( post ) {
506
+ setRef( post.id );
507
+ }
479
508
  selectBlock( clientId );
480
509
  } }
481
510
  canSwitchNavigationMenu={ canSwitchNavigationMenu }
482
511
  hasResolvedNavigationMenus={
483
512
  hasResolvedNavigationMenus
484
513
  }
514
+ clientId={ clientId }
485
515
  />
486
516
  ) }
487
517
  { ! isEntityAvailable && ! isPlaceholderShown && (
@@ -494,6 +524,8 @@ function Navigation( {
494
524
  isOpen={ isResponsiveMenuOpen }
495
525
  isResponsive={ 'never' !== overlayMenu }
496
526
  isHiddenByDefault={ 'always' === overlayMenu }
527
+ classNames={ overlayClassnames }
528
+ styles={ overlayStyles }
497
529
  >
498
530
  { isEntityAvailable && (
499
531
  <NavigationInnerBlocks
@@ -81,7 +81,8 @@ export default function NavigationInnerBlocks( {
81
81
  blocks.every(
82
82
  ( { name } ) =>
83
83
  name === 'core/navigation-link' ||
84
- name === 'core/navigation-submenu'
84
+ name === 'core/navigation-submenu' ||
85
+ name === 'core/page-list'
85
86
  ),
86
87
  [ blocks ]
87
88
  );
@@ -13,13 +13,13 @@ import useNavigationMenu from '../use-navigation-menu';
13
13
 
14
14
  export default function NavigationMenuSelector( { onSelect, onCreateNew } ) {
15
15
  const { navigationMenus } = useNavigationMenu();
16
- const navigationMenuId = useEntityId( 'postType', 'wp_navigation' );
16
+ const ref = useEntityId( 'postType', 'wp_navigation' );
17
17
 
18
18
  return (
19
19
  <>
20
20
  <MenuGroup>
21
21
  <MenuItemsChoice
22
- value={ navigationMenuId }
22
+ value={ ref }
23
23
  onSelect={ ( selectedId ) =>
24
24
  onSelect(
25
25
  navigationMenus.find(
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { serialize, createBlock } from '@wordpress/blocks';
4
+ import { createBlock } from '@wordpress/blocks';
5
5
  import {
6
6
  Placeholder,
7
7
  Button,
@@ -9,8 +9,6 @@ import {
9
9
  MenuGroup,
10
10
  MenuItem,
11
11
  } from '@wordpress/components';
12
- import { store as coreStore } from '@wordpress/core-data';
13
- import { useDispatch } from '@wordpress/data';
14
12
  import { useCallback, useState, useEffect } from '@wordpress/element';
15
13
  import { __ } from '@wordpress/i18n';
16
14
  import { navigation, Icon } from '@wordpress/icons';
@@ -23,8 +21,8 @@ import { decodeEntities } from '@wordpress/html-entities';
23
21
  import useNavigationEntities from '../../use-navigation-entities';
24
22
  import PlaceholderPreview from './placeholder-preview';
25
23
  import menuItemsToBlocks from '../../menu-items-to-blocks';
26
- import NavigationMenuNameModal from '../navigation-menu-name-modal';
27
24
  import useNavigationMenu from '../../use-navigation-menu';
25
+ import useCreateNavigationMenu from '../use-create-navigation-menu';
28
26
 
29
27
  const ExistingMenusDropdown = ( {
30
28
  canSwitchNavigationMenu,
@@ -90,51 +88,25 @@ const ExistingMenusDropdown = ( {
90
88
  };
91
89
 
92
90
  export default function NavigationPlaceholder( {
91
+ clientId,
93
92
  onFinish,
94
93
  canSwitchNavigationMenu,
95
94
  hasResolvedNavigationMenus,
96
95
  } ) {
97
96
  const [ selectedMenu, setSelectedMenu ] = useState();
98
-
99
97
  const [ isCreatingFromMenu, setIsCreatingFromMenu ] = useState( false );
100
-
101
98
  const [ menuName, setMenuName ] = useState( '' );
99
+ const createNavigationMenu = useCreateNavigationMenu( clientId );
102
100
 
103
- const [ isNewMenuModalVisible, setIsNewMenuModalVisible ] = useState(
104
- false
105
- );
106
-
107
- const [ createEmpty, setCreateEmpty ] = useState( false );
108
-
109
- const { saveEntityRecord } = useDispatch( coreStore );
110
-
111
- // This callback uses data from the two placeholder steps and only creates
112
- // a new navigation menu when the user completes the final step.
113
- const createNavigationMenu = useCallback(
114
- async ( title = __( 'Untitled Navigation Menu' ), blocks = [] ) => {
115
- const record = {
116
- title,
117
- content: serialize( blocks ),
118
- status: 'publish',
119
- };
120
-
121
- const navigationMenu = await saveEntityRecord(
122
- 'postType',
123
- 'wp_navigation',
124
- record
125
- );
126
-
127
- return navigationMenu;
128
- },
129
- [ serialize, saveEntityRecord ]
130
- );
131
-
132
- const onFinishMenuCreation = async ( navigationMenuTitle, blocks ) => {
101
+ const onFinishMenuCreation = async (
102
+ blocks,
103
+ navigationMenuTitle = null
104
+ ) => {
133
105
  const navigationMenu = await createNavigationMenu(
134
106
  navigationMenuTitle,
135
107
  blocks
136
108
  );
137
- onFinish( navigationMenu );
109
+ onFinish( navigationMenu, blocks );
138
110
  };
139
111
 
140
112
  const {
@@ -152,7 +124,7 @@ export default function NavigationPlaceholder( {
152
124
  const createFromMenu = useCallback(
153
125
  ( name ) => {
154
126
  const { innerBlocks: blocks } = menuItemsToBlocks( menuItems );
155
- onFinishMenuCreation( name, blocks );
127
+ onFinishMenuCreation( blocks, name );
156
128
  },
157
129
  [ menuItems, menuItemsToBlocks, onFinish ]
158
130
  );
@@ -170,14 +142,13 @@ export default function NavigationPlaceholder( {
170
142
  setMenuName( name );
171
143
  };
172
144
 
173
- const onCreateEmptyMenu = ( name ) => {
174
- onFinishMenuCreation( name, [] );
145
+ const onCreateEmptyMenu = () => {
146
+ onFinishMenuCreation( [] );
175
147
  };
176
148
 
177
- const onCreateAllPages = ( name ) => {
149
+ const onCreateAllPages = () => {
178
150
  const block = [ createBlock( 'core/page-list' ) ];
179
- onFinishMenuCreation( name, block );
180
- setIsNewMenuModalVisible( true );
151
+ onFinishMenuCreation( block );
181
152
  };
182
153
 
183
154
  useEffect( () => {
@@ -225,10 +196,7 @@ export default function NavigationPlaceholder( {
225
196
  <>
226
197
  <Button
227
198
  variant="tertiary"
228
- onClick={ () => {
229
- setIsNewMenuModalVisible( true );
230
- setCreateEmpty( false );
231
- } }
199
+ onClick={ onCreateAllPages }
232
200
  >
233
201
  { __( 'Add all pages' ) }
234
202
  </Button>
@@ -237,10 +205,7 @@ export default function NavigationPlaceholder( {
237
205
  ) : undefined }
238
206
  <Button
239
207
  variant="tertiary"
240
- onClick={ () => {
241
- setIsNewMenuModalVisible( true );
242
- setCreateEmpty( true );
243
- } }
208
+ onClick={ onCreateEmptyMenu }
244
209
  >
245
210
  { __( 'Start empty' ) }
246
211
  </Button>
@@ -248,17 +213,6 @@ export default function NavigationPlaceholder( {
248
213
  </div>
249
214
  </Placeholder>
250
215
  ) }
251
- { isNewMenuModalVisible && (
252
- <NavigationMenuNameModal
253
- title={ __( 'Create your new navigation menu' ) }
254
- onRequestClose={ () => {
255
- setIsNewMenuModalVisible( false );
256
- } }
257
- onFinish={
258
- createEmpty ? onCreateEmptyMenu : onCreateAllPages
259
- }
260
- />
261
- ) }
262
216
  </>
263
217
  );
264
218
  }
@@ -18,12 +18,15 @@ export default function ResponsiveWrapper( {
18
18
  isResponsive,
19
19
  onToggle,
20
20
  isHiddenByDefault,
21
+ classNames,
22
+ styles,
21
23
  } ) {
22
24
  if ( ! isResponsive ) {
23
25
  return children;
24
26
  }
25
27
  const responsiveContainerClasses = classnames(
26
28
  'wp-block-navigation__responsive-container',
29
+ classNames,
27
30
  {
28
31
  'is-menu-open': isOpen,
29
32
  'hidden-by-default': isHiddenByDefault,
@@ -61,7 +64,11 @@ export default function ResponsiveWrapper( {
61
64
  </Button>
62
65
  ) }
63
66
 
64
- <div className={ responsiveContainerClasses } id={ modalId }>
67
+ <div
68
+ className={ responsiveContainerClasses }
69
+ style={ styles }
70
+ id={ modalId }
71
+ >
65
72
  <div
66
73
  className="wp-block-navigation__responsive-close"
67
74
  tabIndex="-1"
@@ -7,18 +7,16 @@ import classnames from 'classnames';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { useInnerBlocksProps } from '@wordpress/block-editor';
10
- import { serialize } from '@wordpress/blocks';
11
10
  import { Disabled, Spinner } from '@wordpress/components';
12
11
  import { store as coreStore } from '@wordpress/core-data';
13
- import { useDispatch, useSelect } from '@wordpress/data';
14
- import { useCallback, useContext, useEffect, useRef } from '@wordpress/element';
15
- import { __, sprintf } from '@wordpress/i18n';
12
+ import { useSelect } from '@wordpress/data';
13
+ import { useContext, useEffect, useRef } from '@wordpress/element';
16
14
 
17
15
  /**
18
16
  * Internal dependencies
19
17
  */
20
18
  import useNavigationMenu from '../use-navigation-menu';
21
- import useTemplatePartAreaLabel from '../use-template-part-area-label';
19
+ import useCreateNavigationMenu from './use-create-navigation-menu';
22
20
 
23
21
  const NOOP = () => {};
24
22
  const EMPTY_OBJECT = {};
@@ -51,7 +49,6 @@ export default function UnsavedInnerBlocks( {
51
49
  onChange: NOOP,
52
50
  onInput: NOOP,
53
51
  } );
54
- const { saveEntityRecord } = useDispatch( coreStore );
55
52
 
56
53
  const {
57
54
  isSaving,
@@ -83,29 +80,7 @@ export default function UnsavedInnerBlocks( {
83
80
 
84
81
  const { hasResolvedNavigationMenus, navigationMenus } = useNavigationMenu();
85
82
 
86
- const createNavigationMenu = useCallback(
87
- async ( title ) => {
88
- const record = {
89
- title,
90
- content: serialize( blocks ),
91
- status: 'draft',
92
- };
93
-
94
- const navigationMenu = await saveEntityRecord(
95
- 'postType',
96
- 'wp_navigation',
97
- record
98
- );
99
-
100
- return navigationMenu;
101
- },
102
- [ blocks, serialize, saveEntityRecord ]
103
- );
104
-
105
- // Because we can't conditionally call hooks, pass an undefined client id
106
- // arg to bypass the expensive `useTemplateArea` code. The hook will return
107
- // early.
108
- const area = useTemplatePartAreaLabel( isDisabled ? undefined : clientId );
83
+ const createNavigationMenu = useCreateNavigationMenu( clientId );
109
84
 
110
85
  // Automatically save the uncontrolled blocks.
111
86
  useEffect( async () => {
@@ -134,33 +109,7 @@ export default function UnsavedInnerBlocks( {
134
109
  }
135
110
 
136
111
  savingLock.current = true;
137
- const title = area
138
- ? sprintf(
139
- // translators: %s: the name of a menu (e.g. Header navigation).
140
- __( '%s navigation' ),
141
- area
142
- )
143
- : // translators: 'navigation' as in website navigation.
144
- __( 'Navigation' );
145
-
146
- // Determine how many menus start with the automatic title.
147
- const matchingMenuTitleCount = [
148
- ...draftNavigationMenus,
149
- ...navigationMenus,
150
- ].reduce(
151
- ( count, menu ) =>
152
- menu?.title?.raw?.startsWith( title ) ? count + 1 : count,
153
- 0
154
- );
155
-
156
- // Append a number to the end of the title if a menu with
157
- // the same name exists.
158
- const titleWithCount =
159
- matchingMenuTitleCount > 0
160
- ? `${ title } ${ matchingMenuTitleCount + 1 }`
161
- : title;
162
-
163
- const menu = await createNavigationMenu( titleWithCount );
112
+ const menu = await createNavigationMenu( null, blocks );
164
113
  onSave( menu );
165
114
  savingLock.current = false;
166
115
  }, [
@@ -172,7 +121,7 @@ export default function UnsavedInnerBlocks( {
172
121
  navigationMenus,
173
122
  hasSelection,
174
123
  createNavigationMenu,
175
- area,
124
+ blocks,
176
125
  ] );
177
126
 
178
127
  return (
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { serialize } from '@wordpress/blocks';
5
+ import { store as coreStore } from '@wordpress/core-data';
6
+ import { useDispatch } from '@wordpress/data';
7
+ import { useCallback } from '@wordpress/element';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import useGenerateDefaultNavigationTitle from './use-generate-default-navigation-title';
13
+
14
+ export default function useCreateNavigationMenu( clientId ) {
15
+ const { saveEntityRecord } = useDispatch( coreStore );
16
+ const generateDefaultTitle = useGenerateDefaultNavigationTitle( clientId );
17
+
18
+ // This callback uses data from the two placeholder steps and only creates
19
+ // a new navigation menu when the user completes the final step.
20
+ return useCallback(
21
+ async ( title = null, blocks = [] ) => {
22
+ if ( ! title ) {
23
+ title = await generateDefaultTitle();
24
+ }
25
+ const record = {
26
+ title,
27
+ content: serialize( blocks ),
28
+ status: 'publish',
29
+ };
30
+
31
+ return await saveEntityRecord(
32
+ 'postType',
33
+ 'wp_navigation',
34
+ record
35
+ );
36
+ },
37
+ [ serialize, saveEntityRecord ]
38
+ );
39
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Disabled } from '@wordpress/components';
5
+ import { store as coreStore } from '@wordpress/core-data';
6
+ import { useRegistry } from '@wordpress/data';
7
+ import { useContext, useCallback } from '@wordpress/element';
8
+ import { __, sprintf } from '@wordpress/i18n';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import useTemplatePartAreaLabel from '../use-template-part-area-label';
14
+
15
+ const DRAFT_MENU_PARAMS = [
16
+ 'postType',
17
+ 'wp_navigation',
18
+ { status: 'draft', per_page: -1 },
19
+ ];
20
+
21
+ const PUBLISHED_MENU_PARAMS = [
22
+ 'postType',
23
+ 'wp_navigation',
24
+ { per_page: -1, status: 'publish' },
25
+ ];
26
+
27
+ export default function useGenerateDefaultNavigationTitle( clientId ) {
28
+ // The block will be disabled in a block preview, use this as a way of
29
+ // avoiding the side-effects of this component for block previews.
30
+ const isDisabled = useContext( Disabled.Context );
31
+
32
+ // Because we can't conditionally call hooks, pass an undefined client id
33
+ // arg to bypass the expensive `useTemplateArea` code. The hook will return
34
+ // early.
35
+ const area = useTemplatePartAreaLabel( isDisabled ? undefined : clientId );
36
+
37
+ const registry = useRegistry();
38
+ return useCallback( async () => {
39
+ // Ensure other navigation menus have loaded so an
40
+ // accurate name can be created.
41
+ if ( isDisabled ) {
42
+ return '';
43
+ }
44
+ const { getEntityRecords } = registry.resolveSelect( coreStore );
45
+
46
+ const [ draftNavigationMenus, navigationMenus ] = await Promise.all( [
47
+ getEntityRecords( ...DRAFT_MENU_PARAMS ),
48
+ getEntityRecords( ...PUBLISHED_MENU_PARAMS ),
49
+ ] );
50
+
51
+ const title = area
52
+ ? sprintf(
53
+ // translators: %s: the name of a menu (e.g. Header navigation).
54
+ __( '%s navigation' ),
55
+ area
56
+ )
57
+ : // translators: 'navigation' as in website navigation.
58
+ __( 'Navigation' );
59
+
60
+ // Determine how many menus start with the automatic title.
61
+ const matchingMenuTitleCount = [
62
+ ...draftNavigationMenus,
63
+ ...navigationMenus,
64
+ ].reduce(
65
+ ( count, menu ) =>
66
+ menu?.title?.raw?.startsWith( title ) ? count + 1 : count,
67
+ 0
68
+ );
69
+
70
+ // Append a number to the end of the title if a menu with
71
+ // the same name exists.
72
+ const titleWithCount =
73
+ matchingMenuTitleCount > 0
74
+ ? `${ title } ${ matchingMenuTitleCount + 1 }`
75
+ : title;
76
+
77
+ return titleWithCount || '';
78
+ }, [ isDisabled, area ] );
79
+ }