@wordpress/block-library 9.19.0 → 9.19.2

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 (59) 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 +5 -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 +5 -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/build-style/post-comments-form/style-rtl.css +3 -0
  43. package/build-style/post-comments-form/style.css +3 -0
  44. package/build-style/style-rtl.css +3 -0
  45. package/build-style/style.css +3 -0
  46. package/package.json +35 -35
  47. package/src/latest-posts/edit.js +1 -0
  48. package/src/navigation/use-template-part-area-label.js +6 -6
  49. package/src/post-author/edit.js +1 -1
  50. package/src/post-author-name/edit.js +4 -4
  51. package/src/post-comments-form/style.scss +5 -0
  52. package/src/query/edit/inspector-controls/index.js +3 -1
  53. package/src/query/edit/inspector-controls/order-control.js +9 -3
  54. package/src/query/utils.js +58 -0
  55. package/src/query-total/block.json +5 -2
  56. package/src/query-total/index.php +3 -3
  57. package/src/site-title/index.php +1 -1
  58. package/src/template-part/edit/advanced-controls.js +1 -1
  59. package/src/template-part/edit/utils/hooks.js +1 -1
@@ -35,6 +35,7 @@ import {
35
35
  useAllowedControls,
36
36
  isControlAllowed,
37
37
  useTaxonomies,
38
+ useOrderByOptions,
38
39
  } from '../../utils';
39
40
  import { useToolsPanelDropdownMenuProps } from '../../../utils/hooks';
40
41
 
@@ -111,6 +112,7 @@ export default function QueryInspectorControls( props ) {
111
112
  return onChangeDebounced.cancel;
112
113
  }, [ querySearch, onChangeDebounced ] );
113
114
 
115
+ const orderByOptions = useOrderByOptions( postType );
114
116
  const showInheritControl =
115
117
  ! isSingular && isControlAllowed( allowedControls, 'inherit' );
116
118
  const showPostTypeControl =
@@ -329,7 +331,7 @@ export default function QueryInspectorControls( props ) {
329
331
  isShownByDefault
330
332
  >
331
333
  <OrderControl
332
- { ...{ order, orderBy } }
334
+ { ...{ order, orderBy, orderByOptions } }
333
335
  onChange={ setQuery }
334
336
  />
335
337
  </ToolsPanelItem>
@@ -4,7 +4,7 @@
4
4
  import { SelectControl } from '@wordpress/components';
5
5
  import { __ } from '@wordpress/i18n';
6
6
 
7
- const orderOptions = [
7
+ const defaultOrderByOptions = [
8
8
  {
9
9
  label: __( 'Newest to oldest' ),
10
10
  value: 'date/desc',
@@ -24,14 +24,20 @@ const orderOptions = [
24
24
  value: 'title/desc',
25
25
  },
26
26
  ];
27
- function OrderControl( { order, orderBy, onChange } ) {
27
+
28
+ function OrderControl( {
29
+ order,
30
+ orderBy,
31
+ orderByOptions = defaultOrderByOptions,
32
+ onChange,
33
+ } ) {
28
34
  return (
29
35
  <SelectControl
30
36
  __nextHasNoMarginBottom
31
37
  __next40pxDefaultSize
32
38
  label={ __( 'Order by' ) }
33
39
  value={ `${ orderBy }/${ order }` }
34
- options={ orderOptions }
40
+ options={ orderByOptions }
35
41
  onChange={ ( value ) => {
36
42
  const [ newOrderBy, newOrder ] = value.split( '/' );
37
43
  onChange( { order: newOrder, orderBy: newOrderBy } );
@@ -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": {
@@ -52,6 +52,9 @@
52
52
  "width": true,
53
53
  "style": true
54
54
  }
55
+ },
56
+ "interactivity": {
57
+ "clientNavigation": true
55
58
  }
56
59
  },
57
60
  "style": "wp-block-query-total"
@@ -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,10 +31,10 @@ 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
- $start = ( $current_page - 1 ) * $posts_per_page + 1;
37
+ $start = ( 0 === $max_rows ) ? 0 : ( ( $current_page - 1 ) * $posts_per_page + 1 );
38
38
  $end = min( $start + $posts_per_page - 1, $max_rows );
39
39
 
40
40
  // Prepare the display based on the `displayType` attribute.
@@ -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(