vue-tippy 6.0.0-alpha.50 → 6.0.0-alpha.51
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/vue-tippy.cjs +1 -1
- package/dist/vue-tippy.esm-browser.js +1 -1
- package/dist/vue-tippy.iife.js +1 -1
- package/dist/vue-tippy.iife.prod.js +1 -1
- package/dist/vue-tippy.mjs +1 -1
- package/dist/vue-tippy.prod.cjs +1 -1
- package/package.json +3 -1
- package/src/components/Tippy.ts +141 -0
- package/src/components/TippySingleton.ts +74 -0
- package/src/composables/index.ts +3 -0
- package/src/composables/useSingleton.ts +44 -0
- package/src/composables/useTippy.ts +255 -0
- package/src/composables/useTippyComponent.ts +25 -0
- package/src/directive/index.ts +89 -0
- package/src/global.d.ts +4 -0
- package/src/index.ts +39 -0
- package/src/plugin/index.ts +18 -0
- package/src/types/index.ts +30 -0
- package/tsconfig.json +31 -0
package/dist/vue-tippy.cjs
CHANGED
package/dist/vue-tippy.iife.js
CHANGED
package/dist/vue-tippy.mjs
CHANGED
package/dist/vue-tippy.prod.cjs
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "vue-tippy",
|
3
|
-
"version": "6.0.0-alpha.
|
3
|
+
"version": "6.0.0-alpha.51",
|
4
4
|
"main": "index.js",
|
5
5
|
"module": "dist/vue-tippy.mjs",
|
6
6
|
"unpkg": "dist/vue-tippy.iife.js",
|
@@ -29,6 +29,7 @@
|
|
29
29
|
"sideEffects": false,
|
30
30
|
"license": "MIT",
|
31
31
|
"files": [
|
32
|
+
"src/**/*",
|
32
33
|
"dist/*.js",
|
33
34
|
"dist/*.mjs",
|
34
35
|
"dist/*.cjs",
|
@@ -36,6 +37,7 @@
|
|
36
37
|
"index.js",
|
37
38
|
"index.cjs",
|
38
39
|
"vetur/*.json",
|
40
|
+
"tsconfig.json",
|
39
41
|
"LICENSE",
|
40
42
|
"README.md"
|
41
43
|
],
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import { defineComponent, ref, h, ComponentObjectPropsOptions, onMounted, nextTick, watch, unref } from 'vue'
|
2
|
+
import { TippyOptions } from '../types'
|
3
|
+
import { useTippy } from '../composables'
|
4
|
+
import tippy, { DefaultProps } from 'tippy.js'
|
5
|
+
|
6
|
+
declare module '@vue/runtime-core' {
|
7
|
+
interface ComponentCustomProps extends TippyOptions { }
|
8
|
+
}
|
9
|
+
|
10
|
+
// const pluginProps = [
|
11
|
+
// 'animateFill',
|
12
|
+
// 'followCursor',
|
13
|
+
// 'inlinePositioning',
|
14
|
+
// 'sticky',
|
15
|
+
// ]
|
16
|
+
const booleanProps = [
|
17
|
+
'a11y',
|
18
|
+
'allowHTML',
|
19
|
+
'arrow',
|
20
|
+
'flip',
|
21
|
+
'flipOnUpdate',
|
22
|
+
'hideOnClick',
|
23
|
+
'ignoreAttributes',
|
24
|
+
'inertia',
|
25
|
+
'interactive',
|
26
|
+
'lazy',
|
27
|
+
'multiple',
|
28
|
+
'showOnInit',
|
29
|
+
'touch',
|
30
|
+
'touchHold',
|
31
|
+
]
|
32
|
+
|
33
|
+
let props: ComponentObjectPropsOptions = {}
|
34
|
+
|
35
|
+
Object.keys(tippy.defaultProps).forEach((prop: string) => {
|
36
|
+
if (booleanProps.includes(prop)) {
|
37
|
+
props[prop] = {
|
38
|
+
type: prop === 'arrow' ? [String, Boolean, SVGElement, DocumentFragment] : Boolean,
|
39
|
+
default: function () {
|
40
|
+
return tippy.defaultProps[prop as keyof DefaultProps] as Boolean
|
41
|
+
},
|
42
|
+
}
|
43
|
+
} else {
|
44
|
+
props[prop] = {
|
45
|
+
default: function () {
|
46
|
+
return tippy.defaultProps[prop as keyof DefaultProps]
|
47
|
+
},
|
48
|
+
}
|
49
|
+
}
|
50
|
+
})
|
51
|
+
|
52
|
+
props['to'] = {}
|
53
|
+
|
54
|
+
props['tag'] = {
|
55
|
+
default: 'span'
|
56
|
+
}
|
57
|
+
|
58
|
+
props['contentTag'] = {
|
59
|
+
default: 'span'
|
60
|
+
}
|
61
|
+
|
62
|
+
props['contentClass'] = {
|
63
|
+
default: null
|
64
|
+
}
|
65
|
+
|
66
|
+
const TippyComponent = defineComponent({
|
67
|
+
props,
|
68
|
+
emits: ['state'],
|
69
|
+
setup(props, { slots, emit, expose }) {
|
70
|
+
const elem = ref<Element>()
|
71
|
+
const contentElem = ref<Element>()
|
72
|
+
const mounted = ref(false)
|
73
|
+
|
74
|
+
let options = { ...props } as TippyOptions;
|
75
|
+
|
76
|
+
for (const prop of ['to', 'tag', 'contentTag', 'contentClass']) {
|
77
|
+
if (options.hasOwnProperty(prop)) {
|
78
|
+
// @ts-ignore
|
79
|
+
delete options[prop];
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
let target: any = elem
|
84
|
+
|
85
|
+
if (props.to) {
|
86
|
+
if (typeof Element !== 'undefined' && props.to instanceof Element) {
|
87
|
+
target = () => props.to
|
88
|
+
} else if (typeof props.to === 'string' || props.to instanceof String) {
|
89
|
+
target = () => document.querySelector(props.to)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
const tippy = useTippy(target, options)
|
94
|
+
|
95
|
+
onMounted(() => {
|
96
|
+
mounted.value = true
|
97
|
+
|
98
|
+
nextTick(() => {
|
99
|
+
if (slots.content)
|
100
|
+
tippy.setContent(() => contentElem.value)
|
101
|
+
})
|
102
|
+
})
|
103
|
+
|
104
|
+
watch(tippy.state, () => {
|
105
|
+
emit('state', unref(tippy.state))
|
106
|
+
}, { immediate: true, deep: true })
|
107
|
+
|
108
|
+
watch(props, () => {
|
109
|
+
tippy.setProps(props)
|
110
|
+
})
|
111
|
+
|
112
|
+
let exposed = {
|
113
|
+
elem,
|
114
|
+
contentElem,
|
115
|
+
mounted,
|
116
|
+
...tippy
|
117
|
+
}
|
118
|
+
|
119
|
+
expose(exposed)
|
120
|
+
|
121
|
+
const slot = slots.default ? slots.default(exposed) : []
|
122
|
+
|
123
|
+
return () => {
|
124
|
+
|
125
|
+
return h(props.tag, { ref: elem, 'data-v-tippy': '' }, slots.content ? [
|
126
|
+
slot,
|
127
|
+
h(
|
128
|
+
props.contentTag,
|
129
|
+
{
|
130
|
+
ref: contentElem,
|
131
|
+
style: { display: mounted.value ? 'inherit' : 'none' },
|
132
|
+
class: props.contentClass
|
133
|
+
},
|
134
|
+
slots.content(exposed)
|
135
|
+
),
|
136
|
+
] : slot)
|
137
|
+
}
|
138
|
+
},
|
139
|
+
})
|
140
|
+
|
141
|
+
export default TippyComponent
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { Instance } from 'tippy.js'
|
2
|
+
import { ComponentObjectPropsOptions, defineComponent, h, ref } from 'vue'
|
3
|
+
import { useSingleton } from '../composables'
|
4
|
+
import { TippyOptions } from '../types'
|
5
|
+
import tippy, { DefaultProps } from 'tippy.js'
|
6
|
+
|
7
|
+
declare module '@vue/runtime-core' {
|
8
|
+
interface ComponentCustomProps extends TippyOptions {}
|
9
|
+
}
|
10
|
+
|
11
|
+
const booleanProps = [
|
12
|
+
'a11y',
|
13
|
+
'allowHTML',
|
14
|
+
'arrow',
|
15
|
+
'flip',
|
16
|
+
'flipOnUpdate',
|
17
|
+
'hideOnClick',
|
18
|
+
'ignoreAttributes',
|
19
|
+
'inertia',
|
20
|
+
'interactive',
|
21
|
+
'lazy',
|
22
|
+
'multiple',
|
23
|
+
'showOnInit',
|
24
|
+
'touch',
|
25
|
+
'touchHold',
|
26
|
+
]
|
27
|
+
|
28
|
+
let props: ComponentObjectPropsOptions = {}
|
29
|
+
|
30
|
+
Object.keys(tippy.defaultProps).forEach((prop: string) => {
|
31
|
+
if (booleanProps.includes(prop)) {
|
32
|
+
props[prop] = {
|
33
|
+
type: Boolean,
|
34
|
+
default: function () {
|
35
|
+
return tippy.defaultProps[prop as keyof DefaultProps] as Boolean
|
36
|
+
},
|
37
|
+
}
|
38
|
+
} else {
|
39
|
+
props[prop] = {
|
40
|
+
default: function () {
|
41
|
+
return tippy.defaultProps[prop as keyof DefaultProps]
|
42
|
+
},
|
43
|
+
}
|
44
|
+
}
|
45
|
+
})
|
46
|
+
|
47
|
+
|
48
|
+
const TippySingleton = defineComponent({
|
49
|
+
props,
|
50
|
+
setup(props) {
|
51
|
+
const instances = ref<Instance<any>[]>([])
|
52
|
+
|
53
|
+
const { singleton } = useSingleton(instances, props)
|
54
|
+
|
55
|
+
return { instances, singleton }
|
56
|
+
},
|
57
|
+
mounted() {
|
58
|
+
const parent = this.$el.parentElement
|
59
|
+
const elements = parent.querySelectorAll('[data-v-tippy]')
|
60
|
+
|
61
|
+
this.instances = Array.from(elements)
|
62
|
+
.map((el: any) => el._tippy)
|
63
|
+
.filter(Boolean)
|
64
|
+
|
65
|
+
this.singleton?.setInstances(this.instances)
|
66
|
+
},
|
67
|
+
render() {
|
68
|
+
let slot = this.$slots.default ? this.$slots.default() : []
|
69
|
+
|
70
|
+
return h(() => slot)
|
71
|
+
},
|
72
|
+
})
|
73
|
+
|
74
|
+
export default TippySingleton
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { TippyInstance, TippyInstances } from '../types'
|
2
|
+
import {
|
3
|
+
createSingleton,
|
4
|
+
CreateSingletonProps,
|
5
|
+
Instance,
|
6
|
+
Props,
|
7
|
+
} from 'tippy.js'
|
8
|
+
import { onMounted, ref } from 'vue'
|
9
|
+
|
10
|
+
export function useSingleton(
|
11
|
+
instances: TippyInstances,
|
12
|
+
optionalProps?: Partial<CreateSingletonProps<Props>>
|
13
|
+
) {
|
14
|
+
const singleton = ref<ReturnType<typeof createSingleton>>()
|
15
|
+
|
16
|
+
onMounted(() => {
|
17
|
+
const pendingTippyInstances: TippyInstance[] = Array.isArray(instances)
|
18
|
+
? instances.map(i => i.value)
|
19
|
+
: typeof instances === 'function'
|
20
|
+
? instances()
|
21
|
+
: instances.value
|
22
|
+
|
23
|
+
const tippyInstances: Instance<any>[] = pendingTippyInstances
|
24
|
+
.map((instance: TippyInstance) => {
|
25
|
+
if (instance instanceof Element) {
|
26
|
+
//@ts-ignore
|
27
|
+
return instance._tippy
|
28
|
+
}
|
29
|
+
return instance
|
30
|
+
})
|
31
|
+
.filter(Boolean)
|
32
|
+
|
33
|
+
singleton.value = createSingleton(
|
34
|
+
tippyInstances,
|
35
|
+
optionalProps
|
36
|
+
? { allowHTML: true, ...optionalProps }
|
37
|
+
: { allowHTML: true }
|
38
|
+
)
|
39
|
+
})
|
40
|
+
|
41
|
+
return {
|
42
|
+
singleton,
|
43
|
+
}
|
44
|
+
}
|
@@ -0,0 +1,255 @@
|
|
1
|
+
import tippy, { Instance, Props, Content } from 'tippy.js'
|
2
|
+
import {
|
3
|
+
ref,
|
4
|
+
onMounted,
|
5
|
+
Ref,
|
6
|
+
isRef,
|
7
|
+
isReactive,
|
8
|
+
isVNode,
|
9
|
+
render,
|
10
|
+
watch,
|
11
|
+
VNode,
|
12
|
+
h,
|
13
|
+
onUnmounted,
|
14
|
+
getCurrentInstance,
|
15
|
+
} from 'vue'
|
16
|
+
import { TippyOptions, TippyContent } from '../types'
|
17
|
+
|
18
|
+
tippy.setDefaultProps({
|
19
|
+
//@ts-ignore
|
20
|
+
onShow: instance => {
|
21
|
+
if (!instance.props.content) return false
|
22
|
+
},
|
23
|
+
})
|
24
|
+
|
25
|
+
export function useTippy(
|
26
|
+
el: Element | (() => Element) | Ref<Element> | Ref<Element | undefined>,
|
27
|
+
opts: TippyOptions = {},
|
28
|
+
settings: {
|
29
|
+
mount: boolean
|
30
|
+
} = { mount: true }
|
31
|
+
) {
|
32
|
+
const vm = getCurrentInstance()
|
33
|
+
const instance = ref<Instance>()
|
34
|
+
const state = ref({
|
35
|
+
isEnabled: false,
|
36
|
+
isVisible: false,
|
37
|
+
isDestroyed: false,
|
38
|
+
isMounted: false,
|
39
|
+
isShown: false,
|
40
|
+
})
|
41
|
+
|
42
|
+
let container: any = null
|
43
|
+
|
44
|
+
const getContainer = () => {
|
45
|
+
if (container) return container
|
46
|
+
container = document.createDocumentFragment()
|
47
|
+
return container
|
48
|
+
}
|
49
|
+
|
50
|
+
const getContent = (content: TippyContent): Content => {
|
51
|
+
let newContent: Content
|
52
|
+
|
53
|
+
let unwrappedContent: Content | VNode | { render: Function } = isRef(
|
54
|
+
content
|
55
|
+
)
|
56
|
+
? content.value
|
57
|
+
: content
|
58
|
+
|
59
|
+
if (isVNode(unwrappedContent)) {
|
60
|
+
if (vm) {
|
61
|
+
unwrappedContent.appContext = vm.appContext
|
62
|
+
}
|
63
|
+
|
64
|
+
render(unwrappedContent, getContainer())
|
65
|
+
newContent = () => getContainer()
|
66
|
+
} else if (typeof unwrappedContent === 'object') {
|
67
|
+
let comp = h(unwrappedContent)
|
68
|
+
|
69
|
+
if (vm) {
|
70
|
+
comp.appContext = vm.appContext
|
71
|
+
}
|
72
|
+
|
73
|
+
render(comp, getContainer())
|
74
|
+
|
75
|
+
newContent = () => getContainer()
|
76
|
+
} else {
|
77
|
+
newContent = unwrappedContent
|
78
|
+
}
|
79
|
+
|
80
|
+
return newContent
|
81
|
+
}
|
82
|
+
|
83
|
+
const getProps = (opts: TippyOptions): Partial<Props> => {
|
84
|
+
let options: any = {}
|
85
|
+
|
86
|
+
if (isRef(opts)) {
|
87
|
+
options = opts.value || {}
|
88
|
+
} else if (isReactive(opts)) {
|
89
|
+
options = { ...opts }
|
90
|
+
} else {
|
91
|
+
options = { ...opts }
|
92
|
+
}
|
93
|
+
|
94
|
+
if (options.content) {
|
95
|
+
options.content = getContent(options.content)
|
96
|
+
}
|
97
|
+
|
98
|
+
if (options.triggerTarget) {
|
99
|
+
options.triggerTarget = isRef(options.triggerTarget)
|
100
|
+
? options.triggerTarget.value
|
101
|
+
: options.triggerTarget
|
102
|
+
}
|
103
|
+
|
104
|
+
if (!options.plugins || !Array.isArray(options.plugins)) {
|
105
|
+
options.plugins = []
|
106
|
+
}
|
107
|
+
|
108
|
+
options.plugins = options.plugins.filter((plugin: any) => plugin.name !== 'vueTippyReactiveState');
|
109
|
+
|
110
|
+
options.plugins.push({
|
111
|
+
name: 'vueTippyReactiveState',
|
112
|
+
fn: () => {
|
113
|
+
return {
|
114
|
+
onCreate() {
|
115
|
+
state.value.isEnabled = true
|
116
|
+
},
|
117
|
+
onMount() {
|
118
|
+
state.value.isMounted = true
|
119
|
+
},
|
120
|
+
onShow() {
|
121
|
+
state.value.isMounted = true
|
122
|
+
state.value.isVisible = true
|
123
|
+
},
|
124
|
+
onShown() {
|
125
|
+
state.value.isShown = true
|
126
|
+
},
|
127
|
+
onHide() {
|
128
|
+
state.value.isMounted = false
|
129
|
+
state.value.isVisible = false
|
130
|
+
},
|
131
|
+
onHidden() {
|
132
|
+
state.value.isShown = false
|
133
|
+
},
|
134
|
+
onUnmounted() {
|
135
|
+
state.value.isMounted = false
|
136
|
+
},
|
137
|
+
onDestroy() {
|
138
|
+
state.value.isDestroyed = true
|
139
|
+
},
|
140
|
+
}
|
141
|
+
}
|
142
|
+
})
|
143
|
+
|
144
|
+
return options as Props
|
145
|
+
}
|
146
|
+
|
147
|
+
const refresh = () => {
|
148
|
+
if (!instance.value) return
|
149
|
+
|
150
|
+
instance.value.setProps(getProps(opts))
|
151
|
+
}
|
152
|
+
|
153
|
+
const refreshContent = () => {
|
154
|
+
if (!instance.value || !opts.content) return
|
155
|
+
|
156
|
+
instance.value.setContent(getContent(opts.content))
|
157
|
+
}
|
158
|
+
|
159
|
+
const setContent = (value: TippyContent) => {
|
160
|
+
instance.value?.setContent(getContent(value))
|
161
|
+
}
|
162
|
+
|
163
|
+
const setProps = (value: TippyOptions) => {
|
164
|
+
instance.value?.setProps(getProps(value))
|
165
|
+
}
|
166
|
+
|
167
|
+
const destroy = () => {
|
168
|
+
if (instance.value) {
|
169
|
+
try {
|
170
|
+
//@ts-ignore
|
171
|
+
// delete instance.value.reference.$tippy
|
172
|
+
} catch (error) { }
|
173
|
+
|
174
|
+
instance.value.destroy()
|
175
|
+
instance.value = undefined
|
176
|
+
}
|
177
|
+
container = null
|
178
|
+
}
|
179
|
+
|
180
|
+
const show = () => {
|
181
|
+
instance.value?.show()
|
182
|
+
}
|
183
|
+
|
184
|
+
const hide = () => {
|
185
|
+
instance.value?.hide()
|
186
|
+
}
|
187
|
+
|
188
|
+
const disable = () => {
|
189
|
+
instance.value?.disable()
|
190
|
+
state.value.isEnabled = false;
|
191
|
+
}
|
192
|
+
|
193
|
+
const enable = () => {
|
194
|
+
instance.value?.enable()
|
195
|
+
state.value.isEnabled = true;
|
196
|
+
}
|
197
|
+
|
198
|
+
const unmount = () => {
|
199
|
+
instance.value?.unmount()
|
200
|
+
}
|
201
|
+
|
202
|
+
const mount = () => {
|
203
|
+
if (!el) return
|
204
|
+
|
205
|
+
let target = isRef(el) ? el.value : el
|
206
|
+
|
207
|
+
if (typeof target === 'function') target = target()
|
208
|
+
|
209
|
+
if (target) {
|
210
|
+
instance.value = tippy(target, getProps(opts))
|
211
|
+
//@ts-ignore
|
212
|
+
target.$tippy = response
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
const response = {
|
217
|
+
tippy: instance,
|
218
|
+
refresh,
|
219
|
+
refreshContent,
|
220
|
+
setContent,
|
221
|
+
setProps,
|
222
|
+
destroy,
|
223
|
+
hide,
|
224
|
+
show,
|
225
|
+
disable,
|
226
|
+
enable,
|
227
|
+
unmount,
|
228
|
+
mount,
|
229
|
+
state,
|
230
|
+
}
|
231
|
+
|
232
|
+
if (settings.mount) {
|
233
|
+
if (vm) {
|
234
|
+
if (vm.isMounted) {
|
235
|
+
mount()
|
236
|
+
} else {
|
237
|
+
onMounted(mount)
|
238
|
+
}
|
239
|
+
|
240
|
+
onUnmounted(() => {
|
241
|
+
destroy()
|
242
|
+
})
|
243
|
+
} else {
|
244
|
+
mount()
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
if (isRef(opts) || isReactive(opts)) {
|
249
|
+
watch(opts, refresh, { immediate: false })
|
250
|
+
} else if (isRef(opts.content)) {
|
251
|
+
watch(opts.content, refreshContent, { immediate: false })
|
252
|
+
}
|
253
|
+
|
254
|
+
return response
|
255
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { h, ref } from 'vue'
|
2
|
+
import { TippyOptions } from '../types'
|
3
|
+
import TippyComponent from './../components/Tippy'
|
4
|
+
|
5
|
+
export function useTippyComponent(
|
6
|
+
opts: TippyOptions = {},
|
7
|
+
children?: any
|
8
|
+
) {
|
9
|
+
const instance = ref()
|
10
|
+
|
11
|
+
return {
|
12
|
+
instance,
|
13
|
+
TippyComponent: h(
|
14
|
+
TippyComponent,
|
15
|
+
{
|
16
|
+
...opts,
|
17
|
+
onVnodeMounted: vnode => {
|
18
|
+
//@ts-ignore
|
19
|
+
instance.value = vnode.component.ctx
|
20
|
+
},
|
21
|
+
},
|
22
|
+
children
|
23
|
+
),
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import { useTippy } from '../composables'
|
2
|
+
import { Directive } from 'vue'
|
3
|
+
|
4
|
+
const directive: Directive = {
|
5
|
+
mounted(el, binding, vnode) {
|
6
|
+
const opts = typeof binding.value === "string" ? { content: binding.value } : binding.value || {}
|
7
|
+
|
8
|
+
const modifiers = Object.keys(binding.modifiers || {})
|
9
|
+
const placement = modifiers.find(modifier => modifier !== 'arrow')
|
10
|
+
const withArrow = modifiers.findIndex(modifier => modifier === 'arrow') !== -1
|
11
|
+
|
12
|
+
if (placement) {
|
13
|
+
opts.placement = opts.placement || placement
|
14
|
+
}
|
15
|
+
|
16
|
+
if (withArrow) {
|
17
|
+
opts.arrow = opts.arrow !== undefined ? opts.arrow : true
|
18
|
+
}
|
19
|
+
|
20
|
+
if (vnode.props && vnode.props.onTippyShow) {
|
21
|
+
opts.onShow = function (...args: any[]) {
|
22
|
+
return vnode.props?.onTippyShow(...args)
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
if (vnode.props && vnode.props.onTippyShown) {
|
27
|
+
opts.onShown = function (...args: any[]) {
|
28
|
+
return vnode.props?.onTippyShown(...args)
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
if (vnode.props && vnode.props.onTippyHidden) {
|
33
|
+
opts.onHidden = function (...args: any[]) {
|
34
|
+
return vnode.props?.onTippyHidden(...args)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
if (vnode.props && vnode.props.onTippyHide) {
|
39
|
+
opts.onHide = function (...args: any[]) {
|
40
|
+
return vnode.props?.onTippyHide(...args)
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
if (vnode.props && vnode.props.onTippyMount) {
|
45
|
+
opts.onMount = function (...args: any[]) {
|
46
|
+
return vnode.props?.onTippyMount(...args)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
if (el.getAttribute('title') && !opts.content) {
|
51
|
+
opts.content = el.getAttribute('title')
|
52
|
+
el.removeAttribute('title')
|
53
|
+
}
|
54
|
+
|
55
|
+
if (el.getAttribute('content') && !opts.content) {
|
56
|
+
opts.content = el.getAttribute('content')
|
57
|
+
}
|
58
|
+
|
59
|
+
useTippy(el, opts)
|
60
|
+
},
|
61
|
+
unmounted(el) {
|
62
|
+
if (el.$tippy) {
|
63
|
+
el.$tippy.destroy()
|
64
|
+
} else if (el._tippy) {
|
65
|
+
el._tippy.destroy()
|
66
|
+
}
|
67
|
+
},
|
68
|
+
|
69
|
+
updated(el, binding) {
|
70
|
+
const opts = typeof binding.value === "string" ? { content: binding.value } : binding.value || {}
|
71
|
+
|
72
|
+
if (el.getAttribute('title') && !opts.content) {
|
73
|
+
opts.content = el.getAttribute('title')
|
74
|
+
el.removeAttribute('title')
|
75
|
+
}
|
76
|
+
|
77
|
+
if (el.getAttribute('content') && !opts.content) {
|
78
|
+
opts.content = el.getAttribute('content')
|
79
|
+
}
|
80
|
+
|
81
|
+
if (el.$tippy) {
|
82
|
+
el.$tippy.setProps(opts || {})
|
83
|
+
} else if (el._tippy) {
|
84
|
+
el._tippy.setProps(opts || {})
|
85
|
+
}
|
86
|
+
},
|
87
|
+
}
|
88
|
+
|
89
|
+
export default directive
|
package/src/global.d.ts
ADDED
package/src/index.ts
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
import tippy, {
|
2
|
+
sticky,
|
3
|
+
inlinePositioning,
|
4
|
+
followCursor,
|
5
|
+
animateFill,
|
6
|
+
roundArrow,
|
7
|
+
} from 'tippy.js'
|
8
|
+
|
9
|
+
import Tippy from './components/Tippy'
|
10
|
+
import TippySingleton from './components/TippySingleton'
|
11
|
+
import directive from './directive'
|
12
|
+
import plugin from './plugin'
|
13
|
+
|
14
|
+
import { useTippy } from './composables/useTippy'
|
15
|
+
import { useTippyComponent } from './composables/useTippyComponent'
|
16
|
+
import { useSingleton } from './composables/useSingleton'
|
17
|
+
|
18
|
+
const setDefaultProps = tippy.setDefaultProps
|
19
|
+
|
20
|
+
setDefaultProps({
|
21
|
+
ignoreAttributes: true,
|
22
|
+
plugins: [sticky, inlinePositioning, followCursor, animateFill],
|
23
|
+
})
|
24
|
+
|
25
|
+
export {
|
26
|
+
useTippy,
|
27
|
+
useTippyComponent,
|
28
|
+
roundArrow,
|
29
|
+
tippy,
|
30
|
+
useSingleton,
|
31
|
+
setDefaultProps,
|
32
|
+
Tippy,
|
33
|
+
TippySingleton,
|
34
|
+
directive,
|
35
|
+
plugin,
|
36
|
+
}
|
37
|
+
|
38
|
+
export * from './types'
|
39
|
+
export default plugin
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import TippyComponent from '../components/Tippy'
|
2
|
+
import TippySingletonComponent from '../components/TippySingleton'
|
3
|
+
import directive from '../directive'
|
4
|
+
import { Plugin } from 'vue'
|
5
|
+
import tippy from 'tippy.js'
|
6
|
+
import { TippyPluginOptions } from '../types'
|
7
|
+
|
8
|
+
const plugin: Plugin = {
|
9
|
+
install(app, options: TippyPluginOptions = {}) {
|
10
|
+
tippy.setDefaultProps(options.defaultProps || {})
|
11
|
+
|
12
|
+
app.directive(options.directive || 'tippy', directive)
|
13
|
+
app.component(options.component || 'tippy', TippyComponent)
|
14
|
+
app.component(options.componentSingleton || 'tippy-singleton', TippySingletonComponent)
|
15
|
+
},
|
16
|
+
}
|
17
|
+
|
18
|
+
export default plugin
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import Tippy from '../components/Tippy'
|
2
|
+
import { Props, Content, DefaultProps, Instance } from 'tippy.js'
|
3
|
+
import { VNode, Ref, Component } from 'vue'
|
4
|
+
|
5
|
+
export declare type TippyContent = Content | VNode | Component | Ref
|
6
|
+
export declare type TippyTarget =
|
7
|
+
| Element
|
8
|
+
| Element[]
|
9
|
+
| Ref<Element | undefined>
|
10
|
+
| Ref<Element[] | undefined>
|
11
|
+
| null
|
12
|
+
|
13
|
+
export declare type TippyOptions = Partial<
|
14
|
+
Omit<Props, 'content' | 'triggerTarget'> & {
|
15
|
+
content: TippyContent
|
16
|
+
triggerTarget: TippyTarget
|
17
|
+
}
|
18
|
+
>
|
19
|
+
|
20
|
+
export declare type TippyComponent = InstanceType<typeof Tippy>
|
21
|
+
|
22
|
+
export interface TippyPluginOptions {
|
23
|
+
directive?: string
|
24
|
+
component?: string
|
25
|
+
componentSingleton?: string
|
26
|
+
defaultProps?: Partial<DefaultProps>
|
27
|
+
}
|
28
|
+
|
29
|
+
export type TippyInstance = Instance | Element | undefined
|
30
|
+
export type TippyInstances = Ref<TippyInstance>[] | Ref<TippyInstance[]> | (() => TippyInstance[])
|
package/tsconfig.json
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"include": ["src/**/*"],
|
3
|
+
"compilerOptions": {
|
4
|
+
"baseUrl": ".",
|
5
|
+
"rootDir": ".",
|
6
|
+
"outDir": "dist",
|
7
|
+
"sourceMap": false,
|
8
|
+
"noEmit": true,
|
9
|
+
|
10
|
+
"target": "es2019",
|
11
|
+
"module": "esnext",
|
12
|
+
"moduleResolution": "node",
|
13
|
+
"allowJs": false,
|
14
|
+
|
15
|
+
"noUnusedLocals": true,
|
16
|
+
"strictNullChecks": true,
|
17
|
+
"noImplicitAny": true,
|
18
|
+
"noImplicitThis": true,
|
19
|
+
"noImplicitReturns": true,
|
20
|
+
"strict": true,
|
21
|
+
"isolatedModules": false,
|
22
|
+
|
23
|
+
"experimentalDecorators": true,
|
24
|
+
"resolveJsonModule": true,
|
25
|
+
"esModuleInterop": true,
|
26
|
+
"removeComments": false,
|
27
|
+
"jsx": "preserve",
|
28
|
+
"lib": ["esnext", "dom"],
|
29
|
+
"types": ["node"]
|
30
|
+
}
|
31
|
+
}
|