vsn 0.1.26 → 0.1.27

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 (191) hide show
  1. package/dist/AST.js +2197 -0
  2. package/dist/AST.js.map +1 -0
  3. package/dist/Attribute.d.ts +1 -1
  4. package/dist/Attribute.js +187 -0
  5. package/dist/Attribute.js.map +1 -0
  6. package/dist/Bencmark.js +179 -0
  7. package/dist/Bencmark.js.map +1 -0
  8. package/dist/Configuration.d.ts +1 -1
  9. package/dist/Configuration.js +64 -0
  10. package/dist/Configuration.js.map +1 -0
  11. package/dist/Controller.d.ts +1 -1
  12. package/dist/Controller.js +54 -0
  13. package/dist/Controller.js.map +1 -0
  14. package/dist/DOM/DOMObject.d.ts +1 -1
  15. package/dist/DOM/DOMObject.js +47 -0
  16. package/dist/DOM/DOMObject.js.map +1 -0
  17. package/dist/DOM/WrappedDocument.js +34 -0
  18. package/dist/DOM/WrappedDocument.js.map +1 -0
  19. package/dist/DOM/WrappedWindow.js +45 -0
  20. package/dist/DOM/WrappedWindow.js.map +1 -0
  21. package/dist/DOM.d.ts +1 -1
  22. package/dist/DOM.js +547 -0
  23. package/dist/DOM.js.map +1 -0
  24. package/dist/EventDispatcher.d.ts +26 -0
  25. package/dist/EventDispatcher.js +117 -0
  26. package/dist/EventDispatcher.js.map +1 -0
  27. package/dist/Formats.js +44 -0
  28. package/dist/Formats.js.map +1 -0
  29. package/dist/MessageList.d.ts +14 -0
  30. package/dist/MessageList.js +88 -0
  31. package/dist/MessageList.js.map +1 -0
  32. package/dist/Model/Collection.d.ts +5 -0
  33. package/dist/Model/Collection.js +37 -0
  34. package/dist/Model/Collection.js.map +1 -0
  35. package/dist/Model/DataModel.d.ts +6 -0
  36. package/dist/Model/DataModel.js +54 -0
  37. package/dist/Model/DataModel.js.map +1 -0
  38. package/dist/Model/ModelAbstract.d.ts +20 -0
  39. package/dist/Model/ModelAbstract.js +122 -0
  40. package/dist/Model/ModelAbstract.js.map +1 -0
  41. package/dist/Model/fields/BooleanField.d.ts +5 -0
  42. package/dist/Model/fields/BooleanField.js +43 -0
  43. package/dist/Model/fields/BooleanField.js.map +1 -0
  44. package/dist/Model/fields/EmailField.d.ts +5 -0
  45. package/dist/Model/fields/EmailField.js +36 -0
  46. package/dist/Model/fields/EmailField.js.map +1 -0
  47. package/dist/Model/fields/Field.d.ts +13 -0
  48. package/dist/Model/fields/Field.js +79 -0
  49. package/dist/Model/fields/Field.js.map +1 -0
  50. package/dist/Model/fields/FloatField.d.ts +5 -0
  51. package/dist/Model/fields/FloatField.js +47 -0
  52. package/dist/Model/fields/FloatField.js.map +1 -0
  53. package/dist/Model/fields/PositiveNumberField.d.ts +5 -0
  54. package/dist/Model/fields/PositiveNumberField.js +51 -0
  55. package/dist/Model/fields/PositiveNumberField.js.map +1 -0
  56. package/dist/Model/fields/StringField.d.ts +5 -0
  57. package/dist/Model/fields/StringField.js +43 -0
  58. package/dist/Model/fields/StringField.js.map +1 -0
  59. package/dist/Model.d.ts +11 -0
  60. package/dist/Model.js +72 -0
  61. package/dist/Model.js.map +1 -0
  62. package/dist/Query.js +66 -0
  63. package/dist/Query.js.map +1 -0
  64. package/dist/Registry.d.ts +2 -2
  65. package/dist/Registry.js +128 -0
  66. package/dist/Registry.js.map +1 -0
  67. package/dist/Scope.d.ts +7 -10
  68. package/dist/Scope.js +462 -0
  69. package/dist/Scope.js.map +1 -0
  70. package/dist/SimplePromise.d.ts +42 -0
  71. package/dist/SimplePromise.js +217 -0
  72. package/dist/SimplePromise.js.map +1 -0
  73. package/dist/Tag/List.js +85 -0
  74. package/dist/Tag/List.js.map +1 -0
  75. package/dist/Tag.js +770 -0
  76. package/dist/Tag.js.map +1 -0
  77. package/dist/Types.js +48 -0
  78. package/dist/Types.js.map +1 -0
  79. package/dist/attributes/AddClassIf.js +93 -0
  80. package/dist/attributes/AddClassIf.js.map +1 -0
  81. package/dist/attributes/Bind.js +272 -0
  82. package/dist/attributes/Bind.js.map +1 -0
  83. package/dist/attributes/ClassConstructor.js +104 -0
  84. package/dist/attributes/ClassConstructor.js.map +1 -0
  85. package/dist/attributes/ClickRemoveClass.js +114 -0
  86. package/dist/attributes/ClickRemoveClass.js.map +1 -0
  87. package/dist/attributes/ClickToggleClass.js +114 -0
  88. package/dist/attributes/ClickToggleClass.js.map +1 -0
  89. package/dist/attributes/ControllerAttribute.js +28 -0
  90. package/dist/attributes/ControllerAttribute.js.map +1 -0
  91. package/dist/attributes/DisableIf.js +94 -0
  92. package/dist/attributes/DisableIf.js.map +1 -0
  93. package/dist/attributes/Exec.js +108 -0
  94. package/dist/attributes/Exec.js.map +1 -0
  95. package/dist/attributes/Format.js +99 -0
  96. package/dist/attributes/Format.js.map +1 -0
  97. package/dist/attributes/If.js +159 -0
  98. package/dist/attributes/If.js.map +1 -0
  99. package/dist/attributes/JSONAttribute.js +118 -0
  100. package/dist/attributes/JSONAttribute.js.map +1 -0
  101. package/dist/attributes/KeyAbstract.js +117 -0
  102. package/dist/attributes/KeyAbstract.js.map +1 -0
  103. package/dist/attributes/KeyDown.js +88 -0
  104. package/dist/attributes/KeyDown.js.map +1 -0
  105. package/dist/attributes/KeyUp.js +88 -0
  106. package/dist/attributes/KeyUp.js.map +1 -0
  107. package/dist/attributes/List.js +282 -0
  108. package/dist/attributes/List.js.map +1 -0
  109. package/dist/attributes/ListItem.js +138 -0
  110. package/dist/attributes/ListItem.js.map +1 -0
  111. package/dist/attributes/ListItemModel.js +39 -0
  112. package/dist/attributes/ListItemModel.js.map +1 -0
  113. package/dist/attributes/ModelAttribute.js +29 -0
  114. package/dist/attributes/ModelAttribute.js.map +1 -0
  115. package/dist/attributes/Name.js +88 -0
  116. package/dist/attributes/Name.js.map +1 -0
  117. package/dist/attributes/On.js +135 -0
  118. package/dist/attributes/On.js.map +1 -0
  119. package/dist/attributes/Radio.js +174 -0
  120. package/dist/attributes/Radio.js.map +1 -0
  121. package/dist/attributes/Referenced.js +38 -0
  122. package/dist/attributes/Referenced.js.map +1 -0
  123. package/dist/attributes/RootAttribute.js +91 -0
  124. package/dist/attributes/RootAttribute.js.map +1 -0
  125. package/dist/attributes/ScopeAttribute.js +40 -0
  126. package/dist/attributes/ScopeAttribute.js.map +1 -0
  127. package/dist/attributes/ScopeChange.js +130 -0
  128. package/dist/attributes/ScopeChange.js.map +1 -0
  129. package/dist/attributes/SetAttribute.js +133 -0
  130. package/dist/attributes/SetAttribute.js.map +1 -0
  131. package/dist/attributes/StandardAttribute.js +186 -0
  132. package/dist/attributes/StandardAttribute.js.map +1 -0
  133. package/dist/attributes/StyleAttribute.js +183 -0
  134. package/dist/attributes/StyleAttribute.js.map +1 -0
  135. package/dist/attributes/Template.js +39 -0
  136. package/dist/attributes/Template.js.map +1 -0
  137. package/dist/attributes/TypeAttribute.js +104 -0
  138. package/dist/attributes/TypeAttribute.js.map +1 -0
  139. package/dist/attributes/_imports.js +60 -0
  140. package/dist/attributes/_imports.js.map +1 -0
  141. package/dist/helpers/DOMHelper.js +81 -0
  142. package/dist/helpers/DOMHelper.js.map +1 -0
  143. package/dist/helpers/ElementHelper.js +25 -0
  144. package/dist/helpers/ElementHelper.js.map +1 -0
  145. package/dist/helpers/VisionHelper.js +71 -0
  146. package/dist/helpers/VisionHelper.js.map +1 -0
  147. package/dist/helpers/decorators.js +38 -0
  148. package/dist/helpers/decorators.js.map +1 -0
  149. package/dist/vsn.d.ts +2 -1
  150. package/dist/vsn.js +166 -0
  151. package/dist/vsn.js.map +1 -0
  152. package/package.json +2 -6
  153. package/src/AST.ts +2 -2
  154. package/src/Attribute.ts +2 -2
  155. package/src/Configuration.ts +3 -3
  156. package/src/Controller.ts +1 -1
  157. package/src/DOM/DOMObject.ts +1 -1
  158. package/src/DOM.ts +3 -3
  159. package/src/EventDispatcher.ts +117 -0
  160. package/src/Formats.ts +2 -2
  161. package/src/MessageList.ts +81 -0
  162. package/src/Model/Collection.ts +13 -0
  163. package/src/Model/DataModel.ts +29 -0
  164. package/src/Model/ModelAbstract.ts +114 -0
  165. package/src/Model/fields/BooleanField.ts +16 -0
  166. package/src/Model/fields/EmailField.ts +12 -0
  167. package/src/Model/fields/Field.ts +65 -0
  168. package/src/Model/fields/FloatField.ts +22 -0
  169. package/src/Model/fields/PositiveNumberField.ts +24 -0
  170. package/src/Model/fields/StringField.ts +16 -0
  171. package/src/Model.ts +57 -0
  172. package/src/Registry.ts +3 -3
  173. package/src/Scope.ts +33 -89
  174. package/src/SimplePromise.ts +219 -0
  175. package/src/Tag.ts +2 -2
  176. package/src/attributes/Bind.ts +1 -1
  177. package/src/attributes/List.ts +3 -3
  178. package/src/attributes/Radio.ts +1 -1
  179. package/src/attributes/ScopeChange.ts +1 -1
  180. package/src/attributes/StandardAttribute.ts +1 -1
  181. package/src/attributes/StyleAttribute.ts +1 -1
  182. package/src/vsn.ts +3 -2
  183. package/test/AST.spec.ts +2 -1
  184. package/test/MessageList.spec.ts +101 -0
  185. package/test/Model/DataModel.spec.ts +141 -0
  186. package/test/Model.spec.ts +306 -0
  187. package/test/Scope.spec.ts +2 -2
  188. package/test/SimplePromise.spec.ts +271 -0
  189. package/test/attributes/Bind.spec.ts +5 -5
  190. package/test/attributes/ListItem.spec.ts +1 -1
  191. package/dist/vsn.min.js +0 -1
