@@ -20,7 +20,7 @@ export function compile(
20
20
innerHTML : '<div id="' + id + '"></div>' ,
21
21
} ) ;
22
22
document . body . appendChild ( ele ) ;
23
- if ( ! isExecute && typeof templateElement === "string" ) {
23
+ if ( ! isExecute && ( typeof templateElement === "string" || ( templateElement . prototype && templateElement . prototype . CSPTemplate && typeof templateElement === 'function' ) ) ) {
24
24
let vueSlot : any = getCurrentVueSlot ( context . vueInstance , templateElement , root ) ;
25
25
if ( vueSlot ) {
26
26
// Compilation for Vue 3 slot template
@@ -68,9 +68,18 @@ export function compile(
68
68
}
69
69
let tempRef : any ;
70
70
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
+ }
74
83
if ( templateCompRef . components ) {
75
84
let objkeys : any = Object . keys ( templateCompRef . components ) || [ ] ;
76
85
for ( let objstring of objkeys ) {
@@ -82,6 +91,14 @@ export function compile(
82
91
}
83
92
}
84
93
}
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
+ }
85
102
templateCompRef . data = function ( ) { return tempRef ; } ;
86
103
let app : any = Vue . createApp ( templateCompRef ) ;
87
104
if ( plugins ) {
@@ -94,7 +111,7 @@ export function compile(
94
111
app . mount ( "#" + pid ) ;
95
112
returnEle = ele . childNodes ;
96
113
detach ( ele ) ;
97
- } else if ( typeof templateElement === "string" ) {
114
+ } else if ( typeof templateElement === "string" || ( templateElement . prototype && templateElement . prototype . CSPTemplate && typeof templateElement === 'function' ) ) {
98
115
let vueSlot : any = getVueSlot ( context . vueInstance , templateElement , root ) ;
99
116
if ( vueSlot ) {
100
117
// Get provide values for Vue 2 slot template
@@ -140,6 +157,12 @@ export function compile(
140
157
if ( typeof templateFunction !== "function" ) {
141
158
templateFunction = Vue . extend ( templateFunction ) ;
142
159
}
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
+ }
143
166
let templateVue : any = new templateFunction ( dataObj ) ;
144
167
// let templateVue = new Vue(tempObj.template);
145
168
// templateVue.$data.data = extend(tempObj.data, data);
@@ -173,7 +196,7 @@ function getValues(app: any, cInstance: any, root: any): any {
173
196
return ;
174
197
}
175
198
// Get globally defined variables.
176
- let globalVariables : string [ ] = [ 'components' , 'mixins' , 'provides' ] ;
199
+ let globalVariables : string [ ] = [ 'components' , 'mixins' , 'provides' , 'directives' ] ;
177
200
for ( let i : number = 0 ; i < globalVariables . length ; i ++ ) {
178
201
let gVariable : string = globalVariables [ i ] ;
179
202
if ( app [ '_context' ] [ gVariable ] && vueInstance [ '$' ] [ 'appContext' ] [ gVariable ] ) {
@@ -258,6 +281,7 @@ function getChildVueSlot(slots: any, templateElement: any): any {
258
281
return slots ;
259
282
} else if ( slots && slots . default ) {
260
283
let childSlots : any = slots . default ( ) ;
284
+ childSlots = childSlots . flatMap ( ( item : any ) => Array . isArray ( item . children ) ? item . children : item ) ;
261
285
for ( let i : number = 0 ; i < childSlots . length ; i ++ ) {
262
286
let slot : any = getChildVueSlot ( childSlots [ parseInt ( i . toString ( ) , 10 ) ] . children , templateElement ) ;
263
287
if ( slot ) {
0 commit comments