Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Open in LiveCodes" #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createReplitProject,
createStackBlitzProject,
getCodeSandboxUrl,
getLiveCodesUrl,
} from '../lib/uploadToThirdParty'

export function Dropdown({
Expand Down Expand Up @@ -73,6 +74,15 @@ export function Dropdown({
}
}, [html, toast])

const openInLiveCodes = useCallback(() => {
try {
const project = getLiveCodesUrl(html)
window.open(project)
} catch {
toast.addToast({ title: 'There was a problem opening in LiveCodes.' })
}
}, [html, toast])

// const openInCodePen = useCallback(async () => {
// window.open(getCodePenUrl(html))
// }, [html])
Expand Down Expand Up @@ -100,6 +110,7 @@ export function Dropdown({
<Item action={openInCodeSandbox}>Open in CodeSandbox</Item>
<Item action={openInStackBlitz}>Open in StackBlitz</Item>
<Item action={openInReplit}>Open in Replit</Item>
<Item action={openInLiveCodes}>Open in LiveCodes</Item>
{/* <Item action={openInCodePen}>Open in CodePen</Item> */}
</div>
</DropdownMenu.Content>
Expand Down
13 changes: 13 additions & 0 deletions app/lib/uploadToThirdParty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export function getCodeSandboxUrl(html: string) {
return `https://codesandbox.io/api/v1/sandboxes/define?parameters=${project}`
}

export function getLiveCodesUrl(html: string) {
const config = {
title: 'Make real from tldraw',
description: 'Your AI generated example made at https://makereal.tldraw.com/',
markup: {
language: 'html',
content: html,
},
}
const compressed = LZString.compressToEncodedURIComponent(JSON.stringify(config))
return `https://livecodes.io/?x=code/${compressed}`
}

// The following two functions are from
// https://github.com/codesandbox/codesandbox-importers/blob/master/packages/import-utils/src/api/define.17:41:36
// They are licensed under GPLv3 and from my understanding usning them here is fine since we are using GNU Affero General Public License v3.0
Expand Down