@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.
- package/es/Children/toArray.js +3 -4
- package/es/Dom/contains.js +1 -1
- package/es/Dom/dynamicCSS.js +50 -60
- package/es/Dom/findDOMNode.js +3 -5
- package/es/Dom/focus.js +13 -21
- package/es/Dom/isVisible.js +10 -8
- package/es/Dom/scrollLocker.js +63 -89
- package/es/Dom/shadow.js +1 -2
- package/es/Dom/styleChecker.js +9 -9
- package/es/KeyCode.js +4 -2
- package/es/Portal.js +15 -16
- package/es/PortalWrapper.js +150 -175
- package/es/React/isFragment.js +4 -5
- package/es/React/render.js +32 -63
- package/es/composeProps.js +9 -16
- package/es/getScrollBarSize.js +19 -15
- package/es/hooks/useEffect.js +3 -5
- package/es/hooks/useEvent.js +2 -8
- package/es/hooks/useId.js +10 -23
- package/es/hooks/useLayoutEffect.js +8 -8
- package/es/hooks/useMemo.js +1 -1
- package/es/hooks/useMergedState.js +23 -34
- package/es/hooks/useMobile.js +3 -12
- package/es/hooks/useState.js +4 -13
- package/es/hooks/useSyncState.js +4 -14
- package/es/isEqual.js +9 -14
- package/es/isMobile.js +3 -3
- package/es/omit.js +2 -2
- package/es/pickAttrs.js +29 -17
- package/es/proxyObject.js +2 -2
- package/es/raf.js +12 -23
- package/es/ref.js +16 -30
- package/es/setStyle.js +8 -8
- package/es/test/domHook.js +19 -25
- package/es/utils/get.js +2 -2
- package/es/utils/set.js +19 -38
- package/es/warning.js +7 -11
- package/lib/Children/toArray.js +3 -4
- package/lib/Dom/contains.js +1 -1
- package/lib/Dom/dynamicCSS.js +50 -60
- package/lib/Dom/findDOMNode.js +3 -5
- package/lib/Dom/focus.js +13 -21
- package/lib/Dom/isVisible.js +12 -9
- package/lib/Dom/scrollLocker.js +64 -88
- package/lib/Dom/shadow.js +1 -2
- package/lib/Dom/styleChecker.js +9 -9
- package/lib/KeyCode.js +4 -2
- package/lib/Portal.js +15 -16
- package/lib/PortalWrapper.js +154 -177
- package/lib/React/isFragment.js +4 -5
- package/lib/React/render.js +34 -65
- package/lib/composeProps.js +9 -16
- package/lib/getScrollBarSize.js +19 -15
- package/lib/hooks/useEffect.js +5 -8
- package/lib/hooks/useEvent.js +4 -11
- package/lib/hooks/useId.js +12 -25
- package/lib/hooks/useLayoutEffect.js +11 -11
- package/lib/hooks/useMemo.js +3 -4
- package/lib/hooks/useMergedState.js +24 -35
- package/lib/hooks/useMobile.js +3 -12
- package/lib/hooks/useState.js +6 -16
- package/lib/hooks/useSyncState.js +6 -17
- package/lib/index.js +8 -8
- package/lib/isEqual.js +9 -14
- package/lib/isMobile.js +5 -4
- package/lib/omit.js +2 -2
- package/lib/pickAttrs.js +29 -17
- package/lib/proxyObject.js +2 -2
- package/lib/raf.js +12 -23
- package/lib/ref.js +23 -31
- package/lib/setStyle.js +8 -8
- package/lib/test/domHook.js +19 -25
- package/lib/utils/get.js +2 -2
- package/lib/utils/set.js +19 -38
- package/lib/warning.js +8 -11
- package/package.json +3 -3
package/lib/PortalWrapper.js
CHANGED
|
@@ -12,24 +12,12 @@ var _canUseDom = _interopRequireDefault(require("./Dom/canUseDom"));
|
|
|
12
12
|
var _setStyle = _interopRequireDefault(require("./setStyle"));
|
|
13
13
|
var _scrollLocker = _interopRequireDefault(require("./Dom/scrollLocker"));
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
16
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
-
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); }; }
|
|
23
|
-
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); }
|
|
24
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
-
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; } }
|
|
26
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
|
-
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; }
|
|
28
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
29
|
-
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); }
|
|
30
|
-
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); } /* eslint-disable no-underscore-dangle,react/require-default-props */
|
|
31
|
-
var openCount = 0;
|
|
32
|
-
var supportDom = (0, _canUseDom.default)();
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
/* eslint-disable no-underscore-dangle,react/require-default-props */
|
|
18
|
+
|
|
19
|
+
let openCount = 0;
|
|
20
|
+
const supportDom = (0, _canUseDom.default)();
|
|
33
21
|
|
|
34
22
|
/** @private Test usage only */
|
|
35
23
|
function getOpenCount() {
|
|
@@ -38,8 +26,8 @@ function getOpenCount() {
|
|
|
38
26
|
|
|
39
27
|
// https://github.com/ant-design/ant-design/issues/19340
|
|
40
28
|
// https://github.com/ant-design/ant-design/issues/19332
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
let cacheOverflow = {};
|
|
30
|
+
const getParent = getContainer => {
|
|
43
31
|
if (!supportDom) {
|
|
44
32
|
return null;
|
|
45
33
|
}
|
|
@@ -50,177 +38,166 @@ var getParent = function getParent(getContainer) {
|
|
|
50
38
|
if (typeof getContainer === 'function') {
|
|
51
39
|
return getContainer();
|
|
52
40
|
}
|
|
53
|
-
if (
|
|
41
|
+
if (typeof getContainer === 'object' && getContainer instanceof window.HTMLElement) {
|
|
54
42
|
return getContainer;
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
45
|
return document.body;
|
|
58
46
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
_defineProperty(_assertThisInitialized(_this), "rafId", void 0);
|
|
69
|
-
_defineProperty(_assertThisInitialized(_this), "scrollLocker", void 0);
|
|
70
|
-
_defineProperty(_assertThisInitialized(_this), "renderComponent", void 0);
|
|
71
|
-
_defineProperty(_assertThisInitialized(_this), "updateScrollLocker", function (prevProps) {
|
|
72
|
-
var _ref = prevProps || {},
|
|
73
|
-
prevVisible = _ref.visible;
|
|
74
|
-
var _this$props = _this.props,
|
|
75
|
-
getContainer = _this$props.getContainer,
|
|
76
|
-
visible = _this$props.visible;
|
|
77
|
-
if (visible && visible !== prevVisible && supportDom && getParent(getContainer) !== _this.scrollLocker.getContainer()) {
|
|
78
|
-
_this.scrollLocker.reLock({
|
|
79
|
-
container: getParent(getContainer)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
47
|
+
class PortalWrapper extends React.Component {
|
|
48
|
+
container;
|
|
49
|
+
componentRef = /*#__PURE__*/React.createRef();
|
|
50
|
+
rafId;
|
|
51
|
+
scrollLocker;
|
|
52
|
+
constructor(props) {
|
|
53
|
+
super(props);
|
|
54
|
+
this.scrollLocker = new _scrollLocker.default({
|
|
55
|
+
container: getParent(props.getContainer)
|
|
82
56
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
57
|
+
}
|
|
58
|
+
renderComponent;
|
|
59
|
+
componentDidMount() {
|
|
60
|
+
this.updateOpenCount();
|
|
61
|
+
if (!this.attachToParent()) {
|
|
62
|
+
this.rafId = (0, _raf.default)(() => {
|
|
63
|
+
this.forceUpdate();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
componentDidUpdate(prevProps) {
|
|
68
|
+
this.updateOpenCount(prevProps);
|
|
69
|
+
this.updateScrollLocker(prevProps);
|
|
70
|
+
this.setWrapperClassName();
|
|
71
|
+
this.attachToParent();
|
|
72
|
+
}
|
|
73
|
+
updateScrollLocker = prevProps => {
|
|
74
|
+
const {
|
|
75
|
+
visible: prevVisible
|
|
76
|
+
} = prevProps || {};
|
|
77
|
+
const {
|
|
78
|
+
getContainer,
|
|
79
|
+
visible
|
|
80
|
+
} = this.props;
|
|
81
|
+
if (visible && visible !== prevVisible && supportDom && getParent(getContainer) !== this.scrollLocker.getContainer()) {
|
|
82
|
+
this.scrollLocker.reLock({
|
|
83
|
+
container: getParent(getContainer)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
updateOpenCount = prevProps => {
|
|
88
|
+
const {
|
|
89
|
+
visible: prevVisible,
|
|
90
|
+
getContainer: prevGetContainer
|
|
91
|
+
} = prevProps || {};
|
|
92
|
+
const {
|
|
93
|
+
visible,
|
|
94
|
+
getContainer
|
|
95
|
+
} = this.props;
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
97
|
+
// Update count
|
|
98
|
+
if (visible !== prevVisible && supportDom && getParent(getContainer) === document.body) {
|
|
99
|
+
if (visible && !prevVisible) {
|
|
100
|
+
openCount += 1;
|
|
101
|
+
} else if (prevProps) {
|
|
102
|
+
openCount -= 1;
|
|
98
103
|
}
|
|
104
|
+
}
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
_defineProperty(_assertThisInitialized(_this), "getContainer", function () {
|
|
119
|
-
if (!supportDom) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
if (!_this.container) {
|
|
123
|
-
_this.container = document.createElement('div');
|
|
124
|
-
_this.attachToParent(true);
|
|
125
|
-
}
|
|
126
|
-
_this.setWrapperClassName();
|
|
127
|
-
return _this.container;
|
|
128
|
-
});
|
|
129
|
-
_defineProperty(_assertThisInitialized(_this), "setWrapperClassName", function () {
|
|
130
|
-
var wrapperClassName = _this.props.wrapperClassName;
|
|
131
|
-
if (_this.container && wrapperClassName && wrapperClassName !== _this.container.className) {
|
|
132
|
-
_this.container.className = wrapperClassName;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
_defineProperty(_assertThisInitialized(_this), "removeCurrentContainer", function () {
|
|
136
|
-
var _this$container;
|
|
137
|
-
// Portal will remove from `parentNode`.
|
|
138
|
-
// Let's handle this again to avoid refactor issue.
|
|
139
|
-
(_this$container = _this.container) === null || _this$container === void 0 || (_this$container = _this$container.parentNode) === null || _this$container === void 0 || _this$container.removeChild(_this.container);
|
|
140
|
-
});
|
|
141
|
-
/**
|
|
142
|
-
* Enhance ./switchScrollingEffect
|
|
143
|
-
* 1. Simulate document body scroll bar with
|
|
144
|
-
* 2. Record body has overflow style and recover when all of PortalWrapper invisible
|
|
145
|
-
* 3. Disable body scroll when PortalWrapper has open
|
|
146
|
-
*
|
|
147
|
-
* @memberof PortalWrapper
|
|
148
|
-
*/
|
|
149
|
-
_defineProperty(_assertThisInitialized(_this), "switchScrollingEffect", function () {
|
|
150
|
-
if (openCount === 1 && !Object.keys(cacheOverflow).length) {
|
|
151
|
-
// Must be set after switchScrollingEffect
|
|
152
|
-
cacheOverflow = (0, _setStyle.default)({
|
|
153
|
-
overflow: 'hidden',
|
|
154
|
-
overflowX: 'hidden',
|
|
155
|
-
overflowY: 'hidden'
|
|
156
|
-
});
|
|
157
|
-
} else if (!openCount) {
|
|
158
|
-
(0, _setStyle.default)(cacheOverflow);
|
|
159
|
-
cacheOverflow = {};
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
_this.scrollLocker = new _scrollLocker.default({
|
|
163
|
-
container: getParent(props.getContainer)
|
|
164
|
-
});
|
|
165
|
-
return _this;
|
|
106
|
+
// Clean up container if needed
|
|
107
|
+
const getContainerIsFunc = typeof getContainer === 'function' && typeof prevGetContainer === 'function';
|
|
108
|
+
if (getContainerIsFunc ? getContainer.toString() !== prevGetContainer.toString() : getContainer !== prevGetContainer) {
|
|
109
|
+
this.removeCurrentContainer();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
componentWillUnmount() {
|
|
113
|
+
const {
|
|
114
|
+
visible,
|
|
115
|
+
getContainer
|
|
116
|
+
} = this.props;
|
|
117
|
+
if (supportDom && getParent(getContainer) === document.body) {
|
|
118
|
+
// 离开时不会 render, 导到离开时数值不变,改用 func 。。
|
|
119
|
+
openCount = visible && openCount ? openCount - 1 : openCount;
|
|
120
|
+
}
|
|
121
|
+
this.removeCurrentContainer();
|
|
122
|
+
_raf.default.cancel(this.rafId);
|
|
166
123
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.rafId = (0, _raf.default)(function () {
|
|
174
|
-
_this2.forceUpdate();
|
|
175
|
-
});
|
|
124
|
+
attachToParent = (force = false) => {
|
|
125
|
+
if (force || this.container && !this.container.parentNode) {
|
|
126
|
+
const parent = getParent(this.props.getContainer);
|
|
127
|
+
if (parent) {
|
|
128
|
+
parent.appendChild(this.container);
|
|
129
|
+
return true;
|
|
176
130
|
}
|
|
131
|
+
return false;
|
|
177
132
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
this.setWrapperClassName();
|
|
184
|
-
this.attachToParent();
|
|
133
|
+
return true;
|
|
134
|
+
};
|
|
135
|
+
getContainer = () => {
|
|
136
|
+
if (!supportDom) {
|
|
137
|
+
return null;
|
|
185
138
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
139
|
+
if (!this.container) {
|
|
140
|
+
this.container = document.createElement('div');
|
|
141
|
+
this.attachToParent(true);
|
|
142
|
+
}
|
|
143
|
+
this.setWrapperClassName();
|
|
144
|
+
return this.container;
|
|
145
|
+
};
|
|
146
|
+
setWrapperClassName = () => {
|
|
147
|
+
const {
|
|
148
|
+
wrapperClassName
|
|
149
|
+
} = this.props;
|
|
150
|
+
if (this.container && wrapperClassName && wrapperClassName !== this.container.className) {
|
|
151
|
+
this.container.className = wrapperClassName;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
removeCurrentContainer = () => {
|
|
155
|
+
// Portal will remove from `parentNode`.
|
|
156
|
+
// Let's handle this again to avoid refactor issue.
|
|
157
|
+
this.container?.parentNode?.removeChild(this.container);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Enhance ./switchScrollingEffect
|
|
162
|
+
* 1. Simulate document body scroll bar with
|
|
163
|
+
* 2. Record body has overflow style and recover when all of PortalWrapper invisible
|
|
164
|
+
* 3. Disable body scroll when PortalWrapper has open
|
|
165
|
+
*
|
|
166
|
+
* @memberof PortalWrapper
|
|
167
|
+
*/
|
|
168
|
+
switchScrollingEffect = () => {
|
|
169
|
+
if (openCount === 1 && !Object.keys(cacheOverflow).length) {
|
|
170
|
+
// Must be set after switchScrollingEffect
|
|
171
|
+
cacheOverflow = (0, _setStyle.default)({
|
|
172
|
+
overflow: 'hidden',
|
|
173
|
+
overflowX: 'hidden',
|
|
174
|
+
overflowY: 'hidden'
|
|
175
|
+
});
|
|
176
|
+
} else if (!openCount) {
|
|
177
|
+
(0, _setStyle.default)(cacheOverflow);
|
|
178
|
+
cacheOverflow = {};
|
|
198
179
|
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
180
|
+
};
|
|
181
|
+
render() {
|
|
182
|
+
const {
|
|
183
|
+
children,
|
|
184
|
+
forceRender,
|
|
185
|
+
visible
|
|
186
|
+
} = this.props;
|
|
187
|
+
let portal = null;
|
|
188
|
+
const childProps = {
|
|
189
|
+
getOpenCount: () => openCount,
|
|
190
|
+
getContainer: this.getContainer,
|
|
191
|
+
switchScrollingEffect: this.switchScrollingEffect,
|
|
192
|
+
scrollLocker: this.scrollLocker
|
|
193
|
+
};
|
|
194
|
+
if (forceRender || visible || this.componentRef.current) {
|
|
195
|
+
portal = /*#__PURE__*/React.createElement(_Portal.default, {
|
|
211
196
|
getContainer: this.getContainer,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
};
|
|
215
|
-
if (forceRender || visible || this.componentRef.current) {
|
|
216
|
-
portal = /*#__PURE__*/React.createElement(_Portal.default, {
|
|
217
|
-
getContainer: this.getContainer,
|
|
218
|
-
ref: this.componentRef
|
|
219
|
-
}, children(childProps));
|
|
220
|
-
}
|
|
221
|
-
return portal;
|
|
197
|
+
ref: this.componentRef
|
|
198
|
+
}, children(childProps));
|
|
222
199
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
200
|
+
return portal;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
226
203
|
var _default = exports.default = PortalWrapper;
|
package/lib/React/isFragment.js
CHANGED
|
@@ -4,10 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = isFragment;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
|
7
|
+
const REACT_ELEMENT_TYPE_18 = Symbol.for('react.element');
|
|
8
|
+
const REACT_ELEMENT_TYPE_19 = Symbol.for('react.transitional.element');
|
|
9
|
+
const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Compatible with React 18 or 19 to check if node is a Fragment.
|
|
@@ -15,7 +14,7 @@ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
|
|
|
15
14
|
function isFragment(object) {
|
|
16
15
|
return (
|
|
17
16
|
// Base object type
|
|
18
|
-
object &&
|
|
17
|
+
object && typeof object === 'object' && (
|
|
19
18
|
// React Element type
|
|
20
19
|
object.$$typeof === REACT_ELEMENT_TYPE_18 || object.$$typeof === REACT_ELEMENT_TYPE_19) &&
|
|
21
20
|
// React Fragment type
|
package/lib/React/render.js
CHANGED
|
@@ -8,50 +8,49 @@ exports._u = _u;
|
|
|
8
8
|
exports.render = render;
|
|
9
9
|
exports.unmount = unmount;
|
|
10
10
|
var ReactDOM = _interopRequireWildcard(require("react-dom"));
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
13
|
-
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; }
|
|
14
|
-
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); } }
|
|
15
|
-
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); }); }; }
|
|
16
|
-
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); }
|
|
17
|
-
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; }
|
|
18
|
-
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; }
|
|
19
|
-
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; }
|
|
20
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
21
|
-
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); }
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
22
13
|
// Let compiler not to search module usage
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
const fullClone = {
|
|
15
|
+
...ReactDOM
|
|
16
|
+
};
|
|
17
|
+
const {
|
|
18
|
+
version,
|
|
19
|
+
render: reactRender,
|
|
20
|
+
unmountComponentAtNode
|
|
21
|
+
} = fullClone;
|
|
22
|
+
let createRoot;
|
|
28
23
|
try {
|
|
29
|
-
|
|
24
|
+
const mainVersion = Number((version || '').split('.')[0]);
|
|
30
25
|
if (mainVersion >= 18) {
|
|
31
|
-
|
|
26
|
+
({
|
|
27
|
+
createRoot
|
|
28
|
+
} = fullClone);
|
|
32
29
|
}
|
|
33
30
|
} catch (e) {
|
|
34
31
|
// Do nothing;
|
|
35
32
|
}
|
|
36
33
|
function toggleWarning(skip) {
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const {
|
|
35
|
+
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
|
|
36
|
+
} = fullClone;
|
|
37
|
+
if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === 'object') {
|
|
39
38
|
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
const MARK = '__rc_react_root__';
|
|
43
42
|
|
|
44
43
|
// ========================== Render ==========================
|
|
45
44
|
|
|
46
45
|
function modernRender(node, container) {
|
|
47
46
|
toggleWarning(true);
|
|
48
|
-
|
|
47
|
+
const root = container[MARK] || createRoot(container);
|
|
49
48
|
toggleWarning(false);
|
|
50
49
|
root.render(node);
|
|
51
50
|
container[MARK] = root;
|
|
52
51
|
}
|
|
53
52
|
function legacyRender(node, container) {
|
|
54
|
-
reactRender
|
|
53
|
+
reactRender?.(node, container);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/** @private Test usage. Not work in prod */
|
|
@@ -69,26 +68,12 @@ function render(node, container) {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
// ========================= Unmount ==========================
|
|
72
|
-
function modernUnmount(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
while (1) switch (_context.prev = _context.next) {
|
|
79
|
-
case 0:
|
|
80
|
-
return _context.abrupt("return", Promise.resolve().then(function () {
|
|
81
|
-
var _container$MARK;
|
|
82
|
-
(_container$MARK = container[MARK]) === null || _container$MARK === void 0 || _container$MARK.unmount();
|
|
83
|
-
delete container[MARK];
|
|
84
|
-
}));
|
|
85
|
-
case 1:
|
|
86
|
-
case "end":
|
|
87
|
-
return _context.stop();
|
|
88
|
-
}
|
|
89
|
-
}, _callee);
|
|
90
|
-
}));
|
|
91
|
-
return _modernUnmount.apply(this, arguments);
|
|
71
|
+
async function modernUnmount(container) {
|
|
72
|
+
// Delay to unmount to avoid React 18 sync warning
|
|
73
|
+
return Promise.resolve().then(() => {
|
|
74
|
+
container[MARK]?.unmount();
|
|
75
|
+
delete container[MARK];
|
|
76
|
+
});
|
|
92
77
|
}
|
|
93
78
|
function legacyUnmount(container) {
|
|
94
79
|
unmountComponentAtNode(container);
|
|
@@ -100,26 +85,10 @@ function _u(container) {
|
|
|
100
85
|
return legacyUnmount(container);
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
|
-
function unmount(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
110
|
-
case 0:
|
|
111
|
-
if (!(createRoot !== undefined)) {
|
|
112
|
-
_context2.next = 2;
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
return _context2.abrupt("return", modernUnmount(container));
|
|
116
|
-
case 2:
|
|
117
|
-
legacyUnmount(container);
|
|
118
|
-
case 3:
|
|
119
|
-
case "end":
|
|
120
|
-
return _context2.stop();
|
|
121
|
-
}
|
|
122
|
-
}, _callee2);
|
|
123
|
-
}));
|
|
124
|
-
return _unmount.apply(this, arguments);
|
|
88
|
+
async function unmount(container) {
|
|
89
|
+
if (createRoot !== undefined) {
|
|
90
|
+
// Delay to unmount to avoid React 18 sync warning
|
|
91
|
+
return modernUnmount(container);
|
|
92
|
+
}
|
|
93
|
+
legacyUnmount(container);
|
|
125
94
|
}
|
package/lib/composeProps.js
CHANGED
|
@@ -4,24 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
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); }
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
10
|
-
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; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
-
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); }
|
|
13
7
|
function composeProps(originProps, patchProps, isAll) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const composedProps = {
|
|
9
|
+
...originProps,
|
|
10
|
+
...(isAll ? patchProps : {})
|
|
11
|
+
};
|
|
12
|
+
Object.keys(patchProps).forEach(key => {
|
|
13
|
+
const func = patchProps[key];
|
|
17
14
|
if (typeof func === 'function') {
|
|
18
|
-
composedProps[key] =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
args[_key] = arguments[_key];
|
|
22
|
-
}
|
|
23
|
-
func.apply(void 0, args);
|
|
24
|
-
return (_originProps$key = originProps[key]) === null || _originProps$key === void 0 ? void 0 : _originProps$key.call.apply(_originProps$key, [originProps].concat(args));
|
|
15
|
+
composedProps[key] = (...args) => {
|
|
16
|
+
func(...args);
|
|
17
|
+
return originProps[key]?.(...args);
|
|
25
18
|
};
|
|
26
19
|
}
|
|
27
20
|
});
|