@makeswift/runtime 0.6.5 → 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.
Files changed (64) 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.es.js +1 -1
  10. package/dist/LiveProvider.es.js +1 -1
  11. package/dist/Navigation.es.js +1 -1
  12. package/dist/PreviewProvider.cjs.js +15 -0
  13. package/dist/PreviewProvider.cjs.js.map +1 -1
  14. package/dist/PreviewProvider.es.js +16 -2
  15. package/dist/PreviewProvider.es.js.map +1 -1
  16. package/dist/ReadOnlyText.cjs.js +32 -3
  17. package/dist/ReadOnlyText.cjs.js.map +1 -1
  18. package/dist/ReadOnlyText.es.js +33 -4
  19. package/dist/ReadOnlyText.es.js.map +1 -1
  20. package/dist/Root.es.js +1 -1
  21. package/dist/SocialLinks.es.js +1 -1
  22. package/dist/Text.es.js +1 -1
  23. package/dist/Video.es.js +1 -1
  24. package/dist/actions.cjs.js +23 -1
  25. package/dist/actions.cjs.js.map +1 -1
  26. package/dist/actions.es.js +21 -2
  27. package/dist/actions.es.js.map +1 -1
  28. package/dist/components.cjs.js +0 -1
  29. package/dist/components.cjs.js.map +1 -1
  30. package/dist/components.es.js +1 -1
  31. package/dist/index.cjs.js +201 -293
  32. package/dist/index.cjs.js.map +1 -1
  33. package/dist/index.es.js +203 -293
  34. package/dist/index.es.js.map +1 -1
  35. package/dist/index.es2.js +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/main.cjs.js +1 -0
  40. package/dist/main.cjs.js.map +1 -1
  41. package/dist/main.es.js +1 -1
  42. package/dist/next.cjs.js +0 -1
  43. package/dist/next.cjs.js.map +1 -1
  44. package/dist/next.es.js +1 -1
  45. package/dist/types/src/api/introspection.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/index.d.ts +1 -1
  49. package/dist/types/src/index.d.ts.map +1 -1
  50. package/dist/types/src/next/api-handler.d.ts +1 -0
  51. package/dist/types/src/next/api-handler.d.ts.map +1 -1
  52. package/dist/types/src/next/client.d.ts +18 -16
  53. package/dist/types/src/next/client.d.ts.map +1 -1
  54. package/dist/types/src/next/index.d.ts +0 -1
  55. package/dist/types/src/next/index.d.ts.map +1 -1
  56. package/dist/types/src/next/snapshots.d.ts +100 -0
  57. package/dist/types/src/next/snapshots.d.ts.map +1 -0
  58. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  59. package/dist/types/src/state/actions.d.ts +19 -1
  60. package/dist/types/src/state/actions.d.ts.map +1 -1
  61. package/dist/types/src/state/modules/api-resources.d.ts +2 -0
  62. package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
  63. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  64. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -154,6 +154,7 @@ async function introspect(element, client, store) {
154
154
  const tableIds = /* @__PURE__ */ new Set();
155
155
  const pageIds = /* @__PURE__ */ new Set();
156
156
  const remaining = [element];
157
+ const seen = /* @__PURE__ */ new Set();
157
158
  let current;
158
159
  while (current = remaining.pop()) {
159
160
  let getResourcesFromElementDescriptors = function(elementDescriptors2, props) {
@@ -165,7 +166,12 @@ async function introspect(element, client, store) {
165
166
  constants.getTypographyIds(descriptor, props[propName]).forEach((typographyId) => typographyIds.add(typographyId));
166
167
  constants.getTableIds(descriptor, props[propName]).forEach((tableId) => tableIds.add(tableId));
167
168
  constants.getPageIds(descriptor, props[propName]).forEach((pageId) => pageIds.add(pageId));
168
- constants.getElementChildren(descriptor, props[propName]).forEach((child) => remaining.push(child));
169
+ constants.getElementChildren(descriptor, props[propName]).forEach((child) => {
170
+ if (!seen.has(child.key)) {
171
+ seen.add(child.key);
172
+ remaining.push(child);
173
+ }
174
+ });
169
175
  if (descriptor.type === control.ShapeControlType) {
170
176
  const prop = props[propName];
171
177
  if (prop == null)
@@ -265,6 +271,16 @@ const deepEqual = (a, b) => {
265
271
  }
266
272
  return true;
267
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
+ }
268
284
  function getInitialState(serializedState = {
269
285
  Swatch: [],
270
286
  File: [],
@@ -951,159 +967,6 @@ function Page$1({
951
967
  }, snippet.id))]
952
968
  });
953
969
  }
954
- function unstable_Page$1({
955
- pageData
956
- }) {
957
- var _a;
958
- const isInBuilder = useIsInBuilder();
959
- const [snippets, setSnippets] = React.useState(pageData.snapshot.resources.snippets);
960
- const cachedPage = useCachedPage(isInBuilder ? pageData.pageId : null);
961
- React.useEffect(() => {
962
- if (cachedPage == null)
963
- return;
964
- const oldSnippets = snippets.map(filterUsedSnippetProperties);
965
- const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties);
966
- if (deepEqual(newSnippets, oldSnippets))
967
- return;
968
- setSnippets(cachedPage.snippets);
969
- }, [cachedPage]);
970
- const site = useCachedSite(isInBuilder ? pageData.siteId : null);
971
- const favicon = (_a = pageData.snapshot.resources.meta.favicon) != null ? _a : defaultFavicon;
972
- const {
973
- title,
974
- description,
975
- keywords,
976
- socialImage
977
- } = pageData.snapshot.resources.meta;
978
- const {
979
- canonicalUrl,
980
- isIndexingBlocked
981
- } = pageData.snapshot.resources.seo;
982
- const fontFamilyParamValue = React.useMemo(() => {
983
- if (site == null) {
984
- return pageData.snapshot.resources.fonts.map(({
985
- family,
986
- variants
987
- }) => {
988
- return `${family.replace(/ /g, "+")}:${variants.join()}`;
989
- }).join("|");
990
- }
991
- return site.googleFonts.edges.filter((edge) => edge != null).map(({
992
- activeVariants,
993
- node: {
994
- family,
995
- variants
996
- }
997
- }) => {
998
- const activeVariantSpecifiers = variants.filter((variant) => activeVariants.some((activeVariant) => activeVariant.specifier === variant.specifier)).map((variant) => variant.specifier).join();
999
- return `${family.replace(/ /g, "+")}:${activeVariantSpecifiers}`;
1000
- }).join("|");
1001
- }, [site, pageData.snapshot.resources.fonts]);
1002
- const filteredSnippets = React.useMemo(() => snippets.filter((snippet) => isInBuilder ? snippet.builderEnabled : snippet.liveEnabled), [snippets, isInBuilder]);
1003
- const headSnippets = React.useMemo(() => filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Head), [filteredSnippets]);
1004
- const previousHeadSnippets = React.useRef(null);
1005
- React.useEffect(() => {
1006
- var _a2;
1007
- const headSnippetsToCleanUp = ((_a2 = previousHeadSnippets.current) != null ? _a2 : []).filter((previousSnippet) => previousSnippet.cleanup != null).filter((previousSnippet) => !headSnippets.some((snippet) => previousSnippet.id === snippet.id));
1008
- headSnippetsToCleanUp.forEach((snippetToCleanUp) => {
1009
- if (snippetToCleanUp.cleanup == null)
1010
- return;
1011
- const cleanUp = new Function(snippetToCleanUp.cleanup);
1012
- try {
1013
- cleanUp();
1014
- } catch {
1015
- }
1016
- });
1017
- previousHeadSnippets.current = headSnippets;
1018
- }, [headSnippets]);
1019
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1020
- children: [/* @__PURE__ */ jsxRuntime.jsxs(Head__default["default"], {
1021
- children: [/* @__PURE__ */ jsxRuntime.jsx("style", {
1022
- children: `
1023
- html {
1024
- font-family: sans-serif;
1025
- }
1026
- div#__next {
1027
- overflow: hidden;
1028
- }
1029
- `
1030
- }), /* @__PURE__ */ jsxRuntime.jsx("link", {
1031
- rel: "icon",
1032
- type: favicon.mimetype,
1033
- href: favicon.publicUrl
1034
- }), canonicalUrl && /* @__PURE__ */ jsxRuntime.jsx("link", {
1035
- rel: "canonical",
1036
- href: canonicalUrl
1037
- }), isIndexingBlocked && /* @__PURE__ */ jsxRuntime.jsx("meta", {
1038
- name: "robots",
1039
- content: "noindex"
1040
- }), title && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1041
- children: [/* @__PURE__ */ jsxRuntime.jsx("title", {
1042
- children: title
1043
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1044
- property: "og:title",
1045
- content: title
1046
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1047
- name: "twitter:title",
1048
- content: title
1049
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1050
- itemProp: "name",
1051
- content: title
1052
- })]
1053
- }), description && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1054
- children: [/* @__PURE__ */ jsxRuntime.jsx("meta", {
1055
- name: "description",
1056
- content: description
1057
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1058
- property: "og:description",
1059
- content: description
1060
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1061
- name: "twitter:description",
1062
- content: description
1063
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1064
- itemProp: "description",
1065
- content: description
1066
- })]
1067
- }), keywords && /* @__PURE__ */ jsxRuntime.jsx("meta", {
1068
- name: "keywords",
1069
- content: keywords
1070
- }), socialImage && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1071
- children: [/* @__PURE__ */ jsxRuntime.jsx("meta", {
1072
- property: "og:image",
1073
- content: socialImage.publicUrl
1074
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1075
- property: "og:image:type",
1076
- content: socialImage.mimetype
1077
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1078
- name: "twitter:image",
1079
- content: socialImage.publicUrl
1080
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1081
- name: "twitter:card",
1082
- content: "summary_large_image"
1083
- }), /* @__PURE__ */ jsxRuntime.jsx("meta", {
1084
- itemProp: "image",
1085
- content: socialImage.publicUrl
1086
- })]
1087
- }), fontFamilyParamValue !== "" && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
1088
- children: /* @__PURE__ */ jsxRuntime.jsx("link", {
1089
- rel: "stylesheet",
1090
- href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
1091
- })
1092
- }), headSnippets.map(snippetToElement).map((children) => React.Children.map(children, (child) => {
1093
- if (typeof child === "string")
1094
- return child;
1095
- if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
1096
- return child;
1097
- return null;
1098
- }))]
1099
- }), /* @__PURE__ */ jsxRuntime.jsx(DocumentReference, {
1100
- documentReference: constants.createDocumentReference(pageData.pageId)
1101
- }), filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Body).map((snippet) => /* @__PURE__ */ jsxRuntime.jsx(BodySnippet, {
1102
- code: snippet.code,
1103
- cleanup: snippet.cleanup
1104
- }, snippet.id))]
1105
- });
1106
- }
1107
970
  function useCachedPage(pageId) {
1108
971
  const client = useMakeswiftClient();
1109
972
  const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
@@ -1116,7 +979,21 @@ function useCachedSite(siteId) {
1116
979
  const site = shim.useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
1117
980
  return site;
1118
981
  }
1119
- const version = "0.6.5";
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
+ }
1120
997
  class Makeswift {
1121
998
  constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
1122
999
  __publicField(this, "apiKey");
@@ -1175,7 +1052,7 @@ Received "${apiKey}" instead.`);
1175
1052
  if (page == null)
1176
1053
  return null;
1177
1054
  const document2 = await this.getDocumentForPage(page.id);
1178
- const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
1055
+ const snapshot = await this.unstable_createSnapshotOnDemand({ document: document2, pageId: page.id });
1179
1056
  return {
1180
1057
  pageId: page.id,
1181
1058
  siteId: document2.site.id,
@@ -1187,13 +1064,13 @@ Received "${apiKey}" instead.`);
1187
1064
  const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
