• Move one element of a flat, parent-referencing array — either reordering it among its current siblings or re-parenting it to another group — and return a new array (#780).

    Since body.structure stores zones, parts, and locations as flat sibling arrays, a child's position "within its parent" is just its relative order among the array elements sharing that parent code. Moving it therefore means splicing it to the flat slot currently occupied by the destination group's toPosition-th member, after re-stamping its parent code.

    Placement rules:

    • toPosition past the destination group's end inserts after its last member.
    • A destination group with no members appends to the end of the array.
    • An out-of-range fromIndex returns an unchanged copy.

    Never mutates the input.

    Type Parameters

    • T

      The persisted element shape.

    Parameters

    • items: readonly T[]

      The source flat array (not mutated).

    • fromIndex: number

      Index of the element to move.

    • toGroup: string

      Parent code of the destination group (its current parent for a plain reorder).

    • toPosition: number

      Target position among the destination group's members, counted after the element has been removed.

    • getGroup: (item: T) => string

      Reads an element's parent code.

    • setGroup: (item: T, group: string) => T

      Returns a copy of an element stamped with a new parent code.

    Returns T[]

    A new array with the element moved (and re-parented if needed).