mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: add text-to-drawing
This commit is contained in:
parent
0958241589
commit
530e92189f
12 changed files with 557 additions and 850 deletions
|
@ -8,8 +8,9 @@ import {
|
|||
import { NonDeletedExcalidrawElement } from "../../element/types";
|
||||
import { AppClassProperties, BinaryFiles } from "../../types";
|
||||
import { canvasToBlob } from "../../data/blob";
|
||||
import { atom } from "jotai";
|
||||
|
||||
const resetPreview = ({
|
||||
export const resetPreview = ({
|
||||
canvasRef,
|
||||
setError,
|
||||
}: {
|
||||
|
@ -30,6 +31,26 @@ const resetPreview = ({
|
|||
canvasNode.replaceChildren();
|
||||
};
|
||||
|
||||
export type OnTestSubmitRetValue = {
|
||||
rateLimit?: number | null;
|
||||
rateLimitRemaining?: number | null;
|
||||
} & (
|
||||
| {
|
||||
generatedResponse: any | string | undefined;
|
||||
error?: null | undefined;
|
||||
}
|
||||
| {
|
||||
error: Error;
|
||||
generatedResponse?: null | undefined;
|
||||
}
|
||||
);
|
||||
export interface CommonDialogProps {
|
||||
onTextSubmit(
|
||||
value: string,
|
||||
type: "text-to-diagram" | "text-to-drawing",
|
||||
): Promise<OnTestSubmitRetValue>;
|
||||
}
|
||||
|
||||
export interface MermaidToExcalidrawLibProps {
|
||||
loaded: boolean;
|
||||
api: Promise<{
|
||||
|
@ -137,14 +158,14 @@ export const insertToEditor = ({
|
|||
shouldSaveMermaidDataToStorage,
|
||||
}: {
|
||||
app: AppClassProperties;
|
||||
data: React.MutableRefObject<{
|
||||
data: {
|
||||
elements: readonly NonDeletedExcalidrawElement[];
|
||||
files: BinaryFiles | null;
|
||||
}>;
|
||||
};
|
||||
text?: string;
|
||||
shouldSaveMermaidDataToStorage?: boolean;
|
||||
}) => {
|
||||
const { elements: newElements, files } = data.current;
|
||||
const { elements: newElements, files } = data;
|
||||
|
||||
if (!newElements.length) {
|
||||
return;
|
||||
|
@ -162,3 +183,11 @@ export const insertToEditor = ({
|
|||
saveMermaidDataToStorage(text);
|
||||
}
|
||||
};
|
||||
|
||||
export const MIN_PROMPT_LENGTH = 3;
|
||||
export const MAX_PROMPT_LENGTH = 1000;
|
||||
|
||||
export const rateLimitsAtom = atom<{
|
||||
rateLimit: number;
|
||||
rateLimitRemaining: number;
|
||||
} | null>(null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue