@destyler/tooltip 0.0.1-beta.8 → 0.0.1
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/LICENSE +21 -0
- package/dist/component.cjs +672 -0
- package/dist/component.d.cts +390 -0
- package/dist/component.d.mts +390 -0
- package/dist/component.d.ts +390 -0
- package/dist/component.mjs +663 -0
- package/dist/index.cjs +19 -670
- package/dist/index.d.cts +5 -999
- package/dist/index.d.mts +5 -999
- package/dist/index.d.ts +5 -999
- package/dist/index.mjs +10 -642
- package/dist/resolver.cjs +25 -0
- package/dist/resolver.d.cts +6 -0
- package/dist/resolver.d.mts +6 -0
- package/dist/resolver.d.ts +6 -0
- package/dist/resolver.mjs +22 -0
- package/dist/shared/tooltip.79d8523b.d.cts +600 -0
- package/dist/shared/tooltip.79d8523b.d.mts +600 -0
- package/dist/shared/tooltip.79d8523b.d.ts +600 -0
- package/package.json +18 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-PRESENT Elone Hoo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const popper = require('@destyler/popper');
|
|
5
|
+
const composition = require('@destyler/composition');
|
|
6
|
+
const shared = require('@destyler/shared');
|
|
7
|
+
const core = require('@vueuse/core');
|
|
8
|
+
const dismissableLayer = require('@destyler/dismissable-layer');
|
|
9
|
+
const visuallyHidden = require('@destyler/visually-hidden');
|
|
10
|
+
const teleport = require('@destyler/teleport');
|
|
11
|
+
const primitive = require('@destyler/primitive');
|
|
12
|
+
|
|
13
|
+
const destylerTooltipArrowProps = {
|
|
14
|
+
as: {
|
|
15
|
+
type: [String, Object],
|
|
16
|
+
required: false,
|
|
17
|
+
default: "div"
|
|
18
|
+
},
|
|
19
|
+
asChild: {
|
|
20
|
+
type: Boolean,
|
|
21
|
+
required: false,
|
|
22
|
+
default: false
|
|
23
|
+
},
|
|
24
|
+
width: {
|
|
25
|
+
type: Number,
|
|
26
|
+
required: false,
|
|
27
|
+
default: 10
|
|
28
|
+
},
|
|
29
|
+
height: {
|
|
30
|
+
type: Number,
|
|
31
|
+
required: false,
|
|
32
|
+
default: 5
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const DestylerTooltipArrow = vue.defineComponent({
|
|
36
|
+
name: "DestylerTooltipArrow",
|
|
37
|
+
props: destylerTooltipArrowProps,
|
|
38
|
+
render() {
|
|
39
|
+
return vue.h(popper.DestylerPopperArrow, vue.mergeProps(this.$props), {
|
|
40
|
+
default: () => this.$slots.default?.()
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const TOOLTIP_OPEN = "tooltip.open";
|
|
46
|
+
function getExitSideFromRect(point, rect) {
|
|
47
|
+
const top = Math.abs(rect.top - point.y);
|
|
48
|
+
const bottom = Math.abs(rect.bottom - point.y);
|
|
49
|
+
const right = Math.abs(rect.right - point.x);
|
|
50
|
+
const left = Math.abs(rect.left - point.x);
|
|
51
|
+
switch (Math.min(top, bottom, right, left)) {
|
|
52
|
+
case left:
|
|
53
|
+
return "left";
|
|
54
|
+
case right:
|
|
55
|
+
return "right";
|
|
56
|
+
case top:
|
|
57
|
+
return "top";
|
|
58
|
+
case bottom:
|
|
59
|
+
return "bottom";
|
|
60
|
+
default:
|
|
61
|
+
throw new Error("unreachable");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function getPaddedExitPoints(exitPoint, exitSide, padding = 5) {
|
|
65
|
+
const paddedExitPoints = [];
|
|
66
|
+
switch (exitSide) {
|
|
67
|
+
case "top":
|
|
68
|
+
paddedExitPoints.push(
|
|
69
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding },
|
|
70
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
|
71
|
+
);
|
|
72
|
+
break;
|
|
73
|
+
case "bottom":
|
|
74
|
+
paddedExitPoints.push(
|
|
75
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
|
76
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding }
|
|
77
|
+
);
|
|
78
|
+
break;
|
|
79
|
+
case "left":
|
|
80
|
+
paddedExitPoints.push(
|
|
81
|
+
{ x: exitPoint.x + padding, y: exitPoint.y - padding },
|
|
82
|
+
{ x: exitPoint.x + padding, y: exitPoint.y + padding }
|
|
83
|
+
);
|
|
84
|
+
break;
|
|
85
|
+
case "right":
|
|
86
|
+
paddedExitPoints.push(
|
|
87
|
+
{ x: exitPoint.x - padding, y: exitPoint.y - padding },
|
|
88
|
+
{ x: exitPoint.x - padding, y: exitPoint.y + padding }
|
|
89
|
+
);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
return paddedExitPoints;
|
|
93
|
+
}
|
|
94
|
+
function getPointsFromRect(rect) {
|
|
95
|
+
const { top, right, bottom, left } = rect;
|
|
96
|
+
return [
|
|
97
|
+
{ x: left, y: top },
|
|
98
|
+
{ x: right, y: top },
|
|
99
|
+
{ x: right, y: bottom },
|
|
100
|
+
{ x: left, y: bottom }
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
function getHull(points) {
|
|
104
|
+
const newPoints = points.slice();
|
|
105
|
+
newPoints.sort((a, b) => {
|
|
106
|
+
if (a.x < b.x)
|
|
107
|
+
return -1;
|
|
108
|
+
else if (a.x > b.x)
|
|
109
|
+
return 1;
|
|
110
|
+
else if (a.y < b.y)
|
|
111
|
+
return -1;
|
|
112
|
+
else if (a.y > b.y)
|
|
113
|
+
return 1;
|
|
114
|
+
else
|
|
115
|
+
return 0;
|
|
116
|
+
});
|
|
117
|
+
return getHullPresorted(newPoints);
|
|
118
|
+
}
|
|
119
|
+
function getHullPresorted(points) {
|
|
120
|
+
if (points.length <= 1)
|
|
121
|
+
return points.slice();
|
|
122
|
+
const upperHull = [];
|
|
123
|
+
for (let i = 0; i < points.length; i++) {
|
|
124
|
+
const p = points[i];
|
|
125
|
+
while (upperHull.length >= 2) {
|
|
126
|
+
const q = upperHull[upperHull.length - 1];
|
|
127
|
+
const r = upperHull[upperHull.length - 2];
|
|
128
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
|
129
|
+
upperHull.pop();
|
|
130
|
+
else
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
upperHull.push(p);
|
|
134
|
+
}
|
|
135
|
+
upperHull.pop();
|
|
136
|
+
const lowerHull = [];
|
|
137
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
|
138
|
+
const p = points[i];
|
|
139
|
+
while (lowerHull.length >= 2) {
|
|
140
|
+
const q = lowerHull[lowerHull.length - 1];
|
|
141
|
+
const r = lowerHull[lowerHull.length - 2];
|
|
142
|
+
if ((q.x - r.x) * (p.y - r.y) >= (q.y - r.y) * (p.x - r.x))
|
|
143
|
+
lowerHull.pop();
|
|
144
|
+
else
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
lowerHull.push(p);
|
|
148
|
+
}
|
|
149
|
+
lowerHull.pop();
|
|
150
|
+
if (upperHull.length === 1 && lowerHull.length === 1 && upperHull[0].x === lowerHull[0].x && upperHull[0].y === lowerHull[0].y)
|
|
151
|
+
return upperHull;
|
|
152
|
+
else
|
|
153
|
+
return upperHull.concat(lowerHull);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const destylerTooltipProviderProps = {
|
|
157
|
+
delayDuration: {
|
|
158
|
+
type: Number,
|
|
159
|
+
required: false,
|
|
160
|
+
default: 700
|
|
161
|
+
},
|
|
162
|
+
skipDelayDuration: {
|
|
163
|
+
type: Number,
|
|
164
|
+
required: false,
|
|
165
|
+
default: 300
|
|
166
|
+
},
|
|
167
|
+
disableHoverableContent: {
|
|
168
|
+
type: Boolean,
|
|
169
|
+
required: false,
|
|
170
|
+
default: false
|
|
171
|
+
},
|
|
172
|
+
disableClosingTrigger: {
|
|
173
|
+
type: Boolean,
|
|
174
|
+
required: false,
|
|
175
|
+
default: false
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const [injectTooltipProviderContext, provideTooltipProviderContext] = shared.createContext("DestylerTooltipProvider");
|
|
179
|
+
const DestylerTooltipProvider = vue.defineComponent({
|
|
180
|
+
name: "DestylerTooltipProvider",
|
|
181
|
+
props: destylerTooltipProviderProps,
|
|
182
|
+
setup(props) {
|
|
183
|
+
const { delayDuration, skipDelayDuration, disableHoverableContent, disableClosingTrigger } = vue.toRefs(props);
|
|
184
|
+
const isOpenDelayed = vue.ref(true);
|
|
185
|
+
const isPointerInTransitRef = vue.ref(false);
|
|
186
|
+
const { start: startTimer, stop: clearTimer } = composition.useTimeoutFn(() => {
|
|
187
|
+
isOpenDelayed.value = true;
|
|
188
|
+
}, skipDelayDuration, { immediate: false });
|
|
189
|
+
provideTooltipProviderContext({
|
|
190
|
+
isOpenDelayed,
|
|
191
|
+
delayDuration,
|
|
192
|
+
onOpen() {
|
|
193
|
+
clearTimer();
|
|
194
|
+
isOpenDelayed.value = false;
|
|
195
|
+
},
|
|
196
|
+
onClose() {
|
|
197
|
+
startTimer();
|
|
198
|
+
},
|
|
199
|
+
isPointerInTransitRef,
|
|
200
|
+
onPointerInTransitChange(inTransit) {
|
|
201
|
+
isPointerInTransitRef.value = inTransit;
|
|
202
|
+
},
|
|
203
|
+
disableHoverableContent,
|
|
204
|
+
disableClosingTrigger
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
render() {
|
|
208
|
+
return this.$slots.default?.();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const destylerTooltipRootProps = {
|
|
213
|
+
defaultOpen: {
|
|
214
|
+
type: Boolean,
|
|
215
|
+
required: false,
|
|
216
|
+
default: false
|
|
217
|
+
},
|
|
218
|
+
open: {
|
|
219
|
+
type: Boolean,
|
|
220
|
+
required: false,
|
|
221
|
+
default: void 0
|
|
222
|
+
},
|
|
223
|
+
delayDuration: {
|
|
224
|
+
type: Number,
|
|
225
|
+
required: false,
|
|
226
|
+
default: 400
|
|
227
|
+
},
|
|
228
|
+
disableHoverableContent: {
|
|
229
|
+
type: Boolean,
|
|
230
|
+
required: false,
|
|
231
|
+
default: void 0
|
|
232
|
+
},
|
|
233
|
+
disableClosingTrigger: {
|
|
234
|
+
type: Boolean,
|
|
235
|
+
required: false,
|
|
236
|
+
default: void 0
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const [injectTooltipRootContext, provideTooltipRootContext] = shared.createContext("DestylerTooltipRoot");
|
|
240
|
+
const DestylerTooltipRoot = vue.defineComponent({
|
|
241
|
+
name: "DestylerTooltipRoot",
|
|
242
|
+
props: destylerTooltipRootProps,
|
|
243
|
+
emits: ["update:open"],
|
|
244
|
+
setup(props, { emit }) {
|
|
245
|
+
const providerContext = injectTooltipProviderContext();
|
|
246
|
+
const disableHoverableContent = vue.computed(() => {
|
|
247
|
+
return props.disableHoverableContent ?? providerContext.disableHoverableContent.value;
|
|
248
|
+
});
|
|
249
|
+
const disableClosingTrigger = vue.computed(() => props.disableClosingTrigger ?? providerContext.disableClosingTrigger.value);
|
|
250
|
+
const delayDuration = vue.computed(() => props.delayDuration ?? providerContext.delayDuration.value);
|
|
251
|
+
const openRef = composition.useVModel(props, "open", emit, {
|
|
252
|
+
defaultValue: props.defaultOpen,
|
|
253
|
+
passive: props.open === void 0
|
|
254
|
+
});
|
|
255
|
+
vue.watch(openRef, (isOpen) => {
|
|
256
|
+
if (!providerContext.onClose)
|
|
257
|
+
return;
|
|
258
|
+
if (isOpen) {
|
|
259
|
+
providerContext.onOpen();
|
|
260
|
+
document.dispatchEvent(new CustomEvent(TOOLTIP_OPEN));
|
|
261
|
+
} else {
|
|
262
|
+
providerContext.onClose();
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
const wasOpenDelayedRef = vue.ref(false);
|
|
266
|
+
const trigger = vue.ref();
|
|
267
|
+
const stateAttribute = vue.computed(() => {
|
|
268
|
+
if (!openRef.value)
|
|
269
|
+
return "closed";
|
|
270
|
+
return wasOpenDelayedRef.value ? "delayed-open" : "instant-open";
|
|
271
|
+
});
|
|
272
|
+
const { start: startTimer, stop: clearTimer } = composition.useTimeoutFn(() => {
|
|
273
|
+
wasOpenDelayedRef.value = true;
|
|
274
|
+
openRef.value = true;
|
|
275
|
+
}, delayDuration, { immediate: false });
|
|
276
|
+
function handleOpen() {
|
|
277
|
+
clearTimer();
|
|
278
|
+
wasOpenDelayedRef.value = false;
|
|
279
|
+
openRef.value = true;
|
|
280
|
+
}
|
|
281
|
+
function handleClose() {
|
|
282
|
+
clearTimer();
|
|
283
|
+
openRef.value = false;
|
|
284
|
+
}
|
|
285
|
+
function handleDelayedOpen() {
|
|
286
|
+
startTimer();
|
|
287
|
+
}
|
|
288
|
+
provideTooltipRootContext({
|
|
289
|
+
contentId: composition.useId(),
|
|
290
|
+
open: openRef,
|
|
291
|
+
stateAttribute,
|
|
292
|
+
trigger,
|
|
293
|
+
onTriggerChange(el) {
|
|
294
|
+
trigger.value = el;
|
|
295
|
+
},
|
|
296
|
+
onTriggerEnter() {
|
|
297
|
+
if (providerContext.isOpenDelayed.value)
|
|
298
|
+
handleDelayedOpen();
|
|
299
|
+
else
|
|
300
|
+
handleOpen();
|
|
301
|
+
},
|
|
302
|
+
onTriggerLeave() {
|
|
303
|
+
if (disableHoverableContent.value)
|
|
304
|
+
handleClose();
|
|
305
|
+
else
|
|
306
|
+
clearTimer();
|
|
307
|
+
},
|
|
308
|
+
onOpen: handleOpen,
|
|
309
|
+
onClose: handleClose,
|
|
310
|
+
disableHoverableContent,
|
|
311
|
+
disableClosingTrigger
|
|
312
|
+
});
|
|
313
|
+
},
|
|
314
|
+
render() {
|
|
315
|
+
return vue.h(popper.DestylerPopperRoot, null, {
|
|
316
|
+
default: () => this.$slots.default?.()
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
const destylerTooltipContentImplProps = {
|
|
322
|
+
as: {
|
|
323
|
+
type: [String, Object],
|
|
324
|
+
required: false,
|
|
325
|
+
default: "div"
|
|
326
|
+
},
|
|
327
|
+
asChild: {
|
|
328
|
+
type: Boolean,
|
|
329
|
+
required: false,
|
|
330
|
+
default: false
|
|
331
|
+
},
|
|
332
|
+
side: {
|
|
333
|
+
type: String,
|
|
334
|
+
required: false,
|
|
335
|
+
default: "top"
|
|
336
|
+
},
|
|
337
|
+
sideOffset: {
|
|
338
|
+
type: Number,
|
|
339
|
+
required: false,
|
|
340
|
+
default: 0
|
|
341
|
+
},
|
|
342
|
+
align: {
|
|
343
|
+
type: String,
|
|
344
|
+
required: false,
|
|
345
|
+
default: "center"
|
|
346
|
+
},
|
|
347
|
+
alignOffset: {
|
|
348
|
+
type: Number,
|
|
349
|
+
required: false,
|
|
350
|
+
default: 0
|
|
351
|
+
},
|
|
352
|
+
avoidCollisions: {
|
|
353
|
+
type: Boolean,
|
|
354
|
+
required: false,
|
|
355
|
+
default: true
|
|
356
|
+
},
|
|
357
|
+
collisionBoundary: {
|
|
358
|
+
type: [Object, Array, null],
|
|
359
|
+
required: false,
|
|
360
|
+
default: () => []
|
|
361
|
+
},
|
|
362
|
+
collisionPadding: {
|
|
363
|
+
type: [Number, Object],
|
|
364
|
+
required: false,
|
|
365
|
+
default: 0
|
|
366
|
+
},
|
|
367
|
+
arrowPadding: {
|
|
368
|
+
type: Number,
|
|
369
|
+
required: false,
|
|
370
|
+
default: 0
|
|
371
|
+
},
|
|
372
|
+
sticky: {
|
|
373
|
+
type: String,
|
|
374
|
+
required: false,
|
|
375
|
+
default: "partial"
|
|
376
|
+
},
|
|
377
|
+
hideWhenDetached: {
|
|
378
|
+
type: Boolean,
|
|
379
|
+
required: false,
|
|
380
|
+
default: false
|
|
381
|
+
},
|
|
382
|
+
ariaLabel: {
|
|
383
|
+
type: String,
|
|
384
|
+
required: false
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const destylerTooltipContentImplEmits = ["escapeKeyDown", "pointerDownOutside"];
|
|
388
|
+
const DestylerTooltipContentImpl = vue.defineComponent({
|
|
389
|
+
name: "DestylerTooltipContentImpl",
|
|
390
|
+
props: destylerTooltipContentImplProps,
|
|
391
|
+
emits: destylerTooltipContentImplEmits,
|
|
392
|
+
setup(props) {
|
|
393
|
+
const contentElement = vue.ref();
|
|
394
|
+
const rootContext = injectTooltipRootContext();
|
|
395
|
+
const slot = vue.useSlots();
|
|
396
|
+
const defaultSlot = vue.computed(() => slot.default?.());
|
|
397
|
+
const ariaLabel = vue.computed(() => {
|
|
398
|
+
if (props.ariaLabel)
|
|
399
|
+
return props.ariaLabel;
|
|
400
|
+
let content = "";
|
|
401
|
+
function recursiveTextSearch(node) {
|
|
402
|
+
if (typeof node.children === "string")
|
|
403
|
+
content += node.children;
|
|
404
|
+
else if (Array.isArray(node.children))
|
|
405
|
+
node.children.forEach((child) => recursiveTextSearch(child));
|
|
406
|
+
}
|
|
407
|
+
defaultSlot.value?.forEach((node) => recursiveTextSearch(node));
|
|
408
|
+
return content;
|
|
409
|
+
});
|
|
410
|
+
const popperContentProps = vue.computed(() => {
|
|
411
|
+
const { ariaLabel: _, ...restProps } = props;
|
|
412
|
+
return restProps;
|
|
413
|
+
});
|
|
414
|
+
vue.onMounted(() => {
|
|
415
|
+
core.useEventListener(window, "scroll", (event) => {
|
|
416
|
+
const target = event.target;
|
|
417
|
+
if (target?.contains(rootContext.trigger.value))
|
|
418
|
+
rootContext.onClose();
|
|
419
|
+
});
|
|
420
|
+
core.useEventListener(window, TOOLTIP_OPEN, rootContext.onClose);
|
|
421
|
+
});
|
|
422
|
+
return {
|
|
423
|
+
contentElement,
|
|
424
|
+
rootContext,
|
|
425
|
+
popperContentProps,
|
|
426
|
+
ariaLabel
|
|
427
|
+
};
|
|
428
|
+
},
|
|
429
|
+
render() {
|
|
430
|
+
return vue.h(dismissableLayer.DestylerDismissableLayer, {
|
|
431
|
+
asChild: true,
|
|
432
|
+
disableOutsidePointerEvents: false,
|
|
433
|
+
onEscapeKeyDown: (event) => {
|
|
434
|
+
this.$emit("escapeKeyDown", event);
|
|
435
|
+
},
|
|
436
|
+
onPointerDownOutside: (event) => {
|
|
437
|
+
if (this.rootContext.disableClosingTrigger.value && this.rootContext.trigger.value?.contains(event.target))
|
|
438
|
+
event.preventDefault();
|
|
439
|
+
this.$emit("pointerDownOutside", event);
|
|
440
|
+
},
|
|
441
|
+
onDismiss: () => {
|
|
442
|
+
this.rootContext.onClose();
|
|
443
|
+
}
|
|
444
|
+
}, vue.h(popper.DestylerPopperContent, vue.mergeProps(this.$attrs, this.popperContentProps, {
|
|
445
|
+
"ref": "contentElement",
|
|
446
|
+
"data-state": this.rootContext.stateAttribute.value,
|
|
447
|
+
"style": {
|
|
448
|
+
"--destyler_tooltip_content_transform_origin": "var(--destyler_popper_transform_origin)",
|
|
449
|
+
"--destyler_tooltip_content_available_width": "var(--destyler_popper_available_width)",
|
|
450
|
+
"--destyler_tooltip_content_available_height": "var(--destyler_popper_available_height)",
|
|
451
|
+
"--destyler_tooltip_trigger_width": "var(--destyler_popper_anchor_width)",
|
|
452
|
+
"--destyler_tooltip_trigger_height": "var(--destyler_popper_anchor_height)"
|
|
453
|
+
}
|
|
454
|
+
}), [
|
|
455
|
+
this.$slots.default?.(),
|
|
456
|
+
vue.h(visuallyHidden.DestylerVisuallyhidden, {
|
|
457
|
+
role: "tooltip"
|
|
458
|
+
}, this.ariaLabel)
|
|
459
|
+
]));
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
const DestylerTooltipContentHoverable = vue.defineComponent({
|
|
464
|
+
name: "DestylerTooltipContentHoverable",
|
|
465
|
+
props: destylerTooltipContentImplProps,
|
|
466
|
+
setup() {
|
|
467
|
+
const { forwardRef, currentElement } = composition.useForwardExpose();
|
|
468
|
+
const { trigger, onClose } = injectTooltipRootContext();
|
|
469
|
+
const providerContext = injectTooltipProviderContext();
|
|
470
|
+
const pointerGraceArea = vue.ref(null);
|
|
471
|
+
function handleRemoveGraceArea() {
|
|
472
|
+
pointerGraceArea.value = null;
|
|
473
|
+
providerContext.onPointerInTransitChange(false);
|
|
474
|
+
}
|
|
475
|
+
function handleCreateGraceArea(event, hoverTarget) {
|
|
476
|
+
const currentTarget = event.currentTarget;
|
|
477
|
+
const exitPoint = { x: event.clientX, y: event.clientY };
|
|
478
|
+
const exitSide = getExitSideFromRect(exitPoint, currentTarget.getBoundingClientRect());
|
|
479
|
+
const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
|
|
480
|
+
const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
|
|
481
|
+
const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
|
|
482
|
+
pointerGraceArea.value = graceArea;
|
|
483
|
+
providerContext.onPointerInTransitChange(true);
|
|
484
|
+
}
|
|
485
|
+
vue.watchEffect((cleanupFn) => {
|
|
486
|
+
if (trigger.value && currentElement.value) {
|
|
487
|
+
const handleTriggerLeave = (event) => handleCreateGraceArea(event, currentElement.value);
|
|
488
|
+
const handleContentLeave = (event) => handleCreateGraceArea(event, trigger.value);
|
|
489
|
+
trigger.value.addEventListener("pointerleave", handleTriggerLeave);
|
|
490
|
+
currentElement.value.addEventListener("pointerleave", handleContentLeave);
|
|
491
|
+
cleanupFn(() => {
|
|
492
|
+
trigger.value?.removeEventListener("pointerleave", handleTriggerLeave);
|
|
493
|
+
currentElement.value?.removeEventListener("pointerleave", handleContentLeave);
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
vue.watchEffect((cleanupFn) => {
|
|
498
|
+
if (pointerGraceArea.value) {
|
|
499
|
+
const handleTrackPointerGrace = (event) => {
|
|
500
|
+
if (!pointerGraceArea.value)
|
|
501
|
+
return;
|
|
502
|
+
const target = event.target;
|
|
503
|
+
const pointerPosition = { x: event.clientX, y: event.clientY };
|
|
504
|
+
const hasEnteredTarget = trigger.value?.contains(target) || currentElement.value?.contains(target);
|
|
505
|
+
const isPointerOutsideGraceArea = !shared.isPointInPolygon(pointerPosition, pointerGraceArea.value);
|
|
506
|
+
if (hasEnteredTarget) {
|
|
507
|
+
handleRemoveGraceArea();
|
|
508
|
+
} else if (isPointerOutsideGraceArea) {
|
|
509
|
+
handleRemoveGraceArea();
|
|
510
|
+
onClose();
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
document.addEventListener("pointermove", handleTrackPointerGrace);
|
|
514
|
+
cleanupFn(() => document.removeEventListener("pointermove", handleTrackPointerGrace));
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
return {
|
|
518
|
+
forwardRef
|
|
519
|
+
};
|
|
520
|
+
},
|
|
521
|
+
render() {
|
|
522
|
+
return vue.h(DestylerTooltipContentImpl, {
|
|
523
|
+
ref: (el) => this.forwardRef(el),
|
|
524
|
+
...vue.mergeProps(this.$props)
|
|
525
|
+
}, {
|
|
526
|
+
default: () => this.$slots.default?.()
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
const destylerTooltipContentProps = {
|
|
532
|
+
...destylerTooltipContentImplProps
|
|
533
|
+
};
|
|
534
|
+
const destylerTooltipContentEmits = [...destylerTooltipContentImplEmits];
|
|
535
|
+
const DestylerTooltipContent = vue.defineComponent({
|
|
536
|
+
name: "DestylerTooltipContent",
|
|
537
|
+
props: destylerTooltipContentProps,
|
|
538
|
+
emits: destylerTooltipContentEmits,
|
|
539
|
+
setup(props, { emit }) {
|
|
540
|
+
const rootContext = injectTooltipRootContext();
|
|
541
|
+
const forwarded = composition.useForwardPropsEmits(props, emit);
|
|
542
|
+
return {
|
|
543
|
+
rootContext,
|
|
544
|
+
forwarded
|
|
545
|
+
};
|
|
546
|
+
},
|
|
547
|
+
render() {
|
|
548
|
+
const useVShow = this.rootContext.open.value;
|
|
549
|
+
return useVShow ? vue.h(this.rootContext.disableHoverableContent.value ? DestylerTooltipContentImpl : DestylerTooltipContentHoverable, {
|
|
550
|
+
...this.forwarded
|
|
551
|
+
}, {
|
|
552
|
+
default: () => this.$slots.default?.()
|
|
553
|
+
}) : null;
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
const destylerTooltipPortalProps = {
|
|
558
|
+
to: {
|
|
559
|
+
type: [String, Object],
|
|
560
|
+
required: false,
|
|
561
|
+
default: "body"
|
|
562
|
+
},
|
|
563
|
+
disabled: {
|
|
564
|
+
type: Boolean,
|
|
565
|
+
required: false,
|
|
566
|
+
default: false
|
|
567
|
+
},
|
|
568
|
+
forceMount: {
|
|
569
|
+
type: Boolean,
|
|
570
|
+
required: false,
|
|
571
|
+
default: false
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
const DestylerTooltipPortal = vue.defineComponent({
|
|
575
|
+
name: "DestylerTooltipPortal",
|
|
576
|
+
props: destylerTooltipPortalProps,
|
|
577
|
+
render() {
|
|
578
|
+
return vue.h(teleport.DestylerTeleport, vue.mergeProps(this.$props), {
|
|
579
|
+
default: () => this.$slots.default?.()
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
const destylerTooltipTriggerProps = {
|
|
585
|
+
asChild: {
|
|
586
|
+
type: Boolean,
|
|
587
|
+
required: false,
|
|
588
|
+
default: false
|
|
589
|
+
},
|
|
590
|
+
as: {
|
|
591
|
+
type: [String, Object],
|
|
592
|
+
required: false,
|
|
593
|
+
default: "button"
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
const DestylerTooltipTrigger = vue.defineComponent({
|
|
597
|
+
name: "DestylerTooltipTrigger",
|
|
598
|
+
props: destylerTooltipTriggerProps,
|
|
599
|
+
setup() {
|
|
600
|
+
const rootContext = injectTooltipRootContext();
|
|
601
|
+
const providerContext = injectTooltipProviderContext();
|
|
602
|
+
const { forwardRef, currentElement: triggerElement } = composition.useForwardExpose();
|
|
603
|
+
const isPointerDown = vue.ref(false);
|
|
604
|
+
const hasPointerMoveOpened = vue.ref(false);
|
|
605
|
+
function handlePointerUp() {
|
|
606
|
+
isPointerDown.value = false;
|
|
607
|
+
}
|
|
608
|
+
function handlePointerDown() {
|
|
609
|
+
isPointerDown.value = true;
|
|
610
|
+
document.addEventListener("pointerup", handlePointerUp, { once: true });
|
|
611
|
+
}
|
|
612
|
+
vue.onMounted(() => {
|
|
613
|
+
rootContext.onTriggerChange(triggerElement.value);
|
|
614
|
+
});
|
|
615
|
+
return {
|
|
616
|
+
rootContext,
|
|
617
|
+
providerContext,
|
|
618
|
+
forwardRef,
|
|
619
|
+
isPointerDown,
|
|
620
|
+
hasPointerMoveOpened,
|
|
621
|
+
handlePointerDown
|
|
622
|
+
};
|
|
623
|
+
},
|
|
624
|
+
render() {
|
|
625
|
+
return vue.h(popper.DestylerPopperAnchor, {
|
|
626
|
+
asChild: true
|
|
627
|
+
}, vue.h(primitive.DestylerPrimitive, {
|
|
628
|
+
"ref": (el) => this.forwardRef(el),
|
|
629
|
+
"aria-describedby": this.rootContext.open.value ? this.rootContext.contentId : void 0,
|
|
630
|
+
"data-state": this.rootContext.stateAttribute.value,
|
|
631
|
+
"as": this.$props.as,
|
|
632
|
+
"asChild": this.$props.asChild,
|
|
633
|
+
"onPointermove": (event) => {
|
|
634
|
+
if (event.pointerType === "touch")
|
|
635
|
+
return;
|
|
636
|
+
if (!this.hasPointerMoveOpened && !this.providerContext.isPointerInTransitRef.value) {
|
|
637
|
+
this.rootContext.onTriggerEnter();
|
|
638
|
+
this.hasPointerMoveOpened = true;
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
"onPointerleave": () => {
|
|
642
|
+
this.rootContext.onTriggerLeave();
|
|
643
|
+
this.hasPointerMoveOpened = false;
|
|
644
|
+
},
|
|
645
|
+
"onPointerdown": () => {
|
|
646
|
+
this.handlePointerDown();
|
|
647
|
+
},
|
|
648
|
+
"onFocus": () => {
|
|
649
|
+
if (!this.isPointerDown)
|
|
650
|
+
this.rootContext.onOpen();
|
|
651
|
+
},
|
|
652
|
+
"onBlur": () => {
|
|
653
|
+
this.rootContext.onClose();
|
|
654
|
+
},
|
|
655
|
+
"onClick": () => {
|
|
656
|
+
if (!this.rootContext.disableClosingTrigger.value)
|
|
657
|
+
this.rootContext.onClose();
|
|
658
|
+
}
|
|
659
|
+
}, {
|
|
660
|
+
default: () => this.$slots.default?.()
|
|
661
|
+
}));
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
exports.DestylerTooltipArrow = DestylerTooltipArrow;
|
|
666
|
+
exports.DestylerTooltipContent = DestylerTooltipContent;
|
|
667
|
+
exports.DestylerTooltipContentHoverable = DestylerTooltipContentHoverable;
|
|
668
|
+
exports.DestylerTooltipContentImpl = DestylerTooltipContentImpl;
|
|
669
|
+
exports.DestylerTooltipPortal = DestylerTooltipPortal;
|
|
670
|
+
exports.DestylerTooltipProvider = DestylerTooltipProvider;
|
|
671
|
+
exports.DestylerTooltipRoot = DestylerTooltipRoot;
|
|
672
|
+
exports.DestylerTooltipTrigger = DestylerTooltipTrigger;
|