@gem-sdk/pages 1.48.0-dev.72 → 1.48.0-dev.93

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.
@@ -8,57 +8,61 @@ var core = require('@gem-sdk/core');
8
8
  const InteractionSelectOnPageHeader = ()=>{
9
9
  const selectType = core.usePageStore((s)=>s.interactionData?.selectType);
10
10
  const setInteractionSelectType = core.usePageStore((s)=>s.setInteractionSelectType);
11
- const setInteractionIsSelectOnPage = core.usePageStore((s)=>s.setInteractionIsSelectOnPage);
12
- const closeSelectOnPage = ()=>{
13
- setInteractionIsSelectOnPage(false);
14
- const event = new CustomEvent('editor:interaction:change-select-on-page', {
15
- bubbles: true,
16
- detail: false
17
- });
18
- window.dispatchEvent(event);
19
- };
11
+ const { closeSelectOnPage } = core.useInteraction();
20
12
  return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
21
13
  children: [
22
14
  /*#__PURE__*/ jsxRuntime.jsxs("header", {
23
- className: "gp-flex gp-justify-between gp-h-10 gp-fixed gp-top-0 gp-left-0 gp-w-full gp-z-100",
15
+ className: "gp-flex gp-justify-between gp-items-center gp-h-10 gp-fixed gp-top-0 gp-left-0 gp-w-full gp-z-100 gp-bg-black gp-text-white",
24
16
  children: [
25
17
  /*#__PURE__*/ jsxRuntime.jsx("div", {
26
- className: "gp-h-10 gp-w-10"
18
+ className: "gp-ml-4 gp-text-xs gp-mt-1",
19
+ children: "Select mode enabled"
27
20
  }),
28
21
  /*#__PURE__*/ jsxRuntime.jsxs("section", {
29
- className: "gp-flex gp-bg-[#3C67FF]/[0.15] gp-items-center gp-h-full gp-rounded-b-lg gp-p-1 gp-gap-1",
22
+ className: "gp-flex gp-bg-[#3C67FF]/[0.15] gp-items-center gp-h-full gp-rounded-b-lg gp-pt-1 gp-gap-1",
30
23
  children: [
31
24
  /*#__PURE__*/ jsxRuntime.jsx("button", {
25
+ "data-interaction-mode": "element",
32
26
  onClick: ()=>setInteractionSelectType('element'),
33
- className: `gp-h-8 gp-w-[132px] gp-items-center gp-justify-center gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-[6px] ${selectType === 'element' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#3C67FF]'}`,
34
- children: "Select an element"
27
+ className: `gp-h-full gp-w-[444px] gp-items-center gp-justify-center gp-bg-[#333333] gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-t-[8px] ${selectType === 'element' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#AAAAAA]'}`,
28
+ style: {
29
+ cursor: "url('https://cdn.shopify.com/s/files/1/0858/3168/0279/files/gempages_502328832959710176-45eb24ff-a9ee-48ac-af8b-eac35e11918d.png?v=1724038301'), auto"
30
+ },
31
+ children: "Choose an element on page"
35
32
  }),
36
33
  /*#__PURE__*/ jsxRuntime.jsx("button", {
34
+ "data-interaction-mode": "page",
37
35
  onClick: ()=>setInteractionSelectType('page'),
38
- className: `gp-h-8 gp-w-[132px] gp-items-center gp-justify-center gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-[6px] ${selectType === 'page' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#3C67FF]'}`,
39
- children: "Choose entire page"
36
+ className: `gp-h-full gp-w-[444px] gp-items-center gp-justify-center gp-bg-[#333333] gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-t-[8px] ${selectType === 'page' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#AAAAAA]'}`,
37
+ style: {
38
+ cursor: "url('https://cdn.shopify.com/s/files/1/0858/3168/0279/files/gempages_502328832959710176-45eb24ff-a9ee-48ac-af8b-eac35e11918d.png?v=1724038301'), auto"
39
+ },
40
+ children: "Use entire page"
40
41
  })
41
42
  ]
42
43
  }),
43
44
  /*#__PURE__*/ jsxRuntime.jsx("button", {
44
45
  onClick: closeSelectOnPage,
45
- className: "gp-h-10 gp-w-10 gp-bg-[#3C67FF]/[0.15] gp-flex gp-items-center gp-justify-center gp-rounded-bl-lg",
46
+ className: "gp-h-10 gp-w-10 gp-flex gp-items-center gp-justify-center gp-rounded-bl-lg",
46
47
  children: /*#__PURE__*/ jsxRuntime.jsx("svg", {
47
- width: "20",
48
- height: "20",
49
- viewBox: "0 0 20 20",
48
+ width: "12",
49
+ height: "12",
50
+ viewBox: "0 0 12 12",
50
51
  fill: "none",
51
52
  xmlns: "http://www.w3.org/2000/svg",
52
53
  children: /*#__PURE__*/ jsxRuntime.jsx("path", {
53
- d: "M3.94194 3.05806C3.69786 2.81398 3.30214 2.81398 3.05806 3.05806C2.81398 3.30214 2.81398 3.69786 3.05806 3.94194L9.11612 10L3.05806 16.0581C2.81398 16.3021 2.81398 16.6979 3.05806 16.9419C3.30214 17.186 3.69786 17.186 3.94194 16.9419L10 10.8839L16.0581 16.9419C16.3021 17.186 16.6979 17.186 16.9419 16.9419C17.186 16.6979 17.186 16.3021 16.9419 16.0581L10.8839 10L16.9419 3.94194C17.186 3.69786 17.186 3.30214 16.9419 3.05806C16.6979 2.81398 16.3021 2.81398 16.0581 3.05806L10 9.11612L3.94194 3.05806Z",
54
- fill: "#3C67FF"
54
+ d: "M9.96967 11.0303C10.2626 11.3232 10.7374 11.3232 11.0303 11.0303C11.3232 10.7374 11.3232 10.2626 11.0303 9.96967L7.06066 6L11.0303 2.03033C11.3232 1.73744 11.3232 1.26256 11.0303 0.96967C10.7374 0.676777 10.2626 0.676777 9.96967 0.96967L6 4.93934L2.03033 0.96967C1.73744 0.676777 1.26256 0.676777 0.96967 0.96967C0.676777 1.26256 0.676777 1.73744 0.96967 2.03033L4.93934 6L0.96967 9.96967C0.676777 10.2626 0.676777 10.7374 0.96967 11.0303C1.26256 11.3232 1.73744 11.3232 2.03033 11.0303L6 7.06066L9.96967 11.0303Z",
55
+ fill: "#F9F9F9"
55
56
  })
56
57
  })
57
58
  })
58
59
  ]
59
60
  }),
60
61
  /*#__PURE__*/ jsxRuntime.jsx("div", {
61
- className: "gp-h-full gp-w-full gp-fixed gp-top-0 gp-left-0 gp-border-[#3C67FF] gp-border-[2px]"
62
+ className: `gp-w-full gp-fixed gp-top-0 gp-left-0 gp-border-[#3C67FF] gp-border-[4px] gp-mt-[40px] ${selectType === 'page' ? 'gp-z-90 gp-bg-[#3c67ff]/[0.25]' : ''}`,
63
+ style: {
64
+ height: 'calc(100% - 40px)'
65
+ }
62
66
  })
63
67
  ]
64
68
  });
