@rc-component/util 1.0.0 → 1.0.1

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.
Files changed (76) hide show
  1. package/es/Children/toArray.js +3 -4
  2. package/es/Dom/contains.js +1 -1
  3. package/es/Dom/dynamicCSS.js +50 -60
  4. package/es/Dom/findDOMNode.js +3 -5
  5. package/es/Dom/focus.js +13 -21
  6. package/es/Dom/isVisible.js +10 -8
  7. package/es/Dom/scrollLocker.js +63 -89
  8. package/es/Dom/shadow.js +1 -2
  9. package/es/Dom/styleChecker.js +9 -9
  10. package/es/KeyCode.js +4 -2
  11. package/es/Portal.js +15 -16
  12. package/es/PortalWrapper.js +150 -175
  13. package/es/React/isFragment.js +4 -5
  14. package/es/React/render.js +32 -63
  15. package/es/composeProps.js +9 -16
  16. package/es/getScrollBarSize.js +19 -15
  17. package/es/hooks/useEffect.js +3 -5
  18. package/es/hooks/useEvent.js +2 -8
  19. package/es/hooks/useId.js +10 -23
  20. package/es/hooks/useLayoutEffect.js +8 -8
  21. package/es/hooks/useMemo.js +1 -1
  22. package/es/hooks/useMergedState.js +23 -34
  23. package/es/hooks/useMobile.js +3 -12
  24. package/es/hooks/useState.js +4 -13
  25. package/es/hooks/useSyncState.js +4 -14
  26. package/es/isEqual.js +9 -14
  27. package/es/isMobile.js +3 -3
  28. package/es/omit.js +2 -2
  29. package/es/pickAttrs.js +29 -17
  30. package/es/proxyObject.js +2 -2
  31. package/es/raf.js +12 -23
  32. package/es/ref.js +16 -30
  33. package/es/setStyle.js +8 -8
  34. package/es/test/domHook.js +19 -25
  35. package/es/utils/get.js +2 -2
  36. package/es/utils/set.js +19 -38
  37. package/es/warning.js +7 -11
  38. package/lib/Children/toArray.js +3 -4
  39. package/lib/Dom/contains.js +1 -1
  40. package/lib/Dom/dynamicCSS.js +50 -60
  41. package/lib/Dom/findDOMNode.js +3 -5
  42. package/lib/Dom/focus.js +13 -21
  43. package/lib/Dom/isVisible.js +12 -9
  44. package/lib/Dom/scrollLocker.js +64 -88
  45. package/lib/Dom/shadow.js +1 -2
  46. package/lib/Dom/styleChecker.js +9 -9
  47. package/lib/KeyCode.js +4 -2
  48. package/lib/Portal.js +15 -16
  49. package/lib/PortalWrapper.js +154 -177
  50. package/lib/React/isFragment.js +4 -5
  51. package/lib/React/render.js +34 -65
  52. package/lib/composeProps.js +9 -16
  53. package/lib/getScrollBarSize.js +19 -15
  54. package/lib/hooks/useEffect.js +5 -8
  55. package/lib/hooks/useEvent.js +4 -11
  56. package/lib/hooks/useId.js +12 -25
  57. package/lib/hooks/useLayoutEffect.js +11 -11
  58. package/lib/hooks/useMemo.js +3 -4
  59. package/lib/hooks/useMergedState.js +24 -35
  60. package/lib/hooks/useMobile.js +3 -12
  61. package/lib/hooks/useState.js +6 -16
  62. package/lib/hooks/useSyncState.js +6 -17
  63. package/lib/index.js +8 -8
  64. package/lib/isEqual.js +9 -14
  65. package/lib/isMobile.js +5 -4
  66. package/lib/omit.js +2 -2
  67. package/lib/pickAttrs.js +29 -17
  68. package/lib/proxyObject.js +2 -2
  69. package/lib/raf.js +12 -23
  70. package/lib/ref.js +23 -31
  71. package/lib/setStyle.js +8 -8
  72. package/lib/test/domHook.js +19 -25
  73. package/lib/utils/get.js +2 -2
  74. package/lib/utils/set.js +19 -38
  75. package/lib/warning.js +8 -11
  76. package/package.json +3 -3
