@prismicio/simulator 0.2.2-canary.a3b2a3b → 0.2.2
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/kit/SimulatorManager.cjs +1 -4
- package/dist/kit/SimulatorManager.cjs.map +1 -1
- package/dist/kit/SimulatorManager.d.cts.map +1 -1
- package/dist/kit/SimulatorManager.d.ts.map +1 -1
- package/dist/kit/SimulatorManager.js +1 -4
- package/dist/kit/SimulatorManager.js.map +1 -1
- package/dist/kit/State.cjs +5 -8
- package/dist/kit/State.cjs.map +1 -1
- package/dist/kit/State.d.cts.map +1 -1
- package/dist/kit/State.d.ts.map +1 -1
- package/dist/kit/State.js +5 -8
- package/dist/kit/State.js.map +1 -1
- package/dist/kit/messages.cjs +5 -28
- package/dist/kit/messages.cjs.map +1 -1
- package/dist/kit/messages.d.cts.map +1 -1
- package/dist/kit/messages.d.ts.map +1 -1
- package/dist/kit/messages.js +5 -28
- package/dist/kit/messages.js.map +1 -1
- package/package.json +1 -1
- package/src/kit/SimulatorManager.ts +8 -6
- package/src/kit/State.ts +6 -13
- package/src/kit/messages.ts +13 -27
- package/dist/package.cjs +0 -11
- package/dist/package.cjs.map +0 -1
- package/dist/package.js +0 -6
- package/dist/package.js.map +0 -1
|
@@ -20,13 +20,10 @@ var SimulatorManager = class {
|
|
|
20
20
|
if (this._initialized) return;
|
|
21
21
|
else this._initialized = true;
|
|
22
22
|
await this.state.init();
|
|
23
|
-
if (window.parent === window) {
|
|
24
|
-
this.state.message = require_messages.sliceSimulatorAccessedDirectly;
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
23
|
try {
|
|
28
24
|
await this._initAPI();
|
|
29
25
|
} catch (error) {
|
|
26
|
+
if (error instanceof Error && error.message === "Receiver is currently not embedded as an iframe" && !this.state.slices.length) this.state.message = require_messages.sliceSimulatorAccessedDirectly;
|
|
30
27
|
console.error(error);
|
|
31
28
|
return;
|
|
32
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorManager.cjs","names":["State","sliceSimulatorAccessedDirectly","SimulatorAPI","ClientRequestType","getSliceZoneDOM","StateEventType","ResponseError","throttle","getSimulatorRootDOM","getSimulatorDOM"],"sources":["../../src/kit/SimulatorManager.ts"],"sourcesContent":["import type { SliceZone } from \"@prismicio/client\"\n\nimport { ResponseError } from \"../channel\"\nimport { throttle } from \"../lib/throttle\"\nimport { SimulatorAPI } from \"../SimulatorAPI\"\nimport { ClientRequestType } from \"../types\"\nimport { getSimulatorDOM, getSimulatorRootDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { sliceSimulatorAccessedDirectly } from \"./messages\"\nimport { State } from \"./State\"\nimport { StateEventType } from \"./types\"\n\ntype ManagerConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class SimulatorManager {\n\tpublic state: State\n\tprivate _api: SimulatorAPI | null\n\tprivate _initialized: boolean\n\n\tconstructor(args?: ManagerConstructorArgs) {\n\t\tthis.state = new State(args)\n\t\tthis._api = null\n\t\tthis._initialized = false\n\t}\n\n\tasync init(): Promise<void> {\n\t\tif (this._initialized) {\n\t\t\treturn\n\t\t} else {\n\t\t\tthis._initialized = true\n\t\t}\n\n\t\t// Init state manager\n\t\tawait this.state.init()\n\n\t\t//
|
|
1
|
+
{"version":3,"file":"SimulatorManager.cjs","names":["State","sliceSimulatorAccessedDirectly","SimulatorAPI","ClientRequestType","getSliceZoneDOM","StateEventType","ResponseError","throttle","getSimulatorRootDOM","getSimulatorDOM"],"sources":["../../src/kit/SimulatorManager.ts"],"sourcesContent":["import type { SliceZone } from \"@prismicio/client\"\n\nimport { ResponseError } from \"../channel\"\nimport { throttle } from \"../lib/throttle\"\nimport { SimulatorAPI } from \"../SimulatorAPI\"\nimport { ClientRequestType } from \"../types\"\nimport { getSimulatorDOM, getSimulatorRootDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { sliceSimulatorAccessedDirectly } from \"./messages\"\nimport { State } from \"./State\"\nimport { StateEventType } from \"./types\"\n\ntype ManagerConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class SimulatorManager {\n\tpublic state: State\n\tprivate _api: SimulatorAPI | null\n\tprivate _initialized: boolean\n\n\tconstructor(args?: ManagerConstructorArgs) {\n\t\tthis.state = new State(args)\n\t\tthis._api = null\n\t\tthis._initialized = false\n\t}\n\n\tasync init(): Promise<void> {\n\t\tif (this._initialized) {\n\t\t\treturn\n\t\t} else {\n\t\t\tthis._initialized = true\n\t\t}\n\n\t\t// Init state manager\n\t\tawait this.state.init()\n\n\t\t// Init API\n\t\ttry {\n\t\t\tawait this._initAPI()\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\terror.message === \"Receiver is currently not embedded as an iframe\" &&\n\t\t\t\t!this.state.slices.length\n\t\t\t) {\n\t\t\t\t// Catch not embedded error and display message\n\t\t\t\tthis.state.message = sliceSimulatorAccessedDirectly\n\t\t\t}\n\t\t\tconsole.error(error)\n\n\t\t\treturn\n\t\t}\n\n\t\t// Init listeners\n\t\tthis._initListeners()\n\t}\n\n\tprivate async _initAPI(): Promise<void> {\n\t\t// Register SimulatorAPI request handlers\n\t\tthis._api = new SimulatorAPI({\n\t\t\t[ClientRequestType.SetSliceZone]: (req, res) => {\n\t\t\t\tthis.state.setSliceZone(req.data)\n\n\t\t\t\treturn res.success()\n\t\t\t},\n\t\t\t[ClientRequestType.ScrollToSlice]: (req, res) => {\n\t\t\t\t// Error if `sliceIndex` is invalid\n\t\t\t\tif (req.data.sliceIndex < 0) {\n\t\t\t\t\treturn res.error(\"`sliceIndex` must be > 0\", 400)\n\t\t\t\t} else if (req.data.sliceIndex >= this.state.slices.length) {\n\t\t\t\t\treturn res.error(\n\t\t\t\t\t\t`\\`sliceIndex\\` must be < ${this.state.slices.length} (\\`<SliceZone />\\` current length)`,\n\t\t\t\t\t\t400,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tconst $sliceZone = getSliceZoneDOM(this.state.slices.length)\n\t\t\t\tif (!$sliceZone) {\n\t\t\t\t\treturn res.error(\"Failed to find `<SliceZone />`\", 500)\n\t\t\t\t}\n\n\t\t\t\t// Destroy existing active slice as we're about to scroll\n\t\t\t\tthis.state.activeSlice = null\n\n\t\t\t\tconst $slice = $sliceZone.children[req.data.sliceIndex]\n\t\t\t\tif (!$slice) {\n\t\t\t\t\treturn res.error(\n\t\t\t\t\t\t`Failed fo find slice at index $\\`{req.data.sliceIndex}\\` in \\`<SliceZone />\\``,\n\t\t\t\t\t\t500,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\t// Scroll to Slice\n\t\t\t\t$slice.scrollIntoView({\n\t\t\t\t\tbehavior: req.data.behavior,\n\t\t\t\t\tblock: req.data.block,\n\t\t\t\t\tinline: req.data.inline,\n\t\t\t\t})\n\n\t\t\t\t// Update active slice after scrolling\n\t\t\t\tif (this._api?.options.activeSliceAPI) {\n\t\t\t\t\tsetTimeout(this.state.setActiveSlice, 750)\n\t\t\t\t}\n\n\t\t\t\treturn res.success()\n\t\t\t},\n\t\t})\n\n\t\t// Mark API as ready\n\t\tawait this._api.ready()\n\t}\n\n\tprivate _initListeners(): void {\n\t\tif (this._api?.options.activeSliceAPI) {\n\t\t\t// Update active slice on mouse move\n\t\t\twindow.addEventListener(\"mousemove\", () => {\n\t\t\t\tthis.state.setActiveSlice()\n\t\t\t})\n\t\t\t// Update active slice on events impacting slices rendering\n\t\t\twindow.addEventListener(\"resize\", () => {\n\t\t\t\tthis.state.setActiveSlice()\n\t\t\t})\n\t\t\twindow.addEventListener(\"mousewheel\", () => {\n\t\t\t\tsetTimeout(this.state.setActiveSlice, 200)\n\t\t\t})\n\n\t\t\t// Update active slice when slices are set\n\t\t\tthis.state.on(StateEventType.Slices, () => {\n\t\t\t\tthis.state.setActiveSlice()\n\t\t\t})\n\t\t\t// Send active slices to renderer\n\t\t\tthis.state.on(StateEventType.ActiveSlice, async (activeSlice) => {\n\t\t\t\tif (this._api) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this._api.setActiveSlice(activeSlice)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Just log bad requests, throw everything else\n\t\t\t\t\t\tif (error instanceof ResponseError && error.response.status === 400) {\n\t\t\t\t\t\t\tconsole.error(error.response)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tif (this._api?.options.sliceZoneSizeAPI) {\n\t\t\t// Monitor Simulator root node size\n\t\t\tconst resizeObserver = new ResizeObserver(\n\t\t\t\tthrottle(async (entries) => {\n\t\t\t\t\tconst [entry] = entries\n\n\t\t\t\t\tif (this._api && entry) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this._api.setSliceZoneSize({ rect: entry.contentRect })\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Just log bad requests, throw everything else\n\t\t\t\t\t\t\tif (error instanceof ResponseError && error.response.status === 400) {\n\t\t\t\t\t\t\t\tconsole.error(error.response)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthrow error\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}, 16),\n\t\t\t)\n\t\t\tconst observeSimulatorRoot = () => {\n\t\t\t\tconst simulatorRootDOM = getSimulatorRootDOM()\n\t\t\t\tresizeObserver.disconnect()\n\t\t\t\tif (simulatorRootDOM) {\n\t\t\t\t\tresizeObserver.observe(simulatorRootDOM)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Monitor Simulator root node in DOM\n\t\t\tconst mutationObserver = new MutationObserver(observeSimulatorRoot)\n\t\t\t// We want it to fail if not found\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tmutationObserver.observe(getSimulatorDOM()!, {\n\t\t\t\tsubtree: false,\n\t\t\t\tchildList: true,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qB,CAGlD,QAAQC,mBAAAA,iBAAiB,EAAG;IAC5C,SAAS;IACT,WAAW;IACX,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorManager.d.cts","names":[],"sources":["../../src/kit/SimulatorManager.ts"],"mappings":";;;;KAWK,sBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,gBAAA;EACL,KAAA,EAAO,KAAA;EAAA,QACN,IAAA;EAAA,QACA,YAAA;cAEI,IAAA,GAAO,sBAAA;EAMb,IAAA,CAAA,GAAQ,OAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"SimulatorManager.d.cts","names":[],"sources":["../../src/kit/SimulatorManager.ts"],"mappings":";;;;KAWK,sBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,gBAAA;EACL,KAAA,EAAO,KAAA;EAAA,QACN,IAAA;EAAA,QACA,YAAA;cAEI,IAAA,GAAO,sBAAA;EAMb,IAAA,CAAA,GAAQ,OAAA;EAAA,QA+BA,QAAA;EAAA,QAuDN,cAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorManager.d.ts","names":[],"sources":["../../src/kit/SimulatorManager.ts"],"mappings":";;;;KAWK,sBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,gBAAA;EACL,KAAA,EAAO,KAAA;EAAA,QACN,IAAA;EAAA,QACA,YAAA;cAEI,IAAA,GAAO,sBAAA;EAMb,IAAA,CAAA,GAAQ,OAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"SimulatorManager.d.ts","names":[],"sources":["../../src/kit/SimulatorManager.ts"],"mappings":";;;;KAWK,sBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,gBAAA;EACL,KAAA,EAAO,KAAA;EAAA,QACN,IAAA;EAAA,QACA,YAAA;cAEI,IAAA,GAAO,sBAAA;EAMb,IAAA,CAAA,GAAQ,OAAA;EAAA,QA+BA,QAAA;EAAA,QAuDN,cAAA;AAAA"}
|
|
@@ -20,13 +20,10 @@ var SimulatorManager = class {
|
|
|
20
20
|
if (this._initialized) return;
|
|
21
21
|
else this._initialized = true;
|
|
22
22
|
await this.state.init();
|
|
23
|
-
if (window.parent === window) {
|
|
24
|
-
this.state.message = sliceSimulatorAccessedDirectly;
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
23
|
try {
|
|
28
24
|
await this._initAPI();
|
|
29
25
|
} catch (error) {
|
|
26
|
+
if (error instanceof Error && error.message === "Receiver is currently not embedded as an iframe" && !this.state.slices.length) this.state.message = sliceSimulatorAccessedDirectly;
|
|
30
27
|
console.error(error);
|
|
31
28
|
return;
|
|
32
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimulatorManager.js","names":[],"sources":["../../src/kit/SimulatorManager.ts"],"sourcesContent":["import type { SliceZone } from \"@prismicio/client\"\n\nimport { ResponseError } from \"../channel\"\nimport { throttle } from \"../lib/throttle\"\nimport { SimulatorAPI } from \"../SimulatorAPI\"\nimport { ClientRequestType } from \"../types\"\nimport { getSimulatorDOM, getSimulatorRootDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { sliceSimulatorAccessedDirectly } from \"./messages\"\nimport { State } from \"./State\"\nimport { StateEventType } from \"./types\"\n\ntype ManagerConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class SimulatorManager {\n\tpublic state: State\n\tprivate _api: SimulatorAPI | null\n\tprivate _initialized: boolean\n\n\tconstructor(args?: ManagerConstructorArgs) {\n\t\tthis.state = new State(args)\n\t\tthis._api = null\n\t\tthis._initialized = false\n\t}\n\n\tasync init(): Promise<void> {\n\t\tif (this._initialized) {\n\t\t\treturn\n\t\t} else {\n\t\t\tthis._initialized = true\n\t\t}\n\n\t\t// Init state manager\n\t\tawait this.state.init()\n\n\t\t//
|
|
1
|
+
{"version":3,"file":"SimulatorManager.js","names":[],"sources":["../../src/kit/SimulatorManager.ts"],"sourcesContent":["import type { SliceZone } from \"@prismicio/client\"\n\nimport { ResponseError } from \"../channel\"\nimport { throttle } from \"../lib/throttle\"\nimport { SimulatorAPI } from \"../SimulatorAPI\"\nimport { ClientRequestType } from \"../types\"\nimport { getSimulatorDOM, getSimulatorRootDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { sliceSimulatorAccessedDirectly } from \"./messages\"\nimport { State } from \"./State\"\nimport { StateEventType } from \"./types\"\n\ntype ManagerConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class SimulatorManager {\n\tpublic state: State\n\tprivate _api: SimulatorAPI | null\n\tprivate _initialized: boolean\n\n\tconstructor(args?: ManagerConstructorArgs) {\n\t\tthis.state = new State(args)\n\t\tthis._api = null\n\t\tthis._initialized = false\n\t}\n\n\tasync init(): Promise<void> {\n\t\tif (this._initialized) {\n\t\t\treturn\n\t\t} else {\n\t\t\tthis._initialized = true\n\t\t}\n\n\t\t// Init state manager\n\t\tawait this.state.init()\n\n\t\t// Init API\n\t\ttry {\n\t\t\tawait this._initAPI()\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\terror.message === \"Receiver is currently not embedded as an iframe\" &&\n\t\t\t\t!this.state.slices.length\n\t\t\t) {\n\t\t\t\t// Catch not embedded error and display message\n\t\t\t\tthis.state.message = sliceSimulatorAccessedDirectly\n\t\t\t}\n\t\t\tconsole.error(error)\n\n\t\t\treturn\n\t\t}\n\n\t\t// Init listeners\n\t\tthis._initListeners()\n\t}\n\n\tprivate async _initAPI(): Promise<void> {\n\t\t// Register SimulatorAPI request handlers\n\t\tthis._api = new SimulatorAPI({\n\t\t\t[ClientRequestType.SetSliceZone]: (req, res) => {\n\t\t\t\tthis.state.setSliceZone(req.data)\n\n\t\t\t\treturn res.success()\n\t\t\t},\n\t\t\t[ClientRequestType.ScrollToSlice]: (req, res) => {\n\t\t\t\t// Error if `sliceIndex` is invalid\n\t\t\t\tif (req.data.sliceIndex < 0) {\n\t\t\t\t\treturn res.error(\"`sliceIndex` must be > 0\", 400)\n\t\t\t\t} else if (req.data.sliceIndex >= this.state.slices.length) {\n\t\t\t\t\treturn res.error(\n\t\t\t\t\t\t`\\`sliceIndex\\` must be < ${this.state.slices.length} (\\`<SliceZone />\\` current length)`,\n\t\t\t\t\t\t400,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tconst $sliceZone = getSliceZoneDOM(this.state.slices.length)\n\t\t\t\tif (!$sliceZone) {\n\t\t\t\t\treturn res.error(\"Failed to find `<SliceZone />`\", 500)\n\t\t\t\t}\n\n\t\t\t\t// Destroy existing active slice as we're about to scroll\n\t\t\t\tthis.state.activeSlice = null\n\n\t\t\t\tconst $slice = $sliceZone.children[req.data.sliceIndex]\n\t\t\t\tif (!$slice) {\n\t\t\t\t\treturn res.error(\n\t\t\t\t\t\t`Failed fo find slice at index $\\`{req.data.sliceIndex}\\` in \\`<SliceZone />\\``,\n\t\t\t\t\t\t500,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\t// Scroll to Slice\n\t\t\t\t$slice.scrollIntoView({\n\t\t\t\t\tbehavior: req.data.behavior,\n\t\t\t\t\tblock: req.data.block,\n\t\t\t\t\tinline: req.data.inline,\n\t\t\t\t})\n\n\t\t\t\t// Update active slice after scrolling\n\t\t\t\tif (this._api?.options.activeSliceAPI) {\n\t\t\t\t\tsetTimeout(this.state.setActiveSlice, 750)\n\t\t\t\t}\n\n\t\t\t\treturn res.success()\n\t\t\t},\n\t\t})\n\n\t\t// Mark API as ready\n\t\tawait this._api.ready()\n\t}\n\n\tprivate _initListeners(): void {\n\t\tif (this._api?.options.activeSliceAPI) {\n\t\t\t// Update active slice on mouse move\n\t\t\twindow.addEventListener(\"mousemove\", () => {\n\t\t\t\tthis.state.setActiveSlice()\n\t\t\t})\n\t\t\t// Update active slice on events impacting slices rendering\n\t\t\twindow.addEventListener(\"resize\", () => {\n\t\t\t\tthis.state.setActiveSlice()\n\t\t\t})\n\t\t\twindow.addEventListener(\"mousewheel\", () => {\n\t\t\t\tsetTimeout(this.state.setActiveSlice, 200)\n\t\t\t})\n\n\t\t\t// Update active slice when slices are set\n\t\t\tthis.state.on(StateEventType.Slices, () => {\n\t\t\t\tthis.state.setActiveSlice()\n\t\t\t})\n\t\t\t// Send active slices to renderer\n\t\t\tthis.state.on(StateEventType.ActiveSlice, async (activeSlice) => {\n\t\t\t\tif (this._api) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait this._api.setActiveSlice(activeSlice)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Just log bad requests, throw everything else\n\t\t\t\t\t\tif (error instanceof ResponseError && error.response.status === 400) {\n\t\t\t\t\t\t\tconsole.error(error.response)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tif (this._api?.options.sliceZoneSizeAPI) {\n\t\t\t// Monitor Simulator root node size\n\t\t\tconst resizeObserver = new ResizeObserver(\n\t\t\t\tthrottle(async (entries) => {\n\t\t\t\t\tconst [entry] = entries\n\n\t\t\t\t\tif (this._api && entry) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this._api.setSliceZoneSize({ rect: entry.contentRect })\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t// Just log bad requests, throw everything else\n\t\t\t\t\t\t\tif (error instanceof ResponseError && error.response.status === 400) {\n\t\t\t\t\t\t\t\tconsole.error(error.response)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthrow error\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}, 16),\n\t\t\t)\n\t\t\tconst observeSimulatorRoot = () => {\n\t\t\t\tconst simulatorRootDOM = getSimulatorRootDOM()\n\t\t\t\tresizeObserver.disconnect()\n\t\t\t\tif (simulatorRootDOM) {\n\t\t\t\t\tresizeObserver.observe(simulatorRootDOM)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Monitor Simulator root node in DOM\n\t\t\tconst mutationObserver = new MutationObserver(observeSimulatorRoot)\n\t\t\t// We want it to fail if not found\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tmutationObserver.observe(getSimulatorDOM()!, {\n\t\t\t\tsubtree: false,\n\t\t\t\tchildList: true,\n\t\t\t})\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;AAeA,IAAa,mBAAb,MAA8B;CAC7B;CACA;CACA;CAEA,YAAY,MAA+B;AAC1C,OAAK,QAAQ,IAAI,MAAM,KAAK;AAC5B,OAAK,OAAO;AACZ,OAAK,eAAe;;CAGrB,MAAM,OAAsB;AAC3B,MAAI,KAAK,aACR;MAEA,MAAK,eAAe;AAIrB,QAAM,KAAK,MAAM,MAAM;AAGvB,MAAI;AACH,SAAM,KAAK,UAAU;WACb,OAAO;AACf,OACC,iBAAiB,SACjB,MAAM,YAAY,qDAClB,CAAC,KAAK,MAAM,OAAO,OAGnB,MAAK,MAAM,UAAU;AAEtB,WAAQ,MAAM,MAAM;AAEpB;;AAID,OAAK,gBAAgB;;CAGtB,MAAc,WAA0B;AAEvC,OAAK,OAAO,IAAI,aAAa;IAC3B,kBAAkB,gBAAgB,KAAK,QAAQ;AAC/C,SAAK,MAAM,aAAa,IAAI,KAAK;AAEjC,WAAO,IAAI,SAAS;;IAEpB,kBAAkB,iBAAiB,KAAK,QAAQ;AAEhD,QAAI,IAAI,KAAK,aAAa,EACzB,QAAO,IAAI,MAAM,4BAA4B,IAAI;aACvC,IAAI,KAAK,cAAc,KAAK,MAAM,OAAO,OACnD,QAAO,IAAI,MACV,4BAA4B,KAAK,MAAM,OAAO,OAAO,sCACrD,IACA;IAGF,MAAM,aAAa,gBAAgB,KAAK,MAAM,OAAO,OAAO;AAC5D,QAAI,CAAC,WACJ,QAAO,IAAI,MAAM,kCAAkC,IAAI;AAIxD,SAAK,MAAM,cAAc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ACN;GACD,MAAM,6BAA6B;IAClC,MAAM,mBAAmB,qBAAqB;AAC9C,mBAAe,YAAY;AAC3B,QAAI,iBACH,gBAAe,QAAQ,iBAAiB;;AAKjB,OAAI,iBAAiB,qBAAqB,CAGlD,QAAQ,iBAAiB,EAAG;IAC5C,SAAS;IACT,WAAW;IACX,CAAC"}
|
package/dist/kit/State.cjs
CHANGED
|
@@ -8,17 +8,16 @@ var State = class extends require_EventEmitter.EventEmitter {
|
|
|
8
8
|
_slices;
|
|
9
9
|
set slices(slices) {
|
|
10
10
|
this._slices = slices;
|
|
11
|
-
this.
|
|
12
|
-
this.emit(require_types.StateEventType.Slices,
|
|
13
|
-
this.emit(require_types.StateEventType.Message, this.message);
|
|
11
|
+
this.message = "";
|
|
12
|
+
this.emit(require_types.StateEventType.Slices, slices);
|
|
14
13
|
}
|
|
15
14
|
get slices() {
|
|
16
|
-
return
|
|
15
|
+
return this._slices;
|
|
17
16
|
}
|
|
18
17
|
_activeSlice;
|
|
19
18
|
set activeSlice(activeSlice) {
|
|
20
19
|
this._activeSlice = activeSlice;
|
|
21
|
-
this.emit(require_types.StateEventType.ActiveSlice,
|
|
20
|
+
this.emit(require_types.StateEventType.ActiveSlice, activeSlice);
|
|
22
21
|
}
|
|
23
22
|
get activeSlice() {
|
|
24
23
|
return this._activeSlice;
|
|
@@ -26,9 +25,7 @@ var State = class extends require_EventEmitter.EventEmitter {
|
|
|
26
25
|
_message;
|
|
27
26
|
set message(message) {
|
|
28
27
|
this._message = message;
|
|
29
|
-
this.
|
|
30
|
-
this.emit(require_types.StateEventType.Message, this.message);
|
|
31
|
-
this.emit(require_types.StateEventType.Slices, this.slices);
|
|
28
|
+
this.emit(require_types.StateEventType.Message, message);
|
|
32
29
|
}
|
|
33
30
|
get message() {
|
|
34
31
|
return this._message;
|
package/dist/kit/State.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.cjs","names":["EventEmitter","StateEventType","getDefaultSlices","getSliceZoneDOM","getActiveSliceDOM","throttle"],"sources":["../../src/kit/State.ts"],"sourcesContent":["import type { SharedSlice, SliceZone } from \"@prismicio/client\"\n\nimport { __PRODUCTION__ } from \"../lib/__PRODUCTION__\"\nimport { EventEmitter } from \"../lib/EventEmitter\"\nimport { throttle } from \"../lib/throttle\"\nimport type { ActiveSlice } from \"../types\"\nimport { getActiveSliceDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { getDefaultSlices } from \"./getDefault\"\nimport type { StateEvents } from \"./types\"\nimport { StateEventType } from \"./types\"\n\ntype StateConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class State extends EventEmitter<StateEvents> {\n\tprivate _slices: SliceZone\n\tpublic set slices(slices: SliceZone) {\n\t\tthis._slices = slices\n\t\t// Clean up message\n\t\tthis.
|
|
1
|
+
{"version":3,"file":"State.cjs","names":["EventEmitter","StateEventType","getDefaultSlices","getSliceZoneDOM","getActiveSliceDOM","throttle"],"sources":["../../src/kit/State.ts"],"sourcesContent":["import type { SharedSlice, SliceZone } from \"@prismicio/client\"\n\nimport { __PRODUCTION__ } from \"../lib/__PRODUCTION__\"\nimport { EventEmitter } from \"../lib/EventEmitter\"\nimport { throttle } from \"../lib/throttle\"\nimport type { ActiveSlice } from \"../types\"\nimport { getActiveSliceDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { getDefaultSlices } from \"./getDefault\"\nimport type { StateEvents } from \"./types\"\nimport { StateEventType } from \"./types\"\n\ntype StateConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class State extends EventEmitter<StateEvents> {\n\tprivate _slices: SliceZone\n\tpublic set slices(slices: SliceZone) {\n\t\tthis._slices = slices\n\t\t// Clean up message\n\t\tthis.message = \"\"\n\t\t// Dispatch event\n\t\tthis.emit(StateEventType.Slices, slices)\n\t}\n\tpublic get slices(): SliceZone {\n\t\treturn this._slices\n\t}\n\n\tprivate _activeSlice: ActiveSlice | null\n\tpublic set activeSlice(activeSlice: ActiveSlice | null) {\n\t\tthis._activeSlice = activeSlice\n\t\tthis.emit(StateEventType.ActiveSlice, activeSlice)\n\t}\n\tpublic get activeSlice(): ActiveSlice | null {\n\t\treturn this._activeSlice\n\t}\n\n\tprivate _message: string\n\tpublic set message(message: string) {\n\t\tthis._message = message\n\t\tthis.emit(StateEventType.Message, message)\n\t}\n\tpublic get message(): string {\n\t\treturn this._message\n\t}\n\n\tprivate _mouse: { x: number; y: number }\n\n\tconstructor(args?: StateConstructorArgs) {\n\t\tsuper()\n\n\t\tthis._slices = args?.slices || getDefaultSlices()\n\t\tthis._activeSlice = null\n\t\tthis._message = \"\"\n\n\t\t// StateManager needs to keep track of mouse position for the active slice\n\t\tthis._mouse = { x: 0, y: 0 }\n\t}\n\n\tasync init(): Promise<void> {\n\t\t// Init listener\n\t\twindow.addEventListener(\"mousemove\", (event) => {\n\t\t\tthis._mouse = { x: event.clientX, y: event.clientY }\n\t\t})\n\t}\n\n\tprivate _setActiveSlice = (): void => {\n\t\t// There can't be an active slice if there's no slice displayed\n\t\tif (this.slices.length === 0) {\n\t\t\tthis.activeSlice = null\n\n\t\t\treturn\n\t\t}\n\n\t\tconst $sliceZone = getSliceZoneDOM(this.slices.length)\n\n\t\t// SliceZone has not been found, therefore active slice cannot be found\n\t\tif (!$sliceZone) {\n\t\t\tthis.activeSlice = null\n\n\t\t\treturn\n\t\t}\n\n\t\tconst $activeSlice = getActiveSliceDOM($sliceZone, this._mouse)\n\n\t\t// Active slice has not been found\n\t\tif (!$activeSlice) {\n\t\t\tthis.activeSlice = null\n\n\t\t\treturn\n\t\t}\n\n\t\tconst activeSliceIndex = Array.prototype.indexOf.call($sliceZone.children, $activeSlice)\n\n\t\t// Active slice has been found\n\t\tthis.activeSlice = {\n\t\t\trect: $activeSlice.getBoundingClientRect(),\n\t\t\tsliceID: this.slices[activeSliceIndex].slice_type,\n\t\t\tvariationID: (this.slices[activeSliceIndex] as SharedSlice).variation,\n\t\t\tindex: activeSliceIndex,\n\t\t}\n\t}\n\tsetActi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AGxF,OAAK,cAAc;GAClB,MAAM,aAAa,uBAAuB;GAC1C,SAAS,KAAK,OAAO,kBAAkB;GACvC,aAAc,KAAK,OAAO,kBAAkC;GAC5D,OAAO;GACP;;CAEF,iBAAiBC,iBAAAA,SAAS,KAAK,iBAAiB,GAAG;CAEnD,aAAa,QAAyB;AAErC,OAAK,SAAS"}
|
package/dist/kit/State.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.cts","names":[],"sources":["../../src/kit/State.ts"],"mappings":";;;;;;KAWK,oBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,KAAA,SAAc,YAAA,CAAa,WAAA;EAAA,QAC/B,OAAA;EAAA,IACG,MAAA,CAAO,MAAA,EAAQ,SAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"State.d.cts","names":[],"sources":["../../src/kit/State.ts"],"mappings":";;;;;;KAWK,oBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,KAAA,SAAc,YAAA,CAAa,WAAA;EAAA,QAC/B,OAAA;EAAA,IACG,MAAA,CAAO,MAAA,EAAQ,SAAA;EAAA,IAOf,MAAA,CAAA,GAAU,SAAA;EAAA,QAIb,YAAA;EAAA,IACG,WAAA,CAAY,WAAA,EAAa,WAAA;EAAA,IAIzB,WAAA,CAAA,GAAe,WAAA;EAAA,QAIlB,QAAA;EAAA,IACG,OAAA,CAAQ,OAAA;EAAA,IAIR,OAAA,CAAA;EAAA,QAIH,MAAA;cAEI,IAAA,GAAO,oBAAA;EAWb,IAAA,CAAA,GAAQ,OAAA;EAAA,QAON,eAAA;EAoCR,cAAA;EAEA,YAAA,CAAa,MAAA,EAAQ,SAAA;AAAA"}
|
package/dist/kit/State.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.d.ts","names":[],"sources":["../../src/kit/State.ts"],"mappings":";;;;;;KAWK,oBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,KAAA,SAAc,YAAA,CAAa,WAAA;EAAA,QAC/B,OAAA;EAAA,IACG,MAAA,CAAO,MAAA,EAAQ,SAAA;EAAA,
|
|
1
|
+
{"version":3,"file":"State.d.ts","names":[],"sources":["../../src/kit/State.ts"],"mappings":";;;;;;KAWK,oBAAA;EACJ,MAAA,GAAS,SAAA;AAAA;AAAA,cAGG,KAAA,SAAc,YAAA,CAAa,WAAA;EAAA,QAC/B,OAAA;EAAA,IACG,MAAA,CAAO,MAAA,EAAQ,SAAA;EAAA,IAOf,MAAA,CAAA,GAAU,SAAA;EAAA,QAIb,YAAA;EAAA,IACG,WAAA,CAAY,WAAA,EAAa,WAAA;EAAA,IAIzB,WAAA,CAAA,GAAe,WAAA;EAAA,QAIlB,QAAA;EAAA,IACG,OAAA,CAAQ,OAAA;EAAA,IAIR,OAAA,CAAA;EAAA,QAIH,MAAA;cAEI,IAAA,GAAO,oBAAA;EAWb,IAAA,CAAA,GAAQ,OAAA;EAAA,QAON,eAAA;EAoCR,cAAA;EAEA,YAAA,CAAa,MAAA,EAAQ,SAAA;AAAA"}
|
package/dist/kit/State.js
CHANGED
|
@@ -8,17 +8,16 @@ var State = class extends EventEmitter {
|
|
|
8
8
|
_slices;
|
|
9
9
|
set slices(slices) {
|
|
10
10
|
this._slices = slices;
|
|
11
|
-
this.
|
|
12
|
-
this.emit(StateEventType.Slices,
|
|
13
|
-
this.emit(StateEventType.Message, this.message);
|
|
11
|
+
this.message = "";
|
|
12
|
+
this.emit(StateEventType.Slices, slices);
|
|
14
13
|
}
|
|
15
14
|
get slices() {
|
|
16
|
-
return
|
|
15
|
+
return this._slices;
|
|
17
16
|
}
|
|
18
17
|
_activeSlice;
|
|
19
18
|
set activeSlice(activeSlice) {
|
|
20
19
|
this._activeSlice = activeSlice;
|
|
21
|
-
this.emit(StateEventType.ActiveSlice,
|
|
20
|
+
this.emit(StateEventType.ActiveSlice, activeSlice);
|
|
22
21
|
}
|
|
23
22
|
get activeSlice() {
|
|
24
23
|
return this._activeSlice;
|
|
@@ -26,9 +25,7 @@ var State = class extends EventEmitter {
|
|
|
26
25
|
_message;
|
|
27
26
|
set message(message) {
|
|
28
27
|
this._message = message;
|
|
29
|
-
this.
|
|
30
|
-
this.emit(StateEventType.Message, this.message);
|
|
31
|
-
this.emit(StateEventType.Slices, this.slices);
|
|
28
|
+
this.emit(StateEventType.Message, message);
|
|
32
29
|
}
|
|
33
30
|
get message() {
|
|
34
31
|
return this._message;
|
package/dist/kit/State.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"State.js","names":[],"sources":["../../src/kit/State.ts"],"sourcesContent":["import type { SharedSlice, SliceZone } from \"@prismicio/client\"\n\nimport { __PRODUCTION__ } from \"../lib/__PRODUCTION__\"\nimport { EventEmitter } from \"../lib/EventEmitter\"\nimport { throttle } from \"../lib/throttle\"\nimport type { ActiveSlice } from \"../types\"\nimport { getActiveSliceDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { getDefaultSlices } from \"./getDefault\"\nimport type { StateEvents } from \"./types\"\nimport { StateEventType } from \"./types\"\n\ntype StateConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class State extends EventEmitter<StateEvents> {\n\tprivate _slices: SliceZone\n\tpublic set slices(slices: SliceZone) {\n\t\tthis._slices = slices\n\t\t// Clean up message\n\t\tthis.
|
|
1
|
+
{"version":3,"file":"State.js","names":[],"sources":["../../src/kit/State.ts"],"sourcesContent":["import type { SharedSlice, SliceZone } from \"@prismicio/client\"\n\nimport { __PRODUCTION__ } from \"../lib/__PRODUCTION__\"\nimport { EventEmitter } from \"../lib/EventEmitter\"\nimport { throttle } from \"../lib/throttle\"\nimport type { ActiveSlice } from \"../types\"\nimport { getActiveSliceDOM, getSliceZoneDOM } from \"./domHelpers\"\nimport { getDefaultSlices } from \"./getDefault\"\nimport type { StateEvents } from \"./types\"\nimport { StateEventType } from \"./types\"\n\ntype StateConstructorArgs = {\n\tslices?: SliceZone\n}\n\nexport class State extends EventEmitter<StateEvents> {\n\tprivate _slices: SliceZone\n\tpublic set slices(slices: SliceZone) {\n\t\tthis._slices = slices\n\t\t// Clean up message\n\t\tthis.message = \"\"\n\t\t// Dispatch event\n\t\tthis.emit(StateEventType.Slices, slices)\n\t}\n\tpublic get slices(): SliceZone {\n\t\treturn this._slices\n\t}\n\n\tprivate _activeSlice: ActiveSlice | null\n\tpublic set activeSlice(activeSlice: ActiveSlice | null) {\n\t\tthis._activeSlice = activeSlice\n\t\tthis.emit(StateEventType.ActiveSlice, activeSlice)\n\t}\n\tpublic get activeSlice(): ActiveSlice | null {\n\t\treturn this._activeSlice\n\t}\n\n\tprivate _message: string\n\tpublic set message(message: string) {\n\t\tthis._message = message\n\t\tthis.emit(StateEventType.Message, message)\n\t}\n\tpublic get message(): string {\n\t\treturn this._message\n\t}\n\n\tprivate _mouse: { x: number; y: number }\n\n\tconstructor(args?: StateConstructorArgs) {\n\t\tsuper()\n\n\t\tthis._slices = args?.slices || getDefaultSlices()\n\t\tthis._activeSlice = null\n\t\tthis._message = \"\"\n\n\t\t// StateManager needs to keep track of mouse position for the active slice\n\t\tthis._mouse = { x: 0, y: 0 }\n\t}\n\n\tasync init(): Promise<void> {\n\t\t// Init listener\n\t\twindow.addEventListener(\"mousemove\", (event) => {\n\t\t\tthis._mouse = { x: event.clientX, y: event.clientY }\n\t\t})\n\t}\n\n\tprivate _setActiveSlice = (): void => {\n\t\t// There can't be an active slice if there's no slice displayed\n\t\tif (this.slices.length === 0) {\n\t\t\tthis.activeSlice = null\n\n\t\t\treturn\n\t\t}\n\n\t\tconst $sliceZone = getSliceZoneDOM(this.slices.length)\n\n\t\t// SliceZone has not been found, therefore active slice cannot be found\n\t\tif (!$sliceZone) {\n\t\t\tthis.activeSlice = null\n\n\t\t\treturn\n\t\t}\n\n\t\tconst $activeSlice = getActiveSliceDOM($sliceZone, this._mouse)\n\n\t\t// Active slice has not been found\n\t\tif (!$activeSlice) {\n\t\t\tthis.activeSlice = null\n\n\t\t\treturn\n\t\t}\n\n\t\tconst activeSliceIndex = Array.prototype.indexOf.call($sliceZone.children, $activeSlice)\n\n\t\t// Active slice has been found\n\t\tthis.activeSlice = {\n\t\t\trect: $activeSlice.getBoundingClientRect(),\n\t\t\tsliceID: this.slices[activeSliceIndex].slice_type,\n\t\t\tvariationID: (this.slices[activeSliceIndex] as SharedSlice).variation,\n\t\t\tindex: activeSliceIndex,\n\t\t}\n\t}\n\tsetActiveSlice = throttle(this._setActiveSlice, 16)\n\n\tsetSliceZone(slices: SliceZone): void {\n\t\t// Set slices\n\t\tthis.slices = slices\n\t}\n}\n"],"mappings":";;;;;;AAeA,IAAa,QAAb,cAA2B,aAA0B;CACpD;CACA,IAAW,OAAO,QAAmB;AACpC,OAAK,UAAU;AAEf,OAAK,UAAU;AAEf,OAAK,KAAK,eAAe,QAAQ,OAAO;;CAEzC,IAAW,SAAoB;AAC9B,SAAO,KAAK;;CAGb;CACA,IAAW,YAAY,aAAiC;AACvD,OAAK,eAAe;AACpB,OAAK,KAAK,eAAe,aAAa,YAAY;;CAEnD,IAAW,cAAkC;AAC5C,SAAO,KAAK;;CAGb;CACA,IAAW,QAAQ,SAAiB;AACnC,OAAK,WAAW;AAChB,OAAK,KAAK,eAAe,SAAS,QAAQ;;CAE3C,IAAW,UAAkB;AAC5B,SAAO,KAAK;;CAGb;CAEA,YAAY,MAA6B;AACxC,SAAO;AAEP,OAAK,UAAU,MAAM,UAAU,kBAAkB;AACjD,OAAK,eAAe;AACpB,OAAK,WAAW;AAGhB,OAAK,SAAS;GAAE,GAAG;GAAG,GAAG;GAAG;;CAG7B,MAAM,OAAsB;AAE3B,SAAO,iBAAiB,cAAc,UAAU;AAC/C,QAAK,SAAS;IAAE,GAAG,MAAM;IAAS,GAAG,MAAM;IAAS;IACnD;;CAGH,wBAAsC;AAErC,MAAI,KAAK,OAAO,WAAW,GAAG;AAC7B,QAAK,cAAc;AAEnB;;EAGD,MAAM,aAAa,gBAAgB,KAAK,OAAO,OAAO;AAGtD,MAAI,CAAC,YAAY;AAChB,QAAK,cAAc;AAEnB;;EAGD,MAAM,eAAe,kBAAkB,YAAY,KAAK,OAAO;AAG/D,MAAI,CAAC,cAAc;AAClB,QAAK,cAAc;AAEnB;;EAGD,MAAM,mBAAmB,MAAM,UAAU,QAAQ,KAAK,WAAW,UAAU,aAAa;AAGxF,OAAK,cAAc;GAClB,MAAM,aAAa,uBAAuB;GAC1C,SAAS,KAAK,OAAO,kBAAkB;GACvC,aAAc,KAAK,OAAO,kBAAkC;GAC5D,OAAO;GACP;;CAEF,iBAAiB,SAAS,KAAK,iBAAiB,GAAG;CAEnD,aAAa,QAAyB;AAErC,OAAK,SAAS"}
|
package/dist/kit/messages.cjs
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
const require_package = require("../package.cjs");
|
|
2
1
|
//#region src/kit/messages.ts
|
|
3
2
|
const div = (content) => `<div style="word-spacing: initial; white-space: pre; line-height: initial; font-family: monospace; color: #ffffff; mix-blend-mode: difference; padding: 1rem; font-size: 1rem;">${content}</div>`;
|
|
4
3
|
const a = (href, label) => `<a href="${href}" style="text-decoration: underline;">${label || href}<a>`;
|
|
5
|
-
const sliceSimulatorAccessedDirectly = div(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
directly, e.g:
|
|
11
|
-
|
|
12
|
-
- ${a("http://localhost:3000/slice-simulator")}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
The Slice simulator can only be accessed through Slice Machine or
|
|
17
|
-
your repository.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
If you believe this is an error, please reach out to us:
|
|
22
|
-
|
|
23
|
-
- ${a("https://github.com/prismicio/slice-simulator/issues/new/choose")}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- The Prismic team`);
|
|
4
|
+
const sliceSimulatorAccessedDirectly = div([
|
|
5
|
+
" _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ `__ \\/ / / / / __ `/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ `__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/\n\n",
|
|
6
|
+
`You're seeing this page because you're accessing Slice simulator\ndirectly, e.g:\n\n - ${a("http://localhost:3000/slice-simulator")}\n\n\n\nThe Slice simulator can only be accessed through Slice Machine or the\nPage Builder. To preview your Slices, head over to Slice Machine:\n\n - ${a("http://localhost:9999")}\n\n\n\nIf you believe this is an error, please reach out to us:\n\n - ${a("https://github.com/prismicio/slice-machine/issues/new/choose")}`,
|
|
7
|
+
"\n\n\n\n\n\n - The Prismic team"
|
|
8
|
+
].join(""));
|
|
32
9
|
//#endregion
|
|
33
10
|
exports.sliceSimulatorAccessedDirectly = sliceSimulatorAccessedDirectly;
|
|
34
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.cjs","names":[
|
|
1
|
+
{"version":3,"file":"messages.cjs","names":[],"sources":["../../src/kit/messages.ts"],"sourcesContent":["const div = (content: string) =>\n\t`<div style=\"word-spacing: initial; white-space: pre; line-height: initial; font-family: monospace; color: #ffffff; mix-blend-mode: difference; padding: 1rem; font-size: 1rem;\">${content}</div>`\n\nconst a = (href: string, label?: string) =>\n\t`<a href=\"${href}\" style=\"text-decoration: underline;\">${label || href}<a>`\n\nconst header =\n\t\" _____ ___ _____ _ __ __ \\n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\\n \\\\__ \\\\/ / / ___/ _ \\\\\\\\__ \\\\/ / __ `__ \\\\/ / / / / __ `/ __/ __ \\\\/ ___/\\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \\n/____/_/_/\\\\___/\\\\___/____/_/_/ /_/ /_/\\\\__,_/_/\\\\__,_/\\\\__/\\\\____/_/ \\n / /_ __ __ / __ \\\\_____(_)________ ___ (_)____\\n / __ \\\\/ / / / / /_/ / ___/ / ___/ __ `__ \\\\/ / ___/\\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \\n /_.___/\\\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\\\___/ \\n /____/\\n\\n\"\n\nconst footer = \"\\n\\n\\n\\n\\n\\n - The Prismic team\"\n\nexport const sliceSimulatorAccessedDirectly = div(\n\t[\n\t\theader,\n\t\t`You're seeing this page because you're accessing Slice simulator\\ndirectly, e.g:\\n\\n - ${a(\n\t\t\t\"http://localhost:3000/slice-simulator\",\n\t\t)}\\n\\n\\n\\nThe Slice simulator can only be accessed through Slice Machine or the\\nPage Builder. To preview your Slices, head over to Slice Machine:\\n\\n - ${a(\n\t\t\t\"http://localhost:9999\",\n\t\t)}\\n\\n\\n\\nIf you believe this is an error, please reach out to us:\\n\\n - ${a(\n\t\t\t\"https://github.com/prismicio/slice-machine/issues/new/choose\",\n\t\t)}`,\n\t\tfooter,\n\t].join(\"\"),\n)\n"],"mappings":";AAAA,MAAM,OAAO,YACZ,mLAAmL,QAAQ;AAE5L,MAAM,KAAK,MAAc,UACxB,YAAY,KAAK,wCAAwC,SAAS,KAAK;AAOxE,MAAa,iCAAiC,IAC7C;CALA;CAOC,2FAA2F,EAC1F,wCACA,CAAC,0JAA0J,EAC3J,wBACA,CAAC,0EAA0E,EAC3E,+DACA;CAXY;CAab,CAAC,KAAK,GAAG,CACV"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.cts","names":[],"sources":["../../src/kit/messages.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"messages.d.cts","names":[],"sources":["../../src/kit/messages.ts"],"mappings":";cAWa,8BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","names":[],"sources":["../../src/kit/messages.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"messages.d.ts","names":[],"sources":["../../src/kit/messages.ts"],"mappings":";cAWa,8BAAA"}
|
package/dist/kit/messages.js
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
import { version } from "../package.js";
|
|
2
1
|
//#region src/kit/messages.ts
|
|
3
2
|
const div = (content) => `<div style="word-spacing: initial; white-space: pre; line-height: initial; font-family: monospace; color: #ffffff; mix-blend-mode: difference; padding: 1rem; font-size: 1rem;">${content}</div>`;
|
|
4
3
|
const a = (href, label) => `<a href="${href}" style="text-decoration: underline;">${label || href}<a>`;
|
|
5
|
-
const sliceSimulatorAccessedDirectly = div(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
directly, e.g:
|
|
11
|
-
|
|
12
|
-
- ${a("http://localhost:3000/slice-simulator")}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
The Slice simulator can only be accessed through Slice Machine or
|
|
17
|
-
your repository.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
If you believe this is an error, please reach out to us:
|
|
22
|
-
|
|
23
|
-
- ${a("https://github.com/prismicio/slice-simulator/issues/new/choose")}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- The Prismic team`);
|
|
4
|
+
const sliceSimulatorAccessedDirectly = div([
|
|
5
|
+
" _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ `__ \\/ / / / / __ `/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ `__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/\n\n",
|
|
6
|
+
`You're seeing this page because you're accessing Slice simulator\ndirectly, e.g:\n\n - ${a("http://localhost:3000/slice-simulator")}\n\n\n\nThe Slice simulator can only be accessed through Slice Machine or the\nPage Builder. To preview your Slices, head over to Slice Machine:\n\n - ${a("http://localhost:9999")}\n\n\n\nIf you believe this is an error, please reach out to us:\n\n - ${a("https://github.com/prismicio/slice-machine/issues/new/choose")}`,
|
|
7
|
+
"\n\n\n\n\n\n - The Prismic team"
|
|
8
|
+
].join(""));
|
|
32
9
|
//#endregion
|
|
33
10
|
export { sliceSimulatorAccessedDirectly };
|
|
34
11
|
|
package/dist/kit/messages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","names":[],"sources":["../../src/kit/messages.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"messages.js","names":[],"sources":["../../src/kit/messages.ts"],"sourcesContent":["const div = (content: string) =>\n\t`<div style=\"word-spacing: initial; white-space: pre; line-height: initial; font-family: monospace; color: #ffffff; mix-blend-mode: difference; padding: 1rem; font-size: 1rem;\">${content}</div>`\n\nconst a = (href: string, label?: string) =>\n\t`<a href=\"${href}\" style=\"text-decoration: underline;\">${label || href}<a>`\n\nconst header =\n\t\" _____ ___ _____ _ __ __ \\n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\\n \\\\__ \\\\/ / / ___/ _ \\\\\\\\__ \\\\/ / __ `__ \\\\/ / / / / __ `/ __/ __ \\\\/ ___/\\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \\n/____/_/_/\\\\___/\\\\___/____/_/_/ /_/ /_/\\\\__,_/_/\\\\__,_/\\\\__/\\\\____/_/ \\n / /_ __ __ / __ \\\\_____(_)________ ___ (_)____\\n / __ \\\\/ / / / / /_/ / ___/ / ___/ __ `__ \\\\/ / ___/\\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \\n /_.___/\\\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\\\___/ \\n /____/\\n\\n\"\n\nconst footer = \"\\n\\n\\n\\n\\n\\n - The Prismic team\"\n\nexport const sliceSimulatorAccessedDirectly = div(\n\t[\n\t\theader,\n\t\t`You're seeing this page because you're accessing Slice simulator\\ndirectly, e.g:\\n\\n - ${a(\n\t\t\t\"http://localhost:3000/slice-simulator\",\n\t\t)}\\n\\n\\n\\nThe Slice simulator can only be accessed through Slice Machine or the\\nPage Builder. To preview your Slices, head over to Slice Machine:\\n\\n - ${a(\n\t\t\t\"http://localhost:9999\",\n\t\t)}\\n\\n\\n\\nIf you believe this is an error, please reach out to us:\\n\\n - ${a(\n\t\t\t\"https://github.com/prismicio/slice-machine/issues/new/choose\",\n\t\t)}`,\n\t\tfooter,\n\t].join(\"\"),\n)\n"],"mappings":";AAAA,MAAM,OAAO,YACZ,mLAAmL,QAAQ;AAE5L,MAAM,KAAK,MAAc,UACxB,YAAY,KAAK,wCAAwC,SAAS,KAAK;AAOxE,MAAa,iCAAiC,IAC7C;CALA;CAOC,2FAA2F,EAC1F,wCACA,CAAC,0JAA0J,EAC3J,wBACA,CAAC,0EAA0E,EAC3E,+DACA;CAXY;CAab,CAAC,KAAK,GAAG,CACV"}
|
package/package.json
CHANGED
|
@@ -34,16 +34,18 @@ export class SimulatorManager {
|
|
|
34
34
|
// Init state manager
|
|
35
35
|
await this.state.init()
|
|
36
36
|
|
|
37
|
-
// Do not init the API is the simulator is accessed directly
|
|
38
|
-
if (window.parent === window) {
|
|
39
|
-
this.state.message = sliceSimulatorAccessedDirectly
|
|
40
|
-
return
|
|
41
|
-
}
|
|
42
|
-
|
|
43
37
|
// Init API
|
|
44
38
|
try {
|
|
45
39
|
await this._initAPI()
|
|
46
40
|
} catch (error) {
|
|
41
|
+
if (
|
|
42
|
+
error instanceof Error &&
|
|
43
|
+
error.message === "Receiver is currently not embedded as an iframe" &&
|
|
44
|
+
!this.state.slices.length
|
|
45
|
+
) {
|
|
46
|
+
// Catch not embedded error and display message
|
|
47
|
+
this.state.message = sliceSimulatorAccessedDirectly
|
|
48
|
+
}
|
|
47
49
|
console.error(error)
|
|
48
50
|
|
|
49
51
|
return
|
package/src/kit/State.ts
CHANGED
|
@@ -18,20 +18,18 @@ export class State extends EventEmitter<StateEvents> {
|
|
|
18
18
|
public set slices(slices: SliceZone) {
|
|
19
19
|
this._slices = slices
|
|
20
20
|
// Clean up message
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.emit(StateEventType.Slices, this.slices)
|
|
25
|
-
this.emit(StateEventType.Message, this.message)
|
|
21
|
+
this.message = ""
|
|
22
|
+
// Dispatch event
|
|
23
|
+
this.emit(StateEventType.Slices, slices)
|
|
26
24
|
}
|
|
27
25
|
public get slices(): SliceZone {
|
|
28
|
-
return
|
|
26
|
+
return this._slices
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
private _activeSlice: ActiveSlice | null
|
|
32
30
|
public set activeSlice(activeSlice: ActiveSlice | null) {
|
|
33
31
|
this._activeSlice = activeSlice
|
|
34
|
-
this.emit(StateEventType.ActiveSlice,
|
|
32
|
+
this.emit(StateEventType.ActiveSlice, activeSlice)
|
|
35
33
|
}
|
|
36
34
|
public get activeSlice(): ActiveSlice | null {
|
|
37
35
|
return this._activeSlice
|
|
@@ -40,12 +38,7 @@ export class State extends EventEmitter<StateEvents> {
|
|
|
40
38
|
private _message: string
|
|
41
39
|
public set message(message: string) {
|
|
42
40
|
this._message = message
|
|
43
|
-
|
|
44
|
-
this._slices = []
|
|
45
|
-
|
|
46
|
-
// Dispatch events
|
|
47
|
-
this.emit(StateEventType.Message, this.message)
|
|
48
|
-
this.emit(StateEventType.Slices, this.slices)
|
|
41
|
+
this.emit(StateEventType.Message, message)
|
|
49
42
|
}
|
|
50
43
|
public get message(): string {
|
|
51
44
|
return this._message
|
package/src/kit/messages.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { version } from "../../package.json"
|
|
2
|
-
|
|
3
1
|
const div = (content: string) =>
|
|
4
2
|
`<div style="word-spacing: initial; white-space: pre; line-height: initial; font-family: monospace; color: #ffffff; mix-blend-mode: difference; padding: 1rem; font-size: 1rem;">${content}</div>`
|
|
5
3
|
|
|
@@ -7,32 +5,20 @@ const a = (href: string, label?: string) =>
|
|
|
7
5
|
`<a href="${href}" style="text-decoration: underline;">${label || href}<a>`
|
|
8
6
|
|
|
9
7
|
const header =
|
|
10
|
-
|
|
8
|
+
" _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ `__ \\/ / / / / __ `/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ `__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/\n\n"
|
|
11
9
|
|
|
12
|
-
const footer = "\n\n\n\n - The Prismic team"
|
|
10
|
+
const footer = "\n\n\n\n\n\n - The Prismic team"
|
|
13
11
|
|
|
14
12
|
export const sliceSimulatorAccessedDirectly = div(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
The Slice simulator can only be accessed through Slice Machine or
|
|
27
|
-
your repository.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
If you believe this is an error, please reach out to us:
|
|
32
|
-
|
|
33
|
-
- ${a("https://github.com/prismicio/slice-simulator/issues/new/choose")}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
${footer}`,
|
|
13
|
+
[
|
|
14
|
+
header,
|
|
15
|
+
`You're seeing this page because you're accessing Slice simulator\ndirectly, e.g:\n\n - ${a(
|
|
16
|
+
"http://localhost:3000/slice-simulator",
|
|
17
|
+
)}\n\n\n\nThe Slice simulator can only be accessed through Slice Machine or the\nPage Builder. To preview your Slices, head over to Slice Machine:\n\n - ${a(
|
|
18
|
+
"http://localhost:9999",
|
|
19
|
+
)}\n\n\n\nIf you believe this is an error, please reach out to us:\n\n - ${a(
|
|
20
|
+
"https://github.com/prismicio/slice-machine/issues/new/choose",
|
|
21
|
+
)}`,
|
|
22
|
+
footer,
|
|
23
|
+
].join(""),
|
|
38
24
|
)
|
package/dist/package.cjs
DELETED
package/dist/package.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/package.js
DELETED
package/dist/package.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|