@sheinx/hooks 3.7.1-beta.4 → 3.7.1-beta.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAOD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;CAwR3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAUpE,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAOD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;CA4S3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -80,6 +80,20 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
80
80
  var popupElSize = (0, _checkElementSize.useCheckElementSize)(popupElRef, {
81
81
  enable: show
82
82
  });
83
+ var _useState3 = (0, _react.useState)(0),
84
+ _useState4 = _slicedToArray(_useState3, 2),
85
+ popupElWidth = _useState4[0],
86
+ setPopupElWidth = _useState4[1];
87
+ (0, _react.useLayoutEffect)(function () {
88
+ if (!show || !popupElRef.current) return;
89
+ if (popupElRef.current) {
90
+ // 二次打开弹出层时,元素被之前的动画设置了display: none,重新获取元素尺寸时,需要立即设置display: block
91
+ if (popupElRef.current.style.display === 'none') {
92
+ popupElRef.current.style.display = 'block';
93
+ }
94
+ setPopupElWidth(popupElRef.current.getBoundingClientRect().width);
95
+ }
96
+ }, [show, popupElRef.current]);
83
97
  var adjustPosition = function adjustPosition(position) {
84
98
  var winHeight = _utils.docSize.height;
85
99
  if (!verticalPosition.includes(position)) return position;
@@ -106,6 +120,14 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
106
120
  newPosition = newPosition.replace('left', 'right');
107
121
  }
108
122
  }
123
+ } else {
124
+ // absolute 场景下,右侧溢出判断需要考虑弹出层元素的尺寸
125
+ var _position$split = position.split('-'),
126
+ _position$split2 = _slicedToArray(_position$split, 2),
127
+ _horizontalPosition = _position$split2[1];
128
+ if (_horizontalPosition === 'left' && context.parentRect.left + (popupElWidth || context.popUpWidth) > _utils.docSize.width) {
129
+ newPosition = newPosition.replace('left', 'right');
130
+ }
109
131
  }
110
132
  return newPosition;
111
133
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AA+BA,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;;;;;;;;;wBAgSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApKnB,MAAM;oCA+OD,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MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAjJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BArPnB,MAAM;gCAgUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA3RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA8VvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAjJpD,MAAM,0BAAyB,qBAAqB;;CAqb9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -73,85 +73,6 @@ var useForm = function useForm(props) {
73
73
  removeLock: false
74
74
  }),
75
75
  context = _React$useRef.current;
