1 | var __extends = (this && this.__extends) || (function () {
|
2 | var extendStatics = Object.setPrototypeOf ||
|
3 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
4 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
5 | return function (d, b) {
|
6 | extendStatics(d, b);
|
7 | function __() { this.constructor = d; }
|
8 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
9 | };
|
10 | })();
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectorRef, Component, ComponentFactoryResolver, Directive, EventEmitter, Injectable, Injector, Input, NgModule, NgModuleFactory, Output, Type, ViewContainerRef } from '@angular/core';
|
17 | import { ActivatedRoute, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router, RouterModule } from '@angular/router';
|
18 | import { assign, camelCase, clone, defaults, differenceWith, each, filter, find, isArray, isEmpty, isEqual, isNil, keys, merge, reject, uniqWith } from 'lodash';
|
19 | import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
20 | import { ReplaySubject, Subject } from 'rxjs';
|
21 | import { ReplaySubject as ReplaySubject$1 } from 'rxjs/Rx';
|
22 | import { CommonModule } from '@angular/common';
|
23 | import { FormsModule } from '@angular/forms';
|
24 | import { BrowserModule } from '@angular/platform-browser';
|
25 | var Component$1 = (function () {
|
26 | function Component$1(controller, injector) {
|
27 | var _this = this;
|
28 | this.controller = controller;
|
29 | this.changeDetectorRef = injector.get(ChangeDetectorRef);
|
30 | this.subscriptions = [];
|
31 | this.subscriptions.push(controller.model$.subscribe(function (model) { return _this.updateModel(model); }), controller.view$.subscribe(function (view) { return _this.updateView(view); }), controller.markForCheck$.subscribe(function () { return _this.changeDetectorRef.markForCheck(); }));
|
32 | this.controller.attach();
|
33 | }
|
34 | Component$1.prototype.ngOnInit = function () {
|
35 | };
|
36 | Component$1.prototype.ngOnDestroy = function () {
|
37 | this.controller.detach();
|
38 | this.subscriptions.forEach(function (s) { return s.unsubscribe(); });
|
39 | this.subscriptions = null;
|
40 | this.changeDetectorRef = null;
|
41 | this.controller = null;
|
42 | this.model = null;
|
43 | this.view = null;
|
44 | };
|
45 | Component$1.prototype.updateModel = function (model) {
|
46 | this.model = model;
|
47 | this.changeDetectorRef.markForCheck();
|
48 | };
|
49 | Component$1.prototype.updateView = function (view) {
|
50 | this.view = view;
|
51 | this.changeDetectorRef.markForCheck();
|
52 | };
|
53 | return Component$1;
|
54 | }());
|
55 | var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
56 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
57 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
58 | r = Reflect.decorate(decorators, target, key, desc);
|
59 | else
|
60 | for (var i = decorators.length - 1; i >= 0; i--)
|
61 | if (d = decorators[i])
|
62 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
63 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
64 | };
|
65 |
|
66 | var Controller = (function () {
|
67 |
|
68 | function Controller() {
|
69 |
|
70 |
|
71 |
|
72 | this._refCount = 0;
|
73 | }
|
74 | Object.defineProperty(Controller.prototype, "model$", {
|
75 |
|
76 |
|
77 |
|
78 | |
79 |
|
80 |
|
81 | get: function () { return this._model$; },
|
82 | enumerable: true,
|
83 | configurable: true
|
84 | });
|
85 | Object.defineProperty(Controller.prototype, "model", {
|
86 | |
87 |
|
88 |
|
89 | get: function () { return this._model; },
|
90 | enumerable: true,
|
91 | configurable: true
|
92 | });
|
93 | Object.defineProperty(Controller.prototype, "view$", {
|
94 | |
95 |
|
96 |
|
97 | get: function () { return this._view$; },
|
98 | enumerable: true,
|
99 | configurable: true
|
100 | });
|
101 | Object.defineProperty(Controller.prototype, "view", {
|
102 | |
103 |
|
104 |
|
105 | get: function () { return this._view; },
|
106 | enumerable: true,
|
107 | configurable: true
|
108 | });
|
109 | Object.defineProperty(Controller.prototype, "markForCheck$", {
|
110 | |
111 |
|
112 |
|
113 | get: function () { return this._markForCheck$; },
|
114 | enumerable: true,
|
115 | configurable: true
|
116 | });
|
117 | Object.defineProperty(Controller.prototype, "frame", {
|
118 | |
119 |
|
120 |
|
121 | get: function () { return this._frame; },
|
122 | enumerable: true,
|
123 | configurable: true
|
124 | });
|
125 | Object.defineProperty(Controller.prototype, "injector", {
|
126 | |
127 |
|
128 |
|
129 | get: function () { return this._injector; },
|
130 | enumerable: true,
|
131 | configurable: true
|
132 | });
|
133 | |
134 |
|
135 |
|
136 | Controller.prototype.onControllerInit = function () { };
|
137 | |
138 |
|
139 |
|
140 | Controller.prototype.onResolveStart = function () { };
|
141 | |
142 |
|
143 |
|
144 | Controller.prototype.onResolveEnd = function () { };
|
145 | |
146 |
|
147 |
|
148 | Controller.prototype.onResolveCancel = function () { };
|
149 | |
150 |
|
151 |
|
152 | Controller.prototype.initController = function (model, view, frame, framerName, injector) {
|
153 | var _this = this;
|
154 | this._modelSubject = new BehaviorSubject(model);
|
155 | this._viewSubject = new BehaviorSubject(view);
|
156 | this._model$ = this._modelSubject.asObservable();
|
157 | this._view$ = this._viewSubject.asObservable();
|
158 | this._model = model;
|
159 | this._view = view;
|
160 | this._markForCheckSubject = new BehaviorSubject(true);
|
161 | this._markForCheck$ = this._markForCheckSubject.asObservable();
|
162 | this._frame = frame;
|
163 | this._injector = injector;
|
164 | this._framerName = framerName;
|
165 | if (this._frame) {
|
166 | this._frame.resolveStart$.subscribe(function () { _this.onResolveStart(); });
|
167 | this._frame.resolveEnd$.subscribe(function () { _this.onResolveEnd(); });
|
168 | this._frame.resolveCancel$.subscribe(function () { _this.onResolveCancel(); });
|
169 | }
|
170 | this.onControllerInit();
|
171 | console.log('initController');
|
172 | console.log(this);
|
173 | };
|
174 | Controller.prototype.updateModel = function (model, replace) {
|
175 | if (replace === void 0) { replace = false; }
|
176 | if (replace) {
|
177 | this._model = clone(model);
|
178 | }
|
179 | else {
|
180 | this._model = assign({}, this._model, model);
|
181 | }
|
182 | this._modelSubject.next(this._model);
|
183 | };
|
184 | Controller.prototype.updateView = function (view, replace) {
|
185 | if (replace === void 0) { replace = false; }
|
186 | if (replace) {
|
187 | this._view = clone(view);
|
188 | }
|
189 | else {
|
190 | this._view = assign({}, this._view, view);
|
191 | }
|
192 | this._viewSubject.next(this._view);
|
193 | };
|
194 | Controller.prototype.markForCheck = function () {
|
195 | this._markForCheckSubject.next(true);
|
196 | };
|
197 | Controller.prototype.attach = function () {
|
198 | var _this = this;
|
199 | this._refCount++;
|
200 | if (this._refCount === 1) {
|
201 | setTimeout(function () {
|
202 | _this.onAttached();
|
203 | });
|
204 | }
|
205 | };
|
206 | Controller.prototype.detach = function () {
|
207 | var _this = this;
|
208 | this._refCount--;
|
209 | if (this._refCount === 0) {
|
210 | setTimeout(function () {
|
211 | _this.onDetached();
|
212 | });
|
213 | }
|
214 | };
|
215 | Controller.prototype.onAttached = function () { };
|
216 | Controller.prototype.onDetached = function () { };
|
217 | return Controller;
|
218 | }());
|
219 | Controller = __decorate$2([
|
220 | Injectable()
|
221 | ], Controller);
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | var FramingTools = (function () {
|
232 | function FramingTools() {
|
233 | this.instantiatedControllers = {};
|
234 | }
|
235 | Object.defineProperty(FramingTools, "Instance", {
|
236 | get: function () {
|
237 | return this._instance || (this._instance = new this());
|
238 | },
|
239 | enumerable: true,
|
240 | configurable: true
|
241 | });
|
242 | FramingTools.prototype.addController = function (framerName, controller) {
|
243 | this.instantiatedControllers[framerName] = controller;
|
244 | };
|
245 | FramingTools.prototype.getAllControllers = function () {
|
246 | return this.instantiatedControllers;
|
247 | };
|
248 | FramingTools.prototype.getControllerByKey = function (key) {
|
249 | return this.instantiatedControllers[key] ? this.instantiatedControllers[key] : null;
|
250 | };
|
251 | return FramingTools;
|
252 | }());
|
253 | var framingTools = FramingTools.Instance;
|
254 | var stateRoot = {};
|
255 | var onLoad = true;
|
256 |
|
257 | var devTools = _createReduxDevtoolsExtension();
|
258 | var isListening = false;
|
259 |
|
260 | function Action(description, log) {
|
261 | if (description === void 0) { description = null; }
|
262 | if (log === void 0) { log = true; }
|
263 | return function (target, propertyKey, descriptor) {
|
264 | if (descriptor === undefined) {
|
265 | descriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
|
266 | }
|
267 | var originalMethod = descriptor.value;
|
268 | descriptor.value = function () {
|
269 | var args = [];
|
270 | var controller = this;
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | for (var _i = 0; _i < arguments.length; _i++) {
|
279 | args[_i] = arguments[_i];
|
280 | }
|
281 | try {
|
282 | listenForChanges();
|
283 | }
|
284 | catch (e) {
|
285 | console.log('Listen to Devtools failed: ');
|
286 | console.log(e);
|
287 | }
|
288 |
|
289 | if (onLoad && log && devTools) {
|
290 | onLoad = !onLoad;
|
291 | stateRoot[controller._framerName] = controller.model;
|
292 | var state = {
|
293 | framerName: controller._framerName,
|
294 | value: stateRoot,
|
295 | };
|
296 | try {
|
297 | devTools.send((description || propertyKey), state);
|
298 | }
|
299 | catch (e) {
|
300 | console.log('Send to Devtools failed: ');
|
301 | console.log(e);
|
302 | }
|
303 | }
|
304 | originalMethod.apply(controller, args);
|
305 |
|
306 | if (log && devTools) {
|
307 | stateRoot[controller._framerName] = controller.model;
|
308 | var state = {
|
309 | framerName: controller._framerName,
|
310 |
|
311 | value: stateRoot,
|
312 | };
|
313 | try {
|
314 | devTools.send((description || propertyKey), state);
|
315 | }
|
316 | catch (e) {
|
317 | console.log('Send to Devtools failed: ');
|
318 | console.log(e);
|
319 | }
|
320 | }
|
321 | controller.markForCheck();
|
322 | };
|
323 | return descriptor;
|
324 | };
|
325 | }
|
326 |
|
327 |
|
328 |
|
329 |
|
330 | function listenForChanges() {
|
331 | if (isListening || !devTools)
|
332 | return;
|
333 | isListening = true;
|
334 | var connection = devTools.connect();
|
335 | connection.subscribe(function (message) {
|
336 | if (!!message.state) {
|
337 | var messageState = JSON.parse(message.state);
|
338 | var messageController = framingTools.getControllerByKey(messageState.framerName);
|
339 | if (messageController) {
|
340 | for (var prop in messageController.model) {
|
341 | messageController.model[prop] = messageState.value[messageState.framerName][prop];
|
342 | }
|
343 | messageController.markForCheck();
|
344 | }
|
345 | }
|
346 | });
|
347 | }
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | function _createReduxDevtoolsExtension() {
|
355 | var legacyExtensionKey = 'devToolsExtension';
|
356 | var extensionKey = '__REDUX_DEVTOOLS_EXTENSION__';
|
357 | if (typeof window === 'object' && typeof window[legacyExtensionKey] !== 'undefined') {
|
358 | return window[legacyExtensionKey];
|
359 | }
|
360 | else if (typeof window === 'object' && typeof window[extensionKey] !== 'undefined') {
|
361 | return window[extensionKey];
|
362 | }
|
363 | else {
|
364 | return null;
|
365 | }
|
366 | }
|
367 | var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
368 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
369 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
370 | r = Reflect.decorate(decorators, target, key, desc);
|
371 | else
|
372 | for (var i = decorators.length - 1; i >= 0; i--)
|
373 | if (d = decorators[i])
|
374 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
375 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
376 | };
|
377 | var __metadata$1 = (undefined && undefined.__metadata) || function (k, v) {
|
378 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
379 | return Reflect.metadata(k, v);
|
380 | };
|
381 | var FramingDevToolsController = (function (_super) {
|
382 | __extends(FramingDevToolsController, _super);
|
383 | function FramingDevToolsController(router) {
|
384 | var _this = _super.call(this) || this;
|
385 | _this.router = router;
|
386 | _this.replayNavigation = false;
|
387 | return _this;
|
388 | }
|
389 | FramingDevToolsController.prototype.onControllerInit = function () {
|
390 | var _this = this;
|
391 | this.router.events.subscribe(function (event) {
|
392 | _this.handleRouterEvents(event);
|
393 | });
|
394 | this.markForCheck$.subscribe(function (data) {
|
395 | if (_this.model.snapshotUrl && _this.model.snapshotUrl !== _this.router.routerState.snapshot.url) {
|
396 | _this.replayNavigation = true;
|
397 | _this.router.navigate([_this.model.snapshotUrl]);
|
398 | }
|
399 | }, function (err) { return console.error(err); });
|
400 | };
|
401 | FramingDevToolsController.prototype.trackRouterState = function () {
|
402 | this.model.snapshotUrl = this.router.routerState.snapshot.url;
|
403 | };
|
404 | FramingDevToolsController.prototype.handleRouterEvents = function (event) {
|
405 | if (event instanceof NavigationEnd) {
|
406 | if (!this.replayNavigation) {
|
407 | this.trackRouterState();
|
408 | }
|
409 | this.replayNavigation = false;
|
410 | }
|
411 | };
|
412 | return FramingDevToolsController;
|
413 | }(Controller));
|
414 | __decorate$1([
|
415 | Action(),
|
416 | __metadata$1("design:type", Function),
|
417 | __metadata$1("design:paramtypes", []),
|
418 | __metadata$1("design:returntype", void 0)
|
419 | ], FramingDevToolsController.prototype, "trackRouterState", null);
|
420 | FramingDevToolsController = __decorate$1([
|
421 | Injectable(),
|
422 | __metadata$1("design:paramtypes", [Router])
|
423 | ], FramingDevToolsController);
|
424 | var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
425 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
426 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
427 | r = Reflect.decorate(decorators, target, key, desc);
|
428 | else
|
429 | for (var i = decorators.length - 1; i >= 0; i--)
|
430 | if (d = decorators[i])
|
431 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
432 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
433 | };
|
434 | var __metadata = (undefined && undefined.__metadata) || function (k, v) {
|
435 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
436 | return Reflect.metadata(k, v);
|
437 | };
|
438 | var FramingDevToolsComponent = (function (_super) {
|
439 | __extends(FramingDevToolsComponent, _super);
|
440 | function FramingDevToolsComponent(controller, injector) {
|
441 | return _super.call(this, controller, injector) || this;
|
442 | }
|
443 | return FramingDevToolsComponent;
|
444 | }(Component$1));
|
445 | FramingDevToolsComponent = __decorate([
|
446 | Component({}),
|
447 | __metadata("design:paramtypes", [FramingDevToolsController, Injector])
|
448 | ], FramingDevToolsComponent);
|
449 | var Frame = (function () {
|
450 | function Frame() {
|
451 |
|
452 |
|
453 |
|
454 | |
455 |
|
456 |
|
457 | this.routeUrlSubject = new ReplaySubject();
|
458 | this.resolveStartSubject = new Subject();
|
459 | this.resolveEndSubject = new Subject();
|
460 | this.resolveCancelSubject = new Subject();
|
461 | }
|
462 | Object.defineProperty(Frame.prototype, "routeUrl$", {
|
463 | |
464 |
|
465 |
|
466 | get: function () { return this.routeUrlSubject; },
|
467 | enumerable: true,
|
468 | configurable: true
|
469 | });
|
470 | Object.defineProperty(Frame.prototype, "resolveStart$", {
|
471 | |
472 |
|
473 |
|
474 | get: function () { return this.resolveStartSubject; },
|
475 | enumerable: true,
|
476 | configurable: true
|
477 | });
|
478 | Object.defineProperty(Frame.prototype, "resolveEnd$", {
|
479 | |
480 |
|
481 |
|
482 | get: function () { return this.resolveEndSubject; },
|
483 | enumerable: true,
|
484 | configurable: true
|
485 | });
|
486 | Object.defineProperty(Frame.prototype, "resolveCancel$", {
|
487 | |
488 |
|
489 |
|
490 | get: function () { return this.resolveCancelSubject; },
|
491 | enumerable: true,
|
492 | configurable: true
|
493 | });
|
494 | return Frame;
|
495 | }());
|
496 |
|
497 |
|
498 |
|
499 | var Framer = (function () {
|
500 |
|
501 |
|
502 |
|
503 | |
504 |
|
505 |
|
506 | function Framer(model, view, controller) {
|
507 | this.framingDevTools = FramingTools.Instance;
|
508 | |
509 |
|
510 |
|
511 | this._framed = false;
|
512 | this.construct(model, view, controller);
|
513 | }
|
514 | Object.defineProperty(Framer.prototype, "theModel", {
|
515 | |
516 |
|
517 |
|
518 | get: function () { return this._model; },
|
519 | enumerable: true,
|
520 | configurable: true
|
521 | });
|
522 | Object.defineProperty(Framer.prototype, "theView", {
|
523 | |
524 |
|
525 |
|
526 | get: function () { return this._view; },
|
527 | enumerable: true,
|
528 | configurable: true
|
529 | });
|
530 | Object.defineProperty(Framer.prototype, "theController", {
|
531 | |
532 |
|
533 |
|
534 | get: function () { return this._controller; },
|
535 | enumerable: true,
|
536 | configurable: true
|
537 | });
|
538 | Object.defineProperty(Framer.prototype, "createFrame", {
|
539 | |
540 |
|
541 |
|
542 | get: function () { return true; },
|
543 | enumerable: true,
|
544 | configurable: true
|
545 | });
|
546 | Object.defineProperty(Framer.prototype, "multiFramer", {
|
547 | |
548 |
|
549 |
|
550 | get: function () { return false; },
|
551 | enumerable: true,
|
552 | configurable: true
|
553 | });
|
554 | Object.defineProperty(Framer.prototype, "provideControllerByType", {
|
555 | |
556 |
|
557 |
|
558 | get: function () { return true; },
|
559 | enumerable: true,
|
560 | configurable: true
|
561 | });
|
562 | Object.defineProperty(Framer.prototype, "addModelToRouteData", {
|
563 | |
564 |
|
565 |
|
566 | get: function () { return false; },
|
567 | enumerable: true,
|
568 | configurable: true
|
569 | });
|
570 | Object.defineProperty(Framer.prototype, "addViewToRouteData", {
|
571 | |
572 |
|
573 |
|
574 | get: function () { return false; },
|
575 | enumerable: true,
|
576 | configurable: true
|
577 | });
|
578 | Object.defineProperty(Framer.prototype, "addFrameToRouteData", {
|
579 | |
580 |
|
581 |
|
582 | get: function () { return false; },
|
583 | enumerable: true,
|
584 | configurable: true
|
585 | });
|
586 | Object.defineProperty(Framer.prototype, "defaultModel", {
|
587 | |
588 |
|
589 |
|
590 | get: function () { return undefined; },
|
591 | enumerable: true,
|
592 | configurable: true
|
593 | });
|
594 | Object.defineProperty(Framer.prototype, "defaultView", {
|
595 | |
596 |
|
597 |
|
598 | get: function () { return undefined; },
|
599 | enumerable: true,
|
600 | configurable: true
|
601 | });
|
602 | Object.defineProperty(Framer.prototype, "defaultController", {
|
603 | |
604 |
|
605 |
|
606 | get: function () { return undefined; },
|
607 | enumerable: true,
|
608 | configurable: true
|
609 | });
|
610 | Object.defineProperty(Framer.prototype, "routeRule", {
|
611 | |
612 |
|
613 |
|
614 |
|
615 |
|
616 | get: function () { return 'require'; },
|
617 | enumerable: true,
|
618 | configurable: true
|
619 | });
|
620 | Object.defineProperty(Framer.prototype, "framerId", {
|
621 | |
622 |
|
623 |
|
624 | get: function () { return this._framerId; },
|
625 | enumerable: true,
|
626 | configurable: true
|
627 | });
|
628 | Object.defineProperty(Framer.prototype, "framerIdent", {
|
629 | |
630 |
|
631 |
|
632 | get: function () { return this.framerName + "Framer-" + this._framerId; },
|
633 | enumerable: true,
|
634 | configurable: true
|
635 | });
|
636 | Object.defineProperty(Framer.prototype, "framed", {
|
637 | |
638 |
|
639 |
|
640 | get: function () { return this._framed; },
|
641 | enumerable: true,
|
642 | configurable: true
|
643 | });
|
644 | Object.defineProperty(Framer.prototype, "injector", {
|
645 | |
646 |
|
647 |
|
648 | get: function () { return this._injector; },
|
649 | enumerable: true,
|
650 | configurable: true
|
651 | });
|
652 | Object.defineProperty(Framer.prototype, "route", {
|
653 | |
654 |
|
655 |
|
656 |
|
657 | get: function () { return this._route; },
|
658 | enumerable: true,
|
659 | configurable: true
|
660 | });
|
661 |
|
662 |
|
663 |
|
664 | |
665 |
|
666 |
|
667 | Framer.buildUrlLink = function (route) {
|
668 | if (!route) {
|
669 | return '/';
|
670 | }
|
671 | var urls = [];
|
672 |
|
673 | for (; route.parent; route = route.parent) {
|
674 |
|
675 | urls = urls.concat(route.url.reverse());
|
676 | }
|
677 | urls = urls.reverse();
|
678 | return '/' + urls.join('/');
|
679 | };
|
680 |
|
681 |
|
682 |
|
683 | |
684 |
|
685 |
|
686 | Framer.prototype.model = function (model) {
|
687 | merge(this._model, model);
|
688 | return this;
|
689 | };
|
690 | |
691 |
|
692 |
|
693 | Framer.prototype.view = function (view) {
|
694 | merge(this._view, view);
|
695 | return this;
|
696 | };
|
697 | |
698 |
|
699 |
|
700 | Framer.prototype.controller = function (controller) {
|
701 | if (controller) {
|
702 | this._controller = controller;
|
703 | }
|
704 | return this;
|
705 | };
|
706 | |
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 | Framer.prototype.framerOnResolveRoute = function () { };
|
713 | |
714 |
|
715 |
|
716 |
|
717 | Framer.prototype.framerOnControllerInit = function (controller) { };
|
718 | |
719 |
|
720 |
|
721 | Framer.prototype.runFraming = function (framing, routeParam) {
|
722 | var _this = this;
|
723 | if (this._framed) {
|
724 | console.warn("runFraming() called multiple times on framer '" + this.framerIdent + "'");
|
725 | return;
|
726 | }
|
727 | this._framed = true;
|
728 | if (this.routeRule === 'auto') {
|
729 |
|
730 | this._route = routeParam;
|
731 | }
|
732 | else if (this.routeRule === 'require') {
|
733 |
|
734 | if (routeParam) {
|
735 | this._route = routeParam;
|
736 | }
|
737 | else {
|
738 |
|
739 | this._route = routeParam = framing.getOrAddRoute();
|
740 |
|
741 | }
|
742 | }
|
743 | this._framing = framing;
|
744 | try {
|
745 | this.frame(framing);
|
746 | }
|
747 | catch (e) {
|
748 | console.error("Exception when framing " + this.framerIdent + " :", e);
|
749 | this._model = undefined;
|
750 | this._view = undefined;
|
751 | this._controller = undefined;
|
752 | }
|
753 | this._framing = undefined;
|
754 | if (this.routeRule === 'auto') {
|
755 | this._route = routeParam;
|
756 | }
|
757 | var self = this;
|
758 | if (this._controller) {
|
759 |
|
760 |
|
761 | var controllerInstance_1;
|
762 | framing
|
763 | .provide({
|
764 | provide: this.framerIdent + '-ControllerInternal',
|
765 | useClass: this._controller,
|
766 | })
|
767 | .provide({
|
768 | provide: this.framerIdent + '-Controller',
|
769 | useFactory: function (injector) {
|
770 | if (controllerInstance_1) {
|
771 | _this.framingDevTools.addController(_this.framerName, controllerInstance_1);
|
772 | return controllerInstance_1;
|
773 | }
|
774 | self._injector = injector;
|
775 | controllerInstance_1 = injector.get(_this.framerIdent + '-ControllerInternal');
|
776 | controllerInstance_1.initController(_this._model, _this._view, _this._frame, _this.framerName, injector);
|
777 | _this.framerOnControllerInit(controllerInstance_1);
|
778 | _this.framingDevTools.addController(_this.framerName, controllerInstance_1);
|
779 | return controllerInstance_1;
|
780 | },
|
781 | deps: [Injector],
|
782 | });
|
783 | if (this.provideControllerByType) {
|
784 | framing
|
785 | .provide({
|
786 | provide: this._controller,
|
787 | useExisting: this.framerIdent + '-Controller',
|
788 | multi: this.multiFramer && this._controller === this.defaultController,
|
789 | });
|
790 |
|
791 | console.info("Providing controller for framer " + this.framerIdent + " by type");
|
792 |
|
793 | if (this.defaultController && this._controller !== this.defaultController) {
|
794 | framing.provide({
|
795 | provide: this.defaultController,
|
796 | useExisting: this.framerIdent + '-Controller',
|
797 | multi: this.multiFramer,
|
798 | });
|
799 |
|
800 | console.info("Providing controller overload for framer " + this.framerIdent + " by default controller type");
|
801 |
|
802 | }
|
803 | }
|
804 | }
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 | if (this.route) {
|
813 | if (this.addFrameToRouteData) {
|
814 | this.addRouteData(framing, this.framerName + 'Frame', this._frame);
|
815 | }
|
816 | if (this.addModelToRouteData) {
|
817 | this.addRouteData(framing, this.framerName + 'Model', this._model);
|
818 | }
|
819 | if (this.addViewToRouteData) {
|
820 | this.addRouteData(framing, this.framerName + 'View', this._view);
|
821 | }
|
822 | if (this._frame) {
|
823 | var FrameResolver_1 = (function () {
|
824 | function FrameResolver_1(router, route, injector) {
|
825 | this.router = router;
|
826 | this.route = route;
|
827 | self._injector = injector;
|
828 | }
|
829 | FrameResolver_1.prototype.resolve = function (routeSnapshot, routeStateSnapshot) {
|
830 | var _this = this;
|
831 | self._frame.resolveStartSubject.next();
|
832 | var routeUrl = Framer.buildUrlLink(routeSnapshot);
|
833 | var sub = this.router.events.subscribe(function (event) {
|
834 | if (event instanceof NavigationStart) {
|
835 | console.error('Unexpected NavigationStart');
|
836 | }
|
837 | else if (event instanceof NavigationEnd) {
|
838 |
|
839 | console.info("Route url for framer " + self.framerIdent + " changed to " + routeUrl);
|
840 |
|
841 | self._frame.routeSnapshot = self.findActivateRouteSnapshot(_this.route);
|
842 | self._frame.routeUrl = routeUrl;
|
843 | self._frame.routeUrlSubject.next(routeUrl);
|
844 | self.framerOnResolveRoute();
|
845 | self._frame.resolveEndSubject.next();
|
846 | }
|
847 | else if (event instanceof NavigationError) {
|
848 | self._frame.resolveCancelSubject.next();
|
849 | }
|
850 | else if (event instanceof NavigationCancel) {
|
851 | self._frame.resolveCancelSubject.next();
|
852 | }
|
853 | sub.unsubscribe();
|
854 | });
|
855 | return self._frame;
|
856 | };
|
857 | return FrameResolver_1;
|
858 | }());
|
859 | framing
|
860 | .resolve(this.framerIdent, FrameResolver_1, this.route)
|
861 | .provide({
|
862 | provide: FrameResolver_1,
|
863 | useFactory: function (r, a, i) { return new FrameResolver_1(r, a, i); },
|
864 | deps: [Router, ActivatedRoute, Injector]
|
865 | });
|
866 | }
|
867 | }
|
868 | this._route = undefined;
|
869 | };
|
870 | |
871 |
|
872 |
|
873 | Framer.prototype.construct = function (model, view, controller) {
|
874 | this._framerId = Framer._nextId++;
|
875 | if (this.createFrame) {
|
876 | this._frame = new Frame();
|
877 | }
|
878 | var defaultModel = this.defaultModel;
|
879 | this._model = defaultModel ? merge(defaultModel, model) : model;
|
880 | var defaultView = this.defaultView;
|
881 | this._view = defaultView ? merge(defaultView, view) : view;
|
882 | this._controller = controller || this.defaultController;
|
883 | };
|
884 | |
885 |
|
886 |
|
887 | Framer.prototype.findActivateRouteSnapshot = function (route) {
|
888 | if (!route) {
|
889 | console.error('Failed to find activated route snapshot');
|
890 | return undefined;
|
891 | }
|
892 | if (route.snapshot && route.snapshot.data && route.snapshot.data.hasOwnProperty(this.framerIdent)) {
|
893 | return route.snapshot;
|
894 | }
|
895 | return this.findActivateRouteSnapshot(route.firstChild);
|
896 | };
|
897 | |
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 | |
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 |
|
921 |
|
922 | |
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 | Framer.prototype.addRouteData = function (framing, name, value) {
|
934 | if (value) {
|
935 | var routeConfig = framing.getOrAddRoute(this.route);
|
936 | if (routeConfig.data && routeConfig.data[name]) {
|
937 | console.warn("Failed to add " + name + " route data for framer " + this.framerIdent + ". Data item already exists.");
|
938 | }
|
939 | else {
|
940 | framing.datum(name, value, this.route);
|
941 |
|
942 | console.info("Adding " + name + " route data for framer " + this.framerIdent);
|
943 |
|
944 | }
|
945 | }
|
946 | };
|
947 | return Framer;
|
948 | }());
|
949 | Framer._nextId = 1;
|
950 | var FramingDevToolsFeature = (function (_super) {
|
951 | __extends(FramingDevToolsFeature, _super);
|
952 | function FramingDevToolsFeature() {
|
953 | return _super !== null && _super.apply(this, arguments) || this;
|
954 | }
|
955 | Object.defineProperty(FramingDevToolsFeature.prototype, "defaultModel", {
|
956 | get: function () {
|
957 | return {};
|
958 | },
|
959 | enumerable: true,
|
960 | configurable: true
|
961 | });
|
962 | Object.defineProperty(FramingDevToolsFeature.prototype, "defaultView", {
|
963 | get: function () {
|
964 | return {};
|
965 | },
|
966 | enumerable: true,
|
967 | configurable: true
|
968 | });
|
969 | FramingDevToolsFeature.prototype.frame = function (framing) { };
|
970 | FramingDevToolsFeature.prototype.framerOnResolveRoute = function () {
|
971 | var framingDevToolsController;
|
972 | framingDevToolsController = this.injector.get(FramingDevToolsController);
|
973 | };
|
974 | Object.defineProperty(FramingDevToolsFeature.prototype, "framerName", {
|
975 |
|
976 |
|
977 |
|
978 | get: function () { return 'FramingDevTools'; },
|
979 | enumerable: true,
|
980 | configurable: true
|
981 | });
|
982 | Object.defineProperty(FramingDevToolsFeature.prototype, "defaultController", {
|
983 | get: function () { return FramingDevToolsController; },
|
984 | enumerable: true,
|
985 | configurable: true
|
986 | });
|
987 | return FramingDevToolsFeature;
|
988 | }(Framer));
|
989 | var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
990 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
991 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
992 | r = Reflect.decorate(decorators, target, key, desc);
|
993 | else
|
994 | for (var i = decorators.length - 1; i >= 0; i--)
|
995 | if (d = decorators[i])
|
996 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
997 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
998 | };
|
999 | var __metadata$2 = (undefined && undefined.__metadata) || function (k, v) {
|
1000 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
1001 | return Reflect.metadata(k, v);
|
1002 | };
|
1003 | var FramingComponentOutletDirective = (function () {
|
1004 | function FramingComponentOutletDirective(_view) {
|
1005 | this._view = _view;
|
1006 | this.onComponent = new EventEmitter();
|
1007 | }
|
1008 | FramingComponentOutletDirective.prototype.isActivated = function () { return !!this._componentRef; };
|
1009 | FramingComponentOutletDirective.prototype.ngOnChanges = function (changes) {
|
1010 | var activate = false;
|
1011 | if (changes.ngModuleFactory) {
|
1012 | if (this._moduleRef) {
|
1013 | this._moduleRef.destroy();
|
1014 | }
|
1015 | if (this.ngModuleFactory) {
|
1016 | var injector = this.injector || this._view.parentInjector;
|
1017 | this._moduleRef = this.ngModuleFactory.create(injector);
|
1018 | }
|
1019 | else {
|
1020 | this._moduleRef = undefined;
|
1021 | }
|
1022 | activate = true;
|
1023 | }
|
1024 | if (changes.framingComponentOutlet.currentValue !== changes.framingComponentOutlet.previousValue) {
|
1025 | activate = true;
|
1026 | }
|
1027 | if (activate) {
|
1028 | this.activate(this.framingComponentOutlet);
|
1029 | }
|
1030 | };
|
1031 | FramingComponentOutletDirective.prototype.ngOnDestroy = function () {
|
1032 | this.deactivate();
|
1033 | if (this._moduleRef) {
|
1034 | this._moduleRef.destroy();
|
1035 | }
|
1036 | };
|
1037 | FramingComponentOutletDirective.prototype.activate = function (component) {
|
1038 | this.deactivate();
|
1039 | if (!component) {
|
1040 | return;
|
1041 | }
|
1042 | try {
|
1043 | var injector = this.injector || this._view.parentInjector;
|
1044 | var factory = injector.get(ComponentFactoryResolver).resolveComponentFactory(component);
|
1045 | this._componentRef = this._view.createComponent(factory, this._view.length, injector, this.content);
|
1046 | this.onComponent.emit(this._componentRef);
|
1047 | try {
|
1048 | this._componentRef.changeDetectorRef.detectChanges();
|
1049 | }
|
1050 | catch (e) {
|
1051 | console.error("detectChanges failed on activated component in FramingComponentOutlet", { e: e, component: component });
|
1052 | return;
|
1053 | }
|
1054 | }
|
1055 | catch (e) {
|
1056 | console.error("Failed to activate component in FramingComponentOutlet", { e: e, component: component });
|
1057 | return;
|
1058 | }
|
1059 | };
|
1060 | FramingComponentOutletDirective.prototype.deactivate = function () {
|
1061 | if (this._componentRef) {
|
1062 | this._view.remove(this._view.indexOf(this._componentRef.hostView));
|
1063 | this._componentRef.destroy();
|
1064 | }
|
1065 | this._view.clear();
|
1066 | this._componentRef = undefined;
|
1067 | };
|
1068 | return FramingComponentOutletDirective;
|
1069 | }());
|
1070 | __decorate$3([
|
1071 | Input(),
|
1072 | __metadata$2("design:type", Type)
|
1073 | ], FramingComponentOutletDirective.prototype, "framingComponentOutlet", void 0);
|
1074 | __decorate$3([
|
1075 | Input(),
|
1076 | __metadata$2("design:type", Injector)
|
1077 | ], FramingComponentOutletDirective.prototype, "injector", void 0);
|
1078 | __decorate$3([
|
1079 | Input(),
|
1080 | __metadata$2("design:type", Array)
|
1081 | ], FramingComponentOutletDirective.prototype, "content", void 0);
|
1082 | __decorate$3([
|
1083 | Input(),
|
1084 | __metadata$2("design:type", NgModuleFactory)
|
1085 | ], FramingComponentOutletDirective.prototype, "ngModuleFactory", void 0);
|
1086 | __decorate$3([
|
1087 | Output(),
|
1088 | __metadata$2("design:type", EventEmitter)
|
1089 | ], FramingComponentOutletDirective.prototype, "onComponent", void 0);
|
1090 | FramingComponentOutletDirective = __decorate$3([
|
1091 | Directive({
|
1092 | selector: '[framingComponentOutlet]',
|
1093 | }),
|
1094 | __metadata$2("design:paramtypes", [ViewContainerRef])
|
1095 | ], FramingComponentOutletDirective);
|
1096 | var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1097 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1098 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1099 | r = Reflect.decorate(decorators, target, key, desc);
|
1100 | else
|
1101 | for (var i = decorators.length - 1; i >= 0; i--)
|
1102 | if (d = decorators[i])
|
1103 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1104 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1105 | };
|
1106 | var FramingComponentOutletModule = FramingComponentOutletModule_1 = (function () {
|
1107 | function FramingComponentOutletModule() {
|
1108 | }
|
1109 | FramingComponentOutletModule.withEntryComponents = function () {
|
1110 | var components = [];
|
1111 | for (var _a = 0; _a < arguments.length; _a++) {
|
1112 | components[_a] = arguments[_a];
|
1113 | }
|
1114 | return {
|
1115 | ngModule: FramingComponentOutletModule_1,
|
1116 | providers: [
|
1117 | { provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: components, multi: true },
|
1118 | ],
|
1119 | };
|
1120 | };
|
1121 | return FramingComponentOutletModule;
|
1122 | }());
|
1123 | FramingComponentOutletModule = FramingComponentOutletModule_1 = __decorate$4([
|
1124 | NgModule({
|
1125 | declarations: [FramingComponentOutletDirective],
|
1126 | exports: [FramingComponentOutletDirective],
|
1127 | })
|
1128 | ], FramingComponentOutletModule);
|
1129 | var FramingComponentOutletModule_1;
|
1130 | var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1131 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1132 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1133 | r = Reflect.decorate(decorators, target, key, desc);
|
1134 | else
|
1135 | for (var i = decorators.length - 1; i >= 0; i--)
|
1136 | if (d = decorators[i])
|
1137 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1138 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1139 | };
|
1140 | var __metadata$4 = (undefined && undefined.__metadata) || function (k, v) {
|
1141 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
1142 | return Reflect.metadata(k, v);
|
1143 | };
|
1144 | var FramingContainerOutletService = (function () {
|
1145 | function FramingContainerOutletService(router) {
|
1146 | var _this = this;
|
1147 | this.router = router;
|
1148 | this.contentsSubject = new ReplaySubject$1();
|
1149 | this.contents = [];
|
1150 | this.routeContents = [];
|
1151 | this.subscriptions = [];
|
1152 | this.subscriptions.push(this.router.events.subscribe(function (event) {
|
1153 | if (event instanceof NavigationEnd) {
|
1154 | _this.onNavigationEnd();
|
1155 | }
|
1156 | }));
|
1157 | }
|
1158 | Object.defineProperty(FramingContainerOutletService.prototype, "contents$", {
|
1159 | get: function () { return this.contentsSubject.asObservable(); },
|
1160 | enumerable: true,
|
1161 | configurable: true
|
1162 | });
|
1163 | FramingContainerOutletService.prototype.hasContent = function (container) {
|
1164 | return !!this.contents.filter(function (c) { return isEqual(c.container, container); }).length;
|
1165 | };
|
1166 | FramingContainerOutletService.prototype.activate = function (content) {
|
1167 | var _this = this;
|
1168 | this.contents.push(content);
|
1169 | this.contentsSubject.next(clone(this.contents));
|
1170 | return function () { _this.deactivate(content); };
|
1171 | };
|
1172 | FramingContainerOutletService.prototype.deactivate = function (content) {
|
1173 | this.contents = this.contents.filter(function (e) { return e !== content; });
|
1174 | this.contentsSubject.next(clone(this.contents));
|
1175 | };
|
1176 | FramingContainerOutletService.prototype.onNavigationEnd = function () {
|
1177 | var _this = this;
|
1178 | var newRouteContents = [];
|
1179 | this.resolveRouteContents(this.router.routerState.snapshot.root, newRouteContents);
|
1180 | newRouteContents = uniqWith(newRouteContents, isEqual);
|
1181 | var newContents = differenceWith(newRouteContents, this.routeContents, isEqual);
|
1182 | var removedContents = differenceWith(this.routeContents, newRouteContents, isEqual);
|
1183 | newContents.forEach(function (c) { return _this.activate(c); });
|
1184 | removedContents.forEach(function (c) { return _this.deactivate(c); });
|
1185 | this.routeContents = newRouteContents;
|
1186 | };
|
1187 | FramingContainerOutletService.prototype.resolveRouteContents = function (snapshot, routeContents) {
|
1188 | if (snapshot.data && snapshot.data.containers) {
|
1189 | var containers = snapshot.data.containers;
|
1190 | for (var _a = 0, containers_1 = containers; _a < containers_1.length; _a++) {
|
1191 | var container = containers_1[_a];
|
1192 | routeContents.push(container);
|
1193 | }
|
1194 | }
|
1195 | for (var _b = 0, _c = snapshot.children; _b < _c.length; _b++) {
|
1196 | var child = _c[_b];
|
1197 | this.resolveRouteContents(child, routeContents);
|
1198 | }
|
1199 | };
|
1200 | return FramingContainerOutletService;
|
1201 | }());
|
1202 | FramingContainerOutletService = __decorate$6([
|
1203 | Injectable(),
|
1204 | __metadata$4("design:paramtypes", [Router])
|
1205 | ], FramingContainerOutletService);
|
1206 | var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1207 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1208 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1209 | r = Reflect.decorate(decorators, target, key, desc);
|
1210 | else
|
1211 | for (var i = decorators.length - 1; i >= 0; i--)
|
1212 | if (d = decorators[i])
|
1213 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1214 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1215 | };
|
1216 | var __metadata$3 = (undefined && undefined.__metadata) || function (k, v) {
|
1217 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
1218 | return Reflect.metadata(k, v);
|
1219 | };
|
1220 | var FramingContainerOutletDirective = (function () {
|
1221 | function FramingContainerOutletDirective(_view, _containerService, _router) {
|
1222 | this._view = _view;
|
1223 | this._containerService = _containerService;
|
1224 | this._router = _router;
|
1225 | this.onComponents = new EventEmitter();
|
1226 | this._activated = [];
|
1227 | this._subscriptions = [];
|
1228 | }
|
1229 | FramingContainerOutletDirective.prototype.containerName = function () { return this.framingContainerOutlet; };
|
1230 | FramingContainerOutletDirective.prototype.isActivated = function () { return this._activated.length > 0; };
|
1231 | FramingContainerOutletDirective.prototype.ngOnInit = function () {
|
1232 | var _this = this;
|
1233 | if (!this.framingContainerOutlet) {
|
1234 | console.warn('FramingContainerOutlet without a container name');
|
1235 | }
|
1236 | else {
|
1237 | if (this.framingContainerOutlet[0] === '\'') {
|
1238 | console.warn("FramingContainerOutlet name \"" + this.framingContainerOutlet + "\" starts with a qoute");
|
1239 | }
|
1240 | this._subscriptions.push(this._containerService.contents$.subscribe(function (contents) { return _this.onContent(contents); }));
|
1241 | }
|
1242 | this._subscriptions.push(this._router.events.subscribe(function (event) {
|
1243 | if (event instanceof NavigationEnd) {
|
1244 | if (!_this.optionalContainer && !_this.isActivated()) {
|
1245 | console.warn("No content for required FramingContainerOutlet '" + _this.framingContainerOutlet + "' found");
|
1246 | }
|
1247 | }
|
1248 | }));
|
1249 | };
|
1250 | FramingContainerOutletDirective.prototype.ngOnDestroy = function () {
|
1251 | var _this = this;
|
1252 | this._activated.forEach(function (a) { return _this.deactivate(a); });
|
1253 | this._subscriptions.forEach(function (s) { return s.unsubscribe(); });
|
1254 | };
|
1255 | FramingContainerOutletDirective.prototype.onContent = function (allContents) {
|
1256 | var _this = this;
|
1257 | var contents = allContents.filter(function (c) { return isEqual(c.container, _this.framingContainerOutlet); });
|
1258 |
|
1259 | this._activated.forEach(function (a) {
|
1260 | if (contents.findIndex(function (content) { return content === a.content; }) === -1) {
|
1261 | _this.deactivate(a);
|
1262 | }
|
1263 | });
|
1264 | this._activated = this._activated.filter(function (a) { return !!a.ref; });
|
1265 |
|
1266 | var i = 0;
|
1267 | var _loop_1 = function (content) {
|
1268 | if (this_1._activated.length > i) {
|
1269 | if (this_1._activated[i].content !== content) {
|
1270 |
|
1271 | var activatedIndex = this_1._activated.findIndex(function (a) { return a.content === content; });
|
1272 | if (activatedIndex === -1) {
|
1273 |
|
1274 | this_1._activated.splice(i, 0, { content: content, ref: this_1.activate(content) });
|
1275 | }
|
1276 | else if (activatedIndex > i) {
|
1277 |
|
1278 | var _activated = this_1._activated.splice(activatedIndex, 1);
|
1279 | (_a = this_1._activated).splice.apply(_a, [i, 0].concat(_activated));
|
1280 | var view = this_1._view.detach(activatedIndex);
|
1281 | this_1._view.insert(view, i);
|
1282 | }
|
1283 | else {
|
1284 | console.error('Logic error in FramingContainerOutlet!');
|
1285 | }
|
1286 | }
|
1287 | }
|
1288 | else {
|
1289 |
|
1290 | var ref = this_1.activate(content);
|
1291 | if (ref) {
|
1292 | this_1._activated.push({ content: content, ref: ref });
|
1293 | }
|
1294 | }
|
1295 | i++;
|
1296 | var _a;
|
1297 | };
|
1298 | var this_1 = this;
|
1299 | for (var _a = 0, contents_1 = contents; _a < contents_1.length; _a++) {
|
1300 | var content = contents_1[_a];
|
1301 | _loop_1(content);
|
1302 | }
|
1303 | this.onComponents.emit(this._activated.map(function (a) { return a.ref; }));
|
1304 | };
|
1305 | FramingContainerOutletDirective.prototype.activate = function (content, i) {
|
1306 | try {
|
1307 | var injector = (!this.useViewInjector && content.injector) ? content.injector : this._view.parentInjector;
|
1308 | var factory = injector.get(ComponentFactoryResolver).resolveComponentFactory(content.component);
|
1309 | var ref = this._view.createComponent(factory, i, injector, this.content);
|
1310 | try {
|
1311 | ref.changeDetectorRef.detectChanges();
|
1312 | }
|
1313 | catch (e) {
|
1314 | console.error("detectChanges failed on activated component in FramingContainerOutlet '" + this.framingContainerOutlet + "'", { e: e, component: content.component });
|
1315 | }
|
1316 | return ref;
|
1317 | }
|
1318 | catch (e) {
|
1319 | console.error("Failed to activate component in FramingContainerOutlet '" + this.framingContainerOutlet + "'", { e: e, component: content.component });
|
1320 | return undefined;
|
1321 | }
|
1322 | };
|
1323 | FramingContainerOutletDirective.prototype.deactivate = function (activated) {
|
1324 | activated.ref.destroy();
|
1325 | activated.ref = null;
|
1326 | };
|
1327 | return FramingContainerOutletDirective;
|
1328 | }());
|
1329 | __decorate$5([
|
1330 | Input(),
|
1331 | __metadata$3("design:type", String)
|
1332 | ], FramingContainerOutletDirective.prototype, "framingContainerOutlet", void 0);
|
1333 | __decorate$5([
|
1334 | Input(),
|
1335 | __metadata$3("design:type", Boolean)
|
1336 | ], FramingContainerOutletDirective.prototype, "optionalContainer", void 0);
|
1337 | __decorate$5([
|
1338 | Input(),
|
1339 | __metadata$3("design:type", Boolean)
|
1340 | ], FramingContainerOutletDirective.prototype, "useViewInjector", void 0);
|
1341 | __decorate$5([
|
1342 | Input(),
|
1343 | __metadata$3("design:type", Array)
|
1344 | ], FramingContainerOutletDirective.prototype, "content", void 0);
|
1345 | __decorate$5([
|
1346 | Output(),
|
1347 | __metadata$3("design:type", EventEmitter)
|
1348 | ], FramingContainerOutletDirective.prototype, "onComponents", void 0);
|
1349 | FramingContainerOutletDirective = __decorate$5([
|
1350 | Directive({
|
1351 | selector: '[framingContainerOutlet]',
|
1352 | }),
|
1353 | __metadata$3("design:paramtypes", [ViewContainerRef,
|
1354 | FramingContainerOutletService,
|
1355 | Router])
|
1356 | ], FramingContainerOutletDirective);
|
1357 | var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1358 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1359 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1360 | r = Reflect.decorate(decorators, target, key, desc);
|
1361 | else
|
1362 | for (var i = decorators.length - 1; i >= 0; i--)
|
1363 | if (d = decorators[i])
|
1364 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1365 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1366 | };
|
1367 | var FramingContainerOutletModule = FramingContainerOutletModule_1 = (function () {
|
1368 | function FramingContainerOutletModule() {
|
1369 | }
|
1370 | FramingContainerOutletModule.withEntryComponents = function () {
|
1371 | var components = [];
|
1372 | for (var _a = 0; _a < arguments.length; _a++) {
|
1373 | components[_a] = arguments[_a];
|
1374 | }
|
1375 | return {
|
1376 | ngModule: FramingContainerOutletModule_1,
|
1377 | providers: [
|
1378 | { provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: components, multi: true },
|
1379 | ],
|
1380 | };
|
1381 | };
|
1382 | FramingContainerOutletModule.forRoot = function () {
|
1383 | return {
|
1384 | ngModule: FramingContainerOutletModule_1,
|
1385 | providers: [FramingContainerOutletService],
|
1386 | };
|
1387 | };
|
1388 | return FramingContainerOutletModule;
|
1389 | }());
|
1390 | FramingContainerOutletModule = FramingContainerOutletModule_1 = __decorate$7([
|
1391 | NgModule({
|
1392 | declarations: [FramingContainerOutletDirective],
|
1393 | exports: [FramingContainerOutletDirective],
|
1394 | })
|
1395 | ], FramingContainerOutletModule);
|
1396 | var FramingContainerOutletModule_1;
|
1397 | var __decorate$8 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1398 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1399 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1400 | r = Reflect.decorate(decorators, target, key, desc);
|
1401 | else
|
1402 | for (var i = decorators.length - 1; i >= 0; i--)
|
1403 | if (d = decorators[i])
|
1404 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1405 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1406 | };
|
1407 | var __metadata$5 = (undefined && undefined.__metadata) || function (k, v) {
|
1408 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
1409 | return Reflect.metadata(k, v);
|
1410 | };
|
1411 | var FramingContainerOutletResolver = (function () {
|
1412 | function FramingContainerOutletResolver(containers, injector) {
|
1413 | this.containers = containers;
|
1414 | this.injector = injector;
|
1415 | }
|
1416 | |
1417 |
|
1418 |
|
1419 | FramingContainerOutletResolver.prototype.resolve = function (route, state) {
|
1420 |
|
1421 | for (var _a = 0, _b = this.containers; _a < _b.length; _a++) {
|
1422 | var container = _b[_a];
|
1423 | container.injector = this.injector;
|
1424 | }
|
1425 | return this.containers;
|
1426 | };
|
1427 | return FramingContainerOutletResolver;
|
1428 | }());
|
1429 | FramingContainerOutletResolver = __decorate$8([
|
1430 | Injectable(),
|
1431 | __metadata$5("design:paramtypes", [Array, Injector])
|
1432 | ], FramingContainerOutletResolver);
|
1433 | var __decorate$9 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1434 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1435 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1436 | r = Reflect.decorate(decorators, target, key, desc);
|
1437 | else
|
1438 | for (var i = decorators.length - 1; i >= 0; i--)
|
1439 | if (d = decorators[i])
|
1440 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1441 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1442 | };
|
1443 |
|
1444 |
|
1445 |
|
1446 | var FramingEmptyParentComponent = (function () {
|
1447 | function FramingEmptyParentComponent() {
|
1448 | }
|
1449 | return FramingEmptyParentComponent;
|
1450 | }());
|
1451 | FramingEmptyParentComponent = __decorate$9([
|
1452 | Component({
|
1453 | selector: 'empty-parent-component',
|
1454 | template: '<router-outlet></router-outlet>',
|
1455 | })
|
1456 | ], FramingEmptyParentComponent);
|
1457 | var __decorate$11 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1458 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1459 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1460 | r = Reflect.decorate(decorators, target, key, desc);
|
1461 | else
|
1462 | for (var i = decorators.length - 1; i >= 0; i--)
|
1463 | if (d = decorators[i])
|
1464 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1465 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1466 | };
|
1467 | var FramingRootComponent = (function () {
|
1468 | function FramingRootComponent() {
|
1469 | }
|
1470 | return FramingRootComponent;
|
1471 | }());
|
1472 | FramingRootComponent = __decorate$11([
|
1473 | Component({
|
1474 | selector: 'app-root',
|
1475 | template: '<router-outlet></router-outlet>',
|
1476 | })
|
1477 | ], FramingRootComponent);
|
1478 | var __decorate$10 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
1479 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
1480 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
1481 | r = Reflect.decorate(decorators, target, key, desc);
|
1482 | else
|
1483 | for (var i = decorators.length - 1; i >= 0; i--)
|
1484 | if (d = decorators[i])
|
1485 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
1486 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
1487 | };
|
1488 | var FramingComponentsModule = (function () {
|
1489 | function FramingComponentsModule() {
|
1490 | }
|
1491 | return FramingComponentsModule;
|
1492 | }());
|
1493 | FramingComponentsModule = __decorate$10([
|
1494 | NgModule({
|
1495 | imports: [
|
1496 | RouterModule,
|
1497 | ],
|
1498 | declarations: [
|
1499 | FramingEmptyParentComponent,
|
1500 | FramingRootComponent,
|
1501 | ],
|
1502 | exports: [
|
1503 | FramingEmptyParentComponent,
|
1504 | FramingRootComponent,
|
1505 | ],
|
1506 | })
|
1507 | ], FramingComponentsModule);
|
1508 | var FramerHelper = (function () {
|
1509 |
|
1510 |
|
1511 |
|
1512 | function FramerHelper() {
|
1513 | this.framerHelperId = FramerHelper._nextId++;
|
1514 | }
|
1515 | Object.defineProperty(FramerHelper.prototype, "framerHelperIdent", {
|
1516 | |
1517 |
|
1518 |
|
1519 | get: function () {
|
1520 | return camelCase("framerHelper-" + this.__proto__.constructor.name + "-" + this.framerHelperId);
|
1521 | },
|
1522 | enumerable: true,
|
1523 | configurable: true
|
1524 | });
|
1525 | return FramerHelper;
|
1526 | }());
|
1527 | FramerHelper._nextId = 1;
|
1528 |
|
1529 |
|
1530 |
|
1531 | var FramingNgModule = (function () {
|
1532 | function FramingNgModule() {
|
1533 |
|
1534 |
|
1535 |
|
1536 | this._ngModule = {
|
1537 | imports: [],
|
1538 | declarations: [],
|
1539 | exports: [],
|
1540 | providers: [],
|
1541 | bootstrap: [],
|
1542 | entryComponents: [],
|
1543 | };
|
1544 | this._root = false;
|
1545 | this._routes = [];
|
1546 | }
|
1547 | Object.defineProperty(FramingNgModule, "defaultPathMatch", {
|
1548 | get: function () { return 'prefix'; },
|
1549 | enumerable: true,
|
1550 | configurable: true
|
1551 | });
|
1552 |
|
1553 |
|
1554 |
|
1555 | FramingNgModule.prototype.ngModule = function (ngModule) {
|
1556 | var _this = this;
|
1557 | if (ngModule) {
|
1558 | defaults(this._ngModule, ngModule);
|
1559 | each(filter(keys(ngModule), function (key) { return isArray(ngModule[key]); }), function (key) {
|
1560 | _this._ngModule[key] = uniqWith(_this._ngModule[key].concat(reject(ngModule[key], isNil)), isEqual);
|
1561 | });
|
1562 | }
|
1563 | return this;
|
1564 | };
|
1565 | FramingNgModule.prototype.bootstrap = function (bootstrap) {
|
1566 | var flattened = [].concat.apply([], bootstrap);
|
1567 | this._ngModule.bootstrap = uniqWith(this._ngModule.bootstrap.concat(reject(flattened, isNil)), isEqual);
|
1568 | return this;
|
1569 | };
|
1570 | FramingNgModule.prototype.child = function (child, parent) {
|
1571 | var parentRoute = this.getOrAddRouteOverload(parent);
|
1572 | if (!parentRoute.children) {
|
1573 | parentRoute.children = [];
|
1574 | }
|
1575 | if (!parentRoute.component) {
|
1576 | parentRoute.component = FramingEmptyParentComponent;
|
1577 | }
|
1578 | this.getOrAddRoute(child, parentRoute.children);
|
1579 | return this;
|
1580 | };
|
1581 | FramingNgModule.prototype.children = function (children, parent) {
|
1582 | var _this = this;
|
1583 | each(children, function (child) {
|
1584 | _this.child(child, parent);
|
1585 | });
|
1586 | return this;
|
1587 | };
|
1588 | FramingNgModule.prototype.component = function (component, route) {
|
1589 | if (component) {
|
1590 | var routeConfig = this.getOrAddRouteOverload(route);
|
1591 | routeConfig.component = component;
|
1592 | }
|
1593 | return this;
|
1594 | };
|
1595 | FramingNgModule.prototype.componentAndDeclare = function (component, route) {
|
1596 | return this.componentAndDeclaration(component, route);
|
1597 | };
|
1598 | FramingNgModule.prototype.componentAndDeclaration = function (component, route) {
|
1599 | this.component(component, route);
|
1600 | if (component) {
|
1601 | this.declare(component);
|
1602 | }
|
1603 | return this;
|
1604 | };
|
1605 | FramingNgModule.prototype.container = function (container, components, route) {
|
1606 | var containers = {};
|
1607 | containers[container] = components;
|
1608 | this.containers(containers, route);
|
1609 | return this;
|
1610 | };
|
1611 | FramingNgModule.prototype.containers = function (containers, route) {
|
1612 | for (var key in containers) {
|
1613 | if (containers.hasOwnProperty(key)) {
|
1614 | if (isNil(containers[key])) {
|
1615 | delete containers[key];
|
1616 | }
|
1617 | }
|
1618 | }
|
1619 | var routeConfig = this.getOrAddRoute(route);
|
1620 | if (!routeConfig.resolve) {
|
1621 | routeConfig.resolve = {};
|
1622 | }
|
1623 | if (!routeConfig.resolve.containers) {
|
1624 | routeConfig.resolve.containers = [];
|
1625 | }
|
1626 | for (var key in containers) {
|
1627 | if (containers.hasOwnProperty(key)) {
|
1628 | var components = containers[key];
|
1629 | if (isArray(components)) {
|
1630 | for (var _a = 0, components_1 = components; _a < components_1.length; _a++) {
|
1631 | var component = components_1[_a];
|
1632 | routeConfig.resolve.containers.push({ container: key, component: component });
|
1633 | }
|
1634 | }
|
1635 | else {
|
1636 | routeConfig.resolve.containers.push({ container: key, component: components });
|
1637 | }
|
1638 | }
|
1639 | }
|
1640 | return this;
|
1641 | };
|
1642 | FramingNgModule.prototype.datum = function (key, datum, route) {
|
1643 | var data = {};
|
1644 | data[key] = datum;
|
1645 | this.data(data, route);
|
1646 | return this;
|
1647 | };
|
1648 | FramingNgModule.prototype.data = function (data, route) {
|
1649 | var routeConfig = this.getOrAddRouteOverload(route);
|
1650 | if (!routeConfig.data) {
|
1651 | routeConfig.data = {};
|
1652 | }
|
1653 | merge(routeConfig.data, data);
|
1654 | return this;
|
1655 | };
|
1656 | FramingNgModule.prototype.resolve = function (key, resolve, route) {
|
1657 | var resolves = {};
|
1658 | resolves[key] = resolve;
|
1659 | this.resolves(resolves, route);
|
1660 | return this;
|
1661 | };
|
1662 | FramingNgModule.prototype.resolves = function (resolves, route) {
|
1663 | var routeConfig = this.getOrAddRouteOverload(route);
|
1664 | if (!routeConfig.resolve) {
|
1665 | routeConfig.resolve = {};
|
1666 | }
|
1667 | merge(routeConfig.resolve, resolves);
|
1668 | return this;
|
1669 | };
|
1670 | FramingNgModule.prototype.declare = function (declaration) {
|
1671 | return this.declaration(declaration);
|
1672 | };
|
1673 | FramingNgModule.prototype.declaration = function (declaration) {
|
1674 | return this.declarations(isArray(declaration) ? declaration : [declaration]);
|
1675 | };
|
1676 | FramingNgModule.prototype.declarations = function (declarations) {
|
1677 | var flattened = [].concat.apply([], declarations);
|
1678 | this._ngModule.declarations = uniqWith(this._ngModule.declarations.concat(reject(flattened, isNil)), isEqual);
|
1679 | return this;
|
1680 | };
|
1681 | FramingNgModule.prototype.declareAndExport = function (declaration) {
|
1682 | return this.declarationAndExport(declaration);
|
1683 | };
|
1684 | FramingNgModule.prototype.declarationAndExport = function (declaration) {
|
1685 | return this.declarationsAndExports(isArray(declaration) ? declaration : [declaration]);
|
1686 | };
|
1687 | FramingNgModule.prototype.declarationsAndExports = function (declarations) {
|
1688 | this.declarations(declarations);
|
1689 | this.exports(declarations);
|
1690 | return this;
|
1691 | };
|
1692 | FramingNgModule.prototype.declareAndEntryComponent = function (declaration) {
|
1693 | return this.declarationAndEntryComponent(declaration);
|
1694 | };
|
1695 | FramingNgModule.prototype.declarationAndEntryComponent = function (declaration) {
|
1696 | return this.declarationsAndEntryComponents(isArray(declaration) ? declaration : [declaration]);
|
1697 | };
|
1698 | FramingNgModule.prototype.declarationsAndEntryComponents = function (declarations) {
|
1699 | this.declarations(declarations);
|
1700 | this.entryComponents(declarations);
|
1701 | return this;
|
1702 | };
|
1703 | FramingNgModule.prototype.entryComponent = function (entryComponent) {
|
1704 | return this.entryComponents(isArray(entryComponent) ? entryComponent : [entryComponent]);
|
1705 | };
|
1706 | FramingNgModule.prototype.entryComponents = function (entryComponents) {
|
1707 | var flattened = [].concat.apply([], entryComponents);
|
1708 | this._ngModule.entryComponents = uniqWith(this._ngModule.entryComponents.concat(reject(flattened, isNil)), isEqual);
|
1709 | return this;
|
1710 | };
|
1711 | FramingNgModule.prototype.export = function (e) {
|
1712 | return this.exports(isArray(e) ? e : [e]);
|
1713 | };
|
1714 | FramingNgModule.prototype.exports = function (exports) {
|
1715 | var flattened = [].concat.apply([], exports);
|
1716 | this._ngModule.exports = uniqWith(this._ngModule.exports.concat(reject(flattened, isNil)), isEqual);
|
1717 | return this;
|
1718 | };
|
1719 | FramingNgModule.prototype.import = function (i) {
|
1720 | return this.imports(isArray(i) ? i : [i]);
|
1721 | };
|
1722 | FramingNgModule.prototype.imports = function (imports) {
|
1723 | var flattened = [].concat.apply([], imports);
|
1724 | this._ngModule.imports = uniqWith(this._ngModule.imports.concat(reject(flattened, isNil)), isEqual);
|
1725 | return this;
|
1726 | };
|
1727 | FramingNgModule.prototype.importAndExport = function (m) {
|
1728 | return this.importsAndExports(isArray(m) ? m : [m]);
|
1729 | };
|
1730 | FramingNgModule.prototype.importsAndExports = function (modules) {
|
1731 | this.imports(modules);
|
1732 | this.exports(modules);
|
1733 | return this;
|
1734 | };
|
1735 | FramingNgModule.prototype.provide = function (provider) {
|
1736 | return this.provider(provider);
|
1737 | };
|
1738 | FramingNgModule.prototype.provider = function (provider) {
|
1739 | return this.providers(isArray(provider) ? provider : [provider]);
|
1740 | };
|
1741 | FramingNgModule.prototype.providers = function (providers) {
|
1742 | var flattened = [].concat.apply([], providers);
|
1743 | this._ngModule.providers = uniqWith(this._ngModule.providers.concat(reject(flattened, isNil)), isEqual);
|
1744 | return this;
|
1745 | };
|
1746 | |
1747 |
|
1748 |
|
1749 |
|
1750 | FramingNgModule.prototype.root = function (rootComponent, config) {
|
1751 | this._root = true;
|
1752 | this._rootComponentConfig = config || {};
|
1753 | defaults(this._rootComponentConfig, { hybrid: false });
|
1754 | this._rootComponent = rootComponent || FramingRootComponent;
|
1755 | return this;
|
1756 | };
|
1757 | |
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 | FramingNgModule.prototype.route = function (route, config) {
|
1763 | this.getOrAddRoute(route);
|
1764 | if (this._routeConfig) {
|
1765 | if (config) {
|
1766 | merge(this._routeConfig, config);
|
1767 | }
|
1768 | }
|
1769 | else {
|
1770 | this._routeConfig = config || {};
|
1771 | defaults(this._routeConfig, { forRoot: false });
|
1772 | }
|
1773 | return this;
|
1774 | };
|
1775 | FramingNgModule.prototype.routes = function (routes, config) {
|
1776 | var _this = this;
|
1777 | each(routes, function (route) {
|
1778 | _this.route(route, config);
|
1779 | });
|
1780 | return this;
|
1781 | };
|
1782 | FramingNgModule.prototype.frameRoute = function (route) {
|
1783 | var framers = [];
|
1784 | for (var _a = 1; _a < arguments.length; _a++) {
|
1785 | framers[_a - 1] = arguments[_a];
|
1786 | }
|
1787 | this.buildFramers(framers, this.getOrAddRouteOverload(route));
|
1788 | return this;
|
1789 | };
|
1790 | |
1791 |
|
1792 |
|
1793 | FramingNgModule.prototype.getRoute = function (route, array) {
|
1794 | if (route === void 0) { route = {}; }
|
1795 |
|
1796 | if (!array) {
|
1797 | array = this._routes;
|
1798 | }
|
1799 |
|
1800 | defaults(route, { path: '', pathMatch: FramingNgModule.defaultPathMatch });
|
1801 | return find(array, function (m) { return m.path === route.path && m.pathMatch === route.pathMatch; });
|
1802 | };
|
1803 | |
1804 |
|
1805 |
|
1806 | FramingNgModule.prototype.getOrAddRoute = function (route, array) {
|
1807 | if (route === void 0) { route = {}; }
|
1808 |
|
1809 | if (!array) {
|
1810 | array = this._routes;
|
1811 | }
|
1812 |
|
1813 | defaults(route, { path: '', pathMatch: FramingNgModule.defaultPathMatch });
|
1814 | var r = find(array, function (m) { return m.path === route.path && m.pathMatch === route.pathMatch; });
|
1815 | if (r) {
|
1816 | merge(r, route);
|
1817 | return r;
|
1818 | }
|
1819 | else {
|
1820 | array.push(route);
|
1821 | return route;
|
1822 | }
|
1823 | };
|
1824 | |
1825 |
|
1826 |
|
1827 | FramingNgModule.prototype.frame = function () {
|
1828 | var framers = [];
|
1829 | for (var _a = 0; _a < arguments.length; _a++) {
|
1830 | framers[_a] = arguments[_a];
|
1831 | }
|
1832 | this.buildFramers(framers);
|
1833 | return this;
|
1834 | };
|
1835 | FramingNgModule.prototype.use = function () {
|
1836 | var framers = [];
|
1837 | for (var _a = 0; _a < arguments.length; _a++) {
|
1838 | framers[_a] = arguments[_a];
|
1839 | }
|
1840 | return this.frame.apply(this, framers);
|
1841 | };
|
1842 | |
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 | FramingNgModule.prototype.build = function () {
|
1849 | this.buildRouteFramers(this._routes);
|
1850 | this.buildRoot();
|
1851 | this.buildContainers(this._routes);
|
1852 | this.buildRoute();
|
1853 | this.inspectModule();
|
1854 | return this._ngModule;
|
1855 | };
|
1856 |
|
1857 |
|
1858 |
|
1859 | FramingNgModule.prototype.inspectModule = function () {
|
1860 | var _this = this;
|
1861 | this._routes.forEach(function (r) { return _this.inspectRoute(r); });
|
1862 | };
|
1863 | FramingNgModule.prototype.inspectRoute = function (route) {
|
1864 | var _this = this;
|
1865 | if (route.component === undefined && route.redirectTo === undefined && isEmpty(route.children) && route.loadChildren === undefined) {
|
1866 | console.error("Looks like you have a badly configured route in a framed module.\n One of the following must be provided: component, redirectTo, children or loadChildren", { route: route, self: this });
|
1867 | }
|
1868 | if (route.children) {
|
1869 | route.children.forEach(function (c) { return _this.inspectRoute(c); });
|
1870 | }
|
1871 | };
|
1872 | FramingNgModule.prototype.buildRoot = function () {
|
1873 | var m = this._ngModule;
|
1874 | if (this._root) {
|
1875 | m.imports = uniqWith(m.imports.concat([
|
1876 | BrowserModule.withServerTransition({
|
1877 | appId: 'app',
|
1878 | }),
|
1879 | FormsModule,
|
1880 | ]), isEqual);
|
1881 | m.bootstrap = uniqWith(m.bootstrap.concat([this._rootComponent]), isEqual);
|
1882 | }
|
1883 | else {
|
1884 | m.imports = uniqWith(m.imports.concat([
|
1885 | CommonModule,
|
1886 | ]), isEqual);
|
1887 | }
|
1888 | m.imports = uniqWith(m.imports.concat([FramingComponentsModule]), isEqual);
|
1889 | };
|
1890 | FramingNgModule.prototype.buildFramers = function (framers, route) {
|
1891 | for (var _a = 0, framers_1 = framers; _a < framers_1.length; _a++) {
|
1892 | var framer = framers_1[_a];
|
1893 | this.buildFramer(framer, route);
|
1894 | }
|
1895 | };
|
1896 | FramingNgModule.prototype.buildFramer = function (framer, route) {
|
1897 | if (!framer.framed) {
|
1898 | framer.runFraming(this, route || this.getRoute());
|
1899 | }
|
1900 | };
|
1901 | |
1902 |
|
1903 |
|
1904 | FramingNgModule.prototype.buildRouteFramers = function (routes) {
|
1905 | for (var _a = 0, routes_1 = routes; _a < routes_1.length; _a++) {
|
1906 | var route = routes_1[_a];
|
1907 | if (route.data) {
|
1908 | for (var key in route.data) {
|
1909 | if (route.data.hasOwnProperty(key)) {
|
1910 | var prop = route.data[key];
|
1911 | if (prop && prop._frame !== undefined) {
|
1912 |
|
1913 | this.buildFramer(prop, route);
|
1914 | }
|
1915 | }
|
1916 | }
|
1917 | }
|
1918 | if (route.children) {
|
1919 | this.buildRouteFramers(route.children);
|
1920 | }
|
1921 | }
|
1922 | };
|
1923 | FramingNgModule.prototype.buildContainers = function (routes) {
|
1924 | var _loop_2 = function (route) {
|
1925 | if (route.resolve && route.resolve.containers) {
|
1926 | var containers_2 = route.resolve.containers;
|
1927 | for (var _a = 0, containers_3 = containers_2; _a < containers_3.length; _a++) {
|
1928 | var container = containers_3[_a];
|
1929 | var containerId = FramingNgModule._nextId++;
|
1930 | container.id = '' + containerId;
|
1931 | }
|
1932 | var resolveId = FramingNgModule._nextId++;
|
1933 | this_2.provide({
|
1934 | provide: 'containerResolver' + resolveId,
|
1935 | useFactory: function (i) { return new FramingContainerOutletResolver(containers_2, i); },
|
1936 | deps: [Injector],
|
1937 | });
|
1938 | route.resolve.containers = 'containerResolver' + resolveId;
|
1939 | }
|
1940 | if (route.children) {
|
1941 | this_2.buildContainers(route.children);
|
1942 | }
|
1943 | };
|
1944 | var this_2 = this;
|
1945 | for (var _a = 0, routes_2 = routes; _a < routes_2.length; _a++) {
|
1946 | var route = routes_2[_a];
|
1947 | _loop_2(route);
|
1948 | }
|
1949 | };
|
1950 | FramingNgModule.prototype.buildRoute = function () {
|
1951 | var _this = this;
|
1952 | if (this._routes.length > 0) {
|
1953 |
|
1954 | var fullRoutes_1 = [];
|
1955 | var prefixRoutes_1 = [];
|
1956 | this._routes.forEach(function (route) {
|
1957 | if (route.pathMatch && route.pathMatch === 'full') {
|
1958 | fullRoutes_1.push(route);
|
1959 | }
|
1960 | else if (!route.pathMatch || route.pathMatch === 'prefix') {
|
1961 | prefixRoutes_1.push(route);
|
1962 | }
|
1963 | else {
|
1964 | console.warn('Unknown pathMatch on route', route);
|
1965 | }
|
1966 | _this._routes = [];
|
1967 | _this._routes = _this._routes.concat(fullRoutes_1);
|
1968 | _this._routes = _this._routes.concat(prefixRoutes_1);
|
1969 | });
|
1970 | var routing = this._root || (this._routeConfig && this._routeConfig.forRoot) ?
|
1971 | RouterModule.forRoot(this._routes, this._routeConfig ? this._routeConfig.extraRootRouterOptions : undefined) :
|
1972 | RouterModule.forChild(this._routes);
|
1973 | this.imports([routing]);
|
1974 | if (this._routeConfig && this._routeConfig.forRoot && !this._root) {
|
1975 | this.exports([RouterModule]);
|
1976 | }
|
1977 | }
|
1978 | };
|
1979 | FramingNgModule.prototype.getOrAddRouteOverload = function (route) {
|
1980 | if (isArray(route)) {
|
1981 | if (route.length) {
|
1982 | var result = void 0;
|
1983 |
|
1984 | result = this.getOrAddRoute(route[0]);
|
1985 | for (var i = 1; i < route.length; i++) {
|
1986 | if (!result.children) {
|
1987 | result.children = [];
|
1988 | }
|
1989 | result = this.getOrAddRoute(route[i], result.children);
|
1990 | }
|
1991 |
|
1992 | return result;
|
1993 | }
|
1994 | else {
|
1995 | return this.getOrAddRoute();
|
1996 | }
|
1997 | }
|
1998 | else {
|
1999 | return this.getOrAddRoute(route);
|
2000 | }
|
2001 | };
|
2002 | return FramingNgModule;
|
2003 | }());
|
2004 | FramingNgModule._nextId = 1;
|
2005 |
|
2006 | var Framing = function (ngModuleBuilder) {
|
2007 |
|
2008 | var framing = ngModuleBuilder(new FramingNgModule());
|
2009 | if (!framing) {
|
2010 | console.error('Framing must return a FramingNgModule');
|
2011 | return {};
|
2012 | }
|
2013 | return framing.build();
|
2014 | };
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 | var SimpleFramer = (function (_super) {
|
2020 | __extends(SimpleFramer, _super);
|
2021 | function SimpleFramer() {
|
2022 | return _super !== null && _super.apply(this, arguments) || this;
|
2023 | }
|
2024 | Object.defineProperty(SimpleFramer.prototype, "framerName", {
|
2025 | get: function () { return 'Simple'; },
|
2026 | enumerable: true,
|
2027 | configurable: true
|
2028 | });
|
2029 | Object.defineProperty(SimpleFramer.prototype, "createFrame", {
|
2030 | get: function () { return false; },
|
2031 | enumerable: true,
|
2032 | configurable: true
|
2033 | });
|
2034 | Object.defineProperty(SimpleFramer.prototype, "routeRule", {
|
2035 | get: function () { return 'none'; },
|
2036 | enumerable: true,
|
2037 | configurable: true
|
2038 | });
|
2039 | return SimpleFramer;
|
2040 | }(Framer));
|
2041 | export { FramingDevToolsComponent, FramingDevToolsController, FramingDevToolsFeature, Action, _createReduxDevtoolsExtension, FramingComponentOutletDirective, FramingComponentOutletModule, FramingContainerOutletDirective, FramingContainerOutletModule, FramingContainerOutletResolver, FramingContainerOutletService, FramingEmptyParentComponent, FramingComponentsModule, FramingRootComponent, Component$1 as Component, Controller, FramingTools, Frame, FramerHelper, Framer, FramingNgModule, Framing, SimpleFramer };
|
2042 |
|