Skip to content

Commit

Permalink
fix: jsx import source types
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Apr 4, 2024
1 parent 805b1a1 commit e66d1ae
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export type TextInputProps = {
}

TextInput.__type = 'text-input'
export function TextInput({ placeholder }: TextInputProps) {
export function TextInput({ placeholder }: TextInputProps): JSX.Element {
return <meta property="fc:frame:input:text" content={placeholder} />
}
9 changes: 5 additions & 4 deletions src/frog-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ export class FrogBase<
return c.redirect(location, 302)
}

const renderAsHTML =
c.req.header('Accept') === 'text/html' ||
c.req.query('accept') === 'text/html'

// If the user is coming from a browser, and a `browserLocation` is set,
// then we will redirect the user to that location.
const browser = detect(c.req.header('user-agent'))
Expand All @@ -392,7 +396,7 @@ export class FrogBase<
basePath: this.basePath,
path,
})
if (browser?.name && browserLocation_)
if (!renderAsHTML && browser?.name && browserLocation_)
return c.redirect(
browserLocation_.startsWith('http')
? browserLocation_
Expand Down Expand Up @@ -502,9 +506,6 @@ export class FrogBase<
for (const [key, value] of Object.entries(headers ?? {}))
c.header(key, value)

const renderAsHTML =
c.req.header('Accept') === 'text/html' ||
c.req.query('accept') === 'text/html'
if (renderAsHTML) {
const height = imageOptions?.height ?? 630
const width = imageOptions?.width ?? 1200
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type { Env } from './types/env.js'
export type {
FrameResponse,
FrameIntent,
/** @deprecated Use `FrameIntent[]` instead. */
FrameIntents,
} from './types/frame.js'
export type { HandlerResponse, TypedResponse } from './types/response.js'
Expand Down
5 changes: 3 additions & 2 deletions src/types/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type FrameResponse = {
* <Button>Submit</Button>,
* ]
*/
intents?: FrameIntents | undefined
intents?: FrameIntent | FrameIntent[] | undefined
/**
* Title of the frame (added as `og:title`).
*
Expand Down Expand Up @@ -149,7 +149,8 @@ export type FrameImageAspectRatio = '1.91:1' | '1:1'

export type FrameVersion = 'vNext'

export type FrameIntent = JSX.Element | false | null | undefined
export type FrameIntent = JSX.Element | JSX.Element[] | false | null | undefined
/** @deprecated */
export type FrameIntents = FrameIntent | FrameIntent[]

export type FrameButtonValue = string
Expand Down
9 changes: 6 additions & 3 deletions src/ui/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Child } from 'hono/jsx'

import type { Direction, SatoriStyleProperties, ValueOf } from './types.js'
import type {
Child,
Direction,
SatoriStyleProperties,
ValueOf,
} from './types.js'
import { type DefaultVars, type Vars, defaultVars } from './vars.js'

export type VariableValue<property extends keyof SatoriStyleProperties, token> =
Expand Down
3 changes: 2 additions & 1 deletion src/ui/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Child } from 'hono/jsx'
import { Box, type BoxProps } from './Box.js'
import type { Child } from './types.js'
import type { DefaultVars, Vars } from './vars.js'

export type TextProps<vars extends Vars = DefaultVars> = {
/** Sets the horizontal alignment of the text. */
align?: BoxProps<vars>['textAlign']
/** The text content. */
children: Child
/** Sets the color of the text. */
color?: BoxProps<vars>['color']
Expand Down
2 changes: 2 additions & 0 deletions src/ui/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Properties } from 'csstype'

export type Child = import('hono/jsx').Child | JSX.Element

export type SatoriStyleProperties = Pick<
Properties,
| 'alignContent'
Expand Down
4 changes: 2 additions & 2 deletions src/utils/parseImage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Child, JSXNode } from 'hono/jsx'
import type { JSXNode } from 'hono/jsx'

import type { Frog } from '../frog.js'
import type { Direction } from '../ui/types.js'
import type { Child, Direction } from '../ui/types.js'
import { parsePath } from './parsePath.js'

export async function parseImage(
Expand Down
4 changes: 2 additions & 2 deletions src/utils/parseIntents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type JSXNode } from 'hono/jsx'

import { buttonPrefix } from '../components/Button.js'
import { type FrameIntents } from '../types/frame.js'
import { type FrameIntent } from '../types/frame.js'
import { parsePath } from './parsePath.js'

type Counter = { button: number }
Expand All @@ -12,7 +12,7 @@ type ParseIntentsOptions = {
}

export function parseIntents(
intents_: FrameIntents | undefined,
intents_: FrameIntent | FrameIntent[] | undefined,
options: ParseIntentsOptions = {},
counter: Counter = { button: 1 },
): JSXNode[] {
Expand Down

0 comments on commit e66d1ae

Please sign in to comment.