UNPKG

react-attractor

Version:

React library to map DOM elements to React components

2 lines (1 loc) 1.17 kB
(function(t,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.ReactTether={},t.React,t.React))})(this,function(t,n,o){"use strict";const f=o.createContext(null),T=({children:e})=>{const s=o.useRef(new WeakMap),a=o.useCallback((r,u)=>{r&&s.current.set(r,u)},[]),c=o.useCallback(r=>s.current.get(r),[]),i={registerTether:a,getTether:c};return n.jsx(f.Provider,{value:i,children:e})},h=()=>{const e=o.useContext(f);if(!e)throw new Error("useTetherContext must be used within a TetherProvider");return e};function l(e){return e!==null&&typeof e=="object"&&e!==null&&"$$typeof"in e}function C(e){const s=a=>{const{tetherMetadata:c,...i}=a,{registerTether:r}=h(),u={props:i,metadata:c},p=o.useCallback(d=>{d&&r(d,u)},[r,u]),x={...i,ref:p};return n.jsx(e,{...x})};return s.displayName=`withTether(${e.displayName||e.name||"Component"})`,s}t.TetherProvider=T,t.isForwardRefComponent=l,t.useTetherContext=h,t.withTether=C,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});