Skip to content

Commit 58a86f4

Browse files
Iurii Karpovclaude
andcommitted
Daily Routines: context menu + touch long-press to edit
- Right-click on routine row / event block opens menu with Edit/Archive/Delete - Long-press (350ms) on touch opens edit modal directly; drag stays mouse-only - Replace hover-only edit/archive/delete buttons with a single "more" trigger - Add RoutineContextMenu component (Teleport, viewport clamping, Esc dismiss) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 63d509f commit 58a86f4

9 files changed

Lines changed: 186 additions & 25 deletions

File tree

‎src/components/dailyRoutine/EventBlock.vue‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
class="dr-week-chip absolute cursor-pointer overflow-hidden rounded-md transition-opacity touch-none"
3+
class="dr-week-chip absolute cursor-pointer overflow-hidden rounded-md transition-opacity"
44
:class="[
55
entry.completed ? 'opacity-50' : 'opacity-100',
66
isBeingDragged ? 'opacity-30' : '',
@@ -9,6 +9,7 @@
99
:title="`${entry.title} · ${entry.time} – ${endTimeStr}`"
1010
@click="onClick"
1111
@pointerdown="onPointerDown($event, entry)"
12+
@contextmenu.prevent="$emit('context', { entry, x: $event.clientX, y: $event.clientY })"
1213
>
1314
<div
1415
v-if="!isShort"
@@ -64,6 +65,7 @@
6465
const emit = defineEmits<{
6566
(e: 'toggle', entry: RoutineEntry): void;
6667
(e: 'edit', entry: RoutineEntry): void;
68+
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
6769
}>();
6870
6971
const { active, onPointerDown } = useRoutineDrag();
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<template>
2+
<Teleport to="body">
3+
<div
4+
class="fixed inset-0 z-[10001]"
5+
@click="$emit('close')"
6+
@contextmenu.prevent="$emit('close')"
7+
>
8+
<div
9+
ref="menuRef"
10+
class="absolute min-w-[180px] overflow-hidden rounded-card border border-line bg-surface py-1 shadow-tmgr-lg"
11+
:style="positionStyle"
12+
@click.stop
13+
@contextmenu.prevent
14+
>
15+
<button
16+
type="button"
17+
class="flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm text-ink transition-colors hover:bg-surface-hover"
18+
@click="onEdit"
19+
>
20+
<DRIcon name="pencil" :size="13" stroke="currentColor" />
21+
Edit
22+
</button>
23+
<button
24+
type="button"
25+
class="flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm text-ink transition-colors hover:bg-surface-hover"
26+
@click="onArchive"
27+
>
28+
<DRIcon name="archive" :size="13" stroke="currentColor" />
29+
Archive
30+
</button>
31+
<div class="my-1 h-px bg-line" />
32+
<button
33+
type="button"
34+
class="flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm text-status-fix-fg transition-colors hover:bg-status-fix-bg/40"
35+
@click="onDelete"
36+
>
37+
<DRIcon name="trash" :size="13" stroke="currentColor" />
38+
Delete
39+
</button>
40+
</div>
41+
</div>
42+
</Teleport>
43+
</template>
44+
45+
<script setup lang="ts">
46+
import { computed, onMounted, onBeforeUnmount, ref, nextTick } from 'vue';
47+
import DRIcon from './DRIcon.vue';
48+
import type { RoutineEntry } from '@/types/dailyRoutine';
49+
50+
const props = defineProps<{
51+
entry: RoutineEntry;
52+
x: number;
53+
y: number;
54+
}>();
55+
56+
const emit = defineEmits<{
57+
(e: 'close'): void;
58+
(e: 'edit', entry: RoutineEntry): void;
59+
(e: 'archive', entry: RoutineEntry): void;
60+
(e: 'delete', entry: RoutineEntry): void;
61+
}>();
62+
63+
const menuRef = ref<HTMLElement | null>(null);
64+
const adjustedX = ref(props.x);
65+
const adjustedY = ref(props.y);
66+
67+
const positionStyle = computed(() => ({
68+
left: `${adjustedX.value}px`,
69+
top: `${adjustedY.value}px`,
70+
}));
71+
72+
function clampPosition() {
73+
const el = menuRef.value;
74+
if (!el) return;
75+
const rect = el.getBoundingClientRect();
76+
const margin = 8;
77+
let x = props.x;
78+
let y = props.y;
79+
if (x + rect.width + margin > window.innerWidth) {
80+
x = window.innerWidth - rect.width - margin;
81+
}
82+
if (y + rect.height + margin > window.innerHeight) {
83+
y = window.innerHeight - rect.height - margin;
84+
}
85+
adjustedX.value = Math.max(margin, x);
86+
adjustedY.value = Math.max(margin, y);
87+
}
88+
89+
function onKey(e: KeyboardEvent) {
90+
if (e.key === 'Escape') emit('close');
91+
}
92+
93+
function onEdit() {
94+
emit('edit', props.entry);
95+
emit('close');
96+
}
97+
98+
function onArchive() {
99+
emit('archive', props.entry);
100+
emit('close');
101+
}
102+
103+
function onDelete() {
104+
// eslint-disable-next-line no-alert
105+
if (!confirm(`Delete "${props.entry.title}"?`)) return;
106+
emit('delete', props.entry);
107+
emit('close');
108+
}
109+
110+
onMounted(async () => {
111+
document.addEventListener('keydown', onKey);
112+
await nextTick();
113+
clampPosition();
114+
});
115+
onBeforeUnmount(() => {
116+
document.removeEventListener('keydown', onKey);
117+
});
118+
</script>

