@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.es.js CHANGED
@@ -40,7 +40,7 @@ import { useEffect, createContext, useContext, useState, useMemo, useRef, Childr
40
40
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
41
41
  import dynamic from "next/dynamic";
42
42
  import { g as getPropControllerDescriptors, i as isElementReference, a as getElementSwatchIds, b as getFileIds, d as getTypographyIds, e as getTableIds, f as getPageIds, h as getElementChildren, j as createDocumentReference, M as MakeswiftComponentType, k as getBorderSwatchIds, l as isNonNullable, m as getBoxShadowsSwatchIds, n as getResponsiveColorSwatchIds, o as isPropControllersHandle, p as getComponentPropControllerDescriptors, q as getPropControllers, r as configureStore$1, s as getDocument, t as getElementId, u as getIsPreview, v as getIsInBuilder, w as copyElementTree, x as getReactComponent, y as getBuilderEditMode } from "./constants.es.js";
43
- import { A as ActionTypes, g as introspectedResourcesFulfilled, h as apiResourceFulfilled, t as typographiesFulfilled, j as registerComponentHandleEffect, k as mountComponentEffect, l as registerComponentEffect, n as registerReactComponentEffect } from "./actions.es.js";
43
+ import { A as ActionTypes, h as introspectedResourcesFulfilled, j as apiResourceFulfilled, t as typographiesFulfilled, k as registerComponentHandleEffect, l as mountComponentEffect, n as registerComponentEffect, o as registerReactComponentEffect } from "./actions.es.js";
44
44
  import { cache, cx } from "@emotion/css";
45
45
  import { serializeStyles } from "@emotion/serialize";
46
46
  import { registerStyles, insertStyles } from "@emotion/utils";
@@ -119,6 +119,7 @@ async function introspect(element, client, store) {
119
119
  const tableIds = /* @__PURE__ */ new Set();
120
120
  const pageIds = /* @__PURE__ */ new Set();
121
121
  const remaining = [element];
122
+ const seen = /* @__PURE__ */ new Set();
122
123
  let current;
123
124
  while (current = remaining.pop()) {
124
125
  let getResourcesFromElementDescriptors = function(elementDescriptors2, props) {
@@ -130,7 +131,12 @@ async function introspect(element, client, store) {
130
131
  getTypographyIds(descriptor, props[propName]).forEach((typographyId) => typographyIds.add(typographyId));
131
132
  getTableIds(descriptor, props[propName]).forEach((tableId) => tableIds.add(tableId));
132
133
  getPageIds(descriptor, props[propName]).forEach((pageId) => pageIds.add(pageId));
133
- getElementChildren(descriptor, props[propName]).forEach((child) => remaining.push(child));
134
+ getElementChildren(descriptor, props[propName]).forEach((child) => {
135
+ if (!seen.has(child.key)) {
136
+ seen.add(child.key);
137
+ remaining.push(child);
138
+ }
139
+ });
134
140
  if (descriptor.type === ShapeControlType) {
135
141
  const prop = props[propName];
136
142
  if (prop == null)
@@ -230,6 +236,16 @@ const deepEqual = (a, b) => {
230
236
  }
231
237
  return true;
232
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
+ }
233
249
  function getInitialState(serializedState = {
234
250
  Swatch: [],
235
251
  File: [],
@@ -916,159 +932,6 @@ function Page$1({
916
932
  }, snippet.id))]
917
933
  });
918
934
  }
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
- }
1072
935
  function useCachedPage(pageId) {
1073
936
  const client = useMakeswiftClient();
1074
937
  const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
@@ -1081,7 +944,21 @@ function useCachedSite(siteId) {
1081
944
  const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
1082
945
  return site;
1083
946
  }
1084
- const version = "0.6.5";
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
+ }
1085
962
  class Makeswift {
1086
963
  constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
1087
964
  __publicField(this, "apiKey");
@@ -1140,7 +1017,7 @@ Received "${apiKey}" instead.`);
1140
1017
  if (page == null)
1141
1018
  return null;
1142
1019
  const document2 = await this.getDocumentForPage(page.id);
1143
- const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
1020
+ const snapshot = await this.unstable_createSnapshotOnDemand({ document: document2, pageId: page.id });
1144
1021
  return {
1145
1022
  pageId: page.id,
1146
1023
  siteId: document2.site.id,
@@ -1152,13 +1029,13 @@ Received "${apiKey}" instead.`);
1152
1029
  const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
1153
1030
  if (!response.ok) {
1154
1031
  if (response.status === 404)
1155
- throw Error("bad");
1032
+ throw Error("Document not found.");
1156
1033
  throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
1157
1034
  }
1158
1035
  const document2 = await response.json();
1159
1036
  return document2;
1160
1037
  }
