scala.scalajs.js.annotation.JSImport Scala Examples

The following examples show how to use scala.scalajs.js.annotation.JSImport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: CryptoJs.scala    From iotchain   with MIT License 6 votes vote down vote up
package jbok.crypto.facade

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object CryptoJs {
  @js.native
  @JSImport("crypto-js/ripemd160", JSImport.Default)
  object ripemd160 extends js.Object {
    def apply(arr: Any): Any = js.native
  }

  @js.native
  @JSImport("crypto-js/sha3", JSImport.Default)
  object sha3 extends js.Object {
    def apply(arr: Any, option: js.Dynamic): Any = js.native
  }

  @js.native
  @JSImport("crypto-js/sha256", JSImport.Default)
  object sha256 extends js.Object {
    def apply(arr: Any): Any = js.native
  }

  @js.native
  @JSImport("crypto-js/enc-base64", JSImport.Default)
  object Base64 extends js.Object {
    def stringify(x: Any): String = js.native
  }

  @js.native
  @JSImport("crypto-js/enc-hex", JSImport.Default)
  object Hex extends js.Object {
    def stringify(x: Any): String = js.native
    def parse(s: String): Any = js.native
  }
} 
Example 2
Source File: Alert.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

case class AlertButton(text: String, onPress: () => Unit)
case class AlertOptions(cancelable: js.UndefOr[Boolean] = js.undefined)

@js.native
@JSImport("react-native", "Alert")
object Alert extends js.Object {
  def alert(
    title: String,
    message: js.UndefOr[String] = js.undefined,
    buttons: js.UndefOr[ObjectOrWritten[Seq[AlertButton]]] = js.undefined,
    options: js.UndefOr[ObjectOrWritten[AlertOptions]] = js.undefined,
    `type`: js.UndefOr[String] = js.undefined
  ): Unit = js.native
} 
Example 3
Source File: ApolloLink.scala    From apollo-scalajs   with MIT License 5 votes vote down vote up
package com.apollographql.scalajs.link

import com.apollographql.scalajs.DocumentNode
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

case class GraphQLRequest(query: DocumentNode)

@js.native
trait FetchResult extends js.Object

@js.native
trait Operation extends js.Object {
  def setContext(context: js.Dictionary[js.Any]): js.Dictionary[js.Any] = js.native
  def getContext(): js.Dictionary[js.Any] = js.native
  def toKey(): String = js.native
}

@JSImport("apollo-link", "ApolloLink")
@js.native
class ApolloLink(handler: js.UndefOr[js.Function2[Operation, js.UndefOr[NextLink], Observable[FetchResult]]] = js.undefined) extends js.Object {
  def concat(next: ApolloLink | RequestHandler): ApolloLink = js.native
  def request(operation: Operation, forward: js.UndefOr[NextLink]): Observable[FetchResult] = js.native
}

@JSImport("apollo-link", "ApolloLink")
@js.native
object ApolloLink extends js.Object {
  def empty(): ApolloLink = js.native
  def from(links: js.Array[ApolloLink]): ApolloLink = js.native
  def concat(first: ApolloLink, second: ApolloLink): ApolloLink = js.native
  def execute(link: ApolloLink, operation: ObjectOrWritten[GraphQLRequest]): Observable[FetchResult] = js.native
} 
Example 4
Source File: TestRenderer.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.testrenderer

import slinky.core.ReactComponentClass
import slinky.core.facade.ReactElement

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSImport, JSName}

@js.native
trait TestRenderer extends js.Object {
  def toJSON(): js.Object                 = js.native
  def toTree(): js.Object                 = js.native
  def update(element: ReactElement): Unit = js.native
  def unmount(): Unit                     = js.native
  def getInstance(): js.Object            = js.native
  val root: TestInstance                  = js.native
}

@js.native
@JSImport("react-test-renderer", JSImport.Default)
object TestRenderer extends js.Object {
  def create(element: ReactElement): TestRenderer = js.native
  def act(callback: js.Function0[js.Any]): Unit   = js.native
}

@js.native
trait TestInstance extends js.Object {
  def find(test: js.Function1[TestInstance, Boolean]): TestInstance = js.native
  def findByType(`type`: ReactComponentClass[_]): TestInstance      = js.native
  def findByProps(props: js.Object): TestInstance                   = js.native

  def findAll(test: js.Function1[TestInstance, Boolean]): js.Array[TestInstance] = js.native
  def findAllByType(`type`: ReactComponentClass[_]): js.Array[TestInstance]      = js.native
  def findAllByProps(props: js.Object): js.Array[TestInstance]                   = js.native

  val instance: js.Object               = js.native
  @JSName("type") val `type`: js.Object = js.native
  val props: js.Object                  = js.native
  val parent: TestInstance              = js.native
  val children: js.Array[TestInstance]  = js.native
} 
Example 5
Source File: ReactRouterDOM.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.reactrouter

import slinky.core._
import slinky.core.annotations.react
import slinky.web.html.a
import org.scalajs.dom.History

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@JSImport("react-router", JSImport.Default)
@js.native
object ReactRouter extends js.Object {
  val StaticRouter: js.Object = js.native
  val MemoryRouter: js.Object = js.native
}

@JSImport("react-router-dom", JSImport.Default)
@js.native
object ReactRouterDOM extends js.Object {
  val Router: js.Object        = js.native
  val BrowserRouter: js.Object = js.native
  val HashRouter: js.Object    = js.native
  val Route: js.Object         = js.native
  val Switch: js.Object        = js.native
  val Link: js.Object          = js.native
  val NavLink: js.Object       = js.native
  val Redirect: js.Object      = js.native
  val Prompt: js.Object        = js.native
}

@react object StaticRouter extends ExternalComponent {
  case class Props(location: String, context: js.Object)

  override val component = ReactRouter.StaticRouter
}

@react object Router extends ExternalComponent {
  case class Props(history: History)
  override val component = ReactRouterDOM.Router
}

object BrowserRouter extends ExternalComponentNoProps {
  override val component = ReactRouterDOM.BrowserRouter
}

object Switch extends ExternalComponentNoProps {
  override val component = ReactRouterDOM.Switch
}

@react object Route extends ExternalComponent {
  case class Props(path: String, component: ReactComponentClass[_], exact: Boolean = false)
  override val component = ReactRouterDOM.Route
}

@react object Link extends ExternalComponentWithAttributes[a.tag.type] {
  case class Props(to: String)
  override val component = ReactRouterDOM.Link
}

@react object Redirect extends ExternalComponent {
  case class Props(to: String, push: Boolean = false)
  override val component = ReactRouterDOM.Redirect
}

@react object NavLink extends ExternalComponentWithAttributes[a.tag.type] {
  case class Props(to: String, activeStyle: Option[js.Dynamic] = None, activeClassName: Option[String] = None)
  override val component = ReactRouterDOM.NavLink
} 
Example 6
Source File: ReactDOM.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.web

import slinky.core.facade.{React, ReactElement, ReactInstance}
import org.scalajs.dom.Element

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-dom", JSImport.Namespace, "ReactDOM")
object ReactDOM extends js.Object {
  def render(component: ReactElement, target: Element): ReactInstance  = js.native
  def hydrate(component: ReactElement, target: Element): ReactInstance = js.native
  def findDOMNode(instance: React.Component): Element                  = js.native

  def unmountComponentAtNode(container: Element): Unit = js.native

  
  def createPortal(child: ReactElement, container: Element): ReactElement = js.native
}

@js.native
@JSImport("react-dom/server", JSImport.Namespace, "ReactDOMServer")
object ReactDOMServer extends js.Object {
  def renderToString(element: ReactElement): String       = js.native
  def renderToStaticMarkup(element: ReactElement): String = js.native

  def renderToNodeStream(element: ReactElement): js.Object       = js.native
  def renderToStaticNodeStream(element: ReactElement): js.Object = js.native
} 
Example 7
Source File: Helmet.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.reacthelmet

import slinky.core.ExternalComponentNoProps

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@JSImport("react-helmet", JSImport.Namespace)
@js.native
object ReactHelmet extends js.Object {
  val Helmet: HelmetStatic = js.native
}

@js.native
trait HelmetStatic extends js.Object {
  def renderStatic(): HelmetRendered = js.native
}

@js.native trait HelmetRendered extends js.Object {
  val title: js.Object = js.native
  val meta: js.Object = js.native
  val link: js.Object = js.native
  val style: js.Object = js.native
}

object Helmet extends ExternalComponentNoProps {
  override val component = ReactHelmet.Helmet
} 
Example 8
Source File: Remark.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.remarkreact

import slinky.core.facade.ReactElement

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("remark", JSImport.Default)
object Remark extends js.Function0[js.Object] {
  override def apply(): RemarkInstance = js.native
}

@js.native
trait RemarkRenderer[T] extends js.Object

@js.native
trait RemarkInstance extends js.Object {
  def use[T](renderer: RemarkRenderer[T]): RemarkInstanceWithRenderer[T] = js.native
  def use[T](renderer: RemarkRenderer[T], options: js.Object): RemarkInstanceWithRenderer[T] = js.native
}

@js.native
trait RemarkInstanceWithRenderer[T] extends js.Object {
  def processSync(text: String): RemarkResult[T] = js.native
}

@js.native
trait RemarkResult[T] extends js.Object {
  val contents: T = js.native
}

@js.native
@JSImport("remark-react", JSImport.Default)
object ReactRenderer extends RemarkRenderer[ReactElement] 
Example 9
Source File: SyntaxHighlighter.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.docs

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-syntax-highlighter/light", JSImport.Default)
object SyntaxHighlighterComp extends js.Object

@js.native
@JSImport("react-syntax-highlighter/light", "registerLanguage")
object RegisterLanguageFunc extends js.Function2[String, js.Object, Unit] {
  override def apply(arg1: String, arg2: js.Object): Unit = js.native
}

@js.native
@JSImport("react-syntax-highlighter/languages/hljs/scala", JSImport.Default)
object ScalaHighlightLanguage extends js.Object

@react object SyntaxHighlighter extends ExternalComponent {
  RegisterLanguageFunc("scala", ScalaHighlightLanguage)
  val component = SyntaxHighlighterComp
  case class Props(language: String, style: js.Dictionary[js.Object])
} 
Example 10
Source File: Homepage.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.docs.homepage

import slinky.core.StatelessComponent
import slinky.core.annotations.react
import slinky.docs.MainPageContent
import slinky.web.html._

import scala.scalajs.js
import scala.scalajs.js.Dynamic.literal
import scala.scalajs.js.annotation.JSImport

import org.scalajs.dom

@JSImport("resources/slinky-logo-horizontal.svg", JSImport.Default)
@js.native
object SlinkyHorizontalLogo extends js.Object

@JSImport("resources/slinky-logo.svg", JSImport.Default)
@js.native
object SlinkyLogo extends js.Object

@react class Homepage extends StatelessComponent {
  type Props = Unit

  override def componentDidMount(): Unit = {
    dom.window.scrollTo(0, 0)
  }

