solarite 0.5.2 → 0.7.1
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/LICENSE +21 -0
- package/dist/Solarite-debug.js +4847 -3878
- package/dist/Solarite.js +4583 -3626
- package/dist/Solarite.min.js +2 -4
- package/package.json +19 -6
- package/readme.md +58 -11
- package/src/Globals.js +54 -72
- package/src/HtmlParser.js +90 -90
- package/src/MultiValueMap.js +57 -105
- package/src/NodeGroup.js +624 -470
- package/src/Path.js +224 -211
- package/src/PathToAttribValue.js +401 -261
- package/src/PathToAttribs.js +113 -80
- package/src/PathToComment.js +7 -7
- package/src/PathToComponent.js +183 -188
- package/src/PathToEvent.js +76 -64
- package/src/PathToKey.js +19 -0
- package/src/PathToNodes.js +1053 -566
- package/src/RootNodeGroup.js +120 -8
- package/src/Shell.js +570 -348
- package/src/Solarite.d.ts +134 -113
- package/src/Solarite.js +243 -286
- package/src/Template.js +195 -274
- package/src/Util.js +353 -351
- package/src/assert.js +10 -10
- package/src/assignAttributes.js +63 -0
- package/src/delve.js +55 -43
- package/src/h.js +220 -138
- package/src/jsx-dev-runtime.d.ts +1 -0
- package/src/jsx-dev-runtime.js +5 -0
- package/src/jsx-runtime.d.ts +21 -0
- package/src/jsx-runtime.js +84 -0
- package/src/jsx.js +194 -0
- package/src/toEl.js +77 -82
- package/dist/udomdiff-license.txt +0 -18
- package/src/getArg.js +0 -137
- package/src/hash.js +0 -89
- package/src/udomdiff.js +0 -176
- package/src/unused/FastLookupArray.js +0 -54
- package/src/unused/Hashes.js +0 -339
- package/src/unused/InUse.test.js +0 -92
- package/src/unused/InUseMap.js +0 -98
- package/src/unused/LinkedList.js +0 -117
- package/src/unused/LinkedList.test.js +0 -115
- package/src/unused/Misc.js +0 -13
- package/src/unused/Perf.js +0 -47
- package/src/unused/TrackedArray.js +0 -54
- package/src/unused/WeakArray.js +0 -33
- package/src/watch.js +0 -543
package/src/RootNodeGroup.js
CHANGED
|
@@ -1,8 +1,120 @@
|
|
|
1
|
-
import NodeGroup from './NodeGroup.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import NodeGroup from './NodeGroup.js';
|
|
2
|
+
import Globals from './Globals.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Has these properties not present on NodeGroup, assigned by instantiate():
|
|
6
|
+
* They're not declared as fields because subclass field initializers run after the
|
|
7
|
+
* super constructor and would overwrite the assigned values.
|
|
8
|
+
* @property {HTMLElement} root - Root node at the top of the hierarchy.
|
|
9
|
+
* @property {?object} options - RenderOptions */
|
|
10
|
+
export default class RootNodeGroup extends NodeGroup {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Special setup for the root: graft the fragment into el (or use it standalone),
|
|
14
|
+
* handle slot children, then resolve paths and embeds against the root.
|
|
15
|
+
* Called by the NodeGroup constructor. */
|
|
16
|
+
instantiate(shell, shellFragment, el, options) {
|
|
17
|
+
let startingPathDepth = 0;
|
|
18
|
+
this.options = options;
|
|
19
|
+
if (shellFragment instanceof Text) {
|
|
20
|
+
if (!el)
|
|
21
|
+
throw new Error('Cannot create a standalone text node');
|
|
22
|
+
|
|
23
|
+
this.root = el;
|
|
24
|
+
if (shellFragment.nodeValue.length)
|
|
25
|
+
this.root.append(shellFragment);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
else {
|
|
29
|
+
if (el) {
|
|
30
|
+
this.root = el;
|
|
31
|
+
|
|
32
|
+
// Save slot
|
|
33
|
+
// 1. Globals.currentSlotChildren is set if this is called via PathToComponent.applyComponent() calls render()
|
|
34
|
+
// 2. el.childNodes is set if render() is called manually for the first time.
|
|
35
|
+
let slotChildren;
|
|
36
|
+
if (Globals.currentSlotChildren || el.childNodes.length) {
|
|
37
|
+
slotChildren = Globals.doc.createDocumentFragment();
|
|
38
|
+
slotChildren.append(...(Globals.currentSlotChildren || el.childNodes));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If el should replace the root node of the fragment.
|
|
42
|
+
if (isReplaceEl(shellFragment, this.root.tagName)) {
|
|
43
|
+
this.root.append(...shellFragment.children[0].childNodes);
|
|
44
|
+
|
|
45
|
+
// Copy attributes
|
|
46
|
+
for (let attrib of shellFragment.children[0].attributes)
|
|
47
|
+
if (!this.root.hasAttribute(attrib.name))
|
|
48
|
+
this.root.setAttribute(attrib.name, attrib.value);
|
|
49
|
+
|
|
50
|
+
// Go one level deeper into all of shell's paths.
|
|
51
|
+
startingPathDepth = 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
else {
|
|
55
|
+
let isEmpty = shellFragment.childNodes.length === 1 && shellFragment.childNodes[0].nodeType === 3 && shellFragment.childNodes[0].textContent === '';
|
|
56
|
+
if (!isEmpty)
|
|
57
|
+
this.root.append(...shellFragment.childNodes);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// Setup slot children (deprecated)
|
|
62
|
+
if (slotChildren) {
|
|
63
|
+
// Named slots
|
|
64
|
+
for (let slot of el.querySelectorAll('slot[name]')) {
|
|
65
|
+
let name = slot.getAttribute('name')
|
|
66
|
+
if (name) {
|
|
67
|
+
let slotChildren2 = slotChildren.querySelectorAll(`[slot='${name}']`);
|
|
68
|
+
slot.append(...slotChildren2);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Unnamed slots
|
|
72
|
+
let unamedSlot = el.querySelector('slot:not([name])')
|
|
73
|
+
if (unamedSlot)
|
|
74
|
+
unamedSlot.append(slotChildren);
|
|
75
|
+
// No slots
|
|
76
|
+
else
|
|
77
|
+
el.append(slotChildren);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Instantiate as a standalone element.
|
|
82
|
+
else {
|
|
83
|
+
let onlyChild = getSingleEl(shellFragment);
|
|
84
|
+
this.root = onlyChild || shellFragment; // We return the whole fragment when calling h() with a collection of nodes.
|
|
85
|
+
if (onlyChild)
|
|
86
|
+
startingPathDepth = 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.setPathsFromFragment(this.root, shell, startingPathDepth);
|
|
90
|
+
this.activateEmbeds(this.root, shell, startingPathDepth);
|
|
91
|
+
}
|
|
92
|
+
this.startNode = this.endNode = this.root;
|
|
93
|
+
|
|
94
|
+
Globals.rootNodeGroups.set(this.root, this);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
function getSingleEl(fragment) {
|
|
100
|
+
let nonempty = [];
|
|
101
|
+
for (let n of fragment.childNodes) {
|
|
102
|
+
if (n.nodeType === 1 || n.nodeType === 3 && n.textContent.trim().length) {
|
|
103
|
+
if (nonempty.length)
|
|
104
|
+
return null;
|
|
105
|
+
nonempty.push(n);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return nonempty[0];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Does the fragment have one child that's an element matching the tagname of el?
|
|
113
|
+
* @param fragment {DocumentFragment}
|
|
114
|
+
* @param tagName {string}
|
|
115
|
+
* @returns {boolean} */
|
|
116
|
+
function isReplaceEl(fragment, tagName) {
|
|
117
|
+
return fragment.children.length===1
|
|
118
|
+
&& tagName.includes('-')
|
|
119
|
+
&& fragment.children[0].tagName.replace('-SOLARITE-PLACEHOLDER', '') === tagName;
|
|
120
|
+
}
|