@solidjs/h 2.0.0-beta.8 → 2.0.0-beta.9
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 +8 -2
- package/dist/h.cjs +59 -21
- package/dist/h.js +60 -22
- package/jsx-runtime/types/index.d.ts +1 -5
- package/jsx-runtime/types-cjs/index.d.cts +1 -5
- package/package.json +9 -6
- package/types/hyperscript.d.ts +9 -3
- package/types-cjs/hyperscript.d.cts +9 -3
package/README.md
CHANGED
|
@@ -17,11 +17,17 @@ h("div", { title: "My button" }, h("span", "1"), h("span", "2"), h("span", "3"))
|
|
|
17
17
|
|
|
18
18
|
This is the least efficient way to use Solid as it requires a slightly larger runtime that isn't treeshakeable, and cannot leverage anything in the way of analysis, so it requires manual wrapping of expressions and has a few other caveats (see below).
|
|
19
19
|
|
|
20
|
+
> `h(...)` returns a tagged zero-arity thunk rather than a DOM node directly.
|
|
21
|
+
> Pass a function reference (or `() => h(App)`) to `render(...)` so the thunk
|
|
22
|
+
> is invoked inside the root. Nested `h(...)` thunks auto-invoke when consumed,
|
|
23
|
+
> so composition with control-flow components like `<For>` and `<Show>` works
|
|
24
|
+
> without extra wrapping.
|
|
25
|
+
|
|
20
26
|
## Example
|
|
21
27
|
|
|
22
28
|
```js
|
|
23
|
-
import { render } from "
|
|
24
|
-
import h from "
|
|
29
|
+
import { render } from "@solidjs/web";
|
|
30
|
+
import h from "@solidjs/h";
|
|
25
31
|
import { createSignal } from "solid-js";
|
|
26
32
|
|
|
27
33
|
function Button(props) {
|
package/dist/h.cjs
CHANGED
|
@@ -2,15 +2,54 @@
|
|
|
2
2
|
|
|
3
3
|
var web = require('@solidjs/web');
|
|
4
4
|
|
|
5
|
+
const $ELEMENT = Symbol("hyper-element");
|
|
6
|
+
const $WRAPPED = Symbol("hyper-wrapped");
|
|
7
|
+
function resolveThunks(value) {
|
|
8
|
+
if (typeof value === "function" && value[$ELEMENT]) return resolveThunks(value());
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
const out = new Array(value.length);
|
|
11
|
+
for (let i = 0; i < value.length; i++) out[i] = resolveThunks(value[i]);
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function wrapCallback(orig) {
|
|
17
|
+
let w;
|
|
18
|
+
if (orig.length === 1) {
|
|
19
|
+
w = function (a) {
|
|
20
|
+
return resolveThunks(orig.call(this, a));
|
|
21
|
+
};
|
|
22
|
+
} else if (orig.length === 2) {
|
|
23
|
+
w = function (a, b) {
|
|
24
|
+
return resolveThunks(orig.call(this, a, b));
|
|
25
|
+
};
|
|
26
|
+
} else {
|
|
27
|
+
w = function (...args) {
|
|
28
|
+
return resolveThunks(orig.apply(this, args));
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(w, "length", {
|
|
31
|
+
value: orig.length
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
w[$WRAPPED] = true;
|
|
35
|
+
return w;
|
|
36
|
+
}
|
|
5
37
|
function createHyperScript(r) {
|
|
6
|
-
function h() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
38
|
+
function h(...rawArgs) {
|
|
39
|
+
if (rawArgs.length === 1 && Array.isArray(rawArgs[0])) return rawArgs[0];
|
|
40
|
+
const thunk = () => r.untrack(() => materialize(rawArgs));
|
|
41
|
+
thunk[$ELEMENT] = true;
|
|
42
|
+
return thunk;
|
|
43
|
+
}
|
|
44
|
+
function materialize(args) {
|
|
45
|
+
let e;
|
|
46
|
+
let classes = [];
|
|
47
|
+
let multiExpression = false;
|
|
48
|
+
args = args.slice();
|
|
11
49
|
function item(l) {
|
|
50
|
+
if (l == null) return;
|
|
12
51
|
const type = typeof l;
|
|
13
|
-
if (
|
|
52
|
+
if ("string" === type) {
|
|
14
53
|
if (!e) parseClass(l);else e.appendChild(document.createTextNode(l));
|
|
15
54
|
} else if ("number" === type || "boolean" === type || "bigint" === type || "symbol" === type || l instanceof Date || l instanceof RegExp) {
|
|
16
55
|
e.appendChild(document.createTextNode(l.toString()));
|
|
@@ -38,26 +77,24 @@ function createHyperScript(r) {
|
|
|
38
77
|
dynamic ? r.spread(e, l, !!args.length) : r.assign(e, l, !!args.length);
|
|
39
78
|
} else if ("function" === type) {
|
|
40
79
|
if (!e) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
const first = args[0];
|
|
81
|
+
const props = first == null || typeof first === "object" && !Array.isArray(first) && !(first instanceof Element) ? args.shift() || {} : {};
|
|
82
|
+
if (args.length) props.children = args.length > 1 ? args : args[0];
|
|
83
|
+
for (const k in props) {
|
|
84
|
+
const v = props[k];
|
|
85
|
+
if (typeof v === "function") {
|
|
86
|
+
if (!v.length) r.dynamicProperty(props, k);else if (!v[$ELEMENT] && !v[$WRAPPED]) {
|
|
87
|
+
props[k] = wrapCallback(v);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
51
90
|
}
|
|
52
91
|
e = r.createComponent(l, props);
|
|
92
|
+
while (typeof e === "function" && e[$ELEMENT]) e = e();
|
|
53
93
|
args = [];
|
|
54
|
-
} else
|
|
55
|
-
r.insert(e, l, multiExpression ? null : undefined);
|
|
56
|
-
}
|
|
94
|
+
} else if (l[$ELEMENT]) item(l());else r.insert(e, l, multiExpression ? null : undefined);
|
|
57
95
|
}
|
|
58
96
|
}
|
|
59
|
-
if (args
|
|
60
|
-
typeof args[0] === "string" && detectMultiExpression(args);
|
|
97
|
+
if (typeof args[0] === "string") detectMultiExpression(args);
|
|
61
98
|
while (args.length) item(args.shift());
|
|
62
99
|
if (e instanceof Element && classes.length) e.classList.add(...classes);
|
|
63
100
|
return e;
|
|
@@ -92,6 +129,7 @@ const h = createHyperScript({
|
|
|
92
129
|
insert: web.insert,
|
|
93
130
|
createComponent: web.createComponent,
|
|
94
131
|
dynamicProperty: web.dynamicProperty,
|
|
132
|
+
untrack: web.untrack,
|
|
95
133
|
SVGElements: web.SVGElements,
|
|
96
134
|
MathMLElements: web.MathMLElements,
|
|
97
135
|
Namespaces: web.Namespaces
|
package/dist/h.js
CHANGED
|
@@ -1,14 +1,53 @@
|
|
|
1
|
-
import { Namespaces, MathMLElements, SVGElements, dynamicProperty, createComponent, insert, assign, spread } from '@solidjs/web';
|
|
1
|
+
import { Namespaces, MathMLElements, SVGElements, untrack, dynamicProperty, createComponent, insert, assign, spread } from '@solidjs/web';
|
|
2
2
|
|
|
3
|
+
const $ELEMENT = Symbol("hyper-element");
|
|
4
|
+
const $WRAPPED = Symbol("hyper-wrapped");
|
|
5
|
+
function resolveThunks(value) {
|
|
6
|
+
if (typeof value === "function" && value[$ELEMENT]) return resolveThunks(value());
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
const out = new Array(value.length);
|
|
9
|
+
for (let i = 0; i < value.length; i++) out[i] = resolveThunks(value[i]);
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function wrapCallback(orig) {
|
|
15
|
+
let w;
|
|
16
|
+
if (orig.length === 1) {
|
|
17
|
+
w = function (a) {
|
|
18
|
+
return resolveThunks(orig.call(this, a));
|
|
19
|
+
};
|
|
20
|
+
} else if (orig.length === 2) {
|
|
21
|
+
w = function (a, b) {
|
|
22
|
+
return resolveThunks(orig.call(this, a, b));
|
|
23
|
+
};
|
|
24
|
+
} else {
|
|
25
|
+
w = function (...args) {
|
|
26
|
+
return resolveThunks(orig.apply(this, args));
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(w, "length", {
|
|
29
|
+
value: orig.length
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
w[$WRAPPED] = true;
|
|
33
|
+
return w;
|
|
34
|
+
}
|
|
3
35
|
function createHyperScript(r) {
|
|
4
|
-
function h() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
36
|
+
function h(...rawArgs) {
|
|
37
|
+
if (rawArgs.length === 1 && Array.isArray(rawArgs[0])) return rawArgs[0];
|
|
38
|
+
const thunk = () => r.untrack(() => materialize(rawArgs));
|
|
39
|
+
thunk[$ELEMENT] = true;
|
|
40
|
+
return thunk;
|
|
41
|
+
}
|
|
42
|
+
function materialize(args) {
|
|
43
|
+
let e;
|
|
44
|
+
let classes = [];
|
|
45
|
+
let multiExpression = false;
|
|
46
|
+
args = args.slice();
|
|
9
47
|
function item(l) {
|
|
48
|
+
if (l == null) return;
|
|
10
49
|
const type = typeof l;
|
|
11
|
-
if (
|
|
50
|
+
if ("string" === type) {
|
|
12
51
|
if (!e) parseClass(l);else e.appendChild(document.createTextNode(l));
|
|
13
52
|
} else if ("number" === type || "boolean" === type || "bigint" === type || "symbol" === type || l instanceof Date || l instanceof RegExp) {
|
|
14
53
|
e.appendChild(document.createTextNode(l.toString()));
|
|
@@ -36,26 +75,24 @@ function createHyperScript(r) {
|
|
|
36
75
|
dynamic ? r.spread(e, l, !!args.length) : r.assign(e, l, !!args.length);
|
|
37
76
|
} else if ("function" === type) {
|
|
38
77
|
if (!e) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
78
|
+
const first = args[0];
|
|
79
|
+
const props = first == null || typeof first === "object" && !Array.isArray(first) && !(first instanceof Element) ? args.shift() || {} : {};
|
|
80
|
+
if (args.length) props.children = args.length > 1 ? args : args[0];
|
|
81
|
+
for (const k in props) {
|
|
82
|
+
const v = props[k];
|
|
83
|
+
if (typeof v === "function") {
|
|
84
|
+
if (!v.length) r.dynamicProperty(props, k);else if (!v[$ELEMENT] && !v[$WRAPPED]) {
|
|
85
|
+
props[k] = wrapCallback(v);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
49
88
|
}
|
|
50
89
|
e = r.createComponent(l, props);
|
|
90
|
+
while (typeof e === "function" && e[$ELEMENT]) e = e();
|
|
51
91
|
args = [];
|
|
52
|
-
} else
|
|
53
|
-
r.insert(e, l, multiExpression ? null : undefined);
|
|
54
|
-
}
|
|
92
|
+
} else if (l[$ELEMENT]) item(l());else r.insert(e, l, multiExpression ? null : undefined);
|
|
55
93
|
}
|
|
56
94
|
}
|
|
57
|
-
if (args
|
|
58
|
-
typeof args[0] === "string" && detectMultiExpression(args);
|
|
95
|
+
if (typeof args[0] === "string") detectMultiExpression(args);
|
|
59
96
|
while (args.length) item(args.shift());
|
|
60
97
|
if (e instanceof Element && classes.length) e.classList.add(...classes);
|
|
61
98
|
return e;
|
|
@@ -90,6 +127,7 @@ const h = createHyperScript({
|
|
|
90
127
|
insert,
|
|
91
128
|
createComponent,
|
|
92
129
|
dynamicProperty,
|
|
130
|
+
untrack,
|
|
93
131
|
SVGElements,
|
|
94
132
|
MathMLElements,
|
|
95
133
|
Namespaces
|
|
@@ -3,9 +3,5 @@ import type { JSX } from "./jsx.d.ts";
|
|
|
3
3
|
declare function Fragment(props: {
|
|
4
4
|
children: JSX.Element;
|
|
5
5
|
}): JSX.Element;
|
|
6
|
-
declare function jsx(type: any, props: any):
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}) | (Node & {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
})[];
|
|
6
|
+
declare function jsx(type: any, props: any): JSX.Element;
|
|
11
7
|
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment };
|
|
@@ -3,9 +3,5 @@ import type { JSX } from "./jsx.d.cts";
|
|
|
3
3
|
declare function Fragment(props: {
|
|
4
4
|
children: JSX.Element;
|
|
5
5
|
}): JSX.Element;
|
|
6
|
-
declare function jsx(type: any, props: any):
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}) | (Node & {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
})[];
|
|
6
|
+
declare function jsx(type: any, props: any): JSX.Element;
|
|
11
7
|
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment };
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/h",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"description": "Hyperscript / h() factory for Solid — write components without compiled JSX.",
|
|
4
|
+
"version": "2.0.0-beta.9",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/solidjs/solid
|
|
10
|
+
"url": "git+https://github.com/solidjs/solid.git",
|
|
11
|
+
"directory": "packages/solid-h"
|
|
11
12
|
},
|
|
12
13
|
"publishConfig": {
|
|
13
14
|
"access": "public"
|
|
@@ -62,10 +63,11 @@
|
|
|
62
63
|
"./types/*": "./types/*"
|
|
63
64
|
},
|
|
64
65
|
"peerDependencies": {
|
|
65
|
-
"@solidjs/web": "^2.0.0-beta.
|
|
66
|
+
"@solidjs/web": "^2.0.0-beta.9"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"
|
|
69
|
+
"solid-js": "2.0.0-beta.9",
|
|
70
|
+
"@solidjs/web": "2.0.0-beta.9"
|
|
69
71
|
},
|
|
70
72
|
"scripts": {
|
|
71
73
|
"build": "npm-run-all -nl build:*",
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
"types:h": "tsc --project ./tsconfig.json && ncp ../../node_modules/hyper-dom-expressions/types/index.d.ts ./types/hyperscript.d.ts",
|
|
78
80
|
"types:jsx": "rimraf ./jsx-runtime/types && tsc --project ./jsx-runtime/tsconfig.json && ncp ../../node_modules/dom-expressions/src/jsx-h.d.ts ./jsx-runtime/types/jsx.d.ts && ncp ../../node_modules/dom-expressions/src/jsx-properties.d.ts ./jsx-runtime/types/jsx-properties.d.ts",
|
|
79
81
|
"types:cjs": "node ../../scripts/sync-dual-types.mjs ./types ./types-cjs ./jsx-runtime/types ./jsx-runtime/types-cjs",
|
|
80
|
-
"link": "symlink-dir . node_modules/@solidjs/h"
|
|
82
|
+
"link": "symlink-dir . node_modules/@solidjs/h",
|
|
83
|
+
"test": "vitest run"
|
|
81
84
|
}
|
|
82
85
|
}
|
package/types/hyperscript.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ interface Runtime {
|
|
|
5
5
|
assign(node: Element, props: any, skipChildren?: Boolean): void;
|
|
6
6
|
createComponent(Comp: (props: any) => any, props: any): any;
|
|
7
7
|
dynamicProperty(props: any, key: string): any;
|
|
8
|
+
untrack<T>(fn: () => T): T;
|
|
8
9
|
SVGElements: Set<string>;
|
|
9
10
|
MathMLElements: Set<string>;
|
|
10
11
|
Namespaces: Record<string, string>;
|
|
@@ -12,11 +13,16 @@ interface Runtime {
|
|
|
12
13
|
type ExpandableNode = Node & {
|
|
13
14
|
[key: string]: any;
|
|
14
15
|
};
|
|
16
|
+
declare const $ELEMENT: unique symbol;
|
|
17
|
+
export type HyperElement = {
|
|
18
|
+
(): ExpandableNode | ExpandableNode[];
|
|
19
|
+
[$ELEMENT]: true;
|
|
20
|
+
};
|
|
15
21
|
export type HyperScript = {
|
|
16
|
-
(...args: any[]):
|
|
22
|
+
(...args: any[]): HyperElement | ExpandableNode[];
|
|
17
23
|
Fragment: (props: {
|
|
18
|
-
children:
|
|
19
|
-
}) =>
|
|
24
|
+
children: any;
|
|
25
|
+
}) => any;
|
|
20
26
|
};
|
|
21
27
|
export declare function createHyperScript(r: Runtime): HyperScript;
|
|
22
28
|
export {};
|
|
@@ -5,6 +5,7 @@ interface Runtime {
|
|
|
5
5
|
assign(node: Element, props: any, skipChildren?: Boolean): void;
|
|
6
6
|
createComponent(Comp: (props: any) => any, props: any): any;
|
|
7
7
|
dynamicProperty(props: any, key: string): any;
|
|
8
|
+
untrack<T>(fn: () => T): T;
|
|
8
9
|
SVGElements: Set<string>;
|
|
9
10
|
MathMLElements: Set<string>;
|
|
10
11
|
Namespaces: Record<string, string>;
|
|
@@ -12,11 +13,16 @@ interface Runtime {
|
|
|
12
13
|
type ExpandableNode = Node & {
|
|
13
14
|
[key: string]: any;
|
|
14
15
|
};
|
|
16
|
+
declare const $ELEMENT: unique symbol;
|
|
17
|
+
export type HyperElement = {
|
|
18
|
+
(): ExpandableNode | ExpandableNode[];
|
|
19
|
+
[$ELEMENT]: true;
|
|
20
|
+
};
|
|
15
21
|
export type HyperScript = {
|
|
16
|
-
(...args: any[]):
|
|
22
|
+
(...args: any[]): HyperElement | ExpandableNode[];
|
|
17
23
|
Fragment: (props: {
|
|
18
|
-
children:
|
|
19
|
-
}) =>
|
|
24
|
+
children: any;
|
|
25
|
+
}) => any;
|
|
20
26
|
};
|
|
21
27
|
export declare function createHyperScript(r: Runtime): HyperScript;
|
|
22
28
|
export {};
|