@entur-partner/app-shell 6.4.1 → 6.4.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,874 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var jsxRuntime = require('react/jsx-runtime');
6
- var auth0React = require('@auth0/auth0-react');
7
- var alert = require('@entur/alert');
8
- var loader = require('@entur/loader');
9
- var tokens = require('@entur/tokens');
10
- var typography = require('@entur/typography');
11
- var common = require('@entur-partner/common');
12
- var util = require('@entur-partner/util');
13
- var react = require('react');
14
- var postHog = require('posthog-js');
15
- var react$1 = require('posthog-js/react');
16
-
17
- function asyncGeneratorStep(n, t, e, r, o, a, c) {
18
- try {
19
- var i = n[a](c),
20
- u = i.value;
21
- } catch (n) {
22
- return void e(n);
23
- }
24
- i.done ? t(u) : Promise.resolve(u).then(r, o);
25
- }
26
- function _asyncToGenerator(n) {
27
- return function () {
28
- var t = this,
29
- e = arguments;
30
- return new Promise(function (r, o) {
31
- var a = n.apply(t, e);
32
- function _next(n) {
33
- asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
34
- }
35
- function _throw(n) {
36
- asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
37
- }
38
- _next(void 0);
39
- });
40
- };
41
- }
42
- function _construct(t, e, r) {
43
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
44
- var o = [null];
45
- o.push.apply(o, e);
46
- var p = new (t.bind.apply(t, o))();
47
- return r && _setPrototypeOf(p, r.prototype), p;
48
- }
49
- function _extends() {
50
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
51
- for (var e = 1; e < arguments.length; e++) {
52
- var t = arguments[e];
53
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
54
- }
55
- return n;
56
- }, _extends.apply(null, arguments);
57
- }
58
- function _getPrototypeOf(t) {
59
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
60
- return t.__proto__ || Object.getPrototypeOf(t);
61
- }, _getPrototypeOf(t);
62
- }
63
- function _inheritsLoose(t, o) {
64
- t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
65
- }
66
- function _isNativeFunction(t) {
67
- try {
68
- return -1 !== Function.toString.call(t).indexOf("[native code]");
69
- } catch (n) {
70
- return "function" == typeof t;
71
- }
72
- }
73
- function _isNativeReflectConstruct() {
74
- try {
75
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
76
- } catch (t) {}
77
- return (_isNativeReflectConstruct = function () {
78
- return !!t;
79
- })();
80
- }
81
- function _objectWithoutPropertiesLoose(r, e) {
82
- if (null == r) return {};
83
- var t = {};
84
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
85
- if (-1 !== e.indexOf(n)) continue;
86
- t[n] = r[n];
87
- }
88
- return t;
89
- }
90
- function _regenerator() {
91
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
92
- var e,
93
- t,
94
- r = "function" == typeof Symbol ? Symbol : {},
95
- n = r.iterator || "@@iterator",
96
- o = r.toStringTag || "@@toStringTag";
97
- function i(r, n, o, i) {
98
- var c = n && n.prototype instanceof Generator ? n : Generator,
99
- u = Object.create(c.prototype);
100
- return _regeneratorDefine(u, "_invoke", function (r, n, o) {
101
- var i,
102
- c,
103
- u,
104
- f = 0,
105
- p = o || [],
106
- y = !1,
107
- G = {
108
- p: 0,
109
- n: 0,
110
- v: e,
111
- a: d,
112
- f: d.bind(e, 4),
113
- d: function (t, r) {
114
- return i = t, c = 0, u = e, G.n = r, a;
115
- }
116
- };
117
- function d(r, n) {
118
- for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
119
- var o,
120
- i = p[t],
121
- d = G.p,
122
- l = i[2];
123
- 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));
124
- }
125
- if (o || r > 1) return a;
126
- throw y = !0, n;
127
- }
128
- return function (o, p, l) {
129
- if (f > 1) throw TypeError("Generator is already running");
130
- for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
131
- i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
132
- try {
133
- if (f = 2, i) {
134
- if (c || (o = "next"), t = i[o]) {
135
- if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
136
- if (!t.done) return t;
137
- u = t.value, c < 2 && (c = 0);
138
- } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
139
- i = e;
140
- } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
141
- } catch (t) {
142
- i = e, c = 1, u = t;
143
- } finally {
144
- f = 1;
145
- }
146
- }
147
- return {
148
- value: t,
149
- done: y
150
- };
151
- };
152
- }(r, o, i), !0), u;
153
- }
154
- var a = {};
155
- function Generator() {}
156
- function GeneratorFunction() {}
157
- function GeneratorFunctionPrototype() {}
158
- t = Object.getPrototypeOf;
159
- var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
160
- return this;
161
- }), t),
162
- u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
163
- function f(e) {
164
- return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
165
- }
166
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
167
- return this;
168
- }), _regeneratorDefine(u, "toString", function () {
169
- return "[object Generator]";
170
- }), (_regenerator = function () {
171
- return {
172
- w: i,
173
- m: f
174
- };
175
- })();
176
- }
177
- function _regeneratorDefine(e, r, n, t) {
178
- var i = Object.defineProperty;
179
- try {
180
- i({}, "", {});
181
- } catch (e) {
182
- i = 0;
183
- }
184
- _regeneratorDefine = function (e, r, n, t) {
185
- function o(r, n) {
186
- _regeneratorDefine(e, r, function (e) {
187
- return this._invoke(r, n, e);
188
- });
189
- }
190
- r ? i ? i(e, r, {
191
- value: n,
192
- enumerable: !t,
193
- configurable: !t,
194
- writable: !t
195
- }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
196
- }, _regeneratorDefine(e, r, n, t);
197
- }
198
- function _setPrototypeOf(t, e) {
199
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
200
- return t.__proto__ = e, t;
201
- }, _setPrototypeOf(t, e);
202
- }
203
- function _wrapNativeSuper(t) {
204
- var r = "function" == typeof Map ? new Map() : void 0;
205
- return _wrapNativeSuper = function (t) {
206
- if (null === t || !_isNativeFunction(t)) return t;
207
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
208
- if (void 0 !== r) {
209
- if (r.has(t)) return r.get(t);
210
- r.set(t, Wrapper);
211
- }
212
- function Wrapper() {
213
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
214
- }
215
- return Wrapper.prototype = Object.create(t.prototype, {
216
- constructor: {
217
- value: Wrapper,
218
- enumerable: !1,
219
- writable: !0,
220
- configurable: !0
221
- }
222
- }), _setPrototypeOf(Wrapper, t);
223
- }, _wrapNativeSuper(t);
224
- }
225
-
226
- var EnvironmentBanner = function EnvironmentBanner(_ref) {
227
- var environment = _ref.environment;
228
- return jsxRuntime.jsx("div", {
229
- className: "epp-environment-banner",
230
- style: {
231
- position: "fixed",
232
- zIndex: 9999,
233
- top: 0,
234
- left: 0,
235
- right: 0,
236
- width: "100vw",
237
- height: "16px",
238
- backgroundColor: common.getColorForEnvironment(environment)
239
- }
240
- });
241
- };
242
-
243
- function userLogout(logout) {
244
- var _window$location = window.location,
245
- protocol = _window$location.protocol,
246
- hostname = _window$location.hostname,
247
- port = _window$location.port;
248
- return logout({
249
- logoutParams: {
250
- returnTo: protocol + "//" + hostname + ":" + port
251
- }
252
- });
253
- }
254
- var Authenticate = function Authenticate(_ref) {
255
- var children = _ref.children,
256
- decorateUser = _ref.decorateUser,
257
- getReturnPath = _ref.getReturnPath;
258
- var _useState = react.useState(undefined),
259
- userWithPermission = _useState[0],
260
- setUserWithPermission = _useState[1];
261
- var _useAuth = auth0React.useAuth0(),
262
- user = _useAuth.user,
263
- getAccessTokenSilently = _useAuth.getAccessTokenSilently,
264
- loginWithRedirect = _useAuth.loginWithRedirect,
265
- _logout = _useAuth.logout,
266
- isLoading = _useAuth.isLoading,
267
- isAuthenticated = _useAuth.isAuthenticated,
268
- error = _useAuth.error;
269
- react.useEffect(function () {
270
- var fetchUserData = /*#__PURE__*/function () {
271
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
272
- var token, decoratedUser, _t;
273
- return _regenerator().w(function (_context) {
274
- while (1) switch (_context.p = _context.n) {
275
- case 0:
276
- _context.p = 0;
277
- _context.n = 1;
278
- return getAccessTokenSilently();
279
- case 1:
280
- token = _context.v;
281
- _context.n = 2;
282
- return decorateUser(user, token);
283
- case 2:
284
- decoratedUser = _context.v;
285
- setUserWithPermission(decoratedUser);
286
- _context.n = 4;
287
- break;
288
- case 3:
289
- _context.p = 3;
290
- _t = _context.v;
291
- console.error("Error fetching user data:", _t);
292
- case 4:
293
- return _context.a(2);
294
- }
295
- }, _callee, null, [[0, 3]]);
296
- }));
297
- return function fetchUserData() {
298
- return _ref2.apply(this, arguments);
299
- };
300
- }();
301
- if (isAuthenticated) {
302
- fetchUserData();
303
- }
304
- }, [decorateUser, getAccessTokenSilently, isAuthenticated, user]);
305
- if (!isLoading && !isAuthenticated) {
306
- loginWithRedirect({
307
- appState: {
308
- returnTo: getReturnPath()
309
- }
310
- });
311
- return jsxRuntime.jsx(loader.Loader, {
312
- style: {
313
- marginTop: tokens.space.extraLarge9
314
- },
315
- children: "Redirecting to login page"
316
- });
317
- }
318
- if (isLoading || !userWithPermission) {
319
- return jsxRuntime.jsx(loader.Loader, {
320
- style: {
321
- marginTop: tokens.space.extraLarge9
322
- },
323
- children: "Authenticating"
324
- });
325
- }
326
- if (error) {
327
- console.error(error);
328
- return jsxRuntime.jsxs(alert.BannerAlertBox, {
329
- variant: "error",
330
- title: "Authentication failed",
331
- style: {
332
- maxWidth: "600px",
333
- margin: "0 auto"
334
- },
335
- children: [jsxRuntime.jsxs(typography.Paragraph, {
336
- children: ["Something went wrong while trying to authenticate you. If the problem persists you should contact", " ", jsxRuntime.jsx(typography.Link, {
337
- href: "mailto:support@entur.org",
338
- children: "support@entur.org"
339
- }), " to get it resolved."]
340
- }), jsxRuntime.jsxs(typography.Paragraph, {
341
- children: ["Authentication failed with: ", jsxRuntime.jsx(typography.CodeText, {
342
- children: error == null ? void 0 : error.toString()
343
- })]
344
- })]
345
- });
346
- }
347
- util.assertIsDefined(userWithPermission);
348
- return jsxRuntime.jsx(jsxRuntime.Fragment, {
349
- children: children({
350
- user: userWithPermission,
351
- logout: function logout() {
352
- return userLogout(_logout);
353
- },
354
- getToken: getAccessTokenSilently
355
- })
356
- });
357
- };
358
- var AppShell = function AppShell(_ref3) {
359
- var _children = _ref3.children,
360
- audience = _ref3.audience,
361
- domain = _ref3.domain,
362
- clientId = _ref3.clientId,
363
- decorateUser = _ref3.decorateUser,
364
- environment = _ref3.environment,
365
- redirectUri = _ref3.redirectUri,
366
- navigate = _ref3.navigate;
367
- // Central place to derive current in-app location (excluding origin)
368
- var getCurrentAppPath = function getCurrentAppPath() {
369
- return "" + window.location.pathname + window.location.search + window.location.hash;
370
- };
371
- // Provide an Auth0 onRedirectCallback that restores the stored path
372
- var handleRedirectCallback = function handleRedirectCallback(appState) {
373
- var target = appState == null ? void 0 : appState.returnTo;
374
- var destination = redirectUri || target || "/";
375
- if (navigate) {
376
- navigate(destination, {
377
- replace: true
378
- });
379
- } else {
380
- // Fallback: use History API
381
- window.history.replaceState({}, "", destination);
382
- }
383
- };
384
- return jsxRuntime.jsx(auth0React.Auth0Provider, {
385
- domain: domain,
386
- clientId: clientId,
387
- authorizationParams: {
388
- redirect_uri: redirectUri != null ? redirectUri : window.location.origin,
389
- audience: audience
390
- },
391
- onRedirectCallback: handleRedirectCallback,
392
- children: jsxRuntime.jsx(Authenticate, {
393
- decorateUser: decorateUser,
394
- getReturnPath: getCurrentAppPath,
395
- children: function children(params) {
396
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
397
- children: [environment && environment !== common.Environment.Production && jsxRuntime.jsx(EnvironmentBanner, {
398
- environment: environment
399
- }), _children(params)]
400
- });
401
- }
402
- })
403
- });
404
- };
405
-
406
- var ORGANISATION_STORAGE_KEY = "EP::activeOrgId";
407
- var organisationStorage = {
408
- get: function get() {
409
- return localStorage.getItem(ORGANISATION_STORAGE_KEY);
410
- },
411
- set: function set(value) {
412
- return localStorage.setItem(ORGANISATION_STORAGE_KEY, value);
413
- }
414
- };
415
- var LANGUAGE_STORAGE_KEY = "EP::locale";
416
- var languageStorage = {
417
- get: function get() {
418
- return localStorage.getItem(LANGUAGE_STORAGE_KEY);
419
- },
420
- set: function set(value) {
421
- return localStorage.setItem(LANGUAGE_STORAGE_KEY, value);
422
- }
423
- };
424
- var UC_UI_STORAGE_KEY = "ucData";
425
- var ucUiStorage = {
426
- get: function get() {
427
- return localStorage.getItem(UC_UI_STORAGE_KEY);
428
- }
429
- };
430
-
431
- var SERVICE_NAMES = {
432
- Usercentrics: "Usercentrics Consent Management Platform",
433
- PostHog: "PostHog.com",
434
- Sentry: "Sentry"
435
- };
436
-
437
- var DEFAULT_CONSENT_GIVEN = {
438
- Usercentrics: {
439
- consentGiven: false
440
- },
441
- PostHog: {
442
- consentGiven: false
443
- },
444
- Sentry: {
445
- consentGiven: false
446
- }
447
- };
448
- var convertUCServicesToConsents = function convertUCServicesToConsents(services) {
449
- return services.map(function (service) {
450
- var _Object$entries$find, _ref3;
451
- var serviceName = (_Object$entries$find = Object.entries(SERVICE_NAMES).find(function (keyValue) {
452
- return keyValue[1] === service.name;
453
- })) == null ? void 0 : _Object$entries$find[0];
454
- // Ensure the service name exists in SERVICE_NAMES
455
- util.assertIsDefined(serviceName, "Service name " + service.name + " not found in SERVICE_NAMES");
456
- if (typeof service.consent === "boolean") {
457
- var _ref;
458
- var consentGiven = service.consent;
459
- return _ref = {}, _ref[serviceName] = {
460
- consentGiven: consentGiven
461
- }, _ref;
462
- } else if (typeof service.consent === "object" && "given" in service.consent) {
463
- var _ref2;
464
- var _consentGiven = service.consent.given;
465
- return _ref2 = {}, _ref2[serviceName] = {
466
- consentGiven: _consentGiven
467
- }, _ref2;
468
- }
469
- return _ref3 = {}, _ref3[serviceName] = {
470
- consentGiven: false
471
- }, _ref3;
472
- }).reduce(
473
- // biome-ignore lint/performance/noAccumulatingSpread: Ignore it for now. No changes in code.
474
- function (acc, curr) {
475
- return _extends({}, acc, curr);
476
- }, DEFAULT_CONSENT_GIVEN);
477
- };
478
-
479
- var ConsentContext = /*#__PURE__*/react.createContext(DEFAULT_CONSENT_GIVEN);
480
- var useConsentManager = function useConsentManager() {
481
- var context = react.useContext(ConsentContext);
482
- return context;
483
- };
484
- var ConsentManagerProvider = function ConsentManagerProvider(_ref) {
485
- var children = _ref.children;
486
- var _useState = react.useState(DEFAULT_CONSENT_GIVEN),
487
- consentManager = _useState[0],
488
- setConsentManager = _useState[1];
489
- // Initialize consent manager from local storage once
490
- react.useEffect(function () {
491
- if (typeof window === "undefined") return;
492
- var ucData = ucUiStorage.get();
493
- if (ucData) {
494
- var data = JSON.parse(ucData);
495
- var services = convertUCServicesToConsents(Object.values(data.consent.services));
496
- setConsentManager(services);
497
- }
498
- }, []);
499
- // Listen for Usercentrics consent events and update consent manager state
500
- react.useEffect(function () {
501
- var handleConsentEvent = /*#__PURE__*/function () {
502
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(event) {
503
- var customEvent, services, updatedConsentManager;
504
- return _regenerator().w(function (_context) {
505
- while (1) switch (_context.n) {
506
- case 0:
507
- if (!(typeof window === "undefined")) {
508
- _context.n = 1;
509
- break;
510
- }
511
- return _context.a(2);
512
- case 1:
513
- customEvent = event;
514
- services = Object.values(customEvent.detail.services);
515
- updatedConsentManager = convertUCServicesToConsents(services);
516
- setConsentManager(updatedConsentManager);
517
- case 2:
518
- return _context.a(2);
519
- }
520
- }, _callee);
521
- }));
522
- return function handleConsentEvent(_x) {
523
- return _ref2.apply(this, arguments);
524
- };
525
- }();
526
- window.addEventListener("UC_CONSENT", handleConsentEvent);
527
- return function () {
528
- return window.removeEventListener("UC_CONSENT", handleConsentEvent);
529
- };
530
- }, []);
531
- return jsxRuntime.jsx(ConsentContext.Provider, {
532
- value: consentManager,
533
- children: children
534
- });
535
- };
536
-
537
- var LanguageContext = /*#__PURE__*/react.createContext(undefined);
538
- var useLanguageState = function useLanguageState(language) {
539
- var _useState = react.useState(language),
540
- activeLanguage = _useState[0],
541
- setLanguage = _useState[1];
542
- react.useEffect(function () {
543
- languageStorage.set(activeLanguage);
544
- }, [activeLanguage]);
545
- return [activeLanguage, setLanguage];
546
- };
547
- var useLanguage = function useLanguage() {
548
- var context = react.useContext(LanguageContext);
549
- util.assertIsDefined(context);
550
- return context;
551
- };
552
- var LanguageProvider = function LanguageProvider(_ref) {
553
- var children = _ref.children,
554
- language = _ref.language;
555
- var _useLanguageState = useLanguageState(language),
556
- activeLanguage = _useLanguageState[0],
557
- setLanguage = _useLanguageState[1];
558
- return jsxRuntime.jsx(LanguageContext.Provider, {
559
- value: {
560
- language: activeLanguage,
561
- setLanguage: setLanguage
562
- },
563
- children: children
564
- });
565
- };
566
-
567
- var MenuContext = /*#__PURE__*/react.createContext({
568
- addItems: function addItems() {},
569
- getItemsForPath: function getItemsForPath() {
570
- return [];
571
- },
572
- getMFNavigate: function getMFNavigate() {
573
- return undefined;
574
- },
575
- setMFNavigate: function setMFNavigate() {},
576
- getItemGroupsPerPath: function getItemGroupsPerPath() {
577
- return {};
578
- }
579
- });
580
- var useMenuGroupItems = function useMenuGroupItems(path) {
581
- var context = react.useContext(MenuContext);
582
- return context.getItemsForPath(path);
583
- };
584
- var useMenu = function useMenu() {
585
- return react.useContext(MenuContext);
586
- };
587
- var useMFNavigation = function useMFNavigation(path) {
588
- var _useMenu = useMenu(),
589
- getMFNavigate = _useMenu.getMFNavigate;
590
- return getMFNavigate(path);
591
- };
592
- var MenuProvider = function MenuProvider(_ref) {
593
- var children = _ref.children;
594
- var _useState = react.useState({}),
595
- groups = _useState[0],
596
- setGroups = _useState[1];
597
- var _useState2 = react.useState({}),
598
- navFuncs = _useState2[0],
599
- setNavFuncs = _useState2[1];
600
- var addItems = react.useCallback(function (newItems, path) {
601
- setGroups(function (prevState) {
602
- var _extends2;
603
- return _extends({}, prevState, (_extends2 = {}, _extends2[path] = newItems, _extends2));
604
- });
605
- }, []);
606
- var getMFNavigate = function getMFNavigate(path) {
607
- return navFuncs[path];
608
- };
609
- var setMFNavigate = function setMFNavigate(path, navigation) {
610
- return setNavFuncs(function (prev) {
611
- var _extends3;
612
- return _extends({}, prev, (_extends3 = {}, _extends3[path] = navigation, _extends3));
613
- });
614
- };
615
- return jsxRuntime.jsx(MenuContext.Provider, {
616
- value: {
617
- addItems: addItems,
618
- getItemGroupsPerPath: function getItemGroupsPerPath() {
619
- return groups;
620
- },
621
- getItemsForPath: function getItemsForPath(path) {
622
- var _groups$path;
623
- return (_groups$path = groups[path]) != null ? _groups$path : [];
624
- },
625
- getMFNavigate: getMFNavigate,
626
- setMFNavigate: setMFNavigate
627
- },
628
- children: children
629
- });
630
- };
631
-
632
- var _excluded$1 = ["navigate", "children", "onClick", "target"];
633
- function isModifiedEvent(event) {
634
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
635
- }
636
- var MicroFrontendLink = function MicroFrontendLink(_ref) {
637
- var navigate = _ref.navigate,
638
- children = _ref.children,
639
- _onClick = _ref.onClick,
640
- target = _ref.target,
641
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
642
- return (
643
- // biome-ignore lint/a11y/noStaticElementInteractions: Ignore lint rule for now. No changes in code.
644
- jsxRuntime.jsx("a", _extends({
645
- // biome-ignore lint/a11y/useValidAnchor: Ignore lint rule for now. No changes in code.
646
- onClick: function onClick(event) {
647
- try {
648
- if (_onClick) _onClick(event);
649
- } catch (ex) {
650
- event.preventDefault();
651
- throw ex;
652
- }
653
- if (!event.defaultPrevented &&
654
- // onClick prevented default
655
- event.button === 0 && (
656
- // ignore everything but right clicks
657
- !target || target === "_self") &&
658
- // let browser handle "target=_blank" etc.
659
- !isModifiedEvent(event) // ignore clicks with modifier keys
660
- ) {
661
- event.preventDefault();
662
- navigate();
663
- }
664
- },
665
- target: target
666
- }, rest, {
667
- children: children
668
- }))
669
- );
670
- };
671
-
672
- var OrganisationContext = /*#__PURE__*/react.createContext(undefined);
673
- var useOrganisation = function useOrganisation() {
674
- var context = react.useContext(OrganisationContext);
675
- util.assertIsDefined(context);
676
- return context;
677
- };
678
- var useOrganisationId = function useOrganisationId() {
679
- var context = react.useContext(OrganisationContext);
680
- util.assertIsDefined(context);
681
- return context.organisationId;
682
- };
683
- var useOrganisationState = function useOrganisationState(initialOrganisationId) {
684
- var _useState = react.useState(Number(initialOrganisationId)),
685
- organisationId = _useState[0],
686
- setOrganisationId = _useState[1];
687
- react.useEffect(function () {
688
- organisationStorage.set(organisationId.toString());
689
- }, [organisationId]);
690
- return [organisationId, setOrganisationId];
691
- };
692
- var OrganisationProvider = function OrganisationProvider(_ref) {
693
- var children = _ref.children,
694
- organisationId = _ref.organisationId;
695
- var _useOrganisationState = useOrganisationState(organisationId),
696
- orgId = _useOrganisationState[0],
697
- setOrganisationId = _useOrganisationState[1];
698
- return jsxRuntime.jsx(OrganisationContext.Provider, {
699
- value: {
700
- organisationId: orgId,
701
- setOrganisationId: setOrganisationId
702
- },
703
- children: children
704
- });
705
- };
706
-
707
- var OrganisationsError = /*#__PURE__*/function (_Error) {
708
- function OrganisationsError() {
709
- var _this;
710
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
711
- args[_key] = arguments[_key];
712
- }
713
- _this = _Error.call.apply(_Error, [this].concat(args)) || this;
714
- _this.message = "Failed fetching organisations";
715
- return _this;
716
- }
717
- _inheritsLoose(OrganisationsError, _Error);
718
- return OrganisationsError;
719
- }(/*#__PURE__*/_wrapNativeSuper(Error));
720
-
721
- var _excluded = ["getToken", "getOrganisations", "selectedOrganisationId", "onChange"];
722
- var OrganisationSelector = function OrganisationSelector(_ref) {
723
- var getToken = _ref.getToken,
724
- getOrganisations = _ref.getOrganisations,
725
- selectedOrganisationId = _ref.selectedOrganisationId,
726
- onChange = _ref.onChange,
727
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
728
- var _useState = react.useState([]),
729
- organisations = _useState[0],
730
- setOrganisations = _useState[1];
731
- var _useLanguage = useLanguage(),
732
- language = _useLanguage.language;
733
- var _useState2 = react.useState("LOADING"),
734
- status = _useState2[0],
735
- setStatus = _useState2[1];
736
- react.useEffect(function () {
737
- var fetchOrganisations = /*#__PURE__*/function () {
738
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
739
- var token, organisations;
740
- return _regenerator().w(function (_context) {
741
- while (1) switch (_context.n) {
742
- case 0:
743
- _context.n = 1;
744
- return getToken();
745
- case 1:
746
- token = _context.v;
747
- if (!(typeof getOrganisations === "string")) {
748
- _context.n = 3;
749
- break;
750
- }
751
- _context.n = 2;
752
- return fetch(getOrganisations, {
753
- headers: {
754
- Authorization: "Bearer " + token,
755
- Accept: "application/json"
756
- }
757
- }).then(function (response) {
758
- return response.json();
759
- });
760
- case 2:
761
- organisations = _context.v;
762
- _context.n = 5;
763
- break;
764
- case 3:
765
- _context.n = 4;
766
- return getOrganisations(token);
767
- case 4:
768
- organisations = _context.v;
769
- case 5:
770
- setOrganisations(organisations);
771
- setStatus("SUCCESS");
772
- case 6:
773
- return _context.a(2);
774
- }
775
- }, _callee);
776
- }));
777
- return function fetchOrganisations() {
778
- return _ref2.apply(this, arguments);
779
- };
780
- }();
781
- fetchOrganisations()["catch"](function (error) {
782
- {
783
- console.error(error);
784
- }
785
- setStatus("ERROR");
786
- });
787
- }, [getOrganisations, getToken]);
788
- switch (status) {
789
- case "LOADING":
790
- return jsxRuntime.jsx("div", {
791
- className: "eds-contrast",
792
- children: jsxRuntime.jsx(loader.SkeletonRectangle, {
793
- style: {
794
- height: "2.4rem"
795
- }
796
- })
797
- });
798
- case "SUCCESS":
799
- return jsxRuntime.jsx(common.OrganisationDropDown, _extends({
800
- label: language === "nb" || language === "nb-NO" ? "Organisasjon" : "Organisation",
801
- selectedOrganisationId: selectedOrganisationId,
802
- organisations: organisations,
803
- onChange: onChange
804
- }, rest));
805
- case "ERROR":
806
- throw new OrganisationsError();
807
- default:
808
- return null;
809
- }
810
- };
811
-
812
- var PostHogProviderWrapper = function PostHogProviderWrapper(_ref) {
813
- var _ref$debug = _ref.debug,
814
- debug = _ref$debug === void 0 ? false : _ref$debug,
815
- postHogApiKey = _ref.postHogApiKey,
816
- isStandalone = _ref.isStandalone,
817
- project = _ref.project,
818
- _ref$forceDisablePost = _ref.forceDisablePostHog,
819
- forceDisablePostHog = _ref$forceDisablePost === void 0 ? false : _ref$forceDisablePost,
820
- children = _ref.children;
821
- var consents = useConsentManager();
822
- react.useEffect(function () {
823
- if (!postHogApiKey || forceDisablePostHog) {
824
- return;
825
- }
826
- if (consents != null && consents.PostHog.consentGiven) {
827
- postHog.opt_in_capturing();
828
- } else {
829
- postHog.opt_out_capturing();
830
- }
831
- }, [consents.PostHog.consentGiven, forceDisablePostHog, postHogApiKey]);
832
- // If no API key is provided or PostHog is forced to be disabled, do not initialize PostHog
833
- if (!postHogApiKey || forceDisablePostHog) {
834
- if (!forceDisablePostHog) {
835
- console.warn("AppShellStandalone Warning: PostHog API key is not provided. PostHog will not be initialized.");
836
- } else {
837
- console.warn("AppShellStandalone Warning: PostHog tracking is disabled by force. PostHog will not be initialized.");
838
- }
839
- return jsxRuntime.jsx(jsxRuntime.Fragment, {
840
- children: children
841
- });
842
- }
843
- postHog.init(postHogApiKey, {
844
- debug: debug,
845
- api_host: isStandalone ? "https://eu.posthog.com" : "/ingest",
846
- ui_host: "https://eu.posthog.com",
847
- opt_out_capturing_by_default: true,
848
- autocapture: isStandalone
849
- }, project);
850
- return jsxRuntime.jsx(react$1.PostHogProvider, {
851
- client: postHog,
852
- children: children
853
- });
854
- };
855
-
856
- exports.AppShell = AppShell;
857
- exports.ConsentManagerProvider = ConsentManagerProvider;
858
- exports.LanguageProvider = LanguageProvider;
859
- exports.MenuProvider = MenuProvider;
860
- exports.MicroFrontendLink = MicroFrontendLink;
861
- exports.OrganisationProvider = OrganisationProvider;
862
- exports.OrganisationSelector = OrganisationSelector;
863
- exports.OrganisationsError = OrganisationsError;
864
- exports.PostHogProviderWrapper = PostHogProviderWrapper;
865
- exports.languageStorage = languageStorage;
866
- exports.organisationStorage = organisationStorage;
867
- exports.useConsentManager = useConsentManager;
868
- exports.useLanguage = useLanguage;
869
- exports.useMFNavigation = useMFNavigation;
870
- exports.useMenu = useMenu;
871
- exports.useMenuGroupItems = useMenuGroupItems;
872
- exports.useOrganisation = useOrganisation;
873
- exports.useOrganisationId = useOrganisationId;
874
- //# sourceMappingURL=app-shell.cjs.development.js.map