@wordpress/block-library 7.3.5 → 7.3.8

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 (81) hide show
  1. package/build/comments-title/deprecated.js +110 -0
  2. package/build/comments-title/deprecated.js.map +1 -0
  3. package/build/comments-title/edit.js +35 -37
  4. package/build/comments-title/edit.js.map +1 -1
  5. package/build/comments-title/index.js +4 -7
  6. package/build/comments-title/index.js.map +1 -1
  7. package/build/cover/edit.js +4 -1
  8. package/build/cover/edit.js.map +1 -1
  9. package/build/index.js +1 -3
  10. package/build/index.js.map +1 -1
  11. package/build/navigation/edit/index.js +5 -28
  12. package/build/navigation/edit/index.js.map +1 -1
  13. package/build/navigation/index.js +0 -1
  14. package/build/navigation/index.js.map +1 -1
  15. package/build/post-comments/edit.js +33 -15
  16. package/build/post-comments/edit.js.map +1 -1
  17. package/build-module/comments-title/deprecated.js +102 -0
  18. package/build-module/comments-title/deprecated.js.map +1 -0
  19. package/build-module/comments-title/edit.js +38 -40
  20. package/build-module/comments-title/edit.js.map +1 -1
  21. package/build-module/comments-title/index.js +3 -7
  22. package/build-module/comments-title/index.js.map +1 -1
  23. package/build-module/cover/edit.js +4 -1
  24. package/build-module/cover/edit.js.map +1 -1
  25. package/build-module/index.js +1 -2
  26. package/build-module/index.js.map +1 -1
  27. package/build-module/navigation/edit/index.js +6 -28
  28. package/build-module/navigation/edit/index.js.map +1 -1
  29. package/build-module/navigation/index.js +0 -1
  30. package/build-module/navigation/index.js.map +1 -1
  31. package/build-module/post-comments/edit.js +34 -15
  32. package/build-module/post-comments/edit.js.map +1 -1
  33. package/build-style/post-comments/style-rtl.css +7 -0
  34. package/build-style/post-comments/style.css +7 -0
  35. package/build-style/post-comments-form/style-rtl.css +1 -3
  36. package/build-style/post-comments-form/style.css +1 -3
  37. package/build-style/style-rtl.css +8 -3
  38. package/build-style/style.css +8 -3
  39. package/package.json +7 -7
  40. package/src/comment-template/index.php +4 -0
  41. package/src/comments-pagination/index.php +4 -0
  42. package/src/comments-title/block.json +0 -6
  43. package/src/comments-title/deprecated.js +34 -0
  44. package/src/comments-title/edit.js +44 -100
  45. package/src/comments-title/index.js +2 -0
  46. package/src/comments-title/index.php +43 -22
  47. package/src/cover/edit.js +5 -0
  48. package/src/cover/index.php +20 -37
  49. package/src/index.js +0 -2
  50. package/src/latest-posts/index.php +12 -6
  51. package/src/navigation/block.json +0 -1
  52. package/src/navigation/edit/index.js +6 -36
  53. package/src/navigation/index.php +40 -0
  54. package/src/post-author/index.php +1 -1
  55. package/src/post-comments/edit.js +53 -21
  56. package/src/post-comments/style.scss +8 -0
  57. package/src/post-comments-form/index.php +5 -1
  58. package/src/post-comments-form/style.scss +1 -4
  59. package/src/post-template/index.php +30 -0
  60. package/build/navigation-area/edit.js +0 -110
  61. package/build/navigation-area/edit.js.map +0 -1
  62. package/build/navigation-area/index.js +0 -62
  63. package/build/navigation-area/index.js.map +0 -1
  64. package/build/navigation-area/inner-blocks.js +0 -34
  65. package/build/navigation-area/inner-blocks.js.map +0 -1
  66. package/build/navigation-area/save.js +0 -18
  67. package/build/navigation-area/save.js.map +0 -1
  68. package/build-module/navigation-area/edit.js +0 -94
  69. package/build-module/navigation-area/edit.js.map +0 -1
  70. package/build-module/navigation-area/index.js +0 -48
  71. package/build-module/navigation-area/index.js.map +0 -1
  72. package/build-module/navigation-area/inner-blocks.js +0 -26
  73. package/build-module/navigation-area/inner-blocks.js.map +0 -1
  74. package/build-module/navigation-area/save.js +0 -10
  75. package/build-module/navigation-area/save.js.map +0 -1
  76. package/src/navigation-area/block.json +0 -23
  77. package/src/navigation-area/edit.js +0 -111
  78. package/src/navigation-area/index.js +0 -26
  79. package/src/navigation-area/index.php +0 -22
  80. package/src/navigation-area/inner-blocks.js +0 -24
  81. package/src/navigation-area/save.js +0 -8
