@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.cjs CHANGED
@@ -7808,11 +7808,12 @@ async function getBlog(swell, id, query) {
7808
7808
  var import_json53 = __toESM(require("json5"), 1);
7809
7809
  var import_lodash_es4 = require("lodash-es");
7810
7810
  var NO_INLINE = true;
7811
- async function getEasyblocksPageTemplate(theme, pageId) {
7811
+ async function getEasyblocksPageTemplate(theme, pageId, altTemplate) {
7812
7812
  let templateConfig = null;
7813
7813
  templateConfig = await theme.getThemeTemplateConfigByType(
7814
7814
  "templates",
7815
- pageId
7815
+ pageId,
7816
+ altTemplate
7816
7817
  );
7817
7818
  if (templateConfig) {
7818
7819
  if (templateConfig.file_path.endsWith(".liquid")) {
@@ -13866,8 +13867,7 @@ function ShopifyArticle(instance, blog, blogCategory) {
13866
13867
  (blog2) => blog2.date_published || blog2.date_created
13867
13868
  ),
13868
13869
  tags: defer(() => blog.tags),
13869
- template_suffix: void 0,
13870
- // TODO
13870
+ template_suffix: defer(() => blog.theme_template),
13871
13871
  title: defer(() => blog.title),
13872
13872
  updated_at: deferWith(
13873
13873
  blog,
@@ -13936,8 +13936,7 @@ function ShopifyBlog(instance, blogCategory) {
13936
13936
  // TODO
13937
13937
  tags: allTags,
13938
13938
  // TODO: this should only apply to articles in the current view
13939
- template_suffix: void 0,
13940
- // TODO
13939
+ template_suffix: defer(() => blogCategory.theme_template),
13941
13940
  title: defer(() => blogCategory.title),
13942
13941
  url: deferWith(
13943
13942
  blogCategory,
@@ -14335,7 +14334,7 @@ function ShopifyProduct(instance, product, depth = 0) {
14335
14334
  selected_variant: void 0,
14336
14335
  selling_plan_groups: [],
14337
14336
  tags: defer(() => product.tags),
14338
- template_suffix: void 0,
14337
+ template_suffix: defer(() => product.theme_template),
14339
14338
  title: defer(() => product.name),
14340
14339
  type: defer(() => product.type),
14341
14340
  url: deferWith(product, (product2) => `/products/${product2.slug}`),
@@ -14847,7 +14846,7 @@ function ShopifyCollection(instance, category) {
14847
14846
  sort_by: defer(() => category.sort),
14848
14847
  sort_options: defer(() => category.sort_options),
14849
14848
  tags: [],
14850
- template_suffix: void 0,
14849
+ template_suffix: defer(() => category.theme_template),
14851
14850
  title: defer(() => category.name),
14852
14851
  url: deferWith(category, (category2) => `/collections/${category2.slug}`)
14853
14852
  });
@@ -15648,8 +15647,7 @@ function ShopifyPage(_instance, page) {
15648
15647
  page,
15649
15648
  (page2) => page2.date_published || page2.date_created
15650
15649
  ),
15651
- template_suffix: void 0,
15652
- // TODO
15650
+ template_suffix: defer(() => page.theme_template),
15653
15651
  title: deferWith(page, (page2) => page2.title || page2.name),
15654
15652
  // Due to deprecated name field
15655
15653
  url: deferWith(page, (page2) => `/pages/${page2.slug}`)
@@ -15985,17 +15983,13 @@ var ShopifyCompatibility3 = class {
15985
15983
  this.queryParamsMap = this.getQueryParamsMap();
15986
15984
  }
15987
15985
  initGlobals(globals) {
15988
- const { request, page } = globals;
15989
- this.pageId = this.getPageType(globals.page?.id);
15990
- globals.page = {
15991
- ...page || void 0
15992
- };
15986
+ const { request } = globals;
15993
15987
  globals.request = {
15994
15988
  ...request || void 0,
15995
15989
  design_mode: this.swell.isEditor,
15996
15990
  visual_section_preview: false,
15997
15991
  // TODO: Add support for visual section preview
15998
- page_type: page?.id
15992
+ page_type: ""
15999
15993
  };
16000
15994
  globals.collections = new CollectionsDrop(this);
16001
15995
  globals.current_page = this.swell.queryParams.page || 1;
@@ -16004,6 +15998,8 @@ var ShopifyCompatibility3 = class {
16004
15998
  adaptGlobals(globals, prevGlobals) {
16005
15999
  if (globals.page) {
16006
16000
  this.pageId = this.getPageType(globals.page.id);
16001
+ const request = globals.request || prevGlobals.request;
16002
+ request.page_type = globals.page.id;
16007
16003
  }
16008
16004
  if (globals.request) {
16009
16005
  const page = globals.page || prevGlobals.page;
@@ -19082,12 +19078,10 @@ var SwellTheme3 = class {
19082
19078
  getSwellAppThemeProps(swellConfig) {
19083
19079
  return swellConfig?.storefront?.theme || {};
19084
19080
  }
19085
- async initGlobals(pageId) {
19086
- this.pageId = pageId;
19081
+ async initGlobals() {
19087
19082
  await this.themeLoader.init(this.themeConfigs || void 0);
19088
19083
  const { store, session, menus, geo, configs } = await this.getSettingsAndConfigs();
19089
- const { settings, request, page, cart, account, customer } = await this.resolvePageData(store, configs, pageId);
19090
- this.page = page;
19084
+ const { settings, request, cart, account, customer } = await this.resolvePageData(store, configs);
19091
19085
  const globals = {
19092
19086
  ...this.globalData,
19093
19087
  store,
@@ -19095,7 +19089,7 @@ var SwellTheme3 = class {
19095
19089
  session,
19096
19090
  request,
19097
19091
  menus,
19098
- page,
19092
+ page: {},
19099
19093
  cart,
19100
19094
  account,
19101
19095
  customer,
@@ -19126,6 +19120,45 @@ var SwellTheme3 = class {
19126
19120
  ...this.globals
19127
19121
  };
19128
19122
  }
19123
+ async initPageGlobals(pageId, altTemplate) {
19124
+ this.pageId = pageId;
19125
+ const swellPage = this.props.pages?.find(
19126
+ (page2) => page2.id === pageId
19127
+ );
19128
+ const page = {
19129
+ ...swellPage,
19130
+ current: Number(this.swell.queryParams.page) || 1,
19131
+ url: this.swell.url.pathname,
19132
+ custom: !swellPage,
19133
+ slug: void 0,
19134
+ description: void 0,
19135
+ $locale: void 0
19136
+ };
19137
+ if (pageId) {
19138
+ const templateConfig = await this.getThemeTemplateConfigByType(
19139
+ "templates",
19140
+ pageId,
19141
+ altTemplate
19142
+ );
19143
+ let pageSchema;
19144
+ try {
19145
+ pageSchema = import_json56.default.parse(
19146
+ templateConfig?.file_data || "{}"
19147
+ );
19148
+ } catch (err) {
19149
+ console.warn(err);
19150
+ }
19151
+ if (pageSchema?.page) {
19152
+ const { slug, label, description, $locale } = pageSchema.page;
19153
+ page.slug = slug;
19154
+ page.label = label || page.label;
19155
+ page.description = description;
19156
+ page.$locale = $locale;
19157
+ }
19158
+ }
19159
+ this.page = page;
19160
+ this.setGlobals({ page });
19161
+ }
19129
19162
  async getSettingsAndConfigs() {
19130
19163
  const geo = GEO_DATA;
19131
19164
  const [storefrontSettings, settingConfigs] = await Promise.all([
@@ -19175,7 +19208,7 @@ var SwellTheme3 = class {
19175
19208
  configs
19176
19209
  };
19177
19210
  }
19178
- async resolvePageData(store, configs, pageId) {
19211
+ async resolvePageData(store, configs) {
19179
19212
  const configVersion = String(
19180
19213
  this.swell.swellHeaders["theme-config-version"]
19181
19214
  );
@@ -19207,39 +19240,6 @@ var SwellTheme3 = class {
19207
19240
  is_editor: this.swell.isEditor,
19208
19241
  is_preview: this.swell.isPreview
19209
19242
  };
19210
- const swellPage = this.props.pages?.find(
19211
- (page2) => page2.id === pageId
19212
- );
19213
- const page = {
19214
- ...swellPage,
19215
- current: Number(this.swell.queryParams.page) || 1,
19216
- url: this.swell.url.pathname,
19217
- custom: !swellPage,
19218
- slug: void 0,
19219
- description: void 0,
19220
- $locale: void 0
19221
- };
19222
- if (pageId) {
19223
- const templateConfig = await this.getThemeTemplateConfigByType(
19224
- "templates",
19225
- pageId
19226
- );
19227
- let pageSchema;
19228
- try {
19229
- pageSchema = import_json56.default.parse(
19230
- templateConfig?.file_data || "{}"
19231
- );
19232
- } catch (err) {
19233
- console.warn(err);
19234
- }
19235
- if (pageSchema?.page) {
19236
- const { slug, label, description, $locale } = pageSchema.page;
19237
- page.slug = slug;
19238
- page.label = label || page.label;
19239
- page.description = description;
19240
- page.$locale = $locale;
19241
- }
19242
- }
19243
19243
  const [cart, account] = await Promise.all([
19244
19244
  this.fetchSingletonResourceCached(
19245
19245
  "cart",
@@ -19262,7 +19262,6 @@ var SwellTheme3 = class {
19262
19262
  return {
19263
19263
  settings,
19264
19264
  request,
19265
- page,
19266
19265
  cart,
19267
19266
  account,
19268
19267
  customer
@@ -19622,15 +19621,15 @@ var SwellTheme3 = class {
19622
19621
  async preloadThemeConfigs(version, configs) {
19623
19622
  await this.themeLoader.preloadTheme(version, configs);
19624
19623
  }
19625
- getPageConfigPath(pageId) {
19624
+ getPageConfigPath(pageId, altTemplate) {
19626
19625
  if (this.shopifyCompatibility) {
19627
19626
  const configPath = this.shopifyCompatibility.getThemeFilePath(
19628
19627
  "templates",
19629
19628
  pageId
19630
19629
  );
19631
- return `theme/${configPath}.json`;
19630
+ return `${withSuffix(`theme/${configPath}`, altTemplate)}.json`;
19632
19631
  }
19633
- return `theme/templates/${pageId}.json`;
19632
+ return `${withSuffix(`theme/templates/${pageId}`, altTemplate)}.json`;
19634
19633
  }
19635
19634
  async getThemeConfig(filePath) {
19636
19635
  if (this.themeConfigs !== null) {
@@ -19659,12 +19658,11 @@ var SwellTheme3 = class {
19659
19658
  }
19660
19659
  return this.getThemeConfig(`${filePath}.liquid`);
19661
19660
  }
19662
- async getThemeTemplateConfigByType(type, name) {
19663
- const templatesByPriority = [`${type}/${name}`];
19661
+ async getThemeTemplateConfigByType(type, name, suffix) {
19662
+ const templatesByPriority = [withSuffix(`${type}/${name}`, suffix)];
19664
19663
  if (this.shopifyCompatibility) {
19665
- templatesByPriority.push(
19666
- this.shopifyCompatibility.getThemeFilePath(type, name)
19667
- );
19664
+ const path = this.shopifyCompatibility.getThemeFilePath(type, name);
19665
+ templatesByPriority.push(withSuffix(path, suffix));
19668
19666
  }
19669
19667
  for (const filePath of templatesByPriority) {
19670
19668
  const templateConfig = await this.getThemeTemplateConfig(
@@ -19833,7 +19831,8 @@ ${content.slice(pos)}`;
19833
19831
  if (altTemplateId) {
19834
19832
  templateConfig = await this.getThemeTemplateConfigByType(
19835
19833
  "templates",
19836
- `${name}.${altTemplateId}`
19834
+ name,
19835
+ altTemplateId
19837
19836
  );
19838
19837
  }
19839
19838
  if (!templateConfig) {
@@ -20130,10 +20129,11 @@ ${this.shopifyCompatibility.getContentForHeader()}`;
20130
20129
  /**
20131
20130
  * Get a list of sections and section groups in a page layout.
20132
20131
  */
20133
- async getPageSectionGroups(pageId) {
20132
+ async getPageSectionGroups(pageId, altTemplate) {
20134
20133
  const pageConfig = await this.getThemeTemplateConfigByType(
20135
20134
  "templates",
20136
- pageId
20135
+ pageId,
20136
+ altTemplate
20137
20137
  );
20138
20138
  if (pageConfig === null) {
20139
20139
  return [];
@@ -20450,6 +20450,9 @@ function extractSchemaTag(template) {
20450
20450
  }
20451
20451
  return list[0];
20452
20452
  }
20453
+ function withSuffix(path, suffix) {
20454
+ return suffix ? `${path}.${suffix}` : path;
20455
+ }
20453
20456
 
20454
20457
  // src/menus.ts
20455
20458
  async function resolveMenuSettings(theme, menus, options) {