Skip to content

Commit

Permalink
chore: preview styles
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Feb 9, 2024
1 parent fef4bb4 commit bdd419d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 25 deletions.
5 changes: 4 additions & 1 deletion example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ app.frame('/', (context) => {
<div
style={{
alignItems: 'center',
background: 'linear-gradient(to right, #432889, #17101F)',
background:
status === 'response'
? 'linear-gradient(to right, #432889, #17101F)'
: 'black',
backgroundSize: '100% 100%',
display: 'flex',
flexDirection: 'column',
Expand Down
14 changes: 8 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { type Context, Hono } from 'hono'
import { ImageResponse } from 'hono-og'
import { type JSXNode } from 'hono/jsx'
import { jsxRenderer } from 'hono/jsx-renderer'
import type { HtmlEscapedString } from 'hono/utils/html'
import { type HtmlEscapedString } from 'hono/utils/html'

import { Preview, previewStyles } from './preview.js'
import {
Expand Down Expand Up @@ -56,7 +56,7 @@ export class Farc extends Hono {

const serializedContext = serializeJson(context)
const serializedPreviousContext = serializeJson({
...context,
...previousContext,
intents: parsedIntents,
})

Expand Down Expand Up @@ -89,10 +89,12 @@ export class Farc extends Hono {
{parsedIntents}

<meta property="farc:context" content={serializedContext} />
<meta
property="farc:prev_context"
content={serializedPreviousContext}
/>
{previousContext && (
<meta
property="farc:prev_context"
content={serializedPreviousContext}
/>
)}
</head>
</html>,
)
Expand Down
100 changes: 82 additions & 18 deletions src/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,92 @@ async function Devtools(props: DevtoolsProps) {
} = frame

return (
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
<pre style={{ fontFamily: 'monospace' }}>
{JSON.stringify(state, null, 2)}
</pre>

<pre style={{ fontFamily: 'monospace' }}>
{JSON.stringify(rest, null, 2)}
</pre>

{htmlTags && (
<pre style={{ fontFamily: 'monospace' }}>
{htmlTags.map((x) => (
<code style={{ display: 'grid' }}>{x}</code>
))}
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: '0.75rem',
}}
>
<div
style={{
borderWidth: '1px',
borderRadius: '0.5rem',
display: 'grid',
gap: '10px',
gridTemplateColumns: 'repeat(2, minmax(0,1fr))',
maxWidth: '85vw',
maxHeight: '48vh',
}}
>
<pre
style={{
fontFamily: 'monospace',
overflow: 'auto',
padding: '0.5rem',
}}
>
<div
style={{
fontFamily: 'sans-serif',
fontSize: '0.85rem',
fontWeight: 'bold',
}}
>
Current
</div>
{JSON.stringify(state.context, null, 2)}
</pre>
)}
<pre
style={{
fontFamily: 'monospace',
overflow: 'auto',
borderLeftWidth: '1px',
padding: '0.5rem',
}}
>
<div
style={{
fontFamily: 'sans-serif',
fontSize: '0.85rem',
fontWeight: 'bold',
}}
>
Previous
</div>
{JSON.stringify(state.previousContext, null, 2)}
</pre>
</div>

{debug && (
<div
style={{
borderRadius: '0.5rem',
borderWidth: '1px',
display: 'flex',
flexDirection: 'column',
maxWidth: '85vw',
overflow: 'auto',
padding: '0.5rem',
}}
>
<pre style={{ fontFamily: 'monospace' }}>
{JSON.stringify(debug, null, 2)}
{JSON.stringify(rest, null, 2)}
</pre>
)}

{htmlTags && (
<pre style={{ fontFamily: 'monospace' }}>
{htmlTags.map((x) => (
<code style={{ display: 'grid' }}>{x}</code>
))}
</pre>
)}

{debug && (
<pre style={{ fontFamily: 'monospace' }}>
{JSON.stringify(debug, null, 2)}
</pre>
)}
</div>
</div>
)
}
Expand Down

0 comments on commit bdd419d

Please sign in to comment.