@@ -15,7 +15,30 @@ export class WidgetResolver {
1515 const rootElement = xmlDoc . children [ 0 ] as parseXml . Element ;
1616 const rootElementAttrs = JSON . parse ( JSON . stringify ( rootElement . attributes ) ) ;
1717 const rootChild = this . getChildWidget ( rootElement ) ;
18- const rootChildWidget = this . resolveWidget ( rootChild , null ) ;
18+ let rootChildWidget = this . resolveWidget ( rootChild , null ) ;
19+
20+ // check for top-level properties, specially for <if>
21+ if ( rootChildWidget . isPropertyElement ) {
22+ const propertyHandler = this . propertyHandlerProvider . get ( rootChildWidget . propertyElement ) ;
23+ if ( propertyHandler && propertyHandler . canResolvePropertyElement ( ) ) {
24+ const childrenElements = rootElement . children . filter ( a => a . type === 'element' ) . map ( a => a as parseXml . Element ) ;
25+ const child = childrenElements . filter ( a => a . name === rootChildWidget . propertyElement ) [ 0 ] ;
26+ const widget = this . resolvePropertyElement ( rootChildWidget , rootElement , childrenElements , child ) ;
27+ if ( widget ) {
28+ rootChildWidget = {
29+ widget : widget ,
30+ isPropertyElement : false ,
31+ propertyElement : null ,
32+ propertyElementProperties : [ ]
33+ } ;
34+ }
35+ }
36+ // no need for now
37+ // else {
38+ // // this child is a property element <title>...</title>
39+ // this.addElementAsAttribute(rootElement, rootChildWidget);
40+ // }
41+ }
1942
2043 removeDuplicatedBuilders ( rootChildWidget . widget , null , 'wrappedWidgets' , { } ) ;
2144 this . callOnResolved ( rootChildWidget . widget ) ;
@@ -222,20 +245,9 @@ export class WidgetResolver {
222245 }
223246
224247 if ( childResult . isPropertyElement ) {
225- // check if we want to treat it as a custom element and not a property <if>...</if>
226- const propertyHandler = this . propertyHandlerProvider . get ( childResult . propertyElement ) ;
227- if ( propertyHandler && propertyHandler . canResolvePropertyElement ( ) ) {
228- const propertyElementWidget : WidgetModel | null = propertyHandler . resolvePropertyElement (
229- child , childResult , element , childrenElements ,
230- ( el , parent ) => this . resolveWidget ( el , parent ) ) ;
231- if ( propertyElementWidget ) {
232- childResult . isPropertyElement = false ;
233- childrenWidgets . push ( propertyElementWidget ) ;
234- }
235- }
236- else {
237- // this child is a property element <title>...</title>
238- this . addElementAsAttribute ( element , childResult ) ;
248+ const widget = this . resolvePropertyElement ( childResult , element , childrenElements , child ) ;
249+ if ( widget ) {
250+ childrenWidgets . push ( widget ) ;
239251 }
240252 }
241253 else {
@@ -262,6 +274,27 @@ export class WidgetResolver {
262274 }
263275 }
264276
277+ private resolvePropertyElement ( resolvedWidget : WidgetResolveResult ,
278+ parentElement : parseXml . Element , parentChildrenElements : parseXml . Element [ ] ,
279+ childElement : parseXml . Element ) : WidgetModel | null {
280+ // check if we want to treat it as a custom element and not a property <if>...</if>
281+ const propertyHandler = this . propertyHandlerProvider . get ( resolvedWidget . propertyElement ) ;
282+ if ( propertyHandler && propertyHandler . canResolvePropertyElement ( ) ) {
283+ const propertyElementWidget : WidgetModel | null = propertyHandler . resolvePropertyElement (
284+ childElement , resolvedWidget , parentElement , parentChildrenElements ,
285+ ( el , parent ) => this . resolveWidget ( el , parent ) ) ;
286+ if ( propertyElementWidget ) {
287+ resolvedWidget . isPropertyElement = false ;
288+ return propertyElementWidget ;
289+ }
290+ }
291+ else {
292+ // this child is a property element <title>...</title>
293+ this . addElementAsAttribute ( parentElement , resolvedWidget ) ;
294+ }
295+ return null ;
296+ }
297+
265298 private resolveContentChildData ( element : parseXml . Element , widget : WidgetModel ) {
266299 //e.g. <Text>content goes here</Text>
267300
0 commit comments