@entur-partner/micro-frontend 3.0.0-alpha.3 → 3.0.0-alpha.5
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/AppProvider.d.ts +11 -13
- package/dist/index.d.ts +1 -2
- package/dist/micro-frontend.cjs.development.js +12 -216
- package/dist/micro-frontend.cjs.development.js.map +1 -1
- package/dist/micro-frontend.cjs.production.min.js +1 -1
- package/dist/micro-frontend.cjs.production.min.js.map +1 -1
- package/dist/micro-frontend.esm.js +13 -217
- package/dist/micro-frontend.esm.js.map +1 -1
- package/package.json +2 -2
- package/dist/constant.d.ts +0 -1
- package/dist/hooks/useNavigateParams.d.ts +0 -9
package/dist/AppProvider.d.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import type { Permission } from "@entur-partner/permission-client-node";
|
|
2
1
|
import React, { type FC, type ReactNode } from "react";
|
|
2
|
+
import { MicroFrontendPayload } from "./Payload";
|
|
3
3
|
import type { User } from "./User";
|
|
4
|
-
|
|
5
|
-
getToken: () => Promise<string>;
|
|
4
|
+
type AppContextType = MicroFrontendPayload & {
|
|
6
5
|
user: User;
|
|
7
|
-
logout?: () => void;
|
|
8
6
|
activeOrgId: number;
|
|
9
|
-
|
|
10
|
-
}
|
|
7
|
+
};
|
|
11
8
|
export declare const AppContext: React.Context<AppContextType | undefined>;
|
|
12
9
|
export declare const useUser: () => User;
|
|
13
10
|
export declare const useActiveOrgId: () => number;
|
|
14
|
-
export
|
|
11
|
+
export declare const useAppShellContext: () => {
|
|
12
|
+
setMFNavigate: (navigate: import("./Payload").NavigationFunction) => void;
|
|
13
|
+
language: string;
|
|
14
|
+
addMenuItems: (items: import("./Payload").MenuItem[]) => void;
|
|
15
|
+
};
|
|
16
|
+
export type AppProviderProps = MicroFrontendPayload & {
|
|
15
17
|
children: ReactNode;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getPermissions: () => Promise<Permission[]>;
|
|
19
|
-
organisationId: string;
|
|
20
|
-
navigate: (path: string) => void;
|
|
21
|
-
}
|
|
18
|
+
activeOrgId: number;
|
|
19
|
+
};
|
|
22
20
|
export declare const AppProvider: FC<AppProviderProps>;
|
|
23
21
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { AppProvider, AppProviderProps, useActiveOrgId, useUser, } from "./AppProvider";
|
|
1
|
+
export { AppProvider, AppProviderProps, useActiveOrgId, useUser, useAppShellContext, } from "./AppProvider";
|
|
2
2
|
export { createMountEvent, createUnmountEvent, MOUNT_EVENT_TYPE, MountEvent, ROUTE_CHANGE_EVENT_TYPE, RouteAction, RouteChangeEvent, UNMOUNT_EVENT_TYPE, UnmountEvent, } from "./events";
|
|
3
|
-
export { useNavigateParams } from "./hooks/useNavigateParams";
|
|
4
3
|
export { MenuItem, MicroFrontendPayload, NavigationFunction } from "./Payload";
|
|
5
4
|
export { registerMicroFrontend } from "./registerMicroFrontend";
|
|
6
5
|
export { User } from "./User";
|
|
@@ -4,33 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var util = require('@entur-partner/util');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var reactRouterDom = require('react-router-dom');
|
|
8
7
|
|
|
9
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
10
|
-
try {
|
|
11
|
-
var i = n[a](c),
|
|
12
|
-
u = i.value;
|
|
13
|
-
} catch (n) {
|
|
14
|
-
return void e(n);
|
|
15
|
-
}
|
|
16
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
17
|
-
}
|
|
18
|
-
function _asyncToGenerator(n) {
|
|
19
|
-
return function () {
|
|
20
|
-
var t = this,
|
|
21
|
-
e = arguments;
|
|
22
|
-
return new Promise(function (r, o) {
|
|
23
|
-
var a = n.apply(t, e);
|
|
24
|
-
function _next(n) {
|
|
25
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
26
|
-
}
|
|
27
|
-
function _throw(n) {
|
|
28
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
29
|
-
}
|
|
30
|
-
_next(void 0);
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
8
|
function _construct(t, e, r) {
|
|
35
9
|
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
36
10
|
var o = [null];
|
|
@@ -38,15 +12,6 @@ function _construct(t, e, r) {
|
|
|
38
12
|
var p = new (t.bind.apply(t, o))();
|
|
39
13
|
return r && _setPrototypeOf(p, r.prototype), p;
|
|
40
14
|
}
|
|
41
|
-
function _extends() {
|
|
42
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
43
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
44
|
-
var t = arguments[e];
|
|
45
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
46
|
-
}
|
|
47
|
-
return n;
|
|
48
|
-
}, _extends.apply(null, arguments);
|
|
49
|
-
}
|
|
50
15
|
function _getPrototypeOf(t) {
|
|
51
16
|
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
52
17
|
return t.__proto__ || Object.getPrototypeOf(t);
|
|
@@ -79,114 +44,6 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
79
44
|
}
|
|
80
45
|
return t;
|
|
81
46
|
}
|
|
82
|
-
function _regenerator() {
|
|
83
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
84
|
-
var e,
|
|
85
|
-
t,
|
|
86
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
87
|
-
n = r.iterator || "@@iterator",
|
|
88
|
-
o = r.toStringTag || "@@toStringTag";
|
|
89
|
-
function i(r, n, o, i) {
|
|
90
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
91
|
-
u = Object.create(c.prototype);
|
|
92
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
93
|
-
var i,
|
|
94
|
-
c,
|
|
95
|
-
u,
|
|
96
|
-
f = 0,
|
|
97
|
-
p = o || [],
|
|
98
|
-
y = !1,
|
|
99
|
-
G = {
|
|
100
|
-
p: 0,
|
|
101
|
-
n: 0,
|
|
102
|
-
v: e,
|
|
103
|
-
a: d,
|
|
104
|
-
f: d.bind(e, 4),
|
|
105
|
-
d: function (t, r) {
|
|
106
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
function d(r, n) {
|
|
110
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
111
|
-
var o,
|
|
112
|
-
i = p[t],
|
|
113
|
-
d = G.p,
|
|
114
|
-
l = i[2];
|
|
115
|
-
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));
|
|
116
|
-
}
|
|
117
|
-
if (o || r > 1) return a;
|
|
118
|
-
throw y = !0, n;
|
|
119
|
-
}
|
|
120
|
-
return function (o, p, l) {
|
|
121
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
122
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
123
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
124
|
-
try {
|
|
125
|
-
if (f = 2, i) {
|
|
126
|
-
if (c || (o = "next"), t = i[o]) {
|
|
127
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
128
|
-
if (!t.done) return t;
|
|
129
|
-
u = t.value, c < 2 && (c = 0);
|
|
130
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
131
|
-
i = e;
|
|
132
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
133
|
-
} catch (t) {
|
|
134
|
-
i = e, c = 1, u = t;
|
|
135
|
-
} finally {
|
|
136
|
-
f = 1;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
value: t,
|
|
141
|
-
done: y
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
}(r, o, i), !0), u;
|
|
145
|
-
}
|
|
146
|
-
var a = {};
|
|
147
|
-
function Generator() {}
|
|
148
|
-
function GeneratorFunction() {}
|
|
149
|
-
function GeneratorFunctionPrototype() {}
|
|
150
|
-
t = Object.getPrototypeOf;
|
|
151
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
152
|
-
return this;
|
|
153
|
-
}), t),
|
|
154
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
155
|
-
function f(e) {
|
|
156
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
157
|
-
}
|
|
158
|
-
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 () {
|
|
159
|
-
return this;
|
|
160
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
161
|
-
return "[object Generator]";
|
|
162
|
-
}), (_regenerator = function () {
|
|
163
|
-
return {
|
|
164
|
-
w: i,
|
|
165
|
-
m: f
|
|
166
|
-
};
|
|
167
|
-
})();
|
|
168
|
-
}
|
|
169
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
170
|
-
var i = Object.defineProperty;
|
|
171
|
-
try {
|
|
172
|
-
i({}, "", {});
|
|
173
|
-
} catch (e) {
|
|
174
|
-
i = 0;
|
|
175
|
-
}
|
|
176
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
177
|
-
function o(r, n) {
|
|
178
|
-
_regeneratorDefine(e, r, function (e) {
|
|
179
|
-
return this._invoke(r, n, e);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
r ? i ? i(e, r, {
|
|
183
|
-
value: n,
|
|
184
|
-
enumerable: !t,
|
|
185
|
-
configurable: !t,
|
|
186
|
-
writable: !t
|
|
187
|
-
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
188
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
189
|
-
}
|
|
190
47
|
function _setPrototypeOf(t, e) {
|
|
191
48
|
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
192
49
|
return t.__proto__ = e, t;
|
|
@@ -215,7 +72,7 @@ function _wrapNativeSuper(t) {
|
|
|
215
72
|
}, _wrapNativeSuper(t);
|
|
216
73
|
}
|
|
217
74
|
|
|
218
|
-
var _excluded = ["children"
|
|
75
|
+
var _excluded = ["children"];
|
|
219
76
|
var AppContext = /*#__PURE__*/React.createContext(undefined);
|
|
220
77
|
var useUser = function useUser() {
|
|
221
78
|
var context = React.useContext(AppContext);
|
|
@@ -227,52 +84,20 @@ var useActiveOrgId = function useActiveOrgId() {
|
|
|
227
84
|
util.assertIsDefined(context);
|
|
228
85
|
return context.activeOrgId;
|
|
229
86
|
};
|
|
87
|
+
var useAppShellContext = function useAppShellContext() {
|
|
88
|
+
var context = React.useContext(AppContext);
|
|
89
|
+
util.assertIsDefined(context, "useAppShellContext can't be used outside AppProvider");
|
|
90
|
+
return {
|
|
91
|
+
setMFNavigate: context.setMFNavigate,
|
|
92
|
+
language: context.language,
|
|
93
|
+
addMenuItems: context.addMenuItems
|
|
94
|
+
};
|
|
95
|
+
};
|
|
230
96
|
var AppProvider = function AppProvider(_ref) {
|
|
231
97
|
var children = _ref.children,
|
|
232
|
-
organisationId = _ref.organisationId,
|
|
233
|
-
getPermissions = _ref.getPermissions,
|
|
234
98
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
235
|
-
var _useState = React.useState([]),
|
|
236
|
-
permissions = _useState[0],
|
|
237
|
-
setPermissions = _useState[1];
|
|
238
|
-
React.useEffect(function () {
|
|
239
|
-
function fetchData() {
|
|
240
|
-
return _fetchData.apply(this, arguments);
|
|
241
|
-
}
|
|
242
|
-
function _fetchData() {
|
|
243
|
-
_fetchData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
244
|
-
var fetchedPermissions, _t;
|
|
245
|
-
return _regenerator().w(function (_context) {
|
|
246
|
-
while (1) switch (_context.p = _context.n) {
|
|
247
|
-
case 0:
|
|
248
|
-
_context.p = 0;
|
|
249
|
-
_context.n = 1;
|
|
250
|
-
return getPermissions();
|
|
251
|
-
case 1:
|
|
252
|
-
fetchedPermissions = _context.v;
|
|
253
|
-
setPermissions(fetchedPermissions);
|
|
254
|
-
_context.n = 3;
|
|
255
|
-
break;
|
|
256
|
-
case 2:
|
|
257
|
-
_context.p = 2;
|
|
258
|
-
_t = _context.v;
|
|
259
|
-
console.error("Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:", _t);
|
|
260
|
-
case 3:
|
|
261
|
-
return _context.a(2);
|
|
262
|
-
}
|
|
263
|
-
}, _callee, null, [[0, 2]]);
|
|
264
|
-
}));
|
|
265
|
-
return _fetchData.apply(this, arguments);
|
|
266
|
-
}
|
|
267
|
-
fetchData();
|
|
268
|
-
}, [getPermissions]);
|
|
269
99
|
return React.createElement(AppContext.Provider, {
|
|
270
|
-
value:
|
|
271
|
-
user: _extends({}, rest.user, {
|
|
272
|
-
permissions: permissions
|
|
273
|
-
}),
|
|
274
|
-
activeOrgId: Number(organisationId)
|
|
275
|
-
})
|
|
100
|
+
value: rest
|
|
276
101
|
}, children);
|
|
277
102
|
};
|
|
278
103
|
|
|
@@ -297,35 +122,6 @@ var RouteChangeEvent = /*#__PURE__*/function (_CustomEvent) {
|
|
|
297
122
|
return RouteChangeEvent;
|
|
298
123
|
}(/*#__PURE__*/_wrapNativeSuper(CustomEvent));
|
|
299
124
|
|
|
300
|
-
var PARAMS_TO_KEEP = ["organisationId"];
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State
|
|
304
|
-
*
|
|
305
|
-
* @param to can be a string path, a To object, or a number (delta)
|
|
306
|
-
* @param options contains options for modifying the navigation
|
|
307
|
-
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
308
|
-
*/
|
|
309
|
-
var useNavigateParams = function useNavigateParams() {
|
|
310
|
-
var navigate = reactRouterDom.useNavigate();
|
|
311
|
-
var _useSearchParams = reactRouterDom.useSearchParams(),
|
|
312
|
-
searchParams = _useSearchParams[0];
|
|
313
|
-
var modifiedSearchParams = PARAMS_TO_KEEP.reduce(function (params, key) {
|
|
314
|
-
var value = searchParams.get(key);
|
|
315
|
-
if (value) {
|
|
316
|
-
params.append(key, value);
|
|
317
|
-
}
|
|
318
|
-
return params;
|
|
319
|
-
}, new URLSearchParams());
|
|
320
|
-
return function (to, options) {
|
|
321
|
-
return navigate(to, _extends({
|
|
322
|
-
state: _extends({}, options == null ? void 0 : options.state, {
|
|
323
|
-
searchParams: modifiedSearchParams.toString()
|
|
324
|
-
})
|
|
325
|
-
}, options));
|
|
326
|
-
};
|
|
327
|
-
};
|
|
328
|
-
|
|
329
125
|
/*global EventListener*/
|
|
330
126
|
function registerMicroFrontend(config) {
|
|
331
127
|
var unmount = config.unmount,
|
|
@@ -354,6 +150,6 @@ exports.createMountEvent = createMountEvent;
|
|
|
354
150
|
exports.createUnmountEvent = createUnmountEvent;
|
|
355
151
|
exports.registerMicroFrontend = registerMicroFrontend;
|
|
356
152
|
exports.useActiveOrgId = useActiveOrgId;
|
|
357
|
-
exports.
|
|
153
|
+
exports.useAppShellContext = useAppShellContext;
|
|
358
154
|
exports.useUser = useUser;
|
|
359
155
|
//# sourceMappingURL=micro-frontend.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.cjs.development.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/constant.ts","../src/hooks/useNavigateParams.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import type { Permission } from \"@entur-partner/permission-client-node\";\nimport { assertIsDefined } from \"@entur-partner/util\";\nimport React, {\n\ttype FC,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseState,\n} from \"react\";\nimport type { User } from \"./User\";\n\ninterface AppContextType {\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tlogout?: () => void;\n\tactiveOrgId: number;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n\tchildren: ReactNode;\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tgetPermissions: () => Promise<Permission[]>;\n\torganisationId: string;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppProvider: FC<AppProviderProps> = ({\n\tchildren,\n\torganisationId,\n\tgetPermissions,\n\t...rest\n}) => {\n\tconst [permissions, setPermissions] = useState<Permission[]>([]);\n\n\tuseEffect(() => {\n\t\tasync function fetchData() {\n\t\t\ttry {\n\t\t\t\tconst fetchedPermissions = await getPermissions();\n\t\t\t\tsetPermissions(fetchedPermissions);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfetchData();\n\t}, [getPermissions]);\n\n\treturn (\n\t\t<AppContext.Provider\n\t\t\tvalue={{\n\t\t\t\t...rest,\n\t\t\t\tuser: { ...rest.user, permissions: permissions },\n\t\t\t\tactiveOrgId: Number(organisationId),\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</AppContext.Provider>\n\t);\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: 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\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn 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\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","export const PARAMS_TO_KEEP = [\"organisationId\"] as const;\n","import {\n\tNavigateOptions,\n\tuseNavigate,\n\tuseSearchParams,\n} from \"react-router-dom\";\n\nimport { PARAMS_TO_KEEP } from \"../constant\";\n\n/**\n * A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State\n *\n * @param to can be a string path, a To object, or a number (delta)\n * @param options contains options for modifying the navigation\n * @returns a function that navigates to the specified path with organisationId in the search params\n */\nexport const useNavigateParams = () => {\n\tconst navigate = useNavigate();\n\tconst [searchParams] = useSearchParams();\n\n\tconst modifiedSearchParams = PARAMS_TO_KEEP.reduce((params, key) => {\n\t\tconst value = searchParams.get(key);\n\t\tif (value) {\n\t\t\tparams.append(key, value);\n\t\t}\n\t\treturn params;\n\t}, new URLSearchParams());\n\n\treturn (to: string, options?: NavigateOptions) =>\n\t\tnavigate(to, {\n\t\t\tstate: {\n\t\t\t\t...options?.state,\n\t\t\t\tsearchParams: modifiedSearchParams.toString(),\n\t\t\t},\n\t\t\t...options,\n\t\t});\n};\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","AppProvider","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","fetchData","_fetchData","apply","arguments","_asyncToGenerator","_regenerator","m","_callee","fetchedPermissions","_t","w","_context","p","n","v","console","error","a","createElement","Provider","value","_extends","Number","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","_CustomEvent","_inheritsLoose","_wrapNativeSuper","PARAMS_TO_KEEP","useNavigateParams","navigate","useNavigate","_useSearchParams","useSearchParams","searchParams","modifiedSearchParams","reduce","params","key","get","append","URLSearchParams","to","options","state","toString","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAAMA,UAAU,gBAAGC,KAAK,CAACC,aAAa,CAC5CC,SAAS,CACT,CAAA;IAEYC,OAAO,GAAG,SAAVA,OAAOA,GAAQ;AAC3B,EAAA,IAAMC,OAAO,GAAGC,gBAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,oBAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACG,IAAI,CAAA;AACpB,EAAC;IAEYC,cAAc,GAAG,SAAjBA,cAAcA,GAAQ;AAClC,EAAA,IAAMJ,OAAO,GAAGC,gBAAU,CAACN,UAAU,CAAC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,"file":"micro-frontend.cjs.development.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import { assertIsDefined } from \"@entur-partner/util\";\nimport React, { type FC, type ReactNode, useContext } from \"react\";\nimport { MicroFrontendPayload } from \"./Payload\";\nimport type { User } from \"./User\";\n\ntype AppContextType = MicroFrontendPayload & {\n\tuser: User;\n\tactiveOrgId: number;\n};\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport const useAppShellContext = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(\n\t\tcontext,\n\t\t\"useAppShellContext can't be used outside AppProvider\",\n\t);\n\treturn {\n\t\tsetMFNavigate: context.setMFNavigate,\n\t\tlanguage: context.language,\n\t\taddMenuItems: context.addMenuItems,\n\t};\n};\n\nexport type AppProviderProps = MicroFrontendPayload & {\n\tchildren: ReactNode;\n\tactiveOrgId: number;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({ children, ...rest }) => {\n\treturn <AppContext.Provider value={rest}>{children}</AppContext.Provider>;\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: 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\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn 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\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","useAppShellContext","setMFNavigate","language","addMenuItems","AppProvider","_ref","children","rest","_objectWithoutPropertiesLoose","_excluded","createElement","Provider","value","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","_CustomEvent","apply","arguments","_inheritsLoose","_wrapNativeSuper","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAMA,UAAU,gBAAGC,KAAK,CAACC,aAAa,CAC5CC,SAAS,CACT,CAAA;IAEYC,OAAO,GAAG,SAAVA,OAAOA,GAAQ;AAC3B,EAAA,IAAMC,OAAO,GAAGC,gBAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,oBAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACG,IAAI,CAAA;AACpB,EAAC;IAEYC,cAAc,GAAG,SAAjBA,cAAcA,GAAQ;AAClC,EAAA,IAAMJ,OAAO,GAAGC,gBAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,oBAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACK,WAAW,CAAA;AAC3B,EAAC;IAEYC,kBAAkB,GAAG,SAArBA,kBAAkBA,GAAQ;AACtC,EAAA,IAAMN,OAAO,GAAGC,gBAAU,CAACN,UAAU,CAAC,CAAA;AACtCO,EAAAA,oBAAe,CACdF,OAAO,EACP,sDAAsD,CACtD,CAAA;EACD,OAAO;IACNO,aAAa,EAAEP,OAAO,CAACO,aAAa;IACpCC,QAAQ,EAAER,OAAO,CAACQ,QAAQ;IAC1BC,YAAY,EAAET,OAAO,CAACS,YAAAA;GACtB,CAAA;AACF,EAAC;IAOYC,WAAW,GAAyB,SAApCA,WAAWA,CAAAC,IAAA,EAAmD;AAAA,EAAA,IAAvBC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;AAAKC,IAAAA,IAAI,GAAAC,6BAAA,CAAAH,IAAA,EAAAI,SAA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AM,CAACkB,EAAE,CAACC,UAAU,CAACN,eAAe,CAAC,EAAE;AACjD,MAAA,OAAA;AACD,KAAA;AACAC,IAAAA,KAAK,CACJG,KAAK,CAACjB,MAAM,CAACoB,UAAU,EACvBH,KAAK,CAACjB,MAAM,CAACqB,OAAO,EACpBJ,KAAK,CAACjB,MAAM,CAACoB,UAAU,CACvB,CAAA;AACF,GAAmB,CAAC,CAAA;AAEpBL,EAAAA,MAAM,CAACC,gBAAgB,CAAClB,kBAAkB,EAAG,UAACmB,KAAmB,EAAI;IACpE,IAAI,CAACA,KAAK,CAACjB,MAAM,CAACkB,EAAE,CAACC,UAAU,CAACN,eAAe,CAAC,EAAE;AACjD,MAAA,OAAA;AACD,KAAA;AACAD,IAAAA,OAAO,CAACK,KAAK,CAACjB,MAAM,CAACoB,UAAU,CAAC,CAAA;AACjC,GAAmB,CAAC,CAAA;AACrB;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@entur-partner/util"),e=require("react")
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@entur-partner/util"),e=require("react");function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(r=function(){return!!t})()}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function u(t){var e="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,u)}function u(){return function(t,e,n){if(r())return Reflect.construct.apply(null,arguments);var u=[null];u.push.apply(u,e);var i=new(t.bind.apply(t,u));return n&&o(i,n.prototype),i}(t,arguments,n(this).constructor)}return u.prototype=Object.create(t.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),o(u,t)},u(t)}var i=["children"],a=e.createContext(void 0),c="@entur-partner:mount",s="@entur-partner:unmount",p=function(t){function e(){return t.apply(this,arguments)||this}var n,r;return r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,o(n,r),e}(u(CustomEvent));exports.AppProvider=function(t){var n=t.children,r=function(t,e){if(null==t)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(-1!==e.indexOf(r))continue;n[r]=t[r]}return n}(t,i);return e.createElement(a.Provider,{value:r},n)},exports.MOUNT_EVENT_TYPE=c,exports.ROUTE_CHANGE_EVENT_TYPE="@entur-partner:after-route-change",exports.RouteChangeEvent=p,exports.UNMOUNT_EVENT_TYPE=s,exports.createMountEvent=function(t){return new CustomEvent(c,{detail:t})},exports.createUnmountEvent=function(t){return new CustomEvent(s,{detail:t})},exports.registerMicroFrontend=function(t){var e=t.unmount,n=t.microFrontendId,r=t.mount;window.addEventListener(c,function(t){t.detail.id.startsWith(n)&&r(t.detail.mountPoint,t.detail.payload,t.detail.mountPoint)}),window.addEventListener(s,function(t){t.detail.id.startsWith(n)&&e(t.detail.mountPoint)})},exports.useActiveOrgId=function(){var n=e.useContext(a);return t.assertIsDefined(n),n.activeOrgId},exports.useAppShellContext=function(){var n=e.useContext(a);return t.assertIsDefined(n,"useAppShellContext can't be used outside AppProvider"),{setMFNavigate:n.setMFNavigate,language:n.language,addMenuItems:n.addMenuItems}},exports.useUser=function(){var n=e.useContext(a);return t.assertIsDefined(n),n.user};
|
|
2
2
|
//# sourceMappingURL=micro-frontend.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/
|
|
1
|
+
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import { assertIsDefined } from \"@entur-partner/util\";\nimport React, { type FC, type ReactNode, useContext } from \"react\";\nimport { MicroFrontendPayload } from \"./Payload\";\nimport type { User } from \"./User\";\n\ntype AppContextType = MicroFrontendPayload & {\n\tuser: User;\n\tactiveOrgId: number;\n};\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport const useAppShellContext = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(\n\t\tcontext,\n\t\t\"useAppShellContext can't be used outside AppProvider\",\n\t);\n\treturn {\n\t\tsetMFNavigate: context.setMFNavigate,\n\t\tlanguage: context.language,\n\t\taddMenuItems: context.addMenuItems,\n\t};\n};\n\nexport type AppProviderProps = MicroFrontendPayload & {\n\tchildren: ReactNode;\n\tactiveOrgId: number;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({ children, ...rest }) => {\n\treturn <AppContext.Provider value={rest}>{children}</AppContext.Provider>;\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: 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\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn 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\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","RouteChangeEvent","_CustomEvent","apply","this","arguments","_wrapNativeSuper","CustomEvent","_ref","children","rest","_objectWithoutPropertiesLoose","_excluded","createElement","Provider","value","detail","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload","context","useContext","assertIsDefined","activeOrgId","setMFNavigate","language","addMenuItems","user"],"mappings":"uuCAUaA,EAAaC,EAAMC,mBAC/BC,GCEYC,EAAmB,uBACnBC,EAAqB,yBAsBrBC,WAAiBC,GAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAC,KAAAC,YAAAD,IAAA,SAAA,SAAAF,KAAAD,yEAAAA,CAAA,EAAAK,EAAQC,kCDQW,SAAzBC,GAAmD,IAAvBC,EAAQD,EAARC,SAAaC,6IAAIC,CAAAH,EAAAI,GACpE,OAAOhB,EAAAiB,cAAClB,EAAWmB,SAAQ,CAACC,MAAOL,GAAOD,EAC3C,6DCnBuC,qHARjC,SAA2BO,GAChC,OAAO,IAAIT,YAA8BR,EAAkB,CAAEiB,OAAAA,GAC9D,6BAEM,SAA6BA,GAClC,OAAO,IAAIT,YAAgCP,EAAoB,CAAEgB,OAAAA,GAClE,gCCLM,SAAgCC,GACrC,IAAQC,EAAoCD,EAApCC,QAASC,EAA2BF,EAA3BE,gBAAiBC,EAAUH,EAAVG,MAElCC,OAAOC,iBAAiBvB,EAAmB,SAACwB,GACtCA,EAAMP,OAAOQ,GAAGC,WAAWN,IAGhCC,EACCG,EAAMP,OAAOU,WACbH,EAAMP,OAAOW,QACbJ,EAAMP,OAAOU,WAEf,GAEAL,OAAOC,iBAAiBtB,EAAqB,SAACuB,GACxCA,EAAMP,OAAOQ,GAAGC,WAAWN,IAGhCD,EAAQK,EAAMP,OAAOU,WACtB,EACD,yBFpB8B,WAC7B,IAAME,EAAUC,aAAWlC,GAE3B,OADAmC,EAAeA,gBAACF,GACTA,EAAQG,WAChB,6BAEkC,WACjC,IAAMH,EAAUC,aAAWlC,GAK3B,OAJAmC,kBACCF,EACA,wDAEM,CACNI,cAAeJ,EAAQI,cACvBC,SAAUL,EAAQK,SAClBC,aAAcN,EAAQM,aAExB,kBAvBuB,WACtB,IAAMN,EAAUC,aAAWlC,GAE3B,OADAmC,EAAeA,gBAACF,GACTA,EAAQO,IAChB"}
|
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
import { assertIsDefined } from '@entur-partner/util';
|
|
2
|
-
import React, { useContext
|
|
3
|
-
import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
2
|
+
import React, { useContext } from 'react';
|
|
4
3
|
|
|
5
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
6
|
-
try {
|
|
7
|
-
var i = n[a](c),
|
|
8
|
-
u = i.value;
|
|
9
|
-
} catch (n) {
|
|
10
|
-
return void e(n);
|
|
11
|
-
}
|
|
12
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
13
|
-
}
|
|
14
|
-
function _asyncToGenerator(n) {
|
|
15
|
-
return function () {
|
|
16
|
-
var t = this,
|
|
17
|
-
e = arguments;
|
|
18
|
-
return new Promise(function (r, o) {
|
|
19
|
-
var a = n.apply(t, e);
|
|
20
|
-
function _next(n) {
|
|
21
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
22
|
-
}
|
|
23
|
-
function _throw(n) {
|
|
24
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
25
|
-
}
|
|
26
|
-
_next(void 0);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
4
|
function _construct(t, e, r) {
|
|
31
5
|
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
32
6
|
var o = [null];
|
|
@@ -34,15 +8,6 @@ function _construct(t, e, r) {
|
|
|
34
8
|
var p = new (t.bind.apply(t, o))();
|
|
35
9
|
return r && _setPrototypeOf(p, r.prototype), p;
|
|
36
10
|
}
|
|
37
|
-
function _extends() {
|
|
38
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
39
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
40
|
-
var t = arguments[e];
|
|
41
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
42
|
-
}
|
|
43
|
-
return n;
|
|
44
|
-
}, _extends.apply(null, arguments);
|
|
45
|
-
}
|
|
46
11
|
function _getPrototypeOf(t) {
|
|
47
12
|
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
48
13
|
return t.__proto__ || Object.getPrototypeOf(t);
|
|
@@ -75,114 +40,6 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
75
40
|
}
|
|
76
41
|
return t;
|
|
77
42
|
}
|
|
78
|
-
function _regenerator() {
|
|
79
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
80
|
-
var e,
|
|
81
|
-
t,
|
|
82
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
83
|
-
n = r.iterator || "@@iterator",
|
|
84
|
-
o = r.toStringTag || "@@toStringTag";
|
|
85
|
-
function i(r, n, o, i) {
|
|
86
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
87
|
-
u = Object.create(c.prototype);
|
|
88
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
89
|
-
var i,
|
|
90
|
-
c,
|
|
91
|
-
u,
|
|
92
|
-
f = 0,
|
|
93
|
-
p = o || [],
|
|
94
|
-
y = !1,
|
|
95
|
-
G = {
|
|
96
|
-
p: 0,
|
|
97
|
-
n: 0,
|
|
98
|
-
v: e,
|
|
99
|
-
a: d,
|
|
100
|
-
f: d.bind(e, 4),
|
|
101
|
-
d: function (t, r) {
|
|
102
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
function d(r, n) {
|
|
106
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
107
|
-
var o,
|
|
108
|
-
i = p[t],
|
|
109
|
-
d = G.p,
|
|
110
|
-
l = i[2];
|
|
111
|
-
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));
|
|
112
|
-
}
|
|
113
|
-
if (o || r > 1) return a;
|
|
114
|
-
throw y = !0, n;
|
|
115
|
-
}
|
|
116
|
-
return function (o, p, l) {
|
|
117
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
118
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
119
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
120
|
-
try {
|
|
121
|
-
if (f = 2, i) {
|
|
122
|
-
if (c || (o = "next"), t = i[o]) {
|
|
123
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
124
|
-
if (!t.done) return t;
|
|
125
|
-
u = t.value, c < 2 && (c = 0);
|
|
126
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
127
|
-
i = e;
|
|
128
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
129
|
-
} catch (t) {
|
|
130
|
-
i = e, c = 1, u = t;
|
|
131
|
-
} finally {
|
|
132
|
-
f = 1;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
value: t,
|
|
137
|
-
done: y
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
}(r, o, i), !0), u;
|
|
141
|
-
}
|
|
142
|
-
var a = {};
|
|
143
|
-
function Generator() {}
|
|
144
|
-
function GeneratorFunction() {}
|
|
145
|
-
function GeneratorFunctionPrototype() {}
|
|
146
|
-
t = Object.getPrototypeOf;
|
|
147
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
148
|
-
return this;
|
|
149
|
-
}), t),
|
|
150
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
151
|
-
function f(e) {
|
|
152
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
153
|
-
}
|
|
154
|
-
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 () {
|
|
155
|
-
return this;
|
|
156
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
157
|
-
return "[object Generator]";
|
|
158
|
-
}), (_regenerator = function () {
|
|
159
|
-
return {
|
|
160
|
-
w: i,
|
|
161
|
-
m: f
|
|
162
|
-
};
|
|
163
|
-
})();
|
|
164
|
-
}
|
|
165
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
166
|
-
var i = Object.defineProperty;
|
|
167
|
-
try {
|
|
168
|
-
i({}, "", {});
|
|
169
|
-
} catch (e) {
|
|
170
|
-
i = 0;
|
|
171
|
-
}
|
|
172
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
173
|
-
function o(r, n) {
|
|
174
|
-
_regeneratorDefine(e, r, function (e) {
|
|
175
|
-
return this._invoke(r, n, e);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
r ? i ? i(e, r, {
|
|
179
|
-
value: n,
|
|
180
|
-
enumerable: !t,
|
|
181
|
-
configurable: !t,
|
|
182
|
-
writable: !t
|
|
183
|
-
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
184
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
185
|
-
}
|
|
186
43
|
function _setPrototypeOf(t, e) {
|
|
187
44
|
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
188
45
|
return t.__proto__ = e, t;
|
|
@@ -211,7 +68,7 @@ function _wrapNativeSuper(t) {
|
|
|
211
68
|
}, _wrapNativeSuper(t);
|
|
212
69
|
}
|
|
213
70
|
|
|
214
|
-
var _excluded = ["children"
|
|
71
|
+
var _excluded = ["children"];
|
|
215
72
|
var AppContext = /*#__PURE__*/React.createContext(undefined);
|
|
216
73
|
var useUser = function useUser() {
|
|
217
74
|
var context = useContext(AppContext);
|
|
@@ -223,52 +80,20 @@ var useActiveOrgId = function useActiveOrgId() {
|
|
|
223
80
|
assertIsDefined(context);
|
|
224
81
|
return context.activeOrgId;
|
|
225
82
|
};
|
|
83
|
+
var useAppShellContext = function useAppShellContext() {
|
|
84
|
+
var context = useContext(AppContext);
|
|
85
|
+
assertIsDefined(context, "useAppShellContext can't be used outside AppProvider");
|
|
86
|
+
return {
|
|
87
|
+
setMFNavigate: context.setMFNavigate,
|
|
88
|
+
language: context.language,
|
|
89
|
+
addMenuItems: context.addMenuItems
|
|
90
|
+
};
|
|
91
|
+
};
|
|
226
92
|
var AppProvider = function AppProvider(_ref) {
|
|
227
93
|
var children = _ref.children,
|
|
228
|
-
organisationId = _ref.organisationId,
|
|
229
|
-
getPermissions = _ref.getPermissions,
|
|
230
94
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
231
|
-
var _useState = useState([]),
|
|
232
|
-
permissions = _useState[0],
|
|
233
|
-
setPermissions = _useState[1];
|
|
234
|
-
useEffect(function () {
|
|
235
|
-
function fetchData() {
|
|
236
|
-
return _fetchData.apply(this, arguments);
|
|
237
|
-
}
|
|
238
|
-
function _fetchData() {
|
|
239
|
-
_fetchData = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
240
|
-
var fetchedPermissions, _t;
|
|
241
|
-
return _regenerator().w(function (_context) {
|
|
242
|
-
while (1) switch (_context.p = _context.n) {
|
|
243
|
-
case 0:
|
|
244
|
-
_context.p = 0;
|
|
245
|
-
_context.n = 1;
|
|
246
|
-
return getPermissions();
|
|
247
|
-
case 1:
|
|
248
|
-
fetchedPermissions = _context.v;
|
|
249
|
-
setPermissions(fetchedPermissions);
|
|
250
|
-
_context.n = 3;
|
|
251
|
-
break;
|
|
252
|
-
case 2:
|
|
253
|
-
_context.p = 2;
|
|
254
|
-
_t = _context.v;
|
|
255
|
-
console.error("Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:", _t);
|
|
256
|
-
case 3:
|
|
257
|
-
return _context.a(2);
|
|
258
|
-
}
|
|
259
|
-
}, _callee, null, [[0, 2]]);
|
|
260
|
-
}));
|
|
261
|
-
return _fetchData.apply(this, arguments);
|
|
262
|
-
}
|
|
263
|
-
fetchData();
|
|
264
|
-
}, [getPermissions]);
|
|
265
95
|
return React.createElement(AppContext.Provider, {
|
|
266
|
-
value:
|
|
267
|
-
user: _extends({}, rest.user, {
|
|
268
|
-
permissions: permissions
|
|
269
|
-
}),
|
|
270
|
-
activeOrgId: Number(organisationId)
|
|
271
|
-
})
|
|
96
|
+
value: rest
|
|
272
97
|
}, children);
|
|
273
98
|
};
|
|
274
99
|
|
|
@@ -293,35 +118,6 @@ var RouteChangeEvent = /*#__PURE__*/function (_CustomEvent) {
|
|
|
293
118
|
return RouteChangeEvent;
|
|
294
119
|
}(/*#__PURE__*/_wrapNativeSuper(CustomEvent));
|
|
295
120
|
|
|
296
|
-
var PARAMS_TO_KEEP = ["organisationId"];
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State
|
|
300
|
-
*
|
|
301
|
-
* @param to can be a string path, a To object, or a number (delta)
|
|
302
|
-
* @param options contains options for modifying the navigation
|
|
303
|
-
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
304
|
-
*/
|
|
305
|
-
var useNavigateParams = function useNavigateParams() {
|
|
306
|
-
var navigate = useNavigate();
|
|
307
|
-
var _useSearchParams = useSearchParams(),
|
|
308
|
-
searchParams = _useSearchParams[0];
|
|
309
|
-
var modifiedSearchParams = PARAMS_TO_KEEP.reduce(function (params, key) {
|
|
310
|
-
var value = searchParams.get(key);
|
|
311
|
-
if (value) {
|
|
312
|
-
params.append(key, value);
|
|
313
|
-
}
|
|
314
|
-
return params;
|
|
315
|
-
}, new URLSearchParams());
|
|
316
|
-
return function (to, options) {
|
|
317
|
-
return navigate(to, _extends({
|
|
318
|
-
state: _extends({}, options == null ? void 0 : options.state, {
|
|
319
|
-
searchParams: modifiedSearchParams.toString()
|
|
320
|
-
})
|
|
321
|
-
}, options));
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
|
|
325
121
|
/*global EventListener*/
|
|
326
122
|
function registerMicroFrontend(config) {
|
|
327
123
|
var unmount = config.unmount,
|
|
@@ -341,5 +137,5 @@ function registerMicroFrontend(config) {
|
|
|
341
137
|
});
|
|
342
138
|
}
|
|
343
139
|
|
|
344
|
-
export { AppProvider, MOUNT_EVENT_TYPE, ROUTE_CHANGE_EVENT_TYPE, RouteChangeEvent, UNMOUNT_EVENT_TYPE, createMountEvent, createUnmountEvent, registerMicroFrontend, useActiveOrgId,
|
|
140
|
+
export { AppProvider, MOUNT_EVENT_TYPE, ROUTE_CHANGE_EVENT_TYPE, RouteChangeEvent, UNMOUNT_EVENT_TYPE, createMountEvent, createUnmountEvent, registerMicroFrontend, useActiveOrgId, useAppShellContext, useUser };
|
|
345
141
|
//# sourceMappingURL=micro-frontend.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.esm.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/constant.ts","../src/hooks/useNavigateParams.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import type { Permission } from \"@entur-partner/permission-client-node\";\nimport { assertIsDefined } from \"@entur-partner/util\";\nimport React, {\n\ttype FC,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseState,\n} from \"react\";\nimport type { User } from \"./User\";\n\ninterface AppContextType {\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tlogout?: () => void;\n\tactiveOrgId: number;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n\tchildren: ReactNode;\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tgetPermissions: () => Promise<Permission[]>;\n\torganisationId: string;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppProvider: FC<AppProviderProps> = ({\n\tchildren,\n\torganisationId,\n\tgetPermissions,\n\t...rest\n}) => {\n\tconst [permissions, setPermissions] = useState<Permission[]>([]);\n\n\tuseEffect(() => {\n\t\tasync function fetchData() {\n\t\t\ttry {\n\t\t\t\tconst fetchedPermissions = await getPermissions();\n\t\t\t\tsetPermissions(fetchedPermissions);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfetchData();\n\t}, [getPermissions]);\n\n\treturn (\n\t\t<AppContext.Provider\n\t\t\tvalue={{\n\t\t\t\t...rest,\n\t\t\t\tuser: { ...rest.user, permissions: permissions },\n\t\t\t\tactiveOrgId: Number(organisationId),\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</AppContext.Provider>\n\t);\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: 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\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn 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\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","export const PARAMS_TO_KEEP = [\"organisationId\"] as const;\n","import {\n\tNavigateOptions,\n\tuseNavigate,\n\tuseSearchParams,\n} from \"react-router-dom\";\n\nimport { PARAMS_TO_KEEP } from \"../constant\";\n\n/**\n * A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State\n *\n * @param to can be a string path, a To object, or a number (delta)\n * @param options contains options for modifying the navigation\n * @returns a function that navigates to the specified path with organisationId in the search params\n */\nexport const useNavigateParams = () => {\n\tconst navigate = useNavigate();\n\tconst [searchParams] = useSearchParams();\n\n\tconst modifiedSearchParams = PARAMS_TO_KEEP.reduce((params, key) => {\n\t\tconst value = searchParams.get(key);\n\t\tif (value) {\n\t\t\tparams.append(key, value);\n\t\t}\n\t\treturn params;\n\t}, new URLSearchParams());\n\n\treturn (to: string, options?: NavigateOptions) =>\n\t\tnavigate(to, {\n\t\t\tstate: {\n\t\t\t\t...options?.state,\n\t\t\t\tsearchParams: modifiedSearchParams.toString(),\n\t\t\t},\n\t\t\t...options,\n\t\t});\n};\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","AppProvider","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","fetchData","_fetchData","apply","arguments","_asyncToGenerator","_regenerator","m","_callee","fetchedPermissions","_t","w","_context","p","n","v","console","error","a","createElement","Provider","value","_extends","Number","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","_CustomEvent","_inheritsLoose","_wrapNativeSuper","PARAMS_TO_KEEP","useNavigateParams","navigate","useNavigate","_useSearchParams","useSearchParams","searchParams","modifiedSearchParams","reduce","params","key","get","append","URLSearchParams","to","options","state","toString","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAAMA,UAAU,gBAAGC,KAAK,CAACC,aAAa,CAC5CC,SAAS,CACT,CAAA;IAEYC,OAAO,GAAG,SAAVA,OAAOA,GAAQ;AAC3B,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,eAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACG,IAAI,CAAA;AACpB,EAAC;IAEYC,cAAc,GAAG,SAAjBA,cAAcA,GAAQ;AAClC,EAAA,IAAMJ,OAAO,GAAGC,UAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,eAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACK,WAAW,CAAA;AAC3B,EAAC;IAWYC,WAAW,GAAyB,SAApCA,WAAWA,CAAAC,IAAA,EAKnB;AAAA,EAAA,IAJJC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IACRC,cAAc,GAAAF,IAAA,CAAdE,cAAc;IACdC,cAAc,GAAAH,IAAA,CAAdG,cAAc;AACXC,IAAAA,IAAI,GAAAC,6BAAA,CAAAL,IAAA,EAAAM,SAAA,CAAA,CAAA;AAEP,EAAA,IAAAC,SAAA,GAAsCC,QAAQ,CAAe,EAAE,CAAC;AAAzDC,IAAAA,WAAW,GAAAF,SAAA,CAAA,CAAA,CAAA;AAAEG,IAAAA,cAAc,GAAAH,SAAA,CAAA,CAAA,C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hBG,KAAK,CAAA;AAEvCC,EAAAA,MAAM,CAACC,gBAAgB,CAACnC,gBAAgB,EAAG,UAACoC,KAAiB,EAAI;IAChE,IAAI,CAACA,KAAK,CAACjC,MAAM,CAACkC,EAAE,CAACC,UAAU,CAACN,eAAe,CAAC,EAAE;AACjD,MAAA,OAAA;AACD,KAAA;AACAC,IAAAA,KAAK,CACJG,KAAK,CAACjC,MAAM,CAACoC,UAAU,EACvBH,KAAK,CAACjC,MAAM,CAACqC,OAAO,EACpBJ,KAAK,CAACjC,MAAM,CAACoC,UAAU,CACvB,CAAA;AACF,GAAmB,CAAC,CAAA;AAEpBL,EAAAA,MAAM,CAACC,gBAAgB,CAAClC,kBAAkB,EAAG,UAACmC,KAAmB,EAAI;IACpE,IAAI,CAACA,KAAK,CAACjC,MAAM,CAACkC,EAAE,CAACC,UAAU,CAACN,eAAe,CAAC,EAAE;AACjD,MAAA,OAAA;AACD,KAAA;AACAD,IAAAA,OAAO,CAACK,KAAK,CAACjC,MAAM,CAACoC,UAAU,CAAC,CAAA;AACjC,GAAmB,CAAC,CAAA;AACrB;;;;"}
|
|
1
|
+
{"version":3,"file":"micro-frontend.esm.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import { assertIsDefined } from \"@entur-partner/util\";\nimport React, { type FC, type ReactNode, useContext } from \"react\";\nimport { MicroFrontendPayload } from \"./Payload\";\nimport type { User } from \"./User\";\n\ntype AppContextType = MicroFrontendPayload & {\n\tuser: User;\n\tactiveOrgId: number;\n};\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport const useAppShellContext = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(\n\t\tcontext,\n\t\t\"useAppShellContext can't be used outside AppProvider\",\n\t);\n\treturn {\n\t\tsetMFNavigate: context.setMFNavigate,\n\t\tlanguage: context.language,\n\t\taddMenuItems: context.addMenuItems,\n\t};\n};\n\nexport type AppProviderProps = MicroFrontendPayload & {\n\tchildren: ReactNode;\n\tactiveOrgId: number;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({ children, ...rest }) => {\n\treturn <AppContext.Provider value={rest}>{children}</AppContext.Provider>;\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: 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\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn 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\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","useAppShellContext","setMFNavigate","language","addMenuItems","AppProvider","_ref","children","rest","_objectWithoutPropertiesLoose","_excluded","createElement","Provider","value","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","_CustomEvent","apply","arguments","_inheritsLoose","_wrapNativeSuper","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,IAAMA,UAAU,gBAAGC,KAAK,CAACC,aAAa,CAC5CC,SAAS,CACT,CAAA;IAEYC,OAAO,GAAG,SAAVA,OAAOA,GAAQ;AAC3B,EAAA,IAAMC,OAAO,GAAGC,UAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,eAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACG,IAAI,CAAA;AAC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A;AACrB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entur-partner/micro-frontend",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.5",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/micro-frontend.esm.js",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"reportFile": "jest-sonar-report.xml",
|
|
46
46
|
"indent": 4
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f5fa3bee2d9df49b7bb02f1b281fc1b37d2a4314"
|
|
49
49
|
}
|
package/dist/constant.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const PARAMS_TO_KEEP: readonly ["organisationId"];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { NavigateOptions } from "react-router-dom";
|
|
2
|
-
/**
|
|
3
|
-
* A custom hook that wraps the useNavigate hook from react-router-dom for MicroFrontend State
|
|
4
|
-
*
|
|
5
|
-
* @param to can be a string path, a To object, or a number (delta)
|
|
6
|
-
* @param options contains options for modifying the navigation
|
|
7
|
-
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
8
|
-
*/
|
|
9
|
-
export declare const useNavigateParams: () => (to: string, options?: NavigateOptions) => void;
|