@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.
@@ -1,153 +1,199 @@
1
- import { defineComponent as F, computed as a, shallowRef as v, ref as m, watch as O, createVNode as n } from "vue";
2
- import H from "@v-c/portal";
3
- import { classNames as g } from "@v-c/util";
4
- import { isDOM as l } from "@v-c/util/dist/Dom/findDOMNode";
5
- import { useTriggerContext as W, UniqueContextProvider as j, TriggerContextProvider as G } from "../context.js";
6
- import J from "../hooks/useAlign.js";
7
- import K from "../hooks/useDelay.js";
8
- import L from "../Popup/index.js";
9
- import { getAlignPopupClassName as Q } from "../util.js";
10
- import Z from "./UniqueContainer.js";
11
- import _ from "./useTargetState.js";
12
- const fe = /* @__PURE__ */ F((c, {
13
- slots: A
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 [d, s, i, M] = _(), e = a(() => !i.value || !c.postTriggerProps ? i.value : c.postTriggerProps(i.value)), p = v(null), C = m(null), V = v(null), E = (t) => {
16
- if (!t)
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
- if (l(t))
19
- return t;
20
- const o = t;
21
- if (l(o?.$el))
22
- return o.$el;
23
- const r = o?.nativeElement;
24
- if (l(r?.value))
25
- return r.value;
26
- if (l(r))
27
- return r;
28
- if (typeof o?.getElement == "function") {
29
- const k = o.getElement();
30
- if (l(k))
31
- return k;
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
- }, z = (t) => {
35
- const o = E(t);
36
- V.value = o, p.value !== o && (p.value = o);
37
- }, P = v(), x = K(), D = (t, o) => {
38
- P.value = o, x(() => {
39
- d(t);
40
- }, t.delay);
41
- }, I = (t) => {
42
- x(() => {
43
- P.value?.() || d(!1);
44
- }, t);
45
- }, X = (t) => {
46
- M(t);
47
- }, [
48
- y,
49
- h,
50
- N,
51
- q,
52
- w,
53
- b,
54
- R,
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
- u,
60
- f
61
- ] = J(
62
- s,
63
- p,
64
- a(() => e.value?.target),
65
- a(() => e.value?.popupPlacement),
66
- a(() => e.value?.builtinPlacements || {}),
67
- a(() => e.value?.popupAlign),
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
- m(!1)
100
+ ref(false)
71
101
  // isMobile
72
- ), S = a(() => {
73
- if (!e.value)
102
+ );
103
+ const alignedClassName = computed(() => {
104
+ if (!mergedOptions.value) {
74
105
  return "";
75
- const t = Q(e.value?.builtinPlacements || {}, e.value.prefixCls || "", u.value, !1);
76
- return g(t, e.value?.getPopupClassNameFromAlign?.(u.value));
77
- }), Y = {
78
- show: D,
79
- hide: I
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
- O(() => e.value?.target, () => {
82
- f();
114
+ watch(() => mergedOptions.value?.target, () => {
115
+ onAlign();
83
116
  }, {
84
- immediate: !0
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 t = e?.value?.prefixCls;
93
- return n(j, Y, {
94
- default: () => [A?.default?.(), !!e.value && n(G, $.value, {
95
- default: () => [n(L, {
96
- ref: z,
97
- portal: H,
98
- prefixCls: t,
99
- popup: e.value?.popup,
100
- className: g(e.value?.popupClassName, S.value, `${t}-unique-controlled`),
101
- style: e.value?.popupStyle,
102
- target: e.value?.target,
103
- open: s.value,
104
- keepDom: !0,
105
- fresh: !0,
106
- autoDestroy: !1,
107
- onVisibleChanged: X,
108
- ready: y.value,
109
- offsetX: h.value,
110
- offsetY: N.value,
111
- offsetR: q.value,
112
- offsetB: w.value,
113
- onAlign: f,
114
- onPrepare: B,
115
- onResize: (o) => {
116
- C.value = {
117
- width: o.offsetWidth,
118
- height: o.offsetHeight
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: b.value,
123
- y: R.value
167
+ "arrowPos": {
168
+ x: arrowX.value,
169
+ y: arrowY.value
124
170
  },
125
- align: u.value,
126
- zIndex: e.value?.zIndex,
127
- mask: e.value?.mask,
128
- arrow: e.value?.arrow,
129
- motion: e.value?.popupMotion,
130
- maskMotion: e.value?.maskMotion,
131
- getPopupContainer: e.value.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: () => [n(Z, {
134
- prefixCls: t,
135
- isMobile: !1,
136
- ready: y.value,
137
- open: s.value,
138
- align: u.value,
139
- offsetX: h.value,
140
- offsetY: N.value,
141
- offsetR: q.value,
142
- offsetB: w.value,
143
- arrowPos: {
144
- x: b.value,
145
- y: R.value
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: C.value,
148
- motion: e.value?.popupMotion,
149
- uniqueContainerClassName: g(e.value?.uniqueContainerClassName, S.value),
150
- uniqueContainerStyle: e?.value?.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: !1,
206
+ required: false,
161
207
  default: void 0
162
208
  }
163
209
  }
164
210
  });
165
211
  export {
166
- fe as default
212
+ UniqueProvider as default
167
213
  };
@@ -1 +1,42 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("vue");function i(){const n=s.ref(),a=s.ref(!1),l=s.ref(!1),e=s.ref();return[u=>{const t=a.value;u===!1?(e.value=null,a.value=!1,l.value=!1):l.value&&t?e.value=u:(a.value=!0,n.value=u,e.value=null,t||(l.value=!0))},a,n,u=>{u?(l.value=!1,e.value&&(n.value=e.value,e.value=null)):(l.value=!1,e.value=null)}]}exports.default=i;
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 as s } from "vue";
2
- function o() {
3
- const n = s(), u = s(!1), l = s(!1), e = s();
4
- return [(a) => {
5
- const t = u.value;
6
- a === !1 ? (e.value = null, u.value = !1, l.value = !1) : l.value && t ? e.value = a : (u.value = !0, n.value = a, e.value = null, t || (l.value = !0));
7
- }, u, n, (a) => {
8
- a ? (l.value = !1, e.value && (n.value = e.value, e.value = null)) : (l.value = !1, e.value = null);
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
- o as default
41
+ useTargetState as default
13
42
  };
package/dist/context.cjs CHANGED
@@ -1 +1,38 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),o=Symbol("TriggerContextKey");function i(){return e.inject(o,void 0)}const u=e.defineComponent((t,{slots:n})=>(e.provide(o,e.computed(()=>t)),()=>n?.default?.()),{props:["registerSubPopup"]}),r=Symbol("UniqueContextKey");function d(){return e.inject(r,void 0)}const g=e.defineComponent((t,{slots:n})=>(e.provide(r,t),()=>n?.default?.()),{props:["show","hide"]});exports.TriggerContextProvider=u;exports.UniqueContextKey=r;exports.UniqueContextProvider=g;exports.useTriggerContext=i;exports.useUniqueContext=d;
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 as r, provide as o, computed as p, inject as n } from "vue";
2
- const i = Symbol("TriggerContextKey");
3
- function s() {
4
- return n(i, void 0);
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 g = r(
7
- (e, { slots: t }) => (o(i, p(() => e)), () => t?.default?.()),
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
- ), u = Symbol("UniqueContextKey");
12
- function x() {
13
- return n(u, void 0);
16
+ );
17
+ const UniqueContextKey = Symbol("UniqueContextKey");
18
+ function useUniqueContext() {
19
+ return inject(UniqueContextKey, void 0);
14
20
  }
15
- const C = r(
16
- (e, { slots: t }) => (o(u, e), () => t?.default?.()),
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
- g as TriggerContextProvider,
23
- u as UniqueContextKey,
24
- C as UniqueContextProvider,
25
- s as useTriggerContext,
26
- x as useUniqueContext
33
+ TriggerContextProvider,
34
+ UniqueContextKey,
35
+ UniqueContextProvider,
36
+ useTriggerContext,
37
+ useUniqueContext
27
38
  };
@@ -1 +1,32 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue");function u(e){return e?Array.isArray(e)?e:[e]:[]}function i(e){return typeof e=="string"?e.toLowerCase():e}function d(e,s,a){const r=n.shallowRef(new Set),c=n.shallowRef(new Set);return n.watchEffect(()=>{const h=u(s?.value??e.value).map(i),l=u(a?.value??e.value).map(i),t=new Set(h),o=new Set(l);t.has("hover")&&!t.has("click")&&t.add("touch"),o.has("hover")&&!o.has("click")&&o.add("touch"),r.value=t,c.value=o}),[r,c]}exports.default=d;
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;
@@ -1,17 +1,32 @@
1
- import { shallowRef as c, watchEffect as A } from "vue";
2
- function i(e) {
3
- return e ? Array.isArray(e) ? e : [e] : [];
1
+ import { shallowRef, watchEffect } from "vue";
2
+ function toArray(val) {
3
+ return val ? Array.isArray(val) ? val : [val] : [];
4
4
  }
5
- function s(e) {
6
- return typeof e == "string" ? e.toLowerCase() : e;
5
+ function normalizeAction(action) {
6
+ if (typeof action === "string") {
7
+ return action.toLowerCase();
8
+ }
9
+ return action;
7
10
  }
8
- function w(e, a, u) {
9
- const n = c(/* @__PURE__ */ new Set()), r = c(/* @__PURE__ */ new Set());
10
- return A(() => {
11
- const h = i(a?.value ?? e.value).map(s), f = i(u?.value ?? e.value).map(s), t = new Set(h), o = new Set(f);
12
- t.has("hover") && !t.has("click") && t.add("touch"), o.has("hover") && !o.has("click") && o.add("touch"), n.value = t, r.value = o;
13
- }), [n, r];
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
- w as default
31
+ useAction as default
17
32
  };