  def render() = {
    div(
      Jumbotron(()),
      MainPageContent(Seq(
        div(style := literal(
          width = "100%",
          overflow = "auto",
          marginTop = "40px"
        ))(
          div(style := literal(
            width = "100%",
            minWidth = "800px",
            display = "flex",
            flexDirection = "row",
            justifyContent = "space-around",
          ))(
            div(style := literal(width = "33%"))(
              h3(style := literal(fontWeight = 100))("Just like ES6"),
              p("Slinky has a strong focus on mirroring the ES6 API. This means that any documentation or examples for ES6 React can be easily applied to your Scala code."),
              p("There are no new patterns involved with using Slinky. Just write React apps like you would in any other language!")
            ),
            div(style := literal(width = "33%"))(
              h3(style := literal(fontWeight = 100))("Complete Interop"),
              p("Slinky provides straightforward APIs for using external components. Simply define the component's properties using standard Scala types and you're good to go!"),
              p("In addition, Slinky components can be used from JavaScript code, thanks to a built in Scala to JS mappings. This means that your favorite libraries like React Router work out of the box with Slinky!")
            ),
            div(style := literal(width = "33%"))(
              h3(style := literal(fontWeight = 100))("First-Class Dev Experience"),
              p("Writing web applications with Scala doesn't have to feel like a degraded development experience. Slinky comes ready with full integration with familiar tools like Webpack and React DevTools."),
              p("Slinky also comes with built-in support for hot-loading via Webpack, allowing you to make your code-test-repeat flow even faster!")
            )
          )
        ),
        hr(style := literal(
          height = "1px",
          marginBottom = "-1px",
          border = "none",
          borderBottom = "1px solid #ececec",
          marginTop = "40px"
        )),
        Examples(())
      )),
      div(style := literal(
        width = "100%",
        backgroundColor = "#282c34",
        padding = "30px",
        boxSizing = "border-box",
        display = "flex",
        flexDirection = "column",
        alignItems = "center"
      ))(
        a(href := "https://www.netlify.com")(
          img(src := "https://www.netlify.com/img/global/badges/netlify-color-bg.svg")
        )
      )
    )
  }
} 
Example 11
Source File: BootstrapJQueryContext.scala    From scalajs-bootstrap   with MIT License 5 votes vote down vote up
package com.karasiq.bootstrap.jquery

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

trait BootstrapJQueryContext extends JQueryContext with BootstrapJQueryImplicits

object BootstrapJQueryContext {
  object imports {
    @js.native
    @JSImport("bootstrap", JSImport.Namespace)
    object bootstrap extends js.Object
  }

  def useNpmImports(): Unit = {
    JQueryContext.useNpmImport()
    imports.bootstrap
  }
} 
Example 12
Source File: JQueryContext.scala    From scalajs-bootstrap   with MIT License 5 votes vote down vote up
package com.karasiq.bootstrap.jquery

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

import org.scalajs.jquery.JQueryStatic

trait JQueryContext {
  def jQuery = JQueryContext.jQuery
}

object JQueryContext {
  var jQuery: JQueryStatic = org.scalajs.jquery.jQuery

  object imports {
    @js.native
    @JSImport("jquery", JSImport.Namespace)
    object jQuery extends JQueryStatic
  }

  def useStatic(): Unit = {
    jQuery = org.scalajs.jquery.jQuery
  }

  def useNpmImport(): Unit = {
    jQuery = imports.jQuery
  }
} 
Example 13
Source File: PakoSuite.scala    From metabrowse   with Apache License 2.0 5 votes vote down vote up
package metabrowse

import metabrowse.schema.Workspace
import org.scalatest.FunSuite
import scala.meta.internal.io.PathIO
import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.typedarray.ArrayBuffer
import scala.scalajs.js.typedarray.TypedArrayBuffer
import scala.scalajs.js.typedarray.Uint8Array

class PakoSuite extends FunSuite {
  test("deflate") {
    val path = PathIO.workingDirectory
      .resolve("target")
      .resolve("metabrowse")
      .resolve("index.workspace.gz")
    val in = path.readAllBytes
    val input = new ArrayBuffer(in.length)
    val bbuf = TypedArrayBuffer.wrap(input)
    bbuf.put(in)
    val output = Pako.inflate(input)
    val out = Array.ofDim[Byte](output.byteLength)
    TypedArrayBuffer.wrap(output).get(out)
    val workspace = Workspace.parseFrom(out)
    val obtained =
      workspace.toProtoString.linesIterator.toList.sorted.mkString("\n").trim
    val expected =
      """
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/Chunk.scala"
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/Doc.scala"
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/Document.scala"
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/package.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/DocumentTests.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/Generators.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/JsonTest.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/PaigesTest.scala"
      """.stripMargin.trim
    assert(obtained == expected)
  }
} 
Example 14
Source File: ReactApollo.scala    From apollo-scalajs   with MIT License 5 votes vote down vote up
package com.apollographql.scalajs.react

import slinky.core.facade.ReactElement

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-apollo", JSImport.Namespace)
object ReactApollo extends js.Object {
  val ApolloProvider: js.Object = js.native
  val Query: js.Object = js.native
  val Mutation: js.Object = js.native
}


@js.native
@JSImport("react-apollo/renderToStringWithData.js", JSImport.Namespace)
object ReactApolloServer extends js.Object {
  def renderToStringWithData(component: ReactElement): js.Promise[String] = js.native
} 
Example 15
Source File: ApolloBoost.scala    From apollo-scalajs   with MIT License 5 votes vote down vote up
package com.apollographql.scalajs

import com.apollographql.scalajs.link.Operation
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

case class ApolloBoostClientOptions(uri: String,
                                    fetchOptions: js.UndefOr[js.Object] = js.undefined,
                                    request: js.UndefOr[js.Function1[Operation, js.Promise[js.Any]]] = js.undefined,
                                    onError: js.UndefOr[js.Function1[ApolloError, js.Any]] = js.undefined)

@js.native
trait ApolloError extends js.Object {
  val operation: js.Object = js.native
  val response: js.Object = js.native
  val graphQLErrors: js.Object = js.native
  val networkError: ApolloNetworkError = js.native
}

@js.native
trait ApolloNetworkError extends js.Object {
  val name: String = js.native
  val response: js.Object = js.native
  val statusCode: Int = js.native
  val bodyText: String = js.native
}

@JSImport("apollo-boost", JSImport.Default)
@js.native
class ApolloBoostClient(options: ObjectOrWritten[ApolloBoostClientOptions]) extends ApolloClientInstance
object ApolloBoostClient {
  def apply(uri: String) = new ApolloBoostClient(ApolloBoostClientOptions(uri = uri))
} 
Example 16
Source File: ApolloClient.scala    From apollo-scalajs   with MIT License 5 votes vote down vote up
package com.apollographql.scalajs

import slinky.readwrite.{ObjectOrWritten, Reader}

import scala.concurrent.{ExecutionContext, Future}
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

case class ApolloClientOptions(link: js.Object, cache: js.Object, ssrMode: Boolean = false)

@JSImport("apollo-client", "ApolloClient")
@js.native
class ApolloClient(options: ObjectOrWritten[ApolloClientOptions]) extends ApolloClientInstance

case class QueryOptions(query: DocumentNode, variables: js.UndefOr[js.Object] = js.undefined)

case class QueryResult[T](data: T)
object QueryResult {
  implicit def reader[T](implicit tReader: Reader[T]): Reader[QueryResult[T]] = { o =>
    val dyn = o.asInstanceOf[js.Dynamic]
    QueryResult[T](
      tReader.read(dyn.data.asInstanceOf[js.Object])
    )
  }
}

@js.native
trait ApolloClientInstance extends js.Object
object ApolloClientInstance {
  @js.native
  private trait ApolloClientInstanceRawInterface extends js.Object {
    def query(options: ObjectOrWritten[QueryOptions]): js.Promise[js.Object] = js.native
  }

  implicit class RichInstance(val i: ApolloClientInstance) extends AnyVal {
    private def raw = i.asInstanceOf[ApolloClientInstanceRawInterface]
    def query[R](options: QueryOptions)(implicit ec: ExecutionContext, rReader: Reader[R]): Future[QueryResult[R]] = {
      raw.query(options).toFuture.map(QueryResult.reader(rReader).read)
    }

    def query[R](query: DocumentNode)(implicit ec: ExecutionContext, rReader: Reader[R]): Future[QueryResult[R]] = {
      raw.query(QueryOptions(query)).toFuture.map(QueryResult.reader(rReader).read)
    }

    def query[R, V](query: DocumentNode, variables: ObjectOrWritten[V])
                   (implicit ec: ExecutionContext, rReader: Reader[R]): Future[QueryResult[R]] = {
      raw.query(QueryOptions(query, variables)).toFuture.map(QueryResult.reader(rReader).read)
    }
  }
} 
Example 17
Source File: Observable.scala    From apollo-scalajs   with MIT License 5 votes vote down vote up
package com.apollographql.scalajs.link

import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
trait SubscriptionObserver[T] extends js.Object {
  var closed: Boolean = js.native
  def next(value: T): Unit = js.native
  def error(errorValue: js.Any): Unit = js.native
  def complete(): Unit = js.native
}

@js.native
trait Subscription extends js.Object {
  var closed: Boolean = js.native
  def unsubscribe(): Unit = js.native
}

@JSImport("apollo-link", "Observable")
@js.native
class Observable[T](subscriber: Subscriber[T]) extends js.Object {
  def subscribe(observerOrNext: ObjectOrWritten[T => Unit],
                error: ObjectOrWritten[js.UndefOr[js.Any => Unit]] = js.undefined,
                complete: ObjectOrWritten[js.UndefOr[() => Unit]] = js.undefined): Subscription = js.native
  def subscribe(observer: SubscriptionObserver[T]): Subscription = js.native

  def forEach(fn: js.Function1[T, Unit]): js.Promise[Unit] = js.native
} 
Example 18
Source File: History.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.history

import org.scalajs.dom.History

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
trait RichHistory extends History {
  def action: String                                = js.native
  def block(prompt: Boolean = false): Unit          = js.native
  def createHref(location: String): Unit            = js.native
  def goBack(): Unit                                = js.native
  def goForward(): Unit                             = js.native
  def listen(listener: js.Function0[Unit]): Unit    = js.native
  def location: String                              = js.native
  def push(route: String): Unit                     = js.native
  def replace(path: String, state: js.Object): Unit = js.native
}

@JSImport("history", JSImport.Default)
@js.native
object History extends js.Object {
  def createBrowserHistory(): RichHistory = js.native
} 
Example 19
Source File: Image.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react
import slinky.core.facade.ReactElement

import scala.concurrent.Future
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|
import scala.scalajs.js.JSConverters._

case class ImageURISource(
  uri: js.UndefOr[String] = js.undefined,
  bundle: js.UndefOr[String] = js.undefined,
  method: js.UndefOr[String] = js.undefined,
  headers: js.UndefOr[js.Object] = js.undefined,
  body: js.UndefOr[String] = js.undefined,
  cache: js.UndefOr[String] = js.undefined,
  width: js.UndefOr[Int] = js.undefined,
  height: js.UndefOr[Int] = js.undefined,
  scale: js.UndefOr[Double] = js.undefined
)

@js.native
trait ImageInterface extends js.Object

case class ImageErrorEvent(error: js.Error)

case class ImageProgressEvent(loaded: Int, total: Int)

@react object Image extends ExternalComponent {
  case class Props(
    style: js.UndefOr[js.Object] = js.undefined,
    blurRadius: js.UndefOr[Int] = js.undefined,
    onLayout: js.UndefOr[NativeSyntheticEvent[LayoutChangeEvent] => Unit] = js.undefined,
    onLoad: js.UndefOr[() => Unit] = js.undefined,
    onLoadEnd: js.UndefOr[() => Unit] = js.undefined,
    onLoadStart: js.UndefOr[() => Unit] = js.undefined,
    resizeMode: js.UndefOr[String] = js.undefined,
    source: js.UndefOr[ImageURISource | Int | Seq[ImageURISource]] = js.undefined,
    loadingIndicatorSource: js.UndefOr[Seq[ImageURISource | Int]] = js.undefined,
    onError: js.UndefOr[NativeSyntheticEvent[ImageErrorEvent] => Unit] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    resizeMethod: js.UndefOr[String] = js.undefined,
    accessibilityLabel: js.UndefOr[ReactElement] = js.undefined,
    accessible: js.UndefOr[Boolean] = js.undefined,
    capInsets: js.UndefOr[BoundingBox] = js.undefined,
    defaultSource: js.UndefOr[js.Object | Int] = js.undefined,
    onPartialLoad: js.UndefOr[() => Unit] = js.undefined,
    onProgress: js.UndefOr[NativeSyntheticEvent[ImageProgressEvent] => Unit] = js.undefined
  )

