@dropins/storefront-wishlist 1.0.0-beta2 → 1.0.0-beta3
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/addProductsToWishlist/addProductsToWishlist.d.ts +0 -1
- package/chunks/mergeWishlists.js +5 -5
- package/containers/Wishlist.js +1 -1
- package/containers/WishlistToggle/WishlistToggle.d.ts +4 -0
- package/containers/WishlistToggle.js +1 -1
- package/data/models/product.d.ts +1 -0
- package/package.json +1 -1
package/chunks/mergeWishlists.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{Initializer as D}from"@dropins/tools/lib.js";import{events as c}from"@dropins/tools/event-bus.js";import{s as l,j as v,f as
|
|
3
|
+
import{Initializer as D}from"@dropins/tools/lib.js";import{events as c}from"@dropins/tools/event-bus.js";import{s as l,j as v,f as h,h as b,g as E,i as C,k as G}from"./removeProductsFromWishlist.js";const R=new D({init:async e=>{const t={isGuestWishlistEnabled:!1,...e};R.config.setConfig(t),S().catch(console.error)},listeners:()=>[c.on("authenticated",async e=>{if(l.authenticated&&!e&&c.emit("wishlist/reset",void 0),e&&!l.authenticated){l.authenticated=e;const t=await S().catch(console.error);t&&ce(t)}},{eager:!0}),c.on("wishlist/data",e=>{v(e)}),c.on("wishlist/reset",()=>{ae().catch(console.error),c.emit("wishlist/data",null)})]}),pe=R.config;function O(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 N(e,t=[]){var i;return e?{type:e.__typename,name:e.name,sku:e.sku,uid:e.uid,image:M(e,t),stockStatus:e.stock_status,canonicalUrl:e.canonical_url,urlKey:e.url_key,categories:(i=e.categories)==null?void 0:i.map(s=>s.name),prices:W(e),productAttributes:F(e),options:U(e)}:null}function U(e){var t,i;return e.__typename==="ConfigurableProduct"?e.configurable_options?(t=e.configurable_options)==null?void 0:t.map(s=>{var n;return{uid:s.uid,attributeUid:s.attribute_uid,attributeCode:s.attribute_code,values:(n=s.values)==null?void 0:n.map(r=>({uid:r.uid,label:r.label})),required:!0}}):[]:e.__typename==="GiftCardProduct"?e.gift_card_options?(i=e.gift_card_options)==null?void 0:i.map(s=>({uid:s.uid,required:s.required,title:s.title})):[]:[]}function M(e,t=[]){var s;let i=e.thumbnail;if(e.__typename==="ConfigurableProduct"&&e.variants&&(t==null?void 0:t.length)>0){const n=t.map(o=>o.uid);let r=e.variants.find(o=>{var u;const _=((u=o.attributes)==null?void 0:u.map(a=>a.uid))||[];return n.every(a=>_.includes(a))});r||(r=e.variants.find(o=>{var _;return(_=o.attributes)==null?void 0:_.some(u=>t.some(a=>a.uid===u.uid))})),(s=r==null?void 0:r.product)!=null&&s.image&&(i=r.product.image)}return{src:i==null?void 0:i.url,alt:i==null?void 0:i.label}}function W(e){var t,i,s,n,r,o,_,u,a,d,m,f,p,I,g,T,y,P;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:((o=(r=(n=e.price_range)==null?void 0:n.minimum_price)==null?void 0:r.regular_price)==null?void 0:o.value)??0},finalPrice:{currency:((a=(u=(_=e.price_range)==null?void 0:_.minimum_price)==null?void 0:u.final_price)==null?void 0:a.currency)??"USD",value:((f=(m=(d=e.price_range)==null?void 0:d.minimum_price)==null?void 0:m.final_price)==null?void 0:f.value)??0},discount:{amountOff:((g=(I=(p=e.price_range)==null?void 0:p.minimum_price)==null?void 0:I.discount)==null?void 0:g.amount_off)??0,percentOff:((P=(y=(T=e.price_range)==null?void 0:T.minimum_price)==null?void 0:y.discount)==null?void 0:P.percent_off)??0},fixedProductTaxes:L(e)}}function F(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 L(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(o=>({money:{value:o.amount.value,currency:o.amount.currency},label:o.label})):[]}function w(e,t){return e?{id:e.id,updated_at:e.updated_at,sharing_code:e.sharing_code,items_count:e.items_count,items:k(e,t??[])}:null}function k(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=>{const r=$(n);return{id:n.id,quantity:n.quantity,description:n.description,added_at:n.added_at,enteredOptions:t,selectedOptions:r,product:N(n.product,r)}}):[]}function $(e){return e.product.__typename==="ConfigurableProduct"?e.configurable_options?e.configurable_options.map(t=>({value:t.value_label,label:t.option_label,uid:t.configurable_product_option_value_uid})):[]:[]}const q=`
|
|
4
4
|
query STORE_CONFIG_QUERY {
|
|
5
5
|
storeConfig {
|
|
6
6
|
magento_wishlist_general_is_enabled
|
|
@@ -13,7 +13,7 @@ query STORE_CONFIG_QUERY {
|
|
|
13
13
|
fixed_product_taxes_display_prices_on_product_view_page
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
`,H=async()=>
|
|
16
|
+
`,H=async()=>h(q,{method:"GET",cache:"force-cache"}).then(({errors:e,data:t})=>e?b(e):O(t)),B=`
|
|
17
17
|
fragment PRICE_RANGE_FRAGMENT on PriceRange {
|
|
18
18
|
minimum_price {
|
|
19
19
|
regular_price {
|
|
@@ -185,7 +185,7 @@ ${B}
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
${x}
|
|
188
|
-
`,Z=async(e,t)=>{if(!e)throw Error("Product SKU is not set");return
|
|
188
|
+
`,Z=async(e,t)=>{if(!e)throw Error("Product SKU is not set");return h(V,{variables:{sku:e}}).then(({errors:i,data:s})=>{var n;return i?b(i):(n=s==null?void 0:s.products)!=null&&n.items?N(s.products.items[0],t??[]):null})},X=`
|
|
189
189
|
fragment CUSTOMIZABLE_OPTIONS_FRAGMENT on SelectedCustomizableOption {
|
|
190
190
|
type
|
|
191
191
|
customizable_option_uid
|
|
@@ -303,7 +303,7 @@ ${se}
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
${A}
|
|
306
|
-
`,ne=async()=>l.authenticated?
|
|
306
|
+
`,ne=async()=>l.authenticated?h(re).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=>w(s)):null}):E(),ue=`
|
|
307
307
|
mutation ADD_PRODUCTS_TO_WISHLIST_MUTATION(
|
|
308
308
|
$wishlistId: ID!,
|
|
309
309
|
$wishlistItems: [WishlistItemInput!]!,
|
|
@@ -322,4 +322,4 @@ ${se}
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
${A}
|
|
325
|
-
`,oe=async e=>{var s,n,r,o,_;if(!e)return null;const t=
|
|
325
|
+
`,oe=async e=>{var s,n,r,o,_;if(!e)return null;const t=E();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(f=>C(f,{sku:u.sku,optionUIDs:u.optionsUIDs})))continue;const d=u.optionsUIDs?(n=u.optionsUIDs)==null?void 0:n.map(f=>({uid:f})):[],m=await Z(u.sku,d);m&&(i.items=[...i.items,{quantity:u.quantity,selectedOptions:d,enteredOptions:[],product:m}])}if(i.items_count=(r=i.items)==null?void 0:r.length,c.emit("wishlist/data",i),l.authenticated){if(!l.wishlistId)throw c.emit("wishlist/data",t),Error("Wishlist ID is not set");const u={wishlistId:l.wishlistId,wishlistItems:e.map(({sku:p,quantity:I,optionsUIDs:g,enteredOptions:T})=>({sku:p,quantity:I,selected_options:g,entered_options:T}))},{errors:a,data:d}=await h(ue,{variables:u}),m=[...((o=d==null?void 0:d.addProductsToWishlist)==null?void 0:o.user_errors)??[],...a??[]];if(m.length>0)return c.emit("wishlist/data",t),b(m);const f=w(d.addProductsToWishlist.wishlist,((_=e[0])==null?void 0:_.enteredOptions)??[]);c.emit("wishlist/data",f)}return null},ae=()=>(l.wishlistId=null,l.authenticated=!1,Promise.resolve(null)),S=async()=>{if(l.initializing)return null;l.initializing=!0,l.config||(l.config=await H());const e=l.authenticated?await le():await _e();return c.emit("wishlist/initialized",e),c.emit("wishlist/data",e),l.initializing=!1,e};async function le(){const e=await ne(),t=e?e[0]:null;return t?(l.wishlistId=t.id,t):null}async function _e(){try{return await E()}catch(e){throw console.error(e),e}}const ce=async e=>{var n;if(!e)return null;const t=E(!0),i=[];if((n=t==null?void 0:t.items)==null||n.forEach(r=>{var u;const o=((u=r.selectedOptions)==null?void 0:u.map(a=>a.uid))||[];if(!e.items.some(a=>C(a,{sku:r.product.sku,optionUIDs:o}))){const a={sku:r.product.sku,quantity:1,optionsUIDs:o,enteredOptions:r.enteredOptions||void 0};i.push(a)}}),i.length===0)return null;const s=await oe(i);return G(),s};export{se as W,oe as a,A as b,pe as c,Z as d,ne as e,S as f,H as g,le as h,R as i,_e as j,ce as m,ae as r,w as t};
|
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]=u(null),[N,_]=u(b.authenticated),[L,g]=u(b.isLoading),W=n=>_(n),[p,a]=u(null),x=j(n=>{const{action:o,item:h}=n;a(i(J,{action:o,item:h}))},[s]);return F(()=>{const n=I.on("authenticated",W),o=I.on("wishlist/alert",t=>x(t)),h=I.on("wishlist/data",t=>{m(t),g(!1)});return()=>{n==null||n.off(),h==null||h.off(),o==null||o.off()}},[x]),i(U,{...r,wishlistData:f,wishlistAlert:p,routeEmptyWishlistCTA:l,moveProdToCart:e,isLoggedIn:N,isLoading:L,routeProdDetailPage:c})},U=({className:l,wishlistData:s,wishlistAlert:e,isLoggedIn:c,isLoading:r,moveProdToCart:f,routeEmptyWishlistCTA:m,onLoginClick:N,routeProdDetailPage:_,...L})=>{const[g,W]=u(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(y=>{var w;return i(G,{initialData:y,moveProdToCart:f,routeProdDetailPage:_},(w=y.product)==null?void 0:w.sku)}):null},[s,f,_]);F(()=>{if(e){W(e);const t=setTimeout(()=>{W(null)},5e3);return()=>clearTimeout(t)}},[e]);const x=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:v(["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:N})]})}),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((y,w)=>{var E;return d(B,{children:[y,w===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())+w)})})}):null},[p,a,s]);return d("div",{...L,className:v(["wishlist-wishlist",l]),children:[x,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};
|
|
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]=u(null),[N,_]=u(b.authenticated),[L,g]=u(b.isLoading),W=n=>_(n),[p,a]=u(null),x=j(n=>{const{action:o,item:h}=n;a(i(J,{action:o,item:h,routeToWishlist:s}))},[s]);return F(()=>{const n=I.on("authenticated",W),o=I.on("wishlist/alert",t=>x(t)),h=I.on("wishlist/data",t=>{m(t),g(!1)});return()=>{n==null||n.off(),h==null||h.off(),o==null||o.off()}},[x]),i(U,{...r,wishlistData:f,wishlistAlert:p,routeEmptyWishlistCTA:l,moveProdToCart:e,isLoggedIn:N,isLoading:L,routeProdDetailPage:c})},U=({className:l,wishlistData:s,wishlistAlert:e,isLoggedIn:c,isLoading:r,moveProdToCart:f,routeEmptyWishlistCTA:m,onLoginClick:N,routeProdDetailPage:_,...L})=>{const[g,W]=u(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(y=>{var w;return i(G,{initialData:y,moveProdToCart:f,routeProdDetailPage:_},(w=y.product)==null?void 0:w.sku)}):null},[s,f,_]);F(()=>{if(e){W(e);const t=setTimeout(()=>{W(null)},5e3);return()=>clearTimeout(t)}},[e]);const x=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:v(["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:N})]})}),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((y,w)=>{var E;return d(B,{children:[y,w===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())+w)})})}):null},[p,a,s]);return d("div",{...L,className:v(["wishlist-wishlist",l]),children:[x,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};
|
|
@@ -13,6 +13,10 @@ export interface WishlistToggleProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
13
13
|
labelToWishlist?: string;
|
|
14
14
|
labelWishlisted?: string;
|
|
15
15
|
onClick?: () => void;
|
|
16
|
+
removeProdFromCart?: (product: {
|
|
17
|
+
uid: string;
|
|
18
|
+
quantity: number;
|
|
19
|
+
}[]) => Promise<any>;
|
|
16
20
|
}
|
|
17
21
|
export declare const WishlistToggle: Container<WishlistToggleProps>;
|
|
18
22
|
//# sourceMappingURL=WishlistToggle.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as
|
|
3
|
+
import{jsx as m}from"@dropins/tools/preact-jsx-runtime.js";import{useState as c,useCallback as y,useEffect as u}from"@dropins/tools/preact-compat.js";import{Button as C,Icon as d}from"@dropins/tools/components.js";import{events as a}from"@dropins/tools/event-bus.js";import{s as j,g as q,i as x,r as E}from"../chunks/removeProductsFromWishlist.js";import{c as H,a as P}from"../chunks/mergeWishlists.js";import{S as T}from"../chunks/HeartFilled.js";import{S as z}from"../chunks/Heart.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const V=({product:s,iconWishlisted:I,iconToWishlist:v,size:g,variant:k,disabled:D,labelToWishlist:U,labelWishlisted:p,onClick:w,removeProdFromCart:r})=>{const[O,S]=c(j.authenticated),[f,n]=c(!1),[h,W]=c(null),{isGuestWishlistEnabled:L}=H.getConfig(),o=y(()=>{var i;const e=q(),t=(i=e==null?void 0:e.items)==null?void 0:i.find(l=>x(l,{sku:s.topLevelSku??s.sku,optionUIDs:s.optionUIDs??(s.selectedOptionsUIDs?Object.values(s.selectedOptionsUIDs):void 0)}));W(t??null),n(!!t)},[s.topLevelSku,s.sku,s.optionUIDs,s.selectedOptionsUIDs]);u(()=>{o()},[o]),u(()=>{const e=l=>S(l),t=a.on("authenticated",e),i=a.on("wishlist/data",o);return()=>{t==null||t.off(),i==null||i.off()}},[o]);const b=async()=>{var e;f?(await E([h]),n(!1),a.emit("wishlist/alert",{action:"remove",item:h})):(await P([{sku:s.topLevelSku??s.sku,quantity:1,optionsUIDs:s.optionUIDs??(s.selectedOptionsUIDs?Object.values(s.selectedOptionsUIDs):void 0),enteredOptions:(e=s.options)!=null&&e.items?s.options.items.filter(t=>t.selected).map(t=>({uid:t.uid,value:t.value})):void 0}]),n(!0),a.emit("wishlist/alert",{action:"add",item:{product:s}}),r&&await r([{uid:s.uid,quantity:0}]))};return!O&&!L?null:m(C,{active:f,"data-testid":"wishlist-toggle",size:g??"medium",variant:k??"tertiary",disabled:D,icon:m(d,{source:v??z}),activeIcon:m(d,{source:I??T}),onClick:w??b,children:U,activeChildren:p})};export{V as WishlistToggle,V as default};
|
package/data/models/product.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-wishlist", "version": "1.0.0-
|
|
1
|
+
{"name": "@dropins/storefront-wishlist", "version": "1.0.0-beta3", "@dropins/tools": "~1.0.0", "license": "SEE LICENSE IN LICENSE.md"}
|