@@ -14,51 +14,23 @@
14
14
  * @return string Returns the cover block markup, if useFeaturedImage is true.
15
15
  */
16
16
  function render_block_core_cover( $attributes, $content ) {
17
- if ( false === $attributes['useFeaturedImage'] ) {
17
+ if ( 'image' !== $attributes['backgroundType'] || false === $attributes['useFeaturedImage'] ) {
18
18
  return $content;
19
19
  }
20
20
 
21
- $current_featured_image = get_the_post_thumbnail_url();
22
-
23
- if ( false === $current_featured_image ) {
24
- return $content;
25
- }
26
-
27
- $is_img_element = ! ( $attributes['hasParallax'] || $attributes['isRepeated'] );
28
- $is_image_background = 'image' === $attributes['backgroundType'];
29
-
30
- if ( $is_image_background && ! $is_img_element ) {
31
- $content = preg_replace(
32
- '/class=\".*?\"/',
33
- '${0} style="background-image:url(' . esc_url( $current_featured_image ) . ')"',
34
- $content,
35
- 1
21
+ if ( ! ( $attributes['hasParallax'] || $attributes['isRepeated'] ) ) {
22
+ $attr = array(
23
+ 'class' => 'wp-block-cover__image-background',
24
+ 'data-object-fit' => 'cover',
36
25
  );
37
- }
38
26
 
39
- if ( $is_image_background && $is_img_element ) {
40
- $object_position = '';
41
27
  if ( isset( $attributes['focalPoint'] ) ) {
42
- $object_position = round( $attributes['focalPoint']['x'] * 100 ) . '%' . ' ' .
43
- round( $attributes['focalPoint']['y'] * 100 ) . '%';
28
+ $object_position = round( $attributes['focalPoint']['x'] * 100 ) . '%' . ' ' . round( $attributes['focalPoint']['y'] * 100 ) . '%';
29
+ $attr['data-object-position'] = $object_position;
30
+ $attr['style'] = 'object-position: ' . $object_position;
44
31
  }
45
32
 
46
- $image_template = '<img
47
- class="wp-block-cover__image-background"
48
- alt="%s"
49
- src="%s"
50
- style="object-position: %s"
51
- data-object-fit="cover"
52
- data-object-position="%s"
53
- />';
54
-
55
- $image = sprintf(
56
- $image_template,
57
- esc_attr( get_the_post_thumbnail_caption() ),
58
- esc_url( $current_featured_image ),
59
- esc_attr( $object_position ),
60
- esc_attr( $object_position )
61
- );
33
+ $image = get_the_post_thumbnail( null, 'post-thumbnail', $attr );
62
34
 
63
35
  $content = str_replace(
64
36
  '</span><div',
@@ -66,6 +38,17 @@ function render_block_core_cover( $attributes, $content ) {
66
38
  $content
67
39
  );
68
40
 
41
+ } else {
42
+ if ( in_the_loop() ) {
43
+ update_post_thumbnail_cache();
44
+ }
45
+ $current_featured_image = get_the_post_thumbnail_url();
46
+ $content = preg_replace(
47
+ '/class=\".*?\"/',
48
+ '${0} style="background-image:url(' . esc_url( $current_featured_image ) . ')"',
49
+ $content,
50
+ 1
51
+ );
69
52
  }
70
53
 
71
54
  return $content;
package/src/index.js CHANGED
@@ -54,7 +54,6 @@ import * as mediaText from './media-text';
54
54
  import * as missing from './missing';
55
55
  import * as more from './more';
56
56
  import * as navigation from './navigation';
57
- import * as navigationArea from './navigation-area';
58
57
  import * as navigationLink from './navigation-link';
59
58
  import * as navigationSubmenu from './navigation-submenu';
60
59
  import * as nextpage from './nextpage';
@@ -279,7 +278,6 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env
279
278
  ...( enableFSEBlocks
280
279
  ? [
281
280
  commentAuthorAvatar,
282
- navigationArea,
283
281
  postComment,
284
282
  postCommentsCount,
285
283
  postCommentsLink,
@@ -37,11 +37,12 @@ function render_block_core_latest_posts( $attributes ) {
37
37
  global $post, $block_core_latest_posts_excerpt_length;
38
38
 
39
39
  $args = array(
40
- 'posts_per_page' => $attributes['postsToShow'],
41
- 'post_status' => 'publish',
42
- 'order' => $attributes['order'],
43
- 'orderby' => $attributes['orderBy'],
44
- 'suppress_filters' => false,
40
+ 'posts_per_page' => $attributes['postsToShow'],
41
+ 'post_status' => 'publish',
42
+ 'order' => $attributes['order'],
43
+ 'orderby' => $attributes['orderBy'],
44
+ 'ignore_sticky_posts' => true,
45
+ 'no_found_rows' => true,
45
46
  );
46
47
 
47
48
  $block_core_latest_posts_excerpt_length = $attributes['excerptLength'];
@@ -54,7 +55,12 @@ function render_block_core_latest_posts( $attributes ) {
54
55
  $args['author'] = $attributes['selectedAuthor'];
55
56
  }
56
57
 
57
- $recent_posts = get_posts( $args );
58
+ $query = new WP_Query;
59
+ $recent_posts = $query->query( $args );
60
+
61
+ if ( isset( $attributes['displayFeaturedImage'] ) && $attributes['displayFeaturedImage'] ) {
62
+ update_post_thumbnail_cache( $query );
63
+ }
58
64
 
59
65
  $list_items_markup = '';
60
66
 
@@ -65,7 +65,6 @@
65
65
  "default": 5
66
66
  }
67
67
  },
68
- "usesContext": [ "navigationArea" ],
69
68
  "providesContext": {
70
69
  "textColor": "textColor",
71
70
  "customTextColor": "customTextColor",
@@ -2,7 +2,6 @@
2
2
  * External dependencies
3
3
  */
4
4
  import classnames from 'classnames';
5
- import { noop } from 'lodash';
6
5
 
7
6
  /**
8
7
  * WordPress dependencies
@@ -26,7 +25,7 @@ import {
26
25
  getColorClassName,
27
26
  Warning,
28
27
  } from '@wordpress/block-editor';
29
- import { EntityProvider, useEntityProp } from '@wordpress/core-data';
28
+ import { EntityProvider } from '@wordpress/core-data';
30
29
 
31
30
  import { useDispatch, useSelect, useRegistry } from '@wordpress/data';
32
31
  import {
@@ -109,7 +108,6 @@ function Navigation( {
109
108
  setOverlayBackgroundColor,
110
109
  overlayTextColor,
111
110
  setOverlayTextColor,
112
- context: { navigationArea },
113
111
 
114
112
  // These props are used by the navigation editor to override specific
115
113
  // navigation block settings.
@@ -129,34 +127,12 @@ function Navigation( {
129
127
  hasIcon,
130
128
  } = attributes;
131
129
 
132
- let areaMenu,
133
- setAreaMenu = noop;
134
- // Navigation areas are deprecated and on their way out. Let's not perform
135
- // the request unless we're in an environment where the endpoint exists.
136
- if ( process.env.IS_GUTENBERG_PLUGIN ) {
137
- // eslint-disable-next-line react-hooks/rules-of-hooks
138
- [ areaMenu, setAreaMenu ] = useEntityProp(
139
- 'root',
140
- 'navigationArea',
141
- 'navigation',
142
- navigationArea
143
- );
144
- }
145
-
146
- const navigationAreaMenu = areaMenu === 0 ? undefined : areaMenu;
147
-
148
- const ref = navigationArea ? navigationAreaMenu : attributes.ref;
130
+ const ref = attributes.ref;
149
131
 
150
132
  const registry = useRegistry();
151
- const setRef = useCallback(
152
- ( postId ) => {
153
- setAttributes( { ref: postId } );
154
- if ( navigationArea ) {
155
- setAreaMenu( postId );
156
- }
157
- },
158
- [ navigationArea ]
159
- );
133
+ const setRef = ( postId ) => {
134
+ setAttributes( { ref: postId } );
135
+ };
160
136
 
161
137
  const [ hasAlreadyRendered, RecursionProvider ] = useNoRecursiveRenders(
162
138
  `navigationMenu/${ ref }`
@@ -261,8 +237,6 @@ function Navigation( {
261
237
  setHasSavedUnsavedInnerBlocks,
262
238
  ] = useState( false );
263
239
 
264
- const isWithinUnassignedArea = !! navigationArea && ! ref;
265
-
266
240
  const [ isResponsiveMenuOpen, setResponsiveMenuVisibility ] = useState(
267
241
  false
268
242
  );
@@ -322,13 +296,12 @@ function Navigation( {
322
296
  // - there is no classic menu conversion process in progress.
323
297
  // - there is no menu creation process in progress.
324
298
  // - there are no uncontrolled blocks.
325
- // - (legacy) there is a Navigation Area without a ref attribute pointing to a Navigation Post.
326
299
  const isPlaceholder =
327
300
  ! ref &&
328
301
  ! isCreatingNavigationMenu &&
329
302
  ! isConvertingClassicMenu &&
330
303
  hasResolvedNavigationMenus &&
331
- ( ! hasUncontrolledInnerBlocks || isWithinUnassignedArea );
304
+ ! hasUncontrolledInnerBlocks;
332
305
 
333
306
  const isEntityAvailable =
334
307
  ! isNavigationMenuMissing && isNavigationMenuResolved;
@@ -567,9 +540,6 @@ function Navigation( {
567
540
 
568
541
  const resetToEmptyBlock = useCallback( () => {
569
542
  registry.batch( () => {
570
- if ( navigationArea ) {
571
- setAreaMenu( 0 );
572
- }
573
543
  setAttributes( {
574
544
  ref: undefined,
575
545
  } );
@@ -350,6 +350,41 @@ function block_core_navigation_get_fallback_blocks() {
350
350
  return apply_filters( 'block_core_navigation_render_fallback', $fallback_blocks );
351
351
  }
352
352
 
353
+ /**
354
+ * Iterate through all inner blocks recursively and get navigation link block's post IDs.
355
+ *
356
+ * @param WP_Block_List $inner_blocks Block list class instance.
357
+ *
358
+ * @return array Array of post IDs.
359
+ */
360
+ function block_core_navigation_get_post_ids( $inner_blocks ) {
361
+ $post_ids = array_map( 'block_core_navigation_from_block_get_post_ids', iterator_to_array( $inner_blocks ) );
362
+ return array_unique( array_merge( ...$post_ids ) );
363
+ }
364
+
365
+ /**
366
+ * Get post IDs from a navigation link block instance.
367
+ *
368
+ * @param WP_Block $block Instance of a block.
369
+ *
370
+ * @return array Array of post IDs.
371
+ */
372
+ function block_core_navigation_from_block_get_post_ids( $block ) {
373
+ $post_ids = array();
374
+
375
+ if ( $block->inner_blocks ) {
376
+ $post_ids = block_core_navigation_get_post_ids( $block->inner_blocks );
377
+ }
378
+
379
+ if ( 'core/navigation-link' === $block->name || 'core/navigation-submenu' === $block->name ) {
380
+ if ( $block->attributes && isset( $block->attributes['kind'] ) && 'post-type' === $block->attributes['kind'] ) {
381
+ $post_ids[] = $block->attributes['id'];
382
+ }
383
+ }
384
+
385
+ return $post_ids;
386
+ }
387
+
353
388
  /**
354
389
  * Renders the `core/navigation` block on server.
355
390
  *
@@ -501,6 +536,11 @@ function render_block_core_navigation( $attributes, $content, $block ) {
501
536
  $text_decoration ? array( $text_decoration_class ) : array()
502
537
  );
503
538
 
539
+ $post_ids = block_core_navigation_get_post_ids( $inner_blocks );
540
+ if ( $post_ids ) {
541
+ _prime_post_caches( $post_ids, false, false );
542
+ }
543
+
504
544
  $inner_blocks_html = '';
505
545
  $is_list_open = false;
506
546
  foreach ( $inner_blocks as $inner_block ) {
@@ -39,7 +39,7 @@ function render_block_core_post_author( $attributes, $content, $block ) {
39
39
  return sprintf( '<div %1$s>', $wrapper_attributes ) .
40
40
  ( ! empty( $attributes['showAvatar'] ) ? '<div class="wp-block-post-author__avatar">' . $avatar . '</div>' : '' ) .
41
41
  '<div class="wp-block-post-author__content">' .
42
- ( ! empty( $byline ) ? '<p class="wp-block-post-author__byline">' . esc_html( $byline ) . '</p>' : '' ) .
42
+ ( ! empty( $byline ) ? '<p class="wp-block-post-author__byline">' . wp_kses_post( $byline ) . '</p>' : '' ) .
43
43
  '<p class="wp-block-post-author__name">' . get_the_author_meta( 'display_name', $author_id ) . '</p>' .
44
44
  ( ! empty( $attributes['showBio'] ) ? '<p class="wp-block-post-author__bio">' . get_the_author_meta( 'user_description', $author_id ) . '</p>' : '' ) .
45
45
  '</div>' .
@@ -20,6 +20,7 @@ import {
20
20
  __experimentalUseDisabled as useDisabled,
21
21
  useInstanceId,
22
22
  } from '@wordpress/compose';
23
+ import { createInterpolateElement } from '@wordpress/element';
23
24
 
24
25
  export default function PostCommentsEdit( {
25
26
  attributes: { textAlign },
@@ -110,7 +111,10 @@ export default function PostCommentsEdit( {
110
111
  ref={ disabledRef }
111
112
  >
112
113
  <h3>
113
- { __( 'One response to' ) } “{ postTitle }”
114
+ {
115
+ /* translators: %s: Post title. */
116
+ sprintf( __( 'One response to %s' ), postTitle )
117
+ }
114
118
  </h3>
115
119
 
116
120
  <div className="navigation">
@@ -135,23 +139,43 @@ export default function PostCommentsEdit( {
135
139
  width="32"
136
140
  loading="lazy"
137
141
  />
138
- <b className="fn">
139
- <a href="#top" className="url">
140
- { __(
141
- 'A WordPress Commenter'
142
- ) }
143
- </a>
144
- </b>{ ' ' }
145
- <span className="says">
146
- { __( 'says' ) }:
147
- </span>
142
+ { createInterpolateElement(
143
+ sprintf(
144
+ /* translators: %s: Comment author link. */
145
+ __(
146
+ '%s <span>says:</span>'
147
+ ),
148
+ sprintf(
149
+ '<cite><a>%s</a></cite>',
150
+ __(
151
+ 'A WordPress Commenter'
152
+ )
153
+ )
154
+ ),
155
+ {
156
+ span: (
157
+ <span className="says" />
158
+ ),
159
+ a: (
160
+ /* eslint-disable jsx-a11y/anchor-has-content */
161
+ <a
162
+ href="#top"
163
+ className="url"
164
+ />
165
+ /* eslint-enable jsx-a11y/anchor-has-content */
166
+ ),
167
+ cite: (
168
+ <cite className="fn" />
169
+ ),
170
+ }
171
+ ) }
148
172
  </div>
149
173
 
150
174
  <div className="comment-metadata">
151
175
  <a href="#top">
152
- <time dateTime="2000-01-01T00:00:00+00:00">
176
+ <time dateTime="2000-01-01T12:00:00+00:00">
153
177
  { __(
154
- 'January 1, 2000 at 00:00 am'
178
+ 'January 1, 2000 at 12:00 am'
155
179
  ) }
156
180
  </time>
157
181
  </a>{ ' ' }
@@ -174,13 +198,17 @@ export default function PostCommentsEdit( {
174
198
  'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.'
175
199
  ) }
176
200
  <br />
177
- { __(
178
- 'Commenter avatars come from'
179
- ) }{ ' ' }
180
- <a href="https://gravatar.com/">
181
- Gravatar
182
- </a>
183
- .
201
+ { createInterpolateElement(
202
+ __(
203
+ 'Commenter avatars come from <a>Gravatar</a>'
204
+ ),
205
+ {
206
+ a: (
207
+ /* eslint-disable-next-line jsx-a11y/anchor-has-content */
208
+ <a href="https://gravatar.com/" />
209
+ ),
210
+ }
211
+ ) }
184
212
  </p>
185
213
  </div>
186
214
 
@@ -188,7 +216,11 @@ export default function PostCommentsEdit( {
188
216
  <a
189
217
  className="comment-reply-link"
190
218
  href="#top"
191
- aria-label="Reply to A WordPress Commenter"
219
+ aria-label={ sprintf(
220
+ /* translators: Comment reply button text. %s: Comment author name. */
221
+ __( 'Reply to %s' ),
222
+ __( 'A WordPress Commenter' )
223
+ ) }
192
224
  >
193
225
  { __( 'Reply' ) }
194
226
  </a>
@@ -86,6 +86,14 @@
86
86
  }
87
87
  }
88
88
 
89
+ .comment-reply-title {
90
+ margin-bottom: 0;
91
+ :where(small) {
92
+ font-size: var(--wp--preset--font-size--medium, smaller);
93
+ margin-left: 0.5em;
94
+ }
95
+ }
96
+
89
97
  .reply {
90
98
  font-size: 0.875em;
91
99
  margin-bottom: 1.4em;
@@ -18,9 +18,13 @@ function render_block_core_post_comments_form( $attributes, $content, $block ) {
18
18
  return '';
19
19
  }
20
20
 
21
+ if ( post_password_required( $block->context['postId'] ) ) {
22
+ return;
23
+ }
24
+
21
25
  $classes = 'comment-respond'; // See comment further below.
22
26
  if ( isset( $attributes['textAlign'] ) ) {
23
- $classes .= 'has-text-align-' . $attributes['textAlign'];
27
+ $classes .= ' has-text-align-' . $attributes['textAlign'];
24
28
  }
25
29
 
26
30
  $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
@@ -69,13 +69,10 @@
69
69
  }
70
70
 
71
71
  .comment-reply-title {
72
- align-items: baseline;
73
- display: flex;
74
- justify-content: space-between;
75
72
  margin-bottom: 0;
76
-
77
73
  :where(small) {
78
74
  font-size: var(--wp--preset--font-size--medium, smaller);
75
+ margin-left: 0.5em;
79
76
  }
80
77
  }
81
78
  }
@@ -5,6 +5,32 @@
5
5
  * @package WordPress
6
6
  */
7
7
 
8
+ /**
9
+ * Determines whether a block list contains a block that uses the featured image.
10
+ *
11
+ * @param WP_Block_List $inner_blocks Inner block instance.
12
+ *
13
+ * @return bool Whether the block list contains a block that uses the featured image.
14
+ */
15
+ function block_core_post_template_uses_featured_image( $inner_blocks ) {
16
+ foreach ( $inner_blocks as $block ) {
17
+ if ( 'core/post-featured-image' === $block->name ) {
18
+ return true;
19
+ }
20
+ if (
21
+ 'core/cover' === $block->name &&
22
+ ! empty( $block->attributes['useFeaturedImage'] )
23
+ ) {
24
+ return true;
25
+ }
26
+ if ( $block->inner_blocks && block_core_post_template_uses_featured_image( $block->inner_blocks ) ) {
27
+ return true;
28
+ }
29
+ }
30
+
31
+ return false;
32
+ }
33
+
8
34
  /**
9
35
  * Renders the `core/post-template` block on the server.
10
36
  *
@@ -40,6 +66,10 @@ function render_block_core_post_template( $attributes, $content, $block ) {
40
66
  return '';
41
67
  }
42
68
 
69
+ if ( block_core_post_template_uses_featured_image( $block->inner_blocks ) ) {
70
+ update_post_thumbnail_cache( $query );
71
+ }
72
+
43
73
  $classnames = '';
44
74
  if ( isset( $block->context['displayLayout'] ) && isset( $block->context['query'] ) ) {
45
75
  if ( isset( $block->context['displayLayout']['type'] ) && 'flex' === $block->context['displayLayout']['type'] ) {
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _i18n = require("@wordpress/i18n");
13
-
14
- var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
15
-
16
- var _coreData = require("@wordpress/core-data");
17
-
18
- var _components = require("@wordpress/components");
19
-
20
- var _blockEditor = require("@wordpress/block-editor");
21
-
22
- var _data = require("@wordpress/data");
23
-
24
- var _innerBlocks = _interopRequireDefault(require("./inner-blocks"));
25
-
26
- var _placeholderPreview = _interopRequireDefault(require("../navigation/edit/placeholder/placeholder-preview"));
27
-
28
- /**
29
- * WordPress dependencies
30
- */
31
-
32
- /**
33
- * Internal dependencies
34
- */
35
- function NavigationAreaBlock(_ref) {
36
- let {
37
- attributes,
38
- setAttributes
39
- } = _ref;
40
- const {
41
- area
42
- } = attributes;
43
- const {
44
- navigationAreas,
45
- hasResolvedNavigationAreas
46
- } = (0, _data.useSelect)(select => {
47
- const {
48
- getEntityRecords,
49
- hasFinishedResolution
50
- } = select(_coreData.store);
51
- return {
52
- navigationAreas: getEntityRecords('root', 'navigationArea'),
53
- hasResolvedNavigationAreas: hasFinishedResolution('getEntityRecords', ['root', 'navigationArea'])
54
- };
55
- });
56
- const navigationMenuId = navigationAreas !== null && navigationAreas !== void 0 && navigationAreas.length ? navigationAreas[area] : undefined;
57
- const choices = (0, _element.useMemo)(() => navigationAreas === null || navigationAreas === void 0 ? void 0 : navigationAreas.map(_ref2 => {
58
- let {
59
- name,
60
- description
61
- } = _ref2;
62
- return {
63
- label: description,
64
- value: name
65
- };
66
- }), [navigationAreas]);
67
- (0, _deprecated.default)('wp.blockLibrary.NavigationArea', {
68
- since: '12.0',
69
- plugin: 'gutenberg'
70
- });
71
- return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_blockEditor.BlockControls, null, (0, _element.createElement)(_components.ToolbarGroup, null, (0, _element.createElement)(_components.ToolbarDropdownMenu, {
72
- label: (0, _i18n.__)('Select Area'),
73
- text: (0, _i18n.__)('Select Area'),
74
- icon: null
75
- }, _ref3 => {
76
- let {
77
- onClose
78
- } = _ref3;
79
- return (0, _element.createElement)(_components.MenuGroup, null, (0, _element.createElement)(_components.MenuItemsChoice, {
80
- value: area,
81
- onSelect: selectedArea => {
82
- setAttributes({
83
- area: selectedArea
84
- });
85
- onClose();
86
- },
87
- choices: choices
88
- }));
89
- }))), (0, _element.createElement)(_blockEditor.InspectorControls, null, (0, _element.createElement)(_components.PanelBody, {
90
- title: (0, _i18n.__)('Options')
91
- }, (0, _element.createElement)(_components.SelectControl, {
92
- label: (0, _i18n._x)('Area'),
93
- value: area // `undefined` is required for the preload attribute to be unset.
94
- ,
95
- onChange: value => setAttributes({
96
- area: value
97
- }),
98
- options: choices
99
- }))), !hasResolvedNavigationAreas && (0, _element.createElement)(_placeholderPreview.default, {
100
- isLoading: true
101
- }), // Render inner blocks only when navigationMenuId is known so
102
- // that inner blocks template is correct from the start.
103
- hasResolvedNavigationAreas && (0, _element.createElement)(_innerBlocks.default, {
104
- navigationMenuId: navigationMenuId
105
- }));
106
- }
107
-
108
- var _default = NavigationAreaBlock;
109
- exports.default = _default;
110
- //# sourceMappingURL=edit.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/navigation-area/edit.js"],"names":["NavigationAreaBlock","attributes","setAttributes","area","navigationAreas","hasResolvedNavigationAreas","select","getEntityRecords","hasFinishedResolution","coreStore","navigationMenuId","length","undefined","choices","map","name","description","label","value","since","plugin","onClose","selectedArea"],"mappings":";;;;;;;;;AAcA;;AAXA;;AACA;;AACA;;AACA;;AASA;;AACA;;AAKA;;AACA;;AAtBA;AACA;AACA;;AAgBA;AACA;AACA;AAIA,SAASA,mBAAT,OAA8D;AAAA,MAAhC;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAAgC;AAC7D,QAAM;AAAEC,IAAAA;AAAF,MAAWF,UAAjB;AAEA,QAAM;AAAEG,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAkD,qBACrDC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,gBAAF;AAAoBC,MAAAA;AAApB,QAA8CF,MAAM,CACzDG,eADyD,CAA1D;AAGA,WAAO;AACNL,MAAAA,eAAe,EAAEG,gBAAgB,CAAE,MAAF,EAAU,gBAAV,CAD3B;AAENF,MAAAA,0BAA0B,EAAEG,qBAAqB,CAChD,kBADgD,EAEhD,CAAE,MAAF,EAAU,gBAAV,CAFgD;AAF3C,KAAP;AAOA,GAZsD,CAAxD;AAcA,QAAME,gBAAgB,GAAGN,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAEO,MAAjB,GACtBP,eAAe,CAAED,IAAF,CADO,GAEtBS,SAFH;AAIA,QAAMC,OAAO,GAAG,sBACf,MACCT,eADD,aACCA,eADD,uBACCA,eAAe,CAAEU,GAAjB,CAAsB;AAAA,QAAE;AAAEC,MAAAA,IAAF;AAAQC,MAAAA;AAAR,KAAF;AAAA,WAA+B;AACpDC,MAAAA,KAAK,EAAED,WAD6C;AAEpDE,MAAAA,KAAK,EAAEH;AAF6C,KAA/B;AAAA,GAAtB,CAFc,EAMf,CAAEX,eAAF,CANe,CAAhB;AASA,2BAAY,gCAAZ,EAA8C;AAC7Ce,IAAAA,KAAK,EAAE,MADsC;AAE7CC,IAAAA,MAAM,EAAE;AAFqC,GAA9C;AAKA,SACC,qDACC,4BAAC,0BAAD,QACC,4BAAC,wBAAD,QACC,4BAAC,+BAAD;AACC,IAAA,KAAK,EAAG,cAAI,aAAJ,CADT;AAEC,IAAA,IAAI,EAAG,cAAI,aAAJ,CAFR;AAGC,IAAA,IAAI,EAAG;AAHR,KAKG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WACD,4BAAC,qBAAD,QACC,4BAAC,2BAAD;AACC,MAAA,KAAK,EAAGlB,IADT;AAEC,MAAA,QAAQ,EAAKmB,YAAF,IAAoB;AAC9BpB,QAAAA,aAAa,CAAE;AAAEC,UAAAA,IAAI,EAAEmB;AAAR,SAAF,CAAb;AACAD,QAAAA,OAAO;AACP,OALF;AAMC,MAAA,OAAO,EAAGR;AANX,MADD,CADC;AAAA,GALH,CADD,CADD,CADD,EAuBC,4BAAC,8BAAD,QACC,4BAAC,qBAAD;AAAW,IAAA,KAAK,EAAG,cAAI,SAAJ;AAAnB,KACC,4BAAC,yBAAD;AACC,IAAA,KAAK,EAAG,cAAI,MAAJ,CADT;AAEC,IAAA,KAAK,EAAGV,IAFT,CAGC;AAHD;AAIC,IAAA,QAAQ,EAAKe,KAAF,IACVhB,aAAa,CAAE;AACdC,MAAAA,IAAI,EAAEe;AADQ,KAAF,CALf;AASC,IAAA,OAAO,EAAGL;AATX,IADD,CADD,CAvBD,EAsCG,CAAER,0BAAF,IAAgC,4BAAC,2BAAD;AAAoB,IAAA,SAAS;AAA7B,IAtCnC,EAwCE;AACA;AACAA,EAAAA,0BAA0B,IACzB,4BAAC,oBAAD;AAAa,IAAA,gBAAgB,EAAGK;AAAhC,IA3CH,CADD;AAiDA;;eAEcV,mB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, _x } from '@wordpress/i18n';\nimport deprecated from '@wordpress/deprecated';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tMenuGroup,\n\tMenuItemsChoice,\n\tPanelBody,\n\tSelectControl,\n\tToolbarDropdownMenu,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { useMemo } from '@wordpress/element';\nimport { BlockControls, InspectorControls } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport InnerBlocks from './inner-blocks';\nimport PlaceholderPreview from '../navigation/edit/placeholder/placeholder-preview';\n\nfunction NavigationAreaBlock( { attributes, setAttributes } ) {\n\tconst { area } = attributes;\n\n\tconst { navigationAreas, hasResolvedNavigationAreas } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecords, hasFinishedResolution } = select(\n\t\t\t\tcoreStore\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tnavigationAreas: getEntityRecords( 'root', 'navigationArea' ),\n\t\t\t\thasResolvedNavigationAreas: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t[ 'root', 'navigationArea' ]\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t);\n\tconst navigationMenuId = navigationAreas?.length\n\t\t? navigationAreas[ area ]\n\t\t: undefined;\n\n\tconst choices = useMemo(\n\t\t() =>\n\t\t\tnavigationAreas?.map( ( { name, description } ) => ( {\n\t\t\t\tlabel: description,\n\t\t\t\tvalue: name,\n\t\t\t} ) ),\n\t\t[ navigationAreas ]\n\t);\n\n\tdeprecated( 'wp.blockLibrary.NavigationArea', {\n\t\tsince: '12.0',\n\t\tplugin: 'gutenberg',\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls>\n\t\t\t\t<ToolbarGroup>\n\t\t\t\t\t<ToolbarDropdownMenu\n\t\t\t\t\t\tlabel={ __( 'Select Area' ) }\n\t\t\t\t\t\ttext={ __( 'Select Area' ) }\n\t\t\t\t\t\ticon={ null }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItemsChoice\n\t\t\t\t\t\t\t\t\tvalue={ area }\n\t\t\t\t\t\t\t\t\tonSelect={ ( selectedArea ) => {\n\t\t\t\t\t\t\t\t\t\tsetAttributes( { area: selectedArea } );\n\t\t\t\t\t\t\t\t\t\tonClose();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tchoices={ choices }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</ToolbarDropdownMenu>\n\t\t\t\t</ToolbarGroup>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls>\n\t\t\t\t<PanelBody title={ __( 'Options' ) }>\n\t\t\t\t\t<SelectControl\n\t\t\t\t\t\tlabel={ _x( 'Area' ) }\n\t\t\t\t\t\tvalue={ area }\n\t\t\t\t\t\t// `undefined` is required for the preload attribute to be unset.\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tarea: value,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\toptions={ choices }\n\t\t\t\t\t/>\n\t\t\t\t</PanelBody>\n\t\t\t</InspectorControls>\n\t\t\t{ ! hasResolvedNavigationAreas && <PlaceholderPreview isLoading /> }\n\t\t\t{\n\t\t\t\t// Render inner blocks only when navigationMenuId is known so\n\t\t\t\t// that inner blocks template is correct from the start.\n\t\t\t\thasResolvedNavigationAreas && (\n\t\t\t\t\t<InnerBlocks navigationMenuId={ navigationMenuId } />\n\t\t\t\t)\n\t\t\t}\n\t\t</>\n\t);\n}\n\nexport default NavigationAreaBlock;\n"]}