@makeswift/runtime 0.6.6 → 0.7.0

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.
Files changed (57) hide show
  1. package/dist/Box.es.js +1 -1
  2. package/dist/Button.es.js +1 -1
  3. package/dist/Carousel.es.js +1 -1
  4. package/dist/Countdown.es.js +1 -1
  5. package/dist/Divider.es.js +1 -1
  6. package/dist/EditableText.es.js +1 -1
  7. package/dist/Embed.es.js +1 -1
  8. package/dist/Form.es.js +1 -1
  9. package/dist/Image.cjs.js +2 -2
  10. package/dist/Image.cjs.js.map +1 -1
  11. package/dist/Image.es.js +3 -3
  12. package/dist/Image.es.js.map +1 -1
  13. package/dist/LiveProvider.es.js +1 -1
  14. package/dist/Navigation.es.js +1 -1
  15. package/dist/PreviewProvider.es.js +1 -1
  16. package/dist/ReadOnlyText.es.js +1 -1
  17. package/dist/Root.es.js +1 -1
  18. package/dist/SocialLinks.es.js +1 -1
  19. package/dist/Text.es.js +1 -1
  20. package/dist/Video.es.js +1 -1
  21. package/dist/api.cjs.js +1 -1
  22. package/dist/api.cjs.js.map +1 -1
  23. package/dist/api.es.js +1 -1
  24. package/dist/api.es.js.map +1 -1
  25. package/dist/components.cjs.js +0 -1
  26. package/dist/components.cjs.js.map +1 -1
  27. package/dist/components.es.js +1 -1
  28. package/dist/index.cjs.js +182 -287
  29. package/dist/index.cjs.js.map +1 -1
  30. package/dist/index.cjs2.js +1 -1
  31. package/dist/index.cjs2.js.map +1 -1
  32. package/dist/index.es.js +187 -290
  33. package/dist/index.es.js.map +1 -1
  34. package/dist/index.es2.js +2 -2
  35. package/dist/index.es2.js.map +1 -1
  36. package/dist/index.es3.js +1 -1
  37. package/dist/index.es4.js +1 -1
  38. package/dist/index.es6.js +1 -1
  39. package/dist/next.cjs.js +0 -1
  40. package/dist/next.cjs.js.map +1 -1
  41. package/dist/next.es.js +1 -1
  42. package/dist/types/src/api/graphql/documents/fragments.d.ts +1 -1
  43. package/dist/types/src/api/graphql/documents/fragments.d.ts.map +1 -1
  44. package/dist/types/src/api/graphql/generated/types.d.ts +3 -3
  45. package/dist/types/src/api/graphql/generated/types.d.ts.map +1 -1
  46. package/dist/types/src/components/page/Page.d.ts +1 -5
  47. package/dist/types/src/components/page/Page.d.ts.map +1 -1
  48. package/dist/types/src/next/api-handler.d.ts.map +1 -1
  49. package/dist/types/src/next/client.d.ts +18 -16
  50. package/dist/types/src/next/client.d.ts.map +1 -1
  51. package/dist/types/src/next/index.d.ts +0 -1
  52. package/dist/types/src/next/index.d.ts.map +1 -1
  53. package/dist/types/src/next/snapshots.d.ts +102 -0
  54. package/dist/types/src/next/snapshots.d.ts.map +1 -0
  55. package/dist/types/src/state/modules/api-resources.d.ts +2 -0
  56. package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
  57. package/package.json +2 -2
package/dist/index.cjs.js CHANGED
@@ -234,6 +234,24 @@ async function introspect(element, client, store) {
234
234
  pageIds: [...pageIds]
235
235
  };
236
236
  }
