@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.
Files changed (209) hide show
  1. package/build/button/edit.js +6 -1
  2. package/build/button/edit.js.map +1 -1
  3. package/build/button/edit.native.js +1 -1
  4. package/build/button/edit.native.js.map +1 -1
  5. package/build/buttons/index.js +2 -1
  6. package/build/buttons/index.js.map +1 -1
  7. package/build/categories/edit.js +3 -1
  8. package/build/categories/edit.js.map +1 -1
  9. package/build/image/edit.native.js +1 -1
  10. package/build/image/edit.native.js.map +1 -1
  11. package/build/image/image.js +5 -8
  12. package/build/image/image.js.map +1 -1
  13. package/build/image/save.js +6 -2
  14. package/build/image/save.js.map +1 -1
  15. package/build/index.js +4 -0
  16. package/build/index.js.map +1 -1
  17. package/build/navigation/edit/index.js +0 -1
  18. package/build/navigation/edit/index.js.map +1 -1
  19. package/build/navigation-link/block-inserter.js +69 -0
  20. package/build/navigation-link/block-inserter.js.map +1 -0
  21. package/build/navigation-link/dialog-wrapper.js +80 -0
  22. package/build/navigation-link/dialog-wrapper.js.map +1 -0
  23. package/build/navigation-link/link-ui.js +34 -82
  24. package/build/navigation-link/link-ui.js.map +1 -1
  25. package/build/navigation-link/page-creator.js +12 -18
  26. package/build/navigation-link/page-creator.js.map +1 -1
  27. package/build/post-date/edit.js +2 -1
  28. package/build/post-date/edit.js.map +1 -1
  29. package/build/post-featured-image/edit.js +7 -2
  30. package/build/post-featured-image/edit.js.map +1 -1
  31. package/build/post-title/edit.js +8 -2
  32. package/build/post-title/edit.js.map +1 -1
  33. package/build/query/edit/pattern-selection.js +9 -1
  34. package/build/query/edit/pattern-selection.js.map +1 -1
  35. package/build/query/index.js +2 -1
  36. package/build/query/index.js.map +1 -1
  37. package/build/rss/edit.js +6 -1
  38. package/build/rss/edit.js.map +1 -1
  39. package/build/site-tagline/index.js +1 -0
  40. package/build/site-tagline/index.js.map +1 -1
  41. package/build/social-link/edit.js +6 -1
  42. package/build/social-link/edit.js.map +1 -1
  43. package/build/social-links/index.js +2 -1
  44. package/build/social-links/index.js.map +1 -1
  45. package/build/spacer/edit.js +2 -1
  46. package/build/spacer/edit.js.map +1 -1
  47. package/build/table-of-contents/edit.js +33 -9
  48. package/build/table-of-contents/edit.js.map +1 -1
  49. package/build/table-of-contents/index.js +4 -0
  50. package/build/table-of-contents/index.js.map +1 -1
  51. package/build/table-of-contents/list.js +6 -3
  52. package/build/table-of-contents/list.js.map +1 -1
  53. package/build/table-of-contents/save.js +6 -3
  54. package/build/table-of-contents/save.js.map +1 -1
  55. package/build/term-template/edit.js +318 -0
  56. package/build/term-template/edit.js.map +1 -0
  57. package/build/term-template/index.js +109 -0
  58. package/build/term-template/index.js.map +1 -0
  59. package/build/term-template/save.js +16 -0
  60. package/build/term-template/save.js.map +1 -0
  61. package/build/term-template/variations.js +83 -0
  62. package/build/term-template/variations.js.map +1 -0
  63. package/build/terms-query/edit.js +20 -0
  64. package/build/terms-query/edit.js.map +1 -0
  65. package/build/terms-query/index.js +83 -0
  66. package/build/terms-query/index.js.map +1 -0
  67. package/build/terms-query/inspector-controls.js +231 -0
  68. package/build/terms-query/inspector-controls.js.map +1 -0
  69. package/build/terms-query/save.js +24 -0
  70. package/build/terms-query/save.js.map +1 -0
  71. package/build/terms-query/terms-query-content.js +71 -0
  72. package/build/terms-query/terms-query-content.js.map +1 -0
  73. package/build/utils/hooks.js +3 -0
  74. package/build/utils/hooks.js.map +1 -1
  75. package/build-module/button/edit.js +7 -2
  76. package/build-module/button/edit.js.map +1 -1
  77. package/build-module/button/edit.native.js +1 -1
  78. package/build-module/button/edit.native.js.map +1 -1
  79. package/build-module/buttons/index.js +2 -1
  80. package/build-module/buttons/index.js.map +1 -1
  81. package/build-module/categories/edit.js +3 -1
  82. package/build-module/categories/edit.js.map +1 -1
  83. package/build-module/image/edit.native.js +1 -1
  84. package/build-module/image/edit.native.js.map +1 -1
  85. package/build-module/image/image.js +5 -8
  86. package/build-module/image/image.js.map +1 -1
  87. package/build-module/image/save.js +6 -2
  88. package/build-module/image/save.js.map +1 -1
  89. package/build-module/index.js +4 -0
  90. package/build-module/index.js.map +1 -1
  91. package/build-module/navigation/edit/index.js +0 -1
  92. package/build-module/navigation/edit/index.js.map +1 -1
  93. package/build-module/navigation-link/block-inserter.js +61 -0
  94. package/build-module/navigation-link/block-inserter.js.map +1 -0
  95. package/build-module/navigation-link/dialog-wrapper.js +75 -0
  96. package/build-module/navigation-link/dialog-wrapper.js.map +1 -0
  97. package/build-module/navigation-link/link-ui.js +37 -85
  98. package/build-module/navigation-link/link-ui.js.map +1 -1
  99. package/build-module/navigation-link/page-creator.js +12 -19
  100. package/build-module/navigation-link/page-creator.js.map +1 -1
  101. package/build-module/post-date/edit.js +3 -2
  102. package/build-module/post-date/edit.js.map +1 -1
  103. package/build-module/post-featured-image/edit.js +9 -4
  104. package/build-module/post-featured-image/edit.js.map +1 -1
  105. package/build-module/post-title/edit.js +9 -3
  106. package/build-module/post-title/edit.js.map +1 -1
  107. package/build-module/query/edit/pattern-selection.js +9 -1
  108. package/build-module/query/edit/pattern-selection.js.map +1 -1
  109. package/build-module/query/index.js +2 -1
  110. package/build-module/query/index.js.map +1 -1
  111. package/build-module/rss/edit.js +8 -3
  112. package/build-module/rss/edit.js.map +1 -1
  113. package/build-module/site-tagline/index.js +1 -0
  114. package/build-module/site-tagline/index.js.map +1 -1
  115. package/build-module/social-link/edit.js +8 -3
  116. package/build-module/social-link/edit.js.map +1 -1
  117. package/build-module/social-links/index.js +2 -1
  118. package/build-module/social-links/index.js.map +1 -1
  119. package/build-module/spacer/edit.js +3 -2
  120. package/build-module/spacer/edit.js.map +1 -1
  121. package/build-module/table-of-contents/edit.js +35 -11
  122. package/build-module/table-of-contents/edit.js.map +1 -1
  123. package/build-module/table-of-contents/index.js +4 -0
  124. package/build-module/table-of-contents/index.js.map +1 -1
  125. package/build-module/table-of-contents/list.js +6 -3
  126. package/build-module/table-of-contents/list.js.map +1 -1
  127. package/build-module/table-of-contents/save.js +6 -3
  128. package/build-module/table-of-contents/save.js.map +1 -1
  129. package/build-module/term-template/edit.js +310 -0
  130. package/build-module/term-template/edit.js.map +1 -0
  131. package/build-module/term-template/index.js +102 -0
  132. package/build-module/term-template/index.js.map +1 -0
  133. package/build-module/term-template/save.js +9 -0
  134. package/build-module/term-template/save.js.map +1 -0
  135. package/build-module/term-template/variations.js +76 -0
  136. package/build-module/term-template/variations.js.map +1 -0
  137. package/build-module/terms-query/edit.js +12 -0
  138. package/build-module/terms-query/edit.js.map +1 -0
  139. package/build-module/terms-query/index.js +76 -0
  140. package/build-module/terms-query/index.js.map +1 -0
  141. package/build-module/terms-query/inspector-controls.js +224 -0
  142. package/build-module/terms-query/inspector-controls.js.map +1 -0
  143. package/build-module/terms-query/save.js +17 -0
  144. package/build-module/terms-query/save.js.map +1 -0
  145. package/build-module/terms-query/terms-query-content.js +63 -0
  146. package/build-module/terms-query/terms-query-content.js.map +1 -0
  147. package/build-module/utils/hooks.js +3 -0
  148. package/build-module/utils/hooks.js.map +1 -1
  149. package/build-style/editor-rtl.css +24 -0
  150. package/build-style/editor.css +24 -0
  151. package/build-style/style-rtl.css +16 -0
  152. package/build-style/style.css +16 -0
  153. package/build-style/term-template/editor-rtl.css +160 -0
  154. package/build-style/term-template/editor.css +160 -0
  155. package/build-style/term-template/style-rtl.css +146 -0
  156. package/build-style/term-template/style.css +146 -0
  157. package/build-style/terms-query/style-rtl.css +140 -0
  158. package/build-style/terms-query/style.css +140 -0
  159. package/build-types/table-of-contents/list.d.ts +2 -1
  160. package/build-types/table-of-contents/list.d.ts.map +1 -1
  161. package/package.json +35 -35
  162. package/src/button/edit.js +12 -1
  163. package/src/button/edit.native.js +1 -1
  164. package/src/buttons/block.json +2 -1
  165. package/src/categories/edit.js +2 -1
  166. package/src/editor.scss +1 -0
  167. package/src/image/edit.native.js +1 -1
  168. package/src/image/image.js +5 -8
  169. package/src/image/save.js +7 -1
  170. package/src/index.js +4 -0
  171. package/src/navigation/edit/index.js +0 -1
  172. package/src/navigation-link/block-inserter.js +65 -0
  173. package/src/navigation-link/dialog-wrapper.js +74 -0
  174. package/src/navigation-link/link-ui.js +32 -95
  175. package/src/navigation-link/page-creator.js +13 -20
  176. package/src/post-date/edit.js +64 -53
  177. package/src/post-date/index.php +5 -13
  178. package/src/post-featured-image/edit.js +19 -3
  179. package/src/post-title/edit.js +14 -2
  180. package/src/query/block.json +2 -1
  181. package/src/query/edit/pattern-selection.js +10 -1
  182. package/src/rss/edit.js +13 -2
  183. package/src/site-tagline/block.json +1 -0
  184. package/src/social-link/edit.js +13 -2
  185. package/src/social-links/block.json +2 -1
  186. package/src/spacer/edit.js +5 -1
  187. package/src/style.scss +2 -0
  188. package/src/table-of-contents/block.json +4 -0
  189. package/src/table-of-contents/edit.js +58 -21
  190. package/src/table-of-contents/list.tsx +7 -2
  191. package/src/table-of-contents/save.js +7 -3
  192. package/src/term-template/block.json +73 -0
  193. package/src/term-template/edit.js +391 -0
  194. package/src/term-template/editor.scss +26 -0
  195. package/src/term-template/index.js +26 -0
  196. package/src/term-template/index.php +224 -0
  197. package/src/term-template/save.js +8 -0
  198. package/src/term-template/style.scss +12 -0
  199. package/src/term-template/variations.js +87 -0
  200. package/src/terms-query/block.json +49 -0
  201. package/src/terms-query/edit.js +10 -0
  202. package/src/terms-query/index.js +24 -0
  203. package/src/terms-query/index.php +44 -0
  204. package/src/terms-query/inspector-controls.js +239 -0
  205. package/src/terms-query/save.js +10 -0
  206. package/src/terms-query/style.scss +6 -0
  207. package/src/terms-query/terms-query-content.js +74 -0
  208. package/src/utils/hooks.js +4 -0
  209. 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,8 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { InnerBlocks } from '@wordpress/block-editor';
5
+
6
+ export default function TermTemplateSave() {
7
+ return <InnerBlocks.Content />;
8
+ }
@@ -0,0 +1,12 @@
1
+ .wp-block-term-template {
2
+ margin-top: 0;
3
+ margin-bottom: 0;
4
+ max-width: 100%;
5
+ box-sizing: border-box;
6
+
7
+ &.is-layout-grid,
8
+ &.is-layout-flex {
9
+ list-style: none;
10
+ padding: 0;
11
+ }
12
+ }
@@ -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,10 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import TermsQueryContent from './terms-query-content';
5
+
6
+ const TermsQueryEdit = ( props ) => {
7
+ return <TermsQueryContent { ...props } />;
8
+ };
9
+
10
+ export default TermsQueryEdit;
@@ -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
+ }