vsn 0.1.65 → 0.1.68
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/demo/demo.html +24 -2
- package/demo/vsn.js +2 -2
- package/dist/AST/ClassNode.d.ts +1 -0
- package/dist/AST/ClassNode.js +20 -14
- package/dist/AST/ClassNode.js.map +1 -1
- package/dist/Scope.d.ts +1 -0
- package/dist/Scope.js +8 -4
- package/dist/Scope.js.map +1 -1
- package/dist/Tag.d.ts +1 -1
- package/dist/Tag.js +5 -5
- package/dist/Tag.js.map +1 -1
- package/dist/helpers/ElementHelper.js +2 -1
- package/dist/helpers/ElementHelper.js.map +1 -1
- package/dist/vsn.min.js +2 -0
- package/package.json +1 -1
- package/src/AST/ClassNode.ts +8 -10
- package/src/Scope.ts +8 -2
- package/src/Tag.ts +4 -5
- package/src/helpers/ElementHelper.ts +2 -1
package/package.json
CHANGED
package/src/AST/ClassNode.ts
CHANGED
|
@@ -11,6 +11,7 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
11
11
|
public static readonly classes: {[name: string]: ClassNode} = {};
|
|
12
12
|
protected requiresPrep: boolean = true;
|
|
13
13
|
public readonly classScope: Scope = new Scope();
|
|
14
|
+
protected _ready: boolean = false;
|
|
14
15
|
|
|
15
16
|
constructor(
|
|
16
17
|
public readonly name: string,
|
|
@@ -32,6 +33,10 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
32
33
|
ClassNode.classes[this.name] = this;
|
|
33
34
|
await this.block.prepare(this.classScope, dom, tag, meta);
|
|
34
35
|
Registry.class(this);
|
|
36
|
+
|
|
37
|
+
for (const element of Array.from(dom.querySelectorAll(`.${this.name}`))) {
|
|
38
|
+
await ClassNode.checkForClassChanges(element as HTMLElement, dom, element[Tag.TaggedVariable] || null);
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
public async prepareTag(tag: Tag, dom: DOM, hasConstructor: boolean | null = null) {
|
|
@@ -45,14 +50,6 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
45
50
|
const fnc = this.classScope.get('construct');
|
|
46
51
|
(await fnc.evaluate(tag.scope, dom, tag))();
|
|
47
52
|
}
|
|
48
|
-
/*
|
|
49
|
-
for (const key of this.classScope.keys) {
|
|
50
|
-
if (this.classScope.get(key) instanceof OnNode) {
|
|
51
|
-
const on = this.classScope.get(key) as OnNode;
|
|
52
|
-
tag.addEventHandler(on.name, [], await on.getFunction(tag.scope, dom, tag), on);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
*/
|
|
56
53
|
tag.preppedClasses.push(this.name);
|
|
57
54
|
}
|
|
58
55
|
|
|
@@ -93,7 +90,8 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
93
90
|
public static async checkForClassChanges(element: HTMLElement, dom: DOM, tag: Tag = null) {
|
|
94
91
|
const classes: string[] = Array.from(element.classList);
|
|
95
92
|
let addedClasses: string[] = classes.filter(c => Registry.instance.classes.has(c));
|
|
96
|
-
let removedClasses: string[]
|
|
93
|
+
let removedClasses: string[];
|
|
94
|
+
|
|
97
95
|
if (!tag) {
|
|
98
96
|
tag = await dom.getTagForElement(element, true);
|
|
99
97
|
}
|
|
@@ -116,6 +114,6 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
public static isClass(cls: string): boolean {
|
|
119
|
-
return this.classes[cls]
|
|
117
|
+
return !!this.classes[cls];
|
|
120
118
|
}
|
|
121
119
|
}
|
package/src/Scope.ts
CHANGED
|
@@ -229,10 +229,16 @@ export class Scope extends EventDispatcher {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
export class FunctionScope extends Scope {
|
|
232
|
+
constructor(parentScope?: Scope) {
|
|
233
|
+
super(parentScope);
|
|
234
|
+
this.addRelay(parentScope);
|
|
235
|
+
}
|
|
236
|
+
|
|
232
237
|
set(key: string, value: any) {
|
|
233
|
-
if (this.parentScope.has(key) || ['$', '@'].indexOf(key[0]) > -1)
|
|
238
|
+
if (this.parentScope.has(key) || ['$', '@'].indexOf(key[0]) > -1) {
|
|
234
239
|
this.parentScope.set(key, value);
|
|
235
|
-
else
|
|
240
|
+
} else {
|
|
236
241
|
super.set(key, value);
|
|
242
|
+
}
|
|
237
243
|
}
|
|
238
244
|
}
|
package/src/Tag.ts
CHANGED
|
@@ -21,9 +21,8 @@ export enum TagState {
|
|
|
21
21
|
Built,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export const TaggedVariable:string = '_vsn_tag';
|
|
25
|
-
|
|
26
24
|
export class Tag extends DOMObject {
|
|
25
|
+
public static readonly TaggedVariable: string = '_vsn_tag';
|
|
27
26
|
public readonly rawAttributes: { [key: string]: string; };
|
|
28
27
|
public readonly parsedAttributes: { [key: string]: string[]; };
|
|
29
28
|
public readonly deferredAttributes: Attribute[] = [];
|
|
@@ -58,7 +57,7 @@ export class Tag extends DOMObject {
|
|
|
58
57
|
...props
|
|
59
58
|
) {
|
|
60
59
|
super(element, props);
|
|
61
|
-
element[TaggedVariable] = this;
|
|
60
|
+
element[Tag.TaggedVariable] = this;
|
|
62
61
|
this.rawAttributes = {};
|
|
63
62
|
this.parsedAttributes = {};
|
|
64
63
|
this.attributes = [];
|
|
@@ -240,9 +239,9 @@ export class Tag extends DOMObject {
|
|
|
240
239
|
let parentElement: HTMLElement = this.element.parentElement as HTMLElement;
|
|
241
240
|
let foundParent = false;
|
|
242
241
|
while (parentElement) {
|
|
243
|
-
if (parentElement[TaggedVariable]) {
|
|
242
|
+
if (parentElement[Tag.TaggedVariable]) {
|
|
244
243
|
foundParent = true;
|
|
245
|
-
this.parentTag = parentElement[TaggedVariable];
|
|
244
|
+
this.parentTag = parentElement[Tag.TaggedVariable];
|
|
246
245
|
break;
|
|
247
246
|
}
|
|
248
247
|
|