@makeswift/runtime 0.6.7 → 0.7.1

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
@@ -39,7 +39,7 @@ 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, y as getBuilderEditMode } from "./constants.es.js";
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$1, 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
43
  import { A as ActionTypes, h as introspectedResourcesFulfilled, j as apiResourceFulfilled, t as typographiesFulfilled, k as registerComponentHandleEffect, l as mountComponentEffect, n as registerComponentEffect, o as registerReactComponentEffect } from "./actions.es.js";
44
44
  import { cache, cx } from "@emotion/css";
45
45
  import { serializeStyles } from "@emotion/serialize";
@@ -199,6 +199,24 @@ async function introspect(element, client, store) {
199
199
  pageIds: [...pageIds]
200
200
  };
201
201
  }
202
+ function normalizeToMakeswiftResources(partialResources) {
203
+ const resources = {
204
+ swatches: (partialResources == null ? void 0 : partialResources.swatches) || [],
205
+ typographies: (partialResources == null ? void 0 : partialResources.typographies) || [],
206
+ files: (partialResources == null ? void 0 : partialResources.files) || [],
207
+ tables: (partialResources == null ? void 0 : partialResources.tables) || [],
208
+ pagePathnameSlices: (partialResources == null ? void 0 : partialResources.pagePathnameSlices) || [],
209
+ globalElements: (partialResources == null ? void 0 : partialResources.globalElements) || [],
210
+ snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
211
+ fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
212
+ pageMetadata: (partialResources == null ? void 0 : partialResources.pageMetadata) || {},
213
+ pageSeo: (partialResources == null ? void 0 : partialResources.pageSeo) || {}
214
+ };
215
+ return resources;
216
+ }
217
+ function fileToFileSnapshot(file) {
218
+ return file;
219
+ }
202
220
  function is(x, y) {
203
221
  if (x === y)
204
222
  return x !== 0 || y !== 0 || 1 / x === 1 / y;
@@ -236,11 +254,15 @@ const deepEqual = (a, b) => {
236
254
  }
237
255
  return true;
238
256
  };
257
+ function isNonNullable(value) {
258
+ return value != null;
259
+ }
239
260
  function getSnapshotResourcesFromSerializedState(serializedState) {
240
261
  const resources = {
241
262
  swatches: serializedState.Swatch.filter((_) => true),
242
263
  typographies: serializedState.Typography.filter((_) => true),
243
- files: serializedState.File.filter((_) => true),
264
+ files: serializedState.File.map(({ id, value }) => value.__typename === APIResourceType.File ? { id, value: fileToFileSnapshot(value) } : null).filter(isNonNullable),
265
+ tables: serializedState.Table.filter((_) => true),
244
266
  pagePathnameSlices: serializedState.PagePathnameSlice.filter((_) => true),
245
267
  globalElements: serializedState.GlobalElement.filter((_) => true)
246
268
  };
@@ -369,7 +391,7 @@ const FileFragment = `
369
391
  __typename
370
392
  id
371
393
  name
372
- publicUrl
394
+ publicUrl: publicUrlV2
373
395
  extension
374
396
  dimensions {
375
397
  width
@@ -944,21 +966,7 @@ function useCachedSite(siteId) {
944
966
  const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
945
967
  return site;
946
968
  }
947
- const version = "0.6.7";
948
- function normalizeToMakeswiftResources(partialResources) {
949
- const resources = {
950
- swatches: (partialResources == null ? void 0 : partialResources.swatches) || [],
951
- typographies: (partialResources == null ? void 0 : partialResources.typographies) || [],
952
- files: (partialResources == null ? void 0 : partialResources.files) || [],
953
- pagePathnameSlices: (partialResources == null ? void 0 : partialResources.pagePathnameSlices) || [],
954
- globalElements: (partialResources == null ? void 0 : partialResources.globalElements) || [],
955
- snippets: (partialResources == null ? void 0 : partialResources.snippets) || [],
956
- fonts: (partialResources == null ? void 0 : partialResources.fonts) || [],
957
- pageMetadata: (partialResources == null ? void 0 : partialResources.pageMetadata) || {},
958
- pageSeo: (partialResources == null ? void 0 : partialResources.pageSeo) || {}
959
- };
960
- return resources;
961
- }
969
+ const version = "0.7.1";
962
970
  class Makeswift {
963
971
  constructor(apiKey, { apiOrigin = "https://api.makeswift.com" } = {}) {
964
972
  __publicField(this, "apiKey");
@@ -1100,6 +1108,11 @@ Received "${apiKey}" instead.`);
1100
1108
  ...resourcesFromCurrentSnapshot2.files,
