@rio-cloud/rio-uikit 0.16.4-beta.21 → 0.16.4-beta.22

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 (241) hide show
  1. package/AssetTree.d.ts +2 -5
  2. package/AssetTree.js +2 -2
  3. package/ButtonDropdown.d.ts +2 -5
  4. package/ButtonDropdown.js +2 -2
  5. package/DropdownSubmenu.d.ts +2 -5
  6. package/DropdownSubmenu.js +2 -2
  7. package/MenuItem.d.ts +2 -5
  8. package/MenuItem.js +2 -2
  9. package/MenuItemList.d.ts +2 -0
  10. package/MenuItemList.js +2 -0
  11. package/MenuItems.d.ts +2 -0
  12. package/MenuItems.js +2 -0
  13. package/Page.d.ts +2 -0
  14. package/Page.js +2 -0
  15. package/Sidebar.d.ts +1 -0
  16. package/Sidebar.js +1 -0
  17. package/SimpleButtonDropdown.d.ts +2 -5
  18. package/SimpleButtonDropdown.js +2 -2
  19. package/SingleButtonDropdown.d.ts +2 -5
  20. package/SingleButtonDropdown.js +2 -2
  21. package/SplitButtonDropdown.d.ts +2 -5
  22. package/SplitButtonDropdown.js +2 -2
  23. package/Tree.d.ts +2 -5
  24. package/Tree.js +2 -2
  25. package/TreeCategory.d.ts +2 -5
  26. package/TreeCategory.js +2 -2
  27. package/TreeOption.d.ts +2 -5
  28. package/TreeOption.js +2 -2
  29. package/TreeSearch.d.ts +2 -5
  30. package/TreeSearch.js +2 -2
  31. package/TreeSummary.d.ts +2 -5
  32. package/TreeSummary.js +2 -2
  33. package/TreeSummaryRow.d.ts +2 -0
  34. package/TreeSummaryRow.js +2 -0
  35. package/TypeCounter.d.ts +2 -5
  36. package/TypeCounter.js +2 -2
  37. package/components/assetTree/AssetTree.d.ts +84 -2
  38. package/components/assetTree/AssetTree.js +41 -61
  39. package/components/assetTree/Tree.d.ts +195 -2
  40. package/components/assetTree/Tree.js +70 -256
  41. package/components/assetTree/TreeCategory.d.ts +24 -11
  42. package/components/assetTree/TreeCategory.js +1 -8
  43. package/components/assetTree/TreeLeaf.d.ts +1 -1
  44. package/components/assetTree/TreeLeaf.js +3 -2
  45. package/components/assetTree/TreeLeafList.d.ts +3 -3
  46. package/components/assetTree/TreeLeafList.js +4 -3
  47. package/components/assetTree/TreeNode.d.ts +12 -2
  48. package/components/assetTree/TreeNode.js +2 -17
  49. package/components/assetTree/TreeNodeContainer.d.ts +10 -12
  50. package/components/assetTree/TreeNodeContainer.js +9 -8
  51. package/components/assetTree/TreeNothingFound.d.ts +3 -2
  52. package/components/assetTree/TreeNothingFound.js +1 -7
  53. package/components/assetTree/TreeOption.d.ts +27 -17
  54. package/components/assetTree/TreeOption.js +5 -14
  55. package/components/assetTree/TreeOptions.d.ts +9 -13
  56. package/components/assetTree/TreeOptions.js +4 -11
  57. package/components/assetTree/TreeRoot.d.ts +9 -11
  58. package/components/assetTree/TreeRoot.js +8 -8
  59. package/components/assetTree/TreeSearch.d.ts +23 -2
  60. package/components/assetTree/TreeSearch.js +4 -12
  61. package/components/assetTree/TreeSelectAll.d.ts +14 -26
  62. package/components/assetTree/TreeSelectAll.js +7 -22
  63. package/components/assetTree/TreeSidebar.d.ts +10 -2
  64. package/components/assetTree/TreeSidebar.js +4 -35
  65. package/components/assetTree/TreeSidebarCategories.d.ts +11 -0
  66. package/components/assetTree/TreeSidebarCategories.js +34 -0
  67. package/components/assetTree/TreeSummary.d.ts +44 -2
  68. package/components/assetTree/TreeSummary.js +6 -19
  69. package/components/assetTree/TreeSummaryRow.d.ts +15 -0
  70. package/components/assetTree/TreeSummaryRow.js +6 -0
  71. package/components/assetTree/TypeCounter.d.ts +45 -2
  72. package/components/assetTree/TypeCounter.js +14 -23
  73. package/components/assetTree/treeReducer.d.ts +47 -0
  74. package/components/assetTree/treeReducer.js +34 -0
  75. package/components/assetTree/treeUtils.d.ts +20 -0
  76. package/components/assetTree/treeUtils.js +88 -0
  77. package/components/button/Button.d.ts +14 -9
  78. package/components/button/Button.js +7 -7
  79. package/components/button/ToggleButton.d.ts +2 -4
  80. package/components/datepicker/DatePicker.d.ts +9 -9
  81. package/components/datepicker/DatePicker.js +4 -2
  82. package/components/dialog/Dialog.js +6 -2
  83. package/components/dropdown/ButtonDropdown.d.ts +115 -65
  84. package/components/dropdown/ButtonDropdown.js +14 -60
  85. package/components/dropdown/Caret.d.ts +1 -1
  86. package/components/dropdown/Caret.js +2 -1
  87. package/components/dropdown/DropdownSubmenu.d.ts +21 -18
  88. package/components/dropdown/DropdownSubmenu.js +26 -19
  89. package/components/dropdown/DropdownToggleButton.d.ts +14 -2
  90. package/components/dropdown/DropdownToggleButton.js +6 -14
  91. package/components/dropdown/SimpleButtonDropdown.d.ts +3 -1
  92. package/components/dropdown/SimpleButtonDropdown.js +3 -2
  93. package/components/dropdown/SingleButtonDropdown.d.ts +3 -1
  94. package/components/dropdown/SingleButtonDropdown.js +3 -2
  95. package/components/dropdown/SplitButtonDropdown.d.ts +3 -1
  96. package/components/dropdown/SplitButtonDropdown.js +3 -2
  97. package/components/dropdown/SplitCaretButton.d.ts +12 -2
  98. package/components/dropdown/SplitCaretButton.js +6 -11
  99. package/components/menuItems/MenuItem.d.ts +16 -0
  100. package/components/menuItems/MenuItem.js +1 -0
  101. package/components/menuItems/MenuItemList.d.ts +7 -0
  102. package/components/menuItems/MenuItemList.js +10 -0
  103. package/components/menuItems/MenuItems.d.ts +7 -2
  104. package/components/menuItems/MenuItems.js +10 -9
  105. package/components/numberInput/NumberInput.js +1 -1
  106. package/components/page/Page.d.ts +10 -0
  107. package/components/page/Page.js +18 -0
  108. package/components/timepicker/TimePicker.js +2 -1
  109. package/hooks/usePrevious.d.ts +1 -1
  110. package/hooks/usePrevious.js +6 -7
  111. package/index.d.ts +34 -26
  112. package/index.js +34 -26
  113. package/lib/es/AssetTree.d.ts +2 -5
  114. package/lib/es/AssetTree.js +3 -2
  115. package/lib/es/ButtonDropdown.d.ts +2 -5
  116. package/lib/es/ButtonDropdown.js +3 -2
  117. package/lib/es/DropdownSubmenu.d.ts +2 -5
  118. package/lib/es/DropdownSubmenu.js +3 -2
  119. package/lib/es/MenuItem.d.ts +2 -5
  120. package/lib/es/MenuItem.js +3 -2
  121. package/lib/es/MenuItemList.d.ts +2 -0
  122. package/lib/es/MenuItemList.js +7 -0
  123. package/lib/es/MenuItems.d.ts +2 -0
  124. package/lib/es/MenuItems.js +7 -0
  125. package/lib/es/Page.d.ts +2 -0
  126. package/lib/es/Page.js +7 -0
  127. package/lib/es/Sidebar.d.ts +1 -0
  128. package/lib/es/Sidebar.js +3 -4
  129. package/lib/es/SimpleButtonDropdown.d.ts +2 -5
  130. package/lib/es/SimpleButtonDropdown.js +3 -2
  131. package/lib/es/SingleButtonDropdown.d.ts +2 -5
  132. package/lib/es/SingleButtonDropdown.js +3 -2
  133. package/lib/es/SplitButtonDropdown.d.ts +2 -5
  134. package/lib/es/SplitButtonDropdown.js +3 -2
  135. package/lib/es/Tree.d.ts +2 -5
  136. package/lib/es/Tree.js +3 -2
  137. package/lib/es/TreeCategory.d.ts +2 -5
  138. package/lib/es/TreeCategory.js +3 -2
  139. package/lib/es/TreeOption.d.ts +2 -5
  140. package/lib/es/TreeOption.js +3 -2
  141. package/lib/es/TreeSearch.d.ts +2 -5
  142. package/lib/es/TreeSearch.js +3 -2
  143. package/lib/es/TreeSummary.d.ts +2 -5
  144. package/lib/es/TreeSummary.js +3 -2
  145. package/lib/es/TreeSummaryRow.d.ts +2 -0
  146. package/lib/es/TreeSummaryRow.js +7 -0
  147. package/lib/es/TypeCounter.d.ts +2 -5
  148. package/lib/es/TypeCounter.js +3 -2
  149. package/lib/es/components/assetTree/AssetTree.d.ts +84 -2
  150. package/lib/es/components/assetTree/AssetTree.js +40 -60
  151. package/lib/es/components/assetTree/Tree.d.ts +195 -2
  152. package/lib/es/components/assetTree/Tree.js +103 -286
  153. package/lib/es/components/assetTree/TreeCategory.d.ts +24 -11
  154. package/lib/es/components/assetTree/TreeCategory.js +1 -9
  155. package/lib/es/components/assetTree/TreeLeaf.d.ts +1 -1
  156. package/lib/es/components/assetTree/TreeLeaf.js +2 -1
  157. package/lib/es/components/assetTree/TreeLeafList.d.ts +3 -3
  158. package/lib/es/components/assetTree/TreeLeafList.js +4 -3
  159. package/lib/es/components/assetTree/TreeNode.d.ts +12 -2
  160. package/lib/es/components/assetTree/TreeNode.js +2 -17
  161. package/lib/es/components/assetTree/TreeNodeContainer.d.ts +10 -12
  162. package/lib/es/components/assetTree/TreeNodeContainer.js +9 -8
  163. package/lib/es/components/assetTree/TreeNothingFound.d.ts +3 -2
  164. package/lib/es/components/assetTree/TreeNothingFound.js +1 -7
  165. package/lib/es/components/assetTree/TreeOption.d.ts +27 -17
  166. package/lib/es/components/assetTree/TreeOption.js +5 -14
  167. package/lib/es/components/assetTree/TreeOptions.d.ts +9 -13
  168. package/lib/es/components/assetTree/TreeOptions.js +4 -11
  169. package/lib/es/components/assetTree/TreeRoot.d.ts +9 -11
  170. package/lib/es/components/assetTree/TreeRoot.js +8 -8
  171. package/lib/es/components/assetTree/TreeSearch.d.ts +23 -2
  172. package/lib/es/components/assetTree/TreeSearch.js +4 -12
  173. package/lib/es/components/assetTree/TreeSelectAll.d.ts +14 -26
  174. package/lib/es/components/assetTree/TreeSelectAll.js +7 -22
  175. package/lib/es/components/assetTree/TreeSidebar.d.ts +10 -2
  176. package/lib/es/components/assetTree/TreeSidebar.js +5 -36
  177. package/lib/es/components/assetTree/TreeSidebarCategories.d.ts +11 -0
  178. package/lib/es/components/assetTree/TreeSidebarCategories.js +37 -0
  179. package/lib/es/components/assetTree/TreeSummary.d.ts +44 -2
  180. package/lib/es/components/assetTree/TreeSummary.js +6 -19
  181. package/lib/es/components/assetTree/TreeSummaryRow.d.ts +15 -0
  182. package/lib/es/components/assetTree/TreeSummaryRow.js +10 -0
  183. package/lib/es/components/assetTree/TypeCounter.d.ts +45 -2
  184. package/lib/es/components/assetTree/TypeCounter.js +14 -23
  185. package/lib/es/components/assetTree/autoAnimateFrames.d.ts +1 -0
  186. package/lib/es/components/assetTree/autoAnimateFrames.js +55 -0
  187. package/lib/es/components/assetTree/treeReducer.d.ts +47 -0
  188. package/lib/es/components/assetTree/treeReducer.js +47 -0
  189. package/lib/es/components/assetTree/treeUtils.d.ts +20 -0
  190. package/lib/es/components/assetTree/treeUtils.js +106 -0
  191. package/lib/es/components/button/Button.d.ts +14 -9
  192. package/lib/es/components/button/Button.js +12 -11
  193. package/lib/es/components/button/ToggleButton.d.ts +2 -4
  194. package/lib/es/components/datepicker/DatePicker.d.ts +9 -9
  195. package/lib/es/components/datepicker/DatePicker.js +4 -2
  196. package/lib/es/components/dialog/Dialog.js +5 -1
  197. package/lib/es/components/dropdown/ButtonDropdown.d.ts +115 -65
  198. package/lib/es/components/dropdown/ButtonDropdown.js +13 -59
  199. package/lib/es/components/dropdown/Caret.d.ts +1 -1
  200. package/lib/es/components/dropdown/Caret.js +2 -2
  201. package/lib/es/components/dropdown/DropdownSubmenu.d.ts +21 -18
  202. package/lib/es/components/dropdown/DropdownSubmenu.js +26 -19
  203. package/lib/es/components/dropdown/DropdownToggleButton.d.ts +14 -2
  204. package/lib/es/components/dropdown/DropdownToggleButton.js +6 -14
  205. package/lib/es/components/dropdown/SimpleButtonDropdown.d.ts +3 -1
  206. package/lib/es/components/dropdown/SimpleButtonDropdown.js +3 -2
  207. package/lib/es/components/dropdown/SingleButtonDropdown.d.ts +3 -1
  208. package/lib/es/components/dropdown/SingleButtonDropdown.js +3 -2
  209. package/lib/es/components/dropdown/SplitButtonDropdown.d.ts +3 -1
  210. package/lib/es/components/dropdown/SplitButtonDropdown.js +3 -2
  211. package/lib/es/components/dropdown/SplitCaretButton.d.ts +12 -2
  212. package/lib/es/components/dropdown/SplitCaretButton.js +6 -11
  213. package/lib/es/components/menuItems/MenuItem.d.ts +16 -0
  214. package/lib/es/components/menuItems/MenuItem.js +1 -0
  215. package/lib/es/components/menuItems/MenuItemList.d.ts +7 -0
  216. package/lib/es/components/menuItems/MenuItemList.js +12 -0
  217. package/lib/es/components/menuItems/MenuItems.d.ts +7 -2
  218. package/lib/es/components/menuItems/MenuItems.js +9 -7
  219. package/lib/es/components/numberInput/NumberInput.js +1 -1
  220. package/lib/es/components/page/Page.d.ts +10 -0
  221. package/lib/es/components/page/Page.js +21 -0
  222. package/lib/es/components/timepicker/TimePicker.js +2 -1
  223. package/lib/es/hooks/usePrevious.d.ts +1 -1
  224. package/lib/es/hooks/usePrevious.js +5 -6
  225. package/lib/es/index.d.ts +34 -26
  226. package/lib/es/index.js +55 -30
  227. package/lib/es/types.d.ts +1 -140
  228. package/lib/es/utils/init.js +1 -0
  229. package/lib/es/utils/mergeRefs.d.ts +3 -0
  230. package/lib/es/utils/mergeRefs.js +18 -0
  231. package/lib/es/utils/searchNormalized.d.ts +2 -2
  232. package/lib/es/utils/searchNormalized.js +1 -1
  233. package/lib/es/version.json +1 -1
  234. package/package.json +39 -36
  235. package/types.d.ts +1 -140
  236. package/utils/init.js +1 -0
  237. package/utils/mergeRefs.d.ts +3 -0
  238. package/utils/mergeRefs.js +16 -0
  239. package/utils/searchNormalized.d.ts +2 -2
  240. package/utils/searchNormalized.js +1 -1
  241. package/version.json +1 -1
