{"version":3,"file":"useTimelineSelection.mjs","names":[],"sources":["../../../src/hooks/selection/useTimelineSelection.ts"],"sourcesContent":["import { timelineCommandOk } from '@techsquidtv/canvas-timeline-core';\nimport type { TimelineCommandResult } from '@techsquidtv/canvas-timeline-core';\nimport { deriveTimelineSelection } from '#react/hooks/clips/timelineClipModel';\nimport type { TimelineSelectionState } from '#react/hooks/clips/timelineClipModel';\nimport { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useTimelineSelector } from '#react/hooks/core/useTimelineSelector';\nimport { useCallback, useMemo } from 'react';\nexport type { TimelineSelectionState } from '#react/hooks/clips/timelineClipModel';\n\n/**\n * Result returned by `useTimelineSelection`.\n *\n * @remarks\n *\n * The result is the shared selection model used by clip inspectors, track\n * headers, grouping controls, clipboard commands, and edit toolbars. It\n * includes both primary selection fields and multi-selection arrays so product\n * chrome can avoid re-deriving selection from raw tracks.\n *\n *\n * @see {@link useTimelineClips}\n * @see {@link https://canvastimeline.com/docs/react-hooks | React editor hooks}\n */\nexport interface UseTimelineSelectionResult extends TimelineSelectionState {\n  /** Selects a clip by id, or clears clip selection when passed null. */\n  selectClip: (clipId: string | null) => TimelineCommandResult;\n  /** Selects multiple clips by id, clearing clips not included. */\n  selectClips: (clipIds: readonly string[]) => TimelineCommandResult;\n  /** Toggles one clip in the current multi-selection. */\n  toggleClipSelection: (clipId: string, selected?: boolean) => TimelineCommandResult;\n  /** Selects a track by id, or clears track selection when passed null. */\n  selectTrack: (trackId: string | null) => TimelineCommandResult;\n  /** Clears both clip and track selection. */\n  clearSelection: () => TimelineCommandResult;\n}\n\n/**\n * Provides the canonical selected clip/track model for timeline editor chrome.\n *\n * @remarks\n *\n * Use this hook when UI needs selection state without the broader clip command\n * surface from {@link useTimelineClips}. It is a good fit for inspectors,\n * selection badges, grouped-clip panels, and toolbar enablement.\n *\n * @returns Selected clip and track state plus selection commands.\n *\n * @example\n * ```tsx\n * import { useTimelineSelection } from '@techsquidtv/canvas-timeline-react';\n *\n * export function SelectionSummary() {\n *   const selection = useTimelineSelection();\n *\n *   if (!selection.hasSelection) {\n *     return <p>No selection</p>;\n *   }\n *\n *   return (\n *     <p>\n *       {selection.selectedClipIds.length} clips selected\n *       {selection.selectedTrack ? ` on ${selection.selectedTrack.name}` : ''}\n *     </p>\n *   );\n * }\n * ```\n *\n * @see {@link useTimelineClips}\n * @see {@link https://canvastimeline.com/demos/clip-grouping-import | Clip grouping import demo}\n */\nexport function useTimelineSelection(): UseTimelineSelectionResult {\n  const engine = useTimelineEngine();\n  const state = useTimelineSelector((state) => ({\n    clipGroups: state.clipGroups,\n    tracks: state.tracks,\n  }));\n  const selection = useMemo(\n    () => deriveTimelineSelection(state.tracks, state.clipGroups),\n    [state.clipGroups, state.tracks]\n  );\n\n  const selectClip = useCallback(\n    (clipId: string | null) => {\n      return engine.selectClip(clipId);\n    },\n    [engine]\n  );\n\n  const selectTrack = useCallback(\n    (trackId: string | null) => {\n      return engine.selectTrack(trackId);\n    },\n    [engine]\n  );\n\n  const selectClips = useCallback(\n    (clipIds: readonly string[]) => {\n      return engine.selectClips(clipIds);\n    },\n    [engine]\n  );\n\n  const toggleClipSelection = useCallback(\n    (clipId: string, selected?: boolean) => engine.toggleClipSelection(clipId, selected),\n    [engine]\n  );\n\n  const clearSelection = useCallback(() => {\n    engine.selectClip(null);\n    engine.selectTrack(null);\n    return timelineCommandOk();\n  }, [engine]);\n\n  return {\n    ...selection,\n    selectClip,\n    selectClips,\n    toggleClipSelection,\n    selectTrack,\n    clearSelection,\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,SAAgB,uBAAmD;CACjE,MAAM,SAAS,kBAAkB;CACjC,MAAM,QAAQ,qBAAqB,WAAW;EAC5C,YAAY,MAAM;EAClB,QAAQ,MAAM;CAChB,EAAE;CACF,MAAM,YAAY,cACV,wBAAwB,MAAM,QAAQ,MAAM,UAAU,GAC5D,CAAC,MAAM,YAAY,MAAM,MAAM,CACjC;CAEA,MAAM,aAAa,aAChB,WAA0B;EACzB,OAAO,OAAO,WAAW,MAAM;CACjC,GACA,CAAC,MAAM,CACT;CAEA,MAAM,cAAc,aACjB,YAA2B;EAC1B,OAAO,OAAO,YAAY,OAAO;CACnC,GACA,CAAC,MAAM,CACT;CAEA,MAAM,cAAc,aACjB,YAA+B;EAC9B,OAAO,OAAO,YAAY,OAAO;CACnC,GACA,CAAC,MAAM,CACT;CAEA,MAAM,sBAAsB,aACzB,QAAgB,aAAuB,OAAO,oBAAoB,QAAQ,QAAQ,GACnF,CAAC,MAAM,CACT;CAEA,MAAM,iBAAiB,kBAAkB;EACvC,OAAO,WAAW,IAAI;EACtB,OAAO,YAAY,IAAI;EACvB,OAAO,kBAAkB;CAC3B,GAAG,CAAC,MAAM,CAAC;CAEX,OAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACA;CACF;AACF"}