@wordpress/block-library 8.19.10 → 8.19.12
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.
- package/build/image/image.js +2 -2
- package/build/image/image.js.map +1 -1
- package/build/image/view.js +6 -6
- package/build/image/view.js.map +1 -1
- package/build/pattern/edit.js +1 -1
- package/build/pattern/edit.js.map +1 -1
- package/build/query/edit/enhanced-pagination-modal.js +25 -13
- package/build/query/edit/enhanced-pagination-modal.js.map +1 -1
- package/build/query/edit/inspector-controls/enhanced-pagination-control.js +15 -16
- package/build/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -1
- package/build/query/utils.js +27 -8
- package/build/query/utils.js.map +1 -1
- package/build/query/view.js +4 -2
- package/build/query/view.js.map +1 -1
- package/build-module/image/image.js +2 -2
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/view.js +6 -6
- package/build-module/image/view.js.map +1 -1
- package/build-module/pattern/edit.js +1 -1
- package/build-module/pattern/edit.js.map +1 -1
- package/build-module/query/edit/enhanced-pagination-modal.js +26 -14
- package/build-module/query/edit/enhanced-pagination-modal.js.map +1 -1
- package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js +17 -18
- package/build-module/query/edit/inspector-controls/enhanced-pagination-control.js.map +1 -1
- package/build-module/query/utils.js +25 -6
- package/build-module/query/utils.js.map +1 -1
- package/build-module/query/view.js +4 -2
- package/build-module/query/view.js.map +1 -1
- package/build-style/image/style-rtl.css +16 -10
- package/build-style/image/style.css +16 -10
- package/build-style/query/style-rtl.css +0 -10
- package/build-style/query/style.css +0 -10
- package/build-style/style-rtl.css +16 -10
- package/build-style/style.css +16 -10
- package/package.json +32 -32
- package/src/image/image.js +2 -2
- package/src/image/index.php +3 -4
- package/src/image/style.scss +15 -10
- package/src/image/view.js +6 -6
- package/src/pattern/edit.js +1 -1
- package/src/query/edit/enhanced-pagination-modal.js +35 -21
- package/src/query/edit/inspector-controls/enhanced-pagination-control.js +19 -32
- package/src/query/index.php +98 -9
- package/src/query/style.scss +0 -11
- package/src/query/utils.js +26 -12
- package/src/query/view.js +11 -2
- package/src/query-pagination-next/index.php +1 -1
- package/src/query-pagination-previous/index.php +1 -1
package/src/query/index.php
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @since 6.4.0
|
|
12
12
|
*
|
|
13
|
-
* @param array
|
|
14
|
-
* @param string
|
|
15
|
-
* @param
|
|
13
|
+
* @param array $attributes Block attributes.
|
|
14
|
+
* @param string $content Block default content.
|
|
15
|
+
* @param WP_Block $block The block instance.
|
|
16
16
|
*
|
|
17
17
|
* @return string Returns the modified output of the query block.
|
|
18
18
|
*/
|
|
19
19
|
function render_block_core_query( $attributes, $content, $block ) {
|
|
20
|
-
if ( $attributes['enhancedPagination'] ) {
|
|
20
|
+
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) {
|
|
21
21
|
$p = new WP_HTML_Tag_Processor( $content );
|
|
22
22
|
if ( $p->next_tag() ) {
|
|
23
23
|
// Add the necessary directives.
|
|
@@ -48,7 +48,7 @@ function render_block_core_query( $attributes, $content, $block ) {
|
|
|
48
48
|
$content = substr_replace(
|
|
49
49
|
$content,
|
|
50
50
|
'<div
|
|
51
|
-
class="wp-block-query__enhanced-pagination-navigation-announce"
|
|
51
|
+
class="wp-block-query__enhanced-pagination-navigation-announce screen-reader-text"
|
|
52
52
|
aria-live="polite"
|
|
53
53
|
data-wp-text="context.core.query.message"
|
|
54
54
|
></div>
|
|
@@ -67,11 +67,14 @@ function render_block_core_query( $attributes, $content, $block ) {
|
|
|
67
67
|
if ( ! wp_script_is( $view_asset ) ) {
|
|
68
68
|
$script_handles = $block->block_type->view_script_handles;
|
|
69
69
|
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
70
|
-
if (
|
|
70
|
+
if (
|
|
71
|
+
( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
|
|
72
|
+
&& in_array( $view_asset, $script_handles, true )
|
|
73
|
+
) {
|
|
71
74
|
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
|
|
72
75
|
}
|
|
73
76
|
// If the script is needed, but it was previously removed, add it again.
|
|
74
|
-
if ( $attributes['enhancedPagination'] && ! in_array( $view_asset, $script_handles, true ) ) {
|
|
77
|
+
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $view_asset, $script_handles, true ) ) {
|
|
75
78
|
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
|
|
76
79
|
}
|
|
77
80
|
}
|
|
@@ -80,11 +83,14 @@ function render_block_core_query( $attributes, $content, $block ) {
|
|
|
80
83
|
if ( ! wp_style_is( $style_asset ) ) {
|
|
81
84
|
$style_handles = $block->block_type->style_handles;
|
|
82
85
|
// If the styles are not needed, and they are still in the `style_handles`, remove them.
|
|
83
|
-
if (
|
|
86
|
+
if (
|
|
87
|
+
( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
|
|
88
|
+
&& in_array( $style_asset, $style_handles, true )
|
|
89
|
+
) {
|
|
84
90
|
$block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
|
|
85
91
|
}
|
|
86
92
|
// If the styles are needed, but they were previously removed, add them again.
|
|
87
|
-
if ( $attributes['enhancedPagination'] && ! in_array( $style_asset, $style_handles, true ) ) {
|
|
93
|
+
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $style_asset, $style_handles, true ) ) {
|
|
88
94
|
$block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
|
|
89
95
|
}
|
|
90
96
|
}
|
|
@@ -123,3 +129,86 @@ function register_block_core_query() {
|
|
|
123
129
|
);
|
|
124
130
|
}
|
|
125
131
|
add_action( 'init', 'register_block_core_query' );
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Traverse the tree of blocks looking for any plugin block (i.e., a block from
|
|
135
|
+
* an installed plugin) inside a Query block with the enhanced pagination
|
|
136
|
+
* enabled. If at least one is found, the enhanced pagination is effectively
|
|
137
|
+
* disabled to prevent any potential incompatibilities.
|
|
138
|
+
*
|
|
139
|
+
* @since 6.4.0
|
|
140
|
+
*
|
|
141
|
+
* @param array $parsed_block The block being rendered.
|
|
142
|
+
* @return string Returns the parsed block, unmodified.
|
|
143
|
+
*/
|
|
144
|
+
function block_core_query_disable_enhanced_pagination( $parsed_block ) {
|
|
145
|
+
static $enhanced_query_stack = array();
|
|
146
|
+
static $dirty_enhanced_queries = array();
|
|
147
|
+
static $render_query_callback = null;
|
|
148
|
+
|
|
149
|
+
$block_name = $parsed_block['blockName'];
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
'core/query' === $block_name &&
|
|
153
|
+
isset( $parsed_block['attrs']['enhancedPagination'] ) &&
|
|
154
|
+
true === $parsed_block['attrs']['enhancedPagination'] &&
|
|
155
|
+
isset( $parsed_block['attrs']['queryId'] )
|
|
156
|
+
) {
|
|
157
|
+
$enhanced_query_stack[] = $parsed_block['attrs']['queryId'];
|
|
158
|
+
|
|
159
|
+
if ( ! isset( $render_query_callback ) ) {
|
|
160
|
+
/**
|
|
161
|
+
* Filter that disables the enhanced pagination feature during block
|
|
162
|
+
* rendering when a plugin block has been found inside. It does so
|
|
163
|
+
* by adding an attribute called `data-wp-navigation-disabled` which
|
|
164
|
+
* is later handled by the front-end logic.
|
|
165
|
+
*
|
|
166
|
+
* @param string $content The block content.
|
|
167
|
+
* @param array $block The full block, including name and attributes.
|
|
168
|
+
* @return string Returns the modified output of the query block.
|
|
169
|
+
*/
|
|
170
|
+
$render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {
|
|
171
|
+
$has_enhanced_pagination =
|
|
172
|
+
isset( $block['attrs']['enhancedPagination'] ) &&
|
|
173
|
+
true === $block['attrs']['enhancedPagination'] &&
|
|
174
|
+
isset( $block['attrs']['queryId'] );
|
|
175
|
+
|
|
176
|
+
if ( ! $has_enhanced_pagination ) {
|
|
177
|
+
return $content;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if ( isset( $dirty_enhanced_queries[ $block['attrs']['queryId'] ] ) ) {
|
|
181
|
+
$p = new WP_HTML_Tag_Processor( $content );
|
|
182
|
+
if ( $p->next_tag() ) {
|
|
183
|
+
$p->set_attribute( 'data-wp-navigation-disabled', 'true' );
|
|
184
|
+
}
|
|
185
|
+
$content = $p->get_updated_html();
|
|
186
|
+
$dirty_enhanced_queries[ $block['attrs']['queryId'] ] = null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
array_pop( $enhanced_query_stack );
|
|
190
|
+
|
|
191
|
+
if ( empty( $enhanced_query_stack ) ) {
|
|
192
|
+
remove_filter( 'render_block_core/query', $render_query_callback );
|
|
193
|
+
$render_query_callback = null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return $content;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
add_filter( 'render_block_core/query', $render_query_callback, 10, 2 );
|
|
200
|
+
}
|
|
201
|
+
} elseif (
|
|
202
|
+
! empty( $enhanced_query_stack ) &&
|
|
203
|
+
isset( $block_name ) &&
|
|
204
|
+
( ! str_starts_with( $block_name, 'core/' ) || 'core/post-content' === $block_name )
|
|
205
|
+
) {
|
|
206
|
+
foreach ( $enhanced_query_stack as $query_id ) {
|
|
207
|
+
$dirty_enhanced_queries[ $query_id ] = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return $parsed_block;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
add_filter( 'render_block_data', 'block_core_query_disable_enhanced_pagination', 10, 1 );
|
package/src/query/style.scss
CHANGED
package/src/query/utils.js
CHANGED
|
@@ -346,29 +346,43 @@ export const usePatterns = ( clientId, name ) => {
|
|
|
346
346
|
};
|
|
347
347
|
|
|
348
348
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
349
|
+
* The object returned by useUnsupportedBlocks with info about the type of
|
|
350
|
+
* unsupported blocks present inside the Query block.
|
|
351
|
+
*
|
|
352
|
+
* @typedef {Object} UnsupportedBlocksInfo
|
|
353
|
+
* @property {boolean} hasBlocksFromPlugins True if blocks from plugins are present.
|
|
354
|
+
* @property {boolean} hasPostContentBlock True if a 'core/post-content' block is present.
|
|
355
|
+
* @property {boolean} hasUnsupportedBlocks True if there are any unsupported blocks.
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Hook that returns an object with information about the unsupported blocks
|
|
360
|
+
* present inside a Query Loop with the given `clientId`. The returned object
|
|
361
|
+
* contains props that are true when a certain type of unsupported block is
|
|
362
|
+
* present.
|
|
351
363
|
*
|
|
352
364
|
* @param {string} clientId The block's client ID.
|
|
353
|
-
* @return {
|
|
365
|
+
* @return {UnsupportedBlocksInfo} The object containing the information.
|
|
354
366
|
*/
|
|
355
|
-
export const
|
|
367
|
+
export const useUnsupportedBlocks = ( clientId ) => {
|
|
356
368
|
return useSelect(
|
|
357
369
|
( select ) => {
|
|
358
370
|
const { getClientIdsOfDescendants, getBlockName } =
|
|
359
371
|
select( blockEditorStore );
|
|
360
|
-
|
|
361
|
-
|
|
372
|
+
const blocks = {};
|
|
373
|
+
getClientIdsOfDescendants( clientId ).forEach(
|
|
362
374
|
( descendantClientId ) => {
|
|
363
375
|
const blockName = getBlockName( descendantClientId );
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
);
|
|
376
|
+
if ( ! blockName.startsWith( 'core/' ) ) {
|
|
377
|
+
blocks.hasBlocksFromPlugins = true;
|
|
378
|
+
} else if ( blockName === 'core/post-content' ) {
|
|
379
|
+
blocks.hasPostContentBlock = true;
|
|
380
|
+
}
|
|
370
381
|
}
|
|
371
382
|
);
|
|
383
|
+
blocks.hasUnsupportedBlocks =
|
|
384
|
+
blocks.hasBlocksFromPlugins || blocks.hasPostContentBlock;
|
|
385
|
+
return blocks;
|
|
372
386
|
},
|
|
373
387
|
[ clientId ]
|
|
374
388
|
);
|
package/src/query/view.js
CHANGED
|
@@ -33,7 +33,14 @@ store( {
|
|
|
33
33
|
core: {
|
|
34
34
|
query: {
|
|
35
35
|
navigate: async ( { event, ref, context } ) => {
|
|
36
|
-
|
|
36
|
+
const isDisabled = ref.closest( '[data-wp-navigation-id]' )
|
|
37
|
+
?.dataset.wpNavigationDisabled;
|
|
38
|
+
|
|
39
|
+
if (
|
|
40
|
+
isValidLink( ref ) &&
|
|
41
|
+
isValidEvent( event ) &&
|
|
42
|
+
! isDisabled
|
|
43
|
+
) {
|
|
37
44
|
event.preventDefault();
|
|
38
45
|
|
|
39
46
|
const id = ref.closest( '[data-wp-navigation-id]' )
|
|
@@ -70,7 +77,9 @@ store( {
|
|
|
70
77
|
}
|
|
71
78
|
},
|
|
72
79
|
prefetch: async ( { ref } ) => {
|
|
73
|
-
|
|
80
|
+
const isDisabled = ref.closest( '[data-wp-navigation-id]' )
|
|
81
|
+
?.dataset.wpNavigationDisabled;
|
|
82
|
+
if ( isValidLink( ref ) && ! isDisabled ) {
|
|
74
83
|
await prefetch( ref.href );
|
|
75
84
|
}
|
|
76
85
|
},
|
|
@@ -63,7 +63,7 @@ function render_block_core_query_pagination_next( $attributes, $content, $block
|
|
|
63
63
|
wp_reset_postdata(); // Restore original Post Data.
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
if ( $enhanced_pagination ) {
|
|
66
|
+
if ( $enhanced_pagination && isset( $content ) ) {
|
|
67
67
|
$p = new WP_HTML_Tag_Processor( $content );
|
|
68
68
|
if ( $p->next_tag(
|
|
69
69
|
array(
|
|
@@ -51,7 +51,7 @@ function render_block_core_query_pagination_previous( $attributes, $content, $bl
|
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
if ( $enhanced_pagination ) {
|
|
54
|
+
if ( $enhanced_pagination && isset( $content ) ) {
|
|
55
55
|
$p = new WP_HTML_Tag_Processor( $content );
|
|
56
56
|
if ( $p->next_tag(
|
|
57
57
|
array(
|