@synerise/ds-item-picker 1.17.0 → 1.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/ItemPicker.d.ts +5 -5
  3. package/dist/ItemPicker.js +13 -17
  4. package/dist/ItemPicker.styles.d.ts +1 -1
  5. package/dist/ItemPicker.styles.js +6 -3
  6. package/dist/components/ItemPickerDropdown/ItemPickerDropdown.d.ts +2 -2
  7. package/dist/components/ItemPickerDropdown/ItemPickerDropdown.js +58 -99
  8. package/dist/components/ItemPickerDropdown/ItemPickerDropdown.style.d.ts +7 -7
  9. package/dist/components/ItemPickerDropdown/ItemPickerDropdown.style.js +22 -19
  10. package/dist/components/ItemPickerDropdown/ItemPickerDropdown.types.d.ts +4 -4
  11. package/dist/components/ItemPickerDropdown/ItemPickerDropdown.types.js +1 -1
  12. package/dist/components/ItemPickerLegacy/ItemPickerLegacy.d.ts +2 -2
  13. package/dist/components/ItemPickerLegacy/ItemPickerLegacy.js +89 -152
  14. package/dist/components/ItemPickerLegacy/ItemPickerLegacy.types.d.ts +8 -8
  15. package/dist/components/ItemPickerLegacy/ItemPickerLegacy.types.js +1 -1
  16. package/dist/components/ItemPickerList/ItemPickerList.d.ts +4 -4
  17. package/dist/components/ItemPickerList/ItemPickerList.js +199 -267
  18. package/dist/components/ItemPickerList/ItemPickerList.styles.d.ts +18 -18
  19. package/dist/components/ItemPickerList/ItemPickerList.styles.js +55 -64
  20. package/dist/components/ItemPickerList/ItemPickerList.types.d.ts +3 -3
  21. package/dist/components/ItemPickerList/ItemPickerList.types.js +1 -1
  22. package/dist/components/ItemPickerList/components/EmptyListMessage.d.ts +3 -3
  23. package/dist/components/ItemPickerList/components/EmptyListMessage.js +27 -40
  24. package/dist/components/ItemPickerList/components/ErrorItem.d.ts +1 -1
  25. package/dist/components/ItemPickerList/components/ErrorItem.js +10 -9
  26. package/dist/components/ItemPickerList/components/ErrorMessage.d.ts +2 -2
  27. package/dist/components/ItemPickerList/components/ErrorMessage.js +12 -15
  28. package/dist/components/ItemPickerList/components/InfiniteLoaderItem.d.ts +2 -2
  29. package/dist/components/ItemPickerList/components/InfiniteLoaderItem.js +19 -17
  30. package/dist/components/ItemPickerList/components/ItemPickerListFooter.d.ts +3 -3
  31. package/dist/components/ItemPickerList/components/ItemPickerListFooter.js +21 -20
  32. package/dist/components/ItemPickerList/components/ItemPickerListRow.d.ts +4 -4
  33. package/dist/components/ItemPickerList/components/ItemPickerListRow.js +42 -43
  34. package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.d.ts +1 -1
  35. package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.js +16 -23
  36. package/dist/components/ItemPickerList/components/ListSearchInput.d.ts +4 -4
  37. package/dist/components/ItemPickerList/components/ListSearchInput.js +36 -51
  38. package/dist/components/ItemPickerList/components/LoadingItem.d.ts +1 -1
  39. package/dist/components/ItemPickerList/components/LoadingItem.js +10 -9
  40. package/dist/components/ItemPickerList/components/NoMoreItem.d.ts +1 -1
  41. package/dist/components/ItemPickerList/components/NoMoreItem.js +10 -9
  42. package/dist/components/ItemPickerList/components/index.js +14 -6
  43. package/dist/components/ItemPickerList/constants.d.ts +2 -2
  44. package/dist/components/ItemPickerList/constants.js +47 -26
  45. package/dist/components/ItemPickerList/hooks/index.js +8 -3
  46. package/dist/components/ItemPickerList/hooks/useFlattenFolders.d.ts +2 -2
  47. package/dist/components/ItemPickerList/hooks/useFlattenFolders.js +40 -61
  48. package/dist/components/ItemPickerList/hooks/useItemsInSections.d.ts +7 -7
  49. package/dist/components/ItemPickerList/hooks/useItemsInSections.js +342 -443
  50. package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.d.ts +5 -5
  51. package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.js +77 -74
  52. package/dist/components/ItemPickerList/hooks/useListHeight.d.ts +2 -2
  53. package/dist/components/ItemPickerList/hooks/useListHeight.js +37 -41
  54. package/dist/components/ItemPickerList/types/renderMode.js +8 -5
  55. package/dist/components/ItemPickerList/utils/actionItemsUtils.d.ts +4 -4
  56. package/dist/components/ItemPickerList/utils/actionItemsUtils.js +92 -92
  57. package/dist/components/ItemPickerList/utils/createTitleFromTitlePath.d.ts +2 -2
  58. package/dist/components/ItemPickerList/utils/createTitleFromTitlePath.js +7 -4
  59. package/dist/components/ItemPickerList/utils/findSectionById.d.ts +1 -1
  60. package/dist/components/ItemPickerList/utils/findSectionById.js +10 -12
  61. package/dist/components/ItemPickerList/utils/getContextAwareActions.d.ts +1 -1
  62. package/dist/components/ItemPickerList/utils/getContextAwareActions.js +19 -15
  63. package/dist/components/ItemPickerList/utils/getSearchByActionItems.d.ts +2 -2
  64. package/dist/components/ItemPickerList/utils/getSearchByActionItems.js +28 -29
  65. package/dist/components/ItemPickerList/utils/index.js +16 -4
  66. package/dist/components/ItemPickerList/utils/isNavKey.d.ts +1 -1
  67. package/dist/components/ItemPickerList/utils/isNavKey.js +6 -3
  68. package/dist/components/ItemPickerList/utils/resolveSectionId.d.ts +2 -2
  69. package/dist/components/ItemPickerList/utils/resolveSectionId.js +15 -9
  70. package/dist/components/ItemPickerList/utils/typeguards.utils.d.ts +5 -5
  71. package/dist/components/ItemPickerList/utils/typeguards.utils.js +23 -14
  72. package/dist/components/ItemPickerNew/ItemPickerNew.d.ts +4 -4
  73. package/dist/components/ItemPickerNew/ItemPickerNew.js +55 -100
  74. package/dist/components/ItemPickerNew/ItemPickerNew.types.d.ts +13 -13
  75. package/dist/components/ItemPickerNew/ItemPickerNew.types.js +1 -1
  76. package/dist/components/ItemPickerNew/types/actions.types.d.ts +2 -2
  77. package/dist/components/ItemPickerNew/types/actions.types.js +10 -6
  78. package/dist/components/ItemPickerNew/types/baseItemSectionType.types.d.ts +3 -3
  79. package/dist/components/ItemPickerNew/types/baseItemSectionType.types.js +1 -1
  80. package/dist/components/ItemPickerNew/types/itemPickerListTexts.types.d.ts +1 -1
  81. package/dist/components/ItemPickerNew/types/itemPickerListTexts.types.js +1 -1
  82. package/dist/components/ItemPickerTrigger/Trigger.d.ts +5 -5
  83. package/dist/components/ItemPickerTrigger/Trigger.js +71 -111
  84. package/dist/components/ItemPickerTrigger/Trigger.styles.d.ts +12 -12
  85. package/dist/components/ItemPickerTrigger/Trigger.styles.js +70 -93
  86. package/dist/components/ItemPickerTrigger/Trigger.types.d.ts +3 -3
  87. package/dist/components/ItemPickerTrigger/Trigger.types.js +1 -1
  88. package/dist/hooks/useDefaultTexts.d.ts +1 -1
  89. package/dist/hooks/useDefaultTexts.js +116 -121
  90. package/dist/index.js +14 -6
  91. package/dist/modules.d.js +1 -1
  92. package/dist/modules.d.ts +0 -0
  93. package/package.json +25 -25
