@financial-times/custom-code-component 2.0.1-alpha.8 → 2.0.1-beta.1
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/{webcomponent/src/index.d.ts → CustomCodeComponent.d.ts} +3 -1
- package/dist/{index.js → CustomCodeComponent.js} +144 -158
- package/dist/CustomCodeComponent.js.map +1 -0
- package/package.json +5 -5
- package/src/custom-code-component.ts +86 -75
- package/src/environment.ts +31 -40
- package/src/errors.ts +1 -1
- package/src/path.ts +19 -23
- package/dist/webcomponent/src/custom-code-component.d.ts +0 -55
- package/dist/webcomponent/src/environment.d.ts +0 -15
- package/dist/webcomponent/src/errors.d.ts +0 -27
- package/dist/webcomponent/src/events.d.ts +0 -10
- package/dist/webcomponent/src/get-trace.d.ts +0 -8
- package/dist/webcomponent/src/logger.d.ts +0 -20
- package/dist/webcomponent/src/path.d.ts +0 -23
- package/dist/webcomponent/src/tracking.d.ts +0 -32
- package/dist/webcomponent/src/util.d.ts +0 -33
- package/dist/webcomponent/test/environment.test.d.ts +0 -1
- package/dist/webcomponent/test/error-handling.test.d.ts +0 -8
- package/dist/webcomponent/test/example.d.ts +0 -11
- package/dist/webcomponent/test/generate-readable-stream.d.ts +0 -8
- package/dist/webcomponent/test/path.test.d.ts +0 -5
- package/dist/webcomponent/test/ssr.test.d.ts +0 -4
- package/dist/webcomponent/test/utils.test.d.ts +0 -1
- package/dist/webcomponent/vite.config.d.ts +0 -2
- package/dist/webcomponent/vitest.config.d.ts +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
2
|
-
this.listenerMap = [{}, {}], o && this.root(o), this.handle =
|
|
1
|
+
function l(o) {
|
|
2
|
+
this.listenerMap = [{}, {}], o && this.root(o), this.handle = l.prototype.handle.bind(this), this._removedListeners = [];
|
|
3
3
|
}
|
|
4
|
-
|
|
4
|
+
l.prototype.root = function(o) {
|
|
5
5
|
const t = this.listenerMap;
|
|
6
6
|
let e;
|
|
7
7
|
if (this.rootElement) {
|
|
@@ -19,23 +19,23 @@ p.prototype.root = function(o) {
|
|
|
19
19
|
t[0].hasOwnProperty(e) && this.rootElement.addEventListener(e, this.handle, !1);
|
|
20
20
|
return this;
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
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
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) ? (c = t, i =
|
|
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 = $) : /^#[a-z0-9\-_]+$/i.test(t) ? (c = t.slice(1), i = L) : (c = t, i = Element.prototype.matches) : (c = null, i = T.bind(this)), r[o].push({
|
|
32
32
|
selector: t,
|
|
33
33
|
handler: e,
|
|
34
34
|
matcher: i,
|
|
35
35
|
matcherParam: c
|
|
36
36
|
}), this;
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
l.prototype.off = function(o, t, e, n) {
|
|
39
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;
|
|
@@ -50,12 +50,12 @@ p.prototype.off = function(o, t, e, n) {
|
|
|
50
50
|
r = c[s], (!t || t === r.selector) && (!e || e === r.handler) && (this._removedListeners.push(r), c.splice(s, 1));
|
|
51
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
56
|
let s, r, i, c, h = [], a;
|
|
57
|
-
const
|
|
58
|
-
if (o[
|
|
57
|
+
const p = "ftLabsDelegateIgnore";
|
|
58
|
+
if (o[p] === !0)
|
|
59
59
|
return;
|
|
60
60
|
switch (a = o.target, a.nodeType === 3 && (a = a.parentNode), a.correspondingUseElement && (a = a.correspondingUseElement), s = this.rootElement, r = o.eventPhase || (o.target !== o.currentTarget ? 3 : 2), r) {
|
|
61
61
|
case 1:
|
|
@@ -75,21 +75,21 @@ p.prototype.handle = function(o) {
|
|
|
75
75
|
if (a === s || (e = h.length, a = a.parentElement || a.parentNode, a instanceof HTMLDocument))
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
|
-
let
|
|
78
|
+
let v;
|
|
79
79
|
for (t = 0; t < u.length; t++)
|
|
80
80
|
if (!(this._removedListeners.indexOf(u[t][2]) > -1) && (c = this.fire.apply(this, u[t]), c === !1)) {
|
|
81
|
-
u[t][0][
|
|
81
|
+
u[t][0][p] = !0, u[t][0].preventDefault(), v = !1;
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
|
-
return
|
|
84
|
+
return v;
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
l.prototype.fire = function(o, t, e) {
|
|
87
87
|
return e.handler.call(t, o, t);
|
|
88
88
|
};
|
|
89
|
-
function
|
|
89
|
+
function $(o, t) {
|
|
90
90
|
return o.toLowerCase() === t.tagName.toLowerCase();
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function T(o, t) {
|
|
93
93
|
return this.rootElement === window ? (
|
|
94
94
|
// Match the outer document (dispatched from document)
|
|
95
95
|
t === document || // The <html> element (dispatched from document.body or document.documentElement)
|
|
@@ -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 m = 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" ? m.DEBUG : t === "info" ? m.INFO : t === "warn" ? m.WARN : t === "error" ? m.ERROR : t === "test" ? m.TEST : m.DEFAULT;
|
|
124
124
|
}
|
|
125
|
-
class
|
|
125
|
+
class k {
|
|
126
126
|
constructor({ level: t = m.DEFAULT } = {
|
|
127
127
|
level: m.DEFAULT
|
|
128
128
|
}) {
|
|
@@ -141,14 +141,14 @@ class C {
|
|
|
141
141
|
this.level <= m.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);
|
|
@@ -191,10 +191,10 @@ function D(o, t) {
|
|
|
191
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
196
|
const a = M(c, i, o === e);
|
|
197
|
-
|
|
197
|
+
A(a, r), o = o.parentNode;
|
|
198
198
|
}
|
|
199
199
|
return { trace: s, customContext: r };
|
|
200
200
|
}
|
|
@@ -210,7 +210,7 @@ class F {
|
|
|
210
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 = i, this.elements = c, this.isInitialised = !1, this.log = h ?? new
|
|
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
|
}
|
|
@@ -233,7 +233,7 @@ class F {
|
|
|
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,
|
|
@@ -273,7 +273,7 @@ class F {
|
|
|
273
273
|
action: "click",
|
|
274
274
|
category: this.category
|
|
275
275
|
}, s = (e = this.shadowRoot) == null ? void 0 : e.querySelector("[data-component-root]");
|
|
276
|
-
s && new
|
|
276
|
+
s && new l(s).on(
|
|
277
277
|
"click",
|
|
278
278
|
this.elements,
|
|
279
279
|
this.handleClickEvent(n, s),
|
|
@@ -282,66 +282,57 @@ class F {
|
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
-
class
|
|
285
|
+
class f {
|
|
286
286
|
constructor(t) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
)
|
|
290
|
-
this.org = e, this.repo = n, this.component = s, this.versionRange = r;
|
|
287
|
+
this.org = "local", this.repo = "dev";
|
|
288
|
+
const { org: e, repo: n, name: s, versionRange: r } = E(t) ? t : f.fromString(t);
|
|
289
|
+
e && (this.org = e), n && (this.repo = n), this.name = s, this.versionRange = r;
|
|
291
290
|
}
|
|
292
291
|
set path(t) {
|
|
293
|
-
const { org: e, repo: n,
|
|
294
|
-
|
|
295
|
-
) ? t : l.fromString(t);
|
|
296
|
-
this.org = e, this.repo = n, this.component = s, this.versionRange = r;
|
|
292
|
+
const { org: e, repo: n, name: s, versionRange: r } = E(t) ? t : f.fromString(t);
|
|
293
|
+
this.org = e, this.repo = n, this.name = s, this.versionRange = r;
|
|
297
294
|
}
|
|
298
295
|
get path() {
|
|
299
|
-
return `${this.org}/${this.repo}@${this.versionRange}/${this.
|
|
296
|
+
return `${this.org}/${this.repo}@${this.versionRange}/${this.name}`;
|
|
300
297
|
}
|
|
301
298
|
toString() {
|
|
302
299
|
return this.path;
|
|
303
300
|
}
|
|
304
301
|
static fromString(t, e) {
|
|
305
302
|
var c;
|
|
306
|
-
if (!t)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
throw new f("No version specified");
|
|
311
|
-
const [s, r, i] = t.replace(/@[^\/]+/, "").split("/").reverse();
|
|
312
|
-
return new l({ org: i, repo: r, component: s, versionRange: n });
|
|
303
|
+
if (!t) throw new d("No path specified");
|
|
304
|
+
const [n, s, r] = t.replace(/@[^\/]+/, "").split("/").reverse(), i = e ?? ((c = t.match(/@[^\/]+/)) == null ? void 0 : c.toString().replace("@", "")) ?? "unknown";
|
|
305
|
+
if (s && !i) throw new d("No version specified");
|
|
306
|
+
return new f({ org: r, repo: s, name: n, versionRange: i });
|
|
313
307
|
}
|
|
314
308
|
}
|
|
315
|
-
function
|
|
316
|
-
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "
|
|
309
|
+
function E(o) {
|
|
310
|
+
return typeof o == "object" && o !== null ? "org" in o && "repo" in o && "name" in o : !1;
|
|
317
311
|
}
|
|
318
|
-
class
|
|
312
|
+
class d extends Error {
|
|
319
313
|
constructor(t, e) {
|
|
320
|
-
|
|
321
|
-
super(...s);
|
|
322
|
-
};
|
|
323
|
-
!e && t ? (n(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (n(
|
|
314
|
+
!e && t ? (super(t), this.component = null) : typeof (e == null ? void 0 : e.component) == "string" ? (super(
|
|
324
315
|
t ?? `${e.cause ?? "Unknown error"} in ${e.component} imported from ${e.source ?? "an undefined source"}.`
|
|
325
|
-
), this.component =
|
|
326
|
-
t ?? `${e.cause ?? "Unknown error"} in ${e.component.org}/${e.component.repo}/${e.component.
|
|
327
|
-
), this.component = new
|
|
316
|
+
), this.component = f.fromString(e.component)) : E(e == null ? void 0 : e.component) ? (super(
|
|
317
|
+
t ?? `${e.cause ?? "Unknown error"} in ${e.component.org}/${e.component.repo}/${e.component.name}@${e.component.versionRange} imported from ${e.source ?? "an undefined source"}.`
|
|
318
|
+
), this.component = new f(e.component)) : (super(
|
|
328
319
|
`${(e == null ? void 0 : e.cause) ?? "Unknown error"} in unknown component imported from ${(e == null ? void 0 : e.source) ?? "unknown source"}.`
|
|
329
|
-
), this.component = null), this.source = e == null ? void 0 : e.source, Error.captureStackTrace && Error.captureStackTrace(this,
|
|
320
|
+
), this.component = null), this.source = e == null ? void 0 : e.source, Error.captureStackTrace && Error.captureStackTrace(this, d), this.name = "CCCError";
|
|
330
321
|
}
|
|
331
322
|
}
|
|
332
|
-
class g extends
|
|
323
|
+
class g extends d {
|
|
333
324
|
constructor(t, e) {
|
|
334
325
|
super(t, { ...e, cause: "Import error" }), this.name = "CCCImportError";
|
|
335
326
|
}
|
|
336
327
|
}
|
|
337
|
-
class
|
|
328
|
+
class j extends d {
|
|
338
329
|
constructor(t) {
|
|
339
330
|
super(null, { ...t, cause: "Timeout error" }), this.name = "CCCTimeoutError";
|
|
340
331
|
}
|
|
341
332
|
}
|
|
342
|
-
const
|
|
333
|
+
const w = class w extends Event {
|
|
343
334
|
constructor(t, e) {
|
|
344
|
-
super(
|
|
335
|
+
super(w.eventType, {
|
|
345
336
|
bubbles: !0,
|
|
346
337
|
cancelable: !1,
|
|
347
338
|
composed: !0,
|
|
@@ -349,33 +340,33 @@ const R = class A extends Event {
|
|
|
349
340
|
}), this.component = t.component, this.source = t.source;
|
|
350
341
|
}
|
|
351
342
|
};
|
|
352
|
-
|
|
353
|
-
let
|
|
354
|
-
const
|
|
343
|
+
w.eventType = "ccc:ConnectedEvent";
|
|
344
|
+
let b = w;
|
|
345
|
+
const V = (o) => o.replace(
|
|
355
346
|
/[A-Z]+(?![a-z])|[A-Z]/g,
|
|
356
347
|
(t, e) => (e ? "-" : "") + t.toLowerCase()
|
|
357
348
|
);
|
|
358
|
-
function
|
|
359
|
-
return
|
|
349
|
+
function z(o) {
|
|
350
|
+
return y([
|
|
360
351
|
"localhost",
|
|
361
352
|
"local.ft.com",
|
|
362
353
|
/^.*\.apps\.in\.ft\.com$/
|
|
363
354
|
], o);
|
|
364
355
|
}
|
|
365
|
-
function
|
|
366
|
-
return
|
|
356
|
+
function J() {
|
|
357
|
+
return y([
|
|
367
358
|
"localhost",
|
|
368
359
|
"local.ft.com",
|
|
369
360
|
/^.*\.in\.ft\.com$/
|
|
370
361
|
], window.location.hostname);
|
|
371
362
|
}
|
|
372
|
-
function
|
|
373
|
-
return
|
|
363
|
+
function W() {
|
|
364
|
+
return y([
|
|
374
365
|
"spark.ft.com",
|
|
375
366
|
"spark-staging.ft.com"
|
|
376
367
|
], window.location.host);
|
|
377
368
|
}
|
|
378
|
-
function
|
|
369
|
+
function y(o, t) {
|
|
379
370
|
return t ? o.some((e) => typeof e == "string" ? e === t : e.test(t)) : !1;
|
|
380
371
|
}
|
|
381
372
|
function H(o) {
|
|
@@ -385,37 +376,25 @@ function H(o) {
|
|
|
385
376
|
const e = new URL("http://localhost:5173");
|
|
386
377
|
try {
|
|
387
378
|
if (typeof o == "string") {
|
|
388
|
-
if ((o === "" || o.toLowerCase() === "true") &&
|
|
379
|
+
if ((o === "" || o.toLowerCase() === "true") && J())
|
|
389
380
|
t = e;
|
|
390
|
-
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !
|
|
381
|
+
else if (t = o.startsWith("http://") || o.startsWith("https://") ? new URL(o) : void 0, t && !z(t == null ? void 0 : t.hostname))
|
|
391
382
|
throw new Error("Unsafe testing host override");
|
|
392
|
-
} else
|
|
393
|
-
J() && (t = e);
|
|
383
|
+
} else W() && (t = e);
|
|
394
384
|
} catch {
|
|
395
385
|
return t;
|
|
396
386
|
}
|
|
397
387
|
return t;
|
|
398
388
|
}
|
|
399
|
-
async function
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return new Promise((s) => {
|
|
405
|
-
const r = new WebSocket(`ws://${n}`, "vite-hmr"), i = setTimeout(() => {
|
|
406
|
-
s(r.readyState === WebSocket.OPEN), r.close();
|
|
407
|
-
}, 50);
|
|
408
|
-
r.addEventListener("error", () => {
|
|
409
|
-
clearTimeout(i), r.close(), s(!1);
|
|
410
|
-
}, { once: !0 });
|
|
411
|
-
});
|
|
412
|
-
} catch {
|
|
413
|
-
return Promise.resolve(!1);
|
|
389
|
+
async function q(o, t) {
|
|
390
|
+
return t ? fetch(
|
|
391
|
+
new URL(`src/${o}/config.yaml`, t),
|
|
392
|
+
{
|
|
393
|
+
method: "HEAD"
|
|
414
394
|
}
|
|
415
|
-
|
|
416
|
-
return await t(o == null ? void 0 : o.host);
|
|
395
|
+
).then(() => !0).catch(() => !1) : !1;
|
|
417
396
|
}
|
|
418
|
-
class
|
|
397
|
+
class K extends HTMLElement {
|
|
419
398
|
constructor() {
|
|
420
399
|
super(), this.mode = "open", this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
|
|
421
400
|
"iframe",
|
|
@@ -427,30 +406,29 @@ class q extends HTMLElement {
|
|
|
427
406
|
"env",
|
|
428
407
|
"load-timeout"
|
|
429
408
|
]), this.channel = new MessageChannel(), this.initTracking = async () => {
|
|
430
|
-
var
|
|
409
|
+
var e;
|
|
431
410
|
try {
|
|
432
|
-
(
|
|
433
|
-
} catch (
|
|
434
|
-
const
|
|
411
|
+
(e = this.tracking) == null || e.init(this.id);
|
|
412
|
+
} catch (n) {
|
|
413
|
+
const s = this.getAttribute("path"), r = this.getAttribute("version");
|
|
435
414
|
this.log.info(
|
|
436
|
-
`Error initialising tracking on <custom-code-component> ${
|
|
437
|
-
), this.log.error(
|
|
415
|
+
`Error initialising tracking on <custom-code-component> ${s}@${r}`
|
|
416
|
+
), this.log.error(n);
|
|
438
417
|
}
|
|
439
|
-
}, this.log = new
|
|
440
|
-
level:
|
|
418
|
+
}, this.log = new k({
|
|
419
|
+
level: N(this.getAttribute("log"))
|
|
441
420
|
});
|
|
442
|
-
const t =
|
|
443
|
-
this.component = l.fromString(t, e), this.lightRoot = Array.from(this.childNodes);
|
|
444
|
-
const n = HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
421
|
+
const t = HTMLElement.prototype.hasOwnProperty("attachInternals");
|
|
445
422
|
try {
|
|
446
|
-
const
|
|
447
|
-
} catch (
|
|
448
|
-
this.log.error(
|
|
423
|
+
const e = t && this.attachInternals();
|
|
424
|
+
} catch (e) {
|
|
425
|
+
this.log.error(e);
|
|
449
426
|
}
|
|
450
427
|
}
|
|
451
428
|
async connectedCallback() {
|
|
452
429
|
try {
|
|
453
|
-
|
|
430
|
+
const t = this.getAttribute("path"), e = this.getAttribute("version");
|
|
431
|
+
this.component = f.fromString(t, e), this.lightRoot = Array.from(this.childNodes), this.app = await this.load(), await this.mount(), await this.initTracking();
|
|
454
432
|
} catch (t) {
|
|
455
433
|
t instanceof Error && requestAnimationFrame(() => {
|
|
456
434
|
this.emitError(t);
|
|
@@ -460,7 +438,7 @@ class q extends HTMLElement {
|
|
|
460
438
|
emitError(t) {
|
|
461
439
|
var n;
|
|
462
440
|
let e;
|
|
463
|
-
if (t instanceof
|
|
441
|
+
if (t instanceof d && ((n = t.name) != null && n.startsWith("CCC")) ? e = t.name.replace(/^CCC/, "ccc:") : e = `ccc:${(t == null ? void 0 : t.name) ?? "UnknownError"}`, !e)
|
|
464
442
|
return this.log.debug(t);
|
|
465
443
|
this.dispatchEvent(
|
|
466
444
|
new ErrorEvent(e, {
|
|
@@ -484,65 +462,72 @@ class q extends HTMLElement {
|
|
|
484
462
|
try {
|
|
485
463
|
await t;
|
|
486
464
|
} catch (e) {
|
|
487
|
-
e instanceof Error &&
|
|
465
|
+
e instanceof Error && requestAnimationFrame(() => {
|
|
466
|
+
this.emitError(e);
|
|
467
|
+
}), this.unmount(e);
|
|
488
468
|
}
|
|
489
469
|
}
|
|
490
470
|
postMessage(t) {
|
|
491
471
|
this.channel.port1.postMessage(t);
|
|
492
472
|
}
|
|
493
473
|
async mount(t) {
|
|
474
|
+
var e, n;
|
|
494
475
|
try {
|
|
495
|
-
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
476
|
+
if (this.mode = this.getAttribute("shadow-open") == "false" ? "closed" : "open", this.component) {
|
|
477
|
+
if (this.dispatchEvent(
|
|
478
|
+
new b({
|
|
479
|
+
component: this.component,
|
|
480
|
+
source: this.source
|
|
481
|
+
})
|
|
482
|
+
), this.dataset.cccReady = "true", delete this.dataset.cccError, !this.app)
|
|
483
|
+
throw new Error("CCC mounted without App");
|
|
484
|
+
const s = this.shadowRoot !== null, r = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), i = JSON.parse(this.getAttribute("data-component-props")), c = Object.fromEntries(
|
|
485
|
+
[...this.attributes].filter((u) => !this.RESERVED_ATTRS.has(u.name)).map((u) => [u.name, u.value])
|
|
486
|
+
);
|
|
487
|
+
this.tracking = new F({
|
|
488
|
+
name: (e = this.component) == null ? void 0 : e.toString(),
|
|
489
|
+
subtype: "interactive",
|
|
490
|
+
teamName: "djd",
|
|
491
|
+
shadowRoot: this.shadowRoot,
|
|
492
|
+
logger: this.log
|
|
493
|
+
});
|
|
494
|
+
const { unmount: h, onmessage: a, ready: p } = this.app(
|
|
495
|
+
r,
|
|
496
|
+
{
|
|
497
|
+
...c,
|
|
498
|
+
data: i,
|
|
499
|
+
port: this.channel.port2,
|
|
500
|
+
tracking: this.tracking,
|
|
501
|
+
prerendered: !!t,
|
|
502
|
+
children: this.children
|
|
503
|
+
},
|
|
504
|
+
s
|
|
505
|
+
) || {};
|
|
506
|
+
h && (this.onunmount = h), a && (this.onmessage = a), p && this.onready(p);
|
|
507
|
+
}
|
|
508
|
+
} catch (s) {
|
|
526
509
|
throw this.log.info(
|
|
527
|
-
`<custom-code-component> uncaught error during mount from ${this.component.toString()}`
|
|
528
|
-
), this.log.error(
|
|
510
|
+
`<custom-code-component> uncaught error during mount from ${(n = this.component) == null ? void 0 : n.toString()}`
|
|
511
|
+
), this.log.error(s), s;
|
|
529
512
|
}
|
|
530
513
|
}
|
|
531
514
|
// Called in top-level error handler
|
|
532
515
|
// Replace shadow root with light DOM children on error
|
|
533
516
|
unmount(t) {
|
|
534
517
|
var e;
|
|
535
|
-
this.onunmount(), (e = this.shadowRoot) == null || e.replaceChildren(...this.lightRoot), this.dataset.cccError || (this.dataset.cccError =
|
|
518
|
+
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);
|
|
536
519
|
}
|
|
537
520
|
async load() {
|
|
538
|
-
|
|
539
|
-
|
|
521
|
+
if (!this.component)
|
|
522
|
+
throw new Error("No path found");
|
|
523
|
+
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 q(this.component.name, r), c = this.getAttribute("id");
|
|
524
|
+
this.source = i ? `${r == null ? void 0 : r.origin}/src/${this.component.name}/index.jsx?id=${c}` : `https://www.ft.com/__component/${this.component.org}/${this.component.repo}${e ? `@${e}` : "@latest"}/${this.component.name}/${this.component.name}.js?id=${c}`;
|
|
540
525
|
try {
|
|
541
526
|
return await new Promise(
|
|
542
527
|
(h, a) => {
|
|
543
|
-
const
|
|
528
|
+
const p = setTimeout(() => {
|
|
544
529
|
this.log.error("CCC import timeout error"), a(
|
|
545
|
-
new
|
|
530
|
+
new j({
|
|
546
531
|
component: this.component,
|
|
547
532
|
source: this.source
|
|
548
533
|
})
|
|
@@ -555,7 +540,7 @@ class q extends HTMLElement {
|
|
|
555
540
|
/* @vite-ignore */
|
|
556
541
|
).then(({ default: u }) => {
|
|
557
542
|
if (u)
|
|
558
|
-
clearTimeout(
|
|
543
|
+
clearTimeout(p), h(u);
|
|
559
544
|
else
|
|
560
545
|
throw new g(
|
|
561
546
|
"No component renderer default export found",
|
|
@@ -565,7 +550,7 @@ class q extends HTMLElement {
|
|
|
565
550
|
}
|
|
566
551
|
);
|
|
567
552
|
}).catch((u) => {
|
|
568
|
-
clearTimeout(
|
|
553
|
+
clearTimeout(p), this.log.error(u), u instanceof Error && !(u instanceof g) ? a(
|
|
569
554
|
new g(u.message, {
|
|
570
555
|
component: this.component,
|
|
571
556
|
source: this.source
|
|
@@ -573,7 +558,7 @@ class q extends HTMLElement {
|
|
|
573
558
|
) : a(u);
|
|
574
559
|
});
|
|
575
560
|
else
|
|
576
|
-
throw clearTimeout(
|
|
561
|
+
throw clearTimeout(p), new g(`Unable to mount ${t}`, {
|
|
577
562
|
component: this.component,
|
|
578
563
|
source: this.source
|
|
579
564
|
});
|
|
@@ -586,8 +571,9 @@ class q extends HTMLElement {
|
|
|
586
571
|
}
|
|
587
572
|
}
|
|
588
573
|
}
|
|
589
|
-
const
|
|
590
|
-
customElements && !customElements.get("custom-code-component") &&
|
|
574
|
+
const _ = () => customElements.define("custom-code-component", K);
|
|
575
|
+
customElements && !customElements.get("custom-code-component") && _();
|
|
591
576
|
export {
|
|
592
|
-
|
|
577
|
+
_ as init
|
|
593
578
|
};
|
|
579
|
+
//# sourceMappingURL=CustomCodeComponent.js.map
|