Skip to content

Commit 2512a96

Browse files
committed
feat: add code editor option to MainMenu
1 parent 2f299ce commit 2512a96

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/frontend/src/ui/MainMenu.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import React from 'react';
33
import type { ExcalidrawImperativeAPI } from '@atyrode/excalidraw/types';
44
import type { MainMenu as MainMenuType } from '@atyrode/excalidraw';
55

6-
import { LogOut, SquarePlus, LayoutDashboard, SquareCode, Eye, Coffee, Grid2x2, User } from 'lucide-react';
6+
import { LogOut, SquarePlus, LayoutDashboard, SquareCode, Eye, Coffee, Grid2x2, User, Text } from 'lucide-react';
77
import { capture } from '../utils/posthog';
88
import { ExcalidrawElementFactory, PlacementMode } from '../lib/ExcalidrawElementFactory';
99
import { useUserProfile } from "../api/hooks";
1010
import { queryClient } from "../api/queryClient";
11+
import Editor from '../pad/editors/Editor';
1112

1213
interface MainMenuConfigProps {
1314
MainMenu: typeof MainMenuType;
@@ -32,8 +33,8 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
3233
if (!excalidrawAPI) return;
3334

3435
const htmlEditorElement = ExcalidrawElementFactory.createEmbeddableElement({
35-
link: "!editor",
36-
width: 1200,
36+
link: "!html",
37+
width: 800,
3738
height: 500
3839
});
3940

@@ -75,6 +76,22 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
7576
scrollToView: true
7677
});
7778
};
79+
80+
const handleEditorClick = () => {
81+
if (!excalidrawAPI) return;
82+
83+
const editorElement = ExcalidrawElementFactory.createEmbeddableElement({
84+
link: "!editor",
85+
width: 800,
86+
height: 500
87+
});
88+
89+
ExcalidrawElementFactory.placeInScene(editorElement, excalidrawAPI, {
90+
mode: PlacementMode.NEAR_VIEWPORT_CENTER,
91+
bufferPercentage: 10,
92+
scrollToView: true
93+
});
94+
};
7895

7996
const handleGridToggle = () => {
8097
if (!excalidrawAPI) return;
@@ -154,6 +171,12 @@ export const MainMenuConfig: React.FC<MainMenuConfigProps> = ({
154171
>
155172
Insert HTML Editor
156173
</MainMenu.Item>
174+
<MainMenu.Item
175+
icon={<Text />}
176+
onClick={handleEditorClick}
177+
>
178+
Insert Code Editor
179+
</MainMenu.Item>
157180
<MainMenu.Item
158181
icon={<LayoutDashboard />}
159182
onClick={handleDashboardButtonClick}

0 commit comments

Comments
 (0)