@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.es.js
CHANGED
|
@@ -230,14 +230,44 @@ const deepEqual = (a, b) => {
|
|
|
230
230
|
}
|
|
231
231
|
return true;
|
|
232
232
|
};
|
|
233
|
-
function getInitialState(serializedState =
|
|
234
|
-
|
|
233
|
+
function getInitialState(serializedState = {
|
|
234
|
+
Swatch: [],
|
|
235
|
+
File: [],
|
|
236
|
+
Typography: [],
|
|
237
|
+
PagePathnameSlice: [],
|
|
238
|
+
GlobalElement: [],
|
|
239
|
+
Table: [],
|
|
240
|
+
Snippet: [],
|
|
241
|
+
Page: [],
|
|
242
|
+
Site: []
|
|
243
|
+
}) {
|
|
244
|
+
return new Map(Object.entries(serializedState).map(([apiResourceType, resources]) => [
|
|
245
|
+
apiResourceType,
|
|
246
|
+
new Map(resources.map(({ id, value }) => [id, value]))
|
|
247
|
+
]));
|
|
235
248
|
}
|
|
236
249
|
function getSerializedState$1(state) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
const resourceMap = {
|
|
251
|
+
Swatch: [],
|
|
252
|
+
File: [],
|
|
253
|
+
Typography: [],
|
|
254
|
+
PagePathnameSlice: [],
|
|
255
|
+
GlobalElement: [],
|
|
256
|
+
Table: [],
|
|
257
|
+
Snippet: [],
|
|
258
|
+
Page: [],
|
|
259
|
+
Site: []
|
|
260
|
+
};
|
|
261
|
+
Array.from(state.entries()).forEach(([resourceType, resources]) => {
|
|
262
|
+
const particularResourceMap = [];
|
|
263
|
+
Array.from(resources.entries()).forEach(([id, value]) => {
|
|
264
|
+
if (value != null) {
|
|
265
|
+
particularResourceMap.push({ id, value });
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
resourceMap[resourceType] = particularResourceMap;
|
|
269
|
+
});
|
|
270
|
+
return resourceMap;
|
|
241
271
|
}
|
|
242
272
|
function getHasAPIResource$1(state, resourceType, resourceId) {
|
|
243
273
|
var _a, _b;
|
|
@@ -886,6 +916,159 @@ function Page$1({
|
|
|
886
916
|
}, snippet.id))]
|
|
887
917
|
});
|
|
888
918
|
}
|
|
919
|
+
function unstable_Page$1({
|
|
920
|
+
pageData
|
|
921
|
+
}) {
|
|
922
|
+
var _a;
|
|
923
|
+
const isInBuilder = useIsInBuilder();
|
|
924
|
+
const [snippets, setSnippets] = useState(pageData.snapshot.resources.snippets);
|
|
925
|
+
const cachedPage = useCachedPage(isInBuilder ? pageData.pageId : null);
|
|
926
|
+
useEffect(() => {
|
|
927
|
+
if (cachedPage == null)
|
|
928
|
+
return;
|
|
929
|
+
const oldSnippets = snippets.map(filterUsedSnippetProperties);
|
|
930
|
+
const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties);
|
|
931
|
+
if (deepEqual(newSnippets, oldSnippets))
|
|
932
|
+
return;
|
|
933
|
+
setSnippets(cachedPage.snippets);
|
|
934
|
+
}, [cachedPage]);
|
|
935
|
+
const site = useCachedSite(isInBuilder ? pageData.siteId : null);
|
|
936
|
+
const favicon = (_a = pageData.snapshot.resources.meta.favicon) != null ? _a : defaultFavicon;
|
|
937
|
+
const {
|
|
938
|
+
title,
|
|
939
|
+
description,
|
|
940
|
+
keywords,
|
|
941
|
+
socialImage
|
|
942
|
+
} = pageData.snapshot.resources.meta;
|
|
943
|
+
const {
|
|
944
|
+
canonicalUrl,
|
|
945
|
+
isIndexingBlocked
|
|
946
|
+
} = pageData.snapshot.resources.seo;
|
|
947
|
+
const fontFamilyParamValue = useMemo(() => {
|
|
948
|
+
if (site == null) {
|
|
949
|
+
return pageData.snapshot.resources.fonts.map(({
|
|
950
|
+
family,
|
|
951
|
+
variants
|
|
952
|
+
}) => {
|
|
953
|
+
return `${family.replace(/ /g, "+")}:${variants.join()}`;
|
|
954
|
+
}).join("|");
|
|
955
|
+
}
|
|
956
|
+
return site.googleFonts.edges.filter((edge) => edge != null).map(({
|
|
957
|
+
activeVariants,
|
|
958
|
+
node: {
|
|
959
|
+
family,
|
|
960
|
+
variants
|
|
961
|
+
}
|
|
962
|
+
}) => {
|
|
963
|
+
const activeVariantSpecifiers = variants.filter((variant) => activeVariants.some((activeVariant) => activeVariant.specifier === variant.specifier)).map((variant) => variant.specifier).join();
|
|
964
|
+
return `${family.replace(/ /g, "+")}:${activeVariantSpecifiers}`;
|
|
965
|
+
}).join("|");
|
|
966
|
+
}, [site, pageData.snapshot.resources.fonts]);
|
|
967
|
+
const filteredSnippets = useMemo(() => snippets.filter((snippet) => isInBuilder ? snippet.builderEnabled : snippet.liveEnabled), [snippets, isInBuilder]);
|
|
968
|
+
const headSnippets = useMemo(() => filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Head), [filteredSnippets]);
|
|
969
|
+
const previousHeadSnippets = useRef(null);
|
|
970
|
+
useEffect(() => {
|
|
971
|
+
var _a2;
|
|
972
|
+
const headSnippetsToCleanUp = ((_a2 = previousHeadSnippets.current) != null ? _a2 : []).filter((previousSnippet) => previousSnippet.cleanup != null).filter((previousSnippet) => !headSnippets.some((snippet) => previousSnippet.id === snippet.id));
|
|
973
|
+
headSnippetsToCleanUp.forEach((snippetToCleanUp) => {
|
|
974
|
+
if (snippetToCleanUp.cleanup == null)
|
|
975
|
+
return;
|
|
976
|
+
const cleanUp = new Function(snippetToCleanUp.cleanup);
|
|
977
|
+
try {
|
|
978
|
+
cleanUp();
|
|
979
|
+
} catch {
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
previousHeadSnippets.current = headSnippets;
|
|
983
|
+
}, [headSnippets]);
|
|
984
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
985
|
+
children: [/* @__PURE__ */ jsxs(Head, {
|
|
986
|
+
children: [/* @__PURE__ */ jsx("style", {
|
|
987
|
+
children: `
|
|
988
|
+
html {
|
|
989
|
+
font-family: sans-serif;
|
|
990
|
+
}
|
|
991
|
+
div#__next {
|
|
992
|
+
overflow: hidden;
|
|
993
|
+
}
|
|
994
|
+
`
|
|
995
|
+
}), /* @__PURE__ */ jsx("link", {
|
|
996
|
+
rel: "icon",
|
|
997
|
+
type: favicon.mimetype,
|
|
998
|
+
href: favicon.publicUrl
|
|
999
|
+
}), canonicalUrl && /* @__PURE__ */ jsx("link", {
|
|
1000
|
+
rel: "canonical",
|
|
1001
|
+
href: canonicalUrl
|
|
1002
|
+
}), isIndexingBlocked && /* @__PURE__ */ jsx("meta", {
|
|
1003
|
+
name: "robots",
|
|
1004
|
+
content: "noindex"
|
|
1005
|
+
}), title && /* @__PURE__ */ jsxs(Fragment, {
|
|
1006
|
+
children: [/* @__PURE__ */ jsx("title", {
|
|
1007
|
+
children: title
|
|
1008
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1009
|
+
property: "og:title",
|
|
1010
|
+
content: title
|
|
1011
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1012
|
+
name: "twitter:title",
|
|
1013
|
+
content: title
|
|
1014
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1015
|
+
itemProp: "name",
|
|
1016
|
+
content: title
|
|
1017
|
+
})]
|
|
1018
|
+
}), description && /* @__PURE__ */ jsxs(Fragment, {
|
|
1019
|
+
children: [/* @__PURE__ */ jsx("meta", {
|
|
1020
|
+
name: "description",
|
|
1021
|
+
content: description
|
|
1022
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1023
|
+
property: "og:description",
|
|
1024
|
+
content: description
|
|
1025
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1026
|
+
name: "twitter:description",
|
|
1027
|
+
content: description
|
|
1028
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1029
|
+
itemProp: "description",
|
|
1030
|
+
content: description
|
|
1031
|
+
})]
|
|
1032
|
+
}), keywords && /* @__PURE__ */ jsx("meta", {
|
|
1033
|
+
name: "keywords",
|
|
1034
|
+
content: keywords
|
|
1035
|
+
}), socialImage && /* @__PURE__ */ jsxs(Fragment, {
|
|
1036
|
+
children: [/* @__PURE__ */ jsx("meta", {
|
|
1037
|
+
property: "og:image",
|
|
1038
|
+
content: socialImage.publicUrl
|
|
1039
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1040
|
+
property: "og:image:type",
|
|
1041
|
+
content: socialImage.mimetype
|
|
1042
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1043
|
+
name: "twitter:image",
|
|
1044
|
+
content: socialImage.publicUrl
|
|
1045
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1046
|
+
name: "twitter:card",
|
|
1047
|
+
content: "summary_large_image"
|
|
1048
|
+
}), /* @__PURE__ */ jsx("meta", {
|
|
1049
|
+
itemProp: "image",
|
|
1050
|
+
content: socialImage.publicUrl
|
|
1051
|
+
})]
|
|
1052
|
+
}), fontFamilyParamValue !== "" && /* @__PURE__ */ jsx(Fragment, {
|
|
1053
|
+
children: /* @__PURE__ */ jsx("link", {
|
|
1054
|
+
rel: "stylesheet",
|
|
1055
|
+
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
1056
|
+
})
|
|
1057
|
+
}), headSnippets.map(snippetToElement).map((children) => Children.map(children, (child) => {
|
|
1058
|
+
if (typeof child === "string")
|
|
1059
|
+
return child;
|
|
1060
|
+
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
1061
|
+
return child;
|
|
1062
|
+
return null;
|
|
1063
|
+
}))]
|
|
1064
|
+
}), /* @__PURE__ */ jsx(DocumentReference, {
|
|
1065
|
+
documentReference: createDocumentReference(pageData.pageId)
|
|
1066
|
+
}), filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Body).map((snippet) => /* @__PURE__ */ jsx(BodySnippet, {
|
|
1067
|
+
code: snippet.code,
|
|
1068
|
+
cleanup: snippet.cleanup
|
|
1069
|
+
}, snippet.id))]
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
889
1072
|
function useCachedPage(pageId) {
|
|
890
1073
|
const client = useMakeswiftClient();
|
|
891
1074
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -898,6 +1081,7 @@ function useCachedSite(siteId) {
|
|
|
898
1081
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
899
1082
|
return site;
|
|
900
1083
|
}
|
|
1084
|
+
const version = "0.6.5";
|
|
901
1085
|
class Makeswift {
|
|
902
1086
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
903
1087
|
__publicField(this, "apiKey");
|
|
@@ -951,6 +1135,199 @@ Received "${apiKey}" instead.`);
|
|
|
951
1135
|
const snapshot = this.getPageSnapshotByPageId(page.id, { preview });
|
|
952
1136
|
return snapshot;
|
|
953
1137
|
}
|
|
1138
|
+
async unstable_getPageData(path, { preview } = {}) {
|
|
1139
|
+
const [page] = await this.getPages({ path });
|
|
1140
|
+
if (page == null)
|
|
1141
|
+
return null;
|
|
1142
|
+
const document2 = await this.getDocumentForPage(page.id);
|
|
1143
|
+
const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
|
|
1144
|
+
return {
|
|
1145
|
+
pageId: page.id,
|
|
1146
|
+
siteId: document2.site.id,
|
|
1147
|
+
snapshot,
|
|
1148
|
+
options: { preview: preview || false, apiOrigin: this.apiOrigin.href }
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
async getDocumentForPage(pageId) {
|
|
1152
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1153
|
+
if (!response.ok) {
|
|
1154
|
+
if (response.status === 404)
|
|
1155
|
+
throw Error("bad");
|
|
1156
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1157
|
+
}
|
|
1158
|
+
const document2 = await response.json();
|
|
1159
|
+
return document2;
|
|
1160
|
+
}
|
|
1161
|
+
async unstable_createSnapshotForPage({
|
|
1162
|
+
document: document2,
|
|
1163
|
+
pageId
|
|
1164
|
+
}) {
|
|
1165
|
+
let fetchedDocument = document2;
|
|
1166
|
+
if (fetchedDocument == null) {
|
|
1167
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1168
|
+
if (!response.ok) {
|
|
1169
|
+
if (response.status === 404) {
|
|
1170
|
+
throw new Error("Not found");
|
|
1171
|
+
}
|
|
1172
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1173
|
+
}
|
|
1174
|
+
fetchedDocument = await response.json();
|
|
1175
|
+
}
|
|
1176
|
+
if (fetchedDocument == null) {
|
|
1177
|
+
throw Error("fetchedDocument should never be null");
|
|
1178
|
+
}
|
|
1179
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1180
|
+
const prefetchedResources = await client.prefetch(fetchedDocument.data);
|
|
1181
|
+
const resources = __spreadProps(__spreadValues({}, prefetchedResources), {
|
|
1182
|
+
snippets: fetchedDocument.snippets,
|
|
1183
|
+
meta: fetchedDocument.meta,
|
|
1184
|
+
seo: fetchedDocument.seo,
|
|
1185
|
+
fonts: fetchedDocument.fonts
|
|
1186
|
+
});
|
|
1187
|
+
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1188
|
+
}
|
|
1189
|
+
async unstable_createSnapshot({
|
|
1190
|
+
publishedResources,
|
|
1191
|
+
deletedResources,
|
|
1192
|
+
publishedElementTree,
|
|
1193
|
+
currentSnapshot
|
|
1194
|
+
}) {
|
|
1195
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1196
|
+
function normalizeToMakeswiftResources(partialResources) {
|
|
1197
|
+
const resources2 = {
|
|
1198
|
+
Swatch: (partialResources == null ? void 0 : partialResources.Swatch) || [],
|
|
1199
|
+
File: (partialResources == null ? void 0 : partialResources.File) || [],
|
|
1200
|
+
Typography: (partialResources == null ? void 0 : partialResources.Typography) || [],
|
|
1201
|
+
PagePathnameSlice: (partialResources == null ? void 0 : partialResources.PagePathnameSlice) || [],
|
|
1202
|
+
GlobalElement: (partialResources == null ? void 0 : partialResources.GlobalElement) || [],
|
|
1203
|
+
Table: (partialResources == null ? void 0 : partialResources.Table) || [],
|
|
1204
|
+
Snippet: (partialResources == null ? void 0 : partialResources.Snippet) || [],
|
|
1205
|
+
Page: (partialResources == null ? void 0 : partialResources.Page) || [],
|
|
1206
|
+
Site: (partialResources == null ? void 0 : partialResources.Site) || [],
|
|
1207
|
+
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
1208
|
+
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
1209
|
+
meta: (partialResources == null ? void 0 : partialResources.meta) || {},
|
|
1210
|
+
seo: (partialResources == null ? void 0 : partialResources.seo) || {}
|
|
1211
|
+
};
|
|
1212
|
+
return resources2;
|
|
1213
|
+
}
|
|
1214
|
+
function mergeResources({
|
|
1215
|
+
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1216
|
+
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1217
|
+
publishedResources: publishedResources2,
|
|
1218
|
+
deletedResources: deletedResources2
|
|
1219
|
+
}) {
|
|
1220
|
+
function mergeElementTreeResource(resourceSet, deletedResources3) {
|
|
1221
|
+
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1222
|
+
deletedResources3.forEach(({ id }) => map.delete(id));
|
|
1223
|
+
const finalResourceSet = [];
|
|
1224
|
+
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1225
|
+
if (value != null) {
|
|
1226
|
+
finalResourceSet.push({ id, value });
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
return finalResourceSet;
|
|
1230
|
+
}
|
|
1231
|
+
function mergeSnippets(snippets, deletedSnippet) {
|
|
1232
|
+
const map = new Map(snippets.map((value) => [value.id, value]));
|
|
1233
|
+
deletedSnippet.forEach(({ id }) => map.delete(id));
|
|
1234
|
+
const uniqueSnippets = [];
|
|
1235
|
+
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1236
|
+
uniqueSnippets.push(value);
|
|
1237
|
+
});
|
|
1238
|
+
return uniqueSnippets;
|
|
1239
|
+
}
|
|
1240
|
+
function mergeFonts(fonts, deletedFonts) {
|
|
1241
|
+
const map = new Map(fonts.map((value) => [value.family, value]));
|
|
1242
|
+
deletedFonts.forEach(({ family }) => map.delete(family));
|
|
1243
|
+
const uniqueFonts = [];
|
|
1244
|
+
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1245
|
+
uniqueFonts.push(value);
|
|
1246
|
+
});
|
|
1247
|
+
return uniqueFonts;
|
|
1248
|
+
}
|
|
1249
|
+
const resources2 = {
|
|
1250
|
+
Swatch: mergeElementTreeResource([
|
|
1251
|
+
...resourcesFromPublishedElementTree2.Swatch,
|
|
1252
|
+
...resourcesFromCurrentSnapshot2.Swatch,
|
|
1253
|
+
...publishedResources2.Swatch
|
|
1254
|
+
], deletedResources2.Swatch),
|
|
1255
|
+
File: mergeElementTreeResource([
|
|
1256
|
+
...resourcesFromPublishedElementTree2.File,
|
|
1257
|
+
...resourcesFromCurrentSnapshot2.File,
|
|
1258
|
+
...publishedResources2.File
|
|
1259
|
+
], deletedResources2.File),
|
|
1260
|
+
Typography: mergeElementTreeResource([
|
|
1261
|
+
...resourcesFromPublishedElementTree2.Typography,
|
|
1262
|
+
...resourcesFromCurrentSnapshot2.Typography,
|
|
1263
|
+
...publishedResources2.Typography
|
|
1264
|
+
], deletedResources2.Typography),
|
|
1265
|
+
PagePathnameSlice: mergeElementTreeResource([
|
|
1266
|
+
...resourcesFromPublishedElementTree2.PagePathnameSlice,
|
|
1267
|
+
...resourcesFromCurrentSnapshot2.PagePathnameSlice,
|
|
1268
|
+
...publishedResources2.PagePathnameSlice
|
|
1269
|
+
], deletedResources2.PagePathnameSlice),
|
|
1270
|
+
GlobalElement: mergeElementTreeResource([
|
|
1271
|
+
...resourcesFromPublishedElementTree2.GlobalElement,
|
|
1272
|
+
...resourcesFromCurrentSnapshot2.GlobalElement,
|
|
1273
|
+
...publishedResources2.GlobalElement
|
|
1274
|
+
], deletedResources2.GlobalElement),
|
|
1275
|
+
Table: mergeElementTreeResource([
|
|
1276
|
+
...resourcesFromPublishedElementTree2.Table,
|
|
1277
|
+
...resourcesFromCurrentSnapshot2.Table,
|
|
1278
|
+
...publishedResources2.Table
|
|
1279
|
+
], deletedResources2.Table),
|
|
1280
|
+
snippets: mergeSnippets([
|
|
1281
|
+
...resourcesFromCurrentSnapshot2.snippets,
|
|
1282
|
+
...resourcesFromPublishedElementTree2.snippets,
|
|
1283
|
+
...publishedResources2.snippets
|
|
1284
|
+
], deletedResources2.snippets),
|
|
1285
|
+
fonts: mergeFonts([
|
|
1286
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1287
|
+
...resourcesFromPublishedElementTree2.fonts,
|
|
1288
|
+
...publishedResources2.fonts
|
|
1289
|
+
], deletedResources2.fonts),
|
|
1290
|
+
meta: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.meta), publishedResources2.meta),
|
|
1291
|
+
seo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.seo), publishedResources2.seo),
|
|
1292
|
+
Snippet: [],
|
|
1293
|
+
Page: [],
|
|
1294
|
+
Site: []
|
|
1295
|
+
};
|
|
1296
|
+
return resources2;
|
|
1297
|
+
}
|
|
1298
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1299
|
+
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1300
|
+
const resources = mergeResources({
|
|
1301
|
+
resourcesFromPublishedElementTree,
|
|
1302
|
+
resourcesFromCurrentSnapshot,
|
|
1303
|
+
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1304
|
+
deletedResources: normalizeToMakeswiftResources(deletedResources)
|
|
1305
|
+
});
|
|
1306
|
+
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1307
|
+
if (elementTree == null) {
|
|
1308
|
+
throw Error("elementTree should not be null; something went wrong.");
|
|
1309
|
+
}
|
|
1310
|
+
return {
|
|
1311
|
+
resources,
|
|
1312
|
+
elementTree,
|
|
1313
|
+
runtimeVersion: version
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
unstable_getSnapshotResourceMapping(snapshot) {
|
|
1317
|
+
const resources = snapshot.resources;
|
|
1318
|
+
function parseResourceIds({ id }) {
|
|
1319
|
+
return id;
|
|
1320
|
+
}
|
|
1321
|
+
return [
|
|
1322
|
+
...resources.Swatch.map(parseResourceIds),
|
|
1323
|
+
...resources.File.map(parseResourceIds),
|
|
1324
|
+
...resources.Typography.map(parseResourceIds),
|
|
1325
|
+
...resources.PagePathnameSlice.map(parseResourceIds),
|
|
1326
|
+
...resources.GlobalElement.map(parseResourceIds),
|
|
1327
|
+
...resources.Table.map(parseResourceIds),
|
|
1328
|
+
...resources.snippets.map(parseResourceIds)
|
|
1329
|
+
];
|
|
1330
|
+
}
|
|
954
1331
|
}
|
|
955
1332
|
function PreviewModeScript({
|
|
956
1333
|
isPreview = false,
|
|
@@ -1079,11 +1456,14 @@ class Document$1 extends NextDocument {
|
|
|
1079
1456
|
});
|
|
1080
1457
|
}
|
|
1081
1458
|
}
|
|
1082
|
-
const version = "0.6.4";
|
|
1083
1459
|
function isErrorWithMessage(error) {
|
|
1084
1460
|
return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
|
|
1085
1461
|
}
|
|
1086
|
-
function MakeswiftApiHandler(apiKey, {
|
|
1462
|
+
function MakeswiftApiHandler(apiKey, {
|
|
1463
|
+
appOrigin = "https://app.makeswift.com",
|
|
1464
|
+
apiOrigin = "https://api.makeswift.com",
|
|
1465
|
+
getFonts
|
|
1466
|
+
} = {}) {
|
|
1087
1467
|
const cors = Cors({ origin: appOrigin });
|
|
1088
1468
|
const previewModeProxy = createProxyServer();
|
|
1089
1469
|
previewModeProxy.on("proxyReq", (proxyReq) => {
|
|
@@ -1193,6 +1573,35 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1193
1573
|
const response = { elementTree: generatedElementTree };
|
|
1194
1574
|
return res.json(response);
|
|
1195
1575
|
}
|
|
1576
|
+
case "snapshot": {
|
|
1577
|
+
let validateBody = function(body2) {
|
|
1578
|
+
if (body2.pageId == null) {
|
|
1579
|
+
return res.status(400).json({ message: "Must define pageId." });
|
|
1580
|
+
}
|
|
1581
|
+
if (body2.currentSnapshot == null && body2.publishedElementTree == null) {
|
|
1582
|
+
return res.status(400).json({ message: "Either currentSnapshot or publishedElementTree must be defined." });
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
const body = req.body;
|
|
1586
|
+
validateBody(body);
|
|
1587
|
+
const client = new Makeswift(apiKey, {
|
|
1588
|
+
apiOrigin
|
|
1589
|
+
});
|
|
1590
|
+
const snapshot = await client.unstable_createSnapshot({
|
|
1591
|
+
publishedResources: body.publishedResources,
|
|
1592
|
+
deletedResources: body.deletedResources,
|
|
1593
|
+
publishedElementTree: body.publishedElementTree,
|
|
1594
|
+
currentSnapshot: body.currentSnapshot
|
|
1595
|
+
});
|
|
1596
|
+
const usedResources = client.unstable_getSnapshotResourceMapping(snapshot);
|
|
1597
|
+
const response = {
|
|
1598
|
+
pageId: body.pageId,
|
|
1599
|
+
snapshot,
|
|
1600
|
+
livePageChanges: body.livePageChanges,
|
|
1601
|
+
usedResources
|
|
1602
|
+
};
|
|
1603
|
+
return res.json(response);
|
|
1604
|
+
}
|
|
1196
1605
|
default:
|
|
1197
1606
|
return res.status(404).json({ message: "Not Found" });
|
|
1198
1607
|
}
|
|
@@ -1327,6 +1736,37 @@ const Page = memo(({
|
|
|
1327
1736
|
}, snapshot.document.data.key)
|
|
1328
1737
|
});
|
|
1329
1738
|
});
|
|
1739
|
+
const unstable_Page = memo(({
|
|
1740
|
+
pageData
|
|
1741
|
+
}) => {
|
|
1742
|
+
function resourcesToCacheData(resources) {
|
|
1743
|
+
if (resources == null)
|
|
1744
|
+
return void 0;
|
|
1745
|
+
return {
|
|
1746
|
+
Swatch: resources.Swatch,
|
|
1747
|
+
File: resources.File,
|
|
1748
|
+
Typography: resources.Typography,
|
|
1749
|
+
PagePathnameSlice: resources.PagePathnameSlice,
|
|
1750
|
+
GlobalElement: resources.GlobalElement,
|
|
1751
|
+
Table: resources.Table,
|
|
1752
|
+
Snippet: resources.Snippet,
|
|
1753
|
+
Page: resources.Page,
|
|
1754
|
+
Site: resources.Site
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
const client = useMemo(() => new MakeswiftClient({
|
|
1758
|
+
uri: new URL("graphql", pageData.options.apiOrigin).href,
|
|
1759
|
+
cacheData: resourcesToCacheData(pageData.snapshot.resources)
|
|
1760
|
+
}), [pageData]);
|
|
1761
|
+
return /* @__PURE__ */ jsx(RuntimeProvider, {
|
|
1762
|
+
client,
|
|
1763
|
+
rootElements: /* @__PURE__ */ new Map([[pageData.pageId, pageData.snapshot.elementTree]]),
|
|
1764
|
+
preview: pageData.options.preview,
|
|
1765
|
+
children: /* @__PURE__ */ jsx(unstable_Page$1, {
|
|
1766
|
+
pageData
|
|
1767
|
+
})
|
|
1768
|
+
});
|
|
1769
|
+
});
|
|
1330
1770
|
const keys = (o) => Object.keys(o);
|
|
1331
1771
|
const coalesce = (...args) => {
|
|
1332
1772
|
let i;
|
|
@@ -3741,5 +4181,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
|
|
|
3741
4181
|
document: document2
|
|
3742
4182
|
});
|
|
3743
4183
|
}));
|
|
3744
|
-
export {
|
|
4184
|
+
export { getStaticProps as $, Provider as A, Alignments as B, Contrasts as C, DocumentReference as D, Element as E, useFile as F, DEVICES as G, findDeviceOverride as H, forwardNextDynamicRef as I, useIsPreview as J, useFiles as K, useSwatches as L, usePagePathnameSlice as M, useElementId as N, deepEqual as O, PageProvider as P, storeContextDefaultValue as Q, RuntimeProvider as R, Shapes as S, StoreContext as T, MakeswiftProvider as U, useBuilderEditMode as V, pollBoxModel as W, useTypography as X, shallowMergeFallbacks as Y, MakeswiftClient as Z, getStaticPaths as _, ReactRuntime as a, getServerSideProps as a0, Page as a1, unstable_Page as a2, Makeswift as a3, PreviewModeScript as a4, Document$1 as a5, MakeswiftApiHandler as a6, 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, unstable_Page$1 as o, useStyle as p, responsiveWidth as q, responsiveStyle as r, responsiveTextStyle as s, colorToString as t, useIsInBuilder as u, Sizes as v, useFormContext as w, responsiveGridItem as x, useTable as y, useMakeswiftClient as z };
|
|
3745
4185
|
//# sourceMappingURL=index.es.js.map
|