@@ -20,7 +20,7 @@ export function compile(
2020        innerHTML : '<div id="'  +  id  +  '"></div>' , 
2121      } ) ; 
2222      document . body . appendChild ( ele ) ; 
23-       if  ( ! isExecute  &&  typeof  templateElement  ===  "string" )  { 
23+       if  ( ! isExecute  &&  ( typeof  templateElement  ===  "string"   ||   ( templateElement . prototype   &&   templateElement . prototype . CSPTemplate   &&   typeof   templateElement   ===   'function' ) ) )  { 
2424        let  vueSlot : any  =  getCurrentVueSlot ( context . vueInstance ,  templateElement ,  root ) ; 
2525        if  ( vueSlot )  { 
2626          // Compilation for Vue 3 slot template 
@@ -68,9 +68,18 @@ export function compile(
6868        } 
6969        let  tempRef : any ; 
7070        if  ( propsData )  { 
71-           tempRef  =  ( < any > Object ) . assign ( templateCompRef . data ( ) ,  propsData ) ; 
72-         }  else  { 
73-           tempRef  =  ( < any > Object ) . assign ( templateCompRef . data ( ) ,  dataObj . data ) ; 
71+           if  ( templateCompRef . setup )  { 
72+             tempRef  =  ( < any > Object ) . assign ( templateCompRef . setup ( null ,  {  expose : function  ( )  { } } ) ,  propsData ) ; 
73+           }  else  { 
74+             tempRef  =  ( < any > Object ) . assign ( templateCompRef . data ( ) ,  propsData ) ; 
75+           } 
76+         } 
77+         else  { 
78+           if  ( templateCompRef . setup )  { 
79+             tempRef  =  ( < any > Object ) . assign ( templateCompRef . setup ( null ,  {  expose : function  ( )  { } } ) ,  dataObj . data ) ; 
80+           }  else  { 
81+             tempRef  =  ( < any > Object ) . assign ( templateCompRef . data ( ) ,  dataObj . data ) ; 
82+           } 
7483          if  ( templateCompRef . components )  { 
7584            let  objkeys : any  =  Object . keys ( templateCompRef . components )  ||  [ ] ; 
7685            for  ( let  objstring  of  objkeys )  { 
@@ -82,6 +91,14 @@ export function compile(
8291            } 
8392          } 
8493        } 
94+         if  ( templateCompRef . setup )  { 
95+           templateCompRef . setup  =  function  ( __props : any ,  {  expose : __expose  } : any )  { 
96+             __expose ( ) ; 
97+             const  __returned__  =  tempRef ; 
98+             Object . defineProperty ( __returned__ ,  '__isScriptSetup' ,  {  enumerable : false ,  value : true  } ) ; 
99+             return  __returned__ ; 
100+           } 
101+         } 
85102        templateCompRef . data  =  function  ( )  {  return  tempRef ;  } ; 
86103        let  app : any  =  Vue . createApp ( templateCompRef ) ; 
87104        if  ( plugins )  { 
@@ -94,7 +111,7 @@ export function compile(
94111        app . mount ( "#"  +  pid ) ; 
95112        returnEle  =  ele . childNodes ; 
96113        detach ( ele ) ; 
97-       }  else  if  ( typeof  templateElement  ===  "string" )  { 
114+       }  else  if  ( typeof  templateElement  ===  "string"   ||   ( templateElement . prototype   &&   templateElement . prototype . CSPTemplate   &&   typeof   templateElement   ===   'function' ) )  { 
98115        let  vueSlot : any  =  getVueSlot ( context . vueInstance ,  templateElement ,  root ) ; 
99116        if  ( vueSlot )  { 
100117          // Get provide values for Vue 2 slot template 
@@ -140,6 +157,12 @@ export function compile(
140157        if  ( typeof  templateFunction  !==  "function" )  { 
141158          templateFunction  =  Vue . extend ( templateFunction ) ; 
142159        } 
160+         if  ( templateFunction . options . setup )  { 
161+           var  variables : any  =  ( < any > Object ) . assign ( templateFunction . options . setup ( ) ,  dataObj . data ) ; 
162+           templateFunction . options . setup  =  function ( __props : any )  { 
163+             return  variables ; 
164+           } ; 
165+         } 
143166        let  templateVue : any  =  new  templateFunction ( dataObj ) ; 
144167        // let templateVue = new Vue(tempObj.template); 
145168        // templateVue.$data.data = extend(tempObj.data, data); 
@@ -173,7 +196,7 @@ function getValues(app: any, cInstance: any, root: any): any {
173196    return ; 
174197  } 
175198  // Get globally defined variables. 
176-   let  globalVariables : string [ ]  =  [ 'components' ,  'mixins' ,  'provides' ] ; 
199+   let  globalVariables : string [ ]  =  [ 'components' ,  'mixins' ,  'provides' ,   'directives' ] ; 
177200  for  ( let  i : number  =  0 ;  i  <  globalVariables . length ;  i ++ )  { 
178201    let  gVariable : string  =  globalVariables [ i ] ; 
179202    if  ( app [ '_context' ] [ gVariable ]  &&  vueInstance [ '$' ] [ 'appContext' ] [ gVariable ] )  { 
@@ -258,6 +281,7 @@ function getChildVueSlot(slots: any, templateElement: any): any {
258281    return  slots ; 
259282  }  else  if  ( slots  &&  slots . default )  { 
260283    let  childSlots : any  =  slots . default ( ) ; 
284+     childSlots  =  childSlots . flatMap ( ( item : any )  =>  Array . isArray ( item . children )  ? item . children  : item ) ; 
261285    for  ( let  i : number  =  0 ;  i  <  childSlots . length ;  i ++ )  { 
262286      let  slot : any  =  getChildVueSlot ( childSlots [ parseInt ( i . toString ( ) ,  10 ) ] . children ,  templateElement ) ; 
263287      if  ( slot )  { 
0 commit comments