UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 1.96 kB
{ "version": 3, "sources": ["../../../src/components/provider/navigation-block-editing-mode.js"], "sourcesContent": ["import { useEffect } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * For the Navigation block editor, we need to force the block editor to contentOnly for that block.\n *\n * Set block editing mode to contentOnly when entering Navigation focus mode.\n * this ensures that non-content controls on the block will be hidden and thus\n * the user can focus on editing the Navigation Menu content only.\n */\n\nexport default function NavigationBlockEditingMode() {\n\tconst registry = useRegistry();\n\t// In the navigation block editor,\n\t// the navigation block is the only root block.\n\tconst blockClientId = useSelect(\n\t\t( select ) => select( blockEditorStore ).getBlockOrder()?.[ 0 ],\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\tif ( ! blockClientId ) {\n\t\t\treturn;\n\t\t}\n\t\tconst {\n\t\t\tsetBlockEditingMode,\n\t\t\tunsetBlockEditingMode,\n\t\t\t__unstableMarkNextChangeAsNotPersistent,\n\t\t} = registry.dispatch( blockEditorStore );\n\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tsetBlockEditingMode( blockClientId, 'contentOnly' );\n\n\t\treturn () => {\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\tunsetBlockEditingMode( blockClientId );\n\t\t};\n\t}, [ registry, blockClientId ] );\n}\n"], "mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,wBAAwB;AAU3B,SAAR,6BAA8C;AACpD,QAAM,WAAW,YAAY;AAG7B,QAAM,gBAAgB;AAAA,IACrB,CAAE,WAAY,OAAQ,gBAAiB,EAAE,cAAc,IAAK,CAAE;AAAA,IAC9D,CAAC;AAAA,EACF;AAEA,YAAW,MAAM;AAChB,QAAK,CAAE,eAAgB;AACtB;AAAA,IACD;AACA,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACD,IAAI,SAAS,SAAU,gBAAiB;AAExC,4CAAwC;AACxC,wBAAqB,eAAe,aAAc;AAElD,WAAO,MAAM;AACZ,8CAAwC;AACxC,4BAAuB,aAAc;AAAA,IACtC;AAAA,EACD,GAAG,CAAE,UAAU,aAAc,CAAE;AAChC;", "names": [] }