@meltingspot/widget 1.6.0 → 1.9.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/CHANGELOG.md +24 -0
- package/index.cjs +1 -1
- package/index.mjs +322 -383
- package/index.standalone.js +17 -17
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,30 @@ Date: YYYY-MM-DD
|
|
|
15
15
|
|
|
16
16
|
-->
|
|
17
17
|
|
|
18
|
+
## v1.9.0
|
|
19
|
+
|
|
20
|
+
Date: 2026-08-18
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- Bump `@meltingspot/core` and `@meltingspot/embed` to `1.9.0`.
|
|
25
|
+
|
|
26
|
+
## v1.8.0
|
|
27
|
+
|
|
28
|
+
Date: 2026-08-13
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- Bump `@meltingspot/core` and `@meltingspot/embed` to `1.8.0`.
|
|
33
|
+
|
|
34
|
+
## v1.7.0
|
|
35
|
+
|
|
36
|
+
Date: 2026-08-10
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- Bump `@meltingspot/core` and `@meltingspot/embed` to `1.7.0`.
|
|
41
|
+
|
|
18
42
|
## v1.6.0
|
|
19
43
|
|
|
20
44
|
Date: 2026-07-31
|
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@meltingspot/core"),t=require("@meltingspot/embed");var n=new e.Logger({appName:`Widget SDK`,appVersion:`1.9.0`}),r=class{constructor(e,t,n){this.content=e,this.rootDocument=t,this.dialogClassname=n,this.dialogElement=null,this.triggerElement=null,this.iframeElement=null,this.currentListener=null}inject({into:t,bind:n,options:r}){this.remove();let i=(0,e.getHTMLElement)({input:t,rootDocument:this.rootDocument});if(this.dialogElement=(0,e.createDialog)(this.rootDocument),this.dialogElement.classList.add(this.dialogClassname),this.dialogElement.onclose=()=>this.#t(),i.appendChild(this.dialogElement),n){this.triggerElement=(0,e.getHTMLElement)({input:n,rootDocument:this.rootDocument});let t=this.open.bind(this,r);this.currentListener=e=>{e.stopPropagation(),e.preventDefault(),t()},this.triggerElement.addEventListener(`click`,this.currentListener)}}remove(){this.dialogElement&&=(this.dialogElement.remove(),this.dialogElement.onclose=null,null),this.triggerElement&&(this.currentListener&&this.triggerElement.removeEventListener(`click`,this.currentListener),this.triggerElement=null,this.currentListener=null)}open(e){this.dialogElement||this.inject({into:this.rootDocument.body}),this.dialogElement&&(this.#e(),this.dialogElement.showModal())}close(){this.dialogElement&&this.dialogElement.close()}#e(){this.dialogElement&&(this.iframeElement=this.dialogElement.appendChild(this.content.iframe))}#t(){this.iframeElement&&=(this.iframeElement.remove(),null)}},i=class extends r{constructor(e,t){super(e,t,`ms-drawer`)}open(e){let{position:t=`right`}=e??{};super.open(e),this.dialogElement&&(this.dialogElement.dataset.position=t)}},a=class extends r{constructor(e,t){super(e,t,`ms-modal`)}},o=class{constructor(t){this.baseURL=(0,e.formatBaseUrl)(t.baseURL),this.spotId=(0,e.formatUUID)(t.spotId),this.widgetId=(0,e.formatUUID)(t.widgetId),this.authToken=t.authToken??null,this.themeMode=t.themeMode??`auto`,this.domain=t.domain??null,this.utmParameters=t.utmParameters??null,this.rootDocument=t.rootDocument}get iframe(){let t=new URL(`/widgets/spot/${this.spotId}/widget/${this.widgetId}`,(0,e.trimSlashRight)(this.baseURL)),n=(0,e.createIframe)({url:t,searchParams:{themeMode:this.themeMode,ms_token:this.authToken,domain:this.domain,...(0,e.flattenUtmParameters)(this.utmParameters)},rootDocument:this.rootDocument});return n.classList.add(`ms-widget`),n}},s=class{constructor(t){this.baseURL=(0,e.formatBaseUrl)(t.baseURL),this.spotId=(0,e.formatUUID)(t.spotId),this.widgetContentId=(0,e.formatUUID)(t.widgetContentId),this.contentId=(0,e.formatUUID)(t.contentId),this.widgetId=(0,e.formatUUID)(t.widgetId),this.contentType=t.contentType,this.authToken=t.authToken??null,this.themeMode=t.themeMode??`auto`,this.domain=t.domain??null,this.utmParameters=t.utmParameters??null,this.rootDocument=t.rootDocument}get iframe(){let t=new URL(`/widgets/spot/${this.spotId}/widgetContent/${this.widgetContentId}`,(0,e.trimSlashRight)(this.baseURL));t.searchParams.set(`widgetId`,this.widgetId);let n=(0,e.createIframe)({url:t,searchParams:{themeMode:this.themeMode,ms_token:this.authToken,domain:this.domain,contentId:this.contentId,contentType:this.contentType,...(0,e.flattenUtmParameters)(this.utmParameters)},rootDocument:this.rootDocument});return n.classList.add(`ms-widget-content`),n}},c=class r{static{this.widgets=[]}static{this.messageListened=!1}static{this.widgetOptions={}}static injectWidgetInto(i,a){let{spotId:o,rootDocument:s,msCommunityWebBaseUrl:c}=e.ConfigurationService.getConfiguration({spotId:a.spotId,rootDocument:a.rootDocument,msCommunityWebBaseUrl:a.baseURL});if(!o)throw n.error(`Spot ID is required`),Error(`Spot ID is not configured. Please set the spotId in the configuration.`);let{widget:l,args:u}=r.createWidget({...a,spotId:o,rootDocument:s,baseURL:c}),d=new t.EmbedFrame(l);return d.inject(i),r.widgets.push(d),n.log(`Widget injected`,r.cleanupLoggedArgs(u),i),d}static injectWidgetContentInto(i,a){let{spotId:o,rootDocument:s,msCommunityWebBaseUrl:c}=e.ConfigurationService.getConfiguration({spotId:a.spotId,rootDocument:a.rootDocument,msCommunityWebBaseUrl:a.baseURL});if(!o)throw n.error(`Spot ID is required`),Error(`Spot ID is not configured. Please set the spotId in the configuration.`);let{widgetContent:l,args:u}=r.createWidgetContent({...a,spotId:o,rootDocument:s,baseURL:c}),d=new t.EmbedFrame(l);return d.inject(i),r.widgets.push(d),n.log(`WidgetContent injected`,r.cleanupLoggedArgs(u),i),d}static bindWidgetModalTo(e,t){return r.bindEntityModalTo(e,{type:`Widget`,data:t})}static bindWidgetDrawerTo(e,t){return r.bindEntityDrawerTo(e,{type:`Widget`,data:t})}static createWidgetDrawer(e){let{widget:t}=r.createWidget(e);return n.log(`Create Widget drawer`,{data:r.cleanupLoggedArgs(e)}),new i(t,e.rootDocument??document)}static createWidgetModal(e){let{widget:t}=r.createWidget(e);return n.log(`Create Widget modal`,{data:r.cleanupLoggedArgs(e)}),new a(t,e.rootDocument??document)}static createWidgetEmbed(e){let{widget:i}=r.createWidget(e),a=new t.EmbedFrame(i);return n.log(`Create Widget embed`,{data:r.cleanupLoggedArgs(e)}),a}static clear(){r.widgets.forEach(e=>{e.remove()}),r.widgets=[],r.widgetOptions={},n.log(`All Widget SDK MeltingSpot elements were cleared`)}static bindEntityDrawerTo(t,a){let{spotId:o,rootDocument:s,msCommunityWebBaseUrl:c}=e.ConfigurationService.getConfiguration({spotId:a.data.spotId,rootDocument:a.data.rootDocument??document,msCommunityWebBaseUrl:a.data.baseURL});if(!o)throw n.error(`Spot ID is required`),Error(`Spot ID is not configured. Please set the spotId in the configuration.`);let l,u;switch(a.type){case`Widget`:{let e=r.createWidget({...a.data,spotId:o,rootDocument:s,baseURL:c});l=e.widget,u=e.args}break;case`WidgetContent`:{let e=r.createWidgetContent({...a.data,spotId:o,rootDocument:s,baseURL:c});l=e.widgetContent,u=e.args}}let d=new i(l,s),f={position:a.data.position},p=a.data.into??s.body;return d.inject({into:p,bind:t,options:f}),r.widgets.push(d),n.log(`Widget bound to drawer`,r.cleanupLoggedArgs(u),f,p,t),d}static bindEntityModalTo(t,i){let{spotId:o,rootDocument:s,msCommunityWebBaseUrl:c}=e.ConfigurationService.getConfiguration({spotId:i.data.spotId,rootDocument:i.data.rootDocument??document,msCommunityWebBaseUrl:i.data.baseURL});if(!o)throw n.error(`Spot ID is required`),Error(`Spot ID is not configured. Please set the spotId in the configuration.`);let l,u;switch(i.type){case`Widget`:{let e=r.createWidget({...i.data,spotId:o,rootDocument:s,baseURL:c});l=e.widget,u=e.args}break;case`WidgetContent`:{let e=r.createWidgetContent({...i.data,spotId:o,rootDocument:s,baseURL:c});l=e.widgetContent,u=e.args}}let d=new a(l,s),f=i.data.into??s.body;return d.inject({into:f,bind:t}),r.widgets.push(d),n.log(`Widget bound to modal`,r.cleanupLoggedArgs(u),f,t),d}static handleMessageEvent(t){if(!t.data||typeof t.data!=`object`||t.data.type!==`OpenWidgetContent`)return;let o=t.data?.widgetId;if(!o||typeof o!=`string`){n.error(`widgetId is required in the message event data`);return}let s=r.widgetOptions[o];if(!s){n.error(`No widget options found for widgetId`,{widgetId:o});return}let c=null;try{c=new URL(s.baseURL).origin}catch{c=null}if(!c||t.origin!==c){n.warn(`Ignoring OpenWidgetContent from unexpected origin`,{origin:t.origin,expectedOrigin:c});return}let{spotId:l,rootDocument:u,msCommunityWebBaseUrl:d}=e.ConfigurationService.getConfiguration({spotId:s.spotId,rootDocument:s.rootDocument??document,msCommunityWebBaseUrl:s.baseURL}),{widgetContent:f}=r.createWidgetContent({...s,widgetContentId:t.data.widgetContentId,contentType:t.data.contentType,contentId:t.data.contentId,widgetId:o,spotId:l,rootDocument:u,baseURL:d});t.data.openingIn===`Drawer`?new i(f,u).open():t.data.openingIn===`Modal`&&new a(f,u).open()}static createWidget(t){let n=new URLSearchParams(window.location.search),i={spotId:t.spotId,widgetId:t.widgetId,authToken:t.authToken,themeMode:t.themeMode,domain:t.domain,rootDocument:t.rootDocument,baseURL:t.baseURL,utmParameters:t.utmParameters??(0,e.parseUtmParameters)(n)};return r.widgetOptions[i.widgetId]=i,r.messageListened||=(window.addEventListener(`message`,r.handleMessageEvent),!0),{widget:new o(i),args:i}}static createWidgetContent(t){let n=new URLSearchParams(window.location.search),r={spotId:t.spotId,contentId:t.contentId,contentType:t.contentType,widgetContentId:t.widgetContentId,widgetId:t.widgetId,authToken:t.authToken,themeMode:t.themeMode,domain:t.domain,rootDocument:t.rootDocument,baseURL:t.baseURL,utmParameters:t.utmParameters??(0,e.parseUtmParameters)(n)};return{widgetContent:new s(r),args:r}}static cleanupLoggedArgs(e){let{authToken:t,...n}=e;return{...n,authToken:t?`***`:void 0}}},l=globalThis;l.MeltingSpot||={},l.MeltingSpot.Widget=c,exports.Drawer=i,exports.Modal=a,exports.Widget=c;
|