1101
1109
  ...publishedResources2.files
1102
1110
  ], deletedResources2 == null ? void 0 : deletedResources2.files),
1111
+ tables: mergeIdSpecifiedResource([
1112
+ ...resourcesFromPublishedElementTree2.tables,
1113
+ ...resourcesFromCurrentSnapshot2.tables,
1114
+ ...publishedResources2.tables
1115
+ ], deletedResources2 == null ? void 0 : deletedResources2.tables),
1103
1116
  typographies: mergeIdSpecifiedResource([
1104
1117
  ...resourcesFromPublishedElementTree2.typographies,
1105
1118
  ...resourcesFromCurrentSnapshot2.typographies,
@@ -1156,6 +1169,7 @@ Received "${apiKey}" instead.`);
1156
1169
  return [
1157
1170
  ...resources.swatches.map(parseResourceIds),
1158
1171
  ...resources.files.map(parseResourceIds),
1172
+ ...resources.tables.map(parseResourceIds),
1159
1173
  ...resources.typographies.map(parseResourceIds),
1160
1174
  ...resources.pagePathnameSlices.map(parseResourceIds),
1161
1175
  ...resources.globalElements.map(parseResourceIds),
@@ -1424,11 +1438,12 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1424
1438
  });
1425
1439
  const makeswiftApiClient = new MakeswiftClient({ uri: new URL("graphql", apiOrigin).href });
1426
1440
  async function formMakeswiftResources(publishedResources) {
1427
- var _a2, _b, _c2, _d, _e, _f, _g;
1441
+ var _a2, _b, _c2, _d, _e, _f, _g, _h;
1428
1442
  const publishedResourcesInMakeswiftSnapshotFormat = {
1429
1443
  swatches: [],
1430
1444
  typographies: [],
1431
1445
  files: [],
1446
+ tables: [],
1432
1447
  pagePathnameSlices: [],
1433
1448
  globalElements: [],
1434
1449
  snippets: [],
@@ -1462,14 +1477,23 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1462
1477
  if (file != null) {
1463
1478
  (_c2 = publishedResourcesInMakeswiftSnapshotFormat.files) == null ? void 0 : _c2.push({
1464
1479
  id: fileId,
1465
- value: file
1480
+ value: fileToFileSnapshot(file)
1481
+ });
1482
+ }
1483
+ }
1484
+ for await (const tableId of publishedResources.tables || []) {
1485
+ const table = await makeswiftApiClient.fetchTable(tableId);
1486
+ if (table != null) {
1487
+ (_d = publishedResourcesInMakeswiftSnapshotFormat.tables) == null ? void 0 : _d.push({
1488
+ id: tableId,
1489
+ value: table
1466
1490
  });
1467
1491
  }
1468
1492
  }
1469
1493
  for await (const pageId of publishedResources.pagePathnameSlices || []) {
1470
1494
  const pagePathnameSlice = await makeswiftApiClient.fetchPagePathnameSlice(pageId);
1471
1495
  if (pagePathnameSlice != null) {
1472
- (_d = publishedResourcesInMakeswiftSnapshotFormat.pagePathnameSlices) == null ? void 0 : _d.push({
1496
+ (_e = publishedResourcesInMakeswiftSnapshotFormat.pagePathnameSlices) == null ? void 0 : _e.push({
1473
1497
  id: pageId,
1474
1498
  value: pagePathnameSlice
1475
1499
  });
@@ -1478,7 +1502,7 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1478
1502
  for await (const globalElementId of publishedResources.globalElements || []) {
1479
1503
  const globalElement = await makeswiftApiClient.fetchGlobalElement(globalElementId);
1480
1504
  if (globalElement != null) {
1481
- (_e = publishedResourcesInMakeswiftSnapshotFormat.globalElements) == null ? void 0 : _e.push({
1505
+ (_f = publishedResourcesInMakeswiftSnapshotFormat.globalElements) == null ? void 0 : _f.push({
1482
1506
  id: globalElementId,
1483
1507
  value: globalElement
1484
1508
  });
@@ -1497,7 +1521,7 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1497
1521
  for await (const snippetId of publishedResources.snippets || []) {
1498
1522
  const snippet = availableSnippets.find((availableSnippet) => availableSnippet.id === snippetId);
1499
1523
  if (snippet != null) {
1500
- (_f = publishedResourcesInMakeswiftSnapshotFormat.snippets) == null ? void 0 : _f.push({
1524
+ (_g = publishedResourcesInMakeswiftSnapshotFormat.snippets) == null ? void 0 : _g.push({
1501
1525
  id: snippetId,
1502
1526
  value: snippet
1503
1527
  });
@@ -1506,7 +1530,7 @@ Read more here: https://nextjs.org/blog/next-12-2#on-demand-incremental-static-r
1506
1530
  for await (const family of publishedResources.fonts || []) {
1507
1531
  const font = availableFonts.find((availableFont) => availableFont.family === family);
1508
1532
  if (font != null) {
1509
- (_g = publishedResourcesInMakeswiftSnapshotFormat.fonts) == null ? void 0 : _g.push({
1533
+ (_h = publishedResourcesInMakeswiftSnapshotFormat.fonts) == null ? void 0 : _h.push({
1510
1534
  id: family,
1511
1535
  value: font
1512
1536
  });
@@ -2842,7 +2866,7 @@ function mapSideColor(swatches, _d) {
2842
2866
  return __spreadProps(__spreadValues({}, restOfSide), {
2843
2867
  color: color && {
2844
2868
  alpha: color.alpha,
2845
- swatch: swatches.filter(isNonNullable).find((s) => s && s.id === color.swatchId)
2869
+ swatch: swatches.filter(isNonNullable$1).find((s) => s && s.id === color.swatchId)
2846
2870
  }
2847
2871
  });
2848
2872
  }
@@ -2888,7 +2912,7 @@ function useBoxShadow(value) {
2888
2912
  return __spreadProps(__spreadValues({}, restOfShadow), {
2889
2913
  payload: {
2890
2914
  color: color != null ? {
2891
- swatch: swatches.filter(isNonNullable).find((s) => s && s.id === color.swatchId),
2915
+ swatch: swatches.filter(isNonNullable$1).find((s) => s && s.id === color.swatchId),
2892
2916
  alpha: color.alpha
2893
2917
  } : null,
2894
2918
  inset: inset != null ? inset : ShadowDefaultValue.inset,
@@ -2912,7 +2936,7 @@ function useResponsiveColor(color) {
2912
2936
  const { swatchId, alpha } = v;
2913
2937
  const swatch = swatches.find((s) => s && s.id === swatchId);
2914
2938
  return swatch == null ? null : __spreadProps(__spreadValues({}, rest), { value: { swatch, alpha } });
2915
- }).filter(isNonNullable);
2939
+ }).filter(isNonNullable$1);
2916
2940
  }
2917
2941
  const DEVICE_QUERIES = DEVICES.map((device) => ({
2918
2942
  id: device.id,