UNPKG

@wordpress/block-library

Version:
42 lines (41 loc) • 1.11 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_core_data = require("@wordpress/core-data"); let _wordpress_data = require("@wordpress/data"); // packages/block-library/src/post-terms/use-post-terms.js const EMPTY_ARRAY = []; function usePostTerms({ postId, term }) { const { slug } = term; return (0, _wordpress_data.useSelect)((select) => { if (!term?.visibility?.publicly_queryable || !postId) return { postTerms: EMPTY_ARRAY, isLoading: false, hasPostTerms: false }; const { getEntityRecords, isResolving } = select(_wordpress_core_data.store); const taxonomyArgs = [ "taxonomy", slug, { post: postId, per_page: -1, context: "view" } ]; const terms = getEntityRecords(...taxonomyArgs); return { postTerms: terms, isLoading: isResolving("getEntityRecords", taxonomyArgs), hasPostTerms: !!terms?.length }; }, [ postId, term?.visibility?.publicly_queryable, slug ]); } exports.default = usePostTerms; //# sourceMappingURL=use-post-terms.cjs.map