diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..a0ece19 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "trailingComma": "es5", + "singleQuote": true, + "semi": false, + "printWidth": 100, + "tabWidth": 2, + "useTabs": true +} diff --git a/README.md b/README.md index d4dc5ef..7e3c8b0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ +**Try it out at [makereal.tldraw.com](https://makereal.tldraw.com/).** + +\*\*To use your own API key, you need to have access to usage tier 1. Check out your current tier, and how to increase it [in the OpenAI settings](http://platform.openai.com/account/limits). + > This is an experimental fork of Sawyer Hood's [draw a ui](https://github.com/SawyerHood/draw-a-ui). > Hopefully some of these changes can make it upstream! +> > - Changes the preview to an embedded shape that appears on the canvas. > - Only selected shapes are used when generating html. > - One embedded preview can be given back to GPT, with annotations. @@ -21,8 +26,8 @@ This is a Next.js app. To get started run the following commands in the root dir ```bash echo "OPENAI_API_KEY=sk-your-key" > .env.local -npm install -npm run dev +yarn +yarn dev ``` Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. diff --git a/app/PreviewShape/PreviewShape.tsx b/app/PreviewShape/PreviewShape.tsx index 7608ad3..20ac179 100644 --- a/app/PreviewShape/PreviewShape.tsx +++ b/app/PreviewShape/PreviewShape.tsx @@ -5,8 +5,6 @@ import { useIsEditing, HTMLContainer, toDomPrecision, - SvgExportContext, - TLFrameShape, Icon, useToasts, stopEventPropagation, diff --git a/app/components/APIKeyInput.tsx b/app/components/APIKeyInput.tsx index 6e6d611..60068ac 100644 --- a/app/components/APIKeyInput.tsx +++ b/app/components/APIKeyInput.tsx @@ -1,13 +1,9 @@ -import { Input, useBreakpoint } from '@tldraw/tldraw' +import { useBreakpoint } from '@tldraw/tldraw' export function APIKeyInput() { const breakpoint = useBreakpoint() return ( -
+
Have your own OpenAI API key?
diff --git a/app/components/ExportButton.tsx b/app/components/ExportButton.tsx index 1bd4eb4..4dde7bc 100644 --- a/app/components/ExportButton.tsx +++ b/app/components/ExportButton.tsx @@ -1,9 +1,4 @@ -import { - useEditor, - getSvgAsImage, - useToasts, - createShapeId, -} from '@tldraw/tldraw' +import { useEditor, getSvgAsImage, useToasts, createShapeId } from '@tldraw/tldraw' import { useState } from 'react' import { PreviewShape } from '../PreviewShape/PreviewShape' @@ -21,6 +16,16 @@ export function ExportButton() { e.preventDefault() const selectedShapes = editor.getSelectedShapes() + + if (selectedShapes.length === 0) { + toast.addToast({ + title: 'Nothing selected', + description: 'First select something to make real.', + id: 'nothing_selected: First select something to make real.', + }) + return + } + const previewPosition = selectedShapes.reduce( (acc, shape) => { const bounds = editor.getShapePageBounds(shape) @@ -39,9 +44,13 @@ export function ExportButton() { }) as PreviewShape[] if (previousPreviews.length > 1) { - throw new Error( - 'You can only give the developer one previous design to work with.' - ) + toast.addToast({ + title: 'Too many previous designs', + description: + 'Currently, you can only give the developer one previous design to work with.', + id: 'too_many_previous_designs', + }) + return } const previousHtml = @@ -54,9 +63,7 @@ export function ExportButton() { return } - const IS_SAFARI = /^((?!chrome|android).)*safari/i.test( - navigator.userAgent - ) + const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) const blob = await getSvgAsImage(svg, IS_SAFARI, { type: 'png', @@ -84,11 +91,8 @@ export function ExportButton() { image: dataUrl, html: previousHtml, apiKey: - ( - document.getElementById( - 'openai_key_risky_but_cool' - ) as HTMLInputElement - )?.value ?? null, + (document.getElementById('openai_key_risky_but_cool') as HTMLInputElement)?.value ?? + null, }), }) diff --git a/app/layout.tsx b/app/layout.tsx index 66728f5..285393e 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -66,11 +66,7 @@ export const metadata: Metadata = { const inter = Inter({ subsets: ['latin'] }) -export default function RootLayout({ - children, -}: { - children: React.ReactNode -}) { +export default function RootLayout({ children }: { children: React.ReactNode }) { return ( diff --git a/app/page.tsx b/app/page.tsx index 6f9ee4c..89fc32d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,13 +1,13 @@ +/* eslint-disable @next/next/no-img-element */ /* eslint-disable react-hooks/rules-of-hooks */ 'use client' -import Lockup from './lockup.svg' import dynamic from 'next/dynamic' import '@tldraw/tldraw/tldraw.css' -import React, { useEffect, useState } from 'react' +import React from 'react' import { PreviewShapeUtil } from './PreviewShape/PreviewShape' import { ExportButton } from './components/ExportButton' -import { useBreakpoint, useDialogs, useEditor } from '@tldraw/tldraw' +import { useBreakpoint } from '@tldraw/tldraw' import { APIKeyInput } from './components/APIKeyInput' const Tldraw = dynamic(async () => (await import('@tldraw/tldraw')).Tldraw, { @@ -20,11 +20,7 @@ export default function Home() { return ( <>
- } - > + }> @@ -41,6 +37,7 @@ function LockupLink() { href="https://www.tldraw.dev" >