UNPKG

@wordpress/block-library

Version:
8 lines (7 loc) 5.83 kB
{ "version": 3, "sources": ["../../src/quote/edit.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\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 } from '@wordpress/data';\nimport { Platform, useEffect } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { verse } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { migrateToQuoteV2 } from './deprecated';\nimport { Caption } from '../utils/caption';\n\nconst isWebPlatform = Platform.OS === 'web';\n\nconst TEMPLATE = [ [ 'core/paragraph', {} ] ];\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 } =\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\tregistry.batch( () => {\n\t\t\tupdateBlockAttributes( clientId, newAttributes );\n\t\t\treplaceInnerBlocks( clientId, newInnerBlocks );\n\t\t} );\n\t}, [ attributes.value ] );\n};\n\nexport default function QuoteEdit( {\n\tattributes,\n\tsetAttributes,\n\tinsertBlocksAfter,\n\tclientId,\n\tclassName,\n\tstyle,\n\tisSelected,\n} ) {\n\tconst { textAlign, allowedBlocks } = attributes;\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\t...( ! isWebPlatform && { style } ),\n\t} );\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplate: TEMPLATE,\n\t\ttemplateInsertUpdatesSelection: true,\n\t\t__experimentalCaptureToolbars: true,\n\t\trenderAppender: false,\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={ isWebPlatform ? 'cite' : 'p' }\n\t\t\t\t\tstyle={ isWebPlatform && { 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\t__unstableMobileNoFocusOnMount\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\t{ ...( ! isWebPlatform ? { textAlign } : {} ) }\n\t\t\t\t/>\n\t\t\t</BlockQuotation>\n\t\t</>\n\t);\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,kBAAmB;AACnB,0BAMO;AACP,wBAA+B;AAC/B,kBAAyC;AACzC,qBAAoC;AACpC,wBAAuB;AACvB,mBAAsB;AAKtB,IAAAA,qBAAiC;AACjC,qBAAwB;AAsEtB;AApEF,IAAM,gBAAgB,wBAAS,OAAO;AAEtC,IAAM,WAAW,CAAE,CAAE,kBAAkB,CAAC,CAAE,CAAE;AAU5C,IAAM,mBAAmB,CAAE,YAAY,aAAc;AACpD,QAAM,eAAW,yBAAY;AAC7B,QAAM,EAAE,uBAAuB,mBAAmB,QACjD,yBAAa,oBAAAC,KAAiB;AAC/B,gCAAW,MAAM;AAGhB,QAAK,CAAE,WAAW,OAAQ;AAEzB;AAAA,IACD;AAEA,UAAM,CAAE,eAAe,cAAe,QACrC,qCAAkB,UAAW;AAE9B,0BAAAC,SAAY,sCAAsC;AAAA,MACjD,OAAO;AAAA,MACP,SAAS;AAAA,MACT,aAAa;AAAA,IACd,CAAE;AAEF,aAAS,MAAO,MAAM;AACrB,4BAAuB,UAAU,aAAc;AAC/C,yBAAoB,UAAU,cAAe;AAAA,IAC9C,CAAE;AAAA,EACH,GAAG,CAAE,WAAW,KAAM,CAAE;AACzB;AAEe,SAAR,UAA4B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,EAAE,WAAW,cAAc,IAAI;AAErC,mBAAkB,YAAY,QAAS;AAEvC,QAAM,iBAAa,mCAAe;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