-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sharing (WIP) and listing unsupported engines
- Loading branch information
1 parent
1d26dfa
commit 49cfefe
Showing
19 changed files
with
320 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TestInput } from '@/types/TestInput'; | ||
import { SubmitButton } from '@/components/SubmitButton'; | ||
import { getWorkingEngine, getWorkingEngineOrThrow } from '@/engines'; | ||
|
||
type PreviewRegexProps = { | ||
theShare: TestInput; | ||
} | ||
|
||
export function PreviewRegex( {theShare}: PreviewRegexProps) { | ||
const engineCode = theShare.engine; | ||
let theEngine = getWorkingEngine(engineCode); | ||
if (!theEngine) { | ||
theEngine = getWorkingEngineOrThrow("java"); | ||
} | ||
return ( | ||
<> | ||
<form action={`/advanced/${theEngine.handle}/index.html`} className="" method="post"> | ||
<div className="mb-3"> | ||
<label htmlFor="regex" className="form-label">Regular Expression</label> | ||
<input type="text" className="form-control" id="regex" name="regex" defaultValue={theShare.regex} /> | ||
</div> | ||
<div className="mb-3"> | ||
<label htmlFor="replacement" className="form-label">Replacement</label> | ||
<input type="text" className="form-control" id="replacement" name="replacement" defaultValue={theShare.replacement} /> | ||
</div> | ||
<SubmitButton>{`Test with ${theEngine.short_name}`}</SubmitButton> | ||
</form> | ||
<details className="mt-3"><summary>Raw data</summary><pre>{JSON.stringify(theShare, null, 2)}</pre></details> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Link from "next/link"; | ||
|
||
type ShareFormProps = { | ||
shareCode?: string; | ||
} | ||
|
||
|
||
export function ShareForm(props: ShareFormProps) { | ||
|
||
return ( | ||
<div className="d-flex justify-content-center"> | ||
<form action="/share/index.html" className="col-8 col-lg-4 border p-3" method="get"> | ||
<div className="mb-3"> | ||
<label htmlFor="legacy" className="form-label">Share Code</label> | ||
<input type="text" className="form-control" id="share" name="share" defaultValue={props.shareCode} /> | ||
</div> | ||
<button type="submit" className="btn btn-primary">Submit</button> | ||
<Link className="btn btn-outline-primary ms-2" href="/">Cancel</Link> | ||
</form> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { TestInput } from "@/types/TestInput"; | ||
|
||
export type ShareFormState = { | ||
shareCode?: string; | ||
message?: string; | ||
messageType?: string; | ||
regex?: TestInput; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Metadata } from 'next'; | ||
|
||
import { cleanupSearchParam } from '@/functions/cleanupSearchParam'; | ||
import { ShareFormState } from './ShareFormState'; | ||
import { ShareForm } from './ShareForm'; | ||
import { PreviewRegex } from './PreviewRegex'; | ||
|
||
export const metadata: Metadata = { | ||
title: "Sharing - RegexPlanet", | ||
}; | ||
|
||
async function lookupShareCode(shareCode: string): Promise<ShareFormState> { | ||
|
||
if (!shareCode) { | ||
return { | ||
message: "Please enter a share code", | ||
messageType: "info", | ||
}; | ||
} | ||
//shareCode = "yyyyfud6z4r"; | ||
const response = await fetch(`https://www.regexplanet.com/share/index.json?share=${shareCode}`); | ||
const data = await response.json(); | ||
console.log(`server response=${JSON.stringify(data)}`); | ||
if (data.success) { | ||
return { | ||
message: `Share code ${shareCode} found!`, | ||
messageType: 'success', | ||
shareCode, | ||
regex: data.recipe, | ||
}; | ||
} | ||
return { | ||
message: `Share code ${shareCode} not found`, | ||
messageType: 'danger', | ||
shareCode, | ||
}; | ||
} | ||
|
||
export default async function Page({ searchParams }: { searchParams: { [key: string]: string | string[] | undefined } }) | ||
{ | ||
const shareCode = cleanupSearchParam(searchParams["share"]); | ||
const shareFormState = await lookupShareCode(shareCode); | ||
|
||
return ( | ||
<> | ||
<h1>Sharing</h1> | ||
{ shareFormState.message ? <div className={`alert alert-${shareFormState.messageType || "info"}`}>{shareFormState.message}</div> : null } | ||
{ shareFormState.regex | ||
? <PreviewRegex theShare={shareFormState.regex} /> | ||
: <ShareForm shareCode={shareCode} /> | ||
} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use client'; | ||
|
||
import { useFormStatus } from 'react-dom'; | ||
|
||
export function SubmitButton({ children }: { children: React.ReactNode }) { | ||
const { pending } = useFormStatus(); | ||
|
||
return ( | ||
<button className="btn btn-primary" type="submit" aria-disabled={pending}> | ||
{children} | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { RegexEngine } from "./RegexEngine"; | ||
|
||
export const dotnet: RegexEngine = { | ||
description: "System.Text.RegularExpressions.Regex", | ||
enabled: true, | ||
help_label: "MSDN", | ||
help_url: | ||
"https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions?view=net-8.0", | ||
handle: "dotnet", | ||
level: "alpha", | ||
links: { | ||
"Learn .NET regular expressions": | ||
"https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions", | ||
"Quick Reference": | ||
"https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions#reference", | ||
"Best Practices": | ||
"https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-regex", | ||
" Behavior details": | ||
"https://learn.microsoft.com/en-us/dotnet/standard/base-types/details-of-regular-expression-behavior", | ||
}, | ||
logo_icon: "https://www.vectorlogo.zone/logos/dotnet/dotnet-icon.svg", | ||
logo_ar21: "https://www.vectorlogo.zone/logos/dotnet/dotnet-ar21.svg", | ||
options: [], | ||
short_name: ".NET", | ||
}; |
Oops, something went wrong.