@makeswift/runtime 0.4.1 → 0.5.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.
Files changed (92) hide show
  1. package/dist/Box.cjs.js +5 -3
  2. package/dist/Box.cjs.js.map +1 -1
  3. package/dist/Box.es.js +5 -3
  4. package/dist/Box.es.js.map +1 -1
  5. package/dist/Button.cjs.js +3 -3
  6. package/dist/Button.es.js +3 -3
  7. package/dist/Carousel.cjs.js +5 -3
  8. package/dist/Carousel.cjs.js.map +1 -1
  9. package/dist/Carousel.es.js +5 -3
  10. package/dist/Carousel.es.js.map +1 -1
  11. package/dist/Countdown.cjs.js +3 -3
  12. package/dist/Countdown.es.js +3 -3
  13. package/dist/Divider.cjs.js +3 -3
  14. package/dist/Divider.es.js +3 -3
  15. package/dist/Embed.cjs.js +3 -3
  16. package/dist/Embed.es.js +3 -3
  17. package/dist/Form.cjs.js +3 -3
  18. package/dist/Form.es.js +3 -3
  19. package/dist/Image.cjs.js +20 -12
  20. package/dist/Image.cjs.js.map +1 -1
  21. package/dist/Image.es.js +20 -12
  22. package/dist/Image.es.js.map +1 -1
  23. package/dist/LiveProvider.cjs.js +62 -0
  24. package/dist/LiveProvider.cjs.js.map +1 -0
  25. package/dist/LiveProvider.es.js +60 -0
  26. package/dist/LiveProvider.es.js.map +1 -0
  27. package/dist/Navigation.cjs.js +5 -3
  28. package/dist/Navigation.cjs.js.map +1 -1
  29. package/dist/Navigation.es.js +5 -3
  30. package/dist/Navigation.es.js.map +1 -1
  31. package/dist/{react-builder-preview.cjs.js → PreviewProvider.cjs.js} +43 -16
  32. package/dist/PreviewProvider.cjs.js.map +1 -0
  33. package/dist/{react-builder-preview.es.js → PreviewProvider.es.js} +47 -15
  34. package/dist/PreviewProvider.es.js.map +1 -0
  35. package/dist/Root.cjs.js +5 -3
  36. package/dist/Root.cjs.js.map +1 -1
  37. package/dist/Root.es.js +5 -3
  38. package/dist/Root.es.js.map +1 -1
  39. package/dist/SocialLinks.cjs.js +3 -3
  40. package/dist/SocialLinks.es.js +3 -3
  41. package/dist/Text.cjs.js +3 -3
  42. package/dist/Text.cjs.js.map +1 -1
  43. package/dist/Text.es.js +3 -3
  44. package/dist/Text.es.js.map +1 -1
  45. package/dist/Video.cjs.js +3 -3
  46. package/dist/Video.es.js +3 -3
  47. package/dist/actions.es.js +1 -1
  48. package/dist/components.cjs.js +5 -3
  49. package/dist/components.cjs.js.map +1 -1
  50. package/dist/components.es.js +5 -3
  51. package/dist/components.es.js.map +1 -1
  52. package/dist/grid-item.cjs.js +12 -1
  53. package/dist/grid-item.cjs.js.map +1 -1
  54. package/dist/grid-item.es.js +12 -1
  55. package/dist/grid-item.es.js.map +1 -1
  56. package/dist/index.cjs.js +56 -81
  57. package/dist/index.cjs.js.map +1 -1
  58. package/dist/index.cjs2.js +6 -7
  59. package/dist/index.cjs2.js.map +1 -1
  60. package/dist/index.es.js +51 -81
  61. package/dist/index.es.js.map +1 -1
  62. package/dist/index.es2.js +6 -7
  63. package/dist/index.es2.js.map +1 -1
  64. package/dist/next-version.cjs.js +10 -0
  65. package/dist/next-version.cjs.js.map +1 -0
  66. package/dist/next-version.es.js +5 -0
  67. package/dist/next-version.es.js.map +1 -0
  68. package/dist/next.cjs.js +3 -3
  69. package/dist/next.es.js +4 -4
  70. package/dist/react-page.es.js +1 -1
  71. package/dist/react.cjs.js +4 -4
  72. package/dist/react.es.js +4 -4
  73. package/dist/types/src/components/builtin/Form/components/Field/components/Checkbox/index.d.ts +1 -1
  74. package/dist/types/src/components/builtin/Image/Image.d.ts.map +1 -1
  75. package/dist/types/src/components/shared/BackgroundsContainer/components/Backgrounds/index.d.ts.map +1 -1
  76. package/dist/types/src/components/shared/Link/index.d.ts.map +1 -1
  77. package/dist/types/src/next/client.d.ts +1 -0
  78. package/dist/types/src/next/client.d.ts.map +1 -1
  79. package/dist/types/src/next/index.d.ts.map +1 -1
  80. package/dist/types/src/next/next-version.d.ts +3 -0
  81. package/dist/types/src/next/next-version.d.ts.map +1 -0
  82. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts +11 -0
  83. package/dist/types/src/runtimes/react/components/LiveProvider.d.ts.map +1 -0
  84. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts +11 -0
  85. package/dist/types/src/runtimes/react/components/PreviewProvider.d.ts.map +1 -0
  86. package/dist/types/src/runtimes/react/index.d.ts +3 -1
  87. package/dist/types/src/runtimes/react/index.d.ts.map +1 -1
  88. package/dist/types/src/state/react-builder-preview.d.ts +3 -1
  89. package/dist/types/src/state/react-builder-preview.d.ts.map +1 -1
  90. package/package.json +4 -4
  91. package/dist/react-builder-preview.cjs.js.map +0 -1
  92. package/dist/react-builder-preview.es.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -38,20 +38,20 @@ var __publicField = (obj, key, value) => {
38
38
  var _c;
39
39
  var React = require("react");
40
40
  var withSelector = require("use-sync-external-store/shim/with-selector");
41
+ var dynamic = require("next/dynamic");
41
42
  var reactPage = require("./react-page.cjs.js");
42
43
  var actions = require("./actions.cjs.js");
43
- var dynamic = require("next/dynamic");
44
- var slate = require("slate");
44
+ var css = require("@emotion/css");
45
+ var jsxRuntime = require("react/jsx-runtime");
45
46
  var slot = require("./slot.cjs.js");
47
+ var textInput = require("./text-input.cjs.js");
48
+ var combobox = require("./combobox.cjs.js");
46
49
  var control = require("./control.cjs.js");
50
+ var shim = require("use-sync-external-store/shim");
51
+ var slate = require("slate");
47
52
  var redux = require("redux");
48
53
  var thunk = require("redux-thunk");
49
54
  var types = require("./types.cjs.js");
50
- var jsxRuntime = require("react/jsx-runtime");
51
- var css = require("@emotion/css");
52
- var textInput = require("./text-input.cjs.js");
53
- var combobox = require("./combobox.cjs.js");
54
- var shim = require("use-sync-external-store/shim");
55
55
  var ColorHelper = require("color");
56
56
  var scrollIntoView = require("scroll-into-view-if-needed");
57
57
  var boxModels = require("./box-models.cjs.js");
@@ -682,17 +682,17 @@ class MakeswiftClient {
682
682
  return getAPIResource(this.makeswiftApiClient.getState(), types.APIResourceType.Snippet, snippetId);
683
683
  }
684
684
  }
