@wordpress/block-library 9.19.0 → 9.19.1

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 (54) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/latest-posts/edit.js +2 -1
  3. package/build/latest-posts/edit.js.map +1 -1
  4. package/build/navigation/use-template-part-area-label.js +7 -6
  5. package/build/navigation/use-template-part-area-label.js.map +1 -1
  6. package/build/post-author/edit.js +1 -1
  7. package/build/post-author/edit.js.map +1 -1
  8. package/build/post-author-name/edit.js +2 -2
  9. package/build/post-author-name/edit.js.map +1 -1
  10. package/build/query/edit/inspector-controls/index.js +2 -0
  11. package/build/query/edit/inspector-controls/index.js.map +1 -1
  12. package/build/query/edit/inspector-controls/order-control.js +3 -2
  13. package/build/query/edit/inspector-controls/order-control.js.map +1 -1
  14. package/build/query/utils.js +45 -0
  15. package/build/query/utils.js.map +1 -1
  16. package/build/query-total/index.js +2 -2
  17. package/build/query-total/index.js.map +1 -1
  18. package/build/template-part/edit/advanced-controls.js +1 -1
  19. package/build/template-part/edit/advanced-controls.js.map +1 -1
  20. package/build/template-part/edit/utils/hooks.js +1 -1
  21. package/build/template-part/edit/utils/hooks.js.map +1 -1
  22. package/build-module/latest-posts/edit.js +2 -1
  23. package/build-module/latest-posts/edit.js.map +1 -1
  24. package/build-module/navigation/use-template-part-area-label.js +7 -6
  25. package/build-module/navigation/use-template-part-area-label.js.map +1 -1
  26. package/build-module/post-author/edit.js +1 -1
  27. package/build-module/post-author/edit.js.map +1 -1
  28. package/build-module/post-author-name/edit.js +2 -2
  29. package/build-module/post-author-name/edit.js.map +1 -1
  30. package/build-module/query/edit/inspector-controls/index.js +3 -1
  31. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  32. package/build-module/query/edit/inspector-controls/order-control.js +3 -2
  33. package/build-module/query/edit/inspector-controls/order-control.js.map +1 -1
  34. package/build-module/query/utils.js +44 -0
  35. package/build-module/query/utils.js.map +1 -1
  36. package/build-module/query-total/index.js +2 -2
  37. package/build-module/query-total/index.js.map +1 -1
  38. package/build-module/template-part/edit/advanced-controls.js +1 -1
  39. package/build-module/template-part/edit/advanced-controls.js.map +1 -1
  40. package/build-module/template-part/edit/utils/hooks.js +1 -1
  41. package/build-module/template-part/edit/utils/hooks.js.map +1 -1
  42. package/package.json +35 -35
  43. package/src/latest-posts/edit.js +1 -0
  44. package/src/navigation/use-template-part-area-label.js +6 -6
  45. package/src/post-author/edit.js +1 -1
  46. package/src/post-author-name/edit.js +4 -4
  47. package/src/query/edit/inspector-controls/index.js +3 -1
  48. package/src/query/edit/inspector-controls/order-control.js +9 -3
  49. package/src/query/utils.js +58 -0
  50. package/src/query-total/block.json +2 -2
  51. package/src/query-total/index.php +2 -2
  52. package/src/site-title/index.php +1 -1
  53. package/src/template-part/edit/advanced-controls.js +1 -1
  54. package/src/template-part/edit/utils/hooks.js +1 -1
@@ -6,6 +6,7 @@ import { useMemo } from '@wordpress/element';
6
6
  import { store as coreStore } from '@wordpress/core-data';
7
7
  import { store as blockEditorStore } from '@wordpress/block-editor';
8
8
  import { decodeEntities } from '@wordpress/html-entities';
