UNPKG

@wordpress/block-library

Version:
1 lines • 2.32 kB
{"version":3,"file":"save.mjs","names":[],"sources":["../../src/gallery/save.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport {\n\tRichText,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\t__experimentalGetElementClassName,\n} from '@wordpress/block-editor';\nimport { isGalleryFlexLayout } from './shared';\n\nexport default function saveWithInnerBlocks( { attributes } ) {\n\tconst { caption, columns, imageCrop, dynamicContent, layout } = attributes;\n\tconst isFlexLayout = isGalleryFlexLayout( layout );\n\n\tconst captionElement = ! RichText.isEmpty( caption ) && (\n\t\t<RichText.Content\n\t\t\ttagName=\"figcaption\"\n\t\t\tclassName={ clsx(\n\t\t\t\t'blocks-gallery-caption',\n\t\t\t\t__experimentalGetElementClassName( 'caption' )\n\t\t\t) }\n\t\t\tvalue={ caption }\n\t\t/>\n\t);\n\n\t// In dynamic mode the images are resolved at render time and the `<figure>`\n\t// wrapper is built by the server render callback (`block_core_gallery_render()`),\n\t// so persist only the gallery-level caption. It still sources from\n\t// `.blocks-gallery-caption`, so it round-trips; the render callback drops it in\n\t// after the resolved images. Nothing is saved when there's no caption.\n\tif ( dynamicContent ) {\n\t\treturn captionElement || null;\n\t}\n\n\tconst className = clsx( 'has-nested-images', {\n\t\t[ `columns-${ columns }` ]: isFlexLayout && columns !== undefined,\n\t\t[ `columns-default` ]: isFlexLayout && columns === undefined,\n\t\t'is-cropped': isFlexLayout && imageCrop,\n\t} );\n\tconst blockProps = useBlockProps.save( { className } );\n\tconst innerBlocksProps = useInnerBlocksProps.save( blockProps );\n\n\treturn (\n\t\t<figure { ...innerBlocksProps }>\n\t\t\t{ innerBlocksProps.children }\n\t\t\t{ captionElement }\n\t\t</figure>\n\t);\n}\n"],"mappings":";;;;;AASA,SAAwB,oBAAqB,EAAE,cAAe;CAC7D,MAAM,EAAE,SAAS,SAAS,WAAW,gBAAgB,WAAW;CAChE,MAAM,eAAe,oBAAqB,MAAO;CAEjD,MAAM,iBAAiB,CAAE,SAAS,QAAS,OAAQ,KAClD,oBAAC,SAAS,SAAV;EACC,SAAQ;EACR,WAAY,KACX,0BACA,kCAAmC,SAAU,CAC9C;EACA,OAAQ;CACR,CAAA;CAQF,IAAK,gBACJ,OAAO,kBAAkB;CAG1B,MAAM,YAAY,KAAM,qBAAqB;GAC1C,WAAY,YAAc,gBAAgB,YAAY,KAAA;GACtD,oBAAqB,gBAAgB,YAAY,KAAA;EACnD,cAAc,gBAAgB;CAC/B,CAAE;CACF,MAAM,aAAa,cAAc,KAAM,EAAE,UAAU,CAAE;CACrD,MAAM,mBAAmB,oBAAoB,KAAM,UAAW;CAE9D,OACC,qBAAC,UAAD;EAAQ,GAAK;EAAb,UAAA,CACG,iBAAiB,UACjB,cACK;;AAEV"}