@makeswift/runtime 0.6.3 → 0.6.5
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.cjs.js +12 -3
- package/dist/EditableText.cjs.js.map +1 -1
- package/dist/EditableText.es.js +13 -4
- package/dist/EditableText.es.js.map +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 +53 -16
- package/dist/PreviewProvider.cjs.js.map +1 -1
- package/dist/PreviewProvider.es.js +56 -20
- package/dist/PreviewProvider.es.js.map +1 -1
- package/dist/ReadOnlyText.cjs.js +5 -2
- package/dist/ReadOnlyText.cjs.js.map +1 -1
- package/dist/ReadOnlyText.es.js +6 -3
- 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 +11 -1
- package/dist/actions.cjs.js.map +1 -1
- package/dist/actions.es.js +11 -2
- package/dist/actions.es.js.map +1 -1
- package/dist/builder.cjs.js +1 -0
- package/dist/builder.cjs.js.map +1 -1
- package/dist/builder.es.js +1 -0
- package/dist/builder.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/constants.cjs.js +6 -1
- package/dist/constants.cjs.js.map +1 -1
- package/dist/constants.es.js +7 -3
- package/dist/constants.es.js.map +1 -1
- package/dist/controls.cjs.js +1 -0
- package/dist/controls.cjs.js.map +1 -1
- package/dist/controls.es.js +2 -1
- package/dist/controls.es.js.map +1 -1
- package/dist/index.cjs.js +494 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +495 -19
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js +2 -2
- package/dist/index.es3.js +1 -1
- package/dist/index.es4.js +1 -1
- package/dist/index.es6.js +2 -2
- 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/prop-controllers.cjs.js +1 -0
- package/dist/prop-controllers.cjs.js.map +1 -1
- package/dist/prop-controllers.es.js +1 -0
- package/dist/prop-controllers.es.js.map +1 -1
- package/dist/rich-text.cjs.js +20 -4
- package/dist/rich-text.cjs.js.map +1 -1
- package/dist/rich-text.es.js +19 -5
- package/dist/rich-text.es.js.map +1 -1
- package/dist/types/src/components/builtin/Text/EditableText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/ReadOnlyText.d.ts.map +1 -1
- package/dist/types/src/components/builtin/Text/register.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/controls/rich-text.d.ts +1 -1
- package/dist/types/src/controls/rich-text.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/next/preview-mode.d.ts.map +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts +1 -1
- package/dist/types/src/prop-controllers/instances.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/index.d.ts +2 -0
- package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
- package/dist/types/src/state/actions.d.ts +12 -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/modules/builder-edit-mode.d.ts +11 -0
- package/dist/types/src/state/modules/builder-edit-mode.d.ts.map +1 -0
- package/dist/types/src/state/react-builder-preview.d.ts +2 -0
- package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
- package/dist/types/src/state/react-page.d.ts +3 -0
- package/dist/types/src/state/react-page.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/types/src/utils/constants.d.ts +0 -6
- package/dist/types/src/utils/constants.d.ts.map +0 -1
package/dist/index.es.js
CHANGED
|
@@ -39,13 +39,13 @@ 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 } from "./constants.es.js";
|
|
43
|
-
import { A as ActionTypes,
|
|
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";
|
|
44
44
|
import { cache, cx } from "@emotion/css";
|
|
45
45
|
import { serializeStyles } from "@emotion/serialize";
|
|
46
46
|
import { registerStyles, insertStyles } from "@emotion/utils";
|
|
47
47
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
48
|
-
import { T as Types, E as ElementID, B as Backgrounds, W as Width, h as ResponsiveIconRadioGroup, M as Margin, P as Padding, i as Border, j as BorderRadius, k as Shadows, G as GapY, l as GapX, m as ResponsiveSelect, n as ResponsiveNumber, o as Checkbox, p as Grid, q as TextInput, L as Link,
|
|
48
|
+
import { T as Types, E as ElementID, B as Backgrounds, W as Width, h as ResponsiveIconRadioGroup, M as Margin, P as Padding, i as Border, j as BorderRadius, k as Shadows, G as GapY, l as GapX, m as ResponsiveSelect, n as ResponsiveNumber, o as Checkbox, p as Grid, q as TextInput, L as Link, s as ResponsiveColor, t as TextStyle, u as Images, N as Number$1, D as Date$1, F as Font, v as ResponsiveLength, w as TextArea, x as Table, y as TableFormFields, z as Image, A as ResponsiveOpacity, H as NavigationLinks, J as SocialLinks, K as RichText, V as Video, O as StyleControlProperty, Q as ImageControlValueFormat, I as ImageControlType, C as ColorControlType, U as BorderPropControllerFormat, X as ShadowsPropControllerFormat, Y as BorderRadiusPropControllerFormat, Z as MarginPropControllerFormat, _ as PaddingPropControllerFormat, $ as WidthPropControllerFormat, S as SlotControlType, a0 as RichTextControlType, a as StyleControlType } from "./rich-text.es.js";
|
|
49
49
|
import { S as SelectControlType, T as TextAreaControlType, a as TextInputControlType, N as NumberControlType, C as CheckboxControlType } from "./text-input.es.js";
|
|
50
50
|
import { C as ComboboxControlType } from "./combobox.es.js";
|
|
51
51
|
import { S as ShapeControlType, L as ListControlType, b as LinkControlType } from "./control.es.js";
|
|
@@ -230,14 +230,44 @@ const deepEqual = (a, b) => {
|
|
|
230
230
|
}
|
|
231
231
|
return true;
|
|
232
232
|
};
|
|
233
|
-
function getInitialState(serializedState =
|
|
234
|
-
|
|
233
|
+
function getInitialState(serializedState = {
|
|
234
|
+
Swatch: [],
|
|
235
|
+
File: [],
|
|
236
|
+
Typography: [],
|
|
237
|
+
PagePathnameSlice: [],
|
|
238
|
+
GlobalElement: [],
|
|
239
|
+
Table: [],
|
|
240
|
+
Snippet: [],
|
|
241
|
+
Page: [],
|
|
242
|
+
Site: []
|
|
243
|
+
}) {
|
|
244
|
+
return new Map(Object.entries(serializedState).map(([apiResourceType, resources]) => [
|
|
245
|
+
apiResourceType,
|
|
246
|
+
new Map(resources.map(({ id, value }) => [id, value]))
|
|
247
|
+
]));
|
|
235
248
|
}
|
|
236
249
|
function getSerializedState$1(state) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
const resourceMap = {
|
|
251
|
+
Swatch: [],
|
|
252
|
+
File: [],
|
|
253
|
+
Typography: [],
|
|
254
|
+
PagePathnameSlice: [],
|
|
255
|
+
GlobalElement: [],
|
|
256
|
+
Table: [],
|
|
257
|
+
Snippet: [],
|
|
258
|
+
Page: [],
|
|
259
|
+
Site: []
|
|
260
|
+
};
|
|
261
|
+
Array.from(state.entries()).forEach(([resourceType, resources]) => {
|
|
262
|
+
const particularResourceMap = [];
|
|
263
|
+
Array.from(resources.entries()).forEach(([id, value]) => {
|
|
264
|
+
if (value != null) {
|
|
265
|
+
particularResourceMap.push({ id, value });
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
resourceMap[resourceType] = particularResourceMap;
|
|
269
|
+
});
|
|
270
|
+
return resourceMap;
|
|
241
271
|
}
|
|
242
272
|
function getHasAPIResource$1(state, resourceType, resourceId) {
|
|
243
273
|
var _a, _b;
|
|
@@ -886,6 +916,159 @@ function Page$1({
|
|
|
886
916
|
}, snippet.id))]
|
|
887
917
|
});
|
|
888
918
|
}
|
|
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
|
+
}
|
|
889
1072
|
function useCachedPage(pageId) {
|
|
890
1073
|
const client = useMakeswiftClient();
|
|
891
1074
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
@@ -898,6 +1081,7 @@ function useCachedSite(siteId) {
|
|
|
898
1081
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
899
1082
|
return site;
|
|
900
1083
|
}
|
|
1084
|
+
const version = "0.6.5";
|
|
901
1085
|
class Makeswift {
|
|
902
1086
|
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
903
1087
|
__publicField(this, "apiKey");
|
|
@@ -951,12 +1135,205 @@ Received "${apiKey}" instead.`);
|
|
|
951
1135
|
const snapshot = this.getPageSnapshotByPageId(page.id, { preview });
|
|
952
1136
|
return snapshot;
|
|
953
1137
|
}
|
|
1138
|
+
async unstable_getPageData(path, { preview } = {}) {
|
|
1139
|
+
const [page] = await this.getPages({ path });
|
|
1140
|
+
if (page == null)
|
|
1141
|
+
return null;
|
|
1142
|
+
const document2 = await this.getDocumentForPage(page.id);
|
|
1143
|
+
const snapshot = await this.unstable_createSnapshotForPage({ document: document2, pageId: page.id });
|
|
1144
|
+
return {
|
|
1145
|
+
pageId: page.id,
|
|
1146
|
+
siteId: document2.site.id,
|
|
1147
|
+
snapshot,
|
|
1148
|
+
options: { preview: preview || false, apiOrigin: this.apiOrigin.href }
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
async getDocumentForPage(pageId) {
|
|
1152
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1153
|
+
if (!response.ok) {
|
|
1154
|
+
if (response.status === 404)
|
|
1155
|
+
throw Error("bad");
|
|
1156
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1157
|
+
}
|
|
1158
|
+
const document2 = await response.json();
|
|
1159
|
+
return document2;
|
|
1160
|
+
}
|
|
1161
|
+
async unstable_createSnapshotForPage({
|
|
1162
|
+
document: document2,
|
|
1163
|
+
pageId
|
|
1164
|
+
}) {
|
|
1165
|
+
let fetchedDocument = document2;
|
|
1166
|
+
if (fetchedDocument == null) {
|
|
1167
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?preview=false`);
|
|
1168
|
+
if (!response.ok) {
|
|
1169
|
+
if (response.status === 404) {
|
|
1170
|
+
throw new Error("Not found");
|
|
1171
|
+
}
|
|
1172
|
+
throw new Error(`Failed to create snapshot with error: "${response.statusText}"`);
|
|
1173
|
+
}
|
|
1174
|
+
fetchedDocument = await response.json();
|
|
1175
|
+
}
|
|
1176
|
+
if (fetchedDocument == null) {
|
|
1177
|
+
throw Error("fetchedDocument should never be null");
|
|
1178
|
+
}
|
|
1179
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
1180
|
+
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
|
+
});
|
|
1187
|
+
return { resources, elementTree: fetchedDocument.data, runtimeVersion: version };
|
|
1188
|
+
}
|
|
1189
|
+
async unstable_createSnapshot({
|
|
1190
|
+
publishedResources,
|
|
1191
|
+
deletedResources,
|
|
1192
|
+
publishedElementTree,
|
|
1193
|
+
currentSnapshot
|
|
1194
|
+
}) {
|
|
1195
|
+
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
|
+
function mergeResources({
|
|
1215
|
+
resourcesFromPublishedElementTree: resourcesFromPublishedElementTree2,
|
|
1216
|
+
resourcesFromCurrentSnapshot: resourcesFromCurrentSnapshot2,
|
|
1217
|
+
publishedResources: publishedResources2,
|
|
1218
|
+
deletedResources: deletedResources2
|
|
1219
|
+
}) {
|
|
1220
|
+
function mergeElementTreeResource(resourceSet, deletedResources3) {
|
|
1221
|
+
const map = new Map(resourceSet.map(({ id, value }) => [id, value]));
|
|
1222
|
+
deletedResources3.forEach(({ id }) => map.delete(id));
|
|
1223
|
+
const finalResourceSet = [];
|
|
1224
|
+
Array.from(map.entries()).forEach(([id, value]) => {
|
|
1225
|
+
if (value != null) {
|
|
1226
|
+
finalResourceSet.push({ id, value });
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
return finalResourceSet;
|
|
1230
|
+
}
|
|
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
|
+
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,
|
|
1282
|
+
...resourcesFromPublishedElementTree2.snippets,
|
|
1283
|
+
...publishedResources2.snippets
|
|
1284
|
+
], deletedResources2.snippets),
|
|
1285
|
+
fonts: mergeFonts([
|
|
1286
|
+
...resourcesFromCurrentSnapshot2.fonts,
|
|
1287
|
+
...resourcesFromPublishedElementTree2.fonts,
|
|
1288
|
+
...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: []
|
|
1295
|
+
};
|
|
1296
|
+
return resources2;
|
|
1297
|
+
}
|
|
1298
|
+
const resourcesFromPublishedElementTree = publishedElementTree != null ? normalizeToMakeswiftResources(await client.prefetch(publishedElementTree)) : normalizeToMakeswiftResources({});
|
|
1299
|
+
const resourcesFromCurrentSnapshot = normalizeToMakeswiftResources((currentSnapshot == null ? void 0 : currentSnapshot.resources) || {});
|
|
1300
|
+
const resources = mergeResources({
|
|
1301
|
+
resourcesFromPublishedElementTree,
|
|
1302
|
+
resourcesFromCurrentSnapshot,
|
|
1303
|
+
publishedResources: normalizeToMakeswiftResources(publishedResources),
|
|
1304
|
+
deletedResources: normalizeToMakeswiftResources(deletedResources)
|
|
1305
|
+
});
|
|
1306
|
+
const elementTree = publishedElementTree || (currentSnapshot == null ? void 0 : currentSnapshot.elementTree);
|
|
1307
|
+
if (elementTree == null) {
|
|
1308
|
+
throw Error("elementTree should not be null; something went wrong.");
|
|
1309
|
+
}
|
|
1310
|
+
return {
|
|
1311
|
+
resources,
|
|
1312
|
+
elementTree,
|
|
1313
|
+
runtimeVersion: version
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
unstable_getSnapshotResourceMapping(snapshot) {
|
|
1317
|
+
const resources = snapshot.resources;
|
|
1318
|
+
function parseResourceIds({ id }) {
|
|
1319
|
+
return id;
|
|
1320
|
+
}
|
|
1321
|
+
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),
|
|
1328
|
+
...resources.snippets.map(parseResourceIds)
|
|
1329
|
+
];
|
|
1330
|
+
}
|
|
954
1331
|
}
|
|
955
1332
|
function PreviewModeScript({
|
|
956
1333
|
isPreview = false,
|
|
957
1334
|
appOrigin = "https://app.makeswift.com"
|
|
958
1335
|
}) {
|
|
959
|
-
const
|
|
1336
|
+
const previewModeScript = `
|
|
960
1337
|
const isPreview = ${isPreview}
|
|
961
1338
|
const appOrigin = '${appOrigin.replace("'", "\\'")}'
|
|
962
1339
|
const searchParamName = 'x-makeswift-preview-mode'
|
|
@@ -1004,12 +1381,43 @@ if (originalUrl.searchParams.has(searchParamName)) {
|
|
|
1004
1381
|
window.history.replaceState(null, '', url)
|
|
1005
1382
|
}
|
|
1006
1383
|
`;
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1384
|
+
const makeswiftConnectionCheckScript = `
|
|
1385
|
+
const appOrigin = '${appOrigin.replace("'", "\\'")}'
|
|
1386
|
+
|
|
1387
|
+
if (window.parent !== window) {
|
|
1388
|
+
window.addEventListener('message', event => {
|
|
1389
|
+
if (
|
|
1390
|
+
event.origin === appOrigin &&
|
|
1391
|
+
event.data.type === '${ActionTypes.MAKESWIFT_CONNECTION_INIT}'
|
|
1392
|
+
) {
|
|
1393
|
+
setInterval(() => {
|
|
1394
|
+
window.parent.postMessage({
|
|
1395
|
+
type: '${ActionTypes.MAKESWIFT_CONNECTION_CHECK}',
|
|
1396
|
+
payload: {
|
|
1397
|
+
currentUrl: window.location.href
|
|
1398
|
+
}
|
|
1399
|
+
}, appOrigin)
|
|
1400
|
+
}, 20)
|
|
1012
1401
|
}
|
|
1402
|
+
})
|
|
1403
|
+
|
|
1404
|
+
window.parent.postMessage({ type: '${ActionTypes.MAKESWIFT_CONNECTION_INIT}' }, appOrigin)
|
|
1405
|
+
}
|
|
1406
|
+
`;
|
|
1407
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
1408
|
+
children: [/* @__PURE__ */ jsx("script", {
|
|
1409
|
+
id: "makeswift-preview-mode",
|
|
1410
|
+
type: "module",
|
|
1411
|
+
dangerouslySetInnerHTML: {
|
|
1412
|
+
__html: previewModeScript
|
|
1413
|
+
}
|
|
1414
|
+
}), /* @__PURE__ */ jsx("script", {
|
|
1415
|
+
id: "makeswift-connection-check",
|
|
1416
|
+
type: "module",
|
|
1417
|
+
dangerouslySetInnerHTML: {
|
|
1418
|
+
__html: makeswiftConnectionCheckScript
|
|
1419
|
+
}
|
|
1420
|
+
})]
|
|
1013
1421
|
});
|
|
1014
1422
|
}
|
|
1015
1423
|
class Document$1 extends NextDocument {
|
|
@@ -1048,11 +1456,14 @@ class Document$1 extends NextDocument {
|
|
|
1048
1456
|
});
|
|
1049
1457
|
}
|
|
1050
1458
|
}
|
|
1051
|
-
const version = "0.6.3";
|
|
1052
1459
|
function isErrorWithMessage(error) {
|
|
1053
1460
|
return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
|
|
1054
1461
|
}
|
|
1055
|
-
function MakeswiftApiHandler(apiKey, {
|
|
1462
|
+
function MakeswiftApiHandler(apiKey, {
|
|
1463
|
+
appOrigin = "https://app.makeswift.com",
|
|
1464
|
+
apiOrigin = "https://api.makeswift.com",
|
|
1465
|
+
getFonts
|
|
1466
|
+
} = {}) {
|
|
1056
1467
|
const cors = Cors({ origin: appOrigin });
|
|
1057
1468
|
const previewModeProxy = createProxyServer();
|
|
1058
1469
|
previewModeProxy.on("proxyReq", (proxyReq) => {
|
|
@@ -1088,7 +1499,8 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
|
|
|
1088
1499
|
return res.status(401).json({ message: "Unauthorized" });
|
|
1089
1500
|
return res.json({
|
|
1090
1501
|
version,
|
|
1091
|
-
previewMode: true
|
|
1502
|
+
previewMode: true,
|
|
1503
|
+
interactionMode: true
|
|
1092
1504
|
});
|
|
1093
1505
|
}
|
|
1094
1506
|
case "revalidate": {
|
|
@@ -1161,6 +1573,35 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
|
|
|
1161
1573
|
const response = { elementTree: generatedElementTree };
|
|
1162
1574
|
return res.json(response);
|
|
1163
1575
|
}
|
|
1576
|
+
case "snapshot": {
|
|
1577
|
+
let validateBody = function(body2) {
|
|
1578
|
+
if (body2.pageId == null) {
|
|
1579
|
+
return res.status(400).json({ message: "Must define pageId." });
|
|
1580
|
+
}
|
|
1581
|
+
if (body2.currentSnapshot == null && body2.publishedElementTree == null) {
|
|
1582
|
+
return res.status(400).json({ message: "Either currentSnapshot or publishedElementTree must be defined." });
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
const body = req.body;
|
|
1586
|
+
validateBody(body);
|
|
1587
|
+
const client = new Makeswift(apiKey, {
|
|
1588
|
+
apiOrigin
|
|
1589
|
+
});
|
|
1590
|
+
const snapshot = await client.unstable_createSnapshot({
|
|
1591
|
+
publishedResources: body.publishedResources,
|
|
1592
|
+
deletedResources: body.deletedResources,
|
|
1593
|
+
publishedElementTree: body.publishedElementTree,
|
|
1594
|
+
currentSnapshot: body.currentSnapshot
|
|
1595
|
+
});
|
|
1596
|
+
const usedResources = client.unstable_getSnapshotResourceMapping(snapshot);
|
|
1597
|
+
const response = {
|
|
1598
|
+
pageId: body.pageId,
|
|
1599
|
+
snapshot,
|
|
1600
|
+
livePageChanges: body.livePageChanges,
|
|
1601
|
+
usedResources
|
|
1602
|
+
};
|
|
1603
|
+
return res.json(response);
|
|
1604
|
+
}
|
|
1164
1605
|
default:
|
|
1165
1606
|
return res.status(404).json({ message: "Not Found" });
|
|
1166
1607
|
}
|
|
@@ -1295,6 +1736,37 @@ const Page = memo(({
|
|
|
1295
1736
|
}, snapshot.document.data.key)
|
|
1296
1737
|
});
|
|
1297
1738
|
});
|
|
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
|
+
});
|
|
1298
1770
|
const keys = (o) => Object.keys(o);
|
|
1299
1771
|
const coalesce = (...args) => {
|
|
1300
1772
|
let i;
|
|
@@ -2202,6 +2674,7 @@ function registerComponent$1(runtime) {
|
|
|
2202
2674
|
text: RichText(() => ({
|
|
2203
2675
|
preset: {
|
|
2204
2676
|
document: {
|
|
2677
|
+
object: "document",
|
|
2205
2678
|
nodes: [
|
|
2206
2679
|
{
|
|
2207
2680
|
object: "block",
|
|
@@ -3574,6 +4047,9 @@ function useIsInBuilder() {
|
|
|
3574
4047
|
function useIsPreview() {
|
|
3575
4048
|
return useSelector((state) => getIsPreview(state));
|
|
3576
4049
|
}
|
|
4050
|
+
function useBuilderEditMode() {
|
|
4051
|
+
return useSelector((state) => getBuilderEditMode(state));
|
|
4052
|
+
}
|
|
3577
4053
|
function useDispatch() {
|
|
3578
4054
|
const store = useContext(StoreContext);
|
|
3579
4055
|
return store.dispatch;
|
|
@@ -3705,5 +4181,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
|
|
|
3705
4181
|
document: document2
|
|
3706
4182
|
});
|
|
3707
4183
|
}));
|
|
3708
|
-
export {
|
|
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 };
|
|
3709
4185
|
//# sourceMappingURL=index.es.js.map
|