9
+ import { __ } from '@wordpress/i18n';
9
10
  import {
10
11
  cloneBlock,
11
12
  getBlockSupport,
@@ -13,6 +14,7 @@ import {
13
14
  } from '@wordpress/blocks';
14
15
 
15
16
  /** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */
17
+ /** @typedef {import('@wordpress/components/build-types/query-controls/types').OrderByOption} OrderByOption */
16
18
 
17
19
  /**
18
20
  * @typedef IHasNameAndId
@@ -186,6 +188,62 @@ export function useIsPostTypeHierarchical( postType ) {
186
188
  );
187
189
  }
188
190
 
191
+ /**
192
+ * List of avaiable options to order by.
193
+ *
194
+ * @param {string} postType The post type to check.
195
+ * @return {OrderByOption[]} List of order options.
196
+ */
197
+ export function useOrderByOptions( postType ) {
198
+ const supportsCustomOrder = useSelect(
199
+ ( select ) => {
200
+ const type = select( coreStore ).getPostType( postType );
201
+ return !! type?.supports?.[ 'page-attributes' ];
202
+ },
203
+ [ postType ]
204
+ );
205
+
206
+ return useMemo( () => {
207
+ const orderByOptions = [
208
+ {
209
+ label: __( 'Newest to oldest' ),
210
+ value: 'date/desc',
211
+ },
212
+ {
213
+ label: __( 'Oldest to newest' ),
214
+ value: 'date/asc',
215
+ },
216
+ {
217
+ /* translators: Label for ordering posts by title in ascending order. */
218
+ label: __( 'A → Z' ),
219
+ value: 'title/asc',
220
+ },
221
+ {
222
+ /* translators: Label for ordering posts by title in descending order. */
223
+ label: __( 'Z → A' ),
224
+ value: 'title/desc',
225
+ },
226
+ ];
227
+
228
+ if ( supportsCustomOrder ) {
229
+ orderByOptions.push(
230
+ {
231
+ /* translators: Label for ordering posts by ascending menu order. */
232
+ label: __( 'Ascending by order' ),
233
+ value: 'menu_order/asc',
234
+ },
235
+ {
236
+ /* translators: Label for ordering posts by descending menu order. */
237
+ label: __( 'Descending by order' ),
238
+ value: 'menu_order/desc',
239
+ }
240
+ );
241
+ }
242
+
243
+ return orderByOptions;
244
+ }, [ supportsCustomOrder ] );
245
+ }
246
+
189
247
  /**
190
248
  * Hook that returns the query properties' names defined by the active
191
249
  * block variation, to determine which block's filters to show.
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "color": {
25
25
  "gradients": true,
26
- "text": true,
27
26
  "__experimentalDefaultControls": {
28
- "background": true
27
+ "background": true,
28
+ "text": true
29
29
  }
30
30
  },
31
31
  "typography": {
@@ -23,7 +23,7 @@ function render_block_core_query_total( $attributes, $content, $block ) {
23
23
  $wrapper_attributes = get_block_wrapper_attributes();
24
24
  if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
25
25
  $query_to_use = $wp_query;
26
- $current_page = max( 1, get_query_var( 'paged', 1 ) );
26
+ $current_page = max( 1, (int) get_query_var( 'paged', 1 ) );
27
27
  } else {
28
28
  $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
29
29
  $current_page = isset( $_GET[ $page_key ] ) ? (int) $_GET[ $page_key ] : 1;
@@ -31,7 +31,7 @@ function render_block_core_query_total( $attributes, $content, $block ) {
31
31
  }
32
32
 
33
33
  $max_rows = $query_to_use->found_posts;
34
- $posts_per_page = $query_to_use->get( 'posts_per_page' );
34
+ $posts_per_page = (int) $query_to_use->get( 'posts_per_page' );
35
35
 
36
36
  // Calculate the range of posts being displayed.
37
37
  $start = ( $current_page - 1 ) * $posts_per_page + 1;
@@ -31,7 +31,7 @@ function render_block_core_site_title( $attributes ) {
31
31
  }
32
32
 
33
33
  if ( $attributes['isLink'] ) {
34
- $aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
34
+ $aria_current = ! is_paged() && ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ? ' aria-current="page"' : '';
35
35
  $link_target = ! empty( $attributes['linkTarget'] ) ? $attributes['linkTarget'] : '_self';
36
36
 
37
37
  $site_title = sprintf(
@@ -36,7 +36,7 @@ export function TemplatePartAdvancedControls( {
36
36
 
37
37
  const defaultTemplatePartAreas = useSelect(
38
38
  ( select ) =>
39
- select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
39
+ select( coreStore ).getCurrentTheme()
40
40
  ?.default_template_part_areas || [],
41
41
  []
42
42
  );
@@ -137,7 +137,7 @@ export function useTemplatePartArea( area ) {
137
137
  return useSelect(
138
138
  ( select ) => {
139
139
  const definedAreas =
140
- select( coreStore ).getEntityRecord( 'root', '__unstableBase' )
140
+ select( coreStore ).getCurrentTheme()
141
141
  ?.default_template_part_areas || [];
142
142
 
143
143
  const selectedArea = definedAreas.find(