slice-machine-ui 1.24.1-beta.4 → 1.24.1-beta.6
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/App/index.tsx +0 -2
- package/components/Changelog/index.tsx +29 -40
- package/components/Changelog/navigation/index.tsx +27 -23
- package/components/Changelog/versionDetails/{ReleaseNoteDetails.tsx → ReleaseNotesDetails.tsx} +5 -5
- package/components/Changelog/versionDetails/UpdateCommandBox.tsx +15 -11
- package/components/Changelog/versionDetails/VersionKindLabel.tsx +3 -2
- package/components/Changelog/versionDetails/index.tsx +17 -16
- package/components/Navigation/RunningVersion.tsx +14 -0
- package/components/Navigation/UpdateBox.tsx +16 -0
- package/components/Navigation/index.test.tsx +10 -35
- package/components/Navigation/index.tsx +14 -29
- package/components/ScreenshotChangesModal/VariationDropZone.tsx +18 -19
- package/lib/models/common/Environment.ts +0 -2
- package/out/404.html +1 -1
- package/out/_next/static/chunks/286-877cd7b96660f95f.js +1 -0
- package/out/_next/static/chunks/{727-c6c0c0d8c72c2676.js → 727-ffb4c69fbb971ed7.js} +1 -1
- package/out/_next/static/chunks/{904-c09e8a519129a3d8.js → 904-d9089efa6d974e3e.js} +1 -1
- package/out/_next/static/chunks/pages/{_app-5e98af5451b0b1ab.js → _app-983b2fd3ede0d388.js} +24 -24
- package/out/_next/static/chunks/pages/changelog-57289ca6bc99702b.js +1 -0
- package/out/_next/static/chunks/pages/{changes-0623b15f5e49d3b0.js → changes-ea6064c1db5ab5e1.js} +1 -1
- package/out/_next/static/chunks/pages/{labs-773e5e6044d04247.js → labs-85d5c752dd5148b6.js} +1 -1
- package/out/_next/static/chunks/pages/{settings-934f8c6734b9c427.js → settings-5182a8e6bdb92822.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/{[variation]-4cd51835ba731872.js → [variation]-89c911fd39271b5d.js} +1 -1
- package/out/_next/static/chunks/pages/{slices-e0ce615c38e8338d.js → slices-5dc0c55c386e047a.js} +1 -1
- package/out/_next/static/{BPmSPNuacjzy05VoBBWe0 → qdfgiTBDB3fV4Iyei9xeV}/_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 -3
- package/src/apiClient.ts +0 -50
- package/src/features/changelog/useSliceMachineLatestNonBreakingVersion.ts +14 -0
- package/src/features/changelog/useSliceMachineReleaseNotes.ts +16 -0
- package/src/features/changelog/useSliceMachineVersions.ts +15 -0
- package/src/features/customTypes/customTypesBuilder/PageSnippetDialog/PageSnippetDialog.tsx +4 -6
- package/src/features/documentation/MarkdownRenderer/index.tsx +4 -6
- package/src/hooks/useAdapterName.ts +4 -5
- package/src/hooks/useMarketingContent.ts +0 -3
- package/src/hooks/useSliceMachineRunningVersion.ts +14 -0
- package/src/hooks/useUpdateAvailable.ts +17 -0
- package/src/modules/environment/index.ts +2 -71
- package/src/modules/loading/types.ts +0 -2
- package/src/modules/useSliceMachineActions.ts +2 -11
- package/src/modules/userContext/index.ts +0 -19
- package/src/modules/userContext/types.ts +0 -4
- package/src/redux/saga.ts +0 -2
- package/test/src/modules/__fixtures__/serverState.ts +0 -13
- package/test/src/modules/environment.test.ts +0 -57
- package/test/src/modules/userContext.test.ts +0 -31
- package/lib/models/common/versions.ts +0 -39
- package/out/_next/static/chunks/286-ed90373e9a469944.js +0 -1
- package/out/_next/static/chunks/pages/changelog-cb1df3a70b20f1b8.js +0 -1
- package/src/hooks/useChangelog.ts +0 -12
- package/test/pages/simulator.test.tsx +0 -332
- /package/out/_next/static/{BPmSPNuacjzy05VoBBWe0 → qdfgiTBDB3fV4Iyei9xeV}/_ssgManifest.js +0 -0
|
@@ -17,10 +17,6 @@ const initialState: UserContextStoreType = {
|
|
|
17
17
|
onboarding: false,
|
|
18
18
|
advancedRepository: false,
|
|
19
19
|
},
|
|
20
|
-
updatesViewed: {
|
|
21
|
-
latest: null,
|
|
22
|
-
latestNonBreaking: null,
|
|
23
|
-
},
|
|
24
20
|
hasSeenTutorialsToolTip: false,
|
|
25
21
|
hasSeenSimulatorToolTip: false,
|
|
26
22
|
hasSeenChangesToolTip: false,
|
|
@@ -37,10 +33,6 @@ export const skipReviewCreator = createAction("USER_CONTEXT/SKIP_REVIEW")<{
|
|
|
37
33
|
reviewType: UserReviewType;
|
|
38
34
|
}>();
|
|
39
35
|
|
|
40
|
-
export const updatesViewedCreator = createAction("USER_CONTEXT/VIEWED_UPDATES")<
|
|
41
|
-
UserContextStoreType["updatesViewed"]
|
|
42
|
-
>();
|
|
43
|
-
|
|
44
36
|
export const hasSeenTutorialsToolTipCreator = createAction(
|
|
45
37
|
"USER_CONTEXT/VIEW_TUTORIALS_TOOL_TIP",
|
|
46
38
|
)();
|
|
@@ -60,7 +52,6 @@ export const changesPushSuccess = createAction(
|
|
|
60
52
|
type userContextActions = ActionType<
|
|
61
53
|
| typeof sendAReviewCreator
|
|
62
54
|
| typeof skipReviewCreator
|
|
63
|
-
| typeof updatesViewedCreator
|
|
64
55
|
| typeof hasSeenTutorialsToolTipCreator
|
|
65
56
|
| typeof hasSeenSimulatorToolTipCreator
|
|
66
57
|
| typeof hasSeenChangesToolTipCreator
|
|
@@ -75,10 +66,6 @@ export const getUserReview = (state: SliceMachineStoreType): UserReviewState =>
|
|
|
75
66
|
advancedRepository: false,
|
|
76
67
|
};
|
|
77
68
|
|
|
78
|
-
export const getUpdatesViewed = (
|
|
79
|
-
state: SliceMachineStoreType,
|
|
80
|
-
): UserContextStoreType["updatesViewed"] => state.userContext.updatesViewed;
|
|
81
|
-
|
|
82
69
|
export const userHasSeenTutorialsToolTip = (
|
|
83
70
|
state: SliceMachineStoreType,
|
|
84
71
|
): boolean => state.userContext.hasSeenTutorialsToolTip || false;
|
|
@@ -110,12 +97,6 @@ export const userContextReducer: Reducer<
|
|
|
110
97
|
[action.payload.reviewType]: true,
|
|
111
98
|
},
|
|
112
99
|
};
|
|
113
|
-
case getType(updatesViewedCreator): {
|
|
114
|
-
return {
|
|
115
|
-
...state,
|
|
116
|
-
updatesViewed: action.payload,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
100
|
case getType(hasSeenTutorialsToolTipCreator): {
|
|
120
101
|
return {
|
|
121
102
|
...state,
|
|
@@ -7,10 +7,6 @@ export enum AuthStatus {
|
|
|
7
7
|
|
|
8
8
|
export type UserContextStoreType = {
|
|
9
9
|
userReview: UserReviewState;
|
|
10
|
-
updatesViewed: {
|
|
11
|
-
latest: string | null;
|
|
12
|
-
latestNonBreaking: string | null;
|
|
13
|
-
};
|
|
14
10
|
hasSeenTutorialsToolTip: boolean;
|
|
15
11
|
hasSeenSimulatorToolTip: boolean;
|
|
16
12
|
hasSeenChangesToolTip: boolean;
|
package/src/redux/saga.ts
CHANGED
|
@@ -2,11 +2,9 @@ import { fork } from "redux-saga/effects";
|
|
|
2
2
|
|
|
3
3
|
import { watchSimulatorSagas } from "@src/modules/simulator";
|
|
4
4
|
import { watchToasterSagas } from "@src/modules/toaster";
|
|
5
|
-
import { watchChangelogSagas } from "@src/modules/environment";
|
|
6
5
|
|
|
7
6
|
// Single entry point to start all Sagas at once
|
|
8
7
|
export default function* rootSaga() {
|
|
9
8
|
yield fork(watchSimulatorSagas);
|
|
10
9
|
yield fork(watchToasterSagas);
|
|
11
|
-
yield fork(watchChangelogSagas);
|
|
12
10
|
}
|
|
@@ -14,19 +14,6 @@ export const dummyServerState: Pick<
|
|
|
14
14
|
localSliceSimulatorURL: "http://localhost:3000/slice-simulator",
|
|
15
15
|
},
|
|
16
16
|
packageManager: "npm",
|
|
17
|
-
changelog: {
|
|
18
|
-
sliceMachine: {
|
|
19
|
-
currentVersion: "0.2.0",
|
|
20
|
-
latestNonBreakingVersion: "0.1.2",
|
|
21
|
-
updateAvailable: false,
|
|
22
|
-
versions: [],
|
|
23
|
-
},
|
|
24
|
-
adapter: {
|
|
25
|
-
name: "test-adapter",
|
|
26
|
-
updateAvailable: false,
|
|
27
|
-
versions: [],
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
17
|
endpoints: {
|
|
31
18
|
PrismicWroom: "https://prismic.io/",
|
|
32
19
|
PrismicAuthentication: "https://auth.prismic.io/",
|
|
@@ -2,13 +2,10 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
environmentReducer,
|
|
5
|
-
getChangelog,
|
|
6
|
-
getChangelogCreator,
|
|
7
5
|
refreshStateCreator,
|
|
8
6
|
} from "@src/modules/environment";
|
|
9
7
|
import { EnvironmentStoreType } from "@src/modules/environment/types";
|
|
10
8
|
import { dummyServerState } from "./__fixtures__/serverState";
|
|
11
|
-
import { SliceMachineStoreType } from "@src/redux/type";
|
|
12
9
|
|
|
13
10
|
const dummyEnvironmentState: EnvironmentStoreType = dummyServerState.env;
|
|
14
11
|
|
|
@@ -44,59 +41,5 @@ describe("[Environment module]", () => {
|
|
|
44
41
|
repo: "newUrl",
|
|
45
42
|
});
|
|
46
43
|
});
|
|
47
|
-
|
|
48
|
-
it("should update the environment state given CHANGELOG.RESPONSE action", () => {
|
|
49
|
-
const newChangeLog = {
|
|
50
|
-
sliceMachine: {
|
|
51
|
-
currentVersion: "1.0.0",
|
|
52
|
-
updateAvailable: true,
|
|
53
|
-
latestNonBreakingVersion: "0.1.2",
|
|
54
|
-
versions: [],
|
|
55
|
-
},
|
|
56
|
-
adapter: {
|
|
57
|
-
name: "test-adapter",
|
|
58
|
-
updateAvailable: true,
|
|
59
|
-
versions: [],
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const action = getChangelogCreator.success({
|
|
63
|
-
changelog: newChangeLog,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect(environmentReducer(dummyEnvironmentState, action)).toEqual({
|
|
67
|
-
...dummyEnvironmentState,
|
|
68
|
-
changelog: newChangeLog,
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("[Selector]", () => {
|
|
74
|
-
it("returns the changelog currently in the store", () => {
|
|
75
|
-
const sliceMachineStore = {
|
|
76
|
-
environment: dummyEnvironmentState,
|
|
77
|
-
} as SliceMachineStoreType;
|
|
78
|
-
const result = getChangelog(sliceMachineStore);
|
|
79
|
-
expect(result).toEqual(dummyEnvironmentState.changelog);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("returns the default changelog when there isn't one in the store", () => {
|
|
83
|
-
const sliceMachineStore = {
|
|
84
|
-
environment: {},
|
|
85
|
-
} as SliceMachineStoreType;
|
|
86
|
-
const result = getChangelog(sliceMachineStore);
|
|
87
|
-
expect(result).toEqual({
|
|
88
|
-
sliceMachine: {
|
|
89
|
-
currentVersion: "",
|
|
90
|
-
latestNonBreakingVersion: null,
|
|
91
|
-
updateAvailable: false,
|
|
92
|
-
versions: [],
|
|
93
|
-
},
|
|
94
|
-
adapter: {
|
|
95
|
-
name: "",
|
|
96
|
-
updateAvailable: false,
|
|
97
|
-
versions: [],
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
44
|
});
|
|
102
45
|
});
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
userContextReducer,
|
|
5
5
|
sendAReviewCreator,
|
|
6
6
|
skipReviewCreator,
|
|
7
|
-
updatesViewedCreator,
|
|
8
7
|
} from "@src/modules/userContext";
|
|
9
8
|
import { UserContextStoreType } from "@src/modules/userContext/types";
|
|
10
9
|
|
|
@@ -27,10 +26,6 @@ describe("[UserContext module]", () => {
|
|
|
27
26
|
onboarding: false,
|
|
28
27
|
advancedRepository: false,
|
|
29
28
|
},
|
|
30
|
-
updatesViewed: {
|
|
31
|
-
latest: null,
|
|
32
|
-
latestNonBreaking: null,
|
|
33
|
-
},
|
|
34
29
|
};
|
|
35
30
|
|
|
36
31
|
const action = sendAReviewCreator({
|
|
@@ -55,10 +50,6 @@ describe("[UserContext module]", () => {
|
|
|
55
50
|
onboarding: false,
|
|
56
51
|
advancedRepository: false,
|
|
57
52
|
},
|
|
58
|
-
updatesViewed: {
|
|
59
|
-
latest: null,
|
|
60
|
-
latestNonBreaking: null,
|
|
61
|
-
},
|
|
62
53
|
};
|
|
63
54
|
|
|
64
55
|
const action = skipReviewCreator({
|
|
@@ -75,27 +66,5 @@ describe("[UserContext module]", () => {
|
|
|
75
66
|
|
|
76
67
|
expect(userContextReducer(initialState, action)).toEqual(expectedState);
|
|
77
68
|
});
|
|
78
|
-
|
|
79
|
-
it("should update dismissedUpdate to the value of the update dismissed", () => {
|
|
80
|
-
// @ts-expect-error TS(2739) FIXME: Type '{ hasSendAReview: false;... Remove this comment to see the full error message
|
|
81
|
-
const initialState: UserContextStoreType = {
|
|
82
|
-
hasSendAReview: false,
|
|
83
|
-
updatesViewed: {
|
|
84
|
-
latest: null,
|
|
85
|
-
latestNonBreaking: null,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const versions = { latestNonBreaking: "0.1.0", latest: "1.0.0" };
|
|
90
|
-
|
|
91
|
-
const action = updatesViewedCreator(versions);
|
|
92
|
-
|
|
93
|
-
const expectedState = {
|
|
94
|
-
...initialState,
|
|
95
|
-
updatesViewed: versions,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
expect(userContextReducer(initialState, action)).toEqual(expectedState);
|
|
99
|
-
});
|
|
100
69
|
});
|
|
101
70
|
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export const VersionKind = {
|
|
2
|
-
MAJOR: "MAJOR",
|
|
3
|
-
MINOR: "MINOR",
|
|
4
|
-
PATCH: "PATCH",
|
|
5
|
-
FIRST: "FIRST",
|
|
6
|
-
} as const;
|
|
7
|
-
export type VersionKind = (typeof VersionKind)[keyof typeof VersionKind];
|
|
8
|
-
|
|
9
|
-
// Model built from Npm version number and GitHub release note
|
|
10
|
-
export interface PackageVersion {
|
|
11
|
-
versionNumber: string;
|
|
12
|
-
releaseNote: string | null;
|
|
13
|
-
kind: VersionKind | undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Release not fetch from GitHub
|
|
17
|
-
export interface ReleaseNote {
|
|
18
|
-
name: string;
|
|
19
|
-
body: string;
|
|
20
|
-
draft: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type SliceMachinePackageChangelog = {
|
|
24
|
-
currentVersion: string;
|
|
25
|
-
latestNonBreakingVersion: string | null;
|
|
26
|
-
updateAvailable: boolean;
|
|
27
|
-
versions: PackageVersion[];
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type AdapterPackageChangelog = {
|
|
31
|
-
name: string;
|
|
32
|
-
updateAvailable: boolean;
|
|
33
|
-
versions: string[];
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export interface PackageChangelog {
|
|
37
|
-
sliceMachine: SliceMachinePackageChangelog;
|
|
38
|
-
adapter: AdapterPackageChangelog;
|
|
39
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[286],{15836:function(e,n,r){"use strict";r.d(n,{Z:function(){return U}});var i,t=r(62230),s=r(85244),o=r(52322),a=r(2784),l=r(56580),c=r(75289),u=r(54132),d=r(951),x=r(75100),p=r(25812),h=r(77174),f=r(24340),v=r(90374),g=r(22710),m=r(99267),j=r(76473),b=r(75329),C=r(40432),y=function(e){var n=e.inputFile,r=e.handleFile,i=e.children,t=e.isDragActive;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(c.__,{htmlFor:"input-file",variant:"buttons.white",sx:{p:2,px:0,display:"flex",justifyContent:"center",width:200,alignItems:"center",flex:1},children:i||"Select file"}),(0,o.jsx)("input",{id:"input-file",type:"file",ref:n,style:{display:"none"},accept:b.nG.map(function(e){return"image/".concat(e)}).join(","),onChange:function(e){var n;r(null===(n=e.target.files)||void 0===n?void 0:n[0],t)}})]})},F=r(32665),E=r(3098),w=r(61931),S=r(67557),I=r(88932),D=r(82770);function k(e){return Z.apply(this,arguments)}function Z(){return(Z=(0,g.Z)(function(e){var n,r,i,o,a,l,c,u,d,x;return(0,m.__generator)(this,function(p){switch(p.label){case 0:n=e.variationId,r=e.slice,i=e.file,o=e.method,p.label=1;case 1:return p.trys.push([1,3,,4]),(a=new FormData).append("file",i),a.append("libraryName",r.from),a.append("sliceName",r.model.name),a.append("variationId",n),[4,(0,D.XQ)({libraryName:r.from,sliceId:r.model.id,variationId:n,file:i})];case 2:if(c=(l=p.sent()).errors,u=l.url,c.length>0)throw c;return D.Xe.track({event:"screenshot-taken",type:"custom",method:o}),[2,(0,s.Z)((0,t.Z)({},r),{screenshots:(0,s.Z)((0,t.Z)({},r.screenshots),(0,S.Z)({},n,{url:u}))})];case 3:return d=p.sent(),x="Screenshot not saved",console.error(x,d),I.Am.error(x),[3,4];case 4:return[2]}})})).apply(this,arguments)}var R,_=function(){return(0,o.jsx)(c.kC,{variant:"boxes.centered",sx:{p:2,position:"absolute",height:"100%",width:"100%",background:"rgba(249, 248, 249, 0.7)",backdropFilter:"blur(5px)",zIndex:"1",pointerEvents:"none"},children:(0,o.jsxs)(c.kC,{variant:"boxes.centered",sx:{border:"1px dashed #6E56CF",height:"100%",width:"100%",borderRadius:"4px"},children:[(0,o.jsx)(M,{isActive:!0}),(0,o.jsx)(c.xv,{sx:{my:2},children:"Drop file here"}),(0,o.jsx)(c.xv,{variant:"secondary",children:"Maximum upload size file: 128Mb"})]})})},M=function(e){var n=e.isActive;return(0,o.jsx)(c.kC,{sx:{p:1,borderRadius:"50%",bg:n?"#F1EEFE":"#EDECEE",alignItems:"center",justifyContent:"center",width:"48px",height:"48px"},children:(0,o.jsx)(d.IEK,{style:{color:n?"#6E56CF":"#6F6E77",fontSize:"34px"}})})},H=function(e){var n=e.variationID,r=e.slice,i=e.imageTypes,u=void 0===i?b.nG:i,d=e.onUploadSuccess,x=r.screenshots[n],p=(0,v.Z)().openToaster,h=(0,a.useState)(!1),f=h[0],S=h[1],I=(0,a.useState)(!1),D=I[0],Z=I[1];(0,j.y1)(["meta+v","ctrl+v"],function(){X()},[n,r,]);var R,H,O,z,A,L,T,N,V=(0,v.Z)().saveSliceCustomScreenshotSuccess,P=(0,l.v9)(function(e){return{isLoadingScreenshot:(0,F.hg)(e,E.z.GENERATE_SLICE_CUSTOM_SCREENSHOT)}}).isLoadingScreenshot,B=(O=(H={onHandleFile:(R=(0,g.Z)(function(e,i){var t,s;return(0,m.__generator)(this,function(o){switch(o.label){case 0:return[4,k({slice:r,file:e,method:i?"dragAndDrop":"upload",variationId:n})];case 1:return t=o.sent(),Z(!1),(s=null==t?void 0:t.screenshots[n])&&(V(n,s,t),d&&d(t)),[2]}})}),function(e,n){return R.apply(this,arguments)})}).onHandleFile,z=(0,a.useRef)(null),A=(0,g.Z)(function(e,n){return(0,m.__generator)(this,function(r){switch(r.label){case 0:if(!e)return[3,2];return[4,O(e,n)];case 1:r.sent(),(null==z?void 0:z.current)&&(z.current.value=""),r.label=2;case 2:return[2]}})}),{handleFile:L=function(e,n){return A.apply(this,arguments)},inputFile:z,FileInputRenderer:y,fileInputProps:{inputFile:z,handleFile:L}}),U=B.FileInputRenderer,W=B.fileInputProps,G=(T=(0,g.Z)(function(e){var i,t;return(0,m.__generator)(this,function(s){switch(s.label){case 0:if(e.size>128e6)return[2,p("File is too big. Max file size: 128Mb.",C.Jf.ERROR)];return[4,k({slice:r,file:e,method:"dragAndDrop",variationId:n})];case 1:return(t=null==(i=s.sent())?void 0:i.screenshots[n])&&(V(n,t,i),d&&d(i)),[2]}})}),function(e){return T.apply(this,arguments)}),q="function"==typeof navigator.clipboard.read,X=(N=(0,g.Z)(function(){var e,n,r,i,t;return(0,m.__generator)(this,function(s){switch(s.label){case 0:if(!q)return[2];s.label=1;case 1:return s.trys.push([1,5,,6]),[4,navigator.clipboard.read()];case 2:if(!(void 0!==(e=s.sent())[0])||!(void 0!==(n=e[0].types.find(function(e){return u.map(function(e){return"image/".concat(e)}).includes(e)}))))return[3,4];return[4,e[0].getType(n)];case 3:return r=s.sent(),i=new File([r],"file"),[2,G(i)];case 4:return[3,6];case 5:return t=s.sent(),console.error("Could not paste file",t),[3,6];case 6:return[2]}})}),function(){return N.apply(this,arguments)}),J=function(e){e.preventDefault(),S(!1);var n,r=null===(n=e.dataTransfer.files)||void 0===n?void 0:n[0];if(void 0!==r)return u.some(function(e){return"image/".concat(e)===r.type})?void G(r):p("Only files of type ".concat(u.join(", ")," are accepted."),C.Jf.ERROR)},K=function(e){return function(n){n.preventDefault(),S(e)}},Y=function(e){return function(n){n.preventDefault(),Z(e)}};return(0,o.jsxs)(c.kC,{as:"form",variant:"boxes.centered",sx:{bg:"#F9F8F9",position:"relative",borderRadius:"6px",height:"320px"},onDragEnter:K(!0),onDragLeave:K(!1),onDragOver:K(!0),onMouseEnter:Y(!0),onMouseLeave:Y(!1),onSubmit:function(e){return e.preventDefault()},onDrop:J,children:[P?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(c.$j,{}),(0,o.jsx)(c.xv,{sx:{my:2},children:"Uploading file ..."})]}):null,P||void 0===x?null:(0,o.jsx)(w.q,{src:x.url,sx:{width:"100%",height:"100%",maxHeight:"100%",backdropFilter:"blur(5px)"}}),P?null:(0,o.jsx)(c.kC,{sx:{p:2,position:"absolute",width:"100%",height:"100%",borderRadius:"6px",background:"#F9F8F9B2",justifyContent:"center",alignItems:"center",visibility:D||void 0===x?"visible":"hidden"},children:(0,o.jsx)(c.kC,{variant:"boxes.centered",sx:{border:"1px dashed #6E56CF",height:"100%",width:"100%",borderRadius:"4px"},children:(0,o.jsxs)(c.kC,{sx:{width:"100%",justifyContent:"center",alignItems:"center",flexDirection:"column"},children:[(0,o.jsx)(M,{isActive:f}),(0,o.jsx)(c.xv,{sx:{my:2},children:q?"Paste, drop or ...":"Drop or ..."}),(0,o.jsx)(U,(0,s.Z)((0,t.Z)({},W),{isDragActive:f})),(0,o.jsx)(c.xv,{sx:{color:"greyIcon",mt:1},children:"Maximum file size: 128Mb"})]})})}),f?(0,o.jsx)(_,{}):null]})},O=function(e){return(0,o.jsxs)("svg",(0,s.Z)((0,t.Z)({width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),{children:[(0,o.jsxs)("g",{clipPath:"url(#clip0_5065_192538)",children:[(0,o.jsx)("path",{d:"M9.66862 19.9993C11.1406 19.9993 12.3353 18.8047 12.3353 17.3327V14.666H9.66862C8.19662 14.666 7.00195 15.8607 7.00195 17.3327C7.00195 18.8047 8.19662 19.9993 9.66862 19.9993Z",fill:"#0ACF83"}),(0,o.jsx)("path",{d:"M7.00195 12.0007C7.00195 10.5287 8.19662 9.33398 9.66862 9.33398H12.3353V14.6673H9.66862C8.19662 14.6673 7.00195 13.4727 7.00195 12.0007Z",fill:"#A259FF"}),(0,o.jsx)("path",{d:"M7.00195 6.66667C7.00195 5.19467 8.19662 4 9.66862 4H12.3353V9.33333H9.66862C8.19662 9.33333 7.00195 8.13867 7.00195 6.66667Z",fill:"#F24E1E"}),(0,o.jsx)("path",{d:"M12.334 4H15.0007C16.4727 4 17.6673 5.19467 17.6673 6.66667C17.6673 8.13867 16.4727 9.33333 15.0007 9.33333H12.334V4Z",fill:"#FF7262"}),(0,o.jsx)("path",{d:"M17.6673 12.0007C17.6673 13.4727 16.4727 14.6673 15.0007 14.6673C13.5287 14.6673 12.334 13.4727 12.334 12.0007C12.334 10.5287 13.5287 9.33398 15.0007 9.33398C16.4727 9.33398 17.6673 10.5287 17.6673 12.0007Z",fill:"#1ABCFE"})]}),(0,o.jsx)("defs",{children:(0,o.jsx)("clipPath",{id:"clip0_5065_192538",children:(0,o.jsx)("rect",{width:"10.6688",height:"16",fill:"white",transform:"translate(7 4)"})})})]}))};(R=i||(i={})).Mac="Mac",R.Linux="Linux",R.Windows="Windows";var z=function(){var e=navigator.userAgent,n=i.Linux;return Object.values(i).forEach(function(r){e.includes(r)&&(n=r)}),n},A=r(36416),L=r.n(A),T=function(e){var n=e.children;return(0,o.jsx)("kbd",{className:L().root,children:n})},N=function(){var e,n=[i.Windows,i.Linux].includes(z())?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(T,{children:"ctrl"})," + ",(0,o.jsx)(T,{children:"shift"})," + ",(0,o.jsx)(T,{children:"c"})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(T,{children:"cmd"})," + ",(0,o.jsx)(T,{children:"shift"})," + ",(0,o.jsx)(T,{children:"c"})]});return(0,o.jsxs)(c.kC,{sx:{pl:"4px",alignItems:"center",color:"#000",borderRadius:"6px",fontSize:"12px",lineHeight:"24px",border:"1px solid #E4E2E4",boxShadow:"0px 1px 0px 0px rgba(0, 0, 0, 0.04)",width:"100%",minHeight:"40px"},children:[(0,o.jsx)(O,{}),(0,o.jsxs)("div",{children:["Use\xa0",n," to copy any frame as .png, then just paste it here"]})]})},V=function(e){var n=e.isValid;return(0,o.jsx)(c.kC,{sx:{p:2,border:"1px solid #E4E2E4",borderRadius:"6px",bg:"#FFF"},children:n?(0,o.jsx)(d.Ypm,{style:{fontSize:"16px"}}):(0,o.jsx)(x.j6O,{style:{fontSize:"16px",color:"#ED811C"}})})},P=function(e){var n=e.slice,r=e.onSelectVariation,i=e.variationSelector;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(c.X6,{as:"h4",sx:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:n.model.name}),(0,o.jsx)(c.xu,{children:(0,o.jsx)(c.xu,{as:"ul",sx:{pl:0,my:3},children:n.model.variations.map(function(e){var a=i.sliceID,l=i.variationID,u=a===n.model.id&&l===e.id;return(0,o.jsx)(c.xu,{as:"li",sx:(0,s.Z)((0,t.Z)({listStyle:"none",my:2,p:2,cursor:"pointer",borderRadius:"4px"},u&&{bg:"#EDECEE",fontWeight:"500"}),{":hover":{bg:"#EDECEE"}}),onClick:function(){return r({sliceID:n.model.id,variationID:e.id})},children:(0,o.jsxs)(c.kC,{sx:{alignItems:"center"},children:[(0,o.jsx)(V,{isValid:!!n.screenshots[e.id]}),(0,o.jsx)(c.xv,{sx:{ml:2},children:e.name})]})},"".concat(n.model.id,"-").concat(e.id))})})})]})},B=function(e,n){return e||(n.length?{sliceID:n[0].model.id,variationID:n[0].model.variations[0].id}:void 0)},U=function(e){var n=e.slices,r=e.defaultVariationSelector,i=e.onUploadSuccess,t=(0,v.Z)().closeModals,s=(0,l.v9)(function(e){return{isOpen:(0,h.gP)(e,f.q.SCREENSHOTS)}}).isOpen,d=(0,a.useState)(B(r,n)),x=d[0],g=d[1];if((0,a.useEffect)(function(){g(B(r,n))},[null==r?void 0:r.sliceID,null==r?void 0:r.variationID,s,]),0===n.length||!x)return null;var m,j="function"==typeof navigator.clipboard.read;return(0,o.jsx)(p.Z,{isOpen:s,shouldCloseOnOverlayClick:!0,onRequestClose:function(){return t()},children:(0,o.jsx)(u.Z,{radius:"0px",bodySx:{p:0,bg:"#FFF",position:"relative"},sx:{border:"none"},Header:function(e){var n=e.radius;return(0,o.jsxs)(c.kC,{sx:{position:"sticky",top:0,zIndex:1,background:"gray",p:"16px",alignItems:"center",justifyContent:"space-between",borderTopLeftRadius:n,borderTopRightRadius:n,borderBottom:function(e){var n;return"1px solid ".concat(String(null===(n=e.colors)||void 0===n?void 0:n.borders))}},children:[(0,o.jsx)(c.X6,{sx:{fontSize:"20px"},children:"Slice screenshots"}),(0,o.jsx)(c.x8,{type:"button",onClick:function(){return t()}})]})},Footer:null,children:(0,o.jsxs)(c.xu,{sx:{display:"flex",flexWrap:"wrap",height:"100%"},children:[(0,o.jsx)(c.xu,{sx:{p:3,bg:"grey07",flexGrow:1,overflow:"auto",maxHeight:"100%",flexBasis:"sidebar"},children:n.map(function(e,n){return(0,o.jsx)(P,{slice:e,variationSelector:x,onSelectVariation:g},"".concat(e.model.id,"-").concat(n))})}),(0,o.jsxs)(c.kC,{as:"main",sx:{p:3,flexGrow:99999,flexBasis:0,flexDirection:"column",minWidth:320,gap:"8px"},children:[j?(0,o.jsx)(N,{}):void 0,(m=n.find(function(e){return e.model.id===x.sliceID}))?(0,o.jsx)(H,{variationID:x.variationID,slice:m,onUploadSuccess:i}):null]})]})})})}},61931:function(e,n,r){"use strict";r.d(n,{q:function(){return c}});var i=r(62230),t=r(52322),s=r(2784),o=r(75289),a=r(65186),l=(0,s.memo)(function(e){var n=e.src;return(0,t.jsx)(o.Ee,{src:n,alt:"Preview image",sx:{maxHeight:"100%"}})}),c=function(e){var n=e.src,r=e.sx;return(0,t.jsx)(o.kC,{sx:(0,i.Z)({position:"relative",alignItems:"center",justifyContent:"center",overflow:"hidden",backgroundImage:"url(/pattern.png)",backgroundColor:"headSection",backgroundRepeat:"repeat",backgroundSize:"20px",borderRadius:"4px"},r),children:void 0!==n?(0,t.jsx)(l,{src:n}):(0,t.jsxs)(o.xv,{sx:{display:"flex",flexDirection:"column",alignItems:"center"},children:[(0,t.jsx)(a.eJU,{}),"You have no screenshot yet."]})})}},47731:function(e,n,r){"use strict";r.d(n,{H:function(){return s}});var i=r(2784),t=r(90374),s=function(){var e=(0,t.Z)().openScreenshotsModal,n=(0,i.useState)({sliceFilterFn:function(e){return e}}),r=n[0],s=n[1];return{modalPayload:r,onOpenModal:function(n){s(n),e()}}}},36416:function(e){e.exports={root:"Kbd_root__nBos2"}}}]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[477],{37782:function(e,n,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/changelog",function(){return r(57825)}])},39576:function(e,n,r){"use strict";r.d(n,{Z:function(){return d}});var i=r(62230),s=r(52322);r(2784);var t=r(59326),a=r(75289),o=r(61183),c=function(e){return{subLanguage:"xml",contains:[e.COMMENT("<!--","-->",{relevance:10}),{begin:/^(\s*)(<script(\s*context="module")?>)/gm,end:/^(\s*)(<\/script>)/gm,subLanguage:"javascript",excludeBegin:!0,excludeEnd:!0,contains:[{begin:/^(\s*)(\$:)/gm,end:/(\s*)/gm,className:"keyword"},]},{begin:/^(\s*)(<style.*>)/gm,end:/^(\s*)(<\/style>)/gm,subLanguage:"css",excludeBegin:!0,excludeEnd:!0},{begin:/\{/gm,end:/\}/gm,subLanguage:"javascript",contains:[{begin:/[\{]/,end:/[\}]/,skip:!0},{begin:/([#:\/@])(if|else|each|await|then|catch|debug|html)/gm,className:"keyword",relevance:10},]},]}};o.Z.registerLanguage("svelte",c);var l=["javascript","bash","xml","html","json"],d=function(e){var n,r=e.children,c=e.lang,d=e.sx,g=e.codeStyle,x=e.codeClass,p=e.Header,u=(0,t.B7)().theme,h=c?o.Z.highlight(r,{language:"vue"===c?"html":c}).value:o.Z.highlightAuto(r,l).value;return(0,s.jsxs)(a.kC,{as:"pre",sx:d,children:[p?(0,s.jsx)(p,{}):null,(0,s.jsx)("code",{className:"hljs".concat(x?" ".concat(x):""),style:(0,i.Z)({overflowX:"auto",padding:"3px 5px",borderRadius:"6px",border:"1px solid",borderColor:String(null===(n=u.colors)||void 0===n?void 0:n.textClear)},g),dangerouslySetInnerHTML:{__html:h}})]})}},57825:function(e,n,r){"use strict";r.r(n),r.d(n,{default:function(){return H}});var i,s,t=r(52322),a=r(97729),o=r.n(a),c=r(22715),l=r(65077),d=r(75289),g=r(56580),x=r(39092),p=r(2784),u=r(62230),h=r(12170),v=function(e){var n=e.type,r=e.hasUpToDateVersions;return(0,t.jsx)(d.xv,{sx:(0,u.Z)({padding:"0px 4px",borderRadius:"2px",fontSize:"8px",fontWeight:600,lineHeight:"16px",textTransform:"uppercase"},(n===i.Latest||n===i.LatestNonBreaking)&&{bg:"grey02",color:"code.gray"},n===i.Current&&r&&{bg:"lightGreen",color:"code.green"},n===i.Current&&!r&&{bg:"lightOrange",color:"code.orange"}),children:n})},f=function(e){var n=e.isSelected,r=e.onClick,i=e.versionNumber,s=e.tags,a=e.hasUpToDateVersions;return(0,t.jsxs)(d.kC,{sx:(0,u.Z)({p:1,borderRadius:"4px",cursor:"pointer",transition:"200ms all",justifyContent:"space-between",alignItems:"center"},n?{color:"purple",bg:(0,h.DZ)("purple",.95)}:{"&:hover":{bg:"grey01"}}),onClick:r,children:[(0,t.jsx)(d.xv,{children:i}),(0,t.jsx)(d.kC,{sx:{gap:"8px"},children:s.map(function(e){return(0,t.jsx)(v,{type:e,hasUpToDateVersions:a},e)})})]})};(s=i||(i={})).Latest="LATEST",s.LatestNonBreaking="LATEST-NON-BREAKING",s.Current="CURRENT";var m=function(e){var n,r=e.changelog,s=e.selectedVersion,a=e.selectVersion,o=function(e){var n=[];return e===l?n.push(i.Latest):e===r.sliceMachine.latestNonBreakingVersion&&n.push(i.LatestNonBreaking),e===r.sliceMachine.currentVersion&&n.push(i.Current),n},l=null===(n=r.sliceMachine.versions[0])||void 0===n?void 0:n.versionNumber,g=!r.adapter.updateAvailable&&!r.sliceMachine.updateAvailable;return(0,t.jsxs)(d.kC,{sx:{minWidth:"228px",borderRight:"1px dashed",borderColor:c.TV.color.greyLight6,flexDirection:"column",paddingRight:"48px"},children:[(0,t.jsxs)(d.kC,{sx:{flexDirection:"column",borderBottom:"1px dashed",borderColor:c.TV.color.greyLight6,paddingBottom:"28px"},children:[(0,t.jsx)(d.xv,{sx:{fontSize:"20px",fontWeight:500,lineHeight:"32px"},children:"Changelog"}),(0,t.jsx)(d.xv,{sx:{fontSize:"16px",fontWeight:500,lineHeight:"24px",marginTop:"28px"},children:"All versions"})]}),(0,t.jsx)(d.kC,{sx:{mt:"24px",flexDirection:"column",gap:"4px",overflow:"auto"},children:r.sliceMachine.versions.map(function(e,n){return(0,t.jsx)(f,{isSelected:(null==s?void 0:s.versionNumber)===e.versionNumber,onClick:function(){return a(e)},versionNumber:e.versionNumber,tags:o(e.versionNumber),hasUpToDateVersions:g},"versionBadge-".concat(e.versionNumber,"-").concat(n))})})]})},b={MAJOR:"MAJOR",MINOR:"MINOR",PATCH:"PATCH",FIRST:"FIRST"},j=function(e){var n=e.versionKind,r=(0,u.Z)({fontSize:"14px",padding:"2px 4px",borderRadius:"4px",textTransform:"uppercase"},n===b.MAJOR?{color:"purple",bg:(0,h.DZ)("purple",.85)}:{color:"grey05",bg:"grey02"});return(0,t.jsx)(d.xv,{sx:r,children:n})},k=r(19870),C=function(e){var n=e.releaseNote;return(0,t.jsx)(d.xv,{sx:{"h1, h2, h3":{fontSize:"16px",fontWeight:600,lineHeight:"20px"},p:{fontSize:"14px",fontWeight:400,lineHeight:"20px"},b:{fontSize:"14px",fontWeight:600,lineHeight:"20px"},code:{color:"code.orange"},li:{listStyleType:"disc",marginLeft:"25px",paddingLeft:"5px"}},dangerouslySetInnerHTML:{__html:k.TU.parse(n)}})},N=r(951),y=r(39576),T=function(e){var n,r,i,s,a,o=e.changelog,c=e.selectedVersion,l=e.packageManager,g=c.versionNumber===o.sliceMachine.versions[0].versionNumber,x=(n={sliceMachineVersionToInstall:g?"latest":c.versionNumber,isLatestSliceMachineVersion:g,adapterName:o.adapter.name},r=n.sliceMachineVersionToInstall,i=n.isLatestSliceMachineVersion,s=n.adapterName,a=["slice-machine-ui@".concat(r)],i&&a.push("".concat(s,"@latest")),a),p=function(e,n){var r=n.join(" ");switch(e){case"bun":return"bun add --development ".concat(r);case"npm":return"npm install --save-dev ".concat(r);case"pnpm":case"pnpm@6":return"pnpm add --save-dev ".concat(r);case"yarn":case"yarn@berry":return"yarn add --dev ".concat(r)}}(l,x),u=o.adapter.updateAvailable&&!o.sliceMachine.updateAvailable;return(0,t.jsxs)(t.Fragment,{children:[u&&g&&(0,t.jsxs)(d.kC,{sx:{padding:"16px",bg:"lightOrange",color:"darkOrange",fontSize:"13px",lineHeight:"24px",borderRadius:"4px",gap:"16px"},children:[(0,t.jsx)(N.CSE,{size:"24px"}),"It looks like you are using an outdated version of the adapter. Run this command to update your adapter:"]}),(0,t.jsxs)(d.kC,{sx:{flexDirection:"column",gap:"16px",padding:"16px",bg:"grey01"},children:[(0,t.jsx)(d.xv,{sx:{fontSize:"16px",fontWeight:500,lineHeight:"20px"},children:"How to install"}),(0,t.jsxs)(d.kC,{sx:{gap:"8px"},children:[(0,t.jsx)(y.Z,{codeStyle:{color:"white",flex:1,padding:"8px"},sx:{flex:1},children:p}),(0,t.jsx)(d.zx,{variant:"secondary",onClick:function(){navigator.clipboard.writeText(p)},children:"Copy"})]})]})]})},S=function(){return(0,t.jsxs)("div",{children:["Could not fetch release notes."," ",(0,t.jsx)("a",{href:"https://github.com/prismicio/slice-machine/releases",target:"_blank",rel:"noopener noreferrer",children:"Find out more on GitHub"})]})},M=function(e){var n,r=e.changelog,i=e.selectedVersion,s=e.packageManager;return(0,t.jsxs)(d.kC,{sx:{flexDirection:"column"},children:[(0,t.jsxs)(d.kC,{sx:{padding:"0px 0px 32px 32px",borderBottom:"1px dashed",borderColor:c.TV.color.greyLight6,justifyContent:"space-between",alignItems:"center"},children:[(0,t.jsx)(d.xv,{sx:{fontSize:"24px",fontWeight:600,lineHeight:"32px"},children:"Version ".concat(i.versionNumber)}),!!i.kind&&(0,t.jsx)(j,{versionKind:i.kind})]}),(0,t.jsxs)(d.kC,{sx:{flexDirection:"column",padding:"24px 0px 0px 32px",gap:"24px"},children:[(null===(n=i.releaseNote)||void 0===n?void 0:n.includes("# Breaking Change"))&&(0,t.jsxs)(d.kC,{sx:{padding:"16px",bg:"lightOrange",color:"darkOrange",fontSize:"13px",lineHeight:"24px",borderRadius:"4px",gap:"16px"},"data-testid":"breaking-changes-warning",children:[(0,t.jsx)(N.CSE,{size:"24px"}),"This update includes breaking changes. To update correctly, follow the steps below."]}),(0,t.jsx)(T,{changelog:r,selectedVersion:i,packageManager:s}),(null==i?void 0:i.releaseNote)?(0,t.jsx)(C,{releaseNote:i.releaseNote}):(0,t.jsx)(S,{})]})]})},L=r(32665),V=r(3098),R=r(22840);function w(){var e=(0,g.v9)(function(e){return{changelog:(0,x.Sx)(e),packageManager:(0,x.Ak)(e),isChangelogLoading:(0,L.hg)(e,V.z.CHANGELOG)}}),n=e.changelog,r=e.packageManager,i=e.isChangelogLoading,s=n.sliceMachine.versions[0],a=(0,p.useState)(s||void 0),o=a[0],u=a[1];(0,p.useEffect)(function(){u(s)},[s]);var h=0===n.sliceMachine.versions.length||!o;return(0,t.jsx)(R.LN,{children:(0,t.jsx)(R.RN,{children:(0,t.jsx)(l.xR,{sx:{display:"flex",minWidth:0},children:i?(0,t.jsx)(c._3,{}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(m,{changelog:n,selectedVersion:o,selectVersion:function(e){return u(e)}}),h?(0,t.jsx)(d.kC,{sx:{paddingLeft:"32px"},children:(0,t.jsx)(S,{})}):(0,t.jsx)(M,{changelog:n,selectedVersion:o,packageManager:r})]})})})})}function H(){return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o(),{children:(0,t.jsx)("title",{children:"Changelog - Slice Machine"})}),(0,t.jsx)(w,{})]})}}},function(e){e.O(0,[898,183,870,774,888,179],function(){return e(e.s=37782)}),_N_E=e.O()}]);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
import useSliceMachineActions from "@src/modules/useSliceMachineActions";
|
|
4
|
-
|
|
5
|
-
export const useChangelog = () => {
|
|
6
|
-
const { getChangelog } = useSliceMachineActions();
|
|
7
|
-
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
getChangelog();
|
|
10
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
11
|
-
}, []);
|
|
12
|
-
};
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
import { describe, test, afterEach, expect, beforeAll, vi } from "vitest";
|
|
4
|
-
import { render, fireEvent, act, waitFor } from "../__testutils__";
|
|
5
|
-
import mockRouter from "next-router-mock";
|
|
6
|
-
import router from "next/router";
|
|
7
|
-
import { createDynamicRouteParser } from "next-router-mock/dynamic-routes";
|
|
8
|
-
import { Analytics } from "@segment/analytics-node";
|
|
9
|
-
|
|
10
|
-
import pkg from "../../package.json";
|
|
11
|
-
import Simulator from "../../pages/slices/[lib]/[sliceName]/[variation]/simulator";
|
|
12
|
-
import { SliceMachineStoreType } from "@src/redux/type";
|
|
13
|
-
import { createTestPlugin } from "test/__testutils__/createTestPlugin";
|
|
14
|
-
import { createTestProject } from "test/__testutils__/createTestProject";
|
|
15
|
-
import { createSliceMachineManager } from "@slicemachine/manager";
|
|
16
|
-
import { createSliceMachineManagerMSWHandler } from "@slicemachine/manager/test";
|
|
17
|
-
|
|
18
|
-
vi.mock("next/router", () => require("next-router-mock"));
|
|
19
|
-
vi.mock("next/dist/client/router", () => require("next-router-mock"));
|
|
20
|
-
mockRouter.useParser(
|
|
21
|
-
createDynamicRouteParser(["/slices/[lib]/[sliceName]/[variation]/simulator"]),
|
|
22
|
-
);
|
|
23
|
-
// mock simulator client, it would be nice not to have to do this :/
|
|
24
|
-
vi.mock("@prismicio/simulator", () => {
|
|
25
|
-
return {
|
|
26
|
-
SimulatorClient: vi.fn().mockReturnValue({
|
|
27
|
-
connect: vi.fn().mockResolvedValue(undefined),
|
|
28
|
-
disconnect: vi.fn(),
|
|
29
|
-
connected: true,
|
|
30
|
-
setSliceZone: vi.fn().mockResolvedValue(undefined),
|
|
31
|
-
}),
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe.skip("simulator", () => {
|
|
36
|
-
beforeAll(async () => {
|
|
37
|
-
// USE THIS IF light mode is not enabled on ThemeProvider
|
|
38
|
-
// Object.defineProperty(window, "matchMedia", {
|
|
39
|
-
// writable: true,
|
|
40
|
-
// value: vi.fn().mockImplementation((query) => ({
|
|
41
|
-
// matches: false,
|
|
42
|
-
// media: query,
|
|
43
|
-
// onchange: null,
|
|
44
|
-
// addListener: vi.fn(), // Deprecated
|
|
45
|
-
// removeListener: vi.fn(), // Deprecated
|
|
46
|
-
// addEventListener: vi.fn(),
|
|
47
|
-
// removeEventListener: vi.fn(),
|
|
48
|
-
// dispatchEvent: vi.fn(),
|
|
49
|
-
// })),
|
|
50
|
-
// });
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
document.createRange = () => {
|
|
54
|
-
// https://github.com/jsdom/jsdom/issues/3002
|
|
55
|
-
const range = new Range();
|
|
56
|
-
|
|
57
|
-
range.getBoundingClientRect = vi.fn().mockReturnValue({
|
|
58
|
-
width: 0,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
range.getClientRects = () => {
|
|
62
|
-
return {
|
|
63
|
-
item: () => null,
|
|
64
|
-
length: 0,
|
|
65
|
-
[Symbol.iterator]: vi.fn(),
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return range;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
vi.clearAllMocks();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("save mock", async (ctx) => {
|
|
77
|
-
const adapter = createTestPlugin({
|
|
78
|
-
setup: ({ hook }) => {
|
|
79
|
-
hook("slice:asset:update", () => void 0);
|
|
80
|
-
hook("slice-simulator:setup:read", () => {
|
|
81
|
-
return [];
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
const cwd = await createTestProject({ adapter });
|
|
86
|
-
const manager = createSliceMachineManager({
|
|
87
|
-
nativePlugins: { [adapter.meta.name]: adapter },
|
|
88
|
-
cwd,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
await manager.telemetry.initTelemetry({
|
|
92
|
-
appName: pkg.name,
|
|
93
|
-
appVersion: pkg.version,
|
|
94
|
-
});
|
|
95
|
-
await manager.plugins.initPlugins();
|
|
96
|
-
|
|
97
|
-
ctx.msw.use(
|
|
98
|
-
createSliceMachineManagerMSWHandler({
|
|
99
|
-
url: "http://localhost:3000/_manager",
|
|
100
|
-
sliceMachineManager: manager,
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
vi.useFakeTimers();
|
|
105
|
-
|
|
106
|
-
router.push("/slices/MySlice/default/simulator");
|
|
107
|
-
const HEADING_TEXT = "HEADING TEXT";
|
|
108
|
-
const state = {
|
|
109
|
-
simulator: {
|
|
110
|
-
isWaitingForIframeCheck: true,
|
|
111
|
-
iframeStatus: null,
|
|
112
|
-
setupStatus: { manifest: null },
|
|
113
|
-
savingMock: false,
|
|
114
|
-
},
|
|
115
|
-
environment: {
|
|
116
|
-
changelog: {
|
|
117
|
-
sliceMachine: {
|
|
118
|
-
currentVersion: "0.0.0",
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
manifest: {
|
|
122
|
-
localSliceSimulatorURL: "http://localhost:3000/slice-simulator",
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
slices: {
|
|
126
|
-
libraries: [
|
|
127
|
-
{
|
|
128
|
-
path: "../../e2e-projects/next/slices2",
|
|
129
|
-
isLocal: true,
|
|
130
|
-
name: "slices",
|
|
131
|
-
components: [
|
|
132
|
-
{
|
|
133
|
-
from: "slices",
|
|
134
|
-
href: "slices",
|
|
135
|
-
pathToSlice: "./slices",
|
|
136
|
-
fileName: "index",
|
|
137
|
-
extension: "js",
|
|
138
|
-
screenshots: {},
|
|
139
|
-
mocks: [
|
|
140
|
-
{
|
|
141
|
-
__TYPE__: "SharedSliceContent",
|
|
142
|
-
variation: "default",
|
|
143
|
-
primary: {
|
|
144
|
-
title: {
|
|
145
|
-
__TYPE__: "StructuredTextContent",
|
|
146
|
-
value: [
|
|
147
|
-
{
|
|
148
|
-
type: "heading1",
|
|
149
|
-
content: {
|
|
150
|
-
text: HEADING_TEXT,
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
description: {
|
|
156
|
-
__TYPE__: "StructuredTextContent",
|
|
157
|
-
value: [
|
|
158
|
-
{
|
|
159
|
-
type: "paragraph",
|
|
160
|
-
content: {
|
|
161
|
-
text: "Et irure id id ea exercitation excepteur consectetur. Ea amet irure minim labore non aliquip ex. Tempor incididunt Lorem incididunt amet est cillum nisi Lorem officia pariatur exercitation in occaecat sit.",
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
items: [
|
|
168
|
-
{
|
|
169
|
-
__TYPE__: "GroupItemContent",
|
|
170
|
-
value: [],
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
model: {
|
|
176
|
-
id: "my_slice",
|
|
177
|
-
type: "SharedSlice",
|
|
178
|
-
name: "MySlice",
|
|
179
|
-
description: "MySlice",
|
|
180
|
-
variations: [
|
|
181
|
-
{
|
|
182
|
-
id: "default",
|
|
183
|
-
name: "Default",
|
|
184
|
-
docURL: "...",
|
|
185
|
-
version: "sktwi1xtmkfgx8626",
|
|
186
|
-
description: "MySlice",
|
|
187
|
-
primary: [
|
|
188
|
-
{
|
|
189
|
-
key: "title",
|
|
190
|
-
value: {
|
|
191
|
-
type: "StructuredText",
|
|
192
|
-
config: {
|
|
193
|
-
single: "heading1",
|
|
194
|
-
label: "Title",
|
|
195
|
-
placeholder: "This is where it all begins...",
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
key: "description",
|
|
201
|
-
value: {
|
|
202
|
-
type: "StructuredText",
|
|
203
|
-
config: {
|
|
204
|
-
single: "paragraph",
|
|
205
|
-
label: "Description",
|
|
206
|
-
placeholder: "A nice description of your feature",
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
items: [],
|
|
212
|
-
},
|
|
213
|
-
],
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
],
|
|
217
|
-
meta: {
|
|
218
|
-
isNodeModule: false,
|
|
219
|
-
isDownloaded: false,
|
|
220
|
-
isManual: true,
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
],
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
// server.use(
|
|
228
|
-
// rest.get("/api/state", (_req, res, ctx) => {
|
|
229
|
-
// return res(
|
|
230
|
-
// ctx.json({
|
|
231
|
-
// env: state.environment,
|
|
232
|
-
// libraries: state.slices.libraries,
|
|
233
|
-
// })
|
|
234
|
-
// );
|
|
235
|
-
// })
|
|
236
|
-
// );
|
|
237
|
-
//
|
|
238
|
-
// server.use(
|
|
239
|
-
// rest.get(
|
|
240
|
-
// state.environment.manifest.localSliceSimulatorURL,
|
|
241
|
-
// (_req, res, ctx) => {
|
|
242
|
-
// return res(ctx.status(200));
|
|
243
|
-
// }
|
|
244
|
-
// )
|
|
245
|
-
// );
|
|
246
|
-
//
|
|
247
|
-
// const saveMockSpy = vi.fn(
|
|
248
|
-
// (req: RestRequest, res: ResponseComposition, ctx: RestContext) => {
|
|
249
|
-
// return req.json().then((json) => {
|
|
250
|
-
// const result = SaveMockBody.decode(json);
|
|
251
|
-
// if (result._tag === "Right") {
|
|
252
|
-
// return res(ctx.json(json.mock));
|
|
253
|
-
// }
|
|
254
|
-
// return res(ctx.status(400));
|
|
255
|
-
// });
|
|
256
|
-
// }
|
|
257
|
-
// );
|
|
258
|
-
//
|
|
259
|
-
// server.use(rest.post("http://localhost/api/slices/mock", saveMockSpy));
|
|
260
|
-
// server.use(
|
|
261
|
-
// rest.get(
|
|
262
|
-
// state.environment.manifest.localSliceSimulatorURL,
|
|
263
|
-
// (_req, res, ctx) => {
|
|
264
|
-
// res(ctx.json({}));
|
|
265
|
-
// }
|
|
266
|
-
// )
|
|
267
|
-
// );
|
|
268
|
-
//
|
|
269
|
-
// server.use(
|
|
270
|
-
// rest.get("http://localhost/api/simulator/check", (_req, res, ctx) => {
|
|
271
|
-
// return res(
|
|
272
|
-
// ctx.json({
|
|
273
|
-
// manifest: "ok",
|
|
274
|
-
// value: state.environment.manifest.localSliceSimulatorURL,
|
|
275
|
-
// })
|
|
276
|
-
// );
|
|
277
|
-
// })
|
|
278
|
-
// );
|
|
279
|
-
|
|
280
|
-
const App = render(<Simulator />, {
|
|
281
|
-
preloadedState: state as unknown as Partial<SliceMachineStoreType>,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
await waitFor(() => expect(Analytics.prototype.track).toHaveBeenCalled());
|
|
285
|
-
|
|
286
|
-
expect(Analytics.prototype.track).toHaveBeenCalledOnce();
|
|
287
|
-
expect(Analytics.prototype.track).toHaveBeenCalledWith(
|
|
288
|
-
expect.objectContaining({
|
|
289
|
-
event: "SliceMachine Slice Simulator Open",
|
|
290
|
-
properties: {
|
|
291
|
-
version: state.environment.changelog.sliceMachine.currentVersion,
|
|
292
|
-
},
|
|
293
|
-
}),
|
|
294
|
-
expect.any(Function),
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
const button = App.container.querySelector('[data-cy="save-mock"]');
|
|
298
|
-
expect(button).not.toBeNull();
|
|
299
|
-
|
|
300
|
-
const input = App.getByText(HEADING_TEXT);
|
|
301
|
-
expect(input).not.toBeNull();
|
|
302
|
-
|
|
303
|
-
await act(async () => {
|
|
304
|
-
// fireEvent.change(input as Element, {target: {value: "🎉"}})
|
|
305
|
-
// see: https://github.com/testing-library/dom-testing-library/pull/235
|
|
306
|
-
fireEvent.blur(input as Element, { target: { textContent: "🎉" } });
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
expect(button).not.toHaveAttribute("disabled");
|
|
310
|
-
|
|
311
|
-
await act(async () => {
|
|
312
|
-
fireEvent.click(button as Element);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const expectedMock = [...state.slices.libraries[0].components[0].mocks];
|
|
316
|
-
expectedMock[0].primary.title.value[0].content.text = "🎉";
|
|
317
|
-
// @ts-expect-error - Ignoring wrong type
|
|
318
|
-
expectedMock[0].primary.title.value[0].content.spans = [];
|
|
319
|
-
// @ts-expect-error - Ignoring wrong type
|
|
320
|
-
expectedMock[0].primary.title.value[0].direction = "ltr";
|
|
321
|
-
|
|
322
|
-
expect(Analytics.prototype.track).toHaveBeenCalledTimes(2);
|
|
323
|
-
expect(Analytics.prototype.track).toHaveBeenCalledWith(
|
|
324
|
-
expect.objectContaining({
|
|
325
|
-
sliceName: "MySlice",
|
|
326
|
-
libraryName: "slices",
|
|
327
|
-
mocks: expectedMock,
|
|
328
|
-
}),
|
|
329
|
-
expect.any(Function),
|
|
330
|
-
);
|
|
331
|
-
});
|
|
332
|
-
});
|
|
File without changes
|