@momentco-ai/moment-sdk 0.2.0-dev.12 → 0.2.0-dev.14
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 +107 -57
- package/dist/types/sdk/types.d.ts +10 -1
- package/package.json +1 -1
package/dist/moment-sdk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m){"use strict";class f{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),o=Math.round(window.screenY+(window.outerHeight-700)/2);if(this.popup=window.open(t,"moment-oauth-popup",`width=500,height=700,left=${i},top=${o},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 r=s.data;!r||typeof r!="object"||r.source!=="moment-live-embed"||r.type!=="moment.embed.result"||(this.resultReceived=!0,this.sendStatusToIframe("completed"),this.opts.iframeWindow&&this.opts.iframeWindow.postMessage(r,this.opts.liveOrigin),this.opts.onResult(r),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 v=".moment-sync-trigger",b="https://live.dev.momentco.ai";class p{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:v,...e},this.liveBaseUrl=b;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)},o=this.boundClickHandlers.get(t);o&&t.removeEventListener("click",o),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,o=e.getAttribute("data-moment-list-slug")??void 0,s=e.getAttribute("data-moment-trigger-type");let r="moment";s!=null&&s!==""&&(s==="moment"||s==="list"||s==="team"?r=s:console.warn("[MomentSdk] Invalid data-moment-trigger-type, falling back to 'moment':",s));const l=e.getAttribute("data-moment-ids")??e.getAttribute("data-moment-game-id")??"",d=l?l.split(",").filter(Boolean):[],a=e.getAttribute("data-moment-calendar");let u;if(a!=null&&a!==""&&(a==="google"||a==="outlook"?u=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 c=r==="team"?void 0:i,y=r==="team"?void 0:o,g=r==="team"?[]:d;this.emitAnalytics("embed.trigger.click",{teamSlug:t,triggerType:r,momentIds:g}),this.open({teamSlug:t,momentSlug:c,listSlug:y,triggerType:r,ids:g,calendar:u??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 o=document.createElement("div");o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true"),o.setAttribute("aria-label","Calendar sync modal"),o.tabIndex=-1,Object.assign(o.style,{position:"relative",width:"100%",maxWidth:"420px",maxHeight:"90vh",borderRadius:"16px",overflow:"hidden",backgroundColor:"#ffffff",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)"});const s=document.createElement("button");s.type="button",s.textContent="ⓧ",s.setAttribute("aria-label","Close"),Object.assign(s.style,{position:"absolute",top:"8px",right:"8px",zIndex:"10",border:"none",backgroundColor:"transparent",color:"#999",fontSize:"20px",lineHeight:"1",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"}),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"),Object.assign(this.iframe.style,{width:"100%",height:"480px",border:"none",display:"block"}),o.appendChild(s),o.appendChild(this.iframe),this.overlay.appendChild(o),document.body.appendChild(this.overlay);const r=l=>{if(l.key!=="Tab")return;const d=o.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(d.length===0){l.preventDefault(),o.focus();return}const a=d[0],u=d[d.length-1],c=document.activeElement;l.shiftKey&&c===a?(l.preventDefault(),u.focus()):!l.shiftKey&&c===u&&(l.preventDefault(),a.focus())};o.addEventListener("keydown",r),s.focus(),this.previousBodyOverflow=document.body.style.overflow,document.body.style.overflow="hidden",this.didManageBodyOverflow=!0,this.setupMessageListener(),this.overlay._escHandler=i,this.overlay._focusTrapHandler=r}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.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 f({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 h(n){const e=document.createElement("button");return e.type="button",e.classList.add("moment-sync-trigger"),n.className&&n.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",n.teamSlug),n.momentSlug&&e.setAttribute("data-moment-slug",n.momentSlug),n.listSlug&&e.setAttribute("data-moment-list-slug",n.listSlug),n.triggerType&&e.setAttribute("data-moment-trigger-type",n.triggerType),n.ids?.length&&e.setAttribute("data-moment-ids",n.ids.join(",")),n.calendar&&e.setAttribute("data-moment-calendar",n.calendar),e.textContent=n.label??"Add to Calendar",e}if(typeof window<"u"){const n=window;n.MomentSdk=p,n.createMomentButton=h}m.MomentSdk=p,m.createMomentButton=h,Object.defineProperty(m,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.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 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class f {
|
|
2
2
|
popup = null;
|
|
3
3
|
pollTimer = null;
|
|
4
4
|
messageHandler = null;
|
|
@@ -12,19 +12,19 @@ class h {
|
|
|
12
12
|
*/
|
|
13
13
|
open(e) {
|
|
14
14
|
this.cleanup(), this.resultReceived = !1;
|
|
15
|
-
const t = this.buildPopupUrl(e), i = Math.round(window.screenX + (window.outerWidth - 500) / 2),
|
|
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=${i},top=${
|
|
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
24
|
this.sendStatusToIframe("popup-opened"), this.startPolling(), this.messageHandler = (s) => {
|
|
25
25
|
if (s.origin !== this.opts.liveOrigin || s.source !== this.popup) return;
|
|
26
|
-
const
|
|
27
|
-
!
|
|
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
|
/**
|
|
@@ -63,8 +63,8 @@ class h {
|
|
|
63
63
|
this.opts.iframeWindow.postMessage(t, this.opts.liveOrigin);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
const
|
|
67
|
-
class
|
|
66
|
+
const v = ".moment-sync-trigger", b = "https://live.dev.momentco.ai";
|
|
67
|
+
class y {
|
|
68
68
|
opts;
|
|
69
69
|
liveBaseUrl;
|
|
70
70
|
liveOrigin;
|
|
@@ -80,9 +80,9 @@ class v {
|
|
|
80
80
|
closeTimer = null;
|
|
81
81
|
constructor(e) {
|
|
82
82
|
this.opts = {
|
|
83
|
-
triggerSelector:
|
|
83
|
+
triggerSelector: v,
|
|
84
84
|
...e
|
|
85
|
-
}, this.liveBaseUrl =
|
|
85
|
+
}, this.liveBaseUrl = b;
|
|
86
86
|
try {
|
|
87
87
|
this.liveOrigin = new URL(this.liveBaseUrl).origin;
|
|
88
88
|
} catch {
|
|
@@ -122,8 +122,8 @@ class v {
|
|
|
122
122
|
document.querySelectorAll(this.opts.triggerSelector).forEach((t) => {
|
|
123
123
|
const i = (s) => {
|
|
124
124
|
s.preventDefault(), this.handleTriggerClick(t);
|
|
125
|
-
},
|
|
126
|
-
|
|
125
|
+
}, r = this.boundClickHandlers.get(t);
|
|
126
|
+
r && t.removeEventListener("click", r), t.addEventListener("click", i), this.boundClickHandlers.set(t, i);
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
unbindTriggers() {
|
|
@@ -132,30 +132,30 @@ class v {
|
|
|
132
132
|
}), this.boundClickHandlers.clear();
|
|
133
133
|
}
|
|
134
134
|
handleTriggerClick(e) {
|
|
135
|
-
const t = e.getAttribute("data-moment-team-slug") ?? "", i = e.getAttribute("data-moment-slug") ?? void 0,
|
|
136
|
-
let
|
|
137
|
-
s != null && s !== "" && (s === "moment" || s === "list" || s === "team" ?
|
|
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
|
-
const
|
|
142
|
-
let
|
|
143
|
-
if (a != null && a !== "" && (a === "google" || a === "outlook" ?
|
|
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
|
+
let m;
|
|
143
|
+
if (a != null && a !== "" && (a === "google" || a === "outlook" ? m = a : console.warn("[MomentSdk] Invalid data-moment-calendar, ignoring value:", a)), !t) {
|
|
144
144
|
console.warn("[MomentSdk] Missing data-moment-team-slug on trigger element");
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
|
-
const
|
|
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:
|
|
151
|
-
momentIds:
|
|
150
|
+
triggerType: n,
|
|
151
|
+
momentIds: p
|
|
152
152
|
}), this.open({
|
|
153
153
|
teamSlug: t,
|
|
154
|
-
momentSlug:
|
|
155
|
-
listSlug:
|
|
156
|
-
triggerType:
|
|
157
|
-
ids:
|
|
158
|
-
calendar:
|
|
154
|
+
momentSlug: l,
|
|
155
|
+
listSlug: c,
|
|
156
|
+
triggerType: n,
|
|
157
|
+
ids: p,
|
|
158
|
+
calendar: m ?? void 0
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
// ── Private: modal creation ───────────────────────────────────────
|
|
@@ -179,51 +179,88 @@ class v {
|
|
|
179
179
|
l.key === "Escape" && this.handleCancel();
|
|
180
180
|
};
|
|
181
181
|
document.addEventListener("keydown", i);
|
|
182
|
-
const
|
|
183
|
-
|
|
182
|
+
const r = document.createElement("div");
|
|
183
|
+
Object.assign(r.style, {
|
|
184
184
|
position: "relative",
|
|
185
185
|
width: "100%",
|
|
186
|
-
maxWidth: "
|
|
187
|
-
maxHeight: "90vh",
|
|
186
|
+
maxWidth: "380px",
|
|
188
187
|
borderRadius: "16px",
|
|
189
188
|
overflow: "hidden",
|
|
190
|
-
backgroundColor: "#
|
|
191
|
-
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)"
|
|
189
|
+
backgroundColor: "#000000",
|
|
190
|
+
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
|
|
191
|
+
display: "flex",
|
|
192
|
+
flexDirection: "column"
|
|
193
|
+
});
|
|
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
|
+
position: "relative",
|
|
197
|
+
width: "100%",
|
|
198
|
+
maxHeight: "80vh",
|
|
199
|
+
borderRadius: "12px",
|
|
200
|
+
overflow: "auto",
|
|
201
|
+
backgroundColor: "#ffffff"
|
|
192
202
|
});
|
|
193
|
-
const
|
|
194
|
-
|
|
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, {
|
|
195
205
|
position: "absolute",
|
|
196
|
-
top: "
|
|
197
|
-
right: "
|
|
206
|
+
top: "10px",
|
|
207
|
+
right: "10px",
|
|
198
208
|
zIndex: "10",
|
|
199
209
|
border: "none",
|
|
200
210
|
backgroundColor: "transparent",
|
|
201
211
|
color: "#999",
|
|
202
|
-
fontSize: "20px",
|
|
203
|
-
lineHeight: "1",
|
|
204
212
|
cursor: "pointer",
|
|
205
213
|
display: "flex",
|
|
206
214
|
alignItems: "center",
|
|
207
|
-
justifyContent: "center"
|
|
208
|
-
|
|
215
|
+
justifyContent: "center",
|
|
216
|
+
width: "24px",
|
|
217
|
+
height: "24px",
|
|
218
|
+
padding: "0"
|
|
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, {
|
|
209
224
|
width: "100%",
|
|
210
|
-
height: "480px",
|
|
211
225
|
border: "none",
|
|
212
|
-
display: "block"
|
|
213
|
-
|
|
214
|
-
|
|
226
|
+
display: "block",
|
|
227
|
+
height: "420px",
|
|
228
|
+
overflow: "hidden",
|
|
229
|
+
transition: "height 0.15s ease"
|
|
230
|
+
}), s.appendChild(n), s.appendChild(this.iframe);
|
|
231
|
+
const d = document.createElement("div");
|
|
232
|
+
Object.assign(d.style, {
|
|
233
|
+
display: "flex",
|
|
234
|
+
alignItems: "center",
|
|
235
|
+
justifyContent: "center",
|
|
236
|
+
gap: "6px",
|
|
237
|
+
padding: "12px 0"
|
|
238
|
+
});
|
|
239
|
+
const u = document.createElement("span");
|
|
240
|
+
u.textContent = "Powered by", Object.assign(u.style, {
|
|
241
|
+
fontFamily: "Inter, system-ui, -apple-system, sans-serif",
|
|
242
|
+
fontSize: "12px",
|
|
243
|
+
lineHeight: "16px",
|
|
244
|
+
color: "#ffffff"
|
|
245
|
+
});
|
|
246
|
+
const a = document.createElement("img");
|
|
247
|
+
a.alt = "Moment", a.src = `${this.liveBaseUrl}/brand/moment-text-white.png`, Object.assign(a.style, {
|
|
248
|
+
height: "auto",
|
|
249
|
+
width: "67px"
|
|
250
|
+
}), d.appendChild(u), d.appendChild(a), r.appendChild(s), r.appendChild(d), this.overlay.appendChild(r), document.body.appendChild(this.overlay);
|
|
251
|
+
const m = (l) => {
|
|
215
252
|
if (l.key !== "Tab") return;
|
|
216
|
-
const
|
|
253
|
+
const c = s.querySelectorAll(
|
|
217
254
|
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
218
255
|
);
|
|
219
|
-
if (
|
|
220
|
-
l.preventDefault(),
|
|
256
|
+
if (c.length === 0) {
|
|
257
|
+
l.preventDefault(), s.focus();
|
|
221
258
|
return;
|
|
222
259
|
}
|
|
223
|
-
const
|
|
224
|
-
l.shiftKey &&
|
|
260
|
+
const p = c[0], h = c[c.length - 1], g = document.activeElement;
|
|
261
|
+
l.shiftKey && g === p ? (l.preventDefault(), h.focus()) : !l.shiftKey && g === h && (l.preventDefault(), p.focus());
|
|
225
262
|
};
|
|
226
|
-
|
|
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;
|
|
227
264
|
}
|
|
228
265
|
buildIframeUrl(e) {
|
|
229
266
|
const t = new URLSearchParams();
|
|
@@ -243,6 +280,19 @@ class v {
|
|
|
243
280
|
}), this.handleOAuthStart(i);
|
|
244
281
|
return;
|
|
245
282
|
}
|
|
283
|
+
if (t.source === "moment-live-embed" && t.type === "moment.embed.resize") {
|
|
284
|
+
const i = typeof t.height == "number" ? t.height : 0;
|
|
285
|
+
if (i > 0 && this.iframe) {
|
|
286
|
+
const r = Math.round(window.innerHeight * 0.8);
|
|
287
|
+
this.iframe.style.height = `${Math.min(i, r)}px`;
|
|
288
|
+
}
|
|
289
|
+
return;
|
|
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
|
+
}
|
|
246
296
|
if (t.source === "moment-live-embed" && t.type === "moment.embed.result") {
|
|
247
297
|
const i = t;
|
|
248
298
|
this.handleResult(i);
|
|
@@ -251,7 +301,7 @@ class v {
|
|
|
251
301
|
}, window.addEventListener("message", this.messageHandler);
|
|
252
302
|
}
|
|
253
303
|
handleOAuthStart(e) {
|
|
254
|
-
this.popupBridge && (this.popupBridge.cleanup(), this.popupBridge = null), this.popupBridge = new
|
|
304
|
+
this.popupBridge && (this.popupBridge.cleanup(), this.popupBridge = null), this.popupBridge = new f({
|
|
255
305
|
liveBaseUrl: this.liveBaseUrl,
|
|
256
306
|
liveOrigin: this.liveOrigin,
|
|
257
307
|
iframeWindow: this.iframe?.contentWindow ?? null,
|
|
@@ -317,9 +367,9 @@ class v {
|
|
|
317
367
|
});
|
|
318
368
|
}
|
|
319
369
|
}
|
|
320
|
-
function
|
|
370
|
+
function w(o) {
|
|
321
371
|
const e = document.createElement("button");
|
|
322
|
-
return e.type = "button", e.classList.add("moment-sync-trigger"),
|
|
372
|
+
return e.type = "button", e.classList.add("moment-sync-trigger"), o.className && o.className.split(" ").forEach((t) => {
|
|
323
373
|
t && e.classList.add(t);
|
|
324
374
|
}), Object.assign(e.style, {
|
|
325
375
|
backgroundColor: "#1c1917",
|
|
@@ -331,13 +381,13 @@ function b(n) {
|
|
|
331
381
|
fontWeight: "500",
|
|
332
382
|
cursor: "pointer",
|
|
333
383
|
lineHeight: "1.4"
|
|
334
|
-
}), e.setAttribute("data-moment-team-slug",
|
|
384
|
+
}), 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;
|
|
335
385
|
}
|
|
336
386
|
if (typeof window < "u") {
|
|
337
|
-
const
|
|
338
|
-
|
|
387
|
+
const o = window;
|
|
388
|
+
o.MomentSdk = y, o.createMomentButton = w;
|
|
339
389
|
}
|
|
340
390
|
export {
|
|
341
|
-
|
|
342
|
-
|
|
391
|
+
y as MomentSdk,
|
|
392
|
+
w as createMomentButton
|
|
343
393
|
};
|
|
@@ -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