amis-rpc-design/node_modules/rc-util/lib/Dom/findDOMNode.js
2023-10-07 19:42:30 +08:00

28 lines
858 B
JavaScript

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = findDOMNode;
exports.isDOM = isDOM;
var _react = _interopRequireDefault(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
function isDOM(node) {
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
return node instanceof HTMLElement || node instanceof SVGElement;
}
/**
* Return if a node is a DOM node. Else will return by `findDOMNode`
*/
function findDOMNode(node) {
if (isDOM(node)) {
return node;
}
if (node instanceof _react.default.Component) {
return _reactDom.default.findDOMNode(node);
}
return null;
}