New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-form-with-constraints-tools

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-form-with-constraints-tools - npm Package Compare versions

Comparing version 0.19.0-beta.1 to 0.19.0-beta.2

8

dist/cjs/DisplayFields.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Async = exports.FieldFeedback = exports.FieldFeedbacks = exports.FormWithConstraints = exports.DisplayFields = void 0;
exports.Async = exports.FieldFeedback = exports.FieldFeedbacks = exports.DisplayFields = void 0;
const React = require("react");
const PropTypes = require("prop-types");
const prop_types_1 = require("prop-types");
const react_form_with_constraints_1 = require("react-form-with-constraints");

@@ -53,6 +53,4 @@ function beautifulStringify(obj, space) {

DisplayFields.contextTypes = {
form: PropTypes.instanceOf(react_form_with_constraints_1.FormWithConstraints).isRequired
form: (0, prop_types_1.instanceOf)(react_form_with_constraints_1.FormWithConstraints).isRequired
};
var react_form_with_constraints_2 = require("react-form-with-constraints");
Object.defineProperty(exports, "FormWithConstraints", { enumerable: true, get: function () { return react_form_with_constraints_2.FormWithConstraints; } });
class FieldFeedbacks extends react_form_with_constraints_1.FieldFeedbacks {

@@ -59,0 +57,0 @@ render() {

@@ -17,2 +17,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.FormWithConstraints = void 0;
__exportStar(require("./DisplayFields"), exports);
var react_form_with_constraints_1 = require("react-form-with-constraints");
Object.defineProperty(exports, "FormWithConstraints", { enumerable: true, get: function () { return react_form_with_constraints_1.FormWithConstraints; } });

@@ -11,3 +11,2 @@ import * as React from 'react';

}
export { FormWithConstraints } from 'react-form-with-constraints';
export declare class FieldFeedbacks extends _FieldFeedbacks {

@@ -14,0 +13,0 @@ render(): JSX.Element;

import * as React from 'react';
import * as PropTypes from 'prop-types';
import { instanceOf } from 'prop-types';
import { Async as _Async, FieldEvent, FieldFeedback as _FieldFeedback, FieldFeedbacks as _FieldFeedbacks, FieldFeedbackType, FormWithConstraints, isHTMLInput } from 'react-form-with-constraints';

@@ -49,5 +49,4 @@ function beautifulStringify(obj, space) {

DisplayFields.contextTypes = {
form: PropTypes.instanceOf(FormWithConstraints).isRequired
form: instanceOf(FormWithConstraints).isRequired
};
export { FormWithConstraints } from 'react-form-with-constraints';
export class FieldFeedbacks extends _FieldFeedbacks {

@@ -54,0 +53,0 @@ render() {

export * from './DisplayFields';
export { FormWithConstraints } from 'react-form-with-constraints';
export * from './DisplayFields';
export { FormWithConstraints } from 'react-form-with-constraints';

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactFormWithConstraintsTools = {}, global.React, global.PropTypes, global.ReactFormWithConstraints));
})(this, (function (exports, React, PropTypes, reactFormWithConstraints) { 'use strict';
})(this, (function (exports, React, propTypes, reactFormWithConstraints) { 'use strict';

@@ -27,50 +27,11 @@ function _interopNamespace(e) {

var React__namespace = /*#__PURE__*/_interopNamespace(React);
var PropTypes__namespace = /*#__PURE__*/_interopNamespace(PropTypes);
// Before:
// [
// {
// "element": "<input id=\"username\" name=\"username\" required=\"\" minlength=\"3\" class=\"form-control is-pending-sm is-invalid\" value=\"\">",
// "name": "username",
// "validations": [
// { "key": "0.0", "type": "error", "show": false },
// { "key": "0.1", "type": "error", "show": true },
// { "key": "0.2", "type": "whenValid" }
// ]
// }
// ]
//
// After:
// [
// {
// element: <input id="username" name="username" required="" minlength="3" class="form-control is-pending-sm is-invalid" value="">,
// name: "username",
// validations: [
// { key: "0.0", type: "error", show: false },
// { key: "0.1", type: "error", show: true },
// { key: "0.2", type: "whenValid", show: undefined }
// ]
// }
// ]
// eslint-disable-next-line @typescript-eslint/ban-types
function beautifulStringify(obj, space) {
// Keep undefined
// [Preserving undefined that JSON.stringify otherwise removes](https://stackoverflow.com/q/26540706)
let str = JSON.stringify(obj, (_key, value) => (value === undefined ? '__undefined__' : value), space);
str = str.replace(/"__undefined__"/g, 'undefined');
// Remove quotes from properties
// Before: "name":
// After: name:
// [JSON.stringify without quotes on properties?](https://stackoverflow.com/q/11233498)
str = str.replace(/"([^"]+)":/g, '$1:');
// Before: element: "<input id=\"username\" name=\"username\" required=\"\">",
// After: element: <input id=\"username\" name=\"username\" required=\"\">,
// eslint-disable-next-line unicorn/better-regex
str = str.replace(/: "(.*[\\"].*)",/g, ': $1,');
// Before: <input id=\"username\" name=\"username\" required=\"\">
// After: <input id="username" name="username" required="">
str = str.replace(/\\"/g, '"');
return str;
}
// Cannot display field.element directly, will throw "Converting circular structure to JSON" when calling JSON.stringify()
function normalizeFieldElementProperty(fields) {

@@ -93,5 +54,3 @@ return fields.map(field => {

};
/* eslint-enable react/destructuring-assignment */
}
/* eslint-disable react/destructuring-assignment */
componentDidMount() {

@@ -111,12 +70,2 @@ this.context.form.fieldsStore.addListener(reactFormWithConstraints.FieldEvent.Added, this.reRender);

let str = beautifulStringify(normalizeFieldElementProperty(this.context.form.fieldsStore.fields), 2);
// Cosmetic: improve formatting
//
// Replace this string:
// {
// key: "1.0",
// type: "error",
// show: true
// }
// with this:
// { key: "1.0", type: "error", show: true }
str = str.replace(/{\s+key: (.*),\s+type: (.*),\s+show: (.*)\s+}/g, '{ key: $1, type: $2, show: $3 }');

@@ -127,3 +76,3 @@ return str;

DisplayFields.contextTypes = {
form: PropTypes__namespace.instanceOf(reactFormWithConstraints.FormWithConstraints).isRequired
form: propTypes.instanceOf(reactFormWithConstraints.FormWithConstraints).isRequired
};

@@ -179,10 +128,6 @@ class FieldFeedbacks extends reactFormWithConstraints.FieldFeedbacks {

componentDidUpdate() {
// Hack: make FieldFeedback <span style="display: inline">
// Also make Bootstrap 4 happy because it sets 'display: none', https://github.com/twbs/bootstrap/blob/v4.1.2/scss/mixins/_forms.scss#L31
const fieldFeedbackSpans = this.rootEl.querySelectorAll('[data-feedback]');
fieldFeedbackSpans.forEach(fieldFeedbackSpan => {
// eslint-disable-next-line no-param-reassign
fieldFeedbackSpan.style.display = 'inline';
});
// Change Async parent style
const li = this.rootEl.closest('li.async');

@@ -193,3 +138,2 @@ if (li !== null) {

}
// Change whenValid style
const { type } = this.state.validation;

@@ -212,3 +156,2 @@ if (type === reactFormWithConstraints.FieldFeedbackType.WhenValid) {

componentDidUpdate() {
// Reset style
const async = this.rootEl.querySelector('span[style]');

@@ -215,0 +158,0 @@ async.style.textDecoration = Async.getTextDecoration();

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types"),require("react-form-with-constraints")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","react-form-with-constraints"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactFormWithConstraintsTools={},e.React,e.PropTypes,e.ReactFormWithConstraints)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=o(t),i=o(r);class l extends s.Component{constructor(){super(...arguments),this.reRender=()=>{this.forceUpdate()}}componentDidMount(){this.context.form.fieldsStore.addListener(n.FieldEvent.Added,this.reRender),this.context.form.fieldsStore.addListener(n.FieldEvent.Removed,this.reRender),this.context.form.addFieldDidValidateEventListener(this.reRender),this.context.form.addFieldDidResetEventListener(this.reRender)}componentWillUnmount(){this.context.form.fieldsStore.removeListener(n.FieldEvent.Added,this.reRender),this.context.form.fieldsStore.removeListener(n.FieldEvent.Removed,this.reRender),this.context.form.removeFieldDidValidateEventListener(this.reRender),this.context.form.removeFieldDidResetEventListener(this.reRender)}render(){let e=function(e,t){let r=JSON.stringify(e,((e,t)=>void 0===t?"__undefined__":t),t);return r=r.replace(/"__undefined__"/g,"undefined"),r=r.replace(/"([^"]+)":/g,"$1:"),r=r.replace(/: "(.*[\\"].*)",/g,": $1,"),r=r.replace(/\\"/g,'"'),r}(this.context.form.fieldsStore.fields.map((e=>{const{element:t,...r}=e;return t?{element:n.isHTMLInput(t)?t.outerHTML:t.props,...r}:e})),2);return e=e.replace(/{\s+key: (.*),\s+type: (.*),\s+show: (.*)\s+}/g,"{ key: $1, type: $2, show: $3 }"),e}}l.contextTypes={form:i.instanceOf(n.FormWithConstraints).isRequired};class d extends n.FieldFeedbacks{render(){const{for:e,stop:t}=this.props;let r="";return e&&(r+=`for="${e}" `),r+=`stop="${t}"`,s.createElement(s.Fragment,null,s.createElement("li",null,'key="',this.key,'" ',r),s.createElement("ul",null,super.render()))}}class c extends n.FieldFeedback{constructor(){super(...arguments),this.rootEl=null}getTextDecoration(){const{show:e}=this.state.validation;let t="";switch(e){case!1:t="line-through";break;case void 0:t="line-through dotted";break;default:t=""}return t}render(){const{key:e,type:t}=this.state.validation;return s.createElement("li",{ref:e=>this.rootEl=e},s.createElement("span",{style:{textDecoration:this.getTextDecoration()}},'key="',e,'" type="',t,'"')," ",super.render())}componentDidUpdate(){this.rootEl.querySelectorAll("[data-feedback]").forEach((e=>{e.style.display="inline"}));const e=this.rootEl.closest("li.async");if(null!==e){e.querySelector("span[style]").style.textDecoration=this.getTextDecoration()}const{type:t}=this.state.validation;if(t===n.FieldFeedbackType.WhenValid){const e=this.rootEl.querySelector("span[style]"),t=this.rootEl.querySelector(`span.${this.props.classes.valid}`);e.style.textDecoration=null!==t?"":"line-through"}}}class a extends n.Async{constructor(){super(...arguments),this.rootEl=null}static getTextDecoration(){return"line-through dotted"}componentDidUpdate(){this.rootEl.querySelector("span[style]").style.textDecoration=a.getTextDecoration()}render(){return s.createElement("li",{className:"async",ref:e=>this.rootEl=e},s.createElement("span",{style:{textDecoration:a.getTextDecoration()}},"Async"),s.createElement("ul",null,super.render()))}}Object.defineProperty(e,"FormWithConstraints",{enumerable:!0,get:function(){return n.FormWithConstraints}}),e.Async=a,e.DisplayFields=l,e.FieldFeedback=c,e.FieldFeedbacks=d,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types"),require("react-form-with-constraints")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","react-form-with-constraints"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactFormWithConstraintsTools={},e.React,e.PropTypes,e.ReactFormWithConstraints)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=o(t);class i extends s.Component{constructor(){super(...arguments),this.reRender=()=>{this.forceUpdate()}}componentDidMount(){this.context.form.fieldsStore.addListener(n.FieldEvent.Added,this.reRender),this.context.form.fieldsStore.addListener(n.FieldEvent.Removed,this.reRender),this.context.form.addFieldDidValidateEventListener(this.reRender),this.context.form.addFieldDidResetEventListener(this.reRender)}componentWillUnmount(){this.context.form.fieldsStore.removeListener(n.FieldEvent.Added,this.reRender),this.context.form.fieldsStore.removeListener(n.FieldEvent.Removed,this.reRender),this.context.form.removeFieldDidValidateEventListener(this.reRender),this.context.form.removeFieldDidResetEventListener(this.reRender)}render(){let e=function(e,t){let r=JSON.stringify(e,((e,t)=>void 0===t?"__undefined__":t),t);return r=r.replace(/"__undefined__"/g,"undefined"),r=r.replace(/"([^"]+)":/g,"$1:"),r=r.replace(/: "(.*[\\"].*)",/g,": $1,"),r=r.replace(/\\"/g,'"'),r}(this.context.form.fieldsStore.fields.map((e=>{const{element:t,...r}=e;return t?{element:n.isHTMLInput(t)?t.outerHTML:t.props,...r}:e})),2);return e=e.replace(/{\s+key: (.*),\s+type: (.*),\s+show: (.*)\s+}/g,"{ key: $1, type: $2, show: $3 }"),e}}i.contextTypes={form:r.instanceOf(n.FormWithConstraints).isRequired};class l extends n.FieldFeedbacks{render(){const{for:e,stop:t}=this.props;let r="";return e&&(r+=`for="${e}" `),r+=`stop="${t}"`,s.createElement(s.Fragment,null,s.createElement("li",null,'key="',this.key,'" ',r),s.createElement("ul",null,super.render()))}}class d extends n.FieldFeedback{constructor(){super(...arguments),this.rootEl=null}getTextDecoration(){const{show:e}=this.state.validation;let t="";switch(e){case!1:t="line-through";break;case void 0:t="line-through dotted";break;default:t=""}return t}render(){const{key:e,type:t}=this.state.validation;return s.createElement("li",{ref:e=>this.rootEl=e},s.createElement("span",{style:{textDecoration:this.getTextDecoration()}},'key="',e,'" type="',t,'"')," ",super.render())}componentDidUpdate(){this.rootEl.querySelectorAll("[data-feedback]").forEach((e=>{e.style.display="inline"}));const e=this.rootEl.closest("li.async");if(null!==e){e.querySelector("span[style]").style.textDecoration=this.getTextDecoration()}const{type:t}=this.state.validation;if(t===n.FieldFeedbackType.WhenValid){const e=this.rootEl.querySelector("span[style]"),t=this.rootEl.querySelector(`span.${this.props.classes.valid}`);e.style.textDecoration=null!==t?"":"line-through"}}}class c extends n.Async{constructor(){super(...arguments),this.rootEl=null}static getTextDecoration(){return"line-through dotted"}componentDidUpdate(){this.rootEl.querySelector("span[style]").style.textDecoration=c.getTextDecoration()}render(){return s.createElement("li",{className:"async",ref:e=>this.rootEl=e},s.createElement("span",{style:{textDecoration:c.getTextDecoration()}},"Async"),s.createElement("ul",null,super.render()))}}Object.defineProperty(e,"FormWithConstraints",{enumerable:!0,get:function(){return n.FormWithConstraints}}),e.Async=c,e.DisplayFields=i,e.FieldFeedback=d,e.FieldFeedbacks=l,Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "react-form-with-constraints-tools",
"version": "0.19.0-beta.1",
"version": "0.19.0-beta.2",
"description": "Simple form validation for React",

@@ -24,10 +24,10 @@ "repository": "github:tkrotoff/react-form-with-constraints",

"tsc": "tsc",
"build": "yarn build:dts && yarn build:esm && yarn build:cjs",
"build": "npm run build:dts && npm run build:esm && npm run build:cjs",
"build:dts": "tsc --project tsconfig.dist.json --declaration --emitDeclarationOnly --outDir dist",
"build:esm": "tsc --project tsconfig.dist.json --removeComments --outDir dist",
"build:cjs": "tsc --project tsconfig.dist.json --removeComments --module commonjs --outDir dist/cjs",
"build:umd": "yarn build:umd:dev && yarn build:umd:prod",
"build:umd": "npm run build:umd:dev && npm run build:umd:prod",
"build:umd:dev": "NODE_ENV=development rollup --config",
"build:umd:prod": "NODE_ENV=production rollup --config",
"prepublishOnly": "yarn clean && yarn build && yarn build:umd",
"prepublishOnly": "npm run clean && npm run build && npm run build:umd",
"prepack": "cp ../../LICENSE . && jscodeshift --transform=../../removeConsoleTransform.ts dist",

@@ -39,3 +39,3 @@ "postpack": "rm LICENSE",

"peerDependencies": {
"react-form-with-constraints": ">=0.17.0"
"react-form-with-constraints": ">=0.19.0"
},

@@ -45,5 +45,5 @@ "devDependencies": {

"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^28.1.4",
"@types/jest": "^28.1.6",
"@types/jscodeshift": "^0.11.5",
"@types/react-dom": "^18.0.6",
"@types/react": "^18.0.15",
"enzyme": "^3.11.0",

@@ -54,4 +54,4 @@ "enzyme-adapter-react-16": "^1.15.6",

"react": "^16.14.0",
"react-form-with-constraints": "^0.19.0-beta.1",
"rollup": "^2.76.0",
"react-form-with-constraints": "^0.19.0-beta.2",
"rollup": "^2.77.0",
"rollup-plugin-terser": "^7.0.2",

@@ -61,4 +61,3 @@ "rollup-plugin-typescript2": "^0.32.1",

"typescript": "^4.7.4"
},
"gitHead": "0071b45b6cb9c0381bb6066d69f4057d4f1f1632"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc