@rc-component/util 1.1.0 → 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.
@@ -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 {};
@@ -1,83 +1,19 @@
1
- import * as ReactDOM from 'react-dom';
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 modernRender(node, container) {
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 modernUnmount(container) {
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
  }
@@ -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 {};
@@ -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 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 (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 modernRender(node, container) {
46
- toggleWarning(true);
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 modernUnmount(container) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/util",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Common Utils For React Component",
5
5
  "keywords": [
6
6
  "react",