import type { SelectableTreeNode } from '../tree-selection'; import { TreeView } from './tree-view'; export type TreeViewSelection = readonly Readonly[] & { source: TreeView; }; export namespace TreeViewSelection { export function isSource( selection: Record | undefined, source: TreeView, ): boolean { return getSource(selection) === source; } export function getSource( selection: Record | undefined, ): TreeView | undefined { return is(selection) ? selection.source : undefined; } export function is( selection: Record | undefined, ): selection is TreeViewSelection { // eslint-disable-next-line @typescript-eslint/no-explicit-any return ( Array.isArray(selection) && 'source' in selection && (selection as any).source instanceof TreeView ); } export function create(source: TreeView): TreeViewSelection { return Object.assign(source.model.selectedNodes, { source }); } }