getNodeForCharacterOffset.js — react Source File
Architecture documentation for getNodeForCharacterOffset.js, a javascript file in the react codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 64aba96e_f920_d498_115f_72489bd5ae8f["getNodeForCharacterOffset.js"] 79306122_0617_c4ea_94ca_a596414f3150["HTMLNodeType.js"] 64aba96e_f920_d498_115f_72489bd5ae8f --> 79306122_0617_c4ea_94ca_a596414f3150 5672f9bd_6a0a_e8f0_9857_0fb959fc7759["ReactDOMSelection.js"] 5672f9bd_6a0a_e8f0_9857_0fb959fc7759 --> 64aba96e_f920_d498_115f_72489bd5ae8f style 64aba96e_f920_d498_115f_72489bd5ae8f 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.
*
* @flow
*/
import {TEXT_NODE} from './HTMLNodeType';
/**
* Given any node return the first leaf node without children.
*
* @param {DOMElement|DOMTextNode} node
* @return {DOMElement|DOMTextNode}
*/
function getLeafNode(node: ?(Node | Element)) {
while (node && node.firstChild) {
node = node.firstChild;
}
return node;
}
/**
* Get the next sibling within a container. This will walk up the
* DOM if a node's siblings have been exhausted.
*
* @param {DOMElement|DOMTextNode} node
* @return {?DOMElement|DOMTextNode}
*/
function getSiblingNode(node: ?(Node | Element)) {
while (node) {
if (node.nextSibling) {
return node.nextSibling;
}
node = node.parentNode;
}
}
/**
* Get object describing the nodes which contain characters at offset.
*
* @param {DOMElement|DOMTextNode} root
* @param {number} offset
* @return {?object}
*/
function getNodeForCharacterOffset(root: Element, offset: number): ?Object {
let node = getLeafNode(root);
let nodeStart = 0;
let nodeEnd = 0;
while (node) {
if (node.nodeType === TEXT_NODE) {
nodeEnd = nodeStart + node.textContent.length;
if (nodeStart <= offset && nodeEnd >= offset) {
return {
node: node,
offset: offset - nodeStart,
};
}
nodeStart = nodeEnd;
}
node = getLeafNode(getSiblingNode(node));
}
}
export default getNodeForCharacterOffset;
Domain
Subdomains
Dependencies
Source
Frequently Asked Questions
What does getNodeForCharacterOffset.js do?
getNodeForCharacterOffset.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 getNodeForCharacterOffset.js?
getNodeForCharacterOffset.js defines 3 function(s): getLeafNode, getNodeForCharacterOffset, getSiblingNode.
What does getNodeForCharacterOffset.js depend on?
getNodeForCharacterOffset.js imports 1 module(s): HTMLNodeType.js.
What files import getNodeForCharacterOffset.js?
getNodeForCharacterOffset.js is imported by 1 file(s): ReactDOMSelection.js.
Where is getNodeForCharacterOffset.js in the architecture?
getNodeForCharacterOffset.js is located at packages/react-dom-bindings/src/client/getNodeForCharacterOffset.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