UNPKG

@wordpress/block-editor

Version:
8 lines (7 loc) 1.67 kB
{ "version": 3, "sources": ["../../src/utils/get-editor-region.js"], "sourcesContent": ["/**\n * Gets the editor region for a given editor canvas element or\n * returns the passed element if no region is found\n *\n * @param { Object } editor The editor canvas element.\n * @return { Object } The editor region or given editor element\n */\nexport default function getEditorRegion( editor ) {\n\tif ( ! editor ) {\n\t\treturn null;\n\t}\n\n\t// If there are multiple editors, we need to find the iframe that contains our contentRef to make sure\n\t// we're focusing the region that contains this editor.\n\tconst editorCanvas =\n\t\tArray.from(\n\t\t\tdocument.querySelectorAll( 'iframe[name=\"editor-canvas\"]' ).values()\n\t\t).find( ( iframe ) => {\n\t\t\t// Find the iframe that contains our contentRef\n\t\t\tconst iframeDocument =\n\t\t\t\tiframe.contentDocument || iframe.contentWindow.document;\n\n\t\t\treturn iframeDocument === editor.ownerDocument;\n\t\t} ) ?? editor;\n\n\t// The region is provided by the editor, not the block-editor.\n\t// We should send focus to the region if one is available to reuse the\n\t// same interface for navigating landmarks. If no region is available,\n\t// use the canvas instead.\n\treturn editorCanvas?.closest( '[role=\"region\"]' ) ?? editorCanvas;\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOe,SAAR,gBAAkC,QAAS;AACjD,MAAK,CAAE,QAAS;AACf,WAAO;AAAA,EACR;AAIA,QAAM,eACL,MAAM;AAAA,IACL,SAAS,iBAAkB,8BAA+B,EAAE,OAAO;AAAA,EACpE,EAAE,KAAM,CAAE,WAAY;AAErB,UAAM,iBACL,OAAO,mBAAmB,OAAO,cAAc;AAEhD,WAAO,mBAAmB,OAAO;AAAA,EAClC,CAAE,KAAK;AAMR,SAAO,cAAc,QAAS,iBAAkB,KAAK;AACtD;", "names": [] }