@aliemir/dom-to-fiber-utils
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,2 +0,74 @@ | ||
var o=e=>{let r=Object.keys(e).find(t=>t.startsWith("__reactFiber$"));return r?e[r]:null},u=e=>e.type.displayName||e.type.name||e.elementType.displayName||e.elementType.name||null,n=e=>e.return||null,F=e=>{let r=e;for(;r;){if(r.stateNode)return r;r=n(r)}return null},s=e=>e._debugOwner||null,a=e=>e._debugSource||null,b=(e,r)=>{let t=e;for(let l=0;l<r;l++)t=n(t);return t},c=e=>e.stateNode,i=e=>{if(!e)return null;if(u(e))return e;let r=n(e);return r?i(r):null};export{s as getDebugOwner,a as getDebugSource,c as getElementFromFiber,o as getFiberFromElement,i as getFirstFiberHasName,F as getFirstStateNodeFiber,u as getNameFromFiber,b as getNthParentOfFiber,n as getParentOfFiber}; | ||
// src/index.ts | ||
var getFiberFromElement = (element) => { | ||
const key = Object.keys(element).find( | ||
(key2) => key2.startsWith("__reactFiber$") | ||
); | ||
return key ? element[key] : null; | ||
}; | ||
var getNameFromFiber = (fiber) => { | ||
var _a, _b, _c, _d; | ||
if (!fiber) | ||
return null; | ||
return ((_a = fiber.type) == null ? void 0 : _a.displayName) || ((_b = fiber.type) == null ? void 0 : _b.name) || ((_c = fiber.elementType) == null ? void 0 : _c.displayName) || ((_d = fiber.elementType) == null ? void 0 : _d.name) || null; | ||
}; | ||
var getParentOfFiber = (fiber) => { | ||
return fiber.return || null; | ||
}; | ||
var getFirstStateNodeFiber = (fiber) => { | ||
let parent = fiber; | ||
while (parent) { | ||
if (parent.stateNode) { | ||
return parent; | ||
} | ||
parent = getParentOfFiber(parent); | ||
} | ||
return null; | ||
}; | ||
var getDebugOwner = (fiber) => { | ||
return fiber._debugOwner || null; | ||
}; | ||
var getDebugSource = (fiber) => { | ||
return fiber._debugSource || null; | ||
}; | ||
var getNthParentOfFiber = (fiber, n) => { | ||
let parent = fiber; | ||
for (let i = 0; i < n; i++) { | ||
parent = getParentOfFiber(parent); | ||
} | ||
return parent; | ||
}; | ||
var getElementFromFiber = (fiber) => { | ||
return fiber.stateNode; | ||
}; | ||
var getFirstFiberHasName = (fiber) => { | ||
if (!fiber) | ||
return null; | ||
if (getNameFromFiber(fiber)) { | ||
return fiber; | ||
} | ||
const parent = getParentOfFiber(fiber); | ||
if (!parent) { | ||
return null; | ||
} | ||
return getFirstFiberHasName(parent); | ||
}; | ||
var getNameOfFirstFiberHasName = (fiber) => { | ||
const firstFiber = getFirstFiberHasName(fiber); | ||
if (!firstFiber) { | ||
return null; | ||
} | ||
return getNameFromFiber(firstFiber); | ||
}; | ||
export { | ||
getDebugOwner, | ||
getDebugSource, | ||
getElementFromFiber, | ||
getFiberFromElement, | ||
getFirstFiberHasName, | ||
getFirstStateNodeFiber, | ||
getNameFromFiber, | ||
getNameOfFirstFiberHasName, | ||
getNthParentOfFiber, | ||
getParentOfFiber | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,65 @@ | ||
"use strict";(()=>{var o=e=>{let r=Object.keys(e).find(t=>t.startsWith("__reactFiber$"));return r?e[r]:null},u=e=>e.type.displayName||e.type.name||e.elementType.displayName||e.elementType.name||null,n=e=>e.return||null,F=e=>{let r=e;for(;r;){if(r.stateNode)return r;r=n(r)}return null},s=e=>e._debugOwner||null,a=e=>e._debugSource||null,b=(e,r)=>{let t=e;for(let l=0;l<r;l++)t=n(t);return t},c=e=>e.stateNode,i=e=>{if(!e)return null;if(u(e))return e;let r=n(e);return r?i(r):null};})(); | ||
"use strict"; | ||
(() => { | ||
// src/index.ts | ||
var getFiberFromElement = (element) => { | ||
const key = Object.keys(element).find( | ||
(key2) => key2.startsWith("__reactFiber$") | ||
); | ||
return key ? element[key] : null; | ||
}; | ||
var getNameFromFiber = (fiber) => { | ||
var _a, _b, _c, _d; | ||
if (!fiber) | ||
return null; | ||
return ((_a = fiber.type) == null ? void 0 : _a.displayName) || ((_b = fiber.type) == null ? void 0 : _b.name) || ((_c = fiber.elementType) == null ? void 0 : _c.displayName) || ((_d = fiber.elementType) == null ? void 0 : _d.name) || null; | ||
}; | ||
var getParentOfFiber = (fiber) => { | ||
return fiber.return || null; | ||
}; | ||
var getFirstStateNodeFiber = (fiber) => { | ||
let parent = fiber; | ||
while (parent) { | ||
if (parent.stateNode) { | ||
return parent; | ||
} | ||
parent = getParentOfFiber(parent); | ||
} | ||
return null; | ||
}; | ||
var getDebugOwner = (fiber) => { | ||
return fiber._debugOwner || null; | ||
}; | ||
var getDebugSource = (fiber) => { | ||
return fiber._debugSource || null; | ||
}; | ||
var getNthParentOfFiber = (fiber, n) => { | ||
let parent = fiber; | ||
for (let i = 0; i < n; i++) { | ||
parent = getParentOfFiber(parent); | ||
} | ||
return parent; | ||
}; | ||
var getElementFromFiber = (fiber) => { | ||
return fiber.stateNode; | ||
}; | ||
var getFirstFiberHasName = (fiber) => { | ||
if (!fiber) | ||
return null; | ||
if (getNameFromFiber(fiber)) { | ||
return fiber; | ||
} | ||
const parent = getParentOfFiber(fiber); | ||
if (!parent) { | ||
return null; | ||
} | ||
return getFirstFiberHasName(parent); | ||
}; | ||
var getNameOfFirstFiberHasName = (fiber) => { | ||
const firstFiber = getFirstFiberHasName(fiber); | ||
if (!firstFiber) { | ||
return null; | ||
} | ||
return getNameFromFiber(firstFiber); | ||
}; | ||
})(); | ||
//# sourceMappingURL=index.js.map |
@@ -9,3 +9,3 @@ import type { Fiber, Source } from "react-reconciler"; | ||
*/ | ||
export declare const getNameFromFiber: (fiber: Fiber) => string | null; | ||
export declare const getNameFromFiber: (fiber: Fiber | null) => string | null; | ||
/** | ||
@@ -39,2 +39,6 @@ * Given a fiber, return the parent fiber. Looks up the tree. | ||
export declare const getFirstFiberHasName: (fiber: Fiber | null) => Fiber | null; | ||
/** | ||
* Given a fiber, return the name of the first fiber with a name. Looks up the tree. | ||
*/ | ||
export declare const getNameOfFirstFiberHasName: (fiber: Fiber | null) => string | null; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,95 @@ | ||
"use strict";var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var c=(e,r)=>{for(var t in r)i(e,t,{get:r[t],enumerable:!0})},p=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of a(r))!b.call(e,l)&&l!==t&&i(e,l,{get:()=>r[l],enumerable:!(n=s(r,l))||n.enumerable});return e};var m=e=>p(i({},"__esModule",{value:!0}),e);var T={};c(T,{getDebugOwner:()=>y,getDebugSource:()=>x,getElementFromFiber:()=>E,getFiberFromElement:()=>g,getFirstFiberHasName:()=>F,getFirstStateNodeFiber:()=>d,getNameFromFiber:()=>o,getNthParentOfFiber:()=>N,getParentOfFiber:()=>u});module.exports=m(T);var g=e=>{let r=Object.keys(e).find(t=>t.startsWith("__reactFiber$"));return r?e[r]:null},o=e=>e.type.displayName||e.type.name||e.elementType.displayName||e.elementType.name||null,u=e=>e.return||null,d=e=>{let r=e;for(;r;){if(r.stateNode)return r;r=u(r)}return null},y=e=>e._debugOwner||null,x=e=>e._debugSource||null,N=(e,r)=>{let t=e;for(let n=0;n<r;n++)t=u(t);return t},E=e=>e.stateNode,F=e=>{if(!e)return null;if(o(e))return e;let r=u(e);return r?F(r):null}; | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
getDebugOwner: () => getDebugOwner, | ||
getDebugSource: () => getDebugSource, | ||
getElementFromFiber: () => getElementFromFiber, | ||
getFiberFromElement: () => getFiberFromElement, | ||
getFirstFiberHasName: () => getFirstFiberHasName, | ||
getFirstStateNodeFiber: () => getFirstStateNodeFiber, | ||
getNameFromFiber: () => getNameFromFiber, | ||
getNameOfFirstFiberHasName: () => getNameOfFirstFiberHasName, | ||
getNthParentOfFiber: () => getNthParentOfFiber, | ||
getParentOfFiber: () => getParentOfFiber | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
var getFiberFromElement = (element) => { | ||
const key = Object.keys(element).find( | ||
(key2) => key2.startsWith("__reactFiber$") | ||
); | ||
return key ? element[key] : null; | ||
}; | ||
var getNameFromFiber = (fiber) => { | ||
var _a, _b, _c, _d; | ||
if (!fiber) | ||
return null; | ||
return ((_a = fiber.type) == null ? void 0 : _a.displayName) || ((_b = fiber.type) == null ? void 0 : _b.name) || ((_c = fiber.elementType) == null ? void 0 : _c.displayName) || ((_d = fiber.elementType) == null ? void 0 : _d.name) || null; | ||
}; | ||
var getParentOfFiber = (fiber) => { | ||
return fiber.return || null; | ||
}; | ||
var getFirstStateNodeFiber = (fiber) => { | ||
let parent = fiber; | ||
while (parent) { | ||
if (parent.stateNode) { | ||
return parent; | ||
} | ||
parent = getParentOfFiber(parent); | ||
} | ||
return null; | ||
}; | ||
var getDebugOwner = (fiber) => { | ||
return fiber._debugOwner || null; | ||
}; | ||
var getDebugSource = (fiber) => { | ||
return fiber._debugSource || null; | ||
}; | ||
var getNthParentOfFiber = (fiber, n) => { | ||
let parent = fiber; | ||
for (let i = 0; i < n; i++) { | ||
parent = getParentOfFiber(parent); | ||
} | ||
return parent; | ||
}; | ||
var getElementFromFiber = (fiber) => { | ||
return fiber.stateNode; | ||
}; | ||
var getFirstFiberHasName = (fiber) => { | ||
if (!fiber) | ||
return null; | ||
if (getNameFromFiber(fiber)) { | ||
return fiber; | ||
} | ||
const parent = getParentOfFiber(fiber); | ||
if (!parent) { | ||
return null; | ||
} | ||
return getFirstFiberHasName(parent); | ||
}; | ||
var getNameOfFirstFiberHasName = (fiber) => { | ||
const firstFiber = getFirstFiberHasName(fiber); | ||
if (!firstFiber) { | ||
return null; | ||
} | ||
return getNameFromFiber(firstFiber); | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "Ali Emir Şen", |
@@ -11,2 +11,6 @@ # @aliemir/dom-to-fiber-utils | ||
## Demo | ||
Example App: https://dom-to-fiber-utils-example.vercel.app | ||
## Exported functions | ||
@@ -13,0 +17,0 @@ |
@@ -17,8 +17,9 @@ import type { Fiber, Source } from "react-reconciler"; | ||
*/ | ||
export const getNameFromFiber = (fiber: Fiber): string | null => { | ||
export const getNameFromFiber = (fiber: Fiber | null): string | null => { | ||
if (!fiber) return null; | ||
return ( | ||
fiber.type.displayName || | ||
fiber.type.name || | ||
fiber.elementType.displayName || | ||
fiber.elementType.name || | ||
fiber.type?.displayName || | ||
fiber.type?.name || | ||
fiber.elementType?.displayName || | ||
fiber.elementType?.name || | ||
null | ||
@@ -105,1 +106,16 @@ ); | ||
}; | ||
/** | ||
* Given a fiber, return the name of the first fiber with a name. Looks up the tree. | ||
*/ | ||
export const getNameOfFirstFiberHasName = ( | ||
fiber: Fiber | null, | ||
): string | null => { | ||
const firstFiber = getFirstFiberHasName(fiber); | ||
if (!firstFiber) { | ||
return null; | ||
} | ||
return getNameFromFiber(firstFiber); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27943
422
56