solid-js 1.1.6-beta.1 → 1.2.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 +2 -4
- package/dist/dev.cjs +12 -4
- package/dist/dev.js +12 -4
- package/dist/solid.cjs +12 -4
- package/dist/solid.js +12 -4
- package/h/README.md +99 -0
- package/html/README.md +84 -0
- package/html/dist/html.cjs +24 -6
- package/html/dist/html.js +25 -7
- package/package.json +14 -2
- package/store/README.md +23 -0
- package/types/jsx.d.ts +3 -2
- package/types/reactive/signal.d.ts +3 -3
- package/types/render/component.d.ts +1 -1
- package/universal/README.md +102 -0
- package/universal/dist/dev.cjs +258 -0
- package/universal/dist/dev.js +254 -0
- package/universal/dist/universal.cjs +258 -0
- package/universal/dist/universal.js +254 -0
- package/universal/package.json +8 -0
- package/universal/types/index.d.ts +2 -0
- package/universal/types/universal.d.ts +29 -0
- package/web/README.md +7 -0
- package/web/types/client.d.ts +1 -1
package/README.md
CHANGED
|
@@ -115,11 +115,9 @@ For TypeScript remember to set your TSConfig to handle Solid's JSX by:
|
|
|
115
115
|
## Documentation
|
|
116
116
|
|
|
117
117
|
Check out the [Documentation](https://www.solidjs.com/guide) website.
|
|
118
|
-
### Resources
|
|
119
118
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
- [Projects](https://github.com/solidjs/solid/blob/main/documentation/resources/projects.md)
|
|
119
|
+
[Examples](https://github.com/solidjs/solid/blob/main/documentation/resources/examples.md)
|
|
120
|
+
|
|
123
121
|
## Browser Support
|
|
124
122
|
|
|
125
123
|
The last 2 versions of modern evergreen browsers and Node LTS.
|
package/dist/dev.cjs
CHANGED
|
@@ -230,7 +230,7 @@ function createResource(source, fetcher, options) {
|
|
|
230
230
|
source = true;
|
|
231
231
|
}
|
|
232
232
|
const contexts = new Set(),
|
|
233
|
-
[s, set] = createSignal(options
|
|
233
|
+
[s, set] = createSignal((options || {}).initialValue),
|
|
234
234
|
[track, trigger] = createSignal(undefined, {
|
|
235
235
|
equals: false
|
|
236
236
|
}),
|
|
@@ -455,6 +455,11 @@ function enableScheduling(scheduler = requestCallback) {
|
|
|
455
455
|
Scheduler = scheduler;
|
|
456
456
|
}
|
|
457
457
|
function startTransition(fn, cb) {
|
|
458
|
+
if (Transition && Transition.running) {
|
|
459
|
+
fn();
|
|
460
|
+
cb && Transition.cb.push(cb);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
458
463
|
queueMicrotask(() => {
|
|
459
464
|
if (Scheduler || SuspenseContext) {
|
|
460
465
|
Transition || (Transition = {
|
|
@@ -1166,23 +1171,26 @@ const propTraps = {
|
|
|
1166
1171
|
return _.keys();
|
|
1167
1172
|
}
|
|
1168
1173
|
};
|
|
1174
|
+
function resolveSource(s) {
|
|
1175
|
+
return typeof s === "function" ? s() : s;
|
|
1176
|
+
}
|
|
1169
1177
|
function mergeProps(...sources) {
|
|
1170
1178
|
return new Proxy({
|
|
1171
1179
|
get(property) {
|
|
1172
1180
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1173
|
-
const v = sources[i][property];
|
|
1181
|
+
const v = resolveSource(sources[i])[property];
|
|
1174
1182
|
if (v !== undefined) return v;
|
|
1175
1183
|
}
|
|
1176
1184
|
},
|
|
1177
1185
|
has(property) {
|
|
1178
1186
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1179
|
-
if (property in sources[i]) return true;
|
|
1187
|
+
if (property in resolveSource(sources[i])) return true;
|
|
1180
1188
|
}
|
|
1181
1189
|
return false;
|
|
1182
1190
|
},
|
|
1183
1191
|
keys() {
|
|
1184
1192
|
const keys = [];
|
|
1185
|
-
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(sources[i]));
|
|
1193
|
+
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i])));
|
|
1186
1194
|
return [...new Set(keys)];
|
|
1187
1195
|
}
|
|
1188
1196
|
}, propTraps);
|
package/dist/dev.js
CHANGED
|
@@ -226,7 +226,7 @@ function createResource(source, fetcher, options) {
|
|
|
226
226
|
source = true;
|
|
227
227
|
}
|
|
228
228
|
const contexts = new Set(),
|
|
229
|
-
[s, set] = createSignal(options
|
|
229
|
+
[s, set] = createSignal((options || {}).initialValue),
|
|
230
230
|
[track, trigger] = createSignal(undefined, {
|
|
231
231
|
equals: false
|
|
232
232
|
}),
|
|
@@ -451,6 +451,11 @@ function enableScheduling(scheduler = requestCallback) {
|
|
|
451
451
|
Scheduler = scheduler;
|
|
452
452
|
}
|
|
453
453
|
function startTransition(fn, cb) {
|
|
454
|
+
if (Transition && Transition.running) {
|
|
455
|
+
fn();
|
|
456
|
+
cb && Transition.cb.push(cb);
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
454
459
|
queueMicrotask(() => {
|
|
455
460
|
if (Scheduler || SuspenseContext) {
|
|
456
461
|
Transition || (Transition = {
|
|
@@ -1162,23 +1167,26 @@ const propTraps = {
|
|
|
1162
1167
|
return _.keys();
|
|
1163
1168
|
}
|
|
1164
1169
|
};
|
|
1170
|
+
function resolveSource(s) {
|
|
1171
|
+
return typeof s === "function" ? s() : s;
|
|
1172
|
+
}
|
|
1165
1173
|
function mergeProps(...sources) {
|
|
1166
1174
|
return new Proxy({
|
|
1167
1175
|
get(property) {
|
|
1168
1176
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1169
|
-
const v = sources[i][property];
|
|
1177
|
+
const v = resolveSource(sources[i])[property];
|
|
1170
1178
|
if (v !== undefined) return v;
|
|
1171
1179
|
}
|
|
1172
1180
|
},
|
|
1173
1181
|
has(property) {
|
|
1174
1182
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1175
|
-
if (property in sources[i]) return true;
|
|
1183
|
+
if (property in resolveSource(sources[i])) return true;
|
|
1176
1184
|
}
|
|
1177
1185
|
return false;
|
|
1178
1186
|
},
|
|
1179
1187
|
keys() {
|
|
1180
1188
|
const keys = [];
|
|
1181
|
-
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(sources[i]));
|
|
1189
|
+
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i])));
|
|
1182
1190
|
return [...new Set(keys)];
|
|
1183
1191
|
}
|
|
1184
1192
|
}, propTraps);
|
package/dist/solid.cjs
CHANGED
|
@@ -227,7 +227,7 @@ function createResource(source, fetcher, options) {
|
|
|
227
227
|
source = true;
|
|
228
228
|
}
|
|
229
229
|
const contexts = new Set(),
|
|
230
|
-
[s, set] = createSignal(options
|
|
230
|
+
[s, set] = createSignal((options || {}).initialValue),
|
|
231
231
|
[track, trigger] = createSignal(undefined, {
|
|
232
232
|
equals: false
|
|
233
233
|
}),
|
|
@@ -452,6 +452,11 @@ function enableScheduling(scheduler = requestCallback) {
|
|
|
452
452
|
Scheduler = scheduler;
|
|
453
453
|
}
|
|
454
454
|
function startTransition(fn, cb) {
|
|
455
|
+
if (Transition && Transition.running) {
|
|
456
|
+
fn();
|
|
457
|
+
cb && Transition.cb.push(cb);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
455
460
|
queueMicrotask(() => {
|
|
456
461
|
if (Scheduler || SuspenseContext) {
|
|
457
462
|
Transition || (Transition = {
|
|
@@ -1090,23 +1095,26 @@ const propTraps = {
|
|
|
1090
1095
|
return _.keys();
|
|
1091
1096
|
}
|
|
1092
1097
|
};
|
|
1098
|
+
function resolveSource(s) {
|
|
1099
|
+
return typeof s === "function" ? s() : s;
|
|
1100
|
+
}
|
|
1093
1101
|
function mergeProps(...sources) {
|
|
1094
1102
|
return new Proxy({
|
|
1095
1103
|
get(property) {
|
|
1096
1104
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1097
|
-
const v = sources[i][property];
|
|
1105
|
+
const v = resolveSource(sources[i])[property];
|
|
1098
1106
|
if (v !== undefined) return v;
|
|
1099
1107
|
}
|
|
1100
1108
|
},
|
|
1101
1109
|
has(property) {
|
|
1102
1110
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1103
|
-
if (property in sources[i]) return true;
|
|
1111
|
+
if (property in resolveSource(sources[i])) return true;
|
|
1104
1112
|
}
|
|
1105
1113
|
return false;
|
|
1106
1114
|
},
|
|
1107
1115
|
keys() {
|
|
1108
1116
|
const keys = [];
|
|
1109
|
-
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(sources[i]));
|
|
1117
|
+
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i])));
|
|
1110
1118
|
return [...new Set(keys)];
|
|
1111
1119
|
}
|
|
1112
1120
|
}, propTraps);
|
package/dist/solid.js
CHANGED
|
@@ -223,7 +223,7 @@ function createResource(source, fetcher, options) {
|
|
|
223
223
|
source = true;
|
|
224
224
|
}
|
|
225
225
|
const contexts = new Set(),
|
|
226
|
-
[s, set] = createSignal(options
|
|
226
|
+
[s, set] = createSignal((options || {}).initialValue),
|
|
227
227
|
[track, trigger] = createSignal(undefined, {
|
|
228
228
|
equals: false
|
|
229
229
|
}),
|
|
@@ -448,6 +448,11 @@ function enableScheduling(scheduler = requestCallback) {
|
|
|
448
448
|
Scheduler = scheduler;
|
|
449
449
|
}
|
|
450
450
|
function startTransition(fn, cb) {
|
|
451
|
+
if (Transition && Transition.running) {
|
|
452
|
+
fn();
|
|
453
|
+
cb && Transition.cb.push(cb);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
451
456
|
queueMicrotask(() => {
|
|
452
457
|
if (Scheduler || SuspenseContext) {
|
|
453
458
|
Transition || (Transition = {
|
|
@@ -1086,23 +1091,26 @@ const propTraps = {
|
|
|
1086
1091
|
return _.keys();
|
|
1087
1092
|
}
|
|
1088
1093
|
};
|
|
1094
|
+
function resolveSource(s) {
|
|
1095
|
+
return typeof s === "function" ? s() : s;
|
|
1096
|
+
}
|
|
1089
1097
|
function mergeProps(...sources) {
|
|
1090
1098
|
return new Proxy({
|
|
1091
1099
|
get(property) {
|
|
1092
1100
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1093
|
-
const v = sources[i][property];
|
|
1101
|
+
const v = resolveSource(sources[i])[property];
|
|
1094
1102
|
if (v !== undefined) return v;
|
|
1095
1103
|
}
|
|
1096
1104
|
},
|
|
1097
1105
|
has(property) {
|
|
1098
1106
|
for (let i = sources.length - 1; i >= 0; i--) {
|
|
1099
|
-
if (property in sources[i]) return true;
|
|
1107
|
+
if (property in resolveSource(sources[i])) return true;
|
|
1100
1108
|
}
|
|
1101
1109
|
return false;
|
|
1102
1110
|
},
|
|
1103
1111
|
keys() {
|
|
1104
1112
|
const keys = [];
|
|
1105
|
-
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(sources[i]));
|
|
1113
|
+
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i])));
|
|
1106
1114
|
return [...new Set(keys)];
|
|
1107
1115
|
}
|
|
1108
1116
|
}, propTraps);
|
package/h/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Solid HyperScript
|
|
2
|
+
|
|
3
|
+
This sub module provides a HyperScript method for Solid. This is useful to use Solid in non-compiled environments or in some environments where you can only use a standard JSX transform. This method can be used as the JSX factory function.
|
|
4
|
+
|
|
5
|
+
HyperScript function takes a few forms. The 2nd props argument is optional. Children may be passed as either an array to the 2nd/3rd argument or as every argument past the 2nd.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
// create an element with a title attribute
|
|
9
|
+
h("button", { title: "My button" }, "Click Me")
|
|
10
|
+
|
|
11
|
+
// create a component with a title prop
|
|
12
|
+
h(Button, { title: "My button" }, "Click Me")
|
|
13
|
+
|
|
14
|
+
// create an element with many children
|
|
15
|
+
h("div", { title: "My button" }, h("span", "1"), h("span", "2"), h("span", "3"))
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This is the least efficient way to use Solid as it requires a slightly larger runtime that isn't treeshakebable, 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
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { render } from "solid-js/web";
|
|
24
|
+
import h from "solid-js/h";
|
|
25
|
+
import { createSignal } from "solid-js";
|
|
26
|
+
|
|
27
|
+
function Button(props) {
|
|
28
|
+
return h("button.btn-primary", props)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Counter() {
|
|
32
|
+
const [count, setCount] = createSignal(0);
|
|
33
|
+
const increment = (e) => setCount(c => c + 1);
|
|
34
|
+
|
|
35
|
+
return h(Button, { type: "button", onClick: increment }, count);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
render(Counter, document.getElementById("app"));
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Differences from JSX
|
|
42
|
+
|
|
43
|
+
There are a few differences from Solid's JSX that are important to note. And also apply when attempting use any transformation that would compile to HyperScript.
|
|
44
|
+
|
|
45
|
+
1. Reactive expression must be manually wrapped in functions to be reactive.
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
// jsx
|
|
49
|
+
<div id={props.id}>{firstName() + lastName()}</div>
|
|
50
|
+
|
|
51
|
+
// hyperscript
|
|
52
|
+
h("div", { id: () => props.id }, () => firstName() + lastName())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. Merging spreads requires using the merge props helper to keep reactivity
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
// jsx
|
|
59
|
+
<div class={selectedClass()} {...props} />
|
|
60
|
+
|
|
61
|
+
// hyperscript
|
|
62
|
+
import { mergeProps } from "solid-js"
|
|
63
|
+
|
|
64
|
+
h("div", mergeProps({ class: selectedClass }, props))
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. Events on components require explicit event in the arguments
|
|
68
|
+
|
|
69
|
+
Solid's HyperScript automatically wraps functions passed to props of components with no arguments in getters so you need to provide one to prevent this. The same applies to render props like in the `<For>` component.
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
// good
|
|
73
|
+
h(Button, { onClick: (e) => console.log("Hi")});
|
|
74
|
+
|
|
75
|
+
// bad
|
|
76
|
+
h(Button, { onClick: () => console.log("Hi")})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
4. All refs are callback form
|
|
80
|
+
|
|
81
|
+
We can't do the compiled assigment trick so only the callback form is supported.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
let myEl;
|
|
85
|
+
|
|
86
|
+
h(div, { ref: (el) => myEl = el });
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
5. There is a shorthand for static id and classes
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
h("div#some-id.my-class")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
6. Fragments are just arrays
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
[h("span", "1"), h("span", "2")]
|
|
99
|
+
```
|
package/html/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Solid Tagged Template Literals
|
|
2
|
+
|
|
3
|
+
This sub module provides a Tagged Template Literal `html` method for Solid. This is useful to use Solid in non-compiled environments. This method can be used as replacement for JSX.
|
|
4
|
+
|
|
5
|
+
`html` uses `${}` to escape into JavaScript expressions. Components are closed with `<//>`
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
// create an element with a title attribute
|
|
9
|
+
html`<button title="My button">Click Me</button>`
|
|
10
|
+
|
|
11
|
+
// create a component with a title prop
|
|
12
|
+
html`<${Button} title="My button">Click me<//>`
|
|
13
|
+
|
|
14
|
+
// create an element with dynamic attribute and spread
|
|
15
|
+
html`<div title=${() => selectedClass()} ...${props} />`
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Using `html` is slightly less efficient than JSX(but more than HyperScript), requires a larger runtime that isn't treeshakebable, and cannot leverage expression analysis, so it requires manual wrapping of expressions and has a few other caveats (see below).
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { render } from "solid-js/web";
|
|
24
|
+
import html from "solid-js/html";
|
|
25
|
+
import { createSignal } from "solid-js";
|
|
26
|
+
|
|
27
|
+
function Button(props) {
|
|
28
|
+
return html`<button class="btn-primary" ...${props} />`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Counter() {
|
|
32
|
+
const [count, setCount] = createSignal(0);
|
|
33
|
+
const increment = (e) => setCount((c) => c + 1);
|
|
34
|
+
|
|
35
|
+
return html`<${Button} type="button" onClick=${increment}>${count}<//>`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
render(Counter, document.getElementById("app"));
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Differences from JSX
|
|
42
|
+
|
|
43
|
+
There are a few differences from Solid's JSX that are important to note.
|
|
44
|
+
|
|
45
|
+
1. Reactive expression must be manually wrapped in functions to be reactive.
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
// jsx
|
|
49
|
+
<div id={props.id}>{firstName() + lastName()}</div>
|
|
50
|
+
|
|
51
|
+
// hyperscript
|
|
52
|
+
html`<div id=${() => props.id}>${() => firstName() + lastName()}</div>`
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. Events on components require explicit event in the arguments
|
|
56
|
+
|
|
57
|
+
Solid's Tagged Template Literals automatically wraps functions passed to props of components with no arguments in getters so you need to provide one to prevent this. The same applies to render props like in the `<For>` component.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
// good
|
|
61
|
+
html`<${Button} onClick=${(e) => console.log("Hi")} />`;
|
|
62
|
+
|
|
63
|
+
// bad
|
|
64
|
+
html`<${Button} onClick=${() => console.log("Hi")} />`;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
4. All refs are callback form
|
|
68
|
+
|
|
69
|
+
We can't do the compiled assigment trick so only the callback form is supported.
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
let myEl;
|
|
73
|
+
html`<div ref=${(el) => myEl = el} />`;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
5. There can be multiple top level elements
|
|
77
|
+
|
|
78
|
+
No need for fragments just:
|
|
79
|
+
```js
|
|
80
|
+
html`
|
|
81
|
+
<div>1</div>
|
|
82
|
+
<div>2</div>
|
|
83
|
+
`
|
|
84
|
+
```
|
package/html/dist/html.cjs
CHANGED
|
@@ -213,7 +213,7 @@ function createHTML(r, {
|
|
|
213
213
|
markup = markup + statics[i] + "<!--#-->";
|
|
214
214
|
}
|
|
215
215
|
markup = markup + statics[i];
|
|
216
|
-
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
216
|
+
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(/\.\.\.(<!--#-->)/g, "###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
217
217
|
const [html, code] = parseTemplate(parse(markup)),
|
|
218
218
|
templates = [];
|
|
219
219
|
for (let i = 0; i < html.length; i++) {
|
|
@@ -323,16 +323,29 @@ function createHTML(r, {
|
|
|
323
323
|
options.counter = childOptions.counter;
|
|
324
324
|
options.templateId = childOptions.templateId;
|
|
325
325
|
}
|
|
326
|
+
function processComponentProps(propGroups) {
|
|
327
|
+
let result = [];
|
|
328
|
+
for (const props of propGroups) {
|
|
329
|
+
if (Array.isArray(props)) {
|
|
330
|
+
if (!props.length) continue;
|
|
331
|
+
result.push(`r.wrapProps({${props.join(",") || ""}})`);
|
|
332
|
+
} else result.push(props);
|
|
333
|
+
}
|
|
334
|
+
return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
|
|
335
|
+
}
|
|
326
336
|
function processComponent(node, options) {
|
|
337
|
+
let props = [];
|
|
327
338
|
const keys = Object.keys(node.attrs),
|
|
328
|
-
|
|
339
|
+
propGroups = [props],
|
|
329
340
|
componentIdentifier = options.counter++;
|
|
330
341
|
for (let i = 0; i < keys.length; i++) {
|
|
331
342
|
const name = keys[i],
|
|
332
343
|
value = node.attrs[name];
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
344
|
+
if (name === "###") {
|
|
345
|
+
propGroups.push(`exprs[${options.counter++}]`);
|
|
346
|
+
propGroups.push(props = []);
|
|
347
|
+
} else if (value === "###") {
|
|
348
|
+
props.push(`${name}: exprs[${options.counter++}]`);
|
|
336
349
|
} else props.push(`${name}: "${value}"`);
|
|
337
350
|
}
|
|
338
351
|
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
|
|
@@ -357,7 +370,7 @@ function createHTML(r, {
|
|
|
357
370
|
tag = `_$el${uuid++}`;
|
|
358
371
|
options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
359
372
|
}
|
|
360
|
-
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}]
|
|
373
|
+
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`);
|
|
361
374
|
options.path = tag;
|
|
362
375
|
options.first = false;
|
|
363
376
|
}
|
|
@@ -410,6 +423,9 @@ function createHTML(r, {
|
|
|
410
423
|
if (value === "###") {
|
|
411
424
|
delete node.attrs[name];
|
|
412
425
|
parseAttribute(tag, name, isSVG, isCE, options);
|
|
426
|
+
} else if (name === "###") {
|
|
427
|
+
delete node.attrs[name];
|
|
428
|
+
options.exprs.push(`r.spread(${tag},exprs[${options.counter++}],${isSVG},${!!node.children.length})`);
|
|
413
429
|
}
|
|
414
430
|
}
|
|
415
431
|
options.path = tag;
|
|
@@ -470,9 +486,11 @@ var index = createHTML({
|
|
|
470
486
|
effect: web.effect,
|
|
471
487
|
style: web.style,
|
|
472
488
|
insert: web.insert,
|
|
489
|
+
spread: web.spread,
|
|
473
490
|
createComponent: web.createComponent,
|
|
474
491
|
delegateEvents: web.delegateEvents,
|
|
475
492
|
classList: web.classList,
|
|
493
|
+
mergeProps: web.mergeProps,
|
|
476
494
|
dynamicProperty: web.dynamicProperty,
|
|
477
495
|
setAttribute: web.setAttribute,
|
|
478
496
|
setAttributeNS: web.setAttributeNS,
|
package/html/dist/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { effect, style, insert, createComponent, delegateEvents, classList, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, PropAliases, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web';
|
|
1
|
+
import { effect, style, insert, spread, createComponent, delegateEvents, classList, mergeProps, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, PropAliases, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web';
|
|
2
2
|
|
|
3
3
|
var attrRE, lookup, parseTag, pushCommentNode, pushTextNode, tagRE;
|
|
4
4
|
tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
|
|
@@ -211,7 +211,7 @@ function createHTML(r, {
|
|
|
211
211
|
markup = markup + statics[i] + "<!--#-->";
|
|
212
212
|
}
|
|
213
213
|
markup = markup + statics[i];
|
|
214
|
-
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
214
|
+
markup = markup.replace(selfClosing, fullClosing).replace(/<(<!--#-->)/g, "<###").replace(/\.\.\.(<!--#-->)/g, "###").replace(attrSeeker, attrReplacer).replace(/>\n+\s*/g, ">").replace(/\n+\s*</g, "<").replace(/\s+</g, " <").replace(/>\s+/g, "> ");
|
|
215
215
|
const [html, code] = parseTemplate(parse(markup)),
|
|
216
216
|
templates = [];
|
|
217
217
|
for (let i = 0; i < html.length; i++) {
|
|
@@ -321,16 +321,29 @@ function createHTML(r, {
|
|
|
321
321
|
options.counter = childOptions.counter;
|
|
322
322
|
options.templateId = childOptions.templateId;
|
|
323
323
|
}
|
|
324
|
+
function processComponentProps(propGroups) {
|
|
325
|
+
let result = [];
|
|
326
|
+
for (const props of propGroups) {
|
|
327
|
+
if (Array.isArray(props)) {
|
|
328
|
+
if (!props.length) continue;
|
|
329
|
+
result.push(`r.wrapProps({${props.join(",") || ""}})`);
|
|
330
|
+
} else result.push(props);
|
|
331
|
+
}
|
|
332
|
+
return result.length > 1 ? `r.mergeProps(${result.join(",")})` : result[0];
|
|
333
|
+
}
|
|
324
334
|
function processComponent(node, options) {
|
|
335
|
+
let props = [];
|
|
325
336
|
const keys = Object.keys(node.attrs),
|
|
326
|
-
|
|
337
|
+
propGroups = [props],
|
|
327
338
|
componentIdentifier = options.counter++;
|
|
328
339
|
for (let i = 0; i < keys.length; i++) {
|
|
329
340
|
const name = keys[i],
|
|
330
341
|
value = node.attrs[name];
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
342
|
+
if (name === "###") {
|
|
343
|
+
propGroups.push(`exprs[${options.counter++}]`);
|
|
344
|
+
propGroups.push(props = []);
|
|
345
|
+
} else if (value === "###") {
|
|
346
|
+
props.push(`${name}: exprs[${options.counter++}]`);
|
|
334
347
|
} else props.push(`${name}: "${value}"`);
|
|
335
348
|
}
|
|
336
349
|
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") {
|
|
@@ -355,7 +368,7 @@ function createHTML(r, {
|
|
|
355
368
|
tag = `_$el${uuid++}`;
|
|
356
369
|
options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
357
370
|
}
|
|
358
|
-
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}]
|
|
371
|
+
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`);
|
|
359
372
|
options.path = tag;
|
|
360
373
|
options.first = false;
|
|
361
374
|
}
|
|
@@ -408,6 +421,9 @@ function createHTML(r, {
|
|
|
408
421
|
if (value === "###") {
|
|
409
422
|
delete node.attrs[name];
|
|
410
423
|
parseAttribute(tag, name, isSVG, isCE, options);
|
|
424
|
+
} else if (name === "###") {
|
|
425
|
+
delete node.attrs[name];
|
|
426
|
+
options.exprs.push(`r.spread(${tag},exprs[${options.counter++}],${isSVG},${!!node.children.length})`);
|
|
411
427
|
}
|
|
412
428
|
}
|
|
413
429
|
options.path = tag;
|
|
@@ -468,9 +484,11 @@ var index = createHTML({
|
|
|
468
484
|
effect,
|
|
469
485
|
style,
|
|
470
486
|
insert,
|
|
487
|
+
spread,
|
|
471
488
|
createComponent,
|
|
472
489
|
delegateEvents,
|
|
473
490
|
classList,
|
|
491
|
+
mergeProps,
|
|
474
492
|
dynamicProperty,
|
|
475
493
|
setAttribute,
|
|
476
494
|
setAttributeNS,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
3
|
"description": "A declarative JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/solidjs/solid#readme",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"h/types",
|
|
30
30
|
"html/dist",
|
|
31
31
|
"html/types",
|
|
32
|
+
"universal/dist",
|
|
33
|
+
"universal/types",
|
|
32
34
|
"types",
|
|
33
35
|
"jsx-runtime.d.ts"
|
|
34
36
|
],
|
|
@@ -84,6 +86,15 @@
|
|
|
84
86
|
"require": "./web/dist/web.cjs"
|
|
85
87
|
},
|
|
86
88
|
"./web/dist/*": "./web/dist/*",
|
|
89
|
+
"./universal": {
|
|
90
|
+
"development": {
|
|
91
|
+
"import": "./universal/dist/dev.js",
|
|
92
|
+
"require": "./universal/dist/dev.cjs"
|
|
93
|
+
},
|
|
94
|
+
"import": "./universal/dist/universal.js",
|
|
95
|
+
"require": "./universal/dist/universal.cjs"
|
|
96
|
+
},
|
|
97
|
+
"./universal/dist/*": "./universal/dist/*",
|
|
87
98
|
"./h": {
|
|
88
99
|
"import": "./h/dist/h.js",
|
|
89
100
|
"require": "./h/dist/h.cjs"
|
|
@@ -106,6 +117,7 @@
|
|
|
106
117
|
"build:types-web": "tsc --project ./web/tsconfig.json && tsconfig-replace-paths --project ./web/tsconfig.types.json",
|
|
107
118
|
"build:types-html": "tsc --project ./html/tsconfig.json",
|
|
108
119
|
"build:types-h": "tsc --project ./h/tsconfig.json",
|
|
120
|
+
"build:types-universal": "tsc --project ./universal/tsconfig.json",
|
|
109
121
|
"bench": "node --allow-natives-syntax bench/bench.cjs",
|
|
110
122
|
"test": "jest && npm run test:types",
|
|
111
123
|
"test:coverage": "jest --coverage && npm run test:types",
|
|
@@ -120,5 +132,5 @@
|
|
|
120
132
|
"compiler",
|
|
121
133
|
"performance"
|
|
122
134
|
],
|
|
123
|
-
"gitHead": "
|
|
135
|
+
"gitHead": "e6bbfa693db53cffd3372ee8bf1c61e3f1d47064"
|
|
124
136
|
}
|
package/store/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Solid Store
|
|
2
|
+
|
|
3
|
+
This submodules contains the means for handling deeps nested reactivity. It provides 2 main primitives `createStore` and `createMutable` which leverage proxies to create dynamic nested reactive structures.
|
|
4
|
+
|
|
5
|
+
This also contains helper methods `produce` and `reconcile` which augment the behavior of the store setter method to allow for localized mutationa and data diffing.
|
|
6
|
+
|
|
7
|
+
For full documentation, check out the [website](https://www.solidjs.com/docs/latest/api).
|
|
8
|
+
|
|
9
|
+
## Example
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { createStore } from "solid-js/store";
|
|
13
|
+
|
|
14
|
+
const [store, setStore] = createStore({
|
|
15
|
+
user: {
|
|
16
|
+
firstName: "John",
|
|
17
|
+
lastName: "Smith"
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// update store.user.firstName
|
|
22
|
+
setStore("user", "firstName", "Will");
|
|
23
|
+
```
|
package/types/jsx.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export namespace JSX {
|
|
|
11
11
|
| Node
|
|
12
12
|
| ArrayElement
|
|
13
13
|
| FunctionElement
|
|
14
|
-
| string
|
|
14
|
+
| (string & {})
|
|
15
15
|
| number
|
|
16
16
|
| boolean
|
|
17
17
|
| null
|
|
@@ -1674,6 +1674,7 @@ export namespace JSX {
|
|
|
1674
1674
|
| "unsafe-url";
|
|
1675
1675
|
type HTMLIframeSandbox =
|
|
1676
1676
|
| "allow-downloads-without-user-activation"
|
|
1677
|
+
| "allow-downloads"
|
|
1677
1678
|
| "allow-forms"
|
|
1678
1679
|
| "allow-modals"
|
|
1679
1680
|
| "allow-orientation-lock"
|
|
@@ -2116,7 +2117,7 @@ export namespace JSX {
|
|
|
2116
2117
|
height?: number | string;
|
|
2117
2118
|
name?: string;
|
|
2118
2119
|
referrerpolicy?: HTMLReferrerPolicy;
|
|
2119
|
-
sandbox?: HTMLIframeSandbox;
|
|
2120
|
+
sandbox?: HTMLIframeSandbox | string;
|
|
2120
2121
|
src?: string;
|
|
2121
2122
|
srcdoc?: string;
|
|
2122
2123
|
width?: number | string;
|