@gem-sdk/pages 1.35.0 → 1.36.6

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.
@@ -29,6 +29,7 @@ const Toolbox = ()=>{
29
29
  const addSection = core.useSectionStore((s)=>s.addSection);
30
30
  const changeSwatches = core.useShopStore((s)=>s.changeSwatches);
31
31
  const updateItemName = core.useBuilderPreviewStore((s)=>s.updateItemName);
32
+ const updateItemAttribute = core.useBuilderPreviewStore((s)=>s.updateItemAttribute);
32
33
  const changeLayoutSettings = core.useShopStore((s)=>s.changeLayoutSettings);
33
34
  const changeCreateThemeSectionCount = core.useShopStore((s)=>s.changeCreateThemeSectionCount);
34
35
  const changeShopPlan = core.useShopStore((s)=>s.changeShopPlan);
@@ -304,6 +305,14 @@ const Toolbox = ()=>{
304
305
  }, [
305
306
  updateItemName
306
307
  ]);
308
+ const onUpdateItemAttribute = react.useCallback((e)=>{
309
+ const detail = e.detail;
310
+ if (detail.uid) {
311
+ updateItemAttribute(detail.uid, detail.value || '', detail.attr || '');
312
+ }
313
+ }, [
314
+ updateItemAttribute
315
+ ]);
307
316
  react.useEffect(()=>{
308
317
  if (fonts) {
309
318
  setFontsToHead('google-font-element', fonts);
@@ -328,6 +337,7 @@ const Toolbox = ()=>{
328
337
  window.addEventListener('set-dynamic-product', onUpdateDynamicProduct);
329
338
  window.addEventListener('set-dynamic-collection', onUpdateDynamicCollection);
330
339
  window.addEventListener('update-item-name', onUpdateItemName);
340
+ window.addEventListener('update-item-attribute', onUpdateItemAttribute);
331
341
  return ()=>{
332
342
  window.removeEventListener('update-shop-info', onChangeShopInfo);
333
343
  window.removeEventListener('revalidate-query', onRevalidateQuery);
@@ -344,6 +354,7 @@ const Toolbox = ()=>{
344
354
  window.removeEventListener('set-dynamic-product', onUpdateDynamicProduct);
345
355
  window.removeEventListener('set-dynamic-collection', onUpdateDynamicCollection);
346
356
  window.removeEventListener('update-item-name', onUpdateItemName);
357
+ window.removeEventListener('update-item-attribute', onUpdateItemAttribute);
347
358
  };
348
359
  }, [
349
360
  onAddEntity,
@@ -361,7 +372,8 @@ const Toolbox = ()=>{
361
372
  onUpdateCreateThemeSectionCount,
362
373
  onUpdateDynamicProduct,
363
374
  onUpdateDynamicCollection,
364
- onUpdateItemName
375
+ onUpdateItemName,
376
+ onUpdateItemAttribute
365
377
  ]);
366
378
  return /*#__PURE__*/ jsxRuntime.jsx("div", {
367
379
  className: "toolbox"
@@ -2,20 +2,6 @@
2
2
 
3
3
  var genFonts = require('./helpers/gen-fonts.js');
4
4
 
5
- const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36';
6
- const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
7
- async function getFontForUA(url, UA) {
8
- return fetch(url, {
9
- headers: {
10
- 'User-Agent': UA
11
- }
12
- }).then((res)=>{
13
- if (res.status === 200) {
14
- return res.text();
15
- }
16
- return '';
17
- });
18
- }
19
5
  const composeFonts = (fonts)=>{
20
6
  const uniqFonts = fonts.filter((font, index, arr)=>{
21
7
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -56,31 +42,19 @@ const createFontUrl = (fonts, option)=>{
56
42
  }
57
43
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
58
44
  };
59
- async function getFonts(fonts, option, maxSize) {
45
+ async function getFonts(fonts, option) {
60
46
  /**
61
47
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
62
48
  * CSS cascading 🤷‍♂️.
63
49
  */ const url = createFontUrl(fonts, option);
64
50
  if (!url) return '';
65
51
  try {
66
- const [ie, chrome] = await Promise.all([
67
- getFontForUA(url, IE_UA),
68
- getFontForUA(url, CHROME_UA)
69
- ]);
70
- const value = ie + chrome;
71
- if (maxSize) {
72
- const textEncoder = new TextEncoder();
73
- const size = value ? textEncoder.encode(value).length : 0;
74
- if (Math.ceil(size / 1024) >= maxSize) {
75
- return `@import url('${url}');`;
76
- }
77
- }
78
- return value;
52
+ return `@import url('${url}');`;
79
53
  } catch (e) {
80
54
  return '';
81
55
  }
82
56
  }
83
- const getFontFromGlobalStyle = (data, maxSize)=>{
57
+ const getFontFromGlobalStyle = (data)=>{
84
58
  if (!data) return '';
85
59
  try {
86
60
  const globalStyle = JSON.parse(data);
@@ -88,7 +62,7 @@ const getFontFromGlobalStyle = (data, maxSize)=>{
88
62
  const fonts = Object.entries(fontData).map(([, value])=>{
89
63
  return value;
90
64
  });
91
- return getFonts(fonts, undefined, maxSize);
65
+ return getFonts(fonts);
92
66
  } catch {
93
67
  return '';
94
68
  }
@@ -25,6 +25,7 @@ const Toolbox = ()=>{
25
25
  const addSection = useSectionStore((s)=>s.addSection);
26
26
  const changeSwatches = useShopStore((s)=>s.changeSwatches);
27
27
  const updateItemName = useBuilderPreviewStore((s)=>s.updateItemName);
28
+ const updateItemAttribute = useBuilderPreviewStore((s)=>s.updateItemAttribute);
28
29
  const changeLayoutSettings = useShopStore((s)=>s.changeLayoutSettings);
29
30
  const changeCreateThemeSectionCount = useShopStore((s)=>s.changeCreateThemeSectionCount);
30
31
  const changeShopPlan = useShopStore((s)=>s.changeShopPlan);
@@ -300,6 +301,14 @@ const Toolbox = ()=>{
300
301
  }, [
301
302
  updateItemName
302
303
  ]);
304
+ const onUpdateItemAttribute = useCallback((e)=>{
305
+ const detail = e.detail;
306
+ if (detail.uid) {
307
+ updateItemAttribute(detail.uid, detail.value || '', detail.attr || '');
308
+ }
309
+ }, [
310
+ updateItemAttribute
311
+ ]);
303
312
  useEffect(()=>{
304
313
  if (fonts) {
305
314
  setFontsToHead('google-font-element', fonts);
@@ -324,6 +333,7 @@ const Toolbox = ()=>{
324
333
  window.addEventListener('set-dynamic-product', onUpdateDynamicProduct);
325
334
  window.addEventListener('set-dynamic-collection', onUpdateDynamicCollection);
326
335
  window.addEventListener('update-item-name', onUpdateItemName);
336
+ window.addEventListener('update-item-attribute', onUpdateItemAttribute);
327
337
  return ()=>{
328
338
  window.removeEventListener('update-shop-info', onChangeShopInfo);
329
339
  window.removeEventListener('revalidate-query', onRevalidateQuery);
@@ -340,6 +350,7 @@ const Toolbox = ()=>{
340
350
  window.removeEventListener('set-dynamic-product', onUpdateDynamicProduct);
341
351
  window.removeEventListener('set-dynamic-collection', onUpdateDynamicCollection);
342
352
  window.removeEventListener('update-item-name', onUpdateItemName);
353
+ window.removeEventListener('update-item-attribute', onUpdateItemAttribute);
343
354
  };
344
355
  }, [
345
356
  onAddEntity,
@@ -357,7 +368,8 @@ const Toolbox = ()=>{
357
368
  onUpdateCreateThemeSectionCount,
358
369
  onUpdateDynamicProduct,
359
370
  onUpdateDynamicCollection,
360
- onUpdateItemName
371
+ onUpdateItemName,
372
+ onUpdateItemAttribute
361
373
  ]);
362
374
  return /*#__PURE__*/ jsx("div", {
363
375
  className: "toolbox"
@@ -1,19 +1,5 @@
1
1
  import { getFontsFromDataBuilder } from './helpers/gen-fonts.js';
2
2
 
3
- const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36';
4
- const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
5
- async function getFontForUA(url, UA) {
6
- return fetch(url, {
7
- headers: {
8
- 'User-Agent': UA
9
- }
10
- }).then((res)=>{
11
- if (res.status === 200) {
12
- return res.text();
13
- }
14
- return '';
15
- });
16
- }
17
3
  const composeFonts = (fonts)=>{
18
4
  const uniqFonts = fonts.filter((font, index, arr)=>{
19
5
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -54,31 +40,19 @@ const createFontUrl = (fonts, option)=>{
54
40
  }
55
41
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
56
42
  };
57
- async function getFonts(fonts, option, maxSize) {
43
+ async function getFonts(fonts, option) {
58
44
  /**
59
45
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
60
46
  * CSS cascading 🤷‍♂️.
61
47
  */ const url = createFontUrl(fonts, option);
62
48
  if (!url) return '';
63
49
  try {
64
- const [ie, chrome] = await Promise.all([
65
- getFontForUA(url, IE_UA),
66
- getFontForUA(url, CHROME_UA)
67
- ]);
68
- const value = ie + chrome;
69
- if (maxSize) {
70
- const textEncoder = new TextEncoder();
71
- const size = value ? textEncoder.encode(value).length : 0;
72
- if (Math.ceil(size / 1024) >= maxSize) {
73
- return `@import url('${url}');`;
74
- }
75
- }
76
- return value;
50
+ return `@import url('${url}');`;
77
51
  } catch (e) {
78
52
  return '';
79
53
  }
80
54
  }
81
- const getFontFromGlobalStyle = (data, maxSize)=>{
55
+ const getFontFromGlobalStyle = (data)=>{
82
56
  if (!data) return '';
83
57
  try {
84
58
  const globalStyle = JSON.parse(data);
@@ -86,7 +60,7 @@ const getFontFromGlobalStyle = (data, maxSize)=>{
86
60
  const fonts = Object.entries(fontData).map(([, value])=>{
87
61
  return value;
88
62
  });
89
- return getFonts(fonts, undefined, maxSize);
63
+ return getFonts(fonts);
90
64
  } catch {
91
65
  return '';
92
66
  }
@@ -167,8 +167,8 @@ type FontOption = {
167
167
  subset?: string;
168
168
  effect?: string;
169
169
  };
170
- declare function getFonts(fonts: FontItem[], option?: FontOption, maxSize?: number): Promise<string>;
171
- declare const getFontFromGlobalStyle: (data?: string, maxSize?: number) => Promise<string> | "";
170
+ declare function getFonts(fonts: FontItem[], option?: FontOption): Promise<string>;
171
+ declare const getFontFromGlobalStyle: (data?: string) => Promise<string> | "";
172
172
 
173
173
  declare const getFontsFromDataBuilder: (dataBuilder: Record<string, any>) => FontItem[];
174
174
  declare const getFontFromGroupSetting: (fonts: FontItem[], groupSetting: Record<string, any>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "1.35.0",
3
+ "version": "1.36.6",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -25,7 +25,7 @@
25
25
  "next-seo": "^6.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@gem-sdk/core": "1.35.0",
28
+ "@gem-sdk/core": "1.36.6",
29
29
  "@gem-sdk/plugin-cookie-bar": "1.35.0",
30
30
  "@gem-sdk/plugin-quick-view": "1.35.0",
31
31
  "@gem-sdk/plugin-sticky-add-to-cart": "1.35.0"