685
- const Context$2 = React.createContext(new MakeswiftClient({
685
+ const Context$1 = React.createContext(new MakeswiftClient({
686
686
  uri: "https://api.makeswift.com/graphql"
687
687
  }));
688
688
  function useMakeswiftClient() {
689
- return React.useContext(Context$2);
689
+ return React.useContext(Context$1);
690
690
  }
691
691
  function MakeswiftProvider({
692
692
  client,
693
693
  children
694
694
  }) {
695
- return /* @__PURE__ */ jsxRuntime.jsx(Context$2.Provider, {
695
+ return /* @__PURE__ */ jsxRuntime.jsx(Context$1.Provider, {
696
696
  value: client,
697
697
  children
698
698
  });
@@ -964,10 +964,10 @@ Received "${apiKey}" instead.`);
964
964
  const json = await response.json();
965
965
  return json;
966
966
  }
967
- async createSnapshot(document2) {
967
+ async createSnapshot(document2, preview) {
968
968
  const client = new MakeswiftClient({ uri: new URL("graphql", this.apiOrigin).href });
969
969
  const cacheData = await client.prefetch(document2.data);
970
- return { document: document2, apiOrigin: this.apiOrigin.href, cacheData };
970
+ return { document: document2, apiOrigin: this.apiOrigin.href, cacheData, preview };
971
971
  }
972
972
  async getPageSnapshotByPageId(pageId, { preview = false } = {}) {
973
973
  const searchParams = new URLSearchParams({ preview: String(preview) });
@@ -978,7 +978,7 @@ Received "${apiKey}" instead.`);
978
978
  throw new Error(`Failed to get snapshot with error: "${response.statusText}"`);
979
979
  }
980
980
  const document2 = await response.json();
981
- return await this.createSnapshot(document2);
981
+ return await this.createSnapshot(document2, preview);
982
982
  }
983
983
  async getPageSnapshot(path, { preview } = {}) {
984
984
  const [page] = await this.getPages({ path });
@@ -1085,7 +1085,7 @@ class Document$1 extends NextDocument__default["default"] {
1085
1085
  });
1086
1086
  }
1087
1087
  }
1088
- const version = "0.4.1";
1088
+ const version = "0.5.0";
1089
1089
  function isErrorWithMessage(error) {
1090
1090
  return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
1091
1091
  }
@@ -1103,7 +1103,7 @@ function MakeswiftApiHandler(apiKey, { appOrigin = "https://app.makeswift.com",
1103
1103
  Received "${apiKey}" instead.`);
1104
1104
  }
1105
1105
  return async function makeswiftApiHandler(req, res) {
1106
- var _a, _b;
1106
+ var _a;
1107
1107
  await new Promise((resolve2, reject) => {
1108
1108
  cors(req, res, (err) => {
1109
1109
  if (err instanceof Error)
@@ -1135,7 +1135,7 @@ Read more about dynamic catch-all routes here: https://nextjs.org/docs/routing/d
1135
1135
  if (typeof req.query.path !== "string") {
1136
1136
  return res.status(400).json({ message: "Bad Request" });
1137
1137
  }
1138
- const revalidate = (_a = res.revalidate) != null ? _a : res.unstable_revalidate;
1138
+ const revalidate = res.revalidate;
1139
1139
  if (typeof revalidate !== "function") {
1140
1140
  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.
1141
1141
  Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-regeneration-stable`;
@@ -1182,7 +1182,7 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1182
1182
  }));
