@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
8 lines (7 loc) • 4.25 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/components/zoom-out-toggle/index.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { square as zoomOutIcon } from '@wordpress/icons';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport {\n\tuseShortcut,\n\tstore as keyboardShortcutsStore,\n} from '@wordpress/keyboard-shortcuts';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\n\nconst ZoomOutToggle = ( { disabled } ) => {\n\tconst { isZoomOut, showIconLabels, isDistractionFree } = useSelect(\n\t\t( select ) => ( {\n\t\t\tisZoomOut: unlock( select( blockEditorStore ) ).isZoomOut(),\n\t\t\tshowIconLabels: select( preferencesStore ).get(\n\t\t\t\t'core',\n\t\t\t\t'showIconLabels'\n\t\t\t),\n\t\t\tisDistractionFree: select( preferencesStore ).get(\n\t\t\t\t'core',\n\t\t\t\t'distractionFree'\n\t\t\t),\n\t\t} )\n\t);\n\n\tconst { resetZoomLevel, setZoomLevel } = unlock(\n\t\tuseDispatch( blockEditorStore )\n\t);\n\tconst { registerShortcut, unregisterShortcut } = useDispatch(\n\t\tkeyboardShortcutsStore\n\t);\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/editor/zoom',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Enter or exit zoom out.' ),\n\t\t\tkeyCombination: {\n\t\t\t\t// `primaryShift+0` (`ctrl+shift+0`) is the shortcut for switching\n\t\t\t\t// to input mode in Windows, so apply a different key combination.\n\t\t\t\tmodifier: isAppleOS() ? 'primaryShift' : 'secondary',\n\t\t\t\tcharacter: '0',\n\t\t\t},\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterShortcut( 'core/editor/zoom' );\n\t\t};\n\t}, [ registerShortcut, unregisterShortcut ] );\n\n\tuseShortcut(\n\t\t'core/editor/zoom',\n\t\t() => {\n\t\t\tif ( isZoomOut ) {\n\t\t\t\tresetZoomLevel();\n\t\t\t} else {\n\t\t\t\tsetZoomLevel( 'auto-scaled' );\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tisDisabled: isDistractionFree,\n\t\t}\n\t);\n\n\tconst handleZoomOut = () => {\n\t\tif ( isZoomOut ) {\n\t\t\tresetZoomLevel();\n\t\t} else {\n\t\t\tsetZoomLevel( 'auto-scaled' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<Button\n\t\t\taccessibleWhenDisabled\n\t\t\tdisabled={ disabled }\n\t\t\tonClick={ handleZoomOut }\n\t\t\ticon={ zoomOutIcon }\n\t\t\tlabel={ __( 'Zoom Out' ) }\n\t\t\tisPressed={ isZoomOut }\n\t\t\tsize=\"compact\"\n\t\t\tshowTooltip={ ! showIconLabels }\n\t\t\tclassName=\"editor-zoom-out-toggle\"\n\t\t/>\n\t);\n};\n\nexport default ZoomOutToggle;\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,kBAAmB;AACnB,qBAA0B;AAC1B,kBAAuC;AACvC,0BAA0C;AAC1C,mBAAsC;AACtC,yBAA0C;AAC1C,gCAGO;AACP,sBAA0B;AAK1B,yBAAuB;AAgErB;AA9DF,IAAM,gBAAgB,CAAE,EAAE,SAAS,MAAO;AACzC,QAAM,EAAE,WAAW,gBAAgB,kBAAkB,QAAI;AAAA,IACxD,CAAE,YAAc;AAAA,MACf,eAAW,2BAAQ,OAAQ,oBAAAA,KAAiB,CAAE,EAAE,UAAU;AAAA,MAC1D,gBAAgB,OAAQ,mBAAAC,KAAiB,EAAE;AAAA,QAC1C;AAAA,QACA;AAAA,MACD;AAA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