@tempots/dom

DOMContext class

DOMContext is an immutable class that represents the context of a DOM element. It provides methods and properties to manipulate and interact with the DOM element.

A reference in a DOMContext is to mark a position within a set of sibblings. It is used to insert new elements before the reference.

Signature:

declare class DOMContext 

Constructors

Constructor

Modifiers

Description

(constructor)(document, element, reference, providers, isFirstLevel)

Constructs a new DOMContext instance.

Properties

Property

Modifiers

Type

Description

appendOrInsert

readonly

(child: Node) => void

Appends or inserts a child node to the element, depending on whether a reference node is provided.

createElement

readonly

(tagName: string, namespace: string | undefined) => Element

Creates a new DOM element (eg: HTML or SVG) with the specified tag name and namespace.

createText

readonly

(text: string) => Text

Creates a new text node with the specified text content.

document

readonly

Document

The Document instance associated with this context.

element

readonly

Element

The Element instance associated with this context.

getProvider

readonly

(mark: ProviderMark) => T

Retrieves a provider for the given provider mark.

isFirstLevel

readonly

boolean

A boolean value indicating whether this context is at the first level, meaning the outermost node in the generated

makeRef

readonly

() => DOMContext

Creates a new DOMContext with a reference to a newly created text node. The text node is appended or inserted to the current DOMContext. The new DOMContext with the reference is returned.

providers

readonly

Providers

The Providers instance associated with this context.

reference

readonly

Node | undefined

An optional Node instance that serves as a reference for this context.

withDocument

readonly

(document: Document) => DOMContext

Creates a new DOMContext instance with the provided document.

withElement

readonly

(element: Element) => DOMContext

Creates a new DOMContext instance with the provided element.

withFirstLevel

readonly

() => DOMContext

Creates a new DOMContext instance with the isFirstLevel property set to true.

withProvider

readonly

(mark: ProviderMark, value: T) => DOMContext

Creates a new DOMContext with the provided provider value.

withProviders

readonly

(providers: { [K in ProviderMark]: unknown; }) => DOMContext

Returns a new DOMContext instance with the specified providers merged into the existing providers.

withReference

readonly

(reference: Text | undefined) => DOMContext

Creates a new DOMContext instance with the specified reference.

Methods

Method

Modifiers

Description

of(element, ref)

static

Creates a new DOMContext instance for the given Element and optional reference Node.