slice-machine-ui 1.26.1-alpha.aa-playground-script.1 → 1.26.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/components/Simulator/components/IframeRenderer/index.tsx +6 -8
  2. package/components/Simulator/index.tsx +40 -44
  3. package/out/404.html +1 -1
  4. package/out/_next/static/chunks/pages/{_app-b57b205722703789.js → _app-756c037ed6c707e9.js} +49 -49
  5. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-01d67e97cb901e46.js +1 -0
  6. package/out/_next/static/{Xw1akSboLhT-BhSrQS3lZ → dLmvq3LL0BsWu15laiKoK}/_buildManifest.js +1 -1
  7. package/out/changelog.html +1 -1
  8. package/out/changes.html +1 -1
  9. package/out/custom-types/[customTypeId].html +1 -1
  10. package/out/custom-types.html +1 -1
  11. package/out/index.html +1 -1
  12. package/out/labs.html +1 -1
  13. package/out/page-types/[pageTypeId].html +1 -1
  14. package/out/settings.html +1 -1
  15. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  16. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  17. package/out/slices.html +1 -1
  18. package/package.json +3 -4
  19. package/src/modules/loading/index.ts +0 -24
  20. package/src/modules/loading/types.ts +0 -3
  21. package/src/modules/useSliceMachineActions.ts +1 -14
  22. package/src/redux/reducer.ts +0 -2
  23. package/src/redux/store.ts +1 -5
  24. package/src/redux/type.ts +0 -2
  25. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-3eb0fdce3228d389.js +0 -1
  26. package/src/modules/simulator/index.ts +0 -102
  27. package/src/modules/simulator/types.ts +0 -5
  28. package/src/redux/saga.ts +0 -8
  29. package/test/src/modules/simulator.test.ts +0 -43
  30. /package/out/_next/static/{Xw1akSboLhT-BhSrQS3lZ → dLmvq3LL0BsWu15laiKoK}/_ssgManifest.js +0 -0
@@ -4,7 +4,6 @@ import { Flex } from "theme-ui";
4
4
 
5
5
  import { SimulatorClient } from "@prismicio/simulator";
6
6
  import { useElementSize } from "@src/hooks/useElementSize";
7
- import useSliceMachineActions from "@src/modules/useSliceMachineActions";
8
7
  import { ScreenDimensions } from "@lib/models/common/Screenshots";
9
8
 
