@makeswift/runtime 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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.cjs.js +2 -2
- package/dist/Image.cjs.js.map +1 -1
- package/dist/Image.es.js +3 -3
- package/dist/Image.es.js.map +1 -1
- package/dist/LiveProvider.es.js +1 -1
- package/dist/Navigation.es.js +1 -1
- package/dist/PreviewProvider.es.js +1 -1
- package/dist/ReadOnlyText.es.js +1 -1
- package/dist/Root.es.js +1 -1
- package/dist/SocialLinks.es.js +1 -1
- package/dist/Text.es.js +1 -1
- package/dist/Video.es.js +1 -1
- package/dist/api.cjs.js +1 -1
- package/dist/api.cjs.js.map +1 -1
- package/dist/api.es.js +1 -1
- package/dist/api.es.js.map +1 -1
- package/dist/components.cjs.js +0 -1
- package/dist/components.cjs.js.map +1 -1
- package/dist/components.es.js +1 -1
- package/dist/index.cjs.js +182 -287
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.es.js +187 -290
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +2 -2
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es3.js +1 -1
- package/dist/index.es4.js +1 -1
- package/dist/index.es6.js +1 -1
- package/dist/next.cjs.js +0 -1
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +1 -1
- package/dist/types/src/api/graphql/documents/fragments.d.ts +1 -1
- package/dist/types/src/api/graphql/documents/fragments.d.ts.map +1 -1
- package/dist/types/src/api/graphql/generated/types.d.ts +3 -3
- package/dist/types/src/api/graphql/generated/types.d.ts.map +1 -1
- package/dist/types/src/components/page/Page.d.ts +1 -5
- package/dist/types/src/components/page/Page.d.ts.map +1 -1
- package/dist/types/src/next/api-handler.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts +18 -16
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts +0 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/next/snapshots.d.ts +102 -0
- package/dist/types/src/next/snapshots.d.ts.map +1 -0
- package/dist/types/src/state/modules/api-resources.d.ts +2 -0
- package/dist/types/src/state/modules/api-resources.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -39,7 +39,7 @@ import * as React from "react";
|
|
|
39
39
|
import { useEffect, createContext, useContext, useState, useMemo, useRef, Children, createElement, forwardRef, memo, useCallback, useImperativeHandle, Component, Suspense } from "react";
|
|
40
40
|
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
41
41
|
import dynamic from "next/dynamic";
|
|
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";
|
|
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$1, 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
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";
|
|
@@ -199,6 +199,24 @@ async function introspect(element, client, store) {
|
|
|
199
199
|
pageIds: [...pageIds]
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
+
function normalizeToMakeswiftResources(partialResources) {
|
|
203
|
+
const resources = {
|
|
204
|
+
swatches: (partialResources == null ? void 0 : partialResources.swatches) || [],
|
|
205
|
+
typographies: (partialResources == null ? void 0 : partialResources.typographies) || [],
|
|
206
|
+
files: (partialResources == null ? void 0 : partialResources.files) || [],
|
|
207
|
+
pagePathnameSlices: (partialResources == null ? void 0 : partialResources.pagePathnameSlices) || [],
|
|
208
|
+
globalElements: (partialResources == null ? void 0 : partialResources.globalElements) || [],
|
|
209
|
+
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
210
|
+
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
211
|
+
pageMetadata: (partialResources == null ? void 0 : partialResources.pageMetadata) || {},
|
|
212
|
+
pageSeo: (partialResources == null ? void 0 : partialResources.pageSeo) || {}
|
|
213
|
+
};
|
|
214
|
+
return resources;
|
|
215
|
+
}
|
|
216
|
+
function fileToFileSnapshot(file) {
|
|
217
|
+
const _a = file, { publicUrlV2 } = _a, restOfFile = __objRest(_a, ["publicUrlV2"]);
|
|
218
|
+
return __spreadProps(__spreadValues({}, restOfFile), { publicUrl: publicUrlV2 });
|
|
219
|
+
}
|
|
202
220
|
function is(x, y) {
|
|
203
221
|
if (x === y)
|
|
204
222
|
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
|
@@ -236,6 +254,19 @@ const deepEqual = (a, b) => {
|
|
|
236
254
|
}
|
|
237
255
|
return true;
|
|
238
256
|
};
|
|
257
|
+
function isNonNullable(value) {
|
|
258
|
+
return value != null;
|
|
259
|
+
}
|
|
260
|
+
function getSnapshotResourcesFromSerializedState(serializedState) {
|
|
261
|
+
const resources = {
|
|
262
|
+
swatches: serializedState.Swatch.filter((_) => true),
|
|
263
|
+
typographies: serializedState.Typography.filter((_) => true),
|
|
264
|
+
files: serializedState.File.map(({ id, value }) => value.__typename === APIResourceType.File ? { id, value: fileToFileSnapshot(value) } : null).filter(isNonNullable),
|
|
265
|
+
pagePathnameSlices: serializedState.PagePathnameSlice.filter((_) => true),
|
|
266
|
+
globalElements: serializedState.GlobalElement.filter((_) => true)
|
|
267
|
+
};
|
|
268
|
+
return resources;
|
|
269
|
+
}
|
|
239
270
|
function getInitialState(serializedState = {
|
|
240
271
|
Swatch: [],
|
|
241
272
|
File: [],
|
|
@@ -359,7 +390,7 @@ const FileFragment = `
|
|
|
359
390
|
__typename
|
|
360
391
|
id
|
|
361
392
|
name
|
|
362
|
-
|
|
393
|
+
publicUrlV2
|
|
363
394
|
extension
|
|
364
395
|
dimensions {
|
|
365
396
|
width
|
|
@@ -922,159 +953,6 @@ function Page$1({
|
|
|
922
953
|
}, snippet.id))]
|
|
923
954
|
});
|
|
924
955
|
}
|
|
925
|
-
function unstable_Page$1({
|
|
926
|
-
pageData
|
|
927
|
-
}) {
|
|
928
|
-
var _a;
|
|
929
|
-
const isInBuilder = useIsInBuilder();
|
|
930
|
-
const [snippets, setSnippets] = useState(pageData.snapshot.resources.snippets);
|
|
931
|
-
const cachedPage = useCachedPage(isInBuilder ? pageData.pageId : null);
|
|
932
|
-
useEffect(() => {
|
|
933
|
-
if (cachedPage == null)
|
|
934
|
-
return;
|
|
935
|
-
const oldSnippets = snippets.map(filterUsedSnippetProperties);
|
|
936
|
-
const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties);
|
|
937
|
-
if (deepEqual(newSnippets, oldSnippets))
|
|
938
|
-
return;
|
|
939
|
-
setSnippets(cachedPage.snippets);
|
|
940
|
-
}, [cachedPage]);
|
|
941
|
-
const site = useCachedSite(isInBuilder ? pageData.siteId : null);
|
|
942
|
-
const favicon = (_a = pageData.snapshot.resources.meta.favicon) != null ? _a : defaultFavicon;
|
|
943
|
-
const {
|
|
944
|
-
title,
|
|
945
|
-
description,
|
|
946
|
-
keywords,
|
|
947
|
-
socialImage
|
|
948
|
-
} = pageData.snapshot.resources.meta;
|
|
949
|
-
const {
|
|
950
|
-
canonicalUrl,
|
|
951
|
-
isIndexingBlocked
|
|
952
|
-
} = pageData.snapshot.resources.seo;
|
|
953
|
-
const fontFamilyParamValue = useMemo(() => {
|
|
954
|
-
if (site == null) {
|
|
955
|
-
return pageData.snapshot.resources.fonts.map(({
|
|
956
|
-
family,
|
|
957
|
-
variants
|
|
958
|
-
}) => {
|
|
959
|
-
return `${family.replace(/ /g, "+")}:${variants.join()}`;
|
|
960
|
-
}).join("|");
|
|
961
|
-
}
|
|
962
|
-
return site.googleFonts.edges.filter((edge) => edge != null).map(({
|
|
963
|
-
activeVariants,
|
|
964
|
-
node: {
|
|
965
|
-
family,
|
|
966
|
-
variants
|
|
967
|
-
}
|
|
968
|
-
}) => {
|
|
969
|
-
const activeVariantSpecifiers = variants.filter((variant) => activeVariants.some((activeVariant) => activeVariant.specifier === variant.specifier)).map((variant) => variant.specifier).join();
|
|
970
|
-
return `${family.replace(/ /g, "+")}:${activeVariantSpecifiers}`;
|
|
971
|
-
}).join("|");
|
|
972
|
-
}, [site, pageData.snapshot.resources.fonts]);
|
|
973
|
-
const filteredSnippets = useMemo(() => snippets.filter((snippet) => isInBuilder ? snippet.builderEnabled : snippet.liveEnabled), [snippets, isInBuilder]);
|
|
974
|
-
const headSnippets = useMemo(() => filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Head), [filteredSnippets]);
|
|
975
|
-
const previousHeadSnippets = useRef(null);
|
|
976
|
-
useEffect(() => {
|
|
977
|
-
var _a2;
|
|
978
|
-
const headSnippetsToCleanUp = ((_a2 = previousHeadSnippets.current) != null ? _a2 : []).filter((previousSnippet) => previousSnippet.cleanup != null).filter((previousSnippet) => !headSnippets.some((snippet) => previousSnippet.id === snippet.id));
|
|
979
|
-
headSnippetsToCleanUp.forEach((snippetToCleanUp) => {
|
|
980
|
-
if (snippetToCleanUp.cleanup == null)
|
|
981
|
-
return;
|
|
982
|
-
const cleanUp = new Function(snippetToCleanUp.cleanup);
|
|
983
|
-
try {
|
|
984
|
-
cleanUp();
|
|
985
|
-
} catch {
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
previousHeadSnippets.current = headSnippets;
|
|
989
|
-
}, [headSnippets]);
|
|
990
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
991
|
-
children: [/* @__PURE__ */ jsxs(Head, {
|
|
992
|
-
children: [/* @__PURE__ */ jsx("style", {
|
|
993
|
-
children: `
|
|
994
|
-
html {
|
|
995
|
-
font-family: sans-serif;
|
|
996
|
-
}
|
|
997
|
-
div#__next {
|
|
998
|
-
overflow: hidden;
|
|
999
|
-
}
|
|
1000
|
-
`
|
|
1001
|
-
}), /* @__PURE__ */ jsx("link", {
|
|
1002
|
-
rel: "icon",
|
|
1003
|
-
type: favicon.mimetype,
|
|
1004
|
-
href: favicon.publicUrl
|
|
1005
|
-
}), canonicalUrl && /* @__PURE__ */ jsx("link", {
|
|
1006
|
-
rel: "canonical",
|
|
1007
|
-
href: canonicalUrl
|
|
1008
|
-
}), isIndexingBlocked && /* @__PURE__ */ jsx("meta", {
|
|
1009
|
-
name: "robots",
|
|
1010
|
-
content: "noindex"
|
|
1011
|
-
}), title && /* @__PURE__ */ jsxs(Fragment, {
|
|
1012
|
-
children: [/* @__PURE__ */ jsx("title", {
|
|
1013
|
-
children: title
|
|
1014
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1015
|
-
property: "og:title",
|
|
1016
|
-
content: title
|
|
1017
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1018
|
-
name: "twitter:title",
|
|
1019
|
-
content: title
|
|
1020
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1021
|
-
itemProp: "name",
|
|
1022
|
-
content: title
|
|
1023
|
-
})]
|
|
1024
|
-
}), description && /* @__PURE__ */ jsxs(Fragment, {
|
|
1025
|
-
children: [/* @__PURE__ */ jsx("meta", {
|
|
1026
|
-
name: "description",
|
|
1027
|
-
content: description
|
|
1028
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1029
|
-
property: "og:description",
|
|
1030
|
-
content: description
|
|
1031
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1032
|
-
name: "twitter:description",
|
|
1033
|
-
content: description
|
|
1034
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1035
|
-
itemProp: "description",
|
|
1036
|
-
content: description
|
|
1037
|
-
})]
|
|
1038
|
-
}), keywords && /* @__PURE__ */ jsx("meta", {
|
|
1039
|
-
name: "keywords",
|
|
1040
|
-
content: keywords
|
|
1041
|
-
}), socialImage && /* @__PURE__ */ jsxs(Fragment, {
|
|
1042
|
-
children: [/* @__PURE__ */ jsx("meta", {
|
|
1043
|
-
property: "og:image",
|
|
1044
|
-
content: socialImage.publicUrl
|
|
1045
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1046
|
-
property: "og:image:type",
|
|
1047
|
-
content: socialImage.mimetype
|
|
1048
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1049
|
-
name: "twitter:image",
|
|
1050
|
-
content: socialImage.publicUrl
|
|
1051
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1052
|
-
name: "twitter:card",
|
|
1053
|
-
content: "summary_large_image"
|
|
1054
|
-
}), /* @__PURE__ */ jsx("meta", {
|
|
1055
|
-
itemProp: "image",
|
|
1056
|
-
content: socialImage.publicUrl
|
|
1057
|
-
})]
|
|
1058
|
-
}), fontFamilyParamValue !== "" && /* @__PURE__ */ jsx(Fragment, {
|
|
1059
|
-
children: /* @__PURE__ */ jsx("link", {
|
|
1060
|
-
rel: "stylesheet",
|
|
1061
|
-
href: `https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`
|
|
1062
|
-
})
|
|
1063
|
-
}), headSnippets.map(snippetToElement).map((children) => Children.map(children, (child) => {
|
|
1064
|
-
if (typeof child === "string")
|
|
1065
|
-
return child;
|
|
1066
|
-
if (VALID_HEAD_ELEMENT_TYPES.includes(child.type))
|
|
1067
|
-
return child;
|
|
1068
|
-
return null;
|
|
1069
|
-
}))]
|
|
1070
|
-
}), /* @__PURE__ */ jsx(DocumentReference, {
|
|
1071
|
-
documentReference: createDocumentReference(pageData.pageId)
|
|
1072
|
-
}), filteredSnippets.filter((snippet) => snippet.location === SnippetLocation.Body).map((snippet) => /* @__PURE__ */ jsx(BodySnippet, {
|
|
1073
|
-
code: snippet.code,
|
|
1074
|
-
cleanup: snippet.cleanup
|
|
1075
|
-
}, snippet.id))]
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
956
|
function useCachedPage(pageId) {
|
|
1079
957
|
const client = useMakeswiftClient();
|
|
1080
958
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -1087,7 +965,7 @@ function useCachedSite(siteId) {
|
|
|
1087
965
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
1088
966
|
return site;
|
|
1089
967
|
}
|
|
1090
|
-
const version = "0.
|
|
968
|
+
const version = "0.7.0";
|
|
1091
969
|
class Makeswift {
|
|
1092
970
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
1093
971
|
__publicField(this, "apiKey");
|
|
@@ -1146,7 +1024,7 @@ Received "${apiKey}" instead.`);
|
|
|
1146
1024
|
if (page == null)
|
|
1147
1025
|
return null;
|
|
1148
1026
|
const document2 = await this.getDocumentForPage(page.id);
|
|
1149
|
-
const snapshot = await this.
|
|
1027
|
+
const snapshot = await this.unstable_createSnapshotOnDemand({ document: document2, pageId: page.id });
|
|
1150
1028
|
return {
|
|
1151
1029
|
pageId: page.id,
|
|
1152
1030
|
siteId: document2.site.id,
|
|
@@ -1158,13 +1036,13 @@ Received "${apiKey}" instead.`);
|
|
|
1158
1036
|
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1159
1037
|
if (!response.ok) {
|
|
1160
1038
|
if (response.status === 404)
|
|
1161
|
-
throw Error("
|
|
1039
|
+
throw Error("Document not found.");
|
|
1162
1040
|
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1163
1041
|
}
|
|
1164
1042
|
const document2 = await response.json();
|
|
1165
1043
|
return document2;
|
|
1166
1044
|
}
|
|
1167
|
-
async
|
|
1045
|
+
async unstable_createSnapshotOnDemand({
|
|
1168
1046
|
document: document2,
|
|
1169
1047
|
pageId
|
|
1170
1048
|
}) {
|
|
@@ -1184,12 +1062,14 @@ Received "${apiKey}" instead.`);
|
|
|
1184
1062
|
}
|
|
1185
1063
|
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1186
1064
|
const prefetchedResources = await client.prefetch(fetchedDocument.data);
|
|
1187
|
-
const resources =
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1065
|
+
const resources = normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(prefetchedResources));
|
|
1066
|
+
resources.snippets = fetchedDocument.snippets.map((snippet) => ({
|
|
1067
|
+
id: snippet.id,
|
|
1068
|
+
value: snippet
|
|
1069
|
+
}));
|
|
1070
|
+
resources.pageMetadata = fetchedDocument.meta;
|
|
1071
|
+
resources.pageSeo = fetchedDocument.seo;
|
|
1072
|
+
resources.fonts = fetchedDocument.fonts.map((font) => ({ id: font.family, value: font }));
|
|
1193
1073
|
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1194
1074
|
}
|
|
1195
1075
|
async unstable_createSnapshot({
|
|
@@ -1199,33 +1079,15 @@ Received "${apiKey}" instead.`);
|
|
|
1199
1079
|
currentSnapshot
|
|
1200
1080
|
}) {
|
|
1201
1081
|
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1202
|
-
function normalizeToMakeswiftResources(partialResources) {
|
|
1203
|
-
const resources2 = {
|
|
1204
|
-
Swatch: (partialResources == null ? void 0 : partialResources.Swatch) || [],
|
|
1205
|
-
File: (partialResources == null ? void 0 : partialResources.File) || [],
|
|
1206
|
-
Typography: (partialResources == null ? void 0 : partialResources.Typography) || [],
|
|
1207
|
-
PagePathnameSlice: (partialResources == null ? void 0 : partialResources.PagePathnameSlice) || [],
|
|
1208
|
-
GlobalElement: (partialResources == null ? void 0 : partialResources.GlobalElement) || [],
|
|
1209
|
-
Table: (partialResources == null ? void 0 : partialResources.Table) || [],
|
|
1210
|
-
Snippet: (partialResources == null ? void 0 : partialResources.Snippet) || [],
|
|
1211
|
-
Page: (partialResources == null ? void 0 : partialResources.Page) || [],
|
|
1212
|
-
Site: (partialResources == null ? void 0 : partialResources.Site) || [],
|
|
1213
|
-
snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
|
|
1214
|
-
fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
|
|
1215
|
-
meta: (partialResources == null ? void 0 : partialResources.meta) || {},
|
|
1216
|
-
seo: (partialResources == null ? void 0 : partialResources.seo) || {}
|
|
1217
|
-
};
|
|
1218
|
-
return resources2;
|
|
1219
|
-
}
|
|
1220
1082
|
function mergeResources({
|
|
1221
1083
|
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1222
1084
|
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1223
1085
|
publishedResources: publishedResources2,
|
|
1224
1086
|
deletedResources: deletedResources2
|
|
1225
1087
|
}) {
|
|
1226
|
-
function
|
|
1088
|
+
function mergeIdSpecifiedResource(resourceSet, deletedResources3) {
|
|
1227
1089
|
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1228
|
-
deletedResources3.forEach((
|
|
1090
|
+
deletedResources3 == null ? void 0 : deletedResources3.forEach((id) => map.delete(id));
|
|
1229
1091
|
const finalResourceSet = [];
|
|
1230
1092
|
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1231
1093
|
if (value != null) {
|
|
@@ -1234,80 +1096,54 @@ Received "${apiKey}" instead.`);
|
|
|
1234
1096
|
});
|
|
1235
1097
|
return finalResourceSet;
|
|
1236
1098
|
}
|
|
1237
|
-
function mergeSnippets(snippets, deletedSnippet) {
|
|
1238
|
-
const map = new Map(snippets.map((value) => [value.id, value]));
|
|
1239
|
-
deletedSnippet.forEach(({ id }) => map.delete(id));
|
|
1240
|
-
const uniqueSnippets = [];
|
|
1241
|
-
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1242
|
-
uniqueSnippets.push(value);
|
|
1243
|
-
});
|
|
1244
|
-
return uniqueSnippets;
|
|
1245
|
-
}
|
|
1246
|
-
function mergeFonts(fonts, deletedFonts) {
|
|
1247
|
-
const map = new Map(fonts.map((value) => [value.family, value]));
|
|
1248
|
-
deletedFonts.forEach(({ family }) => map.delete(family));
|
|
1249
|
-
const uniqueFonts = [];
|
|
1250
|
-
Array.from(map.entries()).forEach(([_, value]) => {
|
|
1251
|
-
uniqueFonts.push(value);
|
|
1252
|
-
});
|
|
1253
|
-
return uniqueFonts;
|
|
1254
|
-
}
|
|
1255
1099
|
const resources2 = {
|
|
1256
|
-
|
|
1257
|
-
...resourcesFromPublishedElementTree2.
|
|
1258
|
-
...resourcesFromCurrentSnapshot2.
|
|
1259
|
-
...publishedResources2.
|
|
1260
|
-
], deletedResources2.
|
|
1261
|
-
|
|
1262
|
-
...resourcesFromPublishedElementTree2.
|
|
1263
|
-
...resourcesFromCurrentSnapshot2.
|
|
1264
|
-
...publishedResources2.
|
|
1265
|
-
], deletedResources2.
|
|
1266
|
-
|
|
1267
|
-
...resourcesFromPublishedElementTree2.
|
|
1268
|
-
...resourcesFromCurrentSnapshot2.
|
|
1269
|
-
...publishedResources2.
|
|
1270
|
-
], deletedResources2.
|
|
1271
|
-
|
|
1272
|
-
...resourcesFromPublishedElementTree2.
|
|
1273
|
-
...resourcesFromCurrentSnapshot2.
|
|
1274
|
-
...publishedResources2.
|
|
1275
|
-
], deletedResources2.
|
|
1276
|
-
|
|
1277
|
-
...resourcesFromPublishedElementTree2.
|
|
1278
|
-
...resourcesFromCurrentSnapshot2.
|
|
1279
|
-
...publishedResources2.
|
|
1280
|
-
], deletedResources2.
|
|
1281
|
-
|
|
1282
|
-
...resourcesFromPublishedElementTree2.Table,
|
|
1283
|
-
...resourcesFromCurrentSnapshot2.Table,
|
|
1284
|
-
...publishedResources2.Table
|
|
1285
|
-
], deletedResources2.Table),
|
|
1286
|
-
snippets: mergeSnippets([
|
|
1287
|
-
...resourcesFromCurrentSnapshot2.snippets,
|
|
1100
|
+
swatches: mergeIdSpecifiedResource([
|
|
1101
|
+
...resourcesFromPublishedElementTree2.swatches,
|
|
1102
|
+
...resourcesFromCurrentSnapshot2.swatches,
|
|
1103
|
+
...publishedResources2.swatches
|
|
1104
|
+
], deletedResources2 == null ? void 0 : deletedResources2.swatches),
|
|
1105
|
+
files: mergeIdSpecifiedResource([
|
|
1106
|
+
...resourcesFromPublishedElementTree2.files,
|
|
1107
|
+
...resourcesFromCurrentSnapshot2.files,
|
|
1108
|
+
...publishedResources2.files
|
|
1109
|
+
], deletedResources2 == null ? void 0 : deletedResources2.files),
|
|
1110
|
+
typographies: mergeIdSpecifiedResource([
|
|
1111
|
+
...resourcesFromPublishedElementTree2.typographies,
|
|
1112
|
+
...resourcesFromCurrentSnapshot2.typographies,
|
|
1113
|
+
...publishedResources2.typographies
|
|
1114
|
+
], deletedResources2 == null ? void 0 : deletedResources2.typographies),
|
|
1115
|
+
pagePathnameSlices: mergeIdSpecifiedResource([
|
|
1116
|
+
...resourcesFromPublishedElementTree2.pagePathnameSlices,
|
|
1117
|
+
...resourcesFromCurrentSnapshot2.pagePathnameSlices,
|
|
1118
|
+
...publishedResources2.pagePathnameSlices
|
|
1119
|
+
], deletedResources2 == null ? void 0 : deletedResources2.pagePathnameSlices),
|
|
1120
|
+
globalElements: mergeIdSpecifiedResource([
|
|
1121
|
+
...resourcesFromPublishedElementTree2.globalElements,
|
|
1122
|
+
...resourcesFromCurrentSnapshot2.globalElements,
|
|
1123
|
+
...publishedResources2.globalElements
|
|
1124
|
+
], deletedResources2 == null ? void 0 : deletedResources2.globalElements),
|
|
1125
|
+
snippets: mergeIdSpecifiedResource([
|
|
1288
1126
|
...resourcesFromPublishedElementTree2.snippets,
|
|
1127
|
+
...resourcesFromCurrentSnapshot2.snippets,
|
|
1289
1128
|
...publishedResources2.snippets
|
|
1290
|
-
], deletedResources2.snippets),
|
|
1291
|
-
fonts:
|
|
1292
|
-
...resourcesFromCurrentSnapshot2.fonts,
|
|
1129
|
+
], deletedResources2 == null ? void 0 : deletedResources2.snippets),
|
|
1130
|
+
fonts: mergeIdSpecifiedResource([
|
|
1293
1131
|
...resourcesFromPublishedElementTree2.fonts,
|
|
1132
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1294
1133
|
...publishedResources2.fonts
|
|
1295
|
-
], deletedResources2.fonts),
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
Snippet: [],
|
|
1299
|
-
Page: [],
|
|
1300
|
-
Site: []
|
|
1134
|
+
], deletedResources2 == null ? void 0 : deletedResources2.fonts),
|
|
1135
|
+
pageMetadata: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageMetadata), publishedResources2.pageMetadata),
|
|
1136
|
+
pageSeo: __spreadValues(__spreadValues({}, resourcesFromCurrentSnapshot2.pageSeo), publishedResources2.pageSeo)
|
|
1301
1137
|
};
|
|
1302
1138
|
return resources2;
|
|
1303
1139
|
}
|
|
1304
|
-
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1140
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(getSnapshotResourcesFromSerializedState(await client.prefetch(publishedElementTree))) : normalizeToMakeswiftResources({});
|
|
1305
1141
|
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1306
1142
|
const resources = mergeResources({
|
|
1307
1143
|
resourcesFromPublishedElementTree,
|
|
1308
1144
|
resourcesFromCurrentSnapshot,
|
|
1309
1145
|
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1310
|
-
deletedResources
|
|
1146
|
+
deletedResources
|
|
1311
1147
|
});
|
|
1312
1148
|
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1313
1149
|
if (elementTree == null) {
|
|
@@ -1325,12 +1161,11 @@ Received "${apiKey}" instead.`);
|
|
|
1325
1161
|
return id;
|
|
1326
1162
|
}
|
|
1327
1163
|
return [
|
|
1328
|
-
...resources.
|
|
1329
|
-
...resources.
|
|
1330
|
-
...resources.
|
|
1331
|
-
...resources.
|
|
1332
|
-
...resources.
|
|
1333
|
-
...resources.Table.map(parseResourceIds),
|
|
1164
|
+
...resources.swatches.map(parseResourceIds),
|
|
1165
|
+
...resources.files.map(parseResourceIds),
|
|
1166
|
+
...resources.typographies.map(parseResourceIds),
|
|
1167
|
+
...resources.pagePathnameSlices.map(parseResourceIds),
|
|
1168
|
+
...resources.globalElements.map(parseResourceIds),
|
|
1334
1169
|
...resources.snippets.map(parseResourceIds)
|
|
1335
1170
|
];
|
|
1336
1171
|
}
|
|
@@ -1594,8 +1429,101 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1594
1429
|
const client = new Makeswift(apiKey, {
|
|
1595
1430
|
apiOrigin
|
|
1596
1431
|
});
|
|
1432
|
+
const makeswiftApiClient = new MakeswiftClient({ uri: new URL("graphql", apiOrigin).href });
|
|
1433
|
+
async function formMakeswiftResources(publishedResources) {
|
|
1434
|
+
var _a2, _b, _c2, _d, _e, _f, _g;
|
|
1435
|
+
const publishedResourcesInMakeswiftSnapshotFormat = {
|
|
1436
|
+
swatches: [],
|
|
1437
|
+
typographies: [],
|
|
1438
|
+
files: [],
|
|
1439
|
+
pagePathnameSlices: [],
|
|
1440
|
+
globalElements: [],
|
|
1441
|
+
snippets: [],
|
|
1442
|
+
fonts: [],
|
|
1443
|
+
pageMetadata: publishedResources == null ? void 0 : publishedResources.pageMetadata,
|
|
1444
|
+
pageSeo: publishedResources == null ? void 0 : publishedResources.pageSeo
|
|
1445
|
+
};
|
|
1446
|
+
if (publishedResources == null) {
|
|
1447
|
+
return publishedResourcesInMakeswiftSnapshotFormat;
|
|
1448
|
+
}
|
|
1449
|
+
for await (const swatchId of publishedResources.swatches || []) {
|
|
1450
|
+
const swatch = await makeswiftApiClient.fetchSwatch(swatchId);
|
|
1451
|
+
if (swatch != null) {
|
|
1452
|
+
(_a2 = publishedResourcesInMakeswiftSnapshotFormat.swatches) == null ? void 0 : _a2.push({
|
|
1453
|
+
id: swatchId,
|
|
1454
|
+
value: swatch
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
for await (const typographyId of publishedResources.typographies || []) {
|
|
1459
|
+
const typography = await makeswiftApiClient.fetchTypography(typographyId);
|
|
1460
|
+
if (typography != null) {
|
|
1461
|
+
(_b = publishedResourcesInMakeswiftSnapshotFormat.typographies) == null ? void 0 : _b.push({
|
|
1462
|
+
id: typographyId,
|
|
1463
|
+
value: typography
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
for await (const fileId of publishedResources.files || []) {
|
|
1468
|
+
const file = await makeswiftApiClient.fetchFile(fileId);
|
|
1469
|
+
if (file != null) {
|
|
1470
|
+
(_c2 = publishedResourcesInMakeswiftSnapshotFormat.files) == null ? void 0 : _c2.push({
|
|
1471
|
+
id: fileId,
|
|
1472
|
+
value: fileToFileSnapshot(file)
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
for await (const pageId of publishedResources.pagePathnameSlices || []) {
|
|
1477
|
+
const pagePathnameSlice = await makeswiftApiClient.fetchPagePathnameSlice(pageId);
|
|
1478
|
+
if (pagePathnameSlice != null) {
|
|
1479
|
+
(_d = publishedResourcesInMakeswiftSnapshotFormat.pagePathnameSlices) == null ? void 0 : _d.push({
|
|
1480
|
+
id: pageId,
|
|
1481
|
+
value: pagePathnameSlice
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
for await (const globalElementId of publishedResources.globalElements || []) {
|
|
1486
|
+
const globalElement = await makeswiftApiClient.fetchGlobalElement(globalElementId);
|
|
1487
|
+
if (globalElement != null) {
|
|
1488
|
+
(_e = publishedResourcesInMakeswiftSnapshotFormat.globalElements) == null ? void 0 : _e.push({
|
|
1489
|
+
id: globalElementId,
|
|
1490
|
+
value: globalElement
|
|
1491
|
+
});
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (publishedResources.snippets != null || publishedResources.fonts != null) {
|
|
1495
|
+
const response2 = await fetch(new URL(`/v1/pages/${body.pageId}/document?preview=false`, apiOrigin).toString(), {
|
|
1496
|
+
headers: { ["X-API-Key"]: apiKey }
|
|
1497
|
+
});
|
|
1498
|
+
if (!response2.ok) {
|
|
1499
|
+
throw new Error(`Failed to hit live page endpoint: "${response2.statusText}"`);
|
|
1500
|
+
}
|
|
1501
|
+
const document2 = await response2.json();
|
|
1502
|
+
const availableSnippets = document2.snippets;
|
|
1503
|
+
const availableFonts = document2.fonts;
|
|
1504
|
+
for await (const snippetId of publishedResources.snippets || []) {
|
|
1505
|
+
const snippet = availableSnippets.find((availableSnippet) => availableSnippet.id === snippetId);
|
|
1506
|
+
if (snippet != null) {
|
|
1507
|
+
(_f = publishedResourcesInMakeswiftSnapshotFormat.snippets) == null ? void 0 : _f.push({
|
|
1508
|
+
id: snippetId,
|
|
1509
|
+
value: snippet
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
for await (const family of publishedResources.fonts || []) {
|
|
1514
|
+
const font = availableFonts.find((availableFont) => availableFont.family === family);
|
|
1515
|
+
if (font != null) {
|
|
1516
|
+
(_g = publishedResourcesInMakeswiftSnapshotFormat.fonts) == null ? void 0 : _g.push({
|
|
1517
|
+
id: family,
|
|
1518
|
+
value: font
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
return publishedResourcesInMakeswiftSnapshotFormat;
|
|
1524
|
+
}
|
|
1597
1525
|
const snapshot = await client.unstable_createSnapshot({
|
|
1598
|
-
publishedResources: body.publishedResources,
|
|
1526
|
+
publishedResources: await formMakeswiftResources(body.publishedResources),
|
|
1599
1527
|
deletedResources: body.deletedResources,
|
|
1600
1528
|
publishedElementTree: body.publishedElementTree,
|
|
1601
1529
|
currentSnapshot: body.currentSnapshot
|
|
@@ -1743,37 +1671,6 @@ const Page = memo(({
|
|
|
1743
1671
|
}, snapshot.document.data.key)
|
|
1744
1672
|
});
|
|
1745
1673
|
});
|
|
1746
|
-
const unstable_Page = memo(({
|
|
1747
|
-
pageData
|
|
1748
|
-
}) => {
|
|
1749
|
-
function resourcesToCacheData(resources) {
|
|
1750
|
-
if (resources == null)
|
|
1751
|
-
return void 0;
|
|
1752
|
-
return {
|
|
1753
|
-
Swatch: resources.Swatch,
|
|
1754
|
-
File: resources.File,
|
|
1755
|
-
Typography: resources.Typography,
|
|
1756
|
-
PagePathnameSlice: resources.PagePathnameSlice,
|
|
1757
|
-
GlobalElement: resources.GlobalElement,
|
|
1758
|
-
Table: resources.Table,
|
|
1759
|
-
Snippet: resources.Snippet,
|
|
1760
|
-
Page: resources.Page,
|
|
1761
|
-
Site: resources.Site
|
|
1762
|
-
};
|
|
1763
|
-
}
|
|
1764
|
-
const client = useMemo(() => new MakeswiftClient({
|
|
1765
|
-
uri: new URL("graphql", pageData.options.apiOrigin).href,
|
|
1766
|
-
cacheData: resourcesToCacheData(pageData.snapshot.resources)
|
|
1767
|
-
}), [pageData]);
|
|
1768
|
-
return /* @__PURE__ */ jsx(RuntimeProvider, {
|
|
1769
|
-
client,
|
|
1770
|
-
rootElements: /* @__PURE__ */ new Map([[pageData.pageId, pageData.snapshot.elementTree]]),
|
|
1771
|
-
preview: pageData.options.preview,
|
|
1772
|
-
children: /* @__PURE__ */ jsx(unstable_Page$1, {
|
|
1773
|
-
pageData
|
|
1774
|
-
})
|
|
1775
|
-
});
|
|
1776
|
-
});
|
|
1777
1674
|
const keys = (o) => Object.keys(o);
|
|
1778
1675
|
const coalesce = (...args) => {
|
|
1779
1676
|
let i;
|
|
@@ -2952,7 +2849,7 @@ function mapSideColor(swatches, _d) {
|
|
|
2952
2849
|
return __spreadProps(__spreadValues({}, restOfSide), {
|
|
2953
2850
|
color: color && {
|
|
2954
2851
|
alpha: color.alpha,
|
|
2955
|
-
swatch: swatches.filter(isNonNullable).find((s) => s && s.id === color.swatchId)
|
|
2852
|
+
swatch: swatches.filter(isNonNullable$1).find((s) => s && s.id === color.swatchId)
|
|
2956
2853
|
}
|
|
2957
2854
|
});
|
|
2958
2855
|
}
|
|
@@ -2998,7 +2895,7 @@ function useBoxShadow(value) {
|
|
|
2998
2895
|
return __spreadProps(__spreadValues({}, restOfShadow), {
|
|
2999
2896
|
payload: {
|
|
3000
2897
|
color: color != null ? {
|
|
3001
|
-
swatch: swatches.filter(isNonNullable).find((s) => s && s.id === color.swatchId),
|
|
2898
|
+
swatch: swatches.filter(isNonNullable$1).find((s) => s && s.id === color.swatchId),
|
|
3002
2899
|
alpha: color.alpha
|
|
3003
2900
|
} : null,
|
|
3004
2901
|
inset: inset != null ? inset : ShadowDefaultValue.inset,
|
|
@@ -3022,7 +2919,7 @@ function useResponsiveColor(color) {
|
|
|
3022
2919
|
const { swatchId, alpha } = v;
|
|
3023
2920
|
const swatch = swatches.find((s) => s && s.id === swatchId);
|
|
3024
2921
|
return swatch == null ? null : __spreadProps(__spreadValues({}, rest), { value: { swatch, alpha } });
|
|
3025
|
-
}).filter(isNonNullable);
|
|
2922
|
+
}).filter(isNonNullable$1);
|
|
3026
2923
|
}
|
|
3027
2924
|
const DEVICE_QUERIES = DEVICES.map((device) => ({
|
|
3028
2925
|
id: device.id,
|
|
@@ -3363,12 +3260,12 @@ function useImageControlValue(data, definition) {
|
|
|
3363
3260
|
const fileId = data != null ? data : null;
|
|
3364
3261
|
const file = useFile(fileId);
|
|
3365
3262
|
if (format === ImageControlValueFormat.URL) {
|
|
3366
|
-
return file == null ? void 0 : file.
|
|
3263
|
+
return file == null ? void 0 : file.publicUrlV2;
|
|
3367
3264
|
}
|
|
3368
3265
|
if (file == null || file.dimensions == null)
|
|
3369
3266
|
return void 0;
|
|
3370
3267
|
return {
|
|
3371
|
-
url: file.
|
|
3268
|
+
url: file.publicUrlV2,
|
|
3372
3269
|
dimensions: { width: file.dimensions.width, height: file.dimensions.height }
|
|
3373
3270
|
};
|
|
3374
3271
|
}
|
|
@@ -4201,5 +4098,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
|
|
|
4201
4098
|
document: document2
|
|
4202
4099
|
});
|
|
4203
4100
|
}));
|
|
4204
|
-
export {
|
|
4101
|
+
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 };
|
|
4205
4102
|
//# sourceMappingURL=index.es.js.map
|