@makeswift/runtime 0.5.1 → 0.5.3

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
@@ -40,7 +40,7 @@ import { useEffect, createContext, useContext, useState, useMemo, useRef, Childr
40
40
  import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
41
41
  import dynamic from "next/dynamic";
42
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, k as getBorderSwatchIds, l as isNonNullable, m as getBoxShadowsSwatchIds, n as getResponsiveColorSwatchIds, o as getComponentPropControllerDescriptors, p as getPropControllers, q as configureStore$1, r as getDocument, s as getElementId, t as getIsInBuilder, u as copyElementTree, v as getReactComponent } from "./react-page.es.js";
43
- import { A as ActionTypes, f as introspectedResourcesFulfilled, g as apiResourceFulfilled, t as typographiesFulfilled, h as restoreAPIResourcesCache, j as registerComponentHandleEffect, k as mountComponentEffect, l as registerComponentEffect, n as registerReactComponentEffect } from "./actions.es.js";
43
+ import { A as ActionTypes, f as introspectedResourcesFulfilled, g as apiResourceFulfilled, t as typographiesFulfilled, h as registerComponentHandleEffect, j as mountComponentEffect, k as registerComponentEffect, l as registerReactComponentEffect } from "./actions.es.js";
44
44
  import { cache, cx } from "@emotion/css";
45
45
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
46
46
  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, r as ResponsiveColor, s as TextStyle, t as Images, N as Number$1, D as Date$1, F as Font, u as ResponsiveLength, v as TextArea, w as Table, x as TableFormFields, y as Image, z as ResponsiveOpacity, A as NavigationLinks, H as SocialLinks, J as RichText, V as Video, K as StyleControlProperty, O as ImageControlValueFormat, I as ImageControlType, C as ColorControlType, Q as BorderPropControllerFormat, U as ShadowsPropControllerFormat, X as BorderRadiusPropControllerFormat, Y as MarginPropControllerFormat, Z as PaddingPropControllerFormat, _ as WidthPropControllerFormat, S as SlotControlType, a as StyleControlType } from "./slot.es.js";
@@ -192,6 +192,43 @@ async function introspect(element, client, store) {
192
192
  pageIds: [...pageIds]
193
193
  };
194
194
  }
195
+ function is(x, y) {
196
+ if (x === y)
197
+ return x !== 0 || y !== 0 || 1 / x === 1 / y;
198
+ return x !== x && y !== y;
199
+ }
200
+ const { hasOwnProperty: hasOwnProperty$1 } = Object.prototype;
201
+ const shallowEqual = (a, b) => {
202
+ if (is(a, b))
203
+ return true;
204
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
205
+ return false;
206
+ const keysA = Object.keys(a);
207
+ const keysB = Object.keys(b);
208
+ if (keysA.length !== keysB.length)
209
+ return false;
210
+ for (let i = 0; i < keysA.length; i += 1) {
211
+ if (!hasOwnProperty$1.call(b, keysA[i]) || !is(a[keysA[i]], b[keysA[i]]))
212
+ return false;
213
+ }
214
+ return true;
215
+ };
216
+ const { hasOwnProperty } = Object.prototype;
217
+ const deepEqual = (a, b) => {
218
+ if (shallowEqual(a, b))
219
+ return true;
220
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
221
+ return false;
222
+ const keysA = Object.keys(a);
223
+ const keysB = Object.keys(b);
224
+ if (keysA.length !== keysB.length)
225
+ return false;
226
+ for (let i = 0; i < keysA.length; i += 1) {
227
+ if (!hasOwnProperty.call(b, keysA[i]) || !deepEqual(a[keysA[i]], b[keysA[i]]))
228
+ return false;
229
+ }
230
+ return true;
231
+ };
195
232
  function getInitialState(serializedState = []) {
196
233
  return new Map(serializedState.map(([resourceType, resources]) => [resourceType, new Map(resources)]));
197
234
  }
@@ -212,8 +249,6 @@ function getAPIResource$1(state, resourceType, resourceId) {
212
249
  }
