@wordpress/block-library 6.0.12 → 6.0.16

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 (139) hide show
  1. package/build/group/edit.native.js +1 -1
  2. package/build/group/edit.native.js.map +1 -1
  3. package/build/group/index.js +3 -1
  4. package/build/group/index.js.map +1 -1
  5. package/build/image/image.js +30 -6
  6. package/build/image/image.js.map +1 -1
  7. package/build/navigation/deprecated.js +1 -3
  8. package/build/navigation/deprecated.js.map +1 -1
  9. package/build/navigation/edit/index.js +109 -43
  10. package/build/navigation/edit/index.js.map +1 -1
  11. package/build/navigation/edit/navigation-menu-selector.js +10 -3
  12. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  13. package/build/navigation/edit/placeholder/index.js +15 -7
  14. package/build/navigation/edit/placeholder/index.js.map +1 -1
  15. package/build/navigation/edit/responsive-wrapper.js +9 -7
  16. package/build/navigation/edit/responsive-wrapper.js.map +1 -1
  17. package/build/navigation/edit/unsaved-inner-blocks.js +3 -11
  18. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  19. package/build/navigation/edit/use-navigation-notice.js +54 -0
  20. package/build/navigation/edit/use-navigation-notice.js.map +1 -0
  21. package/build/navigation/index.js +1 -2
  22. package/build/navigation/index.js.map +1 -1
  23. package/build/navigation/menu-items-to-blocks.js +4 -1
  24. package/build/navigation/menu-items-to-blocks.js.map +1 -1
  25. package/build/navigation/use-navigation-menu.js +9 -2
  26. package/build/navigation/use-navigation-menu.js.map +1 -1
  27. package/build/navigation/view.js +14 -9
  28. package/build/navigation/view.js.map +1 -1
  29. package/build/navigation-submenu/edit.js +1 -1
  30. package/build/navigation-submenu/edit.js.map +1 -1
  31. package/build/post-comments/index.js +1 -1
  32. package/build/post-template/edit.js +54 -13
  33. package/build/post-template/edit.js.map +1 -1
  34. package/build/site-logo/edit.js +9 -6
  35. package/build/site-logo/edit.js.map +1 -1
  36. package/build/site-logo/index.js +0 -3
  37. package/build/site-logo/index.js.map +1 -1
  38. package/build/template-part/edit/index.js +7 -1
  39. package/build/template-part/edit/index.js.map +1 -1
  40. package/build-module/group/edit.native.js +1 -1
  41. package/build-module/group/edit.native.js.map +1 -1
  42. package/build-module/group/index.js +3 -1
  43. package/build-module/group/index.js.map +1 -1
  44. package/build-module/image/image.js +31 -7
  45. package/build-module/image/image.js.map +1 -1
  46. package/build-module/navigation/deprecated.js +1 -3
  47. package/build-module/navigation/deprecated.js.map +1 -1
  48. package/build-module/navigation/edit/index.js +107 -44
  49. package/build-module/navigation/edit/index.js.map +1 -1
  50. package/build-module/navigation/edit/navigation-menu-selector.js +9 -3
  51. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  52. package/build-module/navigation/edit/placeholder/index.js +15 -7
  53. package/build-module/navigation/edit/placeholder/index.js.map +1 -1
  54. package/build-module/navigation/edit/responsive-wrapper.js +9 -7
  55. package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
  56. package/build-module/navigation/edit/unsaved-inner-blocks.js +4 -13
  57. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  58. package/build-module/navigation/edit/use-navigation-notice.js +44 -0
  59. package/build-module/navigation/edit/use-navigation-notice.js.map +1 -0
  60. package/build-module/navigation/index.js +1 -2
  61. package/build-module/navigation/index.js.map +1 -1
  62. package/build-module/navigation/menu-items-to-blocks.js +3 -1
  63. package/build-module/navigation/menu-items-to-blocks.js.map +1 -1
  64. package/build-module/navigation/use-navigation-menu.js +9 -2
  65. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  66. package/build-module/navigation/view.js +14 -9
  67. package/build-module/navigation/view.js.map +1 -1
  68. package/build-module/navigation-submenu/edit.js +1 -1
  69. package/build-module/navigation-submenu/edit.js.map +1 -1
  70. package/build-module/post-comments/index.js +1 -1
  71. package/build-module/post-template/edit.js +54 -15
  72. package/build-module/post-template/edit.js.map +1 -1
  73. package/build-module/site-logo/edit.js +9 -6
  74. package/build-module/site-logo/edit.js.map +1 -1
  75. package/build-module/site-logo/index.js +0 -3
  76. package/build-module/site-logo/index.js.map +1 -1
  77. package/build-module/template-part/edit/index.js +6 -1
  78. package/build-module/template-part/edit/index.js.map +1 -1
  79. package/build-style/common-rtl.css +10 -0
  80. package/build-style/common.css +10 -0
  81. package/build-style/editor-rtl.css +38 -11
  82. package/build-style/editor.css +38 -11
  83. package/build-style/image/editor-rtl.css +16 -0
  84. package/build-style/image/editor.css +16 -0
  85. package/build-style/navigation/editor-rtl.css +11 -0
  86. package/build-style/navigation/editor.css +11 -0
  87. package/build-style/navigation/style-rtl.css +56 -24
  88. package/build-style/navigation/style.css +56 -24
  89. package/build-style/post-comments/style-rtl.css +3 -1
  90. package/build-style/post-comments/style.css +3 -1
  91. package/build-style/post-comments-form/style-rtl.css +2 -2
  92. package/build-style/post-comments-form/style.css +2 -2
  93. package/build-style/site-logo/editor-rtl.css +1 -11
  94. package/build-style/site-logo/editor.css +1 -11
  95. package/build-style/site-logo/style-rtl.css +3 -1
  96. package/build-style/site-logo/style.css +3 -1
  97. package/build-style/style-rtl.css +74 -28
  98. package/build-style/style.css +74 -28
  99. package/package.json +14 -14
  100. package/src/common.scss +12 -0
  101. package/src/editor.scss +12 -0
  102. package/src/gallery/index.php +7 -8
  103. package/src/group/block.json +3 -1
  104. package/src/group/edit.native.js +1 -1
  105. package/src/home-link/index.php +1 -1
  106. package/src/image/editor.scss +18 -0
  107. package/src/image/image.js +32 -8
  108. package/src/image/index.php +1 -1
  109. package/src/navigation/block.json +1 -2
  110. package/src/navigation/deprecated.js +0 -2
  111. package/src/navigation/edit/index.js +166 -60
  112. package/src/navigation/edit/navigation-menu-selector.js +20 -6
  113. package/src/navigation/edit/placeholder/index.js +40 -24
  114. package/src/navigation/edit/responsive-wrapper.js +10 -7
  115. package/src/navigation/edit/unsaved-inner-blocks.js +13 -25
  116. package/src/navigation/edit/use-navigation-notice.js +37 -0
  117. package/src/navigation/editor.scss +14 -0
  118. package/src/navigation/index.php +19 -8
  119. package/src/navigation/menu-items-to-blocks.js +7 -1
  120. package/src/navigation/style.scss +82 -32
  121. package/src/navigation/use-navigation-menu.js +20 -0
  122. package/src/navigation/view.js +15 -9
  123. package/src/navigation-link/index.php +1 -1
  124. package/src/navigation-submenu/edit.js +1 -1
  125. package/src/navigation-submenu/index.php +9 -3
  126. package/src/page-list/index.php +9 -4
  127. package/src/post-comments/block.json +5 -1
  128. package/src/post-comments/index.php +17 -0
  129. package/src/post-comments/style.scss +7 -3
  130. package/src/post-comments-form/index.php +6 -4
  131. package/src/post-comments-form/style.scss +7 -5
  132. package/src/post-template/edit.js +54 -17
  133. package/src/site-logo/block.json +0 -3
  134. package/src/site-logo/edit.js +6 -5
  135. package/src/site-logo/editor.scss +1 -15
  136. package/src/site-logo/index.php +0 -4
  137. package/src/site-logo/style.scss +3 -1
  138. package/src/template-part/edit/index.js +6 -1
  139. package/src/template-part/index.php +5 -2
