UNPKG

@wordpress/block-library

Version:
1 lines • 3.52 kB
{"version":3,"file":"edit.mjs","names":["blockEditorStore","ToolsPanel","ToolsPanelItem"],"sources":["../../src/accordion-item/edit.jsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport {\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tInspectorControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport clsx from 'clsx';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nexport default function Edit( {\n\tattributes,\n\tclientId,\n\tsetAttributes,\n\tisSelected: isSingleSelected,\n} ) {\n\tconst { openByDefault } = attributes;\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst { isSelected } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( isSingleSelected || openByDefault ) {\n\t\t\t\treturn { isSelected: true };\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tisSelected: select( blockEditorStore ).hasSelectedInnerBlock(\n\t\t\t\t\tclientId,\n\t\t\t\t\ttrue\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ clientId, isSingleSelected, openByDefault ]\n\t);\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t'is-open': openByDefault || isSelected,\n\t\t} ),\n\t} );\n\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps, {\n\t\ttemplateLock: 'all',\n\t\tdirectInsert: true,\n\t} );\n\n\treturn (\n\t\t<>\n\t\t\t<InspectorControls key=\"setting\">\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( { openByDefault: false } );\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\tlabel={ __( 'Open by default' ) }\n\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\thasValue={ () => !! openByDefault }\n\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\tsetAttributes( { openByDefault: false } );\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\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\topenByDefault: value,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tchecked={ openByDefault }\n\t\t\t\t\t\t\thelp={ __(\n\t\t\t\t\t\t\t\t'Accordion content will be displayed by default.'\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<div { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAgBA,SAAwB,KAAM,EAC7B,YACA,UACA,eACA,YAAY,oBACT;CACH,MAAM,EAAE,kBAAkB;CAC1B,MAAM,oBAAoB,+BAA+B;CACzD,MAAM,EAAE,eAAe,WACpB,WAAY;EACb,IAAK,oBAAoB,eACxB,OAAO,EAAE,YAAY,KAAK;EAG3B,OAAO,EACN,YAAY,OAAQA,KAAiB,CAAC,CAAC,sBACtC,UACA,IACD,EACD;CACD,GACA;EAAE;EAAU;EAAkB;CAAc,CAC7C;CAEA,MAAM,aAAa,cAAe,EACjC,WAAW,KAAM,EAChB,WAAW,iBAAiB,WAC7B,CAAE,EACH,CAAE;CAEF,MAAM,mBAAmB,oBAAqB,YAAY;EACzD,cAAc;EACd,cAAc;CACf,CAAE;CAEF,OACC,qBAAA,UAAA,EAAA,UAAA,CACC,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