UNPKG

@wordpress/block-library

Version:
8 lines (7 loc) 4.79 kB
{ "version": 3, "sources": ["../../src/social-links/deprecated.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * The specific handling by `className` below is needed because `itemsJustification`\n * was introduced in https://github.com/WordPress/gutenberg/pull/28980/files and wasn't\n * declared in block.json.\n *\n * @param {Object} attributes Block's attributes.\n */\nconst migrateWithLayout = ( attributes ) => {\n\tif ( !! attributes.layout ) {\n\t\treturn attributes;\n\t}\n\tconst { className } = attributes;\n\t// Matches classes with `items-justified-` prefix.\n\tconst prefix = `items-justified-`;\n\tconst justifiedItemsRegex = new RegExp( `\\\\b${ prefix }[^ ]*[ ]?\\\\b`, 'g' );\n\tconst newAttributes = {\n\t\t...attributes,\n\t\tclassName: className?.replace( justifiedItemsRegex, '' ).trim(),\n\t};\n\t/**\n\t * Add `layout` prop only if `justifyContent` is defined, for backwards\n\t * compatibility. In other cases the block's default layout will be used.\n\t * Also noting that due to the missing attribute, it's possible for a block\n\t * to have more than one of `justified` classes.\n\t */\n\tconst justifyContent = className\n\t\t?.match( justifiedItemsRegex )?.[ 0 ]\n\t\t?.trim();\n\tif ( justifyContent ) {\n\t\tObject.assign( newAttributes, {\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\tjustifyContent: justifyContent.slice( prefix.length ),\n\t\t\t},\n\t\t} );\n\t}\n\treturn newAttributes;\n};\n\n// Social Links block deprecations.\nconst deprecated = [\n\t// V1. Remove CSS variable use for colors.\n\t{\n\t\tattributes: {\n\t\t\ticonColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomIconColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\ticonColorValue: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\ticonBackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\tcustomIconBackgroundColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\ticonBackgroundColorValue: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\topenInNewTab: {\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t},\n\t\t\tsize: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t\tprovidesContext: {\n\t\t\topenInNewTab: 'openInNewTab',\n\t\t},\n\t\tsupports: {\n\t\t\talign: [ 'left', 'center', 'right' ],\n\t\t\tanchor: true,\n\t\t},\n\t\tmigrate: migrateWithLayout,\n\t\tsave: ( props ) => {\n\t\t\tconst {\n\t\t\t\tattributes: {\n\t\t\t\t\ticonBackgroundColorValue,\n\t\t\t\t\ticonColorValue,\n\t\t\t\t\titemsJustification,\n\t\t\t\t\tsize,\n\t\t\t\t},\n\t\t\t} = props;\n\n\t\t\tconst className = clsx( size, {\n\t\t\t\t'has-icon-color': iconColorValue,\n\t\t\t\t'has-icon-background-color': iconBackgroundColorValue,\n\t\t\t\t[ `items-justified-${ itemsJustification }` ]:\n\t\t\t\t\titemsJustification,\n\t\t\t} );\n\n\t\t\tconst style = {\n\t\t\t\t'--wp--social-links--icon-color': iconColorValue,\n\t\t\t\t'--wp--social-links--icon-background-color':\n\t\t\t\t\ticonBackgroundColorValue,\n\t\t\t};\n\n\t\t\treturn (\n\t\t\t\t<ul { ...useBlockProps.save( { className, style } ) }>\n\t\t\t\t\t<InnerBlocks.Content />\n\t\t\t\t</ul>\n\t\t\t);\n\t\t},\n\t},\n];\n\nexport default deprecated;\n"], "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,aAAa,qBAAqB;AAyGtC;AAhGL,IAAM,oBAAoB,CAAE,eAAgB;AAC3C,MAAK,CAAC,CAAE,WAAW,QAAS;AAC3B,WAAO;AAAA,EACR;AACA,QAAM,EAAE,UAAU,IAAI;AAEtB,QAAM,SAAS;AACf,QAAM,sBAAsB,IAAI,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