vsn 0.1.13 → 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 (112) 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 +4 -0
  8. package/test/DOM.spec.ts +2 -2
  9. package/test/Scope.spec.ts +14 -0
  10. package/test/attributes/Bind.spec.ts +13 -0
  11. package/dist/AST.js +0 -1978
  12. package/dist/AST.js.map +0 -1
  13. package/dist/Attribute.js +0 -187
  14. package/dist/Attribute.js.map +0 -1
  15. package/dist/Bencmark.js +0 -179
  16. package/dist/Bencmark.js.map +0 -1
  17. package/dist/Configuration.js +0 -64
  18. package/dist/Configuration.js.map +0 -1
  19. package/dist/Controller.js +0 -39
  20. package/dist/Controller.js.map +0 -1
  21. package/dist/DOM/DOMObject.js +0 -45
  22. package/dist/DOM/DOMObject.js.map +0 -1
  23. package/dist/DOM/WrappedDocument.js +0 -34
  24. package/dist/DOM/WrappedDocument.js.map +0 -1
  25. package/dist/DOM/WrappedWindow.js +0 -45
  26. package/dist/DOM/WrappedWindow.js.map +0 -1
  27. package/dist/DOM.js +0 -547
  28. package/dist/DOM.js.map +0 -1
  29. package/dist/Formats.js +0 -44
  30. package/dist/Formats.js.map +0 -1
  31. package/dist/Query.js +0 -66
  32. package/dist/Query.js.map +0 -1
  33. package/dist/Registry.js +0 -138
  34. package/dist/Registry.js.map +0 -1
  35. package/dist/Scope.js +0 -496
  36. package/dist/Scope.js.map +0 -1
  37. package/dist/Tag/List.js +0 -85
  38. package/dist/Tag/List.js.map +0 -1
  39. package/dist/Tag.js +0 -715
  40. package/dist/Tag.js.map +0 -1
  41. package/dist/Types.js +0 -48
  42. package/dist/Types.js.map +0 -1
  43. package/dist/Vision.js +0 -155
  44. package/dist/Vision.js.map +0 -1
  45. package/dist/attributes/AddClassIf.js +0 -93
  46. package/dist/attributes/AddClassIf.js.map +0 -1
  47. package/dist/attributes/Bind.js +0 -272
  48. package/dist/attributes/Bind.js.map +0 -1
  49. package/dist/attributes/ClassConstructor.js +0 -104
  50. package/dist/attributes/ClassConstructor.js.map +0 -1
  51. package/dist/attributes/ClickRemoveClass.js +0 -102
  52. package/dist/attributes/ClickRemoveClass.js.map +0 -1
  53. package/dist/attributes/ClickToggleClass.js +0 -102
  54. package/dist/attributes/ClickToggleClass.js.map +0 -1
  55. package/dist/attributes/ControllerAttribute.js +0 -28
  56. package/dist/attributes/ControllerAttribute.js.map +0 -1
  57. package/dist/attributes/DisableIf.js +0 -94
  58. package/dist/attributes/DisableIf.js.map +0 -1
  59. package/dist/attributes/Exec.js +0 -102
  60. package/dist/attributes/Exec.js.map +0 -1
  61. package/dist/attributes/Format.js +0 -96
  62. package/dist/attributes/Format.js.map +0 -1
  63. package/dist/attributes/If.js +0 -147
  64. package/dist/attributes/If.js.map +0 -1
  65. package/dist/attributes/JSONAttribute.js +0 -115
  66. package/dist/attributes/JSONAttribute.js.map +0 -1
  67. package/dist/attributes/KeyAbstract.js +0 -110
  68. package/dist/attributes/KeyAbstract.js.map +0 -1
  69. package/dist/attributes/KeyDown.js +0 -82
  70. package/dist/attributes/KeyDown.js.map +0 -1
  71. package/dist/attributes/KeyUp.js +0 -82
  72. package/dist/attributes/KeyUp.js.map +0 -1
  73. package/dist/attributes/List.js +0 -273
  74. package/dist/attributes/List.js.map +0 -1
  75. package/dist/attributes/ListItem.js +0 -135
  76. package/dist/attributes/ListItem.js.map +0 -1
  77. package/dist/attributes/ListItemModel.js +0 -39
  78. package/dist/attributes/ListItemModel.js.map +0 -1
  79. package/dist/attributes/ModelAttribute.js +0 -29
  80. package/dist/attributes/ModelAttribute.js.map +0 -1
  81. package/dist/attributes/Name.js +0 -88
  82. package/dist/attributes/Name.js.map +0 -1
  83. package/dist/attributes/On.js +0 -123
  84. package/dist/attributes/On.js.map +0 -1
  85. package/dist/attributes/Radio.js +0 -127
  86. package/dist/attributes/Radio.js.map +0 -1
  87. package/dist/attributes/Referenced.js +0 -38
  88. package/dist/attributes/Referenced.js.map +0 -1
  89. package/dist/attributes/RootAttribute.js +0 -85
  90. package/dist/attributes/RootAttribute.js.map +0 -1
  91. package/dist/attributes/ScopeAttribute.js +0 -40
  92. package/dist/attributes/ScopeAttribute.js.map +0 -1
  93. package/dist/attributes/ScopeChange.js +0 -124
  94. package/dist/attributes/ScopeChange.js.map +0 -1
  95. package/dist/attributes/SetAttribute.js +0 -130
  96. package/dist/attributes/SetAttribute.js.map +0 -1
  97. package/dist/attributes/StandardAttribute.js +0 -168
  98. package/dist/attributes/StandardAttribute.js.map +0 -1
  99. package/dist/attributes/Template.js +0 -39
  100. package/dist/attributes/Template.js.map +0 -1
  101. package/dist/attributes/TypeAttribute.js +0 -101
  102. package/dist/attributes/TypeAttribute.js.map +0 -1
  103. package/dist/attributes/_imports.js +0 -30
  104. package/dist/attributes/_imports.js.map +0 -1
  105. package/dist/helpers/DOMHelper.js +0 -81
  106. package/dist/helpers/DOMHelper.js.map +0 -1
  107. package/dist/helpers/ElementHelper.js +0 -25
  108. package/dist/helpers/ElementHelper.js.map +0 -1
  109. package/dist/helpers/VisionHelper.js +0 -71
  110. package/dist/helpers/VisionHelper.js.map +0 -1
  111. package/dist/helpers/decorators.js +0 -38
  112. package/dist/helpers/decorators.js.map +0 -1