@@ -38,6 +38,7 @@ const Toolbox = ()=>{
38
38
  const clearModal = core.useModalStore((s)=>s.clearModal);
39
39
  const setInteractionIsSelectOnPage = core.usePageStore((s)=>s.setInteractionIsSelectOnPage);
40
40
  const setInteractionItem = core.usePageStore((s)=>s.setInteractionItem);
41
+ const setInteractionSelectType = core.usePageStore((s)=>s.setInteractionSelectType);
41
42
  const fonts = react.useMemo(()=>genFonts.getFontsFromDataBuilder(state), [
42
43
  state
43
44
  ]);
@@ -332,10 +333,13 @@ const Toolbox = ()=>{
332
333
  setSalePageProductId
333
334
  ]);
334
335
  const onUpdateInteractionIsSelectOnPage = react.useCallback((e)=>{
335
- const isSelectOnPage = e.detail;
336
+ const isSelectOnPage = e.detail.value;
337
+ const mode = e.detail.mode;
336
338
  setInteractionIsSelectOnPage(isSelectOnPage);
339
+ setInteractionSelectType(mode);
337
340
  }, [
338
- setInteractionIsSelectOnPage
341
+ setInteractionIsSelectOnPage,
342
+ setInteractionSelectType
339
343
  ]);
