@wordpress/block-editor
Version:
8 lines (7 loc) • 4.71 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/block-tools/zoom-out-mode-inserters.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockPopoverInbetween from '../block-popover/inbetween';\nimport ZoomOutModeInserterButton from './zoom-out-mode-inserter-button';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nfunction ZoomOutModeInserters() {\n\tconst [ isReady, setIsReady ] = useState( false );\n\tconst {\n\t\thasSelection,\n\t\tblockOrder,\n\t\tsetInserterIsOpened,\n\t\tsectionRootClientId,\n\t\tselectedBlockClientId,\n\t\tblockInsertionPoint,\n\t\tinsertionPointVisible,\n\t} = useSelect( ( select ) => {\n\t\tconst {\n\t\t\tgetSettings,\n\t\t\tgetBlockOrder,\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectedBlockClientId,\n\t\t\tgetSectionRootClientId,\n\t\t\tgetBlockInsertionPoint,\n\t\t\tisBlockInsertionPointVisible,\n\t\t} = unlock( select( blockEditorStore ) );\n\n\t\tconst root = getSectionRootClientId();\n\n\t\treturn {\n\t\t\thasSelection: !! getSelectionStart().clientId,\n\t\t\tblockOrder: getBlockOrder( root ),\n\t\t\tsectionRootClientId: root,\n\t\t\tsetInserterIsOpened:\n\t\t\t\tgetSettings().__experimentalSetIsInserterOpened,\n\t\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t\t\tblockInsertionPoint: getBlockInsertionPoint(),\n\t\t\tinsertionPointVisible: isBlockInsertionPointVisible(),\n\t\t};\n\t}, [] );\n\n\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\tconst { showInsertionPoint } = unlock( useDispatch( blockEditorStore ) );\n\n\t// Defer the initial rendering to avoid the jumps due to the animation.\n\tuseEffect( () => {\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetIsReady( true );\n\t\t}, 500 );\n\t\treturn () => {\n\t\t\tclearTimeout( timeout );\n\t\t};\n\t}, [] );\n\n\tif ( ! isReady || ! hasSelection ) {\n\t\treturn null;\n\t}\n\n\tconst previousClientId = selectedBlockClientId;\n\tconst index = blockOrder.findIndex(\n\t\t( clientId ) => selectedBlockClientId === clientId\n\t);\n\n\tconst insertionIndex = index + 1;\n\n\tconst nextClientId = blockOrder[ insertionIndex ];\n\n\t// If the block insertion point is visible, and the insertion\n\t// Indices match then we don't need to render the inserter.\n\tif (\n\t\tinsertionPointVisible &&\n\t\tblockInsertionPoint?.index === insertionIndex\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<BlockPopoverInbetween\n\t\t\tpreviousClientId={ previousClientId }\n\t\t\tnextClientId={ nextClientId }\n\t\t>\n\t\t\t<ZoomOutModeInserterButton\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetInserterIsOpened( {\n\t\t\t\t\t\trootClientId: sectionRootClientId,\n\t\t\t\t\t\tinsertionIndex,\n\t\t\t\t\t\ttab: 'patterns',\n\t\t\t\t\t\tcategory: 'all',\n\t\t\t\t\t} );\n\t\t\t\t\tshowInsertionPoint( sectionRootClientId, insertionIndex, {\n\t\t\t\t\t\toperation: 'insert',\n\t\t\t\t\t} );\n\t\t\t\t} }\n\t\t\t/>\n\t\t</BlockPopoverInbetween>\n\t);\n}\n\nexport default ZoomOutModeInserters;\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuC;AACvC,qBAAoC;AAKpC,uBAAkC;AAClC,2CAAsC;AACtC,mBAA0C;AAC1C,yBAAuB;AA6EpB;AA3EH,SAAS,uBAAuB;AAC/B,QAAM,CAAE,SAAS,UAAW,QAAI,yBAAU,KAAM;AAChD,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;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