@v-c/trigger 1.0.0 → 1.0.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/Popup/index.cjs +6 -6
- package/dist/Popup/index.js +6 -6
- package/dist/UniqueProvider/UniqueContainer.cjs +3 -3
- package/dist/UniqueProvider/UniqueContainer.js +4 -4
- package/dist/UniqueProvider/index.cjs +12 -3
- package/dist/UniqueProvider/index.js +12 -3
- package/dist/UniqueProvider/useTargetState.cjs +0 -1
- package/dist/UniqueProvider/useTargetState.js +0 -1
- package/dist/hooks/useAlign.cjs +26 -64
- package/dist/hooks/useAlign.d.ts +1 -1
- package/dist/hooks/useAlign.js +26 -64
- package/dist/index.cjs +10 -9
- package/dist/index.js +10 -9
- package/package.json +4 -4
package/dist/Popup/index.cjs
CHANGED
|
@@ -72,7 +72,11 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
|
|
|
72
72
|
},
|
|
73
73
|
onAfterEnter: (element) => {
|
|
74
74
|
baseTransitionProps?.onAfterEnter?.(element);
|
|
75
|
-
|
|
75
|
+
requestAnimationFrame(() => {
|
|
76
|
+
requestAnimationFrame(() => {
|
|
77
|
+
onVisibleChanged?.(true);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
76
80
|
},
|
|
77
81
|
onAfterLeave: (element) => {
|
|
78
82
|
baseTransitionProps.onAfterLeave?.(element);
|
|
@@ -137,7 +141,7 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
|
|
|
137
141
|
default: void 0
|
|
138
142
|
},
|
|
139
143
|
style: {
|
|
140
|
-
type:
|
|
144
|
+
type: Object,
|
|
141
145
|
required: false,
|
|
142
146
|
default: void 0
|
|
143
147
|
},
|
|
@@ -148,7 +152,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
|
|
|
148
152
|
default: void 0
|
|
149
153
|
},
|
|
150
154
|
target: {
|
|
151
|
-
type: null,
|
|
152
155
|
required: true,
|
|
153
156
|
default: void 0
|
|
154
157
|
},
|
|
@@ -248,7 +251,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
|
|
|
248
251
|
default: void 0
|
|
249
252
|
},
|
|
250
253
|
portal: {
|
|
251
|
-
type: null,
|
|
252
254
|
required: true,
|
|
253
255
|
default: void 0
|
|
254
256
|
},
|
|
@@ -278,7 +280,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
|
|
|
278
280
|
default: void 0
|
|
279
281
|
},
|
|
280
282
|
onAlign: {
|
|
281
|
-
type: null,
|
|
282
283
|
required: true,
|
|
283
284
|
default: void 0
|
|
284
285
|
},
|
|
@@ -303,7 +304,6 @@ var Popup = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, slots, exp
|
|
|
303
304
|
default: void 0
|
|
304
305
|
},
|
|
305
306
|
onResize: {
|
|
306
|
-
type: null,
|
|
307
307
|
required: false,
|
|
308
308
|
default: void 0
|
|
309
309
|
},
|
package/dist/Popup/index.js
CHANGED
|
@@ -69,7 +69,11 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
|
|
|
69
69
|
},
|
|
70
70
|
onAfterEnter: (element) => {
|
|
71
71
|
baseTransitionProps?.onAfterEnter?.(element);
|
|
72
|
-
|
|
72
|
+
requestAnimationFrame(() => {
|
|
73
|
+
requestAnimationFrame(() => {
|
|
74
|
+
onVisibleChanged?.(true);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
73
77
|
},
|
|
74
78
|
onAfterLeave: (element) => {
|
|
75
79
|
baseTransitionProps.onAfterLeave?.(element);
|
|
@@ -134,7 +138,7 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
|
|
|
134
138
|
default: void 0
|
|
135
139
|
},
|
|
136
140
|
style: {
|
|
137
|
-
type:
|
|
141
|
+
type: Object,
|
|
138
142
|
required: false,
|
|
139
143
|
default: void 0
|
|
140
144
|
},
|
|
@@ -145,7 +149,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
|
|
|
145
149
|
default: void 0
|
|
146
150
|
},
|
|
147
151
|
target: {
|
|
148
|
-
type: null,
|
|
149
152
|
required: true,
|
|
150
153
|
default: void 0
|
|
151
154
|
},
|
|
@@ -245,7 +248,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
|
|
|
245
248
|
default: void 0
|
|
246
249
|
},
|
|
247
250
|
portal: {
|
|
248
|
-
type: null,
|
|
249
251
|
required: true,
|
|
250
252
|
default: void 0
|
|
251
253
|
},
|
|
@@ -275,7 +277,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
|
|
|
275
277
|
default: void 0
|
|
276
278
|
},
|
|
277
279
|
onAlign: {
|
|
278
|
-
type: null,
|
|
279
280
|
required: true,
|
|
280
281
|
default: void 0
|
|
281
282
|
},
|
|
@@ -300,7 +301,6 @@ var Popup_default = /* @__PURE__ */ defineComponent((props, { attrs, slots, expo
|
|
|
300
301
|
default: void 0
|
|
301
302
|
},
|
|
302
303
|
onResize: {
|
|
303
|
-
type: null,
|
|
304
304
|
required: false,
|
|
305
305
|
default: void 0
|
|
306
306
|
},
|
|
@@ -12,8 +12,7 @@ var UniqueContainer = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
|
|
|
12
12
|
(0, vue.watchEffect)(() => {
|
|
13
13
|
if (ready.value) cachedOffsetStyleRef.value = offsetStyle.value;
|
|
14
14
|
});
|
|
15
|
-
(0, vue.watch)(open,
|
|
16
|
-
await (0, vue.nextTick)();
|
|
15
|
+
(0, vue.watch)(open, (nextVisible) => {
|
|
17
16
|
if (nextVisible) motionVisible.value = true;
|
|
18
17
|
});
|
|
19
18
|
return () => {
|
|
@@ -36,6 +35,7 @@ var UniqueContainer = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
|
|
|
36
35
|
},
|
|
37
36
|
onAfterLeave: (element) => {
|
|
38
37
|
motionVisible.value = false;
|
|
38
|
+
cachedOffsetStyleRef.value = {};
|
|
39
39
|
baseTransitionProps.onAfterLeave?.(element);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
@@ -124,7 +124,7 @@ var UniqueContainer = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
|
|
|
124
124
|
default: void 0
|
|
125
125
|
},
|
|
126
126
|
uniqueContainerStyle: {
|
|
127
|
-
type:
|
|
127
|
+
type: Object,
|
|
128
128
|
required: false,
|
|
129
129
|
default: void 0
|
|
130
130
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import useOffsetStyle from "../hooks/useOffsetStyle.js";
|
|
2
|
-
import { Transition, createVNode, defineComponent,
|
|
2
|
+
import { Transition, createVNode, defineComponent, shallowRef, vShow, watch, watchEffect, withDirectives } from "vue";
|
|
3
3
|
import { toPropsRefs } from "@v-c/util/dist/props-util";
|
|
4
4
|
import { getTransitionProps } from "@v-c/util/dist/utils/transition";
|
|
5
5
|
var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
|
|
@@ -10,8 +10,7 @@ var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
10
10
|
watchEffect(() => {
|
|
11
11
|
if (ready.value) cachedOffsetStyleRef.value = offsetStyle.value;
|
|
12
12
|
});
|
|
13
|
-
watch(open,
|
|
14
|
-
await nextTick();
|
|
13
|
+
watch(open, (nextVisible) => {
|
|
15
14
|
if (nextVisible) motionVisible.value = true;
|
|
16
15
|
});
|
|
17
16
|
return () => {
|
|
@@ -34,6 +33,7 @@ var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
34
33
|
},
|
|
35
34
|
onAfterLeave: (element) => {
|
|
36
35
|
motionVisible.value = false;
|
|
36
|
+
cachedOffsetStyleRef.value = {};
|
|
37
37
|
baseTransitionProps.onAfterLeave?.(element);
|
|
38
38
|
}
|
|
39
39
|
};
|
|
@@ -122,7 +122,7 @@ var UniqueContainer_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
122
122
|
default: void 0
|
|
123
123
|
},
|
|
124
124
|
uniqueContainerStyle: {
|
|
125
|
-
type:
|
|
125
|
+
type: Object,
|
|
126
126
|
required: false,
|
|
127
127
|
default: void 0
|
|
128
128
|
}
|
|
@@ -55,10 +55,19 @@ var UniqueProvider = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots })
|
|
|
55
55
|
trigger(false);
|
|
56
56
|
}, delay);
|
|
57
57
|
};
|
|
58
|
+
const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = require_useAlign.default(open, popupEle, (0, vue.computed)(() => mergedOptions.value?.target), (0, vue.computed)(() => mergedOptions.value?.popupPlacement), (0, vue.computed)(() => mergedOptions.value?.builtinPlacements || {}), (0, vue.computed)(() => mergedOptions.value?.popupAlign), void 0, (0, vue.ref)(false));
|
|
59
|
+
const inMotion = (0, vue.shallowRef)(false);
|
|
60
|
+
(0, vue.watch)(open, () => {
|
|
61
|
+
if (open.value) inMotion.value = true;
|
|
62
|
+
});
|
|
63
|
+
const triggerAlign = () => {
|
|
64
|
+
if (!inMotion.value) onAlign();
|
|
65
|
+
};
|
|
58
66
|
const onVisibleChanged = (visible) => {
|
|
59
67
|
onTargetVisibleChanged(visible);
|
|
68
|
+
inMotion.value = false;
|
|
69
|
+
onAlign();
|
|
60
70
|
};
|
|
61
|
-
const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = require_useAlign.default(open, popupEle, (0, vue.computed)(() => mergedOptions.value?.target), (0, vue.computed)(() => mergedOptions.value?.popupPlacement), (0, vue.computed)(() => mergedOptions.value?.builtinPlacements || {}), (0, vue.computed)(() => mergedOptions.value?.popupAlign), void 0, (0, vue.ref)(false));
|
|
62
71
|
const alignedClassName = (0, vue.computed)(() => {
|
|
63
72
|
if (!mergedOptions.value) return "";
|
|
64
73
|
return (0, __v_c_util.classNames)(require_util.getAlignPopupClassName(mergedOptions.value?.builtinPlacements || {}, mergedOptions.value.prefixCls || "", alignInfo.value, false), mergedOptions.value?.getPopupClassNameFromAlign?.(alignInfo.value));
|
|
@@ -69,7 +78,7 @@ var UniqueProvider = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots })
|
|
|
69
78
|
};
|
|
70
79
|
(0, vue.watch)(() => mergedOptions.value?.target, () => {
|
|
71
80
|
onAlign();
|
|
72
|
-
}
|
|
81
|
+
});
|
|
73
82
|
const onPrepare = () => {
|
|
74
83
|
onAlign();
|
|
75
84
|
return Promise.resolve();
|
|
@@ -103,7 +112,7 @@ var UniqueProvider = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots })
|
|
|
103
112
|
"offsetY": offsetY.value,
|
|
104
113
|
"offsetR": offsetR.value,
|
|
105
114
|
"offsetB": offsetB.value,
|
|
106
|
-
"onAlign":
|
|
115
|
+
"onAlign": triggerAlign,
|
|
107
116
|
"onPrepare": onPrepare,
|
|
108
117
|
"onResize": (size) => {
|
|
109
118
|
popupSize.value = {
|
|
@@ -52,10 +52,19 @@ var UniqueProvider_default = /* @__PURE__ */ defineComponent((props, { slots })
|
|
|
52
52
|
trigger(false);
|
|
53
53
|
}, delay);
|
|
54
54
|
};
|
|
55
|
+
const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = useAlign(open, popupEle, computed(() => mergedOptions.value?.target), computed(() => mergedOptions.value?.popupPlacement), computed(() => mergedOptions.value?.builtinPlacements || {}), computed(() => mergedOptions.value?.popupAlign), void 0, ref(false));
|
|
56
|
+
const inMotion = shallowRef(false);
|
|
57
|
+
watch(open, () => {
|
|
58
|
+
if (open.value) inMotion.value = true;
|
|
59
|
+
});
|
|
60
|
+
const triggerAlign = () => {
|
|
61
|
+
if (!inMotion.value) onAlign();
|
|
62
|
+
};
|
|
55
63
|
const onVisibleChanged = (visible) => {
|
|
56
64
|
onTargetVisibleChanged(visible);
|
|
65
|
+
inMotion.value = false;
|
|
66
|
+
onAlign();
|
|
57
67
|
};
|
|
58
|
-
const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, , , alignInfo, onAlign] = useAlign(open, popupEle, computed(() => mergedOptions.value?.target), computed(() => mergedOptions.value?.popupPlacement), computed(() => mergedOptions.value?.builtinPlacements || {}), computed(() => mergedOptions.value?.popupAlign), void 0, ref(false));
|
|
59
68
|
const alignedClassName = computed(() => {
|
|
60
69
|
if (!mergedOptions.value) return "";
|
|
61
70
|
return classNames(getAlignPopupClassName(mergedOptions.value?.builtinPlacements || {}, mergedOptions.value.prefixCls || "", alignInfo.value, false), mergedOptions.value?.getPopupClassNameFromAlign?.(alignInfo.value));
|
|
@@ -66,7 +75,7 @@ var UniqueProvider_default = /* @__PURE__ */ defineComponent((props, { slots })
|
|
|
66
75
|
};
|
|
67
76
|
watch(() => mergedOptions.value?.target, () => {
|
|
68
77
|
onAlign();
|
|
69
|
-
}
|
|
78
|
+
});
|
|
70
79
|
const onPrepare = () => {
|
|
71
80
|
onAlign();
|
|
72
81
|
return Promise.resolve();
|
|
@@ -100,7 +109,7 @@ var UniqueProvider_default = /* @__PURE__ */ defineComponent((props, { slots })
|
|
|
100
109
|
"offsetY": offsetY.value,
|
|
101
110
|
"offsetR": offsetR.value,
|
|
102
111
|
"offsetB": offsetB.value,
|
|
103
|
-
"onAlign":
|
|
112
|
+
"onAlign": triggerAlign,
|
|
104
113
|
"onPrepare": onPrepare,
|
|
105
114
|
"onResize": (size) => {
|
|
106
115
|
popupSize.value = {
|
|
@@ -11,7 +11,6 @@ function useTargetState() {
|
|
|
11
11
|
if (nextOptions === false) {
|
|
12
12
|
pendingOptionsRef.value = null;
|
|
13
13
|
open.value = false;
|
|
14
|
-
isAnimating.value = false;
|
|
15
14
|
} else if (isAnimating.value && wasOpen) pendingOptionsRef.value = nextOptions;
|
|
16
15
|
else {
|
|
17
16
|
open.value = true;
|
package/dist/hooks/useAlign.cjs
CHANGED
|
@@ -5,7 +5,6 @@ let vue = require("vue");
|
|
|
5
5
|
let __v_c_util_dist_Dom_findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
6
6
|
let __v_c_util_dist_Dom_isVisible = require("@v-c/util/dist/Dom/isVisible");
|
|
7
7
|
__v_c_util_dist_Dom_isVisible = require_rolldown_runtime.__toESM(__v_c_util_dist_Dom_isVisible);
|
|
8
|
-
let __v_c_util_dist_raf = require("@v-c/util/dist/raf");
|
|
9
8
|
function getUnitOffset(size, offset = 0) {
|
|
10
9
|
const offsetStr = `${offset}`;
|
|
11
10
|
const cells = offsetStr.match(/^(.*)\%$/);
|
|
@@ -47,46 +46,6 @@ function reversePoints(points, index) {
|
|
|
47
46
|
return point;
|
|
48
47
|
}).join("");
|
|
49
48
|
}
|
|
50
|
-
function parseOriginValue(value, size, axis) {
|
|
51
|
-
const fallback = size / 2;
|
|
52
|
-
if (!value) return fallback;
|
|
53
|
-
const val = value.trim();
|
|
54
|
-
if (!val) return fallback;
|
|
55
|
-
if (val.endsWith("%")) return size * (parseFloat(val) / 100);
|
|
56
|
-
if (val.endsWith("px")) return parseFloat(val);
|
|
57
|
-
if (val === "center") return fallback;
|
|
58
|
-
if (axis === "x") {
|
|
59
|
-
if (val === "left") return 0;
|
|
60
|
-
if (val === "right") return size;
|
|
61
|
-
} else if (axis === "y") {
|
|
62
|
-
if (val === "top") return 0;
|
|
63
|
-
if (val === "bottom") return size;
|
|
64
|
-
}
|
|
65
|
-
const num = parseFloat(val);
|
|
66
|
-
return Number.isNaN(num) ? fallback : num;
|
|
67
|
-
}
|
|
68
|
-
function getTransformOriginPoint(origin, width, height) {
|
|
69
|
-
const [originX = "50%", originY = "50%"] = origin?.split(/\s+/).filter(Boolean) ?? [];
|
|
70
|
-
return [parseOriginValue(originX, width, "x"), parseOriginValue(originY, height, "y")];
|
|
71
|
-
}
|
|
72
|
-
function normalizeRect(rect, scaleX, scaleY, originX, originY) {
|
|
73
|
-
const rawX = rect.x ?? rect.left;
|
|
74
|
-
const rawY = rect.y ?? rect.top;
|
|
75
|
-
const width = rect.width / scaleX;
|
|
76
|
-
const height = rect.height / scaleY;
|
|
77
|
-
const x = rawX - (1 - scaleX) * originX;
|
|
78
|
-
const y = rawY - (1 - scaleY) * originY;
|
|
79
|
-
return {
|
|
80
|
-
x,
|
|
81
|
-
y,
|
|
82
|
-
width,
|
|
83
|
-
height,
|
|
84
|
-
left: x,
|
|
85
|
-
top: y,
|
|
86
|
-
right: x + width,
|
|
87
|
-
bottom: y + height
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
49
|
function shouldSwitchPlacement(isOverflow, isVisibleFirst, newVisibleArea, originVisibleArea, newRecommendArea, originRecommendArea) {
|
|
91
50
|
if (isOverflow) return newVisibleArea > originVisibleArea || newVisibleArea === originVisibleArea && (!isVisibleFirst || newRecommendArea >= originRecommendArea);
|
|
92
51
|
return newVisibleArea > originVisibleArea || isVisibleFirst && newVisibleArea === originVisibleArea && newRecommendArea > originRecommendArea;
|
|
@@ -113,7 +72,9 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
113
72
|
const resetFlipCache = () => {
|
|
114
73
|
prevFlipRef.value = {};
|
|
115
74
|
};
|
|
116
|
-
|
|
75
|
+
let cacheTargetRect = null;
|
|
76
|
+
const _onAlign = (cache = false) => {
|
|
77
|
+
if (cache && !cacheTargetRect) return;
|
|
117
78
|
if (popupEle.value && target.value && open.value && !mobile?.value) {
|
|
118
79
|
const popupElement = popupEle.value;
|
|
119
80
|
const doc = popupElement.ownerDocument;
|
|
@@ -148,7 +109,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
148
109
|
height: 0
|
|
149
110
|
};
|
|
150
111
|
else {
|
|
151
|
-
const
|
|
112
|
+
const targetRectInfo = target.value.getBoundingClientRect();
|
|
113
|
+
const rect = cache ? Object.assign(targetRectInfo, cacheTargetRect ?? {}) : targetRectInfo;
|
|
114
|
+
if (!cache) cacheTargetRect = {
|
|
115
|
+
width: rect.width,
|
|
116
|
+
height: rect.height
|
|
117
|
+
};
|
|
152
118
|
rect.x = rect.x ?? rect.left;
|
|
153
119
|
rect.y = rect.y ?? rect.top;
|
|
154
120
|
targetRect = {
|
|
@@ -194,20 +160,16 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
194
160
|
popupElement.style.bottom = originBottom;
|
|
195
161
|
popupElement.style.overflow = originOverflow;
|
|
196
162
|
popupElement.parentElement?.removeChild(placeholderElement);
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
const safeBaseWidth = baseWidth || rawPopupRect.width || 1;
|
|
202
|
-
const safeBaseHeight = baseHeight || rawPopupRect.height || 1;
|
|
203
|
-
const scaleX$1 = require_util.toNum(Math.round(rawPopupRect.width / safeBaseWidth * 1e3) / 1e3);
|
|
204
|
-
const scaleY$1 = require_util.toNum(Math.round(rawPopupRect.height / safeBaseHeight * 1e3) / 1e3);
|
|
205
|
-
if (scaleX$1 === 0 || scaleY$1 === 0 || (0, __v_c_util_dist_Dom_findDOMNode.isDOM)(target) && !(0, __v_c_util_dist_Dom_isVisible.default)(target)) return;
|
|
206
|
-
const [originX, originY] = getTransformOriginPoint(popupComputedStyle.transformOrigin, safeBaseWidth, safeBaseHeight);
|
|
207
|
-
const popupRect = normalizeRect(rawPopupRect, scaleX$1, scaleY$1, originX, originY);
|
|
208
|
-
const popupMirrorRect = normalizeRect(rawPopupMirrorRect, scaleX$1, scaleY$1, originX, originY);
|
|
163
|
+
const popupRect = rawPopupRect;
|
|
164
|
+
popupRect.x = popupRect.x ?? popupRect.left;
|
|
165
|
+
popupRect.y = popupRect.y ?? popupRect.top;
|
|
166
|
+
const { height, width } = popupComputedStyle;
|
|
209
167
|
const popupHeight = popupRect.height;
|
|
210
168
|
const popupWidth = popupRect.width;
|
|
169
|
+
const popupMirrorRect = rawPopupMirrorRect;
|
|
170
|
+
const scaleX$1 = require_util.toNum(Math.round(popupWidth / parseFloat(width) * 1e3) / 1e3);
|
|
171
|
+
const scaleY$1 = require_util.toNum(Math.round(popupHeight / parseFloat(height) * 1e3) / 1e3);
|
|
172
|
+
if (scaleX$1 === 0 || scaleY$1 === 0 || (0, __v_c_util_dist_Dom_findDOMNode.isDOM)(target) && !(0, __v_c_util_dist_Dom_isVisible.default)(target)) return;
|
|
211
173
|
const { offset, targetOffset } = placementInfo;
|
|
212
174
|
let [popupOffsetX, popupOffsetY] = getNumberOffset(popupRect, offset);
|
|
213
175
|
const [targetOffsetX, targetOffsetY] = getNumberOffset(targetRect, targetOffset);
|
|
@@ -352,12 +314,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
352
314
|
}
|
|
353
315
|
const nextOffsetInfo = {
|
|
354
316
|
ready: true,
|
|
355
|
-
offsetX: nextOffsetX,
|
|
356
|
-
offsetY: nextOffsetY,
|
|
357
|
-
offsetR: offsetX4Right,
|
|
358
|
-
offsetB: offsetY4Bottom,
|
|
359
|
-
arrowX: nextArrowX,
|
|
360
|
-
arrowY: nextArrowY,
|
|
317
|
+
offsetX: nextOffsetX / scaleX$1,
|
|
318
|
+
offsetY: nextOffsetY / scaleY$1,
|
|
319
|
+
offsetR: offsetX4Right / scaleX$1,
|
|
320
|
+
offsetB: offsetY4Bottom / scaleY$1,
|
|
321
|
+
arrowX: nextArrowX / scaleX$1,
|
|
322
|
+
arrowY: nextArrowY / scaleY$1,
|
|
361
323
|
scaleX: scaleX$1,
|
|
362
324
|
scaleY: scaleY$1,
|
|
363
325
|
align: nextAlignInfo
|
|
@@ -365,12 +327,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
365
327
|
Object.assign(offsetInfo, nextOffsetInfo);
|
|
366
328
|
}
|
|
367
329
|
};
|
|
368
|
-
const onAlign =
|
|
369
|
-
const triggerAlign = () => {
|
|
330
|
+
const onAlign = _onAlign;
|
|
331
|
+
const triggerAlign = (cache) => {
|
|
370
332
|
alignCountRef.value += 1;
|
|
371
333
|
const id = alignCountRef.value;
|
|
372
334
|
Promise.resolve().then(() => {
|
|
373
|
-
if (alignCountRef.value === id) onAlign();
|
|
335
|
+
if (alignCountRef.value === id) onAlign(cache);
|
|
374
336
|
});
|
|
375
337
|
};
|
|
376
338
|
(0, vue.watch)(popupEle, async (ele) => {
|
package/dist/hooks/useAlign.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
2
|
import { TriggerProps } from '../index.tsx';
|
|
3
3
|
import { AlignType } from '../interface';
|
|
4
|
-
export default function useAlign(open: Ref<boolean>, popupEle: Ref<HTMLElement>, target: Ref<HTMLElement | [x: number, y: number]>, placement: Ref<string>, builtinPlacements: Ref<any>, popupAlign?: Ref<AlignType | undefined>, onPopupAlign?: TriggerProps['onPopupAlign'], mobile?: Ref<boolean | undefined>): readonly [Ref<boolean, boolean>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<any, any>, () => void];
|
|
4
|
+
export default function useAlign(open: Ref<boolean>, popupEle: Ref<HTMLElement>, target: Ref<HTMLElement | [x: number, y: number]>, placement: Ref<string>, builtinPlacements: Ref<any>, popupAlign?: Ref<AlignType | undefined>, onPopupAlign?: TriggerProps['onPopupAlign'], mobile?: Ref<boolean | undefined>): readonly [Ref<boolean, boolean>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<number, number>, Ref<any, any>, (cache?: boolean) => void];
|
package/dist/hooks/useAlign.js
CHANGED
|
@@ -2,7 +2,6 @@ import { collectScroller, getVisibleArea, getWin, toNum } from "../util.js";
|
|
|
2
2
|
import { computed, nextTick, reactive, ref, shallowRef, toRefs, watch } from "vue";
|
|
3
3
|
import { isDOM } from "@v-c/util/dist/Dom/findDOMNode";
|
|
4
4
|
import isVisible from "@v-c/util/dist/Dom/isVisible";
|
|
5
|
-
import { rafDebounce } from "@v-c/util/dist/raf";
|
|
6
5
|
function getUnitOffset(size, offset = 0) {
|
|
7
6
|
const offsetStr = `${offset}`;
|
|
8
7
|
const cells = offsetStr.match(/^(.*)\%$/);
|
|
@@ -44,46 +43,6 @@ function reversePoints(points, index) {
|
|
|
44
43
|
return point;
|
|
45
44
|
}).join("");
|
|
46
45
|
}
|
|
47
|
-
function parseOriginValue(value, size, axis) {
|
|
48
|
-
const fallback = size / 2;
|
|
49
|
-
if (!value) return fallback;
|
|
50
|
-
const val = value.trim();
|
|
51
|
-
if (!val) return fallback;
|
|
52
|
-
if (val.endsWith("%")) return size * (parseFloat(val) / 100);
|
|
53
|
-
if (val.endsWith("px")) return parseFloat(val);
|
|
54
|
-
if (val === "center") return fallback;
|
|
55
|
-
if (axis === "x") {
|
|
56
|
-
if (val === "left") return 0;
|
|
57
|
-
if (val === "right") return size;
|
|
58
|
-
} else if (axis === "y") {
|
|
59
|
-
if (val === "top") return 0;
|
|
60
|
-
if (val === "bottom") return size;
|
|
61
|
-
}
|
|
62
|
-
const num = parseFloat(val);
|
|
63
|
-
return Number.isNaN(num) ? fallback : num;
|
|
64
|
-
}
|
|
65
|
-
function getTransformOriginPoint(origin, width, height) {
|
|
66
|
-
const [originX = "50%", originY = "50%"] = origin?.split(/\s+/).filter(Boolean) ?? [];
|
|
67
|
-
return [parseOriginValue(originX, width, "x"), parseOriginValue(originY, height, "y")];
|
|
68
|
-
}
|
|
69
|
-
function normalizeRect(rect, scaleX, scaleY, originX, originY) {
|
|
70
|
-
const rawX = rect.x ?? rect.left;
|
|
71
|
-
const rawY = rect.y ?? rect.top;
|
|
72
|
-
const width = rect.width / scaleX;
|
|
73
|
-
const height = rect.height / scaleY;
|
|
74
|
-
const x = rawX - (1 - scaleX) * originX;
|
|
75
|
-
const y = rawY - (1 - scaleY) * originY;
|
|
76
|
-
return {
|
|
77
|
-
x,
|
|
78
|
-
y,
|
|
79
|
-
width,
|
|
80
|
-
height,
|
|
81
|
-
left: x,
|
|
82
|
-
top: y,
|
|
83
|
-
right: x + width,
|
|
84
|
-
bottom: y + height
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
46
|
function shouldSwitchPlacement(isOverflow, isVisibleFirst, newVisibleArea, originVisibleArea, newRecommendArea, originRecommendArea) {
|
|
88
47
|
if (isOverflow) return newVisibleArea > originVisibleArea || newVisibleArea === originVisibleArea && (!isVisibleFirst || newRecommendArea >= originRecommendArea);
|
|
89
48
|
return newVisibleArea > originVisibleArea || isVisibleFirst && newVisibleArea === originVisibleArea && newRecommendArea > originRecommendArea;
|
|
@@ -110,7 +69,9 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
110
69
|
const resetFlipCache = () => {
|
|
111
70
|
prevFlipRef.value = {};
|
|
112
71
|
};
|
|
113
|
-
|
|
72
|
+
let cacheTargetRect = null;
|
|
73
|
+
const _onAlign = (cache = false) => {
|
|
74
|
+
if (cache && !cacheTargetRect) return;
|
|
114
75
|
if (popupEle.value && target.value && open.value && !mobile?.value) {
|
|
115
76
|
const popupElement = popupEle.value;
|
|
116
77
|
const doc = popupElement.ownerDocument;
|
|
@@ -145,7 +106,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
145
106
|
height: 0
|
|
146
107
|
};
|
|
147
108
|
else {
|
|
148
|
-
const
|
|
109
|
+
const targetRectInfo = target.value.getBoundingClientRect();
|
|
110
|
+
const rect = cache ? Object.assign(targetRectInfo, cacheTargetRect ?? {}) : targetRectInfo;
|
|
111
|
+
if (!cache) cacheTargetRect = {
|
|
112
|
+
width: rect.width,
|
|
113
|
+
height: rect.height
|
|
114
|
+
};
|
|
149
115
|
rect.x = rect.x ?? rect.left;
|
|
150
116
|
rect.y = rect.y ?? rect.top;
|
|
151
117
|
targetRect = {
|
|
@@ -191,20 +157,16 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
191
157
|
popupElement.style.bottom = originBottom;
|
|
192
158
|
popupElement.style.overflow = originOverflow;
|
|
193
159
|
popupElement.parentElement?.removeChild(placeholderElement);
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const
|
|
198
|
-
const safeBaseWidth = baseWidth || rawPopupRect.width || 1;
|
|
199
|
-
const safeBaseHeight = baseHeight || rawPopupRect.height || 1;
|
|
200
|
-
const scaleX$1 = toNum(Math.round(rawPopupRect.width / safeBaseWidth * 1e3) / 1e3);
|
|
201
|
-
const scaleY$1 = toNum(Math.round(rawPopupRect.height / safeBaseHeight * 1e3) / 1e3);
|
|
202
|
-
if (scaleX$1 === 0 || scaleY$1 === 0 || isDOM(target) && !isVisible(target)) return;
|
|
203
|
-
const [originX, originY] = getTransformOriginPoint(popupComputedStyle.transformOrigin, safeBaseWidth, safeBaseHeight);
|
|
204
|
-
const popupRect = normalizeRect(rawPopupRect, scaleX$1, scaleY$1, originX, originY);
|
|
205
|
-
const popupMirrorRect = normalizeRect(rawPopupMirrorRect, scaleX$1, scaleY$1, originX, originY);
|
|
160
|
+
const popupRect = rawPopupRect;
|
|
161
|
+
popupRect.x = popupRect.x ?? popupRect.left;
|
|
162
|
+
popupRect.y = popupRect.y ?? popupRect.top;
|
|
163
|
+
const { height, width } = popupComputedStyle;
|
|
206
164
|
const popupHeight = popupRect.height;
|
|
207
165
|
const popupWidth = popupRect.width;
|
|
166
|
+
const popupMirrorRect = rawPopupMirrorRect;
|
|
167
|
+
const scaleX$1 = toNum(Math.round(popupWidth / parseFloat(width) * 1e3) / 1e3);
|
|
168
|
+
const scaleY$1 = toNum(Math.round(popupHeight / parseFloat(height) * 1e3) / 1e3);
|
|
169
|
+
if (scaleX$1 === 0 || scaleY$1 === 0 || isDOM(target) && !isVisible(target)) return;
|
|
208
170
|
const { offset, targetOffset } = placementInfo;
|
|
209
171
|
let [popupOffsetX, popupOffsetY] = getNumberOffset(popupRect, offset);
|
|
210
172
|
const [targetOffsetX, targetOffsetY] = getNumberOffset(targetRect, targetOffset);
|
|
@@ -349,12 +311,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
349
311
|
}
|
|
350
312
|
const nextOffsetInfo = {
|
|
351
313
|
ready: true,
|
|
352
|
-
offsetX: nextOffsetX,
|
|
353
|
-
offsetY: nextOffsetY,
|
|
354
|
-
offsetR: offsetX4Right,
|
|
355
|
-
offsetB: offsetY4Bottom,
|
|
356
|
-
arrowX: nextArrowX,
|
|
357
|
-
arrowY: nextArrowY,
|
|
314
|
+
offsetX: nextOffsetX / scaleX$1,
|
|
315
|
+
offsetY: nextOffsetY / scaleY$1,
|
|
316
|
+
offsetR: offsetX4Right / scaleX$1,
|
|
317
|
+
offsetB: offsetY4Bottom / scaleY$1,
|
|
318
|
+
arrowX: nextArrowX / scaleX$1,
|
|
319
|
+
arrowY: nextArrowY / scaleY$1,
|
|
358
320
|
scaleX: scaleX$1,
|
|
359
321
|
scaleY: scaleY$1,
|
|
360
322
|
align: nextAlignInfo
|
|
@@ -362,12 +324,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
362
324
|
Object.assign(offsetInfo, nextOffsetInfo);
|
|
363
325
|
}
|
|
364
326
|
};
|
|
365
|
-
const onAlign =
|
|
366
|
-
const triggerAlign = () => {
|
|
327
|
+
const onAlign = _onAlign;
|
|
328
|
+
const triggerAlign = (cache) => {
|
|
367
329
|
alignCountRef.value += 1;
|
|
368
330
|
const id = alignCountRef.value;
|
|
369
331
|
Promise.resolve().then(() => {
|
|
370
|
-
if (alignCountRef.value === id) onAlign();
|
|
332
|
+
if (alignCountRef.value === id) onAlign(cache);
|
|
371
333
|
});
|
|
372
334
|
};
|
|
373
335
|
watch(popupEle, async (ele) => {
|
package/dist/index.cjs
CHANGED
|
@@ -158,8 +158,7 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
|
|
|
158
158
|
}, delay);
|
|
159
159
|
};
|
|
160
160
|
const inMotion = (0, vue.shallowRef)(false);
|
|
161
|
-
(0, vue.watch)(mergedOpen,
|
|
162
|
-
await (0, vue.nextTick)();
|
|
161
|
+
(0, vue.watch)(mergedOpen, () => {
|
|
163
162
|
if (mergedOpen.value) inMotion.value = true;
|
|
164
163
|
});
|
|
165
164
|
const motionPrepareResolve = (0, vue.shallowRef)();
|
|
@@ -173,6 +172,7 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
|
|
|
173
172
|
const clickToHide = (0, vue.computed)(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
|
|
174
173
|
const triggerAlign = () => {
|
|
175
174
|
if (!inMotion.value) onAlign();
|
|
175
|
+
else onAlign(true);
|
|
176
176
|
};
|
|
177
177
|
const onScroll = () => {
|
|
178
178
|
if (openRef.value && props?.alignPoint && clickToHide.value) triggerOpen(false);
|
|
@@ -215,9 +215,10 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
|
|
|
215
215
|
props?.afterPopupVisibleChange?.(visible);
|
|
216
216
|
};
|
|
217
217
|
const onPrepare = () => {
|
|
218
|
+
syncTargetSize();
|
|
218
219
|
return new Promise((resolve) => {
|
|
219
|
-
syncTargetSize();
|
|
220
220
|
motionPrepareResolve.value = resolve;
|
|
221
|
+
inMotion.value = true;
|
|
221
222
|
});
|
|
222
223
|
};
|
|
223
224
|
(0, vue.watch)([motionPrepareResolve], () => {
|
|
@@ -226,7 +227,7 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
|
|
|
226
227
|
motionPrepareResolve.value();
|
|
227
228
|
motionPrepareResolve.value = void 0;
|
|
228
229
|
}
|
|
229
|
-
});
|
|
230
|
+
}, { flush: "post" });
|
|
230
231
|
function wrapperAction(target, eventName, nextOpen, delay, callback, ignoreCheck) {
|
|
231
232
|
target[eventName] = (event, ...args) => {
|
|
232
233
|
if (!ignoreCheck || !ignoreCheck()) {
|
|
@@ -506,15 +507,15 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
|
|
|
506
507
|
},
|
|
507
508
|
popup: {
|
|
508
509
|
type: [
|
|
510
|
+
Object,
|
|
511
|
+
Function,
|
|
509
512
|
String,
|
|
510
513
|
Number,
|
|
511
514
|
null,
|
|
512
515
|
Boolean,
|
|
513
|
-
Array
|
|
514
|
-
Function
|
|
516
|
+
Array
|
|
515
517
|
],
|
|
516
518
|
required: true,
|
|
517
|
-
skipCheck: true,
|
|
518
519
|
default: void 0
|
|
519
520
|
},
|
|
520
521
|
popupPlacement: {
|
|
@@ -543,12 +544,12 @@ function generateTrigger(PortalComponent = __v_c_portal.default) {
|
|
|
543
544
|
default: void 0
|
|
544
545
|
},
|
|
545
546
|
uniqueContainerStyle: {
|
|
546
|
-
type:
|
|
547
|
+
type: Object,
|
|
547
548
|
required: false,
|
|
548
549
|
default: void 0
|
|
549
550
|
},
|
|
550
551
|
popupStyle: {
|
|
551
|
-
type:
|
|
552
|
+
type: Object,
|
|
552
553
|
required: false,
|
|
553
554
|
default: void 0
|
|
554
555
|
},
|
package/dist/index.js
CHANGED
|
@@ -154,8 +154,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
154
154
|
}, delay);
|
|
155
155
|
};
|
|
156
156
|
const inMotion = shallowRef(false);
|
|
157
|
-
watch(mergedOpen,
|
|
158
|
-
await nextTick();
|
|
157
|
+
watch(mergedOpen, () => {
|
|
159
158
|
if (mergedOpen.value) inMotion.value = true;
|
|
160
159
|
});
|
|
161
160
|
const motionPrepareResolve = shallowRef();
|
|
@@ -169,6 +168,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
169
168
|
const clickToHide = computed(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
|
|
170
169
|
const triggerAlign = () => {
|
|
171
170
|
if (!inMotion.value) onAlign();
|
|
171
|
+
else onAlign(true);
|
|
172
172
|
};
|
|
173
173
|
const onScroll = () => {
|
|
174
174
|
if (openRef.value && props?.alignPoint && clickToHide.value) triggerOpen(false);
|
|
@@ -211,9 +211,10 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
211
211
|
props?.afterPopupVisibleChange?.(visible);
|
|
212
212
|
};
|
|
213
213
|
const onPrepare = () => {
|
|
214
|
+
syncTargetSize();
|
|
214
215
|
return new Promise((resolve) => {
|
|
215
|
-
syncTargetSize();
|
|
216
216
|
motionPrepareResolve.value = resolve;
|
|
217
|
+
inMotion.value = true;
|
|
217
218
|
});
|
|
218
219
|
};
|
|
219
220
|
watch([motionPrepareResolve], () => {
|
|
@@ -222,7 +223,7 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
222
223
|
motionPrepareResolve.value();
|
|
223
224
|
motionPrepareResolve.value = void 0;
|
|
224
225
|
}
|
|
225
|
-
});
|
|
226
|
+
}, { flush: "post" });
|
|
226
227
|
function wrapperAction(target, eventName, nextOpen, delay, callback, ignoreCheck) {
|
|
227
228
|
target[eventName] = (event, ...args) => {
|
|
228
229
|
if (!ignoreCheck || !ignoreCheck()) {
|
|
@@ -502,15 +503,15 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
502
503
|
},
|
|
503
504
|
popup: {
|
|
504
505
|
type: [
|
|
506
|
+
Object,
|
|
507
|
+
Function,
|
|
505
508
|
String,
|
|
506
509
|
Number,
|
|
507
510
|
null,
|
|
508
511
|
Boolean,
|
|
509
|
-
Array
|
|
510
|
-
Function
|
|
512
|
+
Array
|
|
511
513
|
],
|
|
512
514
|
required: true,
|
|
513
|
-
skipCheck: true,
|
|
514
515
|
default: void 0
|
|
515
516
|
},
|
|
516
517
|
popupPlacement: {
|
|
@@ -539,12 +540,12 @@ function generateTrigger(PortalComponent = Portal) {
|
|
|
539
540
|
default: void 0
|
|
540
541
|
},
|
|
541
542
|
uniqueContainerStyle: {
|
|
542
|
-
type:
|
|
543
|
+
type: Object,
|
|
543
544
|
required: false,
|
|
544
545
|
default: void 0
|
|
545
546
|
},
|
|
546
547
|
popupStyle: {
|
|
547
|
-
type:
|
|
548
|
+
type: Object,
|
|
548
549
|
required: false,
|
|
549
550
|
default: void 0
|
|
550
551
|
},
|
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.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"vue": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@v-c/portal": "^1.0.
|
|
33
|
-
"@v-c/resize-observer": "^1.0.
|
|
34
|
-
"@v-c/util": "^1.0.
|
|
32
|
+
"@v-c/portal": "^1.0.1",
|
|
33
|
+
"@v-c/resize-observer": "^1.0.3",
|
|
34
|
+
"@v-c/util": "^1.0.3"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "vite build",
|