package/es/Portal.js CHANGED
@@ -1,20 +1,20 @@
1
1
  import { useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import canUseDom from "./Dom/canUseDom";
4
- var Portal = /*#__PURE__*/forwardRef(function (props, ref) {
5
- var didUpdate = props.didUpdate,
6
- getContainer = props.getContainer,
7
- children = props.children;
8
- var parentRef = useRef();
9
- var containerRef = useRef();
4
+ const Portal = /*#__PURE__*/forwardRef((props, ref) => {
5
+ const {
6
+ didUpdate,
7
+ getContainer,
8
+ children
9
+ } = props;
10
+ const parentRef = useRef();
11
+ const containerRef = useRef();
10
12
 
11
13
  // Ref return nothing, only for wrapper check exist
12
- useImperativeHandle(ref, function () {
13
- return {};
14
- });
14
+ useImperativeHandle(ref, () => ({}));
15
15
 
16
16
  // Create container in client side with sync to avoid useEffect not get ref
17
- var initRef = useRef(false);
17
+ const initRef = useRef(false);
18
18
  if (!initRef.current && canUseDom()) {
19
19
  containerRef.current = getContainer();
20
20
  parentRef.current = containerRef.current.parentNode;
@@ -22,21 +22,20 @@ var Portal = /*#__PURE__*/forwardRef(function (props, ref) {
22
22
  }
23
23
 
24
24
  // [Legacy] Used by `rc-trigger`
25
- useEffect(function () {
26
- didUpdate === null || didUpdate === void 0 || didUpdate(props);
25
+ useEffect(() => {
26
+ didUpdate?.(props);
27
27
  });
28
- useEffect(function () {
28
+ useEffect(() => {
29
29
  // Restore container to original place
30
30
  // React 18 StrictMode will unmount first and mount back for effect test:
31
31
  // https://reactjs.org/blog/2022/03/29/react-v18.html#new-strict-mode-behaviors
32
32
  if (containerRef.current.parentNode === null && parentRef.current !== null) {
33
33
  parentRef.current.appendChild(containerRef.current);
34
34
  }
35
- return function () {
36
- var _containerRef$current;
35
+ return () => {
37
36
  // [Legacy] This should not be handle by Portal but parent PortalWrapper instead.
38
37
  // Since some component use `Portal` directly, we have to keep the logic here.
39
- (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 || (_containerRef$current = _containerRef$current.parentNode) === null || _containerRef$current === void 0 || _containerRef$current.removeChild(containerRef.current);
38
+ containerRef.current?.parentNode?.removeChild(containerRef.current);
40
39
  };
41
40
  }, []);
42
41
  return containerRef.current ? /*#__PURE__*/ReactDOM.createPortal(children, containerRef.current) : null;
@@ -1,17 +1,3 @@
1
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
5
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
8
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
9
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
11
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
15
1
  /* eslint-disable no-underscore-dangle,react/require-default-props */
16
2
  import * as React from 'react';
17
3
  import raf from "./raf";
@@ -19,8 +5,8 @@ import Portal from "./Portal";
19
5
  import canUseDom from "./Dom/canUseDom";
20
6
  import setStyle from "./setStyle";
21
7
  import ScrollLocker from "./Dom/scrollLocker";
22
- var openCount = 0;
23
- var supportDom = canUseDom();
8
+ let openCount = 0;
9
+ const supportDom = canUseDom();
24
10
 
25
11
  /** @private Test usage only */
26
12
  export function getOpenCount() {
@@ -29,8 +15,8 @@ export function getOpenCount() {
29
15
 
30
16
  // https://github.com/ant-design/ant-design/issues/19340
31
17
  // https://github.com/ant-design/ant-design/issues/19332
32
- var cacheOverflow = {};
33
- var getParent = function getParent(getContainer) {
18
+ let cacheOverflow = {};
19
+ const getParent = getContainer => {
34
20
  if (!supportDom) {
35
21
  return null;
36
22
  }
@@ -41,177 +27,166 @@ var getParent = function getParent(getContainer) {
41
27
  if (typeof getContainer === 'function') {
42
28
  return getContainer();
43
29
  }
44
- if (_typeof(getContainer) === 'object' && getContainer instanceof window.HTMLElement) {
30
+ if (typeof getContainer === 'object' && getContainer instanceof window.HTMLElement) {
45
31
  return getContainer;
46
32
  }
47
33
  }
48
34
  return document.body;
49
35
  };
50
- var PortalWrapper = /*#__PURE__*/function (_React$Component) {
51
- _inherits(PortalWrapper, _React$Component);
52
- var _super = _createSuper(PortalWrapper);
53
- function PortalWrapper(props) {
54
- var _this;
55
- _classCallCheck(this, PortalWrapper);
56
- _this = _super.call(this, props);
57
- _defineProperty(_assertThisInitialized(_this), "container", void 0);
58
- _defineProperty(_assertThisInitialized(_this), "componentRef", /*#__PURE__*/React.createRef());
59
- _defineProperty(_assertThisInitialized(_this), "rafId", void 0);
60
- _defineProperty(_assertThisInitialized(_this), "scrollLocker", void 0);
61
- _defineProperty(_assertThisInitialized(_this), "renderComponent", void 0);
62
- _defineProperty(_assertThisInitialized(_this), "updateScrollLocker", function (prevProps) {
63
- var _ref = prevProps || {},
64
- prevVisible = _ref.visible;
65
- var _this$props = _this.props,
66
- getContainer = _this$props.getContainer,
67
- visible = _this$props.visible;
68
- if (visible && visible !== prevVisible && supportDom && getParent(getContainer) !== _this.scrollLocker.getContainer()) {
69
- _this.scrollLocker.reLock({
70
- container: getParent(getContainer)
71
- });
72
- }
36
+ class PortalWrapper extends React.Component {
37
+ container;
38
+ componentRef = /*#__PURE__*/React.createRef();
39
+ rafId;
40
+ scrollLocker;
41
+ constructor(props) {
42
+ super(props);
43
+ this.scrollLocker = new ScrollLocker({
44
+ container: getParent(props.getContainer)
73
45
  });
74
- _defineProperty(_assertThisInitialized(_this), "updateOpenCount", function (prevProps) {
75
- var _ref2 = prevProps || {},
76
- prevVisible = _ref2.visible,
77
- prevGetContainer = _ref2.getContainer;
78
- var _this$props2 = _this.props,
79
- visible = _this$props2.visible,
80
- getContainer = _this$props2.getContainer;
46
+ }
47
+ renderComponent;
48
+ componentDidMount() {
49
+ this.updateOpenCount();
50
+ if (!this.attachToParent()) {
51
+ this.rafId = raf(() => {
52
+ this.forceUpdate();
53
+ });
54
+ }
55
+ }
56
+ componentDidUpdate(prevProps) {
57
+ this.updateOpenCount(prevProps);
58
+ this.updateScrollLocker(prevProps);
59
+ this.setWrapperClassName();
60
+ this.attachToParent();
61
+ }
62
+ updateScrollLocker = prevProps => {
63
+ const {
64
+ visible: prevVisible
65
+ } = prevProps || {};
66
+ const {
67
+ getContainer,
68
+ visible
69
+ } = this.props;
70
+ if (visible && visible !== prevVisible && supportDom && getParent(getContainer) !== this.scrollLocker.getContainer()) {
71
+ this.scrollLocker.reLock({
72
+ container: getParent(getContainer)
73
+ });
74
+ }
75
+ };
76
+ updateOpenCount = prevProps => {
77
+ const {
78
+ visible: prevVisible,
79
+ getContainer: prevGetContainer
80
+ } = prevProps || {};
81
+ const {
82
+ visible,
83
+ getContainer
84
+ } = this.props;
81
85
 
82
- // Update count
83
- if (visible !== prevVisible && supportDom && getParent(getContainer) === document.body) {
84
- if (visible && !prevVisible) {
85
- openCount += 1;
86
- } else if (prevProps) {
87
- openCount -= 1;
88
- }
86
+ // Update count
87
+ if (visible !== prevVisible && supportDom && getParent(getContainer) === document.body) {
88
+ if (visible && !prevVisible) {
89
+ openCount += 1;
90
+ } else if (prevProps) {
91
+ openCount -= 1;
89
92
  }
93
+ }
90
94
 
91
- // Clean up container if needed
92
- var getContainerIsFunc = typeof getContainer === 'function' && typeof prevGetContainer === 'function';
93
- if (getContainerIsFunc ? getContainer.toString() !== prevGetContainer.toString() : getContainer !== prevGetContainer) {
94
- _this.removeCurrentContainer();
95
- }
96
- });
97
- _defineProperty(_assertThisInitialized(_this), "attachToParent", function () {
98
- var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
99
- if (force || _this.container && !_this.container.parentNode) {
100
- var parent = getParent(_this.props.getContainer);
101
- if (parent) {
102
- parent.appendChild(_this.container);
103
- return true;
104
- }
105
- return false;
106
- }
107
- return true;
108
- });
109
- _defineProperty(_assertThisInitialized(_this), "getContainer", function () {
110
- if (!supportDom) {
111
- return null;
112
- }
113
- if (!_this.container) {
114
- _this.container = document.createElement('div');
115
- _this.attachToParent(true);
116
- }
117
- _this.setWrapperClassName();
118
- return _this.container;
119
- });
120
- _defineProperty(_assertThisInitialized(_this), "setWrapperClassName", function () {
121
- var wrapperClassName = _this.props.wrapperClassName;
122
- if (_this.container && wrapperClassName && wrapperClassName !== _this.container.className) {
123
- _this.container.className = wrapperClassName;
124
- }
125
- });
126
- _defineProperty(_assertThisInitialized(_this), "removeCurrentContainer", function () {
127
- var _this$container;
128
- // Portal will remove from `parentNode`.
129
- // Let's handle this again to avoid refactor issue.
130
- (_this$container = _this.container) === null || _this$container === void 0 || (_this$container = _this$container.parentNode) === null || _this$container === void 0 || _this$container.removeChild(_this.container);
131
- });
132
- /**
133
- * Enhance ./switchScrollingEffect
134
- * 1. Simulate document body scroll bar with
135
- * 2. Record body has overflow style and recover when all of PortalWrapper invisible
136
- * 3. Disable body scroll when PortalWrapper has open
137
- *
138
- * @memberof PortalWrapper
139
- */
140
- _defineProperty(_assertThisInitialized(_this), "switchScrollingEffect", function () {
141
- if (openCount === 1 && !Object.keys(cacheOverflow).length) {
142
- // Must be set after switchScrollingEffect
143
- cacheOverflow = setStyle({
144
- overflow: 'hidden',
145
- overflowX: 'hidden',
146
- overflowY: 'hidden'
147
- });
148
- } else if (!openCount) {
149
- setStyle(cacheOverflow);
150
- cacheOverflow = {};
151
- }
152
- });
153
- _this.scrollLocker = new ScrollLocker({
154
- container: getParent(props.getContainer)
155
- });
156
- return _this;
95
+ // Clean up container if needed
96
+ const getContainerIsFunc = typeof getContainer === 'function' && typeof prevGetContainer === 'function';
97
+ if (getContainerIsFunc ? getContainer.toString() !== prevGetContainer.toString() : getContainer !== prevGetContainer) {
98
+ this.removeCurrentContainer();
99
+ }
100
+ };
101
+ componentWillUnmount() {
102
+ const {
103
+ visible,
104
+ getContainer
105
+ } = this.props;
106
+ if (supportDom && getParent(getContainer) === document.body) {
107
+ // 离开时不会 render, 导到离开时数值不变,改用 func 。。
108
+ openCount = visible && openCount ? openCount - 1 : openCount;
109
+ }
110
+ this.removeCurrentContainer();
111
+ raf.cancel(this.rafId);
157
112
  }
158
- _createClass(PortalWrapper, [{
159
- key: "componentDidMount",
160
- value: function componentDidMount() {
161
- var _this2 = this;
162
- this.updateOpenCount();
163
- if (!this.attachToParent()) {
164
- this.rafId = raf(function () {
165
- _this2.forceUpdate();
166
- });
113
+ attachToParent = (force = false) => {
114
+ if (force || this.container && !this.container.parentNode) {
115
+ const parent = getParent(this.props.getContainer);
116
+ if (parent) {
117
+ parent.appendChild(this.container);
118
+ return true;
167
119
  }
120
+ return false;
168
121
  }
169
- }, {
170
- key: "componentDidUpdate",
171
- value: function componentDidUpdate(prevProps) {
172
- this.updateOpenCount(prevProps);
173
- this.updateScrollLocker(prevProps);
174
- this.setWrapperClassName();
175
- this.attachToParent();
122
+ return true;
123
+ };
124
+ getContainer = () => {
125
+ if (!supportDom) {
126
+ return null;
176
127
  }
177
- }, {
178
- key: "componentWillUnmount",
179
- value: function componentWillUnmount() {
180
- var _this$props3 = this.props,
181
- visible = _this$props3.visible,
182
- getContainer = _this$props3.getContainer;
183
- if (supportDom && getParent(getContainer) === document.body) {
184
- // 离开时不会 render, 导到离开时数值不变,改用 func 。。
185
- openCount = visible && openCount ? openCount - 1 : openCount;
186
- }
187
- this.removeCurrentContainer();
188
- raf.cancel(this.rafId);
128
+ if (!this.container) {
129
+ this.container = document.createElement('div');
130
+ this.attachToParent(true);
131
+ }
132
+ this.setWrapperClassName();
133
+ return this.container;
134
+ };
135
+ setWrapperClassName = () => {
136
+ const {
137
+ wrapperClassName
138
+ } = this.props;
139
+ if (this.container && wrapperClassName && wrapperClassName !== this.container.className) {
140
+ this.container.className = wrapperClassName;
141
+ }
142
+ };
143
+ removeCurrentContainer = () => {
144
+ // Portal will remove from `parentNode`.
145
+ // Let's handle this again to avoid refactor issue.
146
+ this.container?.parentNode?.removeChild(this.container);
147
+ };
148
+
149
+ /**
150
+ * Enhance ./switchScrollingEffect
151
+ * 1. Simulate document body scroll bar with
152
+ * 2. Record body has overflow style and recover when all of PortalWrapper invisible
153
+ * 3. Disable body scroll when PortalWrapper has open
154
+ *
155
+ * @memberof PortalWrapper
156
+ */
157
+ switchScrollingEffect = () => {
158
+ if (openCount === 1 && !Object.keys(cacheOverflow).length) {
159
+ // Must be set after switchScrollingEffect
160
+ cacheOverflow = setStyle({
161
+ overflow: 'hidden',
162
+ overflowX: 'hidden',
163
+ overflowY: 'hidden'
164
+ });
165
+ } else if (!openCount) {
166
+ setStyle(cacheOverflow);
167
+ cacheOverflow = {};
189
168
  }
190
- }, {
191
- key: "render",
192
- value: function render() {
193
- var _this$props4 = this.props,
194
- children = _this$props4.children,
195
- forceRender = _this$props4.forceRender,
196
- visible = _this$props4.visible;
197
- var portal = null;
198
- var childProps = {
199
- getOpenCount: function getOpenCount() {
200
- return openCount;
201
- },
169
+ };
170
+ render() {
171
+ const {
172
+ children,
173
+ forceRender,
174
+ visible
175
+ } = this.props;
176
+ let portal = null;
177
+ const childProps = {
178
+ getOpenCount: () => openCount,
179
+ getContainer: this.getContainer,
180
+ switchScrollingEffect: this.switchScrollingEffect,
181
+ scrollLocker: this.scrollLocker
182
+ };
183
+ if (forceRender || visible || this.componentRef.current) {
184
+ portal = /*#__PURE__*/React.createElement(Portal, {
202
185
  getContainer: this.getContainer,
203
- switchScrollingEffect: this.switchScrollingEffect,
204
- scrollLocker: this.scrollLocker
205
- };
206
- if (forceRender || visible || this.componentRef.current) {
207
- portal = /*#__PURE__*/React.createElement(Portal, {
208
- getContainer: this.getContainer,
209
- ref: this.componentRef
210
- }, children(childProps));
211
- }
212
- return portal;
186
+ ref: this.componentRef
187
+ }, children(childProps));
213
188
  }
214
- }]);
215
- return PortalWrapper;
216
- }(React.Component);
189
+ return portal;
190
+ }
191
+ }
217
192
  export default PortalWrapper;
@@ -1,7 +1,6 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var REACT_ELEMENT_TYPE_18 = Symbol.for('react.element');
3
- var REACT_ELEMENT_TYPE_19 = Symbol.for('react.transitional.element');
4
- var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
1
+ const REACT_ELEMENT_TYPE_18 = Symbol.for('react.element');
2
+ const REACT_ELEMENT_TYPE_19 = Symbol.for('react.transitional.element');
3
+ const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
5
4
 
6
5
  /**
7
6
  * Compatible with React 18 or 19 to check if node is a Fragment.
@@ -9,7 +8,7 @@ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
9
8
  export default function isFragment(object) {
10
9
  return (
11
10
  // Base object type
12
- object && _typeof(object) === 'object' && (
11
+ object && typeof object === 'object' && (
13
12
  // React Element type
14
13
  object.$$typeof === REACT_ELEMENT_TYPE_18 || object.$$typeof === REACT_ELEMENT_TYPE_19) &&
15
14
  // React Fragment type
@@ -1,46 +1,45 @@
1
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
3
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10
1
  import * as ReactDOM from 'react-dom';
11
2
  // Let compiler not to search module usage
12
- var fullClone = _objectSpread({}, ReactDOM);
13
- var version = fullClone.version,
14
- reactRender = fullClone.render,
15
- unmountComponentAtNode = fullClone.unmountComponentAtNode;
16
- var createRoot;
3
+ const fullClone = {
4
+ ...ReactDOM
5
+ };
6
+ const {
7
+ version,
8
+ render: reactRender,
9
+ unmountComponentAtNode
10
+ } = fullClone;
11
+ let createRoot;
17
12
  try {
18
- var mainVersion = Number((version || '').split('.')[0]);
13
+ const mainVersion = Number((version || '').split('.')[0]);
19
14
  if (mainVersion >= 18) {
20
- createRoot = fullClone.createRoot;
15
+ ({
16
+ createRoot
17
+ } = fullClone);
21
18
  }
22
19
  } catch (e) {
23
20
  // Do nothing;
24
21
  }
25
22
  function toggleWarning(skip) {
26
- var __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = fullClone.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
27
- if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && _typeof(__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === 'object') {
23
+ const {
24
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
25
+ } = fullClone;
26
+ if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === 'object') {
28
27
  __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
29
28
  }
30
29
  }
31
- var MARK = '__rc_react_root__';
30
+ const MARK = '__rc_react_root__';
32
31
 
33
32
  // ========================== Render ==========================
34
33
 
35
34
  function modernRender(node, container) {
36
35
  toggleWarning(true);
37
- var root = container[MARK] || createRoot(container);
36
+ const root = container[MARK] || createRoot(container);
38
37
  toggleWarning(false);
39
38
  root.render(node);
40
39
  container[MARK] = root;
41
40
  }
42
41
  function legacyRender(node, container) {
43
- reactRender === null || reactRender === void 0 || reactRender(node, container);
42
+ reactRender?.(node, container);
44
43
  }
45
44
 
46
45
  /** @private Test usage. Not work in prod */
@@ -58,26 +57,12 @@ export function render(node, container) {
58
57
  }
59
58
 
60
59
  // ========================= Unmount ==========================
61
- function modernUnmount(_x) {
62
- return _modernUnmount.apply(this, arguments);
63
- }
64
- function _modernUnmount() {
65
- _modernUnmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(container) {
66
- return _regeneratorRuntime().wrap(function _callee$(_context) {
67
- while (1) switch (_context.prev = _context.next) {
68
- case 0:
69
- return _context.abrupt("return", Promise.resolve().then(function () {
70
- var _container$MARK;
71
- (_container$MARK = container[MARK]) === null || _container$MARK === void 0 || _container$MARK.unmount();
72
- delete container[MARK];
73
- }));
74
- case 1:
75
- case "end":
76
- return _context.stop();
77
- }
78
- }, _callee);
79
- }));
80
- return _modernUnmount.apply(this, arguments);
60
+ async function modernUnmount(container) {
61
+ // Delay to unmount to avoid React 18 sync warning
62
+ return Promise.resolve().then(() => {
63
+ container[MARK]?.unmount();
64
+ delete container[MARK];
65
+ });
81
66
  }
82
67
  function legacyUnmount(container) {
83
68
  unmountComponentAtNode(container);
@@ -89,26 +74,10 @@ export function _u(container) {
89
74
  return legacyUnmount(container);
90
75
  }
91
76
  }
92
- export function unmount(_x2) {
93
- return _unmount.apply(this, arguments);
94
- }
95
- function _unmount() {
96
- _unmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(container) {
97
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
98
- while (1) switch (_context2.prev = _context2.next) {
99
- case 0:
100
- if (!(createRoot !== undefined)) {
101
- _context2.next = 2;
102
- break;
103
- }
104
- return _context2.abrupt("return", modernUnmount(container));
105
- case 2:
106
- legacyUnmount(container);
107
- case 3:
108
- case "end":
109
- return _context2.stop();
110
- }
111
- }, _callee2);
112
- }));
113
- return _unmount.apply(this, arguments);
77
+ export async function unmount(container) {
78
+ if (createRoot !== undefined) {
79
+ // Delay to unmount to avoid React 18 sync warning
80
+ return modernUnmount(container);
81
+ }
82
+ legacyUnmount(container);
114
83
  }
@@ -1,21 +1,14 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
1
  function composeProps(originProps, patchProps, isAll) {
8
- var composedProps = _objectSpread(_objectSpread({}, originProps), isAll ? patchProps : {});
9
- Object.keys(patchProps).forEach(function (key) {
10
- var func = patchProps[key];
2
+ const composedProps = {
3
+ ...originProps,
4
+ ...(isAll ? patchProps : {})
5
+ };
6
+ Object.keys(patchProps).forEach(key => {
7
+ const func = patchProps[key];
11
8
  if (typeof func === 'function') {
12
- composedProps[key] = function () {
13
- var _originProps$key;
14
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15
- args[_key] = arguments[_key];
16
- }
17
- func.apply(void 0, args);
18
- return (_originProps$key = originProps[key]) === null || _originProps$key === void 0 ? void 0 : _originProps$key.call.apply(_originProps$key, [originProps].concat(args));
9
+ composedProps[key] = (...args) => {
10
+ func(...args);
11
+ return originProps[key]?.(...args);
19
12
  };
20
13
  }
21
14
  });