@@ -1,3 +1,85 @@
1
+ import React from 'react';
2
+ export type AssetTreeProps = {
3
+ /**
4
+ * Defines if the component will overlap the body content.
5
+ *
6
+ * @default false
7
+ */
8
+ fly?: boolean;
9
+ /**
10
+ * Defines whether or not the sidebar is resizable.
11
+ *
12
+ * @default true
13
+ */
14
+ resizable?: boolean;
15
+ /**
16
+ * Defines whether the component has a border or not.
17
+ *
18
+ * @default false
19
+ */
20
+ bordered?: boolean;
21
+ /**
22
+ * Defines the width of the component. The value is set as inline style.
23
+ * Note: when component is resizable it will take the provided
24
+ * width in px only and convert it to number in case.
25
+ *
26
+ * @default 350
27
+ */
28
+ width?: number;
29
+ /**
30
+ * Defines the minimum width of the component in px that will take effect when resizing.
31
+ *
32
+ * @default 100
33
+ */
34
+ minWidth?: number;
35
+ /**
36
+ * Defines the maximum width of the component in px that will take effect when resizing.
37
+ *
38
+ * @default 0
39
+ */
40
+ maxWidth?: number;
41
+ /**
42
+ * Defines the height of the component in px.
43
+ */
44
+ height?: number;
45
+ /**
46
+ * Defines whether the component is open or not.
47
+ *
48
+ * @default true
49
+ */
50
+ isOpen?: boolean;
51
+ /**
52
+ * Callback for when the tree visibility is toggled.
53
+ * @param isOpen
54
+ * @returns
55
+ */
56
+ onToggleTree?: (isOpen: boolean) => void;
57
+ /**
58
+ * The id of the category which is currently active and shall be shown.
59
+ */
60
+ currentCategoryId: string;
61
+ /**
62
+ * Callback for handling change of category.
63
+ * @param selectedCategoryId
64
+ * @returns
65
+ */
66
+ onCategoryChange: (selectedCategoryId: string) => void;
67
+ /**
68
+ * Callback for when the resize is done.
69
+ */
70
+ onResizeEnd: VoidFunction;
71
+ /**
72
+ * Defines whether the tree components are rendered offscreen and kept mounted in the DOM.
73
+ *
74
+ * @default false
75
+ */
76
+ useOffscreen: boolean;
77
+ /**
78
+ * Additional classes added on the wrapper element.
79
+ */
80
+ className?: string;
81
+ };
82
+ declare const AssetTree: React.MemoExoticComponent<React.ForwardRefExoticComponent<AssetTreeProps & {
83
+ children?: React.ReactNode;
84
+ } & React.RefAttributes<HTMLDivElement>>>;
1
85
  export default AssetTree;