213
250
  function reducer$1(state = getInitialState(), action) {
214
251
  switch (action.type) {
215
- case ActionTypes.RESTORE_API_RESOURCES_CACHE:
216
- return getInitialState(action.payload.serializedState);
217
252
  case ActionTypes.API_RESOURCE_FULFILLED: {
218
253
  const { resourceType, resourceId, resource } = action.payload;
219
254
  return new Map(state).set(resourceType, new Map(state.get(resourceType)).set(resourceId, resource));
@@ -255,8 +290,12 @@ function reducer$1(state = getInitialState(), action) {
255
290
  });
256
291
  return new Map(state).set(APIResourceType.Typography, typographies);
257
292
  }
258
- case ActionTypes.CHANGE_API_RESOURCE:
293
+ case ActionTypes.CHANGE_API_RESOURCE: {
294
+ const existingApiResource = getAPIResource$1(state, action.payload.resource.__typename, action.payload.resource.id);
295
+ if (deepEqual(existingApiResource, action.payload.resource))
296
+ return state;
259
297
  return new Map(state).set(action.payload.resource.__typename, new Map(state.get(action.payload.resource.__typename)).set(action.payload.resource.id, action.payload.resource));
298
+ }
260
299
  case ActionTypes.EVICT_API_RESOURCE: {
261
300
  const [resourceType, resourceId] = action.payload.id.split(":");
262
301
  if (!(resourceType in APIResourceType))
@@ -585,9 +624,6 @@ class MakeswiftClient {
585
624
  KeyUtils.resetGenerator();
586
625
  return getSerializedState(this.makeswiftApiClient.getState());
587
626
  }
588
- updateCacheData(cacheData) {
589
- this.makeswiftApiClient.dispatch(restoreAPIResourcesCache(cacheData));
590
- }
591
627
  readSwatch(swatchId) {
592
628
  return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Swatch, swatchId);
593
629
  }
@@ -662,43 +698,6 @@ function MakeswiftProvider({
662
698
  children
663
699
  });
664
700
  }
665
- function is(x, y) {
666
- if (x === y)
667
- return x !== 0 || y !== 0 || 1 / x === 1 / y;
668
- return x !== x && y !== y;
669
- }
670
- const { hasOwnProperty: hasOwnProperty$1 } = Object.prototype;
671
- const shallowEqual = (a, b) => {
672
- if (is(a, b))
673
- return true;
674
- if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
675
- return false;
676
- const keysA = Object.keys(a);
677
- const keysB = Object.keys(b);
678
- if (keysA.length !== keysB.length)
679
- return false;
680
- for (let i = 0; i < keysA.length; i += 1) {
681
- if (!hasOwnProperty$1.call(b, keysA[i]) || !is(a[keysA[i]], b[keysA[i]]))
682
- return false;
683
- }
684
- return true;
685
- };
686
- const { hasOwnProperty } = Object.prototype;
687
- const deepEqual = (a, b) => {
688
- if (shallowEqual(a, b))
689
- return true;
690
- if (typeof a !== "object" || a === null || typeof b !== "object" || b === null)
691
- return false;
692
- const keysA = Object.keys(a);
693
- const keysB = Object.keys(b);
694
- if (keysA.length !== keysB.length)
695
- return false;
696
- for (let i = 0; i < keysA.length; i += 1) {
697
- if (!hasOwnProperty.call(b, keysA[i]) || !deepEqual(a[keysA[i]], b[keysA[i]]))
698
- return false;
699
- }
700
- return true;
701
- };
702
701
  const SnippetLocation = {
703
702
  Body: "BODY",
704
703
  Head: "HEAD"
@@ -1050,7 +1049,7 @@ class Document$1 extends NextDocument {
1050
1049
  });
1051
1050
  }
1052
1051
  }
1053
- const version = "0.5.1";
1052
+ const version = "0.5.3";
1054
1053
  function isErrorWithMessage(error) {
1055
1054
  return typeof error === "object" && error !== null && "message" in error && typeof error.message === "string";
1056
1055
  }
@@ -1284,13 +1283,10 @@ async function getServerSideProps(ctx) {
1284
1283
  const Page = memo(({
1285
1284
  snapshot
1286
1285
  }) => {
1287
- const [client] = useState(() => new MakeswiftClient({
1286
+ const client = useMemo(() => new MakeswiftClient({
1288
1287
  uri: new URL("graphql", snapshot.apiOrigin).href,
1289
1288
  cacheData: snapshot.cacheData
1290
- }));
1291
- useEffect(() => {
1292
- client.updateCacheData(snapshot.cacheData);
1293
- }, [client, snapshot]);
1289
+ }), [snapshot]);
1294
1290
  return /* @__PURE__ */ jsx(RuntimeProvider, {
1295
1291
  client,
1296
1292
  rootElements: /* @__PURE__ */ new Map([[snapshot.document.id, snapshot.document.data]]),