@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.mjs CHANGED
@@ -5423,7 +5423,7 @@ function getBlog(swell, id, query) {
5423
5423
 
5424
5424
  // src/easyblocks/config.ts
5425
5425
  import JSON53 from "json5";
5426
- import { reduce as reduce2 } from "lodash-es";
5426
+ import { reduce as reduce2, set } from "lodash-es";
5427
5427
 
5428
5428
  // src/compatibility/drops/template.ts
5429
5429
  import { Drop as Drop3 } from "liquidjs";
@@ -5759,86 +5759,76 @@ function prepareSectionId(id) {
5759
5759
  }
5760
5760
  function getAllSectionComponentTemplates(allSections) {
5761
5761
  const list = [];
5762
+ const processFields = (fields, settings = {}) => {
5763
+ const result = {};
5764
+ for (const field of fields) {
5765
+ if (!field?.id) {
5766
+ continue;
5767
+ }
5768
+ const { id: fieldId, $locale } = field;
5769
+ result[fieldId] = schemaToEasyblocksValue(
5770
+ fields,
5771
+ fieldId,
5772
+ settings[fieldId]
5773
+ );
5774
+ if ($locale) {
5775
+ for (const [locale, localeValues] of Object.entries($locale)) {
5776
+ const defaultValue = localeValues?.default;
5777
+ if (defaultValue) {
5778
+ set(result, `$locale.${locale}.${fieldId}`, defaultValue);
5779
+ }
5780
+ }
5781
+ }
5782
+ }
5783
+ return result;
5784
+ };
5762
5785
  for (const section of allSections) {
5763
5786
  if (section.presets) {
5764
- list.push(
5765
- ...section.presets.map((preset, index) => ({
5787
+ for (let index = 0; index < section.presets.length; index++) {
5788
+ const preset = section.presets[index];
5789
+ const entry = {
5790
+ _id: `${section.id}__preset_${index}`,
5791
+ _component: section.id,
5792
+ custom_css: preset.settings?.["custom_css"] || "",
5793
+ ...processFields(section.fields, preset.settings),
5794
+ // Process blocks inside the preset
5795
+ Blocks: (preset.blocks || []).map((block) => {
5796
+ const blockSchema = section.blocks?.find(
5797
+ ({ type }) => type === block.type
5798
+ );
5799
+ if (!blockSchema) {
5800
+ return null;
5801
+ }
5802
+ return {
5803
+ _id: `Block__${section.id}__${block.type}__preset_${index}`,
5804
+ _component: `Block__${section.id}__${block.type}`,
5805
+ ...processFields(blockSchema.fields, block.settings)
5806
+ };
5807
+ }).filter(Boolean)
5808
+ };
5809
+ list.push({
5766
5810
  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
- );
5811
+ entry
5812
+ });
5813
+ }
5817
5814
  }
5818
5815
  if (section.blocks) {
5819
- list.push(
5820
- ...section.blocks.map((block) => ({
5816
+ for (const block of section.blocks) {
5817
+ list.push({
5821
5818
  id: `Block__${section.id}__${block.type}`,
5822
5819
  entry: {
5823
5820
  _id: `Block__${section.id}__${block.type}`,
5824
5821
  _component: `Block__${section.id}__${block.type}`,
5825
- ...reduce2(
5822
+ ...processFields(
5826
5823
  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
- }
5824
+ block.fields.reduce((acc, f) => {
5825
+ if (f.id) acc[f.id] = f.default;
5835
5826
  return acc;
5836
- },
5837
- {}
5827
+ }, {})
5838
5828
  )
5839
5829
  }
5840
- }))
5841
- );
5830
+ });
5831
+ }
5842
5832
  }
5843
5833
  }
5844
5834
  return list;
@@ -6269,7 +6259,7 @@ import JSON56 from "json5";
6269
6259
  import { get as get2, each, find, reduce as reduce3, cloneDeep as cloneDeep4 } from "lodash-es";
6270
6260
 
6271
6261
  // src/compatibility/shopify.ts
6272
- import { get, isObject as isObject4, merge } from "lodash-es";
6262
+ import { get, set as set2, isObject as isObject4, merge } from "lodash-es";
6273
6263
 
6274
6264
  // src/fonts.ts
6275
6265
  var fontMap = [
@@ -11558,16 +11548,16 @@ function ShopifyBlog(instance, blogCategory) {
11558
11548
  if (!Array.isArray(blogs?.results)) {
11559
11549
  return [];
11560
11550
  }
11561
- const set = blogs.results.reduce(
11562
- (set2, blog) => {
11551
+ const set3 = blogs.results.reduce(
11552
+ (set4, blog) => {
11563
11553
  for (const tag of blog.tags || []) {
11564
- set2.add(tag);
11554
+ set4.add(tag);
11565
11555
  }
11566
- return set2;
11556
+ return set4;
11567
11557
  },
11568
11558
  /* @__PURE__ */ new Set()
11569
11559
  );
11570
- return Array.from(set.values());
11560
+ return Array.from(set3.values());
11571
11561
  });
11572
11562
  return new ShopifyResource({
11573
11563
  all_tags: allTags,
@@ -11951,18 +11941,18 @@ function ShopifyCollection(instance, category) {
11951
11941
  if (!resolved) {
11952
11942
  return [];
11953
11943
  }
11954
- const set = /* @__PURE__ */ new Set();
11944
+ const set3 = /* @__PURE__ */ new Set();
11955
11945
  await Promise.all(
11956
11946
  resolved.results.map(async (product) => {
11957
11947
  const tags2 = await Promise.resolve().then(() => product.tags);
11958
11948
  if (Array.isArray(tags2)) {
11959
11949
  for (const tag of tags2) {
11960
- set.add(tag);
11950
+ set3.add(tag);
11961
11951
  }
11962
11952
  }
11963
11953
  })
11964
11954
  );
11965
- return Array.from(set.values());
11955
+ return Array.from(set3.values());
11966
11956
  }),
11967
11957
  all_types: defer(async () => {
11968
11958
  const products = await resolveProducts();
@@ -14312,26 +14302,32 @@ ${injects.join("\n")}</script>`;
14312
14302
  if (!isObject4(schema)) {
14313
14303
  return schema;
14314
14304
  }
14315
- const editorLocaleConfig = await this.getEditorLocaleConfig(
14316
- theme,
14317
- localeCode
14318
- );
14305
+ const locales = await theme.swell.storefront.locale.list();
14306
+ const localeCodes = /* @__PURE__ */ new Set([
14307
+ localeCode,
14308
+ ...locales.map((locale) => locale.code)
14309
+ ]);
14310
+ const localeConfigs = {};
14311
+ for (const locale of localeCodes) {
14312
+ localeConfigs[locale] = await this.getEditorLocaleConfig(theme, locale);
14313
+ }
14319
14314
  return this.renderSchemaTranslationValue(
14320
14315
  theme,
14321
14316
  schema,
14322
14317
  localeCode,
14323
- editorLocaleConfig
14318
+ localeConfigs
14324
14319
  );
14325
14320
  }
14326
- async renderSchemaTranslationValue(theme, schemaValue, localCode, editorLocaleConfig) {
14321
+ renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
14327
14322
  switch (typeof schemaValue) {
14328
14323
  case "string": {
14329
14324
  if (schemaValue.startsWith("t:")) {
14325
+ const localeConfig = localeConfigs[localeCode];
14330
14326
  const key = schemaValue.slice(2);
14331
14327
  const keyParts = key?.split(".");
14332
14328
  const keyName = keyParts.pop() || "";
14333
14329
  const keyPath = keyParts.join(".");
14334
- const langObject = get(editorLocaleConfig, keyPath);
14330
+ const langObject = get(localeConfig, keyPath);
14335
14331
  return langObject?.[keyName] ?? key;
14336
14332
  }
14337
14333
  break;
@@ -14341,11 +14337,11 @@ ${injects.join("\n")}</script>`;
14341
14337
  const result = [];
14342
14338
  for (const value of schemaValue) {
14343
14339
  result.push(
14344
- await this.renderSchemaTranslationValue(
14340
+ this.renderSchemaTranslationValue(
14345
14341
  theme,
14346
14342
  value,
14347
- localCode,
14348
- editorLocaleConfig
14343
+ localeCode,
14344
+ localeConfigs
14349
14345
  )
14350
14346
  );
14351
14347
  }
@@ -14354,12 +14350,26 @@ ${injects.join("\n")}</script>`;
14354
14350
  if (schemaValue !== null) {
14355
14351
  const result = { ...schemaValue };
14356
14352
  for (const [key, value] of Object.entries(schemaValue)) {
14357
- result[key] = await this.renderSchemaTranslationValue(
14353
+ result[key] = this.renderSchemaTranslationValue(
14358
14354
  theme,
14359
14355
  value,
14360
- localCode,
14361
- editorLocaleConfig
14356
+ localeCode,
14357
+ localeConfigs
14362
14358
  );
14359
+ if (typeof value === "string" && value.startsWith("t:")) {
14360
+ for (const locale of Object.keys(localeConfigs)) {
14361
+ if (locale === localeCode) {
14362
+ continue;
14363
+ }
14364
+ const localeValue = this.renderSchemaTranslationValue(
14365
+ theme,
14366
+ value,
14367
+ locale,
14368
+ localeConfigs
14369
+ );
14370
+ set2(result, `$locale.${locale}.${key}`, localeValue);
14371
+ }
14372
+ }
14363
14373
  }
14364
14374
  return result;
14365
14375
  }