@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.js CHANGED
@@ -5786,86 +5786,76 @@ ${formattedMessage}`;
5786
5786
  }
5787
5787
  function getAllSectionComponentTemplates(allSections) {
5788
5788
  const list = [];
5789
+ const processFields = (fields, settings = {}) => {
5790
+ const result = {};
5791
+ for (const field of fields) {
5792
+ if (!field?.id) {
5793
+ continue;
5794
+ }
5795
+ const { id: fieldId, $locale } = field;
5796
+ result[fieldId] = schemaToEasyblocksValue(
5797
+ fields,
5798
+ fieldId,
5799
+ settings[fieldId]
5800
+ );
5801
+ if ($locale) {
5802
+ for (const [locale, localeValues] of Object.entries($locale)) {
5803
+ const defaultValue = localeValues?.default;
5804
+ if (defaultValue) {
5805
+ (0, import_lodash_es4.set)(result, `$locale.${locale}.${fieldId}`, defaultValue);
5806
+ }
5807
+ }
5808
+ }
5809
+ }
5810
+ return result;
5811
+ };
5789
5812
  for (const section of allSections) {
5790
5813
  if (section.presets) {
5791
- list.push(
5792
- ...section.presets.map((preset, index) => ({
5814
+ for (let index = 0; index < section.presets.length; index++) {
5815
+ const preset = section.presets[index];
5816
+ const entry = {
5817
+ _id: `${section.id}__preset_${index}`,
5818
+ _component: section.id,
5819
+ custom_css: preset.settings?.["custom_css"] || "",
5820
+ ...processFields(section.fields, preset.settings),
5821
+ // Process blocks inside the preset
5822
+ Blocks: (preset.blocks || []).map((block) => {
5823
+ const blockSchema = section.blocks?.find(
5824
+ ({ type }) => type === block.type
5825
+ );
5826
+ if (!blockSchema) {
5827
+ return null;
5828
+ }
5829
+ return {
5830
+ _id: `Block__${section.id}__${block.type}__preset_${index}`,
5831
+ _component: `Block__${section.id}__${block.type}`,
5832
+ ...processFields(blockSchema.fields, block.settings)
5833
+ };
5834
+ }).filter(Boolean)
5835
+ };
5836
+ list.push({
5793
5837
  id: `${section.id}__preset_${index}`,
5794
- entry: {
5795
- _id: `${section.id}__preset_${index}`,
5796
- _component: section.id,
5797
- custom_css: preset.settings?.["custom_css"] || "",
5798
- ...(0, import_lodash_es4.reduce)(
5799
- section.fields,
5800
- (acc, field) => {
5801
- if (field.id) {
5802
- acc[field.id] = schemaToEasyblocksValue(
5803
- section.fields,
5804
- field.id,
5805
- preset.settings?.[field.id]
5806
- );
5807
- }
5808
- return acc;
5809
- },
5810
- {}
5811
- ),
5812
- Blocks: preset.blocks?.reduce(
5813
- (acc, block) => {
5814
- const blockDef = section.blocks?.find(
5815
- ({ type }) => type === block.type
5816
- );
5817
- if (blockDef) {
5818
- acc.push({
5819
- _id: `Block__${section.id}__${block.type}__preset_${index}`,
5820
- _component: `Block__${section.id}__${block.type}`,
5821
- ...(0, import_lodash_es4.reduce)(
5822
- blockDef.fields,
5823
- (acc2, blockField) => {
5824
- if (blockField.id) {
5825
- acc2[blockField.id] = schemaToEasyblocksValue(
5826
- blockDef.fields,
5827
- blockField.id,
5828
- block.settings?.[blockField.id]
5829
- );
5830
- }
5831
- return acc2;
5832
- },
5833
- {}
5834
- )
5835
- });
5836
- }
5837
- return acc;
5838
- },
5839
- []
5840
- )
5841
- }
5842
- }))
5843
- );
5838
+ entry
5839
+ });
5840
+ }
5844
5841
  }
5845
5842
  if (section.blocks) {
5846
- list.push(
5847
- ...section.blocks.map((block) => ({
5843
+ for (const block of section.blocks) {
5844
+ list.push({
5848
5845
  id: `Block__${section.id}__${block.type}`,
5849
5846
  entry: {
5850
5847
  _id: `Block__${section.id}__${block.type}`,
5851
5848
  _component: `Block__${section.id}__${block.type}`,
5852
- ...(0, import_lodash_es4.reduce)(
5849
+ ...processFields(
5853
5850
  block.fields,
5854
- (acc, field) => {
5855
- if (field.id) {
5856
- acc[field.id] = schemaToEasyblocksValue(
5857
- block.fields,
5858
- field.id,
5859
- field.default
5860
- );
5861
- }
5851
+ block.fields.reduce((acc, f) => {
5852
+ if (f.id) acc[f.id] = f.default;
5862
5853
  return acc;
5863
- },
5864
- {}
5854
+ }, {})
5865
5855
  )
5866
5856
  }
5867
- }))
5868
- );
5857
+ });
5858
+ }
5869
5859
  }
5870
5860
  }
5871
5861
  return list;
@@ -11585,16 +11575,16 @@ ${formattedMessage}`;
11585
11575
  if (!Array.isArray(blogs?.results)) {
11586
11576
  return [];
11587
11577
  }