package/dist/Tag.js DELETED
@@ -1,715 +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.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
- this.element.checked = true;
277
- }
278
- else {
279
- this.element.removeAttribute('checked');
280
- this.element.checked = false;
281
- }
282
- }
283
- },
284
- enumerable: false,
285
- configurable: true
286
- });
287
- Tag.prototype.addChild = function (tag) {
288
- this._children.push(tag);
289
- };
290
- Object.defineProperty(Tag.prototype, "children", {
291
- get: function () {
292
- return __spreadArray([], this._children);
293
- },
294
- enumerable: false,
295
- configurable: true
296
- });
297
- Object.defineProperty(Tag.prototype, "parentTag", {
298
- get: function () {
299
- return this._parentTag;
300
- },
301
- set: function (tag) {
302
- if (this.element === document.body)
303
- return;
304
- this._parentTag = tag;
305
- tag.addChild(this);
306
- if (this.scope !== tag.scope)
307
- this.scope.parentScope = tag.scope;
308
- },
309
- enumerable: false,
310
- configurable: true
311
- });
312
- Object.defineProperty(Tag.prototype, "scope", {
313
- get: function () {
314
- if (!!this._scope)
315
- return this._scope;
316
- if (!!this._parentTag)
317
- return this._parentTag.scope;
318
- return null;
319
- },
320
- enumerable: false,
321
- configurable: true
322
- });
323
- Object.defineProperty(Tag.prototype, "controller", {
324
- get: function () {
325
- return this._controller;
326
- },
327
- set: function (controller) {
328
- this._controller = controller;
329
- },
330
- enumerable: false,
331
- configurable: true
332
- });
333
- Tag.prototype.wrap = function (obj, triggerUpdates, updateFromWrapped) {
334
- if (triggerUpdates === void 0) { triggerUpdates = false; }
335
- if (updateFromWrapped === void 0) { updateFromWrapped = true; }
336
- if (VisionHelper_1.VisionHelper.isConstructor(obj)) {
337
- obj = new obj();
338
- }
339
- this.scope.wrap(obj, triggerUpdates, updateFromWrapped);
340
- obj['$scope'] = this.scope;
341
- obj['$tag'] = this;
342
- obj['$el'] = this.element;
343
- return obj;
344
- };
345
- Tag.prototype.unwrap = function () {
346
- this.scope.unwrap();
347
- };
348
- Tag.prototype.removeFromDOM = function () {
349
- this.element.remove();
350
- };
351
- Tag.prototype.addToParentElement = function () {
352
- this._parentTag.element.appendChild(this.element);
353
- };
354
- Tag.prototype.hide = function () {
355
- this.element.hidden = true;
356
- };
357
- Tag.prototype.show = function () {
358
- this.element.hidden = false;
359
- };
360
- Tag.prototype.findAncestorByAttribute = function (attr) {
361
- if (this.hasAttribute(attr))
362
- return this;
363
- return this.parentTag ? this.parentTag.findAncestorByAttribute(attr) : null;
364
- };
365
- Tag.prototype.hasAttribute = function (attr) {
366
- return !!this.parsedAttributes[attr];
367
- };
368
- Tag.prototype.getAttribute = function (key) {
369
- return __awaiter(this, void 0, void 0, function () {
370
- var cls, _i, _a, attr;
371
- return __generator(this, function (_b) {
372
- switch (_b.label) {
373
- case 0: return [4 /*yield*/, Registry_1.Registry.instance.attributes.get(key)];
374
- case 1:
375
- cls = _b.sent();
376
- if (!cls)
377
- return [2 /*return*/];
378
- for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
379
- attr = _a[_i];
380
- if (attr instanceof cls)
381
- return [2 /*return*/, attr];
382
- }
383
- return [2 /*return*/];
384
- }
385
- });
386
- });
387
- };
388
- Tag.prototype.getRawAttributeValue = function (key, fallback) {
389
- if (fallback === void 0) { fallback = null; }
390
- return this.rawAttributes[key] ? this.rawAttributes[key] : fallback;
391
- };
392
- Tag.prototype.hasRawAttribute = function (mod) {
393
- return this.getRawAttributeValue(mod, undefined) !== undefined;
394
- };
395
- Tag.prototype.getParsedAttributeValue = function (key, index, fallback) {
396
- if (index === void 0) { index = 0; }
397
- if (fallback === void 0) { fallback = null; }
398
- return this.parsedAttributes[key] && this.parsedAttributes[key][index] || fallback;
399
- };
400
- Tag.prototype.buildAttributes = function () {
401
- return __awaiter(this, void 0, void 0, function () {
402
- var requiresScope, defer, isMobile, _a, _b, _i, attr, attrClass, attrObj;
403
- return __generator(this, function (_c) {
404
- switch (_c.label) {
405
- case 0:
406
- requiresScope = false;
407
- defer = false;
408
- this.attributes.length = 0;
409
- isMobile = VisionHelper_1.VisionHelper.isMobile();
410
- if (this.element.offsetParent === null ||
411
- this.hasAttribute('hidden') ||
412
- this.hasAttribute('vsn-defer')) {
413
- defer = true;
414
- }
415
- _a = [];
416
- for (_b in this.rawAttributes)
417
- _a.push(_b);
418
- _i = 0;
419
- _c.label = 1;
420
- case 1:
421
- if (!(_i < _a.length)) return [3 /*break*/, 5];
422
- attr = _a[_i];
423
- if (this.hasModifier(attr, 'mobile')) {
424
- if (!isMobile) {
425
- return [3 /*break*/, 4];
426
- }
427
- }
428
- if (this.hasModifier(attr, 'desktop')) {
429
- if (isMobile) {
430
- return [3 /*break*/, 4];
431
- }
432
- }
433
- return [4 /*yield*/, this.getAttributeClass(attr)];
434
- case 2:
435
- attrClass = _c.sent();
436
- if (!attrClass) return [3 /*break*/, 4];
437
- if (attrClass.scoped)
438
- requiresScope = true;
439
- attrObj = new attrClass(this, attr);
440
- this.attributes.push(attrObj);
441
- if (!(defer && attrClass.canDefer)) return [3 /*break*/, 4];
442
- return [4 /*yield*/, attrObj.defer()];
443
- case 3:
444
- _c.sent();
445
- this.deferredAttributes.push(attrObj);
446
- attrObj.bind('state', this.onAttributeStateChange.bind(this));
447
- _c.label = 4;
448
- case 4:
449
- _i++;
450
- return [3 /*break*/, 1];
451
- case 5:
452
- if (this.element.getAttribute('id'))
453
- requiresScope = true;
454
- if (requiresScope && !this.uniqueScope) {
455
- this._uniqueScope = true;
456
- this._scope = new Scope_1.Scope();
457
- }
458
- this._state = TagState.AttributesBuilt;
459
- return [2 /*return*/];
460
- }
461
- });
462
- });
463
- };
464
- Tag.prototype.compileAttributes = function () {
465
- return __awaiter(this, void 0, void 0, function () {
466
- var _i, _a, attr;
467
- return __generator(this, function (_b) {
468
- switch (_b.label) {
469
- case 0:
470
- _i = 0, _a = this.nonDeferredAttributes;
471
- _b.label = 1;
472
- case 1:
473
- if (!(_i < _a.length)) return [3 /*break*/, 4];
474
- attr = _a[_i];
475
- return [4 /*yield*/, attr.compile()];
476
- case 2:
477
- _b.sent();
478
- _b.label = 3;
479
- case 3:
480
- _i++;
481
- return [3 /*break*/, 1];
482
- case 4:
483
- this._state = TagState.AttributesCompiled;
484
- return [2 /*return*/];
485
- }
486
- });
487
- });
488
- };
489
- Tag.prototype.setupAttributes = function () {
490
- return __awaiter(this, void 0, void 0, function () {
491
- var _i, _a, attr;
492
- return __generator(this, function (_b) {
493
- switch (_b.label) {
494
- case 0:
495
- if (VisionHelper_1.VisionHelper.doBenchmark)
496
- Bencmark_1.benchmarkStart('Tag.setupAttributes');
497
- _i = 0, _a = this.nonDeferredAttributes;
498
- _b.label = 1;
499
- case 1:
500
- if (!(_i < _a.length)) return [3 /*break*/, 4];
501
- attr = _a[_i];
502
- return [4 /*yield*/, attr.setup()];
503
- case 2:
504
- _b.sent();
505
- _b.label = 3;
506
- case 3:
507
- _i++;
508
- return [3 /*break*/, 1];
509
- case 4:
510
- if (VisionHelper_1.VisionHelper.doBenchmark)
511
- Bencmark_1.benchmarkEnd('Tag.setupAttributes', 'Attribute.setup');
512
- this.dom.registerElementInRoot(this);
513
- if (VisionHelper_1.VisionHelper.doBenchmark)
514
- Bencmark_1.benchmarkEnd('Tag.setupAttributes', 'register');
515
- this._state = TagState.AttributesSetup;
516
- this.callOnWrapped('$setup');
517
- if (VisionHelper_1.VisionHelper.doBenchmark)
518
- Bencmark_1.benchmarkEnd('Tag.setupAttributes', '$setup');
519
- return [2 /*return*/];
520
- }
521
- });
522
- });
523
- };
524
- Tag.prototype.extractAttributes = function () {
525
- return __awaiter(this, void 0, void 0, function () {
526
- var _i, _a, attr;
527
- return __generator(this, function (_b) {
528
- switch (_b.label) {
529
- case 0:
530
- _i = 0, _a = this.nonDeferredAttributes;
531
- _b.label = 1;
532
- case 1:
533
- if (!(_i < _a.length)) return [3 /*break*/, 4];
534
- attr = _a[_i];
535
- return [4 /*yield*/, attr.extract()];
536
- case 2:
537
- _b.sent();
538
- _b.label = 3;
539
- case 3:
540
- _i++;
541
- return [3 /*break*/, 1];
542
- case 4:
543
- this._state = TagState.AttributesExtracted;
544
- this.callOnWrapped('$extracted');
545
- return [2 /*return*/];
546
- }
547
- });
548
- });
549
- };
550
- Tag.prototype.connectAttributes = function () {
551
- return __awaiter(this, void 0, void 0, function () {
552
- var _i, _a, attr;
553
- return __generator(this, function (_b) {
554
- switch (_b.label) {
555
- case 0:
556
- if (this.isInput) {
557
- this.addEventHandler('input', [], this.inputMutation.bind(this));
558
- }
559
- _i = 0, _a = this.nonDeferredAttributes;
560
- _b.label = 1;
561
- case 1:
562
- if (!(_i < _a.length)) return [3 /*break*/, 4];
563
- attr = _a[_i];
564
- return [4 /*yield*/, attr.connect()];
565
- case 2:
566
- _b.sent();
567
- _b.label = 3;
568
- case 3:
569
- _i++;
570
- return [3 /*break*/, 1];
571
- case 4:
572
- this._state = TagState.AttributesConnected;
573
- this.callOnWrapped('$bound');
574
- return [2 /*return*/];
575
- }
576
- });
577
- });
578
- };
579
- Tag.prototype.inputMutation = function (e) {
580
- this.element.setAttribute('value', e.target.value);
581
- };
582
- Tag.prototype.finalize = function () {
583
- this._state = TagState.Built;
584
- this.callOnWrapped('$built', this, this.scope, this.element);
585
- VisionHelper_1.VisionHelper.nice(this.setupDeferredAttributes.bind(this));
586
- };
587
- Tag.prototype.callOnWrapped = function (method) {
588
- var _a;
589
- var args = [];
590
- for (var _i = 1; _i < arguments.length; _i++) {
591
- args[_i - 1] = arguments[_i];
592
- }
593
- if (this._uniqueScope && this.scope && this.scope.wrapped && this.scope.wrapped[method]) {
594
- (_a = this.scope.wrapped)[method].apply(_a, args);
595
- return true;
596
- }
597
- return false;
598
- };
599
- Tag.prototype.handleEvent = function (eventType, e) {
600
- if (e)
601
- e.stopPropagation();
602
- if (!this.onEventHandlers[eventType])
603
- return;
604
- this.scope.set('$event', e);
605
- this.scope.set('$value', this.value);
606
- for (var _i = 0, _a = this.onEventHandlers[eventType]; _i < _a.length; _i++) {
607
- var handler = _a[_i];
608
- handler(e);
609
- }
610
- };
611
- Tag.prototype.hasModifier = function (attribute, modifier) {
612
- return attribute.indexOf("|" + modifier) > -1;
613
- };
614
- Tag.prototype.stripModifier = function (attribute, modifier) {
615
- return attribute.replace("|" + modifier, '');
616
- };
617
- Tag.prototype.addEventHandler = function (eventType, modifiers, handler) {
618
- var passiveValue = null;
619
- if (modifiers.indexOf('active') > -1) {
620
- passiveValue = false;
621
- }
622
- else if (modifiers.indexOf('passive') > -1) {
623
- passiveValue = true;
624
- }
625
- if (!this.onEventHandlers[eventType]) {
626
- this.onEventHandlers[eventType] = [];
627
- var element = On_1.On.WindowEvents.indexOf(eventType) > -1 && window ? window : this.element;
628
- var opts = {};
629
- if (eventType.indexOf('touch') > -1 || passiveValue !== null)
630
- opts['passive'] = passiveValue === null && true || passiveValue;
631
- element.addEventListener(eventType, this.handleEvent.bind(this, eventType), opts);
632
- }
633
- this.onEventHandlers[eventType].push(handler);
634
- };
635
- Tag.prototype.watchAttribute = function (attributeName) {
636
- return __awaiter(this, void 0, void 0, function () {
637
- var _i, _a, attribute, standardAttribute;
638
- return __generator(this, function (_b) {
639
- switch (_b.label) {
640
- case 0:
641
- for (_i = 0, _a = this.attributes; _i < _a.length; _i++) {
642
- attribute = _a[_i];
643
- if (attribute instanceof StandardAttribute_1.StandardAttribute && attribute.attributeName == attributeName) {
644
- return [2 /*return*/, attribute];
645
- }
646
- }
647
- // Standard attribute requires a unique scope
648
- // @todo: Does this cause any issues with attribute bindings on the parent scope prior to having its own scope? hmm...
649
- if (!this.uniqueScope) {
650
- this._uniqueScope = true;
651
- this._scope = new Scope_1.Scope();
652
- if (this.parentTag) {
653
- this.scope.parentScope = this.parentTag.scope;
654
- }
655
- }
656
- standardAttribute = new StandardAttribute_1.StandardAttribute(this, attributeName);
657
- this.attributes.push(standardAttribute);
658
- return [4 /*yield*/, this.setupAttribute(standardAttribute)];
659
- case 1:
660
- _b.sent();
661
- return [2 /*return*/, standardAttribute];
662
- }
663
- });
664
- });
665
- };
666
- Tag.prototype.setupAttribute = function (attribute) {
667
- return __awaiter(this, void 0, void 0, function () {
668
- return __generator(this, function (_a) {
669
- switch (_a.label) {
670
- case 0: return [4 /*yield*/, attribute.compile()];
671
- case 1:
672
- _a.sent();
673
- return [4 /*yield*/, attribute.setup()];
674
- case 2:
675
- _a.sent();
676
- return [4 /*yield*/, attribute.extract()];
677
- case 3:
678
- _a.sent();
679
- return [4 /*yield*/, attribute.connect()];
680
- case 4:
681
- _a.sent();
682
- return [2 /*return*/];
683
- }
684
- });
685
- });
686
- };
687
- Tag.prototype.setupDeferredAttributes = function () {
688
- return __awaiter(this, void 0, void 0, function () {
689
- var _i, _a, attr;
690
- return __generator(this, function (_b) {
691
- switch (_b.label) {
692
- case 0:
693
- _i = 0, _a = this.deferredAttributes;
694
- _b.label = 1;
695
- case 1:
696
- if (!(_i < _a.length)) return [3 /*break*/, 4];
697
- attr = _a[_i];
698
- return [4 /*yield*/, this.setupAttribute(attr)];
699
- case 2:
700
- _b.sent();
701
- _b.label = 3;
702
- case 3:
703
- _i++;
704
- return [3 /*break*/, 1];
705
- case 4:
706
- this.deferredAttributes.length = 0;
707
- return [2 /*return*/];
708
- }
709
- });
710
- });
711
- };
712
- return Tag;
713
- }(DOMObject_1.DOMObject));
714
- exports.Tag = Tag;
715
- //# sourceMappingURL=Tag.js.map