@dimailn/vuetify 2.7.2-alpha13 → 2.7.2-alpha15
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.
- package/dist/vuetify.js +134 -132
- package/dist/vuetify.js.map +1 -1
- package/dist/vuetify.min.css +1 -1
- package/dist/vuetify.min.js +2 -2
- package/es5/components/VAppBar/VAppBar.js +7 -12
- package/es5/components/VAppBar/VAppBar.js.map +1 -1
- package/es5/components/VAutocomplete/VAutocomplete.js +9 -6
- package/es5/components/VAutocomplete/VAutocomplete.js.map +1 -1
- package/es5/components/VGrid/VContainer.js +3 -1
- package/es5/components/VGrid/VContainer.js.map +1 -1
- package/es5/components/VItemGroup/VItem.js +17 -18
- package/es5/components/VItemGroup/VItem.js.map +1 -1
- package/es5/components/VRadioGroup/VRadioGroup.js +3 -3
- package/es5/components/VRadioGroup/VRadioGroup.js.map +1 -1
- package/es5/components/VTextField/VTextField.js +4 -1
- package/es5/components/VTextField/VTextField.js.map +1 -1
- package/es5/components/VToolbar/VToolbar.js +2 -3
- package/es5/components/VToolbar/VToolbar.js.map +1 -1
- package/es5/directives/intersect/index.js +20 -7
- package/es5/directives/intersect/index.js.map +1 -1
- package/es5/directives/mutate/index.js +13 -13
- package/es5/directives/mutate/index.js.map +1 -1
- package/es5/directives/resize/index.js +8 -8
- package/es5/directives/resize/index.js.map +1 -1
- package/es5/directives/scroll/index.js +10 -9
- package/es5/directives/scroll/index.js.map +1 -1
- package/es5/directives/touch/index.js +4 -4
- package/es5/directives/touch/index.js.map +1 -1
- package/es5/framework.js +1 -1
- package/lib/components/VAppBar/VAppBar.js +7 -11
- package/lib/components/VAppBar/VAppBar.js.map +1 -1
- package/lib/components/VAutocomplete/VAutocomplete.js +10 -7
- package/lib/components/VAutocomplete/VAutocomplete.js.map +1 -1
- package/lib/components/VGrid/VContainer.js +3 -1
- package/lib/components/VGrid/VContainer.js.map +1 -1
- package/lib/components/VItemGroup/VItem.js +20 -18
- package/lib/components/VItemGroup/VItem.js.map +1 -1
- package/lib/components/VRadioGroup/VRadioGroup.js +3 -5
- package/lib/components/VRadioGroup/VRadioGroup.js.map +1 -1
- package/lib/components/VTextField/VTextField.js +4 -1
- package/lib/components/VTextField/VTextField.js.map +1 -1
- package/lib/components/VToolbar/VToolbar.js +4 -3
- package/lib/components/VToolbar/VToolbar.js.map +1 -1
- package/lib/directives/intersect/index.js +20 -7
- package/lib/directives/intersect/index.js.map +1 -1
- package/lib/directives/mutate/index.js +13 -13
- package/lib/directives/mutate/index.js.map +1 -1
- package/lib/directives/resize/index.js +8 -8
- package/lib/directives/resize/index.js.map +1 -1
- package/lib/directives/scroll/index.js +10 -9
- package/lib/directives/scroll/index.js.map +1 -1
- package/lib/directives/touch/index.js +4 -4
- package/lib/directives/touch/index.js.map +1 -1
- package/lib/framework.js +1 -1
- package/package.json +1 -1
- package/src/components/VAppBar/VAppBar.ts +11 -13
- package/src/components/VAutocomplete/VAutocomplete.ts +12 -5
- package/src/components/VGrid/VContainer.ts +1 -1
- package/src/components/VItemGroup/VItem.ts +25 -23
- package/src/components/VRadioGroup/VRadioGroup.ts +6 -7
- package/src/components/VTextField/VTextField.ts +3 -2
- package/src/components/VToolbar/VToolbar.ts +4 -5
- package/src/directives/intersect/index.ts +81 -42
- package/src/directives/mutate/index.ts +58 -49
- package/src/directives/resize/index.ts +33 -14
- package/src/directives/scroll/index.ts +36 -20
- package/src/directives/touch/index.ts +37 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {h} from 'vue'
|
|
1
|
+
import { h } from 'vue'
|
|
2
2
|
// Styles
|
|
3
3
|
import './VToolbar.sass'
|
|
4
4
|
|
|
@@ -156,13 +156,12 @@ export default defineComponent({
|
|
|
156
156
|
const children = [this.genContent()]
|
|
157
157
|
const data = this.setBackgroundColor(this.color, {
|
|
158
158
|
class: this.classes,
|
|
159
|
-
style: this.styles
|
|
160
|
-
on: this.$listeners,
|
|
159
|
+
style: this.styles
|
|
161
160
|
})
|
|
162
161
|
|
|
163
162
|
if (this.isExtended) children.push(this.genExtension())
|
|
164
163
|
if (this.src || this.$slots.img) children.unshift(this.genBackground())
|
|
165
164
|
|
|
166
|
-
return h(this.tag, data, children)
|
|
167
|
-
}
|
|
165
|
+
return h(this.tag, {...this.attrs$, ...data}, children)
|
|
166
|
+
}
|
|
168
167
|
})
|
|
@@ -1,55 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VNode } from 'vue'
|
|
1
|
+
import { DirectiveBinding, ObjectDirective, VNode } from 'vue'
|
|
3
2
|
|
|
4
3
|
type ObserveHandler = (
|
|
5
4
|
entries: IntersectionObserverEntry[],
|
|
6
5
|
observer: IntersectionObserver,
|
|
7
|
-
isIntersecting: boolean
|
|
8
|
-
) => void
|
|
6
|
+
isIntersecting: boolean
|
|
7
|
+
) => void;
|
|
9
8
|
|
|
10
|
-
interface
|
|
11
|
-
|
|
9
|
+
interface ObserveDirectiveBinding
|
|
10
|
+
extends Omit<DirectiveBinding, 'modifiers' | 'value'> {
|
|
11
|
+
value?:
|
|
12
|
+
| ObserveHandler
|
|
13
|
+
| { handler: ObserveHandler, options?: IntersectionObserverInit }
|
|
12
14
|
modifiers?: {
|
|
13
15
|
once?: boolean
|
|
14
16
|
quiet?: boolean
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// Расширяем HTMLElement для хранения данных наблюдателя
|
|
21
|
+
declare global {
|
|
22
|
+
interface HTMLElement {
|
|
23
|
+
_observe?: Record<
|
|
24
|
+
number,
|
|
25
|
+
{ init: boolean, observer: IntersectionObserver }
|
|
26
|
+
>
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function mounted (
|
|
31
|
+
el: HTMLElement,
|
|
32
|
+
binding: ObserveDirectiveBinding,
|
|
33
|
+
vnode: VNode
|
|
34
|
+
) {
|
|
35
|
+
if (typeof window === 'undefined' || !('IntersectionObserver' in window)) { return }
|
|
20
36
|
|
|
21
37
|
const modifiers = binding.modifiers || {}
|
|
22
38
|
const value = binding.value
|
|
23
|
-
const { handler, options } =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
_observe.init
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
const { handler, options } =
|
|
40
|
+
typeof value === 'object' && value !== null && 'handler' in value
|
|
41
|
+
? value
|
|
42
|
+
: { handler: value, options: {} }
|
|
43
|
+
|
|
44
|
+
if (!handler) return
|
|
45
|
+
|
|
46
|
+
const observer = new IntersectionObserver(
|
|
47
|
+
(
|
|
48
|
+
entries: IntersectionObserverEntry[] = [],
|
|
49
|
+
observer: IntersectionObserver
|
|
50
|
+
) => {
|
|
51
|
+
const _observe = el._observe?.[vnode.ctx!.uid]
|
|
52
|
+
if (!_observe) return // Just in case, should never fire
|
|
53
|
+
|
|
54
|
+
const isIntersecting = entries.some(entry => entry.isIntersecting)
|
|
55
|
+
|
|
56
|
+
// If is not quiet or has already been
|
|
57
|
+
// initted, invoke the user callback
|
|
58
|
+
if (
|
|
59
|
+
handler &&
|
|
60
|
+
(!modifiers.quiet || _observe.init) &&
|
|
61
|
+
(!modifiers.once || isIntersecting || _observe.init)
|
|
62
|
+
) {
|
|
63
|
+
handler(entries, observer, isIntersecting)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isIntersecting && modifiers.once) unmounted(el, binding, vnode)
|
|
67
|
+
else _observe.init = true
|
|
68
|
+
},
|
|
69
|
+
options
|
|
70
|
+
)
|
|
53
71
|
|
|
54
72
|
el._observe = Object(el._observe)
|
|
55
73
|
el._observe![vnode.ctx!.uid] = { init: false, observer }
|
|
@@ -57,7 +75,23 @@ function inserted (el: HTMLElement, binding: ObserveVNodeDirective, vnode: VNode
|
|
|
57
75
|
observer.observe(el)
|
|
58
76
|
}
|
|
59
77
|
|
|
60
|
-
function
|
|
78
|
+
function updated (
|
|
79
|
+
el: HTMLElement,
|
|
80
|
+
binding: ObserveDirectiveBinding,
|
|
81
|
+
vnode: VNode
|
|
82
|
+
) {
|
|
83
|
+
// Если значение изменилось, пересоздаем observer
|
|
84
|
+
if (binding.value !== binding.oldValue) {
|
|
85
|
+
unmounted(el, binding, vnode)
|
|
86
|
+
mounted(el, binding, vnode)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function unmounted (
|
|
91
|
+
el: HTMLElement,
|
|
92
|
+
binding: ObserveDirectiveBinding,
|
|
93
|
+
vnode: VNode
|
|
94
|
+
) {
|
|
61
95
|
const observe = el._observe?.[vnode.ctx!.uid]
|
|
62
96
|
if (!observe) return
|
|
63
97
|
|
|
@@ -65,9 +99,14 @@ function unbind (el: HTMLElement, binding: ObserveVNodeDirective, vnode: VNode)
|
|
|
65
99
|
delete el._observe![vnode.ctx!.uid]
|
|
66
100
|
}
|
|
67
101
|
|
|
68
|
-
export const Intersect
|
|
69
|
-
|
|
70
|
-
|
|
102
|
+
export const Intersect: ObjectDirective<
|
|
103
|
+
HTMLElement,
|
|
104
|
+
| ObserveHandler
|
|
105
|
+
| { handler: ObserveHandler, options?: IntersectionObserverInit }
|
|
106
|
+
> = {
|
|
107
|
+
mounted,
|
|
108
|
+
updated,
|
|
109
|
+
unmounted,
|
|
71
110
|
}
|
|
72
111
|
|
|
73
112
|
export default Intersect
|
|
@@ -1,75 +1,84 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DirectiveBinding, VNode } from 'vue'
|
|
2
2
|
|
|
3
3
|
type MutateHandler = (
|
|
4
4
|
mutationsList: MutationRecord[],
|
|
5
|
-
observer: MutationObserver
|
|
6
|
-
) => void
|
|
5
|
+
observer: MutationObserver
|
|
6
|
+
) => void;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
type MutateValue =
|
|
9
|
+
| MutateHandler
|
|
10
|
+
| { handler: MutateHandler, options?: MutationObserverInit };
|
|
11
|
+
|
|
12
|
+
type MutateModifiers = {
|
|
13
|
+
once?: boolean
|
|
14
|
+
attr?: boolean
|
|
15
|
+
child?: boolean
|
|
16
|
+
sub?: boolean
|
|
17
|
+
char?: boolean
|
|
18
|
+
};
|
|
18
19
|
|
|
19
|
-
function
|
|
20
|
-
|
|
20
|
+
function mounted (
|
|
21
|
+
el: HTMLElement,
|
|
22
|
+
binding: DirectiveBinding<MutateValue>,
|
|
23
|
+
vnode: VNode
|
|
24
|
+
) {
|
|
25
|
+
const modifiers = (binding.modifiers as MutateModifiers) || {}
|
|
21
26
|
const value = binding.value
|
|
22
27
|
const callback = typeof value === 'object' ? value.handler : value!
|
|
23
28
|
const { once, ...modifierKeys } = modifiers
|
|
24
29
|
const hasModifiers = Object.keys(modifierKeys).length > 0
|
|
25
30
|
|
|
26
31
|
// Options take top priority
|
|
27
|
-
const options =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
const options =
|
|
33
|
+
typeof value === 'object' && value.options
|
|
34
|
+
? value.options
|
|
35
|
+
: hasModifiers
|
|
36
|
+
? {
|
|
37
|
+
// If we have modifiers, use only those provided
|
|
38
|
+
attributes: modifierKeys.attr,
|
|
39
|
+
childList: modifierKeys.child,
|
|
40
|
+
subtree: modifierKeys.sub,
|
|
41
|
+
characterData: modifierKeys.char,
|
|
42
|
+
}
|
|
43
|
+
: {
|
|
44
|
+
// Defaults to everything on
|
|
45
|
+
attributes: true,
|
|
46
|
+
childList: true,
|
|
47
|
+
subtree: true,
|
|
48
|
+
characterData: true,
|
|
49
|
+
}
|
|
44
50
|
|
|
45
|
-
const observer = new MutationObserver(
|
|
46
|
-
mutationsList: MutationRecord[],
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/* istanbul ignore if */
|
|
50
|
-
if (!el._mutate) return // Just in case, should never fire
|
|
51
|
+
const observer = new MutationObserver(
|
|
52
|
+
(mutationsList: MutationRecord[], observer: MutationObserver) => {
|
|
53
|
+
/* istanbul ignore if */
|
|
54
|
+
if (!el._mutate) return // Just in case, should never fire
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
callback(mutationsList, observer)
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
// If has the once modifier, unbind
|
|
59
|
+
once && unmounted(el, binding, vnode)
|
|
60
|
+
}
|
|
61
|
+
)
|
|
57
62
|
|
|
58
63
|
observer.observe(el, options)
|
|
59
64
|
el._mutate = Object(el._mutate)
|
|
60
|
-
el._mutate![vnode.
|
|
65
|
+
el._mutate![vnode.ctx!.uid] = { observer }
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
function
|
|
64
|
-
|
|
68
|
+
function unmounted (
|
|
69
|
+
el: HTMLElement,
|
|
70
|
+
binding: DirectiveBinding<MutateValue>,
|
|
71
|
+
vnode: VNode
|
|
72
|
+
) {
|
|
73
|
+
if (!el._mutate?.[vnode.ctx!.uid]) return
|
|
65
74
|
|
|
66
|
-
el._mutate[vnode.
|
|
67
|
-
delete el._mutate[vnode.
|
|
75
|
+
el._mutate[vnode.ctx!.uid]!.observer.disconnect()
|
|
76
|
+
delete el._mutate[vnode.ctx!.uid]
|
|
68
77
|
}
|
|
69
78
|
|
|
70
79
|
export const Mutate = {
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
mounted,
|
|
81
|
+
unmounted,
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
export default Mutate
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { VNode } from 'vue'
|
|
1
|
+
import { DirectiveBinding, ObjectDirective, VNode } from 'vue'
|
|
3
2
|
|
|
4
|
-
interface
|
|
5
|
-
value
|
|
3
|
+
interface ResizeDirectiveBinding extends DirectiveBinding {
|
|
4
|
+
value: () => void
|
|
6
5
|
options?: boolean | AddEventListenerOptions
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
declare global {
|
|
9
|
+
interface HTMLElement {
|
|
10
|
+
_onResize?: Record<
|
|
11
|
+
number,
|
|
12
|
+
{
|
|
13
|
+
callback: () => void
|
|
14
|
+
options: boolean | AddEventListenerOptions
|
|
15
|
+
}
|
|
16
|
+
>
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function mounted (
|
|
21
|
+
el: HTMLElement,
|
|
22
|
+
binding: ResizeDirectiveBinding,
|
|
23
|
+
vnode: VNode
|
|
24
|
+
) {
|
|
25
|
+
const callback = binding.value
|
|
11
26
|
const options = binding.options || { passive: true }
|
|
12
27
|
|
|
13
28
|
window.addEventListener('resize', callback, options)
|
|
14
29
|
|
|
15
30
|
el._onResize = Object(el._onResize)
|
|
16
|
-
el._onResize![vnode.
|
|
31
|
+
el._onResize![vnode.ctx!.uid] = {
|
|
17
32
|
callback,
|
|
18
33
|
options,
|
|
19
34
|
}
|
|
@@ -23,19 +38,23 @@ function inserted (el: HTMLElement, binding: ResizeVNodeDirective, vnode: VNode)
|
|
|
23
38
|
}
|
|
24
39
|
}
|
|
25
40
|
|
|
26
|
-
function
|
|
27
|
-
|
|
41
|
+
function unmounted (
|
|
42
|
+
el: HTMLElement,
|
|
43
|
+
binding: ResizeDirectiveBinding,
|
|
44
|
+
vnode: VNode
|
|
45
|
+
) {
|
|
46
|
+
if (!el._onResize?.[vnode.ctx!.uid]) return
|
|
28
47
|
|
|
29
|
-
const { callback, options } = el._onResize[vnode.
|
|
48
|
+
const { callback, options } = el._onResize[vnode.ctx!.uid]!
|
|
30
49
|
|
|
31
50
|
window.removeEventListener('resize', callback, options)
|
|
32
51
|
|
|
33
|
-
delete el._onResize[vnode.
|
|
52
|
+
delete el._onResize[vnode.ctx!.uid]
|
|
34
53
|
}
|
|
35
54
|
|
|
36
|
-
export const Resize = {
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
export const Resize: ObjectDirective = {
|
|
56
|
+
mounted,
|
|
57
|
+
unmounted,
|
|
39
58
|
}
|
|
40
59
|
|
|
41
60
|
export default Resize
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { DirectiveBinding, VNode, ObjectDirective } from 'vue'
|
|
2
|
+
|
|
3
|
+
interface ScrollDirectiveBinding extends Omit<DirectiveBinding, 'modifiers'> {
|
|
4
|
+
value:
|
|
5
|
+
| EventListener
|
|
6
|
+
| {
|
|
7
|
+
handler: EventListener
|
|
8
|
+
options?: boolean | AddEventListenerOptions
|
|
9
|
+
}
|
|
10
|
+
| (EventListenerObject & { options?: boolean | AddEventListenerOptions })
|
|
9
11
|
modifiers?: {
|
|
10
12
|
self?: boolean
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
function
|
|
16
|
+
function mounted (
|
|
17
|
+
el: HTMLElement,
|
|
18
|
+
binding: ScrollDirectiveBinding,
|
|
19
|
+
vnode: VNode
|
|
20
|
+
) {
|
|
15
21
|
const { self = false } = binding.modifiers || {}
|
|
16
22
|
const value = binding.value
|
|
17
|
-
const options = (typeof value === 'object' && value.options) || {
|
|
18
|
-
|
|
23
|
+
const options = (typeof value === 'object' && value.options) || {
|
|
24
|
+
passive: true,
|
|
25
|
+
}
|
|
26
|
+
const handler =
|
|
27
|
+
typeof value === 'function' || 'handleEvent' in value
|
|
28
|
+
? value
|
|
29
|
+
: value.handler
|
|
19
30
|
|
|
20
31
|
const target = self
|
|
21
32
|
? el
|
|
@@ -28,7 +39,8 @@ function inserted (el: HTMLElement, binding: ScrollVNodeDirective, vnode: VNode)
|
|
|
28
39
|
target.addEventListener('scroll', handler, options)
|
|
29
40
|
|
|
30
41
|
el._onScroll = Object(el._onScroll)
|
|
31
|
-
|
|
42
|
+
// В Vue 3 используем vnode.ctx.uid вместо vnode.context._uid
|
|
43
|
+
el._onScroll![vnode.ctx!.uid] = {
|
|
32
44
|
handler,
|
|
33
45
|
options,
|
|
34
46
|
// Don't reference self
|
|
@@ -36,18 +48,22 @@ function inserted (el: HTMLElement, binding: ScrollVNodeDirective, vnode: VNode)
|
|
|
36
48
|
}
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
function
|
|
40
|
-
|
|
51
|
+
function unmounted (
|
|
52
|
+
el: HTMLElement,
|
|
53
|
+
binding: ScrollDirectiveBinding,
|
|
54
|
+
vnode: VNode
|
|
55
|
+
) {
|
|
56
|
+
if (!el._onScroll?.[vnode.ctx!.uid]) return
|
|
41
57
|
|
|
42
|
-
const { handler, options, target = el } = el._onScroll[vnode.
|
|
58
|
+
const { handler, options, target = el } = el._onScroll[vnode.ctx!.uid]!
|
|
43
59
|
|
|
44
60
|
target.removeEventListener('scroll', handler, options)
|
|
45
|
-
delete el._onScroll[vnode.
|
|
61
|
+
delete el._onScroll[vnode.ctx!.uid]
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
export const Scroll = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
64
|
+
export const Scroll: ObjectDirective = {
|
|
65
|
+
mounted,
|
|
66
|
+
unmounted,
|
|
67
|
+
}
|
|
52
68
|
|
|
53
69
|
export default Scroll
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DirectiveBinding, VNode, ObjectDirective } from 'vue'
|
|
2
2
|
import { keys } from '../../util/helpers'
|
|
3
3
|
import { TouchHandlers, TouchValue, TouchWrapper } from 'vuetify/types'
|
|
4
4
|
import makeDirectiveActivatable from '../../util/make-directive-activatable'
|
|
@@ -9,10 +9,6 @@ export interface TouchStoredHandlers {
|
|
|
9
9
|
touchmove: (e: TouchEvent) => void
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
interface TouchVNodeDirective extends VNodeDirective {
|
|
13
|
-
value?: TouchValue
|
|
14
|
-
}
|
|
15
|
-
|
|
16
12
|
const handleGesture = (wrapper: TouchWrapper) => {
|
|
17
13
|
const { touchstartX, touchendX, touchstartY, touchendY } = wrapper
|
|
18
14
|
const dirRatio = 0.5
|
|
@@ -21,13 +17,19 @@ const handleGesture = (wrapper: TouchWrapper) => {
|
|
|
21
17
|
wrapper.offsetY = touchendY - touchstartY
|
|
22
18
|
|
|
23
19
|
if (Math.abs(wrapper.offsetY) < dirRatio * Math.abs(wrapper.offsetX)) {
|
|
24
|
-
wrapper.left &&
|
|
25
|
-
|
|
20
|
+
wrapper.left &&
|
|
21
|
+
touchendX < touchstartX - minDistance &&
|
|
22
|
+
wrapper.left(wrapper)
|
|
23
|
+
wrapper.right &&
|
|
24
|
+
touchendX > touchstartX + minDistance &&
|
|
25
|
+
wrapper.right(wrapper)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
if (Math.abs(wrapper.offsetX) < dirRatio * Math.abs(wrapper.offsetY)) {
|
|
29
|
-
wrapper.up &&
|
|
30
|
-
wrapper.down &&
|
|
29
|
+
wrapper.up && touchendY < touchstartY - minDistance && wrapper.up(wrapper)
|
|
30
|
+
wrapper.down &&
|
|
31
|
+
touchendY > touchstartY + minDistance &&
|
|
32
|
+
wrapper.down(wrapper)
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -36,8 +38,7 @@ function touchstart (event: TouchEvent, wrapper: TouchWrapper) {
|
|
|
36
38
|
wrapper.touchstartX = touch.clientX
|
|
37
39
|
wrapper.touchstartY = touch.clientY
|
|
38
40
|
|
|
39
|
-
wrapper.start &&
|
|
40
|
-
wrapper.start(Object.assign(event, wrapper))
|
|
41
|
+
wrapper.start && wrapper.start(Object.assign(event, wrapper))
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function touchend (event: TouchEvent, wrapper: TouchWrapper) {
|
|
@@ -45,8 +46,7 @@ function touchend (event: TouchEvent, wrapper: TouchWrapper) {
|
|
|
45
46
|
wrapper.touchendX = touch.clientX
|
|
46
47
|
wrapper.touchendY = touch.clientY
|
|
47
48
|
|
|
48
|
-
wrapper.end &&
|
|
49
|
-
wrapper.end(Object.assign(event, wrapper))
|
|
49
|
+
wrapper.end && wrapper.end(Object.assign(event, wrapper))
|
|
50
50
|
|
|
51
51
|
handleGesture(wrapper)
|
|
52
52
|
}
|
|
@@ -85,39 +85,49 @@ function createHandlers (value: TouchHandlers): TouchStoredHandlers {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function
|
|
89
|
-
|
|
88
|
+
function mounted (
|
|
89
|
+
el: HTMLElement,
|
|
90
|
+
binding: DirectiveBinding<TouchValue>,
|
|
91
|
+
vnode: VNode
|
|
92
|
+
) {
|
|
93
|
+
const value = binding.value
|
|
90
94
|
const target = value.parent ? el.parentElement : el
|
|
91
95
|
const options = value.options || { passive: true }
|
|
92
96
|
|
|
93
97
|
// Needed to pass unit tests
|
|
94
98
|
if (!target) return
|
|
95
99
|
|
|
96
|
-
const handlers = createHandlers(binding.value
|
|
100
|
+
const handlers = createHandlers(binding.value)
|
|
97
101
|
target._touchHandlers = Object(target._touchHandlers)
|
|
98
|
-
target._touchHandlers![vnode.ctx
|
|
102
|
+
target._touchHandlers![vnode.ctx!.uid] = handlers
|
|
99
103
|
|
|
100
104
|
keys(handlers).forEach(eventName => {
|
|
101
|
-
target.addEventListener(
|
|
105
|
+
target.addEventListener(
|
|
106
|
+
eventName,
|
|
107
|
+
handlers[eventName] as EventListener,
|
|
108
|
+
options
|
|
109
|
+
)
|
|
102
110
|
})
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
function
|
|
106
|
-
|
|
113
|
+
function unmounted (
|
|
114
|
+
el: HTMLElement,
|
|
115
|
+
binding: DirectiveBinding<TouchValue>,
|
|
116
|
+
vnode: VNode
|
|
117
|
+
) {
|
|
118
|
+
const target = binding.value.parent ? el.parentElement : el
|
|
107
119
|
if (!target || !target._touchHandlers) return
|
|
108
120
|
|
|
109
|
-
const handlers = target._touchHandlers[vnode.ctx
|
|
121
|
+
const handlers = target._touchHandlers[vnode.ctx!.uid]
|
|
110
122
|
keys(handlers).forEach(eventName => {
|
|
111
123
|
target.removeEventListener(eventName, handlers[eventName])
|
|
112
124
|
})
|
|
113
|
-
delete target._touchHandlers[vnode.ctx
|
|
125
|
+
delete target._touchHandlers[vnode.ctx!.uid]
|
|
114
126
|
}
|
|
115
127
|
|
|
116
|
-
export const Touch = {
|
|
117
|
-
mounted
|
|
118
|
-
unmounted
|
|
128
|
+
export const Touch: ObjectDirective<HTMLElement, TouchValue> = {
|
|
129
|
+
mounted,
|
|
130
|
+
unmounted,
|
|
119
131
|
}
|
|
120
132
|
|
|
121
|
-
|
|
122
|
-
|
|
123
133
|
export default makeDirectiveActivatable(Touch)
|