vsn 0.1.111 → 0.1.113

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.
Files changed (41) hide show
  1. package/demo/demo.html +2 -0
  2. package/demo/vsn.js +2 -2
  3. package/demo/xhr-response.html +1 -0
  4. package/demo/xhr-test.html +20 -0
  5. package/dist/AST/FunctionCallNode.js +54 -47
  6. package/dist/AST/FunctionCallNode.js.map +1 -1
  7. package/dist/AST/ScopeMemberNode.js +2 -0
  8. package/dist/AST/ScopeMemberNode.js.map +1 -1
  9. package/dist/Controller.d.ts +1 -2
  10. package/dist/Controller.js +7 -9
  11. package/dist/Controller.js.map +1 -1
  12. package/dist/Scope/ScopeDataAbstract.js +2 -1
  13. package/dist/Scope/ScopeDataAbstract.js.map +1 -1
  14. package/dist/Tag.js +13 -1
  15. package/dist/Tag.js.map +1 -1
  16. package/dist/attributes/ControllerAttribute.d.ts +0 -1
  17. package/dist/attributes/ControllerAttribute.js +13 -12
  18. package/dist/attributes/ControllerAttribute.js.map +1 -1
  19. package/dist/attributes/SetAttribute.d.ts +0 -1
  20. package/dist/attributes/SetAttribute.js +16 -27
  21. package/dist/attributes/SetAttribute.js.map +1 -1
  22. package/dist/attributes/XHRAttribute.d.ts +12 -0
  23. package/dist/attributes/XHRAttribute.js +180 -0
  24. package/dist/attributes/XHRAttribute.js.map +1 -0
  25. package/dist/attributes/_imports.d.ts +1 -0
  26. package/dist/attributes/_imports.js +3 -1
  27. package/dist/attributes/_imports.js.map +1 -1
  28. package/dist/version.d.ts +1 -1
  29. package/dist/version.js +1 -1
  30. package/package.json +1 -1
  31. package/src/AST/FunctionCallNode.ts +5 -0
  32. package/src/AST/ScopeMemberNode.ts +2 -0
  33. package/src/Controller.ts +9 -8
  34. package/src/Scope/ScopeDataAbstract.ts +4 -4
  35. package/src/Tag.ts +10 -1
  36. package/src/attributes/ControllerAttribute.ts +10 -12
  37. package/src/attributes/SetAttribute.ts +1 -5
  38. package/src/attributes/XHRAttribute.ts +67 -0
  39. package/src/attributes/_imports.ts +1 -0
  40. package/src/version.ts +1 -1
  41. package/test/Controller.spec.ts +8 -5
