@wordpress/block-library 7.3.11 → 7.3.14

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 (91) hide show
  1. package/build/avatar/hooks.js +2 -2
  2. package/build/avatar/hooks.js.map +1 -1
  3. package/build/comment-author-name/edit.js +3 -3
  4. package/build/comment-author-name/edit.js.map +1 -1
  5. package/build/comment-author-name/index.js +0 -4
  6. package/build/comment-author-name/index.js.map +1 -1
  7. package/build/comment-date/edit.js +4 -4
  8. package/build/comment-date/edit.js.map +1 -1
  9. package/build/comment-date/index.js +0 -4
  10. package/build/comment-date/index.js.map +1 -1
  11. package/build/comment-edit-link/index.js +0 -4
  12. package/build/comment-edit-link/index.js.map +1 -1
  13. package/build/comment-reply-link/index.js +0 -4
  14. package/build/comment-reply-link/index.js.map +1 -1
  15. package/build/comments-query-loop/edit.js +10 -2
  16. package/build/comments-query-loop/edit.js.map +1 -1
  17. package/build/latest-posts/edit.js +30 -4
  18. package/build/latest-posts/edit.js.map +1 -1
  19. package/build/media-text/edit.js +0 -1
  20. package/build/media-text/edit.js.map +1 -1
  21. package/build/post-comments/edit.js +12 -33
  22. package/build/post-comments/edit.js.map +1 -1
  23. package/build/post-comments-form/edit.js +46 -25
  24. package/build/post-comments-form/edit.js.map +1 -1
  25. package/build/post-comments-form/form.js +48 -0
  26. package/build/post-comments-form/form.js.map +1 -0
  27. package/build/query/edit/inspector-controls/index.js +4 -16
  28. package/build/query/edit/inspector-controls/index.js.map +1 -1
  29. package/build/query/edit/inspector-controls/sticky-control.js +41 -0
  30. package/build/query/edit/inspector-controls/sticky-control.js.map +1 -0
  31. package/build-module/avatar/hooks.js +2 -2
  32. package/build-module/avatar/hooks.js.map +1 -1
  33. package/build-module/comment-author-name/edit.js +3 -3
  34. package/build-module/comment-author-name/edit.js.map +1 -1
  35. package/build-module/comment-author-name/index.js +0 -4
  36. package/build-module/comment-author-name/index.js.map +1 -1
  37. package/build-module/comment-date/edit.js +4 -4
  38. package/build-module/comment-date/edit.js.map +1 -1
  39. package/build-module/comment-date/index.js +0 -4
  40. package/build-module/comment-date/index.js.map +1 -1
  41. package/build-module/comment-edit-link/index.js +0 -4
  42. package/build-module/comment-edit-link/index.js.map +1 -1
  43. package/build-module/comment-reply-link/index.js +0 -4
  44. package/build-module/comment-reply-link/index.js.map +1 -1
  45. package/build-module/comments-query-loop/edit.js +10 -2
  46. package/build-module/comments-query-loop/edit.js.map +1 -1
  47. package/build-module/latest-posts/edit.js +29 -5
  48. package/build-module/latest-posts/edit.js.map +1 -1
  49. package/build-module/media-text/edit.js +0 -1
  50. package/build-module/media-text/edit.js.map +1 -1
  51. package/build-module/post-comments/edit.js +12 -34
  52. package/build-module/post-comments/edit.js.map +1 -1
  53. package/build-module/post-comments-form/edit.js +47 -28
  54. package/build-module/post-comments-form/edit.js.map +1 -1
  55. package/build-module/post-comments-form/form.js +39 -0
  56. package/build-module/post-comments-form/form.js.map +1 -0
  57. package/build-module/query/edit/inspector-controls/index.js +3 -15
  58. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  59. package/build-module/query/edit/inspector-controls/sticky-control.js +31 -0
  60. package/build-module/query/edit/inspector-controls/sticky-control.js.map +1 -0
  61. package/build-style/editor-rtl.css +3 -0
  62. package/build-style/editor.css +3 -0
  63. package/build-style/navigation/style-rtl.css +3 -0
  64. package/build-style/navigation/style.css +3 -0
  65. package/build-style/post-comments-form/editor-rtl.css +3 -0
  66. package/build-style/post-comments-form/editor.css +3 -0
  67. package/build-style/style-rtl.css +3 -0
  68. package/build-style/style.css +3 -0
  69. package/package.json +7 -7
  70. package/src/avatar/hooks.js +9 -6
  71. package/src/comment-author-name/block.json +0 -4
  72. package/src/comment-author-name/edit.js +3 -12
  73. package/src/comment-date/block.json +0 -4
  74. package/src/comment-date/edit.js +10 -14
  75. package/src/comment-date/index.php +0 -3
  76. package/src/comment-edit-link/block.json +0 -4
  77. package/src/comment-reply-link/block.json +0 -4
  78. package/src/comments-query-loop/edit.js +24 -4
  79. package/src/cover/index.php +9 -6
  80. package/src/gallery/index.php +2 -1
  81. package/src/latest-posts/edit.js +27 -2
  82. package/src/media-text/edit.js +0 -1
  83. package/src/navigation/style.scss +3 -0
  84. package/src/post-comments/edit.js +13 -42
  85. package/src/post-comments-form/edit.js +65 -59
  86. package/src/post-comments-form/editor.scss +4 -0
  87. package/src/post-comments-form/form.js +43 -0
  88. package/src/post-template/index.php +25 -16
  89. package/src/query/edit/inspector-controls/index.js +3 -13
  90. package/src/query/edit/inspector-controls/sticky-control.js +25 -0
  91. package/src/query-no-results/index.php +10 -8
