vsn 0.1.11 → 0.1.15

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.
@@ -1,30 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- require("./AddClassIf");
4
- require("./Bind");
5
- require("./ClickRemoveClass");
6
- require("./ClickToggleClass");
7
- require("./ControllerAttribute");
8
- require("./DisableIf");
9
- require("./Exec");
10
- require("./Format");
11
- require("./If");
12
- require("./JSONAttribute");
13
- require("./KeyDown");
14
- require("./KeyUp");
15
- require("./List");
16
- require("./ListItem");
17
- require("./ListItemModel");
18
- require("./ModelAttribute");
19
- require("./Name");
20
- require("./On");
21
- require("./Radio");
22
- require("./Referenced");
23
- require("./RootAttribute");
24
- require("./ScopeAttribute");
25
- require("./ScopeChange");
26
- require("./SetAttribute");
27
- require("./StandardAttribute");
28
- require("./Template");
29
- require("./TypeAttribute");
3
+ exports.TypeAttribute = exports.Template = exports.StandardAttribute = exports.SetAttribute = exports.ScopeChange = exports.ScopeAttribute = exports.RootAttribute = exports.Referenced = exports.Radio = exports.On = exports.Name = exports.ModelAttribute = exports.ListItemModel = exports.ListItem = exports.List = exports.KeyUp = exports.KeyDown = exports.JSONAttribute = exports.If = exports.Format = exports.Exec = exports.DisableIf = exports.ControllerAttribute = exports.ClickToggleClass = exports.ClickRemoveClass = exports.Bind = exports.AddClassIf = void 0;
4
+ var AddClassIf_1 = require("./AddClassIf");
5
+ Object.defineProperty(exports, "AddClassIf", { enumerable: true, get: function () { return AddClassIf_1.AddClassIf; } });
6
+ var Bind_1 = require("./Bind");
7
+ Object.defineProperty(exports, "Bind", { enumerable: true, get: function () { return Bind_1.Bind; } });
8
+ var ClickRemoveClass_1 = require("./ClickRemoveClass");
9
+ Object.defineProperty(exports, "ClickRemoveClass", { enumerable: true, get: function () { return ClickRemoveClass_1.ClickRemoveClass; } });
10
+ var ClickToggleClass_1 = require("./ClickToggleClass");
11
+ Object.defineProperty(exports, "ClickToggleClass", { enumerable: true, get: function () { return ClickToggleClass_1.ClickToggleClass; } });
12
+ var ControllerAttribute_1 = require("./ControllerAttribute");
13
+ Object.defineProperty(exports, "ControllerAttribute", { enumerable: true, get: function () { return ControllerAttribute_1.ControllerAttribute; } });
14
+ var DisableIf_1 = require("./DisableIf");
15
+ Object.defineProperty(exports, "DisableIf", { enumerable: true, get: function () { return DisableIf_1.DisableIf; } });
16
+ var Exec_1 = require("./Exec");
17
+ Object.defineProperty(exports, "Exec", { enumerable: true, get: function () { return Exec_1.Exec; } });
18
+ var Format_1 = require("./Format");
19
+ Object.defineProperty(exports, "Format", { enumerable: true, get: function () { return Format_1.Format; } });
20
+ var If_1 = require("./If");
21
+ Object.defineProperty(exports, "If", { enumerable: true, get: function () { return If_1.If; } });
22
+ var JSONAttribute_1 = require("./JSONAttribute");
23
+ Object.defineProperty(exports, "JSONAttribute", { enumerable: true, get: function () { return JSONAttribute_1.JSONAttribute; } });
24
+ var KeyDown_1 = require("./KeyDown");
25
+ Object.defineProperty(exports, "KeyDown", { enumerable: true, get: function () { return KeyDown_1.KeyDown; } });
26
+ var KeyUp_1 = require("./KeyUp");
27
+ Object.defineProperty(exports, "KeyUp", { enumerable: true, get: function () { return KeyUp_1.KeyUp; } });
28
+ var List_1 = require("./List");
29
+ Object.defineProperty(exports, "List", { enumerable: true, get: function () { return List_1.List; } });
30
+ var ListItem_1 = require("./ListItem");
31
+ Object.defineProperty(exports, "ListItem", { enumerable: true, get: function () { return ListItem_1.ListItem; } });
32
+ var ListItemModel_1 = require("./ListItemModel");
33
+ Object.defineProperty(exports, "ListItemModel", { enumerable: true, get: function () { return ListItemModel_1.ListItemModel; } });
34
+ var ModelAttribute_1 = require("./ModelAttribute");
35
+ Object.defineProperty(exports, "ModelAttribute", { enumerable: true, get: function () { return ModelAttribute_1.ModelAttribute; } });
36
+ var Name_1 = require("./Name");
37
+ Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return Name_1.Name; } });
38
+ var On_1 = require("./On");
39
+ Object.defineProperty(exports, "On", { enumerable: true, get: function () { return On_1.On; } });
40
+ var Radio_1 = require("./Radio");
41
+ Object.defineProperty(exports, "Radio", { enumerable: true, get: function () { return Radio_1.Radio; } });
42
+ var Referenced_1 = require("./Referenced");
43
+ Object.defineProperty(exports, "Referenced", { enumerable: true, get: function () { return Referenced_1.Referenced; } });
44
+ var RootAttribute_1 = require("./RootAttribute");
45
+ Object.defineProperty(exports, "RootAttribute", { enumerable: true, get: function () { return RootAttribute_1.RootAttribute; } });
46
+ var ScopeAttribute_1 = require("./ScopeAttribute");
47
+ Object.defineProperty(exports, "ScopeAttribute", { enumerable: true, get: function () { return ScopeAttribute_1.ScopeAttribute; } });
48
+ var ScopeChange_1 = require("./ScopeChange");
49
+ Object.defineProperty(exports, "ScopeChange", { enumerable: true, get: function () { return ScopeChange_1.ScopeChange; } });
50
+ var SetAttribute_1 = require("./SetAttribute");
51
+ Object.defineProperty(exports, "SetAttribute", { enumerable: true, get: function () { return SetAttribute_1.SetAttribute; } });
52
+ var StandardAttribute_1 = require("./StandardAttribute");
53
+ Object.defineProperty(exports, "StandardAttribute", { enumerable: true, get: function () { return StandardAttribute_1.StandardAttribute; } });
54
+ var Template_1 = require("./Template");
55
+ Object.defineProperty(exports, "Template", { enumerable: true, get: function () { return Template_1.Template; } });
56
+ var TypeAttribute_1 = require("./TypeAttribute");
57
+ Object.defineProperty(exports, "TypeAttribute", { enumerable: true, get: function () { return TypeAttribute_1.TypeAttribute; } });
30
58
  //# sourceMappingURL=_imports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_imports.js","sourceRoot":"","sources":["../../src/attributes/_imports.ts"],"names":[],"mappings":";;AAAA,wBAAsB;AACtB,kBAAgB;AAChB,8BAA4B;AAC5B,8BAA4B;AAC5B,iCAA+B;AAC/B,uBAAqB;AACrB,kBAAgB;AAChB,oBAAkB;AAClB,gBAAc;AACd,2BAAyB;AACzB,qBAAmB;AACnB,mBAAiB;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;AACnB,+CAA4C;AAApC,4GAAA,YAAY,OAAA;AACpB,yDAAsD;AAA9C,sHAAA,iBAAiB,OAAA;AACzB,uCAAoC;AAA5B,oGAAA,QAAQ,OAAA;AAChB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.11",
