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