@makeswift/runtime 0.6.4 → 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.es.js +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.es.js +1 -1
- package/dist/ReadOnlyText.es.js +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/components.cjs.js +1 -0
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +1 -1
- package/dist/index.cjs.js +450 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +449 -9
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es3.js +1 -1
- package/dist/index.es4.js +1 -1
- package/dist/index.es6.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/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/next/api-handler.d.ts +13 -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/state/modules/api-resources.d.ts +6 -2
- package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
- package/package.json +1 -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,6 +1170,199 @@ 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,
|
|
@@ -1114,11 +1491,14 @@ class Document$1 extends NextDocument__default["default"] {
|
|
|
1114
1491
|
});
|
|
1115
1492
|
}
|
|
1116
1493
|
}
|
|
1117
|
-
const version = "0.6.4";
|
|
1118
1494
|
function isErrorWithMessage(error) {
|
|
1119
1495
|
return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
|
|
1120
1496
|
}
|
|
1121
|
-
function MakeswiftApiHandler(apiKey, {
|
|
1497
|
+
function MakeswiftApiHandler(apiKey, {
|
|
1498
|
+
appOrigin = "https://app.makeswift.com",
|
|
1499
|
+
apiOrigin = "https://api.makeswift.com",
|
|
1500
|
+
getFonts
|
|
1501
|
+
} = {}) {
|
|
1122
1502
|
const cors = Cors__default["default"]({ origin: appOrigin });
|
|
1123
1503
|
const previewModeProxy = httpProxy.createProxyServer();
|
|
1124
1504
|
previewModeProxy.on("proxyReq", (proxyReq) => {
|
|
@@ -1228,6 +1608,35 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1228
1608
|
const response = { elementTree: generatedElementTree };
|
|
1229
1609
|
return res.json(response);
|
|
1230
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
|
+
}
|
|
1231
1640
|
default:
|
|
1232
1641
|
return res.status(404).json({ message: "Not Found" });
|
|
1233
1642
|
}
|
|
@@ -1362,6 +1771,37 @@ const Page = React.memo(({
|
|
|
1362
1771
|
}, snapshot.document.data.key)
|
|
1363
1772
|
});
|
|
1364
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
|
+
});
|
|
1365
1805
|
const keys = (o) => Object.keys(o);
|
|
1366
1806
|
const coalesce = (...args) => {
|
|
1367
1807
|
let i;
|
|
@@ -3849,6 +4289,8 @@ exports.responsiveTextStyle = responsiveTextStyle;
|
|
|
3849
4289
|
exports.responsiveWidth = responsiveWidth;
|
|
3850
4290
|
exports.shallowMergeFallbacks = shallowMergeFallbacks;
|
|
3851
4291
|
exports.storeContextDefaultValue = storeContextDefaultValue;
|
|
4292
|
+
exports.unstable_Page = unstable_Page$1;
|
|
4293
|
+
exports.unstable_Page$1 = unstable_Page;
|
|
3852
4294
|
exports.useBorder = useBorder;
|
|
3853
4295
|
exports.useBoxShadow = useBoxShadow;
|
|
3854
4296
|
exports.useBuilderEditMode = useBuilderEditMode;
|