@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,255 +0,0 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __assign = (this && this.__assign) || function () {
17
- __assign = Object.assign || function(t) {
18
- for (var s, i = 1, n = arguments.length; i < n; i++) {
19
- s = arguments[i];
20
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
- t[p] = s[p];
22
- }
23
- return t;
24
- };
25
- return __assign.apply(this, arguments);
26
- };
27
- import * as React from 'react';
28
- import { classNames, guid, Draggable, kendoThemeMaps, IconWrap } from '@progress/kendo-react-common';
29
- import { caretAltDownIcon, caretAltLeftIcon, caretAltRightIcon } from '@progress/kendo-svg-icons';
30
- import { isItemExpandedAndWithChildren, hasChildren, treeIdUtils } from '@progress/kendo-react-common';
31
- import { Reveal } from '@progress/kendo-react-animation';
32
- import { DOM_KENDO_ITEM_ID_FIELD, DOM_KENDO_TREEVIEW_GUID_FIELD } from './utils/consts';
33
- var sizeMap = kendoThemeMaps.sizeMap;
34
- /**
35
- * @hidden
36
- */
37
- export var TreeViewItemPropsContext = React.createContext(function (props) { return props; });
38
- /**
39
- * @hidden
40
- */
41
- var TreeViewItemWithoutContext = /** @class */ (function (_super) {
42
- __extends(TreeViewItemWithoutContext, _super);
43
- function TreeViewItemWithoutContext() {
44
- var _this = _super !== null && _super.apply(this, arguments) || this;
45
- _this.itemGuid = guid();
46
- _this.onCheckChange = function (e) {
47
- _this.props.onCheckChange(e, _this.item, _this.itemId);
48
- };
49
- _this.onExpandChange = function (e) {
50
- _this.props.onExpandChange(e, _this.item, _this.itemId);
51
- };
52
- _this.onItemClick = function (e) {
53
- _this.props.onItemClick(e, _this.item, _this.itemId);
54
- };
55
- _this.onPress = function (e) {
56
- _this.props.onPress(e.event, _this.item, _this.itemId);
57
- };
58
- _this.onDrag = function (e) {
59
- _this.props.onDrag(e.event, _this.item, _this.itemId);
60
- };
61
- _this.onRelease = function (e) {
62
- _this.props.onRelease(e.event, _this.item, _this.itemId);
63
- };
64
- _this.onContextMenu = function (e) {
65
- _this.props.onContextMenu(e, _this.item, _this.itemId);
66
- };
67
- _this.assignDraggableMeta = function (element) {
68
- if (element) {
69
- element[DOM_KENDO_ITEM_ID_FIELD] = _this.props.itemId;
70
- element[DOM_KENDO_TREEVIEW_GUID_FIELD] = _this.props.treeGuid;
71
- }
72
- };
73
- return _this;
74
- }
75
- TreeViewItemWithoutContext.prototype.render = function () {
76
- var _this = this;
77
- var subitems = this.renderSubitemsIfApplicable();
78
- var itemInPart = this.renderItemInPart();
79
- return (React.createElement("li", { className: classNames('k-treeview-item'), tabIndex: this.tabIndex, role: "treeitem", "aria-expanded": this.ariaExpanded, "aria-selected": this.ariaSelected, "aria-checked": this.ariaChecked, "aria-disabled": this.disabled ? true : undefined, ref: function (el) { return _this.itemElement = el; } },
80
- React.createElement("div", { className: "k-treeview-".concat(this.props.position), ref: this.assignDraggableMeta },
81
- this.renderExpandIcon(),
82
- this.renderCheckbox(),
83
- this.props.draggable ?
84
- React.createElement(Draggable, { onPress: this.onPress, onDrag: this.onDrag, onRelease: this.onRelease }, itemInPart) : itemInPart),
85
- this.props.animate ?
86
- React.createElement(Reveal, { transitionEnterDuration: 200, transitionExitDuration: 200, style: { display: 'block' }, children: subitems }) : subitems));
87
- };
88
- TreeViewItemWithoutContext.prototype.componentDidMount = function () {
89
- var focusedItemId = this.props.focusedItemId;
90
- var currentItemId = this.itemId;
91
- if (focusedItemId && focusedItemId === currentItemId) {
92
- this.props.onFocusDomElNeeded(this.itemElement);
93
- }
94
- if (this.checkboxElement) {
95
- this.checkboxElement.indeterminate = this.fieldsSvc.checkIndeterminate(this.item);
96
- }
97
- };
98
- TreeViewItemWithoutContext.prototype.componentDidUpdate = function (prevProps) {
99
- var focusedItemId = this.props.focusedItemId;
100
- if (focusedItemId &&
101
- focusedItemId !== prevProps.focusedItemId &&
102
- focusedItemId === this.itemId) {
103
- this.props.onFocusDomElNeeded(this.itemElement);
104
- }
105
- if (this.checkboxElement) {
106
- var indeterminate = this.fieldsSvc.checkIndeterminate(this.item);
107
- if (indeterminate !== prevProps.fieldsService.checkIndeterminate(prevProps.item)) {
108
- this.checkboxElement.indeterminate = indeterminate;
109
- }
110
- }
111
- };
112
- TreeViewItemWithoutContext.prototype.renderCheckbox = function () {
113
- var _a;
114
- var _this = this;
115
- if (this.props.checkboxes) {
116
- var size = this.props.size;
117
- return (React.createElement("div", { className: classNames('k-checkbox-wrap') },
118
- React.createElement("input", { type: "checkbox", className: classNames('k-checkbox k-rounded-md', (_a = {},
119
- _a["k-checkbox-".concat(sizeMap[size] || size)] = size,
120
- _a['k-disabled'] = this.disabled,
121
- _a)), "aria-label": this.item.text, checked: Boolean(this.fieldsSvc.checked(this.item)), id: this.itemGuid, tabIndex: -1, onChange: this.onCheckChange, ref: function (el) { return _this.checkboxElement = el; } }),
122
- React.createElement("label", { className: "k-checkbox-label", htmlFor: this.itemGuid })));
123
- }
124
- else {
125
- return undefined;
126
- }
127
- };
128
- TreeViewItemWithoutContext.prototype.renderExpandIcon = function () {
129
- var renderExpand = this.props.expandIcons &&
130
- // If it is explicitly said that the item has children (even not loaded yet)
131
- // or if the item actually has children, then render the icon.
132
- (this.fieldsSvc.hasChildren(this.item) || hasChildren(this.item, this.fieldsSvc.getChildrenField()));
133
- return renderExpand && (
134
- // Allowing the toggle-button even with `disabled=true` might be a valid case!
135
- // Re-evaluate the classes bellow if such scenario occurs
136
- React.createElement("span", { className: classNames('k-treeview-toggle', { 'k-disabled': this.disabled }), onClick: this.onExpandChange },
137
- React.createElement(IconWrap, __assign({}, this.getIconProps()))));
138
- };
139
- TreeViewItemWithoutContext.prototype.renderSubitemsIfApplicable = function () {
140
- var _this = this;
141
- var data = this.fieldsSvc.children(this.item);
142
- return isItemExpandedAndWithChildren(this.item, this.fieldsSvc) ?
143
- (React.createElement("ul", { className: "k-treeview-group", role: "group" }, data.map(function (item, index) {
144
- return (React.createElement(TreeViewItem, { item: item, position: index === 0 ? 'top' : index === data.length - 1 ? 'bot' : 'mid', itemId: treeIdUtils.createId(index, _this.itemId), treeGuid: _this.props.treeGuid, animate: _this.props.animate, focusedItemId: _this.props.focusedItemId, tabbableItemId: _this.props.tabbableItemId, fieldsService: _this.props.fieldsService, itemUI: _this.props.itemUI, checkboxes: _this.props.checkboxes, ariaMultiSelectable: _this.props.ariaMultiSelectable, onItemClick: _this.props.onItemClick, onFocusDomElNeeded: _this.props.onFocusDomElNeeded, draggable: _this.props.draggable, onPress: _this.props.onPress, onDrag: _this.props.onDrag, onRelease: _this.props.onRelease, expandIcons: _this.props.expandIcons, onExpandChange: _this.props.onExpandChange, onCheckChange: _this.props.onCheckChange, onContextMenu: _this.props.onContextMenu, key: index, size: _this.props.size, disabled: _this.disabled, isRtl: _this.props.isRtl }));
145
- }))) : undefined;
146
- };
147
- TreeViewItemWithoutContext.prototype.renderItemInPart = function () {
148
- return (React.createElement("span", { className: classNames('k-treeview-leaf', {
149
- 'k-focus': this.props.focusedItemId === this.itemId,
150
- 'k-selected': this.fieldsSvc.selected(this.item),
151
- 'k-disabled': this.disabled
152
- }), style: { touchAction: 'none' }, onClick: this.onItemClick, onContextMenu: this.onContextMenu },
153
- React.createElement("span", { className: "k-treeview-leaf-text" }, this.props.itemUI ?
154
- React.createElement(this.props.itemUI, { item: this.item, itemHierarchicalIndex: this.itemId }) :
155
- this.fieldsSvc.text(this.item))));
156
- };
157
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "fieldsSvc", {
158
- get: function () {
159
- return this.props.fieldsService;
160
- },
161
- enumerable: false,
162
- configurable: true
163
- });
164
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "itemId", {
165
- get: function () {
166
- return this.props.itemId;
167
- },
168
- enumerable: false,
169
- configurable: true
170
- });
171
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "item", {
172
- get: function () {
173
- return this.props.item;
174
- },
175
- enumerable: false,
176
- configurable: true
177
- });
178
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "tabIndex", {
179
- get: function () {
180
- return (this.props.focusedItemId || this.props.tabbableItemId) === this.itemId ? 0 : -1;
181
- },
182
- enumerable: false,
183
- configurable: true
184
- });
185
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "ariaExpanded", {
186
- get: function () {
187
- return this.fieldsSvc.hasChildren(this.item) || hasChildren(this.item, this.fieldsSvc.getChildrenField()) ?
188
- Boolean(this.fieldsSvc.expanded(this.item)) : undefined;
189
- },
190
- enumerable: false,
191
- configurable: true
192
- });
193
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "disabled", {
194
- get: function () {
195
- return this.props.disabled || this.fieldsSvc.disabled(this.item);
196
- },
197
- enumerable: false,
198
- configurable: true
199
- });
200
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "ariaChecked", {
201
- get: function () {
202
- if (this.props.checkboxes) {
203
- if (this.fieldsSvc.checked(this.item)) {
204
- return 'true';
205
- }
206
- else {
207
- return this.fieldsSvc.checkIndeterminate(this.item) ? 'mixed' : 'false';
208
- }
209
- }
210
- else {
211
- return undefined;
212
- }
213
- },
214
- enumerable: false,
215
- configurable: true
216
- });
217
- Object.defineProperty(TreeViewItemWithoutContext.prototype, "ariaSelected", {
218
- get: function () {
219
- if (this.fieldsSvc.selected(this.item)) {
220
- return true;
221
- }
222
- else if (this.props.ariaMultiSelectable) {
223
- return this.disabled ? undefined : false;
224
- }
225
- else {
226
- return undefined;
227
- }
228
- },
229
- enumerable: false,
230
- configurable: true
231
- });
232
- TreeViewItemWithoutContext.prototype.getIconProps = function () {
233
- var expanded = this.fieldsSvc.expanded(this.item);
234
- var loading = expanded && !hasChildren(this.item, this.fieldsSvc.getChildrenField());
235
- if (loading) {
236
- return { name: 'loading' };
237
- }
238
- return expanded
239
- ? { name: 'caret-alt-down', icon: caretAltDownIcon }
240
- : { name: this.props.isRtl ? 'caret-alt-left' : 'caret-alt-right', icon: this.props.isRtl ? caretAltLeftIcon : caretAltRightIcon };
241
- };
242
- TreeViewItemWithoutContext.defaultProps = {
243
- position: 'top'
244
- };
245
- return TreeViewItemWithoutContext;
246
- }(React.Component));
247
- /**
248
- * @hidden
249
- */
250
- export var TreeViewItem = React.forwardRef(function (props, ref) {
251
- var contextPropsCallback = React.useContext(TreeViewItemPropsContext);
252
- var treeViewItemProps = contextPropsCallback.call(undefined, props);
253
- return (React.createElement(TreeViewItemWithoutContext, __assign({ ref: ref }, treeViewItemProps)));
254
- });
255
- TreeViewItem.displayName = 'TreeViewItem';
@@ -1,2 +0,0 @@
1
- /* eslint-disable max-len */
2
- export {};
@@ -1 +0,0 @@
1
- export {};
package/dist/es/events.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,69 +0,0 @@
1
- import { TreeViewExpandChangeEvent } from './events';
2
- import { TreeViewCheckDescriptor } from './TreeViewOperationDescriptors';
3
- /**
4
- * The settings that configure the update of the check descriptor.
5
- */
6
- export interface TreeViewCheckChangeSettings {
7
- /**
8
- * Determines a selection of a single node at a time.
9
- */
10
- singleMode?: boolean;
11
- /**
12
- * Determines if the children checkboxes will be selected when the user selects the parent checkbox.
13
- */
14
- checkChildren?: boolean;
15
- /**
16
- * Determines if the parent checkbox will be selected when the user selects all its children checkboxes.
17
- */
18
- checkParents?: boolean;
19
- }
20
- /**
21
- * A helper function which updates the check descriptor.
22
- *
23
- * @param event - The event that triggered the change.
24
- * @param check - The check descriptor that will be updated.
25
- * @param data - The TreeView items.
26
- * @param settings - The additional settings that configure the update of the check descriptor.
27
- * @param childrenField - The field that points to the dataItem sub items. Defaults to `items`.
28
- * The default behavior allows the selection of multiple items.
29
- * @returns - The updated copy of the input check descriptor.
30
- *
31
- * @example
32
- * ```jsx
33
- * class App extends React.Component {
34
- * state = { check: [], items: tree };
35
- * render() {
36
- * return (
37
- * <div>
38
- * <TreeView
39
- * checkboxes={true} onCheckChange={this.onCheckChange}
40
- * data={processTreeViewItems(this.state.items, { check: this.state.check })}
41
- * />
42
- * <div style={{ marginTop: 5 }}>
43
- * <i>Press SPACE to check/uncheck the active item</i>
44
- * <div className="example-config">
45
- * Checked Indices: {this.state.check.join(",")}
46
- * </div>
47
- * </div>
48
- * </div>
49
- * );
50
- * }
51
- * onCheckChange = (event) => {
52
- * this.setState({ check: handleTreeViewCheckChange(event, this.state.check, this.state.items) });
53
- * }
54
- * }
55
- *
56
- * const tree = [ {
57
- * text: 'Furniture', expanded: true, items: [
58
- * { text: 'Tables & Chairs' }, { text: 'Sofas' }, { text: 'Occasional Furniture' } ]
59
- * }, {
60
- * text: 'Decor', expanded: true, items: [
61
- * { text: 'Bed Linen' }, { text: 'Curtains & Blinds' }, { text: 'Carpets' } ]
62
- * } ];
63
- *
64
- * ReactDOM.render(<App />, document.querySelector('my-app'));
65
- * ```
66
- */
67
- export declare function handleTreeViewCheckChange(event: TreeViewExpandChangeEvent, check: string[] | TreeViewCheckDescriptor, data?: any[] | null, settings?: TreeViewCheckChangeSettings, childrenField?: string): any[] | (TreeViewCheckDescriptor & {
68
- ids: any[];
69
- });
@@ -1,193 +0,0 @@
1
- var __generator = (this && this.__generator) || function (thisArg, body) {
2
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
3
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
4
- function verb(n) { return function (v) { return step([n, v]); }; }
5
- function step(op) {
6
- if (f) throw new TypeError("Generator is already executing.");
7
- while (_) try {
8
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
9
- if (y = 0, t) op = [op[0] & 2, t.value];
10
- switch (op[0]) {
11
- case 0: case 1: t = op; break;
12
- case 4: _.label++; return { value: op[1], done: false };
13
- case 5: _.label++; y = op[1]; op = [0]; continue;
14
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
15
- default:
16
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
17
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
18
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
19
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
20
- if (t[2]) _.ops.pop();
21
- _.trys.pop(); continue;
22
- }
23
- op = body.call(thisArg, _);
24
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
25
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
26
- }
27
- };
28
- import { getAllDirectIndirectChildrenIds, areAllDirectChildrenChecked, getAllParents, isArray, getNestedValue, treeIdUtils } from '@progress/kendo-react-common';
29
- import { CHILDREN_FIELD } from './utils/consts';
30
- /**
31
- * A helper function which updates the check descriptor.
32
- *
33
- * @param event - The event that triggered the change.
34
- * @param check - The check descriptor that will be updated.
35
- * @param data - The TreeView items.
36
- * @param settings - The additional settings that configure the update of the check descriptor.
37
- * @param childrenField - The field that points to the dataItem sub items. Defaults to `items`.
38
- * The default behavior allows the selection of multiple items.
39
- * @returns - The updated copy of the input check descriptor.
40
- *
41
- * @example
42
- * ```jsx
43
- * class App extends React.Component {
44
- * state = { check: [], items: tree };
45
- * render() {
46
- * return (
47
- * <div>
48
- * <TreeView
49
- * checkboxes={true} onCheckChange={this.onCheckChange}
50
- * data={processTreeViewItems(this.state.items, { check: this.state.check })}
51
- * />
52
- * <div style={{ marginTop: 5 }}>
53
- * <i>Press SPACE to check/uncheck the active item</i>
54
- * <div className="example-config">
55
- * Checked Indices: {this.state.check.join(",")}
56
- * </div>
57
- * </div>
58
- * </div>
59
- * );
60
- * }
61
- * onCheckChange = (event) => {
62
- * this.setState({ check: handleTreeViewCheckChange(event, this.state.check, this.state.items) });
63
- * }
64
- * }
65
- *
66
- * const tree = [ {
67
- * text: 'Furniture', expanded: true, items: [
68
- * { text: 'Tables & Chairs' }, { text: 'Sofas' }, { text: 'Occasional Furniture' } ]
69
- * }, {
70
- * text: 'Decor', expanded: true, items: [
71
- * { text: 'Bed Linen' }, { text: 'Curtains & Blinds' }, { text: 'Carpets' } ]
72
- * } ];
73
- *
74
- * ReactDOM.render(<App />, document.querySelector('my-app'));
75
- * ```
76
- */
77
- export function handleTreeViewCheckChange(event, check, data, settings, childrenField) {
78
- if (settings === void 0) { settings = {}; }
79
- if (!data || !data.length) {
80
- return [];
81
- }
82
- var _a = parseOperation(check), ids = _a.ids, idField = _a.idField;
83
- var itemId = idField ? getNestedValue(idField, event.item) : event.itemHierarchicalIndex;
84
- var idIndex = ids.indexOf(itemId);
85
- var itemJustChecked = idIndex === -1;
86
- var subItemsField = childrenField || CHILDREN_FIELD;
87
- var newIds;
88
- if (settings.singleMode) {
89
- newIds = itemJustChecked ? [itemId] : [];
90
- }
91
- else {
92
- newIds = ids.slice();
93
- itemJustChecked ? newIds.push(itemId) : newIds.splice(idIndex, 1);
94
- if (settings.checkChildren) {
95
- checkChildren(event.item, event.itemHierarchicalIndex, itemJustChecked, idField, subItemsField, newIds);
96
- }
97
- if (settings.checkParents) {
98
- checkParents(event.itemHierarchicalIndex, itemJustChecked, idField, subItemsField, newIds, data);
99
- }
100
- }
101
- return isArray(check) ? newIds : Object.assign({}, check, { ids: newIds });
102
- }
103
- function parseOperation(operation) {
104
- var ids;
105
- var idField = undefined;
106
- if (isArray(operation)) {
107
- ids = operation;
108
- }
109
- else {
110
- ids = operation.ids || [];
111
- idField = operation.idField;
112
- }
113
- return { ids: ids, idField: idField };
114
- }
115
- function checkChildren(item, itemHierarchicalIndex, itemJustChecked, idField, childrenField, ids) {
116
- getAllDirectIndirectChildrenIds(item, itemHierarchicalIndex, childrenField, idField).forEach(function (itemId) {
117
- if (itemJustChecked && ids.indexOf(itemId) === -1) {
118
- ids.push(itemId);
119
- }
120
- else if (!itemJustChecked && ids.indexOf(itemId) > -1) {
121
- ids.splice(ids.indexOf(itemId), 1);
122
- }
123
- });
124
- }
125
- function checkParents(itemHierarchicalIndex, itemJustChecked, idField, childrenField, ids, data) {
126
- var it = makeParentsIterator();
127
- var result = it.next();
128
- itemJustChecked ? check() : uncheck();
129
- function check() {
130
- // Check all parents which have all their children checked.
131
- while (!result.done) {
132
- var _a = result.value, id = _a.id, item = _a.item;
133
- // The first check is needed. However, it is not sure whether to stop the entire loop.
134
- if (ids.indexOf(id) === -1 &&
135
- areAllDirectChildrenChecked(item, id, idField, childrenField, ids)) {
136
- ids.push(id);
137
- result = it.next();
138
- }
139
- else {
140
- break;
141
- }
142
- }
143
- }
144
- function uncheck() {
145
- // Uncheck parents until an already unchecked parent is reached.
146
- while (!result.done) {
147
- var id = result.value.id;
148
- var idIndex = ids.indexOf(id);
149
- if (idIndex > -1) {
150
- ids.splice(idIndex, 1);
151
- result = it.next();
152
- }
153
- else {
154
- break;
155
- }
156
- }
157
- }
158
- // When called for unchecking, the parent items are not needed.
159
- // That is why, for optimization, they are not returned.
160
- function makeParentsIterator() {
161
- var parents, i, parentId;
162
- return __generator(this, function (_a) {
163
- switch (_a.label) {
164
- case 0:
165
- if (!idField) return [3 /*break*/, 5];
166
- parents = getAllParents(itemHierarchicalIndex, childrenField, data);
167
- i = parents.length - 1;
168
- _a.label = 1;
169
- case 1:
170
- if (!(i > -1)) return [3 /*break*/, 4];
171
- return [4 /*yield*/, { id: getNestedValue(idField, parents[i]), item: itemJustChecked ? parents[i] : undefined }];
172
- case 2:
173
- _a.sent();
174
- _a.label = 3;
175
- case 3:
176
- i--;
177
- return [3 /*break*/, 1];
178
- case 4: return [3 /*break*/, 8];
179
- case 5:
180
- parentId = treeIdUtils.getDirectParentId(itemHierarchicalIndex);
181
- _a.label = 6;
182
- case 6:
183
- if (!parentId) return [3 /*break*/, 8];
184
- return [4 /*yield*/, { id: parentId, item: itemJustChecked ? treeIdUtils.getItemById(parentId, data, childrenField) : undefined }];
185
- case 7:
186
- _a.sent();
187
- parentId = treeIdUtils.getDirectParentId(parentId);
188
- return [3 /*break*/, 6];
189
- case 8: return [2 /*return*/];
190
- }
191
- });
192
- }
193
- }
package/dist/es/main.js DELETED
@@ -1,10 +0,0 @@
1
- import { TreeView } from './TreeView';
2
- import { processTreeViewItems } from './processTreeViewItems';
3
- import { moveTreeViewItem } from './moveTreeViewItem';
4
- import { handleTreeViewCheckChange } from './handleTreeViewCheckChange';
5
- import { TreeViewDragClue } from './TreeViewDragClue';
6
- import { TreeViewDragAnalyzer } from './TreeViewDragAnalyzer';
7
- import { TreeViewItemPropsContext } from './TreeViewItem';
8
- import getItemIdUponKeyboardNavigation from './utils/getItemIdUponKeyboardNavigation';
9
- import { TreeFieldsService as FieldsService } from '@progress/kendo-react-common';
10
- export { TreeViewItemPropsContext, TreeView, processTreeViewItems, handleTreeViewCheckChange, TreeViewDragClue, moveTreeViewItem, TreeViewDragAnalyzer, getItemIdUponKeyboardNavigation, FieldsService };
@@ -1,109 +0,0 @@
1
- /**
2
- * A helper function which moves a TreeView item in an immutable way.
3
- *
4
- * @param sourceItemHierarchicalIndex - The hierarchical index of the item that will be moved.
5
- * @param sourceData - The tree which contains the item that will be moved.
6
- * @param operation - The specific move operation.
7
- *
8
- * The available options are:
9
- * * `before`&mdash;Indicates that the source item will become the previous sibling of the target item.
10
- * * `after`&mdash;Indicates that the source item will become the next sibling of the target item.
11
- * * `child`&mdash;Indicates that the source item will become a child of the target item.
12
- * @param targetItemHierarchicalIndex - The hierarchical index of the item next to which the source item will be moved.
13
- * @param targetData - The tree which contains the target item.
14
- * If the argument is skipped, then the move operation will be executed within the same tree.
15
- * Setting the `sourceData` and `targetData` arguments to the same tree is also supported.
16
- * @param childrenField - The field that points to the dataItem sub items. Defaults to `items`.
17
- * @returns - The updated copies of the `sourceData` and `targetData` input arguments.
18
- * If `targetData` is not passed, then only the updated copy of the `sourceData` will be returned.
19
- *
20
- * @example
21
- * ```jsx
22
- * class App extends React.Component {
23
- * dragClue;
24
- * state = { tree };
25
- *
26
- * render() {
27
- * return (
28
- * <div>
29
- * <TreeView data={this.state.tree} draggable={true}
30
- * onItemDragOver={this.onItemDragOver} onItemDragEnd={this.onItemDragEnd} />
31
- * <TreeViewDragClue ref={dragClue => this.dragClue = dragClue} />
32
- * </div>
33
- * );
34
- * }
35
- *
36
- * onItemDragOver = (event) => {
37
- * this.dragClue.show(event.pageY + 10, event.pageX, event.item.text, this.getClueClassName(event));
38
- * }
39
- * onItemDragEnd = (event) => {
40
- * this.dragClue.hide();
41
- * const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
42
- *
43
- * if (eventAnalyzer.isDropAllowed) {
44
- * const updatedTree = moveTreeViewItem(
45
- * event.itemHierarchicalIndex,
46
- * this.state.tree,
47
- * eventAnalyzer.getDropOperation(),
48
- * eventAnalyzer.destinationMeta.itemHierarchicalIndex,
49
- * );
50
- *
51
- * this.setState({ tree: updatedTree });
52
- * }
53
- * }
54
- * getClueClassName(event) {
55
- * const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
56
- * const itemIndex = eventAnalyzer.destinationMeta.itemHierarchicalIndex;
57
- *
58
- * if (eventAnalyzer.isDropAllowed) {
59
- * switch (eventAnalyzer.getDropOperation()) {
60
- * case 'child':
61
- * return 'k-i-plus';
62
- * case 'before':
63
- * return itemIndex === '0' || itemIndex.endsWith(`${SEPARATOR}0`) ?
64
- * 'k-i-insert-up' : 'k-i-insert-middle';
65
- * case 'after':
66
- * const siblings = getSiblings(itemIndex, this.state.tree);
67
- * const lastIndex = Number(itemIndex.split(SEPARATOR).pop());
68
- *
69
- * return lastIndex < siblings.length - 1 ? 'k-i-insert-middle' : 'k-i-insert-down';
70
- * default:
71
- * break;
72
- * }
73
- * }
74
- *
75
- * return 'k-i-cancel';
76
- * }
77
- * }
78
- *
79
- * function getSiblings(itemIndex, data) {
80
- * let result = data;
81
- *
82
- * const indices = itemIndex.split(SEPARATOR).map(index => Number(index));
83
- * for (let i = 0; i < indices.length - 1; i++) {
84
- * result = result[indices[i]].items;
85
- * }
86
- *
87
- * return result;
88
- * }
89
- *
90
- * const SEPARATOR = '_';
91
- * const tree = [{
92
- * text: 'Furniture', expanded: true, items: [
93
- * { text: 'Tables & Chairs', expanded: true },
94
- * { text: 'Sofas', expanded: true },
95
- * { text: 'Occasional Furniture', expanded: true }]
96
- * }, {
97
- * text: 'Decor', expanded: true, items: [
98
- * { text: 'Bed Linen', expanded: true },
99
- * { text: 'Curtains & Blinds', expanded: true },
100
- * { text: 'Carpets', expanded: true }]
101
- * }];
102
- *
103
- * ReactDOM.render(<App />, document.querySelector('my-app'));
104
- * ```
105
- */
106
- export declare function moveTreeViewItem(sourceItemHierarchicalIndex: string, sourceData: any[] | null | undefined, operation: 'before' | 'after' | 'child', targetItemHierarchicalIndex: string, targetData?: any[] | null, childrenField?: string): any[] | {
107
- sourceData: any[] | null | undefined;
108
- targetData: any[];
109
- } | null | undefined;