@@ -315,81 +315,8 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
315
315
$ this ->addScopedAttribute ($ node , $ level );
316
316
}
317
317
318
- // Registered Component
319
318
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 );
393
320
}
394
321
395
322
if ($ node instanceof DOMElement) {
@@ -416,6 +343,83 @@ public function convertNode(DOMNode $node, int $level = 0): DOMNode
416
343
return $ node ;
417
344
}
418
345
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
+
419
423
/**
420
424
* @param Property[] $variables
421
425
*
@@ -646,7 +650,14 @@ protected function replacePre(string $html): string
646
650
public function replaceShowWithIf (DOMElement $ node ): void
647
651
{
648
652
if ($ node ->hasAttribute ('v-show ' )) {
649
- $ node ->setAttribute ('v-if ' , $ node ->getAttribute ('v-show ' ));
653
+ if ($ node ->hasAttribute ('v-if ' )) {
654
+ $ node ->setAttribute (
655
+ 'v-if ' ,
656
+ '( ' . $ node ->getAttribute ('v-if ' ) . ') && ( ' . $ node ->getAttribute ('v-show ' ) . ') '
657
+ );
658
+ } else {
659
+ $ node ->setAttribute ('v-if ' , $ node ->getAttribute ('v-show ' ));
660
+ }
650
661
$ node ->removeAttribute ('v-show ' );
651
662
}
652
663
}
@@ -1340,6 +1351,12 @@ protected function handleSlots(DOMElement $node): void
1340
1351
return ;
1341
1352
}
1342
1353
1354
+ if ($ node ->hasChildNodes ()) {
1355
+ foreach ($ node ->childNodes as $ childNode ) {
1356
+ $ this ->convertNode ($ childNode );
1357
+ }
1358
+ }
1359
+
1343
1360
$ slotFallback = $ node ->hasChildNodes () ? $ this ->innerHtmlOfNode ($ node ) : null ;
1344
1361
1345
1362
$ slotName = Slot::SLOT_PREFIX ;
0 commit comments