@sheinx/hooks 3.4.4-beta.1 → 3.4.4-beta.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -139,7 +139,7 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
139
139
  }
140
140
  var targetPosition = position;
141
141
  var rootContainer = getContainer() || document.body;
142
- var closestScrollContainer = (0, _element.getClosestScrollContainer)(parentElRef.current);
142
+ var closestScrollContainer = absolute ? null : (0, _element.getClosestScrollContainer)(parentElRef.current);
143
143
  var containerRect = rootContainer.getBoundingClientRect();
144
144
  var bodyRect = (document.documentElement || document.body).getBoundingClientRect();
145
145
  var containerScrollBarWidth = rootContainer.offsetWidth - rootContainer.clientWidth;
@@ -1 +1 @@
1
- {"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAyB/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBAmHpC,CAAC,YAAY,GAAG,EAAE;;;;;EAiDrD"}
1
+ {"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAyB/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA2IpC,CAAC,YAAY,GAAG,EAAE;;;;;EAiDrD"}
@@ -97,14 +97,37 @@ function useFormControl(props) {
97
97
  var errors = arguments.length > 1 ? arguments[1] : undefined;
98
98
  var severErrors = arguments.length > 2 ? arguments[2] : undefined;
99
99
  if (!name) return;
100
- var value = getValue(name, formValue);
101
- var error = getError(name, errors, severErrors);
102
- if (error !== errorState) {
103
- setErrorState(error);
104
- }
105
- if (!(0, _shallowEqual.shallowEqual)(value, latestInfo.valueState)) {
106
- setValueState(value);
107
- latestInfo.valueState = value;
100
+ if ((0, _is.isArray)(name)) {
101
+ var _value = getValue(name, formValue);
102
+ var _error = getError(name, errors, severErrors);
103
+ if (_error !== errorState) {
104
+ setErrorState(_error);
105
+ }
106
+ // format defaultValue
107
+ var dv = (0, _is.isArray)(defaultValue) ? defaultValue : [];
108
+ var nextValue = [];
109
+ name.forEach(function (n, index) {
110
+ if (_value[index] === undefined && dv[index] !== undefined) {
111
+ nextValue[index] = dv[index];
112
+ } else {
113
+ nextValue[index] = _value[index];
114
+ }
115
+ });
116
+ setValueState(nextValue);
117
+ } else {
118
+ var _value2 = getValue(name, formValue);
119
+ var _error2 = getError(name, errors, severErrors);
120
+ if (_error2 !== errorState) {
121
+ setErrorState(_error2);
122
+ }
123
+ if (!(0, _shallowEqual.shallowEqual)(_value2, latestInfo.valueState)) {
124
+ if (_value2 === undefined && defaultValue !== undefined) {
125
+ setValueState(defaultValue);
126
+ } else {
127
+ setValueState(_value2);
128
+ }
129
+ latestInfo.valueState = _value2;
130
+ }
108
131
  }
109
132
  });
110
133
  var validateFiled = (0, _usePersistFn.default)(function (name, v, formV) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AA0BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAyKC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE;8BAVd,MAAM;oCAkED,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCAlFN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;qCA8I5D,MAAM;gCAzCE,MAAM,SAAS,MAAM,UAAU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MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CAiQ9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -293,10 +293,12 @@ var useForm = function useForm(props) {
293
293
  });
294
294
  var handleSubmit = function handleSubmit(other) {
295
295
  return function (e) {
296
- var _other$onSubmit;
297
296
  e.preventDefault();
298
- submit();
299
- other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
297
+ setTimeout(function () {
298
+ var _other$onSubmit;
299
+ submit();
300
+ other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
301
+ }, 10);
300
302
  };
301
303
  };
302
304
  var validateFieldset = function validateFieldset(name) {
@@ -1 +1 @@
1
- {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,UACzB,WAAW,gKAKpB,CAAC"}
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAkGA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,UACzB,WAAW,gKAKpB,CAAC"}
@@ -66,22 +66,23 @@ var getPopoverPosition = function getPopoverPosition(target) {
66
66
  var popupRect = popup === null || popup === void 0 ? void 0 : popup.getBoundingClientRect();
67
67
  if (verticalPoint > windowHeight / 2) position = 'top';else position = 'bottom';
68
68
 
69
+ // TODO: 暂时移除,另考虑方案
69
70
  // 如果渲染了弹出内容,则根据弹出内容宽度计算是否自动调整位置
70
- if (popupRect) {
71
- if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > rect.left) {
72
- position += '-left';
73
- }
74
- if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > windowWidth - rect.right) {
75
- position += '-right';
76
- }
77
- } else {
78
- // 兜底计算
79
- if (horizontalPoint > windowWidth * 0.6) {
80
- position += '-right';
81
- } else if (horizontalPoint < windowWidth * 0.4) {
82
- position += '-left';
83
- }
71
+ // if (popupRect && popupRect?.width) {
72
+ // if (popupRect?.width / 2 > rect.left) {
73
+ // position += '-left';
74
+ // }
75
+ // if (popupRect?.width / 2 > windowWidth - rect.right) {
76
+ // position += '-right';
77
+ // }
78
+ // } else {
79
+ // 兜底计算
80
+ if (horizontalPoint > windowWidth * 0.6) {
81
+ position += '-right';
82
+ } else if (horizontalPoint < windowWidth * 0.4) {
83
+ position += '-left';
84
84
  }
85
+ // }
85
86
  }
86
87
  return position;
87
88
  };
