gpt-3.5-turbo-0125· OpenAI WildChat-4.8M (AI2)
convert to preact js component - "class InputElement extends React.Component { focused =…
- User
convert to preact js component - "class InputElement extends React.Component { focused = false mounted = false previousSelection = null selectionDeferId = null saveSelectionLoopDeferId = null
constructor(props) { super(props);
const { mask, maskChar, formatChars, alwaysShowMask, beforeMaskedValueChange } = props; let { defaultValue, value } = props; this.maskOptions = parseMask(mask, maskChar, formatChars); if (defaultValue == null) { defaultValue = ''; } if (value == null) { value = defaultValue; } let newValue = getStringValue(value); if (this.maskOptions.mask && (alwaysShowMask || newValue)) { newValue = formatValue(this.maskOptions, newValue); if (isFunction(beforeMaskedValueChange)) { let oldValue = props.value; if (props.value == null) { oldValue = defaultValue; } oldValue = getStringValue(oldValue); const modifiedValue = beforeMaskedValueChange( { value: newValue, selection: null }, { value: oldValue, selection: null }, null, this.getBeforeMaskedValueChangeConfig() ); newValue = modifiedValue.value; } } this.value = newValue;}
componentDidMount() { this.mounted = true;
// workaround for react-test-renderer // https://github.com/sanniassin/react-input-mask/issues/147 if (!this.getInputDOMNode()) { return; } this.isWindowsPhoneBrowser = isWindowsPhoneBrowser(); if (this.maskOptions.mask && this.getInputValue() !== this.value) { this.setInputValue(this.value); }} }"
- Assistant
import { h, Component } from 'preact';
export default class InputElement extends Component { focused = false; mounted = false; previousSelection = null; selectionDeferId = null; saveSelectionLoopDeferId = null;
constructor(props) { super(props);
const { mask, maskChar, formatChars, alwaysShowMask, beforeMaskedValueChange } = props; let { defaultValue, value } = props; this.maskOptions = parseMask(mask, maskChar, formatChars); if (defaultValue == null) { defaultValue = ''; } if (value == null) { value = defaultValue; } let newValue = getStringValue(value); if (this.maskOptions.mask && (alwaysShowMask || newValue)) { newValue = formatValue(this.maskOptions, newValue); if (isFunction(beforeMaskedValueChange)) { let oldValue = props.value; if (props.value == null) { oldValue = defaultValue; } oldValue = getStringValue(oldValue); const modifiedValue = beforeMaskedValueChange( { value: newValue, selection: null }, { value: oldValue, selection: null }, null, this.getBeforeMaskedValueChangeConfig() ); newValue = modifiedValue.value; } } this.value = newValue;}
componentDidMount() { this.mounted = true;
// workaround for react-test-renderer // https://github.com/sanniassin/react-input-mask/issues/147 if (!this.getInputDOMNode()) { return; } this.isWindowsPhoneBrowser = isWindowsPhoneBrowser(); if (this.maskOptions.mask && this.getInputValue() !== this.value) { this.setInputValue(this.value); }}
render() { return null; } }