@kdcloudjs/kdesign 1.6.31 → 1.6.33

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 (64) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +3 -0
  3. package/dist/kdesign.css +1 -1
  4. package/dist/kdesign.css.map +1 -1
  5. package/dist/kdesign.js +2071 -219
  6. package/dist/kdesign.js.map +1 -1
  7. package/dist/kdesign.min.css +1 -1
  8. package/dist/kdesign.min.js +8 -8
  9. package/dist/kdesign.min.js.map +1 -1
  10. package/es/_utils/getStringLength.d.ts +1 -0
  11. package/es/_utils/getStringLength.js +14 -0
  12. package/es/_utils/hooks.d.ts +3 -0
  13. package/es/_utils/hooks.js +50 -1
  14. package/es/_utils/raf.d.ts +3 -0
  15. package/es/_utils/raf.js +35 -0
  16. package/es/_utils/resizeObserver.d.ts +15 -0
  17. package/es/_utils/resizeObserver.js +79 -0
  18. package/es/_utils/usePopper.js +1 -1
  19. package/es/date-picker/date-picker.js +2 -5
  20. package/es/select/interface.d.ts +2 -0
  21. package/es/select/select.js +22 -2
  22. package/es/stepper/stepper.js +2 -1
  23. package/es/table/feature/colGroupExtendable.d.ts +4 -0
  24. package/es/table/feature/colGroupExtendable.js +9 -0
  25. package/es/table/interface.d.ts +2 -1
  26. package/es/table/table.js +5 -1
  27. package/es/virtual-list/Filler.d.ts +9 -0
  28. package/es/virtual-list/Filler.js +38 -0
  29. package/es/virtual-list/index.d.ts +3 -0
  30. package/es/virtual-list/index.js +3 -0
  31. package/es/virtual-list/utils/algorithmUtil.d.ts +19 -0
  32. package/es/virtual-list/utils/algorithmUtil.js +79 -0
  33. package/es/virtual-list/utils/itemUtil.d.ts +75 -0
  34. package/es/virtual-list/utils/itemUtil.js +176 -0
  35. package/es/virtual-list/virtual-list.d.ts +34 -0
  36. package/es/virtual-list/virtual-list.js +589 -0
  37. package/lib/_utils/getStringLength.d.ts +1 -0
  38. package/lib/_utils/getStringLength.js +21 -0
  39. package/lib/_utils/hooks.d.ts +3 -0
  40. package/lib/_utils/hooks.js +56 -0
  41. package/lib/_utils/raf.d.ts +3 -0
  42. package/lib/_utils/raf.js +43 -0
  43. package/lib/_utils/resizeObserver.d.ts +15 -0
  44. package/lib/_utils/resizeObserver.js +95 -0
  45. package/lib/_utils/usePopper.js +1 -1
  46. package/lib/date-picker/date-picker.js +2 -6
  47. package/lib/select/interface.d.ts +2 -0
  48. package/lib/select/select.js +23 -2
  49. package/lib/stepper/stepper.js +3 -1
  50. package/lib/table/feature/colGroupExtendable.d.ts +4 -0
  51. package/lib/table/feature/colGroupExtendable.js +17 -0
  52. package/lib/table/interface.d.ts +2 -1
  53. package/lib/table/table.js +6 -1
  54. package/lib/virtual-list/Filler.d.ts +9 -0
  55. package/lib/virtual-list/Filler.js +59 -0
  56. package/lib/virtual-list/index.d.ts +3 -0
  57. package/lib/virtual-list/index.js +36 -0
  58. package/lib/virtual-list/utils/algorithmUtil.d.ts +19 -0
  59. package/lib/virtual-list/utils/algorithmUtil.js +88 -0
  60. package/lib/virtual-list/utils/itemUtil.d.ts +75 -0
  61. package/lib/virtual-list/utils/itemUtil.js +206 -0
  62. package/lib/virtual-list/virtual-list.d.ts +34 -0
  63. package/lib/virtual-list/virtual-list.js +626 -0
  64. package/package.json +1 -1
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.GHOST_ITEM_KEY = void 0;
9
+ exports.getCompareItemRelativeTop = getCompareItemRelativeTop;
10
+ exports.getItemAbsoluteTop = getItemAbsoluteTop;
11
+ exports.getItemRelativeTop = getItemRelativeTop;
12
+ exports.getLocationItem = getLocationItem;
13
+ exports.getLongestItemIndex = getLongestItemIndex;
14
+ exports.getNodeHeight = getNodeHeight;
15
+ exports.getRangeIndex = getRangeIndex;
16
+ exports.getScrollPercentage = getScrollPercentage;
17
+ exports.getValidScrollTop = getValidScrollTop;
18
+
19
+ var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
20
+
21
+ var _isNan = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/number/is-nan"));
22
+
23
+ var _reactDom = require("react-dom");
24
+
25
+ var _getStringLength = _interopRequireDefault(require("../../_utils/getStringLength"));
26
+
27
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
28
+ var t = {};
29
+
30
+ for (var p in s) {
31
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
32
+ }
33
+
34
+ if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
35
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
36
+ }
37
+ return t;
38
+ };
39
+
40
+ /**
41
+ * 为了计算方便,定位元素的下标可能返回数组长度,代表最后一个元素
42
+ */
43
+ var GHOST_ITEM_KEY = '__rc_ghost_item__';
44
+ /**
45
+ * 根据滚动条当前的滚动百分比,计算出基准元素
46
+ * 在基准元素的上方和下方渲染可见区域的其他元素
47
+ */
48
+
49
+ exports.GHOST_ITEM_KEY = GHOST_ITEM_KEY;
50
+
51
+ function getLocationItem(scrollPtg, total) {
52
+ var itemIndex = Math.floor(scrollPtg * total);
53
+ var itemTopPtg = itemIndex / total;
54
+ var offsetPtg = (scrollPtg - itemTopPtg) / (1 / total);
55
+ return {
56
+ index: itemIndex,
57
+ offsetPtg: (0, _isNan.default)(offsetPtg) ? 0 : offsetPtg
58
+ };
59
+ }
60
+ /**
61
+ * 获取HTML元素高度
62
+ */
63
+
64
+
65
+ function getNodeHeight(node) {
66
+ var needMargin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
67
+ // eslint-disable-next-line react/no-find-dom-node
68
+ var element = (0, _reactDom.findDOMNode)(node);
69
+ var marginVertical = 0;
70
+
71
+ if (needMargin) {
72
+ var _window$getComputedSt = window.getComputedStyle(node),
73
+ marginTop = _window$getComputedSt.marginTop,
74
+ marginBottom = _window$getComputedSt.marginBottom;
75
+
76
+ marginVertical = Number(marginTop.replace(/\D/g, '')) + Number(marginBottom.replace(/\D/g, ''));
77
+ marginVertical = isNaN(marginVertical) ? 0 : marginVertical;
78
+ }
79
+
80
+ return element ? element.offsetHeight + marginVertical : 0;
81
+ }
82
+ /**
83
+ * 获取有效的scrollTop值
84
+ * Safari的缓动效果会获得负值的scrollTop
85
+ */
86
+
87
+
88
+ function getValidScrollTop(scrollTop, scrollRange) {
89
+ return scrollTop < 0 ? 0 : scrollTop > scrollRange ? scrollRange : scrollTop;
90
+ }
91
+ /**
92
+ * 视口已滚动距离 / 总可滚动距离
93
+ */
94
+
95
+
96
+ function getScrollPercentage(_ref) {
97
+ var scrollTop = _ref.scrollTop,
98
+ scrollHeight = _ref.scrollHeight,
99
+ clientHeight = _ref.clientHeight;
100
+ var scrollRange = scrollHeight - clientHeight;
101
+ return scrollRange <= 0 ? 0 : getValidScrollTop(scrollTop, scrollRange) / scrollRange;
102
+ }
103
+ /**
104
+ * 计算需要渲染的元素的开始下标、结束下标和用于定位的元素下标
105
+ */
106
+
107
+
108
+ function getRangeIndex(scrollPtg, itemCount, visibleCount) {
109
+ var _getLocationItem = getLocationItem(scrollPtg, itemCount),
110
+ index = _getLocationItem.index,
111
+ offsetPtg = _getLocationItem.offsetPtg;
112
+
113
+ var beforeCount = Math.ceil(scrollPtg * visibleCount);
114
+ var afterCount = Math.ceil((1 - scrollPtg) * visibleCount);
115
+ return {
116
+ itemIndex: index,
117
+ itemOffsetPtg: offsetPtg,
118
+ startIndex: Math.max(0, index - beforeCount),
119
+ endIndex: Math.min(itemCount - 1, index + afterCount)
120
+ };
121
+ }
122
+ /**
123
+ * 计算元素相对于视口顶部的偏移量
124
+ */
125
+
126
+
127
+ function getItemRelativeTop(_ref2) {
128
+ var itemHeight = _ref2.itemHeight,
129
+ itemOffsetPtg = _ref2.itemOffsetPtg,
130
+ scrollPtg = _ref2.scrollPtg,
131
+ clientHeight = _ref2.clientHeight;
132
+ return Math.floor(clientHeight * scrollPtg - itemHeight * itemOffsetPtg);
133
+ }
134
+ /**
135
+ * 计算元素相对于整个滚动区域顶部的偏移量
136
+ */
137
+
138
+
139
+ function getItemAbsoluteTop(_a) {
140
+ var scrollTop = _a.scrollTop,
141
+ rest = __rest(_a, ["scrollTop"]);
142
+
143
+ return scrollTop + getItemRelativeTop(rest);
144
+ }
145
+ /**
146
+ * 计算某一指定下标的元素相对于视口顶部的偏移量
147
+ */
148
+
149
+
150
+ function getCompareItemRelativeTop(_ref3) {
151
+ var locatedItemRelativeTop = _ref3.locatedItemRelativeTop,
152
+ locatedItemIndex = _ref3.locatedItemIndex,
153
+ compareItemIndex = _ref3.compareItemIndex,
154
+ startIndex = _ref3.startIndex,
155
+ endIndex = _ref3.endIndex,
156
+ getItemKey = _ref3.getItemKey,
157
+ itemElementHeights = _ref3.itemElementHeights,
158
+ itemHeight = _ref3.itemHeight;
159
+ var compareItemTop = locatedItemRelativeTop;
160
+ var compareItemKey = getItemKey(compareItemIndex);
161
+
162
+ if (compareItemIndex <= locatedItemIndex) {
163
+ for (var index = locatedItemIndex; index >= startIndex; index -= 1) {
164
+ var key = getItemKey(index);
165
+
166
+ if (key === compareItemKey) {
167
+ break;
168
+ }
169
+
170
+ var prevItemKey = getItemKey(index - 1);
171
+ compareItemTop -= itemElementHeights[prevItemKey] || itemHeight;
172
+ }
173
+ } else {
174
+ for (var _index = locatedItemIndex; _index <= endIndex; _index += 1) {
175
+ var _key = getItemKey(_index);
176
+
177
+ if (_key === compareItemKey) {
178
+ break;
179
+ }
180
+
181
+ compareItemTop += itemElementHeights[_key] || itemHeight;
182
+ }
183
+ }
184
+
185
+ return compareItemTop;
186
+ }
187
+
188
+ function getLongestItemIndex(data) {
189
+ var result = -1;
190
+ var length = 0;
191
+ data.forEach(function (item, index) {
192
+ var _a;
193
+
194
+ item = typeof item === 'string' ? item : (_a = item.props) === null || _a === void 0 ? void 0 : _a.children;
195
+
196
+ if (typeof item === 'string') {
197
+ var _length = (0, _getStringLength.default)(item);
198
+
199
+ if (_length > length) {
200
+ length = _length;
201
+ result = index;
202
+ }
203
+ }
204
+ });
205
+ return result;
206
+ }
@@ -0,0 +1,34 @@
1
+ import React, { ReactNode, CSSProperties } from 'react';
2
+ import { Key } from './utils/itemUtil';
3
+ export declare function isNumber(obj: any): obj is number;
4
+ export declare type RenderFunc<T> = (item: T, index: number, props: {
5
+ style: React.CSSProperties;
6
+ }) => ReactNode;
7
+ export interface VirtualListProps<T> extends Omit<React.HTMLAttributes<any>, 'children'> {
8
+ children: RenderFunc<T>;
9
+ data: T[];
10
+ height?: number | string;
11
+ itemHeight?: number;
12
+ wrapper?: string | React.FC<any> | React.ComponentClass<any>;
13
+ threshold?: number | null;
14
+ isStaticItemHeight?: boolean;
15
+ itemKey?: Key | ((item: T, index: number) => Key);
16
+ measureLongestItem?: boolean;
17
+ scrollOptions?: ScrollIntoViewOptions;
18
+ needFiller?: boolean;
19
+ outerStyle?: CSSProperties;
20
+ onScroll?: React.UIEventHandler<HTMLElement>;
21
+ }
22
+ export declare type AvailableVirtualListProps = Pick<VirtualListProps<any>, 'height' | 'itemHeight' | 'threshold' | 'isStaticItemHeight' | 'scrollOptions'>;
23
+ export declare type VirtualListHandle = {
24
+ dom: HTMLElement;
25
+ scrollTo: (arg: number | {
26
+ index: number;
27
+ options?: ScrollIntoViewOptions;
28
+ } | {
29
+ key: Key;
30
+ options?: ScrollIntoViewOptions;
31
+ }) => void;
32
+ };
33
+ declare const VirtualList: React.ForwardRefExoticComponent<VirtualListProps<any> & React.RefAttributes<VirtualListHandle>>;
34
+ export default VirtualList;