@king-design/vue 3.4.5 → 3.5.0
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.
- package/__tests__/__snapshots__/Vue Next Demos.md +70 -38
- package/components/affix/index.d.ts +1 -0
- package/components/affix/index.js +2 -1
- package/components/affix/useStyle.js +50 -47
- package/components/datepicker/basepicker.js +3 -3
- package/components/dialog/styles.js +2 -2
- package/components/dropdown/useKeyboard.js +3 -0
- package/components/input/index.spec.js +21 -0
- package/components/input/index.vdt.js +1 -1
- package/components/input/styles.js +1 -1
- package/components/layout/styles.js +1 -1
- package/components/select/base.d.ts +1 -0
- package/components/select/base.js +2 -1
- package/components/select/group.vdt.js +8 -3
- package/components/select/index.spec.js +13 -1
- package/components/select/menu.vdt.js +12 -3
- package/components/select/select.vdt.js +2 -1
- package/components/select/useFilterable.js +7 -5
- package/components/select/useInput.js +6 -2
- package/components/table/index.spec.js +7 -6
- package/components/table/styles.js +1 -1
- package/components/table/table.d.ts +1 -0
- package/components/table/table.js +3 -2
- package/components/table/table.vdt.js +126 -114
- package/components/treeSelect/index.js +4 -3
- package/components/virtualList/container.d.ts +10 -0
- package/components/virtualList/container.js +26 -0
- package/components/virtualList/container.vdt.js +39 -0
- package/components/virtualList/index.d.ts +5 -0
- package/components/virtualList/index.js +5 -0
- package/components/virtualList/index.spec.d.ts +1 -0
- package/components/virtualList/index.spec.js +372 -0
- package/components/virtualList/phantom.d.ts +9 -0
- package/components/virtualList/phantom.js +24 -0
- package/components/virtualList/phantom.vdt.js +33 -0
- package/components/virtualList/rows.d.ts +8 -0
- package/components/virtualList/rows.js +20 -0
- package/components/virtualList/rows.vdt.js +32 -0
- package/components/virtualList/styles.d.ts +13 -0
- package/components/virtualList/styles.js +34 -0
- package/components/virtualList/useRows.d.ts +2 -0
- package/components/virtualList/useRows.js +19 -0
- package/components/virtualList/useVirtualRows.d.ts +20 -0
- package/components/virtualList/useVirtualRows.js +120 -0
- package/components/virtualList/virtual.d.ts +8 -0
- package/components/virtualList/virtual.js +15 -0
- package/components/virtualList/virtual.vdt.js +26 -0
- package/components/virtualList/wrapper.d.ts +9 -0
- package/components/virtualList/wrapper.js +24 -0
- package/components/virtualList/wrapper.vdt.js +34 -0
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import _Map from "@babel/runtime-corejs3/core-js/map";
|
|
2
|
+
import _Set from "@babel/runtime-corejs3/core-js/set";
|
|
3
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
4
|
+
import { createContext } from '../context';
|
|
5
|
+
import { useState, watchState } from '../../hooks/useState';
|
|
6
|
+
import { useInstance, nextTick, onMounted, onUnmounted, findDomFromVNode } from 'intact-vue-next';
|
|
7
|
+
import { isNullOrUndefined } from 'intact-shared';
|
|
8
|
+
export var context = createContext();
|
|
9
|
+
var MIN_LENGTH = 10;
|
|
10
|
+
var BUFFER_SIZE = 3;
|
|
11
|
+
export function useVirtualRows() {
|
|
12
|
+
var instance = useInstance();
|
|
13
|
+
var rowsHeightMap = new _Map();
|
|
14
|
+
var startIndex = useState(0);
|
|
15
|
+
var length = useState(MIN_LENGTH);
|
|
16
|
+
var calculatedHeight = 0;
|
|
17
|
+
var rowAvgHeight = 0;
|
|
18
|
+
var rows = [];
|
|
19
|
+
function notifyRows(_rows) {
|
|
20
|
+
var oldRows = rows;
|
|
21
|
+
var oldLength = rows.length;
|
|
22
|
+
rows = _rows;
|
|
23
|
+
// diff oldRows, newRows
|
|
24
|
+
var newKeys = new _Set(_mapInstanceProperty(_rows).call(_rows, function (row) {
|
|
25
|
+
return row.key;
|
|
26
|
+
}));
|
|
27
|
+
for (var i = 0; i < oldLength; i++) {
|
|
28
|
+
var oldKey = oldRows[i].key;
|
|
29
|
+
if (!newKeys.has(oldKey)) {
|
|
30
|
+
var height = rowsHeightMap.get(oldKey);
|
|
31
|
+
if (!isNullOrUndefined(height)) {
|
|
32
|
+
calculatedHeight -= height;
|
|
33
|
+
rowsHeightMap.delete(oldKey);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// update rowAvgHeight
|
|
38
|
+
if (rowsHeightMap.size === 0) {
|
|
39
|
+
rowAvgHeight = calculatedHeight = 0;
|
|
40
|
+
} else {
|
|
41
|
+
rowAvgHeight = calculatedHeight / rowsHeightMap.size;
|
|
42
|
+
}
|
|
43
|
+
if (_rows.length < oldLength) {
|
|
44
|
+
var maxStartIndex = Math.max(0, _rows.length - length.value);
|
|
45
|
+
if (startIndex.value > maxStartIndex) {
|
|
46
|
+
startIndex.set(maxStartIndex);
|
|
47
|
+
// 重新计算位置
|
|
48
|
+
nextTick(function () {
|
|
49
|
+
handleScroll();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function calculateRowsHeight() {
|
|
55
|
+
for (var i = startIndex.value; i < startIndex.value + length.value && i < rows.length; i++) {
|
|
56
|
+
var row = rows[i];
|
|
57
|
+
var key = row.key;
|
|
58
|
+
if (!rowsHeightMap.has(key)) {
|
|
59
|
+
var rowDom = findDomFromVNode(row, true);
|
|
60
|
+
var height = rowDom.offsetHeight;
|
|
61
|
+
rowsHeightMap.set(key, height);
|
|
62
|
+
calculatedHeight += height;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// use the average height to estimate the row height
|
|
66
|
+
rowAvgHeight = calculatedHeight / rowsHeightMap.size;
|
|
67
|
+
}
|
|
68
|
+
watchState(startIndex, function () {
|
|
69
|
+
nextTick(calculateRowsHeight);
|
|
70
|
+
});
|
|
71
|
+
var containerDom;
|
|
72
|
+
onMounted(function () {
|
|
73
|
+
// get contains height
|
|
74
|
+
containerDom = findDomFromVNode(instance.$lastInput, true);
|
|
75
|
+
var containerHeight = containerDom.offsetHeight;
|
|
76
|
+
calculateRowsHeight();
|
|
77
|
+
// calculate the length of rows we should render
|
|
78
|
+
length.set(Math.max(Math.ceil(containerHeight / rowAvgHeight) + BUFFER_SIZE * 2, MIN_LENGTH));
|
|
79
|
+
containerDom.addEventListener('scroll', handleScroll);
|
|
80
|
+
});
|
|
81
|
+
onUnmounted(function () {
|
|
82
|
+
containerDom.removeEventListener('scroll', handleScroll);
|
|
83
|
+
});
|
|
84
|
+
function getTotalHeight() {
|
|
85
|
+
return calculatedHeight + rowAvgHeight * (rows.length - rowsHeightMap.size);
|
|
86
|
+
}
|
|
87
|
+
var translateY = useState(0);
|
|
88
|
+
function handleScroll() {
|
|
89
|
+
var _instance$get = instance.get(),
|
|
90
|
+
disabled = _instance$get.disabled;
|
|
91
|
+
if (disabled) return;
|
|
92
|
+
var scrollTop = containerDom.scrollTop;
|
|
93
|
+
var accumulatedHeight = 0;
|
|
94
|
+
var start = 0;
|
|
95
|
+
while (start < rows.length) {
|
|
96
|
+
accumulatedHeight += getRowHeightByIndex(start);
|
|
97
|
+
if (accumulatedHeight > scrollTop) {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
start++;
|
|
101
|
+
}
|
|
102
|
+
startIndex.set(Math.max(start - BUFFER_SIZE, 0));
|
|
103
|
+
// translateY should substract the buffer size rows height
|
|
104
|
+
for (var i = start; i >= startIndex.value; i--) {
|
|
105
|
+
accumulatedHeight -= getRowHeightByIndex(i);
|
|
106
|
+
}
|
|
107
|
+
translateY.set(accumulatedHeight);
|
|
108
|
+
}
|
|
109
|
+
function getRowHeightByIndex(index) {
|
|
110
|
+
var key = rows[index].key;
|
|
111
|
+
return rowsHeightMap.get(key) || rowAvgHeight;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
notifyRows: notifyRows,
|
|
115
|
+
startIndex: startIndex,
|
|
116
|
+
length: length,
|
|
117
|
+
getTotalHeight: getTotalHeight,
|
|
118
|
+
translateY: translateY
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Component, TypeDefs } from 'intact-vue-next';
|
|
2
|
+
export interface VirtualListProps {
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class VirtualList extends Component<VirtualListProps> {
|
|
6
|
+
static template: string | import('intact-vue-next').Template<any>;
|
|
7
|
+
static typeDefs: Required<TypeDefs<VirtualListProps>>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
|
+
import { Component } from 'intact-vue-next';
|
|
3
|
+
import template from './virtual.vdt';
|
|
4
|
+
var typeDefs = {
|
|
5
|
+
disabled: Boolean
|
|
6
|
+
};
|
|
7
|
+
export var VirtualList = /*#__PURE__*/function (_Component) {
|
|
8
|
+
_inheritsLoose(VirtualList, _Component);
|
|
9
|
+
function VirtualList() {
|
|
10
|
+
return _Component.apply(this, arguments) || this;
|
|
11
|
+
}
|
|
12
|
+
return VirtualList;
|
|
13
|
+
}(Component);
|
|
14
|
+
VirtualList.template = template;
|
|
15
|
+
VirtualList.typeDefs = typeDefs;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import { createUnknownComponentVNode as _$cc } from 'intact-vue-next';
|
|
3
|
+
import { getRestProps } from '../utils';
|
|
4
|
+
import { VirtualListContainer } from './container';
|
|
5
|
+
import { VirtualListWrapper } from './wrapper';
|
|
6
|
+
import { VirtualListRows } from './rows';
|
|
7
|
+
import { VirtualListPhantom } from './phantom';
|
|
8
|
+
export default function ($props, $blocks, $__proto__) {
|
|
9
|
+
$blocks || ($blocks = {});
|
|
10
|
+
$props || ($props = {});
|
|
11
|
+
var $this = this;
|
|
12
|
+
var _this$get = this.get(),
|
|
13
|
+
children = _this$get.children,
|
|
14
|
+
disabled = _this$get.disabled;
|
|
15
|
+
if (disabled) {
|
|
16
|
+
return children;
|
|
17
|
+
}
|
|
18
|
+
return _$cc(VirtualListContainer, _extends({}, getRestProps(this), {
|
|
19
|
+
'children': [_$cc(VirtualListPhantom), _$cc(VirtualListWrapper, {
|
|
20
|
+
'children': _$cc(VirtualListRows, {
|
|
21
|
+
'children': children
|
|
22
|
+
})
|
|
23
|
+
})]
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component, TypeDefs, ComponentConstructor } from 'intact-vue-next';
|
|
2
|
+
export interface VirtualListWrapperProps {
|
|
3
|
+
tagName?: string | ComponentConstructor;
|
|
4
|
+
}
|
|
5
|
+
export declare class VirtualListWrapper extends Component<VirtualListWrapperProps> {
|
|
6
|
+
static template: string | import('intact-vue-next').Template<any>;
|
|
7
|
+
static typeDefs: Required<TypeDefs<VirtualListWrapperProps>>;
|
|
8
|
+
private config;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
3
|
+
import { Component } from 'intact-vue-next';
|
|
4
|
+
import template from './wrapper.vdt';
|
|
5
|
+
import { useConfigContext } from '../config';
|
|
6
|
+
var typeDefs = {
|
|
7
|
+
tagName: String
|
|
8
|
+
};
|
|
9
|
+
export var VirtualListWrapper = /*#__PURE__*/function (_Component) {
|
|
10
|
+
_inheritsLoose(VirtualListWrapper, _Component);
|
|
11
|
+
function VirtualListWrapper() {
|
|
12
|
+
var _context;
|
|
13
|
+
var _this;
|
|
14
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
15
|
+
args[_key] = arguments[_key];
|
|
16
|
+
}
|
|
17
|
+
_this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
18
|
+
_this.config = useConfigContext();
|
|
19
|
+
return _this;
|
|
20
|
+
}
|
|
21
|
+
return VirtualListWrapper;
|
|
22
|
+
}(Component);
|
|
23
|
+
VirtualListWrapper.template = template;
|
|
24
|
+
VirtualListWrapper.typeDefs = typeDefs;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
2
|
+
import { createUnknownComponentVNode as _$cc } from 'intact-vue-next';
|
|
3
|
+
import { addStyle, getRestProps } from '../utils';
|
|
4
|
+
import { context as VirtualRowsContext } from './useVirtualRows';
|
|
5
|
+
import { createVNode } from 'intact-vue-next';
|
|
6
|
+
import { cx } from '@emotion/css';
|
|
7
|
+
export default function ($props, $blocks, $__proto__) {
|
|
8
|
+
var _this = this;
|
|
9
|
+
$blocks || ($blocks = {});
|
|
10
|
+
$props || ($props = {});
|
|
11
|
+
var $this = this;
|
|
12
|
+
var _this$get = this.get(),
|
|
13
|
+
_children = _this$get.children,
|
|
14
|
+
className = _this$get.className,
|
|
15
|
+
tagName = _this$get.tagName,
|
|
16
|
+
style = _this$get.style;
|
|
17
|
+
var k = this.config.k;
|
|
18
|
+
return _$cc(VirtualRowsContext.Consumer, {
|
|
19
|
+
'children': function children(_ref) {
|
|
20
|
+
var _classNameObj;
|
|
21
|
+
var translateY = _ref.translateY,
|
|
22
|
+
disabled = _ref.disabled;
|
|
23
|
+
var classNameObj = (_classNameObj = {}, _classNameObj[k + "-virtual-wrapper"] = !disabled, _classNameObj[className] = className, _classNameObj);
|
|
24
|
+
var _style = !disabled ? {
|
|
25
|
+
transform: "translateY(" + translateY + "px)"
|
|
26
|
+
} : {};
|
|
27
|
+
return createVNode(tagName || 'div', _extends({}, getRestProps(_this), {
|
|
28
|
+
className: cx(classNameObj),
|
|
29
|
+
style: addStyle(style, _style)
|
|
30
|
+
}), _children);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @king-design v3.
|
|
2
|
+
* @king-design v3.5.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Kingsoft Cloud
|
|
5
5
|
* Released under the MIT License
|
|
@@ -63,8 +63,9 @@ export * from './components/tree';
|
|
|
63
63
|
export * from './components/treeSelect';
|
|
64
64
|
export * from './components/upload';
|
|
65
65
|
export * from './components/view';
|
|
66
|
+
export * from './components/virtualList';
|
|
66
67
|
export * from './components/wave';
|
|
67
|
-
export declare const version = "3.
|
|
68
|
+
export declare const version = "3.5.0";
|
|
68
69
|
|
|
69
70
|
|
|
70
71
|
export {normalize} from 'intact-vue-next';
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @king-design v3.
|
|
2
|
+
* @king-design v3.5.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Kingsoft Cloud
|
|
5
5
|
* Released under the MIT License
|
|
@@ -64,8 +64,9 @@ export * from './components/tree';
|
|
|
64
64
|
export * from './components/treeSelect';
|
|
65
65
|
export * from './components/upload';
|
|
66
66
|
export * from './components/view';
|
|
67
|
+
export * from './components/virtualList';
|
|
67
68
|
export * from './components/wave';
|
|
68
|
-
export var version = '3.
|
|
69
|
+
export var version = '3.5.0';
|
|
69
70
|
/* generate end */
|
|
70
71
|
|
|
71
72
|
export {normalize} from 'intact-vue-next';
|