A wrapper for DOM nodes, to store changes to be applied to the DOM structure later on.

Type Parameters

  • N extends Node = Node

Hierarchy (view full)

Constructors

  • Constructor.

    Type Parameters

    • N extends Node = Node

    Parameters

    • delegate: N

      delegate to wrap

    • mutable: boolean = true

      signals, if this representation is mutable or not

    Returns NodeProxy<N>

Accessors

  • get delegate(): N
  • Returns the wrapped delegate.

    This delegate should not be used for directly manipulating the DOM, as nested rules may not veto applied changes.

    If a manipulation is done, it must be ensured, that previously run rules on this node may be rerun. It is generally considered safe to do manipulation to child elements, as these are processed after this node, so that all applicable rules have a chance to modify these nodes again.

    Returns N

  • get empty(): boolean
  • Signals, if this node is empty, thus, has no child nodes.

    Returns boolean

    See

    isEmpty

  • get lastNode(): boolean
  • Signals, if this is the last node in parent. Always false if no parent exists.

    Returns boolean

  • get mutable(): boolean
  • Signals, if this element is mutable.

    Returns boolean

  • get name(): string
  • Retrieves the name of the node (lower case).

    Returns string

  • get ownerDocument(): null | Document
  • Access owner document.

    Returns null | Document

  • get realName(): string
  • Retrieves the name of the node (lower case). If renaming is supported by this instance, it may differ from name, otherwise, it is the same.

    Returns string

  • get remove(): boolean
  • Signals, if this node is meant to be removed. This includes recursive removal (including children) as well as just removing this node (replacing it by its children).

    Returns boolean

  • set remove(remove): void
  • Signals, if this mutable element represents a state, where the element shall be removed, including all its children.

    It is important to note, that setting this modifies the NodeProxy#state, thus setting this overrides any other decisions upon the state of the node.

    Duplicate Spaces: If you apply this modification, it may end up having duplicate space characters in your DOM. For example if removing the `` element (and all its children) in this scenario:

    Lorem Ipsum Dolor
    
    you will end up having:
    Lorem  Dolor
    
    with two white space characters in the middle. You may want to detect such states, and remove the duplicate space. You shouldn't do this, though, if you are within a space preserving context such as `
    `.

    Parameters

    • remove: boolean

    Returns void

  • get removeChildren(): boolean
  • Signals, if this node represents a state, where the children of the node should be removed.

    Returns boolean

  • set removeChildren(remove): void
  • Sets, if this node represents a state, where the children of the node shall be removed.

    It is important to note, that setting this modifies the NodeProxy#state, thus setting this overrides any other decisions upon the state of the node.

    Parameters

    • remove: boolean

      true to mark as remove children; false otherwise.

    Returns void

  • get replaceByChildren(): boolean
  • Signals, if this node represents a state, where the node shall be removed, while attaching the children to the parent node.

    Returns boolean

  • set replaceByChildren(replace): void
  • Sets, if this node represents a state, where the node shall be removed, while attaching the children to the parent node.

    It is important to note, that setting this modifies the NodeProxy#state, thus setting this overrides any other decisions upon the state of the node.

    Parameters

    • replace: boolean

      true to mark as replace with children; false otherwise.

    Returns void

  • get singleton(): boolean
  • Signals, if this is the only child node at parent node.

    Returns boolean

Methods

  • Helper function for return value, which signals to continue with another node, but to do not abort current processing.

    Parameters

    • node: undefined | null | Node

      node to continue with

    Returns PersistResponse

  • Get first (matching) child node of the given element.

    Parameters

    • Optional condition: string | ChildPredicate

      string: the node name to match (ignoring case), predicate: the predicate to apply.

    Returns null | NodeProxy<ChildNode>

  • Signals, if this element is empty.

    Parameters

    • Optional considerChildNode: ChildPredicate

      signals, if a given node shall be considered while determining empty state

    Returns boolean

  • Persists the applied changes to the DOM.

    Returns void

  • Persists, to keep the current node. May be overwritten for example to apply additional changes to the node like changing attributes of an element.

    Returns PersistResponse

  • Will raise an error, if this element is not mutable.

    Returns void

  • Wraps the given node into a NodeProxy. If the node is falsy, null will be returned.

    Type Parameters

    • T extends Node

    Parameters

    • node: undefined | null | T

      node to wrap

    • mutable: boolean = true

      signals, if this representation is mutable or not

    Returns null | NodeProxy<T>

    NodeProxy for given node; null for falsy values