All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dispalt.vdom.package.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016 Dan Di Spaltro
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dispalt

import org.scalajs.dom
import org.scalajs.dom.html

import scala.scalajs.js
import scala.scalajs.js.annotation.JSName

/*
 * Scalatags version = cdf3d4797236a7d31dc413c1c8ba45466ea4a1c6
 */
package object vdom {

  /** https://facebook.github.io/react/docs/events.html */
  @js.native
  trait SyntheticEvent[+DOMEventTarget <: dom.Node] extends js.Object {
    val bubbles: Boolean              = js.native
    val cancelable: Boolean           = js.native
    val currentTarget: DOMEventTarget = js.native
    def defaultPrevented: Boolean     = js.native
    val eventPhase: Double            = js.native
    val isTrusted: Boolean            = js.native
    val nativeEvent: dom.Event        = js.native
    val target: DOMEventTarget        = js.native
    val timeStamp: js.Date            = js.native

    /**
      * Stops the default action of an element from happening.
      * For example: Prevent a submit button from submitting a form Prevent a link from following the URL
      */
    def preventDefault(): Unit = js.native

    /**
      * Stops the bubbling of an event to parent elements, preventing any parent event handlers from being executed.
      */
    def stopPropagation(): Unit = js.native

    def isPropagationStopped(): Boolean = js.native

    @JSName("type") val eventType: String = js.native

    /**
      * If you want to access the event properties in an asynchronous way, call this on the event, which will remove the
      * synthetic event from the pool and allow references to the event to be retained by user code.
      */
    def persist(): Unit = js.native
  }

  final type ReactEventB = SyntheticEvent[dom.Node]
  final type ReactEventI = SyntheticEvent[html.Input]
  type TopNode           = dom.Element

  val EmptyTag: TagMod = new TagMod {
    def applyTo(t: Builder) = ()
  }

  trait Tags     extends HtmlTags with Extra.Tags
  trait JustTags extends Tags { final def svg = SvgTags }
  object Tags    extends JustTags

  trait Attrs     extends HtmlAttrs with Extra.Attrs with HtmlStyles with BootstrapAttrs
  trait JustAttrs extends Attrs { final def svg = SvgAttrs }
  object Attrs    extends JustAttrs

  // If you're wondering why abstract class instead of trait, https://issues.scala-lang.org/browse/SI-4767
  abstract class Base extends Implicits {
    final type ReactTagOf[+N <: TopNode] = com.dispalt.vdom.ReactTagOf[N]
    final type ReactTag                  = com.dispalt.vdom.ReactTagOf[TopNode]
    final type TagMod                    = com.dispalt.vdom.TagMod
    final type ReactAttr                 = com.dispalt.vdom.ReactAttr
    final type ReactStyle                = com.dispalt.vdom.ReactStyle

    @inline final def TagMod     = com.dispalt.vdom.TagMod
    @inline final def EmptyTag   = com.dispalt.vdom.EmptyTag
    @inline final def ReactAttr  = com.dispalt.vdom.ReactAttr
    @inline final def ReactStyle = com.dispalt.vdom.ReactStyle
  }

  object all extends Base with Tags with Attrs {
    object svg extends SvgTags with SvgAttrs
    @inline def keyAttr = key
    @inline def refAttr = ref
  }

  object prefix_<^ extends Base {
    @inline def < = Tags
    @inline def ^ = Attrs
  }

  object svg {
    object all extends Base with SvgTags with SvgAttrs

    object prefix_<^ extends Base {
      @inline def < = SvgTags
      @inline def ^ = SvgAttrs
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy