@wordpress/block-library 8.0.0 → 8.1.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/CHANGELOG.md +2 -0
- package/build/categories/edit.js +1 -1
- package/build/categories/edit.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +1 -1
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/freeform/edit.js +21 -6
- package/build/freeform/edit.js.map +1 -1
- package/build/freeform/modal.js +97 -0
- package/build/freeform/modal.js.map +1 -0
- package/build/gallery/edit.js +13 -2
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/gallery.js +2 -16
- package/build/gallery/gallery.js.map +1 -1
- package/build/image/image.js +1 -0
- package/build/image/image.js.map +1 -1
- package/build/media-text/edit.js +1 -0
- package/build/media-text/edit.js.map +1 -1
- package/build/missing/edit.native.js +2 -2
- package/build/missing/edit.native.js.map +1 -1
- package/build/navigation/edit/index.js +3 -4
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/menu-inspector-controls.js +29 -7
- package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +11 -8
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/utils.js +81 -0
- package/build/navigation/edit/utils.js.map +1 -1
- package/build/navigation-link/edit.js +4 -58
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-submenu/edit.js +7 -72
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/page-list/edit.js +16 -15
- package/build/page-list/edit.js.map +1 -1
- package/build/page-list/index.js +29 -2
- package/build/page-list/index.js.map +1 -1
- package/build/page-list-item/edit.js +9 -5
- package/build/page-list-item/edit.js.map +1 -1
- package/build/post-featured-image/overlay.js +0 -1
- package/build/post-featured-image/overlay.js.map +1 -1
- package/build/query/edit/index.js +2 -1
- package/build/query/edit/index.js.map +1 -1
- package/build/query/edit/inspector-controls/index.js +10 -5
- package/build/query/edit/inspector-controls/index.js.map +1 -1
- package/build/query/edit/inspector-controls/taxonomy-controls.js +101 -37
- package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
- package/build/query/edit/query-content.js +2 -3
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/edit/query-placeholder.js +17 -12
- package/build/query/edit/query-placeholder.js.map +1 -1
- package/build/query/utils.js +73 -1
- package/build/query/utils.js.map +1 -1
- package/build/search/edit.js +2 -2
- package/build/search/edit.js.map +1 -1
- package/build/social-link/edit.js.map +1 -1
- package/build/social-links/edit.js +0 -1
- package/build/social-links/edit.js.map +1 -1
- package/build/table-of-contents/edit.js +1 -1
- package/build/table-of-contents/edit.js.map +1 -1
- package/build/template-part/edit/advanced-controls.js +11 -1
- package/build/template-part/edit/advanced-controls.js.map +1 -1
- package/build/template-part/edit/import-controls.js +160 -0
- package/build/template-part/edit/import-controls.js.map +1 -0
- package/build/template-part/edit/index.js +2 -1
- package/build/template-part/edit/index.js.map +1 -1
- package/build/template-part/edit/utils/transformers.js +48 -0
- package/build/template-part/edit/utils/transformers.js.map +1 -0
- package/build-module/categories/edit.js +1 -1
- package/build-module/categories/edit.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +3 -3
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/freeform/edit.js +22 -8
- package/build-module/freeform/edit.js.map +1 -1
- package/build-module/freeform/modal.js +90 -0
- package/build-module/freeform/modal.js.map +1 -0
- package/build-module/gallery/edit.js +14 -3
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/gallery.js +3 -16
- package/build-module/gallery/gallery.js.map +1 -1
- package/build-module/image/image.js +1 -0
- package/build-module/image/image.js.map +1 -1
- package/build-module/media-text/edit.js +1 -0
- package/build-module/media-text/edit.js.map +1 -1
- package/build-module/missing/edit.native.js +2 -2
- package/build-module/missing/edit.native.js.map +1 -1
- package/build-module/navigation/edit/index.js +3 -4
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/menu-inspector-controls.js +30 -9
- package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +12 -9
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/utils.js +75 -0
- package/build-module/navigation/edit/utils.js.map +1 -1
- package/build-module/navigation-link/edit.js +4 -59
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +6 -72
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/page-list/edit.js +17 -15
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/page-list/index.js +30 -3
- package/build-module/page-list/index.js.map +1 -1
- package/build-module/page-list-item/edit.js +9 -6
- package/build-module/page-list-item/edit.js.map +1 -1
- package/build-module/post-featured-image/overlay.js +0 -1
- package/build-module/post-featured-image/overlay.js.map +1 -1
- package/build-module/query/edit/index.js +2 -1
- package/build-module/query/edit/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/index.js +10 -5
- package/build-module/query/edit/inspector-controls/index.js.map +1 -1
- package/build-module/query/edit/inspector-controls/taxonomy-controls.js +99 -35
- package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
- package/build-module/query/edit/query-content.js +1 -1
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/edit/query-placeholder.js +16 -12
- package/build-module/query/edit/query-placeholder.js.map +1 -1
- package/build-module/query/utils.js +69 -0
- package/build-module/query/utils.js.map +1 -1
- package/build-module/search/edit.js +2 -2
- package/build-module/search/edit.js.map +1 -1
- package/build-module/social-link/edit.js +2 -2
- package/build-module/social-link/edit.js.map +1 -1
- package/build-module/social-links/edit.js +0 -1
- package/build-module/social-links/edit.js.map +1 -1
- package/build-module/table-of-contents/edit.js +1 -1
- package/build-module/table-of-contents/edit.js.map +1 -1
- package/build-module/template-part/edit/advanced-controls.js +10 -1
- package/build-module/template-part/edit/advanced-controls.js.map +1 -1
- package/build-module/template-part/edit/import-controls.js +146 -0
- package/build-module/template-part/edit/import-controls.js.map +1 -0
- package/build-module/template-part/edit/index.js +2 -1
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/template-part/edit/utils/transformers.js +40 -0
- package/build-module/template-part/edit/utils/transformers.js.map +1 -0
- package/build-style/archives/editor-rtl.css +3 -3
- package/build-style/archives/editor.css +3 -3
- package/build-style/archives/style-rtl.css +3 -3
- package/build-style/archives/style.css +3 -3
- package/build-style/audio/editor-rtl.css +3 -3
- package/build-style/audio/editor.css +3 -3
- package/build-style/audio/style-rtl.css +3 -3
- package/build-style/audio/style.css +3 -3
- package/build-style/audio/theme-rtl.css +3 -3
- package/build-style/audio/theme.css +3 -3
- package/build-style/avatar/editor-rtl.css +3 -3
- package/build-style/avatar/editor.css +3 -3
- package/build-style/avatar/style-rtl.css +3 -3
- package/build-style/avatar/style.css +3 -3
- package/build-style/block/editor-rtl.css +3 -3
- package/build-style/block/editor.css +3 -3
- package/build-style/button/editor-rtl.css +3 -3
- package/build-style/button/editor.css +3 -3
- package/build-style/button/style-rtl.css +3 -3
- package/build-style/button/style.css +3 -3
- package/build-style/buttons/editor-rtl.css +3 -3
- package/build-style/buttons/editor.css +3 -3
- package/build-style/buttons/style-rtl.css +3 -3
- package/build-style/buttons/style.css +3 -3
- package/build-style/calendar/style-rtl.css +3 -3
- package/build-style/calendar/style.css +3 -3
- package/build-style/categories/editor-rtl.css +3 -3
- package/build-style/categories/editor.css +3 -3
- package/build-style/categories/style-rtl.css +3 -3
- package/build-style/categories/style.css +3 -3
- package/build-style/classic-rtl.css +3 -3
- package/build-style/classic.css +3 -3
- package/build-style/code/editor-rtl.css +3 -3
- package/build-style/code/editor.css +3 -3
- package/build-style/code/style-rtl.css +3 -3
- package/build-style/code/style.css +3 -3
- package/build-style/code/theme-rtl.css +3 -3
- package/build-style/code/theme.css +3 -3
- package/build-style/columns/editor-rtl.css +3 -3
- package/build-style/columns/editor.css +3 -3
- package/build-style/columns/style-rtl.css +3 -3
- package/build-style/columns/style.css +3 -3
- package/build-style/comment-author-avatar/editor-rtl.css +3 -3
- package/build-style/comment-author-avatar/editor.css +3 -3
- package/build-style/comment-content/style-rtl.css +3 -3
- package/build-style/comment-content/style.css +3 -3
- package/build-style/comment-template/style-rtl.css +3 -3
- package/build-style/comment-template/style.css +3 -3
- package/build-style/comments/editor-rtl.css +3 -3
- package/build-style/comments/editor.css +3 -3
- package/build-style/comments/style-rtl.css +3 -3
- package/build-style/comments/style.css +3 -3
- package/build-style/comments-pagination/editor-rtl.css +3 -3
- package/build-style/comments-pagination/editor.css +3 -3
- package/build-style/comments-pagination/style-rtl.css +3 -3
- package/build-style/comments-pagination/style.css +3 -3
- package/build-style/comments-pagination-numbers/editor-rtl.css +3 -3
- package/build-style/comments-pagination-numbers/editor.css +3 -3
- package/build-style/comments-title/editor-rtl.css +3 -3
- package/build-style/comments-title/editor.css +3 -3
- package/build-style/common-rtl.css +3 -3
- package/build-style/common.css +3 -3
- package/build-style/cover/editor-rtl.css +3 -3
- package/build-style/cover/editor.css +3 -3
- package/build-style/cover/style-rtl.css +3 -3
- package/build-style/cover/style.css +3 -3
- package/build-style/editor-elements-rtl.css +3 -3
- package/build-style/editor-elements.css +3 -3
- package/build-style/editor-rtl.css +7 -9
- package/build-style/editor.css +7 -9
- package/build-style/elements-rtl.css +3 -3
- package/build-style/elements.css +3 -3
- package/build-style/embed/editor-rtl.css +3 -3
- package/build-style/embed/editor.css +3 -3
- package/build-style/embed/style-rtl.css +3 -3
- package/build-style/embed/style.css +3 -3
- package/build-style/embed/theme-rtl.css +3 -3
- package/build-style/embed/theme.css +3 -3
- package/build-style/file/editor-rtl.css +3 -3
- package/build-style/file/editor.css +3 -3
- package/build-style/file/style-rtl.css +3 -3
- package/build-style/file/style.css +3 -3
- package/build-style/freeform/editor-rtl.css +3 -3
- package/build-style/freeform/editor.css +3 -3
- package/build-style/gallery/editor-rtl.css +3 -3
- package/build-style/gallery/editor.css +3 -3
- package/build-style/gallery/style-rtl.css +3 -3
- package/build-style/gallery/style.css +3 -3
- package/build-style/gallery/theme-rtl.css +3 -3
- package/build-style/gallery/theme.css +3 -3
- package/build-style/group/editor-rtl.css +3 -3
- package/build-style/group/editor.css +3 -3
- package/build-style/group/style-rtl.css +3 -3
- package/build-style/group/style.css +3 -3
- package/build-style/group/theme-rtl.css +3 -3
- package/build-style/group/theme.css +3 -3
- package/build-style/heading/style-rtl.css +3 -3
- package/build-style/heading/style.css +3 -3
- package/build-style/html/editor-rtl.css +3 -3
- package/build-style/html/editor.css +3 -3
- package/build-style/image/editor-rtl.css +3 -3
- package/build-style/image/editor.css +3 -3
- package/build-style/image/style-rtl.css +3 -3
- package/build-style/image/style.css +3 -3
- package/build-style/image/theme-rtl.css +3 -3
- package/build-style/image/theme.css +3 -3
- package/build-style/latest-comments/style-rtl.css +3 -3
- package/build-style/latest-comments/style.css +3 -3
- package/build-style/latest-posts/editor-rtl.css +3 -3
- package/build-style/latest-posts/editor.css +3 -3
- package/build-style/latest-posts/style-rtl.css +3 -3
- package/build-style/latest-posts/style.css +3 -3
- package/build-style/list/style-rtl.css +3 -3
- package/build-style/list/style.css +3 -3
- package/build-style/media-text/editor-rtl.css +3 -3
- package/build-style/media-text/editor.css +3 -3
- package/build-style/media-text/style-rtl.css +3 -3
- package/build-style/media-text/style.css +3 -3
- package/build-style/more/editor-rtl.css +3 -3
- package/build-style/more/editor.css +3 -3
- package/build-style/navigation/editor-rtl.css +3 -9
- package/build-style/navigation/editor.css +3 -9
- package/build-style/navigation/style-rtl.css +3 -4
- package/build-style/navigation/style.css +3 -4
- package/build-style/navigation-link/editor-rtl.css +3 -3
- package/build-style/navigation-link/editor.css +3 -3
- package/build-style/navigation-link/style-rtl.css +3 -3
- package/build-style/navigation-link/style.css +3 -3
- package/build-style/navigation-submenu/editor-rtl.css +3 -3
- package/build-style/navigation-submenu/editor.css +3 -3
- package/build-style/nextpage/editor-rtl.css +3 -3
- package/build-style/nextpage/editor.css +3 -3
- package/build-style/page-list/editor-rtl.css +7 -3
- package/build-style/page-list/editor.css +7 -3
- package/build-style/page-list/style-rtl.css +3 -3
- package/build-style/page-list/style.css +3 -3
- package/build-style/paragraph/editor-rtl.css +3 -3
- package/build-style/paragraph/editor.css +3 -3
- package/build-style/paragraph/style-rtl.css +3 -3
- package/build-style/paragraph/style.css +3 -3
- package/build-style/post-author/style-rtl.css +3 -3
- package/build-style/post-author/style.css +3 -3
- package/build-style/post-comments-form/editor-rtl.css +3 -3
- package/build-style/post-comments-form/editor.css +3 -3
- package/build-style/post-comments-form/style-rtl.css +3 -3
- package/build-style/post-comments-form/style.css +3 -3
- package/build-style/post-date/style-rtl.css +3 -3
- package/build-style/post-date/style.css +3 -3
- package/build-style/post-excerpt/editor-rtl.css +3 -3
- package/build-style/post-excerpt/editor.css +3 -3
- package/build-style/post-excerpt/style-rtl.css +3 -3
- package/build-style/post-excerpt/style.css +3 -3
- package/build-style/post-featured-image/editor-rtl.css +3 -3
- package/build-style/post-featured-image/editor.css +3 -3
- package/build-style/post-featured-image/style-rtl.css +3 -3
- package/build-style/post-featured-image/style.css +3 -3
- package/build-style/post-navigation-link/style-rtl.css +3 -3
- package/build-style/post-navigation-link/style.css +3 -3
- package/build-style/post-template/editor-rtl.css +3 -3
- package/build-style/post-template/editor.css +3 -3
- package/build-style/post-template/style-rtl.css +3 -3
- package/build-style/post-template/style.css +3 -3
- package/build-style/post-terms/style-rtl.css +3 -3
- package/build-style/post-terms/style.css +3 -3
- package/build-style/post-title/style-rtl.css +3 -3
- package/build-style/post-title/style.css +3 -3
- package/build-style/preformatted/style-rtl.css +3 -3
- package/build-style/preformatted/style.css +3 -3
- package/build-style/pullquote/editor-rtl.css +3 -3
- package/build-style/pullquote/editor.css +3 -3
- package/build-style/pullquote/style-rtl.css +3 -3
- package/build-style/pullquote/style.css +3 -3
- package/build-style/pullquote/theme-rtl.css +3 -3
- package/build-style/pullquote/theme.css +3 -3
- package/build-style/query/editor-rtl.css +3 -3
- package/build-style/query/editor.css +3 -3
- package/build-style/query-pagination/editor-rtl.css +3 -3
- package/build-style/query-pagination/editor.css +3 -3
- package/build-style/query-pagination/style-rtl.css +3 -3
- package/build-style/query-pagination/style.css +3 -3
- package/build-style/query-pagination-numbers/editor-rtl.css +3 -3
- package/build-style/query-pagination-numbers/editor.css +3 -3
- package/build-style/query-title/style-rtl.css +3 -3
- package/build-style/query-title/style.css +3 -3
- package/build-style/quote/style-rtl.css +3 -3
- package/build-style/quote/style.css +3 -3
- package/build-style/quote/theme-rtl.css +3 -3
- package/build-style/quote/theme.css +3 -3
- package/build-style/read-more/style-rtl.css +3 -3
- package/build-style/read-more/style.css +3 -3
- package/build-style/reset-rtl.css +3 -3
- package/build-style/reset.css +3 -3
- package/build-style/rss/editor-rtl.css +3 -3
- package/build-style/rss/editor.css +3 -3
- package/build-style/rss/style-rtl.css +3 -3
- package/build-style/rss/style.css +3 -3
- package/build-style/search/editor-rtl.css +3 -3
- package/build-style/search/editor.css +3 -3
- package/build-style/search/style-rtl.css +3 -3
- package/build-style/search/style.css +3 -3
- package/build-style/search/theme-rtl.css +3 -3
- package/build-style/search/theme.css +3 -3
- package/build-style/separator/editor-rtl.css +3 -3
- package/build-style/separator/editor.css +3 -3
- package/build-style/separator/style-rtl.css +3 -3
- package/build-style/separator/style.css +3 -3
- package/build-style/separator/theme-rtl.css +3 -3
- package/build-style/separator/theme.css +3 -3
- package/build-style/shortcode/editor-rtl.css +3 -3
- package/build-style/shortcode/editor.css +3 -3
- package/build-style/site-logo/editor-rtl.css +3 -3
- package/build-style/site-logo/editor.css +3 -3
- package/build-style/site-logo/style-rtl.css +3 -3
- package/build-style/site-logo/style.css +3 -3
- package/build-style/site-tagline/editor-rtl.css +3 -3
- package/build-style/site-tagline/editor.css +3 -3
- package/build-style/site-title/editor-rtl.css +3 -3
- package/build-style/site-title/editor.css +3 -3
- package/build-style/site-title/style-rtl.css +3 -3
- package/build-style/site-title/style.css +3 -3
- package/build-style/social-link/editor-rtl.css +3 -3
- package/build-style/social-link/editor.css +3 -3
- package/build-style/social-links/editor-rtl.css +3 -3
- package/build-style/social-links/editor.css +3 -3
- package/build-style/social-links/style-rtl.css +3 -3
- package/build-style/social-links/style.css +3 -3
- package/build-style/spacer/editor-rtl.css +3 -3
- package/build-style/spacer/editor.css +3 -3
- package/build-style/spacer/style-rtl.css +3 -3
- package/build-style/spacer/style.css +3 -3
- package/build-style/style-rtl.css +13 -5
- package/build-style/style.css +13 -5
- package/build-style/table/editor-rtl.css +3 -3
- package/build-style/table/editor.css +3 -3
- package/build-style/table/style-rtl.css +9 -3
- package/build-style/table/style.css +9 -3
- package/build-style/table/theme-rtl.css +3 -9
- package/build-style/table/theme.css +3 -9
- package/build-style/tag-cloud/style-rtl.css +3 -3
- package/build-style/tag-cloud/style.css +3 -3
- package/build-style/template-part/editor-rtl.css +3 -3
- package/build-style/template-part/editor.css +3 -3
- package/build-style/template-part/theme-rtl.css +3 -3
- package/build-style/template-part/theme.css +3 -3
- package/build-style/text-columns/editor-rtl.css +3 -3
- package/build-style/text-columns/editor.css +3 -3
- package/build-style/text-columns/style-rtl.css +3 -3
- package/build-style/text-columns/style.css +3 -3
- package/build-style/theme-rtl.css +3 -9
- package/build-style/theme.css +3 -9
- package/build-style/verse/style-rtl.css +7 -4
- package/build-style/verse/style.css +7 -4
- package/build-style/video/editor-rtl.css +3 -3
- package/build-style/video/editor.css +3 -3
- package/build-style/video/style-rtl.css +3 -3
- package/build-style/video/style.css +3 -3
- package/build-style/video/theme-rtl.css +3 -3
- package/build-style/video/theme.css +3 -3
- package/package.json +29 -29
- package/src/categories/edit.js +1 -1
- package/src/comments/index.php +0 -1
- package/src/cover/edit/inspector-controls.js +4 -4
- package/src/freeform/edit.js +48 -29
- package/src/freeform/modal.js +111 -0
- package/src/gallery/edit.js +17 -2
- package/src/gallery/gallery.js +3 -13
- package/src/image/image.js +1 -0
- package/src/latest-posts/test/__snapshots__/edit.native.js.snap +3 -0
- package/src/latest-posts/test/edit.native.js +49 -0
- package/src/media-text/edit.js +1 -0
- package/src/missing/edit.native.js +13 -6
- package/src/more/test/__snapshots__/edit.native.js.snap +7 -0
- package/src/more/test/edit.native.js +41 -0
- package/src/navigation/edit/index.js +3 -4
- package/src/navigation/edit/menu-inspector-controls.js +70 -29
- package/src/navigation/edit/navigation-menu-selector.js +19 -9
- package/src/navigation/edit/utils.js +82 -0
- package/src/navigation/editor.scss +0 -7
- package/src/navigation/index.php +32 -0
- package/src/navigation/style.scss +0 -1
- package/src/navigation-link/edit.js +5 -58
- package/src/navigation-link/index.php +32 -0
- package/src/navigation-submenu/edit.js +29 -100
- package/src/navigation-submenu/index.php +32 -0
- package/src/page-list/block.json +18 -1
- package/src/page-list/edit.js +30 -22
- package/src/page-list/editor.scss +4 -0
- package/src/page-list/index.js +8 -2
- package/src/page-list/index.php +9 -10
- package/src/page-list-item/edit.js +17 -9
- package/src/post-featured-image/overlay.js +0 -1
- package/src/query/edit/index.js +1 -0
- package/src/query/edit/inspector-controls/index.js +49 -38
- package/src/query/edit/inspector-controls/taxonomy-controls.js +102 -38
- package/src/query/edit/query-content.js +2 -1
- package/src/query/edit/query-placeholder.js +15 -14
- package/src/query/utils.js +59 -1
- package/src/search/edit.js +2 -2
- package/src/separator/test/__snapshots__/edit.native.js.snap +7 -0
- package/src/separator/test/edit.native.js +41 -0
- package/src/social-link/edit.js +3 -3
- package/src/social-links/edit.js +0 -1
- package/src/table/style.scss +8 -0
- package/src/table/theme.scss +0 -8
- package/src/table-of-contents/edit.js +1 -1
- package/src/template-part/edit/advanced-controls.js +12 -0
- package/src/template-part/edit/import-controls.js +180 -0
- package/src/template-part/edit/index.js +1 -0
- package/src/template-part/edit/utils/transformers.js +37 -0
- package/src/verse/style.scss +4 -1
- package/src/verse/test/__snapshots__/edit.native.js.snap +13 -0
- package/src/verse/test/edit.native.js +40 -33
- package/tsconfig.tsbuildinfo +1 -1
- package/build/query/constants.js +0 -16
- package/build/query/constants.js.map +0 -1
- package/build-module/query/constants.js +0 -7
- package/build-module/query/constants.js.map +0 -1
- package/src/query/constants.js +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/query/edit/inspector-controls/index.js"],"names":["QueryInspectorControls","attributes","setQuery","setDisplayLayout","query","displayLayout","order","orderBy","author","authorIds","postType","sticky","inherit","taxQuery","parents","allowedControls","showSticky","setShowSticky","postTypesTaxonomiesMap","postTypesSelectOptions","taxonomies","isPostTypeHierarchical","onPostTypeChange","newValue","updateQuery","supportedTaxonomies","updatedTaxQuery","Object","entries","reduce","accumulator","taxonomySlug","terms","includes","keys","length","undefined","querySearch","setQuerySearch","search","onChangeDebounced","cancel","showInheritControl","showPostTypeControl","showColumnsControl","type","showOrderControl","showStickyControl","showSettingsPanel","value","columns","Math","max","values","some"],"mappings":";;;;;;;;;AAgBA;;AAbA;;AAUA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA1BA;AACA;AACA;;AAgBA;AACA;AACA;AAce,SAASA,sBAAT,OAIX;AAAA,MAJ4C;AAC/CC,IAAAA,UAD+C;AAE/CC,IAAAA,QAF+C;AAG/CC,IAAAA;AAH+C,GAI5C;AACH,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAA2BJ,UAAjC;AACA,QAAM;AACLK,IAAAA,KADK;AAELC,IAAAA,OAFK;AAGLC,IAAAA,MAAM,EAAEC,SAHH;AAILC,IAAAA,QAJK;AAKLC,IAAAA,MALK;AAMLC,IAAAA,OANK;AAOLC,IAAAA,QAPK;AAQLC,IAAAA;AARK,MASFV,KATJ;AAUA,QAAMW,eAAe,GAAG,+BAAoBd,UAApB,CAAxB;AACA,QAAM,CAAEe,UAAF,EAAcC,aAAd,IAAgC,uBAAUP,QAAQ,KAAK,MAAvB,CAAtC;AACA,QAAM;AAAEQ,IAAAA,sBAAF;AAA0BC,IAAAA;AAA1B,MAAqD,0BAA3D;AACA,QAAMC,UAAU,GAAG,0BAAeV,QAAf,CAAn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,CAAE,EAAF;AAHlC,KAKC,4BAAC,uBAAD;AACC,IAAA,KAAK,EAAG,cAAI,SAAJ,CADT;AAEC,IAAA,KAAK,EAAGD,WAFT;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IALD,CA7CF,EAyDGjB,sBAAsB,IACvB,6BAAkBN,eAAlB,EAAmC,SAAnC,CADC,IAEA,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAG,MAAM,CAAC,EAAED,OAAF,aAAEA,OAAF,eAAEA,OAAO,CAAEqB,MAAX,CADnB;AAEC,IAAA,KAAK,EAAG,cAAI,SAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MACZjC,QAAQ,CAAE;AAAEY,MAAAA,OAAO,EAAE;AAAX,KAAF;AAJV,KAOC,4BAAC,sBAAD;AACC,IAAA,OAAO,EAAGA,OADX;AAEC,IAAA,QAAQ,EAAGJ,QAFZ;AAGC,IAAA,QAAQ,EAAGR;AAHZ,IAPD,CA3DH,CADD,CArEF,CADD;AAqJA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tPanelBody,\n\tTextControl,\n\tSelectControl,\n\tRangeControl,\n\tToggleControl,\n\tNotice,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { debounce } from '@wordpress/compose';\nimport { useEffect, useState, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport OrderControl from './order-control';\nimport AuthorControl from './author-control';\nimport ParentControl from './parent-control';\nimport { TaxonomyControls } from './taxonomy-controls';\nimport StickyControl from './sticky-control';\nimport {\n\tusePostTypes,\n\tuseIsPostTypeHierarchical,\n\tuseAllowedControls,\n\tisControlAllowed,\n\tuseTaxonomies,\n} from '../../utils';\n\nexport default function QueryInspectorControls( {\n\tattributes,\n\tsetQuery,\n\tsetDisplayLayout,\n} ) {\n\tconst { query, displayLayout } = attributes;\n\tconst {\n\t\torder,\n\t\torderBy,\n\t\tauthor: authorIds,\n\t\tpostType,\n\t\tsticky,\n\t\tinherit,\n\t\ttaxQuery,\n\t\tparents,\n\t} = query;\n\tconst allowedControls = useAllowedControls( attributes );\n\tconst [ showSticky, setShowSticky ] = useState( postType === 'post' );\n\tconst { postTypesTaxonomiesMap, postTypesSelectOptions } = usePostTypes();\n\tconst taxonomies = useTaxonomies( postType );\n\tconst isPostTypeHierarchical = useIsPostTypeHierarchical( postType );\n\tuseEffect( () => {\n\t\tsetShowSticky( postType === 'post' );\n\t}, [ postType ] );\n\tconst onPostTypeChange = ( newValue ) => {\n\t\tconst updateQuery = { postType: newValue };\n\t\t// We need to dynamically update the `taxQuery` property,\n\t\t// by removing any not supported taxonomy from the query.\n\t\tconst supportedTaxonomies = postTypesTaxonomiesMap[ newValue ];\n\t\tconst updatedTaxQuery = Object.entries( taxQuery || {} ).reduce(\n\t\t\t( accumulator, [ taxonomySlug, terms ] ) => {\n\t\t\t\tif ( supportedTaxonomies.includes( taxonomySlug ) ) {\n\t\t\t\t\taccumulator[ taxonomySlug ] = terms;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\t\tupdateQuery.taxQuery = !! Object.keys( updatedTaxQuery ).length\n\t\t\t? updatedTaxQuery\n\t\t\t: undefined;\n\n\t\tif ( newValue !== 'post' ) {\n\t\t\tupdateQuery.sticky = '';\n\t\t}\n\t\t// We need to reset `parents` because they are tied to each post type.\n\t\tupdateQuery.parents = [];\n\t\tsetQuery( updateQuery );\n\t};\n\tconst [ querySearch, setQuerySearch ] = useState( query.search );\n\tconst onChangeDebounced = useCallback(\n\t\tdebounce( () => {\n\t\t\tif ( query.search !== querySearch ) {\n\t\t\t\tsetQuery( { search: querySearch } );\n\t\t\t}\n\t\t}, 250 ),\n\t\t[ querySearch, query.search ]\n\t);\n\tuseEffect( () => {\n\t\tonChangeDebounced();\n\t\treturn onChangeDebounced.cancel;\n\t}, [ querySearch, onChangeDebounced ] );\n\tconst showInheritControl = isControlAllowed( allowedControls, 'inherit' );\n\tconst showPostTypeControl =\n\t\t! inherit && isControlAllowed( allowedControls, 'postType' );\n\tconst showColumnsControl = displayLayout?.type === 'flex';\n\tconst showOrderControl =\n\t\t! inherit && isControlAllowed( allowedControls, 'order' );\n\tconst showStickyControl =\n\t\t! inherit &&\n\t\tshowSticky &&\n\t\tisControlAllowed( allowedControls, 'sticky' );\n\tconst showSettingsPanel =\n\t\tshowInheritControl ||\n\t\tshowPostTypeControl ||\n\t\tshowColumnsControl ||\n\t\tshowOrderControl ||\n\t\tshowStickyControl;\n\treturn (\n\t\t<>\n\t\t\t{ showSettingsPanel && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t\t{ showInheritControl && (\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Inherit query from template' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Toggle to use the global query context that is set with the current template, such as an archive or search. Disable to customize the settings independently.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ !! inherit }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetQuery( { inherit: !! value } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showPostTypeControl && (\n\t\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\t\toptions={ postTypesSelectOptions }\n\t\t\t\t\t\t\t\tvalue={ postType }\n\t\t\t\t\t\t\t\tlabel={ __( 'Post type' ) }\n\t\t\t\t\t\t\t\tonChange={ onPostTypeChange }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'WordPress contains different types of content and they are divided into collections called “Post types”. By default there are a few different ones such as blog posts and pages, but plugins could add more.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showColumnsControl && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Columns' ) }\n\t\t\t\t\t\t\t\t\tvalue={ displayLayout.columns }\n\t\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\t\tsetDisplayLayout( { columns: value } )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tmin={ 2 }\n\t\t\t\t\t\t\t\t\tmax={ Math.max( 6, displayLayout.columns ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ displayLayout.columns > 6 && (\n\t\t\t\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t\t'This column count exceeds the recommended amount and may cause visual breakage.'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</Notice>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showOrderControl && (\n\t\t\t\t\t\t\t<OrderControl\n\t\t\t\t\t\t\t\t{ ...{ order, orderBy } }\n\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showStickyControl && (\n\t\t\t\t\t\t\t<StickyControl\n\t\t\t\t\t\t\t\tvalue={ sticky }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetQuery( { sticky: value } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t{ ! inherit && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ToolsPanel\n\t\t\t\t\t\tclassName=\"block-library-query-toolspanel__filters\"\n\t\t\t\t\t\tlabel={ __( 'Filters' ) }\n\t\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\t\tsetQuery( {\n\t\t\t\t\t\t\t\tauthor: '',\n\t\t\t\t\t\t\t\tparents: [],\n\t\t\t\t\t\t\t\tsearch: '',\n\t\t\t\t\t\t\t\ttaxQuery: null,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tsetQuerySearch( '' );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ !! taxonomies?.length &&\n\t\t\t\t\t\t\tisControlAllowed( allowedControls, 'taxQuery' ) && (\n\t\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Taxonomies' ) }\n\t\t\t\t\t\t\t\t\thasValue={ () =>\n\t\t\t\t\t\t\t\t\t\tObject.values( taxQuery || {} ).some(\n\t\t\t\t\t\t\t\t\t\t\t( terms ) => !! terms.length\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\t\t\tsetQuery( { taxQuery: null } )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<TaxonomyControls\n\t\t\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t\t\t\tquery={ query }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ isControlAllowed( allowedControls, 'author' ) && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\thasValue={ () => !! authorIds }\n\t\t\t\t\t\t\t\tlabel={ __( 'Authors' ) }\n\t\t\t\t\t\t\t\tonDeselect={ () => setQuery( { author: '' } ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<AuthorControl\n\t\t\t\t\t\t\t\t\tvalue={ authorIds }\n\t\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ isControlAllowed( allowedControls, 'search' ) && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\thasValue={ () => !! querySearch }\n\t\t\t\t\t\t\t\tlabel={ __( 'Keyword' ) }\n\t\t\t\t\t\t\t\tonDeselect={ () => setQuerySearch( '' ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Keyword' ) }\n\t\t\t\t\t\t\t\t\tvalue={ querySearch }\n\t\t\t\t\t\t\t\t\tonChange={ setQuerySearch }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ isPostTypeHierarchical &&\n\t\t\t\t\t\t\tisControlAllowed( allowedControls, 'parents' ) && (\n\t\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\t\thasValue={ () => !! parents?.length }\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Parents' ) }\n\t\t\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\t\t\tsetQuery( { parents: [] } )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<ParentControl\n\t\t\t\t\t\t\t\t\t\tparents={ parents }\n\t\t\t\t\t\t\t\t\t\tpostType={ postType }\n\t\t\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</ToolsPanel>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/query/edit/inspector-controls/index.js"],"names":["QueryInspectorControls","attributes","setQuery","setDisplayLayout","query","displayLayout","order","orderBy","author","authorIds","postType","sticky","inherit","taxQuery","parents","allowedControls","showSticky","setShowSticky","postTypesTaxonomiesMap","postTypesSelectOptions","taxonomies","isPostTypeHierarchical","onPostTypeChange","newValue","updateQuery","supportedTaxonomies","updatedTaxQuery","Object","entries","reduce","accumulator","taxonomySlug","terms","includes","keys","length","undefined","querySearch","setQuerySearch","search","onChangeDebounced","cancel","showInheritControl","showPostTypeControl","showColumnsControl","type","showOrderControl","showStickyControl","showSettingsPanel","showTaxControl","showAuthorControl","showSearchControl","showParentControl","showFiltersPanel","value","columns","Math","max","values","some"],"mappings":";;;;;;;;;AAgBA;;AAbA;;AAUA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA1BA;AACA;AACA;;AAgBA;AACA;AACA;AAce,SAASA,sBAAT,OAIX;AAAA,MAJ4C;AAC/CC,IAAAA,UAD+C;AAE/CC,IAAAA,QAF+C;AAG/CC,IAAAA;AAH+C,GAI5C;AACH,QAAM;AAAEC,IAAAA,KAAF;AAASC,IAAAA;AAAT,MAA2BJ,UAAjC;AACA,QAAM;AACLK,IAAAA,KADK;AAELC,IAAAA,OAFK;AAGLC,IAAAA,MAAM,EAAEC,SAHH;AAILC,IAAAA,QAJK;AAKLC,IAAAA,MALK;AAMLC,IAAAA,OANK;AAOLC,IAAAA,QAPK;AAQLC,IAAAA;AARK,MASFV,KATJ;AAUA,QAAMW,eAAe,GAAG,+BAAoBd,UAApB,CAAxB;AACA,QAAM,CAAEe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iBAAiB,IAClB,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAG,MAAM,CAAC,CAAEzC,SADrB;AAEC,IAAA,KAAK,EAAG,cAAI,SAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MAAMP,QAAQ,CAAE;AAAEM,MAAAA,MAAM,EAAE;AAAV,KAAF;AAH5B,KAKC,4BAAC,sBAAD;AACC,IAAA,KAAK,EAAGC,SADT;AAEC,IAAA,QAAQ,EAAGP;AAFZ,IALD,CAhCF,EA2CGiD,iBAAiB,IAClB,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAG,MAAM,CAAC,CAAEd,WADrB;AAEC,IAAA,KAAK,EAAG,cAAI,SAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MAAMC,cAAc,CAAE,EAAF;AAHlC,KAKC,4BAAC,uBAAD;AACC,IAAA,KAAK,EAAG,cAAI,SAAJ,CADT;AAEC,IAAA,KAAK,EAAGD,WAFT;AAGC,IAAA,QAAQ,EAAGC;AAHZ,IALD,CA5CF,EAwDGc,iBAAiB,IAClB,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAG,MAAM,CAAC,EAAEtC,OAAF,aAAEA,OAAF,eAAEA,OAAO,CAAEqB,MAAX,CADnB;AAEC,IAAA,KAAK,EAAG,cAAI,SAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MAAMjC,QAAQ,CAAE;AAAEY,MAAAA,OAAO,EAAE;AAAX,KAAF;AAH5B,KAKC,4BAAC,sBAAD;AACC,IAAA,OAAO,EAAGA,OADX;AAEC,IAAA,QAAQ,EAAGJ,QAFZ;AAGC,IAAA,QAAQ,EAAGR;AAHZ,IALD,CAzDF,CADD,CArEF,CADD;AAiJA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tPanelBody,\n\tTextControl,\n\tSelectControl,\n\tRangeControl,\n\tToggleControl,\n\tNotice,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { debounce } from '@wordpress/compose';\nimport { useEffect, useState, useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport OrderControl from './order-control';\nimport AuthorControl from './author-control';\nimport ParentControl from './parent-control';\nimport { TaxonomyControls } from './taxonomy-controls';\nimport StickyControl from './sticky-control';\nimport {\n\tusePostTypes,\n\tuseIsPostTypeHierarchical,\n\tuseAllowedControls,\n\tisControlAllowed,\n\tuseTaxonomies,\n} from '../../utils';\n\nexport default function QueryInspectorControls( {\n\tattributes,\n\tsetQuery,\n\tsetDisplayLayout,\n} ) {\n\tconst { query, displayLayout } = attributes;\n\tconst {\n\t\torder,\n\t\torderBy,\n\t\tauthor: authorIds,\n\t\tpostType,\n\t\tsticky,\n\t\tinherit,\n\t\ttaxQuery,\n\t\tparents,\n\t} = query;\n\tconst allowedControls = useAllowedControls( attributes );\n\tconst [ showSticky, setShowSticky ] = useState( postType === 'post' );\n\tconst { postTypesTaxonomiesMap, postTypesSelectOptions } = usePostTypes();\n\tconst taxonomies = useTaxonomies( postType );\n\tconst isPostTypeHierarchical = useIsPostTypeHierarchical( postType );\n\tuseEffect( () => {\n\t\tsetShowSticky( postType === 'post' );\n\t}, [ postType ] );\n\tconst onPostTypeChange = ( newValue ) => {\n\t\tconst updateQuery = { postType: newValue };\n\t\t// We need to dynamically update the `taxQuery` property,\n\t\t// by removing any not supported taxonomy from the query.\n\t\tconst supportedTaxonomies = postTypesTaxonomiesMap[ newValue ];\n\t\tconst updatedTaxQuery = Object.entries( taxQuery || {} ).reduce(\n\t\t\t( accumulator, [ taxonomySlug, terms ] ) => {\n\t\t\t\tif ( supportedTaxonomies.includes( taxonomySlug ) ) {\n\t\t\t\t\taccumulator[ taxonomySlug ] = terms;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\t\tupdateQuery.taxQuery = !! Object.keys( updatedTaxQuery ).length\n\t\t\t? updatedTaxQuery\n\t\t\t: undefined;\n\n\t\tif ( newValue !== 'post' ) {\n\t\t\tupdateQuery.sticky = '';\n\t\t}\n\t\t// We need to reset `parents` because they are tied to each post type.\n\t\tupdateQuery.parents = [];\n\t\tsetQuery( updateQuery );\n\t};\n\tconst [ querySearch, setQuerySearch ] = useState( query.search );\n\tconst onChangeDebounced = useCallback(\n\t\tdebounce( () => {\n\t\t\tif ( query.search !== querySearch ) {\n\t\t\t\tsetQuery( { search: querySearch } );\n\t\t\t}\n\t\t}, 250 ),\n\t\t[ querySearch, query.search ]\n\t);\n\tuseEffect( () => {\n\t\tonChangeDebounced();\n\t\treturn onChangeDebounced.cancel;\n\t}, [ querySearch, onChangeDebounced ] );\n\tconst showInheritControl = isControlAllowed( allowedControls, 'inherit' );\n\tconst showPostTypeControl =\n\t\t! inherit && isControlAllowed( allowedControls, 'postType' );\n\tconst showColumnsControl = displayLayout?.type === 'flex';\n\tconst showOrderControl =\n\t\t! inherit && isControlAllowed( allowedControls, 'order' );\n\tconst showStickyControl =\n\t\t! inherit &&\n\t\tshowSticky &&\n\t\tisControlAllowed( allowedControls, 'sticky' );\n\tconst showSettingsPanel =\n\t\tshowInheritControl ||\n\t\tshowPostTypeControl ||\n\t\tshowColumnsControl ||\n\t\tshowOrderControl ||\n\t\tshowStickyControl;\n\tconst showTaxControl =\n\t\t!! taxonomies?.length &&\n\t\tisControlAllowed( allowedControls, 'taxQuery' );\n\tconst showAuthorControl = isControlAllowed( allowedControls, 'author' );\n\tconst showSearchControl = isControlAllowed( allowedControls, 'search' );\n\tconst showParentControl =\n\t\tisControlAllowed( allowedControls, 'parents' ) &&\n\t\tisPostTypeHierarchical;\n\n\tconst showFiltersPanel =\n\t\tshowTaxControl ||\n\t\tshowAuthorControl ||\n\t\tshowSearchControl ||\n\t\tshowParentControl;\n\n\treturn (\n\t\t<>\n\t\t\t{ showSettingsPanel && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<PanelBody title={ __( 'Settings' ) }>\n\t\t\t\t\t\t{ showInheritControl && (\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Inherit query from template' ) }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'Toggle to use the global query context that is set with the current template, such as an archive or search. Disable to customize the settings independently.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tchecked={ !! inherit }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetQuery( { inherit: !! value } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showPostTypeControl && (\n\t\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\t\toptions={ postTypesSelectOptions }\n\t\t\t\t\t\t\t\tvalue={ postType }\n\t\t\t\t\t\t\t\tlabel={ __( 'Post type' ) }\n\t\t\t\t\t\t\t\tonChange={ onPostTypeChange }\n\t\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t\t'WordPress contains different types of content and they are divided into collections called “Post types”. By default there are a few different ones such as blog posts and pages, but plugins could add more.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showColumnsControl && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<RangeControl\n\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Columns' ) }\n\t\t\t\t\t\t\t\t\tvalue={ displayLayout.columns }\n\t\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\t\tsetDisplayLayout( { columns: value } )\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tmin={ 2 }\n\t\t\t\t\t\t\t\t\tmax={ Math.max( 6, displayLayout.columns ) }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{ displayLayout.columns > 6 && (\n\t\t\t\t\t\t\t\t\t<Notice\n\t\t\t\t\t\t\t\t\t\tstatus=\"warning\"\n\t\t\t\t\t\t\t\t\t\tisDismissible={ false }\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t\t\t\t'This column count exceeds the recommended amount and may cause visual breakage.'\n\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t</Notice>\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showOrderControl && (\n\t\t\t\t\t\t\t<OrderControl\n\t\t\t\t\t\t\t\t{ ...{ order, orderBy } }\n\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showStickyControl && (\n\t\t\t\t\t\t\t<StickyControl\n\t\t\t\t\t\t\t\tvalue={ sticky }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetQuery( { sticky: value } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</PanelBody>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t{ ! inherit && showFiltersPanel && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ToolsPanel\n\t\t\t\t\t\tclassName=\"block-library-query-toolspanel__filters\"\n\t\t\t\t\t\tlabel={ __( 'Filters' ) }\n\t\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\t\tsetQuery( {\n\t\t\t\t\t\t\t\tauthor: '',\n\t\t\t\t\t\t\t\tparents: [],\n\t\t\t\t\t\t\t\tsearch: '',\n\t\t\t\t\t\t\t\ttaxQuery: null,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tsetQuerySearch( '' );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ showTaxControl && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\tlabel={ __( 'Taxonomies' ) }\n\t\t\t\t\t\t\t\thasValue={ () =>\n\t\t\t\t\t\t\t\t\tObject.values( taxQuery || {} ).some(\n\t\t\t\t\t\t\t\t\t\t( terms ) => !! terms.length\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\t\tsetQuery( { taxQuery: null } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<TaxonomyControls\n\t\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t\t\tquery={ query }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showAuthorControl && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\thasValue={ () => !! authorIds }\n\t\t\t\t\t\t\t\tlabel={ __( 'Authors' ) }\n\t\t\t\t\t\t\t\tonDeselect={ () => setQuery( { author: '' } ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<AuthorControl\n\t\t\t\t\t\t\t\t\tvalue={ authorIds }\n\t\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showSearchControl && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\thasValue={ () => !! querySearch }\n\t\t\t\t\t\t\t\tlabel={ __( 'Keyword' ) }\n\t\t\t\t\t\t\t\tonDeselect={ () => setQuerySearch( '' ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<TextControl\n\t\t\t\t\t\t\t\t\tlabel={ __( 'Keyword' ) }\n\t\t\t\t\t\t\t\t\tvalue={ querySearch }\n\t\t\t\t\t\t\t\t\tonChange={ setQuerySearch }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ showParentControl && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\thasValue={ () => !! parents?.length }\n\t\t\t\t\t\t\t\tlabel={ __( 'Parents' ) }\n\t\t\t\t\t\t\t\tonDeselect={ () => setQuery( { parents: [] } ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<ParentControl\n\t\t\t\t\t\t\t\t\tparents={ parents }\n\t\t\t\t\t\t\t\t\tpostType={ postType }\n\t\t\t\t\t\t\t\t\tonChange={ setQuery }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</ToolsPanel>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -13,9 +13,9 @@ var _data = require("@wordpress/data");
|
|
|
13
13
|
|
|
14
14
|
var _coreData = require("@wordpress/core-data");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _compose = require("@wordpress/compose");
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _utils = require("../../utils");
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* WordPress dependencies
|
|
@@ -24,7 +24,13 @@ var _constants = require("../../constants");
|
|
|
24
24
|
/**
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
const EMPTY_ARRAY = [];
|
|
28
|
+
const BASE_QUERY = {
|
|
29
|
+
order: 'asc',
|
|
30
|
+
_fields: 'id,name',
|
|
31
|
+
context: 'view'
|
|
32
|
+
}; // Helper function to get the term id based on user input in terms `FormTokenField`.
|
|
33
|
+
|
|
28
34
|
const getTermIdByTermValue = (terms, termValue) => {
|
|
29
35
|
var _terms$find, _terms$find2;
|
|
30
36
|
|
|
@@ -49,18 +55,6 @@ const getTermIdByTermValue = (terms, termValue) => {
|
|
|
49
55
|
return (_terms$find2 = terms.find(term => term.name.toLocaleLowerCase() === termValueLower)) === null || _terms$find2 === void 0 ? void 0 : _terms$find2.id;
|
|
50
56
|
};
|
|
51
57
|
|
|
52
|
-
const useTaxonomyTerms = slug => {
|
|
53
|
-
return (0, _data.useSelect)(select => {
|
|
54
|
-
const terms = select(_coreData.store).getEntityRecords('taxonomy', slug, {
|
|
55
|
-
context: 'view',
|
|
56
|
-
per_page: _constants.MAX_FETCHED_TERMS
|
|
57
|
-
});
|
|
58
|
-
return {
|
|
59
|
-
terms
|
|
60
|
-
};
|
|
61
|
-
}, [slug]);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
58
|
function TaxonomyControls(_ref) {
|
|
65
59
|
let {
|
|
66
60
|
onChange,
|
|
@@ -77,7 +71,7 @@ function TaxonomyControls(_ref) {
|
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
return (0, _element.createElement)(_element.Fragment, null, taxonomies.map(taxonomy => {
|
|
80
|
-
const
|
|
74
|
+
const termIds = (taxQuery === null || taxQuery === void 0 ? void 0 : taxQuery[taxonomy.slug]) || [];
|
|
81
75
|
|
|
82
76
|
const handleChange = newTermIds => onChange({
|
|
83
77
|
taxQuery: { ...taxQuery,
|
|
@@ -88,53 +82,123 @@ function TaxonomyControls(_ref) {
|
|
|
88
82
|
return (0, _element.createElement)(TaxonomyItem, {
|
|
89
83
|
key: taxonomy.slug,
|
|
90
84
|
taxonomy: taxonomy,
|
|
91
|
-
|
|
85
|
+
termIds: termIds,
|
|
92
86
|
onChange: handleChange
|
|
93
87
|
});
|
|
94
88
|
}));
|
|
95
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Renders a `FormTokenField` for a given taxonomy.
|
|
92
|
+
*
|
|
93
|
+
* @param {Object} props The props for the component.
|
|
94
|
+
* @param {Object} props.taxonomy The taxonomy object.
|
|
95
|
+
* @param {number[]} props.termIds An array with the block's term ids for the given taxonomy.
|
|
96
|
+
* @param {Function} props.onChange Callback `onChange` function.
|
|
97
|
+
* @return {JSX.Element} The rendered component.
|
|
98
|
+
*/
|
|
99
|
+
|
|
96
100
|
|
|
97
101
|
function TaxonomyItem(_ref2) {
|
|
98
102
|
let {
|
|
99
103
|
taxonomy,
|
|
100
|
-
|
|
104
|
+
termIds,
|
|
101
105
|
onChange
|
|
102
106
|
} = _ref2;
|
|
107
|
+
const [search, setSearch] = (0, _element.useState)('');
|
|
108
|
+
const [value, setValue] = (0, _element.useState)(EMPTY_ARRAY);
|
|
109
|
+
const [suggestions, setSuggestions] = (0, _element.useState)(EMPTY_ARRAY);
|
|
110
|
+
const debouncedSearch = (0, _compose.useDebounce)(setSearch, 250);
|
|
103
111
|
const {
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
searchResults,
|
|
113
|
+
searchHasResolved
|
|
114
|
+
} = (0, _data.useSelect)(select => {
|
|
115
|
+
if (!search) {
|
|
116
|
+
return {
|
|
117
|
+
searchResults: EMPTY_ARRAY,
|
|
118
|
+
searchHasResolved: true
|
|
119
|
+
};
|
|
120
|
+
}
|
|
106
121
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
122
|
+
const {
|
|
123
|
+
getEntityRecords,
|
|
124
|
+
hasFinishedResolution
|
|
125
|
+
} = select(_coreData.store);
|
|
126
|
+
const selectorArgs = ['taxonomy', taxonomy.slug, { ...BASE_QUERY,
|
|
127
|
+
search,
|
|
128
|
+
orderby: 'name',
|
|
129
|
+
exclude: termIds,
|
|
130
|
+
per_page: 20
|
|
131
|
+
}];
|
|
132
|
+
return {
|
|
133
|
+
searchResults: getEntityRecords(...selectorArgs),
|
|
134
|
+
searchHasResolved: hasFinishedResolution('getEntityRecords', selectorArgs)
|
|
135
|
+
};
|
|
136
|
+
}, [search, termIds]); // `existingTerms` are the ones fetched from the API and their type is `{ id: number; name: string }`.
|
|
137
|
+
// They are used to extract the terms' names to populate the `FormTokenField` properly
|
|
138
|
+
// and to sanitize the provided `termIds`, by setting only the ones that exist.
|
|
139
|
+
|
|
140
|
+
const existingTerms = (0, _data.useSelect)(select => {
|
|
141
|
+
if (!(termIds !== null && termIds !== void 0 && termIds.length)) return EMPTY_ARRAY;
|
|
142
|
+
const {
|
|
143
|
+
getEntityRecords
|
|
144
|
+
} = select(_coreData.store);
|
|
145
|
+
return getEntityRecords('taxonomy', taxonomy.slug, { ...BASE_QUERY,
|
|
146
|
+
include: termIds,
|
|
147
|
+
per_page: termIds.length
|
|
148
|
+
});
|
|
149
|
+
}, [termIds]); // Update the `value` state only after the selectors are resolved
|
|
150
|
+
// to avoid emptying the input when we're changing terms.
|
|
151
|
+
|
|
152
|
+
(0, _element.useEffect)(() => {
|
|
153
|
+
if (!(termIds !== null && termIds !== void 0 && termIds.length)) {
|
|
154
|
+
setValue(EMPTY_ARRAY);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!(existingTerms !== null && existingTerms !== void 0 && existingTerms.length)) return; // Returns only the existing entity ids. This prevents the component
|
|
158
|
+
// from crashing in the editor, when non existing ids are provided.
|
|
159
|
+
|
|
160
|
+
const sanitizedValue = termIds.reduce((accumulator, id) => {
|
|
161
|
+
const entity = existingTerms.find(term => term.id === id);
|
|
162
|
+
|
|
163
|
+
if (entity) {
|
|
164
|
+
accumulator.push({
|
|
165
|
+
id,
|
|
166
|
+
value: entity.name
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return accumulator;
|
|
171
|
+
}, []);
|
|
172
|
+
setValue(sanitizedValue);
|
|
173
|
+
}, [termIds, existingTerms]); // Update suggestions only when the query has resolved.
|
|
174
|
+
|
|
175
|
+
(0, _element.useEffect)(() => {
|
|
176
|
+
if (!searchHasResolved) return;
|
|
177
|
+
setSuggestions(searchResults.map(result => result.name));
|
|
178
|
+
}, [searchResults, searchHasResolved]);
|
|
110
179
|
|
|
111
180
|
const onTermsChange = newTermValues => {
|
|
112
|
-
const
|
|
181
|
+
const newTermIds = new Set();
|
|
113
182
|
|
|
114
183
|
for (const termValue of newTermValues) {
|
|
115
|
-
const termId = getTermIdByTermValue(
|
|
184
|
+
const termId = getTermIdByTermValue(searchResults, termValue);
|
|
116
185
|
|
|
117
186
|
if (termId) {
|
|
118
|
-
|
|
187
|
+
newTermIds.add(termId);
|
|
119
188
|
}
|
|
120
189
|
}
|
|
121
190
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// crashing in the editor, when non existing term ids were provided.
|
|
126
|
-
|
|
191
|
+
setSuggestions(EMPTY_ARRAY);
|
|
192
|
+
onChange(Array.from(newTermIds));
|
|
193
|
+
};
|
|
127
194
|
|
|
128
|
-
const taxQueryValue = value.map(termId => terms.find(t => t.id === termId)).filter(Boolean).map(term => ({
|
|
129
|
-
id: term.id,
|
|
130
|
-
value: term.name
|
|
131
|
-
}));
|
|
132
195
|
return (0, _element.createElement)("div", {
|
|
133
196
|
className: "block-library-query-inspector__taxonomy-control"
|
|
134
197
|
}, (0, _element.createElement)(_components.FormTokenField, {
|
|
135
198
|
label: taxonomy.name,
|
|
136
|
-
value:
|
|
137
|
-
|
|
199
|
+
value: value,
|
|
200
|
+
onInputChange: debouncedSearch,
|
|
201
|
+
suggestions: suggestions,
|
|
138
202
|
onChange: onTermsChange,
|
|
139
203
|
__experimentalShowHowTo: false
|
|
140
204
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/query/edit/inspector-controls/taxonomy-controls.js"],"names":["getTermIdByTermValue","terms","termValue","termId","id","find","term","name","termValueLower","toLocaleLowerCase","useTaxonomyTerms","slug","select","coreStore","getEntityRecords","context","per_page","MAX_FETCHED_TERMS","TaxonomyControls","onChange","query","postType","taxQuery","taxonomies","length","map","taxonomy","value","handleChange","newTermIds","TaxonomyItem","onTermsChange","newTermValues","termIds","Set","add","Array","from","taxQueryValue","t","filter","Boolean"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;AAIA;AACA,MAAMA,oBAAoB,GAAG,CAAEC,KAAF,EAASC,SAAT,KAAwB;AAAA;;AACpD;AACA,QAAMC,MAAM,GACX,CAAAD,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAEE,EAAX,qBAAiBH,KAAK,CAACI,IAAN,CAAcC,IAAF,IAAYA,IAAI,CAACC,IAAL,KAAcL,SAAtC,CAAjB,gDAAiB,YAAmDE,EAApE,CADD;;AAEA,MAAKD,MAAL,EAAc;AACb,WAAOA,MAAP;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMK,cAAc,GAAGN,SAAS,CAACO,iBAAV,EAAvB;AACA,yBAAOR,KAAK,CAACI,IAAN,CACJC,IAAF,IAAYA,IAAI,CAACC,IAAL,CAAUE,iBAAV,OAAkCD,cADxC,CAAP,iDAAO,aAEJJ,EAFH;AAGA,CArBD;;AAuBA,MAAMM,gBAAgB,GAAKC,IAAF,IAAY;AACpC,SAAO,qBACJC,MAAF,IAAc;AACb,UAAMX,KAAK,GAAGW,MAAM,CAAEC,eAAF,CAAN,CAAoBC,gBAApB,CACb,UADa,EAEbH,IAFa,EAGb;AAAEI,MAAAA,OAAO,EAAE,MAAX;AAAmBC,MAAAA,QAAQ,EAAEC;AAA7B,KAHa,CAAd;AAKA,WAAO;AAAEhB,MAAAA;AAAF,KAAP;AACA,GARK,EASN,CAAEU,IAAF,CATM,CAAP;AAWA,CAZD;;AAcO,SAASO,gBAAT,OAAiD;AAAA,MAAtB;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,GAAsB;AACvD,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAyBF,KAA/B;AAEA,QAAMG,UAAU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AR,CAAahC,MAAb;AACA;AACD;;AAEDgB,IAAAA,QAAQ,CAAEiB,KAAK,CAACC,IAAN,CAAYJ,OAAZ,CAAF,CAAR;AACA,GAVD,CANsD,CAkBtD;AACA;AACA;;;AACA,QAAMK,aAAa,GAAGX,KAAK,CACzBF,GADoB,CACbtB,MAAF,IAAcF,KAAK,CAACI,IAAN,CAAckC,CAAF,IAASA,CAAC,CAACnC,EAAF,KAASD,MAA9B,CADC,EAEpBqC,MAFoB,CAEZC,OAFY,EAGpBhB,GAHoB,CAGbnB,IAAF,KAAc;AAAEF,IAAAA,EAAE,EAAEE,IAAI,CAACF,EAAX;AAAeuB,IAAAA,KAAK,EAAErB,IAAI,CAACC;AAA3B,GAAd,CAHe,CAAtB;AAKA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,0BAAD;AACC,IAAA,KAAK,EAAGmB,QAAQ,CAACnB,IADlB;AAEC,IAAA,KAAK,EAAG+B,aAFT;AAGC,IAAA,WAAW,EAAGrC,KAAK,CAACwB,GAAN,CAAac,CAAF,IAASA,CAAC,CAAChC,IAAtB,CAHf;AAIC,IAAA,QAAQ,EAAGwB,aAJZ;AAKC,IAAA,uBAAuB,EAAG;AAL3B,IADD,CADD;AAWA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { FormTokenField } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { useTaxonomies } from '../../utils';\nimport { MAX_FETCHED_TERMS } from '../../constants';\n\n// Helper function to get the term id based on user input in terms `FormTokenField`.\nconst getTermIdByTermValue = ( terms, termValue ) => {\n\t// First we check for exact match by `term.id` or case sensitive `term.name` match.\n\tconst termId =\n\t\ttermValue?.id || terms.find( ( term ) => term.name === termValue )?.id;\n\tif ( termId ) {\n\t\treturn termId;\n\t}\n\n\t/**\n\t * Here we make an extra check for entered terms in a non case sensitive way,\n\t * to match user expectations, due to `FormTokenField` behaviour that shows\n\t * suggestions which are case insensitive.\n\t *\n\t * Although WP tries to discourage users to add terms with the same name (case insensitive),\n\t * it's still possible if you manually change the name, as long as the terms have different slugs.\n\t * In this edge case we always apply the first match from the terms list.\n\t */\n\tconst termValueLower = termValue.toLocaleLowerCase();\n\treturn terms.find(\n\t\t( term ) => term.name.toLocaleLowerCase() === termValueLower\n\t)?.id;\n};\n\nconst useTaxonomyTerms = ( slug ) => {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst terms = select( coreStore ).getEntityRecords(\n\t\t\t\t'taxonomy',\n\t\t\t\tslug,\n\t\t\t\t{ context: 'view', per_page: MAX_FETCHED_TERMS }\n\t\t\t);\n\t\t\treturn { terms };\n\t\t},\n\t\t[ slug ]\n\t);\n};\n\nexport function TaxonomyControls( { onChange, query } ) {\n\tconst { postType, taxQuery } = query;\n\n\tconst taxonomies = useTaxonomies( postType );\n\tif ( ! taxonomies || taxonomies.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ taxonomies.map( ( taxonomy ) => {\n\t\t\t\tconst value = taxQuery?.[ taxonomy.slug ] || [];\n\t\t\t\tconst handleChange = ( newTermIds ) =>\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\ttaxQuery: {\n\t\t\t\t\t\t\t...taxQuery,\n\t\t\t\t\t\t\t[ taxonomy.slug ]: newTermIds,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\n\t\t\t\treturn (\n\t\t\t\t\t<TaxonomyItem\n\t\t\t\t\t\tkey={ taxonomy.slug }\n\t\t\t\t\t\ttaxonomy={ taxonomy }\n\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\nfunction TaxonomyItem( { taxonomy, value, onChange } ) {\n\tconst { terms } = useTaxonomyTerms( taxonomy.slug );\n\tif ( ! terms?.length ) {\n\t\treturn null;\n\t}\n\n\tconst onTermsChange = ( newTermValues ) => {\n\t\tconst termIds = new Set();\n\t\tfor ( const termValue of newTermValues ) {\n\t\t\tconst termId = getTermIdByTermValue( terms, termValue );\n\t\t\tif ( termId ) {\n\t\t\t\ttermIds.add( termId );\n\t\t\t}\n\t\t}\n\n\t\tonChange( Array.from( termIds ) );\n\t};\n\n\t// Selects only the existing term ids in proper format to be\n\t// used in `FormTokenField`. This prevents the component from\n\t// crashing in the editor, when non existing term ids were provided.\n\tconst taxQueryValue = value\n\t\t.map( ( termId ) => terms.find( ( t ) => t.id === termId ) )\n\t\t.filter( Boolean )\n\t\t.map( ( term ) => ( { id: term.id, value: term.name } ) );\n\n\treturn (\n\t\t<div className=\"block-library-query-inspector__taxonomy-control\">\n\t\t\t<FormTokenField\n\t\t\t\tlabel={ taxonomy.name }\n\t\t\t\tvalue={ taxQueryValue }\n\t\t\t\tsuggestions={ terms.map( ( t ) => t.name ) }\n\t\t\t\tonChange={ onTermsChange }\n\t\t\t\t__experimentalShowHowTo={ false }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/query/edit/inspector-controls/taxonomy-controls.js"],"names":["EMPTY_ARRAY","BASE_QUERY","order","_fields","context","getTermIdByTermValue","terms","termValue","termId","id","find","term","name","termValueLower","toLocaleLowerCase","TaxonomyControls","onChange","query","postType","taxQuery","taxonomies","length","map","taxonomy","termIds","slug","handleChange","newTermIds","TaxonomyItem","search","setSearch","value","setValue","suggestions","setSuggestions","debouncedSearch","searchResults","searchHasResolved","select","getEntityRecords","hasFinishedResolution","coreStore","selectorArgs","orderby","exclude","per_page","existingTerms","include","sanitizedValue","reduce","accumulator","entity","push","result","onTermsChange","newTermValues","Set","add","Array","from"],"mappings":";;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;AACA,MAAMC,UAAU,GAA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ADiB;AAEjBsB,UAAAA,KAAK,EAAEoB,MAAM,CAACvC;AAFG,SAAlB;AAIA;;AACD,aAAOsC,WAAP;AACA,KATsB,EASpB,EAToB,CAAvB;AAUAlB,IAAAA,QAAQ,CAAEgB,cAAF,CAAR;AACA,GAlBD,EAkBG,CAAExB,OAAF,EAAWsB,aAAX,CAlBH,EAlDwD,CAqExD;;AACA,0BAAW,MAAM;AAChB,QAAK,CAAET,iBAAP,EAA2B;AAC3BH,IAAAA,cAAc,CAAEE,aAAa,CAACd,GAAd,CAAqB+B,MAAF,IAAcA,MAAM,CAACzC,IAAxC,CAAF,CAAd;AACA,GAHD,EAGG,CAAEwB,aAAF,EAAiBC,iBAAjB,CAHH;;AAIA,QAAMiB,aAAa,GAAKC,aAAF,IAAqB;AAC1C,UAAM5B,UAAU,GAAG,IAAI6B,GAAJ,EAAnB;;AACA,SAAM,MAAMjD,SAAZ,IAAyBgD,aAAzB,EAAyC;AACxC,YAAM/C,MAAM,GAAGH,oBAAoB,CAAE+B,aAAF,EAAiB7B,SAAjB,CAAnC;;AACA,UAAKC,MAAL,EAAc;AACbmB,QAAAA,UAAU,CAAC8B,GAAX,CAAgBjD,MAAhB;AACA;AACD;;AACD0B,IAAAA,cAAc,CAAElC,WAAF,CAAd;AACAgB,IAAAA,QAAQ,CAAE0C,KAAK,CAACC,IAAN,CAAYhC,UAAZ,CAAF,CAAR;AACA,GAVD;;AAWA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,0BAAD;AACC,IAAA,KAAK,EAAGJ,QAAQ,CAACX,IADlB;AAEC,IAAA,KAAK,EAAGmB,KAFT;AAGC,IAAA,aAAa,EAAGI,eAHjB;AAIC,IAAA,WAAW,EAAGF,WAJf;AAKC,IAAA,QAAQ,EAAGqB,aALZ;AAMC,IAAA,uBAAuB,EAAG;AAN3B,IADD,CADD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { FormTokenField } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useState, useEffect } from '@wordpress/element';\nimport { useDebounce } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useTaxonomies } from '../../utils';\n\nconst EMPTY_ARRAY = [];\nconst BASE_QUERY = {\n\torder: 'asc',\n\t_fields: 'id,name',\n\tcontext: 'view',\n};\n\n// Helper function to get the term id based on user input in terms `FormTokenField`.\nconst getTermIdByTermValue = ( terms, termValue ) => {\n\t// First we check for exact match by `term.id` or case sensitive `term.name` match.\n\tconst termId =\n\t\ttermValue?.id || terms.find( ( term ) => term.name === termValue )?.id;\n\tif ( termId ) {\n\t\treturn termId;\n\t}\n\n\t/**\n\t * Here we make an extra check for entered terms in a non case sensitive way,\n\t * to match user expectations, due to `FormTokenField` behaviour that shows\n\t * suggestions which are case insensitive.\n\t *\n\t * Although WP tries to discourage users to add terms with the same name (case insensitive),\n\t * it's still possible if you manually change the name, as long as the terms have different slugs.\n\t * In this edge case we always apply the first match from the terms list.\n\t */\n\tconst termValueLower = termValue.toLocaleLowerCase();\n\treturn terms.find(\n\t\t( term ) => term.name.toLocaleLowerCase() === termValueLower\n\t)?.id;\n};\n\nexport function TaxonomyControls( { onChange, query } ) {\n\tconst { postType, taxQuery } = query;\n\n\tconst taxonomies = useTaxonomies( postType );\n\tif ( ! taxonomies || taxonomies.length === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ taxonomies.map( ( taxonomy ) => {\n\t\t\t\tconst termIds = taxQuery?.[ taxonomy.slug ] || [];\n\t\t\t\tconst handleChange = ( newTermIds ) =>\n\t\t\t\t\tonChange( {\n\t\t\t\t\t\ttaxQuery: {\n\t\t\t\t\t\t\t...taxQuery,\n\t\t\t\t\t\t\t[ taxonomy.slug ]: newTermIds,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\n\t\t\t\treturn (\n\t\t\t\t\t<TaxonomyItem\n\t\t\t\t\t\tkey={ taxonomy.slug }\n\t\t\t\t\t\ttaxonomy={ taxonomy }\n\t\t\t\t\t\ttermIds={ termIds }\n\t\t\t\t\t\tonChange={ handleChange }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</>\n\t);\n}\n\n/**\n * Renders a `FormTokenField` for a given taxonomy.\n *\n * @param {Object} props The props for the component.\n * @param {Object} props.taxonomy The taxonomy object.\n * @param {number[]} props.termIds An array with the block's term ids for the given taxonomy.\n * @param {Function} props.onChange Callback `onChange` function.\n * @return {JSX.Element} The rendered component.\n */\nfunction TaxonomyItem( { taxonomy, termIds, onChange } ) {\n\tconst [ search, setSearch ] = useState( '' );\n\tconst [ value, setValue ] = useState( EMPTY_ARRAY );\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tconst debouncedSearch = useDebounce( setSearch, 250 );\n\tconst { searchResults, searchHasResolved } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! search ) {\n\t\t\t\treturn { searchResults: EMPTY_ARRAY, searchHasResolved: true };\n\t\t\t}\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\t\t\tconst selectorArgs = [\n\t\t\t\t'taxonomy',\n\t\t\t\ttaxonomy.slug,\n\t\t\t\t{\n\t\t\t\t\t...BASE_QUERY,\n\t\t\t\t\tsearch,\n\t\t\t\t\torderby: 'name',\n\t\t\t\t\texclude: termIds,\n\t\t\t\t\tper_page: 20,\n\t\t\t\t},\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tsearchResults: getEntityRecords( ...selectorArgs ),\n\t\t\t\tsearchHasResolved: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tselectorArgs\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ search, termIds ]\n\t);\n\t// `existingTerms` are the ones fetched from the API and their type is `{ id: number; name: string }`.\n\t// They are used to extract the terms' names to populate the `FormTokenField` properly\n\t// and to sanitize the provided `termIds`, by setting only the ones that exist.\n\tconst existingTerms = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! termIds?.length ) return EMPTY_ARRAY;\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\treturn getEntityRecords( 'taxonomy', taxonomy.slug, {\n\t\t\t\t...BASE_QUERY,\n\t\t\t\tinclude: termIds,\n\t\t\t\tper_page: termIds.length,\n\t\t\t} );\n\t\t},\n\t\t[ termIds ]\n\t);\n\t// Update the `value` state only after the selectors are resolved\n\t// to avoid emptying the input when we're changing terms.\n\tuseEffect( () => {\n\t\tif ( ! termIds?.length ) {\n\t\t\tsetValue( EMPTY_ARRAY );\n\t\t}\n\t\tif ( ! existingTerms?.length ) return;\n\t\t// Returns only the existing entity ids. This prevents the component\n\t\t// from crashing in the editor, when non existing ids are provided.\n\t\tconst sanitizedValue = termIds.reduce( ( accumulator, id ) => {\n\t\t\tconst entity = existingTerms.find( ( term ) => term.id === id );\n\t\t\tif ( entity ) {\n\t\t\t\taccumulator.push( {\n\t\t\t\t\tid,\n\t\t\t\t\tvalue: entity.name,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, [] );\n\t\tsetValue( sanitizedValue );\n\t}, [ termIds, existingTerms ] );\n\t// Update suggestions only when the query has resolved.\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) return;\n\t\tsetSuggestions( searchResults.map( ( result ) => result.name ) );\n\t}, [ searchResults, searchHasResolved ] );\n\tconst onTermsChange = ( newTermValues ) => {\n\t\tconst newTermIds = new Set();\n\t\tfor ( const termValue of newTermValues ) {\n\t\t\tconst termId = getTermIdByTermValue( searchResults, termValue );\n\t\t\tif ( termId ) {\n\t\t\t\tnewTermIds.add( termId );\n\t\t\t}\n\t\t}\n\t\tsetSuggestions( EMPTY_ARRAY );\n\t\tonChange( Array.from( newTermIds ) );\n\t};\n\treturn (\n\t\t<div className=\"block-library-query-inspector__taxonomy-control\">\n\t\t\t<FormTokenField\n\t\t\t\tlabel={ taxonomy.name }\n\t\t\t\tvalue={ value }\n\t\t\t\tonInputChange={ debouncedSearch }\n\t\t\t\tsuggestions={ suggestions }\n\t\t\t\tonChange={ onTermsChange }\n\t\t\t\t__experimentalShowHowTo={ false }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -23,8 +23,6 @@ var _queryToolbar = _interopRequireDefault(require("./query-toolbar"));
|
|
|
23
23
|
|
|
24
24
|
var _inspectorControls = _interopRequireDefault(require("./inspector-controls"));
|
|
25
25
|
|
|
26
|
-
var _constants = require("../constants");
|
|
27
|
-
|
|
28
26
|
/**
|
|
29
27
|
* WordPress dependencies
|
|
30
28
|
*/
|
|
@@ -32,6 +30,7 @@ var _constants = require("../constants");
|
|
|
32
30
|
/**
|
|
33
31
|
* Internal dependencies
|
|
34
32
|
*/
|
|
33
|
+
const DEFAULTS_POSTS_PER_PAGE = 3;
|
|
35
34
|
const TEMPLATE = [['core/post-template']];
|
|
36
35
|
|
|
37
36
|
function QueryContent(_ref) {
|
|
@@ -84,7 +83,7 @@ function QueryContent(_ref) {
|
|
|
84
83
|
getSettings
|
|
85
84
|
} = select(_blockEditor.store);
|
|
86
85
|
return {
|
|
87
|
-
postsPerPage: +getSettings().postsPerPage ||
|
|
86
|
+
postsPerPage: +getSettings().postsPerPage || DEFAULTS_POSTS_PER_PAGE
|
|
88
87
|
};
|
|
89
88
|
}, []); // There are some effects running where some initialization logic is
|
|
90
89
|
// happening and setting some values to some attributes (ex. queryId).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/query/edit/query-content.js"],"names":["TEMPLATE","QueryContent","attributes","setAttributes","openPatternSelectionModal","name","clientId","queryId","query","displayLayout","tagName","TagName","layout","__unstableMarkNextChangeAsNotPersistent","blockEditorStore","instanceId","themeSupportsLayout","select","getSettings","supportsLayout","defaultLayout","usedLayout","type","blockProps","innerBlocksProps","template","__experimentalLayout","undefined","postsPerPage","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/query/edit/query-content.js"],"names":["DEFAULTS_POSTS_PER_PAGE","TEMPLATE","QueryContent","attributes","setAttributes","openPatternSelectionModal","name","clientId","queryId","query","displayLayout","tagName","TagName","layout","__unstableMarkNextChangeAsNotPersistent","blockEditorStore","instanceId","themeSupportsLayout","select","getSettings","supportsLayout","defaultLayout","usedLayout","type","blockProps","innerBlocksProps","template","__experimentalLayout","undefined","postsPerPage","newQuery","perPage","Object","keys","length","updateQuery","Number","isFinite","updateDisplayLayout","newDisplayLayout","label","value"],"mappings":";;;;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AAQA;;AACA;;AAKA;;AACA;;AArBA;AACA;AACA;;AAeA;AACA;AACA;AAIA,MAAMA,uBAAuB,GAAG,CAAhC;AAEA,MAAMC,QAAQ,GAAG,CAAE,CAAE,oBAAF,CAAF,CAAjB;;AACe,SAASC,YAAT,OAMX;AAAA,MANkC;AACrCC,IAAAA,UADqC;AAErCC,IAAAA,aAFqC;AAGrCC,IAAAA,yBAHqC;AAIrCC,IAAAA,IAJqC;AAKrCC,IAAAA;AALqC,GAMlC;AACH,QAAM;AACLC,IAAAA,OADK;AAELC,IAAAA,KAFK;AAGLC,IAAAA,aAHK;AAILC,IAAAA,OAAO,EAAEC,OAAO,GAAG,KAJd;AAKLC,IAAAA,MAAM,GAAG;AALJ,MAMFV,UANJ;AAOA,QAAM;AAAEW,IAAAA;AAAF,MACL,uBAAaC,kBAAb,CADD;AAEA,QAAMC,UAAU,GAAG,4BAAed,YAAf,CAAnB;AACA,QAAM;AAAEe,IAAAA;AAAF,MAA0B,qBAAaC,MAAF,IAAc;AAAA;;AACxD,UAAM;AAAEC,MAAAA;AAAF,QAAkBD,MAAM,CAAEH,kBAAF,CAA9B;AACA,WAAO;AAAEE,MAAAA,mBAAmB,kBAAEE,WAAW,EAAb,iDAAE,aAAeC;AAAtC,KAAP;AACA,GAH+B,EAG7B,EAH6B,CAAhC;AAIA,QAAMC,aAAa,GAAG,6BAAY,QAAZ,KAA0B,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;AAA3B,KAJS,CAFX;AAQC,IAAA,KAAK,EAAG7B,OART;AASC,IAAA,QAAQ,EAAK6B,KAAF,IACVrC,aAAa,CAAE;AAAEO,MAAAA,OAAO,EAAE8B;AAAX,KAAF;AAVf,IADD,CAhBD,EA+BC,4BAAC,OAAD,EAAchB,gBAAd,CA/BD,CADD;AAmCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useInstanceId } from '@wordpress/compose';\nimport { useEffect } from '@wordpress/element';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tuseBlockProps,\n\tuseSetting,\n\tstore as blockEditorStore,\n\tuseInnerBlocksProps,\n} from '@wordpress/block-editor';\nimport { SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport QueryToolbar from './query-toolbar';\nimport QueryInspectorControls from './inspector-controls';\n\nconst DEFAULTS_POSTS_PER_PAGE = 3;\n\nconst TEMPLATE = [ [ 'core/post-template' ] ];\nexport default function QueryContent( {\n\tattributes,\n\tsetAttributes,\n\topenPatternSelectionModal,\n\tname,\n\tclientId,\n} ) {\n\tconst {\n\t\tqueryId,\n\t\tquery,\n\t\tdisplayLayout,\n\t\ttagName: TagName = 'div',\n\t\tlayout = {},\n\t} = attributes;\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst instanceId = useInstanceId( QueryContent );\n\tconst { themeSupportsLayout } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn { themeSupportsLayout: getSettings()?.supportsLayout };\n\t}, [] );\n\tconst defaultLayout = useSetting( 'layout' ) || {};\n\tconst usedLayout = ! layout?.type\n\t\t? { ...defaultLayout, ...layout, type: 'default' }\n\t\t: { ...defaultLayout, ...layout };\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t\t__experimentalLayout: themeSupportsLayout ? usedLayout : undefined,\n\t} );\n\tconst { postsPerPage } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\tpostsPerPage:\n\t\t\t\t+getSettings().postsPerPage || DEFAULTS_POSTS_PER_PAGE,\n\t\t};\n\t}, [] );\n\t// There are some effects running where some initialization logic is\n\t// happening and setting some values to some attributes (ex. queryId).\n\t// These updates can cause an `undo trap` where undoing will result in\n\t// resetting again, so we need to mark these changes as not persistent\n\t// with `__unstableMarkNextChangeAsNotPersistent`.\n\n\t// Changes in query property (which is an object) need to be in the same callback,\n\t// because updates are batched after the render and changes in different query properties\n\t// would cause to override previous wanted changes.\n\tuseEffect( () => {\n\t\tconst newQuery = {};\n\t\tif ( ! query.perPage && postsPerPage ) {\n\t\t\tnewQuery.perPage = postsPerPage;\n\t\t}\n\t\tif ( !! Object.keys( newQuery ).length ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tupdateQuery( newQuery );\n\t\t}\n\t}, [ query.perPage ] );\n\t// We need this for multi-query block pagination.\n\t// Query parameters for each block are scoped to their ID.\n\tuseEffect( () => {\n\t\tif ( ! Number.isFinite( queryId ) ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { queryId: instanceId } );\n\t\t}\n\t}, [ queryId, instanceId ] );\n\tconst updateQuery = ( newQuery ) =>\n\t\tsetAttributes( { query: { ...query, ...newQuery } } );\n\tconst updateDisplayLayout = ( newDisplayLayout ) =>\n\t\tsetAttributes( {\n\t\t\tdisplayLayout: { ...displayLayout, ...newDisplayLayout },\n\t\t} );\n\treturn (\n\t\t<>\n\t\t\t<QueryInspectorControls\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetQuery={ updateQuery }\n\t\t\t\tsetDisplayLayout={ updateDisplayLayout }\n\t\t\t/>\n\t\t\t<BlockControls>\n\t\t\t\t<QueryToolbar\n\t\t\t\t\tname={ name }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetQuery={ updateQuery }\n\t\t\t\t\tsetDisplayLayout={ updateDisplayLayout }\n\t\t\t\t\topenPatternSelectionModal={ openPatternSelectionModal }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<InspectorControls __experimentalGroup=\"advanced\">\n\t\t\t\t<SelectControl\n\t\t\t\t\tlabel={ __( 'HTML element' ) }\n\t\t\t\t\toptions={ [\n\t\t\t\t\t\t{ label: __( 'Default (<div>)' ), value: 'div' },\n\t\t\t\t\t\t{ label: '<main>', value: 'main' },\n\t\t\t\t\t\t{ label: '<section>', value: 'section' },\n\t\t\t\t\t\t{ label: '<aside>', value: 'aside' },\n\t\t\t\t\t] }\n\t\t\t\t\tvalue={ TagName }\n\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\tsetAttributes( { tagName: value } )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<TagName { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -17,9 +17,15 @@ var _components = require("@wordpress/components");
|
|
|
17
17
|
|
|
18
18
|
var _i18n = require("@wordpress/i18n");
|
|
19
19
|
|
|
20
|
+
var _utils = require("../utils");
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* WordPress dependencies
|
|
22
24
|
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Internal dependencies
|
|
28
|
+
*/
|
|
23
29
|
function QueryPlaceholder(_ref) {
|
|
24
30
|
var _matchingVariation$ic, _blockType$icon;
|
|
25
31
|
|
|
@@ -59,7 +65,6 @@ function QueryPlaceholder(_ref) {
|
|
|
59
65
|
if (isStartingBlank) {
|
|
60
66
|
return (0, _element.createElement)(QueryVariationPicker, {
|
|
61
67
|
clientId: clientId,
|
|
62
|
-
name: name,
|
|
63
68
|
attributes: attributes,
|
|
64
69
|
setAttributes: setAttributes,
|
|
65
70
|
icon: icon,
|
|
@@ -85,13 +90,12 @@ function QueryPlaceholder(_ref) {
|
|
|
85
90
|
function QueryVariationPicker(_ref2) {
|
|
86
91
|
let {
|
|
87
92
|
clientId,
|
|
88
|
-
name,
|
|
89
93
|
attributes,
|
|
90
94
|
setAttributes,
|
|
91
95
|
icon,
|
|
92
96
|
label
|
|
93
97
|
} = _ref2;
|
|
94
|
-
const
|
|
98
|
+
const scopeVariations = (0, _utils.useScopedBlockVariations)(attributes);
|
|
95
99
|
const {
|
|
96
100
|
replaceInnerBlocks
|
|
97
101
|
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
@@ -99,18 +103,19 @@ function QueryVariationPicker(_ref2) {
|
|
|
99
103
|
return (0, _element.createElement)("div", blockProps, (0, _element.createElement)(_blockEditor.__experimentalBlockVariationPicker, {
|
|
100
104
|
icon: icon,
|
|
101
105
|
label: label,
|
|
102
|
-
variations:
|
|
103
|
-
onSelect:
|
|
104
|
-
if (
|
|
105
|
-
setAttributes({ ...
|
|
106
|
-
query: { ...
|
|
107
|
-
postType: attributes.query.postType ||
|
|
108
|
-
}
|
|
106
|
+
variations: scopeVariations,
|
|
107
|
+
onSelect: variation => {
|
|
108
|
+
if (variation.attributes) {
|
|
109
|
+
setAttributes({ ...variation.attributes,
|
|
110
|
+
query: { ...variation.attributes.query,
|
|
111
|
+
postType: attributes.query.postType || variation.attributes.query.postType
|
|
112
|
+
},
|
|
113
|
+
namespace: attributes.namespace
|
|
109
114
|
});
|
|
110
115
|
}
|
|
111
116
|
|
|
112
|
-
if (
|
|
113
|
-
replaceInnerBlocks(clientId, (0, _blocks.createBlocksFromInnerBlocksTemplate)(
|
|
117
|
+
if (variation.innerBlocks) {
|
|
118
|
+
replaceInnerBlocks(clientId, (0, _blocks.createBlocksFromInnerBlocksTemplate)(variation.innerBlocks), false);
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-library/src/query/edit/query-placeholder.js"],"names":["QueryPlaceholder","attributes","clientId","name","openPatternSelectionModal","setAttributes","isStartingBlank","setIsStartingBlank","blockProps","blockType","allVariations","hasPatterns","select","getBlockVariations","getBlockType","blocksStore","getBlockRootClientId","__experimentalGetPatternsByBlockTypes","blockEditorStore","rootClientId","length","matchingVariation","icon","src","label","title","QueryVariationPicker","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-library/src/query/edit/query-placeholder.js"],"names":["QueryPlaceholder","attributes","clientId","name","openPatternSelectionModal","setAttributes","isStartingBlank","setIsStartingBlank","blockProps","blockType","allVariations","hasPatterns","select","getBlockVariations","getBlockType","blocksStore","getBlockRootClientId","__experimentalGetPatternsByBlockTypes","blockEditorStore","rootClientId","length","matchingVariation","icon","src","label","title","QueryVariationPicker","scopeVariations","replaceInnerBlocks","variation","query","postType","namespace","innerBlocks"],"mappings":";;;;;;;AAQA;;AALA;;AACA;;AAKA;;AAMA;;AACA;;AAKA;;AArBA;AACA;AACA;;AAgBA;AACA;AACA;AAGe,SAASA,gBAAT,OAMX;AAAA;;AAAA,MANsC;AACzCC,IAAAA,UADyC;AAEzCC,IAAAA,QAFyC;AAGzCC,IAAAA,IAHyC;AAIzCC,IAAAA,yBAJyC;AAKzCC,IAAAA;AALyC,GAMtC;AACH,QAAM,CAAEC,eAAF,EAAmBC,kBAAnB,IAA0C,uBAAU,KAAV,CAAhD;AACA,QAAMC,UAAU,GAAG,iCAAnB;AAEA,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,aAAb;AAA4BC,IAAAA;AAA5B,MAA4C,qBAC/CC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,kBAAF;AAAsBC,MAAAA;AAAtB,QAAuCF,MAAM,CAAEG,aAAF,CAAnD;AACA,UAAM;AACLC,MAAAA,oBADK;AAELC,MAAAA;AAFK,QAGFL,MAAM,CAAEM,kBAAF,CAHV;AAIA,UAAMC,YAAY,GAAGH,oBAAoB,CAAEd,QAAF,CAAzC;AAEA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AA1BF,IADD,CADD;AAgCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tcreateBlocksFromInnerBlocksTemplate,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { useState } from '@wordpress/element';\nimport {\n\tuseBlockProps,\n\tstore as blockEditorStore,\n\t__experimentalBlockVariationPicker,\n\t__experimentalGetMatchingVariation as getMatchingVariation,\n} from '@wordpress/block-editor';\nimport { Button, Placeholder } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useScopedBlockVariations } from '../utils';\n\nexport default function QueryPlaceholder( {\n\tattributes,\n\tclientId,\n\tname,\n\topenPatternSelectionModal,\n\tsetAttributes,\n} ) {\n\tconst [ isStartingBlank, setIsStartingBlank ] = useState( false );\n\tconst blockProps = useBlockProps();\n\n\tconst { blockType, allVariations, hasPatterns } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockVariations, getBlockType } = select( blocksStore );\n\t\t\tconst {\n\t\t\t\tgetBlockRootClientId,\n\t\t\t\t__experimentalGetPatternsByBlockTypes,\n\t\t\t} = select( blockEditorStore );\n\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\treturn {\n\t\t\t\tblockType: getBlockType( name ),\n\t\t\t\tallVariations: getBlockVariations( name ),\n\t\t\t\thasPatterns: !! __experimentalGetPatternsByBlockTypes(\n\t\t\t\t\tname,\n\t\t\t\t\trootClientId\n\t\t\t\t).length,\n\t\t\t};\n\t\t},\n\t\t[ name, clientId ]\n\t);\n\n\tconst matchingVariation = getMatchingVariation( attributes, allVariations );\n\tconst icon =\n\t\tmatchingVariation?.icon?.src ||\n\t\tmatchingVariation?.icon ||\n\t\tblockType?.icon?.src;\n\tconst label = matchingVariation?.title || blockType?.title;\n\tif ( isStartingBlank ) {\n\t\treturn (\n\t\t\t<QueryVariationPicker\n\t\t\t\tclientId={ clientId }\n\t\t\t\tattributes={ attributes }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t/>\n\t\t);\n\t}\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Placeholder\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t\tinstructions={ __(\n\t\t\t\t\t'Choose a pattern for the query loop or start blank.'\n\t\t\t\t) }\n\t\t\t>\n\t\t\t\t{ !! hasPatterns && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\tonClick={ openPatternSelectionModal }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Choose' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetIsStartingBlank( true );\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Start blank' ) }\n\t\t\t\t</Button>\n\t\t\t</Placeholder>\n\t\t</div>\n\t);\n}\n\nfunction QueryVariationPicker( {\n\tclientId,\n\tattributes,\n\tsetAttributes,\n\ticon,\n\tlabel,\n} ) {\n\tconst scopeVariations = useScopedBlockVariations( attributes );\n\tconst { replaceInnerBlocks } = useDispatch( blockEditorStore );\n\tconst blockProps = useBlockProps();\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<__experimentalBlockVariationPicker\n\t\t\t\ticon={ icon }\n\t\t\t\tlabel={ label }\n\t\t\t\tvariations={ scopeVariations }\n\t\t\t\tonSelect={ ( variation ) => {\n\t\t\t\t\tif ( variation.attributes ) {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t...variation.attributes,\n\t\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\t\t...variation.attributes.query,\n\t\t\t\t\t\t\t\tpostType:\n\t\t\t\t\t\t\t\t\tattributes.query.postType ||\n\t\t\t\t\t\t\t\t\tvariation.attributes.query.postType,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tnamespace: attributes.namespace,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t\tif ( variation.innerBlocks ) {\n\t\t\t\t\t\treplaceInnerBlocks(\n\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\tcreateBlocksFromInnerBlocksTemplate(\n\t\t\t\t\t\t\t\tvariation.innerBlocks\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"]}
|
package/build/query/utils.js
CHANGED
|
@@ -9,7 +9,9 @@ exports.mapToIHasNameAndId = void 0;
|
|
|
9
9
|
exports.useAllowedControls = useAllowedControls;
|
|
10
10
|
exports.useBlockNameForPatterns = useBlockNameForPatterns;
|
|
11
11
|
exports.useIsPostTypeHierarchical = useIsPostTypeHierarchical;
|
|
12
|
-
exports.
|
|
12
|
+
exports.usePostTypes = void 0;
|
|
13
|
+
exports.useScopedBlockVariations = useScopedBlockVariations;
|
|
14
|
+
exports.useTaxonomies = void 0;
|
|
13
15
|
|
|
14
16
|
var _lodash = require("lodash");
|
|
15
17
|
|
|
@@ -94,6 +96,8 @@ const {
|
|
|
94
96
|
},
|
|
95
97
|
editorStyle: "wp-block-query-editor"
|
|
96
98
|
};
|
|
99
|
+
/** @typedef {import('@wordpress/blocks').WPBlockVariation} WPBlockVariation */
|
|
100
|
+
|
|
97
101
|
/**
|
|
98
102
|
* @typedef IHasNameAndId
|
|
99
103
|
* @property {string|number} id The entity's id.
|
|
@@ -365,4 +369,72 @@ function useBlockNameForPatterns(clientId, attributes) {
|
|
|
365
369
|
}, [clientId, activeVariationName]);
|
|
366
370
|
return activeVariationPatterns !== null && activeVariationPatterns !== void 0 && activeVariationPatterns.length ? blockName : queryLoopName;
|
|
367
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Helper hook that determines if there is an active variation of the block
|
|
374
|
+
* and if there are available specific scoped `block` variations connected with
|
|
375
|
+
* this variation.
|
|
376
|
+
*
|
|
377
|
+
* If there are, these variations are going to be the only ones suggested
|
|
378
|
+
* to the user in setup flow when clicking to `start blank`, without including
|
|
379
|
+
* the default ones for Query Loop.
|
|
380
|
+
*
|
|
381
|
+
* If there are no such scoped `block` variations, the default ones for Query
|
|
382
|
+
* Loop are going to be suggested.
|
|
383
|
+
*
|
|
384
|
+
* The way we determine such variations is with the convention that they have the `namespace`
|
|
385
|
+
* attribute defined as an array. This array should contain the names(`name` property) of any
|
|
386
|
+
* variations they want to be connected to.
|
|
387
|
+
* For example, if we have a `Query Loop` scoped `inserter` variation with the name `products`,
|
|
388
|
+
* we can connect a scoped `block` variation by setting its `namespace` attribute to `['products']`.
|
|
389
|
+
* If the user selects this variation, the `namespace` attribute will be overridden by the
|
|
390
|
+
* main `inserter` variation.
|
|
391
|
+
*
|
|
392
|
+
* @param {Object} attributes The block's attributes.
|
|
393
|
+
* @return {WPBlockVariation[]} The block variations to be suggested in setup flow, when clicking to `start blank`.
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
function useScopedBlockVariations(attributes) {
|
|
398
|
+
const {
|
|
399
|
+
activeVariationName,
|
|
400
|
+
blockVariations
|
|
401
|
+
} = (0, _data.useSelect)(select => {
|
|
402
|
+
var _getActiveBlockVariat;
|
|
403
|
+
|
|
404
|
+
const {
|
|
405
|
+
getActiveBlockVariation,
|
|
406
|
+
getBlockVariations
|
|
407
|
+
} = select(_blocks.store);
|
|
408
|
+
return {
|
|
409
|
+
activeVariationName: (_getActiveBlockVariat = getActiveBlockVariation(queryLoopName, attributes)) === null || _getActiveBlockVariat === void 0 ? void 0 : _getActiveBlockVariat.name,
|
|
410
|
+
blockVariations: getBlockVariations(queryLoopName, 'block')
|
|
411
|
+
};
|
|
412
|
+
}, [attributes]);
|
|
413
|
+
const variations = (0, _element.useMemo)(() => {
|
|
414
|
+
// Filter out the variations that have defined a `namespace` attribute,
|
|
415
|
+
// which means they are 'connected' to specific variations of the block.
|
|
416
|
+
const isNotConnected = variation => {
|
|
417
|
+
var _variation$attributes;
|
|
418
|
+
|
|
419
|
+
return !((_variation$attributes = variation.attributes) !== null && _variation$attributes !== void 0 && _variation$attributes.namespace);
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
if (!activeVariationName) {
|
|
423
|
+
return blockVariations.filter(isNotConnected);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const connectedVariations = blockVariations.filter(variation => {
|
|
427
|
+
var _variation$attributes2, _variation$attributes3;
|
|
428
|
+
|
|
429
|
+
return (_variation$attributes2 = variation.attributes) === null || _variation$attributes2 === void 0 ? void 0 : (_variation$attributes3 = _variation$attributes2.namespace) === null || _variation$attributes3 === void 0 ? void 0 : _variation$attributes3.includes(activeVariationName);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
if (!!connectedVariations.length) {
|
|
433
|
+
return connectedVariations;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return blockVariations.filter(isNotConnected);
|
|
437
|
+
}, [activeVariationName, blockVariations]);
|
|
438
|
+
return variations;
|
|
439
|
+
}
|
|
368
440
|
//# sourceMappingURL=utils.js.map
|