‎src/components/dailyRoutine/RoutineRow.vue‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div
3-
class="group relative flex items-center gap-3 overflow-hidden rounded-card border bg-surface px-3.5 py-3 shadow-tmgr-xs transition-all touch-none"
3+
class="relative flex items-center gap-3 overflow-hidden rounded-card border bg-surface px-3.5 py-3 shadow-tmgr-xs transition-all"
44
:class="[
55
selected
66
? 'border-brand bg-brand-bg shadow-tmgr-md'
@@ -9,6 +9,7 @@
99
]"
1010
@click="onClick"
1111
@pointerdown="onPointerDown($event, entry)"
12+
@contextmenu.prevent="$emit('context', { entry, x: $event.clientX, y: $event.clientY })"
1213
>
1314
<span
1415
class="absolute left-0 top-0 bottom-0 w-[3px]"
@@ -58,30 +59,12 @@
5859

5960
<button
6061
type="button"
61-
class="flex h-8 w-8 items-center justify-center rounded-pill text-ink-subtle opacity-0 transition-opacity hover:bg-surface-hover hover:text-brand group-hover:opacity-100"
62-
title="Edit"
63-
@click.stop="$emit('edit', entry)"
62+
class="hidden h-8 w-8 items-center justify-center rounded-pill text-ink-subtle transition-colors hover:bg-surface-hover hover:text-brand md:flex"
63+
title="More (right-click for menu)"
64+
@click.stop="$emit('context', { entry, x: $event.clientX, y: $event.clientY })"
6465
>
6566
<DRIcon name="pencil" :size="13" stroke="currentColor" />
6667
</button>
67-
68-
<button
69-
type="button"
70-
class="flex h-8 w-8 items-center justify-center rounded-pill text-ink-subtle opacity-0 transition-opacity hover:bg-surface-hover hover:text-brand group-hover:opacity-100"
71-
title="Archive"
72-
@click.stop="$emit('archive', entry)"
73-
>
74-
<DRIcon name="archive" :size="13" stroke="currentColor" />
75-
</button>
76-
77-
<button
78-
type="button"
79-
class="flex h-8 w-8 items-center justify-center rounded-pill text-ink-subtle opacity-0 transition-opacity hover:bg-status-fix-bg hover:text-status-fix-fg group-hover:opacity-100"
80-
title="Delete"
81-
@click.stop="$emit('delete', entry)"
82-
>
83-
<DRIcon name="trash" :size="13" stroke="currentColor" />
84-
</button>
8568
</div>
8669
</template>
8770