2
- declare const AssetTree: React.MemoExoticComponent<React.ForwardRefExoticComponent<React.RefAttributes<any>>>;
3
- import React from "react";
@@ -3,15 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = tslib_1.__importStar(require("react"));
6
- const prop_types_1 = tslib_1.__importDefault(require("prop-types"));
7
6
  const classnames_1 = tslib_1.__importDefault(require("classnames"));
8
7
  const head_1 = tslib_1.__importDefault(require("lodash/fp/head"));
9
8
  const isArray_1 = tslib_1.__importDefault(require("lodash/fp/isArray"));
9
+ const noop_1 = tslib_1.__importDefault(require("lodash/fp/noop"));
10
+ const tiny_invariant_1 = tslib_1.__importDefault(require("tiny-invariant"));
11
+ const TreeCategory_1 = tslib_1.__importDefault(require("./TreeCategory"));
10
12
  const Resizer_1 = tslib_1.__importDefault(require("../resizer/Resizer"));
11
13
  const TreeSidebar_1 = tslib_1.__importDefault(require("./TreeSidebar"));
12
- const TreeCategory_1 = tslib_1.__importDefault(require("./TreeCategory"));
13
14
  const getWidthInBoundaries_1 = tslib_1.__importDefault(require("../../utils/getWidthInBoundaries"));
