@wordpress/block-library 8.23.0 → 8.24.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 (136) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/block/edit.js +8 -11
  3. package/build/block/edit.js.map +1 -1
  4. package/build/block/edit.native.js +3 -4
  5. package/build/block/edit.native.js.map +1 -1
  6. package/build/button/edit.js +4 -7
  7. package/build/button/edit.js.map +1 -1
  8. package/build/column/edit.js +1 -1
  9. package/build/column/edit.js.map +1 -1
  10. package/build/column/edit.native.js +1 -1
  11. package/build/column/edit.native.js.map +1 -1
  12. package/build/cover/edit/index.js +2 -1
  13. package/build/cover/edit/index.js.map +1 -1
  14. package/build/file/edit.js +8 -9
  15. package/build/file/edit.js.map +1 -1
  16. package/build/file/view.js +4 -6
  17. package/build/file/view.js.map +1 -1
  18. package/build/group/edit.js +3 -7
  19. package/build/group/edit.js.map +1 -1
  20. package/build/image/edit.js +17 -18
  21. package/build/image/edit.js.map +1 -1
  22. package/build/image/edit.native.js +22 -15
  23. package/build/image/edit.native.js.map +1 -1
  24. package/build/image/image.js +35 -27
  25. package/build/image/image.js.map +1 -1
  26. package/build/image/index.js +2 -3
  27. package/build/image/index.js.map +1 -1
  28. package/build/image/view.js +233 -268
  29. package/build/image/view.js.map +1 -1
  30. package/build/navigation/view.js +153 -176
  31. package/build/navigation/view.js.map +1 -1
  32. package/build/navigation-link/index.js +2 -1
  33. package/build/navigation-link/index.js.map +1 -1
  34. package/build/pattern/edit.js +1 -3
  35. package/build/pattern/edit.js.map +1 -1
  36. package/build/post-template/edit.js +1 -1
  37. package/build/post-template/edit.js.map +1 -1
  38. package/build/query/view.js +52 -60
  39. package/build/query/view.js.map +1 -1
  40. package/build/search/view.js +66 -74
  41. package/build/search/view.js.map +1 -1
  42. package/build/utils/remove-anchor-tag.js +17 -0
  43. package/build/utils/remove-anchor-tag.js.map +1 -0
  44. package/build-module/block/edit.js +8 -11
  45. package/build-module/block/edit.js.map +1 -1
  46. package/build-module/block/edit.native.js +3 -4
  47. package/build-module/block/edit.native.js.map +1 -1
  48. package/build-module/button/edit.js +4 -7
  49. package/build-module/button/edit.js.map +1 -1
  50. package/build-module/column/edit.js +1 -1
  51. package/build-module/column/edit.js.map +1 -1
  52. package/build-module/column/edit.native.js +1 -1
  53. package/build-module/column/edit.native.js.map +1 -1
  54. package/build-module/cover/edit/index.js +2 -1
  55. package/build-module/cover/edit/index.js.map +1 -1
  56. package/build-module/file/edit.js +8 -9
  57. package/build-module/file/edit.js.map +1 -1
  58. package/build-module/file/view.js +5 -7
  59. package/build-module/file/view.js.map +1 -1
  60. package/build-module/group/edit.js +3 -7
  61. package/build-module/group/edit.js.map +1 -1
  62. package/build-module/image/edit.js +18 -19
  63. package/build-module/image/edit.js.map +1 -1
  64. package/build-module/image/edit.native.js +23 -16
  65. package/build-module/image/edit.native.js.map +1 -1
  66. package/build-module/image/image.js +36 -28
  67. package/build-module/image/image.js.map +1 -1
  68. package/build-module/image/index.js +2 -3
  69. package/build-module/image/index.js.map +1 -1
  70. package/build-module/image/view.js +234 -269
  71. package/build-module/image/view.js.map +1 -1
  72. package/build-module/navigation/view.js +154 -177
  73. package/build-module/navigation/view.js.map +1 -1
  74. package/build-module/navigation-link/index.js +2 -1
  75. package/build-module/navigation-link/index.js.map +1 -1
  76. package/build-module/pattern/edit.js +1 -3
  77. package/build-module/pattern/edit.js.map +1 -1
  78. package/build-module/post-template/edit.js +1 -1
  79. package/build-module/post-template/edit.js.map +1 -1
  80. package/build-module/query/view.js +53 -61
  81. package/build-module/query/view.js.map +1 -1
  82. package/build-module/search/view.js +67 -75
  83. package/build-module/search/view.js.map +1 -1
  84. package/build-module/utils/remove-anchor-tag.js +11 -0
  85. package/build-module/utils/remove-anchor-tag.js.map +1 -0
  86. package/build-style/cover/style-rtl.css +14 -14
  87. package/build-style/cover/style.css +14 -14
  88. package/build-style/editor-rtl.css +6 -9
  89. package/build-style/editor.css +6 -9
  90. package/build-style/gallery/style-rtl.css +28 -0
  91. package/build-style/gallery/style.css +28 -0
  92. package/build-style/image/editor-rtl.css +0 -3
  93. package/build-style/image/editor.css +0 -3
  94. package/build-style/style-rtl.css +42 -14
  95. package/build-style/style.css +42 -14
  96. package/package.json +32 -32
  97. package/src/block/edit.js +18 -19
  98. package/src/block/edit.native.js +5 -13
  99. package/src/button/edit.js +6 -6
  100. package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
  101. package/src/buttons/test/edit.native.js +0 -27
  102. package/src/column/edit.js +1 -1
  103. package/src/column/edit.native.js +1 -1
  104. package/src/cover/edit/index.js +1 -0
  105. package/src/cover/style.scss +1 -1
  106. package/src/cover/test/edit.js +1 -1
  107. package/src/editor.scss +6 -6
  108. package/src/file/edit.js +11 -10
  109. package/src/file/index.php +30 -11
  110. package/src/file/view.js +5 -7
  111. package/src/gallery/style.scss +1 -0
  112. package/src/group/edit.js +3 -11
  113. package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
  114. package/src/heading/test/index.native.js +40 -0
  115. package/src/image/block.json +2 -3
  116. package/src/image/edit.js +16 -21
  117. package/src/image/edit.native.js +17 -18
  118. package/src/image/editor.scss +0 -7
  119. package/src/image/image.js +48 -51
  120. package/src/image/index.php +54 -45
  121. package/src/image/view.js +278 -334
  122. package/src/navigation/index.php +19 -10
  123. package/src/navigation/view.js +159 -192
  124. package/src/navigation-link/block.json +2 -1
  125. package/src/paragraph/test/edit.native.js +37 -1
  126. package/src/pattern/edit.js +5 -3
  127. package/src/post-template/edit.js +1 -1
  128. package/src/query/index.php +36 -22
  129. package/src/query/view.js +58 -65
  130. package/src/query-pagination-next/index.php +3 -3
  131. package/src/query-pagination-numbers/index.php +1 -1
  132. package/src/query-pagination-previous/index.php +3 -3
  133. package/src/search/index.php +40 -40
  134. package/src/search/view.js +58 -63
  135. package/src/utils/remove-anchor-tag.js +10 -0
  136. package/tsconfig.json +1 -0