1188
1065
  if (!response.ok) {
1189
1066
  if (response.status === 404)
1190
- throw Error("bad");
1067
+ throw Error("Document not found.");
1191
1068
  throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
1192
1069
  }
1193
1070
  const document2 = await response.json();
1194
1071
  return document2;
1195
1072
  }
1196
- async unstable_createSnapshotForPage({
1073
+ async unstable_createSnapshotOnDemand({
1197
1074
  document: document2,
1198
1075
  pageId
1199
1076
  }) {
@@ -1213,12 +1090,14 @@ Received "${apiKey}" instead.`);
1213
1090
  }
1214
1091
  const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
1215
1092
  const prefetchedResources = await client.prefetch(fetchedDocument.data);
1216
- const resources = __spreadProps(__spreadValues({}, prefetchedResources), {
1217
- snippets: fetchedDocument.snippets,
1218
- meta: fetchedDocument.meta,
1219
- seo: fetchedDocument.seo,
1220
- fonts: fetchedDocument.fonts
1221
- });
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 }));
1222
1101
  return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
1223
1102
  }
1224
1103
  async unstable_createSnapshot({
@@ -1228,33 +1107,15 @@ Received "${apiKey}" instead.`);
1228
1107
  currentSnapshot
1229
1108
  }) {
1230
1109
  const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
1231
- function normalizeToMakeswiftResources(partialResources) {
1232
- const resources2 = {
1233
- Swatch: (partialResources == null ? void 0 : partialResources.Swatch) || [],
1234
- File: (partialResources == null ? void 0 : partialResources.File) || [],
1235
- Typography: (partialResources == null ? void 0 : partialResources.Typography) || [],
1236
- PagePathnameSlice: (partialResources == null ? void 0 : partialResources.PagePathnameSlice) || [],
1237
- GlobalElement: (partialResources == null ? void 0 : partialResources.GlobalElement) || [],
1238
- Table: (partialResources == null ? void 0 : partialResources.Table) || [],
1239
- Snippet: (partialResources == null ? void 0 : partialResources.Snippet) || [],
1240
- Page: (partialResources == null ? void 0 : partialResources.Page) || [],
1241
- Site: (partialResources == null ? void 0 : partialResources.Site) || [],
1242
- snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
1243
- fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
1244
- meta: (partialResources == null ? void 0 : partialResources.meta) || {},
1245
- seo: (partialResources == null ? void 0 : partialResources.seo) || {}
1246
- };
1247
- return resources2;
1248
- }
1249
1110
  function mergeResources({
1250
1111
  resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
1251
1112
  resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
1252
1113
  publishedResources: publishedResources2,
1253
1114
  deletedResources: deletedResources2
1254
1115
  }) {
1255
- function mergeElementTreeResource(resourceSet, deletedResources3) {
1116
+ function mergeIdSpecifiedResource(resourceSet, deletedResources3) {
1256
1117
  const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
1257
- deletedResources3.forEach(({ id }) => map.delete(id));
1118
+ deletedResources3 == null ? void 0 : deletedResources3.forEach((id) => map.delete(id));
1258
1119
  const finalResourceSet = [];
1259
1120
  Array.from(map.entries()).forEach(([id, value]) => {
1260
1121
  if (value != null) {
@@ -1263,80 +1124,54 @@ Received "${apiKey}" instead.`);
1263
1124
  });
1264
1125
  return finalResourceSet;
1265
1126
  }
1266
- function mergeSnippets(snippets, deletedSnippet) {
1267
- const map = new Map(snippets.map((value) => [value.id, value]));
1268
- deletedSnippet.forEach(({ id }) => map.delete(id));
1269
- const uniqueSnippets = [];
1270
- Array.from(map.entries()).forEach(([_, value]) => {
1271
- uniqueSnippets.push(value);
1272
- });
1273
- return uniqueSnippets;
1274
- }
1275
- function mergeFonts(fonts, deletedFonts) {
1276
- const map = new Map(fonts.map((value) => [value.family, value]));
1277
- deletedFonts.forEach(({ family }) => map.delete(family));
1278
- const uniqueFonts = [];
1279
- Array.from(map.entries()).forEach(([_, value]) => {
1280
- uniqueFonts.push(value);
1281
- });
1282
- return uniqueFonts;
1283
- }
1284
1127
  const resources2 = {
1285
- Swatch: mergeElementTreeResource([
1286
- ...resourcesFromPublishedElementTree2.Swatch,
1287
- ...resourcesFromCurrentSnapshot2.Swatch,
1288
- ...publishedResources2.Swatch
1289
- ], deletedResources2.Swatch),
1290
- File: mergeElementTreeResource([
1291
- ...resourcesFromPublishedElementTree2.File,
1292
- ...resourcesFromCurrentSnapshot2.File,
1293
- ...publishedResources2.File
1294
- ], deletedResources2.File),
1295
- Typography: mergeElementTreeResource([
1296
- ...resourcesFromPublishedElementTree2.Typography,
1297
- ...resourcesFromCurrentSnapshot2.Typography,
1298
- ...publishedResources2.Typography
1299
- ], deletedResources2.Typography),
1300
- PagePathnameSlice: mergeElementTreeResource([
1301
- ...resourcesFromPublishedElementTree2.PagePathnameSlice,
1302
- ...resourcesFromCurrentSnapshot2.PagePathnameSlice,
1303
- ...publishedResources2.PagePathnameSlice
1304
- ], deletedResources2.PagePathnameSlice),
1305
- GlobalElement: mergeElementTreeResource([
1306
- ...resourcesFromPublishedElementTree2.GlobalElement,
1307
- ...resourcesFromCurrentSnapshot2.GlobalElement,
1308
- ...publishedResources2.GlobalElement
1309
- ], deletedResources2.GlobalElement),
1310
- Table: mergeElementTreeResource([
1311
- ...resourcesFromPublishedElementTree2.Table,
1312
- ...resourcesFromCurrentSnapshot2.Table,
1313
- ...publishedResources2.Table
1314
- ], deletedResources2.Table),
1315
- snippets: mergeSnippets([
1316
- ...resourcesFromCurrentSnapshot2.snippets,
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([
1317
1154
  ...resourcesFromPublishedElementTree2.snippets,
1155
+ ...resourcesFromCurrentSnapshot2.snippets,
1318
1156
  ...publishedResources2.snippets
1319
- ], deletedResources2.snippets),
1320
- fonts: mergeFonts([
1321
- ...resourcesFromCurrentSnapshot2.fonts,
1157
+ ], deletedResources2 == null ? void 0 : deletedResources2.snippets),
1158
+ fonts: mergeIdSpecifiedResource([
1322
1159
  ...resourcesFromPublishedElementTree2.fonts,
1160
+ ...resourcesFromCurrentSnapshot2.fonts,
1323
1161
  ...publishedResources2.fonts
1324
- ], deletedResources2.fonts),
1325
- meta: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.meta), publishedResources2.meta),
1326
- seo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.seo), publishedResources2.seo),
1327
- Snippet: [],
1328
- Page: [],
1329
- Site: []
1162
+ ], deletedResources2 == null ? void 0 : deletedResources2.fonts),
1163
+ pageMetadata: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageMetadata), publishedResources2.pageMetadata),
1164
+ pageSeo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageSeo), publishedResources2.pageSeo)
1330
1165
  };
1331
1166
  return resources2;
1332
1167
  }
1333
- const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
1168
+ const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(await client.prefetch(publishedElementTree))) : normalizeToMakeswiftResources({});
1334
1169
  const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
1335
1170
  const resources = mergeResources({
1336
1171
  resourcesFromPublishedElementTree,
1337
1172
  resourcesFromCurrentSnapshot,
1338
1173
  publishedResources: normalizeToMakeswiftResources(publishedResources),
1339
- deletedResources: normalizeToMakeswiftResources(deletedResources)
1174
+ deletedResources
1340
1175
  });
1341
1176
  const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
1342
1177
  if (elementTree == null) {
@@ -1354,12 +1189,11 @@ Received "${apiKey}" instead.`);
1354
1189
  return id;
1355
1190
  }
1356
1191
  return [
1357
- ...resources.Swatch.map(parseResourceIds),
1358
- ...resources.File.map(parseResourceIds),
1359
- ...resources.Typography.map(parseResourceIds),
1360
- ...resources.PagePathnameSlice.map(parseResourceIds),
1361
- ...resources.GlobalElement.map(parseResourceIds),
1362
- ...resources.Table.map(parseResourceIds),
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),
1363
1197
  ...resources.snippets.map(parseResourceIds)
1364
1198
  ];
1365
1199
  }
@@ -1535,7 +1369,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
1535
1369
  return res.json({
1536
1370
  version,
1537
1371
  previewMode: true,
1538
- interactionMode: true
1372
+ interactionMode: true,
1373
+ clientSideNavigation: true
1539
1374
  });
1540
1375
  }
1541
1376
  case "revalidate": {
@@ -1622,8 +1457,101 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1622
1457
  const client = new Makeswift(apiKey, {
1623
1458
  apiOrigin
1624
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
+ }
1625
1553
  const snapshot = await client.unstable_createSnapshot({
1626
- publishedResources: body.publishedResources,
1554
+ publishedResources: await formMakeswiftResources(body.publishedResources),
1627
1555
  deletedResources: body.deletedResources,
1628
1556
  publishedElementTree: body.publishedElementTree,
1629
1557
  currentSnapshot: body.currentSnapshot
@@ -1771,37 +1699,6 @@ const Page = React.memo(({
1771
1699
  }, snapshot.document.data.key)
1772
1700
  });
1773
1701
  });
1774
- const unstable_Page = React.memo(({
1775
- pageData
1776
- }) => {
1777
- function resourcesToCacheData(resources) {
1778
- if (resources == null)
1779
- return void 0;
1780
- return {
1781
- Swatch: resources.Swatch,
1782
- File: resources.File,
1783
- Typography: resources.Typography,
1784
- PagePathnameSlice: resources.PagePathnameSlice,
1785
- GlobalElement: resources.GlobalElement,
1786
- Table: resources.Table,
1787
- Snippet: resources.Snippet,
1788
- Page: resources.Page,
1789
- Site: resources.Site
1790
- };
1791
- }
1792
- const client = React.useMemo(() => new MakeswiftClient({
1793
- uri: new URL("graphql", pageData.options.apiOrigin).href,
1794
- cacheData: resourcesToCacheData(pageData.snapshot.resources)
1795
- }), [pageData]);
1796
- return /* @__PURE__ */ jsxRuntime.jsx(RuntimeProvider, {
1797
- client,
1798
- rootElements: /* @__PURE__ */ new Map([[pageData.pageId, pageData.snapshot.elementTree]]),
1799
- preview: pageData.options.preview,
1800
- children: /* @__PURE__ */ jsxRuntime.jsx(unstable_Page$1, {
1801
- pageData
1802
- })
1803
- });
1804
- });
1805
1702
  const keys = (o) => Object.keys(o);
1806
1703
  const coalesce = (...args) => {
1807
1704
  let i;
@@ -4091,6 +3988,7 @@ const DocumentContext = React.createContext(null);
4091
3988
  function useDocumentKey() {
4092
3989
  return React.useContext(DocumentContext);
4093
3990
  }
3991
+ const DocumentCyclesContext = React.createContext([]);
4094
3992
  function useStore() {
4095
3993
  return React.useContext(StoreContext);
4096
3994
  }
@@ -4162,20 +4060,32 @@ const ElementReference = React.memo(React.forwardRef(function ElementReference2(
4162
4060
  const globalElement = useGlobalElement(elementReference.value);
4163
4061
  const globalElementData = globalElement == null ? void 0 : globalElement.data;
4164
4062
  const elementReferenceDocument = useDocument(elementReference.key);
4063
+ const documentKey = elementReference.key;
4064
+ const documentKeys = React.useContext(DocumentCyclesContext);
4065
+ const providedDocumentKeys = React.useMemo(() => [...documentKeys, documentKey], [documentKeys, documentKey]);
4165
4066
  if (globalElementData == null) {
4166
4067
  return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {
4167
4068
  ref,
4168
4069
  text: "This global component doesn't exist"
4169
4070
  });
4170
4071
  }
4171
- return elementReferenceDocument != null ? /* @__PURE__ */ jsxRuntime.jsx(Document, {
4172
- document: elementReferenceDocument,
4173
- ref
4174
- }) : /* @__PURE__ */ jsxRuntime.jsx(DisableRegisterElement.Provider, {
4175
- value: true,
4176
- children: /* @__PURE__ */ jsxRuntime.jsx(ElementData, {
4177
- elementData: globalElementData,
4072
+ if (documentKeys.includes(documentKey)) {
4073
+ return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {
4074
+ ref,
4075
+ text: "This global component contains itself!"
4076
+ });
4077
+ }
4078
+ return /* @__PURE__ */ jsxRuntime.jsx(DocumentCyclesContext.Provider, {
4079
+ value: providedDocumentKeys,
4080
+ children: elementReferenceDocument != null ? /* @__PURE__ */ jsxRuntime.jsx(Document, {
4081
+ document: elementReferenceDocument,
4178
4082
  ref
4083
+ }) : /* @__PURE__ */ jsxRuntime.jsx(DisableRegisterElement.Provider, {
4084
+ value: true,
4085
+ children: /* @__PURE__ */ jsxRuntime.jsx(ElementData, {
4086
+ elementData: globalElementData,
4087
+ ref
4088
+ })
4179
4089
  })
4180
4090
  });
4181
4091
  }));
@@ -4289,8 +4199,6 @@ exports.responsiveTextStyle = responsiveTextStyle;
4289
4199
  exports.responsiveWidth = responsiveWidth;
4290
4200
  exports.shallowMergeFallbacks = shallowMergeFallbacks;
4291
4201
  exports.storeContextDefaultValue = storeContextDefaultValue;
4292
- exports.unstable_Page = unstable_Page$1;
4293
- exports.unstable_Page$1 = unstable_Page;
4294
4202
  exports.useBorder = useBorder;
4295
4203
  exports.useBoxShadow = useBoxShadow;
4296
4204
  exports.useBuilderEditMode = useBuilderEditMode;