From 96f331e2e33e077766937c9dfc0324bbf75abfc6 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Wed, 7 Aug 2024 16:31:53 +0200 Subject: [PATCH 1/3] fix: oui-draggable --- lib/basic/oui-draggable.demo.vue | 48 ++++++++++++++++++++++++++++++++ lib/basic/oui-draggable.vue | 26 ++++++++--------- lib/mobile/oui-mobile.vue | 3 +- 3 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 lib/basic/oui-draggable.demo.vue diff --git a/lib/basic/oui-draggable.demo.vue b/lib/basic/oui-draggable.demo.vue new file mode 100644 index 0000000..8cc6997 --- /dev/null +++ b/lib/basic/oui-draggable.demo.vue @@ -0,0 +1,48 @@ + + + + + diff --git a/lib/basic/oui-draggable.vue b/lib/basic/oui-draggable.vue index f0131a3..05d6484 100644 --- a/lib/basic/oui-draggable.vue +++ b/lib/basic/oui-draggable.vue @@ -24,8 +24,8 @@ let lastY = 0 let deltaX = 0 let deltaY = 0 -function translateMouseEvent(e: MouseEvent): OuiDraggableEvent { - const { pageX, pageY } = e +function translateTouchEvent(e: TouchEvent): OuiDraggableEvent { + const { pageX, pageY } = e?.touches?.[0] ?? e deltaX = pageX - lastX deltaY = pageY - lastY lastX = pageX @@ -46,37 +46,37 @@ function translateMouseEvent(e: MouseEvent): OuiDraggableEvent { return info } -function cancelEvent(e: MouseEvent) { +function cancelEvent(e: TouchEvent) { // log('sep cancel') e?.stopPropagation() e?.preventDefault() } -function onMouseDown(e: MouseEvent) { +function onMouseDown(e: TouchEvent) { log('down') - const { pageX, pageY } = e + const { pageX, pageY } = e?.touches?.[0] ?? e dragging = true startX = pageX startY = pageY lastX = pageX lastY = pageY - emit('moveStart', translateMouseEvent(e)) + emit('moveStart', translateTouchEvent(e)) bindEvents() return cancelEvent(e) } -function onMouseMove(e: MouseEvent) { - log('move') +function onMouseMove(e: TouchEvent) { + log('move', dragging, e) if (!dragging) return - emit('move', translateMouseEvent(e)) + emit('move', translateTouchEvent(e)) return cancelEvent(e) } -function onMouseUp(e: MouseEvent) { +function onMouseUp(e: TouchEvent) { log('up') dragging = false - emit('moveEnd', translateMouseEvent(e)) + emit('moveEnd', translateTouchEvent(e)) unbindEvents() return cancelEvent(e) } @@ -88,7 +88,7 @@ function onDblClick() { const mouseOptions = { passive: false } useEventListener(el, 'mousedown', onMouseDown) -useEventListener(el, 'touchdown', onMouseDown) +useEventListener(el, 'touchstart', onMouseDown) useEventListener(el, 'dblclick', onDblClick) let docListeners: any[] = [] @@ -110,7 +110,7 @@ function unbindEvents() { diff --git a/lib/mobile/oui-mobile.vue b/lib/mobile/oui-mobile.vue index 79995f1..a4d9135 100644 --- a/lib/mobile/oui-mobile.vue +++ b/lib/mobile/oui-mobile.vue @@ -75,7 +75,8 @@ if (useSingleton('oui-mobile')) { while (el != null) { if (el.dataset.noscroll === 'true') { log('exit noscroll') - break + return + // break } if (el.tagName === 'BODY') { log('exit body') From 2a2edc0c1c11316d9bdc7fffb582123d5469620e Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Wed, 7 Aug 2024 17:23:28 +0200 Subject: [PATCH 2/3] feat: drag close modal --- lib/basic/_types.ts | 1 + lib/basic/oui-draggable.vue | 40 +++++++++++++++++++++++++++++-------- lib/mobile/drag-util.ts | 33 ++++++++++++++++++++++++++++++ lib/mobile/oui-mobile.vue | 24 ++++------------------ lib/modal/oui-modal.vue | 35 ++++++++++++++++++++++++++------ 5 files changed, 99 insertions(+), 34 deletions(-) create mode 100644 lib/mobile/drag-util.ts diff --git a/lib/basic/_types.ts b/lib/basic/_types.ts index 35f53e8..3624786 100644 --- a/lib/basic/_types.ts +++ b/lib/basic/_types.ts @@ -36,6 +36,7 @@ export interface OuiDraggableEvent { deltaY: number moveX: number moveY: number + timeMS: number // page: OuiDraggablePosition // delta: OuiDraggablePosition // pos: OuiDraggablePosition diff --git a/lib/basic/oui-draggable.vue b/lib/basic/oui-draggable.vue index 05d6484..68f1974 100644 --- a/lib/basic/oui-draggable.vue +++ b/lib/basic/oui-draggable.vue @@ -1,10 +1,15 @@