@prismicio/simulator 0.2.3 → 0.2.4-canary.20a6505
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/SimulatorAPI.cjs +6 -6
- package/dist/SimulatorAPI.cjs.map +1 -1
- package/dist/SimulatorAPI.d.cts +3 -5
- package/dist/SimulatorAPI.d.cts.map +1 -1
- package/dist/SimulatorAPI.d.ts +3 -5
- package/dist/SimulatorAPI.d.ts.map +1 -1
- package/dist/SimulatorAPI.js +6 -6
- package/dist/SimulatorAPI.js.map +1 -1
- package/dist/SimulatorClient.cjs +9 -9
- package/dist/SimulatorClient.cjs.map +1 -1
- package/dist/SimulatorClient.d.cts +2 -4
- package/dist/SimulatorClient.d.cts.map +1 -1
- package/dist/SimulatorClient.d.ts +2 -4
- package/dist/SimulatorClient.d.ts.map +1 -1
- package/dist/SimulatorClient.js +9 -9
- package/dist/SimulatorClient.js.map +1 -1
- package/dist/channel/ChannelEmitter.cjs +6 -8
- package/dist/channel/ChannelEmitter.cjs.map +1 -1
- package/dist/channel/ChannelEmitter.d.cts +3 -5
- package/dist/channel/ChannelEmitter.d.cts.map +1 -1
- package/dist/channel/ChannelEmitter.d.ts +3 -5
- package/dist/channel/ChannelEmitter.d.ts.map +1 -1
- package/dist/channel/ChannelEmitter.js +6 -9
- package/dist/channel/ChannelEmitter.js.map +1 -1
- package/dist/channel/ChannelNetwork.cjs +13 -11
- package/dist/channel/ChannelNetwork.cjs.map +1 -1
- package/dist/channel/ChannelNetwork.d.cts +3 -5
- package/dist/channel/ChannelNetwork.d.cts.map +1 -1
- package/dist/channel/ChannelNetwork.d.ts +3 -5
- package/dist/channel/ChannelNetwork.d.ts.map +1 -1
- package/dist/channel/ChannelNetwork.js +13 -12
- package/dist/channel/ChannelNetwork.js.map +1 -1
- package/dist/channel/ChannelReceiver.cjs +6 -8
- package/dist/channel/ChannelReceiver.cjs.map +1 -1
- package/dist/channel/ChannelReceiver.d.cts +3 -5
- package/dist/channel/ChannelReceiver.d.cts.map +1 -1
- package/dist/channel/ChannelReceiver.d.ts +3 -5
- package/dist/channel/ChannelReceiver.d.ts.map +1 -1
- package/dist/channel/ChannelReceiver.js +6 -9
- package/dist/channel/ChannelReceiver.js.map +1 -1
- package/dist/channel/errors.cjs.map +1 -1
- package/dist/channel/errors.d.cts +7 -9
- package/dist/channel/errors.d.cts.map +1 -1
- package/dist/channel/errors.d.ts +7 -9
- package/dist/channel/errors.d.ts.map +1 -1
- package/dist/channel/errors.js.map +1 -1
- package/dist/channel/messages.cjs.map +1 -1
- package/dist/channel/messages.d.cts +5 -7
- package/dist/channel/messages.d.cts.map +1 -1
- package/dist/channel/messages.d.ts +5 -7
- package/dist/channel/messages.d.ts.map +1 -1
- package/dist/channel/messages.js.map +1 -1
- package/dist/channel/types.d.cts +21 -22
- package/dist/channel/types.d.cts.map +1 -1
- package/dist/channel/types.d.ts +21 -22
- package/dist/channel/types.d.ts.map +1 -1
- package/dist/globalExtensions.d.cts +2 -2
- package/dist/globalExtensions.d.cts.map +1 -1
- package/dist/globalExtensions.d.ts +1 -2
- package/dist/globalExtensions.d.ts.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/kit/SimulatorManager.cjs +7 -6
- package/dist/kit/SimulatorManager.cjs.map +1 -1
- package/dist/kit/SimulatorManager.d.cts +2 -3
- package/dist/kit/SimulatorManager.d.cts.map +1 -1
- package/dist/kit/SimulatorManager.d.ts +2 -3
- package/dist/kit/SimulatorManager.d.ts.map +1 -1
- package/dist/kit/SimulatorManager.js +7 -6
- package/dist/kit/SimulatorManager.js.map +1 -1
- package/dist/kit/State.cjs +4 -4
- package/dist/kit/State.cjs.map +1 -1
- package/dist/kit/State.d.cts +2 -3
- package/dist/kit/State.d.cts.map +1 -1
- package/dist/kit/State.d.ts +2 -3
- package/dist/kit/State.d.ts.map +1 -1
- package/dist/kit/State.js +4 -4
- package/dist/kit/State.js.map +1 -1
- package/dist/kit/domHelpers.cjs.map +1 -1
- package/dist/kit/domHelpers.d.cts +4 -5
- package/dist/kit/domHelpers.d.cts.map +1 -1
- package/dist/kit/domHelpers.d.ts +4 -5
- package/dist/kit/domHelpers.d.ts.map +1 -1
- package/dist/kit/domHelpers.js.map +1 -1
- package/dist/kit/eventHandlers.cjs.map +1 -1
- package/dist/kit/eventHandlers.d.cts +2 -3
- package/dist/kit/eventHandlers.d.cts.map +1 -1
- package/dist/kit/eventHandlers.d.ts +2 -3
- package/dist/kit/eventHandlers.d.ts.map +1 -1
- package/dist/kit/eventHandlers.js.map +1 -1
- package/dist/kit/getDefault.cjs.map +1 -1
- package/dist/kit/getDefault.d.cts +3 -5
- package/dist/kit/getDefault.d.cts.map +1 -1
- package/dist/kit/getDefault.d.ts +3 -5
- package/dist/kit/getDefault.d.ts.map +1 -1
- package/dist/kit/getDefault.js.map +1 -1
- package/dist/kit/messages.cjs.map +1 -1
- package/dist/kit/messages.d.cts +1 -2
- package/dist/kit/messages.d.cts.map +1 -1
- package/dist/kit/messages.d.ts +1 -2
- package/dist/kit/messages.d.ts.map +1 -1
- package/dist/kit/messages.js.map +1 -1
- package/dist/kit/types.cjs.map +1 -1
- package/dist/kit/types.d.cts +5 -7
- package/dist/kit/types.d.cts.map +1 -1
- package/dist/kit/types.d.ts +5 -7
- package/dist/kit/types.d.ts.map +1 -1
- package/dist/kit/types.js.map +1 -1
- package/dist/lib/EventEmitter.cjs.map +1 -1
- package/dist/lib/EventEmitter.d.cts +3 -4
- package/dist/lib/EventEmitter.d.cts.map +1 -1
- package/dist/lib/EventEmitter.d.ts +3 -4
- package/dist/lib/EventEmitter.d.ts.map +1 -1
- package/dist/lib/EventEmitter.js.map +1 -1
- package/dist/lib/throttle.cjs.map +1 -1
- package/dist/lib/throttle.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -8
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +6 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +11 -11
- package/src/kit/SimulatorManager.ts +1 -0
- package/dist/channel/types.cjs +0 -14
- package/dist/channel/types.cjs.map +0 -1
- package/dist/channel/types.js +0 -13
- package/dist/channel/types.js.map +0 -1
package/dist/SimulatorAPI.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_ChannelReceiver = require("./channel/ChannelReceiver.cjs");
|
|
2
|
-
|
|
2
|
+
require("./types.cjs");
|
|
3
3
|
//#region src/SimulatorAPI.ts
|
|
4
4
|
const simulatorAPIDefaultOptions = {
|
|
5
5
|
requestIDPrefix: "api-",
|
|
@@ -10,7 +10,7 @@ var SimulatorAPI = class extends require_ChannelReceiver.ChannelReceiver {
|
|
|
10
10
|
constructor(requestHandlers, options) {
|
|
11
11
|
const debug = options?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search));
|
|
12
12
|
super({
|
|
13
|
-
[
|
|
13
|
+
["ping"]: (_req, res) => {
|
|
14
14
|
return res.success("pong");
|
|
15
15
|
},
|
|
16
16
|
...requestHandlers
|
|
@@ -26,11 +26,11 @@ var SimulatorAPI = class extends require_ChannelReceiver.ChannelReceiver {
|
|
|
26
26
|
window.prismic.sliceSimulator.api.push(this);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
[
|
|
30
|
-
return await this.postFormattedRequest(
|
|
29
|
+
["setActiveSlice"] = async (data) => {
|
|
30
|
+
return await this.postFormattedRequest("setActiveSlice", data);
|
|
31
31
|
};
|
|
32
|
-
[
|
|
33
|
-
return await this.postFormattedRequest(
|
|
32
|
+
["setSliceZoneSize"] = async (data) => {
|
|
33
|
+
return await this.postFormattedRequest("setSliceZoneSize", data);
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorAPI.cjs","names":["ChannelReceiver"
|
|
1
|
+
{"version":3,"file":"SimulatorAPI.cjs","names":["ChannelReceiver"],"sources":["../src/SimulatorAPI.ts"],"sourcesContent":["import type {\n\tAllChannelReceiverOptions,\n\tTransactionMethod,\n\tTransactionsHandlers,\n\tTransactionsMethods,\n} from \"./channel\"\nimport { ChannelReceiver } from \"./channel\"\nimport type { APITransactions, ClientTransactions } from \"./types\"\nimport { APIRequestType, ClientRequestType } from \"./types\"\n\nexport type SimulatorAPIOptions = {\n\tactiveSliceAPI: boolean\n\tsliceZoneSizeAPI: boolean\n}\n\nexport const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions =\n\t{\n\t\trequestIDPrefix: \"api-\",\n\t\tactiveSliceAPI: false,\n\t\tsliceZoneSizeAPI: false,\n\t}\n\nexport class SimulatorAPI\n\textends ChannelReceiver<ClientTransactions, SimulatorAPIOptions>\n\timplements TransactionsMethods<APITransactions>\n{\n\tconstructor(\n\t\trequestHandlers: Omit<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping> &\n\t\t\tPartial<Pick<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping>>,\n\t\toptions?: Partial<AllChannelReceiverOptions & SimulatorAPIOptions>,\n\t) {\n\t\t// True if `options.debug` is true or `debug=true` is among query parameters\n\t\tconst debug =\n\t\t\toptions?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search))\n\n\t\tsuper(\n\t\t\t{\n\t\t\t\t[ClientRequestType.Ping]: (_req, res) => {\n\t\t\t\t\treturn res.success(\"pong\")\n\t\t\t\t},\n\t\t\t\t...requestHandlers,\n\t\t\t},\n\t\t\t{\n\t\t\t\t...simulatorAPIDefaultOptions,\n\t\t\t\t...options,\n\t\t\t\tdebug,\n\t\t\t},\n\t\t)\n\n\t\t// Append API to window object\n\t\tif (debug) {\n\t\t\twindow.prismic ||= {}\n\t\t\twindow.prismic.sliceSimulator ||= {}\n\t\t\twindow.prismic.sliceSimulator.api ||= []\n\t\t\twindow.prismic.sliceSimulator.api.push(this)\n\t\t}\n\t}\n\n\t[APIRequestType.SetActiveSlice]: TransactionMethod<\n\t\tAPITransactions[APIRequestType.SetActiveSlice]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(APIRequestType.SetActiveSlice, data)\n\t};\n\n\t[APIRequestType.SetSliceZoneSize]: TransactionMethod<\n\t\tAPITransactions[APIRequestType.SetSliceZoneSize]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(APIRequestType.SetSliceZoneSize, data)\n\t}\n}\n"],"mappings":";;;AAeA,MAAa,6BACZ;CACC,iBAAiB;CACjB,gBAAgB;CAChB,kBAAkB;AACnB;AAED,IAAa,eAAb,cACSA,wBAAAA,gBAET;CACC,YACC,iBAEA,SACC;EAED,MAAM,QACL,SAAS,SAAS,kBAAkB,KAAK,mBAAmB,OAAO,SAAS,MAAM,CAAC;EAEpF,MACC;IAC4B,UAAA,MAAM,QAAQ;IACxC,OAAO,IAAI,QAAQ,MAAM;GAC1B;GACA,GAAG;EACJ,GACA;GACC,GAAG;GACH,GAAG;GACH;EACD,CACD;EAGA,IAAI,OAAO;GACV,OAAO,YAAY,CAAC;GACpB,OAAO,QAAQ,mBAAmB,CAAC;GACnC,OAAO,QAAQ,eAAe,QAAQ,CAAC;GACvC,OAAO,QAAQ,eAAe,IAAI,KAAK,IAAI;EAC5C;CACD;CAEA,CAAA,oBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,kBAAoD,IAAI;CAC3E;CAEA,CAAA,sBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,oBAAsD,IAAI;CAC7E;AACD"}
|
package/dist/SimulatorAPI.d.cts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { TransactionMethod, TransactionsHandlers, TransactionsMethods } from "./channel/types.cjs";
|
|
2
2
|
import { AllChannelReceiverOptions, ChannelReceiver } from "./channel/ChannelReceiver.cjs";
|
|
3
3
|
import { APIRequestType, APITransactions, ClientRequestType, ClientTransactions } from "./types.cjs";
|
|
4
|
-
|
|
5
4
|
//#region src/SimulatorAPI.d.ts
|
|
6
|
-
type SimulatorAPIOptions = {
|
|
5
|
+
export type SimulatorAPIOptions = {
|
|
7
6
|
activeSliceAPI: boolean;
|
|
8
7
|
sliceZoneSizeAPI: boolean;
|
|
9
8
|
};
|
|
10
|
-
declare const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions;
|
|
11
|
-
declare class SimulatorAPI extends ChannelReceiver<ClientTransactions, SimulatorAPIOptions> implements TransactionsMethods<APITransactions> {
|
|
9
|
+
export declare const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions;
|
|
10
|
+
export declare class SimulatorAPI extends ChannelReceiver<ClientTransactions, SimulatorAPIOptions> implements TransactionsMethods<APITransactions> {
|
|
12
11
|
constructor(requestHandlers: Omit<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping> & Partial<Pick<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping>>, options?: Partial<AllChannelReceiverOptions & SimulatorAPIOptions>);
|
|
13
12
|
[APIRequestType.SetActiveSlice]: TransactionMethod<APITransactions[APIRequestType.SetActiveSlice]>;
|
|
14
13
|
[APIRequestType.SetSliceZoneSize]: TransactionMethod<APITransactions[APIRequestType.SetSliceZoneSize]>;
|
|
15
14
|
}
|
|
16
15
|
//#endregion
|
|
17
|
-
export { SimulatorAPI, SimulatorAPIOptions, simulatorAPIDefaultOptions };
|
|
18
16
|
//# sourceMappingURL=SimulatorAPI.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorAPI.d.cts","names":[],"sources":["../src/SimulatorAPI.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SimulatorAPI.d.cts","names":[],"sources":["../src/SimulatorAPI.ts"],"mappings":";;;;YAUY;EACX;EACA;;qBAGY,4BAA4B,QAAQ,6BAA6B;qBAOjE,qBACJ,gBAAgB,oBAAoB,gCACjC,oBAAoB;EAE/B,YACC,iBAAiB,KAAK,qBAAqB,qBAAqB,kBAAkB,QACjF,QAAQ,KAAK,qBAAqB,qBAAqB,kBAAkB,QAC1E,UAAU,QAAQ,4BAA4B;GA6B9C,eAAe,iBAAiB,kBAChC,gBAAgB,eAAe;GAK/B,eAAe,mBAAmB,kBAClC,gBAAgB,eAAe"}
|
package/dist/SimulatorAPI.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { TransactionMethod, TransactionsHandlers, TransactionsMethods } from "./channel/types.js";
|
|
2
2
|
import { AllChannelReceiverOptions, ChannelReceiver } from "./channel/ChannelReceiver.js";
|
|
3
3
|
import { APIRequestType, APITransactions, ClientRequestType, ClientTransactions } from "./types.js";
|
|
4
|
-
|
|
5
4
|
//#region src/SimulatorAPI.d.ts
|
|
6
|
-
type SimulatorAPIOptions = {
|
|
5
|
+
export type SimulatorAPIOptions = {
|
|
7
6
|
activeSliceAPI: boolean;
|
|
8
7
|
sliceZoneSizeAPI: boolean;
|
|
9
8
|
};
|
|
10
|
-
declare const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions;
|
|
11
|
-
declare class SimulatorAPI extends ChannelReceiver<ClientTransactions, SimulatorAPIOptions> implements TransactionsMethods<APITransactions> {
|
|
9
|
+
export declare const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions;
|
|
10
|
+
export declare class SimulatorAPI extends ChannelReceiver<ClientTransactions, SimulatorAPIOptions> implements TransactionsMethods<APITransactions> {
|
|
12
11
|
constructor(requestHandlers: Omit<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping> & Partial<Pick<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping>>, options?: Partial<AllChannelReceiverOptions & SimulatorAPIOptions>);
|
|
13
12
|
[APIRequestType.SetActiveSlice]: TransactionMethod<APITransactions[APIRequestType.SetActiveSlice]>;
|
|
14
13
|
[APIRequestType.SetSliceZoneSize]: TransactionMethod<APITransactions[APIRequestType.SetSliceZoneSize]>;
|
|
15
14
|
}
|
|
16
15
|
//#endregion
|
|
17
|
-
export { SimulatorAPI, SimulatorAPIOptions, simulatorAPIDefaultOptions };
|
|
18
16
|
//# sourceMappingURL=SimulatorAPI.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorAPI.d.ts","names":[],"sources":["../src/SimulatorAPI.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SimulatorAPI.d.ts","names":[],"sources":["../src/SimulatorAPI.ts"],"mappings":";;;;YAUY;EACX;EACA;;qBAGY,4BAA4B,QAAQ,6BAA6B;qBAOjE,qBACJ,gBAAgB,oBAAoB,gCACjC,oBAAoB;EAE/B,YACC,iBAAiB,KAAK,qBAAqB,qBAAqB,kBAAkB,QACjF,QAAQ,KAAK,qBAAqB,qBAAqB,kBAAkB,QAC1E,UAAU,QAAQ,4BAA4B;GA6B9C,eAAe,iBAAiB,kBAChC,gBAAgB,eAAe;GAK/B,eAAe,mBAAmB,kBAClC,gBAAgB,eAAe"}
|
package/dist/SimulatorAPI.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChannelReceiver } from "./channel/ChannelReceiver.js";
|
|
2
|
-
import
|
|
2
|
+
import "./types.js";
|
|
3
3
|
//#region src/SimulatorAPI.ts
|
|
4
4
|
const simulatorAPIDefaultOptions = {
|
|
5
5
|
requestIDPrefix: "api-",
|
|
@@ -10,7 +10,7 @@ var SimulatorAPI = class extends ChannelReceiver {
|
|
|
10
10
|
constructor(requestHandlers, options) {
|
|
11
11
|
const debug = options?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search));
|
|
12
12
|
super({
|
|
13
|
-
[
|
|
13
|
+
["ping"]: (_req, res) => {
|
|
14
14
|
return res.success("pong");
|
|
15
15
|
},
|
|
16
16
|
...requestHandlers
|
|
@@ -26,11 +26,11 @@ var SimulatorAPI = class extends ChannelReceiver {
|
|
|
26
26
|
window.prismic.sliceSimulator.api.push(this);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
[
|
|
30
|
-
return await this.postFormattedRequest(
|
|
29
|
+
["setActiveSlice"] = async (data) => {
|
|
30
|
+
return await this.postFormattedRequest("setActiveSlice", data);
|
|
31
31
|
};
|
|
32
|
-
[
|
|
33
|
-
return await this.postFormattedRequest(
|
|
32
|
+
["setSliceZoneSize"] = async (data) => {
|
|
33
|
+
return await this.postFormattedRequest("setSliceZoneSize", data);
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
package/dist/SimulatorAPI.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorAPI.js","names":[],"sources":["../src/SimulatorAPI.ts"],"sourcesContent":["import type {\n\tAllChannelReceiverOptions,\n\tTransactionMethod,\n\tTransactionsHandlers,\n\tTransactionsMethods,\n} from \"./channel\"\nimport { ChannelReceiver } from \"./channel\"\nimport type { APITransactions, ClientTransactions } from \"./types\"\nimport { APIRequestType, ClientRequestType } from \"./types\"\n\nexport type SimulatorAPIOptions = {\n\tactiveSliceAPI: boolean\n\tsliceZoneSizeAPI: boolean\n}\n\nexport const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions =\n\t{\n\t\trequestIDPrefix: \"api-\",\n\t\tactiveSliceAPI: false,\n\t\tsliceZoneSizeAPI: false,\n\t}\n\nexport class SimulatorAPI\n\textends ChannelReceiver<ClientTransactions, SimulatorAPIOptions>\n\timplements TransactionsMethods<APITransactions>\n{\n\tconstructor(\n\t\trequestHandlers: Omit<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping> &\n\t\t\tPartial<Pick<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping>>,\n\t\toptions?: Partial<AllChannelReceiverOptions & SimulatorAPIOptions>,\n\t) {\n\t\t// True if `options.debug` is true or `debug=true` is among query parameters\n\t\tconst debug =\n\t\t\toptions?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search))\n\n\t\tsuper(\n\t\t\t{\n\t\t\t\t[ClientRequestType.Ping]: (_req, res) => {\n\t\t\t\t\treturn res.success(\"pong\")\n\t\t\t\t},\n\t\t\t\t...requestHandlers,\n\t\t\t},\n\t\t\t{\n\t\t\t\t...simulatorAPIDefaultOptions,\n\t\t\t\t...options,\n\t\t\t\tdebug,\n\t\t\t},\n\t\t)\n\n\t\t// Append API to window object\n\t\tif (debug) {\n\t\t\twindow.prismic ||= {}\n\t\t\twindow.prismic.sliceSimulator ||= {}\n\t\t\twindow.prismic.sliceSimulator.api ||= []\n\t\t\twindow.prismic.sliceSimulator.api.push(this)\n\t\t}\n\t}\n\n\t[APIRequestType.SetActiveSlice]: TransactionMethod<\n\t\tAPITransactions[APIRequestType.SetActiveSlice]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(APIRequestType.SetActiveSlice, data)\n\t};\n\n\t[APIRequestType.SetSliceZoneSize]: TransactionMethod<\n\t\tAPITransactions[APIRequestType.SetSliceZoneSize]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(APIRequestType.SetSliceZoneSize, data)\n\t}\n}\n"],"mappings":";;;AAeA,MAAa,6BACZ;CACC,iBAAiB;CACjB,gBAAgB;CAChB,kBAAkB;
|
|
1
|
+
{"version":3,"file":"SimulatorAPI.js","names":[],"sources":["../src/SimulatorAPI.ts"],"sourcesContent":["import type {\n\tAllChannelReceiverOptions,\n\tTransactionMethod,\n\tTransactionsHandlers,\n\tTransactionsMethods,\n} from \"./channel\"\nimport { ChannelReceiver } from \"./channel\"\nimport type { APITransactions, ClientTransactions } from \"./types\"\nimport { APIRequestType, ClientRequestType } from \"./types\"\n\nexport type SimulatorAPIOptions = {\n\tactiveSliceAPI: boolean\n\tsliceZoneSizeAPI: boolean\n}\n\nexport const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> & SimulatorAPIOptions =\n\t{\n\t\trequestIDPrefix: \"api-\",\n\t\tactiveSliceAPI: false,\n\t\tsliceZoneSizeAPI: false,\n\t}\n\nexport class SimulatorAPI\n\textends ChannelReceiver<ClientTransactions, SimulatorAPIOptions>\n\timplements TransactionsMethods<APITransactions>\n{\n\tconstructor(\n\t\trequestHandlers: Omit<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping> &\n\t\t\tPartial<Pick<TransactionsHandlers<ClientTransactions>, ClientRequestType.Ping>>,\n\t\toptions?: Partial<AllChannelReceiverOptions & SimulatorAPIOptions>,\n\t) {\n\t\t// True if `options.debug` is true or `debug=true` is among query parameters\n\t\tconst debug =\n\t\t\toptions?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search))\n\n\t\tsuper(\n\t\t\t{\n\t\t\t\t[ClientRequestType.Ping]: (_req, res) => {\n\t\t\t\t\treturn res.success(\"pong\")\n\t\t\t\t},\n\t\t\t\t...requestHandlers,\n\t\t\t},\n\t\t\t{\n\t\t\t\t...simulatorAPIDefaultOptions,\n\t\t\t\t...options,\n\t\t\t\tdebug,\n\t\t\t},\n\t\t)\n\n\t\t// Append API to window object\n\t\tif (debug) {\n\t\t\twindow.prismic ||= {}\n\t\t\twindow.prismic.sliceSimulator ||= {}\n\t\t\twindow.prismic.sliceSimulator.api ||= []\n\t\t\twindow.prismic.sliceSimulator.api.push(this)\n\t\t}\n\t}\n\n\t[APIRequestType.SetActiveSlice]: TransactionMethod<\n\t\tAPITransactions[APIRequestType.SetActiveSlice]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(APIRequestType.SetActiveSlice, data)\n\t};\n\n\t[APIRequestType.SetSliceZoneSize]: TransactionMethod<\n\t\tAPITransactions[APIRequestType.SetSliceZoneSize]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(APIRequestType.SetSliceZoneSize, data)\n\t}\n}\n"],"mappings":";;;AAeA,MAAa,6BACZ;CACC,iBAAiB;CACjB,gBAAgB;CAChB,kBAAkB;AACnB;AAED,IAAa,eAAb,cACS,gBAET;CACC,YACC,iBAEA,SACC;EAED,MAAM,QACL,SAAS,SAAS,kBAAkB,KAAK,mBAAmB,OAAO,SAAS,MAAM,CAAC;EAEpF,MACC;IAC4B,UAAA,MAAM,QAAQ;IACxC,OAAO,IAAI,QAAQ,MAAM;GAC1B;GACA,GAAG;EACJ,GACA;GACC,GAAG;GACH,GAAG;GACH;EACD,CACD;EAGA,IAAI,OAAO;GACV,OAAO,YAAY,CAAC;GACpB,OAAO,QAAQ,mBAAmB,CAAC;GACnC,OAAO,QAAQ,eAAe,QAAQ,CAAC;GACvC,OAAO,QAAQ,eAAe,IAAI,KAAK,IAAI;EAC5C;CACD;CAEA,CAAA,oBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,kBAAoD,IAAI;CAC3E;CAEA,CAAA,sBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,oBAAsD,IAAI;CAC7E;AACD"}
|
package/dist/SimulatorClient.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const require_ChannelEmitter = require("./channel/ChannelEmitter.cjs");
|
|
2
|
-
|
|
2
|
+
require("./types.cjs");
|
|
3
3
|
//#region src/SimulatorClient.ts
|
|
4
4
|
const simulatorClientDefaultOptions = { requestIDPrefix: "client-" };
|
|
5
5
|
var SimulatorClient = class extends require_ChannelEmitter.ChannelEmitter {
|
|
6
6
|
constructor(target, requestHandlers, options) {
|
|
7
7
|
const debug = options?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search));
|
|
8
8
|
super(target, {
|
|
9
|
-
[
|
|
9
|
+
["setActiveSlice"]: (_req, res) => {
|
|
10
10
|
return res.success();
|
|
11
11
|
},
|
|
12
|
-
[
|
|
12
|
+
["setSliceZoneSize"]: (_req, res) => {
|
|
13
13
|
return res.success();
|
|
14
14
|
},
|
|
15
15
|
...requestHandlers
|
|
@@ -25,14 +25,14 @@ var SimulatorClient = class extends require_ChannelEmitter.ChannelEmitter {
|
|
|
25
25
|
window.prismic.sliceSimulator.client.push(this);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
[
|
|
29
|
-
return await this.postFormattedRequest(
|
|
28
|
+
["ping"] = async () => {
|
|
29
|
+
return await this.postFormattedRequest("ping");
|
|
30
30
|
};
|
|
31
|
-
[
|
|
32
|
-
return await this.postFormattedRequest(
|
|
31
|
+
["setSliceZone"] = async (data) => {
|
|
32
|
+
return await this.postFormattedRequest("setSliceZone", data);
|
|
33
33
|
};
|
|
34
|
-
[
|
|
35
|
-
return await this.postFormattedRequest(
|
|
34
|
+
["scrollToSlice"] = async (data) => {
|
|
35
|
+
return await this.postFormattedRequest("scrollToSlice", data);
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorClient.cjs","names":["ChannelEmitter"
|
|
1
|
+
{"version":3,"file":"SimulatorClient.cjs","names":["ChannelEmitter"],"sources":["../src/SimulatorClient.ts"],"sourcesContent":["import type {\n\tAllChannelEmitterOptions,\n\tTransactionMethod,\n\tTransactionsHandlers,\n\tTransactionsMethods,\n} from \"./channel\"\nimport { ChannelEmitter } from \"./channel\"\nimport type { SimulatorAPIOptions } from \"./SimulatorAPI\"\nimport type { APITransactions, ClientTransactions } from \"./types\"\nimport { APIRequestType, ClientRequestType } from \"./types\"\n\nexport const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions> = {\n\trequestIDPrefix: \"client-\",\n}\n\nexport class SimulatorClient\n\textends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions>\n\timplements TransactionsMethods<ClientTransactions>\n{\n\tconstructor(\n\t\ttarget: HTMLIFrameElement,\n\t\trequestHandlers?: Partial<TransactionsHandlers<APITransactions>>,\n\t\toptions?: Partial<AllChannelEmitterOptions>,\n\t) {\n\t\t// True if `options.debug` is true or `debug=true` is among query parameters\n\t\tconst debug =\n\t\t\toptions?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search))\n\n\t\tsuper(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\t[APIRequestType.SetActiveSlice]: (_req, res) => {\n\t\t\t\t\treturn res.success()\n\t\t\t\t},\n\t\t\t\t[APIRequestType.SetSliceZoneSize]: (_req, res) => {\n\t\t\t\t\treturn res.success()\n\t\t\t\t},\n\t\t\t\t...requestHandlers,\n\t\t\t},\n\t\t\t{\n\t\t\t\t...simulatorClientDefaultOptions,\n\t\t\t\t...options,\n\t\t\t\tdebug,\n\t\t\t},\n\t\t)\n\n\t\t// Append client to window object\n\t\tif (debug) {\n\t\t\twindow.prismic ||= {}\n\t\t\twindow.prismic.sliceSimulator ||= {}\n\t\t\twindow.prismic.sliceSimulator.client ||= []\n\t\t\twindow.prismic.sliceSimulator.client.push(this)\n\t\t}\n\t}\n\n\t[ClientRequestType.Ping]: TransactionMethod<ClientTransactions[ClientRequestType.Ping]> =\n\t\tasync () => {\n\t\t\treturn await this.postFormattedRequest(ClientRequestType.Ping)\n\t\t};\n\n\t[ClientRequestType.SetSliceZone]: TransactionMethod<\n\t\tClientTransactions[ClientRequestType.SetSliceZone]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(ClientRequestType.SetSliceZone, data)\n\t};\n\n\t[ClientRequestType.ScrollToSlice]: TransactionMethod<\n\t\tClientTransactions[ClientRequestType.ScrollToSlice]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(ClientRequestType.ScrollToSlice, data)\n\t}\n}\n"],"mappings":";;;AAWA,MAAa,gCAAmE,EAC/E,iBAAiB,UAClB;AAEA,IAAa,kBAAb,cACSA,uBAAAA,eAET;CACC,YACC,QACA,iBACA,SACC;EAED,MAAM,QACL,SAAS,SAAS,kBAAkB,KAAK,mBAAmB,OAAO,SAAS,MAAM,CAAC;EAEpF,MACC,QACA;IACmC,oBAAA,MAAM,QAAQ;IAC/C,OAAO,IAAI,QAAQ;GACpB;IACoC,sBAAA,MAAM,QAAQ;IACjD,OAAO,IAAI,QAAQ;GACpB;GACA,GAAG;EACJ,GACA;GACC,GAAG;GACH,GAAG;GACH;EACD,CACD;EAGA,IAAI,OAAO;GACV,OAAO,YAAY,CAAC;GACpB,OAAO,QAAQ,mBAAmB,CAAC;GACnC,OAAO,QAAQ,eAAe,WAAW,CAAC;GAC1C,OAAO,QAAQ,eAAe,OAAO,KAAK,IAAI;EAC/C;CACD;CAEA,CAAA,UACC,YAAY;EACX,OAAO,MAAM,KAAK,qBAAA,MAA2C;CAC9D;CAED,CAAA,kBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,gBAAqD,IAAI;CAC5E;CAEA,CAAA,mBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,iBAAsD,IAAI;CAC7E;AACD"}
|
|
@@ -2,15 +2,13 @@ import { TransactionMethod, TransactionsHandlers, TransactionsMethods } from "./
|
|
|
2
2
|
import { AllChannelEmitterOptions, ChannelEmitter } from "./channel/ChannelEmitter.cjs";
|
|
3
3
|
import { APITransactions, ClientRequestType, ClientTransactions } from "./types.cjs";
|
|
4
4
|
import { SimulatorAPIOptions } from "./SimulatorAPI.cjs";
|
|
5
|
-
|
|
6
5
|
//#region src/SimulatorClient.d.ts
|
|
7
|
-
declare const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions>;
|
|
8
|
-
declare class SimulatorClient extends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions> implements TransactionsMethods<ClientTransactions> {
|
|
6
|
+
export declare const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions>;
|
|
7
|
+
export declare class SimulatorClient extends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions> implements TransactionsMethods<ClientTransactions> {
|
|
9
8
|
constructor(target: HTMLIFrameElement, requestHandlers?: Partial<TransactionsHandlers<APITransactions>>, options?: Partial<AllChannelEmitterOptions>);
|
|
10
9
|
[ClientRequestType.Ping]: TransactionMethod<ClientTransactions[ClientRequestType.Ping]>;
|
|
11
10
|
[ClientRequestType.SetSliceZone]: TransactionMethod<ClientTransactions[ClientRequestType.SetSliceZone]>;
|
|
12
11
|
[ClientRequestType.ScrollToSlice]: TransactionMethod<ClientTransactions[ClientRequestType.ScrollToSlice]>;
|
|
13
12
|
}
|
|
14
13
|
//#endregion
|
|
15
|
-
export { SimulatorClient, simulatorClientDefaultOptions };
|
|
16
14
|
//# sourceMappingURL=SimulatorClient.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorClient.d.cts","names":[],"sources":["../src/SimulatorClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SimulatorClient.d.cts","names":[],"sources":["../src/SimulatorClient.ts"],"mappings":";;;;;qBAWa,+BAA+B,QAAQ;qBAIvC,wBACJ,eAAe,iBAAiB,QAAQ,2BAA2B,gCAChE,oBAAoB;EAE/B,YACC,QAAQ,mBACR,kBAAkB,QAAQ,qBAAqB,mBAC/C,UAAU,QAAQ;GAiClB,kBAAkB,OAAO,kBAAkB,mBAAmB,kBAAkB;GAKhF,kBAAkB,eAAe,kBACjC,mBAAmB,kBAAkB;GAKrC,kBAAkB,gBAAgB,kBAClC,mBAAmB,kBAAkB"}
|
|
@@ -2,15 +2,13 @@ import { TransactionMethod, TransactionsHandlers, TransactionsMethods } from "./
|
|
|
2
2
|
import { AllChannelEmitterOptions, ChannelEmitter } from "./channel/ChannelEmitter.js";
|
|
3
3
|
import { APITransactions, ClientRequestType, ClientTransactions } from "./types.js";
|
|
4
4
|
import { SimulatorAPIOptions } from "./SimulatorAPI.js";
|
|
5
|
-
|
|
6
5
|
//#region src/SimulatorClient.d.ts
|
|
7
|
-
declare const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions>;
|
|
8
|
-
declare class SimulatorClient extends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions> implements TransactionsMethods<ClientTransactions> {
|
|
6
|
+
export declare const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions>;
|
|
7
|
+
export declare class SimulatorClient extends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions> implements TransactionsMethods<ClientTransactions> {
|
|
9
8
|
constructor(target: HTMLIFrameElement, requestHandlers?: Partial<TransactionsHandlers<APITransactions>>, options?: Partial<AllChannelEmitterOptions>);
|
|
10
9
|
[ClientRequestType.Ping]: TransactionMethod<ClientTransactions[ClientRequestType.Ping]>;
|
|
11
10
|
[ClientRequestType.SetSliceZone]: TransactionMethod<ClientTransactions[ClientRequestType.SetSliceZone]>;
|
|
12
11
|
[ClientRequestType.ScrollToSlice]: TransactionMethod<ClientTransactions[ClientRequestType.ScrollToSlice]>;
|
|
13
12
|
}
|
|
14
13
|
//#endregion
|
|
15
|
-
export { SimulatorClient, simulatorClientDefaultOptions };
|
|
16
14
|
//# sourceMappingURL=SimulatorClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorClient.d.ts","names":[],"sources":["../src/SimulatorClient.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SimulatorClient.d.ts","names":[],"sources":["../src/SimulatorClient.ts"],"mappings":";;;;;qBAWa,+BAA+B,QAAQ;qBAIvC,wBACJ,eAAe,iBAAiB,QAAQ,2BAA2B,gCAChE,oBAAoB;EAE/B,YACC,QAAQ,mBACR,kBAAkB,QAAQ,qBAAqB,mBAC/C,UAAU,QAAQ;GAiClB,kBAAkB,OAAO,kBAAkB,mBAAmB,kBAAkB;GAKhF,kBAAkB,eAAe,kBACjC,mBAAmB,kBAAkB;GAKrC,kBAAkB,gBAAgB,kBAClC,mBAAmB,kBAAkB"}
|
package/dist/SimulatorClient.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ChannelEmitter } from "./channel/ChannelEmitter.js";
|
|
2
|
-
import
|
|
2
|
+
import "./types.js";
|
|
3
3
|
//#region src/SimulatorClient.ts
|
|
4
4
|
const simulatorClientDefaultOptions = { requestIDPrefix: "client-" };
|
|
5
5
|
var SimulatorClient = class extends ChannelEmitter {
|
|
6
6
|
constructor(target, requestHandlers, options) {
|
|
7
7
|
const debug = options?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search));
|
|
8
8
|
super(target, {
|
|
9
|
-
[
|
|
9
|
+
["setActiveSlice"]: (_req, res) => {
|
|
10
10
|
return res.success();
|
|
11
11
|
},
|
|
12
|
-
[
|
|
12
|
+
["setSliceZoneSize"]: (_req, res) => {
|
|
13
13
|
return res.success();
|
|
14
14
|
},
|
|
15
15
|
...requestHandlers
|
|
@@ -25,14 +25,14 @@ var SimulatorClient = class extends ChannelEmitter {
|
|
|
25
25
|
window.prismic.sliceSimulator.client.push(this);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
[
|
|
29
|
-
return await this.postFormattedRequest(
|
|
28
|
+
["ping"] = async () => {
|
|
29
|
+
return await this.postFormattedRequest("ping");
|
|
30
30
|
};
|
|
31
|
-
[
|
|
32
|
-
return await this.postFormattedRequest(
|
|
31
|
+
["setSliceZone"] = async (data) => {
|
|
32
|
+
return await this.postFormattedRequest("setSliceZone", data);
|
|
33
33
|
};
|
|
34
|
-
[
|
|
35
|
-
return await this.postFormattedRequest(
|
|
34
|
+
["scrollToSlice"] = async (data) => {
|
|
35
|
+
return await this.postFormattedRequest("scrollToSlice", data);
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorClient.js","names":[],"sources":["../src/SimulatorClient.ts"],"sourcesContent":["import type {\n\tAllChannelEmitterOptions,\n\tTransactionMethod,\n\tTransactionsHandlers,\n\tTransactionsMethods,\n} from \"./channel\"\nimport { ChannelEmitter } from \"./channel\"\nimport type { SimulatorAPIOptions } from \"./SimulatorAPI\"\nimport type { APITransactions, ClientTransactions } from \"./types\"\nimport { APIRequestType, ClientRequestType } from \"./types\"\n\nexport const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions> = {\n\trequestIDPrefix: \"client-\",\n}\n\nexport class SimulatorClient\n\textends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions>\n\timplements TransactionsMethods<ClientTransactions>\n{\n\tconstructor(\n\t\ttarget: HTMLIFrameElement,\n\t\trequestHandlers?: Partial<TransactionsHandlers<APITransactions>>,\n\t\toptions?: Partial<AllChannelEmitterOptions>,\n\t) {\n\t\t// True if `options.debug` is true or `debug=true` is among query parameters\n\t\tconst debug =\n\t\t\toptions?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search))\n\n\t\tsuper(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\t[APIRequestType.SetActiveSlice]: (_req, res) => {\n\t\t\t\t\treturn res.success()\n\t\t\t\t},\n\t\t\t\t[APIRequestType.SetSliceZoneSize]: (_req, res) => {\n\t\t\t\t\treturn res.success()\n\t\t\t\t},\n\t\t\t\t...requestHandlers,\n\t\t\t},\n\t\t\t{\n\t\t\t\t...simulatorClientDefaultOptions,\n\t\t\t\t...options,\n\t\t\t\tdebug,\n\t\t\t},\n\t\t)\n\n\t\t// Append client to window object\n\t\tif (debug) {\n\t\t\twindow.prismic ||= {}\n\t\t\twindow.prismic.sliceSimulator ||= {}\n\t\t\twindow.prismic.sliceSimulator.client ||= []\n\t\t\twindow.prismic.sliceSimulator.client.push(this)\n\t\t}\n\t}\n\n\t[ClientRequestType.Ping]: TransactionMethod<ClientTransactions[ClientRequestType.Ping]> =\n\t\tasync () => {\n\t\t\treturn await this.postFormattedRequest(ClientRequestType.Ping)\n\t\t};\n\n\t[ClientRequestType.SetSliceZone]: TransactionMethod<\n\t\tClientTransactions[ClientRequestType.SetSliceZone]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(ClientRequestType.SetSliceZone, data)\n\t};\n\n\t[ClientRequestType.ScrollToSlice]: TransactionMethod<\n\t\tClientTransactions[ClientRequestType.ScrollToSlice]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(ClientRequestType.ScrollToSlice, data)\n\t}\n}\n"],"mappings":";;;AAWA,MAAa,gCAAmE,EAC/E,iBAAiB,
|
|
1
|
+
{"version":3,"file":"SimulatorClient.js","names":[],"sources":["../src/SimulatorClient.ts"],"sourcesContent":["import type {\n\tAllChannelEmitterOptions,\n\tTransactionMethod,\n\tTransactionsHandlers,\n\tTransactionsMethods,\n} from \"./channel\"\nimport { ChannelEmitter } from \"./channel\"\nimport type { SimulatorAPIOptions } from \"./SimulatorAPI\"\nimport type { APITransactions, ClientTransactions } from \"./types\"\nimport { APIRequestType, ClientRequestType } from \"./types\"\n\nexport const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions> = {\n\trequestIDPrefix: \"client-\",\n}\n\nexport class SimulatorClient\n\textends ChannelEmitter<APITransactions, Partial<AllChannelEmitterOptions>, SimulatorAPIOptions>\n\timplements TransactionsMethods<ClientTransactions>\n{\n\tconstructor(\n\t\ttarget: HTMLIFrameElement,\n\t\trequestHandlers?: Partial<TransactionsHandlers<APITransactions>>,\n\t\toptions?: Partial<AllChannelEmitterOptions>,\n\t) {\n\t\t// True if `options.debug` is true or `debug=true` is among query parameters\n\t\tconst debug =\n\t\t\toptions?.debug || /[?&]debug=true/i.test(decodeURIComponent(window.location.search))\n\n\t\tsuper(\n\t\t\ttarget,\n\t\t\t{\n\t\t\t\t[APIRequestType.SetActiveSlice]: (_req, res) => {\n\t\t\t\t\treturn res.success()\n\t\t\t\t},\n\t\t\t\t[APIRequestType.SetSliceZoneSize]: (_req, res) => {\n\t\t\t\t\treturn res.success()\n\t\t\t\t},\n\t\t\t\t...requestHandlers,\n\t\t\t},\n\t\t\t{\n\t\t\t\t...simulatorClientDefaultOptions,\n\t\t\t\t...options,\n\t\t\t\tdebug,\n\t\t\t},\n\t\t)\n\n\t\t// Append client to window object\n\t\tif (debug) {\n\t\t\twindow.prismic ||= {}\n\t\t\twindow.prismic.sliceSimulator ||= {}\n\t\t\twindow.prismic.sliceSimulator.client ||= []\n\t\t\twindow.prismic.sliceSimulator.client.push(this)\n\t\t}\n\t}\n\n\t[ClientRequestType.Ping]: TransactionMethod<ClientTransactions[ClientRequestType.Ping]> =\n\t\tasync () => {\n\t\t\treturn await this.postFormattedRequest(ClientRequestType.Ping)\n\t\t};\n\n\t[ClientRequestType.SetSliceZone]: TransactionMethod<\n\t\tClientTransactions[ClientRequestType.SetSliceZone]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(ClientRequestType.SetSliceZone, data)\n\t};\n\n\t[ClientRequestType.ScrollToSlice]: TransactionMethod<\n\t\tClientTransactions[ClientRequestType.ScrollToSlice]\n\t> = async (data) => {\n\t\treturn await this.postFormattedRequest(ClientRequestType.ScrollToSlice, data)\n\t}\n}\n"],"mappings":";;;AAWA,MAAa,gCAAmE,EAC/E,iBAAiB,UAClB;AAEA,IAAa,kBAAb,cACS,eAET;CACC,YACC,QACA,iBACA,SACC;EAED,MAAM,QACL,SAAS,SAAS,kBAAkB,KAAK,mBAAmB,OAAO,SAAS,MAAM,CAAC;EAEpF,MACC,QACA;IACmC,oBAAA,MAAM,QAAQ;IAC/C,OAAO,IAAI,QAAQ;GACpB;IACoC,sBAAA,MAAM,QAAQ;IACjD,OAAO,IAAI,QAAQ;GACpB;GACA,GAAG;EACJ,GACA;GACC,GAAG;GACH,GAAG;GACH;EACD,CACD;EAGA,IAAI,OAAO;GACV,OAAO,YAAY,CAAC;GACpB,OAAO,QAAQ,mBAAmB,CAAC;GACnC,OAAO,QAAQ,eAAe,WAAW,CAAC;GAC1C,OAAO,QAAQ,eAAe,OAAO,KAAK,IAAI;EAC/C;CACD;CAEA,CAAA,UACC,YAAY;EACX,OAAO,MAAM,KAAK,qBAAA,MAA2C;CAC9D;CAED,CAAA,kBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,gBAAqD,IAAI;CAC5E;CAEA,CAAA,mBAEI,OAAO,SAAS;EACnB,OAAO,MAAM,KAAK,qBAAA,iBAAsD,IAAI;CAC7E;AACD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_errors = require("./errors.cjs");
|
|
2
2
|
const require_messages = require("./messages.cjs");
|
|
3
3
|
const require_ChannelNetwork = require("./ChannelNetwork.cjs");
|
|
4
|
-
const require_types = require("./types.cjs");
|
|
5
4
|
//#region src/channel/ChannelEmitter.ts
|
|
6
5
|
const channelEmitterDefaultOptions = {
|
|
7
6
|
connectTimeout: 2e4,
|
|
@@ -54,7 +53,7 @@ var ChannelEmitter = class extends require_ChannelNetwork.ChannelNetwork {
|
|
|
54
53
|
const receiverReadyCallback = async () => {
|
|
55
54
|
clearTimeout(receiverReadyTimeout);
|
|
56
55
|
this.channel = new MessageChannel();
|
|
57
|
-
const request = this.createRequestMessage(
|
|
56
|
+
const request = this.createRequestMessage("connect", receiverOptions);
|
|
58
57
|
const response = await this.postRequest(request, (request) => {
|
|
59
58
|
this._target.contentWindow.postMessage(request, "*", [this.channel.port2]);
|
|
60
59
|
});
|
|
@@ -82,7 +81,7 @@ var ChannelEmitter = class extends require_ChannelNetwork.ChannelNetwork {
|
|
|
82
81
|
if (require_messages.isRequestMessage(message)) {
|
|
83
82
|
if (this.options.debug) console.debug(event.data);
|
|
84
83
|
switch (message.type) {
|
|
85
|
-
case
|
|
84
|
+
case "ready":
|
|
86
85
|
this._receiverReady = message.requestID;
|
|
87
86
|
if (this._receiverReadyCallback) {
|
|
88
87
|
const receiverReadyCallbackPromise = this._receiverReadyCallback();
|
|
@@ -90,11 +89,9 @@ var ChannelEmitter = class extends require_ChannelNetwork.ChannelNetwork {
|
|
|
90
89
|
await receiverReadyCallbackPromise;
|
|
91
90
|
}
|
|
92
91
|
break;
|
|
93
|
-
default:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
break;
|
|
92
|
+
default: this.postResponse(require_messages.createErrorResponseMessage(message.requestID, void 0), (response) => {
|
|
93
|
+
event.source.postMessage(response, event.origin);
|
|
94
|
+
});
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
} catch (error) {
|
|
@@ -108,5 +105,6 @@ var ChannelEmitter = class extends require_ChannelNetwork.ChannelNetwork {
|
|
|
108
105
|
};
|
|
109
106
|
//#endregion
|
|
110
107
|
exports.ChannelEmitter = ChannelEmitter;
|
|
108
|
+
exports.channelEmitterDefaultOptions = channelEmitterDefaultOptions;
|
|
111
109
|
|
|
112
110
|
//# sourceMappingURL=ChannelEmitter.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelEmitter.cjs","names":["ChannelNetwork","ChannelNotSetError","ConnectionTimeoutError","InternalEmitterRequestType","createSuccessResponseMessage","validateMessage","isRequestMessage","InternalReceiverRequestType","createErrorResponseMessage","NotReadyError"],"sources":["../../src/channel/ChannelEmitter.ts"],"sourcesContent":["import type { ChannelNetworkOptions, PostRequestOptions } from \"./ChannelNetwork\"\nimport { ChannelNetwork } from \"./ChannelNetwork\"\nimport type { AllChannelReceiverOptions } from \"./ChannelReceiver\"\nimport { ChannelNotSetError, ConnectionTimeoutError, NotReadyError } from \"./errors\"\nimport {\n\tcreateErrorResponseMessage,\n\tcreateSuccessResponseMessage,\n\tisRequestMessage,\n\tvalidateMessage,\n} from \"./messages\"\nimport type {\n\tExtractSuccessResponseMessage,\n\tInternalEmitterTransactions,\n\tSuccessResponseMessage,\n\tTransactionsHandlers,\n\tUnknownRequestMessage,\n\tUnknownResponseMessage,\n\tUnknownTransaction,\n} from \"./types\"\nimport { InternalEmitterRequestType, InternalReceiverRequestType } from \"./types\"\n\nexport type ChannelEmitterOptions = {\n\tconnectTimeout: number\n}\n\nexport const channelEmitterDefaultOptions: ChannelEmitterOptions & Partial<ChannelNetworkOptions> =\n\t{\n\t\tconnectTimeout: 20000,\n\t\trequestIDPrefix: \"emitter-\",\n\t}\n\nexport type AllChannelEmitterOptions = ChannelEmitterOptions & ChannelNetworkOptions\n\nexport abstract class ChannelEmitter<\n\tTReceiverTransactions extends Record<string, UnknownTransaction> = Record<string, never>,\n\tTOptions extends Record<string, unknown> = Record<string, unknown>,\n\tTReceiverOptions extends Record<string, unknown> = Record<string, unknown>,\n> extends ChannelNetwork<TReceiverTransactions, ChannelEmitterOptions & TOptions> {\n\tprivate _target: HTMLIFrameElement\n\tprivate _channel: MessageChannel | null = null\n\tprotected get channel(): MessageChannel {\n\t\tif (!this._channel) {\n\t\t\tthrow new ChannelNotSetError()\n\t\t}\n\n\t\treturn this._channel\n\t}\n\tprotected set channel(channel: MessageChannel | null) {\n\t\tthis._channel = channel\n\n\t\t// Update port automatically\n\t\tif (this._channel) {\n\t\t\tthis.port = this._channel.port1\n\t\t} else {\n\t\t\tthis.port = null\n\t\t}\n\t}\n\tprivate _receiverReady = \"\"\n\tprivate _receiverReadyCallback: (() => Promise<void>) | null = null\n\tprivate _connected = false\n\tpublic get connected(): boolean {\n\t\treturn this._connected\n\t}\n\n\tconstructor(\n\t\ttarget: HTMLIFrameElement,\n\t\trequestHandlers: TransactionsHandlers<TReceiverTransactions>,\n\t\toptions: Partial<AllChannelEmitterOptions> & TOptions,\n\t) {\n\t\tsuper(requestHandlers, { ...channelEmitterDefaultOptions, ...options })\n\n\t\tthis._target = target\n\n\t\twindow.addEventListener(\"message\", (event) => {\n\t\t\tthis._onPublicMessage(event)\n\t\t})\n\t}\n\n\t/**\n\t * Initiates connection to receiver\n\t *\n\t * @param receiverOptions - Options to configure the receiver with\n\t * @param newOrigin - Indicates to the emitter that we're connecting to a new origin\n\t * @returns Success connect message\n\t */\n\tconnect(\n\t\treceiverOptions: InternalEmitterTransactions<\n\t\t\tAllChannelReceiverOptions & TReceiverOptions\n\t\t>[\"connect\"][\"request\"][\"data\"] = {},\n\t\tnewOrigin = false,\n\t): Promise<SuccessResponseMessage> {\n\t\t// Disconnect first\n\t\tthis.disconnect()\n\t\t// If changing origin we'll need to wait for receiver to be ready again\n\t\tif (newOrigin) {\n\t\t\tthis._receiverReady = \"\"\n\t\t}\n\n\t\t// Handshake promise\n\t\treturn new Promise<SuccessResponseMessage>((resolve, reject) => {\n\t\t\t// Wait for target to be loaded\n\t\t\tthis._target.addEventListener(\n\t\t\t\t\"load\",\n\t\t\t\t() => {\n\t\t\t\t\t// Throw if target doesn't allow access to content window\n\t\t\t\t\tif (!this._target.contentWindow) {\n\t\t\t\t\t\treturn reject(new Error(\"Target window is not available\"))\n\t\t\t\t\t}\n\n\t\t\t\t\tconst receiverReadyTimeout = setTimeout(() => {\n\t\t\t\t\t\treject(new ConnectionTimeoutError())\n\t\t\t\t\t}, this.options.connectTimeout)\n\n\t\t\t\t\t// Connect to target once ready\n\t\t\t\t\tconst receiverReadyCallback = async (): Promise<void> => {\n\t\t\t\t\t\t// Clear receiver ready timeout\n\t\t\t\t\t\tclearTimeout(receiverReadyTimeout)\n\n\t\t\t\t\t\t// Create new message channel (set up port automatically)\n\t\t\t\t\t\t// This is done here to prevent transferable objects neutering\n\t\t\t\t\t\t// when calling `connect()` multiple times\n\t\t\t\t\t\tthis.channel = new MessageChannel()\n\n\t\t\t\t\t\t// Conclude handshake by sending message channel port to target\n\t\t\t\t\t\tconst request = this.createRequestMessage(\n\t\t\t\t\t\t\tInternalEmitterRequestType.Connect,\n\t\t\t\t\t\t\treceiverOptions,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tconst response = await this.postRequest<\n\t\t\t\t\t\t\tInternalEmitterTransactions<\n\t\t\t\t\t\t\t\tAllChannelReceiverOptions & TReceiverOptions\n\t\t\t\t\t\t\t>[\"connect\"][\"request\"],\n\t\t\t\t\t\t\tInternalEmitterTransactions<\n\t\t\t\t\t\t\t\tAllChannelReceiverOptions & TReceiverOptions\n\t\t\t\t\t\t\t>[\"connect\"][\"response\"]\n\t\t\t\t\t\t>(request, (request) => {\n\t\t\t\t\t\t\t// Target content window is checked in previous statement\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\tthis._target.contentWindow!.postMessage(request, \"*\", [this.channel.port2])\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\t// Finish by aknowledging ready\n\t\t\t\t\t\tthis.postResponse(\n\t\t\t\t\t\t\tcreateSuccessResponseMessage(this._receiverReady, undefined),\n\t\t\t\t\t\t\t(response) => {\n\t\t\t\t\t\t\t\t// Target content window is checked in previous statement\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\t\tthis._target.contentWindow!.postMessage(response, \"*\")\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\t// If post request succeed, we're connected\n\t\t\t\t\t\tthis._connected = true\n\n\t\t\t\t\t\tresolve(response)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._receiverReady) {\n\t\t\t\t\t\t// If receiver is already ready, send port immediately\n\t\t\t\t\t\treceiverReadyCallback()\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Else wait for receiver to be ready\n\t\t\t\t\t\tthis._receiverReadyCallback = receiverReadyCallback\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t)\n\t\t})\n\t}\n\n\t/** Destroys current connection to receiver if any */\n\tdisconnect(): void {\n\t\tthis._connected = false\n\t\tthis.channel = null\n\t}\n\n\t/** Handles public messages */\n\tprivate async _onPublicMessage(event: MessageEvent<unknown>): Promise<void> {\n\t\t// Return is event is not from target\n\t\tif (event.source !== this._target.contentWindow) {\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tconst message = validateMessage(event.data)\n\n\t\t\tif (isRequestMessage(message)) {\n\t\t\t\tif (this.options.debug) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.debug(event.data)\n\t\t\t\t}\n\n\t\t\t\tswitch (message.type) {\n\t\t\t\t\tcase InternalReceiverRequestType.Ready:\n\t\t\t\t\t\tthis._receiverReady = message.requestID\n\n\t\t\t\t\t\t// If emitter is waiting for receiver to be ready\n\t\t\t\t\t\tif (this._receiverReadyCallback) {\n\t\t\t\t\t\t\t// We don't await the promise directly as we need to clear the callback first\n\t\t\t\t\t\t\tconst receiverReadyCallbackPromise = this._receiverReadyCallback()\n\n\t\t\t\t\t\t\tthis._receiverReadyCallback = null\n\n\t\t\t\t\t\t\tawait receiverReadyCallbackPromise\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthis.postResponse(\n\t\t\t\t\t\t\tcreateErrorResponseMessage(message.requestID, undefined),\n\t\t\t\t\t\t\t(response) => {\n\t\t\t\t\t\t\t\t;(event.source as WindowProxy).postMessage(response, event.origin)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No response messages are expected on public channel\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof TypeError) {\n\t\t\t\t// Ignore unknown messages\n\t\t\t} else {\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected postFormattedRequest<\n\t\tTRequest extends UnknownRequestMessage,\n\t\tTResponse extends UnknownResponseMessage,\n\t>(\n\t\ttype: TRequest[\"type\"],\n\t\tdata?: TRequest[\"data\"],\n\t\toptions: PostRequestOptions = {},\n\t): Promise<ExtractSuccessResponseMessage<TResponse>> {\n\t\tif (!this._connected) {\n\t\t\tthrow new NotReadyError(\"Emitter is not connected, use `ChannelEmitter.connect()` first\")\n\t\t}\n\n\t\treturn this.postRequest(this.createRequestMessage(type, data), undefined, options)\n\t}\n}\n"],"mappings":";;;;;AAyBA,MAAa,+BACZ;CACC,gBAAgB;CAChB,iBAAiB;CACjB;AAIF,IAAsB,iBAAtB,cAIUA,uBAAAA,eAAwE;CACjF;CACA,WAA0C;CAC1C,IAAc,UAA0B;AACvC,MAAI,CAAC,KAAK,SACT,OAAM,IAAIC,eAAAA,oBAAoB;AAG/B,SAAO,KAAK;;CAEb,IAAc,QAAQ,SAAgC;AACrD,OAAK,WAAW;AAGhB,MAAI,KAAK,SACR,MAAK,OAAO,KAAK,SAAS;MAE1B,MAAK,OAAO;;CAGd,iBAAyB;CACzB,yBAA+D;CAC/D,aAAqB;CACrB,IAAW,YAAqB;AAC/B,SAAO,KAAK;;CAGb,YACC,QACA,iBACA,SACC;AACD,QAAM,iBAAiB;GAAE,GAAG;GAA8B,GAAG;GAAS,CAAC;AAEvE,OAAK,UAAU;AAEf,SAAO,iBAAiB,YAAY,UAAU;AAC7C,QAAK,iBAAiB,MAAM;IAC3B;;;;;;;;;CAUH,QACC,kBAEkC,EAAE,EACpC,YAAY,OACsB;AAElC,OAAK,YAAY;AAEjB,MAAI,UACH,MAAK,iBAAiB;AAIvB,SAAO,IAAI,SAAiC,SAAS,WAAW;AAE/D,QAAK,QAAQ,iBACZ,cACM;AAEL,QAAI,CAAC,KAAK,QAAQ,cACjB,QAAO,uBAAO,IAAI,MAAM,iCAAiC,CAAC;IAG3D,MAAM,uBAAuB,iBAAiB;AAC7C,YAAO,IAAIC,eAAAA,wBAAwB,CAAC;OAClC,KAAK,QAAQ,eAAe;IAG/B,MAAM,wBAAwB,YAA2B;AAExD,kBAAa,qBAAqB;AAKlC,UAAK,UAAU,IAAI,gBAAgB;KAGnC,MAAM,UAAU,KAAK,qBACpBC,cAAAA,2BAA2B,SAC3B,gBACA;KACD,MAAM,WAAW,MAAM,KAAK,YAO1B,UAAU,YAAY;AAGvB,WAAK,QAAQ,cAAe,YAAY,SAAS,KAAK,CAAC,KAAK,QAAQ,MAAM,CAAC;OAC1E;AAGF,UAAK,aACJC,iBAAAA,6BAA6B,KAAK,gBAAgB,KAAA,EAAU,GAC3D,aAAa;AAGb,WAAK,QAAQ,cAAe,YAAY,UAAU,IAAI;OAEvD;AAGD,UAAK,aAAa;AAElB,aAAQ,SAAS;;AAGlB,QAAI,KAAK,eAER,wBAAuB;QAGvB,MAAK,yBAAyB;MAGhC,EAAE,MAAM,MAAM,CACd;IACA;;;CAIH,aAAmB;AAClB,OAAK,aAAa;AAClB,OAAK,UAAU;;;CAIhB,MAAc,iBAAiB,OAA6C;AAE3E,MAAI,MAAM,WAAW,KAAK,QAAQ,cACjC;AAGD,MAAI;GACH,MAAM,UAAUC,iBAAAA,gBAAgB,MAAM,KAAK;AAE3C,OAAIC,iBAAAA,iBAAiB,QAAQ,EAAE;AAC9B,QAAI,KAAK,QAAQ,MAEhB,SAAQ,MAAM,MAAM,KAAK;AAG1B,YAAQ,QAAQ,MAAhB;KACC,KAAKC,cAAAA,4BAA4B;AAChC,WAAK,iBAAiB,QAAQ;AAG9B,UAAI,KAAK,wBAAwB;OAEhC,MAAM,+BAA+B,KAAK,wBAAwB;AAElE,YAAK,yBAAyB;AAE9B,aAAM;;AAEP;KAED;AACC,WAAK,aACJC,iBAAAA,2BAA2B,QAAQ,WAAW,KAAA,EAAU,GACvD,aAAa;AACX,aAAM,OAAuB,YAAY,UAAU,MAAM,OAAO;QAEnE;AACD;;;WAKK,OAAO;AACf,OAAI,iBAAiB,WAAW,OAG/B,OAAM;;;CAKT,qBAIC,MACA,MACA,UAA8B,EAAE,EACoB;AACpD,MAAI,CAAC,KAAK,WACT,OAAM,IAAIC,eAAAA,cAAc,iEAAiE;AAG1F,SAAO,KAAK,YAAY,KAAK,qBAAqB,MAAM,KAAK,EAAE,KAAA,GAAW,QAAQ"}
|
|
1
|
+
{"version":3,"file":"ChannelEmitter.cjs","names":["ChannelNetwork","ChannelNotSetError","ConnectionTimeoutError","createSuccessResponseMessage","validateMessage","isRequestMessage","createErrorResponseMessage","NotReadyError"],"sources":["../../src/channel/ChannelEmitter.ts"],"sourcesContent":["import type { ChannelNetworkOptions, PostRequestOptions } from \"./ChannelNetwork\"\nimport { ChannelNetwork } from \"./ChannelNetwork\"\nimport type { AllChannelReceiverOptions } from \"./ChannelReceiver\"\nimport { ChannelNotSetError, ConnectionTimeoutError, NotReadyError } from \"./errors\"\nimport {\n\tcreateErrorResponseMessage,\n\tcreateSuccessResponseMessage,\n\tisRequestMessage,\n\tvalidateMessage,\n} from \"./messages\"\nimport type {\n\tExtractSuccessResponseMessage,\n\tInternalEmitterTransactions,\n\tSuccessResponseMessage,\n\tTransactionsHandlers,\n\tUnknownRequestMessage,\n\tUnknownResponseMessage,\n\tUnknownTransaction,\n} from \"./types\"\nimport { InternalEmitterRequestType, InternalReceiverRequestType } from \"./types\"\n\nexport type ChannelEmitterOptions = {\n\tconnectTimeout: number\n}\n\nexport const channelEmitterDefaultOptions: ChannelEmitterOptions & Partial<ChannelNetworkOptions> =\n\t{\n\t\tconnectTimeout: 20000,\n\t\trequestIDPrefix: \"emitter-\",\n\t}\n\nexport type AllChannelEmitterOptions = ChannelEmitterOptions & ChannelNetworkOptions\n\nexport abstract class ChannelEmitter<\n\tTReceiverTransactions extends Record<string, UnknownTransaction> = Record<string, never>,\n\tTOptions extends Record<string, unknown> = Record<string, unknown>,\n\tTReceiverOptions extends Record<string, unknown> = Record<string, unknown>,\n> extends ChannelNetwork<TReceiverTransactions, ChannelEmitterOptions & TOptions> {\n\tprivate _target: HTMLIFrameElement\n\tprivate _channel: MessageChannel | null = null\n\tprotected get channel(): MessageChannel {\n\t\tif (!this._channel) {\n\t\t\tthrow new ChannelNotSetError()\n\t\t}\n\n\t\treturn this._channel\n\t}\n\tprotected set channel(channel: MessageChannel | null) {\n\t\tthis._channel = channel\n\n\t\t// Update port automatically\n\t\tif (this._channel) {\n\t\t\tthis.port = this._channel.port1\n\t\t} else {\n\t\t\tthis.port = null\n\t\t}\n\t}\n\tprivate _receiverReady = \"\"\n\tprivate _receiverReadyCallback: (() => Promise<void>) | null = null\n\tprivate _connected = false\n\tpublic get connected(): boolean {\n\t\treturn this._connected\n\t}\n\n\tconstructor(\n\t\ttarget: HTMLIFrameElement,\n\t\trequestHandlers: TransactionsHandlers<TReceiverTransactions>,\n\t\toptions: Partial<AllChannelEmitterOptions> & TOptions,\n\t) {\n\t\tsuper(requestHandlers, { ...channelEmitterDefaultOptions, ...options })\n\n\t\tthis._target = target\n\n\t\twindow.addEventListener(\"message\", (event) => {\n\t\t\tthis._onPublicMessage(event)\n\t\t})\n\t}\n\n\t/**\n\t * Initiates connection to receiver\n\t *\n\t * @param receiverOptions - Options to configure the receiver with\n\t * @param newOrigin - Indicates to the emitter that we're connecting to a new origin\n\t * @returns Success connect message\n\t */\n\tconnect(\n\t\treceiverOptions: InternalEmitterTransactions<\n\t\t\tAllChannelReceiverOptions & TReceiverOptions\n\t\t>[\"connect\"][\"request\"][\"data\"] = {},\n\t\tnewOrigin = false,\n\t): Promise<SuccessResponseMessage> {\n\t\t// Disconnect first\n\t\tthis.disconnect()\n\t\t// If changing origin we'll need to wait for receiver to be ready again\n\t\tif (newOrigin) {\n\t\t\tthis._receiverReady = \"\"\n\t\t}\n\n\t\t// Handshake promise\n\t\treturn new Promise<SuccessResponseMessage>((resolve, reject) => {\n\t\t\t// Wait for target to be loaded\n\t\t\tthis._target.addEventListener(\n\t\t\t\t\"load\",\n\t\t\t\t() => {\n\t\t\t\t\t// Throw if target doesn't allow access to content window\n\t\t\t\t\tif (!this._target.contentWindow) {\n\t\t\t\t\t\treturn reject(new Error(\"Target window is not available\"))\n\t\t\t\t\t}\n\n\t\t\t\t\tconst receiverReadyTimeout = setTimeout(() => {\n\t\t\t\t\t\treject(new ConnectionTimeoutError())\n\t\t\t\t\t}, this.options.connectTimeout)\n\n\t\t\t\t\t// Connect to target once ready\n\t\t\t\t\tconst receiverReadyCallback = async (): Promise<void> => {\n\t\t\t\t\t\t// Clear receiver ready timeout\n\t\t\t\t\t\tclearTimeout(receiverReadyTimeout)\n\n\t\t\t\t\t\t// Create new message channel (set up port automatically)\n\t\t\t\t\t\t// This is done here to prevent transferable objects neutering\n\t\t\t\t\t\t// when calling `connect()` multiple times\n\t\t\t\t\t\tthis.channel = new MessageChannel()\n\n\t\t\t\t\t\t// Conclude handshake by sending message channel port to target\n\t\t\t\t\t\tconst request = this.createRequestMessage(\n\t\t\t\t\t\t\tInternalEmitterRequestType.Connect,\n\t\t\t\t\t\t\treceiverOptions,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tconst response = await this.postRequest<\n\t\t\t\t\t\t\tInternalEmitterTransactions<\n\t\t\t\t\t\t\t\tAllChannelReceiverOptions & TReceiverOptions\n\t\t\t\t\t\t\t>[\"connect\"][\"request\"],\n\t\t\t\t\t\t\tInternalEmitterTransactions<\n\t\t\t\t\t\t\t\tAllChannelReceiverOptions & TReceiverOptions\n\t\t\t\t\t\t\t>[\"connect\"][\"response\"]\n\t\t\t\t\t\t>(request, (request) => {\n\t\t\t\t\t\t\t// Target content window is checked in previous statement\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\tthis._target.contentWindow!.postMessage(request, \"*\", [this.channel.port2])\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\t// Finish by aknowledging ready\n\t\t\t\t\t\tthis.postResponse(\n\t\t\t\t\t\t\tcreateSuccessResponseMessage(this._receiverReady, undefined),\n\t\t\t\t\t\t\t(response) => {\n\t\t\t\t\t\t\t\t// Target content window is checked in previous statement\n\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\t\tthis._target.contentWindow!.postMessage(response, \"*\")\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\t// If post request succeed, we're connected\n\t\t\t\t\t\tthis._connected = true\n\n\t\t\t\t\t\tresolve(response)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (this._receiverReady) {\n\t\t\t\t\t\t// If receiver is already ready, send port immediately\n\t\t\t\t\t\treceiverReadyCallback()\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Else wait for receiver to be ready\n\t\t\t\t\t\tthis._receiverReadyCallback = receiverReadyCallback\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ once: true },\n\t\t\t)\n\t\t})\n\t}\n\n\t/** Destroys current connection to receiver if any */\n\tdisconnect(): void {\n\t\tthis._connected = false\n\t\tthis.channel = null\n\t}\n\n\t/** Handles public messages */\n\tprivate async _onPublicMessage(event: MessageEvent<unknown>): Promise<void> {\n\t\t// Return is event is not from target\n\t\tif (event.source !== this._target.contentWindow) {\n\t\t\treturn\n\t\t}\n\n\t\ttry {\n\t\t\tconst message = validateMessage(event.data)\n\n\t\t\tif (isRequestMessage(message)) {\n\t\t\t\tif (this.options.debug) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.debug(event.data)\n\t\t\t\t}\n\n\t\t\t\tswitch (message.type) {\n\t\t\t\t\tcase InternalReceiverRequestType.Ready:\n\t\t\t\t\t\tthis._receiverReady = message.requestID\n\n\t\t\t\t\t\t// If emitter is waiting for receiver to be ready\n\t\t\t\t\t\tif (this._receiverReadyCallback) {\n\t\t\t\t\t\t\t// We don't await the promise directly as we need to clear the callback first\n\t\t\t\t\t\t\tconst receiverReadyCallbackPromise = this._receiverReadyCallback()\n\n\t\t\t\t\t\t\tthis._receiverReadyCallback = null\n\n\t\t\t\t\t\t\tawait receiverReadyCallbackPromise\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthis.postResponse(\n\t\t\t\t\t\t\tcreateErrorResponseMessage(message.requestID, undefined),\n\t\t\t\t\t\t\t(response) => {\n\t\t\t\t\t\t\t\t;(event.source as WindowProxy).postMessage(response, event.origin)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// No response messages are expected on public channel\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof TypeError) {\n\t\t\t\t// Ignore unknown messages\n\t\t\t} else {\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected postFormattedRequest<\n\t\tTRequest extends UnknownRequestMessage,\n\t\tTResponse extends UnknownResponseMessage,\n\t>(\n\t\ttype: TRequest[\"type\"],\n\t\tdata?: TRequest[\"data\"],\n\t\toptions: PostRequestOptions = {},\n\t): Promise<ExtractSuccessResponseMessage<TResponse>> {\n\t\tif (!this._connected) {\n\t\t\tthrow new NotReadyError(\"Emitter is not connected, use `ChannelEmitter.connect()` first\")\n\t\t}\n\n\t\treturn this.postRequest(this.createRequestMessage(type, data), undefined, options)\n\t}\n}\n"],"mappings":";;;;AAyBA,MAAa,+BACZ;CACC,gBAAgB;CAChB,iBAAiB;AAClB;AAID,IAAsB,iBAAtB,cAIUA,uBAAAA,eAAwE;CACjF;CACA,WAA0C;CAC1C,IAAc,UAA0B;EACvC,IAAI,CAAC,KAAK,UACT,MAAM,IAAIC,eAAAA,mBAAmB;EAG9B,OAAO,KAAK;CACb;CACA,IAAc,QAAQ,SAAgC;EACrD,KAAK,WAAW;EAGhB,IAAI,KAAK,UACR,KAAK,OAAO,KAAK,SAAS;OAE1B,KAAK,OAAO;CAEd;CACA,iBAAyB;CACzB,yBAA+D;CAC/D,aAAqB;CACrB,IAAW,YAAqB;EAC/B,OAAO,KAAK;CACb;CAEA,YACC,QACA,iBACA,SACC;EACD,MAAM,iBAAiB;GAAE,GAAG;GAA8B,GAAG;EAAQ,CAAC;EAEtE,KAAK,UAAU;EAEf,OAAO,iBAAiB,YAAY,UAAU;GAC7C,KAAK,iBAAiB,KAAK;EAC5B,CAAC;CACF;;;;;;;;CASA,QACC,kBAEkC,CAAC,GACnC,YAAY,OACsB;EAElC,KAAK,WAAW;EAEhB,IAAI,WACH,KAAK,iBAAiB;EAIvB,OAAO,IAAI,SAAiC,SAAS,WAAW;GAE/D,KAAK,QAAQ,iBACZ,cACM;IAEL,IAAI,CAAC,KAAK,QAAQ,eACjB,OAAO,uBAAO,IAAI,MAAM,gCAAgC,CAAC;IAG1D,MAAM,uBAAuB,iBAAiB;KAC7C,OAAO,IAAIC,eAAAA,uBAAuB,CAAC;IACpC,GAAG,KAAK,QAAQ,cAAc;IAG9B,MAAM,wBAAwB,YAA2B;KAExD,aAAa,oBAAoB;KAKjC,KAAK,UAAU,IAAI,eAAe;KAGlC,MAAM,UAAU,KAAK,qBAAA,WAEpB,eACD;KACA,MAAM,WAAW,MAAM,KAAK,YAO1B,UAAU,YAAY;MAGvB,KAAK,QAAQ,cAAe,YAAY,SAAS,KAAK,CAAC,KAAK,QAAQ,KAAK,CAAC;KAC3E,CAAC;KAGD,KAAK,aACJC,iBAAAA,6BAA6B,KAAK,gBAAgB,KAAA,CAAS,IAC1D,aAAa;MAGb,KAAK,QAAQ,cAAe,YAAY,UAAU,GAAG;KACtD,CACD;KAGA,KAAK,aAAa;KAElB,QAAQ,QAAQ;IACjB;IAEA,IAAI,KAAK,gBAER,sBAAsB;SAGtB,KAAK,yBAAyB;GAEhC,GACA,EAAE,MAAM,KAAK,CACd;EACD,CAAC;CACF;;CAGA,aAAmB;EAClB,KAAK,aAAa;EAClB,KAAK,UAAU;CAChB;;CAGA,MAAc,iBAAiB,OAA6C;EAE3E,IAAI,MAAM,WAAW,KAAK,QAAQ,eACjC;EAGD,IAAI;GACH,MAAM,UAAUC,iBAAAA,gBAAgB,MAAM,IAAI;GAE1C,IAAIC,iBAAAA,iBAAiB,OAAO,GAAG;IAC9B,IAAI,KAAK,QAAQ,OAEhB,QAAQ,MAAM,MAAM,IAAI;IAGzB,QAAQ,QAAQ,MAAhB;KACC,KAAA;MACC,KAAK,iBAAiB,QAAQ;MAG9B,IAAI,KAAK,wBAAwB;OAEhC,MAAM,+BAA+B,KAAK,uBAAuB;OAEjE,KAAK,yBAAyB;OAE9B,MAAM;MACP;MACA;KAED,SACC,KAAK,aACJC,iBAAAA,2BAA2B,QAAQ,WAAW,KAAA,CAAS,IACtD,aAAa;MACZ,MAAO,OAAuB,YAAY,UAAU,MAAM,MAAM;KAClE,CACD;IAEF;GACD;EAGD,SAAS,OAAO;GACf,IAAI,iBAAiB,WAAW,CAEhC,OACC,MAAM;EAER;CACD;CAEA,qBAIC,MACA,MACA,UAA8B,CAAC,GACqB;EACpD,IAAI,CAAC,KAAK,YACT,MAAM,IAAIC,eAAAA,cAAc,gEAAgE;EAGzF,OAAO,KAAK,YAAY,KAAK,qBAAqB,MAAM,IAAI,GAAG,KAAA,GAAW,OAAO;CAClF;AACD"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ExtractSuccessResponseMessage, InternalEmitterTransactions, SuccessResponseMessage, TransactionsHandlers, UnknownRequestMessage, UnknownResponseMessage, UnknownTransaction } from "./types.cjs";
|
|
2
2
|
import { ChannelNetwork, ChannelNetworkOptions, PostRequestOptions } from "./ChannelNetwork.cjs";
|
|
3
3
|
import { AllChannelReceiverOptions } from "./ChannelReceiver.cjs";
|
|
4
|
-
|
|
5
4
|
//#region src/channel/ChannelEmitter.d.ts
|
|
6
|
-
type ChannelEmitterOptions = {
|
|
5
|
+
export type ChannelEmitterOptions = {
|
|
7
6
|
connectTimeout: number;
|
|
8
7
|
};
|
|
9
|
-
type AllChannelEmitterOptions = ChannelEmitterOptions & ChannelNetworkOptions;
|
|
10
|
-
declare abstract class ChannelEmitter<TReceiverTransactions extends Record<string, UnknownTransaction> = Record<string, never>, TOptions extends Record<string, unknown> = Record<string, unknown>, TReceiverOptions extends Record<string, unknown> = Record<string, unknown>> extends ChannelNetwork<TReceiverTransactions, ChannelEmitterOptions & TOptions> {
|
|
8
|
+
export type AllChannelEmitterOptions = ChannelEmitterOptions & ChannelNetworkOptions;
|
|
9
|
+
export declare abstract class ChannelEmitter<TReceiverTransactions extends Record<string, UnknownTransaction> = Record<string, never>, TOptions extends Record<string, unknown> = Record<string, unknown>, TReceiverOptions extends Record<string, unknown> = Record<string, unknown>> extends ChannelNetwork<TReceiverTransactions, ChannelEmitterOptions & TOptions> {
|
|
11
10
|
private _target;
|
|
12
11
|
private _channel;
|
|
13
12
|
protected get channel(): MessageChannel;
|
|
@@ -32,5 +31,4 @@ declare abstract class ChannelEmitter<TReceiverTransactions extends Record<strin
|
|
|
32
31
|
protected postFormattedRequest<TRequest extends UnknownRequestMessage, TResponse extends UnknownResponseMessage>(type: TRequest["type"], data?: TRequest["data"], options?: PostRequestOptions): Promise<ExtractSuccessResponseMessage<TResponse>>;
|
|
33
32
|
}
|
|
34
33
|
//#endregion
|
|
35
|
-
export { AllChannelEmitterOptions, ChannelEmitter };
|
|
36
34
|
//# sourceMappingURL=ChannelEmitter.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelEmitter.d.cts","names":[],"sources":["../../src/channel/ChannelEmitter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChannelEmitter.d.cts","names":[],"sources":["../../src/channel/ChannelEmitter.ts"],"mappings":";;;;YAqBY;EACX;;YASW,2BAA2B,wBAAwB;8BAEzC,eACrB,8BAA8B,eAAe,sBAAsB,uBACnE,iBAAiB,0BAA0B,yBAC3C,yBAAyB,0BAA0B,iCAC1C,eAAe,uBAAuB,wBAAwB;UAC/D;UACA;gBACM,WAAW;gBAOX,QAAQ,SAAS;UAUvB;UACA;UACA;MACG;EAIX,YACC,QAAQ,mBACR,iBAAiB,qBAAqB,wBACtC,SAAS,QAAQ,4BAA4B;;;;;;;;EAkB9C,QACC,kBAAiB,4BAChB,4BAA4B,iDAE7B,sBACE,QAAQ;;EAiFX;;UAMc;YAmDJ,qBACT,iBAAiB,uBACjB,kBAAkB,wBAElB,MAAM,kBACN,OAAO,kBACP,UAAS,qBACP,QAAQ,8BAA8B"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ExtractSuccessResponseMessage, InternalEmitterTransactions, SuccessResponseMessage, TransactionsHandlers, UnknownRequestMessage, UnknownResponseMessage, UnknownTransaction } from "./types.js";
|
|
2
2
|
import { ChannelNetwork, ChannelNetworkOptions, PostRequestOptions } from "./ChannelNetwork.js";
|
|
3
3
|
import { AllChannelReceiverOptions } from "./ChannelReceiver.js";
|
|
4
|
-
|
|
5
4
|
//#region src/channel/ChannelEmitter.d.ts
|
|
6
|
-
type ChannelEmitterOptions = {
|
|
5
|
+
export type ChannelEmitterOptions = {
|
|
7
6
|
connectTimeout: number;
|
|
8
7
|
};
|
|
9
|
-
type AllChannelEmitterOptions = ChannelEmitterOptions & ChannelNetworkOptions;
|
|
10
|
-
declare abstract class ChannelEmitter<TReceiverTransactions extends Record<string, UnknownTransaction> = Record<string, never>, TOptions extends Record<string, unknown> = Record<string, unknown>, TReceiverOptions extends Record<string, unknown> = Record<string, unknown>> extends ChannelNetwork<TReceiverTransactions, ChannelEmitterOptions & TOptions> {
|
|
8
|
+
export type AllChannelEmitterOptions = ChannelEmitterOptions & ChannelNetworkOptions;
|
|
9
|
+
export declare abstract class ChannelEmitter<TReceiverTransactions extends Record<string, UnknownTransaction> = Record<string, never>, TOptions extends Record<string, unknown> = Record<string, unknown>, TReceiverOptions extends Record<string, unknown> = Record<string, unknown>> extends ChannelNetwork<TReceiverTransactions, ChannelEmitterOptions & TOptions> {
|
|
11
10
|
private _target;
|
|
12
11
|
private _channel;
|
|
13
12
|
protected get channel(): MessageChannel;
|
|
@@ -32,5 +31,4 @@ declare abstract class ChannelEmitter<TReceiverTransactions extends Record<strin
|
|
|
32
31
|
protected postFormattedRequest<TRequest extends UnknownRequestMessage, TResponse extends UnknownResponseMessage>(type: TRequest["type"], data?: TRequest["data"], options?: PostRequestOptions): Promise<ExtractSuccessResponseMessage<TResponse>>;
|
|
33
32
|
}
|
|
34
33
|
//#endregion
|
|
35
|
-
export { AllChannelEmitterOptions, ChannelEmitter };
|
|
36
34
|
//# sourceMappingURL=ChannelEmitter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChannelEmitter.d.ts","names":[],"sources":["../../src/channel/ChannelEmitter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChannelEmitter.d.ts","names":[],"sources":["../../src/channel/ChannelEmitter.ts"],"mappings":";;;;YAqBY;EACX;;YASW,2BAA2B,wBAAwB;8BAEzC,eACrB,8BAA8B,eAAe,sBAAsB,uBACnE,iBAAiB,0BAA0B,yBAC3C,yBAAyB,0BAA0B,iCAC1C,eAAe,uBAAuB,wBAAwB;UAC/D;UACA;gBACM,WAAW;gBAOX,QAAQ,SAAS;UAUvB;UACA;UACA;MACG;EAIX,YACC,QAAQ,mBACR,iBAAiB,qBAAqB,wBACtC,SAAS,QAAQ,4BAA4B;;;;;;;;EAkB9C,QACC,kBAAiB,4BAChB,4BAA4B,iDAE7B,sBACE,QAAQ;;EAiFX;;UAMc;YAmDJ,qBACT,iBAAiB,uBACjB,kBAAkB,wBAElB,MAAM,kBACN,OAAO,kBACP,UAAS,qBACP,QAAQ,8BAA8B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ChannelNotSetError, ConnectionTimeoutError, NotReadyError } from "./errors.js";
|
|
2
2
|
import { createErrorResponseMessage, createSuccessResponseMessage, isRequestMessage, validateMessage } from "./messages.js";
|
|
3
3
|
import { ChannelNetwork } from "./ChannelNetwork.js";
|
|
4
|
-
import { InternalEmitterRequestType, InternalReceiverRequestType } from "./types.js";
|
|
5
4
|
//#region src/channel/ChannelEmitter.ts
|
|
6
5
|
const channelEmitterDefaultOptions = {
|
|
7
6
|
connectTimeout: 2e4,
|
|
@@ -54,7 +53,7 @@ var ChannelEmitter = class extends ChannelNetwork {
|
|
|
54
53
|
const receiverReadyCallback = async () => {
|
|
55
54
|
clearTimeout(receiverReadyTimeout);
|
|
56
55
|
this.channel = new MessageChannel();
|
|
57
|
-
const request = this.createRequestMessage(
|
|
56
|
+
const request = this.createRequestMessage("connect", receiverOptions);
|
|
58
57
|
const response = await this.postRequest(request, (request) => {
|
|
59
58
|
this._target.contentWindow.postMessage(request, "*", [this.channel.port2]);
|
|
60
59
|
});
|
|
@@ -82,7 +81,7 @@ var ChannelEmitter = class extends ChannelNetwork {
|
|
|
82
81
|
if (isRequestMessage(message)) {
|
|
83
82
|
if (this.options.debug) console.debug(event.data);
|
|
84
83
|
switch (message.type) {
|
|
85
|
-
case
|
|
84
|
+
case "ready":
|
|
86
85
|
this._receiverReady = message.requestID;
|
|
87
86
|
if (this._receiverReadyCallback) {
|
|
88
87
|
const receiverReadyCallbackPromise = this._receiverReadyCallback();
|
|
@@ -90,11 +89,9 @@ var ChannelEmitter = class extends ChannelNetwork {
|
|
|
90
89
|
await receiverReadyCallbackPromise;
|
|
91
90
|
}
|
|
92
91
|
break;
|
|
93
|
-
default:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
break;
|
|
92
|
+
default: this.postResponse(createErrorResponseMessage(message.requestID, void 0), (response) => {
|
|
93
|
+
event.source.postMessage(response, event.origin);
|
|
94
|
+
});
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
} catch (error) {
|
|
@@ -107,6 +104,6 @@ var ChannelEmitter = class extends ChannelNetwork {
|
|
|
107
104
|
}
|
|
108
105
|
};
|
|
109
106
|
//#endregion
|
|
110
|
-
export { ChannelEmitter };
|
|
107
|
+
export { ChannelEmitter, channelEmitterDefaultOptions };
|
|
111
108
|
|
|
112
109
|
//# sourceMappingURL=ChannelEmitter.js.map
|