slice-machine-ui 1.26.1-alpha.aa-playground-script.6 → 1.26.1-alpha.lh-warn-on-dev-env-usage.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/components/Simulator/components/IframeRenderer/index.tsx +6 -8
- package/components/Simulator/index.tsx +40 -44
- package/out/404.html +1 -1
- package/out/_next/static/chunks/pages/{_app-abe0cb23b6dd8c4d.js → _app-cb85a9651e469a50.js} +49 -49
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-01d67e97cb901e46.js +1 -0
- package/out/_next/static/css/{21654235130d0806.css → 238631d146c5ed97.css} +1 -1
- package/out/_next/static/{raqkiSX_S2FQyS4WNJxop → tOlHeIIAx4uhxGvIXJW1Q}/_buildManifest.js +1 -1
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/settings.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +3 -4
- package/src/components/Count/Count.module.css +19 -0
- package/src/components/Count/Count.module.css.d.ts +6 -0
- package/src/components/{Counter/Counter.stories.tsx → Count/Count.stories.tsx} +3 -3
- package/src/components/{Counter/Counter.tsx → Count/Count.tsx} +2 -2
- package/src/components/Count/index.ts +1 -0
- package/src/features/inAppGuide/InAppGuideDialog.tsx +2 -2
- package/src/modules/loading/index.ts +0 -24
- package/src/modules/loading/types.ts +0 -3
- package/src/modules/useSliceMachineActions.ts +1 -14
- package/src/redux/reducer.ts +0 -2
- package/src/redux/store.ts +1 -5
- package/src/redux/type.ts +0 -2
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-3eb0fdce3228d389.js +0 -1
- package/src/components/Counter/Counter.css.ts +0 -26
- package/src/components/Counter/index.ts +0 -1
- package/src/modules/simulator/index.ts +0 -102
- package/src/modules/simulator/types.ts +0 -5
- package/src/redux/saga.ts +0 -8
- package/test/src/modules/simulator.test.ts +0 -43
- /package/out/_next/static/{raqkiSX_S2FQyS4WNJxop → tOlHeIIAx4uhxGvIXJW1Q}/_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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
90
|
+
handleSimulatorConnectionResult("successful");
|
|
93
91
|
})
|
|
94
92
|
.catch(() => {
|
|
95
|
-
|
|
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 {
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
93
|
+
if (iframeConnectionStatus === "waiting") {
|
|
94
|
+
const timer = setTimeout(() => {
|
|
95
|
+
setIframeConnectionStatus("failed");
|
|
96
|
+
}, IFRAME_CONNECTION_TIMEOUT);
|
|
113
97
|
|
|
114
|
-
|
|
115
|
-
if (currentState === UiState.FAILED_CONNECT) {
|
|
116
|
-
void telemetry.track({ event: "slice-simulator:is-not-running" });
|
|
98
|
+
return () => clearTimeout(timer);
|
|
117
99
|
}
|
|
118
|
-
}, [
|
|
100
|
+
}, [iframeConnectionStatus]);
|
|
119
101
|
|
|
120
|
-
|
|
121
|
-
if (
|
|
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
|
-
|
|
112
|
+
|
|
113
|
+
setIframeConnectionStatus(result);
|
|
114
|
+
};
|
|
125
115
|
|
|
126
116
|
const onRetrigger = () => {
|
|
127
|
-
|
|
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={
|
|
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={
|
|
249
|
+
actionsDisabled={iframeConnectionStatus !== "successful"}
|
|
260
250
|
/>
|
|
261
|
-
{
|
|
251
|
+
{iframeConnectionStatus === "failed" ? (
|
|
262
252
|
<FailedConnect onRetrigger={onRetrigger} />
|
|
263
253
|
) : null}
|
|
264
|
-
{
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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/
|
|
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/238631d146c5ed97.css" as="style"/><link rel="stylesheet" href="/_next/static/css/238631d146c5ed97.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-cb85a9651e469a50.js" defer=""></script><script src="/_next/static/chunks/pages/_error-69b4f498bafdd188.js" defer=""></script><script src="/_next/static/tOlHeIIAx4uhxGvIXJW1Q/_buildManifest.js" defer=""></script><script src="/_next/static/tOlHeIIAx4uhxGvIXJW1Q/_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":"tOlHeIIAx4uhxGvIXJW1Q","runtimeConfig":{"sentryEnvironment":"alpha"},"nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
|