14
- const getSidebarBodyRef = sidebarRef => (0, head_1.default)(sidebarRef.current.getElementsByClassName('AssetTreeBody'));
15
+ const mergeRefs_1 = tslib_1.__importDefault(require("../../utils/mergeRefs"));
16
+ const usePrevious_1 = tslib_1.__importDefault(require("../../usePrevious"));
17
+ const DEFAULT_WIDTH = 350;
18
+ const DEFAULT_MIN_WIDTH = 100;
19
+ const DEFAULT_MAX_WIDTH = 0;
20
+ const TreeMode = {
21
+ MODE_FLY: 'fly',
22
+ MODE_FLUID: 'fluid',
23
+ };
24
+ const getSidebarBodyRef = (sidebarRef) => { var _a; return (0, head_1.default)((_a = sidebarRef === null || sidebarRef === void 0 ? void 0 : sidebarRef.current) === null || _a === void 0 ? void 0 : _a.getElementsByClassName('AssetTreeBody')); };
15
25
  const getCurrentCategoryElement = (children, currentCategoryId) => {
16
26
  return (0, isArray_1.default)(children) ? children.find(child => child && child.props.id === currentCategoryId) : children;
17
27
  };
@@ -21,30 +31,42 @@ const renderTreesOffscreen = (children, categoryId) => {
21
31
  return (0, jsx_runtime_1.jsx)("div", Object.assign({ className: offscreenClasses }, { children: child }));
22
32
  });
