{"version":3,"file":"placeholder.mjs","names":["blocksStore"],"sources":["../../src/group/placeholder.jsx"],"sourcesContent":["import { useSelect } from '@wordpress/data';\nimport { useBlockProps } from '@wordpress/block-editor';\nimport { __ } from '@wordpress/i18n';\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { Path, SVG, Button, Placeholder } from '@wordpress/components';\nimport { useState, useEffect } from '@wordpress/element';\n\n/**\n * Returns a custom variation icon.\n *\n * @param {string} name The block variation name.\n *\n * @return {React.JSX.Element} The SVG element.\n */\nconst getGroupPlaceholderIcons = ( name = 'group' ) => {\n\tconst icons = {\n\t\tgroup: (\n\t\t\t<SVG\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\twidth=\"48\"\n\t\t\t\theight=\"48\"\n\t\t\t\tviewBox=\"0 0 48 48\"\n\t\t\t>\n\t\t\t\t<Path d=\"M0 10a2 2 0 0 1 2-2h44a2 2 0 0 1 2 2v28a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V10Z\" />\n\t\t\t</SVG>\n\t\t),\n\t\t'group-row': (\n\t\t\t<SVG\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\twidth=\"48\"\n\t\t\t\theight=\"48\"\n\t\t\t\tviewBox=\"0 0 48 48\"\n\t\t\t>\n\t\t\t\t<Path d=\"M0 10a2 2 0 0 1 2-2h19a2 2 0 0 1 2 2v28a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V10Zm25 0a2 2 0 0 1 2-2h19a2 2 0 0 1 2 2v28a2 2 0 0 1-2 2H27a2 2 0 0 1-2-2V10Z\" />\n\t\t\t</SVG>\n\t\t),\n\t\t'group-stack': (\n\t\t\t<SVG\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\twidth=\"48\"\n\t\t\t\theight=\"48\"\n\t\t\t\tviewBox=\"0 0 48 48\"\n\t\t\t>\n\t\t\t\t<Path d=\"M0 10a2 2 0 0 1 2-2h44a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V10Zm0 17a2 2 0 0 1 2-2h44a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V27Z\" />\n\t\t\t</SVG>\n\t\t),\n\t\t'group-grid': (\n\t\t\t<SVG\n\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\twidth=\"48\"\n\t\t\t\theight=\"48\"\n\t\t\t\tviewBox=\"0 0 48 48\"\n\t\t\t>\n\t\t\t\t<Path d=\"M0 10a2 2 0 0 1 2-2h19a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V10Zm25 0a2 2 0 0 1 2-2h19a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H27a2 2 0 0 1-2-2V10ZM0 27a2 2 0 0 1 2-2h19a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V27Zm25 0a2 2 0 0 1 2-2h19a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H27a2 2 0 0 1-2-2V27Z\" />\n\t\t\t</SVG>\n\t\t),\n\t};\n\treturn icons?.[ name ];\n};\n\n/**\n * A custom hook to tell the Group block whether to show the variation placeholder.\n *\n * @param {Object}  props                  Arguments to pass to hook.\n * @param {Object}  [props.attributes]     The block's attributes.\n * @param {string}  [props.usedLayoutType] The block's current layout type.\n * @param {boolean} [props.hasInnerBlocks] Whether the block has inner blocks.\n *\n * @return {[boolean, Function]} A state value and setter function.\n */\nexport function useShouldShowPlaceHolder( {\n\tattributes = {\n\t\tstyle: undefined,\n\t\tbackgroundColor: undefined,\n\t\ttextColor: undefined,\n\t\tfontSize: undefined,\n\t},\n\tusedLayoutType = '',\n\thasInnerBlocks = false,\n} ) {\n\tconst { style, backgroundColor, textColor, fontSize } = attributes;\n\t/*\n\t * Shows the placeholder when no known styles are set,\n\t * or when a non-default layout has been selected.\n\t * Should the Group block support more style presets in the\n\t * future, e.g., attributes.spacingSize, we can add them to the\n\t * condition.\n\t */\n\tconst [ showPlaceholder, setShowPlaceholder ] = useState(\n\t\t! hasInnerBlocks &&\n\t\t\t! backgroundColor &&\n\t\t\t! fontSize &&\n\t\t\t! textColor &&\n\t\t\t! style &&\n\t\t\tusedLayoutType !== 'flex' &&\n\t\t\tusedLayoutType !== 'grid'\n\t);\n\n\tif (\n\t\tshowPlaceholder &&\n\t\t( !! hasInnerBlocks ||\n\t\t\t!! backgroundColor ||\n\t\t\t!! fontSize ||\n\t\t\t!! textColor ||\n\t\t\t!! style ||\n\t\t\tusedLayoutType === 'flex' )\n\t) {\n\t\tsetShowPlaceholder( false );\n\t}\n\n\treturn [ showPlaceholder, setShowPlaceholder ];\n}\n\n/**\n * Display group variations if none is selected.\n *\n * @param {Object}   props          Component props.\n * @param {string}   props.name     The block's name.\n * @param {Function} props.onSelect Function to set block's attributes.\n *\n * @return {React.JSX.Element}                The placeholder.\n */\nfunction GroupPlaceHolder( { name, onSelect } ) {\n\tconst variations = useSelect(\n\t\t( select ) => select( blocksStore ).getBlockVariations( name, 'block' ),\n\t\t[ name ]\n\t);\n\tconst blockProps = useBlockProps( {\n\t\tclassName: 'wp-block-group__placeholder',\n\t} );\n\n\tuseEffect( () => {\n\t\tif ( variations && variations.length === 1 ) {\n\t\t\tonSelect( variations[ 0 ] );\n\t\t}\n\t}, [ onSelect, variations ] );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t<Placeholder\n\t\t\t\tinstructions={ __( 'Group blocks together. Select a layout:' ) }\n\t\t\t>\n\t\t\t\t{ /*\n\t\t\t\t * Taken from BlockVariationPicker component.\n\t\t\t\t * Disable reason: The `list` ARIA role is redundant but\n\t\t\t\t * Safari+VoiceOver won't announce the list otherwise.\n\t\t\t\t */\n\t\t\t\t/* eslint-disable jsx-a11y/no-redundant-roles */ }\n\t\t\t\t<ul\n\t\t\t\t\trole=\"list\"\n\t\t\t\t\tclassName=\"wp-block-group-placeholder__variations\"\n\t\t\t\t\taria-label={ __( 'Block variations' ) }\n\t\t\t\t>\n\t\t\t\t\t{ variations.map( ( variation ) => (\n\t\t\t\t\t\t<li key={ variation.name }>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\t\ticon={ getGroupPlaceholderIcons(\n\t\t\t\t\t\t\t\t\tvariation.name\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\ticonSize={ 48 }\n\t\t\t\t\t\t\t\tonClick={ () => onSelect( variation ) }\n\t\t\t\t\t\t\t\tclassName=\"wp-block-group-placeholder__variation-button\"\n\t\t\t\t\t\t\t\tlabel={ `${ variation.title }: ${ variation.description }` }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</li>\n\t\t\t\t\t) ) }\n\t\t\t\t</ul>\n\t\t\t\t{ /* eslint-enable jsx-a11y/no-redundant-roles */ }\n\t\t\t</Placeholder>\n\t\t</div>\n\t);\n}\n\nexport default GroupPlaceHolder;\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAM,4BAA6B,OAAO,YAAa;CA2CtD,OAAO;EAzCN,OACC,oBAAC,KAAD;GACC,OAAM;GACN,OAAM;GACN,QAAO;GACP,SAAQ;GAER,UAAA,oBAAC,MAAD,EAAM,GAAE,4EAA6E,CAAA;EACjF,CAAA;EAEN,aACC,oBAAC,KAAD;GACC,OAAM;GACN,OAAM;GACN,QAAO;GACP,SAAQ;GAER,UAAA,oBAAC,MAAD,EAAM,GAAE,sJAAuJ,CAAA;EAC3J,CAAA;EAEN,eACC,oBAAC,KAAD;GACC,OAAM;GACN,OAAM;GACN,QAAO;GACP,SAAQ;GAER,UAAA,oBAAC,MAAD,EAAM,GAAE,qJAAsJ,CAAA;EAC1J,CAAA;EAEN,cACC,oBAAC,KAAD;GACC,OAAM;GACN,OAAM;GACN,QAAO;GACP,SAAQ;GAER,UAAA,oBAAC,MAAD,EAAM,GAAE,ySAA0S,CA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