Skip to content

Commit aaebcd7

Browse files
committed
dev -- cleanup dragging interactions and styling
1 parent ac2050e commit aaebcd7

6 files changed

Lines changed: 64 additions & 57 deletions

File tree

src/parts/add-subtitle.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function add_subtitle()
3939
4040
button {
4141
padding: 0 1.5rem;
42-
margin-top: 1rem;
42+
margin: 1rem 5rem 0;
4343
@include font-code;
4444
color: rgb(black, 20%);
4545
font-size: 200%;

src/parts/insert.svelte

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
<script lang="ts">
44
55
import type { Int } from "#scripts/types";
6+
import type { DraggingData } from "#src/routes/subtitles-view.svelte";
67
78
import { subtitles } from "#scripts/stores";
89
import { Subtitle } from "#scripts/types";
910
1011
1112
interface Props {
1213
index: Int;
14+
dragging: DraggingData;
1315
}
1416
15-
let { index } = $props();
17+
let { index, dragging }: Props = $props();
1618
1719
1820
function insert_subtitle()
@@ -24,7 +26,11 @@ function insert_subtitle()
2426
</script>
2527

2628

27-
<button class="insert" onclick={insert_subtitle}>
29+
<button
30+
class="insert"
31+
class:hidden={dragging.sub_id}
32+
onclick={insert_subtitle}
33+
>
2834
<div class="line"></div>
2935
<div class="add">+</div>
3036
</button>
@@ -34,37 +40,21 @@ function insert_subtitle()
3440
3541
button.insert {
3642
width: calc(100% + 1.5rem);
37-
height: 1em;
43+
height: 1rem;
3844
position: absolute;
3945
z-index: 2;
4046
top: 0;
4147
display: flex;
4248
flex-flow: row nowrap;
4349
align-items: center;
50+
4451
font-size: 150%;
4552
background: none;
4653
border: none;
47-
transform: translateY(-0.9rem);
54+
transform: translateY(-0.64rem);
55+
opacity: 1.0;
4856
transition: all 0.1s ease-out;
4957
50-
.line {
51-
width: 100%;
52-
height: 0.5rem;
53-
background: transparent;
54-
border-radius: 0.25rem;
55-
transition: all 0.1s ease-out;
56-
}
57-
58-
.add {
59-
width: 2rem;
60-
height: 2rem;
61-
@include font-code;
62-
color: rgb(black, 20%);
63-
background: transparent;
64-
border-radius: 50%;
65-
transition: all 0.1s ease-out;
66-
}
67-
6858
&:hover, &:focus-visible {
6959
cursor: pointer;
7060
color: rgb(black, 50%);
@@ -83,10 +73,34 @@ button.insert {
8373
background: rgb(black, 20%);
8474
}
8575
}
76+
77+
&.hidden {
78+
opacity: 0;
79+
}
80+
}
81+
82+
.line {
83+
width: 100%;
84+
height: 0.5rem;
85+
background: transparent;
86+
border-radius: 0.25rem;
87+
transition: all 0.1s ease-out;
88+
}
89+
90+
.add {
91+
width: 2rem;
92+
min-width: 2rem;
93+
height: 2rem;
94+
min-height: 2rem;
95+
@include font-code;
96+
color: rgb(black, 20%);
97+
background: transparent;
98+
border-radius: 50%;
99+
transition: all 0.1s ease-out;
86100
}
87101
88102
:global(.subtitle:active button.insert) {
89-
opacity: 0%;
103+
opacity: 0;
90104
}
91105
92106
</style>

src/parts/subtitle.ghost.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ let { dragging = $bindable() }: Props = $props();
2828
2929
.ghost {
3030
pointer-events: none;
31-
z-index: -2;
31+
width: 100%;
3232
position: absolute;
33+
z-index: 20;
3334
top: 0;
3435
left: 0;
35-
opacity: 0%;
36+
background: rgb(black, 8%);
37+
backdrop-filter: blur(4px);
38+
opacity: 0;
39+
transition: opacity 0.1s ease-out;
3640
3741
&.haunting {
38-
z-index: 20;
39-
opacity: 100%;
42+
opacity: 1;
4043
}
4144
}
4245

src/parts/subtitle.svelte

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { slide } from "svelte/transition";
1515
import { expoOut } from "svelte/easing";
1616
1717
import { getContext } from "svelte";
18+
import { stopPropagation } from "svelte/legacy";
1819
1920
2021
interface Props {
@@ -35,7 +36,8 @@ function onmousedown(e: MouseEvent)
3536
dragging.sub_id = subtitle.id;
3637
3738
if (dragging.ghost) {
38-
dragging.ghost.innerHTML = self.innerHTML;
39+
// dragging.ghost.innerHTML = self.innerHTML;
40+
dragging.ghost.style.height = `${self.offsetHeight}px`;
3941
}
4042
4143
dragging.offset_y = self.getBoundingClientRect().y - e.clientY;
@@ -47,22 +49,14 @@ function onmouseenter(e: MouseEvent)
4749
{
4850
e.stopPropagation();
4951
50-
console.log("dragging.sub_id =", dragging.sub_id);
51-
console.log("subtitle.id =", subtitle.id);
52-
5352
if (!dragging.sub_id || dragging.sub_id === subtitle.id) return;
5453
55-
// console.log("$subtitles.subs.before =", $subtitles.subs.map(sub => `${sub.id}-${sub.body}`));
5654
if (dragging.direction === "up") {
5755
$subtitles.reorder_before_by_id(dragging.sub_id, subtitle.id);
5856
} else {
5957
$subtitles.reorder_after_by_id(dragging.sub_id, subtitle.id);
6058
}
61-
// console.log("$subtitles.subs.after =", $subtitles.subs.map(sub => `${sub.id}-${sub.body}`));
6259
$subtitles.subs = $subtitles.subs;
63-
64-
dragging.reordering_id = subtitle.id;
65-
requestAnimationFrame(() => { dragging.reordering_id = null; });
6660
}
6761
6862
@@ -93,18 +87,17 @@ function get(
9387

9488

9589
<div style:position="relative">
96-
<Insert {index} />
90+
<Insert {index} {dragging} />
9791

9892
<!-- svelte-ignore a11y_no_static_element_interactions -->
9993
<div
10094
class="subtitle"
10195
class:grabbed={dragging.sub_id === subtitle.id}
10296
bind:this={self}
103-
{onmousedown}
10497
{onmouseenter}
10598
transition:slide={{ duration: 400, easing: expoOut }}
10699
>
107-
<div class="grabber">
100+
<div class="grabber" {onmousedown}>
108101
<div>=</div>
109102
</div>
110103

@@ -172,15 +165,16 @@ function get(
172165
box-shadow: 0 0 4px rgb(black, 20%);
173166
}
174167
175-
&:has(.grabber:active) {
176-
user-select: none;
177-
border-color: $col-prot;
178-
outline-color: color.change($col-prot, $alpha: 0.2);
179-
box-shadow: 0 0 0 rgb(black, 20%);
180-
}
168+
// &:has(.grabber:active) {
169+
// user-select: none;
170+
// border-color: $col-prot;
171+
// outline-color: color.change($col-prot, $alpha: 0.2);
172+
// box-shadow: 0 0 0 rgb(black, 20%);
173+
// }
181174
182175
&.grabbed {
183-
opacity: 0%;
176+
user-select: none;
177+
opacity: 0;
184178
}
185179
}
186180
@@ -201,21 +195,23 @@ function get(
201195
202196
203197
.grabber {
204-
padding: 0 0.5rem;
198+
padding: 0 0.1rem;
205199
display: flex;
206200
justify-content: center;
207201
align-items: center;
208202
@include font-code;
209203
color: rgb(black, 20%);
204+
font-size: 150%;
210205
opacity: 0;
211206
transition: all 0.1s ease-out;
212207
213208
.subtitle:where(:hover, :focus-visible) & {
214-
opacity: 100%;
209+
opacity: 1;
215210
}
216211
217212
&:hover {
218213
cursor: grab;
214+
color: rgb(black, 50%);
219215
}
220216
221217
&:active {
@@ -243,7 +239,7 @@ function get(
243239
transition: all 0.1s ease-out;
244240
245241
.subtitle:where(:hover, :focus-visible, :focus-within) &{
246-
opacity: 100%;
242+
opacity: 1;
247243
}
248244
.subtitle:where(:hover, :focus-visible, :focus-within) &[disabled] {
249245
pointer-events: none;

src/parts/textarea.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let { value = $bindable() }: Props = $props();
1919
textarea {
2020
resize: none;
2121
flex-grow: 1;
22-
// width: 20em;
2322
height: 5em;
2423
padding: 0.75em;
2524
@include font-ui;

src/routes/subtitles-view.svelte

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export interface DraggingData {
88
root: HTMLElement | null;
99
ghost: HTMLElement | null;
1010
11-
sub_id: Int | null;
12-
reordering_id: Int | null;
13-
11+
sub_id: Int | null;
1412
direction: "up" | "down";
1513
mouse_y_previous: number;
1614
@@ -39,8 +37,6 @@ let dragging: DraggingData = $state({
3937
ghost: null,
4038
4139
sub_id: null,
42-
reordering_id: null,
43-
4440
direction: "down",
4541
mouse_y_previous: 0,
4642
@@ -80,7 +76,6 @@ function onmouseup(e: MouseEvent)
8076
{
8177
e.stopPropagation();
8278
dragging.sub_id = null;
83-
dragging.reordering_id = null;
8479
}
8580
8681
</script>

0 commit comments

Comments
 (0)