@makeswift/runtime 0.6.3 → 0.6.5
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/Box.es.js +1 -1
- package/dist/Button.es.js +1 -1
- package/dist/Carousel.es.js +1 -1
- package/dist/Countdown.es.js +1 -1
- package/dist/Divider.es.js +1 -1
- package/dist/EditableText.cjs.js +12 -3
- package/dist/EditableText.cjs.js.map +1 -1
- package/dist/EditableText.es.js +13 -4
- package/dist/EditableText.es.js.map +1 -1
- package/dist/Embed.es.js +1 -1
- package/dist/Form.es.js +1 -1
- package/dist/Image.es.js +1 -1
- package/dist/LiveProvider.es.js +1 -1
- package/dist/Navigation.es.js +1 -1
- package/dist/PreviewProvider.cjs.js +53 -16
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +56 -20
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/ReadOnlyText.cjs.js +5 -2
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +6 -3
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/Root.es.js +1 -1
- package/dist/SocialLinks.es.js +1 -1
- package/dist/Text.es.js +1 -1
- package/dist/Video.es.js +1 -1
- package/dist/actions.cjs.js +11 -1
- package/dist/actions.cjs.js.map +1 -1
- package/dist/actions.es.js +11 -2
- package/dist/actions.es.js.map +1 -1
- package/dist/builder.cjs.js +1 -0
- package/dist/builder.cjs.js.map +1 -1
- package/dist/builder.es.js +1 -0
- package/dist/builder.es.js.map +1 -1
- package/dist/components.cjs.js +1 -0
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +1 -1
- package/dist/constants.cjs.js +6 -1
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +7 -3
- package/dist/constants.es.js.map +1 -1
- package/dist/controls.cjs.js +1 -0
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +2 -1
- package/dist/controls.es.js.map +1 -1
- package/dist/index.cjs.js +494 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +495 -19
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +2 -2
- package/dist/index.es3.js +1 -1
- package/dist/index.es4.js +1 -1
- package/dist/index.es6.js +2 -2
- package/dist/main.cjs.js +1 -0
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.es.js +1 -1
- package/dist/next.cjs.js +1 -0
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +1 -1
- package/dist/prop-controllers.cjs.js +1 -0
- package/dist/prop-controllers.cjs.js.map +1 -1
- package/dist/prop-controllers.es.js +1 -0
- package/dist/prop-controllers.es.js.map +1 -1
- package/dist/rich-text.cjs.js +20 -4
- package/dist/rich-text.cjs.js.map +1 -1
- package/dist/rich-text.es.js +19 -5
- package/dist/rich-text.es.js.map +1 -1
- package/dist/types/src/components/builtin/Text/EditableText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/register.d.ts.map +1 -1
- package/dist/types/src/components/page/Page.d.ts +5 -1
- package/dist/types/src/components/page/Page.d.ts.map +1 -1
- package/dist/types/src/controls/rich-text.d.ts +1 -1
- package/dist/types/src/controls/rich-text.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/next/api-handler.d.ts +14 -2
- package/dist/types/src/next/api-handler.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +69 -32
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts +5 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/next/preview-mode.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts +2 -0
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/state/actions.d.ts +12 -1
- package/dist/types/src/state/actions.d.ts.map +1 -1
- package/dist/types/src/state/modules/api-resources.d.ts +6 -2
- package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
- package/dist/types/src/state/modules/builder-edit-mode.d.ts +11 -0
- package/dist/types/src/state/modules/builder-edit-mode.d.ts.map +1 -0
- package/dist/types/src/state/react-builder-preview.d.ts +2 -0
- package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
- package/dist/types/src/state/react-page.d.ts +3 -0
- package/dist/types/src/state/react-page.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/types/src/utils/constants.d.ts +0 -6
- package/dist/types/src/utils/constants.d.ts.map +0 -1
package/dist/index.cjs.js
CHANGED
|
@@ -265,14 +265,44 @@ const deepEqual = (a, b) => {
|
|
|
265
265
|
}
|
|
266
266
|
return true;
|
|
267
267
|
};
|
|
268
|
-
function getInitialState(serializedState =
|
|
269
|
-
|
|
268
|
+
function getInitialState(serializedState = {
|
|
269
|
+
Swatch: [],
|
|
270
|
+
File: [],
|
|
271
|
+
Typography: [],
|
|
272
|
+
PagePathnameSlice: [],
|
|
273
|
+
GlobalElement: [],
|
|
274
|
+
Table: [],
|
|
275
|
+
Snippet: [],
|
|
276
|
+
Page: [],
|
|
277
|
+
Site: []
|
|
278
|
+
}) {
|
|
279
|
+
return new Map(Object.entries(serializedState).map(([apiResourceType, resources]) => [
|
|
280
|
+
apiResourceType,
|
|
281
|
+
new Map(resources.map(({ id, value }) => [id, value]))
|
|
282
|
+
]));
|
|
270
283
|
}
|
|
271
284
|
function getSerializedState$1(state) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
285
|
+
const resourceMap = {
|
|
286
|
+
Swatch: [],
|
|
287
|
+
File: [],
|
|
288
|
+
Typography: [],
|
|
289
|
+
PagePathnameSlice: [],
|
|
290
|
+
GlobalElement: [],
|
|
291
|
+
Table: [],
|
|
292
|
+
Snippet: [],
|
|
293
|
+
Page: [],
|
|
294
|
+
Site: []
|
|
295
|
+
};
|
|
296
|
+
Array.from(state.entries()).forEach(([resourceType, resources]) => {
|
|
297
|
+
const particularResourceMap = [];
|
|
298
|
+
Array.from(resources.entries()).forEach(([id, value]) => {
|
|
299
|
+
if (value != null) {
|
|
300
|
+
particularResourceMap.push({ id, value });
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
resourceMap[resourceType] = particularResourceMap;
|
|
304
|
+
});
|
|
305
|
+
return resourceMap;
|
|
276
306
|
}
|
|
277
307
|
function getHasAPIResource$1(state, resourceType, resourceId) {
|
|
278
308
|
var _a, _b;
|
|
@@ -921,6 +951,159 @@ function Page$1({
|
|
|
921
951
|
}, snippet.id))]
|
|
922
952
|
});
|
|
923
953
|
}
|
|
954
|
+
function unstable_Page$1({
|
|
955
|
+
pageData
|
|
956
|
+
}) {
|
|
957
|
+
var _a;
|
|
958
|
+
const isInBuilder = useIsInBuilder();
|
|
959
|
+
const [snippets, setSnippets] = React.useState(pageData.snapshot.resources.snippets);
|
|
960
|
+
const cachedPage = useCachedPage(isInBuilder ? pageData.pageId : null);
|
|
961
|
+
React.useEffect(() => {
|
|
962
|
+
if (cachedPage == null)
|
|
963
|
+
return;
|
|
964
|
+
const oldSnippets = snippets.map(filterUsedSnippetProperties);
|
|
965
|
+
const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties);
|
|
966
|
+
if (deepEqual(newSnippets, oldSnippets))
|
|
967
|
+
return;
|
|
968
|
+
setSnippets(cachedPage.snippets);
|
|
969
|
+
}, [cachedPage]);
|
|
970
|
+
const site = useCachedSite(isInBuilder ? pageData.siteId : null);
|
|
971
|
+
const favicon = (_a = pageData.snapshot.resources.meta.favicon) != null ? _a : defaultFavicon;
|
|
972
|
+
const {
|
|
973
|
+
title,
|
|
974
|
+
description,
|
|
975
|
+
keywords,
|
|
976
|
+
socialImage
|
|
977
|
+
} = pageData.snapshot.resources.meta;
|
|
978
|
+
const {
|
|
979
|
+
canonicalUrl,
|
|
980
|
+
isIndexingBlocked
|
|
981
|
+
} = pageData.snapshot.resources.seo;
|
|
982
|
+
const fontFamilyParamValue = React.useMemo(() => {
|
|
983
|
+
if (site == null) {
|
|
984
|
+
return pageData.snapshot.resources.fonts.map(({
|
|
985
|
+
family,
|
|
986
|
+
variants
|
|
987
|
+
}) => {
|
|
988
|
+
return `${family.replace(/ /g, "+")}:${variants.join()}`;
|
|
989
|
+
}).join("|");
|
|
990
|
+
}
|
|
991
|
+
return site.googleFonts.edges.filter((edge) => edge != null).map(({
|
|
992
|
+
activeVariants,
|
|
993
|
+
node: {
|
|
994
|
+
family,
|
|
995
|
+
variants
|
|
996
|
+
}
|
|
997
|
+
}) => {
|
|
998
|
+
const activeVariantSpecifiers = variants.filter((variant) => activeVariants.some((activeVariant) => activeVariant.specifier === variant.specifier)).map((variant) => variant.specifier).join();
|
|
999
|
+
return `${family.replace(/ /g, "+")}:${activeVariantSpecifiers}`;
|
|
1000
|
+
}).join("|");
|
|
1001
|
+
}, [site, pageData.snapshot.resources.fonts]);
|
|
1002
|
+
const filteredSnippets = React.useMemo(() => snippets.filter((snippet) => isInBuilder ? snippet.builderEnabled : snippet.liveEnabled), [snippets, isInBuilder]);
|
|
1003
|
+
const headSnippets = React.useMemo(() => filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Head), [filteredSnippets]);
|
|
1004
|
+
const previousHeadSnippets = React.useRef(null);
|
|
1005
|
+
React.useEffect(() => {
|
|
1006
|
+
var _a2;
|
|
1007
|
+
const headSnippetsToCleanUp = ((_a2 = previousHeadSnippets.current) != null ? _a2 : []).filter((previousSnippet) => previousSnippet.cleanup != null).filter((previousSnippet) => !headSnippets.some((snippet) => previousSnippet.id === snippet.id));
|
|
1008
|
+
headSnippetsToCleanUp.forEach((snippetToCleanUp) => {
|
|
1009
|
+
if (snippetToCleanUp.cleanup == null)
|
|
1010
|
+
return;
|
|
1011
|
+
const cleanUp = new Function(snippetToCleanUp.cleanup);
|
|
1012
|
+
try {
|
|
1013
|
+
cleanUp();
|
|
1014
|
+
} catch {
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
previousHeadSnippets.current = headSnippets;
|
|
1018
|
+
}, [headSnippets]);
|
|
1019
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1020
|
+
children: [/* @__PURE__ */ jsxRuntime.jsxs(Head__default["default"], {
|
|
1021
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx("style", {
|
|
1022
|
+
children: `
|
|
1023
|
+
html {
|
|
1024
|
+
font-family: sans-serif;
|
|
1025
|
+
}
|
|
1026
|
+
div#__next {
|
|
1027
|
+
overflow: hidden;
|
|
1028
|
+
}
|
|
1029
|
+
`
|
|
1030
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
1031
|
+
rel: "icon",
|
|
1032
|
+
type: favicon.mimetype,
|
|
1033
|
+
href: favicon.publicUrl
|
|
1034
|
+
}), canonicalUrl && /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
1035
|
+
rel: "canonical",
|
|
1036
|
+
href: canonicalUrl
|
|
1037
|
+
}), isIndexingBlocked && /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1038
|
+
name: "robots",
|
|
1039
|
+
content: "noindex"
|
|
1040
|
+
}), title && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1041
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx("title", {
|
|
1042
|
+
children: title
|
|
1043
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1044
|
+
property: "og:title",
|
|
1045
|
+
content: title
|
|
1046
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1047
|
+
name: "twitter:title",
|
|
1048
|
+
content: title
|
|
1049
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1050
|
+
itemProp: "name",
|
|
1051
|
+
content: title
|
|
1052
|
+
})]
|
|
1053
|
+
}), description && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1054
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1055
|
+
name: "description",
|
|
1056
|
+
content: description
|
|
1057
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1058
|
+
property: "og:description",
|
|
1059
|
+
content: description
|
|
1060
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1061
|
+
name: "twitter:description",
|
|
1062
|
+
content: description
|
|
1063
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1064
|
+
itemProp: "description",
|
|
1065
|
+
content: description
|
|
1066
|
+
})]
|
|
1067
|
+
}), keywords && /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1068
|
+
name: "keywords",
|
|
1069
|
+
content: keywords
|
|
1070
|
+
}), socialImage && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1071
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1072
|
+
property: "og:image",
|
|
1073
|
+
content: socialImage.publicUrl
|
|
1074
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1075
|
+
property: "og:image:type",
|
|
1076
|
+
content: socialImage.mimetype
|
|
1077
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1078
|
+
name: "twitter:image",
|
|
1079
|
+
content: socialImage.publicUrl
|
|
1080
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1081
|
+
name: "twitter:card",
|
|
1082
|
+
content: "summary_large_image"
|
|
1083
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1084
|
+
itemProp: "image",
|
|
1085
|
+
content: socialImage.publicUrl
|
|
1086
|
+
})]
|
|
1087
|
+
}), fontFamilyParamValue !== "" && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
1088
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
1089
|
+
rel: "stylesheet",
|
|
1090
|
+
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
1091
|
+
})
|
|
1092
|
+
}), headSnippets.map(snippetToElement).map((children) => React.Children.map(children, (child) => {
|
|
1093
|
+
if (typeof child === "string")
|
|
1094
|
+
return child;
|
|
1095
|
+
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
1096
|
+
return child;
|
|
1097
|
+
return null;
|
|
1098
|
+
}))]
|
|
1099
|
+
}), /* @__PURE__ */ jsxRuntime.jsx(DocumentReference, {
|
|
1100
|
+
documentReference: constants.createDocumentReference(pageData.pageId)
|
|
1101
|
+
}), filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Body).map((snippet) => /* @__PURE__ */ jsxRuntime.jsx(BodySnippet, {
|
|
1102
|
+
code: snippet.code,
|
|
1103
|
+
cleanup: snippet.cleanup
|
|
1104
|
+
}, snippet.id))]
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
924
1107
|
function useCachedPage(pageId) {
|
|
925
1108
|
const client = useMakeswiftClient();
|
|
926
1109
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -933,6 +1116,7 @@ function useCachedSite(siteId) {
|
|
|
933
1116
|
const site = shim.useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
934
1117
|
return site;
|
|
935
1118
|
}
|
|
1119
|
+
const version = "0.6.5";
|
|
936
1120
|
class Makeswift {
|
|
937
1121
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
938
1122
|
__publicField(this, "apiKey");
|
|
@@ -986,12 +1170,205 @@ Received "${apiKey}" instead.`);
|
|
|
986
1170
|
const snapshot = this.getPageSnapshotByPageId(page.id, { preview });
|
|
987
1171
|
return snapshot;
|
|
988
1172
|
}
|
|
1173
|
+
async unstable_getPageData(path, { preview } = {}) {
|
|
1174
|
+
const [page] = await this.getPages({ path });
|
|
1175
|
+
if (page == null)
|
|
1176
|
+
return null;
|
|
1177
|
+
const document2 = await this.getDocumentForPage(page.id);
|
|
1178
|
+
const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
|
|
1179
|
+
return {
|
|
1180
|
+
pageId: page.id,
|
|
1181
|
+
siteId: document2.site.id,
|
|
1182
|
+
snapshot,
|
|
1183
|
+
options: { preview: preview || false, apiOrigin: this.apiOrigin.href }
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
async getDocumentForPage(pageId) {
|
|
1187
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1188
|
+
if (!response.ok) {
|
|
1189
|
+
if (response.status === 404)
|
|
1190
|
+
throw Error("bad");
|
|
1191
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1192
|
+
}
|
|
1193
|
+
const document2 = await response.json();
|
|
1194
|
+
return document2;
|
|
1195
|
+
}
|
|
1196
|
+
async unstable_createSnapshotForPage({
|
|
1197
|
+
document: document2,
|
|
1198
|
+
pageId
|
|
1199
|
+
}) {
|
|
1200
|
+
let fetchedDocument = document2;
|
|
1201
|
+
if (fetchedDocument == null) {
|
|
1202
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1203
|
+
if (!response.ok) {
|
|
1204
|
+
if (response.status === 404) {
|
|
1205
|
+
throw new Error("Not found");
|
|
1206
|
+
}
|
|
1207
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1208
|
+
}
|
|
1209
|
+
fetchedDocument = await response.json();
|
|
1210
|
+
}
|
|
1211
|
+
if (fetchedDocument == null) {
|
|
1212
|
+
throw Error("fetchedDocument should never be null");
|
|
1213
|
+
}
|
|
1214
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1215
|
+
const prefetchedResources = await client.prefetch(fetchedDocument.data);
|
|
1216
|
+
const resources = __spreadProps(__spreadValues({}, prefetchedResources), {
|
|
1217
|
+
snippets: fetchedDocument.snippets,
|
|
1218
|
+
meta: fetchedDocument.meta,
|
|
1219
|
+
seo: fetchedDocument.seo,
|
|
1220
|
+
fonts: fetchedDocument.fonts
|
|
1221
|
+
});
|
|
1222
|
+
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1223
|
+
}
|
|
1224
|
+
async unstable_createSnapshot({
|
|
1225
|
+
publishedResources,
|
|
1226
|
+
deletedResources,
|
|
1227
|
+
publishedElementTree,
|
|
1228
|
+
currentSnapshot
|
|
1229
|
+
}) {
|
|
1230
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1231
|
+
function normalizeToMakeswiftResources(partialResources) {
|
|
1232
|
+
const resources2 = {
|
|
1233
|
+
Swatch: (partialResources == null ? void 0 : partialResources.Swatch) || [],
|
|
1234
|
+
File: (partialResources == null ? void 0 : partialResources.File) || [],
|
|
1235
|
+
Typography: (partialResources == null ? void 0 : partialResources.Typography) || [],
|
|
1236
|
+
PagePathnameSlice: (partialResources == null ? void 0 : partialResources.PagePathnameSlice) || [],
|
|
1237
|
+
GlobalElement: (partialResources == null ? void 0 : partialResources.GlobalElement) || [],
|
|
1238
|
+
Table: (partialResources == null ? void 0 : partialResources.Table) || [],
|
|
1239
|
+
Snippet: (partialResources == null ? void 0 : partialResources.Snippet) || [],
|
|
1240
|
+
Page: (partialResources == null ? void 0 : partialResources.Page) || [],
|
|
1241
|
+
Site: (partialResources == null ? void 0 : partialResources.Site) || [],
|
|
1242
|
+
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
1243
|
+
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
1244
|
+
meta: (partialResources == null ? void 0 : partialResources.meta) || {},
|
|
1245
|
+
seo: (partialResources == null ? void 0 : partialResources.seo) || {}
|
|
1246
|
+
};
|
|
1247
|
+
return resources2;
|
|
1248
|
+
}
|
|
1249
|
+
function mergeResources({
|
|
1250
|
+
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1251
|
+
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1252
|
+
publishedResources: publishedResources2,
|
|
1253
|
+
deletedResources: deletedResources2
|
|
1254
|
+
}) {
|
|
1255
|
+
function mergeElementTreeResource(resourceSet, deletedResources3) {
|
|
1256
|
+
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1257
|
+
deletedResources3.forEach(({ id }) => map.delete(id));
|
|
1258
|
+
const finalResourceSet = [];
|
|
1259
|
+
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1260
|
+
if (value != null) {
|
|
1261
|
+
finalResourceSet.push({ id, value });
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
return finalResourceSet;
|
|
1265
|
+
}
|
|
1266
|
+
function mergeSnippets(snippets, deletedSnippet) {
|
|
1267
|
+
const map = new Map(snippets.map((value) => [value.id, value]));
|
|
1268
|
+
deletedSnippet.forEach(({ id }) => map.delete(id));
|
|
1269
|
+
const uniqueSnippets = [];
|
|
1270
|
+
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1271
|
+
uniqueSnippets.push(value);
|
|
1272
|
+
});
|
|
1273
|
+
return uniqueSnippets;
|
|
1274
|
+
}
|
|
1275
|
+
function mergeFonts(fonts, deletedFonts) {
|
|
1276
|
+
const map = new Map(fonts.map((value) => [value.family, value]));
|
|
1277
|
+
deletedFonts.forEach(({ family }) => map.delete(family));
|
|
1278
|
+
const uniqueFonts = [];
|
|
1279
|
+
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1280
|
+
uniqueFonts.push(value);
|
|
1281
|
+
});
|
|
1282
|
+
return uniqueFonts;
|
|
1283
|
+
}
|
|
1284
|
+
const resources2 = {
|
|
1285
|
+
Swatch: mergeElementTreeResource([
|
|
1286
|
+
...resourcesFromPublishedElementTree2.Swatch,
|
|
1287
|
+
...resourcesFromCurrentSnapshot2.Swatch,
|
|
1288
|
+
...publishedResources2.Swatch
|
|
1289
|
+
], deletedResources2.Swatch),
|
|
1290
|
+
File: mergeElementTreeResource([
|
|
1291
|
+
...resourcesFromPublishedElementTree2.File,
|
|
1292
|
+
...resourcesFromCurrentSnapshot2.File,
|
|
1293
|
+
...publishedResources2.File
|
|
1294
|
+
], deletedResources2.File),
|
|
1295
|
+
Typography: mergeElementTreeResource([
|
|
1296
|
+
...resourcesFromPublishedElementTree2.Typography,
|
|
1297
|
+
...resourcesFromCurrentSnapshot2.Typography,
|
|
1298
|
+
...publishedResources2.Typography
|
|
1299
|
+
], deletedResources2.Typography),
|
|
1300
|
+
PagePathnameSlice: mergeElementTreeResource([
|
|
1301
|
+
...resourcesFromPublishedElementTree2.PagePathnameSlice,
|
|
1302
|
+
...resourcesFromCurrentSnapshot2.PagePathnameSlice,
|
|
1303
|
+
...publishedResources2.PagePathnameSlice
|
|
1304
|
+
], deletedResources2.PagePathnameSlice),
|
|
1305
|
+
GlobalElement: mergeElementTreeResource([
|
|
1306
|
+
...resourcesFromPublishedElementTree2.GlobalElement,
|
|
1307
|
+
...resourcesFromCurrentSnapshot2.GlobalElement,
|
|
1308
|
+
...publishedResources2.GlobalElement
|
|
1309
|
+
], deletedResources2.GlobalElement),
|
|
1310
|
+
Table: mergeElementTreeResource([
|
|
1311
|
+
...resourcesFromPublishedElementTree2.Table,
|
|
1312
|
+
...resourcesFromCurrentSnapshot2.Table,
|
|
1313
|
+
...publishedResources2.Table
|
|
1314
|
+
], deletedResources2.Table),
|
|
1315
|
+
snippets: mergeSnippets([
|
|
1316
|
+
...resourcesFromCurrentSnapshot2.snippets,
|
|
1317
|
+
...resourcesFromPublishedElementTree2.snippets,
|
|
1318
|
+
...publishedResources2.snippets
|
|
1319
|
+
], deletedResources2.snippets),
|
|
1320
|
+
fonts: mergeFonts([
|
|
1321
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1322
|
+
...resourcesFromPublishedElementTree2.fonts,
|
|
1323
|
+
...publishedResources2.fonts
|
|
1324
|
+
], deletedResources2.fonts),
|
|
1325
|
+
meta: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.meta), publishedResources2.meta),
|
|
1326
|
+
seo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.seo), publishedResources2.seo),
|
|
1327
|
+
Snippet: [],
|
|
1328
|
+
Page: [],
|
|
1329
|
+
Site: []
|
|
1330
|
+
};
|
|
1331
|
+
return resources2;
|
|
1332
|
+
}
|
|
1333
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1334
|
+
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1335
|
+
const resources = mergeResources({
|
|
1336
|
+
resourcesFromPublishedElementTree,
|
|
1337
|
+
resourcesFromCurrentSnapshot,
|
|
1338
|
+
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1339
|
+
deletedResources: normalizeToMakeswiftResources(deletedResources)
|
|
1340
|
+
});
|
|
1341
|
+
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1342
|
+
if (elementTree == null) {
|
|
1343
|
+
throw Error("elementTree should not be null; something went wrong.");
|
|
1344
|
+
}
|
|
1345
|
+
return {
|
|
1346
|
+
resources,
|
|
1347
|
+
elementTree,
|
|
1348
|
+
runtimeVersion: version
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
unstable_getSnapshotResourceMapping(snapshot) {
|
|
1352
|
+
const resources = snapshot.resources;
|
|
1353
|
+
function parseResourceIds({ id }) {
|
|
1354
|
+
return id;
|
|
1355
|
+
}
|
|
1356
|
+
return [
|
|
1357
|
+
...resources.Swatch.map(parseResourceIds),
|
|
1358
|
+
...resources.File.map(parseResourceIds),
|
|
1359
|
+
...resources.Typography.map(parseResourceIds),
|
|
1360
|
+
...resources.PagePathnameSlice.map(parseResourceIds),
|
|
1361
|
+
...resources.GlobalElement.map(parseResourceIds),
|
|
1362
|
+
...resources.Table.map(parseResourceIds),
|
|
1363
|
+
...resources.snippets.map(parseResourceIds)
|
|
1364
|
+
];
|
|
1365
|
+
}
|
|
989
1366
|
}
|
|
990
1367
|
function PreviewModeScript({
|
|
991
1368
|
isPreview = false,
|
|
992
1369
|
appOrigin = "https://app.makeswift.com"
|
|
993
1370
|
}) {
|
|
994
|
-
const
|
|
1371
|
+
const previewModeScript = `
|
|
995
1372
|
const isPreview = ${isPreview}
|
|
996
1373
|
const appOrigin = '${appOrigin.replace("'", "\\'")}'
|
|
997
1374
|
const searchParamName = 'x-makeswift-preview-mode'
|
|
@@ -1039,12 +1416,43 @@ if (originalUrl.searchParams.has(searchParamName)) {
|
|
|
1039
1416
|
window.history.replaceState(null, '', url)
|
|
1040
1417
|
}
|
|
1041
1418
|
`;
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1419
|
+
const makeswiftConnectionCheckScript = `
|
|
1420
|
+
const appOrigin = '${appOrigin.replace("'", "\\'")}'
|
|
1421
|
+
|
|
1422
|
+
if (window.parent !== window) {
|
|
1423
|
+
window.addEventListener('message', event => {
|
|
1424
|
+
if (
|
|
1425
|
+
event.origin === appOrigin &&
|
|
1426
|
+
event.data.type === '${actions.ActionTypes.MAKESWIFT_CONNECTION_INIT}'
|
|
1427
|
+
) {
|
|
1428
|
+
setInterval(() => {
|
|
1429
|
+
window.parent.postMessage({
|
|
1430
|
+
type: '${actions.ActionTypes.MAKESWIFT_CONNECTION_CHECK}',
|
|
1431
|
+
payload: {
|
|
1432
|
+
currentUrl: window.location.href
|
|
1433
|
+
}
|
|
1434
|
+
}, appOrigin)
|
|
1435
|
+
}, 20)
|
|
1047
1436
|
}
|
|
1437
|
+
})
|
|
1438
|
+
|
|
1439
|
+
window.parent.postMessage({ type: '${actions.ActionTypes.MAKESWIFT_CONNECTION_INIT}' }, appOrigin)
|
|
1440
|
+
}
|
|
1441
|
+
`;
|
|
1442
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1443
|
+
children: [/* @__PURE__ */ jsxRuntime.jsx("script", {
|
|
1444
|
+
id: "makeswift-preview-mode",
|
|
1445
|
+
type: "module",
|
|
1446
|
+
dangerouslySetInnerHTML: {
|
|
1447
|
+
__html: previewModeScript
|
|
1448
|
+
}
|
|
1449
|
+
}), /* @__PURE__ */ jsxRuntime.jsx("script", {
|
|
1450
|
+
id: "makeswift-connection-check",
|
|
1451
|
+
type: "module",
|
|
1452
|
+
dangerouslySetInnerHTML: {
|
|
1453
|
+
__html: makeswiftConnectionCheckScript
|
|
1454
|
+
}
|
|
1455
|
+
})]
|
|
1048
1456
|
});
|
|
1049
1457
|
}
|
|
1050
1458
|
class Document$1 extends NextDocument__default["default"] {
|
|
@@ -1083,11 +1491,14 @@ class Document$1 extends NextDocument__default["default"] {
|
|
|
1083
1491
|
});
|
|
1084
1492
|
}
|
|
1085
1493
|
}
|
|
1086
|
-
const version = "0.6.3";
|
|
1087
1494
|
function isErrorWithMessage(error) {
|
|
1088
1495
|
return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
|
|
1089
1496
|
}
|
|
1090
|
-
function MakeswiftApiHandler(apiKey, {
|
|
1497
|
+
function MakeswiftApiHandler(apiKey, {
|
|
1498
|
+
appOrigin = "https://app.makeswift.com",
|
|
1499
|
+
apiOrigin = "https://api.makeswift.com",
|
|
1500
|
+
getFonts
|
|
1501
|
+
} = {}) {
|
|
1091
1502
|
const cors = Cors__default["default"]({ origin: appOrigin });
|
|
1092
1503
|
const previewModeProxy = httpProxy.createProxyServer();
|
|
1093
1504
|
previewModeProxy.on("proxyReq", (proxyReq) => {
|
|
@@ -1123,7 +1534,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
|
|
|
1123
1534
|
return res.status(401).json({ message: "Unauthorized" });
|
|
1124
1535
|
return res.json({
|
|
1125
1536
|
version,
|
|
1126
|
-
previewMode: true
|
|
1537
|
+
previewMode: true,
|
|
1538
|
+
interactionMode: true
|
|
1127
1539
|
});
|
|
1128
1540
|
}
|
|
1129
1541
|
case "revalidate": {
|
|
@@ -1196,6 +1608,35 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1196
1608
|
const response = { elementTree: generatedElementTree };
|
|
1197
1609
|
return res.json(response);
|
|
1198
1610
|
}
|
|
1611
|
+
case "snapshot": {
|
|
1612
|
+
let validateBody = function(body2) {
|
|
1613
|
+
if (body2.pageId == null) {
|
|
1614
|
+
return res.status(400).json({ message: "Must define pageId." });
|
|
1615
|
+
}
|
|
1616
|
+
if (body2.currentSnapshot == null && body2.publishedElementTree == null) {
|
|
1617
|
+
return res.status(400).json({ message: "Either currentSnapshot or publishedElementTree must be defined." });
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
const body = req.body;
|
|
1621
|
+
validateBody(body);
|
|
1622
|
+
const client = new Makeswift(apiKey, {
|
|
1623
|
+
apiOrigin
|
|
1624
|
+
});
|
|
1625
|
+
const snapshot = await client.unstable_createSnapshot({
|
|
1626
|
+
publishedResources: body.publishedResources,
|
|
1627
|
+
deletedResources: body.deletedResources,
|
|
1628
|
+
publishedElementTree: body.publishedElementTree,
|
|
1629
|
+
currentSnapshot: body.currentSnapshot
|
|
1630
|
+
});
|
|
1631
|
+
const usedResources = client.unstable_getSnapshotResourceMapping(snapshot);
|
|
1632
|
+
const response = {
|
|
1633
|
+
pageId: body.pageId,
|
|
1634
|
+
snapshot,
|
|
1635
|
+
livePageChanges: body.livePageChanges,
|
|
1636
|
+
usedResources
|
|
1637
|
+
};
|
|
1638
|
+
return res.json(response);
|
|
1639
|
+
}
|
|
1199
1640
|
default:
|
|
1200
1641
|
return res.status(404).json({ message: "Not Found" });
|
|
1201
1642
|
}
|
|
@@ -1330,6 +1771,37 @@ const Page = React.memo(({
|
|
|
1330
1771
|
}, snapshot.document.data.key)
|
|
1331
1772
|
});
|
|
1332
1773
|
});
|
|
1774
|
+
const unstable_Page = React.memo(({
|
|
1775
|
+
pageData
|
|
1776
|
+
}) => {
|
|
1777
|
+
function resourcesToCacheData(resources) {
|
|
1778
|
+
if (resources == null)
|
|
1779
|
+
return void 0;
|
|
1780
|
+
return {
|
|
1781
|
+
Swatch: resources.Swatch,
|
|
1782
|
+
File: resources.File,
|
|
1783
|
+
Typography: resources.Typography,
|
|
1784
|
+
PagePathnameSlice: resources.PagePathnameSlice,
|
|
1785
|
+
GlobalElement: resources.GlobalElement,
|
|
1786
|
+
Table: resources.Table,
|
|
1787
|
+
Snippet: resources.Snippet,
|
|
1788
|
+
Page: resources.Page,
|
|
1789
|
+
Site: resources.Site
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
const client = React.useMemo(() => new MakeswiftClient({
|
|
1793
|
+
uri: new URL("graphql", pageData.options.apiOrigin).href,
|
|
1794
|
+
cacheData: resourcesToCacheData(pageData.snapshot.resources)
|
|
1795
|
+
}), [pageData]);
|
|
1796
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RuntimeProvider, {
|
|
1797
|
+
client,
|
|
1798
|
+
rootElements: /* @__PURE__ */ new Map([[pageData.pageId, pageData.snapshot.elementTree]]),
|
|
1799
|
+
preview: pageData.options.preview,
|
|
1800
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(unstable_Page$1, {
|
|
1801
|
+
pageData
|
|
1802
|
+
})
|
|
1803
|
+
});
|
|
1804
|
+
});
|
|
1333
1805
|
const keys = (o) => Object.keys(o);
|
|
1334
1806
|
const coalesce = (...args) => {
|
|
1335
1807
|
let i;
|
|
@@ -2261,6 +2733,7 @@ function registerComponent$1(runtime) {
|
|
|
2261
2733
|
text: richText.RichText(() => ({
|
|
2262
2734
|
preset: {
|
|
2263
2735
|
document: {
|
|
2736
|
+
object: "document",
|
|
2264
2737
|
nodes: [
|
|
2265
2738
|
{
|
|
2266
2739
|
object: "block",
|
|
@@ -3641,6 +4114,9 @@ function useIsInBuilder() {
|
|
|
3641
4114
|
function useIsPreview() {
|
|
3642
4115
|
return useSelector((state) => constants.getIsPreview(state));
|
|
3643
4116
|
}
|
|
4117
|
+
function useBuilderEditMode() {
|
|
4118
|
+
return useSelector((state) => constants.getBuilderEditMode(state));
|
|
4119
|
+
}
|
|
3644
4120
|
function useDispatch() {
|
|
3645
4121
|
const store = React.useContext(StoreContext);
|
|
3646
4122
|
return store.dispatch;
|
|
@@ -3813,8 +4289,11 @@ exports.responsiveTextStyle = responsiveTextStyle;
|
|
|
3813
4289
|
exports.responsiveWidth = responsiveWidth;
|
|
3814
4290
|
exports.shallowMergeFallbacks = shallowMergeFallbacks;
|
|
3815
4291
|
exports.storeContextDefaultValue = storeContextDefaultValue;
|
|
4292
|
+
exports.unstable_Page = unstable_Page$1;
|
|
4293
|
+
exports.unstable_Page$1 = unstable_Page;
|
|
3816
4294
|
exports.useBorder = useBorder;
|
|
3817
4295
|
exports.useBoxShadow = useBoxShadow;
|
|
4296
|
+
exports.useBuilderEditMode = useBuilderEditMode;
|
|
3818
4297
|
exports.useElementId = useElementId;
|
|
3819
4298
|
exports.useFile = useFile;
|
|
3820
4299
|
exports.useFiles = useFiles;
|