@elliemae/ds-treeview 2.2.0-alpha.2 → 2.2.0-next.1

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 (206) hide show
  1. package/cjs/TreeView.js +27 -49
  2. package/cjs/TreeViewContext.js +37 -61
  3. package/cjs/config/cssClassesConstants.js +13 -41
  4. package/cjs/config/useTreeview.js +78 -116
  5. package/cjs/hoc/DnDTreeContext.js +18 -0
  6. package/cjs/hoc/SortableItemContext.js +21 -0
  7. package/cjs/hoc/WithConditionalDnDContext.js +138 -0
  8. package/cjs/hoc/WithDnDSortableItemContext.js +70 -0
  9. package/cjs/index.js +26 -37
  10. package/cjs/parts/CheckboxSelectable.js +59 -70
  11. package/cjs/parts/ChildrenCountDisplayer.js +28 -45
  12. package/cjs/parts/DnDHandle.js +46 -0
  13. package/cjs/parts/DropIndicator.js +75 -0
  14. package/cjs/parts/ExpandCaret.js +83 -85
  15. package/cjs/parts/Icon.js +31 -46
  16. package/cjs/parts/NestingSpace.js +35 -43
  17. package/cjs/parts/RadioSelectable.js +37 -52
  18. package/cjs/parts/TreeItem.js +141 -147
  19. package/cjs/parts/TreeItemText.js +95 -88
  20. package/cjs/parts/TreeList.js +130 -119
  21. package/cjs/plugins/dnd/TreeDndPlugin.js +7 -59
  22. package/cjs/plugins/dnd/index.js +9 -28
  23. package/cjs/plugins/index.js +21 -34
  24. package/cjs/plugins/roving/TreeRovingPlugin.js +7 -35
  25. package/cjs/plugins/roving/index.js +9 -28
  26. package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -35
  27. package/cjs/plugins/searchable/index.js +9 -28
  28. package/cjs/plugins/selectable/SelectablePluginTree.js +7 -35
  29. package/cjs/plugins/selectable/index.js +9 -28
  30. package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -35
  31. package/cjs/plugins/toolbar/index.js +9 -28
  32. package/cjs/plugins/tree/TreeDataPlugin.js +7 -35
  33. package/cjs/plugins/tree/index.js +9 -28
  34. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -35
  35. package/cjs/plugins/virtualization/index.js +9 -28
  36. package/cjs/react-desc-prop-types.js +54 -82
  37. package/cjs/related-components/TreeViewSearchBar.js +40 -42
  38. package/cjs/sharedTypes.js +2 -27
  39. package/cjs/utils/array-helpers.js +11 -35
  40. package/cjs/utils/group-expands-helpers.js +59 -86
  41. package/cjs/utils/keyboard-helpers.js +90 -85
  42. package/cjs/utils/object-helpers.js +36 -43
  43. package/cjs/utils/refs-helpers.js +22 -43
  44. package/cjs/utils/selectable-helper.js +53 -61
  45. package/cjs/utils/string-helpers.js +7 -35
  46. package/cjs/utils/tree-helpers.js +161 -105
  47. package/cjs/utils/useInstanceRefActions.js +43 -54
  48. package/cjs/utils/useTree.js +80 -76
  49. package/esm/TreeView.js +16 -18
  50. package/esm/TreeViewContext.js +31 -32
  51. package/esm/config/cssClassesConstants.js +6 -12
  52. package/esm/config/useTreeview.js +56 -73
  53. package/esm/hoc/DnDTreeContext.js +14 -0
  54. package/esm/hoc/SortableItemContext.js +17 -0
  55. package/esm/hoc/WithConditionalDnDContext.js +128 -0
  56. package/esm/hoc/WithDnDSortableItemContext.js +61 -0
  57. package/esm/index.js +9 -8
  58. package/esm/parts/CheckboxSelectable.js +46 -36
  59. package/esm/parts/ChildrenCountDisplayer.js +20 -16
  60. package/esm/parts/DnDHandle.js +38 -0
  61. package/esm/parts/DropIndicator.js +68 -0
  62. package/esm/parts/ExpandCaret.js +72 -54
  63. package/esm/parts/Icon.js +22 -16
  64. package/esm/parts/NestingSpace.js +27 -14
  65. package/esm/parts/RadioSelectable.js +28 -20
  66. package/esm/parts/TreeItem.js +125 -114
  67. package/esm/parts/TreeItemText.js +85 -58
  68. package/esm/parts/TreeList.js +119 -91
  69. package/esm/plugins/dnd/TreeDndPlugin.js +3 -30
  70. package/esm/plugins/dnd/index.js +1 -3
  71. package/esm/plugins/index.js +7 -9
  72. package/esm/plugins/roving/TreeRovingPlugin.js +3 -6
  73. package/esm/plugins/roving/index.js +1 -3
  74. package/esm/plugins/searchable/SearchableTreePlugin.js +3 -6
  75. package/esm/plugins/searchable/index.js +1 -3
  76. package/esm/plugins/selectable/SelectablePluginTree.js +3 -6
  77. package/esm/plugins/selectable/index.js +1 -3
  78. package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -6
  79. package/esm/plugins/toolbar/index.js +1 -3
  80. package/esm/plugins/tree/TreeDataPlugin.js +3 -6
  81. package/esm/plugins/tree/index.js +1 -3
  82. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -6
  83. package/esm/plugins/virtualization/index.js +1 -3
  84. package/esm/react-desc-prop-types.js +44 -47
  85. package/esm/related-components/TreeViewSearchBar.js +32 -13
  86. package/esm/sharedTypes.js +1 -2
  87. package/esm/utils/array-helpers.js +6 -6
  88. package/esm/utils/group-expands-helpers.js +46 -56
  89. package/esm/utils/keyboard-helpers.js +74 -46
  90. package/esm/utils/object-helpers.js +31 -14
  91. package/esm/utils/refs-helpers.js +19 -15
  92. package/esm/utils/selectable-helper.js +43 -32
  93. package/esm/utils/string-helpers.js +3 -6
  94. package/esm/utils/tree-helpers.js +143 -73
  95. package/esm/utils/useInstanceRefActions.js +35 -21
  96. package/esm/utils/useTree.js +59 -35
  97. package/package.json +35 -19
  98. package/types/hoc/DnDTreeContext.d.ts +14 -0
  99. package/types/hoc/SortableItemContext.d.ts +19 -0
  100. package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
  101. package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
  102. package/types/parts/DnDHandle.d.ts +6 -0
  103. package/types/parts/DropIndicator.d.ts +10 -0
  104. package/types/parts/TreeItem.d.ts +4 -11
  105. package/types/parts/TreeList.d.ts +0 -4
  106. package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
  107. package/types/react-desc-prop-types.d.ts +17 -3
  108. package/types/sharedTypes.d.ts +1 -8
  109. package/types/utils/keyboard-helpers.d.ts +2 -1
  110. package/types/utils/refs-helpers.d.ts +1 -1
  111. package/types/utils/tree-helpers.d.ts +4 -1
  112. package/types/utils/useTree.d.ts +1 -0
  113. package/cjs/TreeView.js.map +0 -7
  114. package/cjs/TreeViewContext.js.map +0 -7
  115. package/cjs/config/cssClassesConstants.js.map +0 -7
  116. package/cjs/config/useTreeview.js.map +0 -7
  117. package/cjs/index.js.map +0 -7
  118. package/cjs/parts/CheckboxSelectable.js.map +0 -7
  119. package/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
  120. package/cjs/parts/ExpandCaret.js.map +0 -7
  121. package/cjs/parts/Icon.js.map +0 -7
  122. package/cjs/parts/NestingSpace.js.map +0 -7
  123. package/cjs/parts/RadioSelectable.js.map +0 -7
  124. package/cjs/parts/TreeItem.js.map +0 -7
  125. package/cjs/parts/TreeItemText.js.map +0 -7
  126. package/cjs/parts/TreeList.js.map +0 -7
  127. package/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
  128. package/cjs/plugins/dnd/index.js.map +0 -7
  129. package/cjs/plugins/index.js.map +0 -7
  130. package/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
  131. package/cjs/plugins/roving/index.js.map +0 -7
  132. package/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  133. package/cjs/plugins/searchable/index.js.map +0 -7
  134. package/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
  135. package/cjs/plugins/selectable/index.js.map +0 -7
  136. package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  137. package/cjs/plugins/toolbar/index.js.map +0 -7
  138. package/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
  139. package/cjs/plugins/tree/index.js.map +0 -7
  140. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  141. package/cjs/plugins/virtualization/index.js.map +0 -7
  142. package/cjs/react-desc-prop-types.js.map +0 -7
  143. package/cjs/related-components/TreeViewSearchBar.js.map +0 -7
  144. package/cjs/sharedTypes.js.map +0 -7
  145. package/cjs/utils/array-helpers.js.map +0 -7
  146. package/cjs/utils/dnd-helpers.js +0 -146
  147. package/cjs/utils/dnd-helpers.js.map +0 -7
  148. package/cjs/utils/group-expands-helpers.js.map +0 -7
  149. package/cjs/utils/keyboard-helpers.js.map +0 -7
  150. package/cjs/utils/object-helpers.js.map +0 -7
  151. package/cjs/utils/refs-helpers.js.map +0 -7
  152. package/cjs/utils/selectable-helper.js.map +0 -7
  153. package/cjs/utils/string-helpers.js.map +0 -7
  154. package/cjs/utils/tree-helpers.js.map +0 -7
  155. package/cjs/utils/useDnDHelpers.js +0 -199
  156. package/cjs/utils/useDnDHelpers.js.map +0 -7
  157. package/cjs/utils/useInstanceRefActions.js.map +0 -7
  158. package/cjs/utils/useTree.js.map +0 -7
  159. package/esm/TreeView.js.map +0 -7
  160. package/esm/TreeViewContext.js.map +0 -7
  161. package/esm/config/cssClassesConstants.js.map +0 -7
  162. package/esm/config/useTreeview.js.map +0 -7
  163. package/esm/index.js.map +0 -7
  164. package/esm/parts/CheckboxSelectable.js.map +0 -7
  165. package/esm/parts/ChildrenCountDisplayer.js.map +0 -7
  166. package/esm/parts/ExpandCaret.js.map +0 -7
  167. package/esm/parts/Icon.js.map +0 -7
  168. package/esm/parts/NestingSpace.js.map +0 -7
  169. package/esm/parts/RadioSelectable.js.map +0 -7
  170. package/esm/parts/TreeItem.js.map +0 -7
  171. package/esm/parts/TreeItemText.js.map +0 -7
  172. package/esm/parts/TreeList.js.map +0 -7
  173. package/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
  174. package/esm/plugins/dnd/index.js.map +0 -7
  175. package/esm/plugins/index.js.map +0 -7
  176. package/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
  177. package/esm/plugins/roving/index.js.map +0 -7
  178. package/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  179. package/esm/plugins/searchable/index.js.map +0 -7
  180. package/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
  181. package/esm/plugins/selectable/index.js.map +0 -7
  182. package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  183. package/esm/plugins/toolbar/index.js.map +0 -7
  184. package/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
  185. package/esm/plugins/tree/index.js.map +0 -7
  186. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  187. package/esm/plugins/virtualization/index.js.map +0 -7
  188. package/esm/react-desc-prop-types.js.map +0 -7
  189. package/esm/related-components/TreeViewSearchBar.js.map +0 -7
  190. package/esm/sharedTypes.js.map +0 -7
  191. package/esm/utils/array-helpers.js.map +0 -7
  192. package/esm/utils/dnd-helpers.js +0 -117
  193. package/esm/utils/dnd-helpers.js.map +0 -7
  194. package/esm/utils/group-expands-helpers.js.map +0 -7
  195. package/esm/utils/keyboard-helpers.js.map +0 -7
  196. package/esm/utils/object-helpers.js.map +0 -7
  197. package/esm/utils/refs-helpers.js.map +0 -7
  198. package/esm/utils/selectable-helper.js.map +0 -7
  199. package/esm/utils/string-helpers.js.map +0 -7
  200. package/esm/utils/tree-helpers.js.map +0 -7
  201. package/esm/utils/useDnDHelpers.js +0 -170
  202. package/esm/utils/useDnDHelpers.js.map +0 -7
  203. package/esm/utils/useInstanceRefActions.js.map +0 -7
  204. package/esm/utils/useTree.js.map +0 -7
  205. package/types/utils/dnd-helpers.d.ts +0 -39
  206. package/types/utils/useDnDHelpers.d.ts +0 -26
