44
55namespace Tempest \View \Elements ;
66
7- use DOMAttr ;
8- use DOMElement ;
9- use DOMNode ;
10- use DOMText ;
7+ use Dom \Element as DomElement ;
8+ use Dom \Node ;
9+ use Dom \Text ;
1110use Tempest \Container \Container ;
1211use function Tempest \Support \str ;
1312use Tempest \View \Element ;
@@ -32,17 +31,17 @@ public function setViewCompiler(TempestViewCompiler $compiler): self
3231 return $ this ;
3332 }
3433
35- public function make (DOMNode $ node ): ?Element
34+ public function make (Node $ node ): ?Element
3635 {
3736 return $ this ->makeElement (
3837 node: $ node ,
3938 parent: null ,
4039 );
4140 }
4241
43- private function makeElement (DOMNode $ node , ?Element $ parent ): ?Element
42+ private function makeElement (Node $ node , ?Element $ parent ): ?Element
4443 {
45- if ($ node instanceof DOMText ) {
44+ if ($ node instanceof Text ) {
4645 if (trim ($ node ->textContent ) === '' ) {
4746 return null ;
4847 }
@@ -52,31 +51,34 @@ private function makeElement(DOMNode $node, ?Element $parent): ?Element
5251 );
5352 }
5453
54+ $ tagName = $ node ->tagName ? strtolower ($ node ->tagName ) : null ;
55+
5556 $ attributes = [];
5657
57- /** @var DOMAttr $attribute */
58+ /** @var \Dom\Attr $attribute */
5859 foreach ($ node ->attributes ?? [] as $ attribute ) {
5960 $ name = str ($ attribute ->name )->camel ()->toString ();
6061
6162 $ attributes [$ name ] = $ attribute ->value ;
6263 }
6364
64- if (! $ node instanceof DOMElement
65- || $ node -> tagName === 'pre '
66- || $ node -> tagName === 'code ' ) {
65+ if (! $ node instanceof DomElement
66+ || $ tagName === 'pre '
67+ || $ tagName === 'code ' ) {
6768 $ content = '' ;
69+
6870 foreach ($ node ->childNodes as $ child ) {
6971 $ content .= $ node ->ownerDocument ->saveHTML ($ child );
7072 }
7173
7274 return new RawElement (
73- tag: $ node -> tagName ?? null ,
75+ tag: $ tagName ,
7476 content: $ content ,
7577 attributes: $ attributes ,
7678 );
7779 }
7880
79- if ($ viewComponentClass = $ this ->viewConfig ->viewComponents [$ node -> tagName ] ?? null ) {
81+ if ($ viewComponentClass = $ this ->viewConfig ->viewComponents [$ tagName ] ?? null ) {
8082 if (! $ viewComponentClass instanceof ViewComponent) {
8183 $ viewComponentClass = $ this ->container ->get ($ viewComponentClass );
8284 }
@@ -86,13 +88,13 @@ private function makeElement(DOMNode $node, ?Element $parent): ?Element
8688 $ viewComponentClass ,
8789 $ attributes ,
8890 );
89- } elseif ($ node -> tagName === 'x-slot ' ) {
91+ } elseif ($ tagName === 'x-slot ' ) {
9092 $ element = new SlotElement (
9193 name: $ node ->getAttribute ('name ' ) ?: 'slot ' ,
9294 );
9395 } else {
9496 $ element = new GenericElement (
95- tag: $ node -> tagName ,
97+ tag: $ tagName ,
9698 attributes: $ attributes ,
9799 );
98100 }
0 commit comments