UNPKG

@wordpress/block-library

Version:
8 lines (7 loc) 2.5 kB
{ "version": 3, "sources": ["../../src/buttons/edit.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { store as blocksStore } from '@wordpress/blocks';\n\nconst DEFAULT_BLOCK = {\n\tname: 'core/button',\n\tattributesToCopy: [\n\t\t'backgroundColor',\n\t\t'border',\n\t\t'className',\n\t\t'fontFamily',\n\t\t'fontSize',\n\t\t'gradient',\n\t\t'style',\n\t\t'textColor',\n\t\t'width',\n\t],\n};\n\nfunction ButtonsEdit( { attributes, className } ) {\n\tconst { fontSize, layout, style } = attributes;\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( className, {\n\t\t\t'has-custom-font-size': fontSize || style?.typography?.fontSize,\n\t\t} ),\n\t} );\n\tconst { hasButtonVariations } = useSelect( ( select ) => {\n\t\tconst buttonVariations = select( blocksStore ).getBlockVariations(\n\t\t\t'core/button',\n\t\t\t'inserter'\n\t\t);\n\t\treturn {\n\t\t\thasButtonVariations: buttonVariations.length > 0,\n\t\t};\n\t}, [] );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\tdefaultBlock: DEFAULT_BLOCK,\n\t\t// This check should be handled by the `Inserter` internally to be consistent across all blocks that use it.\n\t\tdirectInsert: ! hasButtonVariations,\n\t\ttemplate: [ [ 'core/button' ] ],\n\t\ttemplateInsertUpdatesSelection: true,\n\t\torientation: layout?.orientation ?? 'horizontal',\n\t} );\n\n\treturn <div { ...innerBlocksProps } />;\n}\n\nexport default ButtonsEdit;\n"], "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,eAAe,2BAA2B;AACnD,SAAS,iBAAiB;AAC1B,SAAS,SAAS,mBAAmB;AA2C7B;AAzCR,IAAM,gBAAgB;AAAA,EACrB,MAAM;AAAA,EACN,kBAAkB;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,SAAS,YAAa,EAAE,YAAY,UAAU,GAAI;AACjD,QAAM,EAAE,UAAU,QAAQ,MAAM,IAAI;AACpC,QAAM,aAAa,cAAe;AAAA,IACjC,WAAW,KAAM,WAAW;AAAA,MAC3B,wBAAwB,YAAY,OAAO,YAAY;AAAA,IACxD,CAAE;AAAA,EACH,CAAE;AACF,QAAM,EAAE,oBAAoB,IAAI,UAAW,CAAE,WAAY;AACxD,UAAM,mBAAmB,OAAQ,WAAY,EAAE;AAAA,MAC9C;AAAA,MACA;AAAA,IACD;AACA,WAAO;AAAA,MACN,qBAAqB,iBAAiB,SAAS;AAAA,IAChD;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,mBAAmB,oBAAqB,YAAY;AAAA,IACzD,cAAc;AAAA;AAAA,IAEd,cAAc,CAAE;AAAA,IAChB,UAAU,CAAE,CAAE,aAAc,CAAE;AAAA,IAC9B,gCAAgC;AAAA,IAChC,aAAa,QAAQ,eAAe;AAAA,EACrC,CAAE;AAEF,SAAO,oBAAC,SAAM,GAAG,kBAAmB;AACrC;AAEA,IAAO,eAAQ;", "names": [] }