solarite 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Solarite-debug.js +1708 -1211
- package/dist/Solarite.js +1642 -1047
- package/dist/Solarite.min.js +2 -2
- package/package.json +1 -1
- package/readme.md +1 -3
- package/src/solarite/ExprPath.js +479 -196
- package/src/solarite/Globals.js +77 -51
- package/src/solarite/HtmlParser.js +91 -0
- package/src/solarite/NodeGroup.js +288 -195
- package/src/solarite/Shell.js +117 -91
- package/src/solarite/Solarite.js +7 -3
- package/src/solarite/Template.js +23 -18
- package/src/solarite/Util.js +117 -179
- package/src/solarite/createSolarite.js +16 -138
- package/src/solarite/getArg.js +31 -16
- package/src/solarite/{r.js → h.js} +56 -18
- package/src/solarite/hash.js +12 -9
- package/src/solarite/watch.js +546 -0
- package/src/util/Errors.js +1 -0
- package/src/util/MultiValueMap.js +73 -13
- package/src/util/Util.js +15 -2
- package/src/util/delve.js +5 -4
- package/src/solarite/watch3.js +0 -98
- package/src/util/WeakArray.js +0 -33
package/src/solarite/Globals.js
CHANGED
|
@@ -1,53 +1,79 @@
|
|
|
1
|
-
var Globals
|
|
2
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
var Globals;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Created with a reset() function because it's useful for testing. */
|
|
5
|
+
function reset() {
|
|
6
|
+
Globals = {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Used by NodeGroup.applyComponentExprs() */
|
|
10
|
+
componentArgsHash: new WeakMap(),
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Store which instances of Solarite have already been added to the DOM.
|
|
14
|
+
* @type {WeakSet<HTMLElement>} */
|
|
15
|
+
connected: new WeakSet(),
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* ExprPath.applyExactNodes() sets this property when an expression is being accessed.
|
|
19
|
+
* watch() then adds the ExprPath to the list of ExprPaths that should be re-rendered when the value changes.
|
|
20
|
+
* @type {ExprPath}*/
|
|
21
|
+
currentExprPath: null,
|
|
22
|
+
|
|
23
|
+
div: document.createElement("div"),
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @type {Object<string, Class<Node>>} A map from built-in tag names to the constructors that create them. */
|
|
27
|
+
elementClasses: {},
|
|
28
|
+
|
|
29
|
+
/** @type {Object<string, boolean>} Key is tag-name.propName. Value is whether it's an attribute.*/
|
|
30
|
+
htmlProps: {},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Used by ExprPath.applyEventAttrib()
|
|
34
|
+
* @type {WeakMap<Node, Object<eventName:string, [original:function, bound:function, args:*[]]>>} */
|
|
35
|
+
nodeEvents: new WeakMap(),
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the RootNodeGroup for an element.
|
|
39
|
+
* @type {WeakMap<HTMLElement, RootNodeGroup>} */
|
|
40
|
+
nodeGroups: new WeakMap(),
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Used by r() path 9. */
|
|
44
|
+
objToEl: new WeakMap(),
|
|
45
|
+
|
|
46
|
+
//pendingChildren: [],
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Elements that have been rendered to by r() at least once.
|
|
51
|
+
* This is used by the Solarite class to know when to call onFirstConnect()
|
|
52
|
+
* @type {WeakSet<HTMLElement>} */
|
|
53
|
+
rendered: new WeakSet(),
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Elements that are currently rendering via the r() function.
|
|
57
|
+
* @type {WeakSet<HTMLElement>} */
|
|
58
|
+
rendering: new WeakSet(),
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Map from array of Html strings to a Shell created from them.
|
|
62
|
+
* @type {WeakMap<string[], Shell>} */
|
|
63
|
+
shells: new WeakMap(),
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A map of individual untagged strings to their Templates.
|
|
67
|
+
* This way we don't keep creating new Templates for the same string when re-rendering.
|
|
68
|
+
* This is used by ExprPath.applyExactNodes()
|
|
69
|
+
* @type {Object<string, Template>} */
|
|
70
|
+
//stringTemplates: {},
|
|
71
|
+
|
|
72
|
+
reset,
|
|
73
|
+
|
|
74
|
+
count: 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
reset();
|
|
52
78
|
|
|
53
79
|
export default Globals;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
export default class HtmlParser {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.defaultState = {
|
|
5
|
+
context: HtmlParser.Text, // possible values: 'TEXT', 'TAG', 'ATTRIBUTE'
|
|
6
|
+
quote: null, // possible values: null, '"', "'"
|
|
7
|
+
buffer: '',
|
|
8
|
+
lastChar: null
|
|
9
|
+
};
|
|
10
|
+
this.state = {...this.defaultState};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
reset() {
|
|
14
|
+
this.state = {...this.defaultState};
|
|
15
|
+
return this.state.context;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse the next chunk of html, starting with the same context we left off with from the previous chunk.
|
|
20
|
+
* @param html {string}
|
|
21
|
+
* @param onContextChange {?function(html:string, index:int, oldContext:string, newContext:string)}
|
|
22
|
+
* Called every time the context changes, and again at the last context.
|
|
23
|
+
* @return {('Attribute','Text','Tag')} The context at the end of html. */
|
|
24
|
+
parse(html, onContextChange=null) {
|
|
25
|
+
if (html === null)
|
|
26
|
+
return this.reset();
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < html.length; i++) {
|
|
29
|
+
const char = html[i];
|
|
30
|
+
switch (this.state.context) {
|
|
31
|
+
case HtmlParser.Text:
|
|
32
|
+
if (char === '<' && html[i + 1].match(/[/a-z!]/i)) { // Start of a tag or comment.
|
|
33
|
+
onContextChange?.(html, i, this.state.context, HtmlParser.Tag);
|
|
34
|
+
this.state.context = HtmlParser.Tag;
|
|
35
|
+
this.state.buffer = '';
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case HtmlParser.Tag:
|
|
39
|
+
if (char === '>') {
|
|
40
|
+
onContextChange?.(html, i+1, this.state.context, HtmlParser.Text);
|
|
41
|
+
this.state.context = HtmlParser.Text;
|
|
42
|
+
this.state.quote = null;
|
|
43
|
+
this.state.buffer = '';
|
|
44
|
+
}
|
|
45
|
+
else if (char === ' ' && !this.state.buffer) {
|
|
46
|
+
// No attribute name is present. Skipping the space.
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
else if (char === ' ' || char === '/' || char === '?') {
|
|
50
|
+
this.state.buffer = ''; // Reset the buffer when a delimiter or potential self-closing sign is found.
|
|
51
|
+
}
|
|
52
|
+
else if (char === '"' || char === "'" || char === '=') {
|
|
53
|
+
onContextChange?.(html, i, this.state.context, HtmlParser.Attribute);
|
|
54
|
+
this.state.context = HtmlParser.Attribute;
|
|
55
|
+
this.state.quote = char === '=' ? null : char;
|
|
56
|
+
this.state.buffer = '';
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
this.state.buffer += char;
|
|
60
|
+
break;
|
|
61
|
+
case HtmlParser.Attribute:
|
|
62
|
+
// Start an attribute quote.
|
|
63
|
+
if (!this.state.quote && !this.state.buffer.length && (char === '"' || char === "'")) {
|
|
64
|
+
this.state.quote = char;
|
|
65
|
+
}
|
|
66
|
+
else if (char === this.state.quote || (!this.state.quote && this.state.buffer.length)) {
|
|
67
|
+
onContextChange?.(html, i, this.state.context, HtmlParser.Tag);
|
|
68
|
+
this.state.context = HtmlParser.Tag;
|
|
69
|
+
this.state.quote = null;
|
|
70
|
+
this.state.buffer = '';
|
|
71
|
+
}
|
|
72
|
+
else if (!this.state.quote && char === '>') {
|
|
73
|
+
onContextChange?.(html, i+1, this.state.context, HtmlParser.Text);
|
|
74
|
+
this.state.context = HtmlParser.Text;
|
|
75
|
+
this.state.quote = null;
|
|
76
|
+
this.state.buffer = '';
|
|
77
|
+
}
|
|
78
|
+
else if (char !== ' ')
|
|
79
|
+
this.state.buffer += char;
|
|
80
|
+
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
onContextChange?.(html, html.length, this.state.context, null);
|
|
85
|
+
return this.state.context;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
HtmlParser.Attribute = 'Attribute';
|
|
90
|
+
HtmlParser.Text = 'Text';
|
|
91
|
+
HtmlParser.Tag = 'Tag';
|