@financial-times/custom-code-component 2.0.1-alpha.16 → 2.0.1-alpha.18
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/CustomCodeComponent.js +71 -96
- package/dist/CustomCodeComponent.js.map +1 -1
- package/package.json +1 -1
- package/src/custom-code-component.ts +8 -9
- package/src/environment.ts +8 -41
- package/src/path.ts +10 -10
|
@@ -23,37 +23,37 @@ l.prototype.captureForType = function(o) {
|
|
|
23
23
|
return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(o) !== -1;
|
|
24
24
|
};
|
|
25
25
|
l.prototype.on = function(o, t, e, n) {
|
|
26
|
-
let s, r,
|
|
26
|
+
let s, r, i, c;
|
|
27
27
|
if (!o)
|
|
28
28
|
throw new TypeError("Invalid event type: " + o);
|
|
29
29
|
if (typeof t == "function" && (n = e, e = t, t = null), n === void 0 && (n = this.captureForType(o)), typeof e != "function")
|
|
30
30
|
throw new TypeError("Handler must be a type of Function");
|
|
31
|
-
return s = this.rootElement, r = this.listenerMap[n ? 1 : 0], r[o] || (s && s.addEventListener(o, this.handle, n), r[o] = []), t ? /^[a-z]+$/i.test(t) ? (
|
|
31
|
+
return s = this.rootElement, r = this.listenerMap[n ? 1 : 0], r[o] || (s && s.addEventListener(o, this.handle, n), r[o] = []), t ? /^[a-z]+$/i.test(t) ? (c = t, i = T) : /^#[a-z0-9\-_]+$/i.test(t) ? (c = t.slice(1), i = L) : (c = t, i = Element.prototype.matches) : (c = null, i = $.bind(this)), r[o].push({
|
|
32
32
|
selector: t,
|
|
33
33
|
handler: e,
|
|
34
|
-
matcher:
|
|
35
|
-
matcherParam:
|
|
34
|
+
matcher: i,
|
|
35
|
+
matcherParam: c
|
|
36
36
|
}), this;
|
|
37
37
|
};
|
|
38
38
|
l.prototype.off = function(o, t, e, n) {
|
|
39
|
-
let s, r,
|
|
39
|
+
let s, r, i, c, h;
|
|
40
40
|
if (typeof t == "function" && (n = e, e = t, t = null), n === void 0)
|
|
41
41
|
return this.off(o, t, e, !0), this.off(o, t, e, !1), this;
|
|
42
|
-
if (
|
|
43
|
-
for (h in
|
|
44
|
-
|
|
42
|
+
if (i = this.listenerMap[n ? 1 : 0], !o) {
|
|
43
|
+
for (h in i)
|
|
44
|
+
i.hasOwnProperty(h) && this.off(h, t, e);
|
|
45
45
|
return this;
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
47
|
+
if (c = i[o], !c || !c.length)
|
|
48
48
|
return this;
|
|
49
|
-
for (s =
|
|
50
|
-
r =
|
|
51
|
-
return
|
|
49
|
+
for (s = c.length - 1; s >= 0; s--)
|
|
50
|
+
r = c[s], (!t || t === r.selector) && (!e || e === r.handler) && (this._removedListeners.push(r), c.splice(s, 1));
|
|
51
|
+
return c.length || (delete i[o], this.rootElement && this.rootElement.removeEventListener(o, this.handle, n)), this;
|
|
52
52
|
};
|
|
53
53
|
l.prototype.handle = function(o) {
|
|
54
54
|
let t, e;
|
|
55
55
|
const n = o.type;
|
|
56
|
-
let s, r,
|
|
56
|
+
let s, r, i, c, h = [], a;
|
|
57
57
|
const m = "ftLabsDelegateIgnore";
|
|
58
58
|
if (o[m] === !0)
|
|
59
59
|
return;
|
|
@@ -70,14 +70,14 @@ l.prototype.handle = function(o) {
|
|
|
70
70
|
}
|
|
71
71
|
let u = [];
|
|
72
72
|
for (e = h.length; a && e; ) {
|
|
73
|
-
for (t = 0; t < e && (
|
|
74
|
-
a.tagName && ["button", "input", "select", "textarea"].indexOf(a.tagName.toLowerCase()) > -1 && a.hasAttribute("disabled") ? u = [] :
|
|
73
|
+
for (t = 0; t < e && (i = h[t], !!i); t++)
|
|
74
|
+
a.tagName && ["button", "input", "select", "textarea"].indexOf(a.tagName.toLowerCase()) > -1 && a.hasAttribute("disabled") ? u = [] : i.matcher.call(a, i.matcherParam, a) && u.push([o, a, i]);
|
|
75
75
|
if (a === s || (e = h.length, a = a.parentElement || a.parentNode, a instanceof HTMLDocument))
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
78
|
let v;
|
|
79
79
|
for (t = 0; t < u.length; t++)
|
|
80
|
-
if (!(this._removedListeners.indexOf(u[t][2]) > -1) && (
|
|
80
|
+
if (!(this._removedListeners.indexOf(u[t][2]) > -1) && (c = this.fire.apply(this, u[t]), c === !1)) {
|
|
81
81
|
u[t][0][m] = !0, u[t][0].preventDefault(), v = !1;
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
@@ -86,7 +86,7 @@ l.prototype.handle = function(o) {
|
|
|
86
86
|
l.prototype.fire = function(o, t, e) {
|
|
87
87
|
return e.handler.call(t, o, t);
|
|
88
88
|
};
|
|
89
|
-
function
|
|
89
|
+
function T(o, t) {
|
|
90
90
|
return o.toLowerCase() === t.tagName.toLowerCase();
|
|
91
91
|
}
|
|
92
92
|
function $(o, t) {
|
|
@@ -97,16 +97,16 @@ function $(o, t) {
|
|
|
97
97
|
t === window
|
|
98
98
|
) : this.rootElement === t;
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function L(o, t) {
|
|
101
101
|
return o === t.id;
|
|
102
102
|
}
|
|
103
103
|
l.prototype.destroy = function() {
|
|
104
104
|
this.off(), this.root();
|
|
105
105
|
};
|
|
106
|
-
function
|
|
106
|
+
function R(o) {
|
|
107
107
|
return typeof o == "string" ? o.trim() : o;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function A(o, t) {
|
|
110
110
|
for (const e in o)
|
|
111
111
|
t[e] ? console.warn(`You can't set a custom property called ${e}`) : t[e] = o[e];
|
|
112
112
|
}
|
|
@@ -118,11 +118,11 @@ const p = Object.freeze({
|
|
|
118
118
|
TEST: 4,
|
|
119
119
|
DEFAULT: 2
|
|
120
120
|
});
|
|
121
|
-
function
|
|
121
|
+
function N(o) {
|
|
122
122
|
const t = o == null ? void 0 : o.toLowerCase();
|
|
123
123
|
return t === "debug" ? p.DEBUG : t === "info" ? p.INFO : t === "warn" ? p.WARN : t === "error" ? p.ERROR : t === "test" ? p.TEST : p.DEFAULT;
|
|
124
124
|
}
|
|
125
|
-
class
|
|
125
|
+
class k {
|
|
126
126
|
constructor({ level: t = p.DEFAULT } = {
|
|
127
127
|
level: p.DEFAULT
|
|
128
128
|
}) {
|
|
@@ -141,14 +141,14 @@ class A {
|
|
|
141
141
|
this.level <= p.ERROR && console.error(...t);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const
|
|
144
|
+
const S = (o, t, e) => {
|
|
145
145
|
const n = Array.from((o == null ? void 0 : o.querySelectorAll(e)) ?? []), s = n.findIndex((r) => r === t);
|
|
146
146
|
if (s !== -1)
|
|
147
147
|
return {
|
|
148
148
|
siblings: n.length,
|
|
149
149
|
position: s
|
|
150
150
|
};
|
|
151
|
-
},
|
|
151
|
+
}, C = [
|
|
152
152
|
"nodeName",
|
|
153
153
|
"className",
|
|
154
154
|
"id",
|
|
@@ -157,9 +157,9 @@ const N = (o, t, e) => {
|
|
|
157
157
|
"role"
|
|
158
158
|
], O = (o) => {
|
|
159
159
|
const t = {};
|
|
160
|
-
for (const e of
|
|
160
|
+
for (const e of C) {
|
|
161
161
|
const n = o[e] || o.getAttribute(e) || o.hasAttribute(e);
|
|
162
|
-
n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] =
|
|
162
|
+
n !== void 0 && (typeof n == "boolean" ? t[e] = n : t[e] = R(n));
|
|
163
163
|
}
|
|
164
164
|
return t;
|
|
165
165
|
}, P = (o) => {
|
|
@@ -178,7 +178,7 @@ const N = (o, t, e) => {
|
|
|
178
178
|
t[e.name] = e.value;
|
|
179
179
|
}), t), M = (o, t, e) => {
|
|
180
180
|
const n = {};
|
|
181
|
-
return e &&
|
|
181
|
+
return e && C.forEach((s) => {
|
|
182
182
|
typeof t[s] < "u" && s !== "id" && (n[s] = t[s]);
|
|
183
183
|
}), o.filter((s) => s.name.match(/^data-trackable-context-/i)).forEach((s) => {
|
|
184
184
|
n[s.name.replace("data-trackable-context-", "")] = x(s.value);
|
|
@@ -187,14 +187,14 @@ const N = (o, t, e) => {
|
|
|
187
187
|
function D(o, t) {
|
|
188
188
|
const e = o, n = e != null && e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e == null ? void 0 : e.nodeName, s = [], r = {};
|
|
189
189
|
for (; o && o !== t; ) {
|
|
190
|
-
const
|
|
191
|
-
let h = I(
|
|
190
|
+
const i = O(o), c = Array.from(o.attributes);
|
|
191
|
+
let h = I(c, i);
|
|
192
192
|
h["data-trackable"] && (h = Object.assign(
|
|
193
193
|
h,
|
|
194
|
-
|
|
194
|
+
S(o, e, n)
|
|
195
195
|
)), s.push(h);
|
|
196
|
-
const a = M(
|
|
197
|
-
|
|
196
|
+
const a = M(c, i, o === e);
|
|
197
|
+
A(a, r), o = o.parentNode;
|
|
198
198
|
}
|
|
199
199
|
return { trace: s, customContext: r };
|
|
200
200
|
}
|
|
@@ -206,11 +206,11 @@ class F {
|
|
|
206
206
|
subtype: n = "interactive",
|
|
207
207
|
teamName: s = "djd",
|
|
208
208
|
shadowRoot: r = null,
|
|
209
|
-
category:
|
|
210
|
-
elements:
|
|
209
|
+
category: i = "cta",
|
|
210
|
+
elements: c = 'a, button, input, [role="button"]',
|
|
211
211
|
logger: h
|
|
212
212
|
}) {
|
|
213
|
-
this.cccId = t, this.cccName = e, this.subtype = n, this.teamName = s, this.shadowRoot = r, this.category =
|
|
213
|
+
this.cccId = t, this.cccName = e, this.subtype = n, this.teamName = s, this.shadowRoot = r, this.category = i, this.elements = c, this.isInitialised = !1, this.log = h ?? new k();
|
|
214
214
|
}
|
|
215
215
|
// Get properties for the event (as opposed to properties of the clicked element)
|
|
216
216
|
getEventProperties(t) {
|
|
@@ -218,7 +218,7 @@ class F {
|
|
|
218
218
|
for (const n of U)
|
|
219
219
|
if (t[n])
|
|
220
220
|
try {
|
|
221
|
-
e[n] =
|
|
221
|
+
e[n] = R(t[n]);
|
|
222
222
|
} catch (s) {
|
|
223
223
|
this.log.info(s);
|
|
224
224
|
}
|
|
@@ -227,13 +227,13 @@ class F {
|
|
|
227
227
|
// Controller for handling click events
|
|
228
228
|
handleClickEvent(t, e) {
|
|
229
229
|
return (n, s) => {
|
|
230
|
-
const r = this.getEventProperties(n), { trace:
|
|
231
|
-
r.custom = s.dataset && s.dataset.custom ? JSON.parse(s.dataset.custom) : null, r.domPathTokens =
|
|
230
|
+
const r = this.getEventProperties(n), { trace: i, customContext: c } = D(s, e);
|
|
231
|
+
r.custom = s.dataset && s.dataset.custom ? JSON.parse(s.dataset.custom) : null, r.domPathTokens = i, r.component = {
|
|
232
232
|
id: this.cccId,
|
|
233
233
|
name: this.cccName,
|
|
234
234
|
type: "custom-code-component",
|
|
235
235
|
subtype: this.subtype
|
|
236
|
-
}, r.teamName = this.teamName, r.url = document.URL,
|
|
236
|
+
}, r.teamName = this.teamName, r.url = document.URL, A(c, r), r.method = "ftCustomAnalytics", t = { ...t, ...r }, document.body.dispatchEvent(
|
|
237
237
|
new CustomEvent("oTracking.event", {
|
|
238
238
|
detail: t,
|
|
239
239
|
bubbles: !0,
|
|
@@ -284,13 +284,14 @@ class F {
|
|
|
284
284
|
}
|
|
285
285
|
class f {
|
|
286
286
|
constructor(t) {
|
|
287
|
-
|
|
287
|
+
this.org = "local", this.repo = "dev";
|
|
288
|
+
const { org: e, repo: n, component: s, versionRange: r } = E(
|
|
288
289
|
t
|
|
289
290
|
) ? t : f.fromString(t);
|
|
290
|
-
this.org = e, this.repo = n, this.component = s, this.versionRange = r;
|
|
291
|
+
e && (this.org = e), n && (this.repo = n), this.component = s, this.versionRange = r;
|
|
291
292
|
}
|
|
292
293
|
set path(t) {
|
|
293
|
-
const { org: e, repo: n, component: s, versionRange: r } =
|
|
294
|
+
const { org: e, repo: n, component: s, versionRange: r } = E(
|
|
294
295
|
t
|
|
295
296
|
) ? t : f.fromString(t);
|
|
296
297
|
this.org = e, this.repo = n, this.component = s, this.versionRange = r;
|
|
@@ -302,22 +303,21 @@ class f {
|
|
|
302
303
|
return this.path;
|
|
303
304
|
}
|
|
304
305
|
static fromString(t, e) {
|
|
305
|
-
var
|
|
306
|
+
var c;
|
|
306
307
|
if (!t) throw new d("No path specified");
|
|
307
|
-
const n = e ?? ((
|
|
308
|
-
if (!
|
|
309
|
-
|
|
310
|
-
return new f({ org: c, repo: r, component: s, versionRange: n });
|
|
308
|
+
const [n, s, r] = t.replace(/@[^\/]+/, "").split("/").reverse(), i = e ?? ((c = t.match(/@[^\/]+/)) == null ? void 0 : c.toString().replace("@", "")) ?? "unknown";
|
|
309
|
+
if (s && !i) throw new d("No version specified");
|
|
310
|
+
return new f({ org: r, repo: s, component: n, versionRange: i });
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
function
|
|
313
|
+
function E(o) {
|
|
314
314
|
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "component" in o : !1;
|
|
315
315
|
}
|
|
316
316
|
class d extends Error {
|
|
317
317
|
constructor(t, e) {
|
|
318
318
|
!e && t ? (super(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (super(
|
|
319
319
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component} imported from ${e.source ?? "an undefined source"}.`
|
|
320
|
-
), this.component = f.fromString(e.component)) :
|
|
320
|
+
), this.component = f.fromString(e.component)) : E(e == null ? void 0 : e.component) ? (super(
|
|
321
321
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component.org}/${e.component.repo}/${e.component.component}@${e.component.versionRange} imported from ${e.source ?? "an undefined source"}.`
|
|
322
322
|
), this.component = new f(e.component)) : (super(
|
|
323
323
|
`${(e == null ? void 0 : e.cause) ?? "Unknown error"} in unknown component imported from ${(e == null ? void 0 : e.source) ?? "unknown source"}.`
|
|
@@ -329,7 +329,7 @@ class g extends d {
|
|
|
329
329
|
super(t, { ...e, cause: "Import error" }), this.name = "CCCImportError";
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
class
|
|
332
|
+
class j extends d {
|
|
333
333
|
constructor(t) {
|
|
334
334
|
super(null, { ...t, cause: "Timeout error" }), this.name = "CCCTimeoutError";
|
|
335
335
|
}
|
|
@@ -345,26 +345,26 @@ const w = class w extends Event {
|
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
w.eventType = "ccc:ConnectedEvent";
|
|
348
|
-
let
|
|
349
|
-
const
|
|
348
|
+
let b = w;
|
|
349
|
+
const V = (o) => o.replace(
|
|
350
350
|
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
351
351
|
(t, e) => (e ? "-" : "") + t.toLowerCase()
|
|
352
352
|
);
|
|
353
|
-
function
|
|
353
|
+
function z(o) {
|
|
354
354
|
return y([
|
|
355
355
|
"localhost",
|
|
356
356
|
"local.ft.com",
|
|
357
357
|
/^.*\.apps\.in\.ft\.com$/
|
|
358
358
|
], o);
|
|
359
359
|
}
|
|
360
|
-
function
|
|
360
|
+
function J() {
|
|
361
361
|
return y([
|
|
362
362
|
"localhost",
|
|
363
363
|
"local.ft.com",
|
|
364
364
|
/^.*\.in\.ft\.com$/
|
|
365
365
|
], window.location.hostname);
|
|
366
366
|
}
|
|
367
|
-
function
|
|
367
|
+
function W() {
|
|
368
368
|
return y([
|
|
369
369
|
"spark.ft.com",
|
|
370
370
|
"spark-staging.ft.com"
|
|
@@ -380,45 +380,20 @@ function H(o) {
|
|
|
380
380
|
const e = new URL("http://localhost:5173");
|
|
381
381
|
try {
|
|
382
382
|
if (typeof o == "string") {
|
|
383
|
-
if ((o === "" || o.toLowerCase() === "true") &&
|
|
383
|
+
if ((o === "" || o.toLowerCase() === "true") && J())
|
|
384
384
|
t = e;
|
|
385
|
-
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !
|
|
385
|
+
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !z(t == null ? void 0 : t.hostname))
|
|
386
386
|
throw new Error("Unsafe testing host override");
|
|
387
|
-
} else
|
|
387
|
+
} else W() && (t = e);
|
|
388
388
|
} catch {
|
|
389
389
|
return t;
|
|
390
390
|
}
|
|
391
391
|
return t;
|
|
392
392
|
}
|
|
393
393
|
async function K(o) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
try {
|
|
398
|
-
return new Promise((s) => {
|
|
399
|
-
const r = new WebSocket(`ws://${n}`, "vite-hmr"), c = setTimeout(() => {
|
|
400
|
-
const i = r.readyState === WebSocket.OPEN;
|
|
401
|
-
i && r.close(), s(i);
|
|
402
|
-
}, 5e3);
|
|
403
|
-
r.addEventListener(
|
|
404
|
-
"open",
|
|
405
|
-
() => {
|
|
406
|
-
clearTimeout(c), r.close(), s(!0);
|
|
407
|
-
},
|
|
408
|
-
{ once: !0 }
|
|
409
|
-
), r.addEventListener(
|
|
410
|
-
"error",
|
|
411
|
-
() => {
|
|
412
|
-
clearTimeout(c), r.close(), s(!1);
|
|
413
|
-
},
|
|
414
|
-
{ once: !0 }
|
|
415
|
-
);
|
|
416
|
-
});
|
|
417
|
-
} catch {
|
|
418
|
-
return Promise.resolve(!1);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return await t(o == null ? void 0 : o.host);
|
|
394
|
+
return o ? fetch(new URL("index.html", o), {
|
|
395
|
+
method: "HEAD"
|
|
396
|
+
}).then(() => !0).catch(() => !1) : !1;
|
|
422
397
|
}
|
|
423
398
|
class _ extends HTMLElement {
|
|
424
399
|
constructor() {
|
|
@@ -441,8 +416,8 @@ class _ extends HTMLElement {
|
|
|
441
416
|
`Error initialising tracking on <custom-code-component> ${s}@${r}`
|
|
442
417
|
), this.log.error(n);
|
|
443
418
|
}
|
|
444
|
-
}, this.log = new
|
|
445
|
-
level:
|
|
419
|
+
}, this.log = new k({
|
|
420
|
+
level: N(this.getAttribute("log"))
|
|
446
421
|
});
|
|
447
422
|
const t = HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
448
423
|
try {
|
|
@@ -499,13 +474,13 @@ class _ extends HTMLElement {
|
|
|
499
474
|
try {
|
|
500
475
|
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.component) {
|
|
501
476
|
if (this.dispatchEvent(
|
|
502
|
-
new
|
|
477
|
+
new b({
|
|
503
478
|
component: this.component,
|
|
504
479
|
source: this.source
|
|
505
480
|
})
|
|
506
481
|
), this.dataset.cccReady = "true", delete this.dataset.cccError, !this.app)
|
|
507
482
|
throw new Error("CCC mounted without App");
|
|
508
|
-
const s = this.shadowRoot !== null, r = this.shadowRoot ?? this.attachShadow({ mode: this.mode }),
|
|
483
|
+
const s = this.shadowRoot !== null, r = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), i = JSON.parse(this.getAttribute("data-component-props")), c = Object.fromEntries(
|
|
509
484
|
[...this.attributes].filter((u) => !this.RESERVED_ATTRS.has(u.name)).map((u) => [u.name, u.value])
|
|
510
485
|
);
|
|
511
486
|
this.tracking = new F({
|
|
@@ -518,8 +493,8 @@ class _ extends HTMLElement {
|
|
|
518
493
|
const { unmount: h, onmessage: a, ready: m } = this.app(
|
|
519
494
|
r,
|
|
520
495
|
{
|
|
521
|
-
...
|
|
522
|
-
data:
|
|
496
|
+
...c,
|
|
497
|
+
data: i,
|
|
523
498
|
port: this.channel.port2,
|
|
524
499
|
tracking: this.tracking,
|
|
525
500
|
prerendered: !!t,
|
|
@@ -539,19 +514,19 @@ class _ extends HTMLElement {
|
|
|
539
514
|
// Replace shadow root with light DOM children on error
|
|
540
515
|
unmount(t) {
|
|
541
516
|
var e;
|
|
542
|
-
this.lightRoot && (this.onunmount(), (e = this.shadowRoot) == null || e.replaceChildren(...this.lightRoot), this.dataset.cccError || (this.dataset.cccError =
|
|
517
|
+
this.lightRoot && (this.onunmount(), (e = this.shadowRoot) == null || e.replaceChildren(...this.lightRoot), this.dataset.cccError || (this.dataset.cccError = V(t.name.replace("CCC", ""))), delete this.dataset.cccReady);
|
|
543
518
|
}
|
|
544
519
|
async load() {
|
|
545
520
|
if (!this.component)
|
|
546
521
|
throw new Error("No path found");
|
|
547
|
-
const t = this.getAttribute("path"), e = this.getAttribute("version"), n = Number(this.getAttribute("load-timeout") || 1e4), s = this.getAttribute("testEnv"), r = H(s),
|
|
548
|
-
this.source =
|
|
522
|
+
const t = this.getAttribute("path"), e = this.getAttribute("version"), n = Number(this.getAttribute("load-timeout") || 1e4), s = this.getAttribute("testEnv"), r = H(s), i = await K(r), c = this.getAttribute("id");
|
|
523
|
+
this.source = i ? `${r == null ? void 0 : r.origin}/src/${this.component.component}/index.jsx?id=${c}` : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${e ? `@${e}` : "@latest"}/${this.component.component}/${this.component.component}.js?id=${c}`;
|
|
549
524
|
try {
|
|
550
525
|
return await new Promise(
|
|
551
526
|
(h, a) => {
|
|
552
527
|
const m = setTimeout(() => {
|
|
553
528
|
this.log.error("CCC import timeout error"), a(
|
|
554
|
-
new
|
|
529
|
+
new j({
|
|
555
530
|
component: this.component,
|
|
556
531
|
source: this.source
|
|
557
532
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomCodeComponent.js","sources":["../node_modules/ftdomdelegate/main.js","../../node_modules/@financial-times/o-tracking/src/javascript/utils.js","../src/logger.ts","../src/get-trace.ts","../src/tracking.ts","../src/path.ts","../src/errors.ts","../src/events.ts","../src/util.ts","../src/environment.ts","../src/custom-code-component.ts","../src/index.ts"],"sourcesContent":["/**\n * DOM event delegator\n *\n * The delegator will listen\n * for events that bubble up\n * to the root node.\n *\n * @constructor\n * @param {Node|string} [root] The root node or a selector string matching the root node\n */\nfunction Delegate(root) {\n\n\t/**\n\t * Maintain a map of listener\n\t * lists, keyed by event name.\n\t *\n\t * @type Object\n\t */\n\tthis.listenerMap = [{}, {}];\n\tif (root) {\n\t\tthis.root(root);\n\t}\n\n\t/** @type function() */\n\tthis.handle = Delegate.prototype.handle.bind(this);\n\n\t// Cache of event listeners removed during an event cycle\n\tthis._removedListeners = [];\n}\n\n/**\n * Start listening for events\n * on the provided DOM element\n *\n * @param {Node|string} [root] The root node or a selector string matching the root node\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.root = function (root) {\n\tconst listenerMap = this.listenerMap;\n\tlet eventType;\n\n\t// Remove master event listeners\n\tif (this.rootElement) {\n\t\tfor (eventType in listenerMap[1]) {\n\t\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, true);\n\t\t\t}\n\t\t}\n\t\tfor (eventType in listenerMap[0]) {\n\t\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, false);\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no root or root is not\n\t// a dom node, then remove internal\n\t// root reference and exit here\n\tif (!root || !root.addEventListener) {\n\t\tif (this.rootElement) {\n\t\t\tdelete this.rootElement;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The root node at which\n\t * listeners are attached.\n\t *\n\t * @type Node\n\t */\n\tthis.rootElement = root;\n\n\t// Set up master event listeners\n\tfor (eventType in listenerMap[1]) {\n\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, true);\n\t\t}\n\t}\n\tfor (eventType in listenerMap[0]) {\n\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, false);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n/**\n * @param {string} eventType\n * @returns boolean\n */\nDelegate.prototype.captureForType = function (eventType) {\n\treturn ['blur', 'error', 'focus', 'load', 'resize', 'scroll'].indexOf(eventType) !== -1;\n};\n\n/**\n * Attach a handler to one\n * event for all elements\n * that match the selector,\n * now or in the future\n *\n * The handler function receives\n * three arguments: the DOM event\n * object, the node that matched\n * the selector while the event\n * was bubbling and a reference\n * to itself. Within the handler,\n * 'this' is equal to the second\n * argument.\n *\n * The node that actually received\n * the event can be accessed via\n * 'event.target'.\n *\n * @param {string} eventType Listen for these events\n * @param {string|undefined} selector Only handle events on elements matching this selector, if undefined match root element\n * @param {function()} handler Handler function - event data passed here will be in event.data\n * @param {boolean} [useCapture] see 'useCapture' in <https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener>\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.on = function (eventType, selector, handler, useCapture) {\n\tlet root;\n\tlet listenerMap;\n\tlet matcher;\n\tlet matcherParam;\n\n\tif (!eventType) {\n\t\tthrow new TypeError('Invalid event type: ' + eventType);\n\t}\n\n\t// handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// Fallback to sensible defaults\n\t// if useCapture not set\n\tif (useCapture === undefined) {\n\t\tuseCapture = this.captureForType(eventType);\n\t}\n\n\tif (typeof handler !== 'function') {\n\t\tthrow new TypeError('Handler must be a type of Function');\n\t}\n\n\troot = this.rootElement;\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\n\t// Add master handler for type if not created yet\n\tif (!listenerMap[eventType]) {\n\t\tif (root) {\n\t\t\troot.addEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t\tlistenerMap[eventType] = [];\n\t}\n\n\tif (!selector) {\n\t\tmatcherParam = null;\n\n\t\t// COMPLEX - matchesRoot needs to have access to\n\t\t// this.rootElement, so bind the function to this.\n\t\tmatcher = matchesRoot.bind(this);\n\n\t\t// Compile a matcher for the given selector\n\t} else if (/^[a-z]+$/i.test(selector)) {\n\t\tmatcherParam = selector;\n\t\tmatcher = matchesTag;\n\t} else if (/^#[a-z0-9\\-_]+$/i.test(selector)) {\n\t\tmatcherParam = selector.slice(1);\n\t\tmatcher = matchesId;\n\t} else {\n\t\tmatcherParam = selector;\n\t\tmatcher = Element.prototype.matches;\n\t}\n\n\t// Add to the list of listeners\n\tlistenerMap[eventType].push({\n\t\tselector: selector,\n\t\thandler: handler,\n\t\tmatcher: matcher,\n\t\tmatcherParam: matcherParam\n\t});\n\n\treturn this;\n};\n\n/**\n * Remove an event handler\n * for elements that match\n * the selector, forever\n *\n * @param {string} [eventType] Remove handlers for events matching this type, considering the other parameters\n * @param {string} [selector] If this parameter is omitted, only handlers which match the other two will be removed\n * @param {function()} [handler] If this parameter is omitted, only handlers which match the previous two will be removed\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.off = function (eventType, selector, handler, useCapture) {\n\tlet i;\n\tlet listener;\n\tlet listenerMap;\n\tlet listenerList;\n\tlet singleEventType;\n\n\t// Handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// If useCapture not set, remove\n\t// all event listeners\n\tif (useCapture === undefined) {\n\t\tthis.off(eventType, selector, handler, true);\n\t\tthis.off(eventType, selector, handler, false);\n\t\treturn this;\n\t}\n\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\tif (!eventType) {\n\t\tfor (singleEventType in listenerMap) {\n\t\t\tif (listenerMap.hasOwnProperty(singleEventType)) {\n\t\t\t\tthis.off(singleEventType, selector, handler);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tlistenerList = listenerMap[eventType];\n\tif (!listenerList || !listenerList.length) {\n\t\treturn this;\n\t}\n\n\t// Remove only parameter matches\n\t// if specified\n\tfor (i = listenerList.length - 1; i >= 0; i--) {\n\t\tlistener = listenerList[i];\n\n\t\tif ((!selector || selector === listener.selector) && (!handler || handler === listener.handler)) {\n\t\t\tthis._removedListeners.push(listener);\n\t\t\tlistenerList.splice(i, 1);\n\t\t}\n\t}\n\n\t// All listeners removed\n\tif (!listenerList.length) {\n\t\tdelete listenerMap[eventType];\n\n\t\t// Remove the main handler\n\t\tif (this.rootElement) {\n\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Handle an arbitrary event.\n *\n * @param {Event} event\n */\nDelegate.prototype.handle = function (event) {\n\tlet i;\n\tlet l;\n\tconst type = event.type;\n\tlet root;\n\tlet phase;\n\tlet listener;\n\tlet returned;\n\tlet listenerList = [];\n\tlet target;\n\tconst eventIgnore = 'ftLabsDelegateIgnore';\n\n\tif (event[eventIgnore] === true) {\n\t\treturn;\n\t}\n\n\ttarget = event.target;\n\n\t// Hardcode value of Node.TEXT_NODE\n\t// as not defined in IE8\n\tif (target.nodeType === 3) {\n\t\ttarget = target.parentNode;\n\t}\n\n\t// Handle SVG <use> elements in IE\n\tif (target.correspondingUseElement) {\n\t\ttarget = target.correspondingUseElement;\n\t}\n\n\troot = this.rootElement;\n\n\tphase = event.eventPhase || (event.target !== event.currentTarget ? 3 : 2);\n\n\t// eslint-disable-next-line default-case\n\tswitch (phase) {\n\t\tcase 1: //Event.CAPTURING_PHASE:\n\t\t\tlistenerList = this.listenerMap[1][type];\n\t\t\tbreak;\n\t\tcase 2: //Event.AT_TARGET:\n\t\t\tif (this.listenerMap[0] && this.listenerMap[0][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[0][type]);\n\t\t\t}\n\t\t\tif (this.listenerMap[1] && this.listenerMap[1][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[1][type]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3: //Event.BUBBLING_PHASE:\n\t\t\tlistenerList = this.listenerMap[0][type];\n\t\t\tbreak;\n\t}\n\n\tlet toFire = [];\n\n\t// Need to continuously check\n\t// that the specific list is\n\t// still populated in case one\n\t// of the callbacks actually\n\t// causes the list to be destroyed.\n\tl = listenerList.length;\n\twhile (target && l) {\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tlistener = listenerList[i];\n\n\t\t\t// Bail from this loop if\n\t\t\t// the length changed and\n\t\t\t// no more listeners are\n\t\t\t// defined between i and l.\n\t\t\tif (!listener) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\ttarget.tagName &&\n\t\t\t\t[\"button\", \"input\", \"select\", \"textarea\"].indexOf(target.tagName.toLowerCase()) > -1 &&\n\t\t\t\ttarget.hasAttribute(\"disabled\")\n\t\t\t) {\n\t\t\t\t// Remove things that have previously fired\n\t\t\t\ttoFire = [];\n\t\t\t}\n\t\t\t// Check for match and fire\n\t\t\t// the event if there's one\n\t\t\t//\n\t\t\t// TODO:MCG:20120117: Need a way\n\t\t\t// to check if event#stopImmediatePropagation\n\t\t\t// was called. If so, break both loops.\n\t\t\telse if (listener.matcher.call(target, listener.matcherParam, target)) {\n\t\t\t\ttoFire.push([event, target, listener]);\n\t\t\t}\n\t\t}\n\n\t\t// TODO:MCG:20120117: Need a way to\n\t\t// check if event#stopPropagation\n\t\t// was called. If so, break looping\n\t\t// through the DOM. Stop if the\n\t\t// delegation root has been reached\n\t\tif (target === root) {\n\t\t\tbreak;\n\t\t}\n\n\t\tl = listenerList.length;\n\n\t\t// Fall back to parentNode since SVG children have no parentElement in IE\n\t\ttarget = target.parentElement || target.parentNode;\n\n\t\t// Do not traverse up to document root when using parentNode, though\n\t\tif (target instanceof HTMLDocument) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tlet ret;\n\n\tfor (i = 0; i < toFire.length; i++) {\n\t\t// Has it been removed during while the event function was fired\n\t\tif (this._removedListeners.indexOf(toFire[i][2]) > -1) {\n\t\t\tcontinue;\n\t\t}\n\t\treturned = this.fire.apply(this, toFire[i]);\n\n\t\t// Stop propagation to subsequent\n\t\t// callbacks if the callback returned\n\t\t// false\n\t\tif (returned === false) {\n\t\t\ttoFire[i][0][eventIgnore] = true;\n\t\t\ttoFire[i][0].preventDefault();\n\t\t\tret = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn ret;\n};\n\n/**\n * Fire a listener on a target.\n *\n * @param {Event} event\n * @param {Node} target\n * @param {Object} listener\n * @returns {boolean}\n */\nDelegate.prototype.fire = function (event, target, listener) {\n\treturn listener.handler.call(target, event, target);\n};\n\n/**\n * Check whether an element\n * matches a tag selector.\n *\n * Tags are NOT case-sensitive,\n * except in XML (and XML-based\n * languages such as XHTML).\n *\n * @param {string} tagName The tag name to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesTag(tagName, element) {\n\treturn tagName.toLowerCase() === element.tagName.toLowerCase();\n}\n\n/**\n * Check whether an element\n * matches the root.\n *\n * @param {?String} selector In this case this is always passed through as null and not used\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesRoot(selector, element) {\n\tif (this.rootElement === window) {\n\t\treturn (\n\t\t\t// Match the outer document (dispatched from document)\n\t\t\telement === document ||\n\t\t\t// The <html> element (dispatched from document.body or document.documentElement)\n\t\t\telement === document.documentElement ||\n\t\t\t// Or the window itself (dispatched from window)\n\t\t\telement === window\n\t\t);\n\t}\n\treturn this.rootElement === element;\n}\n\n/**\n * Check whether the ID of\n * the element in 'this'\n * matches the given ID.\n *\n * IDs are case-sensitive.\n *\n * @param {string} id The ID to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesId(id, element) {\n\treturn id === element.id;\n}\n\n/**\n * Short hand for off()\n * and root(), ie both\n * with no parameters\n *\n * @return void\n */\nDelegate.prototype.destroy = function () {\n\tthis.off();\n\tthis.root();\n};\n\nexport default Delegate;\n","/**\n * Shared 'internal' scope.\n */\nimport {get} from './core/settings.js';\n\n/**\n * CUID Generator\n */\nimport {api as cuid} from '../libs/browser-cuid.js';\n\n/**\n * Record of callbacks to call when a page is tracked.\n */\nconst page_callbacks = [];\n\n/**\n * Log messages to the browser console. Requires 'log' to be set on init.\n *\n * @param {*} args items to log\n * @returns {void}\n */\nfunction log(...args) {\n\tif (get('config').test && window.console) {\n\t\tfor (const arg of args) {\n\t\t\twindow.console.log(arg);\n\t\t}\n\t}\n}\n\n/**\n * Creates a logging function that logs messages to the console with a specified namespace.\n *\n * @function namedLog\n * @param {string} namespace - The namespace to be prefixed to each log message.\n * @returns {function} A function that logs messages to the console with the given namespace if the configuration allows.\n *\n * @example\n * const log = namedLog('MyNamespace');\n * log('This is a message'); \n * // Output: [MyNamespace]: This is a message\n */\nfunction namedLog(namespace) {\n\treturn function(...args) {\n\t\tif(get('config').test && window.console) {\n\t\t\twindow.console.log(`%c[${namespace}]:`, 'color: teal', ...args)\n\t\t}\n\t}\n}\n\n/**\n * Tests if variable is a certain type. Defaults to check for undefined if no type specified.\n *\n * @param {*} variable - The variable to check.\n * @param {string=} type - The type to test for. Defaults to undefined.\n *\n * @returns {boolean} - The answer for if the variable is of type.\n */\nfunction is(variable, type = 'undefined') {\n\treturn typeof variable === type;\n}\n\n/**\n * Merge objects together. Will remove undefined and null values.\n *\n * @param {object} target - The original object to merge in to.\n * @param {object} options - The object to merge into the target. If omitted, will merge target into a new empty Object.\n *\n * @returns {object} The merged object.\n */\nfunction merge(target, options) {\n\tif (!options) {\n\t\toptions = target;\n\t\ttarget = {};\n\t}\n\n\tlet name;\n\tlet src;\n\tlet copy;\n\n\t/* jshint -W089 */\n\t/* eslint guard-for-in: 0 */\n\tfor (name in options) {\n\t\tsrc = target[name];\n\t\tcopy = options[name];\n\n\t\t// Prevent never-ending loop\n\t\tif (target === copy) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Gets rid of missing values too\n\t\tif (typeof copy !== 'undefined' && copy !== null) {\n\t\t\ttarget[name] = src === Object(src) && !is(src, 'function') ? merge(src, copy) : copy;\n\t\t}\n\t}\n\t/* jshint +W089 */\n\t/* jslint forin:true */\n\n\treturn target;\n}\n\n/**\n * URL encode a string.\n *\n * @param {string} str - The string to be encoded.\n * @returns {string} The encoded string.\n */\nfunction encode(str) {\n\tif (window.encodeURIComponent) {\n\t\treturn window.encodeURIComponent(str);\n\t} else {\n\t\treturn window.escape(str);\n\t}\n}\n\n/**\n * URL decode a string.\n *\n * @param {string} str - The string to be decoded.\n * @returns {string} The decoded string.\n */\nfunction decode(str) {\n\tif (window.decodeURIComponent) {\n\t\treturn window.decodeURIComponent(str);\n\t} else {\n\t\treturn window.unescape(str);\n\t}\n}\n\n/**\n * Utility to add event listeners.\n *\n * @param {Element} element\n * @param {string} event\n * @param {EventListenerOrEventListenerObject} listener\n * @returns {void}\n */\nfunction addEvent(element, event, listener) {\n\tif (element.addEventListener) {\n\t\telement.addEventListener(event, listener, false);\n\t} else {\n\t\telement.attachEvent('on' + event, listener);\n\t}\n}\n\n/**\n * Utility for dispatching custom events from window\n *\n * @param {string} namespace\n * @param {string} eventType\n * @param {object} detail\n * @returns {void}\n */\nfunction broadcast(namespace, eventType, detail) {\n\tdetail = detail || {};\n\ttry {\n\t\twindow.dispatchEvent(new CustomEvent(namespace + '.' + eventType, {\n\t\t\tdetail: detail,\n\t\t\tbubbles: true\n\t\t}));\n\t} catch (error) {\n\t\t// empty\n\t}\n}\n\n/**\n * Listen for page tracking requests.\n *\n * @param {Function} cb - The callback to be called whenever a page is tracked.\n * @returns {void}\n */\nfunction onPage(cb) {\n\tif (is(cb, 'function') && !page_callbacks.includes(cb)) {\n\t\tpage_callbacks.push(cb);\n\t}\n}\n\n/**\n * Trigger the 'page' listeners.\n *\n * @returns {void}\n */\nfunction triggerPage() {\n\tfor (let i = 0; i < page_callbacks.length; i++) {\n\t\tpage_callbacks[i]();\n\t}\n}\n\n/**\n * Get a value from document.cookie matching the first match of the regexp you supply\n *\n * @param {RegExp} matcher - The Regex to match with\n * @returns {string} - The vale from the cookie\n */\nfunction getValueFromCookie(matcher) {\n\treturn document.cookie.match(matcher) && RegExp.$1 !== '' && RegExp.$1 !== 'null' ? RegExp.$1 : null;\n}\n\n/**\n * Filter an object to only have the properties which are listed in the `allowlist` parameter.\n *\n * @param {object} objectToFilter - An object whose props need to be filtered\n * @param {Array} allowedPropertyNames - The list of props to allow\n * @returns {object} An object containing only the allowed props\n */\nfunction filterProperties (objectToFilter, allowedPropertyNames) {\n\tconst filteredObject = {};\n\tfor (const allowedName of allowedPropertyNames) {\n\t\tif (objectToFilter[allowedName]) {\n\t\t\tfilteredObject[allowedName] = objectToFilter[allowedName];\n\t\t}\n\t}\n\treturn filteredObject;\n}\n\n/**\n * Trim strings\n *\n * @param {string} str - The string to trim.\n * @returns {string} The trimmed string.\n */\nfunction sanitise (str) {\n\treturn typeof str === 'string' ? str.trim() : str;\n}\n\n/**\n * Assign the subject value if the target properties are undefined\n *\n * @param {object} subject - assign the value\n * @param {object} target - be assigned the value\n * @returns {void}\n */\nfunction assignIfUndefined (subject, target) {\n\tfor (const prop in subject) {\n\t\tif (!target[prop]) {\n\t\t\ttarget[prop] = subject[prop];\n\t\t} else {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(`You can't set a custom property called ${prop}`);\n\t\t}\n\t}\n}\n\n\n/**\n * Identify circular references in 'object', and replace them with a string representation\n * of the reference. Returns a succesfully serialised JSON string, and a list of circular\n * references which were removed.\n * \n * Inspired by https://github.com/sindresorhus/safe-stringify and \n * https://github.com/sindresorhus/decircular\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {Object: {jsonString: string, warnings: array}} The stringified object, and a warnings for each circular reference which was removed\n */\nfunction removeCircularReferences(object) {\n\n\t// WeakMaps release memory when all references are garbage-collected\n\tconst circularReferences = new WeakMap();\n\tconst paths = new WeakMap();\n\n\tconst warnings = [];\n\n\tfunction getPathFragment(parent, key) {\n\t\tif (!key) {\n\t\t\treturn '$';\n\t\t}\n\n\t\tif (Array.isArray(parent)) {\n\t\t\treturn `[${key}]`;\n\t\t}\n\n\t\treturn `.${key}`;\n\t}\n\n\tfunction formatCircularReferencesWarning(references) {\n\t\tconst paths = references.map(path => '`' + path.join('') + '`');\n\t\treturn 'Circular reference between ' + paths.join(' AND ');\n\t}\n\n\tfunction replacer(key, value) {\n\t\t// Scalars don't need to be inspected as they can't contain circular references\n\t\tif (!(value !== null && typeof value === 'object')) {\n\t\t\treturn value\n\t\t}\n\n\t\t// Record the path from the root ($) to the current object (value)\n\t\t// in order to print helpful circular reference warnings.\n\t\tconst path = [...paths.get(this) || [], getPathFragment(this, key)];\n\t\tpaths.set(value, path);\n\n\t\t// If a reference to the current value is already in the list, we have\n\t\t// a circular reference. Add the current value to the list along with its path,\n\t\t// and return a useful error string rather than the unserialisable value.\n\t\tif (circularReferences.has(value)) {\n\t\t\tconst references = [...circularReferences.get(value), path];\n\t\t\tcircularReferences.set(value, references);\n\t\t\tconst warning = formatCircularReferencesWarning(references);\n\t\t\twarnings.push(warning);\n\t\t\treturn warning;\n\t\t}\n\n\t\t// This is the first time we've seen the current value in this branch \n\t\t// of the object. Record its path from the object root.\n\t\tcircularReferences.set(value, [path]);\n\n\t\t// Recurse into the value to proactively find circular references\n\t\t// before encountering a loop.\n\t\tconst newValue = Array.isArray(value) ? [] : {};\n\t\tfor (const [k, v] of Object.entries(value)) {\n\t\t\tnewValue[k] = replacer.call(value, k, v);\n\t\t}\n\n\t\t// All circular references to this object will have been identified,\n\t\t// so remove it from the list.\n\t\tcircularReferences.delete(value);\n\n\t\t// This branch of the object can now be safely serialised to a JSON string\n\t\treturn newValue;\n\t}\n\n\tconst jsonString = JSON.stringify(object, replacer);\n\treturn {jsonString, warnings};\n}\n\n\n/**\n * Stringify an object to JSON, removing any circular references. When circular references\n * are found, an error is thrown in a new event loop so that global error handlers can report it.\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {string} The safely stringified JSON string\n */\nfunction safelyStringifyJson(object) {\n\n\t// JSON.stringify throws on two cases:\n\t// - value contains a circular reference\n\t// - A BigInt value is encountered\n\t// Circular references are a real possibility in the way o-tracking is called (and saves a queue of \n\t// messages in a store), so we need to handle those gracefully.\n\t// \n\t// However, for performance reasons, we always attempt to do a basic JSON.stringify() first. The \n\t// recursion involved in removeCircularReferences() makes it about 20x slower to stringify a basic payload. \n\t// This performance hit will be exacerbated on slow devices (e.g. old Android phones) with lots of queued offline events.\n\ttry {\n\t\treturn JSON.stringify(object);\n\n\t// NB: error is discarded - we have more work to do in order to throw a useful message\n\t} catch (error) {\n\t\n\t\tconst {jsonString, warnings} = removeCircularReferences(object);\n\t\n\t\tif (warnings.length) {\n\t\t\t// Throw in a new event loop, as we always want to return JSON so the tracking payload is sent\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst errorMessage = \"AssertionError: o-tracking does not support circular references in the analytics data.\\n\" +\n\t\t\t\t\"Please remove the circular references in the data.\\n\" +\n\t\t\t\t\"Here are the paths in the data which are circular:\\n\" +\n\t\t\t\twarnings.join('\\n');\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t});\n\t\t}\n\t\n\t\treturn jsonString;\n\t}\n\n\n};\n\n/**\n * Find out whether two objects are deeply equal to each other.\n *\n * @param {*} a\n * @param {*} b\n * @returns {boolean} - true if the two arguments are deeply equal\n */\nfunction isDeepEqual(a, b) {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\ta &&\n\t\tb &&\n\t\ttypeof a === \"object\" &&\n\t\ttypeof b === \"object\"\n\t) {\n\t\tif (a.constructor !== b.constructor) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (Array.isArray(a)) {\n\t\t\tconst length = a.length;\n\t\t\tif (length !== b.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\t\tif (!isDeepEqual(a[i], b[i])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (a.constructor === RegExp) {\n\t\t\treturn (\n\t\t\t\ta.source === b.source && a.flags === b.flags\n\t\t\t);\n\t\t}\n\t\tif (a.valueOf !== Object.prototype.valueOf) {\n\t\t\treturn a.valueOf() === b.valueOf();\n\t\t}\n\t\tif (a.toString !== Object.prototype.toString) {\n\t\t\treturn a.toString() === b.toString();\n\t\t}\n\n\t\tconst keys = Object.keys(a);\n\t\tconst length = keys.length;\n\t\tif (length !== Object.keys(b).length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tif (!Object.prototype.hasOwnProperty.call(b, keys[i])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tconst key = keys[i];\n\n\t\t\tif (!isDeepEqual(a[key], b[key])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\nexport {\n\tlog,\n\tnamedLog,\n\tis,\n\tis as isUndefined,\n\tmerge,\n\tencode,\n\tdecode,\n\tcuid as guid,\n\taddEvent,\n\tbroadcast,\n\tonPage,\n\ttriggerPage,\n\tgetValueFromCookie,\n\tsanitise,\n\tassignIfUndefined,\n\tfilterProperties,\n\tremoveCircularReferences,\n\tsafelyStringifyJson,\n\tisDeepEqual\n};\n","export const LogLevel = Object.freeze({\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3,\n TEST: 4,\n DEFAULT: 2,\n});\n\nexport function convertStringLogLevel(value: string | null) {\n const level = value?.toLowerCase();\n\n if (level === \"debug\") {\n return LogLevel.DEBUG;\n }\n\n if (level === \"info\") {\n return LogLevel.INFO;\n }\n\n if (level === \"warn\") {\n return LogLevel.WARN;\n }\n\n if (level === \"error\") {\n return LogLevel.ERROR;\n }\n\n if (level === \"test\") {\n return LogLevel.TEST;\n }\n\n return LogLevel.DEFAULT;\n}\n\nexport class Logger {\n level: number;\n constructor(\n { level = LogLevel.DEFAULT }: { level: number } = {\n level: LogLevel.DEFAULT,\n }\n ) {\n this.level = level;\n }\n\n debug(...args: any[]) {\n if (this.level <= LogLevel.DEBUG) {\n console.info(...args);\n }\n }\n\n log = this.debug;\n\n info(...args: any[]) {\n if (this.level <= LogLevel.INFO) {\n console.info(...args);\n }\n }\n\n warn(...args: any[]) {\n if (this.level <= LogLevel.WARN) {\n console.warn(...args);\n }\n }\n\n error(...args: any[]) {\n if (this.level <= LogLevel.ERROR) {\n console.error(...args);\n }\n }\n}\n","// Trace the element and all of its parents, collecting properties as we go\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\n\ntype PropMap = { [k: string]: any };\n// For a given container element, get the number of elements that match the\n// original element (siblings); and the index of the original element (position).\nconst getSiblingsAndPosition = (\n el: Element | null,\n originalEl: Element,\n selector: string\n) => {\n const siblings = Array.from(el?.querySelectorAll(selector) ?? []);\n const position = siblings.findIndex((item) => item === originalEl);\n if (position === -1) {\n return;\n }\n return {\n siblings: siblings.length,\n position,\n };\n};\n\nconst elementPropertiesToCollect = [\n \"nodeName\",\n \"className\",\n \"id\",\n \"href\",\n \"text\",\n \"role\",\n];\n// Get all (sanitised) properties of a given element.\nconst getAllElementProperties = (element: any) => {\n const properties: PropMap = {};\n for (const property of elementPropertiesToCollect) {\n const value =\n element[property] ||\n element.getAttribute(property) ||\n element.hasAttribute(property);\n if (value !== undefined) {\n if (typeof value === \"boolean\") {\n properties[property] = value;\n } else {\n properties[property] = sanitise(value);\n }\n }\n }\n\n return properties;\n};\n\nconst parseRawValue = (rawValue: string) => {\n try {\n const parsedValue = JSON.parse(rawValue);\n const type = Object.prototype.toString.call(parsedValue);\n const isJSON = type === \"[object Object]\" || type === \"[object Array]\";\n\n return [isJSON, parsedValue];\n } catch (error) {\n return [false, null];\n }\n};\n\nconst getAttributeValue = (rawValue: string) => {\n const [isJSON, value] = parseRawValue(rawValue);\n\n return isJSON ? value : rawValue;\n};\n\n// Get some properties of a given element.\nconst getDomPathProps = (attrs: Attr[], props: PropMap) => {\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) =>\n attribute.name.match(/^data-trackable|^data-o-|^aria-/i)\n )\n .forEach((attribute) => {\n props[attribute.name] = attribute.value;\n });\n\n return props;\n};\n\n// Get only the custom data-trackable-context-? properties of a given element\nconst getContextProps = (\n attrs: Attr[],\n props: PropMap,\n isOriginalEl: boolean\n) => {\n const customProps: { [k: string]: any } = {};\n\n // for the original element collect properties like className, nodeName\n if (isOriginalEl) {\n elementPropertiesToCollect.forEach((name) => {\n if (typeof props[name] !== \"undefined\" && name !== \"id\") {\n customProps[name] = props[name];\n }\n });\n }\n\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) => attribute.name.match(/^data-trackable-context-/i))\n .forEach((attribute) => {\n customProps[attribute.name.replace(\"data-trackable-context-\", \"\")] =\n getAttributeValue(attribute.value);\n });\n\n return customProps;\n};\n\nexport function getTrace(el: Element, rootEl: Element) {\n const originalEl = el;\n const selector = originalEl?.getAttribute(\"data-trackable\")\n ? `[data-trackable=\"${originalEl.getAttribute(\"data-trackable\")}\"]`\n : originalEl?.nodeName;\n const trace = [];\n const customContext = {};\n while (el && el !== rootEl) {\n const props = getAllElementProperties(el);\n const attrs = Array.from(el.attributes);\n let domPathProps = getDomPathProps(attrs, props);\n\n // If the element happens to have a data-trackable attribute, get the siblings\n // and position of the element (relative to the current element).\n if (domPathProps[\"data-trackable\"]) {\n domPathProps = Object.assign(\n domPathProps,\n getSiblingsAndPosition(el, originalEl, selector)\n );\n }\n\n trace.push(domPathProps);\n\n const contextProps = getContextProps(attrs, props, el === originalEl);\n\n assignIfUndefined(contextProps, customContext);\n\n el = el.parentNode as Element;\n }\n return { trace, customContext };\n}\n","import Delegate from \"ftdomdelegate/main\";\n\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\nimport { Logger } from \"./logger\";\nimport { getTrace } from \"./get-trace\";\n\nconst eventPropertiesToCollect = [\"ctrlKey\", \"altKey\", \"shiftKey\", \"metaKey\"];\n\nclass Tracking {\n cccId: string;\n cccName: string;\n subtype: string;\n teamName: string;\n shadowRoot: ShadowRoot | null;\n category: string;\n elements: string | string[];\n isInitialised: boolean;\n log: Logger;\n\n constructor({\n id = \"00000000-0000-0000-0000-000000000000\",\n name = \"ccc-component\",\n subtype = \"interactive\",\n teamName = \"djd\",\n shadowRoot = null,\n category = \"cta\",\n elements = 'a, button, input, [role=\"button\"]',\n logger,\n }: {\n id?: string;\n name: string;\n subtype: string;\n teamName?: string;\n shadowRoot: ShadowRoot | null;\n category?: string;\n elements?: string | string[];\n logger: Logger;\n }) {\n this.cccId = id;\n this.cccName = name;\n this.subtype = subtype;\n this.teamName = teamName;\n this.shadowRoot = shadowRoot;\n this.category = category;\n this.elements = elements;\n this.isInitialised = false;\n this.log = logger ?? new Logger();\n }\n\n // Get properties for the event (as opposed to properties of the clicked element)\n getEventProperties(event: any) {\n const eventProperties: { [k: string]: any } = {};\n for (const property of eventPropertiesToCollect) {\n if (event[property]) {\n try {\n eventProperties[property] = sanitise(event[property]);\n } catch (e) {\n this.log.info(e);\n }\n }\n }\n return eventProperties;\n }\n\n // Controller for handling click events\n handleClickEvent(\n eventData: { action: string; category: string },\n root: Element\n ) {\n return (clickEvent: Event, clickElement: HTMLElement) => {\n const context: any = this.getEventProperties(clickEvent);\n const { trace, customContext } = getTrace(clickElement, root);\n context.custom =\n clickElement.dataset && clickElement.dataset.custom\n ? JSON.parse(clickElement.dataset.custom)\n : null;\n context.domPathTokens = trace;\n context.component = {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n };\n context.teamName = this.teamName;\n context.url = document.URL;\n\n assignIfUndefined(customContext, context);\n\n context.method = \"ftCustomAnalytics\";\n eventData = { ...eventData, ...context };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n };\n }\n\n sendSpoorEvent(triggerAction: any, extraDetail: any) {\n const eventData = {\n category: \"component\",\n action: \"act\",\n component: {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n },\n teamName: this.teamName,\n trigger_action: triggerAction,\n custom: extraDetail,\n method: \"ftCustomAnalytics\",\n };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n }\n\n init(id: string) {\n if (!this.isInitialised) {\n this.isInitialised = true;\n this.cccId = id ? id : this.cccId;\n\n const eventData = {\n action: \"click\",\n category: this.category,\n };\n\n const root = this.shadowRoot?.querySelector(\"[data-component-root]\");\n\n if (root) {\n const shadowDelegate = new Delegate(root);\n shadowDelegate.on(\n \"click\",\n this.elements,\n this.handleClickEvent(eventData, root),\n true\n );\n }\n }\n }\n}\n\nexport default Tracking;\n","import { CCCError } from \"./errors\";\n\nexport type ComponentPathType = {\n org: string;\n repo: string;\n component: string;\n versionRange: string;\n};\nexport class ComponentPath {\n org: string;\n repo: string;\n component: string;\n versionRange: string;\n\n constructor(path: ComponentPathType | string) {\n const { org, repo, component, versionRange } = isValidComponentPathObject(\n path\n )\n ? path\n : ComponentPath.fromString(path);\n this.org = org;\n this.repo = repo;\n this.component = component;\n this.versionRange = versionRange;\n }\n\n set path(path: ComponentPathType | string) {\n const { org, repo, component, versionRange } = isValidComponentPathObject(\n path\n )\n ? path\n : ComponentPath.fromString(path);\n this.org = org;\n this.repo = repo;\n this.component = component;\n this.versionRange = versionRange;\n }\n\n get path(): string {\n return `${this.org}/${this.repo}@${this.versionRange}/${this.component}`;\n }\n\n toString(): string {\n return this.path;\n }\n\n static fromString(path: string | null, v?: string | null): ComponentPath {\n if (!path) throw new CCCError(\"No path specified\");\n\n const versionRange =\n v ??\n path\n .match(/@[^\\/]+/)\n ?.toString()\n .replace(\"@\", \"\") ??\n \"unknown\";\n\n if (!versionRange) throw new CCCError(\"No version specified\");\n\n const [component, repo, org] = path\n .replace(/@[^\\/]+/, \"\")\n .split(\"/\")\n .reverse();\n\n return new ComponentPath({ org, repo, component, versionRange });\n }\n}\n\nexport type DetailType = {\n component: ComponentPath;\n source?: string;\n cause?: string;\n};\n\nexport function isValidComponentPathObject(\n value: unknown\n): value is ComponentPathType {\n if (typeof value === \"object\" && value !== null) {\n return \"org\" in value && \"repo\" in value && \"component\" in value;\n }\n\n return false;\n}\n","/**\n * This is the base CCC component error class. These are raised when the component being loaded errors\n */\n\nimport { ComponentPath, DetailType, isValidComponentPathObject } from \"./path\";\n\nexport class CCCError extends Error {\n component: ComponentPath | null;\n source?: string;\n constructor(message: string | null, detail?: DetailType) {\n if (!detail && message) {\n super(message);\n this.component = null;\n } else if (typeof detail?.component === \"string\") {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n\n this.component = ComponentPath.fromString(detail.component);\n } else if (isValidComponentPathObject(detail?.component)) {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component.org}/${detail.component.repo}/${detail.component.component}@${detail.component.versionRange} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n this.component = new ComponentPath(detail.component);\n } else {\n super(\n `${detail?.cause ?? \"Unknown error\"} in unknown component imported from ${detail?.source ?? \"unknown source\"}.`\n );\n this.component = null;\n }\n\n this.source = detail?.source;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, CCCError);\n }\n\n this.name = \"CCCError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the import of the CCC component app\n */\nexport class CCCImportError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Import error\" });\n this.name = \"CCCImportError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the rendering of the CCC component app\n */\nexport class CCCRenderError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Render error\" });\n this.name = \"CCCRenderError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur as a result of the CCC component app timing out\n */\nexport class CCCTimeoutError extends CCCError {\n constructor(detail: DetailType) {\n super(null, { ...detail, cause: \"Timeout error\" });\n this.name = \"CCCTimeoutError\";\n }\n}\n","import { ComponentPath } from \"./path\";\n\nexport class CCCConnectedEvent extends Event {\n static eventType = \"ccc:ConnectedEvent\";\n\n component: ComponentPath;\n source?: string;\n\n constructor(\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(CCCConnectedEvent.eventType, {\n bubbles: true,\n cancelable: false,\n composed: true,\n ...opts,\n });\n this.component = detail.component;\n this.source = detail.source;\n }\n}\n","/**\n * Used to convert camelCase to kebab-case\n * @param str\n * @returns\n */\nexport const kebabize = (str: string) =>\n str.replace(\n /[A-Z]+(?![a-z])|[A-Z]/g,\n ($, ofs) => (ofs ? \"-\" : \"\") + $.toLowerCase()\n );\n\n/**\n * Checks if the provided host is part of the allowed test environments.\n *\n * @param host - The hostname to check.\n * @returns True if the hostname is a safe test environment, false otherwise.\n */\nexport function isSafeTestEnv(host: string | undefined) {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.apps\\.in\\.ft\\.com$/,\n ], host);\n}\n\n/**\n * Checks if the current window location hostname is considered a local environment.\n *\n * @returns True if the hostname is local, false otherwise.\n */\nexport function isLocalEnv() {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.in\\.ft\\.com$/,\n ], window.location.hostname);\n}\n\n/**\n * Checks if the current window location host is one of the Spark environments.\n *\n * @returns True if the host is spark.ft.com or spark-staging.ft.com, false otherwise.\n */\nexport function isSparkEnv() {\n return isAllowed([\n 'spark.ft.com',\n 'spark-staging.ft.com',\n ], window.location.host);\n}\n\n/**\n * Checks if the given hostname is in the provided allowlist.\n *\n * @param allowlist - A list of allowed hostnames or RegExp matchers.\n * @param hostname - The hostname to validate.\n * @returns True if the hostname matches any item in the allowlist, false otherwise.\n */\nexport function isAllowed(allowlist: (string|RegExp)[], hostname: string | undefined) {\n if (!hostname) return false;\n return allowlist.some(item => {\n if (typeof item === 'string') {\n return item === hostname;\n }\n return item.test(hostname);\n });\n} \n","import { isLocalEnv, isSafeTestEnv, isSparkEnv } from \"./util\";\n\n/**\n * Assigns a test URL based on the provided testEnv value.\n *\n * @param testEnv - A string indicating test environment setting\n * @returns A `URL` object if valid and safe, or `undefined` if invalid.\n */\nexport function assignTestURL(testEnv: string | null): URL | undefined {\n if (testEnv === null) {\n return;\n }\n\n let testUrl;\n const defaultTestUrl = new URL(\"http://localhost:5173\");\n\n try {\n if (typeof testEnv === \"string\") {\n if (\n (testEnv === \"\" || testEnv.toLowerCase() === \"true\") &&\n isLocalEnv()\n ) {\n testUrl = defaultTestUrl;\n } else {\n const hasProtocol =\n testEnv.startsWith(\"http://\") || testEnv.startsWith(\"https://\");\n testUrl = hasProtocol ? new URL(testEnv) : undefined;\n\n // Prevent script injection\n if (testUrl && !isSafeTestEnv(testUrl?.hostname)) {\n throw new Error(\"Unsafe testing host override\");\n }\n }\n } else if (isSparkEnv()) {\n testUrl = defaultTestUrl;\n }\n } catch (_) {\n return testUrl;\n }\n\n return testUrl;\n}\n\n/**\n * Checks whether the given test URL can establish a successful WebSocket connection,\n * which indicates a live test environment (e.g., Vite HMR is active).\n *\n * @param testUrl - The test environment URL to check.\n * @returns A promise that resolves to true if WebSocket connection is open, otherwise false.\n */\nexport async function useComponentTestEnv(testUrl?: URL): Promise<boolean> {\n if (!testUrl) {\n return false;\n }\n\n function checkWebSocketOpen(host: string): Promise<boolean> {\n try {\n return new Promise<boolean>((res) => {\n const socket = new WebSocket(`ws://${host}`, \"vite-hmr\");\n\n const timer = setTimeout(() => {\n const isOpen = socket.readyState === WebSocket.OPEN;\n if (isOpen) socket.close();\n res(isOpen);\n }, 5000);\n\n socket.addEventListener(\n \"open\",\n () => {\n clearTimeout(timer);\n socket.close();\n res(true);\n },\n { once: true }\n );\n\n socket.addEventListener(\n \"error\",\n () => {\n clearTimeout(timer);\n socket.close();\n res(false);\n },\n { once: true }\n );\n });\n } catch (err) {\n return Promise.resolve(false);\n }\n }\n\n const isWebSocketOpen = await checkWebSocketOpen(testUrl?.host);\n\n return isWebSocketOpen;\n}\n","/**\n * @file\n * Main component definition for custom-code-component\n */\n\nimport type { ContentTree } from \"@financial-times/content-tree\";\nimport { BaseRenderer } from \"../../ccc-sdk/src/renderers/BaseRenderer\";\nimport Tracking from \"./tracking\";\nimport { convertStringLogLevel, Logger } from \"./logger\";\nimport {\n CCCError,\n CCCImportError,\n CCCRenderError,\n CCCTimeoutError,\n} from \"./errors\";\nimport { CCCConnectedEvent } from \"./events\";\nimport { ComponentPath } from \"./path\";\nimport { kebabize } from \"./util\";\nimport { assignTestURL, useComponentTestEnv } from \"./environment\";\n\nexport class FTCustomCodeComponent extends HTMLElement {\n app?: typeof BaseRenderer.prototype.render;\n mode: \"closed\" | \"open\" = \"open\";\n RESERVED_ATTRS = new Set([\n \"iframe\",\n \"path\",\n \"version\",\n \"data-component-props\",\n \"data-asset-type\",\n \"shadow-open\",\n \"env\",\n \"load-timeout\",\n ]);\n\n source?: string;\n tracking?: Tracking;\n lightRoot?: ChildNode[];\n component?: ComponentPath;\n\n log: Logger;\n\n constructor() {\n super();\n this.log = new Logger({\n level: convertStringLogLevel(this.getAttribute(\"log\")),\n });\n\n const supportsDeclarative =\n HTMLElement.prototype.hasOwnProperty(\"attachInternals\");\n\n try {\n const internals = supportsDeclarative && this.attachInternals();\n } catch (e) {\n this.log.error(e);\n }\n }\n\n async connectedCallback() {\n try {\n const path = this.getAttribute(\"path\");\n const versionRange = this.getAttribute(\"version\");\n this.component = ComponentPath.fromString(path, versionRange);\n \n // Backup the light root to restore in case of error\n this.lightRoot = Array.from(this.childNodes);\n this.app = await this.load();\n await this.mount();\n await this.initTracking();\n } catch (e) {\n if (e instanceof Error) {\n requestAnimationFrame(() => {\n this.emitError(e);\n });\n }\n\n this.unmount(e as Error);\n }\n }\n\n emitError(error: Error) {\n let errorEvent;\n\n if (error instanceof CCCError && error.name?.startsWith(\"CCC\")) {\n errorEvent = error.name.replace(/^CCC/, \"ccc:\");\n } else {\n errorEvent = `ccc:${error?.name ?? \"UnknownError\"}`;\n }\n\n if (!errorEvent) {\n return this.log.debug(error);\n }\n\n this.dispatchEvent(\n new ErrorEvent(errorEvent, {\n bubbles: true,\n cancelable: false,\n composed: true,\n error,\n message: error.message,\n })\n );\n }\n\n disconnectedCallback() {\n const path = this.getAttribute(\"path\");\n this.log.info(`<custom-code-component:${path}> disconnected`);\n if (typeof this.onunmount === \"function\") this.onunmount();\n }\n\n channel = new MessageChannel();\n\n onmessage() {}\n onunmount(root?: any) {}\n async onready(app: Promise<void>) {\n try {\n await app;\n } catch (e) {\n if (e instanceof Error) this.emitError(e);\n }\n }\n\n postMessage(event: any) {\n this.channel.port1.postMessage(event);\n }\n\n async mount(prerendered?: ShadowRoot | null) {\n try {\n this.mode =\n this.getAttribute(\"shadow-open\") == \"false\" ? \"closed\" : \"open\";\n if (this.component) {\n\n this.dispatchEvent(\n new CCCConnectedEvent({\n component: this.component,\n source: this.source,\n })\n );\n\n this.dataset.cccReady = \"true\";\n delete this.dataset.cccError;\n \n\n if (!this.app) {\n throw new Error(\"CCC mounted without App\");\n }\n\n const ssr = this.shadowRoot !== null;\n const shadow = this.shadowRoot ?? this.attachShadow({ mode: this.mode });\n\n const data = JSON.parse(this.getAttribute(\"data-component-props\")!);\n\n const extraProps = Object.fromEntries(\n [...this.attributes]\n .filter((attribute) => !this.RESERVED_ATTRS.has(attribute.name))\n .map((attribute) => [attribute.name, attribute.value])\n );\n\n // Create tracking instance\n this.tracking = new Tracking({\n name: this.component?.toString(),\n subtype: \"interactive\",\n teamName: \"djd\",\n shadowRoot: this.shadowRoot,\n logger: this.log,\n });\n\n const { unmount, onmessage, ready } =\n this.app(\n shadow,\n {\n ...extraProps,\n data,\n port: this.channel.port2,\n tracking: this.tracking,\n prerendered: !!prerendered,\n children: this.children,\n },\n ssr\n ) || {};\n\n if (unmount) this.onunmount = unmount;\n if (onmessage) this.onmessage = onmessage;\n if (ready) this.onready(ready);\n }\n } catch (err) {\n this.log.info(\n `<custom-code-component> uncaught error during mount from ${this.component?.toString()}`\n );\n this.log.error(err);\n\n throw err;\n }\n }\n\n // Called in top-level error handler\n // Replace shadow root with light DOM children on error\n unmount(e: Error) {\n if (this.lightRoot) {\n this.onunmount();\n this.shadowRoot?.replaceChildren(...this.lightRoot);\n \n if (!this.dataset.cccError)\n this.dataset.cccError = kebabize(e.name.replace(\"CCC\", \"\"));\n delete this.dataset.cccReady;\n }\n }\n\n async load() {\n if (!this.component) {\n throw new Error(\"No path found\")\n }\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n const timeout = Number(this.getAttribute(\"load-timeout\") || 10000);\n const testEnv = this.getAttribute(\"testEnv\")\n const testUrl = assignTestURL(testEnv)\n const isTestEnv = await useComponentTestEnv(testUrl)\n\n const id = this.getAttribute(\"id\");\n // id querystring necessary to multiple allow components with the same source (same name and version number) to appear on the page correctly\n this.source = isTestEnv\n ? `${testUrl?.origin}/src/${this.component.component}/index.jsx?id=${id}`\n : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${\n componentVersionRange ? `@${componentVersionRange}` : \"@latest\"\n }/${this.component.component}/${this.component.component}.js?id=${id}`;\n\n try {\n return await new Promise<typeof BaseRenderer.prototype.render>(\n (resolve, reject) => {\n const to = setTimeout(() => {\n this.log.error(\"CCC import timeout error\");\n reject(\n new CCCTimeoutError({\n component: this.component!,\n source: this.source,\n })\n );\n }, Number(timeout));\n\n if (this.source) {\n import(/* webpackIgnore: true */ this.source /* @vite-ignore */)\n .then(({ default: componentRenderFunction }) => {\n if (componentRenderFunction) {\n clearTimeout(to);\n resolve(componentRenderFunction);\n } else\n throw new CCCImportError(\n \"No component renderer default export found\",\n {\n component: this.component!,\n source: this.source,\n }\n );\n })\n .catch((e) => {\n clearTimeout(to);\n this.log.error(e);\n if (e instanceof Error && !(e instanceof CCCImportError)) {\n reject(\n new CCCImportError(e.message, {\n component: this.component!,\n source: this.source,\n })\n );\n } else {\n reject(e);\n }\n });\n } else {\n clearTimeout(to);\n throw new CCCImportError(`Unable to mount ${path}`, {\n component: this.component!,\n source: this.source,\n });\n }\n }\n );\n } catch (err) {\n this.log.error(\n `<custom-code-component> error during import from ${path}@${componentVersionRange}`\n );\n\n throw err;\n }\n }\n\n initTracking = async () => {\n try {\n this.tracking?.init(this.id);\n } catch (e) {\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n this.log.info(\n `Error initialising tracking on <custom-code-component> ${path}@${componentVersionRange}`\n );\n this.log.error(e);\n }\n };\n}\n\nexport interface CustomCodeComponent extends ContentTree.Node {\n type: \"CustomCodeComponent\";\n path: string;\n versionRange: string;\n altText: string;\n lastModified: string;\n fallbackImage?: ContentTree.Image;\n displayFallbackText: boolean;\n layout: \"in-line\" | \"mid-grid\" | \"full-grid\" | \"full-bleed\";\n /* prettier-ignore */\n attributes: { \n [key: string]: string | boolean | undefined;\n } | { children?: CustomCodeComponent | Array<CustomCodeComponent> };\n}\n\nexport type { FTCustomCodeComponent as CCCHTMLElement };\n","import { FTCustomCodeComponent } from \"./custom-code-component\";\n\n// Register the custom element\nexport const init = () =>\n customElements.define(\"custom-code-component\", FTCustomCodeComponent);\n\n// Allows module to be imported multiple times but custom element only registered once\nif (customElements && !customElements.get(\"custom-code-component\")) init();\n"],"names":["Delegate","root","listenerMap","eventType","selector","handler","useCapture","matcher","matcherParam","matchesTag","matchesId","matchesRoot","i","listener","listenerList","singleEventType","event","l","type","phase","returned","target","eventIgnore","toFire","ret","tagName","element","id","sanitise","str","assignIfUndefined","subject","prop","LogLevel","convertStringLogLevel","value","level","Logger","args","getSiblingsAndPosition","el","originalEl","siblings","position","item","elementPropertiesToCollect","getAllElementProperties","properties","property","parseRawValue","rawValue","parsedValue","getAttributeValue","isJSON","getDomPathProps","attrs","props","attribute","getContextProps","isOriginalEl","customProps","name","getTrace","rootEl","trace","customContext","domPathProps","contextProps","eventPropertiesToCollect","Tracking","subtype","teamName","shadowRoot","category","elements","logger","eventProperties","e","eventData","clickEvent","clickElement","context","triggerAction","extraDetail","_a","ComponentPath","path","org","repo","component","versionRange","isValidComponentPathObject","v","CCCError","message","detail","CCCImportError","CCCTimeoutError","_CCCConnectedEvent","opts","CCCConnectedEvent","kebabize","$","ofs","isSafeTestEnv","host","isAllowed","isLocalEnv","isSparkEnv","allowlist","hostname","assignTestURL","testEnv","testUrl","defaultTestUrl","useComponentTestEnv","checkWebSocketOpen","res","socket","timer","isOpen","FTCustomCodeComponent","componentVersionRange","supportsDeclarative","internals","error","errorEvent","app","prerendered","_b","ssr","shadow","data","extraProps","unmount","onmessage","ready","err","timeout","isTestEnv","resolve","reject","to","componentRenderFunction","init"],"mappings":"AAUA,SAASA,EAASC,GAAM;AAQvB,OAAK,cAAc,CAAC,CAAE,GAAE,EAAE,GACtBA,KACH,KAAK,KAAKA,CAAI,GAIf,KAAK,SAASD,EAAS,UAAU,OAAO,KAAK,IAAI,GAGjD,KAAK,oBAAoB,CAAE;AAC5B;AASAA,EAAS,UAAU,OAAO,SAAUC,GAAM;AACzC,QAAMC,IAAc,KAAK;AACzB,MAAIC;AAGJ,MAAI,KAAK,aAAa;AACrB,SAAKA,KAAaD,EAAY,CAAC;AAC9B,MAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,oBAAoBA,GAAW,KAAK,QAAQ,EAAI;AAGnE,SAAKA,KAAaD,EAAY,CAAC;AAC9B,MAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,oBAAoBA,GAAW,KAAK,QAAQ,EAAK;AAAA,EAGtE;AAKC,MAAI,CAACF,KAAQ,CAACA,EAAK;AAClB,WAAI,KAAK,eACR,OAAO,KAAK,aAEN;AASR,OAAK,cAAcA;AAGnB,OAAKE,KAAaD,EAAY,CAAC;AAC9B,IAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,iBAAiBA,GAAW,KAAK,QAAQ,EAAI;AAGhE,OAAKA,KAAaD,EAAY,CAAC;AAC9B,IAAIA,EAAY,CAAC,EAAE,eAAeC,CAAS,KAC1C,KAAK,YAAY,iBAAiBA,GAAW,KAAK,QAAQ,EAAK;AAIjE,SAAO;AACR;AAMAH,EAAS,UAAU,iBAAiB,SAAUG,GAAW;AACxD,SAAO,CAAC,QAAQ,SAAS,SAAS,QAAQ,UAAU,QAAQ,EAAE,QAAQA,CAAS,MAAM;AACtF;AA2BAH,EAAS,UAAU,KAAK,SAAUG,GAAWC,GAAU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AAenB,EAAE,SAAS;AAAA,kBAC5B,WAAW,KAAK;AAAA,kBAChB,QAAQ,KAAK;AAAA,gBACd,CAAA;AAAA,cACH,IAEAgE,EAAOhE,CAAC;AAAA,YACV,CACD;AAAA;AAEH,+BAAaiE,CAAE,GACT,IAAI9C,EAAe,mBAAmBV,CAAI,IAAI;AAAA,cAClD,WAAW,KAAK;AAAA,cAChB,QAAQ,KAAK;AAAA,YAAA,CACd;AAAA,QACH;AAAA,MAEJ;AAAA,aACOmD,GAAK;AACZ,iBAAK,IAAI;AAAA,QACP,oDAAoDnD,CAAI,IAAIoC,CAAqB;AAAA,MACnF,GAEMe;AAAA,IAAA;AAAA,EACR;AAeJ;ACvSO,MAAMO,IAAO,MAClB,eAAe,OAAO,yBAAyBvB,CAAqB;AAGlE,kBAAkB,CAAC,eAAe,IAAI,uBAAuB,KAAQuB,EAAA;","x_google_ignoreList":[0,1]}
|
|
1
|
+
{"version":3,"file":"CustomCodeComponent.js","sources":["../node_modules/ftdomdelegate/main.js","../../node_modules/@financial-times/o-tracking/src/javascript/utils.js","../src/logger.ts","../src/get-trace.ts","../src/tracking.ts","../src/path.ts","../src/errors.ts","../src/events.ts","../src/util.ts","../src/environment.ts","../src/custom-code-component.ts","../src/index.ts"],"sourcesContent":["/**\n * DOM event delegator\n *\n * The delegator will listen\n * for events that bubble up\n * to the root node.\n *\n * @constructor\n * @param {Node|string} [root] The root node or a selector string matching the root node\n */\nfunction Delegate(root) {\n\n\t/**\n\t * Maintain a map of listener\n\t * lists, keyed by event name.\n\t *\n\t * @type Object\n\t */\n\tthis.listenerMap = [{}, {}];\n\tif (root) {\n\t\tthis.root(root);\n\t}\n\n\t/** @type function() */\n\tthis.handle = Delegate.prototype.handle.bind(this);\n\n\t// Cache of event listeners removed during an event cycle\n\tthis._removedListeners = [];\n}\n\n/**\n * Start listening for events\n * on the provided DOM element\n *\n * @param {Node|string} [root] The root node or a selector string matching the root node\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.root = function (root) {\n\tconst listenerMap = this.listenerMap;\n\tlet eventType;\n\n\t// Remove master event listeners\n\tif (this.rootElement) {\n\t\tfor (eventType in listenerMap[1]) {\n\t\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, true);\n\t\t\t}\n\t\t}\n\t\tfor (eventType in listenerMap[0]) {\n\t\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, false);\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no root or root is not\n\t// a dom node, then remove internal\n\t// root reference and exit here\n\tif (!root || !root.addEventListener) {\n\t\tif (this.rootElement) {\n\t\t\tdelete this.rootElement;\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * The root node at which\n\t * listeners are attached.\n\t *\n\t * @type Node\n\t */\n\tthis.rootElement = root;\n\n\t// Set up master event listeners\n\tfor (eventType in listenerMap[1]) {\n\t\tif (listenerMap[1].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, true);\n\t\t}\n\t}\n\tfor (eventType in listenerMap[0]) {\n\t\tif (listenerMap[0].hasOwnProperty(eventType)) {\n\t\t\tthis.rootElement.addEventListener(eventType, this.handle, false);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n/**\n * @param {string} eventType\n * @returns boolean\n */\nDelegate.prototype.captureForType = function (eventType) {\n\treturn ['blur', 'error', 'focus', 'load', 'resize', 'scroll'].indexOf(eventType) !== -1;\n};\n\n/**\n * Attach a handler to one\n * event for all elements\n * that match the selector,\n * now or in the future\n *\n * The handler function receives\n * three arguments: the DOM event\n * object, the node that matched\n * the selector while the event\n * was bubbling and a reference\n * to itself. Within the handler,\n * 'this' is equal to the second\n * argument.\n *\n * The node that actually received\n * the event can be accessed via\n * 'event.target'.\n *\n * @param {string} eventType Listen for these events\n * @param {string|undefined} selector Only handle events on elements matching this selector, if undefined match root element\n * @param {function()} handler Handler function - event data passed here will be in event.data\n * @param {boolean} [useCapture] see 'useCapture' in <https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener>\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.on = function (eventType, selector, handler, useCapture) {\n\tlet root;\n\tlet listenerMap;\n\tlet matcher;\n\tlet matcherParam;\n\n\tif (!eventType) {\n\t\tthrow new TypeError('Invalid event type: ' + eventType);\n\t}\n\n\t// handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// Fallback to sensible defaults\n\t// if useCapture not set\n\tif (useCapture === undefined) {\n\t\tuseCapture = this.captureForType(eventType);\n\t}\n\n\tif (typeof handler !== 'function') {\n\t\tthrow new TypeError('Handler must be a type of Function');\n\t}\n\n\troot = this.rootElement;\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\n\t// Add master handler for type if not created yet\n\tif (!listenerMap[eventType]) {\n\t\tif (root) {\n\t\t\troot.addEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t\tlistenerMap[eventType] = [];\n\t}\n\n\tif (!selector) {\n\t\tmatcherParam = null;\n\n\t\t// COMPLEX - matchesRoot needs to have access to\n\t\t// this.rootElement, so bind the function to this.\n\t\tmatcher = matchesRoot.bind(this);\n\n\t\t// Compile a matcher for the given selector\n\t} else if (/^[a-z]+$/i.test(selector)) {\n\t\tmatcherParam = selector;\n\t\tmatcher = matchesTag;\n\t} else if (/^#[a-z0-9\\-_]+$/i.test(selector)) {\n\t\tmatcherParam = selector.slice(1);\n\t\tmatcher = matchesId;\n\t} else {\n\t\tmatcherParam = selector;\n\t\tmatcher = Element.prototype.matches;\n\t}\n\n\t// Add to the list of listeners\n\tlistenerMap[eventType].push({\n\t\tselector: selector,\n\t\thandler: handler,\n\t\tmatcher: matcher,\n\t\tmatcherParam: matcherParam\n\t});\n\n\treturn this;\n};\n\n/**\n * Remove an event handler\n * for elements that match\n * the selector, forever\n *\n * @param {string} [eventType] Remove handlers for events matching this type, considering the other parameters\n * @param {string} [selector] If this parameter is omitted, only handlers which match the other two will be removed\n * @param {function()} [handler] If this parameter is omitted, only handlers which match the previous two will be removed\n * @returns {Delegate} This method is chainable\n */\nDelegate.prototype.off = function (eventType, selector, handler, useCapture) {\n\tlet i;\n\tlet listener;\n\tlet listenerMap;\n\tlet listenerList;\n\tlet singleEventType;\n\n\t// Handler can be passed as\n\t// the second or third argument\n\tif (typeof selector === 'function') {\n\t\tuseCapture = handler;\n\t\thandler = selector;\n\t\tselector = null;\n\t}\n\n\t// If useCapture not set, remove\n\t// all event listeners\n\tif (useCapture === undefined) {\n\t\tthis.off(eventType, selector, handler, true);\n\t\tthis.off(eventType, selector, handler, false);\n\t\treturn this;\n\t}\n\n\tlistenerMap = this.listenerMap[useCapture ? 1 : 0];\n\tif (!eventType) {\n\t\tfor (singleEventType in listenerMap) {\n\t\t\tif (listenerMap.hasOwnProperty(singleEventType)) {\n\t\t\t\tthis.off(singleEventType, selector, handler);\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tlistenerList = listenerMap[eventType];\n\tif (!listenerList || !listenerList.length) {\n\t\treturn this;\n\t}\n\n\t// Remove only parameter matches\n\t// if specified\n\tfor (i = listenerList.length - 1; i >= 0; i--) {\n\t\tlistener = listenerList[i];\n\n\t\tif ((!selector || selector === listener.selector) && (!handler || handler === listener.handler)) {\n\t\t\tthis._removedListeners.push(listener);\n\t\t\tlistenerList.splice(i, 1);\n\t\t}\n\t}\n\n\t// All listeners removed\n\tif (!listenerList.length) {\n\t\tdelete listenerMap[eventType];\n\n\t\t// Remove the main handler\n\t\tif (this.rootElement) {\n\t\t\tthis.rootElement.removeEventListener(eventType, this.handle, useCapture);\n\t\t}\n\t}\n\n\treturn this;\n};\n\n\n/**\n * Handle an arbitrary event.\n *\n * @param {Event} event\n */\nDelegate.prototype.handle = function (event) {\n\tlet i;\n\tlet l;\n\tconst type = event.type;\n\tlet root;\n\tlet phase;\n\tlet listener;\n\tlet returned;\n\tlet listenerList = [];\n\tlet target;\n\tconst eventIgnore = 'ftLabsDelegateIgnore';\n\n\tif (event[eventIgnore] === true) {\n\t\treturn;\n\t}\n\n\ttarget = event.target;\n\n\t// Hardcode value of Node.TEXT_NODE\n\t// as not defined in IE8\n\tif (target.nodeType === 3) {\n\t\ttarget = target.parentNode;\n\t}\n\n\t// Handle SVG <use> elements in IE\n\tif (target.correspondingUseElement) {\n\t\ttarget = target.correspondingUseElement;\n\t}\n\n\troot = this.rootElement;\n\n\tphase = event.eventPhase || (event.target !== event.currentTarget ? 3 : 2);\n\n\t// eslint-disable-next-line default-case\n\tswitch (phase) {\n\t\tcase 1: //Event.CAPTURING_PHASE:\n\t\t\tlistenerList = this.listenerMap[1][type];\n\t\t\tbreak;\n\t\tcase 2: //Event.AT_TARGET:\n\t\t\tif (this.listenerMap[0] && this.listenerMap[0][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[0][type]);\n\t\t\t}\n\t\t\tif (this.listenerMap[1] && this.listenerMap[1][type]) {\n\t\t\t\tlistenerList = listenerList.concat(this.listenerMap[1][type]);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase 3: //Event.BUBBLING_PHASE:\n\t\t\tlistenerList = this.listenerMap[0][type];\n\t\t\tbreak;\n\t}\n\n\tlet toFire = [];\n\n\t// Need to continuously check\n\t// that the specific list is\n\t// still populated in case one\n\t// of the callbacks actually\n\t// causes the list to be destroyed.\n\tl = listenerList.length;\n\twhile (target && l) {\n\t\tfor (i = 0; i < l; i++) {\n\t\t\tlistener = listenerList[i];\n\n\t\t\t// Bail from this loop if\n\t\t\t// the length changed and\n\t\t\t// no more listeners are\n\t\t\t// defined between i and l.\n\t\t\tif (!listener) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\ttarget.tagName &&\n\t\t\t\t[\"button\", \"input\", \"select\", \"textarea\"].indexOf(target.tagName.toLowerCase()) > -1 &&\n\t\t\t\ttarget.hasAttribute(\"disabled\")\n\t\t\t) {\n\t\t\t\t// Remove things that have previously fired\n\t\t\t\ttoFire = [];\n\t\t\t}\n\t\t\t// Check for match and fire\n\t\t\t// the event if there's one\n\t\t\t//\n\t\t\t// TODO:MCG:20120117: Need a way\n\t\t\t// to check if event#stopImmediatePropagation\n\t\t\t// was called. If so, break both loops.\n\t\t\telse if (listener.matcher.call(target, listener.matcherParam, target)) {\n\t\t\t\ttoFire.push([event, target, listener]);\n\t\t\t}\n\t\t}\n\n\t\t// TODO:MCG:20120117: Need a way to\n\t\t// check if event#stopPropagation\n\t\t// was called. If so, break looping\n\t\t// through the DOM. Stop if the\n\t\t// delegation root has been reached\n\t\tif (target === root) {\n\t\t\tbreak;\n\t\t}\n\n\t\tl = listenerList.length;\n\n\t\t// Fall back to parentNode since SVG children have no parentElement in IE\n\t\ttarget = target.parentElement || target.parentNode;\n\n\t\t// Do not traverse up to document root when using parentNode, though\n\t\tif (target instanceof HTMLDocument) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tlet ret;\n\n\tfor (i = 0; i < toFire.length; i++) {\n\t\t// Has it been removed during while the event function was fired\n\t\tif (this._removedListeners.indexOf(toFire[i][2]) > -1) {\n\t\t\tcontinue;\n\t\t}\n\t\treturned = this.fire.apply(this, toFire[i]);\n\n\t\t// Stop propagation to subsequent\n\t\t// callbacks if the callback returned\n\t\t// false\n\t\tif (returned === false) {\n\t\t\ttoFire[i][0][eventIgnore] = true;\n\t\t\ttoFire[i][0].preventDefault();\n\t\t\tret = false;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn ret;\n};\n\n/**\n * Fire a listener on a target.\n *\n * @param {Event} event\n * @param {Node} target\n * @param {Object} listener\n * @returns {boolean}\n */\nDelegate.prototype.fire = function (event, target, listener) {\n\treturn listener.handler.call(target, event, target);\n};\n\n/**\n * Check whether an element\n * matches a tag selector.\n *\n * Tags are NOT case-sensitive,\n * except in XML (and XML-based\n * languages such as XHTML).\n *\n * @param {string} tagName The tag name to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesTag(tagName, element) {\n\treturn tagName.toLowerCase() === element.tagName.toLowerCase();\n}\n\n/**\n * Check whether an element\n * matches the root.\n *\n * @param {?String} selector In this case this is always passed through as null and not used\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesRoot(selector, element) {\n\tif (this.rootElement === window) {\n\t\treturn (\n\t\t\t// Match the outer document (dispatched from document)\n\t\t\telement === document ||\n\t\t\t// The <html> element (dispatched from document.body or document.documentElement)\n\t\t\telement === document.documentElement ||\n\t\t\t// Or the window itself (dispatched from window)\n\t\t\telement === window\n\t\t);\n\t}\n\treturn this.rootElement === element;\n}\n\n/**\n * Check whether the ID of\n * the element in 'this'\n * matches the given ID.\n *\n * IDs are case-sensitive.\n *\n * @param {string} id The ID to test against\n * @param {Element} element The element to test with\n * @returns boolean\n */\nfunction matchesId(id, element) {\n\treturn id === element.id;\n}\n\n/**\n * Short hand for off()\n * and root(), ie both\n * with no parameters\n *\n * @return void\n */\nDelegate.prototype.destroy = function () {\n\tthis.off();\n\tthis.root();\n};\n\nexport default Delegate;\n","/**\n * Shared 'internal' scope.\n */\nimport {get} from './core/settings.js';\n\n/**\n * CUID Generator\n */\nimport {api as cuid} from '../libs/browser-cuid.js';\n\n/**\n * Record of callbacks to call when a page is tracked.\n */\nconst page_callbacks = [];\n\n/**\n * Log messages to the browser console. Requires 'log' to be set on init.\n *\n * @param {*} args items to log\n * @returns {void}\n */\nfunction log(...args) {\n\tif (get('config').test && window.console) {\n\t\tfor (const arg of args) {\n\t\t\twindow.console.log(arg);\n\t\t}\n\t}\n}\n\n/**\n * Creates a logging function that logs messages to the console with a specified namespace.\n *\n * @function namedLog\n * @param {string} namespace - The namespace to be prefixed to each log message.\n * @returns {function} A function that logs messages to the console with the given namespace if the configuration allows.\n *\n * @example\n * const log = namedLog('MyNamespace');\n * log('This is a message'); \n * // Output: [MyNamespace]: This is a message\n */\nfunction namedLog(namespace) {\n\treturn function(...args) {\n\t\tif(get('config').test && window.console) {\n\t\t\twindow.console.log(`%c[${namespace}]:`, 'color: teal', ...args)\n\t\t}\n\t}\n}\n\n/**\n * Tests if variable is a certain type. Defaults to check for undefined if no type specified.\n *\n * @param {*} variable - The variable to check.\n * @param {string=} type - The type to test for. Defaults to undefined.\n *\n * @returns {boolean} - The answer for if the variable is of type.\n */\nfunction is(variable, type = 'undefined') {\n\treturn typeof variable === type;\n}\n\n/**\n * Merge objects together. Will remove undefined and null values.\n *\n * @param {object} target - The original object to merge in to.\n * @param {object} options - The object to merge into the target. If omitted, will merge target into a new empty Object.\n *\n * @returns {object} The merged object.\n */\nfunction merge(target, options) {\n\tif (!options) {\n\t\toptions = target;\n\t\ttarget = {};\n\t}\n\n\tlet name;\n\tlet src;\n\tlet copy;\n\n\t/* jshint -W089 */\n\t/* eslint guard-for-in: 0 */\n\tfor (name in options) {\n\t\tsrc = target[name];\n\t\tcopy = options[name];\n\n\t\t// Prevent never-ending loop\n\t\tif (target === copy) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Gets rid of missing values too\n\t\tif (typeof copy !== 'undefined' && copy !== null) {\n\t\t\ttarget[name] = src === Object(src) && !is(src, 'function') ? merge(src, copy) : copy;\n\t\t}\n\t}\n\t/* jshint +W089 */\n\t/* jslint forin:true */\n\n\treturn target;\n}\n\n/**\n * URL encode a string.\n *\n * @param {string} str - The string to be encoded.\n * @returns {string} The encoded string.\n */\nfunction encode(str) {\n\tif (window.encodeURIComponent) {\n\t\treturn window.encodeURIComponent(str);\n\t} else {\n\t\treturn window.escape(str);\n\t}\n}\n\n/**\n * URL decode a string.\n *\n * @param {string} str - The string to be decoded.\n * @returns {string} The decoded string.\n */\nfunction decode(str) {\n\tif (window.decodeURIComponent) {\n\t\treturn window.decodeURIComponent(str);\n\t} else {\n\t\treturn window.unescape(str);\n\t}\n}\n\n/**\n * Utility to add event listeners.\n *\n * @param {Element} element\n * @param {string} event\n * @param {EventListenerOrEventListenerObject} listener\n * @returns {void}\n */\nfunction addEvent(element, event, listener) {\n\tif (element.addEventListener) {\n\t\telement.addEventListener(event, listener, false);\n\t} else {\n\t\telement.attachEvent('on' + event, listener);\n\t}\n}\n\n/**\n * Utility for dispatching custom events from window\n *\n * @param {string} namespace\n * @param {string} eventType\n * @param {object} detail\n * @returns {void}\n */\nfunction broadcast(namespace, eventType, detail) {\n\tdetail = detail || {};\n\ttry {\n\t\twindow.dispatchEvent(new CustomEvent(namespace + '.' + eventType, {\n\t\t\tdetail: detail,\n\t\t\tbubbles: true\n\t\t}));\n\t} catch (error) {\n\t\t// empty\n\t}\n}\n\n/**\n * Listen for page tracking requests.\n *\n * @param {Function} cb - The callback to be called whenever a page is tracked.\n * @returns {void}\n */\nfunction onPage(cb) {\n\tif (is(cb, 'function') && !page_callbacks.includes(cb)) {\n\t\tpage_callbacks.push(cb);\n\t}\n}\n\n/**\n * Trigger the 'page' listeners.\n *\n * @returns {void}\n */\nfunction triggerPage() {\n\tfor (let i = 0; i < page_callbacks.length; i++) {\n\t\tpage_callbacks[i]();\n\t}\n}\n\n/**\n * Get a value from document.cookie matching the first match of the regexp you supply\n *\n * @param {RegExp} matcher - The Regex to match with\n * @returns {string} - The vale from the cookie\n */\nfunction getValueFromCookie(matcher) {\n\treturn document.cookie.match(matcher) && RegExp.$1 !== '' && RegExp.$1 !== 'null' ? RegExp.$1 : null;\n}\n\n/**\n * Filter an object to only have the properties which are listed in the `allowlist` parameter.\n *\n * @param {object} objectToFilter - An object whose props need to be filtered\n * @param {Array} allowedPropertyNames - The list of props to allow\n * @returns {object} An object containing only the allowed props\n */\nfunction filterProperties (objectToFilter, allowedPropertyNames) {\n\tconst filteredObject = {};\n\tfor (const allowedName of allowedPropertyNames) {\n\t\tif (objectToFilter[allowedName]) {\n\t\t\tfilteredObject[allowedName] = objectToFilter[allowedName];\n\t\t}\n\t}\n\treturn filteredObject;\n}\n\n/**\n * Trim strings\n *\n * @param {string} str - The string to trim.\n * @returns {string} The trimmed string.\n */\nfunction sanitise (str) {\n\treturn typeof str === 'string' ? str.trim() : str;\n}\n\n/**\n * Assign the subject value if the target properties are undefined\n *\n * @param {object} subject - assign the value\n * @param {object} target - be assigned the value\n * @returns {void}\n */\nfunction assignIfUndefined (subject, target) {\n\tfor (const prop in subject) {\n\t\tif (!target[prop]) {\n\t\t\ttarget[prop] = subject[prop];\n\t\t} else {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(`You can't set a custom property called ${prop}`);\n\t\t}\n\t}\n}\n\n\n/**\n * Identify circular references in 'object', and replace them with a string representation\n * of the reference. Returns a succesfully serialised JSON string, and a list of circular\n * references which were removed.\n * \n * Inspired by https://github.com/sindresorhus/safe-stringify and \n * https://github.com/sindresorhus/decircular\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {Object: {jsonString: string, warnings: array}} The stringified object, and a warnings for each circular reference which was removed\n */\nfunction removeCircularReferences(object) {\n\n\t// WeakMaps release memory when all references are garbage-collected\n\tconst circularReferences = new WeakMap();\n\tconst paths = new WeakMap();\n\n\tconst warnings = [];\n\n\tfunction getPathFragment(parent, key) {\n\t\tif (!key) {\n\t\t\treturn '$';\n\t\t}\n\n\t\tif (Array.isArray(parent)) {\n\t\t\treturn `[${key}]`;\n\t\t}\n\n\t\treturn `.${key}`;\n\t}\n\n\tfunction formatCircularReferencesWarning(references) {\n\t\tconst paths = references.map(path => '`' + path.join('') + '`');\n\t\treturn 'Circular reference between ' + paths.join(' AND ');\n\t}\n\n\tfunction replacer(key, value) {\n\t\t// Scalars don't need to be inspected as they can't contain circular references\n\t\tif (!(value !== null && typeof value === 'object')) {\n\t\t\treturn value\n\t\t}\n\n\t\t// Record the path from the root ($) to the current object (value)\n\t\t// in order to print helpful circular reference warnings.\n\t\tconst path = [...paths.get(this) || [], getPathFragment(this, key)];\n\t\tpaths.set(value, path);\n\n\t\t// If a reference to the current value is already in the list, we have\n\t\t// a circular reference. Add the current value to the list along with its path,\n\t\t// and return a useful error string rather than the unserialisable value.\n\t\tif (circularReferences.has(value)) {\n\t\t\tconst references = [...circularReferences.get(value), path];\n\t\t\tcircularReferences.set(value, references);\n\t\t\tconst warning = formatCircularReferencesWarning(references);\n\t\t\twarnings.push(warning);\n\t\t\treturn warning;\n\t\t}\n\n\t\t// This is the first time we've seen the current value in this branch \n\t\t// of the object. Record its path from the object root.\n\t\tcircularReferences.set(value, [path]);\n\n\t\t// Recurse into the value to proactively find circular references\n\t\t// before encountering a loop.\n\t\tconst newValue = Array.isArray(value) ? [] : {};\n\t\tfor (const [k, v] of Object.entries(value)) {\n\t\t\tnewValue[k] = replacer.call(value, k, v);\n\t\t}\n\n\t\t// All circular references to this object will have been identified,\n\t\t// so remove it from the list.\n\t\tcircularReferences.delete(value);\n\n\t\t// This branch of the object can now be safely serialised to a JSON string\n\t\treturn newValue;\n\t}\n\n\tconst jsonString = JSON.stringify(object, replacer);\n\treturn {jsonString, warnings};\n}\n\n\n/**\n * Stringify an object to JSON, removing any circular references. When circular references\n * are found, an error is thrown in a new event loop so that global error handlers can report it.\n *\n * @param {*} object The object we want to stringify, and search within for circular references\n * @returns {string} The safely stringified JSON string\n */\nfunction safelyStringifyJson(object) {\n\n\t// JSON.stringify throws on two cases:\n\t// - value contains a circular reference\n\t// - A BigInt value is encountered\n\t// Circular references are a real possibility in the way o-tracking is called (and saves a queue of \n\t// messages in a store), so we need to handle those gracefully.\n\t// \n\t// However, for performance reasons, we always attempt to do a basic JSON.stringify() first. The \n\t// recursion involved in removeCircularReferences() makes it about 20x slower to stringify a basic payload. \n\t// This performance hit will be exacerbated on slow devices (e.g. old Android phones) with lots of queued offline events.\n\ttry {\n\t\treturn JSON.stringify(object);\n\n\t// NB: error is discarded - we have more work to do in order to throw a useful message\n\t} catch (error) {\n\t\n\t\tconst {jsonString, warnings} = removeCircularReferences(object);\n\t\n\t\tif (warnings.length) {\n\t\t\t// Throw in a new event loop, as we always want to return JSON so the tracking payload is sent\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst errorMessage = \"AssertionError: o-tracking does not support circular references in the analytics data.\\n\" +\n\t\t\t\t\"Please remove the circular references in the data.\\n\" +\n\t\t\t\t\"Here are the paths in the data which are circular:\\n\" +\n\t\t\t\twarnings.join('\\n');\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t});\n\t\t}\n\t\n\t\treturn jsonString;\n\t}\n\n\n};\n\n/**\n * Find out whether two objects are deeply equal to each other.\n *\n * @param {*} a\n * @param {*} b\n * @returns {boolean} - true if the two arguments are deeply equal\n */\nfunction isDeepEqual(a, b) {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\n\tif (\n\t\ta &&\n\t\tb &&\n\t\ttypeof a === \"object\" &&\n\t\ttypeof b === \"object\"\n\t) {\n\t\tif (a.constructor !== b.constructor) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (Array.isArray(a)) {\n\t\t\tconst length = a.length;\n\t\t\tif (length !== b.length) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\t\tif (!isDeepEqual(a[i], b[i])) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tif (a.constructor === RegExp) {\n\t\t\treturn (\n\t\t\t\ta.source === b.source && a.flags === b.flags\n\t\t\t);\n\t\t}\n\t\tif (a.valueOf !== Object.prototype.valueOf) {\n\t\t\treturn a.valueOf() === b.valueOf();\n\t\t}\n\t\tif (a.toString !== Object.prototype.toString) {\n\t\t\treturn a.toString() === b.toString();\n\t\t}\n\n\t\tconst keys = Object.keys(a);\n\t\tconst length = keys.length;\n\t\tif (length !== Object.keys(b).length) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tif (!Object.prototype.hasOwnProperty.call(b, keys[i])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = length; i-- !== 0; ) {\n\t\t\tconst key = keys[i];\n\n\t\t\tif (!isDeepEqual(a[key], b[key])) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\nexport {\n\tlog,\n\tnamedLog,\n\tis,\n\tis as isUndefined,\n\tmerge,\n\tencode,\n\tdecode,\n\tcuid as guid,\n\taddEvent,\n\tbroadcast,\n\tonPage,\n\ttriggerPage,\n\tgetValueFromCookie,\n\tsanitise,\n\tassignIfUndefined,\n\tfilterProperties,\n\tremoveCircularReferences,\n\tsafelyStringifyJson,\n\tisDeepEqual\n};\n","export const LogLevel = Object.freeze({\n DEBUG: 0,\n INFO: 1,\n WARN: 2,\n ERROR: 3,\n TEST: 4,\n DEFAULT: 2,\n});\n\nexport function convertStringLogLevel(value: string | null) {\n const level = value?.toLowerCase();\n\n if (level === \"debug\") {\n return LogLevel.DEBUG;\n }\n\n if (level === \"info\") {\n return LogLevel.INFO;\n }\n\n if (level === \"warn\") {\n return LogLevel.WARN;\n }\n\n if (level === \"error\") {\n return LogLevel.ERROR;\n }\n\n if (level === \"test\") {\n return LogLevel.TEST;\n }\n\n return LogLevel.DEFAULT;\n}\n\nexport class Logger {\n level: number;\n constructor(\n { level = LogLevel.DEFAULT }: { level: number } = {\n level: LogLevel.DEFAULT,\n }\n ) {\n this.level = level;\n }\n\n debug(...args: any[]) {\n if (this.level <= LogLevel.DEBUG) {\n console.info(...args);\n }\n }\n\n log = this.debug;\n\n info(...args: any[]) {\n if (this.level <= LogLevel.INFO) {\n console.info(...args);\n }\n }\n\n warn(...args: any[]) {\n if (this.level <= LogLevel.WARN) {\n console.warn(...args);\n }\n }\n\n error(...args: any[]) {\n if (this.level <= LogLevel.ERROR) {\n console.error(...args);\n }\n }\n}\n","// Trace the element and all of its parents, collecting properties as we go\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\n\ntype PropMap = { [k: string]: any };\n// For a given container element, get the number of elements that match the\n// original element (siblings); and the index of the original element (position).\nconst getSiblingsAndPosition = (\n el: Element | null,\n originalEl: Element,\n selector: string\n) => {\n const siblings = Array.from(el?.querySelectorAll(selector) ?? []);\n const position = siblings.findIndex((item) => item === originalEl);\n if (position === -1) {\n return;\n }\n return {\n siblings: siblings.length,\n position,\n };\n};\n\nconst elementPropertiesToCollect = [\n \"nodeName\",\n \"className\",\n \"id\",\n \"href\",\n \"text\",\n \"role\",\n];\n// Get all (sanitised) properties of a given element.\nconst getAllElementProperties = (element: any) => {\n const properties: PropMap = {};\n for (const property of elementPropertiesToCollect) {\n const value =\n element[property] ||\n element.getAttribute(property) ||\n element.hasAttribute(property);\n if (value !== undefined) {\n if (typeof value === \"boolean\") {\n properties[property] = value;\n } else {\n properties[property] = sanitise(value);\n }\n }\n }\n\n return properties;\n};\n\nconst parseRawValue = (rawValue: string) => {\n try {\n const parsedValue = JSON.parse(rawValue);\n const type = Object.prototype.toString.call(parsedValue);\n const isJSON = type === \"[object Object]\" || type === \"[object Array]\";\n\n return [isJSON, parsedValue];\n } catch (error) {\n return [false, null];\n }\n};\n\nconst getAttributeValue = (rawValue: string) => {\n const [isJSON, value] = parseRawValue(rawValue);\n\n return isJSON ? value : rawValue;\n};\n\n// Get some properties of a given element.\nconst getDomPathProps = (attrs: Attr[], props: PropMap) => {\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) =>\n attribute.name.match(/^data-trackable|^data-o-|^aria-/i)\n )\n .forEach((attribute) => {\n props[attribute.name] = attribute.value;\n });\n\n return props;\n};\n\n// Get only the custom data-trackable-context-? properties of a given element\nconst getContextProps = (\n attrs: Attr[],\n props: PropMap,\n isOriginalEl: boolean\n) => {\n const customProps: { [k: string]: any } = {};\n\n // for the original element collect properties like className, nodeName\n if (isOriginalEl) {\n elementPropertiesToCollect.forEach((name) => {\n if (typeof props[name] !== \"undefined\" && name !== \"id\") {\n customProps[name] = props[name];\n }\n });\n }\n\n // Collect any attribute that matches given strings.\n attrs\n .filter((attribute) => attribute.name.match(/^data-trackable-context-/i))\n .forEach((attribute) => {\n customProps[attribute.name.replace(\"data-trackable-context-\", \"\")] =\n getAttributeValue(attribute.value);\n });\n\n return customProps;\n};\n\nexport function getTrace(el: Element, rootEl: Element) {\n const originalEl = el;\n const selector = originalEl?.getAttribute(\"data-trackable\")\n ? `[data-trackable=\"${originalEl.getAttribute(\"data-trackable\")}\"]`\n : originalEl?.nodeName;\n const trace = [];\n const customContext = {};\n while (el && el !== rootEl) {\n const props = getAllElementProperties(el);\n const attrs = Array.from(el.attributes);\n let domPathProps = getDomPathProps(attrs, props);\n\n // If the element happens to have a data-trackable attribute, get the siblings\n // and position of the element (relative to the current element).\n if (domPathProps[\"data-trackable\"]) {\n domPathProps = Object.assign(\n domPathProps,\n getSiblingsAndPosition(el, originalEl, selector)\n );\n }\n\n trace.push(domPathProps);\n\n const contextProps = getContextProps(attrs, props, el === originalEl);\n\n assignIfUndefined(contextProps, customContext);\n\n el = el.parentNode as Element;\n }\n return { trace, customContext };\n}\n","import Delegate from \"ftdomdelegate/main\";\n\nimport {\n sanitise,\n assignIfUndefined,\n} from \"@financial-times/o-tracking/src/javascript/utils\";\nimport { Logger } from \"./logger\";\nimport { getTrace } from \"./get-trace\";\n\nconst eventPropertiesToCollect = [\"ctrlKey\", \"altKey\", \"shiftKey\", \"metaKey\"];\n\nclass Tracking {\n cccId: string;\n cccName: string;\n subtype: string;\n teamName: string;\n shadowRoot: ShadowRoot | null;\n category: string;\n elements: string | string[];\n isInitialised: boolean;\n log: Logger;\n\n constructor({\n id = \"00000000-0000-0000-0000-000000000000\",\n name = \"ccc-component\",\n subtype = \"interactive\",\n teamName = \"djd\",\n shadowRoot = null,\n category = \"cta\",\n elements = 'a, button, input, [role=\"button\"]',\n logger,\n }: {\n id?: string;\n name: string;\n subtype: string;\n teamName?: string;\n shadowRoot: ShadowRoot | null;\n category?: string;\n elements?: string | string[];\n logger: Logger;\n }) {\n this.cccId = id;\n this.cccName = name;\n this.subtype = subtype;\n this.teamName = teamName;\n this.shadowRoot = shadowRoot;\n this.category = category;\n this.elements = elements;\n this.isInitialised = false;\n this.log = logger ?? new Logger();\n }\n\n // Get properties for the event (as opposed to properties of the clicked element)\n getEventProperties(event: any) {\n const eventProperties: { [k: string]: any } = {};\n for (const property of eventPropertiesToCollect) {\n if (event[property]) {\n try {\n eventProperties[property] = sanitise(event[property]);\n } catch (e) {\n this.log.info(e);\n }\n }\n }\n return eventProperties;\n }\n\n // Controller for handling click events\n handleClickEvent(\n eventData: { action: string; category: string },\n root: Element\n ) {\n return (clickEvent: Event, clickElement: HTMLElement) => {\n const context: any = this.getEventProperties(clickEvent);\n const { trace, customContext } = getTrace(clickElement, root);\n context.custom =\n clickElement.dataset && clickElement.dataset.custom\n ? JSON.parse(clickElement.dataset.custom)\n : null;\n context.domPathTokens = trace;\n context.component = {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n };\n context.teamName = this.teamName;\n context.url = document.URL;\n\n assignIfUndefined(customContext, context);\n\n context.method = \"ftCustomAnalytics\";\n eventData = { ...eventData, ...context };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n };\n }\n\n sendSpoorEvent(triggerAction: any, extraDetail: any) {\n const eventData = {\n category: \"component\",\n action: \"act\",\n component: {\n id: this.cccId,\n name: this.cccName,\n type: \"custom-code-component\",\n subtype: this.subtype,\n },\n teamName: this.teamName,\n trigger_action: triggerAction,\n custom: extraDetail,\n method: \"ftCustomAnalytics\",\n };\n\n // send spoor event\n document.body.dispatchEvent(\n new CustomEvent(\"oTracking.event\", {\n detail: eventData,\n bubbles: true,\n composed: true,\n })\n );\n }\n\n init(id: string) {\n if (!this.isInitialised) {\n this.isInitialised = true;\n this.cccId = id ? id : this.cccId;\n\n const eventData = {\n action: \"click\",\n category: this.category,\n };\n\n const root = this.shadowRoot?.querySelector(\"[data-component-root]\");\n\n if (root) {\n const shadowDelegate = new Delegate(root);\n shadowDelegate.on(\n \"click\",\n this.elements,\n this.handleClickEvent(eventData, root),\n true\n );\n }\n }\n }\n}\n\nexport default Tracking;\n","import { CCCError } from \"./errors\";\n\nexport type ComponentPathType = {\n org: string;\n repo: string;\n component: string;\n versionRange: string;\n};\nexport class ComponentPath {\n org: string = \"local\";\n repo: string = \"dev\";\n component: string;\n versionRange: string;\n\n constructor(path: ComponentPathType | string) {\n const { org, repo, component, versionRange } = isValidComponentPathObject(\n path\n )\n ? path\n : ComponentPath.fromString(path);\n if (org) this.org = org;\n if (repo) this.repo = repo;\n this.component = component;\n this.versionRange = versionRange;\n }\n\n set path(path: ComponentPathType | string) {\n const { org, repo, component, versionRange } = isValidComponentPathObject(\n path\n )\n ? path\n : ComponentPath.fromString(path);\n this.org = org;\n this.repo = repo;\n this.component = component;\n this.versionRange = versionRange;\n }\n\n get path(): string {\n return `${this.org}/${this.repo}@${this.versionRange}/${this.component}`;\n }\n\n toString(): string {\n return this.path;\n }\n\n static fromString(path: string | null, v?: string | null): ComponentPath {\n if (!path) throw new CCCError(\"No path specified\");\n\n const [component, repo, org] = path\n .replace(/@[^\\/]+/, \"\")\n .split(\"/\")\n .reverse();\n\n const versionRange =\n v ??\n path\n .match(/@[^\\/]+/)\n ?.toString()\n .replace(\"@\", \"\") ??\n \"unknown\";\n\n if (repo && !versionRange) throw new CCCError(\"No version specified\");\n\n return new ComponentPath({ org, repo, component, versionRange });\n }\n}\n\nexport type DetailType = {\n component: ComponentPath;\n source?: string;\n cause?: string;\n};\n\nexport function isValidComponentPathObject(\n value: unknown\n): value is ComponentPathType {\n if (typeof value === \"object\" && value !== null) {\n return \"org\" in value && \"repo\" in value && \"component\" in value;\n }\n\n return false;\n}\n","/**\n * This is the base CCC component error class. These are raised when the component being loaded errors\n */\n\nimport { ComponentPath, DetailType, isValidComponentPathObject } from \"./path\";\n\nexport class CCCError extends Error {\n component: ComponentPath | null;\n source?: string;\n constructor(message: string | null, detail?: DetailType) {\n if (!detail && message) {\n super(message);\n this.component = null;\n } else if (typeof detail?.component === \"string\") {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n\n this.component = ComponentPath.fromString(detail.component);\n } else if (isValidComponentPathObject(detail?.component)) {\n super(\n message ??\n `${detail.cause ?? \"Unknown error\"} in ${detail.component.org}/${detail.component.repo}/${detail.component.component}@${detail.component.versionRange} imported from ${detail.source ?? \"an undefined source\"}.`\n );\n this.component = new ComponentPath(detail.component);\n } else {\n super(\n `${detail?.cause ?? \"Unknown error\"} in unknown component imported from ${detail?.source ?? \"unknown source\"}.`\n );\n this.component = null;\n }\n\n this.source = detail?.source;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, CCCError);\n }\n\n this.name = \"CCCError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the import of the CCC component app\n */\nexport class CCCImportError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Import error\" });\n this.name = \"CCCImportError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur during the rendering of the CCC component app\n */\nexport class CCCRenderError extends CCCError {\n constructor(message: string, detail: DetailType) {\n super(message, { ...detail, cause: \"Render error\" });\n this.name = \"CCCRenderError\";\n }\n}\n\n/**\n * This class is used to raise errors that occur as a result of the CCC component app timing out\n */\nexport class CCCTimeoutError extends CCCError {\n constructor(detail: DetailType) {\n super(null, { ...detail, cause: \"Timeout error\" });\n this.name = \"CCCTimeoutError\";\n }\n}\n","import { ComponentPath } from \"./path\";\n\nexport class CCCConnectedEvent extends Event {\n static eventType = \"ccc:ConnectedEvent\";\n\n component: ComponentPath;\n source?: string;\n\n constructor(\n detail: { component: ComponentPath; source?: string },\n opts?: EventInit\n ) {\n super(CCCConnectedEvent.eventType, {\n bubbles: true,\n cancelable: false,\n composed: true,\n ...opts,\n });\n this.component = detail.component;\n this.source = detail.source;\n }\n}\n","/**\n * Used to convert camelCase to kebab-case\n * @param str\n * @returns\n */\nexport const kebabize = (str: string) =>\n str.replace(\n /[A-Z]+(?![a-z])|[A-Z]/g,\n ($, ofs) => (ofs ? \"-\" : \"\") + $.toLowerCase()\n );\n\n/**\n * Checks if the provided host is part of the allowed test environments.\n *\n * @param host - The hostname to check.\n * @returns True if the hostname is a safe test environment, false otherwise.\n */\nexport function isSafeTestEnv(host: string | undefined) {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.apps\\.in\\.ft\\.com$/,\n ], host);\n}\n\n/**\n * Checks if the current window location hostname is considered a local environment.\n *\n * @returns True if the hostname is local, false otherwise.\n */\nexport function isLocalEnv() {\n return isAllowed([\n 'localhost',\n 'local.ft.com',\n /^.*\\.in\\.ft\\.com$/,\n ], window.location.hostname);\n}\n\n/**\n * Checks if the current window location host is one of the Spark environments.\n *\n * @returns True if the host is spark.ft.com or spark-staging.ft.com, false otherwise.\n */\nexport function isSparkEnv() {\n return isAllowed([\n 'spark.ft.com',\n 'spark-staging.ft.com',\n ], window.location.host);\n}\n\n/**\n * Checks if the given hostname is in the provided allowlist.\n *\n * @param allowlist - A list of allowed hostnames or RegExp matchers.\n * @param hostname - The hostname to validate.\n * @returns True if the hostname matches any item in the allowlist, false otherwise.\n */\nexport function isAllowed(allowlist: (string|RegExp)[], hostname: string | undefined) {\n if (!hostname) return false;\n return allowlist.some(item => {\n if (typeof item === 'string') {\n return item === hostname;\n }\n return item.test(hostname);\n });\n} \n","import { isLocalEnv, isSafeTestEnv, isSparkEnv } from \"./util\";\n\n/**\n * Assigns a test URL based on the provided testEnv value.\n *\n * @param testEnv - A string indicating test environment setting\n * @returns A `URL` object if valid and safe, or `undefined` if invalid.\n */\nexport function assignTestURL(testEnv: string | null): URL | undefined {\n if (testEnv === null) {\n return;\n }\n\n let testUrl;\n const defaultTestUrl = new URL(\"http://localhost:5173\");\n\n try {\n if (typeof testEnv === \"string\") {\n if (\n (testEnv === \"\" || testEnv.toLowerCase() === \"true\") &&\n isLocalEnv()\n ) {\n testUrl = defaultTestUrl;\n } else {\n const hasProtocol =\n testEnv.startsWith(\"http://\") || testEnv.startsWith(\"https://\");\n testUrl = hasProtocol ? new URL(testEnv) : undefined;\n\n // Prevent script injection\n if (testUrl && !isSafeTestEnv(testUrl?.hostname)) {\n throw new Error(\"Unsafe testing host override\");\n }\n }\n } else if (isSparkEnv()) {\n testUrl = defaultTestUrl;\n }\n } catch (_) {\n return testUrl;\n }\n\n return testUrl;\n}\n\n/**\n * Checks whether the given test component exists on local dev server\n *\n * @param testUrl - The test environment URL to check.\n * @returns A promise that resolves to true if Vite is running, false otherwise.\n */\nexport async function useComponentTestEnv(testUrl?: URL): Promise<boolean> {\n if (!testUrl) {\n return false;\n }\n\n const localDevOnline = fetch(new URL(`index.html`, testUrl), {\n method: \"HEAD\",\n })\n .then(() => true)\n .catch(() => false);\n\n return localDevOnline;\n}\n","/**\n * @file\n * Main component definition for custom-code-component\n */\n\nimport type { ContentTree } from \"@financial-times/content-tree\";\nimport { BaseRenderer } from \"../../ccc-sdk/src/renderers/BaseRenderer\";\nimport Tracking from \"./tracking\";\nimport { convertStringLogLevel, Logger } from \"./logger\";\nimport {\n CCCError,\n CCCImportError,\n CCCRenderError,\n CCCTimeoutError,\n} from \"./errors\";\nimport { CCCConnectedEvent } from \"./events\";\nimport { ComponentPath } from \"./path\";\nimport { kebabize } from \"./util\";\nimport { assignTestURL, useComponentTestEnv } from \"./environment\";\n\nexport class FTCustomCodeComponent extends HTMLElement {\n app?: typeof BaseRenderer.prototype.render;\n mode: \"closed\" | \"open\" = \"open\";\n RESERVED_ATTRS = new Set([\n \"iframe\",\n \"path\",\n \"version\",\n \"data-component-props\",\n \"data-asset-type\",\n \"shadow-open\",\n \"env\",\n \"load-timeout\",\n ]);\n\n source?: string;\n tracking?: Tracking;\n lightRoot?: ChildNode[];\n component?: ComponentPath;\n\n log: Logger;\n\n constructor() {\n super();\n this.log = new Logger({\n level: convertStringLogLevel(this.getAttribute(\"log\")),\n });\n\n const supportsDeclarative =\n HTMLElement.prototype.hasOwnProperty(\"attachInternals\");\n\n try {\n const internals = supportsDeclarative && this.attachInternals();\n } catch (e) {\n this.log.error(e);\n }\n }\n\n async connectedCallback() {\n try {\n const path = this.getAttribute(\"path\");\n const versionRange = this.getAttribute(\"version\");\n this.component = ComponentPath.fromString(path, versionRange);\n\n // Backup the light root to restore in case of error\n this.lightRoot = Array.from(this.childNodes);\n this.app = await this.load();\n await this.mount();\n await this.initTracking();\n } catch (e) {\n if (e instanceof Error) {\n requestAnimationFrame(() => {\n this.emitError(e);\n });\n }\n\n this.unmount(e as Error);\n }\n }\n\n emitError(error: Error) {\n let errorEvent;\n\n if (error instanceof CCCError && error.name?.startsWith(\"CCC\")) {\n errorEvent = error.name.replace(/^CCC/, \"ccc:\");\n } else {\n errorEvent = `ccc:${error?.name ?? \"UnknownError\"}`;\n }\n\n if (!errorEvent) {\n return this.log.debug(error);\n }\n\n this.dispatchEvent(\n new ErrorEvent(errorEvent, {\n bubbles: true,\n cancelable: false,\n composed: true,\n error,\n message: error.message,\n })\n );\n }\n\n disconnectedCallback() {\n const path = this.getAttribute(\"path\");\n this.log.info(`<custom-code-component:${path}> disconnected`);\n if (typeof this.onunmount === \"function\") this.onunmount();\n }\n\n channel = new MessageChannel();\n\n onmessage() {}\n onunmount(root?: any) {}\n async onready(app: Promise<void>) {\n try {\n await app;\n } catch (e) {\n if (e instanceof Error) this.emitError(e);\n }\n }\n\n postMessage(event: any) {\n this.channel.port1.postMessage(event);\n }\n\n async mount(prerendered?: ShadowRoot | null) {\n try {\n this.mode =\n this.getAttribute(\"shadow-open\") == \"false\" ? \"closed\" : \"open\";\n if (this.component) {\n this.dispatchEvent(\n new CCCConnectedEvent({\n component: this.component,\n source: this.source,\n })\n );\n\n this.dataset.cccReady = \"true\";\n delete this.dataset.cccError;\n\n if (!this.app) {\n throw new Error(\"CCC mounted without App\");\n }\n\n const ssr = this.shadowRoot !== null;\n const shadow =\n this.shadowRoot ?? this.attachShadow({ mode: this.mode });\n\n const data = JSON.parse(this.getAttribute(\"data-component-props\")!);\n\n const extraProps = Object.fromEntries(\n [...this.attributes]\n .filter((attribute) => !this.RESERVED_ATTRS.has(attribute.name))\n .map((attribute) => [attribute.name, attribute.value])\n );\n\n // Create tracking instance\n this.tracking = new Tracking({\n name: this.component?.toString(),\n subtype: \"interactive\",\n teamName: \"djd\",\n shadowRoot: this.shadowRoot,\n logger: this.log,\n });\n\n const { unmount, onmessage, ready } =\n this.app(\n shadow,\n {\n ...extraProps,\n data,\n port: this.channel.port2,\n tracking: this.tracking,\n prerendered: !!prerendered,\n children: this.children,\n },\n ssr\n ) || {};\n\n if (unmount) this.onunmount = unmount;\n if (onmessage) this.onmessage = onmessage;\n if (ready) this.onready(ready);\n }\n } catch (err) {\n this.log.info(\n `<custom-code-component> uncaught error during mount from ${this.component?.toString()}`\n );\n this.log.error(err);\n\n throw err;\n }\n }\n\n // Called in top-level error handler\n // Replace shadow root with light DOM children on error\n unmount(e: Error) {\n if (this.lightRoot) {\n this.onunmount();\n this.shadowRoot?.replaceChildren(...this.lightRoot);\n\n if (!this.dataset.cccError)\n this.dataset.cccError = kebabize(e.name.replace(\"CCC\", \"\"));\n delete this.dataset.cccReady;\n }\n }\n\n async load() {\n if (!this.component) {\n throw new Error(\"No path found\");\n }\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n const timeout = Number(this.getAttribute(\"load-timeout\") || 10000);\n const testEnv = this.getAttribute(\"testEnv\");\n const testUrl = assignTestURL(testEnv);\n const isTestEnv = await useComponentTestEnv(testUrl);\n\n const id = this.getAttribute(\"id\");\n // id querystring necessary to multiple allow components with the same source (same name and version number) to appear on the page correctly\n this.source = isTestEnv\n ? `${testUrl?.origin}/src/${this.component.component}/index.jsx?id=${id}`\n : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${\n componentVersionRange ? `@${componentVersionRange}` : \"@latest\"\n }/${this.component.component}/${this.component.component}.js?id=${id}`;\n\n try {\n return await new Promise<typeof BaseRenderer.prototype.render>(\n (resolve, reject) => {\n const to = setTimeout(() => {\n this.log.error(\"CCC import timeout error\");\n reject(\n new CCCTimeoutError({\n component: this.component!,\n source: this.source,\n })\n );\n }, Number(timeout));\n\n if (this.source) {\n import(/* webpackIgnore: true */ this.source /* @vite-ignore */)\n .then(({ default: componentRenderFunction }) => {\n if (componentRenderFunction) {\n clearTimeout(to);\n resolve(componentRenderFunction);\n } else\n throw new CCCImportError(\n \"No component renderer default export found\",\n {\n component: this.component!,\n source: this.source,\n }\n );\n })\n .catch((e) => {\n clearTimeout(to);\n this.log.error(e);\n if (e instanceof Error && !(e instanceof CCCImportError)) {\n reject(\n new CCCImportError(e.message, {\n component: this.component!,\n source: this.source,\n })\n );\n } else {\n reject(e);\n }\n });\n } else {\n clearTimeout(to);\n throw new CCCImportError(`Unable to mount ${path}`, {\n component: this.component!,\n source: this.source,\n });\n }\n }\n );\n } catch (err) {\n this.log.error(\n `<custom-code-component> error during import from ${path}@${componentVersionRange}`\n );\n\n throw err;\n }\n }\n\n initTracking = async () => {\n try {\n this.tracking?.init(this.id);\n } catch (e) {\n const path = this.getAttribute(\"path\");\n const componentVersionRange = this.getAttribute(\"version\");\n this.log.info(\n `Error initialising tracking on <custom-code-component> ${path}@${componentVersionRange}`\n );\n this.log.error(e);\n }\n };\n}\n\nexport interface CustomCodeComponent extends ContentTree.Node {\n type: \"CustomCodeComponent\";\n path: string;\n versionRange: string;\n altText: string;\n lastModified: string;\n fallbackImage?: ContentTree.Image;\n displayFallbackText: boolean;\n layout: \"in-line\" | \"mid-grid\" | \"full-grid\" | \"full-bleed\";\n /* prettier-ignore */\n attributes: { \n [key: string]: string | boolean | undefined;\n } | { children?: CustomCodeComponent | Array<CustomCodeComponent> };\n}\n\nexport type { FTCustomCodeComponent as CCCHTMLElement };\n","import { FTCustomCodeComponent } from \"./custom-code-component\";\n\n// Register the custom element\nexport const init = () =>\n customElements.define(\"custom-code-component\", FTCustomCodeComponent);\n\n// Allows module to be imported multiple times but custom element only registered once\nif (customElements && !customElements.get(\"custom-code-component\")) init();\n"],"names":["Delegate","root","listenerMap","eventType","selector","handler","useCapture","matcher","matcherParam","matchesTag","matchesId","matchesRoot","i","listener","listenerList","singleEventType","event","l","type","phase","returned","target","eventIgnore","toFire","ret","tagName","element","id","sanitise","str","assignIfUndefined","subject","prop","LogLevel","convertStringLogLevel","value","level","Logger","args","getSiblingsAndPosition","el","originalEl","siblings","position","item","elementPropertiesToCollect","getAllElementProperties","properties","property","parseRawValue","rawValue","parsedValue","getAttributeValue","isJSON","getDomPathProps","attrs","props","attribute","getContextProps","isOriginalEl","customProps","name","getTrace","rootEl","trace","customContext","domPathProps","contextProps","eventPropertiesToCollect","Tracking","subtype","teamName","shadowRoot","category","elements","logger","eventProperties","e","eventData","clickEvent","clickElement","context","triggerAction","extraDetail","_a","ComponentPath","path","org","repo","component","versionRange","isValidComponentPathObject","v","CCCError","message","detail","CCCImportError","CCCTimeoutError","_CCCConnectedEvent","opts","CCCConnectedEvent","kebabize","$","ofs","isSafeTestEnv","host","isAllowed","isLocalEnv","isSparkEnv","allowlist","hostname","assignTestURL","testEnv","testUrl","defaultTestUrl","useComponentTestEnv","FTCustomCodeComponent","componentVersionRange","supportsDeclarative","internals","error","errorEvent","app","prerendered","_b","ssr","shadow","data","extraProps","unmount","onmessage","ready","err","timeout","isTestEnv","resolve","reject","to","componentRenderFunction","init"],"mappings":"AAUA,SAASA,EAASC,GAAM;AAQvB,OAAK,cAAc,CAAC,CAAE,GAAE,EAAE,GACtBA,KACH,KAAK,KAAKA,CAAI,GAIf,KAAK,SAASD,EAAS,UAAU,OAAO,KAAK,IAAI,GAGjD,KAAK,oBAAoB,CAAE;AAC5B;AASAA,EAAS,UAAU,OAAO,SAAUC,GAAM;AACzC,QAAMC,IAAc,KAAK;AACzB,MAAIC;AAGJ,MAAI,KAAK,aAAa;AACrB,SAAKA,KAAaD,EAAY,CAAC;AAC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A,kBACR;AAAA,kBACA;AAAA,oBACE,WAAW,KAAK;AAAA,oBAChB,QAAQ,KAAK;AAAA,kBAAA;AAAA,gBAEjB;AAAA,YAAA,CACH,EACA,MAAM,CAACnB,MAAM;AACZ,2BAAa4D,CAAE,GACV,KAAA,IAAI,MAAM5D,CAAC,GACZA,aAAa,SAAS,EAAEA,aAAamB,KACvCwC;AAAA,gBACE,IAAIxC,EAAenB,EAAE,SAAS;AAAA,kBAC5B,WAAW,KAAK;AAAA,kBAChB,QAAQ,KAAK;AAAA,gBACd,CAAA;AAAA,cACH,IAEA2D,EAAO3D,CAAC;AAAA,YACV,CACD;AAAA;AAEH,+BAAa4D,CAAE,GACT,IAAIzC,EAAe,mBAAmBV,CAAI,IAAI;AAAA,cAClD,WAAW,KAAK;AAAA,cAChB,QAAQ,KAAK;AAAA,YAAA,CACd;AAAA,QACH;AAAA,MAEJ;AAAA,aACO8C,GAAK;AACZ,iBAAK,IAAI;AAAA,QACP,oDAAoD9C,CAAI,IAAI+B,CAAqB;AAAA,MACnF,GAEMe;AAAA,IAAA;AAAA,EACR;AAeJ;ACtSO,MAAMO,IAAO,MAClB,eAAe,OAAO,yBAAyBvB,CAAqB;AAGlE,kBAAkB,CAAC,eAAe,IAAI,uBAAuB,KAAQuB,EAAA;","x_google_ignoreList":[0,1]}
|
package/package.json
CHANGED
|
@@ -60,7 +60,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
60
60
|
const path = this.getAttribute("path");
|
|
61
61
|
const versionRange = this.getAttribute("version");
|
|
62
62
|
this.component = ComponentPath.fromString(path, versionRange);
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
// Backup the light root to restore in case of error
|
|
65
65
|
this.lightRoot = Array.from(this.childNodes);
|
|
66
66
|
this.app = await this.load();
|
|
@@ -128,7 +128,6 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
128
128
|
this.mode =
|
|
129
129
|
this.getAttribute("shadow-open") == "false" ? "closed" : "open";
|
|
130
130
|
if (this.component) {
|
|
131
|
-
|
|
132
131
|
this.dispatchEvent(
|
|
133
132
|
new CCCConnectedEvent({
|
|
134
133
|
component: this.component,
|
|
@@ -138,14 +137,14 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
138
137
|
|
|
139
138
|
this.dataset.cccReady = "true";
|
|
140
139
|
delete this.dataset.cccError;
|
|
141
|
-
|
|
142
140
|
|
|
143
141
|
if (!this.app) {
|
|
144
142
|
throw new Error("CCC mounted without App");
|
|
145
143
|
}
|
|
146
144
|
|
|
147
145
|
const ssr = this.shadowRoot !== null;
|
|
148
|
-
const shadow =
|
|
146
|
+
const shadow =
|
|
147
|
+
this.shadowRoot ?? this.attachShadow({ mode: this.mode });
|
|
149
148
|
|
|
150
149
|
const data = JSON.parse(this.getAttribute("data-component-props")!);
|
|
151
150
|
|
|
@@ -198,7 +197,7 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
198
197
|
if (this.lightRoot) {
|
|
199
198
|
this.onunmount();
|
|
200
199
|
this.shadowRoot?.replaceChildren(...this.lightRoot);
|
|
201
|
-
|
|
200
|
+
|
|
202
201
|
if (!this.dataset.cccError)
|
|
203
202
|
this.dataset.cccError = kebabize(e.name.replace("CCC", ""));
|
|
204
203
|
delete this.dataset.cccReady;
|
|
@@ -207,14 +206,14 @@ export class FTCustomCodeComponent extends HTMLElement {
|
|
|
207
206
|
|
|
208
207
|
async load() {
|
|
209
208
|
if (!this.component) {
|
|
210
|
-
throw new Error("No path found")
|
|
209
|
+
throw new Error("No path found");
|
|
211
210
|
}
|
|
212
211
|
const path = this.getAttribute("path");
|
|
213
212
|
const componentVersionRange = this.getAttribute("version");
|
|
214
213
|
const timeout = Number(this.getAttribute("load-timeout") || 10000);
|
|
215
|
-
const testEnv = this.getAttribute("testEnv")
|
|
216
|
-
const testUrl = assignTestURL(testEnv)
|
|
217
|
-
const isTestEnv = await useComponentTestEnv(testUrl)
|
|
214
|
+
const testEnv = this.getAttribute("testEnv");
|
|
215
|
+
const testUrl = assignTestURL(testEnv);
|
|
216
|
+
const isTestEnv = await useComponentTestEnv(testUrl);
|
|
218
217
|
|
|
219
218
|
const id = this.getAttribute("id");
|
|
220
219
|
// id querystring necessary to multiple allow components with the same source (same name and version number) to appear on the page correctly
|
package/src/environment.ts
CHANGED
|
@@ -42,54 +42,21 @@ export function assignTestURL(testEnv: string | null): URL | undefined {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Checks whether the given test
|
|
46
|
-
* which indicates a live test environment (e.g., Vite HMR is active).
|
|
45
|
+
* Checks whether the given test component exists on local dev server
|
|
47
46
|
*
|
|
48
47
|
* @param testUrl - The test environment URL to check.
|
|
49
|
-
* @returns A promise that resolves to true if
|
|
48
|
+
* @returns A promise that resolves to true if Vite is running, false otherwise.
|
|
50
49
|
*/
|
|
51
50
|
export async function useComponentTestEnv(testUrl?: URL): Promise<boolean> {
|
|
52
51
|
if (!testUrl) {
|
|
53
52
|
return false;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const localDevOnline = fetch(new URL(`index.html`, testUrl), {
|
|
56
|
+
method: "HEAD",
|
|
57
|
+
})
|
|
58
|
+
.then(() => true)
|
|
59
|
+
.catch(() => false);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
const isOpen = socket.readyState === WebSocket.OPEN;
|
|
63
|
-
if (isOpen) socket.close();
|
|
64
|
-
res(isOpen);
|
|
65
|
-
}, 5000);
|
|
66
|
-
|
|
67
|
-
socket.addEventListener(
|
|
68
|
-
"open",
|
|
69
|
-
() => {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
socket.close();
|
|
72
|
-
res(true);
|
|
73
|
-
},
|
|
74
|
-
{ once: true }
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
socket.addEventListener(
|
|
78
|
-
"error",
|
|
79
|
-
() => {
|
|
80
|
-
clearTimeout(timer);
|
|
81
|
-
socket.close();
|
|
82
|
-
res(false);
|
|
83
|
-
},
|
|
84
|
-
{ once: true }
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
} catch (err) {
|
|
88
|
-
return Promise.resolve(false);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const isWebSocketOpen = await checkWebSocketOpen(testUrl?.host);
|
|
93
|
-
|
|
94
|
-
return isWebSocketOpen;
|
|
61
|
+
return localDevOnline;
|
|
95
62
|
}
|
package/src/path.ts
CHANGED
|
@@ -7,8 +7,8 @@ export type ComponentPathType = {
|
|
|
7
7
|
versionRange: string;
|
|
8
8
|
};
|
|
9
9
|
export class ComponentPath {
|
|
10
|
-
org: string;
|
|
11
|
-
repo: string;
|
|
10
|
+
org: string = "local";
|
|
11
|
+
repo: string = "dev";
|
|
12
12
|
component: string;
|
|
13
13
|
versionRange: string;
|
|
14
14
|
|
|
@@ -18,8 +18,8 @@ export class ComponentPath {
|
|
|
18
18
|
)
|
|
19
19
|
? path
|
|
20
20
|
: ComponentPath.fromString(path);
|
|
21
|
-
this.org = org;
|
|
22
|
-
this.repo = repo;
|
|
21
|
+
if (org) this.org = org;
|
|
22
|
+
if (repo) this.repo = repo;
|
|
23
23
|
this.component = component;
|
|
24
24
|
this.versionRange = versionRange;
|
|
25
25
|
}
|
|
@@ -47,6 +47,11 @@ export class ComponentPath {
|
|
|
47
47
|
static fromString(path: string | null, v?: string | null): ComponentPath {
|
|
48
48
|
if (!path) throw new CCCError("No path specified");
|
|
49
49
|
|
|
50
|
+
const [component, repo, org] = path
|
|
51
|
+
.replace(/@[^\/]+/, "")
|
|
52
|
+
.split("/")
|
|
53
|
+
.reverse();
|
|
54
|
+
|
|
50
55
|
const versionRange =
|
|
51
56
|
v ??
|
|
52
57
|
path
|
|
@@ -55,12 +60,7 @@ export class ComponentPath {
|
|
|
55
60
|
.replace("@", "") ??
|
|
56
61
|
"unknown";
|
|
57
62
|
|
|
58
|
-
if (!versionRange) throw new CCCError("No version specified");
|
|
59
|
-
|
|
60
|
-
const [component, repo, org] = path
|
|
61
|
-
.replace(/@[^\/]+/, "")
|
|
62
|
-
.split("/")
|
|
63
|
-
.reverse();
|
|
63
|
+
if (repo && !versionRange) throw new CCCError("No version specified");
|
|
64
64
|
|
|
65
65
|
return new ComponentPath({ org, repo, component, versionRange });
|
|
66
66
|
}
|