Skip to content

Commit 91568bc

Browse files
added editor languages
1 parent 383de77 commit 91568bc

File tree

7 files changed

+85
-40
lines changed

7 files changed

+85
-40
lines changed

app/components/code-capture/controls/control-options.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,45 @@ import {
99
SelectValue,
1010
} from "@/components/ui/select";
1111
import useStore from "@/lib/store/store";
12-
import { setTheme } from "@/lib/themes/change-theme";
12+
import { setTheme } from "@/lib/editor/themes/change-theme";
1313

1414
import themeList from "monaco-themes/themes/themelist.json";
15+
import editorLanguages from "@/lib/editor/languages/editor-languages";
1516

1617
export default function ControlOptions() {
18+
// store
1719
const changeEditorTheme = useStore((state) => state.changeEditorTheme);
20+
const changeEditorLanguage = useStore((state) => state.changeEditorLanguage);
1821

1922
return (
2023
<div className="options space-y-4 p-2">
2124
<div className="language w-full flex gap-2 items-center">
2225
<div className="option-name w-1/3">Language</div>
2326
<div className="option-input w-full">
24-
<Select>
27+
<Select
28+
onValueChange={(value) => {
29+
changeEditorLanguage(value);
30+
}}
31+
>
2532
<SelectTrigger>
2633
<SelectValue placeholder="Javascript" />
2734
</SelectTrigger>
2835
<SelectContent>
2936
<SelectGroup>
30-
<SelectItem value="javascript">Javascript</SelectItem>
31-
<SelectItem value="typescript">Typescript</SelectItem>
32-
<SelectItem value="react">React</SelectItem>
33-
<SelectItem value="html">Html</SelectItem>
34-
<SelectItem value="css">Css</SelectItem>
37+
{editorLanguages.map((language) => (
38+
<SelectItem value={language}>{language}</SelectItem>
39+
))}
3540
</SelectGroup>
3641
</SelectContent>
3742
</Select>
3843
</div>
3944
</div>
45+
4046
<div className="theme w-full flex gap-2 items-center">
4147
<div className="option-name w-1/3">Theme</div>
4248
<div className="option-input w-full">
4349
<Select
4450
onValueChange={(value) => {
45-
console.log("value", value);
4651
changeEditorTheme(value);
4752
setTheme(value);
4853
}}

app/components/code-capture/preview/window-content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function WindowContent() {
1414
`;
1515

1616
return (
17-
<div className="content rounded-b-md opacity-90 h-20">
17+
<div className="content rounded-b-md opacity-90 h-60">
1818
<MonacoEditor />
1919
</div>
2020
);

components/ui/select.tsx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
"use client"
1+
"use client";
22

3-
import * as React from "react"
4-
import * as SelectPrimitive from "@radix-ui/react-select"
5-
import { Check, ChevronDown, ChevronUp } from "lucide-react"
3+
import * as React from "react";
4+
import * as SelectPrimitive from "@radix-ui/react-select";
5+
import { Check, ChevronDown, ChevronUp } from "lucide-react";
66

7-
import { cn } from "@/lib/utils"
7+
import { cn } from "@/lib/utils";
88

9-
const Select = SelectPrimitive.Root
9+
const Select = SelectPrimitive.Root;
1010

11-
const SelectGroup = SelectPrimitive.Group
11+
const SelectGroup = SelectPrimitive.Group;
1212

13-
const SelectValue = SelectPrimitive.Value
13+
const SelectValue = SelectPrimitive.Value;
1414

1515
const SelectTrigger = React.forwardRef<
1616
React.ElementRef<typeof SelectPrimitive.Trigger>,
@@ -19,7 +19,7 @@ const SelectTrigger = React.forwardRef<
1919
<SelectPrimitive.Trigger
2020
ref={ref}
2121
className={cn(
22-
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
22+
"flex h-10 capitalize w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
2323
className
2424
)}
2525
{...props}
@@ -29,8 +29,8 @@ const SelectTrigger = React.forwardRef<
2929
<ChevronDown className="h-4 w-4 opacity-50" />
3030
</SelectPrimitive.Icon>
3131
</SelectPrimitive.Trigger>
32-
))
33-
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
32+
));
33+
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
3434

3535
const SelectScrollUpButton = React.forwardRef<
3636
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
@@ -46,8 +46,8 @@ const SelectScrollUpButton = React.forwardRef<
4646
>
4747
<ChevronUp className="h-4 w-4" />
4848
</SelectPrimitive.ScrollUpButton>
49-
))
50-
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
49+
));
50+
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
5151

5252
const SelectScrollDownButton = React.forwardRef<
5353
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
@@ -63,9 +63,9 @@ const SelectScrollDownButton = React.forwardRef<
6363
>
6464
<ChevronDown className="h-4 w-4" />
6565
</SelectPrimitive.ScrollDownButton>
66-
))
66+
));
6767
SelectScrollDownButton.displayName =
68-
SelectPrimitive.ScrollDownButton.displayName
68+
SelectPrimitive.ScrollDownButton.displayName;
6969

7070
const SelectContent = React.forwardRef<
7171
React.ElementRef<typeof SelectPrimitive.Content>,
@@ -75,7 +75,7 @@ const SelectContent = React.forwardRef<
7575
<SelectPrimitive.Content
7676
ref={ref}
7777
className={cn(
78-
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
78+
"relativ z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
7979
position === "popper" &&
8080
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
8181
className
@@ -96,8 +96,8 @@ const SelectContent = React.forwardRef<
9696
<SelectScrollDownButton />
9797
</SelectPrimitive.Content>
9898
</SelectPrimitive.Portal>
99-
))
100-
SelectContent.displayName = SelectPrimitive.Content.displayName
99+
));
100+
SelectContent.displayName = SelectPrimitive.Content.displayName;
101101

102102
const SelectLabel = React.forwardRef<
103103
React.ElementRef<typeof SelectPrimitive.Label>,
@@ -108,8 +108,8 @@ const SelectLabel = React.forwardRef<
108108
className={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)}
109109
{...props}
110110
/>
111-
))
112-
SelectLabel.displayName = SelectPrimitive.Label.displayName
111+
));
112+
SelectLabel.displayName = SelectPrimitive.Label.displayName;
113113

114114
const SelectItem = React.forwardRef<
115115
React.ElementRef<typeof SelectPrimitive.Item>,
@@ -118,7 +118,7 @@ const SelectItem = React.forwardRef<
118118
<SelectPrimitive.Item
119119
ref={ref}
120120
className={cn(
121-
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
121+
"relative capitalize flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
122122
className
123123
)}
124124
{...props}
@@ -131,8 +131,8 @@ const SelectItem = React.forwardRef<
131131

132132
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
133133
</SelectPrimitive.Item>
134-
))
135-
SelectItem.displayName = SelectPrimitive.Item.displayName
134+
));
135+
SelectItem.displayName = SelectPrimitive.Item.displayName;
136136

137137
const SelectSeparator = React.forwardRef<
138138
React.ElementRef<typeof SelectPrimitive.Separator>,
@@ -143,8 +143,8 @@ const SelectSeparator = React.forwardRef<
143143
className={cn("-mx-1 my-1 h-px bg-muted", className)}
144144
{...props}
145145
/>
146-
))
147-
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
146+
));
147+
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
148148

149149
export {
150150
Select,
@@ -157,4 +157,4 @@ export {
157157
SelectSeparator,
158158
SelectScrollUpButton,
159159
SelectScrollDownButton,
160-
}
160+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const editorLanguages = [
2+
"javascript",
3+
"typescript",
4+
"python",
5+
"java",
6+
"csharp",
7+
"cpp",
8+
"php",
9+
"ruby",
10+
"swift",
11+
"go",
12+
"kotlin",
13+
"sql",
14+
"html",
15+
"css",
16+
"json",
17+
"markdown",
18+
"shell",
19+
];
20+
21+
export default editorLanguages;
File renamed without changes.

lib/monoco-editor.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
import { Editor, MonacoDiffEditor } from "@monaco-editor/react";
44
import React from "react";
55
import useStore from "./store/store";
6-
import { setTheme } from "./themes/change-theme";
6+
import { setTheme } from "./editor/themes/change-theme";
7+
import { Languages } from "lucide-react";
78

89
export default function MonacoEditor() {
910
const editorRef = React.useRef<MonacoDiffEditor>(null);
1011

1112
const windowWidth = useStore((state) => state.windowWidth);
1213
const changeWindowWidth = useStore((state) => state.changeWindowWidth);
14+
1315
const editorTheme = useStore((state) => state.editorTheme);
16+
const editorLanguage = useStore((state) => state.editorLanguage);
1417

15-
// Example function to log scroll width
18+
// to adjust editor width based on its content
1619
const controlEditorWidth = () => {
1720
if (editorRef.current) {
1821
const scrollWidth = editorRef.current.getScrollWidth();
@@ -24,18 +27,25 @@ export default function MonacoEditor() {
2427
}
2528
};
2629

30+
console.log('changed language',editorLanguage);
31+
2732
return (
2833
<Editor
29-
language="javascript"
34+
language={editorLanguage}
3035
height={"100%"}
31-
value="const width = 55;"
36+
value={`class HelloWorldApp {
37+
public static void main(String[] args) {
38+
System.out.println("Hello World!");
39+
}
40+
}`}
3241
theme="vs-dark"
3342
onMount={(editor) => {
3443
editorRef.current = editor;
3544
setTheme(editorTheme);
3645
}}
37-
onChange={() => {
46+
onChange={(editor, monaco) => {
3847
controlEditorWidth();
48+
// detectModel()
3949
}}
4050
options={{
4151
lineNumbers: "off",

lib/store/store.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ interface StoreStates {
66

77
editorTheme: string;
88
changeEditorTheme: (theme: string) => void;
9+
10+
editorLanguage: string;
11+
changeEditorLanguage: (language: string) => void;
912
}
1013

1114
const useStore = create<StoreStates>()((set) => ({
@@ -20,6 +23,12 @@ const useStore = create<StoreStates>()((set) => ({
2023
set(() => ({
2124
editorTheme: theme,
2225
})),
26+
27+
editorLanguage: "javascript",
28+
changeEditorLanguage: (language) =>
29+
set(() => ({
30+
editorLanguage: language,
31+
})),
2332
}));
2433

2534
export default useStore;

0 commit comments

Comments
 (0)