237
+ function normalizeToMakeswiftResources(partialResources) {
238
+ const resources = {
239
+ swatches: (partialResources == null ? void 0 : partialResources.swatches) || [],
240
+ typographies: (partialResources == null ? void 0 : partialResources.typographies) || [],
241
+ files: (partialResources == null ? void 0 : partialResources.files) || [],
242
+ pagePathnameSlices: (partialResources == null ? void 0 : partialResources.pagePathnameSlices) || [],
243
+ globalElements: (partialResources == null ? void 0 : partialResources.globalElements) || [],
244
+ snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
245
+ fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
246
+ pageMetadata: (partialResources == null ? void 0 : partialResources.pageMetadata) || {},
247
+ pageSeo: (partialResources == null ? void 0 : partialResources.pageSeo) || {}
248
+ };
249
+ return resources;
250
+ }
251
+ function fileToFileSnapshot(file) {
252
+ const _a = file, { publicUrlV2 } = _a, restOfFile = __objRest(_a, ["publicUrlV2"]);
253
+ return __spreadProps(__spreadValues({}, restOfFile), { publicUrl: publicUrlV2 });
254
+ }
237
255
  function is(x, y) {
238
256
  if (x === y)
239
257
  return x !== 0 || y !== 0 || 1 / x === 1 / y;
@@ -271,6 +289,19 @@ const deepEqual = (a, b) => {
271
289
  }
272
290
  return true;
273
291
  };
292
+ function isNonNullable(value) {
293
+ return value != null;
294
+ }
295
+ function getSnapshotResourcesFromSerializedState(serializedState) {
296
+ const resources = {
297
+ swatches: serializedState.Swatch.filter((_) => true),
298
+ typographies: serializedState.Typography.filter((_) => true),
299
+ files: serializedState.File.map(({ id, value }) => value.__typename === types.APIResourceType.File ? { id, value: fileToFileSnapshot(value) } : null).filter(isNonNullable),
300
+ pagePathnameSlices: serializedState.PagePathnameSlice.filter((_) => true),
301
+ globalElements: serializedState.GlobalElement.filter((_) => true)
302
+ };
303
+ return resources;
304
+ }
274
305
  function getInitialState(serializedState = {
275
306
  Swatch: [],
276
307
  File: [],
@@ -394,7 +425,7 @@ const FileFragment = `
394
425
  __typename
395
426
  id
396
427
  name
397
- publicUrl
428
+ publicUrlV2
398
429
  extension
399
430
  dimensions {
400
431
  width
@@ -957,159 +988,6 @@ function Page$1({
957
988
  }, snippet.id))]
958
989
  });
959
990
  }
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
991
  function useCachedPage(pageId) {
1114
992
  const client = useMakeswiftClient();
1115
993
  const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
@@ -1122,7 +1000,7 @@ function useCachedSite(siteId) {
1122
1000
  const site = shim.useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
1123
1001
  return site;
1124
1002
  }
1125
- const version = "0.6.6";
1003
+ const version = "0.7.0";
1126
1004
  class Makeswift {
1127
1005
  constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
1128
1006
  __publicField(this, "apiKey");
@@ -1181,7 +1059,7 @@ Received "${apiKey}" instead.`);
1181
1059
  if (page == null)
1182
1060
  return null;
1183
1061
  const document2 = await this.getDocumentForPage(page.id);
1184
- const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
1062
+ const snapshot = await this.unstable_createSnapshotOnDemand({ document: document2, pageId: page.id });
1185
1063
  return {
1186
1064
  pageId: page.id,
1187
1065
  siteId: document2.site.id,
@@ -1193,13 +1071,13 @@ Received "${apiKey}" instead.`);
1193
1071
  const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
1194
1072
  if (!response.ok) {
1195
1073
  if (response.status === 404)
1196
- throw Error("bad");
1074
+ throw Error("Document not found.");
1197
1075
  throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
1198
1076
  }
1199
1077
  const document2 = await response.json();
1200
1078
  return document2;
1201
1079
  }
1202
- async unstable_createSnapshotForPage({
1080
+ async unstable_createSnapshotOnDemand({
1203
1081
  document: document2,
1204
1082
  pageId
1205
1083
  }) {
@@ -1219,12 +1097,14 @@ Received "${apiKey}" instead.`);
1219
1097
  }
