forgeframe 0.0.10 → 0.0.13
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 +105 -43
- package/dist/communication/index.d.ts +5 -4
- package/dist/communication/messenger.d.ts +1 -0
- package/dist/core/consumer/callbacks.d.ts +19 -0
- package/dist/core/consumer/child-refs.d.ts +15 -0
- package/dist/core/consumer/siblings.d.ts +23 -0
- package/dist/core/consumer/transport.d.ts +15 -8
- package/dist/core/consumer.d.ts +0 -73
- package/dist/core/host/auto-init.d.ts +19 -0
- package/dist/core/host/bootstrap.d.ts +15 -0
- package/dist/core/host/component.d.ts +32 -0
- package/dist/core/host/props-runtime.d.ts +31 -0
- package/dist/core/host/security.d.ts +31 -0
- package/dist/core/host/transport.d.ts +44 -0
- package/dist/core/host/types.d.ts +63 -0
- package/dist/core/host.d.ts +6 -271
- package/dist/drivers/index.d.ts +7 -9
- package/dist/drivers/react.d.ts +1 -2
- package/dist/forgeframe.d.ts +202 -0
- package/dist/forgeframe.js +1601 -1730
- package/dist/forgeframe.umd.cjs +2 -2
- package/dist/index.d.ts +2 -202
- package/dist/props/clone.d.ts +22 -0
- package/dist/props/index.d.ts +2 -1
- package/dist/props/serialize.d.ts +1 -14
- package/dist/render/index.d.ts +5 -29
- package/dist/utils/browser.d.ts +6 -0
- package/dist/utils/domain-pattern.d.ts +35 -0
- package/dist/window/helpers.d.ts +1 -1
- package/dist/window/index.d.ts +6 -6
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Host-side consumer window and origin verification helpers.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This internal module resolves the consumer window, derives browser-verifiable
|
|
7
|
+
* origins, and applies allowlist checks so host bootstrap and reconfiguration
|
|
8
|
+
* can share one security policy.
|
|
9
|
+
*/
|
|
10
|
+
import type { DomainMatcher } from '../../types';
|
|
11
|
+
import type { HostSecurityContext } from './types';
|
|
12
|
+
export declare const CONSUMER_WINDOW_RESOLUTION_ERROR = "Could not resolve consumer window";
|
|
13
|
+
export declare const CONSUMER_ORIGIN_VERIFICATION_ERROR = "Could not verify consumer origin";
|
|
14
|
+
export declare function resolveConsumerWindow(hostWindow?: Window): Window;
|
|
15
|
+
export declare function getReferrerOrigin(hostDocument?: Document, hostWindow?: Window): string | null;
|
|
16
|
+
export declare function getAccessibleConsumerOrigin(consumerWindow: Window): string | null;
|
|
17
|
+
export declare function getVerifiedConsumerOrigin(consumerWindow: Window, hostDocument?: Document, hostWindow?: Window): string | null;
|
|
18
|
+
export declare function resolveConsumerSecurityContext(options: {
|
|
19
|
+
consumerWindow: Window;
|
|
20
|
+
claimedConsumerDomain: string;
|
|
21
|
+
allowedConsumerDomains?: DomainMatcher;
|
|
22
|
+
tag: string;
|
|
23
|
+
}): HostSecurityContext;
|
|
24
|
+
export declare function reassertAllowedConsumerDomain(options: {
|
|
25
|
+
consumerWindow: Window;
|
|
26
|
+
consumerDomain: string;
|
|
27
|
+
consumerDomainVerified: boolean;
|
|
28
|
+
allowedConsumerDomains: DomainMatcher;
|
|
29
|
+
tag: string;
|
|
30
|
+
onConsumerDomainChange?: (previousDomain: string, nextDomain: string) => void;
|
|
31
|
+
}): HostSecurityContext;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Host runtime messaging and handshake helpers.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This internal module owns the host messenger/function bridge pair, deferred
|
|
7
|
+
* INIT scheduling, outbound control messages, and inbound PROPS message
|
|
8
|
+
* registration for the host runtime.
|
|
9
|
+
*/
|
|
10
|
+
import { FunctionBridge } from '../../communication/bridge';
|
|
11
|
+
import { Messenger } from '../../communication/messenger';
|
|
12
|
+
import type { GetPeerInstancesOptions, SiblingInfo } from '../../types';
|
|
13
|
+
import type { HostTransportOptions, HostTransportPropsHandler } from './types';
|
|
14
|
+
export declare class HostTransport {
|
|
15
|
+
private options;
|
|
16
|
+
messenger: Messenger;
|
|
17
|
+
bridge: FunctionBridge;
|
|
18
|
+
private destroyed;
|
|
19
|
+
private initSent;
|
|
20
|
+
private initError;
|
|
21
|
+
private deferredInitFlushScheduled;
|
|
22
|
+
constructor(options: HostTransportOptions);
|
|
23
|
+
registerPropsHandler(handler: HostTransportPropsHandler): void;
|
|
24
|
+
handleHostPropsAccess(): void;
|
|
25
|
+
flushInit(): void;
|
|
26
|
+
getInitError(): Error | null;
|
|
27
|
+
updateTrustedConsumerDomain(previousDomain: string, nextDomain: string): void;
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
focus(): Promise<void>;
|
|
30
|
+
resize(dimensions: {
|
|
31
|
+
width?: string | number;
|
|
32
|
+
height?: string | number;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
show(): Promise<void>;
|
|
35
|
+
hide(): Promise<void>;
|
|
36
|
+
onError(error: Error): Promise<void>;
|
|
37
|
+
exportData<T>(exports: T): Promise<void>;
|
|
38
|
+
consumerExport<T>(data: T): Promise<void>;
|
|
39
|
+
getPeerInstances(options?: GetPeerInstancesOptions): Promise<SiblingInfo[]>;
|
|
40
|
+
destroy(): void;
|
|
41
|
+
private scheduleDeferredInitFlush;
|
|
42
|
+
private sendInit;
|
|
43
|
+
private sendMessage;
|
|
44
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Shared internal host runtime types.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This internal module defines the collaboration contracts used by the host
|
|
7
|
+
* bootstrap, transport, security, and props runtime modules so they can share
|
|
8
|
+
* explicit state without reaching through each other's implementations.
|
|
9
|
+
*/
|
|
10
|
+
import type { FunctionBridge } from '../../communication/bridge';
|
|
11
|
+
import type { MessageHandler, Messenger } from '../../communication/messenger';
|
|
12
|
+
import type { EventEmitter } from '../../events/emitter';
|
|
13
|
+
import type { Dimensions, DomainMatcher, GetPeerInstancesOptions, HostProps, PropsDefinition, SerializedProps, SiblingInfo } from '../../types';
|
|
14
|
+
export type VerifiedMessageSource = Parameters<MessageHandler>[1];
|
|
15
|
+
export interface HostSecurityContext {
|
|
16
|
+
consumerDomain: string;
|
|
17
|
+
consumerDomainVerified: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface HostPropsRuntimeControls {
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
focus(): Promise<void>;
|
|
22
|
+
resize(dimensions: Dimensions): Promise<void>;
|
|
23
|
+
show(): Promise<void>;
|
|
24
|
+
hide(): Promise<void>;
|
|
25
|
+
onError(error: Error): Promise<void>;
|
|
26
|
+
exportData<T>(exports: T): Promise<void>;
|
|
27
|
+
consumerExport<T>(data: T): Promise<void>;
|
|
28
|
+
getPeerInstances(options?: GetPeerInstancesOptions): Promise<SiblingInfo[]>;
|
|
29
|
+
}
|
|
30
|
+
export interface HostPropsRuntimeOptions {
|
|
31
|
+
uid: string;
|
|
32
|
+
tag: string;
|
|
33
|
+
event: EventEmitter;
|
|
34
|
+
controls: HostPropsRuntimeControls;
|
|
35
|
+
getConsumerWindow(): Window;
|
|
36
|
+
getConsumerDomain(): string;
|
|
37
|
+
isConsumerDomainVerified(): boolean;
|
|
38
|
+
getMessenger(): Messenger;
|
|
39
|
+
getBridge(): FunctionBridge;
|
|
40
|
+
onFirstHostPropsAccess(): void;
|
|
41
|
+
}
|
|
42
|
+
export interface HostTransportOptions {
|
|
43
|
+
uid: string;
|
|
44
|
+
tag: string;
|
|
45
|
+
event: EventEmitter;
|
|
46
|
+
consumerWindow: Window;
|
|
47
|
+
consumerDomain: string;
|
|
48
|
+
getConsumerDomain(): string;
|
|
49
|
+
deferInit: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface HostTransportPropsHandler {
|
|
52
|
+
isConsumerSource(source: VerifiedMessageSource): boolean;
|
|
53
|
+
applySerializedProps(serializedProps: SerializedProps): {
|
|
54
|
+
success: true;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface HostHostConfiguration<P extends Record<string, unknown>> {
|
|
58
|
+
propDefinitions?: PropsDefinition<P>;
|
|
59
|
+
allowedConsumerDomains?: DomainMatcher;
|
|
60
|
+
}
|
|
61
|
+
export interface WindowWithHostProps<P extends Record<string, unknown>> extends Window {
|
|
62
|
+
hostProps?: HostProps<P>;
|
|
63
|
+
}
|
package/dist/core/host.d.ts
CHANGED
|
@@ -3,272 +3,13 @@
|
|
|
3
3
|
* Host component implementation module.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
|
-
* This module
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* This module exposes the public host-side runtime entrypoints while the
|
|
7
|
+
* concrete bootstrap, security, props, and transport concerns live in
|
|
8
|
+
* focused internal modules under `src/core/host/`.
|
|
9
9
|
*/
|
|
10
|
-
import type { HostProps
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Host-side component implementation.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* This class runs inside the iframe or popup window and manages communication
|
|
17
|
-
* with the consumer component. It provides the hostProps object with props and
|
|
18
|
-
* control methods.
|
|
19
|
-
*
|
|
20
|
-
* @typeParam P - The props type passed from the consumer
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* // In host window
|
|
25
|
-
* const { email, onLogin, close } = window.hostProps;
|
|
26
|
-
* console.log('Email:', email);
|
|
27
|
-
* onLogin({ id: 1, name: 'John' });
|
|
28
|
-
* close();
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export declare class HostComponent<P extends Record<string, unknown>> {
|
|
34
|
-
private propDefinitions;
|
|
35
|
-
private allowedConsumerDomains?;
|
|
36
|
-
private deferInit;
|
|
37
|
-
/** The hostProps object containing props and control methods passed from the consumer. */
|
|
38
|
-
hostProps: HostProps<P>;
|
|
39
|
-
/** Event emitter for lifecycle events. */
|
|
40
|
-
event: EventEmitter;
|
|
41
|
-
/** @internal */
|
|
42
|
-
private uid;
|
|
43
|
-
/** @internal */
|
|
44
|
-
private tag;
|
|
45
|
-
/** @internal */
|
|
46
|
-
private consumerWindow;
|
|
47
|
-
/** @internal */
|
|
48
|
-
private consumerDomain;
|
|
49
|
-
/** @internal */
|
|
50
|
-
private consumerDomainVerified;
|
|
51
|
-
/** @internal */
|
|
52
|
-
private messenger;
|
|
53
|
-
/** @internal */
|
|
54
|
-
private bridge;
|
|
55
|
-
/** @internal */
|
|
56
|
-
private propsHandlers;
|
|
57
|
-
/** @internal */
|
|
58
|
-
private consumerProps;
|
|
59
|
-
/** @internal */
|
|
60
|
-
private initError;
|
|
61
|
-
/** @internal */
|
|
62
|
-
private destroyed;
|
|
63
|
-
/** @internal */
|
|
64
|
-
private initSent;
|
|
65
|
-
/** @internal */
|
|
66
|
-
private deferredInitFlushScheduled;
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new HostComponent instance.
|
|
69
|
-
*
|
|
70
|
-
* @param payload - The payload parsed from window.name
|
|
71
|
-
* @param propDefinitions - Optional prop definitions for deserialization
|
|
72
|
-
* @param allowedConsumerDomains - Optional allowlist of consumer domains
|
|
73
|
-
* @param deferInit - Whether to defer INIT until a later explicit flush
|
|
74
|
-
*/
|
|
75
|
-
constructor(payload: WindowNamePayload<P>, propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher | undefined, deferInit?: boolean);
|
|
76
|
-
/**
|
|
77
|
-
* Ensures the INIT handshake is sent at most once.
|
|
78
|
-
* @internal
|
|
79
|
-
*/
|
|
80
|
-
flushInit(): void;
|
|
81
|
-
/**
|
|
82
|
-
* Schedules deferred INIT flush on the next microtask.
|
|
83
|
-
* This preserves legacy hostProps-only usage while giving same-tick
|
|
84
|
-
* host configuration a chance to run allowlist checks first.
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
private scheduleDeferredInitFlush;
|
|
88
|
-
/**
|
|
89
|
-
* Exposes hostProps on window and lazily flushes deferred init on first access.
|
|
90
|
-
* @internal
|
|
91
|
-
*/
|
|
92
|
-
private exposeHostProps;
|
|
93
|
-
/**
|
|
94
|
-
* Validates that the consumer domain is allowed.
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
private validateConsumerDomain;
|
|
98
|
-
/**
|
|
99
|
-
* Reads a browser-verifiable consumer origin when available.
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
private getVerifiedConsumerOrigin;
|
|
103
|
-
/**
|
|
104
|
-
* Updates the tracked consumer origin and keeps trusted messaging origins in sync.
|
|
105
|
-
* @internal
|
|
106
|
-
*/
|
|
107
|
-
private setConsumerDomain;
|
|
108
|
-
/**
|
|
109
|
-
* Applies host configuration that may arrive after deferred pre-initialization.
|
|
110
|
-
* @internal
|
|
111
|
-
*/
|
|
112
|
-
applyHostConfiguration(propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher): void;
|
|
113
|
-
/**
|
|
114
|
-
* Resolves the consumer origin from browser-provided context and falls back to the
|
|
115
|
-
* claimed bootstrap origin only when no explicit allowlist is configured.
|
|
116
|
-
* @internal
|
|
117
|
-
*/
|
|
118
|
-
private resolveConsumerDomain;
|
|
119
|
-
/**
|
|
120
|
-
* Rechecks allowlist constraints against a browser-verified consumer origin.
|
|
121
|
-
* @internal
|
|
122
|
-
*/
|
|
123
|
-
assertAllowedConsumerDomain(allowedConsumerDomains: DomainMatcher): void;
|
|
124
|
-
/**
|
|
125
|
-
* Reads the consumer origin from the browser-provided referrer when available.
|
|
126
|
-
* @internal
|
|
127
|
-
*/
|
|
128
|
-
private getReferrerOrigin;
|
|
129
|
-
/**
|
|
130
|
-
* Reads the consumer origin directly when same-origin access is available.
|
|
131
|
-
* @internal
|
|
132
|
-
*/
|
|
133
|
-
private getAccessibleConsumerOrigin;
|
|
134
|
-
/**
|
|
135
|
-
* Returns the hostProps object.
|
|
136
|
-
*
|
|
137
|
-
* @returns The hostProps object with props and control methods
|
|
138
|
-
*/
|
|
139
|
-
getProps(): HostProps<P>;
|
|
140
|
-
/**
|
|
141
|
-
* Resolves the consumer window reference (iframe parent or popup opener).
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
private resolveConsumerWindow;
|
|
145
|
-
/**
|
|
146
|
-
* Builds the hostProps object with deserialized props and control methods.
|
|
147
|
-
* @internal
|
|
148
|
-
*/
|
|
149
|
-
private buildHostProps;
|
|
150
|
-
/**
|
|
151
|
-
* Relaxes required sameDomain props during bootstrap for verified same-origin hosts.
|
|
152
|
-
* Those props are synchronized after INIT through the live messaging channel.
|
|
153
|
-
* @internal
|
|
154
|
-
*/
|
|
155
|
-
private getBootstrapValidationDefinitions;
|
|
156
|
-
/**
|
|
157
|
-
* Sends initialization message to the consumer.
|
|
158
|
-
* @internal
|
|
159
|
-
*/
|
|
160
|
-
private sendInit;
|
|
161
|
-
/**
|
|
162
|
-
* Returns the initialization error if one occurred.
|
|
163
|
-
*
|
|
164
|
-
* @returns The initialization error or null if successful
|
|
165
|
-
*/
|
|
166
|
-
getInitError(): Error | null;
|
|
167
|
-
/**
|
|
168
|
-
* Requests the consumer to close this component.
|
|
169
|
-
* @internal
|
|
170
|
-
*/
|
|
171
|
-
private close;
|
|
172
|
-
/**
|
|
173
|
-
* Focuses this window and notifies the consumer.
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
private focus;
|
|
177
|
-
/**
|
|
178
|
-
* Requests the consumer to resize this component.
|
|
179
|
-
* @internal
|
|
180
|
-
*/
|
|
181
|
-
private resize;
|
|
182
|
-
/**
|
|
183
|
-
* Requests the consumer to show this component.
|
|
184
|
-
* @internal
|
|
185
|
-
*/
|
|
186
|
-
private show;
|
|
187
|
-
/**
|
|
188
|
-
* Requests the consumer to hide this component.
|
|
189
|
-
* @internal
|
|
190
|
-
*/
|
|
191
|
-
private hide;
|
|
192
|
-
/**
|
|
193
|
-
* Subscribes to prop updates from the consumer.
|
|
194
|
-
* @internal
|
|
195
|
-
*/
|
|
196
|
-
private onProps;
|
|
197
|
-
/**
|
|
198
|
-
* Reports an error to the consumer.
|
|
199
|
-
* @internal
|
|
200
|
-
*/
|
|
201
|
-
private onError;
|
|
202
|
-
/**
|
|
203
|
-
* Exports data or methods to the consumer.
|
|
204
|
-
* @internal
|
|
205
|
-
*/
|
|
206
|
-
private exportData;
|
|
207
|
-
/**
|
|
208
|
-
* Exports data to the consumer for bidirectional communication.
|
|
209
|
-
* @internal
|
|
210
|
-
*/
|
|
211
|
-
private consumerExport;
|
|
212
|
-
/**
|
|
213
|
-
* Gets information about peer component instances.
|
|
214
|
-
* @internal
|
|
215
|
-
*/
|
|
216
|
-
private getPeerInstances;
|
|
217
|
-
/**
|
|
218
|
-
* Builds nested component factories from refs passed by the consumer.
|
|
219
|
-
* @internal
|
|
220
|
-
*/
|
|
221
|
-
private buildNestedComponents;
|
|
222
|
-
/**
|
|
223
|
-
* Sets up message handlers for consumer communication.
|
|
224
|
-
* @internal
|
|
225
|
-
*/
|
|
226
|
-
private setupMessageHandlers;
|
|
227
|
-
/**
|
|
228
|
-
* Removes stale prop keys that are no longer present in the latest consumer payload.
|
|
229
|
-
* @internal
|
|
230
|
-
*/
|
|
231
|
-
private removeStaleHostProps;
|
|
232
|
-
/**
|
|
233
|
-
* Destroys the host component and cleans up resources.
|
|
234
|
-
*/
|
|
235
|
-
destroy(): void;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Initializes the host component if running in a ForgeFrame window.
|
|
239
|
-
*
|
|
240
|
-
* @remarks
|
|
241
|
-
* This function detects if the current window was created by ForgeFrame
|
|
242
|
-
* and sets up the host component with hostProps. Returns null if not in
|
|
243
|
-
* a ForgeFrame host context.
|
|
244
|
-
*
|
|
245
|
-
* @typeParam P - The props type passed from the consumer
|
|
246
|
-
* @param propDefinitions - Optional prop definitions for deserialization
|
|
247
|
-
* @returns The host component instance or null if not in a host window
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* const host = initHost();
|
|
252
|
-
* if (host) {
|
|
253
|
-
* console.log('Running in ForgeFrame host context');
|
|
254
|
-
* console.log('Props:', host.hostProps);
|
|
255
|
-
* }
|
|
256
|
-
* ```
|
|
257
|
-
*
|
|
258
|
-
* @public
|
|
259
|
-
*/
|
|
260
|
-
export declare function initHost<P extends Record<string, unknown>>(propDefinitions?: PropsDefinition<P>, allowedConsumerDomains?: DomainMatcher, options?: {
|
|
261
|
-
deferInit?: boolean;
|
|
262
|
-
}): HostComponent<P> | null;
|
|
263
|
-
/**
|
|
264
|
-
* Gets the current host component instance.
|
|
265
|
-
*
|
|
266
|
-
* @typeParam P - The props type passed from the consumer
|
|
267
|
-
* @returns The host component instance or null if not initialized
|
|
268
|
-
*
|
|
269
|
-
* @public
|
|
270
|
-
*/
|
|
271
|
-
export declare function getHost<P extends Record<string, unknown>>(): HostComponent<P> | null;
|
|
10
|
+
import type { HostProps } from '../types';
|
|
11
|
+
export { HostComponent } from './host/component';
|
|
12
|
+
export { clearHostInstance, getHost, initHost, } from './host/bootstrap';
|
|
272
13
|
/**
|
|
273
14
|
* Checks if the current window is a ForgeFrame host context.
|
|
274
15
|
*
|
|
@@ -330,9 +71,3 @@ export declare function isEmbedded(): boolean;
|
|
|
330
71
|
* @public
|
|
331
72
|
*/
|
|
332
73
|
export declare function getHostProps<P extends Record<string, unknown>>(): HostProps<P> | undefined;
|
|
333
|
-
/**
|
|
334
|
-
* Clears and destroys the global host instance.
|
|
335
|
-
* Primarily intended for testing.
|
|
336
|
-
* @internal
|
|
337
|
-
*/
|
|
338
|
-
export declare function clearHostInstance(): void;
|
package/dist/drivers/index.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Internal source barrel for framework integrations.
|
|
3
4
|
*
|
|
4
5
|
* @remarks
|
|
5
|
-
* This
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* within the target framework's component model.
|
|
6
|
+
* This file keeps the driver modules organized inside the source tree.
|
|
7
|
+
* The published package does not expose a `forgeframe/drivers` subpath;
|
|
8
|
+
* consumers should import the public React driver APIs from `forgeframe`.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
|
-
* import { createReactComponent, withReactComponent } from 'forgeframe
|
|
13
|
-
* import type { ReactDriverOptions, ReactComponentProps } from 'forgeframe
|
|
12
|
+
* import { createReactComponent, withReactComponent } from 'forgeframe';
|
|
13
|
+
* import type { ReactDriverOptions, ReactComponentProps } from 'forgeframe';
|
|
14
14
|
* ```
|
|
15
|
-
*
|
|
16
|
-
* @packageDocumentation
|
|
17
15
|
*/
|
|
18
16
|
export { createReactComponent, withReactComponent, type ReactDriverOptions, type ReactComponentProps, type ReactComponentType, } from './react';
|
package/dist/drivers/react.d.ts
CHANGED
|
@@ -204,8 +204,7 @@ export declare function createReactComponent<P extends Record<string, unknown>,
|
|
|
204
204
|
* @example
|
|
205
205
|
* ```tsx
|
|
206
206
|
* import React from 'react';
|
|
207
|
-
* import ForgeFrame from 'forgeframe';
|
|
208
|
-
* import { withReactComponent } from 'forgeframe/drivers/react';
|
|
207
|
+
* import ForgeFrame, { withReactComponent } from 'forgeframe';
|
|
209
208
|
*
|
|
210
209
|
* // Create a reusable component factory
|
|
211
210
|
* const createComponent = withReactComponent(React);
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { create, destroy, destroyByTag, destroyAll, isHost, isEmbedded, getHostProps, initHost } from './core';
|
|
2
|
+
import { PopupOpenError } from './render/popup';
|
|
3
|
+
import { isStandardSchema } from './props/schema';
|
|
4
|
+
/**
|
|
5
|
+
* Main ForgeFrame API object.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Provides a zoid-compatible interface for creating and managing
|
|
9
|
+
* cross-domain components. All methods and constants are accessible
|
|
10
|
+
* through this object.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import ForgeFrame from 'forgeframe';
|
|
15
|
+
*
|
|
16
|
+
* const Component = ForgeFrame.create({
|
|
17
|
+
* tag: 'my-component',
|
|
18
|
+
* url: '/component.html',
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare const ForgeFrame: {
|
|
25
|
+
/**
|
|
26
|
+
* Create a new component definition.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This is the main entry point for defining components. Returns a
|
|
30
|
+
* component factory function that can be called to create instances.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import ForgeFrame, { prop } from 'forgeframe';
|
|
35
|
+
*
|
|
36
|
+
* const MyComponent = ForgeFrame.create({
|
|
37
|
+
* tag: 'my-component',
|
|
38
|
+
* url: 'https://example.com/component',
|
|
39
|
+
* props: {
|
|
40
|
+
* email: prop.string().email(),
|
|
41
|
+
* onLogin: prop.function<(user: { id: string }) => void>(),
|
|
42
|
+
* },
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* const instance = MyComponent({ email: 'user@example.com', onLogin: (user) => {} });
|
|
46
|
+
* await instance.render('#container');
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
readonly create: typeof create;
|
|
50
|
+
/**
|
|
51
|
+
* Destroy a single component instance.
|
|
52
|
+
*
|
|
53
|
+
* @param instance - The component instance to destroy
|
|
54
|
+
*/
|
|
55
|
+
readonly destroy: typeof destroy;
|
|
56
|
+
/**
|
|
57
|
+
* Destroy all instances of a specific component by tag.
|
|
58
|
+
*
|
|
59
|
+
* @param tag - The component tag name
|
|
60
|
+
*/
|
|
61
|
+
readonly destroyByTag: typeof destroyByTag;
|
|
62
|
+
/**
|
|
63
|
+
* Destroy all ForgeFrame component instances.
|
|
64
|
+
*/
|
|
65
|
+
readonly destroyAll: typeof destroyAll;
|
|
66
|
+
/**
|
|
67
|
+
* Check if the current window is a host component context.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* A "host" is the embedded iframe or popup window that receives props
|
|
71
|
+
* from the consumer (the embedding app).
|
|
72
|
+
*
|
|
73
|
+
* @returns True if running inside a ForgeFrame iframe/popup
|
|
74
|
+
*/
|
|
75
|
+
readonly isHost: typeof isHost;
|
|
76
|
+
/**
|
|
77
|
+
* Check if the current window is embedded by ForgeFrame.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This is an alias for {@link isHost} that uses more intuitive terminology.
|
|
81
|
+
*
|
|
82
|
+
* @returns True if running inside a ForgeFrame iframe/popup
|
|
83
|
+
*/
|
|
84
|
+
readonly isEmbedded: typeof isEmbedded;
|
|
85
|
+
/**
|
|
86
|
+
* Get hostProps from the current host window.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* Returns the props passed from the consumer plus built-in control methods.
|
|
90
|
+
*
|
|
91
|
+
* @returns The hostProps object if in host context, undefined otherwise
|
|
92
|
+
*/
|
|
93
|
+
readonly getHostProps: typeof getHostProps;
|
|
94
|
+
/**
|
|
95
|
+
* Flush host initialization in embedded contexts.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Only required in host pages that access `window.hostProps` directly
|
|
99
|
+
* without defining a component via `ForgeFrame.create(...)`.
|
|
100
|
+
* When `create()` is used on the host side, init is flushed automatically.
|
|
101
|
+
*
|
|
102
|
+
* @returns The host component instance if running embedded, otherwise null
|
|
103
|
+
*/
|
|
104
|
+
readonly initHost: typeof initHost;
|
|
105
|
+
/**
|
|
106
|
+
* Serialization strategy constants.
|
|
107
|
+
* @see {@link PROP_SERIALIZATION}
|
|
108
|
+
*/
|
|
109
|
+
readonly PROP_SERIALIZATION: {
|
|
110
|
+
readonly JSON: "json";
|
|
111
|
+
readonly BASE64: "base64";
|
|
112
|
+
readonly DOTIFY: "dotify";
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Rendering context constants (IFRAME, POPUP).
|
|
116
|
+
* @see {@link CONTEXT}
|
|
117
|
+
*/
|
|
118
|
+
readonly CONTEXT: {
|
|
119
|
+
readonly IFRAME: "iframe";
|
|
120
|
+
readonly POPUP: "popup";
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Lifecycle event name constants.
|
|
124
|
+
* @see {@link EVENT}
|
|
125
|
+
*/
|
|
126
|
+
readonly EVENT: {
|
|
127
|
+
readonly RENDER: "render";
|
|
128
|
+
readonly RENDERED: "rendered";
|
|
129
|
+
readonly PRERENDER: "prerender";
|
|
130
|
+
readonly PRERENDERED: "prerendered";
|
|
131
|
+
readonly DISPLAY: "display";
|
|
132
|
+
readonly ERROR: "error";
|
|
133
|
+
readonly CLOSE: "close";
|
|
134
|
+
readonly DESTROY: "destroy";
|
|
135
|
+
readonly PROPS: "props";
|
|
136
|
+
readonly RESIZE: "resize";
|
|
137
|
+
readonly FOCUS: "focus";
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Error thrown when popup window fails to open.
|
|
141
|
+
*/
|
|
142
|
+
readonly PopupOpenError: typeof PopupOpenError;
|
|
143
|
+
/**
|
|
144
|
+
* Current library version.
|
|
145
|
+
*/
|
|
146
|
+
readonly VERSION: string;
|
|
147
|
+
/**
|
|
148
|
+
* Check if a value is a Standard Schema (Zod, Valibot, ArkType, etc.)
|
|
149
|
+
*
|
|
150
|
+
* @param value - The value to check
|
|
151
|
+
* @returns True if the value implements StandardSchemaV1
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* import { z } from 'zod';
|
|
156
|
+
*
|
|
157
|
+
* const schema = z.string();
|
|
158
|
+
* if (ForgeFrame.isStandardSchema(schema)) {
|
|
159
|
+
* // schema is StandardSchemaV1
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
readonly isStandardSchema: typeof isStandardSchema;
|
|
164
|
+
/**
|
|
165
|
+
* Prop schema builders for defining component props.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* Provides a fluent, Zod-like API for defining prop schemas with built-in
|
|
169
|
+
* validation. All schemas implement StandardSchemaV1.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import ForgeFrame from 'forgeframe';
|
|
174
|
+
*
|
|
175
|
+
* const Component = ForgeFrame.create({
|
|
176
|
+
* tag: 'my-component',
|
|
177
|
+
* url: '/component',
|
|
178
|
+
* props: {
|
|
179
|
+
* name: ForgeFrame.prop.string(),
|
|
180
|
+
* count: ForgeFrame.prop.number().default(0),
|
|
181
|
+
* onSubmit: ForgeFrame.prop.function().optional(),
|
|
182
|
+
* },
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
readonly prop: {
|
|
187
|
+
readonly string: () => import("./props").StringSchema;
|
|
188
|
+
readonly number: () => import("./props").NumberSchema;
|
|
189
|
+
readonly boolean: () => import("./props").BooleanSchema;
|
|
190
|
+
readonly function: <T extends (...args: any[]) => any = (...args: any[]) => any>() => import("./props").FunctionSchema<T>;
|
|
191
|
+
readonly array: <T = unknown>() => import("./props").ArraySchema<T>;
|
|
192
|
+
readonly object: <T extends object = Record<string, unknown>>() => import("./props").ObjectSchema<T>;
|
|
193
|
+
readonly literal: <T extends string | number | boolean>(value: T) => import("./props").LiteralSchema<T>;
|
|
194
|
+
readonly enum: <T extends string | number>(values: readonly T[]) => import("./props").EnumSchema<T>;
|
|
195
|
+
readonly any: () => import("./props").AnySchema;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Default export of the ForgeFrame API object.
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
export default ForgeFrame;
|