@rc-component/trigger 1.13.1 → 1.13.3

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,4 +1,5 @@
1
1
  import { warning } from 'rc-util';
2
+ import { getShadowRoot } from "rc-util/es/Dom/shadow";
2
3
  import raf from "rc-util/es/raf";
3
4
  import * as React from 'react';
4
5
  import { getWin } from "../util";
@@ -38,28 +39,29 @@ export default function useWinClick(open, clickToHide, targetEle, popupEle, mask
38
39
  }
39
40
  };
40
41
  var win = getWin(popupEle);
41
- var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode();
42
42
  win.addEventListener('mousedown', onWindowMouseDown);
43
43
  win.addEventListener('click', onWindowClick);
44
44
 
45
45
  // shadow root
46
- var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument;
47
- if (inShadow) {
48
- targetRoot.addEventListener('mousedown', onWindowMouseDown);
49
- targetRoot.addEventListener('click', onWindowClick);
46
+ var targetShadowRoot = getShadowRoot(targetEle);
47
+ if (targetShadowRoot) {
48
+ targetShadowRoot.addEventListener('mousedown', onWindowMouseDown);
49
+ targetShadowRoot.addEventListener('click', onWindowClick);
50
50
  }
51
51
 
52
52
  // Warning if target and popup not in same root
53
53
  if (process.env.NODE_ENV !== 'production') {
54
- var popupRoot = popupEle.getRootNode();
54
+ var _targetEle$getRootNod, _popupEle$getRootNode;
55
+ var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : (_targetEle$getRootNod = targetEle.getRootNode) === null || _targetEle$getRootNod === void 0 ? void 0 : _targetEle$getRootNod.call(targetEle);
56
+ var popupRoot = (_popupEle$getRootNode = popupEle.getRootNode) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.call(popupEle);
55
57
  warning(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
56
58
  }
57
59
  return function () {
58
60
  win.removeEventListener('mousedown', onWindowMouseDown);
59
61
  win.removeEventListener('click', onWindowClick);
60
- if (inShadow) {
61
- targetRoot.removeEventListener('mousedown', onWindowMouseDown);
62
- targetRoot.removeEventListener('click', onWindowClick);
62
+ if (targetShadowRoot) {
63
+ targetShadowRoot.removeEventListener('mousedown', onWindowMouseDown);
64
+ targetShadowRoot.removeEventListener('click', onWindowClick);
63
65
  }
64
66
  };
65
67
  }
package/es/index.js CHANGED
@@ -6,6 +6,7 @@ import Portal from '@rc-component/portal';
6
6
  import classNames from 'classnames';
7
7
  import ResizeObserver from 'rc-resize-observer';
8
8
  import { isDOM } from "rc-util/es/Dom/findDOMNode";
9
+ import { getShadowRoot } from "rc-util/es/Dom/shadow";
9
10
  import useEvent from "rc-util/es/hooks/useEvent";
10
11
  import useId from "rc-util/es/hooks/useId";
11
12
  import useLayoutEffect from "rc-util/es/hooks/useLayoutEffect";
@@ -121,9 +122,9 @@ export function generateTrigger() {
121
122
  var originChildProps = (child === null || child === void 0 ? void 0 : child.props) || {};
122
123
  var cloneProps = {};
123
124
  var inPopupOrChild = useEvent(function (ele) {
124
- var _childDOM$getRootNode, _popupEle$getRootNode;
125
+ var _getShadowRoot, _getShadowRoot2;
125
126
  var childDOM = targetEle;
126
- return (childDOM === null || childDOM === void 0 ? void 0 : childDOM.contains(ele)) || (childDOM === null || childDOM === void 0 ? void 0 : (_childDOM$getRootNode = childDOM.getRootNode()) === null || _childDOM$getRootNode === void 0 ? void 0 : _childDOM$getRootNode.host) === ele || ele === childDOM || (popupEle === null || popupEle === void 0 ? void 0 : popupEle.contains(ele)) || (popupEle === null || popupEle === void 0 ? void 0 : (_popupEle$getRootNode = popupEle.getRootNode()) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.host) === ele || ele === popupEle || Object.values(subPopupElements.current).some(function (subPopupEle) {
127
+ return (childDOM === null || childDOM === void 0 ? void 0 : childDOM.contains(ele)) || ((_getShadowRoot = getShadowRoot(childDOM)) === null || _getShadowRoot === void 0 ? void 0 : _getShadowRoot.host) === ele || ele === childDOM || (popupEle === null || popupEle === void 0 ? void 0 : popupEle.contains(ele)) || ((_getShadowRoot2 = getShadowRoot(popupEle)) === null || _getShadowRoot2 === void 0 ? void 0 : _getShadowRoot2.host) === ele || ele === popupEle || Object.values(subPopupElements.current).some(function (subPopupEle) {
127
128
  return (subPopupEle === null || subPopupEle === void 0 ? void 0 : subPopupEle.contains(ele)) || ele === subPopupEle;
128
129
  });
129
130
  });
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = useWinClick;
9
9
  var _rcUtil = require("rc-util");
10
+ var _shadow = require("rc-util/lib/Dom/shadow");
10
11
  var _raf = _interopRequireDefault(require("rc-util/lib/raf"));
11
12
  var React = _interopRequireWildcard(require("react"));
12
13
  var _util = require("../util");
@@ -46,28 +47,29 @@ function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable,
46
47
  }
47
48
  };
48
49
  var win = (0, _util.getWin)(popupEle);
49
- var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : targetEle.getRootNode();
50
50
  win.addEventListener('mousedown', onWindowMouseDown);
51
51
  win.addEventListener('click', onWindowClick);
52
52
 
53
53
  // shadow root
54
- var inShadow = targetRoot && targetRoot !== targetEle.ownerDocument;
55
- if (inShadow) {
56
- targetRoot.addEventListener('mousedown', onWindowMouseDown);
57
- targetRoot.addEventListener('click', onWindowClick);
54
+ var targetShadowRoot = (0, _shadow.getShadowRoot)(targetEle);
55
+ if (targetShadowRoot) {
56
+ targetShadowRoot.addEventListener('mousedown', onWindowMouseDown);
57
+ targetShadowRoot.addEventListener('click', onWindowClick);
58
58
  }
59
59
 
60
60
  // Warning if target and popup not in same root
61
61
  if (process.env.NODE_ENV !== 'production') {
62
- var popupRoot = popupEle.getRootNode();
62
+ var _targetEle$getRootNod, _popupEle$getRootNode;
63
+ var targetRoot = targetEle === null || targetEle === void 0 ? void 0 : (_targetEle$getRootNod = targetEle.getRootNode) === null || _targetEle$getRootNod === void 0 ? void 0 : _targetEle$getRootNod.call(targetEle);
64
+ var popupRoot = (_popupEle$getRootNode = popupEle.getRootNode) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.call(popupEle);
63
65
  (0, _rcUtil.warning)(targetRoot === popupRoot, "trigger element and popup element should in same shadow root.");
64
66
  }
65
67
  return function () {
66
68
  win.removeEventListener('mousedown', onWindowMouseDown);
67
69
  win.removeEventListener('click', onWindowClick);
68
- if (inShadow) {
69
- targetRoot.removeEventListener('mousedown', onWindowMouseDown);
70
- targetRoot.removeEventListener('click', onWindowClick);
70
+ if (targetShadowRoot) {
71
+ targetShadowRoot.removeEventListener('mousedown', onWindowMouseDown);
72
+ targetShadowRoot.removeEventListener('click', onWindowClick);
71
73
  }
72
74
  };
73
75
  }
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ var _portal = _interopRequireDefault(require("@rc-component/portal"));
14
14
  var _classnames = _interopRequireDefault(require("classnames"));
15
15
  var _rcResizeObserver = _interopRequireDefault(require("rc-resize-observer"));
16
16
  var _findDOMNode = require("rc-util/lib/Dom/findDOMNode");
17
+ var _shadow = require("rc-util/lib/Dom/shadow");
17
18
  var _useEvent = _interopRequireDefault(require("rc-util/lib/hooks/useEvent"));
18
19
  var _useId = _interopRequireDefault(require("rc-util/lib/hooks/useId"));
19
20
  var _useLayoutEffect = _interopRequireDefault(require("rc-util/lib/hooks/useLayoutEffect"));
@@ -130,9 +131,9 @@ function generateTrigger() {
130
131
  var originChildProps = (child === null || child === void 0 ? void 0 : child.props) || {};
131
132
  var cloneProps = {};
132
133
  var inPopupOrChild = (0, _useEvent.default)(function (ele) {
133
- var _childDOM$getRootNode, _popupEle$getRootNode;
134
+ var _getShadowRoot, _getShadowRoot2;
134
135
  var childDOM = targetEle;
135
- return (childDOM === null || childDOM === void 0 ? void 0 : childDOM.contains(ele)) || (childDOM === null || childDOM === void 0 ? void 0 : (_childDOM$getRootNode = childDOM.getRootNode()) === null || _childDOM$getRootNode === void 0 ? void 0 : _childDOM$getRootNode.host) === ele || ele === childDOM || (popupEle === null || popupEle === void 0 ? void 0 : popupEle.contains(ele)) || (popupEle === null || popupEle === void 0 ? void 0 : (_popupEle$getRootNode = popupEle.getRootNode()) === null || _popupEle$getRootNode === void 0 ? void 0 : _popupEle$getRootNode.host) === ele || ele === popupEle || Object.values(subPopupElements.current).some(function (subPopupEle) {
136
+ return (childDOM === null || childDOM === void 0 ? void 0 : childDOM.contains(ele)) || ((_getShadowRoot = (0, _shadow.getShadowRoot)(childDOM)) === null || _getShadowRoot === void 0 ? void 0 : _getShadowRoot.host) === ele || ele === childDOM || (popupEle === null || popupEle === void 0 ? void 0 : popupEle.contains(ele)) || ((_getShadowRoot2 = (0, _shadow.getShadowRoot)(popupEle)) === null || _getShadowRoot2 === void 0 ? void 0 : _getShadowRoot2.host) === ele || ele === popupEle || Object.values(subPopupElements.current).some(function (subPopupEle) {
136
137
  return (subPopupEle === null || subPopupEle === void 0 ? void 0 : subPopupEle.contains(ele)) || ele === subPopupEle;
137
138
  });
138
139
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "1.13.1",
3
+ "version": "1.13.3",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"
@@ -66,7 +66,7 @@
66
66
  "rc-align": "^4.0.0",
67
67
  "rc-motion": "^2.0.0",
68
68
  "rc-resize-observer": "^1.3.1",
69
- "rc-util": "^5.29.2"
69
+ "rc-util": "^5.31.1"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "react": ">=16.9.0",