@progress/kendo-react-form 7.2.4-develop.3 → 7.3.0-develop.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Field.js +8 -0
- package/Field.mjs +71 -0
- package/FieldArray.js +8 -0
- package/FieldArray.mjs +74 -0
- package/FieldWrapper.js +8 -0
- package/FieldWrapper.mjs +24 -0
- package/Form.js +8 -0
- package/Form.mjs +247 -0
- package/FormContext.js +8 -0
- package/FormContext.mjs +13 -0
- package/FormElement.js +8 -0
- package/FormElement.mjs +42 -0
- package/dist/cdn/js/kendo-react-form.js +8 -5
- package/index.d.mts +724 -5
- package/index.d.ts +724 -22
- package/index.js +8 -5
- package/index.mjs +21 -412
- package/package-metadata.js +8 -0
- package/package-metadata.mjs +19 -0
- package/package.json +2 -2
- package/Field.d.ts +0 -14
- package/FieldArray.d.ts +0 -11
- package/FieldWrapper.d.ts +0 -32
- package/Form.d.ts +0 -272
- package/FormContext.d.ts +0 -54
- package/FormElement.d.ts +0 -56
- package/interfaces/FieldArrayProps.d.ts +0 -32
- package/interfaces/FieldArrayRenderProps.d.ts +0 -93
- package/interfaces/FieldProps.d.ts +0 -43
- package/interfaces/FieldRenderProps.d.ts +0 -10
- package/interfaces/FieldValidator.d.ts +0 -18
- package/interfaces/FormProps.d.ts +0 -56
- package/interfaces/FormRenderProps.d.ts +0 -78
- package/interfaces/FormSubmitClickEvent.d.ts +0 -27
- package/interfaces/FormValidator.d.ts +0 -14
- package/interfaces/KeyValue.d.ts +0 -10
- package/package-metadata.d.ts +0 -9
package/Field.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react"),p=require("./FormContext.js");function v(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const o in a)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(a,o);Object.defineProperty(e,o,l.get?l:{enumerable:!0,get:()=>a[o]})}}return e.default=a,Object.freeze(e)}const r=v(F),m=a=>{const{name:e,component:o,validator:l,children:i,onChange:c,...s}=a,t=r.useContext(p.FormContext),u=t?t.id:"";r.useEffect(()=>t?t.registerField(e,l):void 0,[e,u,l]);const h=r.useCallback(n=>{const b=n&&(n.value!==void 0?n.value:n.target?n.target.value:n.target);t.onChange(e,{value:b}),c&&c.call(void 0,n)},[e,u,c]),C=r.useCallback(n=>t.onChange(e,{value:n.target.value}),[e,u]),d=r.useCallback(()=>t.onBlur(e),[e,u]),g=r.useCallback(()=>t.onFocus(e),[e,u]);if(!t)return null;const f=t.valueGetter(e);return typeof o=="string"?r.createElement(o,{onChange:C,onBlur:d,onFocus:g,value:f,children:i,...s}):r.createElement(o,{children:i,...s,onChange:h,onBlur:d,onFocus:g,value:f,validationMessage:t.errors[e],touched:t.touched[e],modified:t.modified[e],visited:t.visited[e],valid:!(t.errors[e]&&t.touched[e]),name:e})};m.displayName="KendoReactField";exports.Field=m;
|
package/Field.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as t from "react";
|
|
10
|
+
import { FormContext as F } from "./FormContext.mjs";
|
|
11
|
+
const v = (h) => {
|
|
12
|
+
const { name: e, component: r, validator: s, children: u, onChange: l, ...i } = h, o = t.useContext(F), a = o ? o.id : "";
|
|
13
|
+
t.useEffect(
|
|
14
|
+
() => o ? o.registerField(e, s) : void 0,
|
|
15
|
+
[e, a, s]
|
|
16
|
+
);
|
|
17
|
+
const m = t.useCallback(
|
|
18
|
+
(n) => {
|
|
19
|
+
const f = n && (n.value !== void 0 ? n.value : n.target ? n.target.value : n.target);
|
|
20
|
+
o.onChange(e, { value: f }), l && l.call(void 0, n);
|
|
21
|
+
},
|
|
22
|
+
[e, a, l]
|
|
23
|
+
), C = t.useCallback(
|
|
24
|
+
(n) => o.onChange(e, { value: n.target.value }),
|
|
25
|
+
[e, a]
|
|
26
|
+
), c = t.useCallback(
|
|
27
|
+
() => o.onBlur(e),
|
|
28
|
+
[e, a]
|
|
29
|
+
), d = t.useCallback(
|
|
30
|
+
() => o.onFocus(e),
|
|
31
|
+
[e, a]
|
|
32
|
+
);
|
|
33
|
+
if (!o)
|
|
34
|
+
return null;
|
|
35
|
+
const g = o.valueGetter(e);
|
|
36
|
+
return typeof r == "string" ? t.createElement(r, {
|
|
37
|
+
onChange: C,
|
|
38
|
+
onBlur: c,
|
|
39
|
+
onFocus: d,
|
|
40
|
+
value: g,
|
|
41
|
+
children: u,
|
|
42
|
+
...i
|
|
43
|
+
}) : t.createElement(
|
|
44
|
+
r,
|
|
45
|
+
{
|
|
46
|
+
children: u,
|
|
47
|
+
...i,
|
|
48
|
+
// input
|
|
49
|
+
onChange: m,
|
|
50
|
+
onBlur: c,
|
|
51
|
+
onFocus: d,
|
|
52
|
+
value: g,
|
|
53
|
+
// meta
|
|
54
|
+
validationMessage: o.errors[e],
|
|
55
|
+
touched: o.touched[e],
|
|
56
|
+
modified: o.modified[e],
|
|
57
|
+
visited: o.visited[e],
|
|
58
|
+
// Our `valid` implementation requires double submit to show html5 validation errors,
|
|
59
|
+
// however it's NOT recommended to show html5 validation errors at all as:
|
|
60
|
+
// - There is no standard way to change validation look and feel with CSS.
|
|
61
|
+
// - Look different in each browser / OS
|
|
62
|
+
// - You can have a page in one language but an error message displayed in another language (not localizable)
|
|
63
|
+
valid: !(o.errors[e] && o.touched[e]),
|
|
64
|
+
name: e
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
v.displayName = "KendoReactField";
|
|
69
|
+
export {
|
|
70
|
+
v as Field
|
|
71
|
+
};
|
package/FieldArray.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react"),h=require("./FormContext.js");function k(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const c in s)if(c!=="default"){const a=Object.getOwnPropertyDescriptor(s,c);Object.defineProperty(e,c,a.get?a:{enumerable:!0,get:()=>s[c]})}}return e.default=s,Object.freeze(e)}const n=k(C),l=s=>{const{name:e,component:c,validator:a,type:F,children:i,...u}=s,t=n.useContext(h.FormContext),r=t?t.id:"";n.useEffect(()=>t?t.registerField(e,a):void 0,[e,r,a]);const d=n.useCallback(o=>t.onUnshift(e,o),[e,r]),f=n.useCallback(o=>t.onPush(e,o),[e,r]),m=n.useCallback(o=>t.onInsert(e,o),[e,r]),b=n.useCallback(()=>t.onPop(e),[e,r]),p=n.useCallback(o=>t.onRemove(e,o),[e,r]),v=n.useCallback(o=>t.onReplace(e,o),[e,r]),g=n.useCallback(o=>t.onMove(e,o),[e,r]);if(!t)return null;const y=t.valueGetter(e);return n.createElement(c,{value:y,validationMessage:t.errors[e],touched:t.touched[e],modified:t.modified[e],visited:t.visited[e],valid:!(t.errors[e]&&t.touched[e]),onUnshift:d,onPush:f,onInsert:m,onPop:b,onRemove:p,onReplace:v,onMove:g,children:i,name:e,...u})};l.displayName="KendoReactFieldArray";exports.FieldArray=l;
|
package/FieldArray.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as t from "react";
|
|
10
|
+
import { FormContext as b } from "./FormContext.mjs";
|
|
11
|
+
const k = (a) => {
|
|
12
|
+
const { name: e, component: l, validator: r, type: F, children: c, ...i } = a, o = t.useContext(b), s = o ? o.id : "";
|
|
13
|
+
t.useEffect(
|
|
14
|
+
() => o ? o.registerField(e, r) : void 0,
|
|
15
|
+
[e, s, r]
|
|
16
|
+
);
|
|
17
|
+
const u = t.useCallback(
|
|
18
|
+
(n) => o.onUnshift(e, n),
|
|
19
|
+
[e, s]
|
|
20
|
+
), d = t.useCallback(
|
|
21
|
+
(n) => o.onPush(e, n),
|
|
22
|
+
[e, s]
|
|
23
|
+
), m = t.useCallback(
|
|
24
|
+
(n) => o.onInsert(e, n),
|
|
25
|
+
[e, s]
|
|
26
|
+
), f = t.useCallback(
|
|
27
|
+
() => o.onPop(e),
|
|
28
|
+
[e, s]
|
|
29
|
+
), v = t.useCallback(
|
|
30
|
+
(n) => o.onRemove(e, n),
|
|
31
|
+
[e, s]
|
|
32
|
+
), p = t.useCallback(
|
|
33
|
+
(n) => o.onReplace(e, n),
|
|
34
|
+
[e, s]
|
|
35
|
+
), h = t.useCallback(
|
|
36
|
+
(n) => o.onMove(e, n),
|
|
37
|
+
[e, s]
|
|
38
|
+
);
|
|
39
|
+
if (!o)
|
|
40
|
+
return null;
|
|
41
|
+
const C = o.valueGetter(e);
|
|
42
|
+
return t.createElement(
|
|
43
|
+
l,
|
|
44
|
+
{
|
|
45
|
+
// input
|
|
46
|
+
value: C,
|
|
47
|
+
// meta
|
|
48
|
+
validationMessage: o.errors[e],
|
|
49
|
+
touched: o.touched[e],
|
|
50
|
+
modified: o.modified[e],
|
|
51
|
+
visited: o.visited[e],
|
|
52
|
+
// Our `valid` implementation requires double submit to show html5 validation errors,
|
|
53
|
+
// however it's NOT recommended to show html5 validation errors at all as:
|
|
54
|
+
// - There is no standard way to change validation look and feel with CSS.
|
|
55
|
+
// - Look different in each browser / OS
|
|
56
|
+
// - You can have a page in one language but an error message displayed in another language (not localizable)
|
|
57
|
+
valid: !(o.errors[e] && o.touched[e]),
|
|
58
|
+
onUnshift: u,
|
|
59
|
+
onPush: d,
|
|
60
|
+
onInsert: m,
|
|
61
|
+
onPop: f,
|
|
62
|
+
onRemove: v,
|
|
63
|
+
onReplace: p,
|
|
64
|
+
onMove: h,
|
|
65
|
+
children: c,
|
|
66
|
+
name: e,
|
|
67
|
+
...i
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
k.displayName = "KendoReactFieldArray";
|
|
72
|
+
export {
|
|
73
|
+
k as FieldArray
|
|
74
|
+
};
|
package/FieldWrapper.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),n=require("@progress/kendo-react-common");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const o=i(l),c=e=>{const t=n.classNames({"k-form-field":!0,"k-rtl":e.dir==="rtl"},e.className);return o.createElement("div",{className:t,style:e.style},e.children)};c.displayName="KendoReactFieldWrapper";exports.FieldWrapper=c;
|
package/FieldWrapper.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as l from "react";
|
|
10
|
+
import { classNames as t } from "@progress/kendo-react-common";
|
|
11
|
+
const r = (e) => {
|
|
12
|
+
const a = t(
|
|
13
|
+
{
|
|
14
|
+
"k-form-field": !0,
|
|
15
|
+
"k-rtl": e.dir === "rtl"
|
|
16
|
+
},
|
|
17
|
+
e.className
|
|
18
|
+
);
|
|
19
|
+
return /* @__PURE__ */ l.createElement("div", { className: a, style: e.style }, e.children);
|
|
20
|
+
};
|
|
21
|
+
r.displayName = "KendoReactFieldWrapper";
|
|
22
|
+
export {
|
|
23
|
+
r as FieldWrapper
|
|
24
|
+
};
|
package/Form.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react"),a=require("prop-types"),y=require("./FormContext.js"),u=require("@progress/kendo-react-common"),_=require("./package-metadata.js");function g(n){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(s,t,i.get?i:{enumerable:!0,get:()=>n[t]})}}return s.default=n,Object.freeze(s)}const f=g(F),b=0,l=class l extends f.Component{constructor(s){super(s),this._touched={},this._visited={},this._modified={},this._validatorsByField={},this._values={},this._fields={},this._unmounted=!1,this._submitted=!1,this.isValid=()=>this.isFormValid(this.errors),this.accumulatedForceUpdate=()=>{this._accumulatorTimeout&&clearTimeout(this._accumulatorTimeout),this._accumulatorTimeout=window.setTimeout(()=>{this._accumulatorTimeout=void 0,this.forceUpdate()},b)},this.resetForm=()=>{this.values=u.clone(this.props.initialValues),this._key=u.guid(),this._touched={},this._visited={},this._modified={},this._validatorsByField={},this._fields={},this._submitted=!1,this.forceUpdate()},this.onReset=()=>this.resetForm(),this.addField=t=>{this._fields[t]=!0},this.onSubmit=t=>{const i={},e=this.fields;t&&(typeof t.preventDefault=="function"&&t.preventDefault(),typeof t.stopPropagation=="function"&&t.stopPropagation()),e.forEach(d=>{i[d]=!0}),this.visited={...i},this.touched={...i};const o=this.values,h=this.isFormValid(this.errors),r=this.isFormModified(this.modified,e);this.props.onSubmitClick&&this.props.onSubmitClick.call(void 0,{values:o,isValid:h,isModified:r,event:t}),h&&(this.props.ignoreModified||r)&&this.props.onSubmit&&(this._submitted=!0,this.props.onSubmit.call(void 0,o,t)),this.forceUpdate()},this.onChange=(t,i)=>{const{value:e}=i;this.addField(t),this.modified[t]||(this.modified={...this.modified,[t]:!0}),this.valueSetter(t,e),this.forceUpdate()},this.onFocus=(t,i)=>{this.visited[t]||(this.visited={...this.visited,[t]:!0},i||this.forceUpdate())},this.onBlur=(t,i)=>{this.touched[t]||(this.onFocus(t,i),this.touched={...this.touched,[t]:!0},i||this.forceUpdate())},this.onFieldRegister=(t,i)=>{this.addField(t);const e=this.validatorsByField[t]||[],o=e.length;return this.validatorsByField={...this.validatorsByField,[t]:[...e,i]},this.accumulatedForceUpdate(),()=>{if(this._unmounted)return;const h=[...this.validatorsByField[t]||[]],r=!!h[o];h[o]=void 0,this.validatorsByField={...this.validatorsByField,[t]:h},r&&this.accumulatedForceUpdate()}},this.isFormValid=t=>!Object.keys(t).some(i=>!!t[i]),this.isFormModified=(t,i)=>i.some(e=>t[e]),this.isFormHasNotTouched=(t,i)=>i.some(e=>!t[e]),this.isFormTouched=(t,i)=>i.some(e=>t[e]),this.isFormVisited=(t,i)=>i.some(e=>t[e]),this.valueGetter=t=>u.getter(t)(this.values),this.valueSetter=(t,i)=>u.setter(t)(this.values,i),this.onArrayAction=t=>{this.addField(t),this.modified[t]||(this.modified={...this.modified,[t]:!0}),this.onBlur(t,!0)},this.onInsert=(t,i)=>{this.onArrayAction(t);const e=[...this.valueGetter(t)||[]];e.splice(i.index,0,i.value),this.valueSetter(t,e),this.forceUpdate()},this.onUnshift=(t,i)=>{this.onInsert(t,{value:i.value,index:0})},this.onPush=(t,i)=>{this.onArrayAction(t);const e=[...this.valueGetter(t)||[],i.value];this.valueSetter(t,e),this.forceUpdate()},this.onPop=t=>{this.onArrayAction(t);const i=[...this.valueGetter(t)||[]],e=i.pop();return this.valueSetter(t,i),this.forceUpdate(),e},this.onRemove=(t,i)=>{this.onArrayAction(t);const e=[...this.valueGetter(t)||[]],o=e.splice(i.index,1);return this.valueSetter(t,e),this.forceUpdate(),o},this.onReplace=(t,i)=>{this.onArrayAction(t);const e=[...this.valueGetter(t)||[]];e.splice(i.index,1,i.value),this.valueSetter(t,e),this.forceUpdate()},this.onMove=(t,i)=>{this.onArrayAction(t);const e=[...this.valueGetter(t)||[]],o=e[i.prevIndex];e.splice(i.prevIndex,1),e.splice(i.nextIndex,0,o),this.valueSetter(t,e),this.forceUpdate()},u.validatePackage(_.packageMetadata),this.values=u.clone(s.initialValues)}get touched(){return this._touched}set touched(s){this._touched=s}get visited(){return this._visited}set visited(s){this._visited=s}get modified(){return this._modified}set modified(s){this._modified=s}get validatorsByField(){return this._validatorsByField}set validatorsByField(s){this._validatorsByField=s}get values(){return this._values}set values(s){this._values=s}get fields(){return Object.keys(this._fields)}get formErrors(){if(this.props.validator)return this.props.validator(this.values,this.valueGetter)}get errors(){const s={},t=this.fields,i=this.validatorsByField;return t.forEach(o=>{if(s[o]="",i[o]){const h=[];i[o].forEach(r=>{Array.isArray(r)?h.push(...r):h.push(r)}),h.find(r=>{if(r){const d=r(this.valueGetter(o),this.valueGetter,{name:o});if(d)return s[o]=d,!0}return!1})}}),this.formErrors&&u.cloneObject(this.formErrors,s),s}componentWillUnmount(){this._unmounted=!0,this._accumulatorTimeout&&clearTimeout(this._accumulatorTimeout)}render(){const{render:s}=this.props,t=this.touched,i=this.visited,e=this.modified,o=this.fields,h=this.errors,r=this.isFormValid(h),d=this.isFormModified(e,o),v=this.isFormTouched(t,o),m=this.isFormVisited(i,o),p=this.isFormHasNotTouched(t,o)&&!r||r&&(this.props.ignoreModified||d);return f.createElement(y.FormContext.Provider,{key:this._key||this.props.id,value:{id:this.props.id,valueGetter:this.valueGetter,errors:h,modified:e,touched:t,visited:i,registerField:this.onFieldRegister,onSubmit:this.onSubmit,onChange:this.onChange,onFocus:this.onFocus,onBlur:this.onBlur,onUnshift:this.onUnshift,onPush:this.onPush,onInsert:this.onInsert,onPop:this.onPop,onRemove:this.onRemove,onReplace:this.onReplace,onMove:this.onMove}},s({valid:r,modified:d,touched:v,visited:m,submitted:this._submitted,valueGetter:this.valueGetter,errors:h,allowSubmit:p,onChange:this.onChange,onSubmit:this.onSubmit,onFormReset:this.resetForm}))}};l.displayName="KendoReactForm",l.propTypes={initialValues:a.any,onSubmit:a.func,onSubmitClick:a.func,render:a.func.isRequired,id:a.string};let c=l;exports.Form=c;
|
package/Form.mjs
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as a from "react";
|
|
10
|
+
import u from "prop-types";
|
|
11
|
+
import { FormContext as p } from "./FormContext.mjs";
|
|
12
|
+
import { clone as l, guid as F, getter as y, setter as _, validatePackage as g, cloneObject as A } from "@progress/kendo-react-common";
|
|
13
|
+
import { packageMetadata as U } from "./package-metadata.mjs";
|
|
14
|
+
const T = 0, n = class n extends a.Component {
|
|
15
|
+
/**
|
|
16
|
+
* @hidden
|
|
17
|
+
*/
|
|
18
|
+
constructor(o) {
|
|
19
|
+
super(o), this._touched = {}, this._visited = {}, this._modified = {}, this._validatorsByField = {}, this._values = {}, this._fields = {}, this._unmounted = !1, this._submitted = !1, this.isValid = () => this.isFormValid(this.errors), this.accumulatedForceUpdate = () => {
|
|
20
|
+
this._accumulatorTimeout && clearTimeout(this._accumulatorTimeout), this._accumulatorTimeout = window.setTimeout(
|
|
21
|
+
() => {
|
|
22
|
+
this._accumulatorTimeout = void 0, this.forceUpdate();
|
|
23
|
+
},
|
|
24
|
+
T
|
|
25
|
+
);
|
|
26
|
+
}, this.resetForm = () => {
|
|
27
|
+
this.values = l(this.props.initialValues), this._key = F(), this._touched = {}, this._visited = {}, this._modified = {}, this._validatorsByField = {}, this._fields = {}, this._submitted = !1, this.forceUpdate();
|
|
28
|
+
}, this.onReset = () => this.resetForm(), this.addField = (t) => {
|
|
29
|
+
this._fields[t] = !0;
|
|
30
|
+
}, this.onSubmit = (t) => {
|
|
31
|
+
const i = {}, s = this.fields;
|
|
32
|
+
t && (typeof t.preventDefault == "function" && t.preventDefault(), typeof t.stopPropagation == "function" && t.stopPropagation()), s.forEach((d) => {
|
|
33
|
+
i[d] = !0;
|
|
34
|
+
}), this.visited = { ...i }, this.touched = { ...i };
|
|
35
|
+
const e = this.values, h = this.isFormValid(this.errors), r = this.isFormModified(this.modified, s);
|
|
36
|
+
this.props.onSubmitClick && this.props.onSubmitClick.call(void 0, {
|
|
37
|
+
values: e,
|
|
38
|
+
isValid: h,
|
|
39
|
+
isModified: r,
|
|
40
|
+
event: t
|
|
41
|
+
}), h && (this.props.ignoreModified || r) && this.props.onSubmit && (this._submitted = !0, this.props.onSubmit.call(void 0, e, t)), this.forceUpdate();
|
|
42
|
+
}, this.onChange = (t, i) => {
|
|
43
|
+
const { value: s } = i;
|
|
44
|
+
this.addField(t), this.modified[t] || (this.modified = { ...this.modified, [t]: !0 }), this.valueSetter(t, s), this.forceUpdate();
|
|
45
|
+
}, this.onFocus = (t, i) => {
|
|
46
|
+
this.visited[t] || (this.visited = { ...this.visited, [t]: !0 }, i || this.forceUpdate());
|
|
47
|
+
}, this.onBlur = (t, i) => {
|
|
48
|
+
this.touched[t] || (this.onFocus(t, i), this.touched = { ...this.touched, [t]: !0 }, i || this.forceUpdate());
|
|
49
|
+
}, this.onFieldRegister = (t, i) => {
|
|
50
|
+
this.addField(t);
|
|
51
|
+
const s = this.validatorsByField[t] || [], e = s.length;
|
|
52
|
+
return this.validatorsByField = { ...this.validatorsByField, [t]: [...s, i] }, this.accumulatedForceUpdate(), () => {
|
|
53
|
+
if (this._unmounted)
|
|
54
|
+
return;
|
|
55
|
+
const h = [...this.validatorsByField[t] || []], r = !!h[e];
|
|
56
|
+
h[e] = void 0, this.validatorsByField = { ...this.validatorsByField, [t]: h }, r && this.accumulatedForceUpdate();
|
|
57
|
+
};
|
|
58
|
+
}, this.isFormValid = (t) => !Object.keys(t).some((i) => !!t[i]), this.isFormModified = (t, i) => i.some((s) => t[s]), this.isFormHasNotTouched = (t, i) => i.some((s) => !t[s]), this.isFormTouched = (t, i) => i.some((s) => t[s]), this.isFormVisited = (t, i) => i.some((s) => t[s]), this.valueGetter = (t) => y(t)(this.values), this.valueSetter = (t, i) => _(t)(this.values, i), this.onArrayAction = (t) => {
|
|
59
|
+
this.addField(t), this.modified[t] || (this.modified = { ...this.modified, [t]: !0 }), this.onBlur(t, !0);
|
|
60
|
+
}, this.onInsert = (t, i) => {
|
|
61
|
+
this.onArrayAction(t);
|
|
62
|
+
const s = [...this.valueGetter(t) || []];
|
|
63
|
+
s.splice(i.index, 0, i.value), this.valueSetter(t, s), this.forceUpdate();
|
|
64
|
+
}, this.onUnshift = (t, i) => {
|
|
65
|
+
this.onInsert(t, {
|
|
66
|
+
value: i.value,
|
|
67
|
+
index: 0
|
|
68
|
+
});
|
|
69
|
+
}, this.onPush = (t, i) => {
|
|
70
|
+
this.onArrayAction(t);
|
|
71
|
+
const s = [...this.valueGetter(t) || [], i.value];
|
|
72
|
+
this.valueSetter(t, s), this.forceUpdate();
|
|
73
|
+
}, this.onPop = (t) => {
|
|
74
|
+
this.onArrayAction(t);
|
|
75
|
+
const i = [...this.valueGetter(t) || []], s = i.pop();
|
|
76
|
+
return this.valueSetter(t, i), this.forceUpdate(), s;
|
|
77
|
+
}, this.onRemove = (t, i) => {
|
|
78
|
+
this.onArrayAction(t);
|
|
79
|
+
const s = [...this.valueGetter(t) || []], e = s.splice(i.index, 1);
|
|
80
|
+
return this.valueSetter(t, s), this.forceUpdate(), e;
|
|
81
|
+
}, this.onReplace = (t, i) => {
|
|
82
|
+
this.onArrayAction(t);
|
|
83
|
+
const s = [...this.valueGetter(t) || []];
|
|
84
|
+
s.splice(i.index, 1, i.value), this.valueSetter(t, s), this.forceUpdate();
|
|
85
|
+
}, this.onMove = (t, i) => {
|
|
86
|
+
this.onArrayAction(t);
|
|
87
|
+
const s = [...this.valueGetter(t) || []], e = s[i.prevIndex];
|
|
88
|
+
s.splice(i.prevIndex, 1), s.splice(i.nextIndex, 0, e), this.valueSetter(t, s), this.forceUpdate();
|
|
89
|
+
}, g(U), this.values = l(o.initialValues);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @hidden
|
|
93
|
+
*/
|
|
94
|
+
get touched() {
|
|
95
|
+
return this._touched;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @hidden
|
|
99
|
+
*/
|
|
100
|
+
set touched(o) {
|
|
101
|
+
this._touched = o;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @hidden
|
|
105
|
+
*/
|
|
106
|
+
get visited() {
|
|
107
|
+
return this._visited;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @hidden
|
|
111
|
+
*/
|
|
112
|
+
set visited(o) {
|
|
113
|
+
this._visited = o;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @hidden
|
|
117
|
+
*/
|
|
118
|
+
get modified() {
|
|
119
|
+
return this._modified;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @hidden
|
|
123
|
+
*/
|
|
124
|
+
set modified(o) {
|
|
125
|
+
this._modified = o;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @hidden
|
|
129
|
+
*/
|
|
130
|
+
get validatorsByField() {
|
|
131
|
+
return this._validatorsByField;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @hidden
|
|
135
|
+
*/
|
|
136
|
+
set validatorsByField(o) {
|
|
137
|
+
this._validatorsByField = o;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @hidden
|
|
141
|
+
*/
|
|
142
|
+
get values() {
|
|
143
|
+
return this._values;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @hidden
|
|
147
|
+
*/
|
|
148
|
+
set values(o) {
|
|
149
|
+
this._values = o;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @hidden
|
|
153
|
+
*/
|
|
154
|
+
get fields() {
|
|
155
|
+
return Object.keys(this._fields);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @hidden
|
|
159
|
+
*/
|
|
160
|
+
get formErrors() {
|
|
161
|
+
if (this.props.validator)
|
|
162
|
+
return this.props.validator(this.values, this.valueGetter);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @hidden
|
|
166
|
+
*/
|
|
167
|
+
get errors() {
|
|
168
|
+
const o = {}, t = this.fields, i = this.validatorsByField;
|
|
169
|
+
return t.forEach((e) => {
|
|
170
|
+
if (o[e] = "", i[e]) {
|
|
171
|
+
const h = [];
|
|
172
|
+
i[e].forEach((r) => {
|
|
173
|
+
Array.isArray(r) ? h.push(...r) : h.push(r);
|
|
174
|
+
}), h.find((r) => {
|
|
175
|
+
if (r) {
|
|
176
|
+
const d = r(this.valueGetter(e), this.valueGetter, { name: e });
|
|
177
|
+
if (d)
|
|
178
|
+
return o[e] = d, !0;
|
|
179
|
+
}
|
|
180
|
+
return !1;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}), this.formErrors && A(this.formErrors, o), o;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @hidden
|
|
187
|
+
*/
|
|
188
|
+
componentWillUnmount() {
|
|
189
|
+
this._unmounted = !0, this._accumulatorTimeout && clearTimeout(this._accumulatorTimeout);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* @hidden
|
|
193
|
+
*/
|
|
194
|
+
render() {
|
|
195
|
+
const { render: o } = this.props, t = this.touched, i = this.visited, s = this.modified, e = this.fields, h = this.errors, r = this.isFormValid(h), d = this.isFormModified(s, e), f = this.isFormTouched(t, e), v = this.isFormVisited(i, e), m = this.isFormHasNotTouched(t, e) && !r || r && (this.props.ignoreModified || d);
|
|
196
|
+
return /* @__PURE__ */ a.createElement(
|
|
197
|
+
p.Provider,
|
|
198
|
+
{
|
|
199
|
+
key: this._key || this.props.id,
|
|
200
|
+
value: {
|
|
201
|
+
id: this.props.id,
|
|
202
|
+
valueGetter: this.valueGetter,
|
|
203
|
+
errors: h,
|
|
204
|
+
modified: s,
|
|
205
|
+
touched: t,
|
|
206
|
+
visited: i,
|
|
207
|
+
registerField: this.onFieldRegister,
|
|
208
|
+
onSubmit: this.onSubmit,
|
|
209
|
+
onChange: this.onChange,
|
|
210
|
+
onFocus: this.onFocus,
|
|
211
|
+
onBlur: this.onBlur,
|
|
212
|
+
onUnshift: this.onUnshift,
|
|
213
|
+
onPush: this.onPush,
|
|
214
|
+
onInsert: this.onInsert,
|
|
215
|
+
onPop: this.onPop,
|
|
216
|
+
onRemove: this.onRemove,
|
|
217
|
+
onReplace: this.onReplace,
|
|
218
|
+
onMove: this.onMove
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
o({
|
|
222
|
+
valid: r,
|
|
223
|
+
modified: d,
|
|
224
|
+
touched: f,
|
|
225
|
+
visited: v,
|
|
226
|
+
submitted: this._submitted,
|
|
227
|
+
valueGetter: this.valueGetter,
|
|
228
|
+
errors: h,
|
|
229
|
+
allowSubmit: m,
|
|
230
|
+
onChange: this.onChange,
|
|
231
|
+
onSubmit: this.onSubmit,
|
|
232
|
+
onFormReset: this.resetForm
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
n.displayName = "KendoReactForm", n.propTypes = {
|
|
238
|
+
initialValues: u.any,
|
|
239
|
+
onSubmit: u.func,
|
|
240
|
+
onSubmitClick: u.func,
|
|
241
|
+
render: u.func.isRequired,
|
|
242
|
+
id: u.string
|
|
243
|
+
};
|
|
244
|
+
let c = n;
|
|
245
|
+
export {
|
|
246
|
+
c as Form
|
|
247
|
+
};
|
package/FormContext.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react");function c(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const a=c(r),u=a.createContext(null);exports.FormContext=u;
|
package/FormContext.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as t from "react";
|
|
10
|
+
const e = t.createContext(null);
|
|
11
|
+
export {
|
|
12
|
+
e as FormContext
|
|
13
|
+
};
|
package/FormElement.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),m=require("@progress/kendo-react-common"),p=require("./FormContext.js");function y(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const o=y(b),l=o.forwardRef((e,n)=>{const t={size:"medium",...e},r=o.useRef(null),c=o.useRef(null);o.useImperativeHandle(c,()=>({element:r.current,props:t})),o.useImperativeHandle(n,()=>c.current);const s=o.useContext(p.FormContext),{className:i,style:g,horizontal:u,size:a,...d}=t,f=m.classNames({"k-form":!0,[`k-form-${m.kendoThemeMaps.sizeMap[a]||a}`]:a,"k-form-horizontal":u===!0},i);return o.createElement("form",{ref:r,...d,id:s?s.id:void 0,style:e.style,className:f,onSubmit:s?s.onSubmit:void 0},e.children)});l.displayName="KendoReactFormElement";exports.FormElement=l;
|
package/FormElement.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
"use client";
|
|
9
|
+
import * as e from "react";
|
|
10
|
+
import { classNames as f, kendoThemeMaps as d } from "@progress/kendo-react-common";
|
|
11
|
+
import { FormContext as p } from "./FormContext.mjs";
|
|
12
|
+
const h = e.forwardRef((o, a) => {
|
|
13
|
+
const m = {
|
|
14
|
+
size: "medium",
|
|
15
|
+
...o
|
|
16
|
+
}, s = e.useRef(null), n = e.useRef(null);
|
|
17
|
+
e.useImperativeHandle(n, () => ({ element: s.current, props: m })), e.useImperativeHandle(a, () => n.current);
|
|
18
|
+
const t = e.useContext(p), { className: l, style: z, horizontal: i, size: r, ...c } = m, u = f(
|
|
19
|
+
{
|
|
20
|
+
"k-form": !0,
|
|
21
|
+
[`k-form-${d.sizeMap[r] || r}`]: r,
|
|
22
|
+
"k-form-horizontal": i === !0
|
|
23
|
+
},
|
|
24
|
+
l
|
|
25
|
+
);
|
|
26
|
+
return /* @__PURE__ */ e.createElement(
|
|
27
|
+
"form",
|
|
28
|
+
{
|
|
29
|
+
ref: s,
|
|
30
|
+
...c,
|
|
31
|
+
id: t ? t.id : void 0,
|
|
32
|
+
style: o.style,
|
|
33
|
+
className: u,
|
|
34
|
+
onSubmit: t ? t.onSubmit : void 0
|
|
35
|
+
},
|
|
36
|
+
o.children
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
h.displayName = "KendoReactFormElement";
|
|
40
|
+
export {
|
|
41
|
+
h as FormElement
|
|
42
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*-------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright © 2024 Progress Software Corporation. All rights reserved.
|
|
5
|
+
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
|
+
*-------------------------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types"),require("@progress/kendo-react-common")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","@progress/kendo-react-common"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).KendoReactForm={},e.React,e.PropTypes,e.KendoReactCommon)}(this,(function(e,t,i,s){"use strict";function o(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}})),t.default=e,Object.freeze(t)}var r=o(t);const n=r.createContext(null),a=e=>{const{name:t,component:i,validator:s,children:o,onChange:a,...d}=e,l=r.useContext(n),h=l?l.id:"";r.useEffect((()=>l?l.registerField(t,s):void 0),[t,h,s]);const u=r.useCallback((e=>{const i=e&&(void 0!==e.value?e.value:e.target?e.target.value:e.target);l.onChange(t,{value:i}),a&&a.call(void 0,e)}),[t,h,a]),c=r.useCallback((e=>l.onChange(t,{value:e.target.value})),[t,h]),m=r.useCallback((()=>l.onBlur(t)),[t,h]),v=r.useCallback((()=>l.onFocus(t)),[t,h]);if(!l)return null;const p=l.valueGetter(t);return"string"==typeof i?r.createElement(i,{onChange:c,onBlur:m,onFocus:v,value:p,children:o,...d}):r.createElement(i,{children:o,...d,onChange:u,onBlur:m,onFocus:v,value:p,validationMessage:l.errors[t],touched:l.touched[t],modified:l.modified[t],visited:l.visited[t],valid:!(l.errors[t]&&l.touched[t]),name:t})};a.displayName="KendoReactField";const d={name:"@progress/kendo-react-form",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},l=class extends r.Component{constructor(e){super(e),this._touched={},this._visited={},this._modified={},this._validatorsByField={},this._values={},this._fields={},this._unmounted=!1,this._submitted=!1,this.isValid=()=>this.isFormValid(this.errors),this.accumulatedForceUpdate=()=>{this._accumulatorTimeout&&clearTimeout(this._accumulatorTimeout),this._accumulatorTimeout=window.setTimeout((()=>{this._accumulatorTimeout=void 0,this.forceUpdate()}),0)},this.resetForm=()=>{this.values=s.clone(this.props.initialValues),this._key=s.guid(),this._touched={},this._visited={},this._modified={},this._validatorsByField={},this._fields={},this._submitted=!1,this.forceUpdate()},this.onReset=()=>this.resetForm(),this.addField=e=>{this._fields[e]=!0},this.onSubmit=e=>{const t={},i=this.fields;e&&("function"==typeof e.preventDefault&&e.preventDefault(),"function"==typeof e.stopPropagation&&e.stopPropagation()),i.forEach((e=>{t[e]=!0})),this.visited={...t},this.touched={...t};const s=this.values,o=this.isFormValid(this.errors),r=this.isFormModified(this.modified,i);this.props.onSubmitClick&&this.props.onSubmitClick.call(void 0,{values:s,isValid:o,isModified:r,event:e}),o&&(this.props.ignoreModified||r)&&this.props.onSubmit&&(this._submitted=!0,this.props.onSubmit.call(void 0,s,e)),this.forceUpdate()},this.onChange=(e,t)=>{const{value:i}=t;this.addField(e),this.modified[e]||(this.modified={...this.modified,[e]:!0}),this.valueSetter(e,i),this.forceUpdate()},this.onFocus=(e,t)=>{this.visited[e]||(this.visited={...this.visited,[e]:!0},t||this.forceUpdate())},this.onBlur=(e,t)=>{this.touched[e]||(this.onFocus(e,t),this.touched={...this.touched,[e]:!0},t||this.forceUpdate())},this.onFieldRegister=(e,t)=>{this.addField(e);const i=this.validatorsByField[e]||[],s=i.length;return this.validatorsByField={...this.validatorsByField,[e]:[...i,t]},this.accumulatedForceUpdate(),()=>{if(this._unmounted)return;const t=[...this.validatorsByField[e]||[]],i=!!t[s];t[s]=void 0,this.validatorsByField={...this.validatorsByField,[e]:t},i&&this.accumulatedForceUpdate()}},this.isFormValid=e=>!Object.keys(e).some((t=>!!e[t])),this.isFormModified=(e,t)=>t.some((t=>e[t])),this.isFormHasNotTouched=(e,t)=>t.some((t=>!e[t])),this.isFormTouched=(e,t)=>t.some((t=>e[t])),this.isFormVisited=(e,t)=>t.some((t=>e[t])),this.valueGetter=e=>s.getter(e)(this.values),this.valueSetter=(e,t)=>s.setter(e)(this.values,t),this.onArrayAction=e=>{this.addField(e),this.modified[e]||(this.modified={...this.modified,[e]:!0}),this.onBlur(e,!0)},this.onInsert=(e,t)=>{this.onArrayAction(e);const i=[...this.valueGetter(e)||[]];i.splice(t.index,0,t.value),this.valueSetter(e,i),this.forceUpdate()},this.onUnshift=(e,t)=>{this.onInsert(e,{value:t.value,index:0})},this.onPush=(e,t)=>{this.onArrayAction(e);const i=[...this.valueGetter(e)||[],t.value];this.valueSetter(e,i),this.forceUpdate()},this.onPop=e=>{this.onArrayAction(e);const t=[...this.valueGetter(e)||[]],i=t.pop();return this.valueSetter(e,t),this.forceUpdate(),i},this.onRemove=(e,t)=>{this.onArrayAction(e);const i=[...this.valueGetter(e)||[]],s=i.splice(t.index,1);return this.valueSetter(e,i),this.forceUpdate(),s},this.onReplace=(e,t)=>{this.onArrayAction(e);const i=[...this.valueGetter(e)||[]];i.splice(t.index,1,t.value),this.valueSetter(e,i),this.forceUpdate()},this.onMove=(e,t)=>{this.onArrayAction(e);const i=[...this.valueGetter(e)||[]],s=i[t.prevIndex];i.splice(t.prevIndex,1),i.splice(t.nextIndex,0,s),this.valueSetter(e,i),this.forceUpdate()},s.validatePackage(d),this.values=s.clone(e.initialValues)}get touched(){return this._touched}set touched(e){this._touched=e}get visited(){return this._visited}set visited(e){this._visited=e}get modified(){return this._modified}set modified(e){this._modified=e}get validatorsByField(){return this._validatorsByField}set validatorsByField(e){this._validatorsByField=e}get values(){return this._values}set values(e){this._values=e}get fields(){return Object.keys(this._fields)}get formErrors(){if(this.props.validator)return this.props.validator(this.values,this.valueGetter)}get errors(){const e={},t=this.fields,i=this.validatorsByField;return t.forEach((t=>{if(e[t]="",i[t]){const s=[];i[t].forEach((e=>{Array.isArray(e)?s.push(...e):s.push(e)})),s.find((i=>{if(i){const s=i(this.valueGetter(t),this.valueGetter,{name:t});if(s)return e[t]=s,!0}return!1}))}})),this.formErrors&&s.cloneObject(this.formErrors,e),e}componentWillUnmount(){this._unmounted=!0,this._accumulatorTimeout&&clearTimeout(this._accumulatorTimeout)}render(){const{render:e}=this.props,t=this.touched,i=this.visited,s=this.modified,o=this.fields,a=this.errors,d=this.isFormValid(a),l=this.isFormModified(s,o),h=this.isFormTouched(t,o),u=this.isFormVisited(i,o),c=this.isFormHasNotTouched(t,o)&&!d||d&&(this.props.ignoreModified||l);return r.createElement(n.Provider,{key:this._key||this.props.id,value:{id:this.props.id,valueGetter:this.valueGetter,errors:a,modified:s,touched:t,visited:i,registerField:this.onFieldRegister,onSubmit:this.onSubmit,onChange:this.onChange,onFocus:this.onFocus,onBlur:this.onBlur,onUnshift:this.onUnshift,onPush:this.onPush,onInsert:this.onInsert,onPop:this.onPop,onRemove:this.onRemove,onReplace:this.onReplace,onMove:this.onMove}},e({valid:d,modified:l,touched:h,visited:u,submitted:this._submitted,valueGetter:this.valueGetter,errors:a,allowSubmit:c,onChange:this.onChange,onSubmit:this.onSubmit,onFormReset:this.resetForm}))}};l.displayName="KendoReactForm",l.propTypes={initialValues:i.any,onSubmit:i.func,onSubmitClick:i.func,render:i.func.isRequired,id:i.string};let h=l;const u=e=>{const{name:t,component:i,validator:s,type:o,children:a,...d}=e,l=r.useContext(n),h=l?l.id:"";r.useEffect((()=>l?l.registerField(t,s):void 0),[t,h,s]);const u=r.useCallback((e=>l.onUnshift(t,e)),[t,h]),c=r.useCallback((e=>l.onPush(t,e)),[t,h]),m=r.useCallback((e=>l.onInsert(t,e)),[t,h]),v=r.useCallback((()=>l.onPop(t)),[t,h]),p=r.useCallback((e=>l.onRemove(t,e)),[t,h]),f=r.useCallback((e=>l.onReplace(t,e)),[t,h]),F=r.useCallback((e=>l.onMove(t,e)),[t,h]);if(!l)return null;const y=l.valueGetter(t);return r.createElement(i,{value:y,validationMessage:l.errors[t],touched:l.touched[t],modified:l.modified[t],visited:l.visited[t],valid:!(l.errors[t]&&l.touched[t]),onUnshift:u,onPush:c,onInsert:m,onPop:v,onRemove:p,onReplace:f,onMove:F,children:a,name:t,...d})};u.displayName="KendoReactFieldArray";const c=e=>{const t=s.classNames({"k-form-field":!0,"k-rtl":"rtl"===e.dir},e.className);return r.createElement("div",{className:t,style:e.style},e.children)};c.displayName="KendoReactFieldWrapper";const m=r.forwardRef(((e,t)=>{const i={size:"medium",...e},o=r.useRef(null),a=r.useRef(null);r.useImperativeHandle(a,(()=>({element:o.current,props:i}))),r.useImperativeHandle(t,(()=>a.current));const d=r.useContext(n),{className:l,style:h,horizontal:u,size:c,...m}=i,v=s.classNames({"k-form":!0,[`k-form-${s.kendoThemeMaps.sizeMap[c]||c}`]:c,"k-form-horizontal":!0===u},l);return r.createElement("form",{ref:o,...m,id:d?d.id:void 0,style:e.style,className:v,onSubmit:d?d.onSubmit:void 0},e.children)}));m.displayName="KendoReactFormElement";const v=s.withIdHOC(h);v.displayName="KendoReactForm",e.Field=a,e.FieldArray=u,e.FieldWrapper=c,e.Form=v,e.FormClassComponent=h,e.FormElement=m}));
|