@progress/kendo-vue-treeview 3.2.2-dev.202204181420

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 (87) hide show
  1. package/LICENSE.md +11 -0
  2. package/NOTICE.txt +86 -0
  3. package/README.md +53 -0
  4. package/dist/cdn/js/kendo-vue-treeview.js +1 -0
  5. package/dist/es/ItemRenderProps.d.ts +13 -0
  6. package/dist/es/ItemRenderProps.js +1 -0
  7. package/dist/es/TreeView.d.ts +45 -0
  8. package/dist/es/TreeView.js +359 -0
  9. package/dist/es/TreeViewDragAnalyzer.d.ts +135 -0
  10. package/dist/es/TreeViewDragAnalyzer.js +184 -0
  11. package/dist/es/TreeViewDragClue.d.ts +135 -0
  12. package/dist/es/TreeViewDragClue.js +78 -0
  13. package/dist/es/TreeViewItem.d.ts +69 -0
  14. package/dist/es/TreeViewItem.js +359 -0
  15. package/dist/es/TreeViewOperationDescriptors.d.ts +76 -0
  16. package/dist/es/TreeViewOperationDescriptors.js +1 -0
  17. package/dist/es/TreeViewProps.d.ts +122 -0
  18. package/dist/es/TreeViewProps.js +0 -0
  19. package/dist/es/additionalTypes.ts +9 -0
  20. package/dist/es/events.d.ts +135 -0
  21. package/dist/es/events.js +0 -0
  22. package/dist/es/handleTreeViewCheckChange.d.ts +67 -0
  23. package/dist/es/handleTreeViewCheckChange.js +195 -0
  24. package/dist/es/main.d.ts +12 -0
  25. package/dist/es/main.js +8 -0
  26. package/dist/es/moveTreeViewItem.d.ts +109 -0
  27. package/dist/es/moveTreeViewItem.js +156 -0
  28. package/dist/es/package-metadata.d.ts +5 -0
  29. package/dist/es/package-metadata.js +11 -0
  30. package/dist/es/processTreeViewItems.d.ts +51 -0
  31. package/dist/es/processTreeViewItems.js +166 -0
  32. package/dist/es/utils/FieldsService.d.ts +26 -0
  33. package/dist/es/utils/FieldsService.js +50 -0
  34. package/dist/es/utils/SortedPublicItemIds.d.ts +8 -0
  35. package/dist/es/utils/SortedPublicItemIds.js +26 -0
  36. package/dist/es/utils/consts.d.ts +40 -0
  37. package/dist/es/utils/consts.js +40 -0
  38. package/dist/es/utils/getItemIdUponKeyboardNavigation.d.ts +5 -0
  39. package/dist/es/utils/getItemIdUponKeyboardNavigation.js +77 -0
  40. package/dist/es/utils/itemIdUtils.d.ts +60 -0
  41. package/dist/es/utils/itemIdUtils.js +117 -0
  42. package/dist/es/utils/itemUtils.d.ts +45 -0
  43. package/dist/es/utils/itemUtils.js +191 -0
  44. package/dist/es/utils/misc.d.ts +9 -0
  45. package/dist/es/utils/misc.js +17 -0
  46. package/dist/npm/ItemRenderProps.d.ts +13 -0
  47. package/dist/npm/ItemRenderProps.js +3 -0
  48. package/dist/npm/TreeView.d.ts +45 -0
  49. package/dist/npm/TreeView.js +376 -0
  50. package/dist/npm/TreeViewDragAnalyzer.d.ts +135 -0
  51. package/dist/npm/TreeViewDragAnalyzer.js +186 -0
  52. package/dist/npm/TreeViewDragClue.d.ts +135 -0
  53. package/dist/npm/TreeViewDragClue.js +88 -0
  54. package/dist/npm/TreeViewItem.d.ts +69 -0
  55. package/dist/npm/TreeViewItem.js +373 -0
  56. package/dist/npm/TreeViewOperationDescriptors.d.ts +76 -0
  57. package/dist/npm/TreeViewOperationDescriptors.js +3 -0
  58. package/dist/npm/TreeViewProps.d.ts +122 -0
  59. package/dist/npm/TreeViewProps.js +2 -0
  60. package/dist/npm/additionalTypes.ts +9 -0
  61. package/dist/npm/events.d.ts +135 -0
  62. package/dist/npm/events.js +2 -0
  63. package/dist/npm/handleTreeViewCheckChange.d.ts +67 -0
  64. package/dist/npm/handleTreeViewCheckChange.js +199 -0
  65. package/dist/npm/main.d.ts +12 -0
  66. package/dist/npm/main.js +17 -0
  67. package/dist/npm/moveTreeViewItem.d.ts +109 -0
  68. package/dist/npm/moveTreeViewItem.js +159 -0
  69. package/dist/npm/package-metadata.d.ts +5 -0
  70. package/dist/npm/package-metadata.js +14 -0
  71. package/dist/npm/processTreeViewItems.d.ts +51 -0
  72. package/dist/npm/processTreeViewItems.js +169 -0
  73. package/dist/npm/utils/FieldsService.d.ts +26 -0
  74. package/dist/npm/utils/FieldsService.js +52 -0
  75. package/dist/npm/utils/SortedPublicItemIds.d.ts +8 -0
  76. package/dist/npm/utils/SortedPublicItemIds.js +28 -0
  77. package/dist/npm/utils/consts.d.ts +40 -0
  78. package/dist/npm/utils/consts.js +43 -0
  79. package/dist/npm/utils/getItemIdUponKeyboardNavigation.d.ts +5 -0
  80. package/dist/npm/utils/getItemIdUponKeyboardNavigation.js +80 -0
  81. package/dist/npm/utils/itemIdUtils.d.ts +60 -0
  82. package/dist/npm/utils/itemIdUtils.js +132 -0
  83. package/dist/npm/utils/itemUtils.d.ts +45 -0
  84. package/dist/npm/utils/itemUtils.js +205 -0
  85. package/dist/npm/utils/misc.d.ts +9 -0
  86. package/dist/npm/utils/misc.js +22 -0
  87. package/package.json +56 -0
