Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@domonda/form

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@domonda/form - npm Package Compare versions

Comparing version 2.3.2 to 2.3.3

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## 2.3.3 (2020-05-15)
**Note:** Version bump only for package @domonda/form
## [2.3.2](https://github.com/domonda/domonda-js/compare/@domonda/form@2.3.1...@domonda/form@2.3.2) (2020-04-20)

@@ -8,0 +16,0 @@

61

createForm.js

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

"use strict";
/**

@@ -7,22 +6,13 @@ *

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plumb_1 = require("@domonda/plumb");
const fast_equals_1 = require("fast-equals");
import { __awaiter } from "tslib";
import { createPlumb } from '@domonda/plumb';
import { deepEqual } from 'fast-equals';
// form
const Form_1 = require("./Form");
const createFormField_1 = require("./createFormField");
const FormTag_1 = require("./FormTag");
import { FormConfigRef } from './Form';
import { createFormField } from './createFormField';
import { FormTag } from './FormTag';
const DEFAULT_AUTO_SUBMIT_DELAY = 300;
function createForm(defaultValues = {}, initialConfig = {}) {
const configRef = new Form_1.FormConfigRef(initialConfig, handleSubmit);
const plumb = plumb_1.createPlumb({
export function createForm(defaultValues = {}, initialConfig = {}) {
const configRef = new FormConfigRef(initialConfig, handleSubmit);
const plumb = createPlumb({
defaultValues,

@@ -39,8 +29,8 @@ values: defaultValues,

case undefined:
case FormTag_1.FormTag.DEFAULT_VALUES_CHANGE:
case FormTag_1.FormTag.VALUES_CHANGE:
case FormTag_1.FormTag.VALUES_RESET:
case FormTag_1.FormTag.FIELD_VALUE_CHANGE:
case FormTag_1.FormTag.FIELD_VALUE_RESET:
case FormTag_1.FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE: {
case FormTag.DEFAULT_VALUES_CHANGE:
case FormTag.VALUES_CHANGE:
case FormTag.VALUES_RESET:
case FormTag.FIELD_VALUE_CHANGE:
case FormTag.FIELD_VALUE_RESET:
case FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE: {
if (configRef.current.transformer) {

@@ -61,7 +51,7 @@ return Object.assign(Object.assign({}, state), { values: configRef.current.transformer(state.values, tag) });

(() => {
if (tag !== FormTag_1.FormTag.FIELD_VALUE_CHANGE && tag !== FormTag_1.FormTag.VALUES_CHANGE) {
if (tag !== FormTag.FIELD_VALUE_CHANGE && tag !== FormTag.VALUES_CHANGE) {
return;
}
if (fast_equals_1.deepEqual(currState.values, nextState.values) ||
fast_equals_1.deepEqual(nextState.defaultValues, nextState.values)) {
if (deepEqual(currState.values, nextState.values) ||
deepEqual(nextState.defaultValues, nextState.values)) {
return;

@@ -97,8 +87,8 @@ }

reset: () => {
plumb.next(Object.assign(Object.assign({}, plumb.state), { values: plumb.state.defaultValues, submitting: false, submitError: null }), FormTag_1.FormTag.VALUES_RESET);
plumb.next(Object.assign(Object.assign({}, plumb.state), { values: plumb.state.defaultValues, submitting: false, submitError: null }), FormTag.VALUES_RESET);
},
resetSubmitError: () => {
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, submitError: null }), FormTag_1.FormTag.SUBMIT_ERROR_RESET);
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, submitError: null }), FormTag.SUBMIT_ERROR_RESET);
},
makeFormField: (path, config) => createFormField_1.createFormField(plumb, path, config),
makeFormField: (path, config) => createFormField(plumb, path, config),
};

@@ -112,3 +102,3 @@ function handleSubmit(event) {

}
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: true, submitError: null, disabled: disableOnSubmit ? true : plumb.state.disabled }), FormTag_1.FormTag.SUBMIT);
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: true, submitError: null, disabled: disableOnSubmit ? true : plumb.state.disabled }), FormTag.SUBMIT);
const { fields } = plumb.state;

@@ -123,3 +113,3 @@ const validityMessages = Object.keys(fields).reduce((acc, key) => {

if (validityMessages.some((validityMessages) => validityMessages != null)) {
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, disabled: false }), FormTag_1.FormTag.SUBMIT);
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, disabled: false }), FormTag.SUBMIT);
return;

@@ -131,3 +121,3 @@ }

if (!plumb.disposed) {
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, disabled: disableOnSubmit ? false : plumb.state.disabled, values: resetOnSuccessfulSubmit ? plumb.state.defaultValues : plumb.state.values }), resetOnSuccessfulSubmit ? FormTag_1.FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE : FormTag_1.FormTag.SUBMIT);
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, disabled: disableOnSubmit ? false : plumb.state.disabled, values: resetOnSuccessfulSubmit ? plumb.state.defaultValues : plumb.state.values }), resetOnSuccessfulSubmit ? FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE : FormTag.SUBMIT);
}

@@ -137,3 +127,3 @@ }

if (!plumb.disposed) {
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, submitError: error, disabled: disableOnSubmit ? false : plumb.state.disabled, values: resetOnFailedSubmit ? plumb.state.defaultValues : plumb.state.values }), resetOnFailedSubmit ? FormTag_1.FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE : FormTag_1.FormTag.SUBMIT);
plumb.next(Object.assign(Object.assign({}, plumb.state), { submitting: false, submitError: error, disabled: disableOnSubmit ? false : plumb.state.disabled, values: resetOnFailedSubmit ? plumb.state.defaultValues : plumb.state.values }), resetOnFailedSubmit ? FormTag.SUBMIT_WITH_DEFAULT_VALUES_CHANGE : FormTag.SUBMIT);
}

@@ -156,2 +146,1 @@ }

}
exports.createForm = createForm;

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

"use strict";
/**

@@ -7,26 +6,12 @@ *

*/
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const get_1 = __importDefault(require("lodash/get"));
const setWith_1 = __importDefault(require("lodash/fp/setWith"));
const unset_1 = __importDefault(require("lodash/fp/unset"));
const fast_equals_1 = require("fast-equals");
const FormTag_1 = require("./FormTag");
import { __rest } from "tslib";
import get from 'lodash/get';
import setWith from 'lodash/fp/setWith';
import unset from 'lodash/fp/unset';
import { deepEqual } from 'fast-equals';
import { FormTag } from './FormTag';
function selector(path, state) {
const { fields, defaultValues, values, disabled, readOnly } = state;
const defaultValue = get_1.default(defaultValues, path);
const value = get_1.default(values, path);
const defaultValue = get(defaultValues, path);
const value = get(values, path);
const field = fields[path];

@@ -48,3 +33,3 @@ if (!field) {

}
function createFormField(form, path, // [K in keyof FormDefaultValues]
export function createFormField(form, path, // [K in keyof FormDefaultValues]
config = {}) {

@@ -64,3 +49,3 @@ const { validate, immediateValidate, transformer } = config;

}
const changed = !fast_equals_1.deepEqual(selectedState.defaultValue, value);
const changed = !deepEqual(selectedState.defaultValue, value);
let validityMessage = selectedState.validityMessage;

@@ -79,3 +64,3 @@ if (validate && (changed || (immediateValidate && initialTransform))) {

? state.values
: setWith_1.default(() => undefined, path, rest.value, form.state.values), fields: Object.assign(Object.assign({}, form.state.fields), { [path]: {
: setWith(() => undefined, path, rest.value, form.state.values), fields: Object.assign(Object.assign({}, form.state.fields), { [path]: {
validityMessage,

@@ -88,6 +73,6 @@ changed,

switch (tag) {
case FormTag_1.FormTag.SUBMIT_ERROR_RESET:
case FormTag_1.FormTag.CREATE_FIELD:
case FormTag_1.FormTag.DISPOSE_FIELD:
case FormTag_1.FormTag.SUBMIT:
case FormTag.SUBMIT_ERROR_RESET:
case FormTag.CREATE_FIELD:
case FormTag.DISPOSE_FIELD:
case FormTag.SUBMIT:
return false;

@@ -97,4 +82,4 @@ }

readOnly !== selectedState.readOnly ||
!fast_equals_1.deepEqual(value, selectedState.value) ||
!fast_equals_1.deepEqual(defaultValue, selectedState.defaultValue);
!deepEqual(value, selectedState.value) ||
!deepEqual(defaultValue, selectedState.defaultValue);
disabled = selectedState.disabled;

@@ -106,6 +91,6 @@ readOnly = selectedState.readOnly;

},
}, FormTag_1.FormTag.CREATE_FIELD);
}, FormTag.CREATE_FIELD);
plumb.subscribe({
dispose: () => {
form.next(Object.assign(Object.assign({}, form.state), { fields: unset_1.default(path, form.state.fields) }), FormTag_1.FormTag.DISPOSE_FIELD);
form.next(Object.assign(Object.assign({}, form.state), { fields: unset(path, form.state.fields) }), FormTag.DISPOSE_FIELD);
},

@@ -123,12 +108,12 @@ });

setValue: (nextValue) => {
if (!fast_equals_1.deepEqual(plumb.state.value, nextValue)) {
if (!deepEqual(plumb.state.value, nextValue)) {
value = nextValue;
plumb.next(Object.assign(Object.assign({}, plumb.state), { value: nextValue }), FormTag_1.FormTag.FIELD_VALUE_CHANGE);
plumb.next(Object.assign(Object.assign({}, plumb.state), { value: nextValue }), FormTag.FIELD_VALUE_CHANGE);
}
},
resetValue: () => {
if (!fast_equals_1.deepEqual(plumb.state.defaultValue, plumb.state.value)) {
if (!deepEqual(plumb.state.defaultValue, plumb.state.value)) {
defaultValue = plumb.state.defaultValue;
value = plumb.state.value;
plumb.next(Object.assign(Object.assign({}, plumb.state), { value: plumb.state.defaultValue }), FormTag_1.FormTag.FIELD_VALUE_RESET);
plumb.next(Object.assign(Object.assign({}, plumb.state), { value: plumb.state.defaultValue }), FormTag.FIELD_VALUE_RESET);
}

@@ -140,2 +125,1 @@ },

}
exports.createFormField = createFormField;

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

"use strict";
/**

@@ -7,4 +6,3 @@ *

*/
Object.defineProperty(exports, "__esModule", { value: true });
class FormConfigRef {
export class FormConfigRef {
constructor(config, submitHandler) {

@@ -33,2 +31,1 @@ this.submitHandler = submitHandler;

}
exports.FormConfigRef = FormConfigRef;

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

"use strict";
/**

@@ -7,2 +6,1 @@ *

*/
Object.defineProperty(exports, "__esModule", { value: true });

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

"use strict";
/**

@@ -7,4 +6,3 @@ *

*/
Object.defineProperty(exports, "__esModule", { value: true });
var FormTag;
export var FormTag;
(function (FormTag) {

@@ -22,2 +20,2 @@ FormTag[FormTag["DEFAULT_VALUES_CHANGE"] = 0] = "DEFAULT_VALUES_CHANGE";

FormTag[FormTag["FORM_TOGGLE_DISABLE_OR_READ_ONLY"] = 10] = "FORM_TOGGLE_DISABLE_OR_READ_ONLY";
})(FormTag = exports.FormTag || (exports.FormTag = {}));
})(FormTag || (FormTag = {}));

@@ -1,9 +0,4 @@

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./Form"));
__export(require("./createForm"));
__export(require("./createFormField"));
__export(require("./FormTag"));
export * from './Form';
export * from './createForm';
export * from './createFormField';
export * from './FormTag';
{
"name": "@domonda/form",
"version": "2.3.2",
"version": "2.3.3",
"description": "Powerful yet simple form library built using @domonda/plumb.",

@@ -19,7 +19,4 @@ "keywords": [

},
"bugs": {
"url": "https://github.com/domonda/domonda-js/issues"
},
"dependencies": {
"@domonda/plumb": "^2.2.6",
"@domonda/plumb": "^2.2.7",
"fast-equals": "^2.0.0",

@@ -31,3 +28,3 @@ "lodash.get": "^4.4.2",

"main": "index.js",
"typings": "index.d.ts"
"types": "index.d.ts"
}
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