@sheinx/hooks 3.7.0-beta.9 → 3.7.0-fix.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.
Files changed (151) hide show
  1. package/cjs/common/use-component-memo/index.d.ts +1 -1
  2. package/cjs/common/use-component-memo/index.d.ts.map +1 -1
  3. package/cjs/common/use-component-memo/index.js +2 -9
  4. package/cjs/common/use-component-memo/use-memo.d.ts +1 -1
  5. package/cjs/common/use-component-memo/use-memo.d.ts.map +1 -1
  6. package/cjs/common/use-component-memo/use-memo.js +2 -2
  7. package/cjs/common/use-filter/index.d.ts +1 -0
  8. package/cjs/common/use-filter/index.d.ts.map +1 -1
  9. package/cjs/common/use-filter/index.js +7 -0
  10. package/cjs/common/use-filter/use-filter-context.d.ts +7 -0
  11. package/cjs/common/use-filter/use-filter-context.d.ts.map +1 -0
  12. package/cjs/common/use-filter/use-filter-context.js +10 -0
  13. package/cjs/common/use-filter/use-filter.d.ts +1 -0
  14. package/cjs/common/use-filter/use-filter.d.ts.map +1 -1
  15. package/cjs/common/use-filter/use-filter.js +2 -0
  16. package/cjs/common/use-input-able/use-Input-able.d.ts.map +1 -1
  17. package/cjs/common/use-input-able/use-Input-able.js +6 -7
  18. package/cjs/common/use-position-style/check-element-size.d.ts +10 -0
  19. package/cjs/common/use-position-style/check-element-size.d.ts.map +1 -0
  20. package/cjs/common/use-position-style/check-element-size.js +65 -0
  21. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  22. package/cjs/common/use-position-style/index.js +5 -1
  23. package/cjs/components/use-datepicker/index.d.ts +1 -1
  24. package/cjs/components/use-datepicker/index.d.ts.map +1 -1
  25. package/cjs/components/use-datepicker/index.js +23 -2
  26. package/cjs/components/use-datepicker/use-datepicker-format.d.ts +17 -0
  27. package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  28. package/cjs/components/use-datepicker/use-datepicker-format.js +15 -3
  29. package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  30. package/cjs/components/use-form/use-form-control/use-form-control.js +9 -4
  31. package/cjs/components/use-form/use-form.d.ts +4 -4
  32. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  33. package/cjs/components/use-form/use-form.js +31 -25
  34. package/cjs/components/use-form/use-form.type.d.ts +8 -0
  35. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  36. package/cjs/components/use-image/use-image.d.ts +2 -0
  37. package/cjs/components/use-image/use-image.d.ts.map +1 -1
  38. package/cjs/components/use-image/use-image.js +40 -2
  39. package/cjs/components/use-popup/popup-context.d.ts +2 -0
  40. package/cjs/components/use-popup/popup-context.d.ts.map +1 -1
  41. package/cjs/components/use-popup/popup-context.js +2 -0
  42. package/cjs/components/use-popup/use-popup.d.ts +4 -0
  43. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  44. package/cjs/components/use-popup/use-popup.js +33 -13
  45. package/cjs/components/use-table/index.d.ts +1 -1
  46. package/cjs/components/use-table/index.d.ts.map +1 -1
  47. package/cjs/components/use-table/use-table-filter.d.ts.map +1 -1
  48. package/cjs/components/use-table/use-table-filter.js +2 -1
  49. package/cjs/components/use-table/use-table-group.d.ts.map +1 -1
  50. package/cjs/components/use-table/use-table-group.js +3 -1
  51. package/cjs/components/use-table/use-table-layout.d.ts.map +1 -1
  52. package/cjs/components/use-table/use-table-layout.js +0 -1
  53. package/cjs/components/use-table/use-table-virtual.js +1 -1
  54. package/cjs/components/use-table/use-table.type.d.ts +13 -21
  55. package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
  56. package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
  57. package/cjs/components/use-tree/use-tree.js +25 -7
  58. package/cjs/components/use-tree/use-tree.type.d.ts +1 -0
  59. package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
  60. package/cjs/components/use-upload/use-upload.d.ts.map +1 -1
  61. package/cjs/components/use-upload/use-upload.js +54 -34
  62. package/cjs/components/use-upload/use-upload.type.d.ts +7 -0
  63. package/cjs/components/use-upload/use-upload.type.d.ts.map +1 -1
  64. package/cjs/utils/clean-props.d.ts +11 -0
  65. package/cjs/utils/clean-props.d.ts.map +1 -0
  66. package/cjs/utils/clean-props.js +21 -0
  67. package/cjs/utils/highlight.d.ts +7 -0
  68. package/cjs/utils/highlight.d.ts.map +1 -0
  69. package/cjs/utils/highlight.js +67 -0
  70. package/cjs/utils/index.d.ts +2 -0
  71. package/cjs/utils/index.d.ts.map +1 -1
  72. package/cjs/utils/index.js +24 -0
  73. package/cjs/utils/string.d.ts +1 -0
  74. package/cjs/utils/string.d.ts.map +1 -1
  75. package/cjs/utils/string.js +13 -0
  76. package/esm/common/use-component-memo/index.d.ts +1 -1
  77. package/esm/common/use-component-memo/index.d.ts.map +1 -1
  78. package/esm/common/use-component-memo/index.js +1 -1
  79. package/esm/common/use-component-memo/use-memo.d.ts +1 -1
  80. package/esm/common/use-component-memo/use-memo.d.ts.map +1 -1
  81. package/esm/common/use-component-memo/use-memo.js +1 -1
  82. package/esm/common/use-filter/index.d.ts +1 -0
  83. package/esm/common/use-filter/index.d.ts.map +1 -1
  84. package/esm/common/use-filter/index.js +2 -1
  85. package/esm/common/use-filter/use-filter-context.d.ts +7 -0
  86. package/esm/common/use-filter/use-filter-context.d.ts.map +1 -0
  87. package/esm/common/use-filter/use-filter-context.js +3 -0
  88. package/esm/common/use-filter/use-filter.d.ts +1 -0
  89. package/esm/common/use-filter/use-filter.d.ts.map +1 -1
  90. package/esm/common/use-filter/use-filter.js +2 -0
  91. package/esm/common/use-input-able/use-Input-able.d.ts.map +1 -1
  92. package/esm/common/use-input-able/use-Input-able.js +7 -8
  93. package/esm/common/use-position-style/check-element-size.d.ts +10 -0
  94. package/esm/common/use-position-style/check-element-size.d.ts.map +1 -0
  95. package/esm/common/use-position-style/check-element-size.js +59 -0
  96. package/esm/common/use-position-style/index.d.ts.map +1 -1
  97. package/esm/common/use-position-style/index.js +5 -1
  98. package/esm/components/use-datepicker/index.d.ts +1 -1
  99. package/esm/components/use-datepicker/index.d.ts.map +1 -1
  100. package/esm/components/use-datepicker/index.js +1 -1
  101. package/esm/components/use-datepicker/use-datepicker-format.d.ts +17 -0
  102. package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  103. package/esm/components/use-datepicker/use-datepicker-format.js +14 -2
  104. package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  105. package/esm/components/use-form/use-form-control/use-form-control.js +9 -4
  106. package/esm/components/use-form/use-form.d.ts +4 -4
  107. package/esm/components/use-form/use-form.d.ts.map +1 -1
  108. package/esm/components/use-form/use-form.js +31 -25
  109. package/esm/components/use-form/use-form.type.d.ts +8 -0
  110. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  111. package/esm/components/use-image/use-image.d.ts +2 -0
  112. package/esm/components/use-image/use-image.d.ts.map +1 -1
  113. package/esm/components/use-image/use-image.js +40 -2
  114. package/esm/components/use-popup/popup-context.d.ts +2 -0
  115. package/esm/components/use-popup/popup-context.d.ts.map +1 -1
  116. package/esm/components/use-popup/popup-context.js +2 -0
  117. package/esm/components/use-popup/use-popup.d.ts +4 -0
  118. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  119. package/esm/components/use-popup/use-popup.js +34 -14
  120. package/esm/components/use-table/index.d.ts +1 -1
  121. package/esm/components/use-table/index.d.ts.map +1 -1
  122. package/esm/components/use-table/use-table-filter.d.ts.map +1 -1
  123. package/esm/components/use-table/use-table-filter.js +2 -1
  124. package/esm/components/use-table/use-table-group.d.ts.map +1 -1
  125. package/esm/components/use-table/use-table-group.js +3 -1
  126. package/esm/components/use-table/use-table-layout.d.ts.map +1 -1
  127. package/esm/components/use-table/use-table-layout.js +0 -1
  128. package/esm/components/use-table/use-table-virtual.js +1 -1
  129. package/esm/components/use-table/use-table.type.d.ts +13 -21
  130. package/esm/components/use-table/use-table.type.d.ts.map +1 -1
  131. package/esm/components/use-tree/use-tree.d.ts.map +1 -1
  132. package/esm/components/use-tree/use-tree.js +26 -8
  133. package/esm/components/use-tree/use-tree.type.d.ts +1 -0
  134. package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
  135. package/esm/components/use-upload/use-upload.d.ts.map +1 -1
  136. package/esm/components/use-upload/use-upload.js +54 -34
  137. package/esm/components/use-upload/use-upload.type.d.ts +7 -0
  138. package/esm/components/use-upload/use-upload.type.d.ts.map +1 -1
  139. package/esm/utils/clean-props.d.ts +11 -0
  140. package/esm/utils/clean-props.d.ts.map +1 -0
  141. package/esm/utils/clean-props.js +15 -0
  142. package/esm/utils/highlight.d.ts +7 -0
  143. package/esm/utils/highlight.d.ts.map +1 -0
  144. package/esm/utils/highlight.js +59 -0
  145. package/esm/utils/index.d.ts +2 -0
  146. package/esm/utils/index.d.ts.map +1 -1
  147. package/esm/utils/index.js +3 -1
  148. package/esm/utils/string.d.ts +1 -0
  149. package/esm/utils/string.d.ts.map +1 -1
  150. package/esm/utils/string.js +12 -0
  151. package/package.json +1 -1
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  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; }
5
5
  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; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
