UNPKG

@wordpress/block-library

Version:
8 lines (7 loc) 4.52 kB
{ "version": 3, "sources": ["../../src/buttons/deprecated.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { InnerBlocks, useBlockProps } from '@wordpress/block-editor';\n\n/**\n * @param {Object} attributes Block's attributes.\n */\nconst migrateWithLayout = ( attributes ) => {\n\tif ( !! attributes.layout ) {\n\t\treturn attributes;\n\t}\n\n\tconst { contentJustification, orientation, ...updatedAttributes } =\n\t\tattributes;\n\n\tif ( contentJustification || orientation ) {\n\t\tObject.assign( updatedAttributes, {\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\t...( contentJustification && {\n\t\t\t\t\tjustifyContent: contentJustification,\n\t\t\t\t} ),\n\t\t\t\t...( orientation && { orientation } ),\n\t\t\t},\n\t\t} );\n\t}\n\n\treturn updatedAttributes;\n};\n\nconst deprecated = [\n\t{\n\t\tattributes: {\n\t\t\tcontentJustification: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t\torientation: {\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'horizontal',\n\t\t\t},\n\t\t},\n\t\tsupports: {\n\t\t\tanchor: true,\n\t\t\talign: [ 'wide', 'full' ],\n\t\t\t__experimentalExposeControlsToChildren: true,\n\t\t\tspacing: {\n\t\t\t\tblockGap: true,\n\t\t\t\tmargin: [ 'top', 'bottom' ],\n\t\t\t\t__experimentalDefaultControls: {\n\t\t\t\t\tblockGap: true,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\tisEligible: ( { contentJustification, orientation } ) =>\n\t\t\t!! contentJustification || !! orientation,\n\t\tmigrate: migrateWithLayout,\n\t\tsave( { attributes: { contentJustification, orientation } } ) {\n\t\t\treturn (\n\t\t\t\t<div\n\t\t\t\t\t{ ...useBlockProps.save( {\n\t\t\t\t\t\tclassName: clsx( {\n\t\t\t\t\t\t\t[ `is-content-justification-${ contentJustification }` ]:\n\t\t\t\t\t\t\t\tcontentJustification,\n\t\t\t\t\t\t\t'is-vertical': orientation === 'vertical',\n\t\t\t\t\t\t} ),\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<InnerBlocks.Content />\n\t\t\t\t</div>\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tsupports: {\n\t\t\talign: [ 'center', 'left', 'right' ],\n\t\t\tanchor: true,\n\t\t},\n\t\tsave() {\n\t\t\treturn (\n\t\t\t\t<div>\n\t\t\t\t\t<InnerBlocks.Content />\n\t\t\t\t</div>\n\t\t\t);\n\t\t},\n\t\tisEligible( { align } ) {\n\t\t\treturn align && [ 'center', 'left', 'right' ].includes( align );\n\t\t},\n\t\tmigrate( attributes ) {\n\t\t\treturn migrateWithLayout( {\n\t\t\t\t...attributes,\n\t\t\t\talign: undefined,\n\t\t\t\t// Floating Buttons blocks shouldn't have been supported in the\n\t\t\t\t// first place. Most users using them probably expected them to\n\t\t\t\t// act like content justification controls, so these blocks are\n\t\t\t\t// migrated to use content justification.\n\t\t\t\t// As for center-aligned Buttons blocks, the content justification\n\t\t\t\t// equivalent will create an identical end result in most cases.\n\t\t\t\tcontentJustification: attributes.align,\n\t\t\t} );\n\t\t},\n\t},\n];\n\nexport default deprecated;\n"], "mappings": ";AAGA,OAAO,UAAU;AAIjB,SAAS,aAAa,qBAAqB;AAiEtC;AA5DL,IAAM,oBAAoB,CAAE,eAAgB;AAC3C,MAAK,CAAC,CAAE,WAAW,QAAS;AAC3B,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,sBAAsB,aAAa,GAAG,kBAAkB,IAC/D;AAED,MAAK,wBAAwB,aAAc;AAC1C,WAAO,OAAQ,mBAAmB;AAAA,MACjC,QAAQ;AAAA,QACP,MAAM;AAAA,QACN,GAAK,wBAAwB;AAAA,UAC5B,gBAAgB;AAAA,QACjB;AAAA,QACA,GAAK,eAAe,EAAE,YAAY;AAAA,MACnC;AAAA,IACD,CAAE;AAAA,EACH;AAEA,S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