EditableValue.js — react Source File
Architecture documentation for EditableValue.js, a javascript file in the react codebase. 3 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR dc084a98_cfc9_b696_ce0b_8abf1ee07f6f["EditableValue.js"] 242eaa25_405a_21e5_a3b6_836f3973b621["EditableValue.css"] dc084a98_cfc9_b696_ce0b_8abf1ee07f6f --> 242eaa25_405a_21e5_a3b6_836f3973b621 315baf50_1028_51ca_a9c1_679c6a17ed98["hooks.js"] dc084a98_cfc9_b696_ce0b_8abf1ee07f6f --> 315baf50_1028_51ca_a9c1_679c6a17ed98 ac587885_e294_a1e9_b13f_5e7b920fdb42["react"] dc084a98_cfc9_b696_ce0b_8abf1ee07f6f --> ac587885_e294_a1e9_b13f_5e7b920fdb42 276bc34e_3008_101e_3cd7_cc895fcd3848["KeyValue.js"] 276bc34e_3008_101e_3cd7_cc895fcd3848 --> dc084a98_cfc9_b696_ce0b_8abf1ee07f6f 0e638bf4_827b_30d0_21d6_77d4d615d353["NewKeyValue.js"] 0e638bf4_827b_30d0_21d6_77d4d615d353 --> dc084a98_cfc9_b696_ce0b_8abf1ee07f6f style dc084a98_cfc9_b696_ce0b_8abf1ee07f6f 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 * as React from 'react';
import {Fragment} from 'react';
import styles from './EditableValue.css';
import {useEditableValue} from '../hooks';
type OverrideValueFn = (path: Array<string | number>, value: any) => void;
type EditableValueProps = {
className?: string,
overrideValue: OverrideValueFn,
path: Array<string | number>,
value: any,
};
export default function EditableValue({
className = '',
overrideValue,
path,
value,
}: EditableValueProps): React.Node {
const [state, dispatch] = useEditableValue(value);
const {editableValue, hasPendingChanges, isValid, parsedValue} = state;
const reset = () =>
dispatch({
type: 'RESET',
externalValue: value,
});
// $FlowFixMe[missing-local-annot]
const handleChange = ({target}) =>
dispatch({
type: 'UPDATE',
editableValue: target.value,
externalValue: value,
});
// $FlowFixMe[missing-local-annot]
const handleCheckBoxToggle = ({target}) => {
dispatch({
type: 'UPDATE',
editableValue: target.checked,
externalValue: value,
});
// Unlike <input type="text"> which has both an onChange and an onBlur,
// <input type="checkbox"> updates state *and* applies changes in a single event.
// So we read from target.checked rather than parsedValue (which has not yet updated).
// We also don't check isValid (because that hasn't changed yet either);
// we don't need to check it anyway, since target.checked is always a boolean.
overrideValue(path, target.checked);
};
// $FlowFixMe[missing-local-annot]
const handleKeyDown = event => {
// Prevent keydown events from e.g. change selected element in the tree
event.stopPropagation();
switch (event.key) {
case 'Enter':
applyChanges();
break;
case 'Escape':
reset();
break;
default:
break;
}
};
const applyChanges = () => {
if (isValid && hasPendingChanges) {
overrideValue(path, parsedValue);
}
};
let placeholder = '';
if (editableValue === undefined) {
placeholder = '(undefined)';
} else {
placeholder = 'Enter valid JSON';
}
const isBool = parsedValue === true || parsedValue === false;
return (
<Fragment>
<input
autoComplete="new-password"
className={`${isValid ? styles.Input : styles.Invalid} ${className}`}
data-testname="EditableValue"
onBlur={applyChanges}
onChange={handleChange}
onKeyDown={handleKeyDown}
placeholder={placeholder}
type="text"
value={editableValue}
/>
{isBool && (
<input
className={styles.Checkbox}
checked={parsedValue}
type="checkbox"
onChange={handleCheckBoxToggle}
/>
)}
</Fragment>
);
}
Domain
Subdomains
Functions
Dependencies
Imported By
Source
Frequently Asked Questions
What does EditableValue.js do?
EditableValue.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 EditableValue.js?
EditableValue.js defines 2 function(s): EditableValue, OverrideValueFn.
What does EditableValue.js depend on?
EditableValue.js imports 3 module(s): EditableValue.css, hooks.js, react.
What files import EditableValue.js?
EditableValue.js is imported by 2 file(s): KeyValue.js, NewKeyValue.js.
Where is EditableValue.js in the architecture?
EditableValue.js is located at packages/react-devtools-shared/src/devtools/views/Components/EditableValue.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools/views/Components).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free