  @js.native
  @JSImport("react-native", "Image")
  object Component extends js.Object {
    def getSize(
      uri: String,
      success: js.Function2[Int, Int, Unit],
      failure: js.UndefOr[js.Function1[js.Error, Unit]]
    ): Unit                                                                   = js.native
    def prefetch(uri: String): Int | Unit                                     = js.native
    def abortPrefetch(requestId: Int): Unit                                   = js.native
    def queryCache(urls: js.Array[String]): js.Promise[js.Dictionary[String]] = js.native
  }

  override val component = Component

  def getSize(uri: String, success: (Int, Int) => Unit, failure: js.UndefOr[(js.Error) => Unit] = js.undefined): Unit =
    Component.getSize(uri, success, failure.map(v => v))

  def prefetch(uri: String): Int | Unit = Component.prefetch(uri)

  def abortPrefetch(requestId: Int): Unit = Component.abortPrefetch(requestId)

  def queryCache(urls: Seq[String]): Future[Map[String, String]] = {
    import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
    Component.queryCache(urls.toJSArray).toFuture.map(_.toMap)
  }
} 
Example 20
Source File: Picker.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

@react object Picker extends ExternalComponent {
  case class Props(
    onValueChange: js.UndefOr[(String | Int, Int) => Unit] = js.undefined,
    selectedValue: js.UndefOr[String | Int] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    enabled: js.UndefOr[Boolean] = js.undefined,
    mode: js.UndefOr[String] = js.undefined,
    prompt: js.UndefOr[String] = js.undefined,
    itemStyle: js.UndefOr[js.Object] = js.undefined
  )

  @js.native
  @JSImport("react-native", "Picker")
  object Component extends js.Object {
    val Item: js.Object = js.native
  }

  override val component = Component

  @react object Item extends ExternalComponent {
    case class Props(label: String, value: String | Int)

    override val component = Component.Item
  }
} 
Example 21
Source File: Clipboard.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import scala.concurrent.Future
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-native", "Clipboard")
object RawClipboard extends js.Object {
  def getString(): js.Promise[String]  = js.native
  def setString(content: String): Unit = js.native
}

object Clipboard {
  def getString: Future[String]        = RawClipboard.getString().toFuture
  def setString(content: String): Unit = RawClipboard.setString(content)
} 
Example 22
Source File: Button.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@react object Button extends ExternalComponent {
  case class Props(
    onPress: () => Unit,
    title: String,
    accessibilityLabel: js.UndefOr[String] = js.undefined,
    color: js.UndefOr[String] = js.undefined,
    disabled: js.UndefOr[Boolean] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    hasTVPreferredFocus: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-native", "Button")
  object Component extends js.Object

  override val component = Component
} 
Example 23
Source File: ActivityIndicator.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

@react object ActivityIndicator extends ExternalComponent {
  case class Props(
    animating: js.UndefOr[Boolean] = js.undefined,
    color: js.UndefOr[String] = js.undefined,
    size: js.UndefOr[String | Int] = js.undefined,
    hidesWhenStopped: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-native", "ActivityIndicator")
  object Component extends js.Object

  override val component = Component
} 
Example 24
Source File: Slider.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

@react object Slider extends ExternalComponent {
  case class Props(
    style: js.UndefOr[js.Object] = js.undefined,
    disabled: js.UndefOr[Boolean] = js.undefined,
    maximumValue: js.UndefOr[Double] = js.undefined,
    minimumTrackTintColor: js.UndefOr[String] = js.undefined,
    minimumValue: js.UndefOr[Double] = js.undefined,
    onSlidingComplete: js.UndefOr[Double => Unit] = js.undefined,
    onValueChange: js.UndefOr[Double => Unit] = js.undefined,
    step: js.UndefOr[Double] = js.undefined,
    maximumTrackTintColor: js.UndefOr[String] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    value: js.UndefOr[Double] = js.undefined,
    thumbTintColor: js.UndefOr[String] = js.undefined,
    maximumTrackImage: js.UndefOr[ImageURISource | Int | Seq[ImageURISource]] = js.undefined,
    minimumTrackImage: js.UndefOr[ImageURISource | Int | Seq[ImageURISource]] = js.undefined,
    thumbImage: js.UndefOr[ImageURISource | Int | Seq[ImageURISource]] = js.undefined,
    trackImage: js.UndefOr[ImageURISource | Int | Seq[ImageURISource]] = js.undefined
  )

  @js.native
  @JSImport("react-native", "Slider")
  object Component extends js.Object

  override val component = Component
} 
Example 25
Source File: Switch.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@react object Switch extends ExternalComponent {
  case class Props(
    disabled: js.UndefOr[Boolean] = js.undefined,
    onTintColor: js.UndefOr[String] = js.undefined,
    onValueChange: js.UndefOr[Boolean => Unit] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    thumbTintColor: js.UndefOr[String] = js.undefined,
    tintColor: js.UndefOr[String] = js.undefined,
    value: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-native", "Switch")
  object Component extends js.Object

  override val component = Component
} 
Example 26
Source File: Text.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

case class BoundingBox(top: Double, left: Double, bottom: Double, right: Double)

@react object Text extends ExternalComponent {
  case class Props(
    selectable: js.UndefOr[Boolean] = js.undefined,
    accessible: js.UndefOr[Boolean] = js.undefined,
    ellipsizeMode: js.UndefOr[String] = js.undefined,
    nativeID: js.UndefOr[String] = js.undefined,
    numberOfLines: js.UndefOr[Int] = js.undefined,
    onLayout: js.UndefOr[NativeSyntheticEvent[LayoutChangeEvent] => Unit] = js.undefined,
    onLongPress: js.UndefOr[() => Unit] = js.undefined,
    onPress: js.UndefOr[() => Unit] = js.undefined,
    pressRetentionOffset: js.UndefOr[BoundingBox] = js.undefined,
    allowFontScaling: js.UndefOr[Boolean] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    disabled: js.UndefOr[Boolean] = js.undefined,
    selectionColor: js.UndefOr[String] = js.undefined,
    textBreakStrategy: js.UndefOr[String] = js.undefined,
    adjustsFontSizeToFit: js.UndefOr[Boolean] = js.undefined,
    minimumFontScale: js.UndefOr[Double] = js.undefined,
    suppressHighlighting: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-native", "Text")
  object Component extends js.Object

  override val component = Component
} 
Example 27
Source File: View.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponent
import slinky.core.annotations.react
import slinky.core.facade.ReactElement

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

case class NativeTouchEvent(
  changedTouches: Seq[Any],
  identifier: String,
  locationX: Int,
  locationY: Int,
  pageX: Int,
  pageY: Int,
  target: String,
  timestamp: Int,
  touches: Seq[Any]
)

case class LayoutRectangle(x: Int, y: Int, width: Int, height: Int)

case class LayoutChangeEvent(layout: LayoutRectangle)

@react object View extends ExternalComponent {
  case class Props(
    onStartShouldSetResponder: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Unit] = js.undefined,
    accessibilityLabel: js.UndefOr[ReactElement] = js.undefined,
    hitSlop: js.UndefOr[BoundingBox] = js.undefined,
    nativeID: js.UndefOr[String] = js.undefined,
    onLayout: js.UndefOr[NativeSyntheticEvent[LayoutChangeEvent] => Unit] = js.undefined,
    onMagicTap: js.UndefOr[() => Unit] = js.undefined,
    onMoveShouldSetResponder: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Boolean] = js.undefined,
    onMoveShouldSetResponderCapture: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Boolean] = js.undefined,
    onResponderGrant: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Unit] = js.undefined,
    onResponderMove: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Unit] = js.undefined,
    onResponderReject: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Unit] = js.undefined,
    onResponderRelease: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Unit] = js.undefined,
    onResponderTerminate: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Unit] = js.undefined,
    onResponderTerminationRequest: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Boolean] = js.undefined,
    accessible: js.UndefOr[Boolean] = js.undefined,
    onStartShouldSetResponderCapture: js.UndefOr[NativeSyntheticEvent[NativeTouchEvent] => Boolean] = js.undefined,
    pointerEvents: js.UndefOr[String] = js.undefined,
    removeClippedSubviews: js.UndefOr[Boolean] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined,
    testID: js.UndefOr[String] = js.undefined,
    accessibilityComponentType: js.UndefOr[String] = js.undefined,
    accessibilityLiveRegion: js.UndefOr[String] = js.undefined,
    collapsable: js.UndefOr[Boolean] = js.undefined,
    importantForAccessibility: js.UndefOr[String] = js.undefined,
    needsOffscreenAlphaCompositing: js.UndefOr[Boolean] = js.undefined,
    renderToHardwareTextureAndroid: js.UndefOr[Boolean] = js.undefined,
    accessibilityTraits: js.UndefOr[String | Seq[String]] = js.undefined,
    accessibilityViewIsModal: js.UndefOr[Boolean] = js.undefined,
    shouldRasterizeIOS: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-native", "View")
  object Component extends js.Object

  override val component = Component
} 
Example 28
Source File: TextInput.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.native

import slinky.core.ExternalComponentWithRefType
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

case class ContentSize(width: Int, height: Int)
case class ContentSizeEvent(contentSize: ContentSize)
case class ContentOffset(x: Int, y: Int)
case class ContentOffsetEvent(contentOffset: ContentOffset)
case class Selection(start: Int, end: Int)
case class SelectionEvent(selection: Selection)
case class KeyPressEvent(key: String)

@js.native
trait TextInputInstance extends js.Object {
  def isFocused(): Boolean = js.native
  def clear(): Unit        = js.native
}

@react object TextInput extends ExternalComponentWithRefType[TextInputInstance] {
  case class Props(
    placeholderTextColor: js.UndefOr[String] = js.undefined,
    allowFontScaling: js.UndefOr[Boolean] = js.undefined,
    autoCorrect: js.UndefOr[Boolean] = js.undefined,
    autoFocus: js.UndefOr[Boolean] = js.undefined,
    blurOnSubmit: js.UndefOr[Boolean] = js.undefined,
    caretHidden: js.UndefOr[Boolean] = js.undefined,
    contextMenuHidden: js.UndefOr[Boolean] = js.undefined,
    defaultValue: js.UndefOr[String] = js.undefined,
    editable: js.UndefOr[Boolean] = js.undefined,
    keyboardType: js.UndefOr[String] = js.undefined,
    maxHeight: js.UndefOr[Int] = js.undefined,
    maxLength: js.UndefOr[Int] = js.undefined,
    multiline: js.UndefOr[Boolean] = js.undefined,
    onBlur: js.UndefOr[() => Unit] = js.undefined,
    onChange: js.UndefOr[() => Unit] = js.undefined,
    onChangeText: js.UndefOr[String => Unit] = js.undefined,
    onContextSizeChange: js.UndefOr[NativeSyntheticEvent[ContentSizeEvent] => Unit] = js.undefined,
    onEndEditing: js.UndefOr[() => Unit] = js.undefined,
    onFocus: js.UndefOr[() => Unit] = js.undefined,
    onLayout: js.UndefOr[NativeSyntheticEvent[LayoutChangeEvent] => Unit] = js.undefined,
    onScroll: js.UndefOr[NativeSyntheticEvent[ContentOffsetEvent] => Unit] = js.undefined,
    onSelectionChange: js.UndefOr[NativeSyntheticEvent[SelectionEvent] => Unit] = js.undefined,
    onSubmitEditing: js.UndefOr[() => Unit] = js.undefined,
    placeholder: js.UndefOr[String] = js.undefined,
    autoCapitalize: js.UndefOr[String] = js.undefined,
    returnKeyType: js.UndefOr[String] = js.undefined,
    secureTextEntry: js.UndefOr[Boolean] = js.undefined,
    selectTextOnFocus: js.UndefOr[Boolean] = js.undefined,
    selection: js.UndefOr[Selection] = js.undefined,
    selectionColor: js.UndefOr[String] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined,
    value: js.UndefOr[String] = js.undefined,
    disableFullscreenUI: js.UndefOr[Boolean] = js.undefined,
    inlineImageLeft: js.UndefOr[String] = js.undefined,
    inlineImagePadding: js.UndefOr[Int] = js.undefined,
    numberOfLines: js.UndefOr[Int] = js.undefined,
    returnKeyLabel: js.UndefOr[String] = js.undefined,
    textBreakStrategy: js.UndefOr[String] = js.undefined,
    underlineColorAndroid: js.UndefOr[String] = js.undefined,
    clearButtonMode: js.UndefOr[String] = js.undefined,
    clearTextOnFocus: js.UndefOr[Boolean] = js.undefined,
    dataDetectorTypes: js.UndefOr[String] = js.undefined,
    enablesReturnKeyAutomatically: js.UndefOr[Boolean] = js.undefined,
    keyboardAppearance: js.UndefOr[String] = js.undefined,
    onKeyPress: js.UndefOr[NativeSyntheticEvent[KeyPressEvent] => Unit] = js.undefined,
    selectionState: js.UndefOr[js.Object] = js.undefined,
    spellCheck: js.UndefOr[Boolean] = js.undefined
  )