11588
- const set = blogs.results.reduce(
11589
- (set2, blog) => {
11578
+ const set3 = blogs.results.reduce(
11579
+ (set4, blog) => {
11590
11580
  for (const tag of blog.tags || []) {
11591
- set2.add(tag);
11581
+ set4.add(tag);
11592
11582
  }
11593
- return set2;
11583
+ return set4;
11594
11584
  },
11595
11585
  /* @__PURE__ */ new Set()
11596
11586
  );
11597
- return Array.from(set.values());
11587
+ return Array.from(set3.values());
11598
11588
  });
11599
11589
  return new ShopifyResource({
11600
11590
  all_tags: allTags,
@@ -11978,18 +11968,18 @@ ${formattedMessage}`;
11978
11968
  if (!resolved) {
11979
11969
  return [];
11980
11970
  }
11981
- const set = /* @__PURE__ */ new Set();
11971
+ const set3 = /* @__PURE__ */ new Set();
11982
11972
  await Promise.all(
11983
11973
  resolved.results.map(async (product) => {
11984
11974
  const tags2 = await Promise.resolve().then(() => product.tags);
11985
11975
  if (Array.isArray(tags2)) {
11986
11976
  for (const tag of tags2) {
11987
- set.add(tag);
11977
+ set3.add(tag);
11988
11978
  }
11989
11979
  }
11990
11980
  })
11991
11981
  );
11992
- return Array.from(set.values());
11982
+ return Array.from(set3.values());
11993
11983
  }),
11994
11984
  all_types: defer(async () => {
11995
11985
  const products = await resolveProducts();
@@ -14339,26 +14329,32 @@ ${injects.join("\n")}<\/script>`;
14339
14329
  if (!(0, import_lodash_es7.isObject)(schema)) {
14340
14330
  return schema;
14341
14331
  }
14342
- const editorLocaleConfig = await this.getEditorLocaleConfig(
14343
- theme,
14344
- localeCode
14345
- );
14332
+ const locales = await theme.swell.storefront.locale.list();
14333
+ const localeCodes = /* @__PURE__ */ new Set([
14334
+ localeCode,
14335
+ ...locales.map((locale) => locale.code)
14336
+ ]);
14337
+ const localeConfigs = {};
14338
+ for (const locale of localeCodes) {
14339
+ localeConfigs[locale] = await this.getEditorLocaleConfig(theme, locale);
14340
+ }
14346
14341
  return this.renderSchemaTranslationValue(
14347
14342
  theme,
14348
14343
  schema,
14349
14344
  localeCode,
14350
- editorLocaleConfig
14345
+ localeConfigs
14351
14346
  );
14352
14347
  }
14353
- async renderSchemaTranslationValue(theme, schemaValue, localCode, editorLocaleConfig) {
14348
+ renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
14354
14349
  switch (typeof schemaValue) {
14355
14350
  case "string": {
14356
14351
  if (schemaValue.startsWith("t:")) {
14352
+ const localeConfig = localeConfigs[localeCode];
14357
14353
  const key = schemaValue.slice(2);
14358
14354
  const keyParts = key?.split(".");
14359
14355
  const keyName = keyParts.pop() || "";
14360
14356
  const keyPath = keyParts.join(".");
14361
- const langObject = (0, import_lodash_es7.get)(editorLocaleConfig, keyPath);
14357
+ const langObject = (0, import_lodash_es7.get)(localeConfig, keyPath);
14362
14358
  return langObject?.[keyName] ?? key;
14363
14359
  }
14364
14360
  break;
@@ -14368,11 +14364,11 @@ ${injects.join("\n")}<\/script>`;
14368
14364
  const result = [];
14369
14365
  for (const value of schemaValue) {
14370
14366
  result.push(
14371
- await this.renderSchemaTranslationValue(
14367
+ this.renderSchemaTranslationValue(
14372
14368
  theme,
14373
14369
  value,
14374
- localCode,
14375
- editorLocaleConfig
14370
+ localeCode,
14371
+ localeConfigs
14376
14372
  )
14377
14373
  );
14378
14374
  }
@@ -14381,12 +14377,26 @@ ${injects.join("\n")}<\/script>`;
14381
14377
  if (schemaValue !== null) {
14382
14378
  const result = { ...schemaValue };
14383
14379
  for (const [key, value] of Object.entries(schemaValue)) {
14384
- result[key] = await this.renderSchemaTranslationValue(
14380
+ result[key] = this.renderSchemaTranslationValue(
14385
14381
  theme,
14386
14382
  value,
14387
- localCode,
14388
- editorLocaleConfig
14383
+ localeCode,
14384
+ localeConfigs
14389
14385
  );
14386
+ if (typeof value === "string" && value.startsWith("t:")) {
14387
+ for (const locale of Object.keys(localeConfigs)) {
14388
+ if (locale === localeCode) {
14389
+ continue;
14390
+ }
14391
+ const localeValue = this.renderSchemaTranslationValue(
14392
+ theme,
14393
+ value,
14394
+ locale,
14395
+ localeConfigs
14396
+ );
14397
+ (0, import_lodash_es7.set)(result, `$locale.${locale}.${key}`, localeValue);
14398
+ }
14399
+ }
14390
14400
  }
14391
14401
  return result;
14392
14402
  }