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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. package/cjs/common/use-position-style/index.d.ts +4 -1
  2. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  3. package/cjs/common/use-position-style/index.js +98 -11
  4. package/cjs/components/use-datepicker/use-date.d.ts +2 -2
  5. package/cjs/components/use-datepicker/use-date.d.ts.map +1 -1
  6. package/cjs/components/use-datepicker/use-date.js +2 -2
  7. package/cjs/components/use-datepicker/use-date.type.d.ts +1 -1
  8. package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
  9. package/cjs/components/use-datepicker/use-datepicker-format.d.ts +1 -1
  10. package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  11. package/cjs/components/use-datepicker/use-datepicker-format.js +4 -2
  12. package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts +1 -0
  13. package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
  14. package/cjs/components/use-datepicker/use-month.d.ts +2 -2
  15. package/cjs/components/use-datepicker/use-month.d.ts.map +1 -1
  16. package/cjs/components/use-datepicker/use-month.js +2 -2
  17. package/cjs/components/use-datepicker/use-month.type.d.ts +1 -1
  18. package/cjs/components/use-datepicker/use-month.type.d.ts.map +1 -1
  19. package/cjs/components/use-datepicker/use-quarter.d.ts +2 -2
  20. package/cjs/components/use-datepicker/use-quarter.d.ts.map +1 -1
  21. package/cjs/components/use-datepicker/use-quarter.js +2 -2
  22. package/cjs/components/use-datepicker/use-year.d.ts +2 -2
  23. package/cjs/components/use-datepicker/use-year.d.ts.map +1 -1
  24. package/cjs/components/use-datepicker/use-year.js +2 -2
  25. package/cjs/components/use-datepicker/use-year.type.d.ts +1 -1
  26. package/cjs/components/use-datepicker/use-year.type.d.ts.map +1 -1
  27. package/cjs/components/use-datepicker/util.d.ts +1 -1
  28. package/cjs/components/use-datepicker/util.d.ts.map +1 -1
  29. package/cjs/components/use-datepicker/util.js +2 -1
  30. package/cjs/components/use-form/use-form-control/use-form-control.js +2 -2
  31. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  32. package/cjs/components/use-form/use-form.js +40 -19
  33. package/cjs/components/use-form/use-form.type.d.ts +11 -6
  34. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  35. package/cjs/components/use-input/use-input-format.d.ts +1 -1
  36. package/cjs/components/use-input/use-input-number.d.ts +1 -1
  37. package/cjs/components/use-popup/use-popup.d.ts +1 -0
  38. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  39. package/cjs/components/use-popup/use-popup.js +7 -4
  40. package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
  41. package/cjs/components/use-table/use-table-virtual.js +28 -3
  42. package/cjs/utils/position.d.ts +1 -1
  43. package/cjs/utils/position.d.ts.map +1 -1
  44. package/cjs/utils/position.js +20 -5
  45. package/esm/common/use-position-style/index.d.ts +4 -1
  46. package/esm/common/use-position-style/index.d.ts.map +1 -1
  47. package/esm/common/use-position-style/index.js +99 -12
  48. package/esm/components/use-datepicker/use-date.d.ts +2 -2
  49. package/esm/components/use-datepicker/use-date.d.ts.map +1 -1
  50. package/esm/components/use-datepicker/use-date.js +2 -2
  51. package/esm/components/use-datepicker/use-date.type.d.ts +1 -1
  52. package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
  53. package/esm/components/use-datepicker/use-datepicker-format.d.ts +1 -1
  54. package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  55. package/esm/components/use-datepicker/use-datepicker-format.js +4 -2
  56. package/esm/components/use-datepicker/use-datepicker-format.type.d.ts +1 -0
  57. package/esm/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
  58. package/esm/components/use-datepicker/use-month.d.ts +2 -2
  59. package/esm/components/use-datepicker/use-month.d.ts.map +1 -1
  60. package/esm/components/use-datepicker/use-month.js +2 -2
  61. package/esm/components/use-datepicker/use-month.type.d.ts +1 -1
  62. package/esm/components/use-datepicker/use-month.type.d.ts.map +1 -1
  63. package/esm/components/use-datepicker/use-quarter.d.ts +2 -2
  64. package/esm/components/use-datepicker/use-quarter.d.ts.map +1 -1
  65. package/esm/components/use-datepicker/use-quarter.js +2 -2
  66. package/esm/components/use-datepicker/use-year.d.ts +2 -2
  67. package/esm/components/use-datepicker/use-year.d.ts.map +1 -1
  68. package/esm/components/use-datepicker/use-year.js +2 -2
  69. package/esm/components/use-datepicker/use-year.type.d.ts +1 -1
  70. package/esm/components/use-datepicker/use-year.type.d.ts.map +1 -1
  71. package/esm/components/use-datepicker/util.d.ts +1 -1
  72. package/esm/components/use-datepicker/util.d.ts.map +1 -1
  73. package/esm/components/use-datepicker/util.js +2 -1
  74. package/esm/components/use-form/use-form-control/use-form-control.js +2 -2
  75. package/esm/components/use-form/use-form.d.ts.map +1 -1
  76. package/esm/components/use-form/use-form.js +40 -19
  77. package/esm/components/use-form/use-form.type.d.ts +11 -6
  78. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  79. package/esm/components/use-input/use-input-format.d.ts +1 -1
  80. package/esm/components/use-input/use-input-number.d.ts +1 -1
  81. package/esm/components/use-popup/use-popup.d.ts +1 -0
  82. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  83. package/esm/components/use-popup/use-popup.js +7 -4
  84. package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
  85. package/esm/components/use-table/use-table-virtual.js +28 -3
  86. package/esm/utils/position.d.ts +1 -1
  87. package/esm/utils/position.d.ts.map +1 -1
  88. package/esm/utils/position.js +20 -5
  89. package/package.json +1 -1
