solarite 0.3.2 → 0.5.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 +2149 -2090
- package/dist/Solarite.js +1895 -1821
- package/dist/Solarite.min.js +2 -2
- package/package.json +12 -2
- package/readme.md +2 -2
- package/src/Globals.js +18 -24
- package/src/HtmlParser.js +1 -1
- package/src/MultiValueMap.js +3 -3
- package/src/NodeGroup.js +238 -483
- package/src/Path.js +212 -0
- package/src/PathToAttribValue.js +259 -0
- package/src/PathToAttribs.js +77 -0
- package/src/PathToComment.js +8 -0
- package/src/PathToComponent.js +169 -0
- package/src/PathToEvent.js +57 -0
- package/src/PathToNodes.js +566 -0
- package/src/RootNodeGroup.js +8 -0
- package/src/Shell.js +92 -83
- package/src/Solarite.d.ts +73 -29
- package/src/Solarite.js +133 -21
- package/src/Template.js +173 -42
- package/src/Util.js +74 -52
- package/src/assert.js +5 -5
- package/src/getArg.js +26 -24
- package/src/h.js +83 -128
- package/src/hash.js +11 -9
- package/src/toEl.js +83 -0
- package/src/udomdiff.js +0 -57
- package/src/watch.js +78 -81
- package/src/ExprPath.js +0 -1109
- package/src/createSolarite.js +0 -154
package/src/createSolarite.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import Util from './Util.js';
|
|
2
|
-
import Globals from "./Globals.js";
|
|
3
|
-
|
|
4
|
-
function defineClass(Class, tagName, extendsTag) {
|
|
5
|
-
if (!customElements[getName](Class)) { // If not previously defined.
|
|
6
|
-
tagName = tagName || Util.camelToDashes(Class.name)
|
|
7
|
-
if (!tagName.includes('-'))
|
|
8
|
-
tagName += '-element';
|
|
9
|
-
|
|
10
|
-
let options = null;
|
|
11
|
-
if (extendsTag)
|
|
12
|
-
options = {extends: extendsTag}
|
|
13
|
-
|
|
14
|
-
customElements[define](tagName, Class, options)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a version of the Solarite class that extends from the given tag name.
|
|
20
|
-
* Reasons to inherit from this instead of HTMLElement. None of these are all that useful.
|
|
21
|
-
* 1. customElements.define() is called automatically when you create the first instance.
|
|
22
|
-
* 2. Calls render() when added to the DOM, if it hasn't been called already.
|
|
23
|
-
* 3. Child elements are added before constructor is called. But they're also passed to the constructor. (deprecated?)
|
|
24
|
-
* 4. We can use this.html = r`...` to set html. (deprecated)
|
|
25
|
-
* 5. We have the onConnect, onFirstConnect, and onDisconnect methods.
|
|
26
|
-
* Can't figure out how to have these work standalone though, and still be synchronous.
|
|
27
|
-
* 6. Can we extend from other element types like TR?
|
|
28
|
-
* 7. Shows default text if render() function isn't defined.
|
|
29
|
-
*
|
|
30
|
-
* Advantages to inheriting from HTMLElement
|
|
31
|
-
* 1. Minimization won't break when it renames the Class and we call customElements.define() on the wrong name.
|
|
32
|
-
* 2. We can inherit from things like HTMLTableRowElement directly.
|
|
33
|
-
* 3. There's less magic, since everyone is familiar with defining custom elements.
|
|
34
|
-
*
|
|
35
|
-
* @param extendsTag {?string}
|
|
36
|
-
* @return {Class} */
|
|
37
|
-
export default function createSolarite(extendsTag=null) {
|
|
38
|
-
|
|
39
|
-
let BaseClass = HTMLElement;
|
|
40
|
-
if (extendsTag && !extendsTag.includes('-')) {
|
|
41
|
-
extendsTag = extendsTag.toLowerCase();
|
|
42
|
-
|
|
43
|
-
BaseClass = Globals.elementClasses[extendsTag];
|
|
44
|
-
if (!BaseClass) { // TODO: Use Cache
|
|
45
|
-
BaseClass = document.createElement(extendsTag).constructor;
|
|
46
|
-
Globals.elementClasses[extendsTag] = BaseClass
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Intercept the construct call to auto-define the class before the constructor is called.
|
|
52
|
-
* @type {HTMLElement} */
|
|
53
|
-
let HTMLElementAutoDefine = new Proxy(BaseClass, {
|
|
54
|
-
construct(Parent, args, Class) {
|
|
55
|
-
defineClass(Class, null, extendsTag)
|
|
56
|
-
|
|
57
|
-
// This is a good place to manipulate any args before they're sent to the constructor.
|
|
58
|
-
// Such as loading them from attributes, if I could find a way to do so.
|
|
59
|
-
|
|
60
|
-
// This line is equivalent the to super() call.
|
|
61
|
-
return Reflect.construct(Parent, args, Class);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return class Solarite extends HTMLElementAutoDefine {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* TODO: Make these standalone functions.
|
|
70
|
-
* Callbacks.
|
|
71
|
-
* Use onConnect.push(() => ...); to add new callbacks. */
|
|
72
|
-
onConnect;
|
|
73
|
-
|
|
74
|
-
onFirstConnect;
|
|
75
|
-
onDisconnect;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @param options {RenderOptions} */
|
|
79
|
-
constructor(options={}) {
|
|
80
|
-
super();
|
|
81
|
-
|
|
82
|
-
// TODO: Is options.render ever used?
|
|
83
|
-
if (options.render===true)
|
|
84
|
-
this.render();
|
|
85
|
-
|
|
86
|
-
else if (options.render===false)
|
|
87
|
-
Globals.rendered.add(this); // Don't render on connectedCallback()
|
|
88
|
-
|
|
89
|
-
// Add slot children before constructor code executes.
|
|
90
|
-
// This breaks the styleStaticNested test.
|
|
91
|
-
// PendingChildren is setup in NodeGroup.instantiateComponent()
|
|
92
|
-
// TODO: Match named slots.
|
|
93
|
-
//let ch = Globals.pendingChildren.pop();
|
|
94
|
-
//if (ch) // TODO: how could there be a slot before render is called?
|
|
95
|
-
// (this.querySelector('slot') || this).append(...ch);
|
|
96
|
-
|
|
97
|
-
/** @deprecated
|
|
98
|
-
Object.defineProperty(this, 'html', {
|
|
99
|
-
set(html) {
|
|
100
|
-
Globals.rendered.add(this);
|
|
101
|
-
if (typeof html === 'string') {
|
|
102
|
-
console.warn("Assigning to this.html without the r template prefix.")
|
|
103
|
-
this.innerHTML = html;
|
|
104
|
-
}
|
|
105
|
-
else
|
|
106
|
-
this.modifications = r(this, html, options);
|
|
107
|
-
}
|
|
108
|
-
})*/
|
|
109
|
-
|
|
110
|
-
/*
|
|
111
|
-
let pthis = new Proxy(this, {
|
|
112
|
-
get(obj, prop) {
|
|
113
|
-
return Reflect.get(obj, prop)
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
this.render = this.render.bind(pthis);
|
|
117
|
-
*/
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Call render() only if it hasn't already been called. */
|
|
122
|
-
renderFirstTime() {
|
|
123
|
-
if (!Globals.rendered.has(this) && this.render)
|
|
124
|
-
this.render();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Called automatically by the browser. */
|
|
129
|
-
connectedCallback() {
|
|
130
|
-
this.renderFirstTime();
|
|
131
|
-
if (!Globals.connected.has(this)) {
|
|
132
|
-
Globals.connected.add(this);
|
|
133
|
-
if (this.onFirstConnect)
|
|
134
|
-
this.onFirstConnect();
|
|
135
|
-
}
|
|
136
|
-
if (this.onConnect)
|
|
137
|
-
this.onConnect();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
disconnectedCallback() {
|
|
141
|
-
if (this.onDisconnect)
|
|
142
|
-
this.onDisconnect();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
static define(tagName=null) {
|
|
147
|
-
defineClass(this, tagName, extendsTag)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Trick to prevent minifier from renaming this method.
|
|
153
|
-
let define = 'define';
|
|
154
|
-
let getName = 'getName';
|