Skip to content

Commit 1ff8a07

Browse files
authored
Merge pull request #697 from peter-jerry-ye/custom-element
Partial façade for custom element support
2 parents 06e386f + 029db0e commit 1ff8a07

File tree

11 files changed

+1103
-0
lines changed

11 files changed

+1103
-0
lines changed

api-reports/2_12.txt

+487
Large diffs are not rendered by default.

api-reports/2_13.txt

+487
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
@js.native
6+
sealed trait ShadowRootMode extends js.Any
7+
8+
object ShadowRootMode {
9+
val open: ShadowRootMode = "open".asInstanceOf[ShadowRootMode]
10+
val closed: ShadowRootMode = "closed".asInstanceOf[ShadowRootMode]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.scalajs.dom
2+
3+
opaque type ShadowRootMode <: String = String
4+
5+
object ShadowRootMode {
6+
val open: ShadowRootMode = "open"
7+
val closed: ShadowRootMode = "closed"
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation._
11+
12+
/** The CustomElementRegistry interface provides methods for registering custom elements and querying registered
13+
* elements. To get an instance of it, use the window.customElements property.
14+
*/
15+
@js.native
16+
@JSGlobal
17+
abstract class CustomElementRegistry extends js.Object {
18+
19+
/** Defines a new custom element. */
20+
def define(name: String, constructor: js.Dynamic, options: ElementDefinitionOptions = js.native): Unit
21+
}

dom/src/main/scala/org/scalajs/dom/Element.scala

+6
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,10 @@ abstract class Element extends Node with NodeSelector with ParentNode with NonDo
259259
* pointerlockerror events at the Document level.
260260
*/
261261
def requestPointerLock(): Unit = js.native
262+
263+
/** Attaches a shadow DOM tree to the specified element and returns a reference to its ShadowRoot. */
264+
def attachShadow(init: ShadowRootInit): ShadowRoot = js.native
265+
266+
/** Returns the open shadow root that is hosted by the element, or null if no open shadow root is present. */
267+
def shadowRoot: ShadowRoot = js.native
262268
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** An ElementDefinitionOptions object represents additional options associated with CustomElementRegsitry.define. */
6+
trait ElementDefinitionOptions extends js.Object {
7+
8+
/** String specifying the name of a built-in element to extend. Used to create a customized built-in element. */
9+
var `extends`: js.UndefOr[String] = js.undefined
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation._
11+
12+
/** The HTMLTemplateElement interface enables access to the contents of an HTML <template> element. */
13+
@js.native
14+
@JSGlobal
15+
abstract class HTMLTemplateElement extends HTMLElement {
16+
17+
/** A read-only DocumentFragment which contains the DOM subtree representing the <template> element's template
18+
* contents.
19+
*/
20+
def content: DocumentFragment = js.native
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation._
11+
12+
/** The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree that is rendered separately from a
13+
* document's main DOM tree.
14+
*
15+
* You can retrieve a reference to an element's shadow root using its Element.shadowRoot property, provided it was
16+
* created using Element.attachShadow() with the mode option set to open.
17+
*/
18+
@js.native
19+
@JSGlobal
20+
abstract class ShadowRoot extends DocumentFragment {
21+
22+
/** Returns the Element within the shadow tree that has focus. */
23+
def activeElement: Element = js.native
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** A ShadowRootInit object represents additional options associated with Element.attachShadow. */
6+
trait ShadowRootInit extends js.Object {
7+
8+
/** A string specifying the encapsulation mode for the shadow DOM tree. This can be one of:
9+
*
10+
* open: Elements of the shadow root are accessible from JavaScript outside the root, for example using
11+
* Element.shadowRoot: element.shadowRoot; // Returns a ShadowRoot obj
12+
*
13+
* closed: Denies access to the node(s) of a closed shadow root from JavaScript outside it: element.shadowRoot; //
14+
* Returns null
15+
*/
16+
var mode: ShadowRootMode
17+
18+
/** A boolean that, when set to true, specifies behavior that mitigates custom element issues around focusability.
19+
* When a non-focusable part of the shadow DOM is clicked, the first focusable part is given focus, and the shadow
20+
* host is given any available :focus styling.
21+
*/
22+
var delegatesFocus: js.UndefOr[Boolean] = js.undefined
23+
}

dom/src/main/scala/org/scalajs/dom/Window.scala

+5
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,9 @@ class Window
445445
* number. You can get the number of pixels the document is scrolled horizontally from the scrollX property.
446446
*/
447447
def scrollY: Double = js.native
448+
449+
/** Returns a reference to the CustomElementRegistry object, which can be used to register new custom elements and get
450+
* information about previously registered custom elements.
451+
*/
452+
def customElements: CustomElementRegistry = js.native
448453
}

0 commit comments

Comments
 (0)