UNPKG

@wordpress/block-editor

Version:
40 lines (37 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _element = require("@wordpress/element"); var _data = require("@wordpress/data"); var _blockListContext = require("./block-list-context"); var _store = require("../../store"); /** * WordPress dependencies */ /** * Internal dependencies */ const useScrollUponInsertion = ({ clientId, isSelected, isLayoutCalculated, elementRef }) => { const { scrollRef } = (0, _blockListContext.useBlockListContext)(); const wasBlockJustInserted = (0, _data.useSelect)(select => !!select(_store.store).wasBlockJustInserted(clientId, 'inserter_menu'), [clientId]); (0, _element.useEffect)(() => { const lastScrollTo = scrollRef?.lastScrollTo.current; const alreadyScrolledTo = lastScrollTo?.clientId === clientId; if (alreadyScrolledTo || !isSelected || !scrollRef || !wasBlockJustInserted || !isLayoutCalculated) { return; } scrollRef.scrollToElement(elementRef); lastScrollTo.clientId = clientId; }, [isSelected, scrollRef, wasBlockJustInserted, elementRef, isLayoutCalculated, clientId]); }; var _default = exports.default = useScrollUponInsertion; //# sourceMappingURL=use-scroll-upon-insertion.native.js.map