@open-core/framework 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/client/decorators/onView.d.ts +14 -1
- package/dist/runtime/client/decorators/onView.js +12 -2
- package/dist/runtime/client/system/processors/view.processor.d.ts +1 -0
- package/dist/runtime/client/system/processors/view.processor.js +3 -1
- package/dist/runtime/client/webview-bridge.d.ts +1 -0
- package/dist/runtime/client/webview-bridge.js +3 -0
- package/package.json +1 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export interface OnViewOptions {
|
|
2
|
+
viewId?: string;
|
|
3
|
+
}
|
|
1
4
|
/**
|
|
2
5
|
* Registers a method as a WebView callback handler.
|
|
3
6
|
*
|
|
@@ -5,7 +8,12 @@
|
|
|
5
8
|
* This decorator only stores metadata. During bootstrap, the framework binds the decorated method
|
|
6
9
|
* to the active WebView runtime callback.
|
|
7
10
|
*
|
|
11
|
+
* If `options.viewId` is provided, the handler will only receive messages from the
|
|
12
|
+
* specified WebView viewId. Without it, the handler receives events from all views.
|
|
13
|
+
*
|
|
8
14
|
* @param eventName - Callback name.
|
|
15
|
+
* @param options - Optional configuration. Pass `{ viewId: 'my-view' }` to
|
|
16
|
+
* filter incoming messages by viewId.
|
|
9
17
|
*
|
|
10
18
|
* @example
|
|
11
19
|
* ```ts
|
|
@@ -15,7 +23,12 @@
|
|
|
15
23
|
* saveSettings(payload: unknown) {
|
|
16
24
|
* // ...
|
|
17
25
|
* }
|
|
26
|
+
*
|
|
27
|
+
* @Client.onView('system-ui:ready', { viewId: 'system-ui' })
|
|
28
|
+
* onSystemUiReady() {
|
|
29
|
+
* // Only fires for the 'system-ui' WebView
|
|
30
|
+
* }
|
|
18
31
|
* }
|
|
19
32
|
* ```
|
|
20
33
|
*/
|
|
21
|
-
export declare function OnView(eventName: string): (target: any, propertyKey: string) => void;
|
|
34
|
+
export declare function OnView(eventName: string, options?: OnViewOptions): (target: any, propertyKey: string) => void;
|
|
@@ -6,7 +6,12 @@ import { METADATA_KEYS } from '../system/metadata-client.keys';
|
|
|
6
6
|
* This decorator only stores metadata. During bootstrap, the framework binds the decorated method
|
|
7
7
|
* to the active WebView runtime callback.
|
|
8
8
|
*
|
|
9
|
+
* If `options.viewId` is provided, the handler will only receive messages from the
|
|
10
|
+
* specified WebView viewId. Without it, the handler receives events from all views.
|
|
11
|
+
*
|
|
9
12
|
* @param eventName - Callback name.
|
|
13
|
+
* @param options - Optional configuration. Pass `{ viewId: 'my-view' }` to
|
|
14
|
+
* filter incoming messages by viewId.
|
|
10
15
|
*
|
|
11
16
|
* @example
|
|
12
17
|
* ```ts
|
|
@@ -16,11 +21,16 @@ import { METADATA_KEYS } from '../system/metadata-client.keys';
|
|
|
16
21
|
* saveSettings(payload: unknown) {
|
|
17
22
|
* // ...
|
|
18
23
|
* }
|
|
24
|
+
*
|
|
25
|
+
* @Client.onView('system-ui:ready', { viewId: 'system-ui' })
|
|
26
|
+
* onSystemUiReady() {
|
|
27
|
+
* // Only fires for the 'system-ui' WebView
|
|
28
|
+
* }
|
|
19
29
|
* }
|
|
20
30
|
* ```
|
|
21
31
|
*/
|
|
22
|
-
export function OnView(eventName) {
|
|
32
|
+
export function OnView(eventName, options) {
|
|
23
33
|
return (target, propertyKey) => {
|
|
24
|
-
Reflect.defineMetadata(METADATA_KEYS.VIEW, { eventName }, target, propertyKey);
|
|
34
|
+
Reflect.defineMetadata(METADATA_KEYS.VIEW, { eventName, viewId: options?.viewId }, target, propertyKey);
|
|
25
35
|
};
|
|
26
36
|
}
|
|
@@ -26,6 +26,8 @@ let ViewProcessor = class ViewProcessor {
|
|
|
26
26
|
this.webviews.onMessage(async (message) => {
|
|
27
27
|
if (message.event !== metadata.eventName)
|
|
28
28
|
return;
|
|
29
|
+
if (metadata.viewId && message.viewId !== metadata.viewId)
|
|
30
|
+
return;
|
|
29
31
|
try {
|
|
30
32
|
await handler(message.payload);
|
|
31
33
|
}
|
|
@@ -36,7 +38,7 @@ let ViewProcessor = class ViewProcessor {
|
|
|
36
38
|
}, error);
|
|
37
39
|
}
|
|
38
40
|
});
|
|
39
|
-
loggers.webView.debug(`Registered WebView callback: ${metadata.eventName} -> ${handlerName}`);
|
|
41
|
+
loggers.webView.debug(`Registered WebView callback: ${metadata.eventName}${metadata.viewId ? ` [viewId=${metadata.viewId}]` : ''} -> ${handlerName}`);
|
|
40
42
|
}
|
|
41
43
|
};
|
|
42
44
|
ViewProcessor = __decorate([
|
|
@@ -32,3 +32,4 @@ export declare class NuiBridge<TSend extends Record<string, any> = Record<string
|
|
|
32
32
|
}
|
|
33
33
|
export declare const WebView: WebViewBridge<Record<string, any>, Record<string, any>>;
|
|
34
34
|
export declare const NUI: WebViewBridge<Record<string, any>, Record<string, any>>;
|
|
35
|
+
export declare function createWebView<TSend extends Record<string, any> = Record<string, any>, TReceive extends Record<string, any> = Record<string, any>>(viewId: string): WebViewBridge<TSend, TReceive>;
|