@@ -10,6 +10,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { usePersistFn } from "../../common/use-persist-fn";
12
12
  import { useState, useRef, useEffect, useMemo } from 'react';
13
+ var MAX_ROW_SPAN = 200;
13
14
  var useTableVirtual = function useTableVirtual(props) {
14
15
  var _useState = useState(0),
15
16
  _useState2 = _slicedToArray(_useState, 2),
@@ -92,7 +93,9 @@ var useTableVirtual = function useTableVirtual(props) {
92
93
  topTimer: null,
93
94
  controlScrollRate: null,
94
95
  heightCallback: null,
95
- preIndex: null
96
+ preIndex: null,
97
+ rowSpanRows: 0,
98
+ autoAddRows: 0
96
99
  }),
97
100
  context = _useRef.current;
98
101
  var getTranslate = usePersistFn(function (left, top) {
@@ -143,17 +146,20 @@ var useTableVirtual = function useTableVirtual(props) {
143
146
  var top = 0;
144
147
  var maxIndex = Math.max(props.data.length - rowsInView, 0);
145
148
  for (var i = 0; i <= maxIndex; i++) {
149
+ context.rowSpanRows = 0;
146
150
  sum += context.cachedHeight[i] || props.rowHeight;
147
151
  var rowSpanHeight = 0;
148
152
  if (rowSpanInfos) {
153
+ var maxRowSpanLenth = Math.min(rowSpanInfos.length, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN);
149
154
  var siblingsIndexs = [];
150
- for (var k = 0; k < rowSpanInfos.length; k++) {
155
+ for (var k = 0; k < maxRowSpanLenth; k++) {
151
156
  if (rowSpanInfos[k] <= i && k > i) {
152
157
  siblingsIndexs.push(k);
153
158
  }
154
159
  }
155
160
  for (var j = 0; j < siblingsIndexs.length; j++) {
156
161
  var index = siblingsIndexs[j];
162
+ context.rowSpanRows += 1;
157
163
  rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
158
164
  }
159
165
  }
@@ -244,6 +250,24 @@ var useTableVirtual = function useTableVirtual(props) {
244
250
  props.scrollRef.current.scrollTop = beforeHeight;
245
251
  }
246
252
  });
253
+ useEffect(function () {
254
+ var scrollRefHeight = props.scrollRef.current ? props.scrollRef.current.clientHeight : 0;
255
+ var tableRefHeight = props.innerRef.current ? props.innerRef.current.clientHeight : 0;
256
+ var remainHeight = scrollRefHeight - tableRefHeight;
257
+ if (remainHeight > 0) {
258
+ var addonHeight = 0;
259
+ var addonCount = 0;
260
+ for (var i = startIndex + rowsInView; i < props.data.length; i++) {
261
+ var height = context.cachedHeight[i] || props.rowHeight;
262
+ addonHeight += height;
263
+ addonCount += 1;
264
+ if (addonHeight >= remainHeight + context.cachedHeight[0]) break;
265
+ }
266
+ if (addonCount > 0) {
267
+ context.autoAddRows = addonCount;
268
+ }
269
+ }
270
+ }, []);
247
271
  useEffect(function () {
248
272
  // 记录preIndex
249
273
  context.preIndex = startIndex;
@@ -278,7 +302,8 @@ var useTableVirtual = function useTableVirtual(props) {
278
302
  cb();
279
303
  }
280
304
  }, [scrollHeight]);
281
- var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + rowsInView);
305
+ var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
306
+ var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
282
307
  return {
283
308
  scrollHeight: scrollHeight,
284
309
  startIndex: startIndex,
@@ -1,2 +1,2 @@
1
- export declare const getPosition: (target: HTMLElement | null, priorityDirection: "vertical" | "horizontal" | "auto" | undefined, mode: 'popover' | 'menu' | 'list') => "bottom" | "left" | "right" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom" | "right-top" | "right-bottom";
1
+ export declare const getPosition: (target: HTMLElement | null, priorityDirection: "vertical" | "horizontal" | "auto" | undefined, mode: 'popover' | 'menu' | 'list', popup?: HTMLElement) => "bottom" | "left" | "right" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom" | "right-top" | "right-bottom";
2
2
  //# sourceMappingURL=position.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAgFA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,gKAKlC,CAAC"}
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"}
@@ -35,6 +35,7 @@ var getMenuPosition = function getMenuPosition(target) {
35
35
  };
36
36
  var getPopoverPosition = function getPopoverPosition(target) {
37
37
  var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
38
+ var popup = arguments.length > 2 ? arguments[2] : undefined;
38
39
  var position = 'bottom-left';
39
40
  if (!target) return position;
40
41
  var rect = target.getBoundingClientRect();
@@ -56,11 +57,24 @@ var getPopoverPosition = function getPopoverPosition(target) {
56
57
  position += '-top';
57
58
  }
58
59
  } else {
60
+ var popupRect = popup === null || popup === void 0 ? void 0 : popup.getBoundingClientRect();
59
61
  if (verticalPoint > windowHeight / 2) position = 'top';else position = 'bottom';
60
- if (horizontalPoint > windowWidth * 0.6) {
61
- position += '-right';
62
- } else if (horizontalPoint < windowWidth * 0.4) {
63
- position += '-left';
62
+
63
+ // 如果渲染了弹出内容,则根据弹出内容宽度计算是否自动调整位置
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
+ }
64
78
  }
65
79
  }
66
80
  return position;
@@ -68,7 +82,8 @@ var getPopoverPosition = function getPopoverPosition(target) {
68
82
  export var getPosition = function getPosition(target) {
69
83
  var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
70
84
  var mode = arguments.length > 2 ? arguments[2] : undefined;
71
- if (mode === 'popover') return getPopoverPosition(target, priorityDirection);
85
+ var popup = arguments.length > 3 ? arguments[3] : undefined;
86
+ if (mode === 'popover') return getPopoverPosition(target, priorityDirection, popup);
72
87
  if (mode === 'menu') return getMenuPosition(target, priorityDirection);
73
88
  return 'bottom-left';
74
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.4.0-beta.4",
3
+ "version": "3.4.0-beta.6",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",