@@ -33,6 +33,48 @@ const BLOCKS_WITH_LINK_UI_SUPPORT = [
33
33
'core/navigation-submenu' ,
34
34
] ;
35
35
36
+ function AdditionalBlockContent ( { block, insertedBlock, setInsertedBlock } ) {
37
+ const { updateBlockAttributes } = useDispatch ( blockEditorStore ) ;
38
+
39
+ const supportsLinkControls = BLOCKS_WITH_LINK_UI_SUPPORT ?. includes (
40
+ insertedBlock ?. name
41
+ ) ;
42
+ const blockWasJustInserted = insertedBlock ?. clientId === block . clientId ;
43
+ const showLinkControls = supportsLinkControls && blockWasJustInserted ;
44
+
45
+ if ( ! showLinkControls ) {
46
+ return null ;
47
+ }
48
+
49
+ const setInsertedBlockAttributes =
50
+ ( _insertedBlockClientId ) => ( _updatedAttributes ) => {
51
+ if ( ! _insertedBlockClientId ) return ;
52
+ updateBlockAttributes ( _insertedBlockClientId , _updatedAttributes ) ;
53
+ } ;
54
+
55
+ return (
56
+ < LinkUI
57
+ clientId = { insertedBlock ?. clientId }
58
+ link = { insertedBlock ?. attributes }
59
+ onClose = { ( ) => {
60
+ setInsertedBlock ( null ) ;
61
+ } }
62
+ hasCreateSuggestion = { false }
63
+ onChange = { ( updatedValue ) => {
64
+ updateAttributes (
65
+ updatedValue ,
66
+ setInsertedBlockAttributes ( insertedBlock ?. clientId ) ,
67
+ insertedBlock ?. attributes
68
+ ) ;
69
+ setInsertedBlock ( null ) ;
70
+ } }
71
+ onCancel = { ( ) => {
72
+ setInsertedBlock ( null ) ;
73
+ } }
74
+ />
75
+ ) ;
76
+ }
77
+
36
78
const MainContent = ( {
37
79
clientId,
38
80
currentMenuId,
@@ -52,14 +94,6 @@ const MainContent = ( {
52
94
[ clientId ]
53
95
) ;
54
96
55
- const { updateBlockAttributes } = useDispatch ( blockEditorStore ) ;
56
-
57
- const setInsertedBlockAttributes =
58
- ( _insertedBlockClientId ) => ( _updatedAttributes ) => {
59
- if ( ! _insertedBlockClientId ) return ;
60
- updateBlockAttributes ( _insertedBlockClientId , _updatedAttributes ) ;
61
- } ;
62
-
63
97
const { navigationMenu } = useNavigationMenu ( currentMenuId ) ;
64
98
65
99
if ( currentMenuId && isNavigationMenuMissing ) {
@@ -80,47 +114,6 @@ const MainContent = ( {
80
114
'You have not yet created any menus. Displaying a list of your Pages'
81
115
) ;
82
116
83
- const renderLinkUI = (
84
- currentBlock ,
85
- lastInsertedBlock ,
86
- setLastInsertedBlock
87
- ) => {
88
- const blockSupportsLinkUI = BLOCKS_WITH_LINK_UI_SUPPORT ?. includes (
89
- lastInsertedBlock ?. name
90
- ) ;
91
- const currentBlockWasJustInserted =
92
- lastInsertedBlock ?. clientId === currentBlock . clientId ;
93
-
94
- const shouldShowLinkUIForBlock =
95
- blockSupportsLinkUI && currentBlockWasJustInserted ;
96
-
97
- return (
98
- shouldShowLinkUIForBlock && (
99
- < LinkUI
100
- clientId = { lastInsertedBlock ?. clientId }
101
- link = { lastInsertedBlock ?. attributes }
102
- onClose = { ( ) => {
103
- setLastInsertedBlock ( null ) ;
104
- } }
105
- hasCreateSuggestion = { false }
106
- onChange = { ( updatedValue ) => {
107
- updateAttributes (
108
- updatedValue ,
109
- setInsertedBlockAttributes (
110
- lastInsertedBlock ?. clientId
111
- ) ,
112
- lastInsertedBlock ?. attributes
113
- ) ;
114
- setLastInsertedBlock ( null ) ;
115
- } }
116
- onCancel = { ( ) => {
117
- setLastInsertedBlock ( null ) ;
118
- } }
119
- />
120
- )
121
- ) ;
122
- } ;
123
-
124
117
return (
125
118
< div className = "wp-block-navigation__menu-inspector-controls" >
126
119
{ clientIdsTree . length === 0 && (
@@ -135,7 +128,7 @@ const MainContent = ( {
135
128
description = { description }
136
129
showAppender
137
130
blockSettingsMenu = { LeafMoreMenu }
138
- renderAdditionalBlockUI = { renderLinkUI }
131
+ additionalBlockContent = { AdditionalBlockContent }
139
132
/>
140
133
</ div >
141
134
) ;
0 commit comments