@wordpress/block-library 9.30.1-next.836ecdcae.0 → 9.30.1-next.a730c9c8c.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.
- package/build/button/edit.js +6 -1
- package/build/button/edit.js.map +1 -1
- package/build/button/edit.native.js +1 -1
- package/build/button/edit.native.js.map +1 -1
- package/build/buttons/index.js +2 -1
- package/build/buttons/index.js.map +1 -1
- package/build/categories/edit.js +3 -1
- package/build/categories/edit.js.map +1 -1
- package/build/image/edit.native.js +1 -1
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +5 -8
- package/build/image/image.js.map +1 -1
- package/build/image/save.js +6 -2
- package/build/image/save.js.map +1 -1
- package/build/index.js +4 -0
- package/build/index.js.map +1 -1
- package/build/navigation/edit/index.js +0 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation-link/block-inserter.js +69 -0
- package/build/navigation-link/block-inserter.js.map +1 -0
- package/build/navigation-link/dialog-wrapper.js +80 -0
- package/build/navigation-link/dialog-wrapper.js.map +1 -0
- package/build/navigation-link/link-ui.js +34 -82
- package/build/navigation-link/link-ui.js.map +1 -1
- package/build/navigation-link/page-creator.js +12 -18
- package/build/navigation-link/page-creator.js.map +1 -1
- package/build/post-date/edit.js +2 -1
- package/build/post-date/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +7 -2
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-title/edit.js +8 -2
- package/build/post-title/edit.js.map +1 -1
- package/build/query/edit/pattern-selection.js +9 -1
- package/build/query/edit/pattern-selection.js.map +1 -1
- package/build/query/index.js +2 -1
- package/build/query/index.js.map +1 -1
- package/build/rss/edit.js +6 -1
- package/build/rss/edit.js.map +1 -1
- package/build/site-tagline/index.js +1 -0
- package/build/site-tagline/index.js.map +1 -1
- package/build/social-link/edit.js +6 -1
- package/build/social-link/edit.js.map +1 -1
- package/build/social-links/index.js +2 -1
- package/build/social-links/index.js.map +1 -1
- package/build/spacer/edit.js +2 -1
- package/build/spacer/edit.js.map +1 -1
- package/build/table-of-contents/edit.js +33 -9
- package/build/table-of-contents/edit.js.map +1 -1
- package/build/table-of-contents/index.js +4 -0
- package/build/table-of-contents/index.js.map +1 -1
- package/build/table-of-contents/list.js +6 -3
- package/build/table-of-contents/list.js.map +1 -1
- package/build/table-of-contents/save.js +6 -3
- package/build/table-of-contents/save.js.map +1 -1
- package/build/term-template/edit.js +318 -0
- package/build/term-template/edit.js.map +1 -0
- package/build/term-template/index.js +109 -0
- package/build/term-template/index.js.map +1 -0
- package/build/term-template/save.js +16 -0
- package/build/term-template/save.js.map +1 -0
- package/build/term-template/variations.js +83 -0
- package/build/term-template/variations.js.map +1 -0
- package/build/terms-query/edit.js +20 -0
- package/build/terms-query/edit.js.map +1 -0
- package/build/terms-query/index.js +83 -0
- package/build/terms-query/index.js.map +1 -0
- package/build/terms-query/inspector-controls.js +231 -0
- package/build/terms-query/inspector-controls.js.map +1 -0
- package/build/terms-query/save.js +24 -0
- package/build/terms-query/save.js.map +1 -0
- package/build/terms-query/terms-query-content.js +71 -0
- package/build/terms-query/terms-query-content.js.map +1 -0
- package/build/utils/hooks.js +3 -0
- package/build/utils/hooks.js.map +1 -1
- package/build-module/button/edit.js +7 -2
- package/build-module/button/edit.js.map +1 -1
- package/build-module/button/edit.native.js +1 -1
- package/build-module/button/edit.native.js.map +1 -1
- package/build-module/buttons/index.js +2 -1
- package/build-module/buttons/index.js.map +1 -1
- package/build-module/categories/edit.js +3 -1
- package/build-module/categories/edit.js.map +1 -1
- package/build-module/image/edit.native.js +1 -1
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +5 -8
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/save.js +6 -2
- package/build-module/image/save.js.map +1 -1
- package/build-module/index.js +4 -0
- package/build-module/index.js.map +1 -1
- package/build-module/navigation/edit/index.js +0 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation-link/block-inserter.js +61 -0
- package/build-module/navigation-link/block-inserter.js.map +1 -0
- package/build-module/navigation-link/dialog-wrapper.js +75 -0
- package/build-module/navigation-link/dialog-wrapper.js.map +1 -0
- package/build-module/navigation-link/link-ui.js +37 -85
- package/build-module/navigation-link/link-ui.js.map +1 -1
- package/build-module/navigation-link/page-creator.js +12 -19
- package/build-module/navigation-link/page-creator.js.map +1 -1
- package/build-module/post-date/edit.js +3 -2
- package/build-module/post-date/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +9 -4
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-title/edit.js +9 -3
- package/build-module/post-title/edit.js.map +1 -1
- package/build-module/query/edit/pattern-selection.js +9 -1
- package/build-module/query/edit/pattern-selection.js.map +1 -1
- package/build-module/query/index.js +2 -1
- package/build-module/query/index.js.map +1 -1
- package/build-module/rss/edit.js +8 -3
- package/build-module/rss/edit.js.map +1 -1
- package/build-module/site-tagline/index.js +1 -0
- package/build-module/site-tagline/index.js.map +1 -1
- package/build-module/social-link/edit.js +8 -3
- package/build-module/social-link/edit.js.map +1 -1
- package/build-module/social-links/index.js +2 -1
- package/build-module/social-links/index.js.map +1 -1
- package/build-module/spacer/edit.js +3 -2
- package/build-module/spacer/edit.js.map +1 -1
- package/build-module/table-of-contents/edit.js +35 -11
- package/build-module/table-of-contents/edit.js.map +1 -1
- package/build-module/table-of-contents/index.js +4 -0
- package/build-module/table-of-contents/index.js.map +1 -1
- package/build-module/table-of-contents/list.js +6 -3
- package/build-module/table-of-contents/list.js.map +1 -1
- package/build-module/table-of-contents/save.js +6 -3
- package/build-module/table-of-contents/save.js.map +1 -1
- package/build-module/term-template/edit.js +310 -0
- package/build-module/term-template/edit.js.map +1 -0
- package/build-module/term-template/index.js +102 -0
- package/build-module/term-template/index.js.map +1 -0
- package/build-module/term-template/save.js +9 -0
- package/build-module/term-template/save.js.map +1 -0
- package/build-module/term-template/variations.js +76 -0
- package/build-module/term-template/variations.js.map +1 -0
- package/build-module/terms-query/edit.js +12 -0
- package/build-module/terms-query/edit.js.map +1 -0
- package/build-module/terms-query/index.js +76 -0
- package/build-module/terms-query/index.js.map +1 -0
- package/build-module/terms-query/inspector-controls.js +224 -0
- package/build-module/terms-query/inspector-controls.js.map +1 -0
- package/build-module/terms-query/save.js +17 -0
- package/build-module/terms-query/save.js.map +1 -0
- package/build-module/terms-query/terms-query-content.js +63 -0
- package/build-module/terms-query/terms-query-content.js.map +1 -0
- package/build-module/utils/hooks.js +3 -0
- package/build-module/utils/hooks.js.map +1 -1
- package/build-style/editor-rtl.css +24 -0
- package/build-style/editor.css +24 -0
- package/build-style/style-rtl.css +16 -0
- package/build-style/style.css +16 -0
- package/build-style/term-template/editor-rtl.css +160 -0
- package/build-style/term-template/editor.css +160 -0
- package/build-style/term-template/style-rtl.css +146 -0
- package/build-style/term-template/style.css +146 -0
- package/build-style/terms-query/style-rtl.css +140 -0
- package/build-style/terms-query/style.css +140 -0
- package/build-types/table-of-contents/list.d.ts +2 -1
- package/build-types/table-of-contents/list.d.ts.map +1 -1
- package/package.json +35 -35
- package/src/button/edit.js +12 -1
- package/src/button/edit.native.js +1 -1
- package/src/buttons/block.json +2 -1
- package/src/categories/edit.js +2 -1
- package/src/editor.scss +1 -0
- package/src/image/edit.native.js +1 -1
- package/src/image/image.js +5 -8
- package/src/image/save.js +7 -1
- package/src/index.js +4 -0
- package/src/navigation/edit/index.js +0 -1
- package/src/navigation-link/block-inserter.js +65 -0
- package/src/navigation-link/dialog-wrapper.js +74 -0
- package/src/navigation-link/link-ui.js +32 -95
- package/src/navigation-link/page-creator.js +13 -20
- package/src/post-date/edit.js +64 -53
- package/src/post-date/index.php +5 -13
- package/src/post-featured-image/edit.js +19 -3
- package/src/post-title/edit.js +14 -2
- package/src/query/block.json +2 -1
- package/src/query/edit/pattern-selection.js +10 -1
- package/src/rss/edit.js +13 -2
- package/src/site-tagline/block.json +1 -0
- package/src/social-link/edit.js +13 -2
- package/src/social-links/block.json +2 -1
- package/src/spacer/edit.js +5 -1
- package/src/style.scss +2 -0
- package/src/table-of-contents/block.json +4 -0
- package/src/table-of-contents/edit.js +58 -21
- package/src/table-of-contents/list.tsx +7 -2
- package/src/table-of-contents/save.js +7 -3
- package/src/term-template/block.json +73 -0
- package/src/term-template/edit.js +391 -0
- package/src/term-template/editor.scss +26 -0
- package/src/term-template/index.js +26 -0
- package/src/term-template/index.php +224 -0
- package/src/term-template/save.js +8 -0
- package/src/term-template/style.scss +12 -0
- package/src/term-template/variations.js +87 -0
- package/src/terms-query/block.json +49 -0
- package/src/terms-query/edit.js +10 -0
- package/src/terms-query/index.js +24 -0
- package/src/terms-query/index.php +44 -0
- package/src/terms-query/inspector-controls.js +239 -0
- package/src/terms-query/save.js +10 -0
- package/src/terms-query/style.scss +6 -0
- package/src/terms-query/terms-query-content.js +74 -0
- package/src/utils/hooks.js +4 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Server-side rendering of the `core/term-template` block.
|
|
4
|
+
*
|
|
5
|
+
* @package WordPress
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Renders the `core/term-template` block on the server.
|
|
10
|
+
*
|
|
11
|
+
* @since 6.9.0
|
|
12
|
+
*
|
|
13
|
+
* @param array $attributes Block attributes.
|
|
14
|
+
* @param string $content Block default content.
|
|
15
|
+
* @param WP_Block $block Block instance.
|
|
16
|
+
*
|
|
17
|
+
* @return string Returns the output of the term template.
|
|
18
|
+
*/
|
|
19
|
+
function render_block_core_term_template( $attributes, $content, $block ) {
|
|
20
|
+
if ( ! isset( $block->context ) || ! isset( $attributes ) ) {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
$query_block_context = $block->context;
|
|
25
|
+
|
|
26
|
+
if ( empty( $query_block_context['termQuery'] ) ) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
$query = $query_block_context['termQuery'];
|
|
31
|
+
|
|
32
|
+
$query_args = array(
|
|
33
|
+
'taxonomy' => $query['taxonomy'] ?? 'category',
|
|
34
|
+
'number' => $query['perPage'] ?? 10,
|
|
35
|
+
'order' => $query['order'] ?? 'asc',
|
|
36
|
+
'orderby' => $query['orderBy'] ?? 'name',
|
|
37
|
+
'hide_empty' => $query['hideEmpty'] ?? true,
|
|
38
|
+
'include' => $query['include'] ?? array(),
|
|
39
|
+
'exclude' => $query['exclude'] ?? array(),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Handle parent.
|
|
43
|
+
if ( ! empty( $query['hierarchical'] ) && isset( $query['parent'] ) ) {
|
|
44
|
+
$query_args['parent'] = $query['parent'];
|
|
45
|
+
} elseif ( ! empty( $query['hierarchical'] ) ) {
|
|
46
|
+
$query_args['parent'] = 0;
|
|
47
|
+
} elseif ( isset( $query['parent'] ) ) {
|
|
48
|
+
$query_args['parent'] = $query['parent'];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
$terms_query = new WP_Term_Query( $query_args );
|
|
52
|
+
$terms = $terms_query->get_terms();
|
|
53
|
+
|
|
54
|
+
if ( ! $terms || is_wp_error( $terms ) ) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Handle hierarchical list.
|
|
59
|
+
$is_hierarchical = ! empty( $query['hierarchical'] );
|
|
60
|
+
|
|
61
|
+
if ( $is_hierarchical ) {
|
|
62
|
+
$content = render_block_core_term_template_hierarchical( $terms, $block, $query_args );
|
|
63
|
+
} else {
|
|
64
|
+
$content = render_block_core_term_template_flat( $terms, $block );
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
$classnames = 'wp-block-term-template';
|
|
68
|
+
|
|
69
|
+
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
|
|
70
|
+
$classnames .= ' has-link-color';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classnames ) ) );
|
|
74
|
+
|
|
75
|
+
// Default list layout.
|
|
76
|
+
return sprintf(
|
|
77
|
+
'<ul %s>%s</ul>',
|
|
78
|
+
$wrapper_attributes,
|
|
79
|
+
$content
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Renders terms in a flat list structure.
|
|
85
|
+
*
|
|
86
|
+
* @since 6.9.0
|
|
87
|
+
*
|
|
88
|
+
* @param array $terms Array of WP_Term objects.
|
|
89
|
+
* @param WP_Block $block Block instance.
|
|
90
|
+
*
|
|
91
|
+
* @return string HTML content for flat terms list.
|
|
92
|
+
*/
|
|
93
|
+
function render_block_core_term_template_flat( $terms, $block ) {
|
|
94
|
+
$content = '';
|
|
95
|
+
foreach ( $terms as $term ) {
|
|
96
|
+
$content .= render_block_core_term_template_single( $term, $block );
|
|
97
|
+
}
|
|
98
|
+
return $content;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Renders terms in a hierarchical structure.
|
|
103
|
+
*
|
|
104
|
+
* @since 6.9.0
|
|
105
|
+
*
|
|
106
|
+
* @param array $terms Array of WP_Term objects.
|
|
107
|
+
* @param WP_Block $block Block instance.
|
|
108
|
+
* @param array $base_query_args Base query arguments.
|
|
109
|
+
*
|
|
110
|
+
* @return string HTML content for hierarchical terms list.
|
|
111
|
+
*/
|
|
112
|
+
function render_block_core_term_template_hierarchical( $terms, $block, $base_query_args ) {
|
|
113
|
+
$content = '';
|
|
114
|
+
|
|
115
|
+
foreach ( $terms as $term ) {
|
|
116
|
+
$term_content = render_block_core_term_template_single( $term, $block );
|
|
117
|
+
$children_content = render_block_core_term_template_get_children( $term->term_id, $block, $base_query_args );
|
|
118
|
+
|
|
119
|
+
if ( ! empty( $children_content ) ) {
|
|
120
|
+
$term_content = str_replace( '</li>', '<ul>' . $children_content . '</ul></li>', $term_content );
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
$content .= $term_content;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return $content;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets and renders children of a specific term.
|
|
131
|
+
*
|
|
132
|
+
* @since 6.9.0
|
|
133
|
+
*
|
|
134
|
+
* @param int $parent_term_id Parent term ID.
|
|
135
|
+
* @param WP_Block $block Block instance.
|
|
136
|
+
* @param array $base_query_args Base query arguments.
|
|
137
|
+
*
|
|
138
|
+
* @return string HTML content for children terms.
|
|
139
|
+
*/
|
|
140
|
+
function render_block_core_term_template_get_children( $parent_term_id, $block, $base_query_args ) {
|
|
141
|
+
$child_query_args = $base_query_args;
|
|
142
|
+
$child_query_args['parent'] = $parent_term_id;
|
|
143
|
+
|
|
144
|
+
$child_terms_query = new WP_Term_Query( $child_query_args );
|
|
145
|
+
$child_terms = $child_terms_query->get_terms();
|
|
146
|
+
|
|
147
|
+
if ( ! $child_terms || is_wp_error( $child_terms ) ) {
|
|
148
|
+
return '';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
$content = '';
|
|
152
|
+
|
|
153
|
+
foreach ( $child_terms as $child_term ) {
|
|
154
|
+
$term_content = render_block_core_term_template_single( $child_term, $block );
|
|
155
|
+
$children_content = render_block_core_term_template_get_children( $child_term->term_id, $block, $base_query_args );
|
|
156
|
+
|
|
157
|
+
if ( ! empty( $children_content ) ) {
|
|
158
|
+
$term_content = str_replace( '</li>', '<ul>' . $children_content . '</ul></li>', $term_content );
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
$content .= $term_content;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return $content;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Renders a single term with its inner blocks.
|
|
169
|
+
*
|
|
170
|
+
* @since 6.9.0
|
|
171
|
+
*
|
|
172
|
+
* @param WP_Term $term Term object.
|
|
173
|
+
* @param WP_Block $block Block instance.
|
|
174
|
+
*
|
|
175
|
+
* @return string HTML content for a single term.
|
|
176
|
+
*/
|
|
177
|
+
function render_block_core_term_template_single( $term, $block ) {
|
|
178
|
+
$inner_blocks = $block->inner_blocks;
|
|
179
|
+
$block_content = '';
|
|
180
|
+
|
|
181
|
+
if ( ! empty( $inner_blocks ) ) {
|
|
182
|
+
$term_id = $term->term_id;
|
|
183
|
+
$taxonomy = $term->taxonomy;
|
|
184
|
+
|
|
185
|
+
$filter_block_context = static function ( $context ) use ( $term_id, $taxonomy ) {
|
|
186
|
+
$context['termId'] = $term_id;
|
|
187
|
+
$context['taxonomy'] = $taxonomy;
|
|
188
|
+
return $context;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
add_filter( 'render_block_context', $filter_block_context, 1 );
|
|
192
|
+
|
|
193
|
+
foreach ( $inner_blocks as $inner_block ) {
|
|
194
|
+
if ( method_exists( $inner_block, 'refresh_context_dependents' ) ) {
|
|
195
|
+
// WP_Block::refresh_context_dependents() was introduced in WordPress 6.8.
|
|
196
|
+
$inner_block->refresh_context_dependents();
|
|
197
|
+
$block_content .= $inner_block->render( array( 'dynamic' => true ) );
|
|
198
|
+
} else {
|
|
199
|
+
$block_content = ( new WP_Block( $inner_block->parsed_block ) )->render( array( 'dynamic' => false ) );
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
remove_filter( 'render_block_context', $filter_block_context, 1 );
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
$term_classes = implode( ' ', array( 'wp-block-term', 'term-' . $term->term_id ) );
|
|
206
|
+
|
|
207
|
+
// Default list layout
|
|
208
|
+
return '<li class="' . esc_attr( $term_classes ) . '">' . $block_content . '</li>';
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Registers the `core/term-template` block on the server.
|
|
213
|
+
*
|
|
214
|
+
* @since 6.9.0
|
|
215
|
+
*/
|
|
216
|
+
function register_block_core_term_template() {
|
|
217
|
+
register_block_type_from_metadata(
|
|
218
|
+
__DIR__ . '/term-template',
|
|
219
|
+
array(
|
|
220
|
+
'render_callback' => 'render_block_core_term_template',
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
add_action( 'init', 'register_block_core_term_template' );
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { list, grid } from '@wordpress/icons';
|
|
6
|
+
|
|
7
|
+
const createInnerBlocks = ( groupMetadata, groupStyle = {} ) => [
|
|
8
|
+
[
|
|
9
|
+
'core/group',
|
|
10
|
+
{
|
|
11
|
+
layout: {
|
|
12
|
+
type: 'flex',
|
|
13
|
+
orientation: 'horizontal',
|
|
14
|
+
},
|
|
15
|
+
style: {
|
|
16
|
+
spacing: {
|
|
17
|
+
blockGap: '0.5rem',
|
|
18
|
+
},
|
|
19
|
+
...groupStyle,
|
|
20
|
+
},
|
|
21
|
+
metadata: {
|
|
22
|
+
name: groupMetadata,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
[
|
|
26
|
+
[
|
|
27
|
+
'core/paragraph',
|
|
28
|
+
{
|
|
29
|
+
metadata: {
|
|
30
|
+
name: __( 'Term Name' ),
|
|
31
|
+
bindings: {
|
|
32
|
+
content: {
|
|
33
|
+
source: 'core/term-data',
|
|
34
|
+
args: {
|
|
35
|
+
key: 'name',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
'core/paragraph',
|
|
44
|
+
{
|
|
45
|
+
placeholder: __( '(count)' ),
|
|
46
|
+
metadata: {
|
|
47
|
+
name: __( 'Term Count' ),
|
|
48
|
+
bindings: {
|
|
49
|
+
content: {
|
|
50
|
+
source: 'core/term-data',
|
|
51
|
+
args: {
|
|
52
|
+
key: 'count',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
],
|
|
60
|
+
],
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const variations = [
|
|
64
|
+
{
|
|
65
|
+
name: 'list',
|
|
66
|
+
title: __( 'List' ),
|
|
67
|
+
description: __( 'Display terms in a list layout.' ),
|
|
68
|
+
attributes: { layout: { type: 'default' } },
|
|
69
|
+
isDefault: true,
|
|
70
|
+
icon: list,
|
|
71
|
+
scope: [ 'block', 'inserter' ],
|
|
72
|
+
innerBlocks: createInnerBlocks( __( 'Term Name with Count' ) ),
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'grid',
|
|
76
|
+
title: __( 'Grid' ),
|
|
77
|
+
description: __( 'Display terms in a grid layout.' ),
|
|
78
|
+
attributes: { layout: { type: 'grid', columnCount: 3 } },
|
|
79
|
+
icon: grid,
|
|
80
|
+
scope: [ 'block', 'inserter' ],
|
|
81
|
+
innerBlocks: createInnerBlocks( __( 'Term Card' ), {
|
|
82
|
+
padding: '1rem',
|
|
83
|
+
} ),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
export default variations;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
|
+
"apiVersion": 3,
|
|
4
|
+
"__experimental": true,
|
|
5
|
+
"name": "core/terms-query",
|
|
6
|
+
"title": "Terms Query",
|
|
7
|
+
"category": "theme",
|
|
8
|
+
"description": "An advanced block that allows displaying taxonomy terms based on different query parameters and visual configurations.",
|
|
9
|
+
"keywords": [ "terms", "taxonomy", "categories", "tags", "list" ],
|
|
10
|
+
"textdomain": "default",
|
|
11
|
+
"attributes": {
|
|
12
|
+
"termQueryId": {
|
|
13
|
+
"type": "number"
|
|
14
|
+
},
|
|
15
|
+
"termQuery": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"default": {
|
|
18
|
+
"perPage": 10,
|
|
19
|
+
"pages": 0,
|
|
20
|
+
"taxonomy": "category",
|
|
21
|
+
"order": "asc",
|
|
22
|
+
"orderBy": "name",
|
|
23
|
+
"hideEmpty": true,
|
|
24
|
+
"include": [],
|
|
25
|
+
"exclude": [],
|
|
26
|
+
"parent": 0,
|
|
27
|
+
"hierarchical": false
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"tagName": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"default": "div"
|
|
33
|
+
},
|
|
34
|
+
"namespace": {
|
|
35
|
+
"type": "string"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"providesContext": {
|
|
39
|
+
"termQueryId": "termQueryId",
|
|
40
|
+
"termQuery": "termQuery"
|
|
41
|
+
},
|
|
42
|
+
"supports": {
|
|
43
|
+
"align": [ "wide", "full" ],
|
|
44
|
+
"html": false,
|
|
45
|
+
"interactivity": true
|
|
46
|
+
},
|
|
47
|
+
"allowedBlocks": [ "core/term-template" ],
|
|
48
|
+
"style": "wp-block-terms-query"
|
|
49
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { loop as icon } from '@wordpress/icons';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import initBlock from '../utils/init-block';
|
|
10
|
+
import metadata from './block.json';
|
|
11
|
+
import edit from './edit';
|
|
12
|
+
import save from './save';
|
|
13
|
+
|
|
14
|
+
const { name } = metadata;
|
|
15
|
+
export { metadata, name };
|
|
16
|
+
|
|
17
|
+
export const settings = {
|
|
18
|
+
icon,
|
|
19
|
+
edit,
|
|
20
|
+
save,
|
|
21
|
+
example: {},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const init = () => initBlock( { name, metadata, settings } );
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Server-side rendering of the `core/terms-query` block.
|
|
4
|
+
*
|
|
5
|
+
* @package WordPress
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Renders the `core/terms-query` block on the server.
|
|
10
|
+
*
|
|
11
|
+
* @since 6.9.0
|
|
12
|
+
*
|
|
13
|
+
* @param array $attributes Block attributes.
|
|
14
|
+
* @param string $content Block default content.
|
|
15
|
+
*
|
|
16
|
+
* @return string Returns the output of the query, structured using the layout defined by the block's inner blocks.
|
|
17
|
+
*/
|
|
18
|
+
function render_block_core_terms_query( $attributes, $content ) {
|
|
19
|
+
$tag_name = ! empty( $attributes['tagName'] ) ? $attributes['tagName'] : 'div';
|
|
20
|
+
$wrapper_attributes = get_block_wrapper_attributes();
|
|
21
|
+
|
|
22
|
+
return sprintf(
|
|
23
|
+
'<%1$s %2$s>%3$s</%1$s>',
|
|
24
|
+
$tag_name,
|
|
25
|
+
$wrapper_attributes,
|
|
26
|
+
$content
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Registers the `core/terms-query` block on the server.
|
|
33
|
+
*
|
|
34
|
+
* @since 6.9.0
|
|
35
|
+
*/
|
|
36
|
+
function register_block_core_terms_query() {
|
|
37
|
+
register_block_type_from_metadata(
|
|
38
|
+
__DIR__ . '/terms-query',
|
|
39
|
+
array(
|
|
40
|
+
'render_callback' => 'render_block_core_terms_query',
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
add_action( 'init', 'register_block_core_terms_query' );
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanel as ToolsPanel,
|
|
7
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
8
|
+
RangeControl,
|
|
9
|
+
SelectControl,
|
|
10
|
+
ToggleControl,
|
|
11
|
+
} from '@wordpress/components';
|
|
12
|
+
import {
|
|
13
|
+
InspectorControls,
|
|
14
|
+
privateApis as blockEditorPrivateApis,
|
|
15
|
+
} from '@wordpress/block-editor';
|
|
16
|
+
import { useSelect } from '@wordpress/data';
|
|
17
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Internal dependencies
|
|
21
|
+
*/
|
|
22
|
+
import { useToolsPanelDropdownMenuProps } from '../utils/hooks';
|
|
23
|
+
import { unlock } from '../lock-unlock';
|
|
24
|
+
|
|
25
|
+
const { HTMLElementControl } = unlock( blockEditorPrivateApis );
|
|
26
|
+
|
|
27
|
+
export default function TermsQueryInspectorControls( {
|
|
28
|
+
attributes,
|
|
29
|
+
setQuery,
|
|
30
|
+
setAttributes,
|
|
31
|
+
TagName,
|
|
32
|
+
clientId,
|
|
33
|
+
} ) {
|
|
34
|
+
const { termQuery } = attributes;
|
|
35
|
+
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
36
|
+
|
|
37
|
+
const { taxonomies } = useSelect( ( select ) => {
|
|
38
|
+
const { getEntityRecords } = select( coreStore );
|
|
39
|
+
const allTaxonomies = getEntityRecords( 'root', 'taxonomy' );
|
|
40
|
+
return {
|
|
41
|
+
taxonomies:
|
|
42
|
+
allTaxonomies?.filter( ( t ) => t.visibility.public ) || [],
|
|
43
|
+
};
|
|
44
|
+
}, [] );
|
|
45
|
+
|
|
46
|
+
const taxonomyOptions = taxonomies.map( ( taxonomy ) => ( {
|
|
47
|
+
label: taxonomy.name,
|
|
48
|
+
value: taxonomy.slug,
|
|
49
|
+
} ) );
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
<InspectorControls>
|
|
54
|
+
<ToolsPanel
|
|
55
|
+
label={ __( 'Terms Query Settings' ) }
|
|
56
|
+
resetAll={ () => {
|
|
57
|
+
setAttributes( {
|
|
58
|
+
termQuery: {
|
|
59
|
+
taxonomy: 'category',
|
|
60
|
+
order: 'asc',
|
|
61
|
+
orderBy: 'name',
|
|
62
|
+
hideEmpty: true,
|
|
63
|
+
hierarchical: false,
|
|
64
|
+
parent: 0,
|
|
65
|
+
perPage: 10,
|
|
66
|
+
},
|
|
67
|
+
} );
|
|
68
|
+
} }
|
|
69
|
+
dropdownMenuProps={ dropdownMenuProps }
|
|
70
|
+
>
|
|
71
|
+
<ToolsPanelItem
|
|
72
|
+
hasValue={ () => termQuery.taxonomy !== 'category' }
|
|
73
|
+
label={ __( 'Taxonomy' ) }
|
|
74
|
+
onDeselect={ () =>
|
|
75
|
+
setQuery( { taxonomy: 'category' } )
|
|
76
|
+
}
|
|
77
|
+
isShownByDefault
|
|
78
|
+
>
|
|
79
|
+
<SelectControl
|
|
80
|
+
__nextHasNoMarginBottom
|
|
81
|
+
__next40pxDefaultSize
|
|
82
|
+
label={ __( 'Taxonomy' ) }
|
|
83
|
+
options={ taxonomyOptions }
|
|
84
|
+
value={ termQuery.taxonomy }
|
|
85
|
+
onChange={ ( selectedTaxonomy ) =>
|
|
86
|
+
setQuery( { taxonomy: selectedTaxonomy } )
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
</ToolsPanelItem>
|
|
90
|
+
|
|
91
|
+
<ToolsPanelItem
|
|
92
|
+
hasValue={ () =>
|
|
93
|
+
termQuery.orderBy !== 'name' ||
|
|
94
|
+
termQuery.order !== 'asc'
|
|
95
|
+
}
|
|
96
|
+
label={ __( 'Order by' ) }
|
|
97
|
+
onDeselect={ () =>
|
|
98
|
+
setQuery( { orderBy: 'name', order: 'asc' } )
|
|
99
|
+
}
|
|
100
|
+
isShownByDefault
|
|
101
|
+
>
|
|
102
|
+
<SelectControl
|
|
103
|
+
__nextHasNoMarginBottom
|
|
104
|
+
__next40pxDefaultSize
|
|
105
|
+
label={ __( 'Order by' ) }
|
|
106
|
+
options={ [
|
|
107
|
+
{
|
|
108
|
+
label: __( 'Name: A → Z' ),
|
|
109
|
+
value: 'name/asc',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
label: __( 'Name: Z → A' ),
|
|
113
|
+
value: 'name/desc',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
label: __( 'Count, high to low' ),
|
|
117
|
+
value: 'count/desc',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
label: __( 'Count, low to high' ),
|
|
121
|
+
value: 'count/asc',
|
|
122
|
+
},
|
|
123
|
+
] }
|
|
124
|
+
value={ termQuery.orderBy + '/' + termQuery.order }
|
|
125
|
+
onChange={ ( orderBy ) => {
|
|
126
|
+
const [ newOrderBy, newOrder ] =
|
|
127
|
+
orderBy.split( '/' );
|
|
128
|
+
setQuery( {
|
|
129
|
+
orderBy: newOrderBy,
|
|
130
|
+
order: newOrder,
|
|
131
|
+
} );
|
|
132
|
+
} }
|
|
133
|
+
/>
|
|
134
|
+
</ToolsPanelItem>
|
|
135
|
+
|
|
136
|
+
<ToolsPanelItem
|
|
137
|
+
hasValue={ () => termQuery.parent !== 0 }
|
|
138
|
+
label={ __( 'Show only top level terms' ) }
|
|
139
|
+
onDeselect={ () => setQuery( { parent: 0 } ) }
|
|
140
|
+
isShownByDefault
|
|
141
|
+
>
|
|
142
|
+
<ToggleControl
|
|
143
|
+
__nextHasNoMarginBottom
|
|
144
|
+
label={ __( 'Show only top level terms' ) }
|
|
145
|
+
checked={ termQuery.parent === 0 }
|
|
146
|
+
onChange={ ( showTopLevel ) => {
|
|
147
|
+
setQuery( {
|
|
148
|
+
parent: showTopLevel ? 0 : undefined,
|
|
149
|
+
} );
|
|
150
|
+
if ( showTopLevel && termQuery.hierarchical ) {
|
|
151
|
+
setQuery( { hierarchical: false } );
|
|
152
|
+
}
|
|
153
|
+
} }
|
|
154
|
+
disabled={ !! termQuery.hierarchical }
|
|
155
|
+
/>
|
|
156
|
+
</ToolsPanelItem>
|
|
157
|
+
|
|
158
|
+
<ToolsPanelItem
|
|
159
|
+
hasValue={ () => termQuery.hideEmpty !== true }
|
|
160
|
+
label={ __( 'Show empty terms' ) }
|
|
161
|
+
onDeselect={ () => setQuery( { hideEmpty: true } ) }
|
|
162
|
+
isShownByDefault
|
|
163
|
+
>
|
|
164
|
+
<ToggleControl
|
|
165
|
+
__nextHasNoMarginBottom
|
|
166
|
+
label={ __( 'Show empty terms' ) }
|
|
167
|
+
checked={ ! termQuery.hideEmpty }
|
|
168
|
+
onChange={ ( showEmpty ) =>
|
|
169
|
+
setQuery( { hideEmpty: ! showEmpty } )
|
|
170
|
+
}
|
|
171
|
+
/>
|
|
172
|
+
</ToolsPanelItem>
|
|
173
|
+
|
|
174
|
+
<ToolsPanelItem
|
|
175
|
+
hasValue={ () => termQuery.hierarchical !== false }
|
|
176
|
+
label={ __( 'Show hierarchy' ) }
|
|
177
|
+
onDeselect={ () => setQuery( { hierarchical: false } ) }
|
|
178
|
+
isShownByDefault
|
|
179
|
+
>
|
|
180
|
+
<ToggleControl
|
|
181
|
+
__nextHasNoMarginBottom
|
|
182
|
+
label={ __( 'Show hierarchy' ) }
|
|
183
|
+
checked={ termQuery.hierarchical }
|
|
184
|
+
onChange={ ( hierarchical ) => {
|
|
185
|
+
setQuery( { hierarchical } );
|
|
186
|
+
if ( hierarchical && termQuery.parent ) {
|
|
187
|
+
setQuery( { parent: 0 } );
|
|
188
|
+
}
|
|
189
|
+
} }
|
|
190
|
+
disabled={ termQuery.parent === 0 }
|
|
191
|
+
/>
|
|
192
|
+
</ToolsPanelItem>
|
|
193
|
+
|
|
194
|
+
{ ! termQuery.hierarchical && (
|
|
195
|
+
<ToolsPanelItem
|
|
196
|
+
hasValue={ () => termQuery.perPage !== 10 }
|
|
197
|
+
label={ __( 'Max terms' ) }
|
|
198
|
+
onDeselect={ () => setQuery( { perPage: 10 } ) }
|
|
199
|
+
isShownByDefault
|
|
200
|
+
>
|
|
201
|
+
<RangeControl
|
|
202
|
+
__nextHasNoMarginBottom
|
|
203
|
+
__next40pxDefaultSize
|
|
204
|
+
label={ __( 'Max terms' ) }
|
|
205
|
+
value={ termQuery.perPage }
|
|
206
|
+
min={ 0 }
|
|
207
|
+
max={ 100 }
|
|
208
|
+
onChange={ ( perPage ) => {
|
|
209
|
+
// Show all terms (-1) when 0 is selected.
|
|
210
|
+
setQuery( {
|
|
211
|
+
perPage: perPage === 0 ? -1 : perPage,
|
|
212
|
+
} );
|
|
213
|
+
} }
|
|
214
|
+
help={ __(
|
|
215
|
+
'Limit the number of terms you want to show. To show all terms, use 0 (zero).'
|
|
216
|
+
) }
|
|
217
|
+
/>
|
|
218
|
+
</ToolsPanelItem>
|
|
219
|
+
) }
|
|
220
|
+
</ToolsPanel>
|
|
221
|
+
</InspectorControls>
|
|
222
|
+
<InspectorControls group="advanced">
|
|
223
|
+
<HTMLElementControl
|
|
224
|
+
tagName={ TagName }
|
|
225
|
+
onChange={ ( value ) =>
|
|
226
|
+
setAttributes( { tagName: value } )
|
|
227
|
+
}
|
|
228
|
+
clientId={ clientId }
|
|
229
|
+
options={ [
|
|
230
|
+
{ label: __( 'Default (<div>)' ), value: 'div' },
|
|
231
|
+
{ label: '<main>', value: 'main' },
|
|
232
|
+
{ label: '<section>', value: 'section' },
|
|
233
|
+
{ label: '<aside>', value: 'aside' },
|
|
234
|
+
] }
|
|
235
|
+
/>
|
|
236
|
+
</InspectorControls>
|
|
237
|
+
</>
|
|
238
|
+
);
|
|
239
|
+
}
|