@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.es.js
CHANGED
|
@@ -236,6 +236,16 @@ const deepEqual = (a, b) => {
|
|
|
236
236
|
}
|
|
237
237
|
return true;
|
|
238
238
|
};
|
|
239
|
+
function getSnapshotResourcesFromSerializedState(serializedState) {
|
|
240
|
+
const resources = {
|
|
241
|
+
swatches: serializedState.Swatch.filter((_) => true),
|
|
242
|
+
typographies: serializedState.Typography.filter((_) => true),
|
|
243
|
+
files: serializedState.File.filter((_) => true),
|
|
244
|
+
pagePathnameSlices: serializedState.PagePathnameSlice.filter((_) => true),
|
|
245
|
+
globalElements: serializedState.GlobalElement.filter((_) => true)
|
|
246
|
+
};
|
|
247
|
+
return resources;
|
|
248
|
+
}
|
|
239
249
|
function getInitialState(serializedState = {
|
|
240
250
|
Swatch: [],
|
|
241
251
|
File: [],
|
|
@@ -922,159 +932,6 @@ function Page$1({
|
|
|
922
932
|
}, snippet.id))]
|
|
923
933
|
});
|
|
924
934
|
}
|
|
925
|
-
function unstable_Page$1({
|
|
926
|
-
pageData
|
|
927
|
-
}) {
|
|
928
|
-
var _a;
|
|
929
|
-
const isInBuilder = useIsInBuilder();
|
|
930
|
-
const [snippets, setSnippets] = useState(pageData.snapshot.resources.snippets);
|
|
931
|
-
const cachedPage = useCachedPage(isInBuilder ? pageData.pageId : null);
|
|
932
|
-
useEffect(() => {
|
|
933
|
-
if (cachedPage == null)
|
|
934
|
-
return;
|
|
935
|
-
const oldSnippets = snippets.map(filterUsedSnippetProperties);
|
|
936
|
-
const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties);
|
|
937
|
-
if (deepEqual(newSnippets, oldSnippets))
|
|
938
|
-
return;
|
|
939
|
-
setSnippets(cachedPage.snippets);
|
|
940
|
-
}, [cachedPage]);
|
|
941
|
-
const site = useCachedSite(isInBuilder ? pageData.siteId : null);
|
|
942
|
-
const favicon = (_a = pageData.snapshot.resources.meta.favicon) != null ? _a : defaultFavicon;
|
|
943
|
-
const {
|
|
944
|
-
title,
|
|
945
|
-
description,
|
|
946
|
-
keywords,
|
|
947
|
-
socialImage
|
|
948
|
-
} = pageData.snapshot.resources.meta;
|
|
949
|
-
const {
|
|
950
|
-
canonicalUrl,
|
|
951
|
-
isIndexingBlocked
|
|
952
|
-
} = pageData.snapshot.resources.seo;
|
|
953
|
-
const fontFamilyParamValue = useMemo(() => {
|
|
954
|
-
if (site == null) {
|
|
955
|
-
return pageData.snapshot.resources.fonts.map(({
|
|
956
|
-
family,
|
|
957
|
-
variants
|
|
958
|
-
}) => {
|
|
959
|
-
return `${family.replace(/ /g, "+")}:${variants.join()}`;
|
|
960
|
-
}).join("|");
|
|
961
|
-
}
|
|
962
|
-
return site.googleFonts.edges.filter((edge) => edge != null).map(({
|
|
963
|
-
activeVariants,
|
|
964
|
-
node: {
|
|
965
|
-
family,
|
|
966
|
-
variants
|
|
967
|
-
}
|
|
968
|
-
}) => {
|
|
969
|
-
const activeVariantSpecifiers = variants.filter((variant) => activeVariants.some((activeVariant) => activeVariant.specifier === variant.specifier)).map((variant) => variant.specifier).join();
|
|
970
|
-
return `${family.replace(/ /g, "+")}:${activeVariantSpecifiers}`;
|
|
971
|
-
}).join("|");
|
|
972
|
-
}, [site, pageData.snapshot.resources.fonts]);
|
|
973
|
-
const filteredSnippets = useMemo(() => snippets.filter((snippet) => isInBuilder ? snippet.builderEnabled : snippet.liveEnabled), [snippets, isInBuilder]);
|
|
974
|
-
const headSnippets = useMemo(() => filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Head), [filteredSnippets]);
|
|
975
|
-
const previousHeadSnippets = useRef(null);
|
|
976
|
-
useEffect(() => {
|
|
977
|
-
var _a2;
|
|
978
|
-
const headSnippetsToCleanUp = ((_a2 = previousHeadSnippets.current) != null ? _a2 : []).filter((previousSnippet) => previousSnippet.cleanup != null).filter((previousSnippet) => !headSnippets.some((snippet) => previousSnippet.id === snippet.id));
|
|
979
|
-
headSnippetsToCleanUp.forEach((snippetToCleanUp) => {
|
|
980
|
-
if (snippetToCleanUp.cleanup == null)
|
|
981
|
-
return;
|
|
982
|
-
const cleanUp = new Function(snippetToCleanUp.cleanup);
|
|
983
|
-
try {
|
|
984
|
-
cleanUp();
|
|
985
|
-
} catch {
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
previousHeadSnippets.current = headSnippets;
|
|
989
|
-
}, [headSnippets]);
|
|
990
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
991
|
-
children: [/* @__PURE__ */ jsxs(Head, {
|
|
992
|
-
children: [/* @__PURE__ */ jsx("style", {
|
|
993
|
-
children: `
|
|
994
|
-
html {
|
|
995
|
-
font-family: sans-serif;
|
|
996
|
-
}
|
|
997
|
-
div#__next {
|
|
998
|
-
overflow: hidden;
|
|
999
|
-
}
|
|
1000
|
-
`
|
|
1001
|
-
}), /* @__PURE__ */ jsx("link", {
|
|
1002
|
-
rel: "icon",
|
|
1003
|
-
type: favicon.mimetype,
|
|
1004
|
-
href: favicon.publicUrl
|
|
1005
|
-
}), canonicalUrl && /* @__PURE__ */ jsx("link", {
|
|
1006
|
-
rel: "canonical",
|
|
1007
|
-
href: canonicalUrl
|
|
1008
|
-
}), isIndexingBlocked && /* @__PURE__ */ jsx("meta", {
|
|
1009
|
-
name: "robots",
|
|
1010
|
-
content: "noindex"
|
|
1011
|
-
}), title && /* @__PURE__ */ jsxs(Fragment, {
|
|
1012
|
-
children: [/* @__PURE__ */ jsx("title", {
|
|
1013
|
-
children: title
|
|
1014
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1015
|
-
property: "og:title",
|
|
1016
|
-
content: title
|
|
1017
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1018
|
-
name: "twitter:title",
|
|
1019
|
-
content: title
|
|
1020
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1021
|
-
itemProp: "name",
|
|
1022
|
-
content: title
|
|
1023
|
-
})]
|
|
1024
|
-
}), description && /* @__PURE__ */ jsxs(Fragment, {
|
|
1025
|
-
children: [/* @__PURE__ */ jsx("meta", {
|
|
1026
|
-
name: "description",
|
|
1027
|
-
content: description
|
|
1028
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1029
|
-
property: "og:description",
|
|
1030
|
-
content: description
|
|
1031
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1032
|
-
name: "twitter:description",
|
|
1033
|
-
content: description
|
|
1034
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1035
|
-
itemProp: "description",
|
|
1036
|
-
content: description
|
|
1037
|
-
})]
|
|
1038
|
-
}), keywords && /* @__PURE__ */ jsx("meta", {
|
|
1039
|
-
name: "keywords",
|
|
1040
|
-
content: keywords
|
|
1041
|
-
}), socialImage && /* @__PURE__ */ jsxs(Fragment, {
|
|
1042
|
-
children: [/* @__PURE__ */ jsx("meta", {
|
|
1043
|
-
property: "og:image",
|
|
1044
|
-
content: socialImage.publicUrl
|
|
1045
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1046
|
-
property: "og:image:type",
|
|
1047
|
-
content: socialImage.mimetype
|
|
1048
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1049
|
-
name: "twitter:image",
|
|
1050
|
-
content: socialImage.publicUrl
|
|
1051
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1052
|
-
name: "twitter:card",
|
|
1053
|
-
content: "summary_large_image"
|
|
1054
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1055
|
-
itemProp: "image",
|
|
1056
|
-
content: socialImage.publicUrl
|
|
1057
|
-
})]
|
|
1058
|
-
}), fontFamilyParamValue !== "" && /* @__PURE__ */ jsx(Fragment, {
|
|
1059
|
-
children: /* @__PURE__ */ jsx("link", {
|
|
1060
|
-
rel: "stylesheet",
|
|
1061
|
-
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
1062
|
-
})
|
|
1063
|
-
}), headSnippets.map(snippetToElement).map((children) => Children.map(children, (child) => {
|
|
1064
|
-
if (typeof child === "string")
|
|
1065
|
-
return child;
|
|
1066
|
-
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
1067
|
-
return child;
|
|
1068
|
-
return null;
|
|
1069
|
-
}))]
|
|
1070
|
-
}), /* @__PURE__ */ jsx(DocumentReference, {
|
|
1071
|
-
documentReference: createDocumentReference(pageData.pageId)
|
|
1072
|
-
}), filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Body).map((snippet) => /* @__PURE__ */ jsx(BodySnippet, {
|
|
1073
|
-
code: snippet.code,
|
|
1074
|
-
cleanup: snippet.cleanup
|
|
1075
|
-
}, snippet.id))]
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
935
|
function useCachedPage(pageId) {
|
|
1079
936
|
const client = useMakeswiftClient();
|
|
1080
937
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -1087,7 +944,21 @@ function useCachedSite(siteId) {
|
|
|
1087
944
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
1088
945
|
return site;
|
|
1089
946
|
}
|
|
1090
|
-
const version = "0.6.
|
|
947
|
+
const version = "0.6.7";
|
|
948
|
+
function normalizeToMakeswiftResources(partialResources) {
|
|
949
|
+
const resources = {
|
|
950
|
+
swatches: (partialResources == null ? void 0 : partialResources.swatches) || [],
|
|
951
|
+
typographies: (partialResources == null ? void 0 : partialResources.typographies) || [],
|
|
952
|
+
files: (partialResources == null ? void 0 : partialResources.files) || [],
|
|
953
|
+
pagePathnameSlices: (partialResources == null ? void 0 : partialResources.pagePathnameSlices) || [],
|
|
954
|
+
globalElements: (partialResources == null ? void 0 : partialResources.globalElements) || [],
|
|
955
|
+
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
956
|
+
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
957
|
+
pageMetadata: (partialResources == null ? void 0 : partialResources.pageMetadata) || {},
|
|
958
|
+
pageSeo: (partialResources == null ? void 0 : partialResources.pageSeo) || {}
|
|
959
|
+
};
|
|
960
|
+
return resources;
|
|
961
|
+
}
|
|
1091
962
|
class Makeswift {
|
|
1092
963
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
1093
964
|
__publicField(this, "apiKey");
|
|
@@ -1146,7 +1017,7 @@ Received "${apiKey}" instead.`);
|
|
|
1146
1017
|
if (page == null)
|
|
1147
1018
|
return null;
|
|
1148
1019
|
const document2 = await this.getDocumentForPage(page.id);
|
|
1149
|
-
const snapshot = await this.
|
|
1020
|
+
const snapshot = await this.unstable_createSnapshotOnDemand({ document: document2, pageId: page.id });
|
|
1150
1021
|
return {
|
|
1151
1022
|
pageId: page.id,
|
|
1152
1023
|
siteId: document2.site.id,
|
|
@@ -1158,13 +1029,13 @@ Received "${apiKey}" instead.`);
|
|
|
1158
1029
|
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1159
1030
|
if (!response.ok) {
|
|
1160
1031
|
if (response.status === 404)
|
|
1161
|
-
throw Error("
|
|
1032
|
+
throw Error("Document not found.");
|
|
1162
1033
|
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1163
1034
|
}
|
|
1164
1035
|
const document2 = await response.json();
|
|
1165
1036
|
return document2;
|
|
1166
1037
|
}
|
|
1167
|
-
async
|
|
1038
|
+
async unstable_createSnapshotOnDemand({
|
|
1168
1039
|
document: document2,
|
|
1169
1040
|
pageId
|
|
1170
1041
|
}) {
|
|
@@ -1184,12 +1055,14 @@ Received "${apiKey}" instead.`);
|
|
|
1184
1055
|
}
|
|
1185
1056
|
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1186
1057
|
const prefetchedResources = await client.prefetch(fetchedDocument.data);
|
|
1187
|
-
const resources =
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1058
|
+
const resources = normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(prefetchedResources));
|
|
1059
|
+
resources.snippets = fetchedDocument.snippets.map((snippet) => ({
|
|
1060
|
+
id: snippet.id,
|
|
1061
|
+
value: snippet
|
|
1062
|
+
}));
|
|
1063
|
+
resources.pageMetadata = fetchedDocument.meta;
|
|
1064
|
+
resources.pageSeo = fetchedDocument.seo;
|
|
1065
|
+
resources.fonts = fetchedDocument.fonts.map((font) => ({ id: font.family, value: font }));
|
|
1193
1066
|
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1194
1067
|
}
|
|
1195
1068
|
async unstable_createSnapshot({
|
|
@@ -1199,33 +1072,15 @@ Received "${apiKey}" instead.`);
|
|
|
1199
1072
|
currentSnapshot
|
|
1200
1073
|
}) {
|
|
1201
1074
|
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1202
|
-
function normalizeToMakeswiftResources(partialResources) {
|
|
1203
|
-
const resources2 = {
|
|
1204
|
-
Swatch: (partialResources == null ? void 0 : partialResources.Swatch) || [],
|
|
1205
|
-
File: (partialResources == null ? void 0 : partialResources.File) || [],
|
|
1206
|
-
Typography: (partialResources == null ? void 0 : partialResources.Typography) || [],
|
|
1207
|
-
PagePathnameSlice: (partialResources == null ? void 0 : partialResources.PagePathnameSlice) || [],
|
|
1208
|
-
GlobalElement: (partialResources == null ? void 0 : partialResources.GlobalElement) || [],
|
|
1209
|
-
Table: (partialResources == null ? void 0 : partialResources.Table) || [],
|
|
1210
|
-
Snippet: (partialResources == null ? void 0 : partialResources.Snippet) || [],
|
|
1211
|
-
Page: (partialResources == null ? void 0 : partialResources.Page) || [],
|
|
1212
|
-
Site: (partialResources == null ? void 0 : partialResources.Site) || [],
|
|
1213
|
-
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
1214
|
-
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
1215
|
-
meta: (partialResources == null ? void 0 : partialResources.meta) || {},
|
|
1216
|
-
seo: (partialResources == null ? void 0 : partialResources.seo) || {}
|
|
1217
|
-
};
|
|
1218
|
-
return resources2;
|
|
1219
|
-
}
|
|
1220
1075
|
function mergeResources({
|
|
1221
1076
|
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1222
1077
|
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1223
1078
|
publishedResources: publishedResources2,
|
|
1224
1079
|
deletedResources: deletedResources2
|
|
1225
1080
|
}) {
|
|
1226
|
-
function
|
|
1081
|
+
function mergeIdSpecifiedResource(resourceSet, deletedResources3) {
|
|
1227
1082
|
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1228
|
-
deletedResources3.forEach((
|
|
1083
|
+
deletedResources3 == null ? void 0 : deletedResources3.forEach((id) => map.delete(id));
|
|
1229
1084
|
const finalResourceSet = [];
|
|
1230
1085
|
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1231
1086
|
if (value != null) {
|
|
@@ -1234,80 +1089,54 @@ Received "${apiKey}" instead.`);
|
|
|
1234
1089
|
});
|
|
1235
1090
|
return finalResourceSet;
|
|
1236
1091
|
}
|
|
1237
|
-
function mergeSnippets(snippets, deletedSnippet) {
|
|
1238
|
-
const map = new Map(snippets.map((value) => [value.id, value]));
|
|
1239
|
-
deletedSnippet.forEach(({ id }) => map.delete(id));
|
|
1240
|
-
const uniqueSnippets = [];
|
|
1241
|
-
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1242
|
-
uniqueSnippets.push(value);
|
|
1243
|
-
});
|
|
1244
|
-
return uniqueSnippets;
|
|
1245
|
-
}
|
|
1246
|
-
function mergeFonts(fonts, deletedFonts) {
|
|
1247
|
-
const map = new Map(fonts.map((value) => [value.family, value]));
|
|
1248
|
-
deletedFonts.forEach(({ family }) => map.delete(family));
|
|
1249
|
-
const uniqueFonts = [];
|
|
1250
|
-
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1251
|
-
uniqueFonts.push(value);
|
|
1252
|
-
});
|
|
1253
|
-
return uniqueFonts;
|
|
1254
|
-
}
|
|
1255
1092
|
const resources2 = {
|
|
1256
|
-
|
|
1257
|
-
...resourcesFromPublishedElementTree2.
|
|
1258
|
-
...resourcesFromCurrentSnapshot2.
|
|
1259
|
-
...publishedResources2.
|
|
1260
|
-
], deletedResources2.
|
|
1261
|
-
|
|
1262
|
-
...resourcesFromPublishedElementTree2.
|
|
1263
|
-
...resourcesFromCurrentSnapshot2.
|
|
1264
|
-
...publishedResources2.
|
|
1265
|
-
], deletedResources2.
|
|
1266
|
-
|
|
1267
|
-
...resourcesFromPublishedElementTree2.
|
|
1268
|
-
...resourcesFromCurrentSnapshot2.
|
|
1269
|
-
...publishedResources2.
|
|
1270
|
-
], deletedResources2.
|
|
1271
|
-
|
|
1272
|
-
...resourcesFromPublishedElementTree2.
|
|
1273
|
-
...resourcesFromCurrentSnapshot2.
|
|
1274
|
-
...publishedResources2.
|
|
1275
|
-
], deletedResources2.
|
|
1276
|
-
|
|
1277
|
-
...resourcesFromPublishedElementTree2.
|
|
1278
|
-
...resourcesFromCurrentSnapshot2.
|
|
1279
|
-
...publishedResources2.
|
|
1280
|
-
], deletedResources2.
|
|
1281
|
-
|
|
1282
|
-
...resourcesFromPublishedElementTree2.Table,
|
|
1283
|
-
...resourcesFromCurrentSnapshot2.Table,
|
|
1284
|
-
...publishedResources2.Table
|
|
1285
|
-
], deletedResources2.Table),
|
|
1286
|
-
snippets: mergeSnippets([
|
|
1287
|
-
...resourcesFromCurrentSnapshot2.snippets,
|
|
1093
|
+
swatches: mergeIdSpecifiedResource([
|
|
1094
|
+
...resourcesFromPublishedElementTree2.swatches,
|
|
1095
|
+
...resourcesFromCurrentSnapshot2.swatches,
|
|
1096
|
+
...publishedResources2.swatches
|
|
1097
|
+
], deletedResources2 == null ? void 0 : deletedResources2.swatches),
|
|
1098
|
+
files: mergeIdSpecifiedResource([
|
|
1099
|
+
...resourcesFromPublishedElementTree2.files,
|
|
1100
|
+
...resourcesFromCurrentSnapshot2.files,
|
|
1101
|
+
...publishedResources2.files
|
|
1102
|
+
], deletedResources2 == null ? void 0 : deletedResources2.files),
|
|
1103
|
+
typographies: mergeIdSpecifiedResource([
|
|
1104
|
+
...resourcesFromPublishedElementTree2.typographies,
|
|
1105
|
+
...resourcesFromCurrentSnapshot2.typographies,
|
|
1106
|
+
...publishedResources2.typographies
|
|
1107
|
+
], deletedResources2 == null ? void 0 : deletedResources2.typographies),
|
|
1108
|
+
pagePathnameSlices: mergeIdSpecifiedResource([
|
|
1109
|
+
...resourcesFromPublishedElementTree2.pagePathnameSlices,
|
|
1110
|
+
...resourcesFromCurrentSnapshot2.pagePathnameSlices,
|
|
1111
|
+
...publishedResources2.pagePathnameSlices
|
|
1112
|
+
], deletedResources2 == null ? void 0 : deletedResources2.pagePathnameSlices),
|
|
1113
|
+
globalElements: mergeIdSpecifiedResource([
|
|
1114
|
+
...resourcesFromPublishedElementTree2.globalElements,
|
|
1115
|
+
...resourcesFromCurrentSnapshot2.globalElements,
|
|
1116
|
+
...publishedResources2.globalElements
|
|
1117
|
+
], deletedResources2 == null ? void 0 : deletedResources2.globalElements),
|
|
1118
|
+
snippets: mergeIdSpecifiedResource([
|
|
1288
1119
|
...resourcesFromPublishedElementTree2.snippets,
|
|
1120
|
+
...resourcesFromCurrentSnapshot2.snippets,
|
|
1289
1121
|
...publishedResources2.snippets
|
|
1290
|
-
], deletedResources2.snippets),
|
|
1291
|
-
fonts:
|
|
1292
|
-
...resourcesFromCurrentSnapshot2.fonts,
|
|
1122
|
+
], deletedResources2 == null ? void 0 : deletedResources2.snippets),
|
|
1123
|
+
fonts: mergeIdSpecifiedResource([
|
|
1293
1124
|
...resourcesFromPublishedElementTree2.fonts,
|
|
1125
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1294
1126
|
...publishedResources2.fonts
|
|
1295
|
-
], deletedResources2.fonts),
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
Snippet: [],
|
|
1299
|
-
Page: [],
|
|
1300
|
-
Site: []
|
|
1127
|
+
], deletedResources2 == null ? void 0 : deletedResources2.fonts),
|
|
1128
|
+
pageMetadata: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageMetadata), publishedResources2.pageMetadata),
|
|
1129
|
+
pageSeo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageSeo), publishedResources2.pageSeo)
|
|
1301
1130
|
};
|
|
1302
1131
|
return resources2;
|
|
1303
1132
|
}
|
|
1304
|
-
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1133
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(await client.prefetch(publishedElementTree))) : normalizeToMakeswiftResources({});
|
|
1305
1134
|
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1306
1135
|
const resources = mergeResources({
|
|
1307
1136
|
resourcesFromPublishedElementTree,
|
|
1308
1137
|
resourcesFromCurrentSnapshot,
|
|
1309
1138
|
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1310
|
-
deletedResources
|
|
1139
|
+
deletedResources
|
|
1311
1140
|
});
|
|
1312
1141
|
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1313
1142
|
if (elementTree == null) {
|
|
@@ -1325,12 +1154,11 @@ Received "${apiKey}" instead.`);
|
|
|
1325
1154
|
return id;
|
|
1326
1155
|
}
|
|
1327
1156
|
return [
|
|
1328
|
-
...resources.
|
|
1329
|
-
...resources.
|
|
1330
|
-
...resources.
|
|
1331
|
-
...resources.
|
|
1332
|
-
...resources.
|
|
1333
|
-
...resources.Table.map(parseResourceIds),
|
|
1157
|
+
...resources.swatches.map(parseResourceIds),
|
|
1158
|
+
...resources.files.map(parseResourceIds),
|
|
1159
|
+
...resources.typographies.map(parseResourceIds),
|
|
1160
|
+
...resources.pagePathnameSlices.map(parseResourceIds),
|
|
1161
|
+
...resources.globalElements.map(parseResourceIds),
|
|
1334
1162
|
...resources.snippets.map(parseResourceIds)
|
|
1335
1163
|
];
|
|
1336
1164
|
}
|
|
@@ -1594,8 +1422,101 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1594
1422
|
const client = new Makeswift(apiKey, {
|
|
1595
1423
|
apiOrigin
|
|
1596
1424
|
});
|
|
1425
|
+
const makeswiftApiClient = new MakeswiftClient({ uri: new URL("graphql", apiOrigin).href });
|
|
1426
|
+
async function formMakeswiftResources(publishedResources) {
|
|
1427
|
+
var _a2, _b, _c2, _d, _e, _f, _g;
|
|
1428
|
+
const publishedResourcesInMakeswiftSnapshotFormat = {
|
|
1429
|
+
swatches: [],
|
|
1430
|
+
typographies: [],
|
|
1431
|
+
files: [],
|
|
1432
|
+
pagePathnameSlices: [],
|
|
1433
|
+
globalElements: [],
|
|
1434
|
+
snippets: [],
|
|
1435
|
+
fonts: [],
|
|
1436
|
+
pageMetadata: publishedResources == null ? void 0 : publishedResources.pageMetadata,
|
|
1437
|
+
pageSeo: publishedResources == null ? void 0 : publishedResources.pageSeo
|
|
1438
|
+
};
|
|
1439
|
+
if (publishedResources == null) {
|
|
1440
|
+
return publishedResourcesInMakeswiftSnapshotFormat;
|
|
1441
|
+
}
|
|
1442
|
+
for await (const swatchId of publishedResources.swatches || []) {
|
|
1443
|
+
const swatch = await makeswiftApiClient.fetchSwatch(swatchId);
|
|
1444
|
+
if (swatch != null) {
|
|
1445
|
+
(_a2 = publishedResourcesInMakeswiftSnapshotFormat.swatches) == null ? void 0 : _a2.push({
|
|
1446
|
+
id: swatchId,
|
|
1447
|
+
value: swatch
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
for await (const typographyId of publishedResources.typographies || []) {
|
|
1452
|
+
const typography = await makeswiftApiClient.fetchTypography(typographyId);
|
|
1453
|
+
if (typography != null) {
|
|
1454
|
+
(_b = publishedResourcesInMakeswiftSnapshotFormat.typographies) == null ? void 0 : _b.push({
|
|
1455
|
+
id: typographyId,
|
|
1456
|
+
value: typography
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
for await (const fileId of publishedResources.files || []) {
|
|
1461
|
+
const file = await makeswiftApiClient.fetchFile(fileId);
|
|
1462
|
+
if (file != null) {
|
|
1463
|
+
(_c2 = publishedResourcesInMakeswiftSnapshotFormat.files) == null ? void 0 : _c2.push({
|
|
1464
|
+
id: fileId,
|
|
1465
|
+
value: file
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
for await (const pageId of publishedResources.pagePathnameSlices || []) {
|
|
1470
|
+
const pagePathnameSlice = await makeswiftApiClient.fetchPagePathnameSlice(pageId);
|
|
1471
|
+
if (pagePathnameSlice != null) {
|
|
1472
|
+
(_d = publishedResourcesInMakeswiftSnapshotFormat.pagePathnameSlices) == null ? void 0 : _d.push({
|
|
1473
|
+
id: pageId,
|
|
1474
|
+
value: pagePathnameSlice
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
for await (const globalElementId of publishedResources.globalElements || []) {
|
|
1479
|
+
const globalElement = await makeswiftApiClient.fetchGlobalElement(globalElementId);
|
|
1480
|
+
if (globalElement != null) {
|
|
1481
|
+
(_e = publishedResourcesInMakeswiftSnapshotFormat.globalElements) == null ? void 0 : _e.push({
|
|
1482
|
+
id: globalElementId,
|
|
1483
|
+
value: globalElement
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
if (publishedResources.snippets != null || publishedResources.fonts != null) {
|
|
1488
|
+
const response2 = await fetch(new URL(`/v1/pages/${body.pageId}/document?preview=false`, apiOrigin).toString(), {
|
|
1489
|
+
headers: { ["X-API-Key"]: apiKey }
|
|
1490
|
+
});
|
|
1491
|
+
if (!response2.ok) {
|
|
1492
|
+
throw new Error(`Failed to hit live page endpoint: "${response2.statusText}"`);
|
|
1493
|
+
}
|
|
1494
|
+
const document2 = await response2.json();
|
|
1495
|
+
const availableSnippets = document2.snippets;
|
|
1496
|
+
const availableFonts = document2.fonts;
|
|
1497
|
+
for await (const snippetId of publishedResources.snippets || []) {
|
|
1498
|
+
const snippet = availableSnippets.find((availableSnippet) => availableSnippet.id === snippetId);
|
|
1499
|
+
if (snippet != null) {
|
|
1500
|
+
(_f = publishedResourcesInMakeswiftSnapshotFormat.snippets) == null ? void 0 : _f.push({
|
|
1501
|
+
id: snippetId,
|
|
1502
|
+
value: snippet
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
for await (const family of publishedResources.fonts || []) {
|
|
1507
|
+
const font = availableFonts.find((availableFont) => availableFont.family === family);
|
|
1508
|
+
if (font != null) {
|
|
1509
|
+
(_g = publishedResourcesInMakeswiftSnapshotFormat.fonts) == null ? void 0 : _g.push({
|
|
1510
|
+
id: family,
|
|
1511
|
+
value: font
|
|
1512
|
+
});
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return publishedResourcesInMakeswiftSnapshotFormat;
|
|
1517
|
+
}
|
|
1597
1518
|
const snapshot = await client.unstable_createSnapshot({
|
|
1598
|
-
publishedResources: body.publishedResources,
|
|
1519
|
+
publishedResources: await formMakeswiftResources(body.publishedResources),
|
|
1599
1520
|
deletedResources: body.deletedResources,
|
|
1600
1521
|
publishedElementTree: body.publishedElementTree,
|
|
1601
1522
|
currentSnapshot: body.currentSnapshot
|
|
@@ -1743,37 +1664,6 @@ const Page = memo(({
|
|
|
1743
1664
|
}, snapshot.document.data.key)
|
|
1744
1665
|
});
|
|
1745
1666
|
});
|
|
1746
|
-
const unstable_Page = memo(({
|
|
1747
|
-
pageData
|
|
1748
|
-
}) => {
|
|
1749
|
-
function resourcesToCacheData(resources) {
|
|
1750
|
-
if (resources == null)
|
|
1751
|
-
return void 0;
|
|
1752
|
-
return {
|
|
1753
|
-
Swatch: resources.Swatch,
|
|
1754
|
-
File: resources.File,
|
|
1755
|
-
Typography: resources.Typography,
|
|
1756
|
-
PagePathnameSlice: resources.PagePathnameSlice,
|
|
1757
|
-
GlobalElement: resources.GlobalElement,
|
|
1758
|
-
Table: resources.Table,
|
|
1759
|
-
Snippet: resources.Snippet,
|
|
1760
|
-
Page: resources.Page,
|
|
1761
|
-
Site: resources.Site
|
|
1762
|
-
};
|
|
1763
|
-
}
|
|
1764
|
-
const client = useMemo(() => new MakeswiftClient({
|
|
1765
|
-
uri: new URL("graphql", pageData.options.apiOrigin).href,
|
|
1766
|
-
cacheData: resourcesToCacheData(pageData.snapshot.resources)
|
|
1767
|
-
}), [pageData]);
|
|
1768
|
-
return /* @__PURE__ */ jsx(RuntimeProvider, {
|
|
1769
|
-
client,
|
|
1770
|
-
rootElements: /* @__PURE__ */ new Map([[pageData.pageId, pageData.snapshot.elementTree]]),
|
|
1771
|
-
preview: pageData.options.preview,
|
|
1772
|
-
children: /* @__PURE__ */ jsx(unstable_Page$1, {
|
|
1773
|
-
pageData
|
|
1774
|
-
})
|
|
1775
|
-
});
|
|
1776
|
-
});
|
|
1777
1667
|
const keys = (o) => Object.keys(o);
|
|
1778
1668
|
const coalesce = (...args) => {
|
|
1779
1669
|
let i;
|
|
@@ -4201,5 +4091,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
|
|
|
4201
4091
|
document: document2
|
|
4202
4092
|
});
|
|
4203
4093
|
}));
|
|
4204
|
-
export {
|
|
4094
|
+
export { getServerSideProps as $, Alignments as A, useFile as B, Contrasts as C, DocumentReference as D, Element as E, DEVICES as F, findDeviceOverride as G, forwardNextDynamicRef as H, useIsPreview as I, useFiles as J, useSwatches as K, usePagePathnameSlice as L, useElementId as M, deepEqual as N, storeContextDefaultValue as O, PageProvider as P, StoreContext as Q, RuntimeProvider as R, Shapes as S, MakeswiftProvider as T, useBuilderEditMode as U, pollBoxModel as V, useTypography as W, shallowMergeFallbacks as X, MakeswiftClient as Y, getStaticPaths as Z, getStaticProps as _, ReactRuntime as a, Page as a0, Makeswift as a1, PreviewModeScript as a2, Document$1 as a3, MakeswiftApiHandler as a4, usePageId as b, DEFAULT_BOX_ANIMATE_TYPE as c, DEFAULT_BOX_ANIMATE_DELAY as d, DEFAULT_BOX_ANIMATE_DURATION as e, DEFAULT_ITEM_ANIMATE_TYPE as f, DEFAULT_ITEM_ANIMATE_DELAY as g, DEFAULT_ITEM_ANIMATE_DURATION as h, DEFAULT_ITEM_STAGGER_DURATION as i, useBorder as j, useBoxShadow as k, useResponsiveColor as l, useMediaQuery as m, Page$1 as n, useStyle as o, responsiveWidth as p, responsiveTextStyle as q, responsiveStyle as r, colorToString as s, Sizes as t, useIsInBuilder as u, useFormContext as v, responsiveGridItem as w, useTable as x, useMakeswiftClient as y, Provider as z };
|
|
4205
4095
|
//# sourceMappingURL=index.es.js.map
|