@steroidsjs/core 3.0.0-beta.98 → 3.0.0

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 (175) hide show
  1. package/actions/notifications.js +7 -1
  2. package/actions/router.js +16 -2
  3. package/components/HttpComponent.d.ts +7 -7
  4. package/components/JwtHttpComponent.d.ts +2 -2
  5. package/components/LocaleComponent.d.ts +6 -6
  6. package/components/MetaComponent.d.ts +90 -1
  7. package/components/MetricsComponent.js +2 -1
  8. package/components/ResourceComponent.d.ts +4 -4
  9. package/components/UiComponent.d.ts +7 -7
  10. package/components/WebSocketComponent.d.ts +11 -11
  11. package/docs-autogen-result.json +15226 -6277
  12. package/en.json +151 -84
  13. package/hooks/index.d.ts +4 -3
  14. package/hooks/index.js +7 -5
  15. package/hooks/useAbsolutePositioning.js +0 -1
  16. package/hooks/useAddressBar.js +0 -1
  17. package/hooks/useApplication.js +8 -1
  18. package/hooks/useDataProvider.d.ts +17 -2
  19. package/hooks/useDataSelect.js +21 -4
  20. package/hooks/useFetch.js +6 -1
  21. package/hooks/useFile.d.ts +1 -0
  22. package/hooks/useFile.js +2 -0
  23. package/hooks/useList.d.ts +53 -14
  24. package/hooks/useList.js +31 -70
  25. package/hooks/useTree.d.ts +104 -0
  26. package/hooks/useTree.js +169 -0
  27. package/index.d.ts +3 -3
  28. package/package.json +94 -93
  29. package/reducers/router.d.ts +2 -1
  30. package/ui/content/Accordion/Accordion.d.ts +8 -5
  31. package/ui/content/Accordion/Accordion.js +6 -1
  32. package/ui/content/Accordion/AccordionItem.d.ts +2 -2
  33. package/ui/content/Accordion/AccordionItem.js +1 -12
  34. package/ui/content/Alert/Alert.d.ts +5 -2
  35. package/ui/content/Alert/Alert.js +13 -12
  36. package/ui/content/Avatar/Avatar.js +18 -12
  37. package/ui/content/Badge/Badge.d.ts +5 -1
  38. package/ui/content/Badge/Badge.js +14 -12
  39. package/ui/content/Calendar/Calendar.d.ts +6 -1
  40. package/ui/content/Calendar/Calendar.js +19 -12
  41. package/ui/content/CalendarSystem/CalendarSystem.d.ts +94 -17
  42. package/ui/content/CalendarSystem/CalendarSystem.js +66 -77
  43. package/ui/content/CalendarSystem/hooks/useCalendarControls.d.ts +1 -2
  44. package/ui/content/CalendarSystem/hooks/useCalendarControls.js +14 -17
  45. package/ui/content/CalendarSystem/hooks/useCalendarSystemEventGroupModals.d.ts +2 -1
  46. package/ui/content/CalendarSystem/hooks/useCalendarSystemEventGroupModals.js +13 -5
  47. package/ui/content/CalendarSystem/hooks/useCalendarSystemModals.js +2 -2
  48. package/ui/content/CalendarSystem/hooks/useCalendarType.d.ts +5 -0
  49. package/ui/content/CalendarSystem/hooks/useCalendarType.js +22 -0
  50. package/ui/content/CalendarSystem/hooks/useEventsFromDate.d.ts +5 -0
  51. package/ui/content/CalendarSystem/hooks/useEventsFromDate.js +49 -0
  52. package/ui/content/CalendarSystem/hooks/{useMonthCalendar.d.ts → useMonthGrid.d.ts} +4 -5
  53. package/ui/content/CalendarSystem/hooks/{useMonthCalendar.js → useMonthGrid.js} +24 -15
  54. package/ui/content/CalendarSystem/hooks/{useWeekCalendar.d.ts → useWeekGrid.d.ts} +6 -5
  55. package/ui/content/CalendarSystem/hooks/useWeekGrid.js +72 -0
  56. package/ui/content/CalendarSystem/utils/utils.d.ts +8 -0
  57. package/ui/content/CalendarSystem/utils/utils.js +27 -1
  58. package/ui/content/Card/Card.d.ts +33 -27
  59. package/ui/content/Card/Card.js +1 -12
  60. package/ui/content/Chart/Chart.d.ts +38 -8
  61. package/ui/content/Chart/Chart.js +16 -12
  62. package/ui/content/Chat/Chat.d.ts +109 -0
  63. package/ui/content/Chat/Chat.js +52 -0
  64. package/ui/content/Chat/constants/timeTemplatesAndUnits.d.ts +8 -0
  65. package/ui/content/Chat/constants/timeTemplatesAndUnits.js +11 -0
  66. package/ui/content/Chat/hooks/useChat.d.ts +12 -0
  67. package/ui/content/Chat/hooks/useChat.js +58 -0
  68. package/ui/content/Chat/index.d.ts +2 -0
  69. package/ui/content/Chat/index.js +7 -0
  70. package/ui/content/Chat/utils/addNewMessageIntoGroupedMessages.d.ts +5 -0
  71. package/ui/content/Chat/utils/addNewMessageIntoGroupedMessages.js +61 -0
  72. package/ui/content/Chat/utils/calculateMessageTimeAgo.d.ts +1 -0
  73. package/ui/content/Chat/utils/calculateMessageTimeAgo.js +26 -0
  74. package/ui/content/Chat/utils/getMessagesGroupedByDate.d.ts +4 -0
  75. package/ui/content/Chat/utils/getMessagesGroupedByDate.js +56 -0
  76. package/ui/content/Chat/utils/index.d.ts +5 -0
  77. package/ui/content/Chat/utils/index.js +12 -0
  78. package/ui/content/Chat/utils/isTodayMessage.d.ts +1 -0
  79. package/ui/content/Chat/utils/isTodayMessage.js +13 -0
  80. package/ui/content/CopyToClipboard/CopyToClipboard.d.ts +3 -3
  81. package/ui/content/CopyToClipboard/CopyToClipboard.js +10 -12
  82. package/ui/content/Dashboard/Dashboard.d.ts +5 -2
  83. package/ui/content/Dashboard/Dashboard.js +27 -3
  84. package/ui/content/Detail/Detail.d.ts +15 -2
  85. package/ui/content/Detail/Detail.js +12 -1
  86. package/ui/content/DropDown/DropDown.d.ts +1 -1
  87. package/ui/content/DropDown/DropDown.js +16 -4
  88. package/ui/content/Icon/Icon.js +13 -15
  89. package/ui/content/Kanban/Kanban.d.ts +15 -4
  90. package/ui/content/Kanban/Kanban.js +8 -12
  91. package/ui/content/Kanban/hooks/useKanban.d.ts +33 -26
  92. package/ui/content/Menu/Menu.js +10 -12
  93. package/ui/content/Slider/Slider.js +1 -12
  94. package/ui/content/index.d.ts +2 -1
  95. package/ui/content/index.js +3 -1
  96. package/ui/crud/index.d.ts +3 -0
  97. package/ui/form/AutoCompleteField/AutoCompleteField.js +1 -1
  98. package/ui/form/Button/Button.js +8 -2
  99. package/ui/form/CheckboxField/CheckboxField.d.ts +1 -0
  100. package/ui/form/CheckboxField/CheckboxField.js +2 -2
  101. package/ui/form/CheckboxListField/CheckboxListField.d.ts +18 -2
  102. package/ui/form/CheckboxListField/CheckboxListField.js +1 -1
  103. package/ui/form/CheckboxTreeField/CheckboxTreeField.d.ts +67 -0
  104. package/ui/form/CheckboxTreeField/CheckboxTreeField.js +126 -0
  105. package/ui/form/CheckboxTreeField/index.d.ts +2 -0
  106. package/ui/form/CheckboxTreeField/index.js +7 -0
  107. package/ui/form/DateField/DateField.js +4 -1
  108. package/ui/form/DateField/useDateRange.d.ts +1 -0
  109. package/ui/form/DateField/useDateRange.js +13 -2
  110. package/ui/form/DateRangeField/DateRangeField.d.ts +34 -1
  111. package/ui/form/DateRangeField/DateRangeField.js +59 -8
  112. package/ui/form/DateTimeField/DateTimeField.d.ts +10 -0
  113. package/ui/form/DateTimeField/DateTimeField.js +11 -3
  114. package/ui/form/DateTimeRangeField/DateTimeRangeField.d.ts +25 -1
  115. package/ui/form/DateTimeRangeField/DateTimeRangeField.js +66 -13
  116. package/ui/form/DropDownField/DropDownField.d.ts +23 -3
  117. package/ui/form/DropDownField/DropDownField.js +1 -1
  118. package/ui/form/EmailField/EmailField.d.ts +6 -0
  119. package/ui/form/EmailField/EmailField.js +0 -4
  120. package/ui/form/Field/Field.d.ts +9 -1
  121. package/ui/form/Field/Field.js +1 -1
  122. package/ui/form/Field/fieldWrapper.d.ts +9 -1
  123. package/ui/form/FieldList/FieldList.d.ts +13 -7
  124. package/ui/form/FieldList/FieldList.js +30 -4
  125. package/ui/form/FileField/FileField.js +5 -0
  126. package/ui/form/Form/Form.d.ts +26 -3
  127. package/ui/form/Form/Form.js +5 -3
  128. package/ui/form/ImageField/ImageField.d.ts +9 -1
  129. package/ui/form/InputField/InputField.d.ts +5 -2
  130. package/ui/form/InputField/hooks/useInputFieldWarningByType.js +1 -0
  131. package/ui/form/NumberField/NumberField.js +34 -7
  132. package/ui/form/SliderField/SliderField.d.ts +10 -2
  133. package/ui/form/TimeRangeField/TimeRangeField.d.ts +10 -1
  134. package/ui/form/TimeRangeField/TimeRangeField.js +3 -1
  135. package/ui/form/WizardForm/WizardForm.d.ts +119 -0
  136. package/ui/form/WizardForm/WizardForm.js +167 -0
  137. package/ui/form/WizardForm/index.d.ts +2 -0
  138. package/ui/form/WizardForm/index.js +7 -0
  139. package/ui/form/WizardForm/utils.d.ts +12 -0
  140. package/ui/form/WizardForm/utils.js +111 -0
  141. package/ui/form/index.d.ts +3 -1
  142. package/ui/form/index.js +4 -1
  143. package/ui/layout/ProgressBar/ProgressBar.js +8 -2
  144. package/ui/layout/Skeleton/Skeleton.d.ts +3 -1
  145. package/ui/layout/Tooltip/Tooltip.d.ts +4 -1
  146. package/ui/list/ControlsColumn/ControlsColumn.d.ts +17 -3
  147. package/ui/list/FlexGrid/FlexGrid.d.ts +11 -1
  148. package/ui/list/Grid/Grid.d.ts +42 -6
  149. package/ui/list/Grid/Grid.js +1 -2
  150. package/ui/list/LayoutNames/LayoutNames.d.ts +11 -1
  151. package/ui/list/Steps/Steps.d.ts +19 -7
  152. package/ui/list/Steps/Steps.js +46 -26
  153. package/ui/list/TreeTable/TreeTable.d.ts +34 -33
  154. package/ui/list/TreeTable/TreeTable.js +19 -8
  155. package/ui/modal/Modal/Modal.d.ts +7 -1
  156. package/ui/nav/Breadcrumbs/Breadcrumbs.d.ts +11 -1
  157. package/ui/nav/ButtonGroup/ButtonGroup.d.ts +13 -4
  158. package/ui/nav/Controls/Controls.d.ts +7 -1
  159. package/ui/nav/Link/Link.d.ts +1 -1
  160. package/ui/nav/Nav/Nav.d.ts +19 -4
  161. package/ui/nav/Router/Router.d.ts +19 -3
  162. package/ui/nav/Router/Router.js +11 -6
  163. package/ui/nav/Router/helpers.d.ts +2 -2
  164. package/ui/nav/Router/helpers.js +39 -7
  165. package/ui/nav/Tree/Tree.d.ts +32 -62
  166. package/ui/nav/Tree/Tree.js +18 -165
  167. package/utils/calculateComponentAbsolutePosition.js +74 -24
  168. package/utils/calendar.d.ts +8 -0
  169. package/utils/calendar.js +76 -1
  170. package/utils/data.js +1 -0
  171. package/utils/form.d.ts +1 -0
  172. package/utils/form.js +16 -1
  173. package/ui/content/CalendarSystem/hooks/useWeekCalendar.js +0 -86
  174. package/utils/list.d.ts +0 -1
  175. package/utils/list.js +0 -5
