@v-c/trigger 0.0.10 → 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 -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 +2 -2
|
@@ -1,139 +1,159 @@
|
|
|
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
|
-
|
|
1
|
+
import { defineComponent, shallowRef, watchEffect, watch, 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, (nextVisible) => {
|
|
25
|
+
if (nextVisible) {
|
|
26
|
+
motionVisible.value = true;
|
|
27
|
+
}
|
|
20
28
|
}, {
|
|
21
|
-
immediate:
|
|
22
|
-
})
|
|
29
|
+
immediate: true
|
|
30
|
+
});
|
|
31
|
+
return () => {
|
|
23
32
|
const {
|
|
24
|
-
popupSize
|
|
25
|
-
motion
|
|
26
|
-
prefixCls
|
|
27
|
-
uniqueContainerClassName
|
|
28
|
-
arrowPos
|
|
29
|
-
uniqueContainerStyle
|
|
30
|
-
} =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
popupSize,
|
|
34
|
+
motion,
|
|
35
|
+
prefixCls,
|
|
36
|
+
uniqueContainerClassName,
|
|
37
|
+
arrowPos,
|
|
38
|
+
uniqueContainerStyle
|
|
39
|
+
} = props;
|
|
40
|
+
const sizeStyle = {};
|
|
41
|
+
if (popupSize) {
|
|
42
|
+
sizeStyle.width = `${popupSize.width}px`;
|
|
43
|
+
sizeStyle.height = `${popupSize.height}px`;
|
|
44
|
+
}
|
|
45
|
+
const baseTransitionProps = getTransitionProps(motion?.name, motion);
|
|
46
|
+
const mergedTransitionProps = {
|
|
47
|
+
...baseTransitionProps,
|
|
48
|
+
onBeforeAppear: (element) => {
|
|
49
|
+
motionVisible.value = true;
|
|
50
|
+
baseTransitionProps.onBeforeAppear?.(element);
|
|
36
51
|
},
|
|
37
|
-
onBeforeEnter: (
|
|
38
|
-
|
|
52
|
+
onBeforeEnter: (element) => {
|
|
53
|
+
motionVisible.value = true;
|
|
54
|
+
baseTransitionProps.onBeforeEnter?.(element);
|
|
39
55
|
},
|
|
40
|
-
onAfterAppear: (
|
|
41
|
-
|
|
56
|
+
onAfterAppear: (element) => {
|
|
57
|
+
motionVisible.value = true;
|
|
58
|
+
baseTransitionProps.onAfterAppear?.(element);
|
|
42
59
|
},
|
|
43
|
-
onAfterEnter: (
|
|
44
|
-
|
|
60
|
+
onAfterEnter: (element) => {
|
|
61
|
+
motionVisible.value = true;
|
|
62
|
+
baseTransitionProps.onAfterEnter?.(element);
|
|
45
63
|
},
|
|
46
|
-
onAfterLeave: (
|
|
47
|
-
|
|
64
|
+
onAfterLeave: (element) => {
|
|
65
|
+
motionVisible.value = false;
|
|
66
|
+
baseTransitionProps.onAfterLeave?.(element);
|
|
48
67
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
[`${
|
|
68
|
+
};
|
|
69
|
+
const containerCls = `${prefixCls}-unique-container`;
|
|
70
|
+
return createVNode(Transition, mergedTransitionProps, {
|
|
71
|
+
default: () => [withDirectives(createVNode("div", {
|
|
72
|
+
"class": [containerCls, uniqueContainerClassName, {
|
|
73
|
+
[`${containerCls}-visible`]: motionVisible.value,
|
|
74
|
+
[`${containerCls}-hidden`]: !motionVisible.value
|
|
55
75
|
}],
|
|
56
|
-
style: [{
|
|
57
|
-
"--arrow-x": `${
|
|
58
|
-
"--arrow-y": `${
|
|
59
|
-
},
|
|
60
|
-
}, null), [[
|
|
76
|
+
"style": [{
|
|
77
|
+
"--arrow-x": `${arrowPos?.x || 0}px`,
|
|
78
|
+
"--arrow-y": `${arrowPos?.y || 0}px`
|
|
79
|
+
}, cachedOffsetStyleRef.value, sizeStyle, uniqueContainerStyle]
|
|
80
|
+
}, null), [[vShow, open.value]])]
|
|
61
81
|
});
|
|
62
82
|
};
|
|
63
83
|
}, {
|
|
64
84
|
props: {
|
|
65
85
|
prefixCls: {
|
|
66
86
|
type: String,
|
|
67
|
-
required:
|
|
87
|
+
required: true,
|
|
68
88
|
default: void 0
|
|
69
89
|
},
|
|
70
90
|
isMobile: {
|
|
71
91
|
type: Boolean,
|
|
72
|
-
required:
|
|
92
|
+
required: true,
|
|
73
93
|
default: void 0
|
|
74
94
|
},
|
|
75
95
|
ready: {
|
|
76
96
|
type: Boolean,
|
|
77
|
-
required:
|
|
97
|
+
required: true,
|
|
78
98
|
default: void 0
|
|
79
99
|
},
|
|
80
100
|
open: {
|
|
81
101
|
type: Boolean,
|
|
82
|
-
required:
|
|
102
|
+
required: true,
|
|
83
103
|
default: void 0
|
|
84
104
|
},
|
|
85
105
|
align: {
|
|
86
106
|
type: Object,
|
|
87
|
-
required:
|
|
107
|
+
required: true,
|
|
88
108
|
default: void 0
|
|
89
109
|
},
|
|
90
110
|
offsetR: {
|
|
91
111
|
type: Number,
|
|
92
|
-
required:
|
|
112
|
+
required: true,
|
|
93
113
|
default: void 0
|
|
94
114
|
},
|
|
95
115
|
offsetB: {
|
|
96
116
|
type: Number,
|
|
97
|
-
required:
|
|
117
|
+
required: true,
|
|
98
118
|
default: void 0
|
|
99
119
|
},
|
|
100
120
|
offsetX: {
|
|
101
121
|
type: Number,
|
|
102
|
-
required:
|
|
122
|
+
required: true,
|
|
103
123
|
default: void 0
|
|
104
124
|
},
|
|
105
125
|
offsetY: {
|
|
106
126
|
type: Number,
|
|
107
|
-
required:
|
|
127
|
+
required: true,
|
|
108
128
|
default: void 0
|
|
109
129
|
},
|
|
110
130
|
arrowPos: {
|
|
111
131
|
type: Object,
|
|
112
|
-
required:
|
|
132
|
+
required: false,
|
|
113
133
|
default: void 0
|
|
114
134
|
},
|
|
115
135
|
popupSize: {
|
|
116
136
|
type: Object,
|
|
117
|
-
required:
|
|
137
|
+
required: false,
|
|
118
138
|
default: void 0
|
|
119
139
|
},
|
|
120
140
|
motion: {
|
|
121
141
|
type: Object,
|
|
122
|
-
required:
|
|
142
|
+
required: false,
|
|
123
143
|
default: void 0
|
|
124
144
|
},
|
|
125
145
|
uniqueContainerClassName: {
|
|
126
146
|
type: String,
|
|
127
|
-
required:
|
|
147
|
+
required: false,
|
|
128
148
|
default: void 0
|
|
129
149
|
},
|
|
130
150
|
uniqueContainerStyle: {
|
|
131
151
|
type: null,
|
|
132
|
-
required:
|
|
152
|
+
required: false,
|
|
133
153
|
default: void 0
|
|
134
154
|
}
|
|
135
155
|
}
|
|
136
156
|
});
|
|
137
157
|
export {
|
|
138
|
-
|
|
158
|
+
UniqueContainer as default
|
|
139
159
|
};
|
|
@@ -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
|
+
// scaleX - not used in UniqueProvider
|
|
88
|
+
,
|
|
89
|
+
,
|
|
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;
|