18 lines
680 B
TypeScript
18 lines
680 B
TypeScript
import type { DirectoryEntry } from '~/shared/types';
|
|
|
|
/** Converts a selection and the entry that triggered an action into the target entries
|
|
* @param targetEntry - The entry that triggered an action
|
|
* @param selection - The selected entries
|
|
* @returns If there are no selected elements or the target was not included only the target is returned. Otherwise the selection is returned
|
|
*/
|
|
export function getTargetsFromSelection(
|
|
targetEntry: DirectoryEntry,
|
|
selection: Map<string, DirectoryEntry>
|
|
): DirectoryEntry[] {
|
|
if (selection.size === 0 || !selection.has(targetEntry.name)) {
|
|
return [targetEntry];
|
|
}
|
|
|
|
return Array.from(selection.values());
|
|
}
|