@destyler/hover-card 0.0.6 → 0.0.7-beta.2
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/index.cjs +336 -20
- package/dist/index.d.cts +100 -5
- package/dist/index.d.mts +100 -5
- package/dist/index.d.ts +100 -5
- package/dist/index.mjs +335 -10
- package/package.json +9 -19
- package/README.md +0 -7
- package/dist/component.cjs +0 -373
- package/dist/component.d.cts +0 -435
- package/dist/component.d.mts +0 -435
- package/dist/component.d.ts +0 -435
- package/dist/component.mjs +0 -357
- package/dist/resolver.cjs +0 -24
- package/dist/resolver.d.cts +0 -6
- package/dist/resolver.d.mts +0 -6
- package/dist/resolver.d.ts +0 -6
- package/dist/resolver.mjs +0 -21
- package/dist/shared/hover-card.c926f135.d.cts +0 -843
- package/dist/shared/hover-card.c926f135.d.mts +0 -843
- package/dist/shared/hover-card.c926f135.d.ts +0 -843
package/dist/component.cjs
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const vue = require('vue');
|
|
4
|
-
const primitive = require('@destyler/primitive');
|
|
5
|
-
const composition = require('@destyler/composition');
|
|
6
|
-
const popper = require('@destyler/popper');
|
|
7
|
-
const presence = require('@destyler/presence');
|
|
8
|
-
const dismissableLayer = require('@destyler/dismissable-layer');
|
|
9
|
-
const component = require('@destyler/dismissable-layer/component');
|
|
10
|
-
const shared = require('@destyler/shared');
|
|
11
|
-
const teleport = require('@destyler/teleport');
|
|
12
|
-
|
|
13
|
-
const hoverCardArrowProps = {
|
|
14
|
-
...primitive.primitiveProps,
|
|
15
|
-
/**
|
|
16
|
-
* @default svg
|
|
17
|
-
*/
|
|
18
|
-
as: {
|
|
19
|
-
...primitive.primitiveProps.as,
|
|
20
|
-
default: "svg"
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* The width of the arrow in pixels.
|
|
24
|
-
*
|
|
25
|
-
* @default 10
|
|
26
|
-
*/
|
|
27
|
-
width: {
|
|
28
|
-
type: Number,
|
|
29
|
-
required: false,
|
|
30
|
-
default: 10
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* The height of the arrow in pixels.
|
|
34
|
-
*
|
|
35
|
-
* @default 5
|
|
36
|
-
*/
|
|
37
|
-
height: {
|
|
38
|
-
type: Number,
|
|
39
|
-
required: false,
|
|
40
|
-
default: 5
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const HoverCardArrow = vue.defineComponent({
|
|
44
|
-
name: "DestylerHoverCardArrow",
|
|
45
|
-
props: hoverCardArrowProps,
|
|
46
|
-
setup() {
|
|
47
|
-
composition.useForwardExpose();
|
|
48
|
-
},
|
|
49
|
-
render() {
|
|
50
|
-
return vue.h(popper.PopperArrow, this.$props, () => this.$slots.default?.());
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
function excludeTouch(eventHandler) {
|
|
55
|
-
return (event) => event.pointerType === "touch" ? void 0 : eventHandler();
|
|
56
|
-
}
|
|
57
|
-
function getTabbableNodes(container) {
|
|
58
|
-
const nodes = [];
|
|
59
|
-
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
60
|
-
acceptNode: (node) => {
|
|
61
|
-
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
while (walker.nextNode())
|
|
65
|
-
nodes.push(walker.currentNode);
|
|
66
|
-
return nodes;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const hoverCardRootProps = {
|
|
70
|
-
/**
|
|
71
|
-
* The controlled open state of the hover card.
|
|
72
|
-
* Can be binded as `v-model:open`.
|
|
73
|
-
*
|
|
74
|
-
* @default undefined
|
|
75
|
-
*/
|
|
76
|
-
open: {
|
|
77
|
-
type: Boolean,
|
|
78
|
-
required: false,
|
|
79
|
-
default: void 0
|
|
80
|
-
},
|
|
81
|
-
/**
|
|
82
|
-
* The open state of the hover card when it is initially rendered.
|
|
83
|
-
* Use when you do not need to control its open state.
|
|
84
|
-
*
|
|
85
|
-
* @default false
|
|
86
|
-
*/
|
|
87
|
-
defaultOpen: {
|
|
88
|
-
type: Boolean,
|
|
89
|
-
required: false,
|
|
90
|
-
default: false
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* The duration from when the mouse enters the
|
|
94
|
-
* trigger until the hover card opens.
|
|
95
|
-
*
|
|
96
|
-
* @default 700
|
|
97
|
-
*/
|
|
98
|
-
openDelay: {
|
|
99
|
-
type: Number,
|
|
100
|
-
required: false,
|
|
101
|
-
default: 700
|
|
102
|
-
},
|
|
103
|
-
/**
|
|
104
|
-
* The duration from when the mouse leaves the trigger
|
|
105
|
-
* or content until the hover card closes.
|
|
106
|
-
*
|
|
107
|
-
* @default 300
|
|
108
|
-
*/
|
|
109
|
-
closeDelay: {
|
|
110
|
-
type: Number,
|
|
111
|
-
required: false,
|
|
112
|
-
default: 300
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
const hoverCardRootEmits = {
|
|
116
|
-
/**
|
|
117
|
-
* Event handler called when the open state of the hover card changes.
|
|
118
|
-
*/
|
|
119
|
-
"update:open": (_value) => true
|
|
120
|
-
};
|
|
121
|
-
const [injectHoverCardRootContext, provideHoverCardRootContext] = shared.createContext("DestylerHoverCardRoot");
|
|
122
|
-
const HoverCardRoot = vue.defineComponent({
|
|
123
|
-
name: "DestylerHoverCardRoot",
|
|
124
|
-
props: hoverCardRootProps,
|
|
125
|
-
emits: hoverCardRootEmits,
|
|
126
|
-
setup(props, { emit }) {
|
|
127
|
-
const { openDelay, closeDelay } = vue.toRefs(props);
|
|
128
|
-
composition.useForwardExpose();
|
|
129
|
-
const open = composition.useVModel(props, "open", emit, {
|
|
130
|
-
defaultValue: props.defaultOpen,
|
|
131
|
-
passive: props.open === void 0
|
|
132
|
-
});
|
|
133
|
-
const openTimerRef = vue.ref(0);
|
|
134
|
-
const closeTimerRef = vue.ref(0);
|
|
135
|
-
const hasSelectionRef = vue.ref(false);
|
|
136
|
-
const isPointerDownOnContentRef = vue.ref(false);
|
|
137
|
-
function handleOpen() {
|
|
138
|
-
clearTimeout(closeTimerRef.value);
|
|
139
|
-
openTimerRef.value = window.setTimeout(() => open.value = true, openDelay.value);
|
|
140
|
-
}
|
|
141
|
-
function handleClose() {
|
|
142
|
-
clearTimeout(openTimerRef.value);
|
|
143
|
-
if (!hasSelectionRef.value && !isPointerDownOnContentRef.value)
|
|
144
|
-
closeTimerRef.value = window.setTimeout(() => open.value = false, closeDelay.value);
|
|
145
|
-
}
|
|
146
|
-
function handleDismiss() {
|
|
147
|
-
open.value = false;
|
|
148
|
-
}
|
|
149
|
-
provideHoverCardRootContext({
|
|
150
|
-
open,
|
|
151
|
-
onOpenChange(value) {
|
|
152
|
-
open.value = value;
|
|
153
|
-
},
|
|
154
|
-
onOpen: handleOpen,
|
|
155
|
-
onClose: handleClose,
|
|
156
|
-
onDismiss: handleDismiss,
|
|
157
|
-
hasSelectionRef,
|
|
158
|
-
isPointerDownOnContentRef
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
render() {
|
|
162
|
-
return vue.h(popper.PopperRoot, {}, () => this.$slots.default?.());
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const hoverCardContentImplProps = {
|
|
167
|
-
...popper.popperContentProps
|
|
168
|
-
};
|
|
169
|
-
const hoverCardContentImplEmits = {
|
|
170
|
-
...component.dismissableLayerEmits
|
|
171
|
-
};
|
|
172
|
-
const HoverCardContentImpl = vue.defineComponent({
|
|
173
|
-
name: "DestylerHoverCardContentImpl",
|
|
174
|
-
props: hoverCardContentImplProps,
|
|
175
|
-
emits: hoverCardContentImplEmits,
|
|
176
|
-
setup(props) {
|
|
177
|
-
const forwarded = composition.useForwardProps(props);
|
|
178
|
-
const { forwardRef, currentElement: contentElement } = composition.useForwardExpose();
|
|
179
|
-
const rootContext = injectHoverCardRootContext();
|
|
180
|
-
const containSelection = vue.ref(false);
|
|
181
|
-
let originalBodyUserSelect;
|
|
182
|
-
vue.watchEffect((cleanupFn) => {
|
|
183
|
-
if (containSelection.value) {
|
|
184
|
-
const body = document.body;
|
|
185
|
-
originalBodyUserSelect = body.style.userSelect || body.style.webkitUserSelect;
|
|
186
|
-
body.style.userSelect = "none";
|
|
187
|
-
body.style.webkitUserSelect = "none";
|
|
188
|
-
cleanupFn(() => {
|
|
189
|
-
body.style.userSelect = originalBodyUserSelect;
|
|
190
|
-
body.style.webkitUserSelect = originalBodyUserSelect;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
function handlePointerUp() {
|
|
195
|
-
containSelection.value = false;
|
|
196
|
-
rootContext.isPointerDownOnContentRef.value = false;
|
|
197
|
-
vue.nextTick(() => {
|
|
198
|
-
const hasSelection = document.getSelection()?.toString() !== "";
|
|
199
|
-
if (hasSelection)
|
|
200
|
-
rootContext.hasSelectionRef.value = true;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
vue.onMounted(() => {
|
|
204
|
-
if (contentElement.value) {
|
|
205
|
-
document.addEventListener("pointerup", handlePointerUp);
|
|
206
|
-
const tabbables = getTabbableNodes(contentElement.value);
|
|
207
|
-
tabbables.forEach((tabbable) => tabbable.setAttribute("tabindex", "-1"));
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
vue.onUnmounted(() => {
|
|
211
|
-
document.removeEventListener("pointerup", handlePointerUp);
|
|
212
|
-
rootContext.hasSelectionRef.value = false;
|
|
213
|
-
rootContext.isPointerDownOnContentRef.value = false;
|
|
214
|
-
});
|
|
215
|
-
return {
|
|
216
|
-
rootContext,
|
|
217
|
-
forwarded,
|
|
218
|
-
forwardRef,
|
|
219
|
-
containSelection
|
|
220
|
-
};
|
|
221
|
-
},
|
|
222
|
-
render() {
|
|
223
|
-
return vue.h(dismissableLayer.DismissableLayer, {
|
|
224
|
-
asChild: true,
|
|
225
|
-
disableOutsidePointerEvents: false,
|
|
226
|
-
onEscapeKeyDown: (event) => {
|
|
227
|
-
this.$emit("escapeKeyDown", event);
|
|
228
|
-
},
|
|
229
|
-
onPointerDownOutside: (event) => {
|
|
230
|
-
this.$emit("pointerDownOutside", event);
|
|
231
|
-
},
|
|
232
|
-
onFocusOutside: vue.withModifiers((event) => {
|
|
233
|
-
this.$emit("focusOutside", event);
|
|
234
|
-
}, ["prevent"]),
|
|
235
|
-
onDismiss: () => {
|
|
236
|
-
this.rootContext.onDismiss();
|
|
237
|
-
}
|
|
238
|
-
}, () => vue.h(popper.PopperContent, vue.mergeProps(this.forwarded, this.$attrs, {
|
|
239
|
-
"ref": (el) => this.forwardRef(el),
|
|
240
|
-
"data-state": this.rootContext.open.value ? "open" : "closed",
|
|
241
|
-
"style": {
|
|
242
|
-
"userSelect": this.containSelection ? "text" : void 0,
|
|
243
|
-
"WebkitUserSelect": this.containSelection ? "text" : void 0,
|
|
244
|
-
"--destyler-hover-card-content-transform-origin": "var(--destyler-popper-transform-origin)",
|
|
245
|
-
"--destyler-hover-card-content-available-width": "var(--destyler-popper-available-width)",
|
|
246
|
-
"--destyler-hover-card-content-available-height": "var(--destyler-popper-available-height)",
|
|
247
|
-
"--destyler-hover-card-trigger-width": "var(--destyler-popper-anchor-width)",
|
|
248
|
-
"--destyler-hover-card-trigger-height": "var(--destyler-popper-anchor-height)"
|
|
249
|
-
},
|
|
250
|
-
"onPointerdown": (event) => {
|
|
251
|
-
if (event.currentTarget.contains(event.target))
|
|
252
|
-
this.containSelection = true;
|
|
253
|
-
this.rootContext.hasSelectionRef.value = false;
|
|
254
|
-
this.rootContext.isPointerDownOnContentRef.value = true;
|
|
255
|
-
}
|
|
256
|
-
}), () => this.$slots.default?.()));
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const hoverCardContentProps = {
|
|
261
|
-
...hoverCardContentImplProps,
|
|
262
|
-
/**
|
|
263
|
-
* Used to force mounting when more control is needed.
|
|
264
|
-
* Useful when controlling animation with Vue animation libraries.
|
|
265
|
-
*/
|
|
266
|
-
forceMount: {
|
|
267
|
-
type: Boolean,
|
|
268
|
-
required: false
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
const hoverCardContentEmits = {
|
|
272
|
-
...hoverCardContentImplEmits
|
|
273
|
-
};
|
|
274
|
-
const HoverCardContent = vue.defineComponent({
|
|
275
|
-
name: "DestylerHoverCardContent",
|
|
276
|
-
props: hoverCardContentProps,
|
|
277
|
-
emits: hoverCardContentEmits,
|
|
278
|
-
setup(props, { emit }) {
|
|
279
|
-
const forwarded = composition.useForwardPropsEmits(props, emit);
|
|
280
|
-
const { forwardRef } = composition.useForwardExpose();
|
|
281
|
-
const rootContext = injectHoverCardRootContext();
|
|
282
|
-
return {
|
|
283
|
-
rootContext,
|
|
284
|
-
forwarded,
|
|
285
|
-
forwardRef
|
|
286
|
-
};
|
|
287
|
-
},
|
|
288
|
-
render() {
|
|
289
|
-
return vue.h(presence.Presence, {
|
|
290
|
-
present: this.forceMount || this.rootContext.open.value
|
|
291
|
-
}, () => vue.h(HoverCardContentImpl, vue.mergeProps(this.forwarded, {
|
|
292
|
-
ref: (el) => this.forwardRef(el),
|
|
293
|
-
onPointerenter: (event) => {
|
|
294
|
-
excludeTouch(this.rootContext.onOpen)(event);
|
|
295
|
-
},
|
|
296
|
-
onPointerleave: (event) => {
|
|
297
|
-
excludeTouch(this.rootContext.onClose)(event);
|
|
298
|
-
}
|
|
299
|
-
}), () => this.$slots.default?.()));
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
const hoverCardPortalProps = {
|
|
304
|
-
...teleport.teleportPrimitiveProps
|
|
305
|
-
};
|
|
306
|
-
const HoverCardPortal = vue.defineComponent({
|
|
307
|
-
name: "DestylerHoverCardPortal",
|
|
308
|
-
props: hoverCardPortalProps,
|
|
309
|
-
render() {
|
|
310
|
-
return vue.h(teleport.TeleportPrimitive, this.$props, () => this.$slots.default?.());
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
const hoverCardTriggerProps = {
|
|
315
|
-
...primitive.primitiveProps,
|
|
316
|
-
/**
|
|
317
|
-
* @default a
|
|
318
|
-
*/
|
|
319
|
-
as: {
|
|
320
|
-
...primitive.primitiveProps.as,
|
|
321
|
-
default: "a"
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
const HoverCardTrigger = vue.defineComponent({
|
|
325
|
-
name: "DestylerHoverCardTrigger",
|
|
326
|
-
props: hoverCardTriggerProps,
|
|
327
|
-
setup() {
|
|
328
|
-
const { forwardRef } = composition.useForwardExpose();
|
|
329
|
-
const rootContext = injectHoverCardRootContext();
|
|
330
|
-
return {
|
|
331
|
-
rootContext,
|
|
332
|
-
forwardRef
|
|
333
|
-
};
|
|
334
|
-
},
|
|
335
|
-
render() {
|
|
336
|
-
return vue.h(popper.PopperAnchor, {
|
|
337
|
-
asChild: true
|
|
338
|
-
}, () => vue.h(primitive.Primitive, {
|
|
339
|
-
"ref": (el) => this.forwardRef(el),
|
|
340
|
-
"as": this.$props.as,
|
|
341
|
-
"asChild": this.$props.asChild,
|
|
342
|
-
"data-state": this.rootContext.open.value ? "open" : "closed",
|
|
343
|
-
"onPointerenter": (event) => {
|
|
344
|
-
excludeTouch(this.rootContext.onOpen)(event);
|
|
345
|
-
},
|
|
346
|
-
"onPointerleave": (event) => {
|
|
347
|
-
excludeTouch(this.rootContext.onClose)(event);
|
|
348
|
-
},
|
|
349
|
-
"onFocus": () => {
|
|
350
|
-
this.rootContext.onOpen();
|
|
351
|
-
},
|
|
352
|
-
"onBlur": () => {
|
|
353
|
-
this.rootContext.onClose();
|
|
354
|
-
}
|
|
355
|
-
}, () => this.$slots.default?.()));
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
exports.HoverCardArrow = HoverCardArrow;
|
|
360
|
-
exports.HoverCardContent = HoverCardContent;
|
|
361
|
-
exports.HoverCardContentImpl = HoverCardContentImpl;
|
|
362
|
-
exports.HoverCardPortal = HoverCardPortal;
|
|
363
|
-
exports.HoverCardRoot = HoverCardRoot;
|
|
364
|
-
exports.HoverCardTrigger = HoverCardTrigger;
|
|
365
|
-
exports.hoverCardArrowProps = hoverCardArrowProps;
|
|
366
|
-
exports.hoverCardContentEmits = hoverCardContentEmits;
|
|
367
|
-
exports.hoverCardContentImplEmits = hoverCardContentImplEmits;
|
|
368
|
-
exports.hoverCardContentImplProps = hoverCardContentImplProps;
|
|
369
|
-
exports.hoverCardContentProps = hoverCardContentProps;
|
|
370
|
-
exports.hoverCardPortalProps = hoverCardPortalProps;
|
|
371
|
-
exports.hoverCardRootEmits = hoverCardRootEmits;
|
|
372
|
-
exports.hoverCardRootProps = hoverCardRootProps;
|
|
373
|
-
exports.hoverCardTriggerProps = hoverCardTriggerProps;
|