/**
 * Gets the editor region for a given editor canvas element or
 * returns the passed element if no region is found
 *
 * @param { Object } editor The editor canvas element.
 * @return { Object } The editor region or given editor element
 */
export default function getEditorRegion(editor) {
  var _Array$from$find, _editorCanvas$closest;
  if (!editor) {
    return null;
  }

  // If there are multiple editors, we need to find the iframe that contains our contentRef to make sure
  // we're focusing the region that contains this editor.
  const editorCanvas = (_Array$from$find = Array.from(document.querySelectorAll('iframe[name="editor-canvas"]').values()).find(iframe => {
    // Find the iframe that contains our contentRef
    const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
    return iframeDocument === editor.ownerDocument;
  })) !== null && _Array$from$find !== void 0 ? _Array$from$find : editor;

  // The region is provivided by the editor, not the block-editor.
  // We should send focus to the region if one is available to reuse the
  // same interface for navigating landmarks. If no region is available,
  // use the canvas instead.
  return (_editorCanvas$closest = editorCanvas?.closest('[role="region"]')) !== null && _editorCanvas$closest !== void 0 ? _editorCanvas$closest : editorCanvas;
}
//# sourceMappingURL=get-editor-region.js.map