@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.
- package/build/cover/edit.js +8 -3
- package/build/cover/edit.js.map +1 -1
- package/build/cover/transforms.js +2 -0
- package/build/cover/transforms.js.map +1 -1
- package/build/gallery/edit.js +1 -1
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/v1/update-gallery-modal.js +1 -1
- package/build/gallery/v1/update-gallery-modal.js.map +1 -1
- package/build/index.js +4 -3
- package/build/index.js.map +1 -1
- package/build/navigation/deprecated.js +118 -12
- package/build/navigation/deprecated.js.map +1 -1
- package/build/navigation/edit/index.js +59 -33
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +1 -1
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +2 -2
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/placeholder/index.js +16 -48
- package/build/navigation/edit/placeholder/index.js.map +1 -1
- package/build/navigation/edit/responsive-wrapper.js +5 -2
- package/build/navigation/edit/responsive-wrapper.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +4 -35
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js +50 -0
- package/build/navigation/edit/use-create-navigation-menu.js.map +1 -0
- package/build/navigation/edit/use-generate-default-navigation-title.js +73 -0
- package/build/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
- package/build/navigation/index.js +1 -1
- package/build/navigation/save.js +2 -2
- package/build/navigation/save.js.map +1 -1
- package/build/navigation/use-navigation-menu.js +19 -8
- package/build/navigation/use-navigation-menu.js.map +1 -1
- package/build/navigation-area/edit.js +5 -0
- package/build/navigation-area/edit.js.map +1 -1
- package/build/page-list/edit.js +40 -42
- package/build/page-list/edit.js.map +1 -1
- package/build/pattern/index.js +1 -1
- package/build/post-featured-image/edit.js +53 -23
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-terms/index.js +1 -1
- package/build/post-title/edit.js +2 -2
- package/build/post-title/edit.js.map +1 -1
- package/build/query-title/index.js +1 -1
- package/build/site-logo/index.js +1 -1
- package/build/site-tagline/index.js +1 -1
- package/build/site-title/index.js +1 -1
- package/build/template-part/edit/placeholder/index.js +1 -1
- package/build/template-part/edit/placeholder/index.js.map +1 -1
- package/build/template-part/index.js +2 -1
- package/build/template-part/index.js.map +1 -1
- package/build-module/cover/edit.js +8 -3
- package/build-module/cover/edit.js.map +1 -1
- package/build-module/cover/transforms.js +2 -0
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/gallery/edit.js +1 -1
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/v1/update-gallery-modal.js +1 -1
- package/build-module/gallery/v1/update-gallery-modal.js.map +1 -1
- package/build-module/index.js +4 -3
- package/build-module/index.js.map +1 -1
- package/build-module/navigation/deprecated.js +118 -12
- package/build-module/navigation/deprecated.js.map +1 -1
- package/build-module/navigation/edit/index.js +60 -33
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +1 -1
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +2 -2
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/placeholder/index.js +15 -45
- package/build-module/navigation/edit/placeholder/index.js.map +1 -1
- package/build-module/navigation/edit/responsive-wrapper.js +5 -2
- package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +6 -35
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js +36 -0
- package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -0
- package/build-module/navigation/edit/use-generate-default-navigation-title.js +57 -0
- package/build-module/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
- package/build-module/navigation/index.js +1 -1
- package/build-module/navigation/save.js +2 -2
- package/build-module/navigation/save.js.map +1 -1
- package/build-module/navigation/use-navigation-menu.js +19 -8
- package/build-module/navigation/use-navigation-menu.js.map +1 -1
- package/build-module/navigation-area/edit.js +4 -0
- package/build-module/navigation-area/edit.js.map +1 -1
- package/build-module/page-list/edit.js +41 -43
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/pattern/index.js +1 -1
- package/build-module/post-featured-image/edit.js +55 -26
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-terms/index.js +1 -1
- package/build-module/post-title/edit.js +2 -2
- package/build-module/post-title/edit.js.map +1 -1
- package/build-module/query-title/index.js +1 -1
- package/build-module/site-logo/index.js +1 -1
- package/build-module/site-tagline/index.js +1 -1
- package/build-module/site-title/index.js +1 -1
- package/build-module/template-part/edit/placeholder/index.js +2 -2
- package/build-module/template-part/edit/placeholder/index.js.map +1 -1
- package/build-module/template-part/index.js +2 -1
- package/build-module/template-part/index.js.map +1 -1
- package/build-style/code/theme-rtl.css +1 -1
- package/build-style/code/theme.css +1 -1
- package/build-style/cover/style-rtl.css +8 -2
- package/build-style/cover/style.css +8 -2
- package/build-style/editor-rtl.css +104 -53
- package/build-style/editor.css +104 -53
- package/build-style/gallery/editor-rtl.css +1 -0
- package/build-style/gallery/editor.css +1 -0
- package/build-style/navigation/style-rtl.css +40 -3
- package/build-style/navigation/style.css +40 -3
- package/build-style/post-comments-form/style-rtl.css +18 -0
- package/build-style/post-comments-form/style.css +18 -0
- package/build-style/post-featured-image/editor-rtl.css +100 -16
- package/build-style/post-featured-image/editor.css +100 -16
- package/build-style/site-logo/editor-rtl.css +2 -2
- package/build-style/site-logo/editor.css +2 -2
- package/build-style/social-links/editor-rtl.css +1 -35
- package/build-style/social-links/editor.css +1 -35
- package/build-style/style-rtl.css +66 -27
- package/build-style/style.css +66 -27
- package/build-style/theme-rtl.css +1 -1
- package/build-style/theme.css +1 -1
- package/package.json +8 -8
- package/src/calendar/index.php +3 -3
- package/src/code/theme.scss +1 -1
- package/src/cover/edit.js +8 -1
- package/src/cover/style.scss +9 -2
- package/src/cover/transforms.js +2 -0
- package/src/gallery/edit.js +1 -1
- package/src/gallery/editor.scss +1 -0
- package/src/gallery/index.php +1 -1
- package/src/gallery/v1/update-gallery-modal.js +1 -1
- package/src/home-link/index.php +1 -1
- package/src/image/index.php +1 -1
- package/src/index.js +28 -26
- package/src/navigation/block.json +1 -1
- package/src/navigation/deprecated.js +105 -4
- package/src/navigation/edit/index.js +68 -36
- package/src/navigation/edit/inner-blocks.js +2 -1
- package/src/navigation/edit/navigation-menu-selector.js +2 -2
- package/src/navigation/edit/placeholder/index.js +16 -62
- package/src/navigation/edit/responsive-wrapper.js +8 -1
- package/src/navigation/edit/unsaved-inner-blocks.js +6 -57
- package/src/navigation/edit/use-create-navigation-menu.js +39 -0
- package/src/navigation/edit/use-generate-default-navigation-title.js +79 -0
- package/src/navigation/index.php +173 -19
- package/src/navigation/save.js +2 -2
- package/src/navigation/style.scss +56 -5
- package/src/navigation/use-navigation-menu.js +20 -9
- package/src/navigation-area/edit.js +5 -0
- package/src/navigation-area/index.php +2 -1
- package/src/navigation-link/index.php +1 -1
- package/src/navigation-submenu/index.php +2 -8
- package/src/page-list/edit.js +35 -44
- package/src/page-list/index.php +10 -5
- package/src/pattern/block.json +1 -1
- package/src/post-comments-form/style.scss +20 -1
- package/src/post-featured-image/edit.js +58 -26
- package/src/post-featured-image/editor.scss +124 -20
- package/src/post-terms/block.json +1 -1
- package/src/post-title/edit.js +2 -2
- package/src/query-title/block.json +1 -1
- package/src/site-logo/block.json +1 -1
- package/src/site-logo/editor.scss +3 -2
- package/src/site-tagline/block.json +1 -1
- package/src/site-title/block.json +1 -1
- package/src/social-links/editor.scss +1 -47
- package/src/style.scss +0 -1
- package/src/table-of-contents/index.php +1 -1
- package/src/template-part/block.json +2 -1
- package/src/template-part/edit/placeholder/index.js +2 -2
- package/src/template-part/index.php +2 -1
- package/build/navigation/edit/navigation-menu-name-modal.js +0 -55
- package/build/navigation/edit/navigation-menu-name-modal.js.map +0 -1
- package/build/navigation/edit/navigation-menu-publish-button.js +0 -53
- package/build/navigation/edit/navigation-menu-publish-button.js.map +0 -1
- package/build-module/navigation/edit/navigation-menu-name-modal.js +0 -47
- package/build-module/navigation/edit/navigation-menu-name-modal.js.map +0 -1
- package/build-module/navigation/edit/navigation-menu-publish-button.js +0 -40
- package/build-module/navigation/edit/navigation-menu-publish-button.js.map +0 -1
- package/build-style/navigation-submenu/style-rtl.css +0 -97
- package/build-style/navigation-submenu/style.css +0 -97
- package/src/navigation/edit/navigation-menu-name-modal.js +0 -69
- package/src/navigation/edit/navigation-menu-publish-button.js +0 -57
- 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
|
|
122
|
-
? navigationAreaMenu
|
|
123
|
-
: attributes.navigationMenuId;
|
|
121
|
+
const ref = navigationArea ? navigationAreaMenu : attributes.ref;
|
|
124
122
|
|
|
125
|
-
const
|
|
123
|
+
const setRef = useCallback(
|
|
126
124
|
( postId ) => {
|
|
127
|
-
setAttributes( {
|
|
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/${
|
|
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 && !
|
|
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(
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
{
|
|
501
|
+
{ isPlaceholderShown && (
|
|
475
502
|
<PlaceholderComponent
|
|
476
503
|
onFinish={ ( post ) => {
|
|
477
504
|
setIsPlaceholderShown( false );
|
|
478
|
-
|
|
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
|
|
@@ -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
|
|
16
|
+
const ref = useEntityId( 'postType', 'wp_navigation' );
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
19
|
<>
|
|
20
20
|
<MenuGroup>
|
|
21
21
|
<MenuItemsChoice
|
|
22
|
-
value={
|
|
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 {
|
|
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
|
|
104
|
-
|
|
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(
|
|
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 = (
|
|
174
|
-
onFinishMenuCreation(
|
|
145
|
+
const onCreateEmptyMenu = () => {
|
|
146
|
+
onFinishMenuCreation( [] );
|
|
175
147
|
};
|
|
176
148
|
|
|
177
|
-
const onCreateAllPages = (
|
|
149
|
+
const onCreateAllPages = () => {
|
|
178
150
|
const block = [ createBlock( 'core/page-list' ) ];
|
|
179
|
-
onFinishMenuCreation(
|
|
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
|
|
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 {
|
|
14
|
-
import {
|
|
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
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
+
}
|