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

formulr

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formulr - npm Package Compare versions

Comparing version 0.2.0-beta.40 to 0.2.0-beta.41

lib/field-utils.d.ts

4

lib/builders/field.d.ts

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

import { FieldModel } from '../models';
import { FieldModel, INormalizeBeforeSubmit } from '../models';
import { BasicBuilder } from './basic';

@@ -7,4 +7,6 @@ import { Maybe } from '../maybe';

constructor(_defaultValue: Value);
private _normalizeBeforeSubmit;
normalizeBeforeSubmit<T>(normalizeBeforeSubmit: INormalizeBeforeSubmit<Value, T>): void;
build(defaultValue?: Maybe<Value>): FieldModel<Value>;
}
//# sourceMappingURL=field.d.ts.map

@@ -5,2 +5,3 @@ import { __extends } from "tslib";

import { or } from '../maybe';
import { id } from '../utils';
var FieldBuilder = /** @class */ (function (_super) {

@@ -11,7 +12,12 @@ __extends(FieldBuilder, _super);

_this._defaultValue = _defaultValue;
_this._normalizeBeforeSubmit = id;
return _this;
}
FieldBuilder.prototype.normalizeBeforeSubmit = function (normalizeBeforeSubmit) {
this._normalizeBeforeSubmit = normalizeBeforeSubmit;
};
FieldBuilder.prototype.build = function (defaultValue) {
var model = new FieldModel(or(defaultValue, this._defaultValue));
model.validators = this._validators;
model.normalizeBeforeSubmit = this._normalizeBeforeSubmit;
return model;

@@ -18,0 +24,0 @@ };

import { FieldModel, ModelRef } from './models';
import { IValidators } from './validate';
export declare function makeDefaultFieldProps<Value>(model: FieldModel<Value>): {
value: Value;
onChange(value: Value): void;
onCompositionStart(): void;
onCompositionEnd(): void;
onBlur(): void;
onFocus(): void;
};
export declare enum ValidateOccasion {
None = 0,
Change = 1,
Blur = 2,
Default = 3
}
export declare function useField<Value>(field: string, defaultValue: Value | (() => Value), validators?: IValidators<Value>): FieldModel<Value>;
export declare function useField<Value>(field: FieldModel<Value> | ModelRef<Value, any, FieldModel<Value>>): FieldModel<Value>;
//# sourceMappingURL=field.d.ts.map

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

import { useMemo, useRef, useEffect } from 'react';
import { unstable_scheduleCallback as scheduleCallback, unstable_cancelCallback as cancelCallback, unstable_IdlePriority as IdlePriority, } from 'scheduler';
import { useMemo } from 'react';
import { FieldModel, FormStrategy, isModelRef, isFieldModel, } from './models';

@@ -8,38 +7,10 @@ import { useValue$ } from './hooks';

import { or } from './maybe';
export function makeDefaultFieldProps(model) {
var value = model.value;
var taskRef = useRef(null);
var props = useMemo(function () { return ({
value: value,
onChange: function (value) {
model.onChange(value);
if (model.isCompositing) {
return;
}
if (!taskRef.current) {
taskRef.current = scheduleCallback(IdlePriority, function () {
taskRef.current = null;
model.validate();
});
}
},
onCompositionStart: function () {
model.isCompositing = true;
},
onCompositionEnd: function () {
model.isCompositing = false;
},
onBlur: function () {
model.validate();
},
onFocus: function () {
model._touched = true;
},
}); }, [model]);
useEffect(function () { return function () {
taskRef.current && cancelCallback(taskRef.current);
}; }, []);
props.value = value;
return props;
}
// prettier-ignore
export var ValidateOccasion;
(function (ValidateOccasion) {
ValidateOccasion[ValidateOccasion["None"] = 0] = "None";
ValidateOccasion[ValidateOccasion["Change"] = 1] = "Change";
ValidateOccasion[ValidateOccasion["Blur"] = 2] = "Blur";
ValidateOccasion[ValidateOccasion["Default"] = 3] = "Default";
})(ValidateOccasion || (ValidateOccasion = {}));
function useModelAndChildProps(field, parent, strategy, defaultValue, form) {

@@ -46,0 +17,0 @@ return useMemo(function () {

import * as Validators from './validators';
import * as FieldUtils from './field-utils';
export * from './builders';

@@ -13,3 +14,3 @@ export * from './field';

export * from './maybe';
export { Validators };
export { Validators, FieldUtils };
//# sourceMappingURL=index.d.ts.map
import * as Validators from './validators';
import * as FieldUtils from './field-utils';
export * from './builders';

@@ -13,3 +14,3 @@ export * from './field';

export * from './maybe';
export { Validators };
export { Validators, FieldUtils };
//# sourceMappingURL=index.js.map

@@ -23,2 +23,3 @@ import { BehaviorSubject } from 'rxjs';

getRawValue(): (Item | null)[];
getSubmitValue(): (Item | null)[];
patchValue(value: Item[]): void;

@@ -25,0 +26,0 @@ initialize(values: Item[]): void;

@@ -68,2 +68,14 @@ import { __extends, __spreadArrays } from "tslib";

};
FieldArrayModel.prototype.getSubmitValue = function () {
return this.children$.getValue().map(function (child) {
if (isModelRef(child)) {
var model = child.getModel();
return model ? model.getSubmitValue() : null;
}
else if (isModel(child)) {
return child.getSubmitValue();
}
return null;
});
};
FieldArrayModel.prototype.patchValue = function (value) {

@@ -70,0 +82,0 @@ var children = this.children$.getValue();

@@ -40,2 +40,3 @@ import { Subject, BehaviorSubject } from 'rxjs';

abstract getRawValue(): any;
abstract getSubmitValue(): any;
readonly error$: BehaviorSubject<IMaybeError<Value>>;

@@ -42,0 +43,0 @@ constructor();

@@ -5,2 +5,5 @@ import { BehaviorSubject } from 'rxjs';

declare const FIELD: unique symbol;
export interface INormalizeBeforeSubmit<A, B> {
(a: A): B;
}
declare class FieldModel<Value> extends BasicModel<Value> {

@@ -13,5 +16,5 @@ private readonly defaultValue;

readonly value$: BehaviorSubject<Value>;
/** @internal */
_touched: boolean;
isTouched: boolean;
isCompositing: boolean;
normalizeBeforeSubmit: INormalizeBeforeSubmit<Value, any>;
/** @internal */

@@ -24,2 +27,3 @@ constructor(defaultValue: Value);

getRawValue(): Value;
getSubmitValue(): any;
valid(): boolean;

@@ -31,3 +35,2 @@ validate(option?: ValidateOption): Promise<unknown>;

touched(): boolean;
onChange(value: Value): void;
}

@@ -34,0 +37,0 @@ declare function isFieldModel<T>(maybeModel: any): maybeModel is FieldModel<T>;

@@ -6,2 +6,3 @@ import { __extends } from "tslib";

import { ValidateOption } from '../validate';
import { id } from '../utils';
var FIELD = Symbol('field');

@@ -14,5 +15,5 @@ var FieldModel = /** @class */ (function (_super) {

_this.defaultValue = defaultValue;
/** @internal */
_this._touched = false;
_this.isTouched = false;
_this.isCompositing = false;
_this.normalizeBeforeSubmit = id;
_this.value$ = new BehaviorSubject(defaultValue);

@@ -45,2 +46,6 @@ return _this;

};
FieldModel.prototype.getSubmitValue = function () {
var normalizeBeforeSubmit = this.normalizeBeforeSubmit;
return normalizeBeforeSubmit(this.value$.getValue());
};
FieldModel.prototype.valid = function () {

@@ -67,8 +72,4 @@ return this.error$.getValue() === null;

FieldModel.prototype.touched = function () {
return this._touched;
return this.isTouched;
};
FieldModel.prototype.onChange = function (value) {
this.value$.next(value);
this._touched = true;
};
return FieldModel;

@@ -75,0 +76,0 @@ }(BasicModel));

@@ -27,2 +27,3 @@ import { Subject } from 'rxjs';

getRawValue(): $FieldSetValue<Children>;
getSubmitValue(): any;
registerChild(name: string, model: BasicModel<unknown>): void;

@@ -29,0 +30,0 @@ removeChild(name: string): BasicModel<any>;

@@ -54,2 +54,13 @@ import { __extends } from "tslib";

};
FieldSetModel.prototype.getSubmitValue = function () {
var value = {};
var childrenKeys = Object.keys(this.children);
for (var i = 0; i < childrenKeys.length; i++) {
var key = childrenKeys[i];
var model = this.children[key];
var childValue = model.getSubmitValue();
value[key] = childValue;
}
return value;
};
FieldSetModel.prototype.registerChild = function (name, model) {

@@ -56,0 +67,0 @@ model.form = this.form;

import { FieldSetModel, BasicModel, ModelRef } from './models';
export declare function noop(): void;
export declare const id: <T>(it: T) => T;
export declare function isPlainObject(value: unknown): value is object;
export declare function removeOnUnmount(field: string | BasicModel<any> | ModelRef<any, any>, model: BasicModel<any>, parent: FieldSetModel): void;
//# sourceMappingURL=utils.d.ts.map
import { useEffect } from 'react';
export function noop() { }
export var id = function (it) { return it; };
export function isPlainObject(value) {

@@ -4,0 +5,0 @@ if (value === null || typeof value !== 'object') {

{
"name": "formulr",
"version": "0.2.0-beta.40",
"version": "0.2.0-beta.41",
"description": "Form toolkit for React",

@@ -12,3 +12,3 @@ "main": "./lib/index.js",

"prepublishOnly": "npm run build",
"doc": "typedoc --out ../zent-contrib.github.io/formulr --mode file"
"doc": "typedoc --out typedoc --mode file && gh-pages -d typedoc"
},

@@ -47,5 +47,6 @@ "repository": {

"@babel/preset-react": "^7.0.0",
"@types/scheduler": "^0.16.0",
"@types/scheduler": "~0.16.1",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.0.6",
"gh-pages": "^2.1.1",
"html-webpack-plugin": "^3.2.0",

@@ -52,0 +53,0 @@ "jest": "^24.8.0",

@@ -1,4 +0,5 @@

import { FieldModel } from '../models';
import { FieldModel, INormalizeBeforeSubmit } from '../models';
import { BasicBuilder } from './basic';
import { Maybe, or } from '../maybe';
import { id } from '../utils';

@@ -10,7 +11,14 @@ export class FieldBuilder<Value> extends BasicBuilder<Value, FieldModel<Value>> {

private _normalizeBeforeSubmit: INormalizeBeforeSubmit<Value, any> = id;
normalizeBeforeSubmit<T>(normalizeBeforeSubmit: INormalizeBeforeSubmit<Value, T>) {
this._normalizeBeforeSubmit = normalizeBeforeSubmit;
}
build(defaultValue?: Maybe<Value>) {
const model = new FieldModel(or(defaultValue, this._defaultValue));
model.validators = this._validators;
model.normalizeBeforeSubmit = this._normalizeBeforeSubmit;
return model;
}
}
import * as Validators from './validators';
import * as FieldUtils from './field-utils';
export * from './builders';

@@ -13,2 +15,2 @@ export * from './field';

export * from './maybe';
export { Validators };
export { Validators, FieldUtils };

@@ -80,2 +80,14 @@ import { BehaviorSubject } from 'rxjs';

getSubmitValue(): (Item | null)[] {
return this.children$.getValue().map(child => {
if (isModelRef<Item, this, Child>(child)) {
const model = child.getModel();
return model ? model.getSubmitValue() : null;
} else if (isModel<Item>(child)) {
return child.getSubmitValue();
}
return null;
});
}
patchValue(value: Item[]) {

@@ -82,0 +94,0 @@ const children = this.children$.getValue();

@@ -48,2 +48,3 @@ import { Subject, BehaviorSubject } from 'rxjs';

abstract getRawValue(): any;
abstract getSubmitValue(): any;

@@ -50,0 +51,0 @@ readonly error$ = new BehaviorSubject<IMaybeError<Value>>(null);

@@ -5,5 +5,10 @@ import { BehaviorSubject } from 'rxjs';

import { ValidateOption } from '../validate';
import { id } from '../utils';
const FIELD = Symbol('field');
export interface INormalizeBeforeSubmit<A, B> {
(a: A): B;
}
class FieldModel<Value> extends BasicModel<Value> {

@@ -16,6 +21,6 @@ /**

readonly value$: BehaviorSubject<Value>;
/** @internal */
_touched = false;
isTouched = false;
isCompositing = false;
normalizeBeforeSubmit: INormalizeBeforeSubmit<Value, any> = id;

@@ -54,2 +59,7 @@ /** @internal */

getSubmitValue() {
const { normalizeBeforeSubmit } = this;
return normalizeBeforeSubmit(this.value$.getValue());
}
valid() {

@@ -80,9 +90,4 @@ return this.error$.getValue() === null;

touched() {
return this._touched;
return this.isTouched;
}
onChange(value: Value) {
this.value$.next(value);
this._touched = true;
}
}

@@ -89,0 +94,0 @@

@@ -71,2 +71,14 @@ import { Subject } from 'rxjs';

getSubmitValue() {
const value: any = {};
const childrenKeys = Object.keys(this.children);
for (let i = 0; i < childrenKeys.length; i++) {
const key = childrenKeys[i];
const model = this.children[key] as BasicModel<unknown>;
const childValue = model.getSubmitValue();
value[key] = childValue;
}
return value;
}
registerChild(name: string, model: BasicModel<unknown>) {

@@ -73,0 +85,0 @@ model.form = this.form;

@@ -6,2 +6,4 @@ import { useEffect } from 'react';

export const id = <T>(it: T) => it;
export function isPlainObject(value: unknown): value is object {

@@ -8,0 +10,0 @@ if (value === null || typeof value !== 'object') {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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