vite-plugin-hyperapp 1.1.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -4
- package/index.d.ts +10 -0
- package/index.js +2 -2
- package/jsx.d.ts +59 -0
- package/jsx.js +8 -8
- package/package.json +37 -2
- package/ssr.d.ts +1 -1
- package/jsx-runtime.d.ts +0 -11
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Use vite as a dev-server and bundler for your hyperapp projects. Supports:
|
|
|
12
12
|
To get up and running with Hyperapp and Vite in a few seconds, use [create-vite-hyperapp](https://github.com/zaceno/create-vite-hyperapp):
|
|
13
13
|
|
|
14
14
|
```sh
|
|
15
|
-
> npm create vite-hyperapp
|
|
15
|
+
> npm create vite-hyperapp@latest
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
> Use `npm create vite-hyperapp -- --help` for some command line options.
|
|
@@ -39,16 +39,56 @@ export default defineConfig({
|
|
|
39
39
|
```
|
|
40
40
|
> Options are passed as an object to `hyperapp({...})`. Available options described below.
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
In order to enable build TSX files to build, please add the following options to `compilerOptions` in your `tsconfig.json`:
|
|
43
43
|
|
|
44
44
|
```json
|
|
45
|
-
/* Necessary for tsx to work with vite-plugin-hyperapp*/
|
|
45
|
+
/* Necessary for tsx to work with vite-plugin-hyperapp */
|
|
46
46
|
"jsx": "preserve",
|
|
47
|
-
"
|
|
47
|
+
"jsxFactory": "jsx",
|
|
48
|
+
"jsxFragmentFactory": "jsxFragment"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
and to make sure your editor's TS language server picks up the right types for JSX/TSX,
|
|
52
|
+
add this line in your `src/vite-env.d.ts`:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
/// <reference types="vite-plugin-hyperapp/jsx" />
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## JSX/TSX
|
|
59
|
+
|
|
60
|
+
Our JSX/TSX works the same as React/Preact, however, note that when you pass children to a component, like:
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
<MyComponent>
|
|
64
|
+
<p>foo</p>
|
|
65
|
+
<p>bar</p>
|
|
66
|
+
</MyComponent>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
they will arrive as an array of virtual nodes in the _second_ argument to the component.
|
|
70
|
+
|
|
71
|
+
```jsx
|
|
72
|
+
const MyComponent = (props, children) => {
|
|
73
|
+
//children will be: [<p>foo</p>, <p>bar</p>]
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
It's ok to put this array of children among other children, because the jsx transform will flatten the child-list:
|
|
78
|
+
|
|
79
|
+
```jsx
|
|
80
|
+
const MyComponent = (props, children) => (
|
|
81
|
+
<div>
|
|
82
|
+
<h1>Header</h1>
|
|
83
|
+
{children} {/* <--- this is fine */}
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
48
86
|
```
|
|
49
87
|
|
|
50
88
|
## Hot-module-reloading (HMR)
|
|
51
89
|
|
|
90
|
+
> The following is taken care of already, when you scaffold your app with `npm create vite-hyperapp`, but it is useful to be aware of
|
|
91
|
+
|
|
52
92
|
For hot-module-reloading to work, the plugin injects some code in the module where you initiate the app. In order for this to work, the app-initiation module must follow these two rules:
|
|
53
93
|
|
|
54
94
|
1. It must import `app` from `"hyperapp"` using named imports (i.e. with `{..app...}`, not `*`
|
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -32,10 +32,10 @@ export default function injectConsoleLog(options = {}) {
|
|
|
32
32
|
|
|
33
33
|
config: () => ({
|
|
34
34
|
esbuild: {
|
|
35
|
-
jsxFactory: "
|
|
35
|
+
jsxFactory: "jsx",
|
|
36
36
|
jsxFragment: "jsxFragment",
|
|
37
37
|
jsxInject:
|
|
38
|
-
"import {
|
|
38
|
+
"import {jsx, jsxFragment} from 'vite-plugin-hyperapp/jsx.js'",
|
|
39
39
|
},
|
|
40
40
|
}),
|
|
41
41
|
|
package/jsx.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Props, MaybeVNode, ElementVNode } from "hyperapp"
|
|
2
|
+
|
|
3
|
+
type Component<S, P> = (
|
|
4
|
+
props: P,
|
|
5
|
+
children: MaybeVNode<S>[],
|
|
6
|
+
) => MaybeVNode<S> | MaybeVNode<S>[]
|
|
7
|
+
|
|
8
|
+
type _JSXChild<S> = string | number | MaybeVNode<S>
|
|
9
|
+
type JSXChild<S> = _JSXChild<S> | _JSXChild<S>[]
|
|
10
|
+
|
|
11
|
+
export declare function jsx<S>(
|
|
12
|
+
type: string,
|
|
13
|
+
props?: Props<S>,
|
|
14
|
+
...children: JSXChild<S>[]
|
|
15
|
+
): ElementVNode<S>
|
|
16
|
+
|
|
17
|
+
export declare function jsx<S, P>(
|
|
18
|
+
type: Component<S, P>,
|
|
19
|
+
props?: P | null,
|
|
20
|
+
...children: JSXChild<S>[]
|
|
21
|
+
): ReturnType<Component<S, P>>
|
|
22
|
+
|
|
23
|
+
export declare function jsxFragment<S>(
|
|
24
|
+
_: any,
|
|
25
|
+
children: JSXChild<S>[],
|
|
26
|
+
): MaybeVNode<S>[]
|
|
27
|
+
|
|
28
|
+
declare global {
|
|
29
|
+
namespace JSX {
|
|
30
|
+
/** Result of a JSX expression. Components may return arrays. */
|
|
31
|
+
type Element = MaybeVNode<any> | MaybeVNode<any>[]
|
|
32
|
+
|
|
33
|
+
/** What you can put in the `<X />` position */
|
|
34
|
+
type ElementType = string | Component<any, any>
|
|
35
|
+
|
|
36
|
+
/** Allow `<>...</>` fragments; returns an array */
|
|
37
|
+
type Fragment = MaybeVNode<any>[]
|
|
38
|
+
|
|
39
|
+
/** Intrinsic (HTML/SVG) elements. */
|
|
40
|
+
interface IntrinsicElements {
|
|
41
|
+
[elem: string]: Props<any>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** prevents errors about children missing from props in components */
|
|
45
|
+
type LibraryManagedAttributes<P> = P & { children?: JSXChild<any>[] }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// make jsx and jsxFragment ambient globals because
|
|
50
|
+
// ts server doesn't know I'll add them later in transform
|
|
51
|
+
type JsxFn = typeof jsx
|
|
52
|
+
type JsxFragmentFn = typeof jsxFragment
|
|
53
|
+
|
|
54
|
+
declare global {
|
|
55
|
+
const jsx: JsxFn
|
|
56
|
+
const jsxFragment: JsxFragmentFn
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export {}
|
package/jsx.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { h, text } from "hyperapp"
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const cproc = children =>
|
|
4
|
+
children
|
|
5
|
+
.flat()
|
|
6
|
+
.map(x => ((typeof x === "string") | (typeof x === "number") ? text(x) : x))
|
|
5
7
|
|
|
6
|
-
export const
|
|
8
|
+
export const jsx = (tag, props, ...children) =>
|
|
7
9
|
typeof tag === "function"
|
|
8
|
-
? tag(props, children)
|
|
9
|
-
: h(tag, props || {}, children
|
|
10
|
+
? tag(props, cproc(children))
|
|
11
|
+
: h(tag, props || {}, cproc(children))
|
|
10
12
|
|
|
11
|
-
export const jsxFragment = (_, children) =>
|
|
12
|
-
return children.flat(2).map(nodeify)
|
|
13
|
-
}
|
|
13
|
+
export const jsxFragment = (_, children) => cproc(children)
|
package/package.json
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-hyperapp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Plugin and helpers for using Hyperapp with Vite",
|
|
6
|
-
"main": "index.js",
|
|
6
|
+
"main": "./index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
10
|
"author": "Zacharias Enochsson",
|
|
11
11
|
"license": "MIT",
|
|
12
|
+
"files": [
|
|
13
|
+
"*.js",
|
|
14
|
+
"*.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"import": "./index.js",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"./jsx": {
|
|
23
|
+
"types": "./jsx.d.ts",
|
|
24
|
+
"import": "./jsx.js",
|
|
25
|
+
"default": "./jsx.js"
|
|
26
|
+
},
|
|
27
|
+
"./jsx.js": {
|
|
28
|
+
"types": "./jsx.d.ts",
|
|
29
|
+
"import": "./jsx.js",
|
|
30
|
+
"default": "./jsx.js"
|
|
31
|
+
},
|
|
32
|
+
"./ssr": {
|
|
33
|
+
"types": "./ssr.d.ts",
|
|
34
|
+
"import": "./ssr.js",
|
|
35
|
+
"default": "./ssr.js"
|
|
36
|
+
},
|
|
37
|
+
"./ssr.js": {
|
|
38
|
+
"types": "./ssr.d.ts",
|
|
39
|
+
"import": "./ssr.js",
|
|
40
|
+
"default": "./ssr.js"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
12
44
|
"dependencies": {
|
|
13
45
|
"jsdom": "^24.1.0",
|
|
14
46
|
"hyperapp": "^2.0.22"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"vite": "^4.5.14"
|
|
15
50
|
}
|
|
16
51
|
}
|
package/ssr.d.ts
CHANGED
package/jsx-runtime.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
This type declaration is named 'jsx-runtime.d.tx' even though
|
|
3
|
-
jsx is compiled in the classic way. It's only named this to make
|
|
4
|
-
it easier for tsconfig.json to be ok with jsx in .tsx-files.
|
|
5
|
-
*/
|
|
6
|
-
import { Props } from "hyperapp"
|
|
7
|
-
declare global {
|
|
8
|
-
module JSX {
|
|
9
|
-
type IntrinsicElements = Record<string, Props<any>>
|
|
10
|
-
}
|
|
11
|
-
}
|