@@ -13,7 +13,17 @@ export interface IBreadcrumbsProps {
13
13
  className?: CssClassName;
14
14
  /**
15
15
  * Коллекция элементов навигационной цепочки
16
- * @example [{id: 'root', title: 'Home'}, {id: 'catalog', title: 'Catalog'}]
16
+ * @example
17
+ * [
18
+ * {
19
+ * id: 'root',
20
+ * title: 'Home'
21
+ * },
22
+ * {
23
+ * id: 'catalog',
24
+ * title: 'Catalog'
25
+ * }
26
+ * ]
17
27
  */
18
28
  items?: IRouteItem[];
19
29
  /**
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import { Dispatch, SetStateAction } from 'react';
2
2
  import { IButtonProps } from '../../form/Button/Button';
3
3
  import { DataProviderItems } from '../../../hooks/useDataProvider';
4
4
  /**
@@ -9,14 +9,19 @@ import { DataProviderItems } from '../../../hooks/useDataProvider';
9
9
  export interface IButtonGroupProps extends IUiComponent {
10
10
  /**
11
11
  * Элементы для группы кнопок
12
- * @example ['button1', 'button2', 'button3']
12
+ * @example
13
+ * [
14
+ * 'button1',
15
+ * 'button2',
16
+ * 'button3'
17
+ * ]
13
18
  */
14
19
  items: DataProviderItems;
15
20
  /**
16
21
  * Функция, которая будет вызываться при клике по кнопке
17
22
  * @example setActiveTab
18
23
  */
19
- onClick: (value: number | string | boolean) => void;
24
+ onClick: ((value: number | string | boolean) => void) | Dispatch<SetStateAction<string | number | boolean>>;
20
25
  /**
21
26
  * При указании в связке с onClick предоставляет возможность реализовать two-way binding
22
27
  * @example 'button1'
@@ -28,7 +33,11 @@ export interface IButtonGroupProps extends IUiComponent {
28
33
  defaultActiveButton?: number | string;
29
34
  /**
30
35
  * Общие свойства для всех кнопок группы
31
- * @example {outline: true, color: 'secondary'}
36
+ * @example
37
+ * {
38
+ * outline: true,
39
+ * color: 'secondary'
40
+ * }
32
41
  */
33
42
  buttonProps?: IButtonProps;
34
43
  }
