1
1
import { isString } from "utils/types" ;
2
- import { View , AddChildFromBuilder } from "ui/core/view" ;
2
+ import { View } from "ui/core/view" ;
3
3
import { Placeholder } from "ui/placeholder" ;
4
4
import { ContentView } from 'ui/content-view' ;
5
5
import { LayoutBase } from 'ui/layouts/layout-base' ;
6
6
import { ViewClass , getViewClass , isKnownView } from './element-registry' ;
7
- import { ViewContainer } from './view-container' ;
8
7
import { getSpecialPropertySetter } from "ui/builder/special-properties" ;
9
8
10
9
//var console = {log: function(msg) {}}
@@ -18,83 +17,59 @@ export interface ViewExtensions {
18
17
export type NgView = View & ViewExtensions ;
19
18
export type NgLayoutBase = LayoutBase & ViewExtensions ;
20
19
export type NgContentView = ContentView & ViewExtensions ;
21
- export type NgAddChildFromBuilder = View & AddChildFromBuilder & ViewExtensions ;
22
20
23
- function isView ( view : any ) : view is NgView {
21
+ export function isView ( view : any ) : view is NgView {
24
22
return view instanceof View ;
25
23
}
26
24
27
- function isLayout ( view : any ) : view is NgLayoutBase {
25
+ export function isLayout ( view : any ) : view is NgLayoutBase {
28
26
return view instanceof LayoutBase ;
29
27
}
30
28
31
- function isContentView ( view : any ) : view is NgContentView {
29
+ export function isContentView ( view : any ) : view is NgContentView {
32
30
return view instanceof ContentView ;
33
31
}
34
32
35
- function hasBuilderHooks ( view : any ) : view is NgAddChildFromBuilder {
36
- return view . _addChildFromBuilder !== undefined ;
37
- }
38
-
39
- function isViewContainer ( view : any ) : view is ViewContainer {
40
- return view instanceof ViewContainer ;
41
- }
42
-
43
33
function isComplexProperty ( view : NgView ) {
44
34
const name = view . nodeName
45
35
return isString ( name ) && name . indexOf ( "." ) !== - 1 ;
46
36
}
47
37
48
38
export function insertChild ( parent : any , child : NgView , atIndex = - 1 ) {
49
- if ( child . nodeName === 'Switch' ) {
50
- console . log ( 'inserting switch into: ' + parent ) ;
51
- }
52
-
53
39
if ( isLayout ( parent ) ) {
54
40
if ( atIndex !== - 1 ) {
55
41
parent . insertChild ( child , atIndex ) ;
56
42
} else {
57
43
parent . addChild ( child ) ;
58
44
}
59
- } else if ( isViewContainer ( parent ) ) {
60
- parent . insertChild ( child , atIndex ) ;
61
45
} else if ( isContentView ( parent ) ) {
62
46
parent . content = child ;
63
- } else if ( hasBuilderHooks ( parent ) ) {
64
- parent . _addChildFromBuilder ( this . viewName , this . nativeView ) ;
65
47
} else {
66
- throw new Error ( "Parent can't contain children: " + parent . nodeName + ', ' + parent ) ;
67
- }
68
- if ( child instanceof ViewContainer ) {
69
- ( < ViewContainer > child ) . addedToView ( ) ;
48
+ //throw new Error("Parent can't contain children: " + parent.nodeName + ', ' + parent);
70
49
}
71
50
}
72
51
73
52
export function removeChild ( parent : any , child : NgView ) {
74
53
if ( isLayout ( parent ) ) {
75
54
parent . removeChild ( child ) ;
76
- } else if ( isViewContainer ( parent ) ) {
77
- parent . removeChild ( child ) ;
78
55
} else if ( isContentView ( parent ) ) {
79
56
if ( parent . content === child ) {
80
57
parent . content = null ;
81
58
}
82
59
} else if ( isView ( parent ) ) {
83
60
parent . _removeView ( child ) ;
84
61
} else {
85
- throw new Error ( 'Unknown parent type: ' + parent ) ;
62
+ // throw new Error('Unknown parent type: ' + parent);
86
63
}
87
64
}
88
65
89
66
export function getChildIndex ( parent : any , child : NgView ) {
90
67
if ( isLayout ( parent ) ) {
91
68
return parent . getChildIndex ( child ) ;
92
- } else if ( isViewContainer ( parent ) ) {
93
- return parent . getChildIndex ( child ) ;
94
69
} else if ( isContentView ( parent ) ) {
95
70
return child === parent . content ? 0 : - 1 ;
96
71
} else {
97
- throw new Error ( "Parent can't contain children: " + parent . nodeName + ', ' + parent ) ;
72
+ // throw new Error("Parent can't contain children: " + parent);
98
73
}
99
74
}
100
75
@@ -112,7 +87,7 @@ export function createView(name: string, parent: NgView): NgView {
112
87
const viewClass = getViewClass ( name ) ;
113
88
return createAndAttach ( name , viewClass , parent ) ;
114
89
} else {
115
- return createViewContainer ( parent ) ;
90
+ return createViewContainer ( name , parent ) ;
116
91
}
117
92
}
118
93
@@ -123,25 +98,20 @@ export function createText(value: string): NgView {
123
98
return text ;
124
99
}
125
100
126
- export function createTemplateContainer ( parsedNode : NgView ) {
127
- const parent = < NgView > parsedNode . parent ;
128
- const templateContainer = createView ( 'StackLayout' , parent ) ;
129
- //templateContainer.visibility = "collapse";
130
- return templateContainer ;
131
- }
132
-
133
- export function createViewContainer ( parentElement : NgView ) {
101
+ export function createViewContainer ( name : string , parentElement : NgView ) {
134
102
//HACK: Using a ContentView here, so that it creates a native View object
135
103
console . log ( 'Creating view container in:' + parentElement ) ;
136
- const anchor = createAndAttach ( 'ViewContainer' , ViewContainer , parentElement ) ;
137
- anchor . visibility = "collapse" ;
138
- return anchor ;
104
+
105
+ const layout = createView ( 'ProxyViewContainer' , parentElement ) ;
106
+ layout . nodeName = 'ProxyViewContainer' ;
107
+ return layout ;
139
108
}
140
109
141
110
export function createTemplateAnchor ( parentElement : NgView ) {
142
111
//HACK: Using a ContentView here, so that it creates a native View object
143
112
const anchor = createAndAttach ( 'ContentView' , ContentView , parentElement ) ;
144
113
anchor . visibility = "collapse" ;
114
+ anchor . templateParent = parentElement ;
145
115
return anchor ;
146
116
}
147
117
@@ -162,7 +132,7 @@ export function setProperty(view: NgView, attributeName: string, value: any): vo
162
132
let propMap = getProperties ( view ) ;
163
133
164
134
if ( attributeName === "class" ) {
165
- this . setClasses ( value ) ;
135
+ setClasses ( view , value ) ;
166
136
} else if ( isXMLAttribute ( attributeName ) ) {
167
137
view . _applyXmlAttribute ( attributeName , value ) ;
168
138
} else if ( specialSetter ) {
0 commit comments