@wordpress/block-library 6.0.7 → 6.0.11
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 +127 -19
- 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-pagination-next/index.js +1 -1
- package/build/query-pagination-previous/index.js +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 +127 -19
- 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-pagination-next/index.js +1 -1
- package/build-module/query-pagination-previous/index.js +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 +41 -3
- package/build-style/navigation/style.css +41 -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 +67 -27
- package/build-style/style.css +67 -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 +115 -13
- 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 +171 -25
- package/src/navigation/save.js +2 -2
- package/src/navigation/style.scss +57 -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-pagination-next/block.json +1 -1
- package/src/query-pagination-previous/block.json +1 -1
- 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
|
@@ -21,32 +21,131 @@ const TYPOGRAPHY_PRESET_DEPRECATION_MAP = {
|
|
|
21
21
|
textTransform: 'var:preset|text-transform|',
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
const migrateIdToRef = ( { navigationMenuId, ...attributes } ) => {
|
|
25
|
+
return {
|
|
26
|
+
...attributes,
|
|
27
|
+
ref: navigationMenuId,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
24
31
|
const migrateWithLayout = ( attributes ) => {
|
|
25
32
|
if ( !! attributes.layout ) {
|
|
26
33
|
return attributes;
|
|
27
34
|
}
|
|
28
35
|
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
...
|
|
33
|
-
};
|
|
36
|
+
const {
|
|
37
|
+
itemsJustification,
|
|
38
|
+
orientation,
|
|
39
|
+
...updatedAttributes
|
|
40
|
+
} = attributes;
|
|
34
41
|
|
|
35
42
|
if ( itemsJustification || orientation ) {
|
|
36
43
|
Object.assign( updatedAttributes, {
|
|
37
44
|
layout: {
|
|
38
45
|
type: 'flex',
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
setCascadingProperties: 'true',
|
|
47
|
+
...( itemsJustification && {
|
|
48
|
+
justifyContent: itemsJustification,
|
|
49
|
+
} ),
|
|
50
|
+
...( orientation && { orientation } ),
|
|
41
51
|
},
|
|
42
52
|
} );
|
|
43
|
-
delete updatedAttributes.itemsJustification;
|
|
44
|
-
delete updatedAttributes.orientation;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
return updatedAttributes;
|
|
48
56
|
};
|
|
49
57
|
|
|
58
|
+
const v6 = {
|
|
59
|
+
attributes: {
|
|
60
|
+
navigationMenuId: {
|
|
61
|
+
type: 'number',
|
|
62
|
+
},
|
|
63
|
+
textColor: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
},
|
|
66
|
+
customTextColor: {
|
|
67
|
+
type: 'string',
|
|
68
|
+
},
|
|
69
|
+
rgbTextColor: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
},
|
|
72
|
+
backgroundColor: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
},
|
|
75
|
+
customBackgroundColor: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
},
|
|
78
|
+
rgbBackgroundColor: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
},
|
|
81
|
+
showSubmenuIcon: {
|
|
82
|
+
type: 'boolean',
|
|
83
|
+
default: true,
|
|
84
|
+
},
|
|
85
|
+
openSubmenusOnClick: {
|
|
86
|
+
type: 'boolean',
|
|
87
|
+
default: false,
|
|
88
|
+
},
|
|
89
|
+
overlayMenu: {
|
|
90
|
+
type: 'string',
|
|
91
|
+
default: 'mobile',
|
|
92
|
+
},
|
|
93
|
+
__unstableLocation: {
|
|
94
|
+
type: 'string',
|
|
95
|
+
},
|
|
96
|
+
overlayBackgroundColor: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
},
|
|
99
|
+
customOverlayBackgroundColor: {
|
|
100
|
+
type: 'string',
|
|
101
|
+
},
|
|
102
|
+
overlayTextColor: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
},
|
|
105
|
+
customOverlayTextColor: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
supports: {
|
|
110
|
+
align: [ 'wide', 'full' ],
|
|
111
|
+
anchor: true,
|
|
112
|
+
html: false,
|
|
113
|
+
inserter: true,
|
|
114
|
+
typography: {
|
|
115
|
+
fontSize: true,
|
|
116
|
+
lineHeight: true,
|
|
117
|
+
__experimentalFontStyle: true,
|
|
118
|
+
__experimentalFontWeight: true,
|
|
119
|
+
__experimentalTextTransform: true,
|
|
120
|
+
__experimentalFontFamily: true,
|
|
121
|
+
__experimentalTextDecoration: true,
|
|
122
|
+
__experimentalDefaultControls: {
|
|
123
|
+
fontSize: true,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
spacing: {
|
|
127
|
+
blockGap: true,
|
|
128
|
+
units: [ 'px', 'em', 'rem', 'vh', 'vw' ],
|
|
129
|
+
__experimentalDefaultControls: {
|
|
130
|
+
blockGap: true,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
__experimentalLayout: {
|
|
134
|
+
allowSwitching: false,
|
|
135
|
+
allowInheriting: false,
|
|
136
|
+
default: {
|
|
137
|
+
type: 'flex',
|
|
138
|
+
setCascadingProperties: true,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
save() {
|
|
143
|
+
return <InnerBlocks.Content />;
|
|
144
|
+
},
|
|
145
|
+
isEligible: ( { navigationMenuId } ) => !! navigationMenuId,
|
|
146
|
+
migrate: migrateIdToRef,
|
|
147
|
+
};
|
|
148
|
+
|
|
50
149
|
const v5 = {
|
|
51
150
|
attributes: {
|
|
52
151
|
navigationMenuId: {
|
|
@@ -135,7 +234,7 @@ const v5 = {
|
|
|
135
234
|
},
|
|
136
235
|
isEligible: ( { itemsJustification, orientation } ) =>
|
|
137
236
|
!! itemsJustification || !! orientation,
|
|
138
|
-
migrate: migrateWithLayout,
|
|
237
|
+
migrate: compose( migrateIdToRef, migrateWithLayout ),
|
|
139
238
|
};
|
|
140
239
|
|
|
141
240
|
const v4 = {
|
|
@@ -218,7 +317,7 @@ const v4 = {
|
|
|
218
317
|
save() {
|
|
219
318
|
return <InnerBlocks.Content />;
|
|
220
319
|
},
|
|
221
|
-
migrate: compose( migrateWithLayout, migrateFontFamily ),
|
|
320
|
+
migrate: compose( migrateIdToRef, migrateWithLayout, migrateFontFamily ),
|
|
222
321
|
isEligible( { style } ) {
|
|
223
322
|
return style?.typography?.fontFamily;
|
|
224
323
|
},
|
|
@@ -259,6 +358,7 @@ const migrateTypographyPresets = function ( attributes ) {
|
|
|
259
358
|
};
|
|
260
359
|
|
|
261
360
|
const deprecated = [
|
|
361
|
+
v6,
|
|
262
362
|
v5,
|
|
263
363
|
v4,
|
|
264
364
|
// Remove `isResponsive` attribute.
|
|
@@ -336,6 +436,7 @@ const deprecated = [
|
|
|
336
436
|
return attributes.isResponsive;
|
|
337
437
|
},
|
|
338
438
|
migrate: compose(
|
|
439
|
+
migrateIdToRef,
|
|
339
440
|
migrateWithLayout,
|
|
340
441
|
migrateFontFamily,
|
|
341
442
|
migrateIsResponsive
|
|
@@ -410,6 +511,7 @@ const deprecated = [
|
|
|
410
511
|
return false;
|
|
411
512
|
},
|
|
412
513
|
migrate: compose(
|
|
514
|
+
migrateIdToRef,
|
|
413
515
|
migrateWithLayout,
|
|
414
516
|
migrateFontFamily,
|
|
415
517
|
migrateTypographyPresets
|
|
@@ -454,7 +556,7 @@ const deprecated = [
|
|
|
454
556
|
html: false,
|
|
455
557
|
inserter: true,
|
|
456
558
|
},
|
|
457
|
-
migrate( attributes ) {
|
|
559
|
+
migrate: compose( migrateIdToRef, ( attributes ) => {
|
|
458
560
|
return {
|
|
459
561
|
...omit( attributes, [ 'rgbTextColor', 'rgbBackgroundColor' ] ),
|
|
460
562
|
customTextColor: attributes.textColor
|
|
@@ -464,7 +566,7 @@ const deprecated = [
|
|
|
464
566
|
? undefined
|
|
465
567
|
: attributes.rgbBackgroundColor,
|
|
466
568
|
};
|
|
467
|
-
},
|
|
569
|
+
} ),
|
|
468
570
|
save() {
|
|
469
571
|
return <InnerBlocks.Content />;
|
|
470
572
|
},
|
|
@@ -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"
|