@iota-uz/sdk 0.3.0 → 0.3.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/README.MD +2 -0
- package/dist/applet/vite.cjs +231 -0
- package/dist/applet/vite.cjs.map +1 -0
- package/dist/applet/vite.d.cts +115 -0
- package/dist/applet/vite.d.ts +115 -0
- package/dist/applet/vite.mjs +214 -0
- package/dist/applet/vite.mjs.map +1 -0
- package/dist/bichat/index.cjs +8551 -2320
- package/dist/bichat/index.cjs.map +1 -1
- package/dist/bichat/index.css +145 -37
- package/dist/bichat/index.css.map +1 -1
- package/dist/bichat/index.d.cts +1256 -232
- package/dist/bichat/index.d.ts +1256 -232
- package/dist/bichat/index.mjs +8510 -2327
- package/dist/bichat/index.mjs.map +1 -1
- package/dist/bichat/styles.css +165 -49
- package/dist/bichat/tailwind.cjs +93 -0
- package/dist/bichat/tailwind.cjs.map +1 -0
- package/dist/bichat/tailwind.d.cts +21 -0
- package/dist/bichat/tailwind.d.ts +21 -0
- package/dist/bichat/tailwind.mjs +85 -0
- package/dist/bichat/tailwind.mjs.map +1 -0
- package/dist/index-B73-BCi-.d.cts +84 -0
- package/dist/index-B73-BCi-.d.ts +84 -0
- package/dist/index.cjs +347 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -81
- package/dist/index.d.ts +76 -81
- package/dist/index.mjs +343 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +29 -2
- package/tailwind/compiled.css +1 -1
- package/tailwind/iota.css +7 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,84 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* TypeScript type definitions for IOTA SDK Applet Core
|
|
6
|
-
* Matches Go backend types from pkg/applet/types.go
|
|
7
|
-
*/
|
|
8
|
-
interface InitialContext {
|
|
9
|
-
user: UserContext;
|
|
10
|
-
tenant: TenantContext;
|
|
11
|
-
locale: LocaleContext;
|
|
12
|
-
config: AppConfig;
|
|
13
|
-
route: RouteContext;
|
|
14
|
-
session: SessionContext;
|
|
15
|
-
error: ErrorContext | null;
|
|
16
|
-
extensions?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
interface UserContext {
|
|
19
|
-
id: number;
|
|
20
|
-
email: string;
|
|
21
|
-
firstName: string;
|
|
22
|
-
lastName: string;
|
|
23
|
-
permissions: string[];
|
|
24
|
-
}
|
|
25
|
-
interface TenantContext {
|
|
26
|
-
id: string;
|
|
27
|
-
name: string;
|
|
28
|
-
}
|
|
29
|
-
interface LocaleContext {
|
|
30
|
-
language: string;
|
|
31
|
-
translations: Record<string, string>;
|
|
32
|
-
}
|
|
33
|
-
interface AppConfig {
|
|
34
|
-
graphQLEndpoint?: string;
|
|
35
|
-
streamEndpoint?: string;
|
|
36
|
-
restEndpoint?: string;
|
|
37
|
-
}
|
|
38
|
-
interface RouteContext {
|
|
39
|
-
path: string;
|
|
40
|
-
params: Record<string, string>;
|
|
41
|
-
query: Record<string, string>;
|
|
42
|
-
}
|
|
43
|
-
interface SessionContext {
|
|
44
|
-
expiresAt: number;
|
|
45
|
-
refreshURL: string;
|
|
46
|
-
csrfToken: string;
|
|
47
|
-
}
|
|
48
|
-
interface ErrorContext {
|
|
49
|
-
supportEmail?: string;
|
|
50
|
-
debugMode: boolean;
|
|
51
|
-
errorCodes?: Record<string, string>;
|
|
52
|
-
retryConfig?: RetryConfig;
|
|
53
|
-
}
|
|
54
|
-
interface RetryConfig {
|
|
55
|
-
maxAttempts: number;
|
|
56
|
-
backoffMs: number;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Hook return types
|
|
60
|
-
*/
|
|
61
|
-
interface TranslationHook {
|
|
62
|
-
t: (key: string, params?: Record<string, unknown>) => string;
|
|
63
|
-
language: string;
|
|
64
|
-
}
|
|
65
|
-
interface PermissionsHook {
|
|
66
|
-
hasPermission: (permission: string) => boolean;
|
|
67
|
-
hasAnyPermission: (...permissions: string[]) => boolean;
|
|
68
|
-
permissions: string[];
|
|
69
|
-
}
|
|
70
|
-
interface SessionHook {
|
|
71
|
-
isExpiringSoon: boolean;
|
|
72
|
-
refreshSession: () => Promise<void>;
|
|
73
|
-
csrfToken: string;
|
|
74
|
-
expiresAt: number;
|
|
75
|
-
}
|
|
76
|
-
interface StreamingHook {
|
|
77
|
-
isStreaming: boolean;
|
|
78
|
-
processStream: <T>(generator: AsyncGenerator<T>, onChunk: (chunk: T) => void, signal?: AbortSignal) => Promise<void>;
|
|
79
|
-
cancel: () => void;
|
|
80
|
-
reset: () => void;
|
|
81
|
-
}
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import { I as InitialContext, A as AppConfig, U as UserContext, P as PermissionsHook, T as TranslationHook, S as SessionHook, R as RouteContext, a as StreamingHook } from './index-B73-BCi-.cjs';
|
|
4
|
+
export { L as LocaleContext, b as SessionContext, c as TenantContext } from './index-B73-BCi-.cjs';
|
|
82
5
|
|
|
83
6
|
interface AppletProviderProps {
|
|
84
7
|
children: ReactNode;
|
|
@@ -234,4 +157,76 @@ declare function useRoute(): RouteContext;
|
|
|
234
157
|
*/
|
|
235
158
|
declare function useStreaming(): StreamingHook;
|
|
236
159
|
|
|
237
|
-
|
|
160
|
+
type ShellMode$1 = 'embedded' | 'standalone';
|
|
161
|
+
interface AppletRuntime {
|
|
162
|
+
basePath: string;
|
|
163
|
+
assetsBasePath: string;
|
|
164
|
+
rpcEndpoint?: string;
|
|
165
|
+
shellMode?: ShellMode$1;
|
|
166
|
+
}
|
|
167
|
+
declare function useAppletRuntime(): AppletRuntime;
|
|
168
|
+
|
|
169
|
+
type RouterMode$1 = 'url' | 'memory';
|
|
170
|
+
type ShellMode = 'embedded' | 'standalone';
|
|
171
|
+
interface AppletHostConfig {
|
|
172
|
+
basePath: string;
|
|
173
|
+
shellMode?: ShellMode;
|
|
174
|
+
routerMode: RouterMode$1;
|
|
175
|
+
attrs: Record<string, string>;
|
|
176
|
+
}
|
|
177
|
+
interface DefineReactAppletElementOptions {
|
|
178
|
+
tagName: string;
|
|
179
|
+
styles?: string | (() => string);
|
|
180
|
+
render: (host: AppletHostConfig) => react__default.ReactElement;
|
|
181
|
+
observedAttributes?: string[];
|
|
182
|
+
observeDarkMode?: boolean;
|
|
183
|
+
}
|
|
184
|
+
declare function defineReactAppletElement(options: DefineReactAppletElementOptions): void;
|
|
185
|
+
|
|
186
|
+
interface AppletRPCError {
|
|
187
|
+
code: string;
|
|
188
|
+
message: string;
|
|
189
|
+
details?: unknown;
|
|
190
|
+
}
|
|
191
|
+
declare class AppletRPCException extends Error {
|
|
192
|
+
code: string;
|
|
193
|
+
details?: unknown;
|
|
194
|
+
cause?: unknown;
|
|
195
|
+
constructor(args: {
|
|
196
|
+
code: string;
|
|
197
|
+
message: string;
|
|
198
|
+
details?: unknown;
|
|
199
|
+
cause?: unknown;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
type AppletRPCSchema = Record<string, {
|
|
203
|
+
params: unknown;
|
|
204
|
+
result: unknown;
|
|
205
|
+
}>;
|
|
206
|
+
interface CreateAppletRPCClientOptions {
|
|
207
|
+
endpoint: string;
|
|
208
|
+
fetcher?: typeof fetch;
|
|
209
|
+
}
|
|
210
|
+
declare function createAppletRPCClient(options: CreateAppletRPCClientOptions): {
|
|
211
|
+
call: <TParams, TResult>(method: string, params: TParams) => Promise<TResult>;
|
|
212
|
+
callTyped: <TRouter extends AppletRPCSchema, TMethod extends keyof TRouter & string>(method: TMethod, params: TRouter[TMethod]["params"]) => Promise<TRouter[TMethod]["result"]>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
type RouterMode = 'url' | 'memory';
|
|
216
|
+
interface CreateAppletRouterOptions {
|
|
217
|
+
mode: RouterMode;
|
|
218
|
+
basePath?: string;
|
|
219
|
+
BrowserRouter: react__default.ComponentType<any>;
|
|
220
|
+
MemoryRouter: react__default.ComponentType<any>;
|
|
221
|
+
}
|
|
222
|
+
declare function createAppletRouter(options: CreateAppletRouterOptions): {
|
|
223
|
+
Router: react__default.FC<{
|
|
224
|
+
children?: react__default.ReactNode | undefined;
|
|
225
|
+
}>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
declare function shouldEnableAppletDevtools(): boolean;
|
|
229
|
+
|
|
230
|
+
declare function AppletDevtoolsOverlay(): react_jsx_runtime.JSX.Element;
|
|
231
|
+
|
|
232
|
+
export { AppConfig, AppletDevtoolsOverlay, AppletProvider, type AppletRPCError, AppletRPCException, type AppletRPCSchema, ConfigProvider, InitialContext, PermissionsHook, RouteContext, type RouterMode, SessionHook, StreamingHook, TranslationHook, UserContext, createAppletRPCClient, createAppletRouter, defineReactAppletElement, shouldEnableAppletDevtools, useAppletContext$1 as useAppletContext, useAppletContext as useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,84 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* TypeScript type definitions for IOTA SDK Applet Core
|
|
6
|
-
* Matches Go backend types from pkg/applet/types.go
|
|
7
|
-
*/
|
|
8
|
-
interface InitialContext {
|
|
9
|
-
user: UserContext;
|
|
10
|
-
tenant: TenantContext;
|
|
11
|
-
locale: LocaleContext;
|
|
12
|
-
config: AppConfig;
|
|
13
|
-
route: RouteContext;
|
|
14
|
-
session: SessionContext;
|
|
15
|
-
error: ErrorContext | null;
|
|
16
|
-
extensions?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
interface UserContext {
|
|
19
|
-
id: number;
|
|
20
|
-
email: string;
|
|
21
|
-
firstName: string;
|
|
22
|
-
lastName: string;
|
|
23
|
-
permissions: string[];
|
|
24
|
-
}
|
|
25
|
-
interface TenantContext {
|
|
26
|
-
id: string;
|
|
27
|
-
name: string;
|
|
28
|
-
}
|
|
29
|
-
interface LocaleContext {
|
|
30
|
-
language: string;
|
|
31
|
-
translations: Record<string, string>;
|
|
32
|
-
}
|
|
33
|
-
interface AppConfig {
|
|
34
|
-
graphQLEndpoint?: string;
|
|
35
|
-
streamEndpoint?: string;
|
|
36
|
-
restEndpoint?: string;
|
|
37
|
-
}
|
|
38
|
-
interface RouteContext {
|
|
39
|
-
path: string;
|
|
40
|
-
params: Record<string, string>;
|
|
41
|
-
query: Record<string, string>;
|
|
42
|
-
}
|
|
43
|
-
interface SessionContext {
|
|
44
|
-
expiresAt: number;
|
|
45
|
-
refreshURL: string;
|
|
46
|
-
csrfToken: string;
|
|
47
|
-
}
|
|
48
|
-
interface ErrorContext {
|
|
49
|
-
supportEmail?: string;
|
|
50
|
-
debugMode: boolean;
|
|
51
|
-
errorCodes?: Record<string, string>;
|
|
52
|
-
retryConfig?: RetryConfig;
|
|
53
|
-
}
|
|
54
|
-
interface RetryConfig {
|
|
55
|
-
maxAttempts: number;
|
|
56
|
-
backoffMs: number;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Hook return types
|
|
60
|
-
*/
|
|
61
|
-
interface TranslationHook {
|
|
62
|
-
t: (key: string, params?: Record<string, unknown>) => string;
|
|
63
|
-
language: string;
|
|
64
|
-
}
|
|
65
|
-
interface PermissionsHook {
|
|
66
|
-
hasPermission: (permission: string) => boolean;
|
|
67
|
-
hasAnyPermission: (...permissions: string[]) => boolean;
|
|
68
|
-
permissions: string[];
|
|
69
|
-
}
|
|
70
|
-
interface SessionHook {
|
|
71
|
-
isExpiringSoon: boolean;
|
|
72
|
-
refreshSession: () => Promise<void>;
|
|
73
|
-
csrfToken: string;
|
|
74
|
-
expiresAt: number;
|
|
75
|
-
}
|
|
76
|
-
interface StreamingHook {
|
|
77
|
-
isStreaming: boolean;
|
|
78
|
-
processStream: <T>(generator: AsyncGenerator<T>, onChunk: (chunk: T) => void, signal?: AbortSignal) => Promise<void>;
|
|
79
|
-
cancel: () => void;
|
|
80
|
-
reset: () => void;
|
|
81
|
-
}
|
|
2
|
+
import react__default, { ReactNode } from 'react';
|
|
3
|
+
import { I as InitialContext, A as AppConfig, U as UserContext, P as PermissionsHook, T as TranslationHook, S as SessionHook, R as RouteContext, a as StreamingHook } from './index-B73-BCi-.js';
|
|
4
|
+
export { L as LocaleContext, b as SessionContext, c as TenantContext } from './index-B73-BCi-.js';
|
|
82
5
|
|
|
83
6
|
interface AppletProviderProps {
|
|
84
7
|
children: ReactNode;
|
|
@@ -234,4 +157,76 @@ declare function useRoute(): RouteContext;
|
|
|
234
157
|
*/
|
|
235
158
|
declare function useStreaming(): StreamingHook;
|
|
236
159
|
|
|
237
|
-
|
|
160
|
+
type ShellMode$1 = 'embedded' | 'standalone';
|
|
161
|
+
interface AppletRuntime {
|
|
162
|
+
basePath: string;
|
|
163
|
+
assetsBasePath: string;
|
|
164
|
+
rpcEndpoint?: string;
|
|
165
|
+
shellMode?: ShellMode$1;
|
|
166
|
+
}
|
|
167
|
+
declare function useAppletRuntime(): AppletRuntime;
|
|
168
|
+
|
|
169
|
+
type RouterMode$1 = 'url' | 'memory';
|
|
170
|
+
type ShellMode = 'embedded' | 'standalone';
|
|
171
|
+
interface AppletHostConfig {
|
|
172
|
+
basePath: string;
|
|
173
|
+
shellMode?: ShellMode;
|
|
174
|
+
routerMode: RouterMode$1;
|
|
175
|
+
attrs: Record<string, string>;
|
|
176
|
+
}
|
|
177
|
+
interface DefineReactAppletElementOptions {
|
|
178
|
+
tagName: string;
|
|
179
|
+
styles?: string | (() => string);
|
|
180
|
+
render: (host: AppletHostConfig) => react__default.ReactElement;
|
|
181
|
+
observedAttributes?: string[];
|
|
182
|
+
observeDarkMode?: boolean;
|
|
183
|
+
}
|
|
184
|
+
declare function defineReactAppletElement(options: DefineReactAppletElementOptions): void;
|
|
185
|
+
|
|
186
|
+
interface AppletRPCError {
|
|
187
|
+
code: string;
|
|
188
|
+
message: string;
|
|
189
|
+
details?: unknown;
|
|
190
|
+
}
|
|
191
|
+
declare class AppletRPCException extends Error {
|
|
192
|
+
code: string;
|
|
193
|
+
details?: unknown;
|
|
194
|
+
cause?: unknown;
|
|
195
|
+
constructor(args: {
|
|
196
|
+
code: string;
|
|
197
|
+
message: string;
|
|
198
|
+
details?: unknown;
|
|
199
|
+
cause?: unknown;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
type AppletRPCSchema = Record<string, {
|
|
203
|
+
params: unknown;
|
|
204
|
+
result: unknown;
|
|
205
|
+
}>;
|
|
206
|
+
interface CreateAppletRPCClientOptions {
|
|
207
|
+
endpoint: string;
|
|
208
|
+
fetcher?: typeof fetch;
|
|
209
|
+
}
|
|
210
|
+
declare function createAppletRPCClient(options: CreateAppletRPCClientOptions): {
|
|
211
|
+
call: <TParams, TResult>(method: string, params: TParams) => Promise<TResult>;
|
|
212
|
+
callTyped: <TRouter extends AppletRPCSchema, TMethod extends keyof TRouter & string>(method: TMethod, params: TRouter[TMethod]["params"]) => Promise<TRouter[TMethod]["result"]>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
type RouterMode = 'url' | 'memory';
|
|
216
|
+
interface CreateAppletRouterOptions {
|
|
217
|
+
mode: RouterMode;
|
|
218
|
+
basePath?: string;
|
|
219
|
+
BrowserRouter: react__default.ComponentType<any>;
|
|
220
|
+
MemoryRouter: react__default.ComponentType<any>;
|
|
221
|
+
}
|
|
222
|
+
declare function createAppletRouter(options: CreateAppletRouterOptions): {
|
|
223
|
+
Router: react__default.FC<{
|
|
224
|
+
children?: react__default.ReactNode | undefined;
|
|
225
|
+
}>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
declare function shouldEnableAppletDevtools(): boolean;
|
|
229
|
+
|
|
230
|
+
declare function AppletDevtoolsOverlay(): react_jsx_runtime.JSX.Element;
|
|
231
|
+
|
|
232
|
+
export { AppConfig, AppletDevtoolsOverlay, AppletProvider, type AppletRPCError, AppletRPCException, type AppletRPCSchema, ConfigProvider, InitialContext, PermissionsHook, RouteContext, type RouterMode, SessionHook, StreamingHook, TranslationHook, UserContext, createAppletRPCClient, createAppletRouter, defineReactAppletElement, shouldEnableAppletDevtools, useAppletContext$1 as useAppletContext, useAppletContext as useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createContext, useContext, useMemo, useState, useRef, useCallback } from 'react';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { createContext, useContext, useMemo, useState, useRef, useCallback, useEffect } from 'react';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
3
4
|
|
|
4
5
|
// ui/src/applet-core/context/AppletContext.tsx
|
|
5
6
|
var AppletContext = createContext(null);
|
|
@@ -173,6 +174,345 @@ function useStreaming() {
|
|
|
173
174
|
};
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
|
|
177
|
+
// ui/src/applet-core/hooks/useAppletRuntime.ts
|
|
178
|
+
function useAppletRuntime() {
|
|
179
|
+
const config = useConfig();
|
|
180
|
+
const basePath = config.basePath ?? "";
|
|
181
|
+
const normalizedBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
182
|
+
const assetsBasePath = config.assetsBasePath ?? `${normalizedBasePath || ""}/assets`;
|
|
183
|
+
const rpcEndpoint = config.rpcUIEndpoint;
|
|
184
|
+
const shellMode = config.shellMode;
|
|
185
|
+
return { basePath: normalizedBasePath, assetsBasePath, rpcEndpoint, shellMode };
|
|
186
|
+
}
|
|
187
|
+
function defineReactAppletElement(options) {
|
|
188
|
+
const tagName = options.tagName.toLowerCase();
|
|
189
|
+
const registry = getRegistry();
|
|
190
|
+
const existing = registry.get(tagName);
|
|
191
|
+
if (existing) {
|
|
192
|
+
existing.options = options;
|
|
193
|
+
for (const a of options.observedAttributes ?? []) existing.observed.add(a);
|
|
194
|
+
} else {
|
|
195
|
+
const observed = /* @__PURE__ */ new Set(["base-path", "shell-mode", "router-mode"]);
|
|
196
|
+
for (const a of options.observedAttributes ?? []) observed.add(a);
|
|
197
|
+
registry.set(tagName, { options, observed });
|
|
198
|
+
}
|
|
199
|
+
if (customElements.get(tagName)) {
|
|
200
|
+
if (typeof window !== "undefined") {
|
|
201
|
+
window.dispatchEvent(new CustomEvent("iota:applet-host-update", { detail: { tagName } }));
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
function getEntry() {
|
|
206
|
+
const entry = getRegistry().get(tagName);
|
|
207
|
+
if (!entry) throw new Error(`[${tagName}] applet host registry entry missing`);
|
|
208
|
+
return entry;
|
|
209
|
+
}
|
|
210
|
+
class ReactAppletElement extends HTMLElement {
|
|
211
|
+
constructor() {
|
|
212
|
+
super(...arguments);
|
|
213
|
+
this.reactRoot = null;
|
|
214
|
+
this.container = null;
|
|
215
|
+
this.darkModeObserver = null;
|
|
216
|
+
this.styleEl = null;
|
|
217
|
+
this.updateListener = null;
|
|
218
|
+
}
|
|
219
|
+
static get observedAttributes() {
|
|
220
|
+
return Array.from(getEntry().observed);
|
|
221
|
+
}
|
|
222
|
+
connectedCallback() {
|
|
223
|
+
const shadowRoot = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
224
|
+
if (!this.container) {
|
|
225
|
+
this.container = document.createElement("div");
|
|
226
|
+
this.container.id = "react-root";
|
|
227
|
+
this.container.style.display = "flex";
|
|
228
|
+
this.container.style.flexDirection = "column";
|
|
229
|
+
this.container.style.flex = "1";
|
|
230
|
+
this.container.style.minHeight = "0";
|
|
231
|
+
this.container.style.height = "100%";
|
|
232
|
+
this.container.style.width = "100%";
|
|
233
|
+
}
|
|
234
|
+
const existingContainer = shadowRoot.querySelector("#react-root");
|
|
235
|
+
if (!existingContainer) {
|
|
236
|
+
if (this.styleEl) shadowRoot.appendChild(this.styleEl);
|
|
237
|
+
shadowRoot.appendChild(this.container);
|
|
238
|
+
} else if (existingContainer !== this.container) {
|
|
239
|
+
this.container = existingContainer;
|
|
240
|
+
}
|
|
241
|
+
this.syncFromRegistry();
|
|
242
|
+
this.updateListener ?? (this.updateListener = (e) => {
|
|
243
|
+
if (!(e instanceof CustomEvent)) return;
|
|
244
|
+
const detail = e.detail;
|
|
245
|
+
if (!detail || detail.tagName !== tagName) return;
|
|
246
|
+
this.syncFromRegistry();
|
|
247
|
+
this.renderReact();
|
|
248
|
+
});
|
|
249
|
+
window.addEventListener("iota:applet-host-update", this.updateListener);
|
|
250
|
+
this.renderReact();
|
|
251
|
+
}
|
|
252
|
+
disconnectedCallback() {
|
|
253
|
+
if (this.updateListener) {
|
|
254
|
+
window.removeEventListener("iota:applet-host-update", this.updateListener);
|
|
255
|
+
}
|
|
256
|
+
this.darkModeObserver?.disconnect();
|
|
257
|
+
this.darkModeObserver = null;
|
|
258
|
+
this.reactRoot?.unmount();
|
|
259
|
+
this.reactRoot = null;
|
|
260
|
+
}
|
|
261
|
+
attributeChangedCallback(_name, oldValue, newValue) {
|
|
262
|
+
if (oldValue === newValue) return;
|
|
263
|
+
if (this.container) this.renderReact();
|
|
264
|
+
}
|
|
265
|
+
getHostConfig() {
|
|
266
|
+
const attrs = {};
|
|
267
|
+
for (const { name, value } of Array.from(this.attributes)) {
|
|
268
|
+
attrs[name] = value;
|
|
269
|
+
}
|
|
270
|
+
const basePath = this.getAttribute("base-path") ?? "";
|
|
271
|
+
const shellMode = this.getAttribute("shell-mode") ?? void 0;
|
|
272
|
+
const routerMode = this.getAttribute("router-mode") ?? "url";
|
|
273
|
+
return { basePath, shellMode, routerMode, attrs };
|
|
274
|
+
}
|
|
275
|
+
renderReact() {
|
|
276
|
+
if (!this.container) return;
|
|
277
|
+
if (!this.reactRoot) {
|
|
278
|
+
this.reactRoot = createRoot(this.container);
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
this.reactRoot.render(getEntry().options.render(this.getHostConfig()));
|
|
282
|
+
} catch (err) {
|
|
283
|
+
console.error(`[${tagName}] failed to mount React app:`, err);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
syncFromRegistry() {
|
|
287
|
+
const entry = getEntry();
|
|
288
|
+
const styles = typeof entry.options.styles === "function" ? entry.options.styles() : entry.options.styles;
|
|
289
|
+
if (styles) {
|
|
290
|
+
this.styleEl ?? (this.styleEl = document.createElement("style"));
|
|
291
|
+
this.styleEl.textContent = styles;
|
|
292
|
+
if (this.shadowRoot && !this.shadowRoot.contains(this.styleEl)) {
|
|
293
|
+
this.shadowRoot.insertBefore(this.styleEl, this.shadowRoot.firstChild);
|
|
294
|
+
}
|
|
295
|
+
} else if (this.styleEl) {
|
|
296
|
+
this.styleEl.remove();
|
|
297
|
+
this.styleEl = null;
|
|
298
|
+
}
|
|
299
|
+
if (entry.options.observeDarkMode !== false) {
|
|
300
|
+
this.darkModeObserver ?? (this.darkModeObserver = this.syncDarkMode());
|
|
301
|
+
} else if (this.darkModeObserver) {
|
|
302
|
+
this.darkModeObserver.disconnect();
|
|
303
|
+
this.darkModeObserver = null;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
syncDarkMode() {
|
|
307
|
+
const root = this.container;
|
|
308
|
+
if (!root) throw new Error("react root container not found");
|
|
309
|
+
const apply = () => {
|
|
310
|
+
if (document.documentElement.classList.contains("dark")) root.classList.add("dark");
|
|
311
|
+
else root.classList.remove("dark");
|
|
312
|
+
};
|
|
313
|
+
apply();
|
|
314
|
+
const observer = new MutationObserver(apply);
|
|
315
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
|
|
316
|
+
return observer;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
customElements.define(tagName, ReactAppletElement);
|
|
320
|
+
}
|
|
321
|
+
function getRegistry() {
|
|
322
|
+
const anyGlobal = globalThis;
|
|
323
|
+
anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__ ?? (anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__ = /* @__PURE__ */ new Map());
|
|
324
|
+
return anyGlobal.__IOTA_REACT_APPLET_HOST_REGISTRY__;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ui/src/applet-devtools/enabled.ts
|
|
328
|
+
function shouldEnableAppletDevtools() {
|
|
329
|
+
if (typeof window === "undefined") return false;
|
|
330
|
+
const url = new URL(window.location.href);
|
|
331
|
+
if (url.searchParams.get("appletDebug") === "1") return true;
|
|
332
|
+
try {
|
|
333
|
+
return window.localStorage.getItem("iotaAppletDevtools") === "1";
|
|
334
|
+
} catch {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ui/src/applet-host/rpc.ts
|
|
340
|
+
var AppletRPCException = class extends Error {
|
|
341
|
+
constructor(args) {
|
|
342
|
+
super(args.message);
|
|
343
|
+
this.name = "AppletRPCException";
|
|
344
|
+
this.code = args.code;
|
|
345
|
+
this.details = args.details;
|
|
346
|
+
this.cause = args.cause;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
function createAppletRPCClient(options) {
|
|
350
|
+
const fetcher = options.fetcher ?? fetch;
|
|
351
|
+
async function call(method, params) {
|
|
352
|
+
const req = { id: crypto.randomUUID(), method, params };
|
|
353
|
+
const startedAt = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
354
|
+
maybeDispatchRPCEvent({
|
|
355
|
+
id: req.id,
|
|
356
|
+
method: req.method,
|
|
357
|
+
status: "start"
|
|
358
|
+
});
|
|
359
|
+
try {
|
|
360
|
+
const resp = await fetcher(options.endpoint, {
|
|
361
|
+
method: "POST",
|
|
362
|
+
headers: { "Content-Type": "application/json" },
|
|
363
|
+
body: JSON.stringify(req)
|
|
364
|
+
});
|
|
365
|
+
if (!resp.ok) {
|
|
366
|
+
throw new AppletRPCException({
|
|
367
|
+
code: "http_error",
|
|
368
|
+
message: `HTTP ${resp.status}`,
|
|
369
|
+
details: { status: resp.status }
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
const json = await resp.json();
|
|
373
|
+
if (json.error) {
|
|
374
|
+
throw new AppletRPCException({
|
|
375
|
+
code: json.error.code,
|
|
376
|
+
message: json.error.message,
|
|
377
|
+
details: json.error.details
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (json.result === void 0) {
|
|
381
|
+
throw new AppletRPCException({
|
|
382
|
+
code: "invalid_response",
|
|
383
|
+
message: "Missing result in successful response"
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
maybeDispatchRPCEvent({
|
|
387
|
+
id: req.id,
|
|
388
|
+
method: req.method,
|
|
389
|
+
status: "success",
|
|
390
|
+
durationMs: elapsedMs(startedAt)
|
|
391
|
+
});
|
|
392
|
+
return json.result;
|
|
393
|
+
} catch (err) {
|
|
394
|
+
maybeDispatchRPCEvent({
|
|
395
|
+
id: req.id,
|
|
396
|
+
method: req.method,
|
|
397
|
+
status: "error",
|
|
398
|
+
durationMs: elapsedMs(startedAt),
|
|
399
|
+
error: err
|
|
400
|
+
});
|
|
401
|
+
throw err;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async function callTyped(method, params) {
|
|
405
|
+
return call(method, params);
|
|
406
|
+
}
|
|
407
|
+
return { call, callTyped };
|
|
408
|
+
}
|
|
409
|
+
function maybeDispatchRPCEvent(detail) {
|
|
410
|
+
if (typeof window === "undefined") return;
|
|
411
|
+
if (!shouldEnableAppletDevtools()) return;
|
|
412
|
+
window.dispatchEvent(new CustomEvent("iota:applet-rpc", { detail }));
|
|
413
|
+
}
|
|
414
|
+
function elapsedMs(startedAt) {
|
|
415
|
+
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
416
|
+
return Math.max(0, Math.round(now - startedAt));
|
|
417
|
+
}
|
|
418
|
+
function createAppletRouter(options) {
|
|
419
|
+
const basePath = options.basePath ?? "";
|
|
420
|
+
const Router = ({ children }) => {
|
|
421
|
+
if (options.mode === "memory") {
|
|
422
|
+
const MemoryRouter = options.MemoryRouter;
|
|
423
|
+
return /* @__PURE__ */ jsx(MemoryRouter, { children });
|
|
424
|
+
}
|
|
425
|
+
const BrowserRouter = options.BrowserRouter;
|
|
426
|
+
return /* @__PURE__ */ jsx(BrowserRouter, { basename: basePath, children });
|
|
427
|
+
};
|
|
428
|
+
return { Router };
|
|
429
|
+
}
|
|
430
|
+
function AppletDevtoolsOverlay() {
|
|
431
|
+
const ctx = useAppletContext();
|
|
432
|
+
const runtime = useAppletRuntime();
|
|
433
|
+
const [rpcEvents, setRPCEvents] = useState([]);
|
|
434
|
+
useEffect(() => {
|
|
435
|
+
const onEvent = (e) => {
|
|
436
|
+
if (!(e instanceof CustomEvent)) return;
|
|
437
|
+
const detail = e.detail;
|
|
438
|
+
if (!detail) return;
|
|
439
|
+
setRPCEvents((prev) => [detail, ...prev].slice(0, 50));
|
|
440
|
+
};
|
|
441
|
+
window.addEventListener("iota:applet-rpc", onEvent);
|
|
442
|
+
return () => window.removeEventListener("iota:applet-rpc", onEvent);
|
|
443
|
+
}, []);
|
|
444
|
+
const summary = useMemo(() => {
|
|
445
|
+
return {
|
|
446
|
+
basePath: runtime.basePath,
|
|
447
|
+
assetsBasePath: runtime.assetsBasePath,
|
|
448
|
+
rpcEndpoint: runtime.rpcEndpoint,
|
|
449
|
+
shellMode: runtime.shellMode,
|
|
450
|
+
route: ctx.route,
|
|
451
|
+
user: { id: ctx.user.id, email: ctx.user.email },
|
|
452
|
+
tenant: ctx.tenant
|
|
453
|
+
};
|
|
454
|
+
}, [ctx.route, ctx.tenant, ctx.user.email, ctx.user.id, runtime.assetsBasePath, runtime.basePath, runtime.rpcEndpoint, runtime.shellMode]);
|
|
455
|
+
return /* @__PURE__ */ jsxs(
|
|
456
|
+
"div",
|
|
457
|
+
{
|
|
458
|
+
style: {
|
|
459
|
+
position: "fixed",
|
|
460
|
+
right: 12,
|
|
461
|
+
bottom: 12,
|
|
462
|
+
width: 420,
|
|
463
|
+
maxHeight: "60vh",
|
|
464
|
+
overflow: "auto",
|
|
465
|
+
background: "rgba(17, 24, 39, 0.92)",
|
|
466
|
+
color: "#E5E7EB",
|
|
467
|
+
border: "1px solid rgba(255,255,255,0.12)",
|
|
468
|
+
borderRadius: 10,
|
|
469
|
+
padding: 12,
|
|
470
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
471
|
+
fontSize: 12,
|
|
472
|
+
zIndex: 2147483647
|
|
473
|
+
},
|
|
474
|
+
children: [
|
|
475
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 8 }, children: [
|
|
476
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 700 }, children: "Applet Devtools" }),
|
|
477
|
+
/* @__PURE__ */ jsx("div", { style: { opacity: 0.7 }, children: runtime.shellMode ?? "unknown" })
|
|
478
|
+
] }),
|
|
479
|
+
/* @__PURE__ */ jsxs("div", { style: { marginBottom: 10 }, children: [
|
|
480
|
+
/* @__PURE__ */ jsx("div", { style: { opacity: 0.85, marginBottom: 4 }, children: "Context" }),
|
|
481
|
+
/* @__PURE__ */ jsx("pre", { style: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: JSON.stringify(summary, null, 2) })
|
|
482
|
+
] }),
|
|
483
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
484
|
+
/* @__PURE__ */ jsx("div", { style: { opacity: 0.85, marginBottom: 4 }, children: "RPC" }),
|
|
485
|
+
rpcEvents.length === 0 ? /* @__PURE__ */ jsx("div", { style: { opacity: 0.7 }, children: "No calls yet" }) : /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: "column", gap: 6 }, children: rpcEvents.map((ev) => /* @__PURE__ */ jsxs("div", { style: { padding: 8, border: "1px solid rgba(255,255,255,0.08)", borderRadius: 8 }, children: [
|
|
486
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
|
|
487
|
+
/* @__PURE__ */ jsx("div", { children: ev.method }),
|
|
488
|
+
/* @__PURE__ */ jsxs("div", { style: { opacity: 0.8 }, children: [
|
|
489
|
+
ev.status,
|
|
490
|
+
typeof ev.durationMs === "number" ? ` (${ev.durationMs}ms)` : ""
|
|
491
|
+
] })
|
|
492
|
+
] }),
|
|
493
|
+
ev.status === "error" ? /* @__PURE__ */ jsx("pre", { style: { margin: "6px 0 0", opacity: 0.8, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: JSON.stringify(serializeError(ev.error) ?? {}, null, 2) }) : null
|
|
494
|
+
] }, `${ev.id}:${ev.status}`)) })
|
|
495
|
+
] })
|
|
496
|
+
]
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
function serializeError(err) {
|
|
501
|
+
if (err instanceof Error) {
|
|
502
|
+
const anyErr = err;
|
|
503
|
+
const out = {
|
|
504
|
+
name: err.name,
|
|
505
|
+
message: err.message
|
|
506
|
+
};
|
|
507
|
+
if (err.stack) out.stack = err.stack;
|
|
508
|
+
if (typeof anyErr.code === "string") out.code = anyErr.code;
|
|
509
|
+
if (anyErr.details !== void 0) out.details = anyErr.details;
|
|
510
|
+
if (anyErr.cause !== void 0) out.cause = anyErr.cause;
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
return err;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export { AppletDevtoolsOverlay, AppletProvider, AppletRPCException, ConfigProvider, createAppletRPCClient, createAppletRouter, defineReactAppletElement, shouldEnableAppletDevtools, useAppletContext, useAppletContext2 as useAppletContextDirect, useAppletRuntime, useConfig, useConfigContext, usePermissions, useRoute, useSession, useStreaming, useTranslation, useUser };
|
|
177
517
|
//# sourceMappingURL=index.mjs.map
|
|
178
518
|
//# sourceMappingURL=index.mjs.map
|