@progress/kendo-react-treeview 6.1.1 → 7.0.0-develop.2

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.
Files changed (70) hide show
  1. package/{dist/es/ItemRenderProps.d.ts → ItemRenderProps.d.ts} +4 -0
  2. package/LICENSE.md +1 -1
  3. package/{dist/npm/TreeView.d.ts → TreeView.d.ts} +5 -1
  4. package/{dist/es/TreeViewDragAnalyzer.d.ts → TreeViewDragAnalyzer.d.ts} +5 -1
  5. package/{dist/npm/TreeViewDragClue.d.ts → TreeViewDragClue.d.ts} +5 -1
  6. package/{dist/npm/TreeViewItem.d.ts → TreeViewItem.d.ts} +5 -1
  7. package/{dist/es/TreeViewOperationDescriptors.d.ts → TreeViewOperationDescriptors.d.ts} +4 -0
  8. package/{dist/es/TreeViewProps.d.ts → TreeViewProps.d.ts} +4 -0
  9. package/dist/cdn/js/kendo-react-treeview.js +5 -1
  10. package/{dist/es/events.d.ts → events.d.ts} +4 -1
  11. package/{dist/npm/handleTreeViewCheckChange.d.ts → handleTreeViewCheckChange.d.ts} +4 -0
  12. package/{dist/es/main.d.ts → index.d.ts} +9 -5
  13. package/index.js +5 -0
  14. package/index.mjs +745 -0
  15. package/{dist/npm/moveTreeViewItem.d.ts → moveTreeViewItem.d.ts} +4 -0
  16. package/package-metadata.d.ts +9 -0
  17. package/package.json +28 -37
  18. package/{dist/es/processTreeViewItems.d.ts → processTreeViewItems.d.ts} +4 -0
  19. package/{dist/npm/utils → utils}/consts.d.ts +4 -0
  20. package/utils/getItemIdUponKeyboardNavigation.d.ts +9 -0
  21. package/about.md +0 -3
  22. package/dist/es/ItemRenderProps.js +0 -2
  23. package/dist/es/TreeView.d.ts +0 -124
  24. package/dist/es/TreeView.js +0 -334
  25. package/dist/es/TreeViewDragAnalyzer.js +0 -186
  26. package/dist/es/TreeViewDragClue.d.ts +0 -144
  27. package/dist/es/TreeViewDragClue.js +0 -171
  28. package/dist/es/TreeViewItem.d.ts +0 -96
  29. package/dist/es/TreeViewItem.js +0 -255
  30. package/dist/es/TreeViewOperationDescriptors.js +0 -2
  31. package/dist/es/TreeViewProps.js +0 -1
  32. package/dist/es/events.js +0 -1
  33. package/dist/es/handleTreeViewCheckChange.d.ts +0 -69
  34. package/dist/es/handleTreeViewCheckChange.js +0 -193
  35. package/dist/es/main.js +0 -10
  36. package/dist/es/moveTreeViewItem.d.ts +0 -109
  37. package/dist/es/moveTreeViewItem.js +0 -155
  38. package/dist/es/package-metadata.d.ts +0 -5
  39. package/dist/es/package-metadata.js +0 -11
  40. package/dist/es/processTreeViewItems.js +0 -163
  41. package/dist/es/utils/consts.d.ts +0 -40
  42. package/dist/es/utils/consts.js +0 -40
  43. package/dist/es/utils/getItemIdUponKeyboardNavigation.d.ts +0 -5
  44. package/dist/es/utils/getItemIdUponKeyboardNavigation.js +0 -76
  45. package/dist/npm/ItemRenderProps.d.ts +0 -13
  46. package/dist/npm/ItemRenderProps.js +0 -3
  47. package/dist/npm/TreeView.js +0 -337
  48. package/dist/npm/TreeViewDragAnalyzer.d.ts +0 -135
  49. package/dist/npm/TreeViewDragAnalyzer.js +0 -189
  50. package/dist/npm/TreeViewDragClue.js +0 -174
  51. package/dist/npm/TreeViewItem.js +0 -258
  52. package/dist/npm/TreeViewOperationDescriptors.d.ts +0 -76
  53. package/dist/npm/TreeViewOperationDescriptors.js +0 -3
  54. package/dist/npm/TreeViewProps.d.ts +0 -137
  55. package/dist/npm/TreeViewProps.js +0 -2
  56. package/dist/npm/events.d.ts +0 -159
  57. package/dist/npm/events.js +0 -2
  58. package/dist/npm/handleTreeViewCheckChange.js +0 -197
  59. package/dist/npm/main.d.ts +0 -14
  60. package/dist/npm/main.js +0 -21
  61. package/dist/npm/moveTreeViewItem.js +0 -159
  62. package/dist/npm/package-metadata.d.ts +0 -5
  63. package/dist/npm/package-metadata.js +0 -14
  64. package/dist/npm/processTreeViewItems.d.ts +0 -51
  65. package/dist/npm/processTreeViewItems.js +0 -167
  66. package/dist/npm/utils/consts.js +0 -43
  67. package/dist/npm/utils/getItemIdUponKeyboardNavigation.d.ts +0 -5
  68. package/dist/npm/utils/getItemIdUponKeyboardNavigation.js +0 -79
  69. package/dist/systemjs/kendo-react-treeview.js +0 -1
  70. package/e2e-next/basic.tests.ts +0 -24
