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

wvlet.airframe.rx.html.HtmlAttrs.scala Maven / Gradle / Ivy

/*
 * 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 wvlet.airframe.rx.html

import scala.language.dynamics
import HtmlTags.*

/**
  * This code is borrowed from ScalaTags by Li Haoyi: from
  * https://github.com/lihaoyi/scalatags/blob/master/scalatags/src/scalatags/generic/Attrs.scala
  */
/**
  * A trait for global attributes that are applicable to any HTML5 element. All traits that define Attrs should derive
  * from this trait since all groupings of attributes should include these global ones.
  */
trait GlobalAttrs {

  /**
    * Specifies a shortcut key to activate/focus an element
    */
  lazy val accesskey = attr("accesskey")

  /**
    * This attribute is a space-separated list of the classes of the element. Classes allows CSS and Javascript to
    * select and access specific elements via the class selectors or functions like the DOM method
    * document.getElementsByClassName. You can use cls as an alias for this attribute so you don't have to
    * backtick-escape this attribute.
    *
    * MDN
    */
  lazy val `class` = attr("class")

  /**
    * Shorthand for the `class` attribute
    */
  lazy val cls             = `class`
  lazy val _class          = `class`
  lazy val contenteditable = attr("contenteditable") // Specifies whether the content of an element is editable or not
  lazy val contextmenu =
    attr(
      "contextmenu"
    ) // Specifies a context menu for an element. The context menu appears when a user right-clicks on the element

  /**
    * This class of attributes, called custom data attributes, allows proprietary information to be exchanged between
    * the HTML and its DOM representation that may be used by scripts. All such custom data are available via the
    * HTMLElement interface of the element the attribute is set on. The HTMLElement.dataset property gives access to
    * them.
    *
    * The * may be replaced by any name following the production rule of xml names with the following restrictions:
    *
    * the name must not start with xml, whatever case is used for these letters; the name must not contain any semicolon
    * (U+003A); the name must not contain capital A to Z letters.
    *
    * Note that the HTMLElement.dataset attribute is a StringMap and the name of the custom data attribute
    * data-test-value will be accessible via HTMLElement.dataset.testValue as any dash (U+002D) is replaced by the
    * capitalization of the next letter (camelcase).
    *
    * MDN
    */
  // object data extends DataAttribute(List("data"))

  def data(suffix: String) = attr("data-" + suffix)

  /**
    * Specifies the text direction for the content in an element. The valid values are:
    *
    *   - `ltr` Default. Left-to-right text direction
    *
    *   - `rtl` Right-to-left text direction
    *
    *   - `auto` Let the browser figure out the text direction, based on the content, (only recommended if the text
    *     direction is unknown)
    */
  lazy val dir = attr("dir")

  /**
    * A Boolean attribute that specifies whether an element is draggable or not
    */
  lazy val draggable = attr("draggable").noValue

  /**
    * Specifies whether the dragged data is copied, moved, or linked, when dropped
    */
  lazy val dropzone = attr("dropzone")

  /**
    * Specifies that an element is not yet, or is no longer, relevant and consequently hidden from view of the user.
    */
  lazy val hidden = attr("hidden").noValue

  /**
    * This attribute defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to
    * identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).
    *
    * MDN
    */
  lazy val id = attr("id")

  /**
    * This attribute participates in defining the language of the element, the language that non-editable elements are
    * written in or the language that editable elements should be written in. The tag contains one single entry value in
    * the format defines in the Tags for Identifying Languages (BCP47) IETF document. If the tag content is the empty
    * string the language is set to unknown; if the tag content is not valid, regarding to BCP47, it is set to invalid.
    *
    * MDN
    */
  lazy val lang = attr("lang")

  /**
    * This enumerated attribute defines whether the element may be checked for spelling errors.
    *
    * MDN
    */
  lazy val spellcheck = attr("spellcheck").noValue

  /**
    * This attribute contains CSS styling declarations to be applied to the element. Note that it is recommended for
    * styles to be defined in a separate file or files. This attribute and the style element have mainly the purpose of
    * allowing for quick styling, for example for testing purposes.
    *
    * MDN
    */
  lazy val style = attr("style")

  /**
    * This integer attribute indicates if the element can take input focus (is focusable), if it should participate to
    * sequential keyboard navigation, and if so, at what position. It can takes several values:
    *
    *   - a negative value means that the element should be focusable, but should not be reachable via sequential
    *     keyboard navigation;
    *   - 0 means that the element should be focusable and reachable via sequential keyboard navigation, but its
    *     relative order is defined by the platform convention;
    *   - a positive value which means should be focusable and reachable via sequential keyboard navigation; its
    *     relative order is defined by the value of the attribute: the sequential follow the increasing number of the
    *     tabindex. If several elements share the same tabindex, their relative order follows their relative position in
    *     the document).
    *
    * An element with a 0 value, an invalid value, or no tabindex value should be placed after elements with a positive
    * tabindex in the sequential keyboard navigation order.
    */
  lazy val tabindex = attr("tabindex")

  /**
    * This attribute contains a text representing advisory information related to the element it belongs too. Such
    * information can typically, but not necessarily, be presented to the user as a tooltip.
    *
    * MDN
    */
  lazy val title = attr("title")

  /**
    * Specifies whether the content of an element should be translated or not
    */
  lazy val translate = attr("translate").noValue
}

trait SharedEventAttrs {

  /**
    * Script to be run when an error occurs when the file is being loaded
    */
  lazy val onerror = attr("onerror")
}

/**
  * Clipboard Events
  */
trait ClipboardEventAttrs {

  /**
    * Fires when the user copies the content of an element
    */
  lazy val oncopy = attr("oncopy")

  /**
    * Fires when the user cuts the content of an element
    */
  lazy val oncut = attr("oncut")

  /**
    * Fires when the user pastes some content in an element
    */
  lazy val onpaste = attr("onpaste")
}

/**
  * Media Events - triggered by media like videos, images and audio. These apply to all HTML elements, but they are most
  * common in media elements, like