@wordpress/block-library 9.20.0 → 9.21.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 (80) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/categories/edit.js +3 -3
  3. package/build/categories/edit.js.map +1 -1
  4. package/build/embed/edit.js +4 -1
  5. package/build/embed/edit.js.map +1 -1
  6. package/build/image/edit.js +3 -2
  7. package/build/image/edit.js.map +1 -1
  8. package/build/image/image.js +13 -8
  9. package/build/image/image.js.map +1 -1
  10. package/build/navigation/edit/index.js +8 -4
  11. package/build/navigation/edit/index.js.map +1 -1
  12. package/build/navigation-link/edit.js +27 -8
  13. package/build/navigation-link/edit.js.map +1 -1
  14. package/build/post-featured-image/edit.js +2 -1
  15. package/build/post-featured-image/edit.js.map +1 -1
  16. package/build/query-total/index.js +3 -0
  17. package/build/query-total/index.js.map +1 -1
  18. package/build/rss/edit.js +21 -1
  19. package/build/rss/edit.js.map +1 -1
  20. package/build/rss/index.js +7 -0
  21. package/build/rss/index.js.map +1 -1
  22. package/build/site-title/edit.js +1 -1
  23. package/build/site-title/edit.js.map +1 -1
  24. package/build/table-of-contents/edit.js +50 -8
  25. package/build/table-of-contents/edit.js.map +1 -1
  26. package/build/table-of-contents/hooks.js +7 -1
  27. package/build/table-of-contents/hooks.js.map +1 -1
  28. package/build/table-of-contents/index.js +3 -0
  29. package/build/table-of-contents/index.js.map +1 -1
  30. package/build-module/categories/edit.js +3 -3
  31. package/build-module/categories/edit.js.map +1 -1
  32. package/build-module/embed/edit.js +4 -1
  33. package/build-module/embed/edit.js.map +1 -1
  34. package/build-module/image/edit.js +3 -2
  35. package/build-module/image/edit.js.map +1 -1
  36. package/build-module/image/image.js +14 -9
  37. package/build-module/image/image.js.map +1 -1
  38. package/build-module/navigation/edit/index.js +8 -4
  39. package/build-module/navigation/edit/index.js.map +1 -1
  40. package/build-module/navigation-link/edit.js +28 -9
  41. package/build-module/navigation-link/edit.js.map +1 -1
  42. package/build-module/post-featured-image/edit.js +2 -1
  43. package/build-module/post-featured-image/edit.js.map +1 -1
  44. package/build-module/query-total/index.js +3 -0
  45. package/build-module/query-total/index.js.map +1 -1
  46. package/build-module/rss/edit.js +22 -2
  47. package/build-module/rss/edit.js.map +1 -1
  48. package/build-module/rss/index.js +7 -0
  49. package/build-module/rss/index.js.map +1 -1
  50. package/build-module/site-title/edit.js +1 -1
  51. package/build-module/site-title/edit.js.map +1 -1
  52. package/build-module/table-of-contents/edit.js +52 -10
  53. package/build-module/table-of-contents/edit.js.map +1 -1
  54. package/build-module/table-of-contents/hooks.js +7 -1
  55. package/build-module/table-of-contents/hooks.js.map +1 -1
  56. package/build-module/table-of-contents/index.js +3 -0
  57. package/build-module/table-of-contents/index.js.map +1 -1
  58. package/build-style/post-comments-form/style-rtl.css +3 -0
  59. package/build-style/post-comments-form/style.css +3 -0
  60. package/build-style/style-rtl.css +3 -0
  61. package/build-style/style.css +3 -0
  62. package/package.json +35 -35
  63. package/src/categories/edit.js +3 -3
  64. package/src/embed/edit.js +7 -1
  65. package/src/image/edit.js +3 -3
  66. package/src/image/image.js +9 -12
  67. package/src/navigation/edit/index.js +4 -0
  68. package/src/navigation-link/edit.js +45 -11
  69. package/src/post-comments-form/style.scss +5 -0
  70. package/src/post-featured-image/edit.js +2 -1
  71. package/src/query-total/block.json +3 -0
  72. package/src/query-total/index.php +1 -1
  73. package/src/rss/block.json +7 -0
  74. package/src/rss/edit.js +21 -0
  75. package/src/rss/index.php +27 -9
  76. package/src/site-title/edit.js +1 -1
  77. package/src/site-title/index.php +1 -1
  78. package/src/table-of-contents/block.json +3 -0
  79. package/src/table-of-contents/edit.js +45 -4
  80. package/src/table-of-contents/hooks.js +7 -1
