@progress/kendo-vue-treeview 3.2.2 → 3.2.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/dist/cdn/js/kendo-vue-treeview.js +1 -1
- package/dist/es/TreeView.d.ts +2 -1
- package/dist/es/TreeView.js +39 -36
- package/dist/es/TreeViewDragAnalyzer.d.ts +0 -85
- package/dist/es/TreeViewDragAnalyzer.js +1 -86
- package/dist/es/TreeViewItem.js +58 -21
- package/dist/es/TreeViewProps.d.ts +4 -0
- package/dist/es/package-metadata.js +1 -1
- package/dist/npm/TreeView.d.ts +2 -1
- package/dist/npm/TreeView.js +38 -35
- package/dist/npm/TreeViewDragAnalyzer.d.ts +0 -85
- package/dist/npm/TreeViewDragAnalyzer.js +1 -86
- package/dist/npm/TreeViewItem.js +56 -19
- package/dist/npm/TreeViewProps.d.ts +4 -0
- package/dist/npm/package-metadata.js +1 -1
- package/package.json +6 -6
|
@@ -4,91 +4,6 @@ var DROPZONE_BOUNDARY_DELTA = 6;
|
|
|
4
4
|
* A class which provides an API for analyzing the `drag` events
|
|
5
5
|
* of the TreeView.
|
|
6
6
|
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```jsx
|
|
9
|
-
* class App extends React.Component {
|
|
10
|
-
* dragClue;
|
|
11
|
-
* state = { tree };
|
|
12
|
-
*
|
|
13
|
-
* render() {
|
|
14
|
-
* return (
|
|
15
|
-
* <div>
|
|
16
|
-
* <TreeView data={this.state.tree} draggable={true}
|
|
17
|
-
* onItemDragOver={this.onItemDragOver} onItemDragEnd={this.onItemDragEnd} />
|
|
18
|
-
* <TreeViewDragClue ref={dragClue => this.dragClue = dragClue} />
|
|
19
|
-
* </div>
|
|
20
|
-
* );
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* onItemDragOver = (event) => {
|
|
24
|
-
* this.dragClue.show(event.pageY + 10, event.pageX, event.item.text, this.getClueClassName(event));
|
|
25
|
-
* }
|
|
26
|
-
* onItemDragEnd = (event) => {
|
|
27
|
-
* this.dragClue.hide();
|
|
28
|
-
* const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
|
|
29
|
-
*
|
|
30
|
-
* if (eventAnalyzer.isDropAllowed) {
|
|
31
|
-
* const updatedTree = moveTreeViewItem(
|
|
32
|
-
* event.itemHierarchicalIndex,
|
|
33
|
-
* this.state.tree,
|
|
34
|
-
* eventAnalyzer.getDropOperation(),
|
|
35
|
-
* eventAnalyzer.destinationMeta.itemHierarchicalIndex,
|
|
36
|
-
* );
|
|
37
|
-
*
|
|
38
|
-
* this.setState({ tree: updatedTree });
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
41
|
-
* getClueClassName(event) {
|
|
42
|
-
* const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
|
|
43
|
-
* const itemIndex = eventAnalyzer.destinationMeta.itemHierarchicalIndex;
|
|
44
|
-
*
|
|
45
|
-
* if (eventAnalyzer.isDropAllowed) {
|
|
46
|
-
* switch (eventAnalyzer.getDropOperation()) {
|
|
47
|
-
* case 'child':
|
|
48
|
-
* return 'k-i-plus';
|
|
49
|
-
* case 'before':
|
|
50
|
-
* return itemIndex === '0' || itemIndex.endsWith(`${SEPARATOR}0`) ?
|
|
51
|
-
* 'k-i-insert-up' : 'k-i-insert-middle';
|
|
52
|
-
* case 'after':
|
|
53
|
-
* const siblings = getSiblings(itemIndex, this.state.tree);
|
|
54
|
-
* const lastIndex = Number(itemIndex.split(SEPARATOR).pop());
|
|
55
|
-
*
|
|
56
|
-
* return lastIndex < siblings.length - 1 ? 'k-i-insert-middle' : 'k-i-insert-down';
|
|
57
|
-
* default:
|
|
58
|
-
* break;
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* return 'k-i-cancel';
|
|
63
|
-
* }
|
|
64
|
-
* }
|
|
65
|
-
*
|
|
66
|
-
* function getSiblings(itemIndex, data) {
|
|
67
|
-
* let result = data;
|
|
68
|
-
*
|
|
69
|
-
* const indices = itemIndex.split(SEPARATOR).map(index => Number(index));
|
|
70
|
-
* for (let i = 0; i < indices.length - 1; i++) {
|
|
71
|
-
* result = result[indices[i]].items;
|
|
72
|
-
* }
|
|
73
|
-
*
|
|
74
|
-
* return result;
|
|
75
|
-
* }
|
|
76
|
-
*
|
|
77
|
-
* const SEPARATOR = '_';
|
|
78
|
-
* const tree = [{
|
|
79
|
-
* text: 'Furniture', expanded: true, items: [
|
|
80
|
-
* { text: 'Tables & Chairs', expanded: true },
|
|
81
|
-
* { text: 'Sofas', expanded: true },
|
|
82
|
-
* { text: 'Occasional Furniture', expanded: true }]
|
|
83
|
-
* }, {
|
|
84
|
-
* text: 'Decor', expanded: true, items: [
|
|
85
|
-
* { text: 'Bed Linen', expanded: true },
|
|
86
|
-
* { text: 'Curtains & Blinds', expanded: true },
|
|
87
|
-
* { text: 'Carpets', expanded: true }]
|
|
88
|
-
* }];
|
|
89
|
-
*
|
|
90
|
-
* ReactDOM.render(<App />, document.querySelector('my-app'));
|
|
91
|
-
* ```
|
|
92
7
|
*/
|
|
93
8
|
var TreeViewDragAnalyzer = /** @class */ (function () {
|
|
94
9
|
/**
|
|
@@ -98,7 +13,7 @@ var TreeViewDragAnalyzer = /** @class */ (function () {
|
|
|
98
13
|
this.event = event;
|
|
99
14
|
this.initialized = false;
|
|
100
15
|
this.itemId = event.itemHierarchicalIndex;
|
|
101
|
-
this.treeViewGuid = event.target.guid;
|
|
16
|
+
this.treeViewGuid = event.target.guid();
|
|
102
17
|
}
|
|
103
18
|
/**
|
|
104
19
|
* The method which initializes the analyzer.
|
package/dist/es/TreeViewItem.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = this && this.__assign || function () {
|
|
2
|
+
__assign = Object.assign || function (t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var p in s) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
}; // @ts-ignore
|
|
16
|
+
|
|
17
|
+
|
|
2
18
|
import * as Vue from 'vue';
|
|
3
19
|
var allVue = Vue;
|
|
4
20
|
var gh = allVue.h;
|
|
5
|
-
import { classNames, guid, Draggable, kendoThemeMaps } from '@progress/kendo-vue-common';
|
|
21
|
+
import { classNames, guid, Draggable, kendoThemeMaps, getTemplate } from '@progress/kendo-vue-common';
|
|
6
22
|
import { createId } from './utils/itemIdUtils';
|
|
7
23
|
import { isItemExpandedAndWithChildren, hasChildren } from './utils/itemUtils';
|
|
8
24
|
import { Reveal } from '@progress/kendo-vue-animation';
|
|
@@ -92,6 +108,8 @@ var TreeViewItemVue2 = {
|
|
|
92
108
|
if (this.checkboxElement) {
|
|
93
109
|
this.checkboxElement.indeterminate = this.fieldsSvc.checkIndeterminate(this.item);
|
|
94
110
|
}
|
|
111
|
+
|
|
112
|
+
this.assignDraggableMeta(this.$refs.treemid);
|
|
95
113
|
},
|
|
96
114
|
updated: function updated() {
|
|
97
115
|
var focusedItemId = this.$props.focusedItemId;
|
|
@@ -107,6 +125,8 @@ var TreeViewItemVue2 = {
|
|
|
107
125
|
this.checkboxElement.indeterminate = indeterminate;
|
|
108
126
|
}
|
|
109
127
|
}
|
|
128
|
+
|
|
129
|
+
this.assignDraggableMeta(this.$refs.treemid);
|
|
110
130
|
},
|
|
111
131
|
// @ts-ignore
|
|
112
132
|
setup: !gh ? undefined : function () {
|
|
@@ -119,6 +139,8 @@ var TreeViewItemVue2 = {
|
|
|
119
139
|
render: function render(createElement) {
|
|
120
140
|
var _this2 = this;
|
|
121
141
|
|
|
142
|
+
var _this = this;
|
|
143
|
+
|
|
122
144
|
var h = gh || createElement;
|
|
123
145
|
|
|
124
146
|
var subitems = function subitems() {
|
|
@@ -236,6 +258,16 @@ var TreeViewItemVue2 = {
|
|
|
236
258
|
}
|
|
237
259
|
};
|
|
238
260
|
|
|
261
|
+
var itemRender = getTemplate.call(this, {
|
|
262
|
+
h: h,
|
|
263
|
+
template: this.$props.itemUI,
|
|
264
|
+
defaultRendering: this.fieldsSvc.text(this.item),
|
|
265
|
+
additionalProps: {
|
|
266
|
+
item: this.item,
|
|
267
|
+
itemHierarchicalIndex: this.itemId
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
239
271
|
var itemInPart = function itemInPart() {
|
|
240
272
|
return h("span", {
|
|
241
273
|
"class": this.getContentClassName(),
|
|
@@ -248,14 +280,7 @@ var TreeViewItemVue2 = {
|
|
|
248
280
|
}
|
|
249
281
|
}, [h("span", {
|
|
250
282
|
"class": "k-treeview-leaf-text"
|
|
251
|
-
}, [
|
|
252
|
-
item: this.item,
|
|
253
|
-
attrs: this.v3 ? undefined : {
|
|
254
|
-
item: this.item,
|
|
255
|
-
itemHierarchicalIndex: this.itemId
|
|
256
|
-
},
|
|
257
|
-
itemHierarchicalIndex: this.itemId
|
|
258
|
-
}) : this.fieldsSvc.text(this.item)])]);
|
|
283
|
+
}, [itemRender])]);
|
|
259
284
|
};
|
|
260
285
|
|
|
261
286
|
return h("li", {
|
|
@@ -276,17 +301,29 @@ var TreeViewItemVue2 = {
|
|
|
276
301
|
"aria-disabled": this.fieldsSvc.disabled(this.item) ? true : undefined
|
|
277
302
|
}, [h("div", {
|
|
278
303
|
"class": "k-treeview-mid",
|
|
279
|
-
ref:
|
|
304
|
+
ref: 'treemid'
|
|
280
305
|
}, [renderExpandIcon.call(this), renderCheckbox.call(this), this.$props.draggable ? // @ts-ignore function children
|
|
281
306
|
h(Draggable, {
|
|
282
|
-
onPress:
|
|
307
|
+
onPress: function onPress(e) {
|
|
308
|
+
return _this.handlePress(e);
|
|
309
|
+
},
|
|
283
310
|
on: this.v3 ? undefined : {
|
|
284
|
-
"press":
|
|
285
|
-
|
|
286
|
-
|
|
311
|
+
"press": function onPress(e) {
|
|
312
|
+
return _this.handlePress(e);
|
|
313
|
+
},
|
|
314
|
+
"drag": function drag(e) {
|
|
315
|
+
return _this.handleDrag(e);
|
|
316
|
+
},
|
|
317
|
+
"release": function release(e) {
|
|
318
|
+
return _this.handleRelease(e);
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
onDrag: function drag(e) {
|
|
322
|
+
return _this.handleDrag(e);
|
|
287
323
|
},
|
|
288
|
-
|
|
289
|
-
|
|
324
|
+
onRelease: function release(e) {
|
|
325
|
+
return _this.handleRelease(e);
|
|
326
|
+
}
|
|
290
327
|
}, this.v3 ? function () {
|
|
291
328
|
return [itemInPart.call(_this2)];
|
|
292
329
|
} : [itemInPart.call(_this2)]) : itemInPart.call(this)]), this.$props.animate ? // @ts-ignore function children
|
|
@@ -317,13 +354,13 @@ var TreeViewItemVue2 = {
|
|
|
317
354
|
this.$emit('itemclick', e, subItem || this.item, subItemId || this.itemId);
|
|
318
355
|
},
|
|
319
356
|
handlePress: function handlePress(e, subItem, subItemId) {
|
|
320
|
-
this.$emit('press', e
|
|
357
|
+
this.$emit('press', e, subItem || __assign({}, this.item), subItemId || this.itemId);
|
|
321
358
|
},
|
|
322
359
|
handleDrag: function handleDrag(e, subItem, subItemId) {
|
|
323
|
-
this.$emit('drag', e
|
|
360
|
+
this.$emit('drag', e, subItem || this.item, subItemId || this.itemId);
|
|
324
361
|
},
|
|
325
362
|
handleRelease: function handleRelease(e, subItem, subItemId) {
|
|
326
|
-
this.$emit('release', e
|
|
363
|
+
this.$emit('release', e, subItem || this.item, subItemId || this.itemId);
|
|
327
364
|
},
|
|
328
365
|
handleFocusDomElNeeded: function handleFocusDomElNeeded(e) {
|
|
329
366
|
this.$emit('focusdomelneeded', e);
|
|
@@ -348,7 +385,7 @@ var TreeViewItemVue2 = {
|
|
|
348
385
|
});
|
|
349
386
|
},
|
|
350
387
|
assignDraggableMeta: function assignDraggableMeta(element) {
|
|
351
|
-
if (element) {
|
|
388
|
+
if (element && !element[DOM_KENDO_ITEM_ID_FIELD]) {
|
|
352
389
|
element[DOM_KENDO_ITEM_ID_FIELD] = this.$props.itemId;
|
|
353
390
|
element[DOM_KENDO_TREEVIEW_GUID_FIELD] = this.$props.treeGuid;
|
|
354
391
|
}
|
|
@@ -91,6 +91,10 @@ export interface TreeViewProps {
|
|
|
91
91
|
* Fires when a checkbox is clicked or when `Space` is pressed on a focused item ([see example]({% slug check_items_directly_treeview %})).
|
|
92
92
|
*/
|
|
93
93
|
onCheckChange?: (event: events.TreeViewCheckChangeEvent) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Controls the unique id of the TreeView component.
|
|
96
|
+
*/
|
|
97
|
+
id?: string;
|
|
94
98
|
/**
|
|
95
99
|
* Controls the dispatching of the `drag` events. By default, the `drag` events are not dispatched ([see example]({% slug dragdrop_treeview %})).
|
|
96
100
|
*/
|
|
@@ -5,7 +5,7 @@ export var packageMetadata = {
|
|
|
5
5
|
name: '@progress/kendo-vue-treeview',
|
|
6
6
|
productName: 'Kendo UI for Vue',
|
|
7
7
|
productCodes: ['KENDOUIVUE', 'KENDOUICOMPLETE'],
|
|
8
|
-
publishDate:
|
|
8
|
+
publishDate: 1650381025,
|
|
9
9
|
version: '',
|
|
10
10
|
licensingDocsUrl: 'https://www.telerik.com/kendo-vue-ui/my-license/?utm_medium=product&utm_source=kendovue&utm_campaign=kendo-ui-vue-purchase-license-keys-warning'
|
|
11
11
|
};
|
package/dist/npm/TreeView.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import FieldsService from './utils/FieldsService';
|
|
|
12
12
|
export interface TreeViewState {
|
|
13
13
|
blurRequest: any;
|
|
14
14
|
fieldsSvc: FieldsService;
|
|
15
|
-
|
|
15
|
+
innerId: string;
|
|
16
16
|
allowExplicitFocus: boolean;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -20,6 +20,7 @@ export interface TreeViewState {
|
|
|
20
20
|
*/
|
|
21
21
|
export interface TreeViewComputed {
|
|
22
22
|
[key: string]: any;
|
|
23
|
+
treeGuid: string;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* @hidden
|
package/dist/npm/TreeView.js
CHANGED
|
@@ -36,6 +36,8 @@ var TreeViewVue2 = {
|
|
|
36
36
|
type: Boolean,
|
|
37
37
|
default: true
|
|
38
38
|
},
|
|
39
|
+
id: String,
|
|
40
|
+
draggable: Boolean,
|
|
39
41
|
tabIndex: Number,
|
|
40
42
|
focusIdField: String,
|
|
41
43
|
getFocusHierarchicalIndex: Function,
|
|
@@ -92,10 +94,15 @@ var TreeViewVue2 = {
|
|
|
92
94
|
tabbableItemId: itemIdUtils_1.ZERO_LEVEL_ZERO_NODE_ID
|
|
93
95
|
};
|
|
94
96
|
},
|
|
97
|
+
computed: {
|
|
98
|
+
treeGuid: function treeGuid() {
|
|
99
|
+
return this.id || this.innerId;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
95
102
|
created: function created() {
|
|
96
103
|
kendo_vue_common_1.validatePackage(package_metadata_1.packageMetadata);
|
|
97
104
|
this.allowExplicitFocus = false;
|
|
98
|
-
this.
|
|
105
|
+
this.innerId = kendo_vue_common_1.guid();
|
|
99
106
|
},
|
|
100
107
|
updated: function updated() {
|
|
101
108
|
this.allowExplicitFocus = false;
|
|
@@ -136,7 +143,10 @@ var TreeViewVue2 = {
|
|
|
136
143
|
"aria-multiselectable": this.ariaMultiSelectable ? true : undefined,
|
|
137
144
|
"aria-label": this.$props['aria-label'],
|
|
138
145
|
"aria-labelledby": this.$props['aria-labelledby'],
|
|
139
|
-
tabIndex: this.$props.tabIndex
|
|
146
|
+
tabIndex: this.$props.tabIndex,
|
|
147
|
+
style: {
|
|
148
|
+
userSelect: this.draggable ? 'none' : undefined
|
|
149
|
+
}
|
|
140
150
|
}, [h("ul", {
|
|
141
151
|
"class": "k-treeview-lines k-treeview-group",
|
|
142
152
|
role: "group",
|
|
@@ -144,6 +154,7 @@ var TreeViewVue2 = {
|
|
|
144
154
|
role: "group"
|
|
145
155
|
}
|
|
146
156
|
}, [this.dataItems.map(function (item, index) {
|
|
157
|
+
var itemTemplate = kendo_vue_common_1.templateRendering.call(this, this.item, kendo_vue_common_1.getListeners.call(this));
|
|
147
158
|
return h(TreeViewItem_1.TreeViewItem, {
|
|
148
159
|
item: item,
|
|
149
160
|
attrs: this.v3 ? undefined : {
|
|
@@ -154,7 +165,7 @@ var TreeViewVue2 = {
|
|
|
154
165
|
focusedItemId: this.focusedItemId,
|
|
155
166
|
tabbableItemId: this.tabbableItemId,
|
|
156
167
|
fieldsService: this.fieldsSvc,
|
|
157
|
-
itemUI:
|
|
168
|
+
itemUI: itemTemplate,
|
|
158
169
|
checkboxes: this.$props.checkboxes,
|
|
159
170
|
ariaMultiSelectable: this.ariaMultiSelectable,
|
|
160
171
|
draggable: this.$props.draggable,
|
|
@@ -167,7 +178,7 @@ var TreeViewVue2 = {
|
|
|
167
178
|
focusedItemId: this.focusedItemId,
|
|
168
179
|
tabbableItemId: this.tabbableItemId,
|
|
169
180
|
fieldsService: this.fieldsSvc,
|
|
170
|
-
itemUI:
|
|
181
|
+
itemUI: itemTemplate,
|
|
171
182
|
checkboxes: this.$props.checkboxes,
|
|
172
183
|
ariaMultiSelectable: this.ariaMultiSelectable,
|
|
173
184
|
onItemclick: this.onItemClick,
|
|
@@ -208,49 +219,41 @@ var TreeViewVue2 = {
|
|
|
208
219
|
this.dispatchExpandChange(event, item, itemId);
|
|
209
220
|
},
|
|
210
221
|
onPress: function onPress(_event, item, itemId) {
|
|
211
|
-
|
|
212
|
-
this
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
}
|
|
222
|
+
this.$emit('itemdragstart', {
|
|
223
|
+
target: this,
|
|
224
|
+
item: item,
|
|
225
|
+
itemHierarchicalIndex: itemId
|
|
226
|
+
});
|
|
218
227
|
},
|
|
219
228
|
onDrag: function onDrag(event, item, itemId) {
|
|
220
229
|
var pageX = event.pageX,
|
|
221
230
|
pageY = event.pageY,
|
|
222
231
|
clientX = event.clientX,
|
|
223
232
|
clientY = event.clientY;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
clientY: clientY
|
|
234
|
-
});
|
|
235
|
-
}
|
|
233
|
+
this.$emit('itemdragover', {
|
|
234
|
+
target: this,
|
|
235
|
+
item: item,
|
|
236
|
+
itemHierarchicalIndex: itemId,
|
|
237
|
+
pageX: pageX,
|
|
238
|
+
pageY: pageY,
|
|
239
|
+
clientX: clientX,
|
|
240
|
+
clientY: clientY
|
|
241
|
+
});
|
|
236
242
|
},
|
|
237
243
|
onRelease: function onRelease(event, item, itemId) {
|
|
238
244
|
var pageX = event.pageX,
|
|
239
245
|
pageY = event.pageY,
|
|
240
246
|
clientX = event.clientX,
|
|
241
247
|
clientY = event.clientY;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
clientY: clientY
|
|
252
|
-
});
|
|
253
|
-
}
|
|
248
|
+
this.$emit('itemdragend', {
|
|
249
|
+
target: this,
|
|
250
|
+
item: item,
|
|
251
|
+
itemHierarchicalIndex: itemId,
|
|
252
|
+
pageX: pageX,
|
|
253
|
+
pageY: pageY,
|
|
254
|
+
clientX: clientX,
|
|
255
|
+
clientY: clientY
|
|
256
|
+
});
|
|
254
257
|
},
|
|
255
258
|
onItemClick: function onItemClick(event, item, itemId) {
|
|
256
259
|
this.setFocus(itemId);
|
|
@@ -3,91 +3,6 @@ import { TreeViewItemDragOverEvent, TreeViewItemDragEndEvent } from './events';
|
|
|
3
3
|
* A class which provides an API for analyzing the `drag` events
|
|
4
4
|
* of the TreeView.
|
|
5
5
|
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```jsx
|
|
8
|
-
* class App extends React.Component {
|
|
9
|
-
* dragClue;
|
|
10
|
-
* state = { tree };
|
|
11
|
-
*
|
|
12
|
-
* render() {
|
|
13
|
-
* return (
|
|
14
|
-
* <div>
|
|
15
|
-
* <TreeView data={this.state.tree} draggable={true}
|
|
16
|
-
* onItemDragOver={this.onItemDragOver} onItemDragEnd={this.onItemDragEnd} />
|
|
17
|
-
* <TreeViewDragClue ref={dragClue => this.dragClue = dragClue} />
|
|
18
|
-
* </div>
|
|
19
|
-
* );
|
|
20
|
-
* }
|
|
21
|
-
*
|
|
22
|
-
* onItemDragOver = (event) => {
|
|
23
|
-
* this.dragClue.show(event.pageY + 10, event.pageX, event.item.text, this.getClueClassName(event));
|
|
24
|
-
* }
|
|
25
|
-
* onItemDragEnd = (event) => {
|
|
26
|
-
* this.dragClue.hide();
|
|
27
|
-
* const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
|
|
28
|
-
*
|
|
29
|
-
* if (eventAnalyzer.isDropAllowed) {
|
|
30
|
-
* const updatedTree = moveTreeViewItem(
|
|
31
|
-
* event.itemHierarchicalIndex,
|
|
32
|
-
* this.state.tree,
|
|
33
|
-
* eventAnalyzer.getDropOperation(),
|
|
34
|
-
* eventAnalyzer.destinationMeta.itemHierarchicalIndex,
|
|
35
|
-
* );
|
|
36
|
-
*
|
|
37
|
-
* this.setState({ tree: updatedTree });
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
* getClueClassName(event) {
|
|
41
|
-
* const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
|
|
42
|
-
* const itemIndex = eventAnalyzer.destinationMeta.itemHierarchicalIndex;
|
|
43
|
-
*
|
|
44
|
-
* if (eventAnalyzer.isDropAllowed) {
|
|
45
|
-
* switch (eventAnalyzer.getDropOperation()) {
|
|
46
|
-
* case 'child':
|
|
47
|
-
* return 'k-i-plus';
|
|
48
|
-
* case 'before':
|
|
49
|
-
* return itemIndex === '0' || itemIndex.endsWith(`${SEPARATOR}0`) ?
|
|
50
|
-
* 'k-i-insert-up' : 'k-i-insert-middle';
|
|
51
|
-
* case 'after':
|
|
52
|
-
* const siblings = getSiblings(itemIndex, this.state.tree);
|
|
53
|
-
* const lastIndex = Number(itemIndex.split(SEPARATOR).pop());
|
|
54
|
-
*
|
|
55
|
-
* return lastIndex < siblings.length - 1 ? 'k-i-insert-middle' : 'k-i-insert-down';
|
|
56
|
-
* default:
|
|
57
|
-
* break;
|
|
58
|
-
* }
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* return 'k-i-cancel';
|
|
62
|
-
* }
|
|
63
|
-
* }
|
|
64
|
-
*
|
|
65
|
-
* function getSiblings(itemIndex, data) {
|
|
66
|
-
* let result = data;
|
|
67
|
-
*
|
|
68
|
-
* const indices = itemIndex.split(SEPARATOR).map(index => Number(index));
|
|
69
|
-
* for (let i = 0; i < indices.length - 1; i++) {
|
|
70
|
-
* result = result[indices[i]].items;
|
|
71
|
-
* }
|
|
72
|
-
*
|
|
73
|
-
* return result;
|
|
74
|
-
* }
|
|
75
|
-
*
|
|
76
|
-
* const SEPARATOR = '_';
|
|
77
|
-
* const tree = [{
|
|
78
|
-
* text: 'Furniture', expanded: true, items: [
|
|
79
|
-
* { text: 'Tables & Chairs', expanded: true },
|
|
80
|
-
* { text: 'Sofas', expanded: true },
|
|
81
|
-
* { text: 'Occasional Furniture', expanded: true }]
|
|
82
|
-
* }, {
|
|
83
|
-
* text: 'Decor', expanded: true, items: [
|
|
84
|
-
* { text: 'Bed Linen', expanded: true },
|
|
85
|
-
* { text: 'Curtains & Blinds', expanded: true },
|
|
86
|
-
* { text: 'Carpets', expanded: true }]
|
|
87
|
-
* }];
|
|
88
|
-
*
|
|
89
|
-
* ReactDOM.render(<App />, document.querySelector('my-app'));
|
|
90
|
-
* ```
|
|
91
6
|
*/
|
|
92
7
|
export default class TreeViewDragAnalyzer {
|
|
93
8
|
private event;
|
|
@@ -6,91 +6,6 @@ var DROPZONE_BOUNDARY_DELTA = 6;
|
|
|
6
6
|
* A class which provides an API for analyzing the `drag` events
|
|
7
7
|
* of the TreeView.
|
|
8
8
|
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```jsx
|
|
11
|
-
* class App extends React.Component {
|
|
12
|
-
* dragClue;
|
|
13
|
-
* state = { tree };
|
|
14
|
-
*
|
|
15
|
-
* render() {
|
|
16
|
-
* return (
|
|
17
|
-
* <div>
|
|
18
|
-
* <TreeView data={this.state.tree} draggable={true}
|
|
19
|
-
* onItemDragOver={this.onItemDragOver} onItemDragEnd={this.onItemDragEnd} />
|
|
20
|
-
* <TreeViewDragClue ref={dragClue => this.dragClue = dragClue} />
|
|
21
|
-
* </div>
|
|
22
|
-
* );
|
|
23
|
-
* }
|
|
24
|
-
*
|
|
25
|
-
* onItemDragOver = (event) => {
|
|
26
|
-
* this.dragClue.show(event.pageY + 10, event.pageX, event.item.text, this.getClueClassName(event));
|
|
27
|
-
* }
|
|
28
|
-
* onItemDragEnd = (event) => {
|
|
29
|
-
* this.dragClue.hide();
|
|
30
|
-
* const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
|
|
31
|
-
*
|
|
32
|
-
* if (eventAnalyzer.isDropAllowed) {
|
|
33
|
-
* const updatedTree = moveTreeViewItem(
|
|
34
|
-
* event.itemHierarchicalIndex,
|
|
35
|
-
* this.state.tree,
|
|
36
|
-
* eventAnalyzer.getDropOperation(),
|
|
37
|
-
* eventAnalyzer.destinationMeta.itemHierarchicalIndex,
|
|
38
|
-
* );
|
|
39
|
-
*
|
|
40
|
-
* this.setState({ tree: updatedTree });
|
|
41
|
-
* }
|
|
42
|
-
* }
|
|
43
|
-
* getClueClassName(event) {
|
|
44
|
-
* const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
|
|
45
|
-
* const itemIndex = eventAnalyzer.destinationMeta.itemHierarchicalIndex;
|
|
46
|
-
*
|
|
47
|
-
* if (eventAnalyzer.isDropAllowed) {
|
|
48
|
-
* switch (eventAnalyzer.getDropOperation()) {
|
|
49
|
-
* case 'child':
|
|
50
|
-
* return 'k-i-plus';
|
|
51
|
-
* case 'before':
|
|
52
|
-
* return itemIndex === '0' || itemIndex.endsWith(`${SEPARATOR}0`) ?
|
|
53
|
-
* 'k-i-insert-up' : 'k-i-insert-middle';
|
|
54
|
-
* case 'after':
|
|
55
|
-
* const siblings = getSiblings(itemIndex, this.state.tree);
|
|
56
|
-
* const lastIndex = Number(itemIndex.split(SEPARATOR).pop());
|
|
57
|
-
*
|
|
58
|
-
* return lastIndex < siblings.length - 1 ? 'k-i-insert-middle' : 'k-i-insert-down';
|
|
59
|
-
* default:
|
|
60
|
-
* break;
|
|
61
|
-
* }
|
|
62
|
-
* }
|
|
63
|
-
*
|
|
64
|
-
* return 'k-i-cancel';
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* function getSiblings(itemIndex, data) {
|
|
69
|
-
* let result = data;
|
|
70
|
-
*
|
|
71
|
-
* const indices = itemIndex.split(SEPARATOR).map(index => Number(index));
|
|
72
|
-
* for (let i = 0; i < indices.length - 1; i++) {
|
|
73
|
-
* result = result[indices[i]].items;
|
|
74
|
-
* }
|
|
75
|
-
*
|
|
76
|
-
* return result;
|
|
77
|
-
* }
|
|
78
|
-
*
|
|
79
|
-
* const SEPARATOR = '_';
|
|
80
|
-
* const tree = [{
|
|
81
|
-
* text: 'Furniture', expanded: true, items: [
|
|
82
|
-
* { text: 'Tables & Chairs', expanded: true },
|
|
83
|
-
* { text: 'Sofas', expanded: true },
|
|
84
|
-
* { text: 'Occasional Furniture', expanded: true }]
|
|
85
|
-
* }, {
|
|
86
|
-
* text: 'Decor', expanded: true, items: [
|
|
87
|
-
* { text: 'Bed Linen', expanded: true },
|
|
88
|
-
* { text: 'Curtains & Blinds', expanded: true },
|
|
89
|
-
* { text: 'Carpets', expanded: true }]
|
|
90
|
-
* }];
|
|
91
|
-
*
|
|
92
|
-
* ReactDOM.render(<App />, document.querySelector('my-app'));
|
|
93
|
-
* ```
|
|
94
9
|
*/
|
|
95
10
|
var TreeViewDragAnalyzer = /** @class */ (function () {
|
|
96
11
|
/**
|
|
@@ -100,7 +15,7 @@ var TreeViewDragAnalyzer = /** @class */ (function () {
|
|
|
100
15
|
this.event = event;
|
|
101
16
|
this.initialized = false;
|
|
102
17
|
this.itemId = event.itemHierarchicalIndex;
|
|
103
|
-
this.treeViewGuid = event.target.guid;
|
|
18
|
+
this.treeViewGuid = event.target.guid();
|
|
104
19
|
}
|
|
105
20
|
/**
|
|
106
21
|
* The method which initializes the analyzer.
|