package/src/query/view.js CHANGED
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store, navigate, prefetch } from '@wordpress/interactivity';
4
+ import {
5
+ store,
6
+ getContext,
7
+ getElement,
8
+ navigate,
9
+ prefetch,
10
+ } from '@wordpress/interactivity';
5
11
 
6
12
  const isValidLink = ( ref ) =>
7
13
  ref &&
@@ -18,83 +24,70 @@ const isValidEvent = ( event ) =>
18
24
  ! event.shiftKey &&
19
25
  ! event.defaultPrevented;
20
26
 
21
- store( {
22
- selectors: {
23
- core: {
24
- query: {
25
- startAnimation: ( { context } ) =>
26
- context.core.query.animation === 'start',
27
- finishAnimation: ( { context } ) =>
28
- context.core.query.animation === 'finish',
29
- },
27
+ store( 'core/query', {
28
+ state: {
29
+ get startAnimation() {
30
+ return getContext().animation === 'start';
31
+ },
32
+ get finishAnimation() {
33
+ return getContext().animation === 'finish';
30
34
  },
31
35
  },
32
36
  actions: {
33
- core: {
34
- query: {
35
- navigate: async ( { event, ref, context } ) => {
36
- const isDisabled = ref.closest( '[data-wp-navigation-id]' )
37
- ?.dataset.wpNavigationDisabled;
37
+ *navigate( event ) {
38
+ const ctx = getContext();
39
+ const { ref } = getElement();
40
+ const isDisabled = ref.closest( '[data-wp-navigation-id]' )?.dataset
41
+ .wpNavigationDisabled;
38
42
 
39
- if (
40
- isValidLink( ref ) &&
41
- isValidEvent( event ) &&
42
- ! isDisabled
43
- ) {
44
- event.preventDefault();
43
+ if ( isValidLink( ref ) && isValidEvent( event ) && ! isDisabled ) {
44
+ event.preventDefault();
45
45
 
46
- const id = ref.closest( '[data-wp-navigation-id]' )
47
- .dataset.wpNavigationId;
46
+ const id = ref.closest( '[data-wp-navigation-id]' ).dataset
47
+ .wpNavigationId;
48
48
 
49
- // Don't announce the navigation immediately, wait 400 ms.
50
- const timeout = setTimeout( () => {
51
- context.core.query.message =
52
- context.core.query.loadingText;
53
- context.core.query.animation = 'start';
54
- }, 400 );
49
+ // Don't announce the navigation immediately, wait 400 ms.
50
+ const timeout = setTimeout( () => {
51
+ ctx.message = ctx.loadingText;
52
+ ctx.animation = 'start';
53
+ }, 400 );
55
54
 
56
- await navigate( ref.href );
55
+ yield navigate( ref.href );
57
56
 
58
- // Dismiss loading message if it hasn't been added yet.
59
- clearTimeout( timeout );
57
+ // Dismiss loading message if it hasn't been added yet.
58
+ clearTimeout( timeout );
60
59
 
61
- // Announce that the page has been loaded. If the message is the
62
- // same, we use a no-break space similar to the @wordpress/a11y
63
- // package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
64
- context.core.query.message =
65
- context.core.query.loadedText +
66
- ( context.core.query.message ===
67
- context.core.query.loadedText
68
- ? '\u00A0'
69
- : '' );
60
+ // Announce that the page has been loaded. If the message is the
61
+ // same, we use a no-break space similar to the @wordpress/a11y
62
+ // package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
63
+ ctx.message =
64
+ ctx.loadedText +
65
+ ( ctx.message === ctx.loadedText ? '\u00A0' : '' );
70
66
 
71
- context.core.query.animation = 'finish';
72
- context.core.query.url = ref.href;
67
+ ctx.animation = 'finish';
68
+ ctx.url = ref.href;
73
69
 
74
- // Focus the first anchor of the Query block.
75
- const firstAnchor = `[data-wp-navigation-id=${ id }] .wp-block-post-template a[href]`;
76
- document.querySelector( firstAnchor )?.focus();
77
- }
78
- },
79
- prefetch: async ( { ref } ) => {
80
- const isDisabled = ref.closest( '[data-wp-navigation-id]' )
81
- ?.dataset.wpNavigationDisabled;
82
- if ( isValidLink( ref ) && ! isDisabled ) {
83
- await prefetch( ref.href );
84
- }
85
- },
86
- },
70
+ // Focus the first anchor of the Query block.
71
+ const firstAnchor = `[data-wp-navigation-id=${ id }] .wp-block-post-template a[href]`;
72
+ document.querySelector( firstAnchor )?.focus();
73
+ }
74
+ },
75
+ *prefetch() {
76
+ const { ref } = getElement();
77
+ const isDisabled = ref.closest( '[data-wp-navigation-id]' )?.dataset
78
+ .wpNavigationDisabled;
79
+ if ( isValidLink( ref ) && ! isDisabled ) {
80
+ yield prefetch( ref.href );
81
+ }
87
82
  },
88
83
  },
89
- effects: {
90
- core: {
91
- query: {
92
- prefetch: async ( { ref, context } ) => {
93
- if ( context.core.query.url && isValidLink( ref ) ) {
94
- await prefetch( ref.href );
95
- }
96
- },
97
- },
84
+ callbacks: {
85
+ *prefetch() {
86
+ const { url } = getContext();
87
+ const { ref } = getElement();
88
+ if ( url && isValidLink( ref ) ) {
89
+ yield prefetch( ref.href );
90
+ }
98
91
  },
99
92
  },
100
93
  } );
@@ -72,9 +72,9 @@ function render_block_core_query_pagination_next( $attributes, $content, $block
72
72
  )
73
73
  ) ) {
74
74
  $p->set_attribute( 'data-wp-key', 'query-pagination-next' );
75
- $p->set_attribute( 'data-wp-on--click', 'actions.core.query.navigate' );
76
- $p->set_attribute( 'data-wp-on--mouseenter', 'actions.core.query.prefetch' );
77
- $p->set_attribute( 'data-wp-effect', 'effects.core.query.prefetch' );
75
+ $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
76
+ $p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' );
77
+ $p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' );
78
78
  $content = $p->get_updated_html();
79
79
  }
80
80
  }
@@ -98,7 +98,7 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo
98
98
  'class_name' => 'page-numbers',
99
99
  )
100
100
  ) ) {
101
- $p->set_attribute( 'data-wp-on--click', 'actions.core.query.navigate' );
101
+ $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
102
102
  }
103
103
  $content = $p->get_updated_html();
104
104
  }