package/src/rss/index.php CHANGED
@@ -31,6 +31,20 @@ function render_block_core_rss( $attributes ) {
31
31
 
32
32
  $rss_items = $rss->get_items( 0, $attributes['itemsToShow'] );
33
33
  $list_items = '';
34
+
35
+ $open_in_new_tab = ! empty( $attributes['openInNewTab'] );
36
+ $rel = ! empty( $attributes['rel'] ) ? trim( $attributes['rel'] ) : '';
37
+
38
+ $link_attributes = '';
39
+
40
+ if ( $open_in_new_tab ) {
41
+ $link_attributes .= ' target="_blank"';
42
+ }
43
+
44
+ if ( '' !== $rel ) {
45
+ $link_attributes .= ' rel="' . esc_attr( $rel ) . '"';
46
+ }
47
+
34
48
  foreach ( $rss_items as $item ) {
35
49
  $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
36
50
  if ( empty( $title ) ) {
@@ -38,20 +52,24 @@ function render_block_core_rss( $attributes ) {
38
52
  }
39
53
  $link = $item->get_link();
40
54
  $link = esc_url( $link );
55
+
41
56
  if ( $link ) {
42
- $title = "<a href='{$link}'>{$title}</a>";
57
+ $title = "<a href='{$link}'{$link_attributes}>{$title}</a>";
43
58
  }
44
59
  $title = "<div class='wp-block-rss__item-title'>{$title}</div>";
45
60
 
46
- $date = '';
47
- if ( $attributes['displayDate'] ) {
48
- $date = $item->get_date( 'U' );
61
+ $date_markup = '';
62
+ if ( ! empty( $attributes['displayDate'] ) ) {
63
+ $timestamp = $item->get_date( 'U' );
64
+
65
+ if ( $timestamp ) {
66
+ $gmt_offset = get_option( 'gmt_offset' );
67
+ $timestamp += (int) ( (float) $gmt_offset * HOUR_IN_SECONDS );
49
68
 
50
- if ( $date ) {
51
- $date = sprintf(
69
+ $date_markup = sprintf(
52
70
  '<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ',
53
- esc_attr( date_i18n( 'c', $date ) ),
54
- esc_attr( date_i18n( get_option( 'date_format' ), $date ) )
71
+ esc_attr( date_i18n( 'c', $timestamp ) ),
72
+ esc_html( date_i18n( get_option( 'date_format' ), $timestamp ) )
55
73
  );
56
74
  }
57
75
  }
@@ -85,7 +103,7 @@ function render_block_core_rss( $attributes ) {
85
103
  $excerpt = '<div class="wp-block-rss__item-excerpt">' . esc_html( $excerpt ) . '</div>';
86
104
  }
87
105
 
88
- $list_items .= "<li class='wp-block-rss__item'>{$title}{$date}{$author}{$excerpt}</li>";
106
+ $list_items .= "<li class='wp-block-rss__item'>{$title}{$date_markup}{$author}{$excerpt}</li>";
89
107
  }
90
108
 
91
109
  $classnames = array();
@@ -56,7 +56,7 @@ export default function SiteTitleEdit( {
56
56
 
57
57
  function setTitle( newTitle ) {
58
58
  editEntityRecord( 'root', 'site', undefined, {
59
- title: newTitle,
59
+ title: newTitle.trim(),
60
60
  } );
61
61
  }
62
62
 
@@ -16,7 +16,7 @@
16
16
  */
17
17
  function render_block_core_site_title( $attributes ) {
18
18
  $site_title = get_bloginfo( 'name' );
19
- if ( ! $site_title ) {
19
+ if ( ! trim( $site_title ) ) {
20
20
  return;
21
21
  }
22
22
 
@@ -19,6 +19,9 @@
19
19
  "onlyIncludeCurrentPage": {
20
20
  "type": "boolean",
21
21
  "default": false
22
+ },
23
+ "maxLevel": {
24
+ "type": "number"
22
25
  }
23
26
  },
24
27
  "supports": {
@@ -12,6 +12,7 @@ import { createBlock } from '@wordpress/blocks';
12
12
  import {
13
13
  Placeholder,
14
14
  ToggleControl,
15
+ SelectControl,
15
16
  ToolbarButton,
16
17
  ToolbarGroup,
17
18
  __experimentalToolsPanel as ToolsPanel,
@@ -39,15 +40,16 @@ import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
39
40
  *
40
41
  * @param {Object} props The props.
41
42
  * @param {Object} props.attributes The block attributes.
42
- * @param {HeadingData[]} props.attributes.headings A list of data for each heading in the post.
43
+ * @param {HeadingData[]} props.attributes.headings The list of data for each heading in the post.
43
44
  * @param {boolean} props.attributes.onlyIncludeCurrentPage Whether to only include headings from the current page (if the post is paginated).
44
- * @param {string} props.clientId
45
- * @param {(attributes: Object) => void} props.setAttributes
45
+ * @param {number|undefined} props.attributes.maxLevel The maximum heading level to include, or null to include all levels.
46
+ * @param {string} props.clientId The client id.
47
+ * @param {(attributes: Object) => void} props.setAttributes The set attributes function.
46
48
  *
47
49
  * @return {Component} The component.
48
50
  */
49
51
  export default function TableOfContentsEdit( {
50
- attributes: { headings = [], onlyIncludeCurrentPage },
52
+ attributes: { headings = [], onlyIncludeCurrentPage, maxLevel },
51
53
  clientId,
52
54
  setAttributes,
53
55
  } ) {
@@ -115,6 +117,7 @@ export default function TableOfContentsEdit( {
115
117
  resetAll={ () => {
116
118
  setAttributes( {
117
119
  onlyIncludeCurrentPage: false,
120
+ maxLevel: undefined,
118
121
  } );
119
122
  } }
120
123
  dropdownMenuProps={ dropdownMenuProps }
@@ -145,6 +148,44 @@ export default function TableOfContentsEdit( {
145
148
  }
146
149
  />
147
150
  </ToolsPanelItem>
151
+ <ToolsPanelItem
152
+ hasValue={ () => !! maxLevel }
153
+ label={ __( 'Limit heading levels' ) }
154
+ onDeselect={ () =>
155
+ setAttributes( { maxLevel: undefined } )
156
+ }
157
+ isShownByDefault
158
+ >
159
+ <SelectControl
160
+ __nextHasNoMarginBottom
161
+ __next40pxDefaultSize
162
+ label={ __( 'Include headings down to level' ) }
163
+ value={ maxLevel || '' }
164
+ options={ [
165
+ { value: '', label: __( 'All levels' ) },
166
+ { value: '1', label: __( 'Heading 1' ) },
167
+ { value: '2', label: __( 'Heading 2' ) },
168
+ { value: '3', label: __( 'Heading 3' ) },
169
+ { value: '4', label: __( 'Heading 4' ) },
170
+ { value: '5', label: __( 'Heading 5' ) },
171
+ { value: '6', label: __( 'Heading 6' ) },
172
+ ] }
173
+ onChange={ ( value ) =>
174
+ setAttributes( {
175
+ maxLevel: value ? parseInt( value ) : undefined,
176
+ } )
177
+ }
178
+ help={
179
+ maxLevel
180
+ ? __(
181
+ 'Including all heading levels in the table of contents.'
182
+ )
183
+ : __(
184
+ 'Only include headings up to and including this level.'
185
+ )
186
+ }
187
+ />
188
+ </ToolsPanelItem>
148
189
  </ToolsPanel>
149
190
  </InspectorControls>
150
191
  );
@@ -29,7 +29,8 @@ function getLatestHeadings( select, clientId ) {
29
29
  const permalink = select( 'core/editor' ).getPermalink() ?? null;
30
30
 
31
31
  const isPaginated = getBlocksByName( 'core/nextpage' ).length !== 0;
32
- const { onlyIncludeCurrentPage } = getBlockAttributes( clientId ) ?? {};
32
+ const { onlyIncludeCurrentPage, maxLevel } =
33
+ getBlockAttributes( clientId ) ?? {};
33
34
 
34
35
  // Get post-content block client ID.
35
36
  const [ postContentClientId = '' ] = getBlocksByName( 'core/post-content' );
@@ -100,6 +101,11 @@ function getLatestHeadings( select, clientId ) {
100
101
  if ( blockName === 'core/heading' ) {
101
102
  const headingAttributes = getBlockAttributes( blockClientId );
102
103
 
104
+ // Skip headings that are deeper than maxLevel
105
+ if ( maxLevel && headingAttributes.level > maxLevel ) {
106
+ continue;
107
+ }
108
+
103
109
  const canBeLinked =
104
110
  typeof headingPageLink === 'string' &&
105
111
  typeof headingAttributes.anchor === 'string' &&