function handleRefTargets()

in src/panels/graph.ts [155:181]


function handleRefTargets(
    target: string,
    targets: TargetObject[]
): { targetFull?: string | undefined } {
    if (target.includes('#')) {
        const refs = getRefsFromTarget(target);
        const findTargetByRefId = (targets: TargetObject[], refId: string) => {
            const found = targets.find((target) => target.refId === refId);
            if (!found) {
                throw new Error(
                    `Invalid target reference: #${refId} does not exist. Available refs: ${targets.map((t) => t.refId).join(', ')}`
                );
            }
            return found.target;
        };

        return {
            targetFull: refs.reduce(
                (res, ref) =>
                    res.replace(`#${ref}`, findTargetByRefId(targets, ref)),
                target
            ),
        };
    }

    return {};
}