@v-c/trigger 1.0.11 → 1.0.12-beta.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.
@@ -10,6 +10,7 @@ function useWatch(open, target, popup, onAlign, onScroll) {
10
10
  await nextTick();
11
11
  const targetElement = target.value;
12
12
  const popupElement = popup.value;
13
+ if (!targetElement || !popupElement) return;
13
14
  const targetScrollList = collectScroller(targetElement);
14
15
  const popupScrollList = collectScroller(popupElement);
15
16
  const win = getWin(popupElement);
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { useResizeObserver } from "@v-c/resize-observer";
13
13
  import { classNames } from "@v-c/util";
14
14
  import { getShadowRoot } from "@v-c/util/dist/Dom/shadow";
15
15
  import { filterEmpty } from "@v-c/util/dist/props-util";
16
- import { resolveToElement } from "@v-c/util/dist/vnode";
16
+ import { cloneElement, resolveToElement } from "@v-c/util/dist/vnode";
17
17
  var defaults = {
18
18
  prefixCls: "vc-trigger-popup",
19
19
  action: "hover",
@@ -48,11 +48,14 @@ function generateTrigger(PortalComponent = Portal) {
48
48
  parentContext?.value?.registerSubPopup(id, element ?? null);
49
49
  };
50
50
  const targetEle = shallowRef();
51
+ const persistTargetEle = shallowRef();
52
+ const mergedTargetEle = computed(() => targetEle.value ?? persistTargetEle.value);
51
53
  const externalForwardRef = shallowRef(null);
52
54
  const setTargetRef = (node) => {
53
55
  const element = resolveToElement(node);
54
56
  if (element && targetEle.value !== element) {
55
57
  targetEle.value = element;
58
+ persistTargetEle.value = element;
56
59
  externalForwardRef.value = element;
57
60
  } else if (!element) {
58
61
  targetEle.value = void 0;
@@ -67,7 +70,7 @@ function generateTrigger(PortalComponent = Portal) {
67
70
  ...hoverActionProps.value
68
71
  }));
69
72
  const inPopupOrChild = (ele) => {
70
- const childDOM = targetEle.value;
73
+ const childDOM = mergedTargetEle.value;
71
74
  return childDOM?.contains(ele) || childDOM && getShadowRoot(childDOM)?.host === ele || ele === childDOM || popupEle.value?.contains(ele) || popupEle.value && getShadowRoot(popupEle.value)?.host === ele || ele === popupEle.value || Object.values(subPopupElements.value).some((subPopupEle) => subPopupEle?.contains(ele) || ele === subPopupEle);
72
75
  };
73
76
  const innerArrow = computed(() => {
@@ -88,7 +91,7 @@ function generateTrigger(PortalComponent = Portal) {
88
91
  const getUniqueOptions = (delay = 0) => {
89
92
  return {
90
93
  popup: props.popup,
91
- target: targetEle.value,
94
+ target: mergedTargetEle.value,
92
95
  delay,
93
96
  prefixCls: props.prefixCls,
94
97
  popupClassName: props.popupClassName,
@@ -110,8 +113,8 @@ function generateTrigger(PortalComponent = Portal) {
110
113
  onEsc
111
114
  };
112
115
  };
113
- watch([mergedOpen, targetEle], () => {
114
- if (uniqueContext && props.unique && targetEle.value && !openUncontrolled.value && !parentContext?.value) if (mergedOpen.value) {
116
+ watch([mergedOpen, mergedTargetEle], () => {
117
+ if (uniqueContext && props.unique && mergedTargetEle.value && !openUncontrolled.value && !parentContext?.value) if (mergedOpen.value) {
115
118
  const enterDelay = props.mouseEnterDelay ?? 0;
116
119
  uniqueContext?.show(getUniqueOptions(enterDelay), isOpen);
117
120
  } else uniqueContext?.hide(props.mouseLeaveDelay || 0);
@@ -156,7 +159,7 @@ function generateTrigger(PortalComponent = Portal) {
156
159
  const setMousePosByEvent = (event) => {
157
160
  mousePos.value = [event.clientX, event.clientY];
158
161
  };
159
- const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, scaleX, scaleY, alignInfo, onAlign] = useAlign(mergedOpen, popupEle, computed(() => props?.alignPoint && mousePos.value !== null ? mousePos.value : targetEle.value), computed(() => props?.popupPlacement), computed(() => props?.builtinPlacements), computed(() => props?.popupAlign), props?.onPopupAlign, isMobile);
162
+ const [ready, offsetX, offsetY, offsetR, offsetB, arrowX, arrowY, scaleX, scaleY, alignInfo, onAlign] = useAlign(mergedOpen, popupEle, computed(() => props?.alignPoint && mousePos.value !== null ? mousePos.value : mergedTargetEle.value), computed(() => props?.popupPlacement), computed(() => props?.builtinPlacements), computed(() => props?.popupAlign), props?.onPopupAlign, isMobile);
160
163
  const [showActions, hideActions] = useAction(computed(() => props.action), computed(() => props.showAction), computed(() => props.hideAction));
161
164
  const clickToShow = computed(() => showActions.value?.has("click"));
162
165
  const clickToHide = computed(() => hideActions.value?.has("click") || hideActions.value?.has("contextmenu"));
@@ -167,7 +170,7 @@ function generateTrigger(PortalComponent = Portal) {
167
170
  const onScroll = () => {
168
171
  if (openRef.value && props?.alignPoint && clickToHide.value) triggerOpen(false);
169
172
  };
170
- useWatch(mergedOpen, targetEle, popupEle, triggerAlign, onScroll);
173
+ useWatch(mergedOpen, mergedTargetEle, popupEle, triggerAlign, onScroll);
171
174
  watch([mousePos, () => props.popupPlacement], async () => {
172
175
  await nextTick();
173
176
  triggerAlign();
@@ -188,8 +191,8 @@ function generateTrigger(PortalComponent = Portal) {
188
191
  const targetWidth = shallowRef(0);
189
192
  const targetHeight = shallowRef(0);
190
193
  const syncTargetSize = () => {
191
- if (props.stretch && targetEle.value) {
192
- const rect = targetEle.value.getBoundingClientRect();
194
+ if (props.stretch && mergedTargetEle.value) {
195
+ const rect = mergedTargetEle.value.getBoundingClientRect();
193
196
  targetWidth.value = rect.width;
194
197
  targetHeight.value = rect.height;
195
198
  }
@@ -326,20 +329,20 @@ function generateTrigger(PortalComponent = Portal) {
326
329
  x: arrowX.value,
327
330
  y: arrowY.value
328
331
  };
329
- const triggerNode = createVNode(child, {
332
+ const triggerNode = cloneElement(child, {
330
333
  ...mergedChildrenProps,
331
334
  ...passedProps,
332
335
  ref: setTargetRef
333
- });
336
+ }, true, true);
334
337
  const { unique, prefixCls, popup, popupClassName, popupStyle, zIndex, fresh, onPopupClick, mask, popupMotion, maskMotion, forceRender, getPopupContainer, stretch, mobile } = props;
335
- return createVNode(Fragment, null, [triggerNode, rendedRef.value && targetEle.value && (!uniqueContext || !unique) && createVNode(TriggerContextProvider, context.value, { default: () => [createVNode(Popup_default, {
338
+ return createVNode(Fragment, null, [triggerNode, rendedRef.value && mergedTargetEle.value && (!uniqueContext || !unique) && createVNode(TriggerContextProvider, context.value, { default: () => [createVNode(Popup_default, {
336
339
  "portal": PortalComponent,
337
340
  "ref": setPopupRef,
338
341
  "prefixCls": prefixCls,
339
342
  "popup": popup,
340
343
  "className": classNames(popupClassName, !isMobile.value && alignedClassName.value),
341
344
  "style": popupStyle,
342
- "target": targetEle.value,
345
+ "target": mergedTargetEle.value,
343
346
  "onMouseEnter": onPopupMouseEnter,
344
347
  "onMouseLeave": onPopupMouseLeave,
345
348
  "onPointerEnter": onPopupMouseEnter,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@v-c/trigger",
3
3
  "type": "module",
4
- "version": "1.0.11",
4
+ "version": "1.0.12-beta.2",
5
5
  "description": "",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@v-c/portal": "^1.0.7",
33
33
  "@v-c/resize-observer": "^1.0.8",
34
- "@v-c/util": "^1.0.13"
34
+ "@v-c/util": "^1.0.17"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "vite build",