@@ -0,0 +1,12 @@
1
+ import { Attribute } from "../Attribute";
2
+ import { Tree } from "../AST";
3
+ export declare class XHRAttribute extends Attribute {
4
+ static readonly canDefer: boolean;
5
+ protected tree: Tree;
6
+ get code(): any;
7
+ compile(): Promise<void>;
8
+ connect(): Promise<void>;
9
+ get isForm(): boolean;
10
+ get isAnchor(): boolean;
11
+ handleEvent(e: any): Promise<void>;
12
+ }
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
24
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
+ return new (P || (P = Promise))(function (resolve, reject) {
26
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+ var __generator = (this && this.__generator) || function (thisArg, body) {
33
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
34
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
+ function verb(n) { return function (v) { return step([n, v]); }; }
36
+ function step(op) {
37
+ if (f) throw new TypeError("Generator is already executing.");
38
+ while (_) try {
39
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
40
+ if (y = 0, t) op = [op[0] & 2, t.value];
41
+ switch (op[0]) {
42
+ case 0: case 1: t = op; break;
43
+ case 4: _.label++; return { value: op[1], done: false };
44
+ case 5: _.label++; y = op[1]; op = [0]; continue;
45
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
+ default:
47
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
+ if (t[2]) _.ops.pop();
52
+ _.trys.pop(); continue;
53
+ }
54
+ op = body.call(thisArg, _);
55
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
+ }
58
+ };
59
+ Object.defineProperty(exports, "__esModule", { value: true });
60
+ exports.XHRAttribute = void 0;
61
+ var Registry_1 = require("../Registry");
62
+ var Attribute_1 = require("../Attribute");
63
+ var AST_1 = require("../AST");
64
+ var XHRAttribute = /** @class */ (function (_super) {
65
+ __extends(XHRAttribute, _super);
66
+ function XHRAttribute() {
67
+ return _super !== null && _super.apply(this, arguments) || this;
68
+ }
69
+ Object.defineProperty(XHRAttribute.prototype, "code", {
70
+ get: function () {
71
+ return this.getAttributeValue();
72
+ },
73
+ enumerable: false,
74
+ configurable: true
75
+ });
76
+ XHRAttribute.prototype.compile = function () {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ this.tree = new AST_1.Tree(this.code);
82
+ return [4 /*yield*/, this.tree.prepare(this.tag.scope, this.tag.dom, this.tag)];
83
+ case 1:
84
+ _a.sent();
85
+ return [4 /*yield*/, _super.prototype.compile.call(this)];
86
+ case 2:
87
+ _a.sent();
88
+ return [2 /*return*/];
89
+ }
90
+ });
91
+ });
92
+ };
93
+ XHRAttribute.prototype.connect = function () {
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0:
98
+ if (this.isForm) {
99
+ this.tag.addEventHandler('submit', this.getAttributeModifiers(), this.handleEvent, this);
100
+ }
101
+ else if (this.isAnchor) {
102
+ this.tag.addEventHandler('click', this.getAttributeModifiers(), this.handleEvent, this);
103
+ }
104
+ return [4 /*yield*/, _super.prototype.connect.call(this)];
105
+ case 1:
106
+ _a.sent();
107
+ return [2 /*return*/];
108
+ }
109
+ });
110
+ });
111
+ };
112
+ Object.defineProperty(XHRAttribute.prototype, "isForm", {
113
+ get: function () {
114
+ return this.tag.element.tagName === 'FORM';
115
+ },
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ Object.defineProperty(XHRAttribute.prototype, "isAnchor", {
120
+ get: function () {
121
+ return this.tag.element.tagName === 'A';
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ XHRAttribute.prototype.handleEvent = function (e) {
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ var request, method, url, data;
129
+ var _this = this;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ e.preventDefault();
134
+ request = new XMLHttpRequest();
135
+ request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
136
+ if (this.isForm) {
137
+ url = this.tag.element.getAttribute('action');
138
+ method = this.getAttributeBinding(this.tag.element.getAttribute('method'));
139
+ data = new FormData(this.tag.element);
140
+ }
141
+ else if (this.isAnchor) {
142
+ url = this.tag.element.getAttribute('href');
143
+ method = this.getAttributeBinding('GET');
144
+ }
145
+ request.onload = function () { return __awaiter(_this, void 0, void 0, function () {
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ this.tag.scope.set('status', request.status);
150
+ if (!(request.status >= 200 && request.status < 300)) return [3 /*break*/, 2];
151
+ this.tag.scope.set('response', request.response);
152
+ return [4 /*yield*/, this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag)];
153
+ case 1:
154
+ _a.sent();
155
+ return [3 /*break*/, 3];
156
+ case 2:
157
+ console.error(request.statusText);
158
+ _a.label = 3;
159
+ case 3: return [2 /*return*/];
160
+ }
161
+ });
162
+ }); };
163
+ request.open(method, url);
164
+ request.send(data);
165
+ return [4 /*yield*/, this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag)];
166
+ case 1:
167
+ _a.sent();
168
+ return [2 /*return*/];
169
+ }
170
+ });
171
+ });
172
+ };
173
+ XHRAttribute.canDefer = false;
174
+ XHRAttribute = __decorate([
175
+ Registry_1.Registry.attribute('vsn-xhr')
176
+ ], XHRAttribute);
177
+ return XHRAttribute;
178
+ }(Attribute_1.Attribute));
179
+ exports.XHRAttribute = XHRAttribute;
180
+ //# sourceMappingURL=XHRAttribute.js.map
@@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AI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAA;;wCAAhE,SAAgE,CAAC;;;wCAEjE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;;;;;6BAEzC,CAAA;wBACD,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;wBAC1B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBAEnB,qBAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAA;;wBAAhE,SAAgE,CAAC;;;;;KACpE;IA3DsB,qBAAQ,GAAY,KAAK,CAAC;IADxC,YAAY;QADxB,mBAAQ,CAAC,SAAS,CAAC,SAAS,CAAC;OACjB,YAAY,CA6DxB;IAAD,mBAAC;CAAA,AA7DD,CAAkC,qBAAS,GA6D1C;AA7DY,oCAAY"}
@@ -27,3 +27,4 @@ export { StandardAttribute } from "./StandardAttribute";
27
27
  export { StyleAttribute } from "./StyleAttribute";
