@wordpress/block-editor 10.0.2 → 10.0.3

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.
@@ -8,7 +8,12 @@ import classnames from 'classnames';
8
8
  */
9
9
  import { useMergeRefs } from '@wordpress/compose';
10
10
  import { Popover } from '@wordpress/components';
11
- import { forwardRef, useMemo } from '@wordpress/element';
11
+ import {
12
+ forwardRef,
13
+ useMemo,
14
+ useReducer,
15
+ useLayoutEffect,
16
+ } from '@wordpress/element';
12
17
 
13
18
  /**
14
19
  * Internal dependencies
@@ -16,6 +21,8 @@ import { forwardRef, useMemo } from '@wordpress/element';
16
21
  import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
17
22
  import usePopoverScroll from './use-popover-scroll';
18
23
 
24
+ const MAX_POPOVER_RECOMPUTE_COUNTER = Number.MAX_SAFE_INTEGER;
25
+
19
26
  function BlockPopover(
20
27
  {
21
28
  clientId,
@@ -47,8 +54,41 @@ function BlockPopover(
47
54
  };
48
55
  }, [ selectedElement, lastSelectedElement, __unstableRefreshSize ] );
49
56
 
57
+ const [ popoverAnchorRecomputeCounter, forceRecomputePopoverAnchor ] =
58
+ useReducer(
59
+ // Module is there to make sure that the counter doesn't overflow.
60
+ ( s ) => ( s + 1 ) % MAX_POPOVER_RECOMPUTE_COUNTER,
61
+ 0
62
+ );
63
+
64
+ // When blocks are moved up/down, they are animated to their new position by
65
+ // updating the `transform` property manually (i.e. without using CSS
66
+ // transitions or animations). The animation, which can also scroll the block
67
+ // editor, can sometimes cause the position of the Popover to get out of sync.
68
+ // A MutationObserver is therefore used to make sure that changes to the
69
+ // selectedElement's attribute (i.e. `transform`) can be tracked and used to
70
+ // trigger the Popover to rerender.
71
+ useLayoutEffect( () => {
72
+ if ( ! selectedElement ) {
73
+ return;
74
+ }
75
+
76
+ const observer = new window.MutationObserver(
77
+ forceRecomputePopoverAnchor
78
+ );
79
+ observer.observe( selectedElement, { attributes: true } );
80
+
81
+ return () => {
82
+ observer.disconnect();
83
+ };
84
+ }, [ selectedElement ] );
85
+
50
86
  const popoverAnchor = useMemo( () => {
51
87
  if (
88
+ // popoverAnchorRecomputeCounter is by definition always equal or greater
89
+ // than 0. This check is only there to satisfy the correctness of the
90
+ // exhaustive-deps rule for the `useMemo` hook.
91
+ popoverAnchorRecomputeCounter < 0 ||
52
92
  ! selectedElement ||
53
93
  ( bottomClientId && ! lastSelectedElement )
54
94
  ) {
@@ -88,7 +128,12 @@ function BlockPopover(
88
128
  },
89
129
  ownerDocument: selectedElement.ownerDocument,
90
130
  };
91
- }, [ bottomClientId, lastSelectedElement, selectedElement ] );
131
+ }, [
132
+ bottomClientId,
133
+ lastSelectedElement,
134
+ selectedElement,
135
+ popoverAnchorRecomputeCounter,
136
+ ] );
92
137
 
93
138
  if ( ! selectedElement || ( bottomClientId && ! lastSelectedElement ) ) {
94
139
  return null;
@@ -188,6 +188,7 @@ function ListView(
188
188
  onCollapseRow={ collapseRow }
189
189
  onExpandRow={ expandRow }
190
190
  onFocusRow={ focusRow }
191
+ applicationAriaLabel={ __( 'Block navigation structure' ) }
191
192
  >
192
193
  <ListViewContext.Provider value={ contextValue }>
193
194
  <ListViewBranch
@@ -173,6 +173,13 @@ function RichTextWrapper(
173
173
 
174
174
  // Handle deprecated format.
175
175
  if ( Array.isArray( originalValue ) ) {
176
+ deprecated( 'wp.blockEditor.RichText value prop as children type', {
177
+ since: '6.1',
178
+ version: '6.3',
179
+ alternative: 'value prop as string',
180
+ link: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',
181
+ } );
182
+
176
183
  adjustedValue = childrenSource.toHTML( originalValue );
177
184
  adjustedOnChange = ( newValue ) =>
178
185
  originalOnChange(
@@ -436,6 +443,13 @@ ForwardedRichTextContainer.Content = ( {
436
443
  } ) => {
437
444
  // Handle deprecated `children` and `node` sources.
438
445
  if ( Array.isArray( value ) ) {
446
+ deprecated( 'wp.blockEditor.RichText value prop as children type', {
447
+ since: '6.1',
448
+ version: '6.3',
449
+ alternative: 'value prop as string',
450
+ link: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',
451
+ } );
452
+
439
453
  value = childrenSource.toHTML( value );
440
454
  }
441
455