Skip to content

Commit

Permalink
[pr] t2d
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelle committed Nov 24, 2023
1 parent 438ef99 commit 8800e34
Show file tree
Hide file tree
Showing 34 changed files with 1,238 additions and 258 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ VITE_APP_PORTAL_URL=
VITE_APP_PLUS_LP=https://plus.excalidraw.com
VITE_APP_PLUS_APP=https://app.excalidraw.com

VITE_APP_AI_BACKEND=http://localhost:3015

VITE_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyCMkxA60XIW8KbqMYL7edC4qT5l4qHX2h8","authDomain":"excalidraw-oss-dev.firebaseapp.com","projectId":"excalidraw-oss-dev","storageBucket":"excalidraw-oss-dev.appspot.com","messagingSenderId":"664559512677","appId":"1:664559512677:web:a385181f2928d328a7aa8c"}'

# put these in your .env.local, or make sure you don't commit!
Expand Down
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ VITE_APP_PORTAL_URL=https://portal.excalidraw.com
VITE_APP_PLUS_LP=https://plus.excalidraw.com
VITE_APP_PLUS_APP=https://app.excalidraw.com

VITE_APP_AI_BACKEND=https://oss-ai.excalidraw.com

# Fill to set socket server URL used for collaboration.
# Meant for forks only: excalidraw.com uses custom VITE_APP_PORTAL_URL flow
VITE_APP_WS_SERVER_URL=
Expand Down
24 changes: 24 additions & 0 deletions excalidraw-app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import {
Footer,
Button,
Sidebar,
LiveCollaborationTrigger,
TTDDialog,
TTDDialogTrigger,
} from "../src/packages/excalidraw/index";
import {
AppState,
Expand Down Expand Up @@ -846,6 +849,27 @@ const ExcalidrawWrapper = () => {
</Button>
</div>
</Footer>
<TTDDialog
onTextSubmit={async (input) => {
const response = await fetch(
`${
import.meta.env.VITE_APP_AI_BACKEND
}/v1/ai/text-to-diagram/generate`,
{
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt: input }),
},
);

const { generatedResponse } = await response.json();
return generatedResponse;
}}
/>
<TTDDialogTrigger />
{isCollaborating && isOffline && (
<div className="collab-offline-warning">
{t("alerts.collabOfflineWarning")}
Expand Down
8 changes: 6 additions & 2 deletions src/components/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
MagicIcon,
} from "./icons";
import { KEYS } from "../keys";
import { useTunnels } from "../context/tunnels";

export const SelectedShapeActions = ({
appState,
Expand Down Expand Up @@ -235,6 +236,8 @@ export const ShapesSwitcher = ({
const laserToolSelected = activeTool.type === "laser";
const embeddableToolSelected = activeTool.type === "embeddable";

const { TTDDialogTriggerTunnel } = useTunnels();

return (
<>
{SHAPES.map(({ value, icon, key, numericKey, fillable }, index) => {
Expand Down Expand Up @@ -338,14 +341,14 @@ export const ShapesSwitcher = ({
<div style={{ margin: "6px 0", fontSize: 14, fontWeight: 600 }}>
Generate
</div>
{app.props.aiEnabled !== false && <TTDDialogTriggerTunnel.Out />}
<DropdownMenu.Item
onSelect={() => app.setOpenDialog({ name: "mermaid" })}
onSelect={() => app.setOpenDialog({ name: "ttd", tab: "mermaid" })}
icon={mermaidLogoIcon}
data-testid="toolbar-embeddable"
>
{t("toolBar.mermaidToExcalidraw")}
</DropdownMenu.Item>

{app.props.aiEnabled !== false && (
<>
<DropdownMenu.Item
Expand All @@ -354,6 +357,7 @@ export const ShapesSwitcher = ({
data-testid="toolbar-magicframe"
>
{t("toolBar.magicframe")}
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
</DropdownMenu.Item>
<DropdownMenu.Item
onSelect={() => {
Expand Down
4 changes: 0 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
import { StaticCanvas, InteractiveCanvas } from "./canvases";
import { Renderer } from "../scene/Renderer";
import { ShapeCache } from "../scene/ShapeCache";
import MermaidToExcalidraw from "./MermaidToExcalidraw";
import { LaserToolOverlay } from "./LaserTool/LaserTool";
import { LaserPathManager } from "./LaserTool/LaserPathManager";
import {
Expand Down Expand Up @@ -1442,9 +1441,6 @@ class App extends React.Component<AppProps, AppState> {
uiDisabled={this.props.ui === false}
>
{this.props.children}
{this.state.openDialog?.name === "mermaid" && (
<MermaidToExcalidraw />
)}
</LayerUI>

<div className="excalidraw-textEditorContainer" />
Expand Down
6 changes: 5 additions & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import clsx from "clsx";
import { composeEventHandlers } from "../utils";
import "./Button.scss";

interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
interface ButtonProps
extends React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
> {
type?: "button" | "submit" | "reset";
onSelect: () => any;
/** whether button is in active state */
Expand Down
2 changes: 2 additions & 0 deletions src/components/LayerUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { ShapeCache } from "../scene/ShapeCache";
import Scene from "../scene/Scene";
import { LaserPointerButton } from "./LaserTool/LaserPointerButton";
import { MagicSettings } from "./MagicSettings";
import { TTDDialog } from "./TTDDialog/TTDDialog";

interface LayerUIProps {
actionManager: ActionManager;
Expand Down Expand Up @@ -404,6 +405,7 @@ const LayerUI = ({
{t("toolBar.library")}
</DefaultSidebar.Trigger>
<DefaultOverwriteConfirmDialog />
{appState.openDialog?.name === "ttd" && <TTDDialog __fallback />}
{/* ------------------------------------------------------------------ */}

{appState.isLoading && <LoadingMessage delay={250} />}
Expand Down
221 changes: 0 additions & 221 deletions src/components/MermaidToExcalidraw.scss

This file was deleted.

10 changes: 10 additions & 0 deletions src/components/TTDDialog/MermaidToExcalidraw.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.excalidraw {
.dialog-mermaid {
&-title {
margin-block: 0.25rem;
font-size: 1.25rem;
font-weight: 700;
padding-inline: 2.5rem;
}
}
}
Loading

0 comments on commit 8800e34

Please sign in to comment.