@mocanvas/editor · function

findCommonAncestor

declare function findCommonAncestor(editor: Editor, shapes: readonly ShapeRef[], predicate?: (shape: UnknownShape) => boolean): ShapeId | undefined

The innermost shape that every one of shapes sits inside, or undefined when they only share the page.

This is what decides where a new group goes: a group made from two shapes in the same frame belongs in that frame, not on the page. With predicate, only ancestors that satisfy it are considered — pass isGroup to find the common *group* rather than the common parent of any kind.

A single shape's answer is its own nearest accepted ancestor; an empty list has no answer at all.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.