vsn 0.1.94 → 0.1.97

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.
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.94",
3
+ "version": "0.1.97",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -226,8 +226,13 @@ export class ClassNode extends Node implements TreeNode {
226
226
  tag = await dom.getTagForElement(element, true);
227
227
  }
228
228
 
229
+ if (!tag) {
230
+ console.error('no tag found for element', element);
231
+ return;
232
+ }
233
+
229
234
  const classNode: ClassNode = Registry.instance.classes.getSynchronous(selector);
230
- if (classNode && tag) {
235
+ if (classNode) {
231
236
  await classNode.constructTag(tag, dom);
232
237
  }
233
238
 
package/src/DOM.ts CHANGED
@@ -223,47 +223,29 @@ export class DOM extends EventDispatcher {
223
223
  return tag;
224
224
  }
225
225
 
226
- async buildFrom(ele: any, isRoot: boolean = false, forComponent: boolean = false) {
227
- if (isRoot) {
228
- document.body.setAttribute('vsn-root', '');
229
- document.ondragover = (e) => e.cancelable && e.preventDefault(); // Allow dragging over document
230
- }
231
-
232
- // Create tags for each html element with a vsn-attribute
233
- const newTags: Tag[] = [];
234
- const toBuild: HTMLElement[] = await this.discover(ele, forComponent);
235
-
236
- for (const element of toBuild) {
237
- const tag = await this.buildTag(element);
238
- if (tag)
239
- newTags.push(tag);
240
- }
241
-
242
- if (isRoot)
243
- this._root = await this.getTagForElement(document.body);
244
-
245
- // Configure, setup & execute attributes
246
- for (const tag of newTags)
226
+ async setupTags(tags: Tag[]) {
227
+ // Configure, setup & execute attributes
228
+ for (const tag of tags)
247
229
  await tag.buildAttributes();
248
230
 
249
- for (const tag of newTags)
231
+ for (const tag of tags)
250
232
  await tag.compileAttributes();
251
233
 
252
- for (const tag of newTags)
234
+ for (const tag of tags)
253
235
  await tag.setupAttributes();
254
236
 
255
- for (const tag of newTags)
237
+ for (const tag of tags)
256
238
  await tag.extractAttributes();
257
239
 
258
- for (const tag of newTags)
240
+ for (const tag of tags)
259
241
  await tag.connectAttributes();
260
242
 
261
- for (const tag of newTags) {
243
+ for (const tag of tags) {
262
244
  await tag.finalize();
263
245
  this.queued.splice(this.queued.indexOf(tag.element), 1);
264
246
  }
265
247
 
266
- for (const tag of newTags) {
248
+ for (const tag of tags) {
267
249
  this.observer.observe(tag.element, {
268
250
  attributes: true,
269
251
  characterData: true,
@@ -271,6 +253,28 @@ export class DOM extends EventDispatcher {
271
253
  subtree: true
272
254
  });
273
255
  }
256
+ }
257
+
258
+ async buildFrom(ele: any, isRoot: boolean = false, forComponent: boolean = false) {
259
+ if (isRoot) {
260
+ document.body.setAttribute('vsn-root', '');
261
+ document.ondragover = (e) => e.cancelable && e.preventDefault(); // Allow dragging over document
262
+ }
263
+
264
+ // Create tags for each html element with a vsn-attribute
265
+ const newTags: Tag[] = [];
266
+ const toBuild: HTMLElement[] = await this.discover(ele, forComponent);
267
+
268
+ for (const element of toBuild) {
269
+ const tag = await this.buildTag(element);
270
+ if (tag)
271
+ newTags.push(tag);
272
+ }
273
+
274
+ if (isRoot)
275
+ this._root = await this.getTagForElement(document.body);
276
+
277
+ await this.setupTags(newTags);
274
278
 
275
279
  if (isRoot) {
276
280
  this._built = true;
package/src/Tag.ts CHANGED
@@ -489,7 +489,6 @@ export class Tag extends DOMObject {
489
489
  for (const attr of tag.getAttributesWithState(AttributeState.Instantiated)) {
490
490
  await attr.compile();
491
491
  }
492
-
493
492
  }
494
493
  this._state = TagState.AttributesCompiled;
495
494
  }
@@ -51,7 +51,7 @@ export class List extends Attribute {
51
51
  await this.addExistingItems(items);
52
52
 
53
53
  listScope.on(`change:${listKey}`, (e) => {
54
- if (e.oldValue) {
54
+ if (e?.oldValue) {
55
55
  if (e.oldValue instanceof WrappedArray) {
56
56
  e.oldValue.map((item) => {
57
57
  this.remove(item);
@@ -147,6 +147,17 @@ export class List extends Attribute {
147
147
 
148
148
  // Setup new tag
149
149
  const tag = await this.tag.dom.buildTag(element, true);
150
+ await this.setupTagScope(tag, obj);
151
+
152
+ // Add to DOM & build
153
+ this.tag.element.appendChild(element);
154
+ await this.tag.dom.setupTags([tag]);
155
+ await this.tag.dom.buildFrom(this.tag.element);
156
+ this.tags.push(tag);
157
+ this.tag.dispatch('add', obj);
158
+ }
159
+
160
+ async setupTagScope(tag: Tag, obj: any) {
150
161
  tag.createScope(true);
151
162
 
152
163
  // Setup new scope & class, if defined
@@ -156,18 +167,17 @@ export class List extends Attribute {
156
167
  cls = await Registry.instance.models.get(modelName);
157
168
 
158
169
  if (cls) {
159
- if (!obj || !(obj instanceof cls)) {
170
+ if (!obj || !(obj instanceof cls))
160
171
  obj = new cls(obj);
161
- }
162
172
  }
163
173
 
164
- tag.scope.set(this.listItemName, tag.scope);
165
- tag.wrap(obj);
174
+ // Check if the class is set up already
175
+ if (!cls || (!(tag.scope.data instanceof cls) && !(tag.scope.wrapped instanceof cls))) {
176
+ if (tag.scope.wrapped)
177
+ tag.scope.unwrap();
178
+ tag.wrap(obj);
179
+ }
166
180
 
167
- // Add to DOM & build
168
- this.tag.element.appendChild(element);
169
- await this.tag.dom.buildFrom(this.tag.element);
170
- this.tags.push(tag);
171
- this.tag.dispatch('add', obj);
181
+ tag.scope.set(this.listItemName, tag.scope);
172
182
  }
173
183
  }
@@ -19,8 +19,8 @@ export class ListItem extends Attribute {
19
19
  if (!this._list)
20
20
  throw Error(ListItem.ERROR_NO_PARENT);
21
21
 
22
- this.tag.scope.set((await this.getListAttribute()).listItemName, this.tag.scope);
23
-
22
+ const listAttr = await this.getListAttribute();
23
+ await listAttr.setupTagScope(this.tag, {});
24
24
  await super.setup();
25
25
  }
26
26
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.94';
1
+ export const VERSION = '0.1.97';
2
2
 
@@ -89,15 +89,12 @@ describe('ListItem', () => {
89
89
 
90
90
  it("vsn-list-item should work with vsn-set", (done) => {
91
91
  document.body.innerHTML = `
92
- <ul vsn-list:list list-item-model="ListItemSpecTestItem" id="test"><li vsn-list-item:item id="test-item" vsn-set:item.testing|integer="1"></li></ul>
92
+ <ul vsn-list:list list-item-model="ListItemSpecTestItem" id="test"><li vsn-list-item id="test-item" vsn-set:item.testing|integer="1"></li></ul>
93
93
  `;
94
94
 
95
95
  const dom = new DOM(document);
96
96
  dom.once('built', async () => {
97
- const list = await dom.getTagForElement(document.getElementById('test'));
98
97
  const listItem = await dom.getTagForElement(document.getElementById('test-item'));
99
- const listItemAttr: ListItem = await listItem.getAttribute('vsn-list-item') as ListItem;
100
-
101
98
  expect(listItem.scope.get('testing')).toBe(1);
102
99
  done();
103
100
  });
@@ -110,7 +107,6 @@ describe('ListItem', () => {
110
107
  </ul>
111
108
  `;
112
109
 
113
- console.log('################# building dom');
114
110
  const dom = new DOM(document);
115
111
  dom.once('built', async () => {
116
112
  const listItem = await dom.getTagForElement(document.getElementById('test-item'));