vsn 0.1.96 → 0.1.99
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/examples/component-slots.html +26 -0
- package/demo/vsn.js +2 -2
- package/dist/AST/ElementAttributeNode.js +5 -5
- package/dist/AST/ElementAttributeNode.js.map +1 -1
- package/dist/AST/ElementStyleNode.js +2 -2
- package/dist/AST/ElementStyleNode.js.map +1 -1
- package/dist/AST/FunctionCallNode.js +1 -1
- package/dist/AST/FunctionCallNode.js.map +1 -1
- package/dist/AST/ObjectNode.js +1 -1
- package/dist/AST/ObjectNode.js.map +1 -1
- package/dist/AST/ScopeMemberNode.js +2 -2
- package/dist/AST/ScopeMemberNode.js.map +1 -1
- package/dist/Component.js +14 -5
- package/dist/Component.js.map +1 -1
- package/dist/DOM/DOMObject.d.ts +1 -0
- package/dist/DOM/DOMObject.js +7 -0
- package/dist/DOM/DOMObject.js.map +1 -1
- package/dist/DOM.d.ts +2 -3
- package/dist/DOM.js +68 -31
- package/dist/DOM.js.map +1 -1
- package/dist/Formats.js +4 -1
- package/dist/Formats.js.map +1 -1
- package/dist/Query.d.ts +1 -1
- package/dist/Query.js +2 -2
- package/dist/Query.js.map +1 -1
- package/dist/Scope.d.ts +1 -1
- package/dist/Scope.js +17 -1
- package/dist/Scope.js.map +1 -1
- package/dist/Tag/ShadowRootTag.d.ts +3 -0
- package/dist/Tag/ShadowRootTag.js +28 -0
- package/dist/Tag/ShadowRootTag.js.map +1 -0
- package/dist/Tag/SlotTag.d.ts +3 -0
- package/dist/Tag/SlotTag.js +28 -0
- package/dist/Tag/SlotTag.js.map +1 -0
- package/dist/Tag/SlottedTag.d.ts +3 -0
- package/dist/Tag/SlottedTag.js +28 -0
- package/dist/Tag/SlottedTag.js.map +1 -0
- package/dist/Tag/{List.d.ts → TagList.d.ts} +0 -0
- package/dist/Tag/{List.js → TagList.js} +1 -1
- package/dist/Tag/TagList.js.map +1 -0
- package/dist/Tag.d.ts +11 -2
- package/dist/Tag.js +37 -18
- package/dist/Tag.js.map +1 -1
- package/dist/attributes/List.d.ts +2 -1
- package/dist/attributes/List.js +35 -11
- package/dist/attributes/List.js.map +1 -1
- package/dist/attributes/ListItem.js +1 -1
- package/dist/attributes/ListItem.js.map +1 -1
- package/dist/attributes/ScopeAttribute.js +14 -12
- package/dist/attributes/ScopeAttribute.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vsn.min.js +3 -0
- package/dist/vsn.min.js.LICENSE.txt +9 -0
- package/package.json +1 -1
- package/src/AST/ElementAttributeNode.ts +1 -1
- package/src/AST/ElementStyleNode.ts +1 -1
- package/src/AST/FunctionCallNode.ts +1 -1
- package/src/AST/ObjectNode.ts +1 -1
- package/src/AST/ScopeMemberNode.ts +1 -1
- package/src/Component.ts +10 -3
- package/src/DOM/DOMObject.ts +4 -0
- package/src/DOM.ts +28 -5
- package/src/Formats.ts +4 -1
- package/src/Query.ts +1 -1
- package/src/Scope.ts +14 -1
- package/src/Tag/ShadowRootTag.ts +5 -0
- package/src/Tag/SlotTag.ts +5 -0
- package/src/Tag/SlottedTag.ts +5 -0
- package/src/Tag/{List.ts → TagList.ts} +0 -0
- package/src/Tag.ts +23 -19
- package/src/attributes/List.ts +34 -9
- package/src/attributes/ListItem.ts +1 -1
- package/src/attributes/ScopeAttribute.ts +12 -8
- package/src/version.ts +1 -1
- package/test/AST/ClassNode.spec.ts +1 -1
- package/test/Tag/TagList.spec.ts +1 -1
- package/test/attributes/ListItem.spec.ts +2 -3
- package/dist/Tag/List.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
4
|
+
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
5
|
+
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
6
|
+
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
7
|
+
* Code distributed by Google as part of the polymer project is also
|
|
8
|
+
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
9
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Scope} from "../Scope";
|
|
2
2
|
import {DOM} from "../DOM";
|
|
3
3
|
import {Tag} from "../Tag";
|
|
4
|
-
import {TagList} from "../Tag/
|
|
4
|
+
import {TagList} from "../Tag/TagList";
|
|
5
5
|
import {TreeNode} from "../AST";
|
|
6
6
|
import {Node} from "./Node";
|
|
7
7
|
import {ElementQueryNode} from "./ElementQueryNode";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Scope} from "../Scope";
|
|
2
2
|
import {DOM} from "../DOM";
|
|
3
3
|
import {Tag} from "../Tag";
|
|
4
|
-
import {TagList} from "../Tag/
|
|
4
|
+
import {TagList} from "../Tag/TagList";
|
|
5
5
|
import {TreeNode} from "../AST";
|
|
6
6
|
import {Node} from "./Node";
|
|
7
7
|
import {ElementQueryNode} from "./ElementQueryNode";
|
|
@@ -55,7 +55,7 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
|
|
|
55
55
|
|
|
56
56
|
for (const _tag of tags) {
|
|
57
57
|
let tagNum = 0;
|
|
58
|
-
for (const className of _tag.element[ClassNode.ClassesVariable]) {
|
|
58
|
+
for (const className of _tag.element[ClassNode.ClassesVariable] || []) {
|
|
59
59
|
tagNum++;
|
|
60
60
|
const cls = Registry.instance.classes.getSynchronous(className);
|
|
61
61
|
if (cls) {
|
package/src/AST/ObjectNode.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class ObjectNode extends Node implements TreeNode {
|
|
|
21
21
|
for (let i = 0; i < this.values.length; i++) {
|
|
22
22
|
const key = this.keys[i];
|
|
23
23
|
const val = this.values[i];
|
|
24
|
-
obj.set(await key.evaluate(scope, dom, tag), await val.evaluate(scope, dom, tag));
|
|
24
|
+
obj.set(await key.evaluate(scope, dom, tag), await val.evaluate(scope, dom, tag), true);
|
|
25
25
|
}
|
|
26
26
|
return obj;
|
|
27
27
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Scope} from "../Scope";
|
|
2
2
|
import {DOM} from "../DOM";
|
|
3
3
|
import {Tag} from "../Tag";
|
|
4
|
-
import {TagList} from "../Tag/
|
|
4
|
+
import {TagList} from "../Tag/TagList";
|
|
5
5
|
import {DOMObject} from "../DOM/DOMObject";
|
|
6
6
|
import {TreeNode} from "../AST";
|
|
7
7
|
import {Node} from "./Node";
|
package/src/Component.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {Registry} from "./Registry";
|
|
2
2
|
import {DOM} from "./DOM";
|
|
3
|
+
import {SlotTag} from "./Tag/SlotTag";
|
|
4
|
+
import {SlottedTag} from "./Tag/SlottedTag";
|
|
3
5
|
|
|
4
6
|
export class Component extends HTMLElement {
|
|
5
7
|
protected readonly shadow: ShadowRoot;
|
|
@@ -21,14 +23,19 @@ export class Component extends HTMLElement {
|
|
|
21
23
|
this.setAttribute('vsn-ref', '');
|
|
22
24
|
|
|
23
25
|
this.shadow.appendChild(template.content.cloneNode(true));
|
|
24
|
-
this.shadow.querySelectorAll('slot').forEach(slot => {
|
|
26
|
+
this.shadow.querySelectorAll('slot').forEach((slot) => {
|
|
27
|
+
const slotTagPromise = DOM.instance.buildTag(slot,false, SlotTag);
|
|
25
28
|
slot.addEventListener('slotchange', async (e) => {
|
|
26
29
|
for (const child of slot.assignedNodes()) {
|
|
27
|
-
const t = await DOM.instance.
|
|
28
|
-
t?.slotted(slot);
|
|
30
|
+
const t = await DOM.instance.buildTag(child as HTMLElement, false, SlottedTag);
|
|
31
|
+
await t?.slotted(slot);
|
|
29
32
|
}
|
|
33
|
+
slotTagPromise.then((slotTag) => {
|
|
34
|
+
slotTag.buildAttributes();
|
|
35
|
+
});
|
|
30
36
|
});
|
|
31
37
|
});
|
|
38
|
+
|
|
32
39
|
DOM.instance.buildFrom(this.shadow);
|
|
33
40
|
}
|
|
34
41
|
}
|
package/src/DOM/DOMObject.ts
CHANGED
|
@@ -31,6 +31,10 @@ export abstract class DOMObject extends EventDispatcher {
|
|
|
31
31
|
return this.element instanceof HTMLSlotElement;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
public get isSlotted(): boolean {
|
|
35
|
+
return this.element.hasAttribute('slot');
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
public get scope(): Scope {
|
|
35
39
|
if (!!this._scope)
|
|
36
40
|
return this._scope;
|
package/src/DOM.ts
CHANGED
|
@@ -2,13 +2,15 @@ import {Tag} from "./Tag";
|
|
|
2
2
|
import {ElementHelper} from "./helpers/ElementHelper";
|
|
3
3
|
import {Configuration} from "./Configuration";
|
|
4
4
|
import {Tree} from "./AST";
|
|
5
|
-
import {TagList} from "./Tag/
|
|
5
|
+
import {TagList} from "./Tag/TagList";
|
|
6
6
|
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
10
|
import {ClassNode} from "./AST/ClassNode";
|
|
11
11
|
import {Registry} from "./Registry";
|
|
12
|
+
import {SlotTag} from "./Tag/SlotTag";
|
|
13
|
+
import {SlottedTag} from "./Tag/SlottedTag";
|
|
12
14
|
|
|
13
15
|
export enum EQuerySelectDirection {
|
|
14
16
|
ALL,
|
|
@@ -27,7 +29,6 @@ export class DOM extends EventDispatcher {
|
|
|
27
29
|
protected window: WrappedWindow;
|
|
28
30
|
protected document: WrappedDocument;
|
|
29
31
|
protected _built: boolean = false;
|
|
30
|
-
public selected: Tag;
|
|
31
32
|
|
|
32
33
|
constructor(
|
|
33
34
|
protected rootElement: Document,
|
|
@@ -192,6 +193,10 @@ export class DOM extends EventDispatcher {
|
|
|
192
193
|
async discover(ele: HTMLElement, forComponent: boolean = false): Promise<HTMLElement[]> {
|
|
193
194
|
const discovered: HTMLElement[] = [];
|
|
194
195
|
const checkElement = (e: HTMLElement): boolean => {
|
|
196
|
+
if (Registry.instance.components.has(e?.tagName?.toLowerCase())) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
195
200
|
if (ElementHelper.hasVisionAttribute(e)) {
|
|
196
201
|
if (
|
|
197
202
|
(!forComponent && e.hasAttribute('slot'))
|
|
@@ -216,9 +221,14 @@ export class DOM extends EventDispatcher {
|
|
|
216
221
|
return discovered;
|
|
217
222
|
}
|
|
218
223
|
|
|
219
|
-
async buildTag(element: HTMLElement, returnExisting: boolean = false): Promise<Tag> {
|
|
224
|
+
async buildTag(element: HTMLElement, returnExisting: boolean = false, cls: any = Tag): Promise<Tag> {
|
|
220
225
|
if (element[Tag.TaggedVariable]) return returnExisting ? element[Tag.TaggedVariable] : null;
|
|
221
|
-
|
|
226
|
+
if (element.tagName.toLowerCase() === 'slot')
|
|
227
|
+
cls = SlotTag;
|
|
228
|
+
else if (element.hasAttribute('slot'))
|
|
229
|
+
cls = SlottedTag;
|
|
230
|
+
|
|
231
|
+
const tag: Tag = new cls(element, this);
|
|
222
232
|
this.tags.push(tag);
|
|
223
233
|
return tag;
|
|
224
234
|
}
|
|
@@ -261,6 +271,20 @@ export class DOM extends EventDispatcher {
|
|
|
261
271
|
document.ondragover = (e) => e.cancelable && e.preventDefault(); // Allow dragging over document
|
|
262
272
|
}
|
|
263
273
|
|
|
274
|
+
// Setup components first
|
|
275
|
+
const templateNodes = this.querySelectorElement(ele, 'template');
|
|
276
|
+
const components: Tag[] = [];
|
|
277
|
+
for (const n of Array.from(templateNodes) as HTMLElement[]) {
|
|
278
|
+
if (!ElementHelper.hasVisionAttribute(n))
|
|
279
|
+
continue;
|
|
280
|
+
|
|
281
|
+
const tag = await this.buildTag(n);
|
|
282
|
+
if (tag)
|
|
283
|
+
components.push(tag);
|
|
284
|
+
}
|
|
285
|
+
if (components.length)
|
|
286
|
+
await this.setupTags(components);
|
|
287
|
+
|
|
264
288
|
// Create tags for each html element with a vsn-attribute
|
|
265
289
|
const newTags: Tag[] = [];
|
|
266
290
|
const toBuild: HTMLElement[] = await this.discover(ele, forComponent);
|
|
@@ -270,7 +294,6 @@ export class DOM extends EventDispatcher {
|
|
|
270
294
|
if (tag)
|
|
271
295
|
newTags.push(tag);
|
|
272
296
|
}
|
|
273
|
-
|
|
274
297
|
if (isRoot)
|
|
275
298
|
this._root = await this.getTagForElement(document.body);
|
|
276
299
|
|
package/src/Formats.ts
CHANGED
|
@@ -20,7 +20,10 @@ export class Formats {
|
|
|
20
20
|
setup();
|
|
21
21
|
}
|
|
22
22
|
value = `${value}`.replace(/[^0-9.]+/, '');
|
|
23
|
-
|
|
23
|
+
value = parseFloat(value);
|
|
24
|
+
if (isNaN(value))
|
|
25
|
+
return '';
|
|
26
|
+
return Formats.CurrencyFormatter.format(value);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
@Registry.format('date')
|
package/src/Query.ts
CHANGED
package/src/Scope.ts
CHANGED
|
@@ -94,7 +94,20 @@ export class Scope extends EventDispatcher {
|
|
|
94
94
|
return value;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
set(key: string, value: any) {
|
|
97
|
+
set(key: string, value: any, detectType: boolean = false): void {
|
|
98
|
+
if (detectType) {
|
|
99
|
+
const type = typeof value;
|
|
100
|
+
if (type === 'number') {
|
|
101
|
+
if (value % 1 === 0)
|
|
102
|
+
this.setType(key, 'integer');
|
|
103
|
+
else
|
|
104
|
+
this.setType(key, 'float');
|
|
105
|
+
} else if (type === 'string') {
|
|
106
|
+
this.setType(key, 'string');
|
|
107
|
+
} else if (type === 'boolean') {
|
|
108
|
+
this.setType(key, 'boolean');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
98
111
|
if (!this._data.hasProperty(key))
|
|
99
112
|
this._data.createProperty(key);
|
|
100
113
|
this._data[key] = value;
|
|
File without changes
|
package/src/Tag.ts
CHANGED
|
@@ -26,7 +26,9 @@ export class Tag extends DOMObject {
|
|
|
26
26
|
public readonly parsedAttributes: { [key: string]: string[]; };
|
|
27
27
|
public readonly deferredAttributes: Attribute[] = [];
|
|
28
28
|
protected _state: TagState;
|
|
29
|
+
protected _meta: { [key: string]: any; };
|
|
29
30
|
protected attributes: Attribute[];
|
|
31
|
+
protected attributeMap: { [key: string]: Attribute; };
|
|
30
32
|
protected _nonDeferredAttributes: Attribute[] = [];
|
|
31
33
|
protected _parentTag: Tag;
|
|
32
34
|
protected _children: Tag[] = [];
|
|
@@ -59,19 +61,23 @@ export class Tag extends DOMObject {
|
|
|
59
61
|
this.rawAttributes = {};
|
|
60
62
|
this.parsedAttributes = {};
|
|
61
63
|
this.attributes = [];
|
|
64
|
+
this.attributeMap = {};
|
|
62
65
|
this.onEventHandlers = {};
|
|
63
66
|
this.analyzeElementAttributes();
|
|
64
67
|
this._state = TagState.Instantiated;
|
|
65
|
-
if (this.hasAttribute('slot')) {
|
|
66
|
-
this.addEventHandler('slotted',[], (e) => {
|
|
67
|
-
console.log('slot change', e, this.element.assignedSlot);
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
public
|
|
70
|
+
public get meta() {
|
|
71
|
+
if (!this._meta)
|
|
72
|
+
this._meta = {};
|
|
73
|
+
return this._meta;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public async slotted(slot: HTMLSlotElement) {
|
|
73
77
|
this.slot = slot;
|
|
74
|
-
|
|
78
|
+
this.parentTag = await this.dom.getTagForElement(slot);
|
|
79
|
+
await this.dom.setupTags([this]);
|
|
80
|
+
await this.dom.buildFrom(this.element, false, true);
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
protected onAttributeStateChange(event) {
|
|
@@ -432,7 +438,6 @@ export class Tag extends DOMObject {
|
|
|
432
438
|
public async buildAttributes() {
|
|
433
439
|
let requiresScope = false;
|
|
434
440
|
let defer: boolean = false;
|
|
435
|
-
this.attributes.length = 0;
|
|
436
441
|
const isMobile: boolean = VisionHelper.isMobile();
|
|
437
442
|
if (this.element.offsetParent === null ||
|
|
438
443
|
this.hasAttribute('hidden') ||
|
|
@@ -445,17 +450,15 @@ export class Tag extends DOMObject {
|
|
|
445
450
|
const slot: Tag = this.isSlot ? this : null;
|
|
446
451
|
for (const tag of tags) {
|
|
447
452
|
for (let attr in this.rawAttributes) {
|
|
448
|
-
if (
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
+
if (tag.attributeMap[attr])
|
|
454
|
+
continue;
|
|
455
|
+
|
|
456
|
+
if (this.hasModifier(attr, 'mobile') && !isMobile)
|
|
457
|
+
continue;
|
|
453
458
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
+
|
|
460
|
+
if (this.hasModifier(attr, 'desktop') && isMobile)
|
|
461
|
+
continue;
|
|
459
462
|
|
|
460
463
|
const attrClass = await this.getAttributeClass(attr);
|
|
461
464
|
if (attrClass) {
|
|
@@ -463,7 +466,9 @@ export class Tag extends DOMObject {
|
|
|
463
466
|
requiresScope = true;
|
|
464
467
|
|
|
465
468
|
const attrObj = attrClass.create(tag, attr, attrClass, slot);
|
|
469
|
+
|
|
466
470
|
tag.attributes.push(attrObj);
|
|
471
|
+
tag.attributeMap[attr] = attrObj;
|
|
467
472
|
if (defer && attrClass.canDefer) {
|
|
468
473
|
await attrObj.defer();
|
|
469
474
|
tag.deferredAttributes.push(attrObj);
|
|
@@ -489,7 +494,6 @@ export class Tag extends DOMObject {
|
|
|
489
494
|
for (const attr of tag.getAttributesWithState(AttributeState.Instantiated)) {
|
|
490
495
|
await attr.compile();
|
|
491
496
|
}
|
|
492
|
-
|
|
493
497
|
}
|
|
494
498
|
this._state = TagState.AttributesCompiled;
|
|
495
499
|
}
|
package/src/attributes/List.ts
CHANGED
|
@@ -5,9 +5,11 @@ import {ElementHelper} from "../helpers/ElementHelper";
|
|
|
5
5
|
import {Registry} from "../Registry";
|
|
6
6
|
import {DOM} from "../DOM";
|
|
7
7
|
import {Scope} from "../Scope";
|
|
8
|
+
import {ScopeData} from "../Scope/ScopeData";
|
|
8
9
|
|
|
9
10
|
@Registry.attribute('vsn-list')
|
|
10
11
|
export class List extends Attribute {
|
|
12
|
+
public static readonly MetaItemSetupFlag = 'vsn-list-item-setup';
|
|
11
13
|
public static readonly canDefer: boolean = false;
|
|
12
14
|
public static readonly scoped: boolean = true;
|
|
13
15
|
|
|
@@ -51,7 +53,7 @@ export class List extends Attribute {
|
|
|
51
53
|
await this.addExistingItems(items);
|
|
52
54
|
|
|
53
55
|
listScope.on(`change:${listKey}`, (e) => {
|
|
54
|
-
if (e
|
|
56
|
+
if (e?.oldValue) {
|
|
55
57
|
if (e.oldValue instanceof WrappedArray) {
|
|
56
58
|
e.oldValue.map((item) => {
|
|
57
59
|
this.remove(item);
|
|
@@ -145,36 +147,59 @@ export class List extends Attribute {
|
|
|
145
147
|
}
|
|
146
148
|
delete element[Tag.TaggedVariable];
|
|
147
149
|
|
|
150
|
+
// Collect raw data
|
|
151
|
+
let data;
|
|
152
|
+
if (obj instanceof ScopeData)
|
|
153
|
+
data = obj.getData();
|
|
154
|
+
else
|
|
155
|
+
data = Object.assign({}, obj);
|
|
156
|
+
|
|
148
157
|
// Setup new tag
|
|
149
158
|
const tag = await this.tag.dom.buildTag(element, true);
|
|
150
|
-
|
|
151
|
-
await this.setupTag(tag, obj);
|
|
159
|
+
await this.setupTagScope(tag, obj);
|
|
152
160
|
|
|
153
161
|
// Add to DOM & build
|
|
154
162
|
this.tag.element.appendChild(element);
|
|
163
|
+
await this.tag.dom.setupTags([tag]);
|
|
155
164
|
await this.tag.dom.buildFrom(this.tag.element);
|
|
165
|
+
|
|
166
|
+
// Make sure we're using the correct data (Template may have vsn-bind values that are not desired)
|
|
167
|
+
const itemScope = tag.scope.get(this.listItemName);
|
|
168
|
+
if (itemScope instanceof Scope && data) {
|
|
169
|
+
itemScope.data.setData(data);
|
|
170
|
+
}
|
|
171
|
+
|
|
156
172
|
this.tags.push(tag);
|
|
157
173
|
this.tag.dispatch('add', obj);
|
|
158
174
|
}
|
|
159
175
|
|
|
160
|
-
async
|
|
176
|
+
async setupTagScope(tag: Tag, obj: any) {
|
|
177
|
+
if (tag.meta[List.MetaItemSetupFlag])
|
|
178
|
+
return;
|
|
179
|
+
|
|
161
180
|
tag.createScope(true);
|
|
181
|
+
const itemScope = new Scope(tag.scope);
|
|
162
182
|
|
|
163
|
-
// Setup new scope & class, if defined
|
|
183
|
+
// Setup new scope & model class, if defined
|
|
164
184
|
const modelName: string = this.listItemModel;
|
|
165
185
|
let cls;
|
|
166
186
|
if (modelName)
|
|
167
187
|
cls = await Registry.instance.models.get(modelName);
|
|
168
188
|
|
|
169
189
|
if (cls) {
|
|
170
|
-
if (!obj || !(obj instanceof cls))
|
|
190
|
+
if (!obj || !(obj instanceof cls)) {
|
|
171
191
|
obj = new cls(obj);
|
|
192
|
+
}
|
|
172
193
|
}
|
|
173
194
|
|
|
174
195
|
// Check if the class is set up already
|
|
175
|
-
if (!cls || (!(
|
|
176
|
-
|
|
196
|
+
if (!cls || (!(itemScope.data instanceof cls) && !(itemScope.wrapped instanceof cls))) {
|
|
197
|
+
if (itemScope.wrapped)
|
|
198
|
+
itemScope.unwrap();
|
|
199
|
+
itemScope.wrap(obj, true, true);
|
|
200
|
+
}
|
|
177
201
|
|
|
178
|
-
tag.scope.set(this.listItemName,
|
|
202
|
+
tag.scope.set(this.listItemName, itemScope);
|
|
203
|
+
tag.meta[List.MetaItemSetupFlag] = true;
|
|
179
204
|
}
|
|
180
205
|
}
|
|
@@ -20,17 +20,21 @@ export class ScopeAttribute extends Attribute {
|
|
|
20
20
|
|
|
21
21
|
public async extract() {
|
|
22
22
|
if (this.tree) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const binding = this.getAttributeBinding();
|
|
24
|
+
|
|
25
|
+
const scope = await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
|
|
26
|
+
if (!(scope instanceof Scope)) {
|
|
27
|
+
throw new Error(`vsn-scope value must be an object, got ${typeof scope}`);
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
if (binding) {
|
|
31
|
+
this.tag.scope.set(binding, scope);
|
|
32
|
+
} else {
|
|
33
|
+
for (const key of scope.data.keys) {
|
|
34
|
+
this.tag.scope.set(key, scope.data[key]);
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
|
-
const binding = this.getAttributeBinding();
|
|
32
|
-
if (binding)
|
|
33
|
-
this.tag.scope.parentScope.set(binding, this.tag.scope);
|
|
34
38
|
await super.extract();
|
|
35
39
|
}
|
|
36
40
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.99';
|
|
2
2
|
|
package/test/Tag/TagList.spec.ts
CHANGED
|
@@ -72,7 +72,7 @@ describe('ListItem', () => {
|
|
|
72
72
|
list.on('add', () => {
|
|
73
73
|
const listItem = listAttr.tags[0];
|
|
74
74
|
|
|
75
|
-
expect(listItem.scope.data instanceof ListItemSpecTestItem).toBeTrue();
|
|
75
|
+
expect(listItem.scope.get('item').data instanceof ListItemSpecTestItem).toBeTrue();
|
|
76
76
|
expect(controller.items.length).toBe(1);
|
|
77
77
|
expect(controller.items[0] instanceof ListItemSpecTestItem).toBeTrue();
|
|
78
78
|
|
|
@@ -95,7 +95,7 @@ describe('ListItem', () => {
|
|
|
95
95
|
const dom = new DOM(document);
|
|
96
96
|
dom.once('built', async () => {
|
|
97
97
|
const listItem = await dom.getTagForElement(document.getElementById('test-item'));
|
|
98
|
-
expect(listItem.scope.get('testing')).toBe(1);
|
|
98
|
+
expect(listItem.scope.get('item').get('testing')).toBe(1);
|
|
99
99
|
done();
|
|
100
100
|
});
|
|
101
101
|
});
|
|
@@ -107,7 +107,6 @@ describe('ListItem', () => {
|
|
|
107
107
|
</ul>
|
|
108
108
|
`;
|
|
109
109
|
|
|
110
|
-
console.log('################# building dom');
|
|
111
110
|
const dom = new DOM(document);
|
|
112
111
|
dom.once('built', async () => {
|
|
113
112
|
const listItem = await dom.getTagForElement(document.getElementById('test-item'));
|
package/dist/Tag/List.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../src/Tag/List.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,wDAAqD;AAIrD;IAA6B,2BAAgB;IACzC;QAAY,eAAqB;aAArB,UAAqB,EAArB,qBAAqB,EAArB,IAAqB;YAArB,0BAAqB;;QAAjC,+BACa,KAAK,UAEjB;QADG,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;;IACnD,CAAC;IAED,sBAAI,0BAAK;aAAT;YACI,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QACxB,CAAC;;;OAAA;IAED,sBAAI,6BAAQ;aAAZ;YACI,OAAO,IAAI,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,OAAO,EAAT,CAAS,CAAC,CAAC;QACpC,CAAC;;;OAAA;IAED,sBAAI,0BAAK;aAAT;YACI,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,CAAC;;;OAAA;IAED,sBAAI,yBAAI;aAAR;YACI,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACjC,CAAC;;;OAAA;IAED,qBAAG,GAAH,UAAI,KAAa;QACb,IAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAhB,CAAgB,CAAC,CAAC;QACjD,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED,6BAAW,GAAX,UAAY,SAAS;QACjB,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,EAArC,CAAqC,CAAC,CAAA;QACxD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,0BAAQ,GAAR,UAAS,SAAS;QACd,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAlC,CAAkC,CAAC,CAAA;QACrD,OAAO,IAAI,CAAA;IACf,CAAC;IAED,qBAAG,GAAH,UAAI,QAAQ,EAAE,KAAK;QACf,IAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,UAAA,CAAC;YAC5C,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3C,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,EAApC,CAAoC,CAAC,CAAA;QACvD,OAAO,IAAI,CAAA;IACf,CAAC;IACL,cAAC;AAAD,CAAC,AA5CD,CAA6B,KAAK,GA4CjC;AA5CY,0BAAO;AA8CpB,IAAI,2BAAY,CAAC,aAAa,IAAI,2BAAY,CAAC,MAAM;IACjD,MAAM,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC"}
|