@prismicio/simulator 0.1.4 → 0.2.0
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/README.md +7 -18
- package/dist/SimulatorAPI.cjs +38 -46
- package/dist/SimulatorAPI.cjs.map +1 -1
- package/dist/SimulatorAPI.d.cts +18 -0
- package/dist/SimulatorAPI.d.ts +16 -10
- package/dist/SimulatorAPI.js +37 -46
- package/dist/SimulatorAPI.js.map +1 -1
- package/dist/SimulatorClient.cjs +41 -51
- package/dist/SimulatorClient.cjs.map +1 -1
- package/dist/SimulatorClient.d.cts +16 -0
- package/dist/SimulatorClient.d.ts +15 -9
- package/dist/SimulatorClient.js +40 -51
- package/dist/SimulatorClient.js.map +1 -1
- package/dist/channel/ChannelEmitter.cjs +112 -143
- package/dist/channel/ChannelEmitter.cjs.map +1 -1
- package/dist/channel/ChannelEmitter.d.cts +38 -0
- package/dist/channel/ChannelEmitter.d.ts +36 -36
- package/dist/channel/ChannelEmitter.js +110 -141
- package/dist/channel/ChannelEmitter.js.map +1 -1
- package/dist/channel/ChannelNetwork.cjs +81 -109
- package/dist/channel/ChannelNetwork.cjs.map +1 -1
- package/dist/channel/ChannelNetwork.d.cts +28 -0
- package/dist/channel/ChannelNetwork.d.ts +25 -21
- package/dist/channel/ChannelNetwork.js +81 -109
- package/dist/channel/ChannelNetwork.js.map +1 -1
- package/dist/channel/ChannelReceiver.cjs +69 -92
- package/dist/channel/ChannelReceiver.cjs.map +1 -1
- package/dist/channel/ChannelReceiver.d.cts +20 -0
- package/dist/channel/ChannelReceiver.d.ts +18 -18
- package/dist/channel/ChannelReceiver.js +67 -90
- package/dist/channel/ChannelReceiver.js.map +1 -1
- package/dist/channel/errors.cjs +41 -46
- package/dist/channel/errors.cjs.map +1 -1
- package/dist/channel/errors.d.cts +28 -0
- package/dist/channel/errors.d.ts +22 -19
- package/dist/channel/errors.js +40 -52
- package/dist/channel/errors.js.map +1 -1
- package/dist/channel/messages.cjs +48 -43
- package/dist/channel/messages.cjs.map +1 -1
- package/dist/channel/messages.d.cts +12 -0
- package/dist/channel/messages.d.ts +12 -10
- package/dist/channel/messages.js +50 -53
- package/dist/channel/messages.js.map +1 -1
- package/dist/channel/types.cjs +15 -11
- package/dist/channel/types.cjs.map +1 -1
- package/dist/channel/types.d.cts +53 -0
- package/dist/channel/types.d.ts +42 -50
- package/dist/channel/types.js +13 -13
- package/dist/channel/types.js.map +1 -1
- package/dist/globalExtensions.d.cts +15 -0
- package/dist/globalExtensions.d.ts +13 -10
- package/dist/index.cjs +24 -33
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +5 -25
- package/dist/kit/SimulatorManager.cjs +106 -137
- package/dist/kit/SimulatorManager.cjs.map +1 -1
- package/dist/kit/SimulatorManager.d.cts +19 -0
- package/dist/kit/SimulatorManager.d.ts +16 -12
- package/dist/kit/SimulatorManager.js +103 -134
- package/dist/kit/SimulatorManager.js.map +1 -1
- package/dist/kit/State.cjs +82 -80
- package/dist/kit/State.cjs.map +1 -1
- package/dist/kit/State.d.cts +29 -0
- package/dist/kit/State.d.ts +26 -22
- package/dist/kit/State.js +80 -78
- package/dist/kit/State.js.map +1 -1
- package/dist/kit/domHelpers.cjs +25 -37
- package/dist/kit/domHelpers.cjs.map +1 -1
- package/dist/kit/domHelpers.d.cts +11 -0
- package/dist/kit/domHelpers.d.ts +10 -8
- package/dist/kit/domHelpers.js +25 -43
- package/dist/kit/domHelpers.js.map +1 -1
- package/dist/kit/eventHandlers.cjs +11 -9
- package/dist/kit/eventHandlers.cjs.map +1 -1
- package/dist/kit/eventHandlers.d.cts +8 -0
- package/dist/kit/eventHandlers.d.ts +7 -3
- package/dist/kit/eventHandlers.js +11 -11
- package/dist/kit/eventHandlers.js.map +1 -1
- package/dist/kit/getDefault.cjs +9 -7
- package/dist/kit/getDefault.cjs.map +1 -1
- package/dist/kit/getDefault.d.cts +10 -0
- package/dist/kit/getDefault.d.ts +10 -8
- package/dist/kit/getDefault.js +9 -10
- package/dist/kit/getDefault.js.map +1 -1
- package/dist/kit/messages.cjs +8 -22
- package/dist/kit/messages.cjs.map +1 -1
- package/dist/kit/messages.d.cts +5 -0
- package/dist/kit/messages.d.ts +5 -1
- package/dist/kit/messages.js +8 -23
- package/dist/kit/messages.js.map +1 -1
- package/dist/kit/types.cjs +12 -9
- package/dist/kit/types.cjs.map +1 -1
- package/dist/kit/types.d.cts +28 -0
- package/dist/kit/types.d.ts +24 -19
- package/dist/kit/types.js +11 -10
- package/dist/kit/types.js.map +1 -1
- package/dist/kit.cjs +21 -26
- package/dist/kit.d.cts +8 -0
- package/dist/kit.d.ts +8 -0
- package/dist/kit.js +7 -21
- package/dist/lib/EventEmitter.cjs +16 -25
- package/dist/lib/EventEmitter.cjs.map +1 -1
- package/dist/lib/EventEmitter.d.cts +12 -0
- package/dist/lib/EventEmitter.d.ts +11 -9
- package/dist/lib/EventEmitter.js +16 -26
- package/dist/lib/EventEmitter.js.map +1 -1
- package/dist/lib/throttle.cjs +21 -21
- package/dist/lib/throttle.cjs.map +1 -1
- package/dist/lib/throttle.js +21 -22
- package/dist/lib/throttle.js.map +1 -1
- package/dist/types.cjs +18 -14
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +39 -0
- package/dist/types.d.ts +32 -27
- package/dist/types.js +16 -16
- package/dist/types.js.map +1 -1
- package/package.json +27 -68
- package/src/SimulatorAPI.ts +24 -22
- package/src/SimulatorClient.ts +24 -25
- package/src/channel/ChannelEmitter.ts +71 -74
- package/src/channel/ChannelNetwork.ts +53 -55
- package/src/channel/ChannelReceiver.ts +46 -48
- package/src/channel/errors.ts +14 -14
- package/src/channel/index.ts +10 -10
- package/src/channel/messages.ts +39 -31
- package/src/channel/types.ts +40 -40
- package/src/globalExtensions.ts +6 -6
- package/src/index.ts +8 -8
- package/src/kit/SimulatorManager.ts +64 -63
- package/src/kit/State.ts +45 -44
- package/src/kit/domHelpers.ts +24 -24
- package/src/kit/eventHandlers.ts +6 -6
- package/src/kit/getDefault.ts +8 -8
- package/src/kit/index.ts +8 -8
- package/src/kit/messages.ts +5 -5
- package/src/kit/types.ts +13 -13
- package/src/lib/EventEmitter.ts +8 -8
- package/src/lib/__PRODUCTION__.ts +2 -2
- package/src/lib/throttle.ts +12 -12
- package/src/types.ts +20 -20
- package/dist/channel/index.d.ts +0 -10
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kit/index.d.ts +0 -8
- package/dist/kit.cjs.map +0 -1
- package/dist/kit.js.map +0 -1
- package/dist/lib/__PRODUCTION__.d.ts +0 -7
- package/dist/lib/throttle.d.ts +0 -1
package/dist/lib/throttle.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
+
//#region src/lib/throttle.ts
|
|
1
2
|
const throttle = (fn, delay = 16) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
};
|
|
3
|
+
let lastExec = 0;
|
|
4
|
+
let timer = null;
|
|
5
|
+
return function(...args) {
|
|
6
|
+
const now = Date.now();
|
|
7
|
+
const delta = now - lastExec;
|
|
8
|
+
if (delta >= delay) {
|
|
9
|
+
fn.apply(this, args);
|
|
10
|
+
lastExec = now;
|
|
11
|
+
} else {
|
|
12
|
+
if (timer) clearTimeout(timer);
|
|
13
|
+
timer = setTimeout(() => {
|
|
14
|
+
fn.apply(this, args);
|
|
15
|
+
lastExec = Date.now();
|
|
16
|
+
}, delay - delta);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=throttle.js.map
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { throttle };
|
|
23
|
+
//# sourceMappingURL=throttle.js.map
|
package/dist/lib/throttle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throttle.js","sources":["
|
|
1
|
+
{"version":3,"file":"throttle.js","names":[],"sources":["../../src/lib/throttle.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const throttle = <TFn extends (...args: any[]) => any>(\n\tfn: TFn,\n\tdelay = 16,\n): ((...args: Parameters<TFn>) => void) => {\n\tlet lastExec = 0\n\tlet timer: NodeJS.Timeout | null = null\n\n\treturn function (this: unknown, ...args: Parameters<TFn>) {\n\t\tconst now = Date.now()\n\t\tconst delta = now - lastExec\n\n\t\tif (delta >= delay) {\n\t\t\tfn.apply(this, args)\n\t\t\tlastExec = now\n\t\t} else {\n\t\t\tif (timer) {\n\t\t\t\tclearTimeout(timer)\n\t\t\t}\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\tfn.apply(this, args)\n\t\t\t\tlastExec = Date.now()\n\t\t\t}, delay - delta)\n\t\t}\n\t}\n}\n"],"mappings":";AACA,MAAa,YACZ,IACA,QAAQ,OACkC;CAC1C,IAAI,WAAW;CACf,IAAI,QAA+B;AAEnC,QAAO,SAAyB,GAAG,MAAuB;EACzD,MAAM,MAAM,KAAK,KAAK;EACtB,MAAM,QAAQ,MAAM;AAEpB,MAAI,SAAS,OAAO;AACnB,MAAG,MAAM,MAAM,KAAK;AACpB,cAAW;SACL;AACN,OAAI,MACH,cAAa,MAAM;AAEpB,WAAQ,iBAAiB;AACxB,OAAG,MAAM,MAAM,KAAK;AACpB,eAAW,KAAK,KAAK;MACnB,QAAQ,MAAM"}
|
package/dist/types.cjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/types.ts
|
|
3
|
+
let APIRequestType = /* @__PURE__ */ function(APIRequestType$1) {
|
|
4
|
+
APIRequestType$1["SetActiveSlice"] = "setActiveSlice";
|
|
5
|
+
APIRequestType$1["SetSliceZoneSize"] = "setSliceZoneSize";
|
|
6
|
+
return APIRequestType$1;
|
|
7
|
+
}({});
|
|
8
|
+
let ClientRequestType = /* @__PURE__ */ function(ClientRequestType$1) {
|
|
9
|
+
ClientRequestType$1["Ping"] = "ping";
|
|
10
|
+
ClientRequestType$1["SetSliceZone"] = "setSliceZone";
|
|
11
|
+
ClientRequestType$1["ScrollToSlice"] = "scrollToSlice";
|
|
12
|
+
return ClientRequestType$1;
|
|
13
|
+
}({});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.APIRequestType = APIRequestType;
|
|
17
|
+
exports.ClientRequestType = ClientRequestType;
|
|
18
|
+
//# sourceMappingURL=types.cjs.map
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { SliceZone } from \"@prismicio/client\"\n\nimport type { RequestMessage, ResponseMessage, Transaction } from \"./channel\"\n\nexport type ActiveSlice = {\n\trect: DOMRect\n\tsliceID: string\n\tvariationID: string\n\tindex: number\n}\n\nexport type SliceZoneSize = {\n\trect: DOMRect\n}\n\nexport enum APIRequestType {\n\tSetActiveSlice = \"setActiveSlice\",\n\tSetSliceZoneSize = \"setSliceZoneSize\",\n}\n\nexport type APITransactions = {\n\t[APIRequestType.SetActiveSlice]: Transaction<\n\t\tRequestMessage<APIRequestType.SetActiveSlice, ActiveSlice | null>\n\t>\n\t[APIRequestType.SetSliceZoneSize]: Transaction<\n\t\tRequestMessage<APIRequestType.SetSliceZoneSize, SliceZoneSize>\n\t>\n}\n\nexport enum ClientRequestType {\n\tPing = \"ping\",\n\tSetSliceZone = \"setSliceZone\",\n\tScrollToSlice = \"scrollToSlice\",\n}\n\nexport type ClientTransactions = {\n\t[ClientRequestType.Ping]: Transaction<\n\t\tRequestMessage<ClientRequestType.Ping>,\n\t\tResponseMessage<\"pong\">\n\t>\n\n\t[ClientRequestType.SetSliceZone]: Transaction<\n\t\tRequestMessage<ClientRequestType.SetSliceZone, SliceZone>\n\t>\n\n\t[ClientRequestType.ScrollToSlice]: Transaction<\n\t\tRequestMessage<\n\t\t\tClientRequestType.ScrollToSlice,\n\t\t\t{\n\t\t\t\tsliceIndex: number\n\t\t\t\tbehavior?: \"auto\" | \"smooth\"\n\t\t\t\tblock?: \"start\" | \"center\" | \"end\" | \"nearest\"\n\t\t\t\tinline?: \"start\" | \"center\" | \"end\" | \"nearest\"\n\t\t\t}\n\t\t>\n\t>\n}\n"],"mappings":";;AAeA,IAAY,4DAAL;AACN;AACA;;;AAYD,IAAY,kEAAL;AACN;AACA;AACA"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { RequestMessage, ResponseMessage, Transaction } from "./channel/types.cjs";
|
|
2
|
+
import { SliceZone } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type ActiveSlice = {
|
|
6
|
+
rect: DOMRect;
|
|
7
|
+
sliceID: string;
|
|
8
|
+
variationID: string;
|
|
9
|
+
index: number;
|
|
10
|
+
};
|
|
11
|
+
type SliceZoneSize = {
|
|
12
|
+
rect: DOMRect;
|
|
13
|
+
};
|
|
14
|
+
declare enum APIRequestType {
|
|
15
|
+
SetActiveSlice = "setActiveSlice",
|
|
16
|
+
SetSliceZoneSize = "setSliceZoneSize",
|
|
17
|
+
}
|
|
18
|
+
type APITransactions = {
|
|
19
|
+
[APIRequestType.SetActiveSlice]: Transaction<RequestMessage<APIRequestType.SetActiveSlice, ActiveSlice | null>>;
|
|
20
|
+
[APIRequestType.SetSliceZoneSize]: Transaction<RequestMessage<APIRequestType.SetSliceZoneSize, SliceZoneSize>>;
|
|
21
|
+
};
|
|
22
|
+
declare enum ClientRequestType {
|
|
23
|
+
Ping = "ping",
|
|
24
|
+
SetSliceZone = "setSliceZone",
|
|
25
|
+
ScrollToSlice = "scrollToSlice",
|
|
26
|
+
}
|
|
27
|
+
type ClientTransactions = {
|
|
28
|
+
[ClientRequestType.Ping]: Transaction<RequestMessage<ClientRequestType.Ping>, ResponseMessage<"pong">>;
|
|
29
|
+
[ClientRequestType.SetSliceZone]: Transaction<RequestMessage<ClientRequestType.SetSliceZone, SliceZone>>;
|
|
30
|
+
[ClientRequestType.ScrollToSlice]: Transaction<RequestMessage<ClientRequestType.ScrollToSlice, {
|
|
31
|
+
sliceIndex: number;
|
|
32
|
+
behavior?: "auto" | "smooth";
|
|
33
|
+
block?: "start" | "center" | "end" | "nearest";
|
|
34
|
+
inline?: "start" | "center" | "end" | "nearest";
|
|
35
|
+
}>>;
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { APIRequestType, APITransactions, ActiveSlice, ClientRequestType, ClientTransactions, SliceZoneSize };
|
|
39
|
+
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.ts
CHANGED
|
@@ -1,34 +1,39 @@
|
|
|
1
|
+
import { RequestMessage, ResponseMessage, Transaction } from "./channel/types.js";
|
|
1
2
|
import { SliceZone } from "@prismicio/client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type ActiveSlice = {
|
|
6
|
+
rect: DOMRect;
|
|
7
|
+
sliceID: string;
|
|
8
|
+
variationID: string;
|
|
9
|
+
index: number;
|
|
8
10
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
type SliceZoneSize = {
|
|
12
|
+
rect: DOMRect;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
declare enum APIRequestType {
|
|
15
|
+
SetActiveSlice = "setActiveSlice",
|
|
16
|
+
SetSliceZoneSize = "setSliceZoneSize",
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
type APITransactions = {
|
|
19
|
+
[APIRequestType.SetActiveSlice]: Transaction<RequestMessage<APIRequestType.SetActiveSlice, ActiveSlice | null>>;
|
|
20
|
+
[APIRequestType.SetSliceZoneSize]: Transaction<RequestMessage<APIRequestType.SetSliceZoneSize, SliceZoneSize>>;
|
|
19
21
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
declare enum ClientRequestType {
|
|
23
|
+
Ping = "ping",
|
|
24
|
+
SetSliceZone = "setSliceZone",
|
|
25
|
+
ScrollToSlice = "scrollToSlice",
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
type ClientTransactions = {
|
|
28
|
+
[ClientRequestType.Ping]: Transaction<RequestMessage<ClientRequestType.Ping>, ResponseMessage<"pong">>;
|
|
29
|
+
[ClientRequestType.SetSliceZone]: Transaction<RequestMessage<ClientRequestType.SetSliceZone, SliceZone>>;
|
|
30
|
+
[ClientRequestType.ScrollToSlice]: Transaction<RequestMessage<ClientRequestType.ScrollToSlice, {
|
|
31
|
+
sliceIndex: number;
|
|
32
|
+
behavior?: "auto" | "smooth";
|
|
33
|
+
block?: "start" | "center" | "end" | "nearest";
|
|
34
|
+
inline?: "start" | "center" | "end" | "nearest";
|
|
35
|
+
}>>;
|
|
34
36
|
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { APIRequestType, APITransactions, ActiveSlice, ClientRequestType, ClientTransactions, SliceZoneSize };
|
|
39
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=types.js.map
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
let APIRequestType = /* @__PURE__ */ function(APIRequestType$1) {
|
|
3
|
+
APIRequestType$1["SetActiveSlice"] = "setActiveSlice";
|
|
4
|
+
APIRequestType$1["SetSliceZoneSize"] = "setSliceZoneSize";
|
|
5
|
+
return APIRequestType$1;
|
|
6
|
+
}({});
|
|
7
|
+
let ClientRequestType = /* @__PURE__ */ function(ClientRequestType$1) {
|
|
8
|
+
ClientRequestType$1["Ping"] = "ping";
|
|
9
|
+
ClientRequestType$1["SetSliceZone"] = "setSliceZone";
|
|
10
|
+
ClientRequestType$1["ScrollToSlice"] = "scrollToSlice";
|
|
11
|
+
return ClientRequestType$1;
|
|
12
|
+
}({});
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { APIRequestType, ClientRequestType };
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { SliceZone } from \"@prismicio/client\"\n\nimport type { RequestMessage, ResponseMessage, Transaction } from \"./channel\"\n\nexport type ActiveSlice = {\n\trect: DOMRect\n\tsliceID: string\n\tvariationID: string\n\tindex: number\n}\n\nexport type SliceZoneSize = {\n\trect: DOMRect\n}\n\nexport enum APIRequestType {\n\tSetActiveSlice = \"setActiveSlice\",\n\tSetSliceZoneSize = \"setSliceZoneSize\",\n}\n\nexport type APITransactions = {\n\t[APIRequestType.SetActiveSlice]: Transaction<\n\t\tRequestMessage<APIRequestType.SetActiveSlice, ActiveSlice | null>\n\t>\n\t[APIRequestType.SetSliceZoneSize]: Transaction<\n\t\tRequestMessage<APIRequestType.SetSliceZoneSize, SliceZoneSize>\n\t>\n}\n\nexport enum ClientRequestType {\n\tPing = \"ping\",\n\tSetSliceZone = \"setSliceZone\",\n\tScrollToSlice = \"scrollToSlice\",\n}\n\nexport type ClientTransactions = {\n\t[ClientRequestType.Ping]: Transaction<\n\t\tRequestMessage<ClientRequestType.Ping>,\n\t\tResponseMessage<\"pong\">\n\t>\n\n\t[ClientRequestType.SetSliceZone]: Transaction<\n\t\tRequestMessage<ClientRequestType.SetSliceZone, SliceZone>\n\t>\n\n\t[ClientRequestType.ScrollToSlice]: Transaction<\n\t\tRequestMessage<\n\t\t\tClientRequestType.ScrollToSlice,\n\t\t\t{\n\t\t\t\tsliceIndex: number\n\t\t\t\tbehavior?: \"auto\" | \"smooth\"\n\t\t\t\tblock?: \"start\" | \"center\" | \"end\" | \"nearest\"\n\t\t\t\tinline?: \"start\" | \"center\" | \"end\" | \"nearest\"\n\t\t\t}\n\t\t>\n\t>\n}\n"],"mappings":";AAeA,IAAY,4DAAL;AACN;AACA;;;AAYD,IAAY,kEAAL;AACN;AACA;AACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Preview and develop Prismic slices fast with minimal configuration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -8,37 +8,25 @@
|
|
|
8
8
|
],
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "ssh://git@github.com/
|
|
11
|
+
"url": "ssh://git@github.com/prismicio/slice-simulator.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"require":
|
|
19
|
-
|
|
20
|
-
"default": "./dist/index.cjs"
|
|
21
|
-
},
|
|
22
|
-
"import": {
|
|
23
|
-
"types": "./dist/index.d.ts",
|
|
24
|
-
"default": "./dist/index.js"
|
|
25
|
-
}
|
|
18
|
+
"require": "./dist/index.cjs",
|
|
19
|
+
"import": "./dist/index.js"
|
|
26
20
|
},
|
|
27
21
|
"./kit": {
|
|
28
|
-
"require":
|
|
29
|
-
|
|
30
|
-
"default": "./dist/kit.cjs"
|
|
31
|
-
},
|
|
32
|
-
"import": {
|
|
33
|
-
"types": "./dist/kit/index.d.ts",
|
|
34
|
-
"default": "./dist/kit.js"
|
|
35
|
-
}
|
|
22
|
+
"require": "./dist/kit.cjs",
|
|
23
|
+
"import": "./dist/kit.js"
|
|
36
24
|
},
|
|
37
25
|
"./package.json": "./package.json"
|
|
38
26
|
},
|
|
39
27
|
"main": "./dist/index.cjs",
|
|
40
28
|
"module": "./dist/index.js",
|
|
41
|
-
"types": "./dist/index.d.
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
42
30
|
"files": [
|
|
43
31
|
"./dist",
|
|
44
32
|
"./src"
|
|
@@ -49,65 +37,36 @@
|
|
|
49
37
|
"dist/index.d.ts"
|
|
50
38
|
],
|
|
51
39
|
"kit": [
|
|
52
|
-
"dist/kit
|
|
40
|
+
"dist/kit.d.ts"
|
|
53
41
|
]
|
|
54
42
|
}
|
|
55
43
|
},
|
|
56
44
|
"scripts": {
|
|
57
|
-
"build": "
|
|
58
|
-
"dev": "
|
|
45
|
+
"build": "tsdown",
|
|
46
|
+
"dev": "tsdown --watch",
|
|
59
47
|
"format": "prettier --write .",
|
|
60
48
|
"prepare": "npm run build",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"release:alpha": "npm run test && standard-version --release-as major --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
64
|
-
"release:alpha:dry": "standard-version --release-as major --prerelease alpha --dry-run",
|
|
65
|
-
"lint": "eslint --ext .js,.ts,.jsx,.tsx .",
|
|
66
|
-
"types": "vitest typecheck --run && tsc --noEmit",
|
|
67
|
-
"types:watch": "vitest typecheck",
|
|
49
|
+
"lint": "oxlint --deny-warnings",
|
|
50
|
+
"types": "tsc --noEmit",
|
|
68
51
|
"unit": "vitest run --coverage",
|
|
69
52
|
"unit:watch": "vitest watch",
|
|
70
|
-
"
|
|
71
|
-
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size"
|
|
72
|
-
},
|
|
73
|
-
"dependencies": {
|
|
74
|
-
"@prismicio/client": "^7.1.0",
|
|
75
|
-
"@types/statuses": "^2.0.1",
|
|
76
|
-
"statuses": "^2.0.1"
|
|
53
|
+
"test": "npm run lint && npm run types && npm run unit && npm run build"
|
|
77
54
|
},
|
|
78
55
|
"devDependencies": {
|
|
79
|
-
"@prismicio/
|
|
80
|
-
"@
|
|
81
|
-
"@
|
|
82
|
-
"@
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
"eslint-config-next": "^13.4.5",
|
|
94
|
-
"eslint-config-prettier": "^8.8.0",
|
|
95
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
96
|
-
"eslint-plugin-tsdoc": "^0.2.17",
|
|
97
|
-
"jsdom": "^22.1.0",
|
|
98
|
-
"next": "13.4.5",
|
|
99
|
-
"postcss": "^8.4.24",
|
|
100
|
-
"prettier": "^2.8.8",
|
|
101
|
-
"prettier-plugin-jsdoc": "^0.4.2",
|
|
102
|
-
"react": "18.2.0",
|
|
103
|
-
"react-dom": "18.2.0",
|
|
104
|
-
"size-limit": "^8.2.4",
|
|
105
|
-
"standard-version": "^9.5.0",
|
|
106
|
-
"tailwindcss": "^3.3.2",
|
|
107
|
-
"typescript": "^5.1.3",
|
|
108
|
-
"vite": "^4.3.9",
|
|
109
|
-
"vite-plugin-sdk": "^0.1.1",
|
|
110
|
-
"vitest": "^0.32.0"
|
|
56
|
+
"@prismicio/client": "^7.21.3",
|
|
57
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
58
|
+
"@types/node": "25.0.8",
|
|
59
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
60
|
+
"jsdom": "^27.4.0",
|
|
61
|
+
"oxlint": "^1.39.0",
|
|
62
|
+
"prettier": "^3.7.4",
|
|
63
|
+
"prettier-plugin-jsdoc": "^1.8.0",
|
|
64
|
+
"tsdown": "^0.19.0",
|
|
65
|
+
"typescript": "^5.9.3",
|
|
66
|
+
"vitest": "^4.0.17"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"@prismicio/client": "^7"
|
|
111
70
|
},
|
|
112
71
|
"engines": {
|
|
113
72
|
"node": ">=14.15.0"
|
package/src/SimulatorAPI.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
APITransactions,
|
|
3
|
+
ClientTransactions} from "./types";
|
|
1
4
|
import {
|
|
2
5
|
APIRequestType,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ClientTransactions,
|
|
6
|
-
} from "./types";
|
|
6
|
+
ClientRequestType
|
|
7
|
+
} from "./types"
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import type {
|
|
9
10
|
AllChannelReceiverOptions,
|
|
10
|
-
ChannelReceiver,
|
|
11
11
|
TransactionMethod,
|
|
12
12
|
TransactionsHandlers,
|
|
13
|
-
TransactionsMethods
|
|
14
|
-
|
|
13
|
+
TransactionsMethods} from "./channel";
|
|
14
|
+
import {
|
|
15
|
+
ChannelReceiver
|
|
16
|
+
} from "./channel"
|
|
15
17
|
|
|
16
18
|
export type SimulatorAPIOptions = {
|
|
17
|
-
activeSliceAPI: boolean
|
|
18
|
-
sliceZoneSizeAPI: boolean
|
|
19
|
-
}
|
|
19
|
+
activeSliceAPI: boolean
|
|
20
|
+
sliceZoneSizeAPI: boolean
|
|
21
|
+
}
|
|
20
22
|
|
|
21
23
|
export const simulatorAPIDefaultOptions: Partial<AllChannelReceiverOptions> &
|
|
22
24
|
SimulatorAPIOptions = {
|
|
23
25
|
requestIDPrefix: "api-",
|
|
24
26
|
activeSliceAPI: false,
|
|
25
27
|
sliceZoneSizeAPI: false,
|
|
26
|
-
}
|
|
28
|
+
}
|
|
27
29
|
|
|
28
30
|
export class SimulatorAPI
|
|
29
31
|
extends ChannelReceiver<ClientTransactions, SimulatorAPIOptions>
|
|
@@ -42,12 +44,12 @@ export class SimulatorAPI
|
|
|
42
44
|
// True if `options.debug` is true or `debug=true` is among query parameters
|
|
43
45
|
const debug =
|
|
44
46
|
options?.debug ||
|
|
45
|
-
/[?&]debug=true/i.test(decodeURIComponent(window.location.search))
|
|
47
|
+
/[?&]debug=true/i.test(decodeURIComponent(window.location.search))
|
|
46
48
|
|
|
47
49
|
super(
|
|
48
50
|
{
|
|
49
51
|
[ClientRequestType.Ping]: (_req, res) => {
|
|
50
|
-
return res.success("pong")
|
|
52
|
+
return res.success("pong")
|
|
51
53
|
},
|
|
52
54
|
...requestHandlers,
|
|
53
55
|
},
|
|
@@ -56,21 +58,21 @@ export class SimulatorAPI
|
|
|
56
58
|
...options,
|
|
57
59
|
debug,
|
|
58
60
|
},
|
|
59
|
-
)
|
|
61
|
+
)
|
|
60
62
|
|
|
61
63
|
// Append API to window object
|
|
62
64
|
if (debug) {
|
|
63
|
-
window.prismic ||= {}
|
|
64
|
-
window.prismic.sliceSimulator ||= {}
|
|
65
|
-
window.prismic.sliceSimulator.api ||= []
|
|
66
|
-
window.prismic.sliceSimulator.api.push(this)
|
|
65
|
+
window.prismic ||= {}
|
|
66
|
+
window.prismic.sliceSimulator ||= {}
|
|
67
|
+
window.prismic.sliceSimulator.api ||= []
|
|
68
|
+
window.prismic.sliceSimulator.api.push(this)
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
[APIRequestType.SetActiveSlice]: TransactionMethod<
|
|
71
73
|
APITransactions[APIRequestType.SetActiveSlice]
|
|
72
74
|
> = async (data) => {
|
|
73
|
-
return await this.postFormattedRequest(APIRequestType.SetActiveSlice, data)
|
|
75
|
+
return await this.postFormattedRequest(APIRequestType.SetActiveSlice, data)
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
[APIRequestType.SetSliceZoneSize]: TransactionMethod<
|
|
@@ -79,6 +81,6 @@ export class SimulatorAPI
|
|
|
79
81
|
return await this.postFormattedRequest(
|
|
80
82
|
APIRequestType.SetSliceZoneSize,
|
|
81
83
|
data,
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
+
)
|
|
85
|
+
}
|
|
84
86
|
}
|
package/src/SimulatorClient.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
APITransactions,
|
|
3
|
+
ClientTransactions} from "./types";
|
|
1
4
|
import {
|
|
2
5
|
APIRequestType,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ClientTransactions,
|
|
6
|
-
} from "./types";
|
|
6
|
+
ClientRequestType
|
|
7
|
+
} from "./types"
|
|
7
8
|
|
|
8
|
-
import { SimulatorAPIOptions } from "./SimulatorAPI"
|
|
9
|
-
import {
|
|
9
|
+
import type { SimulatorAPIOptions } from "./SimulatorAPI"
|
|
10
|
+
import type {
|
|
10
11
|
AllChannelEmitterOptions,
|
|
11
|
-
ChannelEmitter,
|
|
12
12
|
TransactionMethod,
|
|
13
13
|
TransactionsHandlers,
|
|
14
|
-
TransactionsMethods
|
|
15
|
-
|
|
14
|
+
TransactionsMethods} from "./channel";
|
|
15
|
+
import {
|
|
16
|
+
ChannelEmitter
|
|
17
|
+
} from "./channel"
|
|
16
18
|
|
|
17
19
|
export const simulatorClientDefaultOptions: Partial<AllChannelEmitterOptions> =
|
|
18
20
|
{
|
|
19
21
|
requestIDPrefix: "client-",
|
|
20
|
-
}
|
|
22
|
+
}
|
|
21
23
|
|
|
22
24
|
export class SimulatorClient
|
|
23
25
|
extends ChannelEmitter<
|
|
@@ -35,16 +37,16 @@ export class SimulatorClient
|
|
|
35
37
|
// True if `options.debug` is true or `debug=true` is among query parameters
|
|
36
38
|
const debug =
|
|
37
39
|
options?.debug ||
|
|
38
|
-
/[?&]debug=true/i.test(decodeURIComponent(window.location.search))
|
|
40
|
+
/[?&]debug=true/i.test(decodeURIComponent(window.location.search))
|
|
39
41
|
|
|
40
42
|
super(
|
|
41
43
|
target,
|
|
42
44
|
{
|
|
43
45
|
[APIRequestType.SetActiveSlice]: (_req, res) => {
|
|
44
|
-
return res.success()
|
|
46
|
+
return res.success()
|
|
45
47
|
},
|
|
46
48
|
[APIRequestType.SetSliceZoneSize]: (_req, res) => {
|
|
47
|
-
return res.success()
|
|
49
|
+
return res.success()
|
|
48
50
|
},
|
|
49
51
|
...requestHandlers,
|
|
50
52
|
},
|
|
@@ -53,30 +55,27 @@ export class SimulatorClient
|
|
|
53
55
|
...options,
|
|
54
56
|
debug,
|
|
55
57
|
},
|
|
56
|
-
)
|
|
58
|
+
)
|
|
57
59
|
|
|
58
60
|
// Append client to window object
|
|
59
61
|
if (debug) {
|
|
60
|
-
window.prismic ||= {}
|
|
61
|
-
window.prismic.sliceSimulator ||= {}
|
|
62
|
-
window.prismic.sliceSimulator.client ||= []
|
|
63
|
-
window.prismic.sliceSimulator.client.push(this)
|
|
62
|
+
window.prismic ||= {}
|
|
63
|
+
window.prismic.sliceSimulator ||= {}
|
|
64
|
+
window.prismic.sliceSimulator.client ||= []
|
|
65
|
+
window.prismic.sliceSimulator.client.push(this)
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
[ClientRequestType.Ping]: TransactionMethod<
|
|
68
70
|
ClientTransactions[ClientRequestType.Ping]
|
|
69
71
|
> = async () => {
|
|
70
|
-
return await this.postFormattedRequest(ClientRequestType.Ping)
|
|
72
|
+
return await this.postFormattedRequest(ClientRequestType.Ping)
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
[ClientRequestType.SetSliceZone]: TransactionMethod<
|
|
74
76
|
ClientTransactions[ClientRequestType.SetSliceZone]
|
|
75
77
|
> = async (data) => {
|
|
76
|
-
return await this.postFormattedRequest(
|
|
77
|
-
ClientRequestType.SetSliceZone,
|
|
78
|
-
data,
|
|
79
|
-
);
|
|
78
|
+
return await this.postFormattedRequest(ClientRequestType.SetSliceZone, data)
|
|
80
79
|
};
|
|
81
80
|
|
|
82
81
|
[ClientRequestType.ScrollToSlice]: TransactionMethod<
|
|
@@ -85,6 +84,6 @@ export class SimulatorClient
|
|
|
85
84
|
return await this.postFormattedRequest(
|
|
86
85
|
ClientRequestType.ScrollToSlice,
|
|
87
86
|
data,
|
|
88
|
-
)
|
|
89
|
-
}
|
|
87
|
+
)
|
|
88
|
+
}
|
|
90
89
|
}
|