10
9
  function useSimulatorClient(): readonly [
@@ -52,6 +51,7 @@ type IframeRendererProps = {
52
51
  simulatorUrl: string | undefined;
53
52
  dryRun?: boolean;
54
53
  isScreenshot?: boolean;
54
+ handleSimulatorConnectionResult: (result: "successful" | "failed") => void;
55
55
  };
56
56
 
57
57
  const IframeRenderer: React.FunctionComponent<IframeRendererProps> = ({
@@ -60,16 +60,14 @@ const IframeRenderer: React.FunctionComponent<IframeRendererProps> = ({
60
60
  simulatorUrl,
61
61
  dryRun = false,
62
62
  isScreenshot = false,
63
+ handleSimulatorConnectionResult,
63
64
  }) => {
64
65
  const [client, iframeRef] = useSimulatorClient();
65
66
 
66
- const { connectToSimulatorSuccess, connectToSimulatorFailure } =
67
- useSliceMachineActions();
68
-
69
67
  useEffect((): void => {
70
68
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
71
69
  if (!simulatorUrl) {
72
- connectToSimulatorFailure();
70
+ handleSimulatorConnectionResult("failed");
73
71
  return;
74
72
  }
75
73
  if (client === undefined) {
@@ -77,7 +75,7 @@ const IframeRenderer: React.FunctionComponent<IframeRendererProps> = ({
77
75
  }
78
76
 
79
77
  if (!client.connected) {
80
- connectToSimulatorFailure();
78
+ handleSimulatorConnectionResult("failed");
81
79
  console.warn("Trying to use a disconnected simulator client.");
82
80
  return;
83
81
  }
@@ -89,10 +87,10 @@ const IframeRenderer: React.FunctionComponent<IframeRendererProps> = ({
89
87
 
90
88
  updateSliceZone()
91
89
  .then(() => {
92
- connectToSimulatorSuccess();
90
+ handleSimulatorConnectionResult("successful");
93
91
  })
94
92
  .catch(() => {
95
- connectToSimulatorFailure();
93
+ handleSimulatorConnectionResult("failed");
96
94
  });
97
95
  // eslint-disable-next-line react-hooks/exhaustive-deps
98
96
  }, [client, apiContent, simulatorUrl]);
@@ -36,10 +36,6 @@ import useThrottle from "@src/hooks/useThrottle";
36
36
  import useSliceMachineActions from "@src/modules/useSliceMachineActions";
37
37
 
38
38
  import IframeRenderer from "./components/IframeRenderer";
39
- import {
40
- selectIframeStatus,
41
- selectIsWaitingForIFrameCheck,
42
- } from "@src/modules/simulator";
43
39
  import { ErrorBoundary } from "@src/ErrorBoundary";
44
40
 
45
41
  import FullPage from "./components/FullPage";
@@ -47,27 +43,21 @@ import FailedConnect from "./components/FailedConnect";
47
43
  import { Slices, VariationSM } from "@lib/models/common/Slice";
48
44
  import { ComponentUI } from "@lib/models/common/ComponentUI";
49
45
 
50
- export enum UiState {
51
- LOADING_IFRAME = "LOADING_IFRAME",
52
- FAILED_CONNECT = "FAILED_CONNECT",
53
- SUCCESS = "SUCCESS",
54
- }
55
-
56
46
  type SimulatorProps = {
57
47
  slice: ComponentUI;
58
48
  variation: VariationSM;
59
49
  };
60
50
 
51
+ const IFRAME_CONNECTION_TIMEOUT = 20000;
52
+
61
53
  const Simulator: FC<SimulatorProps> = ({ slice, variation }) => {
62
- const { connectToSimulatorIframe, updateSliceMockSuccess } =
63
- useSliceMachineActions();
64
- const { simulatorUrl, iframeStatus, isWaitingForIFrameCheck, endpoints } =
65
- useSelector((state: SliceMachineStoreType) => ({
54
+ const { updateSliceMockSuccess } = useSliceMachineActions();
55
+ const { simulatorUrl, endpoints } = useSelector(
56
+ (state: SliceMachineStoreType) => ({
66
57
  simulatorUrl: selectSimulatorUrl(state),
67
- iframeStatus: selectIframeStatus(state),
68
- isWaitingForIFrameCheck: selectIsWaitingForIFrameCheck(state),
69
58
  endpoints: selectEndpoints(state),
70
- }));
59
+ }),
60
+ );
71
61
 
72
62
  const editorConfig: EditorConfig = useMemo(
73
63
  () => ({
@@ -95,36 +85,36 @@ const Simulator: FC<SimulatorProps> = ({ slice, variation }) => {
95
85
  void telemetry.track({ event: "editor:widget-used", sliceId });
96
86
  };
97
87
 
98
- const currentState: UiState = (() => {
99
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
100
- if (isWaitingForIFrameCheck || !iframeStatus) {
101
- return UiState.LOADING_IFRAME;
102
- }
103
- if (iframeStatus !== "ok") {
104
- return UiState.FAILED_CONNECT;
105
- }
106
- return UiState.SUCCESS;
107
- })();
88
+ const [iframeConnectionStatus, setIframeConnectionStatus] = useState<
89
+ "waiting" | "successful" | "failed"
90
+ >("waiting");
108
91
 
109
92
  useEffect(() => {
110
- connectToSimulatorIframe();
111
- // eslint-disable-next-line react-hooks/exhaustive-deps
112
- }, []);
93
+ if (iframeConnectionStatus === "waiting") {
94
+ const timer = setTimeout(() => {
95
+ setIframeConnectionStatus("failed");
96
+ }, IFRAME_CONNECTION_TIMEOUT);
113
97
 
114
- useEffect(() => {
115
- if (currentState === UiState.FAILED_CONNECT) {
116
- void telemetry.track({ event: "slice-simulator:is-not-running" });
98
+ return () => clearTimeout(timer);
117
99
  }
118
- }, [currentState]);
100
+ }, [iframeConnectionStatus]);
119
101
 
120
- useEffect(() => {
121
- if (currentState === UiState.SUCCESS) {
102
+ const handleSimulatorConnectionResult = (result: "successful" | "failed") => {
103
+ if (iframeConnectionStatus !== "waiting") {
104
+ return;
105
+ }
106
+
107
+ if (result === "failed") {
108
+ void telemetry.track({ event: "slice-simulator:is-not-running" });
109
+ } else {
122
110
  toggleIsDisplayEditor(true);
123
111
  }
124
- }, [currentState]);
112
+
113
+ setIframeConnectionStatus(result);
114
+ };
125
115
 
126
116
  const onRetrigger = () => {
127
- connectToSimulatorIframe();
117
+ setIframeConnectionStatus("waiting");
128
118
  };
129
119
 
130
120
  const [screenDimensions, setScreenDimensions] = useState<ScreenDimensions>(
@@ -220,7 +210,7 @@ const Simulator: FC<SimulatorProps> = ({ slice, variation }) => {
220
210
  slice={slice}
221
211
  variation={variation}
222
212
  isDisplayEditor={isDisplayEditor}
223
- actionsDisabled={currentState !== UiState.SUCCESS}
213
+ actionsDisabled={iframeConnectionStatus !== "successful"}
224
214
  toggleIsDisplayEditor={() => toggleIsDisplayEditor(!isDisplayEditor)}
225
215
  onSaveMock={() => void saveMock()}
226
216
  isSavingMock={isSavingMock}
@@ -256,20 +246,23 @@ const Simulator: FC<SimulatorProps> = ({ slice, variation }) => {
256
246
  <Toolbar
257
247
  handleScreenSizeChange={setScreenDimensions}
258
248
  screenDimensions={screenDimensions}
259
- actionsDisabled={currentState !== UiState.SUCCESS}
249
+ actionsDisabled={iframeConnectionStatus !== "successful"}
260
250
  />
261
- {currentState === UiState.FAILED_CONNECT ? (
251
+ {iframeConnectionStatus === "failed" ? (
262
252
  <FailedConnect onRetrigger={onRetrigger} />
263
253
  ) : null}
264
- {currentState === UiState.SUCCESS ? (
254
+ {iframeConnectionStatus === "successful" ? (
265
255
  <IframeRenderer
266
256
  apiContent={apiContent}
267
257
  screenDimensions={screenDimensions}
268
258
  simulatorUrl={simulatorUrl}
259
+ handleSimulatorConnectionResult={
260
+ handleSimulatorConnectionResult
261
+ }
269
262
  />
270
263
  ) : (
271
264
  <>
272
- {currentState === UiState.LOADING_IFRAME ? (
265
+ {iframeConnectionStatus === "waiting" ? (
273
266
  <FullPage>
274
267
  <Spinner variant="styles.spinner" />
275
268
  <IframeRenderer
@@ -277,13 +270,16 @@ const Simulator: FC<SimulatorProps> = ({ slice, variation }) => {
277
270
  screenDimensions={screenDimensions}
278
271
  simulatorUrl={simulatorUrl}
279
272
  dryRun
273
+ handleSimulatorConnectionResult={
274
+ handleSimulatorConnectionResult
275
+ }
280
276
  />
281
277
  </FullPage>
282
278
  ) : null}
283
279
  </>
284
280
  )}
285
281
  </BaseStyles>
286
- {currentState === UiState.SUCCESS && isDisplayEditor ? (
282
+ {iframeConnectionStatus === "successful" && isDisplayEditor ? (
287
283
  <Flex
288
284
  className="editor"
289
285
  sx={{
package/out/404.html CHANGED
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/css/21654235130d0806.css" as="style"/><link rel="stylesheet" href="/_next/static/css/21654235130d0806.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="/_next/static/chunks/webpack-2f903acb0cccbf9e.js" defer=""></script><script src="/_next/static/chunks/framework-cdccea7a52cc6e81.js" defer=""></script><script src="/_next/static/chunks/main-5e6780279ca21cb9.js" defer=""></script><script src="/_next/static/chunks/pages/_app-b57b205722703789.js" defer=""></script><script src="/_next/static/chunks/pages/_error-69b4f498bafdd188.js" defer=""></script><script src="/_next/static/Xw1akSboLhT-BhSrQS3lZ/_buildManifest.js" defer=""></script><script src="/_next/static/Xw1akSboLhT-BhSrQS3lZ/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"Xw1akSboLhT-BhSrQS3lZ","runtimeConfig":{"sentryEnvironment":"alpha"},"nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/css/21654235130d0806.css" as="style"/><link rel="stylesheet" href="/_next/static/css/21654235130d0806.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-c67a75d1b6f99dc8.js"></script><script src="/_next/static/chunks/webpack-2f903acb0cccbf9e.js" defer=""></script><script src="/_next/static/chunks/framework-cdccea7a52cc6e81.js" defer=""></script><script src="/_next/static/chunks/main-5e6780279ca21cb9.js" defer=""></script><script src="/_next/static/chunks/pages/_app-756c037ed6c707e9.js" defer=""></script><script src="/_next/static/chunks/pages/_error-69b4f498bafdd188.js" defer=""></script><script src="/_next/static/dLmvq3LL0BsWu15laiKoK/_buildManifest.js" defer=""></script><script src="/_next/static/dLmvq3LL0BsWu15laiKoK/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"dLmvq3LL0BsWu15laiKoK","runtimeConfig":{"sentryEnvironment":"beta"},"nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>