  @js.native
  @JSImport("react-native", "TextInput")
  object Component extends js.Object

  override val component = Component
} 
Example 29
Source File: VrButton.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.vr

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@react object VrButton extends ExternalComponent {
  case class Props(
    disabled: js.UndefOr[Boolean] = js.undefined,
    ignoreLongClick: js.UndefOr[Boolean] = js.undefined,
    longClickDelayMS: js.UndefOr[Int] = js.undefined,
    onButtonPress: js.UndefOr[() => Unit] = js.undefined,
    onButtonRelease: js.UndefOr[() => Unit] = js.undefined,
    onClick: js.UndefOr[() => Unit] = js.undefined,
    onClickSound: js.UndefOr[js.Object] = js.undefined,
    onEnter: js.UndefOr[() => Unit] = js.undefined,
    onEnterSound: js.UndefOr[js.Object] = js.undefined,
    onExit: js.UndefOr[() => Unit] = js.undefined,
    onExitSound: js.UndefOr[js.Object] = js.undefined,
    onLongClick: js.UndefOr[() => Unit] = js.undefined,
    onLongClickSound: js.UndefOr[js.Object] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined
  )

  @js.native
  @JSImport("react-360", "VrButton")
  object Component extends js.Object

  override val component = Component
} 
Example 30
Source File: NativeModules.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.vr

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-360", "NativeModules")
object NativeModules extends js.Object {
  @js.native
  object VideoModule extends js.Object {
    def createPlayer(name: String): Unit                  = js.native
    def destroyPlayer(name: String): Unit                 = js.native
    def play(name: String, options: js.Object): Unit      = js.native
    def pause(name: String): Unit                         = js.native
    def resume(name: String): Unit                        = js.native
    def stop(name: String): Unit                          = js.native
    def seek(name: String, timeMs: Int): Unit             = js.native
    def setParams(name: String, options: js.Object): Unit = js.native
  }
} 
Example 31
Source File: ReactVR.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.vr

import slinky.readwrite.{Reader, Writer}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

case class NativeSyntheticEvent[T](nativeEvent: T)

object NativeSyntheticEvent {
  implicit def reader[T](implicit tReader: Reader[T]): Reader[NativeSyntheticEvent[T]] = { o =>
    NativeSyntheticEvent(tReader.read(o.asInstanceOf[js.Dynamic].nativeEvent.asInstanceOf[js.Object]))
  }

  implicit def writer[T](implicit tWriter: Writer[T]): Writer[NativeSyntheticEvent[T]] = { s =>
    js.Dynamic.literal(
      nativeEvent = tWriter.write(s.nativeEvent)
    )
  }
}

@js.native
trait Asset extends js.Object

@js.native
@JSImport("react-360", JSImport.Namespace)
object React360 extends js.Object {
  def asset(path: String): Asset = js.native
} 
Example 32
Source File: Text.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.vr

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@react object Text extends ExternalComponent {
  case class Props(
    numberOfLines: js.UndefOr[Int] = js.undefined,
    onLayout: js.UndefOr[NativeSyntheticEvent[LayoutEvent] => Unit] = js.undefined,
    onLongPress: js.UndefOr[() => Unit] = js.undefined,
    onPress: js.UndefOr[() => Unit] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined,
    testID: js.UndefOr[String] = js.undefined
  )

  @js.native
  @JSImport("react-360", "Text")
  object Component extends js.Object

  override val component = Component
} 
Example 33
Source File: View.scala    From slinky   with MIT License 5 votes vote down vote up
package slinky.vr

import slinky.core.ExternalComponent
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

case class EdgeInsets(top: Double, bottom: Double, left: Double, right: Double)
case class Layout(x: Double, y: Double, width: Double, height: Double)
case class LayoutEvent(layout: Layout)

@react object View extends ExternalComponent {
  case class Props(
    billboarding: js.UndefOr[String] = js.undefined,
    cursorVisibilitySlop: js.UndefOr[Double | EdgeInsets] = js.undefined,
    hitSlop: js.UndefOr[Double | EdgeInsets] = js.undefined,
    onEnter: js.UndefOr[() => Unit] = js.undefined,
    onExit: js.UndefOr[() => Unit] = js.undefined,
    onHeadPose: js.UndefOr[NativeSyntheticEvent[js.Object] => Unit] = js.undefined,
    onHeadPoseCaptured: js.UndefOr[() => Unit] = js.undefined,
    onInput: js.UndefOr[() => Unit] = js.undefined,
    onInputCaptured: js.UndefOr[() => Unit] = js.undefined,
    onLayout: js.UndefOr[NativeSyntheticEvent[LayoutEvent] => Unit] = js.undefined,
    onMove: js.UndefOr[() => Unit] = js.undefined,
    pointerEvents: js.UndefOr[String] = js.undefined,
    style: js.UndefOr[js.Object] = js.undefined,
    testID: js.UndefOr[String] = js.undefined
  )

  @js.native
  @JSImport("react-360", "View")
  object Component extends js.Object

  override val component = Component
} 
Example 34
Source File: JbokApp.scala    From iotchain   with MIT License 5 votes vote down vote up
package jbok.app

import com.thoughtworks.binding.Binding.{Var, _}
import com.thoughtworks.binding._
import jbok.app.components.{TabList, TabPane, Tabs}
import jbok.app.views._
import org.scalajs.dom._

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@JSImport("css/normalize.css", JSImport.Namespace)
@js.native
object NormalizeCss extends js.Object

@JSImport("css/app.css", JSImport.Namespace)
@js.native
object AppCss extends js.Object

object JbokApp {
  val normalizeCss = NormalizeCss
  val appCss       = AppCss

  val config = AppConfig.default
  val state  = AppState(Var(config))
  state.init()

  val statusView       = StatusView(state).render
  val accountsView     = AccountsView(state).render
  val blocksView       = BlocksView(state).render
  val transactionsView = TxsView(state).render
  val contractView     = ContractView(state).render
  val configView       = ConfigView(state).render
  val searchView       = SearchView(state).render

  val accountsTab = TabPane("Accounts", accountsView, Some("fa-user-circle"))
  val blocksTab   = TabPane("Blocks", blocksView, Some("fa-th-large"))
  val txsTab      = TabPane("Transactions", transactionsView, Some("fa-arrow-circle-right"))
  val contractTab = TabPane("Contract", contractView, Some("fa-file-contract"))
  val configTab   = TabPane("", configView, Some("fa-cogs"))
  val searchTab   = TabPane("Search", searchView, Some("fa-search"))
  val tabs: Vars[TabPane] = Vars(
    accountsTab,
    blocksTab,
    txsTab,
    contractTab,
    searchTab,
    configTab
  )

  val tabList   = TabList(tabs, Var(tabs.value.head))
  val searchBar = SearchBar(state, onPressEnter = (e: Event) => tabList.selected.value = searchTab).render
  state.activeSearchView(() => tabList.selected.value = searchTab)

  @dom val right: Binding[Node] =
    <div class="nav-right">
      <div class="tab searchbar">{searchBar.bind}</div>
    </div>

  val navBar = Tabs.renderTabBar(tabList, Some(right), onchange = (e: Event) => state.clearSearch())

  @dom def render: Binding[BindingSeq[Node]] =
    <header>
      {navBar.bind}
      {statusView.bind}
    </header>
    <main>
    {Tabs.renderTabContent(tabList).bind}
    </main>
    <footer>
      {Copyright.render.bind}
    </footer>

  def main(args: Array[String]): Unit =
    dom.render(document.body, render)
} 
Example 35
Source File: router_state.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description: Façade traits for @angular/router/router_state.ts (v2.2.1)

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.router

import rxjs.Observable
import rxjs.core.Subscription

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/router","RouterState")
class RouterState(root: ActivatedRoute, val snapshot: RouterStateSnapshot) extends Tree[ActivatedRoute](root)

@js.native
@JSImport("@angular/router","routerState")
class RouterStateSnapshot(val url: String, root: ActivatedRouteSnapshot) extends Tree[ActivatedRouteSnapshot](root)

@js.native
@JSImport("@angular/router","ActivatedRoute")
class ActivatedRoute(val url: Observable[js.Array[UrlSegment]],
                     val params: Observable[Params],
                     val queryParams: Observable[Params],
                     val fragment: Observable[js.UndefOr[String]],
                     val data: Observable[Data],
                     val outlet: String,
                     val component: js.Any,
                     futureSnapshot: ActivatedRouteSnapshot) extends js.Object {
//  def params: Observable[js.Dictionary[String]] = js.native
}
object ActivatedRoute {
  implicit final class RichActivatedRoute(val r: ActivatedRoute) extends AnyVal {
    @inline
    def paramsAs[T]: Observable[T] = r.params.asInstanceOf[Observable[T]]
    @inline
    def dataAs[T]: Observable[T] = r.data.asInstanceOf[Observable[T]]
    @inline
    def subscribeData[T](key: String)(f: T=>_): Subscription = r.data.subscribe((d:Data) => f(d(key).asInstanceOf[T]) )
  }
}

@js.native
@JSImport("@angular/router","ActivatedRouteSnapshot")
class ActivatedRouteSnapshot(val url: js.Array[UrlSegment],
                             val params: Params,
                             val queryParams: Params,
                             val fragment: String,
                             val data: Data,
                             val outlet: String,
                             val component: js.Any,
                             routeConfig: Route,
                             urlSegment: UrlSegmentGroup,
                             lastPathIndex: Int,
                             resolve: ResolveData) extends js.Object {
} 
Example 36
Source File: Elliptic.scala    From iotchain   with MIT License 5 votes vote down vote up
package jbok.crypto.facade

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobal, JSImport}
import scala.scalajs.js.typedarray.Uint8Array

@js.native
@JSImport("elliptic", "ec")
class EC(curve: String) extends js.Object {
  def genKeyPair(options: Option[js.Dynamic] = None): KeyPairEC = js.native
  def keyPair(options: js.Dynamic): KeyPairEC                   = js.native
  def keyFromPublic(pub: String, enc: String): KeyPairEC        = js.native
  def keyFromPrivate(priv: String, enc: String): KeyPairEC      = js.native