1220
1098
  const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
1221
1099
  const prefetchedResources = await client.prefetch(fetchedDocument.data);
1222
- const resources = __spreadProps(__spreadValues({}, prefetchedResources), {
1223
- snippets: fetchedDocument.snippets,
1224
- meta: fetchedDocument.meta,
1225
- seo: fetchedDocument.seo,
1226
- fonts: fetchedDocument.fonts
1227
- });
1100
+ const resources = normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(prefetchedResources));
1101
+ resources.snippets = fetchedDocument.snippets.map((snippet) => ({
1102
+ id: snippet.id,
1103
+ value: snippet
1104
+ }));
1105
+ resources.pageMetadata = fetchedDocument.meta;
1106
+ resources.pageSeo = fetchedDocument.seo;
1107
+ resources.fonts = fetchedDocument.fonts.map((font) => ({ id: font.family, value: font }));
1228
1108
  return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
1229
1109
  }
1230
1110
  async unstable_createSnapshot({
@@ -1234,33 +1114,15 @@ Received "${apiKey}" instead.`);
1234
1114
  currentSnapshot
1235
1115
  }) {
1236
1116
  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
1117
  function mergeResources({
1256
1118
  resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
1257
1119
  resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
1258
1120
  publishedResources: publishedResources2,
1259
1121
  deletedResources: deletedResources2
1260
1122
  }) {
1261
- function mergeElementTreeResource(resourceSet, deletedResources3) {
1123
+ function mergeIdSpecifiedResource(resourceSet, deletedResources3) {
1262
1124
  const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
1263
- deletedResources3.forEach(({ id }) => map.delete(id));
1125
+ deletedResources3 == null ? void 0 : deletedResources3.forEach((id) => map.delete(id));
1264
1126
  const finalResourceSet = [];
1265
1127
  Array.from(map.entries()).forEach(([id, value]) => {
1266
1128
  if (value != null) {
@@ -1269,80 +1131,54 @@ Received "${apiKey}" instead.`);
1269
1131
  });
1270
1132
  return finalResourceSet;
