vsn 0.1.63 → 0.1.66
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 +12 -1
- package/demo/vsn.js +2 -2
- package/demo/xhr.html +10 -3
- package/dist/AST/ClassNode.d.ts +3 -1
- package/dist/AST/ClassNode.js +43 -51
- package/dist/AST/ClassNode.js.map +1 -1
- package/dist/AST/ElementAttributeNode.d.ts +1 -1
- package/dist/AST/ElementAttributeNode.js +3 -2
- package/dist/AST/ElementAttributeNode.js.map +1 -1
- package/dist/AST/ElementQueryNode.d.ts +4 -4
- package/dist/AST/ElementQueryNode.js +17 -6
- package/dist/AST/ElementQueryNode.js.map +1 -1
- package/dist/AST/ElementStyleNode.d.ts +1 -1
- package/dist/AST/ElementStyleNode.js +3 -2
- package/dist/AST/ElementStyleNode.js.map +1 -1
- package/dist/AST/FunctionNode.d.ts +1 -1
- package/dist/AST/FunctionNode.js +4 -3
- package/dist/AST/FunctionNode.js.map +1 -1
- package/dist/AST/Node.d.ts +1 -1
- package/dist/AST/Node.js +3 -2
- package/dist/AST/Node.js.map +1 -1
- package/dist/AST/OnNode.d.ts +1 -1
- package/dist/AST/OnNode.js +5 -4
- package/dist/AST/OnNode.js.map +1 -1
- package/dist/AST.d.ts +1 -1
- package/dist/AST.js +1 -1
- package/dist/AST.js.map +1 -1
- package/dist/DOM.d.ts +7 -1
- package/dist/DOM.js +23 -3
- package/dist/DOM.js.map +1 -1
- package/dist/Registry.d.ts +3 -0
- package/dist/Registry.js +13 -0
- package/dist/Registry.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/attributes/RootAttribute.d.ts +1 -0
- package/dist/attributes/RootAttribute.js +18 -6
- package/dist/attributes/RootAttribute.js.map +1 -1
- package/dist/helpers/ElementHelper.js +6 -0
- package/dist/helpers/ElementHelper.js.map +1 -1
- package/dist/vsn.js +4 -0
- package/dist/vsn.js.map +1 -1
- package/dist/vsn.min.js +2 -0
- package/package.json +1 -1
- package/src/AST/ClassNode.ts +20 -16
- package/src/AST/ElementAttributeNode.ts +2 -2
- package/src/AST/ElementQueryNode.ts +13 -5
- package/src/AST/ElementStyleNode.ts +2 -2
- package/src/AST/FunctionNode.ts +4 -3
- package/src/AST/Node.ts +2 -2
- package/src/AST/OnNode.ts +4 -4
- package/src/AST.ts +2 -3
- package/src/DOM.ts +19 -3
- package/src/Registry.ts +10 -0
- package/src/Scope.ts +8 -2
- package/src/attributes/RootAttribute.ts +11 -3
- package/src/helpers/ElementHelper.ts +6 -0
- package/src/vsn.ts +4 -0
- package/test/DOM.spec.ts +27 -0
package/package.json
CHANGED
package/src/AST/ClassNode.ts
CHANGED
|
@@ -19,19 +19,19 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
19
19
|
super();
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public
|
|
22
|
+
public updateMeta(meta?: any) {
|
|
23
|
+
meta = meta || {};
|
|
24
|
+
meta['ClassNode'] = this;
|
|
25
|
+
return meta;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta?: any): Promise<void> {
|
|
29
|
+
meta = meta || {};
|
|
30
|
+
meta['ClassNodePrepare'] = true;
|
|
23
31
|
if (ClassNode.classes[this.name]) return; // Don't re-prepare same classes
|
|
24
32
|
ClassNode.classes[this.name] = this;
|
|
25
|
-
await this.block.prepare(this.classScope, dom, tag);
|
|
33
|
+
await this.block.prepare(this.classScope, dom, tag, meta);
|
|
26
34
|
Registry.class(this);
|
|
27
|
-
const hasConstructor = this.classScope.has('construct');
|
|
28
|
-
|
|
29
|
-
for (const element of Array.from(dom.querySelectorAll(`.${this.name}`))) {
|
|
30
|
-
const tag: Tag = await dom.getTagForElement(element as HTMLElement, true);
|
|
31
|
-
if (tag) {
|
|
32
|
-
await this.prepareTag(tag, dom, hasConstructor);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public async prepareTag(tag: Tag, dom: DOM, hasConstructor: boolean | null = null) {
|
|
@@ -39,7 +39,8 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
39
39
|
hasConstructor = this.classScope.has('construct');
|
|
40
40
|
|
|
41
41
|
tag.createScope(true);
|
|
42
|
-
|
|
42
|
+
const meta = this.updateMeta();
|
|
43
|
+
await this.block.prepare(tag.scope, dom, tag, meta);
|
|
43
44
|
if (hasConstructor) {
|
|
44
45
|
const fnc = this.classScope.get('construct');
|
|
45
46
|
(await fnc.evaluate(tag.scope, dom, tag))();
|
|
@@ -83,7 +84,7 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
83
84
|
if (t.type === TokenType.L_BRACE) break;
|
|
84
85
|
nameParts.push(t.value);
|
|
85
86
|
}
|
|
86
|
-
const name = nameParts.join('');
|
|
87
|
+
const name = nameParts.join('').trim();
|
|
87
88
|
tokens.splice(0, nameParts.length);
|
|
88
89
|
const block = Tree.processTokens(Tree.getNextStatementTokens(tokens, true, true));
|
|
89
90
|
return new ClassNode(name, block);
|
|
@@ -93,12 +94,11 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
93
94
|
const classes: string[] = Array.from(element.classList);
|
|
94
95
|
let addedClasses: string[] = classes.filter(c => Registry.instance.classes.has(c));
|
|
95
96
|
let removedClasses: string[] = [];
|
|
96
|
-
if (tag) {
|
|
97
|
-
addedClasses = addedClasses.filter(c => !tag.preppedClasses.includes(c));
|
|
98
|
-
removedClasses = tag.preppedClasses.filter(c => !classes.includes(c));
|
|
99
|
-
} else {
|
|
97
|
+
if (!tag) {
|
|
100
98
|
tag = await dom.getTagForElement(element, true);
|
|
101
99
|
}
|
|
100
|
+
addedClasses = addedClasses.filter(c => !tag.preppedClasses.includes(c));
|
|
101
|
+
removedClasses = tag.preppedClasses.filter(c => !classes.includes(c));
|
|
102
102
|
|
|
103
103
|
for (const addedClass of addedClasses) {
|
|
104
104
|
const classNode: ClassNode = Registry.instance.classes.getSynchronous(addedClass);
|
|
@@ -114,4 +114,8 @@ export class ClassNode extends Node implements TreeNode {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
|
|
118
|
+
public static isClass(cls: string): boolean {
|
|
119
|
+
return this.classes[cls] instanceof ClassNode;
|
|
120
|
+
}
|
|
117
121
|
}
|
|
@@ -50,9 +50,9 @@ export class ElementAttributeNode extends Node implements TreeNode {
|
|
|
50
50
|
return tags.map((tag) => tag.scope.get(`@${this.attributeName}`));
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
53
|
+
async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta: any = null) {
|
|
54
54
|
if (this.elementRef) {
|
|
55
|
-
await this.elementRef.prepare(scope, dom, tag);
|
|
55
|
+
await this.elementRef.prepare(scope, dom, tag, meta);
|
|
56
56
|
const tags: TagList = await this.elementRef.evaluate(scope, dom, tag, true);
|
|
57
57
|
for (const t of tags)
|
|
58
58
|
await t.watchAttribute(this.attributeName);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Scope} from "../Scope";
|
|
2
|
-
import {DOM} from "../DOM";
|
|
2
|
+
import {DOM, EQuerySelectDirection} from "../DOM";
|
|
3
3
|
import {Tag} from "../Tag";
|
|
4
4
|
import {Token, TreeNode} from "../AST";
|
|
5
5
|
import {Node} from "./Node";
|
|
@@ -10,24 +10,32 @@ export class ElementQueryNode extends Node implements TreeNode {
|
|
|
10
10
|
constructor(
|
|
11
11
|
public readonly query: string,
|
|
12
12
|
public readonly first: boolean = false,
|
|
13
|
-
public readonly
|
|
13
|
+
public readonly direction: EQuerySelectDirection = EQuerySelectDirection.ALL,
|
|
14
14
|
) {
|
|
15
15
|
super();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async evaluate(scope: Scope, dom: DOM, tag: Tag = null, forceList: boolean = false): Promise<any> {
|
|
19
19
|
tag = tag || await dom.getTagForScope(scope);
|
|
20
|
-
const elements = await dom.get(this.query, true, this.
|
|
20
|
+
const elements = await dom.get(this.query, true, tag, this.direction);
|
|
21
21
|
return this.first && !forceList ? elements[0] : elements;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
24
|
+
async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta: any = null): Promise<any> {
|
|
25
25
|
tag = tag || await dom.getTagForScope(scope);
|
|
26
26
|
await dom.get(this.query, true, tag);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
public static parse(lastNode, token, tokens: Token[]): ElementQueryNode {
|
|
30
30
|
tokens.shift();
|
|
31
|
-
|
|
31
|
+
let first = false;
|
|
32
|
+
let direction = EQuerySelectDirection.ALL;
|
|
33
|
+
if (token.full.startsWith('?>')) {
|
|
34
|
+
direction = EQuerySelectDirection.DOWN;
|
|
35
|
+
} else if (token.full.startsWith('?<')) {
|
|
36
|
+
direction = EQuerySelectDirection.UP;
|
|
37
|
+
first = true;
|
|
38
|
+
}
|
|
39
|
+
return new ElementQueryNode(token.value, first, direction);
|
|
32
40
|
}
|
|
33
41
|
}
|
|
@@ -50,9 +50,9 @@ export class ElementStyleNode extends Node implements TreeNode {
|
|
|
50
50
|
return tags.map((tag) => tag.scope.get(`$${this.attributeName}`));
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
53
|
+
async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta: any = null) {
|
|
54
54
|
if (this.elementRef) {
|
|
55
|
-
await this.elementRef.prepare(scope, dom, tag);
|
|
55
|
+
await this.elementRef.prepare(scope, dom, tag, meta);
|
|
56
56
|
const tags: TagList = await this.elementRef.evaluate(scope, dom, tag, true);
|
|
57
57
|
for (const t of tags)
|
|
58
58
|
await t.watchStyle(this.attributeName);
|
package/src/AST/FunctionNode.ts
CHANGED
|
@@ -22,9 +22,10 @@ export class FunctionNode extends Node implements TreeNode {
|
|
|
22
22
|
];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public async prepare(scope: Scope, dom: DOM, tag: Tag = null): Promise<void> {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
public async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta?: any): Promise<void> {
|
|
26
|
+
if (!meta?.ClassNode) // Don't muddle up tag scope if we're in a class
|
|
27
|
+
scope.set(this.name, this);
|
|
28
|
+
await super.prepare(scope, dom, tag, meta);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
public async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
package/src/AST/Node.ts
CHANGED
|
@@ -27,9 +27,9 @@ export abstract class Node implements TreeNode {
|
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
30
|
+
async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta: any = null): Promise<void> {
|
|
31
31
|
for (const node of this.getChildNodes()) {
|
|
32
|
-
await node.prepare(scope, dom, tag);
|
|
32
|
+
await node.prepare(scope, dom, tag, meta);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
package/src/AST/OnNode.ts
CHANGED
|
@@ -5,11 +5,11 @@ import {DOM} from "../DOM";
|
|
|
5
5
|
import {Tag} from "../Tag";
|
|
6
6
|
|
|
7
7
|
export class OnNode extends FunctionNode implements TreeNode {
|
|
8
|
-
public async prepare(scope: Scope, dom: DOM, tag: Tag = null): Promise<void> {
|
|
9
|
-
if
|
|
8
|
+
public async prepare(scope: Scope, dom: DOM, tag: Tag = null, meta): Promise<void> {
|
|
9
|
+
const classPrep = meta?.ClassNodePrepare; // Don't add event handler if we're in class prep
|
|
10
|
+
if (tag && !classPrep)
|
|
10
11
|
tag.addEventHandler(this.name, [], await this.getFunction(scope, dom, tag), this);
|
|
11
|
-
|
|
12
|
-
await super.prepare(scope, dom, tag);
|
|
12
|
+
await super.prepare(scope, dom, tag, meta);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
public static parse(lastNode, token, tokens: Token[]): OnNode {
|
package/src/AST.ts
CHANGED
|
@@ -226,7 +226,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
226
226
|
},
|
|
227
227
|
{
|
|
228
228
|
type: TokenType.ELEMENT_QUERY,
|
|
229
|
-
pattern:
|
|
229
|
+
pattern: /^\?[>|<]?\(([#.\[\]:,=\-_a-zA-Z0-9*\s]*[\]_a-zA-Z0-9*])\)/
|
|
230
230
|
},
|
|
231
231
|
{
|
|
232
232
|
type: TokenType.NAME,
|
|
@@ -368,8 +368,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
368
368
|
|
|
369
369
|
export interface TreeNode<T = any> {
|
|
370
370
|
evaluate(scope: Scope, dom: DOM, tag?: Tag);
|
|
371
|
-
|
|
372
|
-
prepare(scope: Scope, dom: DOM, tag?: Tag);
|
|
371
|
+
prepare(scope: Scope, dom: DOM, tag?: Tag, meta?: any);
|
|
373
372
|
}
|
|
374
373
|
|
|
375
374
|
export interface IBlockInfo {
|
package/src/DOM.ts
CHANGED
|
@@ -7,9 +7,14 @@ import {WrappedWindow} from "./DOM/WrappedWindow";
|
|
|
7
7
|
import {WrappedDocument} from "./DOM/WrappedDocument";
|
|
8
8
|
import {Scope} from "./Scope";
|
|
9
9
|
import {EventDispatcher} from "./EventDispatcher";
|
|
10
|
-
import {Registry} from "./Registry";
|
|
11
10
|
import {ClassNode} from "./AST/ClassNode";
|
|
12
11
|
|
|
12
|
+
export enum EQuerySelectDirection {
|
|
13
|
+
ALL,
|
|
14
|
+
UP,
|
|
15
|
+
DOWN
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
export class DOM extends EventDispatcher {
|
|
14
19
|
protected static _instance: DOM;
|
|
15
20
|
protected _root: Tag;
|
|
@@ -44,7 +49,7 @@ export class DOM extends EventDispatcher {
|
|
|
44
49
|
return this._root;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
public async get(selector: string, create: boolean = false, tag: Tag = null) {
|
|
52
|
+
public async get(selector: string, create: boolean = false, tag: Tag = null, direction: EQuerySelectDirection = EQuerySelectDirection.DOWN): Promise<TagList> {
|
|
48
53
|
switch (selector) {
|
|
49
54
|
case 'window':
|
|
50
55
|
return new TagList(this.window);
|
|
@@ -53,7 +58,14 @@ export class DOM extends EventDispatcher {
|
|
|
53
58
|
case 'body':
|
|
54
59
|
return new TagList(this.root);
|
|
55
60
|
default:
|
|
56
|
-
|
|
61
|
+
let nodes;
|
|
62
|
+
if (direction === EQuerySelectDirection.DOWN) {
|
|
63
|
+
nodes = this.querySelectorAll(selector, tag);
|
|
64
|
+
} else if (direction === EQuerySelectDirection.UP) {
|
|
65
|
+
nodes = [this.querySelectorClosest(selector, tag)];
|
|
66
|
+
} else {
|
|
67
|
+
nodes = this.querySelectorAll(selector);
|
|
68
|
+
}
|
|
57
69
|
return await this.getTagsForElements(Array.from(nodes) as Element[], create);
|
|
58
70
|
}
|
|
59
71
|
}
|
|
@@ -69,6 +81,10 @@ export class DOM extends EventDispatcher {
|
|
|
69
81
|
this.root.scope.set(`#${id}`, tag.scope);
|
|
70
82
|
}
|
|
71
83
|
|
|
84
|
+
public querySelectorClosest(q: string, tag: Tag = null): HTMLElement {
|
|
85
|
+
return tag.element.closest(q);
|
|
86
|
+
}
|
|
87
|
+
|
|
72
88
|
public querySelectorAll(q: string, tag: Tag = null): NodeList | HTMLElement[] {
|
|
73
89
|
const element: HTMLElement | Document = tag && !q.startsWith('#') ? tag.element : this.rootElement;
|
|
74
90
|
return this.querySelectorElement(element, q);
|
package/src/Registry.ts
CHANGED
|
@@ -54,10 +54,15 @@ export class RegistryStore extends EventDispatcher {
|
|
|
54
54
|
has(key: string) {
|
|
55
55
|
return !!this.store[key];
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
get keys(): string[] {
|
|
59
|
+
return Object.keys(this.store);
|
|
60
|
+
}
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
export class Registry extends EventDispatcher {
|
|
60
64
|
protected static _instance: Registry;
|
|
65
|
+
public readonly functions: RegistryStore;
|
|
61
66
|
public readonly controllers: RegistryStore;
|
|
62
67
|
public readonly classes: RegistryStore;
|
|
63
68
|
public readonly models: RegistryStore;
|
|
@@ -69,6 +74,7 @@ export class Registry extends EventDispatcher {
|
|
|
69
74
|
|
|
70
75
|
constructor() {
|
|
71
76
|
super();
|
|
77
|
+
this.functions = new RegistryStore();
|
|
72
78
|
this.controllers = new RegistryStore();
|
|
73
79
|
this.classes = new RegistryStore();
|
|
74
80
|
this.models = new RegistryStore();
|
|
@@ -79,6 +85,10 @@ export class Registry extends EventDispatcher {
|
|
|
79
85
|
this.attributes = new RegistryStore();
|
|
80
86
|
}
|
|
81
87
|
|
|
88
|
+
public static function(key: string = null, setup = null) {
|
|
89
|
+
return register('functions', key, setup);
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
public static class(cls: ClassNode) {
|
|
83
93
|
Registry.instance.classes.register(cls.name, cls);
|
|
84
94
|
}
|
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
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {Attribute} from "../Attribute";
|
|
2
2
|
import {VisionHelper} from "../helpers/VisionHelper";
|
|
3
3
|
import {Registry} from "../Registry";
|
|
4
|
-
import {Scope} from "../Scope";
|
|
5
4
|
|
|
6
5
|
@Registry.attribute('vsn-root')
|
|
7
6
|
export class RootAttribute extends Attribute {
|
|
@@ -10,8 +9,17 @@ export class RootAttribute extends Attribute {
|
|
|
10
9
|
|
|
11
10
|
public async setup() {
|
|
12
11
|
this.tag.scope.set('$mobile', VisionHelper.isMobile());
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
|
|
13
|
+
for (const key of Registry.instance.functions.keys) {
|
|
14
|
+
const fn = Registry.instance.functions.get(key);
|
|
15
|
+
this.tag.scope.set(key, fn);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Registry.instance.functions.on('register', this.registerFunction, this);
|
|
15
19
|
await super.setup();
|
|
16
20
|
}
|
|
21
|
+
|
|
22
|
+
public async registerFunction(name: string, fn: Function) {
|
|
23
|
+
this.tag.scope.set(name, fn);
|
|
24
|
+
}
|
|
17
25
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {ClassNode} from "../AST/ClassNode";
|
|
1
2
|
|
|
2
3
|
export class ElementHelper {
|
|
3
4
|
public static hasVisionAttribute(element: HTMLElement | Element, testAttr: string = 'vsn-'): boolean {
|
|
@@ -10,6 +11,11 @@ export class ElementHelper {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
for (const cls of Array.from(element.classList)) {
|
|
15
|
+
if (ClassNode.isClass(cls))
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
return false;
|
|
14
20
|
}
|
|
15
21
|
|
package/src/vsn.ts
CHANGED
|
@@ -25,6 +25,10 @@ export class Vision extends EventDispatcher {
|
|
|
25
25
|
} else {
|
|
26
26
|
console.warn('No dom, running in CLI mode.');
|
|
27
27
|
}
|
|
28
|
+
this.registry.functions.register('log', console.log);
|
|
29
|
+
this.registry.functions.register('warn', console.warn);
|
|
30
|
+
this.registry.functions.register('error', console.error);
|
|
31
|
+
this.registry.functions.register('info', console.info);
|
|
28
32
|
this.registry.controllers.register('Object', Object);
|
|
29
33
|
this.registry.controllers.register('WrappedArray', WrappedArray);
|
|
30
34
|
this.registry.controllers.register('Data', DynamicScopeData);
|
package/test/DOM.spec.ts
CHANGED
|
@@ -33,4 +33,31 @@ describe('DOM', () => {
|
|
|
33
33
|
done();
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
it("should be able to query elements in all directions", (done) => {
|
|
38
|
+
document.body.innerHTML = `
|
|
39
|
+
<div id="root" vsn-set:asd|integer="1">
|
|
40
|
+
<main id="parent" vsn-set:asd|integer="123">
|
|
41
|
+
<div id="testing" vsn-controller:test="TestController" vsn-set:asd="234|integer">
|
|
42
|
+
<div id="child" vsn-set:asd|integer="345">
|
|
43
|
+
<ul>
|
|
44
|
+
<li vsn-set:asd|integer="456"></li>
|
|
45
|
+
<li id="grandchild" vsn-set:asd|integer="567"></li>
|
|
46
|
+
</ul>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</main>
|
|
50
|
+
</div>
|
|
51
|
+
`;
|
|
52
|
+
const dom = new DOM(document);
|
|
53
|
+
dom.once('built', async () => {
|
|
54
|
+
const root = await dom.exec('#root');
|
|
55
|
+
const child = await dom.exec('#child');
|
|
56
|
+
const grandchild = await dom.exec('#grandchild');
|
|
57
|
+
expect(await child.exec('?<(main).asd')).toBe(123);
|
|
58
|
+
expect(await child.exec('?>(li)[0].asd')).toBe(456);
|
|
59
|
+
expect(await dom.exec('?(#grandchild)[0]')).toBe(grandchild);
|
|
60
|
+
done();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
36
63
|
});
|