@@ -11,13 +11,17 @@ import {
11
11
  BlockControls,
12
12
  Warning,
13
13
  useBlockProps,
14
+ store as blockEditorStore,
14
15
  } from '@wordpress/block-editor';
15
- import { useEntityProp } from '@wordpress/core-data';
16
- import { __, sprintf } from '@wordpress/i18n';
17
- import {
18
- __experimentalUseDisabled as useDisabled,
19
- useInstanceId,
20
- } from '@wordpress/compose';
16
+ import { Button } from '@wordpress/components';
17
+ import { useEntityProp, store as coreStore } from '@wordpress/core-data';
18
+ import { __, _x, sprintf } from '@wordpress/i18n';
19
+ import { useSelect } from '@wordpress/data';
20
+
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+ import CommentsForm from './form';
21
25
 
22
26
  export default function PostCommentsFormEdit( {
23
27
  attributes,
@@ -26,7 +30,7 @@ export default function PostCommentsFormEdit( {
26
30
  } ) {
27
31
  const { textAlign } = attributes;
28
32
  const { postId, postType } = context;
29
- const [ commentStatus ] = useEntityProp(
33
+ const [ commentStatus, setCommentStatus ] = useEntityProp(
30
34
  'postType',
31
35
  postType,
32
36
  'comment_status',
@@ -38,11 +42,59 @@ export default function PostCommentsFormEdit( {
38
42
  } ),
39
43
  } );
40
44
 
41
- const isInSiteEditor = postType === undefined || postId === undefined;
45
+ const isSiteEditor = postType === undefined || postId === undefined;
46
+
47
+ const { defaultCommentStatus } = useSelect(
48
+ ( select ) =>
49
+ select( blockEditorStore ).getSettings()
50
+ .__experimentalDiscussionSettings
51
+ );
52
+
53
+ const postTypeSupportsComments = useSelect( ( select ) =>
54
+ postType
55
+ ? !! select( coreStore ).getPostType( postType )?.supports.comments
56
+ : false
57
+ );
58
+
59
+ let warning = false;
60
+ let actions;
61
+ let showPlaceholder = true;
42
62
 
43
- const disabledFormRef = useDisabled();
63
+ if ( ! isSiteEditor && 'open' !== commentStatus ) {
64
+ if ( 'closed' === commentStatus ) {
65
+ warning = __(
66
+ 'Post Comments Form block: Comments are not enabled for this item.'
67
+ );
44
68
 
45
- const instanceId = useInstanceId( PostCommentsFormEdit );
69
+ actions = [
70
+ <Button
71
+ key="enableComments"
72
+ onClick={ () => setCommentStatus( 'open' ) }
73
+ variant="primary"
74
+ >
75
+ { _x(
76
+ 'Enable comments',
77
+ 'action that affects the current post'
78
+ ) }
79
+ </Button>,
80
+ ];
81
+ showPlaceholder = false;
82
+ } else if ( ! postTypeSupportsComments ) {
83
+ warning = sprintf(
84
+ /* translators: 1: Post type (i.e. "post", "page") */
85
+ __(
86
+ 'Post Comments Form block: Comments are not enabled for this post type (%s).'
87
+ ),
88
+ postType
89
+ );
90
+ showPlaceholder = false;
91
+ } else if ( 'open' !== defaultCommentStatus ) {
92
+ warning = __(
93
+ 'Post Comments Form block: Comments are not enabled.'
94
+ );
95
+ showPlaceholder = false;
96
+ }
97
+ }
46
98
 
47
99
  return (
48
100
  <>
@@ -55,57 +107,11 @@ export default function PostCommentsFormEdit( {
55
107
  />
56
108
  </BlockControls>
57
109
  <div { ...blockProps }>
58
- { ! commentStatus && ! isInSiteEditor && (
59
- <Warning>
60
- { __(
61
- 'Post Comments Form block: comments are not enabled for this post type.'
62
- ) }
63
- </Warning>
110
+ { warning && (
111
+ <Warning actions={ actions }>{ warning }</Warning>
64
112
  ) }
65
113
 
66
- { 'open' !== commentStatus && ! isInSiteEditor && (
67
- <Warning>
68
- { sprintf(
69
- /* translators: 1: Post type (i.e. "post", "page") */
70
- __(
71
- 'Post Comments Form block: comments to this %s are not allowed.'
72
- ),
73
- postType
74
- ) }
75
- </Warning>
76
- ) }
77
-
78
- { ( 'open' === commentStatus || isInSiteEditor ) && (
79
- <div>
80
- <h3>{ __( 'Leave a Reply' ) }</h3>
81
- <form
82
- noValidate
83
- className="comment-form"
84
- ref={ disabledFormRef }
85
- >
86
- <p>
87
- <label htmlFor={ `comment-${ instanceId }` }>
88
- { __( 'Comment' ) }
89
- </label>
90
- <textarea
91
- id={ `comment-${ instanceId }` }
92
- name="comment"
93
- cols="45"
94
- rows="8"
95
- />
96
- </p>
97
- <p>
98
- <input
99
- name="submit"
100
- className="submit wp-block-button__link"
101
- label={ __( 'Post Comment' ) }
102
- value={ __( 'Post Comment' ) }
103
- readOnly
104
- />
105
- </p>
106
- </form>
107
- </div>
108
- ) }
114
+ { showPlaceholder ? <CommentsForm /> : null }
109
115
  </div>
110
116
  </>
111
117
  );
@@ -1,3 +1,7 @@
1
1
  .wp-block-post-comments-form * {
2
2
  pointer-events: none;
3
+
4
+ &.block-editor-warning * {
5
+ pointer-events: auto;
6
+ }
3
7
  }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import {
6
+ __experimentalUseDisabled as useDisabled,
7
+ useInstanceId,
8
+ } from '@wordpress/compose';
9
+
10
+ const CommentsForm = () => {
11
+ const disabledFormRef = useDisabled();
12
+ const instanceId = useInstanceId( CommentsForm );
13
+
14
+ return (
15
+ <div className="comment-respond">
16
+ <h3 className="comment-reply-title">{ __( 'Leave a Reply' ) }</h3>
17
+ <form noValidate className="comment-form" ref={ disabledFormRef }>
18
+ <p>
19
+ <label htmlFor={ `comment-${ instanceId }` }>
20
+ { __( 'Comment' ) }
21
+ </label>
22
+ <textarea
23
+ id={ `comment-${ instanceId }` }
24
+ name="comment"
25
+ cols="45"
26
+ rows="8"
27
+ />
28
+ </p>
29
+ <p className="form-submit wp-block-button">
30
+ <input
31
+ name="submit"
32
+ type="submit"
33
+ className="submit wp-block-button__link"
34
+ label={ __( 'Post Comment' ) }
35
+ value={ __( 'Post Comment' ) }
36
+ />
37
+ </p>
38
+ </form>
39
+ </div>
40
+ );
41
+ };
42
+
43
+ export default CommentsForm;
@@ -44,24 +44,16 @@ function render_block_core_post_template( $attributes, $content, $block ) {
44
44
  $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
45
45
  $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
46
46
 
47
- $query_args = build_query_vars_from_query_block( $block, $page );
48
- // Override the custom query with the global query if needed.
47
+ // Use global query if needed.
49
48
  $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
50
49
  if ( $use_global_query ) {
51
50
  global $wp_query;
52
- if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) {
53
- // Unset `offset` because if is set, $wp_query overrides/ignores the paged parameter and breaks pagination.
54
- unset( $query_args['offset'] );
55
- $query_args = wp_parse_args( $wp_query->query_vars, $query_args );
56
-
57
- if ( empty( $query_args['post_type'] ) && is_singular() ) {
58
- $query_args['post_type'] = get_post_type( get_the_ID() );
59
- }
60
- }
51
+ $query = clone $wp_query;
52
+ } else {
53
+ $query_args = build_query_vars_from_query_block( $block, $page );
54
+ $query = new WP_Query( $query_args );
61
55
  }
62
56
 
63
- $query = new WP_Query( $query_args );
64
-
65
57
  if ( ! $query->have_posts() ) {
66
58
  return '';
67
59
  }
@@ -82,19 +74,36 @@ function render_block_core_post_template( $attributes, $content, $block ) {
82
74
  $content = '';
83
75
  while ( $query->have_posts() ) {
84
76
  $query->the_post();
77
+
78
+ // Get an instance of the current Post Template block.
79
+ $block_instance = $block->parsed_block;
80
+
81
+ // Set the block name to one that does not correspond to an existing registered block.
82
+ // This ensures that for the inner instances of the Post Template block, we do not render any block supports.
83
+ $block_instance['blockName'] = 'core/null';
84
+
85
+ // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling
86
+ // `render_callback` and ensure that no wrapper markup is included.
85
87
  $block_content = (
86
88
  new WP_Block(
87
- $block->parsed_block,
89
+ $block_instance,
88
90
  array(
89
91
  'postType' => get_post_type(),
90
92
  'postId' => get_the_ID(),
91
93
  )
92
94
  )
93
95
  )->render( array( 'dynamic' => false ) );
94
- $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
95
- $content .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>';
96
+
97
+ // Wrap the render inner blocks in a `li` element with the appropriate post classes.
98
+ $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
99
+ $content .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>';
96
100
  }
97
101
 
102
+ /*
103
+ * Use this function to restore the context of the template tags
104
+ * from a secondary query loop back to the main query loop.
105
+ * Since we use two custom loops, it's safest to always restore.
106
+ */
98
107
  wp_reset_postdata();
99
108
 
100
109
  return sprintf(
@@ -24,14 +24,9 @@ import { useEffect, useState, useCallback } from '@wordpress/element';
24
24
  import OrderControl from './order-control';
25
25
  import AuthorControl from './author-control';
26
26
  import TaxonomyControls from './taxonomy-controls';
27
+ import StickyControl from './sticky-control';
27
28
  import { usePostTypes } from '../../utils';
28
29
 
29
- const stickyOptions = [
30
- { label: __( 'Include' ), value: '' },
31
- { label: __( 'Exclude' ), value: 'exclude' },
32
- { label: __( 'Only' ), value: 'only' },
33
- ];
34
-
35
30
  export default function QueryInspectorControls( {
36
31
  attributes: { query, displayLayout },
37
32
  setQuery,
@@ -135,15 +130,10 @@ export default function QueryInspectorControls( {
135
130
  onChange={ setQuery }
136
131
  />
137
132
  ) }
138
- { showSticky && (
139
- <SelectControl
140
- label={ __( 'Sticky posts' ) }
141
- options={ stickyOptions }
133
+ { ! inherit && showSticky && (
134
+ <StickyControl
142
135
  value={ sticky }
143
136
  onChange={ ( value ) => setQuery( { sticky: value } ) }
144
- help={ __(
145
- 'Blog posts can be "stickied", a feature that places them at the top of the front page of posts, keeping it there until new sticky posts are published.'
146
- ) }
147
137
  />
148
138
  ) }
149
139
  </PanelBody>
@@ -0,0 +1,25 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { SelectControl } from '@wordpress/components';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ const stickyOptions = [
8
+ { label: __( 'Include' ), value: '' },
9
+ { label: __( 'Exclude' ), value: 'exclude' },
10
+ { label: __( 'Only' ), value: 'only' },
11
+ ];
12
+
13
+ export default function StickyControl( { value, onChange } ) {
14
+ return (
15
+ <SelectControl
16
+ label={ __( 'Sticky posts' ) }
17
+ options={ stickyOptions }
18
+ value={ value }
19
+ onChange={ onChange }
20
+ help={ __(
21
+ 'Blog posts can be "stickied", a feature that places them at the top of the front page of posts, keeping it there until new sticky posts are published.'
22
+ ) }
23
+ />
24
+ );
25
+ }
@@ -19,24 +19,26 @@ function render_block_core_query_no_results( $attributes, $content, $block ) {
19
19
  return '';
20
20
  }
21
21
 
22
- $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
23
- $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
24
- $query_args = build_query_vars_from_query_block( $block, $page );
22
+ $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
23
+ $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
24
+
25
25
  // Override the custom query with the global query if needed.
26
26
  $use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
27
27
  if ( $use_global_query ) {
28
28
  global $wp_query;
29
- if ( $wp_query && isset( $wp_query->query_vars ) && is_array( $wp_query->query_vars ) ) {
30
- $query_args = wp_parse_args( $wp_query->query_vars, $query_args );
31
- }
29
+ $query = $wp_query;
30
+ } else {
31
+ $query_args = build_query_vars_from_query_block( $block, $page );
32
+ $query = new WP_Query( $query_args );
32
33
  }
33
- $query = new WP_Query( $query_args );
34
34
 
35
35
  if ( $query->have_posts() ) {
36
36
  return '';
37
37
  }
38
38
 
39
- wp_reset_postdata();
39
+ if ( ! $use_global_query ) {
40
+ wp_reset_postdata();
41
+ }
40
42
 
41
43
  return sprintf(
42
44
  '<div %1$s>%2$s</div>',