@makeswift/runtime 0.10.7 → 0.10.8
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.cjs.js +28 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +28 -20
- package/dist/index.es.js.map +1 -1
- package/dist/types/src/api/react.d.ts +1 -1
- package/dist/types/src/api/react.d.ts.map +1 -1
- package/dist/types/src/next/client.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -476,12 +476,18 @@ class MakeswiftClient {
|
|
|
476
476
|
return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.LocalizedGlobalElement, localizedGlobalElementId);
|
|
477
477
|
}
|
|
478
478
|
async fetchLocalizedGlobalElement(globalElementId) {
|
|
479
|
+
var _a;
|
|
479
480
|
const locale = this.locale;
|
|
480
481
|
if (locale == null)
|
|
481
482
|
return null;
|
|
483
|
+
const noLocalizedResource = this.getLocalizedResourceId(globalElementId) === null;
|
|
484
|
+
if (noLocalizedResource)
|
|
485
|
+
return null;
|
|
486
|
+
const cacheResult = this.readLocalizedGlobalElement(globalElementId);
|
|
487
|
+
if (cacheResult)
|
|
488
|
+
return cacheResult;
|
|
482
489
|
const result = await this.makeswiftApiClient.dispatch(fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, locale));
|
|
483
|
-
|
|
484
|
-
this.setLocalizedResourceId(globalElementId, result.id);
|
|
490
|
+
this.setLocalizedResourceId(globalElementId, (_a = result == null ? void 0 : result.id) != null ? _a : null);
|
|
485
491
|
return result;
|
|
486
492
|
}
|
|
487
493
|
readPagePathnameSlice(pageId) {
|
|
@@ -516,8 +522,8 @@ class MakeswiftClient {
|
|
|
516
522
|
return getAPIResource(this.makeswiftApiClient.getState(), APIResourceType.Snippet, snippetId);
|
|
517
523
|
}
|
|
518
524
|
getLocalizedResourceId(resourceId) {
|
|
519
|
-
var _a
|
|
520
|
-
return (
|
|
525
|
+
var _a;
|
|
526
|
+
return (_a = this.localizedResourcesMap) == null ? void 0 : _a.get(resourceId);
|
|
521
527
|
}
|
|
522
528
|
setLocalizedResourceId(resourceId, localizedResourceId) {
|
|
523
529
|
this.localizedResourcesMap.set(resourceId, localizedResourceId);
|
|
@@ -924,6 +930,7 @@ Received "${apiKey}" instead.`);
|
|
|
924
930
|
return __spreadProps(__spreadValues({}, result), { swatches });
|
|
925
931
|
}
|
|
926
932
|
async introspect(element, preview, locale) {
|
|
933
|
+
var _a;
|
|
927
934
|
const runtime = this.runtime;
|
|
928
935
|
const descriptors = getPropControllerDescriptors(runtime.store.getState());
|
|
929
936
|
const swatchIds = /* @__PURE__ */ new Set();
|
|
@@ -962,9 +969,9 @@ Received "${apiKey}" instead.`);
|
|
|
962
969
|
let elementData = globalElement == null ? void 0 : globalElement.data;
|
|
963
970
|
if (locale) {
|
|
964
971
|
const localizedGlobalElement = await this.getLocalizedGlobalElement(globalElementId, locale);
|
|
972
|
+
localizedResourcesMap.set(globalElementId, (_a = localizedGlobalElement == null ? void 0 : localizedGlobalElement.id) != null ? _a : null);
|
|
965
973
|
if (localizedGlobalElement) {
|
|
966
974
|
elementData = localizedGlobalElement.data;
|
|
967
|
-
localizedResourcesMap.set(globalElementId, localizedGlobalElement.id);
|
|
968
975
|
localizedGlobalElements.set(localizedGlobalElement.id, localizedGlobalElement);
|
|
969
976
|
}
|
|
970
977
|
}
|
|
@@ -983,8 +990,8 @@ Received "${apiKey}" instead.`);
|
|
|
983
990
|
const typographies = await this.getTypographies([...typographyIds]);
|
|
984
991
|
typographies.forEach((typography) => {
|
|
985
992
|
typography == null ? void 0 : typography.style.forEach((style) => {
|
|
986
|
-
var
|
|
987
|
-
const swatchId = (
|
|
993
|
+
var _a2;
|
|
994
|
+
const swatchId = (_a2 = style.value.color) == null ? void 0 : _a2.swatchId;
|
|
988
995
|
if (swatchId != null)
|
|
989
996
|
swatchIds.add(swatchId);
|
|
990
997
|
});
|
|
@@ -1000,38 +1007,38 @@ Received "${apiKey}" instead.`);
|
|
|
1000
1007
|
}));
|
|
1001
1008
|
const cacheData = {
|
|
1002
1009
|
[APIResourceType.Swatch]: [...swatchIds].map((id) => {
|
|
1003
|
-
var
|
|
1010
|
+
var _a2;
|
|
1004
1011
|
return {
|
|
1005
1012
|
id,
|
|
1006
|
-
value: (
|
|
1013
|
+
value: (_a2 = swatches.find((swatch) => (swatch == null ? void 0 : swatch.id) === id)) != null ? _a2 : null
|
|
1007
1014
|
};
|
|
1008
1015
|
}),
|
|
1009
1016
|
[APIResourceType.File]: [...fileIds].map((id) => {
|
|
1010
|
-
var
|
|
1017
|
+
var _a2;
|
|
1011
1018
|
return {
|
|
1012
1019
|
id,
|
|
1013
|
-
value: (
|
|
1020
|
+
value: (_a2 = files.find((file) => (file == null ? void 0 : file.id) === id)) != null ? _a2 : null
|
|
1014
1021
|
};
|
|
1015
1022
|
}),
|
|
1016
1023
|
[APIResourceType.Typography]: [...typographyIds].map((id) => {
|
|
1017
|
-
var
|
|
1024
|
+
var _a2;
|
|
1018
1025
|
return {
|
|
1019
1026
|
id,
|
|
1020
|
-
value: (
|
|
1027
|
+
value: (_a2 = typographies.find((typography) => (typography == null ? void 0 : typography.id) === id)) != null ? _a2 : null
|
|
1021
1028
|
};
|
|
1022
1029
|
}),
|
|
1023
1030
|
[APIResourceType.Table]: [...tableIds].map((id) => {
|
|
1024
|
-
var
|
|
1031
|
+
var _a2;
|
|
1025
1032
|
return {
|
|
1026
1033
|
id,
|
|
1027
|
-
value: (
|
|
1034
|
+
value: (_a2 = tables.find((table) => (table == null ? void 0 : table.id) === id)) != null ? _a2 : null
|
|
1028
1035
|
};
|
|
1029
1036
|
}),
|
|
1030
1037
|
[APIResourceType.PagePathnameSlice]: [...pageIds].map((id) => {
|
|
1031
|
-
var
|
|
1038
|
+
var _a2;
|
|
1032
1039
|
return {
|
|
1033
1040
|
id,
|
|
1034
|
-
value: (
|
|
1041
|
+
value: (_a2 = pagePathnameSlices.find((pagePathnameSlice) => (pagePathnameSlice == null ? void 0 : pagePathnameSlice.id) === id)) != null ? _a2 : null
|
|
1035
1042
|
};
|
|
1036
1043
|
}),
|
|
1037
1044
|
[APIResourceType.GlobalElement]: [...globalElements.entries()].map(([id, value]) => ({
|
|
@@ -1049,7 +1056,7 @@ Received "${apiKey}" instead.`);
|
|
|
1049
1056
|
preview: previewOverride = false,
|
|
1050
1057
|
unstable_locale
|
|
1051
1058
|
} = {}) {
|
|
1052
|
-
var _a, _b;
|
|
1059
|
+
var _a, _b, _c;
|
|
1053
1060
|
const isUsingVersioning = this.siteVersion != null;
|
|
1054
1061
|
const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
|
|
1055
1062
|
const defaultLocale = (_b = getDefaultLocale(this.runtime.store.getState())) == null ? void 0 : _b.toString();
|
|
@@ -1072,7 +1079,8 @@ Received "${apiKey}" instead.`);
|
|
|
1072
1079
|
throw new Error(`Failed to get page snapshot with error: "${response.statusText}"`);
|
|
1073
1080
|
}
|
|
1074
1081
|
const document2 = await response.json();
|
|
1075
|
-
const
|
|
1082
|
+
const baseLocalizedPage = document2.localizedPages.find(({ parentId }) => parentId == null);
|
|
1083
|
+
const { cacheData, localizedResourcesMap } = await this.introspect((_c = baseLocalizedPage == null ? void 0 : baseLocalizedPage.data) != null ? _c : document2.data, previewOverride, locale != null ? locale : void 0);
|
|
1076
1084
|
const apiOrigin = this.apiOrigin.href;
|
|
1077
1085
|
const preview = siteVersion === MakeswiftSiteVersion.Working;
|
|
1078
1086
|
return {
|
|
@@ -1194,7 +1202,7 @@ async function fonts(_req, res, { getFonts } = {}) {
|
|
|
1194
1202
|
const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
|
|
1195
1203
|
return res.json(fonts2);
|
|
1196
1204
|
}
|
|
1197
|
-
const version = "0.10.
|
|
1205
|
+
const version = "0.10.8";
|
|
1198
1206
|
async function handler(req, res, { apiKey, unstable_siteVersions }) {
|
|
1199
1207
|
if (req.query.secret !== apiKey) {
|
|
1200
1208
|
return res.status(401).json({ message: "Unauthorized" });
|