@gem-sdk/core 1.14.0-next.91 → 1.14.0
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/cjs/components/AddOn.js +18 -1
- package/dist/cjs/components/ComponentWrapper.js +28 -1
- package/dist/cjs/components/ComponentWrapperPreview.js +72 -1
- package/dist/cjs/components/Empty.js +7 -1
- package/dist/cjs/components/Render.js +65 -1
- package/dist/cjs/components/Render.liquid.js +158 -3
- package/dist/cjs/components/RenderBlock.js +54 -1
- package/dist/cjs/components/RenderPreview.js +66 -1
- package/dist/cjs/components/RenderSection.js +23 -1
- package/dist/cjs/components/constant.js +39 -1
- package/dist/cjs/contexts/AddonContext.js +36 -1
- package/dist/cjs/contexts/BuilderComponent.js +34 -1
- package/dist/cjs/contexts/BuilderContext.js +35 -1
- package/dist/cjs/contexts/BuilderPreviewContext.js +370 -1
- package/dist/cjs/contexts/CartLineContext.js +29 -1
- package/dist/cjs/contexts/CollectionContext.js +38 -1
- package/dist/cjs/contexts/ModalContext.js +47 -1
- package/dist/cjs/contexts/ProductContext.js +149 -1
- package/dist/cjs/contexts/ProductListContext.js +32 -1
- package/dist/cjs/contexts/SectionContext.js +53 -1
- package/dist/cjs/contexts/ShopContext.js +70 -1
- package/dist/cjs/graphql/fragments/analytic.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection-product.generated.js +6 -2
- package/dist/cjs/graphql/fragments/collection.generated.js +6 -2
- package/dist/cjs/graphql/fragments/custom-code.generated.js +6 -2
- package/dist/cjs/graphql/fragments/data-seo.generated.js +6 -2
- package/dist/cjs/graphql/fragments/media.generated.js +6 -3
- package/dist/cjs/graphql/fragments/product-little.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product-option.generated.js +6 -2
- package/dist/cjs/graphql/fragments/product.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +6 -2
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +6 -2
- package/dist/cjs/graphql/fragments/selected-option.generated.js +6 -2
- package/dist/cjs/graphql/fragments/variant.generated.js +6 -2
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +7 -3
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +16 -2
- package/dist/cjs/graphql/queries/collection.generated.js +14 -2
- package/dist/cjs/graphql/queries/collections.generated.js +9 -2
- package/dist/cjs/graphql/queries/preview-page.generated.js +14 -2
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +11 -2
- package/dist/cjs/graphql/queries/product-medias.generated.js +8 -2
- package/dist/cjs/graphql/queries/product-variants.generated.js +10 -2
- package/dist/cjs/graphql/queries/products.generated.js +17 -3
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +14 -2
- package/dist/cjs/graphql/queries/store-property.generated.js +6 -2
- package/dist/cjs/helpers/GlobalEvent.js +19 -1
- package/dist/cjs/helpers/background.js +109 -1
- package/dist/cjs/helpers/borders.js +183 -4
- package/dist/cjs/helpers/clone-deep.js +5 -1
- package/dist/cjs/helpers/cls.js +16 -1
- package/dist/cjs/helpers/colors.js +183 -1
- package/dist/cjs/helpers/compose-advance-style.js +188 -1
- package/dist/cjs/helpers/constant.js +23 -1
- package/dist/cjs/helpers/convert.js +7 -1
- package/dist/cjs/helpers/css-variable.js +7 -1
- package/dist/cjs/helpers/email.js +11 -1
- package/dist/cjs/helpers/flatten-connection.js +9 -1
- package/dist/cjs/helpers/get-resonsive-value.js +31 -1
- package/dist/cjs/helpers/get-shortname.js +92 -1
- package/dist/cjs/helpers/is-browser.js +9 -1
- package/dist/cjs/helpers/is-defined.js +7 -1
- package/dist/cjs/helpers/is-empty-children.js +12 -1
- package/dist/cjs/helpers/is-safari.js +9 -1
- package/dist/cjs/helpers/layout.js +59 -1
- package/dist/cjs/helpers/load-script.js +31 -1
- package/dist/cjs/helpers/make-style.js +128 -1
- package/dist/cjs/helpers/normalize-builder-data.js +23 -1
- package/dist/cjs/helpers/prefetch-queries.js +78 -1
- package/dist/cjs/helpers/product.js +45 -1
- package/dist/cjs/helpers/queries/get-collection.js +220 -1
- package/dist/cjs/helpers/queries/get-collections.js +21 -1
- package/dist/cjs/helpers/queries/get-product-by-slug.js +125 -1
- package/dist/cjs/helpers/queries/get-product.js +154 -1
- package/dist/cjs/helpers/queries/get-products.js +161 -1
- package/dist/cjs/helpers/query.js +29 -1
- package/dist/cjs/helpers/radius.js +131 -6
- package/dist/cjs/helpers/render.js +71 -1
- package/dist/cjs/helpers/shadow.js +56 -1
- package/dist/cjs/helpers/size.js +35 -4
- package/dist/cjs/helpers/spacing.js +43 -1
- package/dist/cjs/helpers/tracking/fpixel.js +28 -1
- package/dist/cjs/helpers/tracking/gtag.js +93 -1
- package/dist/cjs/helpers/tracking/tiktokpixel.js +17 -1
- package/dist/cjs/helpers/typography.js +105 -17
- package/dist/cjs/helpers/variant.js +8 -1
- package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -1
- package/dist/cjs/hooks/cart/use-cart-data.js +28 -1
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -1
- package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -1
- package/dist/cjs/hooks/cart/use-create-cart.js +22 -1
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -1
- package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -1
- package/dist/cjs/hooks/shop/use-collection-query.js +22 -1
- package/dist/cjs/hooks/shop/use-collections-query.js +17 -1
- package/dist/cjs/hooks/shop/use-product-query.js +22 -1
- package/dist/cjs/hooks/shop/use-products-query.js +22 -1
- package/dist/cjs/hooks/shop.js +126 -1
- package/dist/cjs/hooks/use-current-device.js +21 -1
- package/dist/cjs/hooks/use-lazy-video.js +15 -1
- package/dist/cjs/hooks/useCartId.js +44 -1
- package/dist/cjs/hooks/useCartLine.js +11 -1
- package/dist/cjs/hooks/useCartUI.js +48 -1
- package/dist/cjs/hooks/useCollection.js +9 -1
- package/dist/cjs/hooks/useFetchHandle.js +13 -1
- package/dist/cjs/hooks/useFormatMoney.js +58 -1
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -1
- package/dist/cjs/hooks/useLoadScript.js +32 -1
- package/dist/cjs/hooks/useMoney.js +84 -1
- package/dist/cjs/hooks/usePrevious.js +19 -1
- package/dist/cjs/hooks/useProduct.js +124 -1
- package/dist/cjs/hooks/useProductList.js +21 -1
- package/dist/cjs/hooks/useSuspenseFetch.js +27 -1
- package/dist/cjs/hooks/useSwatchesOptions.js +41 -1
- package/dist/cjs/index.js +291 -1
- package/dist/cjs/types/global-style.js +14 -1
- package/dist/cjs/types/shop.js +2 -1
- package/dist/esm/components/AddOn.js +14 -1
- package/dist/esm/components/ComponentWrapper.js +24 -1
- package/dist/esm/components/ComponentWrapperPreview.js +68 -1
- package/dist/esm/components/Empty.js +3 -1
- package/dist/esm/components/Render.js +61 -1
- package/dist/esm/components/Render.liquid.js +153 -3
- package/dist/esm/components/RenderBlock.js +50 -1
- package/dist/esm/components/RenderPreview.js +62 -1
- package/dist/esm/components/RenderSection.js +19 -1
- package/dist/esm/components/constant.js +37 -1
- package/dist/esm/contexts/AddonContext.js +32 -1
- package/dist/esm/contexts/BuilderComponent.js +31 -1
- package/dist/esm/contexts/BuilderContext.js +32 -1
- package/dist/esm/contexts/BuilderPreviewContext.js +367 -1
- package/dist/esm/contexts/CartLineContext.js +26 -1
- package/dist/esm/contexts/CollectionContext.js +35 -1
- package/dist/esm/contexts/ModalContext.js +44 -1
- package/dist/esm/contexts/ProductContext.js +146 -1
- package/dist/esm/contexts/ProductListContext.js +28 -1
- package/dist/esm/contexts/SectionContext.js +49 -1
- package/dist/esm/contexts/ShopContext.js +67 -1
- package/dist/esm/graphql/fragments/analytic.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection-detail.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection-product.generated.js +4 -2
- package/dist/esm/graphql/fragments/collection.generated.js +4 -2
- package/dist/esm/graphql/fragments/custom-code.generated.js +4 -2
- package/dist/esm/graphql/fragments/data-seo.generated.js +4 -2
- package/dist/esm/graphql/fragments/media.generated.js +4 -3
- package/dist/esm/graphql/fragments/product-little.generated.js +4 -2
- package/dist/esm/graphql/fragments/product-option-value.generated.js +4 -2
- package/dist/esm/graphql/fragments/product-option.generated.js +4 -2
- package/dist/esm/graphql/fragments/product.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-page-section.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +4 -2
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +4 -2
- package/dist/esm/graphql/fragments/selected-option.generated.js +4 -2
- package/dist/esm/graphql/fragments/variant.generated.js +4 -2
- package/dist/esm/graphql/mutations/page-view-up.generated.js +5 -3
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +22 -10
- package/dist/esm/graphql/queries/collection.generated.js +18 -8
- package/dist/esm/graphql/queries/collections.generated.js +8 -3
- package/dist/esm/graphql/queries/preview-page.generated.js +18 -8
- package/dist/esm/graphql/queries/product-little-detail.generated.js +12 -5
- package/dist/esm/graphql/queries/product-medias.generated.js +6 -2
- package/dist/esm/graphql/queries/product-variants.generated.js +10 -4
- package/dist/esm/graphql/queries/products.generated.js +20 -9
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +18 -8
- package/dist/esm/graphql/queries/store-property.generated.js +4 -2
- package/dist/esm/helpers/GlobalEvent.js +15 -1
- package/dist/esm/helpers/background.js +106 -1
- package/dist/esm/helpers/borders.js +175 -4
- package/dist/esm/helpers/clone-deep.js +3 -1
- package/dist/esm/helpers/cls.js +14 -1
- package/dist/esm/helpers/colors.js +168 -1
- package/dist/esm/helpers/compose-advance-style.js +185 -1
- package/dist/esm/helpers/constant.js +19 -1
- package/dist/esm/helpers/convert.js +4 -1
- package/dist/esm/helpers/css-variable.js +5 -1
- package/dist/esm/helpers/email.js +6 -1
- package/dist/esm/helpers/flatten-connection.js +7 -1
- package/dist/esm/helpers/get-resonsive-value.js +27 -1
- package/dist/esm/helpers/get-shortname.js +90 -1
- package/dist/esm/helpers/is-browser.js +5 -1
- package/dist/esm/helpers/is-defined.js +5 -1
- package/dist/esm/helpers/is-empty-children.js +7 -1
- package/dist/esm/helpers/is-safari.js +5 -1
- package/dist/esm/helpers/layout.js +54 -1
- package/dist/esm/helpers/load-script.js +29 -1
- package/dist/esm/helpers/make-style.js +117 -1
- package/dist/esm/helpers/normalize-builder-data.js +21 -1
- package/dist/esm/helpers/prefetch-queries.js +76 -1
- package/dist/esm/helpers/product.js +41 -1
- package/dist/esm/helpers/queries/get-collection.js +217 -1
- package/dist/esm/helpers/queries/get-collections.js +19 -1
- package/dist/esm/helpers/queries/get-product-by-slug.js +123 -1
- package/dist/esm/helpers/queries/get-product.js +150 -1
- package/dist/esm/helpers/queries/get-products.js +159 -1
- package/dist/esm/helpers/query.js +25 -1
- package/dist/esm/helpers/radius.js +124 -6
- package/dist/esm/helpers/render.js +64 -1
- package/dist/esm/helpers/shadow.js +51 -1
- package/dist/esm/helpers/size.js +31 -4
- package/dist/esm/helpers/spacing.js +40 -1
- package/dist/esm/helpers/tracking/fpixel.js +24 -1
- package/dist/esm/helpers/tracking/gtag.js +87 -1
- package/dist/esm/helpers/tracking/tiktokpixel.js +15 -1
- package/dist/esm/helpers/typography.js +96 -17
- package/dist/esm/helpers/variant.js +6 -1
- package/dist/esm/hooks/cart/use-add-to-cart.js +18 -1
- package/dist/esm/hooks/cart/use-cart-data.js +26 -1
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -1
- package/dist/esm/hooks/cart/use-cart-note-update.js +18 -1
- package/dist/esm/hooks/cart/use-create-cart.js +20 -1
- package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -1
- package/dist/esm/hooks/cart/use-update-cart-item.js +18 -1
- package/dist/esm/hooks/shop/use-collection-query.js +20 -1
- package/dist/esm/hooks/shop/use-collections-query.js +15 -1
- package/dist/esm/hooks/shop/use-product-query.js +20 -1
- package/dist/esm/hooks/shop/use-products-query.js +20 -1
- package/dist/esm/hooks/shop.js +111 -1
- package/dist/esm/hooks/use-current-device.js +19 -1
- package/dist/esm/hooks/use-lazy-video.js +13 -1
- package/dist/esm/hooks/useCartId.js +40 -1
- package/dist/esm/hooks/useCartLine.js +7 -1
- package/dist/esm/hooks/useCartUI.js +44 -1
- package/dist/esm/hooks/useCollection.js +7 -1
- package/dist/esm/hooks/useFetchHandle.js +11 -1
- package/dist/esm/hooks/useFormatMoney.js +56 -1
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -1
- package/dist/esm/hooks/useLoadScript.js +28 -1
- package/dist/esm/hooks/useMoney.js +80 -1
- package/dist/esm/hooks/usePrevious.js +17 -1
- package/dist/esm/hooks/useProduct.js +111 -1
- package/dist/esm/hooks/useProductList.js +16 -1
- package/dist/esm/hooks/useSuspenseFetch.js +23 -1
- package/dist/esm/hooks/useSwatchesOptions.js +37 -1
- package/dist/esm/index.js +92 -1
- package/dist/esm/types/global-style.js +11 -1
- package/dist/types/index.d.ts +27 -28
- package/package.json +2 -2
|
@@ -1 +1,159 @@
|
|
|
1
|
-
import{ProductsDocument
|
|
1
|
+
import { ProductsDocument } from '../../graphql/queries/products.generated.js';
|
|
2
|
+
import { calculateFirstProduct } from './get-collection.js';
|
|
3
|
+
import { fetchVariants, fetchMedias } from './get-product.js';
|
|
4
|
+
|
|
5
|
+
const getProducts = async (fetcher, { ids, isSample, isStorefront })=>{
|
|
6
|
+
const products = await loopFetchProducts(fetcher, {
|
|
7
|
+
ids,
|
|
8
|
+
isSample,
|
|
9
|
+
isStorefront
|
|
10
|
+
});
|
|
11
|
+
if (!products) {
|
|
12
|
+
throw new Error('Product not found');
|
|
13
|
+
}
|
|
14
|
+
const [mergedVariant, mergedMedias] = await Promise.all([
|
|
15
|
+
mergeVariantsToProducts({
|
|
16
|
+
fetcher,
|
|
17
|
+
products,
|
|
18
|
+
isSample,
|
|
19
|
+
isStorefront
|
|
20
|
+
}),
|
|
21
|
+
mergeMediasToProducts({
|
|
22
|
+
fetcher,
|
|
23
|
+
products,
|
|
24
|
+
isSample,
|
|
25
|
+
isStorefront
|
|
26
|
+
})
|
|
27
|
+
]);
|
|
28
|
+
return {
|
|
29
|
+
...products,
|
|
30
|
+
products: {
|
|
31
|
+
...products.products,
|
|
32
|
+
edges: products.products?.edges.map((edge)=>{
|
|
33
|
+
const medias = mergedMedias.find((item)=>item.productId === edge.node?.baseID);
|
|
34
|
+
const variants = mergedVariant.find((item)=>item.productId === edge.node?.baseID);
|
|
35
|
+
if (edge.node) {
|
|
36
|
+
return {
|
|
37
|
+
...edge,
|
|
38
|
+
node: {
|
|
39
|
+
...edge.node,
|
|
40
|
+
variants: {
|
|
41
|
+
...edge.node?.variants,
|
|
42
|
+
edges: variants?.items ?? []
|
|
43
|
+
},
|
|
44
|
+
medias: {
|
|
45
|
+
...edge.node?.medias,
|
|
46
|
+
edges: medias?.items ?? []
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return edge;
|
|
52
|
+
}) ?? []
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
const fetchProducts = async (fetcher, variables)=>{
|
|
57
|
+
return fetcher([
|
|
58
|
+
ProductsDocument,
|
|
59
|
+
variables
|
|
60
|
+
]);
|
|
61
|
+
};
|
|
62
|
+
const loopFetchProducts = async (fetcher, { ids, isSample, isStorefront })=>{
|
|
63
|
+
const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
|
|
64
|
+
const productsPerPage = 8; // number of products per page
|
|
65
|
+
let variables; // variables of collection query
|
|
66
|
+
let productAfterFetcher; // product after of collection query
|
|
67
|
+
let dataProducts; // data of collection query
|
|
68
|
+
let hasNextPage; //
|
|
69
|
+
let firstProducts;
|
|
70
|
+
let currentPage = 1;
|
|
71
|
+
// counter number of queries
|
|
72
|
+
const pages = Math.ceil(numberOfProducts / productsPerPage);
|
|
73
|
+
while(currentPage <= pages && hasNextPage !== false){
|
|
74
|
+
variables = {
|
|
75
|
+
first: calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
|
|
76
|
+
firstMedia: 1,
|
|
77
|
+
firstVariant: 1,
|
|
78
|
+
orderBy: {
|
|
79
|
+
field: 'PLATFORM_CREATED_AT',
|
|
80
|
+
direction: 'DESC'
|
|
81
|
+
},
|
|
82
|
+
orderByMedia: {
|
|
83
|
+
field: 'POSITION',
|
|
84
|
+
direction: 'ASC'
|
|
85
|
+
},
|
|
86
|
+
where: {
|
|
87
|
+
status: 'ACTIVE',
|
|
88
|
+
isSample,
|
|
89
|
+
...isStorefront && {
|
|
90
|
+
isStorefront
|
|
91
|
+
},
|
|
92
|
+
...ids?.length ? {
|
|
93
|
+
baseIDIn: ids
|
|
94
|
+
} : {}
|
|
95
|
+
},
|
|
96
|
+
after: productAfterFetcher
|
|
97
|
+
};
|
|
98
|
+
const pageData = await fetchProducts(fetcher, variables);
|
|
99
|
+
productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
|
|
100
|
+
if (currentPage === 1) {
|
|
101
|
+
dataProducts = pageData; // set data of first page
|
|
102
|
+
firstProducts = pageData;
|
|
103
|
+
} else if (firstProducts?.products && pageData?.products?.edges.length) {
|
|
104
|
+
// concat new values to the old ones
|
|
105
|
+
firstProducts.products = {
|
|
106
|
+
edges: firstProducts.products.edges.concat(pageData?.products?.edges),
|
|
107
|
+
pageInfo: pageData?.products?.pageInfo
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
currentPage++;
|
|
111
|
+
// hasNextPage = false if there is no more pages then break the loop
|
|
112
|
+
if (!firstProducts) {
|
|
113
|
+
hasNextPage = false;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return dataProducts;
|
|
118
|
+
};
|
|
119
|
+
const mergeVariantsToProducts = async ({ fetcher, products, isSample, isStorefront })=>{
|
|
120
|
+
const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product)=>{
|
|
121
|
+
const variants = await fetchVariants(fetcher, {
|
|
122
|
+
id: product?.node?.baseID,
|
|
123
|
+
isSample,
|
|
124
|
+
isStorefront
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
productId: product?.node?.baseID,
|
|
128
|
+
items: variants
|
|
129
|
+
};
|
|
130
|
+
}) ?? []);
|
|
131
|
+
return productsWithVariants;
|
|
132
|
+
};
|
|
133
|
+
const mergeMediasToProducts = async ({ fetcher, products, isSample, isStorefront })=>{
|
|
134
|
+
const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product)=>{
|
|
135
|
+
const medias = await fetchMedias(fetcher, {
|
|
136
|
+
id: product?.node?.baseID,
|
|
137
|
+
isSample,
|
|
138
|
+
isStorefront
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
productId: product?.node?.baseID,
|
|
142
|
+
items: medias
|
|
143
|
+
};
|
|
144
|
+
}) ?? []);
|
|
145
|
+
return productsWithMedias;
|
|
146
|
+
}; // future can be used for fetching products with paging ids
|
|
147
|
+
// const pagingQuery = (
|
|
148
|
+
// data: string[],
|
|
149
|
+
// currentPage: number,
|
|
150
|
+
// productsPerPage: number,
|
|
151
|
+
// first: number,
|
|
152
|
+
// ): string[] => {
|
|
153
|
+
// return data.slice(
|
|
154
|
+
// (currentPage - 1) * productsPerPage,
|
|
155
|
+
// (currentPage - 1) * productsPerPage + first,
|
|
156
|
+
// );
|
|
157
|
+
// };
|
|
158
|
+
|
|
159
|
+
export { getProducts };
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
const generateProductQueryKey = (args)=>{
|
|
2
|
+
return [
|
|
3
|
+
'query/product',
|
|
4
|
+
args
|
|
5
|
+
];
|
|
6
|
+
};
|
|
7
|
+
const generateCollectionQueryKey = (args)=>{
|
|
8
|
+
return [
|
|
9
|
+
'query/collection',
|
|
10
|
+
args
|
|
11
|
+
];
|
|
12
|
+
};
|
|
13
|
+
const generateProductsQueryKey = (args)=>{
|
|
14
|
+
return [
|
|
15
|
+
'query/products',
|
|
16
|
+
{
|
|
17
|
+
...args,
|
|
18
|
+
ids: [
|
|
19
|
+
...args.ids
|
|
20
|
+
].sort()
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { generateCollectionQueryKey, generateProductQueryKey, generateProductsQueryKey };
|
|
@@ -1,9 +1,127 @@
|
|
|
1
|
-
import{devicesMapping
|
|
2
|
-
|
|
1
|
+
import { devicesMapping, stateMapping } from './constant.js';
|
|
2
|
+
import { makeStyle } from './make-style.js';
|
|
3
|
+
|
|
4
|
+
const getCornerCSSFromGlobal = (corner)=>{
|
|
5
|
+
if (!corner.radiusType) return {};
|
|
6
|
+
if ([
|
|
7
|
+
'custom',
|
|
8
|
+
'circle'
|
|
9
|
+
].includes(corner.radiusType)) return makeStyle({
|
|
10
|
+
bblr: corner.bblr,
|
|
11
|
+
bbrr: corner.bbrr,
|
|
12
|
+
btlr: corner.btlr,
|
|
13
|
+
btrr: corner.btrr
|
|
14
|
+
});
|
|
15
|
+
return makeStyle({
|
|
16
|
+
radius: `var(--g-radius-${corner.radiusType})`
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
const getRadiusCSSFromGlobal = (state, key, device)=>{
|
|
20
|
+
if (!key || !state) return {};
|
|
21
|
+
const suffix = device && device !== 'desktop' ? devicesMapping?.[device] : '';
|
|
22
|
+
const mState = stateMapping?.[state];
|
|
23
|
+
return {
|
|
24
|
+
[`-${mState}-radius${suffix}`]: `var(--g-radius-${key})`
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const getCustomRadius = (state, radius, device)=>{
|
|
28
|
+
if (!radius || !state || radius.radiusType !== 'custom') return {};
|
|
29
|
+
const suffix = device && device !== 'desktop' ? devicesMapping?.[device] : '';
|
|
30
|
+
const mState = stateMapping?.[state];
|
|
31
|
+
return {
|
|
32
|
+
[`-${mState}-bblr${suffix}`]: radius.bblr,
|
|
33
|
+
[`-${mState}-bbrr${suffix}`]: radius.bbrr,
|
|
34
|
+
[`-${mState}-btlr${suffix}`]: radius.btlr,
|
|
35
|
+
[`-${mState}-btrr${suffix}`]: radius.btrr
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const composeRadius = (value)=>{
|
|
39
|
+
if (!value) return {};
|
|
40
|
+
if ('desktop' in value || 'tablet' in value || 'mobile' in value) {
|
|
41
|
+
return composeRadiusResponsiveState(value);
|
|
42
|
+
}
|
|
43
|
+
return composeRadiusState(value);
|
|
44
|
+
};
|
|
45
|
+
const composeRadiusState = (radiusValue, device)=>{
|
|
46
|
+
const style = {};
|
|
47
|
+
switch(radiusValue?.normal?.radiusType){
|
|
48
|
+
case 'medium':
|
|
49
|
+
case 'large':
|
|
50
|
+
case 'small':
|
|
51
|
+
Object.assign(style, getRadiusCSSFromGlobal('normal', radiusValue?.normal?.radiusType, device));
|
|
52
|
+
break;
|
|
53
|
+
case 'circle':
|
|
54
|
+
case 'none':
|
|
55
|
+
case 'custom':
|
|
56
|
+
Object.assign(style, getCustomRadius('normal', radiusValue.normal, device));
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
switch(radiusValue?.hover?.radiusType){
|
|
60
|
+
case 'medium':
|
|
61
|
+
case 'large':
|
|
62
|
+
case 'small':
|
|
63
|
+
Object.assign(style, getRadiusCSSFromGlobal('hover', radiusValue?.hover?.radiusType, device));
|
|
64
|
+
break;
|
|
65
|
+
case 'circle':
|
|
66
|
+
case 'none':
|
|
67
|
+
case 'custom':
|
|
68
|
+
Object.assign(style, getCustomRadius('hover', radiusValue.hover, device));
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
switch(radiusValue?.focus?.radiusType){
|
|
72
|
+
case 'medium':
|
|
73
|
+
case 'large':
|
|
74
|
+
case 'small':
|
|
75
|
+
Object.assign(style, getRadiusCSSFromGlobal('focus', radiusValue?.focus?.radiusType, device));
|
|
76
|
+
break;
|
|
77
|
+
case 'circle':
|
|
78
|
+
case 'none':
|
|
79
|
+
case 'custom':
|
|
80
|
+
Object.assign(style, getCustomRadius('focus', radiusValue.focus, device));
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return style;
|
|
84
|
+
};
|
|
85
|
+
const composeRadiusResponsiveState = (radiusValue)=>{
|
|
86
|
+
const style = {};
|
|
87
|
+
Object.assign(style, composeRadiusState(radiusValue?.desktop, 'desktop'));
|
|
88
|
+
Object.assign(style, composeRadiusState(radiusValue?.tablet, 'tablet'));
|
|
89
|
+
Object.assign(style, composeRadiusState(radiusValue?.mobile, 'mobile'));
|
|
90
|
+
return style;
|
|
91
|
+
};
|
|
92
|
+
const getRadiusStyleActiveState = (radiusValue)=>{
|
|
93
|
+
if (radiusValue?.active?.radiusType === 'custom') {
|
|
94
|
+
return getCustomRadius('normal', radiusValue?.active);
|
|
95
|
+
}
|
|
96
|
+
return getRadiusCSSFromGlobal('normal', radiusValue?.active?.radiusType);
|
|
97
|
+
};
|
|
98
|
+
const composeCornerCss = (value)=>{
|
|
99
|
+
if (!value) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const { radiusType, bblr, bbrr, btlr, btrr } = value;
|
|
103
|
+
let radiusValue = undefined;
|
|
104
|
+
switch(radiusType){
|
|
105
|
+
case 'medium':
|
|
106
|
+
case 'large':
|
|
107
|
+
case 'small':
|
|
108
|
+
radiusValue = `border-radius: var(--g-radius-${radiusType});`;
|
|
109
|
+
break;
|
|
110
|
+
case 'circle':
|
|
111
|
+
case 'none':
|
|
112
|
+
case 'custom':
|
|
113
|
+
radiusValue = `
|
|
114
|
+
${bblr ? `border-bottom-left-radius: ${bblr};` : ''}
|
|
3
115
|
|
|
4
|
-
${
|
|
116
|
+
${bbrr ? `border-bottom-right-radius: ${bbrr};` : ''}
|
|
5
117
|
|
|
6
|
-
${
|
|
118
|
+
${btlr ? `border-top-left-radius: ${btlr};` : ''}
|
|
7
119
|
|
|
8
|
-
${
|
|
9
|
-
|
|
120
|
+
${btrr ? `border-top-right-radius: ${btrr};` : ''}
|
|
121
|
+
`;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
return radiusValue;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export { composeCornerCss, composeRadius, getCornerCSSFromGlobal, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState };
|
|
@@ -1 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
const RenderIf = (c, t, f)=>c ? typeof t === 'string' ? t : t() : (typeof f === 'string' ? f : f?.()) ?? '';
|
|
2
|
+
const isObject = (obj)=>{
|
|
3
|
+
if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
return false;
|
|
7
|
+
};
|
|
8
|
+
const props = (strings, ...keys)=>{
|
|
9
|
+
const props = keys[0];
|
|
10
|
+
const propsArr = [];
|
|
11
|
+
for(const attr in props){
|
|
12
|
+
if (Object.hasOwnProperty.call(props, attr)) {
|
|
13
|
+
const val = props[attr];
|
|
14
|
+
if (![
|
|
15
|
+
'symbol',
|
|
16
|
+
'object',
|
|
17
|
+
'function'
|
|
18
|
+
].includes(typeof val)) {
|
|
19
|
+
if (val) {
|
|
20
|
+
propsArr.push(`${attr}="${val}"`);
|
|
21
|
+
} else {
|
|
22
|
+
propsArr.push(`${attr}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return propsArr.join(' ');
|
|
28
|
+
};
|
|
29
|
+
const styles = (strings, ...keys)=>{
|
|
30
|
+
const styles = keys[0];
|
|
31
|
+
const styleArr = [];
|
|
32
|
+
for(const attr in styles){
|
|
33
|
+
if (Object.hasOwnProperty.call(styles, attr)) {
|
|
34
|
+
const val = styles[attr];
|
|
35
|
+
if (val !== undefined && val !== false) styleArr.push(`${attr}:${val}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return styleArr.join(';');
|
|
39
|
+
};
|
|
40
|
+
const dataStringify = (obj)=>{
|
|
41
|
+
return JSON.stringify(obj).replace(/\\"/g, '"');
|
|
42
|
+
};
|
|
43
|
+
const template = (strings, ...keys)=>{
|
|
44
|
+
let str = '';
|
|
45
|
+
strings.forEach((item, index)=>{
|
|
46
|
+
str += item;
|
|
47
|
+
if (keys[index] !== undefined) {
|
|
48
|
+
if (isObject(keys[index])) {
|
|
49
|
+
if (/style=["|']/.test(item)) {
|
|
50
|
+
str += styles`${keys[index]}`;
|
|
51
|
+
} else {
|
|
52
|
+
str += props`${keys[index]}`;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
str += keys[index];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return str;
|
|
60
|
+
};
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
62
|
+
const composeMemo = (fn, _)=>fn();
|
|
63
|
+
|
|
64
|
+
export { RenderIf, composeMemo, dataStringify, props, styles, template };
|
|
@@ -1 +1,51 @@
|
|
|
1
|
-
import{getSingleColorVariable
|
|
1
|
+
import { getSingleColorVariable } from './colors.js';
|
|
2
|
+
import { stateMapping } from './constant.js';
|
|
3
|
+
import { getShortName } from './get-shortname.js';
|
|
4
|
+
|
|
5
|
+
const parseValueWithUnit = (valueWithUnit)=>{
|
|
6
|
+
const matches = valueWithUnit.match(/(\d+)(.+)/);
|
|
7
|
+
if (matches && matches.length === 3) {
|
|
8
|
+
const value = Number(matches[1] ?? 0);
|
|
9
|
+
const unit = matches[2];
|
|
10
|
+
return {
|
|
11
|
+
value,
|
|
12
|
+
unit: unit ?? 'px'
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
value: 0,
|
|
17
|
+
unit: 'px'
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const getStyleShadow = (shadowStyle, isActiveState = false)=>{
|
|
21
|
+
const { styleAppliedFor, value, isEnableShadow } = shadowStyle || {};
|
|
22
|
+
let { state } = shadowStyle || {};
|
|
23
|
+
if (!state) state = 'normal';
|
|
24
|
+
if (!styleAppliedFor || !value) return {};
|
|
25
|
+
if (typeof value.distance == 'undefined') return {};
|
|
26
|
+
const { value: distance, unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
|
|
27
|
+
return {
|
|
28
|
+
[`-${!isActiveState ? stateMapping?.[state] : ''}-${getShortName(styleAppliedFor)}`]: isEnableShadow ? `${Math.cos(parseFloat(`${value?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${Math.sin(parseFloat(`${value?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${value?.blur} ${styleAppliedFor === 'box-shadow' ? value?.spread + ' ' : ''}${getSingleColorVariable(value?.color)}` : 'none'
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const getStyleShadowState = (shadow, styleAppliedFor, isEnableShadow)=>{
|
|
32
|
+
if (!shadow || !styleAppliedFor) return {};
|
|
33
|
+
const style = {};
|
|
34
|
+
for (const [key, value] of Object.entries(shadow)){
|
|
35
|
+
Object.assign(style, getStyleShadow({
|
|
36
|
+
value: value,
|
|
37
|
+
state: key,
|
|
38
|
+
styleAppliedFor,
|
|
39
|
+
isEnableShadow: isEnableShadow?.[key]
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
return style;
|
|
43
|
+
};
|
|
44
|
+
const composeShadowCss = ({ hasBoxShadow, boxShadowValue })=>{
|
|
45
|
+
if (!hasBoxShadow) return undefined;
|
|
46
|
+
if (!boxShadowValue) return undefined;
|
|
47
|
+
const { value: distance, unit: unitDistance } = parseValueWithUnit(`${boxShadowValue?.distance}`);
|
|
48
|
+
return `box-shadow: ${Math.cos(parseFloat(`${boxShadowValue?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${Math.sin(parseFloat(`${boxShadowValue?.angle}`) * Math.PI / 180) * parseFloat(`${distance}`)}${unitDistance} ${boxShadowValue?.blur} ${boxShadowValue?.spread + ' '}${getSingleColorVariable(boxShadowValue?.color)};`;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { composeShadowCss, getStyleShadow, getStyleShadowState, parseValueWithUnit };
|
package/dist/esm/helpers/size.js
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
import{devicesMapping
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { devicesMapping } from './constant.js';
|
|
2
|
+
|
|
3
|
+
function getCustomSizeCSSByDevice(size, device) {
|
|
4
|
+
if (!size || !device) return {};
|
|
5
|
+
const suffix = devicesMapping[device] ?? '';
|
|
6
|
+
return {
|
|
7
|
+
[`--pl${suffix}`]: size?.[device]?.horizontal,
|
|
8
|
+
[`--pr${suffix}`]: size?.[device]?.horizontal,
|
|
9
|
+
[`--pt${suffix}`]: size?.[device]?.vertical,
|
|
10
|
+
[`--pb${suffix}`]: size?.[device]?.vertical
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const composeSize = (size)=>{
|
|
14
|
+
return Object.assign({}, getCustomSizeCSSByDevice(size, 'desktop'), getCustomSizeCSSByDevice(size, 'tablet'), getCustomSizeCSSByDevice(size, 'mobile'));
|
|
15
|
+
};
|
|
16
|
+
function genSizeClass(name) {
|
|
17
|
+
return `g-s-${name}`;
|
|
18
|
+
}
|
|
19
|
+
const composeSizeCss = (spacing)=>{
|
|
20
|
+
if (spacing === undefined) return '';
|
|
21
|
+
const size = spacing;
|
|
22
|
+
const sizeHozi = spacing?.custom?.desktop?.horizontal;
|
|
23
|
+
const sizeVerti = spacing?.custom?.desktop?.vertical;
|
|
24
|
+
if (!size?.custom) return undefined;
|
|
25
|
+
return `
|
|
26
|
+
${sizeHozi ? `padding-left: ${sizeHozi}; padding-right: ${sizeHozi};` : undefined}
|
|
27
|
+
${sizeVerti ? `padding-top: ${sizeVerti}; padding-bottom: ${sizeVerti};` : undefined}
|
|
28
|
+
`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { composeSize, composeSizeCss, genSizeClass };
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
import{devicesMapping
|
|
1
|
+
import { devicesMapping } from './constant.js';
|
|
2
|
+
|
|
3
|
+
function getSpacingCSSByType(key, device) {
|
|
4
|
+
if (!key) return {};
|
|
5
|
+
const suffix = device ? devicesMapping?.[device] ?? '' : '';
|
|
6
|
+
return {
|
|
7
|
+
[`--p${suffix}`]: `var(--g-s-${key})`
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function getSpacingVariable(key) {
|
|
11
|
+
if (!key) return '';
|
|
12
|
+
return `var(--g-s-${key})`;
|
|
13
|
+
}
|
|
14
|
+
const composeSpacing = (spacingValue)=>{
|
|
15
|
+
const style = {};
|
|
16
|
+
switch(spacingValue?.desktop){
|
|
17
|
+
case 'm':
|
|
18
|
+
case 'l':
|
|
19
|
+
case 's':
|
|
20
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.desktop));
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
switch(spacingValue?.tablet){
|
|
24
|
+
case 'm':
|
|
25
|
+
case 'l':
|
|
26
|
+
case 's':
|
|
27
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.tablet, 'tablet'));
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
switch(spacingValue?.mobile){
|
|
31
|
+
case 'm':
|
|
32
|
+
case 'l':
|
|
33
|
+
case 's':
|
|
34
|
+
Object.assign(style, getSpacingCSSByType(spacingValue.mobile, 'mobile'));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return style;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { composeSpacing, getSpacingVariable };
|
|
@@ -1 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
const pageview = ()=>{
|
|
2
|
+
if (!window.fbq) return;
|
|
3
|
+
window.fbq('track', 'PageView');
|
|
4
|
+
};
|
|
5
|
+
// https://developers.facebook.com/docs/facebook-pixel/advanced/
|
|
6
|
+
const event = (name, options = {})=>{
|
|
7
|
+
if (!window.fbq) return;
|
|
8
|
+
window.fbq('track', name, options);
|
|
9
|
+
};
|
|
10
|
+
const addToCart = (product)=>{
|
|
11
|
+
if (!window.fbq) return;
|
|
12
|
+
window.fbq('track', 'AddToCart', {
|
|
13
|
+
content_ids: [
|
|
14
|
+
product.id
|
|
15
|
+
],
|
|
16
|
+
content_name: product.name,
|
|
17
|
+
content_category: product.category,
|
|
18
|
+
content_type: 'product',
|
|
19
|
+
value: product.price,
|
|
20
|
+
currency: product.currency
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { addToCart, event, pageview };
|
|
@@ -1 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
2
|
+
const pageview = (url, trackingId)=>{
|
|
3
|
+
// GA 4
|
|
4
|
+
if (window.gtag && trackingId) {
|
|
5
|
+
window.gtag('config', trackingId, {
|
|
6
|
+
page_path: url
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
// GA 3
|
|
10
|
+
if (window.ga) {
|
|
11
|
+
window.ga('send', 'pageview', url);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Addition to cart events
|
|
15
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
16
|
+
*/ const addToCart = (product)=>{
|
|
17
|
+
// GA 3
|
|
18
|
+
if (!window.ga || !product) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
window.ga('ec:addProduct', {
|
|
22
|
+
...product,
|
|
23
|
+
id: product.sku,
|
|
24
|
+
name: product.variant === 'Default Title' ? product.name : `${product.name} - ${product.variant}`,
|
|
25
|
+
variant: product.variant === 'Default Title' ? product.name : product.variant
|
|
26
|
+
});
|
|
27
|
+
window.ga('ec:setAction', 'add');
|
|
28
|
+
window.ga('send', 'event', {
|
|
29
|
+
eventCategory: 'EnhancedEcommerce',
|
|
30
|
+
eventAction: 'Added Product',
|
|
31
|
+
nonInteraction: true
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/** Product clicked event
|
|
35
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
|
|
36
|
+
*/ const productClick = (product)=>{
|
|
37
|
+
if (!window.ga) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
ga('ec:addProduct', {
|
|
41
|
+
id: product.id,
|
|
42
|
+
name: product.name,
|
|
43
|
+
category: product.category,
|
|
44
|
+
brand: product.brand,
|
|
45
|
+
variant: product.variant
|
|
46
|
+
});
|
|
47
|
+
ga('ec:setAction', 'click');
|
|
48
|
+
ga('send', 'event', {
|
|
49
|
+
eventAction: 'Click',
|
|
50
|
+
eventCategory: 'Product'
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/** Product viewed event
|
|
54
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
|
|
55
|
+
*/ const productDetail = (product)=>{
|
|
56
|
+
if (!product || !window.ga) return;
|
|
57
|
+
ga('ec:addProduct', {
|
|
58
|
+
brand: product.brand,
|
|
59
|
+
category: product.category,
|
|
60
|
+
id: product.id,
|
|
61
|
+
name: product.name,
|
|
62
|
+
variant: product.variant
|
|
63
|
+
});
|
|
64
|
+
ga('ec:setAction', 'detail');
|
|
65
|
+
ga('send', 'event', {
|
|
66
|
+
eventAction: 'Detail',
|
|
67
|
+
eventCategory: 'Ecommerce',
|
|
68
|
+
nonInteraction: 1
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/** Removal from cart events
|
|
72
|
+
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#add-remove-cart
|
|
73
|
+
*/ const removeFromCart = (product, price)=>{
|
|
74
|
+
if (!product || !window.ga) return;
|
|
75
|
+
ga('ec:addProduct', {
|
|
76
|
+
id: product.id,
|
|
77
|
+
name: product.name,
|
|
78
|
+
price
|
|
79
|
+
});
|
|
80
|
+
ga('ec:setAction', 'remove');
|
|
81
|
+
ga('send', 'event', {
|
|
82
|
+
eventAction: 'Click',
|
|
83
|
+
eventCategory: 'Remove from cart'
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { addToCart, pageview, productClick, productDetail, removeFromCart };
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const addToCart = (product)=>{
|
|
3
|
+
if (!window?.ttq?.track) return;
|
|
4
|
+
window.ttq.track('AddToCart', {
|
|
5
|
+
content_id: product.id,
|
|
6
|
+
content_type: 'product',
|
|
7
|
+
content_name: product.name,
|
|
8
|
+
quantity: product.quantity,
|
|
9
|
+
price: product.price,
|
|
10
|
+
value: (product.price ?? 0) * (product.quantity ?? 0),
|
|
11
|
+
currency: product.currency
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { addToCart };
|