{"version":3,"file":"edit.mjs","names":["coreStore","WCSpinner"],"sources":["../../src/post-terms/edit.jsx"],"sourcesContent":["import {\n\tInspectorControls,\n\tuseBlockProps,\n\tuseBlockDisplayInformation,\n\tRichText,\n} from '@wordpress/block-editor';\nimport { createBlock, getDefaultBlockName } from '@wordpress/blocks';\nimport { Spinner as WCSpinner, TextControl } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { store as coreStore } from '@wordpress/core-data';\nimport usePostTerms from './use-post-terms';\n\n// Allowed formats for the prefix and suffix fields.\nconst ALLOWED_FORMATS = [\n\t'core/bold',\n\t'core/image',\n\t'core/italic',\n\t'core/link',\n\t'core/strikethrough',\n\t'core/text-color',\n];\n\nexport default function PostTermsEdit( {\n\tattributes,\n\tclientId,\n\tcontext,\n\tisSelected,\n\tsetAttributes,\n\tinsertBlocksAfter,\n} ) {\n\tconst { term, separator, prefix, suffix } = attributes;\n\tconst { postId, postType } = context;\n\n\tconst selectedTerm = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! term ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst { getTaxonomy } = select( coreStore );\n\t\t\tconst taxonomy = getTaxonomy( term );\n\t\t\treturn taxonomy?.visibility?.publicly_queryable ? taxonomy : {};\n\t\t},\n\t\t[ term ]\n\t);\n\tconst { postTerms, hasPostTerms, isLoading } = usePostTerms( {\n\t\tpostId,\n\t\tterm: selectedTerm,\n\t} );\n\tconst hasPost = postId && postType;\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\tconst blockProps = useBlockProps( {\n\t\tclassName: term && `taxonomy-${ term }`,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<TextControl\n\t\t\t\t\tautoComplete=\"off\"\n\t\t\t\t\tlabel={ __( 'Separator' ) }\n\t\t\t\t\tvalue={ separator || '' }\n\t\t\t\t\tonChange={ ( nextValue ) => {\n\t\t\t\t\t\tsetAttributes( { separator: nextValue } );\n\t\t\t\t\t} }\n\t\t\t\t\thelp={ __( 'Enter character(s) used to separate terms.' ) }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<div { ...blockProps }>\n\t\t\t\t{ isLoading && hasPost && <WCSpinner /> }\n\t\t\t\t{ ! isLoading && ( isSelected || prefix ) && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"prefix\"\n\t\t\t\t\t\tallowedFormats={ ALLOWED_FORMATS }\n\t\t\t\t\t\tclassName=\"wp-block-post-terms__prefix\"\n\t\t\t\t\t\taria-label={ __( 'Prefix' ) }\n\t\t\t\t\t\tplaceholder={ __( 'Prefix' ) + ' ' }\n\t\t\t\t\t\tvalue={ prefix }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { prefix: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\t{ ( ! hasPost || ! term ) && (\n\t\t\t\t\t<span>{ blockInformation.title }</span>\n\t\t\t\t) }\n\t\t\t\t{ hasPost &&\n\t\t\t\t\t! isLoading &&\n\t\t\t\t\thasPostTerms &&\n\t\t\t\t\tpostTerms\n\t\t\t\t\t\t.map( ( postTerm ) => (\n\t\t\t\t\t\t\t<a\n\t\t\t\t\t\t\t\tkey={ postTerm.id }\n\t\t\t\t\t\t\t\thref={ postTerm.link }\n\t\t\t\t\t\t\t\tonClick={ ( event ) => event.preventDefault() }\n\t\t\t\t\t\t\t\trel=\"tag\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ decodeEntities( postTerm.name ) }\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t) )\n\t\t\t\t\t\t.reduce( ( prev, curr ) => (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t{ prev }\n\t\t\t\t\t\t\t\t<span className=\"wp-block-post-terms__separator\">\n\t\t\t\t\t\t\t\t\t{ separator || ' ' }\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t{ curr }\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) ) }\n\t\t\t\t{ hasPost &&\n\t\t\t\t\t! isLoading &&\n\t\t\t\t\t! hasPostTerms &&\n\t\t\t\t\t( selectedTerm?.labels?.no_terms ||\n\t\t\t\t\t\t__( 'Term items not found.' ) ) }\n\t\t\t\t{ ! isLoading && ( isSelected || suffix ) && (\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"suffix\"\n\t\t\t\t\t\tallowedFormats={ ALLOWED_FORMATS }\n\t\t\t\t\t\tclassName=\"wp-block-post-terms__suffix\"\n\t\t\t\t\t\taria-label={ __( 'Suffix' ) }\n\t\t\t\t\t\tplaceholder={ ' ' + __( 'Suffix' ) }\n\t\t\t\t\t\tvalue={ suffix }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetAttributes( { suffix: value } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\t__unstableOnSplitAtEnd={\n\t\t\t\t\t\t\tinsertBlocksAfter\n\t\t\t\t\t\t\t\t? () =>\n\t\t\t\t\t\t\t\t\t\tinsertBlocksAfter(\n\t\t\t\t\t\t\t\t\t\t\tcreateBlock( getDefaultBlockName() )\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAM,kBAAkB;CACvB;CACA;CACA;CACA;CACA;CACA;AACD;AAEA,SAAwB,cAAe,EACtC,YACA,UACA,SACA,YACA,eACA,qBACG;CACH,MAAM,EAAE,MAAM,WAAW,QAAQ,WAAW;CAC5C,MAAM,EAAE,QAAQ,aAAa;CAE7B,MAAM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