@king-design/intact 3.1.0-beta.2 → 3.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.vdt +1 -0
- package/components/config/demos/basic.md +19 -0
- package/components/config/index.md +20 -0
- package/components/config/index.ts +8 -4
- 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/index.spec.ts +41 -2
- package/components/dialog/styles.ts +1 -0
- package/components/drawer/index.spec.ts +4 -2
- package/components/icon/demos/icons.md +20 -9
- package/components/input/demos/blocks.md +16 -1
- package/components/input/styles.ts +2 -1
- 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/portal.ts +6 -1
- package/components/table/row.vdt +2 -2
- package/components/table/styles.ts +2 -0
- package/components/table/table.vdt +1 -1
- package/components/tree/demos/draggable.md +63 -48
- package/components/tree/demos/expandAll.md +36 -8
- package/components/tree/index.md +3 -2
- 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 +15 -3
- package/components/tree/useNodes.ts +1 -0
- package/components/treeSelect/index.md +7 -1
- package/components/treeSelect/index.ts +4 -0
- package/components/upload/demos/files.md +14 -12
- package/components/upload/index.md +5 -5
- package/components/upload/index.ts +6 -5
- package/components/upload/useFiles.ts +19 -8
- package/es/components/cascader/index.vdt.js +1 -0
- package/es/components/config/index.d.ts +9 -2
- package/es/components/config/index.js +4 -3
- 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/index.spec.js +87 -5
- package/es/components/dialog/styles.js +1 -1
- package/es/components/drawer/index.spec.js +6 -4
- package/es/components/input/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/portal.js +7 -1
- package/es/components/table/row.vdt.js +1 -1
- package/es/components/table/styles.js +3 -2
- 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 +23 -7
- 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/components/upload/index.d.ts +6 -5
- package/es/components/upload/index.js +1 -0
- package/es/components/upload/useFiles.js +21 -8
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/config/demos/basic/index.d.ts +5 -0
- package/es/site/data/components/config/demos/basic/index.js +17 -0
- package/es/site/data/components/config/demos/basic/react.d.ts +4 -0
- package/es/site/data/components/config/demos/basic/react.js +29 -0
- package/es/site/data/components/config/index.d.ts +57 -0
- package/es/site/data/components/config/index.js +42 -0
- package/es/site/data/components/icon/demos/icons/index.js +3 -2
- package/es/site/data/components/input/demos/blocks/react.js +11 -1
- 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 +55 -36
- package/es/site/data/components/tree/demos/expandAll/index.d.ts +9 -1
- package/es/site/data/components/tree/demos/expandAll/index.js +14 -2
- package/es/site/data/components/tree/demos/expandAll/react.d.ts +10 -1
- package/es/site/data/components/tree/demos/expandAll/react.js +24 -5
- package/es/site/data/components/upload/demos/files/index.d.ts +2 -5
- package/es/site/data/components/upload/demos/files/index.js +5 -1
- package/es/site/data/components/upload/demos/files/react.d.ts +2 -5
- package/es/site/data/components/upload/demos/files/react.js +13 -2
- package/es/site/src/pages/document/styles.js +1 -1
- package/index.ts +2 -2
- package/package.json +2 -2
- package/es/site/data/components/icon/demos/icons/react.d.ts +0 -15
- package/es/site/data/components/icon/demos/icons/react.js +0 -107
|
@@ -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>) {
|
|
@@ -5,19 +5,40 @@ order: 7
|
|
|
5
5
|
|
|
6
6
|
给组件添加`defaultExpandAll`属性,可以默认展开所有节点
|
|
7
7
|
|
|
8
|
-
> 仅限首次渲染`Tree`时生效,后续添加节点不会默认展开
|
|
8
|
+
> `@before v3.1.0` 仅限首次渲染`Tree`时生效,后续添加节点不会默认展开
|
|
9
|
+
> `@since v3.1.0` 当首次渲染时,如果不存在`data`或者`data`为空数组,则待接收到新的`data`后,展开所有节点
|
|
9
10
|
|
|
10
11
|
```vdt
|
|
11
|
-
import {Tree} from 'kpc';
|
|
12
|
+
import {Tree, Button} from 'kpc';
|
|
12
13
|
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
<div class="wrapper">
|
|
15
|
+
<Tree
|
|
16
|
+
defaultExpandAll
|
|
17
|
+
data={this.get('data')}
|
|
18
|
+
/>
|
|
19
|
+
<Tree
|
|
20
|
+
defaultExpandAll
|
|
21
|
+
data={this.get('delayData')}
|
|
22
|
+
/>
|
|
23
|
+
<Button ev-click={this.load}>加载数据</Button>
|
|
24
|
+
</div>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```styl
|
|
28
|
+
.wrapper
|
|
29
|
+
display flex
|
|
30
|
+
gap 18px
|
|
17
31
|
```
|
|
18
32
|
|
|
19
33
|
```ts
|
|
20
|
-
|
|
34
|
+
import {bind, TreeDataItem} from 'kpc';
|
|
35
|
+
|
|
36
|
+
interface Props {
|
|
37
|
+
data: TreeDataItem<string>[]
|
|
38
|
+
delayData?: TreeDataItem<string>[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default class extends Component<Props> {
|
|
21
42
|
static template = template;
|
|
22
43
|
static defaults() {
|
|
23
44
|
return {
|
|
@@ -62,8 +83,15 @@ export default class extends Component {
|
|
|
62
83
|
}
|
|
63
84
|
]
|
|
64
85
|
}
|
|
65
|
-
]
|
|
86
|
+
],
|
|
87
|
+
|
|
88
|
+
delayData: undefined
|
|
66
89
|
}
|
|
67
90
|
}
|
|
91
|
+
|
|
92
|
+
@bind
|
|
93
|
+
load() {
|
|
94
|
+
this.set('delayData', this.get('data'));
|
|
95
|
+
}
|
|
68
96
|
}
|
|
69
97
|
```
|
package/components/tree/index.md
CHANGED
|
@@ -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
|
}
|
|
@@ -11,8 +11,20 @@ export function useExpanded(getNodes: () => Node<Key>[]) {
|
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
onBeforeMount(() => {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* change the behavior
|
|
16
|
+
* if the data is undefined, we expand all keys after we received data
|
|
17
|
+
*/
|
|
18
|
+
const { defaultExpandAll, data } = instance.get();
|
|
19
|
+
if (defaultExpandAll) {
|
|
20
|
+
if (data && data.length) {
|
|
21
|
+
expandAll();
|
|
22
|
+
} else {
|
|
23
|
+
instance.on(`$receive:data`, function cb() {
|
|
24
|
+
expandAll();
|
|
25
|
+
instance.off(`$receive:data`, cb);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
16
28
|
}
|
|
17
29
|
});
|
|
18
30
|
|
|
@@ -55,5 +67,5 @@ export function useExpanded(getNodes: () => Node<Key>[]) {
|
|
|
55
67
|
instance.set('expandedKeys', Array.from(expandedKeys));
|
|
56
68
|
}
|
|
57
69
|
|
|
58
|
-
return {get: () => expandedKeys, toggle};
|
|
70
|
+
return {get: () => expandedKeys, toggle, expandAll};
|
|
59
71
|
}
|
|
@@ -29,7 +29,7 @@ sidebar: doc
|
|
|
29
29
|
| uncorrelated | 是否让父子`checkbox`选中状态互不关联 | `boolean` | `false` |
|
|
30
30
|
| load | 指定异步加载节点数据的函数,该函数通过`Promise`返回数组来添加子节点数据 | <code>(node: TreeNode<K>) => Proomise<void> | void</code> | `undefined` |
|
|
31
31
|
| showLine | 是否展示`Tree`的对齐线 | `boolean` | `true` |
|
|
32
|
-
| defaultExpandAll | 是否默认展开所有节点 | `boolean` | `
|
|
32
|
+
| defaultExpandAll | 是否默认展开所有节点 | `boolean` | `false` |
|
|
33
33
|
| checkbox | 是否展示复选框 | `boolean` | `false` |
|
|
34
34
|
| filter | 当支持筛选时,可以自定义筛选规则 | `(keywords: string, data: TreeDataItem<K>) => boolean` | `undefined` |
|
|
35
35
|
| show | 是否展示菜单项 | `boolean` | `false` |
|
|
@@ -74,6 +74,12 @@ type Collision = 'fit' | 'flip' | 'flipfit' | 'none'
|
|
|
74
74
|
import {Children} from 'intact';
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
# 方法
|
|
78
|
+
|
|
79
|
+
| 方法名 | 说明 | 参数 | 返回值 |
|
|
80
|
+
| --- | --- | --- | --- |
|
|
81
|
+
| expandAll | 展开所有节点 | `() => void` | `undefined` |
|
|
82
|
+
|
|
77
83
|
# 事件
|
|
78
84
|
|
|
79
85
|
| 事件名 | 说明 | 参数 |
|
|
@@ -3,16 +3,20 @@ title: 定义初始化列表
|
|
|
3
3
|
order: 3
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
你可以通过`
|
|
7
|
-
1. `name`
|
|
8
|
-
2. `url` 文件对应的url
|
|
6
|
+
你可以通过`files`定义初始化上传列表,该属性取值为数组,数组每一项结构如下:
|
|
7
|
+
1. `name` 文件名,必填
|
|
8
|
+
2. `url` 文件对应的url地址,非必填
|
|
9
|
+
3. `status` 状态`UploadFileStatus`,默认成功,非必填
|
|
10
|
+
4. `uid` 文件唯一标识id,非必填
|
|
11
|
+
|
|
12
|
+
> @since 3.1.0,defaultFiles已被废弃,使用files来代替,支持响应式更新
|
|
9
13
|
|
|
10
14
|
```vdt
|
|
11
15
|
import {Upload} from 'kpc';
|
|
12
16
|
|
|
13
17
|
<Upload multiple
|
|
14
18
|
action="//fakestoreapi.com/products"
|
|
15
|
-
|
|
19
|
+
v-model:files="files"
|
|
16
20
|
/>
|
|
17
21
|
```
|
|
18
22
|
|
|
@@ -22,22 +26,20 @@ import {Upload} from 'kpc';
|
|
|
22
26
|
```
|
|
23
27
|
|
|
24
28
|
```ts
|
|
25
|
-
|
|
26
|
-
defaultFiles: DefaultFile[]
|
|
27
|
-
}
|
|
29
|
+
import {UploadFileStatus, UploadFile} from 'kpc';
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
url: string
|
|
31
|
+
interface Props {
|
|
32
|
+
files?: UploadFile[]
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export default class extends Component<Props> {
|
|
35
36
|
static template = template;
|
|
36
37
|
static defaults() {
|
|
37
38
|
return {
|
|
38
|
-
|
|
39
|
+
files: [
|
|
39
40
|
{name: 'test1.jpg', url: 'http://www.example.com/test1.jpg'},
|
|
40
|
-
{name: 'test2.png', url: 'http://www.example.com/test2.png'}
|
|
41
|
+
{name: 'test2.png', url: 'http://www.example.com/test2.png'},
|
|
42
|
+
{name: 'test3.png', status: UploadFileStatus.Error},
|
|
41
43
|
]
|
|
42
44
|
} as Props;
|
|
43
45
|
}
|
|
@@ -11,7 +11,7 @@ sidebar: doc
|
|
|
11
11
|
| --- | --- | --- | --- |
|
|
12
12
|
| accept | `input`的[accept](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept)属性,支持的文件的类型 | `string` | `undefined` |
|
|
13
13
|
| files | 所有已上传和待上传的文件列表 | `UploadFile[]` | `[]` |
|
|
14
|
-
| defaultFiles | 指定初始化上传列表,见示例 | <code>(Partial<UploadFile> & Pick<UploadFile, 'name' | 'url'>)[]</code> | `undefined` |
|
|
14
|
+
| defaultFiles `@deprecated` | 指定初始化上传列表,见示例 | <code>(Partial<UploadFile> & Pick<UploadFile, 'name' | 'url'>)[]</code> | `undefined` |
|
|
15
15
|
| maxSize | 最大上传文件大小限制(kb),默认无限制 | `number` | `undefined` |
|
|
16
16
|
| limit | 最大上传文件数量限制,默认无限制 | `number` | `undefined` |
|
|
17
17
|
| autoUpload | 是否选择文件后即自动上传 | `boolean` | `true` |
|
|
@@ -29,13 +29,13 @@ sidebar: doc
|
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
31
|
export type UploadFile = {
|
|
32
|
-
status
|
|
32
|
+
status?: UploadFileStatus
|
|
33
33
|
type?: string
|
|
34
34
|
size?: number
|
|
35
35
|
name: string
|
|
36
|
-
percent
|
|
37
|
-
uid
|
|
38
|
-
raw
|
|
36
|
+
percent?: number
|
|
37
|
+
uid?: number
|
|
38
|
+
raw?: File | Partial<UploadFile>
|
|
39
39
|
url?: string
|
|
40
40
|
request?: any
|
|
41
41
|
}
|
|
@@ -10,7 +10,8 @@ import type {RequestError} from './ajaxUploader';
|
|
|
10
10
|
import type {Events} from '../types';
|
|
11
11
|
import { useConfigContext } from '../config';
|
|
12
12
|
|
|
13
|
-
export type {RequestError
|
|
13
|
+
export type {RequestError};
|
|
14
|
+
export {UploadFileStatus};
|
|
14
15
|
|
|
15
16
|
export interface UploadProps {
|
|
16
17
|
accept?: string
|
|
@@ -45,13 +46,13 @@ export interface UploadBlocks {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export type UploadFile = {
|
|
48
|
-
status
|
|
49
|
+
status?: UploadFileStatus
|
|
49
50
|
type?: string
|
|
50
51
|
size?: number
|
|
51
52
|
name: string
|
|
52
|
-
percent
|
|
53
|
-
uid
|
|
54
|
-
raw
|
|
53
|
+
percent?: number
|
|
54
|
+
uid?: number | string
|
|
55
|
+
raw?: File | Partial<UploadFile>
|
|
55
56
|
url?: string
|
|
56
57
|
request?: any
|
|
57
58
|
}
|
|
@@ -17,21 +17,22 @@ export function useFiles(
|
|
|
17
17
|
const {files, defaultFiles} = instance.get();
|
|
18
18
|
const _files = files!.slice(0);
|
|
19
19
|
if (defaultFiles) {
|
|
20
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
+
console.warn(`'defaultFiles' is deprecated, use 'files' instead for reactive updating.`)
|
|
22
|
+
}
|
|
20
23
|
defaultFiles.forEach(file => {
|
|
21
|
-
_files.push(
|
|
22
|
-
status: UploadFileStatus.Done,
|
|
23
|
-
name: file.name,
|
|
24
|
-
percent: 100,
|
|
25
|
-
uid: uid++,
|
|
26
|
-
raw: file,
|
|
27
|
-
url: file.url,
|
|
28
|
-
});
|
|
24
|
+
_files.push(normalizeFile(file));
|
|
29
25
|
});
|
|
30
26
|
|
|
31
27
|
instance.set('files', _files);
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
30
|
|
|
31
|
+
instance.on(`$receive:files`, (files) => {
|
|
32
|
+
if (!files) return;
|
|
33
|
+
instance.set('files', files.map(normalizeFile));
|
|
34
|
+
});
|
|
35
|
+
|
|
35
36
|
async function addFiles(fileList: FileList) {
|
|
36
37
|
const files = instance.get('files')!.slice(0);
|
|
37
38
|
const newFiles = Array.from(fileList);
|
|
@@ -100,3 +101,13 @@ export function useFiles(
|
|
|
100
101
|
|
|
101
102
|
return {addFiles, removeFile};
|
|
102
103
|
}
|
|
104
|
+
|
|
105
|
+
function normalizeFile(file: UploadFile) {
|
|
106
|
+
return {
|
|
107
|
+
status: UploadFileStatus.Done,
|
|
108
|
+
percent: 100,
|
|
109
|
+
uid: uid++,
|
|
110
|
+
raw: file,
|
|
111
|
+
...file
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -21,6 +21,7 @@ export default function ($props, $blocks, $__proto__) {
|
|
|
21
21
|
fields = _this$get.fields;
|
|
22
22
|
|
|
23
23
|
var k = this.config.k;
|
|
24
|
+
var baseMenuStyles = makeMenuStyles(k);
|
|
24
25
|
var classNameObj = (_classNameObj = {}, _classNameObj[k + "-cascader-menu"] = true, _classNameObj[makeMenuStyles(k)] = true, _classNameObj);
|
|
25
26
|
var getField = this.fields;
|
|
26
27
|
|