@prismicio/next 2.2.1-pr.131.6624bed → 2.2.1-pr.131.6c77550
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/SliceSimulator.cjs +1 -1
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.js +1 -1
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/SliceSimulatorWrapper.cjs +3 -10
- package/dist/SliceSimulatorWrapper.cjs.map +1 -1
- package/dist/SliceSimulatorWrapper.js +3 -10
- package/dist/SliceSimulatorWrapper.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/src/SliceSimulator.tsx +1 -1
- package/src/SliceSimulatorWrapper.tsx +33 -39
package/dist/SliceSimulator.cjs
CHANGED
|
@@ -16,7 +16,7 @@ const simulatorManager = new _prismicio_simulator_kit.SimulatorManager();
|
|
|
16
16
|
* development in Slice Machine and live previews in the Page Builder.
|
|
17
17
|
*/
|
|
18
18
|
const SliceSimulator = ({ children, background, zIndex, className }) => {
|
|
19
|
-
const [message, setMessage] = (0, react.useState)((0, _prismicio_simulator_kit.getDefaultMessage)());
|
|
19
|
+
const [message, setMessage] = (0, react.useState)(() => (0, _prismicio_simulator_kit.getDefaultMessage)());
|
|
20
20
|
const router = (0, next_navigation.useRouter)();
|
|
21
21
|
const routerRef = (0, react.useRef)(router);
|
|
22
22
|
routerRef.current = router;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","StateEventType","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string;\n\t}>;\n};\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n};\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice\n * development in Slice Machine and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(getDefaultMessage());\n\tconst router = useRouter();\n\tconst routerRef = useRef(router);\n\trouterRef.current = router;\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tcompressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t);\n\n\t\t\t\twindow.history.replaceState(null, \"\", url);\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => routerRef.current.refresh(), 0);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tsimulatorManager.init();\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\");\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\");\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t);\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAIA,2CAAkB;;;;;AAoB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","StateEventType","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string;\n\t}>;\n};\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n};\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice\n * development in Slice Machine and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(() => getDefaultMessage());\n\tconst router = useRouter();\n\tconst routerRef = useRef(router);\n\trouterRef.current = router;\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tcompressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t);\n\n\t\t\t\twindow.history.replaceState(null, \"\", url);\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => routerRef.current.refresh(), 0);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tsimulatorManager.init();\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\");\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\");\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t);\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAIA,2CAAkB;;;;;AAoB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,yFAAgD,CAAC;CACjE,MAAM,yCAAoB;CAC1B,MAAM,8BAAmB,OAAO;AAChC,WAAU,UAAU;AAEpB,4BAAgB;AACf,mBAAiB,MAAM,GACtBC,wCAAe,SACd,cAAc;GACd,MAAM,MAAM,IAAI,IAAI,OAAO,SAAS,KAAK;AACzC,OAAI,aAAa,IAChB,+DAC8B,KAAK,UAAU,UAAU,CAAC,CACxD;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,UAAU,QAAQ,SAAS,EAAE,EAAE;KAEjD,mBACA;AACD,mBAAiB,MAAM,GACtBA,wCAAe,UACd,eAAe,WAAW,WAAW,EACtC,oBACA;AAED,mBAAiB,MAAM;AAEvB,eAAa;AACZ,oBAAiB,MAAM,IAAIA,wCAAe,QAAQ,mBAAmB;AAErE,oBAAiB,MAAM,IAAIA,wCAAe,SAAS,oBAAoB;;IAEtE,EAAE,CAAC;AAEN,QACC,2CAACC;EACS;EACG;EACJ;EACG;EAEV;GACsB"}
|
package/dist/SliceSimulator.js
CHANGED
|
@@ -15,7 +15,7 @@ const simulatorManager = new SimulatorManager();
|
|
|
15
15
|
* development in Slice Machine and live previews in the Page Builder.
|
|
16
16
|
*/
|
|
17
17
|
const SliceSimulator = ({ children, background, zIndex, className }) => {
|
|
18
|
-
const [message, setMessage] = useState(getDefaultMessage());
|
|
18
|
+
const [message, setMessage] = useState(() => getDefaultMessage());
|
|
19
19
|
const router = useRouter();
|
|
20
20
|
const routerRef = useRef(router);
|
|
21
21
|
routerRef.current = router;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulator.js","names":[],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string;\n\t}>;\n};\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n};\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice\n * development in Slice Machine and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(getDefaultMessage());\n\tconst router = useRouter();\n\tconst routerRef = useRef(router);\n\trouterRef.current = router;\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tcompressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t);\n\n\t\t\t\twindow.history.replaceState(null, \"\", url);\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => routerRef.current.refresh(), 0);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tsimulatorManager.init();\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\");\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\");\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAI,kBAAkB;;;;;AAoB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,cAAc,
|
|
1
|
+
{"version":3,"file":"SliceSimulator.js","names":[],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string;\n\t}>;\n};\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n};\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice\n * development in Slice Machine and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(() => getDefaultMessage());\n\tconst router = useRouter();\n\tconst routerRef = useRef(router);\n\trouterRef.current = router;\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tcompressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t);\n\n\t\t\t\twindow.history.replaceState(null, \"\", url);\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => routerRef.current.refresh(), 0);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tsimulatorManager.init();\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\");\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\");\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAI,kBAAkB;;;;;AAoB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,cAAc,eAAe,mBAAmB,CAAC;CACjE,MAAM,SAAS,WAAW;CAC1B,MAAM,YAAY,OAAO,OAAO;AAChC,WAAU,UAAU;AAEpB,iBAAgB;AACf,mBAAiB,MAAM,GACtB,eAAe,SACd,cAAc;GACd,MAAM,MAAM,IAAI,IAAI,OAAO,SAAS,KAAK;AACzC,OAAI,aAAa,IAChB,kBACA,8BAA8B,KAAK,UAAU,UAAU,CAAC,CACxD;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,UAAU,QAAQ,SAAS,EAAE,EAAE;KAEjD,mBACA;AACD,mBAAiB,MAAM,GACtB,eAAe,UACd,eAAe,WAAW,WAAW,EACtC,oBACA;AAED,mBAAiB,MAAM;AAEvB,eAAa;AACZ,oBAAiB,MAAM,IAAI,eAAe,QAAQ,mBAAmB;AAErE,oBAAiB,MAAM,IAAI,eAAe,SAAS,oBAAoB;;IAEtE,EAAE,CAAC;AAEN,QACC,oBAAC;EACS;EACG;EACJ;EACG;EAEV;GACsB"}
|
|
@@ -9,7 +9,7 @@ let _prismicio_simulator_kit = require("@prismicio/simulator/kit");
|
|
|
9
9
|
*/
|
|
10
10
|
const SliceSimulatorWrapper = ({ className, children, zIndex, background, message }) => {
|
|
11
11
|
const defaultProps = (0, _prismicio_simulator_kit.getDefaultProps)();
|
|
12
|
-
|
|
12
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
13
13
|
className: [_prismicio_simulator_kit.simulatorClass, className].filter(Boolean).join(" "),
|
|
14
14
|
style: {
|
|
15
15
|
zIndex: typeof zIndex === "undefined" ? defaultProps.zIndex : zIndex ?? void 0,
|
|
@@ -20,15 +20,8 @@ const SliceSimulatorWrapper = ({ className, children, zIndex, background, messag
|
|
|
20
20
|
height: "100vh",
|
|
21
21
|
overflow: "auto",
|
|
22
22
|
background: typeof background === "undefined" ? defaultProps.background : background ?? void 0
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (message) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
26
|
-
...outerProps,
|
|
27
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("article", { dangerouslySetInnerHTML: { __html: message } })
|
|
28
|
-
});
|
|
29
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
30
|
-
...outerProps,
|
|
31
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
23
|
+
},
|
|
24
|
+
children: message ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("article", { dangerouslySetInnerHTML: { __html: message } }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
32
25
|
id: "root",
|
|
33
26
|
className: _prismicio_simulator_kit.simulatorRootClass,
|
|
34
27
|
onClickCapture: _prismicio_simulator_kit.onClickHandler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulatorWrapper.cjs","names":["simulatorClass","simulatorRootClass","onClickHandler","disableEventHandler"],"sources":["../src/SliceSimulatorWrapper.tsx"],"sourcesContent":["import {\n\tdisableEventHandler,\n\tgetDefaultProps,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport type { FC, ReactNode } from \"react\";\n\ntype SliceSimulatorWrapperProps = SliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n\tmessage?: string;\n};\n\n/**\n * A wrapper for the slice simulator that isolates the given children from the\n * page's layout.\n */\nexport const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({\n\tclassName,\n\tchildren,\n\tzIndex,\n\tbackground,\n\tmessage,\n}) => {\n\tconst defaultProps = getDefaultProps();\n\n\
|
|
1
|
+
{"version":3,"file":"SliceSimulatorWrapper.cjs","names":["simulatorClass","simulatorRootClass","onClickHandler","disableEventHandler"],"sources":["../src/SliceSimulatorWrapper.tsx"],"sourcesContent":["import {\n\tdisableEventHandler,\n\tgetDefaultProps,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport type { FC, ReactNode } from \"react\";\n\ntype SliceSimulatorWrapperProps = SliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n\tmessage?: string;\n};\n\n/**\n * A wrapper for the slice simulator that isolates the given children from the\n * page's layout.\n */\nexport const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({\n\tclassName,\n\tchildren,\n\tzIndex,\n\tbackground,\n\tmessage,\n}) => {\n\tconst defaultProps = getDefaultProps();\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: (zIndex ?? undefined),\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: (background ?? undefined),\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n"],"mappings":";;;;;;;;;AAoBA,MAAa,yBAAyD,EACrE,WACA,UACA,QACA,YACA,cACK;CACL,MAAM,8DAAgC;AAEtC,QACC,2CAAC;EACA,WAAW,CAACA,yCAAgB,UAAU,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;EAChE,OAAO;GACN,QACC,OAAO,WAAW,cACf,aAAa,SACZ,UAAU;GACf,UAAU;GACV,KAAK;GACL,MAAM;GACN,OAAO;GACP,QAAQ;GACR,UAAU;GACV,YACC,OAAO,eAAe,cACnB,aAAa,aACZ,cAAc;GACnB;YAEA,UACA,2CAAC,aAAQ,yBAAyB,EAAE,QAAQ,SAAS,GAAI,GAEzD,2CAAC;GACA,IAAG;GACH,WAAWC;GACX,gBAAgBC;GAChB,iBACCC;GAGA;IACI;GAEF"}
|
|
@@ -8,7 +8,7 @@ import { disableEventHandler, getDefaultProps, onClickHandler, simulatorClass, s
|
|
|
8
8
|
*/
|
|
9
9
|
const SliceSimulatorWrapper = ({ className, children, zIndex, background, message }) => {
|
|
10
10
|
const defaultProps = getDefaultProps();
|
|
11
|
-
|
|
11
|
+
return /* @__PURE__ */ jsx("div", {
|
|
12
12
|
className: [simulatorClass, className].filter(Boolean).join(" "),
|
|
13
13
|
style: {
|
|
14
14
|
zIndex: typeof zIndex === "undefined" ? defaultProps.zIndex : zIndex ?? void 0,
|
|
@@ -19,15 +19,8 @@ const SliceSimulatorWrapper = ({ className, children, zIndex, background, messag
|
|
|
19
19
|
height: "100vh",
|
|
20
20
|
overflow: "auto",
|
|
21
21
|
background: typeof background === "undefined" ? defaultProps.background : background ?? void 0
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (message) return /* @__PURE__ */ jsx("div", {
|
|
25
|
-
...outerProps,
|
|
26
|
-
children: /* @__PURE__ */ jsx("article", { dangerouslySetInnerHTML: { __html: message } })
|
|
27
|
-
});
|
|
28
|
-
return /* @__PURE__ */ jsx("div", {
|
|
29
|
-
...outerProps,
|
|
30
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
22
|
+
},
|
|
23
|
+
children: message ? /* @__PURE__ */ jsx("article", { dangerouslySetInnerHTML: { __html: message } }) : /* @__PURE__ */ jsx("div", {
|
|
31
24
|
id: "root",
|
|
32
25
|
className: simulatorRootClass,
|
|
33
26
|
onClickCapture: onClickHandler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceSimulatorWrapper.js","names":[],"sources":["../src/SliceSimulatorWrapper.tsx"],"sourcesContent":["import {\n\tdisableEventHandler,\n\tgetDefaultProps,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport type { FC, ReactNode } from \"react\";\n\ntype SliceSimulatorWrapperProps = SliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n\tmessage?: string;\n};\n\n/**\n * A wrapper for the slice simulator that isolates the given children from the\n * page's layout.\n */\nexport const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({\n\tclassName,\n\tchildren,\n\tzIndex,\n\tbackground,\n\tmessage,\n}) => {\n\tconst defaultProps = getDefaultProps();\n\n\
|
|
1
|
+
{"version":3,"file":"SliceSimulatorWrapper.js","names":[],"sources":["../src/SliceSimulatorWrapper.tsx"],"sourcesContent":["import {\n\tdisableEventHandler,\n\tgetDefaultProps,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport type { FC, ReactNode } from \"react\";\n\ntype SliceSimulatorWrapperProps = SliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n\tmessage?: string;\n};\n\n/**\n * A wrapper for the slice simulator that isolates the given children from the\n * page's layout.\n */\nexport const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({\n\tclassName,\n\tchildren,\n\tzIndex,\n\tbackground,\n\tmessage,\n}) => {\n\tconst defaultProps = getDefaultProps();\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: (zIndex ?? undefined),\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: (background ?? undefined),\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n"],"mappings":";;;;;;;;AAoBA,MAAa,yBAAyD,EACrE,WACA,UACA,QACA,YACA,cACK;CACL,MAAM,eAAe,iBAAiB;AAEtC,QACC,oBAAC;EACA,WAAW,CAAC,gBAAgB,UAAU,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;EAChE,OAAO;GACN,QACC,OAAO,WAAW,cACf,aAAa,SACZ,UAAU;GACf,UAAU;GACV,KAAK;GACL,MAAM;GACN,OAAO;GACP,QAAQ;GACR,UAAU;GACV,YACC,OAAO,eAAe,cACnB,aAAa,aACZ,cAAc;GACnB;YAEA,UACA,oBAAC,aAAQ,yBAAyB,EAAE,QAAQ,SAAS,GAAI,GAEzD,oBAAC;GACA,IAAG;GACH,WAAW;GACX,gBAAgB;GAChB,iBACC;GAGA;IACI;GAEF"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
package/package.json
CHANGED
package/src/SliceSimulator.tsx
CHANGED
|
@@ -40,7 +40,7 @@ export const SliceSimulator: FC<SliceSimulatorProps> = ({
|
|
|
40
40
|
zIndex,
|
|
41
41
|
className,
|
|
42
42
|
}) => {
|
|
43
|
-
const [message, setMessage] = useState(getDefaultMessage());
|
|
43
|
+
const [message, setMessage] = useState(() => getDefaultMessage());
|
|
44
44
|
const router = useRouter();
|
|
45
45
|
const routerRef = useRef(router);
|
|
46
46
|
routerRef.current = router;
|
|
@@ -27,46 +27,40 @@ export const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({
|
|
|
27
27
|
}) => {
|
|
28
28
|
const defaultProps = getDefaultProps();
|
|
29
29
|
|
|
30
|
-
const outerProps = {
|
|
31
|
-
className: [simulatorClass, className].filter(Boolean).join(" "),
|
|
32
|
-
style: {
|
|
33
|
-
zIndex:
|
|
34
|
-
typeof zIndex === "undefined"
|
|
35
|
-
? defaultProps.zIndex
|
|
36
|
-
: (zIndex ?? undefined),
|
|
37
|
-
position: "fixed" as const,
|
|
38
|
-
top: 0,
|
|
39
|
-
left: 0,
|
|
40
|
-
width: "100%",
|
|
41
|
-
height: "100vh",
|
|
42
|
-
overflow: "auto",
|
|
43
|
-
background:
|
|
44
|
-
typeof background === "undefined"
|
|
45
|
-
? defaultProps.background
|
|
46
|
-
: (background ?? undefined),
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
if (message) {
|
|
51
|
-
return (
|
|
52
|
-
<div {...outerProps}>
|
|
53
|
-
<article dangerouslySetInnerHTML={{ __html: message }} />
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
30
|
return (
|
|
59
|
-
<div
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
31
|
+
<div
|
|
32
|
+
className={[simulatorClass, className].filter(Boolean).join(" ")}
|
|
33
|
+
style={{
|
|
34
|
+
zIndex:
|
|
35
|
+
typeof zIndex === "undefined"
|
|
36
|
+
? defaultProps.zIndex
|
|
37
|
+
: (zIndex ?? undefined),
|
|
38
|
+
position: "fixed",
|
|
39
|
+
top: 0,
|
|
40
|
+
left: 0,
|
|
41
|
+
width: "100%",
|
|
42
|
+
height: "100vh",
|
|
43
|
+
overflow: "auto",
|
|
44
|
+
background:
|
|
45
|
+
typeof background === "undefined"
|
|
46
|
+
? defaultProps.background
|
|
47
|
+
: (background ?? undefined),
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
{message ? (
|
|
51
|
+
<article dangerouslySetInnerHTML={{ __html: message }} />
|
|
52
|
+
) : (
|
|
53
|
+
<div
|
|
54
|
+
id="root"
|
|
55
|
+
className={simulatorRootClass}
|
|
56
|
+
onClickCapture={onClickHandler as unknown as React.MouseEventHandler}
|
|
57
|
+
onSubmitCapture={
|
|
58
|
+
disableEventHandler as unknown as React.FormEventHandler
|
|
59
|
+
}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
</div>
|
|
63
|
+
)}
|
|
70
64
|
</div>
|
|
71
65
|
);
|
|
72
66
|
};
|