@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.mjs CHANGED
@@ -888,7 +888,10 @@ var SwellStorefrontCollection = class _SwellStorefrontCollection extends SwellSt
888
888
  }
889
889
  return this._resolve().then(() => this.makeIterator());
890
890
  }
891
- makeIterator() {
891
+ async makeIterator() {
892
+ if (isLikePromise(this.results)) {
893
+ await this.results;
894
+ }
892
895
  return (this.results || []).values();
893
896
  }
894
897
  _clone(newProps) {
@@ -3640,11 +3643,11 @@ function arrayToObject(arr, key = "id") {
3640
3643
  );
3641
3644
  }
3642
3645
  function getCountryCodeFromLocale(locale) {
3643
- const split = locale.split(/-|_/);
3644
- const country = split.pop()?.toUpperCase();
3645
- const lang = split.join("-");
3646
- const code = country ? country : LANG_TO_COUNTRY_CODES[lang] || "";
3647
- return code.toLowerCase();
3646
+ const [lang, country] = locale.split(/-|_/);
3647
+ if (country) {
3648
+ return country.toLowerCase();
3649
+ }
3650
+ return (LANG_TO_COUNTRY_CODES[lang] || "").toLowerCase();
3648
3651
  }
3649
3652
  function getCountryByCurrency(currencyCode) {
3650
3653
  if (currencyCode in CURRENCY_COUNTRIES) {
@@ -5423,7 +5426,7 @@ function getBlog(swell, id, query) {
5423
5426
 
5424
5427
  // src/easyblocks/config.ts
5425
5428
  import JSON53 from "json5";
5426
- import { reduce as reduce2 } from "lodash-es";
5429
+ import { reduce as reduce2, set } from "lodash-es";
5427
5430
 
5428
5431
  // src/compatibility/drops/template.ts
5429
5432
  import { Drop as Drop3 } from "liquidjs";
@@ -5759,86 +5762,76 @@ function prepareSectionId(id) {
5759
5762
  }
5760
5763
  function getAllSectionComponentTemplates(allSections) {
5761
5764
  const list = [];
5765
+ const processFields = (fields, settings = {}) => {
5766
+ const result = {};
5767
+ for (const field of fields) {
5768
+ if (!field?.id) {
5769
+ continue;
5770
+ }
5771
+ const { id: fieldId, $locale } = field;
5772
+ result[fieldId] = schemaToEasyblocksValue(
5773
+ fields,
5774
+ fieldId,
5775
+ settings[fieldId]
5776
+ );
5777
+ if ($locale) {
5778
+ for (const [locale, localeValues] of Object.entries($locale)) {
5779
+ const defaultValue = localeValues?.default;
5780
+ if (defaultValue) {
5781
+ set(result, `$locale.${locale}.${fieldId}`, defaultValue);
5782
+ }
5783
+ }
5784
+ }
5785
+ }
5786
+ return result;
5787
+ };
5762
5788
  for (const section of allSections) {
5763
5789
  if (section.presets) {
5764
- list.push(
5765
- ...section.presets.map((preset, index) => ({
5790
+ for (let index = 0; index < section.presets.length; index++) {
5791
+ const preset = section.presets[index];
5792
+ const entry = {
5793
+ _id: `${section.id}__preset_${index}`,
5794
+ _component: section.id,
5795
+ custom_css: preset.settings?.["custom_css"] || "",
5796
+ ...processFields(section.fields, preset.settings),
5797
+ // Process blocks inside the preset
5798
+ Blocks: (preset.blocks || []).map((block) => {
5799
+ const blockSchema = section.blocks?.find(
5800
+ ({ type }) => type === block.type
5801
+ );
5802
+ if (!blockSchema) {
5803
+ return null;
5804
+ }
5805
+ return {
5806
+ _id: `Block__${section.id}__${block.type}__preset_${index}`,
5807
+ _component: `Block__${section.id}__${block.type}`,
5808
+ ...processFields(blockSchema.fields, block.settings)
5809
+ };
5810
+ }).filter(Boolean)
5811
+ };
5812
+ list.push({
5766
5813
  id: `${section.id}__preset_${index}`,
5767
- entry: {
5768
- _id: `${section.id}__preset_${index}`,
5769
- _component: section.id,
5770
- custom_css: preset.settings?.["custom_css"] || "",
5771
- ...reduce2(
5772
- section.fields,
5773
- (acc, field) => {
5774
- if (field.id) {
5775
- acc[field.id] = schemaToEasyblocksValue(
5776
- section.fields,
5777
- field.id,
5778
- preset.settings?.[field.id]
5779
- );
5780
- }
5781
- return acc;
5782
- },
5783
- {}
5784
- ),
5785
- Blocks: preset.blocks?.reduce(
5786
- (acc, block) => {
5787
- const blockDef = section.blocks?.find(
5788
- ({ type }) => type === block.type
5789
- );
5790
- if (blockDef) {
5791
- acc.push({
5792
- _id: `Block__${section.id}__${block.type}__preset_${index}`,
5793
- _component: `Block__${section.id}__${block.type}`,
5794
- ...reduce2(
5795
- blockDef.fields,
5796
- (acc2, blockField) => {
5797
- if (blockField.id) {
5798
- acc2[blockField.id] = schemaToEasyblocksValue(
5799
- blockDef.fields,
5800
- blockField.id,
5801
- block.settings?.[blockField.id]
5802
- );
5803
- }
5804
- return acc2;
5805
- },
5806
- {}
5807
- )
5808
- });
5809
- }
5810
- return acc;
5811
- },
5812
- []
5813
- )
5814
- }
5815
- }))
5816
- );
5814
+ entry
5815
+ });
5816
+ }
5817
5817
  }
5818
5818
  if (section.blocks) {
5819
- list.push(
5820
- ...section.blocks.map((block) => ({
5819
+ for (const block of section.blocks) {
5820
+ list.push({
5821
5821
  id: `Block__${section.id}__${block.type}`,
5822
5822
  entry: {
5823
5823
  _id: `Block__${section.id}__${block.type}`,
5824
5824
  _component: `Block__${section.id}__${block.type}`,
5825
- ...reduce2(
5825
+ ...processFields(
5826
5826
  block.fields,
5827
- (acc, field) => {
5828
- if (field.id) {
5829
- acc[field.id] = schemaToEasyblocksValue(
5830
- block.fields,
5831
- field.id,
5832
- field.default
5833
- );
5834
- }
5827
+ block.fields.reduce((acc, f) => {
5828
+ if (f.id) acc[f.id] = f.default;
5835
5829
  return acc;
5836
- },
5837
- {}
5830
+ }, {})
5838
5831
  )
5839
5832
  }
5840
- }))
5841
- );
5833
+ });
5834
+ }
5842
5835
  }
5843
5836
  }
5844
5837
  return list;
@@ -6269,7 +6262,7 @@ import JSON56 from "json5";
6269
6262
  import { get as get2, each, find, reduce as reduce3, cloneDeep as cloneDeep4 } from "lodash-es";
6270
6263
 
6271
6264
  // src/compatibility/shopify.ts
6272
- import { get, isObject as isObject4, merge } from "lodash-es";
6265
+ import { get, set as set2, isObject as isObject4, merge } from "lodash-es";
6273
6266
 
6274
6267
  // src/fonts.ts
6275
6268
  var fontMap = [
@@ -10226,6 +10219,9 @@ function getLocalizedValue(value, locale) {
10226
10219
 
10227
10220
  // src/compatibility/shopify-fonts.ts
10228
10221
  function shopifyFontToThemeFront(shopifyFontSetting) {
10222
+ if (typeof shopifyFontSetting !== "string") {
10223
+ return null;
10224
+ }
10229
10225
  const pos = shopifyFontSetting.lastIndexOf("_");
10230
10226
  const familyId = shopifyFontSetting.substring(0, pos);
10231
10227
  const variantId = shopifyFontSetting.substring(pos + 1);
@@ -11558,16 +11554,16 @@ function ShopifyBlog(instance, blogCategory) {
11558
11554
  if (!Array.isArray(blogs?.results)) {
11559
11555
  return [];
11560
11556
  }
11561
- const set = blogs.results.reduce(
11562
- (set2, blog) => {
11557
+ const set3 = blogs.results.reduce(
11558
+ (set4, blog) => {
11563
11559
  for (const tag of blog.tags || []) {
11564
- set2.add(tag);
11560
+ set4.add(tag);
11565
11561
  }
11566
- return set2;
11562
+ return set4;
11567
11563
  },
11568
11564
  /* @__PURE__ */ new Set()
11569
11565
  );
11570
- return Array.from(set.values());
11566
+ return Array.from(set3.values());
11571
11567
  });
11572
11568
  return new ShopifyResource({
11573
11569
  all_tags: allTags,
@@ -11951,18 +11947,18 @@ function ShopifyCollection(instance, category) {
11951
11947
  if (!resolved) {
11952
11948
  return [];
11953
11949
  }
11954
- const set = /* @__PURE__ */ new Set();
11950
+ const set3 = /* @__PURE__ */ new Set();
11955
11951
  await Promise.all(
11956
11952
  resolved.results.map(async (product) => {
11957
11953
  const tags2 = await Promise.resolve().then(() => product.tags);
11958
11954
  if (Array.isArray(tags2)) {
11959
11955
  for (const tag of tags2) {
11960
- set.add(tag);
11956
+ set3.add(tag);
11961
11957
  }
11962
11958
  }
11963
11959
  })
11964
11960
  );
11965
- return Array.from(set.values());
11961
+ return Array.from(set3.values());
11966
11962
  }),
11967
11963
  all_types: defer(async () => {
11968
11964
  const products = await resolveProducts();
@@ -14312,26 +14308,32 @@ ${injects.join("\n")}</script>`;
14312
14308
  if (!isObject4(schema)) {
14313
14309
  return schema;
14314
14310
  }
14315
- const editorLocaleConfig = await this.getEditorLocaleConfig(
14316
- theme,
14317
- localeCode
14318
- );
14311
+ const locales = await theme.swell.storefront.locale.list();
14312
+ const localeCodes = /* @__PURE__ */ new Set([
14313
+ localeCode,
14314
+ ...locales.map((locale) => locale.code)
14315
+ ]);
14316
+ const localeConfigs = {};
14317
+ for (const locale of localeCodes) {
14318
+ localeConfigs[locale] = await this.getEditorLocaleConfig(theme, locale);
14319
+ }
14319
14320
  return this.renderSchemaTranslationValue(
14320
14321
  theme,
14321
14322
  schema,
14322
14323
  localeCode,
14323
- editorLocaleConfig
14324
+ localeConfigs
14324
14325
  );
14325
14326
  }
14326
- async renderSchemaTranslationValue(theme, schemaValue, localCode, editorLocaleConfig) {
14327
+ renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
14327
14328
  switch (typeof schemaValue) {
14328
14329
  case "string": {
14329
14330
  if (schemaValue.startsWith("t:")) {
14331
+ const localeConfig = localeConfigs[localeCode];
14330
14332
  const key = schemaValue.slice(2);
14331
14333
  const keyParts = key?.split(".");
14332
14334
  const keyName = keyParts.pop() || "";
14333
14335
  const keyPath = keyParts.join(".");
14334
- const langObject = get(editorLocaleConfig, keyPath);
14336
+ const langObject = get(localeConfig, keyPath);
14335
14337
  return langObject?.[keyName] ?? key;
14336
14338
  }
14337
14339
  break;
@@ -14341,11 +14343,11 @@ ${injects.join("\n")}</script>`;
14341
14343
  const result = [];
14342
14344
  for (const value of schemaValue) {
14343
14345
  result.push(
14344
- await this.renderSchemaTranslationValue(
14346
+ this.renderSchemaTranslationValue(
14345
14347
  theme,
14346
14348
  value,
14347
- localCode,
14348
- editorLocaleConfig
14349
+ localeCode,
14350
+ localeConfigs
14349
14351
  )
14350
14352
  );
14351
14353
  }
@@ -14354,12 +14356,26 @@ ${injects.join("\n")}</script>`;
14354
14356
  if (schemaValue !== null) {
14355
14357
  const result = { ...schemaValue };
14356
14358
  for (const [key, value] of Object.entries(schemaValue)) {
14357
- result[key] = await this.renderSchemaTranslationValue(
14359
+ result[key] = this.renderSchemaTranslationValue(
14358
14360
  theme,
14359
14361
  value,
14360
- localCode,
14361
- editorLocaleConfig
14362
+ localeCode,
14363
+ localeConfigs
14362
14364
  );
14365
+ if (typeof value === "string" && value.startsWith("t:")) {
14366
+ for (const locale of Object.keys(localeConfigs)) {
14367
+ if (locale === localeCode) {
14368
+ continue;
14369
+ }
14370
+ const localeValue = this.renderSchemaTranslationValue(
14371
+ theme,
14372
+ value,
14373
+ locale,
14374
+ localeConfigs
14375
+ );
14376
+ set2(result, `$locale.${locale}.${key}`, localeValue);
14377
+ }
14378
+ }
14363
14379
  }
14364
14380
  return result;
14365
14381
  }
@@ -16069,19 +16085,12 @@ function bind45(_liquidSwell) {
16069
16085
  // src/liquid/filters/locale_flag.ts
16070
16086
  import { hasFlag } from "country-flag-icons";
16071
16087
  import * as flags from "country-flag-icons/string/1x1";
16072
- function getCountryCode(localCode) {
16073
- if (localCode.includes("-")) {
16074
- return localCode.split("-")[1].toUpperCase();
16075
- } else {
16076
- return localCode.toUpperCase();
16077
- }
16078
- }
16079
16088
  function bind46(_liquidSwell) {
16080
16089
  return (localeCode) => {
16081
16090
  if (typeof localeCode !== "string") {
16082
16091
  return flags.US;
16083
16092
  }
16084
- const countryCode = getCountryCode(localeCode);
16093
+ const countryCode = getCountryCodeFromLocale(localeCode).toUpperCase();
16085
16094
  return hasFlag(countryCode) ? flags[countryCode] : flags.US;
16086
16095
  };
16087
16096
  }
@@ -16289,7 +16298,7 @@ var item_count_for_variant_default = {
16289
16298
  // src/liquid/filters/shopify/payment_button.ts
16290
16299
  function bind60(_liquidSwell) {
16291
16300
  return (form) => {
16292
- return null;
16301
+ return `<button style="display: block; visibility: hidden;"></button>`;
16293
16302
  };
16294
16303
  }
16295
16304
 
@@ -18803,7 +18812,7 @@ function resolveSectionSettings(theme, sectionConfig, index) {
18803
18812
  let blocks = settings.section.blocks?.filter(
18804
18813
  (block) => block.disabled !== true
18805
18814
  );
18806
- blocks = blocks?.map((block) => ({
18815
+ blocks = blocks?.filter((block) => Boolean(block.type)).map((block) => ({
18807
18816
  ...block,
18808
18817
  ...getBlockAttributes(theme, block),
18809
18818
  settings: resolveThemeSettings(