1
1
import { type TestInput } from "@regexplanet/common" ;
2
2
import { SubmitButton } from '@/components/SubmitButton' ;
3
- import { getWorkingEngine , getWorkingEngineOrThrow } from '@/engines' ;
3
+ import { getWorkingEngines } from '@/engines' ;
4
4
5
5
type PreviewRegexProps = {
6
6
theShare : TestInput ;
7
7
}
8
8
9
9
export function PreviewRegex ( { theShare} : PreviewRegexProps ) {
10
- const engineCode = theShare . engine ;
11
- let theEngine = getWorkingEngine ( engineCode ) ;
12
- if ( ! theEngine ) {
13
- theEngine = getWorkingEngineOrThrow ( "java" ) ;
14
- }
10
+
11
+ theShare . engine = theShare . engine || 'java' ;
12
+
13
+ const options = theShare . options . map ( ( option , index ) => { return ( < input type = "hidden" name = "option" key = { `option_ ${ index } ` } value = { option } /> ) ; } ) ;
14
+ const inputs = theShare . inputs . map ( ( input , index ) => { return ( < input type = "hidden" key = { `input_ ${ index } ` } name = "input" value = { input } /> ) } ) ;
15
15
return (
16
16
< >
17
- < form action = { `/advanced/${ theEngine . handle } /index.html` } className = "" method = "post" >
18
17
< div className = "mb-3" >
19
18
< label htmlFor = "regex" className = "form-label" > Regular Expression</ label >
20
19
< input type = "text" className = "form-control" id = "regex" name = "regex" defaultValue = { theShare . regex } />
@@ -23,8 +22,18 @@ export function PreviewRegex( {theShare}: PreviewRegexProps) {
23
22
< label htmlFor = "replacement" className = "form-label" > Replacement</ label >
24
23
< input type = "text" className = "form-control" id = "replacement" name = "replacement" defaultValue = { theShare . replacement } />
25
24
</ div >
26
- < SubmitButton > { `Test with ${ theEngine . short_name } ` } </ SubmitButton >
27
- </ form >
25
+ < div className = "mb-3" >
26
+ < label className = "form-label d-block" > Test with:</ label >
27
+ { getWorkingEngines ( ) . map ( ( theEngine , index ) => { return (
28
+ < form action = { `/advanced/${ theEngine . handle } /index.html` } className = "d-inline-block m-1" key = { `form_${ index } ` } method = "get" >
29
+ < input type = "hidden" name = "engine" value = { theEngine . handle } />
30
+ < input type = "hidden" name = "regex" value = { theShare . regex } />
31
+ < input type = "hidden" name = "replacement" value = { theShare . replacement } />
32
+ { options }
33
+ { inputs }
34
+ < button className = { `btn ${ theShare . engine == theEngine . handle ? 'btn-primary' : 'btn-outline-primary' } ` } > { `${ theEngine . short_name } ` } </ button >
35
+ </ form > ) } ) }
36
+ </ div >
28
37
< details className = "mt-3" > < summary > Raw data</ summary > < pre > { JSON . stringify ( theShare , null , 2 ) } </ pre > </ details >
29
38
</ >
30
39
)
0 commit comments