@@ -315,81 +315,8 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
315315 $ this ->addScopedAttribute ($ node , $ level );
316316 }
317317
318- // Registered Component
319318 if (in_array ($ node ->nodeName , array_keys ($ this ->components ))) {
320- $ matchedComponent = $ this ->components [$ node ->nodeName ];
321- $ usedComponent = new Component ($ matchedComponent ->getName (), $ matchedComponent ->getPath ());
322-
323- if ($ node ->hasAttributes ()) {
324- /** @var DOMAttr $attribute */
325- foreach ($ node ->attributes as $ attribute ) {
326- if (strpos ($ attribute ->name , 'v-bind: ' ) === 0 || strpos ($ attribute ->name , ': ' ) === 0 ) {
327- $ name = substr ($ attribute ->name , strpos ($ attribute ->name , ': ' ) + 1 );
328- $ value = $ attribute ->value ;
329-
330- if (substr_count ($ value , '` ' )) {
331- $ value = $ this ->refactorTemplateString ($ attribute ->value );
332- } else {
333- $ value = $ this ->builder ->refactorCondition ($ value );
334- }
335-
336- $ usedComponent ->addProperty ($ name , $ value , true );
337- } else {
338- $ usedComponent ->addProperty ($ attribute ->name , '" ' . $ attribute ->value . '" ' , false );
339- }
340- }
341- }
342-
343- foreach (iterator_to_array ($ node ->childNodes ) as $ childNode ) {
344- $ this ->convertNode ($ childNode , $ level + 1 );
345- }
346-
347- // Slots
348- if ($ node ->hasChildNodes ()) {
349- $ this ->handleNamedSlotsInclude ($ node , $ usedComponent );
350- // Slots (Default)
351- if ($ node ->hasChildNodes () && !$ usedComponent ->hasSlot (Slot::SLOT_DEFAULT_NAME )) {
352- $ this ->addSlot (Slot::SLOT_DEFAULT_NAME , $ node , $ usedComponent );
353- }
354- } else {
355- $ usedComponent ->addEmptyDefaultSlot ();
356- }
357-
358- // Include Partial
359- $ include = $ this ->document ->createTextNode (
360- $ this ->builder ->createIncludePartial (
361- $ usedComponent ->getPath (),
362- $ this ->preparePropertiesForInclude ($ usedComponent ->getProperties (), $ level === 1 ),
363- $ this ->vBind
364- )
365- );
366-
367- $ node ->parentNode ->insertBefore ($ include , $ node );
368-
369- if ($ usedComponent ->hasSlots ()) {
370- foreach ($ usedComponent ->getSlots () as $ slotName => $ slot ) {
371- // Add variable which contains the content (set)
372- $ openSet = $ this ->document ->createTextNode (
373- $ this ->builder ->createSet ($ slot ->getSlotValueName ())
374- );
375- $ node ->parentNode ->insertBefore ($ openSet , $ include );
376-
377- $ setContent = $ this ->document ->createTextNode ($ slot ->getSlotContentVariableString ());
378-
379- $ node ->parentNode ->insertBefore ($ setContent , $ include );
380-
381- // Close variable (endset)
382- $ closeSet = $ this ->document ->createTextNode (
383- $ this ->builder ->closeSet ()
384- );
385- $ node ->parentNode ->insertBefore ($ closeSet , $ include );
386- }
387- }
388-
389- // Remove original node
390- $ this ->nodeHelper ->removeNode ($ node );
391-
392- return $ node ;
319+ return $ this ->handleComponent ($ node , $ level );
393320 }
394321
395322 if ($ node instanceof DOMElement) {
@@ -416,6 +343,83 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
416343 return $ node ;
417344 }
418345
346+ private function handleComponent (DOMNode $ node , int $ level ): DOMNode
347+ {
348+ $ matchedComponent = $ this ->components [$ node ->nodeName ];
349+ $ usedComponent = new Component ($ matchedComponent ->getName (), $ matchedComponent ->getPath ());
350+
351+ if ($ node ->hasAttributes ()) {
352+ /** @var DOMAttr $attribute */
353+ foreach ($ node ->attributes as $ attribute ) {
354+ if (strpos ($ attribute ->name , 'v-bind: ' ) === 0 || strpos ($ attribute ->name , ': ' ) === 0 ) {
355+ $ name = substr ($ attribute ->name , strpos ($ attribute ->name , ': ' ) + 1 );
356+ $ value = $ attribute ->value ;
357+
358+ if (substr_count ($ value , '` ' )) {
359+ $ value = $ this ->refactorTemplateString ($ attribute ->value );
360+ } else {
361+ $ value = $ this ->builder ->refactorCondition ($ value );
362+ }
363+
364+ $ usedComponent ->addProperty ($ name , $ value , true );
365+ } else {
366+ $ usedComponent ->addProperty ($ attribute ->name , '" ' . $ attribute ->value . '" ' , false );
367+ }
368+ }
369+ }
370+
371+ foreach (iterator_to_array ($ node ->childNodes ) as $ childNode ) {
372+ $ this ->convertNode ($ childNode , $ level + 1 );
373+ }
374+
375+ // Slots
376+ if ($ node ->hasChildNodes ()) {
377+ $ this ->handleNamedSlotsInclude ($ node , $ usedComponent );
378+ // Slots (Default)
379+ if ($ node ->hasChildNodes () && !$ usedComponent ->hasSlot (Slot::SLOT_DEFAULT_NAME )) {
380+ $ this ->addSlot (Slot::SLOT_DEFAULT_NAME , $ node , $ usedComponent );
381+ }
382+ } else {
383+ $ usedComponent ->addEmptyDefaultSlot ();
384+ }
385+
386+ // Include Partial
387+ $ include = $ this ->document ->createTextNode (
388+ $ this ->builder ->createIncludePartial (
389+ $ usedComponent ->getPath (),
390+ $ this ->preparePropertiesForInclude ($ usedComponent ->getProperties (), $ level === 1 ),
391+ $ this ->vBind
392+ )
393+ );
394+
395+ $ node ->parentNode ->insertBefore ($ include , $ node );
396+
397+ if ($ usedComponent ->hasSlots ()) {
398+ foreach ($ usedComponent ->getSlots () as $ slotName => $ slot ) {
399+ // Add variable which contains the content (set)
400+ $ openSet = $ this ->document ->createTextNode (
401+ $ this ->builder ->createSet ($ slot ->getSlotValueName ())
402+ );
403+ $ node ->parentNode ->insertBefore ($ openSet , $ include );
404+
405+ $ setContent = $ this ->document ->createTextNode ($ slot ->getSlotContentVariableString ());
406+
407+ $ node ->parentNode ->insertBefore ($ setContent , $ include );
408+
409+ // Close variable (endset)
410+ $ closeSet = $ this ->document ->createTextNode (
411+ $ this ->builder ->closeSet ()
412+ );
413+ $ node ->parentNode ->insertBefore ($ closeSet , $ include );
414+ }
415+ }
416+
417+ // Remove original node
418+ $ this ->nodeHelper ->removeNode ($ node );
419+
420+ return $ node ;
421+ }
422+
419423 /**
420424 * @param Property[] $variables
421425 *
@@ -1347,6 +1351,12 @@ protected function handleSlots(DOMElement $node): void
13471351 return ;
13481352 }
13491353
1354+ if ($ node ->hasChildNodes ()) {
1355+ foreach ($ node ->childNodes as $ childNode ) {
1356+ $ this ->convertNode ($ childNode );
1357+ }
1358+ }
1359+
13501360 $ slotFallback = $ node ->hasChildNodes () ? $ this ->innerHtmlOfNode ($ node ) : null ;
13511361
13521362 $ slotName = Slot::SLOT_PREFIX ;
0 commit comments