@rc-component/trigger 2.2.6 → 3.1.0

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,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { CSSMotionProps } from 'rc-motion';
2
+ import type { CSSMotionProps } from '@rc-component/motion';
3
3
  export type Placement = 'top' | 'left' | 'right' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom';
4
4
  export type AlignPointTopBottom = 't' | 'b' | 'c';
5
5
  export type AlignPointLeftRight = 'l' | 'r' | 'c';
package/lib/mock.js CHANGED
@@ -1,27 +1,24 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.default = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
7
  var React = _interopRequireWildcard(require("react"));
11
8
  var _index = require("./index");
12
- var MockPortal = function MockPortal(_ref) {
13
- var open = _ref.open,
14
- autoDestroy = _ref.autoDestroy,
15
- children = _ref.children,
16
- getContainer = _ref.getContainer;
17
- var _React$useState = React.useState(open),
18
- _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
19
- visible = _React$useState2[0],
20
- setVisible = _React$useState2[1];
21
- React.useEffect(function () {
22
- getContainer === null || getContainer === void 0 || getContainer();
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ const MockPortal = ({
12
+ open,
13
+ autoDestroy,
14
+ children,
15
+ getContainer
16
+ }) => {
17
+ const [visible, setVisible] = React.useState(open);
18
+ React.useEffect(() => {
19
+ getContainer?.();
23
20
  });
24
- React.useEffect(function () {
21
+ React.useEffect(() => {
25
22
  if (open) {
26
23
  setVisible(true);
27
24
  } else if (autoDestroy) {
package/lib/util.d.ts CHANGED
@@ -1,8 +1,5 @@
1
- import type { CSSMotionProps } from 'rc-motion';
2
- import type { AlignType, AnimationType, BuildInPlacements, TransitionNameType } from './interface';
1
+ import type { AlignType, BuildInPlacements } from './interface';
3
2
  export declare function getAlignPopupClassName(builtinPlacements: BuildInPlacements, prefixCls: string, align: AlignType, isAlignPoint: boolean): string;
4
- /** @deprecated We should not use this if we can refactor all deps */
5
- export declare function getMotion(prefixCls: string, motion: CSSMotionProps, animation: AnimationType, transitionName: TransitionNameType): CSSMotionProps;
6
3
  export declare function getWin(ele: HTMLElement): Window & typeof globalThis;
7
4
  /**
8
5
  * Get all the scrollable parent elements of the element
package/lib/util.js CHANGED
@@ -1,55 +1,32 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.collectScroller = collectScroller;
8
7
  exports.getAlignPopupClassName = getAlignPopupClassName;
9
- exports.getMotion = getMotion;
10
8
  exports.getVisibleArea = getVisibleArea;
11
9
  exports.getWin = getWin;
12
10
  exports.toNum = toNum;
13
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
14
- function isPointsEq() {
15
- var a1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
16
- var a2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
17
- var isAlignPoint = arguments.length > 2 ? arguments[2] : undefined;
11
+ function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
18
12
  if (isAlignPoint) {
19
13
  return a1[0] === a2[0];
20
14
  }
21
15
  return a1[0] === a2[0] && a1[1] === a2[1];
22
16
  }
23
17
  function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
24
- var points = align.points;
25
- var placements = Object.keys(builtinPlacements);
26
- for (var i = 0; i < placements.length; i += 1) {
27
- var _builtinPlacements$pl;
28
- var placement = placements[i];
29
- if (isPointsEq((_builtinPlacements$pl = builtinPlacements[placement]) === null || _builtinPlacements$pl === void 0 ? void 0 : _builtinPlacements$pl.points, points, isAlignPoint)) {
30
- return "".concat(prefixCls, "-placement-").concat(placement);
18
+ const {
19
+ points
20
+ } = align;
21
+ const placements = Object.keys(builtinPlacements);
22
+ for (let i = 0; i < placements.length; i += 1) {
23
+ const placement = placements[i];
24
+ if (isPointsEq(builtinPlacements[placement]?.points, points, isAlignPoint)) {
25
+ return `${prefixCls}-placement-${placement}`;
31
26
  }
32
27
  }
33
28
  return '';
34
29
  }
35
-
36
- /** @deprecated We should not use this if we can refactor all deps */
37
- function getMotion(prefixCls, motion, animation, transitionName) {
38
- if (motion) {
39
- return motion;
40
- }
41
- if (animation) {
42
- return {
43
- motionName: "".concat(prefixCls, "-").concat(animation)
44
- };
45
- }
46
- if (transitionName) {
47
- return {
48
- motionName: transitionName
49
- };
50
- }
51
- return null;
52
- }
53
30
  function getWin(ele) {
54
31
  return ele.ownerDocument.defaultView;
55
32
  }
@@ -60,25 +37,23 @@ function getWin(ele) {
60
37
  * @param areaOnly Only return the parent which will cut visible area
61
38
  */
62
39
  function collectScroller(ele) {
63
- var scrollerList = [];
64
- var current = ele === null || ele === void 0 ? void 0 : ele.parentElement;
65
- var scrollStyle = ['hidden', 'scroll', 'clip', 'auto'];
40
+ const scrollerList = [];
41
+ let current = ele?.parentElement;
42
+ const scrollStyle = ['hidden', 'scroll', 'clip', 'auto'];
66
43
  while (current) {
67
- var _getWin$getComputedSt = getWin(current).getComputedStyle(current),
68
- overflowX = _getWin$getComputedSt.overflowX,
69
- overflowY = _getWin$getComputedSt.overflowY,
70
- overflow = _getWin$getComputedSt.overflow;
71
- if ([overflowX, overflowY, overflow].some(function (o) {
72
- return scrollStyle.includes(o);
73
- })) {
44
+ const {
45
+ overflowX,
46
+ overflowY,
47
+ overflow
48
+ } = getWin(current).getComputedStyle(current);
49
+ if ([overflowX, overflowY, overflow].some(o => scrollStyle.includes(o))) {
74
50
  scrollerList.push(current);
75
51
  }
76
52
  current = current.parentElement;
77
53
  }
78
54
  return scrollerList;
79
55
  }
80
- function toNum(num) {
81
- var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
56
+ function toNum(num, defaultValue = 1) {
82
57
  return Number.isNaN(num) ? defaultValue : num;
83
58
  }
84
59
  function getPxValue(val) {
@@ -107,56 +82,61 @@ function getPxValue(val) {
107
82
  * Get visible area of element
108
83
  */
109
84
  function getVisibleArea(initArea, scrollerList) {
110
- var visibleArea = (0, _objectSpread2.default)({}, initArea);
111
- (scrollerList || []).forEach(function (ele) {
85
+ const visibleArea = {
86
+ ...initArea
87
+ };
88
+ (scrollerList || []).forEach(ele => {
112
89
  if (ele instanceof HTMLBodyElement || ele instanceof HTMLHtmlElement) {
113
90
  return;
114
91
  }
115
92
 
116
93
  // Skip if static position which will not affect visible area
117
- var _getWin$getComputedSt2 = getWin(ele).getComputedStyle(ele),
118
- overflow = _getWin$getComputedSt2.overflow,
119
- overflowClipMargin = _getWin$getComputedSt2.overflowClipMargin,
120
- borderTopWidth = _getWin$getComputedSt2.borderTopWidth,
121
- borderBottomWidth = _getWin$getComputedSt2.borderBottomWidth,
122
- borderLeftWidth = _getWin$getComputedSt2.borderLeftWidth,
123
- borderRightWidth = _getWin$getComputedSt2.borderRightWidth;
124
- var eleRect = ele.getBoundingClientRect();
125
- var eleOutHeight = ele.offsetHeight,
126
- eleInnerHeight = ele.clientHeight,
127
- eleOutWidth = ele.offsetWidth,
128
- eleInnerWidth = ele.clientWidth;
129
- var borderTopNum = getPxValue(borderTopWidth);
130
- var borderBottomNum = getPxValue(borderBottomWidth);
131
- var borderLeftNum = getPxValue(borderLeftWidth);
132
- var borderRightNum = getPxValue(borderRightWidth);
133
- var scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
134
- var scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
94
+ const {
95
+ overflow,
96
+ overflowClipMargin,
97
+ borderTopWidth,
98
+ borderBottomWidth,
99
+ borderLeftWidth,
100
+ borderRightWidth
101
+ } = getWin(ele).getComputedStyle(ele);
102
+ const eleRect = ele.getBoundingClientRect();
103
+ const {
104
+ offsetHeight: eleOutHeight,
105
+ clientHeight: eleInnerHeight,
106
+ offsetWidth: eleOutWidth,
107
+ clientWidth: eleInnerWidth
108
+ } = ele;
109
+ const borderTopNum = getPxValue(borderTopWidth);
110
+ const borderBottomNum = getPxValue(borderBottomWidth);
111
+ const borderLeftNum = getPxValue(borderLeftWidth);
112
+ const borderRightNum = getPxValue(borderRightWidth);
113
+ const scaleX = toNum(Math.round(eleRect.width / eleOutWidth * 1000) / 1000);
114
+ const scaleY = toNum(Math.round(eleRect.height / eleOutHeight * 1000) / 1000);
135
115
 
136
116
  // Original visible area
137
- var eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
138
- var eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
117
+ const eleScrollWidth = (eleOutWidth - eleInnerWidth - borderLeftNum - borderRightNum) * scaleX;
118
+ const eleScrollHeight = (eleOutHeight - eleInnerHeight - borderTopNum - borderBottomNum) * scaleY;
139
119
 
140
120
  // Cut border size
141
- var scaledBorderTopWidth = borderTopNum * scaleY;
142
- var scaledBorderBottomWidth = borderBottomNum * scaleY;
143
- var scaledBorderLeftWidth = borderLeftNum * scaleX;
144
- var scaledBorderRightWidth = borderRightNum * scaleX;
121
+ const scaledBorderTopWidth = borderTopNum * scaleY;
122
+ const scaledBorderBottomWidth = borderBottomNum * scaleY;
123
+ const scaledBorderLeftWidth = borderLeftNum * scaleX;
124
+ const scaledBorderRightWidth = borderRightNum * scaleX;
145
125
 
146
126
  // Clip margin
147
- var clipMarginWidth = 0;
148
- var clipMarginHeight = 0;
127
+ let clipMarginWidth = 0;
128
+ let clipMarginHeight = 0;
149
129
  if (overflow === 'clip') {
150
- var clipNum = getPxValue(overflowClipMargin);
130
+ const clipNum = getPxValue(overflowClipMargin);
151
131
  clipMarginWidth = clipNum * scaleX;
152
132
  clipMarginHeight = clipNum * scaleY;
153
133
  }
154
134
 
155
135
  // Region
156
- var eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
157
- var eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
158
- var eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
159
- var eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
136
+ const eleLeft = eleRect.x + scaledBorderLeftWidth - clipMarginWidth;
137
+ const eleTop = eleRect.y + scaledBorderTopWidth - clipMarginHeight;
138
+ const eleRight = eleLeft + eleRect.width + 2 * clipMarginWidth - scaledBorderLeftWidth - scaledBorderRightWidth - eleScrollWidth;
139
+ const eleBottom = eleTop + eleRect.height + 2 * clipMarginHeight - scaledBorderTopWidth - scaledBorderBottomWidth - eleScrollHeight;
160
140
  visibleArea.left = Math.max(visibleArea.left, eleLeft);
161
141
  visibleArea.top = Math.max(visibleArea.top, eleTop);
162
142
  visibleArea.right = Math.min(visibleArea.right, eleRight);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/trigger",
3
- "version": "2.2.6",
3
+ "version": "3.1.0",
4
4
  "description": "base abstract trigger component for react",
5
5
  "engines": {
6
6
  "node": ">=8.x"
@@ -33,7 +33,7 @@
33
33
  "start": "dumi dev",
34
34
  "build": "dumi build",
35
35
  "compile": "father build && lessc assets/index.less assets/index.css",
36
- "prepublishOnly": "npm run compile && np --yolo --no-publish",
36
+ "prepublishOnly": "npm run compile && rc-np",
37
37
  "lint": "eslint src/ docs/examples/ --ext .tsx,.ts,.jsx,.js",
38
38
  "test": "rc-test",
39
39
  "prettier": "prettier --write .",
@@ -41,21 +41,21 @@
41
41
  "now-build": "npm run build"
42
42
  },
43
43
  "devDependencies": {
44
- "@rc-component/father-plugin": "^1.0.0",
44
+ "@rc-component/father-plugin": "^2.0.0",
45
+ "@rc-component/np": "^1.0.3",
45
46
  "@testing-library/jest-dom": "^6.1.4",
46
47
  "@testing-library/react": "^16.0.0",
47
48
  "@types/classnames": "^2.2.10",
48
49
  "@types/jest": "^29.5.2",
49
50
  "@types/node": "^22.0.2",
50
51
  "@types/react": "^18.0.0",
51
- "@types/react-dom": "^18.0.11",
52
+ "@types/react-dom": "^18.0.0",
52
53
  "@umijs/fabric": "^4.0.1",
53
54
  "cross-env": "^7.0.1",
54
55
  "dumi": "^2.1.0",
55
56
  "eslint": "^8.51.0",
56
57
  "father": "^4.0.0",
57
58
  "less": "^4.2.0",
58
- "np": "^10.0.5",
59
59
  "prettier": "^3.3.3",
60
60
  "rc-test": "^7.0.13",
61
61
  "react": "^18.0.0",
@@ -64,15 +64,14 @@
64
64
  "typescript": "^5.1.6"
65
65
  },
66
66
  "dependencies": {
67
- "@babel/runtime": "^7.23.2",
68
- "@rc-component/portal": "^1.1.0",
69
- "classnames": "^2.3.2",
70
- "rc-motion": "^2.0.0",
71
- "rc-resize-observer": "^1.3.1",
72
- "rc-util": "^5.44.0"
67
+ "@rc-component/motion": "^1.1.4",
68
+ "@rc-component/portal": "^2.0.0",
69
+ "@rc-component/resize-observer": "^1.0.0",
70
+ "@rc-component/util": "^1.2.1",
71
+ "classnames": "^2.3.2"
73
72
  },
74
73
  "peerDependencies": {
75
74
  "react": ">=16.9.0",
76
75
  "react-dom": ">=16.9.0"
77
76
  }
78
- }
77
+ }