@wordpress/block-library 8.19.8 → 8.19.10

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 (49) hide show
  1. package/build/file/view.js +1 -1
  2. package/build/file/view.js.map +1 -1
  3. package/build/image/image.js +8 -2
  4. package/build/image/image.js.map +1 -1
  5. package/build/image/view.js +10 -20
  6. package/build/image/view.js.map +1 -1
  7. package/build/navigation/view.js +20 -5
  8. package/build/navigation/view.js.map +1 -1
  9. package/build/query/edit/enhanced-pagination-modal.js +4 -4
  10. package/build/query/edit/enhanced-pagination-modal.js.map +1 -1
  11. package/build/query/edit/inspector-controls/enhanced-pagination-control.js +9 -5
  12. package/build/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -1
  13. package/build/query/utils.js +10 -8
  14. package/build/query/utils.js.map +1 -1
  15. package/build/term-description/index.js +0 -1
  16. package/build/term-description/index.js.map +1 -1
  17. package/build-module/file/view.js +2 -2
  18. package/build-module/file/view.js.map +1 -1
  19. package/build-module/image/image.js +8 -2
  20. package/build-module/image/image.js.map +1 -1
  21. package/build-module/image/view.js +10 -20
  22. package/build-module/image/view.js.map +1 -1
  23. package/build-module/navigation/view.js +20 -5
  24. package/build-module/navigation/view.js.map +1 -1
  25. package/build-module/query/edit/enhanced-pagination-modal.js +5 -5
  26. package/build-module/query/edit/enhanced-pagination-modal.js.map +1 -1
  27. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js +10 -6
  28. package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -1
  29. package/build-module/query/utils.js +8 -5
  30. package/build-module/query/utils.js.map +1 -1
  31. package/build-module/term-description/index.js +0 -1
  32. package/build-module/term-description/index.js.map +1 -1
  33. package/build-style/file/style-rtl.css +0 -5
  34. package/build-style/file/style.css +0 -5
  35. package/build-style/style-rtl.css +0 -5
  36. package/build-style/style.css +0 -5
  37. package/package.json +32 -32
  38. package/src/file/index.php +2 -1
  39. package/src/file/style.scss +0 -6
  40. package/src/file/view.js +2 -2
  41. package/src/image/image.js +13 -2
  42. package/src/image/index.php +5 -6
  43. package/src/image/view.js +13 -19
  44. package/src/navigation/index.php +7 -0
  45. package/src/navigation/view.js +18 -6
  46. package/src/query/edit/enhanced-pagination-modal.js +5 -5
  47. package/src/query/edit/inspector-controls/enhanced-pagination-control.js +18 -9
  48. package/src/query/utils.js +14 -7
  49. package/src/term-description/block.json +0 -1
package/src/image/view.js CHANGED
@@ -135,7 +135,7 @@ store(
135
135
  false
136
136
  );
137
137
  },
138
- hideLightbox: async ( { context, event } ) => {
138
+ hideLightbox: async ( { context } ) => {
139
139
  context.core.image.hideAnimationEnabled = true;
140
140
  if ( context.core.image.lightboxEnabled ) {
141
141
  // We want to wait until the close animation is completed
@@ -149,19 +149,15 @@ store(
149
149
  'scroll',
150
150
  scrollCallback
151
151
  );
152
+ // If we don't delay before changing the focus,
153
+ // the focus ring will appear on Firefox before
154
+ // the image has finished animating, which looks broken.
155
+ context.core.image.lightboxTriggerRef.focus( {
156
+ preventScroll: true,
157
+ } );
152
158
  }, 450 );
153
159
 
154
160
  context.core.image.lightboxEnabled = false;
155
-
156
- // We want to avoid drawing attention to the button
157
- // after the lightbox closes for mouse and touch users.
158
- // Note that the `event.pointerType` property returns
159
- // as an empty string if a keyboard fired the event.
160
- if ( event.pointerType === '' ) {
161
- context.core.image.lastFocusedElement.focus( {
162
- preventScroll: true,
163
- } );
164
- }
165
161
  }
166
162
  },
