1 | import { __awaiter } from "tslib";
|
2 | import * as ReactDOM from 'react-dom';
|
3 |
|
4 | const fullClone = Object.assign({}, ReactDOM);
|
5 | const {
|
6 | version,
|
7 | render: reactRender,
|
8 | unmountComponentAtNode
|
9 | } = fullClone;
|
10 | let createRoot;
|
11 | try {
|
12 | const mainVersion = Number((version || '').split('.')[0]);
|
13 | if (mainVersion >= 18 && fullClone.createRoot) {
|
14 |
|
15 | createRoot = fullClone.createRoot;
|
16 | }
|
17 | } catch (e) {
|
18 |
|
19 | }
|
20 | function toggleWarning(skip) {
|
21 | const {
|
22 | __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
|
23 | } = fullClone;
|
24 | if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === 'object') {
|
25 | __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
|
26 | }
|
27 | }
|
28 | const MARK = '__antd_mobile_root__';
|
29 | function legacyRender(node, container) {
|
30 | reactRender(node, container);
|
31 | }
|
32 | function concurrentRender(node, container) {
|
33 | toggleWarning(true);
|
34 | const root = container[MARK] || createRoot(container);
|
35 | toggleWarning(false);
|
36 | root.render(node);
|
37 | container[MARK] = root;
|
38 | }
|
39 | export function render(node, container) {
|
40 | if (createRoot) {
|
41 | concurrentRender(node, container);
|
42 | return;
|
43 | }
|
44 | legacyRender(node, container);
|
45 | }
|
46 |
|
47 | function legacyUnmount(container) {
|
48 | return unmountComponentAtNode(container);
|
49 | }
|
50 | function concurrentUnmount(container) {
|
51 | return __awaiter(this, void 0, void 0, function* () {
|
52 |
|
53 | return Promise.resolve().then(() => {
|
54 | var _a;
|
55 | (_a = container[MARK]) === null || _a === void 0 ? void 0 : _a.unmount();
|
56 | delete container[MARK];
|
57 | });
|
58 | });
|
59 | }
|
60 | export function unmount(container) {
|
61 | if (createRoot) {
|
62 | return concurrentUnmount(container);
|
63 | }
|
64 | return legacyUnmount(container);
|
65 | } |
\ | No newline at end of file |