@swell/apps-sdk 1.0.180 → 1.0.182
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 +113 -104
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +113 -104
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +115 -106
- package/dist/index.mjs.map +3 -3
- package/dist/src/compatibility/shopify-fonts.d.ts +1 -1
- package/dist/src/compatibility/shopify.d.ts +1 -1
- package/dist/src/liquid/filters/shopify/payment_button.d.ts +1 -1
- package/dist/src/resources.d.ts +2 -2
- package/dist/types/swell.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1038,7 +1038,10 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
|
|
|
1038
1038
|
}
|
|
1039
1039
|
return this._resolve().then(() => this.makeIterator());
|
|
1040
1040
|
}
|
|
1041
|
-
makeIterator() {
|
|
1041
|
+
async makeIterator() {
|
|
1042
|
+
if (isLikePromise(this.results)) {
|
|
1043
|
+
await this.results;
|
|
1044
|
+
}
|
|
1042
1045
|
return (this.results || []).values();
|
|
1043
1046
|
}
|
|
1044
1047
|
_clone(newProps) {
|
|
@@ -3790,11 +3793,11 @@ function arrayToObject(arr, key = "id") {
|
|
|
3790
3793
|
);
|
|
3791
3794
|
}
|
|
3792
3795
|
function getCountryCodeFromLocale(locale) {
|
|
3793
|
-
const
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
return
|
|
3796
|
+
const [lang, country] = locale.split(/-|_/);
|
|
3797
|
+
if (country) {
|
|
3798
|
+
return country.toLowerCase();
|
|
3799
|
+
}
|
|
3800
|
+
return (LANG_TO_COUNTRY_CODES[lang] || "").toLowerCase();
|
|
3798
3801
|
}
|
|
3799
3802
|
function getCountryByCurrency(currencyCode) {
|
|
3800
3803
|
if (currencyCode in CURRENCY_COUNTRIES) {
|
|
@@ -5909,86 +5912,76 @@ function prepareSectionId(id) {
|
|
|
5909
5912
|
}
|
|
5910
5913
|
function getAllSectionComponentTemplates(allSections) {
|
|
5911
5914
|
const list = [];
|
|
5915
|
+
const processFields = (fields, settings = {}) => {
|
|
5916
|
+
const result = {};
|
|
5917
|
+
for (const field of fields) {
|
|
5918
|
+
if (!field?.id) {
|
|
5919
|
+
continue;
|
|
5920
|
+
}
|
|
5921
|
+
const { id: fieldId, $locale } = field;
|
|
5922
|
+
result[fieldId] = schemaToEasyblocksValue(
|
|
5923
|
+
fields,
|
|
5924
|
+
fieldId,
|
|
5925
|
+
settings[fieldId]
|
|
5926
|
+
);
|
|
5927
|
+
if ($locale) {
|
|
5928
|
+
for (const [locale, localeValues] of Object.entries($locale)) {
|
|
5929
|
+
const defaultValue = localeValues?.default;
|
|
5930
|
+
if (defaultValue) {
|
|
5931
|
+
(0, import_lodash_es4.set)(result, `$locale.${locale}.${fieldId}`, defaultValue);
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
}
|
|
5935
|
+
}
|
|
5936
|
+
return result;
|
|
5937
|
+
};
|
|
5912
5938
|
for (const section of allSections) {
|
|
5913
5939
|
if (section.presets) {
|
|
5914
|
-
|
|
5915
|
-
|
|
5940
|
+
for (let index = 0; index < section.presets.length; index++) {
|
|
5941
|
+
const preset = section.presets[index];
|
|
5942
|
+
const entry = {
|
|
5943
|
+
_id: `${section.id}__preset_${index}`,
|
|
5944
|
+
_component: section.id,
|
|
5945
|
+
custom_css: preset.settings?.["custom_css"] || "",
|
|
5946
|
+
...processFields(section.fields, preset.settings),
|
|
5947
|
+
// Process blocks inside the preset
|
|
5948
|
+
Blocks: (preset.blocks || []).map((block) => {
|
|
5949
|
+
const blockSchema = section.blocks?.find(
|
|
5950
|
+
({ type }) => type === block.type
|
|
5951
|
+
);
|
|
5952
|
+
if (!blockSchema) {
|
|
5953
|
+
return null;
|
|
5954
|
+
}
|
|
5955
|
+
return {
|
|
5956
|
+
_id: `Block__${section.id}__${block.type}__preset_${index}`,
|
|
5957
|
+
_component: `Block__${section.id}__${block.type}`,
|
|
5958
|
+
...processFields(blockSchema.fields, block.settings)
|
|
5959
|
+
};
|
|
5960
|
+
}).filter(Boolean)
|
|
5961
|
+
};
|
|
5962
|
+
list.push({
|
|
5916
5963
|
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
|
-
);
|
|
5964
|
+
entry
|
|
5965
|
+
});
|
|
5966
|
+
}
|
|
5967
5967
|
}
|
|
5968
5968
|
if (section.blocks) {
|
|
5969
|
-
|
|
5970
|
-
|
|
5969
|
+
for (const block of section.blocks) {
|
|
5970
|
+
list.push({
|
|
5971
5971
|
id: `Block__${section.id}__${block.type}`,
|
|
5972
5972
|
entry: {
|
|
5973
5973
|
_id: `Block__${section.id}__${block.type}`,
|
|
5974
5974
|
_component: `Block__${section.id}__${block.type}`,
|
|
5975
|
-
...(
|
|
5975
|
+
...processFields(
|
|
5976
5976
|
block.fields,
|
|
5977
|
-
(acc,
|
|
5978
|
-
if (
|
|
5979
|
-
acc[field.id] = schemaToEasyblocksValue(
|
|
5980
|
-
block.fields,
|
|
5981
|
-
field.id,
|
|
5982
|
-
field.default
|
|
5983
|
-
);
|
|
5984
|
-
}
|
|
5977
|
+
block.fields.reduce((acc, f) => {
|
|
5978
|
+
if (f.id) acc[f.id] = f.default;
|
|
5985
5979
|
return acc;
|
|
5986
|
-
},
|
|
5987
|
-
{}
|
|
5980
|
+
}, {})
|
|
5988
5981
|
)
|
|
5989
5982
|
}
|
|
5990
|
-
})
|
|
5991
|
-
|
|
5983
|
+
});
|
|
5984
|
+
}
|
|
5992
5985
|
}
|
|
5993
5986
|
}
|
|
5994
5987
|
return list;
|
|
@@ -10376,6 +10369,9 @@ function getLocalizedValue(value, locale) {
|
|
|
10376
10369
|
|
|
10377
10370
|
// src/compatibility/shopify-fonts.ts
|
|
10378
10371
|
function shopifyFontToThemeFront(shopifyFontSetting) {
|
|
10372
|
+
if (typeof shopifyFontSetting !== "string") {
|
|
10373
|
+
return null;
|
|
10374
|
+
}
|
|
10379
10375
|
const pos = shopifyFontSetting.lastIndexOf("_");
|
|
10380
10376
|
const familyId = shopifyFontSetting.substring(0, pos);
|
|
10381
10377
|
const variantId = shopifyFontSetting.substring(pos + 1);
|
|
@@ -11708,16 +11704,16 @@ function ShopifyBlog(instance, blogCategory) {
|
|
|
11708
11704
|
if (!Array.isArray(blogs?.results)) {
|
|
11709
11705
|
return [];
|
|
11710
11706
|
}
|
|
11711
|
-
const
|
|
11712
|
-
(
|
|
11707
|
+
const set3 = blogs.results.reduce(
|
|
11708
|
+
(set4, blog) => {
|
|
11713
11709
|
for (const tag of blog.tags || []) {
|
|
11714
|
-
|
|
11710
|
+
set4.add(tag);
|
|
11715
11711
|
}
|
|
11716
|
-
return
|
|
11712
|
+
return set4;
|
|
11717
11713
|
},
|
|
11718
11714
|
/* @__PURE__ */ new Set()
|
|
11719
11715
|
);
|
|
11720
|
-
return Array.from(
|
|
11716
|
+
return Array.from(set3.values());
|
|
11721
11717
|
});
|
|
11722
11718
|
return new ShopifyResource({
|
|
11723
11719
|
all_tags: allTags,
|
|
@@ -12101,18 +12097,18 @@ function ShopifyCollection(instance, category) {
|
|
|
12101
12097
|
if (!resolved) {
|
|
12102
12098
|
return [];
|
|
12103
12099
|
}
|
|
12104
|
-
const
|
|
12100
|
+
const set3 = /* @__PURE__ */ new Set();
|
|
12105
12101
|
await Promise.all(
|
|
12106
12102
|
resolved.results.map(async (product) => {
|
|
12107
12103
|
const tags2 = await Promise.resolve().then(() => product.tags);
|
|
12108
12104
|
if (Array.isArray(tags2)) {
|
|
12109
12105
|
for (const tag of tags2) {
|
|
12110
|
-
|
|
12106
|
+
set3.add(tag);
|
|
12111
12107
|
}
|
|
12112
12108
|
}
|
|
12113
12109
|
})
|
|
12114
12110
|
);
|
|
12115
|
-
return Array.from(
|
|
12111
|
+
return Array.from(set3.values());
|
|
12116
12112
|
}),
|
|
12117
12113
|
all_types: defer(async () => {
|
|
12118
12114
|
const products = await resolveProducts();
|
|
@@ -14462,26 +14458,32 @@ ${injects.join("\n")}</script>`;
|
|
|
14462
14458
|
if (!(0, import_lodash_es7.isObject)(schema)) {
|
|
14463
14459
|
return schema;
|
|
14464
14460
|
}
|
|
14465
|
-
const
|
|
14466
|
-
|
|
14467
|
-
localeCode
|
|
14468
|
-
|
|
14461
|
+
const locales = await theme.swell.storefront.locale.list();
|
|
14462
|
+
const localeCodes = /* @__PURE__ */ new Set([
|
|
14463
|
+
localeCode,
|
|
14464
|
+
...locales.map((locale) => locale.code)
|
|
14465
|
+
]);
|
|
14466
|
+
const localeConfigs = {};
|
|
14467
|
+
for (const locale of localeCodes) {
|
|
14468
|
+
localeConfigs[locale] = await this.getEditorLocaleConfig(theme, locale);
|
|
14469
|
+
}
|
|
14469
14470
|
return this.renderSchemaTranslationValue(
|
|
14470
14471
|
theme,
|
|
14471
14472
|
schema,
|
|
14472
14473
|
localeCode,
|
|
14473
|
-
|
|
14474
|
+
localeConfigs
|
|
14474
14475
|
);
|
|
14475
14476
|
}
|
|
14476
|
-
|
|
14477
|
+
renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
|
|
14477
14478
|
switch (typeof schemaValue) {
|
|
14478
14479
|
case "string": {
|
|
14479
14480
|
if (schemaValue.startsWith("t:")) {
|
|
14481
|
+
const localeConfig = localeConfigs[localeCode];
|
|
14480
14482
|
const key = schemaValue.slice(2);
|
|
14481
14483
|
const keyParts = key?.split(".");
|
|
14482
14484
|
const keyName = keyParts.pop() || "";
|
|
14483
14485
|
const keyPath = keyParts.join(".");
|
|
14484
|
-
const langObject = (0, import_lodash_es7.get)(
|
|
14486
|
+
const langObject = (0, import_lodash_es7.get)(localeConfig, keyPath);
|
|
14485
14487
|
return langObject?.[keyName] ?? key;
|
|
14486
14488
|
}
|
|
14487
14489
|
break;
|
|
@@ -14491,11 +14493,11 @@ ${injects.join("\n")}</script>`;
|
|
|
14491
14493
|
const result = [];
|
|
14492
14494
|
for (const value of schemaValue) {
|
|
14493
14495
|
result.push(
|
|
14494
|
-
|
|
14496
|
+
this.renderSchemaTranslationValue(
|
|
14495
14497
|
theme,
|
|
14496
14498
|
value,
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
+
localeCode,
|
|
14500
|
+
localeConfigs
|
|
14499
14501
|
)
|
|
14500
14502
|
);
|
|
14501
14503
|
}
|
|
@@ -14504,12 +14506,26 @@ ${injects.join("\n")}</script>`;
|
|
|
14504
14506
|
if (schemaValue !== null) {
|
|
14505
14507
|
const result = { ...schemaValue };
|
|
14506
14508
|
for (const [key, value] of Object.entries(schemaValue)) {
|
|
14507
|
-
result[key] =
|
|
14509
|
+
result[key] = this.renderSchemaTranslationValue(
|
|
14508
14510
|
theme,
|
|
14509
14511
|
value,
|
|
14510
|
-
|
|
14511
|
-
|
|
14512
|
+
localeCode,
|
|
14513
|
+
localeConfigs
|
|
14512
14514
|
);
|
|
14515
|
+
if (typeof value === "string" && value.startsWith("t:")) {
|
|
14516
|
+
for (const locale of Object.keys(localeConfigs)) {
|
|
14517
|
+
if (locale === localeCode) {
|
|
14518
|
+
continue;
|
|
14519
|
+
}
|
|
14520
|
+
const localeValue = this.renderSchemaTranslationValue(
|
|
14521
|
+
theme,
|
|
14522
|
+
value,
|
|
14523
|
+
locale,
|
|
14524
|
+
localeConfigs
|
|
14525
|
+
);
|
|
14526
|
+
(0, import_lodash_es7.set)(result, `$locale.${locale}.${key}`, localeValue);
|
|
14527
|
+
}
|
|
14528
|
+
}
|
|
14513
14529
|
}
|
|
14514
14530
|
return result;
|
|
14515
14531
|
}
|
|
@@ -16211,19 +16227,12 @@ function bind45(_liquidSwell) {
|
|
|
16211
16227
|
// src/liquid/filters/locale_flag.ts
|
|
16212
16228
|
var import_country_flag_icons = require("country-flag-icons");
|
|
16213
16229
|
var flags = __toESM(require("country-flag-icons/string/1x1"), 1);
|
|
16214
|
-
function getCountryCode(localCode) {
|
|
16215
|
-
if (localCode.includes("-")) {
|
|
16216
|
-
return localCode.split("-")[1].toUpperCase();
|
|
16217
|
-
} else {
|
|
16218
|
-
return localCode.toUpperCase();
|
|
16219
|
-
}
|
|
16220
|
-
}
|
|
16221
16230
|
function bind46(_liquidSwell) {
|
|
16222
16231
|
return (localeCode) => {
|
|
16223
16232
|
if (typeof localeCode !== "string") {
|
|
16224
16233
|
return flags.US;
|
|
16225
16234
|
}
|
|
16226
|
-
const countryCode =
|
|
16235
|
+
const countryCode = getCountryCodeFromLocale(localeCode).toUpperCase();
|
|
16227
16236
|
return (0, import_country_flag_icons.hasFlag)(countryCode) ? flags[countryCode] : flags.US;
|
|
16228
16237
|
};
|
|
16229
16238
|
}
|
|
@@ -16431,7 +16440,7 @@ var item_count_for_variant_default = {
|
|
|
16431
16440
|
// src/liquid/filters/shopify/payment_button.ts
|
|
16432
16441
|
function bind60(_liquidSwell) {
|
|
16433
16442
|
return (form) => {
|
|
16434
|
-
return
|
|
16443
|
+
return `<button style="display: block; visibility: hidden;"></button>`;
|
|
16435
16444
|
};
|
|
16436
16445
|
}
|
|
16437
16446
|
|
|
@@ -18945,7 +18954,7 @@ function resolveSectionSettings(theme, sectionConfig, index) {
|
|
|
18945
18954
|
let blocks = settings.section.blocks?.filter(
|
|
18946
18955
|
(block) => block.disabled !== true
|
|
18947
18956
|
);
|
|
18948
|
-
blocks = blocks?.map((block) => ({
|
|
18957
|
+
blocks = blocks?.filter((block) => Boolean(block.type)).map((block) => ({
|
|
18949
18958
|
...block,
|
|
18950
18959
|
...getBlockAttributes(theme, block),
|
|
18951
18960
|
settings: resolveThemeSettings(
|