167
163
  handleKeydown: ( { context, actions, event } ) => {
@@ -266,6 +262,10 @@ store(
266
262
  image: {
267
263
  initOriginImage: ( { context, ref } ) => {
268
264
  context.core.image.imageRef = ref;
265
+ context.core.image.lightboxTriggerRef =
266
+ ref.parentElement.querySelector(
267
+ '.lightbox-trigger'
268
+ );
269
269
  if ( ref.complete ) {
270
270
  context.core.image.imageLoaded = true;
271
271
  context.core.image.imageCurrentSrc = ref.currentSrc;
@@ -282,14 +282,8 @@ store(
282
282
  focusableElements.length - 1
283
283
  ];
284
284
 
285
- // We want to avoid drawing unnecessary attention to the close
286
- // button for mouse and touch users. Note that even if opening
287
- // the lightbox via keyboard, the event fired is of type
288
- // `pointerEvent`, so we need to rely on the `event.pointerType`
289
- // property, which returns an empty string for keyboard events.
290
- if ( context.core.image.pointerType === '' ) {
291
- ref.querySelector( '.close-button' ).focus();
292
- }
285
+ // Move focus to the dialog when opening it.
286
+ ref.focus();
293
287
  }
294
288
  },
295
289
  setButtonStyles: ( { context, ref } ) => {
@@ -90,6 +90,13 @@ function block_core_navigation_add_directives_to_submenu( $w, $block_attributes
90
90
  $w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
91
91
  $w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
92
92
  $w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
93
+
94
+ // This is a fix for Safari. Without it, Safari doesn't change the active
95
+ // element when the user clicks on a button. It can be removed once we add
96
+ // an overlay to capture the clicks, instead of relying on the focusout
97
+ // event.
98
+ $w->set_attribute( 'tabindex', '-1' );
99
+
93
100
  if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
94
101
  $w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
95
102
  $w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
@@ -13,10 +13,14 @@ const focusableSelectors = [
13
13
  '[tabindex]:not([tabindex^="-"])',
14
14
  ];
15
15
 
16
+ // This is a fix for Safari in iOS/iPadOS. Without it, Safari doesn't focus out
17
+ // when the user taps in the body. It can be removed once we add an overlay to
18
+ // capture the clicks, instead of relying on the focusout event.
19
+ document.addEventListener( 'click', () => {} );
20
+
16
21
  const openMenu = ( store, menuOpenedOn ) => {
17
- const { context, ref, selectors } = store;
22
+ const { context, selectors } = store;
18
23
  selectors.core.navigation.menuOpenedBy( store )[ menuOpenedOn ] = true;
19
- context.core.navigation.previousFocus = ref;
20
24
  if ( context.core.navigation.type === 'overlay' ) {
21
25
  // Add a `has-modal-open` class to the <html> root.
22
26
  document.documentElement.classList.add( 'has-modal-open' );
@@ -33,7 +37,7 @@ const closeMenu = ( store, menuClosedOn ) => {
33
37
  window.document.activeElement
34
38
  )
35
39
  ) {
36
- context.core.navigation.previousFocus.focus();
40
+ context.core.navigation.previousFocus?.focus();
37
41
  }
38
42
  context.core.navigation.modal = null;
39
43
  context.core.navigation.previousFocus = null;
@@ -130,6 +134,8 @@ wpStore( {
130
134
  closeMenu( store, 'hover' );
131
135
  },
132
136
  openMenuOnClick( store ) {
137
+ const { context, ref } = store;
138
+ context.core.navigation.previousFocus = ref;
133
139
  openMenu( store, 'click' );
134
140
  },
135
141
  closeMenuOnClick( store ) {
@@ -140,13 +146,16 @@ wpStore( {
140
146
  openMenu( store, 'focus' );
141
147
  },
142
148
  toggleMenuOnClick: ( store ) => {
143
- const { selectors } = store;
149
+ const { selectors, context, ref } = store;
150
+ // Safari won't send focus to the clicked element, so we need to manually place it: https://bugs.webkit.org/show_bug.cgi?id=22261
151
+ if ( window.document.activeElement !== ref ) ref.focus();
144
152
  const menuOpenedBy =
145
153
  selectors.core.navigation.menuOpenedBy( store );
146
154
  if ( menuOpenedBy.click || menuOpenedBy.focus ) {
147
155
  closeMenu( store, 'click' );
148
156
  closeMenu( store, 'focus' );
149
157
  } else {
158
+ context.core.navigation.previousFocus = ref;
150
159
  openMenu( store, 'click' );
151
160
  }
152
161
  },
@@ -194,11 +203,14 @@ wpStore( {
194
203
  // event.relatedTarget === The element receiving focus (if any)
195
204
  // When focusout is outsite the document,
196
205
  // `window.document.activeElement` doesn't change.
206
+
207
+ // The event.relatedTarget is null when something outside the navigation menu is clicked. This is only necessary for Safari.
197
208
  if (
198
- ! context.core.navigation.modal?.contains(
209
+ event.relatedTarget === null ||
210
+ ( ! context.core.navigation.modal?.contains(
199
211
  event.relatedTarget
200
212
  ) &&
201
- event.target !== window.document.activeElement
213
+ event.target !== window.document.activeElement )
202
214
  ) {
203
215
  closeMenu( store, 'click' );
204
216
  closeMenu( store, 'focus' );
@@ -12,10 +12,10 @@ import { useState, useEffect } from '@wordpress/element';
12
12
  /**
13
13
  * Internal dependencies
14
14
  */
15
- import { useContainsThirdPartyBlocks } from '../utils';
15
+ import { useUnsupportedBlockList } from '../utils';
16
16
 
17
17
  const disableEnhancedPaginationDescription = __(
18
- 'Plugin blocks are not supported yet. For the enhanced pagination to work, remove the plugin block, then re-enable "Enhanced pagination" in the Query Block settings.'
18
+ 'You have added unsupported blocks. For the enhanced pagination to work, remove them, then re-enable "Enhanced pagination" in the Query Block settings.'
19
19
  );
20
20
 
21
21
  const modalDescriptionId =
@@ -28,11 +28,11 @@ export default function EnhancedPaginationModal( {
28
28
  } ) {
29
29
  const [ isOpen, setOpen ] = useState( false );
30
30
 
31
- const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId );
31
+ const unsupported = useUnsupportedBlockList( clientId );
32
32
 
33
33
  useEffect( () => {
34
- setOpen( containsThirdPartyBlocks && enhancedPagination );
35
- }, [ containsThirdPartyBlocks, enhancedPagination, setOpen ] );
34
+ setOpen( !! unsupported.length && enhancedPagination );
35
+ }, [ unsupported.length, enhancedPagination, setOpen ] );
36
36
 
37
37
  return (
38
38
  isOpen && (
@@ -3,22 +3,19 @@
3
3
  */
4
4
  import { ToggleControl, Notice } from '@wordpress/components';
5
5
  import { __ } from '@wordpress/i18n';
6
+ import { BlockTitle } from '@wordpress/block-editor';
6
7
 
7
8
  /**
8
9
  * Internal dependencies
9
10
  */
10
- import { useContainsThirdPartyBlocks } from '../../utils';
11
+ import { useUnsupportedBlockList } from '../../utils';
11
12
 
12
13
  export default function EnhancedPaginationControl( {
13
14
  enhancedPagination,
14
15
  setAttributes,
15
16
  clientId,
16
17
  } ) {
17
- const enhancedPaginationNotice = __(
18
- "Enhanced pagination doesn't support plugin blocks yet. If you want to enable it, you have to remove all plugin blocks from the Query Loop."
19
- );
20
-
21
- const containsThirdPartyBlocks = useContainsThirdPartyBlocks( clientId );
18
+ const unsupported = useUnsupportedBlockList( clientId );
22
19
 
23
20
  return (
24
21
  <>
@@ -28,20 +25,32 @@ export default function EnhancedPaginationControl( {
28
25
  'Browsing between pages won’t require a full page reload.'
29
26
  ) }
30
27
  checked={ !! enhancedPagination }
31
- disabled={ containsThirdPartyBlocks }
28
+ disabled={ unsupported.length }
32
29
  onChange={ ( value ) => {
33
30
  setAttributes( {
34
31
  enhancedPagination: !! value,
35
32
  } );
36
33
  } }
37
34
  />
38
- { containsThirdPartyBlocks && (
35
+ { !! unsupported.length && (
39
36
  <Notice
40
37
  status="warning"
41
38
  isDismissible={ false }
42
39
  className="wp-block-query__enhanced-pagination-notice"
43
40
  >
44
- { enhancedPaginationNotice }
41
+ { __(
42
+ "Enhanced pagination doesn't support the following blocks:"
43
+ ) }
44
+ <ul>
45
+ { unsupported.map( ( id ) => (
46
+ <li key={ id }>
47
+ <BlockTitle clientId={ id } />
48
+ </li>
49
+ ) ) }
50
+ </ul>
51
+ { __(
52
+ 'If you want to enable it, you have to remove all unsupported blocks first.'
53
+ ) }
45
54
  </Notice>
46
55
  ) }
47
56
  </>
@@ -346,21 +346,28 @@ export const usePatterns = ( clientId, name ) => {
346
346
  };
347
347
 
348
348
  /**
349
- * Hook that returns whether the Query Loop with the given `clientId` contains
350
- * any third-party block.
349
+ * Hook that returns a list of unsupported blocks inside the Query Loop with the
350
+ * given `clientId`.
351
351
  *
352
352
  * @param {string} clientId The block's client ID.
353
- * @return {boolean} True if it contains third-party blocks.
353
+ * @return {string[]} List of block titles.
354
354
  */
355
- export const useContainsThirdPartyBlocks = ( clientId ) => {
355
+ export const useUnsupportedBlockList = ( clientId ) => {
356
356
  return useSelect(
357
357
  ( select ) => {
358
358
  const { getClientIdsOfDescendants, getBlockName } =
359
359
  select( blockEditorStore );
360
360
 
361
- return getClientIdsOfDescendants( clientId ).some(
362
- ( descendantClientId ) =>
363
- ! getBlockName( descendantClientId ).startsWith( 'core/' )
361
+ return getClientIdsOfDescendants( clientId ).filter(
362
+ ( descendantClientId ) => {
363
+ const blockName = getBlockName( descendantClientId );
364
+ return (
365
+ ! blockName.startsWith( 'core/' ) ||
366
+ blockName === 'core/post-content' ||
367
+ blockName === 'core/template-part' ||
368
+ blockName === 'core/block'
369
+ );
370
+ }
364
371
  );
365
372
  },
366
373
  [ clientId ]
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "$schema": "https://schemas.wp.org/trunk/block.json",
3
3
  "apiVersion": 3,
4
- "__experimental": "fse",
5
4
  "name": "core/term-description",
6
5
  "title": "Term Description",
7
6
  "category": "theme",