@makeswift/runtime 0.0.15 → 0.0.16

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/index.es.js CHANGED
@@ -43,6 +43,9 @@ import { f as registerComponentHandleEffect, g as mountComponentEffect, h as reg
43
43
  import styled, { css, keyframes, createGlobalStyle } from "styled-components";
44
44
  import { useReducedMotion, useAnimation, motion } from "framer-motion";
45
45
  import { cx, css as css$1, cache } from "@emotion/css";
46
+ import { getDataFromTree } from "@apollo/client/react/ssr";
47
+ import { KeyUtils, Value } from "slate";
48
+ import uuid from "uuid/v4";
46
49
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
47
50
  import parse$1 from "html-react-parser";
48
51
  import Head from "next/head";
@@ -52,13 +55,11 @@ import scrollIntoView from "scroll-into-view-if-needed";
52
55
  import NextLink from "next/link";
53
56
  import { useGesture } from "react-use-gesture";
54
57
  import { wrap } from "@popmotion/popcorn";
55
- import uuid from "uuid/v4";
56
58
  import NextImage from "next/image";
57
59
  import { Field as Field$1, getIn, Formik } from "formik";
58
60
  import { p as parse, c as createBox, g as getBox } from "./box-models.es.js";
59
61
  import { normalize } from "polished";
60
62
  import ReactPlayer from "react-player";
61
- import { Value } from "slate";
62
63
  import Hotkeys from "slate-hotkeys";
63
64
  import ipsum from "corporate-ipsum";
64
65
  import { isHotkey } from "is-hotkey";
@@ -305,13 +306,9 @@ const typePolicies = {
305
306
  }
306
307
  }
307
308
  };