76
- var update = function update(name) {
77
- var _context$flowMap$glob;
78
- if (!name) {
79
- Object.keys(context.updateMap).forEach(function (key) {
80
- var _context$updateMap$ke;
81
- (_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
82
- update(context.value, context.errors, context.serverErrors);
83
- });
84
- });
85
- Object.keys(context.flowMap).forEach(function (key) {
86
- context.flowMap[key].forEach(function (update) {
87
- update();
88
- });
89
- });
90
- } else {
91
- var names = (0, _utils.isArray)(name) ? name : [name];
92
- names.forEach(function (key) {
93
- var _context$flowMap$key;
94
- // 外部直接设置user.name这种格式的,但是又没有显性的声明user.name绑定的表单元素;
95
- // 这里需要手动触发,否则会导致Input输入过程中光标跳到末尾的异常
96
- if (!context.updateMap[key]) {
97
- var _context$updateMap$pa;
98
- var parentKey = key.split('.')[0];
99
- (_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
100
- update(context.value, context.errors, context.serverErrors);
101
- });
102
- } else {
103
- var _context$updateMap$ke2;
104
- (_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
105
- update(context.value, context.errors, context.serverErrors);
106
- });
107
- }
108
- (_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
109
- update();
110
- });
111
- });
112
- }
113
- (_context$flowMap$glob = context.flowMap[globalKey]) === null || _context$flowMap$glob === void 0 || _context$flowMap$glob.forEach(function (update) {
114
- update();
115
- });
116
- };
117
- var updateFieldsets = (0, _usePersistFn.default)(function (name) {
118
- var na = "".concat(name, "[");
119
- var no = "".concat(name, ".");
120
- context.names.forEach(function (key) {
121
- if (key.startsWith(na) || key.startsWith(no)) {
122
- update(key);
123
- }
124
- });
125
- });
126
- var handleSubmitError = function handleSubmitError(err) {
127
- onError === null || onError === void 0 || onError(err);
128
- if (!props.scrollToError) return;
129
- setTimeout(function () {
130
- var _props$formElRef$curr;
131
- var selector = "[".concat((0, _attribute.getDataAttributeName)('status'), "=\"error\"]");
132
- var el = (_props$formElRef$curr = props.formElRef.current) === null || _props$formElRef$curr === void 0 ? void 0 : _props$formElRef$curr.querySelector(selector);
133
- if (el) {
134
- el.scrollIntoView();
135
- var focusableSelectors = 'textarea, input,[tabindex]:not([tabindex="-1"])';
136
- var focusEl = el.querySelector(focusableSelectors);
137
- if (focusEl && focusEl.focus) focusEl.focus();
138
- }
139
- if (typeof scrollToError === 'number' && scrollToError !== 0) {
140
- var scrollEl = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent();
141
- if (scrollEl) {
142
- scrollEl.scrollTop -= scrollToError;
143
- } else {
144
- _utils.docScroll.top -= scrollToError;
145
- }
146
- }
147
- });
148
- };
149
- var onChange = (0, _usePersistFn.default)(function (change) {
150
- var _props$onChange;
151
- var newValue = typeof change === 'function' ? (0, _immer.produce)(context.value, change) : change;
152
- context.value = newValue;
153
- (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, context.value);
154
- });
155
76
  var getValue = (0, _usePersistFn.default)(function (name) {
156
77
  if (name) {
157
78
  return (0, _utils.deepGet)(context.value, name);
@@ -234,6 +155,88 @@ var useForm = function useForm(props) {
234
155
  }
235
156
  });
236
157
  });
