@entur-partner/app-shell-standalone 7.0.0-alpha.1 → 7.0.1

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,7 +1,7 @@
1
1
  import { type AppShellProps, type GetOrganisationsFn } from "@entur-partner/app-shell";
2
- import { Environment } from "@entur-partner/common";
2
+ import { type Environment } from "@entur-partner/common";
3
3
  import type { MicroFrontendPayload } from "@entur-partner/micro-frontend";
4
- import React, { type ReactNode } from "react";
4
+ import { type ReactNode } from "react";
5
5
  export interface AppShellStandaloneProps extends Omit<AppShellProps, "children"> {
6
6
  children: (options: MicroFrontendPayload) => ReactNode;
7
7
  /**
@@ -11,6 +11,5 @@ export interface AppShellStandaloneProps extends Omit<AppShellProps, "children">
11
11
  getOrganisations: GetOrganisationsFn | string;
12
12
  environment?: Environment;
13
13
  postHogApiKey?: string;
14
- isPublicView?: boolean;
15
14
  }
16
- export declare const AppShellStandalone: ({ children, audience, domain, clientId, decorateUser, getOrganisations, redirectUri, environment, navigate, isPublicView, }: AppShellStandaloneProps) => React.JSX.Element;
15
+ export declare const AppShellStandalone: ({ children, audience, domain, clientId, decorateUser, getOrganisations, redirectUri, environment, navigate, }: AppShellStandaloneProps) => import("react/jsx-runtime").JSX.Element;
package/dist/Menu.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { type AppShellValues, type GetOrganisationsFn } from "@entur-partner/app-shell";
2
2
  import { type Environment } from "@entur-partner/common";
3
- import React from "react";
4
3
  declare global {
5
4
  interface Window {
6
5
  UC_UI: {
@@ -9,53 +8,9 @@ declare global {
9
8
  };
10
9
  }
11
10
  }
12
- export declare const EN_GB: {
13
- switchLanguage: string;
14
- logout: string;
15
- appVersion: string;
16
- myProfile: string;
17
- cookieSettings: string;
18
- };
19
- export declare const NO_NB: {
20
- switchLanguage: string;
21
- logout: string;
22
- appVersion: string;
23
- myProfile: string;
24
- cookieSettings: string;
25
- };
26
- export declare const messages: {
27
- readonly nb: {
28
- switchLanguage: string;
29
- logout: string;
30
- appVersion: string;
31
- myProfile: string;
32
- cookieSettings: string;
33
- };
34
- readonly en: {
35
- switchLanguage: string;
36
- logout: string;
37
- appVersion: string;
38
- myProfile: string;
39
- cookieSettings: string;
40
- };
41
- readonly "nb-NO": {
42
- switchLanguage: string;
43
- logout: string;
44
- appVersion: string;
45
- myProfile: string;
46
- cookieSettings: string;
47
- };
48
- readonly "en-GB": {
49
- switchLanguage: string;
50
- logout: string;
51
- appVersion: string;
52
- myProfile: string;
53
- cookieSettings: string;
54
- };
55
- };
56
11
  interface MenuProps extends AppShellValues {
57
12
  getOrganisations: GetOrganisationsFn | string;
58
13
  environment?: Environment;
59
14
  }
60
- export declare const Menu: ({ getOrganisations, user, getToken, logout, environment, }: MenuProps) => React.JSX.Element;
15
+ export declare const Menu: ({ getOrganisations, user, getToken, logout, environment, }: MenuProps) => import("react/jsx-runtime").JSX.Element;
61
16
  export {};
@@ -2,18 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var jsxRuntime = require('react/jsx-runtime');
5
6
  var appShell = require('@entur-partner/app-shell');
6
7
  var common = require('@entur-partner/common');
7
- var React = require('react');
8
8
  var menu = require('@entur/menu');
9
9
  var tokens = require('@entur/tokens');
10
- var util = require('@entur-partner/util');
11
- var auth0React = require('@auth0/auth0-react');
12
- var button = require('@entur/button');
13
- var layout = require('@entur/layout');
14
- var loader = require('@entur/loader');
15
- var classNames = require('classnames');
16
- var reactRouterDom = require('react-router-dom');
17
10
 
18
11
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
19
12
  try {
@@ -158,25 +151,17 @@ function _regeneratorDefine(e, r, n, t) {
158
151
  }, _regeneratorDefine(e, r, n, t);
159
152
  }
160
153
 
161
- var EN_GB = {
162
- switchLanguage: "Bytt til norsk",
163
- logout: "Sign out",
164
- appVersion: "Versjon",
165
- myProfile: "My profile",
166
- cookieSettings: "Cookie settings"
167
- };
168
- var NO_NB = {
169
- switchLanguage: "Switch to English",
170
- logout: "Logg ut",
171
- appVersion: "Version",
172
- myProfile: "Min profil",
173
- cookieSettings: "Cookieinstillinger"
174
- };
175
- var messages = {
176
- nb: NO_NB,
177
- en: EN_GB,
178
- "nb-NO": NO_NB,
179
- "en-GB": EN_GB
154
+ var convertToLocale = function convertToLocale(language) {
155
+ switch (language) {
156
+ case "nb":
157
+ case "nb-NO":
158
+ return "nb-NO";
159
+ case "en":
160
+ case "en-GB":
161
+ return "en-GB";
162
+ default:
163
+ return "nb-NO";
164
+ }
180
165
  };
181
166
  var Menu = function Menu(_ref) {
182
167
  var getOrganisations = _ref.getOrganisations,
@@ -193,261 +178,84 @@ var Menu = function Menu(_ref) {
193
178
  setOrganisationId = _useOrganisation.setOrganisationId,
194
179
  organisationId = _useOrganisation.organisationId;
195
180
  var items = getItemsForPath("app-shell");
196
- util.assertIsDefined(user, "User must be defined to render Menu");
197
- util.assertIsDefined(organisationId, "Organisation ID must be defined to render Menu");
198
- return React.createElement(common.Menu, null, React.createElement("div", {
199
- style: {
200
- marginLeft: tokens.space.extraLarge2,
201
- marginTop: tokens.space.large,
202
- marginBottom: tokens.space.extraLarge
203
- }
204
- }, React.createElement(common.EnturPartnerLogo, {
205
- altText: "Entur partner logo",
206
- className: "menu-space menu-logo",
207
- environment: environment
208
- })), React.createElement("div", {
209
- style: {
210
- margin: tokens.space.large
211
- }
212
- }, React.createElement(common.Stack, {
213
- space: "small"
214
- }, React.createElement(common.UserMenu, {
215
- className: "ph-no-capture",
216
- onLanguageChange: setLanguage,
217
- onLogout: function () {
218
- var _onLogout = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
219
- return _regenerator().w(function (_context) {
220
- while (1) switch (_context.n) {
221
- case 0:
222
- _context.n = 1;
223
- return logout();
224
- case 1:
225
- return _context.a(2);
226
- }
227
- }, _callee);
228
- }));
229
- function onLogout() {
230
- return _onLogout.apply(this, arguments);
231
- }
232
- return onLogout;
233
- }(),
234
- language: language,
235
- messages: messages[language],
236
- userName: user.given_name ? user.given_name + " " + user.family_name : user.name,
237
- environment: environment,
238
- showVersionItem: false,
239
- showMyProfileItem: false,
240
- showCookieSettingsItem: true,
241
- onCookieSettingsOpen: function onCookieSettingsOpen() {
242
- window.UC_UI.showSecondLayer();
243
- },
244
- onNavigateToMyProfile: function onNavigateToMyProfile() {}
245
- }), React.createElement(appShell.OrganisationSelector, {
246
- getOrganisations: getOrganisations,
247
- getToken: getToken,
248
- selectedOrganisationId: organisationId,
249
- onChange: function onChange(organisationId) {
250
- return setOrganisationId(organisationId);
251
- }
252
- }))), React.createElement(menu.SideNavigation, null, items.map(function (_ref2) {
253
- var to = _ref2.to,
254
- title = _ref2.title,
255
- disabled = _ref2.disabled,
256
- navigate = _ref2.navigate;
257
- var itemProps = {
258
- as: appShell.MicroFrontendLink,
259
- href: to,
260
- navigate: disabled ? null : function () {
261
- return navigate(to);
181
+ var locale = convertToLocale(language);
182
+ return jsxRuntime.jsxs(common.Menu, {
183
+ children: [jsxRuntime.jsx("div", {
184
+ style: {
185
+ marginLeft: tokens.space.extraLarge2,
186
+ marginTop: tokens.space.large,
187
+ marginBottom: tokens.space.extraLarge
262
188
  },
263
- disabled: !!disabled
264
- };
265
- return React.createElement(menu.SideNavigationItem, _extends({
266
- key: to.toString()
267
- }, itemProps), title);
268
- })));
269
- };
270
-
271
- var Content$1 = function Content(_ref) {
272
- var _organisationId$toStr;
273
- var children = _ref.children,
274
- values = _ref.values;
275
- var _useMenu = appShell.useMenu(),
276
- addItems = _useMenu.addItems,
277
- _setMFNavigate = _useMenu.setMFNavigate;
278
- var organisationId = appShell.useOrganisationId();
279
- var _useLanguage = appShell.useLanguage(),
280
- language = _useLanguage.language;
281
- var addMenuItems = function addMenuItems(items) {
282
- return addItems(items, "app-shell");
283
- };
284
- return React.createElement(common.Content, null, children(_extends({}, values, {
285
- language: language,
286
- navigate: function navigate() {
287
- {
288
- console.warn("Calling navigate() from app shell has no effect. It is only provided so that the app shell values are equal to MicroFrontendPayload.");
289
- }
290
- },
291
- addMenuItems: addMenuItems,
292
- organisationId: (_organisationId$toStr = organisationId == null ? void 0 : organisationId.toString()) != null ? _organisationId$toStr : "",
293
- setMFNavigate: function setMFNavigate(navigate) {
294
- return _setMFNavigate("app-shell", navigate);
295
- }
296
- })));
297
- };
298
- var AppShellStandalone = function AppShellStandalone(_ref2) {
299
- var children = _ref2.children,
300
- audience = _ref2.audience,
301
- domain = _ref2.domain,
302
- clientId = _ref2.clientId,
303
- decorateUser = _ref2.decorateUser,
304
- getOrganisations = _ref2.getOrganisations,
305
- redirectUri = _ref2.redirectUri,
306
- environment = _ref2.environment,
307
- navigate = _ref2.navigate,
308
- _ref2$isPublicView = _ref2.isPublicView,
309
- isPublicView = _ref2$isPublicView === void 0 ? false : _ref2$isPublicView;
310
- return React.createElement(appShell.AppShell, {
311
- audience: audience,
312
- domain: domain,
313
- clientId: clientId,
314
- decorateUser: decorateUser,
315
- redirectUri: redirectUri,
316
- environment: environment,
317
- navigate: navigate,
318
- isPublicView: isPublicView
319
- }, function (values) {
320
- var _languageStorage$get, _ref3, _organisationStorage$, _values$user;
321
- return React.createElement(appShell.LanguageProvider, {
322
- language: (_languageStorage$get = appShell.languageStorage.get()) != null ? _languageStorage$get : "nb-NO"
323
- }, React.createElement(appShell.OrganisationProvider, {
324
- organisationId: (_ref3 = (_organisationStorage$ = appShell.organisationStorage.get()) != null ? _organisationStorage$ : (_values$user = values.user) == null ? void 0 : _values$user["https://entur.io/organisationID"].toString()) != null ? _ref3 : ""
325
- }, React.createElement(appShell.MenuProvider, null, isPublicView && React.createElement(Menu, _extends({}, values, {
326
- getOrganisations: getOrganisations,
327
- environment: environment
328
- })), React.createElement(Content$1, {
329
- values: values
330
- }, children))));
331
- });
332
- };
333
-
334
- var BetaTopNavigation = function BetaTopNavigation(_ref) {
335
- var _user$name;
336
- var environment = _ref.environment;
337
- var location = reactRouterDom.useLocation();
338
- var _useAuth = auth0React.useAuth0(),
339
- isAuthenticated = _useAuth.isAuthenticated,
340
- loginWithRedirect = _useAuth.loginWithRedirect,
341
- logout = _useAuth.logout,
342
- user = _useAuth.user;
343
- var _useLanguage = appShell.useLanguage(),
344
- language = _useLanguage.language,
345
- setLanguage = _useLanguage.setLanguage;
346
- var isFrontpage = location.pathname === "/";
347
- var _useMenu = appShell.useMenu(),
348
- getItemsForPath = _useMenu.getItemsForPath;
349
- var items = getItemsForPath("app-shell");
350
- return React.createElement(common.BetaTopNavigation, null, React.createElement("nav", {
351
- className: classNames("top-navigation", {
352
- "top-navigation--frontpage": isFrontpage
353
- }),
354
- "aria-label": "Navigasjon, hovedseksjoner"
355
- }, React.createElement(reactRouterDom.Link, {
356
- to: "/",
357
- className: "top-navigation__logo"
358
- }, React.createElement(common.EnturPartnerLogo, {
359
- altText: "Entur partner logo",
360
- className: "menu-space menu-logo",
361
- environment: environment
362
- })), items.filter(function (_ref2) {
363
- var isPublic = _ref2.isPublic,
364
- disabled = _ref2.disabled;
365
- return !disabled && (isPublic || isAuthenticated);
366
- }).map(function (_ref3) {
367
- var to = _ref3.to,
368
- title = _ref3.title,
369
- disabled = _ref3.disabled,
370
- _navigate = _ref3.navigate;
371
- var itemProps = {
372
- as: appShell.MicroFrontendLink,
373
- to: to,
374
- navigate: function navigate() {
375
- return _navigate(to);
189
+ children: jsxRuntime.jsx(common.EnturPartnerLogo, {
190
+ altText: "Entur partner logo",
191
+ className: "menu-space menu-logo",
192
+ environment: environment
193
+ })
194
+ }), jsxRuntime.jsx("div", {
195
+ style: {
196
+ margin: tokens.space.large
376
197
  },
377
- disabled: disabled
378
- };
379
- return React.createElement(NavItem, _extends({
380
- key: to.toString()
381
- }, itemProps), title);
382
- }), React.createElement("div", {
383
- className: "top-navigation__actions"
384
- }, React.createElement(SkeletonLogInLoader, null,
385
- //TODO: Fix contrast
386
- isAuthenticated ? React.createElement(layout.Contrast, null, React.createElement(common.UserMenu, {
387
- className: "ph-no-capture",
388
- onLanguageChange: setLanguage,
389
- onLogout: function () {
390
- var _onLogout = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
391
- return _regenerator().w(function (_context) {
392
- while (1) switch (_context.n) {
393
- case 0:
394
- _context.n = 1;
395
- return logout({
396
- logoutParams: {
397
- returnTo: window.location.origin
198
+ children: jsxRuntime.jsxs(common.Stack, {
199
+ space: "small",
200
+ children: [jsxRuntime.jsx(common.UserMenu, {
201
+ className: "ph-no-capture",
202
+ onLocaleChange: setLanguage,
203
+ onLogout: function () {
204
+ var _onLogout = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
205
+ return _regenerator().w(function (_context) {
206
+ while (1) switch (_context.n) {
207
+ case 0:
208
+ _context.n = 1;
209
+ return logout();
210
+ case 1:
211
+ return _context.a(2);
398
212
  }
399
- });
400
- case 1:
401
- return _context.a(2);
213
+ }, _callee);
214
+ }));
215
+ function onLogout() {
216
+ return _onLogout.apply(this, arguments);
217
+ }
218
+ return onLogout;
219
+ }(),
220
+ locale: locale,
221
+ userName: user.given_name ? user.given_name + " " + user.family_name : user.name,
222
+ environment: environment,
223
+ showVersionItem: false,
224
+ showMyProfileItem: false,
225
+ showCookieSettingsItem: true,
226
+ onCookieSettingsOpen: function onCookieSettingsOpen() {
227
+ window.UC_UI.showSecondLayer();
228
+ },
229
+ onNavigateToMyProfile: function onNavigateToMyProfile() {}
230
+ }), jsxRuntime.jsx(appShell.OrganisationSelector, {
231
+ getOrganisations: getOrganisations,
232
+ getToken: getToken,
233
+ selectedOrganisationId: organisationId,
234
+ onChange: function onChange(organisationId) {
235
+ return setOrganisationId(organisationId);
402
236
  }
403
- }, _callee);
404
- }));
405
- function onLogout() {
406
- return _onLogout.apply(this, arguments);
407
- }
408
- return onLogout;
409
- }(),
410
- language: language,
411
- messages: messages[language],
412
- userName: (_user$name = user == null ? void 0 : user.name) != null ? _user$name : "",
413
- environment: environment,
414
- showVersionItem: false,
415
- showMyProfileItem: false,
416
- showCookieSettingsItem: true,
417
- onCookieSettingsOpen: function onCookieSettingsOpen() {
418
- window.UC_UI.showSecondLayer();
419
- },
420
- onNavigateToMyProfile: function onNavigateToMyProfile() {}
421
- })) : React.createElement(button.SecondaryButton, {
422
- onClick: function onClick() {
423
- return loginWithRedirect();
424
- },
425
- className: "top-navigation__button"
426
- }, "Log In")))));
427
- };
428
- var NavItem = function NavItem(_ref4) {
429
- var to = _ref4.to,
430
- children = _ref4.children;
431
- var location = reactRouterDom.useLocation();
432
- var isActive = location.pathname.startsWith(to);
433
- return React.createElement(menu.TopNavigationItem, {
434
- as: reactRouterDom.Link,
435
- to: to,
436
- active: isActive
437
- }, children);
438
- };
439
- var SkeletonLogInLoader = function SkeletonLogInLoader(_ref5) {
440
- var children = _ref5.children;
441
- var _useAuth2 = auth0React.useAuth0(),
442
- isLoading = _useAuth2.isLoading;
443
- if (isLoading) {
444
- //TODO: A bug with SkeletonRectangle that shows some black bars on top and bottom
445
- return React.createElement(layout.Contrast, null, React.createElement(loader.SkeletonRectangle, {
446
- width: 130,
447
- height: 50
448
- }));
449
- }
450
- return React.createElement(React.Fragment, null, children);
237
+ })]
238
+ })
239
+ }), jsxRuntime.jsx(menu.SideNavigation, {
240
+ children: items.map(function (_ref2) {
241
+ var to = _ref2.to,
242
+ title = _ref2.title,
243
+ disabled = _ref2.disabled,
244
+ navigate = _ref2.navigate;
245
+ var itemProps = {
246
+ as: appShell.MicroFrontendLink,
247
+ href: to,
248
+ navigate: disabled ? null : function () {
249
+ return navigate(to);
250
+ },
251
+ disabled: !!disabled
252
+ };
253
+ return jsxRuntime.jsx(menu.SideNavigationItem, _extends({}, itemProps, {
254
+ children: title
255
+ }), to.toString());
256
+ })
257
+ })]
258
+ });
451
259
  };
452
260
 
453
261
  var Content = function Content(_ref) {
@@ -456,55 +264,66 @@ var Content = function Content(_ref) {
456
264
  var _useMenu = appShell.useMenu(),
457
265
  addItems = _useMenu.addItems,
458
266
  _setMFNavigate = _useMenu.setMFNavigate;
267
+ var organisationId = appShell.useOrganisationId();
459
268
  var _useLanguage = appShell.useLanguage(),
460
269
  language = _useLanguage.language;
461
270
  var addMenuItems = function addMenuItems(items) {
462
271
  return addItems(items, "app-shell");
463
272
  };
464
- return React.createElement(common.Content, {
465
- className: "eps-public-content"
466
- }, children(_extends({}, values, {
467
- language: language,
468
- navigate: function navigate() {
469
- {
470
- console.warn("Calling navigate() from app shell has no effect. It is only provided so that the app shell values are equal to MicroFrontendPayload.");
273
+ return jsxRuntime.jsx(common.Content, {
274
+ children: children(_extends({}, values, {
275
+ language: language,
276
+ navigate: function navigate() {
277
+ {
278
+ console.warn("Calling navigate() from app shell has no effect. It is only provided so that the app shell values are equal to MicroFrontendPayload.");
279
+ }
280
+ },
281
+ addMenuItems: addMenuItems,
282
+ organisationId: organisationId.toString(),
283
+ setMFNavigate: function setMFNavigate(navigate) {
284
+ return _setMFNavigate("app-shell", navigate);
471
285
  }
472
- },
473
- addMenuItems: addMenuItems,
474
- setMFNavigate: function setMFNavigate(navigate) {
475
- return _setMFNavigate("app-shell", navigate);
476
- }
477
- })));
286
+ }))
287
+ });
478
288
  };
479
- var PublicAppShellStandalone = function PublicAppShellStandalone(_ref2) {
480
- var children = _ref2.children,
289
+ var AppShellStandalone = function AppShellStandalone(_ref2) {
290
+ var _children = _ref2.children,
481
291
  audience = _ref2.audience,
482
292
  domain = _ref2.domain,
483
293
  clientId = _ref2.clientId,
484
294
  decorateUser = _ref2.decorateUser,
295
+ getOrganisations = _ref2.getOrganisations,
485
296
  redirectUri = _ref2.redirectUri,
486
297
  environment = _ref2.environment,
487
298
  navigate = _ref2.navigate;
488
- return React.createElement(appShell.AppShell, {
299
+ return jsxRuntime.jsx(appShell.AppShell, {
489
300
  audience: audience,
490
301
  domain: domain,
491
302
  clientId: clientId,
492
303
  decorateUser: decorateUser,
493
304
  redirectUri: redirectUri,
305
+ environment: environment,
494
306
  navigate: navigate,
495
- isPublicView: true
496
- }, function (values) {
497
- var _languageStorage$get;
498
- return React.createElement(appShell.LanguageProvider, {
499
- language: (_languageStorage$get = appShell.languageStorage.get()) != null ? _languageStorage$get : "nb-NO"
500
- }, React.createElement(appShell.MenuProvider, null, React.createElement(BetaTopNavigation, {
501
- environment: environment
502
- }), React.createElement(Content, {
503
- values: values
504
- }, children)));
307
+ children: function children(values) {
308
+ var _languageStorage$get, _organisationStorage$;
309
+ return jsxRuntime.jsx(appShell.LanguageProvider, {
310
+ language: (_languageStorage$get = appShell.languageStorage.get()) != null ? _languageStorage$get : "nb-NO",
311
+ children: jsxRuntime.jsx(appShell.OrganisationProvider, {
312
+ organisationId: (_organisationStorage$ = appShell.organisationStorage.get()) != null ? _organisationStorage$ : values.user["https://entur.io/organisationID"].toString(),
313
+ children: jsxRuntime.jsxs(appShell.MenuProvider, {
314
+ children: [jsxRuntime.jsx(Menu, _extends({}, values, {
315
+ getOrganisations: getOrganisations,
316
+ environment: environment
317
+ })), jsxRuntime.jsx(Content, {
318
+ values: values,
319
+ children: _children
320
+ })]
321
+ })
322
+ })
323
+ });
324
+ }
505
325
  });
506
326
  };
507
327
 
508
328
  exports.AppShellStandalone = AppShellStandalone;
509
- exports.PublicAppShellStandalone = PublicAppShellStandalone;
510
329
  //# sourceMappingURL=app-shell-standalone.cjs.development.js.map