@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.
- package/dist/AppShellCombinedProvidersContext.js +6 -9
- package/dist/AppShellContext.js +6 -7
- package/dist/AppShellModelContext.js +8 -13
- package/dist/AppShellRuntimeContext.js +8 -13
- package/dist/AppShellViewContext.js +4 -4
- package/dist/bundles/app-shell-shared.esm.js +305 -281
- package/dist/components/DynamicHooksEvaluator/DynamicHooksEvaluator.js +33 -45
- package/dist/hooks/useMenuItems.js +52 -59
- package/dist/i18n/index.js +12 -15
- package/dist/index.js +2 -18
- package/dist/utils/navigationUtils.js +188 -141
- package/package.json +8 -5
|
@@ -1,302 +1,326 @@
|
|
|
1
|
-
import { createContext,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
//#region src/AppShellContext.tsx
|
|
5
|
+
var HvAppShellContext = createContext(void 0);
|
|
6
|
+
var useHvAppShellConfig = () => {
|
|
7
|
+
return useContext(HvAppShellContext);
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/AppShellCombinedProvidersContext.tsx
|
|
30
|
+
var HvAppShellCombinedProvidersContext = createContext(void 0);
|
|
31
|
+
var useHvAppShellCombinedProviders = () => {
|
|
32
|
+
return useContext(HvAppShellCombinedProvidersContext);
|
|
34
33
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
243
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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 };
|