@swell/apps-sdk 1.0.179 → 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
@@ -3252,7 +3252,7 @@ function getSectionSettingsFromProps(props, sectionSchema) {
3252
3252
  (block) => block.type === blockType
3253
3253
  );
3254
3254
  return {
3255
- id,
3255
+ id: toBlockId(id),
3256
3256
  type: blockType,
3257
3257
  disabled: isDisabled,
3258
3258
  settings: blockSchema?.fields?.reduce(
@@ -3281,6 +3281,12 @@ function toSchemaFieldId(fieldId) {
3281
3281
  }
3282
3282
  return fieldId.replace(/·/g, ".");
3283
3283
  }
3284
+ function toBlockId(id) {
3285
+ if (!id) {
3286
+ return id;
3287
+ }
3288
+ return id.replace(/\./g, "_");
3289
+ }
3284
3290
 
3285
3291
  // src/utils/md5.ts
3286
3292
  function md5(inputString) {
@@ -5417,7 +5423,7 @@ function getBlog(swell, id, query) {
5417
5423
 
5418
5424
  // src/easyblocks/config.ts
5419
5425
  import JSON53 from "json5";
5420
- import { reduce as reduce2 } from "lodash-es";
5426
+ import { reduce as reduce2, set } from "lodash-es";
5421
5427
 
5422
5428
  // src/compatibility/drops/template.ts
5423
5429
  import { Drop as Drop3 } from "liquidjs";
@@ -5753,86 +5759,76 @@ function prepareSectionId(id) {
5753
5759
  }
5754
5760
  function getAllSectionComponentTemplates(allSections) {
5755
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
+ };
5756
5785
  for (const section of allSections) {
5757
5786
  if (section.presets) {
5758
- list.push(
5759
- ...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({
5760
5810
  id: `${section.id}__preset_${index}`,
5761
- entry: {
5762
- _id: `${section.id}__preset_${index}`,
5763
- _component: section.id,
5764
- custom_css: preset.settings?.["custom_css"] || "",
5765
- ...reduce2(
5766
- section.fields,
5767
- (acc, field) => {
5768
- if (field.id) {
5769
- acc[field.id] = schemaToEasyblocksValue(
5770
- section.fields,
5771
- field.id,
5772
- preset.settings?.[field.id]
5773
- );
5774
- }
5775
- return acc;
5776
- },
5777
- {}
5778
- ),
5779
- Blocks: preset.blocks?.reduce(
5780
- (acc, block) => {
5781
- const blockDef = section.blocks?.find(
5782
- ({ type }) => type === block.type
5783
- );
5784
- if (blockDef) {
5785
- acc.push({
5786
- _id: `Block__${section.id}__${block.type}__preset_${index}`,
5787
- _component: `Block__${section.id}__${block.type}`,
5788
- ...reduce2(
5789
- blockDef.fields,
5790
- (acc2, blockField) => {
5791
- if (blockField.id) {
5792
- acc2[blockField.id] = schemaToEasyblocksValue(
5793
- blockDef.fields,
5794
- blockField.id,
5795
- block.settings?.[blockField.id]
5796
- );
5797
- }
5798
- return acc2;
5799
- },
5800
- {}
5801
- )
5802
- });
5803
- }
5804
- return acc;
5805
- },
5806
- []
5807
- )
5808
- }
5809
- }))
5810
- );
5811
+ entry
5812
+ });
5813
+ }
5811
5814
  }
5812
5815
  if (section.blocks) {
5813
- list.push(
5814
- ...section.blocks.map((block) => ({
5816
+ for (const block of section.blocks) {
5817
+ list.push({
5815
5818
  id: `Block__${section.id}__${block.type}`,
5816
5819
  entry: {
5817
5820
  _id: `Block__${section.id}__${block.type}`,
5818
5821
  _component: `Block__${section.id}__${block.type}`,
5819
- ...reduce2(
5822
+ ...processFields(
5820
5823
  block.fields,
5821
- (acc, field) => {
5822
- if (field.id) {
5823
- acc[field.id] = schemaToEasyblocksValue(
5824
- block.fields,
5825
- field.id,
5826
- field.default
5827
- );
5828
- }
5824
+ block.fields.reduce((acc, f) => {
5825
+ if (f.id) acc[f.id] = f.default;
5829
5826
  return acc;
5830
- },
5831
- {}
5827
+ }, {})
5832
5828
  )
5833
5829
  }
5834
- }))
5835
- );
5830
+ });
5831
+ }
5836
5832
  }
5837
5833
  }
5838
5834
  return list;
@@ -6263,7 +6259,7 @@ import JSON56 from "json5";
6263
6259
  import { get as get2, each, find, reduce as reduce3, cloneDeep as cloneDeep4 } from "lodash-es";
6264
6260
 
6265
6261
  // src/compatibility/shopify.ts
6266
- import { get, isObject as isObject4, merge } from "lodash-es";
6262
+ import { get, set as set2, isObject as isObject4, merge } from "lodash-es";
6267
6263
 
6268
6264
  // src/fonts.ts
