@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 5.06 kB
Source Map (JSON)
{"version":3,"file":"edit.mjs","names":["blockEditorStore","ToolsPanel","ToolsPanelItem"],"sources":["../../src/query-pagination/edit.jsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport {\n\tInspectorControls,\n\tuseBlockProps,\n\tuseInnerBlocksProps,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { useEffect } from '@wordpress/element';\nimport { QueryPaginationArrowControls } from './query-pagination-arrow-controls';\nimport { QueryPaginationLabelControl } from './query-pagination-label-control';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nexport default function QueryPaginationEdit( {\n\tattributes: { paginationArrow, showLabel },\n\tsetAttributes,\n\tclientId,\n} ) {\n\tconst hasNextPreviousBlocks = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlocks } = select( blockEditorStore );\n\t\t\tconst innerBlocks = getBlocks( clientId );\n\t\t\t/**\n\t\t\t * Show the `paginationArrow` and `showLabel` controls only if a\n\t\t\t * `QueryPaginationNext/Previous` block exists.\n\t\t\t */\n\t\t\treturn innerBlocks?.find( ( innerBlock ) => {\n\t\t\t\treturn [\n\t\t\t\t\t'core/query-pagination-next',\n\t\t\t\t\t'core/query-pagination-previous',\n\t\t\t\t].includes( innerBlock.name );\n\t\t\t} );\n\t\t},\n\t\t[ clientId ]\n\t);\n\tconst { __unstableMarkNextChangeAsNotPersistent } =\n\t\tuseDispatch( blockEditorStore );\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\tconst blockProps = useBlockProps();\n\tconst innerBlocksProps = useInnerBlocksProps( blockProps );\n\n\t// Always show label text if paginationArrow is set to 'none'.\n\tuseEffect( () => {\n\t\tif ( paginationArrow === 'none' && ! showLabel ) {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tsetAttributes( { showLabel: true } );\n\t\t}\n\t}, [\n\t\tpaginationArrow,\n\t\tsetAttributes,\n\t\tshowLabel,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t] );\n\n\treturn (\n\t\t<>\n\t\t\t{ hasNextPreviousBlocks && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ToolsPanel\n\t\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tpaginationArrow: 'none',\n\t\t\t\t\t\t\t\tshowLabel: true,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\thasValue={ () => paginationArrow !== 'none' }\n\t\t\t\t\t\t\tlabel={ __( 'Pagination arrow' ) }\n\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\tsetAttributes( { paginationArrow: 'none' } )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<QueryPaginationArrowControls\n\t\t\t\t\t\t\t\tvalue={ paginationArrow }\n\t\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t\tsetAttributes( { paginationArrow: 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</ToolsPanelItem>\n\t\t\t\t\t\t{ paginationArrow !== 'none' && (\n\t\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\t\thasValue={ () => ! showLabel }\n\t\t\t\t\t\t\t\tlabel={ __( 'Show text' ) }\n\t\t\t\t\t\t\t\tonDeselect={ () =>\n\t\t\t\t\t\t\t\t\tsetAttributes( { showLabel: true } )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<QueryPaginationLabelControl\n\t\t\t\t\t\t\t\t\tvalue={ showLabel }\n\t\t\t\t\t\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\t\t\t\t\t\tsetAttributes( { showLabel: value } );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ToolsPanelItem>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</ToolsPanel>\n\t\t\t\t</InspectorControls>\n\t\t\t) }\n\t\t\t<nav { ...innerBlocksProps } />\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;;;AAiBA,SAAwB,oBAAqB,EAC5C,YAAY,EAAE,iBAAiB,aAC/B,eACA,YACG;CACH,MAAM,wBAAwB,WAC3B,WAAY;EACb,MAAM,EAAE,cAAc,OAAQA,KAAiB;;;;;EAM/C,OALoB,UAAW,QAKd,CAAC,EAAE,MAAQ,eAAgB;GAC3C,OAAO,CACN,8BACA,gCACD,CAAC,CAAC,SAAU,WAAW,IAAK;EAC7B,CAAE;CACH,GACA,CAAE,QAAS,CACZ;CACA,MAAM,EAAE,4CACP,YAAaA,KAAiB;CAC/B,MAAM,oBAAoB,+BAA+B;CACzD,MAAM,aAAa,cAAc;CACjC,MAAM,mBAAmB,oBAAqB,UAAW;CAGzD,gBAAiB;EAChB,IAAK,oBAAoB,UAAU,CAAE,WAAY;GAChD,wCAAwC;GACxC,cAAe,EAAE,WAAW,KAAK,CAAE;EACpC;CACD,GAAG;EACF;EACA;EACA;EACA;CACD,CAAE;CAEF,OACC,qBAAA,UAAA,EAAA,UAAA,CACG,yBACD,oBAAC,mBAAD,EAAA,UACC,qBAACC,0BAAD;EACC,OAAQ,GAAI,UAAW;EACvB,gBAAiB;GAChB,cAAe;IACd,iBAAiB;IACjB,WAAW;GACZ,CAAE;EACH;EACoB;EARrB,UAAA,CAUC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