1
- const fs = require ( "fs" ) ;
2
- const { htmlProps, svgProps, voids, types, typesByElement, reserved } = require ( "./consts" ) ;
3
- const changeCase = require ( 'change-case' )
1
+ import fs from "fs" ;
2
+ import { htmlProps , svgElementAttributes , voids , types , typesByElement , reserved } from "./consts.js" ;
3
+ import * as changeCase from "change-case" ;
4
+
4
5
const htmlGenFile = "../src/React/Basic/DOM/Generated.purs" ;
5
6
const htmlSimplifiedGenFile = "../src/React/Basic/DOM/Simplified/Generated.purs" ;
6
7
const svgGenFile = "../src/React/Basic/DOM/SVG.purs" ;
@@ -25,7 +26,6 @@ import React.Basic.DOM.Internal (CSS, unsafeCreateDOMComponent)
25
26
import React.Basic.Events (EventHandler)
26
27
import Unsafe.Coerce (unsafeCoerce)
27
28
import Web.DOM (Node)
28
-
29
29
` ;
30
30
31
31
const simplifiedHtmlHeader = `${ warningHeader }
@@ -42,7 +42,6 @@ import React.Basic.Events (EventHandler)
42
42
import Record as Record
43
43
import Unsafe.Coerce (unsafeCoerce)
44
44
import Web.DOM (Node)
45
-
46
45
` ;
47
46
48
47
const propType = ( e , p ) => {
@@ -68,7 +67,6 @@ import React.Basic (JSX, ReactComponent, Ref, element)
68
67
import React.Basic.DOM.Internal (SharedSVGProps, unsafeCreateDOMComponent)
69
68
import Unsafe.Coerce (unsafeCoerce)
70
69
import Web.DOM (Node)
71
-
72
70
` ;
73
71
74
72
const ignoredSvgPropKeys = [
@@ -83,7 +81,7 @@ const ignoredSvgPropKeys = [
83
81
]
84
82
85
83
const camelCaseSvgProps = Object . fromEntries (
86
- Object . entries ( svgProps . svgElementAttributes )
84
+ Object . entries ( svgElementAttributes )
87
85
. filter ( ( [ elName ] ) => ! ignoredSvgPropKeys . includes ( elName ) ) // Exclude ignored keys
88
86
. map ( ( [ elName , attrs ] ) => [
89
87
elName ,
@@ -114,39 +112,38 @@ const generatePropTypes = (elements, props, sharedPropType) =>
114
112
const propType = sharedPropType ? `(${ sharedPropType } Props_${ e } )` : `Props_${ e } `
115
113
116
114
return `
117
- type Props_${ e } =${ printRecord ( e ,
118
- ( noChildren
119
- ? reactProps
120
- : reactProps . concat ( "children" )
121
- )
122
- . concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
123
- . sort ( )
124
- ) }
125
-
126
- ${ symbol }
127
- :: forall attrs attrs_
128
- . Union attrs attrs_ ${ propType }
129
- => Record attrs
130
- -> JSX
131
- ${ symbol } = element ${ symbol } '${
132
- noChildren
133
- ? ""
134
- : `
135
-
136
- ${ e } _ :: Array JSX -> JSX
137
- ${ e } _ children = ${ symbol } { children }`
138
- }
115
+ type Props_${ e } =${ printRecord ( e ,
116
+ ( noChildren
117
+ ? reactProps
118
+ : reactProps . concat ( "children" )
119
+ )
120
+ . concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
121
+ . sort ( )
122
+ ) }
123
+
124
+ ${ symbol }
125
+ :: forall attrs attrs_
126
+ . Union attrs attrs_ ${ propType }
127
+ => Record attrs
128
+ -> JSX
129
+ ${ symbol } = element ${ symbol } '${
130
+ noChildren
131
+ ? ""
132
+ : `
133
+
134
+ ${ e } _ :: Array JSX -> JSX
135
+ ${ e } _ children = ${ symbol } { children }`
136
+ }
139
137
140
- ${ symbol } '
141
- :: forall attrs attrs_
142
- . Union attrs attrs_ ${ propType }
143
- => ReactComponent (Record attrs)
144
- ${ symbol } ' = unsafeCoerce _${ e } '
138
+ ${ symbol } '
139
+ :: forall attrs attrs_
140
+ . Union attrs attrs_ ${ propType }
141
+ => ReactComponent (Record attrs)
142
+ ${ symbol } ' = unsafeCoerce _${ e } '
145
143
146
- _${ e } '
147
- :: ReactComponent (Record ${ propType } )
148
- _${ e } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ e } ")
149
- ` ;
144
+ _${ e } '
145
+ :: ReactComponent (Record ${ propType } )
146
+ _${ e } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ e } ")` ;
150
147
} ) . map ( x => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
151
148
. join ( "\n" ) ;
152
149
@@ -158,40 +155,39 @@ const generatePropTypes = (elements, props, sharedPropType) =>
158
155
const propType = sharedPropType ? `(${ sharedPropType } Props_${ e } )` : `Props_${ e } `
159
156
160
157
return noChildren ? `` : `
161
- type Props_${ e } =${ printRecord ( e ,
162
- ( reactProps . concat ( "children" )
163
- )
164
- . concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
165
- . sort ( )
166
- ) }
167
-
168
- ${ symbol }
169
- :: forall attrsNoChildren attrsWithDuplicate attrs attrs_ jsx
170
- . Union attrs attrs_ ${ propType }
171
- => ToJSX jsx
172
- => Union (children :: Array JSX) attrsNoChildren attrsWithDuplicate
173
- => Nub (children :: Array JSX | attrsNoChildren) attrs
174
- => Record attrsNoChildren
175
- -> jsx
176
- -> JSX
177
- ${ symbol } props children = element _internal${ symbol } propsWithChildren
178
- where
179
- propsWithChildren :: { | attrs }
180
- propsWithChildren = Record.merge { children: toJSX children } props
181
-
182
- ${ symbol } ' :: forall jsx. ToJSX jsx => jsx -> JSX
183
- ${ symbol } ' = ${ symbol } {}
184
-
185
- _internal${ symbol }
186
- :: forall attrs attrs_
187
- . Union attrs attrs_ ${ propType }
188
- => ReactComponent (Record attrs)
189
- _internal${ symbol } = unsafeCoerce _internal${ symbol } '
190
-
191
- _internal${ symbol } '
192
- :: ReactComponent (Record ${ propType } )
193
- _internal${ symbol } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ symbol } ")
194
-
158
+ type Props_${ e } =${ printRecord ( e ,
159
+ ( reactProps . concat ( "children" )
160
+ )
161
+ . concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
162
+ . sort ( )
163
+ ) }
164
+
165
+ ${ symbol }
166
+ :: forall attrsNoChildren attrsWithDuplicate attrs attrs_ jsx
167
+ . Union attrs attrs_ ${ propType }
168
+ => ToJSX jsx
169
+ => Union (children :: Array JSX) attrsNoChildren attrsWithDuplicate
170
+ => Nub (children :: Array JSX | attrsNoChildren) attrs
171
+ => Record attrsNoChildren
172
+ -> jsx
173
+ -> JSX
174
+ ${ symbol } props children = element _internal${ symbol } propsWithChildren
175
+ where
176
+ propsWithChildren :: { | attrs }
177
+ propsWithChildren = Record.merge { children: toJSX children } props
178
+
179
+ ${ symbol } ' :: forall jsx. ToJSX jsx => jsx -> JSX
180
+ ${ symbol } ' = ${ symbol } {}
181
+
182
+ _internal${ symbol }
183
+ :: forall attrs attrs_
184
+ . Union attrs attrs_ ${ propType }
185
+ => ReactComponent (Record attrs)
186
+ _internal${ symbol } = unsafeCoerce _internal${ symbol } '
187
+
188
+ _internal${ symbol } '
189
+ :: ReactComponent (Record ${ propType } )
190
+ _internal${ symbol } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ symbol } ")
195
191
` ;
196
192
} ) . map ( x => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
197
193
. join ( "\n" ) ;
@@ -201,12 +197,12 @@ const htmlSimplifiedTagTypes = generateSimplifiedPropTypes(htmlProps.elements.ht
201
197
const svgTagTypes = generatePropTypes ( Object . keys ( camelCaseSvgProps ) , camelCaseSvgProps , 'SharedSVGProps' ) ;
202
198
203
199
console . log ( `Writing "${ htmlGenFile } " ...` ) ;
204
- fs . writeFileSync ( htmlGenFile , htmlHeader + htmlTagTypes ) ;
200
+ fs . writeFileSync ( htmlGenFile , htmlHeader + htmlTagTypes + "\n" ) ;
205
201
206
202
console . log ( `Writing "${ htmlSimplifiedGenFile } " ...` ) ;
207
- fs . writeFileSync ( htmlSimplifiedGenFile , simplifiedHtmlHeader + htmlSimplifiedTagTypes ) ;
203
+ fs . writeFileSync ( htmlSimplifiedGenFile , simplifiedHtmlHeader + htmlSimplifiedTagTypes + "\n" ) ;
208
204
209
205
console . log ( `Writing "${ svgGenFile } " ...` ) ;
210
- fs . writeFileSync ( svgGenFile , svgHeader + svgTagTypes ) ;
206
+ fs . writeFileSync ( svgGenFile , svgHeader + svgTagTypes + "\n" ) ;
211
207
212
208
console . log ( "Done." ) ;
0 commit comments