1
1
const fs = require ( "fs" ) ;
2
- const { htmlProps, svgProps, voids, types, typesByElement, reserved } = require ( "./consts" ) ;
3
- const changeCase = require ( 'change-case' )
2
+ const {
3
+ htmlProps,
4
+ svgProps,
5
+ voids,
6
+ types,
7
+ typesByElement,
8
+ reserved
9
+ } = require ( "./consts" ) ;
10
+ const changeCase = require ( "change-case" ) ;
4
11
const htmlGenFile = "../src/React/Basic/DOM/Generated.purs" ;
5
- const htmlSimplifiedGenFile = "../src/React/Basic/DOM/Simplified/Generated.purs" ;
12
+ const htmlSimplifiedGenFile =
13
+ "../src/React/Basic/DOM/Simplified/Generated.purs" ;
6
14
const svgGenFile = "../src/React/Basic/DOM/SVG.purs" ;
7
15
8
16
const warningHeader = `-- | ------------------------------------------------------------
@@ -55,7 +63,7 @@ const propType = (e, p) => {
55
63
} else {
56
64
return types [ p ] || "String" ;
57
65
}
58
- }
66
+ } ;
59
67
60
68
const svgHeader = `${ warningHeader }
61
69
module React.Basic.DOM.SVG where
@@ -65,29 +73,45 @@ import Effect.Unsafe (unsafePerformEffect)
65
73
import Foreign.Object (Object)
66
74
import Prim.Row (class Union)
67
75
import React.Basic (JSX, ReactComponent, Ref, element)
68
- import React.Basic.DOM.Internal (SharedSVGProps, unsafeCreateDOMComponent)
76
+ import React.Basic.DOM.Internal (SharedSVGProps, unsafeCreateDOMComponent, CSS )
69
77
import Unsafe.Coerce (unsafeCoerce)
70
78
import Web.DOM (Node)
71
79
72
80
` ;
73
81
74
82
const ignoredSvgPropKeys = [
75
- '*' , 'elements' ,
83
+ "*" ,
84
+ "elements" ,
76
85
// These are all deprecated according to MDN, and I'm not sure what the
77
86
// React representation should be for the hyphenated ones if they are
78
87
// supported all, so let's exclude them
79
- "font" , "glyph" , "hkern" , "missing-glyph" , "vkern" ,
80
- "font-face" , "font-face-format" , "font-face-name" , "font-face-src" , "font-face-uri" ,
81
- "altGlyph" , "altGlyphDef" , "altGlyphItem" , "glyphRef" ,
82
- "tref" , "color-profile" , "cursor" ,
83
- ]
84
-
85
- const camelCaseSvgProps = { }
86
- Object . keys ( svgProps ) . forEach ( elName => {
88
+ "font" ,
89
+ "glyph" ,
90
+ "hkern" ,
91
+ "missing-glyph" ,
92
+ "vkern" ,
93
+ "font-face" ,
94
+ "font-face-format" ,
95
+ "font-face-name" ,
96
+ "font-face-src" ,
97
+ "font-face-uri" ,
98
+ "altGlyph" ,
99
+ "altGlyphDef" ,
100
+ "altGlyphItem" ,
101
+ "glyphRef" ,
102
+ "tref" ,
103
+ "color-profile" ,
104
+ "cursor"
105
+ ] ;
106
+
107
+ console . log ( svgProps ) ;
108
+ const camelCaseSvgProps = { } ;
109
+ Object . keys ( svgProps ) . forEach ( ( elName ) => {
87
110
if ( ! ignoredSvgPropKeys . includes ( elName ) ) {
88
- const elAttrs = svgProps [ elName ] . map ( changeCase . camelCase ) ;
111
+ console . log ( svgProps [ elName ] ) ;
112
+ const elAttrs = svgProps [ elName ] [ "*" ] . map ( changeCase . camelCase ) ;
89
113
// style is already included in SharedSVGProps
90
- delete elAttrs [ ' style' ] ;
114
+ delete elAttrs [ " style" ] ;
91
115
camelCaseSvgProps [ elName ] = elAttrs ;
92
116
}
93
117
} ) ;
@@ -101,25 +125,26 @@ delete htmlProps["svg"];
101
125
const printRecord = ( e , elProps ) =>
102
126
elProps . length
103
127
? `
104
- ( ${ elProps . map ( p => `${ p } :: ${ propType ( e , p ) } ` ) . join ( "\n , " ) }
128
+ ( ${ elProps . map ( ( p ) => `${ p } :: ${ propType ( e , p ) } ` ) . join ( "\n , " ) }
105
129
)`
106
130
: "()" ;
107
131
108
132
const reactProps = [ "ref" , "key" , "_data" , "_aria" ] ;
109
133
110
134
const generatePropTypes = ( elements , props , sharedPropType ) =>
111
- elements . map ( e => {
112
- const noChildren = voids . includes ( e ) ;
113
- const symbol = reserved . includes ( e ) ? `${ e } '` : e ;
114
-
115
- const propType = sharedPropType ? `(${ sharedPropType } Props_${ e } )` : `Props_${ e } `
116
-
117
- return `
118
- type Props_${ e } =${ printRecord ( e ,
119
- ( noChildren
120
- ? reactProps
121
- : reactProps . concat ( "children" )
122
- )
135
+ elements
136
+ . map ( ( e ) => {
137
+ const noChildren = voids . includes ( e ) ;
138
+ const symbol = reserved . includes ( e ) ? `${ e } '` : e ;
139
+
140
+ const propType = sharedPropType
141
+ ? `(${ sharedPropType } Props_${ e } )`
142
+ : `Props_${ e } ` ;
143
+
144
+ return `
145
+ type Props_${ e } =${ printRecord (
146
+ e ,
147
+ ( noChildren ? reactProps : reactProps . concat ( "children" ) )
123
148
. concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
124
149
. sort ( )
125
150
) }
@@ -148,20 +173,27 @@ const generatePropTypes = (elements, props, sharedPropType) =>
148
173
:: ReactComponent (Record ${ propType } )
149
174
_${ e } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ e } ")
150
175
` ;
151
- } ) . map ( x => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
152
- . join ( "\n" ) ;
153
-
154
- const generateSimplifiedPropTypes = ( elements , props , sharedPropType ) =>
155
- elements . map ( e => {
156
- const noChildren = voids . includes ( e ) ;
157
- const symbol = reserved . includes ( e ) ? `${ e } '` : e ;
158
-
159
- const propType = sharedPropType ? `(${ sharedPropType } Props_${ e } )` : `Props_${ e } `
160
-
161
- return noChildren ? `` : `
162
- type Props_${ e } =${ printRecord ( e ,
163
- ( reactProps . concat ( "children" )
164
- )
176
+ } )
177
+ . map ( ( x ) => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
178
+ . join ( "\n" ) ;
179
+
180
+ const generateSimplifiedPropTypes = ( elements , props , sharedPropType ) =>
181
+ elements
182
+ . map ( ( e ) => {
183
+ const noChildren = voids . includes ( e ) ;
184
+ const symbol = reserved . includes ( e ) ? `${ e } '` : e ;
185
+
186
+ const propType = sharedPropType
187
+ ? `(${ sharedPropType } Props_${ e } )`
188
+ : `Props_${ e } ` ;
189
+
190
+ return noChildren
191
+ ? ``
192
+ : `
193
+ type Props_${ e } =${ printRecord (
194
+ e ,
195
+ reactProps
196
+ . concat ( "children" )
165
197
. concat ( props [ e ] || [ ] , props [ "*" ] || [ ] )
166
198
. sort ( )
167
199
) }
@@ -194,20 +226,36 @@ const generatePropTypes = (elements, props, sharedPropType) =>
194
226
_internal${ symbol } ' = unsafePerformEffect (unsafeCreateDOMComponent "${ symbol } ")
195
227
196
228
` ;
197
- } ) . map ( x => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
198
- . join ( "\n" ) ;
199
-
200
- const htmlTagTypes = generatePropTypes ( htmlProps . elements . html , htmlProps , null ) ;
201
- const htmlSimplifiedTagTypes = generateSimplifiedPropTypes ( htmlProps . elements . html , htmlProps , null ) ;
202
- const svgTagTypes = generatePropTypes ( Object . keys ( camelCaseSvgProps ) , camelCaseSvgProps , 'SharedSVGProps' ) ;
229
+ } )
230
+ . map ( ( x ) => x . replace ( / ^ \n \ { 4 } / , "" ) . replace ( / \n \ { 4 } / g, "\n" ) )
231
+ . join ( "\n" ) ;
232
+
233
+ const htmlTagTypes = generatePropTypes (
234
+ htmlProps . elements . html ,
235
+ htmlProps ,
236
+ null
237
+ ) ;
238
+ const htmlSimplifiedTagTypes = generateSimplifiedPropTypes (
239
+ htmlProps . elements . html ,
240
+ htmlProps ,
241
+ null
242
+ ) ;
243
+ const svgTagTypes = generatePropTypes (
244
+ Object . keys ( camelCaseSvgProps ) ,
245
+ camelCaseSvgProps ,
246
+ "SharedSVGProps"
247
+ ) ;
203
248
204
249
console . log ( `Writing "${ htmlGenFile } " ...` ) ;
205
250
fs . writeFileSync ( htmlGenFile , htmlHeader + htmlTagTypes ) ;
206
251
207
252
console . log ( `Writing "${ htmlSimplifiedGenFile } " ...` ) ;
208
- fs . writeFileSync ( htmlSimplifiedGenFile , simplifiedHtmlHeader + htmlSimplifiedTagTypes ) ;
253
+ fs . writeFileSync (
254
+ htmlSimplifiedGenFile ,
255
+ simplifiedHtmlHeader + htmlSimplifiedTagTypes
256
+ ) ;
209
257
210
258
console . log ( `Writing "${ svgGenFile } " ...` ) ;
211
259
fs . writeFileSync ( svgGenFile , svgHeader + svgTagTypes ) ;
212
260
213
- console . log ( "Done." ) ;
261
+ console . log ( "Done." ) ;
0 commit comments