@prismicio/simulator 0.2.2 → 0.2.3
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 +4 -1
- 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 +4 -1
- package/dist/kit/SimulatorManager.js.map +1 -1
- package/dist/kit/State.cjs +4 -4
- package/dist/kit/State.cjs.map +1 -1
- package/dist/kit/State.js +4 -4
- package/dist/kit/State.js.map +1 -1
- package/dist/kit/messages.cjs +28 -5
- 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 +28 -5
- package/dist/kit/messages.js.map +1 -1
- package/dist/package.cjs +11 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/package.json +1 -1
- package/src/kit/SimulatorManager.ts +6 -8
- package/src/kit/State.ts +4 -4
- package/src/kit/messages.ts +27 -13
|
@@ -20,10 +20,13 @@ 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
|
+
}
|
|
23
27
|
try {
|
|
24
28
|
await this._initAPI();
|
|
25
29
|
} 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;
|
|
27
30
|
console.error(error);
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
@@ -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// Do not init the API is the simulator is accessed directly\n\t\tif (window.parent === window) {\n\t\t\tthis.state.message = sliceSimulatorAccessedDirectly\n\t\t\treturn\n\t\t}\n\n\t\t// Init API\n\t\ttry {\n\t\t\tawait this._initAPI()\n\t\t} catch (error) {\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,IAAIA,cAAAA,M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;;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,QA6BA,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,QA6BA,QAAA;EAAA,QAuDN,cAAA;AAAA"}
|
|
@@ -20,10 +20,13 @@ 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
|
+
}
|
|
23
27
|
try {
|
|
24
28
|
await this._initAPI();
|
|
25
29
|
} 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;
|
|
27
30
|
console.error(error);
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
@@ -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// Do not init the API is the simulator is accessed directly\n\t\tif (window.parent === window) {\n\t\t\tthis.state.message = sliceSimulatorAccessedDirectly\n\t\t\treturn\n\t\t}\n\n\t\t// Init API\n\t\ttry {\n\t\t\tawait this._initAPI()\n\t\t} catch (error) {\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})\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
9
|
set slices(slices) {
|
|
10
10
|
this._slices = slices;
|
|
11
11
|
this.message = "";
|
|
12
|
-
this.emit(require_types.StateEventType.Slices, slices);
|
|
12
|
+
this.emit(require_types.StateEventType.Slices, this.slices);
|
|
13
13
|
}
|
|
14
14
|
get slices() {
|
|
15
|
-
return this._slices;
|
|
15
|
+
return window.parent !== window ? this._slices : [];
|
|
16
16
|
}
|
|
17
17
|
_activeSlice;
|
|
18
18
|
set activeSlice(activeSlice) {
|
|
19
19
|
this._activeSlice = activeSlice;
|
|
20
|
-
this.emit(require_types.StateEventType.ActiveSlice, activeSlice);
|
|
20
|
+
this.emit(require_types.StateEventType.ActiveSlice, this.activeSlice);
|
|
21
21
|
}
|
|
22
22
|
get activeSlice() {
|
|
23
23
|
return this._activeSlice;
|
|
@@ -25,7 +25,7 @@ var State = class extends require_EventEmitter.EventEmitter {
|
|
|
25
25
|
_message;
|
|
26
26
|
set message(message) {
|
|
27
27
|
this._message = message;
|
|
28
|
-
this.emit(require_types.StateEventType.Message, message);
|
|
28
|
+
this.emit(require_types.StateEventType.Message, this.message);
|
|
29
29
|
}
|
|
30
30
|
get message() {
|
|
31
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.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,cAA2BA,qBAAAA,aAA0B;CACpD;CACA,IAAW,OAAO,QAAmB;AACpC,OAAK,UAAU;AAEf,OAAK,UAAU;AAEf,OAAK,KAAKC,cAAAA,eAAe,QAAQ,OAAO;;
|
|
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, this.slices)\n\t}\n\tpublic get slices(): SliceZone {\n\t\treturn window.parent !== window ? 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, this.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, this.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,cAA2BA,qBAAAA,aAA0B;CACpD;CACA,IAAW,OAAO,QAAmB;AACpC,OAAK,UAAU;AAEf,OAAK,UAAU;AAEf,OAAK,KAAKC,cAAAA,eAAe,QAAQ,KAAK,OAAO;;CAE9C,IAAW,SAAoB;AAC9B,SAAO,OAAO,WAAW,SAAS,KAAK,UAAU,EAAE;;CAGpD;CACA,IAAW,YAAY,aAAiC;AACvD,OAAK,eAAe;AACpB,OAAK,KAAKA,cAAAA,eAAe,aAAa,KAAK,YAAY;;CAExD,IAAW,cAAkC;AAC5C,SAAO,KAAK;;CAGb;CACA,IAAW,QAAQ,SAAiB;AACnC,OAAK,WAAW;AAChB,OAAK,KAAKA,cAAAA,eAAe,SAAS,KAAK,QAAQ;;CAEhD,IAAW,UAAkB;AAC5B,SAAO,KAAK;;CAGb;CAEA,YAAY,MAA6B;AACxC,SAAO;AAEP,OAAK,UAAU,MAAM,UAAUC,mBAAAA,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,aAAaC,mBAAAA,gBAAgB,KAAK,OAAO,OAAO;AAGtD,MAAI,CAAC,YAAY;AAChB,QAAK,cAAc;AAEnB;;EAGD,MAAM,eAAeC,mBAAAA,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,iBAAiBC,iBAAAA,SAAS,KAAK,iBAAiB,GAAG;CAEnD,aAAa,QAAyB;AAErC,OAAK,SAAS"}
|
package/dist/kit/State.js
CHANGED
|
@@ -9,15 +9,15 @@ var State = class extends EventEmitter {
|
|
|
9
9
|
set slices(slices) {
|
|
10
10
|
this._slices = slices;
|
|
11
11
|
this.message = "";
|
|
12
|
-
this.emit(StateEventType.Slices, slices);
|
|
12
|
+
this.emit(StateEventType.Slices, this.slices);
|
|
13
13
|
}
|
|
14
14
|
get slices() {
|
|
15
|
-
return this._slices;
|
|
15
|
+
return window.parent !== window ? this._slices : [];
|
|
16
16
|
}
|
|
17
17
|
_activeSlice;
|
|
18
18
|
set activeSlice(activeSlice) {
|
|
19
19
|
this._activeSlice = activeSlice;
|
|
20
|
-
this.emit(StateEventType.ActiveSlice, activeSlice);
|
|
20
|
+
this.emit(StateEventType.ActiveSlice, this.activeSlice);
|
|
21
21
|
}
|
|
22
22
|
get activeSlice() {
|
|
23
23
|
return this._activeSlice;
|
|
@@ -25,7 +25,7 @@ var State = class extends EventEmitter {
|
|
|
25
25
|
_message;
|
|
26
26
|
set message(message) {
|
|
27
27
|
this._message = message;
|
|
28
|
-
this.emit(StateEventType.Message, message);
|
|
28
|
+
this.emit(StateEventType.Message, this.message);
|
|
29
29
|
}
|
|
30
30
|
get message() {
|
|
31
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.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;;
|
|
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, this.slices)\n\t}\n\tpublic get slices(): SliceZone {\n\t\treturn window.parent !== window ? 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, this.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, this.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,KAAK,OAAO;;CAE9C,IAAW,SAAoB;AAC9B,SAAO,OAAO,WAAW,SAAS,KAAK,UAAU,EAAE;;CAGpD;CACA,IAAW,YAAY,aAAiC;AACvD,OAAK,eAAe;AACpB,OAAK,KAAK,eAAe,aAAa,KAAK,YAAY;;CAExD,IAAW,cAAkC;AAC5C,SAAO,KAAK;;CAGb;CACA,IAAW,QAAQ,SAAiB;AACnC,OAAK,WAAW;AAChB,OAAK,KAAK,eAAe,SAAS,KAAK,QAAQ;;CAEhD,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,11 +1,34 @@
|
|
|
1
|
+
const require_package = require("../package.cjs");
|
|
1
2
|
//#region src/kit/messages.ts
|
|
2
3
|
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>`;
|
|
3
4
|
const a = (href, label) => `<a href="${href}" style="text-decoration: underline;">${label || href}<a>`;
|
|
4
|
-
const sliceSimulatorAccessedDirectly = div(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const sliceSimulatorAccessedDirectly = div(`${` _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ \`__ \\/ / / / / __ \`/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ \`__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/ v${require_package.version}\n\n`}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
You're seeing this page because you're accessing Slice simulator
|
|
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`);
|
|
9
32
|
//#endregion
|
|
10
33
|
exports.sliceSimulatorAccessedDirectly = sliceSimulatorAccessedDirectly;
|
|
11
34
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.cjs","names":[],"sources":["../../src/kit/messages.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"messages.cjs","names":["version"],"sources":["../../src/kit/messages.ts"],"sourcesContent":["import { version } from \"../../package.json\"\n\nconst 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 /____/ v${version}\\n\\n`\n\nconst footer = \"\\n\\n\\n\\n - The Prismic team\"\n\nexport const sliceSimulatorAccessedDirectly = div(\n`${header}\n\n\n\nYou'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\nyour repository.\n\n\n\nIf you believe this is an error, please reach out to us:\n\n - ${a(\"https://github.com/prismicio/slice-simulator/issues/new/choose\")}\n\n\n\n${footer}`,\n)\n"],"mappings":";;AAEA,MAAM,OAAO,YACZ,mLAAmL,QAAQ;AAE5L,MAAM,KAAK,MAAc,UACxB,YAAY,KAAK,wCAAwC,SAAS,KAAK;AAOxE,MAAa,iCAAiC,IAC9C,GALC,6qBAA6qBA,gBAAAA,QAAQ,MAK5qB;;;;;;;MAOJ,EAAE,wCAAwC,CAAC;;;;;;;;;;;MAW3C,EAAE,iEAAiE,CAAC;;;;;;;;oEAKzE"}
|
|
@@ -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":";cAaa,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":";cAaa,8BAAA"}
|
package/dist/kit/messages.js
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
import { version } from "../package.js";
|
|
1
2
|
//#region src/kit/messages.ts
|
|
2
3
|
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>`;
|
|
3
4
|
const a = (href, label) => `<a href="${href}" style="text-decoration: underline;">${label || href}<a>`;
|
|
4
|
-
const sliceSimulatorAccessedDirectly = div(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const sliceSimulatorAccessedDirectly = div(`${` _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ \`__ \\/ / / / / __ \`/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ \`__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/ v${version}\n\n`}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
You're seeing this page because you're accessing Slice simulator
|
|
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`);
|
|
9
32
|
//#endregion
|
|
10
33
|
export { sliceSimulatorAccessedDirectly };
|
|
11
34
|
|
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":["import { version } from \"../../package.json\"\n\nconst 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 /____/ v${version}\\n\\n`\n\nconst footer = \"\\n\\n\\n\\n - The Prismic team\"\n\nexport const sliceSimulatorAccessedDirectly = div(\n`${header}\n\n\n\nYou'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\nyour repository.\n\n\n\nIf you believe this is an error, please reach out to us:\n\n - ${a(\"https://github.com/prismicio/slice-simulator/issues/new/choose\")}\n\n\n\n${footer}`,\n)\n"],"mappings":";;AAEA,MAAM,OAAO,YACZ,mLAAmL,QAAQ;AAE5L,MAAM,KAAK,MAAc,UACxB,YAAY,KAAK,wCAAwC,SAAS,KAAK;AAOxE,MAAa,iCAAiC,IAC9C,GALC,6qBAA6qB,QAAQ,MAK5qB;;;;;;;MAOJ,EAAE,wCAAwC,CAAC;;;;;;;;;;;MAW3C,EAAE,iEAAiE,CAAC;;;;;;;;oEAKzE"}
|
package/dist/package.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.cjs","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../package.json"],"sourcesContent":[""],"mappings":""}
|
package/package.json
CHANGED
|
@@ -34,18 +34,16 @@ 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
|
+
|
|
37
43
|
// Init API
|
|
38
44
|
try {
|
|
39
45
|
await this._initAPI()
|
|
40
46
|
} 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
|
-
}
|
|
49
47
|
console.error(error)
|
|
50
48
|
|
|
51
49
|
return
|
package/src/kit/State.ts
CHANGED
|
@@ -20,16 +20,16 @@ export class State extends EventEmitter<StateEvents> {
|
|
|
20
20
|
// Clean up message
|
|
21
21
|
this.message = ""
|
|
22
22
|
// Dispatch event
|
|
23
|
-
this.emit(StateEventType.Slices, slices)
|
|
23
|
+
this.emit(StateEventType.Slices, this.slices)
|
|
24
24
|
}
|
|
25
25
|
public get slices(): SliceZone {
|
|
26
|
-
return this._slices
|
|
26
|
+
return window.parent !== window ? this._slices : []
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
private _activeSlice: ActiveSlice | null
|
|
30
30
|
public set activeSlice(activeSlice: ActiveSlice | null) {
|
|
31
31
|
this._activeSlice = activeSlice
|
|
32
|
-
this.emit(StateEventType.ActiveSlice, activeSlice)
|
|
32
|
+
this.emit(StateEventType.ActiveSlice, this.activeSlice)
|
|
33
33
|
}
|
|
34
34
|
public get activeSlice(): ActiveSlice | null {
|
|
35
35
|
return this._activeSlice
|
|
@@ -38,7 +38,7 @@ export class State extends EventEmitter<StateEvents> {
|
|
|
38
38
|
private _message: string
|
|
39
39
|
public set message(message: string) {
|
|
40
40
|
this._message = message
|
|
41
|
-
this.emit(StateEventType.Message, message)
|
|
41
|
+
this.emit(StateEventType.Message, this.message)
|
|
42
42
|
}
|
|
43
43
|
public get message(): string {
|
|
44
44
|
return this._message
|
package/src/kit/messages.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { version } from "../../package.json"
|
|
2
|
+
|
|
1
3
|
const div = (content: string) =>
|
|
2
4
|
`<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>`
|
|
3
5
|
|
|
@@ -5,20 +7,32 @@ const a = (href: string, label?: string) =>
|
|
|
5
7
|
`<a href="${href}" style="text-decoration: underline;">${label || href}<a>`
|
|
6
8
|
|
|
7
9
|
const header =
|
|
8
|
-
|
|
10
|
+
` _____ ___ _____ _ __ __ \n / ___// (_)_______ / ___/(_)___ ___ __ __/ /___ _/ /_____ _____\n \\__ \\/ / / ___/ _ \\\\__ \\/ / __ \`__ \\/ / / / / __ \`/ __/ __ \\/ ___/\n ___/ / / / /__/ __/__/ / / / / / / / /_/ / / /_/ / /_/ /_/ / / \n/____/_/_/\\___/\\___/____/_/_/ /_/ /_/\\__,_/_/\\__,_/\\__/\\____/_/ \n / /_ __ __ / __ \\_____(_)________ ___ (_)____\n / __ \\/ / / / / /_/ / ___/ / ___/ __ \`__ \\/ / ___/\n / /_/ / /_/ / / ____/ / / (__ ) / / / / / / /__ \n /_.___/\\__, / /_/ /_/ /_/____/_/ /_/ /_/_/\\___/ \n /____/ v${version}\n\n`
|
|
9
11
|
|
|
10
|
-
const footer = "\n\n\n\n
|
|
12
|
+
const footer = "\n\n\n\n - The Prismic team"
|
|
11
13
|
|
|
12
14
|
export const sliceSimulatorAccessedDirectly = div(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
`${header}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
You're seeing this page because you're accessing Slice simulator
|
|
20
|
+
directly, e.g:
|
|
21
|
+
|
|
22
|
+
- ${a("http://localhost:3000/slice-simulator")}
|
|
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}`,
|
|
24
38
|
)
|