package/dist/Tag.js ADDED
@@ -0,0 +1,770 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
54
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
55
+ to[j] = from[i];
56
+ return to;
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.Tag = exports.TagState = void 0;
60
+ var Scope_1 = require("./Scope");
61
+ var Attribute_1 = require("./Attribute");
62
+ var Controller_1 = require("./Controller");
63
+ var VisionHelper_1 = require("./helpers/VisionHelper");
64
+ var StandardAttribute_1 = require("./attributes/StandardAttribute");
65
+ var On_1 = require("./attributes/On");
66
+ var Registry_1 = require("./Registry");
67
+ var Bencmark_1 = require("./Bencmark");
68
+ var DOMObject_1 = require("./DOM/DOMObject");
69
+ var AST_1 = require("./AST");
70
+ var StyleAttribute_1 = require("./attributes/StyleAttribute");
71
+ var TagState;
72
+ (function (TagState) {
73
+ TagState[TagState["Instantiated"] = 0] = "Instantiated";
74
+ TagState[TagState["AttributesBuilt"] = 1] = "AttributesBuilt";
75
+ TagState[TagState["AttributesCompiled"] = 2] = "AttributesCompiled";
76
+ TagState[TagState["AttributesSetup"] = 3] = "AttributesSetup";
77
+ TagState[TagState["AttributesExtracted"] = 4] = "AttributesExtracted";
78
+ TagState[TagState["AttributesConnected"] = 5] = "AttributesConnected";
79
+ TagState[TagState["Built"] = 6] = "Built";
80
+ })(TagState = exports.TagState || (exports.TagState = {}));
81
+ var Tag = /** @class */ (function (_super) {
82
+ __extends(Tag, _super);
83
+ function Tag(element, dom) {
84
+ var props = [];
85
+ for (var _i = 2; _i < arguments.length; _i++) {
86
+ props[_i - 2] = arguments[_i];
87
+ }
88
+ var _this = _super.call(this, element, props) || this;
89
+ _this.dom = dom;
90
+ _this.deferredAttributes = [];
91
+ _this._nonDeferredAttributes = [];
92
+ _this._children = [];
93
+ _this.inputTags = [
94
+ 'input',
95
+ 'select',
96
+ 'textarea'
97
+ ];
98
+ _this.rawAttributes = {};
99
+ _this.parsedAttributes = {};
100
+ _this.attributes = [];
101
+ _this.onEventHandlers = {};
102
+ _this.analyzeElementAttributes();
103
+ _this._state = TagState.Instantiated;
104
+ if (VisionHelper_1.VisionHelper.window) {
105
+ if (!VisionHelper_1.VisionHelper.window['Tags']) {
106
+ VisionHelper_1.VisionHelper.window['Tags'] = [];
107
+ VisionHelper_1.VisionHelper.window['Attributes'] = [];
108
+ }
109
+ VisionHelper_1.VisionHelper.window['Tags'].push(_this);
110
+ }
111
+ return _this;
112
+ }
113
+ Object.defineProperty(Tag.prototype, "uniqueScope", {
114
+ get: function () {
115
+ return this._uniqueScope;
116
+ },
117
+ enumerable: false,
118
+ configurable: true
119
+ });
120
+ ;
121
+ Tag.prototype.onAttributeStateChange = function (event) {
122
+ if (event.previouseState === Attribute_1.AttributeState.Deferred)
123
+ this._nonDeferredAttributes.length = 0;
124
+ };
125
+ Object.defineProperty(Tag.prototype, "nonDeferredAttributes", {
126
+ get: function () {
127
+ if (this._nonDeferredAttributes.length > 0)
128
+ return this._nonDeferredAttributes;
129
+ var attrs = [];
130
+ for (var _i = 0, _a = this.attributes; _i < _a.length; _i++) {
131
+ var attribute = _a[_i];
132
+ if (attribute.state === Attribute_1.AttributeState.Deferred)
133
+ continue;
134
+ attrs.push(attribute);
135
+ }
136
+ this._nonDeferredAttributes = attrs;
137
+ return attrs;
138
+ },
139
+ enumerable: false,
140
+ configurable: true
141
+ });
142
+ Object.defineProperty(Tag.prototype, "style", {
143
+ get: function () {
144
+ return this.element.style;
145
+ },
146
+ enumerable: false,
147
+ configurable: true
148
+ });
149
+ Object.defineProperty(Tag.prototype, "computedStyle", {
150
+ get: function () {
151
+ return VisionHelper_1.VisionHelper.window && window.getComputedStyle(this.element) || null;
152
+ },
153
+ enumerable: false,
154
+ configurable: true
155
+ });
156
+ Tag.prototype.analyzeElementAttributes = function () {
157
+ if (!this.element.attributes || this.element.attributes.length <= 0)
158
+ return;
159
+ for (var i = 0; i < this.element.attributes.length; i++) {
160
+ var a = this.element.attributes[i];
161
+ this.rawAttributes[a.name] = a.value;
162
+ if (a.name.indexOf(':') > -1) {
163
+ var nameParts = a.name.split(':');
164
+ var values = nameParts.slice(1);
165
+ values.push(a.value);
166
+ this.parsedAttributes[nameParts[0]] = values;
167
+ }
168
+ else {
169
+ this.parsedAttributes[a.name] = [null, a.value];
170
+ }
171
+ }
172
+ };
173
+ Tag.prototype.eval = function (code) {
174
+ return __awaiter(this, void 0, void 0, function () {
175
+ var tree;
176
+ return __generator(this, function (_a) {
177
+ switch (_a.label) {
178
+ case 0:
179
+ tree = new AST_1.Tree(code);
180
+ return [4 /*yield*/, tree.prepare(this.scope, this.dom, this)];
181
+ case 1:
182
+ _a.sent();
183
+ return [4 /*yield*/, tree.evaluate(this.scope, this.dom, this)];
184
+ case 2: return [2 /*return*/, _a.sent()];
185
+ }
186
+ });
187
+ });
188
+ };
189
+ Tag.prototype.evaluate = function () {
190
+ return __awaiter(this, void 0, void 0, function () {
191
+ var _i, _a, attr;
192
+ return __generator(this, function (_b) {
193
+ switch (_b.label) {
194
+ case 0:
195
+ _i = 0, _a = this.nonDeferredAttributes;
196
+ _b.label = 1;
197
+ case 1:
198
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
199
+ attr = _a[_i];
200
+ return [4 /*yield*/, attr.evaluate()];
201
+ case 2:
202
+ _b.sent();
203
+ _b.label = 3;
204
+ case 3:
205
+ _i++;
206
+ return [3 /*break*/, 1];
207
+ case 4: return [2 /*return*/];
208
+ }
209
+ });
210
+ });
211
+ };
212
+ Tag.prototype.mutate = function (mutation) {
213
+ for (var _i = 0, _a = this.attributes; _i < _a.length; _i++) {
214
+ var attr = _a[_i];
215
+ attr.mutate(mutation);
216
+ }
217
+ this.dispatch('mutate', mutation);
218
+ };
219
+ Tag.prototype.get = function (attr) {
220
+ this.element.getAttribute(attr);
221
+ };
222
+ Tag.prototype.set = function (attr, value) {
223
+ this.element.setAttribute(attr, value);
224
+ };
225
+ Tag.prototype.getAttributeClass = function (attr) {
226
+ return __awaiter(this, void 0, void 0, function () {
227
+ return __generator(this, function (_a) {
228
+ if (!attr.startsWith('vsn-'))
229
+ return [2 /*return*/, null];
230
+ attr = this.getAttributeName(attr);
231
+ return [2 /*return*/, Registry_1.Registry.instance.attributes.get(attr)];
232
+ });
233
+ });
234
+ };
235
+ Tag.prototype.getAttributeName = function (attr) {
236
+ attr = attr.split('|')[0];
237
+ if (attr.indexOf(':') > -1) {
238
+ var parts = attr.split(':');
239
+ attr = parts[0];
240
+ }
241
+ return attr;
242
+ };
243
+ Tag.prototype.getAttributeBinding = function (attr) {
244
+ attr = attr.split('|')[0];
245
+ if (attr.indexOf(':') > -1) {
246
+ var parts = attr.split(':');
247
+ return parts[1];
248
+ }
249
+ return null;
250
+ };
251
+ Tag.prototype.getAttributeModifiers = function (attr) {
252
+ return attr.split('|').splice(1);
253
+ };
254
+ Object.defineProperty(Tag.prototype, "isInput", {
255
+ get: function () {
256
+ return this.inputTags.indexOf(this.element.tagName.toLowerCase()) > -1;
257
+ },
258
+ enumerable: false,
259
+ configurable: true
260
+ });
261
+ Object.defineProperty(Tag.prototype, "value", {
262
+ get: function () {
263
+ if (this.isInput) {
264
+ return this.element.value;
265
+ }
266
+ else {
267
+ return this.element.textContent;
268
+ }
269
+ },
270
+ set: function (value) {
271
+ if (this.isInput) {
272
+ this.element.setAttribute('value', value);
273
+ this.element.value = value;
274
+ }
275
+ else {
276
+ this.element.innerText = value;
277
+ }
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
282
+ Object.defineProperty(Tag.prototype, "checked", {
283
+ get: function () {
284
+ if (this.isInput) {
285
+ return this.element.checked;
286
+ }
287
+ else {
288
+ return false;
289
+ }
290
+ },
291
+ set: function (value) {
292
+ if (this.isInput) {
293
+ if (value) {
294
+ this.element.setAttribute('checked', '');
295
+ this.element.checked = true;
296
+ }
297
+ else {
298
+ this.element.removeAttribute('checked');
299
+ this.element.checked = false;
300
+ }
301
+ }
302
+ },
303
+ enumerable: false,
304
+ configurable: true
305
+ });
306
+ Tag.prototype.addChild = function (tag) {
307
+ this._children.push(tag);
308
+ };
309
+ Object.defineProperty(Tag.prototype, "children", {
310
+ get: function () {
311
+ return __spreadArray([], this._children);
312
+ },
313
+ enumerable: false,
314
+ configurable: true
315
+ });
316
+ Object.defineProperty(Tag.prototype, "parentTag", {
317
+ get: function () {
318
+ return this._parentTag;
319
+ },
320
+ set: function (tag) {
321
+ if (this.element === document.body)
322
+ return;
323
+ this._parentTag = tag;
324
+ tag.addChild(this);
325
+ if (this.scope !== tag.scope)
326
+ this.scope.parentScope = tag.scope;
327
+ },
328
+ enumerable: false,
329
+ configurable: true
330
+ });
331
+ Object.defineProperty(Tag.prototype, "scope", {
332
+ get: function () {
333
+ if (!!this._scope)
334
+ return this._scope;
335
+ if (!!this._parentTag)
336
+ return this._parentTag.scope;
337
+ return null;
338
+ },
339
+ enumerable: false,
340
+ configurable: true
341
+ });
342
+ Object.defineProperty(Tag.prototype, "controller", {
343
+ get: function () {
344
+ return this._controller;
345
+ },
346
+ set: function (controller) {
347
+ this._controller = controller;
348
+ },
349
+ enumerable: false,
350
+ configurable: true
351
+ });
352
+ Tag.prototype.wrap = function (obj, triggerUpdates, updateFromWrapped) {
353
+ if (triggerUpdates === void 0) { triggerUpdates = false; }
354
+ if (updateFromWrapped === void 0) { updateFromWrapped = true; }
355
+ if (VisionHelper_1.VisionHelper.isConstructor(obj)) {
356
+ obj = new obj();
357
+ }
358
+ if (obj instanceof Controller_1.Controller) {
359
+ obj.init(this.scope, this, this.element);
360
+ }
361
+ else {
362
+ this.scope.wrap(obj, triggerUpdates, updateFromWrapped);
363
+ obj['$scope'] = this.scope;
364
+ obj['$tag'] = this;
365
+ obj['$el'] = this.element;
366
+ }
367
+ return obj;
368
+ };
369
+ Tag.prototype.unwrap = function () {
370
+ this.scope.unwrap();
371
+ };
372
+ Tag.prototype.removeFromDOM = function () {
373
+ this.element.remove();
374
+ };
375
+ Tag.prototype.addToParentElement = function () {
376
+ this._parentTag.element.appendChild(this.element);
377
+ };
378
+ Tag.prototype.hide = function () {
379
+ this.element.hidden = true;
380
+ };
381
+ Tag.prototype.show = function () {
382
+ this.element.hidden = false;
383
+ };
384
+ Tag.prototype.findAncestorByAttribute = function (attr) {
385
+ if (this.hasAttribute(attr))
386
+ return this;
387
+ return this.parentTag ? this.parentTag.findAncestorByAttribute(attr) : null;
388
+ };
389
+ Tag.prototype.hasAttribute = function (attr) {
390
+ return !!this.parsedAttributes[attr];
391
+ };
392
+ Tag.prototype.getAttribute = function (key) {
393
+ return __awaiter(this, void 0, void 0, function () {
394
+ var cls, _i, _a, attr;
395
+ return __generator(this, function (_b) {
396
+ switch (_b.label) {
397
+ case 0: return [4 /*yield*/, Registry_1.Registry.instance.attributes.get(key)];
398
+ case 1:
399
+ cls = _b.sent();
400
+ if (!cls)
401
+ return [2 /*return*/];
402
+ for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
403
+ attr = _a[_i];
404
+ if (attr instanceof cls)
405
+ return [2 /*return*/, attr];
406
+ }
407
+ return [2 /*return*/];
408
+ }
409
+ });
410
+ });
411
+ };
412
+ Tag.prototype.getRawAttributeValue = function (key, fallback) {
413
+ if (fallback === void 0) { fallback = null; }
414
+ return this.rawAttributes[key] ? this.rawAttributes[key] : fallback;
415
+ };
416
+ Tag.prototype.hasRawAttribute = function (mod) {
417
+ return this.getRawAttributeValue(mod, undefined) !== undefined;
418
+ };
419
+ Tag.prototype.getParsedAttributeValue = function (key, index, fallback) {
420
+ if (index === void 0) { index = 0; }
421
+ if (fallback === void 0) { fallback = null; }
422
+ return this.parsedAttributes[key] && this.parsedAttributes[key][index] || fallback;
423
+ };
424
+ Tag.prototype.buildAttributes = function () {
425
+ return __awaiter(this, void 0, void 0, function () {
426
+ var requiresScope, defer, isMobile, _a, _b, _i, attr, attrClass, attrObj;
427
+ return __generator(this, function (_c) {
428
+ switch (_c.label) {
429
+ case 0:
430
+ requiresScope = false;
431
+ defer = false;
432
+ this.attributes.length = 0;
433
+ isMobile = VisionHelper_1.VisionHelper.isMobile();
434
+ if (this.element.offsetParent === null ||
435
+ this.hasAttribute('hidden') ||
436
+ this.hasAttribute('vsn-defer')) {
437
+ defer = true;
438
+ }
439
+ _a = [];
440
+ for (_b in this.rawAttributes)
441
+ _a.push(_b);
442
+ _i = 0;
443
+ _c.label = 1;
444
+ case 1:
445
+ if (!(_i < _a.length)) return [3 /*break*/, 5];
446
+ attr = _a[_i];
447
+ if (this.hasModifier(attr, 'mobile')) {
448
+ if (!isMobile) {
449
+ return [3 /*break*/, 4];
450
+ }
451
+ }
452
+ if (this.hasModifier(attr, 'desktop')) {
453
+ if (isMobile) {
454
+ return [3 /*break*/, 4];
455
+ }
456
+ }
457
+ return [4 /*yield*/, this.getAttributeClass(attr)];
458
+ case 2:
459
+ attrClass = _c.sent();
460
+ if (!attrClass) return [3 /*break*/, 4];
461
+ if (attrClass.scoped)
462
+ requiresScope = true;
463
+ attrObj = new attrClass(this, attr);
464
+ this.attributes.push(attrObj);
465
+ if (!(defer && attrClass.canDefer)) return [3 /*break*/, 4];
466
+ return [4 /*yield*/, attrObj.defer()];
467
+ case 3:
468
+ _c.sent();
469
+ this.deferredAttributes.push(attrObj);
470
+ attrObj.on('state', this.onAttributeStateChange.bind(this));
471
+ _c.label = 4;
472
+ case 4:
473
+ _i++;
474
+ return [3 /*break*/, 1];
475
+ case 5:
476
+ if (this.element.getAttribute('id'))
477
+ requiresScope = true;
478
+ if (requiresScope && !this.uniqueScope) {
479
+ this._uniqueScope = true;
480
+ this._scope = new Scope_1.Scope();
481
+ }
482
+ this._state = TagState.AttributesBuilt;
483
+ return [2 /*return*/];
484
+ }
485
+ });
486
+ });
487
+ };
488
+ Tag.prototype.compileAttributes = function () {
489
+ return __awaiter(this, void 0, void 0, function () {
490
+ var _i, _a, attr;
491
+ return __generator(this, function (_b) {
492
+ switch (_b.label) {
493
+ case 0:
494
+ _i = 0, _a = this.nonDeferredAttributes;
495
+ _b.label = 1;
496
+ case 1:
497
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
498
+ attr = _a[_i];
499
+ return [4 /*yield*/, attr.compile()];
500
+ case 2:
501
+ _b.sent();
502
+ _b.label = 3;
503
+ case 3:
504
+ _i++;
505
+ return [3 /*break*/, 1];
506
+ case 4:
507
+ this._state = TagState.AttributesCompiled;
508
+ return [2 /*return*/];
509
+ }
510
+ });
511
+ });
512
+ };
513
+ Tag.prototype.setupAttributes = function () {
514
+ return __awaiter(this, void 0, void 0, function () {
515
+ var _i, _a, attr;
516
+ return __generator(this, function (_b) {
517
+ switch (_b.label) {
518
+ case 0:
519
+ if (VisionHelper_1.VisionHelper.doBenchmark)
520
+ Bencmark_1.benchmarkStart('Tag.setupAttributes');
521
+ _i = 0, _a = this.nonDeferredAttributes;
522
+ _b.label = 1;
523
+ case 1:
524
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
525
+ attr = _a[_i];
526
+ return [4 /*yield*/, attr.setup()];
527
+ case 2:
528
+ _b.sent();
529
+ _b.label = 3;
530
+ case 3:
531
+ _i++;
532
+ return [3 /*break*/, 1];
533
+ case 4:
534
+ if (VisionHelper_1.VisionHelper.doBenchmark)
535
+ Bencmark_1.benchmarkEnd('Tag.setupAttributes', 'Attribute.setup');
536
+ this.dom.registerElementInRoot(this);
537
+ if (VisionHelper_1.VisionHelper.doBenchmark)
538
+ Bencmark_1.benchmarkEnd('Tag.setupAttributes', 'register');
539
+ this._state = TagState.AttributesSetup;
540
+ this.callOnWrapped('$setup');
541
+ if (VisionHelper_1.VisionHelper.doBenchmark)
542
+ Bencmark_1.benchmarkEnd('Tag.setupAttributes', '$setup');
543
+ return [2 /*return*/];
544
+ }
545
+ });
546
+ });
547
+ };
548
+ Tag.prototype.extractAttributes = function () {
549
+ return __awaiter(this, void 0, void 0, function () {
550
+ var _i, _a, attr;
551
+ return __generator(this, function (_b) {
552
+ switch (_b.label) {
553
+ case 0:
554
+ _i = 0, _a = this.nonDeferredAttributes;
555
+ _b.label = 1;
556
+ case 1:
557
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
558
+ attr = _a[_i];
559
+ return [4 /*yield*/, attr.extract()];
560
+ case 2:
561
+ _b.sent();
562
+ _b.label = 3;
563
+ case 3:
564
+ _i++;
565
+ return [3 /*break*/, 1];
566
+ case 4:
567
+ this._state = TagState.AttributesExtracted;
568
+ this.callOnWrapped('$extracted');
569
+ return [2 /*return*/];
570
+ }
571
+ });
572
+ });
573
+ };
574
+ Tag.prototype.connectAttributes = function () {
575
+ return __awaiter(this, void 0, void 0, function () {
576
+ var _i, _a, attr;
577
+ return __generator(this, function (_b) {
578
+ switch (_b.label) {
579
+ case 0:
580
+ if (this.isInput) {
581
+ this.addEventHandler('input', [], this.inputMutation.bind(this));
582
+ }
583
+ _i = 0, _a = this.nonDeferredAttributes;
584
+ _b.label = 1;
585
+ case 1:
586
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
587
+ attr = _a[_i];
588
+ return [4 /*yield*/, attr.connect()];
589
+ case 2:
590
+ _b.sent();
591
+ _b.label = 3;
592
+ case 3:
593
+ _i++;
594
+ return [3 /*break*/, 1];
595
+ case 4:
596
+ this._state = TagState.AttributesConnected;
597
+ this.callOnWrapped('$bound');
598
+ return [2 /*return*/];
599
+ }
600
+ });
601
+ });
602
+ };
603
+ Tag.prototype.inputMutation = function (e) {
604
+ this.element.setAttribute('value', e.target.value);
605
+ };
606
+ Tag.prototype.finalize = function () {
607
+ this._state = TagState.Built;
608
+ this.callOnWrapped('$built', this, this.scope, this.element);
609
+ VisionHelper_1.VisionHelper.nice(this.setupDeferredAttributes.bind(this));
610
+ };
611
+ Tag.prototype.callOnWrapped = function (method) {
612
+ var _a;
613
+ var args = [];
614
+ for (var _i = 1; _i < arguments.length; _i++) {
615
+ args[_i - 1] = arguments[_i];
616
+ }
617
+ if (this._uniqueScope && this.scope && this.scope.wrapped && this.scope.wrapped[method]) {
618
+ (_a = this.scope.wrapped)[method].apply(_a, args);
619
+ return true;
620
+ }
621
+ return false;
622
+ };
623
+ Tag.prototype.handleEvent = function (eventType, e) {
624
+ if (e)
625
+ e.stopPropagation();
626
+ if (!this.onEventHandlers[eventType])
627
+ return;
628
+ this.scope.set('$event', e);
629
+ this.scope.set('$value', this.value);
630
+ for (var _i = 0, _a = this.onEventHandlers[eventType]; _i < _a.length; _i++) {
631
+ var handler = _a[_i];
632
+ handler(e);
633
+ }
634
+ };
635
+ Tag.prototype.hasModifier = function (attribute, modifier) {
636
+ return attribute.indexOf("|" + modifier) > -1;
637
+ };
638
+ Tag.prototype.stripModifier = function (attribute, modifier) {
639
+ return attribute.replace("|" + modifier, '');
640
+ };
641
+ Tag.prototype.addEventHandler = function (eventType, modifiers, handler) {
642
+ var passiveValue = null;
643
+ if (modifiers.indexOf('active') > -1) {
644
+ passiveValue = false;
645
+ }
646
+ else if (modifiers.indexOf('passive') > -1) {
647
+ passiveValue = true;
648
+ }
649
+ if (!this.onEventHandlers[eventType]) {
650
+ this.onEventHandlers[eventType] = [];
651
+ var element = On_1.On.WindowEvents.indexOf(eventType) > -1 && window ? window : this.element;
652
+ var opts = {};
653
+ if (eventType.indexOf('touch') > -1 || passiveValue !== null)
654
+ opts['passive'] = passiveValue === null && true || passiveValue;
655
+ element.addEventListener(eventType, this.handleEvent.bind(this, eventType), opts);
656
+ }
657
+ this.onEventHandlers[eventType].push(handler);
658
+ };
659
+ Tag.prototype.watchAttribute = function (attributeName) {
660
+ return __awaiter(this, void 0, void 0, function () {
661
+ var _i, _a, attribute, standardAttribute;
662
+ return __generator(this, function (_b) {
663
+ switch (_b.label) {
664
+ case 0:
665
+ for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
666
+ attribute = _a[_i];
667
+ if (attribute instanceof StandardAttribute_1.StandardAttribute && attribute.attributeName == attributeName) {
668
+ return [2 /*return*/, attribute];
669
+ }
670
+ }
671
+ // Standard attribute requires a unique scope
672
+ // @todo: Does this cause any issues with attribute bindings on the parent scope prior to having its own scope? hmm...
673
+ if (!this.uniqueScope) {
674
+ this._uniqueScope = true;
675
+ this._scope = new Scope_1.Scope();
676
+ if (this.parentTag) {
677
+ this.scope.parentScope = this.parentTag.scope;
678
+ }
679
+ }
680
+ standardAttribute = new StandardAttribute_1.StandardAttribute(this, attributeName);
681
+ this.attributes.push(standardAttribute);
682
+ return [4 /*yield*/, this.setupAttribute(standardAttribute)];
683
+ case 1:
684
+ _b.sent();
685
+ return [2 /*return*/, standardAttribute];
686
+ }
687
+ });
688
+ });
689
+ };
690
+ Tag.prototype.watchStyle = function (styleName) {
691
+ return __awaiter(this, void 0, void 0, function () {
692
+ var _i, _a, attribute, styleAttribute;
693
+ return __generator(this, function (_b) {
694
+ switch (_b.label) {
695
+ case 0:
696
+ for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
697
+ attribute = _a[_i];
698
+ if (attribute instanceof StyleAttribute_1.StyleAttribute) {
699
+ return [2 /*return*/, attribute];
700
+ }
701
+ }
702
+ // Standard attribute requires a unique scope
703
+ // @todo: Does this cause any issues with attribute bindings on the parent scope prior to having its own scope? hmm...
704
+ if (!this.uniqueScope) {
705
+ this._uniqueScope = true;
706
+ this._scope = new Scope_1.Scope();
707
+ if (this.parentTag) {
708
+ this.scope.parentScope = this.parentTag.scope;
709
+ }
710
+ }
711
+ styleAttribute = new StyleAttribute_1.StyleAttribute(this, 'style');
712
+ this.attributes.push(styleAttribute);
713
+ return [4 /*yield*/, this.setupAttribute(styleAttribute)];
714
+ case 1:
715
+ _b.sent();
716
+ return [2 /*return*/, styleAttribute];
717
+ }
718
+ });
719
+ });
720
+ };
721
+ Tag.prototype.setupAttribute = function (attribute) {
722
+ return __awaiter(this, void 0, void 0, function () {
723
+ return __generator(this, function (_a) {
724
+ switch (_a.label) {
725
+ case 0: return [4 /*yield*/, attribute.compile()];
726
+ case 1:
727
+ _a.sent();
728
+ return [4 /*yield*/, attribute.setup()];
729
+ case 2:
730
+ _a.sent();
731
+ return [4 /*yield*/, attribute.extract()];
732
+ case 3:
733
+ _a.sent();
734
+ return [4 /*yield*/, attribute.connect()];
735
+ case 4:
736
+ _a.sent();
737
+ return [2 /*return*/];
738
+ }
739
+ });
740
+ });
741
+ };
742
+ Tag.prototype.setupDeferredAttributes = function () {
743
+ return __awaiter(this, void 0, void 0, function () {
744
+ var _i, _a, attr;
745
+ return __generator(this, function (_b) {
746
+ switch (_b.label) {
747
+ case 0:
748
+ _i = 0, _a = this.deferredAttributes;
749
+ _b.label = 1;
750
+ case 1:
751
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
752
+ attr = _a[_i];
753
+ return [4 /*yield*/, this.setupAttribute(attr)];
754
+ case 2:
755
+ _b.sent();
756
+ _b.label = 3;
757
+ case 3:
758
+ _i++;
759
+ return [3 /*break*/, 1];
760
+ case 4:
761
+ this.deferredAttributes.length = 0;
762
+ return [2 /*return*/];
763
+ }
764
+ });
765
+ });
766
+ };
767
+ return Tag;
768
+ }(DOMObject_1.DOMObject));
769
+ exports.Tag = Tag;
770
+ //# sourceMappingURL=Tag.js.map