@meltingspot/widget 1.7.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/index.mjs CHANGED
@@ -1,383 +1,322 @@
1
- import { Logger as T, getHTMLElement as L, createDialog as P, formatBaseUrl as W, formatUUID as l, trimSlashRight as E, createIframe as U, flattenUtmParameters as y, ConfigurationService as h, parseUtmParameters as C } from "@meltingspot/core";
2
- import { EmbedFrame as I } from "@meltingspot/embed";
3
- const M = "1.7.0", r = new T({
4
- appName: "Widget SDK",
5
- appVersion: M
6
- });
7
- class R {
8
- constructor(t, e, o) {
9
- this.content = t, this.rootDocument = e, this.dialogClassname = o, this.dialogElement = null, this.triggerElement = null, this.iframeElement = null, this.currentListener = null;
10
- }
11
- inject({ into: t, bind: e, options: o }) {
12
- this.remove();
13
- const i = L({
14
- input: t,
15
- rootDocument: this.rootDocument
16
- });
17
- if (this.dialogElement = P(this.rootDocument), this.dialogElement.classList.add(this.dialogClassname), this.dialogElement.onclose = () => this.#e(), i.appendChild(this.dialogElement), e) {
18
- this.triggerElement = L({
19
- input: e,
20
- rootDocument: this.rootDocument
21
- });
22
- const d = this.open.bind(this, o);
23
- this.currentListener = (s) => {
24
- s.stopPropagation(), s.preventDefault(), d();
25
- }, this.triggerElement.addEventListener("click", this.currentListener);
26
- }
27
- }
28
- remove() {
29
- this.dialogElement && (this.dialogElement.remove(), this.dialogElement.onclose = null, this.dialogElement = null), this.triggerElement && (this.currentListener && this.triggerElement.removeEventListener("click", this.currentListener), this.triggerElement = null, this.currentListener = null);
30
- }
31
- open(t) {
32
- this.dialogElement || this.inject({ into: this.rootDocument.body }), this.dialogElement && (this.#t(), this.dialogElement.showModal());
33
- }
34
- close() {
35
- this.dialogElement && this.dialogElement.close();
36
- }
37
- #t() {
38
- this.dialogElement && (this.iframeElement = this.dialogElement.appendChild(this.content.iframe));
39
- }
40
- #e() {
41
- this.iframeElement && (this.iframeElement.remove(), this.iframeElement = null);
42
- }
43
- }
44
- class p extends R {
45
- constructor(t, e) {
46
- super(t, e, "ms-drawer");
47
- }
48
- open(t) {
49
- const { position: e = "right" } = t ?? {};
50
- super.open(t), this.dialogElement && (this.dialogElement.dataset.position = e);
51
- }
52
- }
53
- class f extends R {
54
- constructor(t, e) {
55
- super(t, e, "ms-modal");
56
- }
57
- }
58
- class k {
59
- constructor(t) {
60
- this.baseURL = W(t.baseURL), this.spotId = l(t.spotId), this.widgetId = l(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;
61
- }
62
- get iframe() {
63
- const t = new URL(
64
- `/widgets/spot/${this.spotId}/widget/${this.widgetId}`,
65
- E(this.baseURL)
66
- ), e = U({
67
- url: t,
68
- searchParams: {
69
- themeMode: this.themeMode,
70
- ms_token: this.authToken,
71
- domain: this.domain,
72
- ...y(this.utmParameters)
73
- },
74
- rootDocument: this.rootDocument
75
- });
76
- return e.classList.add("ms-widget"), e;
77
- }
78
- }
79
- class S {
80
- constructor(t) {
81
- this.baseURL = W(t.baseURL), this.spotId = l(t.spotId), this.widgetContentId = l(t.widgetContentId), this.contentId = l(t.contentId), this.widgetId = l(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;
82
- }
83
- get iframe() {
84
- const t = new URL(
85
- `/widgets/spot/${this.spotId}/widgetContent/${this.widgetContentId}`,
86
- E(this.baseURL)
87
- );
88
- t.searchParams.set("widgetId", this.widgetId);
89
- const e = U({
90
- url: t,
91
- searchParams: {
92
- themeMode: this.themeMode,
93
- ms_token: this.authToken,
94
- domain: this.domain,
95
- contentId: this.contentId,
96
- contentType: this.contentType,
97
- ...y(this.utmParameters)
98
- },
99
- rootDocument: this.rootDocument
100
- });
101
- return e.classList.add("ms-widget-content"), e;
102
- }
103
- }
104
- const n = class n {
105
- static injectWidgetInto(t, e) {
106
- const { spotId: o, rootDocument: i, msCommunityWebBaseUrl: d } = h.getConfiguration({
107
- spotId: e.spotId,
108
- rootDocument: e.rootDocument,
109
- msCommunityWebBaseUrl: e.baseURL
110
- });
111
- if (!o)
112
- throw r.error("Spot ID is required"), new Error(
113
- "Spot ID is not configured. Please set the spotId in the configuration."
114
- );
115
- const { widget: s, args: c } = n.createWidget({
116
- ...e,
117
- spotId: o,
118
- rootDocument: i,
119
- baseURL: d
120
- }), a = new I(s);
121
- return a.inject(t), n.widgets.push(a), r.log(
122
- "Widget injected",
123
- n.cleanupLoggedArgs(c),
124
- t
125
- ), a;
126
- }
127
- static injectWidgetContentInto(t, e) {
128
- const { spotId: o, rootDocument: i, msCommunityWebBaseUrl: d } = h.getConfiguration({
129
- spotId: e.spotId,
130
- rootDocument: e.rootDocument,
131
- msCommunityWebBaseUrl: e.baseURL
132
- });
133
- if (!o)
134
- throw r.error("Spot ID is required"), new Error(
135
- "Spot ID is not configured. Please set the spotId in the configuration."
136
- );
137
- const { widgetContent: s, args: c } = n.createWidgetContent({
138
- ...e,
139
- spotId: o,
140
- rootDocument: i,
141
- baseURL: d
142
- }), a = new I(s);
143
- return a.inject(t), n.widgets.push(a), r.log(
144
- "WidgetContent injected",
145
- n.cleanupLoggedArgs(c),
146
- t
147
- ), a;
148
- }
149
- static bindWidgetModalTo(t, e) {
150
- return n.bindEntityModalTo(t, {
151
- type: "Widget",
152
- data: e
153
- });
154
- }
155
- static bindWidgetDrawerTo(t, e) {
156
- return n.bindEntityDrawerTo(t, {
157
- type: "Widget",
158
- data: e
159
- });
160
- }
161
- /**
162
- * Create a drawer that will contain a widget.
163
- * By default, the drawer is positioned on the right side of the screen.
164
- * @param options {WidgetArgs} Widget creation args
165
- * @returns A drawer, that can be opened and closed programmatically, and that will contain the widget.
166
- */
167
- static createWidgetDrawer(t) {
168
- const { widget: e } = n.createWidget(t);
169
- return r.log("Create Widget drawer", {
170
- data: n.cleanupLoggedArgs(t)
171
- }), new p(e, t.rootDocument ?? document);
172
- }
173
- /**
174
- * Create a modal that will contain a widget.
175
- * @param options {WidgetArgs} Widget creation args
176
- * @returns A modal, that can be opened and closed programmatically, and that will contain the widget.
177
- */
178
- static createWidgetModal(t) {
179
- const { widget: e } = n.createWidget(t);
180
- return r.log("Create Widget modal", {
181
- data: n.cleanupLoggedArgs(t)
182
- }), new f(e, t.rootDocument ?? document);
183
- }
184
- /**
185
- * Create an embed that will contain a widget.
186
- * @param options {WidgetArgs} Widget creation args
187
- * @returns An embed, that can be injected programmatically, and that will contain the
188
- */
189
- static createWidgetEmbed(t) {
190
- const { widget: e } = n.createWidget(t), o = new I(e);
191
- return r.log("Create Widget embed", {
192
- data: n.cleanupLoggedArgs(t)
193
- }), o;
194
- }
195
- static clear() {
196
- n.widgets.forEach((t) => {
197
- t.remove();
198
- }), n.widgets = [], n.widgetOptions = {}, r.log("All Widget SDK MeltingSpot elements were cleared");
199
- }
200
- static bindEntityDrawerTo(t, e) {
201
- const { spotId: o, rootDocument: i, msCommunityWebBaseUrl: d } = h.getConfiguration({
202
- spotId: e.data.spotId,
203
- rootDocument: e.data.rootDocument ?? document,
204
- msCommunityWebBaseUrl: e.data.baseURL
205
- });
206
- if (!o)
207
- throw r.error("Spot ID is required"), new Error(
208
- "Spot ID is not configured. Please set the spotId in the configuration."
209
- );
210
- let s, c;
211
- switch (e.type) {
212
- case "Widget":
213
- {
214
- const u = n.createWidget({
215
- ...e.data,
216
- spotId: o,
217
- rootDocument: i,
218
- baseURL: d
219
- });
220
- s = u.widget, c = u.args;
221
- }
222
- break;
223
- case "WidgetContent": {
224
- const u = n.createWidgetContent({
225
- ...e.data,
226
- spotId: o,
227
- rootDocument: i,
228
- baseURL: d
229
- });
230
- s = u.widgetContent, c = u.args;
231
- }
232
- }
233
- const a = new p(s, i), g = {
234
- position: e.data.position
235
- }, m = e.data.into ?? i.body;
236
- return a.inject({
237
- into: m,
238
- bind: t,
239
- options: g
240
- }), n.widgets.push(a), r.log(
241
- "Widget bound to drawer",
242
- n.cleanupLoggedArgs(c),
243
- g,
244
- m,
245
- t
246
- ), a;
247
- }
248
- static bindEntityModalTo(t, e) {
249
- const { spotId: o, rootDocument: i, msCommunityWebBaseUrl: d } = h.getConfiguration({
250
- spotId: e.data.spotId,
251
- rootDocument: e.data.rootDocument ?? document,
252
- msCommunityWebBaseUrl: e.data.baseURL
253
- });
254
- if (!o)
255
- throw r.error("Spot ID is required"), new Error(
256
- "Spot ID is not configured. Please set the spotId in the configuration."
257
- );
258
- let s, c;
259
- switch (e.type) {
260
- case "Widget":
261
- {
262
- const m = n.createWidget({
263
- ...e.data,
264
- spotId: o,
265
- rootDocument: i,
266
- baseURL: d
267
- });
268
- s = m.widget, c = m.args;
269
- }
270
- break;
271
- case "WidgetContent": {
272
- const m = n.createWidgetContent({
273
- ...e.data,
274
- spotId: o,
275
- rootDocument: i,
276
- baseURL: d
277
- });
278
- s = m.widgetContent, c = m.args;
279
- }
280
- }
281
- const a = new f(s, i), g = e.data.into ?? i.body;
282
- return a.inject({ into: g, bind: t }), n.widgets.push(a), r.log(
283
- "Widget bound to modal",
284
- n.cleanupLoggedArgs(c),
285
- g,
286
- t
287
- ), a;
288
- }
289
- static handleMessageEvent(t) {
290
- if (!t.data || typeof t.data != "object" || t.data.type !== "OpenWidgetContent")
291
- return;
292
- const e = t.data?.widgetId;
293
- if (!e || typeof e != "string") {
294
- r.error("widgetId is required in the message event data");
295
- return;
296
- }
297
- const o = n.widgetOptions[e];
298
- if (!o) {
299
- r.error("No widget options found for widgetId", { widgetId: e });
300
- return;
301
- }
302
- let i = null;
303
- try {
304
- i = new URL(o.baseURL).origin;
305
- } catch {
306
- i = null;
307
- }
308
- if (!i || t.origin !== i) {
309
- r.warn("Ignoring OpenWidgetContent from unexpected origin", {
310
- origin: t.origin,
311
- expectedOrigin: i
312
- });
313
- return;
314
- }
315
- const { spotId: d, rootDocument: s, msCommunityWebBaseUrl: c } = h.getConfiguration({
316
- spotId: o.spotId,
317
- rootDocument: o.rootDocument ?? document,
318
- msCommunityWebBaseUrl: o.baseURL
319
- }), { widgetContent: a } = n.createWidgetContent({
320
- ...o,
321
- widgetContentId: t.data.widgetContentId,
322
- contentType: t.data.contentType,
323
- contentId: t.data.contentId,
324
- widgetId: e,
325
- spotId: d,
326
- rootDocument: s,
327
- baseURL: c
328
- });
329
- t.data.openingIn === "Drawer" ? new p(a, s).open() : t.data.openingIn === "Modal" && new f(a, s).open();
330
- }
331
- static createWidget(t) {
332
- const e = new URLSearchParams(window.location.search), o = {
333
- spotId: t.spotId,
334
- widgetId: t.widgetId,
335
- authToken: t.authToken,
336
- themeMode: t.themeMode,
337
- domain: t.domain,
338
- rootDocument: t.rootDocument,
339
- baseURL: t.baseURL,
340
- utmParameters: t.utmParameters ?? C(e)
341
- };
342
- return n.widgetOptions[o.widgetId] = o, n.messageListened || (window.addEventListener("message", n.handleMessageEvent), n.messageListened = !0), {
343
- widget: new k(o),
344
- args: o
345
- };
346
- }
347
- static createWidgetContent(t) {
348
- const e = new URLSearchParams(window.location.search), o = {
349
- spotId: t.spotId,
350
- contentId: t.contentId,
351
- contentType: t.contentType,
352
- widgetContentId: t.widgetContentId,
353
- widgetId: t.widgetId,
354
- authToken: t.authToken,
355
- themeMode: t.themeMode,
356
- domain: t.domain,
357
- rootDocument: t.rootDocument,
358
- baseURL: t.baseURL,
359
- utmParameters: t.utmParameters ?? C(e)
360
- };
361
- return {
362
- widgetContent: new S(o),
363
- args: o
364
- };
365
- }
366
- static cleanupLoggedArgs(t) {
367
- const { authToken: e, ...o } = t;
368
- return {
369
- ...o,
370
- authToken: e ? "***" : void 0
371
- };
372
- }
373
- };
374
- n.widgets = [], n.messageListened = !1, n.widgetOptions = {};
375
- let b = n;
376
- const D = globalThis;
377
- D.MeltingSpot || (D.MeltingSpot = {});
378
- D.MeltingSpot.Widget = b;
379
- export {
380
- p as Drawer,
381
- f as Modal,
382
- b as Widget
383
- };
1
+ import { ConfigurationService as e, Logger as t, createDialog as n, createIframe as r, flattenUtmParameters as i, formatBaseUrl as a, formatUUID as o, getHTMLElement as s, parseUtmParameters as c, trimSlashRight as l } from "@meltingspot/core";
2
+ import { EmbedFrame as u } from "@meltingspot/embed";
3
+ //#endregion
4
+ //#region libs/sdk/widget/src/logger.ts
5
+ var d = new t({
6
+ appName: "Widget SDK",
7
+ appVersion: "1.9.0"
8
+ }), f = class {
9
+ constructor(e, t, n) {
10
+ this.content = e, this.rootDocument = t, this.dialogClassname = n, this.dialogElement = null, this.triggerElement = null, this.iframeElement = null, this.currentListener = null;
11
+ }
12
+ inject({ into: e, bind: t, options: r }) {
13
+ this.remove();
14
+ let i = s({
15
+ input: e,
16
+ rootDocument: this.rootDocument
17
+ });
18
+ if (this.dialogElement = n(this.rootDocument), this.dialogElement.classList.add(this.dialogClassname), this.dialogElement.onclose = () => this.#t(), i.appendChild(this.dialogElement), t) {
19
+ this.triggerElement = s({
20
+ input: t,
21
+ rootDocument: this.rootDocument
22
+ });
23
+ let e = this.open.bind(this, r);
24
+ this.currentListener = (t) => {
25
+ t.stopPropagation(), t.preventDefault(), e();
26
+ }, this.triggerElement.addEventListener("click", this.currentListener);
27
+ }
28
+ }
29
+ remove() {
30
+ 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);
31
+ }
32
+ open(e) {
33
+ this.dialogElement || this.inject({ into: this.rootDocument.body }), this.dialogElement && (this.#e(), this.dialogElement.showModal());
34
+ }
35
+ close() {
36
+ this.dialogElement && this.dialogElement.close();
37
+ }
38
+ #e() {
39
+ this.dialogElement && (this.iframeElement = this.dialogElement.appendChild(this.content.iframe));
40
+ }
41
+ #t() {
42
+ this.iframeElement &&= (this.iframeElement.remove(), null);
43
+ }
44
+ }, p = class extends f {
45
+ constructor(e, t) {
46
+ super(e, t, "ms-drawer");
47
+ }
48
+ open(e) {
49
+ let { position: t = "right" } = e ?? {};
50
+ super.open(e), this.dialogElement && (this.dialogElement.dataset.position = t);
51
+ }
52
+ }, m = class extends f {
53
+ constructor(e, t) {
54
+ super(e, t, "ms-modal");
55
+ }
56
+ }, h = class {
57
+ constructor(e) {
58
+ this.baseURL = a(e.baseURL), this.spotId = o(e.spotId), this.widgetId = o(e.widgetId), this.authToken = e.authToken ?? null, this.themeMode = e.themeMode ?? "auto", this.domain = e.domain ?? null, this.utmParameters = e.utmParameters ?? null, this.rootDocument = e.rootDocument;
59
+ }
60
+ get iframe() {
61
+ let e = new URL(`/widgets/spot/${this.spotId}/widget/${this.widgetId}`, l(this.baseURL)), t = r({
62
+ url: e,
63
+ searchParams: {
64
+ themeMode: this.themeMode,
65
+ ms_token: this.authToken,
66
+ domain: this.domain,
67
+ ...i(this.utmParameters)
68
+ },
69
+ rootDocument: this.rootDocument
70
+ });
71
+ return t.classList.add("ms-widget"), t;
72
+ }
73
+ }, g = class {
74
+ constructor(e) {
75
+ this.baseURL = a(e.baseURL), this.spotId = o(e.spotId), this.widgetContentId = o(e.widgetContentId), this.contentId = o(e.contentId), this.widgetId = o(e.widgetId), this.contentType = e.contentType, this.authToken = e.authToken ?? null, this.themeMode = e.themeMode ?? "auto", this.domain = e.domain ?? null, this.utmParameters = e.utmParameters ?? null, this.rootDocument = e.rootDocument;
76
+ }
77
+ get iframe() {
78
+ let e = new URL(`/widgets/spot/${this.spotId}/widgetContent/${this.widgetContentId}`, l(this.baseURL));
79
+ e.searchParams.set("widgetId", this.widgetId);
80
+ let t = r({
81
+ url: e,
82
+ searchParams: {
83
+ themeMode: this.themeMode,
84
+ ms_token: this.authToken,
85
+ domain: this.domain,
86
+ contentId: this.contentId,
87
+ contentType: this.contentType,
88
+ ...i(this.utmParameters)
89
+ },
90
+ rootDocument: this.rootDocument
91
+ });
92
+ return t.classList.add("ms-widget-content"), t;
93
+ }
94
+ }, _ = class t {
95
+ static {
96
+ this.widgets = [];
97
+ }
98
+ static {
99
+ this.messageListened = !1;
100
+ }
101
+ static {
102
+ this.widgetOptions = {};
103
+ }
104
+ static injectWidgetInto(n, r) {
105
+ let { spotId: i, rootDocument: a, msCommunityWebBaseUrl: o } = e.getConfiguration({
106
+ spotId: r.spotId,
107
+ rootDocument: r.rootDocument,
108
+ msCommunityWebBaseUrl: r.baseURL
109
+ });
110
+ if (!i) throw d.error("Spot ID is required"), Error("Spot ID is not configured. Please set the spotId in the configuration.");
111
+ let { widget: s, args: c } = t.createWidget({
112
+ ...r,
113
+ spotId: i,
114
+ rootDocument: a,
115
+ baseURL: o
116
+ }), l = new u(s);
117
+ return l.inject(n), t.widgets.push(l), d.log("Widget injected", t.cleanupLoggedArgs(c), n), l;
118
+ }
119
+ static injectWidgetContentInto(n, r) {
120
+ let { spotId: i, rootDocument: a, msCommunityWebBaseUrl: o } = e.getConfiguration({
121
+ spotId: r.spotId,
122
+ rootDocument: r.rootDocument,
123
+ msCommunityWebBaseUrl: r.baseURL
124
+ });
125
+ if (!i) throw d.error("Spot ID is required"), Error("Spot ID is not configured. Please set the spotId in the configuration.");
126
+ let { widgetContent: s, args: c } = t.createWidgetContent({
127
+ ...r,
128
+ spotId: i,
129
+ rootDocument: a,
130
+ baseURL: o
131
+ }), l = new u(s);
132
+ return l.inject(n), t.widgets.push(l), d.log("WidgetContent injected", t.cleanupLoggedArgs(c), n), l;
133
+ }
134
+ static bindWidgetModalTo(e, n) {
135
+ return t.bindEntityModalTo(e, {
136
+ type: "Widget",
137
+ data: n
138
+ });
139
+ }
140
+ static bindWidgetDrawerTo(e, n) {
141
+ return t.bindEntityDrawerTo(e, {
142
+ type: "Widget",
143
+ data: n
144
+ });
145
+ }
146
+ static createWidgetDrawer(e) {
147
+ let { widget: n } = t.createWidget(e);
148
+ return d.log("Create Widget drawer", { data: t.cleanupLoggedArgs(e) }), new p(n, e.rootDocument ?? document);
149
+ }
150
+ static createWidgetModal(e) {
151
+ let { widget: n } = t.createWidget(e);
152
+ return d.log("Create Widget modal", { data: t.cleanupLoggedArgs(e) }), new m(n, e.rootDocument ?? document);
153
+ }
154
+ static createWidgetEmbed(e) {
155
+ let { widget: n } = t.createWidget(e), r = new u(n);
156
+ return d.log("Create Widget embed", { data: t.cleanupLoggedArgs(e) }), r;
157
+ }
158
+ static clear() {
159
+ t.widgets.forEach((e) => {
160
+ e.remove();
161
+ }), t.widgets = [], t.widgetOptions = {}, d.log("All Widget SDK MeltingSpot elements were cleared");
162
+ }
163
+ static bindEntityDrawerTo(n, r) {
164
+ let { spotId: i, rootDocument: a, msCommunityWebBaseUrl: o } = e.getConfiguration({
165
+ spotId: r.data.spotId,
166
+ rootDocument: r.data.rootDocument ?? document,
167
+ msCommunityWebBaseUrl: r.data.baseURL
168
+ });
169
+ if (!i) throw d.error("Spot ID is required"), Error("Spot ID is not configured. Please set the spotId in the configuration.");
170
+ let s, c;
171
+ switch (r.type) {
172
+ case "Widget":
173
+ {
174
+ let e = t.createWidget({
175
+ ...r.data,
176
+ spotId: i,
177
+ rootDocument: a,
178
+ baseURL: o
179
+ });
180
+ s = e.widget, c = e.args;
181
+ }
182
+ break;
183
+ case "WidgetContent": {
184
+ let e = t.createWidgetContent({
185
+ ...r.data,
186
+ spotId: i,
187
+ rootDocument: a,
188
+ baseURL: o
189
+ });
190
+ s = e.widgetContent, c = e.args;
191
+ }
192
+ }
193
+ let l = new p(s, a), u = { position: r.data.position }, f = r.data.into ?? a.body;
194
+ return l.inject({
195
+ into: f,
196
+ bind: n,
197
+ options: u
198
+ }), t.widgets.push(l), d.log("Widget bound to drawer", t.cleanupLoggedArgs(c), u, f, n), l;
199
+ }
200
+ static bindEntityModalTo(n, r) {
201
+ let { spotId: i, rootDocument: a, msCommunityWebBaseUrl: o } = e.getConfiguration({
202
+ spotId: r.data.spotId,
203
+ rootDocument: r.data.rootDocument ?? document,
204
+ msCommunityWebBaseUrl: r.data.baseURL
205
+ });
206
+ if (!i) throw d.error("Spot ID is required"), Error("Spot ID is not configured. Please set the spotId in the configuration.");
207
+ let s, c;
208
+ switch (r.type) {
209
+ case "Widget":
210
+ {
211
+ let e = t.createWidget({
212
+ ...r.data,
213
+ spotId: i,
214
+ rootDocument: a,
215
+ baseURL: o
216
+ });
217
+ s = e.widget, c = e.args;
218
+ }
219
+ break;
220
+ case "WidgetContent": {
221
+ let e = t.createWidgetContent({
222
+ ...r.data,
223
+ spotId: i,
224
+ rootDocument: a,
225
+ baseURL: o
226
+ });
227
+ s = e.widgetContent, c = e.args;
228
+ }
229
+ }
230
+ let l = new m(s, a), u = r.data.into ?? a.body;
231
+ return l.inject({
232
+ into: u,
233
+ bind: n
234
+ }), t.widgets.push(l), d.log("Widget bound to modal", t.cleanupLoggedArgs(c), u, n), l;
235
+ }
236
+ static handleMessageEvent(n) {
237
+ if (!n.data || typeof n.data != "object" || n.data.type !== "OpenWidgetContent") return;
238
+ let r = n.data?.widgetId;
239
+ if (!r || typeof r != "string") {
240
+ d.error("widgetId is required in the message event data");
241
+ return;
242
+ }
243
+ let i = t.widgetOptions[r];
244
+ if (!i) {
245
+ d.error("No widget options found for widgetId", { widgetId: r });
246
+ return;
247
+ }
248
+ let a = null;
249
+ try {
250
+ a = new URL(i.baseURL).origin;
251
+ } catch {
252
+ a = null;
253
+ }
254
+ if (!a || n.origin !== a) {
255
+ d.warn("Ignoring OpenWidgetContent from unexpected origin", {
256
+ origin: n.origin,
257
+ expectedOrigin: a
258
+ });
259
+ return;
260
+ }
261
+ let { spotId: o, rootDocument: s, msCommunityWebBaseUrl: c } = e.getConfiguration({
262
+ spotId: i.spotId,
263
+ rootDocument: i.rootDocument ?? document,
264
+ msCommunityWebBaseUrl: i.baseURL
265
+ }), { widgetContent: l } = t.createWidgetContent({
266
+ ...i,
267
+ widgetContentId: n.data.widgetContentId,
268
+ contentType: n.data.contentType,
269
+ contentId: n.data.contentId,
270
+ widgetId: r,
271
+ spotId: o,
272
+ rootDocument: s,
273
+ baseURL: c
274
+ });
275
+ n.data.openingIn === "Drawer" ? new p(l, s).open() : n.data.openingIn === "Modal" && new m(l, s).open();
276
+ }
277
+ static createWidget(e) {
278
+ let n = new URLSearchParams(window.location.search), r = {
279
+ spotId: e.spotId,
280
+ widgetId: e.widgetId,
281
+ authToken: e.authToken,
282
+ themeMode: e.themeMode,
283
+ domain: e.domain,
284
+ rootDocument: e.rootDocument,
285
+ baseURL: e.baseURL,
286
+ utmParameters: e.utmParameters ?? c(n)
287
+ };
288
+ return t.widgetOptions[r.widgetId] = r, t.messageListened ||= (window.addEventListener("message", t.handleMessageEvent), !0), {
289
+ widget: new h(r),
290
+ args: r
291
+ };
292
+ }
293
+ static createWidgetContent(e) {
294
+ let t = new URLSearchParams(window.location.search), n = {
295
+ spotId: e.spotId,
296
+ contentId: e.contentId,
297
+ contentType: e.contentType,
298
+ widgetContentId: e.widgetContentId,
299
+ widgetId: e.widgetId,
300
+ authToken: e.authToken,
301
+ themeMode: e.themeMode,
302
+ domain: e.domain,
303
+ rootDocument: e.rootDocument,
304
+ baseURL: e.baseURL,
305
+ utmParameters: e.utmParameters ?? c(t)
306
+ };
307
+ return {
308
+ widgetContent: new g(n),
309
+ args: n
310
+ };
311
+ }
312
+ static cleanupLoggedArgs(e) {
313
+ let { authToken: t, ...n } = e;
314
+ return {
315
+ ...n,
316
+ authToken: t ? "***" : void 0
317
+ };
318
+ }
319
+ }, v = globalThis;
320
+ v.MeltingSpot ||= {}, v.MeltingSpot.Widget = _;
321
+ //#endregion
322
+ export { p as Drawer, m as Modal, _ as Widget };