@v-c/trigger 0.0.10 → 0.0.12
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 +366 -1
- package/dist/Popup/index.js +196 -161
- package/dist/UniqueProvider/UniqueContainer.cjs +150 -1
- package/dist/UniqueProvider/UniqueContainer.js +81 -70
- package/dist/UniqueProvider/index.cjs +213 -1
- package/dist/UniqueProvider/index.js +178 -132
- 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 -208
- 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 +4 -4
|
@@ -1,139 +1,150 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
import { toPropsRefs
|
|
3
|
-
import { getTransitionProps
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { defineComponent, shallowRef, watchEffect, watch, nextTick, createVNode, Transition, withDirectives, vShow } from "vue";
|
|
2
|
+
import { toPropsRefs } from "@v-c/util/dist/props-util";
|
|
3
|
+
import { getTransitionProps } from "@v-c/util/dist/utils/transition";
|
|
4
|
+
import useOffsetStyle from "../hooks/useOffsetStyle.js";
|
|
5
|
+
const UniqueContainer = /* @__PURE__ */ defineComponent((props) => {
|
|
6
|
+
const motionVisible = shallowRef(false);
|
|
7
|
+
const {
|
|
8
|
+
open,
|
|
9
|
+
isMobile,
|
|
10
|
+
align,
|
|
11
|
+
ready,
|
|
12
|
+
offsetR,
|
|
13
|
+
offsetB,
|
|
14
|
+
offsetX,
|
|
15
|
+
offsetY
|
|
16
|
+
} = toPropsRefs(props, "open", "isMobile", "align", "ready", "offsetR", "offsetB", "offsetX", "offsetY");
|
|
17
|
+
const offsetStyle = useOffsetStyle(isMobile, ready, open, align, offsetR, offsetB, offsetX, offsetY);
|
|
18
|
+
const cachedOffsetStyleRef = shallowRef(offsetStyle.value);
|
|
19
|
+
watchEffect(() => {
|
|
20
|
+
if (ready.value) {
|
|
21
|
+
cachedOffsetStyleRef.value = offsetStyle.value;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
watch(open, async (nextVisible) => {
|
|
25
|
+
await nextTick();
|
|
26
|
+
if (nextVisible) {
|
|
27
|
+
motionVisible.value = true;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return () => {
|
|
23
31
|
const {
|
|
24
|
-
popupSize
|
|
25
|
-
motion
|
|
26
|
-
prefixCls
|
|
27
|
-
uniqueContainerClassName
|
|
28
|
-
arrowPos
|
|
29
|
-
uniqueContainerStyle
|
|
30
|
-
} =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
popupSize,
|
|
33
|
+
motion,
|
|
34
|
+
prefixCls,
|
|
35
|
+
uniqueContainerClassName,
|
|
36
|
+
arrowPos,
|
|
37
|
+
uniqueContainerStyle
|
|
38
|
+
} = props;
|
|
39
|
+
const sizeStyle = {};
|
|
40
|
+
if (popupSize) {
|
|
41
|
+
sizeStyle.width = `${popupSize.width}px`;
|
|
42
|
+
sizeStyle.height = `${popupSize.height}px`;
|
|
43
|
+
}
|
|
44
|
+
const baseTransitionProps = getTransitionProps(motion?.name, motion);
|
|
45
|
+
const mergedTransitionProps = {
|
|
46
|
+
...baseTransitionProps,
|
|
47
|
+
onBeforeEnter: (element) => {
|
|
48
|
+
motionVisible.value = true;
|
|
49
|
+
baseTransitionProps.onBeforeEnter?.(element);
|
|
42
50
|
},
|
|
43
|
-
onAfterEnter: (
|
|
44
|
-
|
|
51
|
+
onAfterEnter: (element) => {
|
|
52
|
+
motionVisible.value = true;
|
|
53
|
+
baseTransitionProps.onAfterEnter?.(element);
|
|
45
54
|
},
|
|
46
|
-
onAfterLeave: (
|
|
47
|
-
|
|
55
|
+
onAfterLeave: (element) => {
|
|
56
|
+
motionVisible.value = false;
|
|
57
|
+
baseTransitionProps.onAfterLeave?.(element);
|
|
48
58
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
[`${
|
|
59
|
+
};
|
|
60
|
+
const containerCls = `${prefixCls}-unique-container`;
|
|
61
|
+
return createVNode(Transition, mergedTransitionProps, {
|
|
62
|
+
default: () => [withDirectives(createVNode("div", {
|
|
63
|
+
"class": [containerCls, uniqueContainerClassName, {
|
|
64
|
+
[`${containerCls}-visible`]: motionVisible.value
|
|
65
|
+
// [`${containerCls}-hidden`]: !motionVisible.value,
|
|
55
66
|
}],
|
|
56
|
-
style: [{
|
|
57
|
-
"--arrow-x": `${
|
|
58
|
-
"--arrow-y": `${
|
|
59
|
-
},
|
|
60
|
-
}, null), [[
|
|
67
|
+
"style": [{
|
|
68
|
+
"--arrow-x": `${arrowPos?.x || 0}px`,
|
|
69
|
+
"--arrow-y": `${arrowPos?.y || 0}px`
|
|
70
|
+
}, cachedOffsetStyleRef.value, sizeStyle, uniqueContainerStyle]
|
|
71
|
+
}, null), [[vShow, open.value]])]
|
|
61
72
|
});
|
|
62
73
|
};
|
|
63
74
|
}, {
|
|
64
75
|
props: {
|
|
65
76
|
prefixCls: {
|
|
66
77
|
type: String,
|
|
67
|
-
required:
|
|
78
|
+
required: true,
|
|
68
79
|
default: void 0
|
|
69
80
|
},
|
|
70
81
|
isMobile: {
|
|
71
82
|
type: Boolean,
|
|
72
|
-
required:
|
|
83
|
+
required: true,
|
|
73
84
|
default: void 0
|
|
74
85
|
},
|
|
75
86
|
ready: {
|
|
76
87
|
type: Boolean,
|
|
77
|
-
required:
|
|
88
|
+
required: true,
|
|
78
89
|
default: void 0
|
|
79
90
|
},
|
|
80
91
|
open: {
|
|
81
92
|
type: Boolean,
|
|
82
|
-
required:
|
|
93
|
+
required: true,
|
|
83
94
|
default: void 0
|
|
84
95
|
},
|
|
85
96
|
align: {
|
|
86
97
|
type: Object,
|
|
87
|
-
required:
|
|
98
|
+
required: true,
|
|
88
99
|
default: void 0
|
|
89
100
|
},
|
|
90
101
|
offsetR: {
|
|
91
102
|
type: Number,
|
|
92
|
-
required:
|
|
103
|
+
required: true,
|
|
93
104
|
default: void 0
|
|
94
105
|
},
|
|
95
106
|
offsetB: {
|
|
96
107
|
type: Number,
|
|
97
|
-
required:
|
|
108
|
+
required: true,
|
|
98
109
|
default: void 0
|
|
99
110
|
},
|
|
100
111
|
offsetX: {
|
|
101
112
|
type: Number,
|
|
102
|
-
required:
|
|
113
|
+
required: true,
|
|
103
114
|
default: void 0
|
|
104
115
|
},
|
|
105
116
|
offsetY: {
|
|
106
117
|
type: Number,
|
|
107
|
-
required:
|
|
118
|
+
required: true,
|
|
108
119
|
default: void 0
|
|
109
120
|
},
|
|
110
121
|
arrowPos: {
|
|
111
122
|
type: Object,
|
|
112
|
-
required:
|
|
123
|
+
required: false,
|
|
113
124
|
default: void 0
|
|
114
125
|
},
|
|
115
126
|
popupSize: {
|
|
116
127
|
type: Object,
|
|
117
|
-
required:
|
|
128
|
+
required: false,
|
|
118
129
|
default: void 0
|
|
119
130
|
},
|
|
120
131
|
motion: {
|
|
121
132
|
type: Object,
|
|
122
|
-
required:
|
|
133
|
+
required: false,
|
|
123
134
|
default: void 0
|
|
124
135
|
},
|
|
125
136
|
uniqueContainerClassName: {
|
|
126
137
|
type: String,
|
|
127
|
-
required:
|
|
138
|
+
required: false,
|
|
128
139
|
default: void 0
|
|
129
140
|
},
|
|
130
141
|
uniqueContainerStyle: {
|
|
131
142
|
type: null,
|
|
132
|
-
required:
|
|
143
|
+
required: false,
|
|
133
144
|
default: void 0
|
|
134
145
|
}
|
|
135
146
|
}
|
|
136
147
|
});
|
|
137
148
|
export {
|
|
138
|
-
|
|
149
|
+
UniqueContainer as default
|
|
139
150
|
};
|
|
@@ -1 +1,213 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const Portal = require("@v-c/portal");
|
|
5
|
+
const util$1 = require("@v-c/util");
|
|
6
|
+
const findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
7
|
+
const context = require("../context.cjs");
|
|
8
|
+
const useAlign = require("../hooks/useAlign.cjs");
|
|
9
|
+
const useDelay = require("../hooks/useDelay.cjs");
|
|
10
|
+
const index = require("../Popup/index.cjs");
|
|
11
|
+
const util = require("../util.cjs");
|
|
12
|
+
const UniqueContainer = require("./UniqueContainer.cjs");
|
|
13
|
+
const useTargetState = require("./useTargetState.cjs");
|
|
14
|
+
const UniqueProvider = /* @__PURE__ */ vue.defineComponent((props, {
|
|
15
|
+
slots
|
|
16
|
+
}) => {
|
|
17
|
+
const [trigger, open, options, onTargetVisibleChanged] = useTargetState.default();
|
|
18
|
+
const mergedOptions = vue.computed(() => {
|
|
19
|
+
if (!options.value || !props.postTriggerProps) {
|
|
20
|
+
return options.value;
|
|
21
|
+
}
|
|
22
|
+
return props.postTriggerProps(options.value);
|
|
23
|
+
});
|
|
24
|
+
const popupEle = vue.shallowRef(null);
|
|
25
|
+
const popupSize = vue.ref(null);
|
|
26
|
+
const externalPopupRef = vue.shallowRef(null);
|
|
27
|
+
const resolveToElement = (node) => {
|
|
28
|
+
if (!node) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (findDOMNode.isDOM(node)) {
|
|
32
|
+
return node;
|
|
33
|
+
}
|
|
34
|
+
const exposed = node;
|
|
35
|
+
if (findDOMNode.isDOM(exposed?.$el)) {
|
|
36
|
+
return exposed.$el;
|
|
37
|
+
}
|
|
38
|
+
const nativeEl = exposed?.nativeElement;
|
|
39
|
+
if (findDOMNode.isDOM(nativeEl?.value)) {
|
|
40
|
+
return nativeEl.value;
|
|
41
|
+
}
|
|
42
|
+
if (findDOMNode.isDOM(nativeEl)) {
|
|
43
|
+
return nativeEl;
|
|
44
|
+
}
|
|
45
|
+
if (typeof exposed?.getElement === "function") {
|
|
46
|
+
const el = exposed.getElement();
|
|
47
|
+
if (findDOMNode.isDOM(el)) {
|
|
48
|
+
return el;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
const setPopupRef = (node) => {
|
|
54
|
+
const element = resolveToElement(node);
|
|
55
|
+
externalPopupRef.value = element;
|
|
56
|
+
if (popupEle.value !== element) {
|
|
57
|
+
popupEle.value = element;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const isOpenRef = vue.shallowRef();
|
|
61
|
+
const delayInvoke = useDelay.default();
|
|
62
|
+
const show = (showOptions, isOpen) => {
|
|
63
|
+
isOpenRef.value = isOpen;
|
|
64
|
+
delayInvoke(() => {
|
|
65
|
+
trigger(showOptions);
|
|
66
|
+
}, showOptions.delay);
|
|
67
|
+
};
|
|
68
|
+
const hide = (delay) => {
|
|
69
|
+
delayInvoke(() => {
|
|
70
|
+
if (isOpenRef.value?.()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
trigger(false);
|
|
74
|
+
}, delay);
|
|
75
|
+
};
|
|
76
|
+
const onVisibleChanged = (visible) => {
|
|
77
|
+
onTargetVisibleChanged(visible);
|
|
78
|
+
};
|
|
79
|
+
const [
|
|
80
|
+
ready,
|
|
81
|
+
offsetX,
|
|
82
|
+
offsetY,
|
|
83
|
+
offsetR,
|
|
84
|
+
offsetB,
|
|
85
|
+
arrowX,
|
|
86
|
+
arrowY,
|
|
87
|
+
,
|
|
88
|
+
,
|
|
89
|
+
// scaleX - not used in UniqueProvider
|
|
90
|
+
// scaleY - not used in UniqueProvider
|
|
91
|
+
alignInfo,
|
|
92
|
+
onAlign
|
|
93
|
+
] = useAlign.default(
|
|
94
|
+
open,
|
|
95
|
+
popupEle,
|
|
96
|
+
vue.computed(() => mergedOptions.value?.target),
|
|
97
|
+
vue.computed(() => mergedOptions.value?.popupPlacement),
|
|
98
|
+
vue.computed(() => mergedOptions.value?.builtinPlacements || {}),
|
|
99
|
+
vue.computed(() => mergedOptions.value?.popupAlign),
|
|
100
|
+
void 0,
|
|
101
|
+
// onPopupAlign
|
|
102
|
+
vue.ref(false)
|
|
103
|
+
// isMobile
|
|
104
|
+
);
|
|
105
|
+
const alignedClassName = vue.computed(() => {
|
|
106
|
+
if (!mergedOptions.value) {
|
|
107
|
+
return "";
|
|
108
|
+
}
|
|
109
|
+
const baseClassName = util.getAlignPopupClassName(mergedOptions.value?.builtinPlacements || {}, mergedOptions.value.prefixCls || "", alignInfo.value, false);
|
|
110
|
+
return util$1.classNames(baseClassName, mergedOptions.value?.getPopupClassNameFromAlign?.(alignInfo.value));
|
|
111
|
+
});
|
|
112
|
+
const contextValue = {
|
|
113
|
+
show,
|
|
114
|
+
hide
|
|
115
|
+
};
|
|
116
|
+
vue.watch(() => mergedOptions.value?.target, () => {
|
|
117
|
+
onAlign();
|
|
118
|
+
}, {
|
|
119
|
+
immediate: true
|
|
120
|
+
});
|
|
121
|
+
const onPrepare = () => {
|
|
122
|
+
onAlign();
|
|
123
|
+
return Promise.resolve();
|
|
124
|
+
};
|
|
125
|
+
const subPopupElements = vue.ref({});
|
|
126
|
+
const parentContext = context.useTriggerContext();
|
|
127
|
+
const triggerContextValue = vue.computed(() => {
|
|
128
|
+
return {
|
|
129
|
+
registerSubPopup: (id, subPopupEle) => {
|
|
130
|
+
if (subPopupEle) {
|
|
131
|
+
subPopupElements.value[id] = subPopupEle;
|
|
132
|
+
} else {
|
|
133
|
+
delete subPopupElements.value[id];
|
|
134
|
+
}
|
|
135
|
+
parentContext?.value?.registerSubPopup(id, subPopupEle);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
return () => {
|
|
140
|
+
const prefixCls = mergedOptions?.value?.prefixCls;
|
|
141
|
+
return vue.createVNode(context.UniqueContextProvider, contextValue, {
|
|
142
|
+
default: () => [slots?.default?.(), !!mergedOptions.value && vue.createVNode(context.TriggerContextProvider, triggerContextValue.value, {
|
|
143
|
+
default: () => [vue.createVNode(index.default, {
|
|
144
|
+
"ref": setPopupRef,
|
|
145
|
+
"portal": Portal,
|
|
146
|
+
"prefixCls": prefixCls,
|
|
147
|
+
"popup": mergedOptions.value?.popup,
|
|
148
|
+
"className": util$1.classNames(mergedOptions.value?.popupClassName, alignedClassName.value, `${prefixCls}-unique-controlled`),
|
|
149
|
+
"style": mergedOptions.value?.popupStyle,
|
|
150
|
+
"target": mergedOptions.value?.target,
|
|
151
|
+
"open": open.value,
|
|
152
|
+
"keepDom": true,
|
|
153
|
+
"fresh": true,
|
|
154
|
+
"autoDestroy": false,
|
|
155
|
+
"onVisibleChanged": onVisibleChanged,
|
|
156
|
+
"ready": ready.value,
|
|
157
|
+
"offsetX": offsetX.value,
|
|
158
|
+
"offsetY": offsetY.value,
|
|
159
|
+
"offsetR": offsetR.value,
|
|
160
|
+
"offsetB": offsetB.value,
|
|
161
|
+
"onAlign": onAlign,
|
|
162
|
+
"onPrepare": onPrepare,
|
|
163
|
+
"onResize": (size) => {
|
|
164
|
+
popupSize.value = {
|
|
165
|
+
width: size.offsetWidth,
|
|
166
|
+
height: size.offsetHeight
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
"arrowPos": {
|
|
170
|
+
x: arrowX.value,
|
|
171
|
+
y: arrowY.value
|
|
172
|
+
},
|
|
173
|
+
"align": alignInfo.value,
|
|
174
|
+
"zIndex": mergedOptions.value?.zIndex,
|
|
175
|
+
"mask": mergedOptions.value?.mask,
|
|
176
|
+
"arrow": mergedOptions.value?.arrow,
|
|
177
|
+
"motion": mergedOptions.value?.popupMotion,
|
|
178
|
+
"maskMotion": mergedOptions.value?.maskMotion,
|
|
179
|
+
"getPopupContainer": mergedOptions.value.getPopupContainer
|
|
180
|
+
}, {
|
|
181
|
+
default: () => [vue.createVNode(UniqueContainer.default, {
|
|
182
|
+
"prefixCls": prefixCls,
|
|
183
|
+
"isMobile": false,
|
|
184
|
+
"ready": ready.value,
|
|
185
|
+
"open": open.value,
|
|
186
|
+
"align": alignInfo.value,
|
|
187
|
+
"offsetX": offsetX.value,
|
|
188
|
+
"offsetY": offsetY.value,
|
|
189
|
+
"offsetR": offsetR.value,
|
|
190
|
+
"offsetB": offsetB.value,
|
|
191
|
+
"arrowPos": {
|
|
192
|
+
x: arrowX.value,
|
|
193
|
+
y: arrowY.value
|
|
194
|
+
},
|
|
195
|
+
"popupSize": popupSize.value,
|
|
196
|
+
"motion": mergedOptions.value?.popupMotion,
|
|
197
|
+
"uniqueContainerClassName": util$1.classNames(mergedOptions.value?.uniqueContainerClassName, alignedClassName.value),
|
|
198
|
+
"uniqueContainerStyle": mergedOptions?.value?.uniqueContainerStyle
|
|
199
|
+
}, null)]
|
|
200
|
+
})]
|
|
201
|
+
})]
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
}, {
|
|
205
|
+
props: {
|
|
206
|
+
postTriggerProps: {
|
|
207
|
+
type: Function,
|
|
208
|
+
required: false,
|
|
209
|
+
default: void 0
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
exports.default = UniqueProvider;
|