Skip to content

Commit a7ac89e

Browse files
committed
feat: update to spago@next
1 parent a0ed953 commit a7ac89e

21 files changed

+2730
-13658
lines changed

bower.json

-32
This file was deleted.

codegen/index.js

+99-51
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
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");
411
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";
614
const svgGenFile = "../src/React/Basic/DOM/SVG.purs";
715

816
const warningHeader = `-- | ------------------------------------------------------------
@@ -55,7 +63,7 @@ const propType = (e, p) => {
5563
} else {
5664
return types[p] || "String";
5765
}
58-
}
66+
};
5967

6068
const svgHeader = `${warningHeader}
6169
module React.Basic.DOM.SVG where
@@ -65,29 +73,45 @@ import Effect.Unsafe (unsafePerformEffect)
6573
import Foreign.Object (Object)
6674
import Prim.Row (class Union)
6775
import React.Basic (JSX, ReactComponent, Ref, element)
68-
import React.Basic.DOM.Internal (SharedSVGProps, unsafeCreateDOMComponent)
76+
import React.Basic.DOM.Internal (SharedSVGProps, unsafeCreateDOMComponent, CSS)
6977
import Unsafe.Coerce (unsafeCoerce)
7078
import Web.DOM (Node)
7179
7280
`;
7381

7482
const ignoredSvgPropKeys = [
75-
'*', 'elements',
83+
"*",
84+
"elements",
7685
// These are all deprecated according to MDN, and I'm not sure what the
7786
// React representation should be for the hyphenated ones if they are
7887
// 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) => {
87110
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);
89113
// style is already included in SharedSVGProps
90-
delete elAttrs['style'];
114+
delete elAttrs["style"];
91115
camelCaseSvgProps[elName] = elAttrs;
92116
}
93117
});
@@ -101,25 +125,26 @@ delete htmlProps["svg"];
101125
const printRecord = (e, elProps) =>
102126
elProps.length
103127
? `
104-
( ${elProps.map(p => `${p} :: ${propType(e, p)}`).join("\n , ")}
128+
( ${elProps.map((p) => `${p} :: ${propType(e, p)}`).join("\n , ")}
105129
)`
106130
: "()";
107131

108132
const reactProps = ["ref", "key", "_data", "_aria"];
109133

110134
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"))
123148
.concat(props[e] || [], props["*"] || [])
124149
.sort()
125150
)}
@@ -148,20 +173,27 @@ const generatePropTypes = (elements, props, sharedPropType) =>
148173
:: ReactComponent (Record ${propType})
149174
_${e}' = unsafePerformEffect (unsafeCreateDOMComponent "${e}")
150175
`;
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")
165197
.concat(props[e] || [], props["*"] || [])
166198
.sort()
167199
)}
@@ -194,20 +226,36 @@ const generatePropTypes = (elements, props, sharedPropType) =>
194226
_internal${symbol}' = unsafePerformEffect (unsafeCreateDOMComponent "${symbol}")
195227
196228
`;
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+
);
203248

204249
console.log(`Writing "${htmlGenFile}" ...`);
205250
fs.writeFileSync(htmlGenFile, htmlHeader + htmlTagTypes);
206251

207252
console.log(`Writing "${htmlSimplifiedGenFile}" ...`);
208-
fs.writeFileSync(htmlSimplifiedGenFile, simplifiedHtmlHeader + htmlSimplifiedTagTypes);
253+
fs.writeFileSync(
254+
htmlSimplifiedGenFile,
255+
simplifiedHtmlHeader + htmlSimplifiedTagTypes
256+
);
209257

210258
console.log(`Writing "${svgGenFile}" ...`);
211259
fs.writeFileSync(svgGenFile, svgHeader + svgTagTypes);
212260

213-
console.log("Done.");
261+
console.log("Done.");

codegen/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"author": "",
77
"dependencies": {
88
"react-html-attributes": "^1.4.6",
9-
"change-case": "^3.1.0",
10-
"svg-element-attributes": "^1.3.0"
9+
"change-case": "^5.4.4",
10+
"svg-element-attributes": "^2.1.0"
1111
}
1212
}

flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
};
3232
}
3333
);
34-
}
34+
}

0 commit comments

Comments
 (0)