3
+ "version": "0.1.15",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
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: /^\.@[_a-zA-Z0-9]*/
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: /^\?([#.\[\]:,=\-_a-zA-Z0-9*\s]*[\]_a-zA-Z0-9*])/
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
- return [
1202
- this.elementRef
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
- const tags: TagList = await this.elementRef.evaluate(scope, dom, tag);
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
- await this.elementRef.prepare(scope, dom, tag);
1221
- const tags: TagList = await this.elementRef.evaluate(scope, dom, tag);
1222
- for (const tag of tags)
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
- if (node instanceof ElementQueryNode) {
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 && !(this.wrapped[field] instanceof WrappedArray)) {
362
- this.wrapped[field] = new WrappedArray(...toWrap[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/Vision.ts CHANGED
@@ -1,11 +1,10 @@
1
1
  import {DOM} from "./DOM";
2
2
  import {EventDispatcher} from "simple-ts-event-dispatcher";
3
- import {Scope, WrappedArray} from "./Scope";
3
+ import {WrappedArray} from "./Scope";
4
4
  import {DataModel} from "simple-ts-models";
5
5
  import {Registry} from "./Registry";
6
6
  import "./Types";
7
7
  import "./Formats";
8
- import "./attributes/_imports";
9
8
  import {Configuration} from "./Configuration";
10
9
  import {VisionHelper} from "./helpers/VisionHelper";
11
10
  import {Tree} from "./AST";
@@ -57,7 +56,7 @@ export class Vision extends EventDispatcher {
57
56
  await this._dom.buildFrom(document, true);
58
57
  const now = (new Date()).getTime();
59
58
  const setupTime = now - startTime;
60
- console.warn(`Took ${setupTime}ms to start up VisionJS`);
59
+ console.warn(`Took ${setupTime}ms to start up VisionJS. https://www.vsnjs.com/`);
61
60
  }
62
61
 
63
62
  public static get instance() {
@@ -68,6 +67,7 @@ export class Vision extends EventDispatcher {
68
67
  }
69
68
  }
70
69
 
70
+ export * from "./attributes/_imports";
71
71
  export * from './Registry';
72
72
  export * from './Attribute';
73
73
  export const vision: Vision = Vision.instance;
@@ -1,27 +1,27 @@
1
- import "./AddClassIf";
2
- import "./Bind";
3
- import "./ClickRemoveClass";
4
- import "./ClickToggleClass";
5
- import "./ControllerAttribute";
6
- import "./DisableIf";
7
- import "./Exec";
8
- import "./Format";
9
- import "./If";
10
- import "./JSONAttribute";
11
- import "./KeyDown";
12
- import "./KeyUp";
13
- import "./List";
14
- import "./ListItem";
15
- import "./ListItemModel";
16
- import "./ModelAttribute";
17
- import "./Name";
18
- import "./On";
19
- import "./Radio";
20
- import "./Referenced";
21
- import "./RootAttribute";
22
- import "./ScopeAttribute";
23
- import "./ScopeChange";
24
- import "./SetAttribute";
25
- import "./StandardAttribute";
26
- import "./Template";
27
- import "./TypeAttribute";
1
+ export {AddClassIf} from "./AddClassIf";
2
+ export {Bind} from "./Bind";
3
+ export {ClickRemoveClass} from "./ClickRemoveClass";
4
+ export {ClickToggleClass} from "./ClickToggleClass";
5
+ export {ControllerAttribute} from "./ControllerAttribute";
6
+ export {DisableIf} from "./DisableIf";
7
+ export {Exec} from "./Exec";
8
+ export {Format} from "./Format";
9
+ export {If} from "./If";
10
+ export {JSONAttribute} from "./JSONAttribute";
11
+ export {KeyDown} from "./KeyDown";
12
+ export {KeyUp} from "./KeyUp";
13
+ export {List} from "./List";
14
+ export {ListItem} from "./ListItem";
15
+ export {ListItemModel} from "./ListItemModel";
16
+ export {ModelAttribute} from "./ModelAttribute";
17
+ export {Name} from "./Name";
18
+ export {On} from "./On";
19
+ export {Radio} from "./Radio";
20
+ export {Referenced} from "./Referenced";
21
+ export {RootAttribute} from "./RootAttribute";
22
+ export {ScopeAttribute} from "./ScopeAttribute";
23
+ export {ScopeChange} from "./ScopeChange";
24
+ export {SetAttribute} from "./SetAttribute";
25
+ export {StandardAttribute} from "./StandardAttribute";
26
+ export {Template} from "./Template";
27
+ export {TypeAttribute} from "./TypeAttribute";
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('(?#parent).asd')).toBe(123);
32
- expect(await dom.eval('(?#testing).asd')).toBe(345);
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
  });
@@ -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>