ReactDOMSelection-test.internal.js — react Source File
Architecture documentation for ReactDOMSelection-test.internal.js, a javascript file in the react codebase.
Entity Profile
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.
*
* @emails react-core
*/
'use strict';
let React;
let ReactDOMClient;
let ReactDOMSelection;
let act;
let getModernOffsetsFromPoints;
describe('ReactDOMSelection', () => {
beforeEach(() => {
React = require('react');
ReactDOMClient = require('react-dom/client');
ReactDOMSelection = require('react-dom-bindings/src/client/ReactDOMSelection');
act = require('internal-test-utils').act;
({getModernOffsetsFromPoints} = ReactDOMSelection);
});
// Simple implementation to compare correctness. React's old implementation of
// this logic used DOM Range objects and is available for manual testing at
// https://gist.github.com/sophiebits/2e6d571f4f10f33b62ea138a6e9c265c.
function simpleModernOffsetsFromPoints(
outerNode,
anchorNode,
anchorOffset,
focusNode,
focusOffset,
) {
let start;
let end;
let length = 0;
function traverse(node) {
if (node.nodeType === Node.TEXT_NODE) {
if (node === anchorNode) {
start = length + anchorOffset;
}
if (node === focusNode) {
end = length + focusOffset;
}
length += node.nodeValue.length;
return;
}
for (let i = 0; true; i++) {
if (node === anchorNode && i === anchorOffset) {
start = length;
}
if (node === focusNode && i === focusOffset) {
end = length;
// ... (148 more lines)
Source
Frequently Asked Questions
What does ReactDOMSelection-test.internal.js do?
ReactDOMSelection-test.internal.js is a source file in the react codebase, written in javascript.
Where is ReactDOMSelection-test.internal.js in the architecture?
ReactDOMSelection-test.internal.js is located at packages/react-dom/src/__tests__/ReactDOMSelection-test.internal.js (directory: packages/react-dom/src/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free