1183
1183
  }
1184
1184
  case "fonts": {
1185
- const fonts = (_b = await (getFonts == null ? void 0 : getFonts())) != null ? _b : [];
1185
+ const fonts = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
1186
1186
  return res.json(fonts);
1187
1187
  }
1188
1188
  case "element-tree": {
@@ -1329,6 +1329,7 @@ const Page = React.memo(({
1329
1329
  return /* @__PURE__ */ jsxRuntime.jsx(RuntimeProvider, {
1330
1330
  client,
1331
1331
  rootElements: /* @__PURE__ */ new Map([[snapshot.document.id, snapshot.document.data]]),
1332
+ preview: snapshot.preview,
1332
1333
  children: /* @__PURE__ */ jsxRuntime.jsx(Page$1, {
1333
1334
  document: snapshot.document
1334
1335
  })
@@ -1885,11 +1886,11 @@ const Contrasts = Object.freeze({
1885
1886
  LIGHT: "light",
1886
1887
  DARK: "dark"
1887
1888
  });
1888
- const Context$1 = React.createContext({});
1889
+ const Context = React.createContext({});
1889
1890
  function useFormContext() {
1890
- return React.useContext(Context$1);
1891
+ return React.useContext(Context);
1891
1892
  }
1892
- const { Provider } = Context$1;
1893
+ const { Provider } = Context;
1893
1894
  function registerComponent$6(runtime) {
1894
1895
  return runtime.registerComponent(forwardNextDynamicRef((patch) => dynamic__default["default"](() => patch(Promise.resolve().then(function() {
1895
1896
  return require("./Form.cjs.js");
@@ -2908,13 +2909,13 @@ function paddingPropertyDataToStyle(data, defaultValue = {}) {
2908
2909
  const paddingBottom = (_c2 = data.paddingBottom) != null ? _c2 : defaultValue.paddingBottom;
2909
2910
  const paddingLeft = (_d = data.paddingLeft) != null ? _d : defaultValue.paddingLeft;
2910
2911
  const style = {};
2911
- if (paddingTop)
2912
+ if (paddingTop != null)
2912
2913
  style.paddingTop = lengthDataToString(paddingTop);
2913
- if (paddingRight)
2914
+ if (paddingRight != null)
2914
2915
  style.paddingRight = lengthDataToString(paddingRight);
2915
- if (paddingBottom)
2916
+ if (paddingBottom != null)
2916
2917
  style.paddingBottom = lengthDataToString(paddingBottom);
2917
- if (paddingLeft)
2918
+ if (paddingLeft != null)
2918
2919
  style.paddingLeft = lengthDataToString(paddingLeft);
2919
2920
  return style;
2920
2921
  }
@@ -2925,13 +2926,13 @@ function marginPropertyDataToStyle(data, defaultValue = {}) {
2925
2926
  const marginBottom = (_c2 = data.marginBottom) != null ? _c2 : defaultValue.marginBottom;
2926
2927
  const marginLeft = (_d = data.marginLeft) != null ? _d : defaultValue.marginLeft;
2927
2928
  const style = {};
2928
- if (marginTop)
2929
+ if (marginTop != null)
2929
2930
  style.marginTop = lengthDataToString(marginTop);
2930
- if (marginRight)
2931
+ if (marginRight != null)
2931
2932
  style.marginRight = lengthDataToString(marginRight);
2932
- if (marginBottom)
2933
+ if (marginBottom != null)
2933
2934
  style.marginBottom = lengthDataToString(marginBottom);
2934
- if (marginLeft)
2935
+ if (marginLeft != null)
2935
2936
  style.marginLeft = lengthDataToString(marginLeft);
2936
2937
  return style;
2937
2938
  }
@@ -2949,16 +2950,16 @@ function borderRadiusPropertyDataToStyle(data, defaultValue = {}) {
2949
2950
  const borderBottomRightRadius = (_c2 = data.borderBottomRightRadius) != null ? _c2 : defaultValue.borderBottomRightRadius;
2950
2951
  const borderBottomLeftRadius = (_d = data.borderBottomLeftRadius) != null ? _d : defaultValue.borderBottomLeftRadius;
2951
2952
  const style = {};
2952
- if (borderTopLeftRadius) {
2953
+ if (borderTopLeftRadius != null) {
2953
2954
  style.borderTopLeftRadius = lengthPercentageDataToString(borderTopLeftRadius);
2954
2955
  }
2955
- if (borderTopRightRadius) {
2956
+ if (borderTopRightRadius != null) {
2956
2957
  style.borderTopRightRadius = lengthPercentageDataToString(borderTopRightRadius);
2957
2958
  }
2958
- if (borderBottomRightRadius) {
2959
+ if (borderBottomRightRadius != null) {
2959
2960
  style.borderBottomRightRadius = lengthPercentageDataToString(borderBottomRightRadius);
2960
2961
  }
2961
- if (borderBottomLeftRadius) {
2962
+ if (borderBottomLeftRadius != null) {
2962
2963
  style.borderBottomLeftRadius = lengthPercentageDataToString(borderBottomLeftRadius);
2963
2964
  }
2964
2965
  return style;
@@ -2973,13 +2974,13 @@ function borderPropertyDataToStyle(data, defaultValue = {}) {
2973
2974
  const borderBottom = (_c2 = data.borderBottom) != null ? _c2 : defaultValue.borderBottom;
2974
2975
  const borderLeft = (_d = data.borderLeft) != null ? _d : defaultValue.borderLeft;
2975
2976
  const style = {};
2976
- if (borderTop)
2977
+ if (borderTop != null)
2977
2978
  style.borderTop = borderSideToString(borderTop);
2978
- if (borderRight)
2979
+ if (borderRight != null)
2979
2980
  style.borderRight = borderSideToString(borderRight);
2980
- if (borderBottom)
2981
+ if (borderBottom != null)
2981
2982
  style.borderBottom = borderSideToString(borderBottom);
2982
- if (borderLeft)
2983
+ if (borderLeft != null)
2983
2984
  style.borderLeft = borderSideToString(borderLeft);
2984
2985
  return style;
2985
2986
  }
@@ -3787,49 +3788,20 @@ function createReactRuntime(store) {
3787
3788
  }
3788
3789
  const ReactRuntime = createReactRuntime(storeContextDefaultValue);
3789
3790
  registerBuiltinComponents(ReactRuntime);
3790
- const Context = React.createContext(storeContextDefaultValue);
3791
- function RuntimeProvider({
3792
- client,
3793
- children,
3794
- rootElements
3795
- }) {
3796
- const [store, setStore] = React.useState(() => {
3797
- const store2 = reactPage.configureStore({
3798
- preloadedState: storeContextDefaultValue.getState(),
3799
- rootElements
3800
- });
3801
- return store2;
3802
- });
3803
- React.useEffect(() => {
3804
- var _a;
3805
- const unregisterDocuments = Array.from((_a = rootElements == null ? void 0 : rootElements.entries()) != null ? _a : []).map(([documentKey, rootElement]) => store.dispatch(actions.registerDocumentEffect(reactPage.createDocument(documentKey, rootElement))));
3806
- return () => {
3807
- unregisterDocuments.forEach((unregisterDocument) => {
3808
- unregisterDocument();
3809
- });
3810
- };
3811
- }, [store, rootElements]);
3812
- React.useEffect(() => {
3813
- const isInBuilder = window.parent !== window;
3814
- if (isInBuilder)
3815
- setReactBuilderPreviewStore();
3816
- async function setReactBuilderPreviewStore() {
3817
- const ReactBuilderPreview = await Promise.resolve().then(function() {
3818
- return require("./react-builder-preview.cjs.js");
3819
- });
3820
- setStore((store2) => ReactBuilderPreview.configureStore({
3821
- preloadedState: store2.getState(),
3822
- client
3823
- }));
3824
- }
3825
- }, [client]);
3826
- return /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, {
3827
- value: store,
3828
- children: /* @__PURE__ */ jsxRuntime.jsx(MakeswiftProvider, {
3829
- client,
3830
- children
3831
- })
3832
- });
3791
+ const StoreContext = React.createContext(storeContextDefaultValue);
3792
+ const PreviewProvider = dynamic__default["default"](() => Promise.resolve().then(function() {
3793
+ return require("./PreviewProvider.cjs.js");
3794
+ }));
3795
+ const LiveProvider = dynamic__default["default"](() => Promise.resolve().then(function() {
3796
+ return require("./LiveProvider.cjs.js");
3797
+ }));
3798
+ function RuntimeProvider(_j) {
3799
+ var _k = _j, {
3800
+ preview
3801
+ } = _k, props = __objRest(_k, [
3802
+ "preview"
3803
+ ]);
3804
+ return preview ? /* @__PURE__ */ jsxRuntime.jsx(PreviewProvider, __spreadValues({}, props)) : /* @__PURE__ */ jsxRuntime.jsx(LiveProvider, __spreadValues({}, props));
3833
3805
  }
3834
3806
  const PageContext = React.createContext(null);
3835
3807
  function usePageIdOrNull() {
@@ -3855,7 +3827,7 @@ function useDocumentKey() {
3855
3827
  return React.useContext(DocumentContext);
3856
3828
  }
3857
3829
  function useStore() {
3858
- return React.useContext(Context);
3830
+ return React.useContext(StoreContext);
3859
3831
  }
3860
3832
  function useSelector(selector) {
3861
3833
  const store = useStore();
@@ -3875,7 +3847,7 @@ function useIsInBuilder() {
3875
3847
  return useSelector((state) => reactPage.getIsInBuilder(state));
3876
3848
  }
3877
3849
  function useDispatch() {
3878
- const store = React.useContext(Context);
3850
+ const store = React.useContext(StoreContext);
3879
3851
  return store.dispatch;
3880
3852
  }
3881
3853
  const originalError = console.error;
@@ -4012,6 +3984,7 @@ exports.Makeswift = Makeswift;
4012
3984
  exports.MakeswiftApiHandler = MakeswiftApiHandler;
4013
3985
  exports.MakeswiftClient = MakeswiftClient;
4014
3986
  exports.MakeswiftComponentType = MakeswiftComponentType;
3987
+ exports.MakeswiftProvider = MakeswiftProvider;
4015
3988
  exports.Page = Page$1;
4016
3989
  exports.Page$1 = Page;
4017
3990
  exports.PageProvider = PageProvider;
@@ -4021,6 +3994,7 @@ exports.ReactRuntime = ReactRuntime;
4021
3994
  exports.RuntimeProvider = RuntimeProvider;
4022
3995
  exports.Shapes = Shapes;
4023
3996
  exports.Sizes = Sizes;
3997
+ exports.StoreContext = StoreContext;
4024
3998
  exports.colorToString = colorToString;
4025
3999
  exports.deepEqual = deepEqual;
4026
4000
  exports.findDeviceOverride = findDeviceOverride;
@@ -4036,6 +4010,7 @@ exports.responsiveTextStyle = responsiveTextStyle;
4036
4010
  exports.responsiveWidth = responsiveWidth;
4037
4011
  exports.serializeStyles = serializeStyles;
4038
4012
  exports.shallowMergeFallbacks = shallowMergeFallbacks;
4013
+ exports.storeContextDefaultValue = storeContextDefaultValue;
4039
4014
  exports.useBorder = useBorder;
4040
4015
  exports.useBoxShadow = useBoxShadow;
4041
4016
  exports.useElementId = useElementId;