UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 2.09 kB
{ "version": 3, "sources": ["../../../src/components/visual-editor/use-zoom-out-mode-exit.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect } from '@wordpress/compose';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Allows Zoom Out mode to be exited by double clicking in the selected block.\n */\nexport function useZoomOutModeExit() {\n\tconst { getSettings, isZoomOut } = unlock( useSelect( blockEditorStore ) );\n\tconst { resetZoomLevel } = unlock( useDispatch( blockEditorStore ) );\n\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tfunction onDoubleClick( event ) {\n\t\t\t\tif ( ! isZoomOut() ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! event.defaultPrevented ) {\n\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\tconst { __experimentalSetIsInserterOpened } = getSettings();\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof __experimentalSetIsInserterOpened === 'function'\n\t\t\t\t\t) {\n\t\t\t\t\t\t__experimentalSetIsInserterOpened( false );\n\t\t\t\t\t}\n\t\t\t\t\tresetZoomLevel();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tnode.addEventListener( 'dblclick', onDoubleClick );\n\n\t\t\treturn () => {\n\t\t\t\tnode.removeEventListener( 'dblclick', onDoubleClick );\n\t\t\t};\n\t\t},\n\t\t[ getSettings, isZoomOut, resetZoomLevel ]\n\t);\n}\n"], "mappings": ";AAGA,SAAS,WAAW,mBAAmB;AACvC,SAAS,oBAAoB;AAC7B,SAAS,SAAS,wBAAwB;AAK1C,SAAS,cAAc;AAKhB,SAAS,qBAAqB;AACpC,QAAM,EAAE,aAAa,UAAU,IAAI,OAAQ,UAAW,gBAAiB,CAAE;AACzE,QAAM,EAAE,eAAe,IAAI,OAAQ,YAAa,gBAAiB,CAAE;AAEnE,SAAO;AAAA,IACN,CAAE,SAAU;AACX,eAAS,cAAe,OAAQ;AAC/B,YAAK,CAAE,UAAU,GAAI;AACpB;AAAA,QACD;AAEA,YAAK,CAAE,MAAM,kBAAmB;AAC/B,gBAAM,eAAe;AAErB,gBAAM,EAAE,kCAAkC,IAAI,YAAY;AAE1D,cACC,OAAO,sCAAsC,YAC5C;AACD,8CAAmC,KAAM;AAAA,UAC1C;AACA,yBAAe;AAAA,QAChB;AAAA,MACD;AAEA,WAAK,iBAAkB,YAAY,aAAc;AAEjD,aAAO,MAAM;AACZ,aAAK,oBAAqB,YAAY,aAAc;AAAA,MACrD;AAAA,IACD;AAAA,IACA,CAAE,aAAa,WAAW,cAAe;AAAA,EAC1C;AACD;", "names": [] }