@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.
@@ -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
  }
@@ -6,5 +6,6 @@ export declare class ViewProcessor implements DecoratorProcessor {
6
6
  constructor(webviews: WebViewService);
7
7
  process(target: any, methodName: string, metadata: {
8
8
  eventName: string;
9
+ viewId?: string;
9
10
  }): void;
10
11
  }
@@ -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>;
@@ -101,3 +101,6 @@ function resolveWebViewService() {
101
101
  }
102
102
  export const WebView = new WebViewBridge(resolveWebViewService);
103
103
  export const NUI = WebView;
104
+ export function createWebView(viewId) {
105
+ return new WebViewBridge(resolveWebViewService, viewId);
106
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-core/framework",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Secure, event-driven TypeScript Framework & Runtime engine for CitizenFX (Cfx).",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",