@wordpress/block-library 8.22.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 (266) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/block/edit.js +11 -13
  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 +61 -9
  7. package/build/button/edit.js.map +1 -1
  8. package/build/code/transforms.js +20 -7
  9. package/build/code/transforms.js.map +1 -1
  10. package/build/column/edit.js +1 -1
  11. package/build/column/edit.js.map +1 -1
  12. package/build/column/edit.native.js +1 -1
  13. package/build/column/edit.native.js.map +1 -1
  14. package/build/comments/edit/comments-inspector-controls.js +1 -0
  15. package/build/comments/edit/comments-inspector-controls.js.map +1 -1
  16. package/build/cover/edit/index.js +2 -1
  17. package/build/cover/edit/index.js.map +1 -1
  18. package/build/cover/edit/inspector-controls.js +1 -0
  19. package/build/cover/edit/inspector-controls.js.map +1 -1
  20. package/build/details/edit.js +1 -2
  21. package/build/details/edit.js.map +1 -1
  22. package/build/file/edit.js +8 -9
  23. package/build/file/edit.js.map +1 -1
  24. package/build/file/view.js +4 -6
  25. package/build/file/view.js.map +1 -1
  26. package/build/form/index.js +1 -1
  27. package/build/form/index.js.map +1 -1
  28. package/build/form-submit-button/edit.js +2 -1
  29. package/build/form-submit-button/edit.js.map +1 -1
  30. package/build/gallery/gap-styles.js +12 -7
  31. package/build/gallery/gap-styles.js.map +1 -1
  32. package/build/group/edit.js +4 -7
  33. package/build/group/edit.js.map +1 -1
  34. package/build/html/transforms.js +7 -2
  35. package/build/html/transforms.js.map +1 -1
  36. package/build/image/deprecated.js +8 -0
  37. package/build/image/deprecated.js.map +1 -1
  38. package/build/image/edit.js +17 -18
  39. package/build/image/edit.js.map +1 -1
  40. package/build/image/edit.native.js +22 -15
  41. package/build/image/edit.native.js.map +1 -1
  42. package/build/image/image.js +35 -27
  43. package/build/image/image.js.map +1 -1
  44. package/build/image/index.js +2 -3
  45. package/build/image/index.js.map +1 -1
  46. package/build/image/view.js +234 -266
  47. package/build/image/view.js.map +1 -1
  48. package/build/missing/index.js +1 -1
  49. package/build/navigation/edit/overlay-menu-preview.js +1 -1
  50. package/build/navigation/edit/overlay-menu-preview.js.map +1 -1
  51. package/build/navigation/use-template-part-area-label.js +2 -1
  52. package/build/navigation/use-template-part-area-label.js.map +1 -1
  53. package/build/navigation/view.js +153 -176
  54. package/build/navigation/view.js.map +1 -1
  55. package/build/navigation-link/edit.js +1 -1
  56. package/build/navigation-link/edit.js.map +1 -1
  57. package/build/navigation-link/index.js +2 -1
  58. package/build/navigation-link/index.js.map +1 -1
  59. package/build/pattern/edit.js +2 -4
  60. package/build/pattern/edit.js.map +1 -1
  61. package/build/post-author/edit.js +0 -1
  62. package/build/post-author/edit.js.map +1 -1
  63. package/build/post-featured-image/edit.js +21 -6
  64. package/build/post-featured-image/edit.js.map +1 -1
  65. package/build/post-template/edit.js +2 -8
  66. package/build/post-template/edit.js.map +1 -1
  67. package/build/post-template/index.js +1 -1
  68. package/build/post-terms/edit.js +0 -2
  69. package/build/post-terms/edit.js.map +1 -1
  70. package/build/preformatted/transforms.js +1 -4
  71. package/build/preformatted/transforms.js.map +1 -1
  72. package/build/query/edit/query-content.js +1 -0
  73. package/build/query/edit/query-content.js.map +1 -1
  74. package/build/query/view.js +52 -60
  75. package/build/query/view.js.map +1 -1
  76. package/build/quote/index.js +6 -0
  77. package/build/quote/index.js.map +1 -1
  78. package/build/search/view.js +66 -74
  79. package/build/search/view.js.map +1 -1
  80. package/build/template-part/edit/advanced-controls.js +1 -0
  81. package/build/template-part/edit/advanced-controls.js.map +1 -1
  82. package/build/template-part/edit/index.js +3 -7
  83. package/build/template-part/edit/index.js.map +1 -1
  84. package/build/template-part/index.js +6 -2
  85. package/build/template-part/index.js.map +1 -1
  86. package/build/template-part/variations.js +5 -1
  87. package/build/template-part/variations.js.map +1 -1
  88. package/build/utils/remove-anchor-tag.js +17 -0
  89. package/build/utils/remove-anchor-tag.js.map +1 -0
  90. package/build-module/block/edit.js +11 -13
  91. package/build-module/block/edit.js.map +1 -1
  92. package/build-module/block/edit.native.js +3 -4
  93. package/build-module/block/edit.native.js.map +1 -1
  94. package/build-module/button/edit.js +65 -13
  95. package/build-module/button/edit.js.map +1 -1
  96. package/build-module/code/transforms.js +20 -7
  97. package/build-module/code/transforms.js.map +1 -1
  98. package/build-module/column/edit.js +1 -1
  99. package/build-module/column/edit.js.map +1 -1
  100. package/build-module/column/edit.native.js +1 -1
  101. package/build-module/column/edit.native.js.map +1 -1
  102. package/build-module/comments/edit/comments-inspector-controls.js +1 -0
  103. package/build-module/comments/edit/comments-inspector-controls.js.map +1 -1
  104. package/build-module/cover/edit/index.js +2 -1
  105. package/build-module/cover/edit/index.js.map +1 -1
  106. package/build-module/cover/edit/inspector-controls.js +1 -0
  107. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  108. package/build-module/details/edit.js +1 -2
  109. package/build-module/details/edit.js.map +1 -1
  110. package/build-module/file/edit.js +8 -9
  111. package/build-module/file/edit.js.map +1 -1
  112. package/build-module/file/view.js +5 -7
  113. package/build-module/file/view.js.map +1 -1
  114. package/build-module/form/index.js +1 -1
  115. package/build-module/form/index.js.map +1 -1
  116. package/build-module/form-submit-button/edit.js +2 -1
  117. package/build-module/form-submit-button/edit.js.map +1 -1
  118. package/build-module/gallery/gap-styles.js +13 -8
  119. package/build-module/gallery/gap-styles.js.map +1 -1
  120. package/build-module/group/edit.js +4 -7
  121. package/build-module/group/edit.js.map +1 -1
  122. package/build-module/html/transforms.js +7 -2
  123. package/build-module/html/transforms.js.map +1 -1
  124. package/build-module/image/deprecated.js +8 -0
  125. package/build-module/image/deprecated.js.map +1 -1
  126. package/build-module/image/edit.js +18 -19
  127. package/build-module/image/edit.js.map +1 -1
  128. package/build-module/image/edit.native.js +23 -16
  129. package/build-module/image/edit.native.js.map +1 -1
  130. package/build-module/image/image.js +36 -28
  131. package/build-module/image/image.js.map +1 -1
  132. package/build-module/image/index.js +2 -3
  133. package/build-module/image/index.js.map +1 -1
  134. package/build-module/image/view.js +235 -267
  135. package/build-module/image/view.js.map +1 -1
  136. package/build-module/missing/index.js +1 -1
  137. package/build-module/navigation/edit/overlay-menu-preview.js +1 -1
  138. package/build-module/navigation/edit/overlay-menu-preview.js.map +1 -1
  139. package/build-module/navigation/use-template-part-area-label.js +2 -1
  140. package/build-module/navigation/use-template-part-area-label.js.map +1 -1
  141. package/build-module/navigation/view.js +154 -177
  142. package/build-module/navigation/view.js.map +1 -1
  143. package/build-module/navigation-link/edit.js +2 -2
  144. package/build-module/navigation-link/edit.js.map +1 -1
  145. package/build-module/navigation-link/index.js +2 -1
  146. package/build-module/navigation-link/index.js.map +1 -1
  147. package/build-module/pattern/edit.js +2 -4
  148. package/build-module/pattern/edit.js.map +1 -1
  149. package/build-module/post-author/edit.js +0 -1
  150. package/build-module/post-author/edit.js.map +1 -1
  151. package/build-module/post-featured-image/edit.js +21 -6
  152. package/build-module/post-featured-image/edit.js.map +1 -1
  153. package/build-module/post-template/edit.js +2 -8
  154. package/build-module/post-template/edit.js.map +1 -1
  155. package/build-module/post-template/index.js +1 -1
  156. package/build-module/post-terms/edit.js +0 -2
  157. package/build-module/post-terms/edit.js.map +1 -1
  158. package/build-module/preformatted/transforms.js +1 -4
  159. package/build-module/preformatted/transforms.js.map +1 -1
  160. package/build-module/query/edit/query-content.js +1 -0
  161. package/build-module/query/edit/query-content.js.map +1 -1
  162. package/build-module/query/view.js +53 -61
  163. package/build-module/query/view.js.map +1 -1
  164. package/build-module/quote/index.js +6 -0
  165. package/build-module/quote/index.js.map +1 -1
  166. package/build-module/search/view.js +67 -75
  167. package/build-module/search/view.js.map +1 -1
  168. package/build-module/template-part/edit/advanced-controls.js +1 -0
  169. package/build-module/template-part/edit/advanced-controls.js.map +1 -1
  170. package/build-module/template-part/edit/index.js +5 -9
  171. package/build-module/template-part/edit/index.js.map +1 -1
  172. package/build-module/template-part/index.js +6 -2
  173. package/build-module/template-part/index.js.map +1 -1
  174. package/build-module/template-part/variations.js +5 -1
  175. package/build-module/template-part/variations.js.map +1 -1
  176. package/build-module/utils/remove-anchor-tag.js +11 -0
  177. package/build-module/utils/remove-anchor-tag.js.map +1 -0
  178. package/build-style/cover/style-rtl.css +14 -14
  179. package/build-style/cover/style.css +14 -14
  180. package/build-style/editor-rtl.css +15 -6
  181. package/build-style/editor.css +15 -6
  182. package/build-style/gallery/style-rtl.css +28 -0
  183. package/build-style/gallery/style.css +28 -0
  184. package/build-style/image/style-rtl.css +19 -13
  185. package/build-style/image/style.css +19 -13
  186. package/build-style/post-featured-image/editor-rtl.css +9 -0
  187. package/build-style/post-featured-image/editor.css +9 -0
  188. package/build-style/quote/style-rtl.css +3 -0
  189. package/build-style/quote/style.css +3 -0
  190. package/build-style/read-more/style-rtl.css +2 -2
  191. package/build-style/read-more/style.css +2 -2
  192. package/build-style/style-rtl.css +66 -29
  193. package/build-style/style.css +66 -29
  194. package/package.json +32 -32
  195. package/src/block/edit.js +20 -20
  196. package/src/block/edit.native.js +5 -13
  197. package/src/button/edit.js +76 -10
  198. package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
  199. package/src/buttons/test/edit.native.js +0 -27
  200. package/src/code/transforms.js +14 -8
  201. package/src/column/edit.js +1 -1
  202. package/src/column/edit.native.js +1 -1
  203. package/src/comments/edit/comments-inspector-controls.js +1 -0
  204. package/src/cover/edit/index.js +1 -0
  205. package/src/cover/edit/inspector-controls.js +1 -0
  206. package/src/cover/style.scss +1 -1
  207. package/src/cover/test/edit.js +1 -1
  208. package/src/details/edit.js +0 -1
  209. package/src/editor.scss +6 -6
  210. package/src/file/edit.js +11 -10
  211. package/src/file/index.php +30 -11
  212. package/src/file/view.js +5 -7
  213. package/src/form/index.js +1 -1
  214. package/src/form-submit-button/edit.js +1 -0
  215. package/src/gallery/gap-styles.js +10 -9
  216. package/src/gallery/style.scss +1 -0
  217. package/src/group/edit.js +4 -11
  218. package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
  219. package/src/heading/test/index.native.js +40 -0
  220. package/src/html/transforms.js +5 -2
  221. package/src/image/block.json +2 -3
  222. package/src/image/deprecated.js +8 -0
  223. package/src/image/edit.js +16 -21
  224. package/src/image/edit.native.js +17 -18
  225. package/src/image/image.js +48 -51
  226. package/src/image/index.php +57 -49
  227. package/src/image/style.scss +18 -13
  228. package/src/image/view.js +281 -324
  229. package/src/missing/block.json +1 -1
  230. package/src/navigation/edit/overlay-menu-preview.js +1 -1
  231. package/src/navigation/index.php +46 -402
  232. package/src/navigation/use-template-part-area-label.js +4 -2
  233. package/src/navigation/view.js +159 -192
  234. package/src/navigation-link/block.json +2 -1
  235. package/src/navigation-link/edit.js +2 -2
  236. package/src/navigation-link/index.php +57 -0
  237. package/src/paragraph/test/__snapshots__/transforms.native.js.snap +6 -0
  238. package/src/paragraph/test/edit.native.js +37 -1
  239. package/src/paragraph/test/transforms.native.js +1 -0
  240. package/src/pattern/edit.js +7 -4
  241. package/src/pattern/index.php +6 -1
  242. package/src/post-author/edit.js +0 -1
  243. package/src/post-featured-image/edit.js +38 -5
  244. package/src/post-featured-image/editor.scss +19 -0
  245. package/src/post-template/block.json +0 -1
  246. package/src/post-template/edit.js +1 -5
  247. package/src/post-terms/edit.js +0 -2
  248. package/src/preformatted/transforms.js +1 -4
  249. package/src/query/edit/query-content.js +1 -0
  250. package/src/query/index.php +42 -24
  251. package/src/query/view.js +58 -65
  252. package/src/query-pagination-next/index.php +3 -3
  253. package/src/query-pagination-numbers/index.php +1 -1
  254. package/src/query-pagination-previous/index.php +3 -3
  255. package/src/quote/block.json +6 -0
  256. package/src/quote/style.scss +4 -0
  257. package/src/read-more/style.scss +1 -1
  258. package/src/search/index.php +40 -40
  259. package/src/search/view.js +58 -63
  260. package/src/template-part/edit/advanced-controls.js +1 -0
  261. package/src/template-part/edit/index.js +7 -14
  262. package/src/template-part/index.js +4 -3
  263. package/src/template-part/index.php +4 -4
  264. package/src/template-part/variations.js +4 -2
  265. package/src/utils/remove-anchor-tag.js +10 -0
  266. package/tsconfig.json +1 -0