@@ -1,337 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.TreeView = void 0;
19
- var React = require("react");
20
- var PropTypes = require("prop-types");
21
- var kendo_react_common_1 = require("@progress/kendo-react-common");
22
- var getItemIdUponKeyboardNavigation_1 = require("./utils/getItemIdUponKeyboardNavigation");
23
- var TreeViewItem_1 = require("./TreeViewItem");
24
- var kendo_react_common_2 = require("@progress/kendo-react-common");
25
- var package_metadata_1 = require("./package-metadata");
26
- var consts_1 = require("./utils/consts");
27
- var sizeMap = kendo_react_common_1.kendoThemeMaps.sizeMap;
28
- /**
29
- * Represents the [KendoReact TreeView component]({% slug overview_treeview %}).
30
- *
31
- * @example
32
- * ```jsx
33
- * const data = [{
34
- * text: 'Furniture', expanded: true, items: [
35
- * { text: 'Tables & Chairs' }, { text: 'Sofas' }, { text: 'Occasional Furniture' }]
36
- * }, {
37
- * text: 'Decor', expanded: true, items: [
38
- * { text: 'Bed Linen' }, { text: 'Curtains & Blinds' }, { text: 'Carpets' }]
39
- * }];
40
- * class App extends React.Component {
41
- * render() {
42
- * return <TreeView data={data} />;
43
- * }
44
- * }
45
- * ReactDOM.render(<App />, document.querySelector('my-app'));
46
- * ```
47
- */
48
- var TreeView = /** @class */ (function (_super) {
49
- __extends(TreeView, _super);
50
- function TreeView(props) {
51
- var _this = _super.call(this, props) || this;
52
- /**
53
- * @hidden
54
- */
55
- _this.state = { focusedItemId: undefined, focusedItemPublicId: undefined, tabbableItemId: kendo_react_common_1.treeIdUtils.ZERO_LEVEL_ZERO_NODE_ID };
56
- _this.fieldsSvc = null;
57
- // When there is a change in state.focusedItemId, calling focus() on the dom element of the focused item
58
- // is most often not needed, because the browser focuses the element on its own.
59
- // https://github.com/telerik/kendo-react/issues/190
60
- _this.allowExplicitFocus = false;
61
- _this.treeGuid = (0, kendo_react_common_1.guid)();
62
- _this._element = null;
63
- _this.onFocusDomElNeeded = function (domItem) {
64
- if (_this.allowExplicitFocus) {
65
- _this.focusDomItem(domItem);
66
- }
67
- };
68
- _this.onCheckChange = function (event, item, itemId) {
69
- _this.setFocus(itemId);
70
- _this.dispatchCheckChange(event, item, itemId);
71
- };
72
- _this.onExpandChange = function (event, item, itemId) {
73
- _this.setFocus(itemId);
74
- _this.dispatchExpandChange(event, item, itemId);
75
- };
76
- _this.onPress = function (_event, item, itemId) {
77
- if (_this.props.onItemDragStart) {
78
- _this.props.onItemDragStart.call(undefined, { target: _this, item: item, itemHierarchicalIndex: itemId });
79
- }
80
- };
81
- _this.onDrag = function (event, item, itemId) {
82
- var pageX = event.pageX, pageY = event.pageY, clientX = event.clientX, clientY = event.clientY;
83
- if (_this.props.onItemDragOver) {
84
- _this.props.onItemDragOver.call(undefined, {
85
- target: _this,
86
- item: item,
87
- itemHierarchicalIndex: itemId,
88
- pageX: pageX,
89
- pageY: pageY,
90
- clientX: clientX,
91
- clientY: clientY
92
- });
93
- }
94
- };
95
- _this.onRelease = function (event, item, itemId) {
96
- var pageX = event.pageX, pageY = event.pageY, clientX = event.clientX, clientY = event.clientY;
97
- if (_this.props.onItemDragEnd) {
98
- _this.props.onItemDragEnd.call(undefined, {
99
- target: _this,
100
- item: item,
101
- itemHierarchicalIndex: itemId,
102
- pageX: pageX,
103
- pageY: pageY,
104
- clientX: clientX,
105
- clientY: clientY
106
- });
107
- }
108
- };
109
- _this.onItemClick = function (event, item, itemId) {
110
- _this.setFocus(itemId);
111
- _this.dispatchItemClick(event, item, itemId);
112
- };
113
- _this.onFocus = function () {
114
- clearTimeout(_this.blurRequest);
115
- if (_this.state.focusedItemId === undefined && _this.data.length) {
116
- _this.setFocus(_this.state.tabbableItemId);
117
- }
118
- };
119
- _this.onBlur = function () {
120
- clearTimeout(_this.blurRequest);
121
- _this.blurRequest = window.setTimeout(function () { return _this.setFocus(undefined); }, 0);
122
- };
123
- _this.onKeyDown = function (event) {
124
- var focusedItem = _this.getFocusedItem();
125
- if (focusedItem && _this.fieldsSvc) {
126
- var newItemId = (0, getItemIdUponKeyboardNavigation_1.default)(focusedItem, _this.state.focusedItemId, _this.data, event.keyCode, _this.fieldsSvc);
127
- if (newItemId !== _this.state.focusedItemId) {
128
- // This disables the auto-scroll. The scroll is achieved via item focusing.
129
- event.preventDefault();
130
- _this.allowExplicitFocus = true;
131
- _this.setFocus(newItemId);
132
- }
133
- _this.dispatchEventsOnKeyDown(event, focusedItem);
134
- }
135
- };
136
- _this.onContextMenu = function (event, item, itemId) {
137
- if (_this.props.onContextMenu) {
138
- var ev = {
139
- target: _this,
140
- syntheticEvent: event,
141
- nativeEvent: event.nativeEvent,
142
- item: item,
143
- itemID: itemId
144
- };
145
- _this.props.onContextMenu.call(undefined, ev);
146
- }
147
- };
148
- (0, kendo_react_common_2.validatePackage)(package_metadata_1.packageMetadata);
149
- return _this;
150
- }
151
- Object.defineProperty(TreeView.prototype, "element", {
152
- /**
153
- * @hidden
154
- */
155
- get: function () {
156
- return this._element;
157
- },
158
- enumerable: false,
159
- configurable: true
160
- });
161
- /**
162
- * @hidden
163
- */
164
- TreeView.prototype.render = function () {
165
- var _a;
166
- var _this = this;
167
- this.fieldsSvc = new kendo_react_common_1.TreeFieldsService(this.props);
168
- var _b = this.props, size = _b.size, className = _b.className;
169
- return (React.createElement("div", { className: (0, kendo_react_common_1.classNames)('k-treeview', (_a = {},
170
- _a["k-treeview-".concat(sizeMap[size] || size)] = size,
171
- _a['k-user-select-none'] = this.props.draggable,
172
- _a['k-rtl'] = this.props.dir === 'rtl',
173
- _a), className), onKeyDown: this.onKeyDown, onFocus: this.onFocus, onBlur: this.onBlur, role: "tree", "aria-multiselectable": this.ariaMultiSelectable ? true : undefined, "aria-label": this.props['aria-label'], "aria-labelledby": this.props['aria-labelledby'], ref: function (element) { return _this._element = element; }, tabIndex: this.props.tabIndex },
174
- React.createElement("ul", { className: "k-treeview-lines k-treeview-group", role: "group" }, this.data.map(function (item, index) {
175
- return (React.createElement(TreeViewItem_1.TreeViewItem, { item: item, position: index === 0 ? 'top' : index === _this.data.length - 1 ? 'bot' : 'mid', itemId: index.toString(), treeGuid: _this.treeGuid, animate: _this.props.animate, focusedItemId: _this.state.focusedItemId, tabbableItemId: _this.state.tabbableItemId, fieldsService: _this.fieldsSvc, itemUI: _this.props.item, checkboxes: _this.props.checkboxes, ariaMultiSelectable: _this.ariaMultiSelectable, onItemClick: _this.onItemClick, onFocusDomElNeeded: _this.onFocusDomElNeeded, draggable: _this.props.draggable, onPress: _this.onPress, onDrag: _this.onDrag, onRelease: _this.onRelease, expandIcons: _this.props.expandIcons, onExpandChange: _this.onExpandChange, onCheckChange: _this.onCheckChange, onContextMenu: _this.onContextMenu, key: index, size: size, isRtl: _this.props.dir === 'rtl' }));
176
- }))));
177
- };
178
- /**
179
- * @hidden
180
- */
181
- TreeView.prototype.componentDidUpdate = function () {
182
- this.allowExplicitFocus = false;
183
- this.refocusDueToFocusIdField();
184
- };
185
- TreeView.prototype.dispatchEventsOnKeyDown = function (event, focusedItem) {
186
- var _this = this;
187
- if (this.fieldsSvc === null) {
188
- return;
189
- }
190
- // isEnabled is the most expensive op and that is why is left last.
191
- var isEnabled = function () {
192
- return _this.fieldsSvc && (0, kendo_react_common_1.isEnabledAndAllParentsEnabled)(_this.state.focusedItemId, _this.data, _this.fieldsSvc);
193
- };
194
- if (event.keyCode === kendo_react_common_1.Keys.left && this.fieldsSvc.expanded(focusedItem) && isEnabled()) {
195
- this.dispatchExpandChange(event, focusedItem, this.state.focusedItemId);
196
- }
197
- else if (event.keyCode === kendo_react_common_1.Keys.right && !this.fieldsSvc.expanded(focusedItem) &&
198
- (this.fieldsSvc.hasChildren(focusedItem) || (0, kendo_react_common_1.hasChildren)(focusedItem, this.props.childrenField)) && isEnabled()) {
199
- this.dispatchExpandChange(event, focusedItem, this.state.focusedItemId);
200
- }
201
- else if (event.keyCode === kendo_react_common_1.Keys.enter && isEnabled()) {
202
- this.dispatchItemClick(event, focusedItem, this.state.focusedItemId);
203
- }
204
- else if (event.keyCode === kendo_react_common_1.Keys.space && isEnabled()) {
205
- // W/o preventDefault() long TreeViews gets incorrectly scrolled.
206
- event.preventDefault();
207
- this.dispatchCheckChange(event, focusedItem, this.state.focusedItemId);
208
- }
209
- };
210
- TreeView.prototype.setFocus = function (focusedItemId) {
211
- if (focusedItemId && this.fieldsSvc) {
212
- if (this.fieldsSvc.focusIdField) {
213
- var item = this.getItemById(focusedItemId);
214
- this.setState({ focusedItemId: focusedItemId, focusedItemPublicId: this.fieldsSvc.focusId(item) });
215
- }
216
- else {
217
- this.setState({ focusedItemId: focusedItemId });
218
- }
219
- }
220
- else {
221
- this.setState(function (state) {
222
- return {
223
- focusedItemId: undefined,
224
- focusedItemPublicId: undefined,
225
- tabbableItemId: state.focusedItemId
226
- };
227
- });
228
- }
229
- };
230
- TreeView.prototype.getFocusedItem = function () {
231
- return this.state.focusedItemId ? this.getItemById(this.state.focusedItemId) : undefined;
232
- };
233
- TreeView.prototype.getItemById = function (itemId) {
234
- return kendo_react_common_1.treeIdUtils.getItemById(itemId, this.data, this.props.childrenField || consts_1.CHILDREN_FIELD);
235
- };
236
- TreeView.prototype.dispatchCheckChange = function (dispatchedEvent, item, itemId) {
237
- (0, kendo_react_common_1.dispatchEvent)(this.props.onCheckChange, dispatchedEvent, this, { item: item, itemHierarchicalIndex: itemId });
238
- };
239
- TreeView.prototype.dispatchExpandChange = function (dispatchedEvent, item, itemId) {
240
- (0, kendo_react_common_1.dispatchEvent)(this.props.onExpandChange, dispatchedEvent, this, { item: item, itemHierarchicalIndex: itemId });
241
- };
242
- TreeView.prototype.dispatchItemClick = function (dispatchedEvent, item, itemId) {
243
- (0, kendo_react_common_1.dispatchEvent)(this.props.onItemClick, dispatchedEvent, this, { item: item, itemHierarchicalIndex: itemId });
244
- };
245
- TreeView.prototype.refocusDueToFocusIdField = function () {
246
- if (this.fieldsSvc && this.fieldsSvc.focusIdField) {
247
- var focusedItemPublicId = this.state.focusedItemPublicId;
248
- if (focusedItemPublicId) {
249
- var focusedItemId = this.props.getFocusHierarchicalIndex ?
250
- this.props.getFocusHierarchicalIndex(focusedItemPublicId) :
251
- (0, kendo_react_common_1.resolveItemId)(focusedItemPublicId, this.fieldsSvc.focusIdField, this.data, this.props.childrenField);
252
- if (focusedItemId !== this.state.focusedItemId) {
253
- this.allowExplicitFocus = true;
254
- this.setState({ focusedItemId: focusedItemId });
255
- }
256
- }
257
- }
258
- };
259
- Object.defineProperty(TreeView.prototype, "ariaMultiSelectable", {
260
- get: function () {
261
- return this.props['aria-multiselectable'] === true || this.props['aria-multiselectable'] === 'true';
262
- },
263
- enumerable: false,
264
- configurable: true
265
- });
266
- Object.defineProperty(TreeView.prototype, "data", {
267
- get: function () {
268
- return this.props.data || [];
269
- },
270
- enumerable: false,
271
- configurable: true
272
- });
273
- TreeView.prototype.focusDomItem = function (domItem) {
274
- domItem.focus();
275
- };
276
- Object.defineProperty(TreeView.prototype, "guid", {
277
- /**
278
- * Returns the `guid` which is associated with the TreeView.
279
- */
280
- get: function () {
281
- return this.treeGuid;
282
- },
283
- enumerable: false,
284
- configurable: true
285
- });
286
- /**
287
- * @hidden
288
- */
289
- TreeView.propTypes = {
290
- data: PropTypes.arrayOf(PropTypes.any),
291
- animate: PropTypes.bool,
292
- tabIndex: PropTypes.number,
293
- focusIdField: PropTypes.string,
294
- getHierarchicalIndexById: PropTypes.func,
295
- onExpandChange: PropTypes.func,
296
- onItemClick: PropTypes.func,
297
- expandField: PropTypes.string,
298
- selectField: PropTypes.string,
299
- childrenField: PropTypes.string,
300
- hasChildrenField: PropTypes.string,
301
- textField: PropTypes.string,
302
- disableField: PropTypes.string,
303
- item: PropTypes.any,
304
- 'aria-multiselectable': function (props, propName, componentName) {
305
- if (props[propName] !== undefined
306
- && props[propName] !== true
307
- && props[propName] !== false
308
- && props[propName] !== 'true'
309
- && props[propName] !== 'false') {
310
- return new Error('Invalid prop `' + propName + '` supplied to' +
311
- ' `' + componentName + '`. Validation failed.');
312
- }
313
- return null;
314
- },
315
- 'aria-label': PropTypes.string,
316
- 'aria-labelledby': PropTypes.string,
317
- size: PropTypes.oneOf([null, 'small', 'medium', 'large']),
318
- dir: PropTypes.string
319
- };
320
- /**
321
- * @hidden
322
- */
323
- TreeView.defaultProps = {
324
- animate: true,
325
- expandField: consts_1.EXPAND_FIELD,
326
- selectField: consts_1.SELECT_FIELD,
327
- hasChildrenField: consts_1.HAS_CHILDREN_FIELD,
328
- childrenField: consts_1.CHILDREN_FIELD,
329
- textField: consts_1.TEXT_FIELD,
330
- disableField: consts_1.DISABLED_FIELD,
331
- checkField: consts_1.CHECK_FIELD,
332
- checkIndeterminateField: consts_1.CHECK_INDETERMINATE_FIELD,
333
- size: 'medium'
334
- };
335
- return TreeView;
336
- }(React.Component));
337
- exports.TreeView = TreeView;
@@ -1,135 +0,0 @@
1
- import { TreeViewItemDragOverEvent, TreeViewItemDragEndEvent } from './events';
2
- /**
3
- * A class which provides an API for analyzing the `drag` events
4
- * of the TreeView.
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
- */
92
- export declare class TreeViewDragAnalyzer {
93
- private event;
94
- private itemId;
95
- private treeViewGuid;
96
- private initialized;
97
- private destDomNodeWithMeta;
98
- private destItemId;
99
- private destTreeViewGuid;
100
- /**
101
- * @param event - The event that will be analyzed.
102
- */
103
- constructor(event: TreeViewItemDragOverEvent | TreeViewItemDragEndEvent);
104
- /**
105
- * The method which initializes the analyzer.
106
- * Invoke the method before you call any other methods.
107
- *
108
- * @returns - The analyzer object of the `drag` event.
109
- */
110
- init(): this;
111
- /**
112
- * Returns `true` if dropping is allowed. Otherwise, returns `false`.
113
- */
114
- get isDropAllowed(): boolean;
115
- /**
116
- * Returns an object which contains:
117
- * * The `itemHierarchicalIndex` of the destination item (the item below the dragged item) and
118
- * * The `guid` of the destination TreeView (the TreeView which renders the destination item).
119
- */
120
- get destinationMeta(): {
121
- itemHierarchicalIndex: string;
122
- treeViewGuid: string;
123
- };
124
- /**
125
- * Returns the specific drop operation.
126
- *
127
- * @returns - The following values are returned:
128
- * * `before`&mdash;Indicates that the dragged item is positioned at the beginning of the destination item.
129
- * * `after`&mdash;Indicates that the dragged item is positioned at the end of the destination item.
130
- * * `child`&mdash;Indicates that the dragged item is positioned in the middle of the destination item.
131
- * * `undefined`&mdash;Indicates that dropping is not allowed.
132
- */
133
- getDropOperation(): "after" | "child" | "before" | undefined;
134
- private setDestimationMeta;
135
- }
@@ -1,189 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeViewDragAnalyzer = void 0;
4
- var consts_1 = require("./utils/consts");
5
- var DROPZONE_BOUNDARY_DELTA = 6;
6
- /**
7
- * A class which provides an API for analyzing the `drag` events
8
- * of the TreeView.
9
- *
10
- * @example
11
- * ```jsx
12
- * class App extends React.Component {
13
- * dragClue;
14
- * state = { tree };
15
- *
16
- * render() {
17
- * return (
18
- * <div>
19
- * <TreeView data={this.state.tree} draggable={true}
20
- * onItemDragOver={this.onItemDragOver} onItemDragEnd={this.onItemDragEnd} />
21
- * <TreeViewDragClue ref={dragClue => this.dragClue = dragClue} />
22
- * </div>
23
- * );
24
- * }
25
- *
26
- * onItemDragOver = (event) => {
27
- * this.dragClue.show(event.pageY + 10, event.pageX, event.item.text, this.getClueClassName(event));
28
- * }
29
- * onItemDragEnd = (event) => {
30
- * this.dragClue.hide();
31
- * const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
32
- *
33
- * if (eventAnalyzer.isDropAllowed) {
34
- * const updatedTree = moveTreeViewItem(
35
- * event.itemHierarchicalIndex,
36
- * this.state.tree,
37
- * eventAnalyzer.getDropOperation(),
38
- * eventAnalyzer.destinationMeta.itemHierarchicalIndex,
39
- * );
40
- *
41
- * this.setState({ tree: updatedTree });
42
- * }
43
- * }
44
- * getClueClassName(event) {
45
- * const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
46
- * const itemIndex = eventAnalyzer.destinationMeta.itemHierarchicalIndex;
47
- *
48
- * if (eventAnalyzer.isDropAllowed) {
49
- * switch (eventAnalyzer.getDropOperation()) {
50
- * case 'child':
51
- * return 'k-i-plus';
52
- * case 'before':
53
- * return itemIndex === '0' || itemIndex.endsWith(`${SEPARATOR}0`) ?
54
- * 'k-i-insert-up' : 'k-i-insert-middle';
55
- * case 'after':
56
- * const siblings = getSiblings(itemIndex, this.state.tree);
57
- * const lastIndex = Number(itemIndex.split(SEPARATOR).pop());
58
- *
59
- * return lastIndex < siblings.length - 1 ? 'k-i-insert-middle' : 'k-i-insert-down';
60
- * default:
61
- * break;
62
- * }
63
- * }
64
- *
65
- * return 'k-i-cancel';
66
- * }
67
- * }
68
- *
69
- * function getSiblings(itemIndex, data) {
70
- * let result = data;
71
- *
72
- * const indices = itemIndex.split(SEPARATOR).map(index => Number(index));
73
- * for (let i = 0; i < indices.length - 1; i++) {
74
- * result = result[indices[i]].items;
75
- * }
76
- *
77
- * return result;
78
- * }
79
- *
80
- * const SEPARATOR = '_';
81
- * const tree = [{
82
- * text: 'Furniture', expanded: true, items: [
83
- * { text: 'Tables & Chairs', expanded: true },
84
- * { text: 'Sofas', expanded: true },
85
- * { text: 'Occasional Furniture', expanded: true }]
86
- * }, {
87
- * text: 'Decor', expanded: true, items: [
88
- * { text: 'Bed Linen', expanded: true },
89
- * { text: 'Curtains & Blinds', expanded: true },
90
- * { text: 'Carpets', expanded: true }]
91
- * }];
92
- *
93
- * ReactDOM.render(<App />, document.querySelector('my-app'));
94
- * ```
95
- */
96
- var TreeViewDragAnalyzer = /** @class */ (function () {
97
- /**
98
- * @param event - The event that will be analyzed.
99
- */
100
- function TreeViewDragAnalyzer(event) {
101
- this.event = event;
102
- this.initialized = false;
103
- this.destItemId = '';
104
- this.destTreeViewGuid = '';
105
- this.itemId = event.itemHierarchicalIndex;
106
- this.treeViewGuid = event.target.guid;
107
- }
108
- /**
109
- * The method which initializes the analyzer.
110
- * Invoke the method before you call any other methods.
111
- *
112
- * @returns - The analyzer object of the `drag` event.
113
- */
114
- TreeViewDragAnalyzer.prototype.init = function () {
115
- if (!this.initialized) {
116
- this.setDestimationMeta(document.elementFromPoint(this.event.clientX, this.event.clientY));
117
- this.initialized = true;
118
- }
119
- return this;
120
- };
121
- Object.defineProperty(TreeViewDragAnalyzer.prototype, "isDropAllowed", {
122
- /**
123
- * Returns `true` if dropping is allowed. Otherwise, returns `false`.
124
- */
125
- get: function () {
126
- if (this.initialized && this.destItemId && this.destTreeViewGuid) {
127
- // Disallow circular references.
128
- return !(("".concat(this.destTreeViewGuid, "_").concat(this.destItemId, "_")).
129
- startsWith("".concat(this.treeViewGuid, "_").concat(this.itemId, "_")));
130
- }
131
- else {
132
- return false;
133
- }
134
- },
135
- enumerable: false,
136
- configurable: true
137
- });
138
- Object.defineProperty(TreeViewDragAnalyzer.prototype, "destinationMeta", {
139
- /**
140
- * Returns an object which contains:
141
- * * The `itemHierarchicalIndex` of the destination item (the item below the dragged item) and
142
- * * The `guid` of the destination TreeView (the TreeView which renders the destination item).
143
- */
144
- get: function () {
145
- return { itemHierarchicalIndex: this.destItemId, treeViewGuid: this.destTreeViewGuid };
146
- },
147
- enumerable: false,
148
- configurable: true
149
- });
150
- /**
151
- * Returns the specific drop operation.
152
- *
153
- * @returns - The following values are returned:
154
- * * `before`&mdash;Indicates that the dragged item is positioned at the beginning of the destination item.
155
- * * `after`&mdash;Indicates that the dragged item is positioned at the end of the destination item.
156
- * * `child`&mdash;Indicates that the dragged item is positioned in the middle of the destination item.
157
- * * `undefined`&mdash;Indicates that dropping is not allowed.
158
- */
159
- TreeViewDragAnalyzer.prototype.getDropOperation = function () {
160
- if (this.initialized && this.isDropAllowed) {
161
- var _a = this.destDomNodeWithMeta.getBoundingClientRect(), top_1 = _a.top, height = _a.height;
162
- if (top_1 + height - this.event.clientY < DROPZONE_BOUNDARY_DELTA) {
163
- return 'after';
164
- }
165
- else if (this.event.clientY - top_1 < DROPZONE_BOUNDARY_DELTA) {
166
- return 'before';
167
- }
168
- else {
169
- return 'child';
170
- }
171
- }
172
- else {
173
- return undefined;
174
- }
175
- };
176
- TreeViewDragAnalyzer.prototype.setDestimationMeta = function (element) {
177
- var node = element;
178
- while (node && !node[consts_1.DOM_KENDO_ITEM_ID_FIELD]) {
179
- node = node.parentNode;
180
- }
181
- if (node && node[consts_1.DOM_KENDO_ITEM_ID_FIELD]) {
182
- this.destDomNodeWithMeta = node;
183
- this.destItemId = node[consts_1.DOM_KENDO_ITEM_ID_FIELD];
184
- this.destTreeViewGuid = node[consts_1.DOM_KENDO_TREEVIEW_GUID_FIELD];
185
- }
186
- };
187
- return TreeViewDragAnalyzer;
188
- }());
189
- exports.TreeViewDragAnalyzer = TreeViewDragAnalyzer;