6269
6265
  var fontMap = [
@@ -11552,16 +11548,16 @@ function ShopifyBlog(instance, blogCategory) {
11552
11548
  if (!Array.isArray(blogs?.results)) {
11553
11549
  return [];
11554
11550
  }
11555
- const set = blogs.results.reduce(
11556
- (set2, blog) => {
11551
+ const set3 = blogs.results.reduce(
11552
+ (set4, blog) => {
11557
11553
  for (const tag of blog.tags || []) {
11558
- set2.add(tag);
11554
+ set4.add(tag);
11559
11555
  }
11560
- return set2;
11556
+ return set4;
11561
11557
  },
11562
11558
  /* @__PURE__ */ new Set()
11563
11559
  );
11564
- return Array.from(set.values());
11560
+ return Array.from(set3.values());
11565
11561
  });
11566
11562
  return new ShopifyResource({
11567
11563
  all_tags: allTags,
@@ -11945,18 +11941,18 @@ function ShopifyCollection(instance, category) {
11945
11941
  if (!resolved) {
11946
11942
  return [];
11947
11943
  }
11948
- const set = /* @__PURE__ */ new Set();
11944
+ const set3 = /* @__PURE__ */ new Set();
11949
11945
  await Promise.all(
11950
11946
  resolved.results.map(async (product) => {
11951
11947
  const tags2 = await Promise.resolve().then(() => product.tags);
11952
11948
  if (Array.isArray(tags2)) {
11953
11949
  for (const tag of tags2) {
11954
- set.add(tag);
11950
+ set3.add(tag);
11955
11951
  }
11956
11952
  }
11957
11953
  })
11958
11954
  );
11959
- return Array.from(set.values());
11955
+ return Array.from(set3.values());
11960
11956
  }),
11961
11957
  all_types: defer(async () => {
11962
11958
  const products = await resolveProducts();
@@ -14306,26 +14302,32 @@ ${injects.join("\n")}</script>`;
14306
14302
  if (!isObject4(schema)) {
14307
14303
  return schema;
14308
14304
  }
14309
- const editorLocaleConfig = await this.getEditorLocaleConfig(
14310
- theme,
14311
- localeCode
14312
- );
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
+ }
14313
14314
  return this.renderSchemaTranslationValue(
14314
14315
  theme,
14315
14316
  schema,
14316
14317
  localeCode,
14317
- editorLocaleConfig
14318
+ localeConfigs
14318
14319
  );
14319
14320
  }
14320
- async renderSchemaTranslationValue(theme, schemaValue, localCode, editorLocaleConfig) {
14321
+ renderSchemaTranslationValue(theme, schemaValue, localeCode, localeConfigs) {
14321
14322
  switch (typeof schemaValue) {
14322
14323
  case "string": {
14323
14324
  if (schemaValue.startsWith("t:")) {
14325
+ const localeConfig = localeConfigs[localeCode];
14324
14326
  const key = schemaValue.slice(2);
14325
14327
  const keyParts = key?.split(".");
14326
14328
  const keyName = keyParts.pop() || "";
14327
14329
  const keyPath = keyParts.join(".");
14328
- const langObject = get(editorLocaleConfig, keyPath);
14330
+ const langObject = get(localeConfig, keyPath);
14329
14331
  return langObject?.[keyName] ?? key;
14330
14332
  }
14331
14333
  break;
@@ -14335,11 +14337,11 @@ ${injects.join("\n")}</script>`;
14335
14337
  const result = [];
14336
14338
  for (const value of schemaValue) {
14337
14339
  result.push(
14338
- await this.renderSchemaTranslationValue(
14340
+ this.renderSchemaTranslationValue(
14339
14341
  theme,
14340
14342
  value,
14341
- localCode,
14342
- editorLocaleConfig
14343
+ localeCode,
14344
+ localeConfigs
14343
14345
  )
14344
14346
  );
14345
14347
  }
@@ -14348,12 +14350,26 @@ ${injects.join("\n")}</script>`;
14348
14350
  if (schemaValue !== null) {
14349
14351
  const result = { ...schemaValue };
14350
14352
  for (const [key, value] of Object.entries(schemaValue)) {
14351
- result[key] = await this.renderSchemaTranslationValue(
14353
+ result[key] = this.renderSchemaTranslationValue(
14352
14354
  theme,
14353
14355
  value,
14354
- localCode,
14355
- editorLocaleConfig
14356
+ localeCode,
14357
+ localeConfigs
14356
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
+ }
14357
14373
  }
14358
14374
  return result;
14359
14375
  }
@@ -16243,18 +16259,11 @@ function bind58(_liquidSwell) {
16243
16259
  }
16244
16260
 
16245
16261
  // src/liquid/filters/shopify/img_url.ts
16246
- function bind59(_liquidSwell) {
16247
- return function filterImgUrl(input, ...params) {
16248
- if (!input) return "";
16249
- let url;
16250
- if (typeof input === "object") {
16251
- if (input.url) {
16252
- url = input.url;
16253
- } else {
16254
- return "";
16255
- }
16256
- } else {
16257
- url = String(input);
16262
+ function bind59(liquidSwell) {
16263
+ return async function filterImgUrl(input, ...params) {
16264
+ const url = await getImageUrlFromInput(input, liquidSwell);
16265
+ if (typeof url !== "string" || url === "") {
16266
+ return "";
16258
16267
  }
16259
16268
  const query = [];
16260
16269
  params.forEach((param) => {
@@ -20053,6 +20062,7 @@ export {
20053
20062
  scopeCustomCSS,
20054
20063
  stringifyQueryParams,
20055
20064
  systemFonts,
20056
- toBase64
20065
+ toBase64,
20066
+ toBlockId
20057
20067
  };
20058
20068
  //# sourceMappingURL=index.mjs.map