(regex, flags)
| 93 | }, [data, regex, flags]); |
| 94 | |
| 95 | const applyRegex = (regex, flags) => { |
| 96 | if (skip) return; |
| 97 | if (data.interactive === false) return; |
| 98 | |
| 99 | if (data.safariAccept) { |
| 100 | const isTrueRegex = data.regex[0] == regex; |
| 101 | setError(!isTrueRegex); |
| 102 | setSuccess(isTrueRegex); |
| 103 | |
| 104 | if (!checkBrowserSupport()) return; |
| 105 | } |
| 106 | |
| 107 | const { isSuccess, isMatch, err, regex: grouppedRegex } = checkRegex(data, { regex, flags }); |
| 108 | |
| 109 | if (err) { |
| 110 | setError(true); |
| 111 | setMatch(false); |
| 112 | setSuccess(false); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | setError(false); |
| 117 | setMatch(isMatch); |
| 118 | setSuccess(isSuccess); |
| 119 | |
| 120 | if (!regex) { |
| 121 | setContent(data.content); |
| 122 | } else { |
| 123 | setContent( |
| 124 | tagWrapper({ |
| 125 | value: data.content, |
| 126 | regex: grouppedRegex, |
| 127 | attributes: { |
| 128 | class: 'highlight shadow-sm h-3 mr-[1px] my-[1px] px-1 py-[2px] rounded-md text-black', |
| 129 | }, |
| 130 | }), |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | if ((isChanged && isSuccess) || isMatch) { |
| 135 | setError(false); |
| 136 | } else { |
| 137 | setError(true); |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | const onChange = e => { |
| 142 | setIsChanged(true); |
no test coverage detected