- import { useEffect, useRef, useState } from 'react';
7
+ import { useLayoutEffect, useRef, useState } from 'react';
8
8
  import { isFunc } from "../../utils/is";
9
9
  import { shallowEqual } from "../../utils/shallow-equal";
10
10
  import usePersistFn from "../use-persist-fn";
@@ -39,19 +39,18 @@ export default function useInputAble(props) {
39
39
  var render = useRender(syncValue);
40
40
  var shouldUseState = delay || !control;
41
41
  var value = shouldUseState ? stateValue : valuePo;
42
- useEffect(function () {
43
- if (context.timer) {
44
- clearTimeout(context.timer);
45
- context.timer = null;
46
- }
42
+ useLayoutEffect(function () {
47
43
  if (delay && control && props.value !== stateValue) {
48
44
  changeStateValue(props.value);
45
+ } else if (context.timer) {
46
+ clearTimeout(context.timer);
47
+ context.timer = null;
49
48
  }
50
49
  }, [props.value, delay, control]);
51
50
  var forceDelayChange = usePersistFn(function () {
52
- if (context.timer && context.delayChange) {
51
+ if (context.delayChange) context.delayChange();
52
+ if (context.timer) {
53
53
  clearTimeout(context.timer);
54
- context.delayChange();
55
54
  context.timer = null;
56
55
  context.delayChange = null;
57
56
  }
@@ -0,0 +1,10 @@
1
+ export interface Size {
2
+ width?: number;
3
+ height?: number;
4
+ }
5
+ interface UseCheckElementSizeOptions {
6
+ enable?: boolean;
7
+ }
8
+ export declare const useCheckElementSize: (targetElementRef: React.RefObject<HTMLElement>, options?: UseCheckElementSizeOptions) => Size | null;
9
+ export {};
10
+ //# sourceMappingURL=check-element-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-element-size.d.ts","sourceRoot":"","sources":["check-element-size.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,IAAI;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,0BAA0B;IAElC,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,eAAO,MAAM,mBAAmB,qBACZ,MAAM,SAAS,CAAC,WAAW,CAAC,YACrC,0BAA0B,KAClC,IAAI,GAAG,IAmDT,CAAC"}
@@ -0,0 +1,59 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useState, useEffect, useRef, useCallback } from 'react';
8
+ export var useCheckElementSize = function useCheckElementSize(targetElementRef) {
9
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
10
+ var enable = options.enable;
11
+ var _useState = useState({
12
+ width: 0,
13
+ height: 0
14
+ }),
15
+ _useState2 = _slicedToArray(_useState, 2),
16
+ size = _useState2[0],
17
+ setSize = _useState2[1];
18
+ var lastSize = useRef({
19
+ width: 0,
20
+ height: 0
21
+ });
22
+ var checkSize = useCallback(function () {
23
+ if (targetElementRef.current) {
24
+ var rect = targetElementRef.current.getBoundingClientRect();
25
+ var newSize = {
26
+ width: rect.width,
27
+ height: rect.height
28
+ };
29
+ if (newSize.width !== lastSize.current.width || newSize.height !== lastSize.current.height) {
30
+ setSize(newSize);
31
+ lastSize.current = newSize;
32
+ }
33
+ }
34
+ }, [targetElementRef]);
35
+ useEffect(function () {
36
+ var _window;
37
+ if (!enable) return;
38
+ var element = targetElementRef.current;
39
+ if (!element) return;
40
+
41
+ // 初始检查
42
+ checkSize();
43
+ var resizeObserver = null;
44
+ if ((_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
45
+ resizeObserver = new ResizeObserver(checkSize);
46
+ resizeObserver.observe(element);
47
+ }
48
+
49
+ // 清理函数
50
+ return function () {
51
+ var _resizeObserver;
52
+ (_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 || _resizeObserver.disconnect();
53
+ };
54
+ }, [enable, targetElementRef, checkSize]);
55
+ if (!enable || !targetElementRef) {
56
+ return null;
57
+ }
58
+ return size;
59
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AASnD,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,CAA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AAC;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"}
@@ -9,6 +9,7 @@ import React, { useEffect, 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";
12
+ import { useCheckElementSize } from "./check-element-size";
12
13
  import shallowEqual from "../../utils/shallow-equal";
13
14
  import usePersistFn from "../use-persist-fn";
14
15
  import { getCurrentCSSZoom } from "../../utils";
@@ -67,6 +68,9 @@ export var usePositionStyle = function usePositionStyle(config) {
67
68
  var parentElBorderWidth = useCheckElementBorderWidth(parentElRef, {
68
69
  direction: 'horizontal'
69
70
  });
71
+ var popupElSize = useCheckElementSize(popupElRef, {
72
+ enable: show
73
+ });
70
74
  var adjustPosition = function adjustPosition(position) {
71
75
  var winHeight = docSize.height;
72
76
  if (!verticalPosition.includes(position)) return position;
@@ -303,7 +307,7 @@ export var usePositionStyle = function usePositionStyle(config) {
303
307
  // 当父元素的滚动容器滚动时,判断是否需要更新弹出层位置,包括是否隐藏弹出层(通过hideStyle隐藏,不是show状态)
304
308
  context.prevParentPosition = parentElNewPosition;
305
309
  });
306
- useEffect(updateStyle, [show, position, absolute, updateKey, fixedWidth, parentElNewPosition]);
310
+ useEffect(updateStyle, [show, position, absolute, updateKey, fixedWidth, parentElNewPosition, popupElSize]);
307
311
  return {
308
312
  style: style
309
313
  };
@@ -1,4 +1,4 @@
1
- export { default as useDatePickerFormat } from './use-datepicker-format';
1
+ export { default as useDatePickerFormat, getFormatValueArr, convertValueToDateArr, getFormat, } from './use-datepicker-format';
2
2
  export { default as dateUtil } from './util';
3
3
  export { default as useDatePick } from './use-date';
4
4
  export { default as useYearPick } from './use-year';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACvE,YAAY,EACV,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,mBAAmB,EAC9B,iBAAiB,EACjB,qBAAqB,EACrB,SAAS,GACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACvE,YAAY,EACV,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,8BAA8B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- export { default as useDatePickerFormat } from "./use-datepicker-format";
2
+ export { default as useDatePickerFormat, getFormatValueArr, convertValueToDateArr, getFormat } from "./use-datepicker-format";
3
3
  export { default as dateUtil } from "./util";
4
4
  export { default as useDatePick } from "./use-date";
5
5
  export { default as useYearPick } from "./use-year";
@@ -1,5 +1,22 @@
1
1
  import React from 'react';
2
2
  import type { DatePickerModeType, DatePickerValueType, UseDatePickerFormatProps } from './use-datepicker-format.type';
3
+ export declare const convertValueToDateArr: (value: DatePickerValueType, format: string, options: {
4
+ timeZone?: string;
5
+ weekStartsOn?: number;
6
+ }) => (Date | undefined)[];
7
+ export declare const getFormat: (format: string | undefined, type: string) => string;
8
+ interface FormatValueType {
9
+ dateArr: (Date | undefined)[];
10
+ format: string;
11
+ fmt?: string;
12
+ type: 'date' | 'datetime' | 'month' | 'time' | 'week' | 'year' | 'quarter';
13
+ clearWithUndefined?: boolean;
14
+ options: {
15
+ timeZone?: string;
16
+ weekStartsOn?: number;
17
+ };
18
+ }
19
+ export declare const getFormatValueArr: (opts: FormatValueType) => (string | undefined)[];
3
20
  declare const useDatePickerFormat: <Value extends DatePickerValueType>(props: UseDatePickerFormatProps<Value>) => {
4
21
  inputArr: (Date | undefined)[];
5
22
  resultArr: (string | undefined)[];
@@ -1 +1 @@
1
- {"version":3,"file":"use-datepicker-format.d.ts","sourceRoot":"","sources":["use-datepicker-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EACV,kBAAkB,EAClB,mBA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CAAC;KACvB,CAAC;CACH;AAED,eAAO,MAAM,iBAAiB,SAAU,eAAe,2BAOtD,CAAC;AAEF,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;0BA6Me,gBAAgB;sCAiEJ,MAAM;iCA7BX,MAAM,SAAS,MAAM;yCA9LrD,OAAO,GAAG,KAAK,GAAG,SAAS,QAAQ,MAAM,UAAU,IAAI,KAAK,OAAO;uCAWvE,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,QAC3B,MAAM;kBACG,MAAM,SAAS;mBAAS,GAAG;;+BA4CrC,IAAI,YAAY,OAAO,GAAG,KAAK,GAAG,SAAS,gBAAgB,MAAM;;CA8N3E,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -13,14 +13,14 @@ import dateUtil from "./util";
13
13
  import shallowEqual from "../../utils/shallow-equal";
14
14
  import { usePersistFn } from "../../common/use-persist-fn";
15
15
  import useLatestObj from "../../common/use-latest-obj";
16
- var convertValueToDateArr = function convertValueToDateArr(value, format, options) {
16
+ export var convertValueToDateArr = function convertValueToDateArr(value, format, options) {
17
17
  var valueArr = Array.isArray(value) ? value : [value];
18
18
  return valueArr.map(function (item) {
19
19
  if (!item) return undefined;
20
20
  return dateUtil.toDateWithFormat(item, format, undefined, options);
21
21
  });
22
22
  };
23
- var getFormat = function getFormat(format, type) {
23
+ export var getFormat = function getFormat(format, type) {
24
24
  if (typeof format === 'string') return format;
25
25
  switch (type) {
26
26
  case 'datetime':
@@ -63,6 +63,18 @@ var getDefaultMode = function getDefaultMode(type) {
63
63
  var mode = getTypeMode(type);
64
64
  return [mode, mode];
65
65
  };
66
+ export var getFormatValueArr = function getFormatValueArr(opts) {
67
+ var dateArr = opts.dateArr,
68
+ format = opts.format,
69
+ clearWithUndefined = opts.clearWithUndefined,
70
+ options = opts.options,
71
+ type = opts.type;
72
+ var fmt = getFormat(format, type);
73
+ return dateArr.map(function (item) {
74
+ if (!item) return clearWithUndefined ? undefined : '';
75
+ return dateUtil.format(item, fmt, options);
76
+ });
77
+ };
66
78
  var useDatePickerFormat = function useDatePickerFormat(props) {
67
79
  var value = props.value,
68
80
  onChange = props.onChange,
@@ -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;AA2BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBAiJpC,CAAC,YAAY,GAAG,EAAE;;;;;EAwDrD"}
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;;kBAiJpC,CAAC,YAAY,GAAG,EAAE;;;;;EA4DrD"}
@@ -20,6 +20,7 @@ import { shallowEqual } from "../../../utils/shallow-equal";
20
20
  import usePersistFn from "../../../common/use-persist-fn";
21
21
  import useLatestObj from "../../../common/use-latest-obj";
22
22
  import { devUseWarning } from "../../../utils/warning";
23
+ import { cleanProps } from "../../../utils/clean-props";
23
24
  var getValue = function getValue(name, formValue) {
24
25
  if (!name) return undefined;
25
26
  if (isArray(name)) {
@@ -148,7 +149,7 @@ export default function useFormControl(props) {
148
149
  }
149
150
  };
150
151
  var fullRules = (controlFunc === null || controlFunc === void 0 ? void 0 : controlFunc.combineRules(name, rules || [])) || [];
151
- return validate(v, formV, fullRules, validateProps).then(function (res) {
152
+ return validate(v, formV, fullRules, cleanProps(validateProps)).then(function (res) {
152
153
  var err = res === true ? undefined : res;
153
154
  formFunc === null || formFunc === void 0 || formFunc.setError(name, err);
154
155
  onError === null || onError === void 0 || onError(err);
@@ -175,7 +176,7 @@ export default function useFormControl(props) {
175
176
  return e;
176
177
  });
177
178
  } else {
178
- return validate(v, {}, rules || [], {}).then(function (res) {
179
+ return validate(v, {}, rules || [], cleanProps(validateProps)).then(function (res) {
179
180
  var err = res === true ? undefined : res;
180
181
  setErrorState(err);
181
182
  onError === null || onError === void 0 || onError(err);
@@ -217,10 +218,14 @@ export default function useFormControl(props) {
217
218
  if (isArray(name)) {
218
219
  var dv = isArray(defaultValue) ? defaultValue : [];
219
220
  name.forEach(function (n, index) {
220
- controlFunc.bind(n, dv[index], validateField, update);
221
+ var v = formFunc === null || formFunc === void 0 ? void 0 : formFunc.getValue(n);
222
+ var bindedValue = v === undefined ? dv[index] : v;
223
+ controlFunc.bind(n, context.mounted ? bindedValue : dv[index], validateField, update);
221
224
  });
222
225
  } else {
223
- controlFunc.bind(name, defaultValue, validateField, update);
226
+ var v = formFunc === null || formFunc === void 0 ? void 0 : formFunc.getValue(name);
227
+ var bindedValue = v === undefined ? defaultValue : v;
228
+ controlFunc.bind(name, context.mounted ? bindedValue : defaultValue, validateField, update);
224
229
  }
225
230
  if (context.mounted) {
226
231
  devUseWarning.warn('Please avoid modifying the name property after the component has mounted, as this may result in unintended behavior or errors.');
@@ -11,10 +11,10 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
11
11
  [key: string]: any;
12
12
  }, option?: {
13
13
  validate?: boolean;
14
- names?: string[];
14
+ forceUpdate?: boolean;
15
15
  }) => void;
16
16
  getValue: (name?: string) => unknown;
17
- submit: (withValidate?: boolean) => void;
17
+ submit: (withValidate?: boolean, callback?: () => void) => void;
18
18
  reset: () => void;
19
19
  setError: (name: string, e: Error | undefined) => void;
20
20
  getErrors: () => ObjectType<Error | undefined>;
@@ -31,10 +31,10 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
31
31
  [key: string]: any;
32
32
  }, option?: {
33
33
  validate?: boolean;
34
- names?: string[];
34
+ forceUpdate?: boolean;
35
35
  }) => void;
36
36
  getValue: (name?: string) => unknown;
37
- submit: (withValidate?: boolean) => void;
37
+ submit: (withValidate?: boolean, callback?: () => void) => void;
38
38
  reset: () => void;
39
39
  setError: (name: string, e: Error | undefined) => void;
40
40
  getErrors: () => ObjectType<Error | undefined>;
@@ -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;;;;;;;;;wBA+RC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE;8BApKd,MAAM;oCAuOD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCAlMxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAoQvB,MAAM,WAAW,gBAAgB;gCA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAzIpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE;0BApKd,MAAM;gCAuOD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCAlMxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAoQvB,MAAM,WAAW,gBAAgB;4BA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAzIpD,MAAM,0BAAyB,qBAAqB;;CA2a9D,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;;;;;;;;;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"}
@@ -38,7 +38,8 @@ var useForm = function useForm(props) {
38
38
  size = props.size,
39
39
  colon = props.colon,
40
40
  formName = props.name,
41
- scrollParent = props.scrollParent;
41
+ scrollParent = props.scrollParent,
42
+ isControl = props.isControl;
42
43
  var deepSetOptions = {
43
44
  removeUndefined: removeUndefined,
44
45
  forceSet: true
@@ -192,7 +193,7 @@ var useForm = function useForm(props) {
192
193
  if (errors.length > 0) {
193
194
  var errorFields = [];
194
195
  for (var _key in context.errors) {
195
- if (context.errors[_key]) {
196
+ if (context.errors[_key] && context.names.has(_key)) {
196
197
  var _context$errors$_key;
197
198
  errorFields.push({
198
199
  name: _key,
@@ -294,13 +295,16 @@ var useForm = function useForm(props) {
294
295
  var values = Object.keys(vals);
295
296
  // 针对 name 为数组模式,如 datepicker 的 name={['startTime', 'endTime']} 时,前者校验可能需要依赖后者,因此需要提前将后者数据整合至 draft 用于多字段整合校验
296
297
  values.forEach(function (key) {
297
- deepSet(draft, key, vals[key], deepSetOptions);
298
+ // upload组件返回的可能是函数: (prev) => [...prev, file]
299
+ var valueOfKey = typeof vals[key] === 'function' ? vals[key](getValue(key)) : vals[key];
300
+ deepSet(draft, key, valueOfKey, deepSetOptions);
298
301
  });
299
302
  values.forEach(function (key) {
300
303
  if (option.validate) {
301
304
  var _context$validateMap$;
302
305
  (_context$validateMap$ = context.validateMap[key]) === null || _context$validateMap$ === void 0 || _context$validateMap$.forEach(function (validate) {
303
- validate(key, vals[key], current(draft));
306
+ var valueOfKey = typeof vals[key] === 'function' ? vals[key](getValue(key)) : vals[key];
307
+ validate(key, valueOfKey, current(draft));
304
308
  });
305
309
  }
306
310
  });
@@ -311,7 +315,11 @@ var useForm = function useForm(props) {
311
315
  fullKeyPaths.forEach(function (key) {
312
316
  delete context.serverErrors[key];
313
317
  });
314
- update(fullKeyPaths);
318
+ if (option.forceUpdate) {
319
+ update();
320
+ } else {
321
+ update(fullKeyPaths);
322
+ }
315
323
  });
316
324
  var updateDefaultValue = function updateDefaultValue() {
317
325
  if (!context.mounted) return;
@@ -356,6 +364,7 @@ var useForm = function useForm(props) {
356
364
  });
357
365
  var submit = usePersistFn(function () {
358
366
  var withValidate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
367
+ var callback = arguments.length > 1 ? arguments[1] : undefined;
359
368
  if (disabled) return;
360
369
  if (context.submitLock) {
361
370
  return;
@@ -373,32 +382,29 @@ var useForm = function useForm(props) {
373
382
  while (1) switch (_context.prev = _context.next) {
374
383
  case 0:
375
384
  if (withValidate) {
376
- _context.next = 3;
385
+ _context.next = 4;
377
386
  break;
378
387
  }
379
388
  (_props$onSubmit = props.onSubmit) === null || _props$onSubmit === void 0 || _props$onSubmit.call(props, (_context$value = context.value) !== null && _context$value !== void 0 ? _context$value : {});
389
+ callback === null || callback === void 0 || callback();
380
390
  return _context.abrupt("return");
381
- case 3:
382
- _context.next = 5;
391
+ case 4:
392
+ _context.next = 6;
383
393
  return validateFields(undefined, {
384
394
  ignoreBind: true
385
395
  }).catch(function (e) {
386
396
  return e;
387
397
  });
388
- case 5:
398
+ case 6:
389
399
  result = _context.sent;
390
- if (!(result === true)) {
391
- _context.next = 11;
392
- break;
400
+ if (result === true) {
401
+ (_props$onSubmit2 = props.onSubmit) === null || _props$onSubmit2 === void 0 || _props$onSubmit2.call(props, (_context$value2 = context.value) !== null && _context$value2 !== void 0 ? _context$value2 : {});
402
+ if (activeEl) activeEl.focus();
403
+ } else {
404
+ handleSubmitError(result);
393
405
  }
394
- (_props$onSubmit2 = props.onSubmit) === null || _props$onSubmit2 === void 0 || _props$onSubmit2.call(props, (_context$value2 = context.value) !== null && _context$value2 !== void 0 ? _context$value2 : {});
395
- if (activeEl) activeEl.focus();
396
- _context.next = 13;
397
- break;
398
- case 11:
399
- handleSubmitError(result);
400
- return _context.abrupt("return");
401
- case 13:
406
+ callback === null || callback === void 0 || callback();
407
+ case 9:
402
408
  case "end":
403
409
  return _context.stop();
404
410
  }
@@ -482,10 +488,8 @@ var useForm = function useForm(props) {
482
488
  context.updateMap[n] = new Set();
483
489
  }
484
490
  context.updateMap[n].add(updateFn);
485
- var shouldTriggerResetChange = context.removeArr.has(n);
486
491
  context.removeArr.delete(n);
487
- var shouldTriggerDefaultChange = df !== undefined && deepGet(context.value, n) === undefined;
488
- if (shouldTriggerDefaultChange || shouldTriggerResetChange) {
492
+ if (df !== undefined && deepGet(context.value, n) === undefined) {
489
493
  if (!context.mounted) context.defaultValues[n] = df;
490
494
  onChange(function (v) {
491
495
  deepSet(v, n, df, deepSetOptions);
@@ -505,7 +509,6 @@ var useForm = function useForm(props) {
505
509
  }
506
510
  if (validateFieldSet.size === 0 && updateFieldSet.size === 0) {
507
511
  context.names.delete(n);
508
- delete context.errors[n];
509
512
  delete context.defaultValues[n];
510
513
  }
511
514
  var finalReserveAble = (_props$reserveAble = props.reserveAble) !== null && _props$reserveAble !== void 0 ? _props$reserveAble : reserveAble;
@@ -600,7 +603,10 @@ var useForm = function useForm(props) {
600
603
  React.useEffect(function () {
601
604
  context.removeLock = false;
602
605
  // 内部 onChange 改的 value, 不需要更新
603
- if (props.value === context.value) return;
606
+ if (props.value === context.value) {
607
+ if (!isControl) update();
608
+ return;
609
+ }
604
610
  if (initValidate && !context.resetTime) {
605
611
  var keys = Object.keys(context.validateMap).filter(function (key) {
606
612
  var oldValue = deepGet(preValue || emptyObj, key);
@@ -58,6 +58,13 @@ export interface FormLabelConfig {
58
58
  * @default false
59
59
  */
60
60
  keepErrorHeight?: boolean;
61
+ /**
62
+ * @en Whether to keep the error message below the form item, the default is false
63
+ * @cn 是否保持错误信息在提示信息下方
64
+ * @default false
65
+ * @version 3.7.0
66
+ */
67
+ keepErrorBelow?: boolean;
61
68
  /**
62
69
  * @en When inline is true, the form is horizontal layout
63
70
  * @cn 是否水平布局
@@ -187,6 +194,7 @@ export interface BaseFormProps<T> extends Omit<FormCommonConfig, 'formName'> {
187
194
  }
188
195
  export type UseFormProps<T> = BaseFormProps<T> & {
189
196
  formElRef: React.RefObject<HTMLFormElement>;
197
+ isControl: boolean;
190
198
  };
191
199
  export type FormContext = {
192
200
  defaultValues: ObjectType;
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB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AEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CACzE,mBAAmB,EACnB,MAAM,CACP,CAAC"}
@@ -14,6 +14,8 @@ declare const useImage: (props?: BaseImageProps) => {
14
14
  onClick: (event: React.MouseEvent<HTMLImageElement | HTMLDivElement>) => void;
15
15
  };
16
16
  getImageProps: <TOther_1 extends ObjectType = ObjectType>(externalProps?: TOther_1) => {
17
+ style: React.CSSProperties;
18
+ } & {
17
19
  [x: string]: (event: any) => void;
18
20
  } & TOther_1 & {
19
21
  alt: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"use-image.d.ts","sourceRoot":"","sources":["use-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAWlD,QAAA,MAAM,QAAQ,WAAW,cAAc;;;;;;;;;;yBA6D3B,gBAAgB,CAAC,gBAAgB,GAAG,cAAc,CAAC;;;;;;;;;;;CAmF9D,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"use-image.d.ts","sourceRoot":"","sources":["use-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAWlD,QAAA,MAAM,QAAQ,WAAW,cAAc;;;;;;;;;;yBAiG3B,gBAAgB,CAAC,gBAAgB,GAAG,cAAc,CAAC;;;;;;;;;;;;;CAoF9D,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -36,6 +36,10 @@ var useImage = function useImage() {
36
36
  _React$useState2 = _slicedToArray(_React$useState, 2),
37
37
  status = _React$useState2[0],
38
38
  setStatus = _React$useState2[1];
39
+ var _React$useState3 = React.useState({}),
40
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
41
+ imgCoverStyle = _React$useState4[0],
42
+ setImgCoverStyle = _React$useState4[1];
39
43
  var elementRef = React.useRef(null);
40
44
  var getUrl = function getUrl(url) {
41
45
  var auto = 'autoSSL' in props ? autoSSL : config.autoSSL;
@@ -70,6 +74,35 @@ var useImage = function useImage() {
70
74
  };
71
75
  img.src = getUrl(alt);
72
76
  };
77
+ var handleCoverStyle = function handleCoverStyle(img) {
78
+ var container = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current;
79
+ if (!container) return;
80
+
81
+ // 根据容器的宽高获取宽高比
82
+ var containerWidth = container.clientWidth;
83
+ var containerHeight = container.clientHeight;
84
+ var containerRatio = containerWidth / containerHeight;
85
+
86
+ // 根据图片的自然尺寸获取宽高比
87
+ var imageWidth = img.naturalWidth;
88
+ var imageHeight = img.naturalHeight;
89
+ var imageRatio = imageWidth / imageHeight;
90
+
91
+ // 判断宽高比,决定图片填充策略
92
+ if (imageRatio > containerRatio) {
93
+ // 图片更宽,宽度占满容器,高度自适应
94
+ setImgCoverStyle({
95
+ height: '100%',
96
+ width: 'auto'
97
+ });
98
+ } else {
99
+ // 图片更高,填满容器高度
100
+ setImgCoverStyle({
101
+ width: '100%',
102
+ height: 'auto'
103
+ });
104
+ }
105
+ };
73
106
  var markToRender = function markToRender() {
74
107
  if (!src) {
75
108
  handleAlt();
@@ -77,7 +110,10 @@ var useImage = function useImage() {
77
110
  }
78
111
  var img = new window.Image();
79
112
  img.onload = function () {
80
- return setStatus(SRC);
113
+ setStatus(SRC);
114
+ if (props.fit === 'fill') {
115
+ handleCoverStyle(img);
116
+ }
81
117
  };
82
118
  img.onerror = function (e) {
83
119
  return handleError(SRC, e);
@@ -106,7 +142,9 @@ var useImage = function useImage() {
106
142
  alt: alt,
107
143
  draggable: !noImgDrag
108
144
  });
109
- return _objectSpread({}, mergedEventHandlers);
145
+ return _objectSpread({
146
+ style: imgCoverStyle
147
+ }, mergedEventHandlers);
110
148
  };
111
149
  var getImageDivProps = function getImageDivProps() {
112
150
  var externalProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
2
  declare const context: React.Context<{
3
+ addParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
4
+ removeParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
3
5
  bindChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
4
6
  removeChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
5
7
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"popup-context.d.ts","sourceRoot":"","sources":["popup-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAO7C,QAAA,MAAM,OAAO;sBAJO,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;wBACxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;EAGnB,CAAC;AAE9C,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"popup-context.d.ts","sourceRoot":"","sources":["popup-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAS7C,QAAA,MAAM,OAAO;sBANO,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;yBACvC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;sBAC7C,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;wBACxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;EAGnB,CAAC;AAE9C,eAAe,OAAO,CAAC"}
@@ -2,6 +2,8 @@
2
2
 
3
3
  import { createContext } from 'react';
4
4
  var defaultContext = {
5
+ addParent: function addParent(_ref) {},
6
+ removeParent: function removeParent(_ref) {},
5
7
  bindChild: function bindChild(_ref) {},
6
8
  removeChild: function removeChild(_ref) {}
7
9
  };
@@ -39,10 +39,14 @@ declare const usePopup: (props: BasePopupProps) => {
39
39
  openPop: () => void;
40
40
  closePop: () => void;
41
41
  Provider: React.Provider<{
42
+ addParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
43
+ removeParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
42
44
  bindChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
43
45
  removeChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
44
46
  }>;
45
47
  providerValue: {
48
+ addParent: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
49
+ removeParent: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
46
50
  bindChild: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
47
51
  removeChild: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
48
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhE,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;;0BA6HK;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;0BAM9B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;qBA5B7B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;;;;;;;;;;;;;;;;;;;;;2BA6ElD,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;6BAGxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;;CAqBpE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"m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