@bagelink/vue 0.0.753 → 0.0.757

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/components/Zoomer.vue.d.ts +40 -0
  2. package/dist/components/Zoomer.vue.d.ts.map +1 -0
  3. package/dist/components/index.d.ts +1 -0
  4. package/dist/components/index.d.ts.map +1 -1
  5. package/dist/components/layout/Tabs.vue.d.ts +2 -0
  6. package/dist/components/layout/Tabs.vue.d.ts.map +1 -1
  7. package/dist/components/lightbox/Lightbox.vue.d.ts.map +1 -1
  8. package/dist/components/lightbox/lightbox.types.d.ts +2 -0
  9. package/dist/components/lightbox/lightbox.types.d.ts.map +1 -1
  10. package/dist/index.cjs +732 -255
  11. package/dist/index.mjs +732 -255
  12. package/dist/style.css +141 -97
  13. package/dist/utils/index.d.ts +1 -1
  14. package/dist/utils/index.d.ts.map +1 -1
  15. package/dist/utils/tapDetector.d.ts +30 -0
  16. package/dist/utils/tapDetector.d.ts.map +1 -0
  17. package/package.json +1 -1
  18. package/src/components/Btn.vue +1 -1
  19. package/src/components/Zoomer.vue +377 -0
  20. package/src/components/form/inputs/RadioGroup.vue +2 -2
  21. package/src/components/form/inputs/RichText2/Toolbar.vue +1 -1
  22. package/src/components/form/inputs/RichText2/index.vue +3 -3
  23. package/src/components/form/inputs/ToggleInput.vue +1 -1
  24. package/src/components/formkit/Toggle.vue +1 -1
  25. package/src/components/index.ts +1 -0
  26. package/src/components/layout/SidebarMenu.vue +1 -1
  27. package/src/components/layout/Tabs.vue +6 -3
  28. package/src/components/lightbox/Lightbox.vue +30 -6
  29. package/src/components/lightbox/index.ts +2 -2
  30. package/src/components/lightbox/lightbox.types.ts +2 -0
  31. package/src/styles/layout.css +18 -2
  32. package/src/styles/mobilLayout.css +16 -2
  33. package/src/utils/BagelFormUtils.ts +1 -1
  34. package/src/utils/index.ts +12 -4
  35. package/src/utils/tapDetector.ts +119 -0
@@ -1,9 +1,17 @@
1
1
  import type { Attributes, BglFormSchemaT } from '@bagelink/vue'
2
2
 
