Skip to content

Commit

Permalink
fix: node builtins rollup warnings from npm audit
Browse files Browse the repository at this point in the history
  • Loading branch information
yawetse committed Jan 11, 2022
1 parent 4fe20a2 commit a1101c3
Show file tree
Hide file tree
Showing 55 changed files with 44,276 additions and 45,446 deletions.
59 changes: 53 additions & 6 deletions build/components.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { ReactElementLike } from "prop-types";
import * as defs from "./types/jsonx/index";
import { ReactComponentLike } from "prop-types";
declare global {
interface window {
[index: string]: any;
Expand All @@ -18,12 +17,12 @@ declare global {
}
}
export declare const ReactHookForm: {
ErrorMessage: <TFieldErrors extends import("react-hook-form").DeepMap<import("react-hook-form").FieldValues, import("react-hook-form").FieldError>, TAs extends React.ReactElement<any, string | React.JSXElementConstructor<any>> | keyof JSX.IntrinsicElements | React.ComponentType<any> | undefined = undefined>({ as, errors, name, message, render, ...rest }: import("@hookform/error-message").Props<TFieldErrors, TAs>) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
ErrorMessage: <TFieldErrors extends {
[x: string]: any;
}, TAs extends React.ComponentType<any> | React.ReactElement<any, string | React.JSXElementConstructor<any>> | keyof JSX.IntrinsicElements | undefined = undefined>({ as, errors, name, message, render, ...rest }: import("@hookform/error-message").Props<TFieldErrors, TAs>) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
Controller: <TFieldValues extends import("react-hook-form").FieldValues = import("react-hook-form").FieldValues, TName extends import("react-hook-form").Path<TFieldValues> = import("react-hook-form").Path<TFieldValues>>(props: import("react-hook-form").ControllerProps<TFieldValues, TName>) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
};
/**
*/
export declare const generatedCustomComponents: Map<string, defs.jsonx["jsonxComponents"] | Map<string, defs.jsonx["jsonxComponents"]>>;
export declare let advancedBinding: boolean;
/**
* object of all react components available for JSONX
Expand Down Expand Up @@ -105,7 +104,7 @@ export declare function getFunctionFromEval(options?: any): any;
* @returns {Function}
* @see {@link https://reactjs.org/docs/react-without-es6.html}
*/
export declare function getReactClassComponent(this: defs.Context, reactComponent?: {}, options?: any): ReactComponentLike;
export declare function getReactClassComponent(this: defs.Context, reactComponent?: {}, options?: any): unknown;
/**
* A helper component that allows you to create forms with [react-hook-form](https://react-hook-form.com/) without needed to add external form libraries
* @param this
Expand Down Expand Up @@ -186,3 +185,51 @@ export declare function makeFunctionComponent(this: defs.Context, func: () => an
*
*/
export declare function getReactContext(options?: any): React.Context<any>;
/**
* generates react function components from a json definition
* @property {object} this
* @param customComponent
* @returns {function} returns react functional component
*/
export declare function getCustomFunctionComponent(this: defs.Context, customComponent: Partial<defs.jsonxCustomComponent>): defs.genericComponent;
/**
* returns a cache key of custom components names
* @param customComponents
* @returns {string} cachekey
*/
export declare function getCustomComponentsCacheKey(customComponents: defs.jsonxCustomComponent[]): string;
/**
*
* @param this
* @param customComponents
* @returns
* @example
const customComponents = [
{
type: 'library',
name: 'someLib',
jsonx?: {
Header: {
type:'function',
jsonxComponent: {p:'sample'},
functionBody:'console.log(44)',
},
Footer: {
type:'function',
jsonxComponent: {p:'sample'},
functionBody:'console.log(44)',
}
}
},
{
type: 'component'|'function'|'library';
name: string;
jsonx?: jsonxDefinitionLibrary | jsonx;
jsonxComponent?: jsonx;
options?: {};
functionBody?: (string);
functionComponent?: ((props?:any)=>any);
},
]
*/
export declare function getReactLibrariesAndComponents(this: defs.Context, customComponents: defs.jsonxCustomComponent[]): defs.jsonxLibrariesAndComponents;
150 changes: 136 additions & 14 deletions build/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ import createReactClass from "create-react-class";
import { getReactElementFromJSONX } from ".";
const cache = new memoryCache.Cache();
export const ReactHookForm = { ErrorMessage, Controller };
export const generatedCustomComponents = new Map();
// if (typeof window === 'undefined') {
// var window = window || global.window || {};
// }
/**
*/
//@ts-ignore
export let advancedBinding = getAdvancedBinding();
// require;
Expand Down Expand Up @@ -504,18 +502,24 @@ export function getReactFunctionComponent(reactComponent = {}, functionBody = ""
const self = this || {};
return function ${options.name || "Anonymous"}(props){
${functionBody}
if(typeof exposeprops==='undefined' || exposeprops){
reactComponent.props = Object.assign({},props,typeof exposeprops==='undefined'?{}:exposeprops);
if(typeof exposeprops!=='undefined') reactComponent.__functionargs = Object.keys(exposeprops);
} else{
reactComponent.props = props;
}
if(!props.children) {
// delete props.children;
try {
${functionBody}
if(typeof exposeprops==='undefined' || exposeprops){
reactComponent.props = Object.assign({},props,typeof exposeprops==='undefined'?{}:exposeprops);
if(typeof exposeprops!=='undefined') reactComponent.__functionargs = Object.keys(exposeprops);
} else{
reactComponent.props = props;
}
if(!props?.children) {
// delete props.children;
}
const context = ${options.bind ? "Object.assign(self,this||{})" : "this"};
return getReactElementFromJSONX.call(context, reactComponent);
} catch(e){
if(self.debug) return e.toString()
else throw e
}
const context = ${options.bind ? "Object.assign(self,this||{})" : "this"};
return getReactElementFromJSONX.call(context, reactComponent);
}
`);
if (options.name) {
Expand Down Expand Up @@ -570,3 +574,121 @@ export function makeFunctionComponent(func, options) {
export function getReactContext(options = {}) {
return createContext(options.value);
}
/**
* generates react function components from a json definition
* @property {object} this
* @param customComponent
* @returns {function} returns react functional component
*/
export function getCustomFunctionComponent(customComponent) {
const { options, functionBody, functionComponent, jsonxComponent, } = customComponent;
if (functionComponent) {
return makeFunctionComponent.call(this, functionComponent, options);
}
else {
return getReactFunctionComponent.call(this, jsonxComponent, functionBody, options);
}
}
/**
* returns a cache key of custom components names
* @param customComponents
* @returns {string} cachekey
*/
export function getCustomComponentsCacheKey(customComponents) {
return customComponents.map(({ name }) => name).join('');
}
/**
*
* @param this
* @param customComponents
* @returns
* @example
const customComponents = [
{
type: 'library',
name: 'someLib',
jsonx?: {
Header: {
type:'function',
jsonxComponent: {p:'sample'},
functionBody:'console.log(44)',
},
Footer: {
type:'function',
jsonxComponent: {p:'sample'},
functionBody:'console.log(44)',
}
}
},
{
type: 'component'|'function'|'library';
name: string;
jsonx?: jsonxDefinitionLibrary | jsonx;
jsonxComponent?: jsonx;
options?: {};
functionBody?: (string);
functionComponent?: ((props?:any)=>any);
},
]
*/
export function getReactLibrariesAndComponents(customComponents) {
const customComponentsCacheKey = getCustomComponentsCacheKey(customComponents);
if (generatedCustomComponents.has(customComponentsCacheKey))
return generatedCustomComponents.get(customComponentsCacheKey);
const cxt = {
componentLibraries: {},
reactComponents: {},
...this,
};
const customComponentLibraries = {};
const customReactComponents = {};
if (customComponents && customComponents.length) {
customComponents.forEach(customComponent => {
const { type, name, jsonx, options, functionBody, functionComponent, jsonxComponent, } = customComponent;
if (type === "library") {
if (jsonx) {
customComponentLibraries[name] = Object
.keys(jsonx)
.reduce((result, prop) => {
const libraryComponent = jsonx[prop];
const { type, name, jsonxComponent, options, functionBody } = libraryComponent;
if (type === "component") {
result[name] = getReactClassComponent.call(this, jsonxComponent, options);
}
else {
result[name] = getCustomFunctionComponent.call(this, { options, functionBody, functionComponent, jsonxComponent, });
}
return result;
}, {});
}
else
customComponentLibraries[name] = window[name];
cxt.componentLibraries[name] = customComponentLibraries[name];
}
else if (type === "component") {
if (jsonx) {
customReactComponents[name] = getReactClassComponent.call(this, jsonx, options);
}
else
customReactComponents[name] = window[name];
cxt.reactComponents[name] = customReactComponents[name];
}
else if (type === "function") {
if (functionComponent || functionBody) {
customReactComponents[name] = getCustomFunctionComponent.call(this, { options, functionBody, functionComponent, jsonxComponent: jsonx, });
}
else
customReactComponents[name] = window[name];
cxt.reactComponents[name] = customReactComponents[name];
}
});
}
generatedCustomComponents.set(customComponentsCacheKey, {
customComponentLibraries,
customReactComponents
});
return {
customComponentLibraries,
customReactComponents
};
}
21 changes: 15 additions & 6 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as jsonxUtils from "./utils";
import numeral from "numeral";
import * as luxon from "luxon";
const createElement = React.createElement;
const { componentMap, getComponentFromMap, getBoundedComponents, DynamicComponent, FormComponent, ReactHookForm, } = jsonxComponents;
const { componentMap, getComponentFromMap, getBoundedComponents, DynamicComponent, FormComponent, ReactHookForm, getReactLibrariesAndComponents, } = jsonxComponents;
const { getComputedProps } = jsonxProps;
const { getJSONXChildren } = jsonxChildren;
const { displayComponent, validSimpleJSONXSyntax, simpleJSONXSyntax } = jsonxUtils;
Expand Down Expand Up @@ -71,7 +71,8 @@ export function outputHTML(config = { jsonx: { component: "" } }) {
*/
export function getReactElementFromJSONX(jsonx, resources = {}) {
// eslint-disable-next-line
const { componentLibraries = {}, debug = false, returnJSON = false, logError = console.error, boundedComponents = [], disableRenderIndexKey = true } = this || {};
const { customComponents, debug = false, returnJSON = false, logError = console.error, boundedComponents = [], disableRenderIndexKey = true } = this || {};
let { componentLibraries = {}, } = this || {};
componentLibraries.ReactHookForm = ReactHookForm;
if (!jsonx)
return null;
Expand All @@ -83,15 +84,22 @@ export function getReactElementFromJSONX(jsonx, resources = {}) {
if (!jsonx || !jsonx.component)
return createElement("span", {}, debug ? "Error: Missing Component Object" : "");
try {
const components = Object.assign({ DynamicComponent: DynamicComponent.bind(this) }, { FormComponent: FormComponent.bind(this) }, componentMap, this?.reactComponents);
const reactComponents = boundedComponents.length
let components = Object.assign({ DynamicComponent: DynamicComponent.bind(this) }, { FormComponent: FormComponent.bind(this) }, componentMap, this?.reactComponents);
let reactComponents = boundedComponents.length
? getBoundedComponents.call(this, {
boundedComponents,
reactComponents: components
})
: components;
renderIndex++;
const element = getComponentFromMap({
if (customComponents && Array.isArray(customComponents) && customComponents.length) {
const cxt = { ...this, componentLibraries, reactComponents: components };
const { customComponentLibraries, customReactComponents } = getReactLibrariesAndComponents.call(cxt, customComponents);
componentLibraries = { ...componentLibraries, ...customComponentLibraries };
reactComponents = { ...reactComponents, ...customReactComponents };
}
if (disableRenderIndexKey === false)
renderIndex++;
const element = getComponentFromMap.call(this, {
jsonx,
reactComponents,
componentLibraries,
Expand Down Expand Up @@ -140,6 +148,7 @@ export function getReactElementFromJSONX(jsonx, resources = {}) {
if (debug) {
logError({ jsonx, resources }, "getReactElementFromJSONX this", this);
logError(e, e.stack ? e.stack : "no stack");
return e.toString();
}
throw e;
}
Expand Down
4 changes: 4 additions & 0 deletions build/jest_custom_test_env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Environment from 'jest-environment-jsdom';
export default class CustomTestEnvironment extends Environment {
setup(): Promise<void>;
}
12 changes: 12 additions & 0 deletions build/jest_custom_test_env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Environment from 'jest-environment-jsdom';
export default class CustomTestEnvironment extends Environment {
async setup() {
await super.setup();
if (typeof this.global.TextEncoder === 'undefined') {
const { TextEncoder, TextDecoder } = require('util');
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
}
}
}
;
11 changes: 8 additions & 3 deletions build/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,16 @@ export function getReactComponents(options) {
if (args) {
args.options = Object.assign({}, args.options, { resources });
if (args.function) {
componentVal = makeFunctionComponent.call(this, args.function, args.options);
const newComponent = makeFunctionComponent.call(this, args.function, args.options);
componentVal = args?.invoke
? newComponent(jsonx.props)
: newComponent;
}
else {
// eslint-disable-next-line
componentVal = getReactFunctionComponent.call(this, args.reactComponent, args.functionBody, args.options);
const newComponent = getReactFunctionComponent.call(this, args.reactComponent, args.functionBody, args.options);
componentVal = args?.invoke
? newComponent(jsonx.props)
: newComponent;
}
}
}
Expand Down
26 changes: 22 additions & 4 deletions build/types/jsonx/jsonx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export declare type createFunctionComponentArgs = {
reactComponent?: jsonx;
function?: callbackFunc;
functionBody?: string;
invoke?: boolean;
options?: {
lazy?: boolean;
bind?: boolean;
Expand Down Expand Up @@ -154,12 +155,29 @@ export declare type jsonxComparison = {
export interface jsonxResourceProps {
[index: string]: any;
}
export declare type genericComponent = React.FunctionComponent | React.PureComponent | React.Component | React.ReactElement | callbackFunc;
export declare type jsonxComponent = {
[index: string]: React.FunctionComponent | React.PureComponent | React.Component | React.ReactElement | callbackFunc;
[index: string]: genericComponent;
};
export interface jsonxLibrary {
[index: string]: jsonxComponent;
[index: string]: genericComponent;
}
export interface jsonxComponents {
[index: string]: jsonxComponent;
export interface jsonxDefinitionLibrary {
[index: string]: jsonxCustomComponent;
}
export interface jsonxComponentLibraries {
[index: string]: jsonxLibrary;
}
export declare type jsonxCustomComponent = {
type: 'component' | 'function' | 'library';
name: string;
jsonx?: jsonxDefinitionLibrary | jsonx;
jsonxComponent?: jsonx;
options?: {};
functionBody?: (string);
functionComponent?: ((props?: any) => any);
};
export declare type jsonxLibrariesAndComponents = {
customComponentLibraries: jsonxComponentLibraries;
customReactComponents: jsonxComponent;
};
1 change: 1 addition & 0 deletions build/types/jsonx/jsonx.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
;
export {};
Loading

0 comments on commit a1101c3

Please sign in to comment.