@entur-partner/micro-frontend 2.4.2 → 2.4.4
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/Payload.d.ts +1 -1
- package/dist/events.d.ts +4 -4
- package/dist/micro-frontend.cjs.development.js +41 -136
- package/dist/micro-frontend.cjs.development.js.map +1 -1
- package/dist/micro-frontend.cjs.production.min.js.map +1 -1
- package/dist/micro-frontend.esm.js +41 -136
- package/dist/micro-frontend.esm.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/events.ts","../src/AppProvider.tsx","../src/registerMicroFrontend.tsx"],"sourcesContent":["import { MicroFrontendPayload } from './Payload';\n\ntype MountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n payload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = '@entur-partner:mount';\nexport const UNMOUNT_EVENT_TYPE = '@entur-partner:unmount';\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n return new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n return new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = '@entur-partner:after-route-change';\n\nexport type RouteAction = 'PUSH' | 'POP' | 'REPLACE';\n\ntype RouteChangeEventDetail = {\n location: Location;\n action: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","import React, { FC, ReactNode, useContext, useEffect, useState } from 'react';\nimport { assertIsDefined } from '@entur-partner/util';\nimport { Permission } from '@entur-partner/permission-client-node';\n\nimport { User } from './User';\n\ninterface AppContextType {\n getToken: () => Promise<string>;\n user: User;\n logout?: () => void;\n activeOrgId: number;\n navigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n undefined\n);\n\nexport const useUser = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.user;\n};\n\nexport const useActiveOrgId = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n children: ReactNode;\n getToken: () => Promise<string>;\n user: User;\n getPermissions: () => Promise<Permission[]>;\n organisationId: string;\n navigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n children,\n organisationId,\n getPermissions,\n ...rest\n}) => {\n const [permissions, setPermissions] = useState<Permission[]>([]);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const fetchedPermissions = await getPermissions();\n setPermissions(fetchedPermissions);\n } catch (error) {\n console.error(\n 'Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:',\n error\n );\n }\n }\n\n fetchData();\n }, [getPermissions]);\n\n return (\n <AppContext.Provider\n value={{\n ...rest,\n user: { ...rest.user, permissions: permissions },\n activeOrgId: Number(organisationId),\n }}\n >\n {children}\n </AppContext.Provider>\n );\n};\n","/*global EventListener*/\nimport { MicroFrontendPayload } from './Payload';\nimport {\n MountEvent,\n UnmountEvent,\n MOUNT_EVENT_TYPE,\n UNMOUNT_EVENT_TYPE,\n} from './events';\n\ninterface Config {\n microFrontendId: string;\n mount: (\n mountPoint: HTMLDivElement,\n payload: MicroFrontendPayload,\n deprecatedMountPoint: HTMLDivElement\n ) => void;\n unmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n const { unmount, microFrontendId, mount } = config;\n\n window.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n mount(\n event.detail.mountPoint,\n event.detail.payload,\n event.detail.mountPoint\n );\n }) as EventListener);\n\n window.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n unmount(event.detail.mountPoint);\n }) as EventListener);\n}\n"],"names":["RouteChangeEvent","_CustomEvent","apply","this","arguments","_wrapNativeSuper","CustomEvent","AppContext","React","createContext","undefined","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","
|
|
1
|
+
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/events.ts","../src/AppProvider.tsx","../src/registerMicroFrontend.tsx"],"sourcesContent":["import { MicroFrontendPayload } from './Payload';\n\ntype MountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n payload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = '@entur-partner:mount';\nexport const UNMOUNT_EVENT_TYPE = '@entur-partner:unmount';\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n return new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n return new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = '@entur-partner:after-route-change';\n\nexport type RouteAction = 'PUSH' | 'POP' | 'REPLACE';\n\ntype RouteChangeEventDetail = {\n location: Location;\n action: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","import React, { FC, ReactNode, useContext, useEffect, useState } from 'react';\nimport { assertIsDefined } from '@entur-partner/util';\nimport { Permission } from '@entur-partner/permission-client-node';\n\nimport { User } from './User';\n\ninterface AppContextType {\n getToken: () => Promise<string>;\n user: User;\n logout?: () => void;\n activeOrgId: number;\n navigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n undefined\n);\n\nexport const useUser = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.user;\n};\n\nexport const useActiveOrgId = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n children: ReactNode;\n getToken: () => Promise<string>;\n user: User;\n getPermissions: () => Promise<Permission[]>;\n organisationId: string;\n navigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n children,\n organisationId,\n getPermissions,\n ...rest\n}) => {\n const [permissions, setPermissions] = useState<Permission[]>([]);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const fetchedPermissions = await getPermissions();\n setPermissions(fetchedPermissions);\n } catch (error) {\n console.error(\n 'Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:',\n error\n );\n }\n }\n\n fetchData();\n }, [getPermissions]);\n\n return (\n <AppContext.Provider\n value={{\n ...rest,\n user: { ...rest.user, permissions: permissions },\n activeOrgId: Number(organisationId),\n }}\n >\n {children}\n </AppContext.Provider>\n );\n};\n","/*global EventListener*/\nimport { MicroFrontendPayload } from './Payload';\nimport {\n MountEvent,\n UnmountEvent,\n MOUNT_EVENT_TYPE,\n UNMOUNT_EVENT_TYPE,\n} from './events';\n\ninterface Config {\n microFrontendId: string;\n mount: (\n mountPoint: HTMLDivElement,\n payload: MicroFrontendPayload,\n deprecatedMountPoint: HTMLDivElement\n ) => void;\n unmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n const { unmount, microFrontendId, mount } = config;\n\n window.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n mount(\n event.detail.mountPoint,\n event.detail.payload,\n event.detail.mountPoint\n );\n }) as EventListener);\n\n window.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n unmount(event.detail.mountPoint);\n }) as EventListener);\n}\n"],"names":["RouteChangeEvent","_CustomEvent","apply","this","arguments","_wrapNativeSuper","CustomEvent","AppContext","React","createContext","undefined","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","_fetchData","_asyncToGenerator","_regeneratorRuntime","mark","_callee","wrap","_context","prev","next","sent","t0","console","error","stop","fetchData","createElement","Provider","value","_extends","user","activeOrgId","Number","detail","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload","context","useContext","assertIsDefined","navigate"],"mappings":"mtQA2BO,IASMA,WAAiBC,WAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAC,KAAAC,YAAAD,KAAA,SAAAF,KAAAD,yEAAAA,GAAAK,EAAQC,+DCtBzBC,EAAaC,EAAK,QAACC,mBAC9BC,uBA8B+C,SAAzBC,GAKnB,IAJHC,EAAQD,EAARC,SACAC,EAAcF,EAAdE,eACAC,EAAcH,EAAdG,eACGC,oIAAIC,CAAAL,EAAAM,GAEPC,EAAsCC,EAAQA,SAAe,IAAtDC,EAAWF,EAAA,GAAEG,EAAcH,EAAA,GAkBlC,OAhBAI,EAAAA,WAAU,WACgB,SAAAC,IAUvB,OAVuBA,EAAAC,EAAAC,IAAAC,MAAxB,SAAAC,IAAA,OAAAF,IAAAG,MAAA,SAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE,MAAA,KAAA,EAAA,OAAAF,EAAAC,KAAA,EAAAD,EAAAE,KAAA,EAEqCjB,IAAgB,KAAA,EACjDO,EADwBQ,EAAAG,MACWH,EAAAE,KAAA,GAAA,MAAA,KAAA,EAAAF,EAAAC,KAAA,EAAAD,EAAAI,GAAAJ,EAAA,MAAA,GAEnCK,QAAQC,MACN,iHAAgHN,EAAAI,IAEhH,KAAA,GAAA,IAAA,MAAA,OAAAJ,EAAAO,UAAAT,EAAA,KAAA,CAAA,CAAA,EAAA,UAELzB,MAAAC,KAAAC,YAXY,WACWmB,EAAArB,MAAAC,KAAAC,WAYxBiC,KACC,CAACvB,IAGFN,UAAC8B,cAAA/B,EAAWgC,SAAQ,CAClBC,MAAKC,EAAA,GACA1B,EAAI,CACP2B,KAAID,EAAO1B,GAAAA,EAAK2B,KAAI,CAAEtB,YAAaA,IACnCuB,YAAaC,OAAO/B,MAGrBD,6BDhEyB,uDAcO,0FAbL,kDAK5B,SAA2BiC,GAC/B,OAAO,IAAIvC,YAPmB,uBAO6B,CAAEuC,OAAAA,gCAGzD,SAA6BA,GACjC,OAAO,IAAIvC,YAVqB,yBAU+B,CAAEuC,OAAAA,mCEL7D,SAAgCC,GACpC,IAAQC,EAAoCD,EAApCC,QAASC,EAA2BF,EAA3BE,gBAAiBC,EAAUH,EAAVG,MAElCC,OAAOC,iBFTuB,wBESa,SAACC,GACrCA,EAAMP,OAAOQ,GAAGC,WAAWN,IAGhCC,EACEG,EAAMP,OAAOU,WACbH,EAAMP,OAAOW,QACbJ,EAAMP,OAAOU,eAIjBL,OAAOC,iBFnByB,0BEmBa,SAACC,GACvCA,EAAMP,OAAOQ,GAAGC,WAAWN,IAGhCD,EAAQK,EAAMP,OAAOU,uCDbK,WAC5B,IAAME,EAAUC,aAAWnD,GAE3B,OADAoD,EAAeA,gBAACF,GACTA,EAAQd,iCAYU,WACzB,IAAMc,EAAUC,aAAWnD,GAE3B,OADAoD,EAAeA,gBAACF,GACTA,EAAQG,0BAxBM,WACrB,IAAMH,EAAUC,aAAWnD,GAE3B,OADAoD,EAAeA,gBAACF,GACTA,EAAQf"}
|
|
@@ -2,20 +2,16 @@ import React, { useContext, useState, useEffect } from 'react';
|
|
|
2
2
|
import { assertIsDefined } from '@entur-partner/util';
|
|
3
3
|
|
|
4
4
|
function _regeneratorRuntime() {
|
|
5
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
6
|
-
|
|
7
5
|
_regeneratorRuntime = function () {
|
|
8
6
|
return exports;
|
|
9
7
|
};
|
|
10
|
-
|
|
11
8
|
var exports = {},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
Op = Object.prototype,
|
|
10
|
+
hasOwn = Op.hasOwnProperty,
|
|
11
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
12
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
13
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
14
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
19
15
|
function define(obj, key, value) {
|
|
20
16
|
return Object.defineProperty(obj, key, {
|
|
21
17
|
value: value,
|
|
@@ -24,7 +20,6 @@ function _regeneratorRuntime() {
|
|
|
24
20
|
writable: !0
|
|
25
21
|
}), obj[key];
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
try {
|
|
29
24
|
define({}, "");
|
|
30
25
|
} catch (err) {
|
|
@@ -32,40 +27,33 @@ function _regeneratorRuntime() {
|
|
|
32
27
|
return obj[key] = value;
|
|
33
28
|
};
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
37
31
|
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
generator = Object.create(protoGenerator.prototype),
|
|
33
|
+
context = new Context(tryLocsList || []);
|
|
40
34
|
return generator._invoke = function (innerFn, self, context) {
|
|
41
35
|
var state = "suspendedStart";
|
|
42
36
|
return function (method, arg) {
|
|
43
37
|
if ("executing" === state) throw new Error("Generator is already running");
|
|
44
|
-
|
|
45
38
|
if ("completed" === state) {
|
|
46
39
|
if ("throw" === method) throw arg;
|
|
47
40
|
return doneResult();
|
|
48
41
|
}
|
|
49
|
-
|
|
50
42
|
for (context.method = method, context.arg = arg;;) {
|
|
51
43
|
var delegate = context.delegate;
|
|
52
|
-
|
|
53
44
|
if (delegate) {
|
|
54
45
|
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
55
|
-
|
|
56
46
|
if (delegateResult) {
|
|
57
47
|
if (delegateResult === ContinueSentinel) continue;
|
|
58
48
|
return delegateResult;
|
|
59
49
|
}
|
|
60
50
|
}
|
|
61
|
-
|
|
62
51
|
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
63
52
|
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
64
53
|
context.dispatchException(context.arg);
|
|
65
54
|
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
66
55
|
state = "executing";
|
|
67
56
|
var record = tryCatch(innerFn, self, context);
|
|
68
|
-
|
|
69
57
|
if ("normal" === record.type) {
|
|
70
58
|
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
71
59
|
return {
|
|
@@ -73,13 +61,11 @@ function _regeneratorRuntime() {
|
|
|
73
61
|
done: context.done
|
|
74
62
|
};
|
|
75
63
|
}
|
|
76
|
-
|
|
77
64
|
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
78
65
|
}
|
|
79
66
|
};
|
|
80
67
|
}(innerFn, self, context), generator;
|
|
81
68
|
}
|
|
82
|
-
|
|
83
69
|
function tryCatch(fn, obj, arg) {
|
|
84
70
|
try {
|
|
85
71
|
return {
|
|
@@ -93,25 +79,19 @@ function _regeneratorRuntime() {
|
|
|
93
79
|
};
|
|
94
80
|
}
|
|
95
81
|
}
|
|
96
|
-
|
|
97
82
|
exports.wrap = wrap;
|
|
98
83
|
var ContinueSentinel = {};
|
|
99
|
-
|
|
100
84
|
function Generator() {}
|
|
101
|
-
|
|
102
85
|
function GeneratorFunction() {}
|
|
103
|
-
|
|
104
86
|
function GeneratorFunctionPrototype() {}
|
|
105
|
-
|
|
106
87
|
var IteratorPrototype = {};
|
|
107
88
|
define(IteratorPrototype, iteratorSymbol, function () {
|
|
108
89
|
return this;
|
|
109
90
|
});
|
|
110
91
|
var getProto = Object.getPrototypeOf,
|
|
111
|
-
|
|
92
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
112
93
|
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
113
94
|
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
114
|
-
|
|
115
95
|
function defineIteratorMethods(prototype) {
|
|
116
96
|
["next", "throw", "return"].forEach(function (method) {
|
|
117
97
|
define(prototype, method, function (arg) {
|
|
@@ -119,14 +99,12 @@ function _regeneratorRuntime() {
|
|
|
119
99
|
});
|
|
120
100
|
});
|
|
121
101
|
}
|
|
122
|
-
|
|
123
102
|
function AsyncIterator(generator, PromiseImpl) {
|
|
124
103
|
function invoke(method, arg, resolve, reject) {
|
|
125
104
|
var record = tryCatch(generator[method], generator, arg);
|
|
126
|
-
|
|
127
105
|
if ("throw" !== record.type) {
|
|
128
106
|
var result = record.arg,
|
|
129
|
-
|
|
107
|
+
value = result.value;
|
|
130
108
|
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
131
109
|
invoke("next", value, resolve, reject);
|
|
132
110
|
}, function (err) {
|
|
@@ -137,89 +115,71 @@ function _regeneratorRuntime() {
|
|
|
137
115
|
return invoke("throw", error, resolve, reject);
|
|
138
116
|
});
|
|
139
117
|
}
|
|
140
|
-
|
|
141
118
|
reject(record.arg);
|
|
142
119
|
}
|
|
143
|
-
|
|
144
120
|
var previousPromise;
|
|
145
|
-
|
|
146
121
|
this._invoke = function (method, arg) {
|
|
147
122
|
function callInvokeWithMethodAndArg() {
|
|
148
123
|
return new PromiseImpl(function (resolve, reject) {
|
|
149
124
|
invoke(method, arg, resolve, reject);
|
|
150
125
|
});
|
|
151
126
|
}
|
|
152
|
-
|
|
153
127
|
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
154
128
|
};
|
|
155
129
|
}
|
|
156
|
-
|
|
157
130
|
function maybeInvokeDelegate(delegate, context) {
|
|
158
131
|
var method = delegate.iterator[context.method];
|
|
159
|
-
|
|
160
132
|
if (undefined === method) {
|
|
161
133
|
if (context.delegate = null, "throw" === context.method) {
|
|
162
134
|
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
|
|
163
135
|
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
|
|
164
136
|
}
|
|
165
|
-
|
|
166
137
|
return ContinueSentinel;
|
|
167
138
|
}
|
|
168
|
-
|
|
169
139
|
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
170
140
|
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
171
141
|
var info = record.arg;
|
|
172
142
|
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
173
143
|
}
|
|
174
|
-
|
|
175
144
|
function pushTryEntry(locs) {
|
|
176
145
|
var entry = {
|
|
177
146
|
tryLoc: locs[0]
|
|
178
147
|
};
|
|
179
148
|
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
180
149
|
}
|
|
181
|
-
|
|
182
150
|
function resetTryEntry(entry) {
|
|
183
151
|
var record = entry.completion || {};
|
|
184
152
|
record.type = "normal", delete record.arg, entry.completion = record;
|
|
185
153
|
}
|
|
186
|
-
|
|
187
154
|
function Context(tryLocsList) {
|
|
188
155
|
this.tryEntries = [{
|
|
189
156
|
tryLoc: "root"
|
|
190
157
|
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
191
158
|
}
|
|
192
|
-
|
|
193
159
|
function values(iterable) {
|
|
194
160
|
if (iterable) {
|
|
195
161
|
var iteratorMethod = iterable[iteratorSymbol];
|
|
196
162
|
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
197
163
|
if ("function" == typeof iterable.next) return iterable;
|
|
198
|
-
|
|
199
164
|
if (!isNaN(iterable.length)) {
|
|
200
165
|
var i = -1,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
};
|
|
206
|
-
|
|
166
|
+
next = function next() {
|
|
167
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
168
|
+
return next.value = undefined, next.done = !0, next;
|
|
169
|
+
};
|
|
207
170
|
return next.next = next;
|
|
208
171
|
}
|
|
209
172
|
}
|
|
210
|
-
|
|
211
173
|
return {
|
|
212
174
|
next: doneResult
|
|
213
175
|
};
|
|
214
176
|
}
|
|
215
|
-
|
|
216
177
|
function doneResult() {
|
|
217
178
|
return {
|
|
218
179
|
value: undefined,
|
|
219
180
|
done: !0
|
|
220
181
|
};
|
|
221
182
|
}
|
|
222
|
-
|
|
223
183
|
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
224
184
|
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
225
185
|
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
@@ -243,15 +203,12 @@ function _regeneratorRuntime() {
|
|
|
243
203
|
return "[object Generator]";
|
|
244
204
|
}), exports.keys = function (object) {
|
|
245
205
|
var keys = [];
|
|
246
|
-
|
|
247
206
|
for (var key in object) keys.push(key);
|
|
248
|
-
|
|
249
207
|
return keys.reverse(), function next() {
|
|
250
208
|
for (; keys.length;) {
|
|
251
209
|
var key = keys.pop();
|
|
252
210
|
if (key in object) return next.value = key, next.done = !1, next;
|
|
253
211
|
}
|
|
254
|
-
|
|
255
212
|
return next.done = !0, next;
|
|
256
213
|
};
|
|
257
214
|
}, exports.values = values, Context.prototype = {
|
|
@@ -268,20 +225,16 @@ function _regeneratorRuntime() {
|
|
|
268
225
|
dispatchException: function (exception) {
|
|
269
226
|
if (this.done) throw exception;
|
|
270
227
|
var context = this;
|
|
271
|
-
|
|
272
228
|
function handle(loc, caught) {
|
|
273
229
|
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
274
230
|
}
|
|
275
|
-
|
|
276
231
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
277
232
|
var entry = this.tryEntries[i],
|
|
278
|
-
|
|
233
|
+
record = entry.completion;
|
|
279
234
|
if ("root" === entry.tryLoc) return handle("end");
|
|
280
|
-
|
|
281
235
|
if (entry.tryLoc <= this.prev) {
|
|
282
236
|
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
283
|
-
|
|
284
|
-
|
|
237
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
285
238
|
if (hasCatch && hasFinally) {
|
|
286
239
|
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
287
240
|
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
@@ -297,13 +250,11 @@ function _regeneratorRuntime() {
|
|
|
297
250
|
abrupt: function (type, arg) {
|
|
298
251
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
299
252
|
var entry = this.tryEntries[i];
|
|
300
|
-
|
|
301
253
|
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
302
254
|
var finallyEntry = entry;
|
|
303
255
|
break;
|
|
304
256
|
}
|
|
305
257
|
}
|
|
306
|
-
|
|
307
258
|
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
308
259
|
var record = finallyEntry ? finallyEntry.completion : {};
|
|
309
260
|
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
@@ -321,19 +272,15 @@ function _regeneratorRuntime() {
|
|
|
321
272
|
catch: function (tryLoc) {
|
|
322
273
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
323
274
|
var entry = this.tryEntries[i];
|
|
324
|
-
|
|
325
275
|
if (entry.tryLoc === tryLoc) {
|
|
326
276
|
var record = entry.completion;
|
|
327
|
-
|
|
328
277
|
if ("throw" === record.type) {
|
|
329
278
|
var thrown = record.arg;
|
|
330
279
|
resetTryEntry(entry);
|
|
331
280
|
}
|
|
332
|
-
|
|
333
281
|
return thrown;
|
|
334
282
|
}
|
|
335
283
|
}
|
|
336
|
-
|
|
337
284
|
throw new Error("illegal catch attempt");
|
|
338
285
|
},
|
|
339
286
|
delegateYield: function (iterable, resultName, nextLoc) {
|
|
@@ -345,7 +292,6 @@ function _regeneratorRuntime() {
|
|
|
345
292
|
}
|
|
346
293
|
}, exports;
|
|
347
294
|
}
|
|
348
|
-
|
|
349
295
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
350
296
|
try {
|
|
351
297
|
var info = gen[key](arg);
|
|
@@ -354,65 +300,53 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
354
300
|
reject(error);
|
|
355
301
|
return;
|
|
356
302
|
}
|
|
357
|
-
|
|
358
303
|
if (info.done) {
|
|
359
304
|
resolve(value);
|
|
360
305
|
} else {
|
|
361
306
|
Promise.resolve(value).then(_next, _throw);
|
|
362
307
|
}
|
|
363
308
|
}
|
|
364
|
-
|
|
365
309
|
function _asyncToGenerator(fn) {
|
|
366
310
|
return function () {
|
|
367
311
|
var self = this,
|
|
368
|
-
|
|
312
|
+
args = arguments;
|
|
369
313
|
return new Promise(function (resolve, reject) {
|
|
370
314
|
var gen = fn.apply(self, args);
|
|
371
|
-
|
|
372
315
|
function _next(value) {
|
|
373
316
|
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
374
317
|
}
|
|
375
|
-
|
|
376
318
|
function _throw(err) {
|
|
377
319
|
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
378
320
|
}
|
|
379
|
-
|
|
380
321
|
_next(undefined);
|
|
381
322
|
});
|
|
382
323
|
};
|
|
383
324
|
}
|
|
384
|
-
|
|
385
325
|
function _extends() {
|
|
386
326
|
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
387
327
|
for (var i = 1; i < arguments.length; i++) {
|
|
388
328
|
var source = arguments[i];
|
|
389
|
-
|
|
390
329
|
for (var key in source) {
|
|
391
330
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
392
331
|
target[key] = source[key];
|
|
393
332
|
}
|
|
394
333
|
}
|
|
395
334
|
}
|
|
396
|
-
|
|
397
335
|
return target;
|
|
398
336
|
};
|
|
399
337
|
return _extends.apply(this, arguments);
|
|
400
338
|
}
|
|
401
|
-
|
|
402
339
|
function _inheritsLoose(subClass, superClass) {
|
|
403
340
|
subClass.prototype = Object.create(superClass.prototype);
|
|
404
341
|
subClass.prototype.constructor = subClass;
|
|
405
|
-
|
|
406
342
|
_setPrototypeOf(subClass, superClass);
|
|
407
343
|
}
|
|
408
|
-
|
|
409
344
|
function _getPrototypeOf(o) {
|
|
410
345
|
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
411
346
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
412
347
|
};
|
|
413
348
|
return _getPrototypeOf(o);
|
|
414
349
|
}
|
|
415
|
-
|
|
416
350
|
function _setPrototypeOf(o, p) {
|
|
417
351
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
418
352
|
o.__proto__ = p;
|
|
@@ -420,12 +354,10 @@ function _setPrototypeOf(o, p) {
|
|
|
420
354
|
};
|
|
421
355
|
return _setPrototypeOf(o, p);
|
|
422
356
|
}
|
|
423
|
-
|
|
424
357
|
function _isNativeReflectConstruct() {
|
|
425
358
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
426
359
|
if (Reflect.construct.sham) return false;
|
|
427
360
|
if (typeof Proxy === "function") return true;
|
|
428
|
-
|
|
429
361
|
try {
|
|
430
362
|
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
431
363
|
return true;
|
|
@@ -433,7 +365,6 @@ function _isNativeReflectConstruct() {
|
|
|
433
365
|
return false;
|
|
434
366
|
}
|
|
435
367
|
}
|
|
436
|
-
|
|
437
368
|
function _construct(Parent, args, Class) {
|
|
438
369
|
if (_isNativeReflectConstruct()) {
|
|
439
370
|
_construct = Reflect.construct.bind();
|
|
@@ -447,34 +378,25 @@ function _construct(Parent, args, Class) {
|
|
|
447
378
|
return instance;
|
|
448
379
|
};
|
|
449
380
|
}
|
|
450
|
-
|
|
451
381
|
return _construct.apply(null, arguments);
|
|
452
382
|
}
|
|
453
|
-
|
|
454
383
|
function _isNativeFunction(fn) {
|
|
455
384
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
456
385
|
}
|
|
457
|
-
|
|
458
386
|
function _wrapNativeSuper(Class) {
|
|
459
387
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
460
|
-
|
|
461
388
|
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
462
389
|
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
463
|
-
|
|
464
390
|
if (typeof Class !== "function") {
|
|
465
391
|
throw new TypeError("Super expression must either be null or a function");
|
|
466
392
|
}
|
|
467
|
-
|
|
468
393
|
if (typeof _cache !== "undefined") {
|
|
469
394
|
if (_cache.has(Class)) return _cache.get(Class);
|
|
470
|
-
|
|
471
395
|
_cache.set(Class, Wrapper);
|
|
472
396
|
}
|
|
473
|
-
|
|
474
397
|
function Wrapper() {
|
|
475
398
|
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
476
399
|
}
|
|
477
|
-
|
|
478
400
|
Wrapper.prototype = Object.create(Class.prototype, {
|
|
479
401
|
constructor: {
|
|
480
402
|
value: Wrapper,
|
|
@@ -485,22 +407,18 @@ function _wrapNativeSuper(Class) {
|
|
|
485
407
|
});
|
|
486
408
|
return _setPrototypeOf(Wrapper, Class);
|
|
487
409
|
};
|
|
488
|
-
|
|
489
410
|
return _wrapNativeSuper(Class);
|
|
490
411
|
}
|
|
491
|
-
|
|
492
412
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
493
413
|
if (source == null) return {};
|
|
494
414
|
var target = {};
|
|
495
415
|
var sourceKeys = Object.keys(source);
|
|
496
416
|
var key, i;
|
|
497
|
-
|
|
498
417
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
499
418
|
key = sourceKeys[i];
|
|
500
419
|
if (excluded.indexOf(key) >= 0) continue;
|
|
501
420
|
target[key] = source[key];
|
|
502
421
|
}
|
|
503
|
-
|
|
504
422
|
return target;
|
|
505
423
|
}
|
|
506
424
|
|
|
@@ -519,30 +437,26 @@ function createUnmountEvent(detail) {
|
|
|
519
437
|
var ROUTE_CHANGE_EVENT_TYPE = '@entur-partner:after-route-change';
|
|
520
438
|
var RouteChangeEvent = /*#__PURE__*/function (_CustomEvent) {
|
|
521
439
|
_inheritsLoose(RouteChangeEvent, _CustomEvent);
|
|
522
|
-
|
|
523
440
|
function RouteChangeEvent() {
|
|
524
441
|
return _CustomEvent.apply(this, arguments) || this;
|
|
525
442
|
}
|
|
526
|
-
|
|
527
443
|
return RouteChangeEvent;
|
|
528
444
|
}( /*#__PURE__*/_wrapNativeSuper(CustomEvent));
|
|
529
445
|
|
|
530
446
|
function registerMicroFrontend(config) {
|
|
531
447
|
var unmount = config.unmount,
|
|
532
|
-
|
|
533
|
-
|
|
448
|
+
microFrontendId = config.microFrontendId,
|
|
449
|
+
mount = config.mount;
|
|
534
450
|
window.addEventListener(MOUNT_EVENT_TYPE, function (event) {
|
|
535
451
|
if (!event.detail.id.startsWith(microFrontendId)) {
|
|
536
452
|
return;
|
|
537
453
|
}
|
|
538
|
-
|
|
539
454
|
mount(event.detail.mountPoint, event.detail.payload, event.detail.mountPoint);
|
|
540
455
|
});
|
|
541
456
|
window.addEventListener(UNMOUNT_EVENT_TYPE, function (event) {
|
|
542
457
|
if (!event.detail.id.startsWith(microFrontendId)) {
|
|
543
458
|
return;
|
|
544
459
|
}
|
|
545
|
-
|
|
546
460
|
unmount(event.detail.mountPoint);
|
|
547
461
|
});
|
|
548
462
|
}
|
|
@@ -566,51 +480,42 @@ var useNavigate = function useNavigate() {
|
|
|
566
480
|
};
|
|
567
481
|
var AppProvider = function AppProvider(_ref) {
|
|
568
482
|
var children = _ref.children,
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
483
|
+
organisationId = _ref.organisationId,
|
|
484
|
+
getPermissions = _ref.getPermissions,
|
|
485
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
573
486
|
var _useState = useState([]),
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
487
|
+
permissions = _useState[0],
|
|
488
|
+
setPermissions = _useState[1];
|
|
577
489
|
useEffect(function () {
|
|
578
490
|
function fetchData() {
|
|
579
491
|
return _fetchData.apply(this, arguments);
|
|
580
492
|
}
|
|
581
|
-
|
|
582
493
|
function _fetchData() {
|
|
583
494
|
_fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
584
495
|
var fetchedPermissions;
|
|
585
496
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
586
|
-
while (1) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
case 10:
|
|
605
|
-
case "end":
|
|
606
|
-
return _context.stop();
|
|
607
|
-
}
|
|
497
|
+
while (1) switch (_context.prev = _context.next) {
|
|
498
|
+
case 0:
|
|
499
|
+
_context.prev = 0;
|
|
500
|
+
_context.next = 3;
|
|
501
|
+
return getPermissions();
|
|
502
|
+
case 3:
|
|
503
|
+
fetchedPermissions = _context.sent;
|
|
504
|
+
setPermissions(fetchedPermissions);
|
|
505
|
+
_context.next = 10;
|
|
506
|
+
break;
|
|
507
|
+
case 7:
|
|
508
|
+
_context.prev = 7;
|
|
509
|
+
_context.t0 = _context["catch"](0);
|
|
510
|
+
console.error('Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:', _context.t0);
|
|
511
|
+
case 10:
|
|
512
|
+
case "end":
|
|
513
|
+
return _context.stop();
|
|
608
514
|
}
|
|
609
515
|
}, _callee, null, [[0, 7]]);
|
|
610
516
|
}));
|
|
611
517
|
return _fetchData.apply(this, arguments);
|
|
612
518
|
}
|
|
613
|
-
|
|
614
519
|
fetchData();
|
|
615
520
|
}, [getPermissions]);
|
|
616
521
|
return React.createElement(AppContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.esm.js","sources":["../src/events.ts","../src/registerMicroFrontend.tsx","../src/AppProvider.tsx"],"sourcesContent":["import { MicroFrontendPayload } from './Payload';\n\ntype MountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n payload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = '@entur-partner:mount';\nexport const UNMOUNT_EVENT_TYPE = '@entur-partner:unmount';\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n return new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n return new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = '@entur-partner:after-route-change';\n\nexport type RouteAction = 'PUSH' | 'POP' | 'REPLACE';\n\ntype RouteChangeEventDetail = {\n location: Location;\n action: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\nimport { MicroFrontendPayload } from './Payload';\nimport {\n MountEvent,\n UnmountEvent,\n MOUNT_EVENT_TYPE,\n UNMOUNT_EVENT_TYPE,\n} from './events';\n\ninterface Config {\n microFrontendId: string;\n mount: (\n mountPoint: HTMLDivElement,\n payload: MicroFrontendPayload,\n deprecatedMountPoint: HTMLDivElement\n ) => void;\n unmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n const { unmount, microFrontendId, mount } = config;\n\n window.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n mount(\n event.detail.mountPoint,\n event.detail.payload,\n event.detail.mountPoint\n );\n }) as EventListener);\n\n window.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n unmount(event.detail.mountPoint);\n }) as EventListener);\n}\n","import React, { FC, ReactNode, useContext, useEffect, useState } from 'react';\nimport { assertIsDefined } from '@entur-partner/util';\nimport { Permission } from '@entur-partner/permission-client-node';\n\nimport { User } from './User';\n\ninterface AppContextType {\n getToken: () => Promise<string>;\n user: User;\n logout?: () => void;\n activeOrgId: number;\n navigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n undefined\n);\n\nexport const useUser = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.user;\n};\n\nexport const useActiveOrgId = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n children: ReactNode;\n getToken: () => Promise<string>;\n user: User;\n getPermissions: () => Promise<Permission[]>;\n organisationId: string;\n navigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n children,\n organisationId,\n getPermissions,\n ...rest\n}) => {\n const [permissions, setPermissions] = useState<Permission[]>([]);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const fetchedPermissions = await getPermissions();\n setPermissions(fetchedPermissions);\n } catch (error) {\n console.error(\n 'Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:',\n error\n );\n }\n }\n\n fetchData();\n }, [getPermissions]);\n\n return (\n <AppContext.Provider\n value={{\n ...rest,\n user: { ...rest.user, permissions: permissions },\n activeOrgId: Number(organisationId),\n }}\n >\n {children}\n </AppContext.Provider>\n );\n};\n"],"names":["MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload","AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","useNavigate","navigate","AppProvider","children","organisationId","getPermissions","rest","useState","permissions","setPermissions","useEffect","fetchData","fetchedPermissions","console","error","createElement","Provider","value","Number"],"mappings":"
|
|
1
|
+
{"version":3,"file":"micro-frontend.esm.js","sources":["../src/events.ts","../src/registerMicroFrontend.tsx","../src/AppProvider.tsx"],"sourcesContent":["import { MicroFrontendPayload } from './Payload';\n\ntype MountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n payload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n id: string;\n mountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = '@entur-partner:mount';\nexport const UNMOUNT_EVENT_TYPE = '@entur-partner:unmount';\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n return new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n return new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = '@entur-partner:after-route-change';\n\nexport type RouteAction = 'PUSH' | 'POP' | 'REPLACE';\n\ntype RouteChangeEventDetail = {\n location: Location;\n action: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\nimport { MicroFrontendPayload } from './Payload';\nimport {\n MountEvent,\n UnmountEvent,\n MOUNT_EVENT_TYPE,\n UNMOUNT_EVENT_TYPE,\n} from './events';\n\ninterface Config {\n microFrontendId: string;\n mount: (\n mountPoint: HTMLDivElement,\n payload: MicroFrontendPayload,\n deprecatedMountPoint: HTMLDivElement\n ) => void;\n unmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n const { unmount, microFrontendId, mount } = config;\n\n window.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n mount(\n event.detail.mountPoint,\n event.detail.payload,\n event.detail.mountPoint\n );\n }) as EventListener);\n\n window.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n if (!event.detail.id.startsWith(microFrontendId)) {\n return;\n }\n unmount(event.detail.mountPoint);\n }) as EventListener);\n}\n","import React, { FC, ReactNode, useContext, useEffect, useState } from 'react';\nimport { assertIsDefined } from '@entur-partner/util';\nimport { Permission } from '@entur-partner/permission-client-node';\n\nimport { User } from './User';\n\ninterface AppContextType {\n getToken: () => Promise<string>;\n user: User;\n logout?: () => void;\n activeOrgId: number;\n navigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n undefined\n);\n\nexport const useUser = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.user;\n};\n\nexport const useActiveOrgId = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n children: ReactNode;\n getToken: () => Promise<string>;\n user: User;\n getPermissions: () => Promise<Permission[]>;\n organisationId: string;\n navigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n const context = useContext(AppContext);\n assertIsDefined(context);\n return context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n children,\n organisationId,\n getPermissions,\n ...rest\n}) => {\n const [permissions, setPermissions] = useState<Permission[]>([]);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const fetchedPermissions = await getPermissions();\n setPermissions(fetchedPermissions);\n } catch (error) {\n console.error(\n 'Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:',\n error\n );\n }\n }\n\n fetchData();\n }, [getPermissions]);\n\n return (\n <AppContext.Provider\n value={{\n ...rest,\n user: { ...rest.user, permissions: permissions },\n activeOrgId: Number(organisationId),\n }}\n >\n {children}\n </AppContext.Provider>\n );\n};\n"],"names":["MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","_CustomEvent","_inheritsLoose","apply","arguments","_wrapNativeSuper","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload","AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","useNavigate","navigate","AppProvider","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","fetchData","_fetchData","_asyncToGenerator","_regeneratorRuntime","mark","_callee","fetchedPermissions","wrap","_callee$","_context","prev","next","sent","t0","console","error","stop","createElement","Provider","value","_extends","Number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaO,IAAMA,gBAAgB,GAAG,uBAAsB;AAC/C,IAAMC,kBAAkB,GAAG,yBAAwB;AAKpD,SAAUC,gBAAgBA,CAACC,MAAwB,EAAA;AACvD,EAAA,OAAO,IAAIC,WAAW,CAAmBJ,gBAAgB,EAAE;AAAEG,IAAAA,MAAM,EAANA,MAAAA;AAAQ,GAAA,CAAC,CAAA;AACxE,CAAA;AAEM,SAAUE,kBAAkBA,CAACF,MAA0B,EAAA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