@momentco-ai/moment-sdk 0.2.0-dev.13 → 0.2.0
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/dist/moment-sdk.js +1 -1
- package/dist/moment-sdk.mjs +51 -46
- package/dist/types/sdk/types.d.ts +10 -1
- package/package.json +1 -1
package/dist/moment-sdk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h){"use strict";class y{popup=null;pollTimer=null;messageHandler=null;resultReceived=!1;opts;constructor(e){this.opts=e}open(e){this.cleanup(),this.resultReceived=!1;const t=this.buildPopupUrl(e),n=Math.round(window.screenX+(window.outerWidth-500)/2),r=Math.round(window.screenY+(window.outerHeight-700)/2);if(this.popup=window.open(t,"moment-oauth-popup",`width=500,height=700,left=${n},top=${r},menubar=no,toolbar=no,location=yes,status=no`),!this.popup||this.popup.closed){this.sendStatusToIframe("popup-blocked"),this.opts.onPopupBlocked();return}this.sendStatusToIframe("popup-opened"),this.startPolling(),this.messageHandler=i=>{if(i.origin!==this.opts.liveOrigin||i.source!==this.popup)return;const s=i.data;!s||typeof s!="object"||s.source!=="moment-live-embed"||s.type!=="moment.embed.result"||(this.resultReceived=!0,this.sendStatusToIframe("completed"),this.opts.iframeWindow&&this.opts.iframeWindow.postMessage(s,this.opts.liveOrigin),this.opts.onResult(s),this.cleanup())},window.addEventListener("message",this.messageHandler)}cleanup(){if(this.pollTimer&&(clearInterval(this.pollTimer),this.pollTimer=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.popup&&!this.popup.closed)try{this.popup.close()}catch{}this.popup=null}buildPopupUrl(e){const t=window.location.origin,n=new URLSearchParams({provider:e.provider,teamSlug:e.teamSlug,ids:e.ids.join(","),triggerType:e.triggerType,returnOrigin:t});return e.subscriptionType&&n.set("subscriptionType",e.subscriptionType),`${this.opts.liveBaseUrl}/en/embed/oauth-popup?${n.toString()}`}startPolling(){this.pollTimer=setInterval(()=>{(!this.popup||this.popup.closed)&&(this.pollTimer&&(clearInterval(this.pollTimer),this.pollTimer=null),this.resultReceived||(this.sendStatusToIframe("popup-closed"),this.opts.onPopupClosed()),this.cleanup())},500)}sendStatusToIframe(e){if(!this.opts.iframeWindow)return;const t={source:"moment-sdk",type:"moment.embed.oauth.status",status:e};this.opts.iframeWindow.postMessage(t,this.opts.liveOrigin)}}const w=".moment-sync-trigger",T="https://live.dev.momentco.ai";class g{opts;liveBaseUrl;liveOrigin;overlay=null;iframe=null;popupBridge=null;messageHandler=null;boundClickHandlers=new Map;activePayload=null;previousFocusedElement=null;previousBodyOverflow="";didManageBodyOverflow=!1;closeTimer=null;constructor(e){this.opts={triggerSelector:w,...e},this.liveBaseUrl=T;try{this.liveOrigin=new URL(this.liveBaseUrl).origin}catch{throw new Error(`[MomentSdk] Invalid VITE_LIVE_BASE_URL: "${this.liveBaseUrl}"`)}this.bindTriggers(),this.emitAnalytics("embed.init")}open(e){this.emitAnalytics("embed.open",{teamSlug:e.teamSlug,triggerType:e.triggerType}),this.createModal(e)}close(){this.handleCancel()}rebind(){this.unbindTriggers(),this.bindTriggers()}destroy(){this.cleanup(),this.unbindTriggers()}bindTriggers(){document.querySelectorAll(this.opts.triggerSelector).forEach(t=>{const n=i=>{i.preventDefault(),this.handleTriggerClick(t)},r=this.boundClickHandlers.get(t);r&&t.removeEventListener("click",r),t.addEventListener("click",n),this.boundClickHandlers.set(t,n)})}unbindTriggers(){this.boundClickHandlers.forEach((e,t)=>{t.removeEventListener("click",e)}),this.boundClickHandlers.clear()}handleTriggerClick(e){const t=e.getAttribute("data-moment-team-slug")??"",n=e.getAttribute("data-moment-slug")??void 0,r=e.getAttribute("data-moment-list-slug")??void 0,i=e.getAttribute("data-moment-trigger-type");let s="moment";i!=null&&i!==""&&(i==="moment"||i==="list"||i==="team"?s=i:console.warn("[MomentSdk] Invalid data-moment-trigger-type, falling back to 'moment':",i));const d=e.getAttribute("data-moment-ids")??e.getAttribute("data-moment-game-id")??"",u=d?d.split(",").filter(Boolean):[],a=e.getAttribute("data-moment-calendar");let m;if(a!=null&&a!==""&&(a==="google"||a==="outlook"?m=a:console.warn("[MomentSdk] Invalid data-moment-calendar, ignoring value:",a)),!t){console.warn("[MomentSdk] Missing data-moment-team-slug on trigger element");return}const l=s==="team"?void 0:n,c=s==="team"?void 0:r,p=s==="team"?[]:u;this.emitAnalytics("embed.trigger.click",{teamSlug:t,triggerType:s,momentIds:p}),this.open({teamSlug:t,momentSlug:l,listSlug:c,triggerType:s,ids:p,calendar:m??void 0})}createModal(e){this.cleanup(),this.previousFocusedElement=document.activeElement||null,this.activePayload=e;const t=this.buildIframeUrl(e);this.overlay=document.createElement("div"),this.overlay.setAttribute("role","presentation"),Object.assign(this.overlay.style,{position:"fixed",inset:"0",zIndex:"999999",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",padding:"16px"}),this.overlay.addEventListener("click",l=>{l.target===this.overlay&&this.handleCancel()});const n=l=>{l.key==="Escape"&&this.handleCancel()};document.addEventListener("keydown",n);const r=document.createElement("div");Object.assign(r.style,{position:"relative",width:"100%",maxWidth:"380px",borderRadius:"16px",overflow:"hidden",backgroundColor:"#000000",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"});const i=document.createElement("div");i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true"),i.setAttribute("aria-label","Calendar sync modal"),i.tabIndex=-1,Object.assign(i.style,{position:"relative",width:"100%",maxHeight:"80vh",borderRadius:"12px",overflow:"auto",backgroundColor:"#ffffff"});const s=document.createElement("button");s.type="button",s.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>',s.setAttribute("aria-label","Close"),Object.assign(s.style,{position:"absolute",top:"10px",right:"10px",zIndex:"10",border:"none",backgroundColor:"transparent",color:"#999",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",padding:"0"}),s.addEventListener("mouseenter",()=>{s.style.color="#666"}),s.addEventListener("mouseleave",()=>{s.style.color="#999"}),s.addEventListener("click",()=>this.handleCancel()),this.iframe=document.createElement("iframe"),this.iframe.src=t,this.iframe.setAttribute("allow",""),this.iframe.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),this.iframe.setAttribute("scrolling","no"),Object.assign(this.iframe.style,{width:"100%",border:"none",display:"block",height:"420px",overflow:"hidden",transition:"height 0.15s ease"}),i.appendChild(s),i.appendChild(this.iframe);const d=document.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"12px 0"});const u=document.createElement("span");u.textContent="Powered by",Object.assign(u.style,{fontFamily:"Inter, system-ui, -apple-system, sans-serif",fontSize:"12px",lineHeight:"16px",color:"#ffffff"});const a=document.createElement("img");a.alt="Moment",a.src=`${this.liveBaseUrl}/brand/moment-text-white.png`,Object.assign(a.style,{height:"auto",width:"67px"}),d.appendChild(u),d.appendChild(a),r.appendChild(i),r.appendChild(d),this.overlay.appendChild(r),document.body.appendChild(this.overlay);const m=l=>{if(l.key!=="Tab")return;const c=i.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(c.length===0){l.preventDefault(),i.focus();return}const p=c[0],v=c[c.length-1],b=document.activeElement;l.shiftKey&&b===p?(l.preventDefault(),v.focus()):!l.shiftKey&&b===v&&(l.preventDefault(),p.focus())};i.addEventListener("keydown",m),s.focus(),this.previousBodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden",this.didManageBodyOverflow=!0,this.setupMessageListener(),this.overlay._escHandler=n,this.overlay._focusTrapHandler=m}buildIframeUrl(e){const t=new URLSearchParams;return t.set("teamSlug",e.teamSlug),e.momentSlug&&t.set("momentSlug",e.momentSlug),e.listSlug&&t.set("listSlug",e.listSlug),t.set("triggerType",e.triggerType),e.ids?.length&&t.set("ids",e.ids.join(",")),e.calendar&&t.set("calendar",e.calendar),t.set("returnOrigin",window.location.origin),t.set("embed","1"),`${this.liveBaseUrl}/en/embed/sync?${t.toString()}`}setupMessageListener(){this.messageHandler=e=>{if(e.origin!==this.liveOrigin||e.source!==this.iframe?.contentWindow)return;const t=e.data;if(!(!t||typeof t!="object")){if(t.source==="moment-live-embed"&&t.type==="moment.embed.oauth.start"){const n=t;this.emitAnalytics("oauth.start",{provider:n.provider,teamSlug:n.teamSlug}),this.handleOAuthStart(n);return}if(t.source==="moment-live-embed"&&t.type==="moment.embed.resize"){const n=typeof t.height=="number"?t.height:0;if(n>0&&this.iframe){const r=Math.round(window.innerHeight*.8);this.iframe.style.height=`${Math.min(n,r)}px`}return}if(t.source==="moment-live-embed"&&t.type==="moment.embed.result"){const n=t;this.handleResult(n)}}},window.addEventListener("message",this.messageHandler)}handleOAuthStart(e){this.popupBridge&&(this.popupBridge.cleanup(),this.popupBridge=null),this.popupBridge=new y({liveBaseUrl:this.liveBaseUrl,liveOrigin:this.liveOrigin,iframeWindow:this.iframe?.contentWindow??null,onResult:t=>{this.handleResult(t)},onPopupBlocked:()=>{this.emitAnalytics("oauth.popup.blocked",{provider:e.provider})},onPopupClosed:()=>{this.emitAnalytics("oauth.popup.closed",{provider:e.provider})}}),this.popupBridge.open(e)}handleResult(e){if(e.result==="success")this.emitAnalytics("subscribe.success",{provider:e.provider,triggerType:e.triggerType,momentIds:e.momentIds}),this.opts.onSuccess?.(e);else if(e.result==="error")this.emitAnalytics("subscribe.error",{provider:e.provider,triggerType:e.triggerType,momentIds:e.momentIds}),this.opts.onError?.(e);else if(e.result==="cancelled")return;this.opts.onClose?.(e),this.emitAnalytics("embed.close"),this.closeTimer=setTimeout(()=>this.cleanup(),1500)}handleCancel(){this.emitAnalytics("embed.close");const t={source:"moment-live-embed",type:"moment.embed.result",result:"cancelled",triggerType:this.activePayload?.triggerType??"moment",momentIds:this.activePayload?.ids??[]};this.opts.onClose?.(t),this.cleanup()}cleanup(){if(this.closeTimer&&(clearTimeout(this.closeTimer),this.closeTimer=null),this.popupBridge&&(this.popupBridge.cleanup(),this.popupBridge=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.overlay){const{_escHandler:e,_focusTrapHandler:t}=this.overlay;e&&document.removeEventListener("keydown",e);const n=this.overlay.firstElementChild;n&&t&&n.removeEventListener("keydown",t),this.overlay.remove(),this.overlay=null}this.iframe=null,this.activePayload=null,this.didManageBodyOverflow&&(document.body.style.overflow=this.previousBodyOverflow,this.didManageBodyOverflow=!1),this.previousFocusedElement&&typeof this.previousFocusedElement.focus=="function"&&this.previousFocusedElement.focus(),this.previousFocusedElement=null}emitAnalytics(e,t){this.opts.onAnalytics?.({event:e,timestamp:Date.now(),...t})}}function f(o){const e=document.createElement("button");return e.type="button",e.classList.add("moment-sync-trigger"),o.className&&o.className.split(" ").forEach(t=>{t&&e.classList.add(t)}),Object.assign(e.style,{backgroundColor:"#1c1917",color:"#ffffff",border:"1px solid #292524",borderRadius:"4px",padding:"8px 16px",fontSize:"14px",fontWeight:"500",cursor:"pointer",lineHeight:"1.4"}),e.setAttribute("data-moment-team-slug",o.teamSlug),o.momentSlug&&e.setAttribute("data-moment-slug",o.momentSlug),o.listSlug&&e.setAttribute("data-moment-list-slug",o.listSlug),o.triggerType&&e.setAttribute("data-moment-trigger-type",o.triggerType),o.ids?.length&&e.setAttribute("data-moment-ids",o.ids.join(",")),o.calendar&&e.setAttribute("data-moment-calendar",o.calendar),e.textContent=o.label??"Add to Calendar",e}if(typeof window<"u"){const o=window;o.MomentSdk=g,o.createMomentButton=f}h.MomentSdk=g,h.createMomentButton=f,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})})(this.MomentSdk=this.MomentSdk||{});
|
|
1
|
+
(function(h){"use strict";class y{popup=null;pollTimer=null;messageHandler=null;resultReceived=!1;opts;constructor(e){this.opts=e}open(e){this.cleanup(),this.resultReceived=!1;const t=this.buildPopupUrl(e),i=Math.round(window.screenX+(window.outerWidth-500)/2),r=Math.round(window.screenY+(window.outerHeight-700)/2);if(this.popup=window.open(t,"moment-oauth-popup",`width=500,height=700,left=${i},top=${r},menubar=no,toolbar=no,location=yes,status=no`),!this.popup||this.popup.closed){this.sendStatusToIframe("popup-blocked"),this.opts.onPopupBlocked();return}this.sendStatusToIframe("popup-opened"),this.startPolling(),this.messageHandler=s=>{if(s.origin!==this.opts.liveOrigin||s.source!==this.popup)return;const n=s.data;!n||typeof n!="object"||n.source!=="moment-live-embed"||n.type!=="moment.embed.result"||(this.resultReceived=!0,this.sendStatusToIframe("completed"),this.opts.iframeWindow&&this.opts.iframeWindow.postMessage(n,this.opts.liveOrigin),this.opts.onResult(n),this.cleanup())},window.addEventListener("message",this.messageHandler)}cleanup(){if(this.pollTimer&&(clearInterval(this.pollTimer),this.pollTimer=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.popup&&!this.popup.closed)try{this.popup.close()}catch{}this.popup=null}buildPopupUrl(e){const t=window.location.origin,i=new URLSearchParams({provider:e.provider,teamSlug:e.teamSlug,ids:e.ids.join(","),triggerType:e.triggerType,returnOrigin:t});return e.subscriptionType&&i.set("subscriptionType",e.subscriptionType),`${this.opts.liveBaseUrl}/en/embed/oauth-popup?${i.toString()}`}startPolling(){this.pollTimer=setInterval(()=>{(!this.popup||this.popup.closed)&&(this.pollTimer&&(clearInterval(this.pollTimer),this.pollTimer=null),this.resultReceived||(this.sendStatusToIframe("popup-closed"),this.opts.onPopupClosed()),this.cleanup())},500)}sendStatusToIframe(e){if(!this.opts.iframeWindow)return;const t={source:"moment-sdk",type:"moment.embed.oauth.status",status:e};this.opts.iframeWindow.postMessage(t,this.opts.liveOrigin)}}const w=".moment-sync-trigger",T="https://live.momentco.ai";class g{opts;liveBaseUrl;liveOrigin;overlay=null;iframe=null;popupBridge=null;messageHandler=null;boundClickHandlers=new Map;activePayload=null;previousFocusedElement=null;previousBodyOverflow="";didManageBodyOverflow=!1;closeTimer=null;constructor(e){this.opts={triggerSelector:w,...e},this.liveBaseUrl=T;try{this.liveOrigin=new URL(this.liveBaseUrl).origin}catch{throw new Error(`[MomentSdk] Invalid VITE_LIVE_BASE_URL: "${this.liveBaseUrl}"`)}this.bindTriggers(),this.emitAnalytics("embed.init")}open(e){this.emitAnalytics("embed.open",{teamSlug:e.teamSlug,triggerType:e.triggerType}),this.createModal(e)}close(){this.handleCancel()}rebind(){this.unbindTriggers(),this.bindTriggers()}destroy(){this.cleanup(),this.unbindTriggers()}bindTriggers(){document.querySelectorAll(this.opts.triggerSelector).forEach(t=>{const i=s=>{s.preventDefault(),this.handleTriggerClick(t)},r=this.boundClickHandlers.get(t);r&&t.removeEventListener("click",r),t.addEventListener("click",i),this.boundClickHandlers.set(t,i)})}unbindTriggers(){this.boundClickHandlers.forEach((e,t)=>{t.removeEventListener("click",e)}),this.boundClickHandlers.clear()}handleTriggerClick(e){const t=e.getAttribute("data-moment-team-slug")??"",i=e.getAttribute("data-moment-slug")??void 0,r=e.getAttribute("data-moment-list-slug")??void 0,s=e.getAttribute("data-moment-trigger-type");let n="moment";s!=null&&s!==""&&(s==="moment"||s==="list"||s==="team"?n=s:console.warn("[MomentSdk] Invalid data-moment-trigger-type, falling back to 'moment':",s));const d=e.getAttribute("data-moment-ids")??e.getAttribute("data-moment-game-id")??"",u=d?d.split(",").filter(Boolean):[],a=e.getAttribute("data-moment-calendar");let m;if(a!=null&&a!==""&&(a==="google"||a==="outlook"?m=a:console.warn("[MomentSdk] Invalid data-moment-calendar, ignoring value:",a)),!t){console.warn("[MomentSdk] Missing data-moment-team-slug on trigger element");return}const l=n==="team"?void 0:i,c=n==="team"?void 0:r,p=n==="team"?[]:u;this.emitAnalytics("embed.trigger.click",{teamSlug:t,triggerType:n,momentIds:p}),this.open({teamSlug:t,momentSlug:l,listSlug:c,triggerType:n,ids:p,calendar:m??void 0})}createModal(e){this.cleanup(),this.previousFocusedElement=document.activeElement||null,this.activePayload=e;const t=this.buildIframeUrl(e);this.overlay=document.createElement("div"),this.overlay.setAttribute("role","presentation"),Object.assign(this.overlay.style,{position:"fixed",inset:"0",zIndex:"999999",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(2px)",padding:"16px"}),this.overlay.addEventListener("click",l=>{l.target===this.overlay&&this.handleCancel()});const i=l=>{l.key==="Escape"&&this.handleCancel()};document.addEventListener("keydown",i);const r=document.createElement("div");Object.assign(r.style,{position:"relative",width:"100%",maxWidth:"380px",borderRadius:"16px",overflow:"hidden",backgroundColor:"#000000",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",display:"flex",flexDirection:"column"});const s=document.createElement("div");s.setAttribute("role","dialog"),s.setAttribute("aria-modal","true"),s.setAttribute("aria-label","Calendar sync modal"),s.tabIndex=-1,Object.assign(s.style,{position:"relative",width:"100%",maxHeight:"80vh",borderRadius:"12px",overflow:"auto",backgroundColor:"#ffffff"});const n=document.createElement("button");n.type="button",n.innerHTML='<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>',n.setAttribute("aria-label","Close"),Object.assign(n.style,{position:"absolute",top:"10px",right:"10px",zIndex:"10",border:"none",backgroundColor:"transparent",color:"#999",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",padding:"0"}),n.addEventListener("mouseenter",()=>{n.style.color="#666"}),n.addEventListener("mouseleave",()=>{n.style.color="#999"}),n.addEventListener("click",()=>this.handleCancel()),this.iframe=document.createElement("iframe"),this.iframe.src=t,this.iframe.setAttribute("allow",""),this.iframe.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),this.iframe.setAttribute("scrolling","no"),Object.assign(this.iframe.style,{width:"100%",border:"none",display:"block",height:"420px",overflow:"hidden",transition:"height 0.15s ease"}),s.appendChild(n),s.appendChild(this.iframe);const d=document.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",gap:"6px",padding:"12px 0"});const u=document.createElement("span");u.textContent="Powered by",Object.assign(u.style,{fontFamily:"Inter, system-ui, -apple-system, sans-serif",fontSize:"12px",lineHeight:"16px",color:"#ffffff"});const a=document.createElement("img");a.alt="Moment",a.src=`${this.liveBaseUrl}/brand/moment-text-white.png`,Object.assign(a.style,{height:"auto",width:"67px"}),d.appendChild(u),d.appendChild(a),r.appendChild(s),r.appendChild(d),this.overlay.appendChild(r),document.body.appendChild(this.overlay);const m=l=>{if(l.key!=="Tab")return;const c=s.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(c.length===0){l.preventDefault(),s.focus();return}const p=c[0],v=c[c.length-1],b=document.activeElement;l.shiftKey&&b===p?(l.preventDefault(),v.focus()):!l.shiftKey&&b===v&&(l.preventDefault(),p.focus())};s.addEventListener("keydown",m),n.focus(),this.previousBodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden",this.didManageBodyOverflow=!0,this.setupMessageListener(),this.overlay._escHandler=i,this.overlay._focusTrapHandler=m}buildIframeUrl(e){const t=new URLSearchParams;return t.set("teamSlug",e.teamSlug),e.momentSlug&&t.set("momentSlug",e.momentSlug),e.listSlug&&t.set("listSlug",e.listSlug),t.set("triggerType",e.triggerType),e.ids?.length&&t.set("ids",e.ids.join(",")),e.calendar&&t.set("calendar",e.calendar),t.set("returnOrigin",window.location.origin),t.set("embed","1"),`${this.liveBaseUrl}/en/embed/sync?${t.toString()}`}setupMessageListener(){this.messageHandler=e=>{if(e.origin!==this.liveOrigin||e.source!==this.iframe?.contentWindow)return;const t=e.data;if(!(!t||typeof t!="object")){if(t.source==="moment-live-embed"&&t.type==="moment.embed.oauth.start"){const i=t;this.emitAnalytics("oauth.start",{provider:i.provider,teamSlug:i.teamSlug}),this.handleOAuthStart(i);return}if(t.source==="moment-live-embed"&&t.type==="moment.embed.resize"){const i=typeof t.height=="number"?t.height:0;if(i>0&&this.iframe){const r=Math.round(window.innerHeight*.8);this.iframe.style.height=`${Math.min(i,r)}px`}return}if(t.source==="moment-live-embed"&&t.type==="moment.embed.open.url"){const{url:i}=t;i&&typeof i=="string"&&i.startsWith("webcal://")&&window.open(i,"_blank");return}if(t.source==="moment-live-embed"&&t.type==="moment.embed.result"){const i=t;this.handleResult(i)}}},window.addEventListener("message",this.messageHandler)}handleOAuthStart(e){this.popupBridge&&(this.popupBridge.cleanup(),this.popupBridge=null),this.popupBridge=new y({liveBaseUrl:this.liveBaseUrl,liveOrigin:this.liveOrigin,iframeWindow:this.iframe?.contentWindow??null,onResult:t=>{this.handleResult(t)},onPopupBlocked:()=>{this.emitAnalytics("oauth.popup.blocked",{provider:e.provider})},onPopupClosed:()=>{this.emitAnalytics("oauth.popup.closed",{provider:e.provider})}}),this.popupBridge.open(e)}handleResult(e){if(e.result==="success")this.emitAnalytics("subscribe.success",{provider:e.provider,triggerType:e.triggerType,momentIds:e.momentIds}),this.opts.onSuccess?.(e);else if(e.result==="error")this.emitAnalytics("subscribe.error",{provider:e.provider,triggerType:e.triggerType,momentIds:e.momentIds}),this.opts.onError?.(e);else if(e.result==="cancelled")return;this.opts.onClose?.(e),this.emitAnalytics("embed.close"),this.closeTimer=setTimeout(()=>this.cleanup(),1500)}handleCancel(){this.emitAnalytics("embed.close");const t={source:"moment-live-embed",type:"moment.embed.result",result:"cancelled",triggerType:this.activePayload?.triggerType??"moment",momentIds:this.activePayload?.ids??[]};this.opts.onClose?.(t),this.cleanup()}cleanup(){if(this.closeTimer&&(clearTimeout(this.closeTimer),this.closeTimer=null),this.popupBridge&&(this.popupBridge.cleanup(),this.popupBridge=null),this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.overlay){const{_escHandler:e,_focusTrapHandler:t}=this.overlay;e&&document.removeEventListener("keydown",e);const i=this.overlay.firstElementChild;i&&t&&i.removeEventListener("keydown",t),this.overlay.remove(),this.overlay=null}this.iframe=null,this.activePayload=null,this.didManageBodyOverflow&&(document.body.style.overflow=this.previousBodyOverflow,this.didManageBodyOverflow=!1),this.previousFocusedElement&&typeof this.previousFocusedElement.focus=="function"&&this.previousFocusedElement.focus(),this.previousFocusedElement=null}emitAnalytics(e,t){this.opts.onAnalytics?.({event:e,timestamp:Date.now(),...t})}}function f(o){const e=document.createElement("button");return e.type="button",e.classList.add("moment-sync-trigger"),o.className&&o.className.split(" ").forEach(t=>{t&&e.classList.add(t)}),Object.assign(e.style,{backgroundColor:"#1c1917",color:"#ffffff",border:"1px solid #292524",borderRadius:"4px",padding:"8px 16px",fontSize:"14px",fontWeight:"500",cursor:"pointer",lineHeight:"1.4"}),e.setAttribute("data-moment-team-slug",o.teamSlug),o.momentSlug&&e.setAttribute("data-moment-slug",o.momentSlug),o.listSlug&&e.setAttribute("data-moment-list-slug",o.listSlug),o.triggerType&&e.setAttribute("data-moment-trigger-type",o.triggerType),o.ids?.length&&e.setAttribute("data-moment-ids",o.ids.join(",")),o.calendar&&e.setAttribute("data-moment-calendar",o.calendar),e.textContent=o.label??"Add to Calendar",e}if(typeof window<"u"){const o=window;o.MomentSdk=g,o.createMomentButton=f}h.MomentSdk=g,h.createMomentButton=f,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})})(this.MomentSdk=this.MomentSdk||{});
|
package/dist/moment-sdk.mjs
CHANGED
|
@@ -12,19 +12,19 @@ class f {
|
|
|
12
12
|
*/
|
|
13
13
|
open(e) {
|
|
14
14
|
this.cleanup(), this.resultReceived = !1;
|
|
15
|
-
const t = this.buildPopupUrl(e),
|
|
15
|
+
const t = this.buildPopupUrl(e), i = Math.round(window.screenX + (window.outerWidth - 500) / 2), r = Math.round(window.screenY + (window.outerHeight - 700) / 2);
|
|
16
16
|
if (this.popup = window.open(
|
|
17
17
|
t,
|
|
18
18
|
"moment-oauth-popup",
|
|
19
|
-
`width=500,height=700,left=${
|
|
19
|
+
`width=500,height=700,left=${i},top=${r},menubar=no,toolbar=no,location=yes,status=no`
|
|
20
20
|
), !this.popup || this.popup.closed) {
|
|
21
21
|
this.sendStatusToIframe("popup-blocked"), this.opts.onPopupBlocked();
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
this.sendStatusToIframe("popup-opened"), this.startPolling(), this.messageHandler = (
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
!
|
|
24
|
+
this.sendStatusToIframe("popup-opened"), this.startPolling(), this.messageHandler = (s) => {
|
|
25
|
+
if (s.origin !== this.opts.liveOrigin || s.source !== this.popup) return;
|
|
26
|
+
const n = s.data;
|
|
27
|
+
!n || typeof n != "object" || n.source !== "moment-live-embed" || n.type !== "moment.embed.result" || (this.resultReceived = !0, this.sendStatusToIframe("completed"), this.opts.iframeWindow && this.opts.iframeWindow.postMessage(n, this.opts.liveOrigin), this.opts.onResult(n), this.cleanup());
|
|
28
28
|
}, window.addEventListener("message", this.messageHandler);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -39,14 +39,14 @@ class f {
|
|
|
39
39
|
this.popup = null;
|
|
40
40
|
}
|
|
41
41
|
buildPopupUrl(e) {
|
|
42
|
-
const t = window.location.origin,
|
|
42
|
+
const t = window.location.origin, i = new URLSearchParams({
|
|
43
43
|
provider: e.provider,
|
|
44
44
|
teamSlug: e.teamSlug,
|
|
45
45
|
ids: e.ids.join(","),
|
|
46
46
|
triggerType: e.triggerType,
|
|
47
47
|
returnOrigin: t
|
|
48
48
|
});
|
|
49
|
-
return e.subscriptionType &&
|
|
49
|
+
return e.subscriptionType && i.set("subscriptionType", e.subscriptionType), `${this.opts.liveBaseUrl}/en/embed/oauth-popup?${i.toString()}`;
|
|
50
50
|
}
|
|
51
51
|
startPolling() {
|
|
52
52
|
this.pollTimer = setInterval(() => {
|
|
@@ -63,7 +63,7 @@ class f {
|
|
|
63
63
|
this.opts.iframeWindow.postMessage(t, this.opts.liveOrigin);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
const v = ".moment-sync-trigger", b = "https://live.
|
|
66
|
+
const v = ".moment-sync-trigger", b = "https://live.momentco.ai";
|
|
67
67
|
class y {
|
|
68
68
|
opts;
|
|
69
69
|
liveBaseUrl;
|
|
@@ -120,10 +120,10 @@ class y {
|
|
|
120
120
|
// ── Private: trigger binding ──────────────────────────────────────
|
|
121
121
|
bindTriggers() {
|
|
122
122
|
document.querySelectorAll(this.opts.triggerSelector).forEach((t) => {
|
|
123
|
-
const
|
|
124
|
-
|
|
123
|
+
const i = (s) => {
|
|
124
|
+
s.preventDefault(), this.handleTriggerClick(t);
|
|
125
125
|
}, r = this.boundClickHandlers.get(t);
|
|
126
|
-
r && t.removeEventListener("click", r), t.addEventListener("click",
|
|
126
|
+
r && t.removeEventListener("click", r), t.addEventListener("click", i), this.boundClickHandlers.set(t, i);
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
unbindTriggers() {
|
|
@@ -132,11 +132,11 @@ class y {
|
|
|
132
132
|
}), this.boundClickHandlers.clear();
|
|
133
133
|
}
|
|
134
134
|
handleTriggerClick(e) {
|
|
135
|
-
const t = e.getAttribute("data-moment-team-slug") ?? "",
|
|
136
|
-
let
|
|
137
|
-
|
|
135
|
+
const t = e.getAttribute("data-moment-team-slug") ?? "", i = e.getAttribute("data-moment-slug") ?? void 0, r = e.getAttribute("data-moment-list-slug") ?? void 0, s = e.getAttribute("data-moment-trigger-type");
|
|
136
|
+
let n = "moment";
|
|
137
|
+
s != null && s !== "" && (s === "moment" || s === "list" || s === "team" ? n = s : console.warn(
|
|
138
138
|
"[MomentSdk] Invalid data-moment-trigger-type, falling back to 'moment':",
|
|
139
|
-
|
|
139
|
+
s
|
|
140
140
|
));
|
|
141
141
|
const d = e.getAttribute("data-moment-ids") ?? e.getAttribute("data-moment-game-id") ?? "", u = d ? d.split(",").filter(Boolean) : [], a = e.getAttribute("data-moment-calendar");
|
|
142
142
|
let m;
|
|
@@ -144,16 +144,16 @@ class y {
|
|
|
144
144
|
console.warn("[MomentSdk] Missing data-moment-team-slug on trigger element");
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
|
-
const l =
|
|
147
|
+
const l = n === "team" ? void 0 : i, c = n === "team" ? void 0 : r, p = n === "team" ? [] : u;
|
|
148
148
|
this.emitAnalytics("embed.trigger.click", {
|
|
149
149
|
teamSlug: t,
|
|
150
|
-
triggerType:
|
|
150
|
+
triggerType: n,
|
|
151
151
|
momentIds: p
|
|
152
152
|
}), this.open({
|
|
153
153
|
teamSlug: t,
|
|
154
154
|
momentSlug: l,
|
|
155
155
|
listSlug: c,
|
|
156
|
-
triggerType:
|
|
156
|
+
triggerType: n,
|
|
157
157
|
ids: p,
|
|
158
158
|
calendar: m ?? void 0
|
|
159
159
|
});
|
|
@@ -175,10 +175,10 @@ class y {
|
|
|
175
175
|
}), this.overlay.addEventListener("click", (l) => {
|
|
176
176
|
l.target === this.overlay && this.handleCancel();
|
|
177
177
|
});
|
|
178
|
-
const
|
|
178
|
+
const i = (l) => {
|
|
179
179
|
l.key === "Escape" && this.handleCancel();
|
|
180
180
|
};
|
|
181
|
-
document.addEventListener("keydown",
|
|
181
|
+
document.addEventListener("keydown", i);
|
|
182
182
|
const r = document.createElement("div");
|
|
183
183
|
Object.assign(r.style, {
|
|
184
184
|
position: "relative",
|
|
@@ -191,8 +191,8 @@ class y {
|
|
|
191
191
|
display: "flex",
|
|
192
192
|
flexDirection: "column"
|
|
193
193
|
});
|
|
194
|
-
const
|
|
195
|
-
|
|
194
|
+
const s = document.createElement("div");
|
|
195
|
+
s.setAttribute("role", "dialog"), s.setAttribute("aria-modal", "true"), s.setAttribute("aria-label", "Calendar sync modal"), s.tabIndex = -1, Object.assign(s.style, {
|
|
196
196
|
position: "relative",
|
|
197
197
|
width: "100%",
|
|
198
198
|
maxHeight: "80vh",
|
|
@@ -200,8 +200,8 @@ class y {
|
|
|
200
200
|
overflow: "auto",
|
|
201
201
|
backgroundColor: "#ffffff"
|
|
202
202
|
});
|
|
203
|
-
const
|
|
204
|
-
|
|
203
|
+
const n = document.createElement("button");
|
|
204
|
+
n.type = "button", n.innerHTML = '<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>', n.setAttribute("aria-label", "Close"), Object.assign(n.style, {
|
|
205
205
|
position: "absolute",
|
|
206
206
|
top: "10px",
|
|
207
207
|
right: "10px",
|
|
@@ -216,18 +216,18 @@ class y {
|
|
|
216
216
|
width: "24px",
|
|
217
217
|
height: "24px",
|
|
218
218
|
padding: "0"
|
|
219
|
-
}),
|
|
220
|
-
|
|
221
|
-
}),
|
|
222
|
-
|
|
223
|
-
}),
|
|
219
|
+
}), n.addEventListener("mouseenter", () => {
|
|
220
|
+
n.style.color = "#666";
|
|
221
|
+
}), n.addEventListener("mouseleave", () => {
|
|
222
|
+
n.style.color = "#999";
|
|
223
|
+
}), n.addEventListener("click", () => this.handleCancel()), this.iframe = document.createElement("iframe"), this.iframe.src = t, this.iframe.setAttribute("allow", ""), this.iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-popups allow-forms"), this.iframe.setAttribute("scrolling", "no"), Object.assign(this.iframe.style, {
|
|
224
224
|
width: "100%",
|
|
225
225
|
border: "none",
|
|
226
226
|
display: "block",
|
|
227
227
|
height: "420px",
|
|
228
228
|
overflow: "hidden",
|
|
229
229
|
transition: "height 0.15s ease"
|
|
230
|
-
}),
|
|
230
|
+
}), s.appendChild(n), s.appendChild(this.iframe);
|
|
231
231
|
const d = document.createElement("div");
|
|
232
232
|
Object.assign(d.style, {
|
|
233
233
|
display: "flex",
|
|
@@ -247,20 +247,20 @@ class y {
|
|
|
247
247
|
a.alt = "Moment", a.src = `${this.liveBaseUrl}/brand/moment-text-white.png`, Object.assign(a.style, {
|
|
248
248
|
height: "auto",
|
|
249
249
|
width: "67px"
|
|
250
|
-
}), d.appendChild(u), d.appendChild(a), r.appendChild(
|
|
250
|
+
}), d.appendChild(u), d.appendChild(a), r.appendChild(s), r.appendChild(d), this.overlay.appendChild(r), document.body.appendChild(this.overlay);
|
|
251
251
|
const m = (l) => {
|
|
252
252
|
if (l.key !== "Tab") return;
|
|
253
|
-
const c =
|
|
253
|
+
const c = s.querySelectorAll(
|
|
254
254
|
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
255
255
|
);
|
|
256
256
|
if (c.length === 0) {
|
|
257
|
-
l.preventDefault(),
|
|
257
|
+
l.preventDefault(), s.focus();
|
|
258
258
|
return;
|
|
259
259
|
}
|
|
260
260
|
const p = c[0], h = c[c.length - 1], g = document.activeElement;
|
|
261
261
|
l.shiftKey && g === p ? (l.preventDefault(), h.focus()) : !l.shiftKey && g === h && (l.preventDefault(), p.focus());
|
|
262
262
|
};
|
|
263
|
-
|
|
263
|
+
s.addEventListener("keydown", m), n.focus(), this.previousBodyOverflow = document.body.style.overflow, document.body.style.overflow = "hidden", this.didManageBodyOverflow = !0, this.setupMessageListener(), this.overlay._escHandler = i, this.overlay._focusTrapHandler = m;
|
|
264
264
|
}
|
|
265
265
|
buildIframeUrl(e) {
|
|
266
266
|
const t = new URLSearchParams();
|
|
@@ -273,24 +273,29 @@ class y {
|
|
|
273
273
|
const t = e.data;
|
|
274
274
|
if (!(!t || typeof t != "object")) {
|
|
275
275
|
if (t.source === "moment-live-embed" && t.type === "moment.embed.oauth.start") {
|
|
276
|
-
const
|
|
276
|
+
const i = t;
|
|
277
277
|
this.emitAnalytics("oauth.start", {
|
|
278
|
-
provider:
|
|
279
|
-
teamSlug:
|
|
280
|
-
}), this.handleOAuthStart(
|
|
278
|
+
provider: i.provider,
|
|
279
|
+
teamSlug: i.teamSlug
|
|
280
|
+
}), this.handleOAuthStart(i);
|
|
281
281
|
return;
|
|
282
282
|
}
|
|
283
283
|
if (t.source === "moment-live-embed" && t.type === "moment.embed.resize") {
|
|
284
|
-
const
|
|
285
|
-
if (
|
|
284
|
+
const i = typeof t.height == "number" ? t.height : 0;
|
|
285
|
+
if (i > 0 && this.iframe) {
|
|
286
286
|
const r = Math.round(window.innerHeight * 0.8);
|
|
287
|
-
this.iframe.style.height = `${Math.min(
|
|
287
|
+
this.iframe.style.height = `${Math.min(i, r)}px`;
|
|
288
288
|
}
|
|
289
289
|
return;
|
|
290
290
|
}
|
|
291
|
+
if (t.source === "moment-live-embed" && t.type === "moment.embed.open.url") {
|
|
292
|
+
const { url: i } = t;
|
|
293
|
+
i && typeof i == "string" && i.startsWith("webcal://") && window.open(i, "_blank");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
291
296
|
if (t.source === "moment-live-embed" && t.type === "moment.embed.result") {
|
|
292
|
-
const
|
|
293
|
-
this.handleResult(
|
|
297
|
+
const i = t;
|
|
298
|
+
this.handleResult(i);
|
|
294
299
|
}
|
|
295
300
|
}
|
|
296
301
|
}, window.addEventListener("message", this.messageHandler);
|
|
@@ -348,8 +353,8 @@ class y {
|
|
|
348
353
|
if (this.closeTimer && (clearTimeout(this.closeTimer), this.closeTimer = null), this.popupBridge && (this.popupBridge.cleanup(), this.popupBridge = null), this.messageHandler && (window.removeEventListener("message", this.messageHandler), this.messageHandler = null), this.overlay) {
|
|
349
354
|
const { _escHandler: e, _focusTrapHandler: t } = this.overlay;
|
|
350
355
|
e && document.removeEventListener("keydown", e);
|
|
351
|
-
const
|
|
352
|
-
|
|
356
|
+
const i = this.overlay.firstElementChild;
|
|
357
|
+
i && t && i.removeEventListener("keydown", t), this.overlay.remove(), this.overlay = null;
|
|
353
358
|
}
|
|
354
359
|
this.iframe = null, this.activePayload = null, this.didManageBodyOverflow && (document.body.style.overflow = this.previousBodyOverflow, this.didManageBodyOverflow = !1), this.previousFocusedElement && typeof this.previousFocusedElement.focus == "function" && this.previousFocusedElement.focus(), this.previousFocusedElement = null;
|
|
355
360
|
}
|
|
@@ -77,6 +77,15 @@ export interface MomentResultPayload {
|
|
|
77
77
|
momentIds: string[];
|
|
78
78
|
message?: string;
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Iframe → Parent: request to open a URL in the parent context.
|
|
82
|
+
* Used for `webcal://` links that cannot navigate from within an iframe.
|
|
83
|
+
*/
|
|
84
|
+
export interface MomentOpenUrlPayload {
|
|
85
|
+
source: 'moment-live-embed';
|
|
86
|
+
type: 'moment.embed.open.url';
|
|
87
|
+
url: string;
|
|
88
|
+
}
|
|
80
89
|
export type MomentAnalyticsEventName = 'embed.init' | 'embed.trigger.click' | 'embed.open' | 'oauth.start' | 'oauth.popup.blocked' | 'oauth.popup.closed' | 'subscribe.success' | 'subscribe.error' | 'embed.close';
|
|
81
90
|
export interface MomentAnalyticsEvent {
|
|
82
91
|
event: MomentAnalyticsEventName;
|
|
@@ -86,4 +95,4 @@ export interface MomentAnalyticsEvent {
|
|
|
86
95
|
momentIds?: string[];
|
|
87
96
|
timestamp: number;
|
|
88
97
|
}
|
|
89
|
-
export type MomentPostMessage = MomentOAuthStartPayload | MomentOAuthStatusPayload | MomentResultPayload;
|
|
98
|
+
export type MomentPostMessage = MomentOAuthStartPayload | MomentOAuthStatusPayload | MomentResultPayload | MomentOpenUrlPayload;
|
package/package.json
CHANGED