@@ -321,15 +321,58 @@ export class VueElement extends BaseClass {
321
321
// replace slot
322
322
if ( ! this . _config . shadowRoot ) {
323
323
this . _slots = { } ;
324
- for ( const child of Array . from ( this . children ) ) {
325
- const slotName = child . getAttribute ( 'slot' ) || 'default' ;
324
+
325
+ const processChildNodes = ( nodes : NodeList ) : ( VNode | string ) [ ] => {
326
+ return Array . from ( nodes )
327
+ . map ( ( node ) : VNode | string | null => {
328
+ if ( node . nodeType === Node . ELEMENT_NODE ) {
329
+ const element = node as HTMLElement ;
330
+ const attributes = Object . fromEntries (
331
+ Array . from ( element . attributes ) . map ( ( attr ) => [ attr . name , attr . value ] )
332
+ ) ;
333
+ return h (
334
+ element . tagName . toLowerCase ( ) ,
335
+ attributes ,
336
+ processChildNodes ( element . childNodes )
337
+ ) ;
338
+ } else if ( node . nodeType === Node . TEXT_NODE ) {
339
+ return node . textContent ?. trim ( ) || null ;
340
+ }
341
+ return null ;
342
+ } )
343
+ . filter ( ( node ) : node is VNode | string => node != null ) ;
344
+ } ;
345
+
346
+ for ( const child of Array . from ( this . childNodes ) ) {
347
+ const slotName = child . nodeType === Node . ELEMENT_NODE
348
+ ? ( child as HTMLElement ) . getAttribute ( 'slot' ) || 'default'
349
+ : 'default' ;
350
+
326
351
if ( ! this . _slots [ slotName ] ) {
327
352
this . _slots [ slotName ] = [ ] ;
328
353
}
329
- this . _slots [ slotName ] . push (
330
- h ( child . tagName . toLowerCase ( ) , { } , child . innerHTML )
331
- ) ;
354
+
355
+ if ( child . nodeType === Node . ELEMENT_NODE ) {
356
+ const element = child as HTMLElement ;
357
+ const attributes = Object . fromEntries (
358
+ Array . from ( element . attributes ) . map ( ( attr ) => [ attr . name , attr . value ] )
359
+ ) ;
360
+ this . _slots [ slotName ] . push (
361
+ h (
362
+ element . tagName . toLowerCase ( ) ,
363
+ attributes ,
364
+ processChildNodes ( element . childNodes )
365
+ )
366
+ ) ;
367
+ } else if ( child . nodeType === Node . TEXT_NODE ) {
368
+ const textContent = child . textContent ?. trim ( ) ;
369
+ if ( textContent ) {
370
+ // @ts -ignore
371
+ this . _slots [ slotName ] . push ( textContent ) ;
372
+ }
373
+ }
332
374
}
375
+
333
376
this . replaceChildren ( ) ;
334
377
}
335
378
0 commit comments