@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 6.26 kB
Source Map (JSON)
{"version":3,"file":"edit.cjs","names":["useBlockProps","useInnerBlocksProps","useState","useToolsPanelDropdownMenuProps","useSelect","blockEditorStore","InspectorControls","ToolsPanel","__","ToolsPanelItem","ToggleControl","TextControl","withIgnoreIMEEvents","RichText"],"sources":["../../src/details/edit.jsx"],"sourcesContent":["import {\n\tRichText,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport {\n\tTextControl,\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { withIgnoreIMEEvents } from '@wordpress/keycodes';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nfunction DetailsEdit( { attributes, setAttributes, clientId } ) {\n\tconst { name, showContent, summary, allowedBlocks, placeholder } =\n\t\tattributes;\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\t__experimentalCaptureToolbars: true,\n\t\tallowedBlocks,\n\t} );\n\tconst [ isOpen, setIsOpen ] = useState( showContent );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\t// Check if the inner blocks are selected.\n\tconst hasSelectedInnerBlock = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).hasSelectedInnerBlock( clientId, true ),\n\t\t[ clientId ]\n\t);\n\n\tconst handleSummaryKeyDown = ( event ) => {\n\t\tif ( event.key === 'Enter' && ! event.shiftKey ) {\n\t\t\tsetIsOpen( ( prevIsOpen ) => ! prevIsOpen );\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\t// Prevent spacebar from toggling <details> while typing.\n\tconst handleSummaryKeyUp = ( event ) => {\n\t\tif ( event.key === ' ' ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls>\n\t\t\t\t<ToolsPanel\n\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\tshowContent: false,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t>\n\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\tlabel={ __( 'Open by default' ) }\n\t\t\t\t\t\thasValue={ () => showContent }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tshowContent: false,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\tlabel={ __( 'Open by default' ) }\n\t\t\t\t\t\t\tchecked={ showContent }\n\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tshowContent: ! showContent,\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\t</ToolsPanelItem>\n\t\t\t\t</ToolsPanel>\n\t\t\t</InspectorControls>\n\t\t\t<InspectorControls group=\"advanced\">\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Name attribute' ) }\n\t\t\t\t\tvalue={ name || '' }\n\t\t\t\t\tonChange={ ( newName ) =>\n\t\t\t\t\t\tsetAttributes( { name: newName } )\n\t\t\t\t\t}\n\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t'Enables multiple Details blocks with the same name attribute to be connected, with only one open at a time.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\t\t\t<details\n\t\t\t\t{ ...innerBlocksProps }\n\t\t\t\topen={ isOpen || hasSelectedInnerBlock }\n\t\t\t\tonToggle={ ( event ) => setIsOpen( event.target.open ) }\n\t\t\t\tname={ name || '' }\n\t\t\t>\n\t\t\t\t<summary\n\t\t\t\t\tonKeyDown={ withIgnoreIMEEvents( handleSummaryKeyDown ) }\n\t\t\t\t\tonKeyUp={ handleSummaryKeyUp }\n\t\t\t\t>\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tidentifier=\"summary\"\n\t\t\t\t\t\taria-label={ __(\n\t\t\t\t\t\t\t'Write summary. Press Enter to expand or collapse the details.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tplaceholder={ placeholder || __( 'Write summary…' ) }\n\t\t\t\t\t\twithoutInteractiveFormatting\n\t\t\t\t\t\tvalue={ summary }\n\t\t\t\t\t\tonChange={ ( newSummary ) =>\n\t\t\t\t\t\t\tsetAttributes( { summary: newSummary } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</summary>\n\t\t\t\t{ innerBlocksProps.children }\n\t\t\t</details>\n\t\t</>\n\t);\n}\n\nexport default DetailsEdit;\n"],"mappings":";;;;;;;;;;;;;;AAmBA,SAAS,YAAa,EAAE,YAAY,eAAe,YAAa;CAC/D,MAAM,EAAE,MAAM,aAAa,SAAS,eAAe,gBAClD;CACD,MAAM,cAAA,GAAaA,wBAAAA,cAAAA,CAAc;CACjC,MAAM,oBAAA,GAAmBC,wBAAAA,oBAAAA,CAAqB,YAAY;EACzD,+BAA+B;EAC/B;CACD,CAAE;CACF,MAAM,CAAE,QAAQ,cAAA,GAAcC,mBAAAA,SAAAA,CAAU,WAAY;CACpD,MAAM,qBAAA,GAAoBC,kBAAAA,+BAAAA,CAA+B;CAGzD,MAAM,yBAAA,GAAwBC,gBAAAA,UAAAA,EAC3B,WACD,OAAQC,wBAAAA,KAAiB,CAAC,CAAC,sBAAuB,UAAU,IAAK,GAClE,CAAE,QAAS,CACZ;CAEA,MAA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