Skip to content

Partial façade for custom element support #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
487 changes: 487 additions & 0 deletions api-reports/2_12.txt

Large diffs are not rendered by default.

487 changes: 487 additions & 0 deletions api-reports/2_13.txt

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions dom/src/main/scala-2/org/scalajs/dom/ShadowRootMode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.scalajs.dom

import scala.scalajs.js

@js.native
sealed trait ShadowRootMode extends js.Any

object ShadowRootMode {
val open: ShadowRootMode = "open".asInstanceOf[ShadowRootMode]
val closed: ShadowRootMode = "closed".asInstanceOf[ShadowRootMode]
}
8 changes: 8 additions & 0 deletions dom/src/main/scala-3/org/scalajs/dom/ShadowRootMode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.scalajs.dom

opaque type ShadowRootMode <: String = String

object ShadowRootMode {
val open: ShadowRootMode = "open"
val closed: ShadowRootMode = "closed"
}
21 changes: 21 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/CustomElementRegistry.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** The CustomElementRegistry interface provides methods for registering custom elements and querying registered
* elements. To get an instance of it, use the window.customElements property.
*/
@js.native
@JSGlobal
abstract class CustomElementRegistry extends js.Object {

/** Defines a new custom element. */
def define(name: String, constructor: js.Dynamic, options: ElementDefinitionOptions = js.native): Unit
}
6 changes: 6 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/Element.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,10 @@ abstract class Element extends Node with NodeSelector with ParentNode with NonDo
* pointerlockerror events at the Document level.
*/
def requestPointerLock(): Unit = js.native

/** Attaches a shadow DOM tree to the specified element and returns a reference to its ShadowRoot. */
def attachShadow(init: ShadowRootInit): ShadowRoot = js.native

/** Returns the open shadow root that is hosted by the element, or null if no open shadow root is present. */
def shadowRoot: ShadowRoot = js.native
}
10 changes: 10 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ElementDefinitionOptions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.scalajs.dom

import scala.scalajs.js

/** An ElementDefinitionOptions object represents additional options associated with CustomElementRegsitry.define. */
trait ElementDefinitionOptions extends js.Object {

/** String specifying the name of a built-in element to extend. Used to create a customized built-in element. */
var `extends`: js.UndefOr[String] = js.undefined
}
21 changes: 21 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/HTMLTemplateElement.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** The HTMLTemplateElement interface enables access to the contents of an HTML <template> element. */
@js.native
@JSGlobal
abstract class HTMLTemplateElement extends HTMLElement {

/** A read-only DocumentFragment which contains the DOM subtree representing the <template> element's template
* contents.
*/
def content: DocumentFragment = js.native
}
24 changes: 24 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ShadowRoot.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree that is rendered separately from a
* document's main DOM tree.
*
* You can retrieve a reference to an element's shadow root using its Element.shadowRoot property, provided it was
* created using Element.attachShadow() with the mode option set to open.
*/
@js.native
@JSGlobal
abstract class ShadowRoot extends DocumentFragment {

/** Returns the Element within the shadow tree that has focus. */
def activeElement: Element = js.native
}
23 changes: 23 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/ShadowRootInit.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.scalajs.dom

import scala.scalajs.js

/** A ShadowRootInit object represents additional options associated with Element.attachShadow. */
trait ShadowRootInit extends js.Object {

/** A string specifying the encapsulation mode for the shadow DOM tree. This can be one of:
*
* open: Elements of the shadow root are accessible from JavaScript outside the root, for example using
* Element.shadowRoot: element.shadowRoot; // Returns a ShadowRoot obj
*
* closed: Denies access to the node(s) of a closed shadow root from JavaScript outside it: element.shadowRoot; //
* Returns null
*/
var mode: ShadowRootMode

/** A boolean that, when set to true, specifies behavior that mitigates custom element issues around focusability.
* When a non-focusable part of the shadow DOM is clicked, the first focusable part is given focus, and the shadow
* host is given any available :focus styling.
*/
var delegatesFocus: js.UndefOr[Boolean] = js.undefined
}
5 changes: 5 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/Window.scala
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,9 @@ class Window
* number. You can get the number of pixels the document is scrolled horizontally from the scrollX property.
*/
def scrollY: Double = js.native

/** Returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and get
* information about previously registered custom elements.
*/
def customElements: CustomElementRegistry = js.native
}