Skip to content

Commit a5ff141

Browse files
committed
Use types and code from regexplanet-common
1 parent 5341b68 commit a5ff141

File tree

11 files changed

+22
-66
lines changed

11 files changed

+22
-66
lines changed

src/app/advanced/[engine]/index.html/OptionsInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PiArrowSquareOut } from "react-icons/pi";
44

55
type OptionInputProps = {
66
engine: RegexEngine;
7-
optionsOrNull: string[];
7+
options: string[];
88
};
99

1010
function getBackendValue(option: RegexOption): string {
@@ -15,7 +15,7 @@ function getBackendValue(option: RegexOption): string {
1515
return option.code;
1616
}
1717

18-
export default function OptionsInput({ engine, optionsOrNull }: OptionInputProps) {
18+
export default function OptionsInput({ engine, options: optionsOrNull }: OptionInputProps) {
1919

2020
const options = optionsOrNull || [];
2121

src/app/advanced/[engine]/index.html/TestFormState.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { TestInput } from "@/types/TestInput";
2-
import { TestOutput } from "@/types/TestOutput";
1+
import { type TestInput, type TestOutput } from "@regexplanet/common";
32

43
export type TestFormState = {
54
message?: string;

src/app/advanced/[engine]/index.html/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { notFound } from 'next/navigation';
55
import TestForm from './TestForm';
66
//import { testRegexAction } from './testRegexAction';
77
//import OptionsInput from './OptionsInput';
8-
import { TestInput } from '@/types/TestInput';
8+
import { type TestInput } from '@regexplanet/common';
99
import { HelpButton } from '@/components/HelpButton';
1010
import { cleanupSearchParam } from '@/functions/cleanupSearchParam';
1111
import { cleanupSearchParamArray } from '@/functions/cleanupSearchParamArray';
@@ -49,7 +49,7 @@ export default function Page({
4949
engine: engine.handle,
5050
regex: cleanupSearchParam(searchParams["regex"]),
5151
replacement: cleanupSearchParam(searchParams["replacement"]),
52-
option: cleanupSearchParamArray(searchParams["option"]),
52+
options: cleanupSearchParamArray(searchParams["option"]),
5353
inputs: cleanupSearchParamArray(searchParams["input"]),
5454
}
5555

src/app/advanced/[engine]/index.html/testRegexAction.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getEngineOrThrow } from "@/engines"
2-
import { TestInput } from "@/types/TestInput";
3-
import { TestOutput } from "@/types/TestOutput";
2+
import { type TestInput, type TestOutput } from "@regexplanet/common";
3+
44

55
export async function testRegexAction(engineHandle: string, formData: FormData) {
66
'use server'
@@ -14,7 +14,7 @@ export async function testRegexAction(engineHandle: string, formData: FormData)
1414
engine: engineHandle,
1515
regex: formData.get('regex') as string,
1616
replacement: formData.get('replacement') as string,
17-
option: formData.getAll('option') as string[],
17+
options: formData.getAll('option') as string[],
1818
inputs: formData.getAll('input') as string[],
1919
}
2020

src/app/advanced/[engine]/results.html/postpage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"use server"
22
import { TestResults } from "@/components/TestResults";
3-
import { TestOutput } from "@/types/TestOutput";
3+
import { type TestInput, type TestOutput } from "@regexplanet/common";
44
import RootLayout from "@/app/layout";
55
import { Navbar } from "@/components/Navbar";
66
import { Footer } from "@/components/Footer";
7-
import { TestInput } from "@/types/TestInput";
87

98

109
// doesn't have layout

src/app/advanced/[engine]/results.html/route.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { TestInput } from "@/types/TestInput";
2-
import { TestOutput } from "@/types/TestOutput";
31
import { NextRequest } from "next/server";
42
//import { renderToStaticMarkup, renderToString } from "react-dom/server";
3+
import { notFound, redirect } from "next/navigation";
4+
55
import { postpage } from "./postpage";
6+
import { type TestInput, type TestOutput } from "@regexplanet/common";
67
import { getEngine } from "@/engines";
7-
import { notFound, redirect } from "next/navigation";
88

99
async function renderPage(
1010
engine: string,
@@ -50,12 +50,12 @@ export async function POST(
5050
engine: engine.handle,
5151
regex: (rawData.get("regex") || "") as string,
5252
replacement: (rawData.get("replacement") || "") as string,
53-
option: (rawData.getAll("options") || "") as string[],
53+
options: (rawData.getAll("option") || "") as string[],
5454
inputs: (rawData.getAll("input") || []) as string[],
5555
};
5656

57-
const response = await fetch(engine.test_url);//(testInput);
58-
const testOutput = await response.json() as TestOutput;
57+
const response = await fetch(engine.test_url); //(testInput);
58+
const testOutput = (await response.json()) as TestOutput;
5959

6060
const html = await renderPage(engine.handle, "post", testInput, testOutput);
6161

src/app/share/index.html/PreviewRegex.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestInput } from '@/types/TestInput';
1+
import { type TestInput } from "@regexplanet/common";
22
import { SubmitButton } from '@/components/SubmitButton';
33
import { getWorkingEngine, getWorkingEngineOrThrow } from '@/engines';
44

src/app/share/index.html/ShareFormState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestInput } from "@/types/TestInput";
1+
import { type TestInput } from "@regexplanet/common";
22

33
export type ShareFormState = {
44
shareCode?: string;

src/components/TestResults.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestOutput } from "@/types/TestOutput";
1+
import { type TestOutput } from "@regexplanet/common";
22

33
type props = {
44
testOutput: TestOutput;

src/engines/RegexEngine.ts

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { TestInput } from "@/types/TestInput";
2-
import { TestOutput } from "@/types/TestOutput";
3-
41
type PortableCodes = "ignorecase" | "multiline" | "comments" | "dotall";
52

63
export type RegexOption = {
74
code: string;
8-
legacyCode?: string; // for the original RegexPlanet backends
9-
portableCode?: PortableCodes; // for translating this code when switching to other engines
10-
numericCode?: number; // the value for engines that use a numeric bitmask for options
5+
legacyCode?: string; // for the original RegexPlanet backends
6+
portableCode?: PortableCodes; // for translating this code when switching to other engines
7+
numericCode?: number; // the value for engines that use a numeric bitmask for options
118
description: string;
129
};
1310

@@ -19,7 +16,7 @@ export type RegexExtraInput = {
1916
defaultValue: string; // the default value to use if the user doesn't provide one
2017
};
2118

22-
type RegexEngine = {
19+
export type RegexEngine = {
2320
description: string; // library or module name (do not include `short_name`)
2421
enabled: boolean; // always true for now
2522
extra_inputs?: RegexExtraInput[]; // A list of extra inputs to gather from the user
@@ -39,29 +36,3 @@ type RegexEngine = {
3936
status_url?: string; // URL of the status endpoint
4037
test_url?: string; // URL of the test endpoint
4138
};
42-
43-
type TestFn = (testInput: TestInput) => Promise<TestOutput>;
44-
45-
function generateRemoteTestFn(test_url: string): TestFn {
46-
47-
return async (testInput: TestInput): Promise<TestOutput> => {
48-
// this is a bogus 'as', but next build insists on it
49-
const postData =
50-
`regex=${encodeURIComponent(testInput.regex)}` +
51-
`&replacement=${encodeURIComponent(testInput.replacement)}` +
52-
`&${testInput.option.map((option) => `option=${option}`).join("&")}` +
53-
`&${testInput.inputs.map((input) => `input=${input}`).join("&")}`;
54-
const response = await fetch(test_url, {
55-
method: "POST",
56-
body: postData,
57-
headers: {
58-
"Content-Type": "application/x-www-form-urlencoded",
59-
},
60-
});
61-
const data = await response.json();
62-
63-
return data as TestOutput;
64-
}
65-
}
66-
67-
export { generateRemoteTestFn, type RegexEngine, type TestFn };

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy