@fairys/valtio-form-basic 1.0.4 → 1.0.5
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.
|
@@ -2,13 +2,12 @@ import { createContext, useContext, useRef } from "react";
|
|
|
2
2
|
import { proxy, ref as external_valtio_ref, snapshot, unstable_getInternalStates, useSnapshot } from "valtio";
|
|
3
3
|
import async_validator from "async-validator";
|
|
4
4
|
import { copy } from "fast-copy";
|
|
5
|
-
import { formatePath, get,
|
|
5
|
+
import { formatePath, get, removeValueByPaths, set } from "../utils/index.js";
|
|
6
6
|
class FairysValtioFormInstance {
|
|
7
7
|
onValuesChange;
|
|
8
8
|
isValtioProxy = (value)=>{
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
return canProxyDefault(value);
|
|
9
|
+
const { proxyStateMap } = unstable_getInternalStates();
|
|
10
|
+
return proxyStateMap.has(value);
|
|
12
11
|
};
|
|
13
12
|
state = proxy({});
|
|
14
13
|
errorState = proxy({});
|
|
@@ -20,10 +19,8 @@ class FairysValtioFormInstance {
|
|
|
20
19
|
const isValtioProxy = this.isValtioProxy(formData);
|
|
21
20
|
if (isValtioProxy) if ('deepCopy' === initFormDataType) this.updated(copy(snapshot(formData)), false);
|
|
22
21
|
else this.state = formData;
|
|
23
|
-
else {
|
|
24
|
-
|
|
25
|
-
this.updated(formData || {}, false);
|
|
26
|
-
}
|
|
22
|
+
else if ('deepCopy' === initFormDataType) this.updated(copy(formData || {}), false);
|
|
23
|
+
else this.updated(formData || {}, false);
|
|
27
24
|
};
|
|
28
25
|
updated = (state, isValidate = true)=>{
|
|
29
26
|
const keys = Object.keys(state);
|
|
@@ -51,9 +51,8 @@ const index_js_namespaceObject = require("../utils/index.js");
|
|
|
51
51
|
class FairysValtioFormInstance {
|
|
52
52
|
onValuesChange;
|
|
53
53
|
isValtioProxy = (value)=>{
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
return canProxyDefault(value);
|
|
54
|
+
const { proxyStateMap } = (0, external_valtio_namespaceObject.unstable_getInternalStates)();
|
|
55
|
+
return proxyStateMap.has(value);
|
|
57
56
|
};
|
|
58
57
|
state = (0, external_valtio_namespaceObject.proxy)({});
|
|
59
58
|
errorState = (0, external_valtio_namespaceObject.proxy)({});
|
|
@@ -65,10 +64,8 @@ class FairysValtioFormInstance {
|
|
|
65
64
|
const isValtioProxy = this.isValtioProxy(formData);
|
|
66
65
|
if (isValtioProxy) if ('deepCopy' === initFormDataType) this.updated((0, external_fast_copy_namespaceObject.copy)((0, external_valtio_namespaceObject.snapshot)(formData)), false);
|
|
67
66
|
else this.state = formData;
|
|
68
|
-
else {
|
|
69
|
-
|
|
70
|
-
this.updated(formData || {}, false);
|
|
71
|
-
}
|
|
67
|
+
else if ('deepCopy' === initFormDataType) this.updated((0, external_fast_copy_namespaceObject.copy)(formData || {}), false);
|
|
68
|
+
else this.updated(formData || {}, false);
|
|
72
69
|
};
|
|
73
70
|
updated = (state, isValidate = true)=>{
|
|
74
71
|
const keys = Object.keys(state);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "使用 valtio 实现的表单基础库, 使其更加便捷,同时支持`PC`、`H5`、`Taro`,同时也更加灵活。",
|
|
5
5
|
"homepage": "https://github.com/autumn-fairy-tales/valtio-form-basic",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.5",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "esm/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
|
@@ -20,21 +20,8 @@ export class FairysValtioFormInstance<T extends MObject<T> = Record<string, any>
|
|
|
20
20
|
* @returns 是否为代理对象
|
|
21
21
|
*/
|
|
22
22
|
isValtioProxy = (value: any) => {
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
isObject(x) &&
|
|
26
|
-
!refSet.has(x) &&
|
|
27
|
-
(Array.isArray(x) || !(Symbol.iterator in x)) &&
|
|
28
|
-
!(x instanceof WeakMap) &&
|
|
29
|
-
!(x instanceof WeakSet) &&
|
|
30
|
-
!(x instanceof Error) &&
|
|
31
|
-
!(x instanceof Number) &&
|
|
32
|
-
!(x instanceof Date) &&
|
|
33
|
-
!(x instanceof String) &&
|
|
34
|
-
!(x instanceof RegExp) &&
|
|
35
|
-
!(x instanceof ArrayBuffer) &&
|
|
36
|
-
!(x instanceof Promise);
|
|
37
|
-
return canProxyDefault(value);
|
|
23
|
+
const { proxyStateMap } = unstable_getInternalStates();
|
|
24
|
+
return proxyStateMap.has(value);
|
|
38
25
|
};
|
|
39
26
|
|
|
40
27
|
/**状态*/
|
|
@@ -58,18 +45,15 @@ export class FairysValtioFormInstance<T extends MObject<T> = Record<string, any>
|
|
|
58
45
|
const isValtioProxy = this.isValtioProxy(formData);
|
|
59
46
|
if (isValtioProxy) {
|
|
60
47
|
if (initFormDataType === 'deepCopy') {
|
|
61
|
-
// this.state = proxy(copy(snapshot(formData)) as T);
|
|
62
48
|
this.updated(copy(snapshot(formData)) as T, false);
|
|
63
49
|
} else {
|
|
64
50
|
this.state = formData as T;
|
|
65
|
-
// this.updated(formData as T, false);
|
|
66
51
|
}
|
|
67
52
|
} else {
|
|
68
53
|
if (initFormDataType === 'deepCopy') {
|
|
69
54
|
// this.state = proxy(copy(formData || {}) as T);
|
|
70
55
|
this.updated(copy(formData || {}) as T, false);
|
|
71
|
-
}
|
|
72
|
-
{
|
|
56
|
+
} else {
|
|
73
57
|
// this.state = proxy((formData || {}) as T);
|
|
74
58
|
this.updated((formData || {}) as T, false);
|
|
75
59
|
}
|