1 | System.register(['aurelia-dependency-injection', 'aurelia-pal', 'aurelia-task-queue', 'aurelia-templating', 'aurelia-binding', 'aurelia-loader', 'aurelia-path', 'aurelia-metadata', 'aurelia-logging'], (function (exports) {
|
2 | 'use strict';
|
3 | var Container, inject, Optional, DOM, FEATURE, TaskQueue, bindable, noView, customElement, CompositionEngine, ViewSlot, ViewResources, customAttribute, templateController, BoundViewFactory, TargetInstruction, Animator, resource, useView, useShadowDOM, ViewEngine, createOverrideContext, bindingMode, BindingBehavior, ValueConverter, sourceContext, mergeSplice, ObserverLocator, valueConverter, DataAttributeObserver, bindingBehavior, targetContext, EventSubscriber, Loader, relativeToFile, mixin, getLogger;
|
4 | return {
|
5 | setters: [function (module) {
|
6 | Container = module.Container;
|
7 | inject = module.inject;
|
8 | Optional = module.Optional;
|
9 | }, function (module) {
|
10 | DOM = module.DOM;
|
11 | FEATURE = module.FEATURE;
|
12 | }, function (module) {
|
13 | TaskQueue = module.TaskQueue;
|
14 | }, function (module) {
|
15 | bindable = module.bindable;
|
16 | noView = module.noView;
|
17 | customElement = module.customElement;
|
18 | CompositionEngine = module.CompositionEngine;
|
19 | ViewSlot = module.ViewSlot;
|
20 | ViewResources = module.ViewResources;
|
21 | customAttribute = module.customAttribute;
|
22 | templateController = module.templateController;
|
23 | BoundViewFactory = module.BoundViewFactory;
|
24 | TargetInstruction = module.TargetInstruction;
|
25 | Animator = module.Animator;
|
26 | resource = module.resource;
|
27 | useView = module.useView;
|
28 | useShadowDOM = module.useShadowDOM;
|
29 | ViewEngine = module.ViewEngine;
|
30 | }, function (module) {
|
31 | createOverrideContext = module.createOverrideContext;
|
32 | bindingMode = module.bindingMode;
|
33 | BindingBehavior = module.BindingBehavior;
|
34 | ValueConverter = module.ValueConverter;
|
35 | sourceContext = module.sourceContext;
|
36 | mergeSplice = module.mergeSplice;
|
37 | ObserverLocator = module.ObserverLocator;
|
38 | valueConverter = module.valueConverter;
|
39 | DataAttributeObserver = module.DataAttributeObserver;
|
40 | bindingBehavior = module.bindingBehavior;
|
41 | targetContext = module.targetContext;
|
42 | EventSubscriber = module.EventSubscriber;
|
43 | }, function (module) {
|
44 | Loader = module.Loader;
|
45 | }, function (module) {
|
46 | relativeToFile = module.relativeToFile;
|
47 | }, function (module) {
|
48 | mixin = module.mixin;
|
49 | }, function (module) {
|
50 | getLogger = module.getLogger;
|
51 | }],
|
52 | execute: (function () {
|
53 |
|
54 | exports({
|
55 | configure: configure,
|
56 | createFullOverrideContext: createFullOverrideContext,
|
57 | getItemsSourceExpression: getItemsSourceExpression,
|
58 | isOneTime: isOneTime,
|
59 | unwrapExpression: unwrapExpression,
|
60 | updateOneTimeBinding: updateOneTimeBinding,
|
61 | updateOverrideContext: updateOverrideContext,
|
62 | viewsRequireLifecycle: viewsRequireLifecycle
|
63 | });
|
64 |
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | var extendStatics = function(d, b) {
|
82 | extendStatics = Object.setPrototypeOf ||
|
83 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
84 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
85 | return extendStatics(d, b);
|
86 | };
|
87 |
|
88 | function __extends(d, b) {
|
89 | if (typeof b !== "function" && b !== null)
|
90 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
91 | extendStatics(d, b);
|
92 | function __() { this.constructor = d; }
|
93 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
94 | }
|
95 |
|
96 | function __decorate(decorators, target, key, desc) {
|
97 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
98 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
99 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
100 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
101 | }
|
102 |
|
103 | var ActivationStrategy;
|
104 | (function (ActivationStrategy) {
|
105 | ActivationStrategy["InvokeLifecycle"] = "invoke-lifecycle";
|
106 | ActivationStrategy["Replace"] = "replace";
|
107 | })(ActivationStrategy || (ActivationStrategy = {}));
|
108 | var Compose = exports('Compose', (function () {
|
109 | function Compose(element, container, compositionEngine, viewSlot, viewResources, taskQueue) {
|
110 | this.activationStrategy = ActivationStrategy.InvokeLifecycle;
|
111 | this.element = element;
|
112 | this.container = container;
|
113 | this.compositionEngine = compositionEngine;
|
114 | this.viewSlot = viewSlot;
|
115 | this.viewResources = viewResources;
|
116 | this.taskQueue = taskQueue;
|
117 | this.currentController = null;
|
118 | this.currentViewModel = null;
|
119 | this.changes = Object.create(null);
|
120 | }
|
121 | Compose.inject = function () {
|
122 | return [DOM.Element, Container, CompositionEngine, ViewSlot, ViewResources, TaskQueue];
|
123 | };
|
124 | Compose.prototype.created = function (owningView) {
|
125 | this.owningView = owningView;
|
126 | };
|
127 | Compose.prototype.bind = function (bindingContext, overrideContext) {
|
128 | this.bindingContext = bindingContext;
|
129 | this.overrideContext = overrideContext;
|
130 | var changes = this.changes;
|
131 | changes.view = this.view;
|
132 | changes.viewModel = this.viewModel;
|
133 | changes.model = this.model;
|
134 | if (!this.pendingTask) {
|
135 | processChanges(this);
|
136 | }
|
137 | };
|
138 | Compose.prototype.unbind = function () {
|
139 | this.changes = Object.create(null);
|
140 | this.bindingContext = null;
|
141 | this.overrideContext = null;
|
142 | var returnToCache = true;
|
143 | var skipAnimation = true;
|
144 | this.viewSlot.removeAll(returnToCache, skipAnimation);
|
145 | };
|
146 | Compose.prototype.modelChanged = function (newValue, oldValue) {
|
147 | this.changes.model = newValue;
|
148 | requestUpdate(this);
|
149 | };
|
150 | Compose.prototype.viewChanged = function (newValue, oldValue) {
|
151 | this.changes.view = newValue;
|
152 | requestUpdate(this);
|
153 | };
|
154 | Compose.prototype.viewModelChanged = function (newValue, oldValue) {
|
155 | this.changes.viewModel = newValue;
|
156 | requestUpdate(this);
|
157 | };
|
158 | __decorate([
|
159 | bindable
|
160 | ], Compose.prototype, "model", void 0);
|
161 | __decorate([
|
162 | bindable
|
163 | ], Compose.prototype, "view", void 0);
|
164 | __decorate([
|
165 | bindable
|
166 | ], Compose.prototype, "viewModel", void 0);
|
167 | __decorate([
|
168 | bindable
|
169 | ], Compose.prototype, "activationStrategy", void 0);
|
170 | __decorate([
|
171 | bindable
|
172 | ], Compose.prototype, "swapOrder", void 0);
|
173 | Compose = __decorate([
|
174 | noView,
|
175 | customElement('compose')
|
176 | ], Compose);
|
177 | return Compose;
|
178 | }()));
|
179 | function isEmpty(obj) {
|
180 | for (var _ in obj) {
|
181 | return false;
|
182 | }
|
183 | return true;
|
184 | }
|
185 | function tryActivateViewModel(vm, model) {
|
186 | if (vm && typeof vm.activate === 'function') {
|
187 | return Promise.resolve(vm.activate(model));
|
188 | }
|
189 | }
|
190 | function createInstruction(composer, instruction) {
|
191 | return Object.assign(instruction, {
|
192 | bindingContext: composer.bindingContext,
|
193 | overrideContext: composer.overrideContext,
|
194 | owningView: composer.owningView,
|
195 | container: composer.container,
|
196 | viewSlot: composer.viewSlot,
|
197 | viewResources: composer.viewResources,
|
198 | currentController: composer.currentController,
|
199 | host: composer.element,
|
200 | swapOrder: composer.swapOrder
|
201 | });
|
202 | }
|
203 | function processChanges(composer) {
|
204 | var changes = composer.changes;
|
205 | composer.changes = Object.create(null);
|
206 | if (needsReInitialization(composer, changes)) {
|
207 | var instruction = {
|
208 | view: composer.view,
|
209 | viewModel: composer.currentViewModel || composer.viewModel,
|
210 | model: composer.model
|
211 | };
|
212 | instruction = Object.assign(instruction, changes);
|
213 | instruction = createInstruction(composer, instruction);
|
214 | composer.pendingTask = composer.compositionEngine.compose(instruction).then(function (controller) {
|
215 | composer.currentController = controller;
|
216 | composer.currentViewModel = controller ? controller.viewModel : null;
|
217 | });
|
218 | }
|
219 | else {
|
220 | composer.pendingTask = tryActivateViewModel(composer.currentViewModel, changes.model);
|
221 | if (!composer.pendingTask) {
|
222 | return;
|
223 | }
|
224 | }
|
225 | composer.pendingTask = composer.pendingTask
|
226 | .then(function () {
|
227 | completeCompositionTask(composer);
|
228 | }, function (reason) {
|
229 | completeCompositionTask(composer);
|
230 | throw reason;
|
231 | });
|
232 | }
|
233 | function completeCompositionTask(composer) {
|
234 | composer.pendingTask = null;
|
235 | if (!isEmpty(composer.changes)) {
|
236 | processChanges(composer);
|
237 | }
|
238 | }
|
239 | function requestUpdate(composer) {
|
240 | if (composer.pendingTask || composer.updateRequested) {
|
241 | return;
|
242 | }
|
243 | composer.updateRequested = true;
|
244 | composer.taskQueue.queueMicroTask(function () {
|
245 | composer.updateRequested = false;
|
246 | processChanges(composer);
|
247 | });
|
248 | }
|
249 | function needsReInitialization(composer, changes) {
|
250 | var activationStrategy = composer.activationStrategy;
|
251 | var vm = composer.currentViewModel;
|
252 | if (vm && typeof vm.determineActivationStrategy === 'function') {
|
253 | activationStrategy = vm.determineActivationStrategy();
|
254 | }
|
255 | return 'view' in changes
|
256 | || 'viewModel' in changes
|
257 | || activationStrategy === ActivationStrategy.Replace;
|
258 | }
|
259 |
|
260 | var IfCore = (function () {
|
261 | function IfCore(viewFactory, viewSlot) {
|
262 | this.viewFactory = viewFactory;
|
263 | this.viewSlot = viewSlot;
|
264 | this.view = null;
|
265 | this.bindingContext = null;
|
266 | this.overrideContext = null;
|
267 | this.showing = false;
|
268 | this.cache = true;
|
269 | }
|
270 | IfCore.prototype.bind = function (bindingContext, overrideContext) {
|
271 | this.bindingContext = bindingContext;
|
272 | this.overrideContext = overrideContext;
|
273 | };
|
274 | IfCore.prototype.unbind = function () {
|
275 | if (this.view === null) {
|
276 | return;
|
277 | }
|
278 | this.view.unbind();
|
279 | if (!this.viewFactory.isCaching) {
|
280 | return;
|
281 | }
|
282 | if (this.showing) {
|
283 | this.showing = false;
|
284 | this.viewSlot.remove(this.view, true, true);
|
285 | }
|
286 | else {
|
287 | this.view.returnToCache();
|
288 | }
|
289 | this.view = null;
|
290 | };
|
291 | IfCore.prototype._show = function () {
|
292 | if (this.showing) {
|
293 | if (!this.view.isBound) {
|
294 | this.view.bind(this.bindingContext, this.overrideContext);
|
295 | }
|
296 | return;
|
297 | }
|
298 | if (this.view === null) {
|
299 | this.view = this.viewFactory.create();
|
300 | }
|
301 | if (!this.view.isBound) {
|
302 | this.view.bind(this.bindingContext, this.overrideContext);
|
303 | }
|
304 | this.showing = true;
|
305 | return this.viewSlot.add(this.view);
|
306 | };
|
307 | IfCore.prototype._hide = function () {
|
308 | var _this = this;
|
309 | if (!this.showing) {
|
310 | return;
|
311 | }
|
312 | this.showing = false;
|
313 | var removed = this.viewSlot.remove(this.view);
|
314 | if (removed instanceof Promise) {
|
315 | return removed.then(function () {
|
316 | _this._unbindView();
|
317 | });
|
318 | }
|
319 | this._unbindView();
|
320 | };
|
321 | IfCore.prototype._unbindView = function () {
|
322 | var cache = this.cache === 'false' ? false : !!this.cache;
|
323 | this.view.unbind();
|
324 | if (!cache) {
|
325 | this.view = null;
|
326 | }
|
327 | };
|
328 | return IfCore;
|
329 | }());
|
330 |
|
331 | var If = exports('If', (function (_super) {
|
332 | __extends(If, _super);
|
333 | function If() {
|
334 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
335 | _this.cache = true;
|
336 | return _this;
|
337 | }
|
338 | If.prototype.bind = function (bindingContext, overrideContext) {
|
339 | _super.prototype.bind.call(this, bindingContext, overrideContext);
|
340 | if (this.condition) {
|
341 | this._show();
|
342 | }
|
343 | else {
|
344 | this._hide();
|
345 | }
|
346 | };
|
347 | If.prototype.conditionChanged = function (newValue) {
|
348 | this._update(newValue);
|
349 | };
|
350 | If.prototype._update = function (show) {
|
351 | var _this = this;
|
352 | if (this.animating) {
|
353 | return;
|
354 | }
|
355 | var promise;
|
356 | if (this.elseVm) {
|
357 | promise = show ? this._swap(this.elseVm, this) : this._swap(this, this.elseVm);
|
358 | }
|
359 | else {
|
360 | promise = show ? this._show() : this._hide();
|
361 | }
|
362 | if (promise) {
|
363 | this.animating = true;
|
364 | promise.then(function () {
|
365 | _this.animating = false;
|
366 | if (_this.condition !== _this.showing) {
|
367 | _this._update(_this.condition);
|
368 | }
|
369 | });
|
370 | }
|
371 | };
|
372 | If.prototype._swap = function (remove, add) {
|
373 | switch (this.swapOrder) {
|
374 | case 'before':
|
375 | return Promise.resolve(add._show()).then(function () { return remove._hide(); });
|
376 | case 'with':
|
377 | return Promise.all([remove._hide(), add._show()]);
|
378 | default:
|
379 | var promise = remove._hide();
|
380 | return promise ? promise.then(function () { return add._show(); }) : add._show();
|
381 | }
|
382 | };
|
383 | __decorate([
|
384 | bindable({ primaryProperty: true })
|
385 | ], If.prototype, "condition", void 0);
|
386 | __decorate([
|
387 | bindable
|
388 | ], If.prototype, "swapOrder", void 0);
|
389 | __decorate([
|
390 | bindable
|
391 | ], If.prototype, "cache", void 0);
|
392 | If = __decorate([
|
393 | customAttribute('if'),
|
394 | templateController,
|
395 | inject(BoundViewFactory, ViewSlot)
|
396 | ], If);
|
397 | return If;
|
398 | }(IfCore)));
|
399 |
|
400 | var Else = exports('Else', (function (_super) {
|
401 | __extends(Else, _super);
|
402 | function Else(viewFactory, viewSlot) {
|
403 | var _this = _super.call(this, viewFactory, viewSlot) || this;
|
404 | _this._registerInIf();
|
405 | return _this;
|
406 | }
|
407 | Else.prototype.bind = function (bindingContext, overrideContext) {
|
408 | _super.prototype.bind.call(this, bindingContext, overrideContext);
|
409 | if (this.ifVm.condition) {
|
410 | this._hide();
|
411 | }
|
412 | else {
|
413 | this._show();
|
414 | }
|
415 | };
|
416 | Else.prototype._registerInIf = function () {
|
417 | var previous = this.viewSlot.anchor.previousSibling;
|
418 | while (previous && !previous.au) {
|
419 | previous = previous.previousSibling;
|
420 | }
|
421 | if (!previous || !previous.au.if) {
|
422 | throw new Error("Can't find matching If for Else custom attribute.");
|
423 | }
|
424 | this.ifVm = previous.au.if.viewModel;
|
425 | this.ifVm.elseVm = this;
|
426 | };
|
427 | Else = __decorate([
|
428 | customAttribute('else'),
|
429 | templateController,
|
430 | inject(BoundViewFactory, ViewSlot)
|
431 | ], Else);
|
432 | return Else;
|
433 | }(IfCore)));
|
434 |
|
435 | var With = exports('With', (function () {
|
436 | function With(viewFactory, viewSlot) {
|
437 | this.viewFactory = viewFactory;
|
438 | this.viewSlot = viewSlot;
|
439 | this.parentOverrideContext = null;
|
440 | this.view = null;
|
441 | }
|
442 | With.prototype.bind = function (bindingContext, overrideContext) {
|
443 | this.parentOverrideContext = overrideContext;
|
444 | this.valueChanged(this.value);
|
445 | };
|
446 | With.prototype.valueChanged = function (newValue) {
|
447 | var overrideContext = createOverrideContext(newValue, this.parentOverrideContext);
|
448 | var view = this.view;
|
449 | if (!view) {
|
450 | view = this.view = this.viewFactory.create();
|
451 | view.bind(newValue, overrideContext);
|
452 | this.viewSlot.add(view);
|
453 | }
|
454 | else {
|
455 | view.bind(newValue, overrideContext);
|
456 | }
|
457 | };
|
458 | With.prototype.unbind = function () {
|
459 | var view = this.view;
|
460 | this.parentOverrideContext = null;
|
461 | if (view) {
|
462 | view.unbind();
|
463 | }
|
464 | };
|
465 | With = __decorate([
|
466 | customAttribute('with'),
|
467 | templateController,
|
468 | inject(BoundViewFactory, ViewSlot)
|
469 | ], With);
|
470 | return With;
|
471 | }()));
|
472 |
|
473 | var oneTime = bindingMode.oneTime;
|
474 | function updateOverrideContexts(views, startIndex) {
|
475 | var length = views.length;
|
476 | if (startIndex > 0) {
|
477 | startIndex = startIndex - 1;
|
478 | }
|
479 | for (; startIndex < length; ++startIndex) {
|
480 | updateOverrideContext(views[startIndex].overrideContext, startIndex, length);
|
481 | }
|
482 | }
|
483 | function createFullOverrideContext(repeat, data, index, length, key) {
|
484 | var bindingContext = {};
|
485 | var overrideContext = createOverrideContext(bindingContext, repeat.scope.overrideContext);
|
486 | if (typeof key !== 'undefined') {
|
487 | bindingContext[repeat.key] = key;
|
488 | bindingContext[repeat.value] = data;
|
489 | }
|
490 | else {
|
491 | bindingContext[repeat.local] = data;
|
492 | }
|
493 | updateOverrideContext(overrideContext, index, length);
|
494 | return overrideContext;
|
495 | }
|
496 | function updateOverrideContext(overrideContext, index, length) {
|
497 | var first = (index === 0);
|
498 | var last = (index === length - 1);
|
499 | var even = index % 2 === 0;
|
500 | overrideContext.$index = index;
|
501 | overrideContext.$first = first;
|
502 | overrideContext.$last = last;
|
503 | overrideContext.$middle = !(first || last);
|
504 | overrideContext.$odd = !even;
|
505 | overrideContext.$even = even;
|
506 | }
|
507 | function getItemsSourceExpression(instruction, attrName) {
|
508 | return instruction.behaviorInstructions
|
509 | .filter(function (bi) { return bi.originalAttrName === attrName; })[0]
|
510 | .attributes
|
511 | .items
|
512 | .sourceExpression;
|
513 | }
|
514 | function unwrapExpression(expression) {
|
515 | var unwrapped = false;
|
516 | while (expression instanceof BindingBehavior) {
|
517 | expression = expression.expression;
|
518 | }
|
519 | while (expression instanceof ValueConverter) {
|
520 | expression = expression.expression;
|
521 | unwrapped = true;
|
522 | }
|
523 | return unwrapped ? expression : null;
|
524 | }
|
525 | function isOneTime(expression) {
|
526 | while (expression instanceof BindingBehavior) {
|
527 | if (expression.name === 'oneTime') {
|
528 | return true;
|
529 | }
|
530 | expression = expression.expression;
|
531 | }
|
532 | return false;
|
533 | }
|
534 | function updateOneTimeBinding(binding) {
|
535 | if (binding.call && binding.mode === oneTime) {
|
536 | binding.call(sourceContext);
|
537 | }
|
538 | else if (binding.updateOneTimeBindings) {
|
539 | binding.updateOneTimeBindings();
|
540 | }
|
541 | }
|
542 | function indexOf(array, item, matcher, startIndex) {
|
543 | if (!matcher) {
|
544 | return array.indexOf(item);
|
545 | }
|
546 | var length = array.length;
|
547 | for (var index = startIndex || 0; index < length; index++) {
|
548 | if (matcher(array[index], item)) {
|
549 | return index;
|
550 | }
|
551 | }
|
552 | return -1;
|
553 | }
|
554 |
|
555 | var ArrayRepeatStrategy = exports('ArrayRepeatStrategy', (function () {
|
556 | function ArrayRepeatStrategy() {
|
557 | }
|
558 | ArrayRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
|
559 | return observerLocator.getArrayObserver(items);
|
560 | };
|
561 | ArrayRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
|
562 | var _this = this;
|
563 | var $repeat = repeat;
|
564 | var itemsLength = items.length;
|
565 | if (!items || itemsLength === 0) {
|
566 | $repeat.removeAllViews(true, !$repeat.viewsRequireLifecycle);
|
567 | return;
|
568 | }
|
569 | var children = $repeat.views();
|
570 | var viewsLength = children.length;
|
571 | if (viewsLength === 0) {
|
572 | this._standardProcessInstanceChanged($repeat, items);
|
573 | return;
|
574 | }
|
575 | if ($repeat.viewsRequireLifecycle) {
|
576 | var childrenSnapshot = children.slice(0);
|
577 | var itemNameInBindingContext = $repeat.local;
|
578 | var matcher_1 = $repeat.matcher();
|
579 | var itemsPreviouslyInViews_1 = [];
|
580 | var viewsToRemove = [];
|
581 | for (var index = 0; index < viewsLength; index++) {
|
582 | var view = childrenSnapshot[index];
|
583 | var oldItem = view.bindingContext[itemNameInBindingContext];
|
584 | if (indexOf(items, oldItem, matcher_1) === -1) {
|
585 | viewsToRemove.push(view);
|
586 | }
|
587 | else {
|
588 | itemsPreviouslyInViews_1.push(oldItem);
|
589 | }
|
590 | }
|
591 | var updateViews = void 0;
|
592 | var removePromise = void 0;
|
593 | if (itemsPreviouslyInViews_1.length > 0) {
|
594 | removePromise = $repeat.removeViews(viewsToRemove, true, !$repeat.viewsRequireLifecycle);
|
595 | updateViews = function () {
|
596 | for (var index = 0; index < itemsLength; index++) {
|
597 | var item = items[index];
|
598 | var indexOfView = indexOf(itemsPreviouslyInViews_1, item, matcher_1, index);
|
599 | var view = void 0;
|
600 | if (indexOfView === -1) {
|
601 | var overrideContext = createFullOverrideContext($repeat, items[index], index, itemsLength);
|
602 | $repeat.insertView(index, overrideContext.bindingContext, overrideContext);
|
603 | itemsPreviouslyInViews_1.splice(index, 0, undefined);
|
604 | }
|
605 | else if (indexOfView === index) {
|
606 | view = children[indexOfView];
|
607 | itemsPreviouslyInViews_1[indexOfView] = undefined;
|
608 | }
|
609 | else {
|
610 | view = children[indexOfView];
|
611 | $repeat.moveView(indexOfView, index);
|
612 | itemsPreviouslyInViews_1.splice(indexOfView, 1);
|
613 | itemsPreviouslyInViews_1.splice(index, 0, undefined);
|
614 | }
|
615 | if (view) {
|
616 | updateOverrideContext(view.overrideContext, index, itemsLength);
|
617 | }
|
618 | }
|
619 | _this._inPlaceProcessItems($repeat, items);
|
620 | };
|
621 | }
|
622 | else {
|
623 | removePromise = $repeat.removeAllViews(true, !$repeat.viewsRequireLifecycle);
|
624 | updateViews = function () { return _this._standardProcessInstanceChanged($repeat, items); };
|
625 | }
|
626 | if (removePromise instanceof Promise) {
|
627 | removePromise.then(updateViews);
|
628 | }
|
629 | else {
|
630 | updateViews();
|
631 | }
|
632 | }
|
633 | else {
|
634 | this._inPlaceProcessItems($repeat, items);
|
635 | }
|
636 | };
|
637 | ArrayRepeatStrategy.prototype._standardProcessInstanceChanged = function (repeat, items) {
|
638 | for (var i = 0, ii = items.length; i < ii; i++) {
|
639 | var overrideContext = createFullOverrideContext(repeat, items[i], i, ii);
|
640 | repeat.addView(overrideContext.bindingContext, overrideContext);
|
641 | }
|
642 | };
|
643 | ArrayRepeatStrategy.prototype._inPlaceProcessItems = function (repeat, items) {
|
644 | var itemsLength = items.length;
|
645 | var viewsLength = repeat.viewCount();
|
646 | while (viewsLength > itemsLength) {
|
647 | viewsLength--;
|
648 | repeat.removeView(viewsLength, true, !repeat.viewsRequireLifecycle);
|
649 | }
|
650 | var local = repeat.local;
|
651 | for (var i = 0; i < viewsLength; i++) {
|
652 | var view = repeat.view(i);
|
653 | var last = i === itemsLength - 1;
|
654 | var middle = i !== 0 && !last;
|
655 | var bindingContext = view.bindingContext;
|
656 | var overrideContext = view.overrideContext;
|
657 | if (bindingContext[local] === items[i]
|
658 | && overrideContext.$middle === middle
|
659 | && overrideContext.$last === last) {
|
660 | continue;
|
661 | }
|
662 | bindingContext[local] = items[i];
|
663 | overrideContext.$middle = middle;
|
664 | overrideContext.$last = last;
|
665 | repeat.updateBindings(view);
|
666 | }
|
667 | for (var i = viewsLength; i < itemsLength; i++) {
|
668 | var overrideContext = createFullOverrideContext(repeat, items[i], i, itemsLength);
|
669 | repeat.addView(overrideContext.bindingContext, overrideContext);
|
670 | }
|
671 | };
|
672 | ArrayRepeatStrategy.prototype.instanceMutated = function (repeat, array, splices) {
|
673 | var _this = this;
|
674 | if (repeat.__queuedSplices) {
|
675 | for (var i = 0, ii = splices.length; i < ii; ++i) {
|
676 | var _a = splices[i], index = _a.index, removed = _a.removed, addedCount = _a.addedCount;
|
677 | mergeSplice(repeat.__queuedSplices, index, removed, addedCount);
|
678 | }
|
679 | repeat.__array = array.slice(0);
|
680 | return;
|
681 | }
|
682 | var maybePromise = this._runSplices(repeat, array.slice(0), splices);
|
683 | if (maybePromise instanceof Promise) {
|
684 | var queuedSplices_1 = repeat.__queuedSplices = [];
|
685 | var runQueuedSplices_1 = function () {
|
686 | if (!queuedSplices_1.length) {
|
687 | repeat.__queuedSplices = undefined;
|
688 | repeat.__array = undefined;
|
689 | return;
|
690 | }
|
691 | var nextPromise = _this._runSplices(repeat, repeat.__array, queuedSplices_1) || Promise.resolve();
|
692 | queuedSplices_1 = repeat.__queuedSplices = [];
|
693 | nextPromise.then(runQueuedSplices_1);
|
694 | };
|
695 | maybePromise.then(runQueuedSplices_1);
|
696 | }
|
697 | };
|
698 | ArrayRepeatStrategy.prototype._runSplices = function (repeat, array, splices) {
|
699 | var _this = this;
|
700 | var removeDelta = 0;
|
701 | var rmPromises = [];
|
702 | for (var i = 0, ii = splices.length; i < ii; ++i) {
|
703 | var splice = splices[i];
|
704 | var removed = splice.removed;
|
705 | for (var j = 0, jj = removed.length; j < jj; ++j) {
|
706 | var viewOrPromise = repeat.removeView(splice.index + removeDelta + rmPromises.length, true);
|
707 | if (viewOrPromise instanceof Promise) {
|
708 | rmPromises.push(viewOrPromise);
|
709 | }
|
710 | }
|
711 | removeDelta -= splice.addedCount;
|
712 | }
|
713 | if (rmPromises.length > 0) {
|
714 | return Promise.all(rmPromises).then(function () {
|
715 | var spliceIndexLow = _this._handleAddedSplices(repeat, array, splices);
|
716 | updateOverrideContexts(repeat.views(), spliceIndexLow);
|
717 | });
|
718 | }
|
719 | var spliceIndexLow = this._handleAddedSplices(repeat, array, splices);
|
720 | updateOverrideContexts(repeat.views(), spliceIndexLow);
|
721 | return undefined;
|
722 | };
|
723 | ArrayRepeatStrategy.prototype._handleAddedSplices = function (repeat, array, splices) {
|
724 | var spliceIndex;
|
725 | var spliceIndexLow;
|
726 | var arrayLength = array.length;
|
727 | for (var i = 0, ii = splices.length; i < ii; ++i) {
|
728 | var splice = splices[i];
|
729 | var addIndex = spliceIndex = splice.index;
|
730 | var end = splice.index + splice.addedCount;
|
731 | if (typeof spliceIndexLow === 'undefined' || spliceIndexLow === null || spliceIndexLow > splice.index) {
|
732 | spliceIndexLow = spliceIndex;
|
733 | }
|
734 | for (; addIndex < end; ++addIndex) {
|
735 | var overrideContext = createFullOverrideContext(repeat, array[addIndex], addIndex, arrayLength);
|
736 | repeat.insertView(addIndex, overrideContext.bindingContext, overrideContext);
|
737 | }
|
738 | }
|
739 | return spliceIndexLow;
|
740 | };
|
741 | return ArrayRepeatStrategy;
|
742 | }()));
|
743 |
|
744 | var MapRepeatStrategy = exports('MapRepeatStrategy', (function () {
|
745 | function MapRepeatStrategy() {
|
746 | }
|
747 | MapRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
|
748 | return observerLocator.getMapObserver(items);
|
749 | };
|
750 | MapRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
|
751 | var _this = this;
|
752 | var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
|
753 | if (removePromise instanceof Promise) {
|
754 | removePromise.then(function () { return _this._standardProcessItems(repeat, items); });
|
755 | return;
|
756 | }
|
757 | this._standardProcessItems(repeat, items);
|
758 | };
|
759 | MapRepeatStrategy.prototype._standardProcessItems = function (repeat, items) {
|
760 | var index = 0;
|
761 | var overrideContext;
|
762 | items.forEach(function (value, key) {
|
763 | overrideContext = createFullOverrideContext(repeat, value, index, items.size, key);
|
764 | repeat.addView(overrideContext.bindingContext, overrideContext);
|
765 | ++index;
|
766 | });
|
767 | };
|
768 | MapRepeatStrategy.prototype.instanceMutated = function (repeat, map, records) {
|
769 | var key;
|
770 | var i;
|
771 | var ii;
|
772 | var overrideContext;
|
773 | var removeIndex;
|
774 | var addIndex;
|
775 | var record;
|
776 | var rmPromises = [];
|
777 | var viewOrPromise;
|
778 | for (i = 0, ii = records.length; i < ii; ++i) {
|
779 | record = records[i];
|
780 | key = record.key;
|
781 | switch (record.type) {
|
782 | case 'update':
|
783 | removeIndex = this._getViewIndexByKey(repeat, key);
|
784 | viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle);
|
785 | if (viewOrPromise instanceof Promise) {
|
786 | rmPromises.push(viewOrPromise);
|
787 | }
|
788 | overrideContext = createFullOverrideContext(repeat, map.get(key), removeIndex, map.size, key);
|
789 | repeat.insertView(removeIndex, overrideContext.bindingContext, overrideContext);
|
790 | break;
|
791 | case 'add':
|
792 | addIndex = repeat.viewCount() <= map.size - 1 ? repeat.viewCount() : map.size - 1;
|
793 | overrideContext = createFullOverrideContext(repeat, map.get(key), addIndex, map.size, key);
|
794 | repeat.insertView(map.size - 1, overrideContext.bindingContext, overrideContext);
|
795 | break;
|
796 | case 'delete':
|
797 | if (record.oldValue === undefined) {
|
798 | return;
|
799 | }
|
800 | removeIndex = this._getViewIndexByKey(repeat, key);
|
801 | viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle);
|
802 | if (viewOrPromise instanceof Promise) {
|
803 | rmPromises.push(viewOrPromise);
|
804 | }
|
805 | break;
|
806 | case 'clear':
|
807 | repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
|
808 | break;
|
809 | default:
|
810 | continue;
|
811 | }
|
812 | }
|
813 | if (rmPromises.length > 0) {
|
814 | Promise.all(rmPromises).then(function () {
|
815 | updateOverrideContexts(repeat.views(), 0);
|
816 | });
|
817 | }
|
818 | else {
|
819 | updateOverrideContexts(repeat.views(), 0);
|
820 | }
|
821 | };
|
822 | MapRepeatStrategy.prototype._getViewIndexByKey = function (repeat, key) {
|
823 | var i;
|
824 | var ii;
|
825 | var child;
|
826 | for (i = 0, ii = repeat.viewCount(); i < ii; ++i) {
|
827 | child = repeat.view(i);
|
828 | if (child.bindingContext[repeat.key] === key) {
|
829 | return i;
|
830 | }
|
831 | }
|
832 | return undefined;
|
833 | };
|
834 | return MapRepeatStrategy;
|
835 | }()));
|
836 |
|
837 | var NullRepeatStrategy = exports('NullRepeatStrategy', (function () {
|
838 | function NullRepeatStrategy() {
|
839 | }
|
840 | NullRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
|
841 | repeat.removeAllViews(true);
|
842 | };
|
843 | NullRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
|
844 | };
|
845 | return NullRepeatStrategy;
|
846 | }()));
|
847 |
|
848 | var NumberRepeatStrategy = exports('NumberRepeatStrategy', (function () {
|
849 | function NumberRepeatStrategy() {
|
850 | }
|
851 | NumberRepeatStrategy.prototype.getCollectionObserver = function () {
|
852 | return null;
|
853 | };
|
854 | NumberRepeatStrategy.prototype.instanceChanged = function (repeat, value) {
|
855 | var _this = this;
|
856 | var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
|
857 | if (removePromise instanceof Promise) {
|
858 | removePromise.then(function () { return _this._standardProcessItems(repeat, value); });
|
859 | return;
|
860 | }
|
861 | this._standardProcessItems(repeat, value);
|
862 | };
|
863 | NumberRepeatStrategy.prototype._standardProcessItems = function (repeat, value) {
|
864 | var childrenLength = repeat.viewCount();
|
865 | var i;
|
866 | var ii;
|
867 | var overrideContext;
|
868 | var viewsToRemove;
|
869 | value = Math.floor(value);
|
870 | viewsToRemove = childrenLength - value;
|
871 | if (viewsToRemove > 0) {
|
872 | if (viewsToRemove > childrenLength) {
|
873 | viewsToRemove = childrenLength;
|
874 | }
|
875 | for (i = 0, ii = viewsToRemove; i < ii; ++i) {
|
876 | repeat.removeView(childrenLength - (i + 1), true, !repeat.viewsRequireLifecycle);
|
877 | }
|
878 | return;
|
879 | }
|
880 | for (i = childrenLength, ii = value; i < ii; ++i) {
|
881 | overrideContext = createFullOverrideContext(repeat, i, i, ii);
|
882 | repeat.addView(overrideContext.bindingContext, overrideContext);
|
883 | }
|
884 | updateOverrideContexts(repeat.views(), 0);
|
885 | };
|
886 | return NumberRepeatStrategy;
|
887 | }()));
|
888 |
|
889 | var SetRepeatStrategy = exports('SetRepeatStrategy', (function () {
|
890 | function SetRepeatStrategy() {
|
891 | }
|
892 | SetRepeatStrategy.prototype.getCollectionObserver = function (observerLocator, items) {
|
893 | return observerLocator.getSetObserver(items);
|
894 | };
|
895 | SetRepeatStrategy.prototype.instanceChanged = function (repeat, items) {
|
896 | var _this = this;
|
897 | var removePromise = repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
|
898 | if (removePromise instanceof Promise) {
|
899 | removePromise.then(function () { return _this._standardProcessItems(repeat, items); });
|
900 | return;
|
901 | }
|
902 | this._standardProcessItems(repeat, items);
|
903 | };
|
904 | SetRepeatStrategy.prototype._standardProcessItems = function (repeat, items) {
|
905 | var index = 0;
|
906 | var overrideContext;
|
907 | items.forEach(function (value) {
|
908 | overrideContext = createFullOverrideContext(repeat, value, index, items.size);
|
909 | repeat.addView(overrideContext.bindingContext, overrideContext);
|
910 | ++index;
|
911 | });
|
912 | };
|
913 | SetRepeatStrategy.prototype.instanceMutated = function (repeat, set, records) {
|
914 | var value;
|
915 | var i;
|
916 | var ii;
|
917 | var overrideContext;
|
918 | var removeIndex;
|
919 | var record;
|
920 | var rmPromises = [];
|
921 | var viewOrPromise;
|
922 | for (i = 0, ii = records.length; i < ii; ++i) {
|
923 | record = records[i];
|
924 | value = record.value;
|
925 | switch (record.type) {
|
926 | case 'add':
|
927 | var size = Math.max(set.size - 1, 0);
|
928 | overrideContext = createFullOverrideContext(repeat, value, size, set.size);
|
929 | repeat.insertView(size, overrideContext.bindingContext, overrideContext);
|
930 | break;
|
931 | case 'delete':
|
932 | removeIndex = this._getViewIndexByValue(repeat, value);
|
933 | viewOrPromise = repeat.removeView(removeIndex, true, !repeat.viewsRequireLifecycle);
|
934 | if (viewOrPromise instanceof Promise) {
|
935 | rmPromises.push(viewOrPromise);
|
936 | }
|
937 | break;
|
938 | case 'clear':
|
939 | repeat.removeAllViews(true, !repeat.viewsRequireLifecycle);
|
940 | break;
|
941 | default:
|
942 | continue;
|
943 | }
|
944 | }
|
945 | if (rmPromises.length > 0) {
|
946 | Promise.all(rmPromises).then(function () {
|
947 | updateOverrideContexts(repeat.views(), 0);
|
948 | });
|
949 | }
|
950 | else {
|
951 | updateOverrideContexts(repeat.views(), 0);
|
952 | }
|
953 | };
|
954 | SetRepeatStrategy.prototype._getViewIndexByValue = function (repeat, value) {
|
955 | var i;
|
956 | var ii;
|
957 | var child;
|
958 | for (i = 0, ii = repeat.viewCount(); i < ii; ++i) {
|
959 | child = repeat.view(i);
|
960 | if (child.bindingContext[repeat.local] === value) {
|
961 | return i;
|
962 | }
|
963 | }
|
964 | return undefined;
|
965 | };
|
966 | return SetRepeatStrategy;
|
967 | }()));
|
968 |
|
969 | var RepeatStrategyLocator = exports('RepeatStrategyLocator', (function () {
|
970 | function RepeatStrategyLocator() {
|
971 | this.matchers = [];
|
972 | this.strategies = [];
|
973 | this.addStrategy(function (items) { return items === null || items === undefined; }, new NullRepeatStrategy());
|
974 | this.addStrategy(function (items) { return items instanceof Array; }, new ArrayRepeatStrategy());
|
975 | this.addStrategy(function (items) { return items instanceof Map; }, new MapRepeatStrategy());
|
976 | this.addStrategy(function (items) { return items instanceof Set; }, new SetRepeatStrategy());
|
977 | this.addStrategy(function (items) { return typeof items === 'number'; }, new NumberRepeatStrategy());
|
978 | }
|
979 | RepeatStrategyLocator.prototype.addStrategy = function (matcher, strategy) {
|
980 | this.matchers.push(matcher);
|
981 | this.strategies.push(strategy);
|
982 | };
|
983 | RepeatStrategyLocator.prototype.getStrategy = function (items) {
|
984 | var matchers = this.matchers;
|
985 | for (var i = 0, ii = matchers.length; i < ii; ++i) {
|
986 | if (matchers[i](items)) {
|
987 | return this.strategies[i];
|
988 | }
|
989 | }
|
990 | return null;
|
991 | };
|
992 | return RepeatStrategyLocator;
|
993 | }()));
|
994 |
|
995 | var lifecycleOptionalBehaviors = ['focus', 'if', 'else', 'repeat', 'show', 'hide', 'with'];
|
996 | function behaviorRequiresLifecycle(instruction) {
|
997 | var t = instruction.type;
|
998 | var name = t.elementName !== null ? t.elementName : t.attributeName;
|
999 | return lifecycleOptionalBehaviors.indexOf(name) === -1 && (t.handlesAttached || t.handlesBind || t.handlesCreated || t.handlesDetached || t.handlesUnbind)
|
1000 | || t.viewFactory && viewsRequireLifecycle(t.viewFactory)
|
1001 | || instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory);
|
1002 | }
|
1003 | function targetRequiresLifecycle(instruction) {
|
1004 | var behaviors = instruction.behaviorInstructions;
|
1005 | if (behaviors) {
|
1006 | var i = behaviors.length;
|
1007 | while (i--) {
|
1008 | if (behaviorRequiresLifecycle(behaviors[i])) {
|
1009 | return true;
|
1010 | }
|
1011 | }
|
1012 | }
|
1013 | return instruction.viewFactory && viewsRequireLifecycle(instruction.viewFactory);
|
1014 | }
|
1015 | function viewsRequireLifecycle(viewFactory) {
|
1016 | if ('_viewsRequireLifecycle' in viewFactory) {
|
1017 | return viewFactory._viewsRequireLifecycle;
|
1018 | }
|
1019 | viewFactory._viewsRequireLifecycle = false;
|
1020 | if (viewFactory.viewFactory) {
|
1021 | viewFactory._viewsRequireLifecycle = viewsRequireLifecycle(viewFactory.viewFactory);
|
1022 | return viewFactory._viewsRequireLifecycle;
|
1023 | }
|
1024 | if (viewFactory.template.querySelector('.au-animate')) {
|
1025 | viewFactory._viewsRequireLifecycle = true;
|
1026 | return true;
|
1027 | }
|
1028 | for (var id in viewFactory.instructions) {
|
1029 | if (targetRequiresLifecycle(viewFactory.instructions[id])) {
|
1030 | viewFactory._viewsRequireLifecycle = true;
|
1031 | return true;
|
1032 | }
|
1033 | }
|
1034 | viewFactory._viewsRequireLifecycle = false;
|
1035 | return false;
|
1036 | }
|
1037 |
|
1038 | var AbstractRepeater = exports('AbstractRepeater', (function () {
|
1039 | function AbstractRepeater(options) {
|
1040 | Object.assign(this, {
|
1041 | local: 'items',
|
1042 | viewsRequireLifecycle: true
|
1043 | }, options);
|
1044 | }
|
1045 | AbstractRepeater.prototype.viewCount = function () {
|
1046 | throw new Error('subclass must implement `viewCount`');
|
1047 | };
|
1048 | AbstractRepeater.prototype.views = function () {
|
1049 | throw new Error('subclass must implement `views`');
|
1050 | };
|
1051 | AbstractRepeater.prototype.view = function (index) {
|
1052 | throw new Error('subclass must implement `view`');
|
1053 | };
|
1054 | AbstractRepeater.prototype.matcher = function () {
|
1055 | throw new Error('subclass must implement `matcher`');
|
1056 | };
|
1057 | AbstractRepeater.prototype.addView = function (bindingContext, overrideContext) {
|
1058 | throw new Error('subclass must implement `addView`');
|
1059 | };
|
1060 | AbstractRepeater.prototype.insertView = function (index, bindingContext, overrideContext) {
|
1061 | throw new Error('subclass must implement `insertView`');
|
1062 | };
|
1063 | AbstractRepeater.prototype.moveView = function (sourceIndex, targetIndex) {
|
1064 | throw new Error('subclass must implement `moveView`');
|
1065 | };
|
1066 | AbstractRepeater.prototype.removeAllViews = function (returnToCache, skipAnimation) {
|
1067 | throw new Error('subclass must implement `removeAllViews`');
|
1068 | };
|
1069 | AbstractRepeater.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) {
|
1070 | throw new Error('subclass must implement `removeView`');
|
1071 | };
|
1072 | AbstractRepeater.prototype.removeView = function (index, returnToCache, skipAnimation) {
|
1073 | throw new Error('subclass must implement `removeView`');
|
1074 | };
|
1075 | AbstractRepeater.prototype.updateBindings = function (view) {
|
1076 | throw new Error('subclass must implement `updateBindings`');
|
1077 | };
|
1078 | return AbstractRepeater;
|
1079 | }()));
|
1080 |
|
1081 | var matcherExtractionMarker = '__marker_extracted__';
|
1082 | var Repeat = exports('Repeat', (function (_super) {
|
1083 | __extends(Repeat, _super);
|
1084 | function Repeat(viewFactory, instruction, viewSlot, viewResources, observerLocator, strategyLocator) {
|
1085 | var _this = _super.call(this, {
|
1086 | local: 'item',
|
1087 | viewsRequireLifecycle: viewsRequireLifecycle(viewFactory)
|
1088 | }) || this;
|
1089 | _this.viewFactory = viewFactory;
|
1090 | _this.instruction = instruction;
|
1091 | _this.viewSlot = viewSlot;
|
1092 | _this.lookupFunctions = viewResources.lookupFunctions;
|
1093 | _this.observerLocator = observerLocator;
|
1094 | _this.key = 'key';
|
1095 | _this.value = 'value';
|
1096 | _this.strategyLocator = strategyLocator;
|
1097 | _this.ignoreMutation = false;
|
1098 | _this.sourceExpression = getItemsSourceExpression(_this.instruction, 'repeat.for');
|
1099 | _this.isOneTime = isOneTime(_this.sourceExpression);
|
1100 | _this.viewsRequireLifecycle = viewsRequireLifecycle(viewFactory);
|
1101 | return _this;
|
1102 | }
|
1103 | Repeat_1 = Repeat;
|
1104 | Repeat.prototype.call = function (context, changes) {
|
1105 | this[context](this.items, changes);
|
1106 | };
|
1107 | Repeat.prototype.bind = function (bindingContext, overrideContext) {
|
1108 | this.scope = { bindingContext: bindingContext, overrideContext: overrideContext };
|
1109 | var instruction = this.instruction;
|
1110 | if (!(matcherExtractionMarker in instruction)) {
|
1111 | instruction[matcherExtractionMarker] = this._captureAndRemoveMatcherBinding();
|
1112 | }
|
1113 | this.matcherBinding = instruction[matcherExtractionMarker];
|
1114 | this.itemsChanged();
|
1115 | };
|
1116 | Repeat.prototype.unbind = function () {
|
1117 | this.scope = null;
|
1118 | this.items = null;
|
1119 | this.matcherBinding = null;
|
1120 | this.viewSlot.removeAll(true, true);
|
1121 | this._unsubscribeCollection();
|
1122 | };
|
1123 | Repeat.prototype._unsubscribeCollection = function () {
|
1124 | if (this.collectionObserver) {
|
1125 | this.collectionObserver.unsubscribe(this.callContext, this);
|
1126 | this.collectionObserver = null;
|
1127 | this.callContext = null;
|
1128 | }
|
1129 | };
|
1130 | Repeat.prototype.itemsChanged = function () {
|
1131 | var _this = this;
|
1132 | this._unsubscribeCollection();
|
1133 | if (!this.scope) {
|
1134 | return;
|
1135 | }
|
1136 | var items = this.items;
|
1137 | this.strategy = this.strategyLocator.getStrategy(items);
|
1138 | if (!this.strategy) {
|
1139 | throw new Error("Value for '".concat(this.sourceExpression, "' is non-repeatable"));
|
1140 | }
|
1141 | if (!this.isOneTime && !this._observeInnerCollection()) {
|
1142 | this._observeCollection();
|
1143 | }
|
1144 | this.ignoreMutation = true;
|
1145 | this.strategy.instanceChanged(this, items);
|
1146 | this.observerLocator.taskQueue.queueMicroTask(function () {
|
1147 | _this.ignoreMutation = false;
|
1148 | });
|
1149 | };
|
1150 | Repeat.prototype._getInnerCollection = function () {
|
1151 | var expression = unwrapExpression(this.sourceExpression);
|
1152 | if (!expression) {
|
1153 | return null;
|
1154 | }
|
1155 | return expression.evaluate(this.scope, null);
|
1156 | };
|
1157 | Repeat.prototype.handleCollectionMutated = function (collection, changes) {
|
1158 | if (!this.collectionObserver) {
|
1159 | return;
|
1160 | }
|
1161 | if (this.ignoreMutation) {
|
1162 | return;
|
1163 | }
|
1164 | this.strategy.instanceMutated(this, collection, changes);
|
1165 | };
|
1166 | Repeat.prototype.handleInnerCollectionMutated = function (collection, changes) {
|
1167 | var _this = this;
|
1168 | if (!this.collectionObserver) {
|
1169 | return;
|
1170 | }
|
1171 | if (this.ignoreMutation) {
|
1172 | return;
|
1173 | }
|
1174 | this.ignoreMutation = true;
|
1175 | var newItems = this.sourceExpression.evaluate(this.scope, this.lookupFunctions);
|
1176 | this.observerLocator.taskQueue.queueMicroTask(function () { return _this.ignoreMutation = false; });
|
1177 | if (newItems === this.items) {
|
1178 | this.itemsChanged();
|
1179 | }
|
1180 | else {
|
1181 | this.items = newItems;
|
1182 | }
|
1183 | };
|
1184 | Repeat.prototype._observeInnerCollection = function () {
|
1185 | var items = this._getInnerCollection();
|
1186 | var strategy = this.strategyLocator.getStrategy(items);
|
1187 | if (!strategy) {
|
1188 | return false;
|
1189 | }
|
1190 | this.collectionObserver = strategy.getCollectionObserver(this.observerLocator, items);
|
1191 | if (!this.collectionObserver) {
|
1192 | return false;
|
1193 | }
|
1194 | this.callContext = 'handleInnerCollectionMutated';
|
1195 | this.collectionObserver.subscribe(this.callContext, this);
|
1196 | return true;
|
1197 | };
|
1198 | Repeat.prototype._observeCollection = function () {
|
1199 | var items = this.items;
|
1200 | this.collectionObserver = this.strategy.getCollectionObserver(this.observerLocator, items);
|
1201 | if (this.collectionObserver) {
|
1202 | this.callContext = 'handleCollectionMutated';
|
1203 | this.collectionObserver.subscribe(this.callContext, this);
|
1204 | }
|
1205 | };
|
1206 | Repeat.prototype._captureAndRemoveMatcherBinding = function () {
|
1207 | var viewFactory = this.viewFactory.viewFactory;
|
1208 | if (viewFactory) {
|
1209 | var template = viewFactory.template;
|
1210 | var instructions = viewFactory.instructions;
|
1211 | if (Repeat_1.useInnerMatcher) {
|
1212 | return extractMatcherBindingExpression(instructions);
|
1213 | }
|
1214 | if (getChildrenCount(template) > 1) {
|
1215 | return undefined;
|
1216 | }
|
1217 | var repeatedElement = getFirstElementChild(template);
|
1218 | if (!repeatedElement.hasAttribute('au-target-id')) {
|
1219 | return undefined;
|
1220 | }
|
1221 | var repeatedElementTargetId = repeatedElement.getAttribute('au-target-id');
|
1222 | return extractMatcherBindingExpression(instructions, repeatedElementTargetId);
|
1223 | }
|
1224 | return undefined;
|
1225 | };
|
1226 | Repeat.prototype.viewCount = function () { return this.viewSlot.children.length; };
|
1227 | Repeat.prototype.views = function () { return this.viewSlot.children; };
|
1228 | Repeat.prototype.view = function (index) { return this.viewSlot.children[index]; };
|
1229 | Repeat.prototype.matcher = function () {
|
1230 | var matcherBinding = this.matcherBinding;
|
1231 | return matcherBinding
|
1232 | ? matcherBinding.sourceExpression.evaluate(this.scope, matcherBinding.lookupFunctions)
|
1233 | : null;
|
1234 | };
|
1235 | Repeat.prototype.addView = function (bindingContext, overrideContext) {
|
1236 | var view = this.viewFactory.create();
|
1237 | view.bind(bindingContext, overrideContext);
|
1238 | this.viewSlot.add(view);
|
1239 | };
|
1240 | Repeat.prototype.insertView = function (index, bindingContext, overrideContext) {
|
1241 | var view = this.viewFactory.create();
|
1242 | view.bind(bindingContext, overrideContext);
|
1243 | this.viewSlot.insert(index, view);
|
1244 | };
|
1245 | Repeat.prototype.moveView = function (sourceIndex, targetIndex) {
|
1246 | this.viewSlot.move(sourceIndex, targetIndex);
|
1247 | };
|
1248 | Repeat.prototype.removeAllViews = function (returnToCache, skipAnimation) {
|
1249 | return this.viewSlot.removeAll(returnToCache, skipAnimation);
|
1250 | };
|
1251 | Repeat.prototype.removeViews = function (viewsToRemove, returnToCache, skipAnimation) {
|
1252 | return this.viewSlot.removeMany(viewsToRemove, returnToCache, skipAnimation);
|
1253 | };
|
1254 | Repeat.prototype.removeView = function (index, returnToCache, skipAnimation) {
|
1255 | return this.viewSlot.removeAt(index, returnToCache, skipAnimation);
|
1256 | };
|
1257 | Repeat.prototype.updateBindings = function (view) {
|
1258 | var $view = view;
|
1259 | var j = $view.bindings.length;
|
1260 | while (j--) {
|
1261 | updateOneTimeBinding($view.bindings[j]);
|
1262 | }
|
1263 | j = $view.controllers.length;
|
1264 | while (j--) {
|
1265 | var k = $view.controllers[j].boundProperties.length;
|
1266 | while (k--) {
|
1267 | var binding = $view.controllers[j].boundProperties[k].binding;
|
1268 | updateOneTimeBinding(binding);
|
1269 | }
|
1270 | }
|
1271 | };
|
1272 | var Repeat_1;
|
1273 | Repeat.useInnerMatcher = true;
|
1274 | __decorate([
|
1275 | bindable
|
1276 | ], Repeat.prototype, "items", void 0);
|
1277 | __decorate([
|
1278 | bindable
|
1279 | ], Repeat.prototype, "local", void 0);
|
1280 | __decorate([
|
1281 | bindable
|
1282 | ], Repeat.prototype, "key", void 0);
|
1283 | __decorate([
|
1284 | bindable
|
1285 | ], Repeat.prototype, "value", void 0);
|
1286 | Repeat = Repeat_1 = __decorate([
|
1287 | customAttribute('repeat'),
|
1288 | templateController,
|
1289 | inject(BoundViewFactory, TargetInstruction, ViewSlot, ViewResources, ObserverLocator, RepeatStrategyLocator)
|
1290 | ], Repeat);
|
1291 | return Repeat;
|
1292 | }(AbstractRepeater)));
|
1293 | var extractMatcherBindingExpression = function (instructions, targetedElementId) {
|
1294 | var instructionIds = Object.keys(instructions);
|
1295 | for (var i = 0; i < instructionIds.length; i++) {
|
1296 | var instructionId = instructionIds[i];
|
1297 | if (targetedElementId !== undefined && instructionId !== targetedElementId) {
|
1298 | continue;
|
1299 | }
|
1300 | var expressions = instructions[instructionId].expressions;
|
1301 | if (expressions) {
|
1302 | for (var ii = 0; ii < expressions.length; ii++) {
|
1303 | if (expressions[ii].targetProperty === 'matcher') {
|
1304 | var matcherBindingExpression = expressions[ii];
|
1305 | expressions.splice(ii, 1);
|
1306 | return matcherBindingExpression;
|
1307 | }
|
1308 | }
|
1309 | }
|
1310 | }
|
1311 | };
|
1312 | var getChildrenCount = function (el) {
|
1313 | var childNodes = el.childNodes;
|
1314 | var count = 0;
|
1315 | for (var i = 0, ii = childNodes.length; ii > i; ++i) {
|
1316 | if (childNodes[i].nodeType === 1) {
|
1317 | ++count;
|
1318 | }
|
1319 | }
|
1320 | return count;
|
1321 | };
|
1322 | var getFirstElementChild = function (el) {
|
1323 | var firstChild = el.firstChild;
|
1324 | while (firstChild !== null) {
|
1325 | if (firstChild.nodeType === 1) {
|
1326 | return firstChild;
|
1327 | }
|
1328 | firstChild = firstChild.nextSibling;
|
1329 | }
|
1330 | return null;
|
1331 | };
|
1332 |
|
1333 | var aureliaHideClassName = 'aurelia-hide';
|
1334 | var aureliaHideClass = ".".concat(aureliaHideClassName, " { display:none !important; }");
|
1335 | function injectAureliaHideStyleAtHead() {
|
1336 | DOM.injectStyles(aureliaHideClass);
|
1337 | }
|
1338 | function injectAureliaHideStyleAtBoundary(domBoundary) {
|
1339 | if (FEATURE.shadowDOM && domBoundary && !domBoundary.hasAureliaHideStyle) {
|
1340 | domBoundary.hasAureliaHideStyle = true;
|
1341 | DOM.injectStyles(aureliaHideClass, domBoundary);
|
1342 | }
|
1343 | }
|
1344 |
|
1345 | var Show = exports('Show', (function () {
|
1346 | function Show(element, animator, domBoundary) {
|
1347 | this.element = element;
|
1348 | this.animator = animator;
|
1349 | this.domBoundary = domBoundary;
|
1350 | }
|
1351 | Show.inject = function () {
|
1352 | return [DOM.Element, Animator, Optional.of(DOM.boundary, true)];
|
1353 | };
|
1354 | Show.prototype.created = function () {
|
1355 | injectAureliaHideStyleAtBoundary(this.domBoundary);
|
1356 | };
|
1357 | Show.prototype.valueChanged = function (newValue) {
|
1358 | var element = this.element;
|
1359 | var animator = this.animator;
|
1360 | if (newValue) {
|
1361 | animator.removeClass(element, aureliaHideClassName);
|
1362 | }
|
1363 | else {
|
1364 | animator.addClass(element, aureliaHideClassName);
|
1365 | }
|
1366 | };
|
1367 | Show.prototype.bind = function (bindingContext) {
|
1368 | this.valueChanged(this.value);
|
1369 | };
|
1370 | Show = __decorate([
|
1371 | customAttribute('show')
|
1372 | ], Show);
|
1373 | return Show;
|
1374 | }()));
|
1375 |
|
1376 | var Hide = exports('Hide', (function () {
|
1377 | function Hide(element, animator, domBoundary) {
|
1378 | this.element = element;
|
1379 | this.animator = animator;
|
1380 | this.domBoundary = domBoundary;
|
1381 | }
|
1382 | Hide.inject = function () {
|
1383 | return [DOM.Element, Animator, Optional.of(DOM.boundary, true)];
|
1384 | };
|
1385 | Hide.prototype.created = function () {
|
1386 | injectAureliaHideStyleAtBoundary(this.domBoundary);
|
1387 | };
|
1388 | Hide.prototype.valueChanged = function (newValue) {
|
1389 | if (newValue) {
|
1390 | this.animator.addClass(this.element, aureliaHideClassName);
|
1391 | }
|
1392 | else {
|
1393 | this.animator.removeClass(this.element, aureliaHideClassName);
|
1394 | }
|
1395 | };
|
1396 | Hide.prototype.bind = function (bindingContext) {
|
1397 | this.valueChanged(this.value);
|
1398 | };
|
1399 | Hide.prototype.value = function (value) {
|
1400 | throw new Error('Method not implemented.');
|
1401 | };
|
1402 | Hide = __decorate([
|
1403 | customAttribute('hide')
|
1404 | ], Hide);
|
1405 | return Hide;
|
1406 | }()));
|
1407 |
|
1408 | var HTMLSanitizer = exports('HTMLSanitizer', (function () {
|
1409 | function HTMLSanitizer() {
|
1410 | }
|
1411 | HTMLSanitizer.prototype.sanitize = function (input) {
|
1412 | throw new Error("To protect the application against a wide variety of sophisticated XSS attacks.\nPlease see https://aurelia.io/docs/binding/basics#element-content for instructions on how to use a secure solution like DOMPurify or sanitize-html.");
|
1413 | };
|
1414 | return HTMLSanitizer;
|
1415 | }()));
|
1416 |
|
1417 | var SanitizeHTMLValueConverter = exports('SanitizeHTMLValueConverter', (function () {
|
1418 | function SanitizeHTMLValueConverter(sanitizer) {
|
1419 | this.sanitizer = sanitizer;
|
1420 | }
|
1421 | SanitizeHTMLValueConverter.prototype.toView = function (untrustedMarkup) {
|
1422 | if (untrustedMarkup === null || untrustedMarkup === undefined) {
|
1423 | return null;
|
1424 | }
|
1425 | return this.sanitizer.sanitize(untrustedMarkup);
|
1426 | };
|
1427 | SanitizeHTMLValueConverter = __decorate([
|
1428 | valueConverter('sanitizeHTML'),
|
1429 | inject(HTMLSanitizer)
|
1430 | ], SanitizeHTMLValueConverter);
|
1431 | return SanitizeHTMLValueConverter;
|
1432 | }()));
|
1433 |
|
1434 | var Replaceable = exports('Replaceable', (function () {
|
1435 | function Replaceable(viewFactory, viewSlot) {
|
1436 | this.viewFactory = viewFactory;
|
1437 | this.viewSlot = viewSlot;
|
1438 | this.view = null;
|
1439 | }
|
1440 | Replaceable.prototype.bind = function (bindingContext, overrideContext) {
|
1441 | if (this.view === null) {
|
1442 | this.view = this.viewFactory.create();
|
1443 | this.viewSlot.add(this.view);
|
1444 | }
|
1445 | this.view.bind(bindingContext, overrideContext);
|
1446 | };
|
1447 | Replaceable.prototype.unbind = function () {
|
1448 | this.view.unbind();
|
1449 | };
|
1450 | Replaceable = __decorate([
|
1451 | customAttribute('replaceable'),
|
1452 | templateController,
|
1453 | inject(BoundViewFactory, ViewSlot)
|
1454 | ], Replaceable);
|
1455 | return Replaceable;
|
1456 | }()));
|
1457 |
|
1458 | var Focus = exports('Focus', (function () {
|
1459 | function Focus(element, taskQueue) {
|
1460 | this.element = element;
|
1461 | this.taskQueue = taskQueue;
|
1462 | this.isAttached = false;
|
1463 | this.needsApply = false;
|
1464 | }
|
1465 | Focus.inject = function () {
|
1466 | return [DOM.Element, TaskQueue];
|
1467 | };
|
1468 | Focus.prototype.valueChanged = function () {
|
1469 | if (this.isAttached) {
|
1470 | this._apply();
|
1471 | }
|
1472 | else {
|
1473 | this.needsApply = true;
|
1474 | }
|
1475 | };
|
1476 | Focus.prototype._apply = function () {
|
1477 | var _this = this;
|
1478 | if (this.value) {
|
1479 | this.taskQueue.queueMicroTask(function () {
|
1480 | if (_this.value) {
|
1481 | _this.element.focus();
|
1482 | }
|
1483 | });
|
1484 | }
|
1485 | else {
|
1486 | this.element.blur();
|
1487 | }
|
1488 | };
|
1489 | Focus.prototype.attached = function () {
|
1490 | this.isAttached = true;
|
1491 | if (this.needsApply) {
|
1492 | this.needsApply = false;
|
1493 | this._apply();
|
1494 | }
|
1495 | this.element.addEventListener('focus', this);
|
1496 | this.element.addEventListener('blur', this);
|
1497 | };
|
1498 | Focus.prototype.detached = function () {
|
1499 | this.isAttached = false;
|
1500 | this.element.removeEventListener('focus', this);
|
1501 | this.element.removeEventListener('blur', this);
|
1502 | };
|
1503 | Focus.prototype.handleEvent = function (e) {
|
1504 | if (e.type === 'focus') {
|
1505 | this.value = true;
|
1506 | }
|
1507 | else if (DOM.activeElement !== this.element) {
|
1508 | this.value = false;
|
1509 | }
|
1510 | };
|
1511 | Focus = __decorate([
|
1512 | customAttribute('focus', bindingMode.twoWay)
|
1513 | ], Focus);
|
1514 | return Focus;
|
1515 | }()));
|
1516 |
|
1517 | var cssUrlMatcher = /url\((?!['"]data)([^)]+)\)/gi;
|
1518 | function fixupCSSUrls(address, css) {
|
1519 | if (typeof css !== 'string') {
|
1520 | throw new Error("Failed loading required CSS file: ".concat(address));
|
1521 | }
|
1522 | return css.replace(cssUrlMatcher, function (match, p1) {
|
1523 | var quote = p1.charAt(0);
|
1524 | if (quote === '\'' || quote === '"') {
|
1525 | p1 = p1.substr(1, p1.length - 2);
|
1526 | }
|
1527 | return 'url(\'' + relativeToFile(p1, address) + '\')';
|
1528 | });
|
1529 | }
|
1530 | var CSSResource = (function () {
|
1531 | function CSSResource(address) {
|
1532 | this.address = address;
|
1533 | this._scoped = null;
|
1534 | this._global = false;
|
1535 | this._alreadyGloballyInjected = false;
|
1536 | }
|
1537 | CSSResource.prototype.initialize = function (container, Target) {
|
1538 | this._scoped = new Target(this);
|
1539 | };
|
1540 | CSSResource.prototype.register = function (registry, name) {
|
1541 | if (name === 'scoped') {
|
1542 | registry.registerViewEngineHooks(this._scoped);
|
1543 | }
|
1544 | else {
|
1545 | this._global = true;
|
1546 | }
|
1547 | };
|
1548 | CSSResource.prototype.load = function (container) {
|
1549 | var _this = this;
|
1550 | return container.get(Loader)
|
1551 | .loadText(this.address)
|
1552 | .catch(function () { return null; })
|
1553 | .then(function (text) {
|
1554 | text = fixupCSSUrls(_this.address, text);
|
1555 | _this._scoped.css = text;
|
1556 | if (_this._global) {
|
1557 | _this._alreadyGloballyInjected = true;
|
1558 | DOM.injectStyles(text);
|
1559 | }
|
1560 | return _this;
|
1561 | });
|
1562 | };
|
1563 | return CSSResource;
|
1564 | }());
|
1565 | var CSSViewEngineHooks = (function () {
|
1566 | function CSSViewEngineHooks(owner) {
|
1567 | this.owner = owner;
|
1568 | this.css = null;
|
1569 | }
|
1570 | CSSViewEngineHooks.prototype.beforeCompile = function (content, resources, instruction) {
|
1571 | if (instruction.targetShadowDOM) {
|
1572 | DOM.injectStyles(this.css, content, true);
|
1573 | }
|
1574 | else if (FEATURE.scopedCSS) {
|
1575 | var styleNode = DOM.injectStyles(this.css, content, true);
|
1576 | styleNode.setAttribute('scoped', 'scoped');
|
1577 | }
|
1578 | else if (this._global && !this.owner._alreadyGloballyInjected) {
|
1579 | DOM.injectStyles(this.css);
|
1580 | this.owner._alreadyGloballyInjected = true;
|
1581 | }
|
1582 | };
|
1583 | return CSSViewEngineHooks;
|
1584 | }());
|
1585 | function _createCSSResource(address) {
|
1586 | var ViewCSS = (function (_super) {
|
1587 | __extends(ViewCSS, _super);
|
1588 | function ViewCSS() {
|
1589 | return _super !== null && _super.apply(this, arguments) || this;
|
1590 | }
|
1591 | ViewCSS = __decorate([
|
1592 | resource(new CSSResource(address))
|
1593 | ], ViewCSS);
|
1594 | return ViewCSS;
|
1595 | }(CSSViewEngineHooks));
|
1596 | return ViewCSS;
|
1597 | }
|
1598 |
|
1599 | var AttrBindingBehavior = exports('AttrBindingBehavior', (function () {
|
1600 | function AttrBindingBehavior() {
|
1601 | }
|
1602 | AttrBindingBehavior.prototype.bind = function (binding, source) {
|
1603 | binding.targetObserver = new DataAttributeObserver(binding.target, binding.targetProperty);
|
1604 | };
|
1605 | AttrBindingBehavior.prototype.unbind = function (binding, source) {
|
1606 | };
|
1607 | AttrBindingBehavior = __decorate([
|
1608 | bindingBehavior('attr')
|
1609 | ], AttrBindingBehavior);
|
1610 | return AttrBindingBehavior;
|
1611 | }()));
|
1612 |
|
1613 | var modeBindingBehavior = {
|
1614 | bind: function (binding, source, lookupFunctions) {
|
1615 | binding.originalMode = binding.mode;
|
1616 | binding.mode = this.mode;
|
1617 | },
|
1618 | unbind: function (binding, source) {
|
1619 | binding.mode = binding.originalMode;
|
1620 | binding.originalMode = null;
|
1621 | }
|
1622 | };
|
1623 | var OneTimeBindingBehavior = exports('OneTimeBindingBehavior', (function () {
|
1624 | function OneTimeBindingBehavior() {
|
1625 | this.mode = bindingMode.oneTime;
|
1626 | }
|
1627 | OneTimeBindingBehavior = __decorate([
|
1628 | mixin(modeBindingBehavior),
|
1629 | bindingBehavior('oneTime')
|
1630 | ], OneTimeBindingBehavior);
|
1631 | return OneTimeBindingBehavior;
|
1632 | }()));
|
1633 | var OneWayBindingBehavior = exports('OneWayBindingBehavior', (function () {
|
1634 | function OneWayBindingBehavior() {
|
1635 | this.mode = bindingMode.toView;
|
1636 | }
|
1637 | OneWayBindingBehavior = __decorate([
|
1638 | mixin(modeBindingBehavior),
|
1639 | bindingBehavior('oneWay')
|
1640 | ], OneWayBindingBehavior);
|
1641 | return OneWayBindingBehavior;
|
1642 | }()));
|
1643 | var ToViewBindingBehavior = exports('ToViewBindingBehavior', (function () {
|
1644 | function ToViewBindingBehavior() {
|
1645 | this.mode = bindingMode.toView;
|
1646 | }
|
1647 | ToViewBindingBehavior = __decorate([
|
1648 | mixin(modeBindingBehavior),
|
1649 | bindingBehavior('toView')
|
1650 | ], ToViewBindingBehavior);
|
1651 | return ToViewBindingBehavior;
|
1652 | }()));
|
1653 | var FromViewBindingBehavior = exports('FromViewBindingBehavior', (function () {
|
1654 | function FromViewBindingBehavior() {
|
1655 | this.mode = bindingMode.fromView;
|
1656 | }
|
1657 | FromViewBindingBehavior = __decorate([
|
1658 | mixin(modeBindingBehavior),
|
1659 | bindingBehavior('fromView')
|
1660 | ], FromViewBindingBehavior);
|
1661 | return FromViewBindingBehavior;
|
1662 | }()));
|
1663 | var TwoWayBindingBehavior = exports('TwoWayBindingBehavior', (function () {
|
1664 | function TwoWayBindingBehavior() {
|
1665 | this.mode = bindingMode.twoWay;
|
1666 | }
|
1667 | TwoWayBindingBehavior = __decorate([
|
1668 | mixin(modeBindingBehavior),
|
1669 | bindingBehavior('twoWay')
|
1670 | ], TwoWayBindingBehavior);
|
1671 | return TwoWayBindingBehavior;
|
1672 | }()));
|
1673 |
|
1674 | function throttle(newValue) {
|
1675 | var _this = this;
|
1676 | var state = this.throttleState;
|
1677 | var elapsed = +new Date() - state.last;
|
1678 | if (elapsed >= state.delay) {
|
1679 | clearTimeout(state.timeoutId);
|
1680 | state.timeoutId = null;
|
1681 | state.last = +new Date();
|
1682 | this.throttledMethod(newValue);
|
1683 | return;
|
1684 | }
|
1685 | state.newValue = newValue;
|
1686 | if (state.timeoutId === null) {
|
1687 | state.timeoutId = setTimeout(function () {
|
1688 | state.timeoutId = null;
|
1689 | state.last = +new Date();
|
1690 | _this.throttledMethod(state.newValue);
|
1691 | }, state.delay - elapsed);
|
1692 | }
|
1693 | }
|
1694 | var ThrottleBindingBehavior = exports('ThrottleBindingBehavior', (function () {
|
1695 | function ThrottleBindingBehavior() {
|
1696 | }
|
1697 | ThrottleBindingBehavior.prototype.bind = function (binding, source, delay) {
|
1698 | if (delay === void 0) { delay = 200; }
|
1699 | var methodToThrottle = 'updateTarget';
|
1700 | if (binding.callSource) {
|
1701 | methodToThrottle = 'callSource';
|
1702 | }
|
1703 | else if (binding.updateSource && binding.mode === bindingMode.twoWay) {
|
1704 | methodToThrottle = 'updateSource';
|
1705 | }
|
1706 | binding.throttledMethod = binding[methodToThrottle];
|
1707 | binding.throttledMethod.originalName = methodToThrottle;
|
1708 | binding[methodToThrottle] = throttle;
|
1709 | binding.throttleState = {
|
1710 | delay: delay,
|
1711 | last: 0,
|
1712 | timeoutId: null
|
1713 | };
|
1714 | };
|
1715 | ThrottleBindingBehavior.prototype.unbind = function (binding, source) {
|
1716 | var methodToRestore = binding.throttledMethod.originalName;
|
1717 | binding[methodToRestore] = binding.throttledMethod;
|
1718 | binding.throttledMethod = null;
|
1719 | clearTimeout(binding.throttleState.timeoutId);
|
1720 | binding.throttleState = null;
|
1721 | };
|
1722 | ThrottleBindingBehavior = __decorate([
|
1723 | bindingBehavior('throttle')
|
1724 | ], ThrottleBindingBehavior);
|
1725 | return ThrottleBindingBehavior;
|
1726 | }()));
|
1727 |
|
1728 | var unset = {};
|
1729 | function debounceCallSource(event) {
|
1730 | var _this = this;
|
1731 | var state = this.debounceState;
|
1732 | clearTimeout(state.timeoutId);
|
1733 | state.timeoutId = setTimeout(function () { return _this.debouncedMethod(event); }, state.delay);
|
1734 | }
|
1735 | function debounceCall(context, newValue, oldValue) {
|
1736 | var _this = this;
|
1737 | var state = this.debounceState;
|
1738 | clearTimeout(state.timeoutId);
|
1739 | if (context !== state.callContextToDebounce) {
|
1740 | state.oldValue = unset;
|
1741 | this.debouncedMethod(context, newValue, oldValue);
|
1742 | return;
|
1743 | }
|
1744 | if (state.oldValue === unset) {
|
1745 | state.oldValue = oldValue;
|
1746 | }
|
1747 | state.timeoutId = setTimeout(function () {
|
1748 | var _oldValue = state.oldValue;
|
1749 | state.oldValue = unset;
|
1750 | _this.debouncedMethod(context, newValue, _oldValue);
|
1751 | }, state.delay);
|
1752 | }
|
1753 | var DebounceBindingBehavior = exports('DebounceBindingBehavior', (function () {
|
1754 | function DebounceBindingBehavior() {
|
1755 | }
|
1756 | DebounceBindingBehavior.prototype.bind = function (binding, source, delay) {
|
1757 | if (delay === void 0) { delay = 200; }
|
1758 | var isCallSource = binding.callSource !== undefined;
|
1759 | var methodToDebounce = isCallSource ? 'callSource' : 'call';
|
1760 | var debouncer = isCallSource ? debounceCallSource : debounceCall;
|
1761 | var mode = binding.mode;
|
1762 | var callContextToDebounce = mode === bindingMode.twoWay || mode === bindingMode.fromView ? targetContext : sourceContext;
|
1763 | binding.debouncedMethod = binding[methodToDebounce];
|
1764 | binding.debouncedMethod.originalName = methodToDebounce;
|
1765 | binding[methodToDebounce] = debouncer;
|
1766 | binding.debounceState = {
|
1767 | callContextToDebounce: callContextToDebounce,
|
1768 | delay: delay,
|
1769 | timeoutId: 0,
|
1770 | oldValue: unset
|
1771 | };
|
1772 | };
|
1773 | DebounceBindingBehavior.prototype.unbind = function (binding, source) {
|
1774 | var methodToRestore = binding.debouncedMethod.originalName;
|
1775 | binding[methodToRestore] = binding.debouncedMethod;
|
1776 | binding.debouncedMethod = null;
|
1777 | clearTimeout(binding.debounceState.timeoutId);
|
1778 | binding.debounceState = null;
|
1779 | };
|
1780 | DebounceBindingBehavior = __decorate([
|
1781 | bindingBehavior('debounce')
|
1782 | ], DebounceBindingBehavior);
|
1783 | return DebounceBindingBehavior;
|
1784 | }()));
|
1785 |
|
1786 | function findOriginalEventTarget(event) {
|
1787 | return (event.path && event.path[0]) || (event.deepPath && event.deepPath[0]) || event.target;
|
1788 | }
|
1789 | function handleSelfEvent(event) {
|
1790 | var target = findOriginalEventTarget(event);
|
1791 | if (this.target !== target) {
|
1792 | return;
|
1793 | }
|
1794 | this.selfEventCallSource(event);
|
1795 | }
|
1796 | var SelfBindingBehavior = exports('SelfBindingBehavior', (function () {
|
1797 | function SelfBindingBehavior() {
|
1798 | }
|
1799 | SelfBindingBehavior.prototype.bind = function (binding, source) {
|
1800 | if (!binding.callSource || !binding.targetEvent) {
|
1801 | throw new Error('Self binding behavior only supports event.');
|
1802 | }
|
1803 | binding.selfEventCallSource = binding.callSource;
|
1804 | binding.callSource = handleSelfEvent;
|
1805 | };
|
1806 | SelfBindingBehavior.prototype.unbind = function (binding, source) {
|
1807 | binding.callSource = binding.selfEventCallSource;
|
1808 | binding.selfEventCallSource = null;
|
1809 | };
|
1810 | SelfBindingBehavior = __decorate([
|
1811 | bindingBehavior('self')
|
1812 | ], SelfBindingBehavior);
|
1813 | return SelfBindingBehavior;
|
1814 | }()));
|
1815 |
|
1816 | var BindingSignaler = exports('BindingSignaler', (function () {
|
1817 | function BindingSignaler() {
|
1818 | this.signals = {};
|
1819 | }
|
1820 | BindingSignaler.prototype.signal = function (name) {
|
1821 | var bindings = this.signals[name];
|
1822 | if (!bindings) {
|
1823 | return;
|
1824 | }
|
1825 | var i = bindings.length;
|
1826 | while (i--) {
|
1827 | bindings[i].call(sourceContext);
|
1828 | }
|
1829 | };
|
1830 | return BindingSignaler;
|
1831 | }()));
|
1832 |
|
1833 | var SignalBindingBehavior = exports('SignalBindingBehavior', (function () {
|
1834 | function SignalBindingBehavior(bindingSignaler) {
|
1835 | this.signals = bindingSignaler.signals;
|
1836 | }
|
1837 | SignalBindingBehavior.inject = function () { return [BindingSignaler]; };
|
1838 | SignalBindingBehavior.prototype.bind = function (binding, source) {
|
1839 | var names = [];
|
1840 | for (var _i = 2; _i < arguments.length; _i++) {
|
1841 | names[_i - 2] = arguments[_i];
|
1842 | }
|
1843 | if (!binding.updateTarget) {
|
1844 | throw new Error('Only property bindings and string interpolation bindings can be signaled. Trigger, delegate and call bindings cannot be signaled.');
|
1845 | }
|
1846 | var signals = this.signals;
|
1847 | if (names.length === 1) {
|
1848 | var name_1 = names[0];
|
1849 | var bindings = signals[name_1] || (signals[name_1] = []);
|
1850 | bindings.push(binding);
|
1851 | binding.signalName = name_1;
|
1852 | }
|
1853 | else if (names.length > 1) {
|
1854 | var i = names.length;
|
1855 | while (i--) {
|
1856 | var name_2 = names[i];
|
1857 | var bindings = signals[name_2] || (signals[name_2] = []);
|
1858 | bindings.push(binding);
|
1859 | }
|
1860 | binding.signalName = names;
|
1861 | }
|
1862 | else {
|
1863 | throw new Error('Signal name is required.');
|
1864 | }
|
1865 | };
|
1866 | SignalBindingBehavior.prototype.unbind = function (binding, source) {
|
1867 | var signals = this.signals;
|
1868 | var name = binding.signalName;
|
1869 | binding.signalName = null;
|
1870 | if (Array.isArray(name)) {
|
1871 | var names = name;
|
1872 | var i = names.length;
|
1873 | while (i--) {
|
1874 | var n = names[i];
|
1875 | var bindings = signals[n];
|
1876 | bindings.splice(bindings.indexOf(binding), 1);
|
1877 | }
|
1878 | }
|
1879 | else {
|
1880 | var bindings = signals[name];
|
1881 | bindings.splice(bindings.indexOf(binding), 1);
|
1882 | }
|
1883 | };
|
1884 | SignalBindingBehavior = __decorate([
|
1885 | bindingBehavior('signal')
|
1886 | ], SignalBindingBehavior);
|
1887 | return SignalBindingBehavior;
|
1888 | }()));
|
1889 |
|
1890 | var eventNamesRequired = 'The updateTrigger binding behavior requires at least one event name argument: eg <input value.bind="firstName & updateTrigger:\'blur\'">';
|
1891 | var notApplicableMessage = 'The updateTrigger binding behavior can only be applied to two-way/ from-view bindings on input/select elements.';
|
1892 | var UpdateTriggerBindingBehavior = exports('UpdateTriggerBindingBehavior', (function () {
|
1893 | function UpdateTriggerBindingBehavior() {
|
1894 | }
|
1895 | UpdateTriggerBindingBehavior.prototype.bind = function (binding, source) {
|
1896 | var events = [];
|
1897 | for (var _i = 2; _i < arguments.length; _i++) {
|
1898 | events[_i - 2] = arguments[_i];
|
1899 | }
|
1900 | if (events.length === 0) {
|
1901 | throw new Error(eventNamesRequired);
|
1902 | }
|
1903 | if (binding.mode !== bindingMode.twoWay && binding.mode !== bindingMode.fromView) {
|
1904 | throw new Error(notApplicableMessage);
|
1905 | }
|
1906 | var targetObserver = binding.observerLocator.getObserver(binding.target, binding.targetProperty);
|
1907 | if (!targetObserver.handler) {
|
1908 | throw new Error(notApplicableMessage);
|
1909 | }
|
1910 | binding.targetObserver = targetObserver;
|
1911 | targetObserver.originalHandler = binding.targetObserver.handler;
|
1912 | var handler = new EventSubscriber(events);
|
1913 | targetObserver.handler = handler;
|
1914 | };
|
1915 | UpdateTriggerBindingBehavior.prototype.unbind = function (binding, source) {
|
1916 | var targetObserver = binding.targetObserver;
|
1917 | targetObserver.handler.dispose();
|
1918 | targetObserver.handler = targetObserver.originalHandler;
|
1919 | targetObserver.originalHandler = null;
|
1920 | };
|
1921 | UpdateTriggerBindingBehavior = __decorate([
|
1922 | bindingBehavior('updateTrigger')
|
1923 | ], UpdateTriggerBindingBehavior);
|
1924 | return UpdateTriggerBindingBehavior;
|
1925 | }()));
|
1926 |
|
1927 | function _createDynamicElement(_a) {
|
1928 | var name = _a.name, viewUrl = _a.viewUrl, bindableNames = _a.bindableNames, useShadowDOMmode = _a.useShadowDOMmode;
|
1929 | var DynamicElement = (function () {
|
1930 | function DynamicElement() {
|
1931 | }
|
1932 | DynamicElement.prototype.bind = function (bindingContext) {
|
1933 | this.$parent = bindingContext;
|
1934 | };
|
1935 | DynamicElement = __decorate([
|
1936 | customElement(name),
|
1937 | useView(viewUrl)
|
1938 | ], DynamicElement);
|
1939 | return DynamicElement;
|
1940 | }());
|
1941 | for (var i = 0, ii = bindableNames.length; i < ii; ++i) {
|
1942 | bindable(bindableNames[i])(DynamicElement);
|
1943 | }
|
1944 | switch (useShadowDOMmode) {
|
1945 | case 'open':
|
1946 | useShadowDOM({ mode: 'open' })(DynamicElement);
|
1947 | break;
|
1948 | case 'closed':
|
1949 | useShadowDOM({ mode: 'closed' })(DynamicElement);
|
1950 | break;
|
1951 | case '':
|
1952 | useShadowDOM(DynamicElement);
|
1953 | break;
|
1954 | case null:
|
1955 | break;
|
1956 | default:
|
1957 | getLogger('aurelia-html-only-element')
|
1958 | .warn("Expected 'use-shadow-dom' value to be \"close\", \"open\" or \"\", received ".concat(useShadowDOMmode));
|
1959 | break;
|
1960 | }
|
1961 | return DynamicElement;
|
1962 | }
|
1963 |
|
1964 | function getElementName(address) {
|
1965 | return /([^\/^\?]+)\.html/i.exec(address)[1].toLowerCase();
|
1966 | }
|
1967 | function configure$1(config) {
|
1968 | var viewEngine = config.container.get(ViewEngine);
|
1969 | var loader = config.aurelia.loader;
|
1970 | viewEngine.addResourcePlugin('.html', {
|
1971 | 'fetch': function (viewUrl) {
|
1972 | return loader.loadTemplate(viewUrl).then(function (registryEntry) {
|
1973 | var _a;
|
1974 | var bindableNames = registryEntry.template.getAttribute('bindable');
|
1975 | var useShadowDOMmode = registryEntry.template.getAttribute('use-shadow-dom');
|
1976 | var name = getElementName(viewUrl);
|
1977 | if (bindableNames) {
|
1978 | bindableNames = bindableNames.split(',').map(function (x) { return x.trim(); });
|
1979 | registryEntry.template.removeAttribute('bindable');
|
1980 | }
|
1981 | else {
|
1982 | bindableNames = [];
|
1983 | }
|
1984 | return _a = {}, _a[name] = _createDynamicElement({ name: name, viewUrl: viewUrl, bindableNames: bindableNames, useShadowDOMmode: useShadowDOMmode }), _a;
|
1985 | });
|
1986 | }
|
1987 | });
|
1988 | }
|
1989 |
|
1990 | function configure(config) {
|
1991 | injectAureliaHideStyleAtHead();
|
1992 | config.globalResources(Compose, If, Else, With, Repeat, Show, Hide, Replaceable, Focus, SanitizeHTMLValueConverter, OneTimeBindingBehavior, OneWayBindingBehavior, ToViewBindingBehavior, FromViewBindingBehavior, TwoWayBindingBehavior, ThrottleBindingBehavior, DebounceBindingBehavior, SelfBindingBehavior, SignalBindingBehavior, UpdateTriggerBindingBehavior, AttrBindingBehavior);
|
1993 | configure$1(config);
|
1994 | var viewEngine = config.container.get(ViewEngine);
|
1995 | var styleResourcePlugin = {
|
1996 | fetch: function (address) {
|
1997 | var _a;
|
1998 | return _a = {}, _a[address] = _createCSSResource(address), _a;
|
1999 | }
|
2000 | };
|
2001 | ['.css', '.less', '.sass', '.scss', '.styl'].forEach(function (ext) { return viewEngine.addResourcePlugin(ext, styleResourcePlugin); });
|
2002 | }
|
2003 |
|
2004 | })
|
2005 | };
|
2006 | }));
|
2007 |
|