@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.cjs.js
CHANGED
|
@@ -509,12 +509,18 @@ class MakeswiftClient {
|
|
|
509
509
|
return getAPIResource(this.makeswiftApiClient.getState(), types.APIResourceType.LocalizedGlobalElement, localizedGlobalElementId);
|
|
510
510
|
}
|
|
511
511
|
async fetchLocalizedGlobalElement(globalElementId) {
|
|
512
|
+
var _a;
|
|
512
513
|
const locale = this.locale;
|
|
513
514
|
if (locale == null)
|
|
514
515
|
return null;
|
|
516
|
+
const noLocalizedResource = this.getLocalizedResourceId(globalElementId) === null;
|
|
517
|
+
if (noLocalizedResource)
|
|
518
|
+
return null;
|
|
519
|
+
const cacheResult = this.readLocalizedGlobalElement(globalElementId);
|
|
520
|
+
if (cacheResult)
|
|
521
|
+
return cacheResult;
|
|
515
522
|
const result = await this.makeswiftApiClient.dispatch(fetchAPIResource(types.APIResourceType.LocalizedGlobalElement, globalElementId, locale));
|
|
516
|
-
|
|
517
|
-
this.setLocalizedResourceId(globalElementId, result.id);
|
|
523
|
+
this.setLocalizedResourceId(globalElementId, (_a = result == null ? void 0 : result.id) != null ? _a : null);
|
|
518
524
|
return result;
|
|
519
525
|
}
|
|
520
526
|
readPagePathnameSlice(pageId) {
|
|
@@ -549,8 +555,8 @@ class MakeswiftClient {
|
|
|
549
555
|
return getAPIResource(this.makeswiftApiClient.getState(), types.APIResourceType.Snippet, snippetId);
|
|
550
556
|
}
|
|
551
557
|
getLocalizedResourceId(resourceId) {
|
|
552
|
-
var _a
|
|
553
|
-
return (
|
|
558
|
+
var _a;
|
|
559
|
+
return (_a = this.localizedResourcesMap) == null ? void 0 : _a.get(resourceId);
|
|
554
560
|
}
|
|
555
561
|
setLocalizedResourceId(resourceId, localizedResourceId) {
|
|
556
562
|
this.localizedResourcesMap.set(resourceId, localizedResourceId);
|
|
@@ -957,6 +963,7 @@ Received "${apiKey}" instead.`);
|
|
|
957
963
|
return __spreadProps(__spreadValues({}, result), { swatches });
|
|
958
964
|
}
|
|
959
965
|
async introspect(element, preview, locale) {
|
|
966
|
+
var _a;
|
|
960
967
|
const runtime = this.runtime;
|
|
961
968
|
const descriptors = reactPage.getPropControllerDescriptors(runtime.store.getState());
|
|
962
969
|
const swatchIds = /* @__PURE__ */ new Set();
|
|
@@ -995,9 +1002,9 @@ Received "${apiKey}" instead.`);
|
|
|
995
1002
|
let elementData = globalElement == null ? void 0 : globalElement.data;
|
|
996
1003
|
if (locale) {
|
|
997
1004
|
const localizedGlobalElement = await this.getLocalizedGlobalElement(globalElementId, locale);
|
|
1005
|
+
localizedResourcesMap.set(globalElementId, (_a = localizedGlobalElement == null ? void 0 : localizedGlobalElement.id) != null ? _a : null);
|
|
998
1006
|
if (localizedGlobalElement) {
|
|
999
1007
|
elementData = localizedGlobalElement.data;
|
|
1000
|
-
localizedResourcesMap.set(globalElementId, localizedGlobalElement.id);
|
|
1001
1008
|
localizedGlobalElements.set(localizedGlobalElement.id, localizedGlobalElement);
|
|
1002
1009
|
}
|
|
1003
1010
|
}
|
|
@@ -1016,8 +1023,8 @@ Received "${apiKey}" instead.`);
|
|
|
1016
1023
|
const typographies = await this.getTypographies([...typographyIds]);
|
|
1017
1024
|
typographies.forEach((typography) => {
|
|
1018
1025
|
typography == null ? void 0 : typography.style.forEach((style) => {
|
|
1019
|
-
var
|
|
1020
|
-
const swatchId = (
|
|
1026
|
+
var _a2;
|
|
1027
|
+
const swatchId = (_a2 = style.value.color) == null ? void 0 : _a2.swatchId;
|
|
1021
1028
|
if (swatchId != null)
|
|
1022
1029
|
swatchIds.add(swatchId);
|
|
1023
1030
|
});
|
|
@@ -1033,38 +1040,38 @@ Received "${apiKey}" instead.`);
|
|
|
1033
1040
|
}));
|
|
1034
1041
|
const cacheData = {
|
|
1035
1042
|
[types.APIResourceType.Swatch]: [...swatchIds].map((id) => {
|
|
1036
|
-
var
|
|
1043
|
+
var _a2;
|
|
1037
1044
|
return {
|
|
1038
1045
|
id,
|
|
1039
|
-
value: (
|
|
1046
|
+
value: (_a2 = swatches.find((swatch) => (swatch == null ? void 0 : swatch.id) === id)) != null ? _a2 : null
|
|
1040
1047
|
};
|
|
1041
1048
|
}),
|
|
1042
1049
|
[types.APIResourceType.File]: [...fileIds].map((id) => {
|
|
1043
|
-
var
|
|
1050
|
+
var _a2;
|
|
1044
1051
|
return {
|
|
1045
1052
|
id,
|
|
1046
|
-
value: (
|
|
1053
|
+
value: (_a2 = files.find((file) => (file == null ? void 0 : file.id) === id)) != null ? _a2 : null
|
|
1047
1054
|
};
|
|
1048
1055
|
}),
|
|
1049
1056
|
[types.APIResourceType.Typography]: [...typographyIds].map((id) => {
|
|
1050
|
-
var
|
|
1057
|
+
var _a2;
|
|
1051
1058
|
return {
|
|
1052
1059
|
id,
|
|
1053
|
-
value: (
|
|
1060
|
+
value: (_a2 = typographies.find((typography) => (typography == null ? void 0 : typography.id) === id)) != null ? _a2 : null
|
|
1054
1061
|
};
|
|
1055
1062
|
}),
|
|
1056
1063
|
[types.APIResourceType.Table]: [...tableIds].map((id) => {
|
|
1057
|
-
var
|
|
1064
|
+
var _a2;
|
|
1058
1065
|
return {
|
|
1059
1066
|
id,
|
|
1060
|
-
value: (
|
|
1067
|
+
value: (_a2 = tables.find((table) => (table == null ? void 0 : table.id) === id)) != null ? _a2 : null
|
|
1061
1068
|
};
|
|
1062
1069
|
}),
|
|
1063
1070
|
[types.APIResourceType.PagePathnameSlice]: [...pageIds].map((id) => {
|
|
1064
|
-
var
|
|
1071
|
+
var _a2;
|
|
1065
1072
|
return {
|
|
1066
1073
|
id,
|
|
1067
|
-
value: (
|
|
1074
|
+
value: (_a2 = pagePathnameSlices.find((pagePathnameSlice) => (pagePathnameSlice == null ? void 0 : pagePathnameSlice.id) === id)) != null ? _a2 : null
|
|
1068
1075
|
};
|
|
1069
1076
|
}),
|
|
1070
1077
|
[types.APIResourceType.GlobalElement]: [...globalElements.entries()].map(([id, value]) => ({
|
|
@@ -1082,7 +1089,7 @@ Received "${apiKey}" instead.`);
|
|
|
1082
1089
|
preview: previewOverride = false,
|
|
1083
1090
|
unstable_locale
|
|
1084
1091
|
} = {}) {
|
|
1085
|
-
var _a, _b;
|
|
1092
|
+
var _a, _b, _c;
|
|
1086
1093
|
const isUsingVersioning = this.siteVersion != null;
|
|
1087
1094
|
const siteVersion = (_a = this.siteVersion) != null ? _a : previewOverride ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live;
|
|
1088
1095
|
const defaultLocale = (_b = reactPage.getDefaultLocale(this.runtime.store.getState())) == null ? void 0 : _b.toString();
|
|
@@ -1105,7 +1112,8 @@ Received "${apiKey}" instead.`);
|
|
|
1105
1112
|
throw new Error(`Failed to get page snapshot with error: "${response.statusText}"`);
|
|
1106
1113
|
}
|
|
1107
1114
|
const document2 = await response.json();
|
|
1108
|
-
const
|
|
1115
|
+
const baseLocalizedPage = document2.localizedPages.find(({ parentId }) => parentId == null);
|
|
1116
|
+
const { cacheData, localizedResourcesMap } = await this.introspect((_c = baseLocalizedPage == null ? void 0 : baseLocalizedPage.data) != null ? _c : document2.data, previewOverride, locale != null ? locale : void 0);
|
|
1109
1117
|
const apiOrigin = this.apiOrigin.href;
|
|
1110
1118
|
const preview = siteVersion === MakeswiftSiteVersion.Working;
|
|
1111
1119
|
return {
|
|
@@ -1227,7 +1235,7 @@ async function fonts(_req, res, { getFonts } = {}) {
|
|
|
1227
1235
|
const fonts2 = (_a = await (getFonts == null ? void 0 : getFonts())) != null ? _a : [];
|
|
1228
1236
|
return res.json(fonts2);
|
|
1229
1237
|
}
|
|
1230
|
-
const version = "0.10.
|
|
1238
|
+
const version = "0.10.8";
|
|
1231
1239
|
async function handler(req, res, { apiKey, unstable_siteVersions }) {
|
|
1232
1240
|
if (req.query.secret !== apiKey) {
|
|
1233
1241
|
return res.status(401).json({ message: "Unauthorized" });
|