@meltingspot/widget 1.7.0 → 1.10.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/index.mjs
CHANGED
|
@@ -1,383 +1,322 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EmbedFrame as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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 src/logger.ts
|
|
5
|
+
var d = new t({
|
|
6
|
+
appName: "Widget SDK",
|
|
7
|
+
appVersion: "1.10.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 };
|