  def sign(msg: Uint8Array, key: KeyPairEC): SignatureEC                = js.native
  def verify(msg: Uint8Array, sig: js.Dynamic, key: KeyPairEC): Boolean = js.native

  def getKeyRecoveryParam(msg: Uint8Array, signature: js.Dynamic): Int           = js.native
  def recoverPubKey(msg: Uint8Array, signature: js.Dynamic, recId: Int): ECPoint = js.native
}

@js.native
@JSImport("elliptic/ec/key", JSImport.Default)
class KeyPairEC(ec: EC, options: js.Dynamic) extends js.Object {
  def getPublic(compact: Boolean, enc: String): String = js.native
  def getPrivate(enc: String): String                  = js.native
//  val priv: js.Any                                     = js.native
//  val pub: js.Any                                      = js.native
}

@js.native
@JSImport("elliptic/ec/signature", JSImport.Default)
class SignatureEC() extends js.Object {
  def r: Any             = js.native
  def s: Any             = js.native
  def recoveryParam: Int = js.native
}

object SignatureEC {
  def apply(r: BN, s: BN, recoveryParam: Int): js.Dynamic =
    js.Dynamic.literal(r = r, s = s, recoveryParam = recoveryParam)
}

@js.native
@JSGlobal
class ECPoint() extends js.Object {
  def encode(enc: String, compact: Boolean): String = js.native
} 
Example 37
Source File: Demo.scala    From Demos   with MIT License 5 votes vote down vote up
package demo

import org.scalajs.dom
import typings.highlightJs.mod.initHighlightingOnLoad
import typings.reveal.{RevealOptions, RevealStatic}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object Demo {
  def main(args: Array[String]): Unit = {
    // Touch to load
    Includes.HighlightingCss
    Includes.WhiteThemeCss
    Includes.RevealCss
    Includes.Reveal
    Includes.ZoomJs

    
  @JSImport("reveal.js/js/reveal.js", JSImport.Namespace)
  @js.native
  object Reveal extends RevealStatic

  @JSImport("reveal.js/plugin/zoom-js/zoom.js", JSImport.Namespace)
  @js.native
  object ZoomJs extends RevealStatic

  @JSImport("reveal.js/lib/css/zenburn.css", JSImport.Namespace)
  @js.native
  object HighlightingCss extends js.Object

  @JSImport("reveal.js/css/theme/white.css", JSImport.Namespace)
  @js.native
  object WhiteThemeCss extends js.Object

  @JSImport("reveal.js/css/reveal.css", JSImport.Namespace)
  @js.native
  object RevealCss extends js.Object
} 
Example 38
Source File: Demo.scala    From Demos   with MIT License 5 votes vote down vote up
package demo

import org.scalablytyped.runtime.{StringDictionary, TopLevel}
import typings.phaser.Phaser.Types.Animations.{Animation, GenerateFrameNames}
import typings.phaser.Phaser.Types.Core.GameConfig
import typings.phaser.Phaser.Types.GameObjects.GameObjectConfig
import typings.phaser.Phaser.Types.GameObjects.Sprite.SpriteConfig
import typings.phaser.Phaser.Types.Scenes.CreateSceneFromObjectConfig
import typings.phaser.phaserMod.{Game, Scene}
import typings.phaser.{phaserMod => Phaser}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.util.Random

object Demo {
  @JSImport("./gems.png", JSImport.Namespace)
  @js.native
  object GemsPng extends TopLevel[String]

   js.ThisFunction1[Scene, js.Object, Unit] = null,
      preload:       js.ThisFunction0[Scene, Unit]                       = null,
      update:        js.ThisFunction0[Scene, Unit]                       = null
  ): CreateSceneFromObjectConfig = {
    val __obj = js.Dynamic.literal()
    if (create != null) __obj.updateDynamic("create")(create)
    if (extend != null) __obj.updateDynamic("extend")(extend.asInstanceOf[js.Any])
    if (extendDotdata != null) __obj.updateDynamic("extend.data")(extendDotdata.asInstanceOf[js.Any])
    if (init != null) __obj.updateDynamic("init")(init)
    if (preload != null) __obj.updateDynamic("preload")(preload)
    if (update != null) __obj.updateDynamic("update")(update.asInstanceOf[js.Any])
    __obj.asInstanceOf[CreateSceneFromObjectConfig]
  }
} 
Example 39
Source File: assets.scala    From Demos   with MIT License 5 votes vote down vote up
package demo

import org.scalablytyped.runtime.TopLevel

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object assets {
  object pixiFilters {
    @js.native
    @JSImport("./assets/pixi-filters/displacement_map_repeat.jpg", JSImport.Namespace)
    object DisplacementMapRepeat extends TopLevel[String]

    @js.native
    @JSImport("./assets/pixi-filters/flag.png", JSImport.Namespace)
    object FlagImage extends TopLevel[String]
  }

  @js.native
  @JSImport("./assets/bg_grass.jpg", JSImport.Namespace)
  object BackgroundGrass extends TopLevel[String]

  @js.native
  @JSImport("./assets/bg_scene_rotate.jpg", JSImport.Namespace)
  object BackgroundSceneRotate extends TopLevel[String]

  @js.native
  @JSImport("./assets/bunny.png", JSImport.Namespace)
  object BunnyImage extends TopLevel[String]

  @js.native
  @JSImport("./assets/eggHead.png", JSImport.Namespace)
  object EggHeadImage extends TopLevel[String]

  @js.native
  @JSImport("./assets/p2.jpeg", JSImport.Namespace)
  object P2Image extends TopLevel[String]

  @js.native
  @JSImport("./assets/star.png", JSImport.Namespace)
  object StarImage extends TopLevel[String]

  @js.native
  @JSImport("./assets/video.mp4", JSImport.Namespace)
  object TheVideo extends TopLevel[String]

  @js.native
  @JSImport("./assets/trail.png", JSImport.Namespace)
  object TrailImage extends TopLevel[String]
} 
Example 40
Source File: JQueryDemo.scala    From Demos   with MIT License 5 votes vote down vote up
package demo

import org.scalajs.dom.html.{Button, Label}
import org.scalajs.dom.document
import org.scalajs.dom.raw.Element
import typings.jquery.{JQueryEventObject, JQuery_, mod => $}
import typings.jqueryui.jqueryuiRequire

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|

object JQueryDemo {
  @JSImport("jqueryui/jquery-ui.css", JSImport.Namespace)
  @js.native
  object JqueryUiCss extends js.Object

   JQueryEventObject, scala.Unit] = eo => {
      counter += 1
      $[Label]("#label").text(s"Value is $counter")
    }

    $[Button]("#button")
      .text("bumpit")
      .on("click", renderLabel)

    isJQueryUi($("#accordion")).accordion()
  }
} 
Example 41
Source File: ReactRedux.scala    From scalajs-reactjs   with MIT License 5 votes vote down vote up
package io.github.shogowada.scalajs.reactjs.redux

import io.github.shogowada.scalajs.reactjs.React
import io.github.shogowada.scalajs.reactjs.React.Props
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.Type.AS_IS
import io.github.shogowada.scalajs.reactjs.VirtualDOM.{VirtualDOMAttributes, VirtualDOMElements}
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.redux.ReactRedux.ReactReduxVirtualDOMAttributes.StoreAttributeSpec
import io.github.shogowada.scalajs.reactjs.redux.Redux.NativeDispatch
import io.github.shogowada.statictags.{Attribute, AttributeSpec}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object ReactRedux {

  import Redux.Dispatch

  implicit class ReactReduxVirtualDOMElements(elements: VirtualDOMElements) {
    lazy val Provider = elements(NativeReactReduxProvider)
  }

  object ReactReduxVirtualDOMAttributes {
    case class StoreAttributeSpec(name: String) extends AttributeSpec {
      def :=[State](store: Store[State]) = Attribute(name, store.native, AS_IS)
    }
  }

  implicit class ReactReduxVirtualDOMAttributes(attributes: VirtualDOMAttributes) {
    lazy val store = StoreAttributeSpec("store")
  }

  def connectAdvanced[ReduxState, OwnProps, WrappedProps](
      selectorFactory: Dispatch => (ReduxState, Props[OwnProps]) => WrappedProps
  ): ContainerComponentFactory[WrappedProps] = {
    val nativeSelectorFactory = selectorFactoryToNative(selectorFactory)

    val nativeFactory = NativeReactRedux.connectAdvanced(nativeSelectorFactory)
    new ContainerComponentFactory[WrappedProps](nativeFactory)
  }

  private def selectorFactoryToNative[ReduxState, OwnProps, WrappedProps](
      selectorFactory: Dispatch => (ReduxState, Props[OwnProps]) => WrappedProps
  ): js.Function1[NativeDispatch, js.Function2[ReduxState, js.Dynamic, js.Any]] =
    (nativeDispatch: NativeDispatch) => {
      val dispatch: Dispatch = ReduxInternal.dispatchFromNative(nativeDispatch)
      val selector = selectorFactory(dispatch)
      selectorToNative(selector)
    }

  private def selectorToNative[ReduxState, OwnProps, WrappedProps](
      selector: (ReduxState, Props[OwnProps]) => WrappedProps
  ): js.Function2[ReduxState, js.Dynamic, js.Any] =
    (state: ReduxState, nativeOwnProps: js.Dynamic) => {
      val ownProps: Props[OwnProps] = Props(nativeOwnProps)
      val wrappedProps: WrappedProps = selector(state, ownProps)
      val nativeProps = clone(nativeOwnProps)
      nativeProps.updateDynamic(React.WrappedProperty)(wrappedProps.asInstanceOf[js.Any])
      nativeProps
    }

  private def clone(plainObject: js.Dynamic): js.Dynamic = {
    val clonedPlainObject = js.Dynamic.literal()
    val keys = js.Object.keys(plainObject.asInstanceOf[js.Object])
    keys.foreach(key => clonedPlainObject.updateDynamic(key)(plainObject.selectDynamic(key)))
    clonedPlainObject
  }
}

@js.native
@JSImport("react-redux", "Provider")
object NativeReactReduxProvider extends ReactClass

@js.native
@JSImport("react-redux", JSImport.Namespace)
object NativeReactRedux extends js.Object {
  def connectAdvanced[State](selectorFactory: js.Function1[Redux.NativeDispatch, js.Function2[State, js.Dynamic, js.Any]]): js.Function1[js.Any, ReactClass] = js.native
} 
Example 42
Source File: RouterDOM.scala    From scalajs-reactjs   with MIT License 5 votes vote down vote up
package io.github.shogowada.scalajs.reactjs.router.dom

import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.Type.AS_IS
import io.github.shogowada.scalajs.reactjs.VirtualDOM.{VirtualDOMAttributes, VirtualDOMElements}
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.router
import io.github.shogowada.scalajs.reactjs.router.{Location, Match}
import io.github.shogowada.statictags.{AttributeSpec, _}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-router-dom", "BrowserRouter")
object NativeBrowserRouter extends ReactClass

@js.native
@JSImport("react-router-dom", "HashRouter")
object NativeHashRouter extends ReactClass

@js.native
@JSImport("react-router-dom", "Link")
object NativeLink extends ReactClass

@js.native
@JSImport("react-router-dom", "NavLink")
object NativeNavLink extends ReactClass

trait RouterDOM extends router.Router {
  implicit class RouterDOMVirtualDOMElements(elements: VirtualDOMElements) {
    lazy val BrowserRouter = elements(NativeBrowserRouter)
    lazy val HashRouter = elements(NativeHashRouter)
    lazy val Link = elements(NativeLink)
    lazy val NavLink = elements(NativeNavLink)
  }

  object RouterDOMVirtualDOMAttributes {
    case class GetUserConfirmationAttributeSpec(name: String) extends AttributeSpec {
      type Get = js.Function2[String, js.Function1[Boolean, _], _]
      def :=(get: Get): Attribute[Get] = Attribute(name, get, AS_IS)
    }

