@kwiz/common 1.0.254 → 1.0.255
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.
|
@@ -24,4 +24,14 @@ target, data) {
|
|
|
24
24
|
: target;
|
|
25
25
|
targetWindow.postMessage(data, '*');
|
|
26
26
|
}
|
|
27
|
+
/** Types were carefully constructed to allow caller to have auto complete options for type while being able to pass other values
|
|
28
|
+
* postMessageSender(window, { type: "xxx", a: 1 });
|
|
29
|
+
* postMessageSender(window, { type: "SOS_RESIZE_IFRAME", height: 1 });
|
|
30
|
+
* postMessageSender(window, { type: "SOS_VISIBILITY_CHANGE", isVisible: false });
|
|
31
|
+
* and
|
|
32
|
+
* postMessageListener("SOS_RESIZE_IFRAME", data => data.height);
|
|
33
|
+
* postMessageListener<{ type: "xxx", param: number }>("xxx", data => {
|
|
34
|
+
* console.log(data.param);
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
27
37
|
//# sourceMappingURL=post-message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-message.js","sourceRoot":"","sources":["../../../src/helpers/post-message.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"post-message.js","sourceRoot":"","sources":["../../../src/helpers/post-message.ts"],"names":[],"mappings":";;AAkDA,kDAkBC;AAcD,8CAUC;AA1CD,SAAgB,mBAAmB,CAC/B,IAAY,EACZ,OAA4B;IAE5B,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAE,EAAE;QAC1C,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACzC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEpD,OAAO;QACH,wCAAwC;QACxC,OAAO,EAAE,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;KACJ,CAAC;AACN,CAAC;AAcD,SAAgB,iBAAiB;AAC7B,8CAA8C;AAC9C,MAAkC,EAClC,IAAqC;IAErC,IAAI,YAAY,GAAG,MAAM,YAAY,iBAAiB;QAClD,CAAC,CAAC,MAAM,CAAC,aAAa;QACtB,CAAC,CAAC,MAAM,CAAC;IAEb,YAAY,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;GASG"}
|
|
@@ -20,4 +20,14 @@ target, data) {
|
|
|
20
20
|
: target;
|
|
21
21
|
targetWindow.postMessage(data, '*');
|
|
22
22
|
}
|
|
23
|
+
/** Types were carefully constructed to allow caller to have auto complete options for type while being able to pass other values
|
|
24
|
+
* postMessageSender(window, { type: "xxx", a: 1 });
|
|
25
|
+
* postMessageSender(window, { type: "SOS_RESIZE_IFRAME", height: 1 });
|
|
26
|
+
* postMessageSender(window, { type: "SOS_VISIBILITY_CHANGE", isVisible: false });
|
|
27
|
+
* and
|
|
28
|
+
* postMessageListener("SOS_RESIZE_IFRAME", data => data.height);
|
|
29
|
+
* postMessageListener<{ type: "xxx", param: number }>("xxx", data => {
|
|
30
|
+
* console.log(data.param);
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
23
33
|
//# sourceMappingURL=post-message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-message.js","sourceRoot":"","sources":["../../../src/helpers/post-message.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"post-message.js","sourceRoot":"","sources":["../../../src/helpers/post-message.ts"],"names":[],"mappings":"AAkDA,MAAM,UAAU,mBAAmB,CAC/B,IAAY,EACZ,OAA4B;IAE5B,MAAM,QAAQ,GAAG,CAAC,KAAwB,EAAE,EAAE;QAC1C,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACzC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEpD,OAAO;QACH,wCAAwC;QACxC,OAAO,EAAE,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;KACJ,CAAC;AACN,CAAC;AAcD,MAAM,UAAU,iBAAiB;AAC7B,8CAA8C;AAC9C,MAAkC,EAClC,IAAqC;IAErC,IAAI,YAAY,GAAG,MAAM,YAAY,iBAAiB;QAClD,CAAC,CAAC,MAAM,CAAC,aAAa;QACtB,CAAC,CAAC,MAAM,CAAC;IAEb,YAAY,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;GASG"}
|
|
@@ -1,19 +1,57 @@
|
|
|
1
|
+
import { IDictionary } from "../types/common.types";
|
|
2
|
+
type postMessagePrimitive = string | number | boolean | null | undefined | bigint;
|
|
3
|
+
type postMessageValue = postMessagePrimitive | Date | RegExp | ArrayBuffer | ArrayBufferView | Blob | File | postMessageValue[] | Map<postMessageValue, postMessageValue> | Set<postMessageValue> | {
|
|
4
|
+
[key: string]: postMessageValue;
|
|
5
|
+
};
|
|
6
|
+
type generic = {
|
|
7
|
+
type: string;
|
|
8
|
+
} & IDictionary<postMessageValue>;
|
|
1
9
|
type resize = {
|
|
2
10
|
type: "SOS_RESIZE_IFRAME";
|
|
3
11
|
height: number;
|
|
12
|
+
params?: IDictionary<postMessageValue>;
|
|
4
13
|
};
|
|
5
14
|
type visible = {
|
|
6
15
|
type: "SOS_VISIBILITY_CHANGE";
|
|
7
16
|
isVisible: boolean;
|
|
17
|
+
params?: IDictionary<postMessageValue>;
|
|
8
18
|
};
|
|
9
19
|
type syncPostMessageValues = resize | visible;
|
|
10
|
-
|
|
20
|
+
type knownPostMessageType = syncPostMessageValues["type"];
|
|
21
|
+
type customPostMessageType = string & {};
|
|
22
|
+
type genericMessage<T extends customPostMessageType> = Omit<generic, "type"> & {
|
|
23
|
+
type: T extends knownPostMessageType ? never : T;
|
|
24
|
+
};
|
|
25
|
+
/** Listen to a known message type */
|
|
26
|
+
export declare function postMessageListener<T extends knownPostMessageType>(type: T, handler: (data: Extract<syncPostMessageValues, {
|
|
11
27
|
type: T;
|
|
12
28
|
}>) => void): {
|
|
13
|
-
/** in case you want to dispose of it */
|
|
14
29
|
dispose: () => void;
|
|
15
30
|
};
|
|
16
|
-
|
|
31
|
+
/** Listen to an unknown message type - you must send in a value for T that has a type that matches the type parameter. For example:
|
|
32
|
+
* postMessageListener<{ type: "m1", param: number }>("m1", data => console.log(data.param));
|
|
33
|
+
*/
|
|
34
|
+
export declare function postMessageListener<T extends genericMessage<customPostMessageType> = never>(type: T["type"] extends knownPostMessageType ? never : T["type"], handler: (data: T) => void): {
|
|
35
|
+
dispose: () => void;
|
|
36
|
+
};
|
|
37
|
+
/** Send a known message type */
|
|
38
|
+
export declare function postMessageSender<T extends knownPostMessageType>(
|
|
39
|
+
/** window.parent, window.top, or iframe ID */
|
|
40
|
+
target: Window | HTMLIFrameElement, data: Extract<syncPostMessageValues, {
|
|
41
|
+
type: T;
|
|
42
|
+
}>): void;
|
|
43
|
+
/** Send an unknown message type, data value will be generic */
|
|
44
|
+
export declare function postMessageSender<T extends customPostMessageType = never>(
|
|
17
45
|
/** window.parent, window.top, or iframe ID */
|
|
18
|
-
target: Window | HTMLIFrameElement, data:
|
|
46
|
+
target: Window | HTMLIFrameElement, data: genericMessage<T>): void;
|
|
19
47
|
export {};
|
|
48
|
+
/** Types were carefully constructed to allow caller to have auto complete options for type while being able to pass other values
|
|
49
|
+
* postMessageSender(window, { type: "xxx", a: 1 });
|
|
50
|
+
* postMessageSender(window, { type: "SOS_RESIZE_IFRAME", height: 1 });
|
|
51
|
+
* postMessageSender(window, { type: "SOS_VISIBILITY_CHANGE", isVisible: false });
|
|
52
|
+
* and
|
|
53
|
+
* postMessageListener("SOS_RESIZE_IFRAME", data => data.height);
|
|
54
|
+
* postMessageListener<{ type: "xxx", param: number }>("xxx", data => {
|
|
55
|
+
* console.log(data.param);
|
|
56
|
+
* });
|
|
57
|
+
*/
|