vsn 0.1.88 → 0.1.91
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 +225 -17
- package/demo/vsn.js +2 -2
- package/dist/DOM.js +5 -3
- package/dist/DOM.js.map +1 -1
- package/dist/Scope/WrappedArray.d.ts +1 -1
- package/dist/Scope/WrappedArray.js +2 -2
- package/dist/Scope/WrappedArray.js.map +1 -1
- package/dist/attributes/List.d.ts +0 -3
- package/dist/attributes/List.js +60 -58
- package/dist/attributes/List.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vsn.min.js +2 -2
- package/package.json +1 -1
- package/src/DOM.ts +6 -4
- package/src/Scope/WrappedArray.ts +2 -2
- package/src/attributes/List.ts +31 -16
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/DOM.ts
CHANGED
|
@@ -199,19 +199,21 @@ export class DOM extends EventDispatcher {
|
|
|
199
199
|
const newTags: Tag[] = [];
|
|
200
200
|
const toBuild: HTMLElement[] = [];
|
|
201
201
|
|
|
202
|
-
const checkElement = (e: HTMLElement) => {
|
|
202
|
+
const checkElement = (e: HTMLElement): boolean => {
|
|
203
203
|
if (ElementHelper.hasVisionAttribute(e)) {
|
|
204
204
|
if (
|
|
205
205
|
(!forComponent && e.hasAttribute('slot'))
|
|
206
|
-
) return;
|
|
207
|
-
if (this.queued.indexOf(e) > -1) return;
|
|
206
|
+
) return false;
|
|
207
|
+
if (this.queued.indexOf(e) > -1) return false;
|
|
208
208
|
this.queued.push(e);
|
|
209
209
|
toBuild.push(e);
|
|
210
210
|
}
|
|
211
|
+
|
|
212
|
+
return true;
|
|
211
213
|
}
|
|
212
214
|
const scanChildren = (e: HTMLElement) => {
|
|
213
215
|
for (const element of Array.from(e.children) as HTMLElement[]) {
|
|
214
|
-
checkElement(element);
|
|
216
|
+
if (!checkElement(element)) continue;
|
|
215
217
|
if (element.tagName.toLowerCase() !== 'template')
|
|
216
218
|
scanChildren(element);
|
|
217
219
|
}
|
|
@@ -14,8 +14,8 @@ export class WrappedArray<T> extends Array<T> {
|
|
|
14
14
|
this.dispatcher.dispatch(event, ...args);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
on(event: string, callback: EventDispatcherCallback) {
|
|
18
|
-
this.dispatcher.on(event, callback);
|
|
17
|
+
on(event: string, callback: EventDispatcherCallback, ctx?: any) {
|
|
18
|
+
this.dispatcher.on(event, callback, ctx);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
off(event: string, key?: number) {
|
package/src/attributes/List.ts
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import {Attribute} from "../Attribute";
|
|
2
2
|
import {Tag} from "../Tag";
|
|
3
3
|
import {WrappedArray} from "../Scope/WrappedArray";
|
|
4
|
-
import {Tree} from "../AST";
|
|
5
4
|
import {ElementHelper} from "../helpers/ElementHelper";
|
|
6
5
|
import {Registry} from "../Registry";
|
|
7
6
|
import {DOM} from "../DOM";
|
|
7
|
+
import {Scope} from "../Scope";
|
|
8
8
|
|
|
9
9
|
@Registry.attribute('vsn-list')
|
|
10
10
|
export class List extends Attribute {
|
|
11
11
|
public static readonly canDefer: boolean = false;
|
|
12
12
|
public static readonly scoped: boolean = true;
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
public items: any[];
|
|
15
15
|
public tags: Tag[];
|
|
16
16
|
protected template: Node;
|
|
17
17
|
|
|
18
|
-
public async compile() {
|
|
19
|
-
const listAttr: string = this.getAttributeBinding();
|
|
20
|
-
this.tree = new Tree(listAttr);
|
|
21
|
-
await this.tree.prepare(this.tag.scope, this.tag.dom, this.tag);
|
|
22
|
-
await super.compile();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
18
|
public async setup() {
|
|
26
19
|
if (this.tag.element.children.length > 0) {
|
|
27
20
|
const template = this.tag.element.children[0];
|
|
@@ -50,9 +43,26 @@ export class List extends Attribute {
|
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
public async extract() {
|
|
53
|
-
const
|
|
46
|
+
const listAttr: string = this.getAttributeBinding('items');
|
|
47
|
+
const ref = this.tag.scope.getReference(listAttr);
|
|
48
|
+
const listScope: Scope = await ref.getScope();
|
|
49
|
+
const listKey: string = await ref.getKey();
|
|
50
|
+
const items = listScope.get(listKey);
|
|
54
51
|
await this.addExistingItems(items);
|
|
55
52
|
|
|
53
|
+
listScope.on(`change:${listKey}`, (e) => {
|
|
54
|
+
if (e.oldValue) {
|
|
55
|
+
if (e.oldValue instanceof WrappedArray) {
|
|
56
|
+
e.oldValue.map((item) => {
|
|
57
|
+
this.remove(item);
|
|
58
|
+
});
|
|
59
|
+
e.oldValue.offWithContext('add', this);
|
|
60
|
+
e.oldValue.offWithContext('remove', this);
|
|
61
|
+
}
|
|
62
|
+
this.addExistingItems(e.value);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
56
66
|
if (this.tag.hasRawAttribute('initial-items')) {
|
|
57
67
|
const toAdd: number = parseInt(this.tag.getRawAttributeValue('initial-items'));
|
|
58
68
|
for (let i = 0; i < toAdd; i++) {
|
|
@@ -64,6 +74,14 @@ export class List extends Attribute {
|
|
|
64
74
|
|
|
65
75
|
protected async addExistingItems(defaultList: any[] | null) {
|
|
66
76
|
this.items = defaultList || new WrappedArray();
|
|
77
|
+
|
|
78
|
+
if (this.tags?.length > 0) {
|
|
79
|
+
for (const tag of this.tags) {
|
|
80
|
+
tag.deconstruct();
|
|
81
|
+
tag.removeFromDOM();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
67
85
|
this.tags = [];
|
|
68
86
|
|
|
69
87
|
if (defaultList)
|
|
@@ -86,12 +104,8 @@ export class List extends Attribute {
|
|
|
86
104
|
this.items = new WrappedArray(this.items);
|
|
87
105
|
}
|
|
88
106
|
|
|
89
|
-
(this.items as WrappedArray<any>).on('add',
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
(this.items as WrappedArray<any>).on('remove', (item) => {
|
|
93
|
-
this.remove(item);
|
|
94
|
-
});
|
|
107
|
+
(this.items as WrappedArray<any>).on('add', this.add, this);
|
|
108
|
+
(this.items as WrappedArray<any>).on('remove', this.remove, this);
|
|
95
109
|
|
|
96
110
|
this.tag.scope.set('add', this.add.bind(this));
|
|
97
111
|
this.tag.scope.set('remove', this.remove.bind(this));
|
|
@@ -110,6 +124,7 @@ export class List extends Attribute {
|
|
|
110
124
|
const tag: Tag = this.tags[i];
|
|
111
125
|
const listItem = tag.scope.get(this.listItemName);
|
|
112
126
|
if ([listItem, listItem.wrapped].indexOf(item) > -1) {
|
|
127
|
+
tag.deconstruct();
|
|
113
128
|
tag.removeFromDOM();
|
|
114
129
|
this.tags.splice(i, 1);
|
|
115
130
|
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.91';
|
|
2
2
|
|