@king-design/vue 3.5.1-beta.0 → 3.5.2
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 +84 -78
- package/components/breadcrumb/index.vdt.js +2 -1
- package/components/breadcrumb/styles.js +5 -3
- package/components/select/index.spec.js +54 -0
- package/components/table/table.vdt.js +4 -2
- package/components/tree/useChecked.js +10 -4
- package/components/treeSelect/index.spec.js +82 -5
- package/components/treeSelect/useValue.d.ts +1 -1
- package/components/treeSelect/useValue.js +6 -3
- package/components/virtualList/index.spec.js +200 -1
- package/components/virtualList/rows.vdt.js +2 -1
- package/components/virtualList/useRows.js +15 -2
- package/components/virtualList/useVirtualRows.js +25 -22
- package/hooks/useDocumentClick.js +3 -3
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/package.json +1 -1
- package/styles/fonts/iconfont.js +2 -1
- package/styles/global.js +2 -1
- package/yarn-error.log +43 -44
|
@@ -6,7 +6,8 @@ import { BreadcrumbItem } from './item';
|
|
|
6
6
|
import { makeStyles } from './styles';
|
|
7
7
|
import { Icon } from '../icon';
|
|
8
8
|
var _$tmp0 = {
|
|
9
|
-
'className': 'k-icon-right'
|
|
9
|
+
'className': 'k-icon-right',
|
|
10
|
+
'size': 'small'
|
|
10
11
|
};
|
|
11
12
|
export default function ($props, $blocks, $__proto__) {
|
|
12
13
|
var _classNameObj;
|
|
@@ -4,7 +4,7 @@ import { theme, setDefault } from '../../styles/theme';
|
|
|
4
4
|
import '../../styles/global';
|
|
5
5
|
import { cache } from '../utils';
|
|
6
6
|
var defaults = {
|
|
7
|
-
fontSize: '
|
|
7
|
+
fontSize: '12px',
|
|
8
8
|
get color() {
|
|
9
9
|
return theme.color.lightBlack;
|
|
10
10
|
},
|
|
@@ -13,7 +13,9 @@ var defaults = {
|
|
|
13
13
|
},
|
|
14
14
|
gap: '6px',
|
|
15
15
|
activeFontWeight: 'normal',
|
|
16
|
-
activeColor
|
|
16
|
+
get activeColor() {
|
|
17
|
+
return theme.color.title;
|
|
18
|
+
}
|
|
17
19
|
};
|
|
18
20
|
var breadcrumb;
|
|
19
21
|
setDefault(function () {
|
|
@@ -23,5 +25,5 @@ setDefault(function () {
|
|
|
23
25
|
makeStyles == null || makeStyles.clearCache();
|
|
24
26
|
});
|
|
25
27
|
export var makeStyles = cache(function makeStyles(k) {
|
|
26
|
-
return /*#__PURE__*/css("font-size:", breadcrumb.fontSize, ";display:flex;align-items:center;.", k, "-breadcrumb-item{&:last-of-type .", k, "-breadcrumb-link{font-weight:", breadcrumb.activeFontWeight, ";color:", breadcrumb.activeColor, ";}}.", k, "-breadcrumb-link,.", k, "-breadcrumb-link a{color:", breadcrumb.color, ";}a.", k, "-breadcrumb-link,.", k, "-breadcrumb-link a{cursor:pointer;&:hover{color:", breadcrumb.hoverColor, ";}}.", k, "-breadcrumb-separator{margin:0 ", breadcrumb.gap, ";}");
|
|
28
|
+
return /*#__PURE__*/css("font-size:", breadcrumb.fontSize, ";line-height:12px;display:flex;align-items:center;.", k, "-breadcrumb-item{&:last-of-type .", k, "-breadcrumb-link{font-weight:", breadcrumb.activeFontWeight, ";color:", breadcrumb.activeColor, ";}}.", k, "-breadcrumb-link,.", k, "-breadcrumb-link a{color:", breadcrumb.color, ";}a.", k, "-breadcrumb-link,.", k, "-breadcrumb-link a{cursor:pointer;&:hover{color:", breadcrumb.hoverColor, ";}}.", k, "-breadcrumb-separator{margin:0 ", breadcrumb.gap, ";}");
|
|
27
29
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
3
3
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
4
|
+
import _Array$from from "@babel/runtime-corejs3/core-js/array/from";
|
|
4
5
|
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
5
6
|
import BasicDemo from '~/components/select/demos/basic';
|
|
6
7
|
import DisabledDemo from '~/components/select/demos/disabled';
|
|
@@ -508,6 +509,59 @@ describe('Select', function () {
|
|
|
508
509
|
}
|
|
509
510
|
}, _callee11);
|
|
510
511
|
})));
|
|
512
|
+
it('should handle async data correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
|
|
513
|
+
var Demo, _mount13, instance, element, wrapper, phantom;
|
|
514
|
+
return _regeneratorRuntime.wrap(function _callee12$(_context15) {
|
|
515
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
516
|
+
case 0:
|
|
517
|
+
Demo = /*#__PURE__*/function (_Component3) {
|
|
518
|
+
_inheritsLoose(Demo, _Component3);
|
|
519
|
+
function Demo() {
|
|
520
|
+
var _context14;
|
|
521
|
+
var _this3;
|
|
522
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
523
|
+
args[_key3] = arguments[_key3];
|
|
524
|
+
}
|
|
525
|
+
_this3 = _Component3.call.apply(_Component3, _concatInstanceProperty(_context14 = [this]).call(_context14, args)) || this;
|
|
526
|
+
_this3.Select = Select;
|
|
527
|
+
_this3.Option = Option;
|
|
528
|
+
return _this3;
|
|
529
|
+
}
|
|
530
|
+
Demo.defaults = function defaults() {
|
|
531
|
+
return {
|
|
532
|
+
list: []
|
|
533
|
+
};
|
|
534
|
+
};
|
|
535
|
+
return Demo;
|
|
536
|
+
}(Component);
|
|
537
|
+
Demo.template = "\n const {Select, Option} = this;\n <Select v-model=\"day\" virtual>\n <Option v-for={this.get('list')} value={$value}>\n {$value}\n </Option>\n </Select>\n ";
|
|
538
|
+
_mount13 = mount(Demo), instance = _mount13[0], element = _mount13[1];
|
|
539
|
+
_context15.next = 5;
|
|
540
|
+
return wait();
|
|
541
|
+
case 5:
|
|
542
|
+
// simulate async data loading
|
|
543
|
+
instance.set('list', _Array$from({
|
|
544
|
+
length: 100
|
|
545
|
+
}, function (_, i) {
|
|
546
|
+
return i;
|
|
547
|
+
}));
|
|
548
|
+
_context15.next = 8;
|
|
549
|
+
return wait(100);
|
|
550
|
+
case 8:
|
|
551
|
+
element.click();
|
|
552
|
+
_context15.next = 11;
|
|
553
|
+
return wait();
|
|
554
|
+
case 11:
|
|
555
|
+
wrapper = getElement('.k-virtual-wrapper');
|
|
556
|
+
phantom = getElement('.k-virtual-phantom');
|
|
557
|
+
expect(wrapper.children.length).to.be.equal(10);
|
|
558
|
+
expect(phantom.style.height).to.be.equal('3000px');
|
|
559
|
+
case 15:
|
|
560
|
+
case "end":
|
|
561
|
+
return _context15.stop();
|
|
562
|
+
}
|
|
563
|
+
}, _callee12);
|
|
564
|
+
})));
|
|
511
565
|
// it('should trigger change event correctly', async () => {
|
|
512
566
|
// const spy = sinon.spy();
|
|
513
567
|
// class Demo extends Component {
|
|
@@ -106,6 +106,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
106
106
|
getAllStatus = _this$checked.getAllStatus,
|
|
107
107
|
onChangeChecked = _this$checked.onChangeChecked;
|
|
108
108
|
var allCheckedStatus = getAllCheckedStatus();
|
|
109
|
+
var allStatus = getAllStatus();
|
|
109
110
|
var thead = hideHeader ? null : _$cc(TableContext.Provider, {
|
|
110
111
|
'value': {
|
|
111
112
|
checkType: checkType,
|
|
@@ -140,7 +141,9 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
140
141
|
'value': allCheckedStatus === AllCheckedStatus.All,
|
|
141
142
|
'indeterminate': showIndeterminate && allCheckedStatus == AllCheckedStatus.Indeterminate,
|
|
142
143
|
'ev-$change:value': toggleCheckedAll,
|
|
143
|
-
'disabled': !hasData
|
|
144
|
+
'disabled': !hasData || allStatus.every(function (_it) {
|
|
145
|
+
return _it.disabled;
|
|
146
|
+
})
|
|
144
147
|
}) : undefined) : undefined, $value];
|
|
145
148
|
return animation[1] ? _$cc(TransitionGroup, {
|
|
146
149
|
'name': 'k-fade-expand',
|
|
@@ -156,7 +159,6 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
156
159
|
});
|
|
157
160
|
var getAllKeys = this.disableRow.getAllKeys;
|
|
158
161
|
var getGrid = this.merge.getGrid;
|
|
159
|
-
var allStatus = getAllStatus();
|
|
160
162
|
var allKeys = getAllKeys();
|
|
161
163
|
var colCount = maxCols + (checkType !== 'none' ? 1 : 0);
|
|
162
164
|
var isExpanded = this.expandable.isExpanded;
|
|
@@ -2,6 +2,7 @@ import _Set from "@babel/runtime-corejs3/core-js/set";
|
|
|
2
2
|
import _Array$from from "@babel/runtime-corejs3/core-js/array/from";
|
|
3
3
|
import { useInstance } from 'intact-vue-next';
|
|
4
4
|
import { useReceive } from '../../hooks/useReceive';
|
|
5
|
+
import { isEqualArray } from '../utils';
|
|
5
6
|
export function useChecked(getNodes) {
|
|
6
7
|
var instance = useInstance();
|
|
7
8
|
var checkedKeys = new _Set();
|
|
@@ -32,9 +33,7 @@ export function useChecked(getNodes) {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
node.checked = checked;
|
|
35
|
-
|
|
36
|
-
node.indeterminate = false;
|
|
37
|
-
}
|
|
36
|
+
node.indeterminate = false;
|
|
38
37
|
if (shouldUpdateCheckedKeys) {
|
|
39
38
|
updateCheckedKeys(node);
|
|
40
39
|
}
|
|
@@ -47,6 +46,13 @@ export function useChecked(getNodes) {
|
|
|
47
46
|
needRecheckNodes.forEach(function (node) {
|
|
48
47
|
updateUpward(node);
|
|
49
48
|
});
|
|
49
|
+
if (instance.get('checkbox')) {
|
|
50
|
+
var oldCheckedKeys = instance.get('checkedKeys');
|
|
51
|
+
var newCheckedKeys = _Array$from(checkedKeys);
|
|
52
|
+
if (!isEqualArray(oldCheckedKeys, newCheckedKeys)) {
|
|
53
|
+
instance.set('checkedKeys', newCheckedKeys);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
function updateCheckedKeys(node) {
|
|
52
58
|
if (node.checked) {
|
|
@@ -56,7 +62,7 @@ export function useChecked(getNodes) {
|
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
function toggle(node) {
|
|
59
|
-
|
|
65
|
+
// const uncorrelated = instance.get('uncorrelated');
|
|
60
66
|
updateDownward(node, !node.checked);
|
|
61
67
|
updateUpward(node.parent);
|
|
62
68
|
instance.set('checkedKeys', _Array$from(checkedKeys));
|
|
@@ -15,7 +15,7 @@ describe('TreeSelect', function () {
|
|
|
15
15
|
return unmount();
|
|
16
16
|
});
|
|
17
17
|
it('should select value correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
18
|
-
var _mount, instance, element, dropdown;
|
|
18
|
+
var _mount, instance, element, dropdown, texts, text1, text111;
|
|
19
19
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
20
|
while (1) switch (_context.prev = _context.next) {
|
|
21
21
|
case 0:
|
|
@@ -26,13 +26,28 @@ describe('TreeSelect', function () {
|
|
|
26
26
|
case 4:
|
|
27
27
|
dropdown = getElement('.k-tree-select-menu');
|
|
28
28
|
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
29
|
-
dropdown.
|
|
29
|
+
texts = dropdown.querySelectorAll('.k-tree-text');
|
|
30
|
+
text1 = texts[0];
|
|
31
|
+
text111 = texts[2];
|
|
32
|
+
text1.click();
|
|
33
|
+
_context.next = 12;
|
|
34
|
+
return wait();
|
|
35
|
+
case 12:
|
|
30
36
|
expect(instance.get('value')).to.eql('1');
|
|
31
|
-
_context.next =
|
|
37
|
+
_context.next = 15;
|
|
32
38
|
return wait(500);
|
|
33
|
-
case
|
|
39
|
+
case 15:
|
|
40
|
+
element.click();
|
|
41
|
+
text111.click();
|
|
42
|
+
_context.next = 19;
|
|
43
|
+
return wait();
|
|
44
|
+
case 19:
|
|
45
|
+
expect(instance.get('value')).to.eql('1.1.1');
|
|
46
|
+
_context.next = 22;
|
|
47
|
+
return wait(500);
|
|
48
|
+
case 22:
|
|
34
49
|
expect(getElement('.k-tree-select-menu')).to.be.undefined;
|
|
35
|
-
case
|
|
50
|
+
case 23:
|
|
36
51
|
case "end":
|
|
37
52
|
return _context.stop();
|
|
38
53
|
}
|
|
@@ -168,4 +183,66 @@ describe('TreeSelect', function () {
|
|
|
168
183
|
}
|
|
169
184
|
}, _callee5);
|
|
170
185
|
})));
|
|
186
|
+
it('should handle parent node correctly when all children are checked initially', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
187
|
+
var _mount6, instance, element, dropdown, parentCheckboxes;
|
|
188
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context7) {
|
|
189
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
190
|
+
case 0:
|
|
191
|
+
_mount6 = mount(CheckboxDemo), instance = _mount6[0], element = _mount6[1]; // init values
|
|
192
|
+
instance.set('values', ['2.1.1', '2.1.2']);
|
|
193
|
+
_context7.next = 4;
|
|
194
|
+
return wait();
|
|
195
|
+
case 4:
|
|
196
|
+
// because 2.2 is disabled, so it will select the outermost parent node 2
|
|
197
|
+
expect(instance.get('values')).to.eql(['2']);
|
|
198
|
+
element.click();
|
|
199
|
+
_context7.next = 8;
|
|
200
|
+
return wait();
|
|
201
|
+
case 8:
|
|
202
|
+
dropdown = getElement('.k-tree-select-menu'); // verify parent node is selected
|
|
203
|
+
parentCheckboxes = dropdown.querySelectorAll('.k-checkbox');
|
|
204
|
+
expect(parentCheckboxes[3].classList.contains('k-checked')).to.be.true; // First floor-2
|
|
205
|
+
expect(parentCheckboxes[4].classList.contains('k-checked')).to.be.true; // Second floor-2.1
|
|
206
|
+
case 12:
|
|
207
|
+
case "end":
|
|
208
|
+
return _context7.stop();
|
|
209
|
+
}
|
|
210
|
+
}, _callee6);
|
|
211
|
+
})));
|
|
212
|
+
it('should clear parent node state when setting values to empty array', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
213
|
+
var _mount7, instance, element, dropdown, checkboxes;
|
|
214
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context8) {
|
|
215
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
216
|
+
case 0:
|
|
217
|
+
_mount7 = mount(CheckboxDemo), instance = _mount7[0], element = _mount7[1]; // select a parent node first
|
|
218
|
+
instance.set('values', ['2.1.1']);
|
|
219
|
+
_context8.next = 4;
|
|
220
|
+
return wait();
|
|
221
|
+
case 4:
|
|
222
|
+
element.click();
|
|
223
|
+
_context8.next = 7;
|
|
224
|
+
return wait();
|
|
225
|
+
case 7:
|
|
226
|
+
dropdown = getElement('.k-tree-select-menu'); // verify related nodes are selected
|
|
227
|
+
checkboxes = dropdown.querySelectorAll('.k-checkbox');
|
|
228
|
+
expect(checkboxes[3].classList.contains('k-indeterminate')).to.be.true; // First floor-2
|
|
229
|
+
expect(checkboxes[4].classList.contains('k-indeterminate')).to.be.true; // Second floor-2.1
|
|
230
|
+
expect(checkboxes[5].classList.contains('k-checkbox')).to.be.true; // Third floor-2.1.1
|
|
231
|
+
// expect(checkboxes[6].classList.contains('k-checked')).to.be.true; // Third floor-2.1.2
|
|
232
|
+
// set to empty array
|
|
233
|
+
instance.set('values', []);
|
|
234
|
+
_context8.next = 15;
|
|
235
|
+
return wait();
|
|
236
|
+
case 15:
|
|
237
|
+
// verify all nodes are cleared selected state
|
|
238
|
+
checkboxes.forEach(function (checkbox) {
|
|
239
|
+
expect(checkbox.classList.contains('k-checked')).to.be.false;
|
|
240
|
+
expect(checkbox.classList.contains('k-indeterminate')).to.be.false;
|
|
241
|
+
});
|
|
242
|
+
case 16:
|
|
243
|
+
case "end":
|
|
244
|
+
return _context8.stop();
|
|
245
|
+
}
|
|
246
|
+
}, _callee7);
|
|
247
|
+
})));
|
|
171
248
|
});
|
|
@@ -4,6 +4,6 @@ export declare function useValue(): {
|
|
|
4
4
|
selectedKeys: import("../../hooks/useState").State<Key[]>;
|
|
5
5
|
checkedKeys: import("../../hooks/useState").State<Key[]>;
|
|
6
6
|
treeRef: import('intact-vue-next').RefObject<Tree<Key>>;
|
|
7
|
-
onChangeCheckedKeys: () => void;
|
|
7
|
+
onChangeCheckedKeys: (allKeys: Key[]) => void;
|
|
8
8
|
onChangeSelectedKeys: (keys: Key[]) => void;
|
|
9
9
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useInstance, createRef } from 'intact-vue-next';
|
|
2
2
|
import { useState } from '../../hooks/useState';
|
|
3
3
|
import { isNullOrUndefined } from 'intact-shared';
|
|
4
|
+
import { isEqualArray } from '../utils';
|
|
4
5
|
export function useValue() {
|
|
5
6
|
var instance = useInstance();
|
|
6
7
|
var selectedKeys = useState([]);
|
|
@@ -16,10 +17,12 @@ export function useValue() {
|
|
|
16
17
|
selectedKeys.set(v);
|
|
17
18
|
checkedKeys.set(v);
|
|
18
19
|
}
|
|
19
|
-
function onChangeCheckedKeys() {
|
|
20
|
+
function onChangeCheckedKeys(allKeys) {
|
|
21
|
+
checkedKeys.set(allKeys);
|
|
20
22
|
var keys = getAllCheckedKeys();
|
|
21
|
-
instance.
|
|
22
|
-
|
|
23
|
+
if (!isEqualArray(keys, instance.get('value'))) {
|
|
24
|
+
instance.set('value', keys);
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
function getAllCheckedKeys() {
|
|
25
28
|
// if the parent has been checked, ignore the children
|
|
@@ -21,13 +21,16 @@ describe('VirtualList', function () {
|
|
|
21
21
|
case 0:
|
|
22
22
|
_mount = mount(BasicDemo), instance = _mount[0], element = _mount[1]; // check basic structure
|
|
23
23
|
container = element.querySelector('.k-virtual-container');
|
|
24
|
+
_context.next = 4;
|
|
25
|
+
return wait();
|
|
26
|
+
case 4:
|
|
24
27
|
expect(container.outerHTML).to.matchSnapshot();
|
|
25
28
|
wrapper = element.querySelector('.k-virtual-wrapper');
|
|
26
29
|
expect(wrapper).to.exist;
|
|
27
30
|
// check render items is less than total
|
|
28
31
|
items = wrapper.children;
|
|
29
32
|
expect(items.length).to.be.lessThan(100);
|
|
30
|
-
case
|
|
33
|
+
case 9:
|
|
31
34
|
case "end":
|
|
32
35
|
return _context.stop();
|
|
33
36
|
}
|
|
@@ -369,4 +372,200 @@ describe('VirtualList', function () {
|
|
|
369
372
|
}
|
|
370
373
|
}, _callee8);
|
|
371
374
|
})));
|
|
375
|
+
it('should handle async data correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
376
|
+
var AsyncDemo, _mount9, instance, container, wrapper, phantom;
|
|
377
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context16) {
|
|
378
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
379
|
+
case 0:
|
|
380
|
+
AsyncDemo = /*#__PURE__*/function (_Component5) {
|
|
381
|
+
_inheritsLoose(AsyncDemo, _Component5);
|
|
382
|
+
function AsyncDemo() {
|
|
383
|
+
var _context15;
|
|
384
|
+
var _this5;
|
|
385
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
386
|
+
args[_key5] = arguments[_key5];
|
|
387
|
+
}
|
|
388
|
+
_this5 = _Component5.call.apply(_Component5, _concatInstanceProperty(_context15 = [this]).call(_context15, args)) || this;
|
|
389
|
+
_this5.VirtualList = VirtualList;
|
|
390
|
+
return _this5;
|
|
391
|
+
}
|
|
392
|
+
AsyncDemo.defaults = function defaults() {
|
|
393
|
+
return {
|
|
394
|
+
list: []
|
|
395
|
+
};
|
|
396
|
+
};
|
|
397
|
+
return AsyncDemo;
|
|
398
|
+
}(Component);
|
|
399
|
+
AsyncDemo.template = "\n const VirtualList = this.VirtualList;\n <VirtualList style=\"height: 300px\">\n <div v-for={this.get('list')} key={$value}>Item {$value}</div>\n </VirtualList>\n ";
|
|
400
|
+
_mount9 = mount(AsyncDemo), instance = _mount9[0];
|
|
401
|
+
_context16.next = 5;
|
|
402
|
+
return wait();
|
|
403
|
+
case 5:
|
|
404
|
+
container = getElement('.k-virtual-container');
|
|
405
|
+
wrapper = getElement('.k-virtual-wrapper');
|
|
406
|
+
phantom = getElement('.k-virtual-phantom'); // check initial state
|
|
407
|
+
expect(wrapper.children.length).to.equal(0);
|
|
408
|
+
expect(phantom.style.height).to.equal('0px');
|
|
409
|
+
// simulate async data loading
|
|
410
|
+
instance.set('list', _Array$from({
|
|
411
|
+
length: 100
|
|
412
|
+
}, function (_, i) {
|
|
413
|
+
return i;
|
|
414
|
+
}));
|
|
415
|
+
_context16.next = 13;
|
|
416
|
+
return wait(50);
|
|
417
|
+
case 13:
|
|
418
|
+
expect(wrapper.children.length).to.be.equal(23);
|
|
419
|
+
expect(phantom.style.height).to.be.equal('1800px');
|
|
420
|
+
// check render content
|
|
421
|
+
expect(wrapper.firstElementChild.textContent).to.equal('Item 0');
|
|
422
|
+
case 16:
|
|
423
|
+
case "end":
|
|
424
|
+
return _context16.stop();
|
|
425
|
+
}
|
|
426
|
+
}, _callee9);
|
|
427
|
+
})));
|
|
428
|
+
it('should handle empty data and re-adding data correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
429
|
+
var EmptyDemo, _mount10, instance, container, wrapper, phantom, initialHeight, initialChildrenCount;
|
|
430
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context18) {
|
|
431
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
432
|
+
case 0:
|
|
433
|
+
EmptyDemo = /*#__PURE__*/function (_Component6) {
|
|
434
|
+
_inheritsLoose(EmptyDemo, _Component6);
|
|
435
|
+
function EmptyDemo() {
|
|
436
|
+
var _context17;
|
|
437
|
+
var _this6;
|
|
438
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
439
|
+
args[_key6] = arguments[_key6];
|
|
440
|
+
}
|
|
441
|
+
_this6 = _Component6.call.apply(_Component6, _concatInstanceProperty(_context17 = [this]).call(_context17, args)) || this;
|
|
442
|
+
_this6.VirtualList = VirtualList;
|
|
443
|
+
return _this6;
|
|
444
|
+
}
|
|
445
|
+
EmptyDemo.defaults = function defaults() {
|
|
446
|
+
return {
|
|
447
|
+
list: _Array$from({
|
|
448
|
+
length: 100
|
|
449
|
+
}, function (_, i) {
|
|
450
|
+
return i;
|
|
451
|
+
})
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
return EmptyDemo;
|
|
455
|
+
}(Component);
|
|
456
|
+
EmptyDemo.template = "\n const VirtualList = this.VirtualList;\n <VirtualList style=\"height: 300px\">\n <div v-for={this.get('list')} key={$value}>Item {$value}</div>\n </VirtualList>\n ";
|
|
457
|
+
_mount10 = mount(EmptyDemo), instance = _mount10[0];
|
|
458
|
+
_context18.next = 5;
|
|
459
|
+
return wait();
|
|
460
|
+
case 5:
|
|
461
|
+
container = getElement('.k-virtual-container');
|
|
462
|
+
wrapper = getElement('.k-virtual-wrapper');
|
|
463
|
+
phantom = getElement('.k-virtual-phantom'); // record initial state
|
|
464
|
+
initialHeight = phantom.style.height;
|
|
465
|
+
initialChildrenCount = wrapper.children.length; // clear data
|
|
466
|
+
instance.set('list', []);
|
|
467
|
+
_context18.next = 13;
|
|
468
|
+
return wait(50);
|
|
469
|
+
case 13:
|
|
470
|
+
// check empty state
|
|
471
|
+
expect(wrapper.children.length).to.equal(0);
|
|
472
|
+
expect(phantom.style.height).to.equal('0px');
|
|
473
|
+
// re-add data
|
|
474
|
+
instance.set('list', _Array$from({
|
|
475
|
+
length: 50
|
|
476
|
+
}, function (_, i) {
|
|
477
|
+
return i;
|
|
478
|
+
}));
|
|
479
|
+
_context18.next = 18;
|
|
480
|
+
return wait(50);
|
|
481
|
+
case 18:
|
|
482
|
+
// check re-add data state
|
|
483
|
+
expect(wrapper.children.length).to.be.equal(23);
|
|
484
|
+
expect(parseInt(phantom.style.height)).to.be.equal(900);
|
|
485
|
+
expect(wrapper.firstElementChild.textContent).to.equal('Item 0');
|
|
486
|
+
// 滚动测试
|
|
487
|
+
// container.scrollTop = 100;
|
|
488
|
+
// await wait(50);
|
|
489
|
+
// // 检查滚动后的渲染是否正确
|
|
490
|
+
// expect(wrapper.firstElementChild!.textContent).to.not.equal('Item 0');
|
|
491
|
+
case 21:
|
|
492
|
+
case "end":
|
|
493
|
+
return _context18.stop();
|
|
494
|
+
}
|
|
495
|
+
}, _callee10);
|
|
496
|
+
})));
|
|
497
|
+
it('should handle extreme height differences correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
|
|
498
|
+
var ExtremeHeightDemo, _mount11, instance, container, wrapper, phantom, initialItems, initialLength, firstItem, initialTotalHeight, initialAvgHeight, newItems, newLength, firstNewItem, firstVisibleIndex, finalItems, finalFirstItem;
|
|
499
|
+
return _regeneratorRuntime.wrap(function _callee11$(_context20) {
|
|
500
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
501
|
+
case 0:
|
|
502
|
+
ExtremeHeightDemo = /*#__PURE__*/function (_Component7) {
|
|
503
|
+
_inheritsLoose(ExtremeHeightDemo, _Component7);
|
|
504
|
+
function ExtremeHeightDemo() {
|
|
505
|
+
var _context19;
|
|
506
|
+
var _this7;
|
|
507
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
508
|
+
args[_key7] = arguments[_key7];
|
|
509
|
+
}
|
|
510
|
+
_this7 = _Component7.call.apply(_Component7, _concatInstanceProperty(_context19 = [this]).call(_context19, args)) || this;
|
|
511
|
+
_this7.VirtualList = VirtualList;
|
|
512
|
+
return _this7;
|
|
513
|
+
}
|
|
514
|
+
ExtremeHeightDemo.defaults = function defaults() {
|
|
515
|
+
return {
|
|
516
|
+
list: _Array$from({
|
|
517
|
+
length: 100
|
|
518
|
+
}, function (_, i) {
|
|
519
|
+
return i;
|
|
520
|
+
})
|
|
521
|
+
};
|
|
522
|
+
};
|
|
523
|
+
return ExtremeHeightDemo;
|
|
524
|
+
}(Component);
|
|
525
|
+
ExtremeHeightDemo.template = "\n const VirtualList = this.VirtualList;\n <VirtualList style=\"height: 300px\">\n <div v-for={this.get('list')} \n key={$value} \n style={$value < 5 ? 'height: 100px' : 'height: 30px'}\n >\n Item {$value}\n </div>\n </VirtualList>\n ";
|
|
526
|
+
_mount11 = mount(ExtremeHeightDemo), instance = _mount11[0];
|
|
527
|
+
_context20.next = 5;
|
|
528
|
+
return wait();
|
|
529
|
+
case 5:
|
|
530
|
+
container = getElement('.k-virtual-container');
|
|
531
|
+
wrapper = getElement('.k-virtual-wrapper');
|
|
532
|
+
phantom = getElement('.k-virtual-phantom');
|
|
533
|
+
initialItems = wrapper.children;
|
|
534
|
+
initialLength = initialItems.length; // check first 5 elements height
|
|
535
|
+
firstItem = initialItems[0];
|
|
536
|
+
expect(firstItem.offsetHeight).to.equal(100);
|
|
537
|
+
// record initial average height (calculate by total height and render count)
|
|
538
|
+
initialTotalHeight = parseInt(phantom.style.height);
|
|
539
|
+
initialAvgHeight = initialTotalHeight / 100;
|
|
540
|
+
expect(initialAvgHeight).to.be.greaterThan(30);
|
|
541
|
+
// scroll to small height area
|
|
542
|
+
container.scrollTop = 800;
|
|
543
|
+
_context20.next = 18;
|
|
544
|
+
return wait(50);
|
|
545
|
+
case 18:
|
|
546
|
+
// check new render elements
|
|
547
|
+
newItems = wrapper.children;
|
|
548
|
+
newLength = newItems.length;
|
|
549
|
+
firstNewItem = newItems[0]; // check
|
|
550
|
+
// new render elements should be 30px height
|
|
551
|
+
expect(firstNewItem.offsetHeight).to.equal(30);
|
|
552
|
+
// because average height is smaller, render elements count should be more
|
|
553
|
+
expect(newLength).to.be.greaterThan(initialLength);
|
|
554
|
+
// check scroll position is correct
|
|
555
|
+
firstVisibleIndex = parseInt(firstNewItem.textContent.replace('Item ', ''));
|
|
556
|
+
expect(firstVisibleIndex).to.be.greaterThan(5);
|
|
557
|
+
container.scrollTop = 1200;
|
|
558
|
+
_context20.next = 28;
|
|
559
|
+
return wait();
|
|
560
|
+
case 28:
|
|
561
|
+
finalItems = wrapper.children;
|
|
562
|
+
finalFirstItem = finalItems[0];
|
|
563
|
+
expect(finalFirstItem.offsetHeight).to.equal(30);
|
|
564
|
+
expect(finalItems.length).to.equal(newLength); // render count should be stable
|
|
565
|
+
case 32:
|
|
566
|
+
case "end":
|
|
567
|
+
return _context20.stop();
|
|
568
|
+
}
|
|
569
|
+
}, _callee11);
|
|
570
|
+
})));
|
|
372
571
|
});
|
|
@@ -19,10 +19,11 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
19
19
|
disabled = _ref.disabled;
|
|
20
20
|
if (!disabled) {
|
|
21
21
|
var _context;
|
|
22
|
-
_children = _sliceInstanceProperty(_context = rows.value).call(_context, startIndex, startIndex + length);
|
|
23
22
|
notifyRows(rows.value);
|
|
23
|
+
_children = _sliceInstanceProperty(_context = rows.value).call(_context, startIndex, startIndex + length);
|
|
24
24
|
}
|
|
25
25
|
if (isNullOrUndefined(tagName)) {
|
|
26
|
+
if (!_children.length) return;
|
|
26
27
|
return createFragment(_children, 8 /* ChildrenTypes.HasKeyedChildren */);
|
|
27
28
|
}
|
|
28
29
|
return createVNode(tagName, null, _children);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useInstance, createRef, createFragment } from 'intact-vue-next';
|
|
1
|
+
import { useInstance, createRef, createFragment, isText } from 'intact-vue-next';
|
|
2
2
|
export function useRows() {
|
|
3
3
|
var instance = useInstance();
|
|
4
4
|
var rows = createRef([]);
|
|
@@ -8,11 +8,24 @@ export function useRows() {
|
|
|
8
8
|
// convert to array if it has only one child
|
|
9
9
|
var childrenType = vNode.childrenType;
|
|
10
10
|
if (childrenType & 2 /* ChildrenTypes.HasVNodeChildren */) {
|
|
11
|
-
|
|
11
|
+
var _children = vNode.children;
|
|
12
|
+
if (isText(_children)) {
|
|
13
|
+
// ignore void and text vnode
|
|
14
|
+
rows.value = [];
|
|
15
|
+
} else {
|
|
16
|
+
rows.value = [_children];
|
|
17
|
+
}
|
|
12
18
|
} else if (childrenType & 1 /* ChildrenTypes.HasInvalidChildren */) {
|
|
13
19
|
rows.value = [];
|
|
14
20
|
} else {
|
|
15
21
|
rows.value = vNode.children;
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
+
rows.value.forEach(function (row) {
|
|
24
|
+
if (isText(row)) {
|
|
25
|
+
console.warn('VirtualList: Text node can not been used as children.');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
16
29
|
}
|
|
17
30
|
});
|
|
18
31
|
return rows;
|