@makeswift/runtime 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Box.es.js +1 -1
- package/dist/Button.es.js +1 -1
- package/dist/Carousel.es.js +1 -1
- package/dist/Countdown.es.js +1 -1
- package/dist/Divider.es.js +1 -1
- package/dist/EditableText.es.js +1 -1
- package/dist/Embed.es.js +1 -1
- package/dist/Form.es.js +1 -1
- package/dist/Image.es.js +1 -1
- package/dist/LiveProvider.es.js +1 -1
- package/dist/Navigation.es.js +1 -1
- package/dist/PreviewProvider.cjs.js +15 -0
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +16 -2
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/ReadOnlyText.cjs.js +32 -3
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +33 -4
- package/dist/ReadOnlyText.es.js.map +1 -1
- package/dist/Root.es.js +1 -1
- package/dist/SocialLinks.es.js +1 -1
- package/dist/Text.es.js +1 -1
- package/dist/Video.es.js +1 -1
- package/dist/actions.cjs.js +23 -1
- package/dist/actions.cjs.js.map +1 -1
- package/dist/actions.es.js +21 -2
- package/dist/actions.es.js.map +1 -1
- package/dist/components.cjs.js +1 -0
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +1 -1
- package/dist/index.cjs.js +479 -17
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +479 -19
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +1 -1
- package/dist/index.es3.js +1 -1
- package/dist/index.es4.js +1 -1
- package/dist/index.es6.js +1 -1
- package/dist/main.cjs.js +1 -0
- package/dist/main.cjs.js.map +1 -1
- package/dist/main.es.js +1 -1
- package/dist/next.cjs.js +1 -0
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +1 -1
- package/dist/types/src/api/introspection.d.ts.map +1 -1
- package/dist/types/src/components/page/Page.d.ts +5 -1
- package/dist/types/src/components/page/Page.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/next/api-handler.d.ts +14 -2
- package/dist/types/src/next/api-handler.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +69 -32
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts +5 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/state/actions.d.ts +19 -1
- package/dist/types/src/state/actions.d.ts.map +1 -1
- package/dist/types/src/state/modules/api-resources.d.ts +6 -2
- package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
- package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
- 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) =>
|
|
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,14 +271,44 @@ const deepEqual = (a, b) => {
|
|
|
265
271
|
}
|
|
266
272
|
return true;
|
|
267
273
|
};
|
|
268
|
-
function getInitialState(serializedState =
|
|
269
|
-
|
|
274
|
+
function getInitialState(serializedState = {
|
|
275
|
+
Swatch: [],
|
|
276
|
+
File: [],
|
|
277
|
+
Typography: [],
|
|
278
|
+
PagePathnameSlice: [],
|
|
279
|
+
GlobalElement: [],
|
|
280
|
+
Table: [],
|
|
281
|
+
Snippet: [],
|
|
282
|
+
Page: [],
|
|
283
|
+
Site: []
|
|
284
|
+
}) {
|
|
285
|
+
return new Map(Object.entries(serializedState).map(([apiResourceType, resources]) => [
|
|
286
|
+
apiResourceType,
|
|
287
|
+
new Map(resources.map(({ id, value }) => [id, value]))
|
|
288
|
+
]));
|
|
270
289
|
}
|
|
271
290
|
function getSerializedState$1(state) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
291
|
+
const resourceMap = {
|
|
292
|
+
Swatch: [],
|
|
293
|
+
File: [],
|
|
294
|
+
Typography: [],
|
|
295
|
+
PagePathnameSlice: [],
|
|
296
|
+
GlobalElement: [],
|
|
297
|
+
Table: [],
|
|
298
|
+
Snippet: [],
|
|
299
|
+
Page: [],
|
|
300
|
+
Site: []
|
|
301
|
+
};
|
|
302
|
+
Array.from(state.entries()).forEach(([resourceType, resources]) => {
|
|
303
|
+
const particularResourceMap = [];
|
|
304
|
+
Array.from(resources.entries()).forEach(([id, value]) => {
|
|
305
|
+
if (value != null) {
|
|
306
|
+
particularResourceMap.push({ id, value });
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
resourceMap[resourceType] = particularResourceMap;
|
|
310
|
+
});
|
|
311
|
+
return resourceMap;
|
|
276
312
|
}
|
|
277
313
|
function getHasAPIResource$1(state, resourceType, resourceId) {
|
|
278
314
|
var _a, _b;
|
|
@@ -921,6 +957,159 @@ function Page$1({
|
|
|
921
957
|
}, snippet.id))]
|
|
922
958
|
});
|
|
923
959
|
}
|
|
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
|
+
}
|
|
924
1113
|
function useCachedPage(pageId) {
|
|
925
1114
|
const client = useMakeswiftClient();
|
|
926
1115
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -933,6 +1122,7 @@ function useCachedSite(siteId) {
|
|
|
933
1122
|
const site = shim.useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
934
1123
|
return site;
|
|
935
1124
|
}
|
|
1125
|
+
const version = "0.6.6";
|
|
936
1126
|
class Makeswift {
|
|
937
1127
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
938
1128
|
__publicField(this, "apiKey");
|
|
@@ -986,6 +1176,199 @@ Received "${apiKey}" instead.`);
|
|
|
986
1176
|
const snapshot = this.getPageSnapshotByPageId(page.id, { preview });
|
|
987
1177
|
return snapshot;
|
|
988
1178
|
}
|
|
1179
|
+
async unstable_getPageData(path, { preview } = {}) {
|
|
1180
|
+
const [page] = await this.getPages({ path });
|
|
1181
|
+
if (page == null)
|
|
1182
|
+
return null;
|
|
1183
|
+
const document2 = await this.getDocumentForPage(page.id);
|
|
1184
|
+
const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
|
|
1185
|
+
return {
|
|
1186
|
+
pageId: page.id,
|
|
1187
|
+
siteId: document2.site.id,
|
|
1188
|
+
snapshot,
|
|
1189
|
+
options: { preview: preview || false, apiOrigin: this.apiOrigin.href }
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
async getDocumentForPage(pageId) {
|
|
1193
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1194
|
+
if (!response.ok) {
|
|
1195
|
+
if (response.status === 404)
|
|
1196
|
+
throw Error("bad");
|
|
1197
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1198
|
+
}
|
|
1199
|
+
const document2 = await response.json();
|
|
1200
|
+
return document2;
|
|
1201
|
+
}
|
|
1202
|
+
async unstable_createSnapshotForPage({
|
|
1203
|
+
document: document2,
|
|
1204
|
+
pageId
|
|
1205
|
+
}) {
|
|
1206
|
+
let fetchedDocument = document2;
|
|
1207
|
+
if (fetchedDocument == null) {
|
|
1208
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1209
|
+
if (!response.ok) {
|
|
1210
|
+
if (response.status === 404) {
|
|
1211
|
+
throw new Error("Not found");
|
|
1212
|
+
}
|
|
1213
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1214
|
+
}
|
|
1215
|
+
fetchedDocument = await response.json();
|
|
1216
|
+
}
|
|
1217
|
+
if (fetchedDocument == null) {
|
|
1218
|
+
throw Error("fetchedDocument should never be null");
|
|
1219
|
+
}
|
|
1220
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1221
|
+
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
|
+
});
|
|
1228
|
+
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1229
|
+
}
|
|
1230
|
+
async unstable_createSnapshot({
|
|
1231
|
+
publishedResources,
|
|
1232
|
+
deletedResources,
|
|
1233
|
+
publishedElementTree,
|
|
1234
|
+
currentSnapshot
|
|
1235
|
+
}) {
|
|
1236
|
+
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
|
+
function mergeResources({
|
|
1256
|
+
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1257
|
+
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1258
|
+
publishedResources: publishedResources2,
|
|
1259
|
+
deletedResources: deletedResources2
|
|
1260
|
+
}) {
|
|
1261
|
+
function mergeElementTreeResource(resourceSet, deletedResources3) {
|
|
1262
|
+
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1263
|
+
deletedResources3.forEach(({ id }) => map.delete(id));
|
|
1264
|
+
const finalResourceSet = [];
|
|
1265
|
+
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1266
|
+
if (value != null) {
|
|
1267
|
+
finalResourceSet.push({ id, value });
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
return finalResourceSet;
|
|
1271
|
+
}
|
|
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
|
+
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,
|
|
1323
|
+
...resourcesFromPublishedElementTree2.snippets,
|
|
1324
|
+
...publishedResources2.snippets
|
|
1325
|
+
], deletedResources2.snippets),
|
|
1326
|
+
fonts: mergeFonts([
|
|
1327
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1328
|
+
...resourcesFromPublishedElementTree2.fonts,
|
|
1329
|
+
...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: []
|
|
1336
|
+
};
|
|
1337
|
+
return resources2;
|
|
1338
|
+
}
|
|
1339
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1340
|
+
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1341
|
+
const resources = mergeResources({
|
|
1342
|
+
resourcesFromPublishedElementTree,
|
|
1343
|
+
resourcesFromCurrentSnapshot,
|
|
1344
|
+
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1345
|
+
deletedResources: normalizeToMakeswiftResources(deletedResources)
|
|
1346
|
+
});
|
|
1347
|
+
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1348
|
+
if (elementTree == null) {
|
|
1349
|
+
throw Error("elementTree should not be null; something went wrong.");
|
|
1350
|
+
}
|
|
1351
|
+
return {
|
|
1352
|
+
resources,
|
|
1353
|
+
elementTree,
|
|
1354
|
+
runtimeVersion: version
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
unstable_getSnapshotResourceMapping(snapshot) {
|
|
1358
|
+
const resources = snapshot.resources;
|
|
1359
|
+
function parseResourceIds({ id }) {
|
|
1360
|
+
return id;
|
|
1361
|
+
}
|
|
1362
|
+
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),
|
|
1369
|
+
...resources.snippets.map(parseResourceIds)
|
|
1370
|
+
];
|
|
1371
|
+
}
|
|
989
1372
|
}
|
|
990
1373
|
function PreviewModeScript({
|
|
991
1374
|
isPreview = false,
|
|
@@ -1114,11 +1497,14 @@ class Document$1 extends NextDocument__default["default"] {
|
|
|
1114
1497
|
});
|
|
1115
1498
|
}
|
|
1116
1499
|
}
|
|
1117
|
-
const version = "0.6.4";
|
|
1118
1500
|
function isErrorWithMessage(error) {
|
|
1119
1501
|
return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
|
|
1120
1502
|
}
|
|
1121
|
-
function MakeswiftApiHandler(apiKey, {
|
|
1503
|
+
function MakeswiftApiHandler(apiKey, {
|
|
1504
|
+
appOrigin = "https://app.makeswift.com",
|
|
1505
|
+
apiOrigin = "https://api.makeswift.com",
|
|
1506
|
+
getFonts
|
|
1507
|
+
} = {}) {
|
|
1122
1508
|
const cors = Cors__default["default"]({ origin: appOrigin });
|
|
1123
1509
|
const previewModeProxy = httpProxy.createProxyServer();
|
|
1124
1510
|
previewModeProxy.on("proxyReq", (proxyReq) => {
|
|
@@ -1155,7 +1541,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
|
|
|
1155
1541
|
return res.json({
|
|
1156
1542
|
version,
|
|
1157
1543
|
previewMode: true,
|
|
1158
|
-
interactionMode: true
|
|
1544
|
+
interactionMode: true,
|
|
1545
|
+
clientSideNavigation: true
|
|
1159
1546
|
});
|
|
1160
1547
|
}
|
|
1161
1548
|
case "revalidate": {
|
|
@@ -1228,6 +1615,35 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1228
1615
|
const response = { elementTree: generatedElementTree };
|
|
1229
1616
|
return res.json(response);
|
|
1230
1617
|
}
|
|
1618
|
+
case "snapshot": {
|
|
1619
|
+
let validateBody = function(body2) {
|
|
1620
|
+
if (body2.pageId == null) {
|
|
1621
|
+
return res.status(400).json({ message: "Must define pageId." });
|
|
1622
|
+
}
|
|
1623
|
+
if (body2.currentSnapshot == null && body2.publishedElementTree == null) {
|
|
1624
|
+
return res.status(400).json({ message: "Either currentSnapshot or publishedElementTree must be defined." });
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
const body = req.body;
|
|
1628
|
+
validateBody(body);
|
|
1629
|
+
const client = new Makeswift(apiKey, {
|
|
1630
|
+
apiOrigin
|
|
1631
|
+
});
|
|
1632
|
+
const snapshot = await client.unstable_createSnapshot({
|
|
1633
|
+
publishedResources: body.publishedResources,
|
|
1634
|
+
deletedResources: body.deletedResources,
|
|
1635
|
+
publishedElementTree: body.publishedElementTree,
|
|
1636
|
+
currentSnapshot: body.currentSnapshot
|
|
1637
|
+
});
|
|
1638
|
+
const usedResources = client.unstable_getSnapshotResourceMapping(snapshot);
|
|
1639
|
+
const response = {
|
|
1640
|
+
pageId: body.pageId,
|
|
1641
|
+
snapshot,
|
|
1642
|
+
livePageChanges: body.livePageChanges,
|
|
1643
|
+
usedResources
|
|
1644
|
+
};
|
|
1645
|
+
return res.json(response);
|
|
1646
|
+
}
|
|
1231
1647
|
default:
|
|
1232
1648
|
return res.status(404).json({ message: "Not Found" });
|
|
1233
1649
|
}
|
|
@@ -1362,6 +1778,37 @@ const Page = React.memo(({
|
|
|
1362
1778
|
}, snapshot.document.data.key)
|
|
1363
1779
|
});
|
|
1364
1780
|
});
|
|
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
|
+
});
|
|
1365
1812
|
const keys = (o) => Object.keys(o);
|
|
1366
1813
|
const coalesce = (...args) => {
|
|
1367
1814
|
let i;
|
|
@@ -3651,6 +4098,7 @@ const DocumentContext = React.createContext(null);
|
|
|
3651
4098
|
function useDocumentKey() {
|
|
3652
4099
|
return React.useContext(DocumentContext);
|
|
3653
4100
|
}
|
|
4101
|
+
const DocumentCyclesContext = React.createContext([]);
|
|
3654
4102
|
function useStore() {
|
|
3655
4103
|
return React.useContext(StoreContext);
|
|
3656
4104
|
}
|
|
@@ -3722,20 +4170,32 @@ const ElementReference = React.memo(React.forwardRef(function ElementReference2(
|
|
|
3722
4170
|
const globalElement = useGlobalElement(elementReference.value);
|
|
3723
4171
|
const globalElementData = globalElement == null ? void 0 : globalElement.data;
|
|
3724
4172
|
const elementReferenceDocument = useDocument(elementReference.key);
|
|
4173
|
+
const documentKey = elementReference.key;
|
|
4174
|
+
const documentKeys = React.useContext(DocumentCyclesContext);
|
|
4175
|
+
const providedDocumentKeys = React.useMemo(() => [...documentKeys, documentKey], [documentKeys, documentKey]);
|
|
3725
4176
|
if (globalElementData == null) {
|
|
3726
4177
|
return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {
|
|
3727
4178
|
ref,
|
|
3728
4179
|
text: "This global component doesn't exist"
|
|
3729
4180
|
});
|
|
3730
4181
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
4182
|
+
if (documentKeys.includes(documentKey)) {
|
|
4183
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FallbackComponent, {
|
|
4184
|
+
ref,
|
|
4185
|
+
text: "This global component contains itself!"
|
|
4186
|
+
});
|
|
4187
|
+
}
|
|
4188
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DocumentCyclesContext.Provider, {
|
|
4189
|
+
value: providedDocumentKeys,
|
|
4190
|
+
children: elementReferenceDocument != null ? /* @__PURE__ */ jsxRuntime.jsx(Document, {
|
|
4191
|
+
document: elementReferenceDocument,
|
|
3738
4192
|
ref
|
|
4193
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(DisableRegisterElement.Provider, {
|
|
4194
|
+
value: true,
|
|
4195
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ElementData, {
|
|
4196
|
+
elementData: globalElementData,
|
|
4197
|
+
ref
|
|
4198
|
+
})
|
|
3739
4199
|
})
|
|
3740
4200
|
});
|
|
3741
4201
|
}));
|
|
@@ -3849,6 +4309,8 @@ exports.responsiveTextStyle = responsiveTextStyle;
|
|
|
3849
4309
|
exports.responsiveWidth = responsiveWidth;
|
|
3850
4310
|
exports.shallowMergeFallbacks = shallowMergeFallbacks;
|
|
3851
4311
|
exports.storeContextDefaultValue = storeContextDefaultValue;
|
|
4312
|
+
exports.unstable_Page = unstable_Page$1;
|
|
4313
|
+
exports.unstable_Page$1 = unstable_Page;
|
|
3852
4314
|
exports.useBorder = useBorder;
|
|
3853
4315
|
exports.useBoxShadow = useBoxShadow;
|
|
3854
4316
|
exports.useBuilderEditMode = useBuilderEditMode;
|