@wordpress/block-library 8.28.4 → 8.28.6

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 (67) hide show
  1. package/build/block/deprecated.js +71 -11
  2. package/build/block/deprecated.js.map +1 -1
  3. package/build/block/edit.js +65 -31
  4. package/build/block/edit.js.map +1 -1
  5. package/build/code/save.js +3 -1
  6. package/build/code/save.js.map +1 -1
  7. package/build/image/edit.js +6 -3
  8. package/build/image/edit.js.map +1 -1
  9. package/build/image/image.js +11 -5
  10. package/build/image/image.js.map +1 -1
  11. package/build/list-item/edit.js +1 -3
  12. package/build/list-item/edit.js.map +1 -1
  13. package/build/list-item/hooks/index.js +0 -7
  14. package/build/list-item/hooks/index.js.map +1 -1
  15. package/build/list-item/index.js +4 -1
  16. package/build/list-item/index.js.map +1 -1
  17. package/build/navigation/edit/index.js +2 -2
  18. package/build/navigation/edit/index.js.map +1 -1
  19. package/build/navigation/edit/navigation-menu-selector.js +20 -19
  20. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  21. package/build/site-logo/edit.js +7 -2
  22. package/build/site-logo/edit.js.map +1 -1
  23. package/build-module/block/deprecated.js +71 -11
  24. package/build-module/block/deprecated.js.map +1 -1
  25. package/build-module/block/edit.js +66 -32
  26. package/build-module/block/edit.js.map +1 -1
  27. package/build-module/code/save.js +3 -1
  28. package/build-module/code/save.js.map +1 -1
  29. package/build-module/image/edit.js +7 -4
  30. package/build-module/image/edit.js.map +1 -1
  31. package/build-module/image/image.js +11 -5
  32. package/build-module/image/image.js.map +1 -1
  33. package/build-module/list-item/edit.js +2 -4
  34. package/build-module/list-item/edit.js.map +1 -1
  35. package/build-module/list-item/hooks/index.js +0 -1
  36. package/build-module/list-item/hooks/index.js.map +1 -1
  37. package/build-module/list-item/index.js +4 -1
  38. package/build-module/list-item/index.js.map +1 -1
  39. package/build-module/navigation/edit/index.js +2 -2
  40. package/build-module/navigation/edit/index.js.map +1 -1
  41. package/build-module/navigation/edit/navigation-menu-selector.js +20 -19
  42. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  43. package/build-module/site-logo/edit.js +7 -2
  44. package/build-module/site-logo/edit.js.map +1 -1
  45. package/build-style/common-rtl.css +1 -0
  46. package/build-style/common.css +1 -0
  47. package/package.json +13 -13
  48. package/src/block/deprecated.js +76 -11
  49. package/src/block/edit.js +100 -32
  50. package/src/block/index.php +21 -12
  51. package/src/code/save.js +7 -1
  52. package/src/image/edit.js +10 -3
  53. package/src/image/image.js +20 -16
  54. package/src/list-item/edit.js +1 -2
  55. package/src/list-item/hooks/index.js +0 -1
  56. package/src/list-item/index.js +3 -0
  57. package/src/navigation/edit/index.js +2 -2
  58. package/src/navigation/edit/navigation-menu-selector.js +34 -16
  59. package/src/navigation/edit/test/navigation-menu-selector.js +61 -39
  60. package/src/navigation/index.php +19 -13
  61. package/src/search/index.php +1 -1
  62. package/src/site-logo/edit.js +10 -5
  63. package/build/list-item/hooks/use-copy.js +0 -39
  64. package/build/list-item/hooks/use-copy.js.map +0 -1
  65. package/build-module/list-item/hooks/use-copy.js +0 -32
  66. package/build-module/list-item/hooks/use-copy.js.map +0 -1
  67. package/src/list-item/hooks/use-copy.js +0 -38