28
28
  export { TemplateAttribute } from "./TemplateAttribute";
29
29
  export { TypeAttribute } from "./TypeAttribute";
30
+ export { XHRAttribute } from "./XHRAttribute";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypeAttribute = exports.TemplateAttribute = exports.StyleAttribute = exports.StandardAttribute = exports.SetAttribute = exports.ServiceAttribute = exports.ScriptAttribute = exports.ScopeChange = exports.ScopeAttribute = exports.RootAttribute = exports.Referenced = exports.On = exports.Name = exports.ModelAttribute = exports.ListItemModel = exports.ListItem = exports.List = exports.LazyAttribute = exports.KeyUp = exports.KeyDown = exports.JSONAttribute = exports.If = exports.Format = exports.Exec = exports.DisableIf = exports.ControllerAttribute = exports.ComponentAttribute = exports.Bind = exports.AddClassIf = void 0;
3
+ exports.XHRAttribute = exports.TypeAttribute = exports.TemplateAttribute = exports.StyleAttribute = exports.StandardAttribute = exports.SetAttribute = exports.ServiceAttribute = exports.ScriptAttribute = exports.ScopeChange = exports.ScopeAttribute = exports.RootAttribute = exports.Referenced = exports.On = exports.Name = exports.ModelAttribute = exports.ListItemModel = exports.ListItem = exports.List = exports.LazyAttribute = exports.KeyUp = exports.KeyDown = exports.JSONAttribute = exports.If = exports.Format = exports.Exec = exports.DisableIf = exports.ControllerAttribute = exports.ComponentAttribute = exports.Bind = exports.AddClassIf = void 0;
4
4
  var AddClassIf_1 = require("./AddClassIf");
5
5
  Object.defineProperty(exports, "AddClassIf", { enumerable: true, get: function () { return AddClassIf_1.AddClassIf; } });
6
6
  var Bind_1 = require("./Bind");
@@ -59,4 +59,6 @@ var TemplateAttribute_1 = require("./TemplateAttribute");
59
59
  Object.defineProperty(exports, "TemplateAttribute", { enumerable: true, get: function () { return TemplateAttribute_1.TemplateAttribute; } });
60
60
  var TypeAttribute_1 = require("./TypeAttribute");
61
61
  Object.defineProperty(exports, "TypeAttribute", { enumerable: true, get: function () { return TypeAttribute_1.TypeAttribute; } });
62
+ var XHRAttribute_1 = require("./XHRAttribute");
63
+ Object.defineProperty(exports, "XHRAttribute", { enumerable: true, get: function () { return XHRAttribute_1.XHRAttribute; } });
62
64
  //# sourceMappingURL=_imports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_imports.js","sourceRoot":"","sources":["../../src/attributes/_imports.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAAhC,wGAAA,UAAU,OAAA;AAClB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,2DAAwD;AAAhD,wHAAA,kBAAkB,OAAA;AAC1B,6DAA0D;AAAlD,0HAAA,mBAAmB,OAAA;AAC3B,yCAAsC;AAA9B,sGAAA,SAAS,OAAA;AACjB,+BAA4B;AAApB,4FAA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AS,OAAA;AACjB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,mCAAgC;AAAxB,gGAAA,MAAM,OAAA;AACd,2BAAwB;AAAhB,wFAAA,EAAE,OAAA;AACV,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,qCAAkC;AAA1B,kGAAA,OAAO,OAAA;AACf,iCAA8B;AAAtB,8FAAA,KAAK,OAAA;AACb,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,uCAAoC;AAA5B,oGAAA,QAAQ,OAAA;AAChB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AACtB,+BAA4B;AAApB,4FAAA,IAAI,OAAA;AACZ,2BAAwB;AAAhB,wFAAA,EAAE,OAAA;AACV,2CAAwC;AAAhC,wGAAA,UAAU,OAAA;AAClB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AACtB,6CAA0C;AAAlC,0GAAA,WAAW,OAAA;AACnB,qDAAkD;AAA1C,kHAAA,eAAe,OAAA;AACvB,uDAAoD;AAA5C,oHAAA,gBAAgB,OAAA;AACxB,+CAA4C;AAApC,4GAAA,YAAY,OAAA;AACpB,yDAAsD;AAA9C,sHAAA,iBAAiB,OAAA;AACzB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AACtB,yDAAsD;AAA9C,sHAAA,iBAAiB,OAAA;AACzB,iDAA8C;AAAtC,8GAAA,aAAa,OAAA;AACrB,+CAA4C;AAApC,4GAAA,YAAY,OAAA"}
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.111";
1
+ export declare const VERSION = "0.1.113";
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '0.1.111';
4
+ exports.VERSION = '0.1.113';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.111",
3
+ "version": "0.1.113",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -29,8 +29,12 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
29
29
  // @todo: Need to rewrite/refactor this. It's a bit of a mess with element queries.