@@ -27,7 +27,13 @@ export interface IControlItem extends IButtonProps {
27
27
  export interface IControlsProps {
28
28
  /**
29
29
  * Коллекция контролов
30
- * @example [{id: 'delete', onClick: () => alert("It's deleted")}]
30
+ * @example
31
+ * [
32
+ * {
33
+ * id: 'delete',
34
+ * onClick: () => alert("It's deleted")
35
+ * }
36
+ * ]
31
37
  */
32
38
  items?: IControlItem[];
33
39
  /**
@@ -3,7 +3,7 @@ import { IButtonProps, IButtonViewProps } from '../../form/Button/Button';
3
3
  /**
4
4
  * Link
5
5
  *
6
- * Ссылка
6
+ * С помощью компонента `Link` вы можете легко настраивать цветовую схему элементов ссылок.
7
7
  */
8
8
  export interface ILinkProps extends IButtonProps {
9
9
  [key: string]: any;
@@ -35,13 +35,16 @@ export interface INavItem extends IButtonProps {
35
35
  */
36
36
  visible?: boolean;
37
37
  /**
38
- * Контент, который отобразиться, если элемент навигации будет активен
38
+ * Контент, который отобразится, если элемент навигации будет активен
39
39
  * @example ContentComponent
40
40
  */
41
41
  content?: any;
42
42
  /**
43
43
  * Свойства для компонента с контентом
44
- * @example {content: 'Some text'}
44
+ * @example
45
+ * {
46
+ * content: 'Some text'
47
+ * }
45
48
  */
46
49
  contentProps?: any;
47
50
  /**
@@ -56,7 +59,9 @@ export interface INavItem extends IButtonProps {
56
59
  }
57
60
  /**
58
61
  * Nav
59
- * Компонент навигации
62
+ *
63
+ * Компонент навигации позволяет переключаться между группами связанного контента.
64
+ *
60
65
  */
61
66
  export interface INavProps {
62
67
  /**
@@ -67,7 +72,17 @@ export interface INavProps {
67
72
  /**
68
73
  * Коллекция с элементами навигации. Также можно передать идентификатор роута, тогда компонент найдет все
69
74
  * вложенные роуты и отобразит их в навигации.
70
- * @example [{id: 1, label: 'One'}, {id: 2, label: 'Two'}] | 'root'
75
+ * @example
76
+ * [
77
+ * {
78
+ * id: 1,
79
+ * label: 'One'
80
+ * },
81
+ * {
82
+ * id: 2,
83
+ * label: 'Two'
84
+ * }
85
+ * ] | 'root'
71
86
  */
72
87
  items?: string | INavItem[];
73
88
  /**
@@ -31,12 +31,18 @@ export interface IRouteItem {
31
31
  * Путь до роута
32
32
  * @example '/catalog'
33
33
  */
34
- path?: string;
34
+ path: string;
35
35
  /**
36
36
  * Если true, то путь должен точно соответствовать location.pathname
37
37
  * @example '/catalog'
38
38
  */
39
39
  exact?: boolean;
40
+ /**
41
+ * Если true, то location.pathname будет совпадать с теми путями, которые содержат слеш в конце.
42
+ * Например, если указать путь '/catalog/', тогда совпадение будет с '/catalog/' и '/catalog/chapter', но не '/catalog'.
43
+ * @example '/catalog'
44
+ */
45
+ strict?: boolean;
40
46
  /**
41
47
  * В свойстве можно передать как путь, на который осуществится редирект, так и булево значение.
42
48
  * Если свойство равно true - то редирект произойдет на первый из вложенных роутов.
@@ -102,7 +108,11 @@ export interface IRouteItem {
102
108
  * @return {Array} Например, [{url: '/api/v1/some-data'}, {listId: 'someList', action: '/api/v1/some-list'}]
103
109
  */
104
110
  preloadData?: (match: Record<string, any>) => (IFetchConfig | IListProps)[];
105
- [key: string]: any;
111
+ /**
112
+ * Пользовательская иконка svg или название иконки
113
+ * @example 'circle'
114
+ */
115
+ icon?: React.ReactElement | string;
106
116
  }
107
117
  export interface IRouterProps {
108
118
  /**
@@ -118,7 +128,7 @@ export interface IRouterProps {
118
128
  * Дерево роутов
119
129
  * @example {id: 'root', path: '/', component: IndexPage, items: [...]}
120
130
  */
121
- routes?: IRouteItem[] | {
131
+ routes: IRouteItem[] | {
122
132
  [key: string]: IRouteItem;
123
133
  };
124
134
  /**
@@ -137,11 +147,17 @@ export interface IRouterProps {
137
147
  * @example SomeComponent
138
148
  */
139
149
  children?: React.ReactNode;
150
+ /**
151
+ * Флаг, который позволяет использовать вложенные роуты c указанием вложенного пути
152
+ * @example true
153
+ */
154
+ alwaysAppendParentRoutePath?: boolean;
140
155
  }
141
156
  declare function Router(props: IRouterProps): JSX.Element;
142
157
  declare namespace Router {
143
158
  var defaultProps: {
144
159
  autoScrollTop: boolean;
160
+ alwaysAppendParentRoutePath: boolean;
145
161
  };
146
162
  }
147
163
  export default Router;
@@ -80,9 +80,10 @@ var renderComponent = function (route, activePath, routeProps) {
80
80
  return (React.createElement(Component, __assign({}, routeProps, route.componentProps)));
81
81
  };
82
82
  function Router(props) {
83
+ var _a;
83
84
  var components = (0, hooks_1.useComponents)();
84
85
  var routeParams = (0, hooks_1.useSelector)(router_2.getRouteParams);
85
- var _a = (0, hooks_1.useSelector)(function (state) {
86
+ var _b = (0, hooks_1.useSelector)(function (state) {
86
87
  var _a, _b;
87
88
  return ({
88
89
  isInitialized: (0, router_2.isRouterInitialized)(state),
@@ -91,24 +92,24 @@ function Router(props) {
91
92
  activePath: (_b = (_a = state.router) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.pathname,
92
93
  activeRouteIds: (0, router_2.getActiveRouteIds)(state)
93
94
  });
94
- }), isInitialized = _a.isInitialized, pathname = _a.pathname, route = _a.route, activePath = _a.activePath, activeRouteIds = _a.activeRouteIds;
95
+ }), isInitialized = _b.isInitialized, pathname = _b.pathname, route = _b.route, activePath = _b.activePath, activeRouteIds = _b.activeRouteIds;
95
96
  var routeId = (route === null || route === void 0 ? void 0 : route.id) || null;
96
97
  // Init routes in redux
97
98
  var dispatch = (0, useDispatch_1["default"])();
98
99
  (0, react_use_1.useEffectOnce)(function () {
99
100
  if (props.routes) {
100
- dispatch((0, router_1.initRoutes)((0, helpers_1.walkRoutesRecursive)(__assign({ id: 'root' }, props.routes), props.defaultRoles ? { roles: props.defaultRoles } : undefined)));
101
+ dispatch((0, router_1.initRoutes)((0, helpers_1.walkRoutesRecursive)(__assign({ id: 'root' }, props.routes), props.defaultRoles ? { roles: props.defaultRoles } : undefined, {}, props.alwaysAppendParentRoutePath)));
101
102
  }
102
103
  });
103
104
  // Sync route params with redux
104
- var prevRouteParams = (0, react_use_1.usePreviousDistinct)(routeParams);
105
+ var prevRouteParams = (_a = (0, react_use_1.usePreviousDistinct)(routeParams)) !== null && _a !== void 0 ? _a : routeParams;
105
106
  (0, react_1.useEffect)(function () {
106
107
  if (!(0, isEqual_1["default"])(prevRouteParams, routeParams)) {
107
108
  dispatch((0, router_1.initParams)(routeParams));
108
109
  }
109
110
  }, [dispatch, prevRouteParams, routeParams]);
110
111
  // Routes state
111
- var _b = (0, react_1.useState)((0, helpers_1.treeToList)(props.routes)), routes = _b[0], setRoutes = _b[1];
112
+ var _c = (0, react_1.useState)((0, helpers_1.treeToList)(props.routes, true, null, props.alwaysAppendParentRoutePath)), routes = _c[0], setRoutes = _c[1];
112
113
  (0, react_use_1.useUpdateEffect)(function () {
113
114
  setRoutes(props.routes);
114
115
  }, [props.routes]);
@@ -175,6 +176,9 @@ function Router(props) {
175
176
  });
176
177
  var result = renderComponent(routeItem, activePath, __assign(__assign({}, routeProps), { children: children }));
177
178
  if (!result) {
179
+ if (children) {
180
+ return children;
181
+ }
178
182
  // eslint-disable-next-line no-console
179
183
  console.error('Not found component for route:', routeItem);
180
184
  }
@@ -202,6 +206,7 @@ function Router(props) {
202
206
  return (React.createElement(connected_react_router_1.ConnectedRouter, { history: components.store.history }, renderContent()));
203
207
  }
204
208
  Router.defaultProps = {
205
- autoScrollTop: true
209
+ autoScrollTop: true,
210
+ alwaysAppendParentRoutePath: true
206
211
  };
207
212
  exports["default"] = Router;
@@ -1,4 +1,4 @@
1
1
  import { IRouteItem } from './Router';
2
2
  export declare const findRedirectPathRecursive: (route: IRouteItem) => any;
3
- export declare const walkRoutesRecursive: (item: IRouteItem | Record<string, any>, defaultItem?: any, parentItem?: any) => any;
4
- export declare const treeToList: (item: IRouteItem | Record<string, any>, isRoot?: boolean) => Record<string, any>;
3
+ export declare const walkRoutesRecursive: (item: IRouteItem | Record<string, any>, defaultItem?: any, parentItem?: any, alwaysAppendParentRoutePath?: boolean) => any;
4
+ export declare const treeToList: (item: IRouteItem | Record<string, any>, isRoot?: boolean, parentItem?: any, alwaysAppendParentRoutePath?: boolean) => Record<string, any>;
@@ -18,6 +18,7 @@ exports.treeToList = exports.walkRoutesRecursive = exports.findRedirectPathRecur
18
18
  var get_1 = __importDefault(require("lodash-es/get"));
19
19
  var isArray_1 = __importDefault(require("lodash-es/isArray"));
20
20
  var isObject_1 = __importDefault(require("lodash-es/isObject"));
21
+ var SLASH = '/';
21
22
  var findRedirectPathRecursive = function (route) {
22
23
  if (!route) {
23
24
  return null;
@@ -34,10 +35,36 @@ var findRedirectPathRecursive = function (route) {
34
35
  : null;
35
36
  };
36
37
  exports.findRedirectPathRecursive = findRedirectPathRecursive;
37
- var walkRoutesRecursive = function (item, defaultItem, parentItem) {
38
+ var addSlashIfNotPresent = function (path) {
39
+ if (path === void 0) { path = ''; }
40
+ return path.startsWith(SLASH) ? path : (SLASH + path);
41
+ };
42
+ var joinChildAndParentPaths = function (path, parentPath) {
43
+ if (path === void 0) { path = ''; }
44
+ if (parentPath === void 0) { parentPath = null; }
45
+ if (!parentPath || parentPath === SLASH) {
46
+ return addSlashIfNotPresent(path);
47
+ }
48
+ return addSlashIfNotPresent(parentPath) + addSlashIfNotPresent(path);
49
+ };
50
+ var appendChildIfNoSlash = function (path, parentPath) {
51
+ if (path === void 0) { path = ''; }
52
+ if (parentPath === void 0) { parentPath = null; }
53
+ if (parentPath === SLASH) {
54
+ return addSlashIfNotPresent(path);
55
+ }
56
+ if (!path.startsWith(SLASH)) {
57
+ return addSlashIfNotPresent(parentPath) + addSlashIfNotPresent(path);
58
+ }
59
+ return path;
60
+ };
61
+ var walkRoutesRecursive = function (item, defaultItem, parentItem, alwaysAppendParentRoutePath) {
38
62
  if (defaultItem === void 0) { defaultItem = {}; }
39
63
  if (parentItem === void 0) { parentItem = {}; }
40
- var normalizedItem = __assign(__assign(__assign({}, defaultItem), item), { id: item.id, exact: item.exact, path: item.path && (item.path.indexOf('/') !== 0 && parentItem.path ? parentItem.path + '/' : '') + item.path, label: item.label, title: item.title, isVisible: typeof item.isVisible !== 'undefined'
64
+ if (alwaysAppendParentRoutePath === void 0) { alwaysAppendParentRoutePath = true; }
65
+ var normalizedItem = __assign(__assign(__assign({}, defaultItem), item), { id: item.id, exact: item.exact, path: alwaysAppendParentRoutePath
66
+ ? joinChildAndParentPaths(item.path, parentItem.path)
67
+ : appendChildIfNoSlash(item.path, parentItem.path), label: item.label, title: item.title, isVisible: typeof item.isVisible !== 'undefined'
41
68
  ? item.isVisible
42
69
  : (typeof parentItem.isVisible !== 'undefined'
43
70
  ? parentItem.isVisible
@@ -48,32 +75,37 @@ var walkRoutesRecursive = function (item, defaultItem, parentItem) {
48
75
  : defaultItem.isNavVisible), layout: item.layout || parentItem.layout || defaultItem.layout || null, roles: item.roles || parentItem.roles || defaultItem.roles || null, component: null, componentProps: null });
49
76
  var items = null;
50
77
  if ((0, isArray_1["default"])(item.items)) {
51
- items = item.items.map(function (subItem) { return (0, exports.walkRoutesRecursive)(subItem, defaultItem, normalizedItem); });
78
+ items = item.items.map(function (subItem) { return (0, exports.walkRoutesRecursive)(subItem, defaultItem, normalizedItem, alwaysAppendParentRoutePath); });
52
79
  }
53
80
  else if ((0, isObject_1["default"])(item.items)) {
54
81
  items = Object.keys(item.items)
55
- .map(function (id) { return (0, exports.walkRoutesRecursive)(__assign(__assign({}, item.items[id]), { id: id }), defaultItem, normalizedItem); });
82
+ .map(function (id) { return (0, exports.walkRoutesRecursive)(__assign(__assign({}, item.items[id]), { id: id }), defaultItem, normalizedItem, alwaysAppendParentRoutePath); });
56
83
  }
57
84
  return __assign(__assign({}, normalizedItem), { items: items });
58
85
  };
59
86
  exports.walkRoutesRecursive = walkRoutesRecursive;
60
- var treeToList = function (item, isRoot) {
87
+ var treeToList = function (item, isRoot, parentItem, alwaysAppendParentRoutePath) {
61
88
  if (isRoot === void 0) { isRoot = true; }
89
+ if (parentItem === void 0) { parentItem = {}; }
90
+ if (alwaysAppendParentRoutePath === void 0) { alwaysAppendParentRoutePath = true; }
62
91
  if ((0, isArray_1["default"])(item)) {
63
92
  return item;
64
93
  }
94
+ item.path = alwaysAppendParentRoutePath
95
+ ? joinChildAndParentPaths(item.path, parentItem === null || parentItem === void 0 ? void 0 : parentItem.path)
96
+ : appendChildIfNoSlash(item.path, parentItem === null || parentItem === void 0 ? void 0 : parentItem.path);
65
97
  if (isRoot && !item.id) {
66
98
  item.id = 'root';
67
99
  }
68
100
  var items = item.path ? [item] : [];
69
101
  if ((0, isArray_1["default"])(item.items)) {
70
102
  item.items.forEach(function (subItem) {
71
- items = items.concat((0, exports.treeToList)(subItem, false));
103
+ items = items.concat((0, exports.treeToList)(subItem, false, item, alwaysAppendParentRoutePath));
72
104
  });
73
105
  }
74
106
  else if ((0, isObject_1["default"])(item.items)) {
75
107
  Object.keys(item.items).forEach(function (id) {
76
- items = items.concat((0, exports.treeToList)(__assign(__assign({}, item.items[id]), { id: id }), false));
108
+ items = items.concat((0, exports.treeToList)(__assign(__assign({}, item.items[id]), { id: id }), false, item, alwaysAppendParentRoutePath));
77
109
  });
78
110
  }
79
111
  return items;
@@ -1,52 +1,22 @@
1
- import * as React from 'react';
2
- import { IButtonProps } from '../../form/Button/Button';
3
- export interface ITreeItem extends IButtonProps {
4
- /**
5
- * Идентификатор узла
6
- */
7
- id?: string | number;
8
- /**
9
- * Вложенные элементы
10
- * @example [{id: 2, label: 'Nested element', items: [...]}]
11
- */
12
- items?: any[];
13
- /**
14
- * Скрыть или показать узел
15
- * @example true
16
- */
17
- visible?: boolean;
1
+ import React from 'react';
2
+ import { IPreparedTreeItem, ITreeConfig, ITreeItem } from '../../../hooks/useTree';
3
+ export interface ITreeViewProps extends ITreeProps {
4
+ items: IPreparedTreeItem[];
5
+ }
6
+ export interface ITreeItemViewProps extends ITreeProps {
7
+ item: IPreparedTreeItem;
8
+ children?: JSX.Element;
18
9
  }
19
10
  /**
20
11
  * Tree
21
12
  * Компонент, который представляет в виде дерева список с иерархической структурой данных
22
13
  */
23
- export interface ITreeProps {
14
+ export interface ITreeProps extends Omit<ITreeConfig, 'currentPage' | 'itemsOnPage'> {
24
15
  /**
25
16
  * Идентификатор (ключ) для сохранения в LocalStorage коллекции с раскрытыми узлами
26
17
  * @example 'exampleTree'
27
18
  */
28
19
  id?: string;
29
- /**
30
- * Коллекция с узлами. Также можно передать идентификатор роута, тогда компонент найдет все
31
- * вложенные роуты и отобразит их в виде дерева.
32
- * @example [{id: 1, label: 'Root', items: [...]}] | 'root'
33
- */
34
- items?: ITreeItem[] | string;
35
- /**
36
- * Ограничивает максимальный уровень вложенности дерева
37
- * @example 2
38
- */
39
- level?: number;
40
- /**
41
- * Ключ для доступа к вложенным элементам узла
42
- * @example 'items'
43
- */
44
- itemsKey?: string;
45
- /**
46
- * Идентификатор узла, которой нужно отобразить в раскрытом виде
47
- * @example 2
48
- */
49
- selectedItemId?: string | number;
50
20
  /**
51
21
  * CSS-класс для элемента отображения
52
22
  */
@@ -56,40 +26,36 @@ export interface ITreeProps {
56
26
  * @example MyCustomView
57
27
  */
58
28
  view?: CustomView;
59
- /**
60
- * Максимальный уровень вложенности, до которого все узлы будут отображаться в развёрнутом виде
61
- * @example 1
62
- */
63
- autoOpenLevels?: number;
64
29
  /**
65
30
  * Обработчик на клик по узлу
66
31
  * @param args
67
32
  */
68
- onItemClick?: (...args: any[]) => any;
33
+ onItemClick?: (event: React.MouseEvent, item: ITreeItem) => any;
69
34
  /**
70
35
  * Отображать раскрытыми узлы из LocalStorage
71
36
  * @example true
72
37
  */
73
38
  autoSave?: boolean;
74
39
  /**
75
- * Используется для управления раскрытием всех элементов в дереве
76
- * @example: true
77
- */
78
- alwaysOpened?: boolean;
79
- [key: string]: any;
80
- }
81
- export interface ITreeViewProps extends ITreeProps {
82
- items: (ITreeItem & {
83
- uniqId: string;
84
- className: CssClassName;
85
- index: number;
86
- level: number;
87
- isOpened: boolean;
88
- isSelected: boolean;
89
- hasItems: boolean;
90
- onClick: (e: Event | React.MouseEvent | any) => void;
91
- })[];
40
+ * Расстояние вложенных элементов от родителя для каждого уровня
41
+ * @example 32
42
+ */
92
43
  levelPadding?: number;
44
+ /**
45
+ * Показать иконку c лева от элемента
46
+ * @example true
47
+ */
48
+ showIcon?: boolean;
49
+ /**
50
+ * Кастомная иконка, заменяющая иконку раскрытия по умолчанию
51
+ */
52
+ customIcon?: string | React.ReactElement;
53
+ /**
54
+ * Флаг, определяющий раскрывать вложенные элементы по клику на весь элемент или только на иконку
55
+ * @example false
56
+ */
57
+ hasIconExpandOnly?: boolean;
58
+ [key: string]: any;
93
59
  }
94
60
  declare function Tree(props: ITreeProps): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
95
61
  declare namespace Tree {
@@ -98,6 +64,10 @@ declare namespace Tree {
98
64
  autoOpenLevels: number;
99
65
  autoSave: boolean;
100
66
  level: number;
67
+ levelPadding: number;
68
+ hasIconExpandOnly: boolean;
69
+ useSameSelectedItemId: boolean;
70
+ showIcon: boolean;
101
71
  };
102
72
  }
103
73
  export default Tree;