@@ -96,6 +96,25 @@
96
96
  height: 100%;
97
97
  width: 100%;
98
98
  }
99
+
100
+ // When the Post Featured Image block is linked,
101
+ // it's wrapped with a disabled <a /> tag.
102
+ // Restore cursor style so it doesn't appear 'clickable'.
103
+ > a {
104
+ cursor: default;
105
+ }
106
+
107
+ // When the Post Featured Image block is linked,
108
+ // and wrapped with a disabled <a /> tag
109
+ // ensure that the placeholder items are visible when selected.
110
+ &.is-selected .components-placeholder.has-illustration {
111
+ .components-button,
112
+ .components-placeholder__instructions,
113
+ .components-placeholder__label {
114
+ opacity: 1;
115
+ pointer-events: auto;
116
+ }
117
+ }
99
118
  }
100
119
 
101
120
  div[data-type="core/post-featured-image"] {
@@ -10,7 +10,6 @@
10
10
  "usesContext": [
11
11
  "queryId",
12
12
  "query",
13
- "queryContext",
14
13
  "displayLayout",
15
14
  "templateSlug",
16
15
  "previewPostType",
@@ -96,7 +96,6 @@ export default function PostTemplateEdit( {
96
96
  // REST API or be handled by custom REST filters like `rest_{$this->post_type}_query`.
97
97
  ...restQueryArgs
98
98
  } = {},
99
- queryContext = [ { page: 1 } ],
100
99
  templateSlug,
101
100
  previewPostType,
102
101
  },
@@ -104,8 +103,6 @@ export default function PostTemplateEdit( {
104
103
  __unstableLayoutClassNames,
105
104
  } ) {
106
105
  const { type: layoutType, columnCount = 3 } = layout || {};
107
-
108
- const [ { page } ] = queryContext;
109
106
  const [ activeBlockContextId, setActiveBlockContextId ] = useState();
110
107
  const { posts, blocks } = useSelect(
111
108
  ( select ) => {
@@ -126,7 +123,7 @@ export default function PostTemplateEdit( {
126
123
  slug: templateSlug.replace( 'category-', '' ),
127
124
  } );
128
125
  const query = {
129
- offset: perPage ? perPage * ( page - 1 ) + offset : 0,
126
+ offset: offset || 0,
130
127
  order,
131
128
  orderby: orderBy,
132
129
  };
@@ -194,7 +191,6 @@ export default function PostTemplateEdit( {
194
191
  },
195
192
  [
196
193
  perPage,
197
- page,
198
194
  offset,
199
195
  order,
200
196
  orderBy,
@@ -97,7 +97,6 @@ export default function PostTermsEdit( {
97
97
  <RichText
98
98
  allowedFormats={ ALLOWED_FORMATS }
99
99
  className="wp-block-post-terms__prefix"
100
- multiline={ false }
101
100
  aria-label={ __( 'Prefix' ) }
102
101
  placeholder={ __( 'Prefix' ) + ' ' }
103
102
  value={ prefix }
@@ -141,7 +140,6 @@ export default function PostTermsEdit( {
141
140
  <RichText
142
141
  allowedFormats={ ALLOWED_FORMATS }
143
142
  className="wp-block-post-terms__suffix"
144
- multiline={ false }
145
143
  aria-label={ __( 'Suffix' ) }
146
144
  placeholder={ ' ' + __( 'Suffix' ) }
147
145
  value={ suffix }
@@ -34,10 +34,7 @@ const transforms = {
34
34
  type: 'block',
35
35
  blocks: [ 'core/paragraph' ],
36
36
  transform: ( attributes ) =>
37
- createBlock( 'core/paragraph', {
38
- ...attributes,
39
- content: attributes.content.replace( /\n/g, '<br>' ),
40
- } ),
37
+ createBlock( 'core/paragraph', attributes ),
41
38
  },
42
39
  {
43
40
  type: 'block',
@@ -131,6 +131,7 @@ export default function QueryContent( {
131
131
  <InspectorControls group="advanced">
132
132
  <SelectControl
133
133
  __nextHasNoMarginBottom
134
+ __next40pxDefaultSize
134
135
  label={ __( 'HTML element' ) }
135
136
  options={ [
136
137
  { label: __( 'Default (<div>)' ), value: 'div' },
@@ -21,19 +21,15 @@ function render_block_core_query( $attributes, $content, $block ) {
21
21
  $p = new WP_HTML_Tag_Processor( $content );
22
22
  if ( $p->next_tag() ) {
23
23
  // Add the necessary directives.
24
- $p->set_attribute( 'data-wp-interactive', true );
24
+ $p->set_attribute( 'data-wp-interactive', '{"namespace":"core/query"}' );
25
25
  $p->set_attribute( 'data-wp-navigation-id', 'query-' . $attributes['queryId'] );
26
26
  // Use context to send translated strings.
27
27
  $p->set_attribute(
28
28
  'data-wp-context',
29
29
  wp_json_encode(
30
30
  array(
31
- 'core' => array(
32
- 'query' => array(
33
- 'loadingText' => __( 'Loading page, please wait.' ),
34
- 'loadedText' => __( 'Page Loaded.' ),
35
- ),
36
- ),
31
+ 'loadingText' => __( 'Loading page, please wait.' ),
32
+ 'loadedText' => __( 'Page Loaded.' ),
37
33
  ),
38
34
  JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
39
35
  )
@@ -44,38 +40,51 @@ function render_block_core_query( $attributes, $content, $block ) {
44
40
  $block->block_type->supports['interactivity'] = true;
45
41
 
46
42
  // Add a div to announce messages using `aria-live`.
47
- $last_div_position = strripos( $content, '</div>' );
43
+ $html_tag = 'div';
44
+ if ( ! empty( $attributes['tagName'] ) ) {
45
+ $html_tag = esc_attr( $attributes['tagName'] );
46
+ }
47
+ $last_tag_position = strripos( $content, '</' . $html_tag . '>' );
48
48
  $content = substr_replace(
49
49
  $content,
50
50
  '<div
51
51
  class="screen-reader-text"
52
52
  aria-live="polite"
53
- data-wp-text="context.core.query.message"
53
+ data-wp-text="context.message"
54
54
  ></div>
55
55
  <div
56
56
  class="wp-block-query__enhanced-pagination-animation"
57
- data-wp-class--start-animation="selectors.core.query.startAnimation"
58
- data-wp-class--finish-animation="selectors.core.query.finishAnimation"
57
+ data-wp-class--start-animation="state.startAnimation"
58
+ data-wp-class--finish-animation="state.finishAnimation"
59
59
  ></div>',
60
- $last_div_position,
60
+ $last_tag_position,
61
61
  0
62
62
  );
63
63
  }
64
64
  }
65
65
 
66
- $view_asset = 'wp-block-query-view';
67
- if ( ! wp_script_is( $view_asset ) ) {
68
- $script_handles = $block->block_type->view_script_handles;
69
- // If the script is not needed, and it is still in the `view_script_handles`, remove it.
70
- if (
71
- ( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
72
- && in_array( $view_asset, $script_handles, true )
73
- ) {
74
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
66
+ $is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
67
+ $should_load_view_script = $attributes['enhancedPagination'] && isset( $attributes['queryId'] );
68
+ $view_asset = 'wp-block-query-view';
69
+ $script_handles = $block->block_type->view_script_handles;
70
+
71
+ if ( $is_gutenberg_plugin ) {
72
+ if ( $should_load_view_script ) {
73
+ gutenberg_enqueue_module( '@wordpress/block-library/query' );
75
74
  }
76
- // If the script is needed, but it was previously removed, add it again.
77
- if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $view_asset, $script_handles, true ) ) {
78
- $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
75
+ // Remove the view script because we are using the module.
76
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
77
+ } else {
78
+ if ( ! wp_script_is( $view_asset ) ) {
79
+ // If the script is not needed, and it is still in the `view_script_handles`, remove it.
80
+ if ( ! $should_load_view_script && in_array( $view_asset, $script_handles, true )
81
+ ) {
82
+ $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
83
+ }
84
+ // If the script is needed, but it was previously removed, add it again.
85
+ if ( $should_load_view_script && ! in_array( $view_asset, $script_handles, true ) ) {
86
+ $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
87
+ }
79
88
  }
80
89
  }
81
90
 
@@ -127,6 +136,15 @@ function register_block_core_query() {
127
136
  'render_callback' => 'render_block_core_query',
128
137
  )
129
138
  );
139
+
140
+ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
141
+ gutenberg_register_module(
142
+ '@wordpress/block-library/query',
143
+ '/wp-content/plugins/gutenberg/build/interactivity/query.min.js',
144
+ array( '@wordpress/interactivity' ),
145
+ defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
146
+ );
147
+ }
130
148
  }
131
149
  add_action( 'init', 'register_block_core_query' );
132
150
 
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
  }
@@ -54,6 +54,12 @@
54
54
  "background": true,
55
55
  "text": true
56
56
  }
57
+ },
58
+ "layout": {
59
+ "allowEditing": false
60
+ },
61
+ "spacing": {
62
+ "blockGap": true
57
63
  }
58
64
  },
59
65
  "styles": [
@@ -18,5 +18,9 @@
18
18
  font-size: 1.125em;
19
19
  text-align: right;
20
20
  }
21
+
22
+ }
23
+ > cite {
24
+ display: block;
21
25
  }
22
26
  }
@@ -1,7 +1,7 @@
1
1
  .wp-block-read-more {
2
2
  display: block;
3
3
  width: fit-content;
4
- &:not([style*="text-decoration"]) {
4
+ &:where(:not([style*="text-decoration"])) {
5
5
  text-decoration: none;
6
6
 
7
7
  &:focus,
@@ -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.