UNPKG

@wordpress/block-library

Version:
1 lines • 12.3 kB
{"version":3,"file":"deprecated.mjs","names":[],"sources":["../../src/quote/deprecated.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport { createBlock, parseWithAttributeSchema } from '@wordpress/blocks';\nimport { InnerBlocks, RichText, useBlockProps } from '@wordpress/block-editor';\n\nexport const migrateToQuoteV2 = ( attributes ) => {\n\tconst { value, ...restAttributes } = attributes;\n\n\treturn [\n\t\t{\n\t\t\t...restAttributes,\n\t\t},\n\t\tvalue\n\t\t\t? parseWithAttributeSchema( value, {\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tsource: 'query',\n\t\t\t\t\tselector: 'p',\n\t\t\t\t\tquery: {\n\t\t\t\t\t\tcontent: {\n\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\tsource: 'html',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t} ).map( ( { content } ) =>\n\t\t\t\t\tcreateBlock( 'core/paragraph', { content } )\n\t\t\t\t)\n\t\t\t: createBlock( 'core/paragraph' ),\n\t];\n};\n\nconst TEXT_ALIGN_OPTIONS = [ 'left', 'right', 'center' ];\n\n// Migrate existing text alignment settings to the renamed attribute.\nconst migrateTextAlign = ( attributes, innerBlocks ) => {\n\tconst { align, ...rest } = attributes;\n\t// Check if there are valid alignments stored in the old attribute\n\t// and assign them to the new attribute name.\n\tconst migratedAttributes = TEXT_ALIGN_OPTIONS.includes( align )\n\t\t? { ...rest, textAlign: align }\n\t\t: attributes;\n\n\treturn [ migratedAttributes, innerBlocks ];\n};\n\n// Migrate the v2 blocks with style === `2`;\nconst migrateLargeStyle = ( attributes, innerBlocks ) => {\n\treturn [\n\t\t{\n\t\t\t...attributes,\n\t\t\tclassName: attributes.className\n\t\t\t\t? attributes.className + ' is-style-large'\n\t\t\t\t: 'is-style-large',\n\t\t},\n\t\tinnerBlocks,\n\t];\n};\n\n// Version before the 'align' attribute was replaced with 'textAlign'.\nconst v4 = {\n\tattributes: {\n\t\tvalue: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'blockquote',\n\t\t\tmultiline: 'p',\n\t\t\tdefault: '',\n\t\t\trole: 'content',\n\t\t},\n\t\tcitation: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'cite',\n\t\t\tdefault: '',\n\t\t\trole: 'content',\n\t\t},\n\t\talign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsupports: {\n\t\tanchor: true,\n\t\thtml: false,\n\t\t__experimentalOnEnter: true,\n\t\t__experimentalOnMerge: true,\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\tlineHeight: true,\n\t\t\t__experimentalFontFamily: true,\n\t\t\t__experimentalFontWeight: true,\n\t\t\t__experimentalFontStyle: true,\n\t\t\t__experimentalTextTransform: true,\n\t\t\t__experimentalTextDecoration: true,\n\t\t\t__experimentalLetterSpacing: true,\n\t\t\t__experimentalDefaultControls: {\n\t\t\t\tfontSize: true,\n\t\t\t\tfontAppearance: true,\n\t\t\t},\n\t\t},\n\t\tcolor: {\n\t\t\tgradients: true,\n\t\t\theading: true,\n\t\t\tlink: true,\n\t\t\t__experimentalDefaultControls: {\n\t\t\t\tbackground: true,\n\t\t\t\ttext: true,\n\t\t\t},\n\t\t},\n\t},\n\tisEligible: ( { align } ) => TEXT_ALIGN_OPTIONS.includes( align ),\n\tsave( { attributes } ) {\n\t\tconst { align, citation } = attributes;\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t} );\n\t\treturn (\n\t\t\t<blockquote { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<InnerBlocks.Content />\n\t\t\t\t{ ! RichText.isEmpty( citation ) && (\n\t\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\n\t\t);\n\t},\n\tmigrate: migrateTextAlign,\n};\n\nconst v3 = {\n\tattributes: {\n\t\tvalue: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'blockquote',\n\t\t\tmultiline: 'p',\n\t\t\tdefault: '',\n\t\t\trole: 'content',\n\t\t},\n\t\tcitation: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'cite',\n\t\t\tdefault: '',\n\t\t\trole: 'content',\n\t\t},\n\t\talign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsupports: {\n\t\tanchor: true,\n\t\t__experimentalSlashInserter: true,\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\tlineHeight: true,\n\t\t\t__experimentalFontStyle: true,\n\t\t\t__experimentalFontWeight: true,\n\t\t\t__experimentalLetterSpacing: true,\n\t\t\t__experimentalTextTransform: true,\n\t\t\t__experimentalDefaultControls: {\n\t\t\t\tfontSize: true,\n\t\t\t\tfontAppearance: true,\n\t\t\t},\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { align, value, citation } = attributes;\n\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t} );\n\n\t\treturn (\n\t\t\t<blockquote { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content multiline value={ value } />\n\t\t\t\t{ ! RichText.isEmpty( citation ) && (\n\t\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\n\t\t);\n\t},\n\tmigrate( attributes ) {\n\t\treturn migrateTextAlign( ...migrateToQuoteV2( attributes ) );\n\t},\n};\n\nconst v2 = {\n\tattributes: {\n\t\tvalue: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'blockquote',\n\t\t\tmultiline: 'p',\n\t\t\tdefault: '',\n\t\t},\n\t\tcitation: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'cite',\n\t\t\tdefault: '',\n\t\t},\n\t\talign: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tmigrate( attributes ) {\n\t\treturn migrateTextAlign( ...migrateToQuoteV2( attributes ) );\n\t},\n\tsave( { attributes } ) {\n\t\tconst { align, value, citation } = attributes;\n\n\t\treturn (\n\t\t\t<blockquote style={ { textAlign: align ? align : null } }>\n\t\t\t\t<RichText.Content multiline value={ value } />\n\t\t\t\t{ ! RichText.isEmpty( citation ) && (\n\t\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\n\t\t);\n\t},\n};\n\nconst v1 = {\n\tattributes: {\n\t\tvalue: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'blockquote',\n\t\t\tmultiline: 'p',\n\t\t\tdefault: '',\n\t\t},\n\t\tcitation: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'cite',\n\t\t\tdefault: '',\n\t\t},\n\t\talign: {\n\t\t\ttype: 'string',\n\t\t},\n\t\tstyle: {\n\t\t\ttype: 'number',\n\t\t\tdefault: 1,\n\t\t},\n\t},\n\n\tmigrate( attributes ) {\n\t\tif ( attributes.style === 2 ) {\n\t\t\tconst { style, ...restAttributes } = attributes;\n\t\t\treturn migrateTextAlign(\n\t\t\t\t...migrateLargeStyle( ...migrateToQuoteV2( restAttributes ) )\n\t\t\t);\n\t\t}\n\n\t\treturn migrateTextAlign( ...migrateToQuoteV2( attributes ) );\n\t},\n\n\tsave( { attributes } ) {\n\t\tconst { align, value, citation, style } = attributes;\n\n\t\treturn (\n\t\t\t<blockquote\n\t\t\t\tclassName={ style === 2 ? 'is-large' : '' }\n\t\t\t\tstyle={ { textAlign: align ? align : null } }\n\t\t\t>\n\t\t\t\t<RichText.Content multiline value={ value } />\n\t\t\t\t{ ! RichText.isEmpty( citation ) && (\n\t\t\t\t\t<RichText.Content tagName=\"cite\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\n\t\t);\n\t},\n};\n\nconst v0 = {\n\tattributes: {\n\t\tvalue: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'blockquote',\n\t\t\tmultiline: 'p',\n\t\t\tdefault: '',\n\t\t},\n\t\tcitation: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'footer',\n\t\t\tdefault: '',\n\t\t},\n\t\talign: {\n\t\t\ttype: 'string',\n\t\t},\n\t\tstyle: {\n\t\t\ttype: 'number',\n\t\t\tdefault: 1,\n\t\t},\n\t},\n\n\tmigrate( attributes ) {\n\t\tif ( ! isNaN( parseInt( attributes.style ) ) ) {\n\t\t\tconst { style, ...restAttributes } = attributes;\n\t\t\treturn migrateTextAlign( ...migrateToQuoteV2( restAttributes ) );\n\t\t}\n\n\t\treturn migrateTextAlign( ...migrateToQuoteV2( attributes ) );\n\t},\n\n\tsave( { attributes } ) {\n\t\tconst { align, value, citation, style } = attributes;\n\n\t\treturn (\n\t\t\t<blockquote\n\t\t\t\tclassName={ `blocks-quote-style-${ style }` }\n\t\t\t\tstyle={ { textAlign: align ? align : null } }\n\t\t\t>\n\t\t\t\t<RichText.Content multiline value={ value } />\n\t\t\t\t{ ! RichText.isEmpty( citation ) && (\n\t\t\t\t\t<RichText.Content tagName=\"footer\" value={ citation } />\n\t\t\t\t) }\n\t\t\t</blockquote>\n\t\t);\n\t},\n};\n\n/**\n * New deprecations need to be placed first\n * for them to have higher priority.\n *\n * Old deprecations may need to be updated as well.\n *\n * See block-deprecation.md\n */\nexport default [ v4, v3, v2, v1, v0 ];\n"],"mappings":";;;;;AAIA,MAAa,oBAAqB,eAAgB;CACjD,MAAM,EAAE,OAAO,GAAG,mBAAmB;CAErC,OAAO,CACN,EACC,GAAG,eACJ,GACA,QACG,yBAA0B,OAAO;EACjC,MAAM;EACN,QAAQ;EACR,UAAU;EACV,OAAO,EACN,SAAS;GACR,MAAM;GACN,QAAQ;EACT,EACD;CACD,CAAE,CAAC,CAAC,KAAO,EAAE,cACZ,YAAa,kBAAkB,EAAE,QAAQ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