@@ -6,12 +6,12 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { useState, useMemo } from '@wordpress/element';
9
+ import { memo, useMemo, useState } from '@wordpress/element';
10
10
  import { useSelect } from '@wordpress/data';
11
11
  import { __ } from '@wordpress/i18n';
12
12
  import {
13
13
  BlockContextProvider,
14
- BlockPreview,
14
+ __experimentalUseBlockPreview as useBlockPreview,
15
15
  useBlockProps,
16
16
  useInnerBlocksProps,
17
17
  store as blockEditorStore,
@@ -30,6 +30,39 @@ function PostTemplateInnerBlocks() {
30
30
  return <li { ...innerBlocksProps } />;
31
31
  }
32
32
 
33
+ function PostTemplateBlockPreview( {
34
+ blocks,
35
+ blockContextId,
36
+ isHidden,
37
+ setActiveBlockContextId,
38
+ } ) {
39
+ const blockPreviewProps = useBlockPreview( {
40
+ blocks,
41
+ } );
42
+
43
+ const handleOnClick = () => {
44
+ setActiveBlockContextId( blockContextId );
45
+ };
46
+
47
+ const style = {
48
+ display: isHidden ? 'none' : undefined,
49
+ };
50
+
51
+ return (
52
+ <li
53
+ { ...blockPreviewProps }
54
+ tabIndex={ 0 }
55
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-to-interactive-role
56
+ role="button"
57
+ onClick={ handleOnClick }
58
+ onKeyPress={ handleOnClick }
59
+ style={ style }
60
+ />
61
+ );
62
+ }
63
+
64
+ const MemoizedPostTemplateBlockPreview = memo( PostTemplateBlockPreview );
65
+
33
66
  export default function PostTemplateEdit( {
34
67
  clientId,
35
68
  context: {
@@ -53,7 +86,7 @@ export default function PostTemplateEdit( {
53
86
  },
54
87
  } ) {
55
88
  const [ { page } ] = queryContext;
56
- const [ activeBlockContext, setActiveBlockContext ] = useState();
89
+ const [ activeBlockContextId, setActiveBlockContextId ] = useState();
57
90
 
58
91
  const { posts, blocks } = useSelect(
59
92
  ( select ) => {
@@ -115,7 +148,6 @@ export default function PostTemplateEdit( {
115
148
  templateSlug,
116
149
  ]
117
150
  );
118
-
119
151
  const blockContexts = useMemo(
120
152
  () =>
121
153
  posts?.map( ( post ) => ( {
@@ -144,6 +176,10 @@ export default function PostTemplateEdit( {
144
176
  return <p { ...blockProps }> { __( 'No results found.' ) }</p>;
145
177
  }
146
178
 
179
+ // To avoid flicker when switching active block contexts, a preview is rendered
180
+ // for each block context, but the preview for the active block context is hidden.
181
+ // This ensures that when it is displayed again, the cached rendering of the
182
+ // block preview is used, instead of having to re-render the preview from scratch.
147
183
  return (
148
184
  <ul { ...blockProps }>
149
185
  { blockContexts &&
@@ -152,20 +188,21 @@ export default function PostTemplateEdit( {
152
188
  key={ blockContext.postId }
153
189
  value={ blockContext }
154
190
  >
155
- { blockContext ===
156
- ( activeBlockContext || blockContexts[ 0 ] ) ? (
191
+ { blockContext.postId ===
192
+ ( activeBlockContextId ||
193
+ blockContexts[ 0 ]?.postId ) ? (
157
194
  <PostTemplateInnerBlocks />
158
- ) : (
159
- <li>
160
- <BlockPreview
161
- blocks={ blocks }
162
- __experimentalLive
163
- __experimentalOnClick={ () =>
164
- setActiveBlockContext( blockContext )
165
- }
166
- />
167
- </li>
168
- ) }
195
+ ) : null }
196
+ <MemoizedPostTemplateBlockPreview
197
+ blocks={ blocks }
198
+ blockContextId={ blockContext.postId }
199
+ setActiveBlockContextId={ setActiveBlockContextId }
200
+ isHidden={
201
+ blockContext.postId ===
202
+ ( activeBlockContextId ||
203
+ blockContexts[ 0 ]?.postId )
204
+ }
205
+ />
169
206
  </BlockContextProvider>
170
207
  ) ) }
171
208
  </ul>
@@ -6,9 +6,6 @@
6
6
  "description": "Display a graphic to represent this site. Update the block, and the changes apply everywhere it’s used. This is different than the site icon, which is the smaller image visible in your dashboard, browser tabs, etc used to help others recognize this site.",
7
7
  "textdomain": "default",
8
8
  "attributes": {
9
- "align": {
10
- "type": "string"
11
- },
12
9
  "width": {
13
10
  "type": "number"
14
11
  },
@@ -142,7 +142,11 @@ const SiteLogo = ( {
142
142
  return <div style={ { width, height } }>{ imgWrapper }</div>;
143
143
  }
144
144
 
145
- const currentWidth = width || imageWidthWithinContainer;
145
+ // Set the default width to a responsible size.
146
+ // Note that this width is also set in the attached frontend CSS file.
147
+ const defaultWidth = 120;
148
+
149
+ const currentWidth = width || defaultWidth;
146
150
  const ratio = naturalWidth / naturalHeight;
147
151
  const currentHeight = currentWidth / ratio;
148
152
  const minWidth = naturalWidth < naturalHeight ? MIN_SIZE : MIN_SIZE * ratio;
@@ -160,10 +164,6 @@ const SiteLogo = ( {
160
164
  // becomes available.
161
165
  const maxWidthBuffer = maxWidth * 2.5;
162
166
 
163
- // Set the default width to a responsible size.
164
- // Note that this width is also set in the attached CSS file.
165
- const defaultWidth = 120;
166
-
167
167
  let showRightHandle = false;
168
168
  let showLeftHandle = false;
169
169
 
@@ -383,6 +383,7 @@ export default function LogoEdit( {
383
383
  const onRemoveLogo = () => {
384
384
  setLogo( null );
385
385
  setLogoUrl( undefined );
386
+ setAttributes( { width: undefined } );
386
387
  };
387
388
 
388
389
  const { createErrorNotice } = useDispatch( noticesStore );
@@ -1,7 +1,7 @@
1
1
  .wp-block[data-align="center"] > .wp-block-site-logo {
2
+ display: table;
2
3
  margin-left: auto;
3
4
  margin-right: auto;
4
- text-align: center;
5
5
  }
6
6
 
7
7
  .wp-block-site-logo {
@@ -10,20 +10,6 @@
10
10
  pointer-events: none;
11
11
  }
12
12
 
13
- &:not(.is-default-size) {
14
- display: table;
15
- }
16
-
17
- // Provide a sane starting point for the size.
18
- &.is-default-size {
19
- width: 120px;
20
-
21
- img {
22
- height: auto;
23
- width: 100%;
24
- }
25
- }
26
-
27
13
  .custom-logo-link {
28
14
  cursor: inherit;
29
15
 
@@ -48,10 +48,6 @@ function render_block_core_site_logo( $attributes ) {
48
48
  $classnames[] = $attributes['className'];
49
49
  }
50
50
 
51
- if ( ! empty( $attributes['align'] ) && in_array( $attributes['align'], array( 'center', 'left', 'right' ), true ) ) {
52
- $classnames[] = "align{$attributes['align']}";
53
- }
54
-
55
51
  if ( empty( $attributes['width'] ) ) {
56
52
  $classnames[] = 'is-default-size';
57
53
  }
@@ -18,7 +18,9 @@
18
18
  }
19
19
 
20
20
  &.aligncenter {
21
- display: table;
21
+ margin-left: auto;
22
+ margin-right: auto;
23
+ text-align: center;
22
24
  }
23
25
 
24
26
  // Style variations
@@ -1,3 +1,8 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { isEmpty } from 'lodash';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
@@ -99,7 +104,7 @@ export default function TemplatePartEdit( {
99
104
  return {
100
105
  innerBlocks: getBlocks( clientId ),
101
106
  isResolved: hasResolvedEntity,
102
- isMissing: hasResolvedEntity && ! entityRecord,
107
+ isMissing: hasResolvedEntity && isEmpty( entityRecord ),
103
108
  defaultWrapper: defaultWrapperElement || 'div',
104
109
  area: _area,
105
110
  enableSelection: _enableSelection,
@@ -64,8 +64,11 @@ function render_block_core_template_part( $attributes ) {
64
64
  } else {
65
65
  // Else, if the template part was provided by the active theme,
66
66
  // render the corresponding file content.
67
- $theme_folders = get_block_theme_folders();
68
- $template_part_file_path = get_theme_file_path( '/' . $theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
67
+ $parent_theme_folders = get_block_theme_folders( get_template() );
68
+ $child_theme_folders = get_block_theme_folders( get_stylesheet() );
69
+ $child_theme_part_file_path = get_theme_file_path( '/' . $child_theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
70
+ $parent_theme_part_file_path = get_theme_file_path( '/' . $parent_theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' );
71
+ $template_part_file_path = 0 === validate_file( $attributes['slug'] ) && file_exists( $child_theme_part_file_path ) ? $child_theme_part_file_path : $parent_theme_part_file_path;
69
72
  if ( 0 === validate_file( $attributes['slug'] ) && file_exists( $template_part_file_path ) ) {
70
73
  $content = file_get_contents( $template_part_file_path );
71
74
  $content = is_string( $content ) && '' !== $content