@wordpress/block-library 9.31.0 → 9.31.1-next.f56bd8138.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/accordion/edit.js +6 -5
- package/build/accordion/edit.js.map +1 -1
- package/build/accordion/index.js +40 -4
- package/build/accordion/index.js.map +1 -1
- package/build/accordion/save.js +2 -19
- package/build/accordion/save.js.map +1 -1
- package/build/accordion/view.js +50 -16
- package/build/accordion/view.js.map +1 -1
- package/build/accordion-content/index.js +15 -2
- package/build/accordion-content/index.js.map +1 -1
- package/build/accordion-header/edit.js +15 -39
- package/build/accordion-header/edit.js.map +1 -1
- package/build/accordion-header/index.js +6 -6
- package/build/accordion-header/index.js.map +1 -1
- package/build/accordion-header/save.js +15 -37
- package/build/accordion-header/save.js.map +1 -1
- package/build/accordion-panel/index.js +1 -2
- package/build/accordion-panel/index.js.map +1 -1
- package/build/avatar/hooks.js +7 -17
- package/build/avatar/hooks.js.map +1 -1
- package/build/navigation/index.js +2 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation-link/index.js +2 -1
- package/build/navigation-link/index.js.map +1 -1
- package/build/navigation-submenu/index.js +2 -1
- package/build/navigation-submenu/index.js.map +1 -1
- package/build/page-list/index.js +2 -1
- package/build/page-list/index.js.map +1 -1
- package/build/post-author/edit.js +7 -6
- package/build/post-author/edit.js.map +1 -1
- package/build/post-time-to-read/edit.js +50 -7
- package/build/post-time-to-read/edit.js.map +1 -1
- package/build/post-time-to-read/index.js +8 -0
- package/build/post-time-to-read/index.js.map +1 -1
- package/build/term-description/edit.js +18 -2
- package/build/term-description/edit.js.map +1 -1
- package/build/term-description/index.js +1 -0
- package/build/term-description/index.js.map +1 -1
- package/build/term-description/use-term-description.js +85 -0
- package/build/term-description/use-term-description.js.map +1 -0
- package/build/term-template/edit.js +11 -7
- package/build/term-template/edit.js.map +1 -1
- package/build/term-template/index.js +1 -1
- package/build/terms-query/index.js +8 -2
- package/build/terms-query/index.js.map +1 -1
- package/build/terms-query/inspector-controls/advanced-controls.js +51 -0
- package/build/terms-query/inspector-controls/advanced-controls.js.map +1 -0
- package/build/terms-query/inspector-controls/display-options.js +87 -0
- package/build/terms-query/inspector-controls/display-options.js.map +1 -0
- package/build/terms-query/inspector-controls/empty-terms-control.js +38 -0
- package/build/terms-query/inspector-controls/empty-terms-control.js.map +1 -0
- package/build/terms-query/inspector-controls/hierarchy-control.js +40 -0
- package/build/terms-query/inspector-controls/hierarchy-control.js.map +1 -0
- package/build/terms-query/inspector-controls/index.js +127 -0
- package/build/terms-query/inspector-controls/index.js.map +1 -0
- package/build/terms-query/inspector-controls/max-terms-control.js +50 -0
- package/build/terms-query/inspector-controls/max-terms-control.js.map +1 -0
- package/build/terms-query/inspector-controls/ordering-controls.js +57 -0
- package/build/terms-query/inspector-controls/ordering-controls.js.map +1 -0
- package/build/terms-query/inspector-controls/taxonomy-control.js +52 -0
- package/build/terms-query/inspector-controls/taxonomy-control.js.map +1 -0
- package/build/utils/hooks.js +15 -0
- package/build/utils/hooks.js.map +1 -1
- package/build-module/accordion/edit.js +6 -5
- package/build-module/accordion/edit.js.map +1 -1
- package/build-module/accordion/index.js +41 -4
- package/build-module/accordion/index.js.map +1 -1
- package/build-module/accordion/save.js +2 -17
- package/build-module/accordion/save.js.map +1 -1
- package/build-module/accordion/view.js +51 -17
- package/build-module/accordion/view.js.map +1 -1
- package/build-module/accordion-content/index.js +15 -2
- package/build-module/accordion-content/index.js.map +1 -1
- package/build-module/accordion-header/edit.js +16 -39
- package/build-module/accordion-header/edit.js.map +1 -1
- package/build-module/accordion-header/index.js +6 -6
- package/build-module/accordion-header/index.js.map +1 -1
- package/build-module/accordion-header/save.js +16 -37
- package/build-module/accordion-header/save.js.map +1 -1
- package/build-module/accordion-panel/index.js +1 -2
- package/build-module/accordion-panel/index.js.map +1 -1
- package/build-module/avatar/hooks.js +5 -15
- package/build-module/avatar/hooks.js.map +1 -1
- package/build-module/navigation/index.js +2 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation-link/index.js +2 -1
- package/build-module/navigation-link/index.js.map +1 -1
- package/build-module/navigation-submenu/index.js +2 -1
- package/build-module/navigation-submenu/index.js.map +1 -1
- package/build-module/page-list/index.js +2 -1
- package/build-module/page-list/index.js.map +1 -1
- package/build-module/post-author/edit.js +8 -7
- package/build-module/post-author/edit.js.map +1 -1
- package/build-module/post-time-to-read/edit.js +50 -9
- package/build-module/post-time-to-read/edit.js.map +1 -1
- package/build-module/post-time-to-read/index.js +8 -0
- package/build-module/post-time-to-read/index.js.map +1 -1
- package/build-module/term-description/edit.js +18 -2
- package/build-module/term-description/edit.js.map +1 -1
- package/build-module/term-description/index.js +1 -0
- package/build-module/term-description/index.js.map +1 -1
- package/build-module/term-description/use-term-description.js +79 -0
- package/build-module/term-description/use-term-description.js.map +1 -0
- package/build-module/term-template/edit.js +11 -7
- package/build-module/term-template/edit.js.map +1 -1
- package/build-module/term-template/index.js +1 -1
- package/build-module/terms-query/index.js +8 -2
- package/build-module/terms-query/index.js.map +1 -1
- package/build-module/terms-query/inspector-controls/advanced-controls.js +44 -0
- package/build-module/terms-query/inspector-controls/advanced-controls.js.map +1 -0
- package/build-module/terms-query/inspector-controls/display-options.js +80 -0
- package/build-module/terms-query/inspector-controls/display-options.js.map +1 -0
- package/build-module/terms-query/inspector-controls/empty-terms-control.js +31 -0
- package/build-module/terms-query/inspector-controls/empty-terms-control.js.map +1 -0
- package/build-module/terms-query/inspector-controls/hierarchy-control.js +33 -0
- package/build-module/terms-query/inspector-controls/hierarchy-control.js.map +1 -0
- package/build-module/terms-query/inspector-controls/index.js +119 -0
- package/build-module/terms-query/inspector-controls/index.js.map +1 -0
- package/build-module/terms-query/inspector-controls/max-terms-control.js +43 -0
- package/build-module/terms-query/inspector-controls/max-terms-control.js.map +1 -0
- package/build-module/terms-query/inspector-controls/ordering-controls.js +50 -0
- package/build-module/terms-query/inspector-controls/ordering-controls.js.map +1 -0
- package/build-module/terms-query/inspector-controls/taxonomy-control.js +45 -0
- package/build-module/terms-query/inspector-controls/taxonomy-control.js.map +1 -0
- package/build-module/utils/hooks.js +14 -0
- package/build-module/utils/hooks.js.map +1 -1
- package/build-style/accordion/style-rtl.css +15 -8
- package/build-style/accordion/style.css +15 -8
- package/build-style/style-rtl.css +15 -8
- package/build-style/style.css +15 -8
- package/package.json +35 -35
- package/src/accordion/block.json +17 -3
- package/src/accordion/edit.js +39 -34
- package/src/accordion/index.js +35 -1
- package/src/accordion/index.php +3 -19
- package/src/accordion/save.js +2 -16
- package/src/accordion/style.scss +16 -8
- package/src/accordion/view.js +64 -15
- package/src/accordion-content/block.json +15 -2
- package/src/accordion-content/index.php +2 -1
- package/src/accordion-header/block.json +6 -6
- package/src/accordion-header/edit.js +19 -56
- package/src/accordion-header/save.js +27 -49
- package/src/accordion-panel/block.json +1 -2
- package/src/avatar/hooks.js +5 -10
- package/src/navigation/block.json +2 -1
- package/src/navigation-link/block.json +2 -1
- package/src/navigation-submenu/block.json +2 -1
- package/src/page-list/block.json +2 -1
- package/src/post-author/edit.js +16 -7
- package/src/post-time-to-read/block.json +8 -0
- package/src/post-time-to-read/edit.js +71 -10
- package/src/post-time-to-read/index.php +29 -17
- package/src/term-description/block.json +1 -0
- package/src/term-description/edit.js +18 -3
- package/src/term-description/use-term-description.js +109 -0
- package/src/term-template/block.json +1 -1
- package/src/term-template/edit.js +11 -6
- package/src/term-template/index.php +13 -7
- package/src/terms-query/block.json +8 -2
- package/src/terms-query/inspector-controls/advanced-controls.js +37 -0
- package/src/terms-query/inspector-controls/display-options.js +87 -0
- package/src/terms-query/inspector-controls/empty-terms-control.js +30 -0
- package/src/terms-query/inspector-controls/hierarchy-control.js +30 -0
- package/src/terms-query/inspector-controls/index.js +137 -0
- package/src/terms-query/inspector-controls/max-terms-control.js +44 -0
- package/src/terms-query/inspector-controls/ordering-controls.js +55 -0
- package/src/terms-query/inspector-controls/taxonomy-control.js +41 -0
- package/src/utils/hooks.js +9 -0
- package/build/accordion-content/icons.js +0 -30
- package/build/accordion-content/icons.js.map +0 -1
- package/build/terms-query/inspector-controls.js +0 -231
- package/build/terms-query/inspector-controls.js.map +0 -1
- package/build-module/accordion-content/icons.js +0 -22
- package/build-module/accordion-content/icons.js.map +0 -1
- package/build-module/terms-query/inspector-controls.js +0 -224
- package/build-module/terms-query/inspector-controls.js.map +0 -1
- package/src/accordion-content/icons.js +0 -23
- package/src/terms-query/inspector-controls.js +0 -239
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as coreStore, useEntityProp } from '@wordpress/core-data';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook to fetch term description based on context or fallback to template parsing.
|
|
9
|
+
*
|
|
10
|
+
* This hook prioritizes context-provided termId and taxonomy, but falls back to
|
|
11
|
+
* template-based detection when no context is available.
|
|
12
|
+
*
|
|
13
|
+
* @param {string|number} termId The term ID from context
|
|
14
|
+
* @param {string} taxonomy The taxonomy name from context
|
|
15
|
+
*/
|
|
16
|
+
export function useTermDescription( termId, taxonomy ) {
|
|
17
|
+
const [ description, setDescription, fullDescription ] = useEntityProp(
|
|
18
|
+
'taxonomy',
|
|
19
|
+
taxonomy,
|
|
20
|
+
'description',
|
|
21
|
+
termId
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Fallback approach: Parse template slug when no context is available.
|
|
25
|
+
const templateBasedData = useTemplateBasedTermData();
|
|
26
|
+
|
|
27
|
+
const hasContext = Boolean( termId && taxonomy );
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
hasContext,
|
|
31
|
+
setDescription,
|
|
32
|
+
termDescription: hasContext
|
|
33
|
+
? fullDescription?.rendered || description || ''
|
|
34
|
+
: templateBasedData,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Fallback hook to fetch term data from template context (backward compatibility).
|
|
40
|
+
* This maintains the same logic as the original implementation for cases where
|
|
41
|
+
* no termId/taxonomy context is provided.
|
|
42
|
+
*/
|
|
43
|
+
function useTemplateBasedTermData() {
|
|
44
|
+
const templateSlug = useSelect( ( select ) => {
|
|
45
|
+
// Access core/editor by string to avoid @wordpress/editor dependency.
|
|
46
|
+
// eslint-disable-next-line @wordpress/data-no-store-string-literals
|
|
47
|
+
const { getCurrentPostId, getCurrentPostType, getCurrentTemplateId } =
|
|
48
|
+
select( 'core/editor' );
|
|
49
|
+
const currentPostType = getCurrentPostType();
|
|
50
|
+
const templateId =
|
|
51
|
+
getCurrentTemplateId() ||
|
|
52
|
+
( currentPostType === 'wp_template' ? getCurrentPostId() : null );
|
|
53
|
+
|
|
54
|
+
return templateId
|
|
55
|
+
? select( coreStore ).getEditedEntityRecord(
|
|
56
|
+
'postType',
|
|
57
|
+
'wp_template',
|
|
58
|
+
templateId
|
|
59
|
+
)?.slug
|
|
60
|
+
: null;
|
|
61
|
+
}, [] );
|
|
62
|
+
|
|
63
|
+
const taxonomyMatches = templateSlug?.match(
|
|
64
|
+
/^(category|tag|taxonomy-([^-]+))$|^(((category|tag)|taxonomy-([^-]+))-(.+))$/
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
let taxonomy;
|
|
68
|
+
let termSlug;
|
|
69
|
+
|
|
70
|
+
if ( taxonomyMatches ) {
|
|
71
|
+
// If it's for all taxonomies of a type (e.g., category, tag).
|
|
72
|
+
if ( taxonomyMatches[ 1 ] ) {
|
|
73
|
+
taxonomy = taxonomyMatches[ 2 ]
|
|
74
|
+
? taxonomyMatches[ 2 ]
|
|
75
|
+
: taxonomyMatches[ 1 ];
|
|
76
|
+
}
|
|
77
|
+
// If it's for a specific term (e.g., category-news, tag-featured).
|
|
78
|
+
else if ( taxonomyMatches[ 3 ] ) {
|
|
79
|
+
taxonomy = taxonomyMatches[ 6 ]
|
|
80
|
+
? taxonomyMatches[ 6 ]
|
|
81
|
+
: taxonomyMatches[ 4 ];
|
|
82
|
+
termSlug = taxonomyMatches[ 7 ];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
taxonomy = taxonomy === 'tag' ? 'post_tag' : taxonomy;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return useSelect(
|
|
89
|
+
( select ) => {
|
|
90
|
+
if ( ! taxonomy || ! termSlug ) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const { getEntityRecords } = select( coreStore );
|
|
95
|
+
|
|
96
|
+
const termRecords = getEntityRecords( 'taxonomy', taxonomy, {
|
|
97
|
+
slug: termSlug,
|
|
98
|
+
per_page: 1,
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
if ( termRecords && termRecords[ 0 ] ) {
|
|
102
|
+
return termRecords[ 0 ].description || '';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return '';
|
|
106
|
+
},
|
|
107
|
+
[ taxonomy, termSlug ]
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"ancestor": [ "core/terms-query" ],
|
|
9
9
|
"description": "Contains the block elements used to render a taxonomy term, like the name, description, and more.",
|
|
10
10
|
"textdomain": "default",
|
|
11
|
-
"usesContext": [ "termQuery" ],
|
|
11
|
+
"usesContext": [ "termQuery", "termsToShow" ],
|
|
12
12
|
"attributes": {
|
|
13
13
|
"namespace": {
|
|
14
14
|
"type": "string"
|
|
@@ -191,13 +191,13 @@ export default function TermTemplateEdit( {
|
|
|
191
191
|
clientId,
|
|
192
192
|
setAttributes,
|
|
193
193
|
context: {
|
|
194
|
+
termsToShow,
|
|
194
195
|
termQuery: {
|
|
195
196
|
taxonomy,
|
|
196
197
|
order,
|
|
197
198
|
orderBy,
|
|
198
199
|
hideEmpty,
|
|
199
200
|
hierarchical,
|
|
200
|
-
parent,
|
|
201
201
|
perPage = 10,
|
|
202
202
|
} = {},
|
|
203
203
|
},
|
|
@@ -222,13 +222,18 @@ export default function TermTemplateEdit( {
|
|
|
222
222
|
queryArgs
|
|
223
223
|
);
|
|
224
224
|
|
|
225
|
-
// Filter to show only top-level terms if "Show only top-level terms" is enabled.
|
|
226
225
|
const filteredTerms = useMemo( () => {
|
|
227
|
-
if ( ! terms
|
|
228
|
-
return
|
|
226
|
+
if ( ! terms ) {
|
|
227
|
+
return [];
|
|
229
228
|
}
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
if ( termsToShow === 'top-level' ) {
|
|
230
|
+
return terms.filter( ( term ) => ! term.parent );
|
|
231
|
+
}
|
|
232
|
+
if ( termsToShow === 'subterms' ) {
|
|
233
|
+
return terms.filter( ( term ) => term.parent );
|
|
234
|
+
}
|
|
235
|
+
return terms;
|
|
236
|
+
}, [ terms, termsToShow ] );
|
|
232
237
|
|
|
233
238
|
const { blocks, variations, defaultVariation } = useSelect(
|
|
234
239
|
( select ) => {
|
|
@@ -27,7 +27,8 @@ function render_block_core_term_template( $attributes, $content, $block ) {
|
|
|
27
27
|
return '';
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
$query
|
|
30
|
+
$query = $query_block_context['termQuery'];
|
|
31
|
+
$terms_to_show = $query_block_context['termsToShow'] ?? 'all';
|
|
31
32
|
|
|
32
33
|
$query_args = array(
|
|
33
34
|
'taxonomy' => $query['taxonomy'] ?? 'category',
|
|
@@ -39,13 +40,18 @@ function render_block_core_term_template( $attributes, $content, $block ) {
|
|
|
39
40
|
'exclude' => $query['exclude'] ?? array(),
|
|
40
41
|
);
|
|
41
42
|
|
|
42
|
-
//
|
|
43
|
-
if ( ! empty( $query['hierarchical'] )
|
|
44
|
-
$query_args['parent'] = $query['parent'];
|
|
45
|
-
} elseif ( ! empty( $query['hierarchical'] ) ) {
|
|
43
|
+
// We set parent to 0 only if we show all terms as hierarchical or we show top-level terms.
|
|
44
|
+
if ( ( 'all' === $terms_to_show && ! empty( $query['hierarchical'] ) ) || 'top-level' === $terms_to_show ) {
|
|
46
45
|
$query_args['parent'] = 0;
|
|
47
|
-
} elseif (
|
|
48
|
-
|
|
46
|
+
} elseif ( 'subterms' === $terms_to_show ) {
|
|
47
|
+
// Check if we're in a taxonomy archive context.
|
|
48
|
+
if ( is_tax( $query_args['taxonomy'] ) ) {
|
|
49
|
+
// Get the current term ID from the queried object.
|
|
50
|
+
$current_term_id = get_queried_object_id();
|
|
51
|
+
if ( $current_term_id && $current_term_id > 0 ) {
|
|
52
|
+
$query_args['parent'] = $current_term_id;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
$terms_query = new WP_Term_Query( $query_args );
|
|
@@ -23,10 +23,15 @@
|
|
|
23
23
|
"hideEmpty": true,
|
|
24
24
|
"include": [],
|
|
25
25
|
"exclude": [],
|
|
26
|
-
"parent":
|
|
26
|
+
"parent": false,
|
|
27
27
|
"hierarchical": false
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
+
"termsToShow": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"default": "all",
|
|
33
|
+
"enum": [ "all", "top-level", "subterms" ]
|
|
34
|
+
},
|
|
30
35
|
"tagName": {
|
|
31
36
|
"type": "string",
|
|
32
37
|
"default": "div"
|
|
@@ -37,7 +42,8 @@
|
|
|
37
42
|
},
|
|
38
43
|
"providesContext": {
|
|
39
44
|
"termQueryId": "termQueryId",
|
|
40
|
-
"termQuery": "termQuery"
|
|
45
|
+
"termQuery": "termQuery",
|
|
46
|
+
"termsToShow": "termsToShow"
|
|
41
47
|
},
|
|
42
48
|
"supports": {
|
|
43
49
|
"align": [ "wide", "full" ],
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
InspectorControls,
|
|
7
|
+
privateApis as blockEditorPrivateApis,
|
|
8
|
+
} from '@wordpress/block-editor';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { unlock } from '../../lock-unlock';
|
|
14
|
+
|
|
15
|
+
const { HTMLElementControl } = unlock( blockEditorPrivateApis );
|
|
16
|
+
|
|
17
|
+
export default function AdvancedControls( {
|
|
18
|
+
TagName,
|
|
19
|
+
setAttributes,
|
|
20
|
+
clientId,
|
|
21
|
+
} ) {
|
|
22
|
+
return (
|
|
23
|
+
<InspectorControls group="advanced">
|
|
24
|
+
<HTMLElementControl
|
|
25
|
+
tagName={ TagName }
|
|
26
|
+
onChange={ ( value ) => setAttributes( { tagName: value } ) }
|
|
27
|
+
clientId={ clientId }
|
|
28
|
+
options={ [
|
|
29
|
+
{ label: __( 'Default (<div>)' ), value: 'div' },
|
|
30
|
+
{ label: '<main>', value: 'main' },
|
|
31
|
+
{ label: '<section>', value: 'section' },
|
|
32
|
+
{ label: '<aside>', value: 'aside' },
|
|
33
|
+
] }
|
|
34
|
+
/>
|
|
35
|
+
</InspectorControls>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
RadioControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
const getOptions = ( displayTopLevelControl, displaySubtermsControl ) => {
|
|
11
|
+
const options = [ { label: __( 'Show all' ), value: 'all' } ];
|
|
12
|
+
|
|
13
|
+
if ( displayTopLevelControl ) {
|
|
14
|
+
options.push( {
|
|
15
|
+
label: __( 'Show only top level terms' ),
|
|
16
|
+
value: 'top-level',
|
|
17
|
+
} );
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if ( displaySubtermsControl ) {
|
|
21
|
+
options.push( {
|
|
22
|
+
label: __( 'Show subterms only' ),
|
|
23
|
+
value: 'subterms',
|
|
24
|
+
description: __(
|
|
25
|
+
'Display subterms of the current term. E.g. subcategories of current category.'
|
|
26
|
+
),
|
|
27
|
+
} );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return options;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const allTermsQuery = {
|
|
34
|
+
include: [],
|
|
35
|
+
exclude: [],
|
|
36
|
+
parent: false,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const topLevelTermsQuery = {
|
|
40
|
+
include: [],
|
|
41
|
+
exclude: [],
|
|
42
|
+
parent: 0,
|
|
43
|
+
hierarchical: false,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getQueryAttributes = ( value ) => {
|
|
47
|
+
if ( value === 'top-level' ) {
|
|
48
|
+
return topLevelTermsQuery;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// For 'all' and 'subterms', we fetch all terms and then filter them as the tree is built in Term Template.
|
|
52
|
+
return allTermsQuery;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default function DisplayOptions( {
|
|
56
|
+
attributes,
|
|
57
|
+
displayTopLevelControl,
|
|
58
|
+
displaySubtermsControl,
|
|
59
|
+
setAttributes,
|
|
60
|
+
} ) {
|
|
61
|
+
const { termQuery, termsToShow } = attributes;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<ToolsPanelItem
|
|
65
|
+
hasValue={ () => termsToShow !== 'all' }
|
|
66
|
+
label={ __( 'Terms to show' ) }
|
|
67
|
+
onDeselect={ () => setAttributes( { termsToShow: 'all' } ) }
|
|
68
|
+
isShownByDefault
|
|
69
|
+
>
|
|
70
|
+
<RadioControl
|
|
71
|
+
label={ __( 'Terms to show' ) }
|
|
72
|
+
options={ getOptions(
|
|
73
|
+
displayTopLevelControl,
|
|
74
|
+
displaySubtermsControl
|
|
75
|
+
) }
|
|
76
|
+
selected={ termsToShow }
|
|
77
|
+
onChange={ ( value ) => {
|
|
78
|
+
const queryAttributes = getQueryAttributes( value );
|
|
79
|
+
setAttributes( {
|
|
80
|
+
termsToShow: value,
|
|
81
|
+
termQuery: { ...termQuery, ...queryAttributes },
|
|
82
|
+
} );
|
|
83
|
+
} }
|
|
84
|
+
/>
|
|
85
|
+
</ToolsPanelItem>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
ToggleControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
export default function EmptyTermsControl( { attributes, setQuery } ) {
|
|
11
|
+
const { termQuery } = attributes;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ToolsPanelItem
|
|
15
|
+
hasValue={ () => termQuery.hideEmpty !== true }
|
|
16
|
+
label={ __( 'Show empty terms' ) }
|
|
17
|
+
onDeselect={ () => setQuery( { hideEmpty: true } ) }
|
|
18
|
+
isShownByDefault
|
|
19
|
+
>
|
|
20
|
+
<ToggleControl
|
|
21
|
+
__nextHasNoMarginBottom
|
|
22
|
+
label={ __( 'Show empty terms' ) }
|
|
23
|
+
checked={ ! termQuery.hideEmpty }
|
|
24
|
+
onChange={ ( showEmpty ) =>
|
|
25
|
+
setQuery( { hideEmpty: ! showEmpty } )
|
|
26
|
+
}
|
|
27
|
+
/>
|
|
28
|
+
</ToolsPanelItem>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
ToggleControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
export default function HierarchyControl( { attributes, setQuery } ) {
|
|
11
|
+
const { termQuery } = attributes;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ToolsPanelItem
|
|
15
|
+
hasValue={ () => termQuery.hierarchical !== false }
|
|
16
|
+
label={ __( 'Show hierarchy' ) }
|
|
17
|
+
onDeselect={ () => setQuery( { hierarchical: false } ) }
|
|
18
|
+
isShownByDefault
|
|
19
|
+
>
|
|
20
|
+
<ToggleControl
|
|
21
|
+
__nextHasNoMarginBottom
|
|
22
|
+
label={ __( 'Show hierarchy' ) }
|
|
23
|
+
checked={ termQuery.hierarchical }
|
|
24
|
+
onChange={ ( hierarchical ) => {
|
|
25
|
+
setQuery( { hierarchical } );
|
|
26
|
+
} }
|
|
27
|
+
/>
|
|
28
|
+
</ToolsPanelItem>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { __experimentalToolsPanel as ToolsPanel } from '@wordpress/components';
|
|
6
|
+
import { InspectorControls } from '@wordpress/block-editor';
|
|
7
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
8
|
+
import { useSelect } from '@wordpress/data';
|
|
9
|
+
import { useMemo } from '@wordpress/element';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { useToolsPanelDropdownMenuProps } from '../../utils/hooks';
|
|
15
|
+
import TaxonomyControl from './taxonomy-control';
|
|
16
|
+
import OrderingControls from './ordering-controls';
|
|
17
|
+
import DisplayOptions from './display-options';
|
|
18
|
+
import HierarchyControl from './hierarchy-control';
|
|
19
|
+
import EmptyTermsControl from './empty-terms-control';
|
|
20
|
+
import MaxTermsControl from './max-terms-control';
|
|
21
|
+
import AdvancedControls from './advanced-controls';
|
|
22
|
+
|
|
23
|
+
const usePublicTaxonomies = () => {
|
|
24
|
+
const taxonomies = useSelect(
|
|
25
|
+
( select ) => select( coreStore ).getTaxonomies( { per_page: -1 } ),
|
|
26
|
+
[]
|
|
27
|
+
);
|
|
28
|
+
return useMemo( () => {
|
|
29
|
+
return (
|
|
30
|
+
taxonomies?.filter(
|
|
31
|
+
( { visibility } ) => visibility?.publicly_queryable
|
|
32
|
+
) || []
|
|
33
|
+
);
|
|
34
|
+
}, [ taxonomies ] );
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default function TermsQueryInspectorControls( {
|
|
38
|
+
attributes,
|
|
39
|
+
setQuery,
|
|
40
|
+
setAttributes,
|
|
41
|
+
TagName,
|
|
42
|
+
clientId,
|
|
43
|
+
} ) {
|
|
44
|
+
const { termQuery, termsToShow } = attributes;
|
|
45
|
+
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
46
|
+
const taxonomies = usePublicTaxonomies();
|
|
47
|
+
|
|
48
|
+
const { templateSlug } = useSelect( ( select ) => {
|
|
49
|
+
// @wordpress/block-library should not depend on @wordpress/editor.
|
|
50
|
+
// Blocks can be loaded into a *non-post* block editor, so to avoid
|
|
51
|
+
// declaring @wordpress/editor as a dependency, we must access its
|
|
52
|
+
// store by string.
|
|
53
|
+
// The solution here is to split WP specific blocks from generic blocks.
|
|
54
|
+
// eslint-disable-next-line @wordpress/data-no-store-string-literals
|
|
55
|
+
const { getEditedPostSlug } = select( 'core/editor' );
|
|
56
|
+
return {
|
|
57
|
+
templateSlug: getEditedPostSlug(),
|
|
58
|
+
};
|
|
59
|
+
}, [] );
|
|
60
|
+
|
|
61
|
+
const taxonomyOptions = taxonomies.map( ( taxonomy ) => ( {
|
|
62
|
+
label: taxonomy.name,
|
|
63
|
+
value: taxonomy.slug,
|
|
64
|
+
} ) );
|
|
65
|
+
|
|
66
|
+
const isTaxonomyHierarchical = taxonomies.find(
|
|
67
|
+
( taxonomy ) => taxonomy.slug === termQuery.taxonomy
|
|
68
|
+
)?.hierarchical;
|
|
69
|
+
|
|
70
|
+
const isTaxonomyMatchingTemplate =
|
|
71
|
+
typeof templateSlug === 'string' &&
|
|
72
|
+
templateSlug.includes( termQuery.taxonomy );
|
|
73
|
+
|
|
74
|
+
const displaySubtermsControl =
|
|
75
|
+
isTaxonomyHierarchical && isTaxonomyMatchingTemplate;
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<InspectorControls>
|
|
80
|
+
<ToolsPanel
|
|
81
|
+
label={ __( 'Terms Query Settings' ) }
|
|
82
|
+
resetAll={ () => {
|
|
83
|
+
setAttributes( {
|
|
84
|
+
termQuery: {
|
|
85
|
+
taxonomy: 'category',
|
|
86
|
+
order: 'asc',
|
|
87
|
+
orderBy: 'name',
|
|
88
|
+
hideEmpty: true,
|
|
89
|
+
hierarchical: false,
|
|
90
|
+
parent: false,
|
|
91
|
+
perPage: 10,
|
|
92
|
+
},
|
|
93
|
+
termsToShow: 'all',
|
|
94
|
+
} );
|
|
95
|
+
} }
|
|
96
|
+
dropdownMenuProps={ dropdownMenuProps }
|
|
97
|
+
>
|
|
98
|
+
<TaxonomyControl
|
|
99
|
+
attributes={ attributes }
|
|
100
|
+
setQuery={ setQuery }
|
|
101
|
+
setAttributes={ setAttributes }
|
|
102
|
+
taxonomyOptions={ taxonomyOptions }
|
|
103
|
+
/>
|
|
104
|
+
<OrderingControls
|
|
105
|
+
attributes={ attributes }
|
|
106
|
+
setQuery={ setQuery }
|
|
107
|
+
/>
|
|
108
|
+
<EmptyTermsControl
|
|
109
|
+
attributes={ attributes }
|
|
110
|
+
setQuery={ setQuery }
|
|
111
|
+
/>
|
|
112
|
+
<DisplayOptions
|
|
113
|
+
attributes={ attributes }
|
|
114
|
+
setAttributes={ setAttributes }
|
|
115
|
+
displayTopLevelControl={ isTaxonomyHierarchical }
|
|
116
|
+
displaySubtermsControl={ displaySubtermsControl }
|
|
117
|
+
/>
|
|
118
|
+
<MaxTermsControl
|
|
119
|
+
attributes={ attributes }
|
|
120
|
+
setQuery={ setQuery }
|
|
121
|
+
/>
|
|
122
|
+
{ isTaxonomyHierarchical && termsToShow === 'all' && (
|
|
123
|
+
<HierarchyControl
|
|
124
|
+
attributes={ attributes }
|
|
125
|
+
setQuery={ setQuery }
|
|
126
|
+
/>
|
|
127
|
+
) }
|
|
128
|
+
</ToolsPanel>
|
|
129
|
+
</InspectorControls>
|
|
130
|
+
<AdvancedControls
|
|
131
|
+
TagName={ TagName }
|
|
132
|
+
setAttributes={ setAttributes }
|
|
133
|
+
clientId={ clientId }
|
|
134
|
+
/>
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
RangeControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
export default function MaxTermsControl( { attributes, setQuery } ) {
|
|
11
|
+
const { termQuery } = attributes;
|
|
12
|
+
|
|
13
|
+
// Only show pagination control when not hierarchical.
|
|
14
|
+
if ( termQuery.hierarchical ) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ToolsPanelItem
|
|
20
|
+
hasValue={ () => termQuery.perPage !== 10 }
|
|
21
|
+
label={ __( 'Max terms' ) }
|
|
22
|
+
onDeselect={ () => setQuery( { perPage: 10 } ) }
|
|
23
|
+
isShownByDefault
|
|
24
|
+
>
|
|
25
|
+
<RangeControl
|
|
26
|
+
__nextHasNoMarginBottom
|
|
27
|
+
__next40pxDefaultSize
|
|
28
|
+
label={ __( 'Max terms' ) }
|
|
29
|
+
value={ termQuery.perPage }
|
|
30
|
+
min={ 0 }
|
|
31
|
+
max={ 100 }
|
|
32
|
+
onChange={ ( perPage ) => {
|
|
33
|
+
// Show all terms (-1) when 0 is selected.
|
|
34
|
+
setQuery( {
|
|
35
|
+
perPage: perPage === 0 ? -1 : perPage,
|
|
36
|
+
} );
|
|
37
|
+
} }
|
|
38
|
+
help={ __(
|
|
39
|
+
'Limit the number of terms you want to show. To show all terms, use 0 (zero).'
|
|
40
|
+
) }
|
|
41
|
+
/>
|
|
42
|
+
</ToolsPanelItem>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
SelectControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
export default function OrderingControls( { attributes, setQuery } ) {
|
|
11
|
+
const { termQuery } = attributes;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ToolsPanelItem
|
|
15
|
+
hasValue={ () =>
|
|
16
|
+
termQuery.orderBy !== 'name' || termQuery.order !== 'asc'
|
|
17
|
+
}
|
|
18
|
+
label={ __( 'Order by' ) }
|
|
19
|
+
onDeselect={ () => setQuery( { orderBy: 'name', order: 'asc' } ) }
|
|
20
|
+
isShownByDefault
|
|
21
|
+
>
|
|
22
|
+
<SelectControl
|
|
23
|
+
__nextHasNoMarginBottom
|
|
24
|
+
__next40pxDefaultSize
|
|
25
|
+
label={ __( 'Order by' ) }
|
|
26
|
+
options={ [
|
|
27
|
+
{
|
|
28
|
+
label: __( 'Name: A → Z' ),
|
|
29
|
+
value: 'name/asc',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: __( 'Name: Z → A' ),
|
|
33
|
+
value: 'name/desc',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
label: __( 'Count, high to low' ),
|
|
37
|
+
value: 'count/desc',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: __( 'Count, low to high' ),
|
|
41
|
+
value: 'count/asc',
|
|
42
|
+
},
|
|
43
|
+
] }
|
|
44
|
+
value={ termQuery.orderBy + '/' + termQuery.order }
|
|
45
|
+
onChange={ ( orderBy ) => {
|
|
46
|
+
const [ newOrderBy, newOrder ] = orderBy.split( '/' );
|
|
47
|
+
setQuery( {
|
|
48
|
+
orderBy: newOrderBy,
|
|
49
|
+
order: newOrder,
|
|
50
|
+
} );
|
|
51
|
+
} }
|
|
52
|
+
/>
|
|
53
|
+
</ToolsPanelItem>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import {
|
|
6
|
+
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
7
|
+
SelectControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
export default function TaxonomyControl( {
|
|
11
|
+
attributes,
|
|
12
|
+
setQuery,
|
|
13
|
+
setAttributes,
|
|
14
|
+
taxonomyOptions,
|
|
15
|
+
} ) {
|
|
16
|
+
const { termQuery } = attributes;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<ToolsPanelItem
|
|
20
|
+
hasValue={ () => termQuery.taxonomy !== 'category' }
|
|
21
|
+
label={ __( 'Taxonomy' ) }
|
|
22
|
+
onDeselect={ () => {
|
|
23
|
+
setQuery( { taxonomy: 'category' } );
|
|
24
|
+
setAttributes( { termsToShow: 'all' } );
|
|
25
|
+
} }
|
|
26
|
+
isShownByDefault
|
|
27
|
+
>
|
|
28
|
+
<SelectControl
|
|
29
|
+
__nextHasNoMarginBottom
|
|
30
|
+
__next40pxDefaultSize
|
|
31
|
+
label={ __( 'Taxonomy' ) }
|
|
32
|
+
options={ taxonomyOptions }
|
|
33
|
+
value={ termQuery.taxonomy }
|
|
34
|
+
onChange={ ( selectedTaxonomy ) => {
|
|
35
|
+
setQuery( { taxonomy: selectedTaxonomy } );
|
|
36
|
+
setAttributes( { termsToShow: 'all' } );
|
|
37
|
+
} }
|
|
38
|
+
/>
|
|
39
|
+
</ToolsPanelItem>
|
|
40
|
+
);
|
|
41
|
+
}
|