@pap-it/system-react
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,67 +0,1 @@ | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
import React from "react"; | ||
export function papHOC(WebComponent) { | ||
const InternalComponent = React.forwardRef((props, forwardedRef) => { | ||
const internalRef = React.useRef(null); | ||
const eventsAdded = React.useRef(new Set()); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [_loaded, setLoaded] = React.useState(false); | ||
React.useEffect(() => { | ||
if (typeof forwardedRef === "function") { | ||
forwardedRef(internalRef.current); | ||
} | ||
else if (forwardedRef) { | ||
forwardedRef.current = internalRef.current; | ||
} | ||
if (internalRef.current) | ||
setLoaded(true); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [internalRef.current]); | ||
const attributes = { | ||
class: props.className, | ||
}; | ||
// TODO use this to get property info later | ||
// const propertyConfig = internalRef.current.getProperties(); | ||
if (internalRef.current) { | ||
for (let name in props) { | ||
if (typeof props[name] === "function") { | ||
// check if its event | ||
if (name.startsWith('on')) // NOTE it would suck for functions that do in fact start with on.. | ||
{ | ||
if (eventsAdded.current.has(name)) { | ||
// we already added it ! | ||
continue; | ||
} | ||
const eventname = extractEventName(name); | ||
if (eventname) { | ||
internalRef.current.addEventListener(eventname, props[name]); | ||
eventsAdded.current.add(name); | ||
continue; | ||
} | ||
} | ||
// else we add this function directly to ref | ||
internalRef.current[name] = props[name]; | ||
} | ||
else if (typeof props[name] === "object") { | ||
internalRef.current[name] = props[name]; | ||
} | ||
else { | ||
// primitive | ||
// we should check if its available in the properties and if attribute is not false | ||
// internalRef.current[name as keyof TElement] = props[name as keyof Props]; | ||
attributes[name] = props[name]; | ||
} | ||
} | ||
} | ||
return (_jsx(WebComponent, { ref: internalRef, ...attributes, children: props.children })); | ||
}); | ||
return React.memo(InternalComponent); | ||
} | ||
function extractEventName(name) { | ||
if (name.startsWith('on')) { | ||
return name | ||
.replace(/^on/, '') | ||
.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
} | ||
return null; | ||
} | ||
"use strict";import{jsx as l}from"react/jsx-runtime";import r from"react";export function papHOC(c){const s=r.forwardRef((t,u)=>{const n=r.useRef(null),i=r.useRef(new Set),[d,o]=r.useState(!1);r.useEffect(()=>{typeof u=="function"?u(n.current):u&&(u.current=n.current),n.current&&o(!0)},[n.current]);const a={class:t.className};if(n.current)for(let e in t)if(typeof t[e]=="function"){if(e.startsWith("on")){if(i.current.has(e))continue;const f=m(e);if(f){n.current.addEventListener(f,t[e]),i.current.add(e);continue}}n.current[e]=t[e]}else typeof t[e]=="object"?n.current[e]=t[e]:a[e]=t[e];return l(c,{ref:n,...a,children:t.children})});return r.memo(s)}function m(c){return c.startsWith("on")?c.replace(/^on/,"").replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase():null} |
@@ -1,3 +0,1 @@ | ||
export * from './HOC'; | ||
export * from './types'; | ||
// * <-- This is an asshole | ||
"use strict";export*from"./HOC";export*from"./types"; |
@@ -1,1 +0,1 @@ | ||
export {}; | ||
"use strict";export{}; |
{ | ||
"name": "@pap-it/system-react", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "test": ".scripts/test.sh", |
@@ -5,5 +5,6 @@ # ReactSystem | ||
Version: Version: 0.0.5 | ||
Version: Version: Version: 0.0.6 | ||
## Development | ||
@@ -10,0 +11,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14
2587
8
16