Skip to content

Commit

Permalink
mui-x-tree-view.version=7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aerialist7 committed May 25, 2024
1 parent ed54a12 commit 03e3e40
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 95 deletions.
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/karakum/mui/Adapter.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package karakum.mui

import karakum.mui.adapters.*
import karakum.mui.adapters.treeview.adaptRichTreeView
import karakum.mui.adapters.treeview.adaptTreeItem
import karakum.mui.adapters.treeview.adaptTreeView

fun String.adaptRawContent(): String = this
.adaptComponentsAndSlots()
Expand All @@ -16,3 +19,6 @@ fun String.adaptRawContent(): String = this
.adaptBreadcrumbs()
.adaptUseMenu()
.adaptUseSlider()
.adaptRichTreeView()
.adaptTreeItem()
.adaptTreeView()
15 changes: 11 additions & 4 deletions buildSrc/src/main/kotlin/karakum/mui/Converter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ private fun findProps(
?.substringBefore(";\n}")
?: ""

val body = convertMembers(membersContent)
val body = if (source.startsWith("}"))
""
else
convertMembers(membersContent)

return props(
propsName = propsDeclaration,
parentType = parentType,
Expand Down Expand Up @@ -501,8 +505,8 @@ private fun findAdditionalProps(
}

when (interfaceName) {
"TreeViewPropsBase",
-> propsBody = propsBody.replace("var id:", "override var id:")
"RichTreeViewPropsBase",
-> propsBody = propsBody.replace("override var sx:", "var sx:")

"CommonColors",
"PaletteColor",
Expand Down Expand Up @@ -664,7 +668,10 @@ private fun props(
baseInterfaces += "PaperProps"

if (propsName == "TreeViewProps")
baseInterfaces += "TreeViewPropsBase"
baseInterfaces += "SimpleTreeViewProps"

if (propsName == "RichTreeViewProps")
baseInterfaces += "RichTreeViewPropsBase"

if (
// TODO: Commented props has conflicts by intrinsic types
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/karakum/mui/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ private fun generateTreeViewDeclarations(
directories.asSequence()
.filter { it.name.isComponentName() || it.name.isHookName() }
.filter { !it.resolve("${it.name}.d.ts").readText().startsWith("export { default } from ") }
.filter { it.name !in setOf("TreeItem2", "TreeItem2Icon", "TreeItem2Provider", "useTreeItem2") }
.onEach {
when (it.name) {
"TreeItem" -> {
Expand All @@ -525,7 +526,7 @@ private fun generateTreeViewDeclarations(
generate(typesFile, targetDir, Package.treeView)
}

"TreeView" -> {
"TreeView", "SimpleTreeView", "RichTreeView" -> {
val typesFile = it.resolve("${it.name}.types.d.ts")
generate(typesFile, targetDir, Package.treeView)
}
Expand Down
13 changes: 12 additions & 1 deletion buildSrc/src/main/kotlin/karakum/mui/KotlinType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ private val KNOWN_TYPE_SUFFIXES = setOf(
it.capitalize()
}

private val KNOWN_TYPE_PREFIX_MAP = mapOf(
"SlotComponentProps" to "react.Props",
)

private val STANDARD_TYPE_MAP = mapOf(
"any" to "Any",
"object" to "Any",
Expand Down Expand Up @@ -173,6 +177,9 @@ private val STANDARD_TYPE_MAP = mapOf(
"React.Ref<unknown>" to "react.Ref<*>",
"React.Ref<any>" to "react.Ref<*>",

"SimpleTreeViewApiRef" to "react.Ref<*>",
"RichTreeViewApiRef" to "react.Ref<*>",

"React.AriaRole" to "react.dom.aria.AriaRole",

"PaletteMode" to "mui.material.PaletteMode",
Expand Down Expand Up @@ -345,6 +352,10 @@ internal fun kotlinType(
if (KNOWN_TYPE_SUFFIXES.any { type.endsWith(it) } && " | " !in type && type != "Color")
return type

val prefixToType = KNOWN_TYPE_PREFIX_MAP.filter { (prefix) -> type.startsWith(prefix) }
if (prefixToType.isNotEmpty())
return prefixToType.values.single()

val promiseResult = type.removeSurrounding("Promise<", ">")
if (promiseResult != type)
return "$PROMISE<${kotlinType(promiseResult)}>"
Expand Down Expand Up @@ -476,7 +487,7 @@ internal fun kotlinType(
}
}

if (name != null && name.endsWith("Props") && name != "componentsProps" && name != "slotProps") {
if (name != null && name.endsWith("Props") && name != "componentsProps") {
val comment = type.split("\n")
.map { it.trim() }
.joinToString(" ")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/karakum/mui/ParentType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal fun findParentType(
"ListItemButtonBaseProps",
"BaseTextFieldProps",
"ListProps",
"TreeViewPropsBase",
"RichTreeViewPropsBase",
"UseInputProps",
"UseSwitchProps",
"UsePaginationItem",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package karakum.mui.adapters.treeview

fun String.adaptRichTreeView(): String = this
.replace(
oldValue = " | React.JSXElementConstructor<TreeItem2Props>",
newValue = "",
)
.replace(
oldValue = ": RichTreeViewSlotProps<R, Multiple>",
newValue = ": RichTreeViewSlotProps",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package karakum.mui.adapters.treeview

fun String.adaptTreeItem(): String = this
.replace(
oldValue = "TreeViewItemId",
newValue = "string",
)
16 changes: 16 additions & 0 deletions buildSrc/src/main/kotlin/karakum/mui/adapters/treeview/TreeView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package karakum.mui.adapters.treeview

fun String.adaptTreeView(): String = this
.replace(
oldValue = """export interface TreeViewProps<Multiple extends boolean | undefined> extends SimpleTreeViewProps<Multiple> {
}
export interface TreeViewSlots extends SimpleTreeViewSlots {
}
export interface TreeViewSlotProps extends SimpleTreeViewSlotProps {
}
export type SingleSelectTreeViewProps = SimpleTreeViewProps<false>;
export type MultiSelectTreeViewProps = SimpleTreeViewProps<true>;
""",
newValue = """export interface TreeViewProps<Multiple extends boolean | undefined> extends SimpleTreeViewProps<Multiple> {
}""",
)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mui-base.version=5.0.0-beta.45
mui-system.version=5.15.15
mui-lab.version=5.0.0-alpha.170
mui-x-date-pickers.version=5.0.20
mui-x-tree-view.version=6.17.0
mui-x-tree-view.version=7.0.0
# Flags
org.gradle.jvmargs=-Xms2g -Xmx4g
org.gradle.parallel=true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Automatically generated - do not modify!

@file:JsModule("@mui/x-tree-view/RichTreeView")

package muix.tree.view

import web.cssom.ClassName

sealed external interface RichTreeViewClasses {
/** Styles applied to the root element. */
val root: ClassName
}

external val richTreeViewClasses: RichTreeViewClasses
17 changes: 17 additions & 0 deletions mui-kotlin/src/jsMain/kotlin/muix/tree/view/RichTreeView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Automatically generated - do not modify!

@file:JsModule("@mui/x-tree-view/RichTreeView")

package muix.tree.view

/**
*
* Demos:
*
* - [Tree View](https://mui.com/x/react-tree-view/)
*
* API:
*
* - [RichTreeView API](https://mui.com/x/api/tree-view/rich-tree-view/)
*/
external val RichTreeView: react.FC<RichTreeViewProps>
60 changes: 60 additions & 0 deletions mui-kotlin/src/jsMain/kotlin/muix/tree/view/RichTreeView.types.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Automatically generated - do not modify!

package muix.tree.view

import mui.material.styles.Theme
import mui.system.SxProps
import web.cssom.ClassName

external interface RichTreeViewProps : RichTreeViewPropsBase {
/**
* Overridable component slots.
* @default {}
*/
var slots: RichTreeViewSlots?

/**
* The props used for each component slot.
* @default {}
*/
var slotProps: RichTreeViewSlotProps?

/**
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
*/
var apiRef: react.Ref<*>?
}

external interface RichTreeViewSlots {
/**
* Element rendered at the root.
* @default RichTreeViewRoot
*/
var root: react.ElementType<*>?

/**
* Custom component for the item.
* @default TreeItem.
*/
var item: react.ComponentType<TreeItemProps>?
}

external interface RichTreeViewSlotProps : react.Props {
var root: react.Props?

var item: react.Props?
}

external interface RichTreeViewPropsBase : react.dom.html.HTMLAttributes<web.html.HTMLUListElement> {
override var className: ClassName?

/**
* Override or extend the styles applied to the component.
*/
var classes: RichTreeViewClasses?

/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
var sx: SxProps<Theme>?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Automatically generated - do not modify!

@file:JsModule("@mui/x-tree-view/SimpleTreeView")

package muix.tree.view

import web.cssom.ClassName

sealed external interface SimpleTreeViewClasses {
/** Styles applied to the root element. */
val root: ClassName
}

external val simpleTreeViewClasses: SimpleTreeViewClasses
17 changes: 17 additions & 0 deletions mui-kotlin/src/jsMain/kotlin/muix/tree/view/SimpleTreeView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Automatically generated - do not modify!

@file:JsModule("@mui/x-tree-view/SimpleTreeView")

package muix.tree.view

/**
*
* Demos:
*
* - [Tree View](https://mui.com/x/react-tree-view/)
*
* API:
*
* - [SimpleTreeView API](https://mui.com/x/api/tree-view/simple-tree-view/)
*/
external val SimpleTreeView: react.FC<SimpleTreeViewProps>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Automatically generated - do not modify!

package muix.tree.view

import mui.material.styles.Theme
import mui.system.SxProps
import web.cssom.ClassName

external interface SimpleTreeViewProps :
react.PropsWithChildren,
react.PropsWithClassName,
mui.system.PropsWithSx {
/**
* The content of the component.
*/
override var children: react.ReactNode?

/**
* Overridable component slots.
*/
var slots: SimpleTreeViewSlots?

/**
* The props used for each component slot.
*/
var slotProps: SimpleTreeViewSlotProps?

override var className: ClassName?

/**
* Override or extend the styles applied to the component.
*/
var classes: SimpleTreeViewClasses?

/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
override var sx: SxProps<Theme>?

/**
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
*/
var apiRef: react.Ref<*>?
}

external interface SimpleTreeViewSlots {
/**
* Element rendered at the root.
* @default SimpleTreeViewRoot
*/
var root: react.ElementType<*>?
}

external interface SimpleTreeViewSlotProps : react.Props {
var root: react.Props?
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sealed external interface TreeItemClasses {
val root: ClassName

/** Styles applied to the transition component. */
val group: ClassName
val groupTransition: ClassName

/** Styles applied to the content element. */
val content: ClassName
Expand Down
Loading

0 comments on commit 03e3e40

Please sign in to comment.