158
+ var update = function update(name) {
159
+ var _context$flowMap$glob;
160
+ if (!name) {
161
+ Object.keys(context.updateMap).forEach(function (key) {
162
+ var _context$updateMap$ke;
163
+ (_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
164
+ update(context.value, context.errors, context.serverErrors);
165
+ if (context.errors[key]) {
166
+ validateFields(key).catch(function () {});
167
+ }
168
+ });
169
+ });
170
+ Object.keys(context.flowMap).forEach(function (key) {
171
+ context.flowMap[key].forEach(function (update) {
172
+ update();
173
+ });
174
+ });
175
+ } else {
176
+ var names = (0, _utils.isArray)(name) ? name : [name];
177
+ names.forEach(function (key) {
178
+ var _context$flowMap$key;
179
+ // 外部直接设置user.name这种格式的,但是又没有显性的声明user.name绑定的表单元素;
180
+ // 这里需要手动触发,否则会导致Input输入过程中光标跳到末尾的异常
181
+ if (!context.updateMap[key]) {
182
+ var _context$updateMap$pa;
183
+ var parentKey = key.split('.')[0];
184
+ (_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
185
+ update(context.value, context.errors, context.serverErrors);
186
+ });
187
+ } else {
188
+ var _context$updateMap$ke2;
189
+ (_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
190
+ update(context.value, context.errors, context.serverErrors);
191
+ });
192
+ }
193
+ (_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
194
+ update();
195
+ });
196
+ });
197
+ }
198
+ (_context$flowMap$glob = context.flowMap[globalKey]) === null || _context$flowMap$glob === void 0 || _context$flowMap$glob.forEach(function (update) {
199
+ update();
200
+ });
201
+ };
202
+ var updateFieldsets = (0, _usePersistFn.default)(function (name) {
203
+ var na = "".concat(name, "[");
204
+ var no = "".concat(name, ".");
205
+ context.names.forEach(function (key) {
206
+ if (key.startsWith(na) || key.startsWith(no)) {
207
+ update(key);
208
+ }
209
+ });
210
+ });
211
+ var handleSubmitError = function handleSubmitError(err) {
212
+ onError === null || onError === void 0 || onError(err);
213
+ if (!props.scrollToError) return;
214
+ setTimeout(function () {
215
+ var _props$formElRef$curr;
216
+ var selector = "[".concat((0, _attribute.getDataAttributeName)('status'), "=\"error\"]");
217
+ var el = (_props$formElRef$curr = props.formElRef.current) === null || _props$formElRef$curr === void 0 ? void 0 : _props$formElRef$curr.querySelector(selector);
218
+ if (el) {
219
+ el.scrollIntoView();
220
+ var focusableSelectors = 'textarea, input,[tabindex]:not([tabindex="-1"])';
221
+ var focusEl = el.querySelector(focusableSelectors);
222
+ if (focusEl && focusEl.focus) focusEl.focus();
223
+ }
224
+ if (typeof scrollToError === 'number' && scrollToError !== 0) {
225
+ var scrollEl = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent();
226
+ if (scrollEl) {
227
+ scrollEl.scrollTop -= scrollToError;
228
+ } else {
229
+ _utils.docScroll.top -= scrollToError;
230
+ }
231
+ }
232
+ });
233
+ };
234
+ var onChange = (0, _usePersistFn.default)(function (change) {
235
+ var _props$onChange;
236
+ var newValue = typeof change === 'function' ? (0, _immer.produce)(context.value, change) : change;
237
+ context.value = newValue;
238
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, context.value);
239
+ });
237
240
  var scrollToField = (0, _usePersistFn.default)(function (name) {
238
241
  var _document;
239
242
  var scrollIntoViewOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CA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AAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAOD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;CA4S3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -5,7 +5,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
5
5
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
- import React, { useEffect, useState } from 'react';
8
+ import React, { useEffect, useLayoutEffect, useState } from 'react';
9
9
  import { getPositionStyle } from "./get-position-style";
10
10
  import { useCheckElementPosition } from "./check-position";
11
11
  import { useCheckElementBorderWidth } from "./check-border";
@@ -71,6 +71,20 @@ export var usePositionStyle = function usePositionStyle(config) {
71
71
  var popupElSize = useCheckElementSize(popupElRef, {
72
72
  enable: show
73
73
  });
74
+ var _useState3 = useState(0),
75
+ _useState4 = _slicedToArray(_useState3, 2),
76
+ popupElWidth = _useState4[0],
77
+ setPopupElWidth = _useState4[1];
78
+ useLayoutEffect(function () {
79
+ if (!show || !popupElRef.current) return;
80
+ if (popupElRef.current) {
81
+ // 二次打开弹出层时,元素被之前的动画设置了display: none,重新获取元素尺寸时,需要立即设置display: block
82
+ if (popupElRef.current.style.display === 'none') {
83
+ popupElRef.current.style.display = 'block';
84
+ }
85
+ setPopupElWidth(popupElRef.current.getBoundingClientRect().width);
86
+ }
87
+ }, [show, popupElRef.current]);
74
88
  var adjustPosition = function adjustPosition(position) {
75
89
  var winHeight = docSize.height;
76
90
  if (!verticalPosition.includes(position)) return position;
@@ -97,6 +111,14 @@ export var usePositionStyle = function usePositionStyle(config) {
97
111
  newPosition = newPosition.replace('left', 'right');
98
112
  }
99
113
  }
114
+ } else {
115
+ // absolute 场景下,右侧溢出判断需要考虑弹出层元素的尺寸
116
+ var _position$split = position.split('-'),
117
+ _position$split2 = _slicedToArray(_position$split, 2),
118
+ _horizontalPosition = _position$split2[1];
119
+ if (_horizontalPosition === 'left' && context.parentRect.left + (popupElWidth || context.popUpWidth) > docSize.width) {
120
+ newPosition = newPosition.replace('left', 'right');
121
+ }
100
122
  }
101
123
  return newPosition;
102
124
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AA+BA,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;;;;;;;;;wBAgSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BApKnB,MAAM;oCA+OD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA1MxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCA6QvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAjJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BApKnB,MAAM;gCA+OD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA1MxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA6QvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAjJpD,MAAM,0BAAyB,qBAAqB;;CAqb9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AA+BA,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;;;;;;;;;wBAoSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BArPnB,MAAM;oCAgUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA3RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCA8VvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAjJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BArPnB,MAAM;gCAgUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA3RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA8VvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAjJpD,MAAM,0BAAyB,qBAAqB;;CAqb9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -64,85 +64,6 @@ var useForm = function useForm(props) {
64
64
  removeLock: false
65
65
  }),
66
66
  context = _React$useRef.current;
67
- var update = function update(name) {
68
- var _context$flowMap$glob;
69
- if (!name) {
70
- Object.keys(context.updateMap).forEach(function (key) {
71
- var _context$updateMap$ke;
72
- (_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
73
- update(context.value, context.errors, context.serverErrors);
74
- });
75
- });
76
- Object.keys(context.flowMap).forEach(function (key) {
77
- context.flowMap[key].forEach(function (update) {
78
- update();
79
- });
80
- });
81
- } else {
82
- var names = isArray(name) ? name : [name];
83
- names.forEach(function (key) {
84
- var _context$flowMap$key;
85
- // 外部直接设置user.name这种格式的,但是又没有显性的声明user.name绑定的表单元素;
86
- // 这里需要手动触发,否则会导致Input输入过程中光标跳到末尾的异常
87
- if (!context.updateMap[key]) {
88
- var _context$updateMap$pa;
89
- var parentKey = key.split('.')[0];
90
- (_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
91
- update(context.value, context.errors, context.serverErrors);
92
- });
93
- } else {
94
- var _context$updateMap$ke2;
95
- (_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
96
- update(context.value, context.errors, context.serverErrors);
97
- });
98
- }
99
- (_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
100
- update();
101
- });
102
- });
103
- }
104
- (_context$flowMap$glob = context.flowMap[globalKey]) === null || _context$flowMap$glob === void 0 || _context$flowMap$glob.forEach(function (update) {
105
- update();
106
- });
107
- };
108
- var updateFieldsets = usePersistFn(function (name) {
109
- var na = "".concat(name, "[");
110
- var no = "".concat(name, ".");
111
- context.names.forEach(function (key) {
112
- if (key.startsWith(na) || key.startsWith(no)) {
113
- update(key);
114
- }
115
- });
116
- });
117
- var handleSubmitError = function handleSubmitError(err) {
118
- onError === null || onError === void 0 || onError(err);
119
- if (!props.scrollToError) return;
120
- setTimeout(function () {
121
- var _props$formElRef$curr;
122
- var selector = "[".concat(getDataAttributeName('status'), "=\"error\"]");
123
- var el = (_props$formElRef$curr = props.formElRef.current) === null || _props$formElRef$curr === void 0 ? void 0 : _props$formElRef$curr.querySelector(selector);
124
- if (el) {
125
- el.scrollIntoView();
126
- var focusableSelectors = 'textarea, input,[tabindex]:not([tabindex="-1"])';
127
- var focusEl = el.querySelector(focusableSelectors);
128
- if (focusEl && focusEl.focus) focusEl.focus();
129
- }
130
- if (typeof scrollToError === 'number' && scrollToError !== 0) {
131
- var scrollEl = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent();
132
- if (scrollEl) {
133
- scrollEl.scrollTop -= scrollToError;
134
- } else {
135
- docScroll.top -= scrollToError;
136
- }
137
- }
138
- });
139
- };
140
- var onChange = usePersistFn(function (change) {
141
- var _props$onChange;
142
- var newValue = typeof change === 'function' ? produce(context.value, change) : change;
143
- context.value = newValue;
144
- (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, context.value);
145
- });
146
67
  var getValue = usePersistFn(function (name) {
147
68
  if (name) {
148
69
  return deepGet(context.value, name);
@@ -225,6 +146,88 @@ var useForm = function useForm(props) {
225
146
  }
226
147
  });
227
148
  });
