vsn 0.1.10 → 0.1.14

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