|
1 | | -<!-- BRANCH HEADER PURE COMPONENT --> |
2 | | -<!-- ONLY CONCERNED ABOUT STYLE 😎 --> |
| 1 | +<script lang="ts" module> |
| 2 | + export type DragableBranchData = { |
| 3 | + disabled: boolean; |
| 4 | + label: string; |
| 5 | + pushStatus: PushStatus | undefined; |
| 6 | + viewportId: string; |
| 7 | + data: BranchDropData | undefined; |
| 8 | + }; |
| 9 | +</script> |
| 10 | + |
3 | 11 | <script lang="ts"> |
4 | 12 | import BranchHeaderIcon from '$components/BranchHeaderIcon.svelte'; |
5 | 13 | import BranchLabel from '$components/BranchLabel.svelte'; |
| 14 | + import { BranchDropData } from '$lib/branches/dropHandler'; |
| 15 | + import { draggableBranch, type DraggableConfig } from '$lib/dragging/draggable'; |
| 16 | + import { DROPZONE_REGISTRY } from '$lib/dragging/registry'; |
| 17 | + import { inject } from '@gitbutler/core/context'; |
6 | 18 | import { Badge } from '@gitbutler/ui'; |
7 | 19 | import { TestId } from '@gitbutler/ui'; |
| 20 | + import { DRAG_STATE_SERVICE } from '@gitbutler/ui/drag/dragStateService.svelte'; |
8 | 21 | import { focusable } from '@gitbutler/ui/focus/focusable'; |
9 | 22 | import { slide } from 'svelte/transition'; |
| 23 | + import type { PushStatus } from '$lib/stacks/stack'; |
10 | 24 | import type iconsJson from '@gitbutler/ui/data/icons.json'; |
11 | 25 | import type { Snippet } from 'svelte'; |
12 | 26 |
|
|
29 | 43 | content?: Snippet; |
30 | 44 | menu?: Snippet<[{ rightClickTrigger: HTMLElement }]>; |
31 | 45 | buttons?: Snippet; |
| 46 | + dragArgs?: DragableBranchData; |
32 | 47 | }; |
33 | 48 |
|
34 | 49 | const { |
|
49 | 64 | emptyState, |
50 | 65 | content, |
51 | 66 | menu, |
52 | | - buttons |
| 67 | + buttons, |
| 68 | + dragArgs |
53 | 69 | }: Props = $props(); |
54 | 70 |
|
| 71 | + const dropzoneRegistry = inject(DROPZONE_REGISTRY); |
| 72 | + const dragStateService = inject(DRAG_STATE_SERVICE); |
| 73 | +
|
55 | 74 | let rightClickTrigger = $state<HTMLDivElement>(); |
56 | 75 | let active = $state(false); |
57 | 76 |
|
58 | 77 | const actionsVisible = $derived(!draft && !isCommitting && (buttons || menu)); |
| 78 | +
|
| 79 | + const draggableBranchConfig = $derived.by<DraggableConfig>(() => { |
| 80 | + if (!dragArgs) { |
| 81 | + return { |
| 82 | + disabled: true, |
| 83 | + dropzoneRegistry, |
| 84 | + dragStateService |
| 85 | + }; |
| 86 | + } |
| 87 | + return { |
| 88 | + ...dragArgs, |
| 89 | + dropzoneRegistry, |
| 90 | + dragStateService |
| 91 | + }; |
| 92 | + }); |
59 | 93 | </script> |
60 | 94 |
|
61 | 95 | <div |
|
79 | 113 | {onclick} |
80 | 114 | onkeypress={onclick} |
81 | 115 | tabindex="0" |
| 116 | + data-remove-from-panning |
| 117 | + use:draggableBranch={draggableBranchConfig} |
82 | 118 | > |
83 | 119 | {#if selected && !draft} |
84 | 120 | <div |
|
122 | 158 | </div> |
123 | 159 |
|
124 | 160 | {#if actionsVisible} |
125 | | - <div class="branch-hedaer__actions-row" class:draft class:new-branch={isEmpty}> |
| 161 | + <div class="branch-hedaer__actions-row" class:draft class:new-branch={isEmpty} data-no-drag> |
126 | 162 | {#if buttons} |
127 | 163 | <div class="text-12 branch-header__actions"> |
128 | 164 | {@render buttons()} |
|
0 commit comments