149
+ var update = function update(name) {
150
+ var _context$flowMap$glob;
151
+ if (!name) {
152
+ Object.keys(context.updateMap).forEach(function (key) {
153
+ var _context$updateMap$ke;
154
+ (_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
155
+ update(context.value, context.errors, context.serverErrors);
156
+ if (context.errors[key]) {
157
+ validateFields(key).catch(function () {});
158
+ }
159
+ });
160
+ });
161
+ Object.keys(context.flowMap).forEach(function (key) {
162
+ context.flowMap[key].forEach(function (update) {
163
+ update();
164
+ });
165
+ });
166
+ } else {
167
+ var names = isArray(name) ? name : [name];
168
+ names.forEach(function (key) {
169
+ var _context$flowMap$key;
170
+ // 外部直接设置user.name这种格式的,但是又没有显性的声明user.name绑定的表单元素;
171
+ // 这里需要手动触发,否则会导致Input输入过程中光标跳到末尾的异常
172
+ if (!context.updateMap[key]) {
173
+ var _context$updateMap$pa;
174
+ var parentKey = key.split('.')[0];
175
+ (_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
176
+ update(context.value, context.errors, context.serverErrors);
177
+ });
178
+ } else {
179
+ var _context$updateMap$ke2;
180
+ (_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
181
+ update(context.value, context.errors, context.serverErrors);
182
+ });
183
+ }
184
+ (_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
185
+ update();
186
+ });
187
+ });
188
+ }
189
+ (_context$flowMap$glob = context.flowMap[globalKey]) === null || _context$flowMap$glob === void 0 || _context$flowMap$glob.forEach(function (update) {
190
+ update();
191
+ });
192
+ };
193
+ var updateFieldsets = usePersistFn(function (name) {
194
+ var na = "".concat(name, "[");
195
+ var no = "".concat(name, ".");
196
+ context.names.forEach(function (key) {
197
+ if (key.startsWith(na) || key.startsWith(no)) {
198
+ update(key);
199
+ }
200
+ });
201
+ });
202
+ var handleSubmitError = function handleSubmitError(err) {
203
+ onError === null || onError === void 0 || onError(err);
204
+ if (!props.scrollToError) return;
205
+ setTimeout(function () {
206
+ var _props$formElRef$curr;
207
+ var selector = "[".concat(getDataAttributeName('status'), "=\"error\"]");
208
+ var el = (_props$formElRef$curr = props.formElRef.current) === null || _props$formElRef$curr === void 0 ? void 0 : _props$formElRef$curr.querySelector(selector);
209
+ if (el) {
210
+ el.scrollIntoView();
211
+ var focusableSelectors = 'textarea, input,[tabindex]:not([tabindex="-1"])';
212
+ var focusEl = el.querySelector(focusableSelectors);
213
+ if (focusEl && focusEl.focus) focusEl.focus();
214
+ }
215
+ if (typeof scrollToError === 'number' && scrollToError !== 0) {
216
+ var scrollEl = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent();
217
+ if (scrollEl) {
218
+ scrollEl.scrollTop -= scrollToError;
219
+ } else {
220
+ docScroll.top -= scrollToError;
221
+ }
222
+ }
223
+ });
224
+ };
225
+ var onChange = usePersistFn(function (change) {
226
+ var _props$onChange;
227
+ var newValue = typeof change === 'function' ? produce(context.value, change) : change;
228
+ context.value = newValue;
229
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, context.value);
230
+ });
228
231
  var scrollToField = usePersistFn(function (name) {
229
232
  var _document;
230
233
  var scrollIntoViewOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.7.1-beta.4",
3
+ "version": "3.7.1-beta.6",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",