{"version":3,"file":"edit.mjs","names":["blockEditorStore"],"sources":["../../src/quote/edit.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tAlignmentControl,\n\tBlockControls,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { BlockQuotation } from '@wordpress/components';\nimport { useDispatch, useRegistry, useSelect } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { verse } from '@wordpress/icons';\nimport { migrateToQuoteV2 } from './deprecated';\nimport { Caption } from '../utils/caption';\n\n/**\n * At the moment, deprecations don't handle create blocks from attributes\n * (like when using CPT templates). For this reason, this hook is necessary\n * to avoid breaking templates using the old quote block format.\n *\n * @param {Object} attributes Block attributes.\n * @param {string} clientId   Block client ID.\n */\nconst useMigrateOnLoad = ( attributes, clientId ) => {\n\tconst registry = useRegistry();\n\tconst { updateBlockAttributes, replaceInnerBlocks, selectBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tuseEffect( () => {\n\t\t// As soon as the block is loaded, migrate it to the new version.\n\n\t\tif ( ! attributes.value ) {\n\t\t\t// No need to migrate if it doesn't have the value attribute.\n\t\t\treturn;\n\t\t}\n\n\t\tconst [ newAttributes, newInnerBlocks ] =\n\t\t\tmigrateToQuoteV2( attributes );\n\n\t\tdeprecated( 'Value attribute on the quote block', {\n\t\t\tsince: '6.0',\n\t\t\tversion: '6.5',\n\t\t\talternative: 'inner blocks',\n\t\t} );\n\n\t\t// The selection can be inside an inner block created from the block\n\t\t// type template at insertion, which the migration replaces; restore\n\t\t// the selection to the migrated block in that case.\n\t\tconst shouldReselectBlock = registry\n\t\t\t.select( blockEditorStore )\n\t\t\t.hasSelectedInnerBlock( clientId, true );\n\n\t\tregistry.batch( () => {\n\t\t\tupdateBlockAttributes( clientId, newAttributes );\n\t\t\treplaceInnerBlocks( clientId, newInnerBlocks );\n\t\t\tif ( shouldReselectBlock ) {\n\t\t\t\tselectBlock( clientId );\n\t\t\t}\n\t\t} );\n\t}, [ attributes.value ] );\n};\n\nexport default function QuoteEdit( {\n\tattributes,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tclientId,\n\tclassName,\n\tisSelected,\n} ) {\n\tconst { textAlign, allowedBlocks } = attributes;\n\n\tconst { hasInnerBlocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockCount } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\thasInnerBlocks: getBlockCount( clientId ) > 0,\n\t\t\t};\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tuseMigrateOnLoad( attributes, clientId );\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( className, {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\t__experimentalCaptureToolbars: true,\n\t\trenderAppender: hasInnerBlocks ? false : undefined,\n\t\tallowedBlocks,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<BlockControls group=\"block\">\n\t\t\t\t<AlignmentControl\n\t\t\t\t\tvalue={ textAlign }\n\t\t\t\t\tonChange={ ( nextAlign ) => {\n\t\t\t\t\t\tsetAttributes( { textAlign: nextAlign } );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</BlockControls>\n\t\t\t<BlockQuotation { ...innerBlocksProps }>\n\t\t\t\t{ innerBlocksProps.children }\n\t\t\t\t<Caption\n\t\t\t\t\tattributeKey=\"citation\"\n\t\t\t\t\ttagName=\"cite\"\n\t\t\t\t\tstyle={ { display: 'block' } }\n\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t\ticon={ verse }\n\t\t\t\t\tlabel={ __( 'Quote citation' ) }\n\t\t\t\t\tplaceholder={\n\t\t\t\t\t\t// translators: placeholder text used for the\n\t\t\t\t\t\t// citation\n\t\t\t\t\t\t__( 'Add citation' )\n\t\t\t\t\t}\n\t\t\t\t\taddLabel={ __( 'Add citation' ) }\n\t\t\t\t\tremoveLabel={ __( 'Remove citation' ) }\n\t\t\t\t\texcludeElementClassName\n\t\t\t\t\tclassName=\"wp-block-quote__citation\"\n\t\t\t\t\tinsertBlocksAfter={ insertBlocksAfter }\n\t\t\t\t/>\n\t\t\t</BlockQuotation>\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,oBAAqB,YAAY,aAAc;CACpD,MAAM,WAAW,YAAY;CAC7B,MAAM,EAAE,uBAAuB,oBAAoB,gBAClD,YAAaA,KAAiB;CAC/B,gBAAiB;EAGhB,IAAK,CAAE,WAAW,OAEjB;EAGD,MAAM,CAAE,eAAe,kBACtB,iBAAkB,UAAW;EAE9B,WAAY,sCAAsC;GACjD,OAAO;GACP,SAAS;GACT,aAAa;EACd,CAAE;EAKF,MAAM,sBAAsB,SAC1B,OAAQA,KAAiB,CAAC,CAC1B,sBAAuB,UAAU,IAAK;EAExC,SAAS,YAAa;GACrB,sBAAuB,UAAU,aAAc;GAC/C,mBAAoB,UAAU,cAAe;GAC7C,IAAK,qBACJ,YAAa,QAAS;EAExB,CAAE;CACH,GAAG,CAAE,WAAW,KAAM,CAAE;AACzB;AAEA,SAAwB,UAAW,EAClC,YACA,eACA,mBACA,UACA,WACA,cACG;CACH,MAAM,EAAE,WAAW,kBAAkB;CAErC,MAAM,EAAE,mBAAmB,WACxB,WAAY;EACb,MAAM,EAAE,kBAAkB,OAAQA,KAAiB;EACnD,OAAO,EACN,gBAAgB,cAAe,QAAS,IAAI,EAC7C;CACD,GACA,CAAE,QAAS,CACZ;CAEA,iBAAkB,YAAY,QAAS;CAEvC,MAAM,aAAa,cAAe,EACjC,WAAW,KAAM,WAAW,GACzB,kBAAmB,cAAgB,UACtC,CAAE,EACH,CAAE;CACF,MAAM,mBAAmB,oBAAqB,YAAY;EACzD,+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