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