@v-c/trigger 1.0.12 → 1.0.13-beta.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/dist/index.js +13 -16
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { useResizeObserver } from "@v-c/resize-observer";
|
|
|
13
13
|
import { classNames } from "@v-c/util";
|
|
14
14
|
import { getShadowRoot } from "@v-c/util/dist/Dom/shadow";
|
|
15
15
|
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
16
|
-
import {
|
|
16
|
+
import { resolveToElement } from "@v-c/util/dist/vnode";
|
|
17
17
|
var defaults = {
|
|
18
18
|
prefixCls: "vc-trigger-popup",
|
|
19
19
|
action: "hover",
|
|
@@ -48,14 +48,11 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
48
48
|
parentContext?.value?.registerSubPopup(id, element ?? null);
|
|
49
49
|
};
|
|
50
50
|
const targetEle = shallowRef();
|
|
51
|
-
const persistTargetEle = shallowRef();
|
|
52
|
-
const mergedTargetEle = computed(() => targetEle.value ?? persistTargetEle.value);
|
|
53
51
|
const externalForwardRef = shallowRef(null);
|
|
54
52
|
const setTargetRef = (node) => {
|
|
55
53
|
const element = resolveToElement(node);
|
|
56
54
|
if (element && targetEle.value !== element) {
|
|
57
55
|
targetEle.value = element;
|
|
58
|
-
persistTargetEle.value = element;
|
|
59
56
|
externalForwardRef.value = element;
|
|
60
57
|
} else if (!element) {
|
|
61
58
|
targetEle.value = void 0;
|
|
@@ -70,7 +67,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
70
67
|
...hoverActionProps.value
|
|
71
68
|
}));
|
|
72
69
|
const inPopupOrChild = (ele) => {
|
|
73
|
-
const childDOM =
|
|
70
|
+
const childDOM = targetEle.value;
|
|
74
71
|
return childDOM?.contains(ele) || childDOM && getShadowRoot(childDOM)?.host === ele || ele === childDOM || popupEle.value?.contains(ele) || popupEle.value && getShadowRoot(popupEle.value)?.host === ele || ele === popupEle.value || Object.values(subPopupElements.value).some((subPopupEle) => subPopupEle?.contains(ele) || ele === subPopupEle);
|
|
75
72
|
};
|
|
76
73
|
const innerArrow = computed(() => {
|
|
@@ -91,7 +88,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
91
88
|
const getUniqueOptions = (delay = 0) => {
|
|
92
89
|
return {
|
|
93
90
|
popup: props.popup,
|
|
94
|
-
target:
|
|
91
|
+
target: targetEle.value,
|
|
95
92
|
delay,
|
|
96
93
|
prefixCls: props.prefixCls,
|
|
97
94
|
popupClassName: props.popupClassName,
|
|
@@ -113,8 +110,8 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
113
110
|
onEsc
|
|
114
111
|
};
|
|
115
112
|
};
|
|
116
|
-
watch([mergedOpen,
|
|
117
|
-
if (uniqueContext && props.unique &&
|
|
113
|
+
watch([mergedOpen, targetEle], () => {
|
|
114
|
+
if (uniqueContext && props.unique && targetEle.value && !openUncontrolled.value && !parentContext?.value) if (mergedOpen.value) {
|
|
118
115
|
const enterDelay = props.mouseEnterDelay ?? 0;
|
|
119
116
|
uniqueContext?.show(getUniqueOptions(enterDelay), isOpen);
|
|
120
117
|
} else uniqueContext?.hide(props.mouseLeaveDelay || 0);
|
|
@@ -159,7 +156,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
159
156
|
const setMousePosByEvent = (event) => {
|
|
160
157
|
mousePos.value = [event.clientX, event.clientY];
|
|
161
158
|
};
|
|
162
|
-
const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, scaleX, scaleY, alignInfo, onAlign] = useAlign(mergedOpen, popupEle, computed(() => props?.alignPoint && mousePos.value !== null ? mousePos.value :
|
|
159
|
+
const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, scaleX, scaleY, alignInfo, onAlign] = useAlign(mergedOpen, popupEle, computed(() => props?.alignPoint && mousePos.value !== null ? mousePos.value : targetEle.value), computed(() => props?.popupPlacement), computed(() => props?.builtinPlacements), computed(() => props?.popupAlign), props?.onPopupAlign, isMobile);
|
|
163
160
|
const [showActions, hideActions] = useAction(computed(() => props.action), computed(() => props.showAction), computed(() => props.hideAction));
|
|
164
161
|
const clickToShow = computed(() => showActions.value?.has("click"));
|
|
165
162
|
const clickToHide = computed(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
|
|
@@ -170,7 +167,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
170
167
|
const onScroll = () => {
|
|
171
168
|
if (openRef.value && props?.alignPoint && clickToHide.value) triggerOpen(false);
|
|
172
169
|
};
|
|
173
|
-
useWatch(mergedOpen,
|
|
170
|
+
useWatch(mergedOpen, targetEle, popupEle, triggerAlign, onScroll);
|
|
174
171
|
watch([mousePos, () => props.popupPlacement], async () => {
|
|
175
172
|
await nextTick();
|
|
176
173
|
triggerAlign();
|
|
@@ -191,8 +188,8 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
191
188
|
const targetWidth = shallowRef(0);
|
|
192
189
|
const targetHeight = shallowRef(0);
|
|
193
190
|
const syncTargetSize = () => {
|
|
194
|
-
if (props.stretch &&
|
|
195
|
-
const rect =
|
|
191
|
+
if (props.stretch && targetEle.value) {
|
|
192
|
+
const rect = targetEle.value.getBoundingClientRect();
|
|
196
193
|
targetWidth.value = rect.width;
|
|
197
194
|
targetHeight.value = rect.height;
|
|
198
195
|
}
|
|
@@ -329,20 +326,20 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
329
326
|
x: arrowX.value,
|
|
330
327
|
y: arrowY.value
|
|
331
328
|
};
|
|
332
|
-
const triggerNode =
|
|
329
|
+
const triggerNode = createVNode(child, {
|
|
333
330
|
...mergedChildrenProps,
|
|
334
331
|
...passedProps,
|
|
335
332
|
ref: setTargetRef
|
|
336
|
-
}
|
|
333
|
+
});
|
|
337
334
|
const { unique, prefixCls, popup, popupClassName, popupStyle, zIndex, fresh, onPopupClick, mask, popupMotion, maskMotion, forceRender, getPopupContainer, stretch, mobile } = props;
|
|
338
|
-
return createVNode(Fragment, null, [triggerNode, rendedRef.value &&
|
|
335
|
+
return createVNode(Fragment, null, [triggerNode, rendedRef.value && targetEle.value && (!uniqueContext || !unique) && createVNode(TriggerContextProvider, context.value, { default: () => [createVNode(Popup_default, {
|
|
339
336
|
"portal": PortalComponent,
|
|
340
337
|
"ref": setPopupRef,
|
|
341
338
|
"prefixCls": prefixCls,
|
|
342
339
|
"popup": popup,
|
|
343
340
|
"className": classNames(popupClassName, !isMobile.value && alignedClassName.value),
|
|
344
341
|
"style": popupStyle,
|
|
345
|
-
"target":
|
|
342
|
+
"target": targetEle.value,
|
|
346
343
|
"onMouseEnter": onPopupMouseEnter,
|
|
347
344
|
"onMouseLeave": onPopupMouseLeave,
|
|
348
345
|
"onPointerEnter": onPopupMouseEnter,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/trigger",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.13-beta.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@v-c/portal": "^1.0.7",
|
|
33
33
|
"@v-c/resize-observer": "^1.0.8",
|
|
34
|
-
"@v-c/util": "^1.0.
|
|
34
|
+
"@v-c/util": "^1.0.18-beta.1"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "vite build",
|