@occluze/tether 0.9.4 → 0.9.5
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 +1 -1
- package/dist/esm/chunks/{account-2467DHLU.js → account-3CDDXYNB.js} +1 -1
- package/dist/esm/chunks/{account-pages-X7U3E7D7.js → account-pages-OWJGEQ4R.js} +1 -1
- package/dist/esm/chunks/{analytics-TF7M4KI2.js → analytics-HOGB5FTF.js} +1 -1
- package/dist/esm/chunks/{chunk-KIZBET7N.js → chunk-7BUJ3442.js} +1 -1
- package/dist/esm/chunks/{chunk-HEK66LYK.js → chunk-DO7NXPVP.js} +1 -1
- package/dist/esm/chunks/{chunk-B2X6ZOKA.js → chunk-FRJ3O7I3.js} +1 -1
- package/dist/esm/chunks/{chunk-6FWNC7QH.js → chunk-GZIUGZVZ.js} +1 -1
- package/dist/esm/chunks/{chunk-AHYDU7Z6.js → chunk-HMSUZ3KF.js} +1 -1
- package/dist/esm/chunks/{chunk-67MCLHFS.js → chunk-P2CFLEGO.js} +1 -1
- package/dist/esm/chunks/chunk-RBXZXOSD.js +1 -0
- package/dist/esm/chunks/{chunk-4QINHHE4.js → chunk-RGDDFRKU.js} +1 -1
- package/dist/esm/chunks/{chunk-UM37ZVSP.js → chunk-RULKN77R.js} +1 -1
- package/dist/esm/chunks/chunk-SKYDS3DT.js +1 -0
- package/dist/esm/chunks/{chunk-EYVBEFKK.js → chunk-TMPLGTXB.js} +1 -1
- package/dist/esm/chunks/{chunk-I7XE7GQR.js → chunk-YLQXC6QC.js} +1 -1
- package/dist/esm/chunks/{chunk-C2GKO34C.js → chunk-YYWS6QKJ.js} +1 -1
- package/dist/esm/chunks/{diagnose-AOSBLXOJ.js → diagnose-ULHFOMN5.js} +1 -1
- package/dist/esm/chunks/extras-FTL2WPUG.js +1 -0
- package/dist/esm/chunks/{lists-UJMD7BCQ.js → lists-OFICUJ4T.js} +1 -1
- package/dist/esm/chunks/{markets-ui-PTAY3FHU.js → markets-ui-CZ6DAHEE.js} +1 -1
- package/dist/esm/chunks/{search-G2SRQXDG.js → search-U2KQ54KS.js} +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/server.js +1 -1
- package/dist/tether.extras.js +32 -10
- package/dist/tether.extras.min.js +1 -1
- package/dist/tether.js +27 -27
- package/dist/tether.min.js +1 -1
- package/dist/tether.min.js.map +3 -3
- package/dist/types/src/cart/store.d.ts +1 -1
- package/dist/types/src/dom.d.ts +2 -1
- package/dist/types/src/extras.d.ts +2 -0
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/chunks/chunk-5TS6IBBB.js +0 -1
- package/dist/esm/chunks/chunk-UJYL5G7T.js +0 -1
- package/dist/esm/chunks/extras-THTXX76O.js +0 -1
|
@@ -175,7 +175,7 @@ export declare function showLastKnownCount(): void;
|
|
|
175
175
|
export declare function setWarnings(notes: readonly CartWarning[]): void;
|
|
176
176
|
/** @returns A runner that starts each task once the one before has settled, whether it succeeded or failed. */
|
|
177
177
|
export declare function serial(): <T>(task: () => Promise<T>) => Promise<T>;
|
|
178
|
-
/** The one queue every cart change runs through;
|
|
178
|
+
/** The one queue every cart change runs through; checkout waits for the changes in it. */
|
|
179
179
|
export declare const runInOrder: <T>(task: () => Promise<T>) => Promise<T>;
|
|
180
180
|
/**
|
|
181
181
|
* Runs a cart change after the ones before it, so quick clicks never race. A failure sets the `error` status (shown by
|
package/dist/types/src/dom.d.ts
CHANGED
|
@@ -36,7 +36,8 @@ export declare function show(el: HTMLElement, visible: boolean): void;
|
|
|
36
36
|
/**
|
|
37
37
|
* Marks an option element as chosen: `is-selected`, the ARIA state its role takes (`chosenState`), and its own or
|
|
38
38
|
* inner radio/checkbox. An element that is no button and has no role of its own (a Webflow button is a link) gets
|
|
39
|
-
* `role="button"`, where `aria-pressed` is valid
|
|
39
|
+
* `role="button"`, where `aria-pressed` is valid, and a place in the Tab order unless it has its own `tabindex`; the
|
|
40
|
+
* product's events press it with Enter and Space.
|
|
40
41
|
*/
|
|
41
42
|
export declare function setSelected(el: Element, selected: boolean): void;
|
|
42
43
|
/**
|
|
@@ -6,6 +6,8 @@ import type { ShopifyCart } from './cart/store.js';
|
|
|
6
6
|
* @returns The cart, `null` with nothing to add or after a reported failure.
|
|
7
7
|
*/
|
|
8
8
|
export declare function addGroup(button: Element): Promise<ShopifyCart | null>;
|
|
9
|
+
/** Applies the code a `tether-discount-form` submitted; one Shopify refuses marks the form `is-invalid`. */
|
|
10
|
+
export declare function applyDiscountCode(form: Element, input: HTMLInputElement | null, code: string): Promise<void>;
|
|
9
11
|
/** Another tab changed the cart (it is loaded again here) or the visitor's market (this tab follows it). */
|
|
10
12
|
export declare function onStorage(event: StorageEvent): void;
|
|
11
13
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.9.
|
|
1
|
+
export declare const VERSION = "0.9.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occluze/tether",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Free, open-source alternative to Smootify and Storesynk (Shopyflow): Shopify products, cart and subscriptions in Webflow with HTML attributes. Optional Shopify to Webflow CMS sync.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as j,c as T,d as J,h as K}from"./chunk-KIZBET7N.js";import{a as S,b as W,c as M,d as N,e as X,f as Y,g as _,h as z,i as Z}from"./chunk-F3OXGENC.js";import{d as G,e as A,f as y,k as Q}from"./chunk-646NGAEM.js";import{c as q,f as tt}from"./chunk-UM37ZVSP.js";import{C as H,D as O,G as h,I as F,J as P,K as E,M as V,N as R,O as U,P as B,S as D,m,n as s,o as l,p as k,q as b,r as $,u as f,x as C}from"./chunk-67MCLHFS.js";import{F as L,b as p,x}from"./chunk-YW3ZIFWB.js";var et={money:O,percent:H},ct=e=>e.tagName==="INPUT";function w(e){let t=b(e,s("add-label"))[0]??e,n=t.dataset.tetherLabel??(ct(t)?t.value:t.textContent);return t.dataset.tetherLabel=n,{label:t,original:n}}function ut(e,t){let{product:n}=e,i=r=>t.selected[e.optName(r)]??"";e.$(s("option-selected")).forEach(r=>{h(r,i(l(r,"option-selected")))}),e.$(s("option-list")).forEach(r=>{let a=e.optName(l(r,"option-list"));b(r,s("option-value")).forEach(o=>{let c=l(o,"option-value")??"";P(o,t.selected[a]===c);let u=!W(n,t.selected,a,c);E(o,u),o.setAttribute("data-unavailable",u?"true":"false")})}),T(e,s("option")).forEach(r=>{r.value=i(l(r,"option"))}),T(e,s("variant-select")).forEach(r=>{r.value=t.variant.id})}function dt(e,t){let{variant:n,purchase:i,line:r}=t;e.$(s("purchase")).forEach(a=>{if(j(a)){a.value=i.kind;return}let o=l(a,"purchase");P(a,o===i.kind),E(a,o==="subscription"?!t.subscriptionAvailable:e.product.requiresSellingPlan)}),e.$(s("plan-value")).forEach(a=>{let o=l(a,"plan-value")??"";P(a,r.kind==="subscription"&&o===r.planId),E(a,!y(n,o));let c=e.plans.find(d=>d.id===o),u=Z(n,o,c,et);b(a,s("plan-bind")).forEach(d=>{let v=u.get(l(d,"plan-bind")??"");v&&h(d,v())})}),T(e,s("plan")).forEach(a=>{a.value=r.kind==="subscription"?r.planId:""})}function ht(e,t){let n=new Map(Object.entries(t.show));q.forEach(i=>n.set(i,i==="ready")),e.$(s("show")).forEach(i=>{let r=l(i,"show")??"",a=n.get(r);a!==void 0&&(q.some(o=>o===r)&&!tt(i,e.root)||F(i,a))})}function pt(e,t){let n=!t.variant.availableForSale;e.$(s("add-to-cart")).forEach(i=>{i.classList.toggle("is-disabled",n),i.setAttribute("aria-disabled",String(n)),"disabled"in i&&(i.disabled=n);let r=l(i,"soldout-text"),a=l(i,"subscribe-text");if(!r&&!a)return;let{label:o,original:c}=w(i),u=c;t.line.kind==="subscription"&&a&&(u=a),n&&r&&(u=r),i.getAttribute("aria-busy")!=="true"&&h(o,u)})}function nt(e,t){let{variant:n}=t,{product:i}=e,r=z(t,et);e.$(s("bind")).forEach(a=>{let o=l(a,"bind")??"";if(o==="variant-image"){C(a,n.image?.url||i.featuredImage?.url,n.image?.altText||i.title);return}let c=r.get(o);c&&h(a,c())}),ut(e,t),dt(e,t),ht(e,t),e.root.classList.toggle("is-subscription",t.line.kind==="subscription"),e.root.setAttribute(m("purchase-mode"),t.line.kind),pt(e,t)}var rt=()=>s("product"),mt=e=>e.tagName==="INPUT"||e.tagName==="SELECT"||e.tagName==="TEXTAREA",it=e=>e instanceof window.Element;function g(e,t,n){let i=t.closest(n);return i?.closest(rt())===e.root?i:null}function ft(e,t){let{label:n,original:i}=w(t),r=l(t,"adding-text");U(t,async()=>{r&&h(n,r);try{await e.addToCart()}catch(a){L(a,"add to cart failed"),f("error",{error:a,context:"add-to-cart"},e.root)}finally{r&&h(n,i)}}).then(()=>{e.renderVariant()}).catch(a=>{L(a,"add to cart render")})}function vt(e,t,n){let i=g(e,n,s("option-value")),r=i?.closest(s("option-list"));if(i&&r){t.preventDefault(),e.select(e.optName(l(r,"option-list")),l(i,"option-value")??"");return}let a=g(e,n,s("plan-value"));if(a){t.preventDefault(),e.selectPlan(l(a,"plan-value"));return}let o=g(e,n,`${s("purchase")}:not(select)`);if(o){o.tagName!=="INPUT"&&t.preventDefault(),e.setPurchase(at(l(o,"purchase")));return}let c=g(e,n,s("qty-plus")),u=c?null:g(e,n,s("qty-minus"));if(c||u){t.preventDefault(),e.setQuantity(e.quantity+(c?1:-1));return}let d=g(e,n,s("add-to-cart"));d&&(t.preventDefault(),ft(e,d))}var at=e=>e==="subscription"?"subscription":"one-time";function gt(e,t){let n=mt(t)?t.value:"";t.matches(`select${s("option")}`)?e.select(e.optName(l(t,"option")),n):t.matches(`select${s("variant-select")}`)?e.selectVariant(n):t.matches(`select${s("plan")}`)?n?e.selectPlan(n):e.setPurchase("one-time"):t.matches(`select${s("purchase")}`)?e.setPurchase(at(n)):t.matches(s("qty"))&&e.setQuantity(n)}function st(e){e.root.addEventListener("click",t=>{it(t.target)&&vt(e,t,t.target)}),e.root.addEventListener("change",t=>{let{target:n}=t;it(n)&&n.closest(rt())===e.root&>(e,n)})}var bt=new WeakMap,Pt=()=>s("product"),I=new Map;function Et(e){e.forEach(t=>{I.has(t.handle)||I.set(t.handle,t.options.map(n=>n.name))})}var ot=e=>e.tagName==="INPUT",yt=e=>e.tagName==="INPUT"||e.tagName==="SELECT"||e.tagName==="TEXTAREA";function Tt(e){return ot(e)&&e.type==="checkbox"?e.checked?e.value&&e.value!=="on"?e.value:"Yes":null:ot(e)&&e.type==="radio"?e.checked?e.value:null:yt(e)&&e.value||null}var lt=class{constructor(t,n){p(this,"root");p(this,"product");p(this,"plans");p(this,"selected");p(this,"purchase");p(this,"variant");p(this,"quantity");this.root=t,this.product=n,this.plans=A(n);let i=new URLSearchParams(window.location.search),r=Y(n,{variant:i.get("variant")||l(t,"variant"),sellingPlan:i.get("selling_plan"),defaultPlan:l(t,"default-plan"),defaultPurchase:l(t,"default-purchase")||x.defaultPurchase});this.selected=r.selected,this.purchase=r.purchase,this.variant=null,this.quantity=k(t,"quantity")?Math.max(0,parseInt(l(t,"quantity")??"",10)||0):1,bt.set(t,this),t.setAttribute(m("state"),"ready"),t.removeAttribute(m("error")),this.renderProduct(),st(this),this.renderVariant(),R(t,"product"),V("product"),f("product-ready",{product:n,scope:this},t)}update(t){let n=this.variant?.id;this.product=t,this.plans=A(t);let i=t.variants.nodes.find(r=>r.id===n);i&&(this.selected=S(i)),this.root.setAttribute(m("state"),"ready"),this.root.removeAttribute(m("error")),this.renderProduct(),this.renderVariant(),V("product"),f("product-updated",{product:t,scope:this},this.root)}$(t){let n=$(this.root,t,Pt());return this.root.matches(t)?[this.root,...n]:n}optName(t){if(!t)return"";let{options:n}=this.product;if(n.some(r=>r.name===t))return t;let i=(I.get(this.product.handle)??[]).indexOf(t);return n[i]?.name??t}get plan(){let t=M(this.purchase);return this.plans.find(n=>n.id===t)??null}get subscriptionAvailable(){return this.plans.some(t=>y(this.variant,t.id))}get isSubscription(){return N(this.purchase,this.variant).kind==="subscription"}getLine(){if(!this.variant)return null;let t={merchandiseId:this.variant.id,quantity:this.quantity},n=N(this.purchase,this.variant);n.kind==="subscription"&&(t.sellingPlanId=n.planId);let i=this.collectAttributes();return i.length&&(t.attributes=i),t}collectAttributes(){let t=D(B(this.root,"line-attributes")),n=this.$(s("line-attribute")).flatMap(i=>{let r=Tt(i);return r===null?[]:[{key:l(i,"line-attribute")??"",value:r}]});return[...t,...n]}select(t,n){if(this.selected[t]===n)return;let i=this.product.variants.nodes.filter(o=>o.selectedOptions.some(c=>c.name===t&&c.value===n)),[r]=i;if(!r)return;let a={...this.selected,[t]:n};if(!i.some(o=>o.selectedOptions.every(c=>a[c.name]===c.value))){let o=u=>u.selectedOptions.filter(v=>v.name!==t&&this.selected[v.name]===v.value).length*2+(u.availableForSale?1:0),c=i.reduce((u,d)=>o(d)>o(u)?d:u,r);Object.assign(a,S(c))}this.selected=a,this.renderVariant()}selectVariant(t){let n=this.product.variants.nodes.find(i=>i.id===G.variant(t));n&&(this.selected=S(n),this.renderVariant())}setPurchase(t){let n=X(this.product,this.variant,t,M(this.purchase));n.kind!==this.purchase.kind&&(this.purchase=n,this.renderVariant())}selectPlan(t){let n=Q(this.product,t);n&&(this.purchase={kind:"subscription",planId:n.id},this.renderVariant())}setQuantity(t){let n=k(this.root,"quantity")?0:1;this.quantity=Math.max(n,parseInt(String(t),10)||0),this.$(s("qty")).forEach(i=>{h(i,this.quantity)}),this.renderVariant()}async addToCart(){if(!this.variant?.availableForSale)return null;let t=this.getLine();if(!t||t.quantity<1)return null;let n=await K.add(t);return f("product-added",{product:this.product,variant:this.variant,line:t},this.root),n}renderProduct(){let{product:t}=this;I.has(t.handle)||this.$(`${s("option-list")},select${s("option")}`).map(i=>l(i,"option-list")||l(i,"option")).some(i=>t.options.some(r=>r.name===i))&&Et([t]),J(this)}renderVariant(){let t=_(this.product,{selected:this.selected,purchase:this.purchase,quantity:this.quantity},x.lowStock);if(!t){this.variant=null;return}this.variant=t.variant,this.selected=t.selected,this.purchase=t.purchase,nt(this,t),f("variant-changed",{product:this.product,variant:t.variant,selected:{...t.selected},purchase:t.purchase.kind,sellingPlanId:t.line.kind==="subscription"?t.line.planId:null},this.root)}};export{bt as a,Et as b,lt as c};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e={diagnose:()=>import("./diagnose-AOSBLXOJ.js"),markets:()=>import("./markets-ui-PTAY3FHU.js"),search:()=>import("./search-G2SRQXDG.js"),lists:()=>import("./lists-UJMD7BCQ.js"),extras:()=>import("./extras-THTXX76O.js"),account:()=>import("./account-2467DHLU.js"),"account-pages":()=>import("./account-pages-X7U3E7D7.js"),analytics:()=>import("./analytics-TF7M4KI2.js")},a=t=>e[t](),o=void 0;export{a,o as b};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as v}from"./chunk-B2X6ZOKA.js";import{a as b,b as S}from"./chunk-HEK66LYK.js";import{a as k}from"./chunk-5TS6IBBB.js";import{h as p}from"./chunk-KIZBET7N.js";import"./chunk-F3OXGENC.js";import"./chunk-646NGAEM.js";import"./chunk-UJYL5G7T.js";import"./chunk-UM37ZVSP.js";import"./chunk-I7XE7GQR.js";import"./chunk-6FWNC7QH.js";import{P as h,S as w,n as l,o as f,p as g,q as d,u as y}from"./chunk-67MCLHFS.js";import{E as m,F as u,x as s}from"./chunk-YW3ZIFWB.js";function U(t,r){let e=w(h(t,"line-attributes"));return r?[{key:"_group",value:r},...e]:e}async function V(t){let r=t.closest(l("group"));if(!r)return null;let e=f(r,"group"),n=U(r,e),i=d(r,l("product")).flatMap(a=>{let o=k.get(a);if(!o?.variant?.availableForSale||o.quantity<=0)return[];let c=o.getLine();return c?[{...c,attributes:[...c.attributes??[],...n]}]:[]});if(!i.length)return m("group-add: nothing selected"),null;try{let a=await p.add(i);return y("group-added",{group:e,lines:i},r),a}catch(a){return u(a,"group add"),null}}function _(t){if(t.key===s.storageKey||t.key===`${s.storageKey}:seen`){p.init().catch(n=>{u(n,"cart from another tab")});return}if(t.key!==b()||!t.newValue)return;let r=S(t.newValue);if(!r)return;let e={language:r.language??null,locale:r.locale,remember:!1};v(r.country,e).catch(n=>{u(n,"market from another tab")})}var E=new WeakMap,K=t=>t.split("/").pop()??t;function x(t){try{window.history.replaceState(window.history.state,"",t)}catch{}}function $(t,{variant:r,sellingPlanId:e}){let n=`${r.id}|${e??""}`,i=E.get(t);if(E.set(t,n),!i||i===n)return;let a=s.variantUrl&&document.querySelector(l("product"))===t;if(!g(t,"variant-url")&&!a)return;let o=new URL(window.location.href);o.searchParams.set("variant",K(r.id)),e?o.searchParams.set("selling_plan",K(e)):o.searchParams.delete("selling_plan"),x(o)}export{V as addGroup,_ as onStorage,$ as writeVariantUrl};
|