3
- let timeout: any
4
- export function debounce(fn: () => void, delay = 500) {
5
- clearTimeout(timeout)
6
- timeout = setTimeout(fn, delay)
3
+ export function debounce<T extends (...args: any[]) => void>(func: T, wait: number): (...args: Parameters<T>) => void {
4
+ let timeoutId: ReturnType<typeof setTimeout> | undefined
5
+
6
+ return function (...args: Parameters<T>) {
7
+ if (timeoutId) {
8
+ clearTimeout(timeoutId)
9
+ }
10
+
11
+ timeoutId = setTimeout(() => {
12
+ func(...args)
13
+ }, wait)
14
+ }
7
15
  }
8
16
 
9
17
  export function keyToLabel(key?: string): string | undefined {
@@ -0,0 +1,119 @@
1
+ type TapCallback = (event: { clientX: number, clientY: number }) => void
2
+ type CallbackType = 'single' | 'double'
3
+
4
+ export default class TapDetector {
5
+ private singleTapCallbacks: TapCallback[] = []
6
+ private doubleTapCallbacks: TapCallback[] = []
7
+ private isTouchMode = false
8
+ private lastTapTimestamp = 0
9
+ private tappedCount = 0
10
+ private touchMovedLength = 0
11
+ private lastPointerX = 0
12
+ private lastPointerY = 0
13
+
14
+ attach(dom: HTMLElement): void {
15
+ if (!(dom instanceof Element)) {
16
+ console.error('TapDetector.attach: arg must be an Element')
17
+ return
18
+ }
19
+ dom.addEventListener('touchstart', this.onTouchStart)
20
+ dom.addEventListener('touchmove', this.onTouchMove)
21
+ dom.addEventListener('touchend', this.onTouchEnd)
22
+ dom.addEventListener('mousedown', this.onMouseDown)
23
+ dom.addEventListener('mouseup', this.onMouseUp)
24
+ dom.addEventListener('mousemove', this.onMouseMove)
25
+ }
26
+
27
+ detach(dom: HTMLElement): void {
28
+ dom.removeEventListener('touchstart', this.onTouchStart)
29
+ dom.removeEventListener('touchmove', this.onTouchMove)
30
+ dom.removeEventListener('touchend', this.onTouchEnd)
31
+ dom.removeEventListener('mousedown', this.onMouseDown)
32
+ dom.removeEventListener('mouseup', this.onMouseUp)
33
+ dom.removeEventListener('mousemove', this.onMouseMove)
34
+ }
35
+
36
+ onSingleTap(callback: TapCallback): void {
37
+ if (typeof callback === 'function' && !this.singleTapCallbacks.includes(callback)) {
38
+ this.singleTapCallbacks.push(callback)
39
+ }
40
+ }
41
+
42
+ onDoubleTap(callback: TapCallback): void {
43
+ if (typeof callback === 'function' && !this.doubleTapCallbacks.includes(callback)) {
44
+ this.doubleTapCallbacks.push(callback)
45
+ }
46
+ }
47
+
48
+ private triggerCallbacks(callbackType: CallbackType, event: { clientX: number, clientY: number }): void {
49
+ const callbacks = callbackType === 'single' ? this.singleTapCallbacks : this.doubleTapCallbacks
50
+ callbacks.forEach((callback) => { callback(event) })
51
+ }
52
+
53
+ private onTouchStart = (event: TouchEvent): void => {
54
+ this.isTouchMode = true
55
+ if (event.touches.length === 1) {
56
+ this.onPointerDown(event.touches[0].clientX, event.touches[0].clientY)
57
+ }
58
+ }
59
+
60
+ private onTouchMove = (event: TouchEvent): void => {
61
+ if (event.touches.length === 1) {
62
+ this.onPointerMove(event.touches[0].clientX, event.touches[0].clientY)
63
+ }
64
+ }
65
+
66
+ private onTouchEnd = (): void => {
67
+ if (this.isTouchMode) this.onPointerUp()
68
+ }
69
+
70
+ private onMouseDown = (event: MouseEvent): void => {
71
+ if (!this.isTouchMode) {
72
+ this.onPointerDown(event.clientX, event.clientY)
73
+ }
74
+ }
75
+
76
+ private onMouseMove = (event: MouseEvent): void => {
77
+ if (!this.isTouchMode && event.button === 0) {
78
+ this.onPointerMove(event.clientX, event.clientY)
79
+ }
80
+ }
81
+
82
+ private onMouseUp = (): void => {
83
+ if (!this.isTouchMode) this.onPointerUp()
84
+ }
85
+
86
+ private onPointerDown(x: number, y: number): void {
87
+ this.lastPointerX = x
88
+ this.lastPointerY = y
89
+ this.touchMovedLength = 0
90
+ }
91
+
92
+ private onPointerUp(): void {
93
+ const currTimeStamp = Date.now()
94
+ if (this.touchMovedLength < 10) {
95
+ if (currTimeStamp - this.lastTapTimestamp < 300) {
96
+ this.tappedCount++
97
+ } else {
98
+ this.tappedCount = 1
99
+ }
100
+
101
+ this.lastTapTimestamp = currTimeStamp
102
+ this.triggerCallbacks('single', { clientX: this.lastPointerX, clientY: this.lastPointerY })
103
+
104
+ if (this.tappedCount === 2) {
105
+ this.triggerCallbacks('double', { clientX: this.lastPointerX, clientY: this.lastPointerY })
106
+ this.tappedCount = 0
107
+ }
108
+ }
109
+ this.touchMovedLength = 0
110
+ }
111
+
112
+ private onPointerMove(x: number, y: number): void {
113
+ const deltaX = this.lastPointerX - x
114
+ const deltaY = this.lastPointerY - y
115
+ this.touchMovedLength += Math.sqrt(deltaX * deltaX + deltaY * deltaY)
116
+ this.lastPointerX = x
117
+ this.lastPointerY = y
118
+ }
119
+ }