Skip to content

Commit

Permalink
React 19.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
porotkin committed Dec 26, 2024
1 parent 426b80a commit bfdc9d3
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
19 changes: 13 additions & 6 deletions buildSrc/src/main/kotlin/karakum/react/Converter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,29 @@ internal fun convertDefinitions(
.replace("""fetchPriority?: "high" | "low" | "auto";""", """fetchPriority?: FetchPriority;""")
.replace(" | undefined", " | undefined")
.replace(" | (string & {})", "")
.replace("((formData: FormData) => void | Promise<void>) |", "")
.withDefaultLineBreaks()

val svgTypes = content.substringAfter(" interface IntrinsicElements {\n")
.substringAfter("// SVG\n")
val intrinsicsContent = content.substringAfter(" interface IntrinsicElements {\n")
.substringBefore("\n }")
.replace("\n\n", "\n")
.replaceIndent(" ")
.replace(" picture", "picture")
.replace(", \n", ",")
.replaceIndent(" ")

val htmlIntrinsics = intrinsicsContent.substringAfter("// HTML\n")
.substringBefore("// SVG\n")

val svgIntrinsics = intrinsicsContent.substringAfter("// SVG\n")

val reactContent = content
.substringAfter("declare namespace React {\n")
.substringBefore("\n}\n")
.replace(Regex("""( ReactSVG \{\n).+?(\n\s+})""", RegexOption.DOT_MATCHES_ALL)) {
"${it.groupValues[1]}$svgTypes${it.groupValues[2]}"
}
.trimIndent()
.plus(ADDITIONAL_TYPES)
.plus("\ninterface ReactSVG {\n$svgIntrinsics\n}")
.plus("\ninterface ReactHTML {\n$htmlIntrinsics\n}")
.trimIndent()

return convertInterfaces(reactContent)
.plus(convertUnions(reactContent))
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/karakum/react/Deprecated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package karakum.react

internal fun String.removeDeprecatedMembers(): String =
replace(Regex(""" +/\*\*[ \n]*.*@deprecated .*[ \n]*\*/\n +.+?\n"""), "")
.replace(" param: DetailedHTMLFactory<ParamHTMLAttributes<HTMLParamElement>, HTMLParamElement>;\n", "")
.replace("param: React.DetailedHTMLProps<React.ParamHTMLAttributes<HTMLParamElement>, HTMLParamElement>;\n", "")
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/karakum/react/EventConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ internal fun convertEventHandlers(
}

private const val DEFAULT_EVENT_IMPORTS = """
import react.dom.html.OldState
import react.dom.html.NewState
import web.dom.Element
import web.window.Window
import web.events.Event
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/karakum/react/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ private val EXCLUDED_TYPES = setOf(
"AutoFillContactField",
"AutoFillBase",
"AutoFillAddressKind",
"HTMLElementType",
"SVGElementType",
)

fun generateKotlinDeclarations(
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/karakum/react/InterfaceConverter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private fun convertIntrinsicTypes(
convert: (String) -> String,
): ConversionResult {
val content = source.substringAfter("{\n")
.substringBefore("\n}")
.trimIndent()
.splitToSequence("\n")
.filter { it.isNotEmpty() }
Expand All @@ -193,9 +194,10 @@ private fun convertHtmlType(
val name = source.substringBefore(": ")
.removeSurrounding("\"")

val propsType = source.substringAfter(": DetailedHTMLFactory<")
val propsType = source.substringAfter(": React.DetailedHTMLProps<")
.substringBefore(",")
.replaceFirst("<", "<")
.removePrefix("React.")
val type = "IntrinsicType<$propsType>"

val id = when (name) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ csstype.version=3.1.3
popperjs-core.version=2.11.8
tanstack-react-query.version=5.62.10
tanstack-react-table.version=8.20.6
types-react.version=18.3.12
types-react.version=19.0.0
tanstack-react-virtual.version=3.11.2

kotlin-wrappers.version=0.0.1-pre.855
Expand Down
15 changes: 4 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bfdc9d3

Please sign in to comment.