@@ -21,7 +21,9 @@ class JSX {
21
21
'onChange ' => 0 ,
22
22
'onDblclick ' => 0 ,
23
23
'onClick ' => 0 ,
24
- 'value ' => 0
24
+ 'onSubmit ' => 0 ,
25
+ 'value ' => 0 ,
26
+ 'items ' => 0
25
27
];
26
28
27
29
private static function getName (string $ name , ReactJS $ react ): string {
@@ -32,7 +34,8 @@ private static function getName(string $name, ReactJS $react): string {
32
34
'classname ' => 'className ' ,
33
35
'onblur ' => 'onBlur ' ,
34
36
'onclick ' => 'onClick ' ,
35
- 'onchange ' => 'onChange '
37
+ 'onchange ' => 'onChange ' ,
38
+ 'onsubmit ' => 'onSubmit '
36
39
];
37
40
38
41
private static function cleanJSONFunctions (string $ json ): string {
@@ -74,32 +77,45 @@ private static function getChildrenStr(\DOMNode $root, ?ReactJS $react): string
74
77
$ children = [];
75
78
76
79
$ childNodes = $ root ->childNodes ;
77
-
80
+ $ open = null ;
78
81
for ($ i = 0 ; $ i < $ childNodes ->length ; $ i ++) {
79
82
$ child = $ childNodes ->item ($ i );
80
83
if ($ child ->nodeType == XML_TEXT_NODE ) {
81
84
$ v = \trim ($ child ->nodeValue );
82
85
if ($ v != null ) {
83
- $ parts = \preg_split ('@(\{.*?\})@ ' , $ v , null , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
84
- if (\count ($ parts ) > 0 ) {
85
- foreach ($ parts as $ ev ) {
86
- if (self ::hasBraces ($ ev )) {
87
- $ children [] = \substr ($ ev , 1 , - 1 );
88
- } elseif (\trim ($ ev ) != null ) {
89
- $ children [] = '" ' . $ ev . '" ' ;
90
- }
91
- }
92
- } else {
93
- $ children [] = "` $ v` " ;
94
- }
86
+ self ::parseTextNode ($ v , $ children , $ open );
95
87
}
96
88
} else {
97
- $ children [] = self ::nodeToJs ($ child , $ react );
89
+ if ($ open != '' ) {
90
+ $ open .= self ::nodeToJs ($ child , $ react );
91
+ } else {
92
+ $ children [] = self ::nodeToJs ($ child , $ react );
93
+ }
98
94
}
99
95
}
100
96
return (count ($ children ) > 0 ) ? (', ' . implode (', ' , $ children )) : '' ;
101
97
}
102
98
99
+ private static function parseTextNode (string $ v , array &$ children , ?string &$ open ) {
100
+ $ parts = \preg_split ('@(\{.*?\})@ ' , $ v , null , PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
101
+ if (\count ($ parts ) > 0 ) {
102
+ foreach ($ parts as $ ev ) {
103
+ if (self ::hasBraces ($ ev )) {
104
+ $ children [] = \substr ($ ev , 1 , - 1 );
105
+ } elseif (\substr ($ ev , 0 , 1 ) === '{ ' ) {
106
+ $ open = \substr ($ ev , 1 );
107
+ } elseif ($ open != '' && \substr ($ ev , - 1 ) === '} ' ) {
108
+ $ children [] = $ open . \substr ($ ev , 0 , - 1 );
109
+ $ open = '' ;
110
+ } elseif (\trim ($ ev ) != null ) {
111
+ $ children [] = '" ' . $ ev . '" ' ;
112
+ }
113
+ }
114
+ } else {
115
+ $ children [] = "` $ v` " ;
116
+ }
117
+ }
118
+
103
119
public static function toJs (string $ html , ?ReactJS $ react = null ): string {
104
120
\libxml_use_internal_errors (true );
105
121
$ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
0 commit comments