@v-c/trigger 0.0.9 → 0.0.11
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/Popup/Arrow.cjs +91 -1
- package/dist/Popup/Arrow.js +60 -38
- package/dist/Popup/Mask.cjs +66 -1
- package/dist/Popup/Mask.js +35 -32
- package/dist/Popup/PopupContent.cjs +29 -1
- package/dist/Popup/PopupContent.js +15 -8
- package/dist/Popup/index.cjs +365 -1
- package/dist/Popup/index.js +194 -160
- package/dist/UniqueProvider/UniqueContainer.cjs +159 -1
- package/dist/UniqueProvider/UniqueContainer.js +87 -67
- package/dist/UniqueProvider/index.cjs +213 -1
- package/dist/UniqueProvider/index.js +177 -131
- package/dist/UniqueProvider/useTargetState.cjs +42 -1
- package/dist/UniqueProvider/useTargetState.js +39 -10
- package/dist/context.cjs +38 -1
- package/dist/context.js +27 -16
- package/dist/hooks/useAction.cjs +32 -1
- package/dist/hooks/useAction.js +27 -12
- package/dist/hooks/useAlign.cjs +499 -1
- package/dist/hooks/useAlign.d.ts +1 -1
- package/dist/hooks/useAlign.js +445 -204
- package/dist/hooks/useDelay.cjs +27 -1
- package/dist/hooks/useDelay.js +23 -12
- package/dist/hooks/useOffsetStyle.cjs +36 -1
- package/dist/hooks/useOffsetStyle.js +28 -12
- package/dist/hooks/useWatch.cjs +37 -1
- package/dist/hooks/useWatch.js +28 -17
- package/dist/hooks/useWinClick.cjs +67 -1
- package/dist/hooks/useWinClick.js +56 -39
- package/dist/index.cjs +700 -1
- package/dist/index.js +501 -312
- package/dist/util.cjs +101 -1
- package/dist/util.js +86 -54
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,511 +1,700 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { classNames
|
|
5
|
-
import { isDOM
|
|
6
|
-
import { getShadowRoot
|
|
7
|
-
import { filterEmpty
|
|
8
|
-
import { useTriggerContext
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import { getAlignPopupClassName
|
|
16
|
-
import { default as
|
|
17
|
-
function
|
|
18
|
-
return typeof
|
|
1
|
+
import { defineComponent, computed, ref, useId, shallowRef, reactive, watch, nextTick, watchEffect, createVNode, Fragment, mergeDefaults, isVNode } from "vue";
|
|
2
|
+
import Portal from "@v-c/portal";
|
|
3
|
+
import ResizeObserver from "@v-c/resize-observer";
|
|
4
|
+
import { classNames } from "@v-c/util";
|
|
5
|
+
import { isDOM } from "@v-c/util/dist/Dom/findDOMNode";
|
|
6
|
+
import { getShadowRoot } from "@v-c/util/dist/Dom/shadow";
|
|
7
|
+
import { filterEmpty } from "@v-c/util/dist/props-util";
|
|
8
|
+
import { useTriggerContext, useUniqueContext, TriggerContextProvider } from "./context.js";
|
|
9
|
+
import useAction from "./hooks/useAction.js";
|
|
10
|
+
import useAlign from "./hooks/useAlign.js";
|
|
11
|
+
import useDelay from "./hooks/useDelay.js";
|
|
12
|
+
import useWatch from "./hooks/useWatch.js";
|
|
13
|
+
import useWinClick from "./hooks/useWinClick.js";
|
|
14
|
+
import Popup from "./Popup/index.js";
|
|
15
|
+
import { getAlignPopupClassName } from "./util.js";
|
|
16
|
+
import { default as default2 } from "./UniqueProvider/index.js";
|
|
17
|
+
function _isSlot(s) {
|
|
18
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const defaults = {
|
|
21
21
|
prefixCls: "vc-trigger-popup",
|
|
22
22
|
action: "hover",
|
|
23
23
|
mouseLeaveDelay: 0.1,
|
|
24
|
-
maskClosable:
|
|
24
|
+
maskClosable: true,
|
|
25
25
|
builtinPlacements: {},
|
|
26
26
|
popupVisible: void 0,
|
|
27
27
|
defaultPopupVisible: void 0
|
|
28
28
|
};
|
|
29
|
-
function
|
|
30
|
-
return /* @__PURE__ */
|
|
31
|
-
expose
|
|
32
|
-
slots
|
|
33
|
-
attrs
|
|
29
|
+
function generateTrigger(PortalComponent = Portal) {
|
|
30
|
+
return /* @__PURE__ */ defineComponent((props, {
|
|
31
|
+
expose,
|
|
32
|
+
slots,
|
|
33
|
+
attrs
|
|
34
34
|
}) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const mergedAutoDestroy = computed(() => props.autoDestroy ?? false);
|
|
36
|
+
const openUncontrolled = computed(() => props.popupVisible === void 0);
|
|
37
|
+
const isMobile = computed(() => !!props.mobile);
|
|
38
|
+
const subPopupElements = ref({});
|
|
39
|
+
const parentContext = useTriggerContext();
|
|
40
|
+
const context = computed(() => {
|
|
41
|
+
return {
|
|
42
|
+
registerSubPopup(id2, subPopupEle) {
|
|
43
|
+
if (subPopupEle) {
|
|
44
|
+
subPopupElements.value[id2] = subPopupEle;
|
|
45
|
+
} else {
|
|
46
|
+
delete subPopupElements.value[id2];
|
|
47
|
+
}
|
|
48
|
+
parentContext?.value.registerSubPopup(id2, subPopupEle);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const uniqueContext = useUniqueContext();
|
|
53
|
+
const id = useId();
|
|
54
|
+
const popupEle = shallowRef(null);
|
|
55
|
+
const externalPopupRef = shallowRef(null);
|
|
56
|
+
const resolveToElement = (node) => {
|
|
57
|
+
if (!node) {
|
|
41
58
|
return null;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
}
|
|
60
|
+
if (isDOM(node)) {
|
|
61
|
+
return node;
|
|
62
|
+
}
|
|
63
|
+
const exposed = node;
|
|
64
|
+
if (isDOM(exposed?.$el)) {
|
|
65
|
+
return exposed.$el;
|
|
66
|
+
}
|
|
67
|
+
const nativeEl = exposed?.nativeElement;
|
|
68
|
+
if (isDOM(nativeEl?.value)) {
|
|
69
|
+
return nativeEl.value;
|
|
70
|
+
}
|
|
71
|
+
if (isDOM(nativeEl)) {
|
|
72
|
+
return nativeEl;
|
|
73
|
+
}
|
|
74
|
+
if (typeof exposed?.getElement === "function") {
|
|
75
|
+
const el = exposed.getElement();
|
|
76
|
+
if (isDOM(el)) {
|
|
77
|
+
return el;
|
|
78
|
+
}
|
|
56
79
|
}
|
|
57
80
|
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
};
|
|
82
|
+
const setPopupRef = (node) => {
|
|
83
|
+
const element = resolveToElement(node);
|
|
84
|
+
externalPopupRef.value = element;
|
|
85
|
+
if (popupEle.value !== element) {
|
|
86
|
+
popupEle.value = element;
|
|
87
|
+
}
|
|
88
|
+
parentContext?.value?.registerSubPopup(id, element ?? null);
|
|
89
|
+
};
|
|
90
|
+
const targetEle = shallowRef(null);
|
|
91
|
+
const externalForwardRef = shallowRef(null);
|
|
92
|
+
const setTargetRef = (node) => {
|
|
93
|
+
const element = resolveToElement(node);
|
|
94
|
+
if (element && targetEle.value !== element) {
|
|
95
|
+
targetEle.value = element;
|
|
96
|
+
externalForwardRef.value = element;
|
|
97
|
+
} else if (!element) {
|
|
98
|
+
targetEle.value = null;
|
|
99
|
+
externalForwardRef.value = null;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const originChildProps = reactive({});
|
|
103
|
+
const baseActionProps = shallowRef({});
|
|
104
|
+
const hoverActionProps = shallowRef({});
|
|
105
|
+
const cloneProps = computed(() => ({
|
|
106
|
+
...baseActionProps.value,
|
|
107
|
+
...hoverActionProps.value
|
|
108
|
+
}));
|
|
109
|
+
const inPopupOrChild = (ele) => {
|
|
110
|
+
const childDOM = targetEle.value;
|
|
111
|
+
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);
|
|
112
|
+
};
|
|
113
|
+
const innerArrow = computed(() => {
|
|
114
|
+
return props.arrow ? {
|
|
115
|
+
...props?.arrow !== true ? props?.arrow : {}
|
|
116
|
+
} : null;
|
|
79
117
|
});
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
uniqueContainerClassName: n.uniqueContainerClassName,
|
|
87
|
-
uniqueContainerStyle: n.uniqueContainerStyle,
|
|
88
|
-
popupStyle: n.popupStyle,
|
|
89
|
-
popupPlacement: n.popupPlacement,
|
|
90
|
-
builtinPlacements: n.builtinPlacements,
|
|
91
|
-
popupAlign: n.popupAlign,
|
|
92
|
-
zIndex: n.zIndex,
|
|
93
|
-
mask: n.mask,
|
|
94
|
-
maskClosable: n.maskClosable,
|
|
95
|
-
popupMotion: n.popupMotion,
|
|
96
|
-
maskMotion: n.maskMotion,
|
|
97
|
-
arrow: ne.value,
|
|
98
|
-
getPopupContainer: n.getPopupContainer,
|
|
99
|
-
getPopupClassNameFromAlign: n.getPopupClassNameFromAlign,
|
|
100
|
-
id: _
|
|
118
|
+
const internalOpen = shallowRef(props?.defaultPopupVisible ?? false);
|
|
119
|
+
if (props.popupVisible !== void 0) {
|
|
120
|
+
internalOpen.value = props.popupVisible;
|
|
121
|
+
}
|
|
122
|
+
const mergedOpen = computed(() => {
|
|
123
|
+
return props?.popupVisible ?? internalOpen.value;
|
|
101
124
|
});
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
const setMergedOpen = (nextOpen) => {
|
|
126
|
+
if (openUncontrolled.value) {
|
|
127
|
+
internalOpen.value = nextOpen;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const isOpen = () => mergedOpen.value;
|
|
131
|
+
watch(() => props.popupVisible, async (nextVisible) => {
|
|
132
|
+
if (nextVisible !== void 0) {
|
|
133
|
+
await nextTick();
|
|
134
|
+
internalOpen.value = nextVisible;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const getUniqueOptions = (delay = 0) => {
|
|
138
|
+
return {
|
|
139
|
+
popup: props.popup,
|
|
140
|
+
target: targetEle.value,
|
|
141
|
+
delay,
|
|
142
|
+
prefixCls: props.prefixCls,
|
|
143
|
+
popupClassName: props.popupClassName,
|
|
144
|
+
uniqueContainerClassName: props.uniqueContainerClassName,
|
|
145
|
+
uniqueContainerStyle: props.uniqueContainerStyle,
|
|
146
|
+
popupStyle: props.popupStyle,
|
|
147
|
+
popupPlacement: props.popupPlacement,
|
|
148
|
+
builtinPlacements: props.builtinPlacements,
|
|
149
|
+
popupAlign: props.popupAlign,
|
|
150
|
+
zIndex: props.zIndex,
|
|
151
|
+
mask: props.mask,
|
|
152
|
+
maskClosable: props.maskClosable,
|
|
153
|
+
popupMotion: props.popupMotion,
|
|
154
|
+
maskMotion: props.maskMotion,
|
|
155
|
+
arrow: innerArrow.value,
|
|
156
|
+
getPopupContainer: props.getPopupContainer,
|
|
157
|
+
getPopupClassNameFromAlign: props.getPopupClassNameFromAlign,
|
|
158
|
+
id
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
watch([mergedOpen, targetEle], () => {
|
|
162
|
+
if (uniqueContext && props.unique && targetEle.value && !openUncontrolled.value && !parentContext?.value) {
|
|
163
|
+
if (mergedOpen.value) {
|
|
164
|
+
const enterDelay = props.mouseEnterDelay ?? 0;
|
|
165
|
+
uniqueContext?.show(getUniqueOptions(enterDelay), isOpen);
|
|
166
|
+
} else {
|
|
167
|
+
uniqueContext?.hide(props.mouseLeaveDelay || 0);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
109
170
|
});
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
171
|
+
const openRef = shallowRef(mergedOpen.value);
|
|
172
|
+
const lastTriggerRef = shallowRef([]);
|
|
173
|
+
lastTriggerRef.value = [];
|
|
174
|
+
watchEffect(() => {
|
|
175
|
+
openRef.value = mergedOpen.value;
|
|
176
|
+
if (!mergedOpen.value) {
|
|
177
|
+
lastTriggerRef.value = [];
|
|
178
|
+
}
|
|
113
179
|
});
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
180
|
+
const internalTriggerOpen = (nextOpen) => {
|
|
181
|
+
setMergedOpen(nextOpen);
|
|
182
|
+
if ((lastTriggerRef.value[lastTriggerRef.value.length - 1] ?? mergedOpen.value) !== nextOpen) {
|
|
183
|
+
lastTriggerRef.value.push(nextOpen);
|
|
184
|
+
props?.onOpenChange?.(nextOpen);
|
|
185
|
+
props?.onPopupVisibleChange?.(nextOpen);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const delayInvoke = useDelay();
|
|
189
|
+
const triggerOpen = (nextOpen, delay = 0) => {
|
|
190
|
+
if (props.popupVisible !== void 0) {
|
|
191
|
+
delayInvoke(() => {
|
|
192
|
+
internalTriggerOpen(nextOpen);
|
|
193
|
+
}, delay);
|
|
121
194
|
return;
|
|
122
195
|
}
|
|
123
|
-
if (
|
|
124
|
-
|
|
196
|
+
if (uniqueContext && props.unique && openUncontrolled.value && !parentContext?.value) {
|
|
197
|
+
if (nextOpen) {
|
|
198
|
+
uniqueContext?.show(getUniqueOptions(delay), isOpen);
|
|
199
|
+
} else {
|
|
200
|
+
uniqueContext.hide(delay);
|
|
201
|
+
}
|
|
125
202
|
return;
|
|
126
203
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
204
|
+
delayInvoke(() => {
|
|
205
|
+
internalTriggerOpen(nextOpen);
|
|
206
|
+
}, delay);
|
|
207
|
+
};
|
|
208
|
+
const inMotion = shallowRef(false);
|
|
209
|
+
watch(mergedOpen, async () => {
|
|
210
|
+
await nextTick();
|
|
211
|
+
if (mergedOpen.value) {
|
|
212
|
+
inMotion.value = true;
|
|
213
|
+
}
|
|
133
214
|
});
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
215
|
+
const motionPrepareResolve = shallowRef();
|
|
216
|
+
const mousePos = ref(null);
|
|
217
|
+
const setMousePosByEvent = (event) => {
|
|
218
|
+
mousePos.value = [event.clientX, event.clientY];
|
|
219
|
+
};
|
|
220
|
+
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);
|
|
221
|
+
const [showActions, hideActions] = useAction(computed(() => props.action), computed(() => props.showAction), computed(() => props.hideAction));
|
|
222
|
+
const clickToShow = computed(() => showActions.value?.has("click"));
|
|
223
|
+
const clickToHide = computed(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
|
|
224
|
+
const triggerAlign = () => {
|
|
225
|
+
if (!inMotion.value) {
|
|
226
|
+
onAlign();
|
|
227
|
+
}
|
|
138
228
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
229
|
+
const onScroll = () => {
|
|
230
|
+
if (openRef.value && props?.alignPoint && clickToHide.value) {
|
|
231
|
+
triggerOpen(false);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
useWatch(mergedOpen, targetEle, popupEle, triggerAlign, onScroll);
|
|
235
|
+
watch([mousePos, () => props.popupPlacement], async () => {
|
|
236
|
+
await nextTick();
|
|
237
|
+
triggerAlign();
|
|
238
|
+
});
|
|
239
|
+
watch(() => JSON.stringify(props.popupAlign), async () => {
|
|
240
|
+
await nextTick();
|
|
145
241
|
const {
|
|
146
|
-
builtinPlacements
|
|
147
|
-
popupPlacement
|
|
148
|
-
} =
|
|
149
|
-
|
|
242
|
+
builtinPlacements,
|
|
243
|
+
popupPlacement
|
|
244
|
+
} = props;
|
|
245
|
+
if (mergedOpen.value && !builtinPlacements?.[popupPlacement]) {
|
|
246
|
+
triggerAlign();
|
|
247
|
+
}
|
|
150
248
|
});
|
|
151
|
-
const
|
|
152
|
-
const
|
|
153
|
-
return
|
|
249
|
+
const alignedClassName = computed(() => {
|
|
250
|
+
const baseClassName = getAlignPopupClassName(props.builtinPlacements, props.prefixCls, alignInfo.value, props.alignPoint);
|
|
251
|
+
return classNames(baseClassName, props?.getPopupClassNameFromAlign?.(alignInfo.value));
|
|
154
252
|
});
|
|
155
|
-
|
|
156
|
-
nativeElement:
|
|
157
|
-
popupElement:
|
|
158
|
-
forceAlign:
|
|
253
|
+
expose({
|
|
254
|
+
nativeElement: externalForwardRef,
|
|
255
|
+
popupElement: externalPopupRef,
|
|
256
|
+
forceAlign: triggerAlign
|
|
159
257
|
});
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
258
|
+
const targetWidth = shallowRef(0);
|
|
259
|
+
const targetHeight = shallowRef(0);
|
|
260
|
+
const syncTargetSize = () => {
|
|
261
|
+
if (props.stretch && targetEle.value) {
|
|
262
|
+
const rect = targetEle.value.getBoundingClientRect();
|
|
263
|
+
targetWidth.value = rect.width;
|
|
264
|
+
targetHeight.value = rect.height;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const onTargetResize = () => {
|
|
268
|
+
syncTargetSize();
|
|
269
|
+
triggerAlign();
|
|
270
|
+
};
|
|
271
|
+
const onVisibleChanged = (visible) => {
|
|
272
|
+
inMotion.value = false;
|
|
273
|
+
onAlign();
|
|
274
|
+
props?.afterOpenChange?.(visible);
|
|
275
|
+
props?.afterPopupVisibleChange?.(visible);
|
|
276
|
+
};
|
|
277
|
+
const onPrepare = () => {
|
|
278
|
+
return new Promise((resolve) => {
|
|
279
|
+
syncTargetSize();
|
|
280
|
+
motionPrepareResolve.value = resolve;
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
watch([motionPrepareResolve], () => {
|
|
284
|
+
if (motionPrepareResolve.value) {
|
|
285
|
+
onAlign();
|
|
286
|
+
motionPrepareResolve.value();
|
|
287
|
+
motionPrepareResolve.value = void 0;
|
|
164
288
|
}
|
|
165
|
-
}, Ve = () => {
|
|
166
|
-
se(), P();
|
|
167
|
-
}, Fe = (e) => {
|
|
168
|
-
y.value = !1, X(), n?.afterOpenChange?.(e), n?.afterPopupVisibleChange?.(e);
|
|
169
|
-
}, Be = () => new Promise((e) => {
|
|
170
|
-
se(), A.value = e;
|
|
171
|
-
});
|
|
172
|
-
b([A], () => {
|
|
173
|
-
A.value && (X(), A.value(), A.value = void 0);
|
|
174
289
|
});
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
(!
|
|
290
|
+
function wrapperAction(target, eventName, nextOpen, delay, callback, ignoreCheck) {
|
|
291
|
+
target[eventName] = (event, ...args) => {
|
|
292
|
+
if (!ignoreCheck || !ignoreCheck()) {
|
|
293
|
+
callback?.(event);
|
|
294
|
+
triggerOpen(nextOpen, delay);
|
|
295
|
+
}
|
|
296
|
+
originChildProps[eventName]?.(event, ...args);
|
|
178
297
|
};
|
|
179
298
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
299
|
+
const touchToShow = computed(() => showActions.value?.has("touch"));
|
|
300
|
+
const touchToHide = computed(() => hideActions.value?.has("touch"));
|
|
301
|
+
const touchedRef = shallowRef(false);
|
|
302
|
+
watchEffect(() => {
|
|
303
|
+
const nextCloneProps = {};
|
|
304
|
+
if (touchToShow.value || touchToHide.value) {
|
|
305
|
+
nextCloneProps.onTouchstart = (...args) => {
|
|
306
|
+
touchedRef.value = true;
|
|
307
|
+
if (openRef.value && touchToHide.value) {
|
|
308
|
+
triggerOpen(false);
|
|
309
|
+
} else if (!openRef.value && touchToShow.value) {
|
|
310
|
+
triggerOpen(true);
|
|
311
|
+
}
|
|
312
|
+
originChildProps.onTouchstart?.(...args);
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (clickToShow.value || clickToHide.value) {
|
|
316
|
+
nextCloneProps.onClick = (event, ...args) => {
|
|
317
|
+
if (openRef.value && clickToHide.value) {
|
|
318
|
+
triggerOpen(false);
|
|
319
|
+
} else if (!openRef.value && clickToShow.value) {
|
|
320
|
+
setMousePosByEvent(event);
|
|
321
|
+
triggerOpen(true);
|
|
322
|
+
}
|
|
323
|
+
originChildProps?.onClick?.(event, ...args);
|
|
324
|
+
touchedRef.value = false;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
baseActionProps.value = nextCloneProps;
|
|
188
328
|
});
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
329
|
+
const onPopupPointerDown = useWinClick(mergedOpen, computed(() => clickToHide.value || touchToHide.value), targetEle, popupEle, computed(() => props.mask), computed(() => props.maskClosable), inPopupOrChild, triggerOpen);
|
|
330
|
+
const hoverToShow = computed(() => showActions.value?.has("hover"));
|
|
331
|
+
const hoverToHide = computed(() => hideActions.value?.has("hover"));
|
|
332
|
+
let onPopupMouseEnter;
|
|
333
|
+
let onPopupMouseLeave;
|
|
334
|
+
const ignoreMouseTrigger = () => {
|
|
335
|
+
return touchedRef.value;
|
|
336
|
+
};
|
|
337
|
+
watchEffect(() => {
|
|
193
338
|
const {
|
|
194
|
-
mouseEnterDelay
|
|
195
|
-
mouseLeaveDelay
|
|
196
|
-
alignPoint
|
|
197
|
-
focusDelay
|
|
198
|
-
blurDelay
|
|
199
|
-
} =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
339
|
+
mouseEnterDelay,
|
|
340
|
+
mouseLeaveDelay,
|
|
341
|
+
alignPoint,
|
|
342
|
+
focusDelay,
|
|
343
|
+
blurDelay
|
|
344
|
+
} = props;
|
|
345
|
+
const nextHoverProps = {};
|
|
346
|
+
if (hoverToShow.value) {
|
|
347
|
+
const onMouseEnterCallback = (event) => {
|
|
348
|
+
setMousePosByEvent(event);
|
|
349
|
+
};
|
|
350
|
+
wrapperAction(nextHoverProps, "onMouseenter", true, mouseEnterDelay, onMouseEnterCallback, ignoreMouseTrigger);
|
|
351
|
+
wrapperAction(nextHoverProps, "onPointerenter", true, mouseEnterDelay, onMouseEnterCallback, ignoreMouseTrigger);
|
|
352
|
+
onPopupMouseEnter = (event) => {
|
|
353
|
+
if ((mergedOpen.value || inMotion.value) && popupEle?.value?.contains(event.target)) {
|
|
354
|
+
triggerOpen(true, mouseEnterDelay);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
if (alignPoint) {
|
|
358
|
+
nextHoverProps.onMouseMove = (event) => {
|
|
359
|
+
originChildProps.onMousemove?.(event);
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
} else {
|
|
363
|
+
onPopupMouseEnter = void 0;
|
|
364
|
+
}
|
|
365
|
+
if (hoverToHide.value) {
|
|
366
|
+
wrapperAction(nextHoverProps, "onMouseleave", false, mouseLeaveDelay, void 0, ignoreMouseTrigger);
|
|
367
|
+
wrapperAction(nextHoverProps, "onPointerleave", false, mouseLeaveDelay, void 0, ignoreMouseTrigger);
|
|
368
|
+
onPopupMouseLeave = (event) => {
|
|
369
|
+
const {
|
|
370
|
+
relatedTarget
|
|
371
|
+
} = event;
|
|
372
|
+
if (relatedTarget && inPopupOrChild(relatedTarget)) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
triggerOpen(false, mouseLeaveDelay);
|
|
376
|
+
};
|
|
377
|
+
} else {
|
|
378
|
+
onPopupMouseLeave = void 0;
|
|
379
|
+
}
|
|
380
|
+
if (showActions.value.has("focus")) {
|
|
381
|
+
wrapperAction(nextHoverProps, "onFocus", true, focusDelay);
|
|
382
|
+
}
|
|
383
|
+
if (hideActions.value.has("focus")) {
|
|
384
|
+
wrapperAction(nextHoverProps, "onBlur", false, blurDelay);
|
|
385
|
+
}
|
|
386
|
+
if (showActions.value.has("contextmenu")) {
|
|
387
|
+
nextHoverProps.onContextmenu = (event, ...args) => {
|
|
388
|
+
if (openRef.value && hideActions.value.has("contextmenu")) {
|
|
389
|
+
triggerOpen(false);
|
|
390
|
+
} else {
|
|
391
|
+
setMousePosByEvent(event);
|
|
392
|
+
triggerOpen(true);
|
|
393
|
+
}
|
|
394
|
+
event.preventDefault();
|
|
395
|
+
originChildProps.onContextmenu?.(event, ...args);
|
|
203
396
|
};
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}, a && (o.onMouseMove = (s) => {
|
|
207
|
-
g.onMousemove?.(s);
|
|
208
|
-
});
|
|
209
|
-
} else
|
|
210
|
-
E = void 0;
|
|
211
|
-
Ie.value ? (C(o, "onMouseleave", !1, t, void 0, O), C(o, "onPointerleave", !1, t, void 0, O), W = (f) => {
|
|
212
|
-
const {
|
|
213
|
-
relatedTarget: s
|
|
214
|
-
} = f;
|
|
215
|
-
s && ee(s) || d(!1, t);
|
|
216
|
-
}) : W = void 0, k.value.has("focus") && C(o, "onFocus", !0, m), h.value.has("focus") && C(o, "onBlur", !1, M), k.value.has("contextmenu") && (o.onContextmenu = (f, ...s) => {
|
|
217
|
-
v.value && h.value.has("contextmenu") ? d(!1) : (L(f), d(!0)), f.preventDefault(), g.onContextmenu?.(f, ...s);
|
|
218
|
-
}), Z.value = o;
|
|
397
|
+
}
|
|
398
|
+
hoverActionProps.value = nextHoverProps;
|
|
219
399
|
});
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
400
|
+
const rendedRef = shallowRef(false);
|
|
401
|
+
watchEffect(() => {
|
|
402
|
+
rendedRef.value ||= props.forceRender || mergedOpen.value || inMotion.value;
|
|
403
|
+
});
|
|
404
|
+
return () => {
|
|
405
|
+
const child = filterEmpty(slots?.default?.() ?? [])?.[0];
|
|
406
|
+
const mergedChildrenProps = {
|
|
407
|
+
...originChildProps,
|
|
408
|
+
...cloneProps.value
|
|
409
|
+
};
|
|
410
|
+
const passedProps = {};
|
|
411
|
+
const passedEventList = ["onContextmenu", "onClick", "onMousedown", "onTouchstart", "onMouseenter", "onMouseleave", "onFocus", "onBlur"];
|
|
412
|
+
passedEventList.forEach((eventName) => {
|
|
413
|
+
if (attrs[eventName]) {
|
|
414
|
+
passedProps[eventName] = (...args) => {
|
|
415
|
+
mergedChildrenProps[eventName]?.(...args);
|
|
416
|
+
attrs[eventName](...args);
|
|
417
|
+
};
|
|
418
|
+
}
|
|
232
419
|
});
|
|
233
|
-
const
|
|
234
|
-
x:
|
|
235
|
-
y:
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
...
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
default: () => [
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
420
|
+
const arrowPos = {
|
|
421
|
+
x: arrowX.value,
|
|
422
|
+
y: arrowY.value
|
|
423
|
+
};
|
|
424
|
+
const triggerNode = createVNode(child, {
|
|
425
|
+
...mergedChildrenProps,
|
|
426
|
+
...passedProps,
|
|
427
|
+
ref: setTargetRef
|
|
428
|
+
});
|
|
429
|
+
const {
|
|
430
|
+
unique,
|
|
431
|
+
prefixCls,
|
|
432
|
+
popup,
|
|
433
|
+
popupClassName,
|
|
434
|
+
popupStyle,
|
|
435
|
+
zIndex,
|
|
436
|
+
fresh,
|
|
437
|
+
onPopupClick,
|
|
438
|
+
mask,
|
|
439
|
+
popupMotion,
|
|
440
|
+
maskMotion,
|
|
441
|
+
forceRender,
|
|
442
|
+
getPopupContainer,
|
|
443
|
+
stretch,
|
|
444
|
+
mobile
|
|
445
|
+
} = props;
|
|
446
|
+
return createVNode(Fragment, null, [createVNode(ResizeObserver, {
|
|
447
|
+
"disabled": !mergedOpen.value,
|
|
448
|
+
"onResize": onTargetResize
|
|
449
|
+
}, _isSlot(triggerNode) ? triggerNode : {
|
|
450
|
+
default: () => [triggerNode]
|
|
451
|
+
}), rendedRef.value && targetEle.value && (!uniqueContext || !unique) && createVNode(TriggerContextProvider, context.value, {
|
|
452
|
+
default: () => [createVNode(Popup, {
|
|
453
|
+
"portal": PortalComponent,
|
|
454
|
+
"ref": setPopupRef,
|
|
455
|
+
"prefixCls": prefixCls,
|
|
456
|
+
"popup": popup,
|
|
457
|
+
"className": classNames(popupClassName, !isMobile.value && alignedClassName.value),
|
|
458
|
+
"style": popupStyle,
|
|
459
|
+
"target": targetEle.value,
|
|
460
|
+
"onMouseEnter": onPopupMouseEnter,
|
|
461
|
+
"onMouseLeave": onPopupMouseLeave,
|
|
462
|
+
"onPointerEnter": onPopupMouseEnter,
|
|
463
|
+
"zIndex": zIndex,
|
|
464
|
+
"open": mergedOpen.value,
|
|
465
|
+
"keepDom": inMotion.value,
|
|
466
|
+
"fresh": fresh,
|
|
467
|
+
"onClick": onPopupClick,
|
|
468
|
+
"onPointerDownCapture": onPopupPointerDown,
|
|
469
|
+
"mask": mask,
|
|
470
|
+
"motion": popupMotion,
|
|
471
|
+
"maskMotion": maskMotion,
|
|
472
|
+
"onVisibleChanged": onVisibleChanged,
|
|
473
|
+
"onPrepare": onPrepare,
|
|
474
|
+
"forceRender": forceRender,
|
|
475
|
+
"autoDestroy": mergedAutoDestroy.value,
|
|
476
|
+
"getPopupContainer": getPopupContainer,
|
|
477
|
+
"align": alignInfo.value,
|
|
478
|
+
"arrow": innerArrow.value,
|
|
479
|
+
"arrowPos": arrowPos,
|
|
480
|
+
"ready": ready.value,
|
|
481
|
+
"offsetX": offsetX.value,
|
|
482
|
+
"offsetY": offsetY.value,
|
|
483
|
+
"offsetR": offsetR.value,
|
|
484
|
+
"offsetB": offsetB.value,
|
|
485
|
+
"onAlign": triggerAlign,
|
|
486
|
+
"stretch": stretch,
|
|
487
|
+
"targetWidth": targetWidth.value / scaleX.value,
|
|
488
|
+
"targetHeight": targetHeight.value / scaleY.value,
|
|
489
|
+
"mobile": mobile
|
|
301
490
|
}, null)]
|
|
302
491
|
})]);
|
|
303
492
|
};
|
|
304
493
|
}, {
|
|
305
|
-
props: /* @__PURE__ */
|
|
494
|
+
props: /* @__PURE__ */ mergeDefaults({
|
|
306
495
|
action: {
|
|
307
496
|
type: [String, Array],
|
|
308
|
-
required:
|
|
497
|
+
required: false,
|
|
309
498
|
default: void 0
|
|
310
499
|
},
|
|
311
500
|
showAction: {
|
|
312
501
|
type: Array,
|
|
313
|
-
required:
|
|
502
|
+
required: false,
|
|
314
503
|
default: void 0
|
|
315
504
|
},
|
|
316
505
|
hideAction: {
|
|
317
506
|
type: Array,
|
|
318
|
-
required:
|
|
507
|
+
required: false,
|
|
319
508
|
default: void 0
|
|
320
509
|
},
|
|
321
510
|
prefixCls: {
|
|
322
511
|
type: String,
|
|
323
|
-
required:
|
|
512
|
+
required: false,
|
|
324
513
|
default: void 0
|
|
325
514
|
},
|
|
326
515
|
zIndex: {
|
|
327
516
|
type: Number,
|
|
328
|
-
required:
|
|
517
|
+
required: false,
|
|
329
518
|
default: void 0
|
|
330
519
|
},
|
|
331
520
|
onPopupAlign: {
|
|
332
521
|
type: Function,
|
|
333
|
-
required:
|
|
522
|
+
required: false,
|
|
334
523
|
default: void 0
|
|
335
524
|
},
|
|
336
525
|
stretch: {
|
|
337
526
|
type: String,
|
|
338
|
-
required:
|
|
527
|
+
required: false,
|
|
339
528
|
default: void 0
|
|
340
529
|
},
|
|
341
530
|
popupVisible: {
|
|
342
531
|
type: Boolean,
|
|
343
|
-
required:
|
|
532
|
+
required: false,
|
|
344
533
|
default: void 0
|
|
345
534
|
},
|
|
346
535
|
defaultPopupVisible: {
|
|
347
536
|
type: Boolean,
|
|
348
|
-
required:
|
|
537
|
+
required: false,
|
|
349
538
|
default: void 0
|
|
350
539
|
},
|
|
351
540
|
onOpenChange: {
|
|
352
541
|
type: Function,
|
|
353
|
-
required:
|
|
542
|
+
required: false,
|
|
354
543
|
default: void 0
|
|
355
544
|
},
|
|
356
545
|
afterOpenChange: {
|
|
357
546
|
type: Function,
|
|
358
|
-
required:
|
|
547
|
+
required: false,
|
|
359
548
|
default: void 0
|
|
360
549
|
},
|
|
361
550
|
onPopupVisibleChange: {
|
|
362
551
|
type: Function,
|
|
363
|
-
required:
|
|
552
|
+
required: false,
|
|
364
553
|
default: void 0
|
|
365
554
|
},
|
|
366
555
|
afterPopupVisibleChange: {
|
|
367
556
|
type: Function,
|
|
368
|
-
required:
|
|
557
|
+
required: false,
|
|
369
558
|
default: void 0
|
|
370
559
|
},
|
|
371
560
|
getPopupContainer: {
|
|
372
561
|
type: Function,
|
|
373
|
-
required:
|
|
562
|
+
required: false,
|
|
374
563
|
default: void 0
|
|
375
564
|
},
|
|
376
565
|
forceRender: {
|
|
377
566
|
type: Boolean,
|
|
378
|
-
required:
|
|
567
|
+
required: false,
|
|
379
568
|
default: void 0
|
|
380
569
|
},
|
|
381
570
|
autoDestroy: {
|
|
382
571
|
type: Boolean,
|
|
383
|
-
required:
|
|
572
|
+
required: false,
|
|
384
573
|
default: void 0
|
|
385
574
|
},
|
|
386
575
|
mask: {
|
|
387
576
|
type: Boolean,
|
|
388
|
-
required:
|
|
577
|
+
required: false,
|
|
389
578
|
default: void 0
|
|
390
579
|
},
|
|
391
580
|
maskClosable: {
|
|
392
581
|
type: Boolean,
|
|
393
|
-
required:
|
|
582
|
+
required: false,
|
|
394
583
|
default: void 0
|
|
395
584
|
},
|
|
396
585
|
popupMotion: {
|
|
397
586
|
type: Object,
|
|
398
|
-
required:
|
|
587
|
+
required: false,
|
|
399
588
|
default: void 0
|
|
400
589
|
},
|
|
401
590
|
maskMotion: {
|
|
402
591
|
type: Object,
|
|
403
|
-
required:
|
|
592
|
+
required: false,
|
|
404
593
|
default: void 0
|
|
405
594
|
},
|
|
406
595
|
mouseEnterDelay: {
|
|
407
596
|
type: Number,
|
|
408
|
-
required:
|
|
597
|
+
required: false,
|
|
409
598
|
default: void 0
|
|
410
599
|
},
|
|
411
600
|
mouseLeaveDelay: {
|
|
412
601
|
type: Number,
|
|
413
|
-
required:
|
|
602
|
+
required: false,
|
|
414
603
|
default: void 0
|
|
415
604
|
},
|
|
416
605
|
focusDelay: {
|
|
417
606
|
type: Number,
|
|
418
|
-
required:
|
|
607
|
+
required: false,
|
|
419
608
|
default: void 0
|
|
420
609
|
},
|
|
421
610
|
blurDelay: {
|
|
422
611
|
type: Number,
|
|
423
|
-
required:
|
|
612
|
+
required: false,
|
|
424
613
|
default: void 0
|
|
425
614
|
},
|
|
426
615
|
popup: {
|
|
427
616
|
type: [String, Number, null, Array, Function],
|
|
428
|
-
required:
|
|
429
|
-
skipCheck:
|
|
617
|
+
required: true,
|
|
618
|
+
skipCheck: true,
|
|
430
619
|
default: void 0
|
|
431
620
|
},
|
|
432
621
|
popupPlacement: {
|
|
433
622
|
type: String,
|
|
434
|
-
required:
|
|
623
|
+
required: false,
|
|
435
624
|
default: void 0
|
|
436
625
|
},
|
|
437
626
|
builtinPlacements: {
|
|
438
627
|
type: Object,
|
|
439
|
-
required:
|
|
628
|
+
required: false,
|
|
440
629
|
default: void 0
|
|
441
630
|
},
|
|
442
631
|
popupAlign: {
|
|
443
632
|
type: Object,
|
|
444
|
-
required:
|
|
633
|
+
required: false,
|
|
445
634
|
default: void 0
|
|
446
635
|
},
|
|
447
636
|
popupClassName: {
|
|
448
637
|
type: String,
|
|
449
|
-
required:
|
|
638
|
+
required: false,
|
|
450
639
|
default: void 0
|
|
451
640
|
},
|
|
452
641
|
uniqueContainerClassName: {
|
|
453
642
|
type: String,
|
|
454
|
-
required:
|
|
643
|
+
required: false,
|
|
455
644
|
default: void 0
|
|
456
645
|
},
|
|
457
646
|
uniqueContainerStyle: {
|
|
458
647
|
type: null,
|
|
459
|
-
required:
|
|
648
|
+
required: false,
|
|
460
649
|
default: void 0
|
|
461
650
|
},
|
|
462
651
|
popupStyle: {
|
|
463
652
|
type: null,
|
|
464
|
-
required:
|
|
653
|
+
required: false,
|
|
465
654
|
default: void 0
|
|
466
655
|
},
|
|
467
656
|
getPopupClassNameFromAlign: {
|
|
468
657
|
type: Function,
|
|
469
|
-
required:
|
|
658
|
+
required: false,
|
|
470
659
|
default: void 0
|
|
471
660
|
},
|
|
472
661
|
onPopupClick: {
|
|
473
662
|
type: Function,
|
|
474
|
-
required:
|
|
663
|
+
required: false,
|
|
475
664
|
default: void 0
|
|
476
665
|
},
|
|
477
666
|
alignPoint: {
|
|
478
667
|
type: Boolean,
|
|
479
|
-
required:
|
|
668
|
+
required: false,
|
|
480
669
|
default: void 0
|
|
481
670
|
},
|
|
482
671
|
fresh: {
|
|
483
672
|
type: Boolean,
|
|
484
|
-
required:
|
|
673
|
+
required: false,
|
|
485
674
|
default: void 0
|
|
486
675
|
},
|
|
487
676
|
unique: {
|
|
488
677
|
type: Boolean,
|
|
489
|
-
required:
|
|
678
|
+
required: false,
|
|
490
679
|
default: void 0
|
|
491
680
|
},
|
|
492
681
|
arrow: {
|
|
493
682
|
type: [Boolean, Object],
|
|
494
|
-
required:
|
|
683
|
+
required: false,
|
|
495
684
|
default: void 0
|
|
496
685
|
},
|
|
497
686
|
mobile: {
|
|
498
687
|
type: Object,
|
|
499
|
-
required:
|
|
688
|
+
required: false,
|
|
500
689
|
default: void 0
|
|
501
690
|
}
|
|
502
|
-
},
|
|
691
|
+
}, defaults)
|
|
503
692
|
});
|
|
504
693
|
}
|
|
505
|
-
const
|
|
694
|
+
const Trigger = generateTrigger(Portal);
|
|
506
695
|
export {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
696
|
+
Trigger,
|
|
697
|
+
default2 as UniqueProvider,
|
|
698
|
+
Trigger as default,
|
|
699
|
+
generateTrigger
|
|
511
700
|
};
|