()
| 42 | const initialContent = ContentState.createFromText(initText); |
| 43 | |
| 44 | const Playground = () => { |
| 45 | const { formatMessage } = useIntl(); |
| 46 | const regexInput = useRef<HTMLInputElement>(null); |
| 47 | const editor = useRef(null); |
| 48 | const [hasChange, setHasChange] = useState(false); |
| 49 | |
| 50 | const [state, setState] = useState({ |
| 51 | regex: '', |
| 52 | flags: '', |
| 53 | editorState: EditorState.createEmpty(), |
| 54 | }); |
| 55 | |
| 56 | const [initial, setInitial] = useState({ |
| 57 | regex: state.regex, |
| 58 | flags: state.flags, |
| 59 | text: state.editorState?.getCurrentContent()?.getPlainText() || '', |
| 60 | }); |
| 61 | |
| 62 | const onChangeFlags = flags => { |
| 63 | let newFlags = ''; |
| 64 | if (flags.includes('g')) { |
| 65 | newFlags += 'g'; |
| 66 | } |
| 67 | if (flags.includes('m')) { |
| 68 | newFlags += 'm'; |
| 69 | } |
| 70 | if (flags.includes('i')) { |
| 71 | newFlags += 'i'; |
| 72 | } |
| 73 | setState({ |
| 74 | regex: state.regex, |
| 75 | flags: newFlags, |
| 76 | editorState: checkRegex(state.regex, newFlags, state.editorState), |
| 77 | }); |
| 78 | setHasChange(initial.flags !== newFlags); |
| 79 | }; |
| 80 | |
| 81 | const onChangeRegex = (event: FormEvent<HTMLInputElement>) => { |
| 82 | const regex = event?.currentTarget?.value || ''; |
| 83 | setState({ ...state, regex, editorState: checkRegex(regex, state.flags, state.editorState) }); |
| 84 | setHasChange(initial.regex !== regex); |
| 85 | }; |
| 86 | |
| 87 | const onChangeContent = (editorState: EditorState) => { |
| 88 | setState({ ...state, editorState }); |
| 89 | const nextText = editorState.getCurrentContent().getPlainText(); |
| 90 | if (initial.text !== nextText) { |
| 91 | setHasChange(true); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | const checkRegex = (regex, flags, editorState) => { |
| 96 | let rowIndex = 0; |
| 97 | let matchCount = 0; |
| 98 | |
| 99 | if (!regex) { |
| 100 | const content = editorState.getCurrentContent(); |
| 101 | return EditorState.createWithContent(content); |
nothing calls this directly
no test coverage detected