This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
@@ -0,0 +1,4 @@
/**
* Compatible with React 18 or 19 to check if node is a Fragment.
*/
export default function isFragment(object: any): boolean;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isFragment;
const REACT_ELEMENT_TYPE_18 = Symbol.for('react.element');
const REACT_ELEMENT_TYPE_19 = Symbol.for('react.transitional.element');
const REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
/**
* Compatible with React 18 or 19 to check if node is a Fragment.
*/
function isFragment(object) {
return (
// Base object type
object && typeof object === 'object' && (
// React Element type
object.$$typeof === REACT_ELEMENT_TYPE_18 || object.$$typeof === REACT_ELEMENT_TYPE_19) &&
// React Fragment type
object.type === REACT_FRAGMENT_TYPE
);
}
@@ -0,0 +1,9 @@
import type * as React from 'react';
import type { Root } from 'react-dom/client';
declare const MARK = "__rc_react_root__";
type ContainerType = (Element | DocumentFragment) & {
[MARK]?: Root;
};
export declare function render(node: React.ReactElement, container: ContainerType): void;
export declare function unmount(container: ContainerType): Promise<void>;
export {};
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.render = render;
exports.unmount = unmount;
var _client = require("react-dom/client");
const MARK = '__rc_react_root__';
// ========================== Render ==========================
function render(node, container) {
const root = container[MARK] || (0, _client.createRoot)(container);
root.render(node);
container[MARK] = root;
}
// ========================= Unmount ==========================
async function unmount(container) {
// Delay to unmount to avoid React 18 sync warning
return Promise.resolve().then(() => {
container[MARK]?.unmount();
delete container[MARK];
});
}