@olenbetong/synergi-react 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/AppMenu/AppMenu.css +0 -25
- package/es/components/AppMenu/AppMenu.js +1 -2
- package/es/components/AppMenu/index.d.ts +0 -1
- package/es/components/AppMenu/index.js +0 -1
- package/es/index.d.ts +1 -2
- package/es/index.js +1 -2
- package/package.json +3 -3
- package/src/colorScheme.ts +81 -81
- package/src/components/AppMenu/AppMenu.css +648 -546
- package/src/components/AppMenu/AppMenu.tsx +285 -478
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -41
- package/src/components/AppMenu/AppMenuFavoriteButton.tsx +47 -0
- package/src/components/AppMenu/AppMenuHeader.tsx +79 -0
- package/src/components/AppMenu/AppMenuList.tsx +89 -0
- package/src/components/AppMenu/AppMenuRail.tsx +117 -0
- package/src/components/AppMenu/icons.tsx +76 -0
- package/src/components/AppMenu/index.ts +17 -12
- package/src/components/AppMenu/menuEntries.ts +128 -0
- package/src/components/AppMenu/types.ts +45 -35
- package/src/components/AppMenu/useFavorites.ts +40 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +130 -118
- package/src/components/AppShell/index.tsx +287 -259
- package/src/components/LinkedCardList/index.scss +93 -93
- package/src/components/ProgressBar/index.scss +94 -94
- package/src/index.ts +61 -61
- package/es/colorScheme.d.ts +0 -17
- package/es/colorScheme.js +0 -54
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +0 -2
- package/es/components/AppMenu/AppMenuColorScheme.js +0 -18
|
@@ -1,478 +1,285 @@
|
|
|
1
|
-
import "./AppMenu.css";
|
|
2
|
-
|
|
3
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
-
import type { DataObject } from "@olenbetong/appframe-data";
|
|
5
|
-
import { useData, useLoading } from "@olenbetong/appframe-react";
|
|
6
|
-
import clsx from "clsx";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
let
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
{item.label}
|
|
287
|
-
</a>
|
|
288
|
-
) : (
|
|
289
|
-
<button {...props} type="button" onClick={activate}>
|
|
290
|
-
{item.label}
|
|
291
|
-
</button>
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return (
|
|
296
|
-
<dialog
|
|
297
|
-
ref={dialogRef}
|
|
298
|
-
id={id}
|
|
299
|
-
className={clsx("ob-app-menu", className)}
|
|
300
|
-
aria-label={getLocalizedString("Applications")}
|
|
301
|
-
data-pane={mobilePane}
|
|
302
|
-
onCancel={(event) => {
|
|
303
|
-
// Let React own the open state instead of the browser's default close.
|
|
304
|
-
event.preventDefault();
|
|
305
|
-
onClose();
|
|
306
|
-
}}
|
|
307
|
-
onKeyDown={(event) => {
|
|
308
|
-
// A `type="search"` input consumes Escape to clear itself, so the
|
|
309
|
-
// dialog's own cancel event never fires when the search has focus.
|
|
310
|
-
if (event.key === "Escape") {
|
|
311
|
-
event.preventDefault();
|
|
312
|
-
onClose();
|
|
313
|
-
}
|
|
314
|
-
}}
|
|
315
|
-
onClick={(event) => {
|
|
316
|
-
// Clicks on the dialog element itself are backdrop clicks; anything
|
|
317
|
-
// inside the menu is caught by the inner wrapper below.
|
|
318
|
-
if (event.target === dialogRef.current) onClose();
|
|
319
|
-
}}
|
|
320
|
-
>
|
|
321
|
-
<div className="ob-app-menu__panel">
|
|
322
|
-
<div className="ob-app-menu__rail">
|
|
323
|
-
<div className="ds-search ob-app-menu__search" data-size="sm">
|
|
324
|
-
<input
|
|
325
|
-
ref={searchRef}
|
|
326
|
-
className="ds-input"
|
|
327
|
-
type="search"
|
|
328
|
-
value={search}
|
|
329
|
-
onChange={(event) => setSearch(event.target.value)}
|
|
330
|
-
placeholder={getLocalizedString("Search applications")}
|
|
331
|
-
aria-label={getLocalizedString("Search applications")}
|
|
332
|
-
autoComplete="off"
|
|
333
|
-
/>
|
|
334
|
-
</div>
|
|
335
|
-
|
|
336
|
-
<nav
|
|
337
|
-
className="ob-app-menu__groups"
|
|
338
|
-
aria-label={getLocalizedString("Categories")}
|
|
339
|
-
onKeyDown={groupRoving.onKeyDown}
|
|
340
|
-
>
|
|
341
|
-
<button
|
|
342
|
-
type="button"
|
|
343
|
-
className="ob-app-menu__group-button"
|
|
344
|
-
aria-current={activeSelection === null ? "true" : undefined}
|
|
345
|
-
onClick={() => select(null)}
|
|
346
|
-
{...groupRoving.getItemProps(0)}
|
|
347
|
-
>
|
|
348
|
-
<span>{getLocalizedString("All applications")}</span>
|
|
349
|
-
<span className="ob-app-menu__count">{searchMatches.length}</span>
|
|
350
|
-
</button>
|
|
351
|
-
{groups.map(([group, items], index) => (
|
|
352
|
-
<button
|
|
353
|
-
key={group}
|
|
354
|
-
type="button"
|
|
355
|
-
className="ob-app-menu__group-button"
|
|
356
|
-
aria-current={isSelected({ type: "group", key: group }) ? "true" : undefined}
|
|
357
|
-
onClick={() => select({ type: "group", key: group })}
|
|
358
|
-
{...groupRoving.getItemProps(index + 1)}
|
|
359
|
-
>
|
|
360
|
-
<span>{groupLabel(group)}</span>
|
|
361
|
-
<span className="ob-app-menu__count">{items.length}</span>
|
|
362
|
-
</button>
|
|
363
|
-
))}
|
|
364
|
-
|
|
365
|
-
{railSections.map(([section, sectionCategories]) => (
|
|
366
|
-
<Fragment key={section || "\u0000default"}>
|
|
367
|
-
{section && <h2 className="ob-app-menu__rail-heading">{section}</h2>}
|
|
368
|
-
{sectionCategories.map((category) => {
|
|
369
|
-
// The rail tab stops are "All applications", then the app
|
|
370
|
-
// groups, then the categories, in that order.
|
|
371
|
-
categoryIndex += 1;
|
|
372
|
-
let railIndex = categoryIndex;
|
|
373
|
-
return (
|
|
374
|
-
<button
|
|
375
|
-
key={category.id}
|
|
376
|
-
type="button"
|
|
377
|
-
className="ob-app-menu__group-button"
|
|
378
|
-
aria-current={isSelected({ type: "category", id: category.id }) ? "true" : undefined}
|
|
379
|
-
onClick={() => select({ type: "category", id: category.id })}
|
|
380
|
-
{...groupRoving.getItemProps(railIndex)}
|
|
381
|
-
>
|
|
382
|
-
<span>{category.label}</span>
|
|
383
|
-
<span className="ob-app-menu__count">{countItems(category)}</span>
|
|
384
|
-
</button>
|
|
385
|
-
);
|
|
386
|
-
})}
|
|
387
|
-
</Fragment>
|
|
388
|
-
))}
|
|
389
|
-
</nav>
|
|
390
|
-
|
|
391
|
-
<AppMenuColorScheme />
|
|
392
|
-
</div>
|
|
393
|
-
|
|
394
|
-
<div className="ob-app-menu__content">
|
|
395
|
-
{isLoading && !hasApps && !activeCategory && (
|
|
396
|
-
<p className="ob-app-menu__message">{getLocalizedString("Loading...")}</p>
|
|
397
|
-
)}
|
|
398
|
-
|
|
399
|
-
{!isLoading && paneItemCount === 0 && (
|
|
400
|
-
<p className="ob-app-menu__message">{getLocalizedString("No applications found")}</p>
|
|
401
|
-
)}
|
|
402
|
-
|
|
403
|
-
{paneItemCount > 0 && (
|
|
404
|
-
<div className="ob-app-menu__columns" onKeyDown={appRoving.onKeyDown}>
|
|
405
|
-
{paneGroups.map((group, groupIdx) => (
|
|
406
|
-
<section key={group.title ?? groupIdx} className="ob-app-menu__group">
|
|
407
|
-
{group.title && <h2 className="ob-app-menu__group-title">{group.title}</h2>}
|
|
408
|
-
<ul className="ob-app-menu__list">
|
|
409
|
-
{group.items.map((item) => {
|
|
410
|
-
itemIndex += 1;
|
|
411
|
-
return <li key={item.href ?? item.label}>{renderItem(item, itemIndex)}</li>;
|
|
412
|
-
})}
|
|
413
|
-
</ul>
|
|
414
|
-
</section>
|
|
415
|
-
))}
|
|
416
|
-
</div>
|
|
417
|
-
)}
|
|
418
|
-
|
|
419
|
-
{/*
|
|
420
|
-
* Rendered after the app list so it comes last in the tab order, and
|
|
421
|
-
* moved back to the top visually with `order: -1`.
|
|
422
|
-
*/}
|
|
423
|
-
<div className="ob-app-menu__content-header">
|
|
424
|
-
<button
|
|
425
|
-
type="button"
|
|
426
|
-
className="ob-app-menu__pane-toggle"
|
|
427
|
-
onClick={() => setMobilePane(mobilePane === "apps" ? "groups" : "apps")}
|
|
428
|
-
>
|
|
429
|
-
{mobilePane === "apps" ? getLocalizedString("Categories") : getLocalizedString("Applications")}
|
|
430
|
-
</button>
|
|
431
|
-
{hasUpdate && (
|
|
432
|
-
<button
|
|
433
|
-
type="button"
|
|
434
|
-
className="ob-app-menu__update"
|
|
435
|
-
aria-label={getLocalizedString("Install update and reload")}
|
|
436
|
-
onClick={onInstallUpdate}
|
|
437
|
-
>
|
|
438
|
-
<svg
|
|
439
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
440
|
-
viewBox="0 0 24 24"
|
|
441
|
-
fill="currentColor"
|
|
442
|
-
aria-hidden="true"
|
|
443
|
-
focusable="false"
|
|
444
|
-
width="18"
|
|
445
|
-
height="18"
|
|
446
|
-
>
|
|
447
|
-
<path d="M12 4a8 8 0 0 1 7.5 5.2.75.75 0 1 1-1.4.5A6.5 6.5 0 0 0 6.2 9.25H8.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10V6.25a.75.75 0 0 1 1.5 0v1.86A8 8 0 0 1 12 4m-7.6 9.55a.75.75 0 0 1 .95.45A6.5 6.5 0 0 0 17.8 14.75H15.5a.75.75 0 0 1 0-1.5h3.75a.75.75 0 0 1 .75.75V17.75a.75.75 0 0 1-1.5 0v-1.86A8 8 0 0 1 4.5 14.5a.75.75 0 0 1 .45-.95z" />
|
|
448
|
-
</svg>
|
|
449
|
-
<span className="ob-app-menu__update-label">{getLocalizedString("Install update and reload")}</span>
|
|
450
|
-
</button>
|
|
451
|
-
)}
|
|
452
|
-
{userDataObject && (
|
|
453
|
-
<AppMenuUserMenu dataObject={userDataObject} items={userMenuItems} subtitle={userSubtitle} />
|
|
454
|
-
)}
|
|
455
|
-
<button
|
|
456
|
-
type="button"
|
|
457
|
-
className="ob-app-menu__close"
|
|
458
|
-
aria-label={getLocalizedString("Close")}
|
|
459
|
-
onClick={onClose}
|
|
460
|
-
>
|
|
461
|
-
<svg
|
|
462
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
463
|
-
viewBox="0 0 24 24"
|
|
464
|
-
fill="currentColor"
|
|
465
|
-
aria-hidden="true"
|
|
466
|
-
focusable="false"
|
|
467
|
-
width="20"
|
|
468
|
-
height="20"
|
|
469
|
-
>
|
|
470
|
-
<path d="M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z" />
|
|
471
|
-
</svg>
|
|
472
|
-
</button>
|
|
473
|
-
</div>
|
|
474
|
-
</div>
|
|
475
|
-
</div>
|
|
476
|
-
</dialog>
|
|
477
|
-
);
|
|
478
|
-
}
|
|
1
|
+
import "./AppMenu.css";
|
|
2
|
+
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
5
|
+
import { useData, useLoading } from "@olenbetong/appframe-react";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
|
|
9
|
+
import { AppMenuHeader } from "./AppMenuHeader.js";
|
|
10
|
+
import { AppMenuList } from "./AppMenuList.js";
|
|
11
|
+
import { AppMenuRail } from "./AppMenuRail.js";
|
|
12
|
+
import type { AppMenuUser } from "./AppMenuUserMenu.js";
|
|
13
|
+
import {
|
|
14
|
+
type AppMenuArticle,
|
|
15
|
+
countItems,
|
|
16
|
+
FAVORITES,
|
|
17
|
+
filterCategory,
|
|
18
|
+
groupEntries,
|
|
19
|
+
groupLabel,
|
|
20
|
+
type Selection,
|
|
21
|
+
toAppEntries,
|
|
22
|
+
} from "./menuEntries.js";
|
|
23
|
+
import type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
24
|
+
import { useFavorites } from "./useFavorites.js";
|
|
25
|
+
|
|
26
|
+
export type { AppMenuArticle } from "./menuEntries.js";
|
|
27
|
+
|
|
28
|
+
export type AppMenuProps = {
|
|
29
|
+
/** Data object returning the articles to list. See `AppMenuArticle` for the required fields. */
|
|
30
|
+
dataObject: DataObject<AppMenuArticle>;
|
|
31
|
+
/** Whether the menu is open. The menu is a controlled component. */
|
|
32
|
+
open: boolean;
|
|
33
|
+
/** Called when the menu requests to be closed (backdrop click, Escape, app selected). */
|
|
34
|
+
onClose: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Extra categories listed below the app categories in the rail, showing a
|
|
37
|
+
* fixed set of links instead of apps. See `createDeveloperCategories`.
|
|
38
|
+
*/
|
|
39
|
+
categories?: AppMenuCategory[];
|
|
40
|
+
/** Data object over `aviw_General_SidebarUserInfo`. Enables the user menu in the header. */
|
|
41
|
+
userDataObject?: DataObject<AppMenuUser>;
|
|
42
|
+
/** Overrides the default user menu entries. */
|
|
43
|
+
userMenuItems?: AppMenuLink[];
|
|
44
|
+
/**
|
|
45
|
+
* Called when the favorite toggle next to an app is activated. Without this
|
|
46
|
+
* handler no favorite toggles are rendered.
|
|
47
|
+
*
|
|
48
|
+
* `id` is the version-less ArticleId. The menu updates its own state
|
|
49
|
+
* optimistically and rolls back if the promise rejects.
|
|
50
|
+
*/
|
|
51
|
+
onToggleFavorite?: (id: string, favorite: boolean) => void | Promise<unknown>;
|
|
52
|
+
/**
|
|
53
|
+
* Link shown at the start of the content header, e.g. the portal/front page,
|
|
54
|
+
* which isn't part of the app list. Omit it when already on that page.
|
|
55
|
+
*/
|
|
56
|
+
homeLink?: AppMenuLink;
|
|
57
|
+
/** Shown below the user's name. Defaults to `af.userSession.domain`. */
|
|
58
|
+
userSubtitle?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Shows a highlighted "install update" button in the menu header. Pair with
|
|
61
|
+
* `useServiceWorkerUpdate()`.
|
|
62
|
+
*/
|
|
63
|
+
hasUpdate?: boolean;
|
|
64
|
+
/** Called when the install update button is pressed. */
|
|
65
|
+
onInstallUpdate?: () => void;
|
|
66
|
+
id?: string;
|
|
67
|
+
className?: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Two pane application menu. The left rail holds a local search field and the
|
|
72
|
+
* list of app categories (`MenuGroup`); the right pane lists the apps in the
|
|
73
|
+
* selected category, or every app when no category is selected.
|
|
74
|
+
*
|
|
75
|
+
* On narrow viewports only one pane is visible at a time, defaulting to the app
|
|
76
|
+
* list, with a button to switch to the category list.
|
|
77
|
+
*/
|
|
78
|
+
export function AppMenu({
|
|
79
|
+
dataObject,
|
|
80
|
+
open,
|
|
81
|
+
onClose,
|
|
82
|
+
categories = [],
|
|
83
|
+
userDataObject,
|
|
84
|
+
userMenuItems,
|
|
85
|
+
userSubtitle,
|
|
86
|
+
onToggleFavorite,
|
|
87
|
+
homeLink,
|
|
88
|
+
hasUpdate = false,
|
|
89
|
+
onInstallUpdate,
|
|
90
|
+
id,
|
|
91
|
+
className,
|
|
92
|
+
}: AppMenuProps) {
|
|
93
|
+
let dialogRef = useRef<HTMLDialogElement>(null);
|
|
94
|
+
let searchRef = useRef<HTMLInputElement>(null);
|
|
95
|
+
let [search, setSearch] = useState("");
|
|
96
|
+
let [selection, setSelection] = useState<Selection>(null);
|
|
97
|
+
let [mobilePane, setMobilePane] = useState<"apps" | "groups">("apps");
|
|
98
|
+
let [hasLoaded, setHasLoaded] = useState(false);
|
|
99
|
+
/*
|
|
100
|
+
* True once the initial category has been decided, either by the menu picking
|
|
101
|
+
* the favorites when the apps arrive, or by the user picking one themselves.
|
|
102
|
+
* Without it the menu would jump to the favorites group the moment the first
|
|
103
|
+
* favorite is added.
|
|
104
|
+
*/
|
|
105
|
+
let [hasResolvedSelection, setHasResolvedSelection] = useState(false);
|
|
106
|
+
|
|
107
|
+
let isLoading = useLoading(dataObject);
|
|
108
|
+
let articles = useData<AppMenuArticle>(dataObject);
|
|
109
|
+
let { applyOverrides, toggleFavorite } = useFavorites(onToggleFavorite);
|
|
110
|
+
|
|
111
|
+
// Sync the native dialog with the `open` prop. Using showModal() puts the
|
|
112
|
+
// dialog in the top layer so it renders above the toolbar and page content.
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
let dialog = dialogRef.current;
|
|
115
|
+
if (!dialog) return;
|
|
116
|
+
|
|
117
|
+
if (open && !dialog.open) {
|
|
118
|
+
dialog.showModal();
|
|
119
|
+
requestAnimationFrame(() => searchRef.current?.focus());
|
|
120
|
+
} else if (!open && dialog.open) {
|
|
121
|
+
dialog.close();
|
|
122
|
+
}
|
|
123
|
+
}, [open]);
|
|
124
|
+
|
|
125
|
+
// Reset transient state whenever the menu is closed.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!open) {
|
|
128
|
+
setSearch("");
|
|
129
|
+
setSelection(null);
|
|
130
|
+
setMobilePane("apps");
|
|
131
|
+
setHasResolvedSelection(false);
|
|
132
|
+
}
|
|
133
|
+
}, [open]);
|
|
134
|
+
|
|
135
|
+
// Load the app list the first time the menu is opened.
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (open && !hasLoaded) {
|
|
138
|
+
setHasLoaded(true);
|
|
139
|
+
dataObject.refreshDataSource();
|
|
140
|
+
userDataObject?.refreshDataSource();
|
|
141
|
+
}
|
|
142
|
+
}, [open, hasLoaded, dataObject, userDataObject]);
|
|
143
|
+
|
|
144
|
+
let entries = useMemo(() => applyOverrides(toAppEntries(articles)), [articles, applyOverrides]);
|
|
145
|
+
let term = search.trim().toLowerCase();
|
|
146
|
+
|
|
147
|
+
let searchMatches = useMemo(() => {
|
|
148
|
+
if (!term) return entries;
|
|
149
|
+
return entries.filter((entry) => entry.title.toLowerCase().includes(term) || entry.id.toLowerCase().includes(term));
|
|
150
|
+
}, [entries, term]);
|
|
151
|
+
|
|
152
|
+
let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
|
|
153
|
+
let visibleCategories = useMemo(
|
|
154
|
+
() => categories.map((category) => filterCategory(category, term)).filter((category) => countItems(category) > 0),
|
|
155
|
+
[categories, term],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
let hasFavorites = groups.length > 0 && groups[0][0] === FAVORITES;
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
* The favorites are the most likely target, so select them by default. The
|
|
162
|
+
* article list loads asynchronously, so this can't be done when opening the
|
|
163
|
+
* menu — it has to wait until the apps have arrived. It only ever runs once
|
|
164
|
+
* per open, so favoriting an app doesn't move the user to another group.
|
|
165
|
+
*/
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!open || hasResolvedSelection || entries.length === 0) return;
|
|
168
|
+
|
|
169
|
+
setHasResolvedSelection(true);
|
|
170
|
+
if (hasFavorites) setSelection({ type: "group", key: FAVORITES });
|
|
171
|
+
}, [open, hasResolvedSelection, entries.length, hasFavorites]);
|
|
172
|
+
|
|
173
|
+
// A selection that no longer has matches falls back to "all apps" so the pane
|
|
174
|
+
// never ends up empty while results exist elsewhere.
|
|
175
|
+
let activeSelection: Selection = null;
|
|
176
|
+
if (selection?.type === "group" && groups.some(([group]) => group === selection.key)) activeSelection = selection;
|
|
177
|
+
else if (selection?.type === "category" && visibleCategories.some((category) => category.id === selection.id)) {
|
|
178
|
+
activeSelection = selection;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let activeCategoryId = activeSelection?.type === "category" ? activeSelection.id : null;
|
|
182
|
+
let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
|
|
183
|
+
let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
|
|
184
|
+
|
|
185
|
+
// Everything the right hand pane renders, normalized to titled link groups.
|
|
186
|
+
// The favorites are left out of the "all apps" pane, since those apps are
|
|
187
|
+
// already listed in their own group.
|
|
188
|
+
let paneGroups: AppMenuLinkGroup[] = useMemo(() => {
|
|
189
|
+
if (activeCategory) return activeCategory.groups;
|
|
190
|
+
|
|
191
|
+
return groups
|
|
192
|
+
.filter(([group]) => (activeGroupKey === null ? group !== FAVORITES : group === activeGroupKey))
|
|
193
|
+
.map(([group, items]) => ({
|
|
194
|
+
title: groupLabel(group),
|
|
195
|
+
items: items.map((entry) => ({
|
|
196
|
+
id: entry.id,
|
|
197
|
+
label: entry.title,
|
|
198
|
+
href: entry.href,
|
|
199
|
+
isFavorite: entry.isFavorite,
|
|
200
|
+
})),
|
|
201
|
+
}));
|
|
202
|
+
}, [activeCategory, activeGroupKey, groups]);
|
|
203
|
+
|
|
204
|
+
let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
|
|
205
|
+
let hasApps = searchMatches.length > 0;
|
|
206
|
+
let railGroups = groups.map(([key, items]) => ({ key, count: items.length }));
|
|
207
|
+
|
|
208
|
+
function select(next: Selection) {
|
|
209
|
+
setSelection(next);
|
|
210
|
+
setHasResolvedSelection(true);
|
|
211
|
+
setMobilePane("apps");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<dialog
|
|
216
|
+
ref={dialogRef}
|
|
217
|
+
id={id}
|
|
218
|
+
className={clsx("ob-app-menu", className)}
|
|
219
|
+
aria-label={getLocalizedString("Applications")}
|
|
220
|
+
data-pane={mobilePane}
|
|
221
|
+
onCancel={(event) => {
|
|
222
|
+
// Let React own the open state instead of the browser's default close.
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
onClose();
|
|
225
|
+
}}
|
|
226
|
+
onKeyDown={(event) => {
|
|
227
|
+
// A `type="search"` input consumes Escape to clear itself, so the
|
|
228
|
+
// dialog's own cancel event never fires when the search has focus.
|
|
229
|
+
if (event.key === "Escape") {
|
|
230
|
+
event.preventDefault();
|
|
231
|
+
onClose();
|
|
232
|
+
}
|
|
233
|
+
}}
|
|
234
|
+
onClick={(event) => {
|
|
235
|
+
// Clicks on the dialog element itself are backdrop clicks; anything
|
|
236
|
+
// inside the menu is caught by the inner wrapper below.
|
|
237
|
+
if (event.target === dialogRef.current) onClose();
|
|
238
|
+
}}
|
|
239
|
+
>
|
|
240
|
+
<div className="ob-app-menu__panel">
|
|
241
|
+
<AppMenuRail
|
|
242
|
+
searchRef={searchRef}
|
|
243
|
+
search={search}
|
|
244
|
+
onSearchChange={setSearch}
|
|
245
|
+
groups={railGroups}
|
|
246
|
+
appCount={searchMatches.length}
|
|
247
|
+
categories={visibleCategories}
|
|
248
|
+
selection={activeSelection}
|
|
249
|
+
onSelect={select}
|
|
250
|
+
/>
|
|
251
|
+
|
|
252
|
+
<div className="ob-app-menu__content">
|
|
253
|
+
{isLoading && !hasApps && !activeCategory && (
|
|
254
|
+
<p className="ob-app-menu__message">{getLocalizedString("Loading...")}</p>
|
|
255
|
+
)}
|
|
256
|
+
|
|
257
|
+
{!isLoading && paneItemCount === 0 && (
|
|
258
|
+
<p className="ob-app-menu__message">{getLocalizedString("No applications found")}</p>
|
|
259
|
+
)}
|
|
260
|
+
|
|
261
|
+
{paneItemCount > 0 && (
|
|
262
|
+
<AppMenuList
|
|
263
|
+
groups={paneGroups}
|
|
264
|
+
itemCount={paneItemCount}
|
|
265
|
+
onClose={onClose}
|
|
266
|
+
onToggleFavorite={toggleFavorite}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
|
|
270
|
+
<AppMenuHeader
|
|
271
|
+
homeLink={homeLink}
|
|
272
|
+
mobilePane={mobilePane}
|
|
273
|
+
onToggleMobilePane={() => setMobilePane(mobilePane === "apps" ? "groups" : "apps")}
|
|
274
|
+
hasUpdate={hasUpdate}
|
|
275
|
+
onInstallUpdate={onInstallUpdate}
|
|
276
|
+
userDataObject={userDataObject}
|
|
277
|
+
userMenuItems={userMenuItems}
|
|
278
|
+
userSubtitle={userSubtitle}
|
|
279
|
+
onClose={onClose}
|
|
280
|
+
/>
|
|
281
|
+
</div>
|
|
282
|
+
</div>
|
|
283
|
+
</dialog>
|
|
284
|
+
);
|
|
285
|
+
}
|