@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 11.7 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["useToolsPanelDropdownMenuProps","usePublicTaxonomies","__","InspectorControls","ToolsPanel","ToolsPanelItem","InheritControl","TaxonomyControl","OrderControl","IncludeControl","EmptyTermsControl","NestedTermsControl","MaxTermsControl","AdvancedControls"],"sources":["../../../../src/terms-query/edit/inspector-controls/index.jsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { InspectorControls } from '@wordpress/block-editor';\nimport { useToolsPanelDropdownMenuProps } from '../../../utils/hooks';\nimport { usePublicTaxonomies } from '../../utils';\nimport TaxonomyControl from './taxonomy-control';\nimport OrderControl from './order-control';\nimport EmptyTermsControl from './empty-terms-control';\nimport NestedTermsControl from './nested-terms-control';\nimport InheritControl from './inherit-control';\nimport MaxTermsControl from './max-terms-control';\nimport AdvancedControls from './advanced-controls';\nimport IncludeControl from './include-control';\n\nexport default function TermsQueryInspectorControls( {\n\tattributes,\n\tsetQuery,\n\tsetAttributes,\n\tclientId,\n\ttemplateSlug,\n} ) {\n\tconst { termQuery, tagName: TagName } = attributes;\n\tconst {\n\t\ttaxonomy,\n\t\torderBy,\n\t\torder,\n\t\thideEmpty,\n\t\tinherit,\n\t\tshowNested,\n\t\tperPage,\n\t\tinclude,\n\t} = termQuery;\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst taxonomies = usePublicTaxonomies();\n\n\tconst isTaxonomyHierarchical = taxonomies.find(\n\t\t( _taxonomy ) => _taxonomy.slug === taxonomy\n\t)?.hierarchical;\n\tconst inheritQuery = !! inherit;\n\t// Display the inherit control when we're in a taxonomy-related\n\t// template (category, tag, or custom taxonomy).\n\tconst displayInheritControl =\n\t\t[ 'taxonomy', 'category', 'tag', 'archive' ].includes( templateSlug ) ||\n\t\ttemplateSlug?.startsWith( 'taxonomy-' ) ||\n\t\ttemplateSlug?.startsWith( 'category-' ) ||\n\t\ttemplateSlug?.startsWith( 'tag-' );\n\t// Display the showNested control if the taxonomy is hierarchical.\n\tconst displayShowNestedControl = isTaxonomyHierarchical;\n\tconst hasIncludeFilter = !! include?.length;\n\n\t// Labels shared between ToolsPanelItem and its child control.\n\tconst queryTypeControlLabel = __( 'Query type' );\n\tconst taxonomyControlLabel = __( 'Taxonomy' );\n\tconst orderByControlLabel = __( 'Order by' );\n\tconst emptyTermsControlLabel = __( 'Show empty terms' );\n\tconst nestedTermsControlLabel = __( 'Show nested terms' );\n\tconst maxTermsControlLabel = __( 'Max terms' );\n\tconst includeControlLabel = __( 'Selected terms' );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\ttermQuery: {\n\t\t\t\t\t\t\t\ttaxonomy: 'category',\n\t\t\t\t\t\t\t\torder: 'asc',\n\t\t\t\t\t\t\t\torderBy: 'name',\n\t\t\t\t\t\t\t\tinclude: [],\n\t\t\t\t\t\t\t\thideEmpty: true,\n\t\t\t\t\t\t\t\tshowNested: false,\n\t\t\t\t\t\t\t\tinherit: false,\n\t\t\t\t\t\t\t\tperPage: 10,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t{ displayInheritControl && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => inherit !== false }\n\t\t\t\t\t\t\tlabel={ queryTypeControlLabel }\n\t\t\t\t\t\t\tonDeselect={ () => setQuery( { inherit: false } ) }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<InheritControl\n\t\t\t\t\t\t\t\tlabel={ queryTypeControlLabel }\n\t\t\t\t\t\t\t\tvalue={ inherit }\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</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! inheritQuery && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => taxonomy !== 'category' }\n\t\t\t\t\t\t\tlabel={ taxonomyControlLabel }\n\t\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\t\tsetQuery( { taxonomy: 'category' } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<TaxonomyControl\n\t\t\t\t\t\t\t\tlabel={ taxonomyControlLabel }\n\t\t\t\t\t\t\t\tvalue={ taxonomy }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\t// We also need to reset the include filter when changing taxonomy.\n\t\t\t\t\t\t\t\t\tsetQuery( { taxonomy: value, include: [] } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => orderBy !== 'name' || order !== 'asc' }\n\t\t\t\t\t\tlabel={ orderByControlLabel }\n\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\tsetQuery( { orderBy: 'name', order: 'asc' } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<OrderControl\n\t\t\t\t\t\t\tlabel={ orderByControlLabel }\n\t\t\t\t\t\t\t{ ...{ orderBy, order } }\n\t\t\t\t\t\t\tonChange={ ( newOrderBy, newOrder ) => {\n\t\t\t\t\t\t\t\tsetQuery( {\n\t\t\t\t\t\t\t\t\torderBy: newOrderBy,\n\t\t\t\t\t\t\t\t\torder: newOrder,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tdisabled={ hasIncludeFilter }\n\t\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t\thasIncludeFilter\n\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t'When specific terms are selected, the order is based on their selection order.'\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ ! inheritQuery && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => !! include?.length }\n\t\t\t\t\t\t\tlabel={ includeControlLabel }\n\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\tsetQuery( {\n\t\t\t\t\t\t\t\t\tinclude: [],\n\t\t\t\t\t\t\t\t\torderBy: 'name',\n\t\t\t\t\t\t\t\t\torder: 'asc',\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<IncludeControl\n\t\t\t\t\t\t\t\tlabel={ includeControlLabel }\n\t\t\t\t\t\t\t\ttaxonomy={ taxonomy }\n\t\t\t\t\t\t\t\tvalue={ include }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetQuery( { include: 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</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => hideEmpty !== true }\n\t\t\t\t\t\tlabel={ emptyTermsControlLabel }\n\t\t\t\t\t\tonDeselect={ () => setQuery( { hideEmpty: true } ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<EmptyTermsControl\n\t\t\t\t\t\t\tlabel={ emptyTermsControlLabel }\n\t\t\t\t\t\t\tvalue={ hideEmpty }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetQuery( { hideEmpty: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t{ displayShowNestedControl && (\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => showNested !== false }\n\t\t\t\t\t\t\tlabel={ nestedTermsControlLabel }\n\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\tsetQuery( { showNested: false } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<NestedTermsControl\n\t\t\t\t\t\t\t\tlabel={ nestedTermsControlLabel }\n\t\t\t\t\t\t\t\tvalue={ showNested }\n\t\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\t\tsetQuery( { showNested: value } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tdisabled={ hasIncludeFilter }\n\t\t\t\t\t\t\t\thelp={\n\t\t\t\t\t\t\t\t\thasIncludeFilter\n\t\t\t\t\t\t\t\t\t\t? __(\n\t\t\t\t\t\t\t\t\t\t\t\t'When specific terms are selected, only those are displayed.'\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t) }\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\thasValue={ () => perPage !== 10 }\n\t\t\t\t\t\tlabel={ maxTermsControlLabel }\n\t\t\t\t\t\tonDeselect={ () => setQuery( { perPage: 10 } ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t>\n\t\t\t\t\t\t<MaxTermsControl\n\t\t\t\t\t\t\tlabel={ maxTermsControlLabel }\n\t\t\t\t\t\t\tvalue={ perPage }\n\t\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\t\tsetQuery( { perPage: value } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<AdvancedControls\n\t\t\t\tTagName={ TagName }\n\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\tclientId={ clientId }\n\t\t\t/>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,SAAwB,4BAA6B,EACpD,YACA,UACA,eACA,UACA,gBACG;CACH,MAAM,EAAE,WAAW,SAAS,YAAY;CACxC,MAAM,EACL,UACA,SACA,OACA,WACA,SACA,YACA,SACA,YACG;CACJ,MAAM,qBAAA,GAAoBA,wBAAAA,+BAAAA,CAA+B;CAIzD,MAAM,0BAAA,GAFaC,eAAAA,oBAAAA,CAEqB,CAAC,CAAC,MACvC,cAAe,UAAU,SAAS,QACrC,CAAC,EAAE;CACH,MAAM,eAAe,CAAC,CAAE;CAGxB,MAAM,wBACL;EAAE;EAAY;EAAY;EAAO;CAAU,CAAC,CAAC,SAAU,YAAa,KACpE,cAAc,WAAY,WAAY,KACtC,cAAc,WAAY,WAAY,KACtC,cAAc,WAAY,MAAO;CAElC,MAAM,2BAA2B;CACjC,MAAM,mBAAmB,CAAC,CAAE,SAAS;CAGrC,MAAM,yBAAA,GAAwBC,gBAAAA,GAAAA,CAAI,YAAa;CAC/C,MAAM,wBAAA,GAAuBA,gBAAAA,GAAAA,CAAI,UAAW;CAC5C,MAAM,uBAAA,GAAsBA,gBAAAA,GAAAA,CAAI,UAAW;CAC3C,MAAM,0BAAA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