@granite-js/micro-frontend 2.0.0
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/GraniteMicroFrontendRuntime.podspec +40 -0
- package/LICENSE +202 -0
- package/LICENSE.react-native-teleport +21 -0
- package/NOTICE +17 -0
- package/README.md +508 -0
- package/android/CMakeLists.txt +34 -0
- package/android/build.gradle +74 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/BundleEvaluator.cpp +64 -0
- package/android/src/main/cpp/BundleEvaluator.h +20 -0
- package/android/src/main/cpp/FileReader.cpp +92 -0
- package/android/src/main/cpp/FileReader.h +27 -0
- package/android/src/main/cpp/onLoad.cpp +9 -0
- package/android/src/main/java/com/teleport/extensions/Float.kt +12 -0
- package/android/src/main/java/com/teleport/extensions/View.kt +10 -0
- package/android/src/main/java/com/teleport/global/PortalRegistry.kt +117 -0
- package/android/src/main/java/com/teleport/host/PortalHostView.kt +97 -0
- package/android/src/main/java/com/teleport/host/PortalHostViewManager.kt +41 -0
- package/android/src/main/java/com/teleport/host/PortalReactRootView.kt +116 -0
- package/android/src/main/java/com/teleport/managers/TeleportViewManager.kt +27 -0
- package/android/src/main/java/com/teleport/portal/PortalLayoutStateController.kt +107 -0
- package/android/src/main/java/com/teleport/portal/PortalView.kt +309 -0
- package/android/src/main/java/com/teleport/portal/PortalViewManager.kt +51 -0
- package/android/src/main/java/run/granite/microfrontend/ActivitySessionBinding.kt +87 -0
- package/android/src/main/java/run/granite/microfrontend/BundleEvaluator.kt +46 -0
- package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendEvent.kt +62 -0
- package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeEventRouter.kt +186 -0
- package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeHost.kt +42 -0
- package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeModule.kt +56 -0
- package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendRuntimePackage.kt +35 -0
- package/android/src/main/java/run/granite/microfrontend/GraniteMicroFrontendSessionStore.kt +116 -0
- package/android/src/main/jni/CMakeLists.txt +64 -0
- package/android/src/test/cpp/CMakeLists.txt +35 -0
- package/android/src/test/cpp/FileReaderTest.cpp +44 -0
- package/android/src/test/java/com/teleport/host/PortalReactRootViewContractTest.kt +76 -0
- package/android/src/test/java/run/granite/microfrontend/GraniteMicroFrontendRuntimeEventRouterTest.kt +216 -0
- package/android/src/test/java/run/granite/microfrontend/GraniteMicroFrontendSessionStoreTest.kt +190 -0
- package/android/test-cpp.sh +12 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/ComponentDescriptors.h +24 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/PortalShadowRegistry.cpp +31 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/PortalShadowRegistry.h +29 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewComponentDescriptor.h +22 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewShadowNode.cpp +7 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewShadowNode.h +43 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalHostViewState.h +21 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewComponentDescriptor.h +54 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewShadowNode.cpp +7 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewShadowNode.h +51 -0
- package/common/cpp/react/renderer/components/GraniteMicroFrontendRuntimeSpec/RNTPortalViewState.h +43 -0
- package/dist/module/createMicroFrontendRuntime.js +18 -0
- package/dist/module/createMicroFrontendRuntime.js.map +1 -0
- package/dist/module/createRoute.js +43 -0
- package/dist/module/createRoute.js.map +1 -0
- package/dist/module/host/PendingHostComponent.js +70 -0
- package/dist/module/host/PendingHostComponent.js.map +1 -0
- package/dist/module/host/index.js +6 -0
- package/dist/module/host/index.js.map +1 -0
- package/dist/module/host/pendingHostComponentStore.js +164 -0
- package/dist/module/host/pendingHostComponentStore.js.map +1 -0
- package/dist/module/host/resolveParams.js +60 -0
- package/dist/module/host/resolveParams.js.map +1 -0
- package/dist/module/host/routeMatcher.js +92 -0
- package/dist/module/host/routeMatcher.js.map +1 -0
- package/dist/module/host/types.js +4 -0
- package/dist/module/host/types.js.map +1 -0
- package/dist/module/index.js +12 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/package.json +1 -0
- package/dist/module/plugin/index.js +4 -0
- package/dist/module/plugin/index.js.map +1 -0
- package/dist/module/plugin/intoShared.js +32 -0
- package/dist/module/plugin/intoShared.js.map +1 -0
- package/dist/module/plugin/microFrontendPlugin.js +58 -0
- package/dist/module/plugin/microFrontendPlugin.js.map +1 -0
- package/dist/module/plugin/prelude.js +23 -0
- package/dist/module/plugin/prelude.js.map +1 -0
- package/dist/module/plugin/resolver.js +25 -0
- package/dist/module/plugin/resolver.js.map +1 -0
- package/dist/module/plugin/types.js +4 -0
- package/dist/module/plugin/types.js.map +1 -0
- package/dist/module/runtime/createMicroFrontendRuntime.js +79 -0
- package/dist/module/runtime/createMicroFrontendRuntime.js.map +1 -0
- package/dist/module/runtime/errors.js +63 -0
- package/dist/module/runtime/errors.js.map +1 -0
- package/dist/module/runtime/parseAppRequest.js +16 -0
- package/dist/module/runtime/parseAppRequest.js.map +1 -0
- package/dist/module/runtime/parseNativeRuntimeEvent.js +54 -0
- package/dist/module/runtime/parseNativeRuntimeEvent.js.map +1 -0
- package/dist/module/runtime/registry.js +87 -0
- package/dist/module/runtime/registry.js.map +1 -0
- package/dist/module/session/MicroFrontendSessionContext.js +32 -0
- package/dist/module/session/MicroFrontendSessionContext.js.map +1 -0
- package/dist/module/session/useMicroFrontendSessions.js +47 -0
- package/dist/module/session/useMicroFrontendSessions.js.map +1 -0
- package/dist/module/specs/NativeGraniteMicroFrontendRuntime.js +21 -0
- package/dist/module/specs/NativeGraniteMicroFrontendRuntime.js.map +1 -0
- package/dist/module/specs/PortalHostViewNativeComponent.ts +9 -0
- package/dist/module/specs/PortalViewNativeComponent.ts +9 -0
- package/dist/module/types.js +2 -0
- package/dist/module/types.js.map +1 -0
- package/dist/typescript/createMicroFrontendRuntime.d.ts +6 -0
- package/dist/typescript/createRoute.d.ts +23 -0
- package/dist/typescript/host/PendingHostComponent.d.ts +14 -0
- package/dist/typescript/host/index.d.ts +5 -0
- package/dist/typescript/host/pendingHostComponentStore.d.ts +11 -0
- package/dist/typescript/host/resolveParams.d.ts +10 -0
- package/dist/typescript/host/routeMatcher.d.ts +7 -0
- package/dist/typescript/host/types.d.ts +32 -0
- package/dist/typescript/index.d.ts +16 -0
- package/dist/typescript/plugin/index.d.ts +2 -0
- package/dist/typescript/plugin/intoShared.d.ts +3 -0
- package/dist/typescript/plugin/microFrontendPlugin.d.ts +3 -0
- package/dist/typescript/plugin/prelude.d.ts +6 -0
- package/dist/typescript/plugin/resolver.d.ts +3 -0
- package/dist/typescript/plugin/types.d.ts +5 -0
- package/dist/typescript/runtime/createMicroFrontendRuntime.d.ts +31 -0
- package/dist/typescript/runtime/errors.d.ts +35 -0
- package/dist/typescript/runtime/parseAppRequest.d.ts +6 -0
- package/dist/typescript/runtime/parseNativeRuntimeEvent.d.ts +3 -0
- package/dist/typescript/runtime/registry.d.ts +35 -0
- package/dist/typescript/session/MicroFrontendSessionContext.d.ts +13 -0
- package/dist/typescript/session/useMicroFrontendSessions.d.ts +8 -0
- package/dist/typescript/specs/NativeGraniteMicroFrontendRuntime.d.ts +21 -0
- package/dist/typescript/specs/PortalHostViewNativeComponent.d.ts +6 -0
- package/dist/typescript/specs/PortalViewNativeComponent.d.ts +6 -0
- package/dist/typescript/types.d.ts +49 -0
- package/ios/GraniteMicroFrontendRuntimeHost+Internal.h +18 -0
- package/ios/GraniteMicroFrontendRuntimeHost.h +34 -0
- package/ios/GraniteMicroFrontendRuntimeHost.mm +485 -0
- package/ios/GraniteMicroFrontendRuntimeModule.h +6 -0
- package/ios/GraniteMicroFrontendRuntimeModule.mm +138 -0
- package/ios/PortalHostContainerView.h +56 -0
- package/ios/PortalHostContainerView.mm +133 -0
- package/ios/PortalHostView.h +39 -0
- package/ios/PortalHostView.mm +153 -0
- package/ios/PortalRegistry.h +38 -0
- package/ios/PortalRegistry.mm +228 -0
- package/ios/PortalView.h +32 -0
- package/ios/PortalView.mm +426 -0
- package/package.json +113 -0
- package/react-native.config.js +13 -0
- package/src/createMicroFrontendRuntime.ts +22 -0
- package/src/createRoute.ts +84 -0
- package/src/host/PendingHostComponent.tsx +92 -0
- package/src/host/index.ts +26 -0
- package/src/host/pendingHostComponentStore.ts +241 -0
- package/src/host/resolveParams.ts +70 -0
- package/src/host/routeMatcher.ts +117 -0
- package/src/host/types.ts +45 -0
- package/src/index.ts +57 -0
- package/src/plugin/index.ts +2 -0
- package/src/plugin/intoShared.ts +50 -0
- package/src/plugin/microFrontendPlugin.ts +57 -0
- package/src/plugin/prelude.ts +73 -0
- package/src/plugin/resolver.ts +73 -0
- package/src/plugin/types.ts +6 -0
- package/src/runtime/createMicroFrontendRuntime.ts +115 -0
- package/src/runtime/errors.ts +86 -0
- package/src/runtime/parseAppRequest.ts +22 -0
- package/src/runtime/parseNativeRuntimeEvent.ts +54 -0
- package/src/runtime/registry.ts +131 -0
- package/src/session/MicroFrontendSessionContext.tsx +45 -0
- package/src/session/useMicroFrontendSessions.ts +73 -0
- package/src/specs/NativeGraniteMicroFrontendRuntime.ts +44 -0
- package/src/specs/PortalHostViewNativeComponent.ts +9 -0
- package/src/specs/PortalViewNativeComponent.ts +9 -0
- package/src/types.ts +55 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MicroFrontendAdapter, MicroFrontendRuntimeApi } from './types';
|
|
2
|
+
export interface CreateMicroFrontendRuntimeOptions {
|
|
3
|
+
readonly adapter: MicroFrontendAdapter;
|
|
4
|
+
readonly onPreloadError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare function createMicroFrontendRuntime(options: CreateMicroFrontendRuntimeOptions): MicroFrontendRuntimeApi;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type RegisterScreenInput, type RouteOptions, useNavigation } from '@granite-js/react-native';
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
import type { PendingHostComponentRenderer } from './host/types';
|
|
4
|
+
export type MicroFrontendRouteOptions<TParams extends Readonly<object> | undefined> = RouteOptions<TParams> & {
|
|
5
|
+
readonly hostPendingComponent?: PendingHostComponentRenderer<TParams>;
|
|
6
|
+
};
|
|
7
|
+
type SetParamsFunction<TParams> = (params: TParams extends undefined ? undefined : Partial<TParams>) => void;
|
|
8
|
+
type ReplaceParamsFunction<TParams> = (params: TParams extends undefined ? undefined : TParams) => void;
|
|
9
|
+
type MicroFrontendRouteResult<TInput, TOutput> = {
|
|
10
|
+
readonly _path: keyof RegisterScreenInput;
|
|
11
|
+
readonly useNavigation: typeof useNavigation;
|
|
12
|
+
readonly useParams: () => TOutput;
|
|
13
|
+
readonly useSetParams: () => SetParamsFunction<TInput>;
|
|
14
|
+
readonly useReplaceParams: () => ReplaceParamsFunction<TInput>;
|
|
15
|
+
readonly _inputType: TInput;
|
|
16
|
+
readonly _outputType: TOutput;
|
|
17
|
+
};
|
|
18
|
+
export declare function createRoute<TSchema extends StandardSchemaV1<unknown, Readonly<object> | undefined>>(path: keyof RegisterScreenInput, options: Omit<RouteOptions<StandardSchemaV1.InferOutput<TSchema>>, 'validateParams'> & {
|
|
19
|
+
readonly validateParams: TSchema;
|
|
20
|
+
readonly hostPendingComponent?: PendingHostComponentRenderer<StandardSchemaV1.InferOutput<TSchema>>;
|
|
21
|
+
}): MicroFrontendRouteResult<StandardSchemaV1.InferInput<TSchema>, StandardSchemaV1.InferOutput<TSchema>>;
|
|
22
|
+
export declare function createRoute<TParams extends Readonly<object> | undefined>(path: keyof RegisterScreenInput, options: MicroFrontendRouteOptions<TParams>): MicroFrontendRouteResult<TParams, TParams>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PendingHostComponentProps {
|
|
2
|
+
readonly url: string | null | undefined;
|
|
3
|
+
}
|
|
4
|
+
export interface PendingHostComponentController {
|
|
5
|
+
readonly url: string | null;
|
|
6
|
+
readonly isPresent: boolean;
|
|
7
|
+
readonly isHidden: boolean;
|
|
8
|
+
readonly present: (url: string | null) => void;
|
|
9
|
+
readonly dismiss: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function useIsPendingHostComponentHidden(): boolean;
|
|
12
|
+
export declare function useResolvedPendingHostComponent(url: string | null | undefined): import("./types").ResolvedPendingHostComponent | null;
|
|
13
|
+
export declare function PendingHostComponent({ url }: PendingHostComponentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export declare function usePendingHostComponentController(): PendingHostComponentController;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { PendingHostComponentController, PendingHostComponentProps } from './PendingHostComponent';
|
|
2
|
+
export { PendingHostComponent, usePendingHostComponentController, useIsPendingHostComponentHidden, useResolvedPendingHostComponent, } from './PendingHostComponent';
|
|
3
|
+
export type { PendingHostComponentAppConfig, PendingHostComponentRenderer, PendingHostComponentParams, PendingHostComponentRouteRequest, RegisterPendingHostComponentRouteOptions, ResolvedPendingHostComponent, } from './types';
|
|
4
|
+
export { createPendingHostComponentRoutePrefix, normalizeRoutePath, } from './routeMatcher';
|
|
5
|
+
export { hidePendingHostComponent, installPendingHostComponentBridge, registerPendingHostComponentRoute, resetPendingHostComponent, resolvePendingHostComponent, } from './pendingHostComponentStore';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PendingHostComponentRouteRequest, RegisterPendingHostComponentRouteOptions, ResolvedPendingHostComponent } from './types';
|
|
2
|
+
export declare function subscribePendingHostComponentStore(listener: () => void): () => boolean;
|
|
3
|
+
export declare function getPendingHostComponentStoreVersion(): number;
|
|
4
|
+
export declare function getIsPendingHostComponentHidden(): boolean;
|
|
5
|
+
export declare function hidePendingHostComponent(): void;
|
|
6
|
+
export declare function resetPendingHostComponent(): void;
|
|
7
|
+
export declare function installPendingHostComponentBridge(): void;
|
|
8
|
+
export declare function registerPendingHostComponentRoute<TParams extends Readonly<object> | undefined = undefined>(routePath: string, options: RegisterPendingHostComponentRouteOptions<TParams>): void;
|
|
9
|
+
export declare function removePendingHostComponentRoutes(appName: string): void;
|
|
10
|
+
export declare function resolvePendingHostComponent(request: PendingHostComponentRouteRequest | string): ResolvedPendingHostComponent | null;
|
|
11
|
+
export declare function resetPendingHostComponentStoreForTest(): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParserParams, ValidateParams } from './types';
|
|
2
|
+
type ResolvedParams = {
|
|
3
|
+
readonly status: 'resolved';
|
|
4
|
+
readonly value: Readonly<object>;
|
|
5
|
+
} | {
|
|
6
|
+
readonly status: 'invalid';
|
|
7
|
+
readonly cause?: Error;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolvePendingHostComponentParams(rawParams: Record<string, unknown>, parserParams: ParserParams | undefined, validateParams: ValidateParams<Readonly<object> | undefined> | undefined): ResolvedParams;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PendingHostComponentAppConfig } from './types';
|
|
2
|
+
export declare function normalizeRoutePath(routePath: string): string;
|
|
3
|
+
export declare function createPendingHostComponentRoutePrefix(app: PendingHostComponentAppConfig): string;
|
|
4
|
+
export declare function getRoutePathFromUrl(url: string, routePrefix: string): string | null;
|
|
5
|
+
export declare function getQueryParamsFromUrl(url: string): Record<string, string>;
|
|
6
|
+
export declare function matchRoutePath(pattern: string, routePath: string): Record<string, string> | null;
|
|
7
|
+
export declare function normalizePendingHostComponentAppName(appName: string): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export type PendingHostComponentParams<TParams extends Readonly<object> | undefined = undefined> = TParams extends Readonly<object> ? TParams : Readonly<Record<string, never>>;
|
|
4
|
+
export type PendingHostComponentRenderer<TParams extends Readonly<object> | undefined = undefined> = {
|
|
5
|
+
bivarianceHack(params: PendingHostComponentParams<TParams>): ReactNode;
|
|
6
|
+
}['bivarianceHack'];
|
|
7
|
+
export type ParserParams = (params: Record<string, unknown>) => Record<string, unknown>;
|
|
8
|
+
export type ValidateParams<TParams extends Readonly<object> | undefined> = ((params: Readonly<object> | undefined) => TParams) | StandardSchemaV1<unknown, TParams>;
|
|
9
|
+
export interface PendingHostComponentAppConfig {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly scheme: string;
|
|
12
|
+
readonly host?: string | null;
|
|
13
|
+
}
|
|
14
|
+
export interface RegisterPendingHostComponentRouteOptions<TParams extends Readonly<object> | undefined = undefined> {
|
|
15
|
+
readonly component: PendingHostComponentRenderer<TParams>;
|
|
16
|
+
readonly parserParams?: ParserParams;
|
|
17
|
+
readonly validateParams?: ValidateParams<TParams>;
|
|
18
|
+
readonly app: PendingHostComponentAppConfig;
|
|
19
|
+
}
|
|
20
|
+
export interface PendingHostComponentRouteRequest {
|
|
21
|
+
readonly routePath: string;
|
|
22
|
+
readonly params?: Record<string, unknown>;
|
|
23
|
+
readonly appName: string;
|
|
24
|
+
readonly url?: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface ResolvedPendingHostComponent {
|
|
27
|
+
readonly component: PendingHostComponentRenderer<Readonly<object>>;
|
|
28
|
+
readonly params: Readonly<object>;
|
|
29
|
+
readonly url: string | null;
|
|
30
|
+
readonly routePath: string;
|
|
31
|
+
readonly appName: string | null;
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { createMicroFrontendRuntime } from './createMicroFrontendRuntime';
|
|
2
|
+
export type { CreateMicroFrontendRuntimeOptions } from './createMicroFrontendRuntime';
|
|
3
|
+
export { createRoute } from './createRoute';
|
|
4
|
+
export type { MicroFrontendRouteOptions } from './createRoute';
|
|
5
|
+
export type { PendingHostComponentController, PendingHostComponentProps } from './host/PendingHostComponent';
|
|
6
|
+
export { PendingHostComponent, usePendingHostComponentController, useIsPendingHostComponentHidden, useResolvedPendingHostComponent, } from './host/PendingHostComponent';
|
|
7
|
+
export type { PendingHostComponentAppConfig, PendingHostComponentRenderer, PendingHostComponentParams, PendingHostComponentRouteRequest, RegisterPendingHostComponentRouteOptions, ResolvedPendingHostComponent, } from './host/types';
|
|
8
|
+
export { createPendingHostComponentRoutePrefix, normalizeRoutePath, } from './host/routeMatcher';
|
|
9
|
+
export { hidePendingHostComponent, installPendingHostComponentBridge, registerPendingHostComponentRoute, resetPendingHostComponent, resolvePendingHostComponent, } from './host/pendingHostComponentStore';
|
|
10
|
+
export { MicroFrontendSessionProvider, MissingMicroFrontendSessionError, useMicroFrontendSession, } from './session/MicroFrontendSessionContext';
|
|
11
|
+
export type { MicroFrontendSession, MicroFrontendSessionProviderProps } from './session/MicroFrontendSessionContext';
|
|
12
|
+
export { useMicroFrontendSessions } from './session/useMicroFrontendSessions';
|
|
13
|
+
export type { MicroFrontendSessionState } from './session/useMicroFrontendSessions';
|
|
14
|
+
export { default as Portal } from './specs/PortalViewNativeComponent';
|
|
15
|
+
export type { AppRequest, MicroFrontendAppProps, MicroFrontendAdapter, MicroFrontendBundle, MicroFrontendBundleRequest, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription, MicroFrontendSessionEvent, } from './types';
|
|
16
|
+
export { AppContainerNotFoundError, ExposedModuleNotFoundError, InvalidAppNameError, InvalidAppRequestError, InvalidNativeRuntimeEventError, } from './runtime/errors';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MicroFrontendPluginOptions } from './types';
|
|
2
|
+
export interface MicroFrontendPreludeConfig {
|
|
3
|
+
readonly banner: string;
|
|
4
|
+
readonly preludeScript: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getPreludeConfig(options: MicroFrontendPluginOptions, appName?: string): MicroFrontendPreludeConfig;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ResolverConfig } from '@granite-js/plugin-core';
|
|
2
|
+
import type { SharedModuleConfig } from '../runtime/registry';
|
|
3
|
+
export declare function createSharedResolverConfig(moduleEntries: readonly (readonly [string, SharedModuleConfig])[]): Pick<ResolverConfig, 'alias' | 'protocols'>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AppRequest, MicroFrontendAdapter, MicroFrontendRuntimeApi, MicroFrontendRuntimeEvent, MicroFrontendRuntimeEventSubscription } from '../types';
|
|
2
|
+
export interface NativeMicroFrontendRuntimeEvent {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly params: {
|
|
5
|
+
readonly appName?: string;
|
|
6
|
+
readonly sessionId?: string;
|
|
7
|
+
readonly scheme?: string;
|
|
8
|
+
readonly isVisible?: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface NativeMicroFrontendRuntime {
|
|
12
|
+
readonly evaluateScript: (request: {
|
|
13
|
+
readonly filePath: string;
|
|
14
|
+
}) => Promise<void>;
|
|
15
|
+
readonly startEventDelivery: () => void;
|
|
16
|
+
readonly onEvent: (listener: (event: NativeMicroFrontendRuntimeEvent) => void) => MicroFrontendRuntimeEventSubscription;
|
|
17
|
+
}
|
|
18
|
+
export interface MicroFrontendModuleRegistry {
|
|
19
|
+
readonly hasContainer: (appName: string) => boolean;
|
|
20
|
+
readonly removeContainer: (appName: string) => void;
|
|
21
|
+
readonly importModule: <TModule>(request: AppRequest) => TModule;
|
|
22
|
+
}
|
|
23
|
+
export interface CreateMicroFrontendRuntimeDependencies {
|
|
24
|
+
readonly adapter: MicroFrontendAdapter;
|
|
25
|
+
readonly nativeRuntime: NativeMicroFrontendRuntime;
|
|
26
|
+
readonly onPreloadError: (error: unknown) => void;
|
|
27
|
+
readonly registry: MicroFrontendModuleRegistry;
|
|
28
|
+
readonly removePendingHostComponentRoutes: (appName: string) => void;
|
|
29
|
+
readonly parseEvent: (event: NativeMicroFrontendRuntimeEvent) => MicroFrontendRuntimeEvent;
|
|
30
|
+
}
|
|
31
|
+
export declare function createMicroFrontendRuntimeWithDependencies(dependencies: CreateMicroFrontendRuntimeDependencies): MicroFrontendRuntimeApi;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class InvalidAppRequestError extends Error {
|
|
2
|
+
readonly request: string;
|
|
3
|
+
constructor(request: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class InvalidAppNameError extends Error {
|
|
6
|
+
readonly appName: string;
|
|
7
|
+
constructor(appName: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class AppContainerNotFoundError extends Error {
|
|
10
|
+
readonly appName: string;
|
|
11
|
+
constructor(appName: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class AppContainerAlreadyRegisteredError extends Error {
|
|
14
|
+
readonly appName: string;
|
|
15
|
+
constructor(appName: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class ExposedModuleNotFoundError extends Error {
|
|
18
|
+
readonly appName: string;
|
|
19
|
+
readonly exposedModule: string;
|
|
20
|
+
constructor(appName: string, exposedModule: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class ExposedModuleAlreadyRegisteredError extends Error {
|
|
23
|
+
readonly appName: string;
|
|
24
|
+
readonly exposedModule: string;
|
|
25
|
+
constructor(appName: string, exposedModule: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class SharedModuleAlreadyRegisteredError extends Error {
|
|
28
|
+
readonly moduleName: string;
|
|
29
|
+
constructor(moduleName: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class InvalidNativeRuntimeEventError extends Error {
|
|
32
|
+
readonly eventName: string;
|
|
33
|
+
readonly fieldName?: string;
|
|
34
|
+
constructor(eventName: string, fieldName?: string);
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AppRequest } from '../types';
|
|
2
|
+
import type { MicroFrontendModuleRegistry } from './createMicroFrontendRuntime';
|
|
3
|
+
export interface SharedModuleConfig {
|
|
4
|
+
readonly eager?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export type SharedConfig = Readonly<Record<string, SharedModuleConfig>>;
|
|
7
|
+
export interface AppContainerConfig {
|
|
8
|
+
readonly shared?: SharedConfig;
|
|
9
|
+
}
|
|
10
|
+
export interface AppContainer {
|
|
11
|
+
readonly appName: string;
|
|
12
|
+
readonly config: AppContainerConfig;
|
|
13
|
+
readonly exposedModules: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
interface SharedModule {
|
|
16
|
+
readonly get: () => unknown;
|
|
17
|
+
readonly loaded: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface MicroFrontendRuntimeContext {
|
|
20
|
+
readonly containers: Record<string, AppContainer>;
|
|
21
|
+
readonly sharedModules: Record<string, SharedModule>;
|
|
22
|
+
}
|
|
23
|
+
declare global {
|
|
24
|
+
var _graniteMicroFrontend: MicroFrontendRuntimeContext | undefined;
|
|
25
|
+
}
|
|
26
|
+
export declare function getMicroFrontendRuntimeContext(): MicroFrontendRuntimeContext;
|
|
27
|
+
export declare function createContainer(appName: string, config?: AppContainerConfig): AppContainer;
|
|
28
|
+
export declare function exposeModule(container: AppContainer, exposedModule: string, module: unknown): void;
|
|
29
|
+
export declare function registerShared(moduleName: string, module: unknown): void;
|
|
30
|
+
export declare function getContainer(appName: string): AppContainer | null;
|
|
31
|
+
export declare function removeContainer(appName: string): void;
|
|
32
|
+
export declare function hasContainer(appName: string): boolean;
|
|
33
|
+
export declare function importModule<TModule>(request: AppRequest): TModule;
|
|
34
|
+
export declare const microFrontendModuleRegistry: MicroFrontendModuleRegistry;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
export interface MicroFrontendSession {
|
|
3
|
+
readonly sessionId: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MicroFrontendSessionProviderProps extends MicroFrontendSession {
|
|
6
|
+
readonly children: ReactNode;
|
|
7
|
+
readonly presentationVisibility: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class MissingMicroFrontendSessionError extends Error {
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
12
|
+
export declare function MicroFrontendSessionProvider(props: MicroFrontendSessionProviderProps): ReactElement;
|
|
13
|
+
export declare function useMicroFrontendSession(): MicroFrontendSession;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MicroFrontendRuntimeApi } from '../types';
|
|
2
|
+
export interface MicroFrontendSessionState {
|
|
3
|
+
readonly appName: string;
|
|
4
|
+
readonly sessionId: string;
|
|
5
|
+
readonly scheme: string;
|
|
6
|
+
readonly isVisible: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function useMicroFrontendSessions(runtime: Pick<MicroFrontendRuntimeApi, 'onEvent'>): readonly MicroFrontendSessionState[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type CodegenTypes, type TurboModule } from 'react-native';
|
|
2
|
+
export interface NativeMicroFrontendRuntimeEventParams {
|
|
3
|
+
readonly appName?: string;
|
|
4
|
+
readonly sessionId?: string;
|
|
5
|
+
readonly scheme?: string;
|
|
6
|
+
readonly isVisible?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface NativeMicroFrontendRuntimeEvent {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly params: NativeMicroFrontendRuntimeEventParams;
|
|
11
|
+
}
|
|
12
|
+
export type EvaluateScriptRequest = Readonly<{
|
|
13
|
+
filePath: string;
|
|
14
|
+
}>;
|
|
15
|
+
export interface Spec extends TurboModule {
|
|
16
|
+
evaluateScript(request: EvaluateScriptRequest): Promise<void>;
|
|
17
|
+
startEventDelivery(): void;
|
|
18
|
+
readonly onEvent: CodegenTypes.EventEmitter<NativeMicroFrontendRuntimeEvent>;
|
|
19
|
+
}
|
|
20
|
+
declare const NativeGraniteMicroFrontendRuntime: Spec;
|
|
21
|
+
export default NativeGraniteMicroFrontendRuntime;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type AppRequest = `${string}/${string}`;
|
|
2
|
+
export interface MicroFrontendBundleRequest {
|
|
3
|
+
readonly appName: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MicroFrontendBundle {
|
|
6
|
+
readonly filePath: string;
|
|
7
|
+
}
|
|
8
|
+
export interface MicroFrontendAppProps {
|
|
9
|
+
readonly scheme: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MicroFrontendAdapter {
|
|
12
|
+
readonly loadBundle: (request: MicroFrontendBundleRequest) => Promise<MicroFrontendBundle>;
|
|
13
|
+
}
|
|
14
|
+
export type MicroFrontendRuntimeEvent = {
|
|
15
|
+
readonly name: 'preloadApp';
|
|
16
|
+
readonly params: {
|
|
17
|
+
readonly appName: string;
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
readonly name: 'openApp';
|
|
21
|
+
readonly params: {
|
|
22
|
+
readonly sessionId: string;
|
|
23
|
+
readonly appName: string;
|
|
24
|
+
readonly scheme: string;
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
readonly name: 'closeApp';
|
|
28
|
+
readonly params: {
|
|
29
|
+
readonly sessionId: string;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
readonly name: 'sessionVisibilityChanged';
|
|
33
|
+
readonly params: {
|
|
34
|
+
readonly sessionId: string;
|
|
35
|
+
readonly isVisible: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export type MicroFrontendSessionEvent = Exclude<MicroFrontendRuntimeEvent, {
|
|
39
|
+
readonly name: 'preloadApp';
|
|
40
|
+
}>;
|
|
41
|
+
export interface MicroFrontendRuntimeEventSubscription {
|
|
42
|
+
readonly remove: () => void;
|
|
43
|
+
}
|
|
44
|
+
export interface MicroFrontendRuntimeApi {
|
|
45
|
+
readonly evaluateScript: (filePath: string) => Promise<void>;
|
|
46
|
+
readonly preloadApp: (appName: string) => Promise<void>;
|
|
47
|
+
readonly importApp: <TModule>(request: AppRequest) => Promise<TModule>;
|
|
48
|
+
readonly onEvent: (listener: (event: MicroFrontendSessionEvent) => void) => MicroFrontendRuntimeEventSubscription;
|
|
49
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import "GraniteMicroFrontendRuntimeHost.h"
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
@protocol GraniteMicroFrontendRuntimeEventSink <NSObject>
|
|
6
|
+
- (BOOL)enqueueRuntimeEvent:(NSDictionary *)event;
|
|
7
|
+
@end
|
|
8
|
+
|
|
9
|
+
@interface GraniteMicroFrontendRuntimeHost (Internal)
|
|
10
|
+
+ (void)startEventDeliveryToEventSink:(id<GraniteMicroFrontendRuntimeEventSink>)eventSink;
|
|
11
|
+
+ (void)detachEventSink:(id<GraniteMicroFrontendRuntimeEventSink>)eventSink;
|
|
12
|
+
+ (void)emitOpenApp:(NSString *)sessionId appName:(NSString *)appName scheme:(NSString *)scheme;
|
|
13
|
+
+ (void)emitCloseApp:(NSString *)sessionId;
|
|
14
|
+
+ (void)emitSessionVisibilityChanged:(NSString *)sessionId isVisible:(BOOL)isVisible;
|
|
15
|
+
+ (void)unregisterSession:(NSString *)sessionId token:(NSString *)token;
|
|
16
|
+
@end
|
|
17
|
+
|
|
18
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
@class UIViewController;
|
|
6
|
+
|
|
7
|
+
@interface GraniteMicroFrontendSessionRegistration : NSObject
|
|
8
|
+
- (void)openAppWithAppName:(NSString *)appName scheme:(NSString *)scheme;
|
|
9
|
+
- (BOOL)setVisible:(BOOL)isVisible;
|
|
10
|
+
- (BOOL)closeApp;
|
|
11
|
+
- (void)invalidate;
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
@interface GraniteMicroFrontendViewControllerSessionBinding : NSObject
|
|
15
|
+
/// Returns an existing binding if this view controller is already bound.
|
|
16
|
+
/// Returns `nil` if `sessionId` is already registered on another container.
|
|
17
|
+
+ (nullable GraniteMicroFrontendViewControllerSessionBinding *)bindViewController:(UIViewController *)viewController
|
|
18
|
+
sessionId:(NSString *)sessionId
|
|
19
|
+
appName:(NSString *)appName
|
|
20
|
+
scheme:(NSString *)scheme;
|
|
21
|
+
- (void)invalidate;
|
|
22
|
+
@end
|
|
23
|
+
|
|
24
|
+
@interface GraniteMicroFrontendRuntimeHost : NSObject
|
|
25
|
+
|
|
26
|
+
/// Registers a session. Returns `nil` if `sessionId` is already registered.
|
|
27
|
+
/// Callers must use a unique id per destination and invalidate before reuse.
|
|
28
|
+
+ (nullable GraniteMicroFrontendSessionRegistration *)registerSession:(NSString *)sessionId;
|
|
29
|
+
|
|
30
|
+
+ (void)emitPreloadApp:(NSString *)appName;
|
|
31
|
+
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
NS_ASSUME_NONNULL_END
|