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