@dropins/storefront-wishlist 0.2.2-alpha → 0.2.3-alpha
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/api/getProductBySku/graphql/getProductBySku.graphql.d.ts +1 -1
- package/api.js +1 -1
- package/chunks/WishlistItem.js +1 -1
- package/chunks/mergeWishlists.js +157 -129
- package/chunks/removeProductsFromWishlist.js +2 -2
- package/containers/Wishlist.js +1 -1
- package/containers/WishlistToggle.js +1 -1
- package/data/transforms/__fixtures__/productData.d.ts +2 -1
- package/lib/persisted-data.d.ts +4 -1
- package/lib/wishlist-item-comparator.d.ts +12 -0
- package/package.json +1 -1
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
* is strictly forbidden unless prior written permission is obtained
|
|
15
15
|
* from Adobe.
|
|
16
16
|
*******************************************************************/
|
|
17
|
-
export declare const GET_PRODUCT_BY_SKU
|
|
17
|
+
export declare const GET_PRODUCT_BY_SKU: string;
|
|
18
18
|
//# sourceMappingURL=getProductBySku.graphql.d.ts.map
|
package/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{W as _,t as h,b as c}from"./chunks/mergeWishlists.js";import{a as G,c as H,h as F,j as v,d as L,g as U,e as A,i as M,f as N,m as R,r as $}from"./chunks/mergeWishlists.js";import{s as l,g as u,f as n,h as I}from"./chunks/removeProductsFromWishlist.js";import{
|
|
3
|
+
import{W as _,t as h,b as c}from"./chunks/mergeWishlists.js";import{a as G,c as H,h as F,j as v,d as L,g as U,e as A,i as M,f as N,m as R,r as $}from"./chunks/mergeWishlists.js";import{s as l,g as u,f as n,h as I}from"./chunks/removeProductsFromWishlist.js";import{k as O,e as Q,l as b,c as B,r as C,a as Y,b as x,d as z,j}from"./chunks/removeProductsFromWishlist.js";import{events as m}from"@dropins/tools/event-bus.js";import"@dropins/tools/lib.js";import"@dropins/tools/fetch-graphql.js";const d=`
|
|
4
4
|
query GET_WISHLIST_BY_ID_QUERY(
|
|
5
5
|
$wishlistId: ID!,
|
|
6
6
|
) {
|
package/chunks/WishlistItem.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as t,Fragment as R,jsxs as f}from"@dropins/tools/preact-jsx-runtime.js";import{classes as
|
|
3
|
+
import{jsx as t,Fragment as R,jsxs as f}from"@dropins/tools/preact-jsx-runtime.js";import{classes as n}from"@dropins/tools/lib.js";import{Price as w,Button as L,Icon as U,Image as W}from"@dropins/tools/components.js";import{useState as $}from"@dropins/tools/preact-compat.js";import{s as h,r as B}from"./removeProductsFromWishlist.js";import{events as G}from"@dropins/tools/event-bus.js";import{a as M,S as j}from"./Trash.js";import{useText as z}from"@dropins/tools/i18n.js";const V=({taxes:e,displayMode:s})=>t(R,{children:e.map((r,c)=>f("div",{"data-testid":`wishlist-product-item-tax-${c}`,className:"wishlist-product-item-tax",children:[t("span",{className:"wishlist-product-item-tax-label",children:r.label}),t(w,{className:"wishlist-product-item-tax-price",amount:r.money.value,currency:r.money.currency}),t("span",{className:"wishlist-product-item-tax-display-mode",children:s==="INCLUDING_FPT_AND_DESCRIPTION"?"incl.":"excl."})]},c))}),q=({className:e,item:s,onCartActionButtonClick:r,onTrashButtonClick:c,fixedProductTaxesEnabled:p,fixedProductTaxesEnabledDisplayInProductLists:u,routeProdDetailPage:d,...o})=>{var l,i,v,x,P,I,N,y,T,_,b,g,S,E,C,A,O,F,k;const a=z({cartActionBtn:"ProductItem.CartActionButton",trashActionBtn:"ProductItem.TrashActionButton"}),m=((v=(i=(l=s.product)==null?void 0:l.prices)==null?void 0:i.discount)==null?void 0:v.amountOff)!==0||((I=(P=(x=s.product)==null?void 0:x.prices)==null?void 0:P.discount)==null?void 0:I.percentOff)!==0;return t("div",{...o,className:n(["wishlist-product-item",e]),children:f("div",{className:"wishlist-product-item__content",children:[t("a",{className:"wishlist-product-item-image","data-testid":"wishlist-product-item-image",href:d(s.product),children:t(K,{images:(N=s.product)!=null&&N.image?[s.product.image]:[]})}),f("div",{className:"wishlist-product-item__title","data-testid":"wishlist-product-item-header",children:[t("a",{className:"wishlist-product-item-name","data-testid":"wishlist-product-item-name",href:d(s.product),children:(y=s.product)==null?void 0:y.name}),t(L,{"data-testid":"wishlist-product-item-remove-button",className:"wishlist-product-item-button__remove",variant:"tertiary",onClick:()=>c==null?void 0:c(),icon:t(U,{source:M,size:"24",stroke:"2",viewBox:"0 0 24 24","aria-label":a.trashActionBtn})}),t(w,{className:n(["wishlist-product-item-price",m?"strikeout":""]),"data-testid":"wishlist-product-item-price",amount:(_=(T=s.product)==null?void 0:T.prices)==null?void 0:_.regularPrice.value,currency:(g=(b=s.product)==null?void 0:b.prices)==null?void 0:g.regularPrice.currency}),m&&t(w,{className:"wishlist-product-item-discounted-price","data-testid":"wishlist-product-item-discounted-price",amount:(E=(S=s.product)==null?void 0:S.prices)==null?void 0:E.finalPrice.value,currency:(A=(C=s.product)==null?void 0:C.prices)==null?void 0:A.finalPrice.currency}),p&&(u==="INCLUDING_FPT_AND_DESCRIPTION"||u==="EXCLUDING_FPT_INCLUDING_DESCRIPTION_FINAL_PRICE")&&((F=(O=s.product)==null?void 0:O.prices)==null?void 0:F.fixedProductTaxes)&&t(V,{taxes:s.product.prices.fixedProductTaxes,displayMode:u})]}),t(L,{"data-testid":"wishlist-product-item-move-to-cart-button",size:"medium",type:"submit",icon:t(U,{source:j}),disabled:((k=s.product)==null?void 0:k.stockStatus)!=="IN_STOCK","aria-label":a.cartActionBtn,onClick:()=>r==null?void 0:r(),children:a.cartActionBtn})]})})},K=({className:e,children:s,images:r,...c})=>{const[p,u]=$(0);return f(R,{children:[t("div",{...c,className:n(["image-carousel",e]),children:t("div",{className:n(["overflow-hidden relative max-w-[200px]",e]),children:r==null?void 0:r.map((d,o)=>o===p&&t(W,{className:"image-carousel-image",alt:d.alt,src:d.src}))})}),(r==null?void 0:r.length)>1&&t("div",{className:n(["absolute","image-switcher-area"]),children:r==null?void 0:r.map((d,o)=>t("span",{className:n(["image-switcher",p===o?"image-switcher-active":"image-switcher-inactive"]),onClick:a=>{u(o),a.stopPropagation()}},o))})]})},te=({initialData:e=null,moveProdToCart:s,routeProdDetailPage:r})=>{var u,d,o,a,m;if(!(e!=null&&e.product))return null;const c=async(l=!0)=>{try{return await B([e]),console.log(`Product ${e.product.sku} removed from wishlist!`),l&&G.emit("wishlist/alert",{action:"remove",item:e}),!0}catch(i){return console.error(`Product ${e.product.sku} could not be removed from wishlist`,i),!1}};return t(q,{item:e,onCartActionButtonClick:async()=>{var l;try{return await s([{sku:e.product.sku,quantity:1,optionsUIDs:(l=e.selectedOptions)==null?void 0:l.map(i=>i.uid),enteredOptions:e.enteredOptions}]),console.log(`Product ${e.product.sku} successfully moved to cart 🛒`),G.emit("wishlist/alert",{action:"move",item:e}),await c(!1)}catch(i){return console.error("Could not move product to cart: ",i),i.toString().includes("You need to choose options for your item.")&&(sessionStorage.setItem("incompleteProduct",e.product.sku),window.location.replace(r(e.product))),!1}},onTrashButtonClick:c,fixedProductTaxesEnabled:((u=h.config)==null?void 0:u.fixedProductTaxesEnabled)??!1,fixedProductTaxesApply:((d=h.config)==null?void 0:d.fixedProductTaxesApply)??!1,fixedProductTaxesEnabledDisplayInProductLists:(o=h.config)==null?void 0:o.fixedProductTaxesEnabledDisplayInProductLists,fixedProductTaxesEnabledDisplayInProductView:(a=h.config)==null?void 0:a.fixedProductTaxesEnabledDisplayInProductView,fixedProductTaxesEnabledDisplayInSalesModules:(m=h.config)==null?void 0:m.fixedProductTaxesEnabledDisplayInSalesModules,routeProdDetailPage:r})};export{te as W};
|
package/chunks/mergeWishlists.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{Initializer as
|
|
3
|
+
import{Initializer as D}from"@dropins/tools/lib.js";import{events as c}from"@dropins/tools/event-bus.js";import{s as o,j as O,f as E,h as b,g as y,i as R,k as G}from"./removeProductsFromWishlist.js";const N=new D({init:async e=>{const t={isGuestWishlistEnabled:!1,...e};N.config.setConfig(t),P().catch(console.error)},listeners:()=>[c.on("authenticated",async e=>{if(o.authenticated&&!e&&c.emit("wishlist/reset",void 0),e&&!o.authenticated){o.authenticated=e;const t=await P().catch(console.error);t&&le(t)}},{eager:!0}),c.on("wishlist/data",e=>{O(e)}),c.on("wishlist/reset",()=>{oe().catch(console.error),c.emit("wishlist/data",null)})]}),pe=N.config;function v(e){if(!e)return null;const t=i=>{switch(i){case 1:return"INCLUDING_FPT_AND_DESCRIPTION";case 2:return"EXCLUDING_FPT_INCLUDING_DESCRIPTION_FINAL_PRICE";case 3:return"EXCLUDING_FPT";default:return"INCLUDING_FPT_ONLY"}};return{wishlistIsEnabled:e.storeConfig.magento_wishlist_general_is_enabled,wishlistMultipleListIsEnabled:e.storeConfig.enable_multiple_wishlists,wishlistMaxNumber:e.storeConfig.maximum_number_of_wishlists,fixedProductTaxesEnabled:e.storeConfig.fixed_product_taxes_enable,fixedProductTaxesApply:e.storeConfig.fixed_product_taxes_apply_tax_to_fpt,fixedProductTaxesEnabledDisplayInProductLists:t(e.storeConfig.fixed_product_taxes_display_prices_in_product_lists),fixedProductTaxesEnabledDisplayInSalesModules:t(e.storeConfig.fixed_product_taxes_display_prices_in_sales_modules),fixedProductTaxesEnabledDisplayInProductView:t(e.storeConfig.fixed_product_taxes_display_prices_on_product_view_page)}}function w(e){var t,i;return e?{type:e.__typename,name:e.name,sku:e.sku,uid:e.uid,image:M(e),stockStatus:e.stock_status,canonicalUrl:e.canonical_url,urlKey:e.url_key,categories:(t=e.categories)==null?void 0:t.map(s=>s.name),prices:U(e),productAttributes:W(e),options:e.gift_card_options?(i=e.gift_card_options)==null?void 0:i.map(s=>({uid:s.uid,required:s.required,title:s.title})):[]}:null}function M(e){var t,i;return{src:(t=e.thumbnail)==null?void 0:t.url,alt:(i=e.thumbnail)==null?void 0:i.label}}function U(e){var t,i,s,n,r,a,p,u,l,_,d,m,f,I,h,T,g,S;return{regularPrice:{currency:((s=(i=(t=e.price_range)==null?void 0:t.minimum_price)==null?void 0:i.regular_price)==null?void 0:s.currency)??"USD",value:((a=(r=(n=e.price_range)==null?void 0:n.minimum_price)==null?void 0:r.regular_price)==null?void 0:a.value)??0},finalPrice:{currency:((l=(u=(p=e.price_range)==null?void 0:p.minimum_price)==null?void 0:u.final_price)==null?void 0:l.currency)??"USD",value:((m=(d=(_=e.price_range)==null?void 0:_.minimum_price)==null?void 0:d.final_price)==null?void 0:m.value)??0},discount:{amountOff:((h=(I=(f=e.price_range)==null?void 0:f.minimum_price)==null?void 0:I.discount)==null?void 0:h.amount_off)??0,percentOff:((S=(g=(T=e.price_range)==null?void 0:T.minimum_price)==null?void 0:g.discount)==null?void 0:S.percent_off)??0},fixedProductTaxes:F(e)}}function W(e){var t,i;return(i=(t=e.custom_attributesV2)==null?void 0:t.items)==null?void 0:i.map(s=>{const n=s.code.split("_").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ");return{...s,code:n}})}function F(e){var t,i,s,n,r;return(i=(t=e.price_range)==null?void 0:t.minimum_price)!=null&&i.fixed_product_taxes?(r=(n=(s=e.price_range)==null?void 0:s.minimum_price)==null?void 0:n.fixed_product_taxes)==null?void 0:r.map(a=>({money:{value:a.amount.value,currency:a.amount.currency},label:a.label})):[]}function x(e,t){return e?{id:e.id,updated_at:e.updated_at,sharing_code:e.sharing_code,items_count:e.items_count,items:L(e,t??[])}:null}function L(e,t){var i,s;return(s=(i=e==null?void 0:e.items_v2)==null?void 0:i.items)!=null&&s.length?e.items_v2.items.map(n=>({id:n.id,quantity:n.quantity,description:n.description,added_at:n.added_at,enteredOptions:t,selectedOptions:n.configurable_options?n.configurable_options.map(r=>({value:r.value_label,label:r.option_label,uid:r.configurable_product_option_value_uid})):[],product:w(n.product)})):[]}const k=`
|
|
4
4
|
query STORE_CONFIG_QUERY {
|
|
5
5
|
storeConfig {
|
|
6
6
|
magento_wishlist_general_is_enabled
|
|
@@ -13,91 +13,7 @@ query STORE_CONFIG_QUERY {
|
|
|
13
13
|
fixed_product_taxes_display_prices_on_product_view_page
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
query GET_PRODUCT_BY_SKU($sku: String!) {
|
|
18
|
-
products(filter: { sku: { eq: $sku } }) {
|
|
19
|
-
items {
|
|
20
|
-
__typename
|
|
21
|
-
sku
|
|
22
|
-
name
|
|
23
|
-
thumbnail {
|
|
24
|
-
label
|
|
25
|
-
url
|
|
26
|
-
}
|
|
27
|
-
price_range {
|
|
28
|
-
minimum_price {
|
|
29
|
-
regular_price {
|
|
30
|
-
currency
|
|
31
|
-
value
|
|
32
|
-
}
|
|
33
|
-
final_price {
|
|
34
|
-
currency
|
|
35
|
-
value
|
|
36
|
-
}
|
|
37
|
-
discount {
|
|
38
|
-
amount_off
|
|
39
|
-
percent_off
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
stock_status
|
|
44
|
-
... on SimpleProduct {
|
|
45
|
-
stock_status
|
|
46
|
-
options {
|
|
47
|
-
uid
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
... on ConfigurableProduct {
|
|
51
|
-
configurable_options {
|
|
52
|
-
uid
|
|
53
|
-
attribute_uid
|
|
54
|
-
attribute_code
|
|
55
|
-
values {
|
|
56
|
-
uid
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
variants {
|
|
60
|
-
product {
|
|
61
|
-
sku
|
|
62
|
-
stock_status
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
... on GiftCardProduct {
|
|
67
|
-
giftcard_type
|
|
68
|
-
giftcard_amounts {
|
|
69
|
-
uid
|
|
70
|
-
website_id
|
|
71
|
-
value
|
|
72
|
-
attribute_id
|
|
73
|
-
website_value
|
|
74
|
-
}
|
|
75
|
-
gift_card_options {
|
|
76
|
-
title
|
|
77
|
-
required
|
|
78
|
-
uid
|
|
79
|
-
... on CustomizableFieldOption {
|
|
80
|
-
value: value {
|
|
81
|
-
uid
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
... on BundleProduct {
|
|
87
|
-
items {
|
|
88
|
-
uid
|
|
89
|
-
title
|
|
90
|
-
options {
|
|
91
|
-
uid
|
|
92
|
-
label
|
|
93
|
-
quantity
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
`,q=async e=>{if(!e)throw Error("Product SKU is not set");return b(L,{variables:{sku:e}}).then(({errors:t,data:i})=>{var s;return t?E(t):(s=i==null?void 0:i.products)!=null&&s.items?P(i.products.items[0]):null})},$=`
|
|
16
|
+
`,$=async()=>E(k,{method:"GET",cache:"force-cache"}).then(({errors:e,data:t})=>e?b(e):v(t)),q=`
|
|
101
17
|
fragment PRICE_RANGE_FRAGMENT on PriceRange {
|
|
102
18
|
minimum_price {
|
|
103
19
|
regular_price {
|
|
@@ -142,11 +58,12 @@ query STORE_CONFIG_QUERY {
|
|
|
142
58
|
}
|
|
143
59
|
}
|
|
144
60
|
}
|
|
145
|
-
`,
|
|
61
|
+
`,C=`
|
|
146
62
|
fragment PRODUCT_FRAGMENT on ProductInterface {
|
|
147
|
-
|
|
148
|
-
sku
|
|
63
|
+
__typename
|
|
149
64
|
uid
|
|
65
|
+
sku
|
|
66
|
+
name
|
|
150
67
|
thumbnail {
|
|
151
68
|
url
|
|
152
69
|
label
|
|
@@ -178,8 +95,87 @@ query STORE_CONFIG_QUERY {
|
|
|
178
95
|
}
|
|
179
96
|
}
|
|
180
97
|
|
|
181
|
-
${
|
|
98
|
+
${q}
|
|
182
99
|
`,H=`
|
|
100
|
+
... on SimpleProduct {
|
|
101
|
+
options {
|
|
102
|
+
uid
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
`,B=`
|
|
106
|
+
... on ConfigurableProduct {
|
|
107
|
+
configurable_options {
|
|
108
|
+
uid
|
|
109
|
+
attribute_uid
|
|
110
|
+
attribute_code
|
|
111
|
+
values {
|
|
112
|
+
uid
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
variants {
|
|
116
|
+
product {
|
|
117
|
+
sku
|
|
118
|
+
stock_status
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
`,z=`
|
|
123
|
+
... on DownloadableProduct {
|
|
124
|
+
image {
|
|
125
|
+
label
|
|
126
|
+
url
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
`,Y=`
|
|
130
|
+
... on GiftCardProduct {
|
|
131
|
+
giftcard_type
|
|
132
|
+
giftcard_amounts {
|
|
133
|
+
uid
|
|
134
|
+
website_id
|
|
135
|
+
value
|
|
136
|
+
attribute_id
|
|
137
|
+
website_value
|
|
138
|
+
}
|
|
139
|
+
gift_card_options {
|
|
140
|
+
title
|
|
141
|
+
required
|
|
142
|
+
uid
|
|
143
|
+
... on CustomizableFieldOption {
|
|
144
|
+
value: value {
|
|
145
|
+
uid
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
`,Q=`
|
|
151
|
+
... on BundleProduct {
|
|
152
|
+
items {
|
|
153
|
+
uid
|
|
154
|
+
required
|
|
155
|
+
title
|
|
156
|
+
options {
|
|
157
|
+
uid
|
|
158
|
+
label
|
|
159
|
+
quantity
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
`,K=`
|
|
164
|
+
query GET_PRODUCT_BY_SKU($sku: String!) {
|
|
165
|
+
products(filter: { sku: { eq: $sku } }) {
|
|
166
|
+
items {
|
|
167
|
+
...PRODUCT_FRAGMENT
|
|
168
|
+
${H}
|
|
169
|
+
${B}
|
|
170
|
+
${z}
|
|
171
|
+
${Y}
|
|
172
|
+
${Q}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
${C}
|
|
178
|
+
`,V=async e=>{if(!e)throw Error("Product SKU is not set");return E(K,{variables:{sku:e}}).then(({errors:t,data:i})=>{var s;return t?b(t):(s=i==null?void 0:i.products)!=null&&s.items?w(i.products.items[0]):null})},j=`
|
|
183
179
|
fragment CUSTOMIZABLE_OPTIONS_FRAGMENT on SelectedCustomizableOption {
|
|
184
180
|
type
|
|
185
181
|
customizable_option_uid
|
|
@@ -195,7 +191,64 @@ ${$}
|
|
|
195
191
|
}
|
|
196
192
|
}
|
|
197
193
|
}
|
|
198
|
-
`,
|
|
194
|
+
`,Z=`
|
|
195
|
+
... on ConfigurableWishlistItem {
|
|
196
|
+
configurable_options {
|
|
197
|
+
option_label
|
|
198
|
+
value_label
|
|
199
|
+
configurable_product_option_value_uid
|
|
200
|
+
configurable_product_option_uid
|
|
201
|
+
}
|
|
202
|
+
configured_variant {
|
|
203
|
+
canonical_url
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
`,X=`
|
|
207
|
+
... on DownloadableWishlistItem {
|
|
208
|
+
added_at
|
|
209
|
+
description
|
|
210
|
+
links_v2 {
|
|
211
|
+
sample_url
|
|
212
|
+
sort_order
|
|
213
|
+
title
|
|
214
|
+
uid
|
|
215
|
+
}
|
|
216
|
+
quantity
|
|
217
|
+
}
|
|
218
|
+
`,J=`
|
|
219
|
+
... on GiftCardWishlistItem {
|
|
220
|
+
added_at
|
|
221
|
+
description
|
|
222
|
+
gift_card_options {
|
|
223
|
+
amount {
|
|
224
|
+
value
|
|
225
|
+
currency
|
|
226
|
+
}
|
|
227
|
+
custom_giftcard_amount {
|
|
228
|
+
value
|
|
229
|
+
currency
|
|
230
|
+
}
|
|
231
|
+
message
|
|
232
|
+
recipient_email
|
|
233
|
+
recipient_name
|
|
234
|
+
sender_email
|
|
235
|
+
sender_name
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
`,ee=`
|
|
239
|
+
... on BundleWishlistItem {
|
|
240
|
+
bundle_options {
|
|
241
|
+
label
|
|
242
|
+
type
|
|
243
|
+
uid
|
|
244
|
+
values {
|
|
245
|
+
uid
|
|
246
|
+
label
|
|
247
|
+
quantity
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
`,te=`
|
|
199
252
|
fragment WISHLIST_ITEM_FRAGMENT on WishlistItemInterface {
|
|
200
253
|
__typename
|
|
201
254
|
id
|
|
@@ -205,43 +258,18 @@ fragment WISHLIST_ITEM_FRAGMENT on WishlistItemInterface {
|
|
|
205
258
|
product {
|
|
206
259
|
...PRODUCT_FRAGMENT
|
|
207
260
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
configurable_product_option_uid
|
|
213
|
-
}
|
|
214
|
-
configured_variant {
|
|
215
|
-
canonical_url
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
... on GiftCardWishlistItem {
|
|
219
|
-
added_at
|
|
220
|
-
description
|
|
221
|
-
gift_card_options {
|
|
222
|
-
amount {
|
|
223
|
-
value
|
|
224
|
-
currency
|
|
225
|
-
}
|
|
226
|
-
custom_giftcard_amount {
|
|
227
|
-
value
|
|
228
|
-
currency
|
|
229
|
-
}
|
|
230
|
-
message
|
|
231
|
-
recipient_email
|
|
232
|
-
recipient_name
|
|
233
|
-
sender_email
|
|
234
|
-
sender_name
|
|
235
|
-
}
|
|
236
|
-
}
|
|
261
|
+
${Z}
|
|
262
|
+
${X}
|
|
263
|
+
${J}
|
|
264
|
+
${ee}
|
|
237
265
|
customizable_options {
|
|
238
266
|
...CUSTOMIZABLE_OPTIONS_FRAGMENT
|
|
239
267
|
}
|
|
240
268
|
}
|
|
241
269
|
|
|
242
|
-
${
|
|
243
|
-
${
|
|
244
|
-
`,
|
|
270
|
+
${C}
|
|
271
|
+
${j}
|
|
272
|
+
`,A=`
|
|
245
273
|
fragment WISHLIST_FRAGMENT on Wishlist {
|
|
246
274
|
id
|
|
247
275
|
updated_at
|
|
@@ -254,8 +282,8 @@ fragment WISHLIST_FRAGMENT on Wishlist {
|
|
|
254
282
|
}
|
|
255
283
|
}
|
|
256
284
|
|
|
257
|
-
${
|
|
258
|
-
`,
|
|
285
|
+
${te}
|
|
286
|
+
`,ie=`
|
|
259
287
|
query GET_WISHLISTS_QUERY {
|
|
260
288
|
customer {
|
|
261
289
|
wishlists {
|
|
@@ -264,8 +292,8 @@ ${B}
|
|
|
264
292
|
}
|
|
265
293
|
}
|
|
266
294
|
|
|
267
|
-
${
|
|
268
|
-
`,
|
|
295
|
+
${A}
|
|
296
|
+
`,se=async()=>o.authenticated?E(ie).then(({errors:e,data:t})=>{var i;return e?b(e):(i=t==null?void 0:t.customer)!=null&&i.wishlists?t.customer.wishlists.map(s=>x(s)):null}):y(),ne=`
|
|
269
297
|
mutation ADD_PRODUCTS_TO_WISHLIST_MUTATION(
|
|
270
298
|
$wishlistId: ID!,
|
|
271
299
|
$wishlistItems: [WishlistItemInput!]!,
|
|
@@ -283,5 +311,5 @@ ${B}
|
|
|
283
311
|
}
|
|
284
312
|
}
|
|
285
313
|
}
|
|
286
|
-
${
|
|
287
|
-
`,
|
|
314
|
+
${A}
|
|
315
|
+
`,re=async e=>{var s,n,r,a,p;if(!e)return null;const t=y();let i={id:(t==null?void 0:t.id)??"",updated_at:"",sharing_code:"",items_count:0,items:(t==null?void 0:t.items)??[]};for(const u of e){if((s=t.items)==null?void 0:s.some(d=>R(d,{sku:u.sku,optionUIDs:u.optionsUIDs})))continue;const _=await V(u.sku);_&&(i.items=[...i.items,{quantity:u.quantity,selectedOptions:u.optionsUIDs?(n=u.optionsUIDs)==null?void 0:n.map(d=>({uid:d})):[],enteredOptions:[],product:_}])}if(i.items_count=(r=i.items)==null?void 0:r.length,c.emit("wishlist/data",i),o.authenticated){if(!o.wishlistId)throw c.emit("wishlist/data",t),Error("Wishlist ID is not set");const u={wishlistId:o.wishlistId,wishlistItems:e.map(({sku:f,parentSku:I,quantity:h,optionsUIDs:T,enteredOptions:g})=>({sku:f,parent_sku:I,quantity:h,selected_options:T,entered_options:g}))},{errors:l,data:_}=await E(ne,{variables:u}),d=[...((a=_==null?void 0:_.addProductsToWishlist)==null?void 0:a.user_errors)??[],...l??[]];if(d.length>0)return c.emit("wishlist/data",t),b(d);const m=x(_.addProductsToWishlist.wishlist,((p=e[0])==null?void 0:p.enteredOptions)??[]);c.emit("wishlist/data",m)}return null},oe=()=>(o.wishlistId=null,o.authenticated=!1,Promise.resolve(null)),P=async()=>{if(o.initializing)return null;o.initializing=!0,o.config||(o.config=await $());const e=o.authenticated?await ue():await ae();return c.emit("wishlist/initialized",e),c.emit("wishlist/data",e),o.initializing=!1,e};async function ue(){const e=await se(),t=e?e[0]:null;return t?(o.wishlistId=t.id,t):null}async function ae(){try{return await y()}catch(e){throw console.error(e),e}}const le=async e=>{var n;if(!e)return null;const t=y(!0),i=[];if((n=t==null?void 0:t.items)==null||n.forEach(r=>{var u;const a=((u=r.selectedOptions)==null?void 0:u.map(l=>l.uid))||[];if(!e.items.some(l=>R(l,{sku:r.product.sku,optionUIDs:a}))){const l={sku:r.product.sku,quantity:1,optionsUIDs:a,enteredOptions:r.enteredOptions||void 0};i.push(l)}}),i.length===0)return null;const s=await re(i);return G(),s};export{te as W,re as a,A as b,pe as c,V as d,se as e,P as f,$ as g,ue as h,N as i,ae as j,le as m,oe as r,x as t};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{events as
|
|
3
|
+
import{events as u}from"@dropins/tools/event-bus.js";import{FetchGraphQL as S}from"@dropins/tools/fetch-graphql.js";function g(s){const e=document.cookie.split(";");for(const t of e)if(t.trim().startsWith(`${s}=`))return t.trim().substring(s.length+1);return null}const f={wishlistId:null,authenticated:!1,isLoading:!0},n=new Proxy(f,{set(s,e,t){if(s[e]=t,e==="wishlistId"){if(t===n.wishlistId)return!0;if(t===null)return document.cookie="DROPIN__WISHLIST__WISHLIST-ID=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/",!0;const r=new Date;r.setDate(r.getDate()+30),document.cookie=`DROPIN__WISHLIST__WISHLIST-ID=${t}; expires=${r.toUTCString()}; path=/`}return Reflect.set(s,e,t)},get(s,e){return e==="wishlistId"?g("DROPIN__WISHLIST__WISHLIST-ID"):s[e]}});function d(s,e){var i;if(s.product.sku!==e.sku)return!1;const t=((i=s.selectedOptions)==null?void 0:i.map(o=>o.uid).sort())||[],r=(e.optionUIDs||[]).sort();return JSON.stringify(t)===JSON.stringify(r)}const c="DROPIN__WISHLIST__WISHLIST__DATA";function E(s){const e=n.authenticated?sessionStorage:localStorage;if(s)try{e.setItem(c,JSON.stringify(s))}catch(t){p(t)?console.error("Storage quota exceeded:",t):console.error("Error saving wishlist:",t)}else e.removeItem(c)}const p=s=>s instanceof DOMException&&s.name==="QuotaExceededError";function _(s=!1){const e=n.authenticated&&!s?sessionStorage:localStorage;try{const t=e.getItem(c);return t?JSON.parse(t):{id:"",items:[]}}catch(t){return console.error("Error retrieving wishlist:",t),{id:"",items:[]}}}function H(){localStorage.removeItem(c)}function L(s,e=[],t=[]){var o;const r=n.authenticated?sessionStorage:localStorage,i=r.getItem(c)?JSON.parse(r.getItem(c)):{items:[]};return(o=i==null?void 0:i.items)==null?void 0:o.find(l=>d(l,{sku:s,optionUIDs:e}))}const{setEndpoint:P,setFetchGraphQlHeader:F,removeFetchGraphQlHeader:R,setFetchGraphQlHeaders:M,fetchGraphQl:w,getConfig:N}=new S().getMethods(),O=s=>{const e=s.map(t=>t.message).join(" ");throw Error(e)},D=`
|
|
4
4
|
mutation REMOVE_PRODUCTS_FROM_WISHLIST_MUTATION(
|
|
5
5
|
$wishlistId: ID!,
|
|
6
6
|
$wishlistItemsIds: [ID!]!,
|
|
@@ -15,4 +15,4 @@ import{events as d}from"@dropins/tools/event-bus.js";import{FetchGraphQL as m}fr
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
`,$=async s=>{var r,i,o;const e=_(),t={...e,items:(r=e.items)==null?void 0:r.filter(l=>!s.some(I=>{var a;return d(l,{sku:I.product.sku,optionUIDs:(a=I.selectedOptions)==null?void 0:a.map(h=>h.uid)})}))};if(t.items_count=(i=t.items)==null?void 0:i.length,u.emit("wishlist/data",t),n.authenticated){if(!n.wishlistId)throw Error("Wishlist ID is not set");const l=s.map(m=>m.id),{errors:I,data:a}=await w(D,{variables:{wishlistId:n.wishlistId,wishlistItemsIds:l}}),h=[...((o=a==null?void 0:a.removeProductsFromWishlist)==null?void 0:o.user_errors)??[],...I??[]];return h.length>0?(u.emit("wishlist/data",e),O(h)):null}return null};export{P as a,F as b,R as c,M as d,N as e,w as f,_ as g,O as h,d as i,E as j,H as k,L as l,$ as r,n as s};
|
package/containers/Wishlist.js
CHANGED
|
@@ -14,4 +14,4 @@ import{jsx as i,jsxs as d,Fragment as H}from"@dropins/tools/preact-jsx-runtime.j
|
|
|
14
14
|
<rect x="6" y="556" width="132" height="22" rx="4" fill="#E8E8E8" />
|
|
15
15
|
<rect x="6" y="592" width="280" height="48" rx="24" fill="#D9D9D9" />
|
|
16
16
|
</svg>
|
|
17
|
-
`}),Q=()=>d(q,{"data-testid":"wishlist-loader",children:[i(S,{}),i(S,{}),i(S,{})]}),hi=({routeEmptyWishlistCTA:l,routeToWishlist:s,moveProdToCart:e,routeProdDetailPage:c,...r})=>{const[f,m]=w(null),[v,N]=w(b.authenticated),[L,g]=w(b.isLoading),_=n=>N(n),[p,a]=w(null),W=j(n=>{const{action:o,item:h}=n;a(i(J,{action:o,item:h}))},[s]);return F(()=>{const n=I.on("authenticated",_),o=I.on("wishlist/alert",t=>W(t)),h=I.on("wishlist/data",t=>{m(t),g(!1)});return()=>{n==null||n.off(),h==null||h.off(),o==null||o.off()}},[W]),i(U,{...r,wishlistData:f,wishlistAlert:p,routeEmptyWishlistCTA:l,moveProdToCart:e,isLoggedIn:v,isLoading:L,routeProdDetailPage:c})},U=({className:l,wishlistData:s,wishlistAlert:e,isLoggedIn:c,isLoading:r,moveProdToCart:f,routeEmptyWishlistCTA:m,onLoginClick:v,routeProdDetailPage:N
|
|
17
|
+
`}),Q=()=>d(q,{"data-testid":"wishlist-loader",children:[i(S,{}),i(S,{}),i(S,{})]}),hi=({routeEmptyWishlistCTA:l,routeToWishlist:s,moveProdToCart:e,routeProdDetailPage:c,...r})=>{const[f,m]=w(null),[v,N]=w(b.authenticated),[L,g]=w(b.isLoading),_=n=>N(n),[p,a]=w(null),W=j(n=>{const{action:o,item:h}=n;a(i(J,{action:o,item:h}))},[s]);return F(()=>{const n=I.on("authenticated",_),o=I.on("wishlist/alert",t=>W(t)),h=I.on("wishlist/data",t=>{m(t),g(!1)});return()=>{n==null||n.off(),h==null||h.off(),o==null||o.off()}},[W]),i(U,{...r,wishlistData:f,wishlistAlert:p,routeEmptyWishlistCTA:l,moveProdToCart:e,isLoggedIn:v,isLoading:L,routeProdDetailPage:c})},U=({className:l,wishlistData:s,wishlistAlert:e,isLoggedIn:c,isLoading:r,moveProdToCart:f,routeEmptyWishlistCTA:m,onLoginClick:v,routeProdDetailPage:N,...L})=>{const[g,_]=w(e),p=$({wishlistHeading:"Wishlist.Wishlist.heading",wishlistLoadingHeading:"Wishlist.Wishlist.loading"}),a=k(()=>{var t;return((t=s==null?void 0:s.items)==null?void 0:t.length)>0?s.items.map(x=>{var u;return i(G,{initialData:x,moveProdToCart:f,routeProdDetailPage:N},(u=x.product)==null?void 0:u.sku)}):null},[s,f]);F(()=>{if(e){_(e);const t=setTimeout(()=>{_(null)},5e3);return()=>clearTimeout(t)}},[e]);const W=k(()=>g?i(R,{node:g,className:"wishlist-wishlist__alert"}):null,[g]),n=()=>d(H,{children:[i("div",{className:"wishlist-wishlist__heading","data-testid":"wishlist-heading-wrapper",children:i("div",{className:"wishlist-wishlist__heading-text","data-testid":"loader-wishlist-heading",children:p.wishlistLoadingHeading})}),i(Q,{})]}),o=()=>a?d(H,{children:[h,i("div",{className:"wishlist-wishlist__content",children:a})]}):i("div",{className:y(["wishlist-wishlist__content","wishlist-wishlist__content--empty"]),children:d("div",{children:[i(O,{"data-testid":"empty-wishlist",ctaLinkURL:m==null?void 0:m()}),!c&&i(X,{onLoginClick:v})]})}),h=k(()=>{var t;return a?i("div",{className:"wishlist-wishlist__heading","data-testid":"wishlist-heading-wrapper",children:i("div",{className:"wishlist-wishlist__heading-text","data-testid":"default-wishlist-heading",children:(t=p.wishlistHeading)==null?void 0:t.split(" {count}").map((x,u)=>{var E;return d(B,{children:[x,u===0&&i("span",{className:"wishlist-wishlist__heading-count","data-testid":"wishlist-heading-count",children:`${s==null?void 0:s.items_count} products`})]},((E=s==null?void 0:s.id)==null?void 0:E.toString())+u)})})}):null},[p,a,s]);return d("div",{...L,className:y(["wishlist-wishlist",l]),children:[W,r?n():o()]})},X=({onLoginClick:l})=>d("div",{className:"wishlist-login__sign-in",children:[i("a",{"data-testid":"log-in-link",className:"wishlist-login__link",href:"",rel:"noreferrer",onClick:l,role:"button",children:i(M,{id:"Wishlist.Login.logIn"})}),i(M,{id:"Wishlist.Login.sync"})]});export{hi as Wishlist,hi as default};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as
|
|
3
|
+
import{jsx as n}from"@dropins/tools/preact-jsx-runtime.js";import{useState as l,useEffect as P}from"@dropins/tools/preact-compat.js";import{Button as x,Icon as d}from"@dropins/tools/components.js";import{events as o}from"@dropins/tools/event-bus.js";import{s as E,g as F,i as H,r as L}from"../chunks/removeProductsFromWishlist.js";import{c as T,a as b}from"../chunks/mergeWishlists.js";import{S as j}from"../chunks/HeartFilled.js";import{S as q}from"../chunks/Heart.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const R=({product:t,iconWishlisted:u,iconToWishlist:f,size:g,variant:I,disabled:v,labelToWishlist:p,labelWishlisted:W,onClick:k})=>{const[w,D]=l(E.authenticated),[r,a]=l(!1),[m,S]=l(null),{isGuestWishlistEnabled:U}=T.getConfig();P(()=>{const e=s=>D(s),i=()=>{var h;const s=F(),c=(h=s==null?void 0:s.items)==null?void 0:h.find(y=>H(y,{sku:t.sku,optionUIDs:t.optionUIDs}));S(c??null),a(!!c)};o.on("authenticated",e),o.on("wishlist/data",i)},[t.optionUIDs,t.sku]);const C=async()=>{var e;r?(await L([m]),a(!1),o.emit("wishlist/alert",{action:"remove",item:m})):(await b([{sku:t.sku,quantity:1,optionsUIDs:t.optionUIDs??void 0,enteredOptions:(e=t.options)!=null&&e.items?t.options.items.filter(i=>i.selected).map(i=>({uid:i.uid,value:i.value})):void 0}]),a(!0),o.emit("wishlist/alert",{action:"add",item:{product:t}}))};return!w&&!U?null:n(x,{active:r,"data-testid":"wishlist-toggle",size:g??"medium",variant:I??"tertiary",disabled:v,icon:n(d,{source:f??q}),activeIcon:n(d,{source:u??j}),onClick:k??C,children:p,activeChildren:W})};export{R as WishlistToggle,R as default};
|
|
@@ -2,5 +2,6 @@ import { Product } from '../../models/product';
|
|
|
2
2
|
|
|
3
3
|
declare const product: Product;
|
|
4
4
|
declare const productOutOfStock: Product;
|
|
5
|
-
|
|
5
|
+
declare const configurableProduct: Product;
|
|
6
|
+
export { product, productOutOfStock, configurableProduct };
|
|
6
7
|
//# sourceMappingURL=productData.d.ts.map
|
package/lib/persisted-data.d.ts
CHANGED
|
@@ -3,5 +3,8 @@ import { Wishlist } from '../data/models';
|
|
|
3
3
|
export declare function setPersistedWishlistData(data: Wishlist | null): void;
|
|
4
4
|
export declare function getPersistedWishlistData(guest?: boolean): Wishlist | {};
|
|
5
5
|
export declare function clearPersistedLocalStorage(): void;
|
|
6
|
-
export declare function getWishlistItemFromStorage(productSku: string
|
|
6
|
+
export declare function getWishlistItemFromStorage(productSku: string, optionUIDs?: string[], enteredOptions?: {
|
|
7
|
+
uid: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[]): any;
|
|
7
10
|
//# sourceMappingURL=persisted-data.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Item } from '../data/models/wishlist';
|
|
2
|
+
|
|
3
|
+
interface ProductLike {
|
|
4
|
+
sku: string;
|
|
5
|
+
optionUIDs?: string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Helper function to compare wishlist items by their SKU and selected options
|
|
9
|
+
*/
|
|
10
|
+
export declare function isMatchingWishlistItem(wishlistItem: Item, product: ProductLike): boolean;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=wishlist-item-comparator.d.ts.map
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-wishlist", "version": "0.2.
|
|
1
|
+
{"name": "@dropins/storefront-wishlist", "version": "0.2.3-alpha", "@dropins/tools": "~1.0.0", "license": "SEE LICENSE IN LICENSE.md"}
|