11import { type TestInput } from "@regexplanet/common" ;
22import { SubmitButton } from '@/components/SubmitButton' ;
3- import { getWorkingEngine , getWorkingEngineOrThrow } from '@/engines' ;
3+ import { getWorkingEngines } from '@/engines' ;
44
55type PreviewRegexProps = {
66 theShare : TestInput ;
77}
88
99export 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 } /> ) } ) ;
1515 return (
1616 < >
17- < form action = { `/advanced/${ theEngine . handle } /index.html` } className = "" method = "post" >
1817 < div className = "mb-3" >
1918 < label htmlFor = "regex" className = "form-label" > Regular Expression</ label >
2019 < input type = "text" className = "form-control" id = "regex" name = "regex" defaultValue = { theShare . regex } />
@@ -23,8 +22,18 @@ export function PreviewRegex( {theShare}: PreviewRegexProps) {
2322 < label htmlFor = "replacement" className = "form-label" > Replacement</ label >
2423 < input type = "text" className = "form-control" id = "replacement" name = "replacement" defaultValue = { theShare . replacement } />
2524 </ 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 >
2837 < details className = "mt-3" > < summary > Raw data</ summary > < pre > { JSON . stringify ( theShare , null , 2 ) } </ pre > </ details >
2938 </ >
3039 )
0 commit comments