@@ -1,88 +1,80 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var selectable_helper_exports = {};
29
- __export(selectable_helper_exports, {
30
- getGroupCheckState: () => getGroupCheckState,
31
- selectCheckboxItemModelParentsTillRoot: () => selectCheckboxItemModelParentsTillRoot,
32
- toggleCheckboxItem: () => toggleCheckboxItem
33
- });
34
- var React = __toESM(require("react"));
35
- var import_tree_helpers = __toESM(require("./tree-helpers"));
36
- const getGroupCheckState = (node) => {
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
+ var treeHelpers = require('./tree-helpers.js');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
16
+
17
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
+
19
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
+ const getGroupCheckState = node => {
37
21
  let childAllChecked = true;
38
22
  let anyChildChecked = false;
39
- (0, import_tree_helpers.walkAllNodeChildren)(node, (childNode) => {
23
+ treeHelpers.walkAllNodeChildren(node, childNode => {
40
24
  const {
41
- model: { isChecked }
25
+ model: {
26
+ isChecked
27
+ }
42
28
  } = childNode;
43
- if (isChecked === "mixed" || isChecked === true)
44
- anyChildChecked = true;
45
- else
46
- childAllChecked = false;
29
+ if (isChecked === 'mixed' || isChecked === true) anyChildChecked = true;else childAllChecked = false;
47
30
  });
48
- if (childAllChecked)
49
- return true;
50
- if (anyChildChecked)
51
- return "mixed";
31
+ if (childAllChecked) return true;
32
+ if (anyChildChecked) return 'mixed';
52
33
  return false;
53
34
  };
54
- const selectCheckboxItemModelParentsTillRoot = (modelToCheck, triggerTreeRerender = null) => {
35
+ const selectCheckboxItemModelParentsTillRoot = function (modelToCheck) {
36
+ let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
55
37
  const newSelections = {};
56
- const { nodePath } = modelToCheck;
57
- (0, import_tree_helpers.walkParents)(nodePath, (parentNode) => {
38
+ const {
39
+ nodePath
40
+ } = modelToCheck;
41
+ treeHelpers.walkParents(nodePath, parentNode => {
58
42
  const nextState = getGroupCheckState(parentNode);
59
43
  parentNode.model.isChecked = nextState;
60
44
  newSelections[parentNode.model.id] = nextState;
61
45
  });
62
- if (triggerTreeRerender)
63
- triggerTreeRerender();
46
+ if (triggerTreeRerender) triggerTreeRerender();
64
47
  return newSelections;
65
48
  };
66
- const toggleCheckboxItem = (itemToSelect, triggerTreeRerender = null) => {
49
+ const toggleCheckboxItem = function (itemToSelect) {
50
+ let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
67
51
  const {
68
52
  node: {
69
- model: { id, isChecked, children = [] }
53
+ model: {
54
+ id,
55
+ isChecked,
56
+ children = []
57
+ }
70
58
  }
71
59
  } = itemToSelect;
72
- const newSelections = {};
73
- const nextState = isChecked === "mixed" ? true : !isChecked;
60
+ const newSelections = {}; // 'mixed' -> true -> false -> true [...->false -> true]
61
+
62
+ const nextState = isChecked === 'mixed' ? true : !isChecked;
74
63
  itemToSelect.node.model.isChecked = nextState;
75
64
  newSelections[id] = nextState;
65
+
76
66
  if (children.length > 0 && (nextState === true || nextState === false)) {
77
- (0, import_tree_helpers.walkAllNodeChildren)(itemToSelect.node, (childNode) => {
67
+ treeHelpers.walkAllNodeChildren(itemToSelect.node, childNode => {
78
68
  childNode.model.isChecked = nextState;
79
69
  newSelections[childNode.model.id] = nextState;
80
70
  });
81
71
  }
72
+
82
73
  const parentsNewSelections = selectCheckboxItemModelParentsTillRoot(itemToSelect);
83
- if (triggerTreeRerender)
84
- triggerTreeRerender();
85
- return { ...parentsNewSelections, ...newSelections };
74
+ if (triggerTreeRerender) triggerTreeRerender();
75
+ return _objectSpread(_objectSpread({}, parentsNewSelections), newSelections);
86
76
  };
87
- module.exports = __toCommonJS(selectable_helper_exports);
88
- //# sourceMappingURL=selectable-helper.js.map
77
+
78
+ exports.getGroupCheckState = getGroupCheckState;
79
+ exports.selectCheckboxItemModelParentsTillRoot = selectCheckboxItemModelParentsTillRoot;
80
+ exports.toggleCheckboxItem = toggleCheckboxItem;
@@ -1,35 +1,7 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var string_helpers_exports = {};
29
- __export(string_helpers_exports, {
30
- standardizeSearchQueryString: () => standardizeSearchQueryString
31
- });
32
- var React = __toESM(require("react"));
33
- const standardizeSearchQueryString = (input) => input.trim().toLowerCase();
34
- module.exports = __toCommonJS(string_helpers_exports);
35
- //# sourceMappingURL=string-helpers.js.map
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const standardizeSearchQueryString = input => input.trim().toLowerCase();
6
+
7
+ exports.standardizeSearchQueryString = standardizeSearchQueryString;
@@ -1,164 +1,220 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var tree_helpers_exports = {};
29
- __export(tree_helpers_exports, {
30
- cloneNode: () => cloneNode,
31
- enrichNodeModelInPlace: () => enrichNodeModelInPlace,
32
- focusItem: () => focusItem,
33
- getChildrenMatchesSearchQuery: () => getChildrenMatchesSearchQuery,
34
- getItemsParentNode: () => getItemsParentNode,
35
- getNodeById: () => getNodeById,
36
- getNodeMatchesSearchQuery: () => getNodeMatchesSearchQuery,
37
- itemsShareSameParent: () => itemsShareSameParent,
38
- walkAllNodeChildren: () => walkAllNodeChildren,
39
- walkParents: () => walkParents,
40
- walkVisibles: () => walkVisibles
41
- });
42
- var React = __toESM(require("react"));
43
- var import_react = __toESM(require("react"));
44
- var import_string_helpers = __toESM(require("./string-helpers"));
45
- const walkVisibles = (node, callback, skipRoot = true, highlightOnlyQuery = false) => {
46
- const { children, model } = node;
47
- const { name, isExpanded, childrenMatchesSearchQuery, matchesSearchQuery } = model;
48
- const shouldSkipBecauseIsRoot = skipRoot && name === "__root";
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.for-each.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.for-each.js');
8
+ require('core-js/modules/web.dom-collections.iterator.js');
9
+ require('core-js/modules/esnext.async-iterator.find.js');
10
+ require('core-js/modules/esnext.iterator.find.js');
11
+ require('core-js/modules/esnext.async-iterator.every.js');
12
+ require('core-js/modules/esnext.iterator.every.js');
13
+ var React = require('react');
14
+ var stringHelpers = require('./string-helpers.js');
15
+
16
+ const walkVisibles = function (node, callback) {
17
+ let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
18
+ let highlightOnlyQuery = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
19
+ const {
20
+ children,
21
+ model
22
+ } = node;
23
+ const {
24
+ name,
25
+ isExpanded,
26
+ childrenMatchesSearchQuery,
27
+ matchesSearchQuery
28
+ } = model;
29
+ const shouldSkipBecauseIsRoot = skipRoot && name === '__root';
49
30
  const queryRestrictionsPassed = !!(highlightOnlyQuery || childrenMatchesSearchQuery || matchesSearchQuery);
50
- if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed)
51
- callback(node);
31
+ if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed) callback(node);
52
32
  const shouldWalkChildren = !!(children.length > 0 && isExpanded && queryRestrictionsPassed);
33
+
53
34
  if (shouldWalkChildren) {
54
- children.forEach((childNode) => {
35
+ children.forEach(childNode => {
55
36
  walkVisibles(childNode, callback, skipRoot, highlightOnlyQuery);
56
37
  });
57
38
  }
58
39
  };
59
- const walkParents = (nodePath, callback, skipRoot = true) => {
40
+ const walkParents = function (nodePath, callback) {
41
+ let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
60
42
  const parents = [...nodePath].reverse();
61
- parents.shift();
62
- if (skipRoot)
63
- parents.pop();
43
+ parents.shift(); // remove current node from the parents array
44
+
45
+ if (skipRoot) parents.pop(); // remove the root from the parents if skipping root
46
+
64
47
  parents.forEach(callback);
65
48
  };
66
- const walkAllNodeChildren = (node, callback, isFirst = true) => {
67
- const { children = [] } = node;
49
+ const walkAllNodeChildren = function (node, callback) {
50
+ let isFirst = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
51
+ const {
52
+ children = []
53
+ } = node;
68
54
  const shouldWalkChildren = children.length;
69
- if (!isFirst)
70
- callback(node);
55
+ if (!isFirst) callback(node);
56
+
71
57
  if (shouldWalkChildren) {
72
- children.forEach((childNode) => {
58
+ children.forEach(childNode => {
73
59
  walkAllNodeChildren(childNode, callback, false);
74
60
  });
75
61
  }
76
62
  };
77
63
  const getNodeById = (treeRoot, id) => {
78
- const nodes = treeRoot.all((node) => node.model.id === id);
64
+ const nodes = treeRoot.all(node => node.model.id === id);
79
65
  return nodes[0];
80
66
  };
81
67
  const cloneNode = (tree, node) => tree.parse(node.model);
82
- const itemsShareSameParent = (items = []) => {
83
- if (items.length === 0)
84
- throw new Error("Received empty items for comparison");
85
- if (items.length === 1)
86
- return true;
87
- const firstExistingItem = items.find((item) => !!item);
88
- if (!firstExistingItem)
89
- throw new Error("Received no items, can't retrieve parent");
90
- const firstExistingItemPath = firstExistingItem.node.getPath();
68
+ const itemsShareSameParent = function () {
69
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
70
+ if (items.length === 0) throw new Error('Received empty items for comparison');
71
+ if (items.length === 1) return true; // when moving in first position we receive [undefined,...{items}]
72
+ // when moving in last position we receive [...{items}, undefined]
73
+
74
+ const firstExistingItem = items.find(item => !!item);
75
+ if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
76
+ const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
77
+ // length -1 is the current-node
78
+ // length -2 is the parent-node
79
+ // root node is not printed and is always present so minimum path length is 2 (root + currentNode)
80
+
91
81
  const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
92
- return items.every((item) => {
93
- if (!item)
94
- return true;
82
+ return items.every(item => {
83
+ // undefined nodes count as having the same parent
84
+ if (!item) return true;
95
85
  const itemPath = item.node.getPath();
96
86
  const itemDirectParent = itemPath[itemPath.length - 2];
97
87
  return directParentNode === itemDirectParent;
98
88
  });
99
89
  };
100
- const getItemsParentNode = (items = [], skipSameParentCheck = false) => {
101
- if (items.length === 0)
102
- throw new Error("Received empty items, can't retrieve parent");
103
- if (!skipSameParentCheck) {
104
- if (!itemsShareSameParent(items))
105
- throw new Error("Received items don't share the same parent, can't retrieve parent");
106
- }
107
- const firstExistingItem = items.find((item) => !!item);
108
- if (!firstExistingItem)
109
- throw new Error("Received no items, can't retrieve parent");
110
- const firstExistingItemPath = firstExistingItem.node.getPath();
90
+ const getItemsParentNode = function () {
91
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
92
+ let skipSameParentCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
93
+ if (items.length === 0) throw new Error("Received empty items, can't retrieve parent"); // in case we already know the items compared shares the same parent
94
+
95
+ if (!skipSameParentCheck) if (!itemsShareSameParent(items)) // if we don't know (default, we don't) check if they share the parent
96
+ throw new Error("Received items don't share the same parent, can't retrieve parent"); // when moving in first position we receive [undefined,...{items}]
97
+ // when moving in last position we receive [...{items}, undefined]
98
+
99
+ const firstExistingItem = items.find(item => !!item);
100
+ if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
101
+ const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
102
+ // length -1 is the current-node
103
+ // length -2 is the parent-node
104
+ // root node is not printed and is always present so minimum path length is 2 (root + currentNode)
105
+
111
106
  const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
112
107
  return directParentNode;
113
108
  };
114
- const getNodeMatchesSearchQuery = (node, searchQuery = "") => {
115
- const standardizedName = (0, import_string_helpers.standardizeSearchQueryString)(node.model.name);
116
- const standardizedSearchQuery = (0, import_string_helpers.standardizeSearchQueryString)(searchQuery);
109
+ const getNodeMatchesSearchQuery = function (node) {
110
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
111
+ const standardizedName = stringHelpers.standardizeSearchQueryString(node.model.name);
112
+ const standardizedSearchQuery = stringHelpers.standardizeSearchQueryString(searchQuery);
117
113
  return standardizedName.includes(standardizedSearchQuery);
118
114
  };
119
- const getChildrenMatchesSearchQuery = (parentNode, searchQuery = "") => {
115
+ const getChildrenMatchesSearchQuery = function (parentNode) {
116
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
120
117
  let anyChildMatch = false;
121
- walkAllNodeChildren(parentNode, (node) => {
122
- if (getNodeMatchesSearchQuery(node, searchQuery))
123
- anyChildMatch = true;
118
+ walkAllNodeChildren(parentNode, node => {
119
+ if (getNodeMatchesSearchQuery(node, searchQuery)) anyChildMatch = true;
124
120
  });
125
121
  return anyChildMatch;
126
122
  };
127
- const enrichNodeModelInPlace = (node, searchQuery = "", selection = null, expanded = null) => {
123
+ /**
124
+ * Mutate in place a node from tree-model normalizing object properties like "isGroup" even if user didn't specify it explicitly,
125
+ * after execution the node will have "nodePath" "treeDepth" "nodeItemRef" "isGroup" "isExpanded"
126
+ * (optionally, based on the provided arguments) "matchesSearchQuery" "childrenMatchesSearchQuery" "isChecked"
127
+ *
128
+ * @param {Object} node - node (based on 'tree-model' lib) that you wish to mutate with extra props
129
+ * @param {string} [searchQuery=''] - optional string used to parse "matchesSearchQuery"/"childrenMatchesSearchQuery" properties
130
+ * @param {Object} [selection=null] - optional selection hashmap used to parse "isChecked" properties
131
+ * @param {Object} [expanded=null] - optional expanded hashmap used to parse "isExpanded" properties
132
+ */
133
+
134
+ const enrichNodeModelInPlace = function (node) {
135
+ var _node$model$children$, _node$model, _node$model$children;
136
+
137
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
138
+ let selection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
139
+ let expanded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
128
140
  const path = node.getPath();
129
141
  const depth = path.length - 1;
130
142
  node.model.nodePath = path;
131
143
  node.model.treeDepth = depth;
144
+
132
145
  if (!node.model.nodeItemRef) {
133
- node.model.nodeItemRef = (0, import_react.createRef)();
134
- }
135
- if (typeof node.model.isGroup !== "boolean" && node.model?.children?.length > 0) {
146
+ node.model.nodeItemRef = /*#__PURE__*/React.createRef();
147
+ } // if a node has children but was not marked as isGroup, force-mark as group
148
+ // this is useful to avoid having to always check both the flag and the children.length...
149
+
150
+
151
+ if (typeof node.model.isGroup !== 'boolean' && ((_node$model$children$ = (_node$model = node.model) === null || _node$model === void 0 ? void 0 : (_node$model$children = _node$model.children) === null || _node$model$children === void 0 ? void 0 : _node$model$children.length) !== null && _node$model$children$ !== void 0 ? _node$model$children$ : 0) > 0) {
136
152
  node.model.isGroup = true;
137
153
  }
138
- if (node.model.isGroup && node.model.id !== "__ds_tree_root") {
139
- if (expanded)
140
- node.model.isExpanded = !!expanded[node.model.id];
141
- else if (typeof node.model.isExpanded !== "boolean") {
154
+
155
+ if (node.model.isGroup && node.model.id !== '__ds_tree_root') {
156
+ if (expanded) node.model.isExpanded = !!expanded[node.model.id];else if (typeof node.model.isExpanded !== 'boolean') {
142
157
  node.model.isExpanded = false;
143
158
  }
144
159
  }
160
+
145
161
  node.model.matchesSearchQuery = true;
146
162
  node.model.childrenMatchesSearchQuery = false;
147
163
  const partiallyEnrichedNode = node;
164
+
148
165
  if (searchQuery) {
149
166
  partiallyEnrichedNode.model.matchesSearchQuery = getNodeMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
167
+
150
168
  if (partiallyEnrichedNode.model.isGroup === true) {
151
169
  partiallyEnrichedNode.model.childrenMatchesSearchQuery = getChildrenMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
152
- if (partiallyEnrichedNode.model.childrenMatchesSearchQuery)
153
- partiallyEnrichedNode.model.isExpanded = true;
170
+ if (partiallyEnrichedNode.model.childrenMatchesSearchQuery) partiallyEnrichedNode.model.isExpanded = true;
154
171
  }
155
172
  }
173
+
156
174
  if (selection && selection[partiallyEnrichedNode.model.id]) {
157
175
  partiallyEnrichedNode.model.isChecked = selection[partiallyEnrichedNode.model.id];
158
176
  }
159
177
  };
160
- const focusItem = (item) => {
161
- item?.nodeItemRef?.current?.focus();
178
+ const focusItem = item => {
179
+ var _item$nodeItemRef, _item$nodeItemRef$cur;
180
+
181
+ item === null || item === void 0 ? void 0 : (_item$nodeItemRef = item.nodeItemRef) === null || _item$nodeItemRef === void 0 ? void 0 : (_item$nodeItemRef$cur = _item$nodeItemRef.current) === null || _item$nodeItemRef$cur === void 0 ? void 0 : _item$nodeItemRef$cur.focus();
182
+ };
183
+ const flattenTreeForDnD = function (data) {
184
+ let shouldDescend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => true;
185
+ const flattenedTree = [];
186
+ let index = 0;
187
+
188
+ const doit = function (node) {
189
+ var _node$children$length, _node$children, _node$children2;
190
+
191
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
192
+ let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
193
+ flattenedTree.push({
194
+ uid: node.id.toString(),
195
+ depth,
196
+ realIndex: index,
197
+ childrenCount: (_node$children$length = (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) !== null && _node$children$length !== void 0 ? _node$children$length : 0,
198
+ parentId: parentId !== null ? parentId.toString() : null,
199
+ original: node
200
+ });
201
+ index += 1;
202
+ if (shouldDescend(node)) (_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.forEach(child => doit(child, depth + 1, node.id.toString()));
203
+ };
204
+
205
+ data.forEach(datum => doit(datum));
206
+ return flattenedTree;
162
207
  };
163
- module.exports = __toCommonJS(tree_helpers_exports);
164
- //# sourceMappingURL=tree-helpers.js.map
208
+
209
+ exports.cloneNode = cloneNode;
210
+ exports.enrichNodeModelInPlace = enrichNodeModelInPlace;
211
+ exports.flattenTreeForDnD = flattenTreeForDnD;
212
+ exports.focusItem = focusItem;
213
+ exports.getChildrenMatchesSearchQuery = getChildrenMatchesSearchQuery;
214
+ exports.getItemsParentNode = getItemsParentNode;
215
+ exports.getNodeById = getNodeById;
216
+ exports.getNodeMatchesSearchQuery = getNodeMatchesSearchQuery;
217
+ exports.itemsShareSameParent = itemsShareSameParent;
218
+ exports.walkAllNodeChildren = walkAllNodeChildren;
219
+ exports.walkParents = walkParents;
220
+ exports.walkVisibles = walkVisibles;