UNPKG

@wordpress/block-library

Version:
1 lines • 5.13 kB
{"version":3,"file":"utils.cjs","names":["unlock","blockEditorPrivateApis","createBlock","__"],"sources":["../../src/post-author/utils.js"],"sourcesContent":["import { createBlock } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { unlock } from '../lock-unlock';\n\nconst { cleanEmptyObject } = unlock( blockEditorPrivateApis );\n\n/**\n * Generate Author-related blocks based on block attributes.\n *\n * @param {Object} attributes Block's attributes.\n * @param {Object} blockTypes Block types.\n * @return {Object} Generated block.\n */\nexport function recreateWithRecommendedBlocks( attributes, blockTypes ) {\n\tconst {\n\t\tavatarSize,\n\t\tbyline,\n\t\tshowAvatar,\n\t\tshowBio,\n\t\tisLink,\n\t\tlinkTarget,\n\t\ttextAlign,\n\t\tstyle,\n\t\t...restAttributes\n\t} = attributes;\n\n\tconst shouldInsertAvatarBlock =\n\t\tshowAvatar &&\n\t\tblockTypes.some( ( blockType ) => blockType.name === 'core/avatar' );\n\tconst shouldInsertParagraphBlock =\n\t\tbyline &&\n\t\tblockTypes.some( ( blockType ) => blockType.name === 'core/paragraph' );\n\tconst shouldInsertPostAuthorNameBlock = blockTypes.some(\n\t\t( blockType ) => blockType.name === 'core/post-author-name'\n\t);\n\tconst shouldInsertPostAuthorBiographyBlock =\n\t\tshowBio &&\n\t\tblockTypes.some(\n\t\t\t( blockType ) => blockType.name === 'core/post-author-biography'\n\t\t);\n\n\treturn createBlock(\n\t\t'core/group',\n\t\t{\n\t\t\t...restAttributes,\n\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t...style,\n\t\t\t\tspacing: {\n\t\t\t\t\t...style?.spacing,\n\t\t\t\t\tblockGap: '1em',\n\t\t\t\t},\n\t\t\t\tcolor: {\n\t\t\t\t\t...style?.color,\n\t\t\t\t\t// Duotone must be applied to the avatar block.\n\t\t\t\t\tduotone: undefined,\n\t\t\t\t},\n\t\t\t} ),\n\t\t\tlayout: {\n\t\t\t\ttype: 'flex',\n\t\t\t\tflexWrap: 'nowrap',\n\t\t\t\tverticalAlignment: 'top',\n\t\t\t},\n\t\t},\n\t\t[\n\t\t\tshouldInsertAvatarBlock &&\n\t\t\t\tcreateBlock( 'core/avatar', {\n\t\t\t\t\tsize: avatarSize,\n\t\t\t\t\tstyle: cleanEmptyObject( {\n\t\t\t\t\t\tborder: {\n\t\t\t\t\t\t\tradius: '0px',\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\tduotone: style?.color?.duotone,\n\t\t\t\t\t\t},\n\t\t\t\t\t} ),\n\t\t\t\t} ),\n\t\t\tcreateBlock(\n\t\t\t\t'core/group',\n\t\t\t\t{\n\t\t\t\t\tstyle: {\n\t\t\t\t\t\tlayout: {\n\t\t\t\t\t\t\tselfStretch: 'fill',\n\t\t\t\t\t\t\tflexSize: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tspacing: {\n\t\t\t\t\t\t\tblockGap: '0',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tlayout: {\n\t\t\t\t\t\ttype: 'flex',\n\t\t\t\t\t\torientation: 'vertical',\n\t\t\t\t\t\tjustifyContent: 'stretch',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t[\n\t\t\t\t\tshouldInsertParagraphBlock &&\n\t\t\t\t\t\tcreateBlock( 'core/paragraph', {\n\t\t\t\t\t\t\tcontent: byline,\n\t\t\t\t\t\t\tplaceholder: __( 'Write byline…' ),\n\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\tfontSize: '0.5em',\n\t\t\t\t\t\t\t\t\ttextAlign,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} ),\n\t\t\t\t\tshouldInsertPostAuthorNameBlock &&\n\t\t\t\t\t\tcreateBlock( 'core/post-author-name', {\n\t\t\t\t\t\t\tisLink,\n\t\t\t\t\t\t\tlinkTarget,\n\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\tfontSize: '1em',\n\t\t\t\t\t\t\t\t\ttextAlign,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} ),\n\t\t\t\t\tshouldInsertPostAuthorBiographyBlock &&\n\t\t\t\t\t\tcreateBlock( 'core/post-author-biography', {\n\t\t\t\t\t\t\tstyle: {\n\t\t\t\t\t\t\t\ttypography: {\n\t\t\t\t\t\t\t\t\tfontSize: '0.7em',\n\t\t\t\t\t\t\t\t\ttextAlign,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t} ),\n\t\t\t\t].filter( Boolean )\n\t\t\t),\n\t\t].filter( Boolean )\n\t);\n}\n"],"mappings":";;;;;;;;;AAKA,MAAM,EAAE,sBAAA,G,4BAAqBA,CAAAA,CAAAA,OAAAA,CAAQC,wBAAAA,WAAuB;;;;;;;;AAS5D,SAAgB,8BAA+B,YAAY,YAAa;CACvE,MAAM,EACL,YACA,QACA,YACA,SACA,QACA,YACA,WACA,OACA,GAAG,mBACA;CAEJ,MAAM,0BACL,cACA,WAAW,MAAQ,cAAe,UAAU,SAAS,aAAc;CACpE,MAAM,6BACL,UACA,WAAW,MAAQ,cAAe,UAAU,SAAS,gBAAiB;CACvE,MAAM,kCAAkC,WAAW,MAChD,cAAe,UAAU,SAAS,uBACrC;CACA,MAAM,uCACL,WACA,WAAW,MACR,cAAe,UAAU,SAAS,4BACrC;CAED,QAAA,GAAOC,kBAAAA,YAAAA,CACN,cACA;EACC,GAAG;EACH,OAAO,iBAAkB;GACxB,GAAG;GACH,SAAS;IACR,GAAG,OAAO;IACV,UAAU;GACX;GACA,OAAO;IACN,GAAG,OAAO;IAEV,SAAS,KAAA;GACV;EACD,CAAE;EACF,QAAQ;GACP,MAAM;GACN,UAAU;GACV,mBAAmB;E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