A general element

An element can be a NativeNode , a Component , or a VirtualNode .

Hierarchy (view full)

Constructors

Properties

Accessors

Methods

addListener appendChild applySlotUpdates applySlotValueUpdates asElement asGeneralComponent asInstanceOf asNativeNode asShadowRoot asTextNode asVirtualNode cancelDestroyBackendElementOnDetach cancelDestroyBackendElementOnRemoval checkComponentPlaceholder collectMarks createComponent createComponentByDef createComponentOrNativeNode createIntersectionObserver createNativeNode createNativeNodeWithInit createTextNode createVirtualNode destroyBackendElement destroyBackendElementOnDetach destroyBackendElementOnRemoval destroyBackendElementOnSubtree dispatchEvent forEachComposedChild forEachNodeInSlot forEachNodeInSpecifiedSlot forEachNonVirtualComposedChild forEachSlot forEachSlotContentInSlot forEachSlotContentInSpecifiedSlot getAttribute getBackendContext getBackendElement getBackendMode getBoundingClientRect getComposedChildren getComposedParent getContainingSlot getContext getElementById getHostNode getScrollOffset getSlotContentArray getSlotElementFromName getSlotMode insertBefore insertChildAt insertChildren isConnected isInheritSlots isVirtual iterateComposedChild matchSelector querySelector querySelectorAll removeAttribute removeChild removeChildAt removeChildren removeListener replaceChild replaceChildAt replaceSlotValue selfReplaceWith setAttribute setDataset setDynamicSlotHandler setMark setNodeClass setNodeStyle toggleNodeClass triggerEvent updateAttribute useDynamicSlotHandlerFrom _$spliceSlotNodes _$updateContainingSlot createShadowRoot forEachNodeInSlot forEachNodeInSpecificSlot forEachSlotContentInSlot forEachSlotContentInSpecificSlot getInheritSlots getSlotName hasSubtreeMutationObservers insertChildReassign isAttached matchSelector parseSelector pretendAttached pretendDetached replaceDocumentElement setInheritSlots setSlotElement setSlotName

Constructors

Properties

[ELEMENT_SYMBOL]: true
[VIRTUAL_NODE_SYMBOL]: true
childNodes: Node[]

The child nodes (must not be modified directly!)

classList: null | ClassList

The ClassList of the element (will never change and must not be modified!)

containingSlot: undefined | null | glassEasel.Element

The parent slot element in composed tree (must not be modified directly!)

dataset: {
    [name: string]: unknown;
}

Type declaration

  • [name: string]: unknown
is: string
ownerShadowRoot: null | ShadowRoot

The shadow-root which owns the element (will never change and must not be modified!)

parentIndex: number

The index in parentNode.childNodes (-1 if no parentNode) (must not be modified directly!)

parentNode: null | glassEasel.Element

The parent element (must not be modified directly!)

slotIndex: undefined | number

The index in containingSlot.slotNodes (must not be modified directly!)

slotNodes: undefined | Node[]

The slot content nodes composed tree (must not be modified directly!)

isElement: ((e) => e is glassEasel.Element)

Type declaration

isShadowRoot: ((e) => e is ShadowRoot)

Type declaration

isVirtualNode: ((e) => e is VirtualNode)

Type declaration

Accessors

  • get attributes(): {
        name: string;
        value: unknown;
    }[]
  • Returns {
        name: string;
        value: unknown;
    }[]

  • get class(): string
  • Returns string

  • set class(classNames): void
  • Parameters

    • classNames: string

    Returns void

  • get id(): string
  • Returns string

  • set id(x): void
  • Parameters

    • x: unknown

    Returns void

  • get slot(): string
  • Returns string

  • set slot(x): void
  • Parameters

    • x: string

    Returns void

  • get style(): string
  • Returns string

  • set style(styleText): void
  • Parameters

    • styleText: string

    Returns void

