@swell/apps-sdk 1.0.180 → 1.0.181
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 +98 -88
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +98 -88
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +100 -90
- package/dist/index.mjs.map +3 -3
- package/dist/src/compatibility/shopify.d.ts +1 -1
- package/dist/types/swell.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5909,86 +5909,76 @@ function prepareSectionId(id) {
|
|
|
5909
5909
|
}
|
|
5910
5910
|
function getAllSectionComponentTemplates(allSections) {
|
|
5911
5911
|
const list = [];
|
|
5912
|
+
const processFields = (fields, settings = {}) => {
|
|
5913
|
+
const result = {};
|
|
5914
|
+
for (const field of fields) {
|
|
5915
|
+
if (!field?.id) {
|
|
5916
|
+
continue;
|
|
5917
|
+
}
|
|
5918
|
+
const { id: fieldId, $locale } = field;
|
|
5919
|
+
result[fieldId] = schemaToEasyblocksValue(
|
|
5920
|
+
fields,
|
|
5921
|
+
fieldId,
|
|
5922
|
+
settings[fieldId]
|
|
5923
|
+
);
|
|
5924
|
+
if ($locale) {
|
|
5925
|
+
for (const [locale, localeValues] of Object.entries($locale)) {
|
|
5926
|
+
const defaultValue = localeValues?.default;
|
|
5927
|
+
if (defaultValue) {
|
|
5928
|
+
(0, import_lodash_es4.set)(result, `$locale.${locale}.${fieldId}`, defaultValue);
|
|
5929
|
+
}
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5932
|
+
}
|
|
5933
|
+
return result;
|
|
5934
|
+
};
|
|
5912
5935
|
for (const section of allSections) {
|
|
5913
5936
|
if (section.presets) {
|
|
5914
|
-
|
|
5915
|
-
|
|
5937
|
+
for (let index = 0; index < section.presets.length; index++) {
|
|
5938
|
+
const preset = section.presets[index];
|
|
5939
|
+
const entry = {
|
|
5940
|
+
_id: `${section.id}__preset_${index}`,
|
|
5941
|
+
_component: section.id,
|
|
5942
|
+
custom_css: preset.settings?.["custom_css"] || "",
|
|
5943
|
+
...processFields(section.fields, preset.settings),
|
|
5944
|
+
// Process blocks inside the preset
|
|
5945
|
+
Blocks: (preset.blocks || []).map((block) => {
|
|
5946
|
+
const blockSchema = section.blocks?.find(
|
|
5947
|
+
({ type }) => type === block.type
|
|
5948
|
+
);
|
|
5949
|
+
if (!blockSchema) {
|
|
5950
|
+
return null;
|
|
5951
|
+
}
|
|
5952
|
+
return {
|
|
5953
|
+
_id: `Block__${section.id}__${block.type}__preset_${index}`,
|
|
5954
|
+
_component: `Block__${section.id}__${block.type}`,
|
|
5955
|
+
...processFields(blockSchema.fields, block.settings)
|
|
5956
|
+
};
|
|
5957
|
+
}).filter(Boolean)
|
|
5958
|
+
};
|
|
5959
|
+
list.push({
|
|
5916
5960
|
id: `${section.id}__preset_${index}`,
|
|
5917
|
-
entry
|
|
5918
|
-
|
|
5919
|
-
|
|
5920
|
-
custom_css: preset.settings?.["custom_css"] || "",
|
|
5921
|
-
...(0, import_lodash_es4.reduce)(
|
|
5922
|
-
section.fields,
|
|
5923
|
-
(acc, field) => {
|
|
5924
|
-
if (field.id) {
|
|
5925
|
-
acc[field.id] = schemaToEasyblocksValue(
|
|
5926
|
-
section.fields,
|
|
5927
|
-
field.id,
|
|
5928
|
-
preset.settings?.[field.id]
|
|
5929
|
-
);
|
|
5930
|
-
}
|
|
5931
|
-
return acc;
|
|
5932
|
-
},
|
|
5933
|
-
{}
|
|
5934
|
-
),
|
|
5935
|
-
Blocks: preset.blocks?.reduce(
|
|
5936
|
-
(acc, block) => {
|
|
5937
|
-
const blockDef = section.blocks?.find(
|
|
5938
|
-
({ type }) => type === block.type
|
|
5939
|
-
);
|
|
5940
|
-
if (blockDef) {
|
|
5941
|
-
acc.push({
|
|
5942
|
-
_id: `Block__${section.id}__${block.type}__preset_${index}`,
|
|
5943
|
-
_component: `Block__${section.id}__${block.type}`,
|
|
5944
|
-
...(0, import_lodash_es4.reduce)(
|
|
5945
|
-
blockDef.fields,
|
|
5946
|
-
(acc2, blockField) => {
|
|
5947
|
-
if (blockField.id) {
|
|
5948
|
-
acc2[blockField.id] = schemaToEasyblocksValue(
|
|
5949
|
-
blockDef.fields,
|
|
5950
|
-
blockField.id,
|
|
5951
|
-
block.settings?.[blockField.id]
|
|
5952
|
-
);
|
|
5953
|
-
}
|
|
5954
|
-
return acc2;
|
|
5955
|
-
},
|
|
5956
|
-
{}
|
|
5957
|
-
)
|
|
5958
|
-
});
|
|
5959
|
-
}
|
|
5960
|
-
return acc;
|
|
5961
|
-
},
|
|
5962
|
-
[]
|
|
5963
|
-
)
|
|
5964
|
-
}
|
|
5965
|
-
}))
|
|
5966
|
-
);
|
|
5961
|
+
entry
|
|
5962
|
+
});
|
|
5963
|
+
}
|
|
5967
5964
|
}
|
|
5968
5965
|
if (section.blocks) {
|
|
5969
|
-
|
|
5970
|
-
|
|
5966
|
+
for (const block of section.blocks) {
|
|
5967
|
+
list.push({
|
|
5971
5968
|
id: `Block__${section.id}__${block.type}`,
|
|
5972
5969
|
entry: {
|
|
5973
5970
|
_id: `Block__${section.id}__${block.type}`,
|
|
5974
5971
|
_component: `Block__${section.id}__${block.type}`,
|
|
5975
|
-
...(
|
|
5972
|
+
...processFields(
|
|
5976
5973
|
block.fields,
|
|
5977
|
-
(acc,
|
|
5978
|
-
if (
|
|
5979
|
-
acc[field.id] = schemaToEasyblocksValue(
|
|
5980
|
-
block.fields,
|
|
5981
|
-
field.id,
|
|
5982
|
-
field.default
|
|
5983
|
-
);
|
|
5984
|
-
}
|
|
5974
|
+
block.fields.reduce((acc, f) => {
|
|
5975
|
+
if (f.id) acc[f.id] = f.default;
|
|
5985
5976
|
return acc;
|
|
5986
|
-
},
|
|
5987
|
-
{}
|
|
5977
|
+
}, {})
|
|
5988
5978
|
)
|
|
5989
5979
|
}
|
|
5990
|
-
})
|
|
5991
|
-
|
|
5980
|
+
});
|
|
5981
|
+
}
|
|
5992
5982
|
}
|
|
5993
5983
|
}
|
|
5994
5984
|
return list;
|
|
@@ -11708,16 +11698,16 @@ function ShopifyBlog(instance, blogCategory) {
|
|
|
11708
11698
|
if (!Array.isArray(blogs?.results)) {
|
|
11709
11699
|
return [];
|
|
11710
11700
|
}
|
|
11711
|
-
const
|
|
11712
|
-
(
|
|
11701
|
+
const set3 = blogs.results.reduce(
|
|
11702
|
+
(set4, blog) => {
|
|
11713
11703
|
for (const tag of blog.tags || []) {
|
|
11714
|
-
|
|
11704
|
+
set4.add(tag);
|
|
11715
11705
|
}
|
|
11716
|
-
return
|
|
11706
|
+
return set4;
|
|
11717
11707
|
},
|
|
11718
11708
|
/* @__PURE__ */ new Set()
|
|
11719
11709
|
);
|
|
11720
|
-
return Array.from(
|
|
11710
|
+
return Array.from(set3.values());
|
|
11721
11711
|
});
|
|
11722
11712
|
return new ShopifyResource({
|
|
11723
11713
|
all_tags: allTags,
|
|
@@ -12101,18 +12091,18 @@ function ShopifyCollection(instance, category) {
|
|
|
12101
12091
|
if (!resolved) {
|
|
12102
12092
|
return [];
|
|
12103
12093
|
}
|
|
12104
|
-
const
|
|
12094
|
+
const set3 = /* @__PURE__ */ new Set();
|
|
12105
12095
|
await Promise.all(
|
|
12106
12096
|
resolved.results.map(async (product) => {
|
|
12107
12097
|
const tags2 = await Promise.resolve().then(() => product.tags);
|
|
12108
12098
|
if (Array.isArray(tags2)) {
|
|
12109
12099
|
for (const tag of tags2) {
|
|
12110
|
-
|
|
12100
|
+
set3.add(tag);
|
|
12111
12101
|
}
|
|
12112
12102
|
}
|
|
12113
12103
|
})
|
|
12114
12104
|
);
|
|
12115
|
-
return Array.from(
|
|
12105
|
+
return Array.from(set3.values());
|
|
12116
12106
|
}),
|
|
12117
12107
|
all_types: defer(async () => {
|
|
12118
12108
|
const products = await resolveProducts();
|
|
@@ -14462,26 +14452,32 @@ ${injects.join("\n")}</script>`;
|
|
|
14462
14452
|
if (!(0, import_lodash_es7.isObject)(schema)) {
|
|
14463
14453
|
return schema;
|
|
14464
14454
|
}
|
|
14465
|
-
const
|
|
14466
|
-
|
|
14467
|
-
localeCode
|
|
14468
|
-
|
|
14455
|
+
const locales = await theme.swell.storefront.locale.list();
|
|
14456
|
+
const localeCodes = /* @__PURE__ */ new Set([
|
|
14457
|
+
localeCode,
|
|
14458
|
+
...locales.map((locale) => locale.code)
|
|
14459
|
+
]);
|
|
14460
|
+
const localeConfigs = {};
|
|
14461
|
+
for (const locale of localeCodes) {
|
|
14462
|
+
localeConfigs[locale] = await this.getEditorLocaleConfig(theme, locale);
|
|
14463
|
+
}
|
|
14469
14464
|
return this.renderSchemaTranslationValue(
|
|
14470
14465
|
theme,
|
|
14471
14466
|
schema,
|
|
14472
14467
|
localeCode,
|
|
14473
|
-
|
|
14468
|
+
localeConfigs
|
|
14474
14469
|
);
|
|
14475
14470
|
}
|
|
14476
|
-
|
|
14471
|
+
renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
|
|
14477
14472
|
switch (typeof schemaValue) {
|
|
14478
14473
|
case "string": {
|
|
14479
14474
|
if (schemaValue.startsWith("t:")) {
|
|
14475
|
+
const localeConfig = localeConfigs[localeCode];
|
|
14480
14476
|
const key = schemaValue.slice(2);
|
|
14481
14477
|
const keyParts = key?.split(".");
|
|
14482
14478
|
const keyName = keyParts.pop() || "";
|
|
14483
14479
|
const keyPath = keyParts.join(".");
|
|
14484
|
-
const langObject = (0, import_lodash_es7.get)(
|
|
14480
|
+
const langObject = (0, import_lodash_es7.get)(localeConfig, keyPath);
|
|
14485
14481
|
return langObject?.[keyName] ?? key;
|
|
14486
14482
|
}
|
|
14487
14483
|
break;
|
|
@@ -14491,11 +14487,11 @@ ${injects.join("\n")}</script>`;
|
|
|
14491
14487
|
const result = [];
|
|
14492
14488
|
for (const value of schemaValue) {
|
|
14493
14489
|
result.push(
|
|
14494
|
-
|
|
14490
|
+
this.renderSchemaTranslationValue(
|
|
14495
14491
|
theme,
|
|
14496
14492
|
value,
|
|
14497
|
-
|
|
14498
|
-
|
|
14493
|
+
localeCode,
|
|
14494
|
+
localeConfigs
|
|
14499
14495
|
)
|
|
14500
14496
|
);
|
|
14501
14497
|
}
|
|
@@ -14504,12 +14500,26 @@ ${injects.join("\n")}</script>`;
|
|
|
14504
14500
|
if (schemaValue !== null) {
|
|
14505
14501
|
const result = { ...schemaValue };
|
|
14506
14502
|
for (const [key, value] of Object.entries(schemaValue)) {
|
|
14507
|
-
result[key] =
|
|
14503
|
+
result[key] = this.renderSchemaTranslationValue(
|
|
14508
14504
|
theme,
|
|
14509
14505
|
value,
|
|
14510
|
-
|
|
14511
|
-
|
|
14506
|
+
localeCode,
|
|
14507
|
+
localeConfigs
|
|
14512
14508
|
);
|
|
14509
|
+
if (typeof value === "string" && value.startsWith("t:")) {
|
|
14510
|
+
for (const locale of Object.keys(localeConfigs)) {
|
|
14511
|
+
if (locale === localeCode) {
|
|
14512
|
+
continue;
|
|
14513
|
+
}
|
|
14514
|
+
const localeValue = this.renderSchemaTranslationValue(
|
|
14515
|
+
theme,
|
|
14516
|
+
value,
|
|
14517
|
+
locale,
|
|
14518
|
+
localeConfigs
|
|
14519
|
+
);
|
|
14520
|
+
(0, import_lodash_es7.set)(result, `$locale.${locale}.${key}`, localeValue);
|
|
14521
|
+
}
|
|
14522
|
+
}
|
|
14513
14523
|
}
|
|
14514
14524
|
return result;
|
|
14515
14525
|
}
|