1271
1133
  }
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
1134
  const resources2 = {
1291
- Swatch: mergeElementTreeResource([
1292
- ...resourcesFromPublishedElementTree2.Swatch,
1293
- ...resourcesFromCurrentSnapshot2.Swatch,
1294
- ...publishedResources2.Swatch
1295
- ], deletedResources2.Swatch),
1296
- File: mergeElementTreeResource([
1297
- ...resourcesFromPublishedElementTree2.File,
1298
- ...resourcesFromCurrentSnapshot2.File,
1299
- ...publishedResources2.File
1300
- ], deletedResources2.File),
1301
- Typography: mergeElementTreeResource([
1302
- ...resourcesFromPublishedElementTree2.Typography,
1303
- ...resourcesFromCurrentSnapshot2.Typography,
1304
- ...publishedResources2.Typography
1305
- ], deletedResources2.Typography),
1306
- PagePathnameSlice: mergeElementTreeResource([
1307
- ...resourcesFromPublishedElementTree2.PagePathnameSlice,
1308
- ...resourcesFromCurrentSnapshot2.PagePathnameSlice,
1309
- ...publishedResources2.PagePathnameSlice
1310
- ], deletedResources2.PagePathnameSlice),
1311
- GlobalElement: mergeElementTreeResource([
1312
- ...resourcesFromPublishedElementTree2.GlobalElement,
1313
- ...resourcesFromCurrentSnapshot2.GlobalElement,
1314
- ...publishedResources2.GlobalElement
1315
- ], deletedResources2.GlobalElement),
1316
- Table: mergeElementTreeResource([
1317
- ...resourcesFromPublishedElementTree2.Table,
1318
- ...resourcesFromCurrentSnapshot2.Table,
1319
- ...publishedResources2.Table
1320
- ], deletedResources2.Table),
1321
- snippets: mergeSnippets([
1322
- ...resourcesFromCurrentSnapshot2.snippets,
1135
+ swatches: mergeIdSpecifiedResource([
1136
+ ...resourcesFromPublishedElementTree2.swatches,
1137
+ ...resourcesFromCurrentSnapshot2.swatches,
1138
+ ...publishedResources2.swatches
1139
+ ], deletedResources2 == null ? void 0 : deletedResources2.swatches),
1140
+ files: mergeIdSpecifiedResource([
1141
+ ...resourcesFromPublishedElementTree2.files,
1142
+ ...resourcesFromCurrentSnapshot2.files,
1143
+ ...publishedResources2.files
1144
+ ], deletedResources2 == null ? void 0 : deletedResources2.files),
1145
+ typographies: mergeIdSpecifiedResource([
1146
+ ...resourcesFromPublishedElementTree2.typographies,
1147
+ ...resourcesFromCurrentSnapshot2.typographies,
1148
+ ...publishedResources2.typographies
1149
+ ], deletedResources2 == null ? void 0 : deletedResources2.typographies),
1150
+ pagePathnameSlices: mergeIdSpecifiedResource([
1151
+ ...resourcesFromPublishedElementTree2.pagePathnameSlices,
1152
+ ...resourcesFromCurrentSnapshot2.pagePathnameSlices,
1153
+ ...publishedResources2.pagePathnameSlices
1154
+ ], deletedResources2 == null ? void 0 : deletedResources2.pagePathnameSlices),
1155
+ globalElements: mergeIdSpecifiedResource([
1156
+ ...resourcesFromPublishedElementTree2.globalElements,
1157
+ ...resourcesFromCurrentSnapshot2.globalElements,
1158
+ ...publishedResources2.globalElements
1159
+ ], deletedResources2 == null ? void 0 : deletedResources2.globalElements),
1160
+ snippets: mergeIdSpecifiedResource([
1323
1161
  ...resourcesFromPublishedElementTree2.snippets,
1162
+ ...resourcesFromCurrentSnapshot2.snippets,
1324
1163
  ...publishedResources2.snippets
1325
- ], deletedResources2.snippets),
1326
- fonts: mergeFonts([
1327
- ...resourcesFromCurrentSnapshot2.fonts,
1164
+ ], deletedResources2 == null ? void 0 : deletedResources2.snippets),
1165
+ fonts: mergeIdSpecifiedResource([
1328
1166
  ...resourcesFromPublishedElementTree2.fonts,
1167
+ ...resourcesFromCurrentSnapshot2.fonts,
1329
1168
  ...publishedResources2.fonts
1330
- ], deletedResources2.fonts),
1331
- meta: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.meta), publishedResources2.meta),
1332
- seo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.seo), publishedResources2.seo),
1333
- Snippet: [],
1334
- Page: [],
1335
- Site: []
1169
+ ], deletedResources2 == null ? void 0 : deletedResources2.fonts),
1170
+ pageMetadata: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageMetadata), publishedResources2.pageMetadata),
1171
+ pageSeo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageSeo), publishedResources2.pageSeo)
1336
1172
  };
1337
1173
  return resources2;
1338
1174
  }
1339
- const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
1175
+ const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(await client.prefetch(publishedElementTree))) : normalizeToMakeswiftResources({});
1340
1176
  const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
1341
1177
  const resources = mergeResources({
1342
1178
  resourcesFromPublishedElementTree,
1343
1179
  resourcesFromCurrentSnapshot,
1344
1180
  publishedResources: normalizeToMakeswiftResources(publishedResources),
1345
- deletedResources: normalizeToMakeswiftResources(deletedResources)
1181
+ deletedResources
1346
1182
  });
1347
1183
  const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
