@king-design/intact 3.1.0-beta.2 → 3.1.0-beta.3
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/copy/index.spec.ts +28 -0
- package/components/copy/index.ts +2 -0
- package/components/copy/useCopy.ts +3 -1
- package/components/dialog/base.ts +1 -1
- package/components/dialog/base.vdt +2 -2
- package/components/dialog/styles.ts +1 -0
- package/components/menu/demos/basic.md +1 -1
- package/components/menu/item.vdt +17 -2
- package/components/menu/menu.ts +4 -0
- package/components/menu/menu.vdt +1 -1
- package/components/menu/styles.ts +19 -15
- package/components/menu/useDropdown.ts +3 -6
- package/components/table/row.vdt +2 -2
- package/components/table/table.vdt +1 -1
- package/components/tree/demos/draggable.md +63 -48
- package/components/tree/index.md +4 -3
- package/components/tree/index.spec.ts +39 -40
- package/components/tree/index.ts +8 -3
- package/components/tree/styles.ts +2 -0
- package/components/tree/useDraggable.ts +5 -5
- package/components/tree/useExpanded.ts +1 -1
- package/components/tree/useNodes.ts +1 -0
- package/components/treeSelect/index.md +7 -1
- package/components/treeSelect/index.ts +4 -0
- package/es/components/copy/index.d.ts +1 -0
- package/es/components/copy/index.js +2 -1
- package/es/components/copy/index.spec.js +64 -1
- package/es/components/copy/useCopy.d.ts +1 -1
- package/es/components/copy/useCopy.js +3 -1
- package/es/components/dialog/base.js +1 -1
- package/es/components/dialog/base.vdt.js +3 -3
- package/es/components/dialog/styles.js +1 -1
- package/es/components/menu/item.vdt.js +22 -2
- package/es/components/menu/menu.d.ts +1 -0
- package/es/components/menu/menu.js +2 -1
- package/es/components/menu/menu.vdt.js +1 -1
- package/es/components/menu/styles.d.ts +1 -0
- package/es/components/menu/styles.js +10 -2
- package/es/components/menu/useDropdown.js +3 -6
- package/es/components/table/row.vdt.js +1 -1
- package/es/components/table/table.vdt.js +1 -1
- package/es/components/tree/index.d.ts +5 -3
- package/es/components/tree/index.js +5 -0
- package/es/components/tree/index.spec.js +60 -39
- package/es/components/tree/styles.js +1 -1
- package/es/components/tree/useDraggable.js +12 -12
- package/es/components/tree/useExpanded.d.ts +1 -0
- package/es/components/tree/useExpanded.js +2 -1
- package/es/components/tree/useNodes.d.ts +1 -0
- package/es/components/treeSelect/index.d.ts +1 -0
- package/es/components/treeSelect/index.js +4 -0
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/menu/demos/basic/react.js +2 -2
- package/es/site/data/components/tree/demos/draggable/index.d.ts +23 -17
- package/es/site/data/components/tree/demos/draggable/index.js +45 -35
- package/es/site/data/components/tree/demos/draggable/react.d.ts +23 -17
- package/es/site/data/components/tree/demos/draggable/react.js +54 -35
- package/index.ts +2 -2
- package/package.json +2 -2
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import BasicDemo from '~/components/copy/demos/basic';
|
|
2
2
|
import {mount, unmount, dispatchEvent, wait, getElement} from '../../test/utils';
|
|
3
|
+
import { Tooltip } from '../tooltip';
|
|
4
|
+
import { Component } from 'intact';
|
|
5
|
+
import { Copy } from '.';
|
|
3
6
|
|
|
4
7
|
describe('Copy', () => {
|
|
5
8
|
afterEach(async () => {
|
|
@@ -18,4 +21,29 @@ describe('Copy', () => {
|
|
|
18
21
|
console.log(e);
|
|
19
22
|
}
|
|
20
23
|
});
|
|
24
|
+
|
|
25
|
+
it('wrap copy with tooltip', async () => {
|
|
26
|
+
class Demo extends Component {
|
|
27
|
+
static template = `
|
|
28
|
+
const { Tooltip, Copy } = this;
|
|
29
|
+
<Tooltip content="test">
|
|
30
|
+
<Copy text="test" />
|
|
31
|
+
</Tooltip>
|
|
32
|
+
`;
|
|
33
|
+
Tooltip = Tooltip;
|
|
34
|
+
Copy = Copy;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const [instance, element] = mount(Demo);
|
|
38
|
+
|
|
39
|
+
element.click();
|
|
40
|
+
await wait();
|
|
41
|
+
try {
|
|
42
|
+
const text = await navigator.clipboard.readText();
|
|
43
|
+
expect(text).to.eql('test');
|
|
44
|
+
} catch (e) {
|
|
45
|
+
// Read permisson denied
|
|
46
|
+
console.log(e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
21
49
|
});
|
package/components/copy/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface CopyProps {
|
|
|
12
12
|
export interface CopyEvents {
|
|
13
13
|
success: [string]
|
|
14
14
|
error: []
|
|
15
|
+
click: [MouseEvent]
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const typeDefs: Required<TypeDefs<CopyProps>> = {
|
|
@@ -26,6 +27,7 @@ const defaults = (): Partial<CopyProps> => ({
|
|
|
26
27
|
const events: Events<CopyEvents> = {
|
|
27
28
|
success: true,
|
|
28
29
|
error: true,
|
|
30
|
+
click: true,
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export class Copy extends Component<CopyProps, CopyEvents> {
|
|
@@ -11,7 +11,7 @@ export function useCopy() {
|
|
|
11
11
|
let timer: number;
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
|
-
startCopy: () => {
|
|
14
|
+
startCopy: (e: MouseEvent) => {
|
|
15
15
|
const { text, showMessage } = instance.get();
|
|
16
16
|
|
|
17
17
|
if (clipboardCopy(text) || commandCopy(text)) {
|
|
@@ -27,6 +27,8 @@ export function useCopy() {
|
|
|
27
27
|
success.set(false);
|
|
28
28
|
instance.trigger('error');
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
instance.trigger('click', e);
|
|
30
32
|
},
|
|
31
33
|
success,
|
|
32
34
|
};
|
|
@@ -26,7 +26,7 @@ import {Menu, MenuItem, Icon} from 'kpc';
|
|
|
26
26
|
</MenuItem>
|
|
27
27
|
<MenuItem key="2" disabled><Icon class="ion-star" />menu 2</MenuItem>
|
|
28
28
|
<MenuItem key="3">
|
|
29
|
-
<
|
|
29
|
+
<Icon class="ion-heart" />menu 3
|
|
30
30
|
<Menu>
|
|
31
31
|
<MenuItem key="3-1">sub menu 1</MenuItem>
|
|
32
32
|
<MenuItem key="3-2">sub menu 2</MenuItem>
|
package/components/menu/item.vdt
CHANGED
|
@@ -5,7 +5,7 @@ import {Icon} from '../icon';
|
|
|
5
5
|
import {Menu} from './menu';
|
|
6
6
|
import {getRestProps, expandAnimationCallbacks} from '../utils';
|
|
7
7
|
import {isNullOrUndefined} from 'intact-shared';
|
|
8
|
-
import {makeItemStyles, makeTitleStyles} from './styles';
|
|
8
|
+
import {makeItemStyles, makeTitleStyles, makeNestedMenuStyles} from './styles';
|
|
9
9
|
|
|
10
10
|
const rootMenu = this.rootMenu;
|
|
11
11
|
const {theme, type, dot: rootDot} = rootMenu.get();
|
|
@@ -18,6 +18,7 @@ const {
|
|
|
18
18
|
tooltipContents, iconVNode, titleVNodes,
|
|
19
19
|
position, isCollapse,
|
|
20
20
|
} = this.dropdown();
|
|
21
|
+
|
|
21
22
|
const { k } = this.config;
|
|
22
23
|
const classNameObj = {
|
|
23
24
|
[`${k}-menu-item`]: true,
|
|
@@ -48,7 +49,21 @@ const title = (children) => (
|
|
|
48
49
|
key="subMenu"
|
|
49
50
|
{...expandAnimationCallbacks}
|
|
50
51
|
>
|
|
51
|
-
{
|
|
52
|
+
{(() => {
|
|
53
|
+
if (subMenuVNode) {
|
|
54
|
+
const paddingLeft = this.parentMenu.get('_paddingLeft');
|
|
55
|
+
const [_classname, _paddingLeft] = makeNestedMenuStyles(k, showDot || !!iconVNode, paddingLeft);
|
|
56
|
+
const className = _$cn({
|
|
57
|
+
[_classname]: true,
|
|
58
|
+
[subMenuVNode.className]: subMenuVNode.className,
|
|
59
|
+
});
|
|
60
|
+
const clonedVNode = directClone(subMenuVNode);
|
|
61
|
+
clonedVNode.props = { ...clonedVNode.props, className, _paddingLeft };
|
|
62
|
+
clonedVNode.className = className;
|
|
63
|
+
|
|
64
|
+
return clonedVNode;
|
|
65
|
+
}
|
|
66
|
+
})()}
|
|
52
67
|
</Transition>
|
|
53
68
|
</template>
|
|
54
69
|
|
package/components/menu/menu.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface MenuProps<K extends Key = Key> {
|
|
|
12
12
|
size?: 'large' | 'default' | 'small'
|
|
13
13
|
accordion?: boolean
|
|
14
14
|
dot?: boolean
|
|
15
|
+
|
|
16
|
+
_paddingLeft?: string
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export interface MenuEvents { }
|
|
@@ -29,6 +31,8 @@ const typeDefs: Required<TypeDefs<MenuProps>> = {
|
|
|
29
31
|
size: ['large', 'default', 'small'],
|
|
30
32
|
accordion: Boolean,
|
|
31
33
|
dot: Boolean,
|
|
34
|
+
|
|
35
|
+
_paddingLeft: String,
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
const defaults = (): Partial<MenuProps> => ({
|
package/components/menu/menu.vdt
CHANGED
|
@@ -96,20 +96,6 @@ export function makeMenuStyles(k: string) {
|
|
|
96
96
|
font-size: ${menu.fontSize};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
// nested menu
|
|
100
|
-
&:not(.${k}-dropdown-menu) &:not(.${k}-dropdown-menu) {
|
|
101
|
-
width: auto;
|
|
102
|
-
background: ${menu.subBgColor};
|
|
103
|
-
.${k}-menu-title {
|
|
104
|
-
padding-left: calc(${getLeft(menu.item.padding)} + ${menu.icon.width} + ${menu.icon.gap});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
&:not(.${k}-dropdown-menu) &:not(.${k}-dropdown-menu) &:not(.${k}-dropdown-menu) {
|
|
108
|
-
.${k}-menu-title {
|
|
109
|
-
padding-left: calc(${getLeft(menu.item.padding)} + ${menu.icon.width} * 2 + ${menu.icon.gap});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
99
|
.${k}-icon {
|
|
114
100
|
width: ${menu.icon.width};
|
|
115
101
|
margin-right: ${menu.icon.gap};
|
|
@@ -244,7 +230,6 @@ export function makeItemStyles(k: string) {
|
|
|
244
230
|
.${k}-menu-title {
|
|
245
231
|
cursor: pointer;
|
|
246
232
|
height: ${menu.item.height};
|
|
247
|
-
transition: all ${menu.transition};
|
|
248
233
|
&:hover {
|
|
249
234
|
color: ${menu.item.hoverColor};
|
|
250
235
|
}
|
|
@@ -259,6 +244,9 @@ export function makeItemStyles(k: string) {
|
|
|
259
244
|
text-overflow: ellipsis;
|
|
260
245
|
min-width: 0;
|
|
261
246
|
}
|
|
247
|
+
.${k}-icon {
|
|
248
|
+
color: inherit;
|
|
249
|
+
}
|
|
262
250
|
}
|
|
263
251
|
.${k}-menu-arrow {
|
|
264
252
|
transition: transform ${menu.transition};
|
|
@@ -305,3 +293,19 @@ export function makeItemStyles(k: string) {
|
|
|
305
293
|
}
|
|
306
294
|
`
|
|
307
295
|
}
|
|
296
|
+
|
|
297
|
+
export function makeNestedMenuStyles(k: string, hasIcon: boolean, parentPaddingLeft: string = getLeft(menu.item.padding)) {
|
|
298
|
+
const paddingLeft = `${parentPaddingLeft}${hasIcon ? ' + ' + menu.icon.width : ''} + ${menu.icon.gap}`;
|
|
299
|
+
return [
|
|
300
|
+
css`
|
|
301
|
+
&.${k}-menu {
|
|
302
|
+
width: auto;
|
|
303
|
+
background: ${menu.subBgColor};
|
|
304
|
+
.${k}-menu-title {
|
|
305
|
+
padding-left: calc(${paddingLeft});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
`,
|
|
309
|
+
paddingLeft,
|
|
310
|
+
]
|
|
311
|
+
}
|
|
@@ -45,16 +45,13 @@ export function useDropdown(rootMenu: Menu, parentMenu: Menu) {
|
|
|
45
45
|
eachChildren(children, vNode => {
|
|
46
46
|
if (isComponentVNode(vNode, Menu)) {
|
|
47
47
|
subMenuVNode = vNode;
|
|
48
|
-
} else if (isTopItem && isCollapse) {
|
|
49
|
-
if (isStringOrNumberNotEmpty(vNode) || isTextVNode(vNode)) {
|
|
50
|
-
tooltipContents.push(vNode);
|
|
51
|
-
} else if (!iconVNode && isComponentVNode(vNode, Icon)) {
|
|
52
|
-
iconVNode = vNode;
|
|
53
|
-
}
|
|
54
48
|
} else {
|
|
55
49
|
if (isStringOrNumberNotEmpty(vNode) || isTextVNode(vNode)) {
|
|
56
50
|
// wrap with span for showing text ellipsis
|
|
57
51
|
vNode = createVNode('span', null, vNode);
|
|
52
|
+
tooltipContents.push(vNode);
|
|
53
|
+
} else if (!iconVNode && isComponentVNode(vNode, Icon)) {
|
|
54
|
+
iconVNode = vNode;
|
|
58
55
|
}
|
|
59
56
|
titleVNodes.push(vNode);
|
|
60
57
|
}
|
package/components/table/row.vdt
CHANGED
|
@@ -39,8 +39,8 @@ const pushCheckTypeVNode = (children) => {
|
|
|
39
39
|
<td key="$checktype"
|
|
40
40
|
{...getClassAndStyleForFixed({
|
|
41
41
|
fixed: hasFixedLeft ? 'left' : false,
|
|
42
|
-
className: [`${k}-table-check`]
|
|
43
|
-
}, 0)}
|
|
42
|
+
className: [`${k}-table-check`],
|
|
43
|
+
}, 0, k)}
|
|
44
44
|
{...spans}
|
|
45
45
|
>{children}</td>
|
|
46
46
|
)
|
|
@@ -8,7 +8,7 @@ order: 6
|
|
|
8
8
|
触发`denydrag`和`denydrop`事件来告知用户
|
|
9
9
|
|
|
10
10
|
```vdt
|
|
11
|
-
import {Tree, Input} from 'kpc';
|
|
11
|
+
import {Tree, Input, Icon} from 'kpc';
|
|
12
12
|
|
|
13
13
|
<Tree
|
|
14
14
|
draggable
|
|
@@ -19,11 +19,22 @@ import {Tree, Input} from 'kpc';
|
|
|
19
19
|
ev-denydrop={this.onDenyDrop}
|
|
20
20
|
v-model:data='data'
|
|
21
21
|
v-model:expandedKeys="expandedKeys"
|
|
22
|
-
|
|
22
|
+
>
|
|
23
|
+
<b:label args="[data, node]">
|
|
24
|
+
<Icon v-if={data.type === 'file'} class="k-icon-paper" />
|
|
25
|
+
<Icon v-else class="k-icon-folder" />
|
|
26
|
+
{data.label}
|
|
27
|
+
</b:label>
|
|
28
|
+
</Tree>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```styl
|
|
32
|
+
.k-tree-text .k-icon
|
|
33
|
+
margin-right 8px
|
|
23
34
|
```
|
|
24
35
|
|
|
25
36
|
```ts
|
|
26
|
-
import {Message, TreeDataItem, TreeNode, TreeDragEndData} from 'kpc';
|
|
37
|
+
import {Message, TreeDataItem, TreeNode, TreeDragEndData, TreeMode} from 'kpc';
|
|
27
38
|
|
|
28
39
|
interface Props {
|
|
29
40
|
data?: TreeDataItem<string>[]
|
|
@@ -37,58 +48,52 @@ export default class extends Component<Props> {
|
|
|
37
48
|
return {
|
|
38
49
|
data: [
|
|
39
50
|
{
|
|
40
|
-
label: '
|
|
41
|
-
key: '
|
|
51
|
+
label: '总览',
|
|
52
|
+
key: 'summarization',
|
|
53
|
+
type: 'file',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
label: '产品简介',
|
|
57
|
+
key: 'introduction',
|
|
58
|
+
type: 'file',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
label: '技术实现',
|
|
62
|
+
key: 'implemention',
|
|
63
|
+
type: 'file',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
label: '操作指南',
|
|
67
|
+
key: 'guide',
|
|
68
|
+
type: 'dir',
|
|
42
69
|
children: [
|
|
43
70
|
{
|
|
44
|
-
label: '
|
|
45
|
-
key: '
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
label: 'This node can not be dragged and dropped.',
|
|
49
|
-
key: '1-1-1'
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
71
|
+
label: '产品安装',
|
|
72
|
+
key: 'installation',
|
|
73
|
+
type: 'file',
|
|
74
|
+
},
|
|
53
75
|
]
|
|
54
76
|
},
|
|
55
77
|
{
|
|
56
|
-
label: '
|
|
57
|
-
key: '
|
|
78
|
+
label: '接入说明',
|
|
79
|
+
key: 'interaction',
|
|
80
|
+
type: 'dir',
|
|
58
81
|
children: [
|
|
59
82
|
{
|
|
60
|
-
label: '
|
|
61
|
-
key: '
|
|
62
|
-
|
|
63
|
-
{
|
|
64
|
-
label: 'Third floor-2.1.1',
|
|
65
|
-
key: '2-1-1'
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
label: 'Third floor-2.1.2',
|
|
69
|
-
key: '2-1-2'
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
label: 'Second floor-2.2',
|
|
75
|
-
key: '2-2',
|
|
76
|
-
children: [
|
|
77
|
-
{
|
|
78
|
-
label: 'Third floor-2.2.1',
|
|
79
|
-
key: '2-2-1'
|
|
80
|
-
}
|
|
81
|
-
]
|
|
83
|
+
label: '使用',
|
|
84
|
+
key: 'usage',
|
|
85
|
+
type: 'file',
|
|
82
86
|
},
|
|
83
|
-
{
|
|
84
|
-
label: 'Second floor-2.3',
|
|
85
|
-
key: '2-3',
|
|
86
|
-
disabled: true
|
|
87
|
-
}
|
|
88
87
|
]
|
|
89
|
-
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
label: '禁用文件',
|
|
91
|
+
key: 'disabled',
|
|
92
|
+
type: 'file',
|
|
93
|
+
disabled: true,
|
|
94
|
+
},
|
|
90
95
|
],
|
|
91
|
-
expandedKeys: [
|
|
96
|
+
expandedKeys: [],
|
|
92
97
|
};
|
|
93
98
|
}
|
|
94
99
|
|
|
@@ -97,11 +102,21 @@ export default class extends Component<Props> {
|
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
allowDrag(node: TreeNode<string>) {
|
|
100
|
-
return node.key !== '
|
|
105
|
+
return node.key !== 'summarization';
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
allowDrop(node: TreeNode<string
|
|
104
|
-
|
|
108
|
+
allowDrop(node: TreeNode<string>, srcNode: TreeNode<string>, mode: TreeMode) {
|
|
109
|
+
// 能够将文件拖入文件夹,但是不能讲文件夹拖入文件夹
|
|
110
|
+
if (mode === TreeMode.Inner) {
|
|
111
|
+
// 文件拖入文件夹
|
|
112
|
+
return srcNode.data.type === 'file' && node.data.type === 'dir';
|
|
113
|
+
} else if (srcNode.data.type === 'dir' && node.parent) {
|
|
114
|
+
// 此时插入模式是,前面或者后面插入
|
|
115
|
+
// 如果拖动的是文件夹,但是目标节点存在父元素,代表目标节点也是文件夹,不能插入
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return true;
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
onDenyDrag(node: TreeNode<string>) {
|
package/components/tree/index.md
CHANGED
|
@@ -14,7 +14,7 @@ sidebar: doc
|
|
|
14
14
|
| uncorrelated | 是否让父子`checkbox`选中状态互不关联 | `boolean` | `false` |
|
|
15
15
|
| checkedKeys | 通过`key`指定勾选的数据节点 | `K[]` | `undefined` |
|
|
16
16
|
| expandedKeys | 通过`key`指定展开的数据节点 | `K[]` | `undefined` |
|
|
17
|
-
| defaultExpandAll | 是否默认展开所有节点 | `boolean` | `false` |
|
|
17
|
+
| defaultExpandAll | 是否默认展开所有节点 (该属性只在首次渲染时起作用,渲染后再更新数据`data`,没有效果) | `boolean` | `false` |
|
|
18
18
|
| selectable | 节点是否可选中,默认为`true`可选中 | `boolean` | `true` |
|
|
19
19
|
| selectedKeys | 通过`key`指定选中的数据节点 | `K[]` | `undefined` |
|
|
20
20
|
| multiple | `selectedKeys`是否支持多选 | `boolean` | `false` |
|
|
@@ -23,7 +23,7 @@ sidebar: doc
|
|
|
23
23
|
| showLine | 是否展示左侧对齐线 | `boolean` | `true` |
|
|
24
24
|
| draggable | 是否支持拖拽 | `boolean` | `false` |
|
|
25
25
|
| allowDrag | 指定哪些节点可拖拽 | `(node: TreeNode<K>) => boolean` | `undefined` |
|
|
26
|
-
| allowDrop | 指定哪些节点可以插入子节点 | `(node: TreeNode<K
|
|
26
|
+
| allowDrop | 指定哪些节点可以插入子节点 | `(node: TreeNode<K>, srcNode: TreeNode[K]) => boolean` | `undefined` |
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
29
|
import {Key, Children} from 'intact';
|
|
@@ -82,6 +82,7 @@ export class TreeNode<K extends Key> {
|
|
|
82
82
|
| expand | 展开节点 | `(key: K) => void`,`key` 要展开的节点的key | `undefined` |
|
|
83
83
|
| shrink | 收起节点 | `(key: K) => void`,`key` 要收起的节点的key | `undefined` |
|
|
84
84
|
| getNodes | 返回一级节点 | `() => TreeNode<K>[]` | `TreeNode<K>[]` 一级节点数组 |
|
|
85
|
+
| expandAll | 展开所有节点 | `() => void` | `undefined` |
|
|
85
86
|
|
|
86
87
|
# 事件
|
|
87
88
|
|
|
@@ -89,7 +90,7 @@ export class TreeNode<K extends Key> {
|
|
|
89
90
|
| --- | --- | --- |
|
|
90
91
|
| dragend | 拖拽完成触发 | `DragEndData<K>`,`{srcNode: '源节点', toNode: '目标节点', mode: '插入模式, Before: 插入节点前面, After: 插入节点后面, Inner: 插入节点内部'}` |
|
|
91
92
|
| denydrag | 拖拽不允许拖拽的节点触发 | `TreeNode<K>` |
|
|
92
|
-
| denydrop | 插入到不允许插入的节点时触发 | `TreeNode
|
|
93
|
+
| denydrop | 插入到不允许插入的节点时触发 | `(node: TreeNode[K], srcNode: TreeNode[K], mode: TreeMode)`,`node`: 当前要插入的目的节点, `srcNode`: 当前拖拽的节点,`mode`: 插入模式 |
|
|
93
94
|
|
|
94
95
|
```ts
|
|
95
96
|
import {Key} from 'intact';
|
|
@@ -181,57 +181,56 @@ describe('Tree', () => {
|
|
|
181
181
|
|
|
182
182
|
const [instance, element] = mount(DraggableDemo);
|
|
183
183
|
|
|
184
|
-
instance.set('expandedKeys', ['
|
|
184
|
+
instance.set('expandedKeys', ['guide']);
|
|
185
185
|
await wait(500);
|
|
186
186
|
|
|
187
|
+
let [notAllowed, file1, file2, dir1, file3, dir2, disabled]= element.querySelectorAll('.k-tree-label') as NodeListOf<HTMLElement>;
|
|
187
188
|
// can not drag disabled item
|
|
188
|
-
const disabled = element.querySelector('.k-disabled') as HTMLElement;
|
|
189
|
-
// dispatchEvent(disabled, 'mousedown');
|
|
190
189
|
dispatchEvent(disabled, 'dragstart');
|
|
191
190
|
expect(onDenyDrag.callCount).to.eql(1);
|
|
192
191
|
|
|
193
|
-
let nodes = element.querySelectorAll('.k-tree-label') as NodeListOf<HTMLElement>;
|
|
194
192
|
|
|
195
193
|
// can not drag not-allowed item
|
|
196
|
-
const notAllowed = nodes[2];
|
|
197
|
-
// dispatchEvent(notAllowed, 'mousedown');
|
|
198
194
|
dispatchEvent(notAllowed, 'dragstart');
|
|
199
195
|
expect(onDenyDrag.callCount).to.eql(2);
|
|
200
196
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
197
|
+
await dragInsert(dir1, dir1);
|
|
198
|
+
// drag to self will do nothing
|
|
199
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
200
|
+
expect(onDragEnd.callCount).to.eql(0);
|
|
201
|
+
|
|
202
|
+
await dragInsert(file1, notAllowed);
|
|
203
|
+
// drag to not-allowed item will do nothing
|
|
204
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
205
|
+
expect(onDragEnd.callCount).to.eql(0);
|
|
206
|
+
|
|
207
|
+
await dragInsert(file1, disabled);
|
|
208
|
+
// drag to disabled item will do nothing
|
|
209
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
210
|
+
expect(onDragEnd.callCount).to.eql(0);
|
|
211
|
+
|
|
212
|
+
await dragInsert(file2, file1, 'before');
|
|
213
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
214
|
+
expect(onDragEnd.callCount).to.eql(1);
|
|
215
|
+
expect(instance.get('data')).to.matchSnapshot();
|
|
216
|
+
|
|
217
|
+
await dragInsert(file2, file1, 'after');
|
|
218
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
219
|
+
expect(onDragEnd.callCount).to.eql(2);
|
|
220
|
+
expect(instance.get('data')).to.matchSnapshot();
|
|
221
|
+
|
|
222
|
+
await dragInsert(file1, dir1);
|
|
223
|
+
expect(onDragEnd.callCount).to.eql(3);
|
|
224
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
225
|
+
expect(instance.get('data')).to.matchSnapshot();
|
|
226
|
+
|
|
227
|
+
await dragInsert(dir2, dir1);
|
|
228
|
+
expect(onDragEnd.callCount).to.eql(3);
|
|
229
|
+
expect(onDenyDrag.callCount).to.eql(2);
|
|
230
|
+
|
|
231
|
+
await dragInsert(dir2, file3, 'before');
|
|
232
|
+
expect(onDragEnd.callCount).to.eql(3);
|
|
233
|
+
expect(onDenyDrag.callCount).to.eql(2);
|
|
235
234
|
});
|
|
236
235
|
});
|
|
237
236
|
|
package/components/tree/index.ts
CHANGED
|
@@ -14,9 +14,10 @@ import { useConfigContext } from '../config';
|
|
|
14
14
|
export type {
|
|
15
15
|
Node as TreeNode,
|
|
16
16
|
DataItem as TreeDataItem,
|
|
17
|
-
Mode as TreeMode,
|
|
18
17
|
};
|
|
19
18
|
|
|
19
|
+
export { Mode as TreeMode };
|
|
20
|
+
|
|
20
21
|
export interface TreeProps<K extends Key = Key> {
|
|
21
22
|
data?: DataItem<K>[]
|
|
22
23
|
filter?: Filter<K>
|
|
@@ -32,12 +33,12 @@ export interface TreeProps<K extends Key = Key> {
|
|
|
32
33
|
showLine?: boolean
|
|
33
34
|
draggable?: boolean
|
|
34
35
|
allowDrag?: (node: Node<K>) => boolean
|
|
35
|
-
allowDrop?: (node: Node<K
|
|
36
|
+
allowDrop?: (node: Node<K>, srcNode: Node<K>, mode: Mode) => boolean
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export interface TreeEvents<K extends Key> {
|
|
39
40
|
denydrag: [Node<K>]
|
|
40
|
-
denydrop: [Node<K
|
|
41
|
+
denydrop: [Node<K>, Node<K>, Mode]
|
|
41
42
|
dragend: [DragEndData<K>]
|
|
42
43
|
transitionEnd: []
|
|
43
44
|
}
|
|
@@ -125,6 +126,10 @@ export class Tree<K extends Key = Key> extends Component<TreeProps<K>, TreeEvent
|
|
|
125
126
|
return this.nodes.getNodes() as Node<K>[];
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
public expandAll() {
|
|
130
|
+
this.expanded.expandAll();
|
|
131
|
+
}
|
|
132
|
+
|
|
128
133
|
@bind
|
|
129
134
|
private onClick(node: Node<K>) {
|
|
130
135
|
if (node.data.disabled) return;
|
|
@@ -59,15 +59,15 @@ export function useDraggable() {
|
|
|
59
59
|
mode.set(newMode);
|
|
60
60
|
overKey.set(node.key);
|
|
61
61
|
|
|
62
|
-
// if the node does not allow drop, prevent the dragging
|
|
63
|
-
if (mode.value === Mode.Inner) {
|
|
62
|
+
// if the node does not allow drop, prevent the dragging node from inserting to it
|
|
63
|
+
// if (mode.value === Mode.Inner) {
|
|
64
64
|
const {allowDrop} = instance.get();
|
|
65
|
-
if (node.data.disabled || allowDrop && !allowDrop(node)) {
|
|
66
|
-
instance.trigger('denydrop', node);
|
|
65
|
+
if (node.data.disabled || allowDrop && !allowDrop(node, draggingNode!, newMode)) {
|
|
66
|
+
instance.trigger('denydrop', node, draggingNode!, newMode);
|
|
67
67
|
valid = false;
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
-
}
|
|
70
|
+
// }
|
|
71
71
|
|
|
72
72
|
valid = true;
|
|
73
73
|
}
|