@makeswift/runtime 0.6.6 → 0.6.7
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 +0 -1
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +1 -1
- package/dist/index.cjs.js +172 -284
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +173 -283
- 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 +0 -1
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +1 -1
- package/dist/types/src/components/page/Page.d.ts +1 -5
- package/dist/types/src/components/page/Page.d.ts.map +1 -1
- package/dist/types/src/next/api-handler.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +18 -16
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts +0 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/next/snapshots.d.ts +100 -0
- package/dist/types/src/next/snapshots.d.ts.map +1 -0
- package/dist/types/src/state/modules/api-resources.d.ts +2 -0
- package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -271,6 +271,16 @@ const deepEqual = (a, b) => {
|
|
|
271
271
|
}
|
|
272
272
|
return true;
|
|
273
273
|
};
|
|
274
|
+
function getSnapshotResourcesFromSerializedState(serializedState) {
|
|
275
|
+
const resources = {
|
|
276
|
+
swatches: serializedState.Swatch.filter((_) => true),
|
|
277
|
+
typographies: serializedState.Typography.filter((_) => true),
|
|
278
|
+
files: serializedState.File.filter((_) => true),
|
|
279
|
+
pagePathnameSlices: serializedState.PagePathnameSlice.filter((_) => true),
|
|
280
|
+
globalElements: serializedState.GlobalElement.filter((_) => true)
|
|
281
|
+
};
|
|
282
|
+
return resources;
|
|
283
|
+
}
|
|
274
284
|
function getInitialState(serializedState = {
|
|
275
285
|
Swatch: [],
|
|
276
286
|
File: [],
|
|
@@ -957,159 +967,6 @@ function Page$1({
|
|
|
957
967
|
}, snippet.id))]
|
|
958
968
|
});
|
|
959
969
|
}
|
|
960
|
-
function unstable_Page$1({
|
|
961
|
-
pageData
|
|
962
|
-
}) {
|
|
963
|
-
var _a;
|
|
964
|
-
const isInBuilder = useIsInBuilder();
|
|
965
|
-
const [snippets, setSnippets] = React.useState(pageData.snapshot.resources.snippets);
|
|
966
|
-
const cachedPage = useCachedPage(isInBuilder ? pageData.pageId : null);
|
|
967
|
-
React.useEffect(() => {
|
|
968
|
-
if (cachedPage == null)
|
|
969
|
-
return;
|
|
970
|
-
const oldSnippets = snippets.map(filterUsedSnippetProperties);
|
|
971
|
-
const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties);
|
|
972
|
-
if (deepEqual(newSnippets, oldSnippets))
|
|
973
|
-
return;
|
|
974
|
-
setSnippets(cachedPage.snippets);
|
|
975
|
-
}, [cachedPage]);
|
|
976
|
-
const site = useCachedSite(isInBuilder ? pageData.siteId : null);
|
|
977
|
-
const favicon = (_a = pageData.snapshot.resources.meta.favicon) != null ? _a : defaultFavicon;
|
|
978
|
-
const {
|
|
979
|
-
title,
|
|
980
|
-
description,
|
|
981
|
-
keywords,
|
|
982
|
-
socialImage
|
|
983
|
-
} = pageData.snapshot.resources.meta;
|
|
984
|
-
const {
|
|
985
|
-
canonicalUrl,
|
|
986
|
-
isIndexingBlocked
|
|
987
|
-
} = pageData.snapshot.resources.seo;
|
|
988
|
-
const fontFamilyParamValue = React.useMemo(() => {
|
|
989
|
-
if (site == null) {
|
|
990
|
-
return pageData.snapshot.resources.fonts.map(({
|
|
991
|
-
family,
|
|
992
|
-
variants
|
|
993
|
-
}) => {
|
|
994
|
-
return `${family.replace(/ /g, "+")}:${variants.join()}`;
|
|
995
|
-
}).join("|");
|
|
996
|
-
}
|
|
997
|
-
return site.googleFonts.edges.filter((edge) => edge != null).map(({
|
|
998
|
-
activeVariants,
|
|
999
|
-
node: {
|
|
1000
|
-
family,
|
|
1001
|
-
variants
|
|
1002
|
-
}
|
|
1003
|
-
}) => {
|
|
1004
|
-
const activeVariantSpecifiers = variants.filter((variant) => activeVariants.some((activeVariant) => activeVariant.specifier === variant.specifier)).map((variant) => variant.specifier).join();
|
|
1005
|
-
return `${family.replace(/ /g, "+")}:${activeVariantSpecifiers}`;
|
|
1006
|
-
}).join("|");
|
|
1007
|
-
}, [site, pageData.snapshot.resources.fonts]);
|
|
1008
|
-
const filteredSnippets = React.useMemo(() => snippets.filter((snippet) => isInBuilder ? snippet.builderEnabled : snippet.liveEnabled), [snippets, isInBuilder]);
|
|
1009
|
-
const headSnippets = React.useMemo(() => filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Head), [filteredSnippets]);
|
|
1010
|
-
const previousHeadSnippets = React.useRef(null);
|
|
1011
|
-
React.useEffect(() => {
|
|
1012
|
-
var _a2;
|
|
1013
|
-
const headSnippetsToCleanUp = ((_a2 = previousHeadSnippets.current) != null ? _a2 : []).filter((previousSnippet) => previousSnippet.cleanup != null).filter((previousSnippet) => !headSnippets.some((snippet) => previousSnippet.id === snippet.id));
|
|
1014
|
-
headSnippetsToCleanUp.forEach((snippetToCleanUp) => {
|
|
1015
|
-
if (snippetToCleanUp.cleanup == null)
|
|
1016
|
-
return;
|
|
1017
|
-
const cleanUp = new Function(snippetToCleanUp.cleanup);
|
|
1018
|
-
try {
|
|
1019
|
-
cleanUp();
|
|
1020
|
-
} catch {
|
|
1021
|
-
}
|
|
1022
|
-
});
|
|
1023
|
-
previousHeadSnippets.current = headSnippets;
|
|
1024
|
-
}, [headSnippets]);
|
|
1025
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1026
|
-
children: [/* @__PURE__ */ jsxRuntime.jsxs(Head__default["default"], {
|
|
1027
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("style", {
|
|
1028
|
-
children: `
|
|
1029
|
-
html {
|
|
1030
|
-
font-family: sans-serif;
|
|
1031
|
-
}
|
|
1032
|
-
div#__next {
|
|
1033
|
-
overflow: hidden;
|
|
1034
|
-
}
|
|
1035
|
-
`
|
|
1036
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
1037
|
-
rel: "icon",
|
|
1038
|
-
type: favicon.mimetype,
|
|
1039
|
-
href: favicon.publicUrl
|
|
1040
|
-
}), canonicalUrl && /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
1041
|
-
rel: "canonical",
|
|
1042
|
-
href: canonicalUrl
|
|
1043
|
-
}), isIndexingBlocked && /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1044
|
-
name: "robots",
|
|
1045
|
-
content: "noindex"
|
|
1046
|
-
}), title && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1047
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("title", {
|
|
1048
|
-
children: title
|
|
1049
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1050
|
-
property: "og:title",
|
|
1051
|
-
content: title
|
|
1052
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1053
|
-
name: "twitter:title",
|
|
1054
|
-
content: title
|
|
1055
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1056
|
-
itemProp: "name",
|
|
1057
|
-
content: title
|
|
1058
|
-
})]
|
|
1059
|
-
}), description && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1060
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1061
|
-
name: "description",
|
|
1062
|
-
content: description
|
|
1063
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1064
|
-
property: "og:description",
|
|
1065
|
-
content: description
|
|
1066
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1067
|
-
name: "twitter:description",
|
|
1068
|
-
content: description
|
|
1069
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1070
|
-
itemProp: "description",
|
|
1071
|
-
content: description
|
|
1072
|
-
})]
|
|
1073
|
-
}), keywords && /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1074
|
-
name: "keywords",
|
|
1075
|
-
content: keywords
|
|
1076
|
-
}), socialImage && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1077
|
-
children: [/* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1078
|
-
property: "og:image",
|
|
1079
|
-
content: socialImage.publicUrl
|
|
1080
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1081
|
-
property: "og:image:type",
|
|
1082
|
-
content: socialImage.mimetype
|
|
1083
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1084
|
-
name: "twitter:image",
|
|
1085
|
-
content: socialImage.publicUrl
|
|
1086
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1087
|
-
name: "twitter:card",
|
|
1088
|
-
content: "summary_large_image"
|
|
1089
|
-
}), /* @__PURE__ */ jsxRuntime.jsx("meta", {
|
|
1090
|
-
itemProp: "image",
|
|
1091
|
-
content: socialImage.publicUrl
|
|
1092
|
-
})]
|
|
1093
|
-
}), fontFamilyParamValue !== "" && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
1094
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("link", {
|
|
1095
|
-
rel: "stylesheet",
|
|
1096
|
-
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
1097
|
-
})
|
|
1098
|
-
}), headSnippets.map(snippetToElement).map((children) => React.Children.map(children, (child) => {
|
|
1099
|
-
if (typeof child === "string")
|
|
1100
|
-
return child;
|
|
1101
|
-
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
1102
|
-
return child;
|
|
1103
|
-
return null;
|
|
1104
|
-
}))]
|
|
1105
|
-
}), /* @__PURE__ */ jsxRuntime.jsx(DocumentReference, {
|
|
1106
|
-
documentReference: constants.createDocumentReference(pageData.pageId)
|
|
1107
|
-
}), filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Body).map((snippet) => /* @__PURE__ */ jsxRuntime.jsx(BodySnippet, {
|
|
1108
|
-
code: snippet.code,
|
|
1109
|
-
cleanup: snippet.cleanup
|
|
1110
|
-
}, snippet.id))]
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
970
|
function useCachedPage(pageId) {
|
|
1114
971
|
const client = useMakeswiftClient();
|
|
1115
972
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -1122,7 +979,21 @@ function useCachedSite(siteId) {
|
|
|
1122
979
|
const site = shim.useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
1123
980
|
return site;
|
|
1124
981
|
}
|
|
1125
|
-
const version = "0.6.
|
|
982
|
+
const version = "0.6.7";
|
|
983
|
+
function normalizeToMakeswiftResources(partialResources) {
|
|
984
|
+
const resources = {
|
|
985
|
+
swatches: (partialResources == null ? void 0 : partialResources.swatches) || [],
|
|
986
|
+
typographies: (partialResources == null ? void 0 : partialResources.typographies) || [],
|
|
987
|
+
files: (partialResources == null ? void 0 : partialResources.files) || [],
|
|
988
|
+
pagePathnameSlices: (partialResources == null ? void 0 : partialResources.pagePathnameSlices) || [],
|
|
989
|
+
globalElements: (partialResources == null ? void 0 : partialResources.globalElements) || [],
|
|
990
|
+
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
991
|
+
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
992
|
+
pageMetadata: (partialResources == null ? void 0 : partialResources.pageMetadata) || {},
|
|
993
|
+
pageSeo: (partialResources == null ? void 0 : partialResources.pageSeo) || {}
|
|
994
|
+
};
|
|
995
|
+
return resources;
|
|
996
|
+
}
|
|
1126
997
|
class Makeswift {
|
|
1127
998
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
1128
999
|
__publicField(this, "apiKey");
|
|
@@ -1181,7 +1052,7 @@ Received "${apiKey}" instead.`);
|
|
|
1181
1052
|
if (page == null)
|
|
1182
1053
|
return null;
|
|
1183
1054
|
const document2 = await this.getDocumentForPage(page.id);
|
|
1184
|
-
const snapshot = await this.
|
|
1055
|
+
const snapshot = await this.unstable_createSnapshotOnDemand({ document: document2, pageId: page.id });
|
|
1185
1056
|
return {
|
|
1186
1057
|
pageId: page.id,
|
|
1187
1058
|
siteId: document2.site.id,
|
|
@@ -1193,13 +1064,13 @@ Received "${apiKey}" instead.`);
|
|
|
1193
1064
|
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1194
1065
|
if (!response.ok) {
|
|
1195
1066
|
if (response.status === 404)
|
|
1196
|
-
throw Error("
|
|
1067
|
+
throw Error("Document not found.");
|
|
1197
1068
|
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1198
1069
|
}
|
|
1199
1070
|
const document2 = await response.json();
|
|
1200
1071
|
return document2;
|
|
1201
1072
|
}
|
|
1202
|
-
async
|
|
1073
|
+
async unstable_createSnapshotOnDemand({
|
|
1203
1074
|
document: document2,
|
|
1204
1075
|
pageId
|
|
1205
1076
|
}) {
|
|
@@ -1219,12 +1090,14 @@ Received "${apiKey}" instead.`);
|
|
|
1219
1090
|
}
|
|
1220
1091
|
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1221
1092
|
const prefetchedResources = await client.prefetch(fetchedDocument.data);
|
|
1222
|
-
const resources =
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1093
|
+
const resources = normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(prefetchedResources));
|
|
1094
|
+
resources.snippets = fetchedDocument.snippets.map((snippet) => ({
|
|
1095
|
+
id: snippet.id,
|
|
1096
|
+
value: snippet
|
|
1097
|
+
}));
|
|
1098
|
+
resources.pageMetadata = fetchedDocument.meta;
|
|
1099
|
+
resources.pageSeo = fetchedDocument.seo;
|
|
1100
|
+
resources.fonts = fetchedDocument.fonts.map((font) => ({ id: font.family, value: font }));
|
|
1228
1101
|
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1229
1102
|
}
|
|
1230
1103
|
async unstable_createSnapshot({
|
|
@@ -1234,33 +1107,15 @@ Received "${apiKey}" instead.`);
|
|
|
1234
1107
|
currentSnapshot
|
|
1235
1108
|
}) {
|
|
1236
1109
|
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1237
|
-
function normalizeToMakeswiftResources(partialResources) {
|
|
1238
|
-
const resources2 = {
|
|
1239
|
-
Swatch: (partialResources == null ? void 0 : partialResources.Swatch) || [],
|
|
1240
|
-
File: (partialResources == null ? void 0 : partialResources.File) || [],
|
|
1241
|
-
Typography: (partialResources == null ? void 0 : partialResources.Typography) || [],
|
|
1242
|
-
PagePathnameSlice: (partialResources == null ? void 0 : partialResources.PagePathnameSlice) || [],
|
|
1243
|
-
GlobalElement: (partialResources == null ? void 0 : partialResources.GlobalElement) || [],
|
|
1244
|
-
Table: (partialResources == null ? void 0 : partialResources.Table) || [],
|
|
1245
|
-
Snippet: (partialResources == null ? void 0 : partialResources.Snippet) || [],
|
|
1246
|
-
Page: (partialResources == null ? void 0 : partialResources.Page) || [],
|
|
1247
|
-
Site: (partialResources == null ? void 0 : partialResources.Site) || [],
|
|
1248
|
-
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
1249
|
-
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
1250
|
-
meta: (partialResources == null ? void 0 : partialResources.meta) || {},
|
|
1251
|
-
seo: (partialResources == null ? void 0 : partialResources.seo) || {}
|
|
1252
|
-
};
|
|
1253
|
-
return resources2;
|
|
1254
|
-
}
|
|
1255
1110
|
function mergeResources({
|
|
1256
1111
|
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1257
1112
|
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1258
1113
|
publishedResources: publishedResources2,
|
|
1259
1114
|
deletedResources: deletedResources2
|
|
1260
1115
|
}) {
|
|
1261
|
-
function
|
|
1116
|
+
function mergeIdSpecifiedResource(resourceSet, deletedResources3) {
|
|
1262
1117
|
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1263
|
-
deletedResources3.forEach((
|
|
1118
|
+
deletedResources3 == null ? void 0 : deletedResources3.forEach((id) => map.delete(id));
|
|
1264
1119
|
const finalResourceSet = [];
|
|
1265
1120
|
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1266
1121
|
if (value != null) {
|
|
@@ -1269,80 +1124,54 @@ Received "${apiKey}" instead.`);
|
|
|
1269
1124
|
});
|
|
1270
1125
|
return finalResourceSet;
|
|
1271
1126
|
}
|
|
1272
|
-
function mergeSnippets(snippets, deletedSnippet) {
|
|
1273
|
-
const map = new Map(snippets.map((value) => [value.id, value]));
|
|
1274
|
-
deletedSnippet.forEach(({ id }) => map.delete(id));
|
|
1275
|
-
const uniqueSnippets = [];
|
|
1276
|
-
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1277
|
-
uniqueSnippets.push(value);
|
|
1278
|
-
});
|
|
1279
|
-
return uniqueSnippets;
|
|
1280
|
-
}
|
|
1281
|
-
function mergeFonts(fonts, deletedFonts) {
|
|
1282
|
-
const map = new Map(fonts.map((value) => [value.family, value]));
|
|
1283
|
-
deletedFonts.forEach(({ family }) => map.delete(family));
|
|
1284
|
-
const uniqueFonts = [];
|
|
1285
|
-
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1286
|
-
uniqueFonts.push(value);
|
|
1287
|
-
});
|
|
1288
|
-
return uniqueFonts;
|
|
1289
|
-
}
|
|
1290
1127
|
const resources2 = {
|
|
1291
|
-
|
|
1292
|
-
...resourcesFromPublishedElementTree2.
|
|
1293
|
-
...resourcesFromCurrentSnapshot2.
|
|
1294
|
-
...publishedResources2.
|
|
1295
|
-
], deletedResources2.
|
|
1296
|
-
|
|
1297
|
-
...resourcesFromPublishedElementTree2.
|
|
1298
|
-
...resourcesFromCurrentSnapshot2.
|
|
1299
|
-
...publishedResources2.
|
|
1300
|
-
], deletedResources2.
|
|
1301
|
-
|
|
1302
|
-
...resourcesFromPublishedElementTree2.
|
|
1303
|
-
...resourcesFromCurrentSnapshot2.
|
|
1304
|
-
...publishedResources2.
|
|
1305
|
-
], deletedResources2.
|
|
1306
|
-
|
|
1307
|
-
...resourcesFromPublishedElementTree2.
|
|
1308
|
-
...resourcesFromCurrentSnapshot2.
|
|
1309
|
-
...publishedResources2.
|
|
1310
|
-
], deletedResources2.
|
|
1311
|
-
|
|
1312
|
-
...resourcesFromPublishedElementTree2.
|
|
1313
|
-
...resourcesFromCurrentSnapshot2.
|
|
1314
|
-
...publishedResources2.
|
|
1315
|
-
], deletedResources2.
|
|
1316
|
-
|
|
1317
|
-
...resourcesFromPublishedElementTree2.Table,
|
|
1318
|
-
...resourcesFromCurrentSnapshot2.Table,
|
|
1319
|
-
...publishedResources2.Table
|
|
1320
|
-
], deletedResources2.Table),
|
|
1321
|
-
snippets: mergeSnippets([
|
|
1322
|
-
...resourcesFromCurrentSnapshot2.snippets,
|
|
1128
|
+
swatches: mergeIdSpecifiedResource([
|
|
1129
|
+
...resourcesFromPublishedElementTree2.swatches,
|
|
1130
|
+
...resourcesFromCurrentSnapshot2.swatches,
|
|
1131
|
+
...publishedResources2.swatches
|
|
1132
|
+
], deletedResources2 == null ? void 0 : deletedResources2.swatches),
|
|
1133
|
+
files: mergeIdSpecifiedResource([
|
|
1134
|
+
...resourcesFromPublishedElementTree2.files,
|
|
1135
|
+
...resourcesFromCurrentSnapshot2.files,
|
|
1136
|
+
...publishedResources2.files
|
|
1137
|
+
], deletedResources2 == null ? void 0 : deletedResources2.files),
|
|
1138
|
+
typographies: mergeIdSpecifiedResource([
|
|
1139
|
+
...resourcesFromPublishedElementTree2.typographies,
|
|
1140
|
+
...resourcesFromCurrentSnapshot2.typographies,
|
|
1141
|
+
...publishedResources2.typographies
|
|
1142
|
+
], deletedResources2 == null ? void 0 : deletedResources2.typographies),
|
|
1143
|
+
pagePathnameSlices: mergeIdSpecifiedResource([
|
|
1144
|
+
...resourcesFromPublishedElementTree2.pagePathnameSlices,
|
|
1145
|
+
...resourcesFromCurrentSnapshot2.pagePathnameSlices,
|
|
1146
|
+
...publishedResources2.pagePathnameSlices
|
|
1147
|
+
], deletedResources2 == null ? void 0 : deletedResources2.pagePathnameSlices),
|
|
1148
|
+
globalElements: mergeIdSpecifiedResource([
|
|
1149
|
+
...resourcesFromPublishedElementTree2.globalElements,
|
|
1150
|
+
...resourcesFromCurrentSnapshot2.globalElements,
|
|
1151
|
+
...publishedResources2.globalElements
|
|
1152
|
+
], deletedResources2 == null ? void 0 : deletedResources2.globalElements),
|
|
1153
|
+
snippets: mergeIdSpecifiedResource([
|
|
1323
1154
|
...resourcesFromPublishedElementTree2.snippets,
|
|
1155
|
+
...resourcesFromCurrentSnapshot2.snippets,
|
|
1324
1156
|
...publishedResources2.snippets
|
|
1325
|
-
], deletedResources2.snippets),
|
|
1326
|
-
fonts:
|
|
1327
|
-
...resourcesFromCurrentSnapshot2.fonts,
|
|
1157
|
+
], deletedResources2 == null ? void 0 : deletedResources2.snippets),
|
|
1158
|
+
fonts: mergeIdSpecifiedResource([
|
|
1328
1159
|
...resourcesFromPublishedElementTree2.fonts,
|
|
1160
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1329
1161
|
...publishedResources2.fonts
|
|
1330
|
-
], deletedResources2.fonts),
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
Snippet: [],
|
|
1334
|
-
Page: [],
|
|
1335
|
-
Site: []
|
|
1162
|
+
], deletedResources2 == null ? void 0 : deletedResources2.fonts),
|
|
1163
|
+
pageMetadata: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageMetadata), publishedResources2.pageMetadata),
|
|
1164
|
+
pageSeo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageSeo), publishedResources2.pageSeo)
|
|
1336
1165
|
};
|
|
1337
1166
|
return resources2;
|
|
1338
1167
|
}
|
|
1339
|
-
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1168
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(await client.prefetch(publishedElementTree))) : normalizeToMakeswiftResources({});
|
|
1340
1169
|
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1341
1170
|
const resources = mergeResources({
|
|
1342
1171
|
resourcesFromPublishedElementTree,
|
|
1343
1172
|
resourcesFromCurrentSnapshot,
|
|
1344
1173
|
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1345
|
-
deletedResources
|
|
1174
|
+
deletedResources
|
|
1346
1175
|
});
|
|
1347
1176
|
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1348
1177
|
if (elementTree == null) {
|
|
@@ -1360,12 +1189,11 @@ Received "${apiKey}" instead.`);
|
|
|
1360
1189
|
return id;
|
|
1361
1190
|
}
|
|
1362
1191
|
return [
|
|
1363
|
-
...resources.
|
|
1364
|
-
...resources.
|
|
1365
|
-
...resources.
|
|
1366
|
-
...resources.
|
|
1367
|
-
...resources.
|
|
1368
|
-
...resources.Table.map(parseResourceIds),
|
|
1192
|
+
...resources.swatches.map(parseResourceIds),
|
|
1193
|
+
...resources.files.map(parseResourceIds),
|
|
1194
|
+
...resources.typographies.map(parseResourceIds),
|
|
1195
|
+
...resources.pagePathnameSlices.map(parseResourceIds),
|
|
1196
|
+
...resources.globalElements.map(parseResourceIds),
|
|
1369
1197
|
...resources.snippets.map(parseResourceIds)
|
|
1370
1198
|
];
|
|
1371
1199
|
}
|
|
@@ -1629,8 +1457,101 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1629
1457
|
const client = new Makeswift(apiKey, {
|
|
1630
1458
|
apiOrigin
|
|
1631
1459
|
});
|
|
1460
|
+
const makeswiftApiClient = new MakeswiftClient({ uri: new URL("graphql", apiOrigin).href });
|
|
1461
|
+
async function formMakeswiftResources(publishedResources) {
|
|
1462
|
+
var _a2, _b, _c2, _d, _e, _f, _g;
|
|
1463
|
+
const publishedResourcesInMakeswiftSnapshotFormat = {
|
|
1464
|
+
swatches: [],
|
|
1465
|
+
typographies: [],
|
|
1466
|
+
files: [],
|
|
1467
|
+
pagePathnameSlices: [],
|
|
1468
|
+
globalElements: [],
|
|
1469
|
+
snippets: [],
|
|
1470
|
+
fonts: [],
|
|
1471
|
+
pageMetadata: publishedResources == null ? void 0 : publishedResources.pageMetadata,
|
|
1472
|
+
pageSeo: publishedResources == null ? void 0 : publishedResources.pageSeo
|
|
1473
|
+
};
|
|
1474
|
+
if (publishedResources == null) {
|
|
1475
|
+
return publishedResourcesInMakeswiftSnapshotFormat;
|
|
1476
|
+
}
|
|
1477
|
+
for await (const swatchId of publishedResources.swatches || []) {
|
|
1478
|
+
const swatch = await makeswiftApiClient.fetchSwatch(swatchId);
|
|
1479
|
+
if (swatch != null) {
|
|
1480
|
+
(_a2 = publishedResourcesInMakeswiftSnapshotFormat.swatches) == null ? void 0 : _a2.push({
|
|
1481
|
+
id: swatchId,
|
|
1482
|
+
value: swatch
|
|
1483
|
+
});
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
for await (const typographyId of publishedResources.typographies || []) {
|
|
1487
|
+
const typography = await makeswiftApiClient.fetchTypography(typographyId);
|
|
1488
|
+
if (typography != null) {
|
|
1489
|
+
(_b = publishedResourcesInMakeswiftSnapshotFormat.typographies) == null ? void 0 : _b.push({
|
|
1490
|
+
id: typographyId,
|
|
1491
|
+
value: typography
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
for await (const fileId of publishedResources.files || []) {
|
|
1496
|
+
const file = await makeswiftApiClient.fetchFile(fileId);
|
|
1497
|
+
if (file != null) {
|
|
1498
|
+
(_c2 = publishedResourcesInMakeswiftSnapshotFormat.files) == null ? void 0 : _c2.push({
|
|
1499
|
+
id: fileId,
|
|
1500
|
+
value: file
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
for await (const pageId of publishedResources.pagePathnameSlices || []) {
|
|
1505
|
+
const pagePathnameSlice = await makeswiftApiClient.fetchPagePathnameSlice(pageId);
|
|
1506
|
+
if (pagePathnameSlice != null) {
|
|
1507
|
+
(_d = publishedResourcesInMakeswiftSnapshotFormat.pagePathnameSlices) == null ? void 0 : _d.push({
|
|
1508
|
+
id: pageId,
|
|
1509
|
+
value: pagePathnameSlice
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
for await (const globalElementId of publishedResources.globalElements || []) {
|
|
1514
|
+
const globalElement = await makeswiftApiClient.fetchGlobalElement(globalElementId);
|
|
1515
|
+
if (globalElement != null) {
|
|
1516
|
+
(_e = publishedResourcesInMakeswiftSnapshotFormat.globalElements) == null ? void 0 : _e.push({
|
|
1517
|
+
id: globalElementId,
|
|
1518
|
+
value: globalElement
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
if (publishedResources.snippets != null || publishedResources.fonts != null) {
|
|
1523
|
+
const response2 = await fetch(new URL(`/v1/pages/${body.pageId}/document?preview=false`, apiOrigin).toString(), {
|
|
1524
|
+
headers: { ["X-API-Key"]: apiKey }
|
|
1525
|
+
});
|
|
1526
|
+
if (!response2.ok) {
|
|
1527
|
+
throw new Error(`Failed to hit live page endpoint: "${response2.statusText}"`);
|
|
1528
|
+
}
|
|
1529
|
+
const document2 = await response2.json();
|
|
1530
|
+
const availableSnippets = document2.snippets;
|
|
1531
|
+
const availableFonts = document2.fonts;
|
|
1532
|
+
for await (const snippetId of publishedResources.snippets || []) {
|
|
1533
|
+
const snippet = availableSnippets.find((availableSnippet) => availableSnippet.id === snippetId);
|
|
1534
|
+
if (snippet != null) {
|
|
1535
|
+
(_f = publishedResourcesInMakeswiftSnapshotFormat.snippets) == null ? void 0 : _f.push({
|
|
1536
|
+
id: snippetId,
|
|
1537
|
+
value: snippet
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
for await (const family of publishedResources.fonts || []) {
|
|
1542
|
+
const font = availableFonts.find((availableFont) => availableFont.family === family);
|
|
1543
|
+
if (font != null) {
|
|
1544
|
+
(_g = publishedResourcesInMakeswiftSnapshotFormat.fonts) == null ? void 0 : _g.push({
|
|
1545
|
+
id: family,
|
|
1546
|
+
value: font
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
return publishedResourcesInMakeswiftSnapshotFormat;
|
|
1552
|
+
}
|
|
1632
1553
|
const snapshot = await client.unstable_createSnapshot({
|
|
1633
|
-
publishedResources: body.publishedResources,
|
|
1554
|
+
publishedResources: await formMakeswiftResources(body.publishedResources),
|
|
1634
1555
|
deletedResources: body.deletedResources,
|
|
1635
1556
|
publishedElementTree: body.publishedElementTree,
|
|
1636
1557
|
currentSnapshot: body.currentSnapshot
|
|
@@ -1778,37 +1699,6 @@ const Page = React.memo(({
|
|
|
1778
1699
|
}, snapshot.document.data.key)
|
|
1779
1700
|
});
|
|
1780
1701
|
});
|
|
1781
|
-
const unstable_Page = React.memo(({
|
|
1782
|
-
pageData
|
|
1783
|
-
}) => {
|
|
1784
|
-
function resourcesToCacheData(resources) {
|
|
1785
|
-
if (resources == null)
|
|
1786
|
-
return void 0;
|
|
1787
|
-
return {
|
|
1788
|
-
Swatch: resources.Swatch,
|
|
1789
|
-
File: resources.File,
|
|
1790
|
-
Typography: resources.Typography,
|
|
1791
|
-
PagePathnameSlice: resources.PagePathnameSlice,
|
|
1792
|
-
GlobalElement: resources.GlobalElement,
|
|
1793
|
-
Table: resources.Table,
|
|
1794
|
-
Snippet: resources.Snippet,
|
|
1795
|
-
Page: resources.Page,
|
|
1796
|
-
Site: resources.Site
|
|
1797
|
-
};
|
|
1798
|
-
}
|
|
1799
|
-
const client = React.useMemo(() => new MakeswiftClient({
|
|
1800
|
-
uri: new URL("graphql", pageData.options.apiOrigin).href,
|
|
1801
|
-
cacheData: resourcesToCacheData(pageData.snapshot.resources)
|
|
1802
|
-
}), [pageData]);
|
|
1803
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RuntimeProvider, {
|
|
1804
|
-
client,
|
|
1805
|
-
rootElements: /* @__PURE__ */ new Map([[pageData.pageId, pageData.snapshot.elementTree]]),
|
|
1806
|
-
preview: pageData.options.preview,
|
|
1807
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(unstable_Page$1, {
|
|
1808
|
-
pageData
|
|
1809
|
-
})
|
|
1810
|
-
});
|
|
1811
|
-
});
|
|
1812
1702
|
const keys = (o) => Object.keys(o);
|
|
1813
1703
|
const coalesce = (...args) => {
|
|
1814
1704
|
let i;
|
|
@@ -4309,8 +4199,6 @@ exports.responsiveTextStyle = responsiveTextStyle;
|
|
|
4309
4199
|
exports.responsiveWidth = responsiveWidth;
|
|
4310
4200
|
exports.shallowMergeFallbacks = shallowMergeFallbacks;
|
|
4311
4201
|
exports.storeContextDefaultValue = storeContextDefaultValue;
|
|
4312
|
-
exports.unstable_Page = unstable_Page$1;
|
|
4313
|
-
exports.unstable_Page$1 = unstable_Page;
|
|
4314
4202
|
exports.useBorder = useBorder;
|
|
4315
4203
|
exports.useBoxShadow = useBoxShadow;
|
|
4316
4204
|
exports.useBuilderEditMode = useBuilderEditMode;
|