Skip to content

Commit

Permalink
add build
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J Baker committed Jul 12, 2024
1 parent 792b611 commit ae655cb
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 105 deletions.
2 changes: 1 addition & 1 deletion packages/core/dist/core.cjs
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;
72 changes: 47 additions & 25 deletions packages/core/dist/core.d.ts
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 { }
34 changes: 17 additions & 17 deletions packages/core/dist/core.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
var C = Object.defineProperty;
var x = (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) => (x(t, typeof e != "symbol" ? e + "" : e, s), s);
var b = (t, e, s) => x(t, typeof e != "symbol" ? e + "" : e, s);
const T = {
stringify: (t) => t,
parse: (t) => t
}, V = {
stringify: (t) => `${t}`,
parse: (t) => parseFloat(t)
}, N = {
stringify: (t) => t ? "true" : "false",
parse: (t) => /^[ty1-9]/i.test(t)
}, P = {
}, V = {
stringify: (t) => t.name,
parse: (t, e, s) => {
const o = (() => {
Expand All @@ -21,15 +15,21 @@ const T = {
})();
return typeof o == "function" ? o.bind(s) : void 0;
}
}, $ = {
}, N = {
stringify: (t) => JSON.stringify(t),
parse: (t) => JSON.parse(t)
}, P = {
stringify: (t) => `${t}`,
parse: (t) => parseFloat(t)
}, $ = {
stringify: (t) => t,
parse: (t) => t
}, A = {
string: T,
number: V,
boolean: N,
function: P,
json: $
string: $,
number: P,
boolean: T,
function: V,
json: N
};
function J(t) {
return t.replace(
Expand All @@ -50,9 +50,9 @@ function M(t, e, s) {
class S extends HTMLElement {
constructor() {
super();
b(this, k, !0);
b(this, j, !0);
b(this, O);
b(this, j, {});
b(this, k, {});
b(this, "container");
e.shadow ? this.container = this.attachShadow({
mode: e.shadow
Expand All @@ -75,7 +75,7 @@ function M(t, e, s) {
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, O = f, j = p, d)]() {
[(j = g, O = f, k = p, d)]() {
this[g] && (this[f] ? s.update(this[f], this[p]) : this[f] = s.mount(
this.container,
t,
Expand Down
3 changes: 0 additions & 3 deletions packages/core/dist/transforms/boolean.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/dist/transforms/function.d.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/core/dist/transforms/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/dist/transforms/json.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/dist/transforms/number.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/dist/transforms/string.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core/dist/utils.d.ts

This file was deleted.

7 changes: 5 additions & 2 deletions packages/emotion/dist/emotion.d.ts
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 { }
59 changes: 33 additions & 26 deletions packages/legacy/dist/react-to-webcomponent.d.ts
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 packages/react-to-web-component/dist/react-to-web-component.d.ts
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 { }

0 comments on commit ae655cb

Please sign in to comment.