@wordpress/block-editor
Version:
8 lines (7 loc) • 1.85 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../../src/components/block-list/use-block-props/use-scroll-into-view.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useReducedMotion, useRefEffect } from '@wordpress/compose';\n\nexport function useScrollIntoView( { isSelected } ) {\n\tconst prefersReducedMotion = useReducedMotion();\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isSelected ) {\n\t\t\t\tconst { ownerDocument } = node;\n\t\t\t\tconst { defaultView } = ownerDocument;\n\t\t\t\tif ( ! defaultView.IntersectionObserver ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst observer = new defaultView.IntersectionObserver(\n\t\t\t\t\t( entries ) => {\n\t\t\t\t\t\t// Once observing starts, we always get an initial\n\t\t\t\t\t\t// entry with the intersecting state.\n\t\t\t\t\t\tif ( ! entries[ 0 ].isIntersecting ) {\n\t\t\t\t\t\t\tnode.scrollIntoView( {\n\t\t\t\t\t\t\t\tbehavior: prefersReducedMotion\n\t\t\t\t\t\t\t\t\t? 'instant'\n\t\t\t\t\t\t\t\t\t: 'smooth',\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tobserver.disconnect();\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tobserver.observe( node );\n\t\t\t\treturn () => {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t\t[ isSelected ]\n\t);\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAExC,SAAS,kBAAmB,EAAE,WAAW,GAAI;AACnD,QAAM,2BAAuB,iCAAiB;AAC9C,aAAO;AAAA,IACN,CAAE,SAAU;AACX,UAAK,YAAa;AACjB,cAAM,EAAE,cAAc,IAAI;AAC1B,cAAM,EAAE,YAAY,IAAI;AACxB,YAAK,CAAE,YAAY,sBAAuB;AACzC;AAAA,QACD;AACA,cAAM,WAAW,IAAI,YAAY;AAAA,UAChC,CAAE,YAAa;AAGd,gBAAK,CAAE,QAAS,CAAE,EAAE,gBAAiB;AACpC,mBAAK,eAAgB;AAAA,gBACpB,UAAU,uBACP,YACA;AAAA,cACJ,CAAE;AAAA,YACH;AACA,qBAAS,WAAW;AAAA,UACrB;AAAA,QACD;AACA,iBAAS,QAAS,IAAK;AACvB,eAAO,MAAM;AACZ,mBAAS,WAAW;AAAA,QACrB;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,UAAW;AAAA,EACd;AACD;",
"names": []
}