vsn 0.1.10 → 0.1.14
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 +15 -7
- package/demo/vision.js +1 -1
- package/dist/Scope.d.ts +1 -0
- package/dist/vision.min.js +1 -0
- package/package.json +1 -1
- package/src/AST.ts +27 -17
- package/src/Scope.ts +17 -3
- package/src/Tag.ts +3 -1
- package/test/DOM.spec.ts +2 -2
- package/test/Scope.spec.ts +14 -0
- package/test/attributes/Bind.spec.ts +13 -0
- package/dist/AST.js +0 -1978
- package/dist/AST.js.map +0 -1
- package/dist/Attribute.js +0 -187
- package/dist/Attribute.js.map +0 -1
- package/dist/Bencmark.js +0 -179
- package/dist/Bencmark.js.map +0 -1
- package/dist/Configuration.js +0 -64
- package/dist/Configuration.js.map +0 -1
- package/dist/Controller.js +0 -39
- package/dist/Controller.js.map +0 -1
- package/dist/DOM/DOMObject.js +0 -45
- package/dist/DOM/DOMObject.js.map +0 -1
- package/dist/DOM/WrappedDocument.js +0 -34
- package/dist/DOM/WrappedDocument.js.map +0 -1
- package/dist/DOM/WrappedWindow.js +0 -45
- package/dist/DOM/WrappedWindow.js.map +0 -1
- package/dist/DOM.js +0 -547
- package/dist/DOM.js.map +0 -1
- package/dist/Formats.js +0 -44
- package/dist/Formats.js.map +0 -1
- package/dist/Query.js +0 -66
- package/dist/Query.js.map +0 -1
- package/dist/Registry.js +0 -138
- package/dist/Registry.js.map +0 -1
- package/dist/Scope.js +0 -482
- package/dist/Scope.js.map +0 -1
- package/dist/Tag/List.js +0 -85
- package/dist/Tag/List.js.map +0 -1
- package/dist/Tag.js +0 -713
- package/dist/Tag.js.map +0 -1
- package/dist/Types.js +0 -48
- package/dist/Types.js.map +0 -1
- package/dist/Vision.js +0 -155
- package/dist/Vision.js.map +0 -1
- package/dist/attributes/AddClassIf.js +0 -93
- package/dist/attributes/AddClassIf.js.map +0 -1
- package/dist/attributes/Bind.js +0 -272
- package/dist/attributes/Bind.js.map +0 -1
- package/dist/attributes/ClassConstructor.js +0 -104
- package/dist/attributes/ClassConstructor.js.map +0 -1
- package/dist/attributes/ClickRemoveClass.js +0 -102
- package/dist/attributes/ClickRemoveClass.js.map +0 -1
- package/dist/attributes/ClickToggleClass.js +0 -102
- package/dist/attributes/ClickToggleClass.js.map +0 -1
- package/dist/attributes/ControllerAttribute.js +0 -28
- package/dist/attributes/ControllerAttribute.js.map +0 -1
- package/dist/attributes/DisableIf.js +0 -94
- package/dist/attributes/DisableIf.js.map +0 -1
- package/dist/attributes/Exec.js +0 -102
- package/dist/attributes/Exec.js.map +0 -1
- package/dist/attributes/Format.js +0 -96
- package/dist/attributes/Format.js.map +0 -1
- package/dist/attributes/If.js +0 -147
- package/dist/attributes/If.js.map +0 -1
- package/dist/attributes/JSONAttribute.js +0 -115
- package/dist/attributes/JSONAttribute.js.map +0 -1
- package/dist/attributes/KeyAbstract.js +0 -110
- package/dist/attributes/KeyAbstract.js.map +0 -1
- package/dist/attributes/KeyDown.js +0 -82
- package/dist/attributes/KeyDown.js.map +0 -1
- package/dist/attributes/KeyUp.js +0 -82
- package/dist/attributes/KeyUp.js.map +0 -1
- package/dist/attributes/List.js +0 -273
- package/dist/attributes/List.js.map +0 -1
- package/dist/attributes/ListItem.js +0 -135
- package/dist/attributes/ListItem.js.map +0 -1
- package/dist/attributes/ListItemModel.js +0 -39
- package/dist/attributes/ListItemModel.js.map +0 -1
- package/dist/attributes/ModelAttribute.js +0 -29
- package/dist/attributes/ModelAttribute.js.map +0 -1
- package/dist/attributes/Name.js +0 -88
- package/dist/attributes/Name.js.map +0 -1
- package/dist/attributes/On.js +0 -123
- package/dist/attributes/On.js.map +0 -1
- package/dist/attributes/Radio.js +0 -127
- package/dist/attributes/Radio.js.map +0 -1
- package/dist/attributes/Referenced.js +0 -38
- package/dist/attributes/Referenced.js.map +0 -1
- package/dist/attributes/RootAttribute.js +0 -85
- package/dist/attributes/RootAttribute.js.map +0 -1
- package/dist/attributes/ScopeAttribute.js +0 -40
- package/dist/attributes/ScopeAttribute.js.map +0 -1
- package/dist/attributes/ScopeChange.js +0 -124
- package/dist/attributes/ScopeChange.js.map +0 -1
- package/dist/attributes/SetAttribute.js +0 -130
- package/dist/attributes/SetAttribute.js.map +0 -1
- package/dist/attributes/StandardAttribute.js +0 -168
- package/dist/attributes/StandardAttribute.js.map +0 -1
- package/dist/attributes/Template.js +0 -39
- package/dist/attributes/Template.js.map +0 -1
- package/dist/attributes/TypeAttribute.js +0 -101
- package/dist/attributes/TypeAttribute.js.map +0 -1
- package/dist/attributes/_imports.js +0 -30
- package/dist/attributes/_imports.js.map +0 -1
- package/dist/helpers/DOMHelper.js +0 -81
- package/dist/helpers/DOMHelper.js.map +0 -1
- package/dist/helpers/ElementHelper.js +0 -25
- package/dist/helpers/ElementHelper.js.map +0 -1
- package/dist/helpers/VisionHelper.js +0 -71
- package/dist/helpers/VisionHelper.js.map +0 -1
- package/dist/helpers/decorators.js +0 -38
- package/dist/helpers/decorators.js.map +0 -1
package/src/AST.ts
CHANGED
|
@@ -143,7 +143,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
145
|
type: TokenType.ELEMENT_ATTRIBUTE,
|
|
146
|
-
pattern:
|
|
146
|
+
pattern: /^\.?@[_a-zA-Z0-9]*/
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
type: TokenType.ELEMENT_REFERENCE,
|
|
@@ -151,7 +151,7 @@ const TOKEN_PATTERNS: TokenPattern[] = [
|
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
153
|
type: TokenType.ELEMENT_QUERY,
|
|
154
|
-
pattern:
|
|
154
|
+
pattern: /^\?\(([#.\[\]:,=\-_a-zA-Z0-9*\s]*[\]_a-zA-Z0-9*])\)/
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
157
|
type: TokenType.NAME,
|
|
@@ -868,7 +868,7 @@ class ArithmeticAssignmentNode extends Node implements TreeNode {
|
|
|
868
868
|
} else {
|
|
869
869
|
scopes.push(inner);
|
|
870
870
|
}
|
|
871
|
-
} else if (this.left instanceof ElementAttributeNode) {
|
|
871
|
+
} else if (this.left instanceof ElementAttributeNode && this.left.elementRef) {
|
|
872
872
|
scopes = await this.left.elementRef.evaluate(scope, dom, tag);
|
|
873
873
|
} else
|
|
874
874
|
scopes.push(scope);
|
|
@@ -1187,7 +1187,7 @@ class ElementAttributeNode extends Node implements TreeNode {
|
|
|
1187
1187
|
protected requiresPrep: boolean = true;
|
|
1188
1188
|
|
|
1189
1189
|
constructor(
|
|
1190
|
-
public readonly elementRef: ElementQueryNode,
|
|
1190
|
+
public readonly elementRef: ElementQueryNode | null,
|
|
1191
1191
|
public readonly attr: string
|
|
1192
1192
|
) {
|
|
1193
1193
|
super();
|
|
@@ -1198,9 +1198,10 @@ class ElementAttributeNode extends Node implements TreeNode {
|
|
|
1198
1198
|
}
|
|
1199
1199
|
|
|
1200
1200
|
protected _getChildNodes(): Node[] {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1201
|
+
let nodes = [];
|
|
1202
|
+
if (this.elementRef)
|
|
1203
|
+
nodes.push(this.elementRef)
|
|
1204
|
+
return nodes;
|
|
1204
1205
|
}
|
|
1205
1206
|
|
|
1206
1207
|
get attributeName(): string {
|
|
@@ -1210,17 +1211,30 @@ class ElementAttributeNode extends Node implements TreeNode {
|
|
|
1210
1211
|
}
|
|
1211
1212
|
|
|
1212
1213
|
async evaluate(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
1213
|
-
|
|
1214
|
+
let tags: TagList;
|
|
1215
|
+
if (this.elementRef) {
|
|
1216
|
+
tags = await this.elementRef.evaluate(scope, dom, tag);
|
|
1217
|
+
} else if (tag) {
|
|
1218
|
+
tags = new TagList(tag)
|
|
1219
|
+
} else {
|
|
1220
|
+
return;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1214
1223
|
if (tags.length === 1)
|
|
1215
1224
|
return tags[0].scope.get(`@${this.attributeName}`);
|
|
1225
|
+
|
|
1216
1226
|
return tags.map((tag) => tag.scope.get(`@${this.attributeName}`));
|
|
1217
1227
|
}
|
|
1218
1228
|
|
|
1219
1229
|
async prepare(scope: Scope, dom: DOM, tag: Tag = null) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1230
|
+
if (this.elementRef) {
|
|
1231
|
+
await this.elementRef.prepare(scope, dom, tag);
|
|
1232
|
+
const tags: TagList = await this.elementRef.evaluate(scope, dom, tag);
|
|
1233
|
+
for (const t of tags)
|
|
1234
|
+
await t.watchAttribute(this.attributeName);
|
|
1235
|
+
} else if(tag) {
|
|
1223
1236
|
await tag.watchAttribute(this.attributeName);
|
|
1237
|
+
}
|
|
1224
1238
|
}
|
|
1225
1239
|
}
|
|
1226
1240
|
|
|
@@ -1273,7 +1287,7 @@ export class Tree {
|
|
|
1273
1287
|
let _scope: Scope = scope;
|
|
1274
1288
|
if (node instanceof ScopeMemberNode)
|
|
1275
1289
|
_scope = await node.scope.evaluate(scope, dom);
|
|
1276
|
-
else if (node instanceof ElementAttributeNode) {
|
|
1290
|
+
else if (node instanceof ElementAttributeNode && node.elementRef) {
|
|
1277
1291
|
_scope = (await node.elementRef.evaluate(scope, dom, tag))[0].scope;
|
|
1278
1292
|
}
|
|
1279
1293
|
|
|
@@ -1367,11 +1381,7 @@ export class Tree {
|
|
|
1367
1381
|
} else if (tokens[0].type === TokenType.L_BRACE) {
|
|
1368
1382
|
node = ObjectNode.parse(node, token, tokens);
|
|
1369
1383
|
} else if (tokens[0].type === TokenType.ELEMENT_ATTRIBUTE) {
|
|
1370
|
-
|
|
1371
|
-
node = new ElementAttributeNode(node, tokens[0].value);
|
|
1372
|
-
} else {
|
|
1373
|
-
node = new ScopeMemberNode(node, new LiteralNode<string>(tokens[0].value.substr(1)));
|
|
1374
|
-
}
|
|
1384
|
+
node = new ElementAttributeNode(node as any, tokens[0].value);
|
|
1375
1385
|
tokens.splice(0, 1);
|
|
1376
1386
|
} else if (node !== null && token.type === TokenType.PERIOD && tokens[1].type === TokenType.NAME) {
|
|
1377
1387
|
node = new ScopeMemberNode(
|
package/src/Scope.ts
CHANGED
|
@@ -79,6 +79,9 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
79
79
|
const num: number = super.push(...items);
|
|
80
80
|
|
|
81
81
|
this.trigger('push', ...items);
|
|
82
|
+
this.trigger('change', {
|
|
83
|
+
'added': items
|
|
84
|
+
});
|
|
82
85
|
for (const item of items) {
|
|
83
86
|
this.trigger('add', item);
|
|
84
87
|
}
|
|
@@ -88,6 +91,9 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
88
91
|
splice(start: number, deleteCount?: number): T[] {
|
|
89
92
|
const removed: T[] = super.splice(start, deleteCount);
|
|
90
93
|
|
|
94
|
+
this.trigger('change', {
|
|
95
|
+
'removed': removed
|
|
96
|
+
});
|
|
91
97
|
for (const item of removed) {
|
|
92
98
|
this.trigger('remove', item);
|
|
93
99
|
}
|
|
@@ -104,6 +110,10 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
set length(num: number) {
|
|
113
|
+
this.setLength(num);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
setLength(num: number) {
|
|
107
117
|
let c: number = 0;
|
|
108
118
|
const toRemove: T[] = [];
|
|
109
119
|
for (const item of this) {
|
|
@@ -115,7 +125,6 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
115
125
|
|
|
116
126
|
for (const item of toRemove) {
|
|
117
127
|
this.splice(this.indexOf(item), 1);
|
|
118
|
-
this.trigger('remove', item);
|
|
119
128
|
}
|
|
120
129
|
}
|
|
121
130
|
|
|
@@ -358,8 +367,13 @@ export class Scope extends EventDispatcher {
|
|
|
358
367
|
continue;
|
|
359
368
|
}
|
|
360
369
|
|
|
361
|
-
if (this.wrapped[field] instanceof Array
|
|
362
|
-
this.wrapped[field]
|
|
370
|
+
if (this.wrapped[field] instanceof Array) {
|
|
371
|
+
if (!(this.wrapped[field] instanceof WrappedArray)) {
|
|
372
|
+
this.wrapped[field] = new WrappedArray(...toWrap[field]);
|
|
373
|
+
}
|
|
374
|
+
this.wrapped[field].bind('change', (...args) => {
|
|
375
|
+
this.trigger(`change:${field}`, ...args);
|
|
376
|
+
})
|
|
363
377
|
}
|
|
364
378
|
|
|
365
379
|
if (typeof this.wrapped[field] == 'object' && this.wrapped[field] && this.wrapped[field].constructor === Object) {
|
package/src/Tag.ts
CHANGED
|
@@ -181,15 +181,17 @@ export class Tag extends DOMObject {
|
|
|
181
181
|
if (this.isInput) {
|
|
182
182
|
if (value) {
|
|
183
183
|
this.element.setAttribute('checked', '');
|
|
184
|
+
(this.element as HTMLInputElement).checked = true;
|
|
184
185
|
} else {
|
|
185
186
|
this.element.removeAttribute('checked');
|
|
187
|
+
(this.element as HTMLInputElement).checked = false;
|
|
186
188
|
}
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
get checked(): boolean {
|
|
191
193
|
if (this.isInput) {
|
|
192
|
-
return this.element
|
|
194
|
+
return (this.element as HTMLInputElement).checked;
|
|
193
195
|
} else {
|
|
194
196
|
return false;
|
|
195
197
|
}
|
package/test/DOM.spec.ts
CHANGED
|
@@ -28,8 +28,8 @@ describe('DOM', () => {
|
|
|
28
28
|
`;
|
|
29
29
|
const dom = new DOM(document);
|
|
30
30
|
dom.once('built', async () => {
|
|
31
|
-
expect(await dom.eval('(
|
|
32
|
-
expect(await dom.eval('(
|
|
31
|
+
expect(await dom.eval('?(#parent).asd')).toBe(123);
|
|
32
|
+
expect(await dom.eval('?(#testing).asd')).toBe(345);
|
|
33
33
|
done();
|
|
34
34
|
});
|
|
35
35
|
});
|
package/test/Scope.spec.ts
CHANGED
|
@@ -40,4 +40,18 @@ describe('WrappedArray', () => {
|
|
|
40
40
|
expect(removes).toBe(2);
|
|
41
41
|
expect(a.length).toBe(1);
|
|
42
42
|
});
|
|
43
|
+
|
|
44
|
+
it("should trigger change events", async () => {
|
|
45
|
+
const a = new WrappedArray();
|
|
46
|
+
let changes: number = 0;
|
|
47
|
+
a.bind('change', (e) => {
|
|
48
|
+
changes += 1;
|
|
49
|
+
});
|
|
50
|
+
a.push(1);
|
|
51
|
+
a.push(2);
|
|
52
|
+
a.push(3);
|
|
53
|
+
a.setLength(0);
|
|
54
|
+
expect(changes).toBe(6);
|
|
55
|
+
expect(a.length).toBe(0);
|
|
56
|
+
});
|
|
43
57
|
});
|
|
@@ -18,6 +18,19 @@ describe('Bind', () => {
|
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
+
it("vsn-bind to work with inner text with @text", (done) => {
|
|
22
|
+
document.body.innerHTML = `
|
|
23
|
+
<span id="test" test="testing" vsn-bind="@test"></span>
|
|
24
|
+
`;
|
|
25
|
+
const dom = new DOM(document);
|
|
26
|
+
dom.once('built', async () => {
|
|
27
|
+
const tag = await dom.getTagForElement(document.getElementById('test'));
|
|
28
|
+
expect(tag).toBeTruthy();
|
|
29
|
+
expect(tag.scope.get('@test')).toBe('testing');
|
|
30
|
+
done();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
21
34
|
it("vsn-bind order of execution to be left to right and top to bottom", (done) => {
|
|
22
35
|
document.body.innerHTML = `
|
|
23
36
|
<span id="test" vsn-name="test" vsn-bind:id="test.id" vsn-bind="test.id">testing</span>
|