@dropins/storefront-wishlist 0.2.4-alpha → 1.0.0-beta1
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
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
|
|
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 o;if(s.product.sku!==e.sku)return!1;const t=((o=s.selectedOptions)==null?void 0:o.map(i=>i.uid).filter(i=>!!i).sort())||[],r=(e.optionUIDs||[]).filter(i=>!!i).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 i;const r=n.authenticated?sessionStorage:localStorage,o=r.getItem(c)?JSON.parse(r.getItem(c)):{items:[]};return(i=o==null?void 0:o.items)==null?void 0:i.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 u}from"@dropins/tools/event-bus.js";import{FetchGraphQL as S}fr
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
`,$=async s=>{var r,i
|
|
18
|
+
`,$=async s=>{var r,o,i;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=(o=t.items)==null?void 0:o.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=[...((i=a==null?void 0:a.removeProductsFromWishlist)==null?void 0:i.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};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as
|
|
3
|
+
import{jsx as r}from"@dropins/tools/preact-jsx-runtime.js";import{useState as m,useCallback as P,useEffect as d}from"@dropins/tools/preact-compat.js";import{Button as b,Icon as h}from"@dropins/tools/components.js";import{events as a}from"@dropins/tools/event-bus.js";import{s as x,g as E,i as F,r as H}from"../chunks/removeProductsFromWishlist.js";import{c as L,a as T}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:s,iconWishlisted:u,iconToWishlist:g,size:I,variant:v,disabled:p,labelToWishlist:k,labelWishlisted:W,onClick:w})=>{const[D,C]=m(x.authenticated),[c,n]=m(!1),[f,S]=m(null),{isGuestWishlistEnabled:U}=L.getConfig(),o=P(()=>{var e;const i=E(),t=(e=i==null?void 0:i.items)==null?void 0:e.find(l=>F(l,{sku:s.sku,optionUIDs:s.optionUIDs}));S(t??null),n(!!t)},[s.sku,s.optionUIDs]);d(()=>{o()},[o]),d(()=>{const i=l=>C(l),t=a.on("authenticated",i),e=a.on("wishlist/data",o);return()=>{t==null||t.off(),e==null||e.off()}},[o]);const y=async()=>{var i;c?(await H([f]),n(!1),a.emit("wishlist/alert",{action:"remove",item:f})):(await T([{sku:s.sku,quantity:1,optionsUIDs:s.optionUIDs??void 0,enteredOptions:(i=s.options)!=null&&i.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}}))};return!D&&!U?null:r(b,{active:c,"data-testid":"wishlist-toggle",size:I??"medium",variant:v??"tertiary",disabled:p,icon:r(h,{source:g??q}),activeIcon:r(h,{source:u??j}),onClick:w??y,children:k,activeChildren:W})};export{R as WishlistToggle,R as default};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-wishlist", "version": "0.
|
|
1
|
+
{"name": "@dropins/storefront-wishlist", "version": "1.0.0-beta1", "@dropins/tools": "~1.0.0", "license": "SEE LICENSE IN LICENSE.md"}
|