@swell/apps-sdk 1.0.129 → 1.0.130

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
@@ -7682,11 +7682,12 @@ async function getBlog(swell, id, query) {
7682
7682
  import JSON53 from "json5";
7683
7683
  import { reduce as reduce2 } from "lodash-es";
7684
7684
  var NO_INLINE = true;
7685
- async function getEasyblocksPageTemplate(theme, pageId) {
7685
+ async function getEasyblocksPageTemplate(theme, pageId, altTemplate) {
7686
7686
  let templateConfig = null;
7687
7687
  templateConfig = await theme.getThemeTemplateConfigByType(
7688
7688
  "templates",
7689
- pageId
7689
+ pageId,
7690
+ altTemplate
7690
7691
  );
7691
7692
  if (templateConfig) {
7692
7693
  if (templateConfig.file_path.endsWith(".liquid")) {
@@ -13740,8 +13741,7 @@ function ShopifyArticle(instance, blog, blogCategory) {
13740
13741
  (blog2) => blog2.date_published || blog2.date_created
13741
13742
  ),
13742
13743
  tags: defer(() => blog.tags),
13743
- template_suffix: void 0,
13744
- // TODO
13744
+ template_suffix: defer(() => blog.theme_template),
13745
13745
  title: defer(() => blog.title),
13746
13746
  updated_at: deferWith(
13747
13747
  blog,
@@ -13810,8 +13810,7 @@ function ShopifyBlog(instance, blogCategory) {
13810
13810
  // TODO
13811
13811
  tags: allTags,
13812
13812
  // TODO: this should only apply to articles in the current view
13813
- template_suffix: void 0,
13814
- // TODO
13813
+ template_suffix: defer(() => blogCategory.theme_template),
13815
13814
  title: defer(() => blogCategory.title),
13816
13815
  url: deferWith(
13817
13816
  blogCategory,
@@ -14209,7 +14208,7 @@ function ShopifyProduct(instance, product, depth = 0) {
14209
14208
  selected_variant: void 0,
14210
14209
  selling_plan_groups: [],
14211
14210
  tags: defer(() => product.tags),
14212
- template_suffix: void 0,
14211
+ template_suffix: defer(() => product.theme_template),
14213
14212
  title: defer(() => product.name),
14214
14213
  type: defer(() => product.type),
14215
14214
  url: deferWith(product, (product2) => `/products/${product2.slug}`),
@@ -14721,7 +14720,7 @@ function ShopifyCollection(instance, category) {
14721
14720
  sort_by: defer(() => category.sort),
14722
14721
  sort_options: defer(() => category.sort_options),
14723
14722
  tags: [],
14724
- template_suffix: void 0,
14723
+ template_suffix: defer(() => category.theme_template),
14725
14724
  title: defer(() => category.name),
14726
14725
  url: deferWith(category, (category2) => `/collections/${category2.slug}`)
14727
14726
  });
@@ -15522,8 +15521,7 @@ function ShopifyPage(_instance, page) {
15522
15521
  page,
15523
15522
  (page2) => page2.date_published || page2.date_created
15524
15523
  ),
15525
- template_suffix: void 0,
15526
- // TODO
15524
+ template_suffix: defer(() => page.theme_template),
15527
15525
  title: deferWith(page, (page2) => page2.title || page2.name),
15528
15526
  // Due to deprecated name field
15529
15527
  url: deferWith(page, (page2) => `/pages/${page2.slug}`)
@@ -15859,17 +15857,13 @@ var ShopifyCompatibility3 = class {
15859
15857
  this.queryParamsMap = this.getQueryParamsMap();
15860
15858
  }
15861
15859
  initGlobals(globals) {
15862
- const { request, page } = globals;
15863
- this.pageId = this.getPageType(globals.page?.id);
15864
- globals.page = {
15865
- ...page || void 0
15866
- };
15860
+ const { request } = globals;
15867
15861
  globals.request = {
15868
15862
  ...request || void 0,
15869
15863
  design_mode: this.swell.isEditor,
15870
15864
  visual_section_preview: false,
15871
15865
  // TODO: Add support for visual section preview
15872
- page_type: page?.id
15866
+ page_type: ""
15873
15867
  };
15874
15868
  globals.collections = new CollectionsDrop(this);
15875
15869
  globals.current_page = this.swell.queryParams.page || 1;
@@ -15878,6 +15872,8 @@ var ShopifyCompatibility3 = class {
15878
15872
  adaptGlobals(globals, prevGlobals) {
15879
15873
  if (globals.page) {
15880
15874
  this.pageId = this.getPageType(globals.page.id);
15875
+ const request = globals.request || prevGlobals.request;
15876
+ request.page_type = globals.page.id;
15881
15877
  }
15882
15878
  if (globals.request) {
15883
15879
  const page = globals.page || prevGlobals.page;
@@ -18964,12 +18960,10 @@ var SwellTheme3 = class {
18964
18960
  getSwellAppThemeProps(swellConfig) {
18965
18961
  return swellConfig?.storefront?.theme || {};
18966
18962
  }
18967
- async initGlobals(pageId) {
18968
- this.pageId = pageId;
18963
+ async initGlobals() {
18969
18964
  await this.themeLoader.init(this.themeConfigs || void 0);
18970
18965
  const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
18971
- const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId);
18972
- this.page = page;
18966
+ const { settings, request, cart, account, customer } = await this.resolvePageData(store, configs);
18973
18967
  const globals = {
18974
18968
  ...this.globalData,
18975
18969
  store,
@@ -18977,7 +18971,7 @@ var SwellTheme3 = class {
18977
18971
  session,
18978
18972
  request,
18979
18973
  menus,
18980
- page,
18974
+ page: {},
18981
18975
  cart,
18982
18976
  account,
18983
18977
  customer,
@@ -19008,6 +19002,45 @@ var SwellTheme3 = class {
19008
19002
  ...this.globals
19009
19003
  };
19010
19004
  }
19005
+ async initPageGlobals(pageId, altTemplate) {
19006
+ this.pageId = pageId;
19007
+ const swellPage = this.props.pages?.find(
19008
+ (page2) => page2.id === pageId
19009
+ );
19010
+ const page = {
19011
+ ...swellPage,
19012
+ current: Number(this.swell.queryParams.page) || 1,
19013
+ url: this.swell.url.pathname,
19014
+ custom: !swellPage,
19015
+ slug: void 0,
19016
+ description: void 0,
19017
+ $locale: void 0
19018
+ };
19019
+ if (pageId) {
19020
+ const templateConfig = await this.getThemeTemplateConfigByType(
19021
+ "templates",
19022
+ pageId,
19023
+ altTemplate
19024
+ );
19025
+ let pageSchema;
19026
+ try {
19027
+ pageSchema = JSON56.parse(
19028
+ templateConfig?.file_data || "{}"
19029
+ );
19030
+ } catch (err) {
19031
+ console.warn(err);
19032
+ }
19033
+ if (pageSchema?.page) {
19034
+ const { slug, label, description, $locale } = pageSchema.page;
19035
+ page.slug = slug;
19036
+ page.label = label || page.label;
19037
+ page.description = description;
19038
+ page.$locale = $locale;
19039
+ }
19040
+ }
19041
+ this.page = page;
19042
+ this.setGlobals({ page });
19043
+ }
19011
19044
  async getSettingsAndConfigs() {
19012
19045
  const geo = GEO_DATA;
19013
19046
  const [storefrontSettings, settingConfigs] = await Promise.all([
@@ -19057,7 +19090,7 @@ var SwellTheme3 = class {
19057
19090
  configs
19058
19091
  };
19059
19092
  }
19060
- async resolvePageData(store, configs, pageId) {
19093
+ async resolvePageData(store, configs) {
19061
19094
  const configVersion = String(
19062
19095
  this.swell.swellHeaders["theme-config-version"]
19063
19096
  );
@@ -19089,39 +19122,6 @@ var SwellTheme3 = class {
19089
19122
  is_editor: this.swell.isEditor,
19090
19123
  is_preview: this.swell.isPreview
19091
19124
  };
19092
- const swellPage = this.props.pages?.find(
19093
- (page2) => page2.id === pageId
19094
- );
19095
- const page = {
19096
- ...swellPage,
19097
- current: Number(this.swell.queryParams.page) || 1,
19098
- url: this.swell.url.pathname,
19099
- custom: !swellPage,
19100
- slug: void 0,
19101
- description: void 0,
19102
- $locale: void 0
19103
- };
19104
- if (pageId) {
19105
- const templateConfig = await this.getThemeTemplateConfigByType(
19106
- "templates",
19107
- pageId
19108
- );
19109
- let pageSchema;
19110
- try {
19111
- pageSchema = JSON56.parse(
19112
- templateConfig?.file_data || "{}"
19113
- );
19114
- } catch (err) {
19115
- console.warn(err);
19116
- }
19117
- if (pageSchema?.page) {
19118
- const { slug, label, description, $locale } = pageSchema.page;
19119
- page.slug = slug;
19120
- page.label = label || page.label;
19121
- page.description = description;
19122
- page.$locale = $locale;
19123
- }
19124
- }
19125
19125
  const [cart, account] = await Promise.all([
19126
19126
  this.fetchSingletonResourceCached(
19127
19127
  "cart",
@@ -19144,7 +19144,6 @@ var SwellTheme3 = class {
19144
19144
  return {
19145
19145
  settings,
19146
19146
  request,
19147
- page,
19148
19147
  cart,
19149
19148
  account,
19150
19149
  customer
@@ -19504,15 +19503,15 @@ var SwellTheme3 = class {
19504
19503
  async preloadThemeConfigs(version, configs) {
19505
19504
  await this.themeLoader.preloadTheme(version, configs);
19506
19505
  }
19507
- getPageConfigPath(pageId) {
19506
+ getPageConfigPath(pageId, altTemplate) {
19508
19507
  if (this.shopifyCompatibility) {
19509
19508
  const configPath = this.shopifyCompatibility.getThemeFilePath(
19510
19509
  "templates",
19511
19510
  pageId
19512
19511
  );
19513
- return `theme/${configPath}.json`;
19512
+ return `${withSuffix(`theme/${configPath}`, altTemplate)}.json`;
19514
19513
  }
19515
- return `theme/templates/${pageId}.json`;
19514
+ return `${withSuffix(`theme/templates/${pageId}`, altTemplate)}.json`;
19516
19515
  }
19517
19516
  async getThemeConfig(filePath) {
19518
19517
  if (this.themeConfigs !== null) {
@@ -19541,12 +19540,11 @@ var SwellTheme3 = class {
19541
19540
  }
19542
19541
  return this.getThemeConfig(`${filePath}.liquid`);
19543
19542
  }
19544
- async getThemeTemplateConfigByType(type, name) {
19545
- const templatesByPriority = [`${type}/${name}`];
19543
+ async getThemeTemplateConfigByType(type, name, suffix) {
19544
+ const templatesByPriority = [withSuffix(`${type}/${name}`, suffix)];
19546
19545
  if (this.shopifyCompatibility) {
19547
- templatesByPriority.push(
19548
- this.shopifyCompatibility.getThemeFilePath(type, name)
19549
- );
19546
+ const path = this.shopifyCompatibility.getThemeFilePath(type, name);
19547
+ templatesByPriority.push(withSuffix(path, suffix));
19550
19548
  }
19551
19549
  for (const filePath of templatesByPriority) {
19552
19550
  const templateConfig = await this.getThemeTemplateConfig(
@@ -19715,7 +19713,8 @@ ${content.slice(pos)}`;
19715
19713
  if (altTemplateId) {
19716
19714
  templateConfig = await this.getThemeTemplateConfigByType(
19717
19715
  "templates",
19718
- `${name}.${altTemplateId}`
19716
+ name,
19717
+ altTemplateId
19719
19718
  );
19720
19719
  }
19721
19720
  if (!templateConfig) {
@@ -20012,10 +20011,11 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
20012
20011
  /**
20013
20012
  * Get a list of sections and section groups in a page layout.
20014
20013
  */
20015
- async getPageSectionGroups(pageId) {
20014
+ async getPageSectionGroups(pageId, altTemplate) {
20016
20015
  const pageConfig = await this.getThemeTemplateConfigByType(
20017
20016
  "templates",
20018
- pageId
20017
+ pageId,
20018
+ altTemplate
20019
20019
  );
20020
20020
  if (pageConfig === null) {
20021
20021
  return [];
@@ -20332,6 +20332,9 @@ function extractSchemaTag(template) {
20332
20332
  }
20333
20333
  return list[0];
20334
20334
  }
20335
+ function withSuffix(path, suffix) {
20336
+ return suffix ? `${path}.${suffix}` : path;
20337
+ }
20335
20338
 
20336
20339
  // src/menus.ts
20337
20340
  async function resolveMenuSettings(theme, menus, options) {