@sheinx/hooks 3.8.0-beta.12 → 3.8.0-beta.14
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/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +12 -3
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +6 -0
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +4 -0
- package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +12 -3
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +6 -0
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +4 -0
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA0JpC,CAAC,YAAY,GAAG,EAAE;;;;;EA4DrD"}
|
@@ -57,7 +57,8 @@ function useFormControl(props) {
|
|
57
57
|
defaultValue = props.defaultValue,
|
58
58
|
rules = props.rules,
|
59
59
|
onError = props.onError,
|
60
|
-
getValidateProps = props.getValidateProps
|
60
|
+
getValidateProps = props.getValidateProps,
|
61
|
+
clearToUndefined = props.clearToUndefined;
|
61
62
|
var _useFieldSetConsumer = (0, _fieldsetContext.useFieldSetConsumer)({
|
62
63
|
name: props.name,
|
63
64
|
bind: props.bind
|
@@ -115,7 +116,11 @@ function useFormControl(props) {
|
|
115
116
|
var nextValue = [];
|
116
117
|
name.forEach(function (n, index) {
|
117
118
|
if (_value[index] === undefined && dv[index] !== undefined) {
|
118
|
-
|
119
|
+
if (clearToUndefined) {
|
120
|
+
nextValue[index] = undefined;
|
121
|
+
} else {
|
122
|
+
nextValue[index] = dv[index];
|
123
|
+
}
|
119
124
|
} else {
|
120
125
|
nextValue[index] = _value[index];
|
121
126
|
}
|
@@ -129,7 +134,11 @@ function useFormControl(props) {
|
|
129
134
|
}
|
130
135
|
if (!(0, _shallowEqual.shallowEqual)(_value2, latestInfo.valueState)) {
|
131
136
|
if (_value2 === undefined && defaultValue !== undefined) {
|
132
|
-
|
137
|
+
if (clearToUndefined) {
|
138
|
+
setValueState(undefined);
|
139
|
+
} else {
|
140
|
+
setValueState(defaultValue);
|
141
|
+
}
|
133
142
|
} else {
|
134
143
|
setValueState(_value2);
|
135
144
|
}
|
@@ -32,6 +32,12 @@ export interface BaseFormControlProps<T> {
|
|
32
32
|
* @private 内部属性 for validate
|
33
33
|
*/
|
34
34
|
getValidateProps: (() => ObjectType) | undefined;
|
35
|
+
/**
|
36
|
+
* @en If set to true, the form will not automatically delete the data after the component is uninstalled
|
37
|
+
* @cn 设置为 true 组件后,有defaultValue时,允许undefined作为最终值
|
38
|
+
* @version 3.8.0
|
39
|
+
*/
|
40
|
+
clearToUndefined?: boolean;
|
35
41
|
}
|
36
42
|
export interface FormControlContext {
|
37
43
|
mounted: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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C;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;IAEjD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;oCAmUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAiWvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCArJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BApPnB,MAAM;gCAmUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAiWvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BArJpD,MAAM,0BAAyB,qBAAqB;;CA8b9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -339,6 +339,10 @@ var useForm = function useForm(props) {
|
|
339
339
|
Object.keys(context.defaultValues).forEach(function (df) {
|
340
340
|
var latestDefaultValue = getValue(df);
|
341
341
|
if (latestDefaultValue === undefined) {
|
342
|
+
// todo: Form组件传了clearToUndefined时,加入这部分判断?
|
343
|
+
// if(context.value.hasOwnProperty(df) && clearToUndefined){
|
344
|
+
// return;
|
345
|
+
// }
|
342
346
|
setValue(_defineProperty({}, df, context.defaultValues[df]), {
|
343
347
|
validate: false
|
344
348
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA0JpC,CAAC,YAAY,GAAG,EAAE;;;;;EA4DrD"}
|
@@ -48,7 +48,8 @@ export default function useFormControl(props) {
|
|
48
48
|
defaultValue = props.defaultValue,
|
49
49
|
rules = props.rules,
|
50
50
|
onError = props.onError,
|
51
|
-
getValidateProps = props.getValidateProps
|
51
|
+
getValidateProps = props.getValidateProps,
|
52
|
+
clearToUndefined = props.clearToUndefined;
|
52
53
|
var _useFieldSetConsumer = useFieldSetConsumer({
|
53
54
|
name: props.name,
|
54
55
|
bind: props.bind
|
@@ -106,7 +107,11 @@ export default function useFormControl(props) {
|
|
106
107
|
var nextValue = [];
|
107
108
|
name.forEach(function (n, index) {
|
108
109
|
if (_value[index] === undefined && dv[index] !== undefined) {
|
109
|
-
|
110
|
+
if (clearToUndefined) {
|
111
|
+
nextValue[index] = undefined;
|
112
|
+
} else {
|
113
|
+
nextValue[index] = dv[index];
|
114
|
+
}
|
110
115
|
} else {
|
111
116
|
nextValue[index] = _value[index];
|
112
117
|
}
|
@@ -120,7 +125,11 @@ export default function useFormControl(props) {
|
|
120
125
|
}
|
121
126
|
if (!shallowEqual(_value2, latestInfo.valueState)) {
|
122
127
|
if (_value2 === undefined && defaultValue !== undefined) {
|
123
|
-
|
128
|
+
if (clearToUndefined) {
|
129
|
+
setValueState(undefined);
|
130
|
+
} else {
|
131
|
+
setValueState(defaultValue);
|
132
|
+
}
|
124
133
|
} else {
|
125
134
|
setValueState(_value2);
|
126
135
|
}
|
@@ -32,6 +32,12 @@ export interface BaseFormControlProps<T> {
|
|
32
32
|
* @private 内部属性 for validate
|
33
33
|
*/
|
34
34
|
getValidateProps: (() => ObjectType) | undefined;
|
35
|
+
/**
|
36
|
+
* @en If set to true, the form will not automatically delete the data after the component is uninstalled
|
37
|
+
* @cn 设置为 true 组件后,有defaultValue时,允许undefined作为最终值
|
38
|
+
* @version 3.8.0
|
39
|
+
*/
|
40
|
+
clearToUndefined?: boolean;
|
35
41
|
}
|
36
42
|
export interface FormControlContext {
|
37
43
|
mounted: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;IAEjD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAiCA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApPnB,MAAM;oCAmUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAiWvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCArJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BApPnB,MAAM;gCAmUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA9RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAiWvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BArJpD,MAAM,0BAAyB,qBAAqB;;CA8b9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -330,6 +330,10 @@ var useForm = function useForm(props) {
|
|
330
330
|
Object.keys(context.defaultValues).forEach(function (df) {
|
331
331
|
var latestDefaultValue = getValue(df);
|
332
332
|
if (latestDefaultValue === undefined) {
|
333
|
+
// todo: Form组件传了clearToUndefined时,加入这部分判断?
|
334
|
+
// if(context.value.hasOwnProperty(df) && clearToUndefined){
|
335
|
+
// return;
|
336
|
+
// }
|
333
337
|
setValue(_defineProperty({}, df, context.defaultValues[df]), {
|
334
338
|
validate: false
|
335
339
|
});
|