@occluze/tether 0.6.7 → 0.6.8
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/README.md +3 -3
- package/dist/esm/astro.js +2 -2
- package/dist/esm/chunks/account-C3NP6HFB.js +1 -0
- package/dist/esm/chunks/account-pages-WLK374FO.js +1 -0
- package/dist/esm/chunks/analytics-G3SAWMNL.js +1 -0
- package/dist/esm/chunks/chunk-27PJJZGC.js +1 -0
- package/dist/esm/chunks/chunk-2FSXS55U.js +1 -0
- package/dist/esm/chunks/chunk-FCSWQDVV.js +1 -0
- package/dist/esm/chunks/chunk-FOMSMIAM.js +1 -0
- package/dist/esm/chunks/chunk-GZJTCLLW.js +1 -0
- package/dist/esm/chunks/chunk-HEQILZVR.js +1 -0
- package/dist/esm/chunks/chunk-JOOEXYF3.js +4 -0
- package/dist/esm/chunks/chunk-MPTQYLSM.js +1 -0
- package/dist/esm/chunks/chunk-NEHZ37TU.js +3 -0
- package/dist/esm/chunks/chunk-V74KGEJF.js +1 -0
- package/dist/esm/chunks/chunk-VT4CDUJJ.js +1 -0
- package/dist/esm/chunks/chunk-YJLWX2HK.js +1 -0
- package/dist/esm/chunks/diagnose-6VVGZNTY.js +14 -0
- package/dist/esm/chunks/extras-GJVRDFM3.js +1 -0
- package/dist/esm/chunks/markets-ui-UNB4PTA7.js +1 -0
- package/dist/esm/chunks/search-OU75RNQL.js +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +2 -1
- package/dist/presets/barba.esm.js +56 -36
- package/dist/tether.account-pages.js +773 -442
- package/dist/tether.account-pages.min.js +1 -1
- package/dist/tether.account.js +648 -318
- package/dist/tether.account.min.js +1 -1
- package/dist/tether.analytics.js +318 -191
- package/dist/tether.analytics.min.js +1 -1
- package/dist/tether.diagnose.js +331 -242
- package/dist/tether.diagnose.min.js +2 -2
- package/dist/tether.extras.js +78 -33
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +3176 -2015
- package/dist/tether.markets.js +231 -126
- package/dist/tether.markets.min.js +1 -1
- package/dist/tether.min.js +0 -0
- package/dist/tether.min.js.map +4 -4
- package/dist/tether.search.js +221 -126
- package/dist/tether.search.min.js +1 -1
- package/package.json +23 -4
- package/src/account/addresses-view.js +92 -0
- package/src/account/browser-session.js +359 -0
- package/src/account/markup.js +48 -0
- package/src/account/operations.js +180 -0
- package/src/account/order-lines.js +96 -0
- package/src/account/order-list.js +91 -0
- package/src/account/order-page.js +192 -0
- package/src/account/page-events.js +288 -0
- package/src/account/server-client.js +172 -0
- package/src/account/shared.js +111 -0
- package/src/account/shopify-auth.js +150 -0
- package/src/account/subscriptions-view.js +158 -0
- package/src/account-api.js +118 -0
- package/src/account-links.js +35 -0
- package/src/account-pages.js +69 -298
- package/src/account.js +280 -323
- package/src/amounts.js +36 -0
- package/src/analytics-shopify.js +241 -0
- package/src/analytics.js +304 -184
- package/src/api-version.js +75 -25
- package/src/astro.js +233 -68
- package/src/cart/checkout.js +97 -0
- package/src/cart/drawer.js +138 -0
- package/src/cart/mutations.js +234 -0
- package/src/cart/render.js +294 -0
- package/src/cart/store.js +326 -0
- package/src/cart.js +320 -488
- package/src/client.js +214 -78
- package/src/collection.js +126 -57
- package/src/config.js +323 -59
- package/src/controls/cart-controls.js +155 -0
- package/src/controls/discount.js +96 -0
- package/src/controls/extras.js +63 -0
- package/src/controls/navigation.js +83 -0
- package/src/diagnose-markup.js +333 -0
- package/src/diagnose.js +251 -202
- package/src/dom.js +219 -220
- package/src/extras.js +119 -37
- package/src/fragments.js +115 -22
- package/src/images.js +104 -0
- package/src/index.js +245 -287
- package/src/initial.js +78 -66
- package/src/lazy-iife.js +92 -22
- package/src/lazy.js +25 -4
- package/src/loader.js +263 -124
- package/src/market-codes.js +35 -0
- package/src/markets-ui.js +169 -55
- package/src/markets.js +286 -85
- package/src/markup.js +64 -0
- package/src/mounting.js +214 -91
- package/src/page-market.js +116 -0
- package/src/parts/account-pages.js +4 -1
- package/src/parts/account.js +4 -1
- package/src/parts/analytics.js +4 -1
- package/src/parts/diagnose.js +4 -1
- package/src/parts/extras.js +4 -1
- package/src/parts/markets.js +4 -1
- package/src/parts/search.js +4 -1
- package/src/presets/barba.js +120 -30
- package/src/product-events.js +130 -0
- package/src/product-render.js +257 -0
- package/src/product-state.js +318 -0
- package/src/product.js +233 -459
- package/src/repeaters.js +173 -0
- package/src/search.js +277 -107
- package/src/selling-plans.js +107 -47
- package/src/server.js +168 -205
- package/src/shopify-values.js +89 -0
- package/src/status.js +99 -39
- package/src/store-html.js +0 -0
- package/src/storefront/catalog.js +199 -0
- package/src/storefront/json-ld.js +167 -0
- package/src/variant-render.js +165 -0
- package/types/astro.d.ts +13 -2
- package/types/index.d.ts +178 -27
- package/types/server.d.ts +89 -17
- package/dist/esm/chunks/account-Q6E2TFEV.js +0 -1
- package/dist/esm/chunks/account-pages-UZXR4R5F.js +0 -1
- package/dist/esm/chunks/analytics-IJBKATUP.js +0 -1
- package/dist/esm/chunks/chunk-4QJKLPYR.js +0 -1
- package/dist/esm/chunks/chunk-64TUD3QR.js +0 -1
- package/dist/esm/chunks/chunk-AJLPU2JC.js +0 -4
- package/dist/esm/chunks/chunk-FIOZPPC5.js +0 -1
- package/dist/esm/chunks/chunk-K2YEQAIH.js +0 -1
- package/dist/esm/chunks/chunk-KIDH76B7.js +0 -1
- package/dist/esm/chunks/chunk-PAYT5ZD7.js +0 -1
- package/dist/esm/chunks/chunk-RREHGH4A.js +0 -1
- package/dist/esm/chunks/chunk-SSJT43CJ.js +0 -1
- package/dist/esm/chunks/chunk-VC46IEJQ.js +0 -1
- package/dist/esm/chunks/diagnose-3WVAWNTX.js +0 -14
- package/dist/esm/chunks/extras-7I7WJX35.js +0 -1
- package/dist/esm/chunks/markets-ui-545XLFTE.js +0 -1
- package/dist/esm/chunks/search-NILMGYXG.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
"use strict";(()=>{var q=Object.defineProperty;var H=(e,n)=>{for(var t in n)q(e,t,{get:n[t],enumerable:!0})};var E={};H(E,{apiVersionStatus:()=>b,checkMarkup:()=>w,diagnose:()=>be,didYouMean:()=>f});var j=window.Tether.__core["config.js"],{DEFAULTS:Ee,cfg:i,configure:$e,isConfigured:S,log:Se,reportError:ke,resolveConfig:Pe,toMetafieldIdentifier:Te,warn:_e}=j;var G=window.Tether.__core["client.js"],{TetherError:Ae,endpoint:k,gql:P,request:ve,unwrap:Me,withContext:xe}=G;var Y=window.Tether.__core["dom.js"],{attr:p,busy:De,cdnUrl:Ue,emit:Ie,formatDate:Ce,formatMoney:Oe,formatPercent:Ve,get:h,has:qe,hasTemplate:T,imageUrl:He,notifyLayoutChanged:je,parseJSONAttr:Ge,productUrl:Ye,qsa:d,repeat:Be,repeatKeyed:Ke,sameImage:Le,scoped:Qe,sel:l,setImage:We,setSelected:Fe,setStoreHtml:ze,setText:Je,setTextTracked:Xe,show:Ze,toAttributes:et,watchImages:tt}=Y;var B=window.Tether.__core["loader.js"],{clearProductCache:ot,getProduct:_,getProducts:rt,getRecommendations:st,hydrateProducts:at,normalizeProductKey:it,primeProduct:ct,refreshProducts:lt,takeStale:ut}=B;var K=window.Tether.__core["selling-plans.js"],{GID:pt,allPlans:R,allocationFor:ht,findPlan:ft,hasPlans:mt,planAdjustment:gt,planCheckoutCharge:bt,planPrice:yt,planSavings:wt,plansForVariant:Et,toGid:$t}=K;var L=window.Tether.__core["status.js"],{STATUS_KEYS:kt,boundary:A,isNotFound:Pt,ownedBy:Tt,resolveProductKey:g,setScopeStatus:_t}=L;var Q=/^(\d{4})-(01|04|07|10)$/;function M(e){let n=Q.exec(typeof e=="string"?e:"");return n?{year:Number(n[1]),month:Number(n[2])}:null}var W=(e,n)=>`${e}-${String(n).padStart(2,"0")}`;function v(e,n=1){let t=M(e);if(!t)throw new Error(`not a quarterly Shopify API version: ${e}`);let o=t.year*4+(t.month-1)/3+n;return W(Math.floor(o/4),o%4*3+1)}function b(e,n=new Date){if(e==="unstable")return{version:e,ok:!1,note:'"unstable" changes without notice: pin a dated version such as 2026-07'};let t=M(e);if(!t)return{version:e,ok:!1,note:"not a quarterly version (YYYY-01, -04, -07 or -10)"};let o=new Date(Date.UTC(t.year,t.month-1,1)),s=new Date(Date.UTC(t.year,t.month-1+12,1)),r=(s.getTime()-n.getTime())/2630016e3,a=o<=n,c=`supported until about ${s.toISOString().slice(0,7)}`;return a?r<=0?c="no longer supported: Shopify falls back to the oldest supported version. Upgrade (see README)":r<3&&(c=`${c}: plan the upgrade to ${v(e)} or later (see README)`):c="not released yet (release candidate at best)",{version:e,ok:a&&r>0,monthsLeft:Math.round(r),next:v(e),note:c}}var F=window.Tether.__core["lazy.js"],{coreModules:vt,loadPart:x}=F;var N=new Set(["in-stock","out-of-stock","backorder","low-stock","plenty-in-stock","on-sale","not-on-sale","has-variants","single-variant","subscription-available","subscription-unavailable","subscription-only","one-time-available","subscription-selected","one-time-selected","has-savings","loading","ready","error","not-found","cart-empty","cart-filled","cart-has-subscription","cart-no-subscription","cart-has-discount","cart-error","cart-warning","list-empty","list-filled","search-empty","search-results","logged-in","logged-out","orders-empty","orders-loading","addresses-loading","addresses-empty","addresses-error","subscriptions-loading","subscriptions-empty","subscriptions-error"]),D=new Set(["title","description","description-text","vendor","type","handle","published-at","price","total-price","compare-at-price","unit-price","min-price","max-price","discount-percentage","discount-amount","variant-title","variant-id","sku","barcode","stock","quantity","featured-image","variant-image","images","tags","link","url","one-time-price","subscription-price","subscription-savings","subscription-savings-amount","checkout-charge","plan-name","plan-description","plan-group","option-value","swatch","image"]),U=new Set(`account account-bind account-link account-login account-logout add-label add-to-cart adding-text
|
|
2
2
|
always-enabled bind cart-checkout-charge cart-clear cart-close cart-count cart-discounts cart-drawer cart-label cart-lines
|
|
3
3
|
cart-note cart-open cart-subtotal cart-total cart-warning checkout code collection collection-bind countries country
|
|
4
4
|
country-bind country-label country-select default-plan default-purchase discount discount-code discount-form discount-input
|
|
@@ -11,4 +11,4 @@
|
|
|
11
11
|
plan-value product products purchase purchase-mode qty qty-minus qty-plus quantity recommendations reverse search
|
|
12
12
|
search-bind search-collections search-input search-limit search-min search-products search-queries search-results
|
|
13
13
|
search-state show soldout-text sort state subscribe-text variant variant-select variant-url max-width max-height crop
|
|
14
|
-
sig label hydrated busy`.split(/\s+/).filter(Boolean));function
|
|
14
|
+
sig label hydrated busy`.split(/\s+/).filter(Boolean)),z=["bind","option-list","option","variant-select","add-to-cart","purchase","plan-list","plan","qty","line-attribute"],J=["option-list","plan-list","cart-lines","list"],y="metafield:",X=/^image:\d+$/,Z=2;function ee(e,n){let t=Array.from({length:n.length+1},(o,s)=>s);for(let o=1;o<=e.length;o++){let s=[o];for(let r=1;r<=n.length;r++){let a=(t[r-1]??0)+(e[o-1]===n[r-1]?0:1);s.push(Math.min((t[r]??0)+1,(s[r-1]??0)+1,a))}t=s}return t[n.length]??0}function f(e,n,t=""){let o=null,s=1/0;for(let a of n){let c=ee(e,a);c<s&&(s=c,o=a)}let r=Math.max(2,Math.floor(e.length/4));return o!==null&&s<=r?` Did you mean "${t}${o}"?`:""}function te(e){let n=e.id?`#${e.id}`:"",t=e.className&&typeof e.className=="string"?e.className.trim().split(/\s+/):[],o=t.length?`.${t.slice(0,Z).join(".")}`:"";return`<${e.tagName.toLowerCase()}${n}${o}>`}var I=()=>`${l("collection")},${l("products")},${l("recommendations")}`;function ne(e,n){d(e,l("product")).forEach(t=>{if(t.closest(I())&&t.closest(l("list")))return;let{key:o,fromUrl:s,raw:r}=g(t);r?s&&!o&&n("warn",`${p("product")}="${r}" but this URL has no value for it (e.g. ?handle=my-product).`,t):n("error",`${p("product")} has no value. Bind it to the Shopify handle (CMS field), or use "url:handle".`,t)})}function oe(e,n){for(let t of z)d(e,l(t)).forEach(o=>{o.closest(l("product"))||t==="line-attribute"&&o.closest(l("group"))||n("warn",`${p(t)} outside any ${p("product")}: it does nothing here.`,o)});d(e,l("group-add")).forEach(t=>{t.closest(l("group"))||n("warn",`${p("group-add")} outside a ${p("group")}.`,t)});for(let t of J)d(e,l(t)).forEach(o=>{!o.firstElementChild&&!T(o)&&n("warn",`${p(t)} without a template child: put one example element inside it.`,o)});d(e,I()).forEach(t=>{d(t,l("list")).length||n("error",`List without a ${p("list")} child: products have nowhere to render.`,t)})}function re(e,n){d(e,l("show")).forEach(t=>{let o=h(t,"show")??"";N.has(o)||n("warn",`Unknown ${p("show")}="${o}".${f(o,N)}`,t)}),d(e,l("bind")).forEach(t=>{let o=h(t,"bind")||"";!o||D.has(o)||X.test(o)||o.startsWith(y)||n("warn",`Unknown ${p("bind")}="${o}": it stays empty.${f(o,D)}`,t)})}function se(e,n){d(e,l("bind")).forEach(t=>{let o=h(t,"bind")||"";if(!o.startsWith(y))return;let s=o.slice(y.length);i.metafields.some(a=>(typeof a=="string"?a:`${a.namespace}.${a.key}`)===s)||n("error",`${p("bind")}="${o}" but "${s}" is not in config.metafields, so it stays empty.`,t)})}function ae(e,n){let t=`${i.prefix}-`,o=new Set;d(e,"*").forEach(s=>{for(let{name:r}of s.attributes){if(!r.startsWith(t))continue;let a=r.slice(t.length);U.has(a)||o.has(a)||(o.add(a),n("warn",`Unknown attribute ${r}: Tether ignores it.${f(a,U,t)}`,s))}})}function ie(e,n){let t=d(e,l("cart-drawer")).length;d(e,l("cart-open")).length&&!t&&n("warn",`${p("cart-open")} exists but there is no ${p("cart-drawer")} on this page.`),t>1&&n("warn",`More than one ${p("cart-drawer")}.`),d(e,`[${p("state")}="error"]`).forEach(o=>{o.matches(A())&&n("error",`Scope failed to load (${h(o,"error")||"error"}).`,o)})}function w(e=document){let n=[],t=(o,s,r)=>{n.push(r?{level:o,message:s,element:te(r),el:r}:{level:o,message:s})};return ne(e,t),oe(e,t),re(e,t),ae(e,t),se(e,t),ie(e,t),n}var ce=20,le=3,C=4;function ue(e){return e?`${e.slice(0,C)}\u2026${e.slice(-C)} (${e.length} chars)`:"(missing)"}function O(e,n){if(e instanceof Error&&e.message)return e.message;let t=typeof e=="object"&&e!==null?Reflect.get(e,"code"):void 0;return typeof t=="string"&&t?t:n}function de(){return{domain:i.domain||"(missing)",token:ue(i.token),apiVersion:i.apiVersion,endpoint:i.domain?k():null,country:i.country,language:i.language,locale:i.locale,markets:i.markets,prefix:i.prefix,productPath:i.productPath,metafields:i.metafields,autoMount:i.autoMount,observe:i.observe,onError:typeof i.onError=="function"}}async function pe(){return{country:i.country||null,language:i.language||null,locale:i.locale||null,detected:i.markets?.detect?(await x("markets")).detectMarket(i.markets):null}}function he({ok:e,monthsLeft:n,note:t}){return e&&(n===void 0||n>=le)?null:{level:e?"warn":"error",message:`apiVersion ${i.apiVersion}: ${t}`}}async function fe(){if(!S())return{kind:"not-configured"};let e=Date.now();try{let n=await P("query TetherDiagnose { shop { name primaryDomain { url } paymentSettings { currencyCode } } }",{},{context:!1});return{kind:"reachable",shop:{name:n.shop.name,url:n.shop.primaryDomain.url,currency:n.shop.paymentSettings.currencyCode},latencyMs:Date.now()-e}}catch(n){return{kind:"unreachable",error:n,latencyMs:Date.now()-e}}}function me(e,n,t){let o=[],s=t.options.map(a=>a.name),r=d(e,l("product")).filter(a=>g(a).key===n&&a.querySelector(l("add-to-cart")));for(let a of r){let c=new Set(d(a,`${l("option-list")},select${l("option")}`).map(u=>h(u,"option-list")||h(u,"option")));if(!(!c.size&&d(a,`select${l("variant-select")}`).length)){if(!i.language)for(let u of c)!u||s.includes(u)||o.push({level:"warn",message:`Product "${t.handle}" has no option "${u}" (its options: ${s.join(", ")||"none"}).${f(u,s)}`});for(let u of t.options)u.optionValues.length<=1||c.has(u.name)||o.push({level:"warn",message:`Product "${t.handle}": option "${u.name}" (${u.optionValues.length} values) has no tether-option-list, so visitors can't choose it.`})}}return o}async function ge(e,n){let t=d(e,l("product")).map(r=>g(r).key),o=[...new Set(t.filter(r=>r!==null&&r!==""))].slice(0,ce);(await Promise.allSettled(o.map(r=>_(r)))).forEach((r,a)=>{let c=o[a]??"";if(r.status==="rejected"){let m=O(r.reason,"not loaded");n.products.push({key:c,error:r.reason instanceof Error?r.reason.message:void 0}),n.problems.push({level:"error",message:`Product "${c}": ${m}. Is it published to the Headless channel?`});return}let u=r.value,$=R(u);n.products.push({key:c,handle:u.handle,title:u.title,plans:$.length,requiresSellingPlan:u.requiresSellingPlan});for(let m of $)n.sellingPlans.push({product:u.handle,group:m.group.name,plan:m.name,id:m.id});n.problems.push(...me(e,c,u))})}async function be({root:e=document,silent:n=!1,version:t,now:o=new Date}={}){let s=await fe(),r={version:t,config:de(),apiVersion:b(i.apiVersion,o),market:await pe(),reachable:s.kind==="reachable",shop:s.kind==="reachable"?s.shop:null,latencyMs:s.kind==="not-configured"?null:s.latencyMs,products:[],sellingPlans:[],problems:[]};switch(s.kind){case"not-configured":r.problems.push({level:"error",message:"TETHER_CONFIG needs domain and token."});break;case"unreachable":r.problems.push({level:"error",message:`Storefront API not reachable: ${O(s.error,"unknown error")}`});break;case"reachable":await ge(e,r);break}let a=he(r.apiVersion);return a&&r.problems.push(a),typeof document<"u"&&r.problems.push(...w(e)),n||ye(r),r}function ye(e){let n=e.problems.filter(c=>c.level==="error").length,t=e.problems.length-n;console.group(`[${i.prefix}] diagnose: ${n?`${n} error(s)`:"no errors"}, ${t} warning(s)`),console.log("version",e.version,"| API",e.apiVersion.version,`(${e.apiVersion.note})`),console.log("config",e.config);let{country:o,language:s,detected:r}=e.market,a=[o,s].filter(Boolean).join(" / ")||"the store default";console.log("market",`in use: ${a}`,r?`(detection picks ${JSON.stringify(r)})`:""),console.log(e.shop?`Storefront API reachable: ${e.shop.name} (${e.latencyMs??0} ms)`:"Storefront API NOT reachable"),e.products.length&&console.table(e.products),e.sellingPlans.length?console.table(e.sellingPlans):e.reachable&&console.log("No selling plans on the products of this page.");for(let c of e.problems)c.level==="error"?console.error(c.message,c.el??""):console.warn(c.message,c.el??"");console.groupEnd()}var{Tether:V}=window;if(!V)throw new Error("tether.diagnose.js runs after the Tether script, which loads it");V.__parts.diagnose=E;})();
|
package/dist/tether.extras.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
(() => {
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __export = (target, all) => {
|
|
@@ -15,11 +16,11 @@
|
|
|
15
16
|
|
|
16
17
|
// tether-core:config.js
|
|
17
18
|
var m = window.Tether.__core["config.js"];
|
|
18
|
-
var { DEFAULTS, cfg, configure, isConfigured, log, reportError, warn } = m;
|
|
19
|
+
var { DEFAULTS, cfg, configure, isConfigured, log, reportError, resolveConfig, toMetafieldIdentifier, warn } = m;
|
|
19
20
|
|
|
20
21
|
// tether-core:dom.js
|
|
21
22
|
var m2 = window.Tether.__core["dom.js"];
|
|
22
|
-
var { attr, busy, cdnUrl,
|
|
23
|
+
var { attr, busy, cdnUrl, emit, formatDate, formatMoney, formatPercent, get, has, hasTemplate, imageUrl, notifyLayoutChanged, parseJSONAttr, productUrl, qsa, repeat, repeatKeyed, sameImage, scoped, sel, setImage, setSelected, setStoreHtml, setText, setTextTracked, show, toAttributes, watchImages } = m2;
|
|
23
24
|
|
|
24
25
|
// tether-core:product.js
|
|
25
26
|
var m3 = window.Tether.__core["product.js"];
|
|
@@ -27,19 +28,26 @@
|
|
|
27
28
|
|
|
28
29
|
// tether-core:cart.js
|
|
29
30
|
var m4 = window.Tether.__core["cart.js"];
|
|
30
|
-
var { Cart,
|
|
31
|
+
var { Cart, trapFocus } = m4;
|
|
31
32
|
|
|
32
33
|
// src/extras.js
|
|
33
|
-
|
|
34
|
-
const
|
|
34
|
+
function groupAttributes(group, name) {
|
|
35
|
+
const extra = toAttributes(
|
|
36
|
+
/** @type {Parameters<typeof toAttributes>[0]} */
|
|
37
|
+
parseJSONAttr(group, "line-attributes")
|
|
38
|
+
);
|
|
39
|
+
return name ? [{ key: "_group", value: name }, ...extra] : extra;
|
|
40
|
+
}
|
|
41
|
+
async function addGroup(button) {
|
|
42
|
+
const group = button.closest(sel("group"));
|
|
35
43
|
if (!group) return null;
|
|
36
44
|
const name = get(group, "group");
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
45
|
+
const attributes = groupAttributes(group, name);
|
|
46
|
+
const lines = qsa(group, sel("product")).flatMap((el) => {
|
|
47
|
+
const scope = scopes.get(el);
|
|
48
|
+
if (!scope?.variant?.availableForSale || scope.quantity <= 0) return [];
|
|
49
|
+
const line = scope.getLine();
|
|
50
|
+
return line ? [{ ...line, attributes: [...line.attributes ?? [], ...attributes] }] : [];
|
|
43
51
|
});
|
|
44
52
|
if (!lines.length) {
|
|
45
53
|
warn("group-add: nothing selected");
|
|
@@ -49,39 +57,76 @@
|
|
|
49
57
|
const cart = await Cart.add(lines);
|
|
50
58
|
emit("group-added", { group: name, lines }, group);
|
|
51
59
|
return cart;
|
|
52
|
-
} catch (
|
|
53
|
-
reportError(
|
|
60
|
+
} catch (error) {
|
|
61
|
+
reportError(error, "group add");
|
|
54
62
|
return null;
|
|
55
63
|
}
|
|
56
64
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
} catch {
|
|
65
|
-
}
|
|
65
|
+
function parseStoredMarket(text) {
|
|
66
|
+
let value;
|
|
67
|
+
try {
|
|
68
|
+
value = JSON.parse(text);
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
66
71
|
}
|
|
72
|
+
if (typeof value !== "object" || value === null) return null;
|
|
73
|
+
const { country, language, locale } = (
|
|
74
|
+
/** @type {Record<string, unknown>} */
|
|
75
|
+
value
|
|
76
|
+
);
|
|
77
|
+
if (typeof country !== "string" || !country) return null;
|
|
78
|
+
return {
|
|
79
|
+
country,
|
|
80
|
+
language: typeof language === "string" ? language : null,
|
|
81
|
+
locale: typeof locale === "string" ? locale : void 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function onStorage(event) {
|
|
85
|
+
if (event.key === cfg.storageKey || event.key === `${cfg.storageKey}:seen`) {
|
|
86
|
+
Cart.init().catch((error) => {
|
|
87
|
+
reportError(error, "cart from another tab");
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (event.key !== `${cfg.prefix}:market:${cfg.domain}` || !event.newValue) return;
|
|
92
|
+
const market = parseStoredMarket(event.newValue);
|
|
93
|
+
const { Tether: Tether2 } = (
|
|
94
|
+
/** @type {Window & { Tether?: { setCountry: SetCountry } }} */
|
|
95
|
+
window
|
|
96
|
+
);
|
|
97
|
+
if (!market || !Tether2) return;
|
|
98
|
+
const options = { language: market.language, locale: market.locale, remember: false };
|
|
99
|
+
Tether2.setCountry(market.country, options).catch((error) => {
|
|
100
|
+
reportError(error, "market from another tab");
|
|
101
|
+
});
|
|
67
102
|
}
|
|
68
103
|
var urlKeys = /* @__PURE__ */ new WeakMap();
|
|
104
|
+
var numericId = (gid) => gid.split("/").pop() ?? gid;
|
|
105
|
+
function replaceUrlIfAllowed(url) {
|
|
106
|
+
try {
|
|
107
|
+
window.history.replaceState(window.history.state, "", url);
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
69
111
|
function writeVariantUrl(root, { variant, sellingPlanId }) {
|
|
70
|
-
const key = `${variant.id}|${sellingPlanId
|
|
112
|
+
const key = `${variant.id}|${sellingPlanId ?? ""}`;
|
|
71
113
|
const before = urlKeys.get(root);
|
|
72
114
|
urlKeys.set(root, key);
|
|
73
115
|
if (!before || before === key) return;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
116
|
+
const isMainProduct = cfg.variantUrl && document.querySelector(sel("product")) === root;
|
|
117
|
+
if (!has(root, "variant-url") && !isMainProduct) return;
|
|
118
|
+
const url = new URL(window.location.href);
|
|
119
|
+
url.searchParams.set("variant", numericId(variant.id));
|
|
120
|
+
if (sellingPlanId) url.searchParams.set("selling_plan", numericId(sellingPlanId));
|
|
121
|
+
else url.searchParams.delete("selling_plan");
|
|
122
|
+
replaceUrlIfAllowed(url);
|
|
83
123
|
}
|
|
84
124
|
|
|
85
125
|
// src/parts/extras.js
|
|
86
|
-
|
|
126
|
+
var { Tether } = (
|
|
127
|
+
/** @type {Window & { Tether?: { __parts: Record<string, unknown> } }} */
|
|
128
|
+
window
|
|
129
|
+
);
|
|
130
|
+
if (!Tether) throw new Error("tether.extras.js runs after the Tether script, which loads it");
|
|
131
|
+
Tether.__parts["extras"] = extras_exports;
|
|
87
132
|
})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
"use strict";(()=>{var k=Object.defineProperty;var U=(e,t)=>{for(var r in t)k(e,r,{get:t[r],enumerable:!0})};var f={};U(f,{addGroup:()=>q,onStorage:()=>I,writeVariantUrl:()=>L});var A=window.Tether.__core["config.js"],{DEFAULTS:O,cfg:c,configure:P,isConfigured:v,log:F,reportError:i,resolveConfig:J,toMetafieldIdentifier:V,warn:d}=A;var j=window.Tether.__core["dom.js"],{attr:G,busy:H,cdnUrl:R,emit:m,formatDate:W,formatMoney:z,formatPercent:B,get:g,has:h,hasTemplate:Q,imageUrl:X,notifyLayoutChanged:Y,parseJSONAttr:w,productUrl:Z,qsa:y,repeat:tt,repeatKeyed:et,sameImage:rt,scoped:ot,sel:u,setImage:nt,setSelected:at,setStoreHtml:st,setText:ct,setTextTracked:it,show:ut,toAttributes:b,watchImages:lt}=j;var C=window.Tether.__core["product.js"],{ProductScope:ft,rememberOptionNames:dt,scopes:x}=C;var M=window.Tether.__core["cart.js"],{Cart:p,trapFocus:gt}=M;function $(e,t){let r=b(w(e,"line-attributes"));return t?[{key:"_group",value:t},...r]:r}async function q(e){let t=e.closest(u("group"));if(!t)return null;let r=g(t,"group"),n=$(t,r),o=y(t,u("product")).flatMap(s=>{let a=x.get(s);if(!a?.variant?.availableForSale||a.quantity<=0)return[];let l=a.getLine();return l?[{...l,attributes:[...l.attributes??[],...n]}]:[]});if(!o.length)return d("group-add: nothing selected"),null;try{let s=await p.add(o);return m("group-added",{group:r,lines:o},t),s}catch(s){return i(s,"group add"),null}}function E(e){let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!="object"||t===null)return null;let{country:r,language:n,locale:o}=t;return typeof r!="string"||!r?null:{country:r,language:typeof n=="string"?n:null,locale:typeof o=="string"?o:void 0}}function I(e){if(e.key===c.storageKey||e.key===`${c.storageKey}:seen`){p.init().catch(o=>{i(o,"cart from another tab")});return}if(e.key!==`${c.prefix}:market:${c.domain}`||!e.newValue)return;let t=E(e.newValue),{Tether:r}=window;if(!t||!r)return;let n={language:t.language,locale:t.locale,remember:!1};r.setCountry(t.country,n).catch(o=>{i(o,"market from another tab")})}var _=new WeakMap,S=e=>e.split("/").pop()??e;function K(e){try{window.history.replaceState(window.history.state,"",e)}catch{}}function L(e,{variant:t,sellingPlanId:r}){let n=`${t.id}|${r??""}`,o=_.get(e);if(_.set(e,n),!o||o===n)return;let s=c.variantUrl&&document.querySelector(u("product"))===e;if(!h(e,"variant-url")&&!s)return;let a=new URL(window.location.href);a.searchParams.set("variant",S(t.id)),r?a.searchParams.set("selling_plan",S(r)):a.searchParams.delete("selling_plan"),K(a)}var{Tether:T}=window;if(!T)throw new Error("tether.extras.js runs after the Tether script, which loads it");T.__parts.extras=f;})();
|