Skip to content

Commit

Permalink
fix: html conversion absolute position support, better inline style s…
Browse files Browse the repository at this point in the history
…upport

feat: deploy button for html23
  • Loading branch information
bbohlender committed Apr 27, 2024
1 parent c113440 commit a74e9bf
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/html23/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@coconut-xr/xinteraction": "^0.1.12",
"@preact/signals-core": "^1.5.1",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-popover": "^1.0.7",
Expand Down
4 changes: 3 additions & 1 deletion apps/html23/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConversionNode, htmlToCode, parsedHtmlToCode } from '@react-three/uikit

import { suspend } from 'suspend-react'
import 'prismjs/themes/prism.css'
import { AlertCircle, HeartHandshake, Link, Maximize, Minimize, Send, HardDriveDownload } from 'lucide-react'
import { AlertCircle, HeartHandshake, Link, Maximize, Minimize, Send, HardDriveDownload, Rocket } from 'lucide-react'
import { Alert, AlertTitle, AlertDescription } from './components/ui/alert.js'
import { Highlight } from 'prism-react-renderer'
import { Button } from './components/ui/button.js'
Expand Down Expand Up @@ -37,6 +37,7 @@ import musicPlayer from './examples/music-player.json'
import pricing from './examples/pricing.json'
import profile from './examples/profile.json'
import weather from './examples/weather.json'
import { DeployDialog } from './components/deploy.js'

export const componentMap = { ...defaultComponentMap, ...lucideComponentMap }

Expand Down Expand Up @@ -132,6 +133,7 @@ export default function App() {
JSON
</Button>
)}
<DeployDialog />
<Tooltip>
<TooltipTrigger asChild>
<a href="https://github.com/sponsors/bbohlender" target="_blank">
Expand Down
65 changes: 65 additions & 0 deletions apps/html23/src/components/deploy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ArrowRight, Rocket } from 'lucide-react'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from './ui/dialog.js'
import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip.js'
import { Button } from './ui/button.js'
import { Label } from './ui/label.js'
import { DialogClose } from '@radix-ui/react-dialog'

export function DeployDialog() {
return (
<Dialog>
<Tooltip>
<TooltipTrigger asChild>
<DialogTrigger asChild>
<Button variant="outline" className="flex flex-row items-center gap-2 pl-3">
<Rocket />
Deploy
</Button>
</DialogTrigger>
</TooltipTrigger>
<TooltipContent>Deploy the Project</TooltipContent>
</Tooltip>
<DialogContent className="flex flex-col flex-shrink">
<DialogHeader>
<DialogTitle className="text-2xl">Project deployment is not yet supported.</DialogTitle>
<DialogDescription className="text-xl">Sorry 😔</DialogDescription>
</DialogHeader>
<div className="flex flex-col pb-4 flex-grow text-md gap-4">
<span className="text-lg">This project is Free and Open Source build by individuals</span>
<hr />
<span className="text-lg">
We are evaluating if there's enough interest for pro features, such as <b>One Click Deployment</b>.
</span>
<span className="text-lg">
Interested in html23 pro features?
<br />↳ Select ✅ and fill out the questionaire.
</span>
<span className="text-gray-400">Your responses will help us decide if html23 pro is demanded.</span>
</div>
<DialogFooter className="gap-2">
<DialogClose asChild>
<Button className="bg-gray-400 w-full flex-basis-0" type="button">
❌ Not Interested
</Button>
</DialogClose>
<a
href="https://docs.google.com/forms/d/e/1FAIpQLSfVb1eBPEU2kMo2CqYpW6HrlwIe027bBHeSvLJmJpqMH6QWcQ/viewform"
target="_blank"
>
<Button type="button" className="w-full flex-basis-0">
<span className="text-lg mr-3">✅</span> I am interested in Pro Features
</Button>
</a>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
120 changes: 120 additions & 0 deletions apps/html23/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { X } from "lucide-react"

import { cn } from "@/lib/utils"

const Dialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

const DialogPortal = DialogPrimitive.Portal

const DialogClose = DialogPrimitive.Close

const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName

const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName

const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"

const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"

const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName

const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}
1 change: 0 additions & 1 deletion apps/html23/src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
}
* {
@apply border-border;
scrollbar-color: tranparent gray;
}
body {
@apply bg-background text-foreground;
Expand Down
9 changes: 7 additions & 2 deletions packages/uikit/src/convert/html/internals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse as parseHTML, Node as ConversionNode, TextNode, HTMLElement } from 'node-html-parser'
import { htmlDefaults } from './defaults.js'
import parseInlineCSS from 'inline-style-parser'
import parseInlineCSS, { Declaration, Comment } from 'inline-style-parser'
import { tailwindToCSS } from 'tw-to-css'
import generatedPropertyTypes from './properties.json' assert { type: 'json' }
import {
Expand Down Expand Up @@ -408,7 +408,12 @@ function convertHtmlAttributes(
Object.assign(result, convertTailwind(propertyTypes, classes, className, colorMap))
}

const styles = style == null ? [] : parseInlineCSS(style)
let styles: Array<Declaration | Comment> = []
try {
if (style != null) {
styles = parseInlineCSS(style)
}
} catch {}
for (const style of styles) {
if (style.type === 'comment') {
continue
Expand Down
4 changes: 4 additions & 0 deletions packages/uikit/src/convert/html/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const yogaPropertyRenamings = {
rowGap: 'gapRow',
columnGap: 'gapColumn',
position: 'positionType',
top: 'positionTop',
left: 'positionLeft',
right: 'positionRight',
bottom: 'positionBottom',
}

const cssShorthandPropertyTranslation: Record<
Expand Down
37 changes: 37 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a74e9bf

Please sign in to comment.