340
344
  const onUpdateInteractionItem = react.useCallback((e)=>{
341
345
  const interactionItem = e.detail;
@@ -119,22 +119,78 @@ const fetchThemePageDataByTemplateID = async (data, fetcher)=>{
119
119
  productOffers: productOffers
120
120
  };
121
121
  };
122
- const getPostPurchasePropsPreview = (fetcher, librarySaleFunnelID, storeFrontFetcher)=>async (id, currentOfferID)=>{
122
+ const fetchLibraryTemplateDataByID = async (data, fetcher)=>{
123
+ const variables = {
124
+ libraryTemplateId: data.libraryTemplateId
125
+ };
126
+ const [theme, storeProperty, saleFunnelDiscounts] = await Promise.allSettled([
127
+ fetcher([
128
+ core.LibraryTemplateDocument,
129
+ variables
130
+ ]),
131
+ fetcher([
132
+ core.StorePropertyDocument
133
+ ]),
134
+ fetcher([
135
+ core.SaleFunnelDiscountsDocument,
136
+ {
137
+ where: {
138
+ saleFunnelOfferID: data.currentOfferID
139
+ }
140
+ }
141
+ ])
142
+ ]);
143
+ if (theme.status === 'rejected') {
144
+ throw new Error(theme.reason?.[0]);
145
+ }
146
+ if (saleFunnelDiscounts.status === 'rejected') {
147
+ throw new Error(saleFunnelDiscounts.reason?.[0]);
148
+ }
149
+ return {
150
+ dataBuilder: theme.value.libraryTemplate,
151
+ pageStyle: undefined,
152
+ storeProperty,
153
+ productOffers: saleFunnelDiscounts.value.saleFunnelDiscounts?.edges?.filter((item)=>item?.node?.objectType === 'PRODUCT' && item?.node?.type === 'ORDER_VALUE') || []
154
+ };
155
+ };
156
+ const getRelevantPageData = async (data)=>{
157
+ const { id, currentOfferID, fetcher, isLibraryTemplate, librarySaleFunnelID } = data;
158
+ if (librarySaleFunnelID) {
159
+ return await fetchThemePageDataByTemplateID({
160
+ libraryTemplateId: id,
161
+ currentOfferID,
162
+ librarySaleFunnelID
163
+ }, fetcher);
164
+ }
165
+ if (isLibraryTemplate && currentOfferID) {
166
+ return await fetchLibraryTemplateDataByID({
167
+ libraryTemplateId: id,
168
+ currentOfferID
169
+ }, fetcher);
170
+ }
171
+ if (currentOfferID) {
172
+ return await fetchPostPurchasePageDataByID({
173
+ themePageId: id,
174
+ currentOfferID
175
+ }, fetcher);
176
+ }
177
+ return await fetchSalePageDataByID({
178
+ themePageId: id
179
+ }, fetcher);
180
+ };
181
+ const getPostPurchasePropsPreview = (fetcher, librarySaleFunnelID, storeFrontFetcher)=>async (id, currentOfferID, isLibraryTemplate)=>{
123
182
  try {
124
- const { dataBuilder, storeProperty, productOffers, pageStyle } = librarySaleFunnelID ? await fetchThemePageDataByTemplateID({
125
- libraryTemplateId: id,
183
+ const { dataBuilder, storeProperty, productOffers, pageStyle } = await getRelevantPageData({
184
+ id,
126
185
  currentOfferID,
186
+ fetcher,
187
+ isLibraryTemplate,
127
188
  librarySaleFunnelID
128
- }, fetcher) : currentOfferID ? await fetchPostPurchasePageDataByID({
129
- themePageId: id,
130
- currentOfferID
131
- }, fetcher) : await fetchSalePageDataByID({
132
- themePageId: id
133
- }, fetcher);
189
+ });
134
190
  if (!dataBuilder) {
135
191
  throw new Error(`No data builder found for slug: /preview/${id}`);
136
192
  }
137
- const pageTemplate = librarySaleFunnelID ? normalize.parseBuilderLibraryTemplate(dataBuilder) : normalize.parseBuilderTemplateV2(dataBuilder);
193
+ const pageTemplate = librarySaleFunnelID || isLibraryTemplate && currentOfferID ? normalize.parseBuilderLibraryTemplate(dataBuilder) : normalize.parseBuilderTemplateV2(dataBuilder);
138
194
  const gemPagesStoreFrontFetcher = storeFrontFetcher || fetcher;
139
195
  const [elementFontStyle, fontStyle, fallback] = await Promise.all([
140
196
  googleFonts.getFontStyleFromPageTemplate(pageTemplate),
@@ -160,7 +216,9 @@ const getPostPurchasePropsPreview = (fetcher, librarySaleFunnelID, storeFrontFet
160
216
  }
161
217
  };
162
218
 
219
+ exports.fetchLibraryTemplateDataByID = fetchLibraryTemplateDataByID;
163
220
  exports.fetchPostPurchasePageDataByID = fetchPostPurchasePageDataByID;
164
221
  exports.fetchSalePageDataByID = fetchSalePageDataByID;
165
222
  exports.fetchThemePageDataByTemplateID = fetchThemePageDataByTemplateID;
166
223
  exports.getPostPurchasePropsPreview = getPostPurchasePropsPreview;
224
+ exports.getRelevantPageData = getRelevantPageData;
@@ -1,60 +1,64 @@
1
1
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
- import { usePageStore } from '@gem-sdk/core';
2
+ import { usePageStore, useInteraction } from '@gem-sdk/core';
3
3
 
4
4
  const InteractionSelectOnPageHeader = ()=>{
5
5
  const selectType = usePageStore((s)=>s.interactionData?.selectType);
6
6
  const setInteractionSelectType = usePageStore((s)=>s.setInteractionSelectType);
7
- const setInteractionIsSelectOnPage = usePageStore((s)=>s.setInteractionIsSelectOnPage);
8
- const closeSelectOnPage = ()=>{
9
- setInteractionIsSelectOnPage(false);
10
- const event = new CustomEvent('editor:interaction:change-select-on-page', {
11
- bubbles: true,
12
- detail: false
13
- });
14
- window.dispatchEvent(event);
15
- };
7
+ const { closeSelectOnPage } = useInteraction();
16
8
  return /*#__PURE__*/ jsxs(Fragment, {
17
9
  children: [
18
10
  /*#__PURE__*/ jsxs("header", {
19
- className: "gp-flex gp-justify-between gp-h-10 gp-fixed gp-top-0 gp-left-0 gp-w-full gp-z-100",
11
+ className: "gp-flex gp-justify-between gp-items-center gp-h-10 gp-fixed gp-top-0 gp-left-0 gp-w-full gp-z-100 gp-bg-black gp-text-white",
20
12
  children: [
21
13
  /*#__PURE__*/ jsx("div", {
22
- className: "gp-h-10 gp-w-10"
14
+ className: "gp-ml-4 gp-text-xs gp-mt-1",
15
+ children: "Select mode enabled"
23
16
  }),
24
17
  /*#__PURE__*/ jsxs("section", {
25
- className: "gp-flex gp-bg-[#3C67FF]/[0.15] gp-items-center gp-h-full gp-rounded-b-lg gp-p-1 gp-gap-1",
18
+ className: "gp-flex gp-bg-[#3C67FF]/[0.15] gp-items-center gp-h-full gp-rounded-b-lg gp-pt-1 gp-gap-1",
26
19
  children: [
27
20
  /*#__PURE__*/ jsx("button", {
21
+ "data-interaction-mode": "element",
28
22
  onClick: ()=>setInteractionSelectType('element'),
29
- className: `gp-h-8 gp-w-[132px] gp-items-center gp-justify-center gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-[6px] ${selectType === 'element' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#3C67FF]'}`,
30
- children: "Select an element"
23
+ className: `gp-h-full gp-w-[444px] gp-items-center gp-justify-center gp-bg-[#333333] gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-t-[8px] ${selectType === 'element' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#AAAAAA]'}`,
24
+ style: {
25
+ cursor: "url('https://cdn.shopify.com/s/files/1/0858/3168/0279/files/gempages_502328832959710176-45eb24ff-a9ee-48ac-af8b-eac35e11918d.png?v=1724038301'), auto"
26
+ },
27
+ children: "Choose an element on page"
31
28
  }),
32
29
  /*#__PURE__*/ jsx("button", {
30
+ "data-interaction-mode": "page",
33
31
  onClick: ()=>setInteractionSelectType('page'),
34
- className: `gp-h-8 gp-w-[132px] gp-items-center gp-justify-center gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-[6px] ${selectType === 'page' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#3C67FF]'}`,
35
- children: "Choose entire page"
32
+ className: `gp-h-full gp-w-[444px] gp-items-center gp-justify-center gp-bg-[#333333] gp-text-[12px] gp-leading-5 gp-font-medium gp-flex gp-rounded-t-[8px] ${selectType === 'page' ? 'gp-bg-[#3C67FF] gp-text-[#F9F9F9]' : 'gp-text-[#AAAAAA]'}`,
33
+ style: {
34
+ cursor: "url('https://cdn.shopify.com/s/files/1/0858/3168/0279/files/gempages_502328832959710176-45eb24ff-a9ee-48ac-af8b-eac35e11918d.png?v=1724038301'), auto"
35
+ },
36
+ children: "Use entire page"
36
37
  })
37
38
  ]
38
39
  }),
39
40
  /*#__PURE__*/ jsx("button", {
40
41
  onClick: closeSelectOnPage,
41
- className: "gp-h-10 gp-w-10 gp-bg-[#3C67FF]/[0.15] gp-flex gp-items-center gp-justify-center gp-rounded-bl-lg",
42
+ className: "gp-h-10 gp-w-10 gp-flex gp-items-center gp-justify-center gp-rounded-bl-lg",
42
43
  children: /*#__PURE__*/ jsx("svg", {
43
- width: "20",
44
- height: "20",
45
- viewBox: "0 0 20 20",
44
+ width: "12",
45
+ height: "12",
46
+ viewBox: "0 0 12 12",
46
47
  fill: "none",
47
48
  xmlns: "http://www.w3.org/2000/svg",
48
49
  children: /*#__PURE__*/ jsx("path", {
49
- d: "M3.94194 3.05806C3.69786 2.81398 3.30214 2.81398 3.05806 3.05806C2.81398 3.30214 2.81398 3.69786 3.05806 3.94194L9.11612 10L3.05806 16.0581C2.81398 16.3021 2.81398 16.6979 3.05806 16.9419C3.30214 17.186 3.69786 17.186 3.94194 16.9419L10 10.8839L16.0581 16.9419C16.3021 17.186 16.6979 17.186 16.9419 16.9419C17.186 16.6979 17.186 16.3021 16.9419 16.0581L10.8839 10L16.9419 3.94194C17.186 3.69786 17.186 3.30214 16.9419 3.05806C16.6979 2.81398 16.3021 2.81398 16.0581 3.05806L10 9.11612L3.94194 3.05806Z",
50
- fill: "#3C67FF"
50
+ d: "M9.96967 11.0303C10.2626 11.3232 10.7374 11.3232 11.0303 11.0303C11.3232 10.7374 11.3232 10.2626 11.0303 9.96967L7.06066 6L11.0303 2.03033C11.3232 1.73744 11.3232 1.26256 11.0303 0.96967C10.7374 0.676777 10.2626 0.676777 9.96967 0.96967L6 4.93934L2.03033 0.96967C1.73744 0.676777 1.26256 0.676777 0.96967 0.96967C0.676777 1.26256 0.676777 1.73744 0.96967 2.03033L4.93934 6L0.96967 9.96967C0.676777 10.2626 0.676777 10.7374 0.96967 11.0303C1.26256 11.3232 1.73744 11.3232 2.03033 11.0303L6 7.06066L9.96967 11.0303Z",
51
+ fill: "#F9F9F9"
51
52
  })
52
53
  })
53
54
  })
54
55
  ]
55
56
  }),
56
57
  /*#__PURE__*/ jsx("div", {
57
- className: "gp-h-full gp-w-full gp-fixed gp-top-0 gp-left-0 gp-border-[#3C67FF] gp-border-[2px]"
58
+ className: `gp-w-full gp-fixed gp-top-0 gp-left-0 gp-border-[#3C67FF] gp-border-[4px] gp-mt-[40px] ${selectType === 'page' ? 'gp-z-90 gp-bg-[#3c67ff]/[0.25]' : ''}`,
59
+ style: {
60
+ height: 'calc(100% - 40px)'
61
+ }
58
62
  })
59
63
  ]
60
64
  });
@@ -34,6 +34,7 @@ const Toolbox = ()=>{
34
34
  const clearModal = useModalStore((s)=>s.clearModal);
35
35
  const setInteractionIsSelectOnPage = usePageStore((s)=>s.setInteractionIsSelectOnPage);
36
36
  const setInteractionItem = usePageStore((s)=>s.setInteractionItem);
37
+ const setInteractionSelectType = usePageStore((s)=>s.setInteractionSelectType);
37
38
  const fonts = useMemo(()=>getFontsFromDataBuilder(state), [
38
39
  state
39
40
  ]);
@@ -328,10 +329,13 @@ const Toolbox = ()=>{
328
329
  setSalePageProductId
329
330
  ]);
330
331
  const onUpdateInteractionIsSelectOnPage = useCallback((e)=>{
331
- const isSelectOnPage = e.detail;
332
+ const isSelectOnPage = e.detail.value;
333
+ const mode = e.detail.mode;
332
334
  setInteractionIsSelectOnPage(isSelectOnPage);
335
+ setInteractionSelectType(mode);
333
336
  }, [
334
- setInteractionIsSelectOnPage
337
+ setInteractionIsSelectOnPage,
338
+ setInteractionSelectType
335
339
  ]);
336
340
  const onUpdateInteractionItem = useCallback((e)=>{
337
341
  const interactionItem = e.detail;
@@ -117,22 +117,78 @@ const fetchThemePageDataByTemplateID = async (data, fetcher)=>{
117
117
  productOffers: productOffers
118
118
  };
119
119
  };
120
- const getPostPurchasePropsPreview = (fetcher, librarySaleFunnelID, storeFrontFetcher)=>async (id, currentOfferID)=>{
120
+ const fetchLibraryTemplateDataByID = async (data, fetcher)=>{
121
+ const variables = {
122
+ libraryTemplateId: data.libraryTemplateId
123
+ };
124
+ const [theme, storeProperty, saleFunnelDiscounts] = await Promise.allSettled([
125
+ fetcher([
126
+ LibraryTemplateDocument,
127
+ variables
128
+ ]),
129
+ fetcher([
130
+ StorePropertyDocument
131
+ ]),
132
+ fetcher([
133
+ SaleFunnelDiscountsDocument,
134
+ {
135
+ where: {
136
+ saleFunnelOfferID: data.currentOfferID
137
+ }
138
+ }
139
+ ])
140
+ ]);
141
+ if (theme.status === 'rejected') {
142
+ throw new Error(theme.reason?.[0]);
143
+ }
144
+ if (saleFunnelDiscounts.status === 'rejected') {
145
+ throw new Error(saleFunnelDiscounts.reason?.[0]);
146
+ }
147
+ return {
148
+ dataBuilder: theme.value.libraryTemplate,
149
+ pageStyle: undefined,
150
+ storeProperty,
151
+ productOffers: saleFunnelDiscounts.value.saleFunnelDiscounts?.edges?.filter((item)=>item?.node?.objectType === 'PRODUCT' && item?.node?.type === 'ORDER_VALUE') || []
152
+ };
153
+ };
154
+ const getRelevantPageData = async (data)=>{
155
+ const { id, currentOfferID, fetcher, isLibraryTemplate, librarySaleFunnelID } = data;
156
+ if (librarySaleFunnelID) {
157
+ return await fetchThemePageDataByTemplateID({
158
+ libraryTemplateId: id,
159
+ currentOfferID,
160
+ librarySaleFunnelID
161
+ }, fetcher);
162
+ }
163
+ if (isLibraryTemplate && currentOfferID) {
164
+ return await fetchLibraryTemplateDataByID({
165
+ libraryTemplateId: id,
166
+ currentOfferID
167
+ }, fetcher);
168
+ }
169
+ if (currentOfferID) {
170
+ return await fetchPostPurchasePageDataByID({
171
+ themePageId: id,
172
+ currentOfferID
173
+ }, fetcher);
174
+ }
175
+ return await fetchSalePageDataByID({
176
+ themePageId: id
177
+ }, fetcher);
178
+ };
179
+ const getPostPurchasePropsPreview = (fetcher, librarySaleFunnelID, storeFrontFetcher)=>async (id, currentOfferID, isLibraryTemplate)=>{
121
180
  try {
122
- const { dataBuilder, storeProperty, productOffers, pageStyle } = librarySaleFunnelID ? await fetchThemePageDataByTemplateID({
123
- libraryTemplateId: id,
181
+ const { dataBuilder, storeProperty, productOffers, pageStyle } = await getRelevantPageData({
182
+ id,
124
183
  currentOfferID,
184
+ fetcher,
185
+ isLibraryTemplate,
125
186
  librarySaleFunnelID
126
- }, fetcher) : currentOfferID ? await fetchPostPurchasePageDataByID({
127
- themePageId: id,
128
- currentOfferID
129
- }, fetcher) : await fetchSalePageDataByID({
130
- themePageId: id
131
- }, fetcher);
187
+ });
132
188
  if (!dataBuilder) {
133
189
  throw new Error(`No data builder found for slug: /preview/${id}`);
134
190
  }
135
- const pageTemplate = librarySaleFunnelID ? parseBuilderLibraryTemplate(dataBuilder) : parseBuilderTemplateV2(dataBuilder);
191
+ const pageTemplate = librarySaleFunnelID || isLibraryTemplate && currentOfferID ? parseBuilderLibraryTemplate(dataBuilder) : parseBuilderTemplateV2(dataBuilder);
136
192
  const gemPagesStoreFrontFetcher = storeFrontFetcher || fetcher;
137
193
  const [elementFontStyle, fontStyle, fallback] = await Promise.all([
138
194
  getFontStyleFromPageTemplate(pageTemplate),
@@ -158,4 +214,4 @@ const getPostPurchasePropsPreview = (fetcher, librarySaleFunnelID, storeFrontFet
158
214
  }
159
215
  };
160
216
 
161
- export { fetchPostPurchasePageDataByID, fetchSalePageDataByID, fetchThemePageDataByTemplateID, getPostPurchasePropsPreview };
217
+ export { fetchLibraryTemplateDataByID, fetchPostPurchasePageDataByID, fetchSalePageDataByID, fetchThemePageDataByTemplateID, getPostPurchasePropsPreview, getRelevantPageData };
@@ -94,7 +94,7 @@ type StaticPagePropsV2 = PageBuilderPropsV2 & {
94
94
  };
95
95
  declare const StaticPageV2: React.FC<StaticPagePropsV2 & AdditionalPageBuilderProps>;
96
96
 
97
- declare const getPostPurchasePropsPreview: (fetcher: FetchFunc, librarySaleFunnelID?: string, storeFrontFetcher?: FetchFunc) => (id: string, currentOfferID: string) => Promise<Omit<StaticPagePropsV2, 'publicStoreFrontData'>>;
97
+ declare const getPostPurchasePropsPreview: (fetcher: FetchFunc, librarySaleFunnelID?: string, storeFrontFetcher?: FetchFunc) => (id: string, currentOfferID: string, isLibraryTemplate?: boolean) => Promise<Omit<StaticPagePropsV2, 'publicStoreFrontData'>>;
98
98
 
99
99
  declare const getStaticPagePropsPreview: (fetcher: FetchFunc, shopifyFetcher: FetchFunc) => (slug: string) => Promise<PageBuilderPropsV2>;
100
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "1.48.0-dev.72",
3
+ "version": "1.48.0-dev.93",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -26,7 +26,7 @@
26
26
  "next": "latest"
27
27
  },
28
28
  "devDependencies": {
29
- "@gem-sdk/core": "1.48.0-dev.72",
29
+ "@gem-sdk/core": "1.48.0-dev.91",
30
30
  "@gem-sdk/plugin-cookie-bar": "1.48.0-dev.3",
31
31
  "@gem-sdk/plugin-quick-view": "1.48.0-dev.3",
32
32
  "@gem-sdk/plugin-sticky-add-to-cart": "1.48.0-dev.3"