@hitachivantara/app-shell-shared 2.3.0 → 2.3.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.
@@ -1,302 +1,326 @@
1
- import { createContext, useContext, useMemo, useState, useEffect, useRef, useCallback, createElement } from "react";
1
+ import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { useAsync } from "@hitachivantara/app-shell-services";
3
3
  import { useLocation } from "react-router-dom";
4
- const HvAppShellContext = createContext(void 0);
5
- const useHvAppShellConfig = () => {
6
- return useContext(HvAppShellContext);
4
+ //#region src/AppShellContext.tsx
5
+ var HvAppShellContext = createContext(void 0);
6
+ var useHvAppShellConfig = () => {
7
+ return useContext(HvAppShellContext);
7
8
  };
8
- const HvAppShellModelContext = createContext(void 0);
9
- const useHvAppShellModel = () => {
10
- const context = useContext(HvAppShellModelContext);
11
- if (!context) {
12
- throw new Error(
13
- "useHvAppShellModel must be used within HvAppShellModelContext.Provider"
14
- );
15
- }
16
- return context;
9
+ //#endregion
10
+ //#region src/AppShellModelContext.tsx
11
+ var HvAppShellModelContext = createContext(void 0);
12
+ var useHvAppShellModel = () => {
13
+ const context = useContext(HvAppShellModelContext);
14
+ if (!context) throw new Error("useHvAppShellModel must be used within HvAppShellModelContext.Provider");
15
+ return context;
17
16
  };
18
- const HvAppShellViewContext = createContext(void 0);
19
- const HvAppShellRuntimeContext = createContext(void 0);
20
- const useHvAppShellRuntimeContext = () => {
21
- const context = useContext(HvAppShellRuntimeContext);
22
- if (!context) {
23
- throw new Error(
24
- "useHvAppShellRuntimeContext must be used within HvAppShellRuntimeContext.Provider"
25
- );
26
- }
27
- return context;
17
+ //#endregion
18
+ //#region src/AppShellViewContext.tsx
19
+ var HvAppShellViewContext = createContext(void 0);
20
+ //#endregion
21
+ //#region src/AppShellRuntimeContext.tsx
22
+ var HvAppShellRuntimeContext = createContext(void 0);
23
+ var useHvAppShellRuntimeContext = () => {
24
+ const context = useContext(HvAppShellRuntimeContext);
25
+ if (!context) throw new Error("useHvAppShellRuntimeContext must be used within HvAppShellRuntimeContext.Provider");
26
+ return context;
28
27
  };
29
- const HvAppShellCombinedProvidersContext = createContext(void 0);
30
- const useHvAppShellCombinedProviders = () => {
31
- return useContext(
32
- HvAppShellCombinedProvidersContext
33
- );
28
+ //#endregion
29
+ //#region src/AppShellCombinedProvidersContext.tsx
30
+ var HvAppShellCombinedProvidersContext = createContext(void 0);
31
+ var useHvAppShellCombinedProviders = () => {
32
+ return useContext(HvAppShellCombinedProvidersContext);
34
33
  };
35
- const CONFIG_TRANSLATIONS_NAMESPACE = "app";
36
- const HvAppShellI18nContext = createContext(void 0);
37
- const useHvAppShellI18n = () => {
38
- const context = useContext(HvAppShellI18nContext);
39
- if (!context) {
40
- throw new Error(
41
- "useHvAppShellI18n must be used within HvAppShellI18nContext.Provider"
42
- );
43
- }
44
- return context;
34
+ //#endregion
35
+ //#region src/i18n/index.ts
36
+ var CONFIG_TRANSLATIONS_NAMESPACE = "app";
37
+ var HvAppShellI18nContext = createContext(void 0);
38
+ /**
39
+ * Gets the App Shell's I18N context.
40
+ */
41
+ var useHvAppShellI18n = () => {
42
+ const context = useContext(HvAppShellI18nContext);
43
+ if (!context) throw new Error("useHvAppShellI18n must be used within HvAppShellI18nContext.Provider");
44
+ return context;
45
45
  };
46
- const getMenuTargetHref = (menuItem) => {
47
- const { target } = menuItem;
48
- if (target) {
49
- return target;
50
- }
51
- if (menuItem.submenus) {
52
- return getMenuTargetHref(menuItem.submenus[0]);
53
- }
54
- return "";
46
+ //#endregion
47
+ //#region src/utils/navigationUtils.ts
48
+ /**
49
+ * Compute the target href for menu item.
50
+ *
51
+ * @param menuItem The root target href.
52
+ *
53
+ * @returns The menu item target href. If empty, returns the first child that has it defined or empty string if none.
54
+ */
55
+ var getMenuTargetHref = (menuItem) => {
56
+ const { target } = menuItem;
57
+ if (target) return target;
58
+ if (menuItem.submenus) return getMenuTargetHref(menuItem.submenus[0]);
59
+ return "";
55
60
  };
56
- const addPrefixToHref = (href) => {
57
- return !href.startsWith(".") ? `.${href}` : href;
61
+ /**
62
+ * Adds a dot to the href to indicate that it is a relative path.
63
+ */
64
+ var addPrefixToHref = (href) => {
65
+ return !href.startsWith(".") ? `.${href}` : href;
58
66
  };
59
- const createMenuItems = (t, menuItems, maxDepth, parentMenuItem) => {
60
- if (maxDepth !== void 0 && maxDepth <= 0) {
61
- return [];
62
- }
63
- return menuItems?.reduce((accumulator, currentValue, index) => {
64
- const navItem = {
65
- id: parentMenuItem ? `${parentMenuItem.id}-${index}` : `${index}`,
66
- label: t(currentValue.label),
67
- href: addPrefixToHref(getMenuTargetHref(currentValue)),
68
- icon: currentValue.icon,
69
- parent: parentMenuItem
70
- };
71
- if (currentValue.submenus) {
72
- const updatedDepth = maxDepth !== void 0 ? maxDepth - 1 : void 0;
73
- const data = createMenuItems(
74
- t,
75
- currentValue.submenus,
76
- updatedDepth,
77
- navItem
78
- );
79
- if (data.length > 0) {
80
- navItem.data = data;
81
- }
82
- }
83
- accumulator.push(navItem);
84
- return accumulator;
85
- }, []) ?? [];
67
+ /**
68
+ * Creates a navigation data structure ({@link MenuItem}) from the provided menu configuration ({@link HvAppShellMenuConfig}).
69
+ *
70
+ * Note: The menu configuration received here has already been filtered based on conditions.
71
+ *
72
+ * @param t Translation function
73
+ * @param menuItems The set of menu items from configuration (already filtered)
74
+ * @param maxDepth The maximum depth up until the recursiveness should occur for the creation of the menu items
75
+ * @param parentMenuItem The parent menu item of the set of menu items
76
+ *
77
+ * @returns An array of {@link MenuItem}
78
+ */
79
+ var createMenuItems = (t, menuItems, maxDepth, parentMenuItem) => {
80
+ if (maxDepth !== void 0 && maxDepth <= 0) return [];
81
+ return menuItems?.reduce((accumulator, currentValue, index) => {
82
+ const navItem = {
83
+ id: parentMenuItem ? `${parentMenuItem.id}-${index}` : `${index}`,
84
+ label: t(currentValue.label),
85
+ href: addPrefixToHref(getMenuTargetHref(currentValue)),
86
+ icon: currentValue.icon,
87
+ parent: parentMenuItem
88
+ };
89
+ if (currentValue.submenus) {
90
+ const updatedDepth = maxDepth !== void 0 ? maxDepth - 1 : void 0;
91
+ const data = createMenuItems(t, currentValue.submenus, updatedDepth, navItem);
92
+ if (data.length > 0) navItem.data = data;
93
+ }
94
+ accumulator.push(navItem);
95
+ return accumulator;
96
+ }, []) ?? [];
86
97
  };
87
- const flatMenuItems = (items) => {
88
- return items.reduce((acc, item) => {
89
- if (item.data) {
90
- acc.push(...flatMenuItems(item.data));
91
- } else {
92
- acc.push(item);
93
- }
94
- return acc;
95
- }, []);
98
+ /**
99
+ * Removes the items that do not have path and replaces it by its children, recursively.
100
+ *
101
+ * @param items The list of {@link MenuItem}.
102
+ *
103
+ * @returns A flat array of {@link MenuItem}.
104
+ */
105
+ var flatMenuItems = (items) => {
106
+ return items.reduce((acc, item) => {
107
+ if (item.data) acc.push(...flatMenuItems(item.data));
108
+ else acc.push(item);
109
+ return acc;
110
+ }, []);
96
111
  };
97
- const decomposeHrefStringToArray = (normalizedHref) => {
98
- const hrefArray = normalizedHref.split("/").reduce((accumulator, currentValue) => {
99
- if (currentValue === "") {
100
- return accumulator;
101
- }
102
- const prefix = accumulator.length === 0 ? "" : accumulator[0];
103
- const href = currentValue === "." ? currentValue : `${prefix}/${currentValue}`;
104
- accumulator.unshift(href);
105
- return accumulator;
106
- }, []);
107
- hrefArray.push("./");
108
- return hrefArray;
112
+ /**
113
+ * Helper function that uses a cumulative reduction to derive an array of cumulative hrefs based on the components
114
+ * of the input string.
115
+ * @example
116
+ * // returns ['/', '/app', '/app/details', '/app/details/1']
117
+ * // normalizedHref: "/app/details/1"
118
+ *
119
+ * @param normalizedHref The href string to be reduced.
120
+ *
121
+ * @returns the array of cumulative hrefs.
122
+ */
123
+ var decomposeHrefStringToArray = (normalizedHref) => {
124
+ const hrefArray = normalizedHref.split("/").reduce((accumulator, currentValue) => {
125
+ if (currentValue === "") return accumulator;
126
+ const prefix = accumulator.length === 0 ? "" : accumulator[0];
127
+ const href = currentValue === "." ? currentValue : `${prefix}/${currentValue}`;
128
+ accumulator.unshift(href);
129
+ return accumulator;
130
+ }, []);
131
+ hrefArray.push("./");
132
+ return hrefArray;
109
133
  };
110
- const searchHrefMatch = (items, normalizedHref, normalizedFullHref) => {
111
- let toBeSelectedId;
112
- let toBeSelectedHref;
113
- const reducedNormalizedHref = decomposeHrefStringToArray(normalizedHref);
114
- flatMenuItems(items).some((item) => {
115
- let normalizedItemHref;
116
- let normalizedItemHrefParams;
117
- const idx = item.href?.indexOf("?");
118
- if (idx !== -1) {
119
- normalizedItemHref = item.href?.slice(0, idx).toLowerCase();
120
- normalizedItemHrefParams = item.href?.slice(idx).toLowerCase();
121
- } else {
122
- normalizedItemHref = item.href?.toLowerCase();
123
- normalizedItemHrefParams = "";
124
- }
125
- if (normalizedItemHref && normalizedItemHref.length > 1 && normalizedItemHref.endsWith("/")) {
126
- normalizedItemHref = normalizedItemHref.slice(
127
- 0,
128
- normalizedItemHref.length - 1
129
- );
130
- }
131
- const normalizedFullItemHref = `${normalizedItemHref}${normalizedItemHrefParams}`;
132
- if (normalizedFullItemHref === normalizedFullHref) {
133
- toBeSelectedId = item.id;
134
- return true;
135
- }
136
- const matchedHref = reducedNormalizedHref.find(
137
- (href) => normalizedItemHref === href
138
- );
139
- if (matchedHref && (!toBeSelectedHref || matchedHref.length > toBeSelectedHref?.length)) {
140
- toBeSelectedId = item.id;
141
- toBeSelectedHref = matchedHref;
142
- }
143
- return false;
144
- });
145
- return toBeSelectedId;
134
+ /**
135
+ * Algorithm implementation of the searchHrefInMenuItems function.
136
+ *
137
+ * @returns An object containing an item id or empty, if no match is found, and a flag to indicate if a
138
+ * full href match was found. If the id is filled but the flag is 'false', then only partial match was found.
139
+ */
140
+ var searchHrefMatch = (items, normalizedHref, normalizedFullHref) => {
141
+ let toBeSelectedId;
142
+ let toBeSelectedHref;
143
+ const reducedNormalizedHref = decomposeHrefStringToArray(normalizedHref);
144
+ flatMenuItems(items).some((item) => {
145
+ let normalizedItemHref;
146
+ let normalizedItemHrefParams;
147
+ const idx = item.href?.indexOf("?");
148
+ if (idx !== -1) {
149
+ normalizedItemHref = item.href?.slice(0, idx).toLowerCase();
150
+ normalizedItemHrefParams = item.href?.slice(idx).toLowerCase();
151
+ } else {
152
+ normalizedItemHref = item.href?.toLowerCase();
153
+ normalizedItemHrefParams = "";
154
+ }
155
+ if (normalizedItemHref && normalizedItemHref.length > 1 && normalizedItemHref.endsWith("/")) normalizedItemHref = normalizedItemHref.slice(0, normalizedItemHref.length - 1);
156
+ if (`${normalizedItemHref}${normalizedItemHrefParams}` === normalizedFullHref) {
157
+ toBeSelectedId = item.id;
158
+ return true;
159
+ }
160
+ const matchedHref = reducedNormalizedHref.find((href) => normalizedItemHref === href);
161
+ if (matchedHref && (!toBeSelectedHref || matchedHref.length > toBeSelectedHref?.length)) {
162
+ toBeSelectedId = item.id;
163
+ toBeSelectedHref = matchedHref;
164
+ }
165
+ return false;
166
+ });
167
+ return toBeSelectedId;
146
168
  };
147
- const searchHrefInMenuItems = (items, href, parameters) => {
148
- if (!href) {
149
- return void 0;
150
- }
151
- const normalizedHref = href.length > 1 && href.endsWith("/") ? href.slice(0, href.length - 1).toLowerCase() : href.toLowerCase();
152
- const normalizedFullHref = parameters ? normalizedHref.concat(parameters.toLowerCase()) : normalizedHref;
153
- return searchHrefMatch(items, normalizedHref, normalizedFullHref);
169
+ /**
170
+ * Searches for the href and parameters on all the menu items and its children until an exact match is found. If no
171
+ * exact match is found but partial is, then the parent id for the first partial match found is returned.
172
+ * @example
173
+ * // returns '2'
174
+ * // href: '/home', parameters: '?x=y', items: [{id:'1', href:'/home?z=v'},{id:'2', href:'/home'}
175
+ *
176
+ * For consistency purposes and based on the Router behavior, if either the href or the item href
177
+ * (stripped of its query params) ends with a forward slash, then the comparison will ignore it
178
+ * @example
179
+ * // returns '1'
180
+ * // href: '/home/', parameters: <empty>, items: [{id:'1', href:'/home'}]
181
+ *
182
+ * @param items The list of menu items to be searched.
183
+ * @param href The url href after the domain up to the query parameters.
184
+ * @param [parameters] The url query string after pathname.
185
+ *
186
+ * @returns The id of a parent menu item or an empty string.
187
+ */
188
+ var searchHrefInMenuItems = (items, href, parameters) => {
189
+ if (!href) return;
190
+ const normalizedHref = href.length > 1 && href.endsWith("/") ? href.slice(0, href.length - 1).toLowerCase() : href.toLowerCase();
191
+ return searchHrefMatch(items, normalizedHref, parameters ? normalizedHref.concat(parameters.toLowerCase()) : normalizedHref);
154
192
  };
155
- const getRootIdFromItemId = (menuItemId) => {
156
- if (!menuItemId) {
157
- return void 0;
158
- }
159
- return menuItemId.split("-")[0];
193
+ /**
194
+ * Get root menu id from the path (in the format 0-0-0 - id's separated by `-`)
195
+ * @param menuItemId
196
+ * @returns the Id of the first menu or undefined if the provided value is undefined
197
+ */
198
+ var getRootIdFromItemId = (menuItemId) => {
199
+ if (!menuItemId) return;
200
+ return menuItemId.split("-")[0];
160
201
  };
161
- const findItemById = (data, itemId) => {
162
- let foundItem = null;
163
- data.some((obj) => {
164
- const { id: objId, data: childData } = obj;
165
- if (objId === itemId) {
166
- foundItem = obj;
167
- return true;
168
- }
169
- if (childData && childData.length > 0) {
170
- foundItem = findItemById(childData, itemId);
171
- return foundItem !== null;
172
- }
173
- return false;
174
- });
175
- return foundItem;
202
+ /**
203
+ * Searches for an item with the specified id.
204
+ *
205
+ * @param {MenuItem[]} data - The navigation data structure.
206
+ * @param {string} itemId - The item id.
207
+ * @returns The item with matching id.
208
+ */
209
+ var findItemById = (data, itemId) => {
210
+ let foundItem = null;
211
+ data.some((obj) => {
212
+ const { id: objId, data: childData } = obj;
213
+ if (objId === itemId) {
214
+ foundItem = obj;
215
+ return true;
216
+ }
217
+ if (childData && childData.length > 0) {
218
+ foundItem = findItemById(childData, itemId);
219
+ return foundItem !== null;
220
+ }
221
+ return false;
222
+ });
223
+ return foundItem;
176
224
  };
177
- const findFirstLeafItem = (data) => {
178
- let foundItem = null;
179
- data.some((obj) => {
180
- if (!obj.data || obj.data.length === 0) {
181
- foundItem = obj;
182
- return true;
183
- }
184
- foundItem = findFirstLeafItem(obj.data);
185
- return foundItem !== null;
186
- });
187
- return foundItem;
225
+ /**
226
+ * Finds the first leaf item (item with children) inside the received structure.
227
+ *
228
+ * @param {MenuItem[]} data - The navigation data structure.
229
+ * @returns - The first leaf item inside the structure.
230
+ */
231
+ var findFirstLeafItem = (data) => {
232
+ let foundItem = null;
233
+ data.some((obj) => {
234
+ if (!obj.data || obj.data.length === 0) {
235
+ foundItem = obj;
236
+ return true;
237
+ }
238
+ foundItem = findFirstLeafItem(obj.data);
239
+ return foundItem !== null;
240
+ });
241
+ return foundItem;
188
242
  };
189
- const MAX_TOP_MENU_DEPTH = 2;
190
- const useHvMenuItems = () => {
191
- const { pathname, search, state: locationState } = useLocation();
192
- const { navigationMode, menu } = useHvAppShellModel();
193
- useHvAppShellI18n();
194
- const { i18n } = useHvAppShellRuntimeContext();
195
- const resolvedLanguage = i18n.resolvedLanguage;
196
- const tConfig = useMemo(
197
- () => i18n.getFixedT(resolvedLanguage ?? null, CONFIG_TRANSLATIONS_NAMESPACE),
198
- [i18n, resolvedLanguage]
199
- );
200
- const items = useMemo(() => {
201
- const menuItemsDepth = navigationMode === "ONLY_TOP" ? MAX_TOP_MENU_DEPTH : void 0;
202
- return createMenuItems(tConfig, menu, menuItemsDepth);
203
- }, [navigationMode, menu, tConfig]);
204
- const [selectedMenuItemId, setSelectedMenuItemId] = useState(searchHrefInMenuItems(items, addPrefixToHref(pathname), search));
205
- const [rootMenuItemId, setRootMenuItemId] = useState(
206
- getRootIdFromItemId(selectedMenuItemId)
207
- );
208
- useEffect(() => {
209
- if (!items.length) {
210
- return;
211
- }
212
- if (locationState?.selectedItemId) {
213
- setRootMenuItemId(getRootIdFromItemId(locationState.selectedItemId));
214
- const selectedItem = findItemById(items, locationState.selectedItemId);
215
- if (selectedItem?.data?.length) {
216
- const firstItemToSelect = findFirstLeafItem(selectedItem.data);
217
- setSelectedMenuItemId(firstItemToSelect?.id);
218
- } else {
219
- setSelectedMenuItemId(selectedItem?.id);
220
- }
221
- return;
222
- }
223
- const toBeSelected = searchHrefInMenuItems(
224
- items,
225
- addPrefixToHref(pathname),
226
- search
227
- );
228
- if (toBeSelected) {
229
- setRootMenuItemId(getRootIdFromItemId(toBeSelected));
230
- setSelectedMenuItemId(toBeSelected);
231
- return;
232
- }
233
- setRootMenuItemId(void 0);
234
- setSelectedMenuItemId(void 0);
235
- }, [items, locationState, pathname, search]);
236
- return {
237
- items,
238
- selectedMenuItemId,
239
- rootMenuItemId
240
- };
243
+ //#endregion
244
+ //#region src/hooks/useMenuItems.tsx
245
+ var MAX_TOP_MENU_DEPTH = 2;
246
+ var useHvMenuItems = () => {
247
+ const { pathname, search, state: locationState } = useLocation();
248
+ const { navigationMode, menu } = useHvAppShellModel();
249
+ useHvAppShellI18n();
250
+ const { i18n } = useHvAppShellRuntimeContext();
251
+ const resolvedLanguage = i18n.resolvedLanguage;
252
+ const tConfig = useMemo(() => i18n.getFixedT(resolvedLanguage ?? null, "app"), [i18n, resolvedLanguage]);
253
+ const items = useMemo(() => {
254
+ return createMenuItems(tConfig, menu, navigationMode === "ONLY_TOP" ? MAX_TOP_MENU_DEPTH : void 0);
255
+ }, [
256
+ navigationMode,
257
+ menu,
258
+ tConfig
259
+ ]);
260
+ const [selectedMenuItemId, setSelectedMenuItemId] = useState(searchHrefInMenuItems(items, addPrefixToHref(pathname), search));
261
+ const [rootMenuItemId, setRootMenuItemId] = useState(getRootIdFromItemId(selectedMenuItemId));
262
+ useEffect(() => {
263
+ if (!items.length) return;
264
+ if (locationState?.selectedItemId) {
265
+ setRootMenuItemId(getRootIdFromItemId(locationState.selectedItemId));
266
+ const selectedItem = findItemById(items, locationState.selectedItemId);
267
+ if (selectedItem?.data?.length) setSelectedMenuItemId(findFirstLeafItem(selectedItem.data)?.id);
268
+ else setSelectedMenuItemId(selectedItem?.id);
269
+ return;
270
+ }
271
+ const toBeSelected = searchHrefInMenuItems(items, addPrefixToHref(pathname), search);
272
+ if (toBeSelected) {
273
+ setRootMenuItemId(getRootIdFromItemId(toBeSelected));
274
+ setSelectedMenuItemId(toBeSelected);
275
+ return;
276
+ }
277
+ setRootMenuItemId(void 0);
278
+ setSelectedMenuItemId(void 0);
279
+ }, [
280
+ items,
281
+ locationState,
282
+ pathname,
283
+ search
284
+ ]);
285
+ return {
286
+ items,
287
+ selectedMenuItemId,
288
+ rootMenuItemId
289
+ };
241
290
  };
242
- const generateKey = () => {
243
- return `hooks-${Date.now()}-${Math.round(1e3 * Math.random())}`;
291
+ //#endregion
292
+ //#region src/components/DynamicHooksEvaluator/DynamicHooksEvaluator.tsx
293
+ var generateKey = () => {
294
+ return `hooks-${Date.now()}-${Math.round(1e3 * Math.random())}`;
244
295
  };
245
- const DynamicHooksEvaluatorInner = ({
246
- hooks,
247
- onEvaluate
248
- }) => {
249
- const results = [];
250
- for (const { hook, params = [] } of hooks) {
251
- const result = hook(...params);
252
- results.push(result);
253
- }
254
- useEffect(() => onEvaluate(results), []);
255
- return null;
296
+ var DynamicHooksEvaluatorInner = ({ hooks, onEvaluate }) => {
297
+ const results = [];
298
+ for (const { hook, params = [] } of hooks) {
299
+ const result = hook(...params);
300
+ results.push(result);
301
+ }
302
+ useEffect(() => onEvaluate(results), []);
303
+ return null;
256
304
  };
257
- const DynamicHooksEvaluator = ({
258
- hooks,
259
- onEvaluate
260
- }) => {
261
- const skipRenderRef = useRef(false);
262
- const keyRef = useRef(generateKey());
263
- const hooksRef = useRef(hooks);
264
- if (hooksRef.current !== hooks) {
265
- skipRenderRef.current = false;
266
- hooksRef.current = hooks;
267
- }
268
- if (skipRenderRef.current) {
269
- skipRenderRef.current = false;
270
- } else {
271
- keyRef.current = generateKey();
272
- }
273
- const onEvaluateWrapper = useCallback(
274
- (results) => {
275
- skipRenderRef.current = true;
276
- onEvaluate(results);
277
- },
278
- [onEvaluate]
279
- );
280
- return createElement(DynamicHooksEvaluatorInner, {
281
- key: keyRef.current,
282
- hooks,
283
- onEvaluate: onEvaluateWrapper
284
- });
285
- };
286
- export {
287
- CONFIG_TRANSLATIONS_NAMESPACE,
288
- DynamicHooksEvaluator,
289
- HvAppShellCombinedProvidersContext,
290
- HvAppShellContext,
291
- HvAppShellI18nContext,
292
- HvAppShellModelContext,
293
- HvAppShellRuntimeContext,
294
- HvAppShellViewContext,
295
- useAsync,
296
- useHvAppShellCombinedProviders,
297
- useHvAppShellConfig,
298
- useHvAppShellI18n,
299
- useHvAppShellModel,
300
- useHvAppShellRuntimeContext,
301
- useHvMenuItems
305
+ var DynamicHooksEvaluator = ({ hooks, onEvaluate }) => {
306
+ const skipRenderRef = useRef(false);
307
+ const keyRef = useRef(generateKey());
308
+ const hooksRef = useRef(hooks);
309
+ if (hooksRef.current !== hooks) {
310
+ skipRenderRef.current = false;
311
+ hooksRef.current = hooks;
312
+ }
313
+ if (skipRenderRef.current) skipRenderRef.current = false;
314
+ else keyRef.current = generateKey();
315
+ const onEvaluateWrapper = useCallback((results) => {
316
+ skipRenderRef.current = true;
317
+ onEvaluate(results);
318
+ }, [onEvaluate]);
319
+ return createElement(DynamicHooksEvaluatorInner, {
320
+ key: keyRef.current,
321
+ hooks,
322
+ onEvaluate: onEvaluateWrapper
323
+ });
302
324
  };
325
+ //#endregion
326
+ export { CONFIG_TRANSLATIONS_NAMESPACE, DynamicHooksEvaluator, HvAppShellCombinedProvidersContext, HvAppShellContext, HvAppShellI18nContext, HvAppShellModelContext, HvAppShellRuntimeContext, HvAppShellViewContext, useAsync, useHvAppShellCombinedProviders, useHvAppShellConfig, useHvAppShellI18n, useHvAppShellModel, useHvAppShellRuntimeContext, useHvMenuItems };