Skip to content

Commit 41b5451

Browse files
committed
Make the the editor playground resizable
1 parent fd81edc commit 41b5451

12 files changed

+93
-12
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
src/lib/utils.ts
2+
src/components/*

packages/cxx-playground/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"lucide-react": "^0.525.0",
1616
"react": "latest",
1717
"react-dom": "latest",
18+
"react-resizable-panels": "^3.0.3",
1819
"tailwind-merge": "^3.3.1"
1920
},
2021
"devDependencies": {

packages/cxx-playground/src/App.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
2626
import ModelProvider from "./editor-model-provider";
2727
import EditorProvider from "./editor-provider";
2828
import AbstractSyntaxTree from "./abstract-syntax-tree";
29-
29+
import {
30+
ResizableHandle,
31+
ResizablePanel,
32+
ResizablePanelGroup,
33+
} from "@/components/ui/resizable";
3034
import * as monaco from "monaco-editor";
3135

3236
window.MonacoEnvironment = {
@@ -50,14 +54,24 @@ function App() {
5054
const model = monaco.editor.createModel(DEFAULT_VALUE, "cpp");
5155

5256
return (
53-
<div className="w-svw h-svh flex">
57+
<div className="w-svw h-svh">
5458
<QueryClientProvider client={queryClient}>
5559
<CxxProvider fallback={<div />}>
5660
<ModelProvider model={model}>
5761
<EditorProvider model={model}>
5862
<ASTProvider model={model} interval={interval}>
59-
<Editor />
60-
<AbstractSyntaxTree />
63+
<ResizablePanelGroup
64+
direction="horizontal"
65+
className="w-full h-full"
66+
>
67+
<ResizablePanel className="min-w-1/4">
68+
<Editor />
69+
</ResizablePanel>
70+
<ResizableHandle />
71+
<ResizablePanel className="min-w-1/4" defaultSize={35}>
72+
<AbstractSyntaxTree />
73+
</ResizablePanel>
74+
</ResizablePanelGroup>
6175
</ASTProvider>
6276
</EditorProvider>
6377
</ModelProvider>

packages/cxx-playground/src/abstract-syntax-tree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function AbstractSyntaxTree() {
4949
message: message,
5050
source: "C++",
5151
});
52-
}
52+
},
5353
);
5454

5555
monaco.editor.setModelMarkers(model, "cxx", markers);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as React from "react"
2+
import { GripVerticalIcon } from "lucide-react"
3+
import * as ResizablePrimitive from "react-resizable-panels"
4+
5+
import { cn } from "@/lib/utils"
6+
7+
function ResizablePanelGroup({
8+
className,
9+
...props
10+
}: React.ComponentProps<typeof ResizablePrimitive.PanelGroup>) {
11+
return (
12+
<ResizablePrimitive.PanelGroup
13+
data-slot="resizable-panel-group"
14+
className={cn(
15+
"flex h-full w-full data-[panel-group-direction=vertical]:flex-col",
16+
className
17+
)}
18+
{...props}
19+
/>
20+
)
21+
}
22+
23+
function ResizablePanel({
24+
...props
25+
}: React.ComponentProps<typeof ResizablePrimitive.Panel>) {
26+
return <ResizablePrimitive.Panel data-slot="resizable-panel" {...props} />
27+
}
28+
29+
function ResizableHandle({
30+
withHandle,
31+
className,
32+
...props
33+
}: React.ComponentProps<typeof ResizablePrimitive.PanelResizeHandle> & {
34+
withHandle?: boolean
35+
}) {
36+
return (
37+
<ResizablePrimitive.PanelResizeHandle
38+
data-slot="resizable-handle"
39+
className={cn(
40+
"bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:translate-x-0 data-[panel-group-direction=vertical]:after:-translate-y-1/2 [&[data-panel-group-direction=vertical]>div]:rotate-90",
41+
className
42+
)}
43+
{...props}
44+
>
45+
{withHandle && (
46+
<div className="bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border">
47+
<GripVerticalIcon className="size-2.5" />
48+
</div>
49+
)}
50+
</ResizablePrimitive.PanelResizeHandle>
51+
)
52+
}
53+
54+
export { ResizablePanelGroup, ResizablePanel, ResizableHandle }

packages/cxx-playground/src/hooks/use-debounced-on-did-change-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function useDebouncedOnDidChangeContent({
3333
}) {
3434
const debouncedOnDidChangeContent = useDebouncedCallback(
3535
() => onDidChangeContent?.(model),
36-
interval
36+
interval,
3737
);
3838

3939
useOnDidChangeContent({

packages/cxx-playground/src/hooks/use-debounced-on-did-change-cursor-position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function useDebouncedOnDidChangeCursorPosition({
3131
interval?: number;
3232
onDidChangeCursorPosition?: (
3333
editor: monaco.editor.IStandaloneCodeEditor,
34-
position: monaco.Position
34+
position: monaco.Position,
3535
) => void;
3636
}) {
3737
const debouncedOnDidChangeContent = useDebouncedCallback(() => {

packages/cxx-playground/src/hooks/use-on-did-change-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function useOnDidChangeContent({
2828
model: monaco.editor.ITextModel;
2929
onDidChangeContent?: (
3030
model: monaco.editor.ITextModel,
31-
event: monaco.editor.IModelContentChangedEvent
31+
event: monaco.editor.IModelContentChangedEvent,
3232
) => void;
3333
}) {
3434
useEffect(() => {

packages/cxx-playground/src/hooks/use-on-did-change-cursor-position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function useOnDidChangeCursorPosition({
2828
editor: monaco.editor.IStandaloneCodeEditor | null;
2929
onDidChangeCursorPosition?: (
3030
editor: monaco.editor.IStandaloneCodeEditor,
31-
event: monaco.Position
31+
event: monaco.Position,
3232
) => void;
3333
}) {
3434
useEffect(() => {

0 commit comments

Comments
 (0)