    case class HashTypeAttributeSpec(name: String) extends AttributeSpec {
      def :=(hashType: String) = Attribute(name, hashType)

      lazy val hashbang = this := ("hashbang")
      lazy val noslash = this := ("noslash")
      lazy val slash = this := ("slash")
    }

    case class IsActiveAttributeSpec(name: String) extends AttributeSpec {
      type IsActive = js.Function2[Match, Location, Boolean]
      def :=(isActive: IsActive): Attribute[IsActive] =
        Attribute(name, isActive, AS_IS)
    }
  }

  implicit class RouterDOMVirtualDOMAttributes(attributes: VirtualDOMAttributes) {

    import RouterDOMVirtualDOMAttributes._

    lazy val activeClassName = SpaceSeparatedStringAttributeSpec("activeClassName")
    lazy val activeStyle = CssAttributeSpec("activeStyle")
    lazy val basename = StringAttributeSpec("basename")
    lazy val forceRefresh = BooleanAttributeSpec("forceRefresh")
    lazy val getUserConfirmation = GetUserConfirmationAttributeSpec("getUserConfirmation")
    lazy val hashType = HashTypeAttributeSpec("hashType")
    lazy val isActive = IsActiveAttributeSpec("isActive")
    lazy val keyLength = IntegerAttributeSpec("keyLength")
    lazy val replace = BooleanAttributeSpec("replace")
  }
}

object RouterDOM extends RouterDOM 
Example 43
Source File: Router.scala    From scalajs-reactjs   with MIT License 5 votes vote down vote up
package io.github.shogowada.scalajs.reactjs.router

import io.github.shogowada.scalajs.history.History
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.Type.AS_IS
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMAttributes.{ReactClassAttributeSpec, RenderAttributeSpec}
import io.github.shogowada.scalajs.reactjs.VirtualDOM.{VirtualDOMAttributes, VirtualDOMElements}
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.statictags.{Attribute, AttributeSpec, BooleanAttributeSpec, StringAttributeSpec}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("react-router", "Prompt")
object NativePrompt extends ReactClass

@js.native
@JSImport("react-router", "Redirect")
object NativeRedirect extends ReactClass

@js.native
@JSImport("react-router", "Route")
object NativeRoute extends ReactClass

@js.native
@JSImport("react-router", "Router")
object NativeRouter extends ReactClass

@js.native
@JSImport("react-router", "Switch")
object NativeSwitch extends ReactClass

trait Router {
  implicit class RouterVirtualDOMElements(elements: VirtualDOMElements) {
    lazy val Prompt = elements(NativePrompt)
    lazy val Redirect = elements(NativeRedirect)
    lazy val Route = elements(NativeRoute)
    lazy val Router = elements(NativeRouter)
    lazy val Switch = elements(NativeSwitch)
  }

  object RouterVirtualDOMAttributes {
    case class MessageAttributeSpec(name: String) extends AttributeSpec {
      def :=(message: String) = Attribute[String](name, message)
      def :=(message: js.Function0[String]) = Attribute[js.Function0[String]](name, message, AS_IS)
    }

    case class HistoryAttributeSpec(name: String) extends AttributeSpec {
      def :=(value: History): Attribute[History] = Attribute(name, value, AS_IS)
    }

    case class LocationAttributeSpec(name: String) extends AttributeSpec {
      def :=(path: String) = Attribute[String](name, path)
      def :=(location: Location) = Attribute[Location](name, location, AS_IS)
    }
  }

  implicit class RouterVirtualDOMAttributes(attribute: VirtualDOMAttributes) {

    import RouterVirtualDOMAttributes._

    lazy val children = RenderAttributeSpec("children")
    lazy val component = ReactClassAttributeSpec("component")
    lazy val exact = BooleanAttributeSpec("exact")
    lazy val from = StringAttributeSpec("from")
    lazy val history = HistoryAttributeSpec("history")
    lazy val message = MessageAttributeSpec("message")
    lazy val path = StringAttributeSpec("path")
    lazy val push = BooleanAttributeSpec("push")
    lazy val render = RenderAttributeSpec("render")
    lazy val strict = BooleanAttributeSpec("strict")
    lazy val to = LocationAttributeSpec("to")
    lazy val when = BooleanAttributeSpec("when")
  }
}

object Router extends Router 
Example 44
Source File: ReactRouterRedux.scala    From scalajs-reactjs   with MIT License 5 votes vote down vote up
package io.github.shogowada.scalajs.reactjs.router.redux

import io.github.shogowada.scalajs.history.History
import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements
import io.github.shogowada.scalajs.reactjs.classes.ReactClass
import io.github.shogowada.scalajs.reactjs.redux.Redux.{Middleware, NativeMiddleware, Reducer}
import io.github.shogowada.scalajs.reactjs.redux.{NativeAction, ReduxInternal}

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSImport, JSName}

@js.native
@JSImport("react-router-redux", JSImport.Namespace)
object ReactRouterReduxAction extends js.Object {
  @JSName("push")
  def Push(path: String): NativeAction = js.native
  @JSName("replace")
  def Replace(path: String): NativeAction = js.native
  @JSName("go")
  def Go(delta: Int): NativeAction = js.native
  @JSName("goBack")
  def GoBack(): NativeAction = js.native
  @JSName("goForward")
  def GoForward(): NativeAction = js.native
}

object ReactRouterRedux {
  implicit class RouterReduxVirtualDOMElements(elements: VirtualDOMElements) {
    lazy val ConnectedRouter = elements(NativeReactRouterRedux.ConnectedRouter)
  }

  val routerReducer: Reducer[js.Object] =
    (state: Option[_], action: Any) => {
      val nativeState: js.Object = state.map(_.asInstanceOf[js.Object]).getOrElse(js.Object())
      val nativeAction = ReduxInternal.actionToNative(action)
      NativeReactRouterRedux.routerReducer(nativeState, nativeAction)
    }

  def routerMiddleware[State](history: History): Middleware[State] =
    ReduxInternal.middlewareFromNative(
      NativeReactRouterRedux.routerMiddleware(history)
    )
}

@js.native
@JSImport("react-router-redux", JSImport.Namespace)
object NativeReactRouterRedux extends js.Object {
  val ConnectedRouter: ReactClass = js.native

  def routerReducer(routerState: js.Object, action: NativeAction): js.Object = js.native
  def routerMiddleware(history: History): NativeMiddleware = js.native
} 
Example 45
Source File: History.scala    From scalajs-reactjs   with MIT License 5 votes vote down vote up
package io.github.shogowada.scalajs.history

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
trait History extends js.Object {
  def push(url: String): Unit = js.native
  def replace(url: String): Unit = js.native

  def go(delta: Int): Unit = js.native
  def goBack(): Unit = js.native
  def goForward(): Unit = js.native
}

@js.native
@JSImport("history", JSImport.Namespace)
object History extends js.Object {
  def createBrowserHistory(): History = js.native
  def createHashHistory(): History = js.native
  def createMemoryHistory(): History = js.native
} 
Example 46
Source File: Http.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.http

import de.surfice.smacrotools.JSOptionsObject
import rxjs.Observable

import scala.scalajs.js
import scala.scalajs.js.JSON
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/http","Http")
class Http extends js.Object {
  def get(url: String, options: js.UndefOr[RequestOptionsArgs] = js.undefined): Observable[Response] = js.native
  def post(url: String, body: js.Any, options: js.UndefOr[RequestOptionsArgs] = js.undefined): Observable[Response] = js.native
  def put(url: String, body: js.Any, options: js.UndefOr[RequestOptionsArgs] = js.undefined): Observable[Response] = js.native
  def delete(url: String, options: js.UndefOr[RequestOptionsArgs] = js.undefined): Observable[Response] = js.native
}

object Http {
//  type RequestOptionsArgs = js.Dynamic

  implicit final class RichHttp(val http: Http) extends AnyVal {
    @inline
    def putJson(url: String, data: js.Any, options: js.UndefOr[RequestOptionsArgs] = js.undefined): Observable[Response] =
      http.put(url,JSON.stringify(data),options)

    @inline
    def postJson(url: String, data: js.Any, options: js.UndefOr[RequestOptionsArgs] = js.undefined): Observable[Response] =
      http.post(url,JSON.stringify(data),options)
  }
}

@JSOptionsObject
case class RequestOptionsArgs(url: js.UndefOr[String] = js.undefined,
                              method: js.UndefOr[String] = js.undefined,
                              search: js.UndefOr[String] = js.undefined,
                              headers: js.UndefOr[Headers] = js.undefined,
                              body: js.UndefOr[js.Any] = js.undefined,
                              withCredentials: js.UndefOr[Boolean] = js.undefined,
                              responseType: js.UndefOr[ResponseContentType] = js.undefined
                              )

@JSImport("@angular/http","Headers")
@js.native
class Headers(headers: js.UndefOr[js.Dynamic] = js.undefined) extends js.Object {
  def append(name: String, value: String): Unit = js.native
  def delete(name: String): Unit = js.native
  def forEach(fn: js.Function): Unit = js.native
  def get(name: String): String = js.native
  def has(name: String): Boolean = js.native
  def keys(): js.Array[String] = js.native
  def set(name: String, value: String): Unit = js.native
}

object Headers {
  def apply(): Headers = new Headers()
  implicit final class RichHeaders(val h: Headers) extends AnyVal {
    def accept(mimeTypes: String): Headers = {
      h.set("Accept",mimeTypes)
      h
    }
    def contentType(mimeType: String): Headers = {
      h.set("Content-Type",mimeType)
      h
    }
  }
}

@js.native
trait ResponseContentType extends js.Object

@js.native
@JSImport("@angular/http","ResponseContentType")
object ResponseContentType extends js.Object {
  val Text: ResponseContentType = js.native
  val Json: ResponseContentType = js.native
  val ArrayBuffer: ResponseContentType = js.native
  val Blob: ResponseContentType = js.native
} 
Example 47
Source File: LocationStrategy.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.common

import angulate2.core.ClassProvider
import angulate2.internal.JSType

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/common","LocationStrategy")
class LocationStrategy extends js.Object {
  def path(includeHash: js.UndefOr[Boolean] = js.undefined): String = js.native
  def prepareExternalUrl(internal: String): String = js.native
  def pushState(state: js.Any, title: String, url: String, queryParams: String): Unit = js.native
  def replaceState(state: js.Any, title: String, url: String, queryParams: String): Unit = js.native
  def forward(): Unit = js.native
  def back(): Unit = js.native
  def onPopState(fn: js.Function): Unit = js.native
  def getBaseHref(): String = js.native
}


@js.native
@JSImport("@angular/common","HashLocationStrategy")
class HashLocationStrategy extends LocationStrategy

@js.native
@JSImport("@angular/common","PathLocationStrategy")
class PathLocationStrategy extends LocationStrategy 
Example 48
Source File: Location.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.common

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/common","Location")
class Location extends js.Object {
  def path(includeHash: js.UndefOr[Boolean] = js.undefined): String = js.native
  def isCurrentPathEqualTo(path: String, query: js.UndefOr[String] = js.undefined): Boolean = js.native
  def normalize(url: String): String = js.native
  def prepareExternalUrl(url: String): String = js.native
  def back(): Unit = js.native
  def forward(): Unit = js.native
  def go(path: String, query: String = ""): Unit = js.native
  def replaceState(path: String, query: String = ""): Unit = js.native
  def subscribe(onNext: js.Function1[js.Any,_],
                onThrow: js.UndefOr[js.Function1[js.Any,_]] = js.undefined,
                onReturn: js.UndefOr[js.Function0[_]] = js.undefined): js.Dynamic = js.native
} 
Example 49
Source File: utils.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.router

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/router","Tree")
class Tree[T](val root: T) extends js.Object {
}

