@ikonai/sdk-react-ui 0.0.34 → 0.0.37

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.
@@ -0,0 +1,56 @@
1
+ import { ConnectionState, IkonClient } from '../../../sdk/src/index.ts';
2
+ import { ReactNode } from 'react';
3
+ import { IkonUiRegistry } from '../ikon-ui-registry';
4
+ import { IkonUiStoreEntry } from '../surface';
5
+ /**
6
+ * Props passed to the renderConnected callback.
7
+ */
8
+ export interface ConnectedRenderProps {
9
+ stores: ReadonlyMap<string, IkonUiStoreEntry>;
10
+ registry: IkonUiRegistry;
11
+ client: IkonClient | null;
12
+ onAction: (actionId: string, payload: unknown) => void;
13
+ isReconnecting: boolean;
14
+ }
15
+ /**
16
+ * Props for the ConnectionStateRenderer component.
17
+ */
18
+ export interface ConnectionStateRendererProps {
19
+ connectionState: ConnectionState;
20
+ error: string | null;
21
+ isReady: boolean;
22
+ stores: ReadonlyMap<string, IkonUiStoreEntry> | undefined;
23
+ registry: IkonUiRegistry | null;
24
+ client: IkonClient | null;
25
+ onAction: (actionId: string, payload: unknown) => void;
26
+ /**
27
+ * Render when idle (not yet started connecting).
28
+ */
29
+ renderIdle: () => ReactNode;
30
+ /**
31
+ * Render when connecting (initial connection attempt).
32
+ */
33
+ renderConnecting: () => ReactNode;
34
+ /**
35
+ * Render when connection is taking longer than expected.
36
+ */
37
+ renderConnectingSlow: () => ReactNode;
38
+ /**
39
+ * Render the main UI when connected.
40
+ * The isReconnecting flag indicates if currently reconnecting (overlay can be shown on top).
41
+ */
42
+ renderConnected: (props: ConnectedRenderProps) => ReactNode;
43
+ /**
44
+ * Render when connection is offline.
45
+ */
46
+ renderOffline: () => ReactNode;
47
+ /**
48
+ * Render when connection failed with error.
49
+ */
50
+ renderError: (error: string | null) => ReactNode;
51
+ }
52
+ /**
53
+ * Headless component that handles connection state logic.
54
+ * User provides all render callbacks - no default UI.
55
+ */
56
+ export declare function ConnectionStateRenderer({ connectionState, error, isReady, stores, registry, client, onAction, renderIdle, renderConnecting, renderConnectingSlow, renderConnected, renderOffline, renderError, }: ConnectionStateRendererProps): ReactNode;
package/app/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { ConnectionStateRenderer, type ConnectedRenderProps, type ConnectionStateRendererProps } from './connection-state-renderer';
2
+ export { useIkonApp, type IkonUiModuleRegistration, type LocalServerConfig, type UseIkonAppOptions, type UseIkonAppResult } from './use-ikon-app';
@@ -0,0 +1,134 @@
1
+ import { AudioConfig, ConnectionState, DebugConfig, IkonClient, MediaSessionConfig, TimeoutConfig, VideoConfig } from '../../../sdk/src/index.ts';
2
+ import { RefObject } from 'react';
3
+ import { AuthConfig } from '../auth/types';
4
+ import { IkonUiRegistry } from '../ikon-ui-registry';
5
+ import { IkonUi } from '../ikon-ui';
6
+ import { IkonUiStoreEntry } from '../surface';
7
+ /**
8
+ * Configuration for local server mode.
9
+ */
10
+ export interface LocalServerConfig {
11
+ enabled: boolean;
12
+ host?: string;
13
+ httpsPort?: number;
14
+ }
15
+ /**
16
+ * Module registration function type.
17
+ */
18
+ export type IkonUiModuleRegistration = (registry: IkonUiRegistry) => void;
19
+ /**
20
+ * Options for the useIkonApp hook.
21
+ */
22
+ export interface UseIkonAppOptions {
23
+ /**
24
+ * Authentication configuration. Pass null to disable auth.
25
+ */
26
+ authConfig: AuthConfig | null;
27
+ /**
28
+ * Local server configuration. If not provided, cloud mode is assumed.
29
+ */
30
+ localServer?: LocalServerConfig;
31
+ /**
32
+ * UI modules to register. Simpler alternative to registerModules callback.
33
+ * @example
34
+ * modules: [registerRadixModule]
35
+ */
36
+ modules?: IkonUiModuleRegistration[];
37
+ /**
38
+ * Register additional UI modules before loading.
39
+ * Use this for advanced scenarios; for simple cases prefer `modules`.
40
+ */
41
+ registerModules?: (registry: IkonUiRegistry) => void;
42
+ /**
43
+ * Callback when connected and joined.
44
+ */
45
+ onJoined?: (sessionId: string | undefined) => void;
46
+ /**
47
+ * Callback when connection state changes.
48
+ */
49
+ onConnectionStateChange?: (state: ConnectionState) => void;
50
+ /**
51
+ * Callback when an error occurs.
52
+ */
53
+ onError?: (error: Error) => void;
54
+ /**
55
+ * Whether to update the URL with the session ID after joining.
56
+ * Default: true
57
+ */
58
+ updateUrlOnJoin?: boolean;
59
+ /**
60
+ * Timeout configuration passed to IkonClient.
61
+ * If not provided, SDK defaults are used.
62
+ */
63
+ timeouts?: TimeoutConfig;
64
+ /**
65
+ * Audio playback configuration passed to IkonClient.
66
+ * If not provided, SDK defaults are used.
67
+ */
68
+ audio?: AudioConfig;
69
+ /**
70
+ * Video playback configuration passed to IkonClient.
71
+ * If not provided, SDK defaults are used.
72
+ */
73
+ video?: VideoConfig;
74
+ /**
75
+ * Media Session metadata for OS-level media controls (lock screen, notifications).
76
+ * Shared across audio and video playback.
77
+ */
78
+ mediaSession?: MediaSessionConfig;
79
+ /**
80
+ * Debug configuration passed to IkonClient.
81
+ * If not provided, SDK defaults are used.
82
+ */
83
+ debug?: DebugConfig;
84
+ }
85
+ /**
86
+ * Result returned by the useIkonApp hook.
87
+ */
88
+ export interface UseIkonAppResult {
89
+ /**
90
+ * Current connection state.
91
+ */
92
+ connectionState: ConnectionState;
93
+ /**
94
+ * Current error message, if any.
95
+ */
96
+ error: string | null;
97
+ /**
98
+ * UI stores for rendering.
99
+ */
100
+ stores: ReadonlyMap<string, IkonUiStoreEntry> | undefined;
101
+ /**
102
+ * Current IkonClient instance, or null if not connected.
103
+ */
104
+ client: IkonClient | null;
105
+ /**
106
+ * Current IkonUiRegistry instance, or null if not initialized.
107
+ */
108
+ registry: IkonUiRegistry | null;
109
+ /**
110
+ * Reference to the IkonClient instance (for use in callbacks).
111
+ */
112
+ clientRef: RefObject<IkonClient | null>;
113
+ /**
114
+ * Reference to the IkonUi instance.
115
+ */
116
+ uiRef: RefObject<IkonUi | null>;
117
+ /**
118
+ * Reference to the IkonUiRegistry instance (for use in callbacks).
119
+ */
120
+ registryRef: RefObject<IkonUiRegistry | null>;
121
+ /**
122
+ * Action handler for UI interactions.
123
+ */
124
+ onAction: (actionId: string, payload: unknown) => void;
125
+ /**
126
+ * Whether the connection is ready to render UI.
127
+ */
128
+ isReady: boolean;
129
+ }
130
+ /**
131
+ * High-level hook that manages the entire Ikon connection lifecycle.
132
+ * Encapsulates client creation, auth scenarios, UI registry setup, and state management.
133
+ */
134
+ export declare function useIkonApp(options: UseIkonAppOptions): UseIkonAppResult;
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from 'react';
2
+ import { AuthConfig, AuthContextValue } from './types';
3
+ export interface AuthProviderProps {
4
+ children: ReactNode;
5
+ config: AuthConfig;
6
+ }
7
+ /**
8
+ * Authentication provider that manages auth state and provides auth methods.
9
+ * This is a headless provider - it manages state only, no UI rendering.
10
+ */
11
+ export declare function AuthProvider({ children, config }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
12
+ /**
13
+ * Hook to access the auth context.
14
+ * Throws if used outside of AuthProvider.
15
+ */
16
+ export declare function useAuth(): AuthContextValue;
17
+ /**
18
+ * Hook to optionally access auth context.
19
+ * Returns null if used outside of AuthProvider (doesn't throw).
20
+ */
21
+ export declare function useAuthOptional(): AuthContextValue | null;
@@ -0,0 +1,43 @@
1
+ import { AuthSession, LoginMethod } from './types';
2
+ /**
3
+ * Result of parsing an OAuth callback from the URL.
4
+ */
5
+ export interface OAuthCallbackResult {
6
+ token: string;
7
+ provider: LoginMethod;
8
+ }
9
+ /**
10
+ * Authenticate anonymously with the Ikon auth service.
11
+ * Returns a session with a token for anonymous users.
12
+ */
13
+ export declare function authenticateAnonymous(spaceId: string, authUrl: string): Promise<AuthSession>;
14
+ /**
15
+ * Options for sending a magic link email.
16
+ */
17
+ export interface SendMagicLinkOptions {
18
+ email: string;
19
+ spaceId: string;
20
+ authUrl: string;
21
+ returnUrl?: string;
22
+ }
23
+ /**
24
+ * Send a magic link email for passwordless authentication.
25
+ */
26
+ export declare function sendMagicLink(options: SendMagicLinkOptions): Promise<void>;
27
+ /**
28
+ * Parse OAuth callback parameters from the current URL.
29
+ * Returns the token and provider if present, or null if not an OAuth callback.
30
+ */
31
+ export declare function parseOAuthCallback(): OAuthCallbackResult | null;
32
+ /**
33
+ * Get the error from an OAuth callback if present.
34
+ */
35
+ export declare function parseOAuthError(): string | null;
36
+ /**
37
+ * Clear OAuth-related parameters from the URL.
38
+ */
39
+ export declare function clearOAuthParams(): void;
40
+ /**
41
+ * Build an OAuth redirect URL for the given provider.
42
+ */
43
+ export declare function buildOAuthRedirectUrl(provider: LoginMethod, spaceId: string, authUrl: string, returnUrl?: string): string;
@@ -0,0 +1,5 @@
1
+ export type { AuthConfig, AuthContextValue, AuthSession, AuthState, AuthUser, LoginMethod } from './types';
2
+ export { clearAuthSession, loadAuthSession, saveAuthSession, sessionToUser } from './storage';
3
+ export { authenticateAnonymous, buildOAuthRedirectUrl, clearOAuthParams, parseOAuthCallback, parseOAuthError, sendMagicLink, type OAuthCallbackResult, type SendMagicLinkOptions } from './auth-service';
4
+ export { AuthProvider, useAuth, useAuthOptional, type AuthProviderProps } from './auth-context';
5
+ export { useAuthGuard, type UseAuthGuardOptions, type UseAuthGuardResult } from './use-auth-guard';
@@ -0,0 +1,18 @@
1
+ import { AuthSession, AuthUser } from './types';
2
+ /**
3
+ * Save the authenticated user session to localStorage.
4
+ */
5
+ export declare function saveAuthSession(session: AuthSession): void;
6
+ /**
7
+ * Load the authenticated user session from localStorage.
8
+ * Returns null if no session exists or if the session has expired.
9
+ */
10
+ export declare function loadAuthSession(): AuthSession | null;
11
+ /**
12
+ * Clear the authenticated user session from localStorage.
13
+ */
14
+ export declare function clearAuthSession(): void;
15
+ /**
16
+ * Convert AuthSession to AuthUser.
17
+ */
18
+ export declare function sessionToUser(session: AuthSession): AuthUser;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * All supported login methods.
3
+ */
4
+ export type LoginMethod = 'google' | 'facebook' | 'apple' | 'microsoft' | 'linkedin' | 'github' | 'email' | 'guest';
5
+ /**
6
+ * Authenticated user information.
7
+ */
8
+ export interface AuthUser {
9
+ id: string;
10
+ provider: LoginMethod | 'anonymous';
11
+ token: string;
12
+ authenticatedAt: number;
13
+ }
14
+ /**
15
+ * Authentication state.
16
+ */
17
+ export interface AuthState {
18
+ isAuthenticated: boolean;
19
+ isLoading: boolean;
20
+ user: AuthUser | null;
21
+ error: string | null;
22
+ }
23
+ /**
24
+ * Authentication configuration.
25
+ */
26
+ export interface AuthConfig {
27
+ enabled: boolean;
28
+ methods: LoginMethod[];
29
+ spaceId: string;
30
+ /** Optional custom auth URL. If not provided, derived from environment. */
31
+ authUrl?: string;
32
+ }
33
+ /**
34
+ * Stored session data in localStorage.
35
+ */
36
+ export interface AuthSession {
37
+ token: string;
38
+ provider: LoginMethod | 'anonymous';
39
+ authenticatedAt: number;
40
+ }
41
+ /**
42
+ * Auth context value returned by useAuth hook.
43
+ */
44
+ export interface AuthContextValue {
45
+ state: AuthState;
46
+ login: (method: LoginMethod) => void;
47
+ logout: () => void;
48
+ getToken: () => string | null;
49
+ }
@@ -0,0 +1,35 @@
1
+ import { AuthConfig } from './types';
2
+ export interface UseAuthGuardOptions {
3
+ /**
4
+ * Auth configuration with enabled methods.
5
+ */
6
+ config: AuthConfig;
7
+ /**
8
+ * URL parameter name that triggers automatic guest login.
9
+ * If the URL contains this parameter with a truthy value, guest login is triggered automatically.
10
+ */
11
+ guestUrlParam?: string;
12
+ }
13
+ export interface UseAuthGuardResult {
14
+ /**
15
+ * Whether the protected content should be rendered.
16
+ */
17
+ shouldRenderChildren: boolean;
18
+ /**
19
+ * Whether auth state is still being checked.
20
+ */
21
+ isCheckingAuth: boolean;
22
+ /**
23
+ * Whether the user is authenticated.
24
+ */
25
+ isAuthenticated: boolean;
26
+ /**
27
+ * Current auth error, if any.
28
+ */
29
+ error: string | null;
30
+ }
31
+ /**
32
+ * Headless hook for route protection logic.
33
+ * Returns state that can be used to conditionally render auth UI or protected content.
34
+ */
35
+ export declare function useAuthGuard(options: UseAuthGuardOptions): UseAuthGuardResult;
@@ -0,0 +1 @@
1
+ export { useLazyFont } from './use-lazy-font';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hook for lazy loading fonts. The font is only loaded when the returned function is called.
3
+ * Useful for loading fonts only when certain UI elements (like error overlays) are displayed.
4
+ *
5
+ * @param fontUrl - The URL of the font stylesheet (e.g., Google Fonts URL)
6
+ * @returns A function that loads the font when called. Safe to call multiple times - font only loads once.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const loadFont = useLazyFont('https://fonts.googleapis.com/css2?family=Space+Grotesk&display=swap');
11
+ *
12
+ * function ErrorOverlay() {
13
+ * loadFont(); // Font loads only when this component renders
14
+ * return <div>Error occurred</div>;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function useLazyFont(fontUrl: string): () => void;
package/i18n/i18n.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { ReactNode } from 'react';
2
+ type TranslationsMap<T> = Record<string, T>;
3
+ export interface I18nContextValue<T> {
4
+ t: <K extends keyof T>(key: K, params?: Record<string, string>) => string;
5
+ locale: string;
6
+ translations: T;
7
+ }
8
+ export interface I18nProviderProps<T> {
9
+ children: ReactNode;
10
+ translations: TranslationsMap<T>;
11
+ defaultLanguage?: string;
12
+ detectLanguage?: boolean;
13
+ }
14
+ export declare function I18nProvider<T extends object>({ children, translations, defaultLanguage, detectLanguage, }: I18nProviderProps<T>): import("react/jsx-runtime").JSX.Element;
15
+ export declare function useI18n<T extends object>(): I18nContextValue<T>;
16
+ export {};
@@ -0,0 +1 @@
1
+ export { I18nProvider, useI18n, type I18nContextValue, type I18nProviderProps } from './i18n';
package/index.d.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  export { IkonUi, type IkonUIConfig } from './ikon-ui';
2
- export { IkonUiRegistry, createIkonUiRegistry, type IkonUiComponentResolver, type IkonUiModuleLoader, type IkonUiModuleLoaderResult, } from './ikon-ui-registry';
3
- export { IkonUiSurface, IKON_UI_STREAM_CATEGORY, isIkonUiCategoryMatch, type IkonUiCategory, type IkonUiStoreEntry, } from './surface';
2
+ export { IkonUiRegistry, createIkonUiRegistry, type IkonUiComponentResolver, type IkonUiModuleLoader, type IkonUiModuleLoaderResult } from './ikon-ui-registry';
3
+ export { IkonUiSurface, IKON_UI_STREAM_CATEGORY, isIkonUiCategoryMatch, type IkonUiCategory, type IkonUiStoreEntry } from './surface';
4
4
  export { useIkonStyles, type IkonUiStyleSource } from './use-ikon-styles';
5
5
  export { useIkonUiStores } from './use-ikon-ui-stores';
6
- export { parseIkonUiInitPayload, normalizeIkonUiModuleList, readIkonUiModules, readIkonUiModulesFromSources, areIkonUiModuleListsEqual, type IkonUiInitInstruction, type IkonUiInitModulePayload, type IkonUiModuleList, } from './modules';
7
- export { IKON_UI_BASE_MODULE, createBaseResolvers, loadBaseModule, registerBaseModule, } from './base/base-module';
8
- export { IKON_UI_MEDIA_MODULE, IKON_UI_VIDEO_CANVAS_TYPE, IKON_UI_VIDEO_URL_PLAYER_TYPE, createMediaResolvers, loadMediaModule, registerMediaModule, } from './media/media-module';
9
- export { UiRenderer, type UiRendererProps, UiComponentRegistry, createComponentLibrary, useUiStore, useUiNode, renderChildren, } from './renderer';
10
- export type { UiComponentRenderer, UiComponentLibrary, UiNode, UiRenderContext, UiComponentRendererProps, ParsedUiUpdate, UiSnapshot, UiFullSnapshot, UiDiffSnapshot, UiNodeDiff, TextDelta, UiNodeProps, UiUpdateType, UiStoreSnapshot, UiOptimisticPatchState, } from './renderer';
6
+ export { parseIkonUiInitPayload, normalizeIkonUiModuleList, readIkonUiModules, readIkonUiModulesFromSources, areIkonUiModuleListsEqual, type IkonUiInitInstruction, type IkonUiInitModulePayload, type IkonUiModuleList } from './modules';
7
+ export { IKON_UI_BASE_MODULE, createBaseResolvers, loadBaseModule, registerBaseModule } from './base/base-module';
8
+ export { IKON_UI_MEDIA_MODULE, IKON_UI_VIDEO_CANVAS_TYPE, IKON_UI_VIDEO_URL_PLAYER_TYPE, createMediaResolvers, loadMediaModule, registerMediaModule } from './media/media-module';
9
+ export { UiRenderer, type UiRendererProps, UiComponentRegistry, createComponentLibrary, useUiStore, useUiNode, renderChildren } from './renderer';
10
+ export type { UiComponentRenderer, UiComponentLibrary, UiNode, UiRenderContext, UiComponentRendererProps, ParsedUiUpdate, UiSnapshot, UiFullSnapshot, UiDiffSnapshot, UiNodeDiff, TextDelta, UiNodeProps, UiUpdateType, UiStoreSnapshot, UiOptimisticPatchState } from './renderer';
11
11
  export { UiStreamStore, type UiStylePayload } from '../../sdk-ui/src/index.ts';
12
12
  export { renderMotionLetters } from './shared/render-motion-letters';
13
+ export { type AuthConfig, type AuthContextValue, type AuthSession, type AuthState, type AuthUser, type LoginMethod, clearAuthSession, loadAuthSession, saveAuthSession, sessionToUser, authenticateAnonymous, buildOAuthRedirectUrl, clearOAuthParams, parseOAuthCallback, parseOAuthError, sendMagicLink, type OAuthCallbackResult, type SendMagicLinkOptions, AuthProvider, useAuth, useAuthOptional, type AuthProviderProps, useAuthGuard, type UseAuthGuardOptions, type UseAuthGuardResult, } from './auth';
14
+ export { ConnectionStateRenderer, type ConnectedRenderProps, type ConnectionStateRendererProps, useIkonApp, type IkonUiModuleRegistration, type LocalServerConfig, type UseIkonAppOptions, type UseIkonAppResult, } from './app';
15
+ export { useLazyFont } from './hooks';
16
+ export { I18nProvider, useI18n, type I18nContextValue, type I18nProviderProps } from './i18n';