1161
- async unstable_createSnapshotForPage({
1038
+ async unstable_createSnapshotOnDemand({
1162
1039
  document: document2,
1163
1040
  pageId
1164
1041
  }) {
@@ -1178,12 +1055,14 @@ Received "${apiKey}" instead.`);
1178
1055
  }
1179
1056
  const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
1180
1057
  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
- });
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 }));
1187
1066
  return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
1188
1067
  }
1189
1068
  async unstable_createSnapshot({
@@ -1193,33 +1072,15 @@ Received "${apiKey}" instead.`);
1193
1072
  currentSnapshot
1194
1073
  }) {
1195
1074
  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
1075
  function mergeResources({
1215
1076
  resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
1216
1077
  resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
1217
1078
  publishedResources: publishedResources2,
1218
1079
  deletedResources: deletedResources2
1219
1080
  }) {
1220
- function mergeElementTreeResource(resourceSet, deletedResources3) {
1081
+ function mergeIdSpecifiedResource(resourceSet, deletedResources3) {
1221
1082
  const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
1222
- deletedResources3.forEach(({ id }) => map.delete(id));
1083
+ deletedResources3 == null ? void 0 : deletedResources3.forEach((id) => map.delete(id));
1223
1084
  const finalResourceSet = [];
1224
1085
  Array.from(map.entries()).forEach(([id, value]) => {
1225
1086
  if (value != null) {
@@ -1228,80 +1089,54 @@ Received "${apiKey}" instead.`);
1228
1089
  });
1229
1090
  return finalResourceSet;
1230
1091
  }
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
1092
  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,
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([
1282
1119
  ...resourcesFromPublishedElementTree2.snippets,
1120
+ ...resourcesFromCurrentSnapshot2.snippets,
1283
1121
  ...publishedResources2.snippets
1284
- ], deletedResources2.snippets),
1285
- fonts: mergeFonts([
1286
- ...resourcesFromCurrentSnapshot2.fonts,
1122
+ ], deletedResources2 == null ? void 0 : deletedResources2.snippets),
1123
+ fonts: mergeIdSpecifiedResource([
1287
1124
  ...resourcesFromPublishedElementTree2.fonts,
1125
+ ...resourcesFromCurrentSnapshot2.fonts,
1288
1126
  ...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: []
1127
+ ], deletedResources2 == null ? void 0 : deletedResources2.fonts),
1128
+ pageMetadata: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageMetadata), publishedResources2.pageMetadata),
1129
+ pageSeo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageSeo), publishedResources2.pageSeo)
1295
1130
  };
1296
1131
  return resources2;
1297
1132
  }
1298
- const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
1133
+ const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(await client.prefetch(publishedElementTree))) : normalizeToMakeswiftResources({});
1299
1134
  const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
1300
1135
  const resources = mergeResources({
1301
1136
  resourcesFromPublishedElementTree,
1302
1137
  resourcesFromCurrentSnapshot,
1303
1138
  publishedResources: normalizeToMakeswiftResources(publishedResources),
1304
- deletedResources: normalizeToMakeswiftResources(deletedResources)
1139
+ deletedResources
1305
1140
  });
1306
1141
  const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
1307
1142
  if (elementTree == null) {
@@ -1319,12 +1154,11 @@ Received "${apiKey}" instead.`);
1319
1154
  return id;
1320
1155
  }
1321
1156
  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),
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),
1328
1162
  ...resources.snippets.map(parseResourceIds)
1329
1163
  ];
1330
1164
  }
@@ -1500,7 +1334,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
1500
1334
  return res.json({
1501
1335
  version,
1502
1336
  previewMode: true,
1503
- interactionMode: true
1337
+ interactionMode: true,
1338
+ clientSideNavigation: true
1504
1339
  });
1505
1340
  }
