gradum-kit - v0.1.0
    Preparing search index...

    Class GradumNodeList<Type>

    GradumNodeList

    A composable, Set-like collection of nodes. A single list can mix individual nodes, live DOM collections (HTMLCollection or NodeList), and nested GradumNodeLists. Iteration resolves all of them in order and de-duplicates, so entries added to a sub-list or to the DOM show up without re-registering anything. Entries are held weakly, so a node removed from the document drops out of the list on its own.

    Type Parameters

    • Type extends object = object

      The type of the nodes held in the list.

    Index
    • Type Parameters

      • Type extends object = object

        The type of the nodes held in the list.

      Parameters

      • Optional...values: (Type | NodeListType<Type>)[]

        Optional initial value(s) to populate the list with.

      Returns GradumNodeList<Type>

    onChanged: Delegate<(entry: Type, state: "added" | "removed") => void> = ...

    Delegate fired whenever an entry is added to or removed from the list, including entries from nested GradumNodeLists, HTMLCollections, and NodeListOf instances.

    • set observeDomLists(value: boolean): void

      Parameters

      • value: boolean

      Returns void

      Whether to observe added HTMLCollections and NodeListOf instances for DOM mutations, automatically firing onChanged when nodes are added or removed from the DOM.

    • get list(): Set<Type>

      Returns Set<Type>

      A Set snapshot of all entries in this list, without duplicates.

    • set list(value: NodeListType<Type>): void

      Parameters

      Returns void

    • get array(): Type[]

      Returns Type[]

      An array snapshot of all entries in this list, without duplicates.

    • get size(): number

      Returns number

      The number of resolved unique entries in this list. For the number of slots, see slotCount.

    • get slotCount(): number

      Returns number

      The number of slots in this list. Individual entries, HTMLCollections, NodeListOf instances, and nested GradumNodeLists each count as one slot, regardless of how many entries they contain. For the number of resolved entries, see size.

    • Protected Function

      isGradumNodeList

      Parameters

      • entry: any

        The value to check.

      Returns entry is GradumNodeList<Type>

      Whether the value is a GradumNodeList.

      Type guard — returns true if the given value is a GradumNodeList.

    • Protected Function

      isDomList

      Parameters

      • entry: any

        The value to check.

      Returns entry is HTMLCollection | NodeListOf<Type & Node>

      Whether the value is a DOM list.

      Type guard — returns true if the given value is an HTMLCollection or NodeListOf.

    • Protected Function

      isSet

      Parameters

      • entry: any

        The value to check.

      Returns entry is Set<Type> | Type[]

      Whether the value is a Set or array.

      Type guard — returns true if the given value is a Set or an array.

    • Protected Function

      isEntry

      Parameters

      • entry: any

        The value to check.

      Returns entry is Type

      Whether the value is an individual entry.

      Type guard — returns true if the given value is an individual node entry (i.e. not a GradumNodeList, DOM list, Set, array, or WeakRef).

    • Returns IterableIterator<Type>

      Iterates over all resolved unique entries in slot order, skipping ignored and duplicate entries.

    • Protected Function

      resolveSlot

      Parameters

      Returns IterableIterator<Type>

      The entries this slot resolves to, in order.

      Expand a single slot into the entries it currently stands for — every entry of a sub-list or DOM list, or the one node of an individual slot. Yields nothing once the slot's referent has been garbage-collected, which is how dead entries leave the list.

    • Parameters

      • callback: (value: Type, set: this) => void

        Called once per entry.

      • OptionalthisArg: any

        Value to bind as this inside the callback.

      Returns this

      Itself, allowing for method chaining.

      Run a callback for each resolved unique entry, in slot order. Ignored and duplicate entries are skipped.

    • Function

      add

      Parameters

      Returns this

      Itself, allowing for method chaining.

      Adds one or more entries to the end of the list. Entries may be individual nodes, arrays, Sets, HTMLCollections, NodeListOf instances, or nested GradumNodeLists.

    • Function

      addAt

      Parameters

      • index: number

        The resolved entry index to insert at.

      • ...entries: (Type | NodeListType<Type>)[]

        The entries to add.

      Returns this

      Itself, allowing for method chaining.

      Adds one or more entries at the given resolved size index. The index refers to the position among resolved unique entries, not slots. Arrays and Sets are expanded inline.

    • Function

      addAtSlot

      Parameters

      • index: number

        The slot index to insert at.

      • ...entries: (Type | NodeListType<Type>)[]

        The entries to add.

      Returns this

      Itself, allowing for method chaining.

      Adds one or more entries at the given slot index. Subsequent entries are inserted consecutively after the previous one. Arrays and Sets are expanded inline, each item occupying the next slot index.

    • Function

      remove

      Parameters

      Returns this

      Itself, allowing for method chaining.

      Removes one or more entries from the list. Entries may be individual nodes, arrays, Sets, HTMLCollections, NodeListOf instances, or nested GradumNodeLists.

    • Function

      removeAtSlot

      Parameters

      • index: number

        The slot index to start removing from.

      • Optionalcount: number = 1

        The number of consecutive slots to remove.

      Returns this

      Itself, allowing for method chaining.

      Removes one or more slots starting at the given slot index. Each slot removed may correspond to an individual entry, a DOM list, or a nested GradumNodeList.

    • Function

      move

      Parameters

      • entry: Type

        The entry to move.

      • index: number

        The resolved entry index to move the entry to.

      Returns this

      Itself, allowing for method chaining.

      Moves an existing entry to the given resolved size index. If the entry is a member of a nested GradumNodeList, it is moved within that sub-list. If it belongs to a DOM list, it is repositioned in the DOM accordingly.

    • Function

      moveToSlot

      Parameters

      • entry: Type

        The entry to move.

      • index: number

        The slot index to move the entry to.

      Returns this

      Itself, allowing for method chaining.

      Moves an existing entry to the given slot index.

    • Function

      has

      Parameters

      Returns boolean

      Whether the entry or entries are present in the list.

      Checks whether the given entry or entries are present in the list.

      • For GradumNodeLists and DOM lists, checks if they belong to this list.
      • For arrays and Sets, returns true only if every item is present.
    • Function

      clear

      Returns this

      Itself, allowing for method chaining.

      Clears all entries from the list, firing onChanged for every resolved entry.

    • Protected Function

      addEntry

      Parameters

      • entry: Type | NodeListType<Type>

        The entry to add.

      • Optionalindex: number

        The slot index to insert at. Defaults to the end of the slot array.

      Returns number

      The next available slot index after this insertion, for consecutive chaining.

      Add one value of any accepted shape. Arrays and sets are expanded so each item takes its own slot; everything else occupies a single slot. Values already present are ignored, and sub-lists and DOM lists start being watched from here.

    • Protected Function

      removeEntry

      Parameters

      Returns void

      Remove one value of any accepted shape. Arrays and sets are expanded and removed item by item. An individual entry stays suppressed even if a sub-list or DOM list it belongs to still resolves to it, and sub-lists and DOM lists stop being watched from here.

    • Protected Function

      insertOrRemoveSlot

      Parameters

      • slot: NodeListSlot<Type>

        The slot value to insert or remove.

      • state: "added" | "removed"

        Whether to insert or remove the slot.

      • Optionalindex: number

        Slot index for insertion. Ignored on removal.

      Returns number

      The next available slot index after the operation, for consecutive chaining.

      Insert or drop a single slot and announce it, firing onChanged once per entry the slot resolves to. An out-of-range insertion index is clamped to the ends.

    • Function

      attachObserver

      Parameters

      Returns void

      Attaches a MutationObserver to the parent of the first node in the given DOM list, firing onChanged when nodes matching the list are added to or removed from the DOM. Does nothing if an observer is already attached for this list, or if no parent node is found.

    • Protected Function

      sizeIndexToSlotIndex

      Parameters

      • sizeIndex: number

        The resolved entry index, clamped to the current size.

      Returns number

      The matching slot index.

      Translate a position among resolved entries into the slot index that holds it. The two differ whenever a slot resolves to more than one entry, as DOM lists and sub-lists do.

    • Protected Function

      findContainingSlot

      Parameters

      • entry: Type

        The entry to locate.

      Returns NodeListSlot<Type>

      The containing slot, or undefined if not found.

      Finds the slot that directly contains or resolves to the given entry. Returns the slot itself if the entry is a direct slot, the nested GradumNodeList that contains it, or the DOM list that contains it.