solid-js 1.8.2 → 1.8.3
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 +1 -1
- package/dist/dev.js +534 -299
- package/dist/server.js +170 -75
- package/dist/solid.cjs +1 -1
- package/dist/solid.js +461 -257
- package/h/dist/h.js +34 -8
- package/h/jsx-runtime/dist/jsx.js +1 -1
- package/h/jsx-runtime/types/index.d.ts +11 -8
- package/h/types/hyperscript.d.ts +11 -11
- package/html/dist/html.js +216 -94
- package/html/types/lit.d.ts +45 -31
- package/package.json +1 -1
- package/store/dist/dev.js +114 -42
- package/store/dist/server.js +19 -8
- package/store/dist/store.js +105 -39
- 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 +12 -4
- package/store/types/store.d.ts +218 -61
- package/types/index.d.ts +72 -9
- 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 +228 -140
- package/types/render/Suspense.d.ts +5 -5
- package/types/render/component.d.ts +62 -31
- package/types/render/flow.d.ts +43 -31
- package/types/render/hydration.d.ts +13 -13
- package/types/server/index.d.ts +57 -2
- package/types/server/reactive.d.ts +73 -42
- package/types/server/rendering.d.ts +166 -95
- 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.js +617 -81
- package/web/dist/server.js +175 -92
- package/web/dist/web.js +611 -80
- package/web/types/client.d.ts +2 -2
- 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/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,7 +401,9 @@ 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;
|
|
@@ -345,26 +425,28 @@ function createHTML(r, {
|
|
|
345
425
|
propGroups = [props],
|
|
346
426
|
componentIdentifier = options.counter++;
|
|
347
427
|
for (let i = 0; i < keys.length; i++) {
|
|
348
|
-
const {
|
|
349
|
-
|
|
350
|
-
name,
|
|
351
|
-
value
|
|
352
|
-
} = node.attrs[i];
|
|
353
|
-
if (type === 'attr') {
|
|
428
|
+
const { type, name, value } = node.attrs[i];
|
|
429
|
+
if (type === "attr") {
|
|
354
430
|
if (name === "###") {
|
|
355
431
|
propGroups.push(`exprs[${options.counter++}]`);
|
|
356
|
-
propGroups.push(props = []);
|
|
432
|
+
propGroups.push((props = []));
|
|
357
433
|
} else if (value === "###") {
|
|
358
434
|
props.push(`${name}: exprs[${options.counter++}]`);
|
|
359
435
|
} else props.push(`${name}: "${value}"`);
|
|
360
|
-
} else if (type ===
|
|
436
|
+
} else if (type === "directive") {
|
|
361
437
|
const tag = `_$el${uuid++}`;
|
|
362
438
|
const topDecl = !options.decl.length;
|
|
363
|
-
options.decl.push(
|
|
439
|
+
options.decl.push(
|
|
440
|
+
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
|
|
441
|
+
);
|
|
364
442
|
parseDirective(name, value, tag, options);
|
|
365
443
|
}
|
|
366
444
|
}
|
|
367
|
-
if (
|
|
445
|
+
if (
|
|
446
|
+
node.children.length === 1 &&
|
|
447
|
+
node.children[0].type === "comment" &&
|
|
448
|
+
node.children[0].content === "#"
|
|
449
|
+
) {
|
|
368
450
|
props.push(`children: () => exprs[${options.counter++}]`);
|
|
369
451
|
} else if (node.children.length) {
|
|
370
452
|
const children = {
|
|
@@ -387,7 +469,20 @@ function createHTML(r, {
|
|
|
387
469
|
tag = `_$el${uuid++}`;
|
|
388
470
|
options.decl.push(`${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`);
|
|
389
471
|
}
|
|
390
|
-
if (options.parent)
|
|
472
|
+
if (options.parent)
|
|
473
|
+
options.exprs.push(
|
|
474
|
+
`r.insert(${
|
|
475
|
+
options.parent
|
|
476
|
+
}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${
|
|
477
|
+
tag ? `, ${tag}` : ""
|
|
478
|
+
})`
|
|
479
|
+
);
|
|
480
|
+
else
|
|
481
|
+
options.exprs.push(
|
|
482
|
+
`${
|
|
483
|
+
options.fragment ? "" : "return "
|
|
484
|
+
}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`
|
|
485
|
+
);
|
|
391
486
|
options.path = tag;
|
|
392
487
|
options.first = false;
|
|
393
488
|
}
|
|
@@ -418,13 +513,21 @@ function createHTML(r, {
|
|
|
418
513
|
});
|
|
419
514
|
options.templateNodes.push([child]);
|
|
420
515
|
parseNode(child, childOptions);
|
|
421
|
-
parts.push(
|
|
516
|
+
parts.push(
|
|
517
|
+
`function() { ${
|
|
518
|
+
childOptions.decl.join(",\n") +
|
|
519
|
+
";\n" +
|
|
520
|
+
childOptions.exprs.join(";\n") +
|
|
521
|
+
`;\nreturn _$el${id};\n`
|
|
522
|
+
}}()`
|
|
523
|
+
);
|
|
422
524
|
options.counter = childOptions.counter;
|
|
423
525
|
options.templateId = childOptions.templateId;
|
|
424
526
|
} else if (child.type === "text") {
|
|
425
527
|
parts.push(`"${child.content}"`);
|
|
426
528
|
} else if (child.type === "comment") {
|
|
427
|
-
if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
|
|
529
|
+
if (child.content === "#") parts.push(`exprs[${options.counter++}]`);
|
|
530
|
+
else if (child.content) {
|
|
428
531
|
for (let i = 0; i < child.content.split("###").length - 1; i++) {
|
|
429
532
|
parts.push(`exprs[${options.counter++}]`);
|
|
430
533
|
}
|
|
@@ -436,7 +539,9 @@ function createHTML(r, {
|
|
|
436
539
|
const tag = `_$el${uuid++}`;
|
|
437
540
|
const topDecl = !options.decl.length;
|
|
438
541
|
const templateId = options.templateId;
|
|
439
|
-
options.decl.push(
|
|
542
|
+
options.decl.push(
|
|
543
|
+
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
|
|
544
|
+
);
|
|
440
545
|
const isSVG = r.SVGElements.has(node.name);
|
|
441
546
|
const isCE = node.name.includes("-");
|
|
442
547
|
options.hasCustomElement = isCE;
|
|
@@ -445,15 +550,13 @@ function createHTML(r, {
|
|
|
445
550
|
let current = "";
|
|
446
551
|
const newAttrs = [];
|
|
447
552
|
for (let i = 0; i < node.attrs.length; i++) {
|
|
448
|
-
const {
|
|
449
|
-
|
|
450
|
-
name,
|
|
451
|
-
value
|
|
452
|
-
} = node.attrs[i];
|
|
453
|
-
if (type === 'attr') {
|
|
553
|
+
const { type, name, value } = node.attrs[i];
|
|
554
|
+
if (type === "attr") {
|
|
454
555
|
if (value.includes("###")) {
|
|
455
556
|
let count = options.counter++;
|
|
456
|
-
current += `${name}: ${
|
|
557
|
+
current += `${name}: ${
|
|
558
|
+
name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""
|
|
559
|
+
}exprs[${count}],`;
|
|
457
560
|
} else if (name === "###") {
|
|
458
561
|
if (current.length) {
|
|
459
562
|
spreadArgs.push(`()=>({${current}})`);
|
|
@@ -463,7 +566,7 @@ function createHTML(r, {
|
|
|
463
566
|
} else {
|
|
464
567
|
newAttrs.push(node.attrs[i]);
|
|
465
568
|
}
|
|
466
|
-
} else if (type ===
|
|
569
|
+
} else if (type === "directive") {
|
|
467
570
|
parseDirective(name, value, tag, options);
|
|
468
571
|
}
|
|
469
572
|
}
|
|
@@ -471,15 +574,17 @@ function createHTML(r, {
|
|
|
471
574
|
if (current.length) {
|
|
472
575
|
spreadArgs.push(`()=>({${current}})`);
|
|
473
576
|
}
|
|
474
|
-
options.exprs.push(
|
|
577
|
+
options.exprs.push(
|
|
578
|
+
`r.spread(${tag},${
|
|
579
|
+
spreadArgs.length === 1
|
|
580
|
+
? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}`
|
|
581
|
+
: `r.mergeProps(${spreadArgs.join(",")})`
|
|
582
|
+
},${isSVG},${!!node.children.length})`
|
|
583
|
+
);
|
|
475
584
|
} else {
|
|
476
585
|
for (let i = 0; i < node.attrs.length; i++) {
|
|
477
|
-
const {
|
|
478
|
-
|
|
479
|
-
name,
|
|
480
|
-
value
|
|
481
|
-
} = node.attrs[i];
|
|
482
|
-
if (type === 'directive') {
|
|
586
|
+
const { type, name, value } = node.attrs[i];
|
|
587
|
+
if (type === "directive") {
|
|
483
588
|
parseDirective(name, value, tag, options);
|
|
484
589
|
node.attrs.splice(i, 1);
|
|
485
590
|
i--;
|
|
@@ -496,7 +601,9 @@ function createHTML(r, {
|
|
|
496
601
|
options.first = false;
|
|
497
602
|
processChildren(node, options);
|
|
498
603
|
if (topDecl) {
|
|
499
|
-
options.decl[0] = options.hasCustomElement
|
|
604
|
+
options.decl[0] = options.hasCustomElement
|
|
605
|
+
? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))`
|
|
606
|
+
: `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`;
|
|
500
607
|
}
|
|
501
608
|
} else if (node.type === "text") {
|
|
502
609
|
const tag = `_$el${uuid++}`;
|
|
@@ -531,10 +638,12 @@ function createHTML(r, {
|
|
|
531
638
|
origNodes = nodes;
|
|
532
639
|
let toplevel;
|
|
533
640
|
if (nodes.length > 1) {
|
|
534
|
-
nodes = [
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
641
|
+
nodes = [
|
|
642
|
+
{
|
|
643
|
+
type: "fragment",
|
|
644
|
+
children: nodes
|
|
645
|
+
}
|
|
646
|
+
];
|
|
538
647
|
}
|
|
539
648
|
if (nodes[0].name === "###") {
|
|
540
649
|
toplevel = true;
|
|
@@ -542,12 +651,25 @@ function createHTML(r, {
|
|
|
542
651
|
} else parseNode(nodes[0], options);
|
|
543
652
|
r.delegateEvents(Array.from(options.delegatedEvents));
|
|
544
653
|
const templateNodes = [origNodes].concat(options.templateNodes);
|
|
545
|
-
return [
|
|
654
|
+
return [
|
|
655
|
+
templateNodes.map(t => stringify(t)),
|
|
656
|
+
funcBuilder(
|
|
657
|
+
"tmpls",
|
|
658
|
+
"exprs",
|
|
659
|
+
"r",
|
|
660
|
+
options.decl.join(",\n") +
|
|
661
|
+
";\n" +
|
|
662
|
+
options.exprs.join(";\n") +
|
|
663
|
+
(toplevel ? "" : `;\nreturn _$el${id};\n`)
|
|
664
|
+
)
|
|
665
|
+
];
|
|
546
666
|
}
|
|
547
667
|
function html(statics, ...args) {
|
|
548
|
-
const templates =
|
|
549
|
-
|
|
550
|
-
|
|
668
|
+
const templates =
|
|
669
|
+
cache.get(statics) ||
|
|
670
|
+
createTemplate(statics, {
|
|
671
|
+
funcBuilder: functionBuilder
|
|
672
|
+
});
|
|
551
673
|
return templates[0].create(templates, args, r);
|
|
552
674
|
}
|
|
553
675
|
return html;
|
package/html/types/lit.d.ts
CHANGED
|
@@ -1,39 +1,53 @@
|
|
|
1
1
|
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
|
|
2
2
|
interface Runtime {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
effect<T>(fn: (prev?: T) => T, init?: T): any;
|
|
4
|
+
untrack<T>(fn: () => T): T;
|
|
5
|
+
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
|
|
6
|
+
spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
|
|
7
|
+
createComponent(Comp: (props: any) => any, props: any): any;
|
|
8
|
+
addEventListener(node: Element, name: string, handler: () => void, delegate: boolean): void;
|
|
9
|
+
delegateEvents(eventNames: string[]): void;
|
|
10
|
+
classList(
|
|
11
|
+
node: Element,
|
|
12
|
+
value: {
|
|
13
|
+
[k: string]: boolean;
|
|
14
|
+
},
|
|
15
|
+
prev?: {
|
|
16
|
+
[k: string]: boolean;
|
|
17
|
+
}
|
|
18
|
+
): void;
|
|
19
|
+
style(
|
|
20
|
+
node: Element,
|
|
21
|
+
value: {
|
|
22
|
+
[k: string]: string;
|
|
23
|
+
},
|
|
24
|
+
prev?: {
|
|
25
|
+
[k: string]: string;
|
|
26
|
+
}
|
|
27
|
+
): void;
|
|
28
|
+
mergeProps(...sources: unknown[]): unknown;
|
|
29
|
+
dynamicProperty(props: any, key: string): any;
|
|
30
|
+
setAttribute(node: Element, name: string, value: any): void;
|
|
31
|
+
setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
|
|
32
|
+
Aliases: Record<string, string>;
|
|
33
|
+
getPropAlias(prop: string, tagName: string): string | undefined;
|
|
34
|
+
Properties: Set<string>;
|
|
35
|
+
ChildProperties: Set<string>;
|
|
36
|
+
DelegatedEvents: Set<string>;
|
|
37
|
+
SVGElements: Set<string>;
|
|
38
|
+
SVGNamespace: Record<string, string>;
|
|
31
39
|
}
|
|
32
40
|
export type HTMLTag = {
|
|
33
|
-
|
|
41
|
+
(statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
|
|
34
42
|
};
|
|
35
|
-
export declare function createHTML(
|
|
43
|
+
export declare function createHTML(
|
|
44
|
+
r: Runtime,
|
|
45
|
+
{
|
|
46
|
+
delegateEvents,
|
|
47
|
+
functionBuilder
|
|
48
|
+
}?: {
|
|
36
49
|
delegateEvents?: boolean;
|
|
37
50
|
functionBuilder?: (...args: string[]) => Function;
|
|
38
|
-
}
|
|
51
|
+
}
|
|
52
|
+
): HTMLTag;
|
|
39
53
|
export {};
|