@js.native
@JSImport("@angular/router","TreeNode")
class TreeNode[T](val value: T, val children: js.Array[TreeNode[T]]) extends js.Object 
Example 50
Source File: Router.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.router

import rxjs.{Observable, RxPromise}

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/router","Router")
class Router extends js.Object {
  def errorHandler: js.Dynamic = js.native
  def navigated: Boolean = js.native
  def urlHandlingStrategy: js.Dynamic = js.native
  def config: Routes = js.native
  def initialNavigation(): Unit = js.native
  def setUpLocationChangeListener(): Unit = js.native
  def routerState: js.Dynamic = js.native
  def url: String = js.native
  def events: Observable[js.Dynamic] = js.native
  def resetConfig(config: Routes): Unit = js.native
  def dispose(): Unit = js.native
  def createUrlTree(commands: js.Array[js.Any], extras: js.UndefOr[js.Object] = js.undefined): UrlTree = js.native
  def navigateByUrl(url: js.|[String,UrlTree], extras: js.UndefOr[js.Object] = js.undefined): RxPromise[Boolean] = js.native
  def navigate(commands: js.Array[js.Any], extras: js.UndefOr[js.Object] = js.undefined): RxPromise[Boolean] = js.native
  def serializeUrl(urlTree: UrlTree): String = js.native
  def parseUrl(url: String): UrlTree = js.native
  def isActive(url: js.|[String,UrlTree], exact: Boolean): Boolean = js.native
}

object Router {
  implicit final class RichRouter(val r: Router) extends AnyVal {
    import scalajs.js.JSConverters._
    import js.Dynamic.literal

    
    @inline
    def navigateRelativeTo(route: ActivatedRoute, commands: js.Any*): RxPromise[Boolean] =
      r.navigate(commands.toJSArray,literal(relativeTo = route))
  }
} 
Example 51
Source File: ApolloClientTest.scala    From apollo-scalajs   with MIT License 5 votes vote down vote up
package com.apollographql.scalajs

import com.apollographql.scalajs.cache.InMemoryCache
import com.apollographql.scalajs.link.{HttpLink, HttpLinkOptions}
import org.scalatest.AsyncFunSuite

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("unfetch", JSImport.Default)
object UnfetchFetch extends js.Object

class ApolloClientTest extends AsyncFunSuite {
  js.Dynamic.global.window.fetch = UnfetchFetch

  implicit override def executionContext =
    scala.concurrent.ExecutionContext.Implicits.global

  test("Can create an instance of Apollo Client") {
    assert(!js.isUndefined(new ApolloClient(ApolloClientOptions(
      link = new HttpLink(HttpLinkOptions("https://graphql-currency-rates.glitch.me")),
      cache = new InMemoryCache()
    ))))
  }

  test("Can create an instance of Apollo Client using Apollo Boost") {
    assert(!js.isUndefined(ApolloBoostClient(
      uri = "https://graphql-currency-rates.glitch.me"
    )))
  }

  test("Can perform a simple query and get the results") {
    ApolloBoostClient(
      uri = "https://graphql-currency-rates.glitch.me"
    ).query[js.Object](
      query = gql(
        """{
          |  rates(currency: "USD") {
          |    currency
          |  }
          |}""".stripMargin
      )
    ).map { r =>
      assert(r.data.asInstanceOf[js.Dynamic]
        .rates.asInstanceOf[js.Array[js.Object]].length > 0)
    }
  }

  test("Can perform a query with variables and get the results") {
    ApolloBoostClient(
      uri = "https://graphql-currency-rates.glitch.me"
    ).query[js.Object, js.Object](
      query = gql(
        """query GetRates($cur: String!) {
          |  rates(currency: $cur) {
          |    currency
          |  }
          |}""".stripMargin
      ),
      variables = js.Dynamic.literal(
        cur = "USD"
      )
    ).map { r =>
      assert(r.data.asInstanceOf[js.Dynamic]
        .rates.asInstanceOf[js.Array[js.Object]].length > 0)
    }
  }

  test("Can perform a query with typed variables and response and get the results") {
    case class Variables(cur: String)
    case class Rate(currency: String)
    case class QueryResult(rates: Seq[Rate])

    ApolloBoostClient(
      uri = "https://graphql-currency-rates.glitch.me"
    ).query[QueryResult, Variables](
      query = gql(
        """query GetRates($cur: String!) {
          |  rates(currency: $cur) {
          |    currency
          |  }
          |}""".stripMargin
      ),
      variables = Variables(
        cur = "USD"
      )
    ).map { r =>
      assert(r.data.rates.nonEmpty)
    }
  }
} 
Example 52
Source File: url_tree.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.router

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/router","UrlTree")
class UrlTree(val root: UrlSegmentGroup, val queryParams: js.Dictionary[String], val fragment: String) extends js.Object {

}

@js.native
@JSImport("@angular/router","UrlSegmentGroup")
class UrlSegmentGroup(val segments: js.Array[UrlSegment], children: js.Dictionary[UrlSegmentGroup]) extends js.Object {

}

@js.native
@JSImport("@angular/router","UrlSegment")
class UrlSegment(val path: String, val parameters: js.Dictionary[String]) extends js.Object 
Example 53
Source File: events.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.router

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/router","NavigationStart")
class NavigationStart(val id: Int, val url: String) extends js.Object

@js.native
@JSImport("@angular/router","NavigationEnd")
class NavigationEnd(val id: Int, val url: String, val urlAfterRedirects: String) extends js.Object

@js.native
@JSImport("@angular/router","NavigationCancel")
class NavigationCancel(val id: Int, val url: String, val reason: String) extends js.Object

@js.native
@JSImport("@angular/router","NavigationError")
class NavigationError(val id: Int, val url: String, val error: js.Any) extends js.Object 
Example 54
Source File: router_module.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2
// Description: Façade traits for @angular/router/router_module.ts (v2.2.1)

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.router

import angulate2.core.ModuleWithProviders

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/router","RouterModule")
class RouterModule extends js.Object

@js.native
@JSImport("@angular/router","RouterModule")
object RouterModule extends js.Object {
  def forRoot(routes: Routes, config: js.UndefOr[js.Dynamic] = js.undefined): ModuleWithProviders = js.native
  def forChild(routes: Routes): ModuleWithProviders = js.native
} 
Example 55
Source File: Injectable.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description: Angular2 @Injectable annotation.

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import angulate2.internal.ClassDecorator

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","Injectable")
object InjectableFacade extends js.Object {
  def apply() : js.Object = js.native
  def apply(options: js.Object) : js.Object = js.native
}

// NOTE: keep the constructor parameter list and Injectable.Macro.annotationParamNames in sync!
@compileTimeOnly("enable macro paradise to expand macro annotations")
class Injectable extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro Injectable.Macro.impl
}


object Injectable {

  private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator {
    import c.universe._
    override val annotationName: String = "Injectable"

    override val annotationParamNames: Seq[String] = Seq()

    override def mainAnnotationObject = q"angulate2.core.InjectableFacade"
  }
} 
Example 56
Source File: NgModule.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2
// Description: Angular2 @NgModule macro annotation

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import angulate2.internal.ClassDecorator

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","NgModule")
object NgModuleFacade extends js.Object {
  def apply() : js.Object = js.native
  def apply(options: js.Object) : js.Object = js.native
}

// NOTE: keep the constructor parameter list and Component.Macro.annotationParamNames in sync!
@compileTimeOnly("enable macro paradise to expand macro annotations")
class NgModule(providers: js.Array[js.Any] = null,
               declarations: js.Array[js.Any] = null,
               imports: js.Array[js.Any] = null,
               exports: js.Array[js.Any] = null,
               entryComponents: js.Array[js.Any] = null,
               bootstrap: js.Array[js.Any] = null,
               schemas: js.Array[js.Any] = null,
               id: String = null) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro NgModule.Macro.impl
}

object NgModule {
  private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator {
    import c.universe._

    val annotationParamNames = Seq(
      "providers",
      "declarations",
      "imports",
      "exports",
      "entryComponents",
      "bootstrap",
      "schemas",
      "id"
    )

    override val annotationName: String = "NgModule"

    override def mainAnnotationObject = q"angulate2.core.NgModuleFacade"
  }

} 
Example 57
Source File: Renderer.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
//      Module: @angular/core/Renderer

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","Renderer")
class Renderer extends js.Any {
  import Renderer._
  def selectRootElement(selectorOrNode: js.Any, debugInfo: OptRenderDebugInfo = js.undefined) : js.Any = js.native
  def createElement(parentElement: js.Any, name: String, debugInfo: OptRenderDebugInfo = js.undefined) : js.Any = js.native
  def createViewRoot(hostElement: js.Any) : js.Any = js.native
  def createTemplateAnchor(parentElement: js.Any, debugInfo: OptRenderDebugInfo = js.undefined) : js.Any = js.native
  def createText(parentElement: js.Any, value: String, debugInfo: OptRenderDebugInfo = js.undefined) : js.Any = js.native
  def projectNodes(parentElement: js.Any, nodes: js.Array[js.Any]) : Unit = js.native
  def attachViewAfter(node: js.Any, viewRootNodes: js.Array[js.Any]) : Unit = js.native
  def detachView(viewRootNodes: js.Array[js.Any]) : Unit = js.native
  def destroyView(hostElement: js.Any, viewAllNodes: js.Array[js.Any]) : Unit = js.native
  def listen(renderElement: js.Any, name: String, callback: js.Function) : js.Function = js.native
  def listenGlobal(target: String, name: String, callback: js.Function) : js.Function = js.native
  def setElementProperty(renderElement: js.Any, propertyName: String, propertyValue: js.Any) : Unit = js.native
  def setElementAttribute(renderElement: js.Any, attributeName: String, attributeValue: String) : Unit = js.native
  def setBindingDebugInfo(renderElement: js.Any, propertyName: String, propertyValue: String) : Unit = js.native
  def setElementClass(renderElement: js.Any, className: String, isAdd: Boolean) : Unit = js.native
  def setElementStyle(renderElement: js.Any, styleName: String, styleValue: String) : Unit = js.native
  def invokeElementMethod(renderElement: js.Any, methodName: String, args: OptAnyArray = js.undefined) : Unit = js.native
  def setText(renderNode: js.Any, text: String) : Unit = js.native
  def animate(element: js.Any, startingStyles: AnimationStyles, keyframes: js.Array[AnimationKeyframe], duration: Int, delay: Int, easing: String, previousPlayers: js.UndefOr[js.Array[AnimationPlayer]] = js.undefined) : AnimationPlayer = js.native
}

object Renderer {
  type RenderDebugInfo = js.Dynamic
  type OptRenderDebugInfo = js.UndefOr[RenderDebugInfo]
  type AnimationStyles = js.Dynamic
  type AnimationKeyframe = js.Dynamic
  type AnimationPlayer = js.Dynamic
} 
Example 58
Source File: Pipe.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import angulate2.internal.ClassDecorator
import de.surfice.smacrotools.createJS

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","Pipe")
object PipeFacade extends js.Object {
  def apply(options: js.Object) : js.Object = js.native
}

// NOTE: keep the constructor parameter list and Directive.Macro.annotationParamNames in sync!
@compileTimeOnly("enable macro paradise to expand macro annotations")
class Pipe(name: String, pure: Boolean = true) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro Pipe.Macro.impl
}

object Pipe {

  private[angulate2] class Macro(val c: whitebox.Context) extends ClassDecorator {
    import c.universe._
    val annotationParamNames = Seq(
      "name",
      "pure"
    )

    override val annotationName: String = "Pipe"

    override def mainAnnotationObject = q"angulate2.core.PipeFacade"
  }
}

@createJS
trait PipeTransform0[T,R] {
  def transform(value: T): R
}