23
33
  };
34
+ // Check if the child is a React element and if it has the type TreeCategory
35
+ const isTreeCategory = (child) => {
36
+ return react_1.default.isValidElement(child) && child.type === TreeCategory_1.default;
37
+ };
24
38
  const AssetTree = (0, react_1.memo)((0, react_1.forwardRef)((props, ref) => {
25
- const { className, resizable, width, maxWidth, minWidth, height, bordered, currentCategoryId, isOpen, useOffscreen, fly, onCategoryChange, onToggleTree, onResizeEnd, children } = props, remainingProps = tslib_1.__rest(props, ["className", "resizable", "width", "maxWidth", "minWidth", "height", "bordered", "currentCategoryId", "isOpen", "useOffscreen", "fly", "onCategoryChange", "onToggleTree", "onResizeEnd", "children"]);
26
- const getSidebarMode = isFly => (isFly ? AssetTree.MODE_FLY : AssetTree.MODE_FLUID);
27
- const [treeWidth, setTreeWidth] = (0, react_1.useState)(parseInt(width, 10));
39
+ const { className, resizable = true, width = DEFAULT_WIDTH, minWidth = DEFAULT_MIN_WIDTH, maxWidth = DEFAULT_MAX_WIDTH, height, bordered = false, currentCategoryId, isOpen = true, useOffscreen = false, fly = false, onCategoryChange = noop_1.default, onToggleTree = noop_1.default, onResizeEnd = noop_1.default, children = [] } = props, remainingProps = tslib_1.__rest(props, ["className", "resizable", "width", "minWidth", "maxWidth", "height", "bordered", "currentCategoryId", "isOpen", "useOffscreen", "fly", "onCategoryChange", "onToggleTree", "onResizeEnd", "children"]);
40
+ const getSidebarMode = (isFly) => (isFly ? TreeMode.MODE_FLY : TreeMode.MODE_FLUID);
41
+ const [treeWidth, setTreeWidth] = (0, react_1.useState)(width);
28
42
  const [isResize, setIsResize] = (0, react_1.useState)(false);
29
43
  const [sidebarMode, setSidebarMode] = (0, react_1.useState)(getSidebarMode(fly));
30
- const sidebarRef = (0, react_1.useRef)();
31
- (0, react_1.useImperativeHandle)(ref, () => sidebarRef, []);
44
+ const sidebarRef = (0, react_1.useRef)(null);
45
+ const mergedRefs = (0, mergeRefs_1.default)([ref, sidebarRef]);
32
46
  // Update internal state when props change
33
- (0, react_1.useEffect)(() => setTreeWidth(width), [width]);
34
- (0, react_1.useEffect)(() => setSidebarMode(getSidebarMode(fly)), [fly]);
35
- const classes = (0, classnames_1.default)('AssetTree', className, !isOpen && 'closed', bordered && 'panel panel-default', sidebarMode === AssetTree.MODE_FLY ? 'fly' : 'fluid');
47
+ const previousWidth = (0, usePrevious_1.default)(width);
48
+ if (previousWidth !== width) {
49
+ setTreeWidth(width);
50
+ }
51
+ const previousMode = (0, usePrevious_1.default)(fly);
52
+ if (previousMode !== fly) {
53
+ setSidebarMode(getSidebarMode(fly));
54
+ }
55
+ const childrenArray = react_1.default.Children.toArray(children);
56
+ // check for children type of TreeCategory and throw error in case
57
+ (0, tiny_invariant_1.default)(childrenArray.every(isTreeCategory), 'AssetTree only excepts children of type "TreeCategory"');
58
+ const classes = (0, classnames_1.default)('AssetTree', className, !isOpen && 'closed', bordered && 'panel panel-default', sidebarMode === TreeMode.MODE_FLY ? 'fly' : 'fluid');
36
59
  const resizeLimitClasses = (0, classnames_1.default)('AssetTreeResizeLimit', isResize && 'display-block');
37
60
  const resizeIndicatorPosition = maxWidth || window.innerWidth * 0.5;
38
61
  const resizeLimitStyle = { left: resizeIndicatorPosition };
39
- const categoryId = currentCategoryId || 0;
40
- const firstChild = (0, head_1.default)(children);
41
- const category = currentCategoryId ? getCurrentCategoryElement(children, currentCategoryId) : firstChild;
62
+ const firstChild = (0, head_1.default)(childrenArray);
63
+ const category = currentCategoryId ? getCurrentCategoryElement(childrenArray, currentCategoryId) : firstChild;
42
64
  const style = {
43
65
  width: treeWidth,
44
66
  height,
45
67
  };
46
68
  const handleToggleTreeContent = () => onToggleTree(!isOpen);
47
- const handleSelectCategory = selectedCategoryId => {
69
+ const handleSelectCategory = (selectedCategoryId) => {
48
70
  onCategoryChange(selectedCategoryId);
49
71
  if (!isOpen) {
50
72
  handleToggleTreeContent();
@@ -53,7 +75,7 @@ const AssetTree = (0, react_1.memo)((0, react_1.forwardRef)((props, ref) => {
53
75
  handleToggleTreeContent();
54
76
  }
55
77
  };
56
- const handleResize = diff => {
78
+ const handleResize = (diff) => {
57
79
  const halfWindowWidth = window.innerWidth * 0.5;
58
80
  const usedMaxWidth = maxWidth || halfWindowWidth;
59
81
  // Check for sidebar width if it is half window size. If it was before but the sidebar was resized so it is
@@ -79,50 +101,8 @@ const AssetTree = (0, react_1.memo)((0, react_1.forwardRef)((props, ref) => {
79
101
  setIsResize(false);
80
102
  onResizeEnd();
81
103
  };
82
- return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { className: classes, style: style, ref: sidebarRef }, { children: [(0, jsx_runtime_1.jsx)("div", { className: resizeLimitClasses, style: resizeLimitStyle }), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: 'AssetTreeContent' }, { children: [(0, jsx_runtime_1.jsx)(TreeSidebar_1.default, Object.assign({ onSelectCategory: handleSelectCategory, currentCategoryId: currentCategoryId, onClick: handleToggleTreeContent }, { children: (0, isArray_1.default)(children) ? children : [children] })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'AssetTreeBody' }, { children: useOffscreen ? renderTreesOffscreen(children, categoryId) : category }))] })), resizable && isOpen && ((0, jsx_runtime_1.jsx)(Resizer_1.default, { onResizeStart: handleResizeStart, onResize: handleResize, onResizeEnd: handleResizeEnd, direction: Resizer_1.default.HORIZONTAL, position: Resizer_1.default.RIGHT }))] })));
104
+ return ((0, jsx_runtime_1.jsxs)("div", Object.assign({}, remainingProps, { className: classes, style: style, ref: mergedRefs }, { children: [(0, jsx_runtime_1.jsx)("div", { className: resizeLimitClasses, style: resizeLimitStyle }), (0, jsx_runtime_1.jsxs)("div", Object.assign({ className: 'AssetTreeContent' }, { children: [(0, jsx_runtime_1.jsx)(TreeSidebar_1.default, Object.assign({ onSelectCategory: handleSelectCategory, currentCategoryId: currentCategoryId, onClick: handleToggleTreeContent }, { children: (0, isArray_1.default)(children) ? children : [children] })), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: 'AssetTreeBody' }, { children: useOffscreen ? renderTreesOffscreen(childrenArray, currentCategoryId) : category }))] })), resizable && isOpen && ((0, jsx_runtime_1.jsx)(Resizer_1.default, { onResizeStart: handleResizeStart, onResize: handleResize, onResizeEnd: handleResizeEnd, direction: Resizer_1.default.HORIZONTAL, position: Resizer_1.default.RIGHT }))] })));
83
105
  }));
