@ttsc/playground 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,93 +1,93 @@
1
- "use client";
2
-
3
- import { useEffect, useMemo, useRef, useState } from "react";
4
-
5
- import type { IPlaygroundExample } from "../structures/IPlaygroundExample";
6
-
7
- interface ExamplePickerProps {
8
- examples: readonly IPlaygroundExample[];
9
- onPick: (id: string) => void;
10
- /** Display labels for groups. Maps `group` key → rendered heading. */
11
- groupLabels?: Record<string, string>;
12
- }
13
-
14
- export function ExamplePicker({
15
- examples,
16
- onPick,
17
- groupLabels,
18
- }: ExamplePickerProps) {
19
- const [open, setOpen] = useState(false);
20
- const ref = useRef<HTMLDivElement>(null);
21
-
22
- useEffect(() => {
23
- if (!open) return;
24
- const close = (e: MouseEvent) => {
25
- if (ref.current && !ref.current.contains(e.target as Node)) {
26
- setOpen(false);
27
- }
28
- };
29
- const onKey = (e: KeyboardEvent) => {
30
- if (e.key === "Escape") setOpen(false);
31
- };
32
- document.addEventListener("mousedown", close);
33
- document.addEventListener("keydown", onKey);
34
- return () => {
35
- document.removeEventListener("mousedown", close);
36
- document.removeEventListener("keydown", onKey);
37
- };
38
- }, [open]);
39
-
40
- const grouped = useMemo(() => {
41
- return examples.reduce<Record<string, IPlaygroundExample[]>>((acc, e) => {
42
- const key = e.group ?? "Examples";
43
- (acc[key] ??= []).push(e);
44
- return acc;
45
- }, {});
46
- }, [examples]);
47
-
48
- if (examples.length === 0) return null;
49
-
50
- return (
51
- <div ref={ref} className="relative">
52
- <button
53
- data-playground-examples-toggle
54
- onClick={() => setOpen((v) => !v)}
55
- className="rounded-md border border-[#b9d5ee] bg-white px-3 py-1.5 font-mono text-xs text-[#235a97] transition-colors hover:border-[#3178c6] hover:bg-[#eaf4ff]"
56
- title="Cmd/Ctrl+K"
57
- >
58
- Examples ▾
59
- </button>
60
- {open && (
61
- <div className="absolute right-0 top-full z-10 mt-2 w-80 overflow-hidden rounded-xl border border-[#b9d5ee] bg-white shadow-[0_14px_42px_rgba(49,120,198,0.18)]">
62
- {Object.entries(grouped).map(([group, items]) => (
63
- <div
64
- key={group}
65
- className="border-b border-[#d8e7f4] last:border-b-0"
66
- >
67
- <div className="bg-[#f7fbff] px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider text-slate-500">
68
- {groupLabels?.[group] ?? group}
69
- </div>
70
- {items.map((item) => (
71
- <button
72
- key={item.id}
73
- onClick={() => {
74
- onPick(item.id);
75
- setOpen(false);
76
- }}
77
- className="w-full px-3 py-2 text-left transition-colors hover:bg-[#eaf4ff]"
78
- >
79
- <div className="font-mono text-[12px] text-[#102a43]">
80
- {item.title}
81
- </div>
82
- <div className="mt-0.5 text-[10px] leading-snug text-slate-500">
83
- {item.description}
84
- </div>
85
- </button>
86
- ))}
87
- </div>
88
- ))}
89
- </div>
90
- )}
91
- </div>
92
- );
93
- }
1
+ "use client";
2
+
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+
5
+ import type { IPlaygroundExample } from "../structures/IPlaygroundExample";
6
+
7
+ interface ExamplePickerProps {
8
+ examples: readonly IPlaygroundExample[];
9
+ onPick: (id: string) => void;
10
+ /** Display labels for groups. Maps `group` key → rendered heading. */
11
+ groupLabels?: Record<string, string>;
12
+ }
13
+
14
+ export function ExamplePicker({
15
+ examples,
16
+ onPick,
17
+ groupLabels,
18
+ }: ExamplePickerProps) {
19
+ const [open, setOpen] = useState(false);
20
+ const ref = useRef<HTMLDivElement>(null);
21
+
22
+ useEffect(() => {
23
+ if (!open) return;
24
+ const close = (e: MouseEvent) => {
25
+ if (ref.current && !ref.current.contains(e.target as Node)) {
26
+ setOpen(false);
27
+ }
28
+ };
29
+ const onKey = (e: KeyboardEvent) => {
30
+ if (e.key === "Escape") setOpen(false);
31
+ };
32
+ document.addEventListener("mousedown", close);
33
+ document.addEventListener("keydown", onKey);
34
+ return () => {
35
+ document.removeEventListener("mousedown", close);
36
+ document.removeEventListener("keydown", onKey);
37
+ };
38
+ }, [open]);
39
+
40
+ const grouped = useMemo(() => {
41
+ return examples.reduce<Record<string, IPlaygroundExample[]>>((acc, e) => {
42
+ const key = e.group ?? "Examples";
43
+ (acc[key] ??= []).push(e);
44
+ return acc;
45
+ }, {});
46
+ }, [examples]);
47
+
48
+ if (examples.length === 0) return null;
49
+
50
+ return (
51
+ <div ref={ref} className="relative">
52
+ <button
53
+ data-playground-examples-toggle
54
+ onClick={() => setOpen((v) => !v)}
55
+ className="rounded-md border border-[#b9d5ee] bg-white px-3 py-1.5 font-mono text-xs text-[#235a97] transition-colors hover:border-[#3178c6] hover:bg-[#eaf4ff]"
56
+ title="Cmd/Ctrl+K"
57
+ >
58
+ Examples ▾
59
+ </button>
60
+ {open && (
61
+ <div className="absolute right-0 top-full z-10 mt-2 w-80 overflow-hidden rounded-xl border border-[#b9d5ee] bg-white shadow-[0_14px_42px_rgba(49,120,198,0.18)]">
62
+ {Object.entries(grouped).map(([group, items]) => (
63
+ <div
64
+ key={group}
65
+ className="border-b border-[#d8e7f4] last:border-b-0"
66
+ >
67
+ <div className="bg-[#f7fbff] px-3 py-1.5 font-mono text-[10px] uppercase tracking-wider text-slate-500">
68
+ {groupLabels?.[group] ?? group}
69
+ </div>
70
+ {items.map((item) => (
71
+ <button
72
+ key={item.id}
73
+ onClick={() => {
74
+ onPick(item.id);
75
+ setOpen(false);
76
+ }}
77
+ className="w-full px-3 py-2 text-left transition-colors hover:bg-[#eaf4ff]"
78
+ >
79
+ <div className="font-mono text-[12px] text-[#102a43]">
80
+ {item.title}
81
+ </div>
82
+ <div className="mt-0.5 text-[10px] leading-snug text-slate-500">
83
+ {item.description}
84
+ </div>
85
+ </button>
86
+ ))}
87
+ </div>
88
+ ))}
89
+ </div>
90
+ )}
91
+ </div>
92
+ );
93
+ }
@@ -1,58 +1,58 @@
1
- "use client";
2
-
3
- import type { ICompilerService } from "../structures/ICompilerService";
4
-
5
- /**
6
- * Renders the lint plugin's findings in a list view. Shown by `PlaygroundShell`
7
- * when the active tab is "lint". Empty state is the green checkmark.
8
- */
9
- export function LintPane({
10
- diagnostics,
11
- emptyHint = "Powered by @ttsc/lint inside playground.wasm.",
12
- }: {
13
- diagnostics: ICompilerService.IDiagnostic[];
14
- emptyHint?: string;
15
- }) {
16
- if (diagnostics.length === 0)
17
- return (
18
- <div className="flex h-full flex-col items-center justify-center gap-2 font-mono text-sm text-slate-500">
19
- <span className="text-emerald-400 text-xl">✓</span>
20
- <span>No lint diagnostics.</span>
21
- <span className="max-w-xs text-center text-[10px] text-slate-400">
22
- {emptyHint}
23
- </span>
24
- </div>
25
- );
26
- return (
27
- <div className="overflow-auto h-full p-4 space-y-2">
28
- {diagnostics.map((d, i) => (
29
- <div
30
- key={i}
31
- className="flex gap-3 rounded-lg border border-[#d2e4f4] bg-[#f7fbff] p-3"
32
- >
33
- <span
34
- className={`mt-0.5 text-[10px] font-mono px-1.5 py-0.5 rounded shrink-0 ${
35
- d.severity === "error"
36
- ? "text-red-300 bg-red-500/10"
37
- : "text-yellow-300 bg-yellow-500/10"
38
- }`}
39
- >
40
- {d.severity}
41
- </span>
42
- <div className="flex-1 min-w-0">
43
- <div className="mb-1 flex items-center gap-2 font-mono text-[11px] text-slate-500">
44
- <span>{d.code}</span>
45
- <span>·</span>
46
- <span>
47
- {d.line}:{d.column}
48
- </span>
49
- </div>
50
- <div className="font-mono text-[13px] text-slate-700">
51
- {d.message}
52
- </div>
53
- </div>
54
- </div>
55
- ))}
56
- </div>
57
- );
58
- }
1
+ "use client";
2
+
3
+ import type { ICompilerService } from "../structures/ICompilerService";
4
+
5
+ /**
6
+ * Renders the lint plugin's findings in a list view. Shown by `PlaygroundShell`
7
+ * when the active tab is "lint". Empty state is the green checkmark.
8
+ */
9
+ export function LintPane({
10
+ diagnostics,
11
+ emptyHint = "Powered by @ttsc/lint inside playground.wasm.",
12
+ }: {
13
+ diagnostics: ICompilerService.IDiagnostic[];
14
+ emptyHint?: string;
15
+ }) {
16
+ if (diagnostics.length === 0)
17
+ return (
18
+ <div className="flex h-full flex-col items-center justify-center gap-2 font-mono text-sm text-slate-500">
19
+ <span className="text-emerald-400 text-xl">✓</span>
20
+ <span>No lint diagnostics.</span>
21
+ <span className="max-w-xs text-center text-[10px] text-slate-400">
22
+ {emptyHint}
23
+ </span>
24
+ </div>
25
+ );
26
+ return (
27
+ <div className="overflow-auto h-full p-4 space-y-2">
28
+ {diagnostics.map((d, i) => (
29
+ <div
30
+ key={i}
31
+ className="flex gap-3 rounded-lg border border-[#d2e4f4] bg-[#f7fbff] p-3"
32
+ >
33
+ <span
34
+ className={`mt-0.5 text-[10px] font-mono px-1.5 py-0.5 rounded shrink-0 ${
35
+ d.severity === "error"
36
+ ? "text-red-300 bg-red-500/10"
37
+ : "text-yellow-300 bg-yellow-500/10"
38
+ }`}
39
+ >
40
+ {d.severity}
41
+ </span>
42
+ <div className="flex-1 min-w-0">
43
+ <div className="mb-1 flex items-center gap-2 font-mono text-[11px] text-slate-500">
44
+ <span>{d.code}</span>
45
+ <span>·</span>
46
+ <span>
47
+ {d.line}:{d.column}
48
+ </span>
49
+ </div>
50
+ <div className="font-mono text-[13px] text-slate-700">
51
+ {d.message}
52
+ </div>
53
+ </div>
54
+ </div>
55
+ ))}
56
+ </div>
57
+ );
58
+ }
@@ -1,132 +1,132 @@
1
- "use client";
2
-
3
- import { useEffect, useRef } from "react";
4
-
5
- import type { IOptionToggle } from "../structures/IOptionToggle";
6
- import type { ITransformOptions } from "../structures/ITransformOptions";
7
- import { DEFAULT_OPTION_TOGGLES } from "./DEFAULT_OPTION_TOGGLES";
8
-
9
- interface OptionsPanelProps {
10
- options: ITransformOptions;
11
- onChange: (next: ITransformOptions) => void;
12
- onClose: () => void;
13
- /** Defaults to the typia + lint pair from `DEFAULT_OPTION_TOGGLES`. */
14
- toggles?: readonly IOptionToggle[];
15
- /** Dialog heading. Defaults to "Transform Options". */
16
- title?: string;
17
- }
18
-
19
- export function OptionsPanel({
20
- options,
21
- onChange,
22
- onClose,
23
- toggles = DEFAULT_OPTION_TOGGLES,
24
- title = "Transform Options",
25
- }: OptionsPanelProps) {
26
- const dialogRef = useRef<HTMLDivElement>(null);
27
-
28
- const toggle = (key: string) =>
29
- onChange({ ...options, [key]: !options[key] });
30
-
31
- // Escape closes. Focus traps inside the dialog.
32
- useEffect(() => {
33
- const onKey = (e: KeyboardEvent) => {
34
- if (e.key === "Escape") {
35
- e.preventDefault();
36
- onClose();
37
- return;
38
- }
39
- if (e.key !== "Tab" || !dialogRef.current) return;
40
- const focusable = dialogRef.current.querySelectorAll<HTMLElement>(
41
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
42
- );
43
- if (focusable.length === 0) return;
44
- const first = focusable[0]!;
45
- const last = focusable[focusable.length - 1]!;
46
- if (e.shiftKey && document.activeElement === first) {
47
- e.preventDefault();
48
- last.focus();
49
- } else if (!e.shiftKey && document.activeElement === last) {
50
- e.preventDefault();
51
- first.focus();
52
- }
53
- };
54
- window.addEventListener("keydown", onKey);
55
- // Auto-focus the first focusable on mount.
56
- const focusable = dialogRef.current?.querySelector<HTMLElement>(
57
- 'button, input, [tabindex]:not([tabindex="-1"])',
58
- );
59
- focusable?.focus();
60
- return () => window.removeEventListener("keydown", onKey);
61
- }, [onClose]);
62
-
63
- return (
64
- <div
65
- className="fixed inset-0 z-50 flex items-center justify-center bg-[#102a43]/35 backdrop-blur-sm"
66
- onClick={onClose}
67
- >
68
- <div
69
- ref={dialogRef}
70
- role="dialog"
71
- aria-modal="true"
72
- aria-labelledby="playground-options-title"
73
- className="w-[480px] max-w-[90vw] rounded-2xl border border-[#b9d5ee] bg-white shadow-[0_30px_80px_rgba(35,90,151,0.25)]"
74
- onClick={(e) => e.stopPropagation()}
75
- >
76
- <div className="flex items-center justify-between border-b border-[#c7dff4] bg-[#f7fbff] px-6 py-4">
77
- <h2
78
- id="playground-options-title"
79
- className="text-base font-semibold text-[#102a43]"
80
- >
81
- {title}
82
- </h2>
83
- <button
84
- onClick={onClose}
85
- className="text-slate-400 transition-colors hover:text-[#235a97]"
86
- aria-label="Close options"
87
- >
88
-
89
- </button>
90
- </div>
91
- <div className="p-6 space-y-6">
92
- <div>
93
- <div className="mb-3 font-mono text-[10px] uppercase tracking-wider text-slate-500">
94
- Plugins
95
- </div>
96
- <div className="space-y-3">
97
- {toggles.map((t) => (
98
- <label
99
- key={t.key}
100
- className="flex items-start gap-3 cursor-pointer group"
101
- >
102
- <input
103
- type="checkbox"
104
- checked={!!options[t.key]}
105
- onChange={() => toggle(t.key)}
106
- className="mt-1 w-4 h-4 accent-blue-500"
107
- />
108
- <div className="flex-1">
109
- <div className="font-mono text-sm text-slate-800 transition-colors group-hover:text-[#235a97]">
110
- {t.label}
111
- </div>
112
- <div className="text-[11px] leading-snug text-slate-500">
113
- {t.description}
114
- </div>
115
- </div>
116
- </label>
117
- ))}
118
- </div>
119
- </div>
120
- </div>
121
- <div className="flex justify-end border-t border-[#c7dff4] bg-[#f7fbff] px-6 py-4">
122
- <button
123
- onClick={onClose}
124
- className="rounded-md bg-[#3178c6] px-4 py-2 font-mono text-xs text-white transition-colors hover:bg-[#235a97]"
125
- >
126
- Done
127
- </button>
128
- </div>
129
- </div>
130
- </div>
131
- );
132
- }
1
+ "use client";
2
+
3
+ import { useEffect, useRef } from "react";
4
+
5
+ import type { IOptionToggle } from "../structures/IOptionToggle";
6
+ import type { ITransformOptions } from "../structures/ITransformOptions";
7
+ import { DEFAULT_OPTION_TOGGLES } from "./DEFAULT_OPTION_TOGGLES";
8
+
9
+ interface OptionsPanelProps {
10
+ options: ITransformOptions;
11
+ onChange: (next: ITransformOptions) => void;
12
+ onClose: () => void;
13
+ /** Defaults to the typia + lint pair from `DEFAULT_OPTION_TOGGLES`. */
14
+ toggles?: readonly IOptionToggle[];
15
+ /** Dialog heading. Defaults to "Transform Options". */
16
+ title?: string;
17
+ }
18
+
19
+ export function OptionsPanel({
20
+ options,
21
+ onChange,
22
+ onClose,
23
+ toggles = DEFAULT_OPTION_TOGGLES,
24
+ title = "Transform Options",
25
+ }: OptionsPanelProps) {
26
+ const dialogRef = useRef<HTMLDivElement>(null);
27
+
28
+ const toggle = (key: string) =>
29
+ onChange({ ...options, [key]: !options[key] });
30
+
31
+ // Escape closes. Focus traps inside the dialog.
32
+ useEffect(() => {
33
+ const onKey = (e: KeyboardEvent) => {
34
+ if (e.key === "Escape") {
35
+ e.preventDefault();
36
+ onClose();
37
+ return;
38
+ }
39
+ if (e.key !== "Tab" || !dialogRef.current) return;
40
+ const focusable = dialogRef.current.querySelectorAll<HTMLElement>(
41
+ 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
42
+ );
43
+ if (focusable.length === 0) return;
44
+ const first = focusable[0]!;
45
+ const last = focusable[focusable.length - 1]!;
46
+ if (e.shiftKey && document.activeElement === first) {
47
+ e.preventDefault();
48
+ last.focus();
49
+ } else if (!e.shiftKey && document.activeElement === last) {
50
+ e.preventDefault();
51
+ first.focus();
52
+ }
53
+ };
54
+ window.addEventListener("keydown", onKey);
55
+ // Auto-focus the first focusable on mount.
56
+ const focusable = dialogRef.current?.querySelector<HTMLElement>(
57
+ 'button, input, [tabindex]:not([tabindex="-1"])',
58
+ );
59
+ focusable?.focus();
60
+ return () => window.removeEventListener("keydown", onKey);
61
+ }, [onClose]);
62
+
63
+ return (
64
+ <div
65
+ className="fixed inset-0 z-50 flex items-center justify-center bg-[#102a43]/35 backdrop-blur-sm"
66
+ onClick={onClose}
67
+ >
68
+ <div
69
+ ref={dialogRef}
70
+ role="dialog"
71
+ aria-modal="true"
72
+ aria-labelledby="playground-options-title"
73
+ className="w-[480px] max-w-[90vw] rounded-2xl border border-[#b9d5ee] bg-white shadow-[0_30px_80px_rgba(35,90,151,0.25)]"
74
+ onClick={(e) => e.stopPropagation()}
75
+ >
76
+ <div className="flex items-center justify-between border-b border-[#c7dff4] bg-[#f7fbff] px-6 py-4">
77
+ <h2
78
+ id="playground-options-title"
79
+ className="text-base font-semibold text-[#102a43]"
80
+ >
81
+ {title}
82
+ </h2>
83
+ <button
84
+ onClick={onClose}
85
+ className="text-slate-400 transition-colors hover:text-[#235a97]"
86
+ aria-label="Close options"
87
+ >
88
+
89
+ </button>
90
+ </div>
91
+ <div className="p-6 space-y-6">
92
+ <div>
93
+ <div className="mb-3 font-mono text-[10px] uppercase tracking-wider text-slate-500">
94
+ Plugins
95
+ </div>
96
+ <div className="space-y-3">
97
+ {toggles.map((t) => (
98
+ <label
99
+ key={t.key}
100
+ className="flex items-start gap-3 cursor-pointer group"
101
+ >
102
+ <input
103
+ type="checkbox"
104
+ checked={!!options[t.key]}
105
+ onChange={() => toggle(t.key)}
106
+ className="mt-1 w-4 h-4 accent-blue-500"
107
+ />
108
+ <div className="flex-1">
109
+ <div className="font-mono text-sm text-slate-800 transition-colors group-hover:text-[#235a97]">
110
+ {t.label}
111
+ </div>
112
+ <div className="text-[11px] leading-snug text-slate-500">
113
+ {t.description}
114
+ </div>
115
+ </div>
116
+ </label>
117
+ ))}
118
+ </div>
119
+ </div>
120
+ </div>
121
+ <div className="flex justify-end border-t border-[#c7dff4] bg-[#f7fbff] px-6 py-4">
122
+ <button
123
+ onClick={onClose}
124
+ className="rounded-md bg-[#3178c6] px-4 py-2 font-mono text-xs text-white transition-colors hover:bg-[#235a97]"
125
+ >
126
+ Done
127
+ </button>
128
+ </div>
129
+ </div>
130
+ </div>
131
+ );
132
+ }