@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,71 @@
|
|
|
1
|
+
import {useInstance, createRef} from 'intact';
|
|
2
|
+
import type {Table, TableRowKey, TableCheckType} from './table';
|
|
3
|
+
import {useState} from '../../hooks/useState';
|
|
4
|
+
import {Pagination, PaginationChangeData} from '../pagination';
|
|
5
|
+
import {isObject} from 'intact-shared';
|
|
6
|
+
import { useReceive } from '../../hooks/useReceive';
|
|
7
|
+
|
|
8
|
+
const defaultPagination = Pagination.defaults();
|
|
9
|
+
|
|
10
|
+
export function usePagination() {
|
|
11
|
+
const instance = useInstance() as Table<any, TableRowKey, TableCheckType>
|
|
12
|
+
const data = useState<any[] | undefined>(instance.get('data'));
|
|
13
|
+
const value = useState<number>(defaultPagination.value!);
|
|
14
|
+
const limit = useState<number>(defaultPagination.limit!);
|
|
15
|
+
const paginationRef = createRef<Pagination>(); // for unit test
|
|
16
|
+
|
|
17
|
+
useReceive<Table>(['data', 'pagination'], () => {
|
|
18
|
+
handleData();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function handleData() {
|
|
22
|
+
let { data: _data, pagination } = instance.get();
|
|
23
|
+
|
|
24
|
+
if (!_data) {
|
|
25
|
+
data.set(undefined);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!pagination) {
|
|
30
|
+
data.set(_data);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isObject(pagination)) {
|
|
35
|
+
if (pagination.value) {
|
|
36
|
+
value.set(pagination.value);
|
|
37
|
+
}
|
|
38
|
+
if (pagination.limit) {
|
|
39
|
+
limit.set(pagination.limit);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
updateDataByPage();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function updateDataByPage() {
|
|
47
|
+
const { data: _data } = instance.get();
|
|
48
|
+
const index = (value.value - 1) * limit.value;
|
|
49
|
+
data.set(_data!.slice(index, index + limit.value));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function onChange(data: PaginationChangeData) {
|
|
53
|
+
const { pagination } = instance.get();
|
|
54
|
+
|
|
55
|
+
value.set(data.value);
|
|
56
|
+
limit.set(data.limit);
|
|
57
|
+
updateDataByPage();
|
|
58
|
+
|
|
59
|
+
if (isObject(pagination)) {
|
|
60
|
+
instance.set('pagination', {
|
|
61
|
+
...pagination,
|
|
62
|
+
value: value.value,
|
|
63
|
+
limit: limit.value,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
instance.trigger('changePage', data);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return { data, value, limit, onChange, paginationRef };
|
|
71
|
+
}
|
|
@@ -29,7 +29,10 @@ export function useRestRowStatus(
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function omit(
|
|
32
|
+
function omit(
|
|
33
|
+
type: 'checkedKeys' | 'selectedKeys' | 'spreadKeys' | 'expandedKeys',
|
|
34
|
+
keys: TableRowKey[]
|
|
35
|
+
) {
|
|
33
36
|
let originKeys = instance.get(type);
|
|
34
37
|
if (!originKeys) return;
|
|
35
38
|
|
|
@@ -2,8 +2,9 @@ import {useInstance} from 'intact';
|
|
|
2
2
|
import type {Table, TableRowKey} from './table';
|
|
3
3
|
import {inArray} from './useChecked';
|
|
4
4
|
import {toggleArray} from '../utils';
|
|
5
|
+
import { State } from '../../hooks/useState';
|
|
5
6
|
|
|
6
|
-
export function useTree() {
|
|
7
|
+
export function useTree(data: State<any[] | undefined>) {
|
|
7
8
|
const instance = useInstance() as Table;
|
|
8
9
|
|
|
9
10
|
function isSpreaded(key: TableRowKey) {
|
|
@@ -18,8 +19,8 @@ export function useTree() {
|
|
|
18
19
|
cb: (value: any, index: number, level: number, meta: T | null) => T,
|
|
19
20
|
shouldBreak: boolean = false,
|
|
20
21
|
) {
|
|
21
|
-
const {childrenKey
|
|
22
|
-
loopDataWithChildrenKey(data, childrenKey, cb, shouldBreak);
|
|
22
|
+
const {childrenKey} = instance.get();
|
|
23
|
+
loopDataWithChildrenKey(data.value, childrenKey, cb, shouldBreak);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
return {isSpreaded, toggleSpreadRow, loopData};
|
|
@@ -29,12 +29,23 @@ sidebar: doc
|
|
|
29
29
|
| min | 最小可选时间 | `Value` | `undefind` |
|
|
30
30
|
| disabledDate | 该属性值是一个函数,用于定义那些日期被禁止选择,函数参数为日期字符串,返回`true`则表示禁用该日期 | `(v: Dayjs) => boolean` | `undefined` |
|
|
31
31
|
| step | 固定时间点的步长 | `string` | `undefined` |
|
|
32
|
+
| position | 菜单弹出的位置,默认与触发器左侧对齐向下偏移`8px`的地方 | `Position` | `"left"` | `"bottom"` | `"right"` | `"top"` | `{my: 'left top+8', 'left bottom'}` |
|
|
32
33
|
|
|
33
34
|
```ts
|
|
34
35
|
import {Dayjs} from 'dayjs';
|
|
35
36
|
import {VNode} from 'intact';
|
|
36
37
|
|
|
37
38
|
export type Value = string | Date | number | Dayjs;
|
|
39
|
+
|
|
40
|
+
type Position = {
|
|
41
|
+
my?: string | [string, string]
|
|
42
|
+
at?: string | [string, string]
|
|
43
|
+
collision?: Collision | [Collision, Collision]
|
|
44
|
+
collisionDirection?: ['left'] | ['top'] | ['left', 'top']
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type Collision = 'fit' | 'flip' | 'flipfit' | 'none'
|
|
48
|
+
|
|
38
49
|
export type Container = string | ((parentDom: Element, anchor: Node | null) => Element)
|
|
39
50
|
```
|
|
40
51
|
|
|
@@ -4,7 +4,7 @@ order: 2
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
使用`trigger`指定触发方式,`click`点击触发,`hover`悬浮触发,`foucs`聚焦触发,默认为`hover`,在悬浮触发情况下,
|
|
7
|
-
鼠标离开触发器,弹层就会消失,如果我们需要鼠标能离开触发器并悬浮在弹层上,需要添加`
|
|
7
|
+
鼠标离开触发器,弹层就会消失,如果我们需要鼠标能离开触发器并悬浮在弹层上,需要添加`hoverable`属性
|
|
8
8
|
|
|
9
9
|
```vdt
|
|
10
10
|
import {Tooltip, ButtonGroup, Button, Input} from 'kpc';
|
|
@@ -21,7 +21,7 @@ sidebar: doc
|
|
|
21
21
|
| always | 是否一直保持当前展示/隐藏状态 | `boolean` | `false` |
|
|
22
22
|
| size | 弹层尺寸 | `"default"` | `"small"` | `"default"` |
|
|
23
23
|
| confirm | 带“确认”和“取消”按钮的确认弹层 | `boolean` | `false` |
|
|
24
|
-
|
|
|
24
|
+
| okText | `confirm`模式下的“确认”按钮文案 | `string` | `"确认"` |
|
|
25
25
|
| cancelText | `confirm`模式下的“取消”按钮文案 | `string` | `"取消"` |
|
|
26
26
|
| content | 指定提示的内容,当然你也可以用`content`扩展点指定 | `string` | `VNode` | `undefined` |
|
|
27
27
|
|
|
@@ -330,16 +330,19 @@ describe('Tooltip', () => {
|
|
|
330
330
|
static defaults = () => ({show: false});
|
|
331
331
|
Tooltip = Tooltip;
|
|
332
332
|
mounted() {
|
|
333
|
-
const element = findDomFromVNode(this.$lastInput!, true) as
|
|
334
|
-
const
|
|
335
|
-
|
|
333
|
+
const element = findDomFromVNode(this.$lastInput!, true) as HTMLElement;
|
|
334
|
+
const style = element.style;
|
|
335
|
+
style.position = 'fixed';
|
|
336
|
+
style.top = '-200px';
|
|
337
|
+
// const windowHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
338
|
+
// (element.parentNode as HTMLElement).style.height = `${windowHeight * 2}px`;
|
|
336
339
|
}
|
|
337
340
|
}
|
|
338
341
|
|
|
339
342
|
const [i] = mount(Demo);
|
|
340
343
|
|
|
341
|
-
await wait(500);
|
|
342
|
-
window.scrollTo(0, 10000);
|
|
344
|
+
// await wait(500);
|
|
345
|
+
// window.scrollTo(0, 10000);
|
|
343
346
|
|
|
344
347
|
i.set('show', true);
|
|
345
348
|
|
|
@@ -33,6 +33,7 @@ sidebar: doc
|
|
|
33
33
|
| checkbox | 是否展示复选框 | `boolean` | `false` |
|
|
34
34
|
| filter | 当支持筛选时,可以自定义筛选规则 | `(keywords: string, data: TreeDataItem<K>) => boolean` | `undefined` |
|
|
35
35
|
| show | 是否展示菜单项 | `boolean` | `false` |
|
|
36
|
+
| position | 菜单弹出的位置,默认与触发器左侧对齐向下偏移`8px`的地方 | `Position` | `"left"` | `"bottom"` | `"right"` | `"top"` | `{my: 'left top+8', 'left bottom'}` |
|
|
36
37
|
|
|
37
38
|
```ts
|
|
38
39
|
import {Key, Children} from 'intact';
|
|
@@ -47,6 +48,14 @@ export type TreeDataItem<K extends Key> = {
|
|
|
47
48
|
children?: TreeDataItem<K>[]
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
type Position = {
|
|
52
|
+
my?: string | [string, string]
|
|
53
|
+
at?: string | [string, string]
|
|
54
|
+
collision?: Collision | [Collision, Collision]
|
|
55
|
+
collisionDirection?: ['left'] | ['top'] | ['left', 'top']
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Collision = 'fit' | 'flip' | 'flipfit' | 'none'
|
|
50
59
|
```
|
|
51
60
|
|
|
52
61
|
# 扩展点
|
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
import { TypeDefs } from 'intact';
|
|
2
2
|
import { BaseSelect, BaseSelectProps, BaseSelectEvents, BaseSelectBlocks } from '../select/base';
|
|
3
|
-
export interface CascaderProps<V = any, Multipe extends boolean = boolean
|
|
4
|
-
data?:
|
|
3
|
+
export interface CascaderProps<V = any, Multipe extends boolean = boolean, Data extends BaseCascaderData = CascaderData<V>> extends BaseSelectProps<V[], Multipe> {
|
|
4
|
+
data?: Data[];
|
|
5
5
|
trigger?: 'click' | 'hover';
|
|
6
6
|
changeOnSelect?: boolean;
|
|
7
7
|
format?: (labels: string[]) => string;
|
|
8
|
-
loadData?: (data:
|
|
9
|
-
filter?: (keywords: string, data:
|
|
8
|
+
loadData?: (data: Data) => any;
|
|
9
|
+
filter?: (keywords: string, data: Data) => boolean;
|
|
10
|
+
fields?: CascaderFields<Data>;
|
|
10
11
|
}
|
|
11
|
-
export declare type
|
|
12
|
+
export declare type CascaderFields<Data> = {
|
|
13
|
+
value?: keyof Data;
|
|
14
|
+
label?: keyof Data;
|
|
15
|
+
children?: keyof Data;
|
|
16
|
+
disabled?: keyof Data;
|
|
17
|
+
};
|
|
18
|
+
export interface BaseCascaderData {
|
|
19
|
+
loaded?: boolean;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}
|
|
22
|
+
export interface CascaderData<V> extends BaseCascaderData {
|
|
12
23
|
value: V;
|
|
13
24
|
label: string;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
loaded?: boolean;
|
|
16
25
|
children?: CascaderData<V>[];
|
|
17
|
-
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
}
|
|
18
28
|
export interface CascaderEvents extends BaseSelectEvents {
|
|
19
29
|
}
|
|
20
30
|
export interface CascaderBlocks<V> extends BaseSelectBlocks<V> {
|
|
21
31
|
}
|
|
22
|
-
export declare class Cascader<V = any, Multipe extends boolean = false
|
|
32
|
+
export declare class Cascader<V = any, Multipe extends boolean = false, Data extends BaseCascaderData = CascaderData<V>> extends BaseSelect<CascaderProps<V, Multipe, Data>, CascaderEvents, CascaderBlocks<V>> {
|
|
23
33
|
static template: string | import("intact").Template<any>;
|
|
24
|
-
static typeDefs: Required<TypeDefs<CascaderProps<any, boolean
|
|
25
|
-
static defaults: () => Partial<CascaderProps<any, boolean
|
|
34
|
+
static typeDefs: Required<TypeDefs<CascaderProps<any, boolean, CascaderData<any>>>>;
|
|
35
|
+
static defaults: () => Partial<CascaderProps<any, boolean, CascaderData<any>>>;
|
|
36
|
+
private fields;
|
|
26
37
|
private value;
|
|
27
38
|
private label;
|
|
28
39
|
private load;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
2
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
3
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/includes";
|
|
4
3
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
|
|
5
4
|
import template from './index.vdt';
|
|
6
5
|
import { BaseSelect } from '../select/base';
|
|
@@ -10,6 +9,7 @@ import { useValue } from './useValue';
|
|
|
10
9
|
import { useLabel } from './useLabel';
|
|
11
10
|
import { useLoad } from './useLoad';
|
|
12
11
|
import { useFilterable } from './useFilterable';
|
|
12
|
+
import { useFields } from './useFields';
|
|
13
13
|
|
|
14
14
|
var typeDefs = _extends({}, BaseSelect.typeDefs, {
|
|
15
15
|
data: Array,
|
|
@@ -17,7 +17,8 @@ var typeDefs = _extends({}, BaseSelect.typeDefs, {
|
|
|
17
17
|
changeOnSelect: Boolean,
|
|
18
18
|
format: Function,
|
|
19
19
|
loadData: Function,
|
|
20
|
-
filter: Function
|
|
20
|
+
filter: Function,
|
|
21
|
+
fields: Object
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
var defaults = function defaults() {
|
|
@@ -26,11 +27,6 @@ var defaults = function defaults() {
|
|
|
26
27
|
trigger: 'click',
|
|
27
28
|
format: function format(labels) {
|
|
28
29
|
return labels.join(' / ');
|
|
29
|
-
},
|
|
30
|
-
filter: function filter(keywords, data) {
|
|
31
|
-
var _context;
|
|
32
|
-
|
|
33
|
-
return _includesInstanceProperty(_context = data.label).call(_context, keywords);
|
|
34
30
|
}
|
|
35
31
|
});
|
|
36
32
|
};
|
|
@@ -39,7 +35,7 @@ export var Cascader = /*#__PURE__*/function (_BaseSelect) {
|
|
|
39
35
|
_inheritsLoose(Cascader, _BaseSelect);
|
|
40
36
|
|
|
41
37
|
function Cascader() {
|
|
42
|
-
var
|
|
38
|
+
var _context;
|
|
43
39
|
|
|
44
40
|
var _this;
|
|
45
41
|
|
|
@@ -47,11 +43,12 @@ export var Cascader = /*#__PURE__*/function (_BaseSelect) {
|
|
|
47
43
|
args[_key] = arguments[_key];
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
_this = _BaseSelect.call.apply(_BaseSelect, _concatInstanceProperty(
|
|
46
|
+
_this = _BaseSelect.call.apply(_BaseSelect, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
47
|
+
_this.fields = useFields();
|
|
51
48
|
_this.value = useValue();
|
|
52
|
-
_this.label = useLabel();
|
|
53
|
-
_this.load = useLoad();
|
|
54
|
-
_this.filterable = useFilterable(_this.input.keywords, _this.value.setValue);
|
|
49
|
+
_this.label = useLabel(_this.fields);
|
|
50
|
+
_this.load = useLoad(_this.fields);
|
|
51
|
+
_this.filterable = useFilterable(_this.input.keywords, _this.value.setValue, _this.fields);
|
|
55
52
|
_this.positionObj = {
|
|
56
53
|
my: 'left top',
|
|
57
54
|
at: 'right top',
|
|
@@ -366,4 +366,85 @@ describe('Cascader', function () {
|
|
|
366
366
|
}
|
|
367
367
|
}, _callee8);
|
|
368
368
|
})));
|
|
369
|
+
it('specify fields', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
370
|
+
var Demo, _mount8, instance, element, select, dropdown1, _dropdown1$querySelec5, item1, dropdown2, _dropdown2$querySelec4, item11;
|
|
371
|
+
|
|
372
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context11) {
|
|
373
|
+
while (1) {
|
|
374
|
+
switch (_context11.prev = _context11.next) {
|
|
375
|
+
case 0:
|
|
376
|
+
Demo = /*#__PURE__*/function (_Component2) {
|
|
377
|
+
_inheritsLoose(Demo, _Component2);
|
|
378
|
+
|
|
379
|
+
function Demo() {
|
|
380
|
+
var _context10;
|
|
381
|
+
|
|
382
|
+
var _this2;
|
|
383
|
+
|
|
384
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
385
|
+
args[_key2] = arguments[_key2];
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
_this2 = _Component2.call.apply(_Component2, _concatInstanceProperty(_context10 = [this]).call(_context10, args)) || this;
|
|
389
|
+
_this2.Cascader = Cascader;
|
|
390
|
+
return _this2;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
Demo.defaults = function defaults() {
|
|
394
|
+
return {
|
|
395
|
+
value: [],
|
|
396
|
+
data: [{
|
|
397
|
+
v: 'beijing',
|
|
398
|
+
l: '北京',
|
|
399
|
+
c: [{
|
|
400
|
+
v: 'haidian',
|
|
401
|
+
l: '海淀区'
|
|
402
|
+
}]
|
|
403
|
+
}, {
|
|
404
|
+
v: 'hunan',
|
|
405
|
+
l: '湖南',
|
|
406
|
+
c: [{
|
|
407
|
+
v: 'haidian',
|
|
408
|
+
l: '海淀区'
|
|
409
|
+
}]
|
|
410
|
+
}]
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
return Demo;
|
|
415
|
+
}(Component);
|
|
416
|
+
|
|
417
|
+
Demo.template = "\n const {Cascader} = this;\n <Cascader data={this.get('data')}\n v-model=\"value\"\n fields={{value: 'v', label: 'l', children: 'c'}}\n />\n ";
|
|
418
|
+
_mount8 = mount(Demo), instance = _mount8[0], element = _mount8[1];
|
|
419
|
+
select = element;
|
|
420
|
+
select.click();
|
|
421
|
+
_context11.next = 7;
|
|
422
|
+
return wait();
|
|
423
|
+
|
|
424
|
+
case 7:
|
|
425
|
+
dropdown1 = getElement('.k-cascader-menu');
|
|
426
|
+
_dropdown1$querySelec5 = dropdown1.querySelectorAll(':scope > .k-dropdown-item'), item1 = _dropdown1$querySelec5[0];
|
|
427
|
+
item1.click();
|
|
428
|
+
_context11.next = 12;
|
|
429
|
+
return wait();
|
|
430
|
+
|
|
431
|
+
case 12:
|
|
432
|
+
expect(dropdown1.innerHTML).to.matchSnapshot();
|
|
433
|
+
dropdown2 = getElement('.k-cascader-menu');
|
|
434
|
+
_dropdown2$querySelec4 = dropdown2.querySelectorAll(':scope > .k-dropdown-item'), item11 = _dropdown2$querySelec4[0];
|
|
435
|
+
item11.click();
|
|
436
|
+
_context11.next = 18;
|
|
437
|
+
return wait();
|
|
438
|
+
|
|
439
|
+
case 18:
|
|
440
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
441
|
+
expect(instance.get('value')).to.eql(['beijing', 'haidian']);
|
|
442
|
+
|
|
443
|
+
case 20:
|
|
444
|
+
case "end":
|
|
445
|
+
return _context11.stop();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}, _callee9);
|
|
449
|
+
})));
|
|
369
450
|
});
|
|
@@ -27,12 +27,14 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
27
27
|
var _this$get = this.get(),
|
|
28
28
|
data = _this$get.data,
|
|
29
29
|
trigger = _this$get.trigger,
|
|
30
|
-
filterable = _this$get.filterable
|
|
30
|
+
filterable = _this$get.filterable,
|
|
31
|
+
fields = _this$get.fields;
|
|
31
32
|
|
|
32
33
|
var baseMenuStyles = makeMenuStyles();
|
|
33
34
|
var classNameObj = (_classNameObj = {
|
|
34
35
|
'k-cascader-menu': true
|
|
35
36
|
}, _classNameObj[baseMenuStyles] = true, _classNameObj);
|
|
37
|
+
var getField = this.fields;
|
|
36
38
|
|
|
37
39
|
var _this$value = this.value,
|
|
38
40
|
values = _valuesInstanceProperty(_this$value),
|
|
@@ -51,31 +53,31 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
return _mapInstanceProperty(data).call(data, function (item, index) {
|
|
54
|
-
var value = item
|
|
56
|
+
var value = getField(item, 'value');
|
|
55
57
|
var showed = isShowed(value, level);
|
|
56
58
|
var selected = parentSelected && isSelected(value, level);
|
|
57
|
-
var children = item
|
|
59
|
+
var children = getField(item, 'children');
|
|
58
60
|
|
|
59
61
|
var Item = function Item() {
|
|
60
62
|
return _$cc(DropdownItem, {
|
|
61
|
-
'disabled': item
|
|
63
|
+
'disabled': getField(item, 'disabled'),
|
|
62
64
|
'className': _$cn({
|
|
63
65
|
'k-cascader-option': true,
|
|
64
66
|
'k-active': showed,
|
|
65
67
|
'k-selected': selected
|
|
66
68
|
}),
|
|
67
69
|
'ev-select': onSelect.bind(null, value, level),
|
|
68
|
-
'children': [item
|
|
70
|
+
'children': [getField(item, 'label'), children ? _$cc(Icon, _$tmp1) : undefined]
|
|
69
71
|
});
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
return children ? _$cc(Dropdown, {
|
|
73
75
|
'position': _this.positionObj,
|
|
74
76
|
'of': 'parent',
|
|
75
|
-
'disabled': item
|
|
77
|
+
'disabled': getField(item, 'disabled'),
|
|
76
78
|
'trigger': trigger,
|
|
77
79
|
'value': showed,
|
|
78
|
-
'ev-$
|
|
80
|
+
'ev-$change:value': toggleShowedValue.bind(null, value, level),
|
|
79
81
|
'ev-show': _this.load.bind(null, item),
|
|
80
82
|
'children': [Item(), _$cc(DropdownMenu, {
|
|
81
83
|
'className': _$cn(classNameObj),
|
|
@@ -116,7 +118,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
116
118
|
'children': function () {
|
|
117
119
|
// highlight keywords
|
|
118
120
|
var label = _mapInstanceProperty($value).call($value, function (item) {
|
|
119
|
-
return item
|
|
121
|
+
return getField(item, 'label');
|
|
120
122
|
}).join(' / ');
|
|
121
123
|
|
|
122
124
|
var labels = label.split(keywords);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useInstance } from 'intact';
|
|
2
|
+
export function useFields() {
|
|
3
|
+
var instance = useInstance();
|
|
4
|
+
return function getField(data, key) {
|
|
5
|
+
var _instance$get = instance.get(),
|
|
6
|
+
fields = _instance$get.fields;
|
|
7
|
+
|
|
8
|
+
if (fields) {
|
|
9
|
+
var field = fields[key];
|
|
10
|
+
|
|
11
|
+
if (field) {
|
|
12
|
+
return data[field];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return data[key];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { CascaderData } from './';
|
|
2
2
|
import { State } from '../../hooks/useState';
|
|
3
3
|
import type { Value } from './useValue';
|
|
4
|
-
|
|
4
|
+
import type { useFields } from './useFields';
|
|
5
|
+
export declare function useFilterable(keywords: State<string>, setValue: (value: Value) => void, getField: ReturnType<typeof useFields>): {
|
|
5
6
|
filter: () => CascaderData<any>[][];
|
|
6
7
|
selectByFilter: (data: CascaderData<any>[]) => void;
|
|
7
8
|
keywords: State<string>;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js/instance/filter";
|
|
2
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/includes";
|
|
2
3
|
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
|
|
3
4
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
4
5
|
import { useInstance } from 'intact';
|
|
5
|
-
export function useFilterable(keywords, setValue) {
|
|
6
|
+
export function useFilterable(keywords, setValue, getField) {
|
|
6
7
|
var instance = useInstance();
|
|
7
8
|
|
|
8
9
|
function filter() {
|
|
10
|
+
var ret = [];
|
|
11
|
+
|
|
9
12
|
var _instance$get = instance.get(),
|
|
10
13
|
data = _instance$get.data,
|
|
11
14
|
filter = _filterInstanceProperty(_instance$get);
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
if (!filter) {
|
|
17
|
+
filter = function filter(keywords, data) {
|
|
18
|
+
var _context;
|
|
19
|
+
|
|
20
|
+
return _includesInstanceProperty(_context = getField(data, 'label')).call(_context, keywords);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
14
23
|
|
|
15
24
|
var loop = function loop(data, prefix, valid, disabled) {
|
|
16
25
|
if (prefix === void 0) {
|
|
@@ -28,14 +37,16 @@ export function useFilterable(keywords, setValue) {
|
|
|
28
37
|
data.forEach(function (item) {
|
|
29
38
|
var _valid = valid || filter(keywords.value, item);
|
|
30
39
|
|
|
31
|
-
var _disabled = disabled || item
|
|
40
|
+
var _disabled = disabled || getField(item, 'disabled');
|
|
32
41
|
|
|
33
42
|
var _prefix = _sliceInstanceProperty(prefix).call(prefix, 0);
|
|
34
43
|
|
|
35
44
|
_prefix.push(item);
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
var children = getField(item, 'children');
|
|
47
|
+
|
|
48
|
+
if (children) {
|
|
49
|
+
loop(children, _prefix, _valid, _disabled);
|
|
39
50
|
} else if (_valid) {
|
|
40
51
|
_prefix.disabled = _disabled;
|
|
41
52
|
ret.push(_prefix);
|
|
@@ -49,7 +60,7 @@ export function useFilterable(keywords, setValue) {
|
|
|
49
60
|
|
|
50
61
|
function selectByFilter(data) {
|
|
51
62
|
var value = _mapInstanceProperty(data).call(data, function (item) {
|
|
52
|
-
return item
|
|
63
|
+
return getField(item, 'value');
|
|
53
64
|
});
|
|
54
65
|
|
|
55
66
|
setValue(value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useInstance } from 'intact';
|
|
2
2
|
import { useBaseLabel } from '../select/useBaseLabel';
|
|
3
|
-
export function useLabel() {
|
|
3
|
+
export function useLabel(getField) {
|
|
4
4
|
var instance = useInstance();
|
|
5
5
|
|
|
6
6
|
function findLabel(data, value) {
|
|
@@ -16,9 +16,9 @@ export function useLabel() {
|
|
|
16
16
|
for (var i = 0; i < data.length; i++) {
|
|
17
17
|
var item = data[i];
|
|
18
18
|
|
|
19
|
-
if (item
|
|
20
|
-
labels.push(item
|
|
21
|
-
var children = item
|
|
19
|
+
if (getField(item, 'value') === value[level]) {
|
|
20
|
+
labels.push(getField(item, 'label'));
|
|
21
|
+
var children = getField(item, 'children');
|
|
22
22
|
|
|
23
23
|
if (children) {
|
|
24
24
|
loop(children, level + 1);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { CascaderData } from './';
|
|
2
|
-
|
|
2
|
+
import type { useFields } from './useFields';
|
|
3
|
+
export declare function useLoad(getField: ReturnType<typeof useFields>): (item: CascaderData<any>) => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
3
|
import { useInstance } from 'intact';
|
|
4
|
-
export function useLoad() {
|
|
4
|
+
export function useLoad(getField) {
|
|
5
5
|
var instance = useInstance();
|
|
6
6
|
|
|
7
7
|
function loadData(_x) {
|
|
@@ -10,7 +10,7 @@ export function useLoad() {
|
|
|
10
10
|
|
|
11
11
|
function _loadData() {
|
|
12
12
|
_loadData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(item) {
|
|
13
|
-
var _instance$get, loadData;
|
|
13
|
+
var _instance$get, loadData, children;
|
|
14
14
|
|
|
15
15
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
16
16
|
while (1) {
|
|
@@ -26,19 +26,21 @@ export function useLoad() {
|
|
|
26
26
|
return _context.abrupt("return");
|
|
27
27
|
|
|
28
28
|
case 3:
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
children = getField(item, 'children');
|
|
30
|
+
|
|
31
|
+
if (!(children && !children.length && !item.loaded)) {
|
|
32
|
+
_context.next = 9;
|
|
31
33
|
break;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
_context.next =
|
|
36
|
+
_context.next = 7;
|
|
35
37
|
return loadData(item);
|
|
36
38
|
|
|
37
|
-
case
|
|
39
|
+
case 7:
|
|
38
40
|
item.loaded = true;
|
|
39
41
|
instance.forceUpdate();
|
|
40
42
|
|
|
41
|
-
case
|
|
43
|
+
case 9:
|
|
42
44
|
case "end":
|
|
43
45
|
return _context.stop();
|
|
44
46
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, TypeDefs } from 'intact';
|
|
2
2
|
import { Sizes } from '../../styles/utils';
|
|
3
3
|
import { Container } from '../portal';
|
|
4
|
+
import { DropdownProps } from '../dropdown';
|
|
4
5
|
export interface ColorpickerProps {
|
|
5
6
|
value: string;
|
|
6
7
|
presets?: string[];
|
|
@@ -8,6 +9,7 @@ export interface ColorpickerProps {
|
|
|
8
9
|
disabled?: boolean;
|
|
9
10
|
container?: Container;
|
|
10
11
|
show?: boolean;
|
|
12
|
+
position?: DropdownProps['position'];
|
|
11
13
|
}
|
|
12
14
|
export interface ColorpickerEvents {
|
|
13
15
|
}
|