@makeswift/runtime 0.2.2 → 0.2.4
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.cjs.js +14 -14
- package/dist/Box.cjs.js.map +1 -1
- package/dist/Button.cjs.js +23 -23
- package/dist/Button.cjs.js.map +1 -1
- package/dist/Carousel.cjs.js +8 -8
- package/dist/Carousel.cjs.js.map +1 -1
- package/dist/Carousel.es.js.map +1 -1
- package/dist/Countdown.cjs.js +13 -13
- package/dist/Countdown.cjs.js.map +1 -1
- package/dist/Divider.cjs.js +4 -4
- package/dist/Divider.cjs.js.map +1 -1
- package/dist/Embed.cjs.js +2 -2
- package/dist/Embed.cjs.js.map +1 -1
- package/dist/Form.cjs.js +72 -72
- package/dist/Form.cjs.js.map +1 -1
- package/dist/Image.cjs2.js +10 -10
- package/dist/Image.cjs2.js.map +1 -1
- package/dist/Navigation.cjs.js +17 -17
- package/dist/Navigation.cjs.js.map +1 -1
- package/dist/Root.cjs.js +2 -2
- package/dist/Root.cjs.js.map +1 -1
- package/dist/SocialLinks.cjs.js +3 -3
- package/dist/SocialLinks.cjs.js.map +1 -1
- package/dist/Text.cjs.js +21 -21
- package/dist/Text.cjs.js.map +1 -1
- package/dist/actions.es.js +1 -1
- package/dist/components.cjs.js +18 -18
- package/dist/cssMediaRules.cjs.js +7 -7
- package/dist/cssMediaRules.cjs.js.map +1 -1
- package/dist/index.cjs.js +374 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs2.js +10 -10
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs3.js +3 -3
- package/dist/index.cjs3.js.map +1 -1
- package/dist/index.es.js +367 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.es2.js.map +1 -1
- package/dist/next.cjs.js +22 -402
- package/dist/next.cjs.js.map +1 -1
- package/dist/next.es.js +12 -388
- package/dist/next.es.js.map +1 -1
- package/dist/react-builder-preview.cjs.js +11 -11
- package/dist/react-builder-preview.cjs.js.map +1 -1
- package/dist/react-builder-preview.es.js +1 -1
- package/dist/react.cjs.js +8 -8
- package/dist/types/src/next/api-handler.d.ts +25 -1
- package/dist/types/src/next/api-handler.d.ts.map +1 -1
- package/dist/types/src/next/index.d.ts +1 -1
- package/dist/types/src/next/index.d.ts.map +1 -1
- package/dist/types/src/runtimes/react/use-style.d.ts.map +1 -1
- package/dist/useBoxShadow.cjs.js +3 -3
- package/dist/useBoxShadow.cjs.js.map +1 -1
- package/dist/useMediaQuery.cjs.js +6 -6
- package/dist/useMediaQuery.cjs.js.map +1 -1
- package/package.json +4 -4
package/dist/index.es.js
CHANGED
|
@@ -36,10 +36,10 @@ var __publicField = (obj, key, value) => {
|
|
|
36
36
|
};
|
|
37
37
|
var _e;
|
|
38
38
|
import * as React from "react";
|
|
39
|
-
import { useEffect, createContext, useContext, useState, useMemo, useRef, Children, createElement, forwardRef, useLayoutEffect, useCallback, Component,
|
|
39
|
+
import { useEffect, createContext, useContext, useState, useMemo, useRef, Children, createElement, forwardRef, memo, useLayoutEffect, useCallback, Component, useImperativeHandle } from "react";
|
|
40
40
|
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
41
|
-
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, k as getComponentPropControllerDescriptors, l as getPropControllers, m as configureStore, n as getDocument, o as getElementId, p as getIsInBuilder,
|
|
42
|
-
import { f as
|
|
41
|
+
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, k as getComponentPropControllerDescriptors, l as getPropControllers, m as configureStore, n as getDocument, o as getElementId, p as getIsInBuilder, c as createDocument, q as getReactComponent } from "./react-page.es.js";
|
|
42
|
+
import { f as registerDocumentEffect, g as registerComponentHandleEffect, h as mountComponentEffect, j as registerComponentEffect, k as registerReactComponentEffect } from "./actions.es.js";
|
|
43
43
|
import dynamic from "next/dynamic";
|
|
44
44
|
import { gql, useQuery as useQuery$1, useMutation as useMutation$1, ApolloClient, InMemoryCache } from "@apollo/client";
|
|
45
45
|
import { BatchHttpLink } from "@apollo/client/link/batch-http";
|
|
@@ -48,7 +48,7 @@ import { P as PagePathnameSliceFragmentDoc } from "./graphql.es.js";
|
|
|
48
48
|
import { T as Types, E as ElementID, B as Backgrounds, W as Width, R as ResponsiveIconRadioGroup, M as Margin, P as Padding, a as Border, b as BorderRadius, S as Shadows, G as GapY, c as GapX, e as ResponsiveSelect, f as ResponsiveNumber, C as Checkbox, g as Grid, h as TextInput, L as Link, i as ResponsiveColor, j as TextStyle, k as Images, N as Number, D as Date$1, F as Font, l as ResponsiveLength, m as TextArea, n as Table, o as TableFormFields, p as Image, q as ResponsiveOpacity, r as NavigationLinks, s as SocialLinks, t as RichText, V as Video, u as StyleControlProperty, v as ImageControlValueFormat, I as ImageControlType, w as StyleControlType, x as WidthControlValueFormats } from "./image.es.js";
|
|
49
49
|
import { S as ShapeControlType, L as ListControlType, C as ComboboxControlType } from "./shape.es.js";
|
|
50
50
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
51
|
-
import styled from "styled-components";
|
|
51
|
+
import styled, { ServerStyleSheet } from "styled-components";
|
|
52
52
|
import { L as LinkControlType, S as SelectControlType, T as TextAreaControlType, a as TextInputControlType, N as NumberControlType, C as CheckboxControlType } from "./text-input.es.js";
|
|
53
53
|
import { C as ColorControlType } from "./color.es.js";
|
|
54
54
|
import { S as SlotControlType } from "./slot.es.js";
|
|
@@ -59,12 +59,12 @@ import { g as getBox } from "./box-models.es.js";
|
|
|
59
59
|
import { findDOMNode } from "react-dom";
|
|
60
60
|
import parse from "html-react-parser";
|
|
61
61
|
import Head from "next/head";
|
|
62
|
-
import "@emotion/server/create-instance";
|
|
63
|
-
import "next/document";
|
|
64
|
-
import "cookie";
|
|
65
|
-
import "cors";
|
|
66
|
-
import "http-proxy";
|
|
67
|
-
import "set-cookie-parser";
|
|
62
|
+
import createEmotionServer from "@emotion/server/create-instance";
|
|
63
|
+
import NextDocument, { Html, Head as Head$1, Main, NextScript } from "next/document";
|
|
64
|
+
import { serialize } from "cookie";
|
|
65
|
+
import Cors from "cors";
|
|
66
|
+
import { createProxyServer } from "http-proxy";
|
|
67
|
+
import { parse as parse$1 } from "set-cookie-parser";
|
|
68
68
|
import uuid from "uuid/v4";
|
|
69
69
|
import ipsum from "corporate-ipsum";
|
|
70
70
|
const SCRIPT_TAG = "script";
|
|
@@ -646,7 +646,7 @@ const SITE_FONTS_QUERY = gql`
|
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
648
|
`;
|
|
649
|
-
function Page({
|
|
649
|
+
function Page$1({
|
|
650
650
|
document: page
|
|
651
651
|
}) {
|
|
652
652
|
var _a;
|
|
@@ -813,6 +813,256 @@ function Page({
|
|
|
813
813
|
}, snippet.id))]
|
|
814
814
|
});
|
|
815
815
|
}
|
|
816
|
+
class Makeswift {
|
|
817
|
+
constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
|
|
818
|
+
__publicField(this, "apiKey");
|
|
819
|
+
__publicField(this, "apiOrigin");
|
|
820
|
+
if (typeof apiKey !== "string") {
|
|
821
|
+
throw new Error(`The Makeswift client must be passed a valid Makeswift site API key: \`new Makeswift('<makeswift_site_api_key>')\`
|
|
822
|
+
Received "${apiKey}" instead.`);
|
|
823
|
+
}
|
|
824
|
+
this.apiKey = apiKey;
|
|
825
|
+
try {
|
|
826
|
+
this.apiOrigin = new URL(apiOrigin);
|
|
827
|
+
} catch {
|
|
828
|
+
throw new Error(`The Makeswift client received an invalid \`apiOrigin\` parameter: "${apiOrigin}".`);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
async fetch(path, init) {
|
|
832
|
+
const response = await fetch(new URL(path, this.apiOrigin).toString(), __spreadProps(__spreadValues({}, init), {
|
|
833
|
+
headers: __spreadProps(__spreadValues({}, init == null ? void 0 : init.headers), { ["X-API-Key"]: this.apiKey })
|
|
834
|
+
}));
|
|
835
|
+
return response;
|
|
836
|
+
}
|
|
837
|
+
async getPages(params = {}) {
|
|
838
|
+
const searchParams = new URLSearchParams(params);
|
|
839
|
+
const response = await this.fetch(`/v1/pages?${searchParams}`);
|
|
840
|
+
if (!response.ok) {
|
|
841
|
+
throw new Error(`Failed to get pages with error: "${response.statusText}"`);
|
|
842
|
+
}
|
|
843
|
+
const json = await response.json();
|
|
844
|
+
return json;
|
|
845
|
+
}
|
|
846
|
+
async createSnapshot(document2) {
|
|
847
|
+
const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
|
|
848
|
+
const cacheData = await client.prefetch(document2.data);
|
|
849
|
+
return { document: document2, apiOrigin: this.apiOrigin.href, cacheData };
|
|
850
|
+
}
|
|
851
|
+
async getPageSnapshotByPageId(pageId, { preview = false } = {}) {
|
|
852
|
+
const searchParams = new URLSearchParams({ preview: String(preview) });
|
|
853
|
+
const response = await this.fetch(`/v1/pages/${pageId}/document?${searchParams}`);
|
|
854
|
+
if (!response.ok) {
|
|
855
|
+
if (response.status === 404)
|
|
856
|
+
return null;
|
|
857
|
+
throw new Error(`Failed to get snapshot with error: "${response.statusText}"`);
|
|
858
|
+
}
|
|
859
|
+
const document2 = await response.json();
|
|
860
|
+
return await this.createSnapshot(document2);
|
|
861
|
+
}
|
|
862
|
+
async getPageSnapshot(path, { preview } = {}) {
|
|
863
|
+
const [page] = await this.getPages({ path });
|
|
864
|
+
if (page == null)
|
|
865
|
+
return null;
|
|
866
|
+
const snapshot = this.getPageSnapshotByPageId(page.id, { preview });
|
|
867
|
+
return snapshot;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
function PreviewModeScript({
|
|
871
|
+
isPreview = false,
|
|
872
|
+
appOrigin = "https://app.makeswift.com"
|
|
873
|
+
}) {
|
|
874
|
+
const __html = `
|
|
875
|
+
const isPreview = ${isPreview}
|
|
876
|
+
const appOrigin = '${appOrigin.replace("'", "\\'")}'
|
|
877
|
+
const searchParamName = 'x-makeswift-preview-mode'
|
|
878
|
+
const headerName = 'X-Makeswift-Preview-Mode'
|
|
879
|
+
const originalUrl = new URL(window.location.href)
|
|
880
|
+
|
|
881
|
+
if (window.parent !== window) {
|
|
882
|
+
window.addEventListener('message', event => {
|
|
883
|
+
if (event.origin === appOrigin && event.data.type === 'makeswift_preview_mode') {
|
|
884
|
+
const { secret } = event.data
|
|
885
|
+
|
|
886
|
+
if (!isPreview && !originalUrl.searchParams.has(searchParamName)) {
|
|
887
|
+
const url = new URL(originalUrl)
|
|
888
|
+
|
|
889
|
+
url.searchParams.set(searchParamName, secret)
|
|
890
|
+
|
|
891
|
+
window.location.replace(url)
|
|
892
|
+
} else {
|
|
893
|
+
const originalFetch = window.fetch
|
|
894
|
+
|
|
895
|
+
window.fetch = function patchedFetch(input, init) {
|
|
896
|
+
return originalFetch.call(this, input, {
|
|
897
|
+
...init,
|
|
898
|
+
headers: { ...init?.headers, [headerName]: secret },
|
|
899
|
+
})
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
})
|
|
904
|
+
|
|
905
|
+
window.parent.postMessage({ type: 'makeswift_preview_mode' }, appOrigin)
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
if (originalUrl.searchParams.has(searchParamName)) {
|
|
909
|
+
const url = new URL(originalUrl)
|
|
910
|
+
|
|
911
|
+
url.searchParams.delete(searchParamName)
|
|
912
|
+
|
|
913
|
+
window.history.replaceState(null, '', url)
|
|
914
|
+
}
|
|
915
|
+
`;
|
|
916
|
+
return /* @__PURE__ */ jsx("script", {
|
|
917
|
+
id: "makeswift-preview-mode",
|
|
918
|
+
type: "module",
|
|
919
|
+
dangerouslySetInnerHTML: {
|
|
920
|
+
__html
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
class Document$1 extends NextDocument {
|
|
925
|
+
static async getInitialProps(ctx) {
|
|
926
|
+
const sheet = new ServerStyleSheet();
|
|
927
|
+
const originalRenderPage = ctx.renderPage;
|
|
928
|
+
try {
|
|
929
|
+
ctx.renderPage = () => originalRenderPage({
|
|
930
|
+
enhanceApp: (App) => (props) => sheet.collectStyles(/* @__PURE__ */ jsx(App, __spreadValues({}, props)))
|
|
931
|
+
});
|
|
932
|
+
const initialProps = await NextDocument.getInitialProps(ctx);
|
|
933
|
+
KeyUtils.resetGenerator();
|
|
934
|
+
const {
|
|
935
|
+
extractCritical
|
|
936
|
+
} = createEmotionServer(cache);
|
|
937
|
+
const {
|
|
938
|
+
ids,
|
|
939
|
+
css: css2
|
|
940
|
+
} = extractCritical(initialProps.html);
|
|
941
|
+
return __spreadProps(__spreadValues({}, initialProps), {
|
|
942
|
+
styles: /* @__PURE__ */ jsxs(Fragment, {
|
|
943
|
+
children: [initialProps.styles, sheet.getStyleElement(), /* @__PURE__ */ jsx("style", {
|
|
944
|
+
"data-emotion": `css ${ids.join(" ")}`,
|
|
945
|
+
dangerouslySetInnerHTML: {
|
|
946
|
+
__html: css2
|
|
947
|
+
}
|
|
948
|
+
})]
|
|
949
|
+
})
|
|
950
|
+
});
|
|
951
|
+
} finally {
|
|
952
|
+
sheet.seal();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
render() {
|
|
956
|
+
const {
|
|
957
|
+
isPreview
|
|
958
|
+
} = this.props.__NEXT_DATA__;
|
|
959
|
+
return /* @__PURE__ */ jsxs(Html, {
|
|
960
|
+
children: [/* @__PURE__ */ jsx(Head$1, {
|
|
961
|
+
children: /* @__PURE__ */ jsx(PreviewModeScript, {
|
|
962
|
+
isPreview
|
|
963
|
+
})
|
|
964
|
+
}), /* @__PURE__ */ jsxs("body", {
|
|
965
|
+
children: [/* @__PURE__ */ jsx(Main, {}), /* @__PURE__ */ jsx(NextScript, {})]
|
|
966
|
+
})]
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
const version = "0.2.4";
|
|
971
|
+
function MakeswiftApiHandler(apiKey, { appOrigin = "https://app.makeswift.com", getFonts } = {}) {
|
|
972
|
+
const cors = Cors({ origin: appOrigin });
|
|
973
|
+
const previewModeProxy = createProxyServer();
|
|
974
|
+
previewModeProxy.on("proxyReq", (proxyReq) => {
|
|
975
|
+
proxyReq.removeHeader("X-Makeswift-Preview-Mode");
|
|
976
|
+
const url = new URL(proxyReq.path, "http://n");
|
|
977
|
+
url.searchParams.delete("x-makeswift-preview-mode");
|
|
978
|
+
proxyReq.path = url.pathname + url.search;
|
|
979
|
+
});
|
|
980
|
+
if (typeof apiKey !== "string") {
|
|
981
|
+
throw new Error(`The Makeswift Next.js API handler must be passed a valid Makeswift site API key: \`MakeswiftApiHandler('<makeswift_site_api_key>')\`
|
|
982
|
+
Received "${apiKey}" instead.`);
|
|
983
|
+
}
|
|
984
|
+
return async function makeswiftApiHandler(req, res) {
|
|
985
|
+
var _a, _b;
|
|
986
|
+
await new Promise((resolve2, reject) => {
|
|
987
|
+
cors(req, res, (err) => {
|
|
988
|
+
if (err instanceof Error)
|
|
989
|
+
reject(err);
|
|
990
|
+
else
|
|
991
|
+
resolve2();
|
|
992
|
+
});
|
|
993
|
+
});
|
|
994
|
+
const { makeswift } = req.query;
|
|
995
|
+
if (!Array.isArray(makeswift)) {
|
|
996
|
+
throw new Error(`The Makeswift Next.js API handler must be used in a dynamic catch-all route named \`[...makeswift]\`.
|
|
997
|
+
Received "${makeswift}" for the \`makeswift\` param instead.
|
|
998
|
+
Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes`);
|
|
999
|
+
}
|
|
1000
|
+
const action = makeswift.join("/");
|
|
1001
|
+
switch (action) {
|
|
1002
|
+
case "manifest": {
|
|
1003
|
+
if (req.query.secret !== apiKey)
|
|
1004
|
+
return res.status(401).json({ message: "Unauthorized" });
|
|
1005
|
+
return res.json({
|
|
1006
|
+
version,
|
|
1007
|
+
previewMode: true
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
case "revalidate": {
|
|
1011
|
+
if (req.query.secret !== apiKey) {
|
|
1012
|
+
return res.status(401).json({ message: "Unauthorized" });
|
|
1013
|
+
}
|
|
1014
|
+
if (typeof req.query.path !== "string") {
|
|
1015
|
+
return res.status(400).json({ message: "Bad Request" });
|
|
1016
|
+
}
|
|
1017
|
+
const revalidate = (_a = res.revalidate) != null ? _a : res.unstable_revalidate;
|
|
1018
|
+
if (typeof revalidate !== "function") {
|
|
1019
|
+
const message = `Cannot revalidate path "${req.query.path}" because \`revalidate\` function does not exist in API handler response. Please update to Next.js v12.2.0 or higher for support for on-demand revalidation.
|
|
1020
|
+
Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-regeneration-stable`;
|
|
1021
|
+
console.warn(message);
|
|
1022
|
+
return res.json({ revalidated: false });
|
|
1023
|
+
}
|
|
1024
|
+
try {
|
|
1025
|
+
await revalidate(req.query.path);
|
|
1026
|
+
return res.json({ revalidated: true });
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
return res.status(500).json({ message: "Error Revalidating" });
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
case "proxy-preview-mode": {
|
|
1032
|
+
if (req.query.secret !== apiKey)
|
|
1033
|
+
return res.status(401).send("Unauthorized");
|
|
1034
|
+
const host = req.headers.host;
|
|
1035
|
+
if (host == null)
|
|
1036
|
+
return res.status(400).send("Bad Request");
|
|
1037
|
+
const forwardedProto = req.headers["x-forwarded-proto"];
|
|
1038
|
+
const proto = typeof forwardedProto === "string" ? forwardedProto : "http";
|
|
1039
|
+
let target = `${proto}://${host}`;
|
|
1040
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
1041
|
+
const port = req.socket.localPort;
|
|
1042
|
+
if (port != null)
|
|
1043
|
+
target = `http://localhost:${port}`;
|
|
1044
|
+
}
|
|
1045
|
+
const setCookie = res.setPreviewData({ makeswift: true }).getHeader("Set-Cookie");
|
|
1046
|
+
res.removeHeader("Set-Cookie");
|
|
1047
|
+
if (!Array.isArray(setCookie))
|
|
1048
|
+
return res.status(500).send("Internal Server Error");
|
|
1049
|
+
const cookie = parse$1(setCookie).map((cookie2) => serialize(cookie2.name, cookie2.value, cookie2)).join(";");
|
|
1050
|
+
return await new Promise((resolve2, reject) => previewModeProxy.web(req, res, { target, headers: { cookie } }, (err) => {
|
|
1051
|
+
if (err)
|
|
1052
|
+
reject(err);
|
|
1053
|
+
else
|
|
1054
|
+
resolve2();
|
|
1055
|
+
}));
|
|
1056
|
+
}
|
|
1057
|
+
case "fonts": {
|
|
1058
|
+
const fonts = (_b = await (getFonts == null ? void 0 : getFonts())) != null ? _b : [];
|
|
1059
|
+
return res.json(fonts);
|
|
1060
|
+
}
|
|
1061
|
+
default:
|
|
1062
|
+
return res.status(404).json({ message: "Not Found" });
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
816
1066
|
const FORWARDED_NEXT_DYNAMIC_REF_KEY = "__forwarded_next_dynamic_ref__";
|
|
817
1067
|
function saveForwardedRef(props, ref) {
|
|
818
1068
|
return __spreadProps(__spreadValues({}, props), {
|
|
@@ -839,6 +1089,111 @@ function forwardNextDynamicRef(nextDynamicThunk) {
|
|
|
839
1089
|
})));
|
|
840
1090
|
return forwardRef((props, ref) => /* @__PURE__ */ jsx(Dynamic, __spreadValues({}, saveForwardedRef(props, ref))));
|
|
841
1091
|
}
|
|
1092
|
+
function getApiOrigin() {
|
|
1093
|
+
var _a;
|
|
1094
|
+
const apiOriginString = (_a = process["env"].MAKESWIFT_API_HOST) != null ? _a : "https://api.makeswift.com";
|
|
1095
|
+
try {
|
|
1096
|
+
const url = new URL(apiOriginString);
|
|
1097
|
+
return url.origin;
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
const errorMessage = `"MAKESWIFT_API_HOST" environment variable must be a valid URL. Expected something like "https://api.makeswift.com" but instead received "${apiOriginString}".`;
|
|
1100
|
+
throw new Error(errorMessage);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
const uuidRegExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
|
|
1104
|
+
function getApiKey() {
|
|
1105
|
+
const apiKey = process["env"].MAKESWIFT_SITE_API_KEY;
|
|
1106
|
+
if (apiKey == null) {
|
|
1107
|
+
const errorMessage = '"MAKESWIFT_SITE_API_KEY" environment variable must be set. Please add your site API key to your `.env.local` file. More info: https://www.makeswift.com/docs/guides/manual-setup#add-environment-variables';
|
|
1108
|
+
throw new Error(errorMessage);
|
|
1109
|
+
}
|
|
1110
|
+
if (!uuidRegExp.test(apiKey)) {
|
|
1111
|
+
const errorMEssage = `Invalid Makeswift site API key "${apiKey}". Please check your \`.env.local\` file for the "MAKESWIFT_SITE_API_KEY" environment variable. More info: https://www.makeswift.com/docs/guides/manual-setup#add-environment-variables`;
|
|
1112
|
+
throw new Error(errorMEssage);
|
|
1113
|
+
}
|
|
1114
|
+
return apiKey;
|
|
1115
|
+
}
|
|
1116
|
+
function deprecationWarning(methodName) {
|
|
1117
|
+
const warningMessage = `The \`${methodName}\` export has been deprecated and will be removed in the next minor version. More info: https://github.com/makeswift/makeswift/releases/tag/%40makeswift%2Fruntime%400.2.0`;
|
|
1118
|
+
if (process.env["NODE_ENV"] !== "production")
|
|
1119
|
+
console.warn(warningMessage);
|
|
1120
|
+
}
|
|
1121
|
+
async function getStaticPaths() {
|
|
1122
|
+
deprecationWarning("getStaticPaths");
|
|
1123
|
+
const makeswift = new Makeswift(getApiKey(), {
|
|
1124
|
+
apiOrigin: getApiOrigin()
|
|
1125
|
+
});
|
|
1126
|
+
const pages = await makeswift.getPages();
|
|
1127
|
+
return {
|
|
1128
|
+
paths: pages.map((page) => ({
|
|
1129
|
+
params: {
|
|
1130
|
+
path: page.path.split("/").filter((segment) => segment !== "")
|
|
1131
|
+
}
|
|
1132
|
+
})),
|
|
1133
|
+
fallback: "blocking"
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
const REVALIDATE_SECONDS = 1;
|
|
1137
|
+
async function getStaticProps(ctx) {
|
|
1138
|
+
var _a, _b, _c;
|
|
1139
|
+
deprecationWarning("getStaticProps");
|
|
1140
|
+
const makeswift = new Makeswift(getApiKey(), {
|
|
1141
|
+
apiOrigin: getApiOrigin()
|
|
1142
|
+
});
|
|
1143
|
+
const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
|
|
1144
|
+
const snapshot = await makeswift.getPageSnapshot(path, {
|
|
1145
|
+
preview: ((_c = ctx.previewData) == null ? void 0 : _c.makeswift) === true
|
|
1146
|
+
});
|
|
1147
|
+
if (snapshot == null)
|
|
1148
|
+
return {
|
|
1149
|
+
notFound: true,
|
|
1150
|
+
revalidate: REVALIDATE_SECONDS
|
|
1151
|
+
};
|
|
1152
|
+
return {
|
|
1153
|
+
props: {
|
|
1154
|
+
snapshot
|
|
1155
|
+
},
|
|
1156
|
+
revalidate: REVALIDATE_SECONDS
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
async function getServerSideProps(ctx) {
|
|
1160
|
+
var _a, _b;
|
|
1161
|
+
deprecationWarning("getServerSideProps");
|
|
1162
|
+
const makeswift = new Makeswift(getApiKey(), {
|
|
1163
|
+
apiOrigin: getApiOrigin()
|
|
1164
|
+
});
|
|
1165
|
+
const path = "/" + ((_b = (_a = ctx.params) == null ? void 0 : _a.path) != null ? _b : []).join("/");
|
|
1166
|
+
const snapshot = await makeswift.getPageSnapshot(path, {
|
|
1167
|
+
preview: true
|
|
1168
|
+
});
|
|
1169
|
+
if (snapshot == null)
|
|
1170
|
+
return {
|
|
1171
|
+
notFound: true
|
|
1172
|
+
};
|
|
1173
|
+
return {
|
|
1174
|
+
props: {
|
|
1175
|
+
snapshot
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
const Page = memo(({
|
|
1180
|
+
snapshot
|
|
1181
|
+
}) => {
|
|
1182
|
+
const [client] = useState(() => new MakeswiftClient({
|
|
1183
|
+
uri: new URL("graphql", snapshot.apiOrigin).href,
|
|
1184
|
+
cacheData: snapshot.cacheData
|
|
1185
|
+
}));
|
|
1186
|
+
useEffect(() => {
|
|
1187
|
+
client.updateCacheData(snapshot.cacheData);
|
|
1188
|
+
}, [client, snapshot]);
|
|
1189
|
+
return /* @__PURE__ */ jsx(RuntimeProvider, {
|
|
1190
|
+
client,
|
|
1191
|
+
rootElements: /* @__PURE__ */ new Map([[snapshot.document.id, snapshot.document.data]]),
|
|
1192
|
+
children: /* @__PURE__ */ jsx(Page$1, {
|
|
1193
|
+
document: snapshot.document
|
|
1194
|
+
})
|
|
1195
|
+
});
|
|
1196
|
+
});
|
|
842
1197
|
const keys = (o) => Object.keys(o);
|
|
843
1198
|
const coalesce = (...args) => {
|
|
844
1199
|
let i;
|
|
@@ -3100,5 +3455,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
|
|
|
3100
3455
|
document: document2
|
|
3101
3456
|
});
|
|
3102
3457
|
}));
|
|
3103
|
-
export { Alignments as A, TYPOGRAPHIES_BY_ID as B, Contrasts as C, DocumentReference as D, Element as E, SWATCHES_BY_ID as F, shallowMergeFallbacks as G, join as H, getDevice as I, getDeviceMediaQuery as J, getIndexes as K, isNonNullable as L, MakeswiftComponentType as M, FILES_BY_ID as N, useElementId as O, PageProvider as P,
|
|
3458
|
+
export { Document$1 as $, Alignments as A, TYPOGRAPHIES_BY_ID as B, Contrasts as C, DocumentReference as D, Element as E, SWATCHES_BY_ID as F, shallowMergeFallbacks as G, join as H, getDevice as I, getDeviceMediaQuery as J, getIndexes as K, isNonNullable as L, MakeswiftComponentType as M, FILES_BY_ID as N, useElementId as O, PageProvider as P, deepEqual as Q, RuntimeProvider as R, SITE_FONTS_QUERY as S, TABLE_BY_ID as T, MakeswiftClient as U, getStaticPaths as V, getStaticProps as W, getServerSideProps as X, Page as Y, Makeswift as Z, PreviewModeScript as _, ReactRuntime as a, MakeswiftApiHandler as a0, forwardNextDynamicRef as a1, 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, useResponsiveColor as k, useFile as l, usePage as m, PAGE_SNIPPETS_QUERY as n, Page$1 as o, colorToString as p, useIsomorphicLayoutEffect as q, Shapes as r, Sizes as s, useFormContext as t, useIsInBuilder as u, useQuery as v, useMutation as w, Provider as x, DEVICES as y, findDeviceOverride as z };
|
|
3104
3459
|
//# sourceMappingURL=index.es.js.map
|