| 1 | import type { ElementType, MemoExoticComponent, ReactElement } from 'react'
|
|---|
| 2 | import { React } from './react'
|
|---|
| 3 |
|
|---|
| 4 | // Directly ported from:
|
|---|
| 5 | // https://unpkg.com/browse/react-is@19.0.0/cjs/react-is.production.js
|
|---|
| 6 | // It's very possible this could change in the future, but given that
|
|---|
| 7 | // we only use these in `connect`, this is a low priority.
|
|---|
| 8 |
|
|---|
| 9 | export const IS_REACT_19 = /* @__PURE__ */ React.version.startsWith('19')
|
|---|
| 10 |
|
|---|
| 11 | const REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for(
|
|---|
| 12 | IS_REACT_19 ? 'react.transitional.element' : 'react.element',
|
|---|
| 13 | )
|
|---|
| 14 | const REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for('react.portal')
|
|---|
| 15 | const REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for('react.fragment')
|
|---|
| 16 | const REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for('react.strict_mode')
|
|---|
| 17 | const REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for('react.profiler')
|
|---|
| 18 | const REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for('react.consumer')
|
|---|
| 19 | const REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for('react.context')
|
|---|
| 20 | const REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for('react.forward_ref')
|
|---|
| 21 | const REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for('react.suspense')
|
|---|
| 22 | const REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for(
|
|---|
| 23 | 'react.suspense_list',
|
|---|
| 24 | )
|
|---|
| 25 | const REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for('react.memo')
|
|---|
| 26 | const REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for('react.lazy')
|
|---|
| 27 | const REACT_OFFSCREEN_TYPE = /* @__PURE__ */ Symbol.for('react.offscreen')
|
|---|
| 28 | const REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for(
|
|---|
| 29 | 'react.client.reference',
|
|---|
| 30 | )
|
|---|
| 31 |
|
|---|
| 32 | export const ForwardRef = REACT_FORWARD_REF_TYPE
|
|---|
| 33 | export const Memo = REACT_MEMO_TYPE
|
|---|
| 34 |
|
|---|
| 35 | export function isValidElementType(type: any): type is ElementType {
|
|---|
| 36 | return typeof type === 'string' ||
|
|---|
| 37 | typeof type === 'function' ||
|
|---|
| 38 | type === REACT_FRAGMENT_TYPE ||
|
|---|
| 39 | type === REACT_PROFILER_TYPE ||
|
|---|
| 40 | type === REACT_STRICT_MODE_TYPE ||
|
|---|
| 41 | type === REACT_SUSPENSE_TYPE ||
|
|---|
| 42 | type === REACT_SUSPENSE_LIST_TYPE ||
|
|---|
| 43 | type === REACT_OFFSCREEN_TYPE ||
|
|---|
| 44 | (typeof type === 'object' &&
|
|---|
| 45 | type !== null &&
|
|---|
| 46 | (type.$$typeof === REACT_LAZY_TYPE ||
|
|---|
| 47 | type.$$typeof === REACT_MEMO_TYPE ||
|
|---|
| 48 | type.$$typeof === REACT_CONTEXT_TYPE ||
|
|---|
| 49 | type.$$typeof === REACT_CONSUMER_TYPE ||
|
|---|
| 50 | type.$$typeof === REACT_FORWARD_REF_TYPE ||
|
|---|
| 51 | type.$$typeof === REACT_CLIENT_REFERENCE ||
|
|---|
| 52 | type.getModuleId !== undefined))
|
|---|
| 53 | ? !0
|
|---|
| 54 | : !1
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | function typeOf(object: any): symbol | undefined {
|
|---|
| 58 | if (typeof object === 'object' && object !== null) {
|
|---|
| 59 | const { $$typeof } = object
|
|---|
| 60 |
|
|---|
| 61 | switch ($$typeof) {
|
|---|
| 62 | case REACT_ELEMENT_TYPE:
|
|---|
| 63 | switch (((object = object.type), object)) {
|
|---|
| 64 | case REACT_FRAGMENT_TYPE:
|
|---|
| 65 | case REACT_PROFILER_TYPE:
|
|---|
| 66 | case REACT_STRICT_MODE_TYPE:
|
|---|
| 67 | case REACT_SUSPENSE_TYPE:
|
|---|
| 68 | case REACT_SUSPENSE_LIST_TYPE:
|
|---|
| 69 | return object
|
|---|
| 70 | default:
|
|---|
| 71 | switch (((object = object && object.$$typeof), object)) {
|
|---|
| 72 | case REACT_CONTEXT_TYPE:
|
|---|
| 73 | case REACT_FORWARD_REF_TYPE:
|
|---|
| 74 | case REACT_LAZY_TYPE:
|
|---|
| 75 | case REACT_MEMO_TYPE:
|
|---|
| 76 | return object
|
|---|
| 77 | case REACT_CONSUMER_TYPE:
|
|---|
| 78 | return object
|
|---|
| 79 | default:
|
|---|
| 80 | return $$typeof
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | case REACT_PORTAL_TYPE:
|
|---|
| 84 | return $$typeof
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | export function isContextConsumer(object: any): object is ReactElement {
|
|---|
| 90 | return IS_REACT_19
|
|---|
| 91 | ? typeOf(object) === REACT_CONSUMER_TYPE
|
|---|
| 92 | : typeOf(object) === REACT_CONTEXT_TYPE
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | export function isMemo(object: any): object is MemoExoticComponent<any> {
|
|---|
| 96 | return typeOf(object) === REACT_MEMO_TYPE
|
|---|
| 97 | }
|
|---|