@@ -46,26 +46,35 @@ function render_block_core_block( $attributes ) {
46
46
  $content = $wp_embed->run_shortcode( $reusable_block->post_content );
47
47
  $content = $wp_embed->autoembed( $content );
48
48
 
49
- // Back compat, the content attribute was previously named overrides and
50
- // had a slightly different format. For blocks that have not been migrated,
51
- // also convert the format here so that the provided `pattern/overrides`
52
- // context is correct.
53
- if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
54
- $migrated_content = array();
55
- foreach ( $attributes['overrides'] as $id => $values ) {
56
- $migrated_content[ $id ] = array(
57
- 'values' => $values,
58
- );
49
+ // Back compat.
50
+ // For blocks that have not been migrated in the editor, add some back compat
51
+ // so that front-end rendering continues to work.
52
+
53
+ // This matches the `v2` deprecation. Removes the inner `values` property
54
+ // from every item.
55
+ if ( isset( $attributes['content'] ) ) {
56
+ foreach ( $attributes['content'] as &$content_data ) {
57
+ if ( isset( $content_data['values'] ) ) {
58
+ $is_assoc_array = is_array( $content_data['values'] ) && ! wp_is_numeric_array( $content_data['values'] );
59
+
60
+ if ( $is_assoc_array ) {
61
+ $content_data = $content_data['values'];
62
+ }
63
+ }
59
64
  }
60
- $attributes['content'] = $migrated_content;
61
65
  }
62
- $has_pattern_overrides = isset( $attributes['content'] );
66
+
67
+ // This matches the `v1` deprecation. Rename `overrides` to `content`.
68
+ if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) {
69
+ $attributes['content'] = $attributes['overrides'];
70
+ }
63
71
 
64
72
  /**
65
73
  * We set the `pattern/overrides` context through the `render_block_context`
66
74
  * filter so that it is available when a pattern's inner blocks are
67
75
  * rendering via do_blocks given it only receives the inner content.
68
76
  */
77
+ $has_pattern_overrides = isset( $attributes['content'] );
69
78
  if ( $has_pattern_overrides ) {
70
79
  $filter_block_context = static function ( $context ) use ( $attributes ) {
71
80
  $context['pattern/overrides'] = $attributes['content'];
package/src/code/save.js CHANGED
@@ -16,7 +16,13 @@ export default function save( { attributes } ) {
16
16
  // To do: `escape` encodes characters in shortcodes and URLs to
17
17
  // prevent embedding in PHP. Ideally checks for the code block,
18
18
  // or pre/code tags, should be made on the PHP side?
19
- value={ escape( attributes.content.toString() ) }
19
+ value={ escape(
20
+ typeof attributes.content === 'string'
21
+ ? attributes.content
22
+ : attributes.content.toHTMLString( {
23
+ preserveWhiteSpace: true,
24
+ } )
25
+ ) }
20
26
  />
21
27
  </pre>
22
28
  );
package/src/image/edit.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  useBlockEditingMode,
21
21
  } from '@wordpress/block-editor';
22
22
  import { useEffect, useRef, useState } from '@wordpress/element';
23
- import { __ } from '@wordpress/i18n';
23
+ import { __, sprintf } from '@wordpress/i18n';
24
24
  import { image as icon, plugins as pluginsIcon } from '@wordpress/icons';
25
25
  import { store as noticesStore } from '@wordpress/notices';
26
26
 
@@ -336,7 +336,7 @@ export function ImageEdit( {
336
336
  } );
337
337
 
338
338
  // Much of this description is duplicated from MediaPlaceholder.
339
- const { lockUrlControls = false } = useSelect(
339
+ const { lockUrlControls = false, lockUrlControlsMessage } = useSelect(
340
340
  ( select ) => {
341
341
  if ( ! isSingleSelected ) {
342
342
  return {};
@@ -351,6 +351,13 @@ export function ImageEdit( {
351
351
  !! metadata?.bindings?.url &&
352
352
  ( ! blockBindingsSource ||
353
353
  blockBindingsSource?.lockAttributesEditing ),
354
+ lockUrlControlsMessage: blockBindingsSource?.label
355
+ ? sprintf(
356
+ /* translators: %s: Label of the bindings source. */
357
+ __( 'Connected to %s' ),
358
+ blockBindingsSource.label
359
+ )
360
+ : __( 'Connected to dynamic data' ),
354
361
  };
355
362
  },
356
363
  [ isSingleSelected ]
@@ -387,7 +394,7 @@ export function ImageEdit( {
387
394
  <span
388
395
  className={ 'block-bindings-media-placeholder-message' }
389
396
  >
390
- { __( 'Connected to a custom field' ) }
397
+ { lockUrlControlsMessage }
391
398
  </span>
392
399
  ) : (
393
400
  content
@@ -410,7 +410,9 @@ export default function Image( {
410
410
  lockUrlControls = false,
411
411
  lockHrefControls = false,
412
412
  lockAltControls = false,
413
+ lockAltControlsMessage,
413
414
  lockTitleControls = false,
415
+ lockTitleControlsMessage,
414
416
  lockCaption = false,
415
417
  } = useSelect(
416
418
  ( select ) => {
@@ -454,10 +456,24 @@ export default function Image( {
454
456
  !! altBinding &&
455
457
  ( ! altBindingSource ||
456
458
  altBindingSource?.lockAttributesEditing ),
459
+ lockAltControlsMessage: altBindingSource?.label
460
+ ? sprintf(
461
+ /* translators: %s: Label of the bindings source. */
462
+ __( 'Connected to %s' ),
463
+ altBindingSource.label
464
+ )
465
+ : __( 'Connected to dynamic data' ),
457
466
  lockTitleControls:
458
467
  !! titleBinding &&
459
468
  ( ! titleBindingSource ||
460
469
  titleBindingSource?.lockAttributesEditing ),
470
+ lockTitleControlsMessage: titleBindingSource?.label
471
+ ? sprintf(
472
+ /* translators: %s: Label of the bindings source. */
473
+ __( 'Connected to %s' ),
474
+ titleBindingSource.label
475
+ )
476
+ : __( 'Connected to dynamic data' ),
461
477
  };
462
478
  },
463
479
  [ clientId, isSingleSelected, metadata?.bindings ]
@@ -557,11 +573,7 @@ export default function Image( {
557
573
  disabled={ lockAltControls }
558
574
  help={
559
575
  lockAltControls ? (
560
- <>
561
- { __(
562
- 'Connected to a custom field'
563
- ) }
564
- </>
576
+ <>{ lockAltControlsMessage }</>
565
577
  ) : (
566
578
  <>
567
579
  <ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
@@ -607,11 +619,7 @@ export default function Image( {
607
619
  disabled={ lockTitleControls }
608
620
  help={
609
621
  lockTitleControls ? (
610
- <>
611
- { __(
612
- 'Connected to a custom field'
613
- ) }
614
- </>
622
+ <>{ lockTitleControlsMessage }</>
615
623
  ) : (
616
624
  <>
617
625
  { __(
@@ -652,11 +660,7 @@ export default function Image( {
652
660
  readOnly={ lockAltControls }
653
661
  help={
654
662
  lockAltControls ? (
655
- <>
656
- { __(
657
- 'Connected to a custom field'
658
- ) }
659
- </>
663
+ <>{ lockAltControlsMessage }</>
660
664
  ) : (
661
665
  <>
662
666
  <ExternalLink href="https://www.w3.org/WAI/tutorials/images/decision-tree">
@@ -694,7 +698,7 @@ export default function Image( {
694
698
  readOnly={ lockTitleControls }
695
699
  help={
696
700
  lockTitleControls ? (
697
- <>{ __( 'Connected to a custom field' ) }</>
701
+ <>{ lockTitleControlsMessage }</>
698
702
  ) : (
699
703
  <>
700
704
  { __(
@@ -29,7 +29,6 @@ import {
29
29
  useOutdentListItem,
30
30
  useSplit,
31
31
  useMerge,
32
- useCopy,
33
32
  } from './hooks';
34
33
  import { convertToListItems } from './utils';
35
34
 
@@ -79,7 +78,7 @@ export default function ListItemEdit( {
79
78
  mergeBlocks,
80
79
  } ) {
81
80
  const { placeholder, content } = attributes;
82
- const blockProps = useBlockProps( { ref: useCopy( clientId ) } );
81
+ const blockProps = useBlockProps();
83
82
  const innerBlocksProps = useInnerBlocksProps( blockProps, {
84
83
  renderAppender: false,
85
84
  __unstableDisableDropZone: true,
@@ -4,4 +4,3 @@ export { default as useEnter } from './use-enter';
4
4
  export { default as useSpace } from './use-space';
5
5
  export { default as useSplit } from './use-split';
6
6
  export { default as useMerge } from './use-merge';
7
- export { default as useCopy } from './use-copy';
@@ -2,6 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { listItem as icon } from '@wordpress/icons';
5
+ import { privateApis } from '@wordpress/block-editor';
5
6
 
6
7
  /**
7
8
  * Internal dependencies
@@ -11,6 +12,7 @@ import metadata from './block.json';
11
12
  import edit from './edit';
12
13
  import save from './save';
13
14
  import transforms from './transforms';
15
+ import { unlock } from '../lock-unlock';
14
16
 
15
17
  const { name } = metadata;
16
18
 
@@ -27,6 +29,7 @@ export const settings = {
27
29
  };
28
30
  },
29
31
  transforms,
32
+ [ unlock( privateApis ).requiresWrapperOnCopy ]: true,
30
33
  };
31
34
 
32
35
  export const init = () => initBlock( { name, metadata, settings } );
@@ -153,8 +153,8 @@ function Navigation( {
153
153
  isError: createNavigationMenuIsError,
154
154
  } = useCreateNavigationMenu( clientId );
155
155
 
156
- const createUntitledEmptyNavigationMenu = () => {
157
- createNavigationMenu( '' );
156
+ const createUntitledEmptyNavigationMenu = async () => {
157
+ await createNavigationMenu( '' );
158
158
  };
159
159
 
160
160
  const {
@@ -49,7 +49,7 @@ function NavigationMenuSelector( {
49
49
  /* translators: %s: The name of a menu. */
50
50
  const createActionLabel = __( "Create from '%s'" );
51
51
 
52
- const [ isCreatingMenu, setIsCreatingMenu ] = useState( false );
52
+ const [ isUpdatingMenuRef, setIsUpdatingMenuRef ] = useState( false );
53
53
 
54
54
  actionLabel = actionLabel || createActionLabel;
55
55
 
@@ -82,10 +82,20 @@ function NavigationMenuSelector( {
82
82
  value: id,
83
83
  label,
84
84
  ariaLabel: sprintf( actionLabel, label ),
85
+ disabled:
86
+ isUpdatingMenuRef ||
87
+ isResolvingNavigationMenus ||
88
+ ! hasResolvedNavigationMenus,
85
89
  };
86
90
  } ) || []
87
91
  );
88
- }, [ navigationMenus, actionLabel ] );
92
+ }, [
93
+ navigationMenus,
94
+ actionLabel,
95
+ isResolvingNavigationMenus,
96
+ hasResolvedNavigationMenus,
97
+ isUpdatingMenuRef,
98
+ ] );
89
99
 
90
100
  const hasNavigationMenus = !! navigationMenus?.length;
91
101
  const hasClassicMenus = !! classicMenus?.length;
@@ -99,7 +109,7 @@ function NavigationMenuSelector( {
99
109
 
100
110
  let selectorLabel = '';
101
111
 
102
- if ( isCreatingMenu || isResolvingNavigationMenus ) {
112
+ if ( isResolvingNavigationMenus ) {
103
113
  selectorLabel = __( 'Loading…' );
104
114
  } else if ( noMenuSelected || noBlockMenus || menuUnavailable ) {
105
115
  // Note: classic Menus may be available.
@@ -111,17 +121,17 @@ function NavigationMenuSelector( {
111
121
 
112
122
  useEffect( () => {
113
123
  if (
114
- isCreatingMenu &&
124
+ isUpdatingMenuRef &&
115
125
  ( createNavigationMenuIsSuccess || createNavigationMenuIsError )
116
126
  ) {
117
- setIsCreatingMenu( false );
127
+ setIsUpdatingMenuRef( false );
118
128
  }
119
129
  }, [
120
130
  hasResolvedNavigationMenus,
121
131
  createNavigationMenuIsSuccess,
122
132
  canUserCreateNavigationMenu,
123
133
  createNavigationMenuIsError,
124
- isCreatingMenu,
134
+ isUpdatingMenuRef,
125
135
  menuUnavailable,
126
136
  noBlockMenus,
127
137
  noMenuSelected,
@@ -140,12 +150,10 @@ function NavigationMenuSelector( {
140
150
  <MenuItemsChoice
141
151
  value={ currentMenuId }
142
152
  onSelect={ ( menuId ) => {
143
- setIsCreatingMenu( true );
144
153
  onSelectNavigationMenu( menuId );
145
154
  onClose();
146
155
  } }
147
156
  choices={ menuChoices }
148
- disabled={ isCreatingMenu }
149
157
  />
150
158
  </MenuGroup>
151
159
  ) }
@@ -155,9 +163,10 @@ function NavigationMenuSelector( {
155
163
  const label = decodeEntities( menu.name );
156
164
  return (
157
165
  <MenuItem
158
- onClick={ () => {
159
- setIsCreatingMenu( true );
160
- onSelectClassicMenu( menu );
166
+ onClick={ async () => {
167
+ setIsUpdatingMenuRef( true );
168
+ await onSelectClassicMenu( menu );
169
+ setIsUpdatingMenuRef( false );
161
170
  onClose();
162
171
  } }
163
172
  key={ menu.id }
@@ -165,7 +174,11 @@ function NavigationMenuSelector( {
165
174
  createActionLabel,
166
175
  label
167
176
  ) }
168
- disabled={ isCreatingMenu }
177
+ disabled={
178
+ isUpdatingMenuRef ||
179
+ isResolvingNavigationMenus ||
180
+ ! hasResolvedNavigationMenus
181
+ }
169
182
  >
170
183
  { label }
171
184
  </MenuItem>
@@ -177,12 +190,17 @@ function NavigationMenuSelector( {
177
190
  { canUserCreateNavigationMenu && (
178
191
  <MenuGroup label={ __( 'Tools' ) }>
179
192
  <MenuItem
180
- disabled={ isCreatingMenu }
181
- onClick={ () => {
193
+ onClick={ async () => {
194
+ setIsUpdatingMenuRef( true );
195
+ await onCreateNew();
196
+ setIsUpdatingMenuRef( false );
182
197
  onClose();
183
- onCreateNew();
184
- setIsCreatingMenu( true );
185
198
  } }
199
+ disabled={
200
+ isUpdatingMenuRef ||
201
+ isResolvingNavigationMenus ||
202
+ ! hasResolvedNavigationMenus
203
+ }
186
204
  >
187
205
  { __( 'Create new menu' ) }
188
206
  </MenuItem>
@@ -250,6 +250,7 @@ describe( 'NavigationMenuSelector', () => {
250
250
  const user = userEvent.setup();
251
251
  const handler = jest.fn();
252
252
 
253
+ // at the start we have the menus and we're not waiting on network
253
254
  useNavigationMenu.mockReturnValue( {
254
255
  navigationMenus: [],
255
256
  hasResolvedNavigationMenus: true,
@@ -271,6 +272,18 @@ describe( 'NavigationMenuSelector', () => {
271
272
  } )
272
273
  );
273
274
 
275
+ // creating a menu is a network activity
276
+ // so we have to wait on it
277
+ useNavigationMenu.mockReturnValue( {
278
+ navigationMenus: [],
279
+ hasResolvedNavigationMenus: false,
280
+ isResolvingNavigationMenus: true,
281
+ canUserCreateNavigationMenu: true,
282
+ canSwitchNavigationMenu: true,
283
+ } );
284
+
285
+ rerender( <NavigationMenuSelector onCreateNew={ handler } /> );
286
+
274
287
  // Re-open the dropdown (it's closed when the "Create menu" button is clicked).
275
288
  await user.click( toggleButton );
276
289
 
@@ -284,6 +297,16 @@ describe( 'NavigationMenuSelector', () => {
284
297
  } )
285
298
  ).toBeDisabled();
286
299
 
300
+ // once the menu is created
301
+ // no more network activity to wait on
302
+ useNavigationMenu.mockReturnValue( {
303
+ navigationMenus: [],
304
+ hasResolvedNavigationMenus: true,
305
+ isResolvingNavigationMenus: false,
306
+ canUserCreateNavigationMenu: true,
307
+ canSwitchNavigationMenu: true,
308
+ } );
309
+
287
310
  // Simulate the menu being created and component being re-rendered.
288
311
  rerender(
289
312
  <NavigationMenuSelector
@@ -422,7 +445,7 @@ describe( 'NavigationMenuSelector', () => {
422
445
  expect( menuItem ).toBeChecked();
423
446
  } );
424
447
 
425
- it( 'should call the handler when the navigation menu is selected and disable all options during the import/creation process', async () => {
448
+ it( 'should call the handler when the navigation menu is selected', async () => {
426
449
  const user = userEvent.setup();
427
450
 
428
451
  const handler = jest.fn();
@@ -434,7 +457,7 @@ describe( 'NavigationMenuSelector', () => {
434
457
  canSwitchNavigationMenu: true,
435
458
  } );
436
459
 
437
- const { rerender } = render(
460
+ render(
438
461
  <NavigationMenuSelector
439
462
  onSelectNavigationMenu={ handler }
440
463
  />
@@ -455,42 +478,6 @@ describe( 'NavigationMenuSelector', () => {
455
478
 
456
479
  // Check the dropdown has been closed.
457
480
  expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument();
458
-
459
- // Re-open the dropdown
460
- await user.click( screen.getByRole( 'button' ) );
461
-
462
- // Check the dropdown is again open and is in the "loading" state.
463
- expect(
464
- screen.getByRole( 'menu', {
465
- name: /Loading/,
466
- } )
467
- ).toBeInTheDocument();
468
-
469
- // // Check all menu items are present but disabled.
470
- screen.getAllByRole( 'menuitem' ).forEach( ( item ) => {
471
- // // Check all menu items are present but disabled.
472
- expect( item ).toBeDisabled();
473
- } );
474
-
475
- // // Simulate the menu being created and component being re-rendered.
476
- rerender(
477
- <NavigationMenuSelector
478
- createNavigationMenuIsSuccess={ true } // classic menu import creates a Navigation menu.
479
- />
480
- );
481
-
482
- // Todo: fix bug where aria label is not updated.
483
- // expect(
484
- // screen.getByRole( 'menu', {
485
- // name: `You are currently editing ${ navigationMenusFixture[ 0 ].title.rendered }`,
486
- // } )
487
- // ).toBeInTheDocument();
488
-
489
- // Check all menu items are re-enabled.
490
- screen.getAllByRole( 'menuitem' ).forEach( ( item ) => {
491
- // // Check all menu items are present but disabled.
492
- expect( item ).toBeEnabled();
493
- } );
494
481
  } );
495
482
  } );
496
483
 
@@ -568,9 +555,14 @@ describe( 'NavigationMenuSelector', () => {
568
555
 
569
556
  it( 'should call the handler when the classic menu item is selected and disable all options during the import/creation process', async () => {
570
557
  const user = userEvent.setup();
571
- const handler = jest.fn();
558
+ const handler = jest.fn( async () => {} );
572
559
 
560
+ // initially we have the menus, and we're not waiting on network
573
561
  useNavigationMenu.mockReturnValue( {
562
+ navigationMenus: [],
563
+ isResolvingNavigationMenus: false,
564
+ hasResolvedNavigationMenus: true,
565
+ canSwitchNavigationMenu: true,
574
566
  canUserCreateNavigationMenu: true,
575
567
  } );
576
568
 
@@ -597,6 +589,23 @@ describe( 'NavigationMenuSelector', () => {
597
589
  // Check the dropdown has been closed.
598
590
  expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument();
599
591
 
592
+ // since we're importing we are doing network activity
593
+ // so we have to wait on it
594
+ useNavigationMenu.mockReturnValue( {
595
+ navigationMenus: [],
596
+ isResolvingNavigationMenus: true,
597
+ hasResolvedNavigationMenus: false,
598
+ canUserCreateNavigationMenu: true,
599
+ } );
600
+
601
+ useNavigationEntities.mockReturnValue( {
602
+ menus: classicMenusFixture,
603
+ } );
604
+
605
+ rerender(
606
+ <NavigationMenuSelector onSelectClassicMenu={ handler } />
607
+ );
608
+
600
609
  // // Re-open the dropdown (it's closed when the "Create menu" button is clicked).
601
610
  await user.click( screen.getByRole( 'button' ) );
602
611
 
@@ -613,6 +622,19 @@ describe( 'NavigationMenuSelector', () => {
613
622
  expect( item ).toBeDisabled();
614
623
  } );
615
624
 
625
+ // once the menu is imported
626
+ // no more network activity to wait on
627
+ useNavigationMenu.mockReturnValue( {
628
+ navigationMenus: [],
629
+ isResolvingNavigationMenus: false,
630
+ hasResolvedNavigationMenus: true,
631
+ canUserCreateNavigationMenu: true,
632
+ } );
633
+
634
+ useNavigationEntities.mockReturnValue( {
635
+ menus: classicMenusFixture,
636
+ } );
637
+
616
638
  // Simulate the menu being created and component being re-rendered.
617
639
  rerender(
618
640
  <NavigationMenuSelector
@@ -552,7 +552,7 @@ class WP_Navigation_Block_Renderer {
552
552
  return '';
553
553
  }
554
554
  // When adding to this array be mindful of security concerns.
555
- $nav_element_context = data_wp_context(
555
+ $nav_element_context = wp_interactivity_data_wp_context(
556
556
  array(
557
557
  'overlayOpenedBy' => array(
558
558
  'click' => false,
@@ -1458,13 +1458,18 @@ function block_core_navigation_set_ignored_hooked_blocks_metadata( $inner_blocks
1458
1458
  /**
1459
1459
  * Updates the post meta with the list of ignored hooked blocks when the navigation is created or updated via the REST API.
1460
1460
  *
1461
- * @param WP_Post $post Post object.
1461
+ * @param stdClass $post Post object.
1462
1462
  */
1463
1463
  function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
1464
1464
  // We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
1465
1465
  // all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
1466
1466
  $blocks = parse_blocks( $post->post_content );
1467
- $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, $post );
1467
+
1468
+ // Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that
1469
+ // we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be
1470
+ // used as context for hooked blocks insertion).
1471
+ // We thus have to look it up from the DB,based on `$post->ID`.
1472
+ $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, get_post( $post->ID ) );
1468
1473
 
1469
1474
  $root_nav_block = parse_blocks( $markup )[0];
1470
1475
  $ignored_hooked_blocks = isset( $root_nav_block['attrs']['metadata']['ignoredHookedBlocks'] )
@@ -1480,14 +1485,8 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
1480
1485
  update_post_meta( $post->ID, '_wp_ignored_hooked_blocks', json_encode( $ignored_hooked_blocks ) );
1481
1486
  }
1482
1487
 
1483
- $serialized_inner_blocks = block_core_navigation_remove_serialized_parent_block( $markup );
1484
-
1485
- wp_update_post(
1486
- array(
1487
- 'ID' => $post->ID,
1488
- 'post_content' => $serialized_inner_blocks,
1489
- )
1490
- );
1488
+ $post->post_content = block_core_navigation_remove_serialized_parent_block( $markup );
1489
+ return $post;
1491
1490
  }
1492
1491
 
1493
1492
  // Before adding our filter, we verify if it's already added in Core.
@@ -1497,8 +1496,15 @@ $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ig
1497
1496
 
1498
1497
  // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1499
1498
  // that are not present in Gutenberg's WP 6.5 compatibility layer.
1500
- if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1501
- add_action( 'rest_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10, 3 );
1499
+ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1500
+ add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10 );
1501
+ }
1502
+
1503
+ // Previous versions of Gutenberg and WordPress 6.5 Betas were attaching the block_core_navigation_update_ignore_hooked_blocks_meta
1504
+ // function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_).
1505
+ // To avoid collisions, we need to remove the filter from that action if it's present.
1506
+ if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1507
+ remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback, 10 );
1502
1508
  }
1503
1509
 
1504
1510
  /**
@@ -179,7 +179,7 @@ function render_block_core_search( $attributes ) {
179
179
  if ( $is_expandable_searchfield ) {
180
180
  $aria_label_expanded = __( 'Submit Search' );
181
181
  $aria_label_collapsed = __( 'Expand search field' );
182
- $form_context = data_wp_context(
182
+ $form_context = wp_interactivity_data_wp_context(
183
183
  array(
184
184
  'isSearchInputVisible' => $open_by_default,
185
185
  'inputId' => $input_id,
@@ -268,6 +268,14 @@ const SiteLogo = ( {
268
268
  </ResizableBox>
269
269
  );
270
270
 
271
+ // Support the previous location for the Site Icon settings. To be removed
272
+ // when the required WP core version for Gutenberg is >= 6.5.0.
273
+ const shouldUseNewUrl = ! window?.__experimentalUseCustomizerSiteLogoUrl;
274
+
275
+ const siteIconSettingsUrl = shouldUseNewUrl
276
+ ? siteUrl + '/wp-admin/options-general.php'
277
+ : siteUrl + '/wp-admin/customize.php?autofocus[section]=title_tagline';
278
+
271
279
  const syncSiteIconHelpText = createInterpolateElement(
272
280
  __(
273
281
  'Site Icons are what you see in browser tabs, bookmark bars, and within the WordPress mobile apps. To use a custom icon that is different from your site logo, use the <a>Site Icon settings</a>.'
@@ -276,10 +284,7 @@ const SiteLogo = ( {
276
284
  a: (
277
285
  // eslint-disable-next-line jsx-a11y/anchor-has-content
278
286
  <a
279
- href={
280
- siteUrl +
281
- '/wp-admin/customize.php?autofocus[section]=title_tagline'
282
- }
287
+ href={ siteIconSettingsUrl }
283
288
  target="_blank"
284
289
  rel="noopener noreferrer"
285
290
  />
@@ -331,7 +336,7 @@ const SiteLogo = ( {
331
336
  <>
332
337
  <ToggleControl
333
338
  __nextHasNoMarginBottom
334
- label={ __( 'Use as site icon' ) }
339
+ label={ __( 'Use as Site Icon' ) }
335
340
  onChange={ ( value ) => {
336
341
  setAttributes( { shouldSyncIcon: value } );
337
342
  setIcon( value ? logoId : undefined );
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = useCopy;
7
- var _compose = require("@wordpress/compose");
8
- var _blockEditor = require("@wordpress/block-editor");
9
- var _data = require("@wordpress/data");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- function useCopy(clientId) {
15
- const {
16
- getBlockRootClientId,
17
- getBlockName,
18
- getBlockAttributes
19
- } = (0, _data.useSelect)(_blockEditor.store);
20
- return (0, _compose.useRefEffect)(node => {
21
- function onCopy(event) {
22
- // The event propagates through all nested lists, so don't override
23
- // when copying nested list items.
24
- if (event.clipboardData.getData('__unstableWrapperBlockName')) {
25
- return;
26
- }
27
- const rootClientId = getBlockRootClientId(clientId);
28
- event.clipboardData.setData('__unstableWrapperBlockName', getBlockName(rootClientId));
29
- event.clipboardData.setData('__unstableWrapperBlockAttributes', JSON.stringify(getBlockAttributes(rootClientId)));
30
- }
31
- node.addEventListener('copy', onCopy);
32
- node.addEventListener('cut', onCopy);
33
- return () => {
34
- node.removeEventListener('copy', onCopy);
35
- node.removeEventListener('cut', onCopy);
36
- };
37
- }, []);
38
- }
39
- //# sourceMappingURL=use-copy.js.map