@king-design/intact 2.0.17-beta.0 → 2.1.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/components/cascader/index.md +18 -0
- package/components/cascader/index.spec.ts +56 -0
- package/components/cascader/index.ts +35 -12
- package/components/cascader/index.vdt +9 -8
- package/components/cascader/useFields.ts +22 -0
- package/components/cascader/useFilterable.ts +23 -8
- package/components/cascader/useLabel.ts +7 -4
- package/components/cascader/useLoad.ts +4 -2
- package/components/code/demos/basic.md +1 -1
- package/components/colorpicker/index.md +16 -0
- package/components/colorpicker/index.ts +4 -0
- package/components/colorpicker/index.vdt +3 -2
- package/components/datepicker/index.md +11 -0
- package/components/dialog/index.spec.ts +2 -2
- package/components/dropdown/dropdown.ts +0 -1
- package/components/dropdown/item.ts +3 -2
- package/components/dropdown/usePosition.ts +9 -1
- package/components/editable/index.ts +17 -3
- package/components/editable/index.vdt +1 -0
- package/components/input/demos/autoRows.md +44 -0
- package/components/input/demos/password.md +12 -0
- package/components/input/demos/textarea.md +2 -2
- package/components/input/index.md +1 -0
- package/components/input/index.spec.ts +97 -1
- package/components/input/index.ts +17 -3
- package/components/input/index.vdt +29 -6
- package/components/input/styles.ts +18 -1
- package/components/input/useAutoRows.ts +65 -0
- package/components/input/useAutoWidth.ts +12 -3
- package/components/input/useShowPassword.ts +27 -0
- package/components/pagination/index.spec.ts +1 -1
- package/components/pagination/index.ts +1 -2
- package/components/portal.ts +4 -4
- package/components/position.ts +5 -1
- package/components/select/base.ts +3 -1
- package/components/select/base.vdt +2 -0
- package/components/select/index.md +11 -1
- package/components/table/cell.ts +4 -5
- package/components/table/demos/hideHeader.md +33 -0
- package/components/table/demos/pagination.md +53 -0
- package/components/table/index.md +22 -0
- package/components/table/index.spec.ts +73 -1
- package/components/table/row.ts +3 -3
- package/components/table/styles.ts +5 -0
- package/components/table/table.ts +29 -4
- package/components/table/table.vdt +21 -3
- package/components/table/useChecked.ts +21 -6
- package/components/table/useDisableRow.ts +3 -2
- package/components/table/useDraggable.ts +11 -8
- package/components/table/useGroup.ts +2 -0
- package/components/table/useMerge.ts +6 -3
- package/components/table/usePagination.ts +71 -0
- package/components/table/useRestRowStatus.ts +4 -1
- package/components/table/useTree.ts +4 -3
- package/components/timepicker/index.md +11 -0
- package/components/tooltip/demos/trigger.md +1 -1
- package/components/tooltip/index.md +1 -1
- package/components/tooltip/index.spec.ts +8 -5
- package/components/treeSelect/index.md +9 -0
- package/es/components/cascader/index.d.ts +22 -11
- package/es/components/cascader/index.js +9 -12
- package/es/components/cascader/index.spec.js +81 -0
- package/es/components/cascader/index.vdt.js +10 -8
- package/es/components/cascader/useFields.d.ts +2 -0
- package/es/components/cascader/useFields.js +18 -0
- package/es/components/cascader/useFilterable.d.ts +2 -1
- package/es/components/cascader/useFilterable.js +17 -6
- package/es/components/cascader/useLabel.d.ts +2 -1
- package/es/components/cascader/useLabel.js +4 -4
- package/es/components/cascader/useLoad.d.ts +2 -1
- package/es/components/cascader/useLoad.js +9 -7
- package/es/components/colorpicker/index.d.ts +2 -0
- package/es/components/colorpicker/index.js +7 -2
- package/es/components/colorpicker/index.vdt.js +3 -6
- package/es/components/dialog/index.spec.js +2 -2
- package/es/components/dropdown/dropdown.js +0 -1
- package/es/components/dropdown/item.js +3 -3
- package/es/components/dropdown/usePosition.js +8 -1
- package/es/components/editable/index.d.ts +1 -0
- package/es/components/editable/index.js +20 -6
- package/es/components/editable/index.vdt.js +2 -1
- package/es/components/input/index.d.ts +10 -2
- package/es/components/input/index.js +10 -3
- package/es/components/input/index.spec.js +169 -1
- package/es/components/input/index.vdt.js +26 -7
- package/es/components/input/styles.js +8 -3
- package/es/components/input/useAutoRows.d.ts +2 -0
- package/es/components/input/useAutoRows.js +79 -0
- package/es/components/input/useAutoWidth.js +13 -3
- package/es/components/input/useShowPassword.d.ts +7 -0
- package/es/components/input/useShowPassword.js +31 -0
- package/es/components/pagination/index.js +1 -3
- package/es/components/pagination/index.spec.js +2 -4
- package/es/components/portal.d.ts +6 -2
- package/es/components/portal.js +4 -3
- package/es/components/position.js +2 -1
- package/es/components/select/base.d.ts +2 -1
- package/es/components/select/base.js +3 -1
- package/es/components/select/base.vdt.js +3 -1
- package/es/components/table/cell.js +1 -6
- package/es/components/table/index.spec.js +130 -19
- package/es/components/table/row.d.ts +1 -1
- package/es/components/table/row.js +2 -1
- package/es/components/table/styles.js +1 -1
- package/es/components/table/table.d.ts +15 -0
- package/es/components/table/table.js +16 -7
- package/es/components/table/table.vdt.js +20 -6
- package/es/components/table/useChecked.d.ts +3 -2
- package/es/components/table/useChecked.js +23 -12
- package/es/components/table/useDisableRow.d.ts +2 -1
- package/es/components/table/useDisableRow.js +4 -4
- package/es/components/table/useDraggable.d.ts +3 -2
- package/es/components/table/useDraggable.js +11 -8
- package/es/components/table/useGroup.js +3 -0
- package/es/components/table/useMerge.d.ts +2 -1
- package/es/components/table/useMerge.js +5 -4
- package/es/components/table/usePagination.d.ts +8 -0
- package/es/components/table/usePagination.js +81 -0
- package/es/components/table/useTree.d.ts +2 -1
- package/es/components/table/useTree.js +3 -4
- package/es/components/tooltip/index.spec.js +9 -10
- package/es/index.d.ts +3 -3
- package/es/index.js +3 -3
- package/es/packages/kpc-react/__tests__/components/cascader.spec.d.ts +1 -0
- package/es/packages/kpc-react/__tests__/components/cascader.spec.js +79 -0
- package/es/site/data/components/dialog/demos/basic/react.js +4 -1
- package/es/site/data/components/input/demos/autoRows/index.d.ts +9 -0
- package/es/site/data/components/input/demos/autoRows/index.js +24 -0
- package/es/site/data/components/input/demos/autoRows/react.d.ts +8 -0
- package/es/site/data/components/input/demos/autoRows/react.js +62 -0
- package/es/site/data/components/input/demos/password/index.d.ts +5 -0
- package/es/site/data/components/input/demos/password/index.js +17 -0
- package/es/site/data/components/input/demos/password/react.d.ts +5 -0
- package/es/site/data/components/input/demos/password/react.js +41 -0
- package/es/site/data/components/input/demos/textarea/react.js +4 -2
- package/es/site/data/components/table/demos/hideHeader/index.d.ts +12 -0
- package/es/site/data/components/table/demos/hideHeader/index.js +30 -0
- package/es/site/data/components/table/demos/hideHeader/react.d.ts +11 -0
- package/es/site/data/components/table/demos/hideHeader/react.js +60 -0
- package/es/site/data/components/table/demos/pagination/index.d.ts +12 -0
- package/es/site/data/components/table/demos/pagination/index.js +35 -0
- package/es/site/data/components/table/demos/pagination/react.d.ts +16 -0
- package/es/site/data/components/table/demos/pagination/react.js +65 -0
- package/es/styles/fonts/ionicons.js +1 -1
- package/index.ts +3 -3
- package/package.json +4 -4
- package/styles/fonts/ionicons.ts +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useInstance, onMounted } from 'intact';
|
|
2
|
+
import { useState } from '../../hooks/useState';
|
|
3
|
+
import { isObject } from 'intact-shared';
|
|
4
|
+
export function useAutoRows(inputRef) {
|
|
5
|
+
var instance = useInstance();
|
|
6
|
+
var height = useState(0);
|
|
7
|
+
var lineHeight;
|
|
8
|
+
var paddingTop;
|
|
9
|
+
var paddingBottom;
|
|
10
|
+
var isBorderBox;
|
|
11
|
+
|
|
12
|
+
function getStyles() {
|
|
13
|
+
if (instance.get('type') === 'textarea') {
|
|
14
|
+
var styles = getComputedStyle(inputRef.value);
|
|
15
|
+
lineHeight = parseInt(styles.lineHeight);
|
|
16
|
+
paddingTop = parseInt(styles.paddingTop);
|
|
17
|
+
paddingBottom = parseInt(styles.paddingBottom);
|
|
18
|
+
isBorderBox = styles.boxSizing === 'border-box';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
onMounted(getStyles);
|
|
23
|
+
instance.watch('type', getStyles, {
|
|
24
|
+
presented: true
|
|
25
|
+
});
|
|
26
|
+
instance.watch('value', adjust, {
|
|
27
|
+
inited: true,
|
|
28
|
+
presented: true
|
|
29
|
+
});
|
|
30
|
+
instance.watch('placeholder', adjust, {
|
|
31
|
+
inited: true,
|
|
32
|
+
presented: true
|
|
33
|
+
});
|
|
34
|
+
instance.watch('rows', adjust, {
|
|
35
|
+
inited: true,
|
|
36
|
+
presented: true
|
|
37
|
+
});
|
|
38
|
+
onMounted(adjust);
|
|
39
|
+
|
|
40
|
+
function adjust() {
|
|
41
|
+
var _instance$get = instance.get(),
|
|
42
|
+
rows = _instance$get.rows,
|
|
43
|
+
type = _instance$get.type;
|
|
44
|
+
|
|
45
|
+
if (type === 'textarea' && (rows === 'auto' || isObject(rows))) {
|
|
46
|
+
var textarea = inputRef.value;
|
|
47
|
+
var originheight = textarea.style.height; // we shuold remove height before get scrollHeight,
|
|
48
|
+
// otherwise we cannot shrink the height when we remove the text
|
|
49
|
+
|
|
50
|
+
textarea.style.height = '';
|
|
51
|
+
var scrollHeight = textarea.scrollHeight;
|
|
52
|
+
var lines = (scrollHeight - paddingTop - paddingBottom) / lineHeight;
|
|
53
|
+
textarea.style.height = originheight;
|
|
54
|
+
var actualLines = lines;
|
|
55
|
+
|
|
56
|
+
if (rows !== 'auto') {
|
|
57
|
+
var min = rows.min,
|
|
58
|
+
max = rows.max;
|
|
59
|
+
|
|
60
|
+
if (min && lines <= min) {
|
|
61
|
+
actualLines = min;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (max && lines >= max) {
|
|
65
|
+
actualLines = max;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
height.set(lineHeight * actualLines + (isBorderBox ? paddingTop + paddingBottom + 2
|
|
70
|
+
/* border */
|
|
71
|
+
: 0));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
height.set(0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return height;
|
|
79
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useInstance, createRef, onMounted } from 'intact';
|
|
1
|
+
import { useInstance, createRef, onMounted, nextTick } from 'intact';
|
|
2
2
|
import { useState } from '../../hooks/useState';
|
|
3
3
|
export function useAutoWidth() {
|
|
4
4
|
var instance = useInstance();
|
|
@@ -16,9 +16,15 @@ export function useAutoWidth() {
|
|
|
16
16
|
|
|
17
17
|
function adjustWidth() {
|
|
18
18
|
if (instance.get('autoWidth')) {
|
|
19
|
-
|
|
19
|
+
nextTick(function () {
|
|
20
|
+
var fakeElem = fakeRef.value;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
if (isVisible(fakeElem)) {
|
|
23
|
+
var _width = fakeElem.offsetWidth || 1;
|
|
24
|
+
|
|
25
|
+
width.set(_width);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
|
|
@@ -26,4 +32,8 @@ export function useAutoWidth() {
|
|
|
26
32
|
fakeRef: fakeRef,
|
|
27
33
|
width: width
|
|
28
34
|
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isVisible(elem) {
|
|
38
|
+
return elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length);
|
|
29
39
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HTMLInputTypes } from './';
|
|
2
|
+
export declare function useShowPassword(): {
|
|
3
|
+
isShow: import("../../hooks/useState").State<boolean>;
|
|
4
|
+
type: import("../../hooks/useState").State<HTMLInputTypes | undefined>;
|
|
5
|
+
toggleShow: () => void;
|
|
6
|
+
showIcon: import("../../hooks/useState").State<boolean>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useInstance } from 'intact';
|
|
2
|
+
import { useState } from '../../hooks/useState';
|
|
3
|
+
import { useReceive } from '../../hooks/useReceive';
|
|
4
|
+
export function useShowPassword() {
|
|
5
|
+
var instance = useInstance();
|
|
6
|
+
var isShow = useState(false);
|
|
7
|
+
var type = useState(undefined);
|
|
8
|
+
var showIcon = useState(false);
|
|
9
|
+
instance.on('$receive:type', function (_type) {
|
|
10
|
+
type.set(_type);
|
|
11
|
+
});
|
|
12
|
+
useReceive(['type', 'showPassword'], function () {
|
|
13
|
+
var _instance$get = instance.get(),
|
|
14
|
+
showPassword = _instance$get.showPassword,
|
|
15
|
+
type = _instance$get.type;
|
|
16
|
+
|
|
17
|
+
showIcon.set(type === 'password' && !!showPassword);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function toggleShow() {
|
|
21
|
+
isShow.set(!isShow.value);
|
|
22
|
+
type.set(isShow.value ? 'text' : 'password');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
isShow: isShow,
|
|
27
|
+
type: type,
|
|
28
|
+
toggleShow: toggleShow,
|
|
29
|
+
showIcon: showIcon
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -4,11 +4,9 @@ import BasicDemo from '~/components/pagination/demos/basic';
|
|
|
4
4
|
import GotoDemo from '~/components/pagination/demos/goto';
|
|
5
5
|
import CurrentDemo from '~/components/pagination/demos/current';
|
|
6
6
|
import DisableDemo from '~/components/pagination/demos/disable';
|
|
7
|
-
import { mount,
|
|
7
|
+
import { mount, dispatchEvent, wait } from '../../test/utils';
|
|
8
8
|
describe('Pagination', function () {
|
|
9
|
-
afterEach(
|
|
10
|
-
return unmount();
|
|
11
|
-
});
|
|
9
|
+
// afterEach(() => unmount());
|
|
12
10
|
it('basic test', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
13
11
|
var _mount, instance, element, pagination, btns, prev, next;
|
|
14
12
|
|
|
@@ -11,8 +11,12 @@ export declare class Portal<T extends PortalProps = PortalProps> extends Compone
|
|
|
11
11
|
mountedQueue?: Function[];
|
|
12
12
|
mountedDone?: boolean;
|
|
13
13
|
$isPortal: boolean;
|
|
14
|
-
$render(lastVNode: VNodeComponentClass<this> | null, nextVNode: VNodeComponentClass<this>, parentDom: Element, anchor: IntactDom | null, mountedQueue: Function[]
|
|
15
|
-
|
|
14
|
+
$render(lastVNode: VNodeComponentClass<this> | null, nextVNode: VNodeComponentClass<this>, parentDom: Element, anchor: IntactDom | null, mountedQueue: Function[] & {
|
|
15
|
+
priority?: Function[];
|
|
16
|
+
}): void;
|
|
17
|
+
$update(lastVNode: VNodeComponentClass<this>, nextVNode: VNodeComponentClass<this>, parentDom: Element, anchor: IntactDom | null, mountedQueue: Function[] & {
|
|
18
|
+
priority?: Function[];
|
|
19
|
+
}, force: boolean): void;
|
|
16
20
|
$unmount(vNode: VNodeComponentClass<this>, nextVNode: VNodeComponentClass<this> | null): void;
|
|
17
21
|
private initContainer;
|
|
18
22
|
}
|
package/es/components/portal.js
CHANGED
|
@@ -38,7 +38,8 @@ export var Portal = /*#__PURE__*/function (_Component) {
|
|
|
38
38
|
|
|
39
39
|
var _proto = Portal.prototype;
|
|
40
40
|
|
|
41
|
-
_proto.$render = function $render(lastVNode, nextVNode, parentDom, anchor, mountedQueue
|
|
41
|
+
_proto.$render = function $render(lastVNode, nextVNode, parentDom, anchor, mountedQueue // in React, it has priority property to add some prior functions
|
|
42
|
+
) {
|
|
42
43
|
var _this2 = this;
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -47,7 +48,7 @@ export var Portal = /*#__PURE__*/function (_Component) {
|
|
|
47
48
|
*/
|
|
48
49
|
var nextProps = nextVNode.props;
|
|
49
50
|
var fakeContainer = document.createDocumentFragment();
|
|
50
|
-
mountedQueue.push(function () {
|
|
51
|
+
(mountedQueue.priority || mountedQueue).push(function () {
|
|
51
52
|
var parentDom = _this2.$lastInput.dom.parentElement;
|
|
52
53
|
|
|
53
54
|
_this2.initContainer(nextProps.container, parentDom, anchor);
|
|
@@ -87,7 +88,7 @@ export var Portal = /*#__PURE__*/function (_Component) {
|
|
|
87
88
|
|
|
88
89
|
if (!this.container) {
|
|
89
90
|
// in react, sometimes $update will be called before mountedQueue in $render
|
|
90
|
-
mountedQueue.push(update);
|
|
91
|
+
(mountedQueue.priority || mountedQueue).push(update);
|
|
91
92
|
} else {
|
|
92
93
|
update();
|
|
93
94
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _Object$assign from "@babel/runtime-corejs3/core-js/object/assign";
|
|
2
2
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
3
3
|
import _atInstanceProperty from "@babel/runtime-corejs3/core-js/instance/at";
|
|
4
|
+
import { isArray } from 'intact-shared';
|
|
4
5
|
var max = Math.max;
|
|
5
6
|
var abs = Math.abs;
|
|
6
7
|
var rHorizontal = /left|center|right/;
|
|
@@ -191,7 +192,7 @@ export default function position(elem, options) {
|
|
|
191
192
|
var basePosition = _Object$assign({}, targetOffset); // don't detect collison if the target is not in viewport
|
|
192
193
|
|
|
193
194
|
|
|
194
|
-
var collision = isInViewport(targetRect) ? (options.collision || 'flip').split(' ') : ['none', 'none'];
|
|
195
|
+
var collision = isInViewport(targetRect) ? !isArray(options.collision) ? (options.collision || 'flip').split(' ') : options.collision : ['none', 'none'];
|
|
195
196
|
var offsets = {};
|
|
196
197
|
var within = getWithinInfo(options.within);
|
|
197
198
|
var scrollInfo = getScrollInfo(within);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Component, Children, TypeDefs, RefObject } from 'intact';
|
|
2
2
|
import { Sizes } from '../../styles/utils';
|
|
3
3
|
import type { Input } from '../input';
|
|
4
|
-
import { Dropdown } from '../dropdown';
|
|
4
|
+
import { Dropdown, DropdownProps } from '../dropdown';
|
|
5
5
|
import { State } from '../../hooks/useState';
|
|
6
6
|
import { Container } from '../portal';
|
|
7
7
|
import type { Events } from '../types';
|
|
@@ -21,6 +21,7 @@ export interface BaseSelectProps<V, Multipe extends boolean = boolean, Attach =
|
|
|
21
21
|
container?: Container;
|
|
22
22
|
width?: string | number;
|
|
23
23
|
show?: boolean;
|
|
24
|
+
position?: DropdownProps['position'];
|
|
24
25
|
}
|
|
25
26
|
export interface BaseSelectEvents {
|
|
26
27
|
keydown: [KeyboardEvent];
|
|
@@ -9,6 +9,7 @@ import { sizes } from '../../styles/utils';
|
|
|
9
9
|
import { SELECT } from './constants';
|
|
10
10
|
import { useShowHideEvents } from '../../hooks/useShowHideEvents';
|
|
11
11
|
import { bind } from '../utils';
|
|
12
|
+
import { Dropdown } from '../dropdown';
|
|
12
13
|
import { useInput } from './useInput';
|
|
13
14
|
import { useFocusout } from './useFocusout';
|
|
14
15
|
import { isNullOrUndefined } from 'intact-shared';
|
|
@@ -27,7 +28,8 @@ var typeDefs = {
|
|
|
27
28
|
placeholder: [String, Number],
|
|
28
29
|
container: [Function, String],
|
|
29
30
|
width: [String, Number],
|
|
30
|
-
show: Boolean
|
|
31
|
+
show: Boolean,
|
|
32
|
+
position: Dropdown.typeDefs.position
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
var defaults = function defaults() {
|
|
@@ -40,7 +40,8 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
40
40
|
inline = _this$get.inline,
|
|
41
41
|
style = _this$get.style,
|
|
42
42
|
width = _this$get.width,
|
|
43
|
-
show = _this$get.show
|
|
43
|
+
show = _this$get.show,
|
|
44
|
+
position = _this$get.position;
|
|
44
45
|
|
|
45
46
|
var classNameObj = (_classNameObj = {
|
|
46
47
|
'k-select': true,
|
|
@@ -67,6 +68,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
67
68
|
'ref': _this.dropdownRef,
|
|
68
69
|
'disabled': disabled,
|
|
69
70
|
'container': container,
|
|
71
|
+
'position': position,
|
|
70
72
|
'children': [_$cv('div', _extends({}, getRestProps(_this), {
|
|
71
73
|
'className': _$cn(classNameObj),
|
|
72
74
|
'tabindex': disabled ? '-1' : '0',
|
|
@@ -16,12 +16,7 @@ export var TableCell = /*#__PURE__*/function (_Component) {
|
|
|
16
16
|
var isSame = true;
|
|
17
17
|
|
|
18
18
|
for (var key in lastProps) {
|
|
19
|
-
if (lastProps[key] !== nextProps[key]) {
|
|
20
|
-
isSame = false;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (key === 'props' && nextProps.props.$blocks) {
|
|
19
|
+
if (lastProps[key] !== nextProps[key] || key === 'props' && nextProps.props.$blocks) {
|
|
25
20
|
isSame = false;
|
|
26
21
|
break;
|
|
27
22
|
}
|
|
@@ -23,13 +23,14 @@ import { Table, TableColumn } from './';
|
|
|
23
23
|
import DraggableTable from '~/components/table/demos/draggable';
|
|
24
24
|
import MergeCellDemo from '~/components/table/demos/mergeCell';
|
|
25
25
|
import { AllCheckedStatus } from './useChecked';
|
|
26
|
+
import PaginationDemo from '~/components/table/demos/pagination';
|
|
26
27
|
describe('Table', function () {
|
|
27
28
|
afterEach(function () {
|
|
28
29
|
unmount();
|
|
29
30
|
localStorage.removeItem('resizableTable');
|
|
30
31
|
});
|
|
31
32
|
it('check & uncheck', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
32
|
-
var _mount, instance, element, table, checked, spy, _element$querySelecto, tr1, tr2, all;
|
|
33
|
+
var _mount, instance, element, table, checked, spy, spyCheckRow, spyUncheckRow, spyCheckAll, spyUncheckAll, _element$querySelecto, tr1, tr2, all;
|
|
33
34
|
|
|
34
35
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
36
|
while (1) {
|
|
@@ -42,54 +43,76 @@ describe('Table', function () {
|
|
|
42
43
|
spy = sinon.spy(function (v) {
|
|
43
44
|
return console.log(v);
|
|
44
45
|
});
|
|
45
|
-
table.on('$change:checkedKeys', spy);
|
|
46
|
+
table.on('$change:checkedKeys', spy);
|
|
47
|
+
spyCheckRow = sinon.spy(function (data, index, key) {
|
|
48
|
+
return console.log('checkRow', data, index, key);
|
|
49
|
+
});
|
|
50
|
+
table.on('checkRow', spyCheckRow);
|
|
51
|
+
spyUncheckRow = sinon.spy(function (data, index, key) {
|
|
52
|
+
return console.log('uncheckRow', data, index, key);
|
|
53
|
+
});
|
|
54
|
+
table.on('uncheckRow', spyUncheckRow);
|
|
55
|
+
spyCheckAll = sinon.spy(function () {
|
|
56
|
+
return console.log('checkAll');
|
|
57
|
+
});
|
|
58
|
+
table.on('checkAll', spyCheckAll);
|
|
59
|
+
spyUncheckAll = sinon.spy(function () {
|
|
60
|
+
return console.log('uncheckAll');
|
|
61
|
+
});
|
|
62
|
+
table.on('uncheckAll', spyUncheckAll); // click row
|
|
46
63
|
|
|
47
64
|
_element$querySelecto = element.querySelectorAll('tbody tr'), tr1 = _element$querySelecto[0], tr2 = _element$querySelecto[1];
|
|
48
65
|
tr1.click();
|
|
49
|
-
_context.next =
|
|
66
|
+
_context.next = 17;
|
|
50
67
|
return wait();
|
|
51
68
|
|
|
52
|
-
case
|
|
69
|
+
case 17:
|
|
53
70
|
expect(table.get('checkedKeys')).to.eql([0]);
|
|
71
|
+
expect(spyCheckRow.callCount).to.eql(1);
|
|
54
72
|
tr2.click();
|
|
55
|
-
_context.next =
|
|
73
|
+
_context.next = 22;
|
|
56
74
|
return wait();
|
|
57
75
|
|
|
58
|
-
case
|
|
76
|
+
case 22:
|
|
59
77
|
expect(table.get('checkedKeys')).to.eql([0, 1]);
|
|
60
78
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.All);
|
|
79
|
+
expect(spyCheckRow.callCount).to.eql(2);
|
|
80
|
+
expect(spyCheckAll.callCount).to.eq(0);
|
|
61
81
|
tr1.click();
|
|
62
|
-
_context.next =
|
|
82
|
+
_context.next = 29;
|
|
63
83
|
return wait();
|
|
64
84
|
|
|
65
|
-
case
|
|
85
|
+
case 29:
|
|
66
86
|
expect(table.get('checkedKeys')).to.eql([1]);
|
|
67
87
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.Indeterminate);
|
|
88
|
+
expect(spyUncheckRow.callCount).to.eql(1);
|
|
68
89
|
all = element.querySelector('.k-checkbox');
|
|
69
90
|
all.click();
|
|
70
|
-
_context.next =
|
|
91
|
+
_context.next = 36;
|
|
71
92
|
return wait();
|
|
72
93
|
|
|
73
|
-
case
|
|
94
|
+
case 36:
|
|
74
95
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.All);
|
|
96
|
+
expect(spyCheckAll.callCount).to.eql(1);
|
|
75
97
|
all.click();
|
|
76
|
-
_context.next =
|
|
98
|
+
_context.next = 41;
|
|
77
99
|
return wait();
|
|
78
100
|
|
|
79
|
-
case
|
|
101
|
+
case 41:
|
|
80
102
|
expect(checked.getAllCheckedStatus()).eql(AllCheckedStatus.None);
|
|
81
103
|
expect(table.get('checkedKeys')).to.eql([]);
|
|
104
|
+
expect(spyUncheckAll.callCount).to.eql(1);
|
|
82
105
|
expect(spy.callCount).to.eql(5); // clear data of table should only trigger $change:checked event once, #407
|
|
83
106
|
|
|
84
107
|
all.click();
|
|
85
|
-
|
|
86
|
-
_context.next =
|
|
108
|
+
instance.set('data', []);
|
|
109
|
+
_context.next = 49;
|
|
87
110
|
return wait();
|
|
88
111
|
|
|
89
|
-
case
|
|
112
|
+
case 49:
|
|
90
113
|
expect(spy.callCount).to.eql(7);
|
|
91
114
|
|
|
92
|
-
case
|
|
115
|
+
case 50:
|
|
93
116
|
case "end":
|
|
94
117
|
return _context.stop();
|
|
95
118
|
}
|
|
@@ -342,7 +365,7 @@ describe('Table', function () {
|
|
|
342
365
|
}, _callee6);
|
|
343
366
|
})));
|
|
344
367
|
it('group', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
345
|
-
var _mount7, instance, element, _instance$refs4, __test1, __test2, _element$querySelecto8, table1, table2, icon, dropdown, item, icon2, dropdown2, _dropdown2$querySelec, item1, item2;
|
|
368
|
+
var _mount7, instance, element, _instance$refs4, __test1, __test2, _element$querySelecto8, table1, table2, icon, dropdown, item, icon2, dropdown2, _dropdown2$querySelec, item1, item2, newDropdown;
|
|
346
369
|
|
|
347
370
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
348
371
|
while (1) {
|
|
@@ -395,9 +418,21 @@ describe('Table', function () {
|
|
|
395
418
|
expect(instance.get('multipleGroup')).to.eql({
|
|
396
419
|
status: ['active', 'stopped']
|
|
397
420
|
});
|
|
398
|
-
expect(table2.innerHTML).to.matchSnapshot();
|
|
421
|
+
expect(table2.innerHTML).to.matchSnapshot(); // update group
|
|
399
422
|
|
|
400
|
-
|
|
423
|
+
instance.set('statusGroup', [{
|
|
424
|
+
label: 'label',
|
|
425
|
+
value: 'value'
|
|
426
|
+
}]);
|
|
427
|
+
dispatchEvent(icon, 'click');
|
|
428
|
+
_context7.next = 36;
|
|
429
|
+
return wait(500);
|
|
430
|
+
|
|
431
|
+
case 36:
|
|
432
|
+
newDropdown = getElement('.k-table-group-dropdown');
|
|
433
|
+
expect(newDropdown.innerHTML).to.matchSnapshot();
|
|
434
|
+
|
|
435
|
+
case 38:
|
|
401
436
|
case "end":
|
|
402
437
|
return _context7.stop();
|
|
403
438
|
}
|
|
@@ -1064,4 +1099,80 @@ describe('Table', function () {
|
|
|
1064
1099
|
}
|
|
1065
1100
|
}, _callee22);
|
|
1066
1101
|
})));
|
|
1102
|
+
it('pagination', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23() {
|
|
1103
|
+
var _mount25, instance, element, table, pagination, spy;
|
|
1104
|
+
|
|
1105
|
+
return _regeneratorRuntime.wrap(function _callee23$(_context26) {
|
|
1106
|
+
while (1) {
|
|
1107
|
+
switch (_context26.prev = _context26.next) {
|
|
1108
|
+
case 0:
|
|
1109
|
+
_mount25 = mount(PaginationDemo), instance = _mount25[0], element = _mount25[1];
|
|
1110
|
+
table = instance.refs.table;
|
|
1111
|
+
pagination = table.pagination.paginationRef;
|
|
1112
|
+
spy = sinon.spy();
|
|
1113
|
+
table.on('changePage', spy); // check all
|
|
1114
|
+
|
|
1115
|
+
table.checkAll();
|
|
1116
|
+
expect(table.getCheckedData()).to.have.length(10); // next page
|
|
1117
|
+
|
|
1118
|
+
table.set('pagination', {
|
|
1119
|
+
value: 2
|
|
1120
|
+
});
|
|
1121
|
+
table.trigger('$receive:pagination');
|
|
1122
|
+
_context26.next = 11;
|
|
1123
|
+
return wait();
|
|
1124
|
+
|
|
1125
|
+
case 11:
|
|
1126
|
+
expect(table.getCheckedData()).to.have.length(0); // check all again
|
|
1127
|
+
|
|
1128
|
+
table.checkAll();
|
|
1129
|
+
expect(table.getCheckedData()).to.have.length(10); // change limit
|
|
1130
|
+
|
|
1131
|
+
table.set('pagination', {
|
|
1132
|
+
value: 1,
|
|
1133
|
+
limit: 20
|
|
1134
|
+
});
|
|
1135
|
+
table.trigger('$receive:pagination');
|
|
1136
|
+
_context26.next = 18;
|
|
1137
|
+
return wait();
|
|
1138
|
+
|
|
1139
|
+
case 18:
|
|
1140
|
+
expect(table.getCheckedData()).to.have.length(10); // check all again
|
|
1141
|
+
|
|
1142
|
+
table.checkAll();
|
|
1143
|
+
expect(table.getCheckedData()).to.have.length(20); // change limit from pagination
|
|
1144
|
+
|
|
1145
|
+
pagination.value.set('limit', 10);
|
|
1146
|
+
_context26.next = 24;
|
|
1147
|
+
return wait();
|
|
1148
|
+
|
|
1149
|
+
case 24:
|
|
1150
|
+
expect(table.getCheckedData()).to.have.length(10); // FIXME: Pagination component should no trigger change event multiple times
|
|
1151
|
+
// when we set value and limit at the same time
|
|
1152
|
+
|
|
1153
|
+
expect(spy.callCount).to.eql(4);
|
|
1154
|
+
expect(spy.lastCall.lastArg).to.eql({
|
|
1155
|
+
value: 1,
|
|
1156
|
+
limit: 10
|
|
1157
|
+
}); // change page from pagination
|
|
1158
|
+
|
|
1159
|
+
_context26.next = 29;
|
|
1160
|
+
return wait();
|
|
1161
|
+
|
|
1162
|
+
case 29:
|
|
1163
|
+
pagination.value.changePage(2);
|
|
1164
|
+
expect(table.getCheckedData()).to.have.length(0);
|
|
1165
|
+
expect(spy.callCount).to.eql(5);
|
|
1166
|
+
expect(spy.lastCall.lastArg).to.eql({
|
|
1167
|
+
value: 2,
|
|
1168
|
+
limit: 10
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
case 33:
|
|
1172
|
+
case "end":
|
|
1173
|
+
return _context26.stop();
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}, _callee23);
|
|
1177
|
+
})));
|
|
1067
1178
|
});
|
|
@@ -14,7 +14,7 @@ export interface TableRowProps {
|
|
|
14
14
|
index: number;
|
|
15
15
|
disabled: boolean;
|
|
16
16
|
allDisabled: boolean;
|
|
17
|
-
onChangeChecked: (index: number, checked: boolean) => void;
|
|
17
|
+
onChangeChecked: (index: number, checked: boolean, key: TableRowKey) => void;
|
|
18
18
|
grid: TableGrid;
|
|
19
19
|
selected: boolean;
|
|
20
20
|
spreaded: boolean;
|
|
@@ -56,9 +56,10 @@ export var TableRow = /*#__PURE__*/function (_Component) {
|
|
|
56
56
|
_proto.onChangeChecked = function onChangeChecked(v) {
|
|
57
57
|
var _this$get2 = this.get(),
|
|
58
58
|
index = _this$get2.index,
|
|
59
|
+
key = _this$get2.key,
|
|
59
60
|
onChangeChecked = _this$get2.onChangeChecked;
|
|
60
61
|
|
|
61
|
-
onChangeChecked(index, v);
|
|
62
|
+
onChangeChecked(index, v, key);
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
_proto.onClickArrow = function onClickArrow(e) {
|
|
@@ -92,7 +92,7 @@ setDefault(function () {
|
|
|
92
92
|
export function makeStyles() {
|
|
93
93
|
return /*#__PURE__*/css("font-size:", table.fontSize, ";color:", table.color, ";border-top:", table.border, ";position:relative;z-index:0;.k-table-wrapper{border-bottom:", table.border, ";overflow:auto;}table{width:100%;border-spacing:0;table-layout:fixed;td,th{transition:all ", table.transition, ";}}thead{text-align:", table.thead.textAlign, ";font-size:", table.thead.fontSize, ";font-weight:", table.thead.fontWeight, ";position:sticky;top:0;z-index:2;tr{height:", table.thead.height, ";}}th{padding:", table.thead.padding, ";position:relative;background:", table.thead.bgColor, ";border-bottom:", table.border, ";&:before{content:'';height:", table.thead.delimiterHeight, ";position:absolute;background-color:", table.thead.delimiterColor, ";width:1px;left:1px;top:50%;transform:translateY(-50%);}&:first-of-type:before{display:none;}}.k-table-title{display:inline-flex;align-items:center;max-width:100%;}.k-table-title-text{flex:1;}tbody{tr{&:hover td{background:", table.tbody.hoverBgcolor, ";}&:last-of-type td{border-bottom-color:transparent;}}}td{padding:", table.tbody.padding, ";border-bottom:", table.border, ";background:", table.bgColor, ";word-wrap:break-word;}.k-fixed-left,.k-fixed-right{position:sticky;z-index:1;&:after{content:'';display:block;transition:box-shadow ", table.transition, ";position:absolute;top:0;bottom:0px;width:10px;pointer-events:none;}}.k-fixed-left:after{right:-11px;}.k-fixed-right:after{left:-11px;}&.k-scroll-left .k-fixed-right:after{box-shadow:", table.fixRightShadow, ";}&.k-scroll-right .k-fixed-left:after{box-shadow:", table.fixLeftShadow, ";}&.k-scroll-middle{.k-fixed-left:after{box-shadow:", table.fixLeftShadow, ";}.k-fixed-right:after{box-shadow:", table.fixRightShadow, ";}}.k-fixed-right+.k-fixed-right:after{display:none;}.k-table-affix-header{position:sticky;top:0;left:0;.k-affix-wrapper{overflow:hidden;}&.k-fixed{position:relative;}}&.k-border,&.k-grid{.k-table-wrapper{border-left:", table.border, ";border-right:", table.border, ";}}&.k-grid{td:not(:last-of-type),th:not(:last-of-type){border-right:", table.border, ";}th:before{display:none;}}&.k-stripe{tr:nth-child(even):not(:hover) td{background:", table.stripeBgColor, ";}}.k-table-group{width:", table.group.width, "!important;height:", table.group.width, "!important;margin-left:", table.group.gap, ";position:relative;color:", table.group.color, ";&:hover{color:", theme.color.primary, ";}.k-icon{transition:transform ", table.transition, ";}&.k-dropdown-open .k-icon{transform:rotate(180deg);}}.k-table-check{.k-checkbox,.k-radio{position:relative;top:-1px;}}.k-column-sortable{cursor:pointer;}.k-column-sort{.k-icon{display:block;height:", _sortInstanceProperty(table).iconHeight, ";line-height:", _sortInstanceProperty(table).iconHeight, ";margin-left:", _sortInstanceProperty(table).gap, ";color:", _sortInstanceProperty(table).color, ";}&.k-asc .k-icon.k-desc,&.k-desc .k-icon.k-asc{color:", _sortInstanceProperty(table).disabledColor, ";}}.k-table-spin.k-overlay{z-index:2;}.k-table-empty{text-align:center;}tr.k-expand{td{padding:0;background:#fdfcff;}}&.k-with-expand{tr:not(.k-expand){td{border-bottom:none;}}}.k-table-expand{border-top:", table.border, ";box-sizing:content-box;}tbody tr.k-selected td{background:", table.selectedBgColor, ";}.k-table-arrow{margin-right:", table.arrow.gap, ";transition:transform ", table.transition, ";position:relative;top:-1px;}tr.k-spreaded{.k-table-arrow{transform:rotate(90deg);}}.k-table-resize{height:100%;width:", table.resizeWidth, ";position:absolute;top:0;left:-1px;cursor:ew-resize;}tr.k-dragging{opacity:", table.draggingOpacity, ";}.k-table-scrollbar{overflow-x:auto;overflow-y:hidden;}.k-table-scrollbar-inner{height:1px;}", _mapInstanceProperty(aligns).call(aligns, function (type) {
|
|
94
94
|
return /*#__PURE__*/css(".k-align-", type, "{text-align:", type, ";}");
|
|
95
|
-
}), ";");
|
|
95
|
+
}), ">.k-pagination{margin:16px 0;}");
|
|
96
96
|
}
|
|
97
97
|
export function makeGroupMenuStyles() {
|
|
98
98
|
return /*#__PURE__*/css("max-height:", table.group.menuMaxHeight, ";overflow:auto;.k-dropdown-item.k-active{color:", table.group.activeColor, ";}.k-table-group-header{padding:", table.group.headerPadding, ";border-bottom:", table.group.headerBorder, ";}");
|
|
@@ -2,6 +2,7 @@ import { Component, TypeDefs } from 'intact';
|
|
|
2
2
|
import { TableMerge } from './useMerge';
|
|
3
3
|
import { TooltipProps } from '../tooltip/tooltip';
|
|
4
4
|
import type { Events } from '../types';
|
|
5
|
+
import type { PaginationProps, PaginationChangeData } from '../pagination';
|
|
5
6
|
export interface TableProps<T = any, K extends TableRowKey = TableRowKey, C extends CheckType = CheckType, S extends string = string, G extends TableGroupValue = TableGroupValue> {
|
|
6
7
|
data?: T[];
|
|
7
8
|
fixHeader?: boolean | string | number;
|
|
@@ -35,6 +36,8 @@ export interface TableProps<T = any, K extends TableRowKey = TableRowKey, C exte
|
|
|
35
36
|
widthStoreKey?: string;
|
|
36
37
|
draggable?: boolean;
|
|
37
38
|
animation?: boolean | [boolean, boolean];
|
|
39
|
+
hideHeader?: boolean;
|
|
40
|
+
pagination?: boolean | PaginationProps;
|
|
38
41
|
}
|
|
39
42
|
export interface TableEvents<T = any, K extends TableRowKey = number> {
|
|
40
43
|
clickRow: [T, number, K];
|
|
@@ -47,6 +50,11 @@ export interface TableEvents<T = any, K extends TableRowKey = number> {
|
|
|
47
50
|
from: number;
|
|
48
51
|
to: number;
|
|
49
52
|
}];
|
|
53
|
+
checkRow: [T, number, K];
|
|
54
|
+
uncheckRow: [T, number, K];
|
|
55
|
+
checkAll: [];
|
|
56
|
+
uncheckAll: [];
|
|
57
|
+
changePage: [PaginationChangeData];
|
|
50
58
|
}
|
|
51
59
|
export interface TableBlocks<T = unknown> {
|
|
52
60
|
empty: null;
|
|
@@ -66,6 +74,13 @@ export declare class Table<T = any, RowKey extends TableRowKey = TableRowKey, Ch
|
|
|
66
74
|
static typeDefs: Required<TypeDefs<TableProps<unknown, TableRowKey, CheckType, string, TableGroupValue<string | number | symbol>>>>;
|
|
67
75
|
static defaults: () => Partial<TableProps<any, TableRowKey, CheckType, string, TableGroupValue<string | number | symbol>>>;
|
|
68
76
|
static events: Events<TableEvents<any, number>>;
|
|
77
|
+
pagination: {
|
|
78
|
+
data: import("../../hooks/useState").State<any[] | undefined>;
|
|
79
|
+
value: import("../../hooks/useState").State<number>;
|
|
80
|
+
limit: import("../../hooks/useState").State<number>;
|
|
81
|
+
onChange: (data: PaginationChangeData) => void;
|
|
82
|
+
paginationRef: import("intact").RefObject<import("../pagination").Pagination>;
|
|
83
|
+
};
|
|
69
84
|
private tree;
|
|
70
85
|
private columns;
|
|
71
86
|
private scroll;
|