-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christopher J Baker
committed
Jul 12, 2024
1 parent
792b611
commit ae655cb
Showing
13 changed files
with
113 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
"use strict";var C=Object.defineProperty;var M=(t,e,s)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var b=(t,e,s)=>(M(t,typeof e!="symbol"?e+"":e,s),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T={stringify:t=>t,parse:t=>t},P={stringify:t=>`${t}`,parse:t=>parseFloat(t)},V={stringify:t=>t?"true":"false",parse:t=>/^[ty1-9]/i.test(t)},_={stringify:t=>t.name,parse:(t,e,s)=>{const o=(()=>{if(typeof window<"u"&&t in window)return window[t];if(typeof global<"u"&&t in global)return global[t]})();return typeof o=="function"?o.bind(s):void 0}},x={stringify:t=>JSON.stringify(t),parse:t=>JSON.parse(t)},A={string:T,number:P,boolean:V,function:_,json:x};function N(t){return t.replace(/([a-z0-9])([A-Z])/g,(e,s,o)=>`${s}-${o.toLowerCase()}`)}const d=Symbol.for("r2wc.render"),g=Symbol.for("r2wc.connected"),l=Symbol.for("r2wc.context"),p=Symbol.for("r2wc.props");function $(t,e,s){var O,j,k;e.props||(e.props=t.propTypes?Object.keys(t.propTypes):[]);const o=Array.isArray(e.props)?e.props.slice():Object.keys(e.props),h={},m={},w={};for(const r of o){h[r]=Array.isArray(e.props)?"string":e.props[r];const u=N(r);m[r]=u,w[u]=r}class S extends HTMLElement{constructor(){super();b(this,O,!0);b(this,j);b(this,k,{});b(this,"container");e.shadow?this.container=this.attachShadow({mode:e.shadow}):this.container=this,this[p].container=this.container;for(const i of o){const f=m[i],n=this.getAttribute(f),c=h[i],a=c?A[c]:null;a!=null&&a.parse&&n&&(this[p][i]=a.parse(n,f,this))}}static get observedAttributes(){return Object.keys(w)}connectedCallback(){this[g]=!0,this[d]()}disconnectedCallback(){this[g]=!1,this[l]&&s.unmount(this[l]),delete this[l]}attributeChangedCallback(i,f,n){const c=w[i],a=h[c],y=a?A[a]:null;c in h&&(y!=null&&y.parse)&&n&&(this[p][c]=y.parse(n,i,this),this[d]())}[(O=g,j=l,k=p,d)](){this[g]&&(this[l]?s.update(this[l],this[p]):this[l]=s.mount(this.container,t,this[p]))}}for(const r of o){const u=m[r],i=h[r];Object.defineProperty(S.prototype,r,{enumerable:!0,configurable:!0,get(){return this[p][r]},set(f){this[p][r]=f;const n=i?A[i]:null;if(n!=null&&n.stringify){const c=n.stringify(f,u,this);this.getAttribute(u)!==c&&this.setAttribute(u,c)}else this[d]()}})}return S}function v(t,e){const s="host"in t?t.host:t;for(const o in e)s[o]=e[o]}exports.default=$;exports.useImperativeMethods=v; | ||
"use strict";var C=Object.defineProperty;var M=(t,e,s)=>e in t?C(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var b=(t,e,s)=>M(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T={stringify:t=>t?"true":"false",parse:t=>/^[ty1-9]/i.test(t)},P={stringify:t=>t.name,parse:(t,e,s)=>{const o=(()=>{if(typeof window<"u"&&t in window)return window[t];if(typeof global<"u"&&t in global)return global[t]})();return typeof o=="function"?o.bind(s):void 0}},V={stringify:t=>JSON.stringify(t),parse:t=>JSON.parse(t)},_={stringify:t=>`${t}`,parse:t=>parseFloat(t)},x={stringify:t=>t,parse:t=>t},A={string:x,number:_,boolean:T,function:P,json:V};function N(t){return t.replace(/([a-z0-9])([A-Z])/g,(e,s,o)=>`${s}-${o.toLowerCase()}`)}const d=Symbol.for("r2wc.render"),g=Symbol.for("r2wc.connected"),l=Symbol.for("r2wc.context"),p=Symbol.for("r2wc.props");function $(t,e,s){var O,j,k;e.props||(e.props=t.propTypes?Object.keys(t.propTypes):[]);const o=Array.isArray(e.props)?e.props.slice():Object.keys(e.props),h={},m={},w={};for(const r of o){h[r]=Array.isArray(e.props)?"string":e.props[r];const u=N(r);m[r]=u,w[u]=r}class S extends HTMLElement{constructor(){super();b(this,k,!0);b(this,j);b(this,O,{});b(this,"container");e.shadow?this.container=this.attachShadow({mode:e.shadow}):this.container=this,this[p].container=this.container;for(const i of o){const f=m[i],n=this.getAttribute(f),c=h[i],a=c?A[c]:null;a!=null&&a.parse&&n&&(this[p][i]=a.parse(n,f,this))}}static get observedAttributes(){return Object.keys(w)}connectedCallback(){this[g]=!0,this[d]()}disconnectedCallback(){this[g]=!1,this[l]&&s.unmount(this[l]),delete this[l]}attributeChangedCallback(i,f,n){const c=w[i],a=h[c],y=a?A[a]:null;c in h&&(y!=null&&y.parse)&&n&&(this[p][c]=y.parse(n,i,this),this[d]())}[(k=g,j=l,O=p,d)](){this[g]&&(this[l]?s.update(this[l],this[p]):this[l]=s.mount(this.container,t,this[p]))}}for(const r of o){const u=m[r],i=h[r];Object.defineProperty(S.prototype,r,{enumerable:!0,configurable:!0,get(){return this[p][r]},set(f){this[p][r]=f;const n=i?A[i]:null;if(n!=null&&n.stringify){const c=n.stringify(f,u,this);this.getAttribute(u)!==c&&this.setAttribute(u,c)}else this[d]()}})}return S}function v(t,e){const s="host"in t?t.host:t;for(const o in e)s[o]=e[o]}exports.default=$;exports.useImperativeMethods=v; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
import type { R2WCType } from "./transforms"; | ||
type PropName<Props> = Exclude<Extract<keyof Props, string>, "container">; | ||
type PropNames<Props> = Array<PropName<Props>>; | ||
export interface R2WCOptions<Props> { | ||
shadow?: "open" | "closed"; | ||
props?: PropNames<Props> | Partial<Record<PropName<Props>, R2WCType>>; | ||
} | ||
export interface R2WCRenderer<Props extends R2WCBaseProps, Context> { | ||
mount: (container: HTMLElement, ReactComponent: React.ComponentType<Props>, props: Props) => Context; | ||
update: (context: Context, props: Props) => void; | ||
unmount: (context: Context) => void; | ||
} | ||
export interface R2WCBaseProps { | ||
container: HTMLElement; | ||
} | ||
/** | ||
* Converts a React component into a Web Component. | ||
* @param {ReactComponent} | ||
* @param {Object} options - Optional parameters | ||
* @param {String?} options.shadow - Shadow DOM mode as either open or closed. | ||
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: "string" | "number" | "boolean" | "function" | "json" } | ||
*/ | ||
export default function r2wc<Props extends R2WCBaseProps, Context>(ReactComponent: React.ComponentType<Props>, options: R2WCOptions<Props>, renderer: R2WCRenderer<Props, Context>): CustomElementConstructor; | ||
export declare function useImperativeMethods<Methods extends string>(container: HTMLElement | ShadowRoot, methods: Record<Methods, () => unknown>): void; | ||
export {}; | ||
declare type PropName<Props> = Exclude<Extract<keyof Props, string>, "container">; | ||
|
||
declare type PropNames<Props> = Array<PropName<Props>>; | ||
|
||
/** | ||
* Converts a React component into a Web Component. | ||
* @param {ReactComponent} | ||
* @param {Object} options - Optional parameters | ||
* @param {String?} options.shadow - Shadow DOM mode as either open or closed. | ||
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: "string" | "number" | "boolean" | "function" | "json" } | ||
*/ | ||
declare function r2wc<Props extends R2WCBaseProps, Context>(ReactComponent: React.ComponentType<Props>, options: R2WCOptions<Props>, renderer: R2WCRenderer<Props, Context>): CustomElementConstructor; | ||
export default r2wc; | ||
|
||
export declare interface R2WCBaseProps { | ||
container: HTMLElement; | ||
} | ||
|
||
export declare interface R2WCOptions<Props> { | ||
shadow?: "open" | "closed"; | ||
props?: PropNames<Props> | Partial<Record<PropName<Props>, R2WCType>>; | ||
} | ||
|
||
export declare interface R2WCRenderer<Props extends R2WCBaseProps, Context> { | ||
mount: (container: HTMLElement, ReactComponent: React.ComponentType<Props>, props: Props) => Context; | ||
update: (context: Context, props: Props) => void; | ||
unmount: (context: Context) => void; | ||
} | ||
|
||
declare type R2WCType = keyof typeof transforms; | ||
|
||
declare interface Transform<Type> { | ||
stringify?: (value: Type, attribute: string, element: HTMLElement) => string; | ||
parse: (value: string, attribute: string, element: HTMLElement) => Type; | ||
} | ||
|
||
declare const transforms: { | ||
string: Transform<string>; | ||
number: Transform<number>; | ||
boolean: Transform<boolean>; | ||
function: Transform<(...args: unknown[]) => unknown>; | ||
json: Transform<string>; | ||
}; | ||
|
||
export declare function useImperativeMethods<Methods extends string>(container: HTMLElement | ShadowRoot, methods: Record<Methods, () => unknown>): void; | ||
|
||
export { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
import type { R2WCBaseProps } from "@r2wc/core"; | ||
export declare function withCacheProvider<Props>(Component: React.ComponentType<Props>, key?: string): React.FC<Props & R2WCBaseProps>; | ||
import { R2WCBaseProps } from '@r2wc/core'; | ||
|
||
export declare function withCacheProvider<Props>(Component: React.ComponentType<Props>, key?: string): React.FC<Props & R2WCBaseProps>; | ||
|
||
export { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
import type { R2WCOptions } from "@r2wc/core"; | ||
interface ReactType { | ||
createElement: (type: any, data: any, children?: any) => React.ReactElement; | ||
} | ||
interface ReactDOMRootRootType { | ||
render: (element: React.ReactElement | null) => void; | ||
unmount: () => void; | ||
} | ||
interface ReactDOMRootType { | ||
createRoot: (container: Element | DocumentFragment, options?: any) => ReactDOMRootRootType; | ||
} | ||
interface ReactDOMRenderType { | ||
unmountComponentAtNode: (container: Element | DocumentFragment) => boolean; | ||
render: (element: React.ReactElement, container: ReactDOM.Container | null) => unknown; | ||
} | ||
/** | ||
* Converts a React component into a webcomponent by mounting it into an HTMLElement container. | ||
* @param {ReactComponent} | ||
* @param {React} | ||
* @param {ReactDOM} | ||
* @param {Object} options - Optional parameters | ||
* @param {String?} options.shadow - Shadow DOM mode as either open or closed. | ||
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: String | Number | Boolean | Function | Object | Array } | ||
*/ | ||
export default function r2wc<Props extends object>(ReactComponent: React.ComponentType<Props>, React: ReactType, ReactDOM: ReactDOMRootType | ReactDOMRenderType, options?: R2WCOptions<Props>): CustomElementConstructor; | ||
export {}; | ||
import { R2WCOptions } from '@r2wc/core'; | ||
|
||
/** | ||
* Converts a React component into a webcomponent by mounting it into an HTMLElement container. | ||
* @param {ReactComponent} | ||
* @param {React} | ||
* @param {ReactDOM} | ||
* @param {Object} options - Optional parameters | ||
* @param {String?} options.shadow - Shadow DOM mode as either open or closed. | ||
* @param {Object|Array?} options.props - Array of camelCasedProps to watch as Strings or { [camelCasedProp]: String | Number | Boolean | Function | Object | Array } | ||
*/ | ||
declare function r2wc<Props extends object>(ReactComponent: React.ComponentType<Props>, React: ReactType, ReactDOM: ReactDOMRootType | ReactDOMRenderType, options?: R2WCOptions<Props>): CustomElementConstructor; | ||
export default r2wc; | ||
|
||
declare interface ReactDOMRenderType { | ||
unmountComponentAtNode: (container: Element | DocumentFragment) => boolean; | ||
render: (element: React.ReactElement, container: ReactDOM.Container | null) => unknown; | ||
} | ||
|
||
declare interface ReactDOMRootRootType { | ||
render: (element: React.ReactElement | null) => void; | ||
unmount: () => void; | ||
} | ||
|
||
declare interface ReactDOMRootType { | ||
createRoot: (container: Element | DocumentFragment, options?: any) => ReactDOMRootRootType; | ||
} | ||
|
||
declare interface ReactType { | ||
createElement: (type: any, data: any, children?: any) => React.ReactElement; | ||
} | ||
|
||
export { } |
14 changes: 10 additions & 4 deletions
14
packages/react-to-web-component/dist/react-to-web-component.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import type { R2WCOptions } from "@r2wc/core"; | ||
import React from "react"; | ||
export { useImperativeMethods } from "@r2wc/core"; | ||
export default function r2wc<Props extends object>(ReactComponent: React.ComponentType<Props>, options?: R2WCOptions<Props>): CustomElementConstructor; | ||
import { default as default_2 } from 'react'; | ||
import { R2WCOptions } from '@r2wc/core'; | ||
import { useImperativeMethods } from '@r2wc/core'; | ||
|
||
declare function r2wc<Props extends object>(ReactComponent: default_2.ComponentType<Props>, options?: R2WCOptions<Props>): CustomElementConstructor; | ||
export default r2wc; | ||
|
||
export { useImperativeMethods } | ||
|
||
export { } |