@rc-component/util 1.0.1 → 1.2.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.
- package/es/Dom/findDOMNode.d.ts +3 -1
- package/es/Dom/findDOMNode.js +5 -4
- package/es/React/render.d.ts +0 -4
- package/es/React/render.js +3 -67
- package/lib/Dom/findDOMNode.d.ts +3 -1
- package/lib/Dom/findDOMNode.js +5 -5
- package/lib/React/render.d.ts +0 -4
- package/lib/React/render.js +4 -72
- package/package.json +1 -1
package/es/Dom/findDOMNode.d.ts
CHANGED
|
@@ -9,4 +9,6 @@ export declare function getDOM(node: any): HTMLElement | SVGElement | null;
|
|
|
9
9
|
*/
|
|
10
10
|
export default function findDOMNode<T = Element | Text>(node: React.ReactInstance | HTMLElement | SVGElement | {
|
|
11
11
|
nativeElement: T;
|
|
12
|
-
}
|
|
12
|
+
} | {
|
|
13
|
+
current: T;
|
|
14
|
+
}): T | null;
|
package/es/Dom/findDOMNode.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
1
|
export function isDOM(node) {
|
|
4
2
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
5
3
|
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
|
|
@@ -27,8 +25,11 @@ export default function findDOMNode(node) {
|
|
|
27
25
|
if (domNode) {
|
|
28
26
|
return domNode;
|
|
29
27
|
}
|
|
30
|
-
if (node
|
|
31
|
-
|
|
28
|
+
if (node && typeof node === 'object' && 'current' in node) {
|
|
29
|
+
const refDomNode = getDOM(node.current);
|
|
30
|
+
if (refDomNode) {
|
|
31
|
+
return refDomNode;
|
|
32
|
+
}
|
|
32
33
|
}
|
|
33
34
|
return null;
|
|
34
35
|
}
|
package/es/React/render.d.ts
CHANGED
|
@@ -4,10 +4,6 @@ declare const MARK = "__rc_react_root__";
|
|
|
4
4
|
type ContainerType = (Element | DocumentFragment) & {
|
|
5
5
|
[MARK]?: Root;
|
|
6
6
|
};
|
|
7
|
-
/** @private Test usage. Not work in prod */
|
|
8
|
-
export declare function _r(node: React.ReactElement, container: ContainerType): void;
|
|
9
7
|
export declare function render(node: React.ReactElement, container: ContainerType): void;
|
|
10
|
-
/** @private Test usage. Not work in prod */
|
|
11
|
-
export declare function _u(container: ContainerType): void;
|
|
12
8
|
export declare function unmount(container: ContainerType): Promise<void>;
|
|
13
9
|
export {};
|
package/es/React/render.js
CHANGED
|
@@ -1,83 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
// Let compiler not to search module usage
|
|
3
|
-
const fullClone = {
|
|
4
|
-
...ReactDOM
|
|
5
|
-
};
|
|
6
|
-
const {
|
|
7
|
-
version,
|
|
8
|
-
render: reactRender,
|
|
9
|
-
unmountComponentAtNode
|
|
10
|
-
} = fullClone;
|
|
11
|
-
let createRoot;
|
|
12
|
-
try {
|
|
13
|
-
const mainVersion = Number((version || '').split('.')[0]);
|
|
14
|
-
if (mainVersion >= 18) {
|
|
15
|
-
({
|
|
16
|
-
createRoot
|
|
17
|
-
} = fullClone);
|
|
18
|
-
}
|
|
19
|
-
} catch (e) {
|
|
20
|
-
// Do nothing;
|
|
21
|
-
}
|
|
22
|
-
function toggleWarning(skip) {
|
|
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') {
|
|
27
|
-
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
import { createRoot } from 'react-dom/client';
|
|
30
2
|
const MARK = '__rc_react_root__';
|
|
31
3
|
|
|
32
4
|
// ========================== Render ==========================
|
|
33
5
|
|
|
34
|
-
function
|
|
35
|
-
toggleWarning(true);
|
|
6
|
+
export function render(node, container) {
|
|
36
7
|
const root = container[MARK] || createRoot(container);
|
|
37
|
-
toggleWarning(false);
|
|
38
8
|
root.render(node);
|
|
39
9
|
container[MARK] = root;
|
|
40
10
|
}
|
|
41
|
-
function legacyRender(node, container) {
|
|
42
|
-
reactRender?.(node, container);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** @private Test usage. Not work in prod */
|
|
46
|
-
export function _r(node, container) {
|
|
47
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
48
|
-
return legacyRender(node, container);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function render(node, container) {
|
|
52
|
-
if (createRoot) {
|
|
53
|
-
modernRender(node, container);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
legacyRender(node, container);
|
|
57
|
-
}
|
|
58
11
|
|
|
59
12
|
// ========================= Unmount ==========================
|
|
60
|
-
async function
|
|
13
|
+
export async function unmount(container) {
|
|
61
14
|
// Delay to unmount to avoid React 18 sync warning
|
|
62
15
|
return Promise.resolve().then(() => {
|
|
63
16
|
container[MARK]?.unmount();
|
|
64
17
|
delete container[MARK];
|
|
65
18
|
});
|
|
66
|
-
}
|
|
67
|
-
function legacyUnmount(container) {
|
|
68
|
-
unmountComponentAtNode(container);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** @private Test usage. Not work in prod */
|
|
72
|
-
export function _u(container) {
|
|
73
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
74
|
-
return legacyUnmount(container);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
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);
|
|
83
19
|
}
|
package/lib/Dom/findDOMNode.d.ts
CHANGED
|
@@ -9,4 +9,6 @@ export declare function getDOM(node: any): HTMLElement | SVGElement | null;
|
|
|
9
9
|
*/
|
|
10
10
|
export default function findDOMNode<T = Element | Text>(node: React.ReactInstance | HTMLElement | SVGElement | {
|
|
11
11
|
nativeElement: T;
|
|
12
|
-
}
|
|
12
|
+
} | {
|
|
13
|
+
current: T;
|
|
14
|
+
}): T | null;
|
package/lib/Dom/findDOMNode.js
CHANGED
|
@@ -6,9 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = findDOMNode;
|
|
7
7
|
exports.getDOM = getDOM;
|
|
8
8
|
exports.isDOM = isDOM;
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
9
|
function isDOM(node) {
|
|
13
10
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element
|
|
14
11
|
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
|
|
@@ -36,8 +33,11 @@ function findDOMNode(node) {
|
|
|
36
33
|
if (domNode) {
|
|
37
34
|
return domNode;
|
|
38
35
|
}
|
|
39
|
-
if (node
|
|
40
|
-
|
|
36
|
+
if (node && typeof node === 'object' && 'current' in node) {
|
|
37
|
+
const refDomNode = getDOM(node.current);
|
|
38
|
+
if (refDomNode) {
|
|
39
|
+
return refDomNode;
|
|
40
|
+
}
|
|
41
41
|
}
|
|
42
42
|
return null;
|
|
43
43
|
}
|
package/lib/React/render.d.ts
CHANGED
|
@@ -4,10 +4,6 @@ declare const MARK = "__rc_react_root__";
|
|
|
4
4
|
type ContainerType = (Element | DocumentFragment) & {
|
|
5
5
|
[MARK]?: Root;
|
|
6
6
|
};
|
|
7
|
-
/** @private Test usage. Not work in prod */
|
|
8
|
-
export declare function _r(node: React.ReactElement, container: ContainerType): void;
|
|
9
7
|
export declare function render(node: React.ReactElement, container: ContainerType): void;
|
|
10
|
-
/** @private Test usage. Not work in prod */
|
|
11
|
-
export declare function _u(container: ContainerType): void;
|
|
12
8
|
export declare function unmount(container: ContainerType): Promise<void>;
|
|
13
9
|
export {};
|
package/lib/React/render.js
CHANGED
|
@@ -3,92 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports._r = _r;
|
|
7
|
-
exports._u = _u;
|
|
8
6
|
exports.render = render;
|
|
9
7
|
exports.unmount = unmount;
|
|
10
|
-
var
|
|
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; }
|
|
13
|
-
// Let compiler not to search module usage
|
|
14
|
-
const fullClone = {
|
|
15
|
-
...ReactDOM
|
|
16
|
-
};
|
|
17
|
-
const {
|
|
18
|
-
version,
|
|
19
|
-
render: reactRender,
|
|
20
|
-
unmountComponentAtNode
|
|
21
|
-
} = fullClone;
|
|
22
|
-
let createRoot;
|
|
23
|
-
try {
|
|
24
|
-
const mainVersion = Number((version || '').split('.')[0]);
|
|
25
|
-
if (mainVersion >= 18) {
|
|
26
|
-
({
|
|
27
|
-
createRoot
|
|
28
|
-
} = fullClone);
|
|
29
|
-
}
|
|
30
|
-
} catch (e) {
|
|
31
|
-
// Do nothing;
|
|
32
|
-
}
|
|
33
|
-
function toggleWarning(skip) {
|
|
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') {
|
|
38
|
-
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
8
|
+
var _client = require("react-dom/client");
|
|
41
9
|
const MARK = '__rc_react_root__';
|
|
42
10
|
|
|
43
11
|
// ========================== Render ==========================
|
|
44
12
|
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
const root = container[MARK] || createRoot(container);
|
|
48
|
-
toggleWarning(false);
|
|
13
|
+
function render(node, container) {
|
|
14
|
+
const root = container[MARK] || (0, _client.createRoot)(container);
|
|
49
15
|
root.render(node);
|
|
50
16
|
container[MARK] = root;
|
|
51
17
|
}
|
|
52
|
-
function legacyRender(node, container) {
|
|
53
|
-
reactRender?.(node, container);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** @private Test usage. Not work in prod */
|
|
57
|
-
function _r(node, container) {
|
|
58
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
59
|
-
return legacyRender(node, container);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function render(node, container) {
|
|
63
|
-
if (createRoot) {
|
|
64
|
-
modernRender(node, container);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
legacyRender(node, container);
|
|
68
|
-
}
|
|
69
18
|
|
|
70
19
|
// ========================= Unmount ==========================
|
|
71
|
-
async function
|
|
20
|
+
async function unmount(container) {
|
|
72
21
|
// Delay to unmount to avoid React 18 sync warning
|
|
73
22
|
return Promise.resolve().then(() => {
|
|
74
23
|
container[MARK]?.unmount();
|
|
75
24
|
delete container[MARK];
|
|
76
25
|
});
|
|
77
|
-
}
|
|
78
|
-
function legacyUnmount(container) {
|
|
79
|
-
unmountComponentAtNode(container);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** @private Test usage. Not work in prod */
|
|
83
|
-
function _u(container) {
|
|
84
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
85
|
-
return legacyUnmount(container);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
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);
|
|
94
26
|
}
|