solid-js 1.8.22 → 1.9.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/dist/dev.cjs +7 -6
- package/dist/dev.js +567 -325
- package/dist/server.cjs +1 -1
- package/dist/server.js +169 -75
- package/dist/solid.cjs +7 -6
- package/dist/solid.js +494 -283
- package/h/dist/h.js +40 -9
- package/h/jsx-runtime/dist/jsx.js +1 -1
- package/h/jsx-runtime/types/index.d.ts +13 -10
- package/h/jsx-runtime/types/jsx.d.ts +22 -1
- package/h/types/hyperscript.d.ts +11 -11
- package/h/types/index.d.ts +1 -1
- package/html/dist/html.cjs +4 -2
- package/html/dist/html.js +222 -95
- package/html/types/index.d.ts +1 -1
- package/html/types/lit.d.ts +52 -33
- package/package.json +1 -5
- package/store/dist/dev.cjs +1 -1
- package/store/dist/dev.js +123 -43
- package/store/dist/server.cjs +4 -0
- package/store/dist/server.js +23 -8
- package/store/dist/store.cjs +1 -1
- package/store/dist/store.js +114 -40
- package/store/package.json +0 -4
- package/store/types/index.d.ts +21 -7
- package/store/types/modifiers.d.ts +6 -3
- package/store/types/mutable.d.ts +5 -2
- package/store/types/server.d.ts +26 -5
- package/store/types/store.d.ts +219 -62
- package/types/index.d.ts +75 -10
- package/types/jsx.d.ts +35 -8
- package/types/reactive/array.d.ts +12 -4
- package/types/reactive/observable.d.ts +25 -17
- package/types/reactive/scheduler.d.ts +9 -6
- package/types/reactive/signal.d.ts +236 -143
- package/types/render/Suspense.d.ts +5 -5
- package/types/render/component.d.ts +64 -33
- package/types/render/flow.d.ts +43 -31
- package/types/render/hydration.d.ts +15 -15
- package/types/server/index.d.ts +57 -2
- package/types/server/reactive.d.ts +73 -42
- package/types/server/rendering.d.ts +169 -98
- package/universal/dist/dev.js +28 -12
- package/universal/dist/universal.js +28 -12
- package/universal/types/index.d.ts +3 -1
- package/universal/types/universal.d.ts +0 -1
- package/web/dist/dev.cjs +57 -24
- package/web/dist/dev.js +679 -101
- package/web/dist/server.cjs +96 -15
- package/web/dist/server.js +676 -105
- package/web/dist/web.cjs +53 -23
- package/web/dist/web.js +664 -99
- package/web/package.json +0 -4
- package/web/storage/dist/storage.js +3 -3
- package/web/types/client.d.ts +5 -3
- package/web/types/core.d.ts +10 -1
- package/web/types/index.d.ts +27 -10
- package/web/types/server-mock.d.ts +47 -32
- package/web/types/server.d.ts +88 -0
package/html/dist/html.js
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
effect,
|
|
3
|
+
style,
|
|
4
|
+
insert,
|
|
5
|
+
untrack,
|
|
6
|
+
spread,
|
|
7
|
+
createComponent,
|
|
8
|
+
delegateEvents,
|
|
9
|
+
classList,
|
|
10
|
+
mergeProps,
|
|
11
|
+
dynamicProperty,
|
|
12
|
+
setAttribute,
|
|
13
|
+
setAttributeNS,
|
|
14
|
+
addEventListener,
|
|
15
|
+
Aliases,
|
|
16
|
+
getPropAlias,
|
|
17
|
+
Properties,
|
|
18
|
+
ChildProperties,
|
|
19
|
+
DelegatedEvents,
|
|
20
|
+
SVGElements,
|
|
21
|
+
SVGNamespace
|
|
22
|
+
} from "solid-js/web";
|
|
2
23
|
|
|
3
24
|
const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
|
|
4
|
-
const attrRE =
|
|
25
|
+
const attrRE =
|
|
26
|
+
/(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g;
|
|
5
27
|
const lookup = {
|
|
6
28
|
area: true,
|
|
7
29
|
base: true,
|
|
@@ -20,10 +42,10 @@ const lookup = {
|
|
|
20
42
|
track: true,
|
|
21
43
|
wbr: true
|
|
22
44
|
};
|
|
23
|
-
function parseTag(
|
|
45
|
+
function parseTag(tag) {
|
|
24
46
|
const res = {
|
|
25
|
-
type:
|
|
26
|
-
name:
|
|
47
|
+
type: "tag",
|
|
48
|
+
name: "",
|
|
27
49
|
voidElement: false,
|
|
28
50
|
attrs: [],
|
|
29
51
|
children: []
|
|
@@ -31,50 +53,50 @@ function parseTag( tag) {
|
|
|
31
53
|
const tagMatch = tag.match(/<\/?([^\s]+?)[/\s>]/);
|
|
32
54
|
if (tagMatch) {
|
|
33
55
|
res.name = tagMatch[1];
|
|
34
|
-
if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) ===
|
|
56
|
+
if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === "/") {
|
|
35
57
|
res.voidElement = true;
|
|
36
58
|
}
|
|
37
|
-
if (res.name.startsWith(
|
|
38
|
-
const endIndex = tag.indexOf(
|
|
59
|
+
if (res.name.startsWith("!--")) {
|
|
60
|
+
const endIndex = tag.indexOf("-->");
|
|
39
61
|
return {
|
|
40
|
-
type:
|
|
41
|
-
comment: endIndex !== -1 ? tag.slice(4, endIndex) :
|
|
62
|
+
type: "comment",
|
|
63
|
+
comment: endIndex !== -1 ? tag.slice(4, endIndex) : ""
|
|
42
64
|
};
|
|
43
65
|
}
|
|
44
66
|
}
|
|
45
67
|
const reg = new RegExp(attrRE);
|
|
46
68
|
for (const match of tag.matchAll(reg)) {
|
|
47
|
-
if ((match[1] || match[2]).startsWith(
|
|
69
|
+
if ((match[1] || match[2]).startsWith("use:")) {
|
|
48
70
|
res.attrs.push({
|
|
49
|
-
type:
|
|
71
|
+
type: "directive",
|
|
50
72
|
name: match[1] || match[2],
|
|
51
|
-
value: match[4] || match[5] ||
|
|
73
|
+
value: match[4] || match[5] || ""
|
|
52
74
|
});
|
|
53
75
|
} else {
|
|
54
76
|
res.attrs.push({
|
|
55
|
-
type:
|
|
77
|
+
type: "attr",
|
|
56
78
|
name: match[1] || match[2],
|
|
57
|
-
value: match[4] || match[5] ||
|
|
79
|
+
value: match[4] || match[5] || ""
|
|
58
80
|
});
|
|
59
81
|
}
|
|
60
82
|
}
|
|
61
83
|
return res;
|
|
62
84
|
}
|
|
63
85
|
function pushTextNode(list, html, start) {
|
|
64
|
-
const end = html.indexOf(
|
|
86
|
+
const end = html.indexOf("<", start);
|
|
65
87
|
const content = html.slice(start, end === -1 ? void 0 : end);
|
|
66
88
|
if (!/^\s*$/.test(content)) {
|
|
67
89
|
list.push({
|
|
68
|
-
type:
|
|
90
|
+
type: "text",
|
|
69
91
|
content: content
|
|
70
92
|
});
|
|
71
93
|
}
|
|
72
94
|
}
|
|
73
95
|
function pushCommentNode(list, tag) {
|
|
74
|
-
const content = tag.replace(
|
|
96
|
+
const content = tag.replace("<!--", "").replace("-->", "");
|
|
75
97
|
if (!/^\s*$/.test(content)) {
|
|
76
98
|
list.push({
|
|
77
|
-
type:
|
|
99
|
+
type: "comment",
|
|
78
100
|
content: content
|
|
79
101
|
});
|
|
80
102
|
}
|
|
@@ -86,15 +108,15 @@ function parse(html) {
|
|
|
86
108
|
const arr = [];
|
|
87
109
|
const byTag = {};
|
|
88
110
|
html.replace(tagRE, (tag, index) => {
|
|
89
|
-
const isOpen = tag.charAt(1) !==
|
|
90
|
-
const isComment = tag.slice(0, 4) ===
|
|
111
|
+
const isOpen = tag.charAt(1) !== "/";
|
|
112
|
+
const isComment = tag.slice(0, 4) === "<!--";
|
|
91
113
|
const start = index + tag.length;
|
|
92
114
|
const nextChar = html.charAt(start);
|
|
93
115
|
let parent = void 0;
|
|
94
116
|
if (isOpen && !isComment) {
|
|
95
117
|
level++;
|
|
96
118
|
current = parseTag(tag);
|
|
97
|
-
if (!current.voidElement && nextChar && nextChar !==
|
|
119
|
+
if (!current.voidElement && nextChar && nextChar !== "<") {
|
|
98
120
|
pushTextNode(current.children, html, start);
|
|
99
121
|
}
|
|
100
122
|
byTag[current.tagName] = current;
|
|
@@ -118,7 +140,7 @@ function parse(html) {
|
|
|
118
140
|
if (!isComment) {
|
|
119
141
|
level--;
|
|
120
142
|
}
|
|
121
|
-
if (nextChar !==
|
|
143
|
+
if (nextChar !== "<" && nextChar) {
|
|
122
144
|
parent = level === -1 ? result : arr[level].children;
|
|
123
145
|
pushTextNode(parent, html, start);
|
|
124
146
|
}
|
|
@@ -129,41 +151,47 @@ function parse(html) {
|
|
|
129
151
|
function attrString(attrs) {
|
|
130
152
|
const buff = [];
|
|
131
153
|
for (const attr of attrs) {
|
|
132
|
-
buff.push(attr.name + '="' + attr.value.replace(/"/g,
|
|
154
|
+
buff.push(attr.name + '="' + attr.value.replace(/"/g, """) + '"');
|
|
133
155
|
}
|
|
134
156
|
if (!buff.length) {
|
|
135
|
-
return
|
|
157
|
+
return "";
|
|
136
158
|
}
|
|
137
|
-
return
|
|
159
|
+
return " " + buff.join(" ");
|
|
138
160
|
}
|
|
139
161
|
function stringifier(buff, doc) {
|
|
140
162
|
switch (doc.type) {
|
|
141
|
-
case
|
|
163
|
+
case "text":
|
|
142
164
|
return buff + doc.content;
|
|
143
|
-
case
|
|
144
|
-
buff +=
|
|
165
|
+
case "tag":
|
|
166
|
+
buff +=
|
|
167
|
+
"<" + doc.name + (doc.attrs ? attrString(doc.attrs) : "") + (doc.voidElement ? "/>" : ">");
|
|
145
168
|
if (doc.voidElement) {
|
|
146
169
|
return buff;
|
|
147
170
|
}
|
|
148
|
-
return buff + doc.children.reduce(stringifier,
|
|
149
|
-
case
|
|
150
|
-
return buff +=
|
|
171
|
+
return buff + doc.children.reduce(stringifier, "") + "</" + doc.name + ">";
|
|
172
|
+
case "comment":
|
|
173
|
+
return (buff += "<!--" + doc.content + "-->");
|
|
151
174
|
}
|
|
152
175
|
}
|
|
153
176
|
function stringify(doc) {
|
|
154
177
|
return doc.reduce(function (token, rootEl) {
|
|
155
|
-
return token + stringifier(
|
|
156
|
-
},
|
|
178
|
+
return token + stringifier("", rootEl);
|
|
179
|
+
}, "");
|
|
157
180
|
}
|
|
158
181
|
const cache = new Map();
|
|
159
|
-
const VOID_ELEMENTS =
|
|
182
|
+
const VOID_ELEMENTS =
|
|
183
|
+
/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
|
|
160
184
|
const spaces = " \\f\\n\\r\\t";
|
|
161
185
|
const almostEverything = "[^" + spaces + "\\/>\"'=]+";
|
|
162
|
-
const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything +
|
|
186
|
+
const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ")";
|
|
163
187
|
const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:";
|
|
164
|
-
const attrPartials =
|
|
188
|
+
const attrPartials =
|
|
189
|
+
"(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)";
|
|
165
190
|
const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g");
|
|
166
|
-
const findAttributes = new RegExp(
|
|
191
|
+
const findAttributes = new RegExp(
|
|
192
|
+
"(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])",
|
|
193
|
+
"gi"
|
|
194
|
+
);
|
|
167
195
|
const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g");
|
|
168
196
|
const marker = "<!--#-->";
|
|
169
197
|
const reservedNameSpaces = new Set(["class", "on", "oncapture", "style", "use", "prop", "attr"]);
|
|
@@ -171,7 +199,10 @@ function attrReplacer($0, $1, $2, $3) {
|
|
|
171
199
|
return "<" + $1 + $2.replace(findAttributes, replaceAttributes) + $3;
|
|
172
200
|
}
|
|
173
201
|
function replaceAttributes($0, $1, $2) {
|
|
174
|
-
return
|
|
202
|
+
return (
|
|
203
|
+
$1.replace(/<!--#-->/g, "###") +
|
|
204
|
+
($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"')
|
|
205
|
+
);
|
|
175
206
|
}
|
|
176
207
|
function fullClosing($0, $1, $2) {
|
|
177
208
|
return VOID_ELEMENTS.test($1) ? $0 : "<" + $1 + $2 + "></" + $1 + ">";
|
|
@@ -180,17 +211,19 @@ function toPropertyName(name) {
|
|
|
180
211
|
return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
|
|
181
212
|
}
|
|
182
213
|
function parseDirective(name, value, tag, options) {
|
|
183
|
-
if (name ===
|
|
214
|
+
if (name === "use:###" && value === "###") {
|
|
184
215
|
const count = options.counter++;
|
|
185
|
-
options.exprs.push(
|
|
216
|
+
options.exprs.push(
|
|
217
|
+
`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`
|
|
218
|
+
);
|
|
186
219
|
} else {
|
|
187
220
|
throw new Error(`Not support syntax ${name} must be use:{function}`);
|
|
188
221
|
}
|
|
189
222
|
}
|
|
190
|
-
function createHTML(
|
|
191
|
-
|
|
192
|
-
functionBuilder = (...args) => new Function(...args)
|
|
193
|
-
|
|
223
|
+
function createHTML(
|
|
224
|
+
r,
|
|
225
|
+
{ delegateEvents = true, functionBuilder = (...args) => new Function(...args) } = {}
|
|
226
|
+
) {
|
|
194
227
|
let uuid = 1;
|
|
195
228
|
r.wrapProps = props => {
|
|
196
229
|
const d = Object.getOwnPropertyDescriptors(props);
|
|
@@ -206,7 +239,16 @@ function createHTML(r, {
|
|
|
206
239
|
markup = markup + statics[i] + "<!--#-->";
|
|
207
240
|
}
|
|
208
241
|
markup = markup + statics[i];
|
|
209
|
-
const replaceList = [
|
|
242
|
+
const replaceList = [
|
|
243
|
+
[selfClosing, fullClosing],
|
|
244
|
+
[/<(<!--#-->)/g, "<###"],
|
|
245
|
+
[/\.\.\.(<!--#-->)/g, "###"],
|
|
246
|
+
[attrSeeker, attrReplacer],
|
|
247
|
+
[/>\n+\s*/g, ">"],
|
|
248
|
+
[/\n+\s*</g, "<"],
|
|
249
|
+
[/\s+</g, " <"],
|
|
250
|
+
[/>\s+/g, "> "]
|
|
251
|
+
];
|
|
210
252
|
markup = replaceList.reduce((acc, x) => {
|
|
211
253
|
return acc.replace(x[0], x[1]);
|
|
212
254
|
}, markup);
|
|
@@ -234,7 +276,19 @@ function createHTML(r, {
|
|
|
234
276
|
return templates;
|
|
235
277
|
}
|
|
236
278
|
function parseKeyValue(node, tag, name, value, isSVG, isCE, options) {
|
|
237
|
-
let expr =
|
|
279
|
+
let expr =
|
|
280
|
+
value === "###"
|
|
281
|
+
? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]`
|
|
282
|
+
: value
|
|
283
|
+
.split("###")
|
|
284
|
+
.map((v, i) =>
|
|
285
|
+
i
|
|
286
|
+
? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${
|
|
287
|
+
options.counter
|
|
288
|
+
}]() : exprs[${options.counter++}]) + "${v}"`
|
|
289
|
+
: `"${v}"`
|
|
290
|
+
)
|
|
291
|
+
.join(""),
|
|
238
292
|
parts,
|
|
239
293
|
namespace;
|
|
240
294
|
if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
|
|
@@ -251,12 +305,21 @@ function createHTML(r, {
|
|
|
251
305
|
const prev = `_$v${uuid++}`;
|
|
252
306
|
options.decl.push(`${prev}={}`);
|
|
253
307
|
options.exprs.push(`r.classList(${tag},${expr},${prev})`);
|
|
254
|
-
} else if (
|
|
308
|
+
} else if (
|
|
309
|
+
namespace !== "attr" &&
|
|
310
|
+
(isChildProp ||
|
|
311
|
+
(!isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp)) ||
|
|
312
|
+
isCE ||
|
|
313
|
+
namespace === "prop")
|
|
314
|
+
) {
|
|
255
315
|
if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name);
|
|
256
|
-
options.exprs.push(
|
|
316
|
+
options.exprs.push(
|
|
317
|
+
`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`
|
|
318
|
+
);
|
|
257
319
|
} else {
|
|
258
320
|
const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[name.split(":")[0]];
|
|
259
|
-
if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);
|
|
321
|
+
if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);
|
|
322
|
+
else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`);
|
|
260
323
|
}
|
|
261
324
|
}
|
|
262
325
|
function parseAttribute(node, tag, name, value, isSVG, isCE, options) {
|
|
@@ -264,11 +327,17 @@ function createHTML(r, {
|
|
|
264
327
|
if (!name.includes(":")) {
|
|
265
328
|
const lc = name.slice(2).toLowerCase();
|
|
266
329
|
const delegate = delegateEvents && r.DelegatedEvents.has(lc);
|
|
267
|
-
options.exprs.push(
|
|
330
|
+
options.exprs.push(
|
|
331
|
+
`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`
|
|
332
|
+
);
|
|
268
333
|
delegate && options.delegatedEvents.add(lc);
|
|
269
334
|
} else {
|
|
270
335
|
let capture = name.startsWith("oncapture:");
|
|
271
|
-
options.exprs.push(
|
|
336
|
+
options.exprs.push(
|
|
337
|
+
`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${
|
|
338
|
+
capture ? ",true" : ""
|
|
339
|
+
})`
|
|
340
|
+
);
|
|
272
341
|
}
|
|
273
342
|
} else if (name === "ref") {
|
|
274
343
|
options.exprs.push(`exprs[${options.counter++}](${tag})`);
|
|
@@ -278,9 +347,15 @@ function createHTML(r, {
|
|
|
278
347
|
}),
|
|
279
348
|
count = options.counter;
|
|
280
349
|
parseKeyValue(node, tag, name, value, isSVG, isCE, childOptions);
|
|
281
|
-
options.decl.push(
|
|
350
|
+
options.decl.push(
|
|
351
|
+
`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(
|
|
352
|
+
";\n"
|
|
353
|
+
)};\n}`
|
|
354
|
+
);
|
|
282
355
|
if (value === "###") {
|
|
283
|
-
options.exprs.push(
|
|
356
|
+
options.exprs.push(
|
|
357
|
+
`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`
|
|
358
|
+
);
|
|
284
359
|
} else {
|
|
285
360
|
let check = "";
|
|
286
361
|
for (let i = count; i < childOptions.counter; i++) {
|
|
@@ -302,7 +377,10 @@ function createHTML(r, {
|
|
|
302
377
|
if (node.children.length > 1) {
|
|
303
378
|
for (let i = 0; i < node.children.length; i++) {
|
|
304
379
|
const child = node.children[i];
|
|
305
|
-
if (
|
|
380
|
+
if (
|
|
381
|
+
(child.type === "comment" && child.content === "#") ||
|
|
382
|
+
(child.type === "tag" && child.name === "###")
|
|
383
|
+
) {
|
|
306
384
|
childOptions.multi = true;
|
|
307
385
|
break;
|
|
308
386
|
}
|
|
@@ -323,11 +401,14 @@ function createHTML(r, {
|
|
|
323
401
|
continue;
|
|
324
402
|
}
|
|
325
403
|
parseNode(child, childOptions);
|
|
326
|
-
if (!childOptions.multi && child.type === "comment" && child.content === "#")
|
|
404
|
+
if (!childOptions.multi && child.type === "comment" && child.content === "#")
|
|
405
|
+
node.children.splice(i, 1);
|
|
406
|
+
else i++;
|
|
327
407
|
}
|
|
328
408
|
options.counter = childOptions.counter;
|
|
329
409
|
options.templateId = childOptions.templateId;
|
|
330
410
|
options.hasCustomElement = options.hasCustomElement || childOptions.hasCustomElement;
|
|
411
|
+
options.isImportNode = options.isImportNode || childOptions.isImportNode;
|
|
331
412
|
}
|
|
332
413
|
function processComponentProps(propGroups) {
|
|
333
414
|
let result = [];
|
|
@@ -345,26 +426,28 @@ function createHTML(r, {
|
|
|
345
426
|
propGroups = [props],
|
|
346
427
|
componentIdentifier = options.counter++;
|
|
347
428
|
for (let i = 0; i < keys.length; i++) {
|
|
348
|
-
const {
|
|
349
|
-
|
|
350
|
-
name,
|
|
351
|
-
value
|
|
352
|
-
} = node.attrs[i];
|
|
353
|
-
if (type === 'attr') {
|
|
429
|
+
const { type, name, value } = node.attrs[i];
|
|
430
|
+
if (type === "attr") {
|
|
354
431
|
if (name === "###") {
|
|
355
432
|
propGroups.push(`exprs[${options.counter++}]`);
|
|
356
|
-
propGroups.push(props = []);
|
|
433
|
+
propGroups.push((props = []));
|
|
357
434
|
} else if (value === "###") {
|
|
358
435
|
props.push(`${name}: exprs[${options.counter++}]`);
|
|
359
436
|
} else props.push(`${name}: "${value}"`);
|
|
360
|
-
} else if (type ===
|
|
437
|
+
} else if (type === "directive") {
|
|
361
438
|
const tag = `_$el${uuid++}`;
|
|
362
439
|
const topDecl = !options.decl.length;
|
|
363
|
-
options.decl.push(
|
|
440
|
+
options.decl.push(
|
|
441
|
+
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
|
|
442
|
+
);
|
|
364
443
|
parseDirective(name, value, tag, options);
|
|
365
444
|
}
|
|
366
445
|
}
|
|
367
|
-
if (
|
|
446
|
+
if (
|
|
447
|
+
node.children.length === 1 &&
|
|
448
|
+
node.children[0].type === "comment" &&
|
|
449
|
+
node.children[0].content === "#"
|
|
450
|
+
) {
|
|
368
451
|
props.push(`children: () => exprs[${options.counter++}]`);
|
|
369
452
|
} else if (node.children.length) {
|
|
370
453
|
const children = {
|
|
@@ -387,7 +470,20 @@ function createHTML(r, {
|
|
|
387
470
|
tag = `_$el${uuid++}`;
|
|
388
471
|
options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
389
472
|
}
|
|
390
|
-
if (options.parent)
|
|
473
|
+
if (options.parent)
|
|
474
|
+
options.exprs.push(
|
|
475
|
+
`r.insert(${
|
|
476
|
+
options.parent
|
|
477
|
+
}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${
|
|
478
|
+
tag ? `, ${tag}` : ""
|
|
479
|
+
})`
|
|
480
|
+
);
|
|
481
|
+
else
|
|
482
|
+
options.exprs.push(
|
|
483
|
+
`${
|
|
484
|
+
options.fragment ? "" : "return "
|
|
485
|
+
}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`
|
|
486
|
+
);
|
|
391
487
|
options.path = tag;
|
|
392
488
|
options.first = false;
|
|
393
489
|
}
|
|
@@ -418,13 +514,21 @@ function createHTML(r, {
|
|
|
418
514
|
});
|
|
419
515
|
options.templateNodes.push([child]);
|
|
420
516
|
parseNode(child, childOptions);
|
|
421
|
-
parts.push(
|
|
517
|
+
parts.push(
|
|
518
|
+
`function() { ${
|
|
519
|
+
childOptions.decl.join(",\n") +
|
|
520
|
+
";\n" +
|
|
521
|
+
childOptions.exprs.join(";\n") +
|
|
522
|
+
`;\nreturn _$el${id};\n`
|
|
523
|
+
}}()`
|
|
524
|
+
);
|
|
422
525
|
options.counter = childOptions.counter;
|
|
423
526
|
options.templateId = childOptions.templateId;
|
|
424
527
|
} else if (child.type === "text") {
|
|
425
528
|
parts.push(`"${child.content}"`);
|
|
426
529
|
} else if (child.type === "comment") {
|
|
427
|
-
if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
|
|
530
|
+
if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
|
|
531
|
+
else if (child.content) {
|
|
428
532
|
for (let i = 0; i < child.content.split("###").length - 1; i++) {
|
|
429
533
|
parts.push(`exprs[${options.counter++}]`);
|
|
430
534
|
}
|
|
@@ -436,24 +540,27 @@ function createHTML(r, {
|
|
|
436
540
|
const tag = `_$el${uuid++}`;
|
|
437
541
|
const topDecl = !options.decl.length;
|
|
438
542
|
const templateId = options.templateId;
|
|
439
|
-
options.decl.push(
|
|
543
|
+
options.decl.push(
|
|
544
|
+
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
|
|
545
|
+
);
|
|
440
546
|
const isSVG = r.SVGElements.has(node.name);
|
|
441
|
-
const isCE = node.name.includes("-");
|
|
547
|
+
const isCE = node.name.includes("-") || node.attrs.some(e => e.name === "is");
|
|
442
548
|
options.hasCustomElement = isCE;
|
|
549
|
+
options.isImportNode =
|
|
550
|
+
(node.name === "img" || node.name === "iframe") &&
|
|
551
|
+
node.attrs.some(e => e.name === "loading" && e.value === "lazy");
|
|
443
552
|
if (node.attrs.some(e => e.name === "###")) {
|
|
444
553
|
const spreadArgs = [];
|
|
445
554
|
let current = "";
|
|
446
555
|
const newAttrs = [];
|
|
447
556
|
for (let i = 0; i < node.attrs.length; i++) {
|
|
448
|
-
const {
|
|
449
|
-
|
|
450
|
-
name,
|
|
451
|
-
value
|
|
452
|
-
} = node.attrs[i];
|
|
453
|
-
if (type === 'attr') {
|
|
557
|
+
const { type, name, value } = node.attrs[i];
|
|
558
|
+
if (type === "attr") {
|
|
454
559
|
if (value.includes("###")) {
|
|
455
560
|
let count = options.counter++;
|
|
456
|
-
current += `${name}: ${
|
|
561
|
+
current += `${name}: ${
|
|
562
|
+
name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""
|
|
563
|
+
}exprs[${count}],`;
|
|
457
564
|
} else if (name === "###") {
|
|
458
565
|
if (current.length) {
|
|
459
566
|
spreadArgs.push(`()=>({${current}})`);
|
|
@@ -463,7 +570,7 @@ function createHTML(r, {
|
|
|
463
570
|
} else {
|
|
464
571
|
newAttrs.push(node.attrs[i]);
|
|
465
572
|
}
|
|
466
|
-
} else if (type ===
|
|
573
|
+
} else if (type === "directive") {
|
|
467
574
|
parseDirective(name, value, tag, options);
|
|
468
575
|
}
|
|
469
576
|
}
|
|
@@ -471,15 +578,17 @@ function createHTML(r, {
|
|
|
471
578
|
if (current.length) {
|
|
472
579
|
spreadArgs.push(`()=>({${current}})`);
|
|
473
580
|
}
|
|
474
|
-
options.exprs.push(
|
|
581
|
+
options.exprs.push(
|
|
582
|
+
`r.spread(${tag},${
|
|
583
|
+
spreadArgs.length === 1
|
|
584
|
+
? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}`
|
|
585
|
+
: `r.mergeProps(${spreadArgs.join(",")})`
|
|
586
|
+
},${isSVG},${!!node.children.length})`
|
|
587
|
+
);
|
|
475
588
|
} else {
|
|
476
589
|
for (let i = 0; i < node.attrs.length; i++) {
|
|
477
|
-
const {
|
|
478
|
-
|
|
479
|
-
name,
|
|
480
|
-
value
|
|
481
|
-
} = node.attrs[i];
|
|
482
|
-
if (type === 'directive') {
|
|
590
|
+
const { type, name, value } = node.attrs[i];
|
|
591
|
+
if (type === "directive") {
|
|
483
592
|
parseDirective(name, value, tag, options);
|
|
484
593
|
node.attrs.splice(i, 1);
|
|
485
594
|
i--;
|
|
@@ -496,7 +605,10 @@ function createHTML(r, {
|
|
|
496
605
|
options.first = false;
|
|
497
606
|
processChildren(node, options);
|
|
498
607
|
if (topDecl) {
|
|
499
|
-
options.decl[0] =
|
|
608
|
+
options.decl[0] =
|
|
609
|
+
options.hasCustomElement || options.isImportNode
|
|
610
|
+
? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))`
|
|
611
|
+
: `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
|
|
500
612
|
}
|
|
501
613
|
} else if (node.type === "text") {
|
|
502
614
|
const tag = `_$el${uuid++}`;
|
|
@@ -531,10 +643,12 @@ function createHTML(r, {
|
|
|
531
643
|
origNodes = nodes;
|
|
532
644
|
let toplevel;
|
|
533
645
|
if (nodes.length > 1) {
|
|
534
|
-
nodes = [
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
646
|
+
nodes = [
|
|
647
|
+
{
|
|
648
|
+
type: "fragment",
|
|
649
|
+
children: nodes
|
|
650
|
+
}
|
|
651
|
+
];
|
|
538
652
|
}
|
|
539
653
|
if (nodes[0].name === "###") {
|
|
540
654
|
toplevel = true;
|
|
@@ -542,12 +656,25 @@ function createHTML(r, {
|
|
|
542
656
|
} else parseNode(nodes[0], options);
|
|
543
657
|
r.delegateEvents(Array.from(options.delegatedEvents));
|
|
544
658
|
const templateNodes = [origNodes].concat(options.templateNodes);
|
|
545
|
-
return [
|
|
659
|
+
return [
|
|
660
|
+
templateNodes.map(t => stringify(t)),
|
|
661
|
+
funcBuilder(
|
|
662
|
+
"tmpls",
|
|
663
|
+
"exprs",
|
|
664
|
+
"r",
|
|
665
|
+
options.decl.join(",\n") +
|
|
666
|
+
";\n" +
|
|
667
|
+
options.exprs.join(";\n") +
|
|
668
|
+
(toplevel ? "" : `;\nreturn _$el${id};\n`)
|
|
669
|
+
)
|
|
670
|
+
];
|
|
546
671
|
}
|
|
547
672
|
function html(statics, ...args) {
|
|
548
|
-
const templates =
|
|
549
|
-
|
|
550
|
-
|
|
673
|
+
const templates =
|
|
674
|
+
cache.get(statics) ||
|
|
675
|
+
createTemplate(statics, {
|
|
676
|
+
funcBuilder: functionBuilder
|
|
677
|
+
});
|
|
551
678
|
return templates[0].create(templates, args, r);
|
|
552
679
|
}
|
|
553
680
|
return html;
|
package/html/types/index.d.ts
CHANGED