308
- const isServer$1 = typeof window === "undefined";
309
- let globalApolloClient = null;
310
- function garbageCollectGlobalCacheData() {
311
- globalApolloClient = null;
312
- }
313
- function getGlobalCacheData() {
314
- return globalApolloClient == null ? void 0 : globalApolloClient.cache.extract();
309
+ const PrefetchContext = createContext(false);
310
+ function useIsPrefetching() {
311
+ return useContext(PrefetchContext);
315
312
  }
316
313
  function createApolloClient({
317
314
  uri,
@@ -324,8 +321,7 @@ function createApolloClient({
324
321
  cache2.restore(cacheData);
325
322
  return new ApolloClient({
326
323
  uri,
327
- cache: cache2,
328
- ssrMode: isServer$1
324
+ cache: cache2
329
325
  });
330
326
  }
331
327
  class MakeswiftClient {
@@ -334,14 +330,25 @@ class MakeswiftClient {
334
330
  cacheData
335
331
  }) {
336
332
  __publicField(this, "apolloClient");
337
- if (globalApolloClient == null)
338
- globalApolloClient = createApolloClient({
339
- uri,
340
- cacheData
341
- });
342
- else if (cacheData != null)
343
- globalApolloClient.cache.restore(cacheData);
344
- this.apolloClient = globalApolloClient;
333
+ this.apolloClient = createApolloClient({
334
+ uri,
335
+ cacheData
336
+ });
337
+ }
338
+ async prefetch(element) {
339
+ const id = uuid();
340
+ await getDataFromTree(/* @__PURE__ */ jsx(PrefetchContext.Provider, {
341
+ value: true,
342
+ children: /* @__PURE__ */ jsx(RuntimeProvider, {
343
+ client: this,
344
+ rootElements: /* @__PURE__ */ new Map([[id, element]]),
345
+ children: /* @__PURE__ */ jsx(DocumentReference, {
346
+ documentReference: createDocumentReference(id)
347
+ })
348
+ })
349
+ }));
350
+ KeyUtils.resetGenerator();
351
+ return this.apolloClient.cache.extract();
345
352
  }
346
353
  updateCacheData(cacheData) {
347
354
  this.apolloClient.cache.restore(cacheData);
@@ -1360,6 +1367,9 @@ const BackgroundsContainer$1 = styled(Container$c)`
1360
1367
  function Backgrounds({
1361
1368
  backgrounds
1362
1369
  }) {
1370
+ const isPrefetching = useIsPrefetching();
1371
+ if (isPrefetching)
1372
+ return /* @__PURE__ */ jsx(Fragment, {});
1363
1373
  if (backgrounds == null)
1364
1374
  return /* @__PURE__ */ jsx(Fragment, {});
1365
1375
  return /* @__PURE__ */ jsx(Fragment, {
@@ -2339,6 +2349,7 @@ const ImageComponent = forwardRef(function Image2({
2339
2349
  const dataDimensions = (fileData == null ? void 0 : fileData.publicUrl) ? fileData == null ? void 0 : fileData.dimensions : placeholder2.dimensions;
2340
2350
  const [measuredDimensions, setMeasuredDimensions] = useState(null);
2341
2351
  const isInBuilder = useIsInBuilder();
2352
+ const isPrefetching = useIsPrefetching();
2342
2353
  useEffect(() => {
2343
2354
  if (dataDimensions)
2344
2355
  return;
@@ -2359,6 +2370,8 @@ const ImageComponent = forwardRef(function Image2({
2359
2370
  if (!dimensions)
2360
2371
  return null;
2361
2372
  const widthClass = css$1(responsiveWidth(width, `${dimensions.width}px`));
2373
+ if (isPrefetching)
2374
+ return null;
2362
2375
  return /* @__PURE__ */ jsx(ImageContainer, {
2363
2376
  as: link ? Link : "div",
2364
2377
  link,
@@ -9009,5 +9022,5 @@ const DocumentReference = memo(forwardRef(function DocumentReference2({
9009
9022
  document: document2
9010
9023
  });
9011
9024
  }));
9012
- export { useBackgrounds as A, Box as B, Carousel as C, DocumentReference as D, Element$1 as E, Form as F, useBorder as G, useBoxShadow as H, ImageComponent as I, useResponsiveColor as J, useFile as K, useMediaQuery as L, usePage as M, Navigation as N, useTable as O, PageProvider as P, PAGE_SNIPPETS_QUERY as Q, RuntimeProvider as R, SocialLinks as S, Text as T, SITE_FONTS_QUERY as U, Page2 as V, garbageCollectGlobalCacheData as W, getGlobalCacheData as X, MakeswiftClient as Y, deepEqual as Z, ReactRuntime as a, usePageId as b, Button$1 as c, Countdown as d, Divider as e, Embed as f, Root as g, registerComponent$c as h, DEFAULT_BOX_ANIMATE_TYPE as i, DEFAULT_BOX_ANIMATE_DELAY as j, DEFAULT_BOX_ANIMATE_DURATION as k, DEFAULT_ITEM_ANIMATE_TYPE as l, DEFAULT_ITEM_ANIMATE_DELAY as m, DEFAULT_ITEM_ANIMATE_DURATION as n, DEFAULT_ITEM_STAGGER_DURATION as o, cssMediaRules as p, cssWidth as q, registerBuiltinComponents as r, cssMargin as s, cssPadding as t, useIsInBuilder as u, cssBorder as v, cssBorderRadius as w, cssBoxShadow as x, cssGridItem as y, cssTextStyle as z };
9025
+ export { useBackgrounds as A, Box as B, Carousel as C, DocumentReference as D, Element$1 as E, Form as F, useBorder as G, useBoxShadow as H, ImageComponent as I, useResponsiveColor as J, useFile as K, useMediaQuery as L, usePage as M, Navigation as N, useTable as O, PageProvider as P, PAGE_SNIPPETS_QUERY as Q, RuntimeProvider as R, SocialLinks as S, Text as T, SITE_FONTS_QUERY as U, Page2 as V, MakeswiftClient as W, deepEqual as X, ReactRuntime as a, usePageId as b, Button$1 as c, Countdown as d, Divider as e, Embed as f, Root as g, registerComponent$c as h, DEFAULT_BOX_ANIMATE_TYPE as i, DEFAULT_BOX_ANIMATE_DELAY as j, DEFAULT_BOX_ANIMATE_DURATION as k, DEFAULT_ITEM_ANIMATE_TYPE as l, DEFAULT_ITEM_ANIMATE_DELAY as m, DEFAULT_ITEM_ANIMATE_DURATION as n, DEFAULT_ITEM_STAGGER_DURATION as o, cssMediaRules as p, cssWidth as q, registerBuiltinComponents as r, cssMargin as s, cssPadding as t, useIsInBuilder as u, cssBorder as v, cssBorderRadius as w, cssBoxShadow as x, cssGridItem as y, cssTextStyle as z };
9013
9026
  //# sourceMappingURL=index.es.js.map