Home / File/ FallbackCompositionState.js — react Source File

FallbackCompositionState.js — react Source File

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

File javascript BabelCompiler Validation 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  b23498c7_3fdf_15b2_7f8a_9e06622117b9["FallbackCompositionState.js"]
  a235366c_1abe_162c_b9bf_7fbbfb597584["BeforeInputEventPlugin.js"]
  a235366c_1abe_162c_b9bf_7fbbfb597584 --> b23498c7_3fdf_15b2_7f8a_9e06622117b9
  style b23498c7_3fdf_15b2_7f8a_9e06622117b9 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.
 */

/**
 * These variables store information about text content of a target node,
 * allowing comparison of content before and after a given event.
 *
 * Identify the node where selection currently begins, then observe
 * both its text content and its current position in the DOM. Since the
 * browser may natively replace the target node during composition, we can
 * use its position to find its replacement.
 *
 *
 */

let root = null;
let startText = null;
let fallbackText = null;

export function initialize(nativeEventTarget) {
  root = nativeEventTarget;
  startText = getText();
  return true;
}

export function reset() {
  root = null;
  startText = null;
  fallbackText = null;
}

export function getData() {
  if (fallbackText) {
    return fallbackText;
  }

  let start;
  const startValue = startText;
  const startLength = startValue.length;
  let end;
  const endValue = getText();
  const endLength = endValue.length;

  for (start = 0; start < startLength; start++) {
    if (startValue[start] !== endValue[start]) {
      break;
    }
  }

  const minEnd = startLength - start;
  for (end = 1; end <= minEnd; end++) {
    if (startValue[startLength - end] !== endValue[endLength - end]) {
      break;
    }
  }

  const sliceTail = end > 1 ? 1 - end : undefined;
  fallbackText = endValue.slice(start, sliceTail);
  return fallbackText;
}

export function getText() {
  if ('value' in root) {
    return root.value;
  }
  return root.textContent;
}

Domain

Subdomains

Frequently Asked Questions

What does FallbackCompositionState.js do?
FallbackCompositionState.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 FallbackCompositionState.js?
FallbackCompositionState.js defines 4 function(s): getData, getText, initialize, reset.
What files import FallbackCompositionState.js?
FallbackCompositionState.js is imported by 1 file(s): BeforeInputEventPlugin.js.
Where is FallbackCompositionState.js in the architecture?
FallbackCompositionState.js is located at packages/react-dom-bindings/src/events/FallbackCompositionState.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom-bindings/src/events).

Analyze Your Own Codebase

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

Try Supermodel Free