1
1
"use strict" ;
2
2
3
3
var React = require ( "react" ) ;
4
+ var createElement = React . createElement ;
4
5
var Fragment = React . Fragment || "div" ;
5
6
6
7
exports . createComponent = ( function ( ) {
@@ -160,20 +161,36 @@ exports.make = function(_unionDict) {
160
161
exports . empty = null ;
161
162
162
163
exports . keyed_ = function ( key , child ) {
163
- return React . createElement ( Fragment , { key : key } , child ) ;
164
+ return createElement ( Fragment , { key : key } , child ) ;
164
165
} ;
165
166
166
- exports . element_ = function ( component , props ) {
167
- return React . createElement . apply (
167
+ function flattenDataProp ( component , props ) {
168
+ var data = null ;
169
+ if ( typeof component === "string" && props . _data != null ) {
170
+ data = { _data : undefined } ;
171
+ Object . entries ( props . _data ) . forEach ( function ( entry ) {
172
+ data [ "data-" + entry [ 0 ] ] = entry [ 1 ] ;
173
+ } ) ;
174
+ }
175
+ return data == null ? props : Object . assign ( { } , props , data ) ;
176
+ }
177
+
178
+ exports . element_ = function ( component , props , areChildrenDynamic ) {
179
+ var args = [ component , flattenDataProp ( component , props ) ] ;
180
+ return createElement . apply (
168
181
null ,
169
- [ component , props ] . concat ( ( props && props . children ) || null )
182
+ areChildrenDynamic || props . children == null
183
+ ? args
184
+ : args . concat ( props . children )
170
185
) ;
171
186
} ;
172
187
173
- exports . elementKeyed_ = exports . element_ ;
188
+ exports . elementKeyed_ = function ( component , props ) {
189
+ return exports . element_ ( component , props , true ) ;
190
+ } ;
174
191
175
192
exports . fragment = function ( children ) {
176
- return React . createElement . apply ( null , [ Fragment , { } ] . concat ( children ) ) ;
193
+ return createElement . apply ( null , [ Fragment , null ] . concat ( children ) ) ;
177
194
} ;
178
195
179
196
exports . displayNameFromComponent = function ( $$type ) {
@@ -210,7 +227,7 @@ exports.toReactComponent = function(_unionDict) {
210
227
$$props : fromJSProps ( this . props ) ,
211
228
$$spec : $$specPadded
212
229
} ;
213
- return React . createElement ( $$type , props ) ;
230
+ return createElement ( $$type , props ) ;
214
231
} ;
215
232
216
233
return Component ;
@@ -220,7 +237,7 @@ exports.toReactComponent = function(_unionDict) {
220
237
} ;
221
238
222
239
exports . createContext = function ( defaultValue ) {
223
- return function ( ) {
240
+ return function ( ) {
224
241
return React . createContext ( defaultValue ) ;
225
242
} ;
226
243
} ;
0 commit comments