@entur-partner/micro-frontend 3.0.0-alpha.1 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useNavigateParams.d.ts +1 -1
- package/dist/micro-frontend.cjs.development.js +8 -6
- 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 +8 -6
- package/dist/micro-frontend.esm.js.map +1 -1
- package/package.json +2 -2
|
@@ -6,4 +6,4 @@ import { NavigateOptions } from "react-router-dom";
|
|
|
6
6
|
* @param options contains options for modifying the navigation
|
|
7
7
|
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
8
8
|
*/
|
|
9
|
-
export declare const useNavigateParams: (to: string, options?: NavigateOptions) => void;
|
|
9
|
+
export declare const useNavigateParams: () => (to: string, options?: NavigateOptions) => void;
|
|
@@ -306,7 +306,7 @@ var PARAMS_TO_KEEP = ["organisationId"];
|
|
|
306
306
|
* @param options contains options for modifying the navigation
|
|
307
307
|
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
308
308
|
*/
|
|
309
|
-
var useNavigateParams = function useNavigateParams(
|
|
309
|
+
var useNavigateParams = function useNavigateParams() {
|
|
310
310
|
var navigate = reactRouterDom.useNavigate();
|
|
311
311
|
var _useSearchParams = reactRouterDom.useSearchParams(),
|
|
312
312
|
searchParams = _useSearchParams[0];
|
|
@@ -317,11 +317,13 @@ var useNavigateParams = function useNavigateParams(to, options) {
|
|
|
317
317
|
}
|
|
318
318
|
return params;
|
|
319
319
|
}, new URLSearchParams());
|
|
320
|
-
return
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
+
};
|
|
325
327
|
};
|
|
326
328
|
|
|
327
329
|
/*global EventListener*/
|
|
@@ -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 = (to: string, options?: NavigateOptions) => {\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 navigate(to, {\n\t\tstate: { ...options?.state, searchParams: modifiedSearchParams.toString() },\n\t\t...options,\n\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","to","options","navigate","useNavigate","_useSearchParams","useSearchParams","searchParams","modifiedSearchParams","reduce","params","key","get","append","URLSearchParams","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,CAAA;EACtCO,oBAAe,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,GAA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AAoB,CAACQ,QAAQ;AAAE,KAAA,CAAA;GACtEd,EAAAA,OAAO,CACV,CAAC,CAAA;AACH;;AC/BA;AAoBM,SAAUe,qBAAqBA,CAACC,MAAc,EAAA;AACnD,EAAA,IAAQC,OAAO,GAA6BD,MAAM,CAA1CC,OAAO;IAAEC,eAAe,GAAYF,MAAM,CAAjCE,eAAe;IAAEC,KAAK,GAAKH,MAAM,CAAhBG,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.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","add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AACnC,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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@entur-partner/util"),e=require("react"),r=require("react-router-dom");function n(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},o.apply(null,arguments)}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(u=function(){return!!t})()}function a(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=Object.create((n&&n.prototype instanceof s?n:s).prototype);return c(a,"_invoke",function(r,n,o){var i,a,c,s=0,f=o||[],p=!1,l={p:0,n:0,v:t,a:v,f:v.bind(t,4),d:function(e,r){return i=e,a=0,c=t,l.n=r,u}};function v(r,n){for(a=r,c=n,e=0;!p&&s&&!o&&e<f.length;e++){var o,i=f[e],v=l.p,d=i[2];r>3?(o=d===n)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=v&&((o=r<2&&v<i[1])?(a=0,l.v=n,l.n=i[1]):v<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,l.n=d,a=0))}if(o||r>1)return u;throw p=!0,n}return function(o,f,d){if(s>1)throw TypeError("Generator is already running");for(p&&1===f&&v(f,d),a=f,c=d;(e=a<2?t:c)||!p;){i||(a?a<3?(a>1&&(l.n=-1),v(a,c)):l.n=c:l.v=c);try{if(s=2,i){if(a||(o="next"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=t}else if((e=(p=l.n<0)?c:r.call(n,l))!==u)break}catch(e){i=t,a=1,c=e}finally{s=1}}return{value:e,done:p}}}(r,o,i),!0),a}var u={};function s(){}function f(){}function p(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(c(e={},n,function(){return this}),e),v=p.prototype=s.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,o,"GeneratorFunction")),t.prototype=Object.create(v),t}return f.prototype=p,c(v,"constructor",p),c(p,"constructor",f),f.displayName="GeneratorFunction",c(p,o,"GeneratorFunction"),c(v),c(v,o,"Generator"),c(v,n,function(){return this}),c(v,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:d}})()}function c(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}c=function(t,e,r,n){function i(e,r){c(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},c(t,e,r,n)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function f(t){var e="function"==typeof Map?new Map:void 0;return f=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,r)}function r(){return function(t,e,r){if(u())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&s(o,r.prototype),o}(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)},f(t)}var p=["children","organisationId","getPermissions"],l=e.createContext(void 0),v="@entur-partner:mount",d="@entur-partner:unmount",y=function(t){function e(){return t.apply(this,arguments)||this}var r,n;return n=t,(r=e).prototype=Object.create(n.prototype),r.prototype.constructor=r,s(r,n),e}(f(CustomEvent)),h=["organisationId"];exports.AppProvider=function(t){var r=t.children,i=t.organisationId,u=t.getPermissions,c=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;r[n]=t[n]}return r}(t,p),s=e.useState([]),f=s[0],v=s[1];return e.useEffect(function(){function t(){var e;return e=a().m(function t(){return a().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,u();case 1:v(t.v),t.n=3;break;case 2:t.p=2,console.error("Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:",t.v);case 3:return t.a(2)}},t,null,[[0,2]])}),t=function(){var t=this,r=arguments;return new Promise(function(o,i){var u=e.apply(t,r);function a(t){n(u,o,i,a,c,"next",t)}function c(t){n(u,o,i,a,c,"throw",t)}a(void 0)})},t.apply(this,arguments)}!function(){t.apply(this,arguments)}()},[u]),e.createElement(l.Provider,{value:o({},c,{user:o({},c.user,{permissions:f}),activeOrgId:Number(i)})},r)},exports.MOUNT_EVENT_TYPE=v,exports.ROUTE_CHANGE_EVENT_TYPE="@entur-partner:after-route-change",exports.RouteChangeEvent=y,exports.UNMOUNT_EVENT_TYPE=d,exports.createMountEvent=function(t){return new CustomEvent(v,{detail:t})},exports.createUnmountEvent=function(t){return new CustomEvent(d,{detail:t})},exports.registerMicroFrontend=function(t){var e=t.unmount,r=t.microFrontendId,n=t.mount;window.addEventListener(v,function(t){t.detail.id.startsWith(r)&&n(t.detail.mountPoint,t.detail.payload,t.detail.mountPoint)}),window.addEventListener(d,function(t){t.detail.id.startsWith(r)&&e(t.detail.mountPoint)})},exports.useActiveOrgId=function(){var r=e.useContext(l);return t.assertIsDefined(r),r.activeOrgId},exports.useNavigateParams=function(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@entur-partner/util"),e=require("react"),r=require("react-router-dom");function n(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function o(){return o=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},o.apply(null,arguments)}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function u(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(u=function(){return!!t})()}function a(){var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=Object.create((n&&n.prototype instanceof s?n:s).prototype);return c(a,"_invoke",function(r,n,o){var i,a,c,s=0,f=o||[],p=!1,l={p:0,n:0,v:t,a:v,f:v.bind(t,4),d:function(e,r){return i=e,a=0,c=t,l.n=r,u}};function v(r,n){for(a=r,c=n,e=0;!p&&s&&!o&&e<f.length;e++){var o,i=f[e],v=l.p,d=i[2];r>3?(o=d===n)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=t):i[0]<=v&&((o=r<2&&v<i[1])?(a=0,l.v=n,l.n=i[1]):v<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,l.n=d,a=0))}if(o||r>1)return u;throw p=!0,n}return function(o,f,d){if(s>1)throw TypeError("Generator is already running");for(p&&1===f&&v(f,d),a=f,c=d;(e=a<2?t:c)||!p;){i||(a?a<3?(a>1&&(l.n=-1),v(a,c)):l.n=c:l.v=c);try{if(s=2,i){if(a||(o="next"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,a<2&&(a=0)}else 1===a&&(e=i.return)&&e.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=t}else if((e=(p=l.n<0)?c:r.call(n,l))!==u)break}catch(e){i=t,a=1,c=e}finally{s=1}}return{value:e,done:p}}}(r,o,i),!0),a}var u={};function s(){}function f(){}function p(){}e=Object.getPrototypeOf;var l=[][n]?e(e([][n]())):(c(e={},n,function(){return this}),e),v=p.prototype=s.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,o,"GeneratorFunction")),t.prototype=Object.create(v),t}return f.prototype=p,c(v,"constructor",p),c(p,"constructor",f),f.displayName="GeneratorFunction",c(p,o,"GeneratorFunction"),c(v),c(v,o,"Generator"),c(v,n,function(){return this}),c(v,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:d}})()}function c(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}c=function(t,e,r,n){function i(e,r){c(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},c(t,e,r,n)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function f(t){var e="function"==typeof Map?new Map:void 0;return f=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,r)}function r(){return function(t,e,r){if(u())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var o=new(t.bind.apply(t,n));return r&&s(o,r.prototype),o}(t,arguments,i(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)},f(t)}var p=["children","organisationId","getPermissions"],l=e.createContext(void 0),v="@entur-partner:mount",d="@entur-partner:unmount",y=function(t){function e(){return t.apply(this,arguments)||this}var r,n;return n=t,(r=e).prototype=Object.create(n.prototype),r.prototype.constructor=r,s(r,n),e}(f(CustomEvent)),h=["organisationId"];exports.AppProvider=function(t){var r=t.children,i=t.organisationId,u=t.getPermissions,c=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;r[n]=t[n]}return r}(t,p),s=e.useState([]),f=s[0],v=s[1];return e.useEffect(function(){function t(){var e;return e=a().m(function t(){return a().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,u();case 1:v(t.v),t.n=3;break;case 2:t.p=2,console.error("Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:",t.v);case 3:return t.a(2)}},t,null,[[0,2]])}),t=function(){var t=this,r=arguments;return new Promise(function(o,i){var u=e.apply(t,r);function a(t){n(u,o,i,a,c,"next",t)}function c(t){n(u,o,i,a,c,"throw",t)}a(void 0)})},t.apply(this,arguments)}!function(){t.apply(this,arguments)}()},[u]),e.createElement(l.Provider,{value:o({},c,{user:o({},c.user,{permissions:f}),activeOrgId:Number(i)})},r)},exports.MOUNT_EVENT_TYPE=v,exports.ROUTE_CHANGE_EVENT_TYPE="@entur-partner:after-route-change",exports.RouteChangeEvent=y,exports.UNMOUNT_EVENT_TYPE=d,exports.createMountEvent=function(t){return new CustomEvent(v,{detail:t})},exports.createUnmountEvent=function(t){return new CustomEvent(d,{detail:t})},exports.registerMicroFrontend=function(t){var e=t.unmount,r=t.microFrontendId,n=t.mount;window.addEventListener(v,function(t){t.detail.id.startsWith(r)&&n(t.detail.mountPoint,t.detail.payload,t.detail.mountPoint)}),window.addEventListener(d,function(t){t.detail.id.startsWith(r)&&e(t.detail.mountPoint)})},exports.useActiveOrgId=function(){var r=e.useContext(l);return t.assertIsDefined(r),r.activeOrgId},exports.useNavigateParams=function(){var t=r.useNavigate(),e=r.useSearchParams()[0],n=h.reduce(function(t,r){var n=e.get(r);return n&&t.append(r,n),t},new URLSearchParams);return function(e,r){return t(e,o({state:o({},null==r?void 0:r.state,{searchParams:n.toString()})},r))}},exports.useUser=function(){var r=e.useContext(l);return t.assertIsDefined(r),r.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/constant.ts","../src/registerMicroFrontend.tsx","../src/hooks/useNavigateParams.ts"],"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","/*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","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 = (
|
|
1
|
+
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/constant.ts","../src/registerMicroFrontend.tsx","../src/hooks/useNavigateParams.ts"],"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","/*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","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"],"names":["AppContext","React","createContext","undefined","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","RouteChangeEvent","_CustomEvent","apply","this","arguments","_wrapNativeSuper","CustomEvent","PARAMS_TO_KEEP","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","_fetchData","_regenerator","m","_callee","w","_context","p","n","v","console","error","a","fetchData","createElement","Provider","value","_extends","user","activeOrgId","Number","detail","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload","context","useContext","assertIsDefined","navigate","useNavigate","searchParams","useSearchParams","modifiedSearchParams","reduce","params","key","get","append","URLSearchParams","to","options","state","toString"],"mappings":"wnHAmBaA,EAAaC,EAAMC,mBAC/BC,GCPYC,EAAmB,uBACnBC,EAAqB,yBAsBrBC,WAAiBC,GAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAC,KAAAC,YAAAD,IAAA,SAAA,SAAAF,KAAAD,yEAAAA,CAAA,EAAAK,EAAQC,cCpCzBC,EAAiB,CAAC,sCF4CkB,SAAzBC,GAKnB,IAJJC,EAAQD,EAARC,SACAC,EAAcF,EAAdE,eACAC,EAAcH,EAAdG,eACGC,6IAAIC,CAAAL,EAAAM,GAEPC,EAAsCC,EAAQA,SAAe,IAAtDC,EAAWF,EAAA,GAAEG,EAAcH,EAAA,GAkBlC,OAhBAI,EAAAA,UAAU,WACe,SAAAC,UAUvB,SAVuBC,IAAAC,EAAxB,SAAAC,IAAA,OAAAF,IAAAG,EAAA,SAAAC,GAAA,cAAAA,EAAAC,EAAAD,EAAAE,GAAA,KAAA,EAAA,OAAAF,EAAAC,EAAA,EAAAD,EAAAE,EAAA,EAEmChB,IAAgB,KAAA,EACjDO,EADwBO,EAAAG,GACWH,EAAAE,EAAA,EAAA,MAAA,KAAA,EAAAF,EAAAC,EAAA,EAEnCG,QAAQC,MACP,iHAHkCL,EAAAG,GAKjC,KAAA,EAAA,OAAAH,EAAAM,EAAA,GAAA,EAAAR,EAAA,KAAA,CAAA,CAAA,EAAA,IAEH,GAVuBH,8KAUvBA,EAAAlB,MAAA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AAcE,EAAqBU,cAEjCF,GACF,CACJ,kBJZuB,WACtB,IAAMf,EAAUC,aAAW3D,GAE3B,OADA4D,EAAeA,gBAACF,GACTA,EAAQf,IAChB"}
|
|
@@ -302,7 +302,7 @@ var PARAMS_TO_KEEP = ["organisationId"];
|
|
|
302
302
|
* @param options contains options for modifying the navigation
|
|
303
303
|
* @returns a function that navigates to the specified path with organisationId in the search params
|
|
304
304
|
*/
|
|
305
|
-
var useNavigateParams = function useNavigateParams(
|
|
305
|
+
var useNavigateParams = function useNavigateParams() {
|
|
306
306
|
var navigate = useNavigate();
|
|
307
307
|
var _useSearchParams = useSearchParams(),
|
|
308
308
|
searchParams = _useSearchParams[0];
|
|
@@ -313,11 +313,13 @@ var useNavigateParams = function useNavigateParams(to, options) {
|
|
|
313
313
|
}
|
|
314
314
|
return params;
|
|
315
315
|
}, new URLSearchParams());
|
|
316
|
-
return
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
+
};
|
|
321
323
|
};
|
|
322
324
|
|
|
323
325
|
/*global EventListener*/
|
|
@@ -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 = (to: string, options?: NavigateOptions) => {\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 navigate(to, {\n\t\tstate: { ...options?.state, searchParams: modifiedSearchParams.toString() },\n\t\t...options,\n\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","to","options","navigate","useNavigate","_useSearchParams","useSearchParams","searchParams","modifiedSearchParams","reduce","params","key","get","append","URLSearchParams","state","toString","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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ACvBH,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/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,CAA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K,CAACjC,MAAM,CAACoC,UAAU,CAAC,CAAA;AACjC,GAAmB,CAAC,CAAA;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.2",
|
|
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": "2cada90202c20a0c1e06eaa92f6e25517cb6b3c1"
|
|
49
49
|
}
|