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