Home / File/ ReactDOMSelection.js — react Source File

ReactDOMSelection.js — react Source File

Architecture documentation for ReactDOMSelection.js, a javascript file in the react codebase. 3 imports, 1 dependents.

File javascript BabelCompiler Validation 3 imports 1 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  5672f9bd_6a0a_e8f0_9857_0fb959fc7759["ReactDOMSelection.js"]
  64aba96e_f920_d498_115f_72489bd5ae8f["getNodeForCharacterOffset.js"]
  5672f9bd_6a0a_e8f0_9857_0fb959fc7759 --> 64aba96e_f920_d498_115f_72489bd5ae8f
  b7dd9a23_f94a_0723_886f_7e1028522525["getNodeForCharacterOffset"]
  5672f9bd_6a0a_e8f0_9857_0fb959fc7759 --> b7dd9a23_f94a_0723_886f_7e1028522525
  79306122_0617_c4ea_94ca_a596414f3150["HTMLNodeType.js"]
  5672f9bd_6a0a_e8f0_9857_0fb959fc7759 --> 79306122_0617_c4ea_94ca_a596414f3150
  61ae92ed_59ee_0d03_f7cc_6c7bd8c060f5["ReactInputSelection.js"]
  61ae92ed_59ee_0d03_f7cc_6c7bd8c060f5 --> 5672f9bd_6a0a_e8f0_9857_0fb959fc7759
  style 5672f9bd_6a0a_e8f0_9857_0fb959fc7759 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import getNodeForCharacterOffset from './getNodeForCharacterOffset';
import {TEXT_NODE} from './HTMLNodeType';

/**
 * @param {DOMElement} outerNode
 * @return {?object}
 */
export function getOffsets(outerNode) {
  const {ownerDocument} = outerNode;
  const win = (ownerDocument && ownerDocument.defaultView) || window;
  const selection = win.getSelection && win.getSelection();

  if (!selection || selection.rangeCount === 0) {
    return null;
  }

  const {anchorNode, anchorOffset, focusNode, focusOffset} = selection;

  // In Firefox, anchorNode and focusNode can be "anonymous divs", e.g. the
  // up/down buttons on an <input type="number">. Anonymous divs do not seem to
  // expose properties, triggering a "Permission denied error" if any of its
  // properties are accessed. The only seemingly possible way to avoid erroring
  // is to access a property that typically works for non-anonymous divs and
  // catch any error that may otherwise arise. See
  // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
  try {
    /* eslint-disable ft-flow/no-unused-expressions */
    anchorNode.nodeType;
    focusNode.nodeType;
    /* eslint-enable ft-flow/no-unused-expressions */
  } catch (e) {
    return null;
  }

  return getModernOffsetsFromPoints(
    outerNode,
    anchorNode,
    anchorOffset,
    focusNode,
    focusOffset,
  );
}

/**
 * Returns {start, end} where `start` is the character/codepoint index of
 * (anchorNode, anchorOffset) within the textContent of `outerNode`, and
 * `end` is the index of (focusNode, focusOffset).
 *
 * Returns null if you pass in garbage input but we should probably just crash.
 *
 * Exported only for testing.
 */
export function getModernOffsetsFromPoints(
// ... (143 more lines)

Domain

Subdomains

Frequently Asked Questions

What does ReactDOMSelection.js do?
ReactDOMSelection.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in ReactDOMSelection.js?
ReactDOMSelection.js defines 3 function(s): getModernOffsetsFromPoints, getOffsets, setOffsets.
What does ReactDOMSelection.js depend on?
ReactDOMSelection.js imports 3 module(s): HTMLNodeType.js, getNodeForCharacterOffset, getNodeForCharacterOffset.js.
What files import ReactDOMSelection.js?
ReactDOMSelection.js is imported by 1 file(s): ReactInputSelection.js.
Where is ReactDOMSelection.js in the architecture?
ReactDOMSelection.js is located at packages/react-dom-bindings/src/client/ReactDOMSelection.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/client).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free