1348
1184
  if (elementTree == null) {
@@ -1360,12 +1196,11 @@ Received "${apiKey}" instead.`);
1360
1196
  return id;
1361
1197
  }
1362
1198
  return [
1363
- ...resources.Swatch.map(parseResourceIds),
1364
- ...resources.File.map(parseResourceIds),
1365
- ...resources.Typography.map(parseResourceIds),
1366
- ...resources.PagePathnameSlice.map(parseResourceIds),
1367
- ...resources.GlobalElement.map(parseResourceIds),
1368
- ...resources.Table.map(parseResourceIds),
1199
+ ...resources.swatches.map(parseResourceIds),
1200
+ ...resources.files.map(parseResourceIds),
1201
+ ...resources.typographies.map(parseResourceIds),
1202
+ ...resources.pagePathnameSlices.map(parseResourceIds),
1203
+ ...resources.globalElements.map(parseResourceIds),
1369
1204
  ...resources.snippets.map(parseResourceIds)
1370
1205
  ];
1371
1206
  }
@@ -1629,8 +1464,101 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1629
1464
  const client = new Makeswift(apiKey, {
1630
1465
  apiOrigin
1631
1466
  });
1467
+ const makeswiftApiClient = new MakeswiftClient({ uri: new URL("graphql", apiOrigin).href });
1468
+ async function formMakeswiftResources(publishedResources) {
1469
+ var _a2, _b, _c2, _d, _e, _f, _g;
1470
+ const publishedResourcesInMakeswiftSnapshotFormat = {
1471
+ swatches: [],
1472
+ typographies: [],
1473
+ files: [],
1474
+ pagePathnameSlices: [],
1475
+ globalElements: [],
1476
+ snippets: [],
1477
+ fonts: [],
1478
+ pageMetadata: publishedResources == null ? void 0 : publishedResources.pageMetadata,
1479
+ pageSeo: publishedResources == null ? void 0 : publishedResources.pageSeo
1480
+ };
1481
+ if (publishedResources == null) {
1482
+ return publishedResourcesInMakeswiftSnapshotFormat;
1483
+ }
1484
+ for await (const swatchId of publishedResources.swatches || []) {
1485
+ const swatch = await makeswiftApiClient.fetchSwatch(swatchId);
1486
+ if (swatch != null) {
1487
+ (_a2 = publishedResourcesInMakeswiftSnapshotFormat.swatches) == null ? void 0 : _a2.push({
1488
+ id: swatchId,
1489
+ value: swatch
1490
+ });
1491
+ }
1492
+ }
1493
+ for await (const typographyId of publishedResources.typographies || []) {
1494
+ const typography = await makeswiftApiClient.fetchTypography(typographyId);
1495
+ if (typography != null) {
1496
+ (_b = publishedResourcesInMakeswiftSnapshotFormat.typographies) == null ? void 0 : _b.push({
1497
+ id: typographyId,
1498
+ value: typography
1499
+ });
1500
+ }
1501
+ }
1502
+ for await (const fileId of publishedResources.files || []) {
1503
+ const file = await makeswiftApiClient.fetchFile(fileId);
1504
+ if (file != null) {
1505
+ (_c2 = publishedResourcesInMakeswiftSnapshotFormat.files) == null ? void 0 : _c2.push({
1506
+ id: fileId,
1507
+ value: fileToFileSnapshot(file)
1508
+ });
1509
+ }
1510
+ }
1511
+ for await (const pageId of publishedResources.pagePathnameSlices || []) {
1512
+ const pagePathnameSlice = await makeswiftApiClient.fetchPagePathnameSlice(pageId);
1513
+ if (pagePathnameSlice != null) {
1514
+ (_d = publishedResourcesInMakeswiftSnapshotFormat.pagePathnameSlices) == null ? void 0 : _d.push({
1515
+ id: pageId,
1516
+ value: pagePathnameSlice
1517
+ });
1518
+ }
1519
+ }
1520
+ for await (const globalElementId of publishedResources.globalElements || []) {
1521
+ const globalElement = await makeswiftApiClient.fetchGlobalElement(globalElementId);
1522
+ if (globalElement != null) {
1523
+ (_e = publishedResourcesInMakeswiftSnapshotFormat.globalElements) == null ? void 0 : _e.push({
1524
+ id: globalElementId,
1525
+ value: globalElement
1526
+ });
1527
+ }
1528
+ }
1529
+ if (publishedResources.snippets != null || publishedResources.fonts != null) {
1530
+ const response2 = await fetch(new URL(`/v1/pages/${body.pageId}/document?preview=false`, apiOrigin).toString(), {
1531
+ headers: { ["X-API-Key"]: apiKey }
1532
+ });
1533
+ if (!response2.ok) {
1534
+ throw new Error(`Failed to hit live page endpoint: "${response2.statusText}"`);
1535
+ }
1536
+ const document2 = await response2.json();
1537
+ const availableSnippets = document2.snippets;
1538
+ const availableFonts = document2.fonts;
1539
+ for await (const snippetId of publishedResources.snippets || []) {
1540
+ const snippet = availableSnippets.find((availableSnippet) => availableSnippet.id === snippetId);
1541
+ if (snippet != null) {
1542
+ (_f = publishedResourcesInMakeswiftSnapshotFormat.snippets) == null ? void 0 : _f.push({
1543
+ id: snippetId,
1544
+ value: snippet
1545
+ });
1546
+ }
1547
+ }
1548
+ for await (const family of publishedResources.fonts || []) {
1549
+ const font = availableFonts.find((availableFont) => availableFont.family === family);
1550
+ if (font != null) {
1551
+ (_g = publishedResourcesInMakeswiftSnapshotFormat.fonts) == null ? void 0 : _g.push({
1552
+ id: family,
1553
+ value: font
1554
+ });
1555
+ }
1556
+ }
1557
+ }
1558
+ return publishedResourcesInMakeswiftSnapshotFormat;
1559
+ }
1632
1560
  const snapshot = await client.unstable_createSnapshot({
1633
- publishedResources: body.publishedResources,
1561
+ publishedResources: await formMakeswiftResources(body.publishedResources),
1634
1562
  deletedResources: body.deletedResources,
1635
1563
  publishedElementTree: body.publishedElementTree,
1636
1564
  currentSnapshot: body.currentSnapshot
@@ -1778,37 +1706,6 @@ const Page = React.memo(({
1778
1706
  }, snapshot.document.data.key)
1779
1707
  });
1780
1708
  });
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
1709
  const keys = (o) => Object.keys(o);
1813
1710
  const coalesce = (...args) => {
1814
1711
  let i;
@@ -3424,12 +3321,12 @@ function useImageControlValue(data, definition) {
3424
3321
  const fileId = data != null ? data : null;
3425
3322
  const file = useFile(fileId);
3426
3323
  if (format === richText.ImageControlValueFormat.URL) {
3427
- return file == null ? void 0 : file.publicUrl;
3324
+ return file == null ? void 0 : file.publicUrlV2;
3428
3325
  }
3429
3326
  if (file == null || file.dimensions == null)
3430
3327
  return void 0;
3431
3328
  return {
3432
- url: file.publicUrl,
3329
+ url: file.publicUrlV2,
3433
3330
  dimensions: { width: file.dimensions.width, height: file.dimensions.height }
3434
3331
  };
3435
3332
  }
@@ -4309,8 +4206,6 @@ exports.responsiveTextStyle = responsiveTextStyle;
4309
4206
  exports.responsiveWidth = responsiveWidth;
4310
4207
  exports.shallowMergeFallbacks = shallowMergeFallbacks;
4311
4208
  exports.storeContextDefaultValue = storeContextDefaultValue;
4312
- exports.unstable_Page = unstable_Page$1;
4313
- exports.unstable_Page$1 = unstable_Page;
4314
4209
  exports.useBorder = useBorder;
4315
4210
  exports.useBoxShadow = useBoxShadow;
4316
4211
  exports.useBuilderEditMode = useBuilderEditMode;