Skip to content

Commit 582a771

Browse files
committed
feat: add encoder sections
1 parent e2d2e79 commit 582a771

26 files changed

Lines changed: 112 additions & 15 deletions

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useState } from "react";
22
import { DebuggerDescription, DebuggerHeader } from "./components/Debugger";
33
import { Header } from "./components/Layout";
44
import { JWPDecoder } from "./features/JWPDecoder";
5+
import { JWPEncoder } from "./features/JWPEncoder";
56
import { cn } from "./libs/tailwindUtils";
67
import { DebuggerStore } from "./store/context";
78

@@ -36,6 +37,7 @@ const App = () => {
3637
</button>
3738
</div>
3839
{activeTab === "decoder" && <JWPDecoder />}
40+
{activeTab === "encoder" && <JWPEncoder />}
3941
</div>
4042
</div>
4143
</DebuggerStore>

src/components/JWPVisualizer/BaseTextarea.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type BaseTextareaProps = {
55
minRows?: number;
66
wrap?: boolean;
77
className?: string;
8+
disabled?: boolean;
89
children?: React.ReactNode;
910
onChange?: (value: string) => void;
1011
};
@@ -16,6 +17,7 @@ export const BaseTextarea = ({
1617
value = "",
1718
minRows = 12,
1819
wrap = true,
20+
disabled = false,
1921
className,
2022
onChange,
2123
}: BaseTextareaProps) => {
@@ -34,7 +36,7 @@ export const BaseTextarea = ({
3436
useEffect(() => {
3537
adjustHeight();
3638
}, [adjustHeight]);
37-
39+
// cursor帰る
3840
return (
3941
<textarea
4042
ref={textareaRef}
@@ -43,12 +45,13 @@ export const BaseTextarea = ({
4345
autoCorrect="off"
4446
autoCapitalize="none"
4547
spellCheck="false"
46-
className={`w-full resize-none overflow-y-auto p-4 text-xs focus:outline-none ${
48+
className={`w-full resize-none overflow-y-auto p-4 text-xs focus:outline-none cursor-text ${
4749
!wrap ? "overflow-x-auto whitespace-nowrap" : ""
4850
} ${className}`}
4951
style={{
5052
whiteSpace: wrap ? "pre-wrap" : "pre",
5153
}}
54+
disabled={disabled}
5255
rows={minRows}
5356
onChange={(e) => {
5457
onChange?.(e.target.value);

src/components/JWPVisualizer/IssuedJWPTextarea.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ const COLORS = ["green", "black", "blue"];
44

55
export type IssuedJWPTextareaProps = {
66
value: string;
7-
onChange: (value: string) => void;
7+
onChange?: (value: string) => void;
8+
disabled?: boolean;
89
};
910

1011
export const IssuedJWPTextarea: React.FC<IssuedJWPTextareaProps> = ({
1112
value,
12-
onChange,
13+
onChange = () => {},
14+
disabled,
1315
}) => {
1416
const parts = value.split(".");
1517

@@ -36,6 +38,7 @@ export const IssuedJWPTextarea: React.FC<IssuedJWPTextareaProps> = ({
3638
value={value}
3739
onChange={onChange}
3840
minRows={12}
41+
disabled={disabled}
3942
className="relative bg-transparent p-4 font-mono text-transparent text-xs caret-black "
4043
/>
4144
</div>

src/components/JWPVisualizer/PresentedJWPTextarea.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ const COLORS = ["green", "purple", "black", "blue"];
44

55
export type PresentedJWPTextareaProps = {
66
value: string;
7-
onChange: (value: string) => void;
7+
onChange?: (value: string) => void;
8+
disabled?: boolean;
89
};
910

1011
export const PresentedJWPTextarea: React.FC<PresentedJWPTextareaProps> = ({
1112
value,
12-
onChange,
13+
onChange = () => {},
14+
disabled,
1315
}) => {
1416
const parts = value.split(".");
1517

@@ -36,6 +38,7 @@ export const PresentedJWPTextarea: React.FC<PresentedJWPTextareaProps> = ({
3638
value={value}
3739
onChange={onChange}
3840
minRows={12}
41+
disabled={disabled}
3942
className="relative bg-transparent p-4 font-mono text-transparent text-xs caret-black "
4043
/>
4144
</div>

src/features/JWPDecoder/hooks/useValidateResult.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { validateIssuedForm, validatePresentedForm } from "@/libs/validate";
12
import { useDebuggerStore } from "@/store/context";
2-
import { validateIssuedForm, validatePresentedForm } from "../libs/validate";
33

44
export const useValidateResult = () => {
55
const { issuedFormJWP, presentedFormJWP } = useDebuggerStore();

src/features/JWPDecoder/hooks/useVerifyResult.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { checkJWK } from "@/libs/verify/checkJWK";
2+
import { verifyIssuedJwp, verifyPresentedJwp } from "@/libs/verify/verifyJWP";
13
import { useDebuggerStore } from "@/store/context";
2-
import { checkJWK } from "../libs/verify/checkJWK";
3-
import { verifyIssuedJwp, verifyPresentedJwp } from "../libs/verify/verifyJWP";
44

55
export const useVerifyResult = (jwkString?: string) => {
66
const { issuedFormJWP, presentedFormJWP } = useDebuggerStore();

src/features/JWPDecoder/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
export { JWPDecoder } from "./components/main";
2-
export type {
3-
IssuedFormJWPResult,
4-
PresentedFormJWPResult,
5-
} from "./libs/validate/validateJWP";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { CardWithTextTitle } from "@/components/Card";
2+
import { JSONVisualize } from "@/components/JWPVisualizer";
3+
4+
type HeaderInputProps = {
5+
title: string;
6+
value?: string;
7+
onChange?: (value: string) => void;
8+
isValid?: boolean;
9+
validationError?: string;
10+
};
11+
12+
export const HeaderInput: React.FC<HeaderInputProps> = ({
13+
title,
14+
value,
15+
onChange,
16+
isValid,
17+
validationError,
18+
}) => {
19+
<div className="flex flex-col space-y-4">
20+
<CardWithTextTitle title={title} disabled>
21+
<div className="p-4">{value && <JSONVisualize jsonData={value} />}</div>
22+
</CardWithTextTitle>
23+
</div>;
24+
};

src/features/JWPEncoder/components/Input/PayloadInput.tsx

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./HeaderInput";
2+
export * from "./PayloadInput";

0 commit comments

Comments
 (0)