84
106
  AssetTree.displayName = 'AssetTree';
85
- AssetTree.MODE_FLY = 'fly';
86
- AssetTree.MODE_FLUID = 'fluid';
87
- AssetTree.defaultProps = {
88
- width: 350,
89
- minWidth: 100,
90
- maxWidth: 0,
91
- resizable: true,
92
- bordered: false,
93
- fly: false,
94
- isOpen: true,
95
- onToggleTree: () => { },
96
- children: [],
97
- onCategoryChange: () => { },
98
- onResizeEnd: () => { },
99
- useOffscreen: false,
100
- };
101
- AssetTree.propTypes = {
102
- fly: prop_types_1.default.bool,
103
- resizable: prop_types_1.default.bool,
104
- bordered: prop_types_1.default.bool,
105
- // When sidebar is resizable it will take the provided width in px only
106
- width: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.number]),
107
- minWidth: prop_types_1.default.number,
108
- maxWidth: prop_types_1.default.number,
109
- height: prop_types_1.default.number,
110
- isOpen: prop_types_1.default.bool,
111
- onToggleTree: prop_types_1.default.func,
112
- currentCategoryId: prop_types_1.default.string.isRequired,
113
- onCategoryChange: prop_types_1.default.func,
114
- className: prop_types_1.default.string,
115
- onResizeEnd: prop_types_1.default.func,
116
- useOffscreen: prop_types_1.default.bool,
117
- children: (props, propName, componentName) => {
118
- const prop = props[propName];
119
- let error = null;
120
- react_1.default.Children.forEach(prop, child => {
121
- if (child.type !== TreeCategory_1.default) {
122
- error = new Error(`\`${componentName}\` children should be of type \`TreeCategory\`.`);
123
- }
124
- });
125
- return error;
126
- },
127
- };
107
+ Object.assign(AssetTree, TreeMode);
128
108
  exports.default = AssetTree;
