metatroncubeswdev db85f3263d fix(build): make every extension build for shopify app deploy
- functions: add codegen config and the downloaded schema.graphql (generated/ ignored)
- order-reschedule: add the @preact/signals peer dependency
- widget: source moved to widget-src/, minified build in assets (npm run build:widget,
  also run by predeploy); e2e passes on the minified file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 00:47:08 -04:00

2 lines
18 KiB
JavaScript

"use strict";(function(){"use strict";if(window.__datewiseLoaded)return;window.__datewiseLoaded=!0;var x=document.querySelector("[data-datewise-config]"),m={};try{m=x?JSON.parse(x.textContent):{}}catch{m={}}var l=Object.assign({choose:"Pick a highlighted date",needTime:"Please choose a delivery or pickup time before checking out.",held:"Held for you for",expired:"Your hold expired. Tap the time again to check it's still free.",left:"left",full:"Full",postal:"Postal / ZIP code",check:"Check",waitlist:"Join the waitlist",joined:"You're on the waitlist. We'll message you if a place opens.",dispatch:"Ships this day (not an arrival date)",change:"Change",prep:"Earliest times include preparation for",free:"Free",fee:"fee",nextAvailable:"Next available",offer:"A place opened up and we're holding it for you",error:"Something went wrong. Please try again."},m.text||{}),N=(window.Shopify&&Shopify.routes&&Shopify.routes.root||"/").replace(/\/?$/,"/"),X=N+"apps/datewise",g=m.locale||document.documentElement.lang||"en",ee=m.currency||window.Shopify&&Shopify.currency&&Shopify.currency.active||"CAD",U="_datewise";function _(e){try{return localStorage.getItem("datewise_"+e)}catch{return null}}function w(e,t){try{t==null?localStorage.removeItem("datewise_"+e):localStorage.setItem("datewise_"+e,t)}catch{}}var a={data:null,cart:null,lines:[],loading:!1,message:null,messageTone:"info",method:_("method"),locationId:_("location"),postal:_("postal")||"",date:null,sel:null,token:_("token"),expiresAt:null,heldAt:null,monthOffset:0,waitlistDone:!1,mutating:0};function i(e){return String(e==null?"":e).replace(/[&<>"']/g,function(t){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[t]})}function T(e){try{return new Intl.NumberFormat(g,{style:"currency",currency:ee}).format(e/100)}catch{return"$"+(e/100).toFixed(2)}}function b(e,t){return new Intl.DateTimeFormat(g,{weekday:t?"long":"short",month:t?"long":"short",day:"numeric",timeZone:"UTC"}).format(new Date(e+"T12:00:00Z"))}function j(e){var t=e.split(":");return new Intl.DateTimeFormat(g,{hour:"numeric",minute:t[1]==="00"?void 0:"2-digit",timeZone:"UTC"}).format(new Date(Date.UTC(2e3,0,1,+t[0],+t[1])))}function q(e){return j(e.start)+" \u2013 "+j(e.end)}function te(e,t){var n=+e.slice(0,4),r=+e.slice(5,7)-1+t;return n+=Math.floor(r/12),r=(r%12+12)%12,n+"-"+String(r+1).padStart(2,"0")}function ae(e){return new Date(Date.UTC(+e.slice(0,4),+e.slice(5,7),0)).getUTCDate()}var ne={pickup:'<path d="M4 10v9h16v-9M3 10l1.5-5h15L21 10M3 10h18M3 10c0 1.4 1.3 2.5 3 2.5S9 11.4 9 10c0 1.4 1.3 2.5 3 2.5s3-1.1 3-2.5c0 1.4 1.3 2.5 3 2.5s3-1.1 3-2.5M10 19v-4h4v4"/>',delivery:'<path d="M2 6h11v10H2zM13 9h4.5l3.5 3.5V16h-8M6.5 18.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3zM17 18.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3z"/>',shipping:'<path d="M3.5 7.5 12 3l8.5 4.5v9L12 21l-8.5-4.5zM3.5 7.5 12 12l8.5-4.5M12 12v9M7.8 5.3l8.5 4.5"/>'};function P(e){return'<svg class="dw-ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round">'+(ne[e]||"")+"</svg>"}function re(e){return new Date(e+"T12:00:00Z").getUTCDay()}function S(e,t,n){var r=X+e,o={method:n||"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},credentials:"same-origin"};return t&&o.method!=="GET"&&(o.body=JSON.stringify(t)),L(r,o).then(function(d){return d.json().catch(function(){return{ok:!1,message:l.error}})})}function A(e,t){return a.mutating++,L(N+e,{method:t?"POST":"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},body:t?JSON.stringify(t):void 0,credentials:"same-origin"}).then(function(n){return n.json()}).finally(function(){setTimeout(function(){a.mutating--},50)})}function F(){return A("cart.js").then(function(e){a.cart=e,a.lines=e.items.filter(function(r){return!(r.properties&&r.properties._datewise_fee)}).map(function(r){return{variantId:r.variant_id,quantity:r.quantity,price:r.final_price,title:r.product_title}});var t=e.attributes&&e.attributes[U];if(t)try{var n=JSON.parse(t);a.sel={method:n.m,locationId:n.l,date:n.d,slot:n.s,fee:n.f},a.token=n.t,w("token",n.t),a.method=a.method||n.m,a.locationId=a.locationId||n.l,a.date=a.date||n.d}catch{a.sel=null}else a.sel=null;return e})}function ie(){return(a.cart?a.cart.items:[]).filter(function(e){return e.properties&&e.properties._datewise_fee})}function R(e){var t=ie(),n=Promise.resolve(),r=null;t.forEach(function(d){!r&&e&&String(d.variant_id)===String(e)&&d.quantity===1?r=d:n=n.then(function(){return A("cart/change.js",{id:d.key,quantity:0})})}),e&&!r&&(n=n.then(function(){return A("cart/add.js",{items:[{id:Number(e),quantity:1,properties:{_datewise_fee:"1"}}]})}));var o=t.length!==(r?1:0)||e&&!r;return n.then(function(){return o})}function B(e){var t=[];try{t=JSON.parse(_("keys")||"[]")}catch{}var n={};return t.forEach(function(r){n[r]=""}),Object.keys(e).forEach(function(r){n[r]=e[r]}),w("keys",JSON.stringify(Object.keys(e))),A("cart/update.js",{attributes:n})}function Z(e){var t={source:"datewise"};["cart:refresh","cart:updated","cart:change","theme:cart:change"].forEach(function(n){document.dispatchEvent(new CustomEvent(n,{detail:t,bubbles:!0}))}),typeof window.publish=="function"&&window.PUB_SUB_EVENTS?F().then(function(n){window.publish(window.PUB_SUB_EVENTS.cartUpdate,{source:"datewise",cartData:n})}):e&&/\/cart\/?$/.test(location.pathname)&&setTimeout(function(){location.reload()},300)}function C(e){var t=a.token;return a.sel=null,a.expiresAt=null,e&&p(e,"critical"),t&&S("/release",{token:t}).catch(function(){}),B({[U]:""}).then(function(){return R(null)}).then(function(n){w("keys","[]"),n&&Z(!0)})}var G=null;function h(e){clearTimeout(G),G=setTimeout(H,e?0:300)}function H(){return!M().length&&!m.checkoutGuard?Promise.resolve():(a.loading=!0,f(),F().then(function(){if(!a.lines.length){a.data=null,a.loading=!1,a.sel&&C(null),f();return}return S("/availability",{lines:a.lines,method:a.method||void 0,locationId:a.locationId||void 0,postal:a.postal||void 0,token:a.token||void 0,locale:g}).then(function(e){if(a.loading=!1,!e||e.ok===!1){p(e&&e.message||l.error,"critical"),f();return}a.data=e,a.method=e.method,a.locationId=e.locationId,se(),f()})}).catch(function(){a.loading=!1,p(l.error,"critical"),f()}))}function oe(e,t){var n=a.data&&a.data.dates.filter(function(r){return r.date===e})[0];return{d:n,s:n&&n.slots.filter(function(r){return r.id===t})[0]}}function se(){if(a.sel){var e=a.data;if(!e||e.method!==a.sel.method||e.locationId!==a.sel.locationId)return C(null);var t=oe(a.sel.date,a.sel.slot);if(!t.s||!t.s.available){var n=t.s&&t.s.reason||t.d&&t.d.reasons[0]||"";C(n?n+". "+l.choose+".":l.choose)}}}function J(e,t){if(a.data)return p(null),a.loading=!0,f(),S("/hold",{lines:a.lines,method:a.data.method,locationId:a.data.locationId,date:e,slot:t,token:a.token||void 0,postal:a.postal||void 0,locale:g}).then(function(n){if(!n.ok){a.loading=!1,p(n.message||l.error,"critical"),h(!0);return}return a.token=n.token,w("token",n.token),a.expiresAt=Date.parse(n.expiresAt),a.heldAt=Date.now(),a.sel={method:a.data.method,locationId:a.data.locationId,date:e,slot:t,fee:n.fee?n.fee.fee:0},B(n.attributes).then(function(){return R(n.feeVariantId)}).then(function(r){a.loading=!1,f(),Z(r)})}).catch(function(){a.loading=!1,p(l.error,"critical"),f()})}function p(e,t){a.message=e,a.messageTone=t||"info"}function M(){return Array.prototype.slice.call(document.querySelectorAll("[data-datewise-root]"))}function f(){M().forEach(V)}function V(e){e.classList.contains("datewise")||e.classList.add("datewise");var t=a.data,n=e.getAttribute("data-heading")||t&&t.text&&t.text.heading||"";t&&t.text&&t.text.accent&&e.style.setProperty("--dw-accent",t.text.accent);var r="";if(n&&(r+='<h2 class="dw-h">'+i(n)+"</h2>"),r+='<div class="dw-live" role="status" aria-live="polite">'+(a.message?'<p class="dw-msg dw-'+a.messageTone+'">'+i(a.message)+"</p>":"")+"</div>",!t){e.innerHTML=r+(a.loading?'<div class="dw-skeleton" aria-hidden="true"></div>':""),e.setAttribute("aria-busy",a.loading);return}if(r+='<div class="dw-methods" role="group" aria-label="Delivery method">',t.methods.forEach(function(s){var v=s.method===t.method;r+='<button type="button" class="dw-method" data-dw="method" data-v="'+s.method+'" aria-pressed="'+v+'"'+(s.available||v?"":' aria-disabled="true"')+">"+P(s.method)+"<b>"+i(t.text.labels[s.method])+"</b><small>"+(s.needsAddress?i(l.postal):s.available?s.firstDate?i(l.nextAvailable+": "+b(s.firstDate)):"":i(s.reason||""))+"</small></button>"}),r+="</div>",!t.method){e.innerHTML=r;return}if(t.method==="delivery"&&(r+='<form class="dw-postal" data-dw="postal"><label for="dw-postal-'+$(e)+'">'+i(l.postal)+'</label><div class="dw-row"><input id="dw-postal-'+$(e)+'" name="postal" autocomplete="postal-code" value="'+i(a.postal)+'"><button type="submit">'+i(l.check)+"</button></div></form>"),t.split&&(r+='<p class="dw-msg dw-critical">'+i(t.split)+"</p>"),t.method!=="shipping"&&t.locations.length>1)r+='<div class="dw-locs" role="group" aria-label="Location">',t.locations.forEach(function(s){var v=s.id===t.locationId,O=s.fee?s.fee.waived?l.free:T(s.fee.fee):s.distanceKm!=null?s.distanceKm+" km":"";r+='<button type="button" class="dw-loc" data-dw="loc" data-v="'+i(s.id)+'" aria-pressed="'+v+'"'+(s.eligible?"":' aria-disabled="true"')+"><span><b>"+i(s.name)+"</b><small>"+i(s.eligible?s.first?l.nextAvailable+": "+b(s.first.date):"":s.reason||"")+"</small></span><span>"+i(O)+"</span></button>"}),r+="</div>";else if(t.locationId){var o=t.locations.filter(function(s){return s.id===t.locationId})[0];o&&t.method!=="shipping"&&(r+='<p class="dw-note">'+i(o.name)+(o.fee?" \xB7 "+(o.fee.waived?l.free:T(o.fee.fee)+" "+l.fee):"")+"</p>")}if(!t.locationId){if(t.needsAddress){e.innerHTML=r;return}var d=t.locations[0]&&t.locations[0].reason;e.innerHTML=r+(d?'<p class="dw-msg dw-critical">'+i(d)+"</p>":"");return}t.prepNote&&t.prepNote.minutes>=60&&(r+='<p class="dw-note">'+i(l.prep+" "+t.prepNote.item)+" ("+Math.round(t.prepNote.minutes/6)/10+" h)</p>");var c=t.dates.filter(function(s){return s.peak&&s.peak.message})[0];c&&(r+='<p class="dw-msg dw-peak">'+i(c.peak.message)+"</p>"),r+=de(t),r+=ce(t,e),e.innerHTML=r,e.setAttribute("aria-busy",a.loading),z()}var le=0;function $(e){return e.__dwid||(e.__dwid=++le),e.__dwid}function de(e){var t={};e.dates.forEach(function(D){t[D.date]=D});var n=(e.dates.filter(function(D){return D.available})[0]||e.dates[0]||{}).date;if(!n)return"";for(var r=te(n.slice(0,7),a.monthOffset),o=e.text.weekStartsOn||0,d=r+"-01",c=(re(d)-o+7)%7,s='<div class="dw-cal"><div class="dw-calhead"><button type="button" data-dw="month" data-v="-1" aria-label="Previous month">\u2039</button><b>'+i(new Intl.DateTimeFormat(g,{month:"long",year:"numeric",timeZone:"UTC"}).format(new Date(d+"T12:00:00Z")))+'</b><button type="button" data-dw="month" data-v="1" aria-label="Next month">\u203A</button></div><div class="dw-grid" role="grid">',v=0;v<7;v++){var O=(o+v)%7;s+='<span class="dw-dow" aria-hidden="true">'+i(new Intl.DateTimeFormat(g,{weekday:"narrow",timeZone:"UTC"}).format(new Date(Date.UTC(2023,0,1+O))))+"</span>"}for(var W=0;W<c;W++)s+="<span></span>";for(var I=1;I<=ae(r);I++){var k=r+"-"+String(I).padStart(2,"0"),u=t[k],y="dw-day",E=b(k,!0),Q="";u?u.available?(y+=" dw-avail",e.text.showRemaining&&u.remaining!=null&&u.remaining<=5&&(Q='<i class="dw-left">'+u.remaining+"</i>")):u.waitlist||/full|booked/i.test(u.reasons[0]||"")?(y+=" dw-full",E+=", "+l.full):(y+=" dw-closed",E+=", "+(u.reasons[0]||"")):y+=" dw-out",a.date===k&&(y+=" dw-sel"),u&&u.peak&&(y+=" dw-peakday",E+=", "+u.peak.name),s+='<button type="button" class="'+y+'" data-dw="date" data-v="'+k+'" aria-label="'+i(E)+'"'+(u&&(u.available||u.waitlist||u.reasons.length)?"":' aria-disabled="true"')+' tabindex="'+(a.date===k||!a.date&&k===n?"0":"-1")+'">'+I+Q+"</button>"}return s+"</div></div>"}function ce(e,t){if(!a.date)return'<p class="dw-note">'+i(l.choose)+"</p>";var n=e.dates.filter(function(o){return o.date===a.date})[0];if(!n)return"";var r='<div class="dw-day-detail"><h3>'+i(b(n.date,!0))+(n.peak?' <span class="dw-badge">'+i(n.peak.name)+"</span>":"")+"</h3>";return e.dateOnly&&(r+='<p class="dw-note">'+i(l.dispatch)+"</p>"),n.available?(r+='<div class="dw-slots" role="group" aria-label="Times">',n.slots.forEach(function(o){var d=a.sel&&a.sel.date===n.date&&a.sel.slot===o.id,c=o.available?(e.text.showRemaining&&o.remaining!=null?o.remaining+" "+l.left:"")+(o.surcharge?(o.remaining!=null&&e.text.showRemaining?" \xB7 ":"")+"+"+T(o.surcharge):""):o.reason||"";r+='<button type="button" class="dw-slot" data-dw="slot" data-v="'+o.id+'" aria-pressed="'+!!d+'"'+(o.available||d?"":' aria-disabled="true"')+"><b>"+i(e.dateOnly?b(n.date):q(o))+"</b><small>"+i(c)+"</small></button>"}),r+="</div>",a.sel&&a.sel.date===n.date&&(r+=ue(e,n)),r+"</div>"):(r+='<p class="dw-msg '+(n.waitlist?"dw-peak":"dw-critical")+'">'+i(n.reasons.join(". "))+"</p>",n.waitlist&&!a.waitlistDone&&(r+='<form class="dw-row" data-dw="waitlist"><input type="email" name="email" required placeholder="Email" aria-label="Email"><button type="submit">'+i(l.waitlist)+"</button></form>"),a.waitlistDone&&(r+='<p class="dw-msg dw-success">'+i(l.joined)+"</p>"),r+"</div>")}function ue(e,t){var n=e.locations.filter(function(s){return s.id===e.locationId})[0],r=t.slots.filter(function(s){return s.id===a.sel.slot})[0],o=a.expiresAt&&a.expiresAt>Date.now(),d=a.expiresAt&&!o,c='<div class="dw-stub'+(d?" dw-stub--expired":"")+'"><div class="dw-stub__main"><span class="dw-stub__method">'+P(e.method)+i(e.text.labels[e.method])+(n&&e.method!=="shipping"?", "+i(n.name):"")+'</span><b class="dw-stub__date">'+i(b(t.date,!0))+"</b>"+(r&&!e.dateOnly?'<span class="dw-stub__time">'+i(q(r))+"</span>":"")+(a.sel.fee?'<span class="dw-stub__fee">+'+i(T(a.sel.fee))+" "+i(l.fee)+"</span>":"")+'</div><div class="dw-stub__side">';return o?c+='<svg class="dw-ring" viewBox="0 0 36 36" aria-hidden="true"><circle cx="18" cy="18" r="15.5"/><circle class="dw-ring__arc" data-dw-ring cx="18" cy="18" r="15.5" pathLength="100"/></svg><span class="dw-stub__hold">'+i(l.held)+" <b data-dw-timer></b></span>":d?c+='<span class="dw-stub__hold">'+i(l.expired)+"</span>":c+='<svg class="dw-check" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5 10 17l9-10"/></svg>',c+="</div></div>",n&&n.pickupInstructions&&e.method==="pickup"&&(c+='<p class="dw-note">'+i(n.pickupInstructions)+"</p>"),c}function z(){var e=a.expiresAt?a.expiresAt-Date.now():0,t=document.querySelectorAll("[data-dw-timer]");if(e<=0&&t.length)return f();for(var n=Math.max(0,Math.round(e/1e3)),r=0;r<t.length;r++)t[r].textContent=Math.floor(n/60)+":"+String(n%60).padStart(2,"0");for(var o=a.expiresAt&&a.heldAt?a.expiresAt-a.heldAt:0,d=document.querySelectorAll("[data-dw-ring]"),c=0;c<d.length;c++)d[c].style.strokeDashoffset=o>0?String(100-Math.max(0,Math.min(100,e/o*100))):"0"}setInterval(z,1e3),document.addEventListener("click",function(e){var t=e.target.closest&&e.target.closest("[data-datewise-root] [data-dw]");if(!(!t||t.tagName==="FORM")&&!(t.getAttribute("aria-disabled")==="true"&&t.getAttribute("data-dw")!=="date")){var n=t.getAttribute("data-dw"),r=t.getAttribute("data-v");n==="method"&&r!==a.method?(a.method=r,w("method",r),a.date=null,a.monthOffset=0,h(!0)):n==="loc"&&r!==a.locationId?(a.locationId=r,w("location",r),a.date=null,h(!0)):n==="month"?(a.monthOffset+=+r,f()):n==="date"?(a.date=r,a.waitlistDone=!1,p(null),f(),fe(".dw-slot:not([aria-disabled])")):n==="slot"&&J(a.date,r)}}),document.addEventListener("submit",function(e){var t=e.target;if(!(!t.closest||!t.closest("[data-datewise-root]"))){var n=t.getAttribute("data-dw");n&&(e.preventDefault(),n==="postal"&&(a.postal=t.postal.value.trim(),w("postal",a.postal),a.date=null,h(!0)),n==="waitlist"&&a.data&&S("/waitlist",{method:a.data.method,locationId:a.data.locationId,date:a.date,slot:"*",email:t.email.value.trim()}).then(function(r){r.ok?a.waitlistDone=!0:p(r.message||l.error,"critical"),f()}))}}),document.addEventListener("keydown",function(e){var t=e.target;if(!(!t.classList||!t.classList.contains("dw-day"))){var n={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[e.key];if(n){var r=Array.prototype.slice.call(t.parentNode.querySelectorAll(".dw-day")),o=r[r.indexOf(t)+n];o&&(e.preventDefault(),t.tabIndex=-1,o.tabIndex=0,o.focus())}}});function fe(e){setTimeout(function(){var t=document.querySelector("[data-datewise-root] "+e);t&&t.focus()},0)}function pe(){return a.data&&a.data.requireScheduling&&a.lines.length>0&&!a.sel}function he(e){if(!(!m.checkoutGuard||!pe())){var t=e.target.closest&&e.target.closest('[name="checkout"], a[href$="/checkout"], form[action$="/checkout"] [type="submit"]');if(t){e.preventDefault(),e.stopPropagation(),p(l.needTime,"critical"),f();var n=M()[0];n&&n.scrollIntoView({behavior:"smooth",block:"center"})}}}document.addEventListener("click",he,!0);var L=window.fetch.bind(window);window.fetch=function(e,t){var n=typeof e=="string"?e:e&&e.url,r=L(e,t);return n&&/\/cart\/(add|change|update|clear)(\.js)?/.test(n)&&!a.mutating&&r.then(function(){h()}),r},["cart:updated","cart:change","cart-drawer:open","ajaxCart:updated"].forEach(function(e){document.addEventListener(e,function(t){t.detail&&t.detail.source==="datewise"||h()})}),typeof window.subscribe=="function"&&window.PUB_SUB_EVENTS&&window.subscribe(window.PUB_SUB_EVENTS.cartUpdate,function(e){(!e||e.source!=="datewise")&&h()});var Y=[m.drawerSelector,"cart-drawer .drawer__footer","#CartDrawer .drawer__footer","#CartDrawer-Footer",".cart-drawer__footer","#cart-drawer .cart__footer",".js-cart-drawer .cart-drawer__footer","[data-cart-drawer] footer"].filter(Boolean);function K(){for(var e=0;e<Y.length;e++){var t=document.querySelector(Y[e]);if(t&&!t.querySelector("[data-datewise-root]")){var n=document.createElement("div");n.className="datewise datewise--drawer",n.setAttribute("data-datewise-root",""),n.setAttribute("data-drawer",""),t.insertBefore(n,t.firstChild),a.data?V(n):h(!0);return}}}x&&(K(),new MutationObserver(function(){K()}).observe(document.body,{childList:!0,subtree:!0}));function me(){var e=location.search.match(/[?&]datewise_offer=([^&]+)/);return e?S("/offer?token="+encodeURIComponent(e[1]),null,"GET").then(function(t){if(!t.ok){p(t.message,"critical");return}return a.token=t.token,w("token",t.token),a.method=t.method,a.locationId=t.locationId,a.date=t.date,p(l.offer+": "+b(t.date,!0)+".","success"),H().then(function(){if(a.data&&a.data.locationId===t.locationId)return J(t.date,t.slot)})}):Promise.resolve()}me().then(function(){a.data||h(!0)})})();