{"version":3,"file":"Guide.acf3fa8b.js","sources":["../../../app/javascript/modules/timeline_selection.ts","../../../app/javascript/components/guide/Guide.vue"],"sourcesContent":["import { computed, Ref, ref } from \"vue\";\nimport { eventHasCmdOrCtrlKey } from \"@modules/helpers\";\nimport { Action } from \"@models/ActionHierarchy\";\nimport VoiceOver from \"@models/VoiceOver\";\n\n// globally define pivoting action\nconst selectionPivotingActionId: Ref = ref(null);\n\nexport const useTimelineSelection = ({\n props,\n emitSelectActionIds,\n emitSelectVoiceOverId,\n goToActionId,\n}: {\n props: {\n actions: Action[];\n selectedActionIds: string[];\n selectedVoiceOverId?: string;\n };\n emitSelectActionIds: (ids: string[]) => void;\n emitSelectVoiceOverId: (id: string | null) => void;\n goToActionId: (id: string) => void;\n}): {\n handleClickOnActionId: (actionId: string, event: MouseEvent) => void;\n handleClickOnVoiceOverId: (voiceOverId: string, forceSelection: boolean) => void;\n selectVoiceOverId: (voiceOverId: string) => void;\n goToStartOfVoiceOverId: (voiceOverId: string) => void;\n} => {\n const selectionPivotingAction: Ref = computed(() => {\n if (selectionPivotingActionId.value) {\n return props.actions.find((a) => a.id === selectionPivotingActionId.value) || null;\n }\n return null;\n });\n\n const selectedActions: Ref = computed(() =>\n props.actions.filter((action) => props.selectedActionIds.includes(action.id)),\n );\n\n function resetVoiceOverSelection(): void {\n // console.log(\"timeline_selection -> resetVoiceOverSelection\");\n if (!props.selectedVoiceOverId) return;\n emitSelectVoiceOverId(null);\n }\n\n function selectVoiceOverId(voiceOverId: string): void {\n // console.log(\"timeline_selection -> selectVoiceOverId\", voiceOverId);\n if (props.selectedVoiceOverId === voiceOverId) return;\n emitSelectVoiceOverId(voiceOverId);\n }\n\n function goToStartOfVoiceOverId(voiceOverId: string): void {\n // FIXME: for the Guide we want to actually jump to the voice over itself (which appears above its first action.)\n // See the note in Guide (the watcher on props.currentActionId) for more details.\n const voiceOver = VoiceOver.find(voiceOverId); // TODO: this is slow, remove if possible\n const action = voiceOver?.firstVisibleAction || voiceOver?.firstAction;\n if (action) goToActionId(action.id);\n }\n\n function handleClickOnVoiceOverId(voiceOverId: string, forceSelection = false): void {\n // console.log(\"timeline_selection -> handleClickOnVoiceOverId\", voiceOverId, forceSelection);\n if (props.selectedVoiceOverId !== voiceOverId || forceSelection) {\n selectVoiceOverId(voiceOverId);\n goToStartOfVoiceOverId(voiceOverId);\n } else {\n resetVoiceOverSelection();\n }\n }\n\n function handleClickOnActionId(actionId: string, event: MouseEvent): void {\n // Our goal here is replicate the same selection routines that macOS supports for list views.\n // Especially regarding: 1) modifier keys (shift + cmd/ctrl), and 2) mouse drags.\n\n let selectedActionIds = Array.from(props.selectedActionIds);\n const cmdOrCtrlKey = eventHasCmdOrCtrlKey(event);\n const action = props.actions.find((a) => a.id === actionId);\n\n if (!action) return;\n // console.log(\"clicked action\", action.id, {\n // shiftKey: event.shiftKey,\n // cmdOrCtrlKey,\n // selectedActionIds,\n // });\n\n const indexOfSelectedActionId = selectedActionIds.indexOf(actionId);\n\n if (cmdOrCtrlKey) {\n // Add single action to existing selection.\n if (selectedActionIds.includes(actionId)) {\n selectedActionIds.splice(indexOfSelectedActionId, 1);\n // Reset shift-clicks to start at the next (or otherwise _last_) _selected_ action:\n const nextSelectedAction = selectedActions.value.find(\n (a) => a.index != null && a.index > (action.index ?? 0),\n );\n if (nextSelectedAction) selectionPivotingActionId.value = nextSelectedAction.id;\n else {\n const lastSelectedActionId = selectedActions.value\n .filter((a) => a.index != null && a.index < (action.index ?? 0))\n .map((a) => a.id)\n .reverse()[0];\n if (lastSelectedActionId) selectionPivotingActionId.value = lastSelectedActionId;\n }\n } else {\n selectedActionIds.push(actionId);\n // Reset shift-clicks to start at this action:\n selectionPivotingActionId.value = actionId;\n }\n } else if (event?.shiftKey) {\n const pivotingAction = selectionPivotingAction.value || props.actions[0];\n if (!pivotingAction) return;\n \n const actionIndex = action.index ?? props.actions.indexOf(action);\n const pivotingActionIndex = pivotingAction.index ?? props.actions.indexOf(pivotingAction);\n // if (typeof pivotingAction?.index === \"number\") {\n const startRangeAtIndex = Math.min(actionIndex, pivotingActionIndex);\n const endRangeAtIndex = Math.max(actionIndex, pivotingActionIndex);\n const actionsInRange = props.actions.slice(startRangeAtIndex, endRangeAtIndex + 1);\n // console.log(\"SHIFT\", {\n // selectionPivotingAction: selectionPivotingAction.value,\n // action,\n // startRangeAtIndex,\n // endRangeAtIndex,\n // actionsInRange,\n // });\n actionsInRange.forEach((a) => {\n if (!selectedActionIds.includes(a.id)) selectedActionIds.push(a.id);\n });\n // }\n } else {\n // This is a completely new selection, so we’ll reset selectionPivotingAction:\n selectionPivotingActionId.value = actionId;\n if (selectedActionIds.length === 1 && selectedActionIds.includes(actionId)) {\n // This was the last id selected, so let’s deselect the action (here we deviate from\n // macOS Finder’s standard behavior)\n selectedActionIds = [];\n } else {\n goToActionId(actionId);\n selectedActionIds = [actionId];\n }\n }\n emitSelectActionIds(selectedActionIds);\n }\n\n return {\n handleClickOnActionId,\n handleClickOnVoiceOverId,\n selectVoiceOverId,\n goToStartOfVoiceOverId,\n };\n};\n\nexport default useTimelineSelection;\n","\n\n\n"],"names":["selectionPivotingActionId","ref","useTimelineSelection","props","emitSelectActionIds","emitSelectVoiceOverId","goToActionId","selectionPivotingAction","computed","a","selectedActions","action","resetVoiceOverSelection","selectVoiceOverId","voiceOverId","goToStartOfVoiceOverId","voiceOver","VoiceOver","handleClickOnVoiceOverId","forceSelection","handleClickOnActionId","actionId","event","selectedActionIds","cmdOrCtrlKey","eventHasCmdOrCtrlKey","indexOfSelectedActionId","nextSelectedAction","_a","lastSelectedActionId","pivotingAction","actionIndex","pivotingActionIndex","_b","startRangeAtIndex","endRangeAtIndex","ids","emit","id","groupsForPlayer","useCachedTimeBasedTimeline","groups","group","actions","chapters","steps","scrollToActionId","element","scrollToVoiceOverId","watch","vo","selectedVoiceOverId","lastAction","nextTick","openChapter"],"mappings":"mRAMA,MAAMA,EAAgDC,EAAI,IAAI,EAEjDC,EAAuB,CAAC,CACnC,MAAA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