Skip to content

Commit

Permalink
React: Identify components which are exported at the top-level of a c…
Browse files Browse the repository at this point in the history
…ommonjs library (#264)
  • Loading branch information
oyvindberg authored Mar 5, 2021
1 parent b6f3ec8 commit 613bc2e
Show file tree
Hide file tree
Showing 26 changed files with 714 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ object AdaptiveNamingImport {
}

private def addMod(str: String) = str match {
case "" => "mod"
case "" => Name.mod.unescaped
case nonEmpty => nonEmpty + "Mod"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final case class Name(unescaped: String) {
}

object Name {
val mod: Name = Name("mod")
val std: Name = Name("std")
val typings: Name = Name("typings")
val global: Name = Name("global")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ class IdentifyReactComponents(
case _: ClassTree => false
case _ => true
}
val propsRef = PropsRef(flattenedParams.headOption.map(_.tpe).getOrElse(TypeRef.Object))
def validName = isUpper(method.name) || (Unnamed(method.name) && (isUpper(owner.name) || Unnamed(owner.name)))
val propsRef = PropsRef(flattenedParams.headOption.map(_.tpe).getOrElse(TypeRef.Object))
def validName =
isUpper(method.name) || (Unnamed(method.name) && (isUpper(owner.name) || Unnamed(owner.name) || owner.name === Name.mod))

if (!validName || !isTopLevel || !method.isNative) None
else
Expand Down Expand Up @@ -385,7 +386,7 @@ class IdentifyReactComponents(
val fromCodePath = codePath.parts
.filterNot(Unnamed)
.reverse
.takeWhile(n => !n.unescaped.endsWith("Mod") && n.unescaped != "mod")
.takeWhile(n => !n.unescaped.endsWith("Mod") && n != Name.mod)
.headOption

val name = fromCodePath.orElse(fromAnnotations(anns))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package flavours

class ReactNames(val outputPkg: Name) {
val libName = Name("react")
val mod = QualifiedName(IArray(outputPkg, libName, Name("mod")))
val mod = QualifiedName(IArray(outputPkg, libName, Name.mod))
val Ref = mod + Name("Ref")
val LegacyRef = mod + Name("LegacyRef")
val RefObject = mod + Name("RefObject")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class SlinkyGenStBuildingComponent(val outputPkg: Name, val scalaVersion: Versio
comments = NoComments,
)
val impl = {
val modParam = ParamTree(Name("mod"), isImplicit = false, isVal = false, TagModE, NotImplemented, NoComments)
val modParam = ParamTree(Name.mod, isImplicit = false, isVal = false, TagModE, NotImplemented, NoComments)
val modRef = Ref(modParam.name)

val AttrPair = TypeRef(SlinkyGenComponents.names.AttrPair, IArray(TypeRef.Wildcard), NoComments)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
organization := "org.scalablytyped"
name := "react-dropzone"
version := "10.1.10-d9f6ec"
version := "10.1.10-f9d26c"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package typingsJapgolly.reactDropzone.components

import japgolly.scalajs.react.Callback
import japgolly.scalajs.react.ReactDragEventFrom
import japgolly.scalajs.react.raw.React.Element
import org.scalajs.dom.raw.HTMLElement
import typingsJapgolly.StBuildingComponent
import typingsJapgolly.react.mod.RefAttributes
import typingsJapgolly.reactDropzone.mod.DropEvent
import typingsJapgolly.reactDropzone.mod.DropzoneProps
import typingsJapgolly.reactDropzone.mod.DropzoneRef
import typingsJapgolly.reactDropzone.mod.DropzoneState
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object ReactDropzone {

@JSImport("react-dropzone", JSImport.Default)
@js.native
val component: js.Object = js.native

@scala.inline
class Builder (val args: js.Array[js.Any])
extends AnyVal
with StBuildingComponent[DropzoneRef] {

@scala.inline
def accept(value: String | js.Array[String]): this.type = set("accept", value.asInstanceOf[js.Any])

@scala.inline
def acceptVarargs(value: String*): this.type = set("accept", js.Array(value :_*))

@scala.inline
def children(value: /* state */ DropzoneState => Element): this.type = set("children", js.Any.fromFunction1(value))

@scala.inline
def disabled(value: Boolean): this.type = set("disabled", value.asInstanceOf[js.Any])

@scala.inline
def getFilesFromEvent(
value: /* event */ DropEvent => /* import warning: transforms.QualifyReferences#resolveTypeRef many Couldn't qualify Promise<Array<File | DataTransferItem>> */ _
): this.type = set("getFilesFromEvent", js.Any.fromFunction1(value))

@scala.inline
def maxSize(value: Double): this.type = set("maxSize", value.asInstanceOf[js.Any])

@scala.inline
def minSize(value: Double): this.type = set("minSize", value.asInstanceOf[js.Any])

@scala.inline
def multiple(value: Boolean): this.type = set("multiple", value.asInstanceOf[js.Any])

@scala.inline
def noClick(value: Boolean): this.type = set("noClick", value.asInstanceOf[js.Any])

@scala.inline
def noDrag(value: Boolean): this.type = set("noDrag", value.asInstanceOf[js.Any])

@scala.inline
def noDragEventsBubbling(value: Boolean): this.type = set("noDragEventsBubbling", value.asInstanceOf[js.Any])

@scala.inline
def noKeyboard(value: Boolean): this.type = set("noKeyboard", value.asInstanceOf[js.Any])

@scala.inline
def onDragEnter(value: ReactDragEventFrom[HTMLElement] => Callback): this.type = set("onDragEnter", js.Any.fromFunction1((t0: ReactDragEventFrom[HTMLElement]) => value(t0).runNow()))

@scala.inline
def onDragLeave(value: ReactDragEventFrom[HTMLElement] => Callback): this.type = set("onDragLeave", js.Any.fromFunction1((t0: ReactDragEventFrom[HTMLElement]) => value(t0).runNow()))

@scala.inline
def onDragOver(value: ReactDragEventFrom[HTMLElement] => Callback): this.type = set("onDragOver", js.Any.fromFunction1((t0: ReactDragEventFrom[HTMLElement]) => value(t0).runNow()))

@scala.inline
def onDrop(
value: (/* acceptedFiles */ js.Array[js.Any], /* rejectedFiles */ js.Array[js.Any], /* event */ DropEvent) => Callback
): this.type = set("onDrop", js.Any.fromFunction3((t0: /* acceptedFiles */ js.Array[js.Any], t1: /* rejectedFiles */ js.Array[js.Any], t2: /* event */ DropEvent) => (value(t0, t1, t2)).runNow()))

@scala.inline
def onDropAccepted(value: (/* files */ js.Array[js.Any], /* event */ DropEvent) => Callback): this.type = set("onDropAccepted", js.Any.fromFunction2((t0: /* files */ js.Array[js.Any], t1: /* event */ DropEvent) => (value(t0, t1)).runNow()))

@scala.inline
def onDropRejected(value: (/* files */ js.Array[js.Any], /* event */ DropEvent) => Callback): this.type = set("onDropRejected", js.Any.fromFunction2((t0: /* files */ js.Array[js.Any], t1: /* event */ DropEvent) => (value(t0, t1)).runNow()))

@scala.inline
def onFileDialogCancel(value: Callback): this.type = set("onFileDialogCancel", value.toJsFn)

@scala.inline
def preventDropOnDocument(value: Boolean): this.type = set("preventDropOnDocument", value.asInstanceOf[js.Any])
}

implicit def make(companion: ReactDropzone.type): Builder = new Builder(js.Array(this.component, js.Dictionary.empty))()

def withProps(p: DropzoneProps with RefAttributes[DropzoneRef]): Builder = new Builder(js.Array(this.component, p.asInstanceOf[js.Any]))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
organization := "org.scalablytyped"
name := "react-markdown"
version := "0.0-unknown-7278fc"
scalaVersion := "2.13.3"
enablePlugins(ScalaJSPlugin)
libraryDependencies ++= Seq(
"com.github.japgolly.scalajs-react" %%% "core" % "1.7.5",
"com.olvind" %%% "scalablytyped-runtime" % "2.4.0",
"org.scalablytyped" %%% "react" % "16.9.2-0e03be",
"org.scalablytyped" %%% "std" % "0.0-unknown-43ed0a")
publishArtifact in packageDoc := false
scalacOptions ++= List("-encoding", "utf-8", "-feature", "-g:notailcalls", "-language:implicitConversions", "-language:higherKinds", "-language:existentials")
licenses += ("MIT", url("http://opensource.org/licenses/MIT"))
bintrayRepository := "ScalablyTyped"
resolvers += Resolver.bintrayRepo("oyvindberg", "ScalablyTyped")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.4.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("org.scala-js" %% "sbt-scalajs" % "1.3.0")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# Scala.js typings for react-markdown




## Note
This library has been generated from typescript code from first party type definitions.

Provided with :purple_heart: from [ScalablyTyped](https://github.com/oyvindberg/ScalablyTyped)

## Usage
See [the main readme](../../readme.md) for instructions.


Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package typingsJapgolly.reactMarkdown.components

import typingsJapgolly.StBuildingComponent.Default
import typingsJapgolly.reactMarkdown.mod.ReactMarkdownProps
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

/* The props of this component has an unsupported shape. You can use `set` manually to use it, but with no compiler support :/ . Couldn't find props for typingsJapgolly.reactMarkdown.mod.ReactMarkdownProps because: IArray(Couldn't find props for typingsJapgolly.reactMarkdown.mod.ChildrenProp with typingsJapgolly.reactMarkdown.reactMarkdownStrings.Not with js.Any because: IArray(Could't extract props from js.Any because couldn't resolve ClassTree.), Couldn't find props for typingsJapgolly.reactMarkdown.mod.SourceProp with typingsJapgolly.reactMarkdown.reactMarkdownStrings.Not with js.Any because: IArray(Could't extract props from js.Any because couldn't resolve ClassTree.)) */
object ReactMarkdown {

def apply(p: ReactMarkdownProps): Default[js.Object] = new Default[js.Object](js.Array(this.component, p.asInstanceOf[js.Any]))

@JSImport("react-markdown", JSImport.Namespace)
@js.native
val component: js.Object = js.native

implicit def make(companion: ReactMarkdown.type): Default[js.Object] = new Default[js.Object](js.Array(this.component, js.Dictionary.empty))()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package typingsJapgolly.reactMarkdown

import japgolly.scalajs.react.raw.React.Element
import japgolly.scalajs.react.raw.React.ElementType
import japgolly.scalajs.react.raw.React.Node
import org.scalablytyped.runtime.StringDictionary
import org.scalablytyped.runtime.TopLevel
import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object mod {

@scala.inline
def apply(props: ReactMarkdownProps): Element = ^.asInstanceOf[js.Dynamic].apply(props.asInstanceOf[js.Any]).asInstanceOf[Element]

@JSImport("react-markdown", JSImport.Namespace)
@js.native
val ^ : js.Any = js.native

@JSImport("react-markdown", "renderers")
@js.native
val renderers: Renderers_ = js.native

@scala.inline
def uriTransformer(uri: String): String = ^.asInstanceOf[js.Dynamic].applyDynamic("uriTransformer")(uri.asInstanceOf[js.Any]).asInstanceOf[String]

@js.native
trait ChildrenProp extends StObject {

val children: String = js.native
}
object ChildrenProp {

@scala.inline
def apply(children: String): ChildrenProp = {
val __obj = js.Dynamic.literal(children = children.asInstanceOf[js.Any])
__obj.asInstanceOf[ChildrenProp]
}

@scala.inline
implicit class ChildrenPropMutableBuilder[Self <: ChildrenProp] (val x: Self) extends AnyVal {

@scala.inline
def setChildren(value: String): Self = StObject.set(x, "children", value.asInstanceOf[js.Any])
}
}

type LinkTargetResolver = js.Function3[/* uri */ String, /* text */ String, /* title */ js.UndefOr[String], String]

type MutuallyExclusive[T, U] = (T with Not[U]) | (U with Not[T])

type Not[T] = /* import warning: importer.ImportType#apply c Unsupported type mapping:
{[ key in keyof T ]:? never}
*/ typingsJapgolly.reactMarkdown.reactMarkdownStrings.Not with TopLevel[js.Any]

type ReactMarkdownProps = ReactMarkdownPropsBase with (MutuallyExclusive[ChildrenProp, SourceProp])

@js.native
trait ReactMarkdownPropsBase extends StObject {

val allowNode: js.UndefOr[js.Function1[/* index */ Double, Boolean]] = js.native

val className: js.UndefOr[String] = js.native

val linkTarget: js.UndefOr[String | LinkTargetResolver] = js.native

val transformLinkUri: js.UndefOr[
(js.Function3[
/* uri */ String,
/* children */ js.UndefOr[Node],
/* title */ js.UndefOr[String],
String
]) | Null
] = js.native
}
object ReactMarkdownPropsBase {

@scala.inline
def apply(): ReactMarkdownPropsBase = {
val __obj = js.Dynamic.literal()
__obj.asInstanceOf[ReactMarkdownPropsBase]
}

@scala.inline
implicit class ReactMarkdownPropsBaseMutableBuilder[Self <: ReactMarkdownPropsBase] (val x: Self) extends AnyVal {

@scala.inline
def setAllowNode(value: /* index */ Double => Boolean): Self = StObject.set(x, "allowNode", js.Any.fromFunction1(value))

@scala.inline
def setAllowNodeUndefined: Self = StObject.set(x, "allowNode", js.undefined)

@scala.inline
def setClassName(value: String): Self = StObject.set(x, "className", value.asInstanceOf[js.Any])

@scala.inline
def setClassNameUndefined: Self = StObject.set(x, "className", js.undefined)

@scala.inline
def setLinkTarget(value: String | LinkTargetResolver): Self = StObject.set(x, "linkTarget", value.asInstanceOf[js.Any])

@scala.inline
def setLinkTargetFunction3(value: (/* uri */ String, /* text */ String, /* title */ js.UndefOr[String]) => String): Self = StObject.set(x, "linkTarget", js.Any.fromFunction3(value))

@scala.inline
def setLinkTargetUndefined: Self = StObject.set(x, "linkTarget", js.undefined)

@scala.inline
def setTransformLinkUri(
value: (/* uri */ String, /* children */ js.UndefOr[Node], /* title */ js.UndefOr[String]) => String
): Self = StObject.set(x, "transformLinkUri", js.Any.fromFunction3(value))

@scala.inline
def setTransformLinkUriNull: Self = StObject.set(x, "transformLinkUri", null)

@scala.inline
def setTransformLinkUriUndefined: Self = StObject.set(x, "transformLinkUri", js.undefined)
}
}

type Renderer[T] = js.Function1[/* props */ T, ElementType]

type Renderers_ = StringDictionary[String | Renderer[js.Any]]

@js.native
trait SourceProp extends StObject {

/** @deprecated use children */
val source: String = js.native
}
object SourceProp {

@scala.inline
def apply(source: String): SourceProp = {
val __obj = js.Dynamic.literal(source = source.asInstanceOf[js.Any])
__obj.asInstanceOf[SourceProp]
}

@scala.inline
implicit class SourcePropMutableBuilder[Self <: SourceProp] (val x: Self) extends AnyVal {

@scala.inline
def setSource(value: String): Self = StObject.set(x, "source", value.asInstanceOf[js.Any])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package typingsJapgolly.reactMarkdown

import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

/* This can be used to `require` the library as a side effect.
If it is a global library this will make scalajs-bundler include it */
@JSImport("react-markdown", JSImport.Namespace)
@js.native
object reactMarkdownRequire extends StObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package typingsJapgolly.reactMarkdown

import org.scalablytyped.runtime.StObject
import scala.scalajs.js
import scala.scalajs.js.`|`
import scala.scalajs.js.annotation.{JSGlobalScope, JSGlobal, JSImport, JSName, JSBracketAccess}

object reactMarkdownStrings {

@js.native
sealed trait Not extends StObject
@scala.inline
def Not: Not = "Not".asInstanceOf[Not]
}
Loading

0 comments on commit 613bc2e

Please sign in to comment.