UNPKG

@wordpress/block-library

Version:
1 lines • 13.8 kB
{"version":3,"file":"deprecated.mjs","names":[],"sources":["../../src/heading/deprecated.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tgetColorClassName,\n\tRichText,\n\tuseBlockProps,\n} from '@wordpress/block-editor';\nimport migrateTextAlignAttributeToBlockSupport from '../utils/migrate-text-align';\n\nconst blockSupports = {\n\tclassName: false,\n\tanchor: true,\n};\n\nconst blockAttributes = {\n\talign: {\n\t\ttype: 'string',\n\t},\n\tcontent: {\n\t\ttype: 'string',\n\t\tsource: 'html',\n\t\tselector: 'h1,h2,h3,h4,h5,h6',\n\t\tdefault: '',\n\t},\n\tlevel: {\n\t\ttype: 'number',\n\t\tdefault: 2,\n\t},\n\tplaceholder: {\n\t\ttype: 'string',\n\t},\n};\n\nconst migrateCustomColors = ( attributes ) => {\n\tif ( ! attributes.customTextColor ) {\n\t\treturn attributes;\n\t}\n\tconst style = {\n\t\tcolor: {\n\t\t\ttext: attributes.customTextColor,\n\t\t},\n\t};\n\n\tconst { customTextColor, ...restAttributes } = attributes;\n\n\treturn {\n\t\t...restAttributes,\n\t\tstyle,\n\t};\n};\n\nconst TEXT_ALIGN_OPTIONS = [ 'left', 'right', 'center' ];\n\nconst migrateTextAlign = ( attributes ) => {\n\tconst { align, ...rest } = attributes;\n\treturn TEXT_ALIGN_OPTIONS.includes( align )\n\t\t? { ...rest, textAlign: align }\n\t\t: attributes;\n};\n\nconst v1 = {\n\tsupports: blockSupports,\n\tattributes: {\n\t\t...blockAttributes,\n\t\tcustomTextColor: {\n\t\t\ttype: 'string',\n\t\t},\n\t\ttextColor: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tmigrate: ( attributes ) =>\n\t\tmigrateTextAlignAttributeToBlockSupport(\n\t\t\tmigrateCustomColors( migrateTextAlign( attributes ) )\n\t\t),\n\tsave( { attributes } ) {\n\t\tconst { align, level, content, textColor, customTextColor } =\n\t\t\tattributes;\n\t\tconst tagName = 'h' + level;\n\n\t\tconst textClass = getColorClassName( 'color', textColor );\n\n\t\tconst className = clsx( {\n\t\t\t[ textClass ]: textClass,\n\t\t} );\n\n\t\treturn (\n\t\t\t<RichText.Content\n\t\t\t\tclassName={ className ? className : undefined }\n\t\t\t\ttagName={ tagName }\n\t\t\t\tstyle={ {\n\t\t\t\t\ttextAlign: align,\n\t\t\t\t\tcolor: textClass ? undefined : customTextColor,\n\t\t\t\t} }\n\t\t\t\tvalue={ content }\n\t\t\t/>\n\t\t);\n\t},\n};\nconst v2 = {\n\tattributes: {\n\t\t...blockAttributes,\n\t\tcustomTextColor: {\n\t\t\ttype: 'string',\n\t\t},\n\t\ttextColor: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tmigrate: ( attributes ) =>\n\t\tmigrateTextAlignAttributeToBlockSupport(\n\t\t\tmigrateCustomColors( migrateTextAlign( attributes ) )\n\t\t),\n\tsave( { attributes } ) {\n\t\tconst { align, content, customTextColor, level, textColor } =\n\t\t\tattributes;\n\t\tconst tagName = 'h' + level;\n\n\t\tconst textClass = getColorClassName( 'color', textColor );\n\n\t\tconst className = clsx( {\n\t\t\t[ textClass ]: textClass,\n\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t} );\n\n\t\treturn (\n\t\t\t<RichText.Content\n\t\t\t\tclassName={ className ? className : undefined }\n\t\t\t\ttagName={ tagName }\n\t\t\t\tstyle={ {\n\t\t\t\t\tcolor: textClass ? undefined : customTextColor,\n\t\t\t\t} }\n\t\t\t\tvalue={ content }\n\t\t\t/>\n\t\t);\n\t},\n\tsupports: blockSupports,\n};\nconst v3 = {\n\tsupports: blockSupports,\n\tattributes: {\n\t\t...blockAttributes,\n\t\tcustomTextColor: {\n\t\t\ttype: 'string',\n\t\t},\n\t\ttextColor: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tmigrate: ( attributes ) =>\n\t\tmigrateTextAlignAttributeToBlockSupport(\n\t\t\tmigrateCustomColors( migrateTextAlign( attributes ) )\n\t\t),\n\tsave( { attributes } ) {\n\t\tconst { align, content, customTextColor, level, textColor } =\n\t\t\tattributes;\n\t\tconst tagName = 'h' + level;\n\n\t\tconst textClass = getColorClassName( 'color', textColor );\n\n\t\tconst className = clsx( {\n\t\t\t[ textClass ]: textClass,\n\t\t\t'has-text-color': textColor || customTextColor,\n\t\t\t[ `has-text-align-${ align }` ]: align,\n\t\t} );\n\n\t\treturn (\n\t\t\t<RichText.Content\n\t\t\t\tclassName={ className ? className : undefined }\n\t\t\t\ttagName={ tagName }\n\t\t\t\tstyle={ {\n\t\t\t\t\tcolor: textClass ? undefined : customTextColor,\n\t\t\t\t} }\n\t\t\t\tvalue={ content }\n\t\t\t/>\n\t\t);\n\t},\n};\nconst v4 = {\n\tsupports: {\n\t\talign: [ 'wide', 'full' ],\n\t\tanchor: true,\n\t\tclassName: false,\n\t\tcolor: { link: true },\n\t\tfontSize: true,\n\t\tlineHeight: true,\n\t\t__experimentalSelector: {\n\t\t\t'core/heading/h1': 'h1',\n\t\t\t'core/heading/h2': 'h2',\n\t\t\t'core/heading/h3': 'h3',\n\t\t\t'core/heading/h4': 'h4',\n\t\t\t'core/heading/h5': 'h5',\n\t\t\t'core/heading/h6': 'h6',\n\t\t},\n\t\t__unstablePasteTextInline: true,\n\t},\n\tattributes: blockAttributes,\n\tisEligible: ( { align } ) => TEXT_ALIGN_OPTIONS.includes( align ),\n\tmigrate: ( attributes ) =>\n\t\tmigrateTextAlignAttributeToBlockSupport(\n\t\t\tmigrateCustomColors( migrateTextAlign( attributes ) )\n\t\t),\n\tsave( { attributes } ) {\n\t\tconst { align, content, level } = attributes;\n\t\tconst TagName = 'h' + level;\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<TagName { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content value={ content } />\n\t\t\t</TagName>\n\t\t);\n\t},\n};\n\n// This deprecation covers the serialization of the `wp-block-heading` class\n// into the block's markup after className support was enabled.\nconst v5 = {\n\tsupports: {\n\t\talign: [ 'wide', 'full' ],\n\t\tanchor: true,\n\t\tclassName: false,\n\t\tcolor: {\n\t\t\tgradients: 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\tspacing: {\n\t\t\tmargin: true,\n\t\t\tpadding: true,\n\t\t},\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\tlineHeight: true,\n\t\t\t__experimentalFontFamily: 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__experimentalTextDecoration: true,\n\t\t\t__experimentalDefaultControls: {\n\t\t\t\tfontSize: true,\n\t\t\t\tfontAppearance: true,\n\t\t\t\ttextTransform: true,\n\t\t\t},\n\t\t},\n\t\t__experimentalSelector: 'h1,h2,h3,h4,h5,h6',\n\t\t__unstablePasteTextInline: true,\n\t\t__experimentalSlashInserter: true,\n\t},\n\tattributes: {\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'h1,h2,h3,h4,h5,h6',\n\t\t\tdefault: '',\n\t\t\trole: 'content',\n\t\t},\n\t\tlevel: {\n\t\t\ttype: 'number',\n\t\t\tdefault: 2,\n\t\t},\n\t\tplaceholder: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content, level } = attributes;\n\t\tconst TagName = 'h' + level;\n\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} );\n\n\t\treturn (\n\t\t\t<TagName { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content value={ content } />\n\t\t\t</TagName>\n\t\t);\n\t},\n\tmigrate: ( attributes ) =>\n\t\tmigrateTextAlignAttributeToBlockSupport(\n\t\t\tmigrateCustomColors( migrateTextAlign( attributes ) )\n\t\t),\n};\n\nconst v6 = {\n\tsupports: {\n\t\talign: [ 'wide', 'full' ],\n\t\tanchor: true,\n\t\tclassName: true,\n\t\tsplitting: true,\n\t\t__experimentalBorder: {\n\t\t\tcolor: true,\n\t\t\tradius: true,\n\t\t\tstyle: true,\n\t\t\twidth: true,\n\t\t},\n\t\tcolor: {\n\t\t\tgradients: 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\tspacing: {\n\t\t\tmargin: true,\n\t\t\tpadding: true,\n\t\t},\n\t\ttypography: {\n\t\t\tfontSize: true,\n\t\t\tlineHeight: true,\n\t\t\t__experimentalFontFamily: 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__experimentalTextDecoration: true,\n\t\t\t__experimentalWritingMode: true,\n\t\t\tfitText: true,\n\t\t\t__experimentalDefaultControls: {\n\t\t\t\tfontSize: true,\n\t\t\t},\n\t\t},\n\t\t__unstablePasteTextInline: true,\n\t\t__experimentalSlashInserter: true,\n\t\tinteractivity: {\n\t\t\tclientNavigation: true,\n\t\t},\n\t},\n\tattributes: {\n\t\ttextAlign: {\n\t\t\ttype: 'string',\n\t\t},\n\t\tcontent: {\n\t\t\ttype: 'string',\n\t\t\tsource: 'html',\n\t\t\tselector: 'h1,h2,h3,h4,h5,h6',\n\t\t\tdefault: '',\n\t\t\trole: 'content',\n\t\t},\n\t\tlevel: {\n\t\t\ttype: 'number',\n\t\t\tdefault: 2,\n\t\t},\n\t\tlevelOptions: {\n\t\t\ttype: 'array',\n\t\t},\n\t\tplaceholder: {\n\t\t\ttype: 'string',\n\t\t},\n\t},\n\tsave( { attributes } ) {\n\t\tconst { textAlign, content, level } = attributes;\n\t\tconst TagName = 'h' + level;\n\n\t\tconst className = clsx( {\n\t\t\t[ `has-text-align-${ textAlign }` ]: textAlign,\n\t\t} );\n\n\t\treturn (\n\t\t\t<TagName { ...useBlockProps.save( { className } ) }>\n\t\t\t\t<RichText.Content value={ content } />\n\t\t\t</TagName>\n\t\t);\n\t},\n\tmigrate: ( attributes ) =>\n\t\tmigrateTextAlignAttributeToBlockSupport(\n\t\t\tmigrateCustomColors( migrateTextAlign( attributes ) )\n\t\t),\n\tisEligible( attributes ) {\n\t\treturn (\n\t\t\t!! attributes.textAlign ||\n\t\t\t!! attributes.className?.match(\n\t\t\t\t/\\bhas-text-align-(left|center|right)\\b/\n\t\t\t)\n\t\t);\n\t},\n};\n\nconst deprecated = [ v6, v5, v4, v3, v2, v1 ];\n\nexport default deprecated;\n"],"mappings":";;;;;AAQA,MAAM,gBAAgB;CACrB,WAAW;CACX,QAAQ;AACT;AAEA,MAAM,kBAAkB;CACvB,OAAO,EACN,MAAM,SACP;CACA,SAAS;EACR,MAAM;EACN,QAAQ;EACR,UAAU;EACV,SAAS;CACV;CACA,OAAO;EACN,MAAM;EACN,SAAS;CACV;CACA,aAAa,EACZ,MAAM,SACP;AACD;AAEA,MAAM,uBAAwB,eAAgB;CAC7C,IAAK,CAAE,WAAW,iBACjB,OAAO;CAER,MAAM,QAAQ,EACb,OAAO,EACN,MAAM,WAAW,gBAClB,EACD;CAEA,MAAM,EAAE,iBAAiB,GAAG,mBAAmB;CAE/C,OAAO;EACN,GAAG;EACH;CACD;AACD;AAEA,MAAM,qBAAqB;CAAE;CAAQ;CAAS;AAAS;AAEvD,MAAM,oBAAqB,eAAgB;CAC1C,MAAM,EAAE,OAAO,GAAG,SAAS;CAC3B,OAAO,mBAAmB,SAAU,KAAM,IACvC;EAAE,GAAG;EAAM,WAAW;CAAM,IAC5B;AACJ;AAEA,MAAM,KAAK;CACV,UAAU;CACV,YAAY;EACX,GAAG;EACH,iBAAiB,EAChB,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