@wordpress/block-library 9.34.1-next.2f1c7c01b.0 → 9.35.1-next.16d95556a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/block/edit.js +2 -2
  3. package/build/block/edit.js.map +2 -2
  4. package/build/block-keyboard-shortcuts/index.js +17 -7
  5. package/build/block-keyboard-shortcuts/index.js.map +2 -2
  6. package/build/cover/deprecated.js +15 -3
  7. package/build/cover/deprecated.js.map +2 -2
  8. package/build/cover/edit/inspector-controls.js +1 -1
  9. package/build/cover/edit/inspector-controls.js.map +2 -2
  10. package/build/cover/transforms.js +10 -2
  11. package/build/cover/transforms.js.map +2 -2
  12. package/build/embed/icons.js +2 -2
  13. package/build/embed/icons.js.map +2 -2
  14. package/build/embed/variations.js +3 -3
  15. package/build/embed/variations.js.map +2 -2
  16. package/build/heading/index.js +3 -1
  17. package/build/heading/index.js.map +3 -3
  18. package/build/heading/transforms.js +10 -3
  19. package/build/heading/transforms.js.map +2 -2
  20. package/build/heading/variations.js +55 -0
  21. package/build/heading/variations.js.map +7 -0
  22. package/build/html/edit.js +54 -44
  23. package/build/html/edit.js.map +3 -3
  24. package/build/html/modal.js +328 -0
  25. package/build/html/modal.js.map +7 -0
  26. package/build/html/utils.js +72 -0
  27. package/build/html/utils.js.map +7 -0
  28. package/build/navigation-link/edit.js +25 -10
  29. package/build/navigation-link/edit.js.map +2 -2
  30. package/build/navigation-link/link-ui/index.js +8 -3
  31. package/build/navigation-link/link-ui/index.js.map +2 -2
  32. package/build/navigation-link/shared/controls.js +42 -7
  33. package/build/navigation-link/shared/controls.js.map +2 -2
  34. package/build/navigation-link/shared/use-entity-binding.js +31 -2
  35. package/build/navigation-link/shared/use-entity-binding.js.map +3 -3
  36. package/build/paragraph/block.json +1 -3
  37. package/build/paragraph/deprecated.js +65 -12
  38. package/build/paragraph/deprecated.js.map +2 -2
  39. package/build/paragraph/edit.js +14 -25
  40. package/build/paragraph/edit.js.map +2 -2
  41. package/build/paragraph/index.js +3 -1
  42. package/build/paragraph/index.js.map +3 -3
  43. package/build/paragraph/save.js +3 -3
  44. package/build/paragraph/save.js.map +2 -2
  45. package/build/paragraph/transforms.js +7 -1
  46. package/build/paragraph/transforms.js.map +2 -2
  47. package/build/paragraph/variations.js +57 -0
  48. package/build/paragraph/variations.js.map +7 -0
  49. package/build/pullquote/block.json +3 -2
  50. package/build/pullquote/transforms.js +0 -31
  51. package/build/pullquote/transforms.js.map +2 -2
  52. package/build/quote/transforms.js +0 -20
  53. package/build/quote/transforms.js.map +2 -2
  54. package/build-module/block/edit.js +2 -2
  55. package/build-module/block/edit.js.map +2 -2
  56. package/build-module/block-keyboard-shortcuts/index.js +17 -7
  57. package/build-module/block-keyboard-shortcuts/index.js.map +2 -2
  58. package/build-module/cover/deprecated.js +15 -3
  59. package/build-module/cover/deprecated.js.map +2 -2
  60. package/build-module/cover/edit/inspector-controls.js +1 -1
  61. package/build-module/cover/edit/inspector-controls.js.map +2 -2
  62. package/build-module/cover/transforms.js +10 -2
  63. package/build-module/cover/transforms.js.map +2 -2
  64. package/build-module/embed/icons.js +2 -2
  65. package/build-module/embed/icons.js.map +2 -2
  66. package/build-module/embed/variations.js +3 -3
  67. package/build-module/embed/variations.js.map +2 -2
  68. package/build-module/heading/index.js +3 -1
  69. package/build-module/heading/index.js.map +2 -2
  70. package/build-module/heading/transforms.js +10 -3
  71. package/build-module/heading/transforms.js.map +2 -2
  72. package/build-module/heading/variations.js +34 -0
  73. package/build-module/heading/variations.js.map +7 -0
  74. package/build-module/html/edit.js +62 -51
  75. package/build-module/html/edit.js.map +2 -2
  76. package/build-module/html/modal.js +304 -0
  77. package/build-module/html/modal.js.map +7 -0
  78. package/build-module/html/utils.js +46 -0
  79. package/build-module/html/utils.js.map +7 -0
  80. package/build-module/navigation-link/edit.js +25 -10
  81. package/build-module/navigation-link/edit.js.map +2 -2
  82. package/build-module/navigation-link/link-ui/index.js +8 -3
  83. package/build-module/navigation-link/link-ui/index.js.map +2 -2
  84. package/build-module/navigation-link/shared/controls.js +42 -7
  85. package/build-module/navigation-link/shared/controls.js.map +2 -2
  86. package/build-module/navigation-link/shared/use-entity-binding.js +35 -3
  87. package/build-module/navigation-link/shared/use-entity-binding.js.map +2 -2
  88. package/build-module/paragraph/block.json +1 -3
  89. package/build-module/paragraph/deprecated.js +65 -12
  90. package/build-module/paragraph/deprecated.js.map +2 -2
  91. package/build-module/paragraph/edit.js +14 -26
  92. package/build-module/paragraph/edit.js.map +2 -2
  93. package/build-module/paragraph/index.js +3 -1
  94. package/build-module/paragraph/index.js.map +2 -2
  95. package/build-module/paragraph/save.js +3 -3
  96. package/build-module/paragraph/save.js.map +2 -2
  97. package/build-module/paragraph/transforms.js +7 -1
  98. package/build-module/paragraph/transforms.js.map +2 -2
  99. package/build-module/paragraph/variations.js +36 -0
  100. package/build-module/paragraph/variations.js.map +7 -0
  101. package/build-module/pullquote/block.json +3 -2
  102. package/build-module/pullquote/transforms.js +0 -31
  103. package/build-module/pullquote/transforms.js.map +2 -2
  104. package/build-module/quote/transforms.js +0 -20
  105. package/build-module/quote/transforms.js.map +2 -2
  106. package/build-style/accordion-heading/style-rtl.css +19 -3
  107. package/build-style/accordion-heading/style.css +19 -3
  108. package/build-style/accordion-panel/style-rtl.css +4 -1
  109. package/build-style/accordion-panel/style.css +4 -1
  110. package/build-style/common-rtl.css +3 -3
  111. package/build-style/common.css +3 -3
  112. package/build-style/editor-rtl.css +62 -21
  113. package/build-style/editor.css +62 -21
  114. package/build-style/embed/style-rtl.css +5 -0
  115. package/build-style/embed/style.css +5 -0
  116. package/build-style/html/editor-rtl.css +55 -21
  117. package/build-style/html/editor.css +55 -21
  118. package/build-style/navigation-link/editor-rtl.css +7 -0
  119. package/build-style/navigation-link/editor.css +7 -0
  120. package/build-style/style-rtl.css +31 -7
  121. package/build-style/style.css +31 -7
  122. package/package.json +37 -37
  123. package/src/accordion-heading/style.scss +40 -7
  124. package/src/accordion-panel/style.scss +6 -1
  125. package/src/block/edit.js +2 -2
  126. package/src/block-keyboard-shortcuts/index.js +23 -9
  127. package/src/common.scss +6 -5
  128. package/src/cover/deprecated.js +15 -3
  129. package/src/cover/edit/inspector-controls.js +1 -1
  130. package/src/cover/transforms.js +10 -2
  131. package/src/embed/icons.js +2 -4
  132. package/src/embed/style.scss +6 -0
  133. package/src/embed/variations.js +3 -3
  134. package/src/heading/index.js +2 -0
  135. package/src/heading/test/__snapshots__/transforms.native.js.snap +0 -6
  136. package/src/heading/test/transforms.native.js +1 -5
  137. package/src/heading/transforms.js +10 -3
  138. package/src/heading/variations.js +37 -0
  139. package/src/html/edit.js +62 -56
  140. package/src/html/editor.scss +69 -10
  141. package/src/html/modal.js +290 -0
  142. package/src/html/test/utils.js +234 -0
  143. package/src/html/utils.js +75 -0
  144. package/src/navigation-link/edit.js +44 -13
  145. package/src/navigation-link/editor.scss +7 -0
  146. package/src/navigation-link/index.php +65 -2
  147. package/src/navigation-link/link-ui/index.js +9 -8
  148. package/src/navigation-link/shared/controls.js +70 -12
  149. package/src/navigation-link/shared/test/controls.js +5 -0
  150. package/src/navigation-link/shared/test/use-entity-binding.js +14 -1
  151. package/src/navigation-link/shared/use-entity-binding.js +57 -9
  152. package/src/paragraph/block.json +1 -3
  153. package/src/paragraph/deprecated.js +87 -20
  154. package/src/paragraph/edit.js +7 -18
  155. package/src/paragraph/edit.native.js +18 -6
  156. package/src/paragraph/index.js +2 -0
  157. package/src/paragraph/save.js +4 -3
  158. package/src/paragraph/test/__snapshots__/transforms.native.js.snap +0 -6
  159. package/src/paragraph/test/edit.native.js +5 -5
  160. package/src/paragraph/test/transforms.native.js +0 -1
  161. package/src/paragraph/transforms.js +7 -1
  162. package/src/paragraph/variations.js +39 -0
  163. package/src/pullquote/block.json +3 -2
  164. package/src/pullquote/test/__snapshots__/transforms.native.js.snap +5 -5
  165. package/src/pullquote/test/transforms.native.js +1 -1
  166. package/src/pullquote/transforms.js +0 -31
  167. package/src/quote/test/__snapshots__/transforms.native.js.snap +0 -6
  168. package/src/quote/test/transforms.native.js +1 -5
  169. package/src/quote/transforms.js +0 -25
  170. package/src/utils/transformation-categories.native.js +0 -1
  171. package/tsconfig.tsbuildinfo +1 -1
  172. package/src/pullquote/test/edit.native.js +0 -73
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { parseContent, serializeContent } from '../utils';
5
+
6
+ describe( 'core/html', () => {
7
+ describe( 'parseContent()', () => {
8
+ it( 'should parse empty content', () => {
9
+ const result = parseContent( '' );
10
+ expect( result ).toEqual( { html: '', css: '', js: '' } );
11
+ } );
12
+
13
+ it( 'should parse whitespace-only content', () => {
14
+ const result = parseContent( ' \n\t ' );
15
+ expect( result ).toEqual( { html: '', css: '', js: '' } );
16
+ } );
17
+
18
+ it( 'should parse HTML-only content', () => {
19
+ const content = '<p>Hello World</p>';
20
+ const result = parseContent( content );
21
+ expect( result ).toEqual( {
22
+ html: '<p>Hello World</p>',
23
+ css: '',
24
+ js: '',
25
+ } );
26
+ } );
27
+
28
+ it( 'should parse CSS-only content', () => {
29
+ const content =
30
+ '<style data-wp-block-html="css">body { color: red; }</style>';
31
+ const result = parseContent( content );
32
+ expect( result ).toEqual( {
33
+ html: '',
34
+ css: 'body { color: red; }',
35
+ js: '',
36
+ } );
37
+ } );
38
+
39
+ it( 'should parse JavaScript-only content', () => {
40
+ const content =
41
+ '<script data-wp-block-html="js">console.log("hello");</script>';
42
+ const result = parseContent( content );
43
+ expect( result ).toEqual( {
44
+ html: '',
45
+ css: '',
46
+ js: 'console.log("hello");',
47
+ } );
48
+ } );
49
+
50
+ it( 'should parse content with all three sections', () => {
51
+ const content = `<style data-wp-block-html="css">
52
+ body { color: red; }
53
+ </style>
54
+
55
+ <script data-wp-block-html="js">
56
+ console.log("hello");
57
+ </script>
58
+
59
+ <p>Hello World</p>`;
60
+ const result = parseContent( content );
61
+ expect( result.css ).toBe( 'body { color: red; }' );
62
+ expect( result.js ).toBe( 'console.log("hello");' );
63
+ expect( result.html ).toBe( '<p>Hello World</p>' );
64
+ } );
65
+
66
+ it( 'should ignore unmarked style tags', () => {
67
+ const content = `<style>body { color: blue; }</style>
68
+ <style data-wp-block-html="css">body { color: red; }</style>
69
+ <p>Test</p>`;
70
+ const result = parseContent( content );
71
+ expect( result.css ).toBe( 'body { color: red; }' );
72
+ expect( result.html ).toContain(
73
+ '<style>body { color: blue; }</style>'
74
+ );
75
+ } );
76
+
77
+ it( 'should ignore unmarked script tags', () => {
78
+ const content = `<script>alert("unmarked");</script>
79
+ <script data-wp-block-html="js">console.log("marked");</script>
80
+ <p>Test</p>`;
81
+ const result = parseContent( content );
82
+ expect( result.js ).toBe( 'console.log("marked");' );
83
+ expect( result.html ).toContain(
84
+ '<script>alert("unmarked");</script>'
85
+ );
86
+ } );
87
+
88
+ it( 'should handle multiple marked style tags (takes first)', () => {
89
+ const content = `<style data-wp-block-html="css">first</style>
90
+ <style data-wp-block-html="css">second</style>`;
91
+ const result = parseContent( content );
92
+ expect( result.css ).toBe( 'first' );
93
+ expect( result.html ).toContain( 'second' );
94
+ } );
95
+
96
+ it( 'should handle multiple marked script tags (takes first)', () => {
97
+ const content = `<script data-wp-block-html="js">first</script>
98
+ <script data-wp-block-html="js">second</script>`;
99
+ const result = parseContent( content );
100
+ expect( result.js ).toBe( 'first' );
101
+ expect( result.html ).toContain( 'second' );
102
+ } );
103
+
104
+ it( 'should trim whitespace from extracted sections', () => {
105
+ const content = `<style data-wp-block-html="css">
106
+
107
+ body { color: red; }
108
+
109
+ </style>
110
+
111
+ <script data-wp-block-html="js">
112
+
113
+ console.log("test");
114
+
115
+ </script>
116
+
117
+ <p>Test</p> `;
118
+ const result = parseContent( content );
119
+ expect( result.css ).toBe( 'body { color: red; }' );
120
+ expect( result.js ).toBe( 'console.log("test");' );
121
+ expect( result.html ).toBe( '<p>Test</p>' );
122
+ } );
123
+
124
+ it( 'should handle malformed HTML gracefully', () => {
125
+ const content = '<p>Unclosed tag<div>Test</p>';
126
+ const result = parseContent( content );
127
+ expect( result ).toHaveProperty( 'html' );
128
+ expect( result ).toHaveProperty( 'css' );
129
+ expect( result ).toHaveProperty( 'js' );
130
+ } );
131
+ } );
132
+
133
+ describe( 'serializeContent()', () => {
134
+ it( 'should serialize empty sections', () => {
135
+ const result = serializeContent( { html: '', css: '', js: '' } );
136
+ expect( result ).toBe( '' );
137
+ } );
138
+
139
+ it( 'should serialize HTML-only', () => {
140
+ const result = serializeContent( {
141
+ html: '<p>Hello World</p>',
142
+ css: '',
143
+ js: '',
144
+ } );
145
+ expect( result ).toBe( '<p>Hello World</p>' );
146
+ } );
147
+
148
+ it( 'should serialize CSS-only', () => {
149
+ const result = serializeContent( {
150
+ html: '',
151
+ css: 'body { color: red; }',
152
+ js: '',
153
+ } );
154
+ expect( result ).toBe(
155
+ '<style data-wp-block-html="css">\nbody { color: red; }\n</style>'
156
+ );
157
+ } );
158
+
159
+ it( 'should serialize JavaScript-only', () => {
160
+ const result = serializeContent( {
161
+ html: '',
162
+ css: '',
163
+ js: 'console.log("test");',
164
+ } );
165
+ expect( result ).toBe(
166
+ '<script data-wp-block-html="js">\nconsole.log("test");\n</script>'
167
+ );
168
+ } );
169
+
170
+ it( 'should serialize all three sections in correct order', () => {
171
+ const result = serializeContent( {
172
+ html: '<p>Hello</p>',
173
+ css: 'body { color: red; }',
174
+ js: 'console.log("test");',
175
+ } );
176
+ expect( result ).toBe(
177
+ '<style data-wp-block-html="css">\nbody { color: red; }\n</style>\n\n<script data-wp-block-html="js">\nconsole.log("test");\n</script>\n\n<p>Hello</p>'
178
+ );
179
+ } );
180
+
181
+ it( 'should ignore whitespace-only sections', () => {
182
+ const result = serializeContent( {
183
+ html: '<p>Test</p>',
184
+ css: ' \n ',
185
+ js: '\t\t',
186
+ } );
187
+ expect( result ).toBe( '<p>Test</p>' );
188
+ } );
189
+
190
+ it( 'should handle missing properties gracefully', () => {
191
+ const result = serializeContent( {} );
192
+ expect( result ).toBe( '' );
193
+ } );
194
+
195
+ it( 'should handle undefined values', () => {
196
+ const result = serializeContent( {
197
+ html: undefined,
198
+ css: undefined,
199
+ js: undefined,
200
+ } );
201
+ expect( result ).toBe( '' );
202
+ } );
203
+ } );
204
+
205
+ describe( 'round-trip serialization', () => {
206
+ it( 'should maintain HTML-only content', () => {
207
+ const original = '<p>Hello World</p>';
208
+ const parsed = parseContent( original );
209
+ const serialized = serializeContent( parsed );
210
+ expect( serialized ).toBe( original );
211
+ } );
212
+
213
+ it( 'should maintain content with all sections', () => {
214
+ const original =
215
+ '<style data-wp-block-html="css">\nbody { color: red; }\n</style>\n\n<script data-wp-block-html="js">\nconsole.log("test");\n</script>\n\n<p>Hello</p>';
216
+ const parsed = parseContent( original );
217
+ const serialized = serializeContent( parsed );
218
+ expect( serialized ).toBe( original );
219
+ } );
220
+
221
+ it( 'should maintain complex HTML structures', () => {
222
+ const sections = {
223
+ html: '<div><h1>Title</h1><p>Paragraph</p></div>',
224
+ css: 'h1 { font-size: 2em; }',
225
+ js: 'document.addEventListener("load", () => {});',
226
+ };
227
+ const serialized = serializeContent( sections );
228
+ const parsed = parseContent( serialized );
229
+ expect( parsed.html ).toBe( sections.html );
230
+ expect( parsed.css ).toBe( sections.css );
231
+ expect( parsed.js ).toBe( sections.js );
232
+ } );
233
+ } );
234
+ } );
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Parses content string into separate HTML, CSS, and JS sections.
3
+ *
4
+ * Extracts CSS from <style data-wp-block-html="css"> tags and
5
+ * JavaScript from <script data-wp-block-html="js"> tags.
6
+ * Everything else is treated as HTML.
7
+ *
8
+ * @param {string} content - The combined content string
9
+ * @return {Object} Object with html, css, and js properties
10
+ */
11
+ export function parseContent( content = '' ) {
12
+ if ( ! content || ! content.trim() ) {
13
+ return { html: '', css: '', js: '' };
14
+ }
15
+
16
+ // Create a temporary document to parse HTML safely
17
+ const doc = document.implementation.createHTMLDocument( '' );
18
+ doc.body.innerHTML = content;
19
+
20
+ // Extract CSS from marked style tag
21
+ const styleTag = doc.body.querySelector(
22
+ 'style[data-wp-block-html="css"]'
23
+ );
24
+ const css = styleTag ? styleTag.textContent.trim() : '';
25
+ if ( styleTag ) {
26
+ styleTag.remove();
27
+ }
28
+
29
+ // Extract JS from marked script tag
30
+ const scriptTag = doc.body.querySelector(
31
+ 'script[data-wp-block-html="js"]'
32
+ );
33
+ const js = scriptTag ? scriptTag.textContent.trim() : '';
34
+ if ( scriptTag ) {
35
+ scriptTag.remove();
36
+ }
37
+
38
+ // Everything else is HTML
39
+ const html = doc.body.innerHTML.trim();
40
+
41
+ return { html, css, js };
42
+ }
43
+
44
+ /**
45
+ * Serializes HTML, CSS, and JS into a single content string.
46
+ *
47
+ * Creates marked <style> and <script> tags for CSS and JS sections,
48
+ * then appends the HTML content.
49
+ *
50
+ * @param {Object} sections Object with html, css, and js properties
51
+ * @param {string} sections.html HTML content
52
+ * @param {string} sections.css CSS content
53
+ * @param {string} sections.js JavaScript content
54
+ * @return {string} Combined content string
55
+ */
56
+ export function serializeContent( { html = '', css = '', js = '' } ) {
57
+ const parts = [];
58
+
59
+ // Add CSS if present
60
+ if ( css.trim() ) {
61
+ parts.push( `<style data-wp-block-html="css">\n${ css }\n</style>` );
62
+ }
63
+
64
+ // Add JS if present
65
+ if ( js.trim() ) {
66
+ parts.push( `<script data-wp-block-html="js">\n${ js }\n</script>` );
67
+ }
68
+
69
+ // Add HTML
70
+ if ( html.trim() ) {
71
+ parts.push( html );
72
+ }
73
+
74
+ return parts.join( '\n\n' );
75
+ }
@@ -97,21 +97,35 @@ const useIsInvalidLink = ( kind, type, id, enabled ) => {
97
97
  const hasId = Number.isInteger( id );
98
98
  const blockEditingMode = useBlockEditingMode();
99
99
 
100
- const postStatus = useSelect(
100
+ const { postStatus, isDeleted } = useSelect(
101
101
  ( select ) => {
102
102
  if ( ! isPostType ) {
103
- return null;
103
+ return { postStatus: null, isDeleted: false };
104
104
  }
105
105
 
106
106
  // Fetching the posts status is an "expensive" operation. Especially for sites with large navigations.
107
107
  // When the block is rendered in a template or other disabled contexts we can skip this check in order
108
108
  // to avoid all these additional requests that don't really add any value in that mode.
109
109
  if ( blockEditingMode === 'disabled' || ! enabled ) {
110
- return null;
110
+ return { postStatus: null, isDeleted: false };
111
111
  }
112
112
 
113
- const { getEntityRecord } = select( coreStore );
114
- return getEntityRecord( 'postType', type, id )?.status;
113
+ const { getEntityRecord, hasFinishedResolution } =
114
+ select( coreStore );
115
+ const entityRecord = getEntityRecord( 'postType', type, id );
116
+ const hasResolved = hasFinishedResolution( 'getEntityRecord', [
117
+ 'postType',
118
+ type,
119
+ id,
120
+ ] );
121
+
122
+ // If resolution has finished and entityRecord is undefined, the entity was deleted.
123
+ const deleted = hasResolved && entityRecord === undefined;
124
+
125
+ return {
126
+ postStatus: entityRecord?.status,
127
+ isDeleted: deleted,
128
+ };
115
129
  },
116
130
  [ isPostType, blockEditingMode, enabled, type, id ]
117
131
  );
@@ -121,11 +135,13 @@ const useIsInvalidLink = ( kind, type, id, enabled ) => {
121
135
  // 2. It has an id.
122
136
  // 3. It's neither null, nor undefined, as valid items might be either of those while loading.
123
137
  // If those conditions are met, check if
124
- // 1. The post status is published.
125
- // 2. The Navigation Link item has no label.
138
+ // 1. The post status is trash (trashed).
139
+ // 2. The entity doesn't exist (deleted).
126
140
  // If either of those is true, invalidate.
127
141
  const isInvalid =
128
- isPostType && hasId && postStatus && 'trash' === postStatus;
142
+ isPostType &&
143
+ hasId &&
144
+ ( isDeleted || ( postStatus && 'trash' === postStatus ) );
129
145
  const isDraft = 'draft' === postStatus;
130
146
 
131
147
  return [ isInvalid, isDraft ];
@@ -248,7 +264,12 @@ export default function NavigationLinkEdit( {
248
264
  const { getBlocks } = useSelect( blockEditorStore );
249
265
 
250
266
  // URL binding logic
251
- const { clearBinding, createBinding } = useEntityBinding( {
267
+ const {
268
+ clearBinding,
269
+ createBinding,
270
+ hasUrlBinding,
271
+ isBoundEntityAvailable,
272
+ } = useEntityBinding( {
252
273
  clientId,
253
274
  attributes,
254
275
  } );
@@ -405,14 +426,23 @@ export default function NavigationLinkEdit( {
405
426
  }
406
427
  );
407
428
 
408
- if ( ! url || isInvalid || isDraft ) {
429
+ if (
430
+ ! url ||
431
+ isInvalid ||
432
+ isDraft ||
433
+ ( hasUrlBinding && ! isBoundEntityAvailable )
434
+ ) {
409
435
  blockProps.onClick = () => {
410
436
  setIsLinkOpen( true );
411
437
  };
412
438
  }
413
439
 
414
440
  const classes = clsx( 'wp-block-navigation-item__content', {
415
- 'wp-block-navigation-link__placeholder': ! url || isInvalid || isDraft,
441
+ 'wp-block-navigation-link__placeholder':
442
+ ! url ||
443
+ isInvalid ||
444
+ isDraft ||
445
+ ( hasUrlBinding && ! isBoundEntityAvailable ),
416
446
  } );
417
447
 
418
448
  const missingText = getMissingText( type );
@@ -531,9 +561,10 @@ export default function NavigationLinkEdit( {
531
561
  link={ attributes }
532
562
  onClose={ () => {
533
563
  setIsLinkOpen( false );
534
- // If there is no link then remove the auto-inserted block.
564
+ // If there is no link and no binding, remove the auto-inserted block.
535
565
  // This avoids empty blocks which can provided a poor UX.
536
- if ( ! url ) {
566
+ // Don't remove if binding exists (even if entity is unavailable) so user can fix it.
567
+ if ( ! url && ! hasUrlBinding ) {
537
568
  onReplace( [] );
538
569
  } else if ( isNewLink.current ) {
539
570
  // If we just created a new link, select it
@@ -143,3 +143,10 @@
143
143
  text-transform: uppercase;
144
144
  }
145
145
  }
146
+
147
+ /**
148
+ * Error text styling for missing entity help text.
149
+ */
150
+ .navigation-link-control__error-text {
151
+ color: $alert-red;
152
+ }
@@ -312,11 +312,50 @@ function build_variation_for_navigation_link( $entity, $kind ) {
312
312
  $title = '';
313
313
  $description = '';
314
314
 
315
+ // Get default labels based on entity type
316
+ $default_labels = null;
317
+ if ( $entity instanceof WP_Post_Type ) {
318
+ $default_labels = WP_Post_Type::get_default_labels();
319
+ } elseif ( $entity instanceof WP_Taxonomy ) {
320
+ $default_labels = WP_Taxonomy::get_default_labels();
321
+ }
322
+
323
+ // Get title and check if it's default
324
+ $is_default_title = false;
315
325
  if ( property_exists( $entity->labels, 'item_link' ) ) {
316
326
  $title = $entity->labels->item_link;
327
+ if ( isset( $default_labels['item_link'] ) ) {
328
+ $is_default_title = in_array( $title, $default_labels['item_link'], true );
329
+ }
317
330
  }
331
+
332
+ // Get description and check if it's default
333
+ $is_default_description = false;
318
334
  if ( property_exists( $entity->labels, 'item_link_description' ) ) {
319
335
  $description = $entity->labels->item_link_description;
336
+ if ( isset( $default_labels['item_link_description'] ) ) {
337
+ $is_default_description = in_array( $description, $default_labels['item_link_description'], true );
338
+ }
339
+ }
340
+
341
+ // Calculate singular name once (used for both title and description)
342
+ $singular = isset( $entity->labels->singular_name ) ? $entity->labels->singular_name : ucfirst( $entity->name );
343
+
344
+ // Set default title if needed
345
+ if ( $is_default_title || '' === $title ) {
346
+ /* translators: %s: Singular label of the entity. */
347
+ $title = sprintf( __( '%s link' ), $singular );
348
+ }
349
+
350
+ // Default description if needed.
351
+ // Use a single space character instead of an empty string to prevent fallback to the
352
+ // block.json default description ("Add a page, link, or another item to your navigation.").
353
+ // An empty string would be treated as missing and trigger the fallback, while a single
354
+ // space appears blank in the UI but prevents the fallback behavior.
355
+ // We avoid generating descriptions like "A link to a %s" to prevent grammatical errors
356
+ // (e.g., "A link to a event" should be "A link to an event").
357
+ if ( $is_default_description || '' === $description ) {
358
+ $description = ' ';
320
359
  }
321
360
 
322
361
  $variation = array(
@@ -368,6 +407,7 @@ function build_variation_for_navigation_link( $entity, $kind ) {
368
407
  *
369
408
  * @param array $variations Array of registered variations for a block type.
370
409
  * @param WP_Block_Type $block_type The full block type object.
410
+ * @return array Numerically indexed array of block variations.
371
411
  */
372
412
  function block_core_navigation_link_filter_variations( $variations, $block_type ) {
373
413
  if ( 'core/navigation-link' !== $block_type->name ) {
@@ -375,7 +415,28 @@ function block_core_navigation_link_filter_variations( $variations, $block_type
375
415
  }
376
416
 
377
417
  $generated_variations = block_core_navigation_link_build_variations();
378
- return array_merge( $variations, $generated_variations );
418
+
419
+ /*
420
+ * IMPORTANT: Order matters for deduplication.
421
+ *
422
+ * The variations returned from this filter are bootstrapped to JavaScript and
423
+ * processed by the block variations reducer. The reducer uses `getUniqueItemsByName()`
424
+ * (packages/blocks/src/store/reducer.js:51-57) which keeps the FIRST variation with
425
+ * a given 'name' and discards later duplicates when processing the array in order.
426
+ *
427
+ * By placing generated variations first in `array_merge()`, the improved
428
+ * labels (e.g., "Product link" instead of generic "Post Link") are processed first
429
+ * and preserved. The generic incoming variations are then discarded as duplicates.
430
+ *
431
+ * Why `array_merge()` instead of manual deduplication?
432
+ * - Both arrays use numeric indices (0, 1, 2...), so `array_merge()` concatenates
433
+ * and re-indexes them sequentially, preserving order
434
+ * - The reducer handles deduplication, so it is not needed here
435
+ * - This keeps the PHP code simple and relies on the established JavaScript behavior
436
+ *
437
+ * See: https://github.com/WordPress/gutenberg/pull/72517
438
+ */
439
+ return array_merge( $generated_variations, $variations );
379
440
  }
380
441
 
381
442
  /**
@@ -419,7 +480,9 @@ function block_core_navigation_link_build_variations() {
419
480
  }
420
481
  }
421
482
 
422
- return array_merge( $built_ins, $variations );
483
+ $all_variations = array_merge( $built_ins, $variations );
484
+
485
+ return $all_variations;
423
486
  }
424
487
 
425
488
  /**
@@ -26,6 +26,7 @@ import { useInstanceId } from '@wordpress/compose';
26
26
  */
27
27
  import { LinkUIPageCreator } from './page-creator';
28
28
  import LinkUIBlockInserter from './block-inserter';
29
+ import { useEntityBinding } from '../shared/use-entity-binding';
29
30
 
30
31
  /**
31
32
  * Given the Link block's type attribute, return the query params to give to
@@ -66,7 +67,8 @@ export function getSuggestionsQuery( type, kind ) {
66
67
  }
67
68
 
68
69
  function UnforwardedLinkUI( props, ref ) {
69
- const { label, url, opensInNewTab, type, kind, id, metadata } = props.link;
70
+ const { label, url, opensInNewTab, type, kind, id } = props.link;
71
+ const { clientId } = props;
70
72
  const postType = type || 'page';
71
73
 
72
74
  const [ addingBlock, setAddingBlock ] = useState( false );
@@ -78,12 +80,11 @@ function UnforwardedLinkUI( props, ref ) {
78
80
  name: postType,
79
81
  } );
80
82
 
81
- // Check if there's a URL binding with the new binding sources
82
- // Only enable handleEntities when there's actually a binding present
83
- const hasUrlBinding =
84
- ( metadata?.bindings?.url?.source === 'core/post-data' ||
85
- metadata?.bindings?.url?.source === 'core/term-data' ) &&
86
- !! id;
83
+ // Use the entity binding hook to get binding status
84
+ const { isBoundEntityAvailable } = useEntityBinding( {
85
+ clientId,
86
+ attributes: props.link,
87
+ } );
87
88
 
88
89
  // Memoize link value to avoid overriding the LinkControl's internal state.
89
90
  // This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
@@ -152,7 +153,7 @@ function UnforwardedLinkUI( props, ref ) {
152
153
  onChange={ props.onChange }
153
154
  onRemove={ props.onRemove }
154
155
  onCancel={ props.onCancel }
155
- handleEntities={ hasUrlBinding }
156
+ handleEntities={ isBoundEntityAvailable }
156
157
  renderControlBottom={ () => {
157
158
  // Don't show the tools when there is submitted link (preview state).
158
159
  if ( link?.url?.length ) {