1 | import { isArray, isPresent } from '../util/util';
|
2 | import { ViewController, isViewController } from './view-controller';
|
3 | export function getComponent(linker, nameOrPageOrView, params) {
|
4 | if (typeof nameOrPageOrView === 'function') {
|
5 | return Promise.resolve(new ViewController(nameOrPageOrView, params));
|
6 | }
|
7 | if (typeof nameOrPageOrView === 'string') {
|
8 | return linker.getComponentFromName(nameOrPageOrView).then(function (component) {
|
9 | var vc = new ViewController(component, params);
|
10 | vc.id = nameOrPageOrView;
|
11 | return vc;
|
12 | });
|
13 | }
|
14 | return Promise.resolve(null);
|
15 | }
|
16 | export function convertToView(linker, nameOrPageOrView, params) {
|
17 | if (nameOrPageOrView) {
|
18 | if (isViewController(nameOrPageOrView)) {
|
19 |
|
20 | return Promise.resolve(nameOrPageOrView);
|
21 | }
|
22 | return getComponent(linker, nameOrPageOrView, params);
|
23 | }
|
24 | return Promise.resolve(null);
|
25 | }
|
26 | export function convertToViews(linker, pages) {
|
27 | var views = [];
|
28 | if (isArray(pages)) {
|
29 | for (var i = 0; i < pages.length; i++) {
|
30 | var page = pages[i];
|
31 | if (page) {
|
32 | if (isViewController(page)) {
|
33 | views.push(page);
|
34 | }
|
35 | else if (page.page) {
|
36 | views.push(convertToView(linker, page.page, page.params));
|
37 | }
|
38 | else {
|
39 | views.push(convertToView(linker, page, null));
|
40 | }
|
41 | }
|
42 | }
|
43 | }
|
44 | return Promise.all(views);
|
45 | }
|
46 | var portalZindex = 9999;
|
47 | export function setZIndex(nav, enteringView, leavingView, direction, renderer) {
|
48 | if (enteringView) {
|
49 | if (nav._isPortal) {
|
50 | if (direction === DIRECTION_FORWARD) {
|
51 | enteringView._setZIndex(nav._zIndexOffset + portalZindex, renderer);
|
52 | }
|
53 | portalZindex++;
|
54 | return;
|
55 | }
|
56 | leavingView = leavingView || nav.getPrevious(enteringView);
|
57 | if (leavingView && isPresent(leavingView._zIndex)) {
|
58 | if (direction === DIRECTION_BACK) {
|
59 | enteringView._setZIndex(leavingView._zIndex - 1, renderer);
|
60 | }
|
61 | else {
|
62 | enteringView._setZIndex(leavingView._zIndex + 1, renderer);
|
63 | }
|
64 | }
|
65 | else {
|
66 | enteringView._setZIndex(INIT_ZINDEX + nav._zIndexOffset, renderer);
|
67 | }
|
68 | }
|
69 | }
|
70 | export function isTabs(nav) {
|
71 |
|
72 | return !!nav && !!nav.getSelected;
|
73 | }
|
74 | export function isTab(nav) {
|
75 |
|
76 | return !!nav && isPresent(nav._tabId);
|
77 | }
|
78 | export function isNav(nav) {
|
79 |
|
80 | return !!nav && !!nav.push && nav.getType() === 'nav';
|
81 | }
|
82 | export function linkToSegment(navId, type, secondaryId, link) {
|
83 | var segment = Object.assign({}, link);
|
84 | segment.navId = navId;
|
85 | segment.type = type;
|
86 | segment.secondaryId = secondaryId;
|
87 | return segment;
|
88 | }
|
89 |
|
90 |
|
91 |
|
92 | var DeepLinkMetadata = (function () {
|
93 | function DeepLinkMetadata() {
|
94 | }
|
95 | return DeepLinkMetadata;
|
96 | }());
|
97 | export { DeepLinkMetadata };
|
98 |
|
99 |
|
100 |
|
101 | export var DeepLinkMetadataFactory;
|
102 | export var STATE_NEW = 1;
|
103 | export var STATE_INITIALIZED = 2;
|
104 | export var STATE_ATTACHED = 3;
|
105 | export var STATE_DESTROYED = 4;
|
106 | export var INIT_ZINDEX = 100;
|
107 | export var DIRECTION_BACK = 'back';
|
108 | export var DIRECTION_FORWARD = 'forward';
|
109 | export var DIRECTION_SWITCH = 'switch';
|
110 | export var NAV = 'nav';
|
111 | export var TABS = 'tabs';
|
112 |
|
\ | No newline at end of file |