@createJS
trait PipeTransform1[T,A1,R] {
  def transform(value: T, arg1: A1): R
}

@createJS
trait PipeTransform2[T,A1,A2,R] {
  def transform(value: T, arg1: A1, arg2: A2): R
}

@createJS
trait PipeTransform3[T,A1,A2,A3,R] {
  def transform(value: T, arg1: A1, arg2: A2, arg3: A3): R
} 
Example 59
Source File: linker.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","ElementRef")
class ElementRef(_nativeElement: js.Any) extends js.Any {
  def nativeElement: js.Dynamic = js.native
}

object ElementRef {
  import org.scalajs.dom.html.Element

  final implicit class RichElementRef(val e: ElementRef) extends AnyVal {
    def htmlElement: Element = e.nativeElement.asInstanceOf[Element]
  }
}

@js.native
trait ComponentFactory[T] extends js.Object {
  def selector: String = js.native
  def create(injector: Injector,
             projectableNodes: js.UndefOr[js.Array[js.Array[js.Any]]] = js.undefined,
             rootSelectorOrNode: js.UndefOr[js.Any] = js.undefined): ComponentRef[T] = js.native
}

@js.native
trait ComponentRef[T] extends js.Object {
  def location: ElementRef = js.native
  def injector: Injector = js.native
  def instance: T = js.native
  def hostView: ViewRef = js.native
}

@js.native
trait ViewRef extends js.Object {
  def destroy(): Unit = js.native
  def destroyed: Boolean = js.native
  def onDestroy(callback: js.Function): Unit = js.native
}

@js.native
@JSImport("@angular/core","ViewContainerRef")
class ViewContainerRef extends js.Object {
  def element: ElementRef = js.native
  def injector: Injector = js.native
  def parentInjector: Injector = js.native
  def clear(): Unit = js.native
  def get(index: Int): ViewRef = js.native
  def length: Int = js.native
  def createComponent[T](componentFactory: ComponentFactory[T],
                         index: js.UndefOr[Int] = js.undefined,
                         injector: js.UndefOr[Injector] = js.undefined,
                         projectableNodes: js.UndefOr[js.Array[js.Array[js.Any]]] = js.undefined): ComponentRef[T] = js.native
  def insert(viewRef: ViewRef, index: js.UndefOr[Int] = js.undefined): ViewRef = js.native
  def move(viewRef: ViewRef, currentIndex: Int): ViewRef = js.native
  def indexOf(viewRef: ViewRef): Int = js.native
  def remove(index: js.UndefOr[Int] = js.undefined): Unit = js.native
  def detach(index: js.UndefOr[Int]): ViewRef = js.native
} 
Example 60
Source File: Directive.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description: Angular2 @Directive macro annotation

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import angulate2.internal.{ClassDecorator, FieldDecorator}

import scala.annotation.{StaticAnnotation, compileTimeOnly}
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","Directive")
object DirectiveFacade extends js.Object {
  def apply(options: js.Object) : js.Object = js.native
}

// NOTE: keep the constructor parameter list and Directive.Macro.annotationParamNames in sync!
@compileTimeOnly("enable macro paradise to expand macro annotations")
class Directive(selector: String = null,
                inputs: js.Array[String] = null,
                outputs: js.Array[String] = null,
                host: js.Dictionary[String] = null,
                template: String = null,
                providers: js.Array[js.Any] = null,
                exportAs: String = null,
                queries: js.Any = null) extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro Directive.Macro.impl
}


object Directive {

  private[angulate2] abstract class BaseMacro extends ClassDecorator with FieldDecorator

  private[angulate2] class Macro(val c: whitebox.Context) extends BaseMacro {
    import c.universe._

    override def annotationName = "Directive"

    override def mainAnnotationObject: c.universe.Tree = q"angulate2.core.DirectiveFacade"

    override def annotationParamNames: Seq[String] = Seq(
      "selector",
      "inputs",
      "outputs",
      "host",
      "template",
      "providers",
      "exportAs",
      "queries"
    )
  }
} 
Example 61
Source File: EventEmitter.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2016 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.core

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/core","EventEmitter")
class EventEmitter[T](isAsync: js.UndefOr[Boolean] = js.undefined) extends js.Any {
  def emit(value: js.UndefOr[T] = js.undefined): Unit = js.native
  def subscribe(generatorOrNext: js.UndefOr[js.Any] = js.undefined, error: js.UndefOr[js.Any] = js.undefined, complete: js.UndefOr[js.Any] = js.undefined): js.Any = js.native
} 
Example 62
Source File: JitCompiler.scala    From angulate2   with MIT License 5 votes vote down vote up
//     Project: angulate2 (https://github.com/jokade/angulate2)
// Description:

// Copyright (c) 2017 Johannes.Kastner <[email protected]>
//               Distributed under the MIT License (see included LICENSE file)
package angulate2.compiler

import angulate2.core.{ModuleWithComponentFactories, NgModuleFactory, Type}
import rxjs.RxPromise
import sun.security.pkcs11.Secmod.ModuleType

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@angular/compiler","JitCompiler")
class JitCompiler extends js.Object {
  def compileModuleSync[T](moduleType: Type[T]): NgModuleFactory[T] = js.native
  def compileModuleAsync[T](moduleType: Type[T]): RxPromise[NgModuleFactory[T]] = js.native
  def compileModuleAndAllComponentsSync[T](moduleType: Type[T]): ModuleWithComponentFactories[T] = js.native
  def compileModuleAndAllComponentsAsync[T](moduleType: Type[T]): RxPromise[ModuleWithComponentFactories[T]] = js.native
} 
Example 63
Source File: IO.scala    From scala-commons   with MIT License 5 votes vote down vote up
package com.avsystem.commons
package testutil

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSBracketAccess, JSGlobal, JSImport}

@js.native
@JSImport("fs", JSImport.Namespace)
object NodeFS extends js.Object {
  def readFileSync(path: String, encoding: String = js.native): String = js.native
  def writeFileSync(path: String, data: String, encoding: String = js.native): Unit = js.native
}

@js.native
@JSImport("path", JSImport.Namespace)
object NodePath extends js.Object {
  val sep: String = js.native
}

@js.native
@JSGlobal("process.env")
object NodeEnv extends js.Object {
  @JSBracketAccess
  def get(name: String): String = js.native
}

object IO {
  private final val ResourcesPath = NodeEnv.get("RESOURCES_DIR")

  private def nativePath(path: String): String =
    ResourcesPath + path.replaceAllLiterally("/", NodePath.sep)

  def readTestResource(path: String): String =
    NodeFS.readFileSync(nativePath(path), "UTF-8")

  def writeTestResource(path: String, data: String): Unit =
    NodeFS.writeFileSync(nativePath(path), data, "UTF-8")
} 
Example 64
Source File: SaxWrapper.scala    From xml-lens   with MIT License 5 votes vote down vote up
package pl.msitko.xml.parsing

import scala.scalajs.js
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("@msitko/sax/lib/sax.js", JSImport.Namespace)
private [parsing] object sax extends js.Object {
  def parser(strict: Boolean, dictionary: js.Dictionary[Boolean]): parser = js.native
}

@js.native
private [parsing] trait Writer extends js.Object {
  def close(): Unit = js.native
}

@js.native
private [parsing] trait parser extends js.Object {
  var ontext: js.Function1[String, Unit] = js.native
  var onprocessinginstruction: js.Function1[JsProcessingInstruction, Unit] = js.native
  var onsgmldeclaration: js.Function0[Unit] = js.native
  var ondoctype: js.Function1[String, Unit] = js.native
  var oncomment: js.Function1[String, Unit] = js.native
  var onopentagstart: js.Function0[Unit] = js.native
  var onattribute: js.Function1[JsAttribute, Unit] = js.native
  var onopentag: js.Function1[JsNode, Unit] = js.native
  var onclosetag: js.Function0[Unit] = js.native
  var onopencdata: js.Function0[Unit] = js.native
  var oncdata: js.Function1[String, Unit] = js.native
  var onclosecdata: js.Function0[Unit] = js.native
  var onerror: js.Function1[js.Error, Unit] = js.native
  var onend: js.Function0[Unit] = js.native
  var onready: js.Function0[Unit] = js.native
  var onscript: js.Function0[Unit] = js.native
  var onopennamespace: js.Function0[Unit] = js.native
  var onentityreference: js.Function1[String, Unit] = js.native

  def write(input: String): Writer = js.native
}

@js.native
private [parsing] trait JsProcessingInstruction extends js.Object {
  val name: String = js.native
  val body: String = js.native
}

@js.native
private [parsing] trait JsNode extends js.Object {
  val name: String = js.native
  val attributes: js.Dictionary[JsAttribute] = js.native
  val ns: js.Dictionary[String] = js.native

  // If the xmlns option is set, then it will contain namespace binding information on the ns member, and will have a local, prefix, and uri member.
  val local: String = js.native
  val prefix: String = js.native
  val uri: String = js.native
}

@js.native
private [parsing] trait JsAttribute extends js.Object {
  val name: String = js.native // e.g. `prefix:attrName`
  val value: String = js.native
  val prefix: String = js.native
  val local: String = js.native
  val uri: String = js.native
}

object JsParser {
  def apply(strict: Boolean, options: JsParserOptions): parser = {
    sax.parser(strict, options.toDict)
  }
}

final case class JsParserOptions(
  trim: Option[Boolean] = None,
  normalize: Option[Boolean] = None,
  lowercase: Option[Boolean] = None,
  xmlns: Option[Boolean] = None,
  position: Option[Boolean] = None,
  strictEntities: Option[Boolean] = None
) {
  def toDict: js.Dictionary[Boolean] = {
    val empty = Map.empty[String, Boolean]

    val fields = List(
      trim.fold(empty)(b => Map("trim" -> b)),
      normalize.fold(empty)(b => Map("normalize" -> b)),
      lowercase.fold(empty)(b => Map("lowercase" -> b)),
      xmlns.fold(empty)(b => Map("xmlns" -> b)),
      position.fold(empty)(b => Map("position" -> b)),
      strictEntities.fold(empty)(b => Map("strictEntities" -> b))
    )

    fields.reduce(_ ++ _).toJSDictionary
  }
} 
Example 65
Source File: Main.scala    From coursier   with Apache License 2.0 5 votes vote down vote up
package coursier.web

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel, JSImport}
import org.scalajs.dom.document

// Initializing bootstrap, like
// https://getbootstrap.com/docs/4.0/getting-started/webpack/#importing-javascript
// but from scala-js, see e.g.
// https://github.com/scalacenter/scalajs-bundler/issues/62#issuecomment-266695471
@js.native
@JSImport("bootstrap", JSImport.Namespace)
object Bootstrap extends js.Object

@js.native
@JSImport("bootstrap-treeview", JSImport.Namespace)
object BootstrapTreeView extends js.Object

@JSExportTopLevel("CoursierWeb")
object Main {
  @JSExport
  def main(args: Array[String]): Unit = {

    println("bootstrap")
    val bootstrap = Bootstrap

    println("bootstrap-treeview")
    val bootstrapTreeView = BootstrapTreeView

    println("Initializing")
    App.app()
      .renderIntoDOM(document.getElementById("demoContent"))
    println("Initialized")
  }
} 
Example 66
Source File: Dracula.scala    From coursier   with Apache License 2.0 5 votes vote down vote up
package coursier.web

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@js.native
@JSImport("graphdracula", JSImport.Namespace)
object Dracula extends js.Object {
  def Graph: js.Dynamic = js.native
  def Layout: Layout = js.native
  def Renderer: Renderer = js.native
}

@js.native
trait Layout extends js.Any {
  def Spring: js.Dynamic
}

@js.native
trait Renderer extends js.Any {
  def Raphael: js.Dynamic
}