Skip to content

Commit

Permalink
🧹 chore: bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Dec 15, 2023
1 parent df93bef commit c41363d
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 108 deletions.
Binary file modified bun.lockb
Binary file not shown.
12 changes: 7 additions & 5 deletions example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function page({ name }: { name: string }): string {
}

// https://elysiajs.com/plugins/html.html#jsx
function tsxPage({ name }: { name: string }): JSX.Element {
function TsxPage({ name }: { name: string }): JSX.Element {
return (
<html lang="en" style={{ backgroundColor: 'black', color: 'white' }}>
<head>
Expand All @@ -35,15 +35,15 @@ async function FakeDatabase({ name }: { name: string }) {
return <h1>Hello {name}!</h1>
}

function asyncPage(rid: number, { name }: { name: string }): JSX.Element {
function AsyncPage({ name, id }: { id: number; name: string }): JSX.Element {
return (
<html lang="en" style={{ backgroundColor: 'black', color: 'white' }}>
<head>
<title>Hello {name}!</title>
</head>
<body>
{/* https://github.com/kitajs/html#suspense-component */}
<Suspense rid={rid} fallback={<h1>Loading...</h1>}>
<Suspense rid={id} fallback={<h1>Loading...</h1>}>
<FakeDatabase name={name} />
</Suspense>
</body>
Expand All @@ -62,6 +62,8 @@ new Elysia()
// https://elysiajs.com/plugins/html.html#options
.use(html())
.get('/', ({ query }) => page(query), indexSchema)
.get('/tsx', ({ query }) => tsxPage(query), indexSchema)
.get('/async', ({ query, html }) => html(asyncPage, query), indexSchema)
.get('/tsx', ({ query }) => <TsxPage name={query.name} />, indexSchema)
.get('/async', ({ query, stream }) => stream(<AsyncPage name={query.name} />, query), indexSchema)
.listen(8080, () => console.log('Listening on http://localhost:8080'))


6 changes: 6 additions & 0 deletions example/simple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Elysia } from 'elysia'
import { html } from '../src'

new Elysia()
.use(html())
.get('/0.7', () => <h1>Hello World</h1>)
134 changes: 75 additions & 59 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,78 @@
{
"name": "@elysiajs/html",
"version": "0.7.3",
"description": "Plugin for Elysia that add support for returning html",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
},
"main": "./dist/index.js",
"exports": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"types": "./src/index.ts",
"keywords": [
"elysia",
"html"
],
"homepage": "https://github.com/elysiajs/elysia-html",
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-html"
},
"bugs": "https://github.com/elysiajs/elysia-html/issues",
"license": "MIT",
"scripts": {
"dev": "bun run --watch example/index.tsx",
"test": "bun test && npm run test:node",
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public",
"format": "prettier --write ."
},
"peerDependencies": {
"@kitajs/html": ">= 3.0.0",
"elysia": ">= 0.7.15"
},
"devDependencies": {
"@types/node": "^20.7.2",
"bun-types": "^1.0.3",
"elysia": "^0.7.15",
"eslint": "^8.50.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
},
"dependencies": {
"@kitajs/html": "^3.0.2",
"@kitajs/ts-html-plugin": "^1.2.0"
},
"peerDependenciesMeta": {
"@kitajs/html": {
"optional": true
"name": "@elysiajs/html",
"version": "0.8.0-rc.0",
"description": "Plugin for Elysia that add support for returning html",
"author": {
"name": "saltyAom",
"url": "https://github.com/SaltyAom",
"email": "[email protected]"
},
"@kitajs/ts-html-plugin": {
"optional": true
"main": "./dist/index.js",
"exports": {
".": {
"bun": "./dist/index.js",
"node": "./dist/cjs/index.js",
"require": "./dist/cjs/index.js",
"import": "./dist/index.js",
"default": "./dist/index.js"
},
"./htmx": {
"bun": "./dist/html.js",
"node": "./dist/cjs/htmx.js",
"require": "./dist/cjs/htmx.js",
"import": "./dist/htmx.js",
"default": "./dist/htmx.js"
},
"./hotwire": {
"bun": "./dist/hotwire.js",
"node": "./dist/cjs/hotwire.js",
"require": "./dist/cjs/hotwire.js",
"import": "./dist/hotwire.js",
"default": "./dist/hotwire.js"
}
},
"types": "./src/index.ts",
"keywords": [
"elysia",
"html"
],
"homepage": "https://github.com/elysiajs/elysia-html",
"repository": {
"type": "git",
"url": "https://github.com/elysiajs/elysia-html"
},
"bugs": "https://github.com/elysiajs/elysia-html/issues",
"license": "MIT",
"scripts": {
"dev": "bun run --watch example/index.tsx",
"test": "bun test && npm run test:node",
"test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js",
"build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json",
"release": "npm run build && npm run test && npm publish --access public",
"format": "prettier --write ."
},
"peerDependencies": {
"elysia": ">= 0.8.0-rc.0"
},
"devDependencies": {
"@elysiajs/stream": "^0.7.2",
"@types/node": "^20.7.2",
"bun-types": "^1.0.3",
"elysia": "0.8.0-rc.0",
"eslint": "^8.50.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
},
"dependencies": {
"@kitajs/html": "^3.0.2",
"@kitajs/ts-html-plugin": "^1.2.0"
},
"peerDependenciesMeta": {
"@kitajs/html": {
"optional": true
},
"@kitajs/ts-html-plugin": {
"optional": true
}
}
}
}
}
1 change: 1 addition & 0 deletions src/hotwire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@kitajs/html/hotwire-turbo'
26 changes: 14 additions & 12 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ export function html(options: HtmlOptions = {}) {

let instance = new Elysia({ name: '@elysiajs/html' }).derive(({ set }) => {
return {
html<A = void>(
value:
| Readable
| JSX.Element
| ((this: void, rid: number, ...args: A[]) => JSX.Element),
...args: A[]
html(
value: Readable | JSX.Element
): Promise<Response | string> | Response | string {
if (typeof value === 'function') {
value = renderToStream((rid) =>
(value as Function)(rid, ...args)
)
}

return handleHtml(value, options, 'content-type' in set.headers)
},
stream<A = any>(
value: (this: void, arg: A & { id: number }) => JSX.Element,
args: A
) {
return handleHtml(
renderToStream((id) =>
(value as Function)({ ...args, id })
),
options,
'content-type' in set.headers
)
}
}
})
Expand Down
1 change: 1 addition & 0 deletions src/htmx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@kitajs/html/htmx'
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ export * from './utils'
// Adds @kitajs/html's Html globally.
export * from '@kitajs/html/register'

export { ErrorBoundary } from '@kitajs/html/error-boundary'
export { Suspense } from '@kitajs/html/suspense'

export { Html } from '@kitajs/html'
64 changes: 32 additions & 32 deletions test/jsx-stream.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,45 @@ describe('Jsx html', () => {
it('auto return html with built in handler', async () => {
const app = new Elysia()
.use(html())
.get('/', ({ html }) => html(() => htmlContent))
.get('/', ({ html }) => html(htmlContent))

const res = await app.handle(request('/'))

expect(await res.text()).toBe(htmlContent)
expect(res.headers.get('Content-Type')).toContain('text/html')
})

it('works with async suspense', async () => {
const app = new Elysia().use(html()).get('/', ({ html }) =>
html((rid) => (
<div>
<Suspense rid={rid} fallback={<div>1</div>}>
{Promise.resolve(<div>2</div>)}
</Suspense>
</div>
))
)

const res = await app.handle(request('/'))

expect(res.headers.get('Content-Type')).toContain('text/html')
expect(await res.text()).toBe(
<>
<div>
<div id="B:1" data-sf>
<div>1</div>
</div>
</div>
{SuspenseScript}
<template id="N:1" data-sr>
<div>2</div>
</template>
<script id="S:1" data-ss>
$RC(1)
</script>
</>
)
})
// it('works with async suspense', async () => {
// const app = new Elysia().use(html()).get('/', ({ html }) =>
// html((rid) => (
// <div>
// <Suspense rid={rid} fallback={<div>1</div>}>
// {Promise.resolve(<div>2</div>)}
// </Suspense>
// </div>
// ))
// )

// const res = await app.handle(request('/'))

// expect(res.headers.get('Content-Type')).toContain('text/html')
// expect(await res.text()).toBe(
// <>
// <div>
// <div id="B:1" data-sf>
// <div>1</div>
// </div>
// </div>
// {SuspenseScript}
// <template id="N:1" data-sr>
// <div>2</div>
// </template>
// <script id="S:1" data-ss>
// $RC(1)
// </script>
// </>
// )
// })
})

describe('HTML', () => {
Expand Down

0 comments on commit c41363d

Please sign in to comment.