@@ -0,0 +1,109 @@
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`—Indicates that the source item will become the previous sibling of the target item.
10
+ * * `after`—Indicates that the source item will become the next sibling of the target item.
11
+ * * `child`—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 default function moveTreeViewItem(sourceItemHierarchicalIndex: string, sourceData: any[] | null | undefined, operation: 'before' | 'after' | 'child', targetItemHierarchicalIndex: string, targetData?: any[] | null, childrenField?: string): any[] | {
107
+ sourceData: any[];
108
+ targetData: any[];
109
+ };
@@ -0,0 +1,156 @@
1
+ import { addItem, removeItem } from './utils/itemUtils';
2
+ import { getDecrementedItemIdAfterRemoval, getItemById } from './utils/itemIdUtils';
3
+ import { CHILDREN_FIELD } from './utils/consts';
4
+ /**
5
+ * A helper function which moves a TreeView item in an immutable way.
6
+ *
7
+ * @param sourceItemHierarchicalIndex - The hierarchical index of the item that will be moved.
8
+ * @param sourceData - The tree which contains the item that will be moved.
9
+ * @param operation - The specific move operation.
10
+ *
11
+ * The available options are:
12
+ * * `before`&mdash;Indicates that the source item will become the previous sibling of the target item.
13
+ * * `after`&mdash;Indicates that the source item will become the next sibling of the target item.
14
+ * * `child`&mdash;Indicates that the source item will become a child of the target item.
15
+ * @param targetItemHierarchicalIndex - The hierarchical index of the item next to which the source item will be moved.
16
+ * @param targetData - The tree which contains the target item.
17
+ * If the argument is skipped, then the move operation will be executed within the same tree.
18
+ * Setting the `sourceData` and `targetData` arguments to the same tree is also supported.
19
+ * @param childrenField - The field that points to the dataItem sub items. Defaults to `items`.
20
+ * @returns - The updated copies of the `sourceData` and `targetData` input arguments.
21
+ * If `targetData` is not passed, then only the updated copy of the `sourceData` will be returned.
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * class App extends React.Component {
26
+ * dragClue;
27
+ * state = { tree };
28
+ *
29
+ * render() {
30
+ * return (
31
+ * <div>
32
+ * <TreeView data={this.state.tree} draggable={true}
33
+ * onItemDragOver={this.onItemDragOver} onItemDragEnd={this.onItemDragEnd} />
34
+ * <TreeViewDragClue ref={dragClue => this.dragClue = dragClue} />
35
+ * </div>
36
+ * );
37
+ * }
38
+ *
39
+ * onItemDragOver = (event) => {
40
+ * this.dragClue.show(event.pageY + 10, event.pageX, event.item.text, this.getClueClassName(event));
41
+ * }
42
+ * onItemDragEnd = (event) => {
43
+ * this.dragClue.hide();
44
+ * const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
45
+ *
46
+ * if (eventAnalyzer.isDropAllowed) {
47
+ * const updatedTree = moveTreeViewItem(
48
+ * event.itemHierarchicalIndex,
49
+ * this.state.tree,
50
+ * eventAnalyzer.getDropOperation(),
51
+ * eventAnalyzer.destinationMeta.itemHierarchicalIndex,
52
+ * );
53
+ *
54
+ * this.setState({ tree: updatedTree });
55
+ * }
56
+ * }
57
+ * getClueClassName(event) {
58
+ * const eventAnalyzer = new TreeViewDragAnalyzer(event).init();
59
+ * const itemIndex = eventAnalyzer.destinationMeta.itemHierarchicalIndex;
60
+ *
61
+ * if (eventAnalyzer.isDropAllowed) {
62
+ * switch (eventAnalyzer.getDropOperation()) {
63
+ * case 'child':
64
+ * return 'k-i-plus';
65
+ * case 'before':
66
+ * return itemIndex === '0' || itemIndex.endsWith(`${SEPARATOR}0`) ?
67
+ * 'k-i-insert-up' : 'k-i-insert-middle';
68
+ * case 'after':
69
+ * const siblings = getSiblings(itemIndex, this.state.tree);
70
+ * const lastIndex = Number(itemIndex.split(SEPARATOR).pop());
71
+ *
72
+ * return lastIndex < siblings.length - 1 ? 'k-i-insert-middle' : 'k-i-insert-down';
73
+ * default:
74
+ * break;
75
+ * }
76
+ * }
77
+ *
78
+ * return 'k-i-cancel';
79
+ * }
80
+ * }
81
+ *
82
+ * function getSiblings(itemIndex, data) {
83
+ * let result = data;
84
+ *
85
+ * const indices = itemIndex.split(SEPARATOR).map(index => Number(index));
86
+ * for (let i = 0; i < indices.length - 1; i++) {
87
+ * result = result[indices[i]].items;
88
+ * }
89
+ *
90
+ * return result;
91
+ * }
92
+ *
93
+ * const SEPARATOR = '_';
94
+ * const tree = [{
95
+ * text: 'Furniture', expanded: true, items: [
96
+ * { text: 'Tables & Chairs', expanded: true },
97
+ * { text: 'Sofas', expanded: true },
98
+ * { text: 'Occasional Furniture', expanded: true }]
99
+ * }, {
100
+ * text: 'Decor', expanded: true, items: [
101
+ * { text: 'Bed Linen', expanded: true },
102
+ * { text: 'Curtains & Blinds', expanded: true },
103
+ * { text: 'Carpets', expanded: true }]
104
+ * }];
105
+ *
106
+ * ReactDOM.render(<App />, document.querySelector('my-app'));
107
+ * ```
108
+ */
109
+ export default function moveTreeViewItem(sourceItemHierarchicalIndex, sourceData, operation, targetItemHierarchicalIndex, targetData, childrenField) {
110
+ var subItemsField = childrenField || CHILDREN_FIELD;
111
+ if (!validateInput()) {
112
+ return prepareInputDataForReturn();
113
+ }
114
+ var sourceItem = getItemById(sourceItemHierarchicalIndex, sourceData, subItemsField);
115
+ if (!sourceItem) {
116
+ return prepareInputDataForReturn();
117
+ }
118
+ // The source and the target tree are the same.
119
+ if (!targetData || targetData === sourceData) {
120
+ if (!validateNoCircularReference()) {
121
+ return prepareInputDataForReturn();
122
+ }
123
+ var updatedSourceData = removeItem(sourceItemHierarchicalIndex, subItemsField, sourceData);
124
+ var resultData = addItem(sourceItem, operation, subItemsField, getDecrementedItemIdAfterRemoval(sourceItemHierarchicalIndex, targetItemHierarchicalIndex), updatedSourceData);
125
+ // A simpler output is explicitly returned when the source and the target tree are
126
+ // the same, that is, the targetData argument is skipped.
127
+ return targetData ? { sourceData: resultData, targetData: resultData } : resultData;
128
+ }
129
+ else {
130
+ var updatedSource = removeItem(sourceItemHierarchicalIndex, subItemsField, sourceData);
131
+ var updatedTarget = addItem(sourceItem, operation, subItemsField, targetItemHierarchicalIndex, targetData);
132
+ return { sourceData: updatedSource, targetData: updatedTarget };
133
+ }
134
+ function prepareInputDataForReturn() {
135
+ return targetData ? { sourceData: sourceData, targetData: targetData } : sourceData;
136
+ }
137
+ function validateNoCircularReference() {
138
+ return !(targetItemHierarchicalIndex + "_").startsWith(sourceItemHierarchicalIndex + "_");
139
+ }
140
+ function validateInput() {
141
+ if (!sourceData || !sourceData.length ||
142
+ !sourceItemHierarchicalIndex || !targetItemHierarchicalIndex) {
143
+ return false;
144
+ }
145
+ if (targetData && !targetData.length) {
146
+ // Dropping over an empty tree is not supported.
147
+ return false;
148
+ }
149
+ // Validate that the target item exists.
150
+ var data = !targetData || targetData === sourceData ? sourceData : targetData;
151
+ if (!getItemById(targetItemHierarchicalIndex, data, subItemsField)) {
152
+ return false;
153
+ }
154
+ return true;
155
+ }
156
+ }
@@ -0,0 +1,5 @@
1
+ import { PackageMetadata } from '@progress/kendo-licensing';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export declare const packageMetadata: PackageMetadata;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export var packageMetadata = {
5
+ name: '@progress/kendo-vue-treeview',
6
+ productName: 'Kendo UI for Vue',
7
+ productCodes: ['KENDOUIVUE', 'KENDOUICOMPLETE'],
8
+ publishDate: 1650291464,
9
+ version: '',
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
+ };
@@ -0,0 +1,51 @@
1
+ import { TreeViewOperationDescriptors } from './TreeViewOperationDescriptors';
2
+ /**
3
+ * A helper function which applies the specified operation descriptors to the data.
4
+ * * [Expanding and collapsing items]({% slug expansion_ways_treeview %}#toc-using-a-helper-function)
5
+ * * [Selecting and deselecting items]({% slug selection_ways_treeview %}#toc-using-a-helper-function)
6
+ * * [Checking and unchecking items]({% slug check_helper_funcs_treeview %})
7
+ *
8
+ * @param data - The data that will be processed.
9
+ * @param operations - The operation descriptors that will be applied to the data.
10
+ * @returns - The processed copy of the input data.
11
+ *
12
+ * @example
13
+ * ```jsx
14
+ * class App extends React.Component {
15
+ * state = { items: tree, expand: [], select: [], check: [] };
16
+ * render() {
17
+ * const { expand, select, check } = this.state;
18
+ * return (
19
+ * <TreeView
20
+ * data={processTreeViewItems(this.state.items, { expand, select, check })}
21
+ * expandIcons={true} onExpandChange={this.onExpandChange} checkboxes={true}
22
+ * onCheckChange={event => this.setState({ check: [ event.itemHierarchicalIndex ] })}
23
+ * onItemClick={event => this.setState({ select: [ event.itemHierarchicalIndex ] })}
24
+ * />
25
+ * );
26
+ * }
27
+ * onExpandChange = (event) => {
28
+ * let expand = this.state.expand.slice();
29
+ * const index = expand.indexOf(event.itemHierarchicalIndex);
30
+ * index === -1 ? expand.push(event.itemHierarchicalIndex) : expand.splice(index, 1);
31
+ * this.setState({ expand });
32
+ * }
33
+ * }
34
+ *
35
+ * const tree = [{
36
+ * text: 'Item1',
37
+ * items: [
38
+ * { text: 'Item1.1' },
39
+ * { text: 'Item1.2' },
40
+ * { text: 'Item1.3', items: [{ text: 'Item1.3.1' }] }]
41
+ * }, {
42
+ * text: 'Item2', disabled: true,
43
+ * items: [{ text: 'Item2.1' }, { text: 'Item2.2' }, { text: 'Item2.3' }]
44
+ * }, {
45
+ * text: 'Item3'
46
+ * }];
47
+ *
48
+ * ReactDOM.render(<App />, document.querySelector('my-app'));
49
+ * ```
50
+ */
51
+ export default function processTreeViewItems(data: any[] | null | undefined, operations: TreeViewOperationDescriptors): any[];
@@ -0,0 +1,166 @@
1
+ /* eslint-disable max-len */
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ import { updateItem, resolveItemsIds } from './utils/itemUtils';
14
+ import { EXPAND_FIELD, SELECT_FIELD, CHECK_FIELD, CHECK_INDETERMINATE_FIELD, CHILDREN_FIELD } from './utils/consts';
15
+ import { getNestedValue, isArray } from './utils/misc';
16
+ /**
17
+ * A helper function which applies the specified operation descriptors to the data.
18
+ * * [Expanding and collapsing items]({% slug expansion_ways_treeview %}#toc-using-a-helper-function)
19
+ * * [Selecting and deselecting items]({% slug selection_ways_treeview %}#toc-using-a-helper-function)
20
+ * * [Checking and unchecking items]({% slug check_helper_funcs_treeview %})
21
+ *
22
+ * @param data - The data that will be processed.
23
+ * @param operations - The operation descriptors that will be applied to the data.
24
+ * @returns - The processed copy of the input data.
25
+ *
26
+ * @example
27
+ * ```jsx
28
+ * class App extends React.Component {
29
+ * state = { items: tree, expand: [], select: [], check: [] };
30
+ * render() {
31
+ * const { expand, select, check } = this.state;
32
+ * return (
33
+ * <TreeView
34
+ * data={processTreeViewItems(this.state.items, { expand, select, check })}
35
+ * expandIcons={true} onExpandChange={this.onExpandChange} checkboxes={true}
36
+ * onCheckChange={event => this.setState({ check: [ event.itemHierarchicalIndex ] })}
37
+ * onItemClick={event => this.setState({ select: [ event.itemHierarchicalIndex ] })}
38
+ * />
39
+ * );
40
+ * }
41
+ * onExpandChange = (event) => {
42
+ * let expand = this.state.expand.slice();
43
+ * const index = expand.indexOf(event.itemHierarchicalIndex);
44
+ * index === -1 ? expand.push(event.itemHierarchicalIndex) : expand.splice(index, 1);
45
+ * this.setState({ expand });
46
+ * }
47
+ * }
48
+ *
49
+ * const tree = [{
50
+ * text: 'Item1',
51
+ * items: [
52
+ * { text: 'Item1.1' },
53
+ * { text: 'Item1.2' },
54
+ * { text: 'Item1.3', items: [{ text: 'Item1.3.1' }] }]
55
+ * }, {
56
+ * text: 'Item2', disabled: true,
57
+ * items: [{ text: 'Item2.1' }, { text: 'Item2.2' }, { text: 'Item2.3' }]
58
+ * }, {
59
+ * text: 'Item3'
60
+ * }];
61
+ *
62
+ * ReactDOM.render(<App />, document.querySelector('my-app'));
63
+ * ```
64
+ */
65
+ export default function processTreeViewItems(data, operations) {
66
+ if (!data || !data.length) {
67
+ return [];
68
+ }
69
+ var result = data;
70
+ var cloneField = operations.cloneField || 'cloned';
71
+ var expandField = operations.expandField || EXPAND_FIELD;
72
+ var selectField = operations.selectField || SELECT_FIELD;
73
+ var checkField = operations.checkField || CHECK_FIELD;
74
+ var childrenField = operations.childrenField || CHILDREN_FIELD;
75
+ result = handleOperation(result, expandField, operations.expand, cloneField, childrenField);
76
+ result = handleOperation(result, selectField, operations.select, cloneField, childrenField);
77
+ result = handleOperation(result, checkField, operations.check, cloneField, childrenField);
78
+ applyCheckIndeterminate(result, childrenField, operations.check);
79
+ return result;
80
+ }
81
+ function handleOperation(items, defaultField, operation, cloneField, childrenField) {
82
+ if (operation) {
83
+ var _a = parseOperation(operation, defaultField), ids = _a.ids, field = _a.field;
84
+ var indices = !isArray(operation) && operation.idField
85
+ ? resolveItemsIds(ids, operation.idField, items, childrenField)
86
+ : ids;
87
+ return raiseFlags(items, indices, field, cloneField, childrenField);
88
+ }
89
+ else {
90
+ return items;
91
+ }
92
+ }
93
+ function parseOperation(operation, defaultField) {
94
+ var ids;
95
+ var field;
96
+ if (isArray(operation)) {
97
+ ids = operation;
98
+ field = defaultField;
99
+ }
100
+ else {
101
+ ids = operation.ids || [];
102
+ field = operation.operationField || defaultField;
103
+ }
104
+ return { ids: ids, field: field };
105
+ }
106
+ function raiseFlags(items, indices, field, cloneField, childrenField) {
107
+ var result = items;
108
+ indices.forEach(function (itemIndex) {
109
+ result = updateItem(result, itemIndex, function (item) { return raiseNestedFlag(field, item); }, cloneField, childrenField);
110
+ });
111
+ return result;
112
+ }
113
+ function raiseNestedFlag(fieldName, dataItem) {
114
+ var fields = (fieldName || '').split('.');
115
+ var item = dataItem;
116
+ for (var index = 0; index < fields.length; index++) {
117
+ var field = fields[index];
118
+ if (index === fields.length - 1) {
119
+ item[field] = true;
120
+ }
121
+ else if (item[field] !== undefined) {
122
+ item[field] = __assign({}, item[field]);
123
+ item = item[field];
124
+ }
125
+ else {
126
+ return;
127
+ }
128
+ }
129
+ }
130
+ function applyCheckIndeterminate(items, childrenField, check) {
131
+ if (check && !isArray(check) && check.applyCheckIndeterminate) {
132
+ var checkField = parseOperation(check, CHECK_FIELD).field;
133
+ var checkIndeterminateField = check.checkIndeterminateField || CHECK_INDETERMINATE_FIELD;
134
+ for (var i = 0; i < items.length; i++) {
135
+ var item = items[i];
136
+ var subItems = item[childrenField];
137
+ if (subItems) {
138
+ applyCheckIndeterminateHelper(subItems, getNestedValue(checkField, item) ? [] : [item], childrenField, checkField, checkIndeterminateField);
139
+ }
140
+ }
141
+ }
142
+ }
143
+ function applyCheckIndeterminateHelper(data, parents, childrenField, checkField, checkIndeterminateField) {
144
+ // The updates will be direct because the corresponding items
145
+ // are already cloned because of their checked children.
146
+ var parentsAlreadyUpdated = false;
147
+ for (var i = 0; i < data.length; i++) {
148
+ var item = data[i];
149
+ if (getNestedValue(checkField, item)) {
150
+ if (!parentsAlreadyUpdated) {
151
+ for (var j = 0; j < parents.length; j++) {
152
+ raiseNestedFlag(checkIndeterminateField, parents[j]);
153
+ }
154
+ }
155
+ parentsAlreadyUpdated = true;
156
+ if (item[childrenField]) {
157
+ applyCheckIndeterminateHelper(item[childrenField], [], childrenField, checkField, checkIndeterminateField);
158
+ }
159
+ }
160
+ else {
161
+ if (item[childrenField]) {
162
+ applyCheckIndeterminateHelper(item[childrenField], parentsAlreadyUpdated ? [item] : parents.concat([item]), childrenField, checkField, checkIndeterminateField);
163
+ }
164
+ }
165
+ }
166
+ }
@@ -0,0 +1,26 @@
1
+ import { TreeViewProps } from '../TreeViewProps';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export default class FieldsService {
6
+ focusIdField: string | undefined;
7
+ private expandField;
8
+ private selectField;
9
+ private childrenField;
10
+ private hasChildrenField;
11
+ private textField;
12
+ private disableField;
13
+ private checkField;
14
+ private checkIndeterminateField;
15
+ constructor(treeViewProps: TreeViewProps);
16
+ expanded(item: any): boolean | undefined;
17
+ selected(item: any): boolean | undefined;
18
+ text(item: any): string | undefined;
19
+ disabled(item: any): boolean | undefined;
20
+ hasChildren(item: any): boolean | undefined;
21
+ children(item: any): any[];
22
+ checked(item: any): boolean | undefined;
23
+ checkIndeterminate(item: any): boolean | undefined;
24
+ focusId(item: any): any;
25
+ getChildrenField(): string;
26
+ }
@@ -0,0 +1,50 @@
1
+ import { getNestedValue } from './misc';
2
+ /**
3
+ * @hidden
4
+ */
5
+ var FieldsService = /** @class */ (function () {
6
+ function FieldsService(treeViewProps) {
7
+ this.expandField = treeViewProps.expandField;
8
+ this.selectField = treeViewProps.selectField;
9
+ this.hasChildrenField = treeViewProps.hasChildrenField;
10
+ this.childrenField = treeViewProps.childrenField;
11
+ this.textField = treeViewProps.textField;
12
+ this.disableField = treeViewProps.disableField;
13
+ this.checkField = treeViewProps.checkField;
14
+ this.checkIndeterminateField = treeViewProps.checkIndeterminateField;
15
+ this.focusIdField = treeViewProps.focusIdField;
16
+ }
17
+ FieldsService.prototype.expanded = function (item) {
18
+ return getNestedValue(this.expandField, item);
19
+ };
20
+ FieldsService.prototype.selected = function (item) {
21
+ return getNestedValue(this.selectField, item);
22
+ };
23
+ FieldsService.prototype.text = function (item) {
24
+ return getNestedValue(this.textField, item);
25
+ };
26
+ FieldsService.prototype.disabled = function (item) {
27
+ return getNestedValue(this.disableField, item);
28
+ };
29
+ FieldsService.prototype.hasChildren = function (item) {
30
+ return getNestedValue(this.hasChildrenField, item);
31
+ };
32
+ FieldsService.prototype.children = function (item) {
33
+ var children = getNestedValue(this.childrenField, item);
34
+ return children ? children : [];
35
+ };
36
+ FieldsService.prototype.checked = function (item) {
37
+ return getNestedValue(this.checkField, item);
38
+ };
39
+ FieldsService.prototype.checkIndeterminate = function (item) {
40
+ return getNestedValue(this.checkIndeterminateField, item);
41
+ };
42
+ FieldsService.prototype.focusId = function (item) {
43
+ return this.focusIdField && getNestedValue(this.focusIdField, item);
44
+ };
45
+ FieldsService.prototype.getChildrenField = function () {
46
+ return this.childrenField;
47
+ };
48
+ return FieldsService;
49
+ }());
50
+ export default FieldsService;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export default class SortedPublicItemIds {
5
+ private objects;
6
+ init(publicItemIds: any[]): void;
7
+ hasId(publicItemId: any): boolean;
8
+ }
@@ -0,0 +1,26 @@
1
+ var PROPS_COUNT_LIMIT = 50000;
2
+ /**
3
+ * @hidden
4
+ */
5
+ // An alternative is to use array.sort() and
6
+ // implement a binary search function.
7
+ var SortedPublicItemIds = /** @class */ (function () {
8
+ function SortedPublicItemIds() {
9
+ this.objects = [];
10
+ }
11
+ SortedPublicItemIds.prototype.init = function (publicItemIds) {
12
+ var currentObj;
13
+ for (var i = 0; i < publicItemIds.length; i++) {
14
+ if (i % PROPS_COUNT_LIMIT === 0) {
15
+ currentObj = {};
16
+ this.objects.push(currentObj);
17
+ }
18
+ currentObj[publicItemIds[i]] = true;
19
+ }
20
+ };
21
+ SortedPublicItemIds.prototype.hasId = function (publicItemId) {
22
+ return this.objects.some(function (obj) { return obj[publicItemId]; });
23
+ };
24
+ return SortedPublicItemIds;
25
+ }());
26
+ export default SortedPublicItemIds;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export declare const EXPAND_FIELD = "expanded";
5
+ /**
6
+ * @hidden
7
+ */
8
+ export declare const TEXT_FIELD = "text";
9
+ /**
10
+ * @hidden
11
+ */
12
+ export declare const DISABLED_FIELD = "disabled";
13
+ /**
14
+ * @hidden
15
+ */
16
+ export declare const CHILDREN_FIELD = "items";
17
+ /**
18
+ * @hidden
19
+ */
20
+ export declare const HAS_CHILDREN_FIELD = "hasChildren";
21
+ /**
22
+ * @hidden
23
+ */
24
+ export declare const SELECT_FIELD = "selected";
25
+ /**
26
+ * @hidden
27
+ */
28
+ export declare const CHECK_FIELD = "checked";
29
+ /**
30
+ * @hidden
31
+ */
32
+ export declare const CHECK_INDETERMINATE_FIELD = "checkIndeterminate";
33
+ /**
34
+ * @hidden
35
+ */
36
+ export declare const DOM_KENDO_ITEM_ID_FIELD = "_kendoItemId";
37
+ /**
38
+ * @hidden
39
+ */
40
+ export declare const DOM_KENDO_TREEVIEW_GUID_FIELD = "_kendoTreeViewGuid";