30
30
  let tags: Tag[] = [];
31
31
  let functionScope: Scope = scope;
32
+ let functionName: string = '';
33
+ let instanceOfScopeMemberNode = false;
32
34
  if (this.fnc instanceof ScopeMemberNode) {
35
+ instanceOfScopeMemberNode = true
33
36
  functionScope = await this.fnc.scope.evaluate(scope, dom, tag);
37
+ functionName = await this.fnc.name.evaluate(scope, dom, tag);
34
38
  if (this.fnc.scope instanceof ElementQueryNode) {
35
39
  const _tags = await this.fnc.scope.evaluate(scope, dom, tag);
36
40
  if (_tags instanceof Array) {
@@ -47,6 +51,7 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
47
51
 
48
52
  const values = await this.args.evaluate(scope, dom, tag);
49
53
  let func = await this.fnc.evaluate(scope, dom, tag);
54
+ console.log(tag?.element, functionName, func, scope.keys, functionScope?.keys, instanceOfScopeMemberNode);
50
55
  if (!func || func instanceof Array) {
51
56
  const functionName = await (this.fnc as any).name.evaluate(scope, dom, tag);
52
57
  const returnValues = [];
@@ -51,6 +51,8 @@ export class ScopeMemberNode extends ScopeNodeAbstract implements TreeNode {
51
51
  }
52
52
  const name = await this.name.evaluate(scope, dom, tag);
53
53
  await this.applyModifiers(name, parent, dom, tag);
54
+ if (!parent.get)
55
+ console.log('nani?', parent);
54
56
  const value: any = parent.get(name, false);
55
57
  values.push(value instanceof Scope && value.wrapped || value);
56
58
  }
package/src/Controller.ts CHANGED
@@ -7,6 +7,15 @@ export abstract class Controller extends ScopeData {
7
7
  protected _tag: Tag;
8
8
  protected _element: HTMLElement;
9
9
 
10
+ constructor() {
11
+ super();
12
+ for (const k in this) {
13
+ if (this[k] as any instanceof Function) {
14
+ this.__properties__.push(k);
15
+ }
16
+ }
17
+ }
18
+
10
19
  public get scope(): Scope {
11
20
  return this._scope;
12
21
  }
@@ -24,12 +33,4 @@ export abstract class Controller extends ScopeData {
24
33
  this._tag = tag;
25
34
  this._element = element;
26
35
  }
27
-
28
- public get(key: string): any {
29
- return this._scope?.get(key);
30
- }
31
-
32
- public set(key: string, value: any): void {
33
- this._scope?.set(key, value);
34
- }
35
36
  }
@@ -23,8 +23,8 @@ export class ScopeDataAbstract extends EventDispatcher {
23
23
  return this.getProperty(name);
24
24
  }
25
25
  config = config || {};
26
- const instance = new propertyType(config.default, config),
27
- propDesc = Object.getOwnPropertyDescriptor(this, name);
26
+ const instance = new propertyType(config.default, config);
27
+ const propDesc = Object.getOwnPropertyDescriptor(this, name);
28
28
  this['__'+name] = instance;
29
29
  this.__properties__.push(name);
30
30
 
@@ -101,11 +101,11 @@ export class ScopeDataAbstract extends EventDispatcher {
101
101
  return data;
102
102
  }
103
103
 
104
- get(key: string) {
104
+ public get(key: string) {
105
105
  return this[key];
106
106
  }
107
107
 
108
- set(key: string, value: any) {
108
+ public set(key: string, value: any) {
109
109
  this[key] = value;
110
110
  }
111
111
 
package/src/Tag.ts CHANGED
@@ -38,7 +38,8 @@ export class Tag extends DOMObject {
38
38
  '@text',
39
39
  '@html',
40
40
  '@class',
41
- '@value'
41
+ '@value',
42
+ '@disabled'
42
43
  ];
43
44
 
44
45
  protected inputTags: string[] = [
@@ -395,6 +396,12 @@ export class Tag extends DOMObject {
395
396
  const classes: string[] = value instanceof Array ? value : [value];
396
397
  if (classes.length)
397
398
  this.element.classList.add(...classes);
399
+ } else if (key === '@disabled') {
400
+ if (!!value) {
401
+ this.element.setAttribute('disabled', '');
402
+ } else {
403
+ this.element.removeAttribute('disabled');
404
+ }
398
405
  }
399
406
  } else {
400
407
  this.element.setAttribute(key, value);
@@ -411,6 +418,8 @@ export class Tag extends DOMObject {
411
418
  return this.value;
412
419
  else if (key === '@class') {
413
420
  return Array.from(this.element.classList);
421
+ } else if (key === '@disabled') {
422
+ return this.element.hasAttribute('disabled');
414
423
  }
415
424
  }
416
425
  return this.element.getAttribute(key);
@@ -1,34 +1,32 @@
1
1
  import {Scope} from "../Scope";
2
2
  import {Attribute} from "../Attribute";
3
3
  import {Registry} from "../Registry";
4
+ import {Controller} from "../Controller";
4
5
 
5
6
  @Registry.attribute('vsn-controller')
6
7
  export class ControllerAttribute extends Attribute {
7
8
  public static readonly canDefer: boolean = false;
8
9
  public static readonly scoped: boolean = true;
9
10
  public readonly registryName: string = 'controllers'
10
- public readonly assignToParent: boolean = true;
11
11
  protected attributeKey: string;
12
12
  protected className: string;
13
13
  protected defaultClassName: string;
14
14
 
15
15
  public async setup() {
16
- const parentScope: Scope = this.tag.parentTag.scope;
17
- if (!parentScope)
18
- return;
19
-
20
16
  this.attributeKey = this.getAttributeBinding();
21
17
  this.className = this.getAttributeValue(this.defaultClassName);
22
-
23
18
  const cls = await Registry.instance[this.registryName].get(this.className);
24
- const obj = this.instantiateClass(cls);
25
19
 
26
- if (this.attributeKey && obj) {
27
- if (this.assignToParent && parentScope) {
28
- parentScope.set(this.attributeKey, obj);
29
- } else {
30
- this.tag.scope.set(this.attributeKey, obj);
20
+ if (this.attributeKey) {
21
+ const controllerScope = new Scope(this.tag.scope);
22
+ const obj = new cls();
23
+ if (obj instanceof Controller) {
24
+ obj.init(this.tag.scope, this.tag, this.tag.element);
31
25
  }
26
+ controllerScope.wrap(obj);
27
+ this.tag.scope.set(this.attributeKey, controllerScope);
28
+ } else {
29
+ this.instantiateClass(cls);
32
30
  }
33
31
  await super.setup();
34
32
  }
@@ -21,7 +21,7 @@ export class SetAttribute extends Attribute {
21
21
  return this.boundScope.get(this.key, false);
22
22
  }
23
23
 
24
- public async setup() {
24
+ public async extract() {
25
25
  this.property = this.getAttributeBinding();
26
26
  let ref: ScopeReference;
27
27
  try {
@@ -31,10 +31,6 @@ export class SetAttribute extends Attribute {
31
31
  }
32
32
  this.key = await ref.getKey();
33
33
  this.boundScope = await ref.getScope();
34
- await super.setup();
35
- }
36
-
37
- public async extract() {
38
34
  let value = this.getAttributeValue(null);
39
35
  for (const m of this.getAttributeModifiers()) {
40
36
  const t = Registry.instance.types.getSynchronous(m);
@@ -0,0 +1,67 @@
1
+ import {Registry} from "../Registry";
2
+ import {Attribute} from "../Attribute";
3
+ import {Tree} from "../AST";
4
+
5
+ @Registry.attribute('vsn-xhr')
6
+ export class XHRAttribute extends Attribute {
7
+ public static readonly canDefer: boolean = false;
8
+ protected tree: Tree;
9
+
10
+ public get code() {
11
+ return this.getAttributeValue();
12
+ }
13
+
14
+ public async compile() {
15
+ this.tree = new Tree(this.code);
16
+ await this.tree.prepare(this.tag.scope, this.tag.dom, this.tag);
17
+ await super.compile();
18
+ }
19
+
20
+ public async connect() {
21
+ if (this.isForm) {
22
+ this.tag.addEventHandler('submit', this.getAttributeModifiers(), this.handleEvent, this);
23
+ } else if (this.isAnchor) {
24
+ this.tag.addEventHandler('click', this.getAttributeModifiers(), this.handleEvent, this);
25
+ }
26
+ await super.connect();
27
+ }
28
+
29
+ public get isForm() {
30
+ return this.tag.element.tagName === 'FORM';
31
+ }
32
+
33
+ public get isAnchor() {
34
+ return this.tag.element.tagName === 'A';
35
+ }
36
+
37
+ public async handleEvent(e) {
38
+ e.preventDefault();
39
+ const request = new XMLHttpRequest();
40
+ request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
41
+ let method;
42
+ let url;
43
+ let data;
44
+ if (this.isForm) {
45
+ url = this.tag.element.getAttribute('action');
46
+ method = this.getAttributeBinding(this.tag.element.getAttribute('method'));
47
+ data = new FormData(this.tag.element as HTMLFormElement);
48
+ } else if (this.isAnchor) {
49
+ url = this.tag.element.getAttribute('href');
50
+ method = this.getAttributeBinding('GET');
51
+ }
52
+
53
+ request.onload = async () => {
54
+ this.tag.scope.set('status', request.status);
55
+ if (request.status >= 200 && request.status < 300) {
56
+ this.tag.scope.set('response', request.response);
57
+ await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
58
+ } else {
59
+ console.error(request.statusText);
60
+ }
61
+ }
62
+ request.open(method, url);
63
+ request.send(data);
64
+
65
+ await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
66
+ }
67
+ }
@@ -27,3 +27,4 @@ export {StandardAttribute} from "./StandardAttribute";
27
27
  export {StyleAttribute} from "./StyleAttribute";
28
28
  export {TemplateAttribute} from "./TemplateAttribute";
29
29
  export {TypeAttribute} from "./TypeAttribute";
30
+ export {XHRAttribute} from "./XHRAttribute";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.111';
1
+ export const VERSION = '0.1.113';
2
2
 
@@ -28,15 +28,18 @@ class TestController extends Controller {
28
28
  describe('Controller', () => {
29
29
  it("methods should be callable from vsn-script", async () => {
30
30
  document.body.innerHTML = `
31
- <div vsn-controller:test="ControllerTestController" vsn-set:test.test="notTest" vsn-bind="test.test"></div>
31
+ <div id="controller" vsn-controller:test="ControllerTestController" vsn-set:test.test="notTest" vsn-bind="test.test"></div>
32
32
  `;
33
33
  const dom = new DOM(document);
34
34
  const deferred = SimplePromise.defer();
35
35
  dom.once('built', async () => {
36
- expect(await dom.exec('test.test')).toBe('notTest');
37
- expect(await dom.exec('test.isValid()')).toBe(false);
38
- await dom.exec('test.test = "test"');
39
- expect(await dom.exec('test.isValid()')).toBe(true);
36
+ const tag = await dom.exec('#controller');
37
+ expect(tag.scope.keys).toEqual(['test']);
38
+ expect(tag.scope.get('test').wrapped).toBeInstanceOf(TestController);
39
+ expect(await tag.exec('test.isValid()')).toBe(false);
40
+ expect(await tag.exec('test.test')).toBe('notTest');
41
+ await tag.exec('test.test = "test"');
42
+ expect(await tag.exec('test.isValid()')).toBe(true);
40
43
  deferred.resolve();
41
44
  });
42
45
  await deferred.promise;