@@ -103,6 +86,7 @@
10386
(e: 'delete', entry: RoutineEntry): void;
10487
(e: 'select', entry: RoutineEntry): void;
10588
(e: 'archive', entry: RoutineEntry): void;
89+
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
10690
}>();
10791
10892
const frequencyLabel = computed(() => entryRecurrenceLabel(props.entry));

‎src/components/dailyRoutine/views/DayView.vue‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@delete="$emit('delete', e)"
3232
@archive="$emit('archive', e)"
3333
@select="$emit('select', e)"
34+
@context="$emit('context', $event)"
3435
/>
3536
</div>
3637

@@ -99,6 +100,7 @@
99100
mode="full"
100101
@toggle="$emit('toggle', item.event.source.entry)"
101102
@edit="$emit('edit', item.event.source.entry)"
103+
@context="$emit('context', $event)"
102104
/>
103105
</template>
104106
</div>
@@ -133,6 +135,7 @@
133135
(e: 'archive', entry: RoutineEntry): void;
134136
(e: 'archive-done-unscheduled'): void;
135137
(e: 'create', payload: { date: string; timeH: number; timeM: number }): void;
138+
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
136139
}>();
137140
138141
function fmtIso(d: Date): string {

‎src/components/dailyRoutine/views/ListView.vue‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@delete="$emit('delete', e)"
3232
@archive="$emit('archive', e)"
3333
@select="$emit('select', e)"
34+
@context="$emit('context', $event)"
3435
/>
3536
</div>
3637
</section>
@@ -54,6 +55,7 @@
5455
@delete="$emit('delete', e)"
5556
@archive="$emit('archive', e)"
5657
@select="$emit('select', e)"
58+
@context="$emit('context', $event)"
5759
/>
5860
</div>
5961
</section>
@@ -86,6 +88,7 @@
8688
(e: 'select', entry: RoutineEntry): void;
8789
(e: 'archive', entry: RoutineEntry): void;
8890
(e: 'archive-done-unscheduled'): void;
91+
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
8992
}>();
9093
9194
const unscheduled = computed(() =>

‎src/components/dailyRoutine/views/MonthView.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
}"
5454
:title="e.title"
5555
@click.stop="$emit('toggle', e)"
56+
@contextmenu.prevent.stop="$emit('context', { entry: e, x: $event.clientX, y: $event.clientY })"
5657
>
5758
<span v-if="e.time" class="text-[10px] tabular-nums text-ink-subtle dark:text-white/60">{{ e.time }}</span>
5859
<span class="truncate">{{ e.title }}</span>
@@ -86,6 +87,7 @@
8687
(e: 'toggle', entry: RoutineEntry): void;
8788
(e: 'select-day', date: Date): void;
8889
(e: 'create', payload: { date: string; timeH: number; timeM: number }): void;
90+
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
8991
}>();
9092
9193
function fmtIso(d: Date): string {

‎src/components/dailyRoutine/views/WeekView.vue‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
}"
6363
:title="e.title"
6464
@click="$emit('toggle', e)"
65+
@contextmenu.prevent="$emit('context', { entry: e, x: $event.clientX, y: $event.clientY })"
6566
>
6667
{{ e.title }}
6768
<button
@@ -133,6 +134,7 @@
133134
mode="compact"
134135
@toggle="$emit('toggle', item.event.source.entry)"
135136
@edit="$emit('edit', item.event.source.entry)"
137+
@context="$emit('context', $event)"
136138
/>
137139
</template>
138140
<div
@@ -177,6 +179,7 @@
177179
(e: 'toggle', entry: RoutineEntry): void;
178180
(e: 'edit', entry: RoutineEntry): void;
179181
(e: 'create', payload: { date: string; timeH: number; timeM: number }): void;
182+
(e: 'context', payload: { entry: RoutineEntry; x: number; y: number }): void;
180183
}>();
181184
182185
function onCellClick(e: MouseEvent, d: Date) {

‎src/composable/useRoutineDrag.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { onBeforeUnmount, ref } from 'vue';
22
import type { RoutineEntry } from '@/types/dailyRoutine';
33

44
const LONG_PRESS_MS = 250;
5+
const TOUCH_HOLD_MS = 350;
56
const MOVE_THRESHOLD = 5;
67

78
export type DropPayload = {
@@ -14,6 +15,7 @@ export type DropPayload = {
1415
type DragState = {
1516
entry: RoutineEntry;
1617
pointerId: number;
18+
pointerType: string;
1719
x: number;
1820
y: number;
1921
ghostEl: HTMLElement | null;
@@ -25,6 +27,7 @@ const hoverKey = ref<string | null>(null);
2527
let state: DragState | null = null;
2628
let pressTimer: number | null = null;
2729
let dropHandler: ((entry: RoutineEntry, payload: DropPayload) => void) | null = null;
30+
let editHandler: ((entry: RoutineEntry) => void) | null = null;
2831
let canceled = false;
2932

3033
function fmtIso(d: Date): string {
@@ -160,6 +163,10 @@ export function useRoutineDrag() {
160163
dropHandler = fn;
161164
}
162165

166+
function setEditHandler(fn: (entry: RoutineEntry) => void) {
167+
editHandler = fn;
168+
}
169+
163170
function onPointerDown(e: PointerEvent, entry: RoutineEntry, srcEl?: HTMLElement) {
164171
if (e.button != null && e.button !== 0) return;
165172
if (active.value) return;
@@ -169,9 +176,11 @@ export function useRoutineDrag() {
169176
}
170177
const el = (srcEl ?? (e.currentTarget as HTMLElement)) || null;
171178
if (!el) return;
179+
const pointerType = e.pointerType || 'mouse';
172180
state = {
173181
entry,
174182
pointerId: e.pointerId,
183+
pointerType,
175184
x: e.clientX,
176185
y: e.clientY,
177186
ghostEl: null,
@@ -180,17 +189,28 @@ export function useRoutineDrag() {
180189
document.addEventListener('pointermove', onPointerMove, { passive: false });
181190
document.addEventListener('pointerup', onPointerUp);
182191
document.addEventListener('pointercancel', onPointerCancel);
192+
const isTouch = pointerType === 'touch';
193+
const delay = isTouch ? TOUCH_HOLD_MS : LONG_PRESS_MS;
183194
pressTimer = window.setTimeout(() => {
184195
if (!state) return;
185196
if (canceled) return;
197+
if (isTouch) {
198+
// touch hold → open edit modal, no drag
199+
const ent = state.entry;
200+
cleanup();
201+
active.value = null;
202+
hoverKey.value = null;
203+
if (editHandler) editHandler(ent);
204+
return;
205+
}
186206
active.value = entry;
187207
document.body.style.userSelect = 'none';
188208
state.ghostEl = buildGhost(el);
189209
if (navigator.vibrate) {
190210
try { navigator.vibrate(15); } catch {}
191211
}
192212
moveGhost(state.x, state.y);
193-
}, LONG_PRESS_MS);
213+
}, delay);
194214
}
195215

196216
onBeforeUnmount(() => {
@@ -202,6 +222,7 @@ export function useRoutineDrag() {
202222
hoverKey,
203223
onPointerDown,
204224
setDropHandler,
225+
setEditHandler,
205226
fmtIso,
206227
};
207228
}

0 commit comments

Comments
 (0)