@dimailn/vuetify 2.7.2-alpha14 → 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 +116 -116
- 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/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/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/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/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/VGrid/VContainer.ts +1 -1
- package/src/components/VItemGroup/VItem.ts +25 -23
- 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,3 @@
|
|
|
1
|
-
import {h} from 'vue'
|
|
2
1
|
// Styles
|
|
3
2
|
import './VAppBar.sass'
|
|
4
3
|
|
|
@@ -16,10 +15,11 @@ import Toggleable from '../../mixins/toggleable'
|
|
|
16
15
|
|
|
17
16
|
// Utilities
|
|
18
17
|
import { convertToUnit } from '../../util/helpers'
|
|
18
|
+
import { mergeProps, withDirectives } from 'vue'
|
|
19
19
|
import mixins from '../../util/mixins'
|
|
20
20
|
|
|
21
21
|
// Types
|
|
22
|
-
import { VNode } from 'vue'
|
|
22
|
+
import type { VNode } from 'vue'
|
|
23
23
|
|
|
24
24
|
const baseMixins = mixins(
|
|
25
25
|
VToolbar,
|
|
@@ -239,8 +239,8 @@ export default baseMixins.extend({
|
|
|
239
239
|
genBackground () {
|
|
240
240
|
const render = VToolbar.methods.genBackground.call(this)
|
|
241
241
|
|
|
242
|
-
render.
|
|
243
|
-
style: { opacity: this.computedOpacity }
|
|
242
|
+
render.props = mergeProps(render.props || {}, {
|
|
243
|
+
style: { opacity: this.computedOpacity }
|
|
244
244
|
})
|
|
245
245
|
|
|
246
246
|
return render
|
|
@@ -268,19 +268,17 @@ export default baseMixins.extend({
|
|
|
268
268
|
},
|
|
269
269
|
|
|
270
270
|
render (): VNode {
|
|
271
|
-
const render = VToolbar.render.call(this
|
|
272
|
-
|
|
273
|
-
render.data = render.data || {}
|
|
271
|
+
const render = VToolbar.render.call(this)
|
|
274
272
|
|
|
275
273
|
if (this.canScroll) {
|
|
276
|
-
render.
|
|
277
|
-
render
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
value: this.onScroll,
|
|
281
|
-
})
|
|
274
|
+
render.key = 'v-app-bar-scroll'
|
|
275
|
+
return withDirectives(render, [
|
|
276
|
+
[Scroll, this.onScroll, this.scrollTarget],
|
|
277
|
+
])
|
|
282
278
|
}
|
|
283
279
|
|
|
280
|
+
render.key = 'v-app-bar-no-scroll'
|
|
281
|
+
|
|
284
282
|
return render
|
|
285
283
|
},
|
|
286
284
|
})
|
|
@@ -7,10 +7,9 @@ import { factory as GroupableFactory } from '../../mixins/groupable'
|
|
|
7
7
|
// Utilities
|
|
8
8
|
import mixins from '../../util/mixins'
|
|
9
9
|
import { consoleWarn } from '../../util/console'
|
|
10
|
+
import { defineComponent, mergeProps } from "vue"
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
import {defineComponent} from 'vue'
|
|
13
|
-
import { VNode, ScopedSlotChildren } from 'vue/types/vnode'
|
|
12
|
+
import type { VNode } from 'vue'
|
|
14
13
|
|
|
15
14
|
/* @vue/component */
|
|
16
15
|
export const BaseItem = defineComponent({
|
|
@@ -32,42 +31,45 @@ export const BaseItem = defineComponent({
|
|
|
32
31
|
},
|
|
33
32
|
},
|
|
34
33
|
|
|
35
|
-
render (): VNode {
|
|
34
|
+
render (): VNode | null {
|
|
36
35
|
if (!this.$slots.default) {
|
|
37
36
|
consoleWarn('v-item is missing a default scopedSlot', this)
|
|
38
|
-
|
|
39
|
-
return null as any
|
|
37
|
+
return null
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
const slotContent = this.$slots.default({
|
|
41
|
+
active: this.isActive,
|
|
42
|
+
toggle: this.toggle,
|
|
43
|
+
})
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
active: this.isActive,
|
|
48
|
-
toggle: this.toggle,
|
|
49
|
-
})
|
|
45
|
+
if (!slotContent || slotContent.length === 0) {
|
|
46
|
+
consoleWarn('v-item slot returned empty content', this)
|
|
47
|
+
return null
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
element = element[0]
|
|
54
|
-
}
|
|
50
|
+
let element = slotContent[0]
|
|
55
51
|
|
|
56
|
-
if (!element
|
|
57
|
-
consoleWarn('v-item should
|
|
52
|
+
if (!element) {
|
|
53
|
+
consoleWarn('v-item should contain at least one element', this)
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
if (!element.type) {
|
|
58
|
+
consoleWarn('v-item should only contain valid VNode elements', this)
|
|
59
|
+
return element
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
element.
|
|
62
|
+
element.props = mergeProps(element.props || {}, {
|
|
63
63
|
class: {
|
|
64
64
|
[this.activeClass]: this.isActive,
|
|
65
|
-
|
|
66
|
-
}
|
|
65
|
+
"v-item--disabled": this.disabled
|
|
66
|
+
}
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
if (this.disabled) {
|
|
70
|
-
element.
|
|
70
|
+
element.props = mergeProps(element.props || {}, {
|
|
71
|
+
tabindex: -1
|
|
72
|
+
})
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
return element
|
|
@@ -355,6 +355,7 @@ export default baseMixins.extend({
|
|
|
355
355
|
if (!this.showLabel) return null
|
|
356
356
|
|
|
357
357
|
const data = {
|
|
358
|
+
ref: "label",
|
|
358
359
|
absolute: true,
|
|
359
360
|
color: this.validationState,
|
|
360
361
|
dark: this.dark,
|
|
@@ -500,8 +501,8 @@ export default baseMixins.extend({
|
|
|
500
501
|
setLabelWidth () {
|
|
501
502
|
if (!this.outlined) return
|
|
502
503
|
|
|
503
|
-
this.labelWidth = this.$refs
|
|
504
|
-
? Math.min(this.$refs
|
|
504
|
+
this.labelWidth = this.$refs?.label?.$el
|
|
505
|
+
? Math.min(this.$refs?.label?.$el.scrollWidth * 0.75 + 6, (this.$el as HTMLElement).offsetWidth - 24)
|
|
505
506
|
: 0
|
|
506
507
|
},
|
|
507
508
|
setPrefixWidth () {
|
|
@@ -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
|