@@ -129,7 +129,7 @@ export var usePositionStyle = function usePositionStyle(config) {
129
129
  }
130
130
  var targetPosition = position;
131
131
  var rootContainer = getContainer() || document.body;
132
- var closestScrollContainer = getClosestScrollContainer(parentElRef.current);
132
+ var closestScrollContainer = absolute ? null : getClosestScrollContainer(parentElRef.current);
133
133
  var containerRect = rootContainer.getBoundingClientRect();
134
134
  var bodyRect = (document.documentElement || document.body).getBoundingClientRect();
135
135
  var containerScrollBarWidth = rootContainer.offsetWidth - rootContainer.clientWidth;
@@ -1 +1 @@
1
- {"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAyB/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBAmHpC,CAAC,YAAY,GAAG,EAAE;;;;;EAiDrD"}
1
+ {"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAyB/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA2IpC,CAAC,YAAY,GAAG,EAAE;;;;;EAiDrD"}
@@ -88,14 +88,37 @@ export default function useFormControl(props) {
88
88
  var errors = arguments.length > 1 ? arguments[1] : undefined;
89
89
  var severErrors = arguments.length > 2 ? arguments[2] : undefined;
90
90
  if (!name) return;
91
- var value = getValue(name, formValue);
92
- var error = getError(name, errors, severErrors);
93
- if (error !== errorState) {
94
- setErrorState(error);
95
- }
96
- if (!shallowEqual(value, latestInfo.valueState)) {
97
- setValueState(value);
98
- latestInfo.valueState = value;
91
+ if (isArray(name)) {
92
+ var _value = getValue(name, formValue);
93
+ var _error = getError(name, errors, severErrors);
94
+ if (_error !== errorState) {
95
+ setErrorState(_error);
96
+ }
97
+ // format defaultValue
98
+ var dv = isArray(defaultValue) ? defaultValue : [];
99
+ var nextValue = [];
100
+ name.forEach(function (n, index) {
101
+ if (_value[index] === undefined && dv[index] !== undefined) {
102
+ nextValue[index] = dv[index];
103
+ } else {
104
+ nextValue[index] = _value[index];
105
+ }
106
+ });
107
+ setValueState(nextValue);
108
+ } else {
109
+ var _value2 = getValue(name, formValue);
110
+ var _error2 = getError(name, errors, severErrors);
111
+ if (_error2 !== errorState) {
112
+ setErrorState(_error2);
113
+ }
114
+ if (!shallowEqual(_value2, latestInfo.valueState)) {
115
+ if (_value2 === undefined && defaultValue !== undefined) {
116
+ setValueState(defaultValue);
117
+ } else {
118
+ setValueState(_value2);
119
+ }
120
+ latestInfo.valueState = _value2;
121
+ }
99
122
  }
100
123
  });
101
124
  var validateFiled = usePersistFn(function (name, v, formV) {
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AA0BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM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,KAAK;gCAKpC,MAAM,SAAS,MAAM;;;;;;oBAnDjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE;0BAVd,MAAM;gCAkED,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCAlFN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;iCAgJ5D,MAAM;4BA3CE,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CAiQ9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -284,10 +284,12 @@ var useForm = function useForm(props) {
284
284
  });
285
285
  var handleSubmit = function handleSubmit(other) {
286
286
  return function (e) {
287
- var _other$onSubmit;
288
287
  e.preventDefault();
289
- submit();
290
- other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
288
+ setTimeout(function () {
289
+ var _other$onSubmit;
290
+ submit();
291
+ other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
292
+ }, 10);
291
293
  };
292
294
  };
293
295
  var validateFieldset = function validateFieldset(name) {
@@ -1 +1 @@
1
- {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,UACzB,WAAW,gKAKpB,CAAC"}
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAkGA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,UACzB,WAAW,gKAKpB,CAAC"}
@@ -60,22 +60,23 @@ var getPopoverPosition = function getPopoverPosition(target) {
60
60
  var popupRect = popup === null || popup === void 0 ? void 0 : popup.getBoundingClientRect();
61
61
  if (verticalPoint > windowHeight / 2) position = 'top';else position = 'bottom';
62
62
 
63
+ // TODO: 暂时移除,另考虑方案
63
64
  // 如果渲染了弹出内容,则根据弹出内容宽度计算是否自动调整位置
64
- if (popupRect) {
65
- if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > rect.left) {
66
- position += '-left';
67
- }
68
- if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > windowWidth - rect.right) {
69
- position += '-right';
70
- }
71
- } else {
72
- // 兜底计算
73
- if (horizontalPoint > windowWidth * 0.6) {
74
- position += '-right';
75
- } else if (horizontalPoint < windowWidth * 0.4) {
76
- position += '-left';
77
- }
65
+ // if (popupRect && popupRect?.width) {
66
+ // if (popupRect?.width / 2 > rect.left) {
67
+ // position += '-left';
68
+ // }
69
+ // if (popupRect?.width / 2 > windowWidth - rect.right) {
70
+ // position += '-right';
71
+ // }
72
+ // } else {
73
+ // 兜底计算
74
+ if (horizontalPoint > windowWidth * 0.6) {
75
+ position += '-right';
76
+ } else if (horizontalPoint < windowWidth * 0.4) {
77
+ position += '-left';
78
78
  }
79
+ // }
79
80
  }
80
81
  return position;
81
82
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.4.4-beta.1",
3
+ "version": "3.4.4-beta.10",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",