@@ -1,3 +1,196 @@
1
+ import React from 'react';
2
+ export { getTypeCounts, getSubTypeCounts } from './treeUtils';
3
+ export type TreeItemName = {
4
+ firstName?: string;
5
+ lastName: string;
6
+ };
7
+ export type TreeGroup = {
8
+ /**
9
+ * A unique identifier of a group.
10
+ */
11
+ id: string;
12
+ /**
13
+ * The name of a group.
14
+ */
15
+ name: string | React.ReactNode;
16
+ /**
17
+ * Can be set to "last" to enforce the last position in the tree.
18
+ */
19
+ position?: 'last';
20
+ /**
21
+ * Disallows the selection of the group itself.
22
+ */
23
+ disabled?: boolean;
24
+ /**
25
+ * The rioglyph icon name for a group.
26
+ */
27
+ icon?: string;
28
+ /**
29
+ * Additional classes added to the group element.
30
+ */
31
+ className?: string;
32
+ };
33
+ export type TreeItem = {
34
+ /**
35
+ * A unique identifier of an item.
36
+ */
37
+ id: string;
38
+ /**
39
+ * The name of an item. Either it is a plain string or an object composed of:
40
+ * `firstName` and `lastName` where __lastName__ is mandatory.
41
+ */
42
+ name: string | TreeItemName;
43
+ /**
44
+ * The subline of an item. This can e used to show additional information for that item.
45
+ */
46
+ info?: string | React.ReactNode;
47
+ /**
48
+ * The type of an item which is also the name of the respective rioplyph icon without the prefix
49
+ * `rioglyph-`.
50
+ */
51
+ type: string;
52
+ /**
53
+ * The sub type of an item which is also the name of the respective rioplyph icon without the prefix.
54
+ * This could be used to show a secondary paired icon like for fuel type.
55
+ */
56
+ subType?: string;
57
+ /**
58
+ * List of group ids the items is associated with.
59
+ *
60
+ * @default []
61
+ */
62
+ groupIds?: string[];
63
+ /**
64
+ * Additional classes added to the item element.
65
+ */
66
+ className?: string;
67
+ };
68
+ export type GroupedItem = TreeGroup & {
69
+ items: TreeItem[];
70
+ };
71
+ export type GroupedItems = {
72
+ [key: string]: GroupedItem;
73
+ };
74
+ export type SelectionChangeResponse = {
75
+ items: string[];
76
+ groups: string[];
77
+ };
78
+ export type TreeProps = {
79
+ /**
80
+ * The list of groups of the items. If no groups are provided all items
81
+ * are rendered as flat list.
82
+ *
83
+ * @default []
84
+ */
85
+ groups?: TreeGroup[];
86
+ /**
87
+ * The list of items.
88
+ *
89
+ * @default []
90
+ */
91
+ items?: TreeItem[];
92
+ /**
93
+ * List of selected group ids.
94
+ *
95
+ * @default []
96
+ */
97
+ selectedGroups?: string[];
98
+ /**
99
+ * List of selected item ids.
100
+ *
101
+ * @default []
102
+ */
103
+ selectedItems?: string[];
104
+ /**
105
+ * Merged Callback for item and group selection changes.
106
+ * It responds with a selection object that contains the selected itemIds and groupIds:
107
+ * `{ items: [], groups: [] }`
108
+ * @returns
109
+ */
110
+ onSelectionChange?: ({ items, groups }: SelectionChangeResponse) => void;
111
+ /**
112
+ * Defines the selection behavior of the tree.
113
+ *
114
+ * @default true
115
+ */
116
+ hasMultiselect?: boolean;
117
+ /**
118
+ * Defines if the single selection should also show radios.
119
+ *
120
+ * @default false
121
+ */
122
+ showRadioButtons?: boolean;
123
+ /**
124
+ * Defines whether or not the built-in Search is shown.
125
+ *
126
+ * @default false
127
+ */
128
+ hideSearch?: boolean;
129
+ /**
130
+ * The text used as placeholder for the search input.
131
+ */
132
+ searchPlaceholder?: string;
133
+ /**
134
+ * Callback for when the search value changes.
135
+ * @param value
136
+ * @returns
137
+ */
138
+ onSearchChange?: (value: string) => void;
139
+ /**
140
+ * Used to define custom search component which replaces the built-in search.
141
+ */
142
+ search?: React.ReactNode;
143
+ /**
144
+ * Used to define custom asset type counter component which replaces the built-in summary.
145
+ */
146
+ summary?: React.ReactNode;
147
+ /**
148
+ * Defines whether a summary is shown.
149
+ *
150
+ * @default false
151
+ */
152
+ hideSummary?: boolean;
153
+ /**
154
+ * Defines whether the entire area below the search field is shown or not. Note: Disabling the
155
+ * tree head will hide the select all checkbox and the tree options as well as the tree summary.
156
+ *
157
+ * @default false
158
+ */
159
+ hideTreeHead?: boolean;
160
+ /**
161
+ * Defines the max-height of the scrollable list.
162
+ */
163
+ scrollHeight?: number;
164
+ /**
165
+ * List of group ids which are expanded.
166
+ */
167
+ expandedGroups?: string[];
168
+ /**
169
+ * Callback function triggered when a group expands or collapses.
170
+ * @param newExpandedGroups
171
+ * @returns
172
+ */
173
+ onExpandGroupsChange?: (newExpandedGroups: string[]) => void;
174
+ /**
175
+ * Defines whether empty groups are shown or not.
176
+ *
177
+ * @default true
178
+ */
179
+ showEmptyGroups?: boolean;
180
+ /**
181
+ * Component to offer customization options for the tree.
182
+ */
183
+ treeOptions?: React.ReactNode[];
184
+ /**
185
+ * Disables animation when filtering or using search
186
+ *
187
+ * @default false
188
+ */
189
+ disableAnimation?: boolean;
190
+ /**
191
+ * Additional classes added to the wrapping element.
192
+ */
193
+ className?: string;
194
+ };
195
+ declare const Tree: React.MemoExoticComponent<(props: TreeProps) => import("react/jsx-runtime").JSX.Element>;
1
196
  export default Tree;
2
- declare const Tree: React.NamedExoticComponent<object>;
3
- import React from "react";