unreal-toolkit 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -16,3 +16,14 @@ npm install unreal-toolkit
16
16
  ```javascript
17
17
  import UnrealToolkit from 'unreal-toolkit';
18
18
  ```
19
+
20
+ * Unreal Toolkit Message Bus Usage
21
+ ```typescript
22
+ // Post window message
23
+ UnrealToolkit.EventBus.PostWindowMessage("myevent", ["Hello World!"]);
24
+
25
+ // Handle window message
26
+ UnrealToolkit.EventBus.OnWindowMessage("myevent", (args:string[]) => {
27
+ console.log("My Event Args: ", args);
28
+ });
29
+ ```
package/dist/index.d.ts CHANGED
@@ -8,13 +8,13 @@ export declare class UnrealToolkit {
8
8
  /** Unreal Toolkit event message bus
9
9
  * @example
10
10
  * ```typescript
11
- * // Handle myevent message
12
- * UnrealToolkit.EventBus.OnMessage("myevent", (data:string) => {
13
- * console.log("My Event Data: " + data);
14
- * });
11
+ * // Post myevent window message
12
+ * UnrealToolkit.EventBus.PostWindowMessage("myevent", ["Hello World!"]);
15
13
  *
16
- * // Post myevent message
17
- * UnrealToolkit.EventBus.PostMessage("myevent", "Hello World!");
14
+ * // Handle myevent window message
15
+ * UnrealToolkit.EventBus.OnWindowMessage("myevent", (args:string[]) => {
16
+ * console.log("My Event Args: ", args);
17
+ * });
18
18
  * ```
19
19
  */
20
20
  static get EventBus(): UnrealMessageBus;
@@ -24,28 +24,27 @@ export declare class UnrealToolkit {
24
24
  * @class UnrealMessageBus - All rights reserved (c) 2024 Mackey Kinard
25
25
  */
26
26
  export declare class UnrealMessageBus {
27
- RequiredOrigin: string;
27
+ static AllowedOrigin: string;
28
+ static TargetOrigin: string;
28
29
  constructor();
29
- /** Handle event bus message
30
- * @param message The message to handle
31
- * @param data The data to handle
30
+ /** Post event bus message
31
+ * @param name The message to post
32
+ * @param args The args to post
32
33
  * @returns void
33
34
  */
34
- OnMessage(message: string, handler: (data: string) => void): void;
35
- /** Post event bus message
36
- * @param message The message to post
37
- * @param data The data to post
38
- * @param target The target to post
39
- * @param transfer The transfer to post
35
+ PostWindowMessage(name: string, args?: string[]): void;
36
+ /** Handle event bus message
37
+ * @param name The name to handle
38
+ * @param args The args to handle
40
39
  * @returns void
41
40
  */
42
- PostMessage(message: string, data?: string, targetOrigin?: string): void;
41
+ OnWindowMessage(name: string, handler: (args: string[]) => void): void;
43
42
  /** Remove event bus message handler
44
43
  * @param message The message to remove
45
44
  * @param handler The handler to remove
46
45
  * @returns void
47
46
  */
48
- RemoveHandler(message: string, handler: (data: string) => void): void;
47
+ RemoveHandler(message: string, handler: (args: string[]) => void): void;
49
48
  /** Clear and reset all event bus message handlers
50
49
  * @returns void
51
50
  */
@@ -60,8 +59,8 @@ export declare class UnrealMessageBus {
60
59
  */
61
60
  private HandleWindowMessage;
62
61
  /** Dispatch internal event bus message
63
- * @param message The message to dispatch
64
- * @param data The data to dispatch
62
+ * @param name The name to dispatch
63
+ * @param args The args to dispatch
65
64
  * @returns void
66
65
  */
67
66
  private OnDispatchMessage;
@@ -8,13 +8,13 @@ export declare class UnrealToolkit {
8
8
  /** Unreal Toolkit event message bus
9
9
  * @example
10
10
  * ```typescript
11
- * // Handle myevent message
12
- * UnrealToolkit.EventBus.OnMessage("myevent", (data:string) => {
13
- * console.log("My Event Data: " + data);
14
- * });
11
+ * // Post myevent window message
12
+ * UnrealToolkit.EventBus.PostWindowMessage("myevent", ["Hello World!"]);
15
13
  *
16
- * // Post myevent message
17
- * UnrealToolkit.EventBus.PostMessage("myevent", "Hello World!");
14
+ * // Handle myevent window message
15
+ * UnrealToolkit.EventBus.OnWindowMessage("myevent", (args:string[]) => {
16
+ * console.log("My Event Args: ", args);
17
+ * });
18
18
  * ```
19
19
  */
20
20
  static get EventBus(): UnrealMessageBus;
@@ -24,28 +24,27 @@ export declare class UnrealToolkit {
24
24
  * @class UnrealMessageBus - All rights reserved (c) 2024 Mackey Kinard
25
25
  */
26
26
  export declare class UnrealMessageBus {
27
- RequiredOrigin: string;
27
+ static AllowedOrigin: string;
28
+ static TargetOrigin: string;
28
29
  constructor();
29
- /** Handle event bus message
30
- * @param message The message to handle
31
- * @param data The data to handle
30
+ /** Post event bus message
31
+ * @param name The message to post
32
+ * @param args The args to post
32
33
  * @returns void
33
34
  */
34
- OnMessage(message: string, handler: (data: string) => void): void;
35
- /** Post event bus message
36
- * @param message The message to post
37
- * @param data The data to post
38
- * @param target The target to post
39
- * @param transfer The transfer to post
35
+ PostWindowMessage(name: string, args?: string[]): void;
36
+ /** Handle event bus message
37
+ * @param name The name to handle
38
+ * @param args The args to handle
40
39
  * @returns void
41
40
  */
42
- PostMessage(message: string, data?: string, targetOrigin?: string): void;
41
+ OnWindowMessage(name: string, handler: (args: string[]) => void): void;
43
42
  /** Remove event bus message handler
44
43
  * @param message The message to remove
45
44
  * @param handler The handler to remove
46
45
  * @returns void
47
46
  */
48
- RemoveHandler(message: string, handler: (data: string) => void): void;
47
+ RemoveHandler(message: string, handler: (args: string[]) => void): void;
49
48
  /** Clear and reset all event bus message handlers
50
49
  * @returns void
51
50
  */
@@ -60,8 +59,8 @@ export declare class UnrealMessageBus {
60
59
  */
61
60
  private HandleWindowMessage;
62
61
  /** Dispatch internal event bus message
63
- * @param message The message to dispatch
64
- * @param data The data to dispatch
62
+ * @param name The name to dispatch
63
+ * @param args The args to dispatch
65
64
  * @returns void
66
65
  */
67
66
  private OnDispatchMessage;
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.UnrealToolkit=n():e.UnrealToolkit=n()}(this,(()=>(()=>{"use strict";var e={d:(n,t)=>{for(var i in t)e.o(t,i)&&!e.o(n,i)&&Object.defineProperty(n,i,{enumerable:!0,get:t[i]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n)},n={};e.d(n,{default:()=>o});var t=function(){function e(){}return Object.defineProperty(e,"EventBus",{get:function(){return null==e._EventBus&&(e._EventBus=new i),e._EventBus},enumerable:!1,configurable:!0}),e._EventBus=null,e}(),i=function(){function e(){this.RequiredOrigin="*",this.ListenerDictionary={},window&&window.top?(this.HandleWindowMessage=this.HandleWindowMessage.bind(this),window.top.addEventListener("message",this.HandleWindowMessage)):console.warn("UnrealMessageBus: No Top Window Available")}return e.prototype.OnMessage=function(e,n){var t;null==this.ListenerDictionary[e]?(t=[],this.ListenerDictionary[e]=t):t=this.ListenerDictionary[e],t.findIndex((function(e){return n==e}))<0&&t.push(n)},e.prototype.PostMessage=function(e,n,t){void 0===t&&(t="*"),window&&window.top?window.top.postMessage({source:"unrealmessagebus",message:e,data:n},t):console.warn("UnrealMessageBus: No Top Window Available")},e.prototype.RemoveHandler=function(e,n){var t=this.ListenerDictionary[e];if(null!=t){var i=t.findIndex((function(e){return n==e}));i>=0&&t.splice(i,1)}},e.prototype.ResetHandlers=function(){this.ListenerDictionary={}},e.prototype.Dispose=function(){this.ResetHandlers(),window&&window.top&&window.top.removeEventListener("message",this.HandleWindowMessage)},e.prototype.HandleWindowMessage=function(e){null!=e&&null!=e.data&&(!0==(null!=this.RequiredOrigin&&""!==this.RequiredOrigin&&"*"!==this.RequiredOrigin)&&e.origin!==this.RequiredOrigin||null!=e.data.message&&null!=e.data.source&&"unrealmessagebus"==e.data.source&&this.OnDispatchMessage(e.data.message,null!=e.data.data?e.data.data:null))},e.prototype.OnDispatchMessage=function(e,n){void 0===n&&(n=null);var t=this.ListenerDictionary[e];null!=t&&t.forEach((function(e){try{e&&e(n)}catch(e){console.warn(e)}}))},e}();console.log("Unreal Toolkit Runtime - Version 0.1.8");const o=t;return n.default})()));
1
+ !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.UnrealToolkit=n():e.UnrealToolkit=n()}(this,(()=>(()=>{"use strict";var e={d:(n,t)=>{for(var i in t)e.o(t,i)&&!e.o(n,i)&&Object.defineProperty(n,i,{enumerable:!0,get:t[i]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n)},n={};e.d(n,{default:()=>o});var t=function(){function e(){}return Object.defineProperty(e,"EventBus",{get:function(){return null==e._EventBus&&(e._EventBus=new i),e._EventBus},enumerable:!1,configurable:!0}),e._EventBus=null,e}(),i=function(){function e(){this.ListenerDictionary={},this.HandleWindowMessage=this.HandleWindowMessage.bind(this),window.top.addEventListener("message",this.HandleWindowMessage)}return e.prototype.PostWindowMessage=function(n,t){try{window.top.postMessage({source:"unrealtoolkit",message:n,args:t},e.TargetOrigin)}catch(e){console.warn(e)}},e.prototype.OnWindowMessage=function(e,n){var t;null==this.ListenerDictionary[e]?(t=[],this.ListenerDictionary[e]=t):t=this.ListenerDictionary[e],t.findIndex((function(e){return n==e}))<0&&t.push(n)},e.prototype.RemoveHandler=function(e,n){var t=this.ListenerDictionary[e];if(null!=t){var i=t.findIndex((function(e){return n==e}));i>=0&&t.splice(i,1)}},e.prototype.ResetHandlers=function(){this.ListenerDictionary={}},e.prototype.Dispose=function(){this.ResetHandlers(),window.top.removeEventListener("message",this.HandleWindowMessage)},e.prototype.HandleWindowMessage=function(n){if(null!=n&&null!=n.origin&&null!=n.data&&null!=n.data.source&&null!=n.data.message)try{if(null!=e.AllowedOrigin&&""!==e.AllowedOrigin&&"*"!==e.AllowedOrigin&&n.origin!==e.AllowedOrigin)return void console.warn("UnrealMessageBus: Invalid Origin: "+n.origin);this.OnDispatchMessage(n.data.message,null!=n.data.args?n.data.args:null)}catch(e){console.warn(e)}},e.prototype.OnDispatchMessage=function(e,n){void 0===n&&(n=null);var t=this.ListenerDictionary[e];null!=t&&t.forEach((function(e){try{e&&e(n)}catch(e){console.warn(e)}}))},e.AllowedOrigin="*",e.TargetOrigin="*",e}();console.log("Unreal Toolkit Runtime - Version 0.1.8");const o=t;return n.default})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unreal-toolkit",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Unreal Toolkit Runtime Library (UMD)",
5
5
  "main": "dist/unreal.toolkit.js",
6
6
  "types": "dist/index.d.ts",