@@ -2,6 +2,7 @@ const fs = require("fs");
22const { htmlProps, svgProps, voids, types, typesByElement, reserved } = require ( "./consts" ) ;
33const changeCase = require ( 'change-case' )
44const htmlGenFile = "../src/React/Basic/DOM/Generated.purs" ;
5+ const htmlSimplifiedGenFile = "../src/React/Basic/DOM/Simplified/Generated.purs" ;
56const svgGenFile = "../src/React/Basic/DOM/SVG.purs" ;
67
78const htmlHeader = `-- | ----------------------------------------
@@ -22,6 +23,26 @@ import Web.DOM (Node)
2223
2324` ;
2425
26+ const simplifiedHtmlHeader = `-- | ----------------------------------------
27+ -- | THIS FILE IS GENERATED -- DO NOT EDIT IT
28+ -- | ----------------------------------------
29+
30+ module React.Basic.DOM.Simplified.Generated where
31+
32+ import Data.Nullable (Nullable)
33+ import Effect.Unsafe (unsafePerformEffect)
34+ import Foreign.Object (Object)
35+ import Prim.Row (class Nub, class Union)
36+ import React.Basic (JSX, ReactComponent, Ref, element)
37+ import React.Basic.DOM.Internal (CSS, unsafeCreateDOMComponent)
38+ import React.Basic.DOM.Simplified.ToJSX (class ToJSX, toJSX)
39+ import React.Basic.Events (EventHandler)
40+ import Record as Record
41+ import Unsafe.Coerce (unsafeCoerce)
42+ import Web.DOM (Node)
43+
44+ ` ;
45+
2546const propType = ( e , p ) => {
2647 const elPropTypes = typesByElement [ p ] ;
2748 if ( elPropTypes ) {
@@ -127,15 +148,67 @@ const generatePropTypes = (elements, props, sharedPropType) =>
127148 _${ e } '
128149 :: ReactComponent (Record ${ propType } )
129150 _${ e } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ e } ")
151+ ` ;
152+ } ) . map ( x => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
153+ . join ( "\n" ) ;
154+
155+ const generateSimplifiedPropTypes = ( elements , props , sharedPropType ) =>
156+ elements . map ( e => {
157+ const noChildren = voids . includes ( e ) ;
158+ const symbol = reserved . includes ( e ) ? `${ e } '` : e ;
159+
160+ const propType = sharedPropType ? `(${ sharedPropType } Props_${ e } )` : `Props_${ e } `
161+
162+ return noChildren ? `` : `
163+ type Props_${ e } =${ printRecord ( e ,
164+ ( reactProps . concat ( "children" )
165+ )
166+ . concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
167+ . sort ( )
168+ ) }
169+
170+ ${ symbol }
171+ :: forall attrsNoChildren attrsWithDuplicate attrs attrs_ jsx
172+ . Union attrs attrs_ ${ propType }
173+ => ToJSX jsx
174+ => Union (children :: Array JSX) attrsNoChildren attrsWithDuplicate
175+ => Nub (children :: Array JSX | attrsNoChildren) attrs
176+ => Record attrsNoChildren
177+ -> jsx
178+ -> JSX
179+ ${ symbol } props children = element _internal${ symbol } propsWithChildren
180+ where
181+ propsWithChildren :: { | attrs }
182+ propsWithChildren = Record.merge { children: toJSX children } props
183+
184+ ${ symbol } ' :: forall jsx. ToJSX jsx => jsx -> JSX
185+ ${ symbol } ' = ${ symbol } {}
186+
187+ _internal${ symbol }
188+ :: forall attrs attrs_
189+ . Union attrs attrs_ ${ propType }
190+ => ReactComponent (Record attrs)
191+ _internal${ symbol } = unsafeCoerce _internal${ symbol } '
192+
193+ _internal${ symbol } '
194+ :: ReactComponent (Record ${ propType } )
195+ _internal${ symbol } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ symbol } ")
196+
130197` ;
131198 } ) . map ( x => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
132199 . join ( "\n" ) ;
133200
134201const htmlTagTypes = generatePropTypes ( htmlProps . elements . html , htmlProps , null ) ;
202+ const htmlSimplifiedTagTypes = generateSimplifiedPropTypes ( htmlProps . elements . html , htmlProps , null ) ;
135203const svgTagTypes = generatePropTypes ( Object . keys ( camelCaseSvgProps ) , camelCaseSvgProps , 'SharedSVGProps' ) ;
136204
137205console . log ( `Writing "${ htmlGenFile } " ...` ) ;
138206fs . writeFileSync ( htmlGenFile , htmlHeader + htmlTagTypes ) ;
207+
208+ console . log ( `Writing "${ htmlSimplifiedGenFile } " ...` ) ;
209+ fs . writeFileSync ( htmlSimplifiedGenFile , simplifiedHtmlHeader + htmlSimplifiedTagTypes ) ;
210+
139211console . log ( `Writing "${ svgGenFile } " ...` ) ;
140212fs . writeFileSync ( svgGenFile , svgHeader + svgTagTypes ) ;
213+
141214console . log ( "Done." ) ;
0 commit comments