1506
1341
  case "revalidate": {
@@ -1587,8 +1422,101 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1587
1422
  const client = new Makeswift(apiKey, {
1588
1423
  apiOrigin
1589
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
+ }
1590
1518
  const snapshot = await client.unstable_createSnapshot({
1591
- publishedResources: body.publishedResources,
1519
+ publishedResources: await formMakeswiftResources(body.publishedResources),
1592
1520
  deletedResources: body.deletedResources,
1593
1521
  publishedElementTree: body.publishedElementTree,
1594
1522
  currentSnapshot: body.currentSnapshot
@@ -1736,37 +1664,6 @@ const Page = memo(({
1736
1664
  }, snapshot.document.data.key)
1737
1665
  });
1738
1666
  });
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
- });
1770
1667
  const keys = (o) => Object.keys(o);
1771
1668
  const coalesce = (...args) => {
1772
1669
  let i;
@@ -4024,6 +3921,7 @@ const DocumentContext = createContext(null);
4024
3921
  function useDocumentKey() {
4025
3922
  return useContext(DocumentContext);
4026
3923
  }
3924
+ const DocumentCyclesContext = createContext([]);
4027
3925
  function useStore() {
4028
3926
  return useContext(StoreContext);
4029
3927
  }
@@ -4095,20 +3993,32 @@ const ElementReference = memo(forwardRef(function ElementReference2({
4095
3993
  const globalElement = useGlobalElement(elementReference.value);
4096
3994
  const globalElementData = globalElement == null ? void 0 : globalElement.data;
4097
3995
  const elementReferenceDocument = useDocument(elementReference.key);
3996
+ const documentKey = elementReference.key;
3997
+ const documentKeys = useContext(DocumentCyclesContext);
3998
+ const providedDocumentKeys = useMemo(() => [...documentKeys, documentKey], [documentKeys, documentKey]);
4098
3999
  if (globalElementData == null) {
4099
4000
  return /* @__PURE__ */ jsx(FallbackComponent, {
4100
4001
  ref,
4101
4002
  text: "This global component doesn't exist"
4102
4003
  });
4103
4004
  }
4104
- return elementReferenceDocument != null ? /* @__PURE__ */ jsx(Document, {
4105
- document: elementReferenceDocument,
4106
- ref
4107
- }) : /* @__PURE__ */ jsx(DisableRegisterElement.Provider, {
4108
- value: true,
4109
- children: /* @__PURE__ */ jsx(ElementData, {
4110
- elementData: globalElementData,
4005
+ if (documentKeys.includes(documentKey)) {
4006
+ return /* @__PURE__ */ jsx(FallbackComponent, {
4007
+ ref,
4008
+ text: "This global component contains itself!"
4009
+ });
4010
+ }
4011
+ return /* @__PURE__ */ jsx(DocumentCyclesContext.Provider, {
4012
+ value: providedDocumentKeys,
4013
+ children: elementReferenceDocument != null ? /* @__PURE__ */ jsx(Document, {
4014
+ document: elementReferenceDocument,
4111
4015
  ref
4016
+ }) : /* @__PURE__ */ jsx(DisableRegisterElement.Provider, {
4017
+ value: true,
4018
+ children: /* @__PURE__ */ jsx(ElementData, {
4019
+ elementData: globalElementData,
4020
+ ref
4021
+ })
4112
4022
  })
4113
4023
  });
4114
4024
  }));
@@ -4181,5 +4091,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
4181
4091
  document: document2
4182
4092
  });
4183
4093
  }));
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 };
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 };
4185
4095
  //# sourceMappingURL=index.es.js.map