@@ -60,9 +60,9 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
60
60
  )
61
61
  ) ) {
62
62
  $p->set_attribute( 'data-wp-key', 'query-pagination-previous' );
63
- $p->set_attribute( 'data-wp-on--click', 'actions.core.query.navigate' );
64
- $p->set_attribute( 'data-wp-on--mouseenter', 'actions.core.query.prefetch' );
65
- $p->set_attribute( 'data-wp-effect', 'effects.core.query.prefetch' );
63
+ $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
64
+ $p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' );
65
+ $p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' );
66
66
  $content = $p->get_updated_html();
67
67
  }
68
68
  }
@@ -80,25 +80,35 @@ function render_block_core_search( $attributes, $content, $block ) {
80
80
 
81
81
  $is_expandable_searchfield = 'button-only' === $button_position && 'expand-searchfield' === $button_behavior;
82
82
  if ( $is_expandable_searchfield ) {
83
- $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.core.search.isSearchInputVisible' );
84
- $input->set_attribute( 'data-wp-bind--tabindex', 'selectors.core.search.tabindex' );
83
+ $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' );
84
+ $input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' );
85
85
  // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core.
86
86
  $input->set_attribute( 'aria-hidden', 'true' );
87
87
  $input->set_attribute( 'tabindex', '-1' );
88
88
  }
89
89
 
90
- // If the script already exists, there is no point in removing it from viewScript.
91
- $view_js_file = 'wp-block-search-view';
92
- if ( ! wp_script_is( $view_js_file ) ) {
93
- $script_handles = $block->block_type->view_script_handles;
90
+ $is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
91
+ $script_handles = $block->block_type->view_script_handles;
92
+ $view_js_file = 'wp-block-search-view';
94
93
 
95
- // If the script is not needed, and it is still in the `view_script_handles`, remove it.
96
- if ( ! $is_expandable_searchfield && in_array( $view_js_file, $script_handles, true ) ) {
97
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
94
+ if ( $is_gutenberg_plugin ) {
95
+ if ( $is_expandable_searchfield ) {
96
+ gutenberg_enqueue_module( '@wordpress/block-library/search-block' );
98
97
  }
99
- // If the script is needed, but it was previously removed, add it again.
100
- if ( $is_expandable_searchfield && ! in_array( $view_js_file, $script_handles, true ) ) {
101
- $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
98
+ // Remove the view script because we are using the module.
99
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
100
+ } else {
101
+ // If the script already exists, there is no point in removing it from viewScript.
102
+ if ( ! wp_script_is( $view_js_file ) ) {
103
+
104
+ // If the script is not needed, and it is still in the `view_script_handles`, remove it.
105
+ if ( ! $is_expandable_searchfield && in_array( $view_js_file, $script_handles, true ) ) {
106
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
107
+ }
108
+ // If the script is needed, but it was previously removed, add it again.
109
+ if ( $is_expandable_searchfield && ! in_array( $view_js_file, $script_handles, true ) ) {
110
+ $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
111
+ }
102
112
  }
103
113
  }
104
114
  }
@@ -145,11 +155,11 @@ function render_block_core_search( $attributes, $content, $block ) {
145
155
  if ( $button->next_tag() ) {
146
156
  $button->add_class( implode( ' ', $button_classes ) );
147
157
  if ( 'expand-searchfield' === $attributes['buttonBehavior'] && 'button-only' === $attributes['buttonPosition'] ) {
148
- $button->set_attribute( 'data-wp-bind--aria-label', 'selectors.core.search.ariaLabel' );
149
- $button->set_attribute( 'data-wp-bind--aria-controls', 'selectors.core.search.ariaControls' );
150
- $button->set_attribute( 'data-wp-bind--aria-expanded', 'context.core.search.isSearchInputVisible' );
151
- $button->set_attribute( 'data-wp-bind--type', 'selectors.core.search.type' );
152
- $button->set_attribute( 'data-wp-on--click', 'actions.core.search.openSearchInput' );
158
+ $button->set_attribute( 'data-wp-bind--aria-label', 'state.ariaLabel' );
159
+ $button->set_attribute( 'data-wp-bind--aria-controls', 'state.ariaControls' );
160
+ $button->set_attribute( 'data-wp-bind--aria-expanded', 'context.isSearchInputVisible' );
161
+ $button->set_attribute( 'data-wp-bind--type', 'state.type' );
162
+ $button->set_attribute( 'data-wp-on--click', 'actions.openSearchInput' );
153
163
  // Adding these attributes manually is needed until the Interactivity API SSR logic is added to core.
154
164
  $button->set_attribute( 'aria-label', __( 'Expand search field' ) );
155
165
  $button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id );
@@ -176,11 +186,11 @@ function render_block_core_search( $attributes, $content, $block ) {
176
186
  $aria_label_expanded = __( 'Submit Search' );
177
187
  $aria_label_collapsed = __( 'Expand search field' );
178
188
  $form_directives = '
179
- data-wp-interactive
180
- data-wp-context=\'{ "core": { "search": { "isSearchInputVisible": ' . $open_by_default . ', "inputId": "' . $input_id . '", "ariaLabelExpanded": "' . $aria_label_expanded . '", "ariaLabelCollapsed": "' . $aria_label_collapsed . '" } } }\'
181
- data-wp-class--wp-block-search__searchfield-hidden="!context.core.search.isSearchInputVisible"
182
- data-wp-on--keydown="actions.core.search.handleSearchKeydown"
183
- data-wp-on--focusout="actions.core.search.handleSearchFocusout"
189
+ data-wp-interactive=\'{ "namespace": "core/search" }\'
190
+ data-wp-context=\'{ "isSearchInputVisible": ' . $open_by_default . ', "inputId": "' . $input_id . '", "ariaLabelExpanded": "' . $aria_label_expanded . '", "ariaLabelCollapsed": "' . $aria_label_collapsed . '" }\'
191
+ data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
192
+ data-wp-on--keydown="actions.handleSearchKeydown"
193
+ data-wp-on--focusout="actions.handleSearchFocusout"
184
194
  ';
185
195
  }
186
196
 
@@ -203,27 +213,17 @@ function register_block_core_search() {
203
213
  'render_callback' => 'render_block_core_search',
204
214
  )
205
215
  );
206
- }
207
- add_action( 'init', 'register_block_core_search' );
208
216
 
209
- /**
210
- * Ensure that the view script has the `wp-interactivity` dependency.
211
- *
212
- * @since 6.4.0
213
- *
214
- * @global WP_Scripts $wp_scripts
215
- */
216
- function block_core_search_ensure_interactivity_dependency() {
217
- global $wp_scripts;
218
- if (
219
- isset( $wp_scripts->registered['wp-block-search-view'] ) &&
220
- ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-search-view']->deps, true )
221
- ) {
222
- $wp_scripts->registered['wp-block-search-view']->deps[] = 'wp-interactivity';
217
+ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
218
+ gutenberg_register_module(
219
+ '@wordpress/block-library/search-block',
220
+ gutenberg_url( '/build/interactivity/search.min.js' ),
221
+ array( '@wordpress/interactivity' ),
222
+ defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
223
+ );
223
224
  }
224
225
  }
225
-
226
- add_action( 'wp_print_scripts', 'block_core_search_ensure_interactivity_dependency' );
226
+ add_action( 'init', 'register_block_core_search' );
227
227
 
228
228
  /**
229
229
  * Builds the correct top level classnames for the 'core/search' block.
@@ -1,73 +1,68 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store as wpStore } from '@wordpress/interactivity';
4
+ import { store, getContext, getElement } from '@wordpress/interactivity';
5
5
 
6
- wpStore( {
7
- selectors: {
8
- core: {
9
- search: {
10
- ariaLabel: ( { context } ) => {
11
- const { ariaLabelCollapsed, ariaLabelExpanded } =
12
- context.core.search;
13
- return context.core.search.isSearchInputVisible
14
- ? ariaLabelExpanded
15
- : ariaLabelCollapsed;
16
- },
17
- ariaControls: ( { context } ) => {
18
- return context.core.search.isSearchInputVisible
19
- ? null
20
- : context.core.search.inputId;
21
- },
22
- type: ( { context } ) => {
23
- return context.core.search.isSearchInputVisible
24
- ? 'submit'
25
- : 'button';
26
- },
27
- tabindex: ( { context } ) => {
28
- return context.core.search.isSearchInputVisible
29
- ? '0'
30
- : '-1';
31
- },
32
- },
6
+ const { actions } = store( 'core/search', {
7
+ state: {
8
+ get ariaLabel() {
9
+ const {
10
+ isSearchInputVisible,
11
+ ariaLabelCollapsed,
12
+ ariaLabelExpanded,
13
+ } = getContext();
14
+ return isSearchInputVisible
15
+ ? ariaLabelExpanded
16
+ : ariaLabelCollapsed;
17
+ },
18
+ get ariaControls() {
19
+ const { isSearchInputVisible, inputId } = getContext();
20
+ return isSearchInputVisible ? null : inputId;
21
+ },
22
+ get type() {
23
+ const { isSearchInputVisible } = getContext();
24
+ return isSearchInputVisible ? 'submit' : 'button';
25
+ },
26
+ get tabindex() {
27
+ const { isSearchInputVisible } = getContext();
28
+ return isSearchInputVisible ? '0' : '-1';
33
29
  },
34
30
  },
35
31
  actions: {
36
- core: {
37
- search: {
38
- openSearchInput: ( { context, event, ref } ) => {
39
- if ( ! context.core.search.isSearchInputVisible ) {
40
- event.preventDefault();
41
- context.core.search.isSearchInputVisible = true;
42
- ref.parentElement.querySelector( 'input' ).focus();
43
- }
44
- },
45
- closeSearchInput: ( { context } ) => {
46
- context.core.search.isSearchInputVisible = false;
47
- },
48
- handleSearchKeydown: ( store ) => {
49
- const { actions, event, ref } = store;
50
- // If Escape close the menu.
51
- if ( event?.key === 'Escape' ) {
52
- actions.core.search.closeSearchInput( store );
53
- ref.querySelector( 'button' ).focus();
54
- }
55
- },
56
- handleSearchFocusout: ( store ) => {
57
- const { actions, event, ref } = store;
58
- // If focus is outside search form, and in the document, close menu
59
- // event.target === The element losing focus
60
- // event.relatedTarget === The element receiving focus (if any)
61
- // When focusout is outside the document,
62
- // `window.document.activeElement` doesn't change.
63
- if (
64
- ! ref.contains( event.relatedTarget ) &&
65
- event.target !== window.document.activeElement
66
- ) {
67
- actions.core.search.closeSearchInput( store );
68
- }
69
- },
70
- },
32
+ openSearchInput( event ) {
33
+ const ctx = getContext();
34
+ const { ref } = getElement();
35
+ if ( ! ctx.isSearchInputVisible ) {
36
+ event.preventDefault();
37
+ ctx.isSearchInputVisible = true;
38
+ ref.parentElement.querySelector( 'input' ).focus();
39
+ }
40
+ },
41
+ closeSearchInput() {
42
+ const ctx = getContext();
43
+ ctx.isSearchInputVisible = false;
44
+ },
45
+ handleSearchKeydown( event ) {
46
+ const { ref } = getElement();
47
+ // If Escape close the menu.
48
+ if ( event?.key === 'Escape' ) {
49
+ actions.closeSearchInput();
50
+ ref.querySelector( 'button' ).focus();
51
+ }
52
+ },
53
+ handleSearchFocusout( event ) {
54
+ const { ref } = getElement();
55
+ // If focus is outside search form, and in the document, close menu
56
+ // event.target === The element losing focus
57
+ // event.relatedTarget === The element receiving focus (if any)
58
+ // When focusout is outside the document,
59
+ // `window.document.activeElement` doesn't change.
60
+ if (
61
+ ! ref.contains( event.relatedTarget ) &&
62
+ event.target !== window.document.activeElement
63
+ ) {
64
+ actions.closeSearchInput();
65
+ }
71
66
  },
72
67
  },
73
68
  } );
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Removes anchor tags from a string.
3
+ *
4
+ * @param {string} value The value to remove anchor tags from.
5
+ *
6
+ * @return {string} The value with anchor tags removed.
7
+ */
8
+ export default function removeAnchorTag( value ) {
9
+ return value.replace( /<\/?a[^>]*>/g, '' );
10
+ }
package/tsconfig.json CHANGED
@@ -26,6 +26,7 @@
26
26
  { "path": "../html-entities" },
27
27
  { "path": "../i18n" },
28
28
  { "path": "../icons" },
29
+ { "path": "../interactivity" },
29
30
  { "path": "../notices" },
30
31
  { "path": "../keycodes" },
31
32
  { "path": "../primitives" },