Methods

  • Parameters

    Returns void

  • Returns void

  • Apply slot value updates

    Parameters

    Returns void

  • Cast an element to a native node

    Returns null if the element is not a native node.

    Returns null | NativeNode

  • Cast an element to a shadow root

    Returns null if the element is not a shadow root.

    Returns null | ShadowRoot

  • Cast a node to a text node

    Returns null if the element is not a text node.

    Returns null

  • Cast an element to a virtual node

    Returns null if the element is not a virtual node.

    Returns null | VirtualNode

  • Cancel the destroy scheduling of the backend element

    Returns void

    Deprecated

    Use cancelDestroyBackendElementOnRemoval instead.

  • Find whether this component is placeholding or not

    This method will only find in the component using list and generics list. If not found, returns undefined . If the placeholder will be used, returns true ; false otherwise.

    Parameters

    • usingKey: string

    Returns undefined | boolean

  • Collect the marks on the element

    The marks includes the marks on ancestors (in shadow tree) of the element. If multiple marks on different elements shares the same name, the mark value on the child-most element is accepted.

    Returns {
        [name: string]: unknown;
    }

    • [name: string]: unknown
  • Create a component if possible

    Placeholding status should be checked with checkComponentPlaceholder . This function may create a native node if the using target is native node.

    Parameters

    Returns NativeNode | glassEasel.GeneralComponent

  • Create a component if the given tag name is a component in the space, or a native node if not

    The component using map is not used. Consider using checkComponentPlaceholder to check if the tag name is in the using map. The global using registered with ComponentSpace.prototype.getGlobalUsingComponent is still used.

    Parameters

    • tagName: string
    • Optional genericTargets: {
          [key: string]: string;
      }
      • [key: string]: string
    • Optional initPropValues: ((comp) => void)

    Returns NativeNode | glassEasel.GeneralComponent

  • Create an intersection observer

    The relativeElement is the element to calculate intersection with ( null for the viewport). The relativeElementMargin is the margins of the relativeElement . The thresholds is a list of intersection ratios to trigger the listener . The listener always triggers once immediately after this call.

    Parameters

    • relativeElement: null | glassEasel.Element
    • relativeElementMargin: string
    • thresholds: number[]
    • listener: ((res) => void)
        • (res): void
        • Parameters

          • res: IntersectionStatus

          Returns void

    Returns null | Observer

  • Parameters

    • tagName: string

    Returns NativeNode

  • Parameters

    • tagName: string
    • stylingName: string
    • placeholderHandlerRemover: undefined | (() => void)
    • Optional initPropValues: ((comp) => void)
        • (comp): void
        • Parameters

          Returns void

    Returns NativeNode

  • Parameters

    • Optional text: string

    Returns TextNode

  • Parameters

    • Optional virtualName: string

    Returns VirtualNode

  • Destroy the backend element

    It only destroy the backend element of the element itself.

    Returns void

  • Destroy the backend element when removed from any parent element

    Returns void

    Deprecated

    Use destroyBackendElementOnRemoval instead.

  • Destroy the backend element when removed from any parent element

    Returns void

  • Destroy backend element for the whole subtree.

    It will destroy backend elements for the whole subtree (shadow tree) recursively. If a backend element for a component is destroyed, any backend element in the shadow tree of the component will also be destroyed.

    Returns void

  • Trigger an event with specified event object on the element

    Parameters

    Returns void

  • Iterate composed child nodes (including virtual nodes)

    if f returns false then the iteration is interrupted. Returns true if that happens.

    Parameters

    • f: ((node) => boolean | void)
        • (node): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

  • Iterate through elements ahd their corresponding slots (including slots-inherited nodes)

    Parameters

    • f: ((node, slot) => boolean | void)

      A function to execute for each element. Return false to break the iteration.

        • (node, slot): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

    A boolean indicating whether the iteration is complete.

  • Iterate through elements of a specified slot (including slots-inherited nodes)

    Parameters

    • slot: null | glassEasel.Element
    • f: ((node) => boolean | void)

      A function to execute for each element. Return false to break the iteration.

        • (node): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

    A boolean indicating whether the iteration is complete.

  • Iterate non-virtual composed child nodes

    if f returns false then the iteration is interrupted. Returns true if that happens.

    Parameters

    • f: ((node) => boolean | void)
        • (node): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

  • Iterate slots

    Parameters

    • f: ((slot) => boolean | void)

    Returns void

  • Iterate through elements ahd their corresponding slots (NOT including slots-inherited nodes)

    Parameters

    • f: ((node, slot) => boolean | void)

      A function to execute for each element. Return false to break the iteration.

        • (node, slot): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

    A boolean indicating whether the iteration is complete.

  • Iterate through elements of a specified slot (NOT including slots-inherited nodes)

    Parameters

    • slot: null | glassEasel.Element
    • f: ((node) => boolean | void)

      A function to execute for each element. Return false to break the iteration.

        • (node): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

    A boolean indicating whether the iteration is complete.

  • Get an attribute value ( null if not set or removed)

    Parameters

    • name: string

    Returns unknown

  • Get the bounding client rect

    Return zero values when the backend element is invalid or it does not have layout information.

    Parameters

    Returns void

  • Get the composed children

    This method always returns a new array. It is convenient but less performant. For better performance, consider using forEachComposedChild .

    Returns Node[]

  • Get the slot element for the slot content

    The provided node must be a valid child node of the host of this shadow root. Otherwise the behavior is undefined.

    Parameters

    Returns null | glassEasel.Element

  • Get an interactive context

    Parameters

    • cb: ((res) => void)
        • (res): void
        • Parameters

          • res: unknown

          Returns void

    Returns void

  • Get the bounding client rect

    Return zero values when the backend element is invalid or it does not have layout information.

    Parameters

    Returns void

  • Get the elements that should be composed in specified slot

    This method always returns a new array (or null if the specified slot is invalid). It is convenient but less performant. For better performance, consider using forEachNodeInSpecifiedSlot .

    Parameters

    Returns null | Node[]

  • Get slot mode

    Returns SlotMode

  • Parameters

    Returns void

  • Parameters

    • child: Node
    • index: number

    Returns void

  • Parameters

    • children: Node[]
    • index: number

    Returns void

  • Check whether a node is connected to this shadow root

    Parameters

    Returns boolean

  • Get whether the slot-inherit mode is set or not

    Returns boolean

  • Get whether the node is virtual or not

    Returns boolean

  • Iterate composed child nodes (including virtual nodes)

    if f returns false then the iteration is interrupted. Returns true if that happens.

    Returns Generator<Node, void, void>

  • Test whether the target in this subtree matches the selector

    Parameters

    Returns boolean

  • Remove an attribute

    Parameters

    • name: string

    Returns void

  • Parameters

    Returns void

  • Parameters

    • index: number

    Returns void

  • Parameters

    • index: number
    • count: number

    Returns void

  • Parameters

    Returns void

  • Parameters

    • child: Node
    • index: number

    Returns void

  • Update a slot value

    The updated value should be applied with applySlotValueUpdates call.

    Parameters

    Returns void

  • Set an attribute value

    Parameters

    • name: string
    • value: unknown

    Returns void

  • Set a dataset on the element

    Parameters

    • name: string
    • value: unknown

    Returns void

  • Set the dynamic slot handlers

    If the handlers have not been set yet, the insertSlotHandler will be called for each slot that has been added to the shadow tree, otherwise call updateSlotHandler for each slots.

    Parameters

    • requiredSlotValueNames: string[]
    • insertSlotHandler: ((slots) => void)
        • (slots): void
        • Parameters

          • slots: {
                name: string;
                slot: glassEasel.Element;
                slotValues: {
                    [name: string]: unknown;
                };
            }[]

          Returns void

    • removeSlotHandler: ((slots) => void)
    • updateSlotHandler: ((slot, slotValues, updatePathTree) => void)
        • (slot, slotValues, updatePathTree): void
        • Parameters

          • slot: glassEasel.Element
          • slotValues: {
                [name: string]: unknown;
            }
            • [name: string]: unknown
          • updatePathTree: {
                [name: string]: true;
            }
            • [name: string]: true

          Returns void

    Returns void

  • Set a mark on the element

    Parameters

    • name: string
    • value: unknown

    Returns void

  • Set the node class

    Parameters

    Returns void

  • Set the node style

    Parameters

    Returns void

  • Toggle the node class

    Parameters

    Returns void

  • Trigger an event on the element

    Parameters

    • name: string
    • Optional detail: unknown
    • Optional options: EventOptions

    Returns void

  • Update an attribute value

    Parameters

    • name: string
    • value: unknown

    Returns void

  • Use the same dynamic slot handlers with the source

    Parameters

    Returns void

  • Parameters

    Returns void

  • Iterate elements with their slots (slots-inherited nodes included)

    Parameters

    • node: Node
    • f: ((node, slot) => boolean | void)
        • (node, slot): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

  • Iterate elements in specified slot (slots-inherited nodes included)

    Parameters

    • node: Node
    • slot: undefined | null | glassEasel.Element
    • f: ((node) => boolean | void)
        • (node): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

  • Iterate elements with their slots (slots-inherited nodes NOT included)

    Parameters

    • node: Node
    • f: ((node, slot) => boolean | void)
        • (node, slot): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

  • Iterate elements in specified slot (slots-inherited nodes NOT included)

    Parameters

    • node: Node
    • slot: undefined | null | glassEasel.Element
    • f: ((node) => boolean | void)
        • (node): boolean | void
        • Parameters

          Returns boolean | void

    Returns boolean

  • Get whether the slot-inherit mode is set or not

    Parameters

    Returns boolean

  • Get the slot name of the element

    Parameters

    Returns undefined | string

  • Get whether a node has any subtree MutationObserver attached to it

    If there is, then tree update may have more performance impact.

    Parameters

    Returns boolean

  • Check the element is attached or not

    Parameters

    Returns boolean

  • Make the element looks like attached.

    If the element will never be attached to backend or it has no backend element at all, this can be used to trigger attached life-time.

    Parameters

    Returns void

  • Make the element looks like detached.

    This can be used to trigger detached life-time without remove the element in the backend.

    Parameters

    Returns void

  • Attach the element into the backend, swapping out a placeholder element in the backend.

    The element must not be a child node of another element, must not be attached before, and must not have a ownerShadowRoot . The element targetParent and targetNode must be in the same backend context. The element replaces the targetNode in the targetParent .

    Parameters

    Returns void

  • Set the virtual node to slot-inherit mode

    In slot-inherit mode of an element, the child nodes of the element will be treated as siblings and can have different target slot.

    Parameters

    Returns void

  • Set the binding slot of specific node

    Necessary if node belongs to a dynamic slot, which cannot be identified by slot name.

    Parameters

    Returns void

  • Set the slot name of the element

    Once this method is called for an element , it will be treated as a slot which can contain child nodes in composed tree. This method should not be used in components, otherwise the slot content will always be dangled.

    Parameters

    Returns void