@prismicio/simulator 0.2.0 → 0.2.1
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 +7 -9
- package/dist/SimulatorAPI.cjs.map +1 -1
- package/dist/SimulatorAPI.d.cts.map +1 -0
- package/dist/SimulatorAPI.d.ts.map +1 -0
- package/dist/SimulatorAPI.js +6 -8
- package/dist/SimulatorAPI.js.map +1 -1
- package/dist/SimulatorClient.cjs +7 -9
- package/dist/SimulatorClient.cjs.map +1 -1
- package/dist/SimulatorClient.d.cts.map +1 -0
- package/dist/SimulatorClient.d.ts.map +1 -0
- package/dist/SimulatorClient.js +6 -8
- package/dist/SimulatorClient.js.map +1 -1
- package/dist/channel/ChannelEmitter.cjs +10 -13
- package/dist/channel/ChannelEmitter.cjs.map +1 -1
- package/dist/channel/ChannelEmitter.d.cts +1 -3
- package/dist/channel/ChannelEmitter.d.cts.map +1 -0
- package/dist/channel/ChannelEmitter.d.ts +1 -3
- package/dist/channel/ChannelEmitter.d.ts.map +1 -0
- package/dist/channel/ChannelEmitter.js +6 -9
- package/dist/channel/ChannelEmitter.js.map +1 -1
- package/dist/channel/ChannelNetwork.cjs +5 -6
- package/dist/channel/ChannelNetwork.cjs.map +1 -1
- package/dist/channel/ChannelNetwork.d.cts.map +1 -0
- package/dist/channel/ChannelNetwork.d.ts.map +1 -0
- package/dist/channel/ChannelNetwork.js +3 -4
- package/dist/channel/ChannelNetwork.js.map +1 -1
- package/dist/channel/ChannelReceiver.cjs +9 -10
- package/dist/channel/ChannelReceiver.cjs.map +1 -1
- package/dist/channel/ChannelReceiver.d.cts.map +1 -0
- package/dist/channel/ChannelReceiver.d.ts.map +1 -0
- package/dist/channel/ChannelReceiver.js +5 -6
- package/dist/channel/ChannelReceiver.js.map +1 -1
- package/dist/channel/errors.cjs +1 -2
- package/dist/channel/errors.cjs.map +1 -1
- package/dist/channel/errors.d.cts.map +1 -0
- package/dist/channel/errors.d.ts.map +1 -0
- package/dist/channel/errors.js +1 -1
- package/dist/channel/errors.js.map +1 -1
- package/dist/channel/messages.cjs +5 -6
- package/dist/channel/messages.cjs.map +1 -1
- package/dist/channel/messages.d.cts +0 -1
- package/dist/channel/messages.d.cts.map +1 -0
- package/dist/channel/messages.d.ts +0 -1
- package/dist/channel/messages.d.ts.map +1 -0
- package/dist/channel/messages.js +5 -5
- package/dist/channel/messages.js.map +1 -1
- package/dist/channel/types.cjs +7 -8
- package/dist/channel/types.cjs.map +1 -1
- package/dist/channel/types.d.cts +1 -1
- package/dist/channel/types.d.cts.map +1 -0
- package/dist/channel/types.d.ts +1 -1
- package/dist/channel/types.d.ts.map +1 -0
- package/dist/channel/types.js +7 -7
- package/dist/channel/types.js.map +1 -1
- package/dist/globalExtensions.d.cts +1 -1
- package/dist/globalExtensions.d.cts.map +1 -0
- package/dist/globalExtensions.d.ts +1 -1
- package/dist/globalExtensions.d.ts.map +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +2 -3
- package/dist/kit/SimulatorManager.cjs +12 -15
- package/dist/kit/SimulatorManager.cjs.map +1 -1
- package/dist/kit/SimulatorManager.d.cts.map +1 -0
- package/dist/kit/SimulatorManager.d.ts.map +1 -0
- package/dist/kit/SimulatorManager.js +7 -10
- package/dist/kit/SimulatorManager.js.map +1 -1
- package/dist/kit/State.cjs +7 -8
- package/dist/kit/State.cjs.map +1 -1
- package/dist/kit/State.d.cts.map +1 -0
- package/dist/kit/State.d.ts.map +1 -0
- package/dist/kit/State.js +4 -5
- package/dist/kit/State.js.map +1 -1
- package/dist/kit/domHelpers.cjs +1 -2
- package/dist/kit/domHelpers.cjs.map +1 -1
- package/dist/kit/domHelpers.d.cts.map +1 -0
- package/dist/kit/domHelpers.d.ts.map +1 -0
- package/dist/kit/domHelpers.js +1 -1
- package/dist/kit/domHelpers.js.map +1 -1
- package/dist/kit/eventHandlers.cjs +1 -2
- package/dist/kit/eventHandlers.cjs.map +1 -1
- package/dist/kit/eventHandlers.d.cts.map +1 -0
- package/dist/kit/eventHandlers.d.ts.map +1 -0
- package/dist/kit/eventHandlers.js +1 -1
- package/dist/kit/eventHandlers.js.map +1 -1
- package/dist/kit/getDefault.cjs +1 -2
- package/dist/kit/getDefault.cjs.map +1 -1
- package/dist/kit/getDefault.d.cts.map +1 -0
- package/dist/kit/getDefault.d.ts.map +1 -0
- package/dist/kit/getDefault.js +1 -1
- package/dist/kit/messages.cjs +3 -6
- package/dist/kit/messages.cjs.map +1 -1
- package/dist/kit/messages.d.cts.map +1 -0
- package/dist/kit/messages.d.ts.map +1 -0
- package/dist/kit/messages.js +3 -5
- package/dist/kit/messages.js.map +1 -1
- package/dist/kit/types.cjs +6 -7
- package/dist/kit/types.cjs.map +1 -1
- package/dist/kit/types.d.cts +1 -1
- package/dist/kit/types.d.cts.map +1 -0
- package/dist/kit/types.d.ts +1 -1
- package/dist/kit/types.d.ts.map +1 -0
- package/dist/kit/types.js +6 -6
- package/dist/kit/types.js.map +1 -1
- package/dist/kit.cjs +9 -9
- package/dist/kit.js +3 -4
- package/dist/lib/EventEmitter.cjs +1 -2
- package/dist/lib/EventEmitter.cjs.map +1 -1
- package/dist/lib/EventEmitter.d.cts.map +1 -0
- package/dist/lib/EventEmitter.d.ts.map +1 -0
- package/dist/lib/EventEmitter.js +1 -1
- package/dist/lib/EventEmitter.js.map +1 -1
- package/dist/lib/throttle.cjs +1 -2
- package/dist/lib/throttle.cjs.map +1 -1
- package/dist/lib/throttle.js +1 -1
- package/dist/types.cjs +10 -11
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -10
- package/dist/types.js.map +1 -1
- package/package.json +33 -35
- package/src/SimulatorAPI.ts +14 -30
- package/src/SimulatorClient.ts +15 -32
- package/src/channel/ChannelEmitter.ts +25 -57
- package/src/channel/ChannelNetwork.ts +36 -61
- package/src/channel/ChannelReceiver.ts +20 -51
- package/src/channel/errors.ts +2 -7
- package/src/channel/index.ts +5 -20
- package/src/channel/messages.ts +4 -13
- package/src/channel/types.ts +15 -31
- package/src/index.ts +2 -10
- package/src/kit/SimulatorManager.ts +7 -20
- package/src/kit/State.ts +4 -9
- package/src/kit/domHelpers.ts +1 -3
- package/src/kit/eventHandlers.ts +2 -7
- package/src/kit/index.ts +1 -5
- package/src/kit/messages.ts +1 -2
- package/src/kit/types.ts +0 -1
- package/src/lib/EventEmitter.ts +3 -9
- package/src/lib/__PRODUCTION__.ts +1 -2
package/src/index.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
SimulatorClient,
|
|
3
|
-
simulatorClientDefaultOptions,
|
|
4
|
-
} from "./SimulatorClient"
|
|
1
|
+
export { SimulatorClient, simulatorClientDefaultOptions } from "./SimulatorClient"
|
|
5
2
|
|
|
6
3
|
export { SimulatorAPI, simulatorAPIDefaultOptions } from "./SimulatorAPI"
|
|
7
4
|
export type { SimulatorAPIOptions } from "./SimulatorAPI"
|
|
@@ -32,11 +29,6 @@ export type {
|
|
|
32
29
|
} from "./channel"
|
|
33
30
|
|
|
34
31
|
export { APIRequestType, ClientRequestType } from "./types"
|
|
35
|
-
export type {
|
|
36
|
-
ActiveSlice,
|
|
37
|
-
SliceZoneSize,
|
|
38
|
-
APITransactions,
|
|
39
|
-
ClientTransactions,
|
|
40
|
-
} from "./types"
|
|
32
|
+
export type { ActiveSlice, SliceZoneSize, APITransactions, ClientTransactions } from "./types"
|
|
41
33
|
|
|
42
34
|
export * from "./globalExtensions"
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import type { SliceZone } from "@prismicio/client"
|
|
2
2
|
|
|
3
|
+
import { ResponseError } from "../channel"
|
|
3
4
|
import { throttle } from "../lib/throttle"
|
|
4
|
-
|
|
5
|
-
import { ClientRequestType } from "../types"
|
|
6
|
-
import { StateEventType } from "./types"
|
|
7
|
-
|
|
8
5
|
import { SimulatorAPI } from "../SimulatorAPI"
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { State } from "./State"
|
|
12
|
-
import {
|
|
13
|
-
getSimulatorDOM,
|
|
14
|
-
getSimulatorRootDOM,
|
|
15
|
-
getSliceZoneDOM,
|
|
16
|
-
} from "./domHelpers"
|
|
6
|
+
import { ClientRequestType } from "../types"
|
|
7
|
+
import { getSimulatorDOM, getSimulatorRootDOM, getSliceZoneDOM } from "./domHelpers"
|
|
17
8
|
import { sliceSimulatorAccessedDirectly } from "./messages"
|
|
9
|
+
import { State } from "./State"
|
|
10
|
+
import { StateEventType } from "./types"
|
|
18
11
|
|
|
19
12
|
type ManagerConstructorArgs = {
|
|
20
13
|
slices?: SliceZone
|
|
@@ -142,10 +135,7 @@ export class SimulatorManager {
|
|
|
142
135
|
await this._api.setActiveSlice(activeSlice)
|
|
143
136
|
} catch (error) {
|
|
144
137
|
// Just log bad requests, throw everything else
|
|
145
|
-
if (
|
|
146
|
-
error instanceof ResponseError &&
|
|
147
|
-
error.response.status === 400
|
|
148
|
-
) {
|
|
138
|
+
if (error instanceof ResponseError && error.response.status === 400) {
|
|
149
139
|
console.error(error.response)
|
|
150
140
|
} else {
|
|
151
141
|
throw error
|
|
@@ -166,10 +156,7 @@ export class SimulatorManager {
|
|
|
166
156
|
await this._api.setSliceZoneSize({ rect: entry.contentRect })
|
|
167
157
|
} catch (error) {
|
|
168
158
|
// Just log bad requests, throw everything else
|
|
169
|
-
if (
|
|
170
|
-
error instanceof ResponseError &&
|
|
171
|
-
error.response.status === 400
|
|
172
|
-
) {
|
|
159
|
+
if (error instanceof ResponseError && error.response.status === 400) {
|
|
173
160
|
console.error(error.response)
|
|
174
161
|
} else {
|
|
175
162
|
throw error
|
package/src/kit/State.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { SharedSlice, SliceZone } from "@prismicio/client"
|
|
2
2
|
|
|
3
|
-
import { EventEmitter } from "../lib/EventEmitter"
|
|
4
3
|
import { __PRODUCTION__ } from "../lib/__PRODUCTION__"
|
|
4
|
+
import { EventEmitter } from "../lib/EventEmitter"
|
|
5
5
|
import { throttle } from "../lib/throttle"
|
|
6
|
-
|
|
7
6
|
import type { ActiveSlice } from "../types"
|
|
8
|
-
import type { StateEvents } from "./types";
|
|
9
|
-
import { StateEventType } from "./types"
|
|
10
|
-
|
|
11
7
|
import { getActiveSliceDOM, getSliceZoneDOM } from "./domHelpers"
|
|
12
8
|
import { getDefaultSlices } from "./getDefault"
|
|
9
|
+
import type { StateEvents } from "./types"
|
|
10
|
+
import { StateEventType } from "./types"
|
|
13
11
|
|
|
14
12
|
type StateConstructorArgs = {
|
|
15
13
|
slices?: SliceZone
|
|
@@ -92,10 +90,7 @@ export class State extends EventEmitter<StateEvents> {
|
|
|
92
90
|
return
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
const activeSliceIndex = Array.prototype.indexOf.call(
|
|
96
|
-
$sliceZone.children,
|
|
97
|
-
$activeSlice,
|
|
98
|
-
)
|
|
93
|
+
const activeSliceIndex = Array.prototype.indexOf.call($sliceZone.children, $activeSlice)
|
|
99
94
|
|
|
100
95
|
// Active slice has been found
|
|
101
96
|
this.activeSlice = {
|
package/src/kit/domHelpers.ts
CHANGED
|
@@ -9,9 +9,7 @@ export const getSimulatorRootDOM = (): Element | null => {
|
|
|
9
9
|
return document.querySelector(`.${simulatorRootClass}`)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const getSliceZoneDOM = (
|
|
13
|
-
expectedNumberOfChildren: number,
|
|
14
|
-
): Element | null => {
|
|
12
|
+
export const getSliceZoneDOM = (expectedNumberOfChildren: number): Element | null => {
|
|
15
13
|
// If SliceZone has been tagged (#5)
|
|
16
14
|
let node = document.querySelector(`.${simulatorClass} [data-slice-zone]`)
|
|
17
15
|
if (node) {
|
package/src/kit/eventHandlers.ts
CHANGED
|
@@ -3,13 +3,8 @@ export const disableEventHandler = (event: Event): void => {
|
|
|
3
3
|
event.stopPropagation()
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
export const onClickHandler = (
|
|
7
|
-
event
|
|
8
|
-
): void => {
|
|
9
|
-
if (
|
|
10
|
-
event.path &&
|
|
11
|
-
event.path.slice(0, 5).some((el) => el instanceof HTMLAnchorElement)
|
|
12
|
-
) {
|
|
6
|
+
export const onClickHandler = (event: MouseEvent & { path?: HTMLElement[] }): void => {
|
|
7
|
+
if (event.path && event.path.slice(0, 5).some((el) => el instanceof HTMLAnchorElement)) {
|
|
13
8
|
event.preventDefault()
|
|
14
9
|
event.stopPropagation()
|
|
15
10
|
}
|
package/src/kit/index.ts
CHANGED
|
@@ -3,11 +3,7 @@ export { SimulatorManager } from "./SimulatorManager"
|
|
|
3
3
|
export { State } from "./State"
|
|
4
4
|
|
|
5
5
|
// Defaults
|
|
6
|
-
export {
|
|
7
|
-
getDefaultProps,
|
|
8
|
-
getDefaultSlices,
|
|
9
|
-
getDefaultMessage,
|
|
10
|
-
} from "./getDefault"
|
|
6
|
+
export { getDefaultProps, getDefaultSlices, getDefaultMessage } from "./getDefault"
|
|
11
7
|
|
|
12
8
|
// DOM helpers
|
|
13
9
|
export {
|
package/src/kit/messages.ts
CHANGED
|
@@ -7,8 +7,7 @@ const a = (href: string, label?: string) =>
|
|
|
7
7
|
const header =
|
|
8
8
|
" _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ `__ \\/ / / / / __ `/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ `__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/\n\n"
|
|
9
9
|
|
|
10
|
-
const footer =
|
|
11
|
-
"\n\n\n\n\n\n - The Prismic team"
|
|
10
|
+
const footer = "\n\n\n\n\n\n - The Prismic team"
|
|
12
11
|
|
|
13
12
|
export const sliceSimulatorAccessedDirectly = div(
|
|
14
13
|
[
|
package/src/kit/types.ts
CHANGED
package/src/lib/EventEmitter.ts
CHANGED
|
@@ -14,21 +14,15 @@ export abstract class EventEmitter<TEventMap = EventMap> {
|
|
|
14
14
|
listener: Listener<TEventMap[TEventType]>,
|
|
15
15
|
key: string | null = null,
|
|
16
16
|
): void {
|
|
17
|
-
this._listeners[event] = [
|
|
18
|
-
...(this._listeners[event] ?? []),
|
|
19
|
-
[listener, key],
|
|
20
|
-
]
|
|
17
|
+
this._listeners[event] = [...(this._listeners[event] ?? []), [listener, key]]
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
off<TEventType extends keyof TEventMap>(
|
|
24
21
|
event: TEventType,
|
|
25
22
|
listenerOrKey: Listener<TEventMap[TEventType]> | string,
|
|
26
23
|
): void {
|
|
27
|
-
this._listeners[event] = (this._listeners[event] ?? []).filter(
|
|
28
|
-
|
|
29
|
-
typeof listenerOrKey === "function"
|
|
30
|
-
? listener !== listenerOrKey
|
|
31
|
-
: key !== listenerOrKey,
|
|
24
|
+
this._listeners[event] = (this._listeners[event] ?? []).filter(([listener, key]) =>
|
|
25
|
+
typeof listenerOrKey === "function" ? listener !== listenerOrKey : key !== listenerOrKey,
|
|
32
26
|
)
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -6,7 +6,6 @@ if (typeof process === "undefined") {
|
|
|
6
6
|
/**
|
|
7
7
|
* `true` if in the production environment, `false` otherwise.
|
|
8
8
|
*
|
|
9
|
-
* This boolean can be used to perform actions only in development environments,
|
|
10
|
-
* such as logging.
|
|
9
|
+
* This boolean can be used to perform actions only in development environments, such as logging.
|
|
11
10
|
*/
|
|
12
11
|
export const __PRODUCTION__ = process.env.NODE_ENV === "production"
|