@@ -1,226 +1,184 @@
1
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
4
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
5
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
6
- import { itemSizes } from '@synerise/ds-list-item';
7
- import { FIRST_PAGE, GET_ITEM_KEY, ITEMS_PER_PAGE, ITEMS_PER_SECTION, ITEMS_PER_SECTION_IN_SEARCH, ITEM_SIZE, SECOND_PAGE, SECTION_HEADER_HEIGHT } from '../constants';
8
- import { RENDER_MODES } from '../types/renderMode';
9
- import { isItems, isItemsConfig, isWithOutSections } from '../utils';
10
- import { getActionItems, getSectionActionItems } from '../utils/actionItemsUtils';
11
- import { getSearchByActionItems } from '../utils/getSearchByActionItems';
12
- import { resolveSectionId } from '../utils/resolveSectionId';
13
- import { useFlattenFolders } from './useFlattenFolders';
14
- import { getFolderItems, getItems, getRecentItems, matchesSearchQuery } from './useItemsInSections.utils';
15
- var getSectionHeight = function getSectionHeight(itemsCount, withTitle) {
16
- var itemsHeight = itemsCount * ITEM_SIZE[itemSizes.DEFAULT];
17
- var titleHeight = withTitle && itemsCount ? ITEM_SIZE.title : 0;
1
+ import { useState, useRef, useMemo, useCallback, useEffect } from "react";
2
+ import { itemSizes } from "@synerise/ds-list-item";
3
+ import { FIRST_PAGE, ITEMS_PER_SECTION_IN_SEARCH, ITEMS_PER_SECTION, ITEM_SIZE, SECTION_HEADER_HEIGHT, GET_ITEM_KEY, ITEMS_PER_PAGE, SECOND_PAGE } from "../constants.js";
4
+ import { RENDER_MODES } from "../types/renderMode.js";
5
+ import { isItems, isItemsConfig, isWithOutSections } from "../utils/typeguards.utils.js";
6
+ import { getActionItems, getSectionActionItems } from "../utils/actionItemsUtils.js";
7
+ import { getSearchByActionItems } from "../utils/getSearchByActionItems.js";
8
+ import { resolveSectionId } from "../utils/resolveSectionId.js";
9
+ import { useFlattenFolders } from "./useFlattenFolders.js";
10
+ import { matchesSearchQuery, getRecentItems, getFolderItems, getItems } from "./useItemsInSections.utils.js";
11
+ const getSectionHeight = (itemsCount, withTitle) => {
12
+ const itemsHeight = itemsCount * ITEM_SIZE[itemSizes.DEFAULT];
13
+ const titleHeight = withTitle && itemsCount ? ITEM_SIZE.title : 0;
18
14
  return itemsHeight + titleHeight;
19
15
  };
20
- export var useItemsInSections = function useItemsInSections(_ref) {
21
- var items = _ref.items,
22
- texts = _ref.texts,
23
- selectedItem = _ref.selectedItem,
24
- sections = _ref.sections,
25
- recents = _ref.recents,
26
- actions = _ref.actions,
27
- searchQuery = _ref.searchQuery,
28
- handleItemSelect = _ref.handleItemSelect,
29
- onSectionChange = _ref.onSectionChange,
30
- _ref$getItemKey = _ref.getItemKey,
31
- getItemKey = _ref$getItemKey === void 0 ? GET_ITEM_KEY : _ref$getItemKey,
32
- showItemsSectionLabel = _ref.showItemsSectionLabel,
33
- changeSearchQuery = _ref.changeSearchQuery,
34
- onLoadedData = _ref.onLoadedData;
35
- var _useState = useState(),
36
- currentSection = _useState[0],
37
- setCurrentSection = _useState[1];
38
- var _useState2 = useState(),
39
- previousSection = _useState2[0],
40
- setPreviousSection = _useState2[1];
41
- var _useState3 = useState(),
42
- searchByAction = _useState3[0],
43
- setSearchByAction = _useState3[1];
44
- var _useState4 = useState(),
45
- searchByParamConfig = _useState4[0],
46
- setSearchByParamConfig = _useState4[1];
47
- var _useState5 = useState(),
48
- searchInAction = _useState5[0],
49
- setSearchInAction = _useState5[1];
50
- var _useState6 = useState(),
51
- searchInItem = _useState6[0],
52
- setSearchInItem = _useState6[1];
53
- var _useFlattenFolders = useFlattenFolders({
54
- currentSection: currentSection,
55
- sections: sections
56
- }),
57
- currentSectionHasFolders = _useFlattenFolders.currentSectionHasFolders,
58
- currentFolders = _useFlattenFolders.currentFolders,
59
- parentFolder = _useFlattenFolders.parentFolder,
60
- currentPath = _useFlattenFolders.currentPath;
61
- var requestIdRef = useRef();
62
- var pageToLoad = useRef(FIRST_PAGE);
63
- var metaRef = useRef({});
64
- var sectionTotals = useRef({});
65
- var abortControllerRef = useRef();
66
- var isFixedItemsList = isItems(items) || isItemsConfig(items);
67
- var _useState7 = useState(),
68
- contentHeight = _useState7[0],
69
- setContentHeight = _useState7[1];
70
- var _useState8 = useState(isFixedItemsList),
71
- isInitialDataLoaded = _useState8[0],
72
- setIsInitialDataLoaded = _useState8[1];
73
- var _useState9 = useState(false),
74
- isLoading = _useState9[0],
75
- setIsLoading = _useState9[1];
76
- var _useState0 = useState(false),
77
- isLoadingError = _useState0[0],
78
- setIsLoadingError = _useState0[1];
79
- var _useState1 = useState(false),
80
- isLoadingMoreError = _useState1[0],
81
- setIsLoadingMoreError = _useState1[1];
82
- var _useState10 = useState(false),
83
- isLoadingMore = _useState10[0],
84
- setIsLoadingMore = _useState10[1];
85
- var _useState11 = useState(false),
86
- isLoadedAll = _useState11[0],
87
- setIsLoadedAll = _useState11[1];
88
- var _useState12 = useState(),
89
- refreshTrigger = _useState12[0],
90
- setRefreshTrigger = _useState12[1];
91
- var _useState13 = useState(function () {
92
- if (isFixedItemsList) {
93
- var fixedItems = isItemsConfig(items) ? items.items : items;
94
- if (searchQuery) {
95
- return fixedItems.filter(function (item) {
96
- return item.text && matchesSearchQuery(item.text, searchQuery);
97
- });
98
- }
99
- return fixedItems;
16
+ const useItemsInSections = ({
17
+ items,
18
+ texts,
19
+ selectedItem,
20
+ sections,
21
+ recents,
22
+ actions,
23
+ searchQuery,
24
+ handleItemSelect,
25
+ onSectionChange,
26
+ getItemKey = GET_ITEM_KEY,
27
+ showItemsSectionLabel,
28
+ changeSearchQuery,
29
+ onLoadedData
30
+ }) => {
31
+ const [currentSection, setCurrentSection] = useState();
32
+ const [previousSection, setPreviousSection] = useState();
33
+ const [searchByAction, setSearchByAction] = useState();
34
+ const [searchByParamConfig, setSearchByParamConfig] = useState();
35
+ const [searchInAction, setSearchInAction] = useState();
36
+ const [searchInItem, setSearchInItem] = useState();
37
+ const {
38
+ currentSectionHasFolders,
39
+ currentFolders,
40
+ parentFolder,
41
+ currentPath
42
+ } = useFlattenFolders({
43
+ currentSection,
44
+ sections
45
+ });
46
+ const requestIdRef = useRef();
47
+ const pageToLoad = useRef(FIRST_PAGE);
48
+ const metaRef = useRef({});
49
+ const sectionTotals = useRef({});
50
+ const abortControllerRef = useRef();
51
+ const isFixedItemsList = isItems(items) || isItemsConfig(items);
52
+ const [contentHeight, setContentHeight] = useState();
53
+ const [isInitialDataLoaded, setIsInitialDataLoaded] = useState(isFixedItemsList);
54
+ const [isLoading, setIsLoading] = useState(false);
55
+ const [isLoadingError, setIsLoadingError] = useState(false);
56
+ const [isLoadingMoreError, setIsLoadingMoreError] = useState(false);
57
+ const [isLoadingMore, setIsLoadingMore] = useState(false);
58
+ const [isLoadedAll, setIsLoadedAll] = useState(false);
59
+ const [refreshTrigger, setRefreshTrigger] = useState();
60
+ const [currentItems, setCurrentItems] = useState(() => {
61
+ if (isFixedItemsList) {
62
+ const fixedItems = isItemsConfig(items) ? items.items : items;
63
+ if (searchQuery) {
64
+ return fixedItems.filter((item) => item.text && matchesSearchQuery(item.text, searchQuery));
100
65
  }
101
- return [];
102
- }),
103
- currentItems = _useState13[0],
104
- setCurrentItems = _useState13[1];
105
- var isSearchInActionActive = !!searchInAction && !searchInItem;
106
- var canPerformListActions = actions !== undefined && !searchByAction && !searchByParamConfig && !isSearchInActionActive;
107
- var listActions = searchQuery === '/' && canPerformListActions;
108
- var hasSearchQuery = !!searchQuery;
109
- var _resolveSectionId = resolveSectionId({
110
- currentSection: currentSection,
111
- searchInAction: searchInAction,
112
- searchInItem: searchInItem
113
- }),
114
- activeSectionId = _resolveSectionId.activeSectionId,
115
- isListItemsRenderingMode = _resolveSectionId.isListItemsRenderingMode;
116
- var activeSectionIdWithFallback = activeSectionId || 'DEFAULT';
117
- var hasCurrentSection = !!activeSectionId;
118
- var hasSections = !isWithOutSections(sections);
119
- var hasSectionsAndFolders = useMemo(function () {
120
- return hasSections && (sections == null ? void 0 : sections.some(function (section) {
121
- var _section$folders;
122
- return (_section$folders = section.folders) == null ? void 0 : _section$folders.length;
123
- }));
124
- }, [hasSections, sections]);
125
- var handleItemSelectExtended = useCallback(function (item) {
66
+ return fixedItems;
67
+ }
68
+ return [];
69
+ });
70
+ const isSearchInActionActive = !!searchInAction && !searchInItem;
71
+ const canPerformListActions = actions !== void 0 && !searchByAction && !searchByParamConfig && !isSearchInActionActive;
72
+ const listActions = searchQuery === "/" && canPerformListActions;
73
+ const hasSearchQuery = !!searchQuery;
74
+ const {
75
+ activeSectionId,
76
+ isListItemsRenderingMode
77
+ } = resolveSectionId({
78
+ currentSection,
79
+ searchInAction,
80
+ searchInItem
81
+ });
82
+ const activeSectionIdWithFallback = activeSectionId || "DEFAULT";
83
+ const hasCurrentSection = !!activeSectionId;
84
+ const hasSections = !isWithOutSections(sections);
85
+ const hasSectionsAndFolders = useMemo(() => hasSections && sections?.some((section) => section.folders?.length), [hasSections, sections]);
86
+ const handleItemSelectExtended = useCallback((item) => {
126
87
  if (searchInAction && !searchInItem) {
127
- changeSearchQuery('');
88
+ changeSearchQuery("");
128
89
  setSearchInItem(item);
129
- setSearchByParamConfig(undefined);
130
- searchInAction.onSearchInItemClick == null || searchInAction.onSearchInItemClick(item);
90
+ setSearchByParamConfig(void 0);
91
+ searchInAction.onSearchInItemClick?.(item);
131
92
  return;
132
93
  }
133
- handleItemSelect == null || handleItemSelect(item);
94
+ handleItemSelect?.(item);
134
95
  }, [changeSearchQuery, handleItemSelect, searchInAction, searchInItem]);
135
- var itemsLimitPerSection = useMemo(function () {
136
- var _items$limitPerSectio2;
137
- var fallbackLimit = searchQuery ? ITEMS_PER_SECTION_IN_SEARCH : ITEMS_PER_SECTION;
96
+ const itemsLimitPerSection = useMemo(() => {
97
+ const fallbackLimit = searchQuery ? ITEMS_PER_SECTION_IN_SEARCH : ITEMS_PER_SECTION;
138
98
  if (isFixedItemsList) {
139
- var _items$limitPerSectio;
140
- return isItemsConfig(items) ? (_items$limitPerSectio = items.limitPerSection) != null ? _items$limitPerSectio : fallbackLimit : fallbackLimit;
99
+ return isItemsConfig(items) ? items.limitPerSection ?? fallbackLimit : fallbackLimit;
141
100
  }
142
- return (_items$limitPerSectio2 = items.limitPerSection) != null ? _items$limitPerSectio2 : fallbackLimit;
101
+ return items.limitPerSection ?? fallbackLimit;
143
102
  }, [isFixedItemsList, searchQuery, items]);
144
- var _useMemo = useMemo(function () {
145
- if (isListItemsRenderingMode) {
146
- return {
147
- listRenderingMode: RENDER_MODES.LIST_ITEMS
148
- };
149
- }
150
- if (hasSectionsAndFolders) {
151
- if (hasCurrentSection) {
152
- if (!currentSectionHasFolders) {
153
- return {
154
- listRenderingMode: RENDER_MODES.LIST_ITEMS
155
- };
156
- }
103
+ const {
104
+ listRenderingMode
105
+ } = useMemo(() => {
106
+ if (isListItemsRenderingMode) {
107
+ return {
108
+ listRenderingMode: RENDER_MODES.LIST_ITEMS
109
+ };
110
+ }
111
+ if (hasSectionsAndFolders) {
112
+ if (hasCurrentSection) {
113
+ if (!currentSectionHasFolders) {
157
114
  return {
158
- listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
115
+ listRenderingMode: RENDER_MODES.LIST_ITEMS
159
116
  };
160
117
  }
161
- return {
162
- listRenderingMode: hasSearchQuery ? RENDER_MODES.LIST_ITEMS_IN_SECTIONS : RENDER_MODES.LIST_FOLDERS_IN_SECTIONS
163
- };
164
- }
165
- if (hasSections && !hasCurrentSection) {
166
118
  return {
167
119
  listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
168
120
  };
169
121
  }
170
122
  return {
171
- listRenderingMode: RENDER_MODES.LIST_ITEMS
123
+ listRenderingMode: hasSearchQuery ? RENDER_MODES.LIST_ITEMS_IN_SECTIONS : RENDER_MODES.LIST_FOLDERS_IN_SECTIONS
172
124
  };
173
- }, [hasCurrentSection, hasSections, hasSearchQuery, hasSectionsAndFolders, currentSectionHasFolders, isListItemsRenderingMode]),
174
- listRenderingMode = _useMemo.listRenderingMode;
175
- var globalActionsLength = (actions == null ? void 0 : actions.filter(function (action) {
176
- return !action.sectionId;
177
- }).length) || 0;
178
- var recentsLength = (recents == null ? void 0 : recents.length) || 0;
179
- var currentItemsLength = currentItems.length;
180
- var resetCurrentSection = useCallback(function () {
181
- setSearchInAction(undefined);
182
- setSearchInItem(undefined);
183
- setCurrentSection(undefined);
184
- setPreviousSection(undefined);
125
+ }
126
+ if (hasSections && !hasCurrentSection) {
127
+ return {
128
+ listRenderingMode: RENDER_MODES.LIST_ITEMS_IN_SECTIONS
129
+ };
130
+ }
131
+ return {
132
+ listRenderingMode: RENDER_MODES.LIST_ITEMS
133
+ };
134
+ }, [hasCurrentSection, hasSections, hasSearchQuery, hasSectionsAndFolders, currentSectionHasFolders, isListItemsRenderingMode]);
135
+ const globalActionsLength = actions?.filter((action) => !action.sectionId).length || 0;
136
+ const recentsLength = recents?.length || 0;
137
+ const currentItemsLength = currentItems.length;
138
+ const resetCurrentSection = useCallback(() => {
139
+ setSearchInAction(void 0);
140
+ setSearchInItem(void 0);
141
+ setCurrentSection(void 0);
142
+ setPreviousSection(void 0);
185
143
  }, []);
186
- var goBack = useCallback(function () {
144
+ const goBack = useCallback(() => {
187
145
  if (searchByAction) {
188
- setSearchByAction(undefined);
146
+ setSearchByAction(void 0);
189
147
  return;
190
148
  }
191
149
  if (searchInItem) {
192
- changeSearchQuery('');
193
- setSearchByParamConfig(undefined);
194
- setSearchInItem(undefined);
150
+ changeSearchQuery("");
151
+ setSearchByParamConfig(void 0);
152
+ setSearchInItem(void 0);
195
153
  return;
196
154
  }
197
155
  if (searchInAction) {
198
- changeSearchQuery('');
199
- setSearchInAction(undefined);
156
+ changeSearchQuery("");
157
+ setSearchInAction(void 0);
200
158
  return;
201
159
  }
202
160
  if (searchQuery) {
203
161
  setCurrentSection(previousSection);
204
- setPreviousSection(undefined);
162
+ setPreviousSection(void 0);
205
163
  return;
206
164
  }
207
165
  if (parentFolder) {
208
166
  setCurrentSection(parentFolder);
209
167
  return;
210
168
  }
211
- setCurrentSection(undefined);
169
+ setCurrentSection(void 0);
212
170
  }, [searchInAction, searchByAction, searchQuery, parentFolder, previousSection, searchInItem, changeSearchQuery]);
213
- var handleCurrentSectionChange = useCallback(function (section) {
171
+ const handleCurrentSectionChange = useCallback((section) => {
214
172
  setPreviousSection(currentSection);
215
173
  setCurrentSection(section);
216
174
  }, [currentSection]);
217
- var handleSectionChange = useCallback(function (section) {
175
+ const handleSectionChange = useCallback((section) => {
218
176
  handleCurrentSectionChange(section);
219
- onSectionChange == null || onSectionChange(section);
177
+ onSectionChange?.(section);
220
178
  }, [onSectionChange, handleCurrentSectionChange]);
221
- var getLargestSectionHeight = useCallback(function () {
222
- var itemsPerSection = {};
223
- currentItems.forEach(function (item) {
179
+ const getLargestSectionHeight = useCallback(() => {
180
+ const itemsPerSection = {};
181
+ currentItems.forEach((item) => {
224
182
  if (!item.sectionId) {
225
183
  return;
226
184
  }
@@ -233,7 +191,7 @@ export var useItemsInSections = function useItemsInSections(_ref) {
233
191
  itemsPerSection[item.sectionId].items += ITEM_SIZE[itemSizes.DEFAULT];
234
192
  });
235
193
  if (actions) {
236
- actions.forEach(function (item) {
194
+ actions.forEach((item) => {
237
195
  if (!item.sectionId) {
238
196
  return;
239
197
  }
@@ -246,183 +204,131 @@ export var useItemsInSections = function useItemsInSections(_ref) {
246
204
  itemsPerSection[item.sectionId].actions += ITEM_SIZE[itemSizes.DEFAULT];
247
205
  });
248
206
  }
249
- var largestSectionHeight = Object.values(itemsPerSection).reduce(function (maxHeight, sectionData) {
250
- var sectionHeight = sectionData.actions + sectionData.items + (+Boolean(sectionData.actions) + +Boolean(sectionData.items)) * ITEM_SIZE.title;
207
+ const largestSectionHeight = Object.values(itemsPerSection).reduce((maxHeight, sectionData) => {
208
+ const sectionHeight = sectionData.actions + sectionData.items + (+Boolean(sectionData.actions) + +Boolean(sectionData.items)) * ITEM_SIZE.title;
251
209
  return Math.max(maxHeight, sectionHeight);
252
210
  }, 0);
253
211
  return largestSectionHeight + SECTION_HEADER_HEIGHT;
254
212
  }, [currentItems, actions]);
255
- var calculatedContentHeight = useMemo(function () {
213
+ const calculatedContentHeight = useMemo(() => {
256
214
  if (isFixedItemsList && !searchQuery && !activeSectionId) {
257
- var globalActionsHeight = getSectionHeight(globalActionsLength, !!globalActionsLength);
258
- var recentHeight = getSectionHeight(recentsLength, !!recentsLength);
215
+ const globalActionsHeight = getSectionHeight(globalActionsLength, !!globalActionsLength);
216
+ const recentHeight = getSectionHeight(recentsLength, !!recentsLength);
259
217
  if (!hasSections) {
260
- var mainItemsHeight = getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
218
+ const mainItemsHeight = getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
261
219
  return mainItemsHeight + globalActionsHeight + recentHeight;
262
220
  }
263
- var largestSectionHeight = getLargestSectionHeight();
221
+ const largestSectionHeight = getLargestSectionHeight();
264
222
  if (hasSectionsAndFolders) {
265
- var _initialViewHeight = globalActionsHeight + recentHeight + ITEM_SIZE.title * (sections.length + sections.reduce(function (folderCount, section) {
266
- var _section$folders2;
267
- return folderCount + (((_section$folders2 = section.folders) == null ? void 0 : _section$folders2.length) || 0);
268
- }, 0));
269
- return Math.max(_initialViewHeight, largestSectionHeight);
223
+ const initialViewHeight2 = globalActionsHeight + recentHeight + ITEM_SIZE.title * (sections.length + sections.reduce((folderCount, section) => folderCount + (section.folders?.length || 0), 0));
224
+ return Math.max(initialViewHeight2, largestSectionHeight);
270
225
  }
271
- // sections but no folders
272
- var initialViewHeight = globalActionsHeight + recentHeight + ITEM_SIZE.title * sections.length + getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
226
+ const initialViewHeight = globalActionsHeight + recentHeight + ITEM_SIZE.title * sections.length + getSectionHeight(currentItemsLength, showItemsSectionLabel || !!(globalActionsHeight || recentHeight));
273
227
  return Math.max(initialViewHeight, largestSectionHeight);
274
228
  }
275
- return undefined;
229
+ return void 0;
276
230
  }, [isFixedItemsList, searchQuery, activeSectionId, globalActionsLength, recentsLength, hasSections, getLargestSectionHeight, hasSectionsAndFolders, sections, currentItemsLength, showItemsSectionLabel]);
277
- var isSelected = useCallback(function (item) {
231
+ const isSelected = useCallback((item) => {
278
232
  return !!(selectedItem && getItemKey(item) === getItemKey(selectedItem));
279
233
  }, [getItemKey, selectedItem]);
280
- var loadItems = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
281
- var currentRequestId, _yield$items$loadItem, _fetchedItems, meta, fetchedItems, requests, results, _t, _t2, _t3;
282
- return _regenerator().w(function (_context) {
283
- while (1) switch (_context.p = _context.n) {
284
- case 0:
285
- if (!(isFixedItemsList || listActions || searchByAction)) {
286
- _context.n = 1;
287
- break;
288
- }
289
- return _context.a(2);
290
- case 1:
291
- setIsLoading(true);
292
- setIsLoadingError(false);
293
- currentRequestId = crypto.randomUUID();
294
- requestIdRef.current = currentRequestId;
295
- if (!(listRenderingMode === RENDER_MODES.LIST_ITEMS)) {
296
- _context.n = 7;
297
- break;
298
- }
299
- _context.p = 2;
300
- _context.n = 3;
301
- return items.loadItems({
302
- page: FIRST_PAGE,
303
- searchQuery: searchQuery,
304
- sectionId: activeSectionIdWithFallback,
305
- limit: items.limitPerPage || ITEMS_PER_PAGE,
306
- meta: undefined,
307
- abortController: abortControllerRef.current,
308
- searchKey: searchByParamConfig == null ? void 0 : searchByParamConfig.paramKey,
309
- searchInItem: searchInItem
310
- });
311
- case 3:
312
- _yield$items$loadItem = _context.v;
313
- _fetchedItems = _yield$items$loadItem.items;
314
- meta = _yield$items$loadItem.meta;
315
- if (!(currentRequestId !== requestIdRef.current)) {
316
- _context.n = 4;
317
- break;
318
- }
319
- return _context.a(2);
320
- case 4:
321
- setIsLoading(false);
322
- pageToLoad.current = FIRST_PAGE + 1;
323
- metaRef.current[activeSectionIdWithFallback] = meta;
324
- onLoadedData == null || onLoadedData({
325
- sectionId: activeSectionIdWithFallback,
326
- meta: meta,
327
- renderMode: listRenderingMode
328
- });
329
- setIsInitialDataLoaded(true);
330
- setCurrentItems(_fetchedItems);
331
- _context.n = 6;
332
- break;
333
- case 5:
334
- _context.p = 5;
335
- _t = _context.v;
336
- setIsLoading(false);
337
- setIsInitialDataLoaded(true);
338
- setIsLoadingError(true);
339
- case 6:
340
- return _context.a(2);
341
- case 7:
342
- fetchedItems = [];
343
- requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : currentFolders == null ? void 0 : currentFolders.map(function (folder) {
344
- var sectionId = folder.id;
345
- return items.loadItems({
346
- page: FIRST_PAGE,
347
- searchQuery: searchQuery,
348
- limit: (items.limitPerSection || ITEMS_PER_SECTION) + 1,
349
- sectionId: sectionId,
350
- meta: undefined,
351
- abortController: abortControllerRef.current,
352
- searchKey: searchByParamConfig == null ? void 0 : searchByParamConfig.paramKey,
353
- searchInItem: searchInItem
354
- }).then(function (_ref3) {
355
- var sectionItems = _ref3.items,
356
- total = _ref3.total,
357
- meta = _ref3.meta;
358
- onLoadedData == null || onLoadedData({
359
- sectionId: sectionId,
360
- meta: meta,
361
- renderMode: listRenderingMode
362
- });
363
- metaRef.current[folder.id] = meta;
364
- sectionTotals.current[folder.id] = total;
365
- fetchedItems = [].concat(fetchedItems, sectionItems);
366
- });
367
- });
368
- _context.p = 8;
369
- if (!requests) {
370
- _context.n = 10;
371
- break;
372
- }
373
- _context.n = 9;
374
- return Promise.allSettled(requests);
375
- case 9:
376
- _t2 = _context.v;
377
- _context.n = 11;
378
- break;
379
- case 10:
380
- _t2 = [];
381
- case 11:
382
- results = _t2;
383
- if (!(currentRequestId !== requestIdRef.current)) {
384
- _context.n = 12;
385
- break;
386
- }
387
- return _context.a(2);
388
- case 12:
389
- setIsLoading(false);
390
- setIsInitialDataLoaded(true);
391
- if (!results.every(function (result) {
392
- return result.status === 'fulfilled';
393
- })) {
394
- _context.n = 13;
395
- break;
396
- }
397
- setCurrentItems(fetchedItems);
398
- return _context.a(2);
399
- case 13:
400
- setIsLoadingError(true);
401
- _context.n = 15;
402
- break;
403
- case 14:
404
- _context.p = 14;
405
- _t3 = _context.v;
406
- setIsLoading(false);
407
- setIsInitialDataLoaded(true);
408
- setIsLoadingError(true);
409
- case 15:
410
- return _context.a(2);
234
+ const loadItems = useCallback(async () => {
235
+ if (isFixedItemsList || listActions || searchByAction) {
236
+ return;
237
+ }
238
+ setIsLoading(true);
239
+ setIsLoadingError(false);
240
+ const currentRequestId = crypto.randomUUID();
241
+ requestIdRef.current = currentRequestId;
242
+ if (listRenderingMode === RENDER_MODES.LIST_ITEMS) {
243
+ try {
244
+ const {
245
+ items: fetchedItems2,
246
+ meta
247
+ } = await items.loadItems({
248
+ page: FIRST_PAGE,
249
+ searchQuery,
250
+ sectionId: activeSectionIdWithFallback,
251
+ limit: items.limitPerPage || ITEMS_PER_PAGE,
252
+ meta: void 0,
253
+ abortController: abortControllerRef.current,
254
+ searchKey: searchByParamConfig?.paramKey,
255
+ searchInItem
256
+ });
257
+ if (currentRequestId !== requestIdRef.current) {
258
+ return;
259
+ }
260
+ setIsLoading(false);
261
+ pageToLoad.current = FIRST_PAGE + 1;
262
+ metaRef.current[activeSectionIdWithFallback] = meta;
263
+ onLoadedData?.({
264
+ sectionId: activeSectionIdWithFallback,
265
+ meta,
266
+ renderMode: listRenderingMode
267
+ });
268
+ setIsInitialDataLoaded(true);
269
+ setCurrentItems(fetchedItems2);
270
+ } catch (_event) {
271
+ setIsLoading(false);
272
+ setIsInitialDataLoaded(true);
273
+ setIsLoadingError(true);
411
274
  }
412
- }, _callee, null, [[8, 14], [2, 5]]);
413
- })), [searchByParamConfig, isFixedItemsList, currentFolders, listRenderingMode, items, listActions, searchQuery, searchByAction, onLoadedData, activeSectionIdWithFallback, searchInItem]);
414
- useEffect(function () {
275
+ return;
276
+ }
277
+ let fetchedItems = [];
278
+ const requests = listRenderingMode === RENDER_MODES.LIST_FOLDERS_IN_SECTIONS ? [Promise.resolve()] : currentFolders?.map((folder) => {
279
+ const sectionId = folder.id;
280
+ return items.loadItems({
281
+ page: FIRST_PAGE,
282
+ searchQuery,
283
+ limit: (items.limitPerSection || ITEMS_PER_SECTION) + 1,
284
+ sectionId,
285
+ meta: void 0,
286
+ abortController: abortControllerRef.current,
287
+ searchKey: searchByParamConfig?.paramKey,
288
+ searchInItem
289
+ }).then(({
290
+ items: sectionItems,
291
+ total,
292
+ meta
293
+ }) => {
294
+ onLoadedData?.({
295
+ sectionId,
296
+ meta,
297
+ renderMode: listRenderingMode
298
+ });
299
+ metaRef.current[folder.id] = meta;
300
+ sectionTotals.current[folder.id] = total;
301
+ fetchedItems = [...fetchedItems, ...sectionItems];
302
+ });
303
+ });
304
+ try {
305
+ const results = requests ? await Promise.allSettled(requests) : [];
306
+ if (currentRequestId !== requestIdRef.current) {
307
+ return;
308
+ }
309
+ setIsLoading(false);
310
+ setIsInitialDataLoaded(true);
311
+ if (results.every((result) => result.status === "fulfilled")) {
312
+ setCurrentItems(fetchedItems);
313
+ return;
314
+ }
315
+ setIsLoadingError(true);
316
+ } catch (_event) {
317
+ setIsLoading(false);
318
+ setIsInitialDataLoaded(true);
319
+ setIsLoadingError(true);
320
+ }
321
+ }, [searchByParamConfig, isFixedItemsList, currentFolders, listRenderingMode, items, listActions, searchQuery, searchByAction, onLoadedData, activeSectionIdWithFallback, searchInItem]);
322
+ useEffect(() => {
415
323
  if (listActions) {
416
324
  return;
417
325
  }
418
326
  if (isFixedItemsList) {
419
- var allItems = isItemsConfig(items) ? items.items : items;
420
- var itemsInSection = currentSection && !currentSectionHasFolders ? allItems.filter(function (item) {
421
- return item.sectionId === currentSection.id;
422
- }) : allItems;
327
+ const allItems = isItemsConfig(items) ? items.items : items;
328
+ const itemsInSection = currentSection && !currentSectionHasFolders ? allItems.filter((item) => item.sectionId === currentSection.id) : allItems;
423
329
  if (searchQuery) {
424
- var matchingItems = itemsInSection.filter(function (item) {
425
- var matchValue = searchByParamConfig ? String(item[searchByParamConfig.paramKey]) : item.text;
330
+ const matchingItems = itemsInSection.filter((item) => {
331
+ const matchValue = searchByParamConfig ? String(item[searchByParamConfig.paramKey]) : item.text;
426
332
  return matchValue && matchesSearchQuery(matchValue, searchQuery);
427
333
  });
428
334
  setCurrentItems(matchingItems);
@@ -431,7 +337,7 @@ export var useItemsInSections = function useItemsInSections(_ref) {
431
337
  setCurrentItems(itemsInSection);
432
338
  }
433
339
  }, [isFixedItemsList, isLoading, currentSection, isLoadingError, currentSectionHasFolders, currentItemsLength, items, listActions, searchQuery, searchByParamConfig]);
434
- useEffect(function () {
340
+ useEffect(() => {
435
341
  pageToLoad.current = FIRST_PAGE;
436
342
  metaRef.current = {};
437
343
  setIsLoadedAll(false);
@@ -442,34 +348,28 @@ export var useItemsInSections = function useItemsInSections(_ref) {
442
348
  loadItems();
443
349
  }
444
350
  }
445
- return function () {
446
- var _abortControllerRef$c;
447
- (_abortControllerRef$c = abortControllerRef.current) == null || _abortControllerRef$c.abort();
351
+ return () => {
352
+ abortControllerRef.current?.abort();
448
353
  abortControllerRef.current = new AbortController();
449
354
  };
450
- // eslint-disable-next-line react-hooks/exhaustive-deps
451
355
  }, [activeSectionId, isFixedItemsList, searchQuery, listActions, refreshTrigger]);
452
- useEffect(function () {
453
- var timeout;
356
+ useEffect(() => {
357
+ let timeout;
454
358
  if (!hasSearchQuery && !hasCurrentSection && calculatedContentHeight) {
455
- timeout = setTimeout(function () {
456
- return setContentHeight(calculatedContentHeight);
457
- }, 50);
359
+ timeout = setTimeout(() => setContentHeight(calculatedContentHeight), 50);
458
360
  }
459
- return function () {
361
+ return () => {
460
362
  timeout && clearTimeout(timeout);
461
363
  };
462
364
  }, [calculatedContentHeight, hasCurrentSection, hasSearchQuery]);
463
- var hasInfiniteScroll = !listActions && !isFixedItemsList && listRenderingMode === RENDER_MODES.LIST_ITEMS;
464
- var refreshItems = useMemo(function () {
365
+ const hasInfiniteScroll = !listActions && !isFixedItemsList && listRenderingMode === RENDER_MODES.LIST_ITEMS;
366
+ const refreshItems = useMemo(() => {
465
367
  if (!isFixedItemsList) {
466
- return function () {
467
- return setRefreshTrigger(Date.now());
468
- };
368
+ return () => setRefreshTrigger(Date.now());
469
369
  }
470
- return undefined;
370
+ return void 0;
471
371
  }, [isFixedItemsList]);
472
- var handleScrollEndReach = useCallback(function () {
372
+ const handleScrollEndReach = useCallback(() => {
473
373
  if (pageToLoad.current < SECOND_PAGE) {
474
374
  return;
475
375
  }
@@ -481,15 +381,16 @@ export var useItemsInSections = function useItemsInSections(_ref) {
481
381
  items.loadItems({
482
382
  page: pageToLoad.current,
483
383
  limit: items.limitPerPage || ITEMS_PER_PAGE,
484
- searchQuery: searchQuery,
384
+ searchQuery,
485
385
  sectionId: activeSectionIdWithFallback,
486
386
  meta: metaRef.current[activeSectionIdWithFallback],
487
- searchKey: searchByParamConfig == null ? void 0 : searchByParamConfig.paramKey,
488
- searchInItem: searchInItem
489
- }).then(function (_ref4) {
490
- var fetchedItems = _ref4.items,
491
- total = _ref4.total,
492
- meta = _ref4.meta;
387
+ searchKey: searchByParamConfig?.paramKey,
388
+ searchInItem
389
+ }).then(({
390
+ items: fetchedItems,
391
+ total,
392
+ meta
393
+ }) => {
493
394
  sectionTotals.current[activeSectionIdWithFallback] = total;
494
395
  metaRef.current[activeSectionIdWithFallback] = meta;
495
396
  setIsLoadingMore(false);
@@ -498,138 +399,136 @@ export var useItemsInSections = function useItemsInSections(_ref) {
498
399
  setIsLoadedAll(true);
499
400
  }
500
401
  pageToLoad.current += 1;
501
- setCurrentItems([].concat(currentItems, fetchedItems));
502
- })["catch"](function () {
402
+ setCurrentItems([...currentItems, ...fetchedItems]);
403
+ }).catch(() => {
503
404
  setIsLoadingMore(false);
504
405
  setIsLoadingMoreError(true);
505
406
  });
506
407
  }
507
408
  }, [searchByParamConfig, isLoadingMore, hasInfiniteScroll, isLoadedAll, items, searchQuery, currentItems, activeSectionIdWithFallback, searchInItem]);
508
- var mergedItemsList = useMemo(function () {
509
- var isSearchInItemActive = !!searchInItem;
409
+ const mergedItemsList = useMemo(() => {
410
+ const isSearchInItemActive = !!searchInItem;
510
411
  if (searchByAction) {
511
412
  return getSearchByActionItems({
512
413
  action: searchByAction,
513
- setSearchByAction: setSearchByAction,
514
- setSearchByParamConfig: setSearchByParamConfig,
515
- searchQuery: searchQuery,
516
- changeSearchQuery: changeSearchQuery
414
+ setSearchByAction,
415
+ setSearchByParamConfig,
416
+ searchQuery,
417
+ changeSearchQuery
517
418
  });
518
419
  }
519
420
  if (listActions) {
520
421
  return getActionItems({
521
- actions: actions,
522
- texts: texts,
422
+ actions,
423
+ texts,
523
424
  sectionId: activeSectionId,
524
- setSearchByAction: setSearchByAction,
525
- changeSearchQuery: changeSearchQuery,
526
- setSearchInAction: setSearchInAction,
527
- isSearchInItemActive: isSearchInItemActive,
528
- searchByParamConfig: searchByParamConfig,
529
- setSearchByParamConfig: setSearchByParamConfig
425
+ setSearchByAction,
426
+ changeSearchQuery,
427
+ setSearchInAction,
428
+ isSearchInItemActive,
429
+ searchByParamConfig,
430
+ setSearchByParamConfig
530
431
  });
531
432
  }
532
- var sectionActions = getSectionActionItems({
533
- actions: actions,
534
- texts: texts,
535
- searchQuery: searchQuery,
433
+ const sectionActions = getSectionActionItems({
434
+ actions,
435
+ texts,
436
+ searchQuery,
536
437
  sectionId: activeSectionId,
537
- setSearchByAction: setSearchByAction,
538
- changeSearchQuery: changeSearchQuery,
539
- setSearchInAction: setSearchInAction,
540
- isSearchInItemActive: isSearchInItemActive,
541
- searchByParamConfig: searchByParamConfig,
542
- setSearchByParamConfig: setSearchByParamConfig
438
+ setSearchByAction,
439
+ changeSearchQuery,
440
+ setSearchInAction,
441
+ isSearchInItemActive,
442
+ searchByParamConfig,
443
+ setSearchByParamConfig
543
444
  });
544
- var recentItems = activeSectionId || isSearchInItemActive || searchByParamConfig ? [] : getRecentItems({
545
- recents: recents,
546
- texts: texts,
547
- isSelected: isSelected,
548
- searchQuery: searchQuery,
549
- handleItemSelect: handleItemSelect,
445
+ const recentItems = activeSectionId || isSearchInItemActive || searchByParamConfig ? [] : getRecentItems({
446
+ recents,
447
+ texts,
448
+ isSelected,
449
+ searchQuery,
450
+ handleItemSelect,
550
451
  isSearchParam: !!searchByParamConfig
551
452
  });
552
- var folderItems = sections ? getFolderItems({
553
- sections: sections,
554
- handleSectionChange: handleSectionChange
453
+ const folderItems = sections ? getFolderItems({
454
+ sections,
455
+ handleSectionChange
555
456
  }) : [];
556
- var listItems = !isListItemsRenderingMode && currentFolders ? currentFolders.flatMap(function (folder) {
557
- var itemsInFolder = currentItems.filter(function (item) {
558
- return item.sectionId === folder.id;
559
- });
457
+ const listItems = !isListItemsRenderingMode && currentFolders ? currentFolders.flatMap((folder) => {
458
+ const itemsInFolder = currentItems.filter((item) => item.sectionId === folder.id);
560
459
  return getItems({
561
460
  items: itemsInFolder,
562
461
  titlePath: folder.titles,
563
- texts: texts,
564
- searchQuery: searchQuery,
462
+ texts,
463
+ searchQuery,
565
464
  maxItems: itemsLimitPerSection,
566
- showMoreOnClick: function showMoreOnClick() {
567
- return handleSectionChange(folder);
568
- },
569
- showItemsSectionLabel: showItemsSectionLabel,
570
- isSelected: isSelected,
571
- handleItemSelect: handleItemSelect,
465
+ showMoreOnClick: () => handleSectionChange(folder),
466
+ showItemsSectionLabel,
467
+ isSelected,
468
+ handleItemSelect,
572
469
  isSearchParam: !!searchByParamConfig
573
470
  });
574
471
  }) : getItems({
575
472
  items: currentItems,
576
- texts: texts,
577
- searchQuery: searchQuery,
578
- showItemsSectionLabel: showItemsSectionLabel,
579
- isSelected: isSelected,
473
+ texts,
474
+ searchQuery,
475
+ showItemsSectionLabel,
476
+ isSelected,
580
477
  handleItemSelect: handleItemSelectExtended,
581
478
  isSearchParam: !!searchByParamConfig
582
479
  });
583
- var listItemsLength = listItems.length;
584
- var isNoActionsRecentList = isSearchInActionActive || !listItemsLength && isSearchInItemActive;
585
- var composedList = isNoActionsRecentList ? [] : [].concat(sectionActions, recentItems);
480
+ const listItemsLength = listItems.length;
481
+ const isNoActionsRecentList = isSearchInActionActive || !listItemsLength && isSearchInItemActive;
482
+ const composedList = isNoActionsRecentList ? [] : [...sectionActions, ...recentItems];
586
483
  switch (listRenderingMode) {
587
484
  case RENDER_MODES.LIST_ITEMS:
588
- return [].concat(composedList, listItems);
485
+ return [...composedList, ...listItems];
589
486
  case RENDER_MODES.LIST_FOLDERS_IN_SECTIONS:
590
- return [].concat(composedList, folderItems);
487
+ return [...composedList, ...folderItems];
591
488
  case RENDER_MODES.LIST_ITEMS_IN_SECTIONS:
592
489
  default:
593
- return [].concat(composedList, listItems);
490
+ return [...composedList, ...listItems];
594
491
  }
595
492
  }, [listActions, activeSectionId, actions, texts, searchQuery, recents, currentItems, showItemsSectionLabel, sections, currentFolders, itemsLimitPerSection, listRenderingMode, isSelected, handleItemSelect, handleSectionChange, setSearchByParamConfig, searchByAction, searchByParamConfig, changeSearchQuery, handleItemSelectExtended, isSearchInActionActive, searchInItem, isListItemsRenderingMode]);
596
- var reloadActiveSection = useCallback(function () {
597
- var _abortControllerRef$c2;
493
+ const reloadActiveSection = useCallback(() => {
598
494
  pageToLoad.current = FIRST_PAGE;
599
495
  metaRef.current = {};
600
496
  setIsLoadedAll(false);
601
497
  setIsLoadingMore(false);
602
498
  sectionTotals.current = {};
603
- (_abortControllerRef$c2 = abortControllerRef.current) == null || _abortControllerRef$c2.abort();
499
+ abortControllerRef.current?.abort();
604
500
  abortControllerRef.current = new AbortController();
605
501
  if (!listActions) {
606
502
  loadItems();
607
503
  }
608
504
  }, [listActions, loadItems]);
609
505
  return {
610
- currentSection: !listActions ? currentSection : undefined,
611
- currentPath: currentPath,
612
- goBack: goBack,
613
- resetCurrentSection: resetCurrentSection,
506
+ currentSection: !listActions ? currentSection : void 0,
507
+ currentPath,
508
+ goBack,
509
+ resetCurrentSection,
614
510
  setCurrentSection: handleCurrentSectionChange,
615
- mergedItemsList: mergedItemsList,
511
+ mergedItemsList,
616
512
  isLoading: isLoading || !isInitialDataLoaded,
617
- isLoadingMore: isLoadingMore,
618
- isLoadedAll: isLoadedAll,
619
- handleScrollEndReach: handleScrollEndReach,
620
- refreshItems: refreshItems,
621
- isLoadingError: isLoadingError,
622
- isLoadingMoreError: isLoadingMoreError,
623
- contentHeight: contentHeight,
513
+ isLoadingMore,
514
+ isLoadedAll,
515
+ handleScrollEndReach,
516
+ refreshItems,
517
+ isLoadingError,
518
+ isLoadingMoreError,
519
+ contentHeight,
624
520
  refreshEnabled: !listActions,
625
- searchByAction: searchByAction,
626
- searchByParamConfig: searchByParamConfig,
627
- setSearchByParamConfig: setSearchByParamConfig,
628
- listActions: listActions,
629
- searchInItem: searchInItem,
630
- searchInAction: searchInAction,
631
- canPerformListActions: canPerformListActions,
632
- reloadActiveSection: reloadActiveSection,
633
- activeSectionId: activeSectionId
521
+ searchByAction,
522
+ searchByParamConfig,
523
+ setSearchByParamConfig,
524
+ listActions,
525
+ searchInItem,
526
+ searchInAction,
527
+ canPerformListActions,
528
+ reloadActiveSection,
529
+ activeSectionId
634
530
  };
635
- };
531
+ };
532
+ export {
533
+ useItemsInSections
534
+ };