UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 4.21 kB
{ "version": 3, "sources": ["../../../src/components/block-tools/block-toolbar-popover.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useShortcut } from '@wordpress/keyboard-shortcuts';\n/**\n * Internal dependencies\n */\nimport { PrivateBlockPopover } from '../block-popover';\nimport useBlockToolbarPopoverProps from './use-block-toolbar-popover-props';\nimport useSelectedBlockToolProps from './use-selected-block-tool-props';\nimport { store as blockEditorStore } from '../../store';\nimport { PrivateBlockToolbar } from '../block-toolbar';\n\nexport default function BlockToolbarPopover( {\n\tclientId,\n\tisTyping,\n\t__unstableContentRef,\n} ) {\n\tconst { capturingClientId, isInsertionPointVisible, lastClientId } =\n\t\tuseSelectedBlockToolProps( clientId );\n\n\t// Stores the active toolbar item index so the block toolbar can return focus\n\t// to it when re-mounting.\n\tconst initialToolbarItemIndexRef = useRef();\n\n\tuseEffect( () => {\n\t\t// Resets the index whenever the active block changes so this is not\n\t\t// persisted. See https://github.com/WordPress/gutenberg/pull/25760#issuecomment-717906169\n\t\tinitialToolbarItemIndexRef.current = undefined;\n\t}, [ clientId ] );\n\n\tconst { stopTyping } = useDispatch( blockEditorStore );\n\tconst isToolbarForcedRef = useRef( false );\n\n\tuseShortcut( 'core/block-editor/focus-toolbar', () => {\n\t\tisToolbarForcedRef.current = true;\n\t\tstopTyping( true );\n\t} );\n\n\tuseEffect( () => {\n\t\tisToolbarForcedRef.current = false;\n\t} );\n\n\t// If the block has a parent with __experimentalCaptureToolbars enabled,\n\t// the toolbar should be positioned over the topmost capturing parent.\n\tconst clientIdToPositionOver = capturingClientId || clientId;\n\n\tconst popoverProps = useBlockToolbarPopoverProps( {\n\t\tcontentElement: __unstableContentRef?.current,\n\t\tclientId: clientIdToPositionOver,\n\t} );\n\n\treturn (\n\t\t! isTyping && (\n\t\t\t<PrivateBlockPopover\n\t\t\t\tclientId={ clientIdToPositionOver }\n\t\t\t\tbottomClientId={ lastClientId }\n\t\t\t\tclassName={ clsx( 'block-editor-block-list__block-popover', {\n\t\t\t\t\t'is-insertion-point-visible': isInsertionPointVisible,\n\t\t\t\t} ) }\n\t\t\t\tresize={ false }\n\t\t\t\t{ ...popoverProps }\n\t\t\t\t__unstableContentRef={ __unstableContentRef }\n\t\t\t>\n\t\t\t\t<PrivateBlockToolbar\n\t\t\t\t\t// If the toolbar is being shown because of being forced\n\t\t\t\t\t// it should focus the toolbar right after the mount.\n\t\t\t\t\tfocusOnMount={ isToolbarForcedRef.current }\n\t\t\t\t\t__experimentalInitialIndex={\n\t\t\t\t\t\tinitialToolbarItemIndexRef.current\n\t\t\t\t\t}\n\t\t\t\t\t__experimentalOnIndexChange={ ( index ) => {\n\t\t\t\t\t\tinitialToolbarItemIndexRef.current = index;\n\t\t\t\t\t} }\n\t\t\t\t\tvariant=\"toolbar\"\n\t\t\t\t/>\n\t\t\t</PrivateBlockPopover>\n\t\t)\n\t);\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAIjB,kBAA4B;AAC5B,qBAAkC;AAClC,gCAA4B;AAI5B,2BAAoC;AACpC,6CAAwC;AACxC,2CAAsC;AACtC,mBAA0C;AAC1C,2BAAoC;AAqDhC;AAnDW,SAAR,oBAAsC;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,EAAE,mBAAmB,yBAAyB,aAAa,QAChE,qCAAAA,SAA2B,QAAS;AAIrC,QAAM,iCAA6B,uBAAO;AAE1C,gCAAW,MAAM;AAGhB,+BAA2B,UAAU;AAAA,EACtC,GAAG,CAAE,QAAS,CAAE;AAEhB,QAAM,EAAE,WAAW,QAAI,yBAAa,aAAAC,KAAiB;AACrD,QAAM,yBAAqB,uBAAQ,KAAM;AAEzC,6CAA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