Skip to main content

reorderNodes()v4.0.533

Moves one or more nodes as a group before or after a sibling. The moved nodes keep their source order. For ordinary <Sequence> siblings, this changes stacking order. For <Series.Sequence> and <TransitionSeries.Sequence> siblings, it also changes their calculated timing.

warning

Draft API: This API is experimental and may change.

reorder-nodes.ts
import {reorderNodes, type CodemodProject, type NodeReference} from '@remotion/codemods'; declare const project: CodemodProject; declare const first: NodeReference; declare const second: NodeReference; declare const target: NodeReference; const result = await reorderNodes({ project, nodes: [first, second], target, position: 'before', }); console.log(result.changes);

All moved nodes and the target must be direct JSX siblings in the same file. A target in the moved group is invalid. The edit is atomic, so an invalid node leaves the input project unchanged.

Options​

project​

An in-memory CodemodProject. The input project is not mutated.

nodes​

A nonempty array of NodeReference values for the nodes to move. Their array order does not affect the result.

target​

The sibling node to position the group relative to.

position​

Either 'before' or 'after'.

Return value​

A promise resolving to an object with the following properties.

changes​

An array of {filePath, previousContents, nextContents} file changes. This operation changes one file.

nodePathRemappings​

An array of {filePath, oldNodePath, newNodePath} mappings. A null old path indicates an insertion; a null new path indicates removal. Apply these mappings to references from the input project. See node references.

updatedNodes​

References to the moved nodes in the output project, in the order passed in nodes.

editDetails​

The source location and label for the edit.

Errors​

Throws or rejects when a reference cannot be resolved